{"version":3,"file":"validate.cjs","sources":["../../../src/schemas/validate.ts"],"sourcesContent":["// src/schemas/validate.ts\nimport { z } from 'zod';\nimport type * as t from '@/types';\nimport { Providers } from '@/common';\n\n/**\n * Validation result from structured output\n */\nexport interface ValidationResult<T = Record<string, unknown>> {\n  success: boolean;\n  data?: T;\n  error?: string;\n  raw?: unknown;\n}\n\n/**\n * Validates structured output against a JSON Schema.\n *\n * @param output - The output to validate\n * @param schema - JSON Schema to validate against\n * @returns Validation result with success flag and data or error\n */\nexport function validateStructuredOutput(\n  output: unknown,\n  schema: Record<string, unknown>\n): ValidationResult {\n  try {\n    // Parse output if it's a string\n    const data = typeof output === 'string' ? JSON.parse(output) : output;\n\n    // Basic JSON Schema validation\n    const errors = validateAgainstJsonSchema(data, schema);\n\n    if (errors.length > 0) {\n      return {\n        success: false,\n        error: `Validation failed: ${errors.join('; ')}`,\n        raw: data,\n      };\n    }\n\n    return {\n      success: true,\n      data: data as Record<string, unknown>,\n    };\n  } catch (e) {\n    return {\n      success: false,\n      error: `Failed to parse output: ${(e as Error).message}`,\n      raw: output,\n    };\n  }\n}\n\n/**\n * Validates data against a JSON Schema (simplified implementation).\n * For complex schemas, consider using ajv or similar library.\n */\nfunction validateAgainstJsonSchema(\n  data: unknown,\n  schema: Record<string, unknown>,\n  path = ''\n): string[] {\n  const errors: string[] = [];\n\n  if (schema.type === 'object' && typeof data !== 'object') {\n    errors.push(`${path || 'root'}: expected object, got ${typeof data}`);\n    return errors;\n  }\n\n  if (schema.type === 'array' && !Array.isArray(data)) {\n    errors.push(`${path || 'root'}: expected array, got ${typeof data}`);\n    return errors;\n  }\n\n  if (schema.type === 'string' && typeof data !== 'string') {\n    errors.push(`${path || 'root'}: expected string, got ${typeof data}`);\n    return errors;\n  }\n\n  if (schema.type === 'number' && typeof data !== 'number') {\n    errors.push(`${path || 'root'}: expected number, got ${typeof data}`);\n    return errors;\n  }\n\n  if (schema.type === 'boolean' && typeof data !== 'boolean') {\n    errors.push(`${path || 'root'}: expected boolean, got ${typeof data}`);\n    return errors;\n  }\n\n  // Validate required properties\n  if (\n    schema.type === 'object' &&\n    Array.isArray(schema.required) &&\n    typeof data === 'object' &&\n    data !== null\n  ) {\n    for (const requiredProp of schema.required as string[]) {\n      if (!(requiredProp in data)) {\n        errors.push(\n          `${path || 'root'}: missing required property '${requiredProp}'`\n        );\n      }\n    }\n  }\n\n  // Validate nested properties\n  if (\n    schema.type === 'object' &&\n    schema.properties &&\n    typeof data === 'object' &&\n    data !== null\n  ) {\n    const properties = schema.properties as Record<\n      string,\n      Record<string, unknown>\n    >;\n    for (const [key, propSchema] of Object.entries(properties)) {\n      if (key in data) {\n        const nestedErrors = validateAgainstJsonSchema(\n          (data as Record<string, unknown>)[key],\n          propSchema,\n          path ? `${path}.${key}` : key\n        );\n        errors.push(...nestedErrors);\n      }\n    }\n  }\n\n  // Validate array items\n  if (schema.type === 'array' && schema.items && Array.isArray(data)) {\n    const itemSchema = schema.items as Record<string, unknown>;\n    for (let i = 0; i < data.length; i++) {\n      const nestedErrors = validateAgainstJsonSchema(\n        data[i],\n        itemSchema,\n        `${path || 'root'}[${i}]`\n      );\n      errors.push(...nestedErrors);\n    }\n  }\n\n  // Validate enum values\n  if (schema.enum && Array.isArray(schema.enum)) {\n    if (!schema.enum.includes(data)) {\n      errors.push(\n        `${path || 'root'}: value '${data}' not in enum [${(schema.enum as unknown[]).join(', ')}]`\n      );\n    }\n  }\n\n  return errors;\n}\n\n/**\n * Converts a Zod schema to JSON Schema format.\n * This is a simplified converter for common types.\n */\nexport function zodToJsonSchema(zodSchema: z.ZodType): Record<string, unknown> {\n  // Use the zod-to-json-schema library if available\n  // For now, provide a basic implementation\n  try {\n    // eslint-disable-next-line @typescript-eslint/no-require-imports\n    const { zodToJsonSchema: convert } = require('zod-to-json-schema');\n    return convert(zodSchema) as Record<string, unknown>;\n  } catch {\n    // Fallback: return a generic object schema\n    return {\n      type: 'object',\n      additionalProperties: true,\n    };\n  }\n}\n\n/**\n * Creates a structured output error message for retry.\n */\nexport function createValidationErrorMessage(\n  result: ValidationResult,\n  customMessage?: string\n): string {\n  if (customMessage) {\n    return customMessage;\n  }\n\n  return `The response did not match the expected schema. Error: ${result.error}. Please try again and ensure your response exactly matches the required format.`;\n}\n\n/**\n * Checks if a value is a valid JSON Schema object.\n */\nexport function isValidJsonSchema(\n  value: unknown\n): value is Record<string, unknown> {\n  if (typeof value !== 'object' || value === null) {\n    return false;\n  }\n\n  const schema = value as Record<string, unknown>;\n\n  // Basic check: must have a type or properties\n  return (\n    typeof schema.type === 'string' ||\n    typeof schema.properties === 'object' ||\n    typeof schema.$schema === 'string'\n  );\n}\n\n/**\n * Normalizes a JSON Schema by adding defaults and cleaning up.\n */\nexport function normalizeJsonSchema(\n  schema: Record<string, unknown>,\n  config?: t.StructuredOutputConfig\n): Record<string, unknown> {\n  const normalized = { ...schema };\n\n  // Ensure type is set\n  if (!normalized.type && normalized.properties) {\n    normalized.type = 'object';\n  }\n\n  // Add title from config name\n  if (config?.name && !normalized.title) {\n    normalized.title = config.name;\n  }\n\n  // Add description from config\n  if (config?.description && !normalized.description) {\n    normalized.description = config.description;\n  }\n\n  // Enable additionalProperties: false for strict mode\n  if (config?.strict !== false && normalized.type === 'object') {\n    normalized.additionalProperties = normalized.additionalProperties ?? false;\n  }\n\n  return normalized;\n}\n\n/**\n * Keywords unsupported by native structured output providers.\n * These are stripped from schemas and moved to description fields when strict mode is enabled.\n */\nconst UNSUPPORTED_NUMERIC_KEYWORDS = ['minimum', 'maximum', 'exclusiveMinimum', 'exclusiveMaximum', 'multipleOf'] as const;\nconst UNSUPPORTED_STRING_KEYWORDS = ['minLength', 'maxLength', 'pattern', 'format'] as const;\nconst UNSUPPORTED_ARRAY_KEYWORDS = ['minItems', 'maxItems', 'uniqueItems'] as const;\nconst UNSUPPORTED_OBJECT_KEYWORDS = ['minProperties', 'maxProperties', 'patternProperties'] as const;\n\n/**\n * Result from schema preparation, includes the prepared schema and any warnings.\n */\nexport interface SchemaPreparationResult {\n  schema: Record<string, unknown>;\n  warnings: string[];\n}\n\n/**\n * Prepares a JSON Schema for a specific provider's native structured output API.\n *\n * This function normalizes the schema to comply with provider-specific requirements:\n * - Adds `additionalProperties: false` recursively to all objects (required by all providers in strict mode)\n * - Ensures all properties are listed in `required` (required by OpenAI and Anthropic)\n * - Strips unsupported constraint keywords (minimum, maxLength, etc.) and moves them to description\n * - Returns warnings for any modifications made\n *\n * @param schema - The original JSON Schema\n * @param provider - The LLM provider\n * @param strict - Whether strict mode is enabled (default: true)\n * @returns The prepared schema and any warnings\n */\nexport function prepareSchemaForProvider(\n  schema: Record<string, unknown>,\n  provider: Providers | string,\n  strict = true,\n): SchemaPreparationResult {\n  const warnings: string[] = [];\n\n  if (!strict) {\n    return { schema: { ...schema }, warnings };\n  }\n\n  const prepared = prepareObjectRecursive(schema, '', provider, warnings);\n  return { schema: prepared, warnings };\n}\n\n/**\n * Recursively prepares a schema node for native structured output.\n */\nfunction prepareObjectRecursive(\n  schema: Record<string, unknown>,\n  path: string,\n  provider: Providers | string,\n  warnings: string[],\n  depth = 0,\n): Record<string, unknown> {\n  const result = { ...schema };\n  const currentPath = path || 'root';\n\n  // Warn on deep nesting (OpenAI limit is 5)\n  if (depth > 5 && (provider === Providers.OPENAI || provider === Providers.AZURE)) {\n    warnings.push(`${currentPath}: nesting depth ${depth} exceeds OpenAI's limit of 5 levels`);\n  }\n\n  // Handle object type\n  if (result.type === 'object' || (result.properties && !result.type)) {\n    if (!result.type) {\n      result.type = 'object';\n    }\n\n    // Add additionalProperties: false\n    if (result.additionalProperties !== false) {\n      result.additionalProperties = false;\n      if (path) {\n        warnings.push(`${currentPath}: set additionalProperties to false for strict mode`);\n      }\n    }\n\n    // Ensure all properties are in required\n    if (result.properties && typeof result.properties === 'object') {\n      const properties = result.properties as Record<string, Record<string, unknown>>;\n      const propertyNames = Object.keys(properties);\n      const currentRequired = Array.isArray(result.required) ? result.required as string[] : [];\n      const missingRequired = propertyNames.filter(name => !currentRequired.includes(name));\n\n      if (missingRequired.length > 0) {\n        result.required = [...currentRequired, ...missingRequired];\n        warnings.push(`${currentPath}: added ${missingRequired.join(', ')} to required (all properties must be required for strict mode; use type union with null for optional fields)`);\n      }\n\n      // Recursively prepare nested properties\n      const preparedProperties: Record<string, Record<string, unknown>> = {};\n      for (const [key, propSchema] of Object.entries(properties)) {\n        preparedProperties[key] = preparePropertySchema(\n          propSchema,\n          path ? `${path}.${key}` : key,\n          provider,\n          warnings,\n          depth + 1,\n        );\n      }\n      result.properties = preparedProperties;\n    }\n  }\n\n  // Handle array type\n  if (result.type === 'array' && result.items && typeof result.items === 'object') {\n    result.items = preparePropertySchema(\n      result.items as Record<string, unknown>,\n      `${currentPath}[]`,\n      provider,\n      warnings,\n      depth + 1,\n    );\n\n    // Strip unsupported array keywords\n    for (const keyword of UNSUPPORTED_ARRAY_KEYWORDS) {\n      if (keyword in result) {\n        appendToDescription(result, `${keyword}: ${result[keyword]}`);\n        delete result[keyword];\n        warnings.push(`${currentPath}: moved unsupported keyword '${keyword}' to description`);\n      }\n    }\n  }\n\n  // Handle anyOf\n  if (Array.isArray(result.anyOf)) {\n    result.anyOf = (result.anyOf as Record<string, unknown>[]).map((variant, i) =>\n      preparePropertySchema(variant, `${currentPath}.anyOf[${i}]`, provider, warnings, depth + 1)\n    );\n  }\n\n  // Handle $defs / definitions\n  for (const defsKey of ['$defs', 'definitions']) {\n    if (result[defsKey] && typeof result[defsKey] === 'object') {\n      const defs = result[defsKey] as Record<string, Record<string, unknown>>;\n      const preparedDefs: Record<string, Record<string, unknown>> = {};\n      for (const [key, defSchema] of Object.entries(defs)) {\n        preparedDefs[key] = preparePropertySchema(\n          defSchema,\n          `${defsKey}.${key}`,\n          provider,\n          warnings,\n          depth,\n        );\n      }\n      result[defsKey] = preparedDefs;\n    }\n  }\n\n  return result;\n}\n\n/**\n * Prepares a single property schema, stripping unsupported keywords based on type.\n */\nfunction preparePropertySchema(\n  schema: Record<string, unknown>,\n  path: string,\n  provider: Providers | string,\n  warnings: string[],\n  depth: number,\n): Record<string, unknown> {\n  const result = { ...schema };\n\n  // Strip unsupported numeric keywords\n  if (result.type === 'number' || result.type === 'integer') {\n    for (const keyword of UNSUPPORTED_NUMERIC_KEYWORDS) {\n      if (keyword in result) {\n        appendToDescription(result, `${keyword}: ${result[keyword]}`);\n        delete result[keyword];\n        warnings.push(`${path}: moved unsupported keyword '${keyword}' to description`);\n      }\n    }\n  }\n\n  // Strip unsupported string keywords\n  if (result.type === 'string') {\n    for (const keyword of UNSUPPORTED_STRING_KEYWORDS) {\n      if (keyword in result) {\n        appendToDescription(result, `${keyword}: ${result[keyword]}`);\n        delete result[keyword];\n        warnings.push(`${path}: moved unsupported keyword '${keyword}' to description`);\n      }\n    }\n  }\n\n  // Strip unsupported object keywords\n  if (result.type === 'object') {\n    for (const keyword of UNSUPPORTED_OBJECT_KEYWORDS) {\n      if (keyword in result) {\n        appendToDescription(result, `${keyword}: ${result[keyword]}`);\n        delete result[keyword];\n        warnings.push(`${path}: moved unsupported keyword '${keyword}' to description`);\n      }\n    }\n  }\n\n  // Recursively handle nested objects and arrays\n  if (result.type === 'object' || result.properties || result.type === 'array' || result.anyOf || result.$defs || result.definitions) {\n    return prepareObjectRecursive(result, path, provider, warnings, depth);\n  }\n\n  return result;\n}\n\n/**\n * Appends a constraint description to the schema's description field.\n */\nfunction appendToDescription(schema: Record<string, unknown>, constraint: string): void {\n  const existing = typeof schema.description === 'string' ? schema.description : '';\n  const constraintNote = `[Constraint: ${constraint}]`;\n  schema.description = existing ? `${existing} ${constraintNote}` : constraintNote;\n}\n"],"names":["Providers"],"mappings":";;;;;AAeA;;;;;;AAMG;AACG,SAAU,wBAAwB,CACtC,MAAe,EACf,MAA+B,EAAA;AAE/B,IAAA,IAAI;;AAEF,QAAA,MAAM,IAAI,GAAG,OAAO,MAAM,KAAK,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,MAAM;;QAGrE,M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