respond

package
v0.1.158 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 2, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package respond holds the small set of response-shaping helpers that every toolbox.Toolbox implementation needs: extract arguments from a CallToolRequest, build error / structured / content responses, and bake JSON-Schema constants into the proto Struct shape.

Go-SDK convenience for codefly toolbox plugin authors. Plugin authors writing in other languages implement the proto directly. Semi-public — may evolve with the framework, not a stability promise to third-party Go plugins.

Why centralized: drift was already a risk. The git, web, and docker toolboxes each had their own copies of `argMap` / `errResp` / `structResp` / `mustSchema` — four functions, three copies. Any bug in error formatting or schema-panic behavior would have to be fixed in three places. This package collapses them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Args

func Args(req *toolboxv0.CallToolRequest) map[string]any

Args extracts a CallToolRequest's structured arguments as a Go map. Returns an empty map (not nil) when no arguments are supplied — callers can read keys with a comma-ok idiom without nil-checking.

func Error

func Error(format string, args ...any) *toolboxv0.CallToolResponse

Error builds a non-routed error response. The Error field is populated; CanonicalRouted stays false. Use this for tool-level failures (open repo failed, unknown method, validation fail) — canonical-routing decisions live on the bash side, not inside a toolbox's own dispatch.

func Schema

func Schema(m map[string]any) *structpb.Struct

Schema converts a JSON-Schema-shaped Go map to a proto Struct. Used at server construction to bake the input/output schemas into Tool definitions; a failure here is a programmer typo and MUST surface immediately — schemas are constants and a malformed one means the binary is shipping a broken contract. Hence panic rather than returning an error.

func Struct

func Struct(payload map[string]any) *toolboxv0.CallToolResponse

Struct wraps a Go map as a single structured Content block. Returns an Error response (NOT a panic) if the map can't be marshaled to a proto Struct — that's a programmer-error path (channels, functions, etc. in the payload), but a runtime fault shouldn't be a panic at the host level.

func Text

func Text(text string) *toolboxv0.CallToolResponse

Text wraps a string as a single text Content block. Useful for tools whose natural output is unstructured (man pages, README excerpts, raw command stdout).

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL