/** * Low-level wrappers shared by spec-driven and hand-written tool bindings. * * Each wrapper: * 1. Calls the appropriate transport. * 2. Records the invocation through the tracker (success or failure). * 3. Wraps the result in the Claude Agent SDK's `{ content: [{ type, text }] }` * response envelope, applying a size cap to avoid blowing through * the LLM context window. */ import type { AgentsApiTransport, McpTransport, ToolTracker } from './transport.js'; /** * Default cap on the JSON length of any single tool result. LLMs ignore * pretty-printing whitespace, so we serialize compactly to make every * byte useful. Truncated results gain a hint asking the model to use * pagination/`limit` arguments. * * Per-call sites can override this via `deps.maxResultChars` on the * `ToolDeps` bundle. */ export declare const DEFAULT_MAX_RESULT_CHARS = 8000; /** @deprecated Renamed to {@link DEFAULT_MAX_RESULT_CHARS}. */ export declare const MAX_RESULT_CHARS = 8000; /** * Build a Claude Agent SDK tool result. Serializes non-string `data` * with compact JSON, truncating if it exceeds `maxChars` (defaults to * {@link DEFAULT_MAX_RESULT_CHARS}). * * Truncation deliberately wraps the partial payload between obvious * sentinel lines so the LLM does not attempt to parse mid-JSON * fragments as a complete object — the slice is almost certainly * not valid JSON. */ export declare function textResult(data: unknown, isError?: boolean, maxChars?: number): { isError?: true | undefined; content: { type: "text"; text: string; }[]; }; /** * Return a copy of `obj` containing only the requested keys whose value * is not `undefined`. Used by handlers that build partial-update params. */ export declare function pickDefined>(obj: T, keys: readonly (keyof T)[]): Partial; /** * Marker class for transport-layer failures (network, auth, 5xx). * * Domain-layer failures (`{ ok: false, error: 'NotFound' }`-style * responses already unwrapped by the transport) come back as plain * `Error`. Transports SHOULD wrap network/auth/5xx failures in * `TransportError` so `safeMcp` can tag them in the tracker and tag * the LLM-visible result text — agents tend to retry transport * errors and abandon flows on domain errors, so the distinction * matters. * * Transports that don't yet wrap failures are still supported; their * errors fall through as generic domain errors. */ export declare class TransportError extends Error { constructor(message: string, options?: { cause?: unknown; }); } /** * Call an MCP endpoint, record the invocation, return a tool-result * envelope. Errors become `{ isError: true }` results so the LLM can * read the error message and self-correct rather than crashing the * agent loop. Transport-level errors (see {@link TransportError}) * are tagged so the tracker can distinguish them from domain errors. */ export declare function safeMcp(toolName: string, input: Record, endpoint: string, params: unknown, mcp: McpTransport, track: ToolTracker, maxChars?: number): Promise<{ isError?: true | undefined; content: { type: "text"; text: string; }[]; }>; /** * Call an Agents API method, record the invocation, return a tool-result * envelope. Mirrors {@link safeMcp} for the agents transport. */ export declare function safeAgentsApi(toolName: string, input: Record, method: string, params: unknown, agentsApi: AgentsApiTransport, track: ToolTracker, maxChars?: number): Promise<{ isError?: true | undefined; content: { type: "text"; text: string; }[]; }>; /** * Bind transports + tracker once, return wrappers so call sites stay * terse. Hand-written bindings use this when they call multiple * endpoints in a single tool body. */ export declare function bindWrappers(mcp: McpTransport, agentsApi: AgentsApiTransport | undefined, track: ToolTracker, maxChars?: number): { safeMcp: (name: string, input: Record, endpoint: string, params: unknown) => Promise<{ isError?: true | undefined; content: { type: "text"; text: string; }[]; }>; safeAgentsApi: (name: string, input: Record, method: string, params: unknown) => Promise<{ isError?: true | undefined; content: { type: "text"; text: string; }[]; }>; };