/** * Compute the wire (JSON Schema) representation of a tool's parameters. * * Tools may author parameters in three shapes: * 1. Zod (canonical) — converted to JSON Schema on demand. * 2. ArkType — converted to JSON Schema via its native `toJsonSchema`. * 3. TypeBox / plain JSON Schema (legacy + extension compat) — upgraded to * draft 2020-12 without converting. * * All three are normalized at the boundary so providers and validators see the same * JSON Schema dialect. */ import type { Type } from "arktype"; import { type ZodType } from "zod/v4"; import type { Tool } from "../../types"; /** * True when `value` is a live Zod schema instance. * * The check is stricter than "has a `_zod` property" because a JSON * round-trip preserves the `_zod` key as a plain object and would otherwise * fool the predicate — see issue #1101, where MCP servers ship * `JSON.stringify(zodSchemaInstance)` as a tool's `inputSchema` and the * resulting plain object then explodes `z.toJSONSchema` because the prototype * (and every Zod parsing method) is gone. * * Live Zod instances always carry a `.parse` function on the prototype; * impostors do not. */ export declare function isZodSchema(value: unknown): value is ZodType; /** * True when `value` is a live ArkType schema instance. * * ArkType schemas are callable functions carrying `toJsonSchema`/`assert` * methods. Zod v4 instances are non-callable objects (keyed off `_zod`), and * raw JSON Schema is a plain object — the three are disjoint. We deliberately * avoid the Standard Schema `~standard` marker because Zod v4 implements it too. */ export declare function isArkSchema(value: unknown): value is Type; /** * Normalize `{}` (empty JSON Schema = `z.unknown()` / unconstrained value) to * boolean `true` in every schema-valued position. JSON Schema draft 2020-12 * §4.3.1: `{}` and `true` are semantically equivalent ("any JSON value"). * Grammar-constrained samplers (llama.cpp, etc.) treat the object form as * "generate an empty object" rather than "any JSON value", causing open-typed * fields like `extra.title` (from `z.record(z.string(), z.unknown())`) to * always emit `{}` instead of the intended string/number/etc. (issue #1179). * * Mutates in place. Provider-agnostic — applied to every tool wire schema so * Anthropic, Google, OpenAI, Ollama, Bedrock, and Cursor all see the * normalized form, regardless of whether the source was Zod or TypeBox. */ export declare function normalizeEmptySchemas(node: unknown): void; /** Convert a Zod schema into the JSON Schema shape providers consume. */ export declare function zodToWireSchema(schema: ZodType): Record; /** * Convert an ArkType schema into the JSON Schema shape providers consume. * * Mirrors {@link zodToWireSchema}: emit draft-2020-12, drop the `$schema` * metadata, run the JSON-schema post-process (NOT the Zod-only cleanup), then * close declared objects so the wire is `additionalProperties: false` like Zod. * * The `fallback` degrades any un-emittable node (a `.narrow()` predicate or a * morph) to its underlying base schema instead of throwing — matching Zod, * whose `.refine()`/`.transform()` likewise never appear in the wire schema. */ export declare function arkToWireSchema(schema: Type): Record; /** * Resolve a tool's parameters to a JSON Schema object suitable for sending * over the wire. Zod schemas are converted (and cached); legacy TypeBox / raw * JSON Schema parameters are upgraded to draft 2020-12 (and cached). * * Zod schemas also receive Zod-artifact cleanup; both branches normalize * schema-valued positions and nullable scalar unions. */ export declare function toolWireSchema(tool: Tool): Record; /** * Return a deep clone of `schema` with every `description` annotation removed. * The result is memoized on the input via a non-enumerable symbol (`stamp`) so * repeated provider requests reuse the same stripped object; the input is never * mutated, so the stamped `toolWireSchema` cache stays intact for * system-prompt/UI rendering. */ export declare function stripSchemaDescriptions(schema: Record): Record; /** * Strip a tool's human-readable text from its provider-bound spec: empties the * top-level `description` and removes nested schema `description` annotations. * Used when the full tool catalog is rendered into the system prompt instead, so * the descriptions ride the wire once (in the prompt) rather than duplicated on * every tool definition. Parameters are resolved to wire JSON Schema and cloned, * leaving the original tool objects and the stamped schema cache untouched. */ export declare function stripToolDescriptions(tools: readonly Tool[]): Tool[];