@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,20 +1,838 @@
1
- var _ChatCompletionStream_instances, _ChatCompletionStream_params, _ChatCompletionStream_choiceEventStates, _ChatCompletionStream_currentChatCompletionSnapshot, _ChatCompletionStream_beginRequest, _ChatCompletionStream_getChoiceEventState, _ChatCompletionStream_addChunk, _ChatCompletionStream_emitToolCallDoneEvent, _ChatCompletionStream_emitContentDoneEvents, _ChatCompletionStream_endRequest, _ChatCompletionStream_getAutoParseableResponseFormat, _ChatCompletionStream_accumulateChatCompletion;
1
+ var _ChatCompletionStream_instances, _ChatCompletionStream_params, _ChatCompletionStream_rejectsUnfinishedTurns, _ChatCompletionStream_audioDoneChoiceIndexes, _ChatCompletionStream_choiceEventStates, _ChatCompletionStream_currentChatCompletionSnapshot, _ChatCompletionStream_hasAutoParseableTool, _ChatCompletionStream_partialJSONParseBudget, _ChatCompletionStream_beginRequest, _ChatCompletionStream_getChoiceEventState, _ChatCompletionStream_addChunk, _ChatCompletionStream_emitToolCallDoneEvent, _ChatCompletionStream_emitContentDoneEvents, _ChatCompletionStream_validateStructuredSnapshots, _ChatCompletionStream_endRequest, _ChatCompletionStream_accumulateChatCompletion;
2
2
  import { __classPrivateFieldGet, __classPrivateFieldSet } from "../internal/tslib.mjs";
3
- import { partialParse } from "../_vendor/partial-json-parser/parser.mjs";
4
- import { APIUserAbortError, ContentFilterFinishReasonError, LengthFinishReasonError, OpenAIError, } from "../error.mjs";
5
- import { hasAutoParseableInput, isAutoParsableResponseFormat, isAutoParsableTool, isChatCompletionFunctionTool, maybeParseChatCompletion, shouldParseToolCall, } from "../lib/parser.mjs";
3
+ import { MalformedJSON, partialParse } from "../_vendor/partial-json-parser/parser.mjs";
4
+ import { APIError, ContentFilterFinishReasonError, LengthFinishReasonError, OpenAIError } from "../error.mjs";
5
+ import { observeJSONRequestBody } from "../internal/request-options.mjs";
6
+ import { uuid4 } from "../internal/utils/uuid.mjs";
7
+ import { hasOwn } from "../internal/utils/values.mjs";
8
+ import { hasAutoParseableInput, isAutoParsableTool, isChatCompletionFunctionTool, isParseableResponseFormat, maybeParseChatCompletion, parseResponseFormatContent, shouldParseToolCall, } from "../lib/parser.mjs";
6
9
  import { Stream } from "../streaming.mjs";
7
- import { AbstractChatCompletionRunner, } from "./AbstractChatCompletionRunner.mjs";
10
+ import { AbstractChatCompletionRunner } from "./AbstractChatCompletionRunner.mjs";
11
+ // oxlint-disable-next-line anti-slop/no-unknown-returns -- Partial JSON may have any shape; callers validate or parse it against their response schema.
12
+ function parseStructuredStreamingJSON(content) {
13
+ try {
14
+ return partialParse(content);
15
+ }
16
+ catch (error) {
17
+ if (error instanceof MalformedJSON || error instanceof SyntaxError) {
18
+ return parseResponseFormatContent({ type: 'json_schema', $parseRaw: undefined }, content);
19
+ }
20
+ throw error;
21
+ }
22
+ }
23
+ // Keep message records readable as empty chunks by older SDKs. Their finalizer
24
+ // overwrites `object`, so the encoded payload does not leak into completions.
25
+ const CHAT_COMPLETION_READABLE_STREAM_MESSAGE_PREFIX = 'chat.completion.chunk.message:';
26
+ /** Encodes a tool-result message as a backwards-compatible, empty completion chunk. */
27
+ export function makeChatCompletionReadableStreamMessageChunk(chunk, message, toolCallIds) {
28
+ const payload = {
29
+ type: 'message',
30
+ message,
31
+ // Spread creates an own data property without invoking inherited setters or changing the object prototype.
32
+ ...(toolCallIds ? { tool_call_ids: toolCallIds } : {}),
33
+ };
34
+ return {
35
+ id: chunk.id,
36
+ choices: [],
37
+ created: chunk.created,
38
+ model: chunk.model,
39
+ object: `${CHAT_COMPLETION_READABLE_STREAM_MESSAGE_PREFIX}${JSON.stringify(payload)}`,
40
+ };
41
+ }
42
+ function isChatCompletionReadableStreamMessage(item) {
43
+ return (('type' in item && item.type === 'message' && 'message' in item) ||
44
+ ('object' in item &&
45
+ typeof item.object === 'string' &&
46
+ item.object.startsWith(CHAT_COMPLETION_READABLE_STREAM_MESSAGE_PREFIX)));
47
+ }
48
+ function getChatCompletionReadableStreamMessage(item) {
49
+ if ('type' in item) {
50
+ return item;
51
+ }
52
+ // SAFETY: This decoder reads the SDK's tagged readable-stream envelope; JSON parsing restores its serialized message fields for the stream accumulator.
53
+ return JSON.parse(item.object.slice(CHAT_COMPLETION_READABLE_STREAM_MESSAGE_PREFIX.length));
54
+ }
55
+ // The Chat Completions schema limits n to 128. Replayed streams do not retain
56
+ // request parameters, so apply that choice limit independently and use the same
57
+ // conservative ceiling to prevent sparse tool-call arrays from growing unbounded.
58
+ const MAX_STREAM_CHOICES = 128;
59
+ const MAX_STREAM_TOOL_CALLS = 128;
60
+ const MAX_PARTIAL_JSON_BYTES = 16 * 1024 * 1024;
61
+ const MAX_PARTIAL_JSON_FRAGMENTS = 65536;
62
+ const MAX_PARTIAL_JSON_DEPTH = 128;
63
+ const MAX_PARTIAL_JSON_PARSE_WORK = 64 * 1024 * 1024;
64
+ const EAGER_PARTIAL_JSON_BYTES = 1024;
65
+ function createPartialJSONParseState() {
66
+ return {
67
+ bytes: 0,
68
+ depth: 0,
69
+ fragments: 0,
70
+ work: 0,
71
+ escaped: false,
72
+ has_non_whitespace: false,
73
+ in_string: false,
74
+ last_parsed_bytes: 0,
75
+ pending_high_surrogate: false,
76
+ };
77
+ }
78
+ function recordPartialJSONFragment(state, budget, fragment, validationWorkBudget) {
79
+ if (budget.fragments >= MAX_PARTIAL_JSON_FRAGMENTS) {
80
+ throw new OpenAIError('Chat completion stream exceeded its structured JSON fragment limit');
81
+ }
82
+ let bytes = 0;
83
+ let { depth, escaped, has_non_whitespace: hasNonWhitespace, in_string: inString } = state;
84
+ let completed = false;
85
+ let firstCharacter = true;
86
+ for (const character of fragment) {
87
+ const previousBytes = bytes;
88
+ const codePoint = character.codePointAt(0);
89
+ if (firstCharacter && state.pending_high_surrogate && codePoint >= 56320 && codePoint <= 57343) {
90
+ bytes += 1;
91
+ }
92
+ else if (codePoint <= 0x7f) {
93
+ bytes += 1;
94
+ }
95
+ else if (codePoint <= 2047) {
96
+ bytes += 2;
97
+ }
98
+ else if (codePoint <= 65535) {
99
+ bytes += 3;
100
+ }
101
+ else {
102
+ bytes += 4;
103
+ }
104
+ firstCharacter = false;
105
+ if (budget.bytes + bytes > MAX_PARTIAL_JSON_BYTES) {
106
+ throw new OpenAIError('Chat completion stream exceeded its structured JSON byte limit');
107
+ }
108
+ if (validationWorkBudget && validationWorkBudget.work + bytes > MAX_PARTIAL_JSON_PARSE_WORK) {
109
+ validationWorkBudget.work += previousBytes;
110
+ throw new OpenAIError('Chat completion stream exceeded its structured JSON parse-work limit');
111
+ }
112
+ if (character !== ' ' && character !== '\n' && character !== '\r' && character !== '\t') {
113
+ hasNonWhitespace = true;
114
+ }
115
+ if (inString) {
116
+ if (escaped) {
117
+ escaped = false;
118
+ }
119
+ else if (character === '\\') {
120
+ escaped = true;
121
+ }
122
+ else if (character === '"') {
123
+ inString = false;
124
+ completed || (completed = depth === 0);
125
+ }
126
+ continue;
127
+ }
128
+ if (character === '"') {
129
+ inString = true;
130
+ }
131
+ else if (character === '{' || character === '[') {
132
+ depth += 1;
133
+ if (depth > MAX_PARTIAL_JSON_DEPTH) {
134
+ throw new OpenAIError('Chat completion stream exceeded its structured JSON nesting depth limit');
135
+ }
136
+ }
137
+ else if ((character === '}' || character === ']') && depth > 0) {
138
+ depth -= 1;
139
+ completed || (completed = depth === 0);
140
+ }
141
+ }
142
+ state.bytes += bytes;
143
+ state.fragments += 1;
144
+ state.depth = depth;
145
+ state.escaped = escaped;
146
+ state.has_non_whitespace = hasNonWhitespace;
147
+ state.in_string = inString;
148
+ if (fragment.length > 0) {
149
+ const finalCodeUnit = fragment.codePointAt(fragment.length - 1) ?? 0;
150
+ state.pending_high_surrogate = finalCodeUnit >= 55296 && finalCodeUnit <= 56319;
151
+ }
152
+ budget.bytes += bytes;
153
+ budget.fragments += 1;
154
+ if (validationWorkBudget) {
155
+ validationWorkBudget.work += bytes;
156
+ }
157
+ if (!hasNonWhitespace || bytes === 0) {
158
+ return false;
159
+ }
160
+ const minimumGrowth = Math.max(EAGER_PARTIAL_JSON_BYTES, Math.floor(state.last_parsed_bytes / 2));
161
+ if (state.bytes > EAGER_PARTIAL_JSON_BYTES &&
162
+ !completed &&
163
+ state.bytes - state.last_parsed_bytes < minimumGrowth) {
164
+ return false;
165
+ }
166
+ return true;
167
+ }
168
+ function reservePartialJSONParse(state, budget) {
169
+ if (budget.work + state.bytes > MAX_PARTIAL_JSON_PARSE_WORK) {
170
+ return false;
171
+ }
172
+ budget.work += state.bytes;
173
+ state.work += state.bytes;
174
+ state.last_parsed_bytes = state.bytes;
175
+ return true;
176
+ }
177
+ function captureStructuredJSONSnapshot(snapshot, property) {
178
+ const descriptor = Object.getOwnPropertyDescriptor(snapshot, property);
179
+ if (!descriptor) {
180
+ // SAFETY: Object.getPrototypeOf returns an object or null; the following traversal checks inherited properties without assuming a specific prototype type.
181
+ let prototype = Object.getPrototypeOf(snapshot);
182
+ for (let depth = 0; prototype !== null; depth += 1) {
183
+ if (depth >= MAX_PARTIAL_JSON_DEPTH || Object.getOwnPropertyDescriptor(prototype, property)) {
184
+ throw new OpenAIError('Chat completion stream contains an unsafe structured JSON snapshot');
185
+ }
186
+ // SAFETY: Object.getPrototypeOf returns an object or null; the following traversal checks inherited properties without assuming a specific prototype type.
187
+ prototype = Object.getPrototypeOf(prototype);
188
+ }
189
+ return undefined;
190
+ }
191
+ if (!('value' in descriptor) ||
192
+ (typeof descriptor.value !== 'string' && descriptor.value !== null && descriptor.value !== undefined)) {
193
+ throw new OpenAIError('Chat completion stream contains an unsafe structured JSON snapshot');
194
+ }
195
+ // SAFETY: The own data descriptor was explicitly checked to contain only a string, null, or undefined.
196
+ return descriptor.value;
197
+ }
198
+ function captureStructuredMessageSnapshot(choice) {
199
+ const descriptor = Object.getOwnPropertyDescriptor(choice, 'message');
200
+ if (!descriptor ||
201
+ !('value' in descriptor) ||
202
+ typeof descriptor.value !== 'object' ||
203
+ descriptor.value === null) {
204
+ throw new OpenAIError('Chat completion stream contains an unsafe structured JSON snapshot');
205
+ }
206
+ // SAFETY: The choice contract supplies a message; the own data descriptor check prevents getters from changing which object is captured.
207
+ return descriptor.value;
208
+ }
209
+ function captureSnapshotArray(snapshot, property, maximum, kind) {
210
+ const descriptor = Object.getOwnPropertyDescriptor(snapshot, property);
211
+ if (!descriptor) {
212
+ // SAFETY: Object.getPrototypeOf returns an object or null; the following traversal checks inherited properties without assuming a specific prototype type.
213
+ let prototype = Object.getPrototypeOf(snapshot);
214
+ for (let depth = 0; prototype !== null; depth += 1) {
215
+ if (depth >= MAX_PARTIAL_JSON_DEPTH || Object.getOwnPropertyDescriptor(prototype, property)) {
216
+ throw new OpenAIError(`Chat completion stream contains an unsafe snapshot ${kind} collection`);
217
+ }
218
+ // SAFETY: Object.getPrototypeOf returns an object or null; the following traversal checks inherited properties without assuming a specific prototype type.
219
+ prototype = Object.getPrototypeOf(prototype);
220
+ }
221
+ return undefined;
222
+ }
223
+ if (!('value' in descriptor) || !Array.isArray(descriptor.value)) {
224
+ throw new OpenAIError(`Chat completion stream contains an unsafe snapshot ${kind} collection`);
225
+ }
226
+ const length = Object.getOwnPropertyDescriptor(descriptor.value, 'length');
227
+ if (!length || !('value' in length) || !Number.isSafeInteger(length.value) || length.value > maximum) {
228
+ throw new OpenAIError(`Chat completion stream exceeded its snapshot ${kind} limit`);
229
+ }
230
+ // SAFETY: The captured data property is an array with a checked bounded length; Item comes from the owning snapshot collection's contract.
231
+ return descriptor.value;
232
+ }
233
+ function captureSnapshotArrayItem(array, index) {
234
+ const descriptor = Object.getOwnPropertyDescriptor(array, index);
235
+ if (!descriptor) {
236
+ return undefined;
237
+ }
238
+ if (!('value' in descriptor)) {
239
+ throw new OpenAIError('Chat completion stream contains an unsafe structured JSON snapshot');
240
+ }
241
+ // SAFETY: The descriptor is a data property of the typed Item array, so its value retains that array's element contract.
242
+ return descriptor.value;
243
+ }
244
+ function mapCapturedSnapshotArray(array, maximum, kind, map) {
245
+ const descriptor = Object.getOwnPropertyDescriptor(array, 'length');
246
+ const length = descriptor && 'value' in descriptor ? descriptor.value : undefined;
247
+ if (typeof length !== 'number' || !Number.isSafeInteger(length) || length < 0 || length > maximum) {
248
+ throw new OpenAIError(`Chat completion stream exceeded its snapshot ${kind} limit`);
249
+ }
250
+ const mapped = [];
251
+ mapped.length = length;
252
+ for (let index = 0; index < length; index += 1) {
253
+ const item = Object.getOwnPropertyDescriptor(array, index);
254
+ if (!item) {
255
+ continue;
256
+ }
257
+ if (!('value' in item)) {
258
+ throw new OpenAIError('Chat completion stream contains an unsafe structured JSON snapshot');
259
+ }
260
+ // SAFETY: The descriptor is a data property of the typed Item array, so its value retains that array's element contract.
261
+ mapped[index] = map(item.value, index);
262
+ }
263
+ return mapped;
264
+ }
265
+ function validateStructuredJSONSnapshot(value, budget, validationWorkBudget) {
266
+ const state = createPartialJSONParseState();
267
+ const parseBudget = budget ?? { bytes: 0, fragments: 0, work: 0 };
268
+ recordPartialJSONFragment(state, parseBudget, value, validationWorkBudget);
269
+ if (!reservePartialJSONParse(state, parseBudget)) {
270
+ throw new OpenAIError('Chat completion stream exceeded its structured JSON parse-work limit');
271
+ }
272
+ return value;
273
+ }
274
+ function ownFunctionToolIdentity(toolCall) {
275
+ const type = Object.getOwnPropertyDescriptor(toolCall, 'type');
276
+ const fn = Object.getOwnPropertyDescriptor(toolCall, 'function');
277
+ if (!type || !('value' in type) || type.value !== 'function' || !fn || !('value' in fn)) {
278
+ return undefined;
279
+ }
280
+ if (typeof fn.value !== 'object' || fn.value === null) {
281
+ return undefined;
282
+ }
283
+ const name = Object.getOwnPropertyDescriptor(fn.value, 'name');
284
+ if (!name || !('value' in name) || typeof name.value !== 'string' || name.value.length === 0) {
285
+ return undefined;
286
+ }
287
+ return { type: 'function', name: name.value };
288
+ }
289
+ function assertBoundToolCallIdentity(toolCall, identity) {
290
+ const current = ownFunctionToolIdentity(toolCall);
291
+ if (!current || current.name !== identity.name || current.type !== identity.type) {
292
+ throw new OpenAIError('Chat completion stream contains a changed tool call identity');
293
+ }
294
+ }
295
+ // oxlint-disable-next-line anti-slop/no-object-parameters -- This assignment primitive copies own properties from heterogeneous snapshot and delta objects.
296
+ function assignOwnProperties(target, source) {
297
+ if (Object.prototype.propertyIsEnumerable.call(source, '__proto__') && !hasOwn(target, '__proto__')) {
298
+ Object.defineProperty(target, '__proto__', {
299
+ value: undefined,
300
+ writable: true,
301
+ enumerable: true,
302
+ configurable: true,
303
+ });
304
+ }
305
+ return Object.assign(target, source);
306
+ }
307
+ function cloneParserConfigObject(value, stableFields = []) {
308
+ const descriptors = Object.getOwnPropertyDescriptors(value);
309
+ for (const field of stableFields) {
310
+ const descriptor = descriptors[field];
311
+ if (!descriptor && !(field in value)) {
312
+ continue;
313
+ }
314
+ descriptors[field] = {
315
+ // oxlint-disable-next-line anti-slop/no-reflect-get -- Generic config cloning must resolve inherited/accessor keys outside the declared config shape.
316
+ value: descriptor && 'value' in descriptor ? descriptor.value : Reflect.get(value, field, value),
317
+ enumerable: descriptor?.enumerable ?? false,
318
+ configurable: descriptor?.configurable ?? true,
319
+ writable: descriptor && 'writable' in descriptor ? descriptor.writable : false,
320
+ };
321
+ }
322
+ // SAFETY: The clone preserves the original prototype and descriptors, replacing only the parser metadata captured from that same value.
323
+ return Object.create(Object.getPrototypeOf(value), descriptors);
324
+ }
325
+ function snapshotChatCompletionParserParams(params) {
326
+ const snapshot = cloneParserConfigObject(params);
327
+ if (params.tools) {
328
+ const stableTools = [];
329
+ const lengthDescriptor = Object.getOwnPropertyDescriptor(params.tools, 'length');
330
+ const length = lengthDescriptor && 'value' in lengthDescriptor ? lengthDescriptor.value : undefined;
331
+ const toolCount = typeof length === 'number' && Number.isSafeInteger(length) && length >= 0
332
+ ? Math.min(length, MAX_STREAM_TOOL_CALLS)
333
+ : 0;
334
+ for (let index = 0; index < toolCount; index += 1) {
335
+ const item = Object.getOwnPropertyDescriptor(params.tools, String(index));
336
+ if (!item || !('value' in item)) {
337
+ stableTools.length = index + 1;
338
+ continue;
339
+ }
340
+ // SAFETY: This own data descriptor comes from the request's typed tools array; the following code captures its parser metadata.
341
+ const tool = item.value;
342
+ const stableTool = cloneParserConfigObject(tool, [
343
+ 'type',
344
+ '$brand',
345
+ '$parseRaw',
346
+ '$callback',
347
+ 'function',
348
+ ]);
349
+ const descriptors = Object.getOwnPropertyDescriptors(stableTool);
350
+ if (isChatCompletionFunctionTool(stableTool)) {
351
+ const descriptor = descriptors.function;
352
+ descriptors.function = {
353
+ ...(descriptor && 'value' in descriptor
354
+ ? descriptor
355
+ : { configurable: true, enumerable: true, writable: true }),
356
+ value: cloneParserConfigObject(stableTool.function, ['name', 'strict']),
357
+ };
358
+ }
359
+ // SAFETY: The cloned tool retains the original prototype and descriptors while substituting its captured parser configuration.
360
+ stableTools[index] = Object.create(Object.getPrototypeOf(tool), descriptors);
361
+ }
362
+ snapshot.tools = stableTools;
363
+ }
364
+ if (params.response_format) {
365
+ snapshot.response_format = cloneParserConfigObject(params.response_format, [
366
+ 'type',
367
+ '$brand',
368
+ '$parseRaw',
369
+ ]);
370
+ }
371
+ return snapshot;
372
+ }
373
+ const MAX_SERIALIZED_PARSER_SCHEMA_NODES = 4096;
374
+ const stringifyParserSchemaValue = JSON.stringify;
375
+ const MAX_SERIALIZED_PARSER_SCHEMA_BYTES = 1024 * 1024;
376
+ const MAX_SERIALIZED_PARSER_SCHEMA_DEPTH = 64;
377
+ const OMITTED_SERIALIZED_PARSER_VALUE = Symbol('omitted serialized parser value');
378
+ const UNSAFE_SERIALIZED_PARSER_VALUE = Symbol('unsafe serialized parser value');
379
+ function canonicalSerializedParserSchema(value, budget) {
380
+ const ancestors = new WeakSet();
381
+ const charge = (bytes) => {
382
+ if (!Number.isSafeInteger(bytes) ||
383
+ bytes < 0 ||
384
+ budget.bytes + bytes > MAX_SERIALIZED_PARSER_SCHEMA_BYTES) {
385
+ return false;
386
+ }
387
+ budget.bytes += bytes;
388
+ return true;
389
+ };
390
+ // SAFETY: Object.getPrototypeOf returns an object or null; the following traversal checks inherited properties without assuming a specific prototype type.
391
+ const visit = (current, depth) => {
392
+ if (depth > MAX_SERIALIZED_PARSER_SCHEMA_DEPTH || budget.nodes >= MAX_SERIALIZED_PARSER_SCHEMA_NODES) {
393
+ return UNSAFE_SERIALIZED_PARSER_VALUE;
394
+ }
395
+ budget.nodes += 1;
396
+ if (current === undefined || typeof current === 'function' || typeof current === 'symbol') {
397
+ return OMITTED_SERIALIZED_PARSER_VALUE;
398
+ }
399
+ if (typeof current === 'bigint') {
400
+ return UNSAFE_SERIALIZED_PARSER_VALUE;
401
+ }
402
+ if (current === null || typeof current === 'boolean' || typeof current === 'number') {
403
+ const serialized = stringifyParserSchemaValue(current);
404
+ return typeof serialized === 'string' && charge(serialized.length)
405
+ ? serialized
406
+ : UNSAFE_SERIALIZED_PARSER_VALUE;
407
+ }
408
+ if (typeof current === 'string') {
409
+ if (!charge(current.length * 6 + 2)) {
410
+ return UNSAFE_SERIALIZED_PARSER_VALUE;
411
+ }
412
+ return stringifyParserSchemaValue(current);
413
+ }
414
+ if (typeof current !== 'object' || ancestors.has(current)) {
415
+ return UNSAFE_SERIALIZED_PARSER_VALUE;
416
+ }
417
+ const array = Array.isArray(current);
418
+ // SAFETY: Object.getPrototypeOf returns an object or null; the following traversal checks inherited properties without assuming a specific prototype type.
419
+ const prototype = Object.getPrototypeOf(current);
420
+ if ((array && prototype !== Array.prototype) ||
421
+ (!array && prototype !== null && prototype !== Object.prototype)) {
422
+ return UNSAFE_SERIALIZED_PARSER_VALUE;
423
+ }
424
+ for (let owner = current; owner !== null; owner = Object.getPrototypeOf(owner)) {
425
+ const serializer = Object.getOwnPropertyDescriptor(owner, 'toJSON');
426
+ if (!serializer) {
427
+ continue;
428
+ }
429
+ if (!('value' in serializer) || typeof serializer.value === 'function') {
430
+ return UNSAFE_SERIALIZED_PARSER_VALUE;
431
+ }
432
+ break;
433
+ }
434
+ ancestors.add(current);
435
+ try {
436
+ if (!charge(2)) {
437
+ return UNSAFE_SERIALIZED_PARSER_VALUE;
438
+ }
439
+ if (array) {
440
+ const lengthDescriptor = Object.getOwnPropertyDescriptor(current, 'length');
441
+ const length = lengthDescriptor && 'value' in lengthDescriptor ? lengthDescriptor.value : undefined;
442
+ if (typeof length !== 'number' ||
443
+ !Number.isSafeInteger(length) ||
444
+ length < 0 ||
445
+ length > MAX_SERIALIZED_PARSER_SCHEMA_NODES - budget.nodes) {
446
+ return UNSAFE_SERIALIZED_PARSER_VALUE;
447
+ }
448
+ const items = [];
449
+ for (let index = 0; index < length; index += 1) {
450
+ const key = String(index);
451
+ const descriptor = Object.getOwnPropertyDescriptor(current, key);
452
+ if (!descriptor) {
453
+ if (Object.getOwnPropertyDescriptor(Array.prototype, key) ||
454
+ Object.getOwnPropertyDescriptor(Object.prototype, key)) {
455
+ return UNSAFE_SERIALIZED_PARSER_VALUE;
456
+ }
457
+ budget.nodes += 1;
458
+ if (!charge(4)) {
459
+ return UNSAFE_SERIALIZED_PARSER_VALUE;
460
+ }
461
+ items.push('null');
462
+ continue;
463
+ }
464
+ if (!('value' in descriptor)) {
465
+ return UNSAFE_SERIALIZED_PARSER_VALUE;
466
+ }
467
+ const item = visit(descriptor.value, depth + 1);
468
+ if (item === UNSAFE_SERIALIZED_PARSER_VALUE) {
469
+ return item;
470
+ }
471
+ items.push(item === OMITTED_SERIALIZED_PARSER_VALUE ? 'null' : item);
472
+ }
473
+ return `[${items.join(',')}]`;
474
+ }
475
+ const keys = Reflect.ownKeys(current);
476
+ if (keys.length > MAX_SERIALIZED_PARSER_SCHEMA_NODES - budget.nodes) {
477
+ return UNSAFE_SERIALIZED_PARSER_VALUE;
478
+ }
479
+ const entries = [];
480
+ for (const key of keys) {
481
+ if (typeof key !== 'string') {
482
+ continue;
483
+ }
484
+ const descriptor = Object.getOwnPropertyDescriptor(current, key);
485
+ if (!descriptor) {
486
+ return UNSAFE_SERIALIZED_PARSER_VALUE;
487
+ }
488
+ if (!descriptor.enumerable) {
489
+ continue;
490
+ }
491
+ if (!('value' in descriptor)) {
492
+ return UNSAFE_SERIALIZED_PARSER_VALUE;
493
+ }
494
+ entries.push([key, descriptor.value]);
495
+ }
496
+ entries.sort(([left], [right]) => {
497
+ if (left === right) {
498
+ return 0;
499
+ }
500
+ return left < right ? -1 : 1;
501
+ });
502
+ const fields = [];
503
+ for (const [key, entry] of entries) {
504
+ const normalized = visit(entry, depth + 1);
505
+ if (normalized === UNSAFE_SERIALIZED_PARSER_VALUE) {
506
+ return normalized;
507
+ }
508
+ if (normalized === OMITTED_SERIALIZED_PARSER_VALUE) {
509
+ continue;
510
+ }
511
+ if (!charge(key.length * 6 + 3)) {
512
+ return UNSAFE_SERIALIZED_PARSER_VALUE;
513
+ }
514
+ fields.push(`${stringifyParserSchemaValue(key)}:${normalized}`);
515
+ }
516
+ return `{${fields.join(',')}}`;
517
+ }
518
+ finally {
519
+ ancestors.delete(current);
520
+ }
521
+ };
522
+ try {
523
+ const normalized = visit(value, 0);
524
+ return typeof normalized === 'string' ? normalized : undefined;
525
+ }
526
+ catch {
527
+ return undefined;
528
+ }
529
+ }
530
+ function rememberSerializedParserSchema(signatures,
531
+ // oxlint-disable-next-line anti-slop/no-object-parameters -- Parser owners are tracked by identity before their metadata descriptors are validated.
532
+ source,
533
+ // oxlint-disable-next-line anti-slop/no-object-parameters -- Serialized schema holders may be arbitrary objects with hostile accessors or prototypes.
534
+ holder, key) {
535
+ const parser = Object.getOwnPropertyDescriptor(source, '$parseRaw');
536
+ const schema = Object.getOwnPropertyDescriptor(holder, key);
537
+ if (!parser ||
538
+ !('value' in parser) ||
539
+ typeof parser.value !== 'function' ||
540
+ !schema ||
541
+ !('value' in schema)) {
542
+ return;
543
+ }
544
+ const normalized = canonicalSerializedParserSchema(schema.value, { nodes: 0, bytes: 0 });
545
+ if (normalized !== undefined) {
546
+ signatures.set(source, normalized);
547
+ }
548
+ }
549
+ function hasMatchingSerializedParserSchema(signatures,
550
+ // oxlint-disable-next-line anti-slop/no-object-parameters -- Parser signatures belong to the original object identity, independent of its fields.
551
+ source,
552
+ // oxlint-disable-next-line anti-slop/no-object-parameters -- The schema holder is inspected through own descriptors before its contents are trusted.
553
+ holder, key, value) {
554
+ const expected = source && signatures.get(source);
555
+ const descriptor = Object.getOwnPropertyDescriptor(holder, key);
556
+ return (expected !== undefined &&
557
+ descriptor !== undefined &&
558
+ 'value' in descriptor &&
559
+ canonicalSerializedParserSchema(value, { nodes: 0, bytes: 0 }) === expected);
560
+ }
561
+ function serializedParserDescriptor(descriptor, value) {
562
+ return descriptor && 'value' in descriptor
563
+ ? { ...descriptor, value }
564
+ : { configurable: true, enumerable: true, writable: true, value };
565
+ }
566
+ function shadowSerializedParserMetadata(descriptors, source, fields) {
567
+ for (const field of fields) {
568
+ const descriptor = descriptors[field];
569
+ if (!descriptor && !(field in source)) {
570
+ continue;
571
+ }
572
+ descriptors[field] =
573
+ descriptor && 'value' in descriptor
574
+ ? { ...descriptor, value: undefined }
575
+ : {
576
+ configurable: descriptor?.configurable ?? true,
577
+ enumerable: descriptor?.enumerable ?? false,
578
+ writable: false,
579
+ value: undefined,
580
+ };
581
+ }
582
+ }
583
+ function snapshotSerializedParserTool(serialized) {
584
+ // SAFETY: The fallback is a serialization scaffold: the code below installs the captured wire fields before the tool is returned.
585
+ const source = serialized.source ??
586
+ {
587
+ type: serialized.type,
588
+ ...(serialized.type === 'function' ? { function: {} } : {}),
589
+ };
590
+ const descriptors = Object.getOwnPropertyDescriptors(source);
591
+ descriptors.type = serializedParserDescriptor(descriptors.type, serialized.type);
592
+ if (serialized.type !== 'function' || !serialized.function) {
593
+ if (descriptors.function) {
594
+ descriptors.function = serializedParserDescriptor(descriptors.function, undefined);
595
+ }
596
+ shadowSerializedParserMetadata(descriptors, source, ['$brand', '$parseRaw', '$callback']);
597
+ // SAFETY: The descriptors reconstruct the tool's captured serialized fields and shadow parser metadata while retaining its original prototype.
598
+ return Object.create(Object.getPrototypeOf(source), descriptors);
599
+ }
600
+ const descriptor = descriptors.function;
601
+ // SAFETY: The preceding guard proves this data descriptor contains a non-null object; no more specific type is assumed.
602
+ const original = descriptor && 'value' in descriptor && typeof descriptor.value === 'object' && descriptor.value !== null
603
+ ? descriptor.value
604
+ : {};
605
+ const functionDescriptors = Object.getOwnPropertyDescriptors(original);
606
+ functionDescriptors['name'] = serializedParserDescriptor(functionDescriptors['name'], serialized.function.name);
607
+ functionDescriptors['strict'] = serializedParserDescriptor(functionDescriptors['strict'], serialized.function.strict);
608
+ descriptors.function = serializedParserDescriptor(descriptor, Object.create(Object.getPrototypeOf(original), functionDescriptors));
609
+ if (!serialized.function.schemaMatches) {
610
+ shadowSerializedParserMetadata(descriptors, source, ['$brand', '$parseRaw', '$callback']);
611
+ }
612
+ // SAFETY: The descriptors reconstruct the tool's captured serialized fields and shadow parser metadata while retaining its original prototype.
613
+ return Object.create(Object.getPrototypeOf(source), descriptors);
614
+ }
615
+ function snapshotSerializedResponseFormat(serialized) {
616
+ // SAFETY: The fallback seeds only the discriminator; the captured response-format fields are installed below before returning it.
617
+ const source = serialized.source ?? { type: serialized.type };
618
+ const descriptors = Object.getOwnPropertyDescriptors(source);
619
+ descriptors.type = serializedParserDescriptor(descriptors.type, serialized.type);
620
+ if (serialized.type !== 'json_schema' || !serialized.source || !serialized.schemaMatches) {
621
+ shadowSerializedParserMetadata(descriptors, source, ['$brand', '$parseRaw']);
622
+ }
623
+ // SAFETY: The descriptors restore the captured response-format fields and parser metadata on the original prototype.
624
+ return Object.create(Object.getPrototypeOf(source), descriptors);
625
+ }
626
+ // oxlint-disable-next-line anti-slop/no-object-parameters -- The serialization visitor accepts arbitrary object and array holders, inspecting own descriptors only.
627
+ function ownSerializedParserObject(holder, key) {
628
+ const descriptor = Object.getOwnPropertyDescriptor(holder, key);
629
+ if (!descriptor || !('value' in descriptor)) {
630
+ return undefined;
631
+ }
632
+ const { value } = descriptor;
633
+ return typeof value === 'object' && value !== null ? value : undefined;
634
+ }
635
+ function observeSerializedChatCompletionParserParams(body, initial, update) {
636
+ const originalToolOwners = new WeakMap();
637
+ const originalSchemaSignatures = new WeakMap();
638
+ // At most 128 tools plus one response format each receive an independent
639
+ // 4,096-node/1 MiB source and wire allowance (129 MiB maximum per pass).
640
+ if (body.tools) {
641
+ for (let index = 0; index < body.tools.length && index < MAX_STREAM_TOOL_CALLS; index += 1) {
642
+ const owner = ownSerializedParserObject(body.tools, String(index));
643
+ const source = initial.tools?.[index];
644
+ if (owner && source) {
645
+ originalToolOwners.set(owner, source);
646
+ const originalFunction = ownSerializedParserObject(source, 'function');
647
+ if (originalFunction) {
648
+ rememberSerializedParserSchema(originalSchemaSignatures, source, originalFunction, 'parameters');
649
+ }
650
+ }
651
+ }
652
+ }
653
+ if (initial.response_format) {
654
+ rememberSerializedParserSchema(originalSchemaSignatures, initial.response_format, initial.response_format, 'json_schema');
655
+ }
656
+ let root;
657
+ let tools;
658
+ let responseFormat;
659
+ let responseFrame;
660
+ let frames = [];
661
+ let toolFrames = new WeakMap();
662
+ let actualToolOwners = new Map();
663
+ let functionFrames = new WeakMap();
664
+ return observeJSONRequestBody(body, {
665
+ value(holder, key, value) {
666
+ if (!root && key === '' && typeof value === 'object' && value !== null) {
667
+ root = value;
668
+ tools = undefined;
669
+ responseFormat = undefined;
670
+ responseFrame = undefined;
671
+ frames = [];
672
+ toolFrames = new WeakMap();
673
+ actualToolOwners = new Map();
674
+ functionFrames = new WeakMap();
675
+ return;
676
+ }
677
+ if (holder === root && key === 'response_format') {
678
+ if (typeof value === 'object' && value !== null) {
679
+ responseFormat = value;
680
+ const owner = ownSerializedParserObject(holder, key);
681
+ responseFrame = {
682
+ source: owner === body.response_format ? initial.response_format : undefined,
683
+ schemaMatches: false,
684
+ };
685
+ }
686
+ return;
687
+ }
688
+ if (holder === root && key === 'tools') {
689
+ if (Array.isArray(value)) {
690
+ tools = new Proxy(value, {
691
+ get(target, property) {
692
+ // SAFETY: Proxy property values may be arbitrary; unknown preserves that uncertainty before the property-specific checks below.
693
+ // oxlint-disable-next-line anti-slop/no-reflect-get -- Proxy forwarding must preserve arbitrary keys with the original target as accessor receiver.
694
+ const actual = Reflect.get(target, property, target);
695
+ if (typeof property === 'string') {
696
+ const index = Number(property);
697
+ if (Number.isSafeInteger(index) &&
698
+ index >= 0 &&
699
+ index < MAX_STREAM_TOOL_CALLS &&
700
+ String(index) === property) {
701
+ actualToolOwners.set(index, typeof actual === 'object' && actual !== null ? actual : undefined);
702
+ }
703
+ }
704
+ return actual;
705
+ },
706
+ });
707
+ return tools;
708
+ }
709
+ return;
710
+ }
711
+ if (holder === tools) {
712
+ const index = Number(key);
713
+ if (!Number.isSafeInteger(index) ||
714
+ index < 0 ||
715
+ index >= MAX_STREAM_TOOL_CALLS ||
716
+ typeof value !== 'object' ||
717
+ value === null) {
718
+ return;
719
+ }
720
+ const owner = actualToolOwners.get(index);
721
+ const source = owner ? originalToolOwners.get(owner) : undefined;
722
+ const frame = { source };
723
+ frames[index] = frame;
724
+ toolFrames.set(value, frame);
725
+ return;
726
+ }
727
+ const tool = toolFrames.get(holder);
728
+ if (tool) {
729
+ if (key === 'type' && typeof value === 'string') {
730
+ tool.type = value;
731
+ }
732
+ else if (key === 'function' && typeof value === 'object' && value !== null) {
733
+ const fn = { source: tool.source, schemaMatches: false };
734
+ tool.function = fn;
735
+ functionFrames.set(value, fn);
736
+ }
737
+ return;
738
+ }
739
+ if (holder === responseFormat && responseFrame) {
740
+ if (key === 'type' && typeof value === 'string') {
741
+ responseFrame.type = value;
742
+ }
743
+ else if (key === 'json_schema') {
744
+ responseFrame.schemaMatches = hasMatchingSerializedParserSchema(originalSchemaSignatures, responseFrame.source, holder, key, value);
745
+ }
746
+ return;
747
+ }
748
+ const fn = functionFrames.get(holder);
749
+ if (fn) {
750
+ if (key === 'name' && typeof value === 'string') {
751
+ fn.name = value;
752
+ }
753
+ else if (key === 'strict' && typeof value === 'boolean') {
754
+ fn.strict = value;
755
+ }
756
+ else if (key === 'parameters') {
757
+ fn.schemaMatches = hasMatchingSerializedParserSchema(originalSchemaSignatures, fn.source, holder, key, value);
758
+ }
759
+ }
760
+ return undefined;
761
+ },
762
+ complete() {
763
+ if (!root) {
764
+ return;
765
+ }
766
+ const snapshot = cloneParserConfigObject(initial);
767
+ if (tools) {
768
+ const serializedTools = [];
769
+ for (let index = 0; index < frames.length; index += 1) {
770
+ const frame = frames[index];
771
+ if (frame) {
772
+ serializedTools[index] = snapshotSerializedParserTool(frame);
773
+ }
774
+ }
775
+ snapshot.tools = serializedTools;
776
+ }
777
+ else {
778
+ delete snapshot.tools;
779
+ }
780
+ if (responseFrame) {
781
+ snapshot.response_format = snapshotSerializedResponseFormat(responseFrame);
782
+ }
783
+ else {
784
+ delete snapshot.response_format;
785
+ }
786
+ update(snapshot);
787
+ root = undefined;
788
+ tools = undefined;
789
+ responseFormat = undefined;
790
+ responseFrame = undefined;
791
+ frames = [];
792
+ toolFrames = new WeakMap();
793
+ actualToolOwners = new Map();
794
+ functionFrames = new WeakMap();
795
+ },
796
+ });
797
+ }
798
+ /** Streams chat completion chunks while accumulating snapshots, parsed output, and events. */
8
799
  export class ChatCompletionStream extends AbstractChatCompletionRunner {
800
+ /** Creates an unstarted stream, retaining request parameters for structured-output parsing. */
9
801
  constructor(params) {
10
802
  super();
11
803
  _ChatCompletionStream_instances.add(this);
12
804
  _ChatCompletionStream_params.set(this, void 0);
805
+ _ChatCompletionStream_rejectsUnfinishedTurns.set(this, false);
806
+ _ChatCompletionStream_audioDoneChoiceIndexes.set(this, void 0);
13
807
  _ChatCompletionStream_choiceEventStates.set(this, void 0);
14
808
  _ChatCompletionStream_currentChatCompletionSnapshot.set(this, void 0);
809
+ _ChatCompletionStream_hasAutoParseableTool.set(this, void 0);
810
+ _ChatCompletionStream_partialJSONParseBudget.set(this, void 0);
15
811
  __classPrivateFieldSet(this, _ChatCompletionStream_params, params, "f");
812
+ __classPrivateFieldSet(this, _ChatCompletionStream_audioDoneChoiceIndexes, new Set(), "f");
16
813
  __classPrivateFieldSet(this, _ChatCompletionStream_choiceEventStates, [], "f");
814
+ __classPrivateFieldSet(this, _ChatCompletionStream_hasAutoParseableTool, false, "f");
815
+ const tools = params?.tools;
816
+ const lengthDescriptor = tools && Object.getOwnPropertyDescriptor(tools, 'length');
817
+ const length = lengthDescriptor && 'value' in lengthDescriptor ? lengthDescriptor.value : undefined;
818
+ if (tools && typeof length === 'number' && Number.isSafeInteger(length) && length >= 0) {
819
+ for (let index = 0; index < Math.min(length, MAX_STREAM_TOOL_CALLS); index += 1) {
820
+ const descriptor = Object.getOwnPropertyDescriptor(tools, String(index));
821
+ if (!descriptor || !('value' in descriptor)) {
822
+ continue;
823
+ }
824
+ // SAFETY: The descriptor is read from the typed request tools array and checked as an own data property before accessing the tool.
825
+ const tool = descriptor.value;
826
+ if (isChatCompletionFunctionTool(tool) &&
827
+ (isAutoParsableTool(tool) || tool.function.strict === true)) {
828
+ __classPrivateFieldSet(this, _ChatCompletionStream_hasAutoParseableTool, true, "f");
829
+ break;
830
+ }
831
+ }
832
+ }
833
+ __classPrivateFieldSet(this, _ChatCompletionStream_partialJSONParseBudget, { bytes: 0, fragments: 0, work: 0 }, "f");
17
834
  }
835
+ /** The latest accumulated completion, or `undefined` before a chunk arrives or after finalization. */
18
836
  get currentChatCompletionSnapshot() {
19
837
  return __classPrivateFieldGet(this, _ChatCompletionStream_currentChatCompletionSnapshot, "f");
20
838
  }
@@ -22,66 +840,112 @@ export class ChatCompletionStream extends AbstractChatCompletionRunner {
22
840
  * Intended for use on the frontend, consuming a stream produced with
23
841
  * `.toReadableStream()` on the backend.
24
842
  *
25
- * Note that messages sent to the model do not appear in `.on('message')`
26
- * in this context.
843
+ * Original input messages are not included in the serialized stream. Tool-result
844
+ * messages explicitly serialized by a streaming tool runner are replayed.
27
845
  */
28
846
  static fromReadableStream(stream) {
29
847
  const runner = new ChatCompletionStream(null);
30
848
  runner._run(() => runner._fromReadableStream(stream));
31
849
  return runner;
32
850
  }
851
+ /** Starts a streaming chat completion request and returns its event-driven helper. */
33
852
  static createChatCompletion(client, params, options) {
853
+ // SAFETY: The runner forces stream: true when sending this request; the same parameters retain the caller's parsing configuration.
34
854
  const runner = new ChatCompletionStream(params);
35
- runner._run(() => runner._runChatCompletion(client, { ...params, stream: true }, { ...options, headers: { ...options?.headers, 'X-Stainless-Helper-Method': 'stream' } }));
855
+ runner._run(() => runner._runChatCompletion(client, { ...params, stream: true }, { ...options, __metadata: { ...options?.__metadata, helperMethod: 'stream' } }));
36
856
  return runner;
37
857
  }
858
+ /** Rejects unfinished turns before tool callbacks while preserving ordinary stream and replay behavior. */
859
+ _runTools(client, params, runner, options) {
860
+ __classPrivateFieldSet(this, _ChatCompletionStream_rejectsUnfinishedTurns, true, "f");
861
+ return super._runTools(client, params, runner, options);
862
+ }
38
863
  async _createChatCompletion(client, params, options) {
39
- super._createChatCompletion;
40
- const signal = options?.signal;
41
- if (signal) {
42
- if (signal.aborted)
43
- this.controller.abort();
44
- signal.addEventListener('abort', () => this.controller.abort());
45
- }
864
+ this._listenForAbort(options?.signal);
865
+ const requestParams = { ...params, stream: true };
866
+ __classPrivateFieldSet(this, _ChatCompletionStream_params, requestParams, "f");
46
867
  __classPrivateFieldGet(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_beginRequest).call(this);
47
- const stream = await client.chat.completions.create({ ...params, stream: true }, { ...options, signal: this.controller.signal });
868
+ const parserParams = snapshotChatCompletionParserParams(requestParams);
869
+ __classPrivateFieldSet(this, _ChatCompletionStream_params, parserParams, "f");
870
+ __classPrivateFieldSet(this, _ChatCompletionStream_hasAutoParseableTool, parserParams.tools?.some((tool) => isChatCompletionFunctionTool(tool) && (isAutoParsableTool(tool) || tool.function.strict === true)) ?? false, "f");
871
+ const stopObserving = requestParams.tools || requestParams.response_format
872
+ ? observeSerializedChatCompletionParserParams(requestParams, parserParams, (serialized) => {
873
+ __classPrivateFieldSet(this, _ChatCompletionStream_params, serialized, "f");
874
+ __classPrivateFieldSet(this, _ChatCompletionStream_hasAutoParseableTool, serialized.tools?.some((tool) => isChatCompletionFunctionTool(tool) &&
875
+ (isAutoParsableTool(tool) || tool.function.strict === true)) ?? false, "f");
876
+ })
877
+ : undefined;
878
+ const stream = await client.chat.completions
879
+ .create(requestParams, {
880
+ ...options,
881
+ signal: this.controller.signal,
882
+ })
883
+ .finally(stopObserving);
48
884
  this._connected();
49
885
  for await (const chunk of stream) {
50
886
  __classPrivateFieldGet(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_addChunk).call(this, chunk);
51
887
  }
52
888
  if (stream.controller.signal?.aborted) {
53
- throw new APIUserAbortError();
889
+ throw this._userAbortError();
54
890
  }
55
891
  return this._addChatCompletion(__classPrivateFieldGet(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_endRequest).call(this));
56
892
  }
57
893
  async _fromReadableStream(readableStream, options) {
58
- const signal = options?.signal;
59
- if (signal) {
60
- if (signal.aborted)
61
- this.controller.abort();
62
- signal.addEventListener('abort', () => this.controller.abort());
63
- }
894
+ this._listenForAbort(options?.signal);
64
895
  __classPrivateFieldGet(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_beginRequest).call(this);
65
896
  this._connected();
66
897
  const stream = Stream.fromReadableStream(readableStream, this.controller);
67
898
  let chatId;
68
- for await (const chunk of stream) {
69
- if (chatId && chatId !== chunk.id) {
899
+ for await (const item of stream) {
900
+ if ('error' in item && hasOwn(item, 'error') && typeof item.error === 'object' && item.error !== null) {
901
+ throw new APIError(undefined, item.error, undefined, undefined);
902
+ }
903
+ if (isChatCompletionReadableStreamMessage(item)) {
904
+ const message = getChatCompletionReadableStreamMessage(item);
905
+ if (__classPrivateFieldGet(this, _ChatCompletionStream_currentChatCompletionSnapshot, "f")) {
906
+ const toolCalls = __classPrivateFieldGet(this, _ChatCompletionStream_currentChatCompletionSnapshot, "f").choices[0]?.message.tool_calls;
907
+ for (const [index, id] of message.tool_call_ids?.entries() ?? []) {
908
+ const toolCall = toolCalls?.[index];
909
+ if (toolCall && id) {
910
+ toolCall.id = id;
911
+ }
912
+ }
913
+ this._addChatCompletion(__classPrivateFieldGet(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_endRequest).call(this));
914
+ chatId = undefined;
915
+ }
916
+ this._addMessage(message.message);
917
+ continue;
918
+ }
919
+ const chunk = item;
920
+ if (chatId && chunk.id && chatId !== chunk.id) {
70
921
  // A new request has been made.
71
922
  this._addChatCompletion(__classPrivateFieldGet(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_endRequest).call(this));
72
923
  }
73
924
  __classPrivateFieldGet(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_addChunk).call(this, chunk);
74
- chatId = chunk.id;
925
+ if (chunk.id) {
926
+ chatId = chunk.id;
927
+ }
75
928
  }
76
929
  if (stream.controller.signal?.aborted) {
77
- throw new APIUserAbortError();
930
+ throw this._userAbortError();
78
931
  }
79
- return this._addChatCompletion(__classPrivateFieldGet(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_endRequest).call(this));
932
+ if (__classPrivateFieldGet(this, _ChatCompletionStream_currentChatCompletionSnapshot, "f")) {
933
+ return this._addChatCompletion(__classPrivateFieldGet(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_endRequest).call(this));
934
+ }
935
+ const lastChatCompletion = this._chatCompletions[this._chatCompletions.length - 1];
936
+ if (lastChatCompletion) {
937
+ return lastChatCompletion;
938
+ }
939
+ throw new OpenAIError(`request ended without sending any chunks`);
80
940
  }
81
- [(_ChatCompletionStream_params = new WeakMap(), _ChatCompletionStream_choiceEventStates = new WeakMap(), _ChatCompletionStream_currentChatCompletionSnapshot = new WeakMap(), _ChatCompletionStream_instances = new WeakSet(), _ChatCompletionStream_beginRequest = function _ChatCompletionStream_beginRequest() {
82
- if (this.ended)
941
+ /** Iterates over raw API chunks; stopping iteration early aborts the underlying request. */
942
+ [(_ChatCompletionStream_params = new WeakMap(), _ChatCompletionStream_rejectsUnfinishedTurns = new WeakMap(), _ChatCompletionStream_audioDoneChoiceIndexes = new WeakMap(), _ChatCompletionStream_choiceEventStates = new WeakMap(), _ChatCompletionStream_currentChatCompletionSnapshot = new WeakMap(), _ChatCompletionStream_hasAutoParseableTool = new WeakMap(), _ChatCompletionStream_partialJSONParseBudget = new WeakMap(), _ChatCompletionStream_instances = new WeakSet(), _ChatCompletionStream_beginRequest = function _ChatCompletionStream_beginRequest() {
943
+ if (this.ended) {
83
944
  return;
945
+ }
946
+ __classPrivateFieldSet(this, _ChatCompletionStream_audioDoneChoiceIndexes, new Set(), "f");
84
947
  __classPrivateFieldSet(this, _ChatCompletionStream_currentChatCompletionSnapshot, undefined, "f");
948
+ __classPrivateFieldSet(this, _ChatCompletionStream_partialJSONParseBudget, { bytes: 0, fragments: 0, work: 0 }, "f");
85
949
  }, _ChatCompletionStream_getChoiceEventState = function _ChatCompletionStream_getChoiceEventState(choice) {
86
950
  let state = __classPrivateFieldGet(this, _ChatCompletionStream_choiceEventStates, "f")[choice.index];
87
951
  if (state) {
@@ -89,46 +953,62 @@ export class ChatCompletionStream extends AbstractChatCompletionRunner {
89
953
  }
90
954
  state = {
91
955
  content_done: false,
956
+ content_parse_state: undefined,
92
957
  refusal_done: false,
93
958
  logprobs_content_done: false,
94
959
  logprobs_refusal_done: false,
95
960
  done_tool_calls: new Set(),
96
961
  current_tool_call_index: null,
962
+ tool_call_parse_states: new Map(),
963
+ tool_call_identities: new Map(),
97
964
  };
98
965
  __classPrivateFieldGet(this, _ChatCompletionStream_choiceEventStates, "f")[choice.index] = state;
99
966
  return state;
100
967
  }, _ChatCompletionStream_addChunk = function _ChatCompletionStream_addChunk(chunk) {
101
- if (this.ended)
968
+ if (this.ended) {
102
969
  return;
103
- const completion = __classPrivateFieldGet(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_accumulateChatCompletion).call(this, chunk);
970
+ }
971
+ const capturedChoiceFrames = new WeakMap();
972
+ const completion = __classPrivateFieldGet(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_accumulateChatCompletion).call(this, chunk, capturedChoiceFrames);
104
973
  this._emit('chunk', chunk, completion);
105
974
  for (const choice of chunk.choices) {
106
- const choiceSnapshot = completion.choices[choice.index];
107
- if (choice.delta.content != null &&
108
- choiceSnapshot.message?.role === 'assistant' &&
109
- choiceSnapshot.message?.content) {
110
- this._emit('content', choice.delta.content, choiceSnapshot.message.content);
975
+ const capturedChoice = capturedChoiceFrames.get(choice);
976
+ const choiceSnapshot = completion.choices[capturedChoice?.index ?? choice.index];
977
+ const capturedToolCalls = capturedChoice?.tool_calls ?? [];
978
+ const { delta } = choice;
979
+ const structuredResponse = isParseableResponseFormat(__classPrivateFieldGet(this, _ChatCompletionStream_params, "f")?.response_format);
980
+ const boundedSnapshot = structuredResponse || __classPrivateFieldGet(this, _ChatCompletionStream_hasAutoParseableTool, "f");
981
+ const messageSnapshot = boundedSnapshot
982
+ ? captureStructuredMessageSnapshot(choiceSnapshot)
983
+ : choiceSnapshot.message;
984
+ const refusal = boundedSnapshot
985
+ ? captureStructuredJSONSnapshot(messageSnapshot, 'refusal')
986
+ : messageSnapshot.refusal;
987
+ const parseableContent = !refusal && structuredResponse;
988
+ const messageContent = parseableContent
989
+ ? captureStructuredJSONSnapshot(messageSnapshot, 'content')
990
+ : messageSnapshot.content;
991
+ if (delta?.content != null && messageSnapshot.role === 'assistant' && messageContent) {
992
+ this._emit('content', delta.content, messageContent);
111
993
  this._emit('content.delta', {
112
- delta: choice.delta.content,
113
- snapshot: choiceSnapshot.message.content,
114
- parsed: choiceSnapshot.message.parsed,
994
+ delta: delta.content,
995
+ snapshot: messageContent,
996
+ parsed: messageSnapshot.parsed,
115
997
  });
116
998
  }
117
- if (choice.delta.refusal != null &&
118
- choiceSnapshot.message?.role === 'assistant' &&
119
- choiceSnapshot.message?.refusal) {
999
+ if (delta?.refusal != null && messageSnapshot.role === 'assistant' && refusal) {
120
1000
  this._emit('refusal.delta', {
121
- delta: choice.delta.refusal,
122
- snapshot: choiceSnapshot.message.refusal,
1001
+ delta: delta.refusal,
1002
+ snapshot: refusal,
123
1003
  });
124
1004
  }
125
- if (choice.logprobs?.content != null && choiceSnapshot.message?.role === 'assistant') {
1005
+ if (choice.logprobs?.content != null && messageSnapshot.role === 'assistant') {
126
1006
  this._emit('logprobs.content.delta', {
127
1007
  content: choice.logprobs?.content,
128
1008
  snapshot: choiceSnapshot.logprobs?.content ?? [],
129
1009
  });
130
1010
  }
131
- if (choice.logprobs?.refusal != null && choiceSnapshot.message?.role === 'assistant') {
1011
+ if (choice.logprobs?.refusal != null && messageSnapshot.role === 'assistant') {
132
1012
  this._emit('logprobs.refusal.delta', {
133
1013
  refusal: choice.logprobs?.refusal,
134
1014
  snapshot: choiceSnapshot.logprobs?.refusal ?? [],
@@ -141,7 +1021,7 @@ export class ChatCompletionStream extends AbstractChatCompletionRunner {
141
1021
  __classPrivateFieldGet(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_emitToolCallDoneEvent).call(this, choiceSnapshot, state.current_tool_call_index);
142
1022
  }
143
1023
  }
144
- for (const toolCall of choice.delta.tool_calls ?? []) {
1024
+ for (const toolCall of capturedToolCalls) {
145
1025
  if (state.current_tool_call_index !== toolCall.index) {
146
1026
  __classPrivateFieldGet(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_emitContentDoneEvents).call(this, choiceSnapshot);
147
1027
  // new tool call started, the previous one is done
@@ -151,22 +1031,34 @@ export class ChatCompletionStream extends AbstractChatCompletionRunner {
151
1031
  }
152
1032
  state.current_tool_call_index = toolCall.index;
153
1033
  }
154
- for (const toolCallDelta of choice.delta.tool_calls ?? []) {
155
- const toolCallSnapshot = choiceSnapshot.message.tool_calls?.[toolCallDelta.index];
1034
+ for (const toolCallDelta of capturedToolCalls) {
1035
+ const toolCallSnapshot = messageSnapshot.tool_calls?.[toolCallDelta.index];
156
1036
  if (!toolCallSnapshot?.type) {
157
1037
  continue;
158
1038
  }
159
- if (toolCallSnapshot?.type === 'function') {
1039
+ if (toolCallSnapshot.type === 'function') {
1040
+ const boundIdentity = state.tool_call_identities.get(toolCallDelta.index);
1041
+ let argumentsSnapshot;
1042
+ if (boundIdentity?.parseable) {
1043
+ const capturedArguments = captureStructuredJSONSnapshot(toolCallSnapshot.function, 'arguments');
1044
+ if (typeof capturedArguments !== 'string') {
1045
+ throw new OpenAIError('Chat completion stream contains an unsafe structured JSON snapshot');
1046
+ }
1047
+ argumentsSnapshot = capturedArguments;
1048
+ }
1049
+ else {
1050
+ argumentsSnapshot = toolCallSnapshot.function.arguments;
1051
+ }
160
1052
  this._emit('tool_calls.function.arguments.delta', {
161
- name: toolCallSnapshot.function?.name,
1053
+ name: toolCallSnapshot.function.name,
162
1054
  index: toolCallDelta.index,
163
- arguments: toolCallSnapshot.function.arguments,
1055
+ arguments: argumentsSnapshot,
164
1056
  parsed_arguments: toolCallSnapshot.function.parsed_arguments,
165
- arguments_delta: toolCallDelta.function?.arguments ?? '',
1057
+ arguments_delta: toolCallDelta.arguments_delta,
166
1058
  });
167
1059
  }
168
- else {
169
- assertNever(toolCallSnapshot?.type);
1060
+ else if (toolCallSnapshot.type !== 'custom') {
1061
+ assertNever(toolCallSnapshot);
170
1062
  }
171
1063
  }
172
1064
  }
@@ -176,40 +1068,91 @@ export class ChatCompletionStream extends AbstractChatCompletionRunner {
176
1068
  // we've already fired the done event
177
1069
  return;
178
1070
  }
179
- const toolCallSnapshot = choiceSnapshot.message.tool_calls?.[toolCallIndex];
1071
+ const messageSnapshot = __classPrivateFieldGet(this, _ChatCompletionStream_hasAutoParseableTool, "f")
1072
+ ? captureStructuredMessageSnapshot(choiceSnapshot)
1073
+ : choiceSnapshot.message;
1074
+ const toolCallSnapshot = messageSnapshot.tool_calls?.[toolCallIndex];
180
1075
  if (!toolCallSnapshot) {
181
1076
  throw new Error('no tool call snapshot');
182
1077
  }
1078
+ const boundIdentity = state.tool_call_identities.get(toolCallIndex);
1079
+ if (boundIdentity) {
1080
+ assertBoundToolCallIdentity(toolCallSnapshot, boundIdentity);
1081
+ }
183
1082
  if (!toolCallSnapshot.type) {
184
1083
  throw new Error('tool call snapshot missing `type`');
185
1084
  }
186
1085
  if (toolCallSnapshot.type === 'function') {
1086
+ // SAFETY: The find predicate verifies the function-tool discriminator before matching its name; the cast carries that refinement through find.
187
1087
  const inputTool = __classPrivateFieldGet(this, _ChatCompletionStream_params, "f")?.tools?.find((tool) => isChatCompletionFunctionTool(tool) && tool.function.name === toolCallSnapshot.function.name); // TS doesn't narrow based on isChatCompletionTool
1088
+ // oxlint-disable-next-line anti-slop/no-known-value-widening -- The initial null is replaced with an arbitrary tool-parser result after snapshot validation.
1089
+ let parsedArguments = null;
1090
+ const parseable = isAutoParsableTool(inputTool) || inputTool?.function.strict === true;
1091
+ let argumentsSnapshot;
1092
+ if (parseable) {
1093
+ if (__classPrivateFieldGet(this, _ChatCompletionStream_currentChatCompletionSnapshot, "f")) {
1094
+ __classPrivateFieldGet(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_validateStructuredSnapshots).call(this, __classPrivateFieldGet(this, _ChatCompletionStream_currentChatCompletionSnapshot, "f"));
1095
+ }
1096
+ const capturedArguments = captureStructuredJSONSnapshot(toolCallSnapshot.function, 'arguments');
1097
+ if (typeof capturedArguments !== 'string') {
1098
+ throw new OpenAIError('Chat completion stream contains an unsafe structured JSON snapshot');
1099
+ }
1100
+ argumentsSnapshot = capturedArguments;
1101
+ }
1102
+ else {
1103
+ argumentsSnapshot = toolCallSnapshot.function.arguments;
1104
+ }
1105
+ if (isAutoParsableTool(inputTool)) {
1106
+ parsedArguments = inputTool.$parseRaw(validateStructuredJSONSnapshot(argumentsSnapshot));
1107
+ }
1108
+ else if (inputTool?.function.strict) {
1109
+ parsedArguments = parseResponseFormatContent({ type: 'json_schema', $parseRaw: undefined }, validateStructuredJSONSnapshot(argumentsSnapshot));
1110
+ }
1111
+ if (choiceSnapshot.finish_reason) {
1112
+ state.done_tool_calls.add(toolCallIndex);
1113
+ }
188
1114
  this._emit('tool_calls.function.arguments.done', {
189
1115
  name: toolCallSnapshot.function.name,
190
1116
  index: toolCallIndex,
191
- arguments: toolCallSnapshot.function.arguments,
192
- parsed_arguments: isAutoParsableTool(inputTool) ? inputTool.$parseRaw(toolCallSnapshot.function.arguments)
193
- : inputTool?.function.strict ? JSON.parse(toolCallSnapshot.function.arguments)
194
- : null,
1117
+ arguments: argumentsSnapshot,
1118
+ parsed_arguments: parsedArguments,
195
1119
  });
196
1120
  }
197
- else {
198
- assertNever(toolCallSnapshot.type);
1121
+ else if (toolCallSnapshot.type !== 'custom') {
1122
+ assertNever(toolCallSnapshot);
199
1123
  }
200
1124
  }, _ChatCompletionStream_emitContentDoneEvents = function _ChatCompletionStream_emitContentDoneEvents(choiceSnapshot) {
201
1125
  const state = __classPrivateFieldGet(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_getChoiceEventState).call(this, choiceSnapshot);
202
- if (choiceSnapshot.message.content && !state.content_done) {
1126
+ const structuredResponse = isParseableResponseFormat(__classPrivateFieldGet(this, _ChatCompletionStream_params, "f")?.response_format);
1127
+ const boundedSnapshot = structuredResponse || __classPrivateFieldGet(this, _ChatCompletionStream_hasAutoParseableTool, "f");
1128
+ const messageSnapshot = boundedSnapshot
1129
+ ? captureStructuredMessageSnapshot(choiceSnapshot)
1130
+ : choiceSnapshot.message;
1131
+ const refusal = boundedSnapshot
1132
+ ? captureStructuredJSONSnapshot(messageSnapshot, 'refusal')
1133
+ : messageSnapshot.refusal;
1134
+ const parseableContent = !refusal && structuredResponse;
1135
+ const content = parseableContent
1136
+ ? captureStructuredJSONSnapshot(messageSnapshot, 'content')
1137
+ : messageSnapshot.content;
1138
+ if (content != null &&
1139
+ (content !== '' ||
1140
+ (!refusal && !messageSnapshot.tool_calls?.length && !messageSnapshot.function_call)) &&
1141
+ !state.content_done) {
1142
+ if (parseableContent && __classPrivateFieldGet(this, _ChatCompletionStream_currentChatCompletionSnapshot, "f")) {
1143
+ __classPrivateFieldGet(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_validateStructuredSnapshots).call(this, __classPrivateFieldGet(this, _ChatCompletionStream_currentChatCompletionSnapshot, "f"));
1144
+ }
203
1145
  state.content_done = true;
204
- const responseFormat = __classPrivateFieldGet(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_getAutoParseableResponseFormat).call(this);
205
1146
  this._emit('content.done', {
206
- content: choiceSnapshot.message.content,
207
- parsed: responseFormat ? responseFormat.$parseRaw(choiceSnapshot.message.content) : null,
1147
+ content,
1148
+ parsed: refusal
1149
+ ? null
1150
+ : parseResponseFormatContent(__classPrivateFieldGet(this, _ChatCompletionStream_params, "f")?.response_format, parseableContent ? validateStructuredJSONSnapshot(content) : content),
208
1151
  });
209
1152
  }
210
- if (choiceSnapshot.message.refusal && !state.refusal_done) {
1153
+ if (refusal && !state.refusal_done) {
211
1154
  state.refusal_done = true;
212
- this._emit('refusal.done', { refusal: choiceSnapshot.message.refusal });
1155
+ this._emit('refusal.done', { refusal });
213
1156
  }
214
1157
  if (choiceSnapshot.logprobs?.content && !state.logprobs_content_done) {
215
1158
  state.logprobs_content_done = true;
@@ -219,6 +1162,98 @@ export class ChatCompletionStream extends AbstractChatCompletionRunner {
219
1162
  state.logprobs_refusal_done = true;
220
1163
  this._emit('logprobs.refusal.done', { refusal: choiceSnapshot.logprobs.refusal });
221
1164
  }
1165
+ }, _ChatCompletionStream_validateStructuredSnapshots = function _ChatCompletionStream_validateStructuredSnapshots(snapshot) {
1166
+ const finalJSONBudget = { bytes: 0, fragments: 0, work: 0 };
1167
+ const parseableContent = isParseableResponseFormat(__classPrivateFieldGet(this, _ChatCompletionStream_params, "f")?.response_format);
1168
+ const validatedMessages = new WeakMap();
1169
+ const choices = captureSnapshotArray(snapshot, 'choices', MAX_STREAM_CHOICES, 'choice');
1170
+ if (!choices) {
1171
+ throw new OpenAIError('Chat completion stream contains an unsafe snapshot choice collection');
1172
+ }
1173
+ for (let choiceIndex = 0; choiceIndex < choices.length; choiceIndex += 1) {
1174
+ const choice = captureSnapshotArrayItem(choices, choiceIndex);
1175
+ if (!choice) {
1176
+ continue;
1177
+ }
1178
+ const message = captureStructuredMessageSnapshot(choice);
1179
+ const refusal = captureStructuredJSONSnapshot(message, 'refusal');
1180
+ const content = captureStructuredJSONSnapshot(message, 'content');
1181
+ const validatedTools = new Map();
1182
+ const toolCalls = captureSnapshotArray(message, 'tool_calls', MAX_STREAM_TOOL_CALLS, 'tool-call');
1183
+ validatedMessages.set(choice, Object.freeze({
1184
+ message,
1185
+ content,
1186
+ refusal,
1187
+ toolCallCollection: toolCalls,
1188
+ toolCalls: validatedTools,
1189
+ }));
1190
+ const state = __classPrivateFieldGet(this, _ChatCompletionStream_choiceEventStates, "f")[choice.index];
1191
+ if (parseableContent && !refusal && typeof content === 'string') {
1192
+ validateStructuredJSONSnapshot(content, finalJSONBudget, __classPrivateFieldGet(this, _ChatCompletionStream_partialJSONParseBudget, "f"));
1193
+ }
1194
+ for (const [index, identity] of state?.tool_call_identities ?? []) {
1195
+ const toolCall = toolCalls && captureSnapshotArrayItem(toolCalls, index);
1196
+ if (!toolCall) {
1197
+ throw new OpenAIError('Chat completion stream contains a changed tool call identity');
1198
+ }
1199
+ assertBoundToolCallIdentity(toolCall, identity);
1200
+ }
1201
+ if (!__classPrivateFieldGet(this, _ChatCompletionStream_hasAutoParseableTool, "f")) {
1202
+ continue;
1203
+ }
1204
+ for (let toolCallIndex = 0; toolCallIndex < (toolCalls?.length ?? 0); toolCallIndex += 1) {
1205
+ const toolCall = captureSnapshotArrayItem(toolCalls, toolCallIndex);
1206
+ if (!toolCall) {
1207
+ continue;
1208
+ }
1209
+ const identity = ownFunctionToolIdentity(toolCall);
1210
+ if (!identity) {
1211
+ const type = Object.getOwnPropertyDescriptor(toolCall, 'type');
1212
+ if (type && !('value' in type)) {
1213
+ throw new OpenAIError('Chat completion stream contains an unsafe structured JSON snapshot');
1214
+ }
1215
+ if (type?.value !== 'function') {
1216
+ continue;
1217
+ }
1218
+ const fn = Object.getOwnPropertyDescriptor(toolCall, 'function');
1219
+ if (fn && !('value' in fn)) {
1220
+ throw new OpenAIError('Chat completion stream contains an unsafe structured JSON snapshot');
1221
+ }
1222
+ if (fn && typeof fn.value === 'object' && fn.value !== null) {
1223
+ const name = Object.getOwnPropertyDescriptor(fn.value, 'name');
1224
+ if (name && !('value' in name)) {
1225
+ throw new OpenAIError('Chat completion stream contains an unsafe structured JSON snapshot');
1226
+ }
1227
+ }
1228
+ continue;
1229
+ }
1230
+ if (!shouldParseToolCall(__classPrivateFieldGet(this, _ChatCompletionStream_params, "f"), {
1231
+ type: identity.type,
1232
+ function: { name: identity.name },
1233
+ })) {
1234
+ continue;
1235
+ }
1236
+ const descriptor = Object.getOwnPropertyDescriptor(toolCall, 'function');
1237
+ if (!descriptor || !('value' in descriptor)) {
1238
+ throw new OpenAIError('Chat completion stream contains an unsafe structured JSON snapshot');
1239
+ }
1240
+ // SAFETY: The tool-call function is captured through an own data descriptor; its fields are subsequently checked by the structured snapshot reader.
1241
+ const fn = descriptor.value;
1242
+ const argumentsSnapshot = captureStructuredJSONSnapshot(fn, 'arguments');
1243
+ if (typeof argumentsSnapshot !== 'string') {
1244
+ throw new OpenAIError('Chat completion stream contains an unsafe structured JSON snapshot');
1245
+ }
1246
+ validateStructuredJSONSnapshot(argumentsSnapshot, finalJSONBudget, __classPrivateFieldGet(this, _ChatCompletionStream_partialJSONParseBudget, "f"));
1247
+ validatedTools.set(toolCallIndex, Object.freeze({
1248
+ tool: toolCall,
1249
+ function: fn,
1250
+ type: identity.type,
1251
+ name: identity.name,
1252
+ arguments: argumentsSnapshot,
1253
+ }));
1254
+ }
1255
+ }
1256
+ return validatedMessages;
222
1257
  }, _ChatCompletionStream_endRequest = function _ChatCompletionStream_endRequest() {
223
1258
  if (this.ended) {
224
1259
  throw new OpenAIError(`stream has ended, this shouldn't happen`);
@@ -227,41 +1262,54 @@ export class ChatCompletionStream extends AbstractChatCompletionRunner {
227
1262
  if (!snapshot) {
228
1263
  throw new OpenAIError(`request ended without sending any chunks`);
229
1264
  }
1265
+ const validatedMessages = __classPrivateFieldGet(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_validateStructuredSnapshots).call(this, snapshot);
1266
+ const audioDoneChoiceIndexes = __classPrivateFieldGet(this, _ChatCompletionStream_audioDoneChoiceIndexes, "f");
1267
+ __classPrivateFieldSet(this, _ChatCompletionStream_audioDoneChoiceIndexes, new Set(), "f");
230
1268
  __classPrivateFieldSet(this, _ChatCompletionStream_currentChatCompletionSnapshot, undefined, "f");
231
1269
  __classPrivateFieldSet(this, _ChatCompletionStream_choiceEventStates, [], "f");
232
- return finalizeChatCompletion(snapshot, __classPrivateFieldGet(this, _ChatCompletionStream_params, "f"));
233
- }, _ChatCompletionStream_getAutoParseableResponseFormat = function _ChatCompletionStream_getAutoParseableResponseFormat() {
234
- const responseFormat = __classPrivateFieldGet(this, _ChatCompletionStream_params, "f")?.response_format;
235
- if (isAutoParsableResponseFormat(responseFormat)) {
236
- return responseFormat;
237
- }
238
- return null;
239
- }, _ChatCompletionStream_accumulateChatCompletion = function _ChatCompletionStream_accumulateChatCompletion(chunk) {
240
- var _a, _b, _c, _d;
1270
+ return finalizeChatCompletion(snapshot, __classPrivateFieldGet(this, _ChatCompletionStream_params, "f"), audioDoneChoiceIndexes, validatedMessages);
1271
+ }, _ChatCompletionStream_accumulateChatCompletion = function _ChatCompletionStream_accumulateChatCompletion(chunk, capturedChoiceFrames) {
1272
+ var _a, _b, _c, _d, _e;
241
1273
  let snapshot = __classPrivateFieldGet(this, _ChatCompletionStream_currentChatCompletionSnapshot, "f");
242
- const { choices, ...rest } = chunk;
1274
+ const { choices, obfuscation: _obfuscation, ...rest } = chunk;
243
1275
  if (!snapshot) {
244
- snapshot = __classPrivateFieldSet(this, _ChatCompletionStream_currentChatCompletionSnapshot, {
1276
+ const newSnapshot = {
245
1277
  ...rest,
246
1278
  choices: [],
247
- }, "f");
1279
+ };
1280
+ __classPrivateFieldSet(this, _ChatCompletionStream_currentChatCompletionSnapshot, newSnapshot, "f");
1281
+ snapshot = newSnapshot;
248
1282
  }
249
- else {
250
- Object.assign(snapshot, rest);
1283
+ else if (chunk.id) {
1284
+ assignOwnProperties(snapshot, rest);
251
1285
  }
252
- for (const { delta, finish_reason, index, logprobs = null, ...other } of chunk.choices) {
1286
+ const requestedChoiceCount = __classPrivateFieldGet(this, _ChatCompletionStream_params, "f")?.n;
1287
+ const maxChoices = typeof requestedChoiceCount === 'number' &&
1288
+ Number.isSafeInteger(requestedChoiceCount) &&
1289
+ requestedChoiceCount > 0
1290
+ ? Math.min(requestedChoiceCount, MAX_STREAM_CHOICES)
1291
+ : MAX_STREAM_CHOICES;
1292
+ for (const chunkChoice of chunk.choices) {
1293
+ const { delta, finish_reason, index, logprobs = null, ...other } = chunkChoice;
1294
+ const capturedToolCalls = [];
1295
+ capturedChoiceFrames.set(chunkChoice, Object.freeze({ index, tool_calls: capturedToolCalls }));
1296
+ if (!Number.isSafeInteger(index) || index < 0 || index >= maxChoices) {
1297
+ throw new OpenAIError(`Chat completion stream contains an invalid choice index: ${index}`);
1298
+ }
253
1299
  let choice = snapshot.choices[index];
254
1300
  if (!choice) {
255
- choice = snapshot.choices[index] = { finish_reason, index, message: {}, logprobs, ...other };
1301
+ const newChoice = { finish_reason, index, message: {}, logprobs: null, ...other };
1302
+ snapshot.choices[index] = newChoice;
1303
+ choice = newChoice;
1304
+ }
1305
+ if (isParseableResponseFormat(__classPrivateFieldGet(this, _ChatCompletionStream_params, "f")?.response_format) || __classPrivateFieldGet(this, _ChatCompletionStream_hasAutoParseableTool, "f")) {
1306
+ captureStructuredJSONSnapshot(captureStructuredMessageSnapshot(choice), 'refusal');
256
1307
  }
257
1308
  if (logprobs) {
258
- if (!choice.logprobs) {
259
- choice.logprobs = Object.assign({}, logprobs);
260
- }
261
- else {
1309
+ if (choice.logprobs) {
262
1310
  const { content, refusal, ...rest } = logprobs;
263
1311
  assertIsEmpty(rest);
264
- Object.assign(choice.logprobs, rest);
1312
+ assignOwnProperties(choice.logprobs, rest);
265
1313
  if (content) {
266
1314
  (_a = choice.logprobs).content ?? (_a.content = []);
267
1315
  choice.logprobs.content.push(...content);
@@ -271,10 +1319,19 @@ export class ChatCompletionStream extends AbstractChatCompletionRunner {
271
1319
  choice.logprobs.refusal.push(...refusal);
272
1320
  }
273
1321
  }
1322
+ else {
1323
+ choice.logprobs = { ...logprobs };
1324
+ if (logprobs.content) {
1325
+ choice.logprobs.content = [...logprobs.content];
1326
+ }
1327
+ if (logprobs.refusal) {
1328
+ choice.logprobs.refusal = [...logprobs.refusal];
1329
+ }
1330
+ }
274
1331
  }
275
1332
  if (finish_reason) {
276
1333
  choice.finish_reason = finish_reason;
277
- if (__classPrivateFieldGet(this, _ChatCompletionStream_params, "f") && hasAutoParseableInput(__classPrivateFieldGet(this, _ChatCompletionStream_params, "f"))) {
1334
+ if (__classPrivateFieldGet(this, _ChatCompletionStream_params, "f") && (__classPrivateFieldGet(this, _ChatCompletionStream_rejectsUnfinishedTurns, "f") || hasAutoParseableInput(__classPrivateFieldGet(this, _ChatCompletionStream_params, "f")))) {
278
1335
  if (finish_reason === 'length') {
279
1336
  throw new LengthFinishReasonError();
280
1337
  }
@@ -283,126 +1340,248 @@ export class ChatCompletionStream extends AbstractChatCompletionRunner {
283
1340
  }
284
1341
  }
285
1342
  }
286
- Object.assign(choice, other);
287
- if (!delta)
288
- continue; // Shouldn't happen; just in case.
289
- const { content, refusal, function_call, role, tool_calls, ...rest } = delta;
1343
+ assignOwnProperties(choice, other);
1344
+ if (!delta) {
1345
+ Object.freeze(capturedToolCalls);
1346
+ continue;
1347
+ } // Shouldn't happen; just in case.
1348
+ __classPrivateFieldGet(this, _ChatCompletionStream_audioDoneChoiceIndexes, "f").delete(index);
1349
+ // SAFETY: Streaming audio fields arrive incrementally even though the generated delta type omits them; each present field is merged below.
1350
+ const { audio, content, refusal, function_call, role, ...capturedDeltaFields } = delta;
1351
+ const { tool_calls: capturedToolCallDelta, ...rest } = capturedDeltaFields;
1352
+ const tool_calls = hasOwn(capturedDeltaFields, 'tool_calls') ? capturedToolCallDelta : delta.tool_calls;
290
1353
  assertIsEmpty(rest);
291
- Object.assign(choice.message, rest);
1354
+ assignOwnProperties(choice.message, rest);
1355
+ if (audio?.expires_at != null &&
1356
+ audio.id == null &&
1357
+ audio.data == null &&
1358
+ audio.transcript == null &&
1359
+ content == null &&
1360
+ refusal == null &&
1361
+ function_call == null &&
1362
+ role == null &&
1363
+ tool_calls == null &&
1364
+ Object.keys(rest).length === 0) {
1365
+ __classPrivateFieldGet(this, _ChatCompletionStream_audioDoneChoiceIndexes, "f").add(index);
1366
+ }
292
1367
  if (refusal) {
293
1368
  choice.message.refusal = (choice.message.refusal || '') + refusal;
294
1369
  }
295
- if (role)
1370
+ if (role) {
296
1371
  choice.message.role = role;
297
- if (function_call) {
298
- if (!choice.message.function_call) {
299
- choice.message.function_call = function_call;
1372
+ }
1373
+ if (audio) {
1374
+ const audioSnapshot = ((_c = choice.message).audio ?? (_c.audio = {}));
1375
+ if (audio.id != null) {
1376
+ audioSnapshot.id = audio.id;
300
1377
  }
301
- else {
302
- if (function_call.name)
1378
+ if (audio.data != null) {
1379
+ audioSnapshot.data = (audioSnapshot.data ?? '') + audio.data;
1380
+ }
1381
+ if (audio.transcript != null) {
1382
+ audioSnapshot.transcript = (audioSnapshot.transcript ?? '') + audio.transcript;
1383
+ }
1384
+ if (audio.expires_at != null) {
1385
+ audioSnapshot.expires_at = audio.expires_at;
1386
+ }
1387
+ }
1388
+ if (function_call) {
1389
+ if (choice.message.function_call) {
1390
+ if (function_call.name) {
303
1391
  choice.message.function_call.name = function_call.name;
1392
+ }
304
1393
  if (function_call.arguments) {
305
- (_c = choice.message.function_call).arguments ?? (_c.arguments = '');
1394
+ (_d = choice.message.function_call).arguments ?? (_d.arguments = '');
306
1395
  choice.message.function_call.arguments += function_call.arguments;
307
1396
  }
308
1397
  }
1398
+ else {
1399
+ choice.message.function_call = function_call;
1400
+ }
309
1401
  }
310
- if (content) {
311
- choice.message.content = (choice.message.content || '') + content;
312
- if (!choice.message.refusal && __classPrivateFieldGet(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_getAutoParseableResponseFormat).call(this)) {
313
- choice.message.parsed = partialParse(choice.message.content);
1402
+ if (content != null) {
1403
+ if (!choice.message.refusal && isParseableResponseFormat(__classPrivateFieldGet(this, _ChatCompletionStream_params, "f")?.response_format)) {
1404
+ const eventState = __classPrivateFieldGet(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_getChoiceEventState).call(this, choice);
1405
+ const parseState = (eventState.content_parse_state ?? (eventState.content_parse_state = createPartialJSONParseState()));
1406
+ const shouldParse = recordPartialJSONFragment(parseState, __classPrivateFieldGet(this, _ChatCompletionStream_partialJSONParseBudget, "f"), content);
1407
+ choice.message.content = (captureStructuredJSONSnapshot(choice.message, 'content') || '') + content;
1408
+ // The partial parser does not accept whitespace-only input. Once output
1409
+ // grows, coalesce prefix reparses while preserving every raw snapshot.
1410
+ if (!parseState.has_non_whitespace) {
1411
+ choice.message.parsed = null;
1412
+ }
1413
+ else if (shouldParse && reservePartialJSONParse(parseState, __classPrivateFieldGet(this, _ChatCompletionStream_partialJSONParseBudget, "f"))) {
1414
+ __classPrivateFieldGet(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_validateStructuredSnapshots).call(this, snapshot);
1415
+ choice.message.parsed = parseStructuredStreamingJSON(validateStructuredJSONSnapshot(choice.message.content));
1416
+ }
1417
+ else if (content.length > 0) {
1418
+ choice.message.parsed = null;
1419
+ }
1420
+ }
1421
+ else {
1422
+ choice.message.content = (choice.message.content || '') + content;
314
1423
  }
315
1424
  }
316
1425
  if (tool_calls) {
317
- if (!choice.message.tool_calls)
318
- choice.message.tool_calls = [];
319
- for (const { index, id, type, function: fn, ...rest } of tool_calls) {
320
- const tool_call = ((_d = choice.message.tool_calls)[index] ?? (_d[index] = {}));
321
- Object.assign(tool_call, rest);
322
- if (id)
1426
+ // Tool calls are built up across chunks, so while the stream is in progress the
1427
+ // entries are only partially filled in; they match `ChatCompletionSnapshot.Choice.Message.ToolCall`
1428
+ // once every delta for them has been accumulated.
1429
+ // SAFETY: This SDK-owned collection holds partial tool calls during accumulation; finalization checks required fields before exposing completed calls.
1430
+ const toolCallSnapshots = ((_e = choice.message).tool_calls ?? (_e.tool_calls = []));
1431
+ for (const toolCallDelta of tool_calls) {
1432
+ const { index, id, type, function: fn, custom, ...rest } = toolCallDelta;
1433
+ if (!Number.isSafeInteger(index) || index < 0 || index >= MAX_STREAM_TOOL_CALLS) {
1434
+ throw new OpenAIError(`Chat completion stream contains an invalid tool call index: ${index}`);
1435
+ }
1436
+ let argumentsDelta = '';
1437
+ const tool_call = (toolCallSnapshots[index] ?? (toolCallSnapshots[index] = {}));
1438
+ const functionName = fn?.name;
1439
+ const eventState = __classPrivateFieldGet(this, _ChatCompletionStream_hasAutoParseableTool, "f") ? __classPrivateFieldGet(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_getChoiceEventState).call(this, choice) : undefined;
1440
+ let boundIdentity = eventState?.tool_call_identities.get(index);
1441
+ if (boundIdentity) {
1442
+ assertBoundToolCallIdentity(tool_call, boundIdentity);
1443
+ if ((type !== undefined && type !== boundIdentity.type) ||
1444
+ (functionName !== undefined && functionName !== boundIdentity.name)) {
1445
+ throw new OpenAIError('Chat completion stream contains a changed tool call identity');
1446
+ }
1447
+ }
1448
+ assignOwnProperties(tool_call, rest);
1449
+ if (id) {
323
1450
  tool_call.id = id;
324
- if (type)
1451
+ }
1452
+ if (type) {
325
1453
  tool_call.type = type;
326
- if (fn)
327
- tool_call.function ?? (tool_call.function = { name: fn.name ?? '', arguments: '' });
328
- if (fn?.name)
329
- tool_call.function.name = fn.name;
330
- if (fn?.arguments) {
331
- tool_call.function.arguments += fn.arguments;
332
- if (shouldParseToolCall(__classPrivateFieldGet(this, _ChatCompletionStream_params, "f"), tool_call)) {
333
- tool_call.function.parsed_arguments = partialParse(tool_call.function.arguments);
1454
+ }
1455
+ if (custom) {
1456
+ const customSnapshot = (tool_call.custom ?? (tool_call.custom = { name: custom.name ?? '', input: '' }));
1457
+ if (custom.name) {
1458
+ customSnapshot.name = custom.name;
1459
+ }
1460
+ if (custom.input) {
1461
+ customSnapshot.input += custom.input;
334
1462
  }
335
1463
  }
1464
+ if (fn) {
1465
+ const functionSnapshot = (tool_call.function ?? (tool_call.function = { name: functionName ?? '', arguments: '' }));
1466
+ if (functionName) {
1467
+ functionSnapshot.name = functionName;
1468
+ }
1469
+ if (eventState && !boundIdentity) {
1470
+ const identity = ownFunctionToolIdentity(tool_call);
1471
+ const configuredTool = identity &&
1472
+ __classPrivateFieldGet(this, _ChatCompletionStream_params, "f")?.tools?.find((tool) => isChatCompletionFunctionTool(tool) && tool.function.name === identity.name);
1473
+ if (identity) {
1474
+ boundIdentity = {
1475
+ ...identity,
1476
+ parseable: configuredTool !== undefined &&
1477
+ shouldParseToolCall(__classPrivateFieldGet(this, _ChatCompletionStream_params, "f"), {
1478
+ type: identity.type,
1479
+ function: { name: identity.name },
1480
+ }),
1481
+ };
1482
+ eventState.tool_call_identities.set(index, boundIdentity);
1483
+ if (!boundIdentity.parseable) {
1484
+ const provisionalState = eventState.tool_call_parse_states.get(index);
1485
+ if (provisionalState) {
1486
+ __classPrivateFieldGet(this, _ChatCompletionStream_partialJSONParseBudget, "f").bytes -= provisionalState.bytes;
1487
+ __classPrivateFieldGet(this, _ChatCompletionStream_partialJSONParseBudget, "f").fragments -= provisionalState.fragments;
1488
+ __classPrivateFieldGet(this, _ChatCompletionStream_partialJSONParseBudget, "f").work -= provisionalState.work;
1489
+ eventState.tool_call_parse_states.delete(index);
1490
+ }
1491
+ }
1492
+ }
1493
+ }
1494
+ const argumentFragment = fn.arguments;
1495
+ if (argumentFragment != null) {
1496
+ argumentsDelta = argumentFragment;
1497
+ if (eventState && boundIdentity?.parseable !== false) {
1498
+ let parseState = eventState.tool_call_parse_states.get(index);
1499
+ if (!parseState) {
1500
+ parseState = createPartialJSONParseState();
1501
+ eventState.tool_call_parse_states.set(index, parseState);
1502
+ }
1503
+ const shouldParse = recordPartialJSONFragment(parseState, __classPrivateFieldGet(this, _ChatCompletionStream_partialJSONParseBudget, "f"), argumentFragment);
1504
+ const previousArguments = captureStructuredJSONSnapshot(functionSnapshot, 'arguments');
1505
+ if (typeof previousArguments !== 'string') {
1506
+ throw new OpenAIError('Chat completion stream contains an unsafe structured JSON snapshot');
1507
+ }
1508
+ functionSnapshot.arguments = previousArguments + argumentFragment;
1509
+ if (shouldParse &&
1510
+ boundIdentity?.parseable === true &&
1511
+ reservePartialJSONParse(parseState, __classPrivateFieldGet(this, _ChatCompletionStream_partialJSONParseBudget, "f"))) {
1512
+ __classPrivateFieldGet(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_validateStructuredSnapshots).call(this, snapshot);
1513
+ functionSnapshot.parsed_arguments = parseStructuredStreamingJSON(validateStructuredJSONSnapshot(functionSnapshot.arguments));
1514
+ }
1515
+ else if (argumentFragment.length > 0 && hasOwn(functionSnapshot, 'parsed_arguments')) {
1516
+ functionSnapshot.parsed_arguments = undefined;
1517
+ }
1518
+ }
1519
+ else {
1520
+ functionSnapshot.arguments += argumentFragment;
1521
+ }
1522
+ }
1523
+ }
1524
+ capturedToolCalls.push(Object.freeze({ index, arguments_delta: argumentsDelta }));
336
1525
  }
337
1526
  }
1527
+ Object.freeze(capturedToolCalls);
338
1528
  }
339
1529
  return snapshot;
340
1530
  }, Symbol.asyncIterator)]() {
341
- const pushQueue = [];
342
- const readQueue = [];
343
- let done = false;
344
- this.on('chunk', (chunk) => {
345
- const reader = readQueue.shift();
346
- if (reader) {
347
- reader.resolve(chunk);
348
- }
349
- else {
350
- pushQueue.push(chunk);
351
- }
352
- });
353
- this.on('end', () => {
354
- done = true;
355
- for (const reader of readQueue) {
356
- reader.resolve(undefined);
357
- }
358
- readQueue.length = 0;
359
- });
360
- this.on('abort', (err) => {
361
- done = true;
362
- for (const reader of readQueue) {
363
- reader.reject(err);
364
- }
365
- readQueue.length = 0;
366
- });
367
- this.on('error', (err) => {
368
- done = true;
369
- for (const reader of readQueue) {
370
- reader.reject(err);
371
- }
372
- readQueue.length = 0;
373
- });
374
- return {
375
- next: async () => {
376
- if (!pushQueue.length) {
377
- if (done) {
378
- return { value: undefined, done: true };
379
- }
380
- return new Promise((resolve, reject) => readQueue.push({ resolve, reject })).then((chunk) => (chunk ? { value: chunk, done: false } : { value: undefined, done: true }));
381
- }
382
- const chunk = pushQueue.shift();
383
- return { value: chunk, done: false };
384
- },
385
- return: async () => {
386
- this.abort();
387
- return { value: undefined, done: true };
388
- },
389
- };
1531
+ return this._createIterator((push) => {
1532
+ const onChunk = (chunk) => push(chunk);
1533
+ this.on('chunk', onChunk);
1534
+ return () => this.off('chunk', onChunk);
1535
+ }, { onReturn: () => this.abort() });
390
1536
  }
1537
+ /** Serializes raw completion chunks into a readable stream for transfer to another runtime. */
391
1538
  toReadableStream() {
392
1539
  const stream = new Stream(this[Symbol.asyncIterator].bind(this), this.controller);
393
1540
  return stream.toReadableStream();
394
1541
  }
395
1542
  }
396
- function finalizeChatCompletion(snapshot, params) {
1543
+ function finalizeChatCompletion(snapshot, params, audioDoneChoiceIndexes, validatedMessages) {
397
1544
  const { id, choices, created, model, system_fingerprint, ...rest } = snapshot;
398
1545
  const completion = {
399
1546
  ...rest,
400
1547
  id,
401
- choices: choices.map(({ message, finish_reason, index, logprobs, ...choiceRest }) => {
402
- if (!finish_reason) {
1548
+ choices: mapCapturedSnapshotArray(choices, MAX_STREAM_CHOICES, 'choice', (choice) => {
1549
+ const validated = validatedMessages.get(choice);
1550
+ if (!validated) {
1551
+ throw new OpenAIError('Chat completion stream contains an unsafe structured JSON snapshot');
1552
+ }
1553
+ const stableChoice = new Proxy(choice, {
1554
+ get(target, property, receiver) {
1555
+ // oxlint-disable-next-line anti-slop/no-reflect-get -- Proxy forwarding must preserve arbitrary keys and the original accessor receiver.
1556
+ return property === 'message' ? validated.message : Reflect.get(target, property, receiver);
1557
+ },
1558
+ });
1559
+ const { message: sourceMessage, finish_reason, index, logprobs, ...choiceRest } = stableChoice;
1560
+ const message = new Proxy(sourceMessage, {
1561
+ get(target, property, receiver) {
1562
+ if (property === 'content') {
1563
+ return validated.content;
1564
+ }
1565
+ if (property === 'refusal') {
1566
+ return validated.refusal;
1567
+ }
1568
+ if (property === 'tool_calls') {
1569
+ return validated.toolCallCollection;
1570
+ }
1571
+ // oxlint-disable-next-line anti-slop/no-reflect-get -- Proxy forwarding must preserve arbitrary keys and the original accessor receiver.
1572
+ return Reflect.get(target, property, receiver);
1573
+ },
1574
+ });
1575
+ const { content = null, function_call, tool_calls, audio, ...messageRest } = message;
1576
+ // Audio streams can end with an expires_at-only chunk after the
1577
+ // generated audio, without a separate finish_reason.
1578
+ const finishReason = finish_reason ?? (audioDoneChoiceIndexes.has(index) && isCompleteAudio(audio) ? 'stop' : null);
1579
+ if (!finishReason) {
403
1580
  throw new OpenAIError(`missing finish_reason for choice ${index}`);
404
1581
  }
405
- const { content = null, function_call, tool_calls, ...messageRest } = message;
1582
+ // SAFETY: The completed API response contract supplies the audio fields; this preserves the existing pass-through behavior at finalization.
1583
+ const audioResponse = audio ? { audio: audio } : {};
1584
+ // SAFETY: The API completion contract uses assistant role; retaining the wire role preserves existing behavior without adding runtime rejection.
406
1585
  const role = message.role; // this is what we expect; in theory it could be different which would make our types a slight lie but would be fine.
407
1586
  if (!role) {
408
1587
  throw new OpenAIError(`missing role for choice ${index}`);
@@ -418,12 +1597,13 @@ function finalizeChatCompletion(snapshot, params) {
418
1597
  return {
419
1598
  ...choiceRest,
420
1599
  message: {
1600
+ ...audioResponse,
421
1601
  content,
422
1602
  function_call: { arguments: args, name },
423
1603
  role,
424
1604
  refusal: message.refusal ?? null,
425
1605
  },
426
- finish_reason,
1606
+ finish_reason: finishReason,
427
1607
  index,
428
1608
  logprobs,
429
1609
  };
@@ -432,37 +1612,94 @@ function finalizeChatCompletion(snapshot, params) {
432
1612
  return {
433
1613
  ...choiceRest,
434
1614
  index,
435
- finish_reason,
1615
+ finish_reason: finishReason,
436
1616
  logprobs,
437
1617
  message: {
438
1618
  ...messageRest,
1619
+ ...audioResponse,
439
1620
  role,
440
1621
  content,
441
1622
  refusal: message.refusal ?? null,
442
- tool_calls: tool_calls.map((tool_call, i) => {
443
- const { function: fn, type, id, ...toolRest } = tool_call;
444
- const { arguments: args, name, ...fnRest } = fn || {};
445
- if (id == null) {
446
- throw new OpenAIError(`missing choices[${index}].tool_calls[${i}].id\n${str(snapshot)}`);
1623
+ tool_calls: mapCapturedSnapshotArray(tool_calls, MAX_STREAM_TOOL_CALLS, 'tool-call', (tool_call, i) => {
1624
+ const captured = validated.toolCalls.get(i);
1625
+ if (!captured) {
1626
+ const identity = ownFunctionToolIdentity(tool_call);
1627
+ if (identity &&
1628
+ shouldParseToolCall(params, {
1629
+ type: identity.type,
1630
+ function: { name: identity.name },
1631
+ })) {
1632
+ throw new OpenAIError('Chat completion stream contains an unsafe structured JSON snapshot');
1633
+ }
447
1634
  }
448
- if (type == null) {
449
- throw new OpenAIError(`missing choices[${index}].tool_calls[${i}].type\n${str(snapshot)}`);
1635
+ if (captured && captured.tool !== tool_call) {
1636
+ throw new OpenAIError('Chat completion stream contains a changed tool call identity');
450
1637
  }
1638
+ const stableFunction = captured &&
1639
+ new Proxy(captured.function, {
1640
+ get(target, property, receiver) {
1641
+ if (property === 'arguments') {
1642
+ return captured.arguments;
1643
+ }
1644
+ if (property === 'name') {
1645
+ return captured.name;
1646
+ }
1647
+ // oxlint-disable-next-line anti-slop/no-reflect-get -- Proxy forwarding must preserve arbitrary keys and the original accessor receiver.
1648
+ return Reflect.get(target, property, receiver);
1649
+ },
1650
+ });
1651
+ const stableTool = captured && stableFunction
1652
+ ? new Proxy(tool_call, {
1653
+ get(target, property, receiver) {
1654
+ if (property === 'type') {
1655
+ return captured.type;
1656
+ }
1657
+ if (property === 'function') {
1658
+ return stableFunction;
1659
+ }
1660
+ // oxlint-disable-next-line anti-slop/no-reflect-get -- Proxy forwarding must preserve arbitrary keys and the original accessor receiver.
1661
+ return Reflect.get(target, property, receiver);
1662
+ },
1663
+ })
1664
+ : tool_call;
1665
+ if (stableTool.type == null) {
1666
+ throw new OpenAIError(`missing choices[${index}].tool_calls[${i}].type`);
1667
+ }
1668
+ if (stableTool.type === 'custom') {
1669
+ const { custom, type, id, ...toolRest } = stableTool;
1670
+ const { input = '', name, ...customRest } = custom || {};
1671
+ if (name == null) {
1672
+ throw new OpenAIError(`missing choices[${index}].tool_calls[${i}].custom.name`);
1673
+ }
1674
+ return {
1675
+ ...toolRest,
1676
+ id: id || `call_${uuid4()}`,
1677
+ type,
1678
+ custom: { ...customRest, name, input },
1679
+ };
1680
+ }
1681
+ const { function: fn, type, id, ...toolRest } = stableTool;
1682
+ const { arguments: args, name, ...fnRest } = fn || {};
451
1683
  if (name == null) {
452
- throw new OpenAIError(`missing choices[${index}].tool_calls[${i}].function.name\n${str(snapshot)}`);
1684
+ throw new OpenAIError(`missing choices[${index}].tool_calls[${i}].function.name`);
453
1685
  }
454
1686
  if (args == null) {
455
- throw new OpenAIError(`missing choices[${index}].tool_calls[${i}].function.arguments\n${str(snapshot)}`);
1687
+ throw new OpenAIError(`missing choices[${index}].tool_calls[${i}].function.arguments`);
456
1688
  }
457
- return { ...toolRest, id, type, function: { ...fnRest, name, arguments: args } };
1689
+ return {
1690
+ ...toolRest,
1691
+ id: id || `call_${uuid4()}`,
1692
+ type,
1693
+ function: { ...fnRest, name, arguments: args },
1694
+ };
458
1695
  }),
459
1696
  },
460
1697
  };
461
1698
  }
462
1699
  return {
463
1700
  ...choiceRest,
464
- message: { ...messageRest, content, role, refusal: message.refusal ?? null },
465
- finish_reason,
1701
+ message: { ...messageRest, ...audioResponse, content, role, refusal: message.refusal ?? null },
1702
+ finish_reason: finishReason,
466
1703
  index,
467
1704
  logprobs,
468
1705
  };
@@ -470,12 +1707,13 @@ function finalizeChatCompletion(snapshot, params) {
470
1707
  created,
471
1708
  model,
472
1709
  object: 'chat.completion',
1710
+ // Spread creates an own data property without invoking inherited setters or changing the object prototype.
473
1711
  ...(system_fingerprint ? { system_fingerprint } : {}),
474
1712
  };
475
1713
  return maybeParseChatCompletion(completion, params);
476
1714
  }
477
- function str(x) {
478
- return JSON.stringify(x);
1715
+ function isCompleteAudio(audio) {
1716
+ return audio?.id != null && audio.data != null && audio.transcript != null && audio.expires_at != null;
479
1717
  }
480
1718
  /**
481
1719
  * Ensures the given argument is an empty object, useful for
@@ -483,7 +1721,9 @@ function str(x) {
483
1721
  * destructured.
484
1722
  */
485
1723
  function assertIsEmpty(obj) {
486
- return;
1724
+ void obj;
1725
+ }
1726
+ function assertNever(_x) {
1727
+ return _x;
487
1728
  }
488
- function assertNever(_x) { }
489
1729
  //# sourceMappingURL=ChatCompletionStream.mjs.map