tools

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package tools is Ether's one tool catalogue. The Ask Ether agent and the MCP server both read it; plugin tools join it through the plugin host.

It mirrors AppKit's McpCatalogTool contract (appkit-mcp): a hidden tool is never offered to a model, every tool ends in an existing gated service and never a parallel query path, inputs are re-validated in Execute, every call is audited, and only mapped error messages reach a model.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SafeMessage

func SafeMessage(err error) string

SafeMessage maps err to text a model may see.

func Userf

func Userf(format string, args ...any) error

Userf returns a UserError.

Types

type Audience

type Audience string

Audience says who may use a tool.

const (
	AudienceOwner  Audience = "owner"
	AudienceViewer Audience = "viewer" // later phase; no viewer tools in v1
)

type Catalogue

type Catalogue struct {
	// contains filtered or unexported fields
}

Catalogue is the set of tools. It is safe for concurrent use.

func NewCatalogue

func NewCatalogue() *Catalogue

NewCatalogue returns an empty catalogue.

func (*Catalogue) Lookup

func (c *Catalogue) Lookup(ctx context.Context, p Principal, name string) (Tool, bool)

Lookup returns a tool by name only if p may see it.

func (*Catalogue) Register

func (c *Catalogue) Register(ts ...Tool) error

Register adds tools; it is all or nothing.

func (*Catalogue) ReplaceOwner

func (c *Catalogue) ReplaceOwner(owner string, ts []Tool) error

ReplaceOwner swaps every tool owned by a plugin.

func (*Catalogue) Visible

func (c *Catalogue) Visible(ctx context.Context, p Principal) []Tool

Visible returns the tools p may see, sorted by name. Read-only principals (MCP "read" scope) see only read-only tools.

type Link struct {
	Label string `json:"label"` // English source; the console translates it
	Route string `json:"route"` // console route, e.g. "/releases/history/42"
}

Link is a console deep link a result may offer.

type Principal

type Principal struct {
	ViewerID int64
	IsOwner  bool
	// Surface is "console" for Ask Ether, "mcp" for paired MCP clients.
	Surface string
	// Scopes holds grant scopes ("read", "full") for MCP; empty for console.
	Scopes []string
	// Plugin is set when a plugin acts through the catalogue.
	Plugin string
}

Principal is the authenticated actor a tool runs as.

func (Principal) HasScope

func (p Principal) HasScope(s string) bool

HasScope reports whether p carries scope s. Console principals carry all.

type Proposal

type Proposal struct {
	// Category is a short English label for the approval card ("Blocklist a release").
	Category    string           `json:"category"`
	Description string           `json:"description"`
	Details     []ProposalDetail `json:"details,omitempty"`
	// Apply runs the change after approval. It must be idempotent.
	Apply func(ctx context.Context) (Result, error) `json:"-"`
	// Input is the validated input, stored with the approval for audit.
	Input map[string]any `json:"input,omitempty"`
}

Proposal is a write the owner must approve before it runs. Tools that change anything return a Proposal instead of acting.

type ProposalDetail

type ProposalDetail struct {
	Label string `json:"label"`
	Value string `json:"value"`
}

ProposalDetail is one labelled value shown on an approval card.

type Result

type Result struct {
	// Data is sent to the model. Keep it compact and bounded.
	Data map[string]any `json:"data,omitempty"`
	// Links are offered in the console next to the answer.
	Links []Link `json:"links,omitempty"`
	// Navigate asks the console to open a route (the navigate tool).
	Navigate string `json:"navigate,omitempty"`
	// Proposal, when set, becomes an approval card; nothing has changed yet.
	Proposal *Proposal `json:"proposal,omitempty"`
	// Secret, when set, asks the owner for a credential through a secret
	// card. The value goes straight to sealed storage through Store and is
	// never returned to the tool, the transcript or a model.
	Secret *SecretRequest `json:"secret,omitempty"`
}

Result is what a tool returns.

type SecretRequest

type SecretRequest struct {
	ProviderLabel   string `json:"providerLabel"`   // English source, e.g. "Real-Debrid"
	CredentialLabel string `json:"credentialLabel"` // English source, e.g. "API token"
	Purpose         string `json:"purpose"`         // English source, one sentence
	HelpURL         string `json:"helpUrl,omitempty"`
	// Store seals the value into its destination. It runs once, after the
	// owner submits, and must never log or echo the value.
	Store func(ctx context.Context, value string) error `json:"-"`
}

SecretRequest asks the owner for one credential.

type Tool

type Tool struct {
	Name        string          // snake_case; plugin tools are "<plugin>__<name>" with dots as _
	Title       string          // English source, translated in the console
	Description string          // for the model
	InputSchema json.RawMessage // JSON Schema (object); Execute re-validates
	ReadOnly    bool
	Destructive bool
	// OpenWorld marks tools that reach external services or return text that
	// third parties control (release names, TMDB overviews, plugin output).
	OpenWorld bool
	Audience  Audience
	// Owner is "builtin" or a plugin id.
	Owner string
	// Visible hides a tool from a principal entirely. Nil means visible.
	Visible   func(ctx context.Context, p Principal) bool
	Execute   func(ctx context.Context, p Principal, input map[string]any) (Result, error)
	Summarize func(Result) string
}

Tool is one catalogue entry.

func (Tool) Validate

func (t Tool) Validate() error

Validate checks a tool's static contract.

type UserError

type UserError struct{ Message string }

UserError is an error whose message is safe to show a model and a person. Every other error reaches a model only as a generic failure.

func (*UserError) Error

func (e *UserError) Error() string

Jump to

Keyboard shortcuts

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