Simplify codebase per audit of 8b89f14

This commit is contained in:
Ian Gulliver
2026-10-23 15:35:42 -07:00
parent 382d27d356
commit 461aac75e9
134 changed files with 1038 additions and 2907 deletions
+29
View File
@@ -17,6 +17,35 @@ type Tool struct {
Rich func(ctx context.Context, args json.RawMessage) Result
}
func decode[A any](raw json.RawMessage) (A, error) {
args := *new(A)
err := json.Unmarshal(raw, &args)
if err != nil {
return args, fmt.Errorf("malformed call: %w", err)
}
return args, nil
}
func Typed[A any](run func(ctx context.Context, args A) (string, error)) func(ctx context.Context, raw json.RawMessage) (string, error) {
return func(ctx context.Context, raw json.RawMessage) (string, error) {
args, err := decode[A](raw)
if err != nil {
return "", err
}
return run(ctx, args)
}
}
func TypedRich[A any](run func(ctx context.Context, args A) Result) func(ctx context.Context, raw json.RawMessage) Result {
return func(ctx context.Context, raw json.RawMessage) Result {
args, err := decode[A](raw)
if err != nil {
return TextResult(err.Error(), true)
}
return run(ctx, args)
}
}
type Content struct {
Type string `json:"type"`
Text string `json:"text"`