This repository has been archived on 2026-08-16. You can view files and clone it, but cannot push or open issues or pull requests.
ollie-core/tools/tool_load.go

32 lines
747 B
Go

package tools
import (
"context"
"encoding/json"
"fmt"
"ollie/toolsrv"
)
// ToolLoad loads a tool into the current session.
func ToolLoad(ctx context.Context, srv *toolsrv.Server, args json.RawMessage) (string, error) {
var a struct {
Name string `json:"name"`
}
if err := json.Unmarshal(args, &a); err != nil {
return "", fmt.Errorf("tool_load: bad args: %w", err)
}
if a.Name == "" {
return "", fmt.Errorf("tool_load: name is required")
}
reg := srv.ToolRegistry()
sid := srv.SessionID()
if reg == nil || sid == "" {
return "", fmt.Errorf("tool_load: no session registry")
}
if err := reg.Load(sid, a.Name); err != nil {
return "", fmt.Errorf("tool_load: %w", err)
}
return fmt.Sprintf("loaded: %s", a.Name), nil
}