/** * 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 { 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; /** 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: ["