import type { Tool } from "ai"; import type { SmithersDb } from "@smithers-orchestrator/db/adapter"; import type { SmithersEvent } from "@smithers-orchestrator/observability/SmithersEvent"; import type { z } from "zod"; export type ToolContext = { db: SmithersDb; runId: string; nodeId: string; iteration: number; attempt: number; idempotencyKey?: string | null; rootDir: string; allowNetwork: boolean; maxOutputBytes: number; timeoutMs: number; seq: number; emitEvent?: (event: SmithersEvent) => void | Promise; }; export type DefinedToolContext = ToolContext & { idempotencyKey: string | null; toolName: string; sideEffect: boolean; idempotent: boolean; }; export type DefineToolOptions = { name: string; description?: string; schema: Schema; sideEffect?: boolean; idempotent?: boolean; execute: ( args: z.infer, ctx: DefinedToolContext, ) => Promise | Result; }; export type DefinedToolMetadata = { name: string; sideEffect: boolean; idempotent: boolean; }; /** * A tool produced by {@link defineTool} — an `ai` SDK {@link Tool} whose input * type has been narrowed from its Zod schema and whose output type is the * caller-declared `Result`. */ export type DefinedTool = Tool< z.infer, Result >; export declare function runWithToolContext( ctx: ToolContext, fn: () => Promise, ): Promise; export declare function getToolContext(): ToolContext | undefined; export declare function getToolIdempotencyKey( ctx?: ToolContext, ): string | null; export declare function nextToolSeq(ctx: ToolContext): number; export declare function getDefinedToolMetadata( value: unknown, ): DefinedToolMetadata | null; export declare function defineTool< Schema extends z.ZodTypeAny, Result, >(options: DefineToolOptions): DefinedTool; export declare const read: DefinedTool< z.ZodObject<{ path: z.ZodString }>, string >; export declare const write: DefinedTool< z.ZodObject<{ path: z.ZodString; content: z.ZodString }>, "ok" >; export declare const edit: DefinedTool< z.ZodObject<{ path: z.ZodString; patch: z.ZodString }>, "ok" >; export declare const grep: DefinedTool< z.ZodObject<{ pattern: z.ZodString; path: z.ZodOptional }>, string >; export declare const bash: DefinedTool< z.ZodObject<{ cmd: z.ZodString; args: z.ZodOptional>; opts: z.ZodOptional }>>; }>, string >; export declare const tools: { read: typeof read; write: typeof write; edit: typeof edit; grep: typeof grep; bash: typeof bash; }; export declare function readFileTool(path: string): Promise; export declare function writeFileTool( path: string, content: string, ): Promise<"ok">; export declare function editFileTool( path: string, patch: string, ): Promise<"ok">; export declare function grepTool( pattern: string, path?: string, ): Promise; export declare function bashTool( cmd: string, args?: string[], opts?: { cwd?: string }, ): Promise;