/** * @license * Copyright 2026 Google LLC * SPDX-License-Identifier: Apache-2.0 */ /** * A single, reusable abstraction over the schema formats ADK APIs accept: a Zod * v3 type, a Zod v4 type, or a genai `Schema`. Mirrors the union * `FunctionTool` uses for its parameters, but at the `ZodType` level (any * schema, not just an object) so it also fits value validation. */ import { Schema } from '@google/genai'; import { z as z3 } from 'zod/v3'; import { z as z4 } from 'zod/v4'; /** * A schema accepted by ADK APIs, expressed as a Zod v3 type, a Zod v4 type, or * a genai `Schema`. * * Use `parseWithSchema` to validate a value against one, and `toJsonSchema` to * render one as a plain JSON Schema. */ export type SchemaLike = z3.ZodType | z4.ZodType | Schema; /** * Validates `value` against `schema`, returning the parsed value. * * Every schema form ADK accepts is enforced: * * - Zod v3/v4: runs `schema.parse(value)`. * - genai `Schema`: converted to JSON Schema and compiled to a Zod type once * (then cached), so a declaration written in the genai dialect is checked * just as a Zod one is. * - `undefined`: returns `value` unchanged. * * A genai `Schema` that has no Zod equivalent is left unenforced rather than * rejected — see {@link genaiSchemaValidator}. */ export declare function parseWithSchema(schema: SchemaLike | undefined, value: T): T; /** * Renders a {@link SchemaLike} as a plain JSON Schema object. * * Zod v3 and v4 schemas are converted with their respective serializers. A * genai `Schema` is translated out of the genai/OpenAPI dialect (uppercase * type names, stringified bounds, `nullable`) so that every schema form * produces the same JSON Schema shape for a consumer to read. */ export declare function toJsonSchema(schema: SchemaLike): Record; /** * Compiles a plain JSON Schema into a validator, for schemas that survive only * in serialized form — a `RequestInput.responseSchema` reaches the resume that * answers it as the JSON Schema recorded on the interrupt event, not as the * original {@link SchemaLike}. * * Returns `undefined` when the schema cannot be compiled (JSON Schema is wider * than Zod can express). Callers treat that as "no contract to check" rather * than failing: refusing data because we could not build the validator would be * worse than the unchecked pass-through this replaces. */ export declare function compileJsonSchema(jsonSchema: unknown): z4.ZodType | undefined; /** * Decomposes an object {@link SchemaLike} into its declared fields, each mapped * to a validator for that field alone. * * This is what lets a *partial* object be checked key by key. A state schema * declares the keys a workflow may write, but the state holds only the ones * written so far, so validating the whole object against the schema would * reject it for missing fields that simply have not been set yet. * * Returns `undefined` when the schema is not an object schema or cannot be * decomposed, and maps a field to `undefined` when that field's own schema has * no Zod equivalent. Both mean "unvalidatable" rather than invalid, consistent * with {@link parseWithSchema}. */ export declare function objectSchemaFields(schema: SchemaLike): Map | undefined;