openai 7.7.0 → 7.9.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 +39 -0
- package/README.md +15 -30
- 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/types.d.mts +9 -4
- package/auth/types.d.mts.map +1 -1
- package/auth/types.d.ts +9 -4
- package/auth/types.d.ts.map +1 -1
- package/auth/workload-identity-auth.d.mts +1 -1
- package/auth/workload-identity-auth.d.mts.map +1 -1
- package/auth/workload-identity-auth.d.ts +1 -1
- package/auth/workload-identity-auth.d.ts.map +1 -1
- package/auth/workload-identity-auth.js +23 -6
- package/auth/workload-identity-auth.js.map +1 -1
- package/auth/workload-identity-auth.mjs +23 -6
- package/auth/workload-identity-auth.mjs.map +1 -1
- package/auth/x509-transport.d.mts +36 -1
- package/auth/x509-transport.d.mts.map +1 -1
- package/auth/x509-transport.d.ts +36 -1
- package/auth/x509-transport.d.ts.map +1 -1
- package/auth/x509-transport.js +224 -1
- package/auth/x509-transport.js.map +1 -1
- package/auth/x509-transport.mjs +222 -1
- package/auth/x509-transport.mjs.map +1 -1
- package/azure.d.mts +3 -1
- package/azure.d.mts.map +1 -1
- package/azure.d.ts +3 -1
- package/azure.d.ts.map +1 -1
- package/azure.js.map +1 -1
- package/azure.mjs.map +1 -1
- package/bedrock.d.mts +3 -1
- package/bedrock.d.mts.map +1 -1
- package/bedrock.d.ts +3 -1
- package/bedrock.d.ts.map +1 -1
- package/bedrock.js.map +1 -1
- package/bedrock.mjs.map +1 -1
- package/beta/realtime/ws.d.mts.map +1 -1
- package/beta/realtime/ws.d.ts.map +1 -1
- package/beta/realtime/ws.js +2 -0
- package/beta/realtime/ws.js.map +1 -1
- package/beta/realtime/ws.mjs +2 -0
- package/beta/realtime/ws.mjs.map +1 -1
- package/client.d.mts +3 -1
- package/client.d.mts.map +1 -1
- package/client.d.ts +3 -1
- package/client.d.ts.map +1 -1
- package/client.js +31 -38
- package/client.js.map +1 -1
- package/client.mjs +31 -38
- 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 +14 -1
- package/core/EventEmitter.js.map +1 -1
- package/core/EventEmitter.mjs +14 -1
- package/core/EventEmitter.mjs.map +1 -1
- package/internal/auth/x509-api-origin.d.mts +5 -0
- package/internal/auth/x509-api-origin.d.mts.map +1 -0
- package/internal/auth/x509-api-origin.d.ts +5 -0
- package/internal/auth/x509-api-origin.d.ts.map +1 -0
- package/internal/auth/x509-api-origin.js +28 -0
- package/internal/auth/x509-api-origin.js.map +1 -0
- package/internal/auth/x509-api-origin.mjs +24 -0
- package/internal/auth/x509-api-origin.mjs.map +1 -0
- package/internal/auth/x509-credential-options.d.mts +13 -0
- package/internal/auth/x509-credential-options.d.mts.map +1 -0
- package/internal/auth/x509-credential-options.d.ts +13 -0
- package/internal/auth/x509-credential-options.d.ts.map +1 -0
- package/internal/auth/x509-credential-options.js +122 -0
- package/internal/auth/x509-credential-options.js.map +1 -0
- package/internal/auth/x509-credential-options.mjs +118 -0
- package/internal/auth/x509-credential-options.mjs.map +1 -0
- package/internal/auth/x509-token-exchange.js +1 -1
- package/internal/auth/x509-token-exchange.mjs +1 -1
- package/internal/auth/x509-transport-capability.d.mts +12 -5
- package/internal/auth/x509-transport-capability.d.mts.map +1 -1
- package/internal/auth/x509-transport-capability.d.ts +12 -5
- package/internal/auth/x509-transport-capability.d.ts.map +1 -1
- package/internal/auth/x509-transport-capability.js +6 -5
- package/internal/auth/x509-transport-capability.js.map +1 -1
- package/internal/auth/x509-transport-capability.mjs +6 -5
- package/internal/auth/x509-transport-capability.mjs.map +1 -1
- package/internal/auth/x509-transport-registry.d.mts +8 -0
- package/internal/auth/x509-transport-registry.d.mts.map +1 -1
- package/internal/auth/x509-transport-registry.d.ts +8 -0
- package/internal/auth/x509-transport-registry.d.ts.map +1 -1
- package/internal/auth/x509-transport-registry.js +1 -1
- package/internal/auth/x509-transport-registry.js.map +1 -1
- package/internal/auth/x509-transport-registry.mjs +1 -1
- package/internal/auth/x509-transport-registry.mjs.map +1 -1
- package/internal/auth/x509-transport-state-browser.d.mts +4 -0
- package/internal/auth/x509-transport-state-browser.d.mts.map +1 -1
- package/internal/auth/x509-transport-state-browser.d.ts +4 -0
- package/internal/auth/x509-transport-state-browser.d.ts.map +1 -1
- package/internal/auth/x509-transport-state-browser.js +6 -1
- package/internal/auth/x509-transport-state-browser.js.map +1 -1
- package/internal/auth/x509-transport-state-browser.mjs +5 -0
- package/internal/auth/x509-transport-state-browser.mjs.map +1 -1
- package/internal/auth/x509-transport-state.cjs +6 -1
- package/internal/auth/x509-transport-state.cjs.map +1 -1
- package/internal/auth/x509-transport-state.d.cts +4 -0
- package/internal/auth/x509-transport-state.d.cts.map +1 -1
- package/internal/auth/x509-transport-state.js +36 -0
- package/internal/auth/x509-transport-state.mjs +19 -0
- package/internal/auth/x509-workload-identity-auth.d.mts +2 -4
- package/internal/auth/x509-workload-identity-auth.d.mts.map +1 -1
- package/internal/auth/x509-workload-identity-auth.d.ts +2 -4
- package/internal/auth/x509-workload-identity-auth.d.ts.map +1 -1
- package/internal/auth/x509-workload-identity-auth.js +44 -35
- package/internal/auth/x509-workload-identity-auth.js.map +1 -1
- package/internal/auth/x509-workload-identity-auth.mjs +40 -30
- package/internal/auth/x509-workload-identity-auth.mjs.map +1 -1
- package/internal/uploads.js +4 -2
- package/internal/uploads.js.map +1 -1
- package/internal/uploads.mjs +4 -2
- package/internal/uploads.mjs.map +1 -1
- package/internal/utils/log.d.mts +6 -0
- package/internal/utils/log.d.mts.map +1 -1
- package/internal/utils/log.d.ts +6 -0
- package/internal/utils/log.d.ts.map +1 -1
- package/internal/utils/log.js +72 -11
- package/internal/utils/log.js.map +1 -1
- package/internal/utils/log.mjs +69 -11
- package/internal/utils/log.mjs.map +1 -1
- package/lib/EventEmitter.d.mts.map +1 -1
- package/lib/EventEmitter.d.ts.map +1 -1
- package/lib/EventEmitter.js +14 -1
- package/lib/EventEmitter.js.map +1 -1
- package/lib/EventEmitter.mjs +14 -1
- package/lib/EventEmitter.mjs.map +1 -1
- package/package.json +10 -6
- package/realtime/ws.d.mts.map +1 -1
- package/realtime/ws.d.ts.map +1 -1
- package/realtime/ws.js +2 -0
- package/realtime/ws.js.map +1 -1
- package/realtime/ws.mjs +2 -0
- package/realtime/ws.mjs.map +1 -1
- package/resources/admin/organization/audit-logs.d.mts +2 -2
- package/resources/admin/organization/audit-logs.d.mts.map +1 -1
- package/resources/admin/organization/audit-logs.d.ts +2 -2
- package/resources/admin/organization/audit-logs.d.ts.map +1 -1
- package/resources/admin/organization/usage.d.mts +5 -0
- package/resources/admin/organization/usage.d.mts.map +1 -1
- package/resources/admin/organization/usage.d.ts +5 -0
- package/resources/admin/organization/usage.d.ts.map +1 -1
- package/resources/batches.d.mts +3 -3
- package/resources/batches.d.ts +3 -3
- package/resources/beta/responses/responses.d.mts +11 -23
- package/resources/beta/responses/responses.d.mts.map +1 -1
- package/resources/beta/responses/responses.d.ts +11 -23
- 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/responses/ws.d.mts.map +1 -1
- package/resources/beta/responses/ws.d.ts.map +1 -1
- package/resources/beta/responses/ws.js +3 -0
- package/resources/beta/responses/ws.js.map +1 -1
- package/resources/beta/responses/ws.mjs +3 -0
- package/resources/beta/responses/ws.mjs.map +1 -1
- package/resources/chat/completions/completions.d.mts +4 -4
- package/resources/chat/completions/completions.d.ts +4 -4
- package/resources/evals/evals.d.mts +4 -4
- package/resources/evals/evals.d.ts +4 -4
- package/resources/evals/runs/runs.d.mts +1 -1
- package/resources/evals/runs/runs.d.ts +1 -1
- package/resources/responses/responses.d.mts +13 -19
- package/resources/responses/responses.d.mts.map +1 -1
- package/resources/responses/responses.d.ts +13 -19
- 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/responses/ws.d.mts.map +1 -1
- package/resources/responses/ws.d.ts.map +1 -1
- package/resources/responses/ws.js +3 -0
- package/resources/responses/ws.js.map +1 -1
- package/resources/responses/ws.mjs +3 -0
- package/resources/responses/ws.mjs.map +1 -1
- package/resources/shared.d.mts +0 -2
- package/resources/shared.d.mts.map +1 -1
- package/resources/shared.d.ts +0 -2
- package/resources/shared.d.ts.map +1 -1
- package/src/_vendor/partial-json-parser/LICENSE +21 -0
- package/src/_vendor/partial-json-parser/README.md +11 -1
- package/src/auth/index.ts +1 -0
- package/src/auth/types.ts +10 -4
- package/src/auth/workload-identity-auth.ts +30 -6
- package/src/auth/x509-transport.ts +311 -2
- package/src/azure.ts +4 -1
- package/src/bedrock.ts +4 -1
- package/src/beta/realtime/ws.ts +2 -0
- package/src/client.ts +39 -34
- package/src/core/EventEmitter.ts +13 -1
- package/src/internal/auth/x509-api-origin.ts +27 -0
- package/src/internal/auth/x509-credential-options.ts +146 -0
- package/src/internal/auth/x509-transport-capability.ts +12 -5
- package/src/internal/auth/x509-transport-registry.ts +9 -0
- package/src/internal/auth/x509-transport-state-browser.ts +7 -0
- package/src/internal/auth/x509-transport-state.cts +7 -0
- package/src/internal/auth/x509-workload-identity-auth.ts +42 -33
- package/src/internal/uploads.ts +4 -2
- package/src/internal/utils/log.ts +76 -11
- package/src/lib/EventEmitter.ts +13 -1
- package/src/realtime/ws.ts +2 -0
- package/src/resources/admin/organization/audit-logs.ts +4 -0
- package/src/resources/admin/organization/usage.ts +6 -0
- package/src/resources/batches.ts +3 -3
- package/src/resources/beta/responses/responses.ts +11 -23
- package/src/resources/beta/responses/ws.ts +4 -0
- package/src/resources/chat/completions/completions.ts +4 -4
- package/src/resources/evals/evals.ts +4 -4
- package/src/resources/evals/runs/runs.ts +1 -1
- package/src/resources/responses/responses.ts +13 -19
- package/src/resources/responses/ws.ts +4 -0
- package/src/resources/shared.ts +0 -2
- 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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../src/resources/shared.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,SAAS,GACjB,CAAC,MAAM,GAAG,EAAE,CAAC,GACb,SAAS,GACT,QAAQ,GACR,mBAAmB,GACnB,QAAQ,GACR,mBAAmB,GACnB,kBAAkB,GAClB,6BAA6B,GAC7B,uBAAuB,GACvB,kCAAkC,GAClC,sBAAsB,GACtB,iCAAiC,GACjC,aAAa,GACb,wBAAwB,GACxB,aAAa,GACb,WAAW,GACX,sBAAsB,GACtB,mBAAmB,GACnB,0BAA0B,GAC1B,yBAAyB,GACzB,eAAe,CAAC;AAEpB,MAAM,MAAM,SAAS,GACjB,aAAa,GACb,eAAe,GACf,cAAc,GACd,SAAS,GACT,oBAAoB,GACpB,SAAS,GACT,cAAc,GACd,cAAc,GACd,yBAAyB,GACzB,yBAAyB,GACzB,qBAAqB,GACrB,SAAS,GACT,oBAAoB,GACpB,qBAAqB,GACrB,aAAa,GACb,wBAAwB,GACxB,SAAS,GACT,oBAAoB,GACpB,eAAe,GACf,cAAc,GACd,qBAAqB,GACrB,OAAO,GACP,YAAY,GACZ,YAAY,GACZ,kBAAkB,GAClB,uBAAuB,GACvB,uBAAuB,GACvB,mBAAmB,GACnB,SAAS,GACT,cAAc,GACd,cAAc,GACd,oBAAoB,GACpB,yBAAyB,GACzB,yBAAyB,GACzB,SAAS,GACT,oBAAoB,GACpB,IAAI,GACJ,eAAe,GACf,SAAS,GACT,oBAAoB,GACpB,IAAI,GACJ,eAAe,GACf,YAAY,GACZ,uBAAuB,GACvB,SAAS,GACT,oBAAoB,GACpB,QAAQ,G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AI,EAAE,aAAa,CAAC;CACrB;AAED,yBAAiB,wBAAwB,CAAC;IACxC;;OAEG;IACH,UAAiB,UAAU;QACzB;;;WAGG;QACH,IAAI,EAAE,MAAM,CAAC;QAEb;;;WAGG;QACH,WAAW,CAAC,EAAE,MAAM,CAAC;QAErB;;;WAGG;QACH,MAAM,CAAC,EAAE;YAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;SAAE,CAAC;QAEpC;;;;;;WAMG;QACH,MAAM,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;KACzB;CACF;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;GAGG;AACH,MAAM,WAAW,yBAAyB;IACxC;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,IAAI,EAAE,SAAS,CAAC;CACjB;AAED;;;;GAIG;AACH,MAAM,WAAW,wBAAwB;IACvC;;OAEG;IACH,IAAI,EAAE,QAAQ,CAAC;CAChB;AAED,MAAM,MAAM,cAAc,GACtB,CAAC,MAAM,GAAG,EAAE,CAAC,GACb,SAAS,GACT,QAAQ,GACR,mBAAmB,GACnB,QAAQ,GACR,mBAAmB,GACnB,kBAAkB,GAClB,6BAA6B,GAC7B,uBAAuB,GACvB,kCAAkC,GAClC,sBAAsB,GACtB,iCAAiC,GACjC,aAAa,GACb,wBAAwB,GACxB,aAAa,GACb,WAAW,GACX,sBAAsB,GACtB,mBAAmB,GACnB,0BAA0B,GAC1B,yBAAyB,GACzB,eAAe,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Promplate Dev Team
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -1,3 +1,13 @@
|
|
|
1
1
|
# Partial JSON Parser
|
|
2
2
|
|
|
3
|
-
Vendored from https://www.npmjs.com/package/partial-json
|
|
3
|
+
Vendored from [`partial-json@0.1.7`](https://www.npmjs.com/package/partial-json/v/0.1.7),
|
|
4
|
+
with local modifications for the SDK's streaming parser.
|
|
5
|
+
|
|
6
|
+
- Upstream source: https://github.com/promplate/partial-json-parser-js/tree/b65f82c541f5dd7dc17e0764db78fca6a8d2a159
|
|
7
|
+
- Published tarball SHA-256: `30eafeed6fdc25fb2ca24f34c37796d9f98f0bf5e156452b98a2c356762f6322`
|
|
8
|
+
- Upstream license: MIT; the exact published copyright and license notice are in [`LICENSE`](LICENSE).
|
|
9
|
+
|
|
10
|
+
SDK maintainers own this vendored copy. Updates must review upstream changes,
|
|
11
|
+
preserve local streaming-parser behavior, refresh the exact upstream license,
|
|
12
|
+
record the upstream commit and tarball SHA-256, and verify the license remains in
|
|
13
|
+
the packed SDK.
|
package/src/auth/index.ts
CHANGED
package/src/auth/types.ts
CHANGED
|
@@ -21,7 +21,7 @@ export interface WorkloadIdentity {
|
|
|
21
21
|
/** Provider that obtains the external subject token for each token exchange. */
|
|
22
22
|
provider: SubjectTokenProvider;
|
|
23
23
|
|
|
24
|
-
/** Seconds before expiration when access-token refresh begins; defaults to 1,200 seconds. */
|
|
24
|
+
/** Seconds before expiration when access-token refresh begins; defaults to 1,200 seconds and is capped at half of the actual token lifetime. */
|
|
25
25
|
refreshBufferSeconds?: number;
|
|
26
26
|
}
|
|
27
27
|
|
|
@@ -36,7 +36,10 @@ export interface X509WorkloadIdentity {
|
|
|
36
36
|
/** OpenAI service account authorized for the verified certificate identity. */
|
|
37
37
|
serviceAccountId: string;
|
|
38
38
|
|
|
39
|
-
/**
|
|
39
|
+
/** Seconds before expiration when access-token refresh begins; defaults to 1,200 seconds. */
|
|
40
|
+
refreshBufferSeconds?: number;
|
|
41
|
+
|
|
42
|
+
/** @deprecated Use refreshBufferSeconds to match other workload-identity credentials. */
|
|
40
43
|
refreshBufferMs?: number;
|
|
41
44
|
|
|
42
45
|
/** X.509 federation proves certificate possession instead of supplying a subject token. */
|
|
@@ -44,9 +47,12 @@ export interface X509WorkloadIdentity {
|
|
|
44
47
|
|
|
45
48
|
/** X.509 federation does not send an OAuth client identifier. */
|
|
46
49
|
clientId?: never;
|
|
50
|
+
}
|
|
47
51
|
|
|
48
|
-
|
|
49
|
-
|
|
52
|
+
/** An SDK-owned certificate credential created by the Node-only X.509 authentication helper. */
|
|
53
|
+
export interface X509Credential {
|
|
54
|
+
/** Closes the credential's owned certificate transport after requests have finished. */
|
|
55
|
+
close: () => Promise<void>;
|
|
50
56
|
}
|
|
51
57
|
|
|
52
58
|
/** OAuth token-exchange response returned by the OpenAI workload-identity endpoint. */
|
|
@@ -6,6 +6,7 @@ import { APIError, OAuthError, OpenAIError } from '../core/error';
|
|
|
6
6
|
interface CachedToken {
|
|
7
7
|
token: string;
|
|
8
8
|
expiresAt: number;
|
|
9
|
+
refreshAt: number;
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
const SUBJECT_TOKEN_TYPES: Record<WorkloadIdentity['provider']['tokenType'], string> = {
|
|
@@ -14,6 +15,20 @@ const SUBJECT_TOKEN_TYPES: Record<WorkloadIdentity['provider']['tokenType'], str
|
|
|
14
15
|
};
|
|
15
16
|
|
|
16
17
|
const TOKEN_EXCHANGE_GRANT_TYPE = 'urn:ietf:params:oauth:grant-type:token-exchange';
|
|
18
|
+
// Cap the refresh buffer at half the actual token lifetime, matching the X.509
|
|
19
|
+
// workload-identity path, so short-lived tokens keep a usable cache window.
|
|
20
|
+
const MAX_REFRESH_BUFFER_FRACTION = 0.5;
|
|
21
|
+
|
|
22
|
+
function calculateRefreshAt(
|
|
23
|
+
expiresAt: number,
|
|
24
|
+
now: number,
|
|
25
|
+
refreshBufferSeconds: number | undefined,
|
|
26
|
+
): number {
|
|
27
|
+
const configuredBufferMs = (refreshBufferSeconds ?? 1200) * 1000;
|
|
28
|
+
const effectiveBufferMs = Math.min(configuredBufferMs, (expiresAt - now) * MAX_REFRESH_BUFFER_FRACTION);
|
|
29
|
+
return expiresAt - effectiveBufferMs;
|
|
30
|
+
}
|
|
31
|
+
|
|
17
32
|
const NATIVE_RESPONSE_PROTOTYPE = Response.prototype;
|
|
18
33
|
const READ_NATIVE_RESPONSE_BODY = NATIVE_RESPONSE_PROTOTYPE.arrayBuffer;
|
|
19
34
|
|
|
@@ -133,7 +148,17 @@ export class WorkloadIdentityAuth {
|
|
|
133
148
|
* @param fetch Optional fetch implementation for calls to the OpenAI token endpoint.
|
|
134
149
|
*/
|
|
135
150
|
constructor(config: WorkloadIdentity, fetch?: Fetch) {
|
|
136
|
-
|
|
151
|
+
const { identityProviderId, serviceAccountId, clientId, refreshBufferSeconds, provider } = config;
|
|
152
|
+
this.config = {
|
|
153
|
+
identityProviderId,
|
|
154
|
+
serviceAccountId,
|
|
155
|
+
...(clientId === undefined ? {} : { clientId }),
|
|
156
|
+
...(refreshBufferSeconds === undefined ? {} : { refreshBufferSeconds }),
|
|
157
|
+
provider: {
|
|
158
|
+
tokenType: provider.tokenType,
|
|
159
|
+
getToken: provider.getToken.bind(provider),
|
|
160
|
+
},
|
|
161
|
+
};
|
|
137
162
|
this.fetch = fetch ?? Shims.getDefaultFetch();
|
|
138
163
|
}
|
|
139
164
|
|
|
@@ -165,7 +190,7 @@ export class WorkloadIdentityAuth {
|
|
|
165
190
|
}
|
|
166
191
|
}
|
|
167
192
|
|
|
168
|
-
if (
|
|
193
|
+
if (WorkloadIdentityAuth.needsRefresh(this.cachedToken) && !this.refreshPromise) {
|
|
169
194
|
const refreshPromise = this.refreshToken(this.tokenGeneration).finally(() => {
|
|
170
195
|
if (this.refreshPromise === refreshPromise) {
|
|
171
196
|
this.refreshPromise = null;
|
|
@@ -250,6 +275,7 @@ export class WorkloadIdentityAuth {
|
|
|
250
275
|
this.cachedToken = {
|
|
251
276
|
token: accessToken,
|
|
252
277
|
expiresAt,
|
|
278
|
+
refreshAt: calculateRefreshAt(expiresAt, now, this.config.refreshBufferSeconds),
|
|
253
279
|
};
|
|
254
280
|
}
|
|
255
281
|
|
|
@@ -260,10 +286,8 @@ export class WorkloadIdentityAuth {
|
|
|
260
286
|
return Date.now() >= cachedToken.expiresAt;
|
|
261
287
|
}
|
|
262
288
|
|
|
263
|
-
private needsRefresh(cachedToken: CachedToken): boolean {
|
|
264
|
-
|
|
265
|
-
const bufferMs = bufferSeconds * 1000;
|
|
266
|
-
return Date.now() >= cachedToken.expiresAt - bufferMs;
|
|
289
|
+
private static needsRefresh(cachedToken: CachedToken): boolean {
|
|
290
|
+
return Date.now() >= cachedToken.refreshAt;
|
|
267
291
|
}
|
|
268
292
|
|
|
269
293
|
/** Discards the cached access token so the next request performs a fresh exchange. */
|
|
@@ -1,15 +1,284 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
+
import { createPrivateKey, X509Certificate } from 'node:crypto';
|
|
2
3
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
4
|
+
import { types } from 'node:util';
|
|
5
|
+
import { Agent, ProxyAgent } from 'undici';
|
|
3
6
|
import {
|
|
4
7
|
createX509Transport as createCapability,
|
|
5
8
|
registerX509Transport,
|
|
6
9
|
sendX509Request,
|
|
7
10
|
} from '../internal/auth/x509-transport-capability';
|
|
8
|
-
import type {
|
|
11
|
+
import type {
|
|
12
|
+
X509ProxyMode,
|
|
13
|
+
X509Transport,
|
|
14
|
+
X509TransportOptions,
|
|
15
|
+
} from '../internal/auth/x509-transport-capability';
|
|
9
16
|
import { exchangeX509Token } from '../internal/auth/x509-token-exchange';
|
|
10
17
|
import { isRetryableX509TransportFailure } from '../internal/auth/x509-transport-registry';
|
|
11
18
|
import type { X509RequestScope } from '../internal/auth/x509-transport-registry';
|
|
12
|
-
import { markTransientX509ConnectionError } from '#x509-transport-state';
|
|
19
|
+
import { markTransientX509ConnectionError, rememberX509Credential } from '#x509-transport-state';
|
|
20
|
+
import type { X509Credential, X509WorkloadIdentity } from './types';
|
|
21
|
+
|
|
22
|
+
/** Explicit, separately trusted CONNECT configuration for an SDK-owned X.509 credential. */
|
|
23
|
+
export interface X509CredentialProxyOptions {
|
|
24
|
+
/** CONNECT proxy endpoint; its protocol must match the selected mode. */
|
|
25
|
+
url: string | URL;
|
|
26
|
+
|
|
27
|
+
/** Whether the connection to the CONNECT proxy itself is encrypted. */
|
|
28
|
+
mode: Exclude<X509ProxyMode, 'direct'>;
|
|
29
|
+
|
|
30
|
+
/** Optional private trust roots for the HTTPS proxy; never used for workload TLS. */
|
|
31
|
+
ca?: string | string[] | undefined;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Private certificate material and enrolled selectors for one SDK-owned workload credential. */
|
|
35
|
+
export interface X509CredentialOptions {
|
|
36
|
+
/** Leaf client certificate followed by its required PEM intermediate chain. */
|
|
37
|
+
certificateChain: string;
|
|
38
|
+
|
|
39
|
+
/** PEM private key matching the leaf client certificate. */
|
|
40
|
+
privateKey: string;
|
|
41
|
+
|
|
42
|
+
/** Existing OpenAI identity-provider resource enrolled for the certificate. */
|
|
43
|
+
identityProviderId: string;
|
|
44
|
+
|
|
45
|
+
/** OpenAI service account authorized for the verified certificate identity. */
|
|
46
|
+
serviceAccountId: string;
|
|
47
|
+
|
|
48
|
+
/** Optional private certificate authorities trusted for OpenAI's issuer and API. */
|
|
49
|
+
ca?: string | string[] | undefined;
|
|
50
|
+
|
|
51
|
+
/** Optional passphrase used to decrypt an encrypted PEM private key. */
|
|
52
|
+
passphrase?: string | undefined;
|
|
53
|
+
|
|
54
|
+
/** Optional CONNECT proxy with separately scoped target and proxy TLS settings. */
|
|
55
|
+
proxy?: X509CredentialProxyOptions | undefined;
|
|
56
|
+
|
|
57
|
+
/** Seconds before expiration when access-token refresh begins; defaults to 1,200. */
|
|
58
|
+
refreshBufferSeconds?: number | undefined;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const credentialOptionNames = new Set([
|
|
62
|
+
'certificateChain',
|
|
63
|
+
'privateKey',
|
|
64
|
+
'identityProviderId',
|
|
65
|
+
'serviceAccountId',
|
|
66
|
+
'ca',
|
|
67
|
+
'passphrase',
|
|
68
|
+
'proxy',
|
|
69
|
+
'refreshBufferSeconds',
|
|
70
|
+
]);
|
|
71
|
+
const proxyOptionNames = new Set(['url', 'mode', 'ca']);
|
|
72
|
+
|
|
73
|
+
function safeOptionRecord(
|
|
74
|
+
value: unknown,
|
|
75
|
+
allowed: ReadonlySet<string>,
|
|
76
|
+
label: string,
|
|
77
|
+
): Record<string, unknown> {
|
|
78
|
+
if (!value || typeof value !== 'object' || types.isProxy(value)) {
|
|
79
|
+
throw new Error(`X.509 ${label} options must be a non-proxy object.`);
|
|
80
|
+
}
|
|
81
|
+
const prototype: unknown = Object.getPrototypeOf(value);
|
|
82
|
+
if (prototype !== Object.prototype && prototype !== null) {
|
|
83
|
+
throw new Error(`X.509 ${label} options must have only own plain data properties.`);
|
|
84
|
+
}
|
|
85
|
+
const snapshot = Object.create(null) as Record<string, unknown>;
|
|
86
|
+
for (const name of Reflect.ownKeys(value)) {
|
|
87
|
+
if (typeof name !== 'string' || !allowed.has(name)) {
|
|
88
|
+
throw new Error(`Unsupported X.509 ${label} option: \`${String(name)}\`.`);
|
|
89
|
+
}
|
|
90
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, name);
|
|
91
|
+
if (!descriptor || !('value' in descriptor)) {
|
|
92
|
+
throw new Error(`X.509 ${label} option \`${name}\` must be a plain data property.`);
|
|
93
|
+
}
|
|
94
|
+
snapshot[name] = descriptor.value;
|
|
95
|
+
}
|
|
96
|
+
return snapshot;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function requiredCredentialValue(options: Record<string, unknown>, name: string): string {
|
|
100
|
+
const value = options[name];
|
|
101
|
+
if (typeof value !== 'string' || value.trim().length === 0) {
|
|
102
|
+
throw new Error(`X.509 credential requires a nonempty own \`${name}\` value.`);
|
|
103
|
+
}
|
|
104
|
+
return value;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function snapshotCertificateAuthorities(value: unknown): string | string[] | undefined {
|
|
108
|
+
if (value === undefined) {
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
if (typeof value === 'string') {
|
|
112
|
+
if (value.trim().length === 0) {
|
|
113
|
+
throw new Error('X.509 certificate authorities must contain nonempty PEM values.');
|
|
114
|
+
}
|
|
115
|
+
return value;
|
|
116
|
+
}
|
|
117
|
+
if (!Array.isArray(value) || types.isProxy(value) || value.length === 0) {
|
|
118
|
+
throw new Error('X.509 certificate authorities must be a PEM string or plain PEM string array.');
|
|
119
|
+
}
|
|
120
|
+
const authorities: string[] = [];
|
|
121
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
122
|
+
const entry = Object.getOwnPropertyDescriptor(value, String(index));
|
|
123
|
+
if (!entry || !('value' in entry) || typeof entry.value !== 'string' || entry.value.trim().length === 0) {
|
|
124
|
+
throw new Error('X.509 certificate authorities require own plain nonempty PEM strings.');
|
|
125
|
+
}
|
|
126
|
+
authorities.push(entry.value);
|
|
127
|
+
}
|
|
128
|
+
return authorities;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
class OwnedX509Credential implements X509Credential {
|
|
132
|
+
readonly #dispatcher: Agent | ProxyAgent;
|
|
133
|
+
#closing: Promise<void> | undefined;
|
|
134
|
+
|
|
135
|
+
constructor(dispatcher: Agent | ProxyAgent) {
|
|
136
|
+
this.#dispatcher = dispatcher;
|
|
137
|
+
Object.freeze(this);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** Closes this credential's owned transport once all in-flight requests have drained. */
|
|
141
|
+
close(): Promise<void> {
|
|
142
|
+
this.#closing ??= this.#dispatcher.close();
|
|
143
|
+
return this.#closing;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
interface ValidatedX509CredentialOptions {
|
|
148
|
+
certificateChain: string;
|
|
149
|
+
privateKey: string;
|
|
150
|
+
identityProviderId: string;
|
|
151
|
+
serviceAccountId: string;
|
|
152
|
+
refreshBufferSeconds: number | undefined;
|
|
153
|
+
passphrase: string | undefined;
|
|
154
|
+
ca: string | string[] | undefined;
|
|
155
|
+
proxy: unknown;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function validatedCredentialOptions(options: X509CredentialOptions): ValidatedX509CredentialOptions {
|
|
159
|
+
const configured = safeOptionRecord(options, credentialOptionNames, 'credential');
|
|
160
|
+
const certificateChain = requiredCredentialValue(configured, 'certificateChain');
|
|
161
|
+
const privateKeyPEM = requiredCredentialValue(configured, 'privateKey');
|
|
162
|
+
const identityProviderId = requiredCredentialValue(configured, 'identityProviderId');
|
|
163
|
+
const serviceAccountId = requiredCredentialValue(configured, 'serviceAccountId');
|
|
164
|
+
const { refreshBufferSeconds, passphrase } = configured;
|
|
165
|
+
if (passphrase !== undefined && typeof passphrase !== 'string') {
|
|
166
|
+
throw new Error('X.509 credential requires a string private-key passphrase.');
|
|
167
|
+
}
|
|
168
|
+
if (
|
|
169
|
+
refreshBufferSeconds !== undefined &&
|
|
170
|
+
(typeof refreshBufferSeconds !== 'number' ||
|
|
171
|
+
!Number.isSafeInteger(refreshBufferSeconds) ||
|
|
172
|
+
refreshBufferSeconds < 0 ||
|
|
173
|
+
!Number.isSafeInteger(refreshBufferSeconds * 1000))
|
|
174
|
+
) {
|
|
175
|
+
throw new Error('X.509 credential requires a nonnegative integer refreshBufferSeconds.');
|
|
176
|
+
}
|
|
177
|
+
const ca = snapshotCertificateAuthorities(configured['ca']);
|
|
178
|
+
|
|
179
|
+
const leaf = new X509Certificate(certificateChain);
|
|
180
|
+
const privateKey = createPrivateKey({
|
|
181
|
+
key: privateKeyPEM,
|
|
182
|
+
...(passphrase === undefined ? {} : { passphrase }),
|
|
183
|
+
});
|
|
184
|
+
if (!leaf.checkPrivateKey(privateKey)) {
|
|
185
|
+
throw new Error('X.509 credential private key must match its leaf client certificate.');
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return {
|
|
189
|
+
certificateChain,
|
|
190
|
+
privateKey: privateKeyPEM,
|
|
191
|
+
identityProviderId,
|
|
192
|
+
serviceAccountId,
|
|
193
|
+
refreshBufferSeconds,
|
|
194
|
+
passphrase,
|
|
195
|
+
ca,
|
|
196
|
+
proxy: configured['proxy'],
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
interface VerifiedX509TLSOptions {
|
|
201
|
+
cert: string;
|
|
202
|
+
key: string;
|
|
203
|
+
rejectUnauthorized: true;
|
|
204
|
+
passphrase?: string;
|
|
205
|
+
ca?: string | string[];
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function proxyAuthentication(url: URL): string | undefined {
|
|
209
|
+
if (url.username === '' && url.password === '') {
|
|
210
|
+
return undefined;
|
|
211
|
+
}
|
|
212
|
+
let username: string;
|
|
213
|
+
let password: string;
|
|
214
|
+
try {
|
|
215
|
+
username = decodeURIComponent(url.username);
|
|
216
|
+
password = decodeURIComponent(url.password);
|
|
217
|
+
} catch {
|
|
218
|
+
throw new Error('X.509 CONNECT proxy credentials contain invalid URL encoding.');
|
|
219
|
+
}
|
|
220
|
+
if (username.includes(':')) {
|
|
221
|
+
throw new Error('X.509 CONNECT proxy username cannot contain a colon.');
|
|
222
|
+
}
|
|
223
|
+
return Buffer.from(`${username}:${password}`, 'utf-8').toString('base64');
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function normalizeProxyURL(value: unknown): URL {
|
|
227
|
+
if (typeof value !== 'string' && (typeof value !== 'object' || value === null || types.isProxy(value))) {
|
|
228
|
+
throw new Error('X.509 CONNECT proxy requires an own URL string or URL value.');
|
|
229
|
+
}
|
|
230
|
+
try {
|
|
231
|
+
return new URL(typeof value === 'string' ? value : URL.prototype.toString.call(value));
|
|
232
|
+
} catch {
|
|
233
|
+
throw new Error('X.509 CONNECT proxy requires a valid proxy URL.');
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function credentialDispatcher(
|
|
238
|
+
proxyOptionsInput: unknown,
|
|
239
|
+
requestTls: VerifiedX509TLSOptions,
|
|
240
|
+
): { dispatcher: Agent | ProxyAgent; proxy: X509ProxyMode } {
|
|
241
|
+
if (proxyOptionsInput === undefined) {
|
|
242
|
+
return { dispatcher: new Agent({ connect: requestTls }), proxy: 'direct' };
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const proxyOptions = safeOptionRecord(proxyOptionsInput, proxyOptionNames, 'proxy');
|
|
246
|
+
const url = normalizeProxyURL(proxyOptions['url']);
|
|
247
|
+
const selected = proxyOptions['mode'];
|
|
248
|
+
const proxy: X509ProxyMode =
|
|
249
|
+
selected === 'http-connect' || selected === 'https-connect' ? selected : 'direct';
|
|
250
|
+
if (
|
|
251
|
+
(proxy !== 'http-connect' && proxy !== 'https-connect') ||
|
|
252
|
+
url.protocol !== (proxy === 'https-connect' ? 'https:' : 'http:') ||
|
|
253
|
+
url.pathname !== '/' ||
|
|
254
|
+
url.search ||
|
|
255
|
+
url.hash
|
|
256
|
+
) {
|
|
257
|
+
throw new Error('X.509 CONNECT proxy URL protocol must match its selected secure proxy mode.');
|
|
258
|
+
}
|
|
259
|
+
const proxyCA = snapshotCertificateAuthorities(proxyOptions['ca']);
|
|
260
|
+
if (proxy === 'http-connect' && proxyCA !== undefined) {
|
|
261
|
+
throw new Error('A plaintext X.509 CONNECT proxy cannot configure proxy TLS authorities.');
|
|
262
|
+
}
|
|
263
|
+
const auth = proxyAuthentication(url);
|
|
264
|
+
|
|
265
|
+
return {
|
|
266
|
+
proxy,
|
|
267
|
+
dispatcher: new ProxyAgent({
|
|
268
|
+
uri: url.href,
|
|
269
|
+
...(auth === undefined ? {} : { auth }),
|
|
270
|
+
requestTls,
|
|
271
|
+
...(proxy === 'https-connect'
|
|
272
|
+
? {
|
|
273
|
+
proxyTls: {
|
|
274
|
+
rejectUnauthorized: true,
|
|
275
|
+
...(proxyCA === undefined ? {} : { ca: proxyCA }),
|
|
276
|
+
},
|
|
277
|
+
}
|
|
278
|
+
: {}),
|
|
279
|
+
}),
|
|
280
|
+
};
|
|
281
|
+
}
|
|
13
282
|
|
|
14
283
|
/** Creates one frozen, caller-attested Node.js transport for X.509 workload authentication. */
|
|
15
284
|
export function createX509Transport(options: X509TransportOptions): X509Transport {
|
|
@@ -42,6 +311,46 @@ export function createX509Transport(options: X509TransportOptions): X509Transpor
|
|
|
42
311
|
return capability;
|
|
43
312
|
}
|
|
44
313
|
|
|
314
|
+
/** Creates a first-class certificate credential with SDK-owned, verified TLS and CONNECT policy. */
|
|
315
|
+
export function fromX509(options: X509CredentialOptions): X509Credential {
|
|
316
|
+
const configured = validatedCredentialOptions(options);
|
|
317
|
+
|
|
318
|
+
const requestTls = {
|
|
319
|
+
cert: configured.certificateChain,
|
|
320
|
+
key: configured.privateKey,
|
|
321
|
+
rejectUnauthorized: true as const,
|
|
322
|
+
...(configured.passphrase === undefined ? {} : { passphrase: configured.passphrase }),
|
|
323
|
+
...(configured.ca === undefined ? {} : { ca: configured.ca }),
|
|
324
|
+
};
|
|
325
|
+
const { dispatcher, proxy } = credentialDispatcher(configured.proxy, requestTls);
|
|
326
|
+
|
|
327
|
+
try {
|
|
328
|
+
const transport = createX509Transport({
|
|
329
|
+
runtime: 'node',
|
|
330
|
+
dispatcher,
|
|
331
|
+
certificateIdentity: 'static',
|
|
332
|
+
proxy,
|
|
333
|
+
});
|
|
334
|
+
const identity: X509WorkloadIdentity = Object.freeze({
|
|
335
|
+
type: 'x509',
|
|
336
|
+
identityProviderId: configured.identityProviderId,
|
|
337
|
+
serviceAccountId: configured.serviceAccountId,
|
|
338
|
+
...(configured.refreshBufferSeconds === undefined
|
|
339
|
+
? {}
|
|
340
|
+
: { refreshBufferSeconds: configured.refreshBufferSeconds }),
|
|
341
|
+
});
|
|
342
|
+
const credential = new OwnedX509Credential(dispatcher);
|
|
343
|
+
rememberX509Credential(credential, Object.freeze({ identity, transport }));
|
|
344
|
+
return credential;
|
|
345
|
+
} catch (error) {
|
|
346
|
+
void dispatcher.close();
|
|
347
|
+
throw error;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/** Namespaced first-class credential factory, isolated from ordinary browser-safe auth imports. */
|
|
352
|
+
export const workloadIdentity = Object.freeze({ fromX509 });
|
|
353
|
+
|
|
45
354
|
export type {
|
|
46
355
|
X509ProxyMode,
|
|
47
356
|
X509Transport,
|
package/src/azure.ts
CHANGED
|
@@ -13,7 +13,7 @@ import { assertNoDataResidency } from './internal/data-residency';
|
|
|
13
13
|
/** API Client for interfacing with the Azure OpenAI API. */
|
|
14
14
|
export interface AzureClientOptions extends Omit<
|
|
15
15
|
ClientOptions,
|
|
16
|
-
'provider' | 'dataResidency' | 'workloadIdentity' | 'x509Transport'
|
|
16
|
+
'provider' | 'dataResidency' | 'credential' | 'workloadIdentity' | 'x509Transport'
|
|
17
17
|
> {
|
|
18
18
|
/** AzureOpenAI does not support third-party provider configuration. */
|
|
19
19
|
provider?: never;
|
|
@@ -21,6 +21,9 @@ export interface AzureClientOptions extends Omit<
|
|
|
21
21
|
/** OpenAI data residency cannot be combined with Azure routing. */
|
|
22
22
|
dataResidency?: never;
|
|
23
23
|
|
|
24
|
+
/** Azure cannot receive an SDK-owned OpenAI X.509 certificate credential. */
|
|
25
|
+
credential?: never;
|
|
26
|
+
|
|
24
27
|
/** Azure cannot receive OpenAI X.509 workload-identity certificate transports. */
|
|
25
28
|
x509Transport?: never;
|
|
26
29
|
|
package/src/bedrock.ts
CHANGED
|
@@ -20,7 +20,7 @@ import type * as ResponsesAPI from './resources/responses/responses';
|
|
|
20
20
|
/** Configures Amazon Bedrock's OpenAI-compatible endpoint and bearer-token authentication. */
|
|
21
21
|
export interface BedrockClientOptions extends Omit<
|
|
22
22
|
ClientOptions,
|
|
23
|
-
'apiKey' | 'adminAPIKey' | 'baseURL' | 'workloadIdentity' | 'x509Transport' | 'dataResidency'
|
|
23
|
+
'apiKey' | 'adminAPIKey' | 'baseURL' | 'credential' | 'workloadIdentity' | 'x509Transport' | 'dataResidency'
|
|
24
24
|
> {
|
|
25
25
|
/**
|
|
26
26
|
* Bedrock bearer token used for authentication.
|
|
@@ -46,6 +46,9 @@ export interface BedrockClientOptions extends Omit<
|
|
|
46
46
|
/** OpenAI data residency cannot be combined with Bedrock routing. */
|
|
47
47
|
dataResidency?: never;
|
|
48
48
|
|
|
49
|
+
/** Bedrock cannot receive an SDK-owned OpenAI X.509 certificate credential. */
|
|
50
|
+
credential?: never;
|
|
51
|
+
|
|
49
52
|
/**
|
|
50
53
|
* BedrockOpenAI only supports Bedrock bearer token authentication.
|
|
51
54
|
*/
|
package/src/beta/realtime/ws.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { assertBedrockWebSocketOrigin } from '../../internal/bedrock';
|
|
|
3
3
|
import { protectWebSocketOptionsFromCredentialRedirects } from '../../internal/ws';
|
|
4
4
|
import type { AzureOpenAI } from '../../index';
|
|
5
5
|
import { OpenAI } from '../../index';
|
|
6
|
+
import { VERSION } from '../../version';
|
|
6
7
|
import type { RealtimeClientEvent } from '../../resources/beta/realtime/realtime';
|
|
7
8
|
import { OpenAIRealtimeEmitter, buildRealtimeURL, isAzure, parseRealtimeEvent } from './internal-base';
|
|
8
9
|
import type { RealtimeConnectionConfig } from './internal-base';
|
|
@@ -68,6 +69,7 @@ export class OpenAIRealtimeWS extends OpenAIRealtimeEmitter {
|
|
|
68
69
|
assertTrustedRealtimeURL(client, this.url);
|
|
69
70
|
assertBedrockWebSocketOrigin(client, this.url);
|
|
70
71
|
const headers = {
|
|
72
|
+
'User-Agent': `${client.constructor.name}/JS ${VERSION}`,
|
|
71
73
|
...props.options?.headers,
|
|
72
74
|
...(isAzure(client) && !props.__resolvedApiKey ? {} : { Authorization: `Bearer ${client.apiKey}` }),
|
|
73
75
|
'OpenAI-Beta': 'realtime=v1',
|