/** * Vercel AI SDK tool adapter over withCodeRifts (roadmap 129 / wave-2 — * same thin pattern as OpenAI / Anthropic / LangGraph / Gemini). * * Thin converter. Guard logic stays in withCodeRifts; this module: * 1. calls withCodeRifts with the same input shape, * 2. maps each ProtectedTool → a dependency-free Vercel `tool()` object, * 3. wraps `execute` so the guarded execute runs first, then bindVercelGuardOutcome, * 4. returns those tools PLUS the untouched assurance objects. * * Measured Vercel AI SDK v4 `tool()` (no `ai` package in this repo; types from * https://ai-sdk.dev/v4/docs/reference/ai-sdk-core/tool ): * * import { tool } from 'ai'; * tool({ * description?: string, * parameters: Zod Schema | JSON Schema, * execute?: async (parameters: T, options: ToolExecutionOptions) => RESULT, * }) * ToolExecutionOptions = { toolCallId: string, messages: CoreMessage[], abortSignal?: AbortSignal } * * generateText / streamText `tools` is a Record keyed by tool name (not an array). * This package does NOT depend on `ai` or `zod`. `parameters` is JSON Schema from * ProtectedTool.inputSchema (v4 accepts JSON Schema; hosts may wrap with `tool()` + Zod). * * Only-protected-tools (6/D at the adapter surface): * - `tools` is derived ONLY from the frozen registry's ProtectedTool list. * - Raw tools never appear in the returned table. * * Honesty (do not "upgrade" assurance): composition_assurance is passed through * EXACTLY as the core reported it. */ import type { WithCodeRiftsInput, WithCodeRiftsResult, CompositionAssurance, ReceiptThreadHandle } from '../with-coderifts.js'; import type { CoverageObservedHandle } from '../coverage-observed.js'; import type { ProtectedTool, RegistryCoverageReport } from '../tool-registry.js'; import type { GuardOutcome } from '../types.js'; /** * Second argument of Vercel AI SDK v4 `execute` (ToolExecutionOptions). * @see https://ai-sdk.dev/v4/docs/ai-sdk-core/tools-and-tool-calling#tool-execution-options */ export type VercelToolExecutionOptions = { toolCallId: string; messages?: unknown[]; abortSignal?: AbortSignal; }; /** * Dependency-free Vercel `tool()` object (no `ai` import). * Name is the key in the generateText `tools` record, not a field on the object. * @see https://ai-sdk.dev/v4/docs/reference/ai-sdk-core/tool */ export type VercelTool = { description?: string; /** JSON Schema — v4 `parameters` accepts Zod Schema | JSON Schema. */ parameters: Record; /** * Guarded execute. Return is the Vercel RESULT (generateText puts it in ToolResultPart.result). * Mutators: proof-bound string from bindVercelGuardOutcome (never a nested part, never raw GuardOutcome). * Readonly passthrough may return the raw factory value. */ execute: (args: unknown, options?: VercelToolExecutionOptions) => Promise; }; /** * Result of withCodeRiftsVercel — Vercel tool record + core assurance, unflattened. * * `tools` is the ONLY bag intended for generateText / streamText. `protected_tools` * is the same guarded list (with execute) for host dispatch — never the raw tools. */ export type WithCodeRiftsVercelResult = { /** generateText `tools` record — only protected/guarded tools, keyed by name. */ tools: Record; /** * Guarded ProtectedTool list from withCodeRifts (same tools as `tools`). * Host may dispatch through these; never raw tools. */ protected_tools: ProtectedTool[]; /** Untouched registry report — registry's own truth. */ registry_report: RegistryCoverageReport; /** * Product-level assurance — deliberately narrower than the registry. * Passed through untouched; may still show inescapable_runtime:false and * residual composition_call_policy_incomplete. */ composition_assurance: CompositionAssurance; /** Per-composition receipt cursor — NOT product-truth chain evidence. */ receipt_thread: ReceiptThreadHandle; /** Observed coverage for this withCodeRifts run. Half A always; Half B via reportToolDispatch. */ coverage_observed: CoverageObservedHandle; repository?: string; }; /** * Map one ProtectedTool → Vercel `tool()` object (description, parameters, execute). * Binds guarded execute; mutator GuardOutcome is mapped through bindVercelGuardOutcome. * Prefer tool.inputSchema when it is a plain object; otherwise empty object schema. */ export declare function protectedToolToVercel(tool: ProtectedTool): VercelTool; /** * Convert a list of ProtectedTool into a Vercel generateText `tools` record. * Does NOT call the guard — map over an already-protected list. */ export declare function toVercelTools(protectedTools: readonly ProtectedTool[]): Record; /** * Build Vercel-ready guarded tools from raw tools + client + operation. * * Calls withCodeRifts internally (guard logic stays in the core). Returns: * - `tools` — generateText record { [name]: { description?, parameters, execute } } * - `protected_tools` — same guarded tools * - assurance objects from the core, passed through untouched * * @param input Same shape as withCodeRifts (WithCodeRiftsInput). */ export declare function withCodeRiftsVercel(input: WithCodeRiftsInput): WithCodeRiftsVercelResult; /** * Shape adapter over an existing WithCodeRiftsResult (composition style). * Prefer withCodeRiftsVercel when starting from raw tools. * * Does not re-run the guard; does not invent assurance. */ export declare function vercelToolAdapter(result: WithCodeRiftsResult): WithCodeRiftsVercelResult; /** * Minimal Vercel AI SDK v4 tool-result part. No `ai` dependency. * Id field is `toolCallId` (ToolExecutionOptions / ToolResultPart). * @see https://ai-sdk.dev/v4/docs/ai-sdk-core/tools-and-tool-calling */ export type VercelToolResult = { type: 'tool-result'; toolCallId: string; toolName?: string; result: string; }; declare const __proofBoundVercelBrand: unique symbol; export type ProofBoundVercelToolResult = VercelToolResult & { readonly __proofBound: typeof __proofBoundVercelBrand; }; export type BindVercelGuardOutcomeArgs = { /** Vercel toolCallId this tool-result answers. */ toolCallId: string; /** Optional tool name (ToolResultPart.toolName). */ toolName?: string; serialize?: (result: T) => string; /** * Attach the rendered GuardExecutionProof (S4). Default ON. * Pass `false` to opt out. */ attachProof?: boolean; }; export declare function defaultSerializeVercelToolResult(result: T): string; /** * Map a full GuardOutcome into a Vercel tool-result part with proof embedded. * Same arm mapping as bindOpenAIGuardOutcome; id field is toolCallId. */ export declare function bindVercelGuardOutcome(outcome: GuardOutcome, args: BindVercelGuardOutcomeArgs): ProofBoundVercelToolResult; export {}; //# sourceMappingURL=vercel.d.ts.map