tool

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: Apache-2.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

func (r *Registry) Call(ctx context.Context, name string, input json.RawMessage) (Result, error)

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.

func (*Registry) Get

func (r *Registry) Get(name string) (Tool, bool)

Get returns the Tool registered under name and whether it exists.

func (*Registry) List

func (r *Registry) List() []Tool

List returns a name-sorted snapshot of all registered Tools.

Returned Tools remain owned by their registrations. The deterministic order gives future discovery adapters stable output without constraining calls.

func (*Registry) Register

func (r *Registry) Register(tool Tool) error

Register adds tool under its unique name.

Register does not replace existing Tools because replacement could leave an in-flight caller observing an unexpected implementation or resource owner.

type Result

type Result map[string]any

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.

Jump to

Keyboard shortcuts

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