@songtonyli/dsh-cli 0.1.55 → 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 (1379) 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/@bufbuild/protobuf/dist/commonjs/codegenv1/symbols.js +17 -1
  6. package/node_modules/@bufbuild/protobuf/dist/commonjs/codegenv2/embed.js +1 -1
  7. package/node_modules/@bufbuild/protobuf/dist/commonjs/codegenv2/file.js +1 -1
  8. package/node_modules/@bufbuild/protobuf/dist/commonjs/codegenv2/symbols.js +60 -41
  9. package/node_modules/@bufbuild/protobuf/dist/commonjs/create.js +2 -1
  10. package/node_modules/@bufbuild/protobuf/dist/commonjs/from-binary.js +9 -6
  11. package/node_modules/@bufbuild/protobuf/dist/commonjs/from-json.js +30 -12
  12. package/node_modules/@bufbuild/protobuf/dist/commonjs/reflect/message.js +3 -2
  13. package/node_modules/@bufbuild/protobuf/dist/commonjs/reflect/reflect-check.js +3 -4
  14. package/node_modules/@bufbuild/protobuf/dist/commonjs/reflect/reflect.js +2 -2
  15. package/node_modules/@bufbuild/protobuf/dist/commonjs/reflect/unsafe.js +31 -0
  16. package/node_modules/@bufbuild/protobuf/dist/commonjs/registry.js +53 -5
  17. package/node_modules/@bufbuild/protobuf/dist/commonjs/to-json.js +27 -5
  18. package/node_modules/@bufbuild/protobuf/dist/commonjs/wire/binary-encoding.js +5 -3
  19. package/node_modules/@bufbuild/protobuf/dist/commonjs/wkt/any.js +1 -1
  20. package/node_modules/@bufbuild/protobuf/dist/commonjs/wkt/duration.js +1 -1
  21. package/node_modules/@bufbuild/protobuf/dist/commonjs/wkt/{gen/google → google}/protobuf/any_pb.js +2 -2
  22. package/node_modules/@bufbuild/protobuf/dist/commonjs/wkt/{gen/google → google}/protobuf/api_pb.js +2 -2
  23. package/node_modules/@bufbuild/protobuf/dist/commonjs/wkt/google/protobuf/c_sharp_features_pb.js +33 -0
  24. package/node_modules/@bufbuild/protobuf/dist/commonjs/wkt/{gen/google → google}/protobuf/compiler/plugin_pb.js +3 -3
  25. package/node_modules/@bufbuild/protobuf/dist/commonjs/wkt/{gen/google → google}/protobuf/cpp_features_pb.js +34 -6
  26. package/node_modules/@bufbuild/protobuf/dist/commonjs/wkt/google/protobuf/cpp_file_options_pb.js +33 -0
  27. package/node_modules/@bufbuild/protobuf/dist/commonjs/wkt/google/protobuf/cpp_options_pb.js +22 -0
  28. package/node_modules/@bufbuild/protobuf/dist/commonjs/wkt/{gen/google → google}/protobuf/descriptor_pb.js +49 -6
  29. package/node_modules/@bufbuild/protobuf/dist/commonjs/wkt/{gen/google → google}/protobuf/duration_pb.js +2 -2
  30. package/node_modules/@bufbuild/protobuf/dist/commonjs/wkt/{gen/google → google}/protobuf/empty_pb.js +2 -2
  31. package/node_modules/@bufbuild/protobuf/dist/commonjs/wkt/{gen/google → google}/protobuf/field_mask_pb.js +2 -2
  32. package/node_modules/@bufbuild/protobuf/dist/commonjs/wkt/{gen/google → google}/protobuf/go_features_pb.js +4 -4
  33. package/node_modules/@bufbuild/protobuf/dist/commonjs/wkt/{gen/google → google}/protobuf/java_features_pb.js +4 -4
  34. package/node_modules/@bufbuild/protobuf/dist/commonjs/wkt/google/protobuf/json_enumvalue_options_pb.js +33 -0
  35. package/node_modules/@bufbuild/protobuf/dist/commonjs/wkt/google/protobuf/json_options_pb.js +22 -0
  36. package/node_modules/@bufbuild/protobuf/dist/commonjs/wkt/{gen/google → google}/protobuf/source_context_pb.js +2 -2
  37. package/node_modules/@bufbuild/protobuf/dist/commonjs/wkt/{gen/google → google}/protobuf/struct_pb.js +11 -6
  38. package/node_modules/@bufbuild/protobuf/dist/commonjs/wkt/{gen/google → google}/protobuf/timestamp_pb.js +2 -2
  39. package/node_modules/@bufbuild/protobuf/dist/commonjs/wkt/{gen/google → google}/protobuf/type_pb.js +3 -3
  40. package/node_modules/@bufbuild/protobuf/dist/commonjs/wkt/{gen/google → google}/protobuf/wrappers_pb.js +2 -2
  41. package/node_modules/@bufbuild/protobuf/dist/commonjs/wkt/index.js +15 -15
  42. package/node_modules/@bufbuild/protobuf/dist/commonjs/wkt/timestamp.js +1 -1
  43. package/node_modules/@bufbuild/protobuf/dist/esm/codegenv1/symbols.js +18 -2
  44. package/node_modules/@bufbuild/protobuf/dist/esm/codegenv2/embed.js +1 -1
  45. package/node_modules/@bufbuild/protobuf/dist/esm/codegenv2/file.js +1 -1
  46. package/node_modules/@bufbuild/protobuf/dist/esm/codegenv2/symbols.js +60 -41
  47. package/node_modules/@bufbuild/protobuf/dist/esm/create.js +2 -1
  48. package/node_modules/@bufbuild/protobuf/dist/esm/from-binary.js +10 -7
  49. package/node_modules/@bufbuild/protobuf/dist/esm/from-json.js +31 -13
  50. package/node_modules/@bufbuild/protobuf/dist/esm/reflect/message.js +3 -2
  51. package/node_modules/@bufbuild/protobuf/dist/esm/reflect/reflect-check.js +4 -5
  52. package/node_modules/@bufbuild/protobuf/dist/esm/reflect/reflect.js +3 -3
  53. package/node_modules/@bufbuild/protobuf/dist/esm/reflect/unsafe.js +29 -0
  54. package/node_modules/@bufbuild/protobuf/dist/esm/registry.js +53 -5
  55. package/node_modules/@bufbuild/protobuf/dist/esm/to-json.js +28 -6
  56. package/node_modules/@bufbuild/protobuf/dist/esm/wire/binary-encoding.js +5 -3
  57. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/any.js +1 -1
  58. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/duration.js +1 -1
  59. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/{gen/google → google}/protobuf/any_pb.js +2 -2
  60. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/{gen/google → google}/protobuf/api_pb.js +2 -2
  61. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/google/protobuf/c_sharp_features_pb.js +30 -0
  62. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/{gen/google → google}/protobuf/compiler/plugin_pb.js +3 -3
  63. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/{gen/google → google}/protobuf/cpp_features_pb.js +33 -5
  64. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/google/protobuf/cpp_file_options_pb.js +30 -0
  65. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/google/protobuf/cpp_options_pb.js +19 -0
  66. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/{gen/google → google}/protobuf/descriptor_pb.js +47 -4
  67. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/{gen/google → google}/protobuf/duration_pb.js +2 -2
  68. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/{gen/google → google}/protobuf/empty_pb.js +2 -2
  69. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/{gen/google → google}/protobuf/field_mask_pb.js +2 -2
  70. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/{gen/google → google}/protobuf/go_features_pb.js +4 -4
  71. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/{gen/google → google}/protobuf/java_features_pb.js +4 -4
  72. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/google/protobuf/json_enumvalue_options_pb.js +30 -0
  73. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/google/protobuf/json_options_pb.js +19 -0
  74. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/{gen/google → google}/protobuf/source_context_pb.js +2 -2
  75. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/{gen/google → google}/protobuf/struct_pb.js +11 -6
  76. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/{gen/google → google}/protobuf/timestamp_pb.js +2 -2
  77. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/{gen/google → google}/protobuf/type_pb.js +3 -3
  78. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/{gen/google → google}/protobuf/wrappers_pb.js +2 -2
  79. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/index.js +15 -15
  80. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/timestamp.js +1 -1
  81. package/node_modules/@bufbuild/protobuf/package.json +236 -13
  82. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/package.json +2 -2
  83. package/node_modules/@deepseek-ai/dsh-client-ui-sidebar/lib/client.js +1 -1
  84. package/node_modules/@deepseek-ai/dsh-client-ui-slots/package.json +2 -2
  85. package/node_modules/@deepseek-ai/dsh-llm-pi-ai/README.i18n.yaml +2 -2
  86. package/node_modules/@deepseek-ai/dsh-llm-pi-ai/README.md +1 -1
  87. package/node_modules/@deepseek-ai/dsh-llm-pi-ai/README.zh.md +1 -1
  88. package/node_modules/@deepseek-ai/dsh-llm-pi-ai/lib/index.js +1 -182
  89. package/node_modules/@deepseek-ai/dsh-llm-pi-ai/package.json +1 -1
  90. package/node_modules/@deepseek-ai/dsh-tui-app/README.i18n.yaml +8 -8
  91. package/node_modules/@deepseek-ai/dsh-tui-app/README.md +15 -4
  92. package/node_modules/@deepseek-ai/dsh-tui-app/README.zh.md +15 -4
  93. package/node_modules/@deepseek-ai/dsh-tui-app/lib/index.js +692 -43
  94. package/node_modules/@earendil-works/pi-ai/README.md +207 -27
  95. package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js +6 -0
  96. package/node_modules/@earendil-works/pi-ai/dist/api/azure-openai-responses.js +6 -5
  97. package/node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.js +1 -0
  98. package/node_modules/@earendil-works/pi-ai/dist/api/cloudflare-workers-ai-system-one.js +43 -0
  99. package/node_modules/@earendil-works/pi-ai/dist/api/cloudflare-workers-ai-system-one.lazy.js +4 -0
  100. package/node_modules/@earendil-works/pi-ai/dist/api/cloudflare.js +2 -0
  101. package/node_modules/@earendil-works/pi-ai/dist/api/google-generative-ai.js +1 -0
  102. package/node_modules/@earendil-works/pi-ai/dist/api/google-vertex.js +1 -0
  103. package/node_modules/@earendil-works/pi-ai/dist/api/llama-cpp-classify.js +365 -0
  104. package/node_modules/@earendil-works/pi-ai/dist/api/llama-cpp-classify.lazy.js +4 -0
  105. package/node_modules/@earendil-works/pi-ai/dist/api/mistral-conversations.js +18 -17
  106. package/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.js +20 -4
  107. package/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.js +4 -4
  108. package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses-shared.js +14 -0
  109. package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses.js +26 -9
  110. package/node_modules/@earendil-works/pi-ai/dist/api/openrouter-images.js +1 -0
  111. package/node_modules/@earendil-works/pi-ai/dist/api/pi-messages.js +1 -0
  112. package/node_modules/@earendil-works/pi-ai/dist/api/simple-options.js +2 -4
  113. package/node_modules/@earendil-works/pi-ai/dist/api/system-one-shared.js +183 -0
  114. package/node_modules/@earendil-works/pi-ai/dist/api/typesafe-system-one.js +19 -0
  115. package/node_modules/@earendil-works/pi-ai/dist/api/typesafe-system-one.lazy.js +4 -0
  116. package/node_modules/@earendil-works/pi-ai/dist/auth/helpers.js +1 -1
  117. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/anthropic.js +19 -128
  118. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/callback-server.js +146 -0
  119. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/load.js +5 -0
  120. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/openai-chatgpt.js +266 -0
  121. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/openai-codex.js +20 -124
  122. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/openrouter.js +19 -138
  123. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/radius.js +21 -89
  124. package/node_modules/@earendil-works/pi-ai/dist/auth/resolve.js +3 -19
  125. package/node_modules/@earendil-works/pi-ai/dist/bun-oauth.js +2 -0
  126. package/node_modules/@earendil-works/pi-ai/dist/cli.js +3 -1
  127. package/node_modules/@earendil-works/pi-ai/dist/env-api-keys.js +1 -0
  128. package/node_modules/@earendil-works/pi-ai/dist/image-models.js +14 -13
  129. package/node_modules/@earendil-works/pi-ai/dist/images.js +5 -0
  130. package/node_modules/@earendil-works/pi-ai/dist/index.js +0 -1
  131. package/node_modules/@earendil-works/pi-ai/dist/model-catalog.js +14 -2
  132. package/node_modules/@earendil-works/pi-ai/dist/models.generated.js +131 -41
  133. package/node_modules/@earendil-works/pi-ai/dist/models.js +157 -30
  134. package/node_modules/@earendil-works/pi-ai/dist/providers/all.js +25 -21
  135. package/node_modules/@earendil-works/pi-ai/dist/providers/amazon-bedrock.models.js +4 -2
  136. package/node_modules/@earendil-works/pi-ai/dist/providers/ant-ling.models.js +4 -2
  137. package/node_modules/@earendil-works/pi-ai/dist/providers/anthropic.models.js +4 -2
  138. package/node_modules/@earendil-works/pi-ai/dist/providers/azure-openai-responses.models.js +4 -2
  139. package/node_modules/@earendil-works/pi-ai/dist/providers/baseten.models.js +4 -2
  140. package/node_modules/@earendil-works/pi-ai/dist/providers/cerebras.models.js +4 -2
  141. package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-ai-gateway.models.js +4 -2
  142. package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-stream.js +6 -0
  143. package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-workers-ai.js +10 -3
  144. package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-workers-ai.models.js +4 -2
  145. package/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
  146. package/node_modules/@earendil-works/pi-ai/dist/providers/data/amazon-bedrock.json +1 -1
  147. package/node_modules/@earendil-works/pi-ai/dist/providers/data/ant-ling.json +1 -1
  148. package/node_modules/@earendil-works/pi-ai/dist/providers/data/anthropic.json +1 -1
  149. package/node_modules/@earendil-works/pi-ai/dist/providers/data/azure-openai-responses.json +1 -1
  150. package/node_modules/@earendil-works/pi-ai/dist/providers/data/baseten.json +1 -1
  151. package/node_modules/@earendil-works/pi-ai/dist/providers/data/cerebras.json +1 -1
  152. package/node_modules/@earendil-works/pi-ai/dist/providers/data/cloudflare-ai-gateway.json +1 -1
  153. package/node_modules/@earendil-works/pi-ai/dist/providers/data/cloudflare-workers-ai.json +1 -1
  154. package/node_modules/@earendil-works/pi-ai/dist/providers/data/deepseek.json +1 -1
  155. package/node_modules/@earendil-works/pi-ai/dist/providers/data/fireworks.json +1 -1
  156. package/node_modules/@earendil-works/pi-ai/dist/providers/data/github-copilot.json +1 -1
  157. package/node_modules/@earendil-works/pi-ai/dist/providers/data/google-vertex.json +1 -1
  158. package/node_modules/@earendil-works/pi-ai/dist/providers/data/google.json +1 -1
  159. package/node_modules/@earendil-works/pi-ai/dist/providers/data/groq.json +1 -1
  160. package/node_modules/@earendil-works/pi-ai/dist/providers/data/huggingface.json +1 -1
  161. package/node_modules/@earendil-works/pi-ai/dist/providers/data/kimi-coding.json +1 -1
  162. package/node_modules/@earendil-works/pi-ai/dist/providers/data/meta.json +1 -1
  163. package/node_modules/@earendil-works/pi-ai/dist/providers/data/minimax-cn.json +1 -1
  164. package/node_modules/@earendil-works/pi-ai/dist/providers/data/minimax.json +1 -1
  165. package/node_modules/@earendil-works/pi-ai/dist/providers/data/mistral.json +1 -1
  166. package/node_modules/@earendil-works/pi-ai/dist/providers/data/moonshotai-cn.json +1 -1
  167. package/node_modules/@earendil-works/pi-ai/dist/providers/data/moonshotai.json +1 -1
  168. package/node_modules/@earendil-works/pi-ai/dist/providers/data/nvidia.json +1 -1
  169. package/node_modules/@earendil-works/pi-ai/dist/providers/data/openai-codex.json +1 -1
  170. package/node_modules/@earendil-works/pi-ai/dist/providers/data/openai.json +1 -1
  171. package/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode-go.json +1 -1
  172. package/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode.json +1 -1
  173. package/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
  174. package/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan-cn.json +1 -1
  175. package/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan-individual.json +1 -1
  176. package/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan.json +1 -1
  177. package/node_modules/@earendil-works/pi-ai/dist/providers/data/radius.json +1 -1
  178. package/node_modules/@earendil-works/pi-ai/dist/providers/data/together.json +1 -1
  179. package/node_modules/@earendil-works/pi-ai/dist/providers/data/typesafe.json +1 -0
  180. package/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
  181. package/node_modules/@earendil-works/pi-ai/dist/providers/data/xai.json +1 -1
  182. package/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi-token-plan-ams.json +1 -1
  183. package/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi-token-plan-cn.json +1 -1
  184. package/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi-token-plan-sgp.json +1 -1
  185. package/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi.json +1 -1
  186. package/node_modules/@earendil-works/pi-ai/dist/providers/data/zai-coding-cn.json +1 -1
  187. package/node_modules/@earendil-works/pi-ai/dist/providers/data/zai.json +1 -1
  188. package/node_modules/@earendil-works/pi-ai/dist/providers/deepseek.models.js +4 -2
  189. package/node_modules/@earendil-works/pi-ai/dist/providers/fireworks.models.js +4 -2
  190. package/node_modules/@earendil-works/pi-ai/dist/providers/github-copilot.models.js +4 -2
  191. package/node_modules/@earendil-works/pi-ai/dist/providers/google-vertex.models.js +4 -2
  192. package/node_modules/@earendil-works/pi-ai/dist/providers/google.models.js +4 -2
  193. package/node_modules/@earendil-works/pi-ai/dist/providers/groq.models.js +4 -2
  194. package/node_modules/@earendil-works/pi-ai/dist/providers/huggingface.models.js +4 -2
  195. package/node_modules/@earendil-works/pi-ai/dist/providers/kimi-coding.models.js +4 -2
  196. package/node_modules/@earendil-works/pi-ai/dist/providers/meta.models.js +4 -2
  197. package/node_modules/@earendil-works/pi-ai/dist/providers/minimax-cn.models.js +4 -2
  198. package/node_modules/@earendil-works/pi-ai/dist/providers/minimax.models.js +4 -2
  199. package/node_modules/@earendil-works/pi-ai/dist/providers/mistral.models.js +4 -2
  200. package/node_modules/@earendil-works/pi-ai/dist/providers/moonshotai-cn.models.js +4 -2
  201. package/node_modules/@earendil-works/pi-ai/dist/providers/moonshotai.models.js +4 -2
  202. package/node_modules/@earendil-works/pi-ai/dist/providers/nvidia.models.js +4 -2
  203. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-codex.js +1 -1
  204. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-codex.models.js +4 -2
  205. package/node_modules/@earendil-works/pi-ai/dist/providers/openai.js +11 -2
  206. package/node_modules/@earendil-works/pi-ai/dist/providers/openai.models.js +4 -2
  207. package/node_modules/@earendil-works/pi-ai/dist/providers/opencode-go.models.js +4 -2
  208. package/node_modules/@earendil-works/pi-ai/dist/providers/opencode.js +5 -2
  209. package/node_modules/@earendil-works/pi-ai/dist/providers/opencode.models.js +4 -2
  210. package/node_modules/@earendil-works/pi-ai/dist/providers/openrouter.js +11 -2
  211. package/node_modules/@earendil-works/pi-ai/dist/providers/openrouter.models.js +4 -2
  212. package/node_modules/@earendil-works/pi-ai/dist/providers/qwen-token-plan-cn.models.js +4 -2
  213. package/node_modules/@earendil-works/pi-ai/dist/providers/qwen-token-plan-individual.models.js +4 -2
  214. package/node_modules/@earendil-works/pi-ai/dist/providers/qwen-token-plan.models.js +4 -2
  215. package/node_modules/@earendil-works/pi-ai/dist/providers/radius.models.js +4 -2
  216. package/node_modules/@earendil-works/pi-ai/dist/providers/together.models.js +4 -2
  217. package/node_modules/@earendil-works/pi-ai/dist/providers/typesafe.js +18 -0
  218. package/node_modules/@earendil-works/pi-ai/dist/providers/typesafe.models.js +8 -0
  219. package/node_modules/@earendil-works/pi-ai/dist/providers/vercel-ai-gateway.js +5 -2
  220. package/node_modules/@earendil-works/pi-ai/dist/providers/vercel-ai-gateway.models.js +4 -2
  221. package/node_modules/@earendil-works/pi-ai/dist/providers/xai.models.js +4 -2
  222. package/node_modules/@earendil-works/pi-ai/dist/providers/xiaomi-token-plan-ams.models.js +4 -2
  223. package/node_modules/@earendil-works/pi-ai/dist/providers/xiaomi-token-plan-cn.models.js +4 -2
  224. package/node_modules/@earendil-works/pi-ai/dist/providers/xiaomi-token-plan-sgp.models.js +4 -2
  225. package/node_modules/@earendil-works/pi-ai/dist/providers/xiaomi.models.js +4 -2
  226. package/node_modules/@earendil-works/pi-ai/dist/providers/zai-coding-cn.models.js +4 -2
  227. package/node_modules/@earendil-works/pi-ai/dist/providers/zai.models.js +4 -2
  228. package/node_modules/@earendil-works/pi-ai/dist/utils/headers.js +10 -8
  229. package/node_modules/@earendil-works/pi-ai/dist/utils/model-operations.js +47 -0
  230. package/node_modules/@earendil-works/pi-ai/dist/utils/models-error.js +19 -0
  231. package/node_modules/@earendil-works/pi-ai/dist/utils/retry.js +7 -0
  232. package/node_modules/@earendil-works/pi-ai/package.json +4 -4
  233. package/node_modules/@earendil-works/pi-telemetry/package.json +2 -2
  234. package/node_modules/openai/CHANGELOG.md +1089 -1
  235. package/node_modules/openai/README.md +201 -102
  236. package/node_modules/openai/_vendor/partial-json-parser/parser.js +55 -38
  237. package/node_modules/openai/_vendor/partial-json-parser/parser.mjs +55 -38
  238. package/node_modules/openai/_vendor/zod-to-json-schema/Options.js +11 -2
  239. package/node_modules/openai/_vendor/zod-to-json-schema/Options.mjs +11 -2
  240. package/node_modules/openai/_vendor/zod-to-json-schema/Refs.js +4 -4
  241. package/node_modules/openai/_vendor/zod-to-json-schema/Refs.mjs +4 -4
  242. package/node_modules/openai/_vendor/zod-to-json-schema/errorMessages.js +2 -1
  243. package/node_modules/openai/_vendor/zod-to-json-schema/errorMessages.mjs +2 -1
  244. package/node_modules/openai/_vendor/zod-to-json-schema/index.js +1 -1
  245. package/node_modules/openai/_vendor/zod-to-json-schema/index.mjs +1 -1
  246. package/node_modules/openai/_vendor/zod-to-json-schema/parseDef.js +139 -54
  247. package/node_modules/openai/_vendor/zod-to-json-schema/parseDef.mjs +139 -54
  248. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/array.js +1 -1
  249. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/array.mjs +1 -1
  250. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/bigint.js +10 -4
  251. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/bigint.mjs +10 -4
  252. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/branded.js +2 -2
  253. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/branded.mjs +2 -2
  254. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/catch.js +1 -3
  255. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/catch.mjs +1 -3
  256. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/date.js +10 -5
  257. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/date.mjs +10 -5
  258. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/default.js +2 -2
  259. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/default.mjs +2 -2
  260. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/intersection.js +6 -5
  261. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/intersection.mjs +6 -5
  262. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/literal.js +5 -0
  263. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/literal.mjs +5 -0
  264. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/nativeEnum.js +7 -9
  265. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/nativeEnum.mjs +7 -9
  266. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/null.js +3 -2
  267. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/null.mjs +3 -2
  268. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/nullable.js +8 -3
  269. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/nullable.mjs +8 -3
  270. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/number.js +12 -5
  271. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/number.mjs +12 -5
  272. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/object.js +43 -38
  273. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/object.mjs +43 -38
  274. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/optional.js +11 -12
  275. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/optional.mjs +11 -12
  276. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/pipeline.js +3 -3
  277. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/pipeline.mjs +3 -3
  278. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/promise.js +2 -2
  279. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/promise.mjs +2 -2
  280. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/readonly.js +1 -3
  281. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/readonly.mjs +1 -3
  282. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/record.js +7 -5
  283. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/record.mjs +7 -5
  284. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/string.js +57 -34
  285. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/string.mjs +57 -34
  286. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/tuple.js +24 -19
  287. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/tuple.mjs +24 -19
  288. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/union.js +46 -24
  289. package/node_modules/openai/_vendor/zod-to-json-schema/parsers/union.mjs +46 -24
  290. package/node_modules/openai/_vendor/zod-to-json-schema/util.js +7 -5
  291. package/node_modules/openai/_vendor/zod-to-json-schema/util.mjs +7 -5
  292. package/node_modules/openai/_vendor/zod-to-json-schema/zodToJsonSchema.js +110 -38
  293. package/node_modules/openai/_vendor/zod-to-json-schema/zodToJsonSchema.mjs +110 -38
  294. package/node_modules/openai/auth/subject-token-providers.js +235 -10
  295. package/node_modules/openai/auth/subject-token-providers.mjs +235 -10
  296. package/node_modules/openai/auth/workload-identity-auth.js +185 -24
  297. package/node_modules/openai/auth/workload-identity-auth.mjs +186 -25
  298. package/node_modules/openai/auth/x509-transport.js +273 -0
  299. package/node_modules/openai/auth/x509-transport.mjs +268 -0
  300. package/node_modules/openai/azure.js +74 -21
  301. package/node_modules/openai/azure.mjs +75 -22
  302. package/node_modules/openai/bedrock.js +174 -0
  303. package/node_modules/openai/bedrock.mjs +169 -0
  304. package/node_modules/openai/beta/realtime/internal-base.js +71 -10
  305. package/node_modules/openai/beta/realtime/internal-base.mjs +70 -10
  306. package/node_modules/openai/beta/realtime/websocket.js +180 -33
  307. package/node_modules/openai/beta/realtime/websocket.mjs +181 -34
  308. package/node_modules/openai/beta/realtime/ws.js +93 -14
  309. package/node_modules/openai/beta/realtime/ws.mjs +94 -15
  310. package/node_modules/openai/client.js +745 -99
  311. package/node_modules/openai/client.mjs +747 -101
  312. package/node_modules/openai/core/EventEmitter.js +127 -16
  313. package/node_modules/openai/core/EventEmitter.mjs +128 -17
  314. package/node_modules/openai/core/api-promise.js +0 -1
  315. package/node_modules/openai/core/api-promise.mjs +0 -1
  316. package/node_modules/openai/core/error.js +5 -5
  317. package/node_modules/openai/core/error.mjs +5 -5
  318. package/node_modules/openai/core/pagination.js +33 -3
  319. package/node_modules/openai/core/pagination.mjs +31 -2
  320. package/node_modules/openai/core/resource.js +0 -1
  321. package/node_modules/openai/core/resource.mjs +0 -1
  322. package/node_modules/openai/core/streaming.js +453 -88
  323. package/node_modules/openai/core/streaming.mjs +454 -89
  324. package/node_modules/openai/core/uploads.js +3 -1
  325. package/node_modules/openai/core/uploads.mjs +1 -0
  326. package/node_modules/openai/helpers/audio.js +198 -28
  327. package/node_modules/openai/helpers/audio.mjs +199 -29
  328. package/node_modules/openai/helpers/live.js +6 -0
  329. package/node_modules/openai/helpers/live.mjs +2 -0
  330. package/node_modules/openai/helpers/standard-schema.js +393 -0
  331. package/node_modules/openai/helpers/standard-schema.mjs +387 -0
  332. package/node_modules/openai/helpers/zod-v3-strict-schema.js +408 -0
  333. package/node_modules/openai/helpers/zod-v3-strict-schema.mjs +404 -0
  334. package/node_modules/openai/helpers/zod.js +221 -24
  335. package/node_modules/openai/helpers/zod.mjs +222 -26
  336. package/node_modules/openai/index.js +8 -7
  337. package/node_modules/openai/index.mjs +2 -2
  338. package/node_modules/openai/internal/assistant-stream-delta.js +316 -0
  339. package/node_modules/openai/internal/assistant-stream-delta.mjs +308 -0
  340. package/node_modules/openai/internal/auth/x509-api-origin.js +28 -0
  341. package/node_modules/openai/internal/auth/x509-api-origin.mjs +24 -0
  342. package/node_modules/openai/internal/auth/x509-credential-options.js +125 -0
  343. package/node_modules/openai/internal/auth/x509-credential-options.mjs +121 -0
  344. package/node_modules/openai/internal/auth/x509-token-exchange.js +248 -0
  345. package/node_modules/openai/internal/auth/x509-token-exchange.mjs +245 -0
  346. package/node_modules/openai/internal/auth/x509-transport-capability.js +171 -0
  347. package/node_modules/openai/internal/auth/x509-transport-capability.mjs +166 -0
  348. package/node_modules/openai/internal/auth/x509-transport-registry.js +53 -0
  349. package/node_modules/openai/internal/auth/x509-transport-registry.mjs +48 -0
  350. package/node_modules/openai/internal/auth/x509-transport-state-browser.js +35 -0
  351. package/node_modules/openai/internal/auth/x509-transport-state-browser.mjs +32 -0
  352. package/node_modules/openai/internal/auth/x509-transport-state.cjs +35 -0
  353. package/node_modules/openai/internal/auth/x509-transport-state.js +36 -0
  354. package/node_modules/openai/internal/auth/x509-transport-state.mjs +20 -0
  355. package/node_modules/openai/internal/auth/x509-workload-identity-auth.js +787 -0
  356. package/node_modules/openai/internal/auth/x509-workload-identity-auth.mjs +778 -0
  357. package/node_modules/openai/internal/bedrock.js +438 -0
  358. package/node_modules/openai/internal/bedrock.mjs +424 -0
  359. package/node_modules/openai/internal/builtin-types.js +0 -1
  360. package/node_modules/openai/internal/builtin-types.mjs +0 -1
  361. package/node_modules/openai/internal/data-residency.js +34 -0
  362. package/node_modules/openai/internal/data-residency.mjs +30 -0
  363. package/node_modules/openai/internal/decoders/line.js +140 -54
  364. package/node_modules/openai/internal/decoders/line.mjs +141 -55
  365. package/node_modules/openai/internal/detect-platform.js +3 -4
  366. package/node_modules/openai/internal/detect-platform.mjs +3 -4
  367. package/node_modules/openai/internal/errors.js +3 -3
  368. package/node_modules/openai/internal/errors.mjs +3 -3
  369. package/node_modules/openai/internal/headers.js +11 -9
  370. package/node_modules/openai/internal/headers.mjs +11 -9
  371. package/node_modules/openai/internal/multipart-encoding.js +51 -0
  372. package/node_modules/openai/internal/multipart-encoding.mjs +48 -0
  373. package/node_modules/openai/internal/parse.js +35 -11
  374. package/node_modules/openai/internal/parse.mjs +35 -11
  375. package/node_modules/openai/internal/provider.js +50 -0
  376. package/node_modules/openai/internal/provider.mjs +46 -0
  377. package/node_modules/openai/internal/qs/formats.js +1 -2
  378. package/node_modules/openai/internal/qs/formats.mjs +1 -1
  379. package/node_modules/openai/internal/qs/stringify.js +60 -51
  380. package/node_modules/openai/internal/qs/stringify.mjs +60 -51
  381. package/node_modules/openai/internal/qs/utils.js +368 -50
  382. package/node_modules/openai/internal/qs/utils.mjs +368 -50
  383. package/node_modules/openai/internal/realtime-credentials.js +23 -0
  384. package/node_modules/openai/internal/realtime-credentials.mjs +19 -0
  385. package/node_modules/openai/internal/request-options.js +43 -2
  386. package/node_modules/openai/internal/request-options.mjs +42 -2
  387. package/node_modules/openai/internal/responses/canonical-output-text.js +123 -0
  388. package/node_modules/openai/internal/responses/canonical-output-text.mjs +115 -0
  389. package/node_modules/openai/internal/responses/output-text-index.js +77 -0
  390. package/node_modules/openai/internal/responses/output-text-index.mjs +73 -0
  391. package/node_modules/openai/internal/responses/response-accumulator.js +942 -0
  392. package/node_modules/openai/internal/responses/response-accumulator.mjs +938 -0
  393. package/node_modules/openai/internal/shim-types.js +6 -1
  394. package/node_modules/openai/internal/shim-types.mjs +6 -1
  395. package/node_modules/openai/internal/shims.js +6 -1
  396. package/node_modules/openai/internal/shims.mjs +6 -1
  397. package/node_modules/openai/internal/stream-utils.js +35 -7
  398. package/node_modules/openai/internal/stream-utils.mjs +35 -7
  399. package/node_modules/openai/internal/to-file.js +47 -24
  400. package/node_modules/openai/internal/to-file.mjs +47 -24
  401. package/node_modules/openai/internal/tslib.js +6 -0
  402. package/node_modules/openai/internal/tslib.mjs +6 -1
  403. package/node_modules/openai/internal/types.js +0 -1
  404. package/node_modules/openai/internal/types.mjs +0 -1
  405. package/node_modules/openai/internal/uploads.js +377 -43
  406. package/node_modules/openai/internal/uploads.mjs +376 -44
  407. package/node_modules/openai/internal/utils/abort.js +94 -0
  408. package/node_modules/openai/internal/utils/abort.mjs +90 -0
  409. package/node_modules/openai/internal/utils/base64.js +3 -1
  410. package/node_modules/openai/internal/utils/base64.mjs +3 -1
  411. package/node_modules/openai/internal/utils/bytes.js +5 -0
  412. package/node_modules/openai/internal/utils/bytes.mjs +5 -0
  413. package/node_modules/openai/internal/utils/env.js +9 -5
  414. package/node_modules/openai/internal/utils/env.mjs +9 -5
  415. package/node_modules/openai/internal/utils/log.js +73 -11
  416. package/node_modules/openai/internal/utils/log.mjs +70 -11
  417. package/node_modules/openai/internal/utils/path.js +50 -30
  418. package/node_modules/openai/internal/utils/path.mjs +50 -30
  419. package/node_modules/openai/internal/utils/query.js +0 -1
  420. package/node_modules/openai/internal/utils/query.mjs +0 -1
  421. package/node_modules/openai/internal/utils/sleep.js +51 -2
  422. package/node_modules/openai/internal/utils/sleep.mjs +51 -2
  423. package/node_modules/openai/internal/utils/uuid.js +0 -1
  424. package/node_modules/openai/internal/utils/uuid.mjs +0 -1
  425. package/node_modules/openai/internal/utils/values.js +0 -1
  426. package/node_modules/openai/internal/utils/values.mjs +0 -1
  427. package/node_modules/openai/internal/utils.js +0 -1
  428. package/node_modules/openai/internal/utils.mjs +0 -1
  429. package/node_modules/openai/internal/ws-adapter-browser.js +66 -21
  430. package/node_modules/openai/internal/ws-adapter-browser.mjs +66 -21
  431. package/node_modules/openai/internal/ws-adapter-node.js +90 -24
  432. package/node_modules/openai/internal/ws-adapter-node.mjs +90 -24
  433. package/node_modules/openai/internal/ws-adapter.js +4 -0
  434. package/node_modules/openai/internal/ws-adapter.mjs +4 -0
  435. package/node_modules/openai/internal/ws.js +193 -48
  436. package/node_modules/openai/internal/ws.mjs +188 -49
  437. package/node_modules/openai/lib/AbstractChatCompletionRunner.js +254 -72
  438. package/node_modules/openai/lib/AbstractChatCompletionRunner.mjs +256 -74
  439. package/node_modules/openai/lib/AssistantStream.js +430 -259
  440. package/node_modules/openai/lib/AssistantStream.mjs +432 -261
  441. package/node_modules/openai/lib/ChatCompletionRunner.js +12 -5
  442. package/node_modules/openai/lib/ChatCompletionRunner.mjs +13 -6
  443. package/node_modules/openai/lib/ChatCompletionStream.js +1430 -189
  444. package/node_modules/openai/lib/ChatCompletionStream.mjs +1433 -193
  445. package/node_modules/openai/lib/ChatCompletionStreamingRunner.js +40 -2
  446. package/node_modules/openai/lib/ChatCompletionStreamingRunner.mjs +41 -3
  447. package/node_modules/openai/lib/EventEmitter.js +124 -16
  448. package/node_modules/openai/lib/EventEmitter.mjs +125 -17
  449. package/node_modules/openai/lib/EventStream.js +1533 -55
  450. package/node_modules/openai/lib/EventStream.mjs +1534 -56
  451. package/node_modules/openai/lib/ResponsesParser.js +68 -29
  452. package/node_modules/openai/lib/ResponsesParser.mjs +69 -30
  453. package/node_modules/openai/lib/RunnableFunction.js +3 -0
  454. package/node_modules/openai/lib/RunnableFunction.mjs +3 -0
  455. package/node_modules/openai/lib/Util.js +7 -4
  456. package/node_modules/openai/lib/Util.mjs +7 -4
  457. package/node_modules/openai/lib/agents/agent-session-stream.js +274 -0
  458. package/node_modules/openai/lib/agents/agent-session-stream.mjs +270 -0
  459. package/node_modules/openai/lib/agents/output-text.js +8 -0
  460. package/node_modules/openai/lib/agents/output-text.mjs +5 -0
  461. package/node_modules/openai/lib/agents/turn-state.js +62 -0
  462. package/node_modules/openai/lib/agents/turn-state.mjs +58 -0
  463. package/node_modules/openai/lib/assistant-run-polling.js +17 -0
  464. package/node_modules/openai/lib/assistant-run-polling.mjs +14 -0
  465. package/node_modules/openai/lib/chatCompletionUtils.js +5 -6
  466. package/node_modules/openai/lib/chatCompletionUtils.mjs +5 -6
  467. package/node_modules/openai/lib/embeddings.js +58 -0
  468. package/node_modules/openai/lib/embeddings.mjs +55 -0
  469. package/node_modules/openai/lib/file-processing.js +31 -0
  470. package/node_modules/openai/lib/file-processing.mjs +28 -0
  471. package/node_modules/openai/lib/live/transcript-grouper.js +229 -0
  472. package/node_modules/openai/lib/live/transcript-grouper.mjs +225 -0
  473. package/node_modules/openai/lib/live/transcript-grouping.js +309 -0
  474. package/node_modules/openai/lib/live/transcript-grouping.mjs +305 -0
  475. package/node_modules/openai/lib/live/webrtc.js +16 -0
  476. package/node_modules/openai/lib/live/webrtc.mjs +10 -0
  477. package/node_modules/openai/lib/parser.js +142 -42
  478. package/node_modules/openai/lib/parser.mjs +140 -42
  479. package/node_modules/openai/lib/polling.js +131 -0
  480. package/node_modules/openai/lib/polling.mjs +128 -0
  481. package/node_modules/openai/lib/realtime/webrtc.js +16 -0
  482. package/node_modules/openai/lib/realtime/webrtc.mjs +10 -0
  483. package/node_modules/openai/lib/responses/ResponseAccumulator.js +15 -0
  484. package/node_modules/openai/lib/responses/ResponseAccumulator.mjs +12 -0
  485. package/node_modules/openai/lib/responses/ResponseInputItems.js +139 -0
  486. package/node_modules/openai/lib/responses/ResponseInputItems.mjs +135 -0
  487. package/node_modules/openai/lib/responses/ResponseStream.js +85 -159
  488. package/node_modules/openai/lib/responses/ResponseStream.mjs +86 -160
  489. package/node_modules/openai/lib/responses/responses-websocket-lane.js +314 -0
  490. package/node_modules/openai/lib/responses/responses-websocket-lane.mjs +309 -0
  491. package/node_modules/openai/lib/responses/responses-websocket-session.js +268 -0
  492. package/node_modules/openai/lib/responses/responses-websocket-session.mjs +263 -0
  493. package/node_modules/openai/lib/transform.js +1608 -82
  494. package/node_modules/openai/lib/transform.mjs +1602 -82
  495. package/node_modules/openai/lib/vector-store-polling.js +24 -0
  496. package/node_modules/openai/lib/vector-store-polling.mjs +20 -0
  497. package/node_modules/openai/lib/vector-store-upload.js +41 -0
  498. package/node_modules/openai/lib/vector-store-upload.mjs +38 -0
  499. package/node_modules/openai/lib/webhook-signature.js +125 -0
  500. package/node_modules/openai/lib/webhook-signature.mjs +121 -0
  501. package/node_modules/openai/lib/webrtc/connection.js +233 -0
  502. package/node_modules/openai/lib/webrtc/connection.mjs +229 -0
  503. package/node_modules/openai/lib/webrtc/data-channel.js +133 -0
  504. package/node_modules/openai/lib/webrtc/data-channel.mjs +129 -0
  505. package/node_modules/openai/lib/webrtc/errors.js +18 -0
  506. package/node_modules/openai/lib/webrtc/errors.mjs +14 -0
  507. package/node_modules/openai/lib/webrtc/subscriptions.js +64 -0
  508. package/node_modules/openai/lib/webrtc/subscriptions.mjs +60 -0
  509. package/node_modules/openai/lib/webrtc/types.js +3 -0
  510. package/node_modules/openai/lib/webrtc/types.mjs +2 -0
  511. package/node_modules/openai/live/webrtc.js +8 -0
  512. package/node_modules/openai/live/webrtc.mjs +2 -0
  513. package/node_modules/openai/package.json +71 -11
  514. package/node_modules/openai/providers/bedrock/aws.js +211 -0
  515. package/node_modules/openai/providers/bedrock/aws.mjs +207 -0
  516. package/node_modules/openai/providers/bedrock.js +43 -0
  517. package/node_modules/openai/providers/bedrock.mjs +39 -0
  518. package/node_modules/openai/realtime/internal-base.js +118 -11
  519. package/node_modules/openai/realtime/internal-base.mjs +116 -11
  520. package/node_modules/openai/realtime/webrtc.js +8 -0
  521. package/node_modules/openai/realtime/webrtc.mjs +2 -0
  522. package/node_modules/openai/realtime/websocket.js +174 -39
  523. package/node_modules/openai/realtime/websocket.mjs +175 -40
  524. package/node_modules/openai/realtime/ws.js +86 -18
  525. package/node_modules/openai/realtime/ws.mjs +87 -19
  526. package/node_modules/openai/resources/admin/admin.js +1 -1
  527. package/node_modules/openai/resources/admin/admin.mjs +1 -1
  528. package/node_modules/openai/resources/admin/index.js +1 -1
  529. package/node_modules/openai/resources/admin/index.mjs +1 -1
  530. package/node_modules/openai/resources/admin/organization/admin-api-keys.js +1 -1
  531. package/node_modules/openai/resources/admin/organization/admin-api-keys.mjs +1 -1
  532. package/node_modules/openai/resources/admin/organization/audit-logs.js +1 -1
  533. package/node_modules/openai/resources/admin/organization/audit-logs.mjs +1 -1
  534. package/node_modules/openai/resources/admin/organization/certificates.js +1 -1
  535. package/node_modules/openai/resources/admin/organization/certificates.mjs +1 -1
  536. package/node_modules/openai/resources/admin/organization/data-retention.js +1 -1
  537. package/node_modules/openai/resources/admin/organization/data-retention.mjs +1 -1
  538. package/node_modules/openai/resources/admin/organization/groups/groups.js +1 -1
  539. package/node_modules/openai/resources/admin/organization/groups/groups.mjs +1 -1
  540. package/node_modules/openai/resources/admin/organization/groups/index.js +1 -1
  541. package/node_modules/openai/resources/admin/organization/groups/index.mjs +1 -1
  542. package/node_modules/openai/resources/admin/organization/groups/roles.js +1 -1
  543. package/node_modules/openai/resources/admin/organization/groups/roles.mjs +1 -1
  544. package/node_modules/openai/resources/admin/organization/groups/users.js +1 -1
  545. package/node_modules/openai/resources/admin/organization/groups/users.mjs +1 -1
  546. package/node_modules/openai/resources/admin/organization/groups.js +1 -1
  547. package/node_modules/openai/resources/admin/organization/groups.mjs +1 -1
  548. package/node_modules/openai/resources/admin/organization/index.js +4 -2
  549. package/node_modules/openai/resources/admin/organization/index.mjs +2 -1
  550. package/node_modules/openai/resources/admin/organization/invites.js +1 -1
  551. package/node_modules/openai/resources/admin/organization/invites.mjs +1 -1
  552. package/node_modules/openai/resources/admin/organization/organization.js +5 -1
  553. package/node_modules/openai/resources/admin/organization/organization.mjs +5 -1
  554. package/node_modules/openai/resources/admin/organization/projects/api-keys.js +1 -1
  555. package/node_modules/openai/resources/admin/organization/projects/api-keys.mjs +1 -1
  556. package/node_modules/openai/resources/admin/organization/projects/certificates.js +1 -1
  557. package/node_modules/openai/resources/admin/organization/projects/certificates.mjs +1 -1
  558. package/node_modules/openai/resources/admin/organization/projects/data-retention.js +1 -1
  559. package/node_modules/openai/resources/admin/organization/projects/data-retention.mjs +1 -1
  560. package/node_modules/openai/resources/admin/organization/projects/groups/groups.js +1 -1
  561. package/node_modules/openai/resources/admin/organization/projects/groups/groups.mjs +1 -1
  562. package/node_modules/openai/resources/admin/organization/projects/groups/index.js +1 -1
  563. package/node_modules/openai/resources/admin/organization/projects/groups/index.mjs +1 -1
  564. package/node_modules/openai/resources/admin/organization/projects/groups/roles.js +1 -1
  565. package/node_modules/openai/resources/admin/organization/projects/groups/roles.mjs +1 -1
  566. package/node_modules/openai/resources/admin/organization/projects/groups.js +1 -1
  567. package/node_modules/openai/resources/admin/organization/projects/groups.mjs +1 -1
  568. package/node_modules/openai/resources/admin/organization/projects/hosted-tool-permissions.js +1 -1
  569. package/node_modules/openai/resources/admin/organization/projects/hosted-tool-permissions.mjs +1 -1
  570. package/node_modules/openai/resources/admin/organization/projects/index.js +8 -6
  571. package/node_modules/openai/resources/admin/organization/projects/index.mjs +3 -2
  572. package/node_modules/openai/resources/admin/organization/projects/model-permissions.js +1 -1
  573. package/node_modules/openai/resources/admin/organization/projects/model-permissions.mjs +1 -1
  574. package/node_modules/openai/resources/admin/organization/projects/projects.js +7 -3
  575. package/node_modules/openai/resources/admin/organization/projects/projects.mjs +7 -3
  576. package/node_modules/openai/resources/admin/organization/projects/rate-limits.js +1 -1
  577. package/node_modules/openai/resources/admin/organization/projects/rate-limits.mjs +1 -1
  578. package/node_modules/openai/resources/admin/organization/projects/roles.js +1 -1
  579. package/node_modules/openai/resources/admin/organization/projects/roles.mjs +1 -1
  580. package/node_modules/openai/resources/admin/organization/projects/service-accounts/api-keys.js +26 -0
  581. package/node_modules/openai/resources/admin/organization/projects/service-accounts/api-keys.mjs +22 -0
  582. package/node_modules/openai/resources/admin/organization/projects/service-accounts/index.js +9 -0
  583. package/node_modules/openai/resources/admin/organization/projects/service-accounts/index.mjs +4 -0
  584. package/node_modules/openai/resources/admin/organization/projects/service-accounts/service-accounts.js +109 -0
  585. package/node_modules/openai/resources/admin/organization/projects/service-accounts/service-accounts.mjs +104 -0
  586. package/node_modules/openai/resources/admin/organization/projects/service-accounts.js +3 -98
  587. package/node_modules/openai/resources/admin/organization/projects/service-accounts.mjs +2 -96
  588. package/node_modules/openai/resources/admin/organization/projects/spend-alerts.js +20 -1
  589. package/node_modules/openai/resources/admin/organization/projects/spend-alerts.mjs +20 -1
  590. package/node_modules/openai/resources/admin/organization/projects/spend-limit.js +67 -0
  591. package/node_modules/openai/resources/admin/organization/projects/spend-limit.mjs +63 -0
  592. package/node_modules/openai/resources/admin/organization/projects/users/index.js +1 -1
  593. package/node_modules/openai/resources/admin/organization/projects/users/index.mjs +1 -1
  594. package/node_modules/openai/resources/admin/organization/projects/users/roles.js +1 -1
  595. package/node_modules/openai/resources/admin/organization/projects/users/roles.mjs +1 -1
  596. package/node_modules/openai/resources/admin/organization/projects/users/users.js +1 -1
  597. package/node_modules/openai/resources/admin/organization/projects/users/users.mjs +1 -1
  598. package/node_modules/openai/resources/admin/organization/projects/users.js +1 -1
  599. package/node_modules/openai/resources/admin/organization/projects/users.mjs +1 -1
  600. package/node_modules/openai/resources/admin/organization/projects.js +1 -1
  601. package/node_modules/openai/resources/admin/organization/projects.mjs +1 -1
  602. package/node_modules/openai/resources/admin/organization/roles.js +1 -1
  603. package/node_modules/openai/resources/admin/organization/roles.mjs +1 -1
  604. package/node_modules/openai/resources/admin/organization/spend-alerts.js +18 -1
  605. package/node_modules/openai/resources/admin/organization/spend-alerts.mjs +18 -1
  606. package/node_modules/openai/resources/admin/organization/spend-limit.js +59 -0
  607. package/node_modules/openai/resources/admin/organization/spend-limit.mjs +55 -0
  608. package/node_modules/openai/resources/admin/organization/usage.js +1 -1
  609. package/node_modules/openai/resources/admin/organization/usage.mjs +1 -1
  610. package/node_modules/openai/resources/admin/organization/users/index.js +1 -1
  611. package/node_modules/openai/resources/admin/organization/users/index.mjs +1 -1
  612. package/node_modules/openai/resources/admin/organization/users/roles.js +1 -1
  613. package/node_modules/openai/resources/admin/organization/users/roles.mjs +1 -1
  614. package/node_modules/openai/resources/admin/organization/users/users.js +1 -1
  615. package/node_modules/openai/resources/admin/organization/users/users.mjs +1 -1
  616. package/node_modules/openai/resources/admin/organization/users.js +1 -1
  617. package/node_modules/openai/resources/admin/organization/users.mjs +1 -1
  618. package/node_modules/openai/resources/admin/organization.js +1 -1
  619. package/node_modules/openai/resources/admin/organization.mjs +1 -1
  620. package/node_modules/openai/resources/admin.js +1 -1
  621. package/node_modules/openai/resources/admin.mjs +1 -1
  622. package/node_modules/openai/resources/audio/audio.js +1 -1
  623. package/node_modules/openai/resources/audio/audio.mjs +1 -1
  624. package/node_modules/openai/resources/audio/index.js +1 -1
  625. package/node_modules/openai/resources/audio/index.mjs +1 -1
  626. package/node_modules/openai/resources/audio/speech.js +1 -1
  627. package/node_modules/openai/resources/audio/speech.mjs +1 -1
  628. package/node_modules/openai/resources/audio/transcriptions.js +1 -1
  629. package/node_modules/openai/resources/audio/transcriptions.mjs +1 -1
  630. package/node_modules/openai/resources/audio/translations.js +1 -1
  631. package/node_modules/openai/resources/audio/translations.mjs +1 -1
  632. package/node_modules/openai/resources/audio.js +1 -1
  633. package/node_modules/openai/resources/audio.mjs +1 -1
  634. package/node_modules/openai/resources/batches.js +1 -1
  635. package/node_modules/openai/resources/batches.mjs +1 -1
  636. package/node_modules/openai/resources/beta/agents/agents.js +118 -0
  637. package/node_modules/openai/resources/beta/agents/agents.mjs +113 -0
  638. package/node_modules/openai/resources/beta/agents/environments/environments.js +43 -0
  639. package/node_modules/openai/resources/beta/agents/environments/environments.mjs +38 -0
  640. package/node_modules/openai/resources/beta/agents/environments/files.js +61 -0
  641. package/node_modules/openai/resources/beta/agents/environments/files.mjs +57 -0
  642. package/node_modules/openai/resources/beta/agents/environments/index.js +11 -0
  643. package/node_modules/openai/resources/beta/agents/environments/index.mjs +5 -0
  644. package/node_modules/openai/resources/beta/agents/environments/templates.js +112 -0
  645. package/node_modules/openai/resources/beta/agents/environments/templates.mjs +108 -0
  646. package/node_modules/openai/resources/beta/agents/environments.js +6 -0
  647. package/node_modules/openai/resources/beta/agents/environments.mjs +3 -0
  648. package/node_modules/openai/resources/beta/agents/index.js +13 -0
  649. package/node_modules/openai/resources/beta/agents/index.mjs +6 -0
  650. package/node_modules/openai/resources/beta/agents/sessions/artifacts.js +106 -0
  651. package/node_modules/openai/resources/beta/agents/sessions/artifacts.mjs +102 -0
  652. package/node_modules/openai/resources/beta/agents/sessions/events.js +75 -0
  653. package/node_modules/openai/resources/beta/agents/sessions/events.mjs +71 -0
  654. package/node_modules/openai/resources/beta/agents/sessions/index.js +17 -0
  655. package/node_modules/openai/resources/beta/agents/sessions/index.mjs +8 -0
  656. package/node_modules/openai/resources/beta/agents/sessions/items.js +35 -0
  657. package/node_modules/openai/resources/beta/agents/sessions/items.mjs +31 -0
  658. package/node_modules/openai/resources/beta/agents/sessions/sessions.js +127 -0
  659. package/node_modules/openai/resources/beta/agents/sessions/sessions.mjs +122 -0
  660. package/node_modules/openai/resources/beta/agents/sessions/subagents/index.js +11 -0
  661. package/node_modules/openai/resources/beta/agents/sessions/subagents/index.mjs +5 -0
  662. package/node_modules/openai/resources/beta/agents/sessions/subagents/items.js +36 -0
  663. package/node_modules/openai/resources/beta/agents/sessions/subagents/items.mjs +32 -0
  664. package/node_modules/openai/resources/beta/agents/sessions/subagents/subagents.js +67 -0
  665. package/node_modules/openai/resources/beta/agents/sessions/subagents/subagents.mjs +62 -0
  666. package/node_modules/openai/resources/beta/agents/sessions/subagents/turns/index.js +9 -0
  667. package/node_modules/openai/resources/beta/agents/sessions/subagents/turns/index.mjs +4 -0
  668. package/node_modules/openai/resources/beta/agents/sessions/subagents/turns/items.js +36 -0
  669. package/node_modules/openai/resources/beta/agents/sessions/subagents/turns/items.mjs +32 -0
  670. package/node_modules/openai/resources/beta/agents/sessions/subagents/turns/turns.js +68 -0
  671. package/node_modules/openai/resources/beta/agents/sessions/subagents/turns/turns.mjs +63 -0
  672. package/node_modules/openai/resources/beta/agents/sessions/subagents/turns.js +6 -0
  673. package/node_modules/openai/resources/beta/agents/sessions/subagents/turns.mjs +3 -0
  674. package/node_modules/openai/resources/beta/agents/sessions/subagents.js +6 -0
  675. package/node_modules/openai/resources/beta/agents/sessions/subagents.mjs +3 -0
  676. package/node_modules/openai/resources/beta/agents/sessions/turns.js +57 -0
  677. package/node_modules/openai/resources/beta/agents/sessions/turns.mjs +53 -0
  678. package/node_modules/openai/resources/beta/agents/sessions.js +6 -0
  679. package/node_modules/openai/resources/beta/agents/sessions.mjs +3 -0
  680. package/node_modules/openai/resources/beta/agents/vaults/credentials.js +132 -0
  681. package/node_modules/openai/resources/beta/agents/vaults/credentials.mjs +128 -0
  682. package/node_modules/openai/resources/beta/agents/vaults/index.js +9 -0
  683. package/node_modules/openai/resources/beta/agents/vaults/index.mjs +4 -0
  684. package/node_modules/openai/resources/beta/agents/vaults/vaults.js +93 -0
  685. package/node_modules/openai/resources/beta/agents/vaults/vaults.mjs +88 -0
  686. package/node_modules/openai/resources/beta/agents/vaults.js +6 -0
  687. package/node_modules/openai/resources/beta/agents/vaults.mjs +3 -0
  688. package/node_modules/openai/resources/beta/agents.js +6 -0
  689. package/node_modules/openai/resources/beta/agents.mjs +3 -0
  690. package/node_modules/openai/resources/beta/assistants.js +1 -1
  691. package/node_modules/openai/resources/beta/assistants.mjs +1 -1
  692. package/node_modules/openai/resources/beta/beta.js +9 -1
  693. package/node_modules/openai/resources/beta/beta.mjs +9 -1
  694. package/node_modules/openai/resources/beta/chatkit/chatkit.js +1 -1
  695. package/node_modules/openai/resources/beta/chatkit/chatkit.mjs +1 -1
  696. package/node_modules/openai/resources/beta/chatkit/index.js +1 -1
  697. package/node_modules/openai/resources/beta/chatkit/index.mjs +1 -1
  698. package/node_modules/openai/resources/beta/chatkit/sessions.js +1 -1
  699. package/node_modules/openai/resources/beta/chatkit/sessions.mjs +1 -1
  700. package/node_modules/openai/resources/beta/chatkit/threads.js +1 -1
  701. package/node_modules/openai/resources/beta/chatkit/threads.mjs +1 -1
  702. package/node_modules/openai/resources/beta/chatkit.js +1 -1
  703. package/node_modules/openai/resources/beta/chatkit.mjs +1 -1
  704. package/node_modules/openai/resources/beta/index.js +12 -8
  705. package/node_modules/openai/resources/beta/index.mjs +3 -1
  706. package/node_modules/openai/resources/beta/realtime/index.js +0 -1
  707. package/node_modules/openai/resources/beta/realtime/index.mjs +0 -1
  708. package/node_modules/openai/resources/beta/realtime/realtime.js +0 -1
  709. package/node_modules/openai/resources/beta/realtime/realtime.mjs +0 -1
  710. package/node_modules/openai/resources/beta/realtime/sessions.js +0 -1
  711. package/node_modules/openai/resources/beta/realtime/sessions.mjs +0 -1
  712. package/node_modules/openai/resources/beta/realtime/transcription-sessions.js +0 -1
  713. package/node_modules/openai/resources/beta/realtime/transcription-sessions.mjs +0 -1
  714. package/node_modules/openai/resources/beta/realtime.js +0 -1
  715. package/node_modules/openai/resources/beta/realtime.mjs +0 -1
  716. package/node_modules/openai/resources/beta/responses/index.js +11 -0
  717. package/node_modules/openai/resources/beta/responses/index.mjs +5 -0
  718. package/node_modules/openai/resources/beta/responses/input-items.js +37 -0
  719. package/node_modules/openai/resources/beta/responses/input-items.mjs +33 -0
  720. package/node_modules/openai/resources/beta/responses/input-tokens.js +34 -0
  721. package/node_modules/openai/resources/beta/responses/input-tokens.mjs +30 -0
  722. package/node_modules/openai/resources/beta/responses/internal-base.js +66 -0
  723. package/node_modules/openai/resources/beta/responses/internal-base.mjs +60 -0
  724. package/node_modules/openai/resources/beta/responses/responses.js +121 -0
  725. package/node_modules/openai/resources/beta/responses/responses.mjs +116 -0
  726. package/node_modules/openai/resources/beta/responses/ws-base.js +566 -0
  727. package/node_modules/openai/resources/beta/responses/ws-base.mjs +560 -0
  728. package/node_modules/openai/resources/beta/responses/ws.js +47 -0
  729. package/node_modules/openai/resources/beta/responses/ws.mjs +42 -0
  730. package/node_modules/openai/resources/beta/responses.js +6 -0
  731. package/node_modules/openai/resources/beta/responses.mjs +3 -0
  732. package/node_modules/openai/resources/beta/threads/index.js +1 -1
  733. package/node_modules/openai/resources/beta/threads/index.mjs +1 -1
  734. package/node_modules/openai/resources/beta/threads/messages.js +1 -1
  735. package/node_modules/openai/resources/beta/threads/messages.mjs +1 -1
  736. package/node_modules/openai/resources/beta/threads/runs/index.js +1 -1
  737. package/node_modules/openai/resources/beta/threads/runs/index.mjs +1 -1
  738. package/node_modules/openai/resources/beta/threads/runs/runs.js +3 -44
  739. package/node_modules/openai/resources/beta/threads/runs/runs.mjs +3 -44
  740. package/node_modules/openai/resources/beta/threads/runs/steps.js +1 -1
  741. package/node_modules/openai/resources/beta/threads/runs/steps.mjs +1 -1
  742. package/node_modules/openai/resources/beta/threads/runs.js +1 -1
  743. package/node_modules/openai/resources/beta/threads/runs.mjs +1 -1
  744. package/node_modules/openai/resources/beta/threads/threads.js +1 -1
  745. package/node_modules/openai/resources/beta/threads/threads.mjs +1 -1
  746. package/node_modules/openai/resources/beta/threads.js +1 -1
  747. package/node_modules/openai/resources/beta/threads.mjs +1 -1
  748. package/node_modules/openai/resources/beta.js +1 -1
  749. package/node_modules/openai/resources/beta.mjs +1 -1
  750. package/node_modules/openai/resources/chat/chat.js +1 -1
  751. package/node_modules/openai/resources/chat/chat.mjs +1 -1
  752. package/node_modules/openai/resources/chat/completions/completions.js +2 -5
  753. package/node_modules/openai/resources/chat/completions/completions.mjs +2 -5
  754. package/node_modules/openai/resources/chat/completions/index.js +1 -1
  755. package/node_modules/openai/resources/chat/completions/index.mjs +1 -1
  756. package/node_modules/openai/resources/chat/completions/messages.js +1 -1
  757. package/node_modules/openai/resources/chat/completions/messages.mjs +1 -1
  758. package/node_modules/openai/resources/chat/completions.js +1 -1
  759. package/node_modules/openai/resources/chat/completions.mjs +1 -1
  760. package/node_modules/openai/resources/chat/index.js +1 -1
  761. package/node_modules/openai/resources/chat/index.mjs +1 -1
  762. package/node_modules/openai/resources/chat.js +1 -1
  763. package/node_modules/openai/resources/chat.mjs +1 -1
  764. package/node_modules/openai/resources/completions.js +1 -1
  765. package/node_modules/openai/resources/completions.mjs +1 -1
  766. package/node_modules/openai/resources/containers/containers.js +1 -1
  767. package/node_modules/openai/resources/containers/containers.mjs +1 -1
  768. package/node_modules/openai/resources/containers/files/content.js +1 -1
  769. package/node_modules/openai/resources/containers/files/content.mjs +1 -1
  770. package/node_modules/openai/resources/containers/files/files.js +1 -1
  771. package/node_modules/openai/resources/containers/files/files.mjs +1 -1
  772. package/node_modules/openai/resources/containers/files/index.js +1 -1
  773. package/node_modules/openai/resources/containers/files/index.mjs +1 -1
  774. package/node_modules/openai/resources/containers/files.js +1 -1
  775. package/node_modules/openai/resources/containers/files.mjs +1 -1
  776. package/node_modules/openai/resources/containers/index.js +1 -1
  777. package/node_modules/openai/resources/containers/index.mjs +1 -1
  778. package/node_modules/openai/resources/containers.js +1 -1
  779. package/node_modules/openai/resources/containers.mjs +1 -1
  780. package/node_modules/openai/resources/content-provenance-checks.js +24 -0
  781. package/node_modules/openai/resources/content-provenance-checks.mjs +20 -0
  782. package/node_modules/openai/resources/conversations/conversations.js +1 -1
  783. package/node_modules/openai/resources/conversations/conversations.mjs +1 -1
  784. package/node_modules/openai/resources/conversations/index.js +1 -1
  785. package/node_modules/openai/resources/conversations/index.mjs +1 -1
  786. package/node_modules/openai/resources/conversations/items.js +1 -1
  787. package/node_modules/openai/resources/conversations/items.mjs +1 -1
  788. package/node_modules/openai/resources/conversations.js +1 -1
  789. package/node_modules/openai/resources/conversations.mjs +1 -1
  790. package/node_modules/openai/resources/embeddings.js +3 -47
  791. package/node_modules/openai/resources/embeddings.mjs +3 -47
  792. package/node_modules/openai/resources/evals/evals.js +2 -2
  793. package/node_modules/openai/resources/evals/evals.mjs +2 -2
  794. package/node_modules/openai/resources/evals/index.js +1 -1
  795. package/node_modules/openai/resources/evals/index.mjs +1 -1
  796. package/node_modules/openai/resources/evals/runs/index.js +1 -1
  797. package/node_modules/openai/resources/evals/runs/index.mjs +1 -1
  798. package/node_modules/openai/resources/evals/runs/output-items.js +1 -1
  799. package/node_modules/openai/resources/evals/runs/output-items.mjs +1 -1
  800. package/node_modules/openai/resources/evals/runs/runs.js +1 -1
  801. package/node_modules/openai/resources/evals/runs/runs.mjs +1 -1
  802. package/node_modules/openai/resources/evals/runs.js +1 -1
  803. package/node_modules/openai/resources/evals/runs.mjs +1 -1
  804. package/node_modules/openai/resources/evals.js +1 -1
  805. package/node_modules/openai/resources/evals.mjs +1 -1
  806. package/node_modules/openai/resources/files.js +9 -22
  807. package/node_modules/openai/resources/files.mjs +9 -22
  808. package/node_modules/openai/resources/fine-tuning/alpha/alpha.js +1 -1
  809. package/node_modules/openai/resources/fine-tuning/alpha/alpha.mjs +1 -1
  810. package/node_modules/openai/resources/fine-tuning/alpha/graders.js +1 -1
  811. package/node_modules/openai/resources/fine-tuning/alpha/graders.mjs +1 -1
  812. package/node_modules/openai/resources/fine-tuning/alpha/index.js +1 -1
  813. package/node_modules/openai/resources/fine-tuning/alpha/index.mjs +1 -1
  814. package/node_modules/openai/resources/fine-tuning/alpha.js +1 -1
  815. package/node_modules/openai/resources/fine-tuning/alpha.mjs +1 -1
  816. package/node_modules/openai/resources/fine-tuning/checkpoints/checkpoints.js +1 -1
  817. package/node_modules/openai/resources/fine-tuning/checkpoints/checkpoints.mjs +1 -1
  818. package/node_modules/openai/resources/fine-tuning/checkpoints/index.js +1 -1
  819. package/node_modules/openai/resources/fine-tuning/checkpoints/index.mjs +1 -1
  820. package/node_modules/openai/resources/fine-tuning/checkpoints/permissions.js +9 -5
  821. package/node_modules/openai/resources/fine-tuning/checkpoints/permissions.mjs +9 -5
  822. package/node_modules/openai/resources/fine-tuning/checkpoints.js +1 -1
  823. package/node_modules/openai/resources/fine-tuning/checkpoints.mjs +1 -1
  824. package/node_modules/openai/resources/fine-tuning/fine-tuning.js +1 -1
  825. package/node_modules/openai/resources/fine-tuning/fine-tuning.mjs +1 -1
  826. package/node_modules/openai/resources/fine-tuning/index.js +1 -1
  827. package/node_modules/openai/resources/fine-tuning/index.mjs +1 -1
  828. package/node_modules/openai/resources/fine-tuning/jobs/checkpoints.js +1 -1
  829. package/node_modules/openai/resources/fine-tuning/jobs/checkpoints.mjs +1 -1
  830. package/node_modules/openai/resources/fine-tuning/jobs/index.js +1 -1
  831. package/node_modules/openai/resources/fine-tuning/jobs/index.mjs +1 -1
  832. package/node_modules/openai/resources/fine-tuning/jobs/jobs.js +3 -3
  833. package/node_modules/openai/resources/fine-tuning/jobs/jobs.mjs +3 -3
  834. package/node_modules/openai/resources/fine-tuning/jobs.js +1 -1
  835. package/node_modules/openai/resources/fine-tuning/jobs.mjs +1 -1
  836. package/node_modules/openai/resources/fine-tuning/methods.js +1 -1
  837. package/node_modules/openai/resources/fine-tuning/methods.mjs +1 -1
  838. package/node_modules/openai/resources/fine-tuning.js +1 -1
  839. package/node_modules/openai/resources/fine-tuning.mjs +1 -1
  840. package/node_modules/openai/resources/graders/grader-models.js +1 -1
  841. package/node_modules/openai/resources/graders/grader-models.mjs +1 -1
  842. package/node_modules/openai/resources/graders/graders.js +1 -1
  843. package/node_modules/openai/resources/graders/graders.mjs +1 -1
  844. package/node_modules/openai/resources/graders/index.js +1 -1
  845. package/node_modules/openai/resources/graders/index.mjs +1 -1
  846. package/node_modules/openai/resources/graders.js +1 -1
  847. package/node_modules/openai/resources/graders.mjs +1 -1
  848. package/node_modules/openai/resources/images.js +8 -2
  849. package/node_modules/openai/resources/images.mjs +8 -2
  850. package/node_modules/openai/resources/index.js +9 -3
  851. package/node_modules/openai/resources/index.mjs +5 -2
  852. package/node_modules/openai/resources/live/forks/forks.js +9 -0
  853. package/node_modules/openai/resources/live/forks/forks.mjs +5 -0
  854. package/node_modules/openai/resources/live/forks/index.js +7 -0
  855. package/node_modules/openai/resources/live/forks/index.mjs +3 -0
  856. package/node_modules/openai/resources/live/forks/internal-base.js +65 -0
  857. package/node_modules/openai/resources/live/forks/internal-base.mjs +59 -0
  858. package/node_modules/openai/resources/live/forks/ws-base.js +547 -0
  859. package/node_modules/openai/resources/live/forks/ws-base.mjs +543 -0
  860. package/node_modules/openai/resources/live/forks/ws.js +32 -0
  861. package/node_modules/openai/resources/live/forks/ws.mjs +27 -0
  862. package/node_modules/openai/resources/live/forks.js +6 -0
  863. package/node_modules/openai/resources/live/forks.mjs +3 -0
  864. package/node_modules/openai/resources/live/index.js +13 -0
  865. package/node_modules/openai/resources/live/index.mjs +6 -0
  866. package/node_modules/openai/resources/live/internal-base.js +64 -0
  867. package/node_modules/openai/resources/live/internal-base.mjs +58 -0
  868. package/node_modules/openai/resources/live/live.js +40 -0
  869. package/node_modules/openai/resources/live/live.mjs +35 -0
  870. package/node_modules/openai/resources/live/sessions.js +124 -0
  871. package/node_modules/openai/resources/live/sessions.mjs +120 -0
  872. package/node_modules/openai/resources/live/sideband/index.js +7 -0
  873. package/node_modules/openai/resources/live/sideband/index.mjs +3 -0
  874. package/node_modules/openai/resources/live/sideband/internal-base.js +65 -0
  875. package/node_modules/openai/resources/live/sideband/internal-base.mjs +59 -0
  876. package/node_modules/openai/resources/live/sideband/sideband.js +9 -0
  877. package/node_modules/openai/resources/live/sideband/sideband.mjs +5 -0
  878. package/node_modules/openai/resources/live/sideband/ws-base.js +547 -0
  879. package/node_modules/openai/resources/live/sideband/ws-base.mjs +543 -0
  880. package/node_modules/openai/resources/live/sideband/ws.js +32 -0
  881. package/node_modules/openai/resources/live/sideband/ws.mjs +27 -0
  882. package/node_modules/openai/resources/live/sideband.js +6 -0
  883. package/node_modules/openai/resources/live/sideband.mjs +3 -0
  884. package/node_modules/openai/resources/live/ws-base.js +547 -0
  885. package/node_modules/openai/resources/live/ws-base.mjs +543 -0
  886. package/node_modules/openai/resources/live/ws.js +32 -0
  887. package/node_modules/openai/resources/live/ws.mjs +27 -0
  888. package/node_modules/openai/resources/live.js +6 -0
  889. package/node_modules/openai/resources/live.mjs +3 -0
  890. package/node_modules/openai/resources/models.js +1 -1
  891. package/node_modules/openai/resources/models.mjs +1 -1
  892. package/node_modules/openai/resources/moderations.js +3 -2
  893. package/node_modules/openai/resources/moderations.mjs +3 -2
  894. package/node_modules/openai/resources/realtime/calls.js +25 -1
  895. package/node_modules/openai/resources/realtime/calls.mjs +25 -1
  896. package/node_modules/openai/resources/realtime/client-secrets.js +2 -2
  897. package/node_modules/openai/resources/realtime/client-secrets.mjs +2 -2
  898. package/node_modules/openai/resources/realtime/index.js +1 -1
  899. package/node_modules/openai/resources/realtime/index.mjs +2 -2
  900. package/node_modules/openai/resources/realtime/realtime.js +1 -1
  901. package/node_modules/openai/resources/realtime/realtime.mjs +1 -1
  902. package/node_modules/openai/resources/realtime.js +1 -1
  903. package/node_modules/openai/resources/realtime.mjs +1 -1
  904. package/node_modules/openai/resources/responses/index.js +1 -1
  905. package/node_modules/openai/resources/responses/index.mjs +1 -1
  906. package/node_modules/openai/resources/responses/input-items.js +1 -1
  907. package/node_modules/openai/resources/responses/input-items.mjs +1 -1
  908. package/node_modules/openai/resources/responses/input-tokens.js +1 -1
  909. package/node_modules/openai/resources/responses/input-tokens.mjs +1 -1
  910. package/node_modules/openai/resources/responses/internal-base.js +24 -6
  911. package/node_modules/openai/resources/responses/internal-base.mjs +24 -6
  912. package/node_modules/openai/resources/responses/responses.js +5 -5
  913. package/node_modules/openai/resources/responses/responses.mjs +5 -5
  914. package/node_modules/openai/resources/responses/ws-base.js +115 -23
  915. package/node_modules/openai/resources/responses/ws-base.mjs +115 -25
  916. package/node_modules/openai/resources/responses/ws.js +23 -7
  917. package/node_modules/openai/resources/responses/ws.mjs +23 -7
  918. package/node_modules/openai/resources/responses.js +1 -1
  919. package/node_modules/openai/resources/responses.mjs +1 -1
  920. package/node_modules/openai/resources/safety/alerts.js +16 -0
  921. package/node_modules/openai/resources/safety/alerts.mjs +12 -0
  922. package/node_modules/openai/resources/safety/index.js +9 -0
  923. package/node_modules/openai/resources/safety/index.mjs +4 -0
  924. package/node_modules/openai/resources/safety/safety.js +17 -0
  925. package/node_modules/openai/resources/safety/safety.mjs +12 -0
  926. package/node_modules/openai/resources/safety.js +6 -0
  927. package/node_modules/openai/resources/safety.mjs +3 -0
  928. package/node_modules/openai/resources/shared.js +1 -1
  929. package/node_modules/openai/resources/shared.mjs +1 -1
  930. package/node_modules/openai/resources/skills/content.js +1 -1
  931. package/node_modules/openai/resources/skills/content.mjs +1 -1
  932. package/node_modules/openai/resources/skills/index.js +1 -1
  933. package/node_modules/openai/resources/skills/index.mjs +1 -1
  934. package/node_modules/openai/resources/skills/skills.js +4 -2
  935. package/node_modules/openai/resources/skills/skills.mjs +4 -2
  936. package/node_modules/openai/resources/skills/versions/content.js +1 -1
  937. package/node_modules/openai/resources/skills/versions/content.mjs +1 -1
  938. package/node_modules/openai/resources/skills/versions/index.js +1 -1
  939. package/node_modules/openai/resources/skills/versions/index.mjs +1 -1
  940. package/node_modules/openai/resources/skills/versions/versions.js +4 -2
  941. package/node_modules/openai/resources/skills/versions/versions.mjs +4 -2
  942. package/node_modules/openai/resources/skills/versions.js +1 -1
  943. package/node_modules/openai/resources/skills/versions.mjs +1 -1
  944. package/node_modules/openai/resources/skills.js +1 -1
  945. package/node_modules/openai/resources/skills.mjs +1 -1
  946. package/node_modules/openai/resources/uploads/index.js +1 -1
  947. package/node_modules/openai/resources/uploads/index.mjs +1 -1
  948. package/node_modules/openai/resources/uploads/parts.js +6 -5
  949. package/node_modules/openai/resources/uploads/parts.mjs +6 -5
  950. package/node_modules/openai/resources/uploads/uploads.js +10 -10
  951. package/node_modules/openai/resources/uploads/uploads.mjs +10 -10
  952. package/node_modules/openai/resources/uploads.js +1 -1
  953. package/node_modules/openai/resources/uploads.mjs +1 -1
  954. package/node_modules/openai/resources/vector-stores/file-batches.js +6 -63
  955. package/node_modules/openai/resources/vector-stores/file-batches.mjs +6 -63
  956. package/node_modules/openai/resources/vector-stores/files.js +6 -39
  957. package/node_modules/openai/resources/vector-stores/files.mjs +6 -39
  958. package/node_modules/openai/resources/vector-stores/index.js +1 -1
  959. package/node_modules/openai/resources/vector-stores/index.mjs +1 -1
  960. package/node_modules/openai/resources/vector-stores/vector-stores.js +1 -1
  961. package/node_modules/openai/resources/vector-stores/vector-stores.mjs +1 -1
  962. package/node_modules/openai/resources/vector-stores.js +1 -1
  963. package/node_modules/openai/resources/vector-stores.mjs +1 -1
  964. package/node_modules/openai/resources/videos.js +24 -1
  965. package/node_modules/openai/resources/videos.mjs +24 -1
  966. package/node_modules/openai/resources/webhooks/event-types.js +21 -0
  967. package/node_modules/openai/resources/webhooks/event-types.mjs +17 -0
  968. package/node_modules/openai/resources/webhooks/index.js +4 -1
  969. package/node_modules/openai/resources/webhooks/index.mjs +2 -1
  970. package/node_modules/openai/resources/webhooks/webhooks.js +127 -43
  971. package/node_modules/openai/resources/webhooks/webhooks.mjs +127 -43
  972. package/node_modules/openai/resources/webhooks.js +1 -1
  973. package/node_modules/openai/resources/webhooks.mjs +1 -1
  974. package/node_modules/openai/src/_vendor/partial-json-parser/LICENSE +21 -0
  975. package/node_modules/openai/src/_vendor/partial-json-parser/README.md +11 -1
  976. package/node_modules/openai/src/_vendor/partial-json-parser/parser.ts +66 -35
  977. package/node_modules/openai/src/_vendor/zod-to-json-schema/Options.ts +32 -18
  978. package/node_modules/openai/src/_vendor/zod-to-json-schema/Refs.ts +7 -6
  979. package/node_modules/openai/src/_vendor/zod-to-json-schema/errorMessages.ts +5 -3
  980. package/node_modules/openai/src/_vendor/zod-to-json-schema/index.ts +3 -1
  981. package/node_modules/openai/src/_vendor/zod-to-json-schema/parseDef.ts +194 -79
  982. package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/array.ts +8 -5
  983. package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/bigint.ts +20 -12
  984. package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/branded.ts +4 -4
  985. package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/catch.ts +4 -5
  986. package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/date.ts +16 -10
  987. package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/default.ts +10 -5
  988. package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/effects.ts +4 -3
  989. package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/enum.ts +1 -1
  990. package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/intersection.ts +12 -9
  991. package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/literal.ts +12 -2
  992. package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/map.ts +6 -4
  993. package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/nativeEnum.ts +10 -11
  994. package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/null.ts +4 -3
  995. package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/nullable.ts +25 -10
  996. package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/number.ts +17 -8
  997. package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/object.ts +57 -54
  998. package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/optional.ts +25 -17
  999. package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/pipeline.ts +8 -6
  1000. package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/promise.ts +10 -5
  1001. package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/readonly.ts +4 -5
  1002. package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/record.ts +22 -19
  1003. package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/set.ts +6 -4
  1004. package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/string.ts +62 -37
  1005. package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/tuple.ts +32 -25
  1006. package/node_modules/openai/src/_vendor/zod-to-json-schema/parsers/union.ts +51 -33
  1007. package/node_modules/openai/src/_vendor/zod-to-json-schema/util.ts +11 -6
  1008. package/node_modules/openai/src/_vendor/zod-to-json-schema/zodToJsonSchema.ts +133 -52
  1009. package/node_modules/openai/src/auth/index.ts +7 -1
  1010. package/node_modules/openai/src/auth/subject-token-providers.ts +281 -16
  1011. package/node_modules/openai/src/auth/types.ts +48 -5
  1012. package/node_modules/openai/src/auth/workload-identity-auth.ts +227 -26
  1013. package/node_modules/openai/src/auth/x509-transport.ts +369 -0
  1014. package/node_modules/openai/src/azure.ts +127 -28
  1015. package/node_modules/openai/src/bedrock.ts +294 -0
  1016. package/node_modules/openai/src/beta/realtime/internal-base.ts +136 -16
  1017. package/node_modules/openai/src/beta/realtime/websocket.ts +264 -48
  1018. package/node_modules/openai/src/beta/realtime/ws.ts +138 -25
  1019. package/node_modules/openai/src/client.ts +975 -124
  1020. package/node_modules/openai/src/core/EventEmitter.ts +162 -26
  1021. package/node_modules/openai/src/core/api-promise.ts +0 -2
  1022. package/node_modules/openai/src/core/error.ts +6 -8
  1023. package/node_modules/openai/src/core/pagination.ts +67 -7
  1024. package/node_modules/openai/src/core/resource.ts +0 -2
  1025. package/node_modules/openai/src/core/streaming.ts +490 -100
  1026. package/node_modules/openai/src/core/uploads.ts +6 -1
  1027. package/node_modules/openai/src/helpers/audio.ts +215 -32
  1028. package/node_modules/openai/src/helpers/live.ts +8 -0
  1029. package/node_modules/openai/src/helpers/standard-schema.ts +819 -0
  1030. package/node_modules/openai/src/helpers/zod-v3-strict-schema.ts +520 -0
  1031. package/node_modules/openai/src/helpers/zod.ts +418 -56
  1032. package/node_modules/openai/src/index.ts +4 -5
  1033. package/node_modules/openai/src/internal/assistant-stream-delta.ts +440 -0
  1034. package/node_modules/openai/src/internal/auth/x509-api-origin.ts +27 -0
  1035. package/node_modules/openai/src/internal/auth/x509-credential-options.ts +149 -0
  1036. package/node_modules/openai/src/internal/auth/x509-token-exchange.ts +319 -0
  1037. package/node_modules/openai/src/internal/auth/x509-transport-capability.ts +227 -0
  1038. package/node_modules/openai/src/internal/auth/x509-transport-registry.ts +127 -0
  1039. package/node_modules/openai/src/internal/auth/x509-transport-state-browser.ts +43 -0
  1040. package/node_modules/openai/src/internal/auth/x509-transport-state.cts +43 -0
  1041. package/node_modules/openai/src/internal/auth/x509-workload-identity-auth.ts +972 -0
  1042. package/node_modules/openai/src/internal/bedrock.ts +586 -0
  1043. package/node_modules/openai/src/internal/builtin-types.ts +0 -2
  1044. package/node_modules/openai/src/internal/data-residency.ts +44 -0
  1045. package/node_modules/openai/src/internal/decoders/line.ts +145 -61
  1046. package/node_modules/openai/src/internal/detect-platform.ts +3 -5
  1047. package/node_modules/openai/src/internal/errors.ts +3 -4
  1048. package/node_modules/openai/src/internal/headers.ts +14 -10
  1049. package/node_modules/openai/src/internal/multipart-encoding.ts +53 -0
  1050. package/node_modules/openai/src/internal/parse.ts +47 -19
  1051. package/node_modules/openai/src/internal/provider.ts +92 -0
  1052. package/node_modules/openai/src/internal/qs/formats.ts +1 -1
  1053. package/node_modules/openai/src/internal/qs/stringify.ts +57 -53
  1054. package/node_modules/openai/src/internal/qs/types.ts +1 -1
  1055. package/node_modules/openai/src/internal/qs/utils.ts +443 -54
  1056. package/node_modules/openai/src/internal/realtime-credentials.ts +27 -0
  1057. package/node_modules/openai/src/internal/request-options.ts +52 -3
  1058. package/node_modules/openai/src/internal/responses/canonical-output-text.ts +160 -0
  1059. package/node_modules/openai/src/internal/responses/output-text-index.ts +84 -0
  1060. package/node_modules/openai/src/internal/responses/response-accumulator.ts +1263 -0
  1061. package/node_modules/openai/src/internal/shim-types.ts +3 -4
  1062. package/node_modules/openai/src/internal/shims.ts +0 -2
  1063. package/node_modules/openai/src/internal/stream-utils.ts +37 -5
  1064. package/node_modules/openai/src/internal/to-file.ts +90 -35
  1065. package/node_modules/openai/src/internal/types.ts +21 -29
  1066. package/node_modules/openai/src/internal/uploads.ts +533 -59
  1067. package/node_modules/openai/src/internal/utils/abort.ts +116 -0
  1068. package/node_modules/openai/src/internal/utils/base64.ts +3 -2
  1069. package/node_modules/openai/src/internal/utils/bytes.ts +7 -0
  1070. package/node_modules/openai/src/internal/utils/env.ts +9 -7
  1071. package/node_modules/openai/src/internal/utils/log.ts +77 -14
  1072. package/node_modules/openai/src/internal/utils/path.ts +53 -32
  1073. package/node_modules/openai/src/internal/utils/query.ts +0 -2
  1074. package/node_modules/openai/src/internal/utils/sleep.ts +51 -2
  1075. package/node_modules/openai/src/internal/utils/uuid.ts +0 -2
  1076. package/node_modules/openai/src/internal/utils/values.ts +0 -2
  1077. package/node_modules/openai/src/internal/utils.ts +0 -2
  1078. package/node_modules/openai/src/internal/ws-adapter-browser.ts +83 -24
  1079. package/node_modules/openai/src/internal/ws-adapter-node.ts +105 -26
  1080. package/node_modules/openai/src/internal/ws-adapter.ts +23 -0
  1081. package/node_modules/openai/src/internal/ws.ts +250 -51
  1082. package/node_modules/openai/src/lib/.keep +2 -2
  1083. package/node_modules/openai/src/lib/AbstractChatCompletionRunner.ts +349 -102
  1084. package/node_modules/openai/src/lib/AssistantStream.ts +537 -268
  1085. package/node_modules/openai/src/lib/ChatCompletionRunner.ts +75 -22
  1086. package/node_modules/openai/src/lib/ChatCompletionStream.ts +2016 -268
  1087. package/node_modules/openai/src/lib/ChatCompletionStreamingRunner.ts +115 -17
  1088. package/node_modules/openai/src/lib/EventEmitter.ts +171 -26
  1089. package/node_modules/openai/src/lib/EventStream.ts +1979 -64
  1090. package/node_modules/openai/src/lib/ResponsesParser.ts +153 -56
  1091. package/node_modules/openai/src/lib/RunnableFunction.ts +99 -37
  1092. package/node_modules/openai/src/lib/Util.ts +7 -5
  1093. package/node_modules/openai/src/lib/agents/agent-session-stream.ts +328 -0
  1094. package/node_modules/openai/src/lib/agents/output-text.ts +6 -0
  1095. package/node_modules/openai/src/lib/agents/turn-state.ts +61 -0
  1096. package/node_modules/openai/src/lib/assistant-run-polling.ts +27 -0
  1097. package/node_modules/openai/src/lib/chatCompletionUtils.ts +9 -10
  1098. package/node_modules/openai/src/lib/embeddings.ts +73 -0
  1099. package/node_modules/openai/src/lib/file-processing.ts +37 -0
  1100. package/node_modules/openai/src/lib/jsonschema.ts +77 -34
  1101. package/node_modules/openai/src/lib/live/transcript-grouper.ts +307 -0
  1102. package/node_modules/openai/src/lib/live/transcript-grouping.ts +394 -0
  1103. package/node_modules/openai/src/lib/live/webrtc.ts +23 -0
  1104. package/node_modules/openai/src/lib/parser.ts +247 -69
  1105. package/node_modules/openai/src/lib/polling.ts +145 -0
  1106. package/node_modules/openai/src/lib/realtime/webrtc.ts +20 -0
  1107. package/node_modules/openai/src/lib/responses/EventTypes.ts +9 -60
  1108. package/node_modules/openai/src/lib/responses/ResponseAccumulator.ts +27 -0
  1109. package/node_modules/openai/src/lib/responses/ResponseInputItems.ts +167 -0
  1110. package/node_modules/openai/src/lib/responses/ResponseStream.ts +135 -179
  1111. package/node_modules/openai/src/lib/responses/responses-websocket-lane.ts +388 -0
  1112. package/node_modules/openai/src/lib/responses/responses-websocket-session.ts +317 -0
  1113. package/node_modules/openai/src/lib/transform.ts +2015 -100
  1114. package/node_modules/openai/src/lib/vector-store-polling.ts +46 -0
  1115. package/node_modules/openai/src/lib/vector-store-upload.ts +57 -0
  1116. package/node_modules/openai/src/lib/webhook-signature.ts +164 -0
  1117. package/node_modules/openai/src/lib/webrtc/connection.ts +313 -0
  1118. package/node_modules/openai/src/lib/webrtc/data-channel.ts +151 -0
  1119. package/node_modules/openai/src/lib/webrtc/errors.ts +38 -0
  1120. package/node_modules/openai/src/lib/webrtc/subscriptions.ts +65 -0
  1121. package/node_modules/openai/src/lib/webrtc/types.ts +110 -0
  1122. package/node_modules/openai/src/live/webrtc.ts +10 -0
  1123. package/node_modules/openai/src/providers/bedrock/aws.ts +331 -0
  1124. package/node_modules/openai/src/providers/bedrock.ts +51 -0
  1125. package/node_modules/openai/src/realtime/internal-base.ts +265 -17
  1126. package/node_modules/openai/src/realtime/webrtc.ts +10 -0
  1127. package/node_modules/openai/src/realtime/websocket.ts +259 -54
  1128. package/node_modules/openai/src/realtime/ws.ts +135 -29
  1129. package/node_modules/openai/src/resources/admin/admin.ts +1 -1
  1130. package/node_modules/openai/src/resources/admin/index.ts +1 -1
  1131. package/node_modules/openai/src/resources/admin/organization/admin-api-keys.ts +18 -2
  1132. package/node_modules/openai/src/resources/admin/organization/audit-logs.ts +327 -4
  1133. package/node_modules/openai/src/resources/admin/organization/certificates.ts +1 -1
  1134. package/node_modules/openai/src/resources/admin/organization/data-retention.ts +1 -1
  1135. package/node_modules/openai/src/resources/admin/organization/groups/groups.ts +1 -1
  1136. package/node_modules/openai/src/resources/admin/organization/groups/index.ts +1 -1
  1137. package/node_modules/openai/src/resources/admin/organization/groups/roles.ts +1 -1
  1138. package/node_modules/openai/src/resources/admin/organization/groups/users.ts +1 -1
  1139. package/node_modules/openai/src/resources/admin/organization/groups.ts +1 -1
  1140. package/node_modules/openai/src/resources/admin/organization/index.ts +9 -1
  1141. package/node_modules/openai/src/resources/admin/organization/invites.ts +1 -1
  1142. package/node_modules/openai/src/resources/admin/organization/organization.ts +21 -1
  1143. package/node_modules/openai/src/resources/admin/organization/projects/api-keys.ts +22 -2
  1144. package/node_modules/openai/src/resources/admin/organization/projects/certificates.ts +1 -1
  1145. package/node_modules/openai/src/resources/admin/organization/projects/data-retention.ts +1 -1
  1146. package/node_modules/openai/src/resources/admin/organization/projects/groups/groups.ts +1 -1
  1147. package/node_modules/openai/src/resources/admin/organization/projects/groups/index.ts +1 -1
  1148. package/node_modules/openai/src/resources/admin/organization/projects/groups/roles.ts +1 -1
  1149. package/node_modules/openai/src/resources/admin/organization/projects/groups.ts +1 -1
  1150. package/node_modules/openai/src/resources/admin/organization/projects/hosted-tool-permissions.ts +1 -1
  1151. package/node_modules/openai/src/resources/admin/organization/projects/index.ts +10 -2
  1152. package/node_modules/openai/src/resources/admin/organization/projects/model-permissions.ts +1 -1
  1153. package/node_modules/openai/src/resources/admin/organization/projects/projects.ts +70 -19
  1154. package/node_modules/openai/src/resources/admin/organization/projects/rate-limits.ts +1 -1
  1155. package/node_modules/openai/src/resources/admin/organization/projects/roles.ts +1 -1
  1156. package/node_modules/openai/src/resources/admin/organization/projects/service-accounts/api-keys.ts +91 -0
  1157. package/node_modules/openai/src/resources/admin/organization/projects/service-accounts/index.ts +15 -0
  1158. package/node_modules/openai/src/resources/admin/organization/projects/service-accounts/service-accounts.ts +299 -0
  1159. package/node_modules/openai/src/resources/admin/organization/projects/service-accounts.ts +2 -265
  1160. package/node_modules/openai/src/resources/admin/organization/projects/spend-alerts.ts +33 -1
  1161. package/node_modules/openai/src/resources/admin/organization/projects/spend-limit.ts +156 -0
  1162. package/node_modules/openai/src/resources/admin/organization/projects/users/index.ts +1 -1
  1163. package/node_modules/openai/src/resources/admin/organization/projects/users/roles.ts +1 -1
  1164. package/node_modules/openai/src/resources/admin/organization/projects/users/users.ts +1 -1
  1165. package/node_modules/openai/src/resources/admin/organization/projects/users.ts +1 -1
  1166. package/node_modules/openai/src/resources/admin/organization/projects.ts +1 -1
  1167. package/node_modules/openai/src/resources/admin/organization/roles.ts +1 -1
  1168. package/node_modules/openai/src/resources/admin/organization/spend-alerts.ts +19 -1
  1169. package/node_modules/openai/src/resources/admin/organization/spend-limit.ts +144 -0
  1170. package/node_modules/openai/src/resources/admin/organization/usage.ts +706 -89
  1171. package/node_modules/openai/src/resources/admin/organization/users/index.ts +1 -1
  1172. package/node_modules/openai/src/resources/admin/organization/users/roles.ts +1 -1
  1173. package/node_modules/openai/src/resources/admin/organization/users/users.ts +1 -1
  1174. package/node_modules/openai/src/resources/admin/organization/users.ts +1 -1
  1175. package/node_modules/openai/src/resources/admin/organization.ts +1 -1
  1176. package/node_modules/openai/src/resources/admin.ts +1 -1
  1177. package/node_modules/openai/src/resources/audio/audio.ts +4 -1
  1178. package/node_modules/openai/src/resources/audio/index.ts +2 -1
  1179. package/node_modules/openai/src/resources/audio/speech.ts +4 -3
  1180. package/node_modules/openai/src/resources/audio/transcriptions.ts +51 -13
  1181. package/node_modules/openai/src/resources/audio/translations.ts +5 -3
  1182. package/node_modules/openai/src/resources/audio.ts +1 -1
  1183. package/node_modules/openai/src/resources/batches.ts +10 -9
  1184. package/node_modules/openai/src/resources/beta/agents/agents.ts +4627 -0
  1185. package/node_modules/openai/src/resources/beta/agents/environments/environments.ts +111 -0
  1186. package/node_modules/openai/src/resources/beta/agents/environments/files.ts +169 -0
  1187. package/node_modules/openai/src/resources/beta/agents/environments/index.ts +19 -0
  1188. package/node_modules/openai/src/resources/beta/agents/environments/templates.ts +535 -0
  1189. package/node_modules/openai/src/resources/beta/agents/environments.ts +3 -0
  1190. package/node_modules/openai/src/resources/beta/agents/index.ts +127 -0
  1191. package/node_modules/openai/src/resources/beta/agents/sessions/artifacts.ts +249 -0
  1192. package/node_modules/openai/src/resources/beta/agents/sessions/events.ts +94 -0
  1193. package/node_modules/openai/src/resources/beta/agents/sessions/index.ts +24 -0
  1194. package/node_modules/openai/src/resources/beta/agents/sessions/items.ts +59 -0
  1195. package/node_modules/openai/src/resources/beta/agents/sessions/sessions.ts +403 -0
  1196. package/node_modules/openai/src/resources/beta/agents/sessions/subagents/index.ts +5 -0
  1197. package/node_modules/openai/src/resources/beta/agents/sessions/subagents/items.ts +65 -0
  1198. package/node_modules/openai/src/resources/beta/agents/sessions/subagents/subagents.ts +113 -0
  1199. package/node_modules/openai/src/resources/beta/agents/sessions/subagents/turns/index.ts +4 -0
  1200. package/node_modules/openai/src/resources/beta/agents/sessions/subagents/turns/items.ts +70 -0
  1201. package/node_modules/openai/src/resources/beta/agents/sessions/subagents/turns/turns.ts +111 -0
  1202. package/node_modules/openai/src/resources/beta/agents/sessions/subagents/turns.ts +3 -0
  1203. package/node_modules/openai/src/resources/beta/agents/sessions/subagents.ts +3 -0
  1204. package/node_modules/openai/src/resources/beta/agents/sessions/turns.ts +159 -0
  1205. package/node_modules/openai/src/resources/beta/agents/sessions.ts +3 -0
  1206. package/node_modules/openai/src/resources/beta/agents/vaults/credentials.ts +693 -0
  1207. package/node_modules/openai/src/resources/beta/agents/vaults/index.ts +29 -0
  1208. package/node_modules/openai/src/resources/beta/agents/vaults/vaults.ts +243 -0
  1209. package/node_modules/openai/src/resources/beta/agents/vaults.ts +3 -0
  1210. package/node_modules/openai/src/resources/beta/agents.ts +3 -0
  1211. package/node_modules/openai/src/resources/beta/assistants.ts +154 -172
  1212. package/node_modules/openai/src/resources/beta/beta.ts +578 -3
  1213. package/node_modules/openai/src/resources/beta/chatkit/chatkit.ts +1 -1
  1214. package/node_modules/openai/src/resources/beta/chatkit/index.ts +1 -1
  1215. package/node_modules/openai/src/resources/beta/chatkit/sessions.ts +1 -1
  1216. package/node_modules/openai/src/resources/beta/chatkit/threads.ts +1 -1
  1217. package/node_modules/openai/src/resources/beta/chatkit.ts +1 -1
  1218. package/node_modules/openai/src/resources/beta/index.ts +290 -1
  1219. package/node_modules/openai/src/resources/beta/realtime/index.ts +0 -2
  1220. package/node_modules/openai/src/resources/beta/realtime/realtime.ts +0 -2
  1221. package/node_modules/openai/src/resources/beta/realtime/sessions.ts +0 -2
  1222. package/node_modules/openai/src/resources/beta/realtime/transcription-sessions.ts +0 -2
  1223. package/node_modules/openai/src/resources/beta/realtime.ts +0 -2
  1224. package/node_modules/openai/src/resources/beta/responses/index.ts +189 -0
  1225. package/node_modules/openai/src/resources/beta/responses/input-items.ts +105 -0
  1226. package/node_modules/openai/src/resources/beta/responses/input-tokens.ts +249 -0
  1227. package/node_modules/openai/src/resources/beta/responses/internal-base.ts +136 -0
  1228. package/node_modules/openai/src/resources/beta/responses/responses.ts +15060 -0
  1229. package/node_modules/openai/src/resources/beta/responses/ws-base.ts +729 -0
  1230. package/node_modules/openai/src/resources/beta/responses/ws.ts +62 -0
  1231. package/node_modules/openai/src/resources/beta/responses.ts +3 -0
  1232. package/node_modules/openai/src/resources/beta/threads/index.ts +1 -1
  1233. package/node_modules/openai/src/resources/beta/threads/messages.ts +30 -24
  1234. package/node_modules/openai/src/resources/beta/threads/runs/index.ts +2 -2
  1235. package/node_modules/openai/src/resources/beta/threads/runs/runs.ts +47 -93
  1236. package/node_modules/openai/src/resources/beta/threads/runs/steps.ts +15 -16
  1237. package/node_modules/openai/src/resources/beta/threads/runs.ts +1 -1
  1238. package/node_modules/openai/src/resources/beta/threads/threads.ts +54 -51
  1239. package/node_modules/openai/src/resources/beta/threads.ts +1 -1
  1240. package/node_modules/openai/src/resources/beta.ts +1 -1
  1241. package/node_modules/openai/src/resources/chat/chat.ts +1 -1
  1242. package/node_modules/openai/src/resources/chat/completions/completions.ts +762 -108
  1243. package/node_modules/openai/src/resources/chat/completions/index.ts +1 -1
  1244. package/node_modules/openai/src/resources/chat/completions/messages.ts +1 -1
  1245. package/node_modules/openai/src/resources/chat/completions.ts +1 -1
  1246. package/node_modules/openai/src/resources/chat/index.ts +1 -1
  1247. package/node_modules/openai/src/resources/chat.ts +1 -1
  1248. package/node_modules/openai/src/resources/completions.ts +36 -15
  1249. package/node_modules/openai/src/resources/containers/containers.ts +1 -1
  1250. package/node_modules/openai/src/resources/containers/files/content.ts +1 -1
  1251. package/node_modules/openai/src/resources/containers/files/files.ts +1 -1
  1252. package/node_modules/openai/src/resources/containers/files/index.ts +1 -1
  1253. package/node_modules/openai/src/resources/containers/files.ts +1 -1
  1254. package/node_modules/openai/src/resources/containers/index.ts +1 -1
  1255. package/node_modules/openai/src/resources/containers.ts +1 -1
  1256. package/node_modules/openai/src/resources/content-provenance-checks.ts +132 -0
  1257. package/node_modules/openai/src/resources/conversations/conversations.ts +23 -2
  1258. package/node_modules/openai/src/resources/conversations/index.ts +1 -1
  1259. package/node_modules/openai/src/resources/conversations/items.ts +93 -5
  1260. package/node_modules/openai/src/resources/conversations.ts +1 -1
  1261. package/node_modules/openai/src/resources/embeddings.ts +22 -49
  1262. package/node_modules/openai/src/resources/evals/evals.ts +6 -6
  1263. package/node_modules/openai/src/resources/evals/index.ts +1 -1
  1264. package/node_modules/openai/src/resources/evals/runs/index.ts +1 -1
  1265. package/node_modules/openai/src/resources/evals/runs/output-items.ts +1 -1
  1266. package/node_modules/openai/src/resources/evals/runs/runs.ts +119 -191
  1267. package/node_modules/openai/src/resources/evals/runs.ts +1 -1
  1268. package/node_modules/openai/src/resources/evals.ts +1 -1
  1269. package/node_modules/openai/src/resources/files.ts +9 -26
  1270. package/node_modules/openai/src/resources/fine-tuning/alpha/alpha.ts +1 -1
  1271. package/node_modules/openai/src/resources/fine-tuning/alpha/graders.ts +6 -5
  1272. package/node_modules/openai/src/resources/fine-tuning/alpha/index.ts +1 -1
  1273. package/node_modules/openai/src/resources/fine-tuning/alpha.ts +1 -1
  1274. package/node_modules/openai/src/resources/fine-tuning/checkpoints/checkpoints.ts +1 -1
  1275. package/node_modules/openai/src/resources/fine-tuning/checkpoints/index.ts +1 -1
  1276. package/node_modules/openai/src/resources/fine-tuning/checkpoints/permissions.ts +9 -5
  1277. package/node_modules/openai/src/resources/fine-tuning/checkpoints.ts +1 -1
  1278. package/node_modules/openai/src/resources/fine-tuning/fine-tuning.ts +1 -1
  1279. package/node_modules/openai/src/resources/fine-tuning/index.ts +1 -1
  1280. package/node_modules/openai/src/resources/fine-tuning/jobs/checkpoints.ts +1 -1
  1281. package/node_modules/openai/src/resources/fine-tuning/jobs/index.ts +1 -1
  1282. package/node_modules/openai/src/resources/fine-tuning/jobs/jobs.ts +14 -13
  1283. package/node_modules/openai/src/resources/fine-tuning/jobs.ts +1 -1
  1284. package/node_modules/openai/src/resources/fine-tuning/methods.ts +1 -1
  1285. package/node_modules/openai/src/resources/fine-tuning.ts +1 -1
  1286. package/node_modules/openai/src/resources/graders/grader-models.ts +7 -14
  1287. package/node_modules/openai/src/resources/graders/graders.ts +1 -1
  1288. package/node_modules/openai/src/resources/graders/index.ts +1 -1
  1289. package/node_modules/openai/src/resources/graders.ts +1 -1
  1290. package/node_modules/openai/src/resources/images.ts +100 -85
  1291. package/node_modules/openai/src/resources/index.ts +9 -2
  1292. package/node_modules/openai/src/resources/live/api.md +87 -0
  1293. package/node_modules/openai/src/resources/live/forks/forks.ts +169 -0
  1294. package/node_modules/openai/src/resources/live/forks/index.ts +5 -0
  1295. package/node_modules/openai/src/resources/live/forks/internal-base.ts +126 -0
  1296. package/node_modules/openai/src/resources/live/forks/ws-base.ts +700 -0
  1297. package/node_modules/openai/src/resources/live/forks/ws.ts +47 -0
  1298. package/node_modules/openai/src/resources/live/forks.ts +3 -0
  1299. package/node_modules/openai/src/resources/live/index.ts +20 -0
  1300. package/node_modules/openai/src/resources/live/internal-base.ts +123 -0
  1301. package/node_modules/openai/src/resources/live/live.ts +2296 -0
  1302. package/node_modules/openai/src/resources/live/sessions.ts +343 -0
  1303. package/node_modules/openai/src/resources/live/sideband/index.ts +10 -0
  1304. package/node_modules/openai/src/resources/live/sideband/internal-base.ts +126 -0
  1305. package/node_modules/openai/src/resources/live/sideband/sideband.ts +58 -0
  1306. package/node_modules/openai/src/resources/live/sideband/ws-base.ts +710 -0
  1307. package/node_modules/openai/src/resources/live/sideband/ws.ts +47 -0
  1308. package/node_modules/openai/src/resources/live/sideband.ts +3 -0
  1309. package/node_modules/openai/src/resources/live/ws-base.ts +696 -0
  1310. package/node_modules/openai/src/resources/live/ws.ts +43 -0
  1311. package/node_modules/openai/src/resources/live.ts +3 -0
  1312. package/node_modules/openai/src/resources/models.ts +6 -1
  1313. package/node_modules/openai/src/resources/moderations.ts +6 -5
  1314. package/node_modules/openai/src/resources/realtime/api.md +1 -0
  1315. package/node_modules/openai/src/resources/realtime/calls.ts +50 -2
  1316. package/node_modules/openai/src/resources/realtime/client-secrets.ts +27 -10
  1317. package/node_modules/openai/src/resources/realtime/index.ts +8 -2
  1318. package/node_modules/openai/src/resources/realtime/realtime.ts +93 -35
  1319. package/node_modules/openai/src/resources/realtime.ts +1 -1
  1320. package/node_modules/openai/src/resources/responses/api.md +20 -0
  1321. package/node_modules/openai/src/resources/responses/index.ts +1 -1
  1322. package/node_modules/openai/src/resources/responses/input-items.ts +1 -1
  1323. package/node_modules/openai/src/resources/responses/input-tokens.ts +26 -16
  1324. package/node_modules/openai/src/resources/responses/internal-base.ts +33 -14
  1325. package/node_modules/openai/src/resources/responses/responses.ts +4150 -792
  1326. package/node_modules/openai/src/resources/responses/ws-base.ts +147 -31
  1327. package/node_modules/openai/src/resources/responses/ws.ts +33 -9
  1328. package/node_modules/openai/src/resources/responses.ts +1 -1
  1329. package/node_modules/openai/src/resources/safety/alerts.ts +51 -0
  1330. package/node_modules/openai/src/resources/safety/index.ts +4 -0
  1331. package/node_modules/openai/src/resources/safety/safety.ts +15 -0
  1332. package/node_modules/openai/src/resources/safety.ts +3 -0
  1333. package/node_modules/openai/src/resources/shared.ts +98 -41
  1334. package/node_modules/openai/src/resources/skills/content.ts +1 -1
  1335. package/node_modules/openai/src/resources/skills/index.ts +1 -1
  1336. package/node_modules/openai/src/resources/skills/skills.ts +4 -2
  1337. package/node_modules/openai/src/resources/skills/versions/content.ts +1 -1
  1338. package/node_modules/openai/src/resources/skills/versions/index.ts +1 -1
  1339. package/node_modules/openai/src/resources/skills/versions/versions.ts +4 -2
  1340. package/node_modules/openai/src/resources/skills/versions.ts +1 -1
  1341. package/node_modules/openai/src/resources/skills.ts +1 -1
  1342. package/node_modules/openai/src/resources/uploads/index.ts +1 -1
  1343. package/node_modules/openai/src/resources/uploads/parts.ts +6 -5
  1344. package/node_modules/openai/src/resources/uploads/uploads.ts +12 -12
  1345. package/node_modules/openai/src/resources/uploads.ts +1 -1
  1346. package/node_modules/openai/src/resources/vector-stores/file-batches.ts +24 -89
  1347. package/node_modules/openai/src/resources/vector-stores/files.ts +12 -52
  1348. package/node_modules/openai/src/resources/vector-stores/index.ts +1 -1
  1349. package/node_modules/openai/src/resources/vector-stores/vector-stores.ts +4 -4
  1350. package/node_modules/openai/src/resources/vector-stores.ts +1 -1
  1351. package/node_modules/openai/src/resources/videos.ts +63 -2
  1352. package/node_modules/openai/src/resources/webhooks/api.md +40 -17
  1353. package/node_modules/openai/src/resources/webhooks/event-types.ts +21 -0
  1354. package/node_modules/openai/src/resources/webhooks/index.ts +2 -1
  1355. package/node_modules/openai/src/resources/webhooks/webhooks.ts +694 -69
  1356. package/node_modules/openai/src/resources/webhooks.ts +1 -1
  1357. package/node_modules/openai/src/tsconfig.json +6 -3
  1358. package/node_modules/openai/src/version.ts +2 -1
  1359. package/node_modules/openai/version.js +2 -1
  1360. package/node_modules/openai/version.mjs +2 -1
  1361. package/package.json +6 -6
  1362. package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.js +0 -832
  1363. package/node_modules/@earendil-works/pi-ai/dist/images-models.js +0 -143
  1364. package/node_modules/@earendil-works/pi-ai/dist/providers/openrouter-images.js +0 -22
  1365. /package/node_modules/@aws-sdk/{credential-provider-sso → client-bedrock-runtime}/node_modules/@aws-sdk/token-providers/LICENSE +0 -0
  1366. /package/node_modules/@aws-sdk/{credential-provider-sso → client-bedrock-runtime}/node_modules/@aws-sdk/token-providers/README.md +0 -0
  1367. /package/node_modules/@aws-sdk/{credential-provider-sso → client-bedrock-runtime}/node_modules/@aws-sdk/token-providers/dist-cjs/index.js +0 -0
  1368. /package/node_modules/@aws-sdk/{credential-provider-sso → client-bedrock-runtime}/node_modules/@aws-sdk/token-providers/dist-es/constants.js +0 -0
  1369. /package/node_modules/@aws-sdk/{credential-provider-sso → client-bedrock-runtime}/node_modules/@aws-sdk/token-providers/dist-es/fromEnvSigningName.js +0 -0
  1370. /package/node_modules/@aws-sdk/{credential-provider-sso → client-bedrock-runtime}/node_modules/@aws-sdk/token-providers/dist-es/fromSso.js +0 -0
  1371. /package/node_modules/@aws-sdk/{credential-provider-sso → client-bedrock-runtime}/node_modules/@aws-sdk/token-providers/dist-es/fromStatic.js +0 -0
  1372. /package/node_modules/@aws-sdk/{credential-provider-sso → client-bedrock-runtime}/node_modules/@aws-sdk/token-providers/dist-es/getNewSsoOidcToken.js +0 -0
  1373. /package/node_modules/@aws-sdk/{credential-provider-sso → client-bedrock-runtime}/node_modules/@aws-sdk/token-providers/dist-es/getSsoOidcClient.js +0 -0
  1374. /package/node_modules/@aws-sdk/{credential-provider-sso → client-bedrock-runtime}/node_modules/@aws-sdk/token-providers/dist-es/index.js +0 -0
  1375. /package/node_modules/@aws-sdk/{credential-provider-sso → client-bedrock-runtime}/node_modules/@aws-sdk/token-providers/dist-es/nodeProvider.js +0 -0
  1376. /package/node_modules/@aws-sdk/{credential-provider-sso → client-bedrock-runtime}/node_modules/@aws-sdk/token-providers/dist-es/validateTokenExpiry.js +0 -0
  1377. /package/node_modules/@aws-sdk/{credential-provider-sso → client-bedrock-runtime}/node_modules/@aws-sdk/token-providers/dist-es/validateTokenKey.js +0 -0
  1378. /package/node_modules/@aws-sdk/{credential-provider-sso → client-bedrock-runtime}/node_modules/@aws-sdk/token-providers/dist-es/writeSSOTokenToFile.js +0 -0
  1379. /package/node_modules/@earendil-works/pi-ai/dist/{auth/oauth → utils}/oauth-page.js +0 -0
@@ -1,145 +1,1334 @@
1
- import { partialParse } from '../_vendor/partial-json-parser/parser';
1
+ import { MalformedJSON, partialParse } from '../_vendor/partial-json-parser/parser';
2
+ import { APIError, ContentFilterFinishReasonError, LengthFinishReasonError, OpenAIError } from '../error';
3
+ import type OpenAI from '../index';
4
+ import { observeJSONRequestBody, type RequestOptions } from '../internal/request-options';
5
+ import type { ReadableStream } from '../internal/shim-types';
6
+ import { uuid4 } from '../internal/utils/uuid';
7
+ import { hasOwn } from '../internal/utils/values';
2
8
  import {
3
- APIUserAbortError,
4
- ContentFilterFinishReasonError,
5
- LengthFinishReasonError,
6
- OpenAIError,
7
- } from '../error';
8
- import OpenAI from '../index';
9
- import { RequestOptions } from '../internal/request-options';
10
- import { type ReadableStream } from '../internal/shim-types';
11
- import {
12
- AutoParseableResponseFormat,
13
9
  hasAutoParseableInput,
14
- isAutoParsableResponseFormat,
15
10
  isAutoParsableTool,
16
11
  isChatCompletionFunctionTool,
12
+ isParseableResponseFormat,
17
13
  maybeParseChatCompletion,
14
+ parseResponseFormatContent,
18
15
  shouldParseToolCall,
19
16
  } from '../lib/parser';
20
- import { ChatCompletionFunctionTool, ParsedChatCompletion } from '../resources/chat/completions';
21
- import {
17
+ import type { ChatCompletionFunctionTool, ParsedChatCompletion } from '../resources/chat/completions';
18
+ import type {
19
+ ChatCompletionAudio,
20
+ ChatCompletion,
21
+ ChatCompletionChunk,
22
+ ChatCompletionCreateParams,
23
+ ChatCompletionCreateParamsBase,
24
+ ChatCompletionCreateParamsStreaming,
25
+ ChatCompletionMessageParam,
26
+ ChatCompletionMessageToolCall,
27
+ ChatCompletionRole,
22
28
  ChatCompletionTokenLogprob,
23
- type ChatCompletion,
24
- type ChatCompletionChunk,
25
- type ChatCompletionCreateParams,
26
- type ChatCompletionCreateParamsBase,
27
- type ChatCompletionCreateParamsStreaming,
28
- type ChatCompletionRole,
29
29
  } from '../resources/chat/completions/completions';
30
30
  import { Stream } from '../streaming';
31
- import {
32
- AbstractChatCompletionRunner,
33
- type AbstractChatCompletionRunnerEvents,
34
- } from './AbstractChatCompletionRunner';
31
+ import { AbstractChatCompletionRunner } from './AbstractChatCompletionRunner';
32
+ import type { AbstractChatCompletionRunnerEvents, RunnerOptions } from './AbstractChatCompletionRunner';
33
+ import type {
34
+ ChatCompletionRunner,
35
+ ChatCompletionToolRunnerParamsWithContext,
36
+ ChatCompletionToolRunnerParamsWithoutContext,
37
+ } from './ChatCompletionRunner';
38
+ import type {
39
+ ChatCompletionStreamingRunner,
40
+ ChatCompletionStreamingToolRunnerParamsWithContext,
41
+ ChatCompletionStreamingToolRunnerParamsWithoutContext,
42
+ } from './ChatCompletionStreamingRunner';
43
+ import type { BaseFunctionsArgs } from './RunnableFunction';
44
+
45
+ // oxlint-disable-next-line anti-slop/no-unknown-returns -- Partial JSON may have any shape; callers validate or parse it against their response schema.
46
+ function parseStructuredStreamingJSON(content: string): unknown {
47
+ try {
48
+ return partialParse(content);
49
+ } catch (error) {
50
+ if (error instanceof MalformedJSON || error instanceof SyntaxError) {
51
+ return parseResponseFormatContent({ type: 'json_schema', $parseRaw: undefined }, content);
52
+ }
35
53
 
54
+ throw error;
55
+ }
56
+ }
57
+
58
+ /** An incremental assistant-text event and its accumulated state. */
36
59
  export interface ContentDeltaEvent {
60
+ /** The new text received in this chunk. */
37
61
  delta: string;
62
+ /** All assistant text received for this choice, including `delta`. */
38
63
  snapshot: string;
64
+ /** The partially parsed structured output when an auto-parseable response format is supplied. */
39
65
  parsed: unknown | null;
40
66
  }
41
67
 
68
+ /** The completed assistant-text content and its fully parsed structured value. */
42
69
  export interface ContentDoneEvent<ParsedT = null> {
70
+ /** The complete assistant text for the finished choice. */
43
71
  content: string;
72
+ /** The fully parsed structured output, or `null` when no parser was supplied. */
44
73
  parsed: ParsedT | null;
45
74
  }
46
75
 
76
+ /** An incremental refusal-text event and its accumulated state. */
47
77
  export interface RefusalDeltaEvent {
78
+ /** The new refusal text received in this chunk. */
48
79
  delta: string;
80
+ /** All refusal text received for this choice, including `delta`. */
49
81
  snapshot: string;
50
82
  }
51
83
 
84
+ /** The complete refusal text emitted when the refusal finishes. */
52
85
  export interface RefusalDoneEvent {
86
+ /** The model's complete refusal message. */
53
87
  refusal: string;
54
88
  }
55
89
 
90
+ /** An incremental function-tool argument event and its accumulated JSON state. */
56
91
  export interface FunctionToolCallArgumentsDeltaEvent {
92
+ /** The name of the function being called. */
57
93
  name: string;
58
94
 
95
+ /** The position of this tool call within the assistant message. */
59
96
  index: number;
60
97
 
98
+ /** The complete argument JSON received so far, including `arguments_delta`. */
61
99
  arguments: string;
62
100
 
101
+ /** The partially parsed arguments when the matching tool supports parsing. */
63
102
  parsed_arguments: unknown;
64
103
 
104
+ /** The new argument JSON fragment received in this chunk. */
65
105
  arguments_delta: string;
66
106
  }
67
107
 
108
+ /** The final raw and parsed arguments for a completed function-tool call. */
68
109
  export interface FunctionToolCallArgumentsDoneEvent {
110
+ /** The name of the function being called. */
69
111
  name: string;
70
112
 
113
+ /** The position of this tool call within the assistant message. */
71
114
  index: number;
72
115
 
116
+ /** The complete JSON argument string produced for the tool call. */
73
117
  arguments: string;
74
118
 
119
+ /** The fully parsed arguments when the matching tool supports parsing. */
75
120
  parsed_arguments: unknown;
76
121
  }
77
122
 
123
+ /** Newly received assistant-content token probabilities and their accumulated snapshot. */
78
124
  export interface LogProbsContentDeltaEvent {
79
- content: Array<ChatCompletionTokenLogprob>;
80
- snapshot: Array<ChatCompletionTokenLogprob>;
125
+ /** Token probabilities received in the current chunk. */
126
+ content: ChatCompletionTokenLogprob[];
127
+ /** All assistant-content token probabilities received for this choice. */
128
+ snapshot: ChatCompletionTokenLogprob[];
81
129
  }
82
130
 
131
+ /** The complete assistant-content token probabilities for a finished choice. */
83
132
  export interface LogProbsContentDoneEvent {
84
- content: Array<ChatCompletionTokenLogprob>;
133
+ /** Every assistant-content token probability produced for this choice. */
134
+ content: ChatCompletionTokenLogprob[];
85
135
  }
86
136
 
137
+ /** Newly received refusal-token probabilities and their accumulated snapshot. */
87
138
  export interface LogProbsRefusalDeltaEvent {
88
- refusal: Array<ChatCompletionTokenLogprob>;
89
- snapshot: Array<ChatCompletionTokenLogprob>;
139
+ /** Refusal-token probabilities received in the current chunk. */
140
+ refusal: ChatCompletionTokenLogprob[];
141
+ /** All refusal-token probabilities received for this choice. */
142
+ snapshot: ChatCompletionTokenLogprob[];
90
143
  }
91
144
 
145
+ /** The complete refusal-token probabilities for a finished choice. */
92
146
  export interface LogProbsRefusalDoneEvent {
93
- refusal: Array<ChatCompletionTokenLogprob>;
147
+ /** Every refusal-token probability produced for this choice. */
148
+ refusal: ChatCompletionTokenLogprob[];
94
149
  }
95
150
 
151
+ /** Event listeners supported by a streamed Chat Completions helper. */
96
152
  export interface ChatCompletionStreamEvents<ParsedT = null> extends AbstractChatCompletionRunnerEvents {
153
+ /** Called with each new text fragment and the complete text accumulated so far. */
97
154
  content: (contentDelta: string, contentSnapshot: string) => void;
155
+ /** Called with each raw API chunk and its accumulated chat-completion snapshot. */
98
156
  chunk: (chunk: ChatCompletionChunk, snapshot: ChatCompletionSnapshot) => void;
99
157
 
158
+ /** Called when assistant text arrives, including any partially parsed output. */
100
159
  'content.delta': (props: ContentDeltaEvent) => void;
160
+ /** Called once the assistant text is complete and can be fully parsed. */
101
161
  'content.done': (props: ContentDoneEvent<ParsedT>) => void;
102
162
 
163
+ /** Called when another fragment of a model refusal arrives. */
103
164
  'refusal.delta': (props: RefusalDeltaEvent) => void;
165
+ /** Called once the model's complete refusal is available. */
104
166
  'refusal.done': (props: RefusalDoneEvent) => void;
105
167
 
168
+ /** Called when another JSON argument fragment arrives for a function tool. */
106
169
  'tool_calls.function.arguments.delta': (props: FunctionToolCallArgumentsDeltaEvent) => void;
170
+ /** Called once a function tool's complete arguments are available. */
107
171
  'tool_calls.function.arguments.done': (props: FunctionToolCallArgumentsDoneEvent) => void;
108
172
 
173
+ /** Called when assistant-content token probabilities arrive. */
109
174
  'logprobs.content.delta': (props: LogProbsContentDeltaEvent) => void;
175
+ /** Called once all assistant-content token probabilities are available. */
110
176
  'logprobs.content.done': (props: LogProbsContentDoneEvent) => void;
111
177
 
178
+ /** Called when refusal-token probabilities arrive. */
112
179
  'logprobs.refusal.delta': (props: LogProbsRefusalDeltaEvent) => void;
180
+ /** Called once all refusal-token probabilities are available. */
113
181
  'logprobs.refusal.done': (props: LogProbsRefusalDoneEvent) => void;
114
182
  }
115
183
 
184
+ /** Chat completion request parameters accepted by the streaming convenience helper. */
116
185
  export type ChatCompletionStreamParams = Omit<ChatCompletionCreateParamsBase, 'stream'> & {
186
+ /** Streaming is always enabled by the helper and may be specified explicitly. */
117
187
  stream?: true;
118
188
  };
119
189
 
190
+ /** A conversation message embedded in a serialized chat completion stream. */
191
+ type ChatCompletionReadableStreamMessage = {
192
+ /** Identifies this readable-stream item as a serialized conversation message. */
193
+ type: 'message';
194
+ /** The conversation message to restore while replaying the serialized stream. */
195
+ message: ChatCompletionMessageParam;
196
+ /** Tool-call identifiers to restore on the preceding assistant completion. */
197
+ tool_call_ids?: string[];
198
+ };
199
+
200
+ // Keep message records readable as empty chunks by older SDKs. Their finalizer
201
+ // overwrites `object`, so the encoded payload does not leak into completions.
202
+ const CHAT_COMPLETION_READABLE_STREAM_MESSAGE_PREFIX = 'chat.completion.chunk.message:';
203
+
204
+ /** A serialized conversation message disguised as a backwards-compatible empty completion chunk. */
205
+ type ChatCompletionReadableStreamMessageChunk = Pick<ChatCompletionChunk, 'id' | 'created' | 'model'> & {
206
+ /** Empty choices keep the encoded message compatible with older completion-stream readers. */
207
+ choices: [];
208
+ /** Reserved object prefix followed by the JSON-encoded conversation-message payload. */
209
+ object: `${typeof CHAT_COMPLETION_READABLE_STREAM_MESSAGE_PREFIX}${string}`;
210
+ };
211
+
212
+ /** A raw completion chunk or serialized message preserved in a transportable stream. */
213
+ export type ChatCompletionReadableStreamItem =
214
+ | ChatCompletionChunk
215
+ | ChatCompletionReadableStreamMessage
216
+ | ChatCompletionReadableStreamMessageChunk;
217
+
218
+ /** Encodes a tool-result message as a backwards-compatible, empty completion chunk. */
219
+ export function makeChatCompletionReadableStreamMessageChunk(
220
+ chunk: ChatCompletionChunk,
221
+ message: ChatCompletionMessageParam,
222
+ toolCallIds?: string[],
223
+ ): ChatCompletionReadableStreamMessageChunk {
224
+ const payload: ChatCompletionReadableStreamMessage = {
225
+ type: 'message',
226
+ message,
227
+ // Spread creates an own data property without invoking inherited setters or changing the object prototype.
228
+ ...(toolCallIds ? { tool_call_ids: toolCallIds } : {}),
229
+ };
230
+
231
+ return {
232
+ id: chunk.id,
233
+ choices: [],
234
+ created: chunk.created,
235
+ model: chunk.model,
236
+ object: `${CHAT_COMPLETION_READABLE_STREAM_MESSAGE_PREFIX}${JSON.stringify(payload)}`,
237
+ };
238
+ }
239
+
240
+ function isChatCompletionReadableStreamMessage(
241
+ item: ChatCompletionReadableStreamItem,
242
+ ): item is ChatCompletionReadableStreamMessage | ChatCompletionReadableStreamMessageChunk {
243
+ return (
244
+ ('type' in item && item.type === 'message' && 'message' in item) ||
245
+ ('object' in item &&
246
+ typeof item.object === 'string' &&
247
+ item.object.startsWith(CHAT_COMPLETION_READABLE_STREAM_MESSAGE_PREFIX))
248
+ );
249
+ }
250
+
251
+ function getChatCompletionReadableStreamMessage(
252
+ item: ChatCompletionReadableStreamMessage | ChatCompletionReadableStreamMessageChunk,
253
+ ): ChatCompletionReadableStreamMessage {
254
+ if ('type' in item) {
255
+ return item;
256
+ }
257
+
258
+ // SAFETY: This decoder reads the SDK's tagged readable-stream envelope; JSON parsing restores its serialized message fields for the stream accumulator.
259
+ return JSON.parse(
260
+ item.object.slice(CHAT_COMPLETION_READABLE_STREAM_MESSAGE_PREFIX.length),
261
+ ) as ChatCompletionReadableStreamMessage;
262
+ }
263
+
264
+ /**
265
+ * A tool call snapshot while it is still being accumulated from stream chunks.
266
+ *
267
+ * Every property is optional because the deltas that make up a tool call arrive
268
+ * across chunks; once they have all been accumulated the entry satisfies
269
+ * {@link ChatCompletionSnapshot.Choice.Message.ToolCall}.
270
+ */
271
+ type PartialToolCallSnapshot = {
272
+ id?: string;
273
+ type?: ChatCompletionSnapshot.Choice.Message.ToolCall['type'];
274
+ function?: ChatCompletionSnapshot.Choice.Message.ToolCall.Function;
275
+ custom?: ChatCompletionSnapshot.Choice.Message.ToolCall.CustomToolCall.Custom;
276
+ };
277
+
120
278
  interface ChoiceEventState {
121
279
  content_done: boolean;
280
+ content_parse_state: PartialJSONParseState | undefined;
122
281
  refusal_done: boolean;
123
282
  logprobs_content_done: boolean;
124
283
  logprobs_refusal_done: boolean;
125
284
  current_tool_call_index: number | null;
126
285
  done_tool_calls: Set<number>;
286
+ tool_call_parse_states: Map<number, PartialJSONParseState>;
287
+ tool_call_identities: Map<number, ToolCallIdentity>;
288
+ }
289
+
290
+ interface CapturedToolCallDeltaFrame {
291
+ readonly index: number;
292
+ readonly arguments_delta: string;
293
+ }
294
+
295
+ interface CapturedChoiceToolCallFrames {
296
+ readonly index: number;
297
+ readonly tool_calls: readonly CapturedToolCallDeltaFrame[];
298
+ }
299
+
300
+ interface ValidatedChoiceSnapshot {
301
+ message: ChatCompletionSnapshot.Choice.Message;
302
+ content: string | null | undefined;
303
+ refusal: string | null | undefined;
304
+ toolCallCollection: ChatCompletionSnapshot.Choice.Message.ToolCall[] | undefined;
305
+ toolCalls: ReadonlyMap<number, ValidatedToolCallSnapshot>;
306
+ }
307
+
308
+ interface ValidatedToolCallSnapshot {
309
+ tool: ChatCompletionSnapshot.Choice.Message.ToolCall;
310
+ function: ChatCompletionSnapshot.Choice.Message.ToolCall.Function;
311
+ type: 'function';
312
+ name: string;
313
+ arguments: string;
314
+ }
315
+
316
+ interface ToolCallIdentity {
317
+ type: 'function';
318
+ name: string;
319
+ parseable: boolean;
320
+ }
321
+
322
+ interface PartialJSONParseState {
323
+ bytes: number;
324
+ depth: number;
325
+ fragments: number;
326
+ work: number;
327
+ escaped: boolean;
328
+ has_non_whitespace: boolean;
329
+ in_string: boolean;
330
+ last_parsed_bytes: number;
331
+ pending_high_surrogate: boolean;
332
+ }
333
+
334
+ interface PartialJSONParseBudget {
335
+ bytes: number;
336
+ fragments: number;
337
+ work: number;
338
+ }
339
+
340
+ // The Chat Completions schema limits n to 128. Replayed streams do not retain
341
+ // request parameters, so apply that choice limit independently and use the same
342
+ // conservative ceiling to prevent sparse tool-call arrays from growing unbounded.
343
+ const MAX_STREAM_CHOICES = 128;
344
+ const MAX_STREAM_TOOL_CALLS = 128;
345
+ const MAX_PARTIAL_JSON_BYTES = 16 * 1024 * 1024;
346
+ const MAX_PARTIAL_JSON_FRAGMENTS = 65_536;
347
+ const MAX_PARTIAL_JSON_DEPTH = 128;
348
+ const MAX_PARTIAL_JSON_PARSE_WORK = 64 * 1024 * 1024;
349
+ const EAGER_PARTIAL_JSON_BYTES = 1024;
350
+
351
+ function createPartialJSONParseState(): PartialJSONParseState {
352
+ return {
353
+ bytes: 0,
354
+ depth: 0,
355
+ fragments: 0,
356
+ work: 0,
357
+ escaped: false,
358
+ has_non_whitespace: false,
359
+ in_string: false,
360
+ last_parsed_bytes: 0,
361
+ pending_high_surrogate: false,
362
+ };
363
+ }
364
+
365
+ function recordPartialJSONFragment(
366
+ state: PartialJSONParseState,
367
+ budget: PartialJSONParseBudget,
368
+ fragment: string,
369
+ validationWorkBudget?: PartialJSONParseBudget,
370
+ ): boolean {
371
+ if (budget.fragments >= MAX_PARTIAL_JSON_FRAGMENTS) {
372
+ throw new OpenAIError('Chat completion stream exceeded its structured JSON fragment limit');
373
+ }
374
+
375
+ let bytes = 0;
376
+ let { depth, escaped, has_non_whitespace: hasNonWhitespace, in_string: inString } = state;
377
+ let completed = false;
378
+ let firstCharacter = true;
379
+
380
+ for (const character of fragment) {
381
+ const previousBytes = bytes;
382
+ const codePoint = character.codePointAt(0)!;
383
+ if (firstCharacter && state.pending_high_surrogate && codePoint >= 0xdc_00 && codePoint <= 0xdf_ff) {
384
+ bytes += 1;
385
+ } else if (codePoint <= 0x7f) {
386
+ bytes += 1;
387
+ } else if (codePoint <= 0x7_ff) {
388
+ bytes += 2;
389
+ } else if (codePoint <= 0xff_ff) {
390
+ bytes += 3;
391
+ } else {
392
+ bytes += 4;
393
+ }
394
+ firstCharacter = false;
395
+ if (budget.bytes + bytes > MAX_PARTIAL_JSON_BYTES) {
396
+ throw new OpenAIError('Chat completion stream exceeded its structured JSON byte limit');
397
+ }
398
+ if (validationWorkBudget && validationWorkBudget.work + bytes > MAX_PARTIAL_JSON_PARSE_WORK) {
399
+ validationWorkBudget.work += previousBytes;
400
+ throw new OpenAIError('Chat completion stream exceeded its structured JSON parse-work limit');
401
+ }
402
+
403
+ if (character !== ' ' && character !== '\n' && character !== '\r' && character !== '\t') {
404
+ hasNonWhitespace = true;
405
+ }
406
+
407
+ if (inString) {
408
+ if (escaped) {
409
+ escaped = false;
410
+ } else if (character === '\\') {
411
+ escaped = true;
412
+ } else if (character === '"') {
413
+ inString = false;
414
+ completed ||= depth === 0;
415
+ }
416
+ continue;
417
+ }
418
+
419
+ if (character === '"') {
420
+ inString = true;
421
+ } else if (character === '{' || character === '[') {
422
+ depth += 1;
423
+ if (depth > MAX_PARTIAL_JSON_DEPTH) {
424
+ throw new OpenAIError('Chat completion stream exceeded its structured JSON nesting depth limit');
425
+ }
426
+ } else if ((character === '}' || character === ']') && depth > 0) {
427
+ depth -= 1;
428
+ completed ||= depth === 0;
429
+ }
430
+ }
431
+
432
+ state.bytes += bytes;
433
+ state.fragments += 1;
434
+ state.depth = depth;
435
+ state.escaped = escaped;
436
+ state.has_non_whitespace = hasNonWhitespace;
437
+ state.in_string = inString;
438
+ if (fragment.length > 0) {
439
+ const finalCodeUnit = fragment.codePointAt(fragment.length - 1) ?? 0;
440
+ state.pending_high_surrogate = finalCodeUnit >= 0xd8_00 && finalCodeUnit <= 0xdb_ff;
441
+ }
442
+ budget.bytes += bytes;
443
+ budget.fragments += 1;
444
+ if (validationWorkBudget) {
445
+ validationWorkBudget.work += bytes;
446
+ }
447
+
448
+ if (!hasNonWhitespace || bytes === 0) {
449
+ return false;
450
+ }
451
+
452
+ const minimumGrowth = Math.max(EAGER_PARTIAL_JSON_BYTES, Math.floor(state.last_parsed_bytes / 2));
453
+ if (
454
+ state.bytes > EAGER_PARTIAL_JSON_BYTES &&
455
+ !completed &&
456
+ state.bytes - state.last_parsed_bytes < minimumGrowth
457
+ ) {
458
+ return false;
459
+ }
460
+
461
+ return true;
462
+ }
463
+
464
+ function reservePartialJSONParse(state: PartialJSONParseState, budget: PartialJSONParseBudget): boolean {
465
+ if (budget.work + state.bytes > MAX_PARTIAL_JSON_PARSE_WORK) {
466
+ return false;
467
+ }
468
+
469
+ budget.work += state.bytes;
470
+ state.work += state.bytes;
471
+ state.last_parsed_bytes = state.bytes;
472
+ return true;
473
+ }
474
+
475
+ function captureStructuredJSONSnapshot(
476
+ snapshot: ChatCompletionSnapshot.Choice.Message | ChatCompletionSnapshot.Choice.Message.ToolCall.Function,
477
+ property: 'content' | 'arguments' | 'refusal',
478
+ ): string | null | undefined {
479
+ const descriptor = Object.getOwnPropertyDescriptor(snapshot, property);
480
+ if (!descriptor) {
481
+ // SAFETY: Object.getPrototypeOf returns an object or null; the following traversal checks inherited properties without assuming a specific prototype type.
482
+ let prototype = Object.getPrototypeOf(snapshot) as object | null;
483
+ for (let depth = 0; prototype !== null; depth += 1) {
484
+ if (depth >= MAX_PARTIAL_JSON_DEPTH || Object.getOwnPropertyDescriptor(prototype, property)) {
485
+ throw new OpenAIError('Chat completion stream contains an unsafe structured JSON snapshot');
486
+ }
487
+ // SAFETY: Object.getPrototypeOf returns an object or null; the following traversal checks inherited properties without assuming a specific prototype type.
488
+ prototype = Object.getPrototypeOf(prototype) as object | null;
489
+ }
490
+ return undefined;
491
+ }
492
+ if (
493
+ !('value' in descriptor) ||
494
+ (typeof descriptor.value !== 'string' && descriptor.value !== null && descriptor.value !== undefined)
495
+ ) {
496
+ throw new OpenAIError('Chat completion stream contains an unsafe structured JSON snapshot');
497
+ }
498
+
499
+ // SAFETY: The own data descriptor was explicitly checked to contain only a string, null, or undefined.
500
+ return descriptor.value as string | null | undefined;
501
+ }
502
+
503
+ function captureStructuredMessageSnapshot(
504
+ choice: ChatCompletionSnapshot.Choice,
505
+ ): ChatCompletionSnapshot.Choice.Message {
506
+ const descriptor = Object.getOwnPropertyDescriptor(choice, 'message');
507
+ if (
508
+ !descriptor ||
509
+ !('value' in descriptor) ||
510
+ typeof descriptor.value !== 'object' ||
511
+ descriptor.value === null
512
+ ) {
513
+ throw new OpenAIError('Chat completion stream contains an unsafe structured JSON snapshot');
514
+ }
515
+
516
+ // SAFETY: The choice contract supplies a message; the own data descriptor check prevents getters from changing which object is captured.
517
+ return descriptor.value as ChatCompletionSnapshot.Choice.Message;
518
+ }
519
+
520
+ function captureSnapshotArray<Item>(
521
+ snapshot: ChatCompletionSnapshot | ChatCompletionSnapshot.Choice.Message,
522
+ property: 'choices' | 'tool_calls',
523
+ maximum: number,
524
+ kind: 'choice' | 'tool-call',
525
+ ): Item[] | undefined {
526
+ const descriptor = Object.getOwnPropertyDescriptor(snapshot, property);
527
+ if (!descriptor) {
528
+ // SAFETY: Object.getPrototypeOf returns an object or null; the following traversal checks inherited properties without assuming a specific prototype type.
529
+ let prototype = Object.getPrototypeOf(snapshot) as object | null;
530
+ for (let depth = 0; prototype !== null; depth += 1) {
531
+ if (depth >= MAX_PARTIAL_JSON_DEPTH || Object.getOwnPropertyDescriptor(prototype, property)) {
532
+ throw new OpenAIError(`Chat completion stream contains an unsafe snapshot ${kind} collection`);
533
+ }
534
+ // SAFETY: Object.getPrototypeOf returns an object or null; the following traversal checks inherited properties without assuming a specific prototype type.
535
+ prototype = Object.getPrototypeOf(prototype) as object | null;
536
+ }
537
+ return undefined;
538
+ }
539
+ if (!('value' in descriptor) || !Array.isArray(descriptor.value)) {
540
+ throw new OpenAIError(`Chat completion stream contains an unsafe snapshot ${kind} collection`);
541
+ }
542
+
543
+ const length = Object.getOwnPropertyDescriptor(descriptor.value, 'length');
544
+ if (!length || !('value' in length) || !Number.isSafeInteger(length.value) || length.value > maximum) {
545
+ throw new OpenAIError(`Chat completion stream exceeded its snapshot ${kind} limit`);
546
+ }
547
+
548
+ // SAFETY: The captured data property is an array with a checked bounded length; Item comes from the owning snapshot collection's contract.
549
+ return descriptor.value as Item[];
550
+ }
551
+
552
+ function captureSnapshotArrayItem<Item>(array: Item[], index: number): Item | undefined {
553
+ const descriptor = Object.getOwnPropertyDescriptor(array, index);
554
+ if (!descriptor) {
555
+ return undefined;
556
+ }
557
+ if (!('value' in descriptor)) {
558
+ throw new OpenAIError('Chat completion stream contains an unsafe structured JSON snapshot');
559
+ }
560
+
561
+ // SAFETY: The descriptor is a data property of the typed Item array, so its value retains that array's element contract.
562
+ return descriptor.value as Item;
563
+ }
564
+
565
+ function mapCapturedSnapshotArray<Item, Mapped>(
566
+ array: Item[],
567
+ maximum: number,
568
+ kind: 'choice' | 'tool-call',
569
+ map: (item: Item, index: number) => Mapped,
570
+ ): Mapped[] {
571
+ const descriptor = Object.getOwnPropertyDescriptor(array, 'length');
572
+ const length: unknown = descriptor && 'value' in descriptor ? descriptor.value : undefined;
573
+ if (typeof length !== 'number' || !Number.isSafeInteger(length) || length < 0 || length > maximum) {
574
+ throw new OpenAIError(`Chat completion stream exceeded its snapshot ${kind} limit`);
575
+ }
576
+
577
+ const mapped: Mapped[] = [];
578
+ mapped.length = length;
579
+ for (let index = 0; index < length; index += 1) {
580
+ const item = Object.getOwnPropertyDescriptor(array, index);
581
+ if (!item) {
582
+ continue;
583
+ }
584
+ if (!('value' in item)) {
585
+ throw new OpenAIError('Chat completion stream contains an unsafe structured JSON snapshot');
586
+ }
587
+ // SAFETY: The descriptor is a data property of the typed Item array, so its value retains that array's element contract.
588
+ mapped[index] = map(item.value as Item, index);
589
+ }
590
+
591
+ return mapped;
592
+ }
593
+
594
+ function validateStructuredJSONSnapshot(
595
+ value: string,
596
+ budget?: PartialJSONParseBudget,
597
+ validationWorkBudget?: PartialJSONParseBudget,
598
+ ): string {
599
+ const state = createPartialJSONParseState();
600
+ const parseBudget = budget ?? { bytes: 0, fragments: 0, work: 0 };
601
+ recordPartialJSONFragment(state, parseBudget, value, validationWorkBudget);
602
+ if (!reservePartialJSONParse(state, parseBudget)) {
603
+ throw new OpenAIError('Chat completion stream exceeded its structured JSON parse-work limit');
604
+ }
605
+
606
+ return value;
607
+ }
608
+
609
+ function ownFunctionToolIdentity(
610
+ toolCall: PartialToolCallSnapshot,
611
+ ): Pick<ToolCallIdentity, 'type' | 'name'> | undefined {
612
+ const type = Object.getOwnPropertyDescriptor(toolCall, 'type');
613
+ const fn = Object.getOwnPropertyDescriptor(toolCall, 'function');
614
+ if (!type || !('value' in type) || type.value !== 'function' || !fn || !('value' in fn)) {
615
+ return undefined;
616
+ }
617
+ if (typeof fn.value !== 'object' || fn.value === null) {
618
+ return undefined;
619
+ }
620
+
621
+ const name = Object.getOwnPropertyDescriptor(fn.value, 'name');
622
+ if (!name || !('value' in name) || typeof name.value !== 'string' || name.value.length === 0) {
623
+ return undefined;
624
+ }
625
+
626
+ return { type: 'function', name: name.value };
627
+ }
628
+
629
+ function assertBoundToolCallIdentity(toolCall: PartialToolCallSnapshot, identity: ToolCallIdentity): void {
630
+ const current = ownFunctionToolIdentity(toolCall);
631
+ if (!current || current.name !== identity.name || current.type !== identity.type) {
632
+ throw new OpenAIError('Chat completion stream contains a changed tool call identity');
633
+ }
634
+ }
635
+
636
+ // oxlint-disable-next-line anti-slop/no-object-parameters -- This assignment primitive copies own properties from heterogeneous snapshot and delta objects.
637
+ function assignOwnProperties<T extends object>(target: T, source: object): T {
638
+ if (Object.prototype.propertyIsEnumerable.call(source, '__proto__') && !hasOwn(target, '__proto__')) {
639
+ Object.defineProperty(target, '__proto__', {
640
+ value: undefined,
641
+ writable: true,
642
+ enumerable: true,
643
+ configurable: true,
644
+ });
645
+ }
646
+
647
+ return Object.assign(target, source);
648
+ }
649
+
650
+ function cloneParserConfigObject<Value extends object>(
651
+ value: Value,
652
+ stableFields: readonly PropertyKey[] = [],
653
+ ): Value {
654
+ const descriptors: PropertyDescriptorMap = Object.getOwnPropertyDescriptors(value);
655
+ for (const field of stableFields) {
656
+ const descriptor = descriptors[field];
657
+ if (!descriptor && !(field in value)) {
658
+ continue;
659
+ }
660
+
661
+ descriptors[field] = {
662
+ // oxlint-disable-next-line anti-slop/no-reflect-get -- Generic config cloning must resolve inherited/accessor keys outside the declared config shape.
663
+ value: descriptor && 'value' in descriptor ? descriptor.value : Reflect.get(value, field, value),
664
+ enumerable: descriptor?.enumerable ?? false,
665
+ configurable: descriptor?.configurable ?? true,
666
+ writable: descriptor && 'writable' in descriptor ? descriptor.writable : false,
667
+ };
668
+ }
669
+
670
+ // SAFETY: The clone preserves the original prototype and descriptors, replacing only the parser metadata captured from that same value.
671
+ return Object.create(Object.getPrototypeOf(value), descriptors) as Value;
672
+ }
673
+
674
+ function snapshotChatCompletionParserParams(params: ChatCompletionCreateParams): ChatCompletionCreateParams {
675
+ const snapshot = cloneParserConfigObject(params);
676
+
677
+ if (params.tools) {
678
+ const stableTools: NonNullable<ChatCompletionCreateParams['tools']> = [];
679
+ const lengthDescriptor = Object.getOwnPropertyDescriptor(params.tools, 'length');
680
+ const length = lengthDescriptor && 'value' in lengthDescriptor ? lengthDescriptor.value : undefined;
681
+ const toolCount =
682
+ typeof length === 'number' && Number.isSafeInteger(length) && length >= 0
683
+ ? Math.min(length, MAX_STREAM_TOOL_CALLS)
684
+ : 0;
685
+
686
+ for (let index = 0; index < toolCount; index += 1) {
687
+ const item = Object.getOwnPropertyDescriptor(params.tools, String(index));
688
+ if (!item || !('value' in item)) {
689
+ stableTools.length = index + 1;
690
+ continue;
691
+ }
692
+
693
+ // SAFETY: This own data descriptor comes from the request's typed tools array; the following code captures its parser metadata.
694
+ const tool = item.value as NonNullable<ChatCompletionCreateParams['tools']>[number];
695
+ const stableTool = cloneParserConfigObject(tool, [
696
+ 'type',
697
+ '$brand',
698
+ '$parseRaw',
699
+ '$callback',
700
+ 'function',
701
+ ]);
702
+ const descriptors = Object.getOwnPropertyDescriptors(stableTool);
703
+
704
+ if (isChatCompletionFunctionTool(stableTool)) {
705
+ const descriptor = descriptors.function;
706
+ descriptors.function = {
707
+ ...(descriptor && 'value' in descriptor
708
+ ? descriptor
709
+ : { configurable: true, enumerable: true, writable: true }),
710
+ value: cloneParserConfigObject(stableTool.function, ['name', 'strict']),
711
+ };
712
+ }
713
+
714
+ // SAFETY: The cloned tool retains the original prototype and descriptors while substituting its captured parser configuration.
715
+ stableTools[index] = Object.create(Object.getPrototypeOf(tool), descriptors) as typeof tool;
716
+ }
717
+ snapshot.tools = stableTools;
718
+ }
719
+
720
+ if (params.response_format) {
721
+ snapshot.response_format = cloneParserConfigObject(params.response_format, [
722
+ 'type',
723
+ '$brand',
724
+ '$parseRaw',
725
+ ]);
726
+ }
727
+
728
+ return snapshot;
729
+ }
730
+
731
+ type ChatCompletionInputTool = NonNullable<ChatCompletionCreateParams['tools']>[number];
732
+ type ChatCompletionResponseFormat = NonNullable<ChatCompletionCreateParams['response_format']>;
733
+
734
+ interface SerializedFunctionParserConfig {
735
+ source: ChatCompletionInputTool | undefined;
736
+ schemaMatches: boolean;
737
+ name?: string;
738
+ strict?: boolean;
739
+ }
740
+
741
+ interface SerializedToolParserConfig {
742
+ source: ChatCompletionInputTool | undefined;
743
+ type?: string;
744
+ function?: SerializedFunctionParserConfig;
745
+ }
746
+
747
+ interface SerializedResponseParserConfig {
748
+ source: ChatCompletionResponseFormat | undefined;
749
+ schemaMatches: boolean;
750
+ type?: string;
751
+ }
752
+
753
+ interface SerializedParserSchemaBudget {
754
+ nodes: number;
755
+ bytes: number;
756
+ }
757
+
758
+ const MAX_SERIALIZED_PARSER_SCHEMA_NODES = 4096;
759
+ const stringifyParserSchemaValue = JSON.stringify;
760
+ const MAX_SERIALIZED_PARSER_SCHEMA_BYTES = 1024 * 1024;
761
+ const MAX_SERIALIZED_PARSER_SCHEMA_DEPTH = 64;
762
+ const OMITTED_SERIALIZED_PARSER_VALUE = Symbol('omitted serialized parser value');
763
+ const UNSAFE_SERIALIZED_PARSER_VALUE = Symbol('unsafe serialized parser value');
764
+
765
+ type CanonicalSerializedParserValue =
766
+ | string
767
+ | typeof OMITTED_SERIALIZED_PARSER_VALUE
768
+ | typeof UNSAFE_SERIALIZED_PARSER_VALUE;
769
+
770
+ function canonicalSerializedParserSchema(
771
+ value: unknown,
772
+ budget: SerializedParserSchemaBudget,
773
+ ): string | undefined {
774
+ const ancestors = new WeakSet<object>();
775
+
776
+ const charge = (bytes: number): boolean => {
777
+ if (
778
+ !Number.isSafeInteger(bytes) ||
779
+ bytes < 0 ||
780
+ budget.bytes + bytes > MAX_SERIALIZED_PARSER_SCHEMA_BYTES
781
+ ) {
782
+ return false;
783
+ }
784
+ budget.bytes += bytes;
785
+ return true;
786
+ };
787
+
788
+ // SAFETY: Object.getPrototypeOf returns an object or null; the following traversal checks inherited properties without assuming a specific prototype type.
789
+ const visit = (current: unknown, depth: number): CanonicalSerializedParserValue => {
790
+ if (depth > MAX_SERIALIZED_PARSER_SCHEMA_DEPTH || budget.nodes >= MAX_SERIALIZED_PARSER_SCHEMA_NODES) {
791
+ return UNSAFE_SERIALIZED_PARSER_VALUE;
792
+ }
793
+ budget.nodes += 1;
794
+
795
+ if (current === undefined || typeof current === 'function' || typeof current === 'symbol') {
796
+ return OMITTED_SERIALIZED_PARSER_VALUE;
797
+ }
798
+ if (typeof current === 'bigint') {
799
+ return UNSAFE_SERIALIZED_PARSER_VALUE;
800
+ }
801
+ if (current === null || typeof current === 'boolean' || typeof current === 'number') {
802
+ const serialized = stringifyParserSchemaValue(current);
803
+ return typeof serialized === 'string' && charge(serialized.length)
804
+ ? serialized
805
+ : UNSAFE_SERIALIZED_PARSER_VALUE;
806
+ }
807
+ if (typeof current === 'string') {
808
+ if (!charge(current.length * 6 + 2)) {
809
+ return UNSAFE_SERIALIZED_PARSER_VALUE;
810
+ }
811
+ return stringifyParserSchemaValue(current);
812
+ }
813
+ if (typeof current !== 'object' || ancestors.has(current)) {
814
+ return UNSAFE_SERIALIZED_PARSER_VALUE;
815
+ }
816
+
817
+ const array = Array.isArray(current);
818
+ // SAFETY: Object.getPrototypeOf returns an object or null; the following traversal checks inherited properties without assuming a specific prototype type.
819
+ const prototype = Object.getPrototypeOf(current) as object | null;
820
+ if (
821
+ (array && prototype !== Array.prototype) ||
822
+ (!array && prototype !== null && prototype !== Object.prototype)
823
+ ) {
824
+ return UNSAFE_SERIALIZED_PARSER_VALUE;
825
+ }
826
+
827
+ for (
828
+ let owner: object | null = current;
829
+ owner !== null;
830
+ owner = Object.getPrototypeOf(owner) as object | null
831
+ ) {
832
+ const serializer = Object.getOwnPropertyDescriptor(owner, 'toJSON');
833
+ if (!serializer) {
834
+ continue;
835
+ }
836
+ if (!('value' in serializer) || typeof serializer.value === 'function') {
837
+ return UNSAFE_SERIALIZED_PARSER_VALUE;
838
+ }
839
+ break;
840
+ }
841
+
842
+ ancestors.add(current);
843
+ try {
844
+ if (!charge(2)) {
845
+ return UNSAFE_SERIALIZED_PARSER_VALUE;
846
+ }
847
+
848
+ if (array) {
849
+ const lengthDescriptor = Object.getOwnPropertyDescriptor(current, 'length');
850
+ const length = lengthDescriptor && 'value' in lengthDescriptor ? lengthDescriptor.value : undefined;
851
+ if (
852
+ typeof length !== 'number' ||
853
+ !Number.isSafeInteger(length) ||
854
+ length < 0 ||
855
+ length > MAX_SERIALIZED_PARSER_SCHEMA_NODES - budget.nodes
856
+ ) {
857
+ return UNSAFE_SERIALIZED_PARSER_VALUE;
858
+ }
859
+
860
+ const items: string[] = [];
861
+ for (let index = 0; index < length; index += 1) {
862
+ const key = String(index);
863
+ const descriptor = Object.getOwnPropertyDescriptor(current, key);
864
+ if (!descriptor) {
865
+ if (
866
+ Object.getOwnPropertyDescriptor(Array.prototype, key) ||
867
+ Object.getOwnPropertyDescriptor(Object.prototype, key)
868
+ ) {
869
+ return UNSAFE_SERIALIZED_PARSER_VALUE;
870
+ }
871
+ budget.nodes += 1;
872
+ if (!charge(4)) {
873
+ return UNSAFE_SERIALIZED_PARSER_VALUE;
874
+ }
875
+ items.push('null');
876
+ continue;
877
+ }
878
+ if (!('value' in descriptor)) {
879
+ return UNSAFE_SERIALIZED_PARSER_VALUE;
880
+ }
881
+
882
+ const item = visit(descriptor.value, depth + 1);
883
+ if (item === UNSAFE_SERIALIZED_PARSER_VALUE) {
884
+ return item;
885
+ }
886
+ items.push(item === OMITTED_SERIALIZED_PARSER_VALUE ? 'null' : item);
887
+ }
888
+ return `[${items.join(',')}]`;
889
+ }
890
+
891
+ const keys = Reflect.ownKeys(current);
892
+ if (keys.length > MAX_SERIALIZED_PARSER_SCHEMA_NODES - budget.nodes) {
893
+ return UNSAFE_SERIALIZED_PARSER_VALUE;
894
+ }
895
+
896
+ const entries: [string, unknown][] = [];
897
+ for (const key of keys) {
898
+ if (typeof key !== 'string') {
899
+ continue;
900
+ }
901
+ const descriptor = Object.getOwnPropertyDescriptor(current, key);
902
+ if (!descriptor) {
903
+ return UNSAFE_SERIALIZED_PARSER_VALUE;
904
+ }
905
+ if (!descriptor.enumerable) {
906
+ continue;
907
+ }
908
+ if (!('value' in descriptor)) {
909
+ return UNSAFE_SERIALIZED_PARSER_VALUE;
910
+ }
911
+ entries.push([key, descriptor.value]);
912
+ }
913
+ entries.sort(([left], [right]) => {
914
+ if (left === right) {
915
+ return 0;
916
+ }
917
+ return left < right ? -1 : 1;
918
+ });
919
+
920
+ const fields: string[] = [];
921
+ for (const [key, entry] of entries) {
922
+ const normalized = visit(entry, depth + 1);
923
+ if (normalized === UNSAFE_SERIALIZED_PARSER_VALUE) {
924
+ return normalized;
925
+ }
926
+ if (normalized === OMITTED_SERIALIZED_PARSER_VALUE) {
927
+ continue;
928
+ }
929
+ if (!charge(key.length * 6 + 3)) {
930
+ return UNSAFE_SERIALIZED_PARSER_VALUE;
931
+ }
932
+ fields.push(`${stringifyParserSchemaValue(key)}:${normalized}`);
933
+ }
934
+ return `{${fields.join(',')}}`;
935
+ } finally {
936
+ ancestors.delete(current);
937
+ }
938
+ };
939
+
940
+ try {
941
+ const normalized = visit(value, 0);
942
+ return typeof normalized === 'string' ? normalized : undefined;
943
+ } catch {
944
+ return undefined;
945
+ }
946
+ }
947
+
948
+ function rememberSerializedParserSchema(
949
+ signatures: WeakMap<object, string>,
950
+ // oxlint-disable-next-line anti-slop/no-object-parameters -- Parser owners are tracked by identity before their metadata descriptors are validated.
951
+ source: object,
952
+ // oxlint-disable-next-line anti-slop/no-object-parameters -- Serialized schema holders may be arbitrary objects with hostile accessors or prototypes.
953
+ holder: object,
954
+ key: string,
955
+ ): void {
956
+ const parser = Object.getOwnPropertyDescriptor(source, '$parseRaw');
957
+ const schema = Object.getOwnPropertyDescriptor(holder, key);
958
+ if (
959
+ !parser ||
960
+ !('value' in parser) ||
961
+ typeof parser.value !== 'function' ||
962
+ !schema ||
963
+ !('value' in schema)
964
+ ) {
965
+ return;
966
+ }
967
+
968
+ const normalized = canonicalSerializedParserSchema(schema.value, { nodes: 0, bytes: 0 });
969
+ if (normalized !== undefined) {
970
+ signatures.set(source, normalized);
971
+ }
972
+ }
973
+
974
+ function hasMatchingSerializedParserSchema(
975
+ signatures: WeakMap<object, string>,
976
+ // oxlint-disable-next-line anti-slop/no-object-parameters -- Parser signatures belong to the original object identity, independent of its fields.
977
+ source: object | undefined,
978
+ // oxlint-disable-next-line anti-slop/no-object-parameters -- The schema holder is inspected through own descriptors before its contents are trusted.
979
+ holder: object,
980
+ key: string,
981
+ value: unknown,
982
+ ): boolean {
983
+ const expected = source && signatures.get(source);
984
+ const descriptor = Object.getOwnPropertyDescriptor(holder, key);
985
+ return (
986
+ expected !== undefined &&
987
+ descriptor !== undefined &&
988
+ 'value' in descriptor &&
989
+ canonicalSerializedParserSchema(value, { nodes: 0, bytes: 0 }) === expected
990
+ );
991
+ }
992
+
993
+ function serializedParserDescriptor(
994
+ descriptor: PropertyDescriptor | undefined,
995
+ value: unknown,
996
+ ): PropertyDescriptor {
997
+ return descriptor && 'value' in descriptor
998
+ ? { ...descriptor, value }
999
+ : { configurable: true, enumerable: true, writable: true, value };
1000
+ }
1001
+
1002
+ function shadowSerializedParserMetadata(
1003
+ descriptors: PropertyDescriptorMap,
1004
+ source: ChatCompletionInputTool | ChatCompletionResponseFormat,
1005
+ fields: readonly string[],
1006
+ ): void {
1007
+ for (const field of fields) {
1008
+ const descriptor = descriptors[field];
1009
+ if (!descriptor && !(field in source)) {
1010
+ continue;
1011
+ }
1012
+ descriptors[field] =
1013
+ descriptor && 'value' in descriptor
1014
+ ? { ...descriptor, value: undefined }
1015
+ : {
1016
+ configurable: descriptor?.configurable ?? true,
1017
+ enumerable: descriptor?.enumerable ?? false,
1018
+ writable: false,
1019
+ value: undefined,
1020
+ };
1021
+ }
1022
+ }
1023
+
1024
+ function snapshotSerializedParserTool(serialized: SerializedToolParserConfig): ChatCompletionInputTool {
1025
+ // SAFETY: The fallback is a serialization scaffold: the code below installs the captured wire fields before the tool is returned.
1026
+ const source =
1027
+ serialized.source ??
1028
+ ({
1029
+ type: serialized.type,
1030
+ ...(serialized.type === 'function' ? { function: {} } : {}),
1031
+ } as ChatCompletionInputTool);
1032
+ const descriptors = Object.getOwnPropertyDescriptors(source);
1033
+ descriptors.type = serializedParserDescriptor(descriptors.type, serialized.type);
1034
+
1035
+ if (serialized.type !== 'function' || !serialized.function) {
1036
+ if (descriptors.function) {
1037
+ descriptors.function = serializedParserDescriptor(descriptors.function, undefined);
1038
+ }
1039
+ shadowSerializedParserMetadata(descriptors, source, ['$brand', '$parseRaw', '$callback']);
1040
+ // SAFETY: The descriptors reconstruct the tool's captured serialized fields and shadow parser metadata while retaining its original prototype.
1041
+ return Object.create(Object.getPrototypeOf(source), descriptors) as ChatCompletionInputTool;
1042
+ }
1043
+
1044
+ const descriptor = descriptors.function;
1045
+ // SAFETY: The preceding guard proves this data descriptor contains a non-null object; no more specific type is assumed.
1046
+ const original =
1047
+ descriptor && 'value' in descriptor && typeof descriptor.value === 'object' && descriptor.value !== null
1048
+ ? (descriptor.value as object)
1049
+ : {};
1050
+ const functionDescriptors = Object.getOwnPropertyDescriptors(original);
1051
+ functionDescriptors['name'] = serializedParserDescriptor(
1052
+ functionDescriptors['name'],
1053
+ serialized.function.name,
1054
+ );
1055
+ functionDescriptors['strict'] = serializedParserDescriptor(
1056
+ functionDescriptors['strict'],
1057
+ serialized.function.strict,
1058
+ );
1059
+ descriptors.function = serializedParserDescriptor(
1060
+ descriptor,
1061
+ Object.create(Object.getPrototypeOf(original), functionDescriptors),
1062
+ );
1063
+ if (!serialized.function.schemaMatches) {
1064
+ shadowSerializedParserMetadata(descriptors, source, ['$brand', '$parseRaw', '$callback']);
1065
+ }
1066
+
1067
+ // SAFETY: The descriptors reconstruct the tool's captured serialized fields and shadow parser metadata while retaining its original prototype.
1068
+ return Object.create(Object.getPrototypeOf(source), descriptors) as ChatCompletionInputTool;
1069
+ }
1070
+
1071
+ function snapshotSerializedResponseFormat(
1072
+ serialized: SerializedResponseParserConfig,
1073
+ ): ChatCompletionResponseFormat {
1074
+ // SAFETY: The fallback seeds only the discriminator; the captured response-format fields are installed below before returning it.
1075
+ const source = serialized.source ?? ({ type: serialized.type } as ChatCompletionResponseFormat);
1076
+ const descriptors = Object.getOwnPropertyDescriptors(source);
1077
+ descriptors.type = serializedParserDescriptor(descriptors.type, serialized.type);
1078
+ if (serialized.type !== 'json_schema' || !serialized.source || !serialized.schemaMatches) {
1079
+ shadowSerializedParserMetadata(descriptors, source, ['$brand', '$parseRaw']);
1080
+ }
1081
+ // SAFETY: The descriptors restore the captured response-format fields and parser metadata on the original prototype.
1082
+ return Object.create(Object.getPrototypeOf(source), descriptors) as ChatCompletionResponseFormat;
1083
+ }
1084
+
1085
+ // oxlint-disable-next-line anti-slop/no-object-parameters -- The serialization visitor accepts arbitrary object and array holders, inspecting own descriptors only.
1086
+ function ownSerializedParserObject(holder: object, key: string): object | undefined {
1087
+ const descriptor = Object.getOwnPropertyDescriptor(holder, key);
1088
+ if (!descriptor || !('value' in descriptor)) {
1089
+ return undefined;
1090
+ }
1091
+ const { value } = descriptor;
1092
+ return typeof value === 'object' && value !== null ? value : undefined;
1093
+ }
1094
+
1095
+ function observeSerializedChatCompletionParserParams(
1096
+ body: ChatCompletionCreateParams,
1097
+ initial: ChatCompletionCreateParams,
1098
+ update: (params: ChatCompletionCreateParams) => void,
1099
+ ): () => void {
1100
+ const originalToolOwners = new WeakMap<object, ChatCompletionInputTool>();
1101
+ const originalSchemaSignatures = new WeakMap<object, string>();
1102
+ // At most 128 tools plus one response format each receive an independent
1103
+ // 4,096-node/1 MiB source and wire allowance (129 MiB maximum per pass).
1104
+ if (body.tools) {
1105
+ for (let index = 0; index < body.tools.length && index < MAX_STREAM_TOOL_CALLS; index += 1) {
1106
+ const owner = ownSerializedParserObject(body.tools, String(index));
1107
+ const source = initial.tools?.[index];
1108
+ if (owner && source) {
1109
+ originalToolOwners.set(owner, source);
1110
+ const originalFunction = ownSerializedParserObject(source, 'function');
1111
+ if (originalFunction) {
1112
+ rememberSerializedParserSchema(originalSchemaSignatures, source, originalFunction, 'parameters');
1113
+ }
1114
+ }
1115
+ }
1116
+ }
1117
+ if (initial.response_format) {
1118
+ rememberSerializedParserSchema(
1119
+ originalSchemaSignatures,
1120
+ initial.response_format,
1121
+ initial.response_format,
1122
+ 'json_schema',
1123
+ );
1124
+ }
1125
+ let root: object | undefined;
1126
+ let tools: object | undefined;
1127
+ let responseFormat: object | undefined;
1128
+ let responseFrame: SerializedResponseParserConfig | undefined;
1129
+ let frames: (SerializedToolParserConfig | undefined)[] = [];
1130
+ let toolFrames = new WeakMap<object, SerializedToolParserConfig>();
1131
+ let actualToolOwners = new Map<number, object | undefined>();
1132
+ let functionFrames = new WeakMap<object, SerializedFunctionParserConfig>();
1133
+
1134
+ return observeJSONRequestBody(body, {
1135
+ value(holder, key, value) {
1136
+ if (!root && key === '' && typeof value === 'object' && value !== null) {
1137
+ root = value;
1138
+ tools = undefined;
1139
+ responseFormat = undefined;
1140
+ responseFrame = undefined;
1141
+ frames = [];
1142
+ toolFrames = new WeakMap();
1143
+ actualToolOwners = new Map();
1144
+ functionFrames = new WeakMap();
1145
+ return;
1146
+ }
1147
+
1148
+ if (holder === root && key === 'response_format') {
1149
+ if (typeof value === 'object' && value !== null) {
1150
+ responseFormat = value;
1151
+ const owner = ownSerializedParserObject(holder, key);
1152
+ responseFrame = {
1153
+ source: owner === body.response_format ? initial.response_format : undefined,
1154
+ schemaMatches: false,
1155
+ };
1156
+ }
1157
+ return;
1158
+ }
1159
+
1160
+ if (holder === root && key === 'tools') {
1161
+ if (Array.isArray(value)) {
1162
+ tools = new Proxy(value, {
1163
+ get(target, property) {
1164
+ // SAFETY: Proxy property values may be arbitrary; unknown preserves that uncertainty before the property-specific checks below.
1165
+ // oxlint-disable-next-line anti-slop/no-reflect-get -- Proxy forwarding must preserve arbitrary keys with the original target as accessor receiver.
1166
+ const actual = Reflect.get(target, property, target) as unknown;
1167
+ if (typeof property === 'string') {
1168
+ const index = Number(property);
1169
+ if (
1170
+ Number.isSafeInteger(index) &&
1171
+ index >= 0 &&
1172
+ index < MAX_STREAM_TOOL_CALLS &&
1173
+ String(index) === property
1174
+ ) {
1175
+ actualToolOwners.set(
1176
+ index,
1177
+ typeof actual === 'object' && actual !== null ? actual : undefined,
1178
+ );
1179
+ }
1180
+ }
1181
+ return actual;
1182
+ },
1183
+ });
1184
+ return tools;
1185
+ }
1186
+ return;
1187
+ }
1188
+
1189
+ if (holder === tools) {
1190
+ const index = Number(key);
1191
+ if (
1192
+ !Number.isSafeInteger(index) ||
1193
+ index < 0 ||
1194
+ index >= MAX_STREAM_TOOL_CALLS ||
1195
+ typeof value !== 'object' ||
1196
+ value === null
1197
+ ) {
1198
+ return;
1199
+ }
1200
+ const owner = actualToolOwners.get(index);
1201
+ const source = owner ? originalToolOwners.get(owner) : undefined;
1202
+ const frame: SerializedToolParserConfig = { source };
1203
+ frames[index] = frame;
1204
+ toolFrames.set(value, frame);
1205
+ return;
1206
+ }
1207
+
1208
+ const tool = toolFrames.get(holder);
1209
+ if (tool) {
1210
+ if (key === 'type' && typeof value === 'string') {
1211
+ tool.type = value;
1212
+ } else if (key === 'function' && typeof value === 'object' && value !== null) {
1213
+ const fn: SerializedFunctionParserConfig = { source: tool.source, schemaMatches: false };
1214
+ tool.function = fn;
1215
+ functionFrames.set(value, fn);
1216
+ }
1217
+ return;
1218
+ }
1219
+
1220
+ if (holder === responseFormat && responseFrame) {
1221
+ if (key === 'type' && typeof value === 'string') {
1222
+ responseFrame.type = value;
1223
+ } else if (key === 'json_schema') {
1224
+ responseFrame.schemaMatches = hasMatchingSerializedParserSchema(
1225
+ originalSchemaSignatures,
1226
+ responseFrame.source,
1227
+ holder,
1228
+ key,
1229
+ value,
1230
+ );
1231
+ }
1232
+ return;
1233
+ }
1234
+
1235
+ const fn = functionFrames.get(holder);
1236
+ if (fn) {
1237
+ if (key === 'name' && typeof value === 'string') {
1238
+ fn.name = value;
1239
+ } else if (key === 'strict' && typeof value === 'boolean') {
1240
+ fn.strict = value;
1241
+ } else if (key === 'parameters') {
1242
+ fn.schemaMatches = hasMatchingSerializedParserSchema(
1243
+ originalSchemaSignatures,
1244
+ fn.source,
1245
+ holder,
1246
+ key,
1247
+ value,
1248
+ );
1249
+ }
1250
+ }
1251
+ return undefined;
1252
+ },
1253
+ complete() {
1254
+ if (!root) {
1255
+ return;
1256
+ }
1257
+ const snapshot = cloneParserConfigObject(initial);
1258
+ if (tools) {
1259
+ const serializedTools: ChatCompletionInputTool[] = [];
1260
+ for (let index = 0; index < frames.length; index += 1) {
1261
+ const frame = frames[index];
1262
+ if (frame) {
1263
+ serializedTools[index] = snapshotSerializedParserTool(frame);
1264
+ }
1265
+ }
1266
+ snapshot.tools = serializedTools;
1267
+ } else {
1268
+ delete snapshot.tools;
1269
+ }
1270
+ if (responseFrame) {
1271
+ snapshot.response_format = snapshotSerializedResponseFormat(responseFrame);
1272
+ } else {
1273
+ delete snapshot.response_format;
1274
+ }
1275
+ update(snapshot);
1276
+ root = undefined;
1277
+ tools = undefined;
1278
+ responseFormat = undefined;
1279
+ responseFrame = undefined;
1280
+ frames = [];
1281
+ toolFrames = new WeakMap();
1282
+ actualToolOwners = new Map();
1283
+ functionFrames = new WeakMap();
1284
+ },
1285
+ });
127
1286
  }
128
1287
 
1288
+ /** Streams chat completion chunks while accumulating snapshots, parsed output, and events. */
129
1289
  export class ChatCompletionStream<ParsedT = null>
130
1290
  extends AbstractChatCompletionRunner<ChatCompletionStreamEvents<ParsedT>, ParsedT>
131
1291
  implements AsyncIterable<ChatCompletionChunk>
132
1292
  {
133
1293
  #params: ChatCompletionCreateParams | null;
1294
+ #rejectsUnfinishedTurns = false;
1295
+ #audioDoneChoiceIndexes: Set<number>;
134
1296
  #choiceEventStates: ChoiceEventState[];
135
1297
  #currentChatCompletionSnapshot: ChatCompletionSnapshot | undefined;
1298
+ #hasAutoParseableTool: boolean;
1299
+ #partialJSONParseBudget: PartialJSONParseBudget;
136
1300
 
1301
+ /** Creates an unstarted stream, retaining request parameters for structured-output parsing. */
137
1302
  constructor(params: ChatCompletionCreateParams | null) {
138
1303
  super();
139
1304
  this.#params = params;
1305
+ this.#audioDoneChoiceIndexes = new Set();
140
1306
  this.#choiceEventStates = [];
1307
+ this.#hasAutoParseableTool = false;
1308
+ const tools = params?.tools;
1309
+ const lengthDescriptor = tools && Object.getOwnPropertyDescriptor(tools, 'length');
1310
+ const length = lengthDescriptor && 'value' in lengthDescriptor ? lengthDescriptor.value : undefined;
1311
+ if (tools && typeof length === 'number' && Number.isSafeInteger(length) && length >= 0) {
1312
+ for (let index = 0; index < Math.min(length, MAX_STREAM_TOOL_CALLS); index += 1) {
1313
+ const descriptor = Object.getOwnPropertyDescriptor(tools, String(index));
1314
+ if (!descriptor || !('value' in descriptor)) {
1315
+ continue;
1316
+ }
1317
+ // SAFETY: The descriptor is read from the typed request tools array and checked as an own data property before accessing the tool.
1318
+ const tool = descriptor.value as ChatCompletionInputTool;
1319
+ if (
1320
+ isChatCompletionFunctionTool(tool) &&
1321
+ (isAutoParsableTool(tool) || tool.function.strict === true)
1322
+ ) {
1323
+ this.#hasAutoParseableTool = true;
1324
+ break;
1325
+ }
1326
+ }
1327
+ }
1328
+ this.#partialJSONParseBudget = { bytes: 0, fragments: 0, work: 0 };
141
1329
  }
142
1330
 
1331
+ /** The latest accumulated completion, or `undefined` before a chunk arrives or after finalization. */
143
1332
  get currentChatCompletionSnapshot(): ChatCompletionSnapshot | undefined {
144
1333
  return this.#currentChatCompletionSnapshot;
145
1334
  }
@@ -148,8 +1337,8 @@ export class ChatCompletionStream<ParsedT = null>
148
1337
  * Intended for use on the frontend, consuming a stream produced with
149
1338
  * `.toReadableStream()` on the backend.
150
1339
  *
151
- * Note that messages sent to the model do not appear in `.on('message')`
152
- * in this context.
1340
+ * Original input messages are not included in the serialized stream. Tool-result
1341
+ * messages explicitly serialized by a streaming tool runner are replayed.
153
1342
  */
154
1343
  static fromReadableStream(stream: ReadableStream): ChatCompletionStream<null> {
155
1344
  const runner = new ChatCompletionStream(null);
@@ -157,25 +1346,31 @@ export class ChatCompletionStream<ParsedT = null>
157
1346
  return runner;
158
1347
  }
159
1348
 
1349
+ /** Starts a streaming chat completion request and returns its event-driven helper. */
160
1350
  static createChatCompletion<ParsedT>(
161
1351
  client: OpenAI,
162
1352
  params: ChatCompletionStreamParams,
163
1353
  options?: RequestOptions,
164
1354
  ): ChatCompletionStream<ParsedT> {
1355
+ // SAFETY: The runner forces stream: true when sending this request; the same parameters retain the caller's parsing configuration.
165
1356
  const runner = new ChatCompletionStream<ParsedT>(params as ChatCompletionCreateParamsStreaming);
166
1357
  runner._run(() =>
167
1358
  runner._runChatCompletion(
168
1359
  client,
169
1360
  { ...params, stream: true },
170
- { ...options, headers: { ...options?.headers, 'X-Stainless-Helper-Method': 'stream' } },
1361
+ { ...options, __metadata: { ...options?.__metadata, helperMethod: 'stream' } },
171
1362
  ),
172
1363
  );
173
1364
  return runner;
174
1365
  }
175
1366
 
176
1367
  #beginRequest() {
177
- if (this.ended) return;
1368
+ if (this.ended) {
1369
+ return;
1370
+ }
1371
+ this.#audioDoneChoiceIndexes = new Set();
178
1372
  this.#currentChatCompletionSnapshot = undefined;
1373
+ this.#partialJSONParseBudget = { bytes: 0, fragments: 0, work: 0 };
179
1374
  }
180
1375
 
181
1376
  #getChoiceEventState(choice: ChatCompletionSnapshot.Choice): ChoiceEventState {
@@ -186,57 +1381,70 @@ export class ChatCompletionStream<ParsedT = null>
186
1381
 
187
1382
  state = {
188
1383
  content_done: false,
1384
+ content_parse_state: undefined,
189
1385
  refusal_done: false,
190
1386
  logprobs_content_done: false,
191
1387
  logprobs_refusal_done: false,
192
1388
  done_tool_calls: new Set(),
193
1389
  current_tool_call_index: null,
1390
+ tool_call_parse_states: new Map(),
1391
+ tool_call_identities: new Map(),
194
1392
  };
195
1393
  this.#choiceEventStates[choice.index] = state;
196
1394
  return state;
197
1395
  }
198
1396
 
199
1397
  #addChunk(this: ChatCompletionStream<ParsedT>, chunk: ChatCompletionChunk) {
200
- if (this.ended) return;
1398
+ if (this.ended) {
1399
+ return;
1400
+ }
201
1401
 
202
- const completion = this.#accumulateChatCompletion(chunk);
1402
+ const capturedChoiceFrames = new WeakMap<object, CapturedChoiceToolCallFrames>();
1403
+ const completion = this.#accumulateChatCompletion(chunk, capturedChoiceFrames);
203
1404
  this._emit('chunk', chunk, completion);
204
1405
 
205
1406
  for (const choice of chunk.choices) {
206
- const choiceSnapshot = completion.choices[choice.index]!;
207
-
208
- if (
209
- choice.delta.content != null &&
210
- choiceSnapshot.message?.role === 'assistant' &&
211
- choiceSnapshot.message?.content
212
- ) {
213
- this._emit('content', choice.delta.content, choiceSnapshot.message.content);
1407
+ const capturedChoice = capturedChoiceFrames.get(choice);
1408
+ const choiceSnapshot = completion.choices[capturedChoice?.index ?? choice.index]!;
1409
+ const capturedToolCalls = capturedChoice?.tool_calls ?? [];
1410
+ const { delta } = choice;
1411
+ const structuredResponse = isParseableResponseFormat(this.#params?.response_format);
1412
+ const boundedSnapshot = structuredResponse || this.#hasAutoParseableTool;
1413
+ const messageSnapshot = boundedSnapshot
1414
+ ? captureStructuredMessageSnapshot(choiceSnapshot)
1415
+ : choiceSnapshot.message;
1416
+ const refusal = boundedSnapshot
1417
+ ? captureStructuredJSONSnapshot(messageSnapshot, 'refusal')
1418
+ : messageSnapshot.refusal;
1419
+ const parseableContent = !refusal && structuredResponse;
1420
+ const messageContent = parseableContent
1421
+ ? captureStructuredJSONSnapshot(messageSnapshot, 'content')
1422
+ : messageSnapshot.content;
1423
+
1424
+ if (delta?.content != null && messageSnapshot.role === 'assistant' && messageContent) {
1425
+ this._emit('content', delta.content, messageContent);
214
1426
  this._emit('content.delta', {
215
- delta: choice.delta.content,
216
- snapshot: choiceSnapshot.message.content,
217
- parsed: choiceSnapshot.message.parsed,
1427
+ delta: delta.content,
1428
+ snapshot: messageContent,
1429
+ parsed: messageSnapshot.parsed,
218
1430
  });
219
1431
  }
220
1432
 
221
- if (
222
- choice.delta.refusal != null &&
223
- choiceSnapshot.message?.role === 'assistant' &&
224
- choiceSnapshot.message?.refusal
225
- ) {
1433
+ if (delta?.refusal != null && messageSnapshot.role === 'assistant' && refusal) {
226
1434
  this._emit('refusal.delta', {
227
- delta: choice.delta.refusal,
228
- snapshot: choiceSnapshot.message.refusal,
1435
+ delta: delta.refusal,
1436
+ snapshot: refusal,
229
1437
  });
230
1438
  }
231
1439
 
232
- if (choice.logprobs?.content != null && choiceSnapshot.message?.role === 'assistant') {
1440
+ if (choice.logprobs?.content != null && messageSnapshot.role === 'assistant') {
233
1441
  this._emit('logprobs.content.delta', {
234
1442
  content: choice.logprobs?.content,
235
1443
  snapshot: choiceSnapshot.logprobs?.content ?? [],
236
1444
  });
237
1445
  }
238
1446
 
239
- if (choice.logprobs?.refusal != null && choiceSnapshot.message?.role === 'assistant') {
1447
+ if (choice.logprobs?.refusal != null && messageSnapshot.role === 'assistant') {
240
1448
  this._emit('logprobs.refusal.delta', {
241
1449
  refusal: choice.logprobs?.refusal,
242
1450
  snapshot: choiceSnapshot.logprobs?.refusal ?? [],
@@ -253,7 +1461,7 @@ export class ChatCompletionStream<ParsedT = null>
253
1461
  }
254
1462
  }
255
1463
 
256
- for (const toolCall of choice.delta.tool_calls ?? []) {
1464
+ for (const toolCall of capturedToolCalls) {
257
1465
  if (state.current_tool_call_index !== toolCall.index) {
258
1466
  this.#emitContentDoneEvents(choiceSnapshot);
259
1467
 
@@ -266,22 +1474,33 @@ export class ChatCompletionStream<ParsedT = null>
266
1474
  state.current_tool_call_index = toolCall.index;
267
1475
  }
268
1476
 
269
- for (const toolCallDelta of choice.delta.tool_calls ?? []) {
270
- const toolCallSnapshot = choiceSnapshot.message.tool_calls?.[toolCallDelta.index];
1477
+ for (const toolCallDelta of capturedToolCalls) {
1478
+ const toolCallSnapshot = messageSnapshot.tool_calls?.[toolCallDelta.index];
271
1479
  if (!toolCallSnapshot?.type) {
272
1480
  continue;
273
1481
  }
274
1482
 
275
- if (toolCallSnapshot?.type === 'function') {
1483
+ if (toolCallSnapshot.type === 'function') {
1484
+ const boundIdentity = state.tool_call_identities.get(toolCallDelta.index);
1485
+ let argumentsSnapshot: string;
1486
+ if (boundIdentity?.parseable) {
1487
+ const capturedArguments = captureStructuredJSONSnapshot(toolCallSnapshot.function, 'arguments');
1488
+ if (typeof capturedArguments !== 'string') {
1489
+ throw new OpenAIError('Chat completion stream contains an unsafe structured JSON snapshot');
1490
+ }
1491
+ argumentsSnapshot = capturedArguments;
1492
+ } else {
1493
+ argumentsSnapshot = toolCallSnapshot.function.arguments;
1494
+ }
276
1495
  this._emit('tool_calls.function.arguments.delta', {
277
- name: toolCallSnapshot.function?.name,
1496
+ name: toolCallSnapshot.function.name,
278
1497
  index: toolCallDelta.index,
279
- arguments: toolCallSnapshot.function.arguments,
1498
+ arguments: argumentsSnapshot,
280
1499
  parsed_arguments: toolCallSnapshot.function.parsed_arguments,
281
- arguments_delta: toolCallDelta.function?.arguments ?? '',
1500
+ arguments_delta: toolCallDelta.arguments_delta,
282
1501
  });
283
- } else {
284
- assertNever(toolCallSnapshot?.type);
1502
+ } else if (toolCallSnapshot.type !== 'custom') {
1503
+ assertNever(toolCallSnapshot);
285
1504
  }
286
1505
  }
287
1506
  }
@@ -294,51 +1513,108 @@ export class ChatCompletionStream<ParsedT = null>
294
1513
  return;
295
1514
  }
296
1515
 
297
- const toolCallSnapshot = choiceSnapshot.message.tool_calls?.[toolCallIndex];
1516
+ const messageSnapshot = this.#hasAutoParseableTool
1517
+ ? captureStructuredMessageSnapshot(choiceSnapshot)
1518
+ : choiceSnapshot.message;
1519
+ const toolCallSnapshot = messageSnapshot.tool_calls?.[toolCallIndex];
298
1520
  if (!toolCallSnapshot) {
299
1521
  throw new Error('no tool call snapshot');
300
1522
  }
1523
+ const boundIdentity = state.tool_call_identities.get(toolCallIndex);
1524
+ if (boundIdentity) {
1525
+ assertBoundToolCallIdentity(toolCallSnapshot, boundIdentity);
1526
+ }
1527
+
301
1528
  if (!toolCallSnapshot.type) {
302
1529
  throw new Error('tool call snapshot missing `type`');
303
1530
  }
304
1531
 
305
1532
  if (toolCallSnapshot.type === 'function') {
1533
+ // SAFETY: The find predicate verifies the function-tool discriminator before matching its name; the cast carries that refinement through find.
306
1534
  const inputTool = this.#params?.tools?.find(
307
1535
  (tool) => isChatCompletionFunctionTool(tool) && tool.function.name === toolCallSnapshot.function.name,
308
1536
  ) as ChatCompletionFunctionTool | undefined; // TS doesn't narrow based on isChatCompletionTool
309
1537
 
1538
+ // oxlint-disable-next-line anti-slop/no-known-value-widening -- The initial null is replaced with an arbitrary tool-parser result after snapshot validation.
1539
+ let parsedArguments: unknown = null;
1540
+ const parseable = isAutoParsableTool(inputTool) || inputTool?.function.strict === true;
1541
+ let argumentsSnapshot: string;
1542
+ if (parseable) {
1543
+ if (this.#currentChatCompletionSnapshot) {
1544
+ this.#validateStructuredSnapshots(this.#currentChatCompletionSnapshot);
1545
+ }
1546
+ const capturedArguments = captureStructuredJSONSnapshot(toolCallSnapshot.function, 'arguments');
1547
+ if (typeof capturedArguments !== 'string') {
1548
+ throw new OpenAIError('Chat completion stream contains an unsafe structured JSON snapshot');
1549
+ }
1550
+ argumentsSnapshot = capturedArguments;
1551
+ } else {
1552
+ argumentsSnapshot = toolCallSnapshot.function.arguments;
1553
+ }
1554
+ if (isAutoParsableTool(inputTool)) {
1555
+ parsedArguments = inputTool.$parseRaw(validateStructuredJSONSnapshot(argumentsSnapshot));
1556
+ } else if (inputTool?.function.strict) {
1557
+ parsedArguments = parseResponseFormatContent(
1558
+ { type: 'json_schema', $parseRaw: undefined },
1559
+ validateStructuredJSONSnapshot(argumentsSnapshot),
1560
+ );
1561
+ }
1562
+
1563
+ if (choiceSnapshot.finish_reason) {
1564
+ state.done_tool_calls.add(toolCallIndex);
1565
+ }
310
1566
  this._emit('tool_calls.function.arguments.done', {
311
1567
  name: toolCallSnapshot.function.name,
312
1568
  index: toolCallIndex,
313
- arguments: toolCallSnapshot.function.arguments,
314
- parsed_arguments:
315
- isAutoParsableTool(inputTool) ? inputTool.$parseRaw(toolCallSnapshot.function.arguments)
316
- : inputTool?.function.strict ? JSON.parse(toolCallSnapshot.function.arguments)
317
- : null,
1569
+ arguments: argumentsSnapshot,
1570
+ parsed_arguments: parsedArguments,
318
1571
  });
319
- } else {
320
- assertNever(toolCallSnapshot.type);
1572
+ } else if (toolCallSnapshot.type !== 'custom') {
1573
+ assertNever(toolCallSnapshot);
321
1574
  }
322
1575
  }
323
1576
 
324
1577
  #emitContentDoneEvents(choiceSnapshot: ChatCompletionSnapshot.Choice) {
325
1578
  const state = this.#getChoiceEventState(choiceSnapshot);
326
-
327
- if (choiceSnapshot.message.content && !state.content_done) {
1579
+ const structuredResponse = isParseableResponseFormat(this.#params?.response_format);
1580
+ const boundedSnapshot = structuredResponse || this.#hasAutoParseableTool;
1581
+ const messageSnapshot = boundedSnapshot
1582
+ ? captureStructuredMessageSnapshot(choiceSnapshot)
1583
+ : choiceSnapshot.message;
1584
+ const refusal = boundedSnapshot
1585
+ ? captureStructuredJSONSnapshot(messageSnapshot, 'refusal')
1586
+ : messageSnapshot.refusal;
1587
+ const parseableContent = !refusal && structuredResponse;
1588
+ const content = parseableContent
1589
+ ? captureStructuredJSONSnapshot(messageSnapshot, 'content')
1590
+ : messageSnapshot.content;
1591
+
1592
+ if (
1593
+ content != null &&
1594
+ (content !== '' ||
1595
+ (!refusal && !messageSnapshot.tool_calls?.length && !messageSnapshot.function_call)) &&
1596
+ !state.content_done
1597
+ ) {
1598
+ if (parseableContent && this.#currentChatCompletionSnapshot) {
1599
+ this.#validateStructuredSnapshots(this.#currentChatCompletionSnapshot);
1600
+ }
328
1601
  state.content_done = true;
329
1602
 
330
- const responseFormat = this.#getAutoParseableResponseFormat();
331
-
332
1603
  this._emit('content.done', {
333
- content: choiceSnapshot.message.content,
334
- parsed: responseFormat ? responseFormat.$parseRaw(choiceSnapshot.message.content) : (null as any),
1604
+ content,
1605
+ parsed: refusal
1606
+ ? null
1607
+ : parseResponseFormatContent<ParsedT>(
1608
+ this.#params?.response_format,
1609
+ parseableContent ? validateStructuredJSONSnapshot(content) : content,
1610
+ ),
335
1611
  });
336
1612
  }
337
1613
 
338
- if (choiceSnapshot.message.refusal && !state.refusal_done) {
1614
+ if (refusal && !state.refusal_done) {
339
1615
  state.refusal_done = true;
340
1616
 
341
- this._emit('refusal.done', { refusal: choiceSnapshot.message.refusal });
1617
+ this._emit('refusal.done', { refusal });
342
1618
  }
343
1619
 
344
1620
  if (choiceSnapshot.logprobs?.content && !state.logprobs_content_done) {
@@ -354,6 +1630,120 @@ export class ChatCompletionStream<ParsedT = null>
354
1630
  }
355
1631
  }
356
1632
 
1633
+ #validateStructuredSnapshots(
1634
+ snapshot: ChatCompletionSnapshot,
1635
+ ): WeakMap<ChatCompletionSnapshot.Choice, ValidatedChoiceSnapshot> {
1636
+ const finalJSONBudget: PartialJSONParseBudget = { bytes: 0, fragments: 0, work: 0 };
1637
+ const parseableContent = isParseableResponseFormat(this.#params?.response_format);
1638
+ const validatedMessages = new WeakMap<ChatCompletionSnapshot.Choice, ValidatedChoiceSnapshot>();
1639
+ const choices = captureSnapshotArray<ChatCompletionSnapshot.Choice>(
1640
+ snapshot,
1641
+ 'choices',
1642
+ MAX_STREAM_CHOICES,
1643
+ 'choice',
1644
+ );
1645
+ if (!choices) {
1646
+ throw new OpenAIError('Chat completion stream contains an unsafe snapshot choice collection');
1647
+ }
1648
+ for (let choiceIndex = 0; choiceIndex < choices.length; choiceIndex += 1) {
1649
+ const choice = captureSnapshotArrayItem(choices, choiceIndex);
1650
+ if (!choice) {
1651
+ continue;
1652
+ }
1653
+ const message = captureStructuredMessageSnapshot(choice);
1654
+ const refusal = captureStructuredJSONSnapshot(message, 'refusal');
1655
+ const content = captureStructuredJSONSnapshot(message, 'content');
1656
+ const validatedTools = new Map<number, ValidatedToolCallSnapshot>();
1657
+ const toolCalls = captureSnapshotArray<ChatCompletionSnapshot.Choice.Message.ToolCall>(
1658
+ message,
1659
+ 'tool_calls',
1660
+ MAX_STREAM_TOOL_CALLS,
1661
+ 'tool-call',
1662
+ );
1663
+ validatedMessages.set(
1664
+ choice,
1665
+ Object.freeze({
1666
+ message,
1667
+ content,
1668
+ refusal,
1669
+ toolCallCollection: toolCalls,
1670
+ toolCalls: validatedTools,
1671
+ }),
1672
+ );
1673
+ const state = this.#choiceEventStates[choice.index];
1674
+ if (parseableContent && !refusal && typeof content === 'string') {
1675
+ validateStructuredJSONSnapshot(content, finalJSONBudget, this.#partialJSONParseBudget);
1676
+ }
1677
+ for (const [index, identity] of state?.tool_call_identities ?? []) {
1678
+ const toolCall = toolCalls && captureSnapshotArrayItem(toolCalls, index);
1679
+ if (!toolCall) {
1680
+ throw new OpenAIError('Chat completion stream contains a changed tool call identity');
1681
+ }
1682
+ assertBoundToolCallIdentity(toolCall, identity);
1683
+ }
1684
+ if (!this.#hasAutoParseableTool) {
1685
+ continue;
1686
+ }
1687
+ for (let toolCallIndex = 0; toolCallIndex < (toolCalls?.length ?? 0); toolCallIndex += 1) {
1688
+ const toolCall = captureSnapshotArrayItem(toolCalls!, toolCallIndex);
1689
+ if (!toolCall) {
1690
+ continue;
1691
+ }
1692
+ const identity = ownFunctionToolIdentity(toolCall);
1693
+ if (!identity) {
1694
+ const type = Object.getOwnPropertyDescriptor(toolCall, 'type');
1695
+ if (type && !('value' in type)) {
1696
+ throw new OpenAIError('Chat completion stream contains an unsafe structured JSON snapshot');
1697
+ }
1698
+ if (type?.value !== 'function') {
1699
+ continue;
1700
+ }
1701
+ const fn = Object.getOwnPropertyDescriptor(toolCall, 'function');
1702
+ if (fn && !('value' in fn)) {
1703
+ throw new OpenAIError('Chat completion stream contains an unsafe structured JSON snapshot');
1704
+ }
1705
+ if (fn && typeof fn.value === 'object' && fn.value !== null) {
1706
+ const name = Object.getOwnPropertyDescriptor(fn.value, 'name');
1707
+ if (name && !('value' in name)) {
1708
+ throw new OpenAIError('Chat completion stream contains an unsafe structured JSON snapshot');
1709
+ }
1710
+ }
1711
+ continue;
1712
+ }
1713
+ if (
1714
+ !shouldParseToolCall(this.#params, {
1715
+ type: identity.type,
1716
+ function: { name: identity.name },
1717
+ })
1718
+ ) {
1719
+ continue;
1720
+ }
1721
+ const descriptor = Object.getOwnPropertyDescriptor(toolCall, 'function');
1722
+ if (!descriptor || !('value' in descriptor)) {
1723
+ throw new OpenAIError('Chat completion stream contains an unsafe structured JSON snapshot');
1724
+ }
1725
+ // SAFETY: The tool-call function is captured through an own data descriptor; its fields are subsequently checked by the structured snapshot reader.
1726
+ const fn = descriptor.value as ChatCompletionSnapshot.Choice.Message.ToolCall.Function;
1727
+ const argumentsSnapshot = captureStructuredJSONSnapshot(fn, 'arguments');
1728
+ if (typeof argumentsSnapshot !== 'string') {
1729
+ throw new OpenAIError('Chat completion stream contains an unsafe structured JSON snapshot');
1730
+ }
1731
+ validateStructuredJSONSnapshot(argumentsSnapshot, finalJSONBudget, this.#partialJSONParseBudget);
1732
+ validatedTools.set(
1733
+ toolCallIndex,
1734
+ Object.freeze({
1735
+ tool: toolCall,
1736
+ function: fn,
1737
+ type: identity.type,
1738
+ name: identity.name,
1739
+ arguments: argumentsSnapshot,
1740
+ }),
1741
+ );
1742
+ }
1743
+ }
1744
+ return validatedMessages;
1745
+ }
1746
+
357
1747
  #endRequest(): ParsedChatCompletion<ParsedT> {
358
1748
  if (this.ended) {
359
1749
  throw new OpenAIError(`stream has ended, this shouldn't happen`);
@@ -362,9 +1752,27 @@ export class ChatCompletionStream<ParsedT = null>
362
1752
  if (!snapshot) {
363
1753
  throw new OpenAIError(`request ended without sending any chunks`);
364
1754
  }
1755
+ const validatedMessages = this.#validateStructuredSnapshots(snapshot);
1756
+ const audioDoneChoiceIndexes = this.#audioDoneChoiceIndexes;
1757
+ this.#audioDoneChoiceIndexes = new Set();
365
1758
  this.#currentChatCompletionSnapshot = undefined;
366
1759
  this.#choiceEventStates = [];
367
- return finalizeChatCompletion(snapshot, this.#params);
1760
+ return finalizeChatCompletion(snapshot, this.#params, audioDoneChoiceIndexes, validatedMessages);
1761
+ }
1762
+
1763
+ /** Rejects unfinished turns before tool callbacks while preserving ordinary stream and replay behavior. */
1764
+ protected override _runTools<FunctionsArgs extends BaseFunctionsArgs, ToolContext>(
1765
+ client: OpenAI,
1766
+ params:
1767
+ | ChatCompletionToolRunnerParamsWithContext<FunctionsArgs, ToolContext>
1768
+ | ChatCompletionToolRunnerParamsWithoutContext<FunctionsArgs>
1769
+ | ChatCompletionStreamingToolRunnerParamsWithContext<FunctionsArgs, ToolContext>
1770
+ | ChatCompletionStreamingToolRunnerParamsWithoutContext<FunctionsArgs>,
1771
+ runner: ChatCompletionRunner<any> | ChatCompletionStreamingRunner<any>,
1772
+ options?: RunnerOptions,
1773
+ ): Promise<void> {
1774
+ this.#rejectsUnfinishedTurns = true;
1775
+ return super._runTools(client, params, runner, options);
368
1776
  }
369
1777
 
370
1778
  protected override async _createChatCompletion(
@@ -372,24 +1780,42 @@ export class ChatCompletionStream<ParsedT = null>
372
1780
  params: ChatCompletionCreateParams,
373
1781
  options?: RequestOptions,
374
1782
  ): Promise<ParsedChatCompletion<ParsedT>> {
375
- super._createChatCompletion;
376
- const signal = options?.signal;
377
- if (signal) {
378
- if (signal.aborted) this.controller.abort();
379
- signal.addEventListener('abort', () => this.controller.abort());
380
- }
1783
+ this._listenForAbort(options?.signal);
1784
+ const requestParams = { ...params, stream: true as const };
1785
+ this.#params = requestParams;
381
1786
  this.#beginRequest();
382
1787
 
383
- const stream = await client.chat.completions.create(
384
- { ...params, stream: true },
385
- { ...options, signal: this.controller.signal },
386
- );
1788
+ const parserParams = snapshotChatCompletionParserParams(requestParams);
1789
+ this.#params = parserParams;
1790
+ this.#hasAutoParseableTool =
1791
+ parserParams.tools?.some(
1792
+ (tool) =>
1793
+ isChatCompletionFunctionTool(tool) && (isAutoParsableTool(tool) || tool.function.strict === true),
1794
+ ) ?? false;
1795
+ const stopObserving =
1796
+ requestParams.tools || requestParams.response_format
1797
+ ? observeSerializedChatCompletionParserParams(requestParams, parserParams, (serialized) => {
1798
+ this.#params = serialized;
1799
+ this.#hasAutoParseableTool =
1800
+ serialized.tools?.some(
1801
+ (tool) =>
1802
+ isChatCompletionFunctionTool(tool) &&
1803
+ (isAutoParsableTool(tool) || tool.function.strict === true),
1804
+ ) ?? false;
1805
+ })
1806
+ : undefined;
1807
+ const stream = await client.chat.completions
1808
+ .create(requestParams, {
1809
+ ...options,
1810
+ signal: this.controller.signal,
1811
+ })
1812
+ .finally(stopObserving);
387
1813
  this._connected();
388
1814
  for await (const chunk of stream) {
389
1815
  this.#addChunk(chunk);
390
1816
  }
391
1817
  if (stream.controller.signal?.aborted) {
392
- throw new APIUserAbortError();
1818
+ throw this._userAbortError();
393
1819
  }
394
1820
  return this._addChatCompletion(this.#endRequest());
395
1821
  }
@@ -398,64 +1824,110 @@ export class ChatCompletionStream<ParsedT = null>
398
1824
  readableStream: ReadableStream,
399
1825
  options?: RequestOptions,
400
1826
  ): Promise<ChatCompletion> {
401
- const signal = options?.signal;
402
- if (signal) {
403
- if (signal.aborted) this.controller.abort();
404
- signal.addEventListener('abort', () => this.controller.abort());
405
- }
1827
+ this._listenForAbort(options?.signal);
406
1828
  this.#beginRequest();
407
1829
  this._connected();
408
- const stream = Stream.fromReadableStream<ChatCompletionChunk>(readableStream, this.controller);
1830
+ const stream = Stream.fromReadableStream<ChatCompletionReadableStreamItem>(
1831
+ readableStream,
1832
+ this.controller,
1833
+ );
409
1834
  let chatId;
410
- for await (const chunk of stream) {
411
- if (chatId && chatId !== chunk.id) {
1835
+ for await (const item of stream) {
1836
+ if ('error' in item && hasOwn(item, 'error') && typeof item.error === 'object' && item.error !== null) {
1837
+ throw new APIError(undefined, item.error, undefined, undefined);
1838
+ }
1839
+
1840
+ if (isChatCompletionReadableStreamMessage(item)) {
1841
+ const message = getChatCompletionReadableStreamMessage(item);
1842
+ if (this.#currentChatCompletionSnapshot) {
1843
+ const toolCalls = this.#currentChatCompletionSnapshot.choices[0]?.message.tool_calls;
1844
+ for (const [index, id] of message.tool_call_ids?.entries() ?? []) {
1845
+ const toolCall = toolCalls?.[index];
1846
+ if (toolCall && id) {
1847
+ toolCall.id = id;
1848
+ }
1849
+ }
1850
+
1851
+ this._addChatCompletion(this.#endRequest());
1852
+ chatId = undefined;
1853
+ }
1854
+ this._addMessage(message.message);
1855
+ continue;
1856
+ }
1857
+
1858
+ const chunk = item;
1859
+
1860
+ if (chatId && chunk.id && chatId !== chunk.id) {
412
1861
  // A new request has been made.
413
1862
  this._addChatCompletion(this.#endRequest());
414
1863
  }
415
1864
 
416
1865
  this.#addChunk(chunk);
417
- chatId = chunk.id;
1866
+ if (chunk.id) {
1867
+ chatId = chunk.id;
1868
+ }
418
1869
  }
419
1870
  if (stream.controller.signal?.aborted) {
420
- throw new APIUserAbortError();
1871
+ throw this._userAbortError();
421
1872
  }
422
- return this._addChatCompletion(this.#endRequest());
423
- }
424
-
425
- #getAutoParseableResponseFormat(): AutoParseableResponseFormat<ParsedT> | null {
426
- const responseFormat = this.#params?.response_format;
427
- if (isAutoParsableResponseFormat<ParsedT>(responseFormat)) {
428
- return responseFormat;
1873
+ if (this.#currentChatCompletionSnapshot) {
1874
+ return this._addChatCompletion(this.#endRequest());
429
1875
  }
430
-
431
- return null;
1876
+ const lastChatCompletion = this._chatCompletions[this._chatCompletions.length - 1];
1877
+ if (lastChatCompletion) {
1878
+ return lastChatCompletion;
1879
+ }
1880
+ throw new OpenAIError(`request ended without sending any chunks`);
432
1881
  }
433
1882
 
434
- #accumulateChatCompletion(chunk: ChatCompletionChunk): ChatCompletionSnapshot {
1883
+ #accumulateChatCompletion(
1884
+ chunk: ChatCompletionChunk,
1885
+ capturedChoiceFrames: WeakMap<object, CapturedChoiceToolCallFrames>,
1886
+ ): ChatCompletionSnapshot {
435
1887
  let snapshot = this.#currentChatCompletionSnapshot;
436
- const { choices, ...rest } = chunk;
1888
+ const { choices, obfuscation: _obfuscation, ...rest } = chunk;
437
1889
  if (!snapshot) {
438
- snapshot = this.#currentChatCompletionSnapshot = {
1890
+ const newSnapshot: ChatCompletionSnapshot = {
439
1891
  ...rest,
440
1892
  choices: [],
441
1893
  };
442
- } else {
443
- Object.assign(snapshot, rest);
1894
+ this.#currentChatCompletionSnapshot = newSnapshot;
1895
+ snapshot = newSnapshot;
1896
+ } else if (chunk.id) {
1897
+ assignOwnProperties(snapshot, rest);
444
1898
  }
445
1899
 
446
- for (const { delta, finish_reason, index, logprobs = null, ...other } of chunk.choices) {
1900
+ const requestedChoiceCount = this.#params?.n;
1901
+ const maxChoices =
1902
+ typeof requestedChoiceCount === 'number' &&
1903
+ Number.isSafeInteger(requestedChoiceCount) &&
1904
+ requestedChoiceCount > 0
1905
+ ? Math.min(requestedChoiceCount, MAX_STREAM_CHOICES)
1906
+ : MAX_STREAM_CHOICES;
1907
+
1908
+ for (const chunkChoice of chunk.choices) {
1909
+ const { delta, finish_reason, index, logprobs = null, ...other } = chunkChoice;
1910
+ const capturedToolCalls: CapturedToolCallDeltaFrame[] = [];
1911
+ capturedChoiceFrames.set(chunkChoice, Object.freeze({ index, tool_calls: capturedToolCalls }));
1912
+ if (!Number.isSafeInteger(index) || index < 0 || index >= maxChoices) {
1913
+ throw new OpenAIError(`Chat completion stream contains an invalid choice index: ${index}`);
1914
+ }
1915
+
447
1916
  let choice = snapshot.choices[index];
448
1917
  if (!choice) {
449
- choice = snapshot.choices[index] = { finish_reason, index, message: {}, logprobs, ...other };
1918
+ const newChoice = { finish_reason, index, message: {}, logprobs: null, ...other };
1919
+ snapshot.choices[index] = newChoice;
1920
+ choice = newChoice;
1921
+ }
1922
+ if (isParseableResponseFormat(this.#params?.response_format) || this.#hasAutoParseableTool) {
1923
+ captureStructuredJSONSnapshot(captureStructuredMessageSnapshot(choice), 'refusal');
450
1924
  }
451
1925
 
452
1926
  if (logprobs) {
453
- if (!choice.logprobs) {
454
- choice.logprobs = Object.assign({}, logprobs);
455
- } else {
1927
+ if (choice.logprobs) {
456
1928
  const { content, refusal, ...rest } = logprobs;
457
1929
  assertIsEmpty(rest);
458
- Object.assign(choice.logprobs, rest);
1930
+ assignOwnProperties(choice.logprobs, rest);
459
1931
 
460
1932
  if (content) {
461
1933
  choice.logprobs.content ??= [];
@@ -466,13 +1938,23 @@ export class ChatCompletionStream<ParsedT = null>
466
1938
  choice.logprobs.refusal ??= [];
467
1939
  choice.logprobs.refusal.push(...refusal);
468
1940
  }
1941
+ } else {
1942
+ choice.logprobs = { ...logprobs };
1943
+
1944
+ if (logprobs.content) {
1945
+ choice.logprobs.content = [...logprobs.content];
1946
+ }
1947
+
1948
+ if (logprobs.refusal) {
1949
+ choice.logprobs.refusal = [...logprobs.refusal];
1950
+ }
469
1951
  }
470
1952
  }
471
1953
 
472
1954
  if (finish_reason) {
473
1955
  choice.finish_reason = finish_reason;
474
1956
 
475
- if (this.#params && hasAutoParseableInput(this.#params)) {
1957
+ if (this.#params && (this.#rejectsUnfinishedTurns || hasAutoParseableInput(this.#params))) {
476
1958
  if (finish_reason === 'length') {
477
1959
  throw new LengthFinishReasonError();
478
1960
  }
@@ -483,123 +1965,233 @@ export class ChatCompletionStream<ParsedT = null>
483
1965
  }
484
1966
  }
485
1967
 
486
- Object.assign(choice, other);
1968
+ assignOwnProperties(choice, other);
487
1969
 
488
- if (!delta) continue; // Shouldn't happen; just in case.
1970
+ if (!delta) {
1971
+ Object.freeze(capturedToolCalls);
1972
+ continue;
1973
+ } // Shouldn't happen; just in case.
489
1974
 
490
- const { content, refusal, function_call, role, tool_calls, ...rest } = delta;
1975
+ this.#audioDoneChoiceIndexes.delete(index);
1976
+ // SAFETY: Streaming audio fields arrive incrementally even though the generated delta type omits them; each present field is merged below.
1977
+ const { audio, content, refusal, function_call, role, ...capturedDeltaFields } =
1978
+ delta as typeof delta & {
1979
+ audio?: Partial<ChatCompletionAudio> | null;
1980
+ };
1981
+ const { tool_calls: capturedToolCallDelta, ...rest } = capturedDeltaFields;
1982
+ const tool_calls = hasOwn(capturedDeltaFields, 'tool_calls') ? capturedToolCallDelta : delta.tool_calls;
491
1983
  assertIsEmpty(rest);
492
- Object.assign(choice.message, rest);
1984
+ assignOwnProperties(choice.message, rest);
1985
+ if (
1986
+ audio?.expires_at != null &&
1987
+ audio.id == null &&
1988
+ audio.data == null &&
1989
+ audio.transcript == null &&
1990
+ content == null &&
1991
+ refusal == null &&
1992
+ function_call == null &&
1993
+ role == null &&
1994
+ tool_calls == null &&
1995
+ Object.keys(rest).length === 0
1996
+ ) {
1997
+ this.#audioDoneChoiceIndexes.add(index);
1998
+ }
493
1999
 
494
2000
  if (refusal) {
495
2001
  choice.message.refusal = (choice.message.refusal || '') + refusal;
496
2002
  }
497
2003
 
498
- if (role) choice.message.role = role;
2004
+ if (role) {
2005
+ choice.message.role = role;
2006
+ }
2007
+ if (audio) {
2008
+ const audioSnapshot = (choice.message.audio ??= {});
2009
+ if (audio.id != null) {
2010
+ audioSnapshot.id = audio.id;
2011
+ }
2012
+ if (audio.data != null) {
2013
+ audioSnapshot.data = (audioSnapshot.data ?? '') + audio.data;
2014
+ }
2015
+ if (audio.transcript != null) {
2016
+ audioSnapshot.transcript = (audioSnapshot.transcript ?? '') + audio.transcript;
2017
+ }
2018
+ if (audio.expires_at != null) {
2019
+ audioSnapshot.expires_at = audio.expires_at;
2020
+ }
2021
+ }
499
2022
  if (function_call) {
500
- if (!choice.message.function_call) {
501
- choice.message.function_call = function_call;
502
- } else {
503
- if (function_call.name) choice.message.function_call.name = function_call.name;
2023
+ if (choice.message.function_call) {
2024
+ if (function_call.name) {
2025
+ choice.message.function_call.name = function_call.name;
2026
+ }
504
2027
  if (function_call.arguments) {
505
2028
  choice.message.function_call.arguments ??= '';
506
2029
  choice.message.function_call.arguments += function_call.arguments;
507
2030
  }
2031
+ } else {
2032
+ choice.message.function_call = function_call;
508
2033
  }
509
2034
  }
510
- if (content) {
511
- choice.message.content = (choice.message.content || '') + content;
512
-
513
- if (!choice.message.refusal && this.#getAutoParseableResponseFormat()) {
514
- choice.message.parsed = partialParse(choice.message.content);
2035
+ if (content != null) {
2036
+ if (!choice.message.refusal && isParseableResponseFormat(this.#params?.response_format)) {
2037
+ const eventState = this.#getChoiceEventState(choice);
2038
+ const parseState = (eventState.content_parse_state ??= createPartialJSONParseState());
2039
+ const shouldParse = recordPartialJSONFragment(parseState, this.#partialJSONParseBudget, content);
2040
+ choice.message.content = (captureStructuredJSONSnapshot(choice.message, 'content') || '') + content;
2041
+
2042
+ // The partial parser does not accept whitespace-only input. Once output
2043
+ // grows, coalesce prefix reparses while preserving every raw snapshot.
2044
+ if (!parseState.has_non_whitespace) {
2045
+ choice.message.parsed = null;
2046
+ } else if (shouldParse && reservePartialJSONParse(parseState, this.#partialJSONParseBudget)) {
2047
+ this.#validateStructuredSnapshots(snapshot);
2048
+ choice.message.parsed = parseStructuredStreamingJSON(
2049
+ validateStructuredJSONSnapshot(choice.message.content),
2050
+ );
2051
+ } else if (content.length > 0) {
2052
+ choice.message.parsed = null;
2053
+ }
2054
+ } else {
2055
+ choice.message.content = (choice.message.content || '') + content;
515
2056
  }
516
2057
  }
517
2058
 
518
2059
  if (tool_calls) {
519
- if (!choice.message.tool_calls) choice.message.tool_calls = [];
520
-
521
- for (const { index, id, type, function: fn, ...rest } of tool_calls) {
522
- const tool_call = (choice.message.tool_calls[index] ??=
523
- {} as ChatCompletionSnapshot.Choice.Message.ToolCall);
524
- Object.assign(tool_call, rest);
525
- if (id) tool_call.id = id;
526
- if (type) tool_call.type = type;
527
- if (fn) tool_call.function ??= { name: fn.name ?? '', arguments: '' };
528
- if (fn?.name) tool_call.function!.name = fn.name;
529
- if (fn?.arguments) {
530
- tool_call.function!.arguments += fn.arguments;
531
-
532
- if (shouldParseToolCall(this.#params, tool_call)) {
533
- tool_call.function!.parsed_arguments = partialParse(tool_call.function!.arguments);
2060
+ // Tool calls are built up across chunks, so while the stream is in progress the
2061
+ // entries are only partially filled in; they match `ChatCompletionSnapshot.Choice.Message.ToolCall`
2062
+ // once every delta for them has been accumulated.
2063
+ // SAFETY: This SDK-owned collection holds partial tool calls during accumulation; finalization checks required fields before exposing completed calls.
2064
+ const toolCallSnapshots = (choice.message.tool_calls ??= []) as PartialToolCallSnapshot[];
2065
+
2066
+ for (const toolCallDelta of tool_calls) {
2067
+ const { index, id, type, function: fn, custom, ...rest } = toolCallDelta;
2068
+ if (!Number.isSafeInteger(index) || index < 0 || index >= MAX_STREAM_TOOL_CALLS) {
2069
+ throw new OpenAIError(`Chat completion stream contains an invalid tool call index: ${index}`);
2070
+ }
2071
+ let argumentsDelta = '';
2072
+
2073
+ const tool_call = (toolCallSnapshots[index] ??= {});
2074
+ const functionName = fn?.name;
2075
+ const eventState = this.#hasAutoParseableTool ? this.#getChoiceEventState(choice) : undefined;
2076
+ let boundIdentity = eventState?.tool_call_identities.get(index);
2077
+ if (boundIdentity) {
2078
+ assertBoundToolCallIdentity(tool_call, boundIdentity);
2079
+ if (
2080
+ (type !== undefined && type !== boundIdentity.type) ||
2081
+ (functionName !== undefined && functionName !== boundIdentity.name)
2082
+ ) {
2083
+ throw new OpenAIError('Chat completion stream contains a changed tool call identity');
534
2084
  }
535
2085
  }
2086
+
2087
+ assignOwnProperties(tool_call, rest);
2088
+ if (id) {
2089
+ tool_call.id = id;
2090
+ }
2091
+ if (type) {
2092
+ tool_call.type = type;
2093
+ }
2094
+ if (custom) {
2095
+ const customSnapshot = (tool_call.custom ??= { name: custom.name ?? '', input: '' });
2096
+ if (custom.name) {
2097
+ customSnapshot.name = custom.name;
2098
+ }
2099
+ if (custom.input) {
2100
+ customSnapshot.input += custom.input;
2101
+ }
2102
+ }
2103
+ if (fn) {
2104
+ const functionSnapshot = (tool_call.function ??= { name: functionName ?? '', arguments: '' });
2105
+ if (functionName) {
2106
+ functionSnapshot.name = functionName;
2107
+ }
2108
+ if (eventState && !boundIdentity) {
2109
+ const identity = ownFunctionToolIdentity(tool_call);
2110
+ const configuredTool =
2111
+ identity &&
2112
+ this.#params?.tools?.find(
2113
+ (tool) => isChatCompletionFunctionTool(tool) && tool.function.name === identity.name,
2114
+ );
2115
+ if (identity) {
2116
+ boundIdentity = {
2117
+ ...identity,
2118
+ parseable:
2119
+ configuredTool !== undefined &&
2120
+ shouldParseToolCall(this.#params, {
2121
+ type: identity.type,
2122
+ function: { name: identity.name },
2123
+ }),
2124
+ };
2125
+ eventState.tool_call_identities.set(index, boundIdentity);
2126
+ if (!boundIdentity.parseable) {
2127
+ const provisionalState = eventState.tool_call_parse_states.get(index);
2128
+ if (provisionalState) {
2129
+ this.#partialJSONParseBudget.bytes -= provisionalState.bytes;
2130
+ this.#partialJSONParseBudget.fragments -= provisionalState.fragments;
2131
+ this.#partialJSONParseBudget.work -= provisionalState.work;
2132
+ eventState.tool_call_parse_states.delete(index);
2133
+ }
2134
+ }
2135
+ }
2136
+ }
2137
+ const argumentFragment = fn.arguments;
2138
+ if (argumentFragment != null) {
2139
+ argumentsDelta = argumentFragment;
2140
+ if (eventState && boundIdentity?.parseable !== false) {
2141
+ let parseState = eventState.tool_call_parse_states.get(index);
2142
+ if (!parseState) {
2143
+ parseState = createPartialJSONParseState();
2144
+ eventState.tool_call_parse_states.set(index, parseState);
2145
+ }
2146
+
2147
+ const shouldParse = recordPartialJSONFragment(
2148
+ parseState,
2149
+ this.#partialJSONParseBudget,
2150
+ argumentFragment,
2151
+ );
2152
+ const previousArguments = captureStructuredJSONSnapshot(functionSnapshot, 'arguments');
2153
+ if (typeof previousArguments !== 'string') {
2154
+ throw new OpenAIError('Chat completion stream contains an unsafe structured JSON snapshot');
2155
+ }
2156
+ functionSnapshot.arguments = previousArguments + argumentFragment;
2157
+ if (
2158
+ shouldParse &&
2159
+ boundIdentity?.parseable === true &&
2160
+ reservePartialJSONParse(parseState, this.#partialJSONParseBudget)
2161
+ ) {
2162
+ this.#validateStructuredSnapshots(snapshot);
2163
+ functionSnapshot.parsed_arguments = parseStructuredStreamingJSON(
2164
+ validateStructuredJSONSnapshot(functionSnapshot.arguments),
2165
+ );
2166
+ } else if (argumentFragment.length > 0 && hasOwn(functionSnapshot, 'parsed_arguments')) {
2167
+ functionSnapshot.parsed_arguments = undefined;
2168
+ }
2169
+ } else {
2170
+ functionSnapshot.arguments += argumentFragment;
2171
+ }
2172
+ }
2173
+ }
2174
+ capturedToolCalls.push(Object.freeze({ index, arguments_delta: argumentsDelta }));
536
2175
  }
537
2176
  }
2177
+ Object.freeze(capturedToolCalls);
538
2178
  }
539
2179
  return snapshot;
540
2180
  }
541
2181
 
2182
+ /** Iterates over raw API chunks; stopping iteration early aborts the underlying request. */
542
2183
  [Symbol.asyncIterator](this: ChatCompletionStream<ParsedT>): AsyncIterator<ChatCompletionChunk> {
543
- const pushQueue: ChatCompletionChunk[] = [];
544
- const readQueue: {
545
- resolve: (chunk: ChatCompletionChunk | undefined) => void;
546
- reject: (err: unknown) => void;
547
- }[] = [];
548
- let done = false;
549
-
550
- this.on('chunk', (chunk) => {
551
- const reader = readQueue.shift();
552
- if (reader) {
553
- reader.resolve(chunk);
554
- } else {
555
- pushQueue.push(chunk);
556
- }
557
- });
558
-
559
- this.on('end', () => {
560
- done = true;
561
- for (const reader of readQueue) {
562
- reader.resolve(undefined);
563
- }
564
- readQueue.length = 0;
565
- });
566
-
567
- this.on('abort', (err) => {
568
- done = true;
569
- for (const reader of readQueue) {
570
- reader.reject(err);
571
- }
572
- readQueue.length = 0;
573
- });
574
-
575
- this.on('error', (err) => {
576
- done = true;
577
- for (const reader of readQueue) {
578
- reader.reject(err);
579
- }
580
- readQueue.length = 0;
581
- });
582
-
583
- return {
584
- next: async (): Promise<IteratorResult<ChatCompletionChunk>> => {
585
- if (!pushQueue.length) {
586
- if (done) {
587
- return { value: undefined, done: true };
588
- }
589
- return new Promise<ChatCompletionChunk | undefined>((resolve, reject) =>
590
- readQueue.push({ resolve, reject }),
591
- ).then((chunk) => (chunk ? { value: chunk, done: false } : { value: undefined, done: true }));
592
- }
593
- const chunk = pushQueue.shift()!;
594
- return { value: chunk, done: false };
595
- },
596
- return: async () => {
597
- this.abort();
598
- return { value: undefined, done: true };
2184
+ return this._createIterator<ChatCompletionChunk>(
2185
+ (push) => {
2186
+ const onChunk = (chunk: ChatCompletionChunk) => push(chunk);
2187
+ this.on('chunk', onChunk);
2188
+ return () => this.off('chunk', onChunk);
599
2189
  },
600
- };
2190
+ { onReturn: () => this.abort() },
2191
+ );
601
2192
  }
602
2193
 
2194
+ /** Serializes raw completion chunks into a readable stream for transfer to another runtime. */
603
2195
  toReadableStream(): ReadableStream {
604
2196
  const stream = new Stream(this[Symbol.asyncIterator].bind(this), this.controller);
605
2197
  return stream.toReadableStream();
@@ -609,18 +2201,56 @@ export class ChatCompletionStream<ParsedT = null>
609
2201
  function finalizeChatCompletion<ParsedT>(
610
2202
  snapshot: ChatCompletionSnapshot,
611
2203
  params: ChatCompletionCreateParams | null,
2204
+ audioDoneChoiceIndexes: ReadonlySet<number>,
2205
+ validatedMessages: WeakMap<ChatCompletionSnapshot.Choice, ValidatedChoiceSnapshot>,
612
2206
  ): ParsedChatCompletion<ParsedT> {
613
2207
  const { id, choices, created, model, system_fingerprint, ...rest } = snapshot;
614
2208
  const completion: ChatCompletion = {
615
2209
  ...rest,
616
2210
  id,
617
- choices: choices.map(
618
- ({ message, finish_reason, index, logprobs, ...choiceRest }): ChatCompletion.Choice => {
619
- if (!finish_reason) {
2211
+ choices: mapCapturedSnapshotArray(
2212
+ choices,
2213
+ MAX_STREAM_CHOICES,
2214
+ 'choice',
2215
+ (choice): ChatCompletion.Choice => {
2216
+ const validated = validatedMessages.get(choice);
2217
+ if (!validated) {
2218
+ throw new OpenAIError('Chat completion stream contains an unsafe structured JSON snapshot');
2219
+ }
2220
+ const stableChoice = new Proxy(choice, {
2221
+ get(target, property, receiver) {
2222
+ // oxlint-disable-next-line anti-slop/no-reflect-get -- Proxy forwarding must preserve arbitrary keys and the original accessor receiver.
2223
+ return property === 'message' ? validated.message : Reflect.get(target, property, receiver);
2224
+ },
2225
+ });
2226
+ const { message: sourceMessage, finish_reason, index, logprobs, ...choiceRest } = stableChoice;
2227
+ const message = new Proxy(sourceMessage, {
2228
+ get(target, property, receiver) {
2229
+ if (property === 'content') {
2230
+ return validated.content;
2231
+ }
2232
+ if (property === 'refusal') {
2233
+ return validated.refusal;
2234
+ }
2235
+ if (property === 'tool_calls') {
2236
+ return validated.toolCallCollection;
2237
+ }
2238
+ // oxlint-disable-next-line anti-slop/no-reflect-get -- Proxy forwarding must preserve arbitrary keys and the original accessor receiver.
2239
+ return Reflect.get(target, property, receiver);
2240
+ },
2241
+ });
2242
+ const { content = null, function_call, tool_calls, audio, ...messageRest } = message;
2243
+ // Audio streams can end with an expires_at-only chunk after the
2244
+ // generated audio, without a separate finish_reason.
2245
+ const finishReason =
2246
+ finish_reason ?? (audioDoneChoiceIndexes.has(index) && isCompleteAudio(audio) ? 'stop' : null);
2247
+ if (!finishReason) {
620
2248
  throw new OpenAIError(`missing finish_reason for choice ${index}`);
621
2249
  }
622
2250
 
623
- const { content = null, function_call, tool_calls, ...messageRest } = message;
2251
+ // SAFETY: The completed API response contract supplies the audio fields; this preserves the existing pass-through behavior at finalization.
2252
+ const audioResponse = audio ? { audio: audio as ChatCompletionAudio } : {};
2253
+ // SAFETY: The API completion contract uses assistant role; retaining the wire role preserves existing behavior without adding runtime rejection.
624
2254
  const role = message.role as 'assistant'; // this is what we expect; in theory it could be different which would make our types a slight lie but would be fine.
625
2255
  if (!role) {
626
2256
  throw new OpenAIError(`missing role for choice ${index}`);
@@ -639,12 +2269,13 @@ function finalizeChatCompletion<ParsedT>(
639
2269
  return {
640
2270
  ...choiceRest,
641
2271
  message: {
2272
+ ...audioResponse,
642
2273
  content,
643
2274
  function_call: { arguments: args, name },
644
2275
  role,
645
2276
  refusal: message.refusal ?? null,
646
2277
  },
647
- finish_reason,
2278
+ finish_reason: finishReason,
648
2279
  index,
649
2280
  logprobs,
650
2281
  };
@@ -654,42 +2285,108 @@ function finalizeChatCompletion<ParsedT>(
654
2285
  return {
655
2286
  ...choiceRest,
656
2287
  index,
657
- finish_reason,
2288
+ finish_reason: finishReason,
658
2289
  logprobs,
659
2290
  message: {
660
2291
  ...messageRest,
2292
+ ...audioResponse,
661
2293
  role,
662
2294
  content,
663
2295
  refusal: message.refusal ?? null,
664
- tool_calls: tool_calls.map((tool_call, i) => {
665
- const { function: fn, type, id, ...toolRest } = tool_call;
666
- const { arguments: args, name, ...fnRest } = fn || {};
667
- if (id == null) {
668
- throw new OpenAIError(`missing choices[${index}].tool_calls[${i}].id\n${str(snapshot)}`);
669
- }
670
- if (type == null) {
671
- throw new OpenAIError(`missing choices[${index}].tool_calls[${i}].type\n${str(snapshot)}`);
672
- }
673
- if (name == null) {
674
- throw new OpenAIError(
675
- `missing choices[${index}].tool_calls[${i}].function.name\n${str(snapshot)}`,
676
- );
677
- }
678
- if (args == null) {
679
- throw new OpenAIError(
680
- `missing choices[${index}].tool_calls[${i}].function.arguments\n${str(snapshot)}`,
681
- );
682
- }
683
-
684
- return { ...toolRest, id, type, function: { ...fnRest, name, arguments: args } };
685
- }),
2296
+ tool_calls: mapCapturedSnapshotArray(
2297
+ tool_calls,
2298
+ MAX_STREAM_TOOL_CALLS,
2299
+ 'tool-call',
2300
+ (tool_call, i): ChatCompletionMessageToolCall => {
2301
+ const captured = validated.toolCalls.get(i);
2302
+ if (!captured) {
2303
+ const identity = ownFunctionToolIdentity(tool_call);
2304
+ if (
2305
+ identity &&
2306
+ shouldParseToolCall(params, {
2307
+ type: identity.type,
2308
+ function: { name: identity.name },
2309
+ })
2310
+ ) {
2311
+ throw new OpenAIError(
2312
+ 'Chat completion stream contains an unsafe structured JSON snapshot',
2313
+ );
2314
+ }
2315
+ }
2316
+ if (captured && captured.tool !== tool_call) {
2317
+ throw new OpenAIError('Chat completion stream contains a changed tool call identity');
2318
+ }
2319
+ const stableFunction =
2320
+ captured &&
2321
+ new Proxy(captured.function, {
2322
+ get(target, property, receiver) {
2323
+ if (property === 'arguments') {
2324
+ return captured.arguments;
2325
+ }
2326
+ if (property === 'name') {
2327
+ return captured.name;
2328
+ }
2329
+ // oxlint-disable-next-line anti-slop/no-reflect-get -- Proxy forwarding must preserve arbitrary keys and the original accessor receiver.
2330
+ return Reflect.get(target, property, receiver);
2331
+ },
2332
+ });
2333
+ const stableTool =
2334
+ captured && stableFunction
2335
+ ? new Proxy(tool_call, {
2336
+ get(target, property, receiver) {
2337
+ if (property === 'type') {
2338
+ return captured.type;
2339
+ }
2340
+ if (property === 'function') {
2341
+ return stableFunction;
2342
+ }
2343
+ // oxlint-disable-next-line anti-slop/no-reflect-get -- Proxy forwarding must preserve arbitrary keys and the original accessor receiver.
2344
+ return Reflect.get(target, property, receiver);
2345
+ },
2346
+ })
2347
+ : tool_call;
2348
+ if (stableTool.type == null) {
2349
+ throw new OpenAIError(`missing choices[${index}].tool_calls[${i}].type`);
2350
+ }
2351
+
2352
+ if (stableTool.type === 'custom') {
2353
+ const { custom, type, id, ...toolRest } = stableTool;
2354
+ const { input = '', name, ...customRest } = custom || {};
2355
+ if (name == null) {
2356
+ throw new OpenAIError(`missing choices[${index}].tool_calls[${i}].custom.name`);
2357
+ }
2358
+ return {
2359
+ ...toolRest,
2360
+ id: id || `call_${uuid4()}`,
2361
+ type,
2362
+ custom: { ...customRest, name, input },
2363
+ };
2364
+ }
2365
+
2366
+ const { function: fn, type, id, ...toolRest } = stableTool;
2367
+ const { arguments: args, name, ...fnRest } = fn || {};
2368
+ if (name == null) {
2369
+ throw new OpenAIError(`missing choices[${index}].tool_calls[${i}].function.name`);
2370
+ }
2371
+ if (args == null) {
2372
+ throw new OpenAIError(`missing choices[${index}].tool_calls[${i}].function.arguments`);
2373
+ }
2374
+
2375
+ return {
2376
+ ...toolRest,
2377
+ id: id || `call_${uuid4()}`,
2378
+ type,
2379
+ function: { ...fnRest, name, arguments: args },
2380
+ };
2381
+ },
2382
+ ),
686
2383
  },
687
2384
  };
688
2385
  }
689
2386
  return {
690
2387
  ...choiceRest,
691
- message: { ...messageRest, content, role, refusal: message.refusal ?? null },
692
- finish_reason,
2388
+ message: { ...messageRest, ...audioResponse, content, role, refusal: message.refusal ?? null },
2389
+ finish_reason: finishReason,
693
2390
  index,
694
2391
  logprobs,
695
2392
  };
@@ -698,19 +2395,22 @@ function finalizeChatCompletion<ParsedT>(
698
2395
  created,
699
2396
  model,
700
2397
  object: 'chat.completion',
2398
+ // Spread creates an own data property without invoking inherited setters or changing the object prototype.
701
2399
  ...(system_fingerprint ? { system_fingerprint } : {}),
702
2400
  };
703
2401
 
704
2402
  return maybeParseChatCompletion(completion, params);
705
2403
  }
706
2404
 
707
- function str(x: unknown) {
708
- return JSON.stringify(x);
2405
+ function isCompleteAudio(
2406
+ audio: Partial<ChatCompletionAudio> | null | undefined,
2407
+ ): audio is ChatCompletionAudio {
2408
+ return audio?.id != null && audio.data != null && audio.transcript != null && audio.expires_at != null;
709
2409
  }
710
2410
 
711
2411
  /**
712
- * Represents a streamed chunk of a chat completion response returned by model,
713
- * based on the provided input.
2412
+ * The chat completion accumulated from every streamed chunk received so far.
2413
+ * Fields within each choice can remain incomplete until generation finishes.
714
2414
  */
715
2415
  export interface ChatCompletionSnapshot {
716
2416
  /**
@@ -722,7 +2422,7 @@ export interface ChatCompletionSnapshot {
722
2422
  * A list of chat completion choices. Can be more than one if `n` is greater
723
2423
  * than 1.
724
2424
  */
725
- choices: Array<ChatCompletionSnapshot.Choice>;
2425
+ choices: ChatCompletionSnapshot.Choice[];
726
2426
 
727
2427
  /**
728
2428
  * The Unix timestamp (in seconds) of when the chat completion was created.
@@ -730,7 +2430,7 @@ export interface ChatCompletionSnapshot {
730
2430
  created: number;
731
2431
 
732
2432
  /**
733
- * The model to generate the completion.
2433
+ * The model generating the completion.
734
2434
  */
735
2435
  model: string;
736
2436
 
@@ -747,10 +2447,12 @@ export interface ChatCompletionSnapshot {
747
2447
  system_fingerprint?: string;
748
2448
  }
749
2449
 
2450
+ /** Nested shapes used by an in-progress chat completion snapshot. */
750
2451
  export namespace ChatCompletionSnapshot {
2452
+ /** One in-progress assistant choice and the metadata accumulated for it. */
751
2453
  export interface Choice {
752
2454
  /**
753
- * A chat completion delta generated by streamed model responses.
2455
+ * The assistant message accumulated from streamed model response deltas.
754
2456
  */
755
2457
  message: Choice.Message;
756
2458
 
@@ -758,8 +2460,8 @@ export namespace ChatCompletionSnapshot {
758
2460
  * The reason the model stopped generating tokens. This will be `stop` if the model
759
2461
  * hit a natural stop point or a provided stop sequence, `length` if the maximum
760
2462
  * number of tokens specified in the request was reached, `content_filter` if
761
- * content was omitted due to a flag from our content filters, or `function_call`
762
- * if the model called a function.
2463
+ * content was omitted due to a flag from our content filters, `tool_calls` if
2464
+ * the model called a tool, or the deprecated `function_call` value.
763
2465
  */
764
2466
  finish_reason: ChatCompletion.Choice['finish_reason'] | null;
765
2467
 
@@ -774,18 +2476,24 @@ export namespace ChatCompletionSnapshot {
774
2476
  index: number;
775
2477
  }
776
2478
 
2479
+ /** Nested message shapes belonging to an in-progress completion choice. */
777
2480
  export namespace Choice {
778
2481
  /**
779
- * A chat completion delta generated by streamed model responses.
2482
+ * The assistant message accumulated from streamed response deltas.
780
2483
  */
781
2484
  export interface Message {
782
2485
  /**
783
- * The contents of the chunk message.
2486
+ * The assistant text accumulated for this message so far.
784
2487
  */
785
2488
  content?: string | null;
786
2489
 
2490
+ /** Audio fields received so far; individual fields can remain absent until generation finishes. */
2491
+ audio?: Partial<ChatCompletionAudio> | null;
2492
+
2493
+ /** The model's refusal text accumulated so far, when the request is refused. */
787
2494
  refusal?: string | null;
788
2495
 
2496
+ /** A best-effort partial parse of structured assistant content. */
789
2497
  parsed?: unknown | null;
790
2498
 
791
2499
  /**
@@ -794,7 +2502,8 @@ export namespace ChatCompletionSnapshot {
794
2502
  */
795
2503
  function_call?: Message.FunctionCall;
796
2504
 
797
- tool_calls?: Array<Message.ToolCall>;
2505
+ /** Function and custom tool calls accumulated so far; inputs may still be incomplete. */
2506
+ tool_calls?: Message.ToolCall[];
798
2507
 
799
2508
  /**
800
2509
  * The role of the author of this message.
@@ -802,22 +2511,30 @@ export namespace ChatCompletionSnapshot {
802
2511
  role?: ChatCompletionRole;
803
2512
  }
804
2513
 
2514
+ /** Nested tool-call shapes belonging to an in-progress assistant message. */
805
2515
  export namespace Message {
806
- export interface ToolCall {
807
- /**
808
- * The ID of the tool call.
809
- */
810
- id: string;
2516
+ /** A function or custom tool call accumulated incrementally from streamed chunks. */
2517
+ export type ToolCall = ToolCall.FunctionToolCall | ToolCall.CustomToolCall;
811
2518
 
812
- function: ToolCall.Function;
2519
+ /** Function and custom details nested under an in-progress tool call. */
2520
+ export namespace ToolCall {
2521
+ /** A function-tool call whose name, identifier, and arguments are streamed incrementally. */
2522
+ export interface FunctionToolCall {
2523
+ /**
2524
+ * The ID of the tool call.
2525
+ */
2526
+ id: string;
813
2527
 
814
- /**
815
- * The type of the tool.
816
- */
817
- type: 'function';
818
- }
2528
+ /** The function name and the complete or partial JSON arguments received so far. */
2529
+ function: ToolCall.Function;
819
2530
 
820
- export namespace ToolCall {
2531
+ /**
2532
+ * The type of the tool.
2533
+ */
2534
+ type: 'function';
2535
+ }
2536
+
2537
+ /** The name and incrementally accumulated arguments of a function-tool call. */
821
2538
  export interface Function {
822
2539
  /**
823
2540
  * The arguments to call the function with, as generated by the model in JSON
@@ -827,6 +2544,7 @@ export namespace ChatCompletionSnapshot {
827
2544
  */
828
2545
  arguments: string;
829
2546
 
2547
+ /** A best-effort partial parse of `arguments` for strict or auto-parseable tools. */
830
2548
  parsed_arguments?: unknown;
831
2549
 
832
2550
  /**
@@ -834,6 +2552,34 @@ export namespace ChatCompletionSnapshot {
834
2552
  */
835
2553
  name: string;
836
2554
  }
2555
+
2556
+ /** A custom-tool call whose name, identifier, and input are streamed incrementally. */
2557
+ export interface CustomToolCall {
2558
+ /**
2559
+ * The ID of the tool call.
2560
+ */
2561
+ id: string;
2562
+
2563
+ /** The custom-tool name and complete or partial input received so far. */
2564
+ custom: CustomToolCall.Custom;
2565
+
2566
+ /**
2567
+ * The type of the tool.
2568
+ */
2569
+ type: 'custom';
2570
+ }
2571
+
2572
+ /** Custom-tool details nested under an in-progress tool call. */
2573
+ export namespace CustomToolCall {
2574
+ /** The name and incrementally accumulated input of a custom-tool call. */
2575
+ export interface Custom {
2576
+ /** The name of the custom tool to call. */
2577
+ name: string;
2578
+
2579
+ /** The custom tool's complete or partial free-form input. */
2580
+ input: string;
2581
+ }
2582
+ }
837
2583
  }
838
2584
 
839
2585
  /**
@@ -858,15 +2604,17 @@ export namespace ChatCompletionSnapshot {
858
2604
  }
859
2605
  }
860
2606
 
861
- type AssertIsEmpty<T extends {}> = keyof T extends never ? T : never;
2607
+ type AssertIsEmpty<T extends object> = keyof T extends never ? T : never;
862
2608
 
863
2609
  /**
864
2610
  * Ensures the given argument is an empty object, useful for
865
2611
  * asserting that all known properties on an object have been
866
2612
  * destructured.
867
2613
  */
868
- function assertIsEmpty<T extends {}>(obj: AssertIsEmpty<T>): asserts obj is AssertIsEmpty<T> {
869
- return;
2614
+ function assertIsEmpty<T extends object>(obj: AssertIsEmpty<T>): asserts obj is AssertIsEmpty<T> {
2615
+ void obj;
870
2616
  }
871
2617
 
872
- function assertNever(_x: never) {}
2618
+ function assertNever(_x: never) {
2619
+ return _x;
2620
+ }