add: finalize logic

This commit is contained in:
2026-02-15 21:25:17 -08:00
parent 6ad52121d3
commit 964544bd82
4 changed files with 284 additions and 61 deletions

View File

@@ -0,0 +1,42 @@
// Package tools collects tools
package tools
import (
"context"
"fmt"
"github.com/ollama/ollama/api"
"tipsy.codes/charles/mc-god/v2/internal/pkg/rcon"
)
type Tool interface {
Do(ctx context.Context, toolCall api.ToolCall, client *rcon.Client) error
Desc() api.Tool
Name() string
}
type Tools map[string]Tool
func New(tools ...Tool) Tools {
ret := make(map[string]Tool)
for _, tool := range tools {
ret[tool.Name()] = tool
}
return ret
}
func (t Tools) AsAPI() api.Tools {
var ret api.Tools
for _, tool := range t {
ret = append(ret, tool.Desc())
}
return ret
}
func (t Tools) Do(ctx context.Context, toolCall api.ToolCall, client *rcon.Client) error {
tool, found := t[toolCall.Function.Name]
if !found {
return fmt.Errorf("unknown tool %q", toolCall.Function.Name)
}
return tool.Do(ctx, toolCall, client)
}