import type { JSONSchema7 } from 'json-schema'; import type { ZodType } from 'zod'; import type { AgentExecutionCounter } from './agent'; import type { AgentMessage } from './message'; import type { AgentEventData } from '../runtime/event'; import type { BuiltTelemetry } from '../telemetry'; import type { JSONObject, JSONValue } from '../utils/json'; export interface ToolSuspendOptions { resumeSchema?: ZodType | JSONSchema7; continuation?: JSONValue; } export interface ToolExecutionContext { runId?: string; persistence?: { threadId: string; resourceId: string; hostMetadata?: JSONObject; }; emitEvent?: (event: AgentEventData) => void; abortSignal?: AbortSignal; executionCounter?: AgentExecutionCounter; onSuspend?: (payload: unknown, options?: ToolSuspendOptions) => void | Promise; suspendPayload?: unknown; continuation?: JSONValue; resumeSchema?: ToolSuspendOptions['resumeSchema']; } export interface ToolContext { toolCallId?: string; toolName?: string; runId?: string; persistence?: ToolExecutionContext['persistence']; parentTelemetry?: BuiltTelemetry; emitEvent?: ToolExecutionContext['emitEvent']; abortSignal?: ToolExecutionContext['abortSignal']; executionCounter?: ToolExecutionContext['executionCounter']; } export interface InterruptibleToolContext { suspend: (payload: S, options?: ToolSuspendOptions) => Promise; resumeData: R | undefined; cancellation?: { message: string; }; toolCallId?: string; toolName?: string; runId?: string; persistence?: ToolExecutionContext['persistence']; parentTelemetry?: BuiltTelemetry; emitEvent?: ToolExecutionContext['emitEvent']; abortSignal?: ToolExecutionContext['abortSignal']; executionCounter?: ToolExecutionContext['executionCounter']; suspendPayload?: S; continuation?: JSONValue; resumeSchema?: ToolSuspendOptions['resumeSchema']; } export interface ToolCancellationContext extends ToolContext { cancellation: { message: string; }; suspendPayload?: unknown; continuation?: JSONValue; resumeSchema?: ToolSuspendOptions['resumeSchema']; } export interface BuiltTool { readonly name: string; readonly description: string; readonly systemInstruction?: string; readonly suspendSchema?: ZodType | JSONSchema7; readonly resumeSchema?: ZodType | JSONSchema7; readonly approval?: { readonly required: boolean; readonly conditional?: boolean; }; readonly handleCancellation?: boolean; readonly onCancellation?: (input: unknown, ctx: ToolCancellationContext) => Promise; readonly toMessage?: (output: unknown) => AgentMessage | undefined | Promise; readonly toModelOutput?: (output: unknown) => unknown; readonly handler?: (input: unknown, ctx: ToolContext | InterruptibleToolContext) => Promise; readonly inputSchema?: ZodType | JSONSchema7; readonly outputSchema?: ZodType | JSONSchema7; readonly mcpTool?: boolean; readonly mcpServerName?: string; readonly mcpToolName?: string; readonly providerOptions?: Record; readonly metadata?: Record; readonly editable?: boolean; } export interface BuiltProviderTool { readonly name: `${string}.${string}`; readonly args: Record; inputSchema?: ZodType; }