mirror of
https://github.com/mudler/LocalAI.git
synced 2026-11-06 04:23:15 -05:00
* feat(skills): reserve document provider slots Separate document provider slots from protected core skill names. Keep existing same-name shadows declarations compatible. Normalize legacy document OFF markers in JSON and database stores. Persist normalization under the existing lock or transaction so an explicit re-enable cannot be overwritten by a stale read. Cover persistence, rollback, ownership and concurrent replacement. Refresh the contracts inventory from the passing Ginkgo report. Signed-off-by: Ettore Di Giacinto <mudler@localai.io> Assisted-by: nib:gpt-6.1-sol * feat(skills): gate Sandbox document procedures Resolve document providers against the selected isolated command backend. Keep Office guidance available without command execution and preserve explicit provider pins when their backend is unavailable. Reuse authorized chat access during tool construction to avoid reentering the session lock. Recheck access and capabilities when loading guidance. Signed-off-by: Ettore Di Giacinto <mudler@localai.io> Assisted-by: nib:gpt-6.1-sol * fix(skills): resolve saved-agent child command grants Describe saved-agent child commands from their current agent scope rather than the inherited tool map reserved for ad-hoc children. Cover index, picker and loader behavior for permitted, absent and revoked Sandbox grants without changing saved skill selections. Signed-off-by: Ettore Di Giacinto <mudler@localai.io> Assisted-by: nib:gpt-6.1-sol * feat(sandbox): install and exercise guest-owned PDF helpers Preserve PDF helper sources and MIT attribution in the guest image. Exercise valid, empty-text and defective PDFs during the image build and through the packaged isolated command route. Register the packaging regression in the exact suite inventory. Signed-off-by: Ettore Di Giacinto <mudler@localai.io> Assisted-by: nib:gpt-5 * feat(sandbox): own document skills and consolidated references Move the four document authoring trees out of core and package their text-only procedures with Sandbox. Preserve source coverage with offline fingerprints, guest PDF helper paths, and package-local license notices. Exercise actual skill receipt materialization across install, upgrade and uninstall; keep stale built-in cleanup and report-derived suite inventories current. Assisted-by: nib:gpt-6.1-sol Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(ui): explain document skill providers and unavailable selections Show provider-owned document procedures without removed built-in fallbacks, retain remaining built-in replacement notices, and translate install guidance in every locale. Cover picker labels, saved names and real API OFF normalization, and document grants, isolated execution and unchanged extraction. Acknowledge the intentionally injected GORM callback error in preference regression tests for lint. Signed-off-by: Ettore Di Giacinto <mudler@localai.io> Assisted-by: nib:gpt-6.1-sol * docs(agents): fix document guidance formatting Signed-off-by: Ettore Di Giacinto <mudler@localai.io> Assisted-by: nib:gpt-6.1-sol * fix(ui): correct rebased skill label import Signed-off-by: Ettore Di Giacinto <mudler@localai.io> Assisted-by: nib:gpt-6.1-sol --------- Signed-off-by: Ettore Di Giacinto <mudler@localai.io> Co-authored-by: Ettore Di Giacinto <mudler@localai.io>
123 lines
5.1 KiB
Go
123 lines
5.1 KiB
Go
// SPDX-License-Identifier: MIT
|
|
package contract
|
|
|
|
import (
|
|
"fmt"
|
|
"io/fs"
|
|
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
|
|
"github.com/mudler/LocalAI/core/services/studio/builtinskills"
|
|
)
|
|
|
|
var _ = Describe("reserved document slots", func() {
|
|
It("does not promise a core fallback for document provider names", func() {
|
|
for _, name := range []string{"docx", "pptx", "pdf", "xlsx"} {
|
|
Expect(BuiltinSkillName(name)).To(BeFalse())
|
|
Expect(validateSkillDefinitions("office", []SkillDefinition{{Name: name, Shadows: name}})).To(Succeed())
|
|
Expect(validateSkillDefinitions(name, []SkillDefinition{{Name: name}})).NotTo(Succeed())
|
|
}
|
|
})
|
|
})
|
|
|
|
var _ = Describe("Skill definitions in a manifest", func() {
|
|
withSkills := func(defs ...SkillDefinition) Manifest {
|
|
m, e := ParseManifest(fixture()) // id "sample"
|
|
Expect(e).NotTo(HaveOccurred())
|
|
m.Capabilities.SkillDefinitions = defs
|
|
return m
|
|
}
|
|
valid := func(m Manifest) error {
|
|
h := compatible()
|
|
h.SDK = 0
|
|
return ValidateManifest(m, h)
|
|
}
|
|
|
|
It("parses skillDefinitions from the manifest", func() {
|
|
b := []byte(`{"schemaVersion":1,"id":"sample","version":"1.2.3","executable":"bin/sample","os":"linux","arch":"amd64","host":{"min":1,"max":2},"api":{"min":1,"max":1},"protocol":{"min":1,"max":1},"dataFormat":{"min":1,"max":2},"capabilities":{"service":true,"skillDefinitions":[{"name":"sample"},{"name":"sample-quickstart"}]}}`)
|
|
m, e := ParseManifest(b)
|
|
Expect(e).NotTo(HaveOccurred())
|
|
Expect(SkillNames(m.Capabilities.SkillDefinitions)).To(Equal([]string{"sample", "sample-quickstart"}))
|
|
})
|
|
|
|
It("accepts the add-on id and names that start with it", func() {
|
|
Expect(valid(withSkills(SkillDefinition{Name: "sample"}, SkillDefinition{Name: "sample-notes"}))).To(Succeed())
|
|
})
|
|
|
|
It("refuses a bad name, naming it", func() {
|
|
for _, n := range []string{"", "Sample", "sample_notes", "-sample", "sample/x", "sample..x"} {
|
|
Expect(valid(withSkills(SkillDefinition{Name: n}))).To(MatchError(ContainSubstring("not a valid skill name")), n)
|
|
}
|
|
})
|
|
|
|
It("refuses a name declared twice", func() {
|
|
Expect(valid(withSkills(SkillDefinition{Name: "sample"}, SkillDefinition{Name: "sample"}))).To(MatchError(ContainSubstring("declared twice")))
|
|
})
|
|
|
|
It("refuses more than 16 skills", func() {
|
|
var defs []SkillDefinition
|
|
for i := range MaxSkillDefinitions + 1 {
|
|
defs = append(defs, SkillDefinition{Name: fmt.Sprintf("sample-%d", i)})
|
|
}
|
|
Expect(valid(withSkills(defs[:MaxSkillDefinitions]...))).To(Succeed())
|
|
Expect(valid(withSkills(defs...))).To(MatchError(ContainSubstring("too many skill definitions")))
|
|
})
|
|
|
|
It("refuses a plain name that does not start with the add-on id", func() {
|
|
Expect(valid(withSkills(SkillDefinition{Name: "other-notes"}))).To(MatchError(ContainSubstring("must be sample or start with sample-")))
|
|
Expect(valid(withSkills(SkillDefinition{Name: "samplenotes"}))).NotTo(Succeed())
|
|
})
|
|
|
|
It("refuses protected or reserved plain names, whatever the add-on id", func() {
|
|
for _, n := range []string{"localai-apps", "localai-workspace", "writing-skills", "xlsx", "pdf"} {
|
|
m := withSkills(SkillDefinition{Name: n}) // no shadows: a plain skill
|
|
m.ID = n // the prefix rule alone would accept it
|
|
Expect(valid(m)).NotTo(Succeed(), n)
|
|
}
|
|
})
|
|
|
|
It("accepts a skill that replaces a replaceable built-in skill by its name", func() {
|
|
m := withSkills(SkillDefinition{Name: "xlsx", Shadows: "xlsx"}, SkillDefinition{Name: "docx", Shadows: "docx"}, SkillDefinition{Name: "sample"})
|
|
Expect(valid(m)).To(Succeed())
|
|
Expect(ShadowedSkills(m.Capabilities.SkillDefinitions)).To(Equal([]string{"xlsx", "docx"}))
|
|
})
|
|
|
|
It("refuses shadows that does not repeat the name, or names a skill that may not be replaced", func() {
|
|
Expect(valid(withSkills(SkillDefinition{Name: "sample-xlsx", Shadows: "xlsx"}))).To(MatchError(ContainSubstring("must repeat the skill's name")))
|
|
for _, n := range []string{"writing-skills", "localai-apps", "localai-workspace", "sample"} {
|
|
Expect(valid(withSkills(SkillDefinition{Name: n, Shadows: n}))).To(MatchError(ContainSubstring("may replace")), n)
|
|
}
|
|
})
|
|
|
|
It("keeps embedded names protected or reserved without requiring a slot fallback", func() {
|
|
entries, err := fs.ReadDir(builtinskills.FS(), ".")
|
|
Expect(err).NotTo(HaveOccurred())
|
|
var names []string
|
|
for _, e := range entries {
|
|
if e.IsDir() {
|
|
names = append(names, e.Name())
|
|
}
|
|
}
|
|
Expect(names).NotTo(BeEmpty())
|
|
for _, n := range names {
|
|
Expect(ReplaceableSkill(n) != ProtectedSkill(n)).To(BeTrue(), "built-in skill %s must be replaceable or protected", n)
|
|
}
|
|
Expect(ReplaceableSkills).To(ConsistOf("docx", "pptx", "pdf", "xlsx"))
|
|
for _, n := range ReplaceableSkills {
|
|
Expect(DocumentSkill(n)).To(BeTrue())
|
|
Expect(BuiltinSkillName(n)).To(BeFalse())
|
|
}
|
|
Expect(DocumentSkill("unknown")).To(BeFalse())
|
|
for _, n := range []string{"localai-workspace", "localai-apps", "writing-skills"} {
|
|
Expect(ReplaceableSkill(n)).To(BeFalse(), n)
|
|
}
|
|
})
|
|
|
|
It("keeps the replaceable skills and tools apart, so one pin map holds both", func() {
|
|
for _, n := range ReplaceableSkills {
|
|
Expect(Replaceable(n)).To(BeFalse(), n)
|
|
}
|
|
})
|
|
})
|