@songtonyli/dsh-cli 0.1.56 → 0.1.57
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/bin/dsh.mjs +1 -1
- package/node_modules/@aws-sdk/{credential-provider-sso → client-bedrock-runtime}/node_modules/@aws-sdk/token-providers/package.json +6 -6
- package/node_modules/@aws-sdk/token-providers/package.json +6 -6
- package/node_modules/@deepseek-ai/dsh-client-ui-primitives/package.json +2 -2
- package/node_modules/@deepseek-ai/dsh-client-ui-sidebar/lib/client.js +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-slots/package.json +2 -2
- package/node_modules/@deepseek-ai/dsh-llm-pi-ai/README.i18n.yaml +2 -2
- package/node_modules/@deepseek-ai/dsh-llm-pi-ai/README.md +1 -1
- package/node_modules/@deepseek-ai/dsh-llm-pi-ai/README.zh.md +1 -1
- package/node_modules/@deepseek-ai/dsh-llm-pi-ai/lib/index.js +1 -182
- package/node_modules/@deepseek-ai/dsh-llm-pi-ai/package.json +1 -1
- package/node_modules/@deepseek-ai/dsh-tui-app/lib/index.js +1 -1
- package/node_modules/@earendil-works/pi-ai/README.md +207 -27
- package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js +6 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/azure-openai-responses.js +6 -5
- package/node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.js +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/cloudflare-workers-ai-system-one.js +43 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/cloudflare-workers-ai-system-one.lazy.js +4 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/cloudflare.js +2 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/google-generative-ai.js +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/google-vertex.js +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/llama-cpp-classify.js +365 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/llama-cpp-classify.lazy.js +4 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/mistral-conversations.js +18 -17
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.js +20 -4
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.js +4 -4
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses-shared.js +14 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses.js +26 -9
- package/node_modules/@earendil-works/pi-ai/dist/api/openrouter-images.js +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/pi-messages.js +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/simple-options.js +2 -4
- package/node_modules/@earendil-works/pi-ai/dist/api/system-one-shared.js +183 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/typesafe-system-one.js +19 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/typesafe-system-one.lazy.js +4 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/helpers.js +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/anthropic.js +19 -128
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/callback-server.js +146 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/load.js +5 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/openai-chatgpt.js +266 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/openai-codex.js +20 -124
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/openrouter.js +19 -138
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/radius.js +21 -89
- package/node_modules/@earendil-works/pi-ai/dist/auth/resolve.js +3 -19
- package/node_modules/@earendil-works/pi-ai/dist/bun-oauth.js +2 -0
- package/node_modules/@earendil-works/pi-ai/dist/cli.js +3 -1
- package/node_modules/@earendil-works/pi-ai/dist/env-api-keys.js +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/image-models.js +14 -13
- package/node_modules/@earendil-works/pi-ai/dist/images.js +5 -0
- package/node_modules/@earendil-works/pi-ai/dist/index.js +0 -1
- package/node_modules/@earendil-works/pi-ai/dist/model-catalog.js +14 -2
- package/node_modules/@earendil-works/pi-ai/dist/models.generated.js +131 -41
- package/node_modules/@earendil-works/pi-ai/dist/models.js +157 -30
- package/node_modules/@earendil-works/pi-ai/dist/providers/all.js +25 -21
- package/node_modules/@earendil-works/pi-ai/dist/providers/amazon-bedrock.models.js +4 -2
- package/node_modules/@earendil-works/pi-ai/dist/providers/ant-ling.models.js +4 -2
- package/node_modules/@earendil-works/pi-ai/dist/providers/anthropic.models.js +4 -2
- package/node_modules/@earendil-works/pi-ai/dist/providers/azure-openai-responses.models.js +4 -2
- package/node_modules/@earendil-works/pi-ai/dist/providers/baseten.models.js +4 -2
- package/node_modules/@earendil-works/pi-ai/dist/providers/cerebras.models.js +4 -2
- package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-ai-gateway.models.js +4 -2
- package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-stream.js +6 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-workers-ai.js +10 -3
- package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-workers-ai.models.js +4 -2
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/amazon-bedrock.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/ant-ling.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/anthropic.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/azure-openai-responses.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/baseten.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/cerebras.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/cloudflare-ai-gateway.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/cloudflare-workers-ai.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/deepseek.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/fireworks.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/github-copilot.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/google-vertex.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/google.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/groq.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/huggingface.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/kimi-coding.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/meta.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/minimax-cn.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/minimax.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/mistral.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/moonshotai-cn.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/moonshotai.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/nvidia.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/openai-codex.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/openai.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode-go.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan-cn.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan-individual.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/radius.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/together.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/typesafe.json +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/xai.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi-token-plan-ams.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi-token-plan-cn.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi-token-plan-sgp.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/zai-coding-cn.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/zai.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/deepseek.models.js +4 -2
- package/node_modules/@earendil-works/pi-ai/dist/providers/fireworks.models.js +4 -2
- package/node_modules/@earendil-works/pi-ai/dist/providers/github-copilot.models.js +4 -2
- package/node_modules/@earendil-works/pi-ai/dist/providers/google-vertex.models.js +4 -2
- package/node_modules/@earendil-works/pi-ai/dist/providers/google.models.js +4 -2
- package/node_modules/@earendil-works/pi-ai/dist/providers/groq.models.js +4 -2
- package/node_modules/@earendil-works/pi-ai/dist/providers/huggingface.models.js +4 -2
- package/node_modules/@earendil-works/pi-ai/dist/providers/kimi-coding.models.js +4 -2
- package/node_modules/@earendil-works/pi-ai/dist/providers/meta.models.js +4 -2
- package/node_modules/@earendil-works/pi-ai/dist/providers/minimax-cn.models.js +4 -2
- package/node_modules/@earendil-works/pi-ai/dist/providers/minimax.models.js +4 -2
- package/node_modules/@earendil-works/pi-ai/dist/providers/mistral.models.js +4 -2
- package/node_modules/@earendil-works/pi-ai/dist/providers/moonshotai-cn.models.js +4 -2
- package/node_modules/@earendil-works/pi-ai/dist/providers/moonshotai.models.js +4 -2
- package/node_modules/@earendil-works/pi-ai/dist/providers/nvidia.models.js +4 -2
- package/node_modules/@earendil-works/pi-ai/dist/providers/openai-codex.js +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/openai-codex.models.js +4 -2
- package/node_modules/@earendil-works/pi-ai/dist/providers/openai.js +11 -2
- package/node_modules/@earendil-works/pi-ai/dist/providers/openai.models.js +4 -2
- package/node_modules/@earendil-works/pi-ai/dist/providers/opencode-go.models.js +4 -2
- package/node_modules/@earendil-works/pi-ai/dist/providers/opencode.js +5 -2
- package/node_modules/@earendil-works/pi-ai/dist/providers/opencode.models.js +4 -2
- package/node_modules/@earendil-works/pi-ai/dist/providers/openrouter.js +11 -2
- package/node_modules/@earendil-works/pi-ai/dist/providers/openrouter.models.js +4 -2
- package/node_modules/@earendil-works/pi-ai/dist/providers/qwen-token-plan-cn.models.js +4 -2
- package/node_modules/@earendil-works/pi-ai/dist/providers/qwen-token-plan-individual.models.js +4 -2
- package/node_modules/@earendil-works/pi-ai/dist/providers/qwen-token-plan.models.js +4 -2
- package/node_modules/@earendil-works/pi-ai/dist/providers/radius.models.js +4 -2
- package/node_modules/@earendil-works/pi-ai/dist/providers/together.models.js +4 -2
- package/node_modules/@earendil-works/pi-ai/dist/providers/typesafe.js +18 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/typesafe.models.js +8 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/vercel-ai-gateway.js +5 -2
- package/node_modules/@earendil-works/pi-ai/dist/providers/vercel-ai-gateway.models.js +4 -2
- package/node_modules/@earendil-works/pi-ai/dist/providers/xai.models.js +4 -2
- package/node_modules/@earendil-works/pi-ai/dist/providers/xiaomi-token-plan-ams.models.js +4 -2
- package/node_modules/@earendil-works/pi-ai/dist/providers/xiaomi-token-plan-cn.models.js +4 -2
- package/node_modules/@earendil-works/pi-ai/dist/providers/xiaomi-token-plan-sgp.models.js +4 -2
- package/node_modules/@earendil-works/pi-ai/dist/providers/xiaomi.models.js +4 -2
- package/node_modules/@earendil-works/pi-ai/dist/providers/zai-coding-cn.models.js +4 -2
- package/node_modules/@earendil-works/pi-ai/dist/providers/zai.models.js +4 -2
- package/node_modules/@earendil-works/pi-ai/dist/utils/headers.js +10 -8
- package/node_modules/@earendil-works/pi-ai/dist/utils/model-operations.js +47 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/models-error.js +19 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry.js +7 -0
- package/node_modules/@earendil-works/pi-ai/package.json +4 -4
- package/node_modules/@earendil-works/pi-telemetry/package.json +2 -2
- package/node_modules/openai/CHANGELOG.md +1089 -1
- package/node_modules/openai/README.md +201 -102
- package/node_modules/openai/_vendor/partial-json-parser/parser.js +55 -38
- package/node_modules/openai/_vendor/partial-json-parser/parser.mjs +55 -38
- package/node_modules/openai/_vendor/zod-to-json-schema/Options.js +11 -2
- package/node_modules/openai/_vendor/zod-to-json-schema/Options.mjs +11 -2
- package/node_modules/openai/_vendor/zod-to-json-schema/Refs.js +4 -4
- package/node_modules/openai/_vendor/zod-to-json-schema/Refs.mjs +4 -4
- package/node_modules/openai/_vendor/zod-to-json-schema/errorMessages.js +2 -1
- package/node_modules/openai/_vendor/zod-to-json-schema/errorMessages.mjs +2 -1
- package/node_modules/openai/_vendor/zod-to-json-schema/index.js +1 -1
- package/node_modules/openai/_vendor/zod-to-json-schema/index.mjs +1 -1
- package/node_modules/openai/_vendor/zod-to-json-schema/parseDef.js +139 -54
- package/node_modules/openai/_vendor/zod-to-json-schema/parseDef.mjs +139 -54
- package/node_modules/openai/_vendor/zod-to-json-schema/parsers/array.js +1 -1
- package/node_modules/openai/_vendor/zod-to-json-schema/parsers/array.mjs +1 -1
- package/node_modules/openai/_vendor/zod-to-json-schema/parsers/bigint.js +10 -4
- package/node_modules/openai/_vendor/zod-to-json-schema/parsers/bigint.mjs +10 -4
- package/node_modules/openai/_vendor/zod-to-json-schema/parsers/branded.js +2 -2
- package/node_modules/openai/_vendor/zod-to-json-schema/parsers/branded.mjs +2 -2
- package/node_modules/openai/_vendor/zod-to-json-schema/parsers/catch.js +1 -3
- package/node_modules/openai/_vendor/zod-to-json-schema/parsers/catch.mjs +1 -3
- package/node_modules/openai/_vendor/zod-to-json-schema/parsers/date.js +10 -5
- package/node_modules/openai/_vendor/zod-to-json-schema/parsers/date.mjs +10 -5
- package/node_modules/openai/_vendor/zod-to-json-schema/parsers/default.js +2 -2
- package/node_modules/openai/_vendor/zod-to-json-schema/parsers/default.mjs +2 -2
- package/node_modules/openai/_vendor/zod-to-json-schema/parsers/intersection.js +6 -5
- package/node_modules/openai/_vendor/zod-to-json-schema/parsers/intersection.mjs +6 -5
- package/node_modules/openai/_vendor/zod-to-json-schema/parsers/literal.js +5 -0
- package/node_modules/openai/_vendor/zod-to-json-schema/parsers/literal.mjs +5 -0
- package/node_modules/openai/_vendor/zod-to-json-schema/parsers/nativeEnum.js +7 -9
- package/node_modules/openai/_vendor/zod-to-json-schema/parsers/nativeEnum.mjs +7 -9
- package/node_modules/openai/_vendor/zod-to-json-schema/parsers/null.js +3 -2
- package/node_modules/openai/_vendor/zod-to-json-schema/parsers/null.mjs +3 -2
- package/node_modules/openai/_vendor/zod-to-json-schema/parsers/nullable.js +8 -3
- package/node_modules/openai/_vendor/zod-to-json-schema/parsers/nullable.mjs +8 -3
- package/node_modules/openai/_vendor/zod-to-json-schema/parsers/number.js +12 -5
- package/node_modules/openai/_vendor/zod-to-json-schema/parsers/number.mjs +12 -5
- package/node_modules/openai/_vendor/zod-to-json-schema/parsers/object.js +43 -38
- package/node_modules/openai/_vendor/zod-to-json-schema/parsers/object.mjs +43 -38
- package/node_modules/openai/_vendor/zod-to-json-schema/parsers/optional.js +11 -12
- package/node_modules/openai/_vendor/zod-to-json-schema/parsers/optional.mjs +11 -12
- package/node_modules/openai/_vendor/zod-to-json-schema/parsers/pipeline.js +3 -3
- package/node_modules/openai/_vendor/zod-to-json-schema/parsers/pipeline.mjs +3 -3
- package/node_modules/openai/_vendor/zod-to-json-schema/parsers/promise.js +2 -2
- package/node_modules/openai/_vendor/zod-to-json-schema/parsers/promise.mjs +2 -2
- package/node_modules/openai/_vendor/zod-to-json-schema/parsers/readonly.js +1 -3
- package/node_modules/openai/_vendor/zod-to-json-schema/parsers/readonly.mjs +1 -3
- package/node_modules/openai/_vendor/zod-to-json-schema/parsers/record.js +7 -5
- package/node_modules/openai/_vendor/zod-to-json-schema/parsers/record.mjs +7 -5
- package/node_modules/openai/_vendor/zod-to-json-schema/parsers/string.js +57 -34
- package/node_modules/openai/_vendor/zod-to-json-schema/parsers/string.mjs +57 -34
- package/node_modules/openai/_vendor/zod-to-json-schema/parsers/tuple.js +24 -19
- package/node_modules/openai/_vendor/zod-to-json-schema/parsers/tuple.mjs +24 -19
- package/node_modules/openai/_vendor/zod-to-json-schema/parsers/union.js +46 -24
- package/node_modules/openai/_vendor/zod-to-json-schema/parsers/union.mjs +46 -24
- package/node_modules/openai/_vendor/zod-to-json-schema/util.js +7 -5
- package/node_modules/openai/_vendor/zod-to-json-schema/util.mjs +7 -5
- package/node_modules/openai/_vendor/zod-to-json-schema/zodToJsonSchema.js +110 -38
- package/node_modules/openai/_vendor/zod-to-json-schema/zodToJsonSchema.mjs +110 -38
- package/node_modules/openai/auth/subject-token-providers.js +235 -10
- package/node_modules/openai/auth/subject-token-providers.mjs +235 -10
- package/node_modules/openai/auth/workload-identity-auth.js +185 -24
- package/node_modules/openai/auth/workload-identity-auth.mjs +186 -25
- package/node_modules/openai/auth/x509-transport.js +273 -0
- package/node_modules/openai/auth/x509-transport.mjs +268 -0
- package/node_modules/openai/azure.js +74 -21
- package/node_modules/openai/azure.mjs +75 -22
- package/node_modules/openai/bedrock.js +174 -0
- package/node_modules/openai/bedrock.mjs +169 -0
- package/node_modules/openai/beta/realtime/internal-base.js +71 -10
- package/node_modules/openai/beta/realtime/internal-base.mjs +70 -10
- package/node_modules/openai/beta/realtime/websocket.js +180 -33
- package/node_modules/openai/beta/realtime/websocket.mjs +181 -34
- package/node_modules/openai/beta/realtime/ws.js +93 -14
- package/node_modules/openai/beta/realtime/ws.mjs +94 -15
- package/node_modules/openai/client.js +745 -99
- package/node_modules/openai/client.mjs +747 -101
- package/node_modules/openai/core/EventEmitter.js +127 -16
- package/node_modules/openai/core/EventEmitter.mjs +128 -17
- package/node_modules/openai/core/api-promise.js +0 -1
- package/node_modules/openai/core/api-promise.mjs +0 -1
- package/node_modules/openai/core/error.js +5 -5
- package/node_modules/openai/core/error.mjs +5 -5
- package/node_modules/openai/core/pagination.js +33 -3
- package/node_modules/openai/core/pagination.mjs +31 -2
- package/node_modules/openai/core/resource.js +0 -1
- package/node_modules/openai/core/resource.mjs +0 -1
- package/node_modules/openai/core/streaming.js +453 -88
- package/node_modules/openai/core/streaming.mjs +454 -89
- package/node_modules/openai/core/uploads.js +3 -1
- package/node_modules/openai/core/uploads.mjs +1 -0
- package/node_modules/openai/helpers/audio.js +198 -28
- package/node_modules/openai/helpers/audio.mjs +199 -29
- package/node_modules/openai/helpers/live.js +6 -0
- package/node_modules/openai/helpers/live.mjs +2 -0
- package/node_modules/openai/helpers/standard-schema.js +393 -0
- package/node_modules/openai/helpers/standard-schema.mjs +387 -0
- package/node_modules/openai/helpers/zod-v3-strict-schema.js +408 -0
- package/node_modules/openai/helpers/zod-v3-strict-schema.mjs +404 -0
- package/node_modules/openai/helpers/zod.js +221 -24
- package/node_modules/openai/helpers/zod.mjs +222 -26
- package/node_modules/openai/index.js +8 -7
- package/node_modules/openai/index.mjs +2 -2
- package/node_modules/openai/internal/assistant-stream-delta.js +316 -0
- package/node_modules/openai/internal/assistant-stream-delta.mjs +308 -0
- package/node_modules/openai/internal/auth/x509-api-origin.js +28 -0
- package/node_modules/openai/internal/auth/x509-api-origin.mjs +24 -0
- package/node_modules/openai/internal/auth/x509-credential-options.js +125 -0
- package/node_modules/openai/internal/auth/x509-credential-options.mjs +121 -0
- package/node_modules/openai/internal/auth/x509-token-exchange.js +248 -0
- package/node_modules/openai/internal/auth/x509-token-exchange.mjs +245 -0
- package/node_modules/openai/internal/auth/x509-transport-capability.js +171 -0
- package/node_modules/openai/internal/auth/x509-transport-capability.mjs +166 -0
- package/node_modules/openai/internal/auth/x509-transport-registry.js +53 -0
- package/node_modules/openai/internal/auth/x509-transport-registry.mjs +48 -0
- package/node_modules/openai/internal/auth/x509-transport-state-browser.js +35 -0
- package/node_modules/openai/internal/auth/x509-transport-state-browser.mjs +32 -0
- package/node_modules/openai/internal/auth/x509-transport-state.cjs +35 -0
- package/node_modules/openai/internal/auth/x509-transport-state.js +36 -0
- package/node_modules/openai/internal/auth/x509-transport-state.mjs +20 -0
- package/node_modules/openai/internal/auth/x509-workload-identity-auth.js +787 -0
- package/node_modules/openai/internal/auth/x509-workload-identity-auth.mjs +778 -0
- package/node_modules/openai/internal/bedrock.js +438 -0
- package/node_modules/openai/internal/bedrock.mjs +424 -0
- package/node_modules/openai/internal/builtin-types.js +0 -1
- package/node_modules/openai/internal/builtin-types.mjs +0 -1
- package/node_modules/openai/internal/data-residency.js +34 -0
- package/node_modules/openai/internal/data-residency.mjs +30 -0
- package/node_modules/openai/internal/decoders/line.js +140 -54
- package/node_modules/openai/internal/decoders/line.mjs +141 -55
- package/node_modules/openai/internal/detect-platform.js +3 -4
- package/node_modules/openai/internal/detect-platform.mjs +3 -4
- package/node_modules/openai/internal/errors.js +3 -3
- package/node_modules/openai/internal/errors.mjs +3 -3
- package/node_modules/openai/internal/headers.js +11 -9
- package/node_modules/openai/internal/headers.mjs +11 -9
- package/node_modules/openai/internal/multipart-encoding.js +51 -0
- package/node_modules/openai/internal/multipart-encoding.mjs +48 -0
- package/node_modules/openai/internal/parse.js +35 -11
- package/node_modules/openai/internal/parse.mjs +35 -11
- package/node_modules/openai/internal/provider.js +50 -0
- package/node_modules/openai/internal/provider.mjs +46 -0
- package/node_modules/openai/internal/qs/formats.js +1 -2
- package/node_modules/openai/internal/qs/formats.mjs +1 -1
- package/node_modules/openai/internal/qs/stringify.js +60 -51
- package/node_modules/openai/internal/qs/stringify.mjs +60 -51
- package/node_modules/openai/internal/qs/utils.js +368 -50
- package/node_modules/openai/internal/qs/utils.mjs +368 -50
- package/node_modules/openai/internal/realtime-credentials.js +23 -0
- package/node_modules/openai/internal/realtime-credentials.mjs +19 -0
- package/node_modules/openai/internal/request-options.js +43 -2
- package/node_modules/openai/internal/request-options.mjs +42 -2
- package/node_modules/openai/internal/responses/canonical-output-text.js +123 -0
- package/node_modules/openai/internal/responses/canonical-output-text.mjs +115 -0
- package/node_modules/openai/internal/responses/output-text-index.js +77 -0
- package/node_modules/openai/internal/responses/output-text-index.mjs +73 -0
- package/node_modules/openai/internal/responses/response-accumulator.js +942 -0
- package/node_modules/openai/internal/responses/response-accumulator.mjs +938 -0
- package/node_modules/openai/internal/shim-types.js +6 -1
- package/node_modules/openai/internal/shim-types.mjs +6 -1
- package/node_modules/openai/internal/shims.js +6 -1
- package/node_modules/openai/internal/shims.mjs +6 -1
- package/node_modules/openai/internal/stream-utils.js +35 -7
- package/node_modules/openai/internal/stream-utils.mjs +35 -7
- package/node_modules/openai/internal/to-file.js +47 -24
- package/node_modules/openai/internal/to-file.mjs +47 -24
- package/node_modules/openai/internal/tslib.js +6 -0
- package/node_modules/openai/internal/tslib.mjs +6 -1
- package/node_modules/openai/internal/types.js +0 -1
- package/node_modules/openai/internal/types.mjs +0 -1
- package/node_modules/openai/internal/uploads.js +377 -43
- package/node_modules/openai/internal/uploads.mjs +376 -44
- package/node_modules/openai/internal/utils/abort.js +94 -0
- package/node_modules/openai/internal/utils/abort.mjs +90 -0
- package/node_modules/openai/internal/utils/base64.js +3 -1
- package/node_modules/openai/internal/utils/base64.mjs +3 -1
- package/node_modules/openai/internal/utils/bytes.js +5 -0
- package/node_modules/openai/internal/utils/bytes.mjs +5 -0
- package/node_modules/openai/internal/utils/env.js +9 -5
- package/node_modules/openai/internal/utils/env.mjs +9 -5
- package/node_modules/openai/internal/utils/log.js +73 -11
- package/node_modules/openai/internal/utils/log.mjs +70 -11
- package/node_modules/openai/internal/utils/path.js +50 -30
- package/node_modules/openai/internal/utils/path.mjs +50 -30
- package/node_modules/openai/internal/utils/query.js +0 -1
- package/node_modules/openai/internal/utils/query.mjs +0 -1
- package/node_modules/openai/internal/utils/sleep.js +51 -2
- package/node_modules/openai/internal/utils/sleep.mjs +51 -2
- package/node_modules/openai/internal/utils/uuid.js +0 -1
- package/node_modules/openai/internal/utils/uuid.mjs +0 -1
- package/node_modules/openai/internal/utils/values.js +0 -1
- package/node_modules/openai/internal/utils/values.mjs +0 -1
- package/node_modules/openai/internal/utils.js +0 -1
- package/node_modules/openai/internal/utils.mjs +0 -1
- package/node_modules/openai/internal/ws-adapter-browser.js +66 -21
- package/node_modules/openai/internal/ws-adapter-browser.mjs +66 -21
- package/node_modules/openai/internal/ws-adapter-node.js +90 -24
- package/node_modules/openai/internal/ws-adapter-node.mjs +90 -24
- package/node_modules/openai/internal/ws-adapter.js +4 -0
- package/node_modules/openai/internal/ws-adapter.mjs +4 -0
- package/node_modules/openai/internal/ws.js +193 -48
- package/node_modules/openai/internal/ws.mjs +188 -49
- package/node_modules/openai/lib/AbstractChatCompletionRunner.js +254 -72
- package/node_modules/openai/lib/AbstractChatCompletionRunner.mjs +256 -74
- package/node_modules/openai/lib/AssistantStream.js +430 -259
- package/node_modules/openai/lib/AssistantStream.mjs +432 -261
- package/node_modules/openai/lib/ChatCompletionRunner.js +12 -5
- package/node_modules/openai/lib/ChatCompletionRunner.mjs +13 -6
- package/node_modules/openai/lib/ChatCompletionStream.js +1430 -189
- package/node_modules/openai/lib/ChatCompletionStream.mjs +1433 -193
- package/node_modules/openai/lib/ChatCompletionStreamingRunner.js +40 -2
- package/node_modules/openai/lib/ChatCompletionStreamingRunner.mjs +41 -3
- package/node_modules/openai/lib/EventEmitter.js +124 -16
- package/node_modules/openai/lib/EventEmitter.mjs +125 -17
- package/node_modules/openai/lib/EventStream.js +1533 -55
- package/node_modules/openai/lib/EventStream.mjs +1534 -56
- package/node_modules/openai/lib/ResponsesParser.js +68 -29
- package/node_modules/openai/lib/ResponsesParser.mjs +69 -30
- package/node_modules/openai/lib/RunnableFunction.js +3 -0
- package/node_modules/openai/lib/RunnableFunction.mjs +3 -0
- package/node_modules/openai/lib/Util.js +7 -4
- package/node_modules/openai/lib/Util.mjs +7 -4
- package/node_modules/openai/lib/agents/agent-session-stream.js +274 -0
- package/node_modules/openai/lib/agents/agent-session-stream.mjs +270 -0
- package/node_modules/openai/lib/agents/output-text.js +8 -0
- package/node_modules/openai/lib/agents/output-text.mjs +5 -0
- package/node_modules/openai/lib/agents/turn-state.js +62 -0
- package/node_modules/openai/lib/agents/turn-state.mjs +58 -0
- package/node_modules/openai/lib/assistant-run-polling.js +17 -0
- package/node_modules/openai/lib/assistant-run-polling.mjs +14 -0
- package/node_modules/openai/lib/chatCompletionUtils.js +5 -6
- package/node_modules/openai/lib/chatCompletionUtils.mjs +5 -6
- package/node_modules/openai/lib/embeddings.js +58 -0
- package/node_modules/openai/lib/embeddings.mjs +55 -0
- package/node_modules/openai/lib/file-processing.js +31 -0
- package/node_modules/openai/lib/file-processing.mjs +28 -0
- package/node_modules/openai/lib/live/transcript-grouper.js +229 -0
- package/node_modules/openai/lib/live/transcript-grouper.mjs +225 -0
- package/node_modules/openai/lib/live/transcript-grouping.js +309 -0
- package/node_modules/openai/lib/live/transcript-grouping.mjs +305 -0
- package/node_modules/openai/lib/live/webrtc.js +16 -0
- package/node_modules/openai/lib/live/webrtc.mjs +10 -0
- package/node_modules/openai/lib/parser.js +142 -42
- package/node_modules/openai/lib/parser.mjs +140 -42
- package/node_modules/openai/lib/polling.js +131 -0
- package/node_modules/openai/lib/polling.mjs +128 -0
- package/node_modules/openai/lib/realtime/webrtc.js +16 -0
- package/node_modules/openai/lib/realtime/webrtc.mjs +10 -0
- package/node_modules/openai/lib/responses/ResponseAccumulator.js +15 -0
- package/node_modules/openai/lib/responses/ResponseAccumulator.mjs +12 -0
- package/node_modules/openai/lib/responses/ResponseInputItems.js +139 -0
- package/node_modules/openai/lib/responses/ResponseInputItems.mjs +135 -0
- package/node_modules/openai/lib/responses/ResponseStream.js +85 -159
- package/node_modules/openai/lib/responses/ResponseStream.mjs +86 -160
- package/node_modules/openai/lib/responses/responses-websocket-lane.js +314 -0
- package/node_modules/openai/lib/responses/responses-websocket-lane.mjs +309 -0
- package/node_modules/openai/lib/responses/responses-websocket-session.js +268 -0
- package/node_modules/openai/lib/responses/responses-websocket-session.mjs +263 -0
- package/node_modules/openai/lib/transform.js +1608 -82
- package/node_modules/openai/lib/transform.mjs +1602 -82
- package/node_modules/openai/lib/vector-store-polling.js +24 -0
- package/node_modules/openai/lib/vector-store-polling.mjs +20 -0
- package/node_modules/openai/lib/vector-store-upload.js +41 -0
- package/node_modules/openai/lib/vector-store-upload.mjs +38 -0
- package/node_modules/openai/lib/webhook-signature.js +125 -0
- package/node_modules/openai/lib/webhook-signature.mjs +121 -0
- package/node_modules/openai/lib/webrtc/connection.js +233 -0
- package/node_modules/openai/lib/webrtc/connection.mjs +229 -0
- package/node_modules/openai/lib/webrtc/data-channel.js +133 -0
- package/node_modules/openai/lib/webrtc/data-channel.mjs +129 -0
- package/node_modules/openai/lib/webrtc/errors.js +18 -0
- package/node_modules/openai/lib/webrtc/errors.mjs +14 -0
- package/node_modules/openai/lib/webrtc/subscriptions.js +64 -0
- package/node_modules/openai/lib/webrtc/subscriptions.mjs +60 -0
- package/node_modules/openai/lib/webrtc/types.js +3 -0
- package/node_modules/openai/lib/webrtc/types.mjs +2 -0
- package/node_modules/openai/live/webrtc.js +8 -0
- package/node_modules/openai/live/webrtc.mjs +2 -0
- package/node_modules/openai/package.json +71 -11
- package/node_modules/openai/providers/bedrock/aws.js +211 -0
- package/node_modules/openai/providers/bedrock/aws.mjs +207 -0
- package/node_modules/openai/providers/bedrock.js +43 -0
- package/node_modules/openai/providers/bedrock.mjs +39 -0
- package/node_modules/openai/realtime/internal-base.js +118 -11
- package/node_modules/openai/realtime/internal-base.mjs +116 -11
- package/node_modules/openai/realtime/webrtc.js +8 -0
- package/node_modules/openai/realtime/webrtc.mjs +2 -0
- package/node_modules/openai/realtime/websocket.js +174 -39
- package/node_modules/openai/realtime/websocket.mjs +175 -40
- package/node_modules/openai/realtime/ws.js +86 -18
- package/node_modules/openai/realtime/ws.mjs +87 -19
- package/node_modules/openai/resources/admin/admin.js +1 -1
- package/node_modules/openai/resources/admin/admin.mjs +1 -1
- package/node_modules/openai/resources/admin/index.js +1 -1
- package/node_modules/openai/resources/admin/index.mjs +1 -1
- package/node_modules/openai/resources/admin/organization/admin-api-keys.js +1 -1
- package/node_modules/openai/resources/admin/organization/admin-api-keys.mjs +1 -1
- package/node_modules/openai/resources/admin/organization/audit-logs.js +1 -1
- package/node_modules/openai/resources/admin/organization/audit-logs.mjs +1 -1
- package/node_modules/openai/resources/admin/organization/certificates.js +1 -1
- package/node_modules/openai/resources/admin/organization/certificates.mjs +1 -1
- package/node_modules/openai/resources/admin/organization/data-retention.js +1 -1
- package/node_modules/openai/resources/admin/organization/data-retention.mjs +1 -1
- package/node_modules/openai/resources/admin/organization/groups/groups.js +1 -1
- package/node_modules/openai/resources/admin/organization/groups/groups.mjs +1 -1
- package/node_modules/openai/resources/admin/organization/groups/index.js +1 -1
- package/node_modules/openai/resources/admin/organization/groups/index.mjs +1 -1
- package/node_modules/openai/resources/admin/organization/groups/roles.js +1 -1
- package/node_modules/openai/resources/admin/organization/groups/roles.mjs +1 -1
- package/node_modules/openai/resources/admin/organization/groups/users.js +1 -1
- package/node_modules/openai/resources/admin/organization/groups/users.mjs +1 -1
- package/node_modules/openai/resources/admin/organization/groups.js +1 -1
- package/node_modules/openai/resources/admin/organization/groups.mjs +1 -1
- package/node_modules/openai/resources/admin/organization/index.js +4 -2
- package/node_modules/openai/resources/admin/organization/index.mjs +2 -1
- package/node_modules/openai/resources/admin/organization/invites.js +1 -1
- package/node_modules/openai/resources/admin/organization/invites.mjs +1 -1
- package/node_modules/openai/resources/admin/organization/organization.js +5 -1
- package/node_modules/openai/resources/admin/organization/organization.mjs +5 -1
- package/node_modules/openai/resources/admin/organization/projects/api-keys.js +1 -1
- package/node_modules/openai/resources/admin/organization/projects/api-keys.mjs +1 -1
- package/node_modules/openai/resources/admin/organization/projects/certificates.js +1 -1
- package/node_modules/openai/resources/admin/organization/projects/certificates.mjs +1 -1
- package/node_modules/openai/resources/admin/organization/projects/data-retention.js +1 -1
- package/node_modules/openai/resources/admin/organization/projects/data-retention.mjs +1 -1
- package/node_modules/openai/resources/admin/organization/projects/groups/groups.js +1 -1
- package/node_modules/openai/resources/admin/organization/projects/groups/groups.mjs +1 -1
- package/node_modules/openai/resources/admin/organization/projects/groups/index.js +1 -1
- package/node_modules/openai/resources/admin/organization/projects/groups/index.mjs +1 -1
- package/node_modules/openai/resources/admin/organization/projects/groups/roles.js +1 -1
- package/node_modules/openai/resources/admin/organization/projects/groups/roles.mjs +1 -1
- package/node_modules/openai/resources/admin/organization/projects/groups.js +1 -1
- package/node_modules/openai/resources/admin/organization/projects/groups.mjs +1 -1
- package/node_modules/openai/resources/admin/organization/projects/hosted-tool-permissions.js +1 -1
- package/node_modules/openai/resources/admin/organization/projects/hosted-tool-permissions.mjs +1 -1
- package/node_modules/openai/resources/admin/organization/projects/index.js +8 -6
- package/node_modules/openai/resources/admin/organization/projects/index.mjs +3 -2
- package/node_modules/openai/resources/admin/organization/projects/model-permissions.js +1 -1
- package/node_modules/openai/resources/admin/organization/projects/model-permissions.mjs +1 -1
- package/node_modules/openai/resources/admin/organization/projects/projects.js +7 -3
- package/node_modules/openai/resources/admin/organization/projects/projects.mjs +7 -3
- package/node_modules/openai/resources/admin/organization/projects/rate-limits.js +1 -1
- package/node_modules/openai/resources/admin/organization/projects/rate-limits.mjs +1 -1
- package/node_modules/openai/resources/admin/organization/projects/roles.js +1 -1
- package/node_modules/openai/resources/admin/organization/projects/roles.mjs +1 -1
- package/node_modules/openai/resources/admin/organization/projects/service-accounts/api-keys.js +26 -0
- package/node_modules/openai/resources/admin/organization/projects/service-accounts/api-keys.mjs +22 -0
- package/node_modules/openai/resources/admin/organization/projects/service-accounts/index.js +9 -0
- package/node_modules/openai/resources/admin/organization/projects/service-accounts/index.mjs +4 -0
- package/node_modules/openai/resources/admin/organization/projects/service-accounts/service-accounts.js +109 -0
- package/node_modules/openai/resources/admin/organization/projects/service-accounts/service-accounts.mjs +104 -0
- package/node_modules/openai/resources/admin/organization/projects/service-accounts.js +3 -98
- package/node_modules/openai/resources/admin/organization/projects/service-accounts.mjs +2 -96
- package/node_modules/openai/resources/admin/organization/projects/spend-alerts.js +20 -1
- package/node_modules/openai/resources/admin/organization/projects/spend-alerts.mjs +20 -1
- package/node_modules/openai/resources/admin/organization/projects/spend-limit.js +67 -0
- package/node_modules/openai/resources/admin/organization/projects/spend-limit.mjs +63 -0
- package/node_modules/openai/resources/admin/organization/projects/users/index.js +1 -1
- package/node_modules/openai/resources/admin/organization/projects/users/index.mjs +1 -1
- package/node_modules/openai/resources/admin/organization/projects/users/roles.js +1 -1
- package/node_modules/openai/resources/admin/organization/projects/users/roles.mjs +1 -1
- package/node_modules/openai/resources/admin/organization/projects/users/users.js +1 -1
- package/node_modules/openai/resources/admin/organization/projects/users/users.mjs +1 -1
- package/node_modules/openai/resources/admin/organization/projects/users.js +1 -1
- package/node_modules/openai/resources/admin/organization/projects/users.mjs +1 -1
- package/node_modules/openai/resources/admin/organization/projects.js +1 -1
- package/node_modules/openai/resources/admin/organization/projects.mjs +1 -1
- package/node_modules/openai/resources/admin/organization/roles.js +1 -1
- package/node_modules/openai/resources/admin/organization/roles.mjs +1 -1
- package/node_modules/openai/resources/admin/organization/spend-alerts.js +18 -1
- package/node_modules/openai/resources/admin/organization/spend-alerts.mjs +18 -1
- package/node_modules/openai/resources/admin/organization/spend-limit.js +59 -0
- package/node_modules/openai/resources/admin/organization/spend-limit.mjs +55 -0
- package/node_modules/openai/resources/admin/organization/usage.js +1 -1
- package/node_modules/openai/resources/admin/organization/usage.mjs +1 -1
- package/node_modules/openai/resources/admin/organization/users/index.js +1 -1
- package/node_modules/openai/resources/admin/organization/users/index.mjs +1 -1
- package/node_modules/openai/resources/admin/organization/users/roles.js +1 -1
- package/node_modules/openai/resources/admin/organization/users/roles.mjs +1 -1
- package/node_modules/openai/resources/admin/organization/users/users.js +1 -1
- package/node_modules/openai/resources/admin/organization/users/users.mjs +1 -1
- package/node_modules/openai/resources/admin/organization/users.js +1 -1
- package/node_modules/openai/resources/admin/organization/users.mjs +1 -1
- package/node_modules/openai/resources/admin/organization.js +1 -1
- package/node_modules/openai/resources/admin/organization.mjs +1 -1
- package/node_modules/openai/resources/admin.js +1 -1
- package/node_modules/openai/resources/admin.mjs +1 -1
- package/node_modules/openai/resources/audio/audio.js +1 -1
- package/node_modules/openai/resources/audio/audio.mjs +1 -1
- package/node_modules/openai/resources/audio/index.js +1 -1
- package/node_modules/openai/resources/audio/index.mjs +1 -1
- package/node_modules/openai/resources/audio/speech.js +1 -1
- package/node_modules/openai/resources/audio/speech.mjs +1 -1
- package/node_modules/openai/resources/audio/transcriptions.js +1 -1
- package/node_modules/openai/resources/audio/transcriptions.mjs +1 -1
- package/node_modules/openai/resources/audio/translations.js +1 -1
- package/node_modules/openai/resources/audio/translations.mjs +1 -1
- package/node_modules/openai/resources/audio.js +1 -1
- package/node_modules/openai/resources/audio.mjs +1 -1
- package/node_modules/openai/resources/batches.js +1 -1
- package/node_modules/openai/resources/batches.mjs +1 -1
- package/node_modules/openai/resources/beta/agents/agents.js +118 -0
- package/node_modules/openai/resources/beta/agents/agents.mjs +113 -0
- package/node_modules/openai/resources/beta/agents/environments/environments.js +43 -0
- package/node_modules/openai/resources/beta/agents/environments/environments.mjs +38 -0
- package/node_modules/openai/resources/beta/agents/environments/files.js +61 -0
- package/node_modules/openai/resources/beta/agents/environments/files.mjs +57 -0
- package/node_modules/openai/resources/beta/agents/environments/index.js +11 -0
- package/node_modules/openai/resources/beta/agents/environments/index.mjs +5 -0
- package/node_modules/openai/resources/beta/agents/environments/templates.js +112 -0
- package/node_modules/openai/resources/beta/agents/environments/templates.mjs +108 -0
- package/node_modules/openai/resources/beta/agents/environments.js +6 -0
- package/node_modules/openai/resources/beta/agents/environments.mjs +3 -0
- package/node_modules/openai/resources/beta/agents/index.js +13 -0
- package/node_modules/openai/resources/beta/agents/index.mjs +6 -0
- package/node_modules/openai/resources/beta/agents/sessions/artifacts.js +106 -0
- package/node_modules/openai/resources/beta/agents/sessions/artifacts.mjs +102 -0
- package/node_modules/openai/resources/beta/agents/sessions/events.js +75 -0
- package/node_modules/openai/resources/beta/agents/sessions/events.mjs +71 -0
- package/node_modules/openai/resources/beta/agents/sessions/index.js +17 -0
- package/node_modules/openai/resources/beta/agents/sessions/index.mjs +8 -0
- package/node_modules/openai/resources/beta/agents/sessions/items.js +35 -0
- package/node_modules/openai/resources/beta/agents/sessions/items.mjs +31 -0
- package/node_modules/openai/resources/beta/agents/sessions/sessions.js +127 -0
- package/node_modules/openai/resources/beta/agents/sessions/sessions.mjs +122 -0
- package/node_modules/openai/resources/beta/agents/sessions/subagents/index.js +11 -0
- package/node_modules/openai/resources/beta/agents/sessions/subagents/index.mjs +5 -0
- package/node_modules/openai/resources/beta/agents/sessions/subagents/items.js +36 -0
- package/node_modules/openai/resources/beta/agents/sessions/subagents/items.mjs +32 -0
- package/node_modules/openai/resources/beta/agents/sessions/subagents/subagents.js +67 -0
- package/node_modules/openai/resources/beta/agents/sessions/subagents/subagents.mjs +62 -0
- package/node_modules/openai/resources/beta/agents/sessions/subagents/turns/index.js +9 -0
- package/node_modules/openai/resources/beta/agents/sessions/subagents/turns/index.mjs +4 -0
- package/node_modules/openai/resources/beta/agents/sessions/subagents/turns/items.js +36 -0
- package/node_modules/openai/resources/beta/agents/sessions/subagents/turns/items.mjs +32 -0
- package/node_modules/openai/resources/beta/agents/sessions/subagents/turns/turns.js +68 -0
- package/node_modules/openai/resources/beta/agents/sessions/subagents/turns/turns.mjs +63 -0
- package/node_modules/openai/resources/beta/agents/sessions/subagents/turns.js +6 -0
- package/node_modules/openai/resources/beta/agents/sessions/subagents/turns.mjs +3 -0
- package/node_modules/openai/resources/beta/agents/sessions/subagents.js +6 -0
- package/node_modules/openai/resources/beta/agents/sessions/subagents.mjs +3 -0
- package/node_modules/openai/resources/beta/agents/sessions/turns.js +57 -0
- package/node_modules/openai/resources/beta/agents/sessions/turns.mjs +53 -0
- package/node_modules/openai/resources/beta/agents/sessions.js +6 -0
- package/node_modules/openai/resources/beta/agents/sessions.mjs +3 -0
- package/node_modules/openai/resources/beta/agents/vaults/credentials.js +132 -0
- package/node_modules/openai/resources/beta/agents/vaults/credentials.mjs +128 -0
- package/node_modules/openai/resources/beta/agents/vaults/index.js +9 -0
- package/node_modules/openai/resources/beta/agents/vaults/index.mjs +4 -0
- package/node_modules/openai/resources/beta/agents/vaults/vaults.js +93 -0
- package/node_modules/openai/resources/beta/agents/vaults/vaults.mjs +88 -0
- package/node_modules/openai/resources/beta/agents/vaults.js +6 -0
- package/node_modules/openai/resources/beta/agents/vaults.mjs +3 -0
- package/node_modules/openai/resources/beta/agents.js +6 -0
- package/node_modules/openai/resources/beta/agents.mjs +3 -0
- package/node_modules/openai/resources/beta/assistants.js +1 -1
- package/node_modules/openai/resources/beta/assistants.mjs +1 -1
- package/node_modules/openai/resources/beta/beta.js +9 -1
- package/node_modules/openai/resources/beta/beta.mjs +9 -1
- package/node_modules/openai/resources/beta/chatkit/chatkit.js +1 -1
- package/node_modules/openai/resources/beta/chatkit/chatkit.mjs +1 -1
- package/node_modules/openai/resources/beta/chatkit/index.js +1 -1
- package/node_modules/openai/resources/beta/chatkit/index.mjs +1 -1
- package/node_modules/openai/resources/beta/chatkit/sessions.js +1 -1
- package/node_modules/openai/resources/beta/chatkit/sessions.mjs +1 -1
- package/node_modules/openai/resources/beta/chatkit/threads.js +1 -1
- package/node_modules/openai/resources/beta/chatkit/threads.mjs +1 -1
- package/node_modules/openai/resources/beta/chatkit.js +1 -1
- package/node_modules/openai/resources/beta/chatkit.mjs +1 -1
- package/node_modules/openai/resources/beta/index.js +12 -8
- package/node_modules/openai/resources/beta/index.mjs +3 -1
- package/node_modules/openai/resources/beta/realtime/index.js +0 -1
- package/node_modules/openai/resources/beta/realtime/index.mjs +0 -1
- package/node_modules/openai/resources/beta/realtime/realtime.js +0 -1
- package/node_modules/openai/resources/beta/realtime/realtime.mjs +0 -1
- package/node_modules/openai/resources/beta/realtime/sessions.js +0 -1
- package/node_modules/openai/resources/beta/realtime/sessions.mjs +0 -1
- package/node_modules/openai/resources/beta/realtime/transcription-sessions.js +0 -1
- package/node_modules/openai/resources/beta/realtime/transcription-sessions.mjs +0 -1
- package/node_modules/openai/resources/beta/realtime.js +0 -1
- package/node_modules/openai/resources/beta/realtime.mjs +0 -1
- package/node_modules/openai/resources/beta/responses/index.js +11 -0
- package/node_modules/openai/resources/beta/responses/index.mjs +5 -0
- package/node_modules/openai/resources/beta/responses/input-items.js +37 -0
- package/node_modules/openai/resources/beta/responses/input-items.mjs +33 -0
- package/node_modules/openai/resources/beta/responses/input-tokens.js +34 -0
- package/node_modules/openai/resources/beta/responses/input-tokens.mjs +30 -0
- package/node_modules/openai/resources/beta/responses/internal-base.js +66 -0
- package/node_modules/openai/resources/beta/responses/internal-base.mjs +60 -0
- package/node_modules/openai/resources/beta/responses/responses.js +121 -0
- package/node_modules/openai/resources/beta/responses/responses.mjs +116 -0
- package/node_modules/openai/resources/beta/responses/ws-base.js +566 -0
- package/node_modules/openai/resources/beta/responses/ws-base.mjs +560 -0
- package/node_modules/openai/resources/beta/responses/ws.js +47 -0
- package/node_modules/openai/resources/beta/responses/ws.mjs +42 -0
- package/node_modules/openai/resources/beta/responses.js +6 -0
- package/node_modules/openai/resources/beta/responses.mjs +3 -0
- package/node_modules/openai/resources/beta/threads/index.js +1 -1
- package/node_modules/openai/resources/beta/threads/index.mjs +1 -1
- package/node_modules/openai/resources/beta/threads/messages.js +1 -1
- package/node_modules/openai/resources/beta/threads/messages.mjs +1 -1
- package/node_modules/openai/resources/beta/threads/runs/index.js +1 -1
- package/node_modules/openai/resources/beta/threads/runs/index.mjs +1 -1
- package/node_modules/openai/resources/beta/threads/runs/runs.js +3 -44
- package/node_modules/openai/resources/beta/threads/runs/runs.mjs +3 -44
- package/node_modules/openai/resources/beta/threads/runs/steps.js +1 -1
- package/node_modules/openai/resources/beta/threads/runs/steps.mjs +1 -1
- package/node_modules/openai/resources/beta/threads/runs.js +1 -1
- package/node_modules/openai/resources/beta/threads/runs.mjs +1 -1
- package/node_modules/openai/resources/beta/threads/threads.js +1 -1
- package/node_modules/openai/resources/beta/threads/threads.mjs +1 -1
- package/node_modules/openai/resources/beta/threads.js +1 -1
- package/node_modules/openai/resources/beta/threads.mjs +1 -1
- package/node_modules/openai/resources/beta.js +1 -1
- package/node_modules/openai/resources/beta.mjs +1 -1
- package/node_modules/openai/resources/chat/chat.js +1 -1
- package/node_modules/openai/resources/chat/chat.mjs +1 -1
- package/node_modules/openai/resources/chat/completions/completions.js +2 -5
- package/node_modules/openai/resources/chat/completions/completions.mjs +2 -5
- package/node_modules/openai/resources/chat/completions/index.js +1 -1
- package/node_modules/openai/resources/chat/completions/index.mjs +1 -1
- package/node_modules/openai/resources/chat/completions/messages.js +1 -1
- package/node_modules/openai/resources/chat/completions/messages.mjs +1 -1
- package/node_modules/openai/resources/chat/completions.js +1 -1
- package/node_modules/openai/resources/chat/completions.mjs +1 -1
- package/node_modules/openai/resources/chat/index.js +1 -1
- package/node_modules/openai/resources/chat/index.mjs +1 -1
- package/node_modules/openai/resources/chat.js +1 -1
- package/node_modules/openai/resources/chat.mjs +1 -1
- package/node_modules/openai/resources/completions.js +1 -1
- package/node_modules/openai/resources/completions.mjs +1 -1
- package/node_modules/openai/resources/containers/containers.js +1 -1
- package/node_modules/openai/resources/containers/containers.mjs +1 -1
- package/node_modules/openai/resources/containers/files/content.js +1 -1
- package/node_modules/openai/resources/containers/files/content.mjs +1 -1
- package/node_modules/openai/resources/containers/files/files.js +1 -1
- package/node_modules/openai/resources/containers/files/files.mjs +1 -1
- package/node_modules/openai/resources/containers/files/index.js +1 -1
- package/node_modules/openai/resources/containers/files/index.mjs +1 -1
- package/node_modules/openai/resources/containers/files.js +1 -1
- package/node_modules/openai/resources/containers/files.mjs +1 -1
- package/node_modules/openai/resources/containers/index.js +1 -1
- package/node_modules/openai/resources/containers/index.mjs +1 -1
- package/node_modules/openai/resources/containers.js +1 -1
- package/node_modules/openai/resources/containers.mjs +1 -1
- package/node_modules/openai/resources/content-provenance-checks.js +24 -0
- package/node_modules/openai/resources/content-provenance-checks.mjs +20 -0
- package/node_modules/openai/resources/conversations/conversations.js +1 -1
- package/node_modules/openai/resources/conversations/conversations.mjs +1 -1
- package/node_modules/openai/resources/conversations/index.js +1 -1
- package/node_modules/openai/resources/conversations/index.mjs +1 -1
- package/node_modules/openai/resources/conversations/items.js +1 -1
- package/node_modules/openai/resources/conversations/items.mjs +1 -1
- package/node_modules/openai/resources/conversations.js +1 -1
- package/node_modules/openai/resources/conversations.mjs +1 -1
- package/node_modules/openai/resources/embeddings.js +3 -47
- package/node_modules/openai/resources/embeddings.mjs +3 -47
- package/node_modules/openai/resources/evals/evals.js +2 -2
- package/node_modules/openai/resources/evals/evals.mjs +2 -2
- package/node_modules/openai/resources/evals/index.js +1 -1
- package/node_modules/openai/resources/evals/index.mjs +1 -1
- package/node_modules/openai/resources/evals/runs/index.js +1 -1
- package/node_modules/openai/resources/evals/runs/index.mjs +1 -1
- package/node_modules/openai/resources/evals/runs/output-items.js +1 -1
- package/node_modules/openai/resources/evals/runs/output-items.mjs +1 -1
- package/node_modules/openai/resources/evals/runs/runs.js +1 -1
- package/node_modules/openai/resources/evals/runs/runs.mjs +1 -1
- package/node_modules/openai/resources/evals/runs.js +1 -1
- package/node_modules/openai/resources/evals/runs.mjs +1 -1
- package/node_modules/openai/resources/evals.js +1 -1
- package/node_modules/openai/resources/evals.mjs +1 -1
- package/node_modules/openai/resources/files.js +9 -22
- package/node_modules/openai/resources/files.mjs +9 -22
- package/node_modules/openai/resources/fine-tuning/alpha/alpha.js +1 -1
- package/node_modules/openai/resources/fine-tuning/alpha/alpha.mjs +1 -1
- package/node_modules/openai/resources/fine-tuning/alpha/graders.js +1 -1
- package/node_modules/openai/resources/fine-tuning/alpha/graders.mjs +1 -1
- package/node_modules/openai/resources/fine-tuning/alpha/index.js +1 -1
- package/node_modules/openai/resources/fine-tuning/alpha/index.mjs +1 -1
- package/node_modules/openai/resources/fine-tuning/alpha.js +1 -1
- package/node_modules/openai/resources/fine-tuning/alpha.mjs +1 -1
- package/node_modules/openai/resources/fine-tuning/checkpoints/checkpoints.js +1 -1
- package/node_modules/openai/resources/fine-tuning/checkpoints/checkpoints.mjs +1 -1
- package/node_modules/openai/resources/fine-tuning/checkpoints/index.js +1 -1
- package/node_modules/openai/resources/fine-tuning/checkpoints/index.mjs +1 -1
- package/node_modules/openai/resources/fine-tuning/checkpoints/permissions.js +9 -5
- package/node_modules/openai/resources/fine-tuning/checkpoints/permissions.mjs +9 -5
- package/node_modules/openai/resources/fine-tuning/checkpoints.js +1 -1
- package/node_modules/openai/resources/fine-tuning/checkpoints.mjs +1 -1
- package/node_modules/openai/resources/fine-tuning/fine-tuning.js +1 -1
- package/node_modules/openai/resources/fine-tuning/fine-tuning.mjs +1 -1
- package/node_modules/openai/resources/fine-tuning/index.js +1 -1
- package/node_modules/openai/resources/fine-tuning/index.mjs +1 -1
- package/node_modules/openai/resources/fine-tuning/jobs/checkpoints.js +1 -1
- package/node_modules/openai/resources/fine-tuning/jobs/checkpoints.mjs +1 -1
- package/node_modules/openai/resources/fine-tuning/jobs/index.js +1 -1
- package/node_modules/openai/resources/fine-tuning/jobs/index.mjs +1 -1
- package/node_modules/openai/resources/fine-tuning/jobs/jobs.js +3 -3
- package/node_modules/openai/resources/fine-tuning/jobs/jobs.mjs +3 -3
- package/node_modules/openai/resources/fine-tuning/jobs.js +1 -1
- package/node_modules/openai/resources/fine-tuning/jobs.mjs +1 -1
- package/node_modules/openai/resources/fine-tuning/methods.js +1 -1
- package/node_modules/openai/resources/fine-tuning/methods.mjs +1 -1
- package/node_modules/openai/resources/fine-tuning.js +1 -1
- package/node_modules/openai/resources/fine-tuning.mjs +1 -1
- package/node_modules/openai/resources/graders/grader-models.js +1 -1
- package/node_modules/openai/resources/graders/grader-models.mjs +1 -1
- package/node_modules/openai/resources/graders/graders.js +1 -1
- package/node_modules/openai/resources/graders/graders.mjs +1 -1
- package/node_modules/openai/resources/graders/index.js +1 -1
- package/node_modules/openai/resources/graders/index.mjs +1 -1
- package/node_modules/openai/resources/graders.js +1 -1
- package/node_modules/openai/resources/graders.mjs +1 -1
- package/node_modules/openai/resources/images.js +8 -2
- package/node_modules/openai/resources/images.mjs +8 -2
- package/node_modules/openai/resources/index.js +9 -3
- package/node_modules/openai/resources/index.mjs +5 -2
- package/node_modules/openai/resources/live/forks/forks.js +9 -0
- package/node_modules/openai/resources/live/forks/forks.mjs +5 -0
- package/node_modules/openai/resources/live/forks/index.js +7 -0
- package/node_modules/openai/resources/live/forks/index.mjs +3 -0
- package/node_modules/openai/resources/live/forks/internal-base.js +65 -0
- package/node_modules/openai/resources/live/forks/internal-base.mjs +59 -0
- package/node_modules/openai/resources/live/forks/ws-base.js +547 -0
- package/node_modules/openai/resources/live/forks/ws-base.mjs +543 -0
- package/node_modules/openai/resources/live/forks/ws.js +32 -0
- package/node_modules/openai/resources/live/forks/ws.mjs +27 -0
- package/node_modules/openai/resources/live/forks.js +6 -0
- package/node_modules/openai/resources/live/forks.mjs +3 -0
- package/node_modules/openai/resources/live/index.js +13 -0
- package/node_modules/openai/resources/live/index.mjs +6 -0
- package/node_modules/openai/resources/live/internal-base.js +64 -0
- package/node_modules/openai/resources/live/internal-base.mjs +58 -0
- package/node_modules/openai/resources/live/live.js +40 -0
- package/node_modules/openai/resources/live/live.mjs +35 -0
- package/node_modules/openai/resources/live/sessions.js +124 -0
- package/node_modules/openai/resources/live/sessions.mjs +120 -0
- package/node_modules/openai/resources/live/sideband/index.js +7 -0
- package/node_modules/openai/resources/live/sideband/index.mjs +3 -0
- package/node_modules/openai/resources/live/sideband/internal-base.js +65 -0
- package/node_modules/openai/resources/live/sideband/internal-base.mjs +59 -0
- package/node_modules/openai/resources/live/sideband/sideband.js +9 -0
- package/node_modules/openai/resources/live/sideband/sideband.mjs +5 -0
- package/node_modules/openai/resources/live/sideband/ws-base.js +547 -0
- package/node_modules/openai/resources/live/sideband/ws-base.mjs +543 -0
- package/node_modules/openai/resources/live/sideband/ws.js +32 -0
- package/node_modules/openai/resources/live/sideband/ws.mjs +27 -0
- package/node_modules/openai/resources/live/sideband.js +6 -0
- package/node_modules/openai/resources/live/sideband.mjs +3 -0
- package/node_modules/openai/resources/live/ws-base.js +547 -0
- package/node_modules/openai/resources/live/ws-base.mjs +543 -0
- package/node_modules/openai/resources/live/ws.js +32 -0
- package/node_modules/openai/resources/live/ws.mjs +27 -0
- package/node_modules/openai/resources/live.js +6 -0
- package/node_modules/openai/resources/live.mjs +3 -0
- package/node_modules/openai/resources/models.js +1 -1
- package/node_modules/openai/resources/models.mjs +1 -1
- package/node_modules/openai/resources/moderations.js +3 -2
- package/node_modules/openai/resources/moderations.mjs +3 -2
- package/node_modules/openai/resources/realtime/calls.js +25 -1
- package/node_modules/openai/resources/realtime/calls.mjs +25 -1
- package/node_modules/openai/resources/realtime/client-secrets.js +2 -2
- package/node_modules/openai/resources/realtime/client-secrets.mjs +2 -2
- package/node_modules/openai/resources/realtime/index.js +1 -1
- package/node_modules/openai/resources/realtime/index.mjs +2 -2
- package/node_modules/openai/resources/realtime/realtime.js +1 -1
- package/node_modules/openai/resources/realtime/realtime.mjs +1 -1
- package/node_modules/openai/resources/realtime.js +1 -1
- package/node_modules/openai/resources/realtime.mjs +1 -1
- package/node_modules/openai/resources/responses/index.js +1 -1
- package/node_modules/openai/resources/responses/index.mjs +1 -1
- package/node_modules/openai/resources/responses/input-items.js +1 -1
- package/node_modules/openai/resources/responses/input-items.mjs +1 -1
- package/node_modules/openai/resources/responses/input-tokens.js +1 -1
- package/node_modules/openai/resources/responses/input-tokens.mjs +1 -1
- package/node_modules/openai/resources/responses/internal-base.js +24 -6
- package/node_modules/openai/resources/responses/internal-base.mjs +24 -6
- package/node_modules/openai/resources/responses/responses.js +5 -5
- package/node_modules/openai/resources/responses/responses.mjs +5 -5
- package/node_modules/openai/resources/responses/ws-base.js +115 -23
- package/node_modules/openai/resources/responses/ws-base.mjs +115 -25
- package/node_modules/openai/resources/responses/ws.js +23 -7
- package/node_modules/openai/resources/responses/ws.mjs +23 -7
- package/node_modules/openai/resources/responses.js +1 -1
- package/node_modules/openai/resources/responses.mjs +1 -1
- package/node_modules/openai/resources/safety/alerts.js +16 -0
- package/node_modules/openai/resources/safety/alerts.mjs +12 -0
- package/node_modules/openai/resources/safety/index.js +9 -0
- package/node_modules/openai/resources/safety/index.mjs +4 -0
- package/node_modules/openai/resources/safety/safety.js +17 -0
- package/node_modules/openai/resources/safety/safety.mjs +12 -0
- package/node_modules/openai/resources/safety.js +6 -0
- package/node_modules/openai/resources/safety.mjs +3 -0
- package/node_modules/openai/resources/shared.js +1 -1
- package/node_modules/openai/resources/shared.mjs +1 -1
- package/node_modules/openai/resources/skills/content.js +1 -1
- package/node_modules/openai/resources/skills/content.mjs +1 -1
- package/node_modules/openai/resources/skills/index.js +1 -1
- package/node_modules/openai/resources/skills/index.mjs +1 -1
- package/node_modules/openai/resources/skills/skills.js +4 -2
- package/node_modules/openai/resources/skills/skills.mjs +4 -2
- package/node_modules/openai/resources/skills/versions/content.js +1 -1
- package/node_modules/openai/resources/skills/versions/content.mjs +1 -1
- package/node_modules/openai/resources/skills/versions/index.js +1 -1
- package/node_modules/openai/resources/skills/versions/index.mjs +1 -1
- package/node_modules/openai/resources/skills/versions/versions.js +4 -2
- package/node_modules/openai/resources/skills/versions/versions.mjs +4 -2
- package/node_modules/openai/resources/skills/versions.js +1 -1
- package/node_modules/openai/resources/skills/versions.mjs +1 -1
- package/node_modules/openai/resources/skills.js +1 -1
- package/node_modules/openai/resources/skills.mjs +1 -1
- package/node_modules/openai/resources/uploads/index.js +1 -1
- package/node_modules/openai/resources/uploads/index.mjs +1 -1
- package/node_modules/openai/resources/uploads/parts.js +6 -5
- package/node_modules/openai/resources/uploads/parts.mjs +6 -5
- package/node_modules/openai/resources/uploads/uploads.js +10 -10
- package/node_modules/openai/resources/uploads/uploads.mjs +10 -10
- package/node_modules/openai/resources/uploads.js +1 -1
- package/node_modules/openai/resources/uploads.mjs +1 -1
- package/node_modules/openai/resources/vector-stores/file-batches.js +6 -63
- package/node_modules/openai/resources/vector-stores/file-batches.mjs +6 -63
- package/node_modules/openai/resources/vector-stores/files.js +6 -39
- package/node_modules/openai/resources/vector-stores/files.mjs +6 -39
- package/node_modules/openai/resources/vector-stores/index.js +1 -1
- package/node_modules/openai/resources/vector-stores/index.mjs +1 -1
- package/node_modules/openai/resources/vector-stores/vector-stores.js +1 -1
- package/node_modules/openai/resources/vector-stores/vector-stores.mjs +1 -1
- package/node_modules/openai/resources/vector-stores.js +1 -1
- package/node_modules/openai/resources/vector-stores.mjs +1 -1
- package/node_modules/openai/resources/videos.js +24 -1
- package/node_modules/openai/resources/videos.mjs +24 -1
- package/node_modules/openai/resources/webhooks/event-types.js +21 -0
- package/node_modules/openai/resources/webhooks/event-types.mjs +17 -0
- package/node_modules/openai/resources/webhooks/index.js +4 -1
- package/node_modules/openai/resources/webhooks/index.mjs +2 -1
- package/node_modules/openai/resources/webhooks/webhooks.js +127 -43
- package/node_modules/openai/resources/webhooks/webhooks.mjs +127 -43
- package/node_modules/openai/resources/webhooks.js +1 -1
- package/node_modules/openai/resources/webhooks.mjs +1 -1
- package/node_modules/openai/src/_vendor/partial-json-parser/LICENSE +21 -0
- package/node_modules/openai/src/_vendor/partial-json-parser/README.md +11 -1
- package/node_modules/openai/src/_vendor/partial-json-parser/parser.ts +66 -35
- package/node_modules/openai/src/_vendor/zod-to-json-schema/Options.ts +32 -18
- package/node_modules/openai/src/_vendor/zod-to-json-schema/Refs.ts +7 -6
- package/node_modules/openai/src/_vendor/zod-to-json-schema/errorMessages.ts +5 -3
- package/node_modules/openai/src/_vendor/zod-to-json-schema/index.ts +3 -1
- package/node_modules/openai/src/_vendor/zod-to-json-schema/parseDef.ts +194 -79
- package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/array.ts +8 -5
- package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/bigint.ts +20 -12
- package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/branded.ts +4 -4
- package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/catch.ts +4 -5
- package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/date.ts +16 -10
- package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/default.ts +10 -5
- package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/effects.ts +4 -3
- package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/enum.ts +1 -1
- package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/intersection.ts +12 -9
- package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/literal.ts +12 -2
- package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/map.ts +6 -4
- package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/nativeEnum.ts +10 -11
- package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/null.ts +4 -3
- package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/nullable.ts +25 -10
- package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/number.ts +17 -8
- package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/object.ts +57 -54
- package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/optional.ts +25 -17
- package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/pipeline.ts +8 -6
- package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/promise.ts +10 -5
- package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/readonly.ts +4 -5
- package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/record.ts +22 -19
- package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/set.ts +6 -4
- package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/string.ts +62 -37
- package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/tuple.ts +32 -25
- package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/union.ts +51 -33
- package/node_modules/openai/src/_vendor/zod-to-json-schema/util.ts +11 -6
- package/node_modules/openai/src/_vendor/zod-to-json-schema/zodToJsonSchema.ts +133 -52
- package/node_modules/openai/src/auth/index.ts +7 -1
- package/node_modules/openai/src/auth/subject-token-providers.ts +281 -16
- package/node_modules/openai/src/auth/types.ts +48 -5
- package/node_modules/openai/src/auth/workload-identity-auth.ts +227 -26
- package/node_modules/openai/src/auth/x509-transport.ts +369 -0
- package/node_modules/openai/src/azure.ts +127 -28
- package/node_modules/openai/src/bedrock.ts +294 -0
- package/node_modules/openai/src/beta/realtime/internal-base.ts +136 -16
- package/node_modules/openai/src/beta/realtime/websocket.ts +264 -48
- package/node_modules/openai/src/beta/realtime/ws.ts +138 -25
- package/node_modules/openai/src/client.ts +975 -124
- package/node_modules/openai/src/core/EventEmitter.ts +162 -26
- package/node_modules/openai/src/core/api-promise.ts +0 -2
- package/node_modules/openai/src/core/error.ts +6 -8
- package/node_modules/openai/src/core/pagination.ts +67 -7
- package/node_modules/openai/src/core/resource.ts +0 -2
- package/node_modules/openai/src/core/streaming.ts +490 -100
- package/node_modules/openai/src/core/uploads.ts +6 -1
- package/node_modules/openai/src/helpers/audio.ts +215 -32
- package/node_modules/openai/src/helpers/live.ts +8 -0
- package/node_modules/openai/src/helpers/standard-schema.ts +819 -0
- package/node_modules/openai/src/helpers/zod-v3-strict-schema.ts +520 -0
- package/node_modules/openai/src/helpers/zod.ts +418 -56
- package/node_modules/openai/src/index.ts +4 -5
- package/node_modules/openai/src/internal/assistant-stream-delta.ts +440 -0
- package/node_modules/openai/src/internal/auth/x509-api-origin.ts +27 -0
- package/node_modules/openai/src/internal/auth/x509-credential-options.ts +149 -0
- package/node_modules/openai/src/internal/auth/x509-token-exchange.ts +319 -0
- package/node_modules/openai/src/internal/auth/x509-transport-capability.ts +227 -0
- package/node_modules/openai/src/internal/auth/x509-transport-registry.ts +127 -0
- package/node_modules/openai/src/internal/auth/x509-transport-state-browser.ts +43 -0
- package/node_modules/openai/src/internal/auth/x509-transport-state.cts +43 -0
- package/node_modules/openai/src/internal/auth/x509-workload-identity-auth.ts +972 -0
- package/node_modules/openai/src/internal/bedrock.ts +586 -0
- package/node_modules/openai/src/internal/builtin-types.ts +0 -2
- package/node_modules/openai/src/internal/data-residency.ts +44 -0
- package/node_modules/openai/src/internal/decoders/line.ts +145 -61
- package/node_modules/openai/src/internal/detect-platform.ts +3 -5
- package/node_modules/openai/src/internal/errors.ts +3 -4
- package/node_modules/openai/src/internal/headers.ts +14 -10
- package/node_modules/openai/src/internal/multipart-encoding.ts +53 -0
- package/node_modules/openai/src/internal/parse.ts +47 -19
- package/node_modules/openai/src/internal/provider.ts +92 -0
- package/node_modules/openai/src/internal/qs/formats.ts +1 -1
- package/node_modules/openai/src/internal/qs/stringify.ts +57 -53
- package/node_modules/openai/src/internal/qs/types.ts +1 -1
- package/node_modules/openai/src/internal/qs/utils.ts +443 -54
- package/node_modules/openai/src/internal/realtime-credentials.ts +27 -0
- package/node_modules/openai/src/internal/request-options.ts +52 -3
- package/node_modules/openai/src/internal/responses/canonical-output-text.ts +160 -0
- package/node_modules/openai/src/internal/responses/output-text-index.ts +84 -0
- package/node_modules/openai/src/internal/responses/response-accumulator.ts +1263 -0
- package/node_modules/openai/src/internal/shim-types.ts +3 -4
- package/node_modules/openai/src/internal/shims.ts +0 -2
- package/node_modules/openai/src/internal/stream-utils.ts +37 -5
- package/node_modules/openai/src/internal/to-file.ts +90 -35
- package/node_modules/openai/src/internal/types.ts +21 -29
- package/node_modules/openai/src/internal/uploads.ts +533 -59
- package/node_modules/openai/src/internal/utils/abort.ts +116 -0
- package/node_modules/openai/src/internal/utils/base64.ts +3 -2
- package/node_modules/openai/src/internal/utils/bytes.ts +7 -0
- package/node_modules/openai/src/internal/utils/env.ts +9 -7
- package/node_modules/openai/src/internal/utils/log.ts +77 -14
- package/node_modules/openai/src/internal/utils/path.ts +53 -32
- package/node_modules/openai/src/internal/utils/query.ts +0 -2
- package/node_modules/openai/src/internal/utils/sleep.ts +51 -2
- package/node_modules/openai/src/internal/utils/uuid.ts +0 -2
- package/node_modules/openai/src/internal/utils/values.ts +0 -2
- package/node_modules/openai/src/internal/utils.ts +0 -2
- package/node_modules/openai/src/internal/ws-adapter-browser.ts +83 -24
- package/node_modules/openai/src/internal/ws-adapter-node.ts +105 -26
- package/node_modules/openai/src/internal/ws-adapter.ts +23 -0
- package/node_modules/openai/src/internal/ws.ts +250 -51
- package/node_modules/openai/src/lib/.keep +2 -2
- package/node_modules/openai/src/lib/AbstractChatCompletionRunner.ts +349 -102
- package/node_modules/openai/src/lib/AssistantStream.ts +537 -268
- package/node_modules/openai/src/lib/ChatCompletionRunner.ts +75 -22
- package/node_modules/openai/src/lib/ChatCompletionStream.ts +2016 -268
- package/node_modules/openai/src/lib/ChatCompletionStreamingRunner.ts +115 -17
- package/node_modules/openai/src/lib/EventEmitter.ts +171 -26
- package/node_modules/openai/src/lib/EventStream.ts +1979 -64
- package/node_modules/openai/src/lib/ResponsesParser.ts +153 -56
- package/node_modules/openai/src/lib/RunnableFunction.ts +99 -37
- package/node_modules/openai/src/lib/Util.ts +7 -5
- package/node_modules/openai/src/lib/agents/agent-session-stream.ts +328 -0
- package/node_modules/openai/src/lib/agents/output-text.ts +6 -0
- package/node_modules/openai/src/lib/agents/turn-state.ts +61 -0
- package/node_modules/openai/src/lib/assistant-run-polling.ts +27 -0
- package/node_modules/openai/src/lib/chatCompletionUtils.ts +9 -10
- package/node_modules/openai/src/lib/embeddings.ts +73 -0
- package/node_modules/openai/src/lib/file-processing.ts +37 -0
- package/node_modules/openai/src/lib/jsonschema.ts +77 -34
- package/node_modules/openai/src/lib/live/transcript-grouper.ts +307 -0
- package/node_modules/openai/src/lib/live/transcript-grouping.ts +394 -0
- package/node_modules/openai/src/lib/live/webrtc.ts +23 -0
- package/node_modules/openai/src/lib/parser.ts +247 -69
- package/node_modules/openai/src/lib/polling.ts +145 -0
- package/node_modules/openai/src/lib/realtime/webrtc.ts +20 -0
- package/node_modules/openai/src/lib/responses/EventTypes.ts +9 -60
- package/node_modules/openai/src/lib/responses/ResponseAccumulator.ts +27 -0
- package/node_modules/openai/src/lib/responses/ResponseInputItems.ts +167 -0
- package/node_modules/openai/src/lib/responses/ResponseStream.ts +135 -179
- package/node_modules/openai/src/lib/responses/responses-websocket-lane.ts +388 -0
- package/node_modules/openai/src/lib/responses/responses-websocket-session.ts +317 -0
- package/node_modules/openai/src/lib/transform.ts +2015 -100
- package/node_modules/openai/src/lib/vector-store-polling.ts +46 -0
- package/node_modules/openai/src/lib/vector-store-upload.ts +57 -0
- package/node_modules/openai/src/lib/webhook-signature.ts +164 -0
- package/node_modules/openai/src/lib/webrtc/connection.ts +313 -0
- package/node_modules/openai/src/lib/webrtc/data-channel.ts +151 -0
- package/node_modules/openai/src/lib/webrtc/errors.ts +38 -0
- package/node_modules/openai/src/lib/webrtc/subscriptions.ts +65 -0
- package/node_modules/openai/src/lib/webrtc/types.ts +110 -0
- package/node_modules/openai/src/live/webrtc.ts +10 -0
- package/node_modules/openai/src/providers/bedrock/aws.ts +331 -0
- package/node_modules/openai/src/providers/bedrock.ts +51 -0
- package/node_modules/openai/src/realtime/internal-base.ts +265 -17
- package/node_modules/openai/src/realtime/webrtc.ts +10 -0
- package/node_modules/openai/src/realtime/websocket.ts +259 -54
- package/node_modules/openai/src/realtime/ws.ts +135 -29
- package/node_modules/openai/src/resources/admin/admin.ts +1 -1
- package/node_modules/openai/src/resources/admin/index.ts +1 -1
- package/node_modules/openai/src/resources/admin/organization/admin-api-keys.ts +18 -2
- package/node_modules/openai/src/resources/admin/organization/audit-logs.ts +327 -4
- package/node_modules/openai/src/resources/admin/organization/certificates.ts +1 -1
- package/node_modules/openai/src/resources/admin/organization/data-retention.ts +1 -1
- package/node_modules/openai/src/resources/admin/organization/groups/groups.ts +1 -1
- package/node_modules/openai/src/resources/admin/organization/groups/index.ts +1 -1
- package/node_modules/openai/src/resources/admin/organization/groups/roles.ts +1 -1
- package/node_modules/openai/src/resources/admin/organization/groups/users.ts +1 -1
- package/node_modules/openai/src/resources/admin/organization/groups.ts +1 -1
- package/node_modules/openai/src/resources/admin/organization/index.ts +9 -1
- package/node_modules/openai/src/resources/admin/organization/invites.ts +1 -1
- package/node_modules/openai/src/resources/admin/organization/organization.ts +21 -1
- package/node_modules/openai/src/resources/admin/organization/projects/api-keys.ts +22 -2
- package/node_modules/openai/src/resources/admin/organization/projects/certificates.ts +1 -1
- package/node_modules/openai/src/resources/admin/organization/projects/data-retention.ts +1 -1
- package/node_modules/openai/src/resources/admin/organization/projects/groups/groups.ts +1 -1
- package/node_modules/openai/src/resources/admin/organization/projects/groups/index.ts +1 -1
- package/node_modules/openai/src/resources/admin/organization/projects/groups/roles.ts +1 -1
- package/node_modules/openai/src/resources/admin/organization/projects/groups.ts +1 -1
- package/node_modules/openai/src/resources/admin/organization/projects/hosted-tool-permissions.ts +1 -1
- package/node_modules/openai/src/resources/admin/organization/projects/index.ts +10 -2
- package/node_modules/openai/src/resources/admin/organization/projects/model-permissions.ts +1 -1
- package/node_modules/openai/src/resources/admin/organization/projects/projects.ts +70 -19
- package/node_modules/openai/src/resources/admin/organization/projects/rate-limits.ts +1 -1
- package/node_modules/openai/src/resources/admin/organization/projects/roles.ts +1 -1
- package/node_modules/openai/src/resources/admin/organization/projects/service-accounts/api-keys.ts +91 -0
- package/node_modules/openai/src/resources/admin/organization/projects/service-accounts/index.ts +15 -0
- package/node_modules/openai/src/resources/admin/organization/projects/service-accounts/service-accounts.ts +299 -0
- package/node_modules/openai/src/resources/admin/organization/projects/service-accounts.ts +2 -265
- package/node_modules/openai/src/resources/admin/organization/projects/spend-alerts.ts +33 -1
- package/node_modules/openai/src/resources/admin/organization/projects/spend-limit.ts +156 -0
- package/node_modules/openai/src/resources/admin/organization/projects/users/index.ts +1 -1
- package/node_modules/openai/src/resources/admin/organization/projects/users/roles.ts +1 -1
- package/node_modules/openai/src/resources/admin/organization/projects/users/users.ts +1 -1
- package/node_modules/openai/src/resources/admin/organization/projects/users.ts +1 -1
- package/node_modules/openai/src/resources/admin/organization/projects.ts +1 -1
- package/node_modules/openai/src/resources/admin/organization/roles.ts +1 -1
- package/node_modules/openai/src/resources/admin/organization/spend-alerts.ts +19 -1
- package/node_modules/openai/src/resources/admin/organization/spend-limit.ts +144 -0
- package/node_modules/openai/src/resources/admin/organization/usage.ts +706 -89
- package/node_modules/openai/src/resources/admin/organization/users/index.ts +1 -1
- package/node_modules/openai/src/resources/admin/organization/users/roles.ts +1 -1
- package/node_modules/openai/src/resources/admin/organization/users/users.ts +1 -1
- package/node_modules/openai/src/resources/admin/organization/users.ts +1 -1
- package/node_modules/openai/src/resources/admin/organization.ts +1 -1
- package/node_modules/openai/src/resources/admin.ts +1 -1
- package/node_modules/openai/src/resources/audio/audio.ts +4 -1
- package/node_modules/openai/src/resources/audio/index.ts +2 -1
- package/node_modules/openai/src/resources/audio/speech.ts +4 -3
- package/node_modules/openai/src/resources/audio/transcriptions.ts +51 -13
- package/node_modules/openai/src/resources/audio/translations.ts +5 -3
- package/node_modules/openai/src/resources/audio.ts +1 -1
- package/node_modules/openai/src/resources/batches.ts +10 -9
- package/node_modules/openai/src/resources/beta/agents/agents.ts +4627 -0
- package/node_modules/openai/src/resources/beta/agents/environments/environments.ts +111 -0
- package/node_modules/openai/src/resources/beta/agents/environments/files.ts +169 -0
- package/node_modules/openai/src/resources/beta/agents/environments/index.ts +19 -0
- package/node_modules/openai/src/resources/beta/agents/environments/templates.ts +535 -0
- package/node_modules/openai/src/resources/beta/agents/environments.ts +3 -0
- package/node_modules/openai/src/resources/beta/agents/index.ts +127 -0
- package/node_modules/openai/src/resources/beta/agents/sessions/artifacts.ts +249 -0
- package/node_modules/openai/src/resources/beta/agents/sessions/events.ts +94 -0
- package/node_modules/openai/src/resources/beta/agents/sessions/index.ts +24 -0
- package/node_modules/openai/src/resources/beta/agents/sessions/items.ts +59 -0
- package/node_modules/openai/src/resources/beta/agents/sessions/sessions.ts +403 -0
- package/node_modules/openai/src/resources/beta/agents/sessions/subagents/index.ts +5 -0
- package/node_modules/openai/src/resources/beta/agents/sessions/subagents/items.ts +65 -0
- package/node_modules/openai/src/resources/beta/agents/sessions/subagents/subagents.ts +113 -0
- package/node_modules/openai/src/resources/beta/agents/sessions/subagents/turns/index.ts +4 -0
- package/node_modules/openai/src/resources/beta/agents/sessions/subagents/turns/items.ts +70 -0
- package/node_modules/openai/src/resources/beta/agents/sessions/subagents/turns/turns.ts +111 -0
- package/node_modules/openai/src/resources/beta/agents/sessions/subagents/turns.ts +3 -0
- package/node_modules/openai/src/resources/beta/agents/sessions/subagents.ts +3 -0
- package/node_modules/openai/src/resources/beta/agents/sessions/turns.ts +159 -0
- package/node_modules/openai/src/resources/beta/agents/sessions.ts +3 -0
- package/node_modules/openai/src/resources/beta/agents/vaults/credentials.ts +693 -0
- package/node_modules/openai/src/resources/beta/agents/vaults/index.ts +29 -0
- package/node_modules/openai/src/resources/beta/agents/vaults/vaults.ts +243 -0
- package/node_modules/openai/src/resources/beta/agents/vaults.ts +3 -0
- package/node_modules/openai/src/resources/beta/agents.ts +3 -0
- package/node_modules/openai/src/resources/beta/assistants.ts +154 -172
- package/node_modules/openai/src/resources/beta/beta.ts +578 -3
- package/node_modules/openai/src/resources/beta/chatkit/chatkit.ts +1 -1
- package/node_modules/openai/src/resources/beta/chatkit/index.ts +1 -1
- package/node_modules/openai/src/resources/beta/chatkit/sessions.ts +1 -1
- package/node_modules/openai/src/resources/beta/chatkit/threads.ts +1 -1
- package/node_modules/openai/src/resources/beta/chatkit.ts +1 -1
- package/node_modules/openai/src/resources/beta/index.ts +290 -1
- package/node_modules/openai/src/resources/beta/realtime/index.ts +0 -2
- package/node_modules/openai/src/resources/beta/realtime/realtime.ts +0 -2
- package/node_modules/openai/src/resources/beta/realtime/sessions.ts +0 -2
- package/node_modules/openai/src/resources/beta/realtime/transcription-sessions.ts +0 -2
- package/node_modules/openai/src/resources/beta/realtime.ts +0 -2
- package/node_modules/openai/src/resources/beta/responses/index.ts +189 -0
- package/node_modules/openai/src/resources/beta/responses/input-items.ts +105 -0
- package/node_modules/openai/src/resources/beta/responses/input-tokens.ts +249 -0
- package/node_modules/openai/src/resources/beta/responses/internal-base.ts +136 -0
- package/node_modules/openai/src/resources/beta/responses/responses.ts +15060 -0
- package/node_modules/openai/src/resources/beta/responses/ws-base.ts +729 -0
- package/node_modules/openai/src/resources/beta/responses/ws.ts +62 -0
- package/node_modules/openai/src/resources/beta/responses.ts +3 -0
- package/node_modules/openai/src/resources/beta/threads/index.ts +1 -1
- package/node_modules/openai/src/resources/beta/threads/messages.ts +30 -24
- package/node_modules/openai/src/resources/beta/threads/runs/index.ts +2 -2
- package/node_modules/openai/src/resources/beta/threads/runs/runs.ts +47 -93
- package/node_modules/openai/src/resources/beta/threads/runs/steps.ts +15 -16
- package/node_modules/openai/src/resources/beta/threads/runs.ts +1 -1
- package/node_modules/openai/src/resources/beta/threads/threads.ts +54 -51
- package/node_modules/openai/src/resources/beta/threads.ts +1 -1
- package/node_modules/openai/src/resources/beta.ts +1 -1
- package/node_modules/openai/src/resources/chat/chat.ts +1 -1
- package/node_modules/openai/src/resources/chat/completions/completions.ts +762 -108
- package/node_modules/openai/src/resources/chat/completions/index.ts +1 -1
- package/node_modules/openai/src/resources/chat/completions/messages.ts +1 -1
- package/node_modules/openai/src/resources/chat/completions.ts +1 -1
- package/node_modules/openai/src/resources/chat/index.ts +1 -1
- package/node_modules/openai/src/resources/chat.ts +1 -1
- package/node_modules/openai/src/resources/completions.ts +36 -15
- package/node_modules/openai/src/resources/containers/containers.ts +1 -1
- package/node_modules/openai/src/resources/containers/files/content.ts +1 -1
- package/node_modules/openai/src/resources/containers/files/files.ts +1 -1
- package/node_modules/openai/src/resources/containers/files/index.ts +1 -1
- package/node_modules/openai/src/resources/containers/files.ts +1 -1
- package/node_modules/openai/src/resources/containers/index.ts +1 -1
- package/node_modules/openai/src/resources/containers.ts +1 -1
- package/node_modules/openai/src/resources/content-provenance-checks.ts +132 -0
- package/node_modules/openai/src/resources/conversations/conversations.ts +23 -2
- package/node_modules/openai/src/resources/conversations/index.ts +1 -1
- package/node_modules/openai/src/resources/conversations/items.ts +93 -5
- package/node_modules/openai/src/resources/conversations.ts +1 -1
- package/node_modules/openai/src/resources/embeddings.ts +22 -49
- package/node_modules/openai/src/resources/evals/evals.ts +6 -6
- package/node_modules/openai/src/resources/evals/index.ts +1 -1
- package/node_modules/openai/src/resources/evals/runs/index.ts +1 -1
- package/node_modules/openai/src/resources/evals/runs/output-items.ts +1 -1
- package/node_modules/openai/src/resources/evals/runs/runs.ts +119 -191
- package/node_modules/openai/src/resources/evals/runs.ts +1 -1
- package/node_modules/openai/src/resources/evals.ts +1 -1
- package/node_modules/openai/src/resources/files.ts +9 -26
- package/node_modules/openai/src/resources/fine-tuning/alpha/alpha.ts +1 -1
- package/node_modules/openai/src/resources/fine-tuning/alpha/graders.ts +6 -5
- package/node_modules/openai/src/resources/fine-tuning/alpha/index.ts +1 -1
- package/node_modules/openai/src/resources/fine-tuning/alpha.ts +1 -1
- package/node_modules/openai/src/resources/fine-tuning/checkpoints/checkpoints.ts +1 -1
- package/node_modules/openai/src/resources/fine-tuning/checkpoints/index.ts +1 -1
- package/node_modules/openai/src/resources/fine-tuning/checkpoints/permissions.ts +9 -5
- package/node_modules/openai/src/resources/fine-tuning/checkpoints.ts +1 -1
- package/node_modules/openai/src/resources/fine-tuning/fine-tuning.ts +1 -1
- package/node_modules/openai/src/resources/fine-tuning/index.ts +1 -1
- package/node_modules/openai/src/resources/fine-tuning/jobs/checkpoints.ts +1 -1
- package/node_modules/openai/src/resources/fine-tuning/jobs/index.ts +1 -1
- package/node_modules/openai/src/resources/fine-tuning/jobs/jobs.ts +14 -13
- package/node_modules/openai/src/resources/fine-tuning/jobs.ts +1 -1
- package/node_modules/openai/src/resources/fine-tuning/methods.ts +1 -1
- package/node_modules/openai/src/resources/fine-tuning.ts +1 -1
- package/node_modules/openai/src/resources/graders/grader-models.ts +7 -14
- package/node_modules/openai/src/resources/graders/graders.ts +1 -1
- package/node_modules/openai/src/resources/graders/index.ts +1 -1
- package/node_modules/openai/src/resources/graders.ts +1 -1
- package/node_modules/openai/src/resources/images.ts +100 -85
- package/node_modules/openai/src/resources/index.ts +9 -2
- package/node_modules/openai/src/resources/live/api.md +87 -0
- package/node_modules/openai/src/resources/live/forks/forks.ts +169 -0
- package/node_modules/openai/src/resources/live/forks/index.ts +5 -0
- package/node_modules/openai/src/resources/live/forks/internal-base.ts +126 -0
- package/node_modules/openai/src/resources/live/forks/ws-base.ts +700 -0
- package/node_modules/openai/src/resources/live/forks/ws.ts +47 -0
- package/node_modules/openai/src/resources/live/forks.ts +3 -0
- package/node_modules/openai/src/resources/live/index.ts +20 -0
- package/node_modules/openai/src/resources/live/internal-base.ts +123 -0
- package/node_modules/openai/src/resources/live/live.ts +2296 -0
- package/node_modules/openai/src/resources/live/sessions.ts +343 -0
- package/node_modules/openai/src/resources/live/sideband/index.ts +10 -0
- package/node_modules/openai/src/resources/live/sideband/internal-base.ts +126 -0
- package/node_modules/openai/src/resources/live/sideband/sideband.ts +58 -0
- package/node_modules/openai/src/resources/live/sideband/ws-base.ts +710 -0
- package/node_modules/openai/src/resources/live/sideband/ws.ts +47 -0
- package/node_modules/openai/src/resources/live/sideband.ts +3 -0
- package/node_modules/openai/src/resources/live/ws-base.ts +696 -0
- package/node_modules/openai/src/resources/live/ws.ts +43 -0
- package/node_modules/openai/src/resources/live.ts +3 -0
- package/node_modules/openai/src/resources/models.ts +6 -1
- package/node_modules/openai/src/resources/moderations.ts +6 -5
- package/node_modules/openai/src/resources/realtime/api.md +1 -0
- package/node_modules/openai/src/resources/realtime/calls.ts +50 -2
- package/node_modules/openai/src/resources/realtime/client-secrets.ts +27 -10
- package/node_modules/openai/src/resources/realtime/index.ts +8 -2
- package/node_modules/openai/src/resources/realtime/realtime.ts +93 -35
- package/node_modules/openai/src/resources/realtime.ts +1 -1
- package/node_modules/openai/src/resources/responses/api.md +20 -0
- package/node_modules/openai/src/resources/responses/index.ts +1 -1
- package/node_modules/openai/src/resources/responses/input-items.ts +1 -1
- package/node_modules/openai/src/resources/responses/input-tokens.ts +26 -16
- package/node_modules/openai/src/resources/responses/internal-base.ts +33 -14
- package/node_modules/openai/src/resources/responses/responses.ts +4150 -792
- package/node_modules/openai/src/resources/responses/ws-base.ts +147 -31
- package/node_modules/openai/src/resources/responses/ws.ts +33 -9
- package/node_modules/openai/src/resources/responses.ts +1 -1
- package/node_modules/openai/src/resources/safety/alerts.ts +51 -0
- package/node_modules/openai/src/resources/safety/index.ts +4 -0
- package/node_modules/openai/src/resources/safety/safety.ts +15 -0
- package/node_modules/openai/src/resources/safety.ts +3 -0
- package/node_modules/openai/src/resources/shared.ts +98 -41
- package/node_modules/openai/src/resources/skills/content.ts +1 -1
- package/node_modules/openai/src/resources/skills/index.ts +1 -1
- package/node_modules/openai/src/resources/skills/skills.ts +4 -2
- package/node_modules/openai/src/resources/skills/versions/content.ts +1 -1
- package/node_modules/openai/src/resources/skills/versions/index.ts +1 -1
- package/node_modules/openai/src/resources/skills/versions/versions.ts +4 -2
- package/node_modules/openai/src/resources/skills/versions.ts +1 -1
- package/node_modules/openai/src/resources/skills.ts +1 -1
- package/node_modules/openai/src/resources/uploads/index.ts +1 -1
- package/node_modules/openai/src/resources/uploads/parts.ts +6 -5
- package/node_modules/openai/src/resources/uploads/uploads.ts +12 -12
- package/node_modules/openai/src/resources/uploads.ts +1 -1
- package/node_modules/openai/src/resources/vector-stores/file-batches.ts +24 -89
- package/node_modules/openai/src/resources/vector-stores/files.ts +12 -52
- package/node_modules/openai/src/resources/vector-stores/index.ts +1 -1
- package/node_modules/openai/src/resources/vector-stores/vector-stores.ts +4 -4
- package/node_modules/openai/src/resources/vector-stores.ts +1 -1
- package/node_modules/openai/src/resources/videos.ts +63 -2
- package/node_modules/openai/src/resources/webhooks/api.md +40 -17
- package/node_modules/openai/src/resources/webhooks/event-types.ts +21 -0
- package/node_modules/openai/src/resources/webhooks/index.ts +2 -1
- package/node_modules/openai/src/resources/webhooks/webhooks.ts +694 -69
- package/node_modules/openai/src/resources/webhooks.ts +1 -1
- package/node_modules/openai/src/tsconfig.json +6 -3
- package/node_modules/openai/src/version.ts +2 -1
- package/node_modules/openai/version.js +2 -1
- package/node_modules/openai/version.mjs +2 -1
- package/package.json +5 -5
- package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.js +0 -832
- package/node_modules/@earendil-works/pi-ai/dist/images-models.js +0 -143
- package/node_modules/@earendil-works/pi-ai/dist/providers/openrouter-images.js +0 -22
- /package/node_modules/@aws-sdk/{credential-provider-sso → client-bedrock-runtime}/node_modules/@aws-sdk/token-providers/LICENSE +0 -0
- /package/node_modules/@aws-sdk/{credential-provider-sso → client-bedrock-runtime}/node_modules/@aws-sdk/token-providers/README.md +0 -0
- /package/node_modules/@aws-sdk/{credential-provider-sso → client-bedrock-runtime}/node_modules/@aws-sdk/token-providers/dist-cjs/index.js +0 -0
- /package/node_modules/@aws-sdk/{credential-provider-sso → client-bedrock-runtime}/node_modules/@aws-sdk/token-providers/dist-es/constants.js +0 -0
- /package/node_modules/@aws-sdk/{credential-provider-sso → client-bedrock-runtime}/node_modules/@aws-sdk/token-providers/dist-es/fromEnvSigningName.js +0 -0
- /package/node_modules/@aws-sdk/{credential-provider-sso → client-bedrock-runtime}/node_modules/@aws-sdk/token-providers/dist-es/fromSso.js +0 -0
- /package/node_modules/@aws-sdk/{credential-provider-sso → client-bedrock-runtime}/node_modules/@aws-sdk/token-providers/dist-es/fromStatic.js +0 -0
- /package/node_modules/@aws-sdk/{credential-provider-sso → client-bedrock-runtime}/node_modules/@aws-sdk/token-providers/dist-es/getNewSsoOidcToken.js +0 -0
- /package/node_modules/@aws-sdk/{credential-provider-sso → client-bedrock-runtime}/node_modules/@aws-sdk/token-providers/dist-es/getSsoOidcClient.js +0 -0
- /package/node_modules/@aws-sdk/{credential-provider-sso → client-bedrock-runtime}/node_modules/@aws-sdk/token-providers/dist-es/index.js +0 -0
- /package/node_modules/@aws-sdk/{credential-provider-sso → client-bedrock-runtime}/node_modules/@aws-sdk/token-providers/dist-es/nodeProvider.js +0 -0
- /package/node_modules/@aws-sdk/{credential-provider-sso → client-bedrock-runtime}/node_modules/@aws-sdk/token-providers/dist-es/validateTokenExpiry.js +0 -0
- /package/node_modules/@aws-sdk/{credential-provider-sso → client-bedrock-runtime}/node_modules/@aws-sdk/token-providers/dist-es/validateTokenKey.js +0 -0
- /package/node_modules/@aws-sdk/{credential-provider-sso → client-bedrock-runtime}/node_modules/@aws-sdk/token-providers/dist-es/writeSSOTokenToFile.js +0 -0
- /package/node_modules/@earendil-works/pi-ai/dist/{auth/oauth → utils}/oauth-page.js +0 -0
|
@@ -1,34 +1,676 @@
|
|
|
1
1
|
import type { JSONSchema, JSONSchemaDefinition } from './jsonschema';
|
|
2
|
+
import { hasOwn } from '../internal/utils';
|
|
2
3
|
|
|
4
|
+
const JSON_SCHEMA_ANNOTATION_KEYWORDS = new Set([
|
|
5
|
+
'$comment',
|
|
6
|
+
'default',
|
|
7
|
+
'description',
|
|
8
|
+
'examples',
|
|
9
|
+
'readOnly',
|
|
10
|
+
'title',
|
|
11
|
+
'writeOnly',
|
|
12
|
+
]);
|
|
13
|
+
|
|
14
|
+
const JSON_SCHEMA_ROOT_METADATA_KEYWORDS = new Set(['$id', '$schema']);
|
|
15
|
+
|
|
16
|
+
const JSON_SCHEMA_OBJECT_KEYWORDS = new Set([
|
|
17
|
+
'additionalProperties',
|
|
18
|
+
'dependencies',
|
|
19
|
+
'maxProperties',
|
|
20
|
+
'minProperties',
|
|
21
|
+
'patternProperties',
|
|
22
|
+
'properties',
|
|
23
|
+
'propertyNames',
|
|
24
|
+
'required',
|
|
25
|
+
]);
|
|
26
|
+
|
|
27
|
+
const JSON_SCHEMA_SINGLE_SCHEMA_KEYWORDS = [
|
|
28
|
+
'additionalItems',
|
|
29
|
+
'additionalProperties',
|
|
30
|
+
'contains',
|
|
31
|
+
'contentSchema',
|
|
32
|
+
'else',
|
|
33
|
+
'if',
|
|
34
|
+
'not',
|
|
35
|
+
'propertyNames',
|
|
36
|
+
'then',
|
|
37
|
+
'unevaluatedItems',
|
|
38
|
+
'unevaluatedProperties',
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
const JSON_SCHEMA_ARRAY_SCHEMA_KEYWORDS = ['allOf', 'anyOf', 'items', 'oneOf', 'prefixItems'];
|
|
42
|
+
|
|
43
|
+
const JSON_SCHEMA_MAP_SCHEMA_KEYWORDS = [
|
|
44
|
+
'$defs',
|
|
45
|
+
'definitions',
|
|
46
|
+
'dependentSchemas',
|
|
47
|
+
'dependencies',
|
|
48
|
+
'patternProperties',
|
|
49
|
+
'properties',
|
|
50
|
+
];
|
|
51
|
+
|
|
52
|
+
const JSON_SCHEMA_UNSUPPORTED_SCHEMA_KEYWORDS = new Set([
|
|
53
|
+
'$anchor',
|
|
54
|
+
'$dynamicAnchor',
|
|
55
|
+
'$dynamicRef',
|
|
56
|
+
'$recursiveAnchor',
|
|
57
|
+
'$recursiveRef',
|
|
58
|
+
'allOf',
|
|
59
|
+
'contains',
|
|
60
|
+
'contentEncoding',
|
|
61
|
+
'contentMediaType',
|
|
62
|
+
'contentSchema',
|
|
63
|
+
'dependentRequired',
|
|
64
|
+
'dependentSchemas',
|
|
65
|
+
'dependencies',
|
|
66
|
+
'else',
|
|
67
|
+
'if',
|
|
68
|
+
'maxContains',
|
|
69
|
+
'maxProperties',
|
|
70
|
+
'minContains',
|
|
71
|
+
'minProperties',
|
|
72
|
+
'not',
|
|
73
|
+
'oneOf',
|
|
74
|
+
'patternProperties',
|
|
75
|
+
'prefixItems',
|
|
76
|
+
'propertyNames',
|
|
77
|
+
'then',
|
|
78
|
+
'unevaluatedItems',
|
|
79
|
+
'unevaluatedProperties',
|
|
80
|
+
'uniqueItems',
|
|
81
|
+
]);
|
|
82
|
+
|
|
83
|
+
const MERGEABLE_OBJECT_ALL_OF_KEYWORDS = new Set([
|
|
84
|
+
...JSON_SCHEMA_ANNOTATION_KEYWORDS,
|
|
85
|
+
'additionalProperties',
|
|
86
|
+
'properties',
|
|
87
|
+
'required',
|
|
88
|
+
'type',
|
|
89
|
+
]);
|
|
90
|
+
|
|
91
|
+
/** Visits a nested schema together with its root-relative path and containing schema keyword. */
|
|
92
|
+
type JSONSchemaChildVisitor = (schema: unknown, path: string[], keyword: string) => void;
|
|
93
|
+
|
|
94
|
+
/** Assigns schema keywords without invoking the inherited `__proto__` setter. */
|
|
95
|
+
function assignSchema<T extends object>(target: T, ...sources: object[]): T {
|
|
96
|
+
for (const source of sources) {
|
|
97
|
+
if (Object.prototype.propertyIsEnumerable.call(source, '__proto__') && !hasOwn(target, '__proto__')) {
|
|
98
|
+
Object.defineProperty(target, '__proto__', {
|
|
99
|
+
value: undefined,
|
|
100
|
+
writable: true,
|
|
101
|
+
enumerable: true,
|
|
102
|
+
configurable: true,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
Object.assign(target, source);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return target;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Visits only values carried by JSON Schema keywords that contain schemas.
|
|
114
|
+
* Literal payloads such as enum, const, and default deliberately do not
|
|
115
|
+
* participate.
|
|
116
|
+
*/
|
|
117
|
+
export function forEachJSONSchemaChild(
|
|
118
|
+
schema: JSONSchema | Record<string, unknown>,
|
|
119
|
+
path: string[],
|
|
120
|
+
visit: JSONSchemaChildVisitor,
|
|
121
|
+
): void {
|
|
122
|
+
// SAFETY: This is an object schema at this traversal point; the record view permits dynamic keyword access while individual values remain subject to schema checks.
|
|
123
|
+
const record = schema as Record<string, unknown>;
|
|
124
|
+
|
|
125
|
+
for (const keyword of JSON_SCHEMA_SINGLE_SCHEMA_KEYWORDS) {
|
|
126
|
+
if (keyword in record) {
|
|
127
|
+
visit(record[keyword], [...path, keyword], keyword);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
for (const keyword of JSON_SCHEMA_ARRAY_SCHEMA_KEYWORDS) {
|
|
132
|
+
const children = record[keyword];
|
|
133
|
+
if (Array.isArray(children)) {
|
|
134
|
+
for (const [index, child] of children.entries()) {
|
|
135
|
+
visit(child, [...path, keyword, String(index)], keyword);
|
|
136
|
+
}
|
|
137
|
+
} else if (children !== undefined) {
|
|
138
|
+
visit(children, [...path, keyword], keyword);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
for (const keyword of JSON_SCHEMA_MAP_SCHEMA_KEYWORDS) {
|
|
143
|
+
const children = record[keyword];
|
|
144
|
+
if (!isObject(children)) {
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
for (const [key, child] of Object.entries(children)) {
|
|
149
|
+
// Draft 7 dependencies also permits property dependency arrays. They
|
|
150
|
+
// are not schemas and must not be traversed as literal JSON payloads.
|
|
151
|
+
if (keyword === 'dependencies' && !isSchemaDefinition(child)) {
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
visit(child, [...path, keyword, key], keyword);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Returns a cloned schema normalized for strict Structured Outputs.
|
|
161
|
+
*
|
|
162
|
+
* Object properties become required, object schemas are closed to additional
|
|
163
|
+
* properties, and representable local references and intersections are preserved.
|
|
164
|
+
*
|
|
165
|
+
* @throws {Error} If the schema cannot be represented without changing its validation semantics.
|
|
166
|
+
*/
|
|
3
167
|
export function toStrictJsonSchema(schema: JSONSchema): JSONSchema {
|
|
4
|
-
|
|
168
|
+
const schemaCopy = structuredClone(schema);
|
|
169
|
+
// JSON serialization omits undefined object properties. Drop optional
|
|
170
|
+
// placeholders before any structural checks so they cannot accidentally
|
|
171
|
+
// look like validation-bearing schema keywords.
|
|
172
|
+
stripUndefinedSchemaKeywords(schemaCopy);
|
|
173
|
+
normalizeSingletonTypeArrays(schemaCopy);
|
|
174
|
+
// Root ref/allOf normalization can promote a nested branch into the root.
|
|
175
|
+
// Reject separate resource scopes while their original nesting is still
|
|
176
|
+
// visible so branch-local definitions cannot be rebound at the root.
|
|
177
|
+
assertNoNestedSchemaIds(schemaCopy);
|
|
178
|
+
normalizeRootRefAndAllOf(schemaCopy);
|
|
179
|
+
|
|
180
|
+
if (schemaCopy.type !== 'object') {
|
|
181
|
+
throw new Error(
|
|
182
|
+
`Root schema must have type: 'object' but got type: ${
|
|
183
|
+
schemaCopy.type ? `'${schemaCopy.type}'` : 'undefined'
|
|
184
|
+
}`,
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
if (schemaCopy.anyOf !== undefined) {
|
|
5
188
|
throw new Error(
|
|
6
|
-
|
|
189
|
+
'Root schema must not use `anyOf` because strict Structured Outputs requires a root object without a union.',
|
|
7
190
|
);
|
|
8
191
|
}
|
|
9
192
|
|
|
10
|
-
|
|
11
|
-
|
|
193
|
+
validateRefSchemas(schemaCopy, [], schemaCopy);
|
|
194
|
+
preserveAllOfRefTargets(schemaCopy);
|
|
195
|
+
validateRefSchemas(schemaCopy, [], schemaCopy);
|
|
196
|
+
rewriteLocalRefsIntoFilteredAnyOfBranches(schemaCopy);
|
|
197
|
+
// Resolve representable object intersections before recursive
|
|
198
|
+
// strictification closes referenced definitions. Otherwise a definition
|
|
199
|
+
// reached through an allOf ref would be closed in isolation before its
|
|
200
|
+
// sibling object properties can be merged.
|
|
201
|
+
normalizeObjectAllOfBranches(schemaCopy, [], schemaCopy);
|
|
202
|
+
const strictSchema = ensureStrictJsonSchema(schemaCopy, [], schemaCopy);
|
|
203
|
+
validateRefSchemas(strictSchema, [], strictSchema);
|
|
204
|
+
return strictSchema;
|
|
12
205
|
}
|
|
13
206
|
|
|
14
|
-
function
|
|
15
|
-
if (
|
|
207
|
+
function stripUndefinedSchemaKeywords(schema: JSONSchemaDefinition, visited = new Set<JSONSchema>()): void {
|
|
208
|
+
if (!isObject(schema) || visited.has(schema)) {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
visited.add(schema);
|
|
212
|
+
|
|
213
|
+
// SAFETY: This is an object schema at this traversal point; the record view permits dynamic keyword access while individual values remain subject to schema checks.
|
|
214
|
+
const schemaRecord = schema as Record<string, unknown>;
|
|
215
|
+
for (const keyword of Object.keys(schemaRecord)) {
|
|
216
|
+
if (schemaRecord[keyword] === undefined) {
|
|
217
|
+
delete schemaRecord[keyword];
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
forEachJSONSchemaChild(schema, [], (child) => {
|
|
222
|
+
// SAFETY: The schema-child visitor supplies only recognized object or boolean schema positions; the recursive helper validates their contents.
|
|
223
|
+
stripUndefinedSchemaKeywords(child as JSONSchemaDefinition, visited);
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Root ref inlining and singleton allOf flattening can expose each other.
|
|
229
|
+
* Iterate until flattening no longer produces another root ref so every
|
|
230
|
+
* exactly representable chain reaches its final object form before the root
|
|
231
|
+
* type check runs.
|
|
232
|
+
*/
|
|
233
|
+
function normalizeRootRefAndAllOf(schema: JSONSchema): void {
|
|
234
|
+
const seenRefs = new Set<string>();
|
|
235
|
+
while (true) {
|
|
236
|
+
if (typeof schema.$ref === 'string') {
|
|
237
|
+
if (seenRefs.has(schema.$ref)) {
|
|
238
|
+
throw new Error('Cyclic local $ref at `<root>` is not supported: ' + JSON.stringify(schema.$ref));
|
|
239
|
+
}
|
|
240
|
+
seenRefs.add(schema.$ref);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
inlineRootRefObject(schema);
|
|
244
|
+
preserveAllOfRefTargets(schema, true);
|
|
245
|
+
normalizeRootAllOf(schema);
|
|
246
|
+
const normalizedAnyOf = normalizeRootAnyOf(schema);
|
|
247
|
+
|
|
248
|
+
if (schema.$ref === undefined && !normalizedAnyOf) {
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Some Standard Schema converters emit the root object through a local ref,
|
|
256
|
+
* with the referenced schema stored in a root definition map. Structured
|
|
257
|
+
* Outputs requires the root itself to be an object, so inline that safe,
|
|
258
|
+
* definition-only form while keeping the root maps available for every local
|
|
259
|
+
* pointer in the schema.
|
|
260
|
+
*/
|
|
261
|
+
function inlineRootRefObject(schema: JSONSchema): void {
|
|
262
|
+
let ref = schema.$ref;
|
|
263
|
+
if (ref === undefined) {
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
assertLocalRootRef(ref);
|
|
268
|
+
if (!hasOnlyRootRefAndDefinitions(schema)) {
|
|
269
|
+
throw new Error(
|
|
270
|
+
'Schema $ref at `<root>` has non-metadata siblings that Draft 7 ignores and cannot be represented in strict Structured Outputs.',
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const seenRefs = new Set<string>();
|
|
275
|
+
// Ref siblings are annotations in Draft 7, so keep them while following
|
|
276
|
+
// aliases. Add outer annotations first so they win over inner aliases and
|
|
277
|
+
// the final target when the effective root is assembled.
|
|
278
|
+
const inheritedAnnotations: Record<string, unknown> = Object.fromEntries(
|
|
279
|
+
Object.entries(schema).filter(([keyword]) => JSON_SCHEMA_ANNOTATION_KEYWORDS.has(keyword)),
|
|
280
|
+
);
|
|
281
|
+
let resolved: JSONSchema;
|
|
282
|
+
while (true) {
|
|
283
|
+
if (seenRefs.has(ref)) {
|
|
284
|
+
throw new Error('Cyclic local $ref at `<root>` is not supported: ' + JSON.stringify(ref));
|
|
285
|
+
}
|
|
286
|
+
seenRefs.add(ref);
|
|
287
|
+
|
|
288
|
+
const target = resolveLocalRef(schema, ref);
|
|
289
|
+
if (target === undefined) {
|
|
290
|
+
throw new Error(
|
|
291
|
+
'Local $ref at `<root>` does not resolve to an object or boolean schema: ' + JSON.stringify(ref),
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
if (typeof target === 'boolean') {
|
|
295
|
+
throw new TypeError('Expected object schema but got boolean; path=<root>');
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
const nextRef = target.$ref;
|
|
299
|
+
if (nextRef === undefined) {
|
|
300
|
+
resolved = target;
|
|
301
|
+
break;
|
|
302
|
+
}
|
|
303
|
+
assertLocalRootRef(nextRef);
|
|
304
|
+
if (seenRefs.has(nextRef)) {
|
|
305
|
+
throw new Error('Cyclic local $ref at `<root>` is not supported: ' + JSON.stringify(nextRef));
|
|
306
|
+
}
|
|
307
|
+
if (!hasOnlyRefAndAnnotations(target)) {
|
|
308
|
+
throw new Error(
|
|
309
|
+
'Schema $ref in root chain has non-annotation siblings that Draft 7 ignores and cannot be represented in strict Structured Outputs.',
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
|
+
for (const keyword of JSON_SCHEMA_ANNOTATION_KEYWORDS) {
|
|
313
|
+
if (!(keyword in inheritedAnnotations) && keyword in target) {
|
|
314
|
+
// SAFETY: This is an object schema at this traversal point; the record view permits dynamic keyword access while individual values remain subject to schema checks.
|
|
315
|
+
inheritedAnnotations[keyword] = (target as Record<string, unknown>)[keyword];
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
ref = nextRef;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
const rootDefinitions = schema.$defs;
|
|
322
|
+
const legacyDefinitions = schema.definitions;
|
|
323
|
+
const rootMetadata = Object.fromEntries(
|
|
324
|
+
Object.entries(schema).filter(
|
|
325
|
+
([keyword]) =>
|
|
326
|
+
JSON_SCHEMA_ANNOTATION_KEYWORDS.has(keyword) || JSON_SCHEMA_ROOT_METADATA_KEYWORDS.has(keyword),
|
|
327
|
+
),
|
|
328
|
+
);
|
|
329
|
+
const inlined = structuredClone(resolved);
|
|
330
|
+
// A target's definition map lives below the target's original pointer, not
|
|
331
|
+
// at the document root. Keep the outer document map at the root so existing
|
|
332
|
+
// absolute refs retain their meaning; the retained outer map also keeps the
|
|
333
|
+
// target's nested map reachable at its original pointer.
|
|
334
|
+
for (const keyword of ['$defs', 'definitions'] as const) {
|
|
335
|
+
if (schema[keyword] !== undefined && inlined[keyword] !== undefined) {
|
|
336
|
+
delete inlined[keyword];
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
// SAFETY: This is an object schema at this traversal point; the record view permits dynamic keyword access while individual values remain subject to schema checks.
|
|
340
|
+
const schemaRecord = schema as Record<string, unknown>;
|
|
341
|
+
|
|
342
|
+
for (const keyword of Object.keys(schema)) {
|
|
343
|
+
delete schemaRecord[keyword];
|
|
344
|
+
}
|
|
345
|
+
assignSchema(schema, inlined, inheritedAnnotations, rootMetadata);
|
|
346
|
+
if (rootDefinitions !== undefined) {
|
|
347
|
+
schema.$defs = rootDefinitions;
|
|
348
|
+
}
|
|
349
|
+
if (legacyDefinitions !== undefined) {
|
|
350
|
+
schema.definitions = legacyDefinitions;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Root object validation runs before recursive strictification, so normalize
|
|
356
|
+
* the same exactly representable allOf forms here that the recursive pass
|
|
357
|
+
* handles for nested schemas.
|
|
358
|
+
*/
|
|
359
|
+
function normalizeRootAllOf(schema: JSONSchema): void {
|
|
360
|
+
while (schema.allOf !== undefined) {
|
|
361
|
+
// Root normalization runs before recursive strictification so the root
|
|
362
|
+
// type check can see an inlined object. Normalize nested intersections in
|
|
363
|
+
// its branches first for the same associative allOf case handled by the
|
|
364
|
+
// later recursive pass.
|
|
365
|
+
if (Array.isArray(schema.allOf)) {
|
|
366
|
+
for (const [index, branch] of schema.allOf.entries()) {
|
|
367
|
+
normalizeObjectAllOfBranches(branch, ['allOf', String(index)], schema);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
if (mergeObjectAllOf(schema, [], schema)) {
|
|
372
|
+
// Removing neutral true branches can leave a singleton allOf behind;
|
|
373
|
+
// keep normalizing until the root reaches its final object form.
|
|
374
|
+
continue;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
const allOf = schema.allOf;
|
|
378
|
+
if (!Array.isArray(allOf) || allOf.length !== 1 || !hasOnlyRootAllOfMetadataSiblings(schema)) {
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
const branch = allOf[0];
|
|
383
|
+
if (!isObject(branch)) {
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
const rootMetadata = { ...schema };
|
|
388
|
+
delete rootMetadata.allOf;
|
|
389
|
+
const normalized = structuredClone(branch);
|
|
390
|
+
// SAFETY: This is an object schema at this traversal point; the record view permits dynamic keyword access while individual values remain subject to schema checks.
|
|
391
|
+
const schemaRecord = schema as Record<string, unknown>;
|
|
392
|
+
|
|
393
|
+
for (const keyword of Object.keys(schema)) {
|
|
394
|
+
delete schemaRecord[keyword];
|
|
395
|
+
}
|
|
396
|
+
assignSchema(schema, normalized, rootMetadata);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* A singleton root anyOf with no validating siblings is equivalent to its
|
|
402
|
+
* only branch. Flatten it before the root-union check so converters that
|
|
403
|
+
* retain a redundant object wrapper can still produce a strict root object.
|
|
404
|
+
*/
|
|
405
|
+
function normalizeRootAnyOf(schema: JSONSchema): boolean {
|
|
406
|
+
const anyOf = schema.anyOf;
|
|
407
|
+
if (!Array.isArray(anyOf) || !hasOnlyRootAnyOfMetadataSiblings(schema)) {
|
|
16
408
|
return false;
|
|
17
409
|
}
|
|
18
|
-
|
|
19
|
-
|
|
410
|
+
|
|
411
|
+
// `false` contributes no instances to a union. Keep the original array in
|
|
412
|
+
// place until promotion so refs into the surviving branch can be rewritten
|
|
413
|
+
// from their original index, while refs into removed false branches become
|
|
414
|
+
// dangling and remain fail closed after the wrapper disappears.
|
|
415
|
+
const realBranches = anyOf
|
|
416
|
+
.map((branch, index) => ({ branch, index }))
|
|
417
|
+
.filter(({ branch }) => branch !== false);
|
|
418
|
+
if (realBranches.length !== 1) {
|
|
419
|
+
return false;
|
|
20
420
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
421
|
+
|
|
422
|
+
const { branch, index: branchIndex } = realBranches[0]!;
|
|
423
|
+
if (!isObject(branch) || !isObjectOnlySchema(branch, schema)) {
|
|
424
|
+
return false;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
const definitionRenames = planPromotedRootAnyOfDefinitionRenames(schema, branch);
|
|
428
|
+
rewriteLocalRefsIntoPromotedRootAnyOfBranch(schema, branchIndex, definitionRenames);
|
|
429
|
+
const rootMetadata = { ...schema };
|
|
430
|
+
delete rootMetadata.anyOf;
|
|
431
|
+
const normalized = structuredClone(branch);
|
|
432
|
+
|
|
433
|
+
for (const keyword of ['$defs', 'definitions'] as const) {
|
|
434
|
+
const rootDefinitions = schema[keyword];
|
|
435
|
+
const branchDefinitions = normalized[keyword];
|
|
436
|
+
if (!isObject(rootDefinitions) || !isObject(branchDefinitions)) {
|
|
437
|
+
continue;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
const renames = definitionRenames.get(keyword);
|
|
441
|
+
const mergedDefinitions = { ...rootDefinitions };
|
|
442
|
+
for (const [name, definition] of Object.entries(branchDefinitions)) {
|
|
443
|
+
Object.defineProperty(mergedDefinitions, renames?.get(name) ?? name, {
|
|
444
|
+
value: definition,
|
|
445
|
+
writable: true,
|
|
446
|
+
enumerable: true,
|
|
447
|
+
configurable: true,
|
|
448
|
+
});
|
|
24
449
|
}
|
|
450
|
+
normalized[keyword] = mergedDefinitions;
|
|
451
|
+
delete rootMetadata[keyword];
|
|
25
452
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
453
|
+
|
|
454
|
+
// SAFETY: This is an object schema at this traversal point; the record view permits dynamic keyword access while individual values remain subject to schema checks.
|
|
455
|
+
const schemaRecord = schema as Record<string, unknown>;
|
|
456
|
+
|
|
457
|
+
for (const keyword of Object.keys(schema)) {
|
|
458
|
+
delete schemaRecord[keyword];
|
|
459
|
+
}
|
|
460
|
+
assignSchema(schema, normalized, rootMetadata);
|
|
461
|
+
return true;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
type RootDefinitionKeyword = '$defs' | 'definitions';
|
|
465
|
+
type PromotedRootAnyOfDefinitionRenames = Map<RootDefinitionKeyword, Map<string, string>>;
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* Root and promoted branch definition maps occupy the same pointer after
|
|
469
|
+
* promotion. Give conflicting branch definitions stable aliases before refs
|
|
470
|
+
* are rewritten so neither original target is rebound.
|
|
471
|
+
*/
|
|
472
|
+
function planPromotedRootAnyOfDefinitionRenames(
|
|
473
|
+
root: JSONSchema,
|
|
474
|
+
branch: JSONSchema,
|
|
475
|
+
): PromotedRootAnyOfDefinitionRenames {
|
|
476
|
+
const renames: PromotedRootAnyOfDefinitionRenames = new Map();
|
|
477
|
+
|
|
478
|
+
for (const keyword of ['$defs', 'definitions'] as const) {
|
|
479
|
+
const rootDefinitions = root[keyword];
|
|
480
|
+
const branchDefinitions = branch[keyword];
|
|
481
|
+
if (!isObject(rootDefinitions) || !isObject(branchDefinitions)) {
|
|
482
|
+
continue;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
const usedNames = new Set([...Object.keys(rootDefinitions), ...Object.keys(branchDefinitions)]);
|
|
486
|
+
const keywordRenames = new Map<string, string>();
|
|
487
|
+
let aliasIndex = 0;
|
|
488
|
+
|
|
489
|
+
for (const [name, definition] of Object.entries(branchDefinitions)) {
|
|
490
|
+
if (!hasOwn(rootDefinitions, name) || schemasEqual(rootDefinitions[name], definition)) {
|
|
491
|
+
continue;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
let alias = '__openai_strict_anyOf_definition_' + aliasIndex++;
|
|
495
|
+
while (usedNames.has(alias)) {
|
|
496
|
+
alias = '__openai_strict_anyOf_definition_' + aliasIndex++;
|
|
497
|
+
}
|
|
498
|
+
usedNames.add(alias);
|
|
499
|
+
keywordRenames.set(name, alias);
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
if (keywordRenames.size > 0) {
|
|
503
|
+
renames.set(keyword, keywordRenames);
|
|
29
504
|
}
|
|
30
505
|
}
|
|
31
|
-
|
|
506
|
+
|
|
507
|
+
return renames;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* Promoting a singleton root anyOf branch removes the original anyOf/index
|
|
512
|
+
* pointer prefix. Rewrite refs through that prefix while the old tree still
|
|
513
|
+
* exists so the promoted schema keeps naming the same targets.
|
|
514
|
+
*/
|
|
515
|
+
function rewriteLocalRefsIntoPromotedRootAnyOfBranch(
|
|
516
|
+
root: JSONSchema,
|
|
517
|
+
branchIndex: number,
|
|
518
|
+
definitionRenames: PromotedRootAnyOfDefinitionRenames,
|
|
519
|
+
): void {
|
|
520
|
+
const rewriteRef = (ref: string): string => {
|
|
521
|
+
const parts = parseLocalRef(ref);
|
|
522
|
+
if (parts === undefined || parts[0] !== 'anyOf' || parts[1] !== String(branchIndex)) {
|
|
523
|
+
return ref;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
const promotedParts = parts.slice(2);
|
|
527
|
+
const definitionKeyword = promotedParts[0];
|
|
528
|
+
if (promotedParts.length > 1 && (definitionKeyword === '$defs' || definitionKeyword === 'definitions')) {
|
|
529
|
+
const renamed = definitionRenames.get(definitionKeyword)?.get(promotedParts[1]!);
|
|
530
|
+
if (renamed !== undefined) {
|
|
531
|
+
promotedParts[1] = renamed;
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
return promotedParts.length === 0
|
|
536
|
+
? '#'
|
|
537
|
+
: '#/' + promotedParts.map(encodeJSONPointerTokenForURIFragment).join('/');
|
|
538
|
+
};
|
|
539
|
+
|
|
540
|
+
const rewriteRefs = (value: JSONSchemaDefinition): void => {
|
|
541
|
+
if (!isObject(value)) {
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
if (typeof value.$ref === 'string') {
|
|
546
|
+
value.$ref = rewriteRef(value.$ref);
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
forEachJSONSchemaChild(value, [], (child) => {
|
|
550
|
+
// SAFETY: The schema-child visitor supplies only recognized object or boolean schema positions; the recursive helper validates their contents.
|
|
551
|
+
rewriteRefs(child as JSONSchemaDefinition);
|
|
552
|
+
});
|
|
553
|
+
};
|
|
554
|
+
|
|
555
|
+
rewriteRefs(root);
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
function assertLocalRootRef(ref: unknown): asserts ref is string {
|
|
559
|
+
if (typeof ref !== 'string') {
|
|
560
|
+
throw new TypeError('Received non-string $ref - ' + String(ref) + '; path=<root>');
|
|
561
|
+
}
|
|
562
|
+
if (!ref.startsWith('#')) {
|
|
563
|
+
throw new Error(
|
|
564
|
+
'External $ref at `<root>` is not supported in strict Structured Outputs: ' + JSON.stringify(ref),
|
|
565
|
+
);
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
function hasOnlyRootRefAndDefinitions(schema: JSONSchema): boolean {
|
|
570
|
+
return Object.keys(schema).every(
|
|
571
|
+
(keyword) =>
|
|
572
|
+
keyword === '$ref' ||
|
|
573
|
+
keyword === '$defs' ||
|
|
574
|
+
keyword === 'definitions' ||
|
|
575
|
+
JSON_SCHEMA_ROOT_METADATA_KEYWORDS.has(keyword) ||
|
|
576
|
+
JSON_SCHEMA_ANNOTATION_KEYWORDS.has(keyword),
|
|
577
|
+
);
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
/**
|
|
581
|
+
* Draft 7 permits `type` to be either a string or an array of strings. A
|
|
582
|
+
* singleton array has exactly the same validation semantics as its scalar
|
|
583
|
+
* form, so canonicalize it before root validation and recursive strictifying.
|
|
584
|
+
* Multi-type arrays carry real union semantics and must remain unchanged.
|
|
585
|
+
*/
|
|
586
|
+
function normalizeSingletonTypeArrays(schema: JSONSchemaDefinition): void {
|
|
587
|
+
if (!isObject(schema)) {
|
|
588
|
+
return;
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
if (Array.isArray(schema.type) && schema.type.length === 1) {
|
|
592
|
+
schema.type = schema.type[0]!;
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
forEachJSONSchemaChild(schema, [], (child) => {
|
|
596
|
+
// SAFETY: The schema-child visitor supplies only recognized object or boolean schema positions; the recursive helper validates their contents.
|
|
597
|
+
normalizeSingletonTypeArrays(child as JSONSchemaDefinition);
|
|
598
|
+
});
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
function isNullable(schema: JSONSchemaDefinition, root: JSONSchema, seenRefs = new Set<string>()): boolean {
|
|
602
|
+
if (typeof schema === 'boolean') {
|
|
603
|
+
return schema;
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
const ref = schema.$ref;
|
|
607
|
+
if (ref !== undefined) {
|
|
608
|
+
// Annotation keywords do not constrain validation, so they are safe beside
|
|
609
|
+
// a local ref. Keep the proof conservative for every other sibling because
|
|
610
|
+
// resolving those correctly would require intersecting the referenced
|
|
611
|
+
// schema and its sibling constraints.
|
|
612
|
+
if (typeof ref !== 'string' || !hasOnlyRefAndAnnotations(schema) || seenRefs.has(ref)) {
|
|
613
|
+
return false;
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
const resolved = resolveLocalRef(root, ref);
|
|
617
|
+
if (resolved === undefined) {
|
|
618
|
+
return false;
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
return isNullable(resolved, root, new Set([...seenRefs, ref]));
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
if (
|
|
625
|
+
schema.type !== undefined &&
|
|
626
|
+
schema.type !== 'null' &&
|
|
627
|
+
!(Array.isArray(schema.type) && schema.type.includes('null'))
|
|
628
|
+
) {
|
|
629
|
+
return false;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
if ('const' in schema && schema.const !== null) {
|
|
633
|
+
return false;
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
if (schema.enum !== undefined && (!Array.isArray(schema.enum) || !schema.enum.includes(null))) {
|
|
637
|
+
return false;
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
if (
|
|
641
|
+
schema.allOf !== undefined &&
|
|
642
|
+
(!Array.isArray(schema.allOf) || !schema.allOf.every((variant) => isNullable(variant, root)))
|
|
643
|
+
) {
|
|
644
|
+
return false;
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
if (
|
|
648
|
+
schema.anyOf !== undefined &&
|
|
649
|
+
(!Array.isArray(schema.anyOf) || !schema.anyOf.some((variant) => isNullable(variant, root)))
|
|
650
|
+
) {
|
|
651
|
+
return false;
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
if (
|
|
655
|
+
schema.oneOf !== undefined &&
|
|
656
|
+
(!Array.isArray(schema.oneOf) || schema.oneOf.filter((variant) => isNullable(variant, root)).length !== 1)
|
|
657
|
+
) {
|
|
658
|
+
return false;
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
// Conditional and negated schemas need a full JSON Schema evaluator to prove
|
|
662
|
+
// that null is allowed. Treat them conservatively instead of accepting an
|
|
663
|
+
// optional field that may not actually accept null.
|
|
664
|
+
if (
|
|
665
|
+
schema.not !== undefined ||
|
|
666
|
+
schema.if !== undefined ||
|
|
667
|
+
schema.then !== undefined ||
|
|
668
|
+
schema.else !== undefined
|
|
669
|
+
) {
|
|
670
|
+
return false;
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
return true;
|
|
32
674
|
}
|
|
33
675
|
|
|
34
676
|
/**
|
|
@@ -48,146 +690,1419 @@ function ensureStrictJsonSchema(
|
|
|
48
690
|
throw new TypeError(`Expected ${JSON.stringify(jsonSchema)} to be an object; path=${path.join('/')}`);
|
|
49
691
|
}
|
|
50
692
|
|
|
51
|
-
//
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
693
|
+
// Closing each object branch in an allOf independently changes the
|
|
694
|
+
// intersection: sibling branches' properties become forbidden extras. Merge
|
|
695
|
+
// the small object-intersection subset that can be represented exactly before
|
|
696
|
+
// applying strict object closure, and fail closed for the rest.
|
|
697
|
+
if (mergeObjectAllOf(jsonSchema, path, root)) {
|
|
698
|
+
return ensureStrictJsonSchema(jsonSchema, path, root);
|
|
57
699
|
}
|
|
58
700
|
|
|
59
|
-
//
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
701
|
+
// false is the identity element for a union. Remove it before proving
|
|
702
|
+
// whether an outer object/array wrapper is redundant so an impossible
|
|
703
|
+
// alternative cannot hide the shape of every real branch. Keep all-false
|
|
704
|
+
// and boolean-only unions intact so the existing boolean-schema rejection
|
|
705
|
+
// remains fail closed.
|
|
706
|
+
normalizeAnyOfFalseBranches(jsonSchema);
|
|
707
|
+
|
|
708
|
+
// Closing a type: object wrapper around object union branches without any
|
|
709
|
+
// own properties would turn it into an empty object and forbid every branch
|
|
710
|
+
// property. A bare object type is redundant when every branch already proves
|
|
711
|
+
// the value is an object, so remove only that exact constraint; fail closed
|
|
712
|
+
// for wrappers whose object constraints cannot be preserved mechanically.
|
|
713
|
+
normalizeObjectUnionWrapper(jsonSchema, path, root);
|
|
66
714
|
|
|
67
|
-
// Add additionalProperties: false to object
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
715
|
+
// Add additionalProperties: false to object schemas. Draft 7 permits object
|
|
716
|
+
// keywords without an explicit type, so those implicit object shapes need
|
|
717
|
+
// the same strict handling as type: 'object'. Explicitly open object schemas
|
|
718
|
+
// cannot be represented in Structured Outputs strict mode.
|
|
719
|
+
if (hasObjectConstraints(jsonSchema)) {
|
|
720
|
+
if (!hasOwn(jsonSchema, 'additionalProperties')) {
|
|
721
|
+
jsonSchema.additionalProperties = false;
|
|
722
|
+
} else if (jsonSchema.additionalProperties !== false) {
|
|
723
|
+
throw new Error(
|
|
724
|
+
`Object schema at \`${
|
|
725
|
+
path.join('/') || '<root>'
|
|
726
|
+
}\` must set \`additionalProperties: false\` to be compatible with strict Structured Outputs.`,
|
|
727
|
+
);
|
|
728
|
+
}
|
|
71
729
|
}
|
|
72
730
|
|
|
73
731
|
const required = jsonSchema.required ?? [];
|
|
732
|
+
if (!Array.isArray(required) || required.some((key) => typeof key !== 'string')) {
|
|
733
|
+
throw new TypeError(
|
|
734
|
+
`Expected \`required\` to be an array of strings; path=${path.join('/') || '<root>'}`,
|
|
735
|
+
);
|
|
736
|
+
}
|
|
74
737
|
|
|
75
738
|
// Handle object properties
|
|
76
739
|
const properties = jsonSchema.properties;
|
|
740
|
+
if (hasObjectConstraints(jsonSchema)) {
|
|
741
|
+
for (const key of required) {
|
|
742
|
+
if (!isObject(properties) || !hasOwn(properties, key)) {
|
|
743
|
+
throw new Error(
|
|
744
|
+
`Object schema at \`${
|
|
745
|
+
path.join('/') || '<root>'
|
|
746
|
+
}\` requires property \`${key}\` but does not declare it in \`properties\`.`,
|
|
747
|
+
);
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
}
|
|
77
751
|
if (isObject(properties)) {
|
|
78
752
|
for (const [key, value] of Object.entries(properties)) {
|
|
79
|
-
if (!isNullable(value) && !required.includes(key)) {
|
|
753
|
+
if (!isNullable(value, root) && !required.includes(key)) {
|
|
80
754
|
throw new Error(
|
|
81
|
-
`
|
|
755
|
+
`Schema field at \`${[...path, 'properties', key].join(
|
|
82
756
|
'/',
|
|
83
757
|
)}\` uses \`.optional()\` without \`.nullable()\` which is not supported by the API. See: https://platform.openai.com/docs/guides/structured-outputs?api-mode=responses#all-fields-must-be-required`,
|
|
84
758
|
);
|
|
85
759
|
}
|
|
86
760
|
}
|
|
87
761
|
jsonSchema.required = Object.keys(properties);
|
|
88
|
-
jsonSchema.properties = Object.fromEntries(
|
|
89
|
-
Object.entries(properties).map(([key, propSchema]) => [
|
|
90
|
-
key,
|
|
91
|
-
ensureStrictJsonSchema(propSchema, [...path, 'properties', key], root),
|
|
92
|
-
]),
|
|
93
|
-
);
|
|
94
762
|
}
|
|
95
763
|
|
|
96
|
-
//
|
|
764
|
+
// Structured Outputs accepts one schema for every array item and does not
|
|
765
|
+
// support Draft 7 tuples or additionalItems. Reject both forms rather than
|
|
766
|
+
// advertising a schema whose array validation the API cannot preserve.
|
|
97
767
|
const items = jsonSchema.items;
|
|
98
|
-
|
|
99
|
-
|
|
768
|
+
const additionalItems = jsonSchema.additionalItems;
|
|
769
|
+
if (Array.isArray(items)) {
|
|
770
|
+
throw new TypeError(
|
|
771
|
+
`Schema at \`${
|
|
772
|
+
path.join('/') || '<root>'
|
|
773
|
+
}\` uses tuple-form \`items\`, which cannot be represented in strict Structured Outputs.`,
|
|
774
|
+
);
|
|
100
775
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
ensureStrictJsonSchema(variant, [...path, 'anyOf', String(i)], root),
|
|
776
|
+
if (additionalItems !== undefined) {
|
|
777
|
+
throw new Error(
|
|
778
|
+
`Schema at \`${
|
|
779
|
+
path.join('/') || '<root>'
|
|
780
|
+
}\` uses unsupported keyword \`additionalItems\` and cannot be represented in strict Structured Outputs.`,
|
|
107
781
|
);
|
|
108
782
|
}
|
|
109
783
|
|
|
110
784
|
// Handle intersections (allOf)
|
|
111
785
|
const allOf = jsonSchema.allOf;
|
|
112
|
-
if (Array.isArray(allOf)) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
786
|
+
if (Array.isArray(allOf) && allOf.length === 1 && hasOnlyAnnotationSiblings(jsonSchema, 'allOf')) {
|
|
787
|
+
const branch = allOf[0]!;
|
|
788
|
+
if (branch === false) {
|
|
789
|
+
throw new Error(
|
|
790
|
+
`Schema at \`${
|
|
791
|
+
path.join('/') || '<root>'
|
|
792
|
+
}\` uses \`allOf: [false]\`, which cannot be represented in strict Structured Outputs.`,
|
|
793
|
+
);
|
|
794
|
+
}
|
|
795
|
+
if (branch === true) {
|
|
796
|
+
// true is the neutral schema for an intersection, so removing this
|
|
797
|
+
// branch preserves validation while retaining the parent annotations.
|
|
116
798
|
delete jsonSchema.allOf;
|
|
117
799
|
} else {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
800
|
+
const resolved = ensureStrictJsonSchema(branch, [...path, 'allOf', '0'], root);
|
|
801
|
+
const annotations = { ...jsonSchema };
|
|
802
|
+
delete annotations.allOf;
|
|
803
|
+
assignSchema(jsonSchema, resolved, annotations);
|
|
804
|
+
delete jsonSchema.allOf;
|
|
121
805
|
}
|
|
122
806
|
}
|
|
123
807
|
|
|
124
|
-
|
|
125
|
-
if (jsonSchema.default === null) {
|
|
126
|
-
delete jsonSchema.default;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// Handle $ref with additional properties
|
|
130
|
-
const ref = (jsonSchema as any).$ref;
|
|
131
|
-
if (ref && hasMoreThanNKeys(jsonSchema, 1)) {
|
|
132
|
-
if (typeof ref !== 'string') {
|
|
133
|
-
throw new TypeError(`Received non-string $ref - ${ref}; path=${path.join('/')}`);
|
|
134
|
-
}
|
|
808
|
+
normalizeArrayUnionWrapper(jsonSchema, root);
|
|
135
809
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
810
|
+
// SAFETY: This is an object schema at this traversal point; the record view permits dynamic keyword access while individual values remain subject to schema checks.
|
|
811
|
+
const schemaRecord = jsonSchema as Record<string, unknown>;
|
|
812
|
+
for (const keyword of JSON_SCHEMA_UNSUPPORTED_SCHEMA_KEYWORDS) {
|
|
813
|
+
// Optional converter output often keeps undefined placeholders on the
|
|
814
|
+
// JavaScript object even though JSON serialization omits them. They carry
|
|
815
|
+
// no validation semantics, so treat only undefined as absent; every
|
|
816
|
+
// defined value remains unsupported.
|
|
817
|
+
if (schemaRecord[keyword] !== undefined) {
|
|
141
818
|
throw new Error(
|
|
142
|
-
`
|
|
819
|
+
`Schema at \`${
|
|
820
|
+
path.join('/') || '<root>'
|
|
821
|
+
}\` uses unsupported keyword \`${keyword}\` and cannot be represented in strict Structured Outputs.`,
|
|
143
822
|
);
|
|
144
823
|
}
|
|
824
|
+
delete schemaRecord[keyword];
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
const type = jsonSchema.type;
|
|
828
|
+
const currentItems = jsonSchema.items;
|
|
829
|
+
if ((type === 'array' || (Array.isArray(type) && type.includes('array'))) && currentItems === undefined) {
|
|
830
|
+
throw new Error(
|
|
831
|
+
`Schema at \`${
|
|
832
|
+
path.join('/') || '<root>'
|
|
833
|
+
}\` declares an array without \`items\`, which cannot be represented in strict Structured Outputs.`,
|
|
834
|
+
);
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
forEachJSONSchemaChild(jsonSchema, path, (child, childPath, keyword) => {
|
|
838
|
+
// These boolean forms are already handled as parent-keyword semantics:
|
|
839
|
+
// additionalProperties: false closes objects, while boolean
|
|
840
|
+
// additionalItems does not contain a nested schema to strictify.
|
|
841
|
+
if (typeof child === 'boolean' && (keyword === 'additionalProperties' || keyword === 'additionalItems')) {
|
|
842
|
+
return;
|
|
843
|
+
}
|
|
145
844
|
|
|
146
|
-
//
|
|
147
|
-
|
|
148
|
-
|
|
845
|
+
// SAFETY: The schema-child visitor supplies only recognized object or boolean schema positions; the recursive helper validates their contents.
|
|
846
|
+
ensureStrictJsonSchema(child as JSONSchemaDefinition, childPath, root);
|
|
847
|
+
});
|
|
149
848
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
849
|
+
// Strip `null` defaults as there's no meaningful distinction
|
|
850
|
+
if (jsonSchema.default === null) {
|
|
851
|
+
delete jsonSchema.default;
|
|
153
852
|
}
|
|
154
853
|
|
|
155
854
|
return jsonSchema;
|
|
156
855
|
}
|
|
157
856
|
|
|
158
|
-
function
|
|
159
|
-
if (!ref.startsWith('
|
|
160
|
-
|
|
857
|
+
function parseLocalRef(ref: string): string[] | undefined {
|
|
858
|
+
if (!ref.startsWith('#')) {
|
|
859
|
+
return undefined;
|
|
161
860
|
}
|
|
162
861
|
|
|
163
|
-
|
|
164
|
-
|
|
862
|
+
let pointer: string;
|
|
863
|
+
try {
|
|
864
|
+
// A local $ref is a URI fragment containing a JSON Pointer. RFC 6901
|
|
865
|
+
// decodes the complete fragment before tokenizing the pointer, so an
|
|
866
|
+
// encoded slash is a separator rather than part of a literal key.
|
|
867
|
+
pointer = decodeURIComponent(ref.slice(1));
|
|
868
|
+
} catch {
|
|
869
|
+
return undefined;
|
|
870
|
+
}
|
|
165
871
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
if (value === undefined) {
|
|
172
|
-
throw new Error(`Key ${key} not found while resolving ${ref}`);
|
|
173
|
-
}
|
|
174
|
-
resolved = value;
|
|
872
|
+
if (pointer === '') {
|
|
873
|
+
return [];
|
|
874
|
+
}
|
|
875
|
+
if (!pointer.startsWith('/')) {
|
|
876
|
+
return undefined;
|
|
175
877
|
}
|
|
176
878
|
|
|
177
|
-
|
|
879
|
+
const parts: string[] = [];
|
|
880
|
+
for (const encodedPart of pointer.slice(1).split('/')) {
|
|
881
|
+
// JSON Pointer only defines ~0 and ~1 escapes. Reject malformed escape
|
|
882
|
+
// sequences instead of looking up a different literal key.
|
|
883
|
+
if (/~(?:[^01]|$)/.test(encodedPart)) {
|
|
884
|
+
return undefined;
|
|
885
|
+
}
|
|
886
|
+
parts.push(encodedPart.replace(/~1/g, '/').replace(/~0/g, '~'));
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
return parts;
|
|
178
890
|
}
|
|
179
891
|
|
|
180
|
-
|
|
892
|
+
// oxlint-disable-next-line anti-slop/no-unknown-returns -- Resolving untrusted schema references may produce any value; callers perform the schema checks. JSON Schema traversal accepts arbitrary keyword values and validates each node before interpreting it.
|
|
893
|
+
function resolvePointerPart(resolved: unknown, part: string): unknown | undefined {
|
|
894
|
+
if (Array.isArray(resolved)) {
|
|
895
|
+
if (!/^(?:0|[1-9]\d*)$/.test(part)) {
|
|
896
|
+
return undefined;
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
const index = Number(part);
|
|
900
|
+
if (!hasOwn(resolved, index)) {
|
|
901
|
+
return undefined;
|
|
902
|
+
}
|
|
903
|
+
return resolved[index];
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
if (!isObject(resolved) || !hasOwn(resolved, part)) {
|
|
907
|
+
return undefined;
|
|
908
|
+
}
|
|
909
|
+
return resolved[part];
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
/**
|
|
913
|
+
* Resolves a local JSON Pointer through schema-bearing keywords only.
|
|
914
|
+
*
|
|
915
|
+
* Returns `undefined` for external references, malformed pointers, missing
|
|
916
|
+
* targets, and pointers into literal values such as `default` or `enum`.
|
|
917
|
+
*/
|
|
918
|
+
export function resolveLocalRef(root: JSONSchema, ref: string): JSONSchemaDefinition | undefined {
|
|
919
|
+
const parts = parseLocalRef(ref);
|
|
920
|
+
if (parts === undefined) {
|
|
921
|
+
return undefined;
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
// Literal payloads such as `default`, `enum`, and `const` can contain
|
|
925
|
+
// object-shaped values, but they are not schemas and are never traversed by
|
|
926
|
+
// strictification. Resolve only the schema-bearing locations visited by
|
|
927
|
+
// forEachJSONSchemaChild so every accepted target is normalized before we
|
|
928
|
+
// advertise the result as strict.
|
|
929
|
+
let resolved: unknown = root;
|
|
930
|
+
for (let index = 0; index < parts.length;) {
|
|
931
|
+
if (!isObject(resolved)) {
|
|
932
|
+
return undefined;
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
const keyword = parts[index]!;
|
|
936
|
+
if (JSON_SCHEMA_SINGLE_SCHEMA_KEYWORDS.includes(keyword)) {
|
|
937
|
+
resolved = resolvePointerPart(resolved, keyword);
|
|
938
|
+
index += 1;
|
|
939
|
+
continue;
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
if (JSON_SCHEMA_ARRAY_SCHEMA_KEYWORDS.includes(keyword)) {
|
|
943
|
+
resolved = resolvePointerPart(resolved, keyword);
|
|
944
|
+
index += 1;
|
|
945
|
+
if (Array.isArray(resolved)) {
|
|
946
|
+
if (index >= parts.length) {
|
|
947
|
+
return undefined;
|
|
948
|
+
}
|
|
949
|
+
resolved = resolvePointerPart(resolved, parts[index]!);
|
|
950
|
+
index += 1;
|
|
951
|
+
}
|
|
952
|
+
continue;
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
if (JSON_SCHEMA_MAP_SCHEMA_KEYWORDS.includes(keyword)) {
|
|
956
|
+
const children = resolvePointerPart(resolved, keyword);
|
|
957
|
+
index += 1;
|
|
958
|
+
if (!isObject(children) || index >= parts.length) {
|
|
959
|
+
return undefined;
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
resolved = resolvePointerPart(children, parts[index]!);
|
|
963
|
+
if (keyword === 'dependencies' && !isSchemaDefinition(resolved)) {
|
|
964
|
+
return undefined;
|
|
965
|
+
}
|
|
966
|
+
index += 1;
|
|
967
|
+
continue;
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
return undefined;
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
return isSchemaDefinition(resolved) ? resolved : undefined;
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
function isObject<T>(obj: T | any[]): obj is Extract<T, Record<string, any>> {
|
|
181
977
|
return typeof obj === 'object' && obj !== null && !Array.isArray(obj);
|
|
182
978
|
}
|
|
183
979
|
|
|
184
|
-
function
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
980
|
+
function isSchemaDefinition(value: unknown): value is JSONSchemaDefinition {
|
|
981
|
+
return typeof value === 'boolean' || isObject(value);
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
function isObjectOnlySchema(
|
|
985
|
+
schema: JSONSchemaDefinition,
|
|
986
|
+
root: JSONSchema,
|
|
987
|
+
seenRefs = new Set<string>(),
|
|
988
|
+
): boolean {
|
|
989
|
+
if (!isObject(schema)) {
|
|
990
|
+
return false;
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
if (schema.$ref !== undefined) {
|
|
994
|
+
if (typeof schema.$ref !== 'string' || !hasOnlyRefAndAnnotations(schema) || seenRefs.has(schema.$ref)) {
|
|
995
|
+
return false;
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
const resolved = resolveLocalRef(root, schema.$ref);
|
|
999
|
+
if (resolved === undefined) {
|
|
1000
|
+
return false;
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
return isObjectOnlySchema(resolved, root, new Set([...seenRefs, schema.$ref]));
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
if (schema.allOf !== undefined) {
|
|
1007
|
+
if (
|
|
1008
|
+
!Array.isArray(schema.allOf) ||
|
|
1009
|
+
schema.allOf.length !== 1 ||
|
|
1010
|
+
!hasOnlyAnnotationSiblings(schema, 'allOf')
|
|
1011
|
+
) {
|
|
1012
|
+
return false;
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
const branch = schema.allOf[0];
|
|
1016
|
+
return branch !== undefined && branch !== true && branch !== false
|
|
1017
|
+
? isObjectOnlySchema(branch, root, seenRefs)
|
|
1018
|
+
: false;
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
return (
|
|
1022
|
+
schema.type === 'object' ||
|
|
1023
|
+
(Array.isArray(schema.type) && schema.type.length === 1 && schema.type[0] === 'object')
|
|
1024
|
+
);
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
function isArrayOnlySchema(
|
|
1028
|
+
schema: JSONSchemaDefinition,
|
|
1029
|
+
root: JSONSchema,
|
|
1030
|
+
seenRefs = new Set<string>(),
|
|
1031
|
+
): boolean {
|
|
1032
|
+
if (!isObject(schema)) {
|
|
1033
|
+
return false;
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
if (schema.$ref !== undefined) {
|
|
1037
|
+
if (typeof schema.$ref !== 'string' || !hasOnlyRefAndAnnotations(schema) || seenRefs.has(schema.$ref)) {
|
|
1038
|
+
return false;
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
const resolved = resolveLocalRef(root, schema.$ref);
|
|
1042
|
+
if (resolved === undefined) {
|
|
1043
|
+
return false;
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
return isArrayOnlySchema(resolved, root, new Set([...seenRefs, schema.$ref]));
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
if (schema.allOf !== undefined) {
|
|
1050
|
+
if (
|
|
1051
|
+
!Array.isArray(schema.allOf) ||
|
|
1052
|
+
schema.allOf.length !== 1 ||
|
|
1053
|
+
!hasOnlyAnnotationSiblings(schema, 'allOf')
|
|
1054
|
+
) {
|
|
1055
|
+
return false;
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
const branch = schema.allOf[0];
|
|
1059
|
+
return branch !== undefined && branch !== true && branch !== false
|
|
1060
|
+
? isArrayOnlySchema(branch, root, seenRefs)
|
|
1061
|
+
: false;
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
return (
|
|
1065
|
+
schema.type === 'array' ||
|
|
1066
|
+
(Array.isArray(schema.type) && schema.type.length === 1 && schema.type[0] === 'array')
|
|
1067
|
+
);
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1070
|
+
/** Returns whether a schema contains only a reference, reusable definitions, and annotations. */
|
|
1071
|
+
export function hasOnlyRefAndAnnotations(schema: JSONSchema): boolean {
|
|
1072
|
+
return Object.keys(schema).every(
|
|
1073
|
+
// Definition maps do not add sibling validation constraints, and keeping
|
|
1074
|
+
// them in place preserves local pointers into a nested alias's scope.
|
|
1075
|
+
(keyword) =>
|
|
1076
|
+
keyword === '$ref' ||
|
|
1077
|
+
keyword === '$defs' ||
|
|
1078
|
+
keyword === 'definitions' ||
|
|
1079
|
+
JSON_SCHEMA_ANNOTATION_KEYWORDS.has(keyword),
|
|
1080
|
+
);
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
function hasOnlyAnnotationSiblings(schema: JSONSchema, keyword: string): boolean {
|
|
1084
|
+
// SAFETY: This is an object schema at this traversal point; the record view permits dynamic keyword access while individual values remain subject to schema checks.
|
|
1085
|
+
const schemaRecord = schema as Record<string, unknown>;
|
|
1086
|
+
return Object.keys(schema).every(
|
|
1087
|
+
// Definition maps do not add sibling validation constraints. Keep them
|
|
1088
|
+
// beside a flattened singleton allOf so refs into this nested scope stay
|
|
1089
|
+
// reachable at their original pointers.
|
|
1090
|
+
(schemaKeyword) =>
|
|
1091
|
+
schemaKeyword === keyword ||
|
|
1092
|
+
((schemaKeyword === '$defs' || schemaKeyword === 'definitions') &&
|
|
1093
|
+
isObject(schemaRecord[schemaKeyword])) ||
|
|
1094
|
+
JSON_SCHEMA_ANNOTATION_KEYWORDS.has(schemaKeyword),
|
|
1095
|
+
);
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
function hasOnlyRootAllOfMetadataSiblings(schema: JSONSchema): boolean {
|
|
1099
|
+
return Object.keys(schema).every(
|
|
1100
|
+
(keyword) =>
|
|
1101
|
+
keyword === 'allOf' ||
|
|
1102
|
+
keyword === '$defs' ||
|
|
1103
|
+
keyword === 'definitions' ||
|
|
1104
|
+
JSON_SCHEMA_ROOT_METADATA_KEYWORDS.has(keyword) ||
|
|
1105
|
+
JSON_SCHEMA_ANNOTATION_KEYWORDS.has(keyword),
|
|
1106
|
+
);
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
function hasOnlyRootAnyOfMetadataSiblings(schema: JSONSchema): boolean {
|
|
1110
|
+
return Object.keys(schema).every(
|
|
1111
|
+
(keyword) =>
|
|
1112
|
+
keyword === 'anyOf' ||
|
|
1113
|
+
keyword === '$defs' ||
|
|
1114
|
+
keyword === 'definitions' ||
|
|
1115
|
+
(keyword === 'type' && schema.type === 'object') ||
|
|
1116
|
+
JSON_SCHEMA_ROOT_METADATA_KEYWORDS.has(keyword) ||
|
|
1117
|
+
JSON_SCHEMA_ANNOTATION_KEYWORDS.has(keyword),
|
|
1118
|
+
);
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
function hasObjectKeywords(schema: JSONSchema): boolean {
|
|
1122
|
+
return Object.keys(schema).some((keyword) => JSON_SCHEMA_OBJECT_KEYWORDS.has(keyword));
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
function hasObjectConstraints(schema: JSONSchema): boolean {
|
|
1126
|
+
const typ = schema.type;
|
|
1127
|
+
return (
|
|
1128
|
+
typ === 'object' ||
|
|
1129
|
+
(Array.isArray(typ) && typ.includes('object')) ||
|
|
1130
|
+
(typ === undefined && hasObjectKeywords(schema))
|
|
1131
|
+
);
|
|
1132
|
+
}
|
|
1133
|
+
|
|
1134
|
+
function isRedundantUnionWrapperType(type: JSONSchema['type'], branchType: 'object' | 'array'): boolean {
|
|
1135
|
+
return (
|
|
1136
|
+
type === branchType ||
|
|
1137
|
+
(Array.isArray(type) && type.length === 2 && type.includes(branchType) && type.includes('null'))
|
|
1138
|
+
);
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
function normalizeObjectUnionWrapper(jsonSchema: JSONSchema, path: string[], root: JSONSchema): void {
|
|
1142
|
+
if (jsonSchema.anyOf === undefined) {
|
|
1143
|
+
return;
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
const hasEmptyProperties =
|
|
1147
|
+
isObject(jsonSchema.properties) && Object.keys(jsonSchema.properties).length === 0;
|
|
1148
|
+
const hasEmptyRequired = Array.isArray(jsonSchema.required) && jsonSchema.required.length === 0;
|
|
1149
|
+
if (hasEmptyProperties) {
|
|
1150
|
+
delete jsonSchema.properties;
|
|
1151
|
+
}
|
|
1152
|
+
if (hasEmptyRequired) {
|
|
1153
|
+
delete jsonSchema.required;
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
if (!hasObjectConstraints(jsonSchema)) {
|
|
1157
|
+
return;
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
const hasOwnObjectConstraints = Object.keys(jsonSchema).some((keyword) =>
|
|
1161
|
+
JSON_SCHEMA_OBJECT_KEYWORDS.has(keyword),
|
|
1162
|
+
);
|
|
1163
|
+
if (
|
|
1164
|
+
isRedundantUnionWrapperType(jsonSchema.type, 'object') &&
|
|
1165
|
+
!hasOwnObjectConstraints &&
|
|
1166
|
+
Array.isArray(jsonSchema.anyOf) &&
|
|
1167
|
+
jsonSchema.anyOf.every((branch) => isObjectOnlySchema(branch, root))
|
|
1168
|
+
) {
|
|
1169
|
+
// The union already excludes null and every non-object value, so both a
|
|
1170
|
+
// scalar object wrapper and a nullable object wrapper are redundant under
|
|
1171
|
+
// Draft 7's conjunctive keyword semantics.
|
|
1172
|
+
delete jsonSchema.type;
|
|
1173
|
+
return;
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
throw new Error(
|
|
1177
|
+
'Object anyOf schema at `' +
|
|
1178
|
+
(path.join('/') || '<root>') +
|
|
1179
|
+
'` cannot be represented in strict Structured Outputs without changing Draft 7 validation.',
|
|
1180
|
+
);
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
function normalizeArrayUnionWrapper(jsonSchema: JSONSchema, root: JSONSchema): void {
|
|
1184
|
+
if (
|
|
1185
|
+
isRedundantUnionWrapperType(jsonSchema.type, 'array') &&
|
|
1186
|
+
jsonSchema.items === undefined &&
|
|
1187
|
+
Array.isArray(jsonSchema.anyOf) &&
|
|
1188
|
+
jsonSchema.anyOf.every((branch) => isArrayOnlySchema(branch, root))
|
|
1189
|
+
) {
|
|
1190
|
+
// Every union branch already proves the value is an array and excludes
|
|
1191
|
+
// null. Keeping either redundant wrapper would require an outer items
|
|
1192
|
+
// schema that does not contribute any Draft 7 validation.
|
|
1193
|
+
delete jsonSchema.type;
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
function normalizeAnyOfFalseBranches(jsonSchema: JSONSchema): void {
|
|
1198
|
+
if (!Array.isArray(jsonSchema.anyOf)) {
|
|
1199
|
+
return;
|
|
1200
|
+
}
|
|
1201
|
+
|
|
1202
|
+
const realBranches = jsonSchema.anyOf.filter((branch) => branch !== false);
|
|
1203
|
+
if (realBranches.length > 0 && realBranches.length !== jsonSchema.anyOf.length) {
|
|
1204
|
+
jsonSchema.anyOf = realBranches;
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
/**
|
|
1209
|
+
* Rejects nested schema resource identifiers that would change local reference scope.
|
|
1210
|
+
*
|
|
1211
|
+
* @throws {Error} If a nested subschema defines its own `$id`.
|
|
1212
|
+
*/
|
|
1213
|
+
export function assertNoNestedSchemaIds(schema: JSONSchema): void {
|
|
1214
|
+
const visit = (value: JSONSchemaDefinition, path: string[]): void => {
|
|
1215
|
+
if (!isObject(value)) {
|
|
1216
|
+
return;
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1219
|
+
if (path.length > 0 && value.$id !== undefined) {
|
|
1220
|
+
throw new Error(
|
|
1221
|
+
'Nested $id at ' +
|
|
1222
|
+
JSON.stringify(path.join('/')) +
|
|
1223
|
+
' establishes a separate JSON Schema resource scope and cannot be represented in strict Structured Outputs.',
|
|
1224
|
+
);
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
forEachJSONSchemaChild(value, path, (child, childPath) => {
|
|
1228
|
+
// SAFETY: The schema-child visitor supplies only recognized object or boolean schema positions; the recursive helper validates their contents.
|
|
1229
|
+
visit(child as JSONSchemaDefinition, childPath);
|
|
1230
|
+
});
|
|
1231
|
+
};
|
|
1232
|
+
|
|
1233
|
+
visit(schema, []);
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1236
|
+
function refTargetsAllOfBranch(root: JSONSchema, ref: string): boolean {
|
|
1237
|
+
const parts = parseLocalRef(ref);
|
|
1238
|
+
if (parts === undefined) {
|
|
1239
|
+
return false;
|
|
1240
|
+
}
|
|
1241
|
+
|
|
1242
|
+
let resolved: unknown = root;
|
|
1243
|
+
for (const [index, part] of parts.entries()) {
|
|
1244
|
+
if (
|
|
1245
|
+
part === 'allOf' &&
|
|
1246
|
+
isObject(resolved) &&
|
|
1247
|
+
Array.isArray(resolved['allOf']) &&
|
|
1248
|
+
index < parts.length - 1
|
|
1249
|
+
) {
|
|
189
1250
|
return true;
|
|
190
1251
|
}
|
|
1252
|
+
|
|
1253
|
+
resolved = resolvePointerPart(resolved, part);
|
|
1254
|
+
if (resolved === undefined) {
|
|
1255
|
+
return false;
|
|
1256
|
+
}
|
|
191
1257
|
}
|
|
1258
|
+
|
|
192
1259
|
return false;
|
|
193
1260
|
}
|
|
1261
|
+
|
|
1262
|
+
function escapeJSONPointerToken(token: string): string {
|
|
1263
|
+
return token.replace(/~/g, '~0').replace(/\//g, '~1');
|
|
1264
|
+
}
|
|
1265
|
+
|
|
1266
|
+
function encodeJSONPointerTokenForURIFragment(token: string): string {
|
|
1267
|
+
// `$` is a valid URI fragment sub-delimiter and keeping it readable retains
|
|
1268
|
+
// the conventional `#/$defs/...` spelling. Everything else that could
|
|
1269
|
+
// invalidate or retokenize the fragment (notably `%` and spaces) is encoded
|
|
1270
|
+
// after JSON Pointer escaping.
|
|
1271
|
+
return encodeURIComponent(escapeJSONPointerToken(token)).replace(/%24/g, '$');
|
|
1272
|
+
}
|
|
1273
|
+
|
|
1274
|
+
/**
|
|
1275
|
+
* Standard Schema normalization moves representable oneOf branches to anyOf.
|
|
1276
|
+
* Rewrite only pointers that traverse an actual oneOf schema array while the
|
|
1277
|
+
* original tree is still intact, preserving escaped tokens for every other
|
|
1278
|
+
* path segment.
|
|
1279
|
+
*/
|
|
1280
|
+
export function rewriteLocalRefsIntoMovedOneOfBranches(root: JSONSchema): void {
|
|
1281
|
+
const rewriteRef = (ref: string): string => {
|
|
1282
|
+
const parts = parseLocalRef(ref);
|
|
1283
|
+
if (parts === undefined || parts.length === 0) {
|
|
1284
|
+
return ref;
|
|
1285
|
+
}
|
|
1286
|
+
|
|
1287
|
+
let resolved: unknown = root;
|
|
1288
|
+
let changed = false;
|
|
1289
|
+
for (const [index, part] of parts.entries()) {
|
|
1290
|
+
if (
|
|
1291
|
+
part === 'oneOf' &&
|
|
1292
|
+
index < parts.length - 1 &&
|
|
1293
|
+
isObject(resolved) &&
|
|
1294
|
+
Array.isArray(resolved['oneOf'])
|
|
1295
|
+
) {
|
|
1296
|
+
parts[index] = 'anyOf';
|
|
1297
|
+
changed = true;
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1300
|
+
resolved = resolvePointerPart(resolved, part);
|
|
1301
|
+
if (resolved === undefined) {
|
|
1302
|
+
return ref;
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
|
|
1306
|
+
return changed ? '#/' + parts.map(encodeJSONPointerTokenForURIFragment).join('/') : ref;
|
|
1307
|
+
};
|
|
1308
|
+
|
|
1309
|
+
const rewriteRefs = (value: JSONSchemaDefinition): void => {
|
|
1310
|
+
if (!isObject(value)) {
|
|
1311
|
+
return;
|
|
1312
|
+
}
|
|
1313
|
+
|
|
1314
|
+
if (typeof value.$ref === 'string') {
|
|
1315
|
+
value.$ref = rewriteRef(value.$ref);
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1318
|
+
forEachJSONSchemaChild(value, [], (child) => {
|
|
1319
|
+
// SAFETY: The schema-child visitor supplies only recognized object or boolean schema positions; the recursive helper validates their contents.
|
|
1320
|
+
rewriteRefs(child as JSONSchemaDefinition);
|
|
1321
|
+
});
|
|
1322
|
+
};
|
|
1323
|
+
|
|
1324
|
+
rewriteRefs(root);
|
|
1325
|
+
}
|
|
1326
|
+
|
|
1327
|
+
/**
|
|
1328
|
+
* Strictification removes false anyOf alternatives. Rewrite pointers into
|
|
1329
|
+
* surviving alternatives before that filtering happens so each local ref
|
|
1330
|
+
* still names the same schema after earlier indices disappear.
|
|
1331
|
+
*/
|
|
1332
|
+
function rewriteLocalRefsIntoFilteredAnyOfBranches(root: JSONSchema): void {
|
|
1333
|
+
const rewriteRef = (ref: string): string => {
|
|
1334
|
+
const originalParts = parseLocalRef(ref);
|
|
1335
|
+
if (originalParts === undefined || originalParts.length === 0) {
|
|
1336
|
+
return ref;
|
|
1337
|
+
}
|
|
1338
|
+
|
|
1339
|
+
const rewrittenParts = [...originalParts];
|
|
1340
|
+
let resolved: unknown = root;
|
|
1341
|
+
let changed = false;
|
|
1342
|
+
|
|
1343
|
+
for (const [index, part] of originalParts.entries()) {
|
|
1344
|
+
// SAFETY: This is an object schema at this traversal point; the record view permits dynamic keyword access while individual values remain subject to schema checks.
|
|
1345
|
+
const resolvedRecord = isObject(resolved) ? (resolved as Record<string, unknown>) : undefined;
|
|
1346
|
+
if (
|
|
1347
|
+
part === 'anyOf' &&
|
|
1348
|
+
index < originalParts.length - 1 &&
|
|
1349
|
+
resolvedRecord !== undefined &&
|
|
1350
|
+
Array.isArray(resolvedRecord['anyOf'])
|
|
1351
|
+
) {
|
|
1352
|
+
const branches = resolvedRecord['anyOf'];
|
|
1353
|
+
const branchIndexPart = originalParts[index + 1]!;
|
|
1354
|
+
if (!/^(?:0|[1-9]\d*)$/.test(branchIndexPart)) {
|
|
1355
|
+
return ref;
|
|
1356
|
+
}
|
|
1357
|
+
|
|
1358
|
+
const branchIndex = Number(branchIndexPart);
|
|
1359
|
+
if (!hasOwn(branches, branchIndex)) {
|
|
1360
|
+
return ref;
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1363
|
+
const realBranches = branches.filter((branch) => branch !== false);
|
|
1364
|
+
if (realBranches.length > 0 && realBranches.length !== branches.length) {
|
|
1365
|
+
// A ref to a removed false schema is already rejected by the first
|
|
1366
|
+
// ref-validation pass. Leave it untouched so it remains fail closed.
|
|
1367
|
+
if (branches[branchIndex] === false) {
|
|
1368
|
+
return ref;
|
|
1369
|
+
}
|
|
1370
|
+
|
|
1371
|
+
const rewrittenIndex = branches.slice(0, branchIndex).filter((branch) => branch !== false).length;
|
|
1372
|
+
if (rewrittenIndex !== branchIndex) {
|
|
1373
|
+
rewrittenParts[index + 1] = String(rewrittenIndex);
|
|
1374
|
+
changed = true;
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
|
|
1379
|
+
// Resolve through the original pointer, not the rewritten one, so a
|
|
1380
|
+
// nested anyOf can also be remapped after its parent index shifts.
|
|
1381
|
+
resolved = resolvePointerPart(resolved, part);
|
|
1382
|
+
if (resolved === undefined) {
|
|
1383
|
+
return ref;
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
|
|
1387
|
+
return changed ? '#/' + rewrittenParts.map(encodeJSONPointerTokenForURIFragment).join('/') : ref;
|
|
1388
|
+
};
|
|
1389
|
+
|
|
1390
|
+
const rewriteRefs = (value: JSONSchemaDefinition): void => {
|
|
1391
|
+
if (!isObject(value)) {
|
|
1392
|
+
return;
|
|
1393
|
+
}
|
|
1394
|
+
|
|
1395
|
+
if (typeof value.$ref === 'string') {
|
|
1396
|
+
value.$ref = rewriteRef(value.$ref);
|
|
1397
|
+
}
|
|
1398
|
+
|
|
1399
|
+
forEachJSONSchemaChild(value, [], (child) => {
|
|
1400
|
+
// SAFETY: The schema-child visitor supplies only recognized object or boolean schema positions; the recursive helper validates their contents.
|
|
1401
|
+
rewriteRefs(child as JSONSchemaDefinition);
|
|
1402
|
+
});
|
|
1403
|
+
};
|
|
1404
|
+
|
|
1405
|
+
rewriteRefs(root);
|
|
1406
|
+
}
|
|
1407
|
+
|
|
1408
|
+
/**
|
|
1409
|
+
* Strictification removes every representable allOf. Preserve any schema
|
|
1410
|
+
* referenced through an allOf branch under a stable root definition first so
|
|
1411
|
+
* structural flattening cannot leave a dangling local pointer behind.
|
|
1412
|
+
*/
|
|
1413
|
+
function preserveAllOfRefTargets(root: JSONSchema, rootOnly = false): void {
|
|
1414
|
+
const refsToPreserve = new Set<string>();
|
|
1415
|
+
const collectRefs = (value: JSONSchemaDefinition): void => {
|
|
1416
|
+
if (!isObject(value)) {
|
|
1417
|
+
return;
|
|
1418
|
+
}
|
|
1419
|
+
|
|
1420
|
+
if (typeof value.$ref === 'string' && refTargetsAllOfBranch(root, value.$ref)) {
|
|
1421
|
+
const pointerParts = parseLocalRef(value.$ref);
|
|
1422
|
+
if (!rootOnly || pointerParts?.[0] === 'allOf') {
|
|
1423
|
+
refsToPreserve.add(value.$ref);
|
|
1424
|
+
}
|
|
1425
|
+
}
|
|
1426
|
+
|
|
1427
|
+
forEachJSONSchemaChild(value, [], (child) => {
|
|
1428
|
+
// SAFETY: The schema-child visitor supplies only recognized object or boolean schema positions; the recursive helper validates their contents.
|
|
1429
|
+
collectRefs(child as JSONSchemaDefinition);
|
|
1430
|
+
});
|
|
1431
|
+
};
|
|
1432
|
+
collectRefs(root);
|
|
1433
|
+
|
|
1434
|
+
if (refsToPreserve.size === 0) {
|
|
1435
|
+
return;
|
|
1436
|
+
}
|
|
1437
|
+
|
|
1438
|
+
if (root.$defs !== undefined && !isObject(root.$defs)) {
|
|
1439
|
+
throw new Error('Root schema has invalid $defs and cannot preserve local allOf references.');
|
|
1440
|
+
}
|
|
1441
|
+
const definitions = (root.$defs ??= {});
|
|
1442
|
+
const rewrittenRefs = new Map<string, string>();
|
|
1443
|
+
let aliasIndex = 0;
|
|
1444
|
+
|
|
1445
|
+
for (const ref of refsToPreserve) {
|
|
1446
|
+
const target = resolveLocalRef(root, ref);
|
|
1447
|
+
// oxlint-disable-next-line anti-slop/no-known-value-widening -- Local references require runtime schema validation even when the static return type is narrower.
|
|
1448
|
+
if (!isSchemaDefinition(target)) {
|
|
1449
|
+
if (rootOnly) {
|
|
1450
|
+
continue;
|
|
1451
|
+
}
|
|
1452
|
+
throw new Error('Local $ref cannot be preserved before allOf flattening: ' + JSON.stringify(ref));
|
|
1453
|
+
}
|
|
1454
|
+
|
|
1455
|
+
let alias = '__openai_strict_allOf_ref_' + aliasIndex++;
|
|
1456
|
+
while (hasOwn(definitions, alias)) {
|
|
1457
|
+
alias = '__openai_strict_allOf_ref_' + aliasIndex++;
|
|
1458
|
+
}
|
|
1459
|
+
definitions[alias] = structuredClone(target);
|
|
1460
|
+
rewrittenRefs.set(ref, '#/$defs/' + escapeJSONPointerToken(alias));
|
|
1461
|
+
}
|
|
1462
|
+
|
|
1463
|
+
const rewriteRefs = (value: JSONSchemaDefinition): void => {
|
|
1464
|
+
if (!isObject(value)) {
|
|
1465
|
+
return;
|
|
1466
|
+
}
|
|
1467
|
+
|
|
1468
|
+
if (typeof value.$ref === 'string') {
|
|
1469
|
+
value.$ref = rewrittenRefs.get(value.$ref) ?? value.$ref;
|
|
1470
|
+
}
|
|
1471
|
+
|
|
1472
|
+
forEachJSONSchemaChild(value, [], (child) => {
|
|
1473
|
+
// SAFETY: The schema-child visitor supplies only recognized object or boolean schema positions; the recursive helper validates their contents.
|
|
1474
|
+
rewriteRefs(child as JSONSchemaDefinition);
|
|
1475
|
+
});
|
|
1476
|
+
};
|
|
1477
|
+
rewriteRefs(root);
|
|
1478
|
+
}
|
|
1479
|
+
|
|
1480
|
+
/**
|
|
1481
|
+
* Closed allOf merges can discard optional property declarations. Preserve
|
|
1482
|
+
* only local refs into declarations that are about to disappear, then rewrite
|
|
1483
|
+
* those refs to stable root definitions before the merge removes their paths.
|
|
1484
|
+
*/
|
|
1485
|
+
function preserveDiscardedAllOfPropertyRefTargets(root: JSONSchema, discardedPaths: string[][]): void {
|
|
1486
|
+
if (discardedPaths.length === 0) {
|
|
1487
|
+
return;
|
|
1488
|
+
}
|
|
1489
|
+
|
|
1490
|
+
const refsToPreserve = new Set<string>();
|
|
1491
|
+
const collectRefs = (value: JSONSchemaDefinition): void => {
|
|
1492
|
+
if (!isObject(value)) {
|
|
1493
|
+
return;
|
|
1494
|
+
}
|
|
1495
|
+
|
|
1496
|
+
if (typeof value.$ref === 'string') {
|
|
1497
|
+
const parts = parseLocalRef(value.$ref);
|
|
1498
|
+
if (
|
|
1499
|
+
parts !== undefined &&
|
|
1500
|
+
discardedPaths.some(
|
|
1501
|
+
(discardedPath) =>
|
|
1502
|
+
parts.length >= discardedPath.length &&
|
|
1503
|
+
discardedPath.every((part, index) => parts[index] === part),
|
|
1504
|
+
)
|
|
1505
|
+
) {
|
|
1506
|
+
refsToPreserve.add(value.$ref);
|
|
1507
|
+
}
|
|
1508
|
+
}
|
|
1509
|
+
|
|
1510
|
+
forEachJSONSchemaChild(value, [], (child) => {
|
|
1511
|
+
// SAFETY: The schema-child visitor supplies only recognized object or boolean schema positions; the recursive helper validates their contents.
|
|
1512
|
+
collectRefs(child as JSONSchemaDefinition);
|
|
1513
|
+
});
|
|
1514
|
+
};
|
|
1515
|
+
collectRefs(root);
|
|
1516
|
+
|
|
1517
|
+
if (refsToPreserve.size === 0) {
|
|
1518
|
+
return;
|
|
1519
|
+
}
|
|
1520
|
+
|
|
1521
|
+
if (root.$defs !== undefined && !isObject(root.$defs)) {
|
|
1522
|
+
throw new Error('Root schema has invalid $defs and cannot preserve discarded allOf properties.');
|
|
1523
|
+
}
|
|
1524
|
+
const definitions = (root.$defs ??= {});
|
|
1525
|
+
const rewrittenRefs = new Map<string, string>();
|
|
1526
|
+
let aliasIndex = 0;
|
|
1527
|
+
|
|
1528
|
+
for (const ref of refsToPreserve) {
|
|
1529
|
+
const target = resolveLocalRef(root, ref);
|
|
1530
|
+
// oxlint-disable-next-line anti-slop/no-known-value-widening -- Validate referenced schema values at runtime before preserving them under generated definitions.
|
|
1531
|
+
if (!isSchemaDefinition(target)) {
|
|
1532
|
+
throw new Error('Local $ref cannot be preserved before allOf property removal: ' + JSON.stringify(ref));
|
|
1533
|
+
}
|
|
1534
|
+
|
|
1535
|
+
let alias = '__openai_strict_allOf_property_ref_' + aliasIndex++;
|
|
1536
|
+
while (hasOwn(definitions, alias)) {
|
|
1537
|
+
alias = '__openai_strict_allOf_property_ref_' + aliasIndex++;
|
|
1538
|
+
}
|
|
1539
|
+
definitions[alias] = structuredClone(target);
|
|
1540
|
+
rewrittenRefs.set(ref, '#/$defs/' + escapeJSONPointerToken(alias));
|
|
1541
|
+
}
|
|
1542
|
+
|
|
1543
|
+
const rewriteRefs = (value: JSONSchemaDefinition): void => {
|
|
1544
|
+
if (!isObject(value)) {
|
|
1545
|
+
return;
|
|
1546
|
+
}
|
|
1547
|
+
|
|
1548
|
+
if (typeof value.$ref === 'string') {
|
|
1549
|
+
value.$ref = rewrittenRefs.get(value.$ref) ?? value.$ref;
|
|
1550
|
+
}
|
|
1551
|
+
|
|
1552
|
+
forEachJSONSchemaChild(value, [], (child) => {
|
|
1553
|
+
// SAFETY: The schema-child visitor supplies only recognized object or boolean schema positions; the recursive helper validates their contents.
|
|
1554
|
+
rewriteRefs(child as JSONSchemaDefinition);
|
|
1555
|
+
});
|
|
1556
|
+
};
|
|
1557
|
+
rewriteRefs(root);
|
|
1558
|
+
}
|
|
1559
|
+
|
|
1560
|
+
function validateRefSchemas(schema: JSONSchemaDefinition, path: string[], root: JSONSchema): void {
|
|
1561
|
+
if (!isObject(schema)) {
|
|
1562
|
+
return;
|
|
1563
|
+
}
|
|
1564
|
+
|
|
1565
|
+
const ref = schema.$ref;
|
|
1566
|
+
if (ref !== undefined) {
|
|
1567
|
+
if (typeof ref !== 'string') {
|
|
1568
|
+
throw new TypeError(`Received non-string $ref - ${ref}; path=${path.join('/')}`);
|
|
1569
|
+
}
|
|
1570
|
+
if (!ref.startsWith('#')) {
|
|
1571
|
+
throw new Error(
|
|
1572
|
+
`External $ref at \`${
|
|
1573
|
+
path.join('/') || '<root>'
|
|
1574
|
+
}\` is not supported in strict Structured Outputs: ${JSON.stringify(ref)}`,
|
|
1575
|
+
);
|
|
1576
|
+
}
|
|
1577
|
+
const resolved = resolveLocalRef(root, ref);
|
|
1578
|
+
// oxlint-disable-next-line anti-slop/no-known-value-widening -- Untrusted local references must pass the runtime schema predicate before normalization.
|
|
1579
|
+
if (resolved === undefined || !isSchemaDefinition(resolved)) {
|
|
1580
|
+
throw new Error(
|
|
1581
|
+
`Local $ref at \`${
|
|
1582
|
+
path.join('/') || '<root>'
|
|
1583
|
+
}\` does not resolve to an object or boolean schema: ${JSON.stringify(ref)}`,
|
|
1584
|
+
);
|
|
1585
|
+
}
|
|
1586
|
+
if (typeof resolved === 'boolean') {
|
|
1587
|
+
throw new TypeError(`Expected object schema but got boolean; path=${path.join('/')}`);
|
|
1588
|
+
}
|
|
1589
|
+
if (!hasOnlyRefAndAnnotations(schema)) {
|
|
1590
|
+
throw new Error(
|
|
1591
|
+
`Schema $ref at \`${
|
|
1592
|
+
path.join('/') || '<root>'
|
|
1593
|
+
}\` has non-annotation siblings that Draft 7 ignores and cannot be represented in strict Structured Outputs.`,
|
|
1594
|
+
);
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1597
|
+
|
|
1598
|
+
forEachJSONSchemaChild(schema, path, (child, childPath) => {
|
|
1599
|
+
// SAFETY: The schema-child visitor supplies only recognized object or boolean schema positions; the recursive helper validates their contents.
|
|
1600
|
+
validateRefSchemas(child as JSONSchemaDefinition, childPath, root);
|
|
1601
|
+
});
|
|
1602
|
+
}
|
|
1603
|
+
|
|
1604
|
+
type ResolvedObjectAllOfBranch = {
|
|
1605
|
+
schema: JSONSchema;
|
|
1606
|
+
refChain: JSONSchema[];
|
|
1607
|
+
};
|
|
1608
|
+
|
|
1609
|
+
/**
|
|
1610
|
+
* Resolve only local aliases whose siblings carry no validation semantics.
|
|
1611
|
+
* Keeping this separate from general ref validation lets allOf merging inspect
|
|
1612
|
+
* the effective object shape without broadening which refs or sibling
|
|
1613
|
+
* constraints are accepted.
|
|
1614
|
+
*/
|
|
1615
|
+
function resolveObjectAllOfBranch(
|
|
1616
|
+
schema: JSONSchema,
|
|
1617
|
+
root: JSONSchema,
|
|
1618
|
+
normalizing: Set<JSONSchema>,
|
|
1619
|
+
): ResolvedObjectAllOfBranch | undefined {
|
|
1620
|
+
const refChain = [schema];
|
|
1621
|
+
const seenRefs = new Set<string>();
|
|
1622
|
+
let resolved = schema;
|
|
1623
|
+
let resolvedPath: string[] = [];
|
|
1624
|
+
|
|
1625
|
+
while (true) {
|
|
1626
|
+
while (resolved.$ref !== undefined) {
|
|
1627
|
+
const ref = resolved.$ref;
|
|
1628
|
+
if (typeof ref !== 'string' || !hasOnlyRefAndAnnotations(resolved) || seenRefs.has(ref)) {
|
|
1629
|
+
return undefined;
|
|
1630
|
+
}
|
|
1631
|
+
seenRefs.add(ref);
|
|
1632
|
+
|
|
1633
|
+
const target = resolveLocalRef(root, ref);
|
|
1634
|
+
if (!isObject(target)) {
|
|
1635
|
+
return undefined;
|
|
1636
|
+
}
|
|
1637
|
+
const targetPath = parseLocalRef(ref);
|
|
1638
|
+
if (targetPath === undefined) {
|
|
1639
|
+
return undefined;
|
|
1640
|
+
}
|
|
1641
|
+
|
|
1642
|
+
resolved = target;
|
|
1643
|
+
resolvedPath = targetPath;
|
|
1644
|
+
refChain.push(resolved);
|
|
1645
|
+
}
|
|
1646
|
+
|
|
1647
|
+
// A ref can point forward to a target whose own mergeable allOf has not
|
|
1648
|
+
// been visited yet. Normalize that target before its consumer classifies
|
|
1649
|
+
// the resolved shape, making property order irrelevant. An active target
|
|
1650
|
+
// is a ref/allOf cycle; leave it wrapped so the caller still fails closed.
|
|
1651
|
+
if (resolved.allOf !== undefined && !normalizing.has(resolved)) {
|
|
1652
|
+
const previousAllOf = resolved.allOf;
|
|
1653
|
+
normalizeObjectAllOfBranches(resolved, resolvedPath, root, normalizing);
|
|
1654
|
+
// Singleton flattening can expose another local ref. Follow it through
|
|
1655
|
+
// the same guarded loop before returning the effective branch.
|
|
1656
|
+
if (resolved.$ref !== undefined || resolved.allOf !== previousAllOf) {
|
|
1657
|
+
continue;
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1660
|
+
|
|
1661
|
+
return { schema: resolved, refChain };
|
|
1662
|
+
}
|
|
1663
|
+
}
|
|
1664
|
+
|
|
1665
|
+
function normalizeObjectAllOfBranches(
|
|
1666
|
+
schema: JSONSchemaDefinition,
|
|
1667
|
+
path: string[],
|
|
1668
|
+
root: JSONSchema,
|
|
1669
|
+
normalizing = new Set<JSONSchema>(),
|
|
1670
|
+
): void {
|
|
1671
|
+
if (!isObject(schema)) {
|
|
1672
|
+
return;
|
|
1673
|
+
}
|
|
1674
|
+
if (normalizing.has(schema)) {
|
|
1675
|
+
return;
|
|
1676
|
+
}
|
|
1677
|
+
|
|
1678
|
+
normalizing.add(schema);
|
|
1679
|
+
try {
|
|
1680
|
+
while (true) {
|
|
1681
|
+
forEachJSONSchemaChild(schema, path, (child, childPath) => {
|
|
1682
|
+
// SAFETY: The schema-child visitor supplies only recognized object or boolean schema positions; the recursive helper validates their contents.
|
|
1683
|
+
normalizeObjectAllOfBranches(child as JSONSchemaDefinition, childPath, root, normalizing);
|
|
1684
|
+
});
|
|
1685
|
+
|
|
1686
|
+
// Intersections are associative, so normalize nested object
|
|
1687
|
+
// intersections before classifying their parents. Otherwise an inner
|
|
1688
|
+
// allOf wrapper has no directly visible object shape and makes an
|
|
1689
|
+
// exactly mergeable outer allOf fail closed.
|
|
1690
|
+
if (!mergeObjectAllOf(schema, path, root, normalizing)) {
|
|
1691
|
+
return;
|
|
1692
|
+
}
|
|
1693
|
+
}
|
|
1694
|
+
} finally {
|
|
1695
|
+
normalizing.delete(schema);
|
|
1696
|
+
}
|
|
1697
|
+
}
|
|
1698
|
+
|
|
1699
|
+
/**
|
|
1700
|
+
* Standard Schema needs to prove oneOf branches exclusive before it rewrites
|
|
1701
|
+
* them to anyOf. Inspect a cloned branch through the same conservative object
|
|
1702
|
+
* allOf merger without mutating the caller's schema or broadening failures.
|
|
1703
|
+
*/
|
|
1704
|
+
export function normalizeObjectAllOfForExclusivity(
|
|
1705
|
+
schema: JSONSchema,
|
|
1706
|
+
root: JSONSchema,
|
|
1707
|
+
): JSONSchema | undefined {
|
|
1708
|
+
if (schema.allOf === undefined) {
|
|
1709
|
+
return undefined;
|
|
1710
|
+
}
|
|
1711
|
+
|
|
1712
|
+
const normalized = structuredClone(schema);
|
|
1713
|
+
try {
|
|
1714
|
+
// Removing neutral branches or flattening a singleton can expose another
|
|
1715
|
+
// mergeable allOf wrapper. Keep applying the recursive merger and safe
|
|
1716
|
+
// singleton flattening until the proof sees the branch's final shape.
|
|
1717
|
+
while (normalized.allOf !== undefined) {
|
|
1718
|
+
normalizeObjectAllOfBranches(normalized, [], root);
|
|
1719
|
+
if (normalized.allOf === undefined) {
|
|
1720
|
+
break;
|
|
1721
|
+
}
|
|
1722
|
+
|
|
1723
|
+
const allOf = normalized.allOf;
|
|
1724
|
+
if (!Array.isArray(allOf) || allOf.length !== 1 || !hasOnlyAnnotationSiblings(normalized, 'allOf')) {
|
|
1725
|
+
return undefined;
|
|
1726
|
+
}
|
|
1727
|
+
|
|
1728
|
+
const branch = allOf[0];
|
|
1729
|
+
if (!isObject(branch)) {
|
|
1730
|
+
return undefined;
|
|
1731
|
+
}
|
|
1732
|
+
|
|
1733
|
+
const siblings = { ...normalized };
|
|
1734
|
+
delete siblings.allOf;
|
|
1735
|
+
const flattened = structuredClone(branch);
|
|
1736
|
+
for (const keyword of Object.keys(normalized)) {
|
|
1737
|
+
// SAFETY: Only an enumerated own keyword is deleted from this mutable schema object before installing its normalized replacement.
|
|
1738
|
+
delete (normalized as Record<string, unknown>)[keyword];
|
|
1739
|
+
}
|
|
1740
|
+
assignSchema(normalized, flattened, siblings);
|
|
1741
|
+
}
|
|
1742
|
+
|
|
1743
|
+
return normalized;
|
|
1744
|
+
} catch {
|
|
1745
|
+
return undefined;
|
|
1746
|
+
}
|
|
1747
|
+
}
|
|
1748
|
+
|
|
1749
|
+
function mergeObjectAllOf(
|
|
1750
|
+
jsonSchema: JSONSchema,
|
|
1751
|
+
path: string[],
|
|
1752
|
+
root: JSONSchema,
|
|
1753
|
+
normalizing = new Set<JSONSchema>(),
|
|
1754
|
+
): boolean {
|
|
1755
|
+
const allOf = jsonSchema.allOf;
|
|
1756
|
+
if (!Array.isArray(allOf) || allOf.length === 0) {
|
|
1757
|
+
return false;
|
|
1758
|
+
}
|
|
1759
|
+
|
|
1760
|
+
// Intersections are idempotent. Collapse structurally identical branches
|
|
1761
|
+
// before object-shape classification so duplicate scalar and array schemas
|
|
1762
|
+
// can reach the existing safe singleton-flattening path.
|
|
1763
|
+
const uniqueBranches = allOf.filter(
|
|
1764
|
+
(branch, index) => !allOf.slice(0, index).some((candidate) => schemasEqual(candidate, branch)),
|
|
1765
|
+
);
|
|
1766
|
+
if (uniqueBranches.length !== allOf.length) {
|
|
1767
|
+
jsonSchema.allOf = uniqueBranches;
|
|
1768
|
+
return true;
|
|
1769
|
+
}
|
|
1770
|
+
|
|
1771
|
+
// `true` is the identity element for Draft 7 intersections. Remove it
|
|
1772
|
+
// before deciding whether the remaining branches are object-mergeable so a
|
|
1773
|
+
// neutral branch cannot make an otherwise exact merge fail closed.
|
|
1774
|
+
const nonNeutralBranches = allOf.filter((entry) => entry !== true);
|
|
1775
|
+
if (nonNeutralBranches.length !== allOf.length) {
|
|
1776
|
+
if (nonNeutralBranches.length === 0) {
|
|
1777
|
+
delete jsonSchema.allOf;
|
|
1778
|
+
} else {
|
|
1779
|
+
jsonSchema.allOf = nonNeutralBranches;
|
|
1780
|
+
}
|
|
1781
|
+
return true;
|
|
1782
|
+
}
|
|
1783
|
+
|
|
1784
|
+
const parentIsMergeableObject = isMergeableObjectSchema(jsonSchema);
|
|
1785
|
+
const resolvedEntries = allOf.map((entry) =>
|
|
1786
|
+
isObject(entry) ? resolveObjectAllOfBranch(entry, root, normalizing) : undefined,
|
|
1787
|
+
);
|
|
1788
|
+
const objectBranches = resolvedEntries
|
|
1789
|
+
.map((entry) => entry?.schema)
|
|
1790
|
+
.filter((entry): entry is JSONSchema => entry !== undefined && isMergeableObjectSchema(entry));
|
|
1791
|
+
if (!parentIsMergeableObject && objectBranches.length === 0) {
|
|
1792
|
+
return false;
|
|
1793
|
+
}
|
|
1794
|
+
// A lone object branch with no object-valued parent is handled by the
|
|
1795
|
+
// existing safe single-allOf flattening path below.
|
|
1796
|
+
if (!parentIsMergeableObject && allOf.length === 1) {
|
|
1797
|
+
return false;
|
|
1798
|
+
}
|
|
1799
|
+
|
|
1800
|
+
const fail = (): never => {
|
|
1801
|
+
throw new Error(
|
|
1802
|
+
`Object allOf at \`${
|
|
1803
|
+
path.join('/') || '<root>'
|
|
1804
|
+
}\` cannot be merged without changing Draft 7 validation.`,
|
|
1805
|
+
);
|
|
1806
|
+
};
|
|
1807
|
+
|
|
1808
|
+
if (
|
|
1809
|
+
!parentIsMergeableObject &&
|
|
1810
|
+
['additionalProperties', 'properties', 'required', 'type'].some((keyword) => keyword in jsonSchema)
|
|
1811
|
+
) {
|
|
1812
|
+
fail();
|
|
1813
|
+
}
|
|
1814
|
+
|
|
1815
|
+
for (const keyword of Object.keys(jsonSchema)) {
|
|
1816
|
+
if (
|
|
1817
|
+
keyword !== 'allOf' &&
|
|
1818
|
+
keyword !== '$defs' &&
|
|
1819
|
+
keyword !== 'definitions' &&
|
|
1820
|
+
!(path.length === 0 && JSON_SCHEMA_ROOT_METADATA_KEYWORDS.has(keyword)) &&
|
|
1821
|
+
!MERGEABLE_OBJECT_ALL_OF_KEYWORDS.has(keyword)
|
|
1822
|
+
) {
|
|
1823
|
+
fail();
|
|
1824
|
+
}
|
|
1825
|
+
}
|
|
1826
|
+
|
|
1827
|
+
const branches: { schema: JSONSchema; sourcePath: string[] | undefined }[] = [];
|
|
1828
|
+
if (parentIsMergeableObject) {
|
|
1829
|
+
branches.push({ schema: jsonSchema, sourcePath: path });
|
|
1830
|
+
}
|
|
1831
|
+
for (const [index, entry] of allOf.entries()) {
|
|
1832
|
+
if (!isObject(entry)) {
|
|
1833
|
+
fail();
|
|
1834
|
+
}
|
|
1835
|
+
const resolvedEntry = resolvedEntries[index];
|
|
1836
|
+
if (resolvedEntry === undefined) {
|
|
1837
|
+
return fail();
|
|
1838
|
+
}
|
|
1839
|
+
const branch = resolvedEntry.schema;
|
|
1840
|
+
// Definition maps do not constrain instances. Any refs into an allOf
|
|
1841
|
+
// branch were preserved under stable root definitions before this merge,
|
|
1842
|
+
// so a valid definitions-only branch can now be discarded like an
|
|
1843
|
+
// annotation-only branch.
|
|
1844
|
+
if (isMergeableObjectSchema(branch)) {
|
|
1845
|
+
branches.push({
|
|
1846
|
+
schema: branch,
|
|
1847
|
+
sourcePath: branch === entry ? [...path, 'allOf', String(index)] : undefined,
|
|
1848
|
+
});
|
|
1849
|
+
} else if (!hasOnlyNeutralAllOfBranchKeywords(branch)) {
|
|
1850
|
+
fail();
|
|
1851
|
+
}
|
|
1852
|
+
}
|
|
1853
|
+
|
|
1854
|
+
const merged: JSONSchema = {};
|
|
1855
|
+
// SAFETY: This is an object schema at this traversal point; the record view permits dynamic keyword access while individual values remain subject to schema checks.
|
|
1856
|
+
for (const keyword of ['$defs', 'definitions'] as const) {
|
|
1857
|
+
if (jsonSchema[keyword] !== undefined) {
|
|
1858
|
+
merged[keyword] = jsonSchema[keyword];
|
|
1859
|
+
}
|
|
1860
|
+
}
|
|
1861
|
+
if (path.length === 0) {
|
|
1862
|
+
for (const keyword of JSON_SCHEMA_ROOT_METADATA_KEYWORDS) {
|
|
1863
|
+
if (keyword in jsonSchema) {
|
|
1864
|
+
// SAFETY: Root annotation keywords are copied unchanged between schema objects; the record views preserve their unknown values.
|
|
1865
|
+
// oxlint-disable-next-line anti-slop/no-known-value-widening -- Root annotation keywords are copied dynamically; JSONSchema has no index signature for extension fields. Metadata merging preserves arbitrary annotation/default values under the selected schema keywords.
|
|
1866
|
+
(merged as Record<string, unknown>)[keyword] = (jsonSchema as Record<string, unknown>)[keyword];
|
|
1867
|
+
}
|
|
1868
|
+
}
|
|
1869
|
+
}
|
|
1870
|
+
|
|
1871
|
+
// SAFETY: This fresh null-prototype dictionary receives only JSON schema definitions while merging the validated property maps.
|
|
1872
|
+
const mergedProperties = Object.create(null) as Record<string, JSONSchemaDefinition>;
|
|
1873
|
+
const mergedRequired = new Set<string>();
|
|
1874
|
+
const closedPropertySets: Set<string>[] = [];
|
|
1875
|
+
const propertyEntries: {
|
|
1876
|
+
key: string;
|
|
1877
|
+
propertySchema: JSONSchemaDefinition;
|
|
1878
|
+
sourcePath: string[] | undefined;
|
|
1879
|
+
}[] = [];
|
|
1880
|
+
let sawProperties = false;
|
|
1881
|
+
let sawRequired = false;
|
|
1882
|
+
let hasExplicitObjectType = false;
|
|
1883
|
+
let hasExplicitNullableObjectType = false;
|
|
1884
|
+
|
|
1885
|
+
const mergeAnnotations = (schema: JSONSchema) => {
|
|
1886
|
+
for (const keyword of JSON_SCHEMA_ANNOTATION_KEYWORDS) {
|
|
1887
|
+
if (!(keyword in schema)) {
|
|
1888
|
+
continue;
|
|
1889
|
+
}
|
|
1890
|
+
// Annotation keywords do not affect Draft 7 validation. Preserve the
|
|
1891
|
+
// first value (the outer schema, then earlier branches) instead of
|
|
1892
|
+
// rejecting an otherwise exactly mergeable intersection.
|
|
1893
|
+
if (!(keyword in merged)) {
|
|
1894
|
+
// SAFETY: These annotation keywords are copied unchanged from the validated branch; arbitrary values are preserved without narrowing.
|
|
1895
|
+
(merged as any)[keyword] = (schema as any)[keyword];
|
|
1896
|
+
}
|
|
1897
|
+
}
|
|
1898
|
+
};
|
|
1899
|
+
|
|
1900
|
+
mergeAnnotations(jsonSchema);
|
|
1901
|
+
for (const resolvedEntry of resolvedEntries) {
|
|
1902
|
+
if (resolvedEntry === undefined) {
|
|
1903
|
+
continue;
|
|
1904
|
+
}
|
|
1905
|
+
for (const entry of resolvedEntry.refChain) {
|
|
1906
|
+
mergeAnnotations(entry);
|
|
1907
|
+
}
|
|
1908
|
+
}
|
|
1909
|
+
|
|
1910
|
+
for (const { schema: branch, sourcePath } of branches) {
|
|
1911
|
+
for (const keyword of Object.keys(branch)) {
|
|
1912
|
+
if (keyword === 'allOf' && branch === jsonSchema) {
|
|
1913
|
+
continue;
|
|
1914
|
+
}
|
|
1915
|
+
// SAFETY: This is an object schema at this traversal point; the record view permits dynamic keyword access while individual values remain subject to schema checks.
|
|
1916
|
+
if (
|
|
1917
|
+
(keyword === '$defs' || keyword === 'definitions') &&
|
|
1918
|
+
isObject((branch as Record<string, unknown>)[keyword])
|
|
1919
|
+
) {
|
|
1920
|
+
continue;
|
|
1921
|
+
}
|
|
1922
|
+
if (branch === jsonSchema && path.length === 0 && JSON_SCHEMA_ROOT_METADATA_KEYWORDS.has(keyword)) {
|
|
1923
|
+
continue;
|
|
1924
|
+
}
|
|
1925
|
+
if (!MERGEABLE_OBJECT_ALL_OF_KEYWORDS.has(keyword)) {
|
|
1926
|
+
fail();
|
|
1927
|
+
}
|
|
1928
|
+
}
|
|
1929
|
+
|
|
1930
|
+
if (branch.type !== undefined) {
|
|
1931
|
+
if (!isMergeableObjectType(branch.type)) {
|
|
1932
|
+
fail();
|
|
1933
|
+
}
|
|
1934
|
+
if (branch.type === 'object') {
|
|
1935
|
+
hasExplicitObjectType = true;
|
|
1936
|
+
} else {
|
|
1937
|
+
hasExplicitNullableObjectType = true;
|
|
1938
|
+
}
|
|
1939
|
+
}
|
|
1940
|
+
|
|
1941
|
+
if (branch.properties !== undefined) {
|
|
1942
|
+
if (!isObject(branch.properties)) {
|
|
1943
|
+
fail();
|
|
1944
|
+
}
|
|
1945
|
+
sawProperties = true;
|
|
1946
|
+
for (const [key, propertySchema] of Object.entries(branch.properties)) {
|
|
1947
|
+
propertyEntries.push({
|
|
1948
|
+
key,
|
|
1949
|
+
propertySchema,
|
|
1950
|
+
sourcePath: sourcePath === undefined ? undefined : [...sourcePath, 'properties', key],
|
|
1951
|
+
});
|
|
1952
|
+
}
|
|
1953
|
+
}
|
|
1954
|
+
|
|
1955
|
+
if (branch.required !== undefined) {
|
|
1956
|
+
if (!Array.isArray(branch.required) || branch.required.some((key) => typeof key !== 'string')) {
|
|
1957
|
+
fail();
|
|
1958
|
+
}
|
|
1959
|
+
sawRequired = true;
|
|
1960
|
+
for (const key of branch.required) {
|
|
1961
|
+
mergedRequired.add(key);
|
|
1962
|
+
}
|
|
1963
|
+
}
|
|
1964
|
+
|
|
1965
|
+
if ('additionalProperties' in branch) {
|
|
1966
|
+
if (branch.additionalProperties !== false) {
|
|
1967
|
+
fail();
|
|
1968
|
+
}
|
|
1969
|
+
closedPropertySets.push(new Set(Object.keys(branch.properties ?? {})));
|
|
1970
|
+
}
|
|
1971
|
+
}
|
|
1972
|
+
|
|
1973
|
+
// A closed branch forbids every property it does not declare. Intersect all
|
|
1974
|
+
// closed property sets before merging schemas so optional declarations
|
|
1975
|
+
// excluded by another closed branch are discarded, while required excluded
|
|
1976
|
+
// properties remain unrepresentable and fail closed.
|
|
1977
|
+
let allowedClosedProperties: Set<string> | undefined;
|
|
1978
|
+
if (closedPropertySets.length > 0) {
|
|
1979
|
+
allowedClosedProperties = new Set(closedPropertySets[0]);
|
|
1980
|
+
for (const keys of closedPropertySets.slice(1)) {
|
|
1981
|
+
for (const key of allowedClosedProperties) {
|
|
1982
|
+
if (!keys.has(key)) {
|
|
1983
|
+
allowedClosedProperties.delete(key);
|
|
1984
|
+
}
|
|
1985
|
+
}
|
|
1986
|
+
}
|
|
1987
|
+
}
|
|
1988
|
+
const closedProperties = allowedClosedProperties;
|
|
1989
|
+
const excludesRequiredProperty =
|
|
1990
|
+
closedProperties !== undefined && [...mergedRequired].some((key) => !closedProperties.has(key));
|
|
1991
|
+
const collapsesToNull = excludesRequiredProperty && !hasExplicitObjectType && hasExplicitNullableObjectType;
|
|
1992
|
+
const discardedPropertyPaths = propertyEntries
|
|
1993
|
+
.filter(
|
|
1994
|
+
({ key, sourcePath }) =>
|
|
1995
|
+
sourcePath !== undefined &&
|
|
1996
|
+
(collapsesToNull || (allowedClosedProperties !== undefined && !allowedClosedProperties.has(key))),
|
|
1997
|
+
)
|
|
1998
|
+
.map(({ sourcePath }) => sourcePath!);
|
|
1999
|
+
preserveDiscardedAllOfPropertyRefTargets(root, discardedPropertyPaths);
|
|
2000
|
+
if (jsonSchema === root && root.$defs !== undefined) {
|
|
2001
|
+
merged.$defs = root.$defs;
|
|
2002
|
+
}
|
|
2003
|
+
|
|
2004
|
+
if (excludesRequiredProperty) {
|
|
2005
|
+
// Object keywords do not constrain null. If every explicit object type
|
|
2006
|
+
// also admits null, the object portion is contradictory but null remains
|
|
2007
|
+
// an exact representation of the intersection.
|
|
2008
|
+
if (collapsesToNull) {
|
|
2009
|
+
merged.type = 'null';
|
|
2010
|
+
for (const keyword of Object.keys(jsonSchema)) {
|
|
2011
|
+
// SAFETY: Only an enumerated own keyword is deleted from this mutable schema object before installing its normalized replacement.
|
|
2012
|
+
delete (jsonSchema as any)[keyword];
|
|
2013
|
+
}
|
|
2014
|
+
assignSchema(jsonSchema, merged);
|
|
2015
|
+
return true;
|
|
2016
|
+
}
|
|
2017
|
+
fail();
|
|
2018
|
+
}
|
|
2019
|
+
|
|
2020
|
+
for (const { key, propertySchema } of propertyEntries) {
|
|
2021
|
+
if (allowedClosedProperties !== undefined && !allowedClosedProperties.has(key)) {
|
|
2022
|
+
continue;
|
|
2023
|
+
}
|
|
2024
|
+
if (hasOwn(mergedProperties, key) && !schemasEqual(mergedProperties[key], propertySchema)) {
|
|
2025
|
+
fail();
|
|
2026
|
+
}
|
|
2027
|
+
mergedProperties[key] = propertySchema;
|
|
2028
|
+
}
|
|
2029
|
+
|
|
2030
|
+
if (hasExplicitObjectType || hasExplicitNullableObjectType) {
|
|
2031
|
+
merged.type = hasExplicitObjectType ? 'object' : ['object', 'null'];
|
|
2032
|
+
}
|
|
2033
|
+
if (sawProperties) {
|
|
2034
|
+
merged.properties = Object.fromEntries(Object.entries(mergedProperties));
|
|
2035
|
+
}
|
|
2036
|
+
if (sawRequired) {
|
|
2037
|
+
merged.required = [...mergedRequired];
|
|
2038
|
+
}
|
|
2039
|
+
if (closedPropertySets.length > 0) {
|
|
2040
|
+
merged.additionalProperties = false;
|
|
2041
|
+
}
|
|
2042
|
+
|
|
2043
|
+
for (const keyword of Object.keys(jsonSchema)) {
|
|
2044
|
+
// SAFETY: Only an enumerated own keyword is deleted from this mutable schema object before installing its normalized replacement.
|
|
2045
|
+
delete (jsonSchema as any)[keyword];
|
|
2046
|
+
}
|
|
2047
|
+
assignSchema(jsonSchema, merged);
|
|
2048
|
+
return true;
|
|
2049
|
+
}
|
|
2050
|
+
|
|
2051
|
+
function isMergeableObjectSchema(schema: JSONSchema): boolean {
|
|
2052
|
+
if (schema.type !== undefined) {
|
|
2053
|
+
return isMergeableObjectType(schema.type);
|
|
2054
|
+
}
|
|
2055
|
+
return Object.keys(schema).some((keyword) => JSON_SCHEMA_OBJECT_KEYWORDS.has(keyword));
|
|
2056
|
+
}
|
|
2057
|
+
|
|
2058
|
+
function hasOnlyNeutralAllOfBranchKeywords(schema: JSONSchema): boolean {
|
|
2059
|
+
// SAFETY: This is an object schema at this traversal point; the record view permits dynamic keyword access while individual values remain subject to schema checks.
|
|
2060
|
+
const schemaRecord = schema as Record<string, unknown>;
|
|
2061
|
+
return Object.keys(schema).every(
|
|
2062
|
+
(keyword) =>
|
|
2063
|
+
JSON_SCHEMA_ANNOTATION_KEYWORDS.has(keyword) ||
|
|
2064
|
+
((keyword === '$defs' || keyword === 'definitions') && isObject(schemaRecord[keyword])),
|
|
2065
|
+
);
|
|
2066
|
+
}
|
|
2067
|
+
|
|
2068
|
+
function isMergeableObjectType(type: JSONSchema['type']): boolean {
|
|
2069
|
+
return (
|
|
2070
|
+
type === 'object' ||
|
|
2071
|
+
(Array.isArray(type) && type.length === 2 && type.includes('object') && type.includes('null'))
|
|
2072
|
+
);
|
|
2073
|
+
}
|
|
2074
|
+
|
|
2075
|
+
function schemasEqual(left: unknown, right: unknown): boolean {
|
|
2076
|
+
if (left === right) {
|
|
2077
|
+
return true;
|
|
2078
|
+
}
|
|
2079
|
+
|
|
2080
|
+
if (Array.isArray(left) || Array.isArray(right)) {
|
|
2081
|
+
if (!Array.isArray(left) || !Array.isArray(right) || left.length !== right.length) {
|
|
2082
|
+
return false;
|
|
2083
|
+
}
|
|
2084
|
+
|
|
2085
|
+
return left.every((value, index) => schemasEqual(value, right[index]));
|
|
2086
|
+
}
|
|
2087
|
+
|
|
2088
|
+
if (typeof left !== 'object' || left === null || typeof right !== 'object' || right === null) {
|
|
2089
|
+
return false;
|
|
2090
|
+
}
|
|
2091
|
+
|
|
2092
|
+
// SAFETY: This is an object schema at this traversal point; the record view permits dynamic keyword access while individual values remain subject to schema checks.
|
|
2093
|
+
const leftRecord = left as Record<string, unknown>;
|
|
2094
|
+
// SAFETY: This is an object schema at this traversal point; the record view permits dynamic keyword access while individual values remain subject to schema checks.
|
|
2095
|
+
const rightRecord = right as Record<string, unknown>;
|
|
2096
|
+
const leftKeys = Object.keys(leftRecord);
|
|
2097
|
+
const rightKeys = Object.keys(rightRecord);
|
|
2098
|
+
leftKeys.sort();
|
|
2099
|
+
rightKeys.sort();
|
|
2100
|
+
|
|
2101
|
+
if (leftKeys.length !== rightKeys.length) {
|
|
2102
|
+
return false;
|
|
2103
|
+
}
|
|
2104
|
+
|
|
2105
|
+
return leftKeys.every(
|
|
2106
|
+
(key, index) => key === rightKeys[index] && schemasEqual(leftRecord[key], rightRecord[key]),
|
|
2107
|
+
);
|
|
2108
|
+
}
|