@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.
Files changed (1299) hide show
  1. package/README.md +1 -1
  2. package/bin/dsh.mjs +1 -1
  3. package/node_modules/@aws-sdk/{credential-provider-sso → client-bedrock-runtime}/node_modules/@aws-sdk/token-providers/package.json +6 -6
  4. package/node_modules/@aws-sdk/token-providers/package.json +6 -6
  5. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/package.json +2 -2
  6. package/node_modules/@deepseek-ai/dsh-client-ui-sidebar/lib/client.js +1 -1
  7. package/node_modules/@deepseek-ai/dsh-client-ui-slots/package.json +2 -2
  8. package/node_modules/@deepseek-ai/dsh-llm-pi-ai/README.i18n.yaml +2 -2
  9. package/node_modules/@deepseek-ai/dsh-llm-pi-ai/README.md +1 -1
  10. package/node_modules/@deepseek-ai/dsh-llm-pi-ai/README.zh.md +1 -1
  11. package/node_modules/@deepseek-ai/dsh-llm-pi-ai/lib/index.js +1 -182
  12. package/node_modules/@deepseek-ai/dsh-llm-pi-ai/package.json +1 -1
  13. package/node_modules/@deepseek-ai/dsh-tui-app/lib/index.js +1 -1
  14. package/node_modules/@earendil-works/pi-ai/README.md +207 -27
  15. package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js +6 -0
  16. package/node_modules/@earendil-works/pi-ai/dist/api/azure-openai-responses.js +6 -5
  17. package/node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.js +1 -0
  18. package/node_modules/@earendil-works/pi-ai/dist/api/cloudflare-workers-ai-system-one.js +43 -0
  19. package/node_modules/@earendil-works/pi-ai/dist/api/cloudflare-workers-ai-system-one.lazy.js +4 -0
  20. package/node_modules/@earendil-works/pi-ai/dist/api/cloudflare.js +2 -0
  21. package/node_modules/@earendil-works/pi-ai/dist/api/google-generative-ai.js +1 -0
  22. package/node_modules/@earendil-works/pi-ai/dist/api/google-vertex.js +1 -0
  23. package/node_modules/@earendil-works/pi-ai/dist/api/llama-cpp-classify.js +365 -0
  24. package/node_modules/@earendil-works/pi-ai/dist/api/llama-cpp-classify.lazy.js +4 -0
  25. package/node_modules/@earendil-works/pi-ai/dist/api/mistral-conversations.js +18 -17
  26. package/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.js +20 -4
  27. package/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.js +4 -4
  28. package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses-shared.js +14 -0
  29. package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses.js +26 -9
  30. package/node_modules/@earendil-works/pi-ai/dist/api/openrouter-images.js +1 -0
  31. package/node_modules/@earendil-works/pi-ai/dist/api/pi-messages.js +1 -0
  32. package/node_modules/@earendil-works/pi-ai/dist/api/simple-options.js +2 -4
  33. package/node_modules/@earendil-works/pi-ai/dist/api/system-one-shared.js +183 -0
  34. package/node_modules/@earendil-works/pi-ai/dist/api/typesafe-system-one.js +19 -0
  35. package/node_modules/@earendil-works/pi-ai/dist/api/typesafe-system-one.lazy.js +4 -0
  36. package/node_modules/@earendil-works/pi-ai/dist/auth/helpers.js +1 -1
  37. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/anthropic.js +19 -128
  38. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/callback-server.js +146 -0
  39. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/load.js +5 -0
  40. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/openai-chatgpt.js +266 -0
  41. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/openai-codex.js +20 -124
  42. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/openrouter.js +19 -138
  43. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/radius.js +21 -89
  44. package/node_modules/@earendil-works/pi-ai/dist/auth/resolve.js +3 -19
  45. package/node_modules/@earendil-works/pi-ai/dist/bun-oauth.js +2 -0
  46. package/node_modules/@earendil-works/pi-ai/dist/cli.js +3 -1
  47. package/node_modules/@earendil-works/pi-ai/dist/env-api-keys.js +1 -0
  48. package/node_modules/@earendil-works/pi-ai/dist/image-models.js +14 -13
  49. package/node_modules/@earendil-works/pi-ai/dist/images.js +5 -0
  50. package/node_modules/@earendil-works/pi-ai/dist/index.js +0 -1
  51. package/node_modules/@earendil-works/pi-ai/dist/model-catalog.js +14 -2
  52. package/node_modules/@earendil-works/pi-ai/dist/models.generated.js +131 -41
  53. package/node_modules/@earendil-works/pi-ai/dist/models.js +157 -30
  54. package/node_modules/@earendil-works/pi-ai/dist/providers/all.js +25 -21
  55. package/node_modules/@earendil-works/pi-ai/dist/providers/amazon-bedrock.models.js +4 -2
  56. package/node_modules/@earendil-works/pi-ai/dist/providers/ant-ling.models.js +4 -2
  57. package/node_modules/@earendil-works/pi-ai/dist/providers/anthropic.models.js +4 -2
  58. package/node_modules/@earendil-works/pi-ai/dist/providers/azure-openai-responses.models.js +4 -2
  59. package/node_modules/@earendil-works/pi-ai/dist/providers/baseten.models.js +4 -2
  60. package/node_modules/@earendil-works/pi-ai/dist/providers/cerebras.models.js +4 -2
  61. package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-ai-gateway.models.js +4 -2
  62. package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-stream.js +6 -0
  63. package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-workers-ai.js +10 -3
  64. package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-workers-ai.models.js +4 -2
  65. package/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
  66. package/node_modules/@earendil-works/pi-ai/dist/providers/data/amazon-bedrock.json +1 -1
  67. package/node_modules/@earendil-works/pi-ai/dist/providers/data/ant-ling.json +1 -1
  68. package/node_modules/@earendil-works/pi-ai/dist/providers/data/anthropic.json +1 -1
  69. package/node_modules/@earendil-works/pi-ai/dist/providers/data/azure-openai-responses.json +1 -1
  70. package/node_modules/@earendil-works/pi-ai/dist/providers/data/baseten.json +1 -1
  71. package/node_modules/@earendil-works/pi-ai/dist/providers/data/cerebras.json +1 -1
  72. package/node_modules/@earendil-works/pi-ai/dist/providers/data/cloudflare-ai-gateway.json +1 -1
  73. package/node_modules/@earendil-works/pi-ai/dist/providers/data/cloudflare-workers-ai.json +1 -1
  74. package/node_modules/@earendil-works/pi-ai/dist/providers/data/deepseek.json +1 -1
  75. package/node_modules/@earendil-works/pi-ai/dist/providers/data/fireworks.json +1 -1
  76. package/node_modules/@earendil-works/pi-ai/dist/providers/data/github-copilot.json +1 -1
  77. package/node_modules/@earendil-works/pi-ai/dist/providers/data/google-vertex.json +1 -1
  78. package/node_modules/@earendil-works/pi-ai/dist/providers/data/google.json +1 -1
  79. package/node_modules/@earendil-works/pi-ai/dist/providers/data/groq.json +1 -1
  80. package/node_modules/@earendil-works/pi-ai/dist/providers/data/huggingface.json +1 -1
  81. package/node_modules/@earendil-works/pi-ai/dist/providers/data/kimi-coding.json +1 -1
  82. package/node_modules/@earendil-works/pi-ai/dist/providers/data/meta.json +1 -1
  83. package/node_modules/@earendil-works/pi-ai/dist/providers/data/minimax-cn.json +1 -1
  84. package/node_modules/@earendil-works/pi-ai/dist/providers/data/minimax.json +1 -1
  85. package/node_modules/@earendil-works/pi-ai/dist/providers/data/mistral.json +1 -1
  86. package/node_modules/@earendil-works/pi-ai/dist/providers/data/moonshotai-cn.json +1 -1
  87. package/node_modules/@earendil-works/pi-ai/dist/providers/data/moonshotai.json +1 -1
  88. package/node_modules/@earendil-works/pi-ai/dist/providers/data/nvidia.json +1 -1
  89. package/node_modules/@earendil-works/pi-ai/dist/providers/data/openai-codex.json +1 -1
  90. package/node_modules/@earendil-works/pi-ai/dist/providers/data/openai.json +1 -1
  91. package/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode-go.json +1 -1
  92. package/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode.json +1 -1
  93. package/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
  94. package/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan-cn.json +1 -1
  95. package/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan-individual.json +1 -1
  96. package/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan.json +1 -1
  97. package/node_modules/@earendil-works/pi-ai/dist/providers/data/radius.json +1 -1
  98. package/node_modules/@earendil-works/pi-ai/dist/providers/data/together.json +1 -1
  99. package/node_modules/@earendil-works/pi-ai/dist/providers/data/typesafe.json +1 -0
  100. package/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
  101. package/node_modules/@earendil-works/pi-ai/dist/providers/data/xai.json +1 -1
  102. package/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi-token-plan-ams.json +1 -1
  103. package/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi-token-plan-cn.json +1 -1
  104. package/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi-token-plan-sgp.json +1 -1
  105. package/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi.json +1 -1
  106. package/node_modules/@earendil-works/pi-ai/dist/providers/data/zai-coding-cn.json +1 -1
  107. package/node_modules/@earendil-works/pi-ai/dist/providers/data/zai.json +1 -1
  108. package/node_modules/@earendil-works/pi-ai/dist/providers/deepseek.models.js +4 -2
  109. package/node_modules/@earendil-works/pi-ai/dist/providers/fireworks.models.js +4 -2
  110. package/node_modules/@earendil-works/pi-ai/dist/providers/github-copilot.models.js +4 -2
  111. package/node_modules/@earendil-works/pi-ai/dist/providers/google-vertex.models.js +4 -2
  112. package/node_modules/@earendil-works/pi-ai/dist/providers/google.models.js +4 -2
  113. package/node_modules/@earendil-works/pi-ai/dist/providers/groq.models.js +4 -2
  114. package/node_modules/@earendil-works/pi-ai/dist/providers/huggingface.models.js +4 -2
  115. package/node_modules/@earendil-works/pi-ai/dist/providers/kimi-coding.models.js +4 -2
  116. package/node_modules/@earendil-works/pi-ai/dist/providers/meta.models.js +4 -2
  117. package/node_modules/@earendil-works/pi-ai/dist/providers/minimax-cn.models.js +4 -2
  118. package/node_modules/@earendil-works/pi-ai/dist/providers/minimax.models.js +4 -2
  119. package/node_modules/@earendil-works/pi-ai/dist/providers/mistral.models.js +4 -2
  120. package/node_modules/@earendil-works/pi-ai/dist/providers/moonshotai-cn.models.js +4 -2
  121. package/node_modules/@earendil-works/pi-ai/dist/providers/moonshotai.models.js +4 -2
  122. package/node_modules/@earendil-works/pi-ai/dist/providers/nvidia.models.js +4 -2
  123. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-codex.js +1 -1
  124. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-codex.models.js +4 -2
  125. package/node_modules/@earendil-works/pi-ai/dist/providers/openai.js +11 -2
  126. package/node_modules/@earendil-works/pi-ai/dist/providers/openai.models.js +4 -2
  127. package/node_modules/@earendil-works/pi-ai/dist/providers/opencode-go.models.js +4 -2
  128. package/node_modules/@earendil-works/pi-ai/dist/providers/opencode.js +5 -2
  129. package/node_modules/@earendil-works/pi-ai/dist/providers/opencode.models.js +4 -2
  130. package/node_modules/@earendil-works/pi-ai/dist/providers/openrouter.js +11 -2
  131. package/node_modules/@earendil-works/pi-ai/dist/providers/openrouter.models.js +4 -2
  132. package/node_modules/@earendil-works/pi-ai/dist/providers/qwen-token-plan-cn.models.js +4 -2
  133. package/node_modules/@earendil-works/pi-ai/dist/providers/qwen-token-plan-individual.models.js +4 -2
  134. package/node_modules/@earendil-works/pi-ai/dist/providers/qwen-token-plan.models.js +4 -2
  135. package/node_modules/@earendil-works/pi-ai/dist/providers/radius.models.js +4 -2
  136. package/node_modules/@earendil-works/pi-ai/dist/providers/together.models.js +4 -2
  137. package/node_modules/@earendil-works/pi-ai/dist/providers/typesafe.js +18 -0
  138. package/node_modules/@earendil-works/pi-ai/dist/providers/typesafe.models.js +8 -0
  139. package/node_modules/@earendil-works/pi-ai/dist/providers/vercel-ai-gateway.js +5 -2
  140. package/node_modules/@earendil-works/pi-ai/dist/providers/vercel-ai-gateway.models.js +4 -2
  141. package/node_modules/@earendil-works/pi-ai/dist/providers/xai.models.js +4 -2
  142. package/node_modules/@earendil-works/pi-ai/dist/providers/xiaomi-token-plan-ams.models.js +4 -2
  143. package/node_modules/@earendil-works/pi-ai/dist/providers/xiaomi-token-plan-cn.models.js +4 -2
  144. package/node_modules/@earendil-works/pi-ai/dist/providers/xiaomi-token-plan-sgp.models.js +4 -2
  145. package/node_modules/@earendil-works/pi-ai/dist/providers/xiaomi.models.js +4 -2
  146. package/node_modules/@earendil-works/pi-ai/dist/providers/zai-coding-cn.models.js +4 -2
  147. package/node_modules/@earendil-works/pi-ai/dist/providers/zai.models.js +4 -2
  148. package/node_modules/@earendil-works/pi-ai/dist/utils/headers.js +10 -8
  149. package/node_modules/@earendil-works/pi-ai/dist/utils/model-operations.js +47 -0
  150. package/node_modules/@earendil-works/pi-ai/dist/utils/models-error.js +19 -0
  151. package/node_modules/@earendil-works/pi-ai/dist/utils/retry.js +7 -0
  152. package/node_modules/@earendil-works/pi-ai/package.json +4 -4
  153. package/node_modules/@earendil-works/pi-telemetry/package.json +2 -2
  154. package/node_modules/openai/CHANGELOG.md +1089 -1
  155. package/node_modules/openai/README.md +201 -102
  156. package/node_modules/openai/_vendor/partial-json-parser/parser.js +55 -38
  157. package/node_modules/openai/_vendor/partial-json-parser/parser.mjs +55 -38
  158. package/node_modules/openai/_vendor/zod-to-json-schema/Options.js +11 -2
  159. package/node_modules/openai/_vendor/zod-to-json-schema/Options.mjs +11 -2
  160. package/node_modules/openai/_vendor/zod-to-json-schema/Refs.js +4 -4
  161. package/node_modules/openai/_vendor/zod-to-json-schema/Refs.mjs +4 -4
  162. package/node_modules/openai/_vendor/zod-to-json-schema/errorMessages.js +2 -1
  163. package/node_modules/openai/_vendor/zod-to-json-schema/errorMessages.mjs +2 -1
  164. package/node_modules/openai/_vendor/zod-to-json-schema/index.js +1 -1
  165. package/node_modules/openai/_vendor/zod-to-json-schema/index.mjs +1 -1
  166. package/node_modules/openai/_vendor/zod-to-json-schema/parseDef.js +139 -54
  167. package/node_modules/openai/_vendor/zod-to-json-schema/parseDef.mjs +139 -54
  168. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/array.js +1 -1
  169. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/array.mjs +1 -1
  170. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/bigint.js +10 -4
  171. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/bigint.mjs +10 -4
  172. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/branded.js +2 -2
  173. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/branded.mjs +2 -2
  174. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/catch.js +1 -3
  175. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/catch.mjs +1 -3
  176. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/date.js +10 -5
  177. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/date.mjs +10 -5
  178. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/default.js +2 -2
  179. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/default.mjs +2 -2
  180. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/intersection.js +6 -5
  181. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/intersection.mjs +6 -5
  182. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/literal.js +5 -0
  183. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/literal.mjs +5 -0
  184. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/nativeEnum.js +7 -9
  185. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/nativeEnum.mjs +7 -9
  186. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/null.js +3 -2
  187. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/null.mjs +3 -2
  188. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/nullable.js +8 -3
  189. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/nullable.mjs +8 -3
  190. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/number.js +12 -5
  191. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/number.mjs +12 -5
  192. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/object.js +43 -38
  193. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/object.mjs +43 -38
  194. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/optional.js +11 -12
  195. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/optional.mjs +11 -12
  196. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/pipeline.js +3 -3
  197. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/pipeline.mjs +3 -3
  198. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/promise.js +2 -2
  199. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/promise.mjs +2 -2
  200. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/readonly.js +1 -3
  201. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/readonly.mjs +1 -3
  202. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/record.js +7 -5
  203. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/record.mjs +7 -5
  204. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/string.js +57 -34
  205. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/string.mjs +57 -34
  206. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/tuple.js +24 -19
  207. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/tuple.mjs +24 -19
  208. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/union.js +46 -24
  209. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/union.mjs +46 -24
  210. package/node_modules/openai/_vendor/zod-to-json-schema/util.js +7 -5
  211. package/node_modules/openai/_vendor/zod-to-json-schema/util.mjs +7 -5
  212. package/node_modules/openai/_vendor/zod-to-json-schema/zodToJsonSchema.js +110 -38
  213. package/node_modules/openai/_vendor/zod-to-json-schema/zodToJsonSchema.mjs +110 -38
  214. package/node_modules/openai/auth/subject-token-providers.js +235 -10
  215. package/node_modules/openai/auth/subject-token-providers.mjs +235 -10
  216. package/node_modules/openai/auth/workload-identity-auth.js +185 -24
  217. package/node_modules/openai/auth/workload-identity-auth.mjs +186 -25
  218. package/node_modules/openai/auth/x509-transport.js +273 -0
  219. package/node_modules/openai/auth/x509-transport.mjs +268 -0
  220. package/node_modules/openai/azure.js +74 -21
  221. package/node_modules/openai/azure.mjs +75 -22
  222. package/node_modules/openai/bedrock.js +174 -0
  223. package/node_modules/openai/bedrock.mjs +169 -0
  224. package/node_modules/openai/beta/realtime/internal-base.js +71 -10
  225. package/node_modules/openai/beta/realtime/internal-base.mjs +70 -10
  226. package/node_modules/openai/beta/realtime/websocket.js +180 -33
  227. package/node_modules/openai/beta/realtime/websocket.mjs +181 -34
  228. package/node_modules/openai/beta/realtime/ws.js +93 -14
  229. package/node_modules/openai/beta/realtime/ws.mjs +94 -15
  230. package/node_modules/openai/client.js +745 -99
  231. package/node_modules/openai/client.mjs +747 -101
  232. package/node_modules/openai/core/EventEmitter.js +127 -16
  233. package/node_modules/openai/core/EventEmitter.mjs +128 -17
  234. package/node_modules/openai/core/api-promise.js +0 -1
  235. package/node_modules/openai/core/api-promise.mjs +0 -1
  236. package/node_modules/openai/core/error.js +5 -5
  237. package/node_modules/openai/core/error.mjs +5 -5
  238. package/node_modules/openai/core/pagination.js +33 -3
  239. package/node_modules/openai/core/pagination.mjs +31 -2
  240. package/node_modules/openai/core/resource.js +0 -1
  241. package/node_modules/openai/core/resource.mjs +0 -1
  242. package/node_modules/openai/core/streaming.js +453 -88
  243. package/node_modules/openai/core/streaming.mjs +454 -89
  244. package/node_modules/openai/core/uploads.js +3 -1
  245. package/node_modules/openai/core/uploads.mjs +1 -0
  246. package/node_modules/openai/helpers/audio.js +198 -28
  247. package/node_modules/openai/helpers/audio.mjs +199 -29
  248. package/node_modules/openai/helpers/live.js +6 -0
  249. package/node_modules/openai/helpers/live.mjs +2 -0
  250. package/node_modules/openai/helpers/standard-schema.js +393 -0
  251. package/node_modules/openai/helpers/standard-schema.mjs +387 -0
  252. package/node_modules/openai/helpers/zod-v3-strict-schema.js +408 -0
  253. package/node_modules/openai/helpers/zod-v3-strict-schema.mjs +404 -0
  254. package/node_modules/openai/helpers/zod.js +221 -24
  255. package/node_modules/openai/helpers/zod.mjs +222 -26
  256. package/node_modules/openai/index.js +8 -7
  257. package/node_modules/openai/index.mjs +2 -2
  258. package/node_modules/openai/internal/assistant-stream-delta.js +316 -0
  259. package/node_modules/openai/internal/assistant-stream-delta.mjs +308 -0
  260. package/node_modules/openai/internal/auth/x509-api-origin.js +28 -0
  261. package/node_modules/openai/internal/auth/x509-api-origin.mjs +24 -0
  262. package/node_modules/openai/internal/auth/x509-credential-options.js +125 -0
  263. package/node_modules/openai/internal/auth/x509-credential-options.mjs +121 -0
  264. package/node_modules/openai/internal/auth/x509-token-exchange.js +248 -0
  265. package/node_modules/openai/internal/auth/x509-token-exchange.mjs +245 -0
  266. package/node_modules/openai/internal/auth/x509-transport-capability.js +171 -0
  267. package/node_modules/openai/internal/auth/x509-transport-capability.mjs +166 -0
  268. package/node_modules/openai/internal/auth/x509-transport-registry.js +53 -0
  269. package/node_modules/openai/internal/auth/x509-transport-registry.mjs +48 -0
  270. package/node_modules/openai/internal/auth/x509-transport-state-browser.js +35 -0
  271. package/node_modules/openai/internal/auth/x509-transport-state-browser.mjs +32 -0
  272. package/node_modules/openai/internal/auth/x509-transport-state.cjs +35 -0
  273. package/node_modules/openai/internal/auth/x509-transport-state.js +36 -0
  274. package/node_modules/openai/internal/auth/x509-transport-state.mjs +20 -0
  275. package/node_modules/openai/internal/auth/x509-workload-identity-auth.js +787 -0
  276. package/node_modules/openai/internal/auth/x509-workload-identity-auth.mjs +778 -0
  277. package/node_modules/openai/internal/bedrock.js +438 -0
  278. package/node_modules/openai/internal/bedrock.mjs +424 -0
  279. package/node_modules/openai/internal/builtin-types.js +0 -1
  280. package/node_modules/openai/internal/builtin-types.mjs +0 -1
  281. package/node_modules/openai/internal/data-residency.js +34 -0
  282. package/node_modules/openai/internal/data-residency.mjs +30 -0
  283. package/node_modules/openai/internal/decoders/line.js +140 -54
  284. package/node_modules/openai/internal/decoders/line.mjs +141 -55
  285. package/node_modules/openai/internal/detect-platform.js +3 -4
  286. package/node_modules/openai/internal/detect-platform.mjs +3 -4
  287. package/node_modules/openai/internal/errors.js +3 -3
  288. package/node_modules/openai/internal/errors.mjs +3 -3
  289. package/node_modules/openai/internal/headers.js +11 -9
  290. package/node_modules/openai/internal/headers.mjs +11 -9
  291. package/node_modules/openai/internal/multipart-encoding.js +51 -0
  292. package/node_modules/openai/internal/multipart-encoding.mjs +48 -0
  293. package/node_modules/openai/internal/parse.js +35 -11
  294. package/node_modules/openai/internal/parse.mjs +35 -11
  295. package/node_modules/openai/internal/provider.js +50 -0
  296. package/node_modules/openai/internal/provider.mjs +46 -0
  297. package/node_modules/openai/internal/qs/formats.js +1 -2
  298. package/node_modules/openai/internal/qs/formats.mjs +1 -1
  299. package/node_modules/openai/internal/qs/stringify.js +60 -51
  300. package/node_modules/openai/internal/qs/stringify.mjs +60 -51
  301. package/node_modules/openai/internal/qs/utils.js +368 -50
  302. package/node_modules/openai/internal/qs/utils.mjs +368 -50
  303. package/node_modules/openai/internal/realtime-credentials.js +23 -0
  304. package/node_modules/openai/internal/realtime-credentials.mjs +19 -0
  305. package/node_modules/openai/internal/request-options.js +43 -2
  306. package/node_modules/openai/internal/request-options.mjs +42 -2
  307. package/node_modules/openai/internal/responses/canonical-output-text.js +123 -0
  308. package/node_modules/openai/internal/responses/canonical-output-text.mjs +115 -0
  309. package/node_modules/openai/internal/responses/output-text-index.js +77 -0
  310. package/node_modules/openai/internal/responses/output-text-index.mjs +73 -0
  311. package/node_modules/openai/internal/responses/response-accumulator.js +942 -0
  312. package/node_modules/openai/internal/responses/response-accumulator.mjs +938 -0
  313. package/node_modules/openai/internal/shim-types.js +6 -1
  314. package/node_modules/openai/internal/shim-types.mjs +6 -1
  315. package/node_modules/openai/internal/shims.js +6 -1
  316. package/node_modules/openai/internal/shims.mjs +6 -1
  317. package/node_modules/openai/internal/stream-utils.js +35 -7
  318. package/node_modules/openai/internal/stream-utils.mjs +35 -7
  319. package/node_modules/openai/internal/to-file.js +47 -24
  320. package/node_modules/openai/internal/to-file.mjs +47 -24
  321. package/node_modules/openai/internal/tslib.js +6 -0
  322. package/node_modules/openai/internal/tslib.mjs +6 -1
  323. package/node_modules/openai/internal/types.js +0 -1
  324. package/node_modules/openai/internal/types.mjs +0 -1
  325. package/node_modules/openai/internal/uploads.js +377 -43
  326. package/node_modules/openai/internal/uploads.mjs +376 -44
  327. package/node_modules/openai/internal/utils/abort.js +94 -0
  328. package/node_modules/openai/internal/utils/abort.mjs +90 -0
  329. package/node_modules/openai/internal/utils/base64.js +3 -1
  330. package/node_modules/openai/internal/utils/base64.mjs +3 -1
  331. package/node_modules/openai/internal/utils/bytes.js +5 -0
  332. package/node_modules/openai/internal/utils/bytes.mjs +5 -0
  333. package/node_modules/openai/internal/utils/env.js +9 -5
  334. package/node_modules/openai/internal/utils/env.mjs +9 -5
  335. package/node_modules/openai/internal/utils/log.js +73 -11
  336. package/node_modules/openai/internal/utils/log.mjs +70 -11
  337. package/node_modules/openai/internal/utils/path.js +50 -30
  338. package/node_modules/openai/internal/utils/path.mjs +50 -30
  339. package/node_modules/openai/internal/utils/query.js +0 -1
  340. package/node_modules/openai/internal/utils/query.mjs +0 -1
  341. package/node_modules/openai/internal/utils/sleep.js +51 -2
  342. package/node_modules/openai/internal/utils/sleep.mjs +51 -2
  343. package/node_modules/openai/internal/utils/uuid.js +0 -1
  344. package/node_modules/openai/internal/utils/uuid.mjs +0 -1
  345. package/node_modules/openai/internal/utils/values.js +0 -1
  346. package/node_modules/openai/internal/utils/values.mjs +0 -1
  347. package/node_modules/openai/internal/utils.js +0 -1
  348. package/node_modules/openai/internal/utils.mjs +0 -1
  349. package/node_modules/openai/internal/ws-adapter-browser.js +66 -21
  350. package/node_modules/openai/internal/ws-adapter-browser.mjs +66 -21
  351. package/node_modules/openai/internal/ws-adapter-node.js +90 -24
  352. package/node_modules/openai/internal/ws-adapter-node.mjs +90 -24
  353. package/node_modules/openai/internal/ws-adapter.js +4 -0
  354. package/node_modules/openai/internal/ws-adapter.mjs +4 -0
  355. package/node_modules/openai/internal/ws.js +193 -48
  356. package/node_modules/openai/internal/ws.mjs +188 -49
  357. package/node_modules/openai/lib/AbstractChatCompletionRunner.js +254 -72
  358. package/node_modules/openai/lib/AbstractChatCompletionRunner.mjs +256 -74
  359. package/node_modules/openai/lib/AssistantStream.js +430 -259
  360. package/node_modules/openai/lib/AssistantStream.mjs +432 -261
  361. package/node_modules/openai/lib/ChatCompletionRunner.js +12 -5
  362. package/node_modules/openai/lib/ChatCompletionRunner.mjs +13 -6
  363. package/node_modules/openai/lib/ChatCompletionStream.js +1430 -189
  364. package/node_modules/openai/lib/ChatCompletionStream.mjs +1433 -193
  365. package/node_modules/openai/lib/ChatCompletionStreamingRunner.js +40 -2
  366. package/node_modules/openai/lib/ChatCompletionStreamingRunner.mjs +41 -3
  367. package/node_modules/openai/lib/EventEmitter.js +124 -16
  368. package/node_modules/openai/lib/EventEmitter.mjs +125 -17
  369. package/node_modules/openai/lib/EventStream.js +1533 -55
  370. package/node_modules/openai/lib/EventStream.mjs +1534 -56
  371. package/node_modules/openai/lib/ResponsesParser.js +68 -29
  372. package/node_modules/openai/lib/ResponsesParser.mjs +69 -30
  373. package/node_modules/openai/lib/RunnableFunction.js +3 -0
  374. package/node_modules/openai/lib/RunnableFunction.mjs +3 -0
  375. package/node_modules/openai/lib/Util.js +7 -4
  376. package/node_modules/openai/lib/Util.mjs +7 -4
  377. package/node_modules/openai/lib/agents/agent-session-stream.js +274 -0
  378. package/node_modules/openai/lib/agents/agent-session-stream.mjs +270 -0
  379. package/node_modules/openai/lib/agents/output-text.js +8 -0
  380. package/node_modules/openai/lib/agents/output-text.mjs +5 -0
  381. package/node_modules/openai/lib/agents/turn-state.js +62 -0
  382. package/node_modules/openai/lib/agents/turn-state.mjs +58 -0
  383. package/node_modules/openai/lib/assistant-run-polling.js +17 -0
  384. package/node_modules/openai/lib/assistant-run-polling.mjs +14 -0
  385. package/node_modules/openai/lib/chatCompletionUtils.js +5 -6
  386. package/node_modules/openai/lib/chatCompletionUtils.mjs +5 -6
  387. package/node_modules/openai/lib/embeddings.js +58 -0
  388. package/node_modules/openai/lib/embeddings.mjs +55 -0
  389. package/node_modules/openai/lib/file-processing.js +31 -0
  390. package/node_modules/openai/lib/file-processing.mjs +28 -0
  391. package/node_modules/openai/lib/live/transcript-grouper.js +229 -0
  392. package/node_modules/openai/lib/live/transcript-grouper.mjs +225 -0
  393. package/node_modules/openai/lib/live/transcript-grouping.js +309 -0
  394. package/node_modules/openai/lib/live/transcript-grouping.mjs +305 -0
  395. package/node_modules/openai/lib/live/webrtc.js +16 -0
  396. package/node_modules/openai/lib/live/webrtc.mjs +10 -0
  397. package/node_modules/openai/lib/parser.js +142 -42
  398. package/node_modules/openai/lib/parser.mjs +140 -42
  399. package/node_modules/openai/lib/polling.js +131 -0
  400. package/node_modules/openai/lib/polling.mjs +128 -0
  401. package/node_modules/openai/lib/realtime/webrtc.js +16 -0
  402. package/node_modules/openai/lib/realtime/webrtc.mjs +10 -0
  403. package/node_modules/openai/lib/responses/ResponseAccumulator.js +15 -0
  404. package/node_modules/openai/lib/responses/ResponseAccumulator.mjs +12 -0
  405. package/node_modules/openai/lib/responses/ResponseInputItems.js +139 -0
  406. package/node_modules/openai/lib/responses/ResponseInputItems.mjs +135 -0
  407. package/node_modules/openai/lib/responses/ResponseStream.js +85 -159
  408. package/node_modules/openai/lib/responses/ResponseStream.mjs +86 -160
  409. package/node_modules/openai/lib/responses/responses-websocket-lane.js +314 -0
  410. package/node_modules/openai/lib/responses/responses-websocket-lane.mjs +309 -0
  411. package/node_modules/openai/lib/responses/responses-websocket-session.js +268 -0
  412. package/node_modules/openai/lib/responses/responses-websocket-session.mjs +263 -0
  413. package/node_modules/openai/lib/transform.js +1608 -82
  414. package/node_modules/openai/lib/transform.mjs +1602 -82
  415. package/node_modules/openai/lib/vector-store-polling.js +24 -0
  416. package/node_modules/openai/lib/vector-store-polling.mjs +20 -0
  417. package/node_modules/openai/lib/vector-store-upload.js +41 -0
  418. package/node_modules/openai/lib/vector-store-upload.mjs +38 -0
  419. package/node_modules/openai/lib/webhook-signature.js +125 -0
  420. package/node_modules/openai/lib/webhook-signature.mjs +121 -0
  421. package/node_modules/openai/lib/webrtc/connection.js +233 -0
  422. package/node_modules/openai/lib/webrtc/connection.mjs +229 -0
  423. package/node_modules/openai/lib/webrtc/data-channel.js +133 -0
  424. package/node_modules/openai/lib/webrtc/data-channel.mjs +129 -0
  425. package/node_modules/openai/lib/webrtc/errors.js +18 -0
  426. package/node_modules/openai/lib/webrtc/errors.mjs +14 -0
  427. package/node_modules/openai/lib/webrtc/subscriptions.js +64 -0
  428. package/node_modules/openai/lib/webrtc/subscriptions.mjs +60 -0
  429. package/node_modules/openai/lib/webrtc/types.js +3 -0
  430. package/node_modules/openai/lib/webrtc/types.mjs +2 -0
  431. package/node_modules/openai/live/webrtc.js +8 -0
  432. package/node_modules/openai/live/webrtc.mjs +2 -0
  433. package/node_modules/openai/package.json +71 -11
  434. package/node_modules/openai/providers/bedrock/aws.js +211 -0
  435. package/node_modules/openai/providers/bedrock/aws.mjs +207 -0
  436. package/node_modules/openai/providers/bedrock.js +43 -0
  437. package/node_modules/openai/providers/bedrock.mjs +39 -0
  438. package/node_modules/openai/realtime/internal-base.js +118 -11
  439. package/node_modules/openai/realtime/internal-base.mjs +116 -11
  440. package/node_modules/openai/realtime/webrtc.js +8 -0
  441. package/node_modules/openai/realtime/webrtc.mjs +2 -0
  442. package/node_modules/openai/realtime/websocket.js +174 -39
  443. package/node_modules/openai/realtime/websocket.mjs +175 -40
  444. package/node_modules/openai/realtime/ws.js +86 -18
  445. package/node_modules/openai/realtime/ws.mjs +87 -19
  446. package/node_modules/openai/resources/admin/admin.js +1 -1
  447. package/node_modules/openai/resources/admin/admin.mjs +1 -1
  448. package/node_modules/openai/resources/admin/index.js +1 -1
  449. package/node_modules/openai/resources/admin/index.mjs +1 -1
  450. package/node_modules/openai/resources/admin/organization/admin-api-keys.js +1 -1
  451. package/node_modules/openai/resources/admin/organization/admin-api-keys.mjs +1 -1
  452. package/node_modules/openai/resources/admin/organization/audit-logs.js +1 -1
  453. package/node_modules/openai/resources/admin/organization/audit-logs.mjs +1 -1
  454. package/node_modules/openai/resources/admin/organization/certificates.js +1 -1
  455. package/node_modules/openai/resources/admin/organization/certificates.mjs +1 -1
  456. package/node_modules/openai/resources/admin/organization/data-retention.js +1 -1
  457. package/node_modules/openai/resources/admin/organization/data-retention.mjs +1 -1
  458. package/node_modules/openai/resources/admin/organization/groups/groups.js +1 -1
  459. package/node_modules/openai/resources/admin/organization/groups/groups.mjs +1 -1
  460. package/node_modules/openai/resources/admin/organization/groups/index.js +1 -1
  461. package/node_modules/openai/resources/admin/organization/groups/index.mjs +1 -1
  462. package/node_modules/openai/resources/admin/organization/groups/roles.js +1 -1
  463. package/node_modules/openai/resources/admin/organization/groups/roles.mjs +1 -1
  464. package/node_modules/openai/resources/admin/organization/groups/users.js +1 -1
  465. package/node_modules/openai/resources/admin/organization/groups/users.mjs +1 -1
  466. package/node_modules/openai/resources/admin/organization/groups.js +1 -1
  467. package/node_modules/openai/resources/admin/organization/groups.mjs +1 -1
  468. package/node_modules/openai/resources/admin/organization/index.js +4 -2
  469. package/node_modules/openai/resources/admin/organization/index.mjs +2 -1
  470. package/node_modules/openai/resources/admin/organization/invites.js +1 -1
  471. package/node_modules/openai/resources/admin/organization/invites.mjs +1 -1
  472. package/node_modules/openai/resources/admin/organization/organization.js +5 -1
  473. package/node_modules/openai/resources/admin/organization/organization.mjs +5 -1
  474. package/node_modules/openai/resources/admin/organization/projects/api-keys.js +1 -1
  475. package/node_modules/openai/resources/admin/organization/projects/api-keys.mjs +1 -1
  476. package/node_modules/openai/resources/admin/organization/projects/certificates.js +1 -1
  477. package/node_modules/openai/resources/admin/organization/projects/certificates.mjs +1 -1
  478. package/node_modules/openai/resources/admin/organization/projects/data-retention.js +1 -1
  479. package/node_modules/openai/resources/admin/organization/projects/data-retention.mjs +1 -1
  480. package/node_modules/openai/resources/admin/organization/projects/groups/groups.js +1 -1
  481. package/node_modules/openai/resources/admin/organization/projects/groups/groups.mjs +1 -1
  482. package/node_modules/openai/resources/admin/organization/projects/groups/index.js +1 -1
  483. package/node_modules/openai/resources/admin/organization/projects/groups/index.mjs +1 -1
  484. package/node_modules/openai/resources/admin/organization/projects/groups/roles.js +1 -1
  485. package/node_modules/openai/resources/admin/organization/projects/groups/roles.mjs +1 -1
  486. package/node_modules/openai/resources/admin/organization/projects/groups.js +1 -1
  487. package/node_modules/openai/resources/admin/organization/projects/groups.mjs +1 -1
  488. package/node_modules/openai/resources/admin/organization/projects/hosted-tool-permissions.js +1 -1
  489. package/node_modules/openai/resources/admin/organization/projects/hosted-tool-permissions.mjs +1 -1
  490. package/node_modules/openai/resources/admin/organization/projects/index.js +8 -6
  491. package/node_modules/openai/resources/admin/organization/projects/index.mjs +3 -2
  492. package/node_modules/openai/resources/admin/organization/projects/model-permissions.js +1 -1
  493. package/node_modules/openai/resources/admin/organization/projects/model-permissions.mjs +1 -1
  494. package/node_modules/openai/resources/admin/organization/projects/projects.js +7 -3
  495. package/node_modules/openai/resources/admin/organization/projects/projects.mjs +7 -3
  496. package/node_modules/openai/resources/admin/organization/projects/rate-limits.js +1 -1
  497. package/node_modules/openai/resources/admin/organization/projects/rate-limits.mjs +1 -1
  498. package/node_modules/openai/resources/admin/organization/projects/roles.js +1 -1
  499. package/node_modules/openai/resources/admin/organization/projects/roles.mjs +1 -1
  500. package/node_modules/openai/resources/admin/organization/projects/service-accounts/api-keys.js +26 -0
  501. package/node_modules/openai/resources/admin/organization/projects/service-accounts/api-keys.mjs +22 -0
  502. package/node_modules/openai/resources/admin/organization/projects/service-accounts/index.js +9 -0
  503. package/node_modules/openai/resources/admin/organization/projects/service-accounts/index.mjs +4 -0
  504. package/node_modules/openai/resources/admin/organization/projects/service-accounts/service-accounts.js +109 -0
  505. package/node_modules/openai/resources/admin/organization/projects/service-accounts/service-accounts.mjs +104 -0
  506. package/node_modules/openai/resources/admin/organization/projects/service-accounts.js +3 -98
  507. package/node_modules/openai/resources/admin/organization/projects/service-accounts.mjs +2 -96
  508. package/node_modules/openai/resources/admin/organization/projects/spend-alerts.js +20 -1
  509. package/node_modules/openai/resources/admin/organization/projects/spend-alerts.mjs +20 -1
  510. package/node_modules/openai/resources/admin/organization/projects/spend-limit.js +67 -0
  511. package/node_modules/openai/resources/admin/organization/projects/spend-limit.mjs +63 -0
  512. package/node_modules/openai/resources/admin/organization/projects/users/index.js +1 -1
  513. package/node_modules/openai/resources/admin/organization/projects/users/index.mjs +1 -1
  514. package/node_modules/openai/resources/admin/organization/projects/users/roles.js +1 -1
  515. package/node_modules/openai/resources/admin/organization/projects/users/roles.mjs +1 -1
  516. package/node_modules/openai/resources/admin/organization/projects/users/users.js +1 -1
  517. package/node_modules/openai/resources/admin/organization/projects/users/users.mjs +1 -1
  518. package/node_modules/openai/resources/admin/organization/projects/users.js +1 -1
  519. package/node_modules/openai/resources/admin/organization/projects/users.mjs +1 -1
  520. package/node_modules/openai/resources/admin/organization/projects.js +1 -1
  521. package/node_modules/openai/resources/admin/organization/projects.mjs +1 -1
  522. package/node_modules/openai/resources/admin/organization/roles.js +1 -1
  523. package/node_modules/openai/resources/admin/organization/roles.mjs +1 -1
  524. package/node_modules/openai/resources/admin/organization/spend-alerts.js +18 -1
  525. package/node_modules/openai/resources/admin/organization/spend-alerts.mjs +18 -1
  526. package/node_modules/openai/resources/admin/organization/spend-limit.js +59 -0
  527. package/node_modules/openai/resources/admin/organization/spend-limit.mjs +55 -0
  528. package/node_modules/openai/resources/admin/organization/usage.js +1 -1
  529. package/node_modules/openai/resources/admin/organization/usage.mjs +1 -1
  530. package/node_modules/openai/resources/admin/organization/users/index.js +1 -1
  531. package/node_modules/openai/resources/admin/organization/users/index.mjs +1 -1
  532. package/node_modules/openai/resources/admin/organization/users/roles.js +1 -1
  533. package/node_modules/openai/resources/admin/organization/users/roles.mjs +1 -1
  534. package/node_modules/openai/resources/admin/organization/users/users.js +1 -1
  535. package/node_modules/openai/resources/admin/organization/users/users.mjs +1 -1
  536. package/node_modules/openai/resources/admin/organization/users.js +1 -1
  537. package/node_modules/openai/resources/admin/organization/users.mjs +1 -1
  538. package/node_modules/openai/resources/admin/organization.js +1 -1
  539. package/node_modules/openai/resources/admin/organization.mjs +1 -1
  540. package/node_modules/openai/resources/admin.js +1 -1
  541. package/node_modules/openai/resources/admin.mjs +1 -1
  542. package/node_modules/openai/resources/audio/audio.js +1 -1
  543. package/node_modules/openai/resources/audio/audio.mjs +1 -1
  544. package/node_modules/openai/resources/audio/index.js +1 -1
  545. package/node_modules/openai/resources/audio/index.mjs +1 -1
  546. package/node_modules/openai/resources/audio/speech.js +1 -1
  547. package/node_modules/openai/resources/audio/speech.mjs +1 -1
  548. package/node_modules/openai/resources/audio/transcriptions.js +1 -1
  549. package/node_modules/openai/resources/audio/transcriptions.mjs +1 -1
  550. package/node_modules/openai/resources/audio/translations.js +1 -1
  551. package/node_modules/openai/resources/audio/translations.mjs +1 -1
  552. package/node_modules/openai/resources/audio.js +1 -1
  553. package/node_modules/openai/resources/audio.mjs +1 -1
  554. package/node_modules/openai/resources/batches.js +1 -1
  555. package/node_modules/openai/resources/batches.mjs +1 -1
  556. package/node_modules/openai/resources/beta/agents/agents.js +118 -0
  557. package/node_modules/openai/resources/beta/agents/agents.mjs +113 -0
  558. package/node_modules/openai/resources/beta/agents/environments/environments.js +43 -0
  559. package/node_modules/openai/resources/beta/agents/environments/environments.mjs +38 -0
  560. package/node_modules/openai/resources/beta/agents/environments/files.js +61 -0
  561. package/node_modules/openai/resources/beta/agents/environments/files.mjs +57 -0
  562. package/node_modules/openai/resources/beta/agents/environments/index.js +11 -0
  563. package/node_modules/openai/resources/beta/agents/environments/index.mjs +5 -0
  564. package/node_modules/openai/resources/beta/agents/environments/templates.js +112 -0
  565. package/node_modules/openai/resources/beta/agents/environments/templates.mjs +108 -0
  566. package/node_modules/openai/resources/beta/agents/environments.js +6 -0
  567. package/node_modules/openai/resources/beta/agents/environments.mjs +3 -0
  568. package/node_modules/openai/resources/beta/agents/index.js +13 -0
  569. package/node_modules/openai/resources/beta/agents/index.mjs +6 -0
  570. package/node_modules/openai/resources/beta/agents/sessions/artifacts.js +106 -0
  571. package/node_modules/openai/resources/beta/agents/sessions/artifacts.mjs +102 -0
  572. package/node_modules/openai/resources/beta/agents/sessions/events.js +75 -0
  573. package/node_modules/openai/resources/beta/agents/sessions/events.mjs +71 -0
  574. package/node_modules/openai/resources/beta/agents/sessions/index.js +17 -0
  575. package/node_modules/openai/resources/beta/agents/sessions/index.mjs +8 -0
  576. package/node_modules/openai/resources/beta/agents/sessions/items.js +35 -0
  577. package/node_modules/openai/resources/beta/agents/sessions/items.mjs +31 -0
  578. package/node_modules/openai/resources/beta/agents/sessions/sessions.js +127 -0
  579. package/node_modules/openai/resources/beta/agents/sessions/sessions.mjs +122 -0
  580. package/node_modules/openai/resources/beta/agents/sessions/subagents/index.js +11 -0
  581. package/node_modules/openai/resources/beta/agents/sessions/subagents/index.mjs +5 -0
  582. package/node_modules/openai/resources/beta/agents/sessions/subagents/items.js +36 -0
  583. package/node_modules/openai/resources/beta/agents/sessions/subagents/items.mjs +32 -0
  584. package/node_modules/openai/resources/beta/agents/sessions/subagents/subagents.js +67 -0
  585. package/node_modules/openai/resources/beta/agents/sessions/subagents/subagents.mjs +62 -0
  586. package/node_modules/openai/resources/beta/agents/sessions/subagents/turns/index.js +9 -0
  587. package/node_modules/openai/resources/beta/agents/sessions/subagents/turns/index.mjs +4 -0
  588. package/node_modules/openai/resources/beta/agents/sessions/subagents/turns/items.js +36 -0
  589. package/node_modules/openai/resources/beta/agents/sessions/subagents/turns/items.mjs +32 -0
  590. package/node_modules/openai/resources/beta/agents/sessions/subagents/turns/turns.js +68 -0
  591. package/node_modules/openai/resources/beta/agents/sessions/subagents/turns/turns.mjs +63 -0
  592. package/node_modules/openai/resources/beta/agents/sessions/subagents/turns.js +6 -0
  593. package/node_modules/openai/resources/beta/agents/sessions/subagents/turns.mjs +3 -0
  594. package/node_modules/openai/resources/beta/agents/sessions/subagents.js +6 -0
  595. package/node_modules/openai/resources/beta/agents/sessions/subagents.mjs +3 -0
  596. package/node_modules/openai/resources/beta/agents/sessions/turns.js +57 -0
  597. package/node_modules/openai/resources/beta/agents/sessions/turns.mjs +53 -0
  598. package/node_modules/openai/resources/beta/agents/sessions.js +6 -0
  599. package/node_modules/openai/resources/beta/agents/sessions.mjs +3 -0
  600. package/node_modules/openai/resources/beta/agents/vaults/credentials.js +132 -0
  601. package/node_modules/openai/resources/beta/agents/vaults/credentials.mjs +128 -0
  602. package/node_modules/openai/resources/beta/agents/vaults/index.js +9 -0
  603. package/node_modules/openai/resources/beta/agents/vaults/index.mjs +4 -0
  604. package/node_modules/openai/resources/beta/agents/vaults/vaults.js +93 -0
  605. package/node_modules/openai/resources/beta/agents/vaults/vaults.mjs +88 -0
  606. package/node_modules/openai/resources/beta/agents/vaults.js +6 -0
  607. package/node_modules/openai/resources/beta/agents/vaults.mjs +3 -0
  608. package/node_modules/openai/resources/beta/agents.js +6 -0
  609. package/node_modules/openai/resources/beta/agents.mjs +3 -0
  610. package/node_modules/openai/resources/beta/assistants.js +1 -1
  611. package/node_modules/openai/resources/beta/assistants.mjs +1 -1
  612. package/node_modules/openai/resources/beta/beta.js +9 -1
  613. package/node_modules/openai/resources/beta/beta.mjs +9 -1
  614. package/node_modules/openai/resources/beta/chatkit/chatkit.js +1 -1
  615. package/node_modules/openai/resources/beta/chatkit/chatkit.mjs +1 -1
  616. package/node_modules/openai/resources/beta/chatkit/index.js +1 -1
  617. package/node_modules/openai/resources/beta/chatkit/index.mjs +1 -1
  618. package/node_modules/openai/resources/beta/chatkit/sessions.js +1 -1
  619. package/node_modules/openai/resources/beta/chatkit/sessions.mjs +1 -1
  620. package/node_modules/openai/resources/beta/chatkit/threads.js +1 -1
  621. package/node_modules/openai/resources/beta/chatkit/threads.mjs +1 -1
  622. package/node_modules/openai/resources/beta/chatkit.js +1 -1
  623. package/node_modules/openai/resources/beta/chatkit.mjs +1 -1
  624. package/node_modules/openai/resources/beta/index.js +12 -8
  625. package/node_modules/openai/resources/beta/index.mjs +3 -1
  626. package/node_modules/openai/resources/beta/realtime/index.js +0 -1
  627. package/node_modules/openai/resources/beta/realtime/index.mjs +0 -1
  628. package/node_modules/openai/resources/beta/realtime/realtime.js +0 -1
  629. package/node_modules/openai/resources/beta/realtime/realtime.mjs +0 -1
  630. package/node_modules/openai/resources/beta/realtime/sessions.js +0 -1
  631. package/node_modules/openai/resources/beta/realtime/sessions.mjs +0 -1
  632. package/node_modules/openai/resources/beta/realtime/transcription-sessions.js +0 -1
  633. package/node_modules/openai/resources/beta/realtime/transcription-sessions.mjs +0 -1
  634. package/node_modules/openai/resources/beta/realtime.js +0 -1
  635. package/node_modules/openai/resources/beta/realtime.mjs +0 -1
  636. package/node_modules/openai/resources/beta/responses/index.js +11 -0
  637. package/node_modules/openai/resources/beta/responses/index.mjs +5 -0
  638. package/node_modules/openai/resources/beta/responses/input-items.js +37 -0
  639. package/node_modules/openai/resources/beta/responses/input-items.mjs +33 -0
  640. package/node_modules/openai/resources/beta/responses/input-tokens.js +34 -0
  641. package/node_modules/openai/resources/beta/responses/input-tokens.mjs +30 -0
  642. package/node_modules/openai/resources/beta/responses/internal-base.js +66 -0
  643. package/node_modules/openai/resources/beta/responses/internal-base.mjs +60 -0
  644. package/node_modules/openai/resources/beta/responses/responses.js +121 -0
  645. package/node_modules/openai/resources/beta/responses/responses.mjs +116 -0
  646. package/node_modules/openai/resources/beta/responses/ws-base.js +566 -0
  647. package/node_modules/openai/resources/beta/responses/ws-base.mjs +560 -0
  648. package/node_modules/openai/resources/beta/responses/ws.js +47 -0
  649. package/node_modules/openai/resources/beta/responses/ws.mjs +42 -0
  650. package/node_modules/openai/resources/beta/responses.js +6 -0
  651. package/node_modules/openai/resources/beta/responses.mjs +3 -0
  652. package/node_modules/openai/resources/beta/threads/index.js +1 -1
  653. package/node_modules/openai/resources/beta/threads/index.mjs +1 -1
  654. package/node_modules/openai/resources/beta/threads/messages.js +1 -1
  655. package/node_modules/openai/resources/beta/threads/messages.mjs +1 -1
  656. package/node_modules/openai/resources/beta/threads/runs/index.js +1 -1
  657. package/node_modules/openai/resources/beta/threads/runs/index.mjs +1 -1
  658. package/node_modules/openai/resources/beta/threads/runs/runs.js +3 -44
  659. package/node_modules/openai/resources/beta/threads/runs/runs.mjs +3 -44
  660. package/node_modules/openai/resources/beta/threads/runs/steps.js +1 -1
  661. package/node_modules/openai/resources/beta/threads/runs/steps.mjs +1 -1
  662. package/node_modules/openai/resources/beta/threads/runs.js +1 -1
  663. package/node_modules/openai/resources/beta/threads/runs.mjs +1 -1
  664. package/node_modules/openai/resources/beta/threads/threads.js +1 -1
  665. package/node_modules/openai/resources/beta/threads/threads.mjs +1 -1
  666. package/node_modules/openai/resources/beta/threads.js +1 -1
  667. package/node_modules/openai/resources/beta/threads.mjs +1 -1
  668. package/node_modules/openai/resources/beta.js +1 -1
  669. package/node_modules/openai/resources/beta.mjs +1 -1
  670. package/node_modules/openai/resources/chat/chat.js +1 -1
  671. package/node_modules/openai/resources/chat/chat.mjs +1 -1
  672. package/node_modules/openai/resources/chat/completions/completions.js +2 -5
  673. package/node_modules/openai/resources/chat/completions/completions.mjs +2 -5
  674. package/node_modules/openai/resources/chat/completions/index.js +1 -1
  675. package/node_modules/openai/resources/chat/completions/index.mjs +1 -1
  676. package/node_modules/openai/resources/chat/completions/messages.js +1 -1
  677. package/node_modules/openai/resources/chat/completions/messages.mjs +1 -1
  678. package/node_modules/openai/resources/chat/completions.js +1 -1
  679. package/node_modules/openai/resources/chat/completions.mjs +1 -1
  680. package/node_modules/openai/resources/chat/index.js +1 -1
  681. package/node_modules/openai/resources/chat/index.mjs +1 -1
  682. package/node_modules/openai/resources/chat.js +1 -1
  683. package/node_modules/openai/resources/chat.mjs +1 -1
  684. package/node_modules/openai/resources/completions.js +1 -1
  685. package/node_modules/openai/resources/completions.mjs +1 -1
  686. package/node_modules/openai/resources/containers/containers.js +1 -1
  687. package/node_modules/openai/resources/containers/containers.mjs +1 -1
  688. package/node_modules/openai/resources/containers/files/content.js +1 -1
  689. package/node_modules/openai/resources/containers/files/content.mjs +1 -1
  690. package/node_modules/openai/resources/containers/files/files.js +1 -1
  691. package/node_modules/openai/resources/containers/files/files.mjs +1 -1
  692. package/node_modules/openai/resources/containers/files/index.js +1 -1
  693. package/node_modules/openai/resources/containers/files/index.mjs +1 -1
  694. package/node_modules/openai/resources/containers/files.js +1 -1
  695. package/node_modules/openai/resources/containers/files.mjs +1 -1
  696. package/node_modules/openai/resources/containers/index.js +1 -1
  697. package/node_modules/openai/resources/containers/index.mjs +1 -1
  698. package/node_modules/openai/resources/containers.js +1 -1
  699. package/node_modules/openai/resources/containers.mjs +1 -1
  700. package/node_modules/openai/resources/content-provenance-checks.js +24 -0
  701. package/node_modules/openai/resources/content-provenance-checks.mjs +20 -0
  702. package/node_modules/openai/resources/conversations/conversations.js +1 -1
  703. package/node_modules/openai/resources/conversations/conversations.mjs +1 -1
  704. package/node_modules/openai/resources/conversations/index.js +1 -1
  705. package/node_modules/openai/resources/conversations/index.mjs +1 -1
  706. package/node_modules/openai/resources/conversations/items.js +1 -1
  707. package/node_modules/openai/resources/conversations/items.mjs +1 -1
  708. package/node_modules/openai/resources/conversations.js +1 -1
  709. package/node_modules/openai/resources/conversations.mjs +1 -1
  710. package/node_modules/openai/resources/embeddings.js +3 -47
  711. package/node_modules/openai/resources/embeddings.mjs +3 -47
  712. package/node_modules/openai/resources/evals/evals.js +2 -2
  713. package/node_modules/openai/resources/evals/evals.mjs +2 -2
  714. package/node_modules/openai/resources/evals/index.js +1 -1
  715. package/node_modules/openai/resources/evals/index.mjs +1 -1
  716. package/node_modules/openai/resources/evals/runs/index.js +1 -1
  717. package/node_modules/openai/resources/evals/runs/index.mjs +1 -1
  718. package/node_modules/openai/resources/evals/runs/output-items.js +1 -1
  719. package/node_modules/openai/resources/evals/runs/output-items.mjs +1 -1
  720. package/node_modules/openai/resources/evals/runs/runs.js +1 -1
  721. package/node_modules/openai/resources/evals/runs/runs.mjs +1 -1
  722. package/node_modules/openai/resources/evals/runs.js +1 -1
  723. package/node_modules/openai/resources/evals/runs.mjs +1 -1
  724. package/node_modules/openai/resources/evals.js +1 -1
  725. package/node_modules/openai/resources/evals.mjs +1 -1
  726. package/node_modules/openai/resources/files.js +9 -22
  727. package/node_modules/openai/resources/files.mjs +9 -22
  728. package/node_modules/openai/resources/fine-tuning/alpha/alpha.js +1 -1
  729. package/node_modules/openai/resources/fine-tuning/alpha/alpha.mjs +1 -1
  730. package/node_modules/openai/resources/fine-tuning/alpha/graders.js +1 -1
  731. package/node_modules/openai/resources/fine-tuning/alpha/graders.mjs +1 -1
  732. package/node_modules/openai/resources/fine-tuning/alpha/index.js +1 -1
  733. package/node_modules/openai/resources/fine-tuning/alpha/index.mjs +1 -1
  734. package/node_modules/openai/resources/fine-tuning/alpha.js +1 -1
  735. package/node_modules/openai/resources/fine-tuning/alpha.mjs +1 -1
  736. package/node_modules/openai/resources/fine-tuning/checkpoints/checkpoints.js +1 -1
  737. package/node_modules/openai/resources/fine-tuning/checkpoints/checkpoints.mjs +1 -1
  738. package/node_modules/openai/resources/fine-tuning/checkpoints/index.js +1 -1
  739. package/node_modules/openai/resources/fine-tuning/checkpoints/index.mjs +1 -1
  740. package/node_modules/openai/resources/fine-tuning/checkpoints/permissions.js +9 -5
  741. package/node_modules/openai/resources/fine-tuning/checkpoints/permissions.mjs +9 -5
  742. package/node_modules/openai/resources/fine-tuning/checkpoints.js +1 -1
  743. package/node_modules/openai/resources/fine-tuning/checkpoints.mjs +1 -1
  744. package/node_modules/openai/resources/fine-tuning/fine-tuning.js +1 -1
  745. package/node_modules/openai/resources/fine-tuning/fine-tuning.mjs +1 -1
  746. package/node_modules/openai/resources/fine-tuning/index.js +1 -1
  747. package/node_modules/openai/resources/fine-tuning/index.mjs +1 -1
  748. package/node_modules/openai/resources/fine-tuning/jobs/checkpoints.js +1 -1
  749. package/node_modules/openai/resources/fine-tuning/jobs/checkpoints.mjs +1 -1
  750. package/node_modules/openai/resources/fine-tuning/jobs/index.js +1 -1
  751. package/node_modules/openai/resources/fine-tuning/jobs/index.mjs +1 -1
  752. package/node_modules/openai/resources/fine-tuning/jobs/jobs.js +3 -3
  753. package/node_modules/openai/resources/fine-tuning/jobs/jobs.mjs +3 -3
  754. package/node_modules/openai/resources/fine-tuning/jobs.js +1 -1
  755. package/node_modules/openai/resources/fine-tuning/jobs.mjs +1 -1
  756. package/node_modules/openai/resources/fine-tuning/methods.js +1 -1
  757. package/node_modules/openai/resources/fine-tuning/methods.mjs +1 -1
  758. package/node_modules/openai/resources/fine-tuning.js +1 -1
  759. package/node_modules/openai/resources/fine-tuning.mjs +1 -1
  760. package/node_modules/openai/resources/graders/grader-models.js +1 -1
  761. package/node_modules/openai/resources/graders/grader-models.mjs +1 -1
  762. package/node_modules/openai/resources/graders/graders.js +1 -1
  763. package/node_modules/openai/resources/graders/graders.mjs +1 -1
  764. package/node_modules/openai/resources/graders/index.js +1 -1
  765. package/node_modules/openai/resources/graders/index.mjs +1 -1
  766. package/node_modules/openai/resources/graders.js +1 -1
  767. package/node_modules/openai/resources/graders.mjs +1 -1
  768. package/node_modules/openai/resources/images.js +8 -2
  769. package/node_modules/openai/resources/images.mjs +8 -2
  770. package/node_modules/openai/resources/index.js +9 -3
  771. package/node_modules/openai/resources/index.mjs +5 -2
  772. package/node_modules/openai/resources/live/forks/forks.js +9 -0
  773. package/node_modules/openai/resources/live/forks/forks.mjs +5 -0
  774. package/node_modules/openai/resources/live/forks/index.js +7 -0
  775. package/node_modules/openai/resources/live/forks/index.mjs +3 -0
  776. package/node_modules/openai/resources/live/forks/internal-base.js +65 -0
  777. package/node_modules/openai/resources/live/forks/internal-base.mjs +59 -0
  778. package/node_modules/openai/resources/live/forks/ws-base.js +547 -0
  779. package/node_modules/openai/resources/live/forks/ws-base.mjs +543 -0
  780. package/node_modules/openai/resources/live/forks/ws.js +32 -0
  781. package/node_modules/openai/resources/live/forks/ws.mjs +27 -0
  782. package/node_modules/openai/resources/live/forks.js +6 -0
  783. package/node_modules/openai/resources/live/forks.mjs +3 -0
  784. package/node_modules/openai/resources/live/index.js +13 -0
  785. package/node_modules/openai/resources/live/index.mjs +6 -0
  786. package/node_modules/openai/resources/live/internal-base.js +64 -0
  787. package/node_modules/openai/resources/live/internal-base.mjs +58 -0
  788. package/node_modules/openai/resources/live/live.js +40 -0
  789. package/node_modules/openai/resources/live/live.mjs +35 -0
  790. package/node_modules/openai/resources/live/sessions.js +124 -0
  791. package/node_modules/openai/resources/live/sessions.mjs +120 -0
  792. package/node_modules/openai/resources/live/sideband/index.js +7 -0
  793. package/node_modules/openai/resources/live/sideband/index.mjs +3 -0
  794. package/node_modules/openai/resources/live/sideband/internal-base.js +65 -0
  795. package/node_modules/openai/resources/live/sideband/internal-base.mjs +59 -0
  796. package/node_modules/openai/resources/live/sideband/sideband.js +9 -0
  797. package/node_modules/openai/resources/live/sideband/sideband.mjs +5 -0
  798. package/node_modules/openai/resources/live/sideband/ws-base.js +547 -0
  799. package/node_modules/openai/resources/live/sideband/ws-base.mjs +543 -0
  800. package/node_modules/openai/resources/live/sideband/ws.js +32 -0
  801. package/node_modules/openai/resources/live/sideband/ws.mjs +27 -0
  802. package/node_modules/openai/resources/live/sideband.js +6 -0
  803. package/node_modules/openai/resources/live/sideband.mjs +3 -0
  804. package/node_modules/openai/resources/live/ws-base.js +547 -0
  805. package/node_modules/openai/resources/live/ws-base.mjs +543 -0
  806. package/node_modules/openai/resources/live/ws.js +32 -0
  807. package/node_modules/openai/resources/live/ws.mjs +27 -0
  808. package/node_modules/openai/resources/live.js +6 -0
  809. package/node_modules/openai/resources/live.mjs +3 -0
  810. package/node_modules/openai/resources/models.js +1 -1
  811. package/node_modules/openai/resources/models.mjs +1 -1
  812. package/node_modules/openai/resources/moderations.js +3 -2
  813. package/node_modules/openai/resources/moderations.mjs +3 -2
  814. package/node_modules/openai/resources/realtime/calls.js +25 -1
  815. package/node_modules/openai/resources/realtime/calls.mjs +25 -1
  816. package/node_modules/openai/resources/realtime/client-secrets.js +2 -2
  817. package/node_modules/openai/resources/realtime/client-secrets.mjs +2 -2
  818. package/node_modules/openai/resources/realtime/index.js +1 -1
  819. package/node_modules/openai/resources/realtime/index.mjs +2 -2
  820. package/node_modules/openai/resources/realtime/realtime.js +1 -1
  821. package/node_modules/openai/resources/realtime/realtime.mjs +1 -1
  822. package/node_modules/openai/resources/realtime.js +1 -1
  823. package/node_modules/openai/resources/realtime.mjs +1 -1
  824. package/node_modules/openai/resources/responses/index.js +1 -1
  825. package/node_modules/openai/resources/responses/index.mjs +1 -1
  826. package/node_modules/openai/resources/responses/input-items.js +1 -1
  827. package/node_modules/openai/resources/responses/input-items.mjs +1 -1
  828. package/node_modules/openai/resources/responses/input-tokens.js +1 -1
  829. package/node_modules/openai/resources/responses/input-tokens.mjs +1 -1
  830. package/node_modules/openai/resources/responses/internal-base.js +24 -6
  831. package/node_modules/openai/resources/responses/internal-base.mjs +24 -6
  832. package/node_modules/openai/resources/responses/responses.js +5 -5
  833. package/node_modules/openai/resources/responses/responses.mjs +5 -5
  834. package/node_modules/openai/resources/responses/ws-base.js +115 -23
  835. package/node_modules/openai/resources/responses/ws-base.mjs +115 -25
  836. package/node_modules/openai/resources/responses/ws.js +23 -7
  837. package/node_modules/openai/resources/responses/ws.mjs +23 -7
  838. package/node_modules/openai/resources/responses.js +1 -1
  839. package/node_modules/openai/resources/responses.mjs +1 -1
  840. package/node_modules/openai/resources/safety/alerts.js +16 -0
  841. package/node_modules/openai/resources/safety/alerts.mjs +12 -0
  842. package/node_modules/openai/resources/safety/index.js +9 -0
  843. package/node_modules/openai/resources/safety/index.mjs +4 -0
  844. package/node_modules/openai/resources/safety/safety.js +17 -0
  845. package/node_modules/openai/resources/safety/safety.mjs +12 -0
  846. package/node_modules/openai/resources/safety.js +6 -0
  847. package/node_modules/openai/resources/safety.mjs +3 -0
  848. package/node_modules/openai/resources/shared.js +1 -1
  849. package/node_modules/openai/resources/shared.mjs +1 -1
  850. package/node_modules/openai/resources/skills/content.js +1 -1
  851. package/node_modules/openai/resources/skills/content.mjs +1 -1
  852. package/node_modules/openai/resources/skills/index.js +1 -1
  853. package/node_modules/openai/resources/skills/index.mjs +1 -1
  854. package/node_modules/openai/resources/skills/skills.js +4 -2
  855. package/node_modules/openai/resources/skills/skills.mjs +4 -2
  856. package/node_modules/openai/resources/skills/versions/content.js +1 -1
  857. package/node_modules/openai/resources/skills/versions/content.mjs +1 -1
  858. package/node_modules/openai/resources/skills/versions/index.js +1 -1
  859. package/node_modules/openai/resources/skills/versions/index.mjs +1 -1
  860. package/node_modules/openai/resources/skills/versions/versions.js +4 -2
  861. package/node_modules/openai/resources/skills/versions/versions.mjs +4 -2
  862. package/node_modules/openai/resources/skills/versions.js +1 -1
  863. package/node_modules/openai/resources/skills/versions.mjs +1 -1
  864. package/node_modules/openai/resources/skills.js +1 -1
  865. package/node_modules/openai/resources/skills.mjs +1 -1
  866. package/node_modules/openai/resources/uploads/index.js +1 -1
  867. package/node_modules/openai/resources/uploads/index.mjs +1 -1
  868. package/node_modules/openai/resources/uploads/parts.js +6 -5
  869. package/node_modules/openai/resources/uploads/parts.mjs +6 -5
  870. package/node_modules/openai/resources/uploads/uploads.js +10 -10
  871. package/node_modules/openai/resources/uploads/uploads.mjs +10 -10
  872. package/node_modules/openai/resources/uploads.js +1 -1
  873. package/node_modules/openai/resources/uploads.mjs +1 -1
  874. package/node_modules/openai/resources/vector-stores/file-batches.js +6 -63
  875. package/node_modules/openai/resources/vector-stores/file-batches.mjs +6 -63
  876. package/node_modules/openai/resources/vector-stores/files.js +6 -39
  877. package/node_modules/openai/resources/vector-stores/files.mjs +6 -39
  878. package/node_modules/openai/resources/vector-stores/index.js +1 -1
  879. package/node_modules/openai/resources/vector-stores/index.mjs +1 -1
  880. package/node_modules/openai/resources/vector-stores/vector-stores.js +1 -1
  881. package/node_modules/openai/resources/vector-stores/vector-stores.mjs +1 -1
  882. package/node_modules/openai/resources/vector-stores.js +1 -1
  883. package/node_modules/openai/resources/vector-stores.mjs +1 -1
  884. package/node_modules/openai/resources/videos.js +24 -1
  885. package/node_modules/openai/resources/videos.mjs +24 -1
  886. package/node_modules/openai/resources/webhooks/event-types.js +21 -0
  887. package/node_modules/openai/resources/webhooks/event-types.mjs +17 -0
  888. package/node_modules/openai/resources/webhooks/index.js +4 -1
  889. package/node_modules/openai/resources/webhooks/index.mjs +2 -1
  890. package/node_modules/openai/resources/webhooks/webhooks.js +127 -43
  891. package/node_modules/openai/resources/webhooks/webhooks.mjs +127 -43
  892. package/node_modules/openai/resources/webhooks.js +1 -1
  893. package/node_modules/openai/resources/webhooks.mjs +1 -1
  894. package/node_modules/openai/src/_vendor/partial-json-parser/LICENSE +21 -0
  895. package/node_modules/openai/src/_vendor/partial-json-parser/README.md +11 -1
  896. package/node_modules/openai/src/_vendor/partial-json-parser/parser.ts +66 -35
  897. package/node_modules/openai/src/_vendor/zod-to-json-schema/Options.ts +32 -18
  898. package/node_modules/openai/src/_vendor/zod-to-json-schema/Refs.ts +7 -6
  899. package/node_modules/openai/src/_vendor/zod-to-json-schema/errorMessages.ts +5 -3
  900. package/node_modules/openai/src/_vendor/zod-to-json-schema/index.ts +3 -1
  901. package/node_modules/openai/src/_vendor/zod-to-json-schema/parseDef.ts +194 -79
  902. package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/array.ts +8 -5
  903. package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/bigint.ts +20 -12
  904. package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/branded.ts +4 -4
  905. package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/catch.ts +4 -5
  906. package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/date.ts +16 -10
  907. package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/default.ts +10 -5
  908. package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/effects.ts +4 -3
  909. package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/enum.ts +1 -1
  910. package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/intersection.ts +12 -9
  911. package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/literal.ts +12 -2
  912. package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/map.ts +6 -4
  913. package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/nativeEnum.ts +10 -11
  914. package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/null.ts +4 -3
  915. package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/nullable.ts +25 -10
  916. package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/number.ts +17 -8
  917. package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/object.ts +57 -54
  918. package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/optional.ts +25 -17
  919. package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/pipeline.ts +8 -6
  920. package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/promise.ts +10 -5
  921. package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/readonly.ts +4 -5
  922. package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/record.ts +22 -19
  923. package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/set.ts +6 -4
  924. package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/string.ts +62 -37
  925. package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/tuple.ts +32 -25
  926. package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/union.ts +51 -33
  927. package/node_modules/openai/src/_vendor/zod-to-json-schema/util.ts +11 -6
  928. package/node_modules/openai/src/_vendor/zod-to-json-schema/zodToJsonSchema.ts +133 -52
  929. package/node_modules/openai/src/auth/index.ts +7 -1
  930. package/node_modules/openai/src/auth/subject-token-providers.ts +281 -16
  931. package/node_modules/openai/src/auth/types.ts +48 -5
  932. package/node_modules/openai/src/auth/workload-identity-auth.ts +227 -26
  933. package/node_modules/openai/src/auth/x509-transport.ts +369 -0
  934. package/node_modules/openai/src/azure.ts +127 -28
  935. package/node_modules/openai/src/bedrock.ts +294 -0
  936. package/node_modules/openai/src/beta/realtime/internal-base.ts +136 -16
  937. package/node_modules/openai/src/beta/realtime/websocket.ts +264 -48
  938. package/node_modules/openai/src/beta/realtime/ws.ts +138 -25
  939. package/node_modules/openai/src/client.ts +975 -124
  940. package/node_modules/openai/src/core/EventEmitter.ts +162 -26
  941. package/node_modules/openai/src/core/api-promise.ts +0 -2
  942. package/node_modules/openai/src/core/error.ts +6 -8
  943. package/node_modules/openai/src/core/pagination.ts +67 -7
  944. package/node_modules/openai/src/core/resource.ts +0 -2
  945. package/node_modules/openai/src/core/streaming.ts +490 -100
  946. package/node_modules/openai/src/core/uploads.ts +6 -1
  947. package/node_modules/openai/src/helpers/audio.ts +215 -32
  948. package/node_modules/openai/src/helpers/live.ts +8 -0
  949. package/node_modules/openai/src/helpers/standard-schema.ts +819 -0
  950. package/node_modules/openai/src/helpers/zod-v3-strict-schema.ts +520 -0
  951. package/node_modules/openai/src/helpers/zod.ts +418 -56
  952. package/node_modules/openai/src/index.ts +4 -5
  953. package/node_modules/openai/src/internal/assistant-stream-delta.ts +440 -0
  954. package/node_modules/openai/src/internal/auth/x509-api-origin.ts +27 -0
  955. package/node_modules/openai/src/internal/auth/x509-credential-options.ts +149 -0
  956. package/node_modules/openai/src/internal/auth/x509-token-exchange.ts +319 -0
  957. package/node_modules/openai/src/internal/auth/x509-transport-capability.ts +227 -0
  958. package/node_modules/openai/src/internal/auth/x509-transport-registry.ts +127 -0
  959. package/node_modules/openai/src/internal/auth/x509-transport-state-browser.ts +43 -0
  960. package/node_modules/openai/src/internal/auth/x509-transport-state.cts +43 -0
  961. package/node_modules/openai/src/internal/auth/x509-workload-identity-auth.ts +972 -0
  962. package/node_modules/openai/src/internal/bedrock.ts +586 -0
  963. package/node_modules/openai/src/internal/builtin-types.ts +0 -2
  964. package/node_modules/openai/src/internal/data-residency.ts +44 -0
  965. package/node_modules/openai/src/internal/decoders/line.ts +145 -61
  966. package/node_modules/openai/src/internal/detect-platform.ts +3 -5
  967. package/node_modules/openai/src/internal/errors.ts +3 -4
  968. package/node_modules/openai/src/internal/headers.ts +14 -10
  969. package/node_modules/openai/src/internal/multipart-encoding.ts +53 -0
  970. package/node_modules/openai/src/internal/parse.ts +47 -19
  971. package/node_modules/openai/src/internal/provider.ts +92 -0
  972. package/node_modules/openai/src/internal/qs/formats.ts +1 -1
  973. package/node_modules/openai/src/internal/qs/stringify.ts +57 -53
  974. package/node_modules/openai/src/internal/qs/types.ts +1 -1
  975. package/node_modules/openai/src/internal/qs/utils.ts +443 -54
  976. package/node_modules/openai/src/internal/realtime-credentials.ts +27 -0
  977. package/node_modules/openai/src/internal/request-options.ts +52 -3
  978. package/node_modules/openai/src/internal/responses/canonical-output-text.ts +160 -0
  979. package/node_modules/openai/src/internal/responses/output-text-index.ts +84 -0
  980. package/node_modules/openai/src/internal/responses/response-accumulator.ts +1263 -0
  981. package/node_modules/openai/src/internal/shim-types.ts +3 -4
  982. package/node_modules/openai/src/internal/shims.ts +0 -2
  983. package/node_modules/openai/src/internal/stream-utils.ts +37 -5
  984. package/node_modules/openai/src/internal/to-file.ts +90 -35
  985. package/node_modules/openai/src/internal/types.ts +21 -29
  986. package/node_modules/openai/src/internal/uploads.ts +533 -59
  987. package/node_modules/openai/src/internal/utils/abort.ts +116 -0
  988. package/node_modules/openai/src/internal/utils/base64.ts +3 -2
  989. package/node_modules/openai/src/internal/utils/bytes.ts +7 -0
  990. package/node_modules/openai/src/internal/utils/env.ts +9 -7
  991. package/node_modules/openai/src/internal/utils/log.ts +77 -14
  992. package/node_modules/openai/src/internal/utils/path.ts +53 -32
  993. package/node_modules/openai/src/internal/utils/query.ts +0 -2
  994. package/node_modules/openai/src/internal/utils/sleep.ts +51 -2
  995. package/node_modules/openai/src/internal/utils/uuid.ts +0 -2
  996. package/node_modules/openai/src/internal/utils/values.ts +0 -2
  997. package/node_modules/openai/src/internal/utils.ts +0 -2
  998. package/node_modules/openai/src/internal/ws-adapter-browser.ts +83 -24
  999. package/node_modules/openai/src/internal/ws-adapter-node.ts +105 -26
  1000. package/node_modules/openai/src/internal/ws-adapter.ts +23 -0
  1001. package/node_modules/openai/src/internal/ws.ts +250 -51
  1002. package/node_modules/openai/src/lib/.keep +2 -2
  1003. package/node_modules/openai/src/lib/AbstractChatCompletionRunner.ts +349 -102
  1004. package/node_modules/openai/src/lib/AssistantStream.ts +537 -268
  1005. package/node_modules/openai/src/lib/ChatCompletionRunner.ts +75 -22
  1006. package/node_modules/openai/src/lib/ChatCompletionStream.ts +2016 -268
  1007. package/node_modules/openai/src/lib/ChatCompletionStreamingRunner.ts +115 -17
  1008. package/node_modules/openai/src/lib/EventEmitter.ts +171 -26
  1009. package/node_modules/openai/src/lib/EventStream.ts +1979 -64
  1010. package/node_modules/openai/src/lib/ResponsesParser.ts +153 -56
  1011. package/node_modules/openai/src/lib/RunnableFunction.ts +99 -37
  1012. package/node_modules/openai/src/lib/Util.ts +7 -5
  1013. package/node_modules/openai/src/lib/agents/agent-session-stream.ts +328 -0
  1014. package/node_modules/openai/src/lib/agents/output-text.ts +6 -0
  1015. package/node_modules/openai/src/lib/agents/turn-state.ts +61 -0
  1016. package/node_modules/openai/src/lib/assistant-run-polling.ts +27 -0
  1017. package/node_modules/openai/src/lib/chatCompletionUtils.ts +9 -10
  1018. package/node_modules/openai/src/lib/embeddings.ts +73 -0
  1019. package/node_modules/openai/src/lib/file-processing.ts +37 -0
  1020. package/node_modules/openai/src/lib/jsonschema.ts +77 -34
  1021. package/node_modules/openai/src/lib/live/transcript-grouper.ts +307 -0
  1022. package/node_modules/openai/src/lib/live/transcript-grouping.ts +394 -0
  1023. package/node_modules/openai/src/lib/live/webrtc.ts +23 -0
  1024. package/node_modules/openai/src/lib/parser.ts +247 -69
  1025. package/node_modules/openai/src/lib/polling.ts +145 -0
  1026. package/node_modules/openai/src/lib/realtime/webrtc.ts +20 -0
  1027. package/node_modules/openai/src/lib/responses/EventTypes.ts +9 -60
  1028. package/node_modules/openai/src/lib/responses/ResponseAccumulator.ts +27 -0
  1029. package/node_modules/openai/src/lib/responses/ResponseInputItems.ts +167 -0
  1030. package/node_modules/openai/src/lib/responses/ResponseStream.ts +135 -179
  1031. package/node_modules/openai/src/lib/responses/responses-websocket-lane.ts +388 -0
  1032. package/node_modules/openai/src/lib/responses/responses-websocket-session.ts +317 -0
  1033. package/node_modules/openai/src/lib/transform.ts +2015 -100
  1034. package/node_modules/openai/src/lib/vector-store-polling.ts +46 -0
  1035. package/node_modules/openai/src/lib/vector-store-upload.ts +57 -0
  1036. package/node_modules/openai/src/lib/webhook-signature.ts +164 -0
  1037. package/node_modules/openai/src/lib/webrtc/connection.ts +313 -0
  1038. package/node_modules/openai/src/lib/webrtc/data-channel.ts +151 -0
  1039. package/node_modules/openai/src/lib/webrtc/errors.ts +38 -0
  1040. package/node_modules/openai/src/lib/webrtc/subscriptions.ts +65 -0
  1041. package/node_modules/openai/src/lib/webrtc/types.ts +110 -0
  1042. package/node_modules/openai/src/live/webrtc.ts +10 -0
  1043. package/node_modules/openai/src/providers/bedrock/aws.ts +331 -0
  1044. package/node_modules/openai/src/providers/bedrock.ts +51 -0
  1045. package/node_modules/openai/src/realtime/internal-base.ts +265 -17
  1046. package/node_modules/openai/src/realtime/webrtc.ts +10 -0
  1047. package/node_modules/openai/src/realtime/websocket.ts +259 -54
  1048. package/node_modules/openai/src/realtime/ws.ts +135 -29
  1049. package/node_modules/openai/src/resources/admin/admin.ts +1 -1
  1050. package/node_modules/openai/src/resources/admin/index.ts +1 -1
  1051. package/node_modules/openai/src/resources/admin/organization/admin-api-keys.ts +18 -2
  1052. package/node_modules/openai/src/resources/admin/organization/audit-logs.ts +327 -4
  1053. package/node_modules/openai/src/resources/admin/organization/certificates.ts +1 -1
  1054. package/node_modules/openai/src/resources/admin/organization/data-retention.ts +1 -1
  1055. package/node_modules/openai/src/resources/admin/organization/groups/groups.ts +1 -1
  1056. package/node_modules/openai/src/resources/admin/organization/groups/index.ts +1 -1
  1057. package/node_modules/openai/src/resources/admin/organization/groups/roles.ts +1 -1
  1058. package/node_modules/openai/src/resources/admin/organization/groups/users.ts +1 -1
  1059. package/node_modules/openai/src/resources/admin/organization/groups.ts +1 -1
  1060. package/node_modules/openai/src/resources/admin/organization/index.ts +9 -1
  1061. package/node_modules/openai/src/resources/admin/organization/invites.ts +1 -1
  1062. package/node_modules/openai/src/resources/admin/organization/organization.ts +21 -1
  1063. package/node_modules/openai/src/resources/admin/organization/projects/api-keys.ts +22 -2
  1064. package/node_modules/openai/src/resources/admin/organization/projects/certificates.ts +1 -1
  1065. package/node_modules/openai/src/resources/admin/organization/projects/data-retention.ts +1 -1
  1066. package/node_modules/openai/src/resources/admin/organization/projects/groups/groups.ts +1 -1
  1067. package/node_modules/openai/src/resources/admin/organization/projects/groups/index.ts +1 -1
  1068. package/node_modules/openai/src/resources/admin/organization/projects/groups/roles.ts +1 -1
  1069. package/node_modules/openai/src/resources/admin/organization/projects/groups.ts +1 -1
  1070. package/node_modules/openai/src/resources/admin/organization/projects/hosted-tool-permissions.ts +1 -1
  1071. package/node_modules/openai/src/resources/admin/organization/projects/index.ts +10 -2
  1072. package/node_modules/openai/src/resources/admin/organization/projects/model-permissions.ts +1 -1
  1073. package/node_modules/openai/src/resources/admin/organization/projects/projects.ts +70 -19
  1074. package/node_modules/openai/src/resources/admin/organization/projects/rate-limits.ts +1 -1
  1075. package/node_modules/openai/src/resources/admin/organization/projects/roles.ts +1 -1
  1076. package/node_modules/openai/src/resources/admin/organization/projects/service-accounts/api-keys.ts +91 -0
  1077. package/node_modules/openai/src/resources/admin/organization/projects/service-accounts/index.ts +15 -0
  1078. package/node_modules/openai/src/resources/admin/organization/projects/service-accounts/service-accounts.ts +299 -0
  1079. package/node_modules/openai/src/resources/admin/organization/projects/service-accounts.ts +2 -265
  1080. package/node_modules/openai/src/resources/admin/organization/projects/spend-alerts.ts +33 -1
  1081. package/node_modules/openai/src/resources/admin/organization/projects/spend-limit.ts +156 -0
  1082. package/node_modules/openai/src/resources/admin/organization/projects/users/index.ts +1 -1
  1083. package/node_modules/openai/src/resources/admin/organization/projects/users/roles.ts +1 -1
  1084. package/node_modules/openai/src/resources/admin/organization/projects/users/users.ts +1 -1
  1085. package/node_modules/openai/src/resources/admin/organization/projects/users.ts +1 -1
  1086. package/node_modules/openai/src/resources/admin/organization/projects.ts +1 -1
  1087. package/node_modules/openai/src/resources/admin/organization/roles.ts +1 -1
  1088. package/node_modules/openai/src/resources/admin/organization/spend-alerts.ts +19 -1
  1089. package/node_modules/openai/src/resources/admin/organization/spend-limit.ts +144 -0
  1090. package/node_modules/openai/src/resources/admin/organization/usage.ts +706 -89
  1091. package/node_modules/openai/src/resources/admin/organization/users/index.ts +1 -1
  1092. package/node_modules/openai/src/resources/admin/organization/users/roles.ts +1 -1
  1093. package/node_modules/openai/src/resources/admin/organization/users/users.ts +1 -1
  1094. package/node_modules/openai/src/resources/admin/organization/users.ts +1 -1
  1095. package/node_modules/openai/src/resources/admin/organization.ts +1 -1
  1096. package/node_modules/openai/src/resources/admin.ts +1 -1
  1097. package/node_modules/openai/src/resources/audio/audio.ts +4 -1
  1098. package/node_modules/openai/src/resources/audio/index.ts +2 -1
  1099. package/node_modules/openai/src/resources/audio/speech.ts +4 -3
  1100. package/node_modules/openai/src/resources/audio/transcriptions.ts +51 -13
  1101. package/node_modules/openai/src/resources/audio/translations.ts +5 -3
  1102. package/node_modules/openai/src/resources/audio.ts +1 -1
  1103. package/node_modules/openai/src/resources/batches.ts +10 -9
  1104. package/node_modules/openai/src/resources/beta/agents/agents.ts +4627 -0
  1105. package/node_modules/openai/src/resources/beta/agents/environments/environments.ts +111 -0
  1106. package/node_modules/openai/src/resources/beta/agents/environments/files.ts +169 -0
  1107. package/node_modules/openai/src/resources/beta/agents/environments/index.ts +19 -0
  1108. package/node_modules/openai/src/resources/beta/agents/environments/templates.ts +535 -0
  1109. package/node_modules/openai/src/resources/beta/agents/environments.ts +3 -0
  1110. package/node_modules/openai/src/resources/beta/agents/index.ts +127 -0
  1111. package/node_modules/openai/src/resources/beta/agents/sessions/artifacts.ts +249 -0
  1112. package/node_modules/openai/src/resources/beta/agents/sessions/events.ts +94 -0
  1113. package/node_modules/openai/src/resources/beta/agents/sessions/index.ts +24 -0
  1114. package/node_modules/openai/src/resources/beta/agents/sessions/items.ts +59 -0
  1115. package/node_modules/openai/src/resources/beta/agents/sessions/sessions.ts +403 -0
  1116. package/node_modules/openai/src/resources/beta/agents/sessions/subagents/index.ts +5 -0
  1117. package/node_modules/openai/src/resources/beta/agents/sessions/subagents/items.ts +65 -0
  1118. package/node_modules/openai/src/resources/beta/agents/sessions/subagents/subagents.ts +113 -0
  1119. package/node_modules/openai/src/resources/beta/agents/sessions/subagents/turns/index.ts +4 -0
  1120. package/node_modules/openai/src/resources/beta/agents/sessions/subagents/turns/items.ts +70 -0
  1121. package/node_modules/openai/src/resources/beta/agents/sessions/subagents/turns/turns.ts +111 -0
  1122. package/node_modules/openai/src/resources/beta/agents/sessions/subagents/turns.ts +3 -0
  1123. package/node_modules/openai/src/resources/beta/agents/sessions/subagents.ts +3 -0
  1124. package/node_modules/openai/src/resources/beta/agents/sessions/turns.ts +159 -0
  1125. package/node_modules/openai/src/resources/beta/agents/sessions.ts +3 -0
  1126. package/node_modules/openai/src/resources/beta/agents/vaults/credentials.ts +693 -0
  1127. package/node_modules/openai/src/resources/beta/agents/vaults/index.ts +29 -0
  1128. package/node_modules/openai/src/resources/beta/agents/vaults/vaults.ts +243 -0
  1129. package/node_modules/openai/src/resources/beta/agents/vaults.ts +3 -0
  1130. package/node_modules/openai/src/resources/beta/agents.ts +3 -0
  1131. package/node_modules/openai/src/resources/beta/assistants.ts +154 -172
  1132. package/node_modules/openai/src/resources/beta/beta.ts +578 -3
  1133. package/node_modules/openai/src/resources/beta/chatkit/chatkit.ts +1 -1
  1134. package/node_modules/openai/src/resources/beta/chatkit/index.ts +1 -1
  1135. package/node_modules/openai/src/resources/beta/chatkit/sessions.ts +1 -1
  1136. package/node_modules/openai/src/resources/beta/chatkit/threads.ts +1 -1
  1137. package/node_modules/openai/src/resources/beta/chatkit.ts +1 -1
  1138. package/node_modules/openai/src/resources/beta/index.ts +290 -1
  1139. package/node_modules/openai/src/resources/beta/realtime/index.ts +0 -2
  1140. package/node_modules/openai/src/resources/beta/realtime/realtime.ts +0 -2
  1141. package/node_modules/openai/src/resources/beta/realtime/sessions.ts +0 -2
  1142. package/node_modules/openai/src/resources/beta/realtime/transcription-sessions.ts +0 -2
  1143. package/node_modules/openai/src/resources/beta/realtime.ts +0 -2
  1144. package/node_modules/openai/src/resources/beta/responses/index.ts +189 -0
  1145. package/node_modules/openai/src/resources/beta/responses/input-items.ts +105 -0
  1146. package/node_modules/openai/src/resources/beta/responses/input-tokens.ts +249 -0
  1147. package/node_modules/openai/src/resources/beta/responses/internal-base.ts +136 -0
  1148. package/node_modules/openai/src/resources/beta/responses/responses.ts +15060 -0
  1149. package/node_modules/openai/src/resources/beta/responses/ws-base.ts +729 -0
  1150. package/node_modules/openai/src/resources/beta/responses/ws.ts +62 -0
  1151. package/node_modules/openai/src/resources/beta/responses.ts +3 -0
  1152. package/node_modules/openai/src/resources/beta/threads/index.ts +1 -1
  1153. package/node_modules/openai/src/resources/beta/threads/messages.ts +30 -24
  1154. package/node_modules/openai/src/resources/beta/threads/runs/index.ts +2 -2
  1155. package/node_modules/openai/src/resources/beta/threads/runs/runs.ts +47 -93
  1156. package/node_modules/openai/src/resources/beta/threads/runs/steps.ts +15 -16
  1157. package/node_modules/openai/src/resources/beta/threads/runs.ts +1 -1
  1158. package/node_modules/openai/src/resources/beta/threads/threads.ts +54 -51
  1159. package/node_modules/openai/src/resources/beta/threads.ts +1 -1
  1160. package/node_modules/openai/src/resources/beta.ts +1 -1
  1161. package/node_modules/openai/src/resources/chat/chat.ts +1 -1
  1162. package/node_modules/openai/src/resources/chat/completions/completions.ts +762 -108
  1163. package/node_modules/openai/src/resources/chat/completions/index.ts +1 -1
  1164. package/node_modules/openai/src/resources/chat/completions/messages.ts +1 -1
  1165. package/node_modules/openai/src/resources/chat/completions.ts +1 -1
  1166. package/node_modules/openai/src/resources/chat/index.ts +1 -1
  1167. package/node_modules/openai/src/resources/chat.ts +1 -1
  1168. package/node_modules/openai/src/resources/completions.ts +36 -15
  1169. package/node_modules/openai/src/resources/containers/containers.ts +1 -1
  1170. package/node_modules/openai/src/resources/containers/files/content.ts +1 -1
  1171. package/node_modules/openai/src/resources/containers/files/files.ts +1 -1
  1172. package/node_modules/openai/src/resources/containers/files/index.ts +1 -1
  1173. package/node_modules/openai/src/resources/containers/files.ts +1 -1
  1174. package/node_modules/openai/src/resources/containers/index.ts +1 -1
  1175. package/node_modules/openai/src/resources/containers.ts +1 -1
  1176. package/node_modules/openai/src/resources/content-provenance-checks.ts +132 -0
  1177. package/node_modules/openai/src/resources/conversations/conversations.ts +23 -2
  1178. package/node_modules/openai/src/resources/conversations/index.ts +1 -1
  1179. package/node_modules/openai/src/resources/conversations/items.ts +93 -5
  1180. package/node_modules/openai/src/resources/conversations.ts +1 -1
  1181. package/node_modules/openai/src/resources/embeddings.ts +22 -49
  1182. package/node_modules/openai/src/resources/evals/evals.ts +6 -6
  1183. package/node_modules/openai/src/resources/evals/index.ts +1 -1
  1184. package/node_modules/openai/src/resources/evals/runs/index.ts +1 -1
  1185. package/node_modules/openai/src/resources/evals/runs/output-items.ts +1 -1
  1186. package/node_modules/openai/src/resources/evals/runs/runs.ts +119 -191
  1187. package/node_modules/openai/src/resources/evals/runs.ts +1 -1
  1188. package/node_modules/openai/src/resources/evals.ts +1 -1
  1189. package/node_modules/openai/src/resources/files.ts +9 -26
  1190. package/node_modules/openai/src/resources/fine-tuning/alpha/alpha.ts +1 -1
  1191. package/node_modules/openai/src/resources/fine-tuning/alpha/graders.ts +6 -5
  1192. package/node_modules/openai/src/resources/fine-tuning/alpha/index.ts +1 -1
  1193. package/node_modules/openai/src/resources/fine-tuning/alpha.ts +1 -1
  1194. package/node_modules/openai/src/resources/fine-tuning/checkpoints/checkpoints.ts +1 -1
  1195. package/node_modules/openai/src/resources/fine-tuning/checkpoints/index.ts +1 -1
  1196. package/node_modules/openai/src/resources/fine-tuning/checkpoints/permissions.ts +9 -5
  1197. package/node_modules/openai/src/resources/fine-tuning/checkpoints.ts +1 -1
  1198. package/node_modules/openai/src/resources/fine-tuning/fine-tuning.ts +1 -1
  1199. package/node_modules/openai/src/resources/fine-tuning/index.ts +1 -1
  1200. package/node_modules/openai/src/resources/fine-tuning/jobs/checkpoints.ts +1 -1
  1201. package/node_modules/openai/src/resources/fine-tuning/jobs/index.ts +1 -1
  1202. package/node_modules/openai/src/resources/fine-tuning/jobs/jobs.ts +14 -13
  1203. package/node_modules/openai/src/resources/fine-tuning/jobs.ts +1 -1
  1204. package/node_modules/openai/src/resources/fine-tuning/methods.ts +1 -1
  1205. package/node_modules/openai/src/resources/fine-tuning.ts +1 -1
  1206. package/node_modules/openai/src/resources/graders/grader-models.ts +7 -14
  1207. package/node_modules/openai/src/resources/graders/graders.ts +1 -1
  1208. package/node_modules/openai/src/resources/graders/index.ts +1 -1
  1209. package/node_modules/openai/src/resources/graders.ts +1 -1
  1210. package/node_modules/openai/src/resources/images.ts +100 -85
  1211. package/node_modules/openai/src/resources/index.ts +9 -2
  1212. package/node_modules/openai/src/resources/live/api.md +87 -0
  1213. package/node_modules/openai/src/resources/live/forks/forks.ts +169 -0
  1214. package/node_modules/openai/src/resources/live/forks/index.ts +5 -0
  1215. package/node_modules/openai/src/resources/live/forks/internal-base.ts +126 -0
  1216. package/node_modules/openai/src/resources/live/forks/ws-base.ts +700 -0
  1217. package/node_modules/openai/src/resources/live/forks/ws.ts +47 -0
  1218. package/node_modules/openai/src/resources/live/forks.ts +3 -0
  1219. package/node_modules/openai/src/resources/live/index.ts +20 -0
  1220. package/node_modules/openai/src/resources/live/internal-base.ts +123 -0
  1221. package/node_modules/openai/src/resources/live/live.ts +2296 -0
  1222. package/node_modules/openai/src/resources/live/sessions.ts +343 -0
  1223. package/node_modules/openai/src/resources/live/sideband/index.ts +10 -0
  1224. package/node_modules/openai/src/resources/live/sideband/internal-base.ts +126 -0
  1225. package/node_modules/openai/src/resources/live/sideband/sideband.ts +58 -0
  1226. package/node_modules/openai/src/resources/live/sideband/ws-base.ts +710 -0
  1227. package/node_modules/openai/src/resources/live/sideband/ws.ts +47 -0
  1228. package/node_modules/openai/src/resources/live/sideband.ts +3 -0
  1229. package/node_modules/openai/src/resources/live/ws-base.ts +696 -0
  1230. package/node_modules/openai/src/resources/live/ws.ts +43 -0
  1231. package/node_modules/openai/src/resources/live.ts +3 -0
  1232. package/node_modules/openai/src/resources/models.ts +6 -1
  1233. package/node_modules/openai/src/resources/moderations.ts +6 -5
  1234. package/node_modules/openai/src/resources/realtime/api.md +1 -0
  1235. package/node_modules/openai/src/resources/realtime/calls.ts +50 -2
  1236. package/node_modules/openai/src/resources/realtime/client-secrets.ts +27 -10
  1237. package/node_modules/openai/src/resources/realtime/index.ts +8 -2
  1238. package/node_modules/openai/src/resources/realtime/realtime.ts +93 -35
  1239. package/node_modules/openai/src/resources/realtime.ts +1 -1
  1240. package/node_modules/openai/src/resources/responses/api.md +20 -0
  1241. package/node_modules/openai/src/resources/responses/index.ts +1 -1
  1242. package/node_modules/openai/src/resources/responses/input-items.ts +1 -1
  1243. package/node_modules/openai/src/resources/responses/input-tokens.ts +26 -16
  1244. package/node_modules/openai/src/resources/responses/internal-base.ts +33 -14
  1245. package/node_modules/openai/src/resources/responses/responses.ts +4150 -792
  1246. package/node_modules/openai/src/resources/responses/ws-base.ts +147 -31
  1247. package/node_modules/openai/src/resources/responses/ws.ts +33 -9
  1248. package/node_modules/openai/src/resources/responses.ts +1 -1
  1249. package/node_modules/openai/src/resources/safety/alerts.ts +51 -0
  1250. package/node_modules/openai/src/resources/safety/index.ts +4 -0
  1251. package/node_modules/openai/src/resources/safety/safety.ts +15 -0
  1252. package/node_modules/openai/src/resources/safety.ts +3 -0
  1253. package/node_modules/openai/src/resources/shared.ts +98 -41
  1254. package/node_modules/openai/src/resources/skills/content.ts +1 -1
  1255. package/node_modules/openai/src/resources/skills/index.ts +1 -1
  1256. package/node_modules/openai/src/resources/skills/skills.ts +4 -2
  1257. package/node_modules/openai/src/resources/skills/versions/content.ts +1 -1
  1258. package/node_modules/openai/src/resources/skills/versions/index.ts +1 -1
  1259. package/node_modules/openai/src/resources/skills/versions/versions.ts +4 -2
  1260. package/node_modules/openai/src/resources/skills/versions.ts +1 -1
  1261. package/node_modules/openai/src/resources/skills.ts +1 -1
  1262. package/node_modules/openai/src/resources/uploads/index.ts +1 -1
  1263. package/node_modules/openai/src/resources/uploads/parts.ts +6 -5
  1264. package/node_modules/openai/src/resources/uploads/uploads.ts +12 -12
  1265. package/node_modules/openai/src/resources/uploads.ts +1 -1
  1266. package/node_modules/openai/src/resources/vector-stores/file-batches.ts +24 -89
  1267. package/node_modules/openai/src/resources/vector-stores/files.ts +12 -52
  1268. package/node_modules/openai/src/resources/vector-stores/index.ts +1 -1
  1269. package/node_modules/openai/src/resources/vector-stores/vector-stores.ts +4 -4
  1270. package/node_modules/openai/src/resources/vector-stores.ts +1 -1
  1271. package/node_modules/openai/src/resources/videos.ts +63 -2
  1272. package/node_modules/openai/src/resources/webhooks/api.md +40 -17
  1273. package/node_modules/openai/src/resources/webhooks/event-types.ts +21 -0
  1274. package/node_modules/openai/src/resources/webhooks/index.ts +2 -1
  1275. package/node_modules/openai/src/resources/webhooks/webhooks.ts +694 -69
  1276. package/node_modules/openai/src/resources/webhooks.ts +1 -1
  1277. package/node_modules/openai/src/tsconfig.json +6 -3
  1278. package/node_modules/openai/src/version.ts +2 -1
  1279. package/node_modules/openai/version.js +2 -1
  1280. package/node_modules/openai/version.mjs +2 -1
  1281. package/package.json +5 -5
  1282. package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.js +0 -832
  1283. package/node_modules/@earendil-works/pi-ai/dist/images-models.js +0 -143
  1284. package/node_modules/@earendil-works/pi-ai/dist/providers/openrouter-images.js +0 -22
  1285. /package/node_modules/@aws-sdk/{credential-provider-sso → client-bedrock-runtime}/node_modules/@aws-sdk/token-providers/LICENSE +0 -0
  1286. /package/node_modules/@aws-sdk/{credential-provider-sso → client-bedrock-runtime}/node_modules/@aws-sdk/token-providers/README.md +0 -0
  1287. /package/node_modules/@aws-sdk/{credential-provider-sso → client-bedrock-runtime}/node_modules/@aws-sdk/token-providers/dist-cjs/index.js +0 -0
  1288. /package/node_modules/@aws-sdk/{credential-provider-sso → client-bedrock-runtime}/node_modules/@aws-sdk/token-providers/dist-es/constants.js +0 -0
  1289. /package/node_modules/@aws-sdk/{credential-provider-sso → client-bedrock-runtime}/node_modules/@aws-sdk/token-providers/dist-es/fromEnvSigningName.js +0 -0
  1290. /package/node_modules/@aws-sdk/{credential-provider-sso → client-bedrock-runtime}/node_modules/@aws-sdk/token-providers/dist-es/fromSso.js +0 -0
  1291. /package/node_modules/@aws-sdk/{credential-provider-sso → client-bedrock-runtime}/node_modules/@aws-sdk/token-providers/dist-es/fromStatic.js +0 -0
  1292. /package/node_modules/@aws-sdk/{credential-provider-sso → client-bedrock-runtime}/node_modules/@aws-sdk/token-providers/dist-es/getNewSsoOidcToken.js +0 -0
  1293. /package/node_modules/@aws-sdk/{credential-provider-sso → client-bedrock-runtime}/node_modules/@aws-sdk/token-providers/dist-es/getSsoOidcClient.js +0 -0
  1294. /package/node_modules/@aws-sdk/{credential-provider-sso → client-bedrock-runtime}/node_modules/@aws-sdk/token-providers/dist-es/index.js +0 -0
  1295. /package/node_modules/@aws-sdk/{credential-provider-sso → client-bedrock-runtime}/node_modules/@aws-sdk/token-providers/dist-es/nodeProvider.js +0 -0
  1296. /package/node_modules/@aws-sdk/{credential-provider-sso → client-bedrock-runtime}/node_modules/@aws-sdk/token-providers/dist-es/validateTokenExpiry.js +0 -0
  1297. /package/node_modules/@aws-sdk/{credential-provider-sso → client-bedrock-runtime}/node_modules/@aws-sdk/token-providers/dist-es/validateTokenKey.js +0 -0
  1298. /package/node_modules/@aws-sdk/{credential-provider-sso → client-bedrock-runtime}/node_modules/@aws-sdk/token-providers/dist-es/writeSSOTokenToFile.js +0 -0
  1299. /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
- if (schema.type !== 'object') {
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
- `Root schema must have type: 'object' but got type: ${schema.type ? `'${schema.type}'` : 'undefined'}`,
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
- const schemaCopy = structuredClone(schema);
11
- return ensureStrictJsonSchema(schemaCopy, [], schemaCopy);
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 isNullable(schema: JSONSchemaDefinition): boolean {
15
- if (typeof schema === 'boolean') {
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
- if (schema.type === 'null') {
19
- return true;
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
- for (const oneOfVariant of schema.oneOf ?? []) {
22
- if (isNullable(oneOfVariant)) {
23
- return true;
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
- for (const allOfVariant of schema.anyOf ?? []) {
27
- if (isNullable(allOfVariant)) {
28
- return true;
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
- return false;
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
- // Handle $defs (non-standard but sometimes used)
52
- const defs = (jsonSchema as any).$defs;
53
- if (isObject(defs)) {
54
- for (const [defName, defSchema] of Object.entries(defs)) {
55
- ensureStrictJsonSchema(defSchema as JSONSchema, [...path, '$defs', defName], root);
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
- // Handle definitions (draft-04 style, deprecated in draft-07 but still used)
60
- const definitions = (jsonSchema as any).definitions;
61
- if (isObject(definitions)) {
62
- for (const [definitionName, definitionSchema] of Object.entries(definitions)) {
63
- ensureStrictJsonSchema(definitionSchema as JSONSchema, [...path, 'definitions', definitionName], root);
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 types
68
- const typ = jsonSchema.type;
69
- if (typ === 'object' && !('additionalProperties' in jsonSchema)) {
70
- jsonSchema.additionalProperties = false;
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
- `Zod field at \`${[...path, 'properties', key].join(
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
- // Handle arrays
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
- if (isObject(items)) {
99
- jsonSchema.items = ensureStrictJsonSchema(items, [...path, 'items'], root);
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
- // Handle unions (anyOf)
103
- const anyOf = jsonSchema.anyOf;
104
- if (Array.isArray(anyOf)) {
105
- jsonSchema.anyOf = anyOf.map((variant, i) =>
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
- if (allOf.length === 1) {
114
- const resolved = ensureStrictJsonSchema(allOf[0]!, [...path, 'allOf', '0'], root);
115
- Object.assign(jsonSchema, resolved);
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
- jsonSchema.allOf = allOf.map((entry, i) =>
119
- ensureStrictJsonSchema(entry, [...path, 'allOf', String(i)], root),
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
- // Strip `null` defaults as there's no meaningful distinction
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
- const resolved = resolveRef(root, ref);
137
- if (typeof resolved === 'boolean') {
138
- throw new Error(`Expected \`$ref: ${ref}\` to resolve to an object schema but got boolean`);
139
- }
140
- if (!isObject(resolved)) {
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
- `Expected \`$ref: ${ref}\` to resolve to an object but got ${JSON.stringify(resolved)}`,
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
- // Properties from the json schema take priority over the ones on the `$ref`
147
- Object.assign(jsonSchema, { ...resolved, ...jsonSchema });
148
- delete (jsonSchema as any).$ref;
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
- // Since the schema expanded from `$ref` might not have `additionalProperties: false` applied,
151
- // we call `ensureStrictJsonSchema` again to fix the inlined schema and ensure it's valid.
152
- return ensureStrictJsonSchema(jsonSchema, path, root);
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 resolveRef(root: JSONSchema, ref: string): JSONSchemaDefinition {
159
- if (!ref.startsWith('#/')) {
160
- throw new Error(`Unexpected $ref format ${JSON.stringify(ref)}; Does not start with #/`);
857
+ function parseLocalRef(ref: string): string[] | undefined {
858
+ if (!ref.startsWith('#')) {
859
+ return undefined;
161
860
  }
162
861
 
163
- const pathParts = ref.slice(2).split('/');
164
- let resolved: any = root;
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
- for (const key of pathParts) {
167
- if (!isObject(resolved)) {
168
- throw new Error(`encountered non-object entry while resolving ${ref} - ${JSON.stringify(resolved)}`);
169
- }
170
- const value = resolved[key];
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
- return resolved;
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
- function isObject<T>(obj: T | Array<any>): obj is Extract<T, Record<string, any>> {
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 hasMoreThanNKeys(obj: Record<string, any>, n: number): boolean {
185
- let i = 0;
186
- for (const _ in obj) {
187
- i++;
188
- if (i > n) {
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
+ }