/** * Shared output-schema validation for subagent yield + executor finalization. * * Both the in-process `yield` tool (subagent side) and the executor's post-mortem * finalize path (parent side) need to validate yield payloads against the agent's * declared output schema. This module is the single source of truth for that * pipeline — keeping the two callsites in lockstep so a schema accepted in-tool * cannot be rejected post-mortem (or vice versa). */ import { dereferenceJsonSchema, isValidJsonSchema, type JsonSchemaValidationIssue, type JsonSchemaValidationResult, validateJsonSchemaValue, } from "@oh-my-pi/pi-ai/utils/schema"; import { isRecord } from "@oh-my-pi/pi-utils"; import { LRUCache } from "@oh-my-pi/pi-utils/lru"; import { jtdToJsonSchema, normalizeSchema } from "./jtd-to-json-schema"; /** A validator bound to a specific output schema. */ export interface OutputValidator { /** Run JSON Schema validation; returns the raw `success`/`issues` shape so callers may inspect every failure. */ validate(value: unknown): JsonSchemaValidationResult; /** Treat strict-provider nulls for optional non-nullable properties as omitted before validation and delivery. */ normalize(value: unknown): unknown; /** Apply the same normalization to one incremental section (array sections carry one item). */ normalizeSection(label: string, value: unknown): unknown; /** Top-level required property names. Empty if the schema has no `required` array at root. */ readonly requiredFields: readonly string[]; /** * Per-label validators for incremental yields (`type: ["