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