/** * KHAELOR * File: src/tools/registry.ts * Description: ToolDefinition interface and ToolRegistry — schema export for the Anthropic tools parameter. * * Author: Simon-Pierre Boucher * Contact: contact@spboucher.ai */ import { KhaelorError } from "../shared/index.js"; import type { ParsedInput, ToolJsonSchema } from "./schema.js"; import { validateToolInput } from "./schema.js"; import type { ToolCapabilityHint, ToolContext, ToolName, ToolResult } from "./types.js"; /** * A tool the model can call (TOOL_PROTOCOL §1.2). The JSON schema is the * source of truth for the Anthropic `input_schema`; `capability` is the * coarse hint the executor's permission layer refines into capability * requests before `execute` runs. Tools never check permissions themselves. */ export interface ToolDefinition
{
readonly name: ToolName;
/** Model-facing description — the exact text sent in the tools array. */
readonly description: string;
/** Flat object schema, ≤5 properties (ADR-8). */
readonly inputSchema: ToolJsonSchema;
/** Coarse capability hint for the permission layer. */
readonly capability: ToolCapabilityHint;
/** Runs only after approval. Must respect ctx.signal. */
execute(input: P, ctx: ToolContext): Promise (tool: ToolDefinition , input: unknown): ParsedInput {
return validateToolInput (tool.name, tool.inputSchema, input);
}
/** Registry of the tools available to the model (TOOL_PROTOCOL §1.2). */
export class ToolRegistry {
private readonly tools = new Map