import { JSONSchema7 } from 'json-schema'; import { T as ToolDefinition } from './message-CyXbT7Zj.js'; /** * One link in a composed tool: invoke `tool` with arguments derived * from the prior step's output (or the macro-call's original args), * optionally transform the result before feeding it into the next * link. */ interface ComposeStep = Record, TState = unknown> { tool: ToolDefinition; /** * Map the current pipeline state into the sub-tool's arguments. * Receives the macro call's raw args and the accumulated state * (the result of every prior step, in declaration order). */ mapArgs: (input: { args: TArgs; state: TState; prior: unknown[]; }) => Record | Promise>; /** * Transform the sub-tool's raw output before storing it in state. * Default: pass the value through untouched. */ mapResult?: (output: unknown, input: { args: TArgs; state: TState; prior: unknown[]; }) => TState | Promise; /** * Short-circuit the pipeline and return the current state when * this returns true. The step's sub-tool is still executed; use * `mapArgs` to skip if needed. */ stopWhen?: (state: TState, input: { args: TArgs; prior: unknown[]; }) => boolean; } interface ComposeToolOptions = Record> { name: string; description?: string; schema?: JSONSchema7; requiresConfirmation?: boolean; tags?: string[]; category?: string; /** Execution steps. Run left-to-right; output becomes input of next. */ steps: ComposeStep[]; /** * Final reducer — receives the last state + every intermediate * output, returns the macro tool's result. Default: the last state. */ finalize?: (input: { args: TArgs; prior: unknown[]; state: unknown; }) => unknown | Promise; /** Observability — fires before/after each step. */ onStep?: (event: { phase: 'start' | 'end' | 'skip'; step: number; tool: string; args?: Record; result?: unknown; }) => void; } /** * Chain N tools into a single macro tool. The composed tool exposes * one schema to the model (`options.schema`) but under the hood runs * a fixed pipeline of sub-tools — a "skill" that always performs the * same multi-step recipe. * * Each step's `mapArgs` builds the next call from the running state; * `mapResult` transforms the output before it's stored. The final * step's state is returned unless a `finalize` reducer is given. */ declare function composeTool = Record>(options: ComposeToolOptions): ToolDefinition; export { type ComposeStep, type ComposeToolOptions, composeTool };