ollie/toolsrv/meta.go

55 lines
1.3 KiB
Go

package toolsrv
import (
"encoding/json"
"os"
"path/filepath"
)
// MetaFile is the JSON structure of a .meta sidecar file.
type MetaFile struct {
Description string `json:"description"`
Prompt string `json:"prompt,omitempty"`
Args json.RawMessage `json:"args,omitempty"`
Tier string `json:"tier,omitempty"`
ReadOnly bool `json:"readOnly,omitempty"`
}
// LoadMetaFile reads and parses a .meta sidecar file for the given tool name.
// Returns nil if the .meta file does not exist.
func LoadMetaFile(name string) (*MetaFile, error) {
path := filepath.Join(ToolsPath(), name+".meta")
data, err := os.ReadFile(path)
if err != nil {
if os.IsNotExist(err) {
return nil, nil
}
return nil, err
}
var m MetaFile
if err := json.Unmarshal(data, &m); err != nil {
return nil, err
}
return &m, nil
}
// ToolInfoFromMeta builds a ToolInfo from a MetaFile.
func ToolInfoFromMeta(name string, m *MetaFile) ToolInfo {
args := m.Args
if args == nil {
args = json.RawMessage(`{"type":"object","properties":{}}`)
}
tier := m.Tier
if tier == "" {
tier = "hot"
}
return ToolInfo{
Name: name,
Description: m.Description,
InputSchema: args,
Prompt: m.Prompt,
Tier: tier,
ReadOnly: m.ReadOnly,
}
}