openai 7.5.0 → 7.7.0
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/CHANGELOG.md +117 -0
- package/README.md +46 -2
- package/auth/index.d.mts +1 -1
- package/auth/index.d.mts.map +1 -1
- package/auth/index.d.ts +1 -1
- package/auth/index.d.ts.map +1 -1
- package/auth/index.js.map +1 -1
- package/auth/index.mjs.map +1 -1
- package/auth/subject-token-providers.d.mts.map +1 -1
- package/auth/subject-token-providers.d.ts.map +1 -1
- package/auth/subject-token-providers.js +176 -4
- package/auth/subject-token-providers.js.map +1 -1
- package/auth/subject-token-providers.mjs +176 -4
- package/auth/subject-token-providers.mjs.map +1 -1
- package/auth/types.d.mts +17 -0
- package/auth/types.d.mts.map +1 -1
- package/auth/types.d.ts +17 -0
- package/auth/types.d.ts.map +1 -1
- package/auth/workload-identity-auth.d.mts.map +1 -1
- package/auth/workload-identity-auth.d.ts.map +1 -1
- package/auth/workload-identity-auth.js +80 -7
- package/auth/workload-identity-auth.js.map +1 -1
- package/auth/workload-identity-auth.mjs +80 -7
- package/auth/workload-identity-auth.mjs.map +1 -1
- package/auth/x509-transport.d.mts +5 -0
- package/auth/x509-transport.d.mts.map +1 -0
- package/auth/x509-transport.d.ts +5 -0
- package/auth/x509-transport.d.ts.map +1 -0
- package/auth/x509-transport.js +39 -0
- package/auth/x509-transport.js.map +1 -0
- package/auth/x509-transport.mjs +36 -0
- package/auth/x509-transport.mjs.map +1 -0
- package/azure.d.mts +11 -2
- package/azure.d.mts.map +1 -1
- package/azure.d.ts +11 -2
- package/azure.d.ts.map +1 -1
- package/azure.js +7 -1
- package/azure.js.map +1 -1
- package/azure.mjs +7 -1
- package/azure.mjs.map +1 -1
- package/bedrock.d.mts +6 -2
- package/bedrock.d.mts.map +1 -1
- package/bedrock.d.ts +6 -2
- package/bedrock.d.ts.map +1 -1
- package/bedrock.js +34 -4
- package/bedrock.js.map +1 -1
- package/bedrock.mjs +35 -5
- package/bedrock.mjs.map +1 -1
- package/beta/realtime/internal-base.d.mts +2 -0
- package/beta/realtime/internal-base.d.mts.map +1 -1
- package/beta/realtime/internal-base.d.ts +2 -0
- package/beta/realtime/internal-base.d.ts.map +1 -1
- package/beta/realtime/internal-base.js +15 -0
- package/beta/realtime/internal-base.js.map +1 -1
- package/beta/realtime/internal-base.mjs +14 -0
- package/beta/realtime/internal-base.mjs.map +1 -1
- package/beta/realtime/websocket.d.mts +11 -5
- package/beta/realtime/websocket.d.mts.map +1 -1
- package/beta/realtime/websocket.d.ts +11 -5
- package/beta/realtime/websocket.d.ts.map +1 -1
- package/beta/realtime/websocket.js +106 -31
- package/beta/realtime/websocket.js.map +1 -1
- package/beta/realtime/websocket.mjs +107 -32
- package/beta/realtime/websocket.mjs.map +1 -1
- package/beta/realtime/ws.d.mts +0 -2
- package/beta/realtime/ws.d.mts.map +1 -1
- package/beta/realtime/ws.d.ts +0 -2
- package/beta/realtime/ws.d.ts.map +1 -1
- package/beta/realtime/ws.js +24 -5
- package/beta/realtime/ws.js.map +1 -1
- package/beta/realtime/ws.mjs +25 -6
- package/beta/realtime/ws.mjs.map +1 -1
- package/client.d.mts +17 -2
- package/client.d.mts.map +1 -1
- package/client.d.ts +17 -2
- package/client.d.ts.map +1 -1
- package/client.js +422 -70
- package/client.js.map +1 -1
- package/client.mjs +423 -71
- package/client.mjs.map +1 -1
- package/core/EventEmitter.d.mts.map +1 -1
- package/core/EventEmitter.d.ts.map +1 -1
- package/core/EventEmitter.js +67 -9
- package/core/EventEmitter.js.map +1 -1
- package/core/EventEmitter.mjs +68 -10
- package/core/EventEmitter.mjs.map +1 -1
- package/core/streaming.d.mts +1 -0
- package/core/streaming.d.mts.map +1 -1
- package/core/streaming.d.ts +1 -0
- package/core/streaming.d.ts.map +1 -1
- package/core/streaming.js +216 -26
- package/core/streaming.js.map +1 -1
- package/core/streaming.mjs +216 -26
- package/core/streaming.mjs.map +1 -1
- package/helpers/audio.d.mts +5 -5
- package/helpers/audio.d.mts.map +1 -1
- package/helpers/audio.d.ts +5 -5
- package/helpers/audio.d.ts.map +1 -1
- package/helpers/audio.js +93 -22
- package/helpers/audio.js.map +1 -1
- package/helpers/audio.mjs +93 -22
- package/helpers/audio.mjs.map +1 -1
- package/helpers/standard-schema.d.mts.map +1 -1
- package/helpers/standard-schema.d.ts.map +1 -1
- package/helpers/standard-schema.js +34 -14
- package/helpers/standard-schema.js.map +1 -1
- package/helpers/standard-schema.mjs +35 -15
- package/helpers/standard-schema.mjs.map +1 -1
- package/helpers/zod-v3-strict-schema.d.mts +7 -0
- package/helpers/zod-v3-strict-schema.d.mts.map +1 -0
- package/helpers/zod-v3-strict-schema.d.ts +7 -0
- package/helpers/zod-v3-strict-schema.d.ts.map +1 -0
- package/helpers/zod-v3-strict-schema.js +403 -0
- package/helpers/zod-v3-strict-schema.js.map +1 -0
- package/helpers/zod-v3-strict-schema.mjs +399 -0
- package/helpers/zod-v3-strict-schema.mjs.map +1 -0
- package/helpers/zod.d.mts.map +1 -1
- package/helpers/zod.d.ts.map +1 -1
- package/helpers/zod.js +11 -3
- package/helpers/zod.js.map +1 -1
- package/helpers/zod.mjs +12 -4
- package/helpers/zod.mjs.map +1 -1
- package/index.d.mts +1 -1
- package/index.d.mts.map +1 -1
- package/index.d.ts +1 -1
- package/index.d.ts.map +1 -1
- package/index.js.map +1 -1
- package/index.mjs.map +1 -1
- package/internal/assistant-stream-delta.d.mts.map +1 -1
- package/internal/assistant-stream-delta.d.ts.map +1 -1
- package/internal/assistant-stream-delta.js +28 -8
- package/internal/assistant-stream-delta.js.map +1 -1
- package/internal/assistant-stream-delta.mjs +28 -8
- package/internal/assistant-stream-delta.mjs.map +1 -1
- package/internal/auth/x509-token-exchange.d.mts +16 -0
- package/internal/auth/x509-token-exchange.d.mts.map +1 -0
- package/internal/auth/x509-token-exchange.d.ts +16 -0
- package/internal/auth/x509-token-exchange.d.ts.map +1 -0
- package/internal/auth/x509-token-exchange.js +246 -0
- package/internal/auth/x509-token-exchange.js.map +1 -0
- package/internal/auth/x509-token-exchange.mjs +243 -0
- package/internal/auth/x509-token-exchange.mjs.map +1 -0
- package/internal/auth/x509-transport-capability.d.mts +37 -0
- package/internal/auth/x509-transport-capability.d.mts.map +1 -0
- package/internal/auth/x509-transport-capability.d.ts +37 -0
- package/internal/auth/x509-transport-capability.d.ts.map +1 -0
- package/internal/auth/x509-transport-capability.js +169 -0
- package/internal/auth/x509-transport-capability.js.map +1 -0
- package/internal/auth/x509-transport-capability.mjs +164 -0
- package/internal/auth/x509-transport-capability.mjs.map +1 -0
- package/internal/auth/x509-transport-registry.d.mts +63 -0
- package/internal/auth/x509-transport-registry.d.mts.map +1 -0
- package/internal/auth/x509-transport-registry.d.ts +63 -0
- package/internal/auth/x509-transport-registry.d.ts.map +1 -0
- package/internal/auth/x509-transport-registry.js +53 -0
- package/internal/auth/x509-transport-registry.js.map +1 -0
- package/internal/auth/x509-transport-registry.mjs +48 -0
- package/internal/auth/x509-transport-registry.mjs.map +1 -0
- package/internal/auth/x509-transport-state-browser.d.mts +21 -0
- package/internal/auth/x509-transport-state-browser.d.mts.map +1 -0
- package/internal/auth/x509-transport-state-browser.d.ts +21 -0
- package/internal/auth/x509-transport-state-browser.d.ts.map +1 -0
- package/internal/auth/x509-transport-state-browser.js +30 -0
- package/internal/auth/x509-transport-state-browser.js.map +1 -0
- package/internal/auth/x509-transport-state-browser.mjs +27 -0
- package/internal/auth/x509-transport-state-browser.mjs.map +1 -0
- package/internal/auth/x509-transport-state.cjs +30 -0
- package/internal/auth/x509-transport-state.cjs.map +1 -0
- package/internal/auth/x509-transport-state.d.cts +21 -0
- package/internal/auth/x509-transport-state.d.cts.map +1 -0
- package/internal/auth/x509-workload-identity-auth.d.mts +128 -0
- package/internal/auth/x509-workload-identity-auth.d.mts.map +1 -0
- package/internal/auth/x509-workload-identity-auth.d.ts +128 -0
- package/internal/auth/x509-workload-identity-auth.d.ts.map +1 -0
- package/internal/auth/x509-workload-identity-auth.js +767 -0
- package/internal/auth/x509-workload-identity-auth.js.map +1 -0
- package/internal/auth/x509-workload-identity-auth.mjs +757 -0
- package/internal/auth/x509-workload-identity-auth.mjs.map +1 -0
- package/internal/bedrock.d.mts +2 -0
- package/internal/bedrock.d.mts.map +1 -1
- package/internal/bedrock.d.ts +2 -0
- package/internal/bedrock.d.ts.map +1 -1
- package/internal/bedrock.js +169 -5
- package/internal/bedrock.js.map +1 -1
- package/internal/bedrock.mjs +168 -5
- package/internal/bedrock.mjs.map +1 -1
- package/internal/data-residency.d.mts +12 -0
- package/internal/data-residency.d.mts.map +1 -0
- package/internal/data-residency.d.ts +12 -0
- package/internal/data-residency.d.ts.map +1 -0
- package/internal/data-residency.js +34 -0
- package/internal/data-residency.js.map +1 -0
- package/internal/data-residency.mjs +30 -0
- package/internal/data-residency.mjs.map +1 -0
- package/internal/multipart-encoding.d.mts +8 -0
- package/internal/multipart-encoding.d.mts.map +1 -0
- package/internal/multipart-encoding.d.ts +8 -0
- package/internal/multipart-encoding.d.ts.map +1 -0
- package/internal/multipart-encoding.js +51 -0
- package/internal/multipart-encoding.js.map +1 -0
- package/internal/multipart-encoding.mjs +48 -0
- package/internal/multipart-encoding.mjs.map +1 -0
- package/internal/qs/utils.d.mts.map +1 -1
- package/internal/qs/utils.d.ts.map +1 -1
- package/internal/qs/utils.js +307 -10
- package/internal/qs/utils.js.map +1 -1
- package/internal/qs/utils.mjs +307 -10
- package/internal/qs/utils.mjs.map +1 -1
- package/internal/request-options.d.mts +7 -0
- package/internal/request-options.d.mts.map +1 -1
- package/internal/request-options.d.ts +7 -0
- package/internal/request-options.d.ts.map +1 -1
- package/internal/request-options.js +43 -1
- package/internal/request-options.js.map +1 -1
- package/internal/request-options.mjs +42 -1
- package/internal/request-options.mjs.map +1 -1
- package/internal/responses/canonical-output-text.js +3 -3
- package/internal/responses/canonical-output-text.js.map +1 -1
- package/internal/responses/canonical-output-text.mjs +3 -3
- package/internal/responses/canonical-output-text.mjs.map +1 -1
- package/internal/responses/response-accumulator.d.mts +1 -1
- package/internal/responses/response-accumulator.d.mts.map +1 -1
- package/internal/responses/response-accumulator.d.ts +1 -1
- package/internal/responses/response-accumulator.d.ts.map +1 -1
- package/internal/responses/response-accumulator.js +331 -25
- package/internal/responses/response-accumulator.js.map +1 -1
- package/internal/responses/response-accumulator.mjs +331 -25
- package/internal/responses/response-accumulator.mjs.map +1 -1
- package/internal/tslib.js +6 -0
- package/internal/tslib.mjs +6 -1
- package/internal/uploads.d.mts +10 -6
- package/internal/uploads.d.mts.map +1 -1
- package/internal/uploads.d.ts +10 -6
- package/internal/uploads.d.ts.map +1 -1
- package/internal/uploads.js +65 -24
- package/internal/uploads.js.map +1 -1
- package/internal/uploads.mjs +65 -24
- package/internal/uploads.mjs.map +1 -1
- package/internal/utils/env.d.mts.map +1 -1
- package/internal/utils/env.d.ts.map +1 -1
- package/internal/utils/env.js +9 -4
- package/internal/utils/env.js.map +1 -1
- package/internal/utils/env.mjs +9 -4
- package/internal/utils/env.mjs.map +1 -1
- package/internal/ws.d.mts.map +1 -1
- package/internal/ws.d.ts.map +1 -1
- package/internal/ws.js +23 -1
- package/internal/ws.js.map +1 -1
- package/internal/ws.mjs +23 -1
- package/internal/ws.mjs.map +1 -1
- package/lib/AbstractChatCompletionRunner.d.mts.map +1 -1
- package/lib/AbstractChatCompletionRunner.d.ts.map +1 -1
- package/lib/AbstractChatCompletionRunner.js +32 -7
- package/lib/AbstractChatCompletionRunner.js.map +1 -1
- package/lib/AbstractChatCompletionRunner.mjs +34 -9
- package/lib/AbstractChatCompletionRunner.mjs.map +1 -1
- package/lib/AssistantStream.d.mts.map +1 -1
- package/lib/AssistantStream.d.ts.map +1 -1
- package/lib/AssistantStream.js +211 -23
- package/lib/AssistantStream.js.map +1 -1
- package/lib/AssistantStream.mjs +211 -23
- package/lib/AssistantStream.mjs.map +1 -1
- package/lib/ChatCompletionStream.d.mts +1 -1
- package/lib/ChatCompletionStream.d.mts.map +1 -1
- package/lib/ChatCompletionStream.d.ts +1 -1
- package/lib/ChatCompletionStream.d.ts.map +1 -1
- package/lib/ChatCompletionStream.js +1118 -67
- package/lib/ChatCompletionStream.js.map +1 -1
- package/lib/ChatCompletionStream.mjs +1119 -68
- package/lib/ChatCompletionStream.mjs.map +1 -1
- package/lib/EventEmitter.d.mts.map +1 -1
- package/lib/EventEmitter.d.ts.map +1 -1
- package/lib/EventEmitter.js +67 -9
- package/lib/EventEmitter.js.map +1 -1
- package/lib/EventEmitter.mjs +68 -10
- package/lib/EventEmitter.mjs.map +1 -1
- package/lib/EventStream.d.mts +4 -0
- package/lib/EventStream.d.mts.map +1 -1
- package/lib/EventStream.d.ts +4 -0
- package/lib/EventStream.d.ts.map +1 -1
- package/lib/EventStream.js +1096 -11
- package/lib/EventStream.js.map +1 -1
- package/lib/EventStream.mjs +1097 -12
- package/lib/EventStream.mjs.map +1 -1
- package/lib/ResponsesParser.d.mts.map +1 -1
- package/lib/ResponsesParser.d.ts.map +1 -1
- package/lib/ResponsesParser.js +1 -1
- package/lib/ResponsesParser.js.map +1 -1
- package/lib/ResponsesParser.mjs +1 -1
- package/lib/ResponsesParser.mjs.map +1 -1
- package/lib/Util.d.mts +2 -0
- package/lib/Util.d.mts.map +1 -1
- package/lib/Util.d.ts +2 -0
- package/lib/Util.d.ts.map +1 -1
- package/lib/Util.js +7 -4
- package/lib/Util.js.map +1 -1
- package/lib/Util.mjs +7 -4
- package/lib/Util.mjs.map +1 -1
- package/lib/assistant-run-polling.d.mts +12 -0
- package/lib/assistant-run-polling.d.mts.map +1 -0
- package/lib/assistant-run-polling.d.ts +12 -0
- package/lib/assistant-run-polling.d.ts.map +1 -0
- package/lib/assistant-run-polling.js +17 -0
- package/lib/assistant-run-polling.js.map +1 -0
- package/lib/assistant-run-polling.mjs +14 -0
- package/lib/assistant-run-polling.mjs.map +1 -0
- package/lib/embeddings.d.mts +18 -0
- package/lib/embeddings.d.mts.map +1 -0
- package/lib/embeddings.d.ts +18 -0
- package/lib/embeddings.d.ts.map +1 -0
- package/lib/embeddings.js +50 -0
- package/lib/embeddings.js.map +1 -0
- package/lib/embeddings.mjs +47 -0
- package/lib/embeddings.mjs.map +1 -0
- package/lib/file-processing.d.mts +10 -0
- package/lib/file-processing.d.mts.map +1 -0
- package/lib/file-processing.d.ts +10 -0
- package/lib/file-processing.d.ts.map +1 -0
- package/lib/file-processing.js +30 -0
- package/lib/file-processing.js.map +1 -0
- package/lib/file-processing.mjs +27 -0
- package/lib/file-processing.mjs.map +1 -0
- package/lib/parser.d.mts.map +1 -1
- package/lib/parser.d.ts.map +1 -1
- package/lib/parser.js +16 -4
- package/lib/parser.js.map +1 -1
- package/lib/parser.mjs +16 -4
- package/lib/parser.mjs.map +1 -1
- package/lib/polling.d.mts +20 -0
- package/lib/polling.d.mts.map +1 -0
- package/lib/polling.d.ts +20 -0
- package/lib/polling.d.ts.map +1 -0
- package/lib/polling.js +130 -0
- package/lib/polling.js.map +1 -0
- package/lib/polling.mjs +127 -0
- package/lib/polling.mjs.map +1 -0
- package/lib/responses/ResponseStream.d.mts.map +1 -1
- package/lib/responses/ResponseStream.d.ts.map +1 -1
- package/lib/responses/ResponseStream.js +21 -11
- package/lib/responses/ResponseStream.js.map +1 -1
- package/lib/responses/ResponseStream.mjs +21 -11
- package/lib/responses/ResponseStream.mjs.map +1 -1
- package/lib/vector-store-polling.d.mts +22 -0
- package/lib/vector-store-polling.d.mts.map +1 -0
- package/lib/vector-store-polling.d.ts +22 -0
- package/lib/vector-store-polling.d.ts.map +1 -0
- package/lib/vector-store-polling.js +24 -0
- package/lib/vector-store-polling.js.map +1 -0
- package/lib/vector-store-polling.mjs +20 -0
- package/lib/vector-store-polling.mjs.map +1 -0
- package/lib/vector-store-upload.d.mts +17 -0
- package/lib/vector-store-upload.d.mts.map +1 -0
- package/lib/vector-store-upload.d.ts +17 -0
- package/lib/vector-store-upload.d.ts.map +1 -0
- package/lib/vector-store-upload.js +37 -0
- package/lib/vector-store-upload.js.map +1 -0
- package/lib/vector-store-upload.mjs +34 -0
- package/lib/vector-store-upload.mjs.map +1 -0
- package/lib/webhook-signature.d.mts +15 -0
- package/lib/webhook-signature.d.mts.map +1 -0
- package/lib/webhook-signature.d.ts +15 -0
- package/lib/webhook-signature.d.ts.map +1 -0
- package/lib/webhook-signature.js +125 -0
- package/lib/webhook-signature.js.map +1 -0
- package/lib/webhook-signature.mjs +121 -0
- package/lib/webhook-signature.mjs.map +1 -0
- package/package.json +14 -1
- package/realtime/internal-base.d.mts +2 -0
- package/realtime/internal-base.d.mts.map +1 -1
- package/realtime/internal-base.d.ts +2 -0
- package/realtime/internal-base.d.ts.map +1 -1
- package/realtime/internal-base.js +15 -0
- package/realtime/internal-base.js.map +1 -1
- package/realtime/internal-base.mjs +14 -0
- package/realtime/internal-base.mjs.map +1 -1
- package/realtime/websocket.d.mts +3 -2
- package/realtime/websocket.d.mts.map +1 -1
- package/realtime/websocket.d.ts +3 -2
- package/realtime/websocket.d.ts.map +1 -1
- package/realtime/websocket.js +90 -26
- package/realtime/websocket.js.map +1 -1
- package/realtime/websocket.mjs +91 -27
- package/realtime/websocket.mjs.map +1 -1
- package/realtime/ws.d.mts.map +1 -1
- package/realtime/ws.d.ts.map +1 -1
- package/realtime/ws.js +9 -1
- package/realtime/ws.js.map +1 -1
- package/realtime/ws.mjs +10 -2
- package/realtime/ws.mjs.map +1 -1
- package/resources/admin/organization/index.d.mts +2 -2
- package/resources/admin/organization/index.d.mts.map +1 -1
- package/resources/admin/organization/index.d.ts +2 -2
- package/resources/admin/organization/index.d.ts.map +1 -1
- package/resources/admin/organization/index.js.map +1 -1
- package/resources/admin/organization/index.mjs.map +1 -1
- package/resources/admin/organization/organization.d.mts +4 -4
- package/resources/admin/organization/organization.d.mts.map +1 -1
- package/resources/admin/organization/organization.d.ts +4 -4
- package/resources/admin/organization/organization.d.ts.map +1 -1
- package/resources/admin/organization/organization.js.map +1 -1
- package/resources/admin/organization/organization.mjs.map +1 -1
- package/resources/admin/organization/projects/index.d.mts +1 -1
- package/resources/admin/organization/projects/index.d.mts.map +1 -1
- package/resources/admin/organization/projects/index.d.ts +1 -1
- package/resources/admin/organization/projects/index.d.ts.map +1 -1
- package/resources/admin/organization/projects/index.js.map +1 -1
- package/resources/admin/organization/projects/index.mjs.map +1 -1
- package/resources/admin/organization/projects/projects.d.mts +22 -5
- package/resources/admin/organization/projects/projects.d.mts.map +1 -1
- package/resources/admin/organization/projects/projects.d.ts +22 -5
- package/resources/admin/organization/projects/projects.d.ts.map +1 -1
- package/resources/admin/organization/projects/projects.js.map +1 -1
- package/resources/admin/organization/projects/projects.mjs.map +1 -1
- package/resources/admin/organization/usage.d.mts +62 -1
- package/resources/admin/organization/usage.d.mts.map +1 -1
- package/resources/admin/organization/usage.d.ts +62 -1
- package/resources/admin/organization/usage.d.ts.map +1 -1
- package/resources/admin/organization/usage.js.map +1 -1
- package/resources/admin/organization/usage.mjs.map +1 -1
- package/resources/beta/responses/internal-base.d.mts.map +1 -1
- package/resources/beta/responses/internal-base.d.ts.map +1 -1
- package/resources/beta/responses/internal-base.js +2 -0
- package/resources/beta/responses/internal-base.js.map +1 -1
- package/resources/beta/responses/internal-base.mjs +2 -0
- package/resources/beta/responses/internal-base.mjs.map +1 -1
- package/resources/beta/responses/responses.d.mts +17 -20
- package/resources/beta/responses/responses.d.mts.map +1 -1
- package/resources/beta/responses/responses.d.ts +17 -20
- package/resources/beta/responses/responses.d.ts.map +1 -1
- package/resources/beta/responses/responses.js.map +1 -1
- package/resources/beta/responses/responses.mjs.map +1 -1
- package/resources/beta/threads/runs/index.d.mts +1 -1
- package/resources/beta/threads/runs/index.d.mts.map +1 -1
- package/resources/beta/threads/runs/index.d.ts +1 -1
- package/resources/beta/threads/runs/index.d.ts.map +1 -1
- package/resources/beta/threads/runs/runs.d.mts.map +1 -1
- package/resources/beta/threads/runs/runs.d.ts.map +1 -1
- package/resources/beta/threads/runs/runs.js +2 -43
- package/resources/beta/threads/runs/runs.js.map +1 -1
- package/resources/beta/threads/runs/runs.mjs +2 -43
- package/resources/beta/threads/runs/runs.mjs.map +1 -1
- package/resources/chat/completions/completions.d.mts +6 -0
- package/resources/chat/completions/completions.d.mts.map +1 -1
- package/resources/chat/completions/completions.d.ts +6 -0
- package/resources/chat/completions/completions.d.ts.map +1 -1
- package/resources/chat/completions/completions.js.map +1 -1
- package/resources/chat/completions/completions.mjs.map +1 -1
- package/resources/embeddings.d.mts.map +1 -1
- package/resources/embeddings.d.ts.map +1 -1
- package/resources/embeddings.js +2 -36
- package/resources/embeddings.js.map +1 -1
- package/resources/embeddings.mjs +2 -36
- package/resources/embeddings.mjs.map +1 -1
- package/resources/files.d.mts.map +1 -1
- package/resources/files.d.ts.map +1 -1
- package/resources/files.js +2 -15
- package/resources/files.js.map +1 -1
- package/resources/files.mjs +2 -15
- package/resources/files.mjs.map +1 -1
- package/resources/images.d.mts +12 -22
- package/resources/images.d.mts.map +1 -1
- package/resources/images.d.ts +12 -22
- package/resources/images.d.ts.map +1 -1
- package/resources/realtime/calls.d.mts +23 -1
- package/resources/realtime/calls.d.mts.map +1 -1
- package/resources/realtime/calls.d.ts +23 -1
- package/resources/realtime/calls.d.ts.map +1 -1
- package/resources/realtime/calls.js +24 -0
- package/resources/realtime/calls.js.map +1 -1
- package/resources/realtime/calls.mjs +24 -0
- package/resources/realtime/calls.mjs.map +1 -1
- package/resources/realtime/index.d.mts +1 -1
- package/resources/realtime/index.d.mts.map +1 -1
- package/resources/realtime/index.d.ts +1 -1
- package/resources/realtime/index.d.ts.map +1 -1
- package/resources/realtime/index.js.map +1 -1
- package/resources/realtime/index.mjs +1 -1
- package/resources/realtime/index.mjs.map +1 -1
- package/resources/realtime/realtime.d.mts +5 -4
- package/resources/realtime/realtime.d.mts.map +1 -1
- package/resources/realtime/realtime.d.ts +5 -4
- package/resources/realtime/realtime.d.ts.map +1 -1
- package/resources/realtime/realtime.js.map +1 -1
- package/resources/realtime/realtime.mjs.map +1 -1
- package/resources/responses/internal-base.d.mts.map +1 -1
- package/resources/responses/internal-base.d.ts.map +1 -1
- package/resources/responses/internal-base.js +2 -0
- package/resources/responses/internal-base.js.map +1 -1
- package/resources/responses/internal-base.mjs +2 -0
- package/resources/responses/internal-base.mjs.map +1 -1
- package/resources/responses/responses.d.mts +17 -20
- package/resources/responses/responses.d.mts.map +1 -1
- package/resources/responses/responses.d.ts +17 -20
- package/resources/responses/responses.d.ts.map +1 -1
- package/resources/responses/responses.js.map +1 -1
- package/resources/responses/responses.mjs.map +1 -1
- package/resources/vector-stores/file-batches.d.mts.map +1 -1
- package/resources/vector-stores/file-batches.d.ts.map +1 -1
- package/resources/vector-stores/file-batches.js +4 -61
- package/resources/vector-stores/file-batches.js.map +1 -1
- package/resources/vector-stores/file-batches.mjs +4 -61
- package/resources/vector-stores/file-batches.mjs.map +1 -1
- package/resources/vector-stores/files.d.mts +1 -1
- package/resources/vector-stores/files.d.mts.map +1 -1
- package/resources/vector-stores/files.d.ts +1 -1
- package/resources/vector-stores/files.d.ts.map +1 -1
- package/resources/vector-stores/files.js +2 -35
- package/resources/vector-stores/files.js.map +1 -1
- package/resources/vector-stores/files.mjs +2 -35
- package/resources/vector-stores/files.mjs.map +1 -1
- package/resources/webhooks/webhooks.d.mts.map +1 -1
- package/resources/webhooks/webhooks.d.ts.map +1 -1
- package/resources/webhooks/webhooks.js +5 -43
- package/resources/webhooks/webhooks.js.map +1 -1
- package/resources/webhooks/webhooks.mjs +5 -43
- package/resources/webhooks/webhooks.mjs.map +1 -1
- package/src/auth/index.ts +6 -1
- package/src/auth/subject-token-providers.ts +196 -4
- package/src/auth/types.ts +24 -0
- package/src/auth/workload-identity-auth.ts +104 -7
- package/src/auth/x509-transport.ts +49 -0
- package/src/azure.ts +22 -1
- package/src/bedrock.ts +49 -5
- package/src/beta/realtime/internal-base.ts +15 -0
- package/src/beta/realtime/websocket.ts +148 -40
- package/src/beta/realtime/ws.ts +31 -13
- package/src/client.ts +536 -92
- package/src/core/EventEmitter.ts +91 -7
- package/src/core/streaming.ts +226 -30
- package/src/helpers/audio.ts +93 -22
- package/src/helpers/standard-schema.ts +50 -16
- package/src/helpers/zod-v3-strict-schema.ts +514 -0
- package/src/helpers/zod.ts +17 -4
- package/src/index.ts +1 -1
- package/src/internal/assistant-stream-delta.ts +33 -10
- package/src/internal/auth/x509-token-exchange.ts +310 -0
- package/src/internal/auth/x509-transport-capability.ts +219 -0
- package/src/internal/auth/x509-transport-registry.ts +118 -0
- package/src/internal/auth/x509-transport-state-browser.ts +36 -0
- package/src/internal/auth/x509-transport-state.cts +36 -0
- package/src/internal/auth/x509-workload-identity-auth.ts +958 -0
- package/src/internal/bedrock.ts +182 -5
- package/src/internal/data-residency.ts +44 -0
- package/src/internal/multipart-encoding.ts +53 -0
- package/src/internal/qs/utils.ts +375 -13
- package/src/internal/request-options.ts +52 -1
- package/src/internal/responses/canonical-output-text.ts +3 -3
- package/src/internal/responses/response-accumulator.ts +411 -24
- package/src/internal/uploads.ts +81 -26
- package/src/internal/utils/env.ts +9 -5
- package/src/internal/ws.ts +24 -3
- package/src/lib/AbstractChatCompletionRunner.ts +33 -6
- package/src/lib/AssistantStream.ts +262 -22
- package/src/lib/ChatCompletionStream.ts +1467 -103
- package/src/lib/EventEmitter.ts +91 -7
- package/src/lib/EventStream.ts +1483 -10
- package/src/lib/ResponsesParser.ts +4 -1
- package/src/lib/Util.ts +7 -5
- package/src/lib/assistant-run-polling.ts +27 -0
- package/src/lib/embeddings.ts +65 -0
- package/src/lib/file-processing.ts +36 -0
- package/src/lib/parser.ts +19 -4
- package/src/lib/polling.ts +144 -0
- package/src/lib/responses/ResponseStream.ts +22 -10
- package/src/lib/vector-store-polling.ts +46 -0
- package/src/lib/vector-store-upload.ts +53 -0
- package/src/lib/webhook-signature.ts +164 -0
- package/src/realtime/internal-base.ts +15 -0
- package/src/realtime/websocket.ts +130 -27
- package/src/realtime/ws.ts +15 -2
- package/src/resources/admin/organization/index.ts +2 -0
- package/src/resources/admin/organization/organization.ts +4 -0
- package/src/resources/admin/organization/projects/index.ts +1 -0
- package/src/resources/admin/organization/projects/projects.ts +37 -4
- package/src/resources/admin/organization/usage.ts +83 -0
- package/src/resources/beta/responses/internal-base.ts +2 -0
- package/src/resources/beta/responses/responses.ts +19 -22
- package/src/resources/beta/threads/runs/index.ts +1 -1
- package/src/resources/beta/threads/runs/runs.ts +2 -45
- package/src/resources/chat/completions/completions.ts +7 -0
- package/src/resources/embeddings.ts +2 -42
- package/src/resources/files.ts +2 -19
- package/src/resources/images.ts +12 -22
- package/src/resources/realtime/api.md +1 -0
- package/src/resources/realtime/calls.ts +46 -0
- package/src/resources/realtime/index.ts +7 -1
- package/src/resources/realtime/realtime.ts +5 -3
- package/src/resources/responses/internal-base.ts +2 -0
- package/src/resources/responses/responses.ts +19 -22
- package/src/resources/vector-stores/file-batches.ts +8 -77
- package/src/resources/vector-stores/files.ts +3 -43
- package/src/resources/webhooks/webhooks.ts +5 -61
- package/src/version.ts +1 -1
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
package/client.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Castiron. See CONTRIBUTING.md for details.
|
|
2
|
-
var _OpenAI_instances, _a, _OpenAI_encoder, _OpenAI_responseAttempts, _OpenAI_baseURLOverridden;
|
|
2
|
+
var _OpenAI_instances, _a, _OpenAI_encoder, _OpenAI_x509Authentication, _OpenAI_x509Fetch, _OpenAI_explicitDataResidency, _OpenAI_responseAttempts, _OpenAI_baseURLOverridden;
|
|
3
3
|
import { __classPrivateFieldGet, __classPrivateFieldSet } from "./internal/tslib.mjs";
|
|
4
4
|
import { uuid4 } from "./internal/utils/uuid.mjs";
|
|
5
|
-
import { validatePositiveInteger, isAbsoluteURL, safeJSON } from "./internal/utils/values.mjs";
|
|
5
|
+
import { validatePositiveInteger, isAbsoluteURL, safeJSON, hasOwn } from "./internal/utils/values.mjs";
|
|
6
6
|
import { sleep } from "./internal/utils/sleep.mjs";
|
|
7
7
|
import { castToError, isAbortError } from "./internal/errors.mjs";
|
|
8
8
|
import { addRequestID, defaultParseResponse } from "./internal/parse.mjs";
|
|
@@ -11,9 +11,12 @@ import * as Shims from "./internal/shims.mjs";
|
|
|
11
11
|
import * as Opts from "./internal/request-options.mjs";
|
|
12
12
|
import { stringifyQuery } from "./internal/utils/query.mjs";
|
|
13
13
|
import { VERSION } from "./version.mjs";
|
|
14
|
+
import { resolveDataResidency } from "./internal/data-residency.mjs";
|
|
14
15
|
import * as Errors from "./core/error.mjs";
|
|
15
16
|
import * as Pagination from "./core/pagination.mjs";
|
|
16
17
|
import { WorkloadIdentityAuth } from "./auth/workload-identity-auth.mjs";
|
|
18
|
+
import { X509_API_BASE_URL, X509WorkloadIdentityAuth, assertX509APIOrigin, assertX509RequestOptions, isX509WorkloadIdentity, snapshotX509RequestOptions, } from "./internal/auth/x509-workload-identity-auth.mjs";
|
|
19
|
+
import { isTransientX509ConnectionError, markApprovedX509Client } from '#x509-transport-state';
|
|
17
20
|
import { OAuthError, SubjectTokenProviderError } from "./core/error.mjs";
|
|
18
21
|
import * as Uploads from "./core/uploads.mjs";
|
|
19
22
|
import * as API from "./resources/index.mjs";
|
|
@@ -65,6 +68,7 @@ function isRunningInBrowserOrBrowserWorker() {
|
|
|
65
68
|
scope.WebSocketPair === undefined);
|
|
66
69
|
}
|
|
67
70
|
const WORKLOAD_IDENTITY_API_KEY_PLACEHOLDER = 'workload-identity-auth';
|
|
71
|
+
const inheritedDataResidencySelection = Symbol('inheritedDataResidencySelection');
|
|
68
72
|
/**
|
|
69
73
|
* API Client for interfacing with the OpenAI API.
|
|
70
74
|
*/
|
|
@@ -90,6 +94,10 @@ export class OpenAI {
|
|
|
90
94
|
constructor(clientOptions = {}) {
|
|
91
95
|
_OpenAI_instances.add(this);
|
|
92
96
|
_OpenAI_encoder.set(this, void 0);
|
|
97
|
+
_OpenAI_x509Authentication.set(this, void 0);
|
|
98
|
+
_OpenAI_x509Fetch.set(this, void 0);
|
|
99
|
+
// Preserve an explicit global selection without storing a second routing URL.
|
|
100
|
+
_OpenAI_explicitDataResidency.set(this, false);
|
|
93
101
|
_OpenAI_responseAttempts.set(this, new WeakMap());
|
|
94
102
|
/**
|
|
95
103
|
* Given a prompt, the model will return one or more predicted completions, and can also return the probabilities of alternative tokens at each position.
|
|
@@ -148,16 +156,22 @@ export class OpenAI {
|
|
|
148
156
|
* @deprecated The Sora API is scheduled to permanently shut down on September 24, 2026.
|
|
149
157
|
*/
|
|
150
158
|
this.videos = new API.Videos(this);
|
|
159
|
+
const residencyBaseURL = resolveDataResidency(clientOptions);
|
|
151
160
|
const provider = clientOptions.provider;
|
|
161
|
+
const { baseURL = provider ? null : readEnv('OPENAI_BASE_URL'), dataResidency: _dataResidency, [inheritedDataResidencySelection]: inheritedResidencySelection = false, apiKey = provider ? null : (readEnv('OPENAI_API_KEY') ?? null), adminAPIKey = provider ? null : (readEnv('OPENAI_ADMIN_KEY') ?? null), organization = provider ? null : (readEnv('OPENAI_ORG_ID') ?? null), project = provider ? null : (readEnv('OPENAI_PROJECT_ID') ?? null), webhookSecret = readEnv('OPENAI_WEBHOOK_SECRET') ?? null, workloadIdentity, x509Transport, ...opts } = clientOptions;
|
|
152
162
|
if (provider) {
|
|
153
|
-
const conflictingOptions = ['apiKey', 'adminAPIKey', 'workloadIdentity', 'baseURL'].filter((key) => clientOptions[key] != null);
|
|
163
|
+
const conflictingOptions = ['apiKey', 'adminAPIKey', 'workloadIdentity', 'x509Transport', 'baseURL', 'dataResidency'].filter((key) => (key === 'workloadIdentity' ? workloadIdentity : clientOptions[key]) != null);
|
|
154
164
|
if (conflictingOptions.length) {
|
|
155
165
|
throw new Errors.OpenAIError(`The \`provider\` option cannot be used with ${conflictingOptions
|
|
156
166
|
.map((key) => `\`${key}\``)
|
|
157
167
|
.join(', ')}. Configure authentication and the base URL through the provider instead.`);
|
|
158
168
|
}
|
|
159
169
|
}
|
|
160
|
-
const
|
|
170
|
+
const identity = isX509WorkloadIdentity(workloadIdentity)
|
|
171
|
+
? { x509: workloadIdentity, legacy: undefined }
|
|
172
|
+
: { x509: undefined, legacy: workloadIdentity };
|
|
173
|
+
const x509Identity = identity.x509;
|
|
174
|
+
const usesX509Identity = x509Identity !== undefined;
|
|
161
175
|
const providerRuntime = provider ? configureProvider(provider) : undefined;
|
|
162
176
|
const options = {
|
|
163
177
|
apiKey,
|
|
@@ -166,10 +180,30 @@ export class OpenAI {
|
|
|
166
180
|
project,
|
|
167
181
|
webhookSecret,
|
|
168
182
|
workloadIdentity,
|
|
183
|
+
x509Transport,
|
|
169
184
|
provider,
|
|
170
185
|
...opts,
|
|
171
|
-
baseURL: providerRuntime?.baseURL ??
|
|
186
|
+
baseURL: providerRuntime?.baseURL ??
|
|
187
|
+
residencyBaseURL ??
|
|
188
|
+
(baseURL || (usesX509Identity ? X509_API_BASE_URL : `https://api.openai.com/v1`)),
|
|
172
189
|
};
|
|
190
|
+
if (x509Transport && !usesX509Identity) {
|
|
191
|
+
throw new Errors.OpenAIError('An X.509 transport requires an X.509 workload identity.');
|
|
192
|
+
}
|
|
193
|
+
if (usesX509Identity) {
|
|
194
|
+
if (residencyBaseURL !== undefined || inheritedResidencySelection) {
|
|
195
|
+
throw new Errors.OpenAIError('X.509 workload identity does not support data residency selection.');
|
|
196
|
+
}
|
|
197
|
+
if (clientOptions.fetch !== undefined) {
|
|
198
|
+
throw new Errors.OpenAIError('X.509 workload identity does not support a custom fetch implementation.');
|
|
199
|
+
}
|
|
200
|
+
assertX509APIOrigin(options.baseURL);
|
|
201
|
+
assertX509RequestOptions(options.fetchOptions);
|
|
202
|
+
if (this.fetchWithAuth !== _a.prototype.fetchWithAuth ||
|
|
203
|
+
this.fetchWithTimeout !== _a.prototype.fetchWithTimeout) {
|
|
204
|
+
throw new Errors.OpenAIError('X.509 workload identity does not support overridden fetch dispatch hooks.');
|
|
205
|
+
}
|
|
206
|
+
}
|
|
173
207
|
if (apiKey && workloadIdentity) {
|
|
174
208
|
throw new Errors.OpenAIError('The `apiKey` and `workloadIdentity` options are mutually exclusive');
|
|
175
209
|
}
|
|
@@ -180,6 +214,7 @@ export class OpenAI {
|
|
|
180
214
|
throw new Errors.OpenAIError("It looks like you're running in a browser-like environment.\n\nThis is disabled by default, as it risks exposing your secret API credentials to attackers.\nIf you understand the risks and have appropriate mitigations in place,\nyou can set the `dangerouslyAllowBrowser` option to `true`, e.g.,\n\nnew OpenAI({ apiKey, dangerouslyAllowBrowser: true });\n\nhttps://help.openai.com/en/articles/5112595-best-practices-for-api-key-safety\n");
|
|
181
215
|
}
|
|
182
216
|
this.baseURL = options.baseURL;
|
|
217
|
+
__classPrivateFieldSet(this, _OpenAI_explicitDataResidency, residencyBaseURL !== undefined || inheritedResidencySelection, "f");
|
|
183
218
|
this.timeout = options.timeout ?? _a.DEFAULT_TIMEOUT; /* 10 minutes */
|
|
184
219
|
this.logger = options.logger ?? console;
|
|
185
220
|
const defaultLogLevel = 'warn';
|
|
@@ -206,8 +241,16 @@ export class OpenAI {
|
|
|
206
241
|
}
|
|
207
242
|
this._options = options;
|
|
208
243
|
this._provider = providerRuntime;
|
|
209
|
-
if (
|
|
210
|
-
|
|
244
|
+
if (x509Identity) {
|
|
245
|
+
const authentication = new X509WorkloadIdentityAuth(x509Identity, x509Transport, organization, project);
|
|
246
|
+
this._workloadIdentityAuth = authentication;
|
|
247
|
+
__classPrivateFieldSet(this, _OpenAI_x509Authentication, authentication, "f");
|
|
248
|
+
__classPrivateFieldSet(this, _OpenAI_x509Fetch, authentication.fetch(), "f");
|
|
249
|
+
this.fetch = __classPrivateFieldGet(this, _OpenAI_x509Fetch, "f");
|
|
250
|
+
markApprovedX509Client(this);
|
|
251
|
+
}
|
|
252
|
+
else if (identity.legacy) {
|
|
253
|
+
this._workloadIdentityAuth = new WorkloadIdentityAuth(identity.legacy, this.fetch);
|
|
211
254
|
}
|
|
212
255
|
this.apiKey = typeof apiKey === 'string' ? apiKey : null;
|
|
213
256
|
this.adminAPIKey = adminAPIKey;
|
|
@@ -219,8 +262,10 @@ export class OpenAI {
|
|
|
219
262
|
* Create a new client instance re-using the same options given to the current client with optional overriding.
|
|
220
263
|
*/
|
|
221
264
|
withOptions(options) {
|
|
265
|
+
const residencyBaseURL = resolveDataResidency(options);
|
|
222
266
|
const inheritedProvider = this._options.provider;
|
|
223
267
|
const provider = options.provider ?? inheritedProvider;
|
|
268
|
+
const x509Authentication = __classPrivateFieldGet(this, _OpenAI_x509Authentication, "f");
|
|
224
269
|
const inheritedOptions = {
|
|
225
270
|
...this._options,
|
|
226
271
|
baseURL: this.baseURL,
|
|
@@ -228,19 +273,39 @@ export class OpenAI {
|
|
|
228
273
|
timeout: this.timeout,
|
|
229
274
|
logger: this.logger,
|
|
230
275
|
logLevel: this.logLevel,
|
|
231
|
-
fetch: this.fetch,
|
|
276
|
+
fetch: __classPrivateFieldGet(this, _OpenAI_x509Authentication, "f") ? undefined : this.fetch,
|
|
232
277
|
fetchOptions: this.fetchOptions,
|
|
233
278
|
apiKey: this._options.apiKey,
|
|
234
279
|
adminAPIKey: this.adminAPIKey,
|
|
235
|
-
workloadIdentity: this._options.workloadIdentity,
|
|
280
|
+
workloadIdentity: x509Authentication?.identitySnapshot() ?? this._options.workloadIdentity,
|
|
281
|
+
x509Transport: this._options.x509Transport,
|
|
236
282
|
organization: this.organization,
|
|
237
283
|
project: this.project,
|
|
238
284
|
webhookSecret: this.webhookSecret,
|
|
239
285
|
};
|
|
286
|
+
const currentlyX509 = x509Authentication !== undefined;
|
|
287
|
+
const nextIdentity = hasOwn(options, 'workloadIdentity')
|
|
288
|
+
? options.workloadIdentity
|
|
289
|
+
: inheritedOptions.workloadIdentity;
|
|
290
|
+
const nextX509 = isX509WorkloadIdentity(nextIdentity);
|
|
291
|
+
if (currentlyX509 !== nextX509) {
|
|
292
|
+
delete inheritedOptions.fetch;
|
|
293
|
+
delete inheritedOptions.baseURL;
|
|
294
|
+
if (nextX509) {
|
|
295
|
+
inheritedOptions.apiKey = null;
|
|
296
|
+
}
|
|
297
|
+
else {
|
|
298
|
+
delete inheritedOptions.x509Transport;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
if (residencyBaseURL !== undefined) {
|
|
302
|
+
delete inheritedOptions.baseURL;
|
|
303
|
+
}
|
|
240
304
|
if (provider) {
|
|
241
305
|
delete inheritedOptions.apiKey;
|
|
242
306
|
delete inheritedOptions.adminAPIKey;
|
|
243
307
|
delete inheritedOptions.workloadIdentity;
|
|
308
|
+
delete inheritedOptions.x509Transport;
|
|
244
309
|
delete inheritedOptions.baseURL;
|
|
245
310
|
if (provider !== inheritedProvider) {
|
|
246
311
|
delete inheritedOptions.organization;
|
|
@@ -248,11 +313,24 @@ export class OpenAI {
|
|
|
248
313
|
delete inheritedOptions.defaultHeaders;
|
|
249
314
|
}
|
|
250
315
|
}
|
|
251
|
-
const
|
|
316
|
+
const clientOptions = {
|
|
252
317
|
...inheritedOptions,
|
|
253
318
|
...options,
|
|
254
319
|
provider,
|
|
255
|
-
|
|
320
|
+
[inheritedDataResidencySelection]: __classPrivateFieldGet(this, _OpenAI_explicitDataResidency, "f") &&
|
|
321
|
+
residencyBaseURL === undefined &&
|
|
322
|
+
!hasOwn(options, 'baseURL') &&
|
|
323
|
+
!provider,
|
|
324
|
+
};
|
|
325
|
+
const client = new this.constructor(clientOptions);
|
|
326
|
+
if (__classPrivateFieldGet(this, _OpenAI_x509Authentication, "f") &&
|
|
327
|
+
__classPrivateFieldGet(client, _OpenAI_x509Authentication, "f") &&
|
|
328
|
+
this.baseURL === client.baseURL &&
|
|
329
|
+
__classPrivateFieldGet(this, _OpenAI_x509Authentication, "f").matches(__classPrivateFieldGet(client, _OpenAI_x509Authentication, "f"))) {
|
|
330
|
+
client._workloadIdentityAuth = __classPrivateFieldGet(this, _OpenAI_x509Authentication, "f");
|
|
331
|
+
__classPrivateFieldSet(client, _OpenAI_x509Authentication, __classPrivateFieldGet(this, _OpenAI_x509Authentication, "f"), "f");
|
|
332
|
+
__classPrivateFieldSet(client, _OpenAI_x509Fetch, __classPrivateFieldGet(this, _OpenAI_x509Fetch, "f"), "f");
|
|
333
|
+
}
|
|
256
334
|
return client;
|
|
257
335
|
}
|
|
258
336
|
defaultQuery() {
|
|
@@ -277,14 +355,41 @@ export class OpenAI {
|
|
|
277
355
|
bearerAuth: true,
|
|
278
356
|
adminAPIKeyAuth: true,
|
|
279
357
|
}) {
|
|
358
|
+
const authentication = __classPrivateFieldGet(this, _OpenAI_x509Authentication, "f") ?? this._workloadIdentityAuth;
|
|
359
|
+
if (authentication instanceof X509WorkloadIdentityAuth &&
|
|
360
|
+
schemes.adminAPIKeyAuth &&
|
|
361
|
+
this.adminAPIKey !== null) {
|
|
362
|
+
return await this.adminAPIKeyAuth(opts);
|
|
363
|
+
}
|
|
280
364
|
return buildHeaders([
|
|
281
365
|
schemes.bearerAuth ? await this.bearerAuth(opts) : null,
|
|
282
366
|
schemes.adminAPIKeyAuth ? await this.adminAPIKeyAuth(opts) : null,
|
|
283
367
|
]);
|
|
284
368
|
}
|
|
285
369
|
async bearerAuth(opts) {
|
|
286
|
-
|
|
287
|
-
|
|
370
|
+
const authentication = __classPrivateFieldGet(this, _OpenAI_x509Authentication, "f") ?? this._workloadIdentityAuth;
|
|
371
|
+
if (authentication) {
|
|
372
|
+
if (authentication instanceof X509WorkloadIdentityAuth) {
|
|
373
|
+
if (authentication === this._workloadIdentityAuth &&
|
|
374
|
+
(this.fetchWithAuth !== _a.prototype.fetchWithAuth ||
|
|
375
|
+
this.fetchWithTimeout !== _a.prototype.fetchWithTimeout)) {
|
|
376
|
+
throw new Errors.OpenAIError('X.509 workload identity does not support overridden fetch dispatch hooks.');
|
|
377
|
+
}
|
|
378
|
+
const snapshots = authentication.headerSnapshots();
|
|
379
|
+
if (!X509WorkloadIdentityAuth.shouldAuthenticate(opts, snapshots.defaultHeaders, snapshots.requestHeaders)) {
|
|
380
|
+
return undefined;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
const token = authentication instanceof X509WorkloadIdentityAuth
|
|
384
|
+
? await authentication.getToken(opts, {
|
|
385
|
+
apiURL: authentication.requestAPIURL(),
|
|
386
|
+
...authentication.headerSnapshots(),
|
|
387
|
+
...authentication.requestSnapshot(),
|
|
388
|
+
signal: authentication.effectiveSignal(),
|
|
389
|
+
...authentication.tenantSnapshot(),
|
|
390
|
+
})
|
|
391
|
+
: await authentication.getToken();
|
|
392
|
+
return buildHeaders([{ Authorization: `Bearer ${token}` }]);
|
|
288
393
|
}
|
|
289
394
|
if (this.apiKey == null) {
|
|
290
395
|
return undefined;
|
|
@@ -387,10 +492,17 @@ export class OpenAI {
|
|
|
387
492
|
}));
|
|
388
493
|
}
|
|
389
494
|
request(options, remainingRetries = null) {
|
|
390
|
-
|
|
495
|
+
const authentication = __classPrivateFieldGet(this, _OpenAI_x509Authentication, "f") ?? this._workloadIdentityAuth;
|
|
496
|
+
const request = authentication instanceof X509WorkloadIdentityAuth
|
|
497
|
+
? Promise.resolve(options).then((resolved) => authentication.runRequest(() => this.makeRequest(resolved, remainingRetries, undefined), this))
|
|
498
|
+
: this.makeRequest(options, remainingRetries, undefined);
|
|
499
|
+
return this.responsePromise(request);
|
|
391
500
|
}
|
|
392
501
|
responsePromise(request, parse = (client, props) => this.parseResponseWithTimeout(client, props)) {
|
|
393
|
-
const promise = new APIPromise(this, request,
|
|
502
|
+
const promise = new APIPromise(this, request, (client, props) => {
|
|
503
|
+
const resume = __classPrivateFieldGet(this, _OpenAI_responseAttempts, "f").get(props.controller)?.continueRequest;
|
|
504
|
+
return resume ? resume(() => parse(client, props)) : parse(client, props);
|
|
505
|
+
});
|
|
394
506
|
// A body timeout can retry after the original raw response has arrived. Wait for
|
|
395
507
|
// parsing before selecting the response so withResponse() reports the retry.
|
|
396
508
|
promise.withResponse = async () => {
|
|
@@ -411,15 +523,30 @@ export class OpenAI {
|
|
|
411
523
|
while (true) {
|
|
412
524
|
const attempt = __classPrivateFieldGet(this, _OpenAI_responseAttempts, "f").get(props.controller);
|
|
413
525
|
const timeout = attempt?.timeout ?? props.options.timeout ?? this.timeout;
|
|
414
|
-
const
|
|
415
|
-
const callerSignal = props.options.signal;
|
|
526
|
+
const x509Authentication = attempt?.authentication;
|
|
527
|
+
const callerSignal = x509Authentication ? props.controller.signal : props.options.signal;
|
|
528
|
+
const abortError = () => x509Authentication && callerSignal
|
|
529
|
+
? this._makeUserAbortError(callerSignal)
|
|
530
|
+
: new Errors.APIUserAbortError();
|
|
531
|
+
let remaining;
|
|
532
|
+
try {
|
|
533
|
+
remaining =
|
|
534
|
+
x509Authentication?.remainingTimeout(props.options, timeout) ??
|
|
535
|
+
Math.max(0, props.startTime + timeout - Date.now());
|
|
536
|
+
}
|
|
537
|
+
catch (error) {
|
|
538
|
+
const cancellation = callerSignal?.aborted ? abortError() : undefined;
|
|
539
|
+
props.controller.abort();
|
|
540
|
+
void Shims.CancelReadableStream(props.response.body).catch(() => undefined);
|
|
541
|
+
throw cancellation ?? error;
|
|
542
|
+
}
|
|
416
543
|
let timer;
|
|
417
544
|
let abortListener;
|
|
418
545
|
let timedOut = false;
|
|
419
546
|
try {
|
|
420
547
|
// Tool runners preserve a completed buffered turn before cancellation stops the next request.
|
|
421
|
-
if (callerSignal?.aborted &&
|
|
422
|
-
throw
|
|
548
|
+
if (callerSignal?.aborted && attempt?.helperMethod !== 'runTools') {
|
|
549
|
+
throw abortError();
|
|
423
550
|
}
|
|
424
551
|
const timeoutPromise = new Promise((_, reject) => {
|
|
425
552
|
timer = setTimeout(() => {
|
|
@@ -428,21 +555,33 @@ export class OpenAI {
|
|
|
428
555
|
reject(new Errors.APIConnectionTimeoutError());
|
|
429
556
|
}, remaining);
|
|
430
557
|
if (callerSignal) {
|
|
431
|
-
abortListener = () =>
|
|
558
|
+
abortListener = () => {
|
|
559
|
+
if (!timedOut)
|
|
560
|
+
reject(abortError());
|
|
561
|
+
};
|
|
432
562
|
callerSignal.addEventListener('abort', abortListener, { once: true });
|
|
433
563
|
}
|
|
434
564
|
});
|
|
435
565
|
return await Promise.race([defaultParseResponse(client, props), timeoutPromise]);
|
|
436
566
|
}
|
|
437
567
|
catch (error) {
|
|
438
|
-
if (callerSignal?.aborted) {
|
|
439
|
-
throw
|
|
568
|
+
if (callerSignal?.aborted && !timedOut) {
|
|
569
|
+
throw abortError();
|
|
440
570
|
}
|
|
441
571
|
if (!timedOut) {
|
|
572
|
+
if (x509Authentication && error instanceof SyntaxError) {
|
|
573
|
+
throw new SyntaxError('X.509 workload identity API response contains invalid JSON.');
|
|
574
|
+
}
|
|
575
|
+
if (x509Authentication && !(error instanceof Errors.OpenAIError)) {
|
|
576
|
+
throw new Errors.APIConnectionError({
|
|
577
|
+
message: 'X.509 workload identity API response body could not be read.',
|
|
578
|
+
});
|
|
579
|
+
}
|
|
442
580
|
throw error;
|
|
443
581
|
}
|
|
444
582
|
const retriesRemaining = attempt?.retriesRemaining ?? 0;
|
|
445
583
|
if (!retriesRemaining ||
|
|
584
|
+
attempt?.hasStreamingBody ||
|
|
446
585
|
props.options.__metadata?.['hasStreamingBody'] ||
|
|
447
586
|
(globalThis.ReadableStream &&
|
|
448
587
|
props.options.body instanceof globalThis.ReadableStream) ||
|
|
@@ -470,6 +609,46 @@ export class OpenAI {
|
|
|
470
609
|
}
|
|
471
610
|
}
|
|
472
611
|
}
|
|
612
|
+
/** Keeps terminal X.509 error-body consumption inside the original logical request deadline. */
|
|
613
|
+
async readX509ResponseError(response, options, timeout, controller, authentication) {
|
|
614
|
+
const deadline = new AbortController();
|
|
615
|
+
const callerSignal = controller.signal;
|
|
616
|
+
let timedOut = false;
|
|
617
|
+
const cancel = () => deadline.abort(callerSignal.reason);
|
|
618
|
+
callerSignal.addEventListener('abort', cancel, { once: true });
|
|
619
|
+
if (callerSignal.aborted) {
|
|
620
|
+
cancel();
|
|
621
|
+
}
|
|
622
|
+
try {
|
|
623
|
+
const remaining = authentication.remainingTimeout(options, timeout);
|
|
624
|
+
const expiration = authentication.waitForRetry(remaining, deadline.signal).then(() => {
|
|
625
|
+
throw new Errors.APIConnectionTimeoutError();
|
|
626
|
+
});
|
|
627
|
+
const body = await Promise.race([
|
|
628
|
+
response.text().catch(() => 'X.509 workload identity API response body could not be read.'),
|
|
629
|
+
expiration,
|
|
630
|
+
]);
|
|
631
|
+
if (callerSignal.aborted) {
|
|
632
|
+
throw this._makeUserAbortError(callerSignal);
|
|
633
|
+
}
|
|
634
|
+
return body;
|
|
635
|
+
}
|
|
636
|
+
catch (error) {
|
|
637
|
+
if (error instanceof Errors.APIConnectionTimeoutError) {
|
|
638
|
+
timedOut = !callerSignal.aborted;
|
|
639
|
+
controller.abort();
|
|
640
|
+
void Shims.CancelReadableStream(response.body).catch(() => undefined);
|
|
641
|
+
}
|
|
642
|
+
if (callerSignal.aborted && !timedOut) {
|
|
643
|
+
throw this._makeUserAbortError(callerSignal);
|
|
644
|
+
}
|
|
645
|
+
throw error;
|
|
646
|
+
}
|
|
647
|
+
finally {
|
|
648
|
+
callerSignal.removeEventListener('abort', cancel);
|
|
649
|
+
deadline.abort();
|
|
650
|
+
}
|
|
651
|
+
}
|
|
473
652
|
async makeRequest(optionsInput, retriesRemaining, retryOfRequestLogID) {
|
|
474
653
|
const options = await optionsInput;
|
|
475
654
|
const maxRetries = options.maxRetries ?? this.maxRetries;
|
|
@@ -477,37 +656,102 @@ export class OpenAI {
|
|
|
477
656
|
retriesRemaining = maxRetries;
|
|
478
657
|
}
|
|
479
658
|
await this.prepareOptions(options);
|
|
480
|
-
const
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
659
|
+
const x509Authentication = __classPrivateFieldGet(this, _OpenAI_x509Authentication, "f");
|
|
660
|
+
x509Authentication?.beginRequestPlanning();
|
|
661
|
+
let built;
|
|
662
|
+
try {
|
|
663
|
+
const candidate = await this.buildRequest(options, {
|
|
664
|
+
retryCount: maxRetries - retriesRemaining,
|
|
665
|
+
});
|
|
666
|
+
built = { req: candidate.req, url: candidate.url, timeout: candidate.timeout };
|
|
667
|
+
if (x509Authentication) {
|
|
668
|
+
validatePositiveInteger('timeout', built.timeout);
|
|
669
|
+
x509Authentication.authorizePlannedRequest(built.url, built.req, built.timeout);
|
|
670
|
+
if (X509WorkloadIdentityAuth.isStreamingRequestBody(built.req.body)) {
|
|
671
|
+
options.__metadata = { ...options.__metadata, hasStreamingBody: true };
|
|
672
|
+
}
|
|
673
|
+
await this.prepareRequest(built.req, { url: built.url, options });
|
|
674
|
+
await this._provider?.prepareRequest?.(built.req, { url: built.url, options });
|
|
675
|
+
x509Authentication.beginRequestPlanning();
|
|
676
|
+
x509Authentication.authorizePlannedRequest(built.url, built.req, built.timeout, true);
|
|
677
|
+
if (X509WorkloadIdentityAuth.isStreamingRequestBody(built.req.body)) {
|
|
678
|
+
options.__metadata = { ...options.__metadata, hasStreamingBody: true };
|
|
679
|
+
}
|
|
680
|
+
const callerSignal = x509Authentication.requestSnapshot().signal;
|
|
681
|
+
if (callerSignal?.aborted || built.req.signal?.aborted) {
|
|
682
|
+
throw this._makeUserAbortError(callerSignal?.aborted ? callerSignal : built.req.signal);
|
|
683
|
+
}
|
|
684
|
+
x509Authentication.setEffectiveSignal(built.req.signal || callerSignal
|
|
685
|
+
? createRequestController(built.req.signal ?? callerSignal, callerSignal).signal
|
|
686
|
+
: undefined);
|
|
687
|
+
x509Authentication.beginRequestNetwork();
|
|
688
|
+
const security = options.__security ?? { bearerAuth: true };
|
|
689
|
+
const authenticationHeaders = await this.authHeaders(options, security);
|
|
690
|
+
const suppliedHeaders = x509Authentication.headerSnapshots();
|
|
691
|
+
const supplied = buildHeaders([suppliedHeaders.defaultHeaders, suppliedHeaders.requestHeaders]);
|
|
692
|
+
for (const [name, value] of authenticationHeaders?.values ?? []) {
|
|
693
|
+
if (!supplied.nulls.has(name) && !built.req.headers.has(name)) {
|
|
694
|
+
built.req.headers.set(name, value);
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
this.validateHeaders(buildHeaders([supplied, built.req.headers]), security);
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
catch (error) {
|
|
701
|
+
x509Authentication?.retireRequestBody();
|
|
702
|
+
if (x509Authentication &&
|
|
703
|
+
retriesRemaining &&
|
|
704
|
+
!options.__metadata?.['hasStreamingBody'] &&
|
|
705
|
+
X509WorkloadIdentityAuth.isRetryableFailure(error)) {
|
|
706
|
+
return await this.retryRequest(options, retriesRemaining, retryOfRequestLogID ?? 'x509-token-exchange', X509WorkloadIdentityAuth.retryHeaders(error));
|
|
707
|
+
}
|
|
708
|
+
throw error;
|
|
709
|
+
}
|
|
710
|
+
const { req, url } = built;
|
|
711
|
+
const timeout = x509Authentication
|
|
712
|
+
? Math.min(built.timeout, x509Authentication.requestSnapshot().timeout)
|
|
713
|
+
: built.timeout;
|
|
714
|
+
x509Authentication?.bindRequest(options, req, this.adminAPIKey);
|
|
715
|
+
let hasStreamingBody = options.__metadata?.['hasStreamingBody'] === true;
|
|
716
|
+
if (!x509Authentication) {
|
|
717
|
+
await this.prepareRequest(req, { url, options });
|
|
718
|
+
await this._provider?.prepareRequest?.(req, { url, options });
|
|
719
|
+
}
|
|
720
|
+
x509Authentication?.adoptRequestHeaders(req);
|
|
721
|
+
if (x509Authentication && X509WorkloadIdentityAuth.isStreamingRequestBody(req.body)) {
|
|
722
|
+
hasStreamingBody = true;
|
|
723
|
+
}
|
|
486
724
|
/** Not an API request ID, just for correlating local log entries. */
|
|
487
725
|
const requestLogID = 'log_' + ((Math.random() * (1 << 24)) | 0).toString(16).padStart(6, '0');
|
|
488
726
|
const retryLogStr = retryOfRequestLogID === undefined ? '' : `, retryOf: ${retryOfRequestLogID}`;
|
|
489
|
-
const startTime = Date.now();
|
|
727
|
+
const startTime = x509Authentication?.requestStartedAt(options) ?? Date.now();
|
|
490
728
|
loggerFor(this).debug(`[${requestLogID}] sending request`, formatRequestDetails({
|
|
491
729
|
retryOfRequestLogID,
|
|
492
730
|
method: options.method,
|
|
493
731
|
url,
|
|
494
|
-
options,
|
|
732
|
+
options: x509Authentication ? { body: req.body, ...x509Authentication.requestSnapshot() } : options,
|
|
495
733
|
headers: req.headers,
|
|
496
734
|
}));
|
|
497
|
-
|
|
498
|
-
|
|
735
|
+
const callerSignal = x509Authentication ? x509Authentication.requestSnapshot().signal : options.signal;
|
|
736
|
+
if (callerSignal?.aborted || req.signal?.aborted) {
|
|
737
|
+
throw this._makeUserAbortError(callerSignal?.aborted ? callerSignal : req.signal);
|
|
499
738
|
}
|
|
500
739
|
const security = options.__security ?? { bearerAuth: true };
|
|
501
740
|
// Request hooks may replace the caller signal before it reaches fetch.
|
|
502
|
-
const controller = this.fetchWithTimeout === _a.prototype.fetchWithTimeout
|
|
503
|
-
? createRequestController(req.signal)
|
|
741
|
+
const controller = x509Authentication || this.fetchWithTimeout === _a.prototype.fetchWithTimeout
|
|
742
|
+
? createRequestController(req.signal ?? (x509Authentication ? callerSignal : undefined), x509Authentication ? callerSignal : undefined)
|
|
504
743
|
: new AbortController();
|
|
505
|
-
const
|
|
744
|
+
const remainingTimeout = x509Authentication?.remainingTimeout(options, timeout) ?? timeout;
|
|
745
|
+
const fetchWithAuth = x509Authentication ? _a.prototype.fetchWithAuth : this.fetchWithAuth;
|
|
746
|
+
x509Authentication?.releaseRequestBody(req.body);
|
|
747
|
+
const response = await fetchWithAuth
|
|
748
|
+
.call(this, url, req, remainingTimeout, controller, security)
|
|
749
|
+
.catch(castToError);
|
|
506
750
|
const headersTime = Date.now();
|
|
507
751
|
if (response instanceof globalThis.Error) {
|
|
508
752
|
const retryMessage = `retrying, ${retriesRemaining} attempts remaining`;
|
|
509
|
-
if (
|
|
510
|
-
throw this._makeUserAbortError(
|
|
753
|
+
if (callerSignal?.aborted || req.signal?.aborted) {
|
|
754
|
+
throw this._makeUserAbortError(callerSignal?.aborted ? callerSignal : req.signal);
|
|
511
755
|
}
|
|
512
756
|
// detect native connection timeout errors
|
|
513
757
|
// deno throws "TypeError: error sending request for url (https://example/): client error (Connect): tcp connect error: Operation timed out (os error 60): Operation timed out (os error 60)"
|
|
@@ -515,13 +759,15 @@ export class OpenAI {
|
|
|
515
759
|
// others do not provide enough information to distinguish timeouts from other connection errors
|
|
516
760
|
const isTimeout = isAbortError(response) ||
|
|
517
761
|
/timed? ?out/i.test(String(response) + ('cause' in response ? String(response.cause) : ''));
|
|
518
|
-
if (retriesRemaining &&
|
|
762
|
+
if (retriesRemaining &&
|
|
763
|
+
!hasStreamingBody &&
|
|
764
|
+
(!x509Authentication || isTransientX509ConnectionError(response))) {
|
|
519
765
|
loggerFor(this).info(`[${requestLogID}] connection ${isTimeout ? 'timed out' : 'failed'} - ${retryMessage}`);
|
|
520
766
|
loggerFor(this).debug(`[${requestLogID}] connection ${isTimeout ? 'timed out' : 'failed'} (${retryMessage})`, formatRequestDetails({
|
|
521
767
|
retryOfRequestLogID,
|
|
522
768
|
url,
|
|
523
769
|
durationMs: headersTime - startTime,
|
|
524
|
-
message: response.message,
|
|
770
|
+
message: x509Authentication ? 'X.509 workload identity API connection failed.' : response.message,
|
|
525
771
|
}));
|
|
526
772
|
return this.retryRequest(options, retriesRemaining, retryOfRequestLogID ?? requestLogID);
|
|
527
773
|
}
|
|
@@ -533,7 +779,7 @@ export class OpenAI {
|
|
|
533
779
|
retryOfRequestLogID,
|
|
534
780
|
url,
|
|
535
781
|
durationMs: headersTime - startTime,
|
|
536
|
-
message: response.message,
|
|
782
|
+
message: x509Authentication ? 'X.509 workload identity API connection failed.' : response.message,
|
|
537
783
|
}));
|
|
538
784
|
if (response instanceof OAuthError || response instanceof SubjectTokenProviderError) {
|
|
539
785
|
throw response;
|
|
@@ -550,8 +796,14 @@ export class OpenAI {
|
|
|
550
796
|
'configure a matching undici fetch and fetchOptions.dispatcher with an Agent whose headersTimeout is at least the SDK timeout.',
|
|
551
797
|
})
|
|
552
798
|
: new Errors.APIConnectionTimeoutError();
|
|
799
|
+
if (x509Authentication) {
|
|
800
|
+
throw new Errors.APIConnectionTimeoutError();
|
|
801
|
+
}
|
|
553
802
|
throw Object.assign(timeoutError, { cause: response });
|
|
554
803
|
}
|
|
804
|
+
if (x509Authentication) {
|
|
805
|
+
throw new Errors.APIConnectionError({ message: 'X.509 workload identity API connection failed.' });
|
|
806
|
+
}
|
|
555
807
|
throw new Errors.APIConnectionError({
|
|
556
808
|
message: getConnectionErrorMessage(response),
|
|
557
809
|
cause: response,
|
|
@@ -563,26 +815,48 @@ export class OpenAI {
|
|
|
563
815
|
.join('');
|
|
564
816
|
const responseInfo = `[${requestLogID}${retryLogStr}${specialHeaders}] ${req.method} ${url} ${response.ok ? 'succeeded' : 'failed'} with status ${response.status} in ${headersTime - startTime}ms`;
|
|
565
817
|
if (!response.ok) {
|
|
818
|
+
const rejectedX509Credential = response.status === 401 &&
|
|
819
|
+
x509Authentication &&
|
|
820
|
+
security.bearerAuth &&
|
|
821
|
+
x509Authentication.usedWorkloadToken(options);
|
|
822
|
+
if (rejectedX509Credential) {
|
|
823
|
+
x509Authentication.invalidateToken();
|
|
824
|
+
}
|
|
566
825
|
if (response.status === 401 &&
|
|
567
|
-
this._workloadIdentityAuth &&
|
|
826
|
+
(x509Authentication || this._workloadIdentityAuth) &&
|
|
568
827
|
security.bearerAuth &&
|
|
569
|
-
!options
|
|
828
|
+
(!x509Authentication || x509Authentication.usedWorkloadToken(options)) &&
|
|
829
|
+
(!x509Authentication || retriesRemaining > 0) &&
|
|
830
|
+
!hasStreamingBody &&
|
|
570
831
|
!options.__metadata?.['workloadIdentityTokenRefreshed']) {
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
832
|
+
if (x509Authentication) {
|
|
833
|
+
void Shims.CancelReadableStream(response.body).catch(() => undefined);
|
|
834
|
+
}
|
|
835
|
+
else {
|
|
836
|
+
await Shims.CancelReadableStream(response.body);
|
|
837
|
+
this._workloadIdentityAuth?.invalidateToken();
|
|
838
|
+
}
|
|
839
|
+
const replayOptions = {
|
|
574
840
|
...options,
|
|
575
841
|
__metadata: {
|
|
576
842
|
...options.__metadata,
|
|
577
843
|
workloadIdentityTokenRefreshed: true,
|
|
578
844
|
},
|
|
579
|
-
}
|
|
845
|
+
};
|
|
846
|
+
return this.makeRequest(replayOptions, x509Authentication ? retriesRemaining - 1 : retriesRemaining, retryOfRequestLogID ?? requestLogID);
|
|
580
847
|
}
|
|
581
|
-
const shouldRetry =
|
|
848
|
+
const shouldRetry = rejectedX509Credential && options.__metadata?.['workloadIdentityTokenRefreshed']
|
|
849
|
+
? false
|
|
850
|
+
: await this.shouldRetry(response);
|
|
582
851
|
if (retriesRemaining && shouldRetry && !hasStreamingBody) {
|
|
583
852
|
const retryMessage = `retrying, ${retriesRemaining} attempts remaining`;
|
|
584
853
|
// We don't need the body of this response.
|
|
585
|
-
|
|
854
|
+
if (x509Authentication) {
|
|
855
|
+
void Shims.CancelReadableStream(response.body).catch(() => undefined);
|
|
856
|
+
}
|
|
857
|
+
else {
|
|
858
|
+
await Shims.CancelReadableStream(response.body);
|
|
859
|
+
}
|
|
586
860
|
loggerFor(this).info(`${responseInfo} - ${retryMessage}`);
|
|
587
861
|
loggerFor(this).debug(`[${requestLogID}] response error (${retryMessage})`, formatRequestDetails({
|
|
588
862
|
retryOfRequestLogID,
|
|
@@ -599,7 +873,9 @@ export class OpenAI {
|
|
|
599
873
|
: `error; no more retries left`
|
|
600
874
|
: `error; not retryable`;
|
|
601
875
|
loggerFor(this).info(`${responseInfo} - ${retryMessage}`);
|
|
602
|
-
const errText =
|
|
876
|
+
const errText = x509Authentication
|
|
877
|
+
? await this.readX509ResponseError(response, options, timeout, controller, x509Authentication)
|
|
878
|
+
: await response.text().catch((err) => castToError(err).message);
|
|
603
879
|
const errJSON = safeJSON(errText);
|
|
604
880
|
const errMessage = errJSON ? undefined : errText;
|
|
605
881
|
loggerFor(this).debug(`[${requestLogID}] response error (${retryMessage})`, formatRequestDetails({
|
|
@@ -621,7 +897,16 @@ export class OpenAI {
|
|
|
621
897
|
headers: response.headers,
|
|
622
898
|
durationMs: headersTime - startTime,
|
|
623
899
|
}));
|
|
624
|
-
|
|
900
|
+
const continueRequest = x509Authentication?.continuation();
|
|
901
|
+
x509Authentication?.releaseRequestCredentials();
|
|
902
|
+
__classPrivateFieldGet(this, _OpenAI_responseAttempts, "f").set(controller, {
|
|
903
|
+
timeout,
|
|
904
|
+
retriesRemaining,
|
|
905
|
+
hasStreamingBody,
|
|
906
|
+
...(x509Authentication ? { authentication: x509Authentication } : {}),
|
|
907
|
+
helperMethod: options.__metadata?.['helperMethod'],
|
|
908
|
+
...(continueRequest ? { continueRequest } : {}),
|
|
909
|
+
});
|
|
625
910
|
return { response, options, controller, requestLogID, retryOfRequestLogID, startTime };
|
|
626
911
|
}
|
|
627
912
|
getAPIList(path, Page, opts) {
|
|
@@ -630,7 +915,10 @@ export class OpenAI {
|
|
|
630
915
|
: { method: 'get', path, ...opts });
|
|
631
916
|
}
|
|
632
917
|
requestAPIList(Page, options) {
|
|
633
|
-
const
|
|
918
|
+
const authentication = __classPrivateFieldGet(this, _OpenAI_x509Authentication, "f") ?? this._workloadIdentityAuth;
|
|
919
|
+
const request = authentication instanceof X509WorkloadIdentityAuth
|
|
920
|
+
? Promise.resolve(options).then((resolved) => authentication.runRequest(() => this.makeRequest(resolved, null, undefined), this))
|
|
921
|
+
: this.makeRequest(options, null, undefined);
|
|
634
922
|
const page = new Pagination.PagePromise(this, request, Page);
|
|
635
923
|
const guarded = this.responsePromise(request, async (client, props) => {
|
|
636
924
|
const body = await this.parseResponseWithTimeout(client, props);
|
|
@@ -647,7 +935,7 @@ export class OpenAI {
|
|
|
647
935
|
bearerAuth: true,
|
|
648
936
|
adminAPIKeyAuth: true,
|
|
649
937
|
}) {
|
|
650
|
-
if (this._workloadIdentityAuth && schemes.bearerAuth) {
|
|
938
|
+
if (this._workloadIdentityAuth && !__classPrivateFieldGet(this, _OpenAI_x509Fetch, "f") && schemes.bearerAuth) {
|
|
651
939
|
const headers = init.headers;
|
|
652
940
|
const authHeader = headers.get('Authorization');
|
|
653
941
|
if (!authHeader || authHeader === `Bearer ${WORKLOAD_IDENTITY_API_KEY_PLACEHOLDER}`) {
|
|
@@ -655,7 +943,8 @@ export class OpenAI {
|
|
|
655
943
|
headers.set('Authorization', `Bearer ${token}`);
|
|
656
944
|
}
|
|
657
945
|
}
|
|
658
|
-
const
|
|
946
|
+
const fetchWithTimeout = __classPrivateFieldGet(this, _OpenAI_x509Fetch, "f") ? _a.prototype.fetchWithTimeout : this.fetchWithTimeout;
|
|
947
|
+
const response = await fetchWithTimeout.call(this, url, init, timeout, controller);
|
|
659
948
|
return response;
|
|
660
949
|
}
|
|
661
950
|
async fetchWithTimeout(url, init, ms, controller) {
|
|
@@ -680,7 +969,7 @@ export class OpenAI {
|
|
|
680
969
|
}
|
|
681
970
|
try {
|
|
682
971
|
// use undefined this binding; fetch errors if bound to something else in browser/cloudflare
|
|
683
|
-
return await this.fetch.call(undefined, url, fetchOptions);
|
|
972
|
+
return await (__classPrivateFieldGet(this, _OpenAI_x509Fetch, "f") ?? this.fetch).call(undefined, url, fetchOptions);
|
|
684
973
|
}
|
|
685
974
|
catch (err) {
|
|
686
975
|
if (signal && !composed)
|
|
@@ -743,7 +1032,19 @@ export class OpenAI {
|
|
|
743
1032
|
const maxRetries = options.maxRetries ?? this.maxRetries;
|
|
744
1033
|
timeoutMillis = this.calculateDefaultRetryTimeoutMillis(retriesRemaining, maxRetries);
|
|
745
1034
|
}
|
|
746
|
-
|
|
1035
|
+
const x509Authentication = __classPrivateFieldGet(this, _OpenAI_x509Authentication, "f");
|
|
1036
|
+
if (x509Authentication) {
|
|
1037
|
+
const remaining = x509Authentication.remainingTimeout(options, x509Authentication.requestSnapshot().timeout);
|
|
1038
|
+
if (timeoutMillis >= remaining) {
|
|
1039
|
+
throw new Errors.APIConnectionTimeoutError();
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
if (x509Authentication) {
|
|
1043
|
+
await x509Authentication.waitForRetry(timeoutMillis, x509Authentication.effectiveSignal());
|
|
1044
|
+
}
|
|
1045
|
+
else {
|
|
1046
|
+
await sleep(timeoutMillis);
|
|
1047
|
+
}
|
|
747
1048
|
return this.makeRequest(options, retriesRemaining - 1, requestLogID);
|
|
748
1049
|
}
|
|
749
1050
|
calculateDefaultRetryTimeoutMillis(retriesRemaining, maxRetries) {
|
|
@@ -757,20 +1058,64 @@ export class OpenAI {
|
|
|
757
1058
|
return sleepSeconds * jitter * 1000;
|
|
758
1059
|
}
|
|
759
1060
|
async buildRequest(inputOptions, { retryCount = 0 } = {}) {
|
|
1061
|
+
if (__classPrivateFieldGet(this, _OpenAI_x509Authentication, "f") && !__classPrivateFieldGet(this, _OpenAI_x509Authentication, "f").inRequest(this)) {
|
|
1062
|
+
const authentication = __classPrivateFieldGet(this, _OpenAI_x509Authentication, "f");
|
|
1063
|
+
return await authentication.runRequest(async () => {
|
|
1064
|
+
const built = await _a.prototype.buildRequest.call(this, inputOptions, { retryCount });
|
|
1065
|
+
authentication.releaseRequestBody(built.req.body);
|
|
1066
|
+
return built;
|
|
1067
|
+
}, this);
|
|
1068
|
+
}
|
|
760
1069
|
const options = { ...inputOptions };
|
|
1070
|
+
const x509Authentication = __classPrivateFieldGet(this, _OpenAI_x509Authentication, "f");
|
|
1071
|
+
const x509Tenant = x509Authentication?.snapshotTenant(this.organization, this.project);
|
|
1072
|
+
const x509Headers = x509Authentication?.snapshotHeaders(this._options.defaultHeaders, options.headers);
|
|
1073
|
+
if (x509Headers) {
|
|
1074
|
+
options.headers = x509Headers.requestHeaders;
|
|
1075
|
+
}
|
|
1076
|
+
const x509ClientFetchOptions = x509Authentication
|
|
1077
|
+
? snapshotX509RequestOptions(this.fetchOptions)
|
|
1078
|
+
: undefined;
|
|
1079
|
+
const x509RequestFetchOptions = x509Authentication
|
|
1080
|
+
? snapshotX509RequestOptions(options.fetchOptions)
|
|
1081
|
+
: undefined;
|
|
761
1082
|
const { method, path, query, defaultBaseURL } = options;
|
|
762
1083
|
const url = this.buildURL(path, query, defaultBaseURL);
|
|
763
|
-
|
|
1084
|
+
x509Authentication?.snapshotAPIURL(url);
|
|
1085
|
+
const explicitTimeout = 'timeout' in options;
|
|
1086
|
+
if (explicitTimeout)
|
|
764
1087
|
validatePositiveInteger('timeout', options.timeout);
|
|
765
1088
|
options.timeout = options.timeout ?? this.timeout;
|
|
1089
|
+
if (x509Authentication && x509RequestFetchOptions) {
|
|
1090
|
+
x509Authentication.snapshotRequest(options.signal, options.timeout, x509RequestFetchOptions);
|
|
1091
|
+
}
|
|
1092
|
+
if (x509Authentication) {
|
|
1093
|
+
const snapshot = x509Authentication.requestSnapshot();
|
|
1094
|
+
options.timeout = snapshot.timeout;
|
|
1095
|
+
if (snapshot.signal === undefined) {
|
|
1096
|
+
delete options.signal;
|
|
1097
|
+
}
|
|
1098
|
+
else {
|
|
1099
|
+
options.signal = snapshot.signal;
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
766
1102
|
const { bodyHeaders, body, isStreamingBody } = this.buildBody({ options });
|
|
767
1103
|
if (isStreamingBody) {
|
|
768
1104
|
inputOptions.__metadata = {
|
|
769
1105
|
...inputOptions.__metadata,
|
|
770
1106
|
hasStreamingBody: true,
|
|
771
1107
|
};
|
|
1108
|
+
x509Authentication?.ownRequestBody(body, options.body);
|
|
772
1109
|
}
|
|
773
|
-
const reqHeaders = await this.buildHeaders({
|
|
1110
|
+
const reqHeaders = await this.buildHeaders({
|
|
1111
|
+
options: inputOptions,
|
|
1112
|
+
method,
|
|
1113
|
+
bodyHeaders,
|
|
1114
|
+
retryCount,
|
|
1115
|
+
x509Headers,
|
|
1116
|
+
x509Timeout: explicitTimeout ? options.timeout : undefined,
|
|
1117
|
+
x509Tenant,
|
|
1118
|
+
});
|
|
774
1119
|
const req = {
|
|
775
1120
|
method,
|
|
776
1121
|
headers: reqHeaders,
|
|
@@ -778,12 +1123,12 @@ export class OpenAI {
|
|
|
778
1123
|
...(globalThis.ReadableStream &&
|
|
779
1124
|
body instanceof globalThis.ReadableStream && { duplex: 'half' }),
|
|
780
1125
|
...(body && { body }),
|
|
781
|
-
...(this.fetchOptions ?? {}),
|
|
782
|
-
...(options.fetchOptions ?? {}),
|
|
1126
|
+
...((x509Authentication ? x509ClientFetchOptions : this.fetchOptions) ?? {}),
|
|
1127
|
+
...((x509Authentication ? x509RequestFetchOptions : options.fetchOptions) ?? {}),
|
|
783
1128
|
};
|
|
784
1129
|
return { req, url, timeout: options.timeout };
|
|
785
1130
|
}
|
|
786
|
-
async buildHeaders({ options, method, bodyHeaders, retryCount, }) {
|
|
1131
|
+
async buildHeaders({ options, method, bodyHeaders, retryCount, x509Headers, x509Timeout, x509Tenant, }) {
|
|
787
1132
|
let idempotencyHeaders = {};
|
|
788
1133
|
if (this.idempotencyHeader && method !== 'get') {
|
|
789
1134
|
if (!options.idempotencyKey)
|
|
@@ -791,26 +1136,27 @@ export class OpenAI {
|
|
|
791
1136
|
idempotencyHeaders[this.idempotencyHeader] = options.idempotencyKey;
|
|
792
1137
|
}
|
|
793
1138
|
const helperMethod = options.__metadata?.['helperMethod'];
|
|
1139
|
+
const timeout = x509Headers ? x509Timeout : options.timeout;
|
|
794
1140
|
const headers = buildHeaders([
|
|
795
1141
|
idempotencyHeaders,
|
|
796
1142
|
{
|
|
797
1143
|
Accept: 'application/json',
|
|
798
1144
|
...(!isRunningInBrowserOrBrowserWorker() ? { 'User-Agent': this.getUserAgent() } : undefined),
|
|
799
1145
|
'X-Stainless-Retry-Count': String(retryCount),
|
|
800
|
-
...(
|
|
1146
|
+
...(timeout ? { 'X-Stainless-Timeout': String(Math.trunc(timeout / 1000)) } : {}),
|
|
801
1147
|
...getPlatformHeaders(),
|
|
802
1148
|
...(typeof helperMethod === 'string' ? { 'X-Stainless-Helper-Method': helperMethod } : {}),
|
|
803
|
-
'OpenAI-Organization': this.organization,
|
|
804
|
-
'OpenAI-Project': this.project,
|
|
1149
|
+
'OpenAI-Organization': x509Tenant ? x509Tenant.organization : this.organization,
|
|
1150
|
+
'OpenAI-Project': x509Tenant ? x509Tenant.project : this.project,
|
|
805
1151
|
},
|
|
806
|
-
this._provider
|
|
1152
|
+
this._provider || __classPrivateFieldGet(this, _OpenAI_x509Authentication, "f")?.isPlanningRequest()
|
|
807
1153
|
? undefined
|
|
808
1154
|
: await this.authHeaders(options, options.__security ?? { bearerAuth: true }),
|
|
809
|
-
this._options.defaultHeaders,
|
|
1155
|
+
x509Headers?.defaultHeaders ?? this._options.defaultHeaders,
|
|
810
1156
|
bodyHeaders,
|
|
811
|
-
options.headers,
|
|
1157
|
+
x509Headers?.requestHeaders ?? options.headers,
|
|
812
1158
|
]);
|
|
813
|
-
if (!this._provider) {
|
|
1159
|
+
if (!this._provider && !__classPrivateFieldGet(this, _OpenAI_x509Authentication, "f")?.isPlanningRequest()) {
|
|
814
1160
|
this.validateHeaders(headers, options.__security ?? { bearerAuth: true });
|
|
815
1161
|
}
|
|
816
1162
|
return headers.values;
|
|
@@ -887,8 +1233,10 @@ export class OpenAI {
|
|
|
887
1233
|
}
|
|
888
1234
|
}
|
|
889
1235
|
}
|
|
890
|
-
_a = OpenAI, _OpenAI_encoder = new WeakMap(), _OpenAI_responseAttempts = new WeakMap(), _OpenAI_instances = new WeakSet(), _OpenAI_baseURLOverridden = function _OpenAI_baseURLOverridden() {
|
|
891
|
-
return this
|
|
1236
|
+
_a = OpenAI, _OpenAI_encoder = new WeakMap(), _OpenAI_x509Authentication = new WeakMap(), _OpenAI_x509Fetch = new WeakMap(), _OpenAI_explicitDataResidency = new WeakMap(), _OpenAI_responseAttempts = new WeakMap(), _OpenAI_instances = new WeakSet(), _OpenAI_baseURLOverridden = function _OpenAI_baseURLOverridden() {
|
|
1237
|
+
return (__classPrivateFieldGet(this, _OpenAI_explicitDataResidency, "f") ||
|
|
1238
|
+
this._provider !== undefined ||
|
|
1239
|
+
this.baseURL !== 'https://api.openai.com/v1');
|
|
892
1240
|
};
|
|
893
1241
|
OpenAI.OpenAI = _a;
|
|
894
1242
|
OpenAI.DEFAULT_TIMEOUT = 600000; // 10 minutes
|
|
@@ -933,7 +1281,7 @@ OpenAI.Containers = Containers;
|
|
|
933
1281
|
OpenAI.Skills = Skills;
|
|
934
1282
|
OpenAI.Videos = Videos;
|
|
935
1283
|
const composedCallerSignals = new WeakMap();
|
|
936
|
-
function createRequestController(callerSignal) {
|
|
1284
|
+
function createRequestController(callerSignal, originalSignal) {
|
|
937
1285
|
const controller = new AbortController();
|
|
938
1286
|
if (!callerSignal)
|
|
939
1287
|
return controller;
|
|
@@ -944,7 +1292,11 @@ function createRequestController(callerSignal) {
|
|
|
944
1292
|
try {
|
|
945
1293
|
// Native composition keeps cancellation active after response headers without
|
|
946
1294
|
// retaining an abort listener on the caller's signal or changing its reason.
|
|
947
|
-
const
|
|
1295
|
+
const signals = [controller.signal, callerSignal];
|
|
1296
|
+
if (originalSignal && originalSignal !== callerSignal) {
|
|
1297
|
+
signals.push(originalSignal);
|
|
1298
|
+
}
|
|
1299
|
+
const composed = nativeAbortSignal.any(signals);
|
|
948
1300
|
Object.defineProperty(controller, 'signal', { value: composed, configurable: true });
|
|
949
1301
|
composedCallerSignals.set(controller, callerSignal);
|
|
950
1302
|
}
|