Changeset 0.29.2 (#197)

Co-authored-by: Jeffrey Smith <jasafpro@gmail.com>
Co-committed-by: Jeffrey Smith <jasafpro@gmail.com>
This commit is contained in:
2026-03-17 22:31:34 +00:00
committed by xcaliber
parent d4de84f3f1
commit 115004a3ab
35 changed files with 2285 additions and 48 deletions

View File

@@ -180,15 +180,25 @@ func BuildToolDefs(
})
}
// Append browser-defined tool schemas from extensions
if includeBrowser && stores.Packages != nil {
// Append browser-defined and starlark-tier tool schemas from extensions.
// v0.29.2: starlark tools are always included (not gated on browser connection).
if stores.Packages != nil {
pkgs, err := stores.Packages.ListForUser(ctx, userID)
if err != nil {
log.Printf("⚠️ Failed to load extensions for tools: %v", err)
return defs
}
for _, pkg := range pkgs {
if pkg.Tier != "browser" {
// Browser tools only when a browser client is connected.
if pkg.Tier == "browser" && !includeBrowser {
continue
}
// Only browser and starlark tiers expose tools this way.
if pkg.Tier != "browser" && pkg.Tier != "starlark" {
continue
}
// Starlark packages must be active to expose tools.
if pkg.Tier == "starlark" && pkg.Status != "active" {
continue
}
var manifest struct {
@@ -196,7 +206,6 @@ func BuildToolDefs(
Name string `json:"name"`
Description string `json:"description"`
Parameters json.RawMessage `json:"parameters"`
Tier string `json:"tier"`
} `json:"tools"`
}
if err := json.Unmarshal(marshalManifest(pkg.Manifest), &manifest); err != nil {
@@ -243,6 +252,39 @@ func BuildToolDefs(
return defs
}
// BuildExtToolMap returns a map of toolName → PackageRegistration for all
// active starlark-tier extensions that declare tools in their manifest.
// Used by the tool loop to dispatch matched calls to on_tool_call.
func BuildExtToolMap(ctx context.Context, stores store.Stores, userID string) map[string]*store.PackageRegistration {
if stores.Packages == nil {
return nil
}
pkgs, err := stores.Packages.ListForUser(ctx, userID)
if err != nil {
return nil
}
result := make(map[string]*store.PackageRegistration)
for i, pkg := range pkgs {
if pkg.Tier != "starlark" || pkg.Status != "active" {
continue
}
var manifest struct {
Tools []struct {
Name string `json:"name"`
} `json:"tools"`
}
if json.Unmarshal(marshalManifest(pkg.Manifest), &manifest) != nil {
continue
}
for _, t := range manifest.Tools {
if t.Name != "" {
result[t.Name] = &pkgs[i].PackageRegistration
}
}
}
return result
}
// FilterToolDefsByGrants applies an additional allowlist to tool defs.
// Used by the task scheduler to enforce task-level tool grants on top
// of persona-level grants. Passing nil or empty grants returns defs unchanged.