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