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