Documentation
¶
Overview ¶
Package tool defines protocol-neutral callable tools for ChannelTerm.
Tool definitions intentionally use a small JSON-Schema-shaped input model so future MCP or model adapters can expose the same terminal operations without making the Session Core depend on either integration.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrDuplicateTool is returned when a name is already registered. ErrDuplicateTool = errors.New("tool is already registered") // ErrToolNotFound is returned when no registered Tool has the requested name. ErrToolNotFound = errors.New("tool not found") // ErrNilTool is returned when Register receives a nil Tool. ErrNilTool = errors.New("tool must not be nil") // ErrInvalidToolName is returned when a Tool has no usable name. ErrInvalidToolName = errors.New("tool name must not be empty") )
Functions ¶
This section is empty.
Types ¶
type InputProperty ¶
type InputProperty struct {
Type string `json:"type"`
Description string `json:"description,omitempty"`
Enum []string `json:"enum,omitempty"`
}
InputProperty describes a single property within an InputSchema object.
type InputSchema ¶
type InputSchema struct {
Type string `json:"type"`
Properties map[string]InputProperty `json:"properties,omitempty"`
Required []string `json:"required,omitempty"`
}
InputSchema describes a JSON object accepted by a Tool.
It deliberately mirrors the useful subset of JSON Schema used by MCP and function calling: object properties, their primitive types, descriptions, and required fields. Protocol adapters can serialize it directly.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry provides concurrent-safe registration and invocation of Tools.
Registry holds its lock only while accessing its map. Tool.Call always runs after releasing that lock, so a slow or cancelled operation cannot block registration, discovery, or unrelated calls.
func NewRegistry ¶
func NewRegistry() *Registry
NewRegistry creates an empty Registry ready for concurrent use.
func (*Registry) Call ¶
Call invokes the Tool registered under name.
ctx is checked before handing control to the Tool. Errors from the Tool are returned unchanged so callers can retain context and underlying error chains.
type Result ¶
Result contains structured data returned by a Tool call.
Values must remain JSON-serializable so future protocol adapters can forward them without parsing console-oriented text.
type Tool ¶
type Tool interface {
// Name returns the unique stable identifier used by Registry lookups.
Name() string
// Description explains the operation to a human or a future tool adapter.
Description() string
// InputSchema describes the JSON object accepted by Call.
InputSchema() InputSchema
// Call executes the operation. ctx controls cancellation and any deadline.
Call(ctx context.Context, input json.RawMessage) (Result, error)
}
Tool describes one named operation that can be exposed by a Tool Registry.
Call receives a JSON object matching InputSchema and returns structured data. Implementations must not write user-facing output to process streams; callers decide how to render Result and errors.