import type { ModelMessage, ToolExecutionOptions } from "ai"; import type { StandardJSONSchemaV1, StandardSchemaV1 } from "#compiled/@standard-schema/spec/index.js"; import type { Approval } from "#approval/definition.js"; import type { SessionContext } from "#context/session-context.js"; import type { JsonObject } from "#shared/json.js"; import type { TokenResult } from "#shared/connection-types.js"; import type { ToolAuthOptions, ToolAuthProvider } from "#tools/auth.js"; import type { InputOption } from "#shared/input.js"; import type { ToolModelOutput } from "#tools/model-output.js"; type ApprovalContextInput = unknown extends TInput ? Record : TInput; export type { ToolAuthDefinition, ToolAuthOptions, ToolAuthProvider } from "#tools/auth.js"; export type { ToolModelOutput, ToolModelOutputPart } from "#tools/model-output.js"; export type ToolExecuteOptions = Omit, "context">; export type ToolExecuteFn = (input: TInput, options: ToolExecuteOptions) => Promise | TOutput | AsyncIterable; interface ToolDefinitionBase { /** Whether delegated agent sessions receive this tool. Defaults to `true`. */ readonly availableInSubagents?: boolean; /** * Keeps this tool out of the model's tool list. The model finds it with * `eve__search` and calls it with `eve__tool`. Defaults to `false`. */ readonly deferred?: boolean; readonly description: string; } export interface ToolLabelDefinition { /** Returns the presentation-safe label when one action invocation starts. */ start(input: Readonly): string; /** Projects one preliminary output snapshot into presentation-safe label text. */ delta?(input: Readonly, partial: Readonly): string; /** Projects a successful final output into presentation-safe settlement text. */ complete?(input: Readonly, output: Readonly): string; } /** * Internal/compiled tool definition shape. Carries `name` because the * compiler stamps a path-derived identifier onto every tool entry. * * Authored public definitions (see {@link PublicToolDefinition}) do not * carry `name`; identity comes from the file path. */ export interface InternalToolLabelDefinition { readonly complete?: (input: unknown, output: unknown) => string; readonly delta?: (input: unknown, partial: unknown) => string; readonly start?: (input: unknown) => string; } export interface InternalToolDefinition extends ToolDefinitionBase { readonly endsTurn?: ToolDefinition["endsTurn"]; label?: InternalToolLabelDefinition; name: string; inputSchema: JsonObject | null; outputSchema?: JsonObject; } export type PublicToolInputSchema = StandardSchemaV1 | StandardJSONSchemaV1 | JsonObject; export type PublicToolOutputSchema = StandardJSONSchemaV1 | JsonObject; /** * Authored public tool definition shape. Identity is derived from the * file path at compile time, so `name` is intentionally absent here. */ export interface PublicToolDefinition extends ToolDefinitionBase { label?: ToolLabelDefinition; inputSchema: PublicToolInputSchema; /** * Optional schema describing the value returned by the tool executor. * The AI SDK can use this for tool result typing. */ outputSchema?: PublicToolOutputSchema; /** Derives the input-scoped key recorded when this tool is approved. */ approvalKey?: (input: Readonly>) => string; } export interface InternalToolDefinitionWithExecuteFn extends InternalToolDefinition { execute: ToolExecuteFn; } /** * A question a workflow tool asks the human on the session's channel, sent * with `ctx.ask` from a `defineWorkflowTool` executor. Channels render it the * way they render tool approvals. */ export interface ToolInputRequest { /** * Whether the user may answer with free text instead of one of the * {@link options}. */ readonly allowFreeform?: boolean; /** Rendering hint: confirmation buttons, a selection list, or a text field. */ readonly display?: "confirmation" | "select" | "text"; /** Selectable answers. */ readonly options?: readonly InputOption[]; readonly prompt: string; } /** Public identity fields for the authenticated person who answered a question. */ export interface ToolInputResponseResponder { readonly authenticator: string; readonly principalId: string; readonly principalType: string; } /** * The outcome of a {@link ToolInputRequest}. * * - `answered`: the user picked an option or typed an answer. An answer the * session accepted before a withdrawal wins, even after a signal aborted. * - `cancelled`: the request was withdrawn before anyone answered it, because * the ask's `signal` or the call's `abortSignal` aborted. * - `unavailable`: the session cannot reach a human, such as a scheduled run, * so the request resolved immediately without being shown. */ export type ToolInputResponse = { readonly status: "answered"; /** The selected option's `id`, when the user picked one. */ readonly optionId?: string; /** Authenticated identity of the responder, without channel attributes. */ readonly responder?: ToolInputResponseResponder; /** Free text, when the user typed an answer. */ readonly text?: string; } | { readonly status: "cancelled"; } | { readonly status: "unavailable"; }; /** Options for `ctx.ask` in a `defineWorkflowTool` executor. */ export interface ToolInputRequestOptions { /** * Withdraws the request when it aborts: the channel stops offering the * question and the ask resolves as `cancelled`, unless the session accepted * an answer first, which the ask then resolves with. The call's * `abortSignal` withdraws the request the same way without being passed. */ readonly signal?: AbortSignal; } /** * Authored tool context. Passed as the last argument to * {@link ToolDefinition.execute}. * * Extends {@link SessionContext} with token accessors. Passing a provider * resolves that provider inline, which lets one tool use multiple credentials. * * Workflow tools use the separate `WorkflowToolContext` provided by * `defineWorkflowTool`. */ export type ToolContext = SessionContext & { /** * Aborts when the work this tool is doing is cancelled: the active turn * for an ordinary tool, the durable run for a workflow tool. In a workflow * body the signal is durable — it survives replay and steps that receive it * observe the abort — and the run waits a grace period for the body to * unwind through `finally` before it ends. */ readonly abortSignal: AbortSignal; /** * Id of the current tool call — the same `callId` carried by the call's * stream events and its {@link ApprovalContext}. */ readonly callId: string; /** * Final runtime name of the current tool, including any namespace * qualification. This is the same `toolName` carried by stream events and * the tool's {@link ApprovalContext}. */ readonly toolName: string; /** * Messages sent to the model for the step that requested this call, oldest * first — the same model input a `step.started` dynamic resolver reads from * `ctx.messages`. Excludes system instructions and the assistant response * that contains this call. Includes eve-authored context messages, such as * request context and recalled memory, and reflects history projection and * compaction. */ readonly messages: readonly ModelMessage[]; /** * Resolves the bearer token for an inline provider. This accepts the same * auth shapes as a connection's `auth` field, including `connect("...")` * from `@vercel/connect/eve`. */ getToken(provider: ToolAuthProvider, options?: ToolAuthOptions): Promise; /** * Signals that the caller must complete authorization for an inline * provider before proceeding. Use this after a downstream `401` rejects a * token returned by {@link getToken}. */ requireAuth(provider: ToolAuthProvider, options?: ToolAuthOptions): never; }; /** * Public tool definition authored in `agent/tools/*.ts`. * * The tool's runtime name is the filename slug under `agent/tools/` without * the extension (`agent/tools/get_weather.ts` registers as `get_weather`). * Authored definitions have no `name` field; identity is path-derived. */ export interface ToolDefinition extends PublicToolDefinition { execute(input: TInput, ctx: ToolContext): Promise | TOutput | AsyncIterable; /** * Ends the turn after this tool succeeds, without another model call and * without a final reply. Use it for a tool whose action is the whole * answer, such as reacting to a message. The turn ends only when every * tool call in the model's step ends the turn and succeeds; a failed call * lets the model recover. Ignored in delegated sessions, which must return * a reply to their caller, and on turns that request structured output. * With `true`, eve appends a sentence to the description the model sees * telling it the call ends its turn, so write `description` for what the * tool does. * * Pass a function to decide from the result. eve calls it with the output * of `execute` after each successful call, and the call ends the turn only * when it returns `true`; if it throws, the turn continues as though it * returned `false`. The model sees no appended sentence, so describe * when the call ends the turn in `description` if the model needs to know. * Defaults to `false`. */ endsTurn?: boolean | ((output: TOutput) => boolean | Promise); /** * Optional per-tool approval gate. The return value determines whether * user approval is required before executing this tool. * * Use the helpers from `eve/tools/approval` for common cases: * - {@link always}: always require approval * - {@link never}: never require approval * - {@link once}: require approval only the first time per session */ approval?: Approval>; /** * Optional projection controlling what the model sees as the tool result. * Receives the full `TOutput` from {@link execute} and returns the * model-facing {@link ToolModelOutput}. * * When omitted, the model sees the full `execute` return value * (default AI SDK serialization). Channel event handlers * (`action.result`) always receive the full output regardless. */ toModelOutput?: (output: TOutput) => ToolModelOutput | Promise; } type ToolOutputFromExecuteReturn = TReturn extends Promise ? TOutput : TReturn extends AsyncIterable ? TOutput : TReturn; type ToolDefinitionWithExecuteReturn = ToolDefinition & { execute(input: TInput, ctx: ToolContext): TReturn; }; /** * Defines a tool configuration, used both for static tools (default export * from `agent/tools/*.ts`) and as the entry wrapper inside `defineDynamic` * resolvers. * * For static tools, the runtime tool name is the filename slug. `defineTool` * stamps a brand that lifecycle code validates; it rejects raw object literals. */ export declare function defineTool | StandardJSONSchemaV1, TOutputSchema extends StandardJSONSchemaV1, TReturn extends Promise> | StandardJSONSchemaV1.InferOutput | AsyncIterable>>(definition: { description: ToolDefinition["description"]; endsTurn?: ToolDefinition>["endsTurn"]; inputSchema: TInputSchema; outputSchema: TOutputSchema; execute(input: StandardSchemaV1.InferOutput, ctx: ToolContext): TReturn; label?: ToolDefinition, StandardJSONSchemaV1.InferOutput>["label"]; approval?: ToolDefinition, unknown>["approval"]; approvalKey?: ToolDefinition, unknown>["approvalKey"]; toModelOutput?: ToolDefinition>["toModelOutput"]; }): ToolDefinitionWithExecuteReturn, StandardJSONSchemaV1.InferOutput, TReturn>; export declare function defineTool | StandardJSONSchemaV1, TReturn>(definition: { description: ToolDefinition["description"]; endsTurn?: ToolDefinition>["endsTurn"]; inputSchema: TSchema; outputSchema?: JsonObject; execute(input: StandardSchemaV1.InferOutput, ctx: ToolContext): TReturn; label?: ToolDefinition, ToolOutputFromExecuteReturn>["label"]; approval?: ToolDefinition, unknown>["approval"]; approvalKey?: ToolDefinition, unknown>["approvalKey"]; toModelOutput?: ToolDefinition>["toModelOutput"]; }): ToolDefinitionWithExecuteReturn, ToolOutputFromExecuteReturn, TReturn>; export declare function defineTool, TReturn extends Promise> | StandardJSONSchemaV1.InferOutput | AsyncIterable>>(definition: { description: ToolDefinition["description"]; endsTurn?: ToolDefinition>["endsTurn"]; inputSchema: JsonObject; outputSchema: TOutputSchema; execute(input: Record, ctx: ToolContext): TReturn; label?: ToolDefinition, StandardJSONSchemaV1.InferOutput>["label"]; approval?: ToolDefinition, unknown>["approval"]; approvalKey?: ToolDefinition, unknown>["approvalKey"]; toModelOutput?: ToolDefinition>["toModelOutput"]; }): ToolDefinitionWithExecuteReturn, StandardJSONSchemaV1.InferOutput, TReturn>; export declare function defineTool(definition: { description: ToolDefinition["description"]; endsTurn?: ToolDefinition>["endsTurn"]; inputSchema: JsonObject; outputSchema?: JsonObject; execute(input: Record, ctx: ToolContext): TReturn; label?: ToolDefinition, ToolOutputFromExecuteReturn>["label"]; approval?: ToolDefinition, unknown>["approval"]; approvalKey?: ToolDefinition, unknown>["approvalKey"]; toModelOutput?: ToolDefinition>["toModelOutput"]; }): ToolDefinitionWithExecuteReturn, ToolOutputFromExecuteReturn, TReturn>; export declare function defineTool(definition: ToolDefinition): ToolDefinition; export declare function stampToolDefinition unknown; readonly label?: ToolLabelDefinition; readonly approval?: Approval; readonly approvalKey?: (...args: never[]) => unknown; readonly toModelOutput?: (...args: never[]) => unknown; }>(definition: T, definer: "defineTool" | "defineWorkflowTool"): T; /** * Marker discriminator written into every {@link DisabledToolSentinel}. */ declare const DISABLED_TOOL_SENTINEL_KIND = "eve:disabled-tool"; /** * Marker value returned from {@link disableTool}. Export this as the default * export of a file in `agent/tools/` to remove the model tool whose name * matches the file's slug, including framework defaults and derived subagent * tools. */ export interface DisabledToolSentinel { readonly kind: typeof DISABLED_TOOL_SENTINEL_KIND; } /** * Returns a sentinel that disables the model tool whose name matches the * containing file's slug. */ export declare function disableTool(): DisabledToolSentinel; /** * Type guard: returns whether `value` is a {@link DisabledToolSentinel} * produced by {@link disableTool}. */ export declare function isDisabledToolSentinel(value: unknown): value is DisabledToolSentinel;