openai 6.43.0 → 6.45.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 +56 -0
- package/README.md +85 -102
- package/_vendor/zod-to-json-schema/parseDef.d.mts.map +1 -1
- package/_vendor/zod-to-json-schema/parseDef.d.ts.map +1 -1
- package/_vendor/zod-to-json-schema/parseDef.js +41 -15
- package/_vendor/zod-to-json-schema/parseDef.js.map +1 -1
- package/_vendor/zod-to-json-schema/parseDef.mjs +41 -15
- package/_vendor/zod-to-json-schema/parseDef.mjs.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/branded.d.mts +1 -1
- package/_vendor/zod-to-json-schema/parsers/branded.d.mts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/branded.d.ts +1 -1
- package/_vendor/zod-to-json-schema/parsers/branded.d.ts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/branded.js +2 -2
- package/_vendor/zod-to-json-schema/parsers/branded.js.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/branded.mjs +2 -2
- package/_vendor/zod-to-json-schema/parsers/branded.mjs.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/catch.d.mts +1 -1
- package/_vendor/zod-to-json-schema/parsers/catch.d.mts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/catch.d.ts +1 -1
- package/_vendor/zod-to-json-schema/parsers/catch.d.ts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/catch.js +2 -2
- package/_vendor/zod-to-json-schema/parsers/catch.js.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/catch.mjs +2 -2
- package/_vendor/zod-to-json-schema/parsers/catch.mjs.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/default.d.mts +1 -1
- package/_vendor/zod-to-json-schema/parsers/default.d.mts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/default.d.ts +1 -1
- package/_vendor/zod-to-json-schema/parsers/default.d.ts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/default.js +2 -2
- package/_vendor/zod-to-json-schema/parsers/default.js.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/default.mjs +2 -2
- package/_vendor/zod-to-json-schema/parsers/default.mjs.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/nullable.d.mts +1 -1
- package/_vendor/zod-to-json-schema/parsers/nullable.d.mts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/nullable.d.ts +1 -1
- package/_vendor/zod-to-json-schema/parsers/nullable.d.ts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/nullable.js +2 -2
- package/_vendor/zod-to-json-schema/parsers/nullable.js.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/nullable.mjs +2 -2
- package/_vendor/zod-to-json-schema/parsers/nullable.mjs.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/optional.d.mts +1 -1
- package/_vendor/zod-to-json-schema/parsers/optional.d.mts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/optional.d.ts +1 -1
- package/_vendor/zod-to-json-schema/parsers/optional.d.ts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/optional.js +3 -3
- package/_vendor/zod-to-json-schema/parsers/optional.js.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/optional.mjs +3 -3
- package/_vendor/zod-to-json-schema/parsers/optional.mjs.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/pipeline.d.mts +1 -1
- package/_vendor/zod-to-json-schema/parsers/pipeline.d.mts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/pipeline.d.ts +1 -1
- package/_vendor/zod-to-json-schema/parsers/pipeline.d.ts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/pipeline.js +3 -3
- package/_vendor/zod-to-json-schema/parsers/pipeline.js.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/pipeline.mjs +3 -3
- package/_vendor/zod-to-json-schema/parsers/pipeline.mjs.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/promise.d.mts +1 -1
- package/_vendor/zod-to-json-schema/parsers/promise.d.mts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/promise.d.ts +1 -1
- package/_vendor/zod-to-json-schema/parsers/promise.d.ts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/promise.js +2 -2
- package/_vendor/zod-to-json-schema/parsers/promise.js.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/promise.mjs +2 -2
- package/_vendor/zod-to-json-schema/parsers/promise.mjs.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/readonly.d.mts +1 -1
- package/_vendor/zod-to-json-schema/parsers/readonly.d.mts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/readonly.d.ts +1 -1
- package/_vendor/zod-to-json-schema/parsers/readonly.d.ts.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/readonly.js +2 -2
- package/_vendor/zod-to-json-schema/parsers/readonly.js.map +1 -1
- package/_vendor/zod-to-json-schema/parsers/readonly.mjs +2 -2
- package/_vendor/zod-to-json-schema/parsers/readonly.mjs.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 +12 -4
- package/auth/workload-identity-auth.js.map +1 -1
- package/auth/workload-identity-auth.mjs +13 -5
- package/auth/workload-identity-auth.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/beta/realtime/internal-base.d.mts +14 -1
- package/beta/realtime/internal-base.d.mts.map +1 -1
- package/beta/realtime/internal-base.d.ts +14 -1
- package/beta/realtime/internal-base.d.ts.map +1 -1
- package/beta/realtime/internal-base.js +21 -5
- package/beta/realtime/internal-base.js.map +1 -1
- package/beta/realtime/internal-base.mjs +21 -5
- package/beta/realtime/internal-base.mjs.map +1 -1
- package/beta/realtime/websocket.d.mts +3 -5
- package/beta/realtime/websocket.d.mts.map +1 -1
- package/beta/realtime/websocket.d.ts +3 -5
- package/beta/realtime/websocket.d.ts.map +1 -1
- package/beta/realtime/websocket.js +2 -3
- package/beta/realtime/websocket.js.map +1 -1
- package/beta/realtime/websocket.mjs +3 -4
- package/beta/realtime/websocket.mjs.map +1 -1
- package/beta/realtime/ws.d.mts +3 -5
- package/beta/realtime/ws.d.mts.map +1 -1
- package/beta/realtime/ws.d.ts +3 -5
- package/beta/realtime/ws.d.ts.map +1 -1
- package/beta/realtime/ws.js +2 -3
- package/beta/realtime/ws.js.map +1 -1
- package/beta/realtime/ws.mjs +3 -4
- package/beta/realtime/ws.mjs.map +1 -1
- package/client.d.mts +9 -1
- package/client.d.mts.map +1 -1
- package/client.d.ts +9 -1
- package/client.d.ts.map +1 -1
- package/client.js +56 -9
- package/client.js.map +1 -1
- package/client.mjs +56 -9
- package/client.mjs.map +1 -1
- package/helpers/zod.d.mts.map +1 -1
- package/helpers/zod.d.ts.map +1 -1
- package/helpers/zod.js +12 -0
- package/helpers/zod.js.map +1 -1
- package/helpers/zod.mjs +12 -0
- package/helpers/zod.mjs.map +1 -1
- package/internal/bedrock.d.mts +34 -0
- package/internal/bedrock.d.mts.map +1 -0
- package/internal/bedrock.d.ts +34 -0
- package/internal/bedrock.d.ts.map +1 -0
- package/internal/bedrock.js +107 -0
- package/internal/bedrock.js.map +1 -0
- package/internal/bedrock.mjs +99 -0
- package/internal/bedrock.mjs.map +1 -0
- package/internal/provider.d.mts +23 -0
- package/internal/provider.d.mts.map +1 -0
- package/internal/provider.d.ts +23 -0
- package/internal/provider.d.ts.map +1 -0
- package/internal/provider.js +36 -0
- package/internal/provider.js.map +1 -0
- package/internal/provider.mjs +32 -0
- package/internal/provider.mjs.map +1 -0
- package/internal/utils/log.d.mts.map +1 -1
- package/internal/utils/log.d.ts.map +1 -1
- package/internal/utils/log.js +1 -0
- package/internal/utils/log.js.map +1 -1
- package/internal/utils/log.mjs +1 -0
- package/internal/utils/log.mjs.map +1 -1
- package/lib/AbstractChatCompletionRunner.d.mts +15 -4
- package/lib/AbstractChatCompletionRunner.d.mts.map +1 -1
- package/lib/AbstractChatCompletionRunner.d.ts +15 -4
- package/lib/AbstractChatCompletionRunner.d.ts.map +1 -1
- package/lib/AbstractChatCompletionRunner.js +63 -40
- package/lib/AbstractChatCompletionRunner.js.map +1 -1
- package/lib/AbstractChatCompletionRunner.mjs +63 -40
- 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 +4 -24
- package/lib/AssistantStream.js.map +1 -1
- package/lib/AssistantStream.mjs +4 -24
- package/lib/AssistantStream.mjs.map +1 -1
- package/lib/ChatCompletionRunner.js +1 -1
- package/lib/ChatCompletionRunner.js.map +1 -1
- package/lib/ChatCompletionRunner.mjs +1 -1
- package/lib/ChatCompletionRunner.mjs.map +1 -1
- package/lib/ChatCompletionStream.d.mts.map +1 -1
- package/lib/ChatCompletionStream.d.ts.map +1 -1
- package/lib/ChatCompletionStream.js +4 -13
- package/lib/ChatCompletionStream.js.map +1 -1
- package/lib/ChatCompletionStream.mjs +4 -13
- package/lib/ChatCompletionStream.mjs.map +1 -1
- package/lib/ChatCompletionStreamingRunner.js +1 -1
- package/lib/ChatCompletionStreamingRunner.js.map +1 -1
- package/lib/ChatCompletionStreamingRunner.mjs +1 -1
- package/lib/ChatCompletionStreamingRunner.mjs.map +1 -1
- package/lib/EventEmitter.d.mts.map +1 -1
- package/lib/EventEmitter.d.ts.map +1 -1
- package/lib/EventEmitter.js +12 -2
- package/lib/EventEmitter.js.map +1 -1
- package/lib/EventEmitter.mjs +12 -2
- package/lib/EventEmitter.mjs.map +1 -1
- package/lib/EventStream.d.mts +1 -0
- package/lib/EventStream.d.mts.map +1 -1
- package/lib/EventStream.d.ts +1 -0
- package/lib/EventStream.d.ts.map +1 -1
- package/lib/EventStream.js +19 -2
- package/lib/EventStream.js.map +1 -1
- package/lib/EventStream.mjs +19 -2
- 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 +12 -4
- package/lib/ResponsesParser.js.map +1 -1
- package/lib/ResponsesParser.mjs +12 -4
- package/lib/ResponsesParser.mjs.map +1 -1
- package/lib/responses/ResponseAccumulator.d.mts +10 -0
- package/lib/responses/ResponseAccumulator.d.mts.map +1 -0
- package/lib/responses/ResponseAccumulator.d.ts +10 -0
- package/lib/responses/ResponseAccumulator.d.ts.map +1 -0
- package/lib/responses/ResponseAccumulator.js +402 -0
- package/lib/responses/ResponseAccumulator.js.map +1 -0
- package/lib/responses/ResponseAccumulator.mjs +399 -0
- package/lib/responses/ResponseAccumulator.mjs.map +1 -0
- package/lib/responses/ResponseInputItems.d.mts +19 -0
- package/lib/responses/ResponseInputItems.d.mts.map +1 -0
- package/lib/responses/ResponseInputItems.d.ts +19 -0
- package/lib/responses/ResponseInputItems.d.ts.map +1 -0
- package/lib/responses/ResponseInputItems.js +102 -0
- package/lib/responses/ResponseInputItems.js.map +1 -0
- package/lib/responses/ResponseInputItems.mjs +98 -0
- package/lib/responses/ResponseInputItems.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 +5 -90
- package/lib/responses/ResponseStream.js.map +1 -1
- package/lib/responses/ResponseStream.mjs +5 -90
- package/lib/responses/ResponseStream.mjs.map +1 -1
- package/package.json +24 -1
- package/providers/bedrock/aws.d.mts +24 -0
- package/providers/bedrock/aws.d.mts.map +1 -0
- package/providers/bedrock/aws.d.ts +24 -0
- package/providers/bedrock/aws.d.ts.map +1 -0
- package/providers/bedrock/aws.js +170 -0
- package/providers/bedrock/aws.js.map +1 -0
- package/providers/bedrock/aws.mjs +166 -0
- package/providers/bedrock/aws.mjs.map +1 -0
- package/providers/bedrock.d.mts +7 -0
- package/providers/bedrock.d.mts.map +1 -0
- package/providers/bedrock.d.ts +7 -0
- package/providers/bedrock.d.ts.map +1 -0
- package/providers/bedrock.js +26 -0
- package/providers/bedrock.js.map +1 -0
- package/providers/bedrock.mjs +22 -0
- package/providers/bedrock.mjs.map +1 -0
- package/realtime/internal-base.d.mts +28 -1
- package/realtime/internal-base.d.mts.map +1 -1
- package/realtime/internal-base.d.ts +28 -1
- package/realtime/internal-base.d.ts.map +1 -1
- package/realtime/internal-base.js +50 -7
- package/realtime/internal-base.js.map +1 -1
- package/realtime/internal-base.mjs +49 -7
- package/realtime/internal-base.mjs.map +1 -1
- package/realtime/websocket.d.mts +4 -7
- package/realtime/websocket.d.mts.map +1 -1
- package/realtime/websocket.d.ts +4 -7
- package/realtime/websocket.d.ts.map +1 -1
- package/realtime/websocket.js +4 -8
- package/realtime/websocket.js.map +1 -1
- package/realtime/websocket.mjs +5 -9
- package/realtime/websocket.mjs.map +1 -1
- package/realtime/ws.d.mts +4 -7
- package/realtime/ws.d.mts.map +1 -1
- package/realtime/ws.d.ts +4 -7
- package/realtime/ws.d.ts.map +1 -1
- package/realtime/ws.js +4 -8
- package/realtime/ws.js.map +1 -1
- package/realtime/ws.mjs +5 -9
- package/realtime/ws.mjs.map +1 -1
- package/resources/realtime/client-secrets.d.mts +9 -4
- package/resources/realtime/client-secrets.d.mts.map +1 -1
- package/resources/realtime/client-secrets.d.ts +9 -4
- package/resources/realtime/client-secrets.d.ts.map +1 -1
- package/resources/realtime/realtime.d.mts +18 -8
- package/resources/realtime/realtime.d.mts.map +1 -1
- package/resources/realtime/realtime.d.ts +18 -8
- 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/responses.d.mts +9 -4
- package/resources/responses/responses.d.mts.map +1 -1
- package/resources/responses/responses.d.ts +9 -4
- 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/videos.d.mts +1 -1
- package/resources/videos.d.ts +1 -1
- package/src/_vendor/zod-to-json-schema/parseDef.ts +44 -16
- package/src/_vendor/zod-to-json-schema/parsers/branded.ts +2 -2
- package/src/_vendor/zod-to-json-schema/parsers/catch.ts +2 -2
- package/src/_vendor/zod-to-json-schema/parsers/default.ts +6 -2
- package/src/_vendor/zod-to-json-schema/parsers/nullable.ts +13 -5
- package/src/_vendor/zod-to-json-schema/parsers/optional.ts +14 -6
- package/src/_vendor/zod-to-json-schema/parsers/pipeline.ts +3 -2
- package/src/_vendor/zod-to-json-schema/parsers/promise.ts +6 -2
- package/src/_vendor/zod-to-json-schema/parsers/readonly.ts +2 -2
- package/src/auth/workload-identity-auth.ts +16 -5
- package/src/azure.ts +4 -1
- package/src/beta/realtime/internal-base.ts +43 -5
- package/src/beta/realtime/websocket.ts +10 -7
- package/src/beta/realtime/ws.ts +10 -7
- package/src/client.ts +80 -18
- package/src/helpers/zod.ts +16 -0
- package/src/internal/bedrock.ts +153 -0
- package/src/internal/provider.ts +60 -0
- package/src/internal/utils/log.ts +1 -0
- package/src/lib/AbstractChatCompletionRunner.ts +96 -45
- package/src/lib/AssistantStream.ts +4 -20
- package/src/lib/ChatCompletionRunner.ts +1 -1
- package/src/lib/ChatCompletionStream.ts +4 -11
- package/src/lib/ChatCompletionStreamingRunner.ts +1 -1
- package/src/lib/EventEmitter.ts +11 -2
- package/src/lib/EventStream.ts +20 -0
- package/src/lib/ResponsesParser.ts +18 -4
- package/src/lib/responses/ResponseAccumulator.ts +412 -0
- package/src/lib/responses/ResponseInputItems.ts +127 -0
- package/src/lib/responses/ResponseStream.ts +4 -93
- package/src/providers/bedrock/aws.ts +255 -0
- package/src/providers/bedrock.ts +33 -0
- package/src/realtime/internal-base.ts +90 -7
- package/src/realtime/websocket.ts +15 -13
- package/src/realtime/ws.ts +15 -13
- package/src/resources/realtime/client-secrets.ts +10 -4
- package/src/resources/realtime/realtime.ts +20 -8
- package/src/resources/responses/responses.ts +10 -4
- package/src/resources/videos.ts +1 -1
- 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
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import { defaultProvider } from '@aws-sdk/credential-provider-node';
|
|
2
|
+
import { Hash } from '@smithy/hash-node';
|
|
3
|
+
import { SignatureV4 } from '@smithy/signature-v4';
|
|
4
|
+
|
|
5
|
+
import * as Errors from '../../error';
|
|
6
|
+
import type { BodyInit } from '../../internal/builtin-types';
|
|
7
|
+
import {
|
|
8
|
+
assertProviderOwnsAuthorization,
|
|
9
|
+
errorWithCause,
|
|
10
|
+
normalizeOptionalString,
|
|
11
|
+
resolveBedrockBearerAuth,
|
|
12
|
+
resolveBedrockEndpoint,
|
|
13
|
+
type BedrockBearerOptions,
|
|
14
|
+
type BedrockEndpointOptions,
|
|
15
|
+
type BedrockRequestAuth,
|
|
16
|
+
} from '../../internal/bedrock';
|
|
17
|
+
import { createProvider, type Provider, type ProviderRequestContext } from '../../internal/provider';
|
|
18
|
+
import type { FinalizedRequestInit } from '../../internal/types';
|
|
19
|
+
|
|
20
|
+
const BEDROCK_SERVICE = 'bedrock-mantle';
|
|
21
|
+
|
|
22
|
+
export interface AwsCredentialIdentity {
|
|
23
|
+
accessKeyId: string;
|
|
24
|
+
secretAccessKey: string;
|
|
25
|
+
sessionToken?: string;
|
|
26
|
+
expiration?: Date;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type AwsCredentialsProvider = () => AwsCredentialIdentity | Promise<AwsCredentialIdentity>;
|
|
30
|
+
|
|
31
|
+
export interface BedrockProviderOptions extends BedrockEndpointOptions, BedrockBearerOptions {
|
|
32
|
+
/** Explicit AWS access key ID. Must be paired with secretAccessKey. */
|
|
33
|
+
accessKeyId?: string | undefined;
|
|
34
|
+
|
|
35
|
+
/** Explicit AWS secret access key. Must be paired with accessKeyId. */
|
|
36
|
+
secretAccessKey?: string | undefined;
|
|
37
|
+
|
|
38
|
+
/** Optional session token for explicit temporary AWS credentials. */
|
|
39
|
+
sessionToken?: string | undefined;
|
|
40
|
+
|
|
41
|
+
/** Explicit AWS shared-config profile. */
|
|
42
|
+
profile?: string | undefined;
|
|
43
|
+
|
|
44
|
+
/** A refreshable provider returning AWS credentials. */
|
|
45
|
+
credentialProvider?: AwsCredentialsProvider | undefined;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function validateStaticCredentials(options: BedrockProviderOptions): AwsCredentialIdentity | undefined {
|
|
49
|
+
const hasAccessKey = options.accessKeyId !== undefined;
|
|
50
|
+
const hasSecretKey = options.secretAccessKey !== undefined;
|
|
51
|
+
if (hasAccessKey !== hasSecretKey || (options.sessionToken !== undefined && !hasAccessKey)) {
|
|
52
|
+
throw new Errors.OpenAIError(
|
|
53
|
+
'The `accessKeyId` and `secretAccessKey` options must be provided together. A `sessionToken` may only be used with both.',
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
if (!hasAccessKey) return undefined;
|
|
57
|
+
|
|
58
|
+
if (
|
|
59
|
+
typeof options.accessKeyId !== 'string' ||
|
|
60
|
+
!options.accessKeyId.trim() ||
|
|
61
|
+
typeof options.secretAccessKey !== 'string' ||
|
|
62
|
+
!options.secretAccessKey.trim()
|
|
63
|
+
) {
|
|
64
|
+
throw new Errors.OpenAIError(
|
|
65
|
+
'Static AWS credentials require non-empty `accessKeyId` and `secretAccessKey` values.',
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
if (
|
|
69
|
+
options.sessionToken !== undefined &&
|
|
70
|
+
(typeof options.sessionToken !== 'string' || !options.sessionToken.trim())
|
|
71
|
+
) {
|
|
72
|
+
throw new Errors.OpenAIError('A static AWS `sessionToken` must not be empty when provided.');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
accessKeyId: options.accessKeyId,
|
|
77
|
+
secretAccessKey: options.secretAccessKey,
|
|
78
|
+
...(options.sessionToken ? { sessionToken: options.sessionToken } : {}),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function requestTarget(parsedURL: URL): { path: string; query: Record<string, string | string[]> } {
|
|
83
|
+
const query: Record<string, string | string[]> = {};
|
|
84
|
+
for (const [name, value] of parsedURL.searchParams) {
|
|
85
|
+
const existing = query[name];
|
|
86
|
+
query[name] =
|
|
87
|
+
existing === undefined ? value
|
|
88
|
+
: typeof existing === 'string' ? [existing, value]
|
|
89
|
+
: [...existing, value];
|
|
90
|
+
}
|
|
91
|
+
return { path: parsedURL.pathname, query };
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function signableBody(body: BodyInit | null | undefined): string | ArrayBuffer | ArrayBufferView | undefined {
|
|
95
|
+
if (body === undefined || body === null) return undefined;
|
|
96
|
+
if (typeof body === 'string' || body instanceof ArrayBuffer || ArrayBuffer.isView(body)) return body;
|
|
97
|
+
throw new Errors.OpenAIError(
|
|
98
|
+
"The SDK's Bedrock SigV4 mode requires a replayable request body. Buffer the body before sending or use bearer authentication.",
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function validateCredentialIdentity(identity: AwsCredentialIdentity): AwsCredentialIdentity {
|
|
103
|
+
if (
|
|
104
|
+
typeof identity?.accessKeyId !== 'string' ||
|
|
105
|
+
!identity.accessKeyId.trim() ||
|
|
106
|
+
typeof identity.secretAccessKey !== 'string' ||
|
|
107
|
+
!identity.secretAccessKey.trim() ||
|
|
108
|
+
(identity.sessionToken !== undefined &&
|
|
109
|
+
(typeof identity.sessionToken !== 'string' || !identity.sessionToken.trim()))
|
|
110
|
+
) {
|
|
111
|
+
throw new Errors.OpenAIError(
|
|
112
|
+
'Failed to resolve AWS credentials for Bedrock. Verify your AWS profile, environment variables, or runtime identity configuration and try again.',
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
return identity;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
class BedrockSigV4Auth implements BedrockRequestAuth {
|
|
119
|
+
private signer: SignatureV4 | undefined;
|
|
120
|
+
private resolvedCredentialsProvider: (() => Promise<AwsCredentialIdentity>) | undefined;
|
|
121
|
+
|
|
122
|
+
constructor(
|
|
123
|
+
private readonly options: {
|
|
124
|
+
region: string;
|
|
125
|
+
staticCredentials?: AwsCredentialIdentity | undefined;
|
|
126
|
+
profile?: string | undefined;
|
|
127
|
+
credentialProvider?: AwsCredentialsProvider | undefined;
|
|
128
|
+
usesDefaultChain: boolean;
|
|
129
|
+
},
|
|
130
|
+
) {}
|
|
131
|
+
|
|
132
|
+
private credentialsProvider(): () => Promise<AwsCredentialIdentity> {
|
|
133
|
+
if (this.resolvedCredentialsProvider) return this.resolvedCredentialsProvider;
|
|
134
|
+
|
|
135
|
+
if (this.options.staticCredentials) {
|
|
136
|
+
const credentials = this.options.staticCredentials;
|
|
137
|
+
return (this.resolvedCredentialsProvider = async () => credentials);
|
|
138
|
+
}
|
|
139
|
+
if (this.options.credentialProvider) {
|
|
140
|
+
const provider = this.options.credentialProvider;
|
|
141
|
+
return (this.resolvedCredentialsProvider = async () => validateCredentialIdentity(await provider()));
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const provider = defaultProvider(this.options.profile ? { profile: this.options.profile } : {});
|
|
145
|
+
return (this.resolvedCredentialsProvider = async () => validateCredentialIdentity(await provider()));
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
private signatureV4(): SignatureV4 {
|
|
149
|
+
return (this.signer ??= new SignatureV4({
|
|
150
|
+
credentials: this.credentialsProvider(),
|
|
151
|
+
region: this.options.region,
|
|
152
|
+
service: BEDROCK_SERVICE,
|
|
153
|
+
sha256: Hash.bind(null, 'sha256'),
|
|
154
|
+
}));
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
async prepareRequest(request: FinalizedRequestInit, { url }: ProviderRequestContext): Promise<void> {
|
|
158
|
+
if (Object.prototype.toString.call((globalThis as any).process) !== '[object process]') {
|
|
159
|
+
throw new Errors.OpenAIError(
|
|
160
|
+
'Bedrock AWS credential authentication is only supported in Node.js and compatible server runtimes. Use bearer authentication in this runtime.',
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const parsedURL = new URL(url);
|
|
165
|
+
const canonicalRegion = /^bedrock-mantle\.([a-z0-9-]+)\.api\.aws$/i.exec(parsedURL.hostname)?.[1];
|
|
166
|
+
if (canonicalRegion && canonicalRegion !== this.options.region) {
|
|
167
|
+
throw new Errors.OpenAIError(
|
|
168
|
+
`The Bedrock endpoint region \`${canonicalRegion}\` does not match the SigV4 region \`${this.options.region}\`.`,
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const headers = new Headers(request.headers);
|
|
173
|
+
assertProviderOwnsAuthorization(headers);
|
|
174
|
+
headers.delete('x-amz-date');
|
|
175
|
+
headers.delete('x-amz-security-token');
|
|
176
|
+
headers.delete('x-amz-content-sha256');
|
|
177
|
+
headers.set('host', parsedURL.host);
|
|
178
|
+
|
|
179
|
+
const method = (request.method ?? 'GET').toUpperCase();
|
|
180
|
+
const body = signableBody(request.body);
|
|
181
|
+
|
|
182
|
+
let signed: { headers: Record<string, string> };
|
|
183
|
+
try {
|
|
184
|
+
signed = await this.signatureV4().sign({
|
|
185
|
+
protocol: parsedURL.protocol,
|
|
186
|
+
hostname: parsedURL.hostname,
|
|
187
|
+
...(parsedURL.port ? { port: Number(parsedURL.port) } : {}),
|
|
188
|
+
method,
|
|
189
|
+
...requestTarget(parsedURL),
|
|
190
|
+
headers: Object.fromEntries(headers.entries()),
|
|
191
|
+
...(body !== undefined ? { body } : {}),
|
|
192
|
+
});
|
|
193
|
+
} catch (cause) {
|
|
194
|
+
const message =
|
|
195
|
+
this.options.usesDefaultChain ?
|
|
196
|
+
'Could not find credentials for Bedrock. Pass AWS credentials to `bedrock(...)` or configure the default AWS credential chain.'
|
|
197
|
+
: 'Failed to resolve AWS credentials for Bedrock. Verify your AWS profile, environment variables, or runtime identity configuration and try again.';
|
|
198
|
+
throw errorWithCause(message, cause);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
request.method = method;
|
|
202
|
+
request.redirect = 'manual';
|
|
203
|
+
request.headers = new Headers(signed.headers);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** Configure the standard OpenAI client for Amazon Bedrock using bearer or AWS authentication. */
|
|
208
|
+
export function bedrock(options: BedrockProviderOptions = {}): Provider {
|
|
209
|
+
const staticCredentials = validateStaticCredentials(options);
|
|
210
|
+
const profile = normalizeOptionalString(options.profile);
|
|
211
|
+
if (options.profile !== undefined && !profile) {
|
|
212
|
+
throw new Errors.OpenAIError('The Bedrock AWS `profile` must not be empty.');
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const awsModes = [!!staticCredentials, !!profile, !!options.credentialProvider].filter(Boolean).length;
|
|
216
|
+
if (awsModes > 1) {
|
|
217
|
+
throw new Errors.OpenAIError(
|
|
218
|
+
'Bedrock authentication is ambiguous. Configure exactly one explicit AWS mode: static credentials, profile, or credential provider.',
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
const explicitAwsAuth = awsModes === 1;
|
|
222
|
+
const bearerAuth = resolveBedrockBearerAuth(options, { allowEnvironment: !explicitAwsAuth });
|
|
223
|
+
if (bearerAuth.explicit && explicitAwsAuth) {
|
|
224
|
+
throw new Errors.OpenAIError(
|
|
225
|
+
'Bearer and AWS credential authentication are mutually exclusive. Configure exactly one explicit mode: bearer credential, static AWS credentials, profile, or credential provider.',
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const { region, baseURL } = resolveBedrockEndpoint(options);
|
|
230
|
+
if (!bearerAuth.factory && !region) {
|
|
231
|
+
throw new Errors.OpenAIError(
|
|
232
|
+
'Bedrock requires an AWS region. Pass `region` to `bedrock(...)`, or set `AWS_REGION` or `AWS_DEFAULT_REGION`.',
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
const credentialProvider = options.credentialProvider;
|
|
236
|
+
|
|
237
|
+
return createProvider({
|
|
238
|
+
configure() {
|
|
239
|
+
const auth =
|
|
240
|
+
bearerAuth.factory?.() ??
|
|
241
|
+
new BedrockSigV4Auth({
|
|
242
|
+
region: region!,
|
|
243
|
+
staticCredentials,
|
|
244
|
+
profile,
|
|
245
|
+
credentialProvider,
|
|
246
|
+
usesDefaultChain: !explicitAwsAuth,
|
|
247
|
+
});
|
|
248
|
+
return {
|
|
249
|
+
name: 'bedrock',
|
|
250
|
+
baseURL,
|
|
251
|
+
prepareRequest: auth.prepareRequest.bind(auth),
|
|
252
|
+
};
|
|
253
|
+
},
|
|
254
|
+
});
|
|
255
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as Errors from '../error';
|
|
2
|
+
import type { Provider } from '../internal/provider';
|
|
3
|
+
import { createProvider } from '../internal/provider';
|
|
4
|
+
import {
|
|
5
|
+
resolveBedrockBearerAuth,
|
|
6
|
+
resolveBedrockEndpoint,
|
|
7
|
+
type BedrockBearerOptions,
|
|
8
|
+
type BedrockEndpointOptions,
|
|
9
|
+
} from '../internal/bedrock';
|
|
10
|
+
|
|
11
|
+
export interface BedrockProviderOptions extends BedrockEndpointOptions, BedrockBearerOptions {}
|
|
12
|
+
|
|
13
|
+
/** Configure the standard OpenAI client for Amazon Bedrock using bearer authentication. */
|
|
14
|
+
export function bedrock(options: BedrockProviderOptions = {}): Provider {
|
|
15
|
+
const { baseURL } = resolveBedrockEndpoint(options);
|
|
16
|
+
const { factory } = resolveBedrockBearerAuth(options);
|
|
17
|
+
if (!factory) {
|
|
18
|
+
throw new Errors.OpenAIError(
|
|
19
|
+
'Bedrock bearer authentication requires an `apiKey`, `tokenProvider`, or `AWS_BEARER_TOKEN_BEDROCK`. For AWS credential authentication, import `bedrock` from `openai/providers/bedrock/aws`.',
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return createProvider({
|
|
24
|
+
configure() {
|
|
25
|
+
const auth = factory();
|
|
26
|
+
return {
|
|
27
|
+
name: 'bedrock',
|
|
28
|
+
baseURL,
|
|
29
|
+
prepareRequest: auth.prepareRequest.bind(auth),
|
|
30
|
+
};
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
}
|
|
@@ -83,16 +83,99 @@ export function isAzure(client: Pick<OpenAI, 'apiKey' | 'baseURL'>): client is A
|
|
|
83
83
|
return client instanceof AzureOpenAI;
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
export
|
|
87
|
-
|
|
86
|
+
export type RealtimeConnectionConfig =
|
|
87
|
+
| {
|
|
88
|
+
/**
|
|
89
|
+
* Start a new Realtime session using the given model.
|
|
90
|
+
*/
|
|
91
|
+
model: string;
|
|
92
|
+
callID?: undefined;
|
|
93
|
+
}
|
|
94
|
+
| {
|
|
95
|
+
model?: undefined;
|
|
96
|
+
/**
|
|
97
|
+
* Attach to an in-progress Realtime call over a sideband control connection.
|
|
98
|
+
*/
|
|
99
|
+
callID: string;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
export type AzureRealtimeConnectionConfig =
|
|
103
|
+
| {
|
|
104
|
+
/**
|
|
105
|
+
* Override the deployment configured on the Azure client.
|
|
106
|
+
*/
|
|
107
|
+
deploymentName?: string;
|
|
108
|
+
callID?: undefined;
|
|
109
|
+
}
|
|
110
|
+
| {
|
|
111
|
+
deploymentName?: undefined;
|
|
112
|
+
/**
|
|
113
|
+
* Attach to an in-progress Azure Realtime call over a sideband control connection.
|
|
114
|
+
*/
|
|
115
|
+
callID: string;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export function buildRealtimeURL(
|
|
119
|
+
client: Pick<OpenAI, 'apiKey' | 'baseURL'>,
|
|
120
|
+
connection: string | RealtimeConnectionConfig,
|
|
121
|
+
): URL {
|
|
122
|
+
const config: RealtimeConnectionConfig =
|
|
123
|
+
typeof connection === 'string' ? { model: connection } : connection;
|
|
88
124
|
const baseURL = client.baseURL;
|
|
89
|
-
const
|
|
125
|
+
const azure = isAzure(client);
|
|
126
|
+
const hasModel = !!config.model;
|
|
127
|
+
const hasCallID = !!config.callID;
|
|
128
|
+
|
|
129
|
+
if (hasModel === hasCallID) {
|
|
130
|
+
throw new Error('Pass exactly one of `model` or `callID` when opening a Realtime WebSocket.');
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
let url: URL;
|
|
134
|
+
if (azure && hasCallID) {
|
|
135
|
+
url = new URL(baseURL);
|
|
136
|
+
const basePath = url.pathname.replace(/\/+/g, '/').replace(/\/+$/, '');
|
|
137
|
+
const versionedPath = basePath.endsWith('/v1') ? basePath : `${basePath}/v1`;
|
|
138
|
+
url.pathname = `${versionedPath}/realtime`;
|
|
139
|
+
url.search = '';
|
|
140
|
+
url.hash = '';
|
|
141
|
+
} else {
|
|
142
|
+
const path = '/realtime';
|
|
143
|
+
url = new URL(baseURL + (baseURL.endsWith('/') ? path.slice(1) : path));
|
|
144
|
+
}
|
|
145
|
+
|
|
90
146
|
url.protocol = 'wss';
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
147
|
+
// Sideband control connections attach to an existing call via `call_id`.
|
|
148
|
+
if (azure) {
|
|
149
|
+
if (hasCallID) {
|
|
150
|
+
url.searchParams.set('call_id', config.callID!);
|
|
151
|
+
} else {
|
|
152
|
+
url.searchParams.set('api-version', client.apiVersion);
|
|
153
|
+
url.searchParams.set('deployment', config.model!);
|
|
154
|
+
}
|
|
94
155
|
} else {
|
|
95
|
-
|
|
156
|
+
if (hasCallID) {
|
|
157
|
+
url.searchParams.set('call_id', config.callID!);
|
|
158
|
+
} else {
|
|
159
|
+
url.searchParams.set('model', config.model!);
|
|
160
|
+
}
|
|
96
161
|
}
|
|
97
162
|
return url;
|
|
98
163
|
}
|
|
164
|
+
|
|
165
|
+
export function getAzureRealtimeConnection(
|
|
166
|
+
client: Pick<AzureOpenAI, 'deploymentName'>,
|
|
167
|
+
connection: AzureRealtimeConnectionConfig,
|
|
168
|
+
): RealtimeConnectionConfig {
|
|
169
|
+
if (connection.callID !== undefined) {
|
|
170
|
+
if (connection.deploymentName !== undefined) {
|
|
171
|
+
throw new Error('Pass either `deploymentName` or `callID`, but not both.');
|
|
172
|
+
}
|
|
173
|
+
return { callID: connection.callID };
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const model = connection.deploymentName ?? client.deploymentName;
|
|
177
|
+
if (!model) {
|
|
178
|
+
throw new Error('No deployment name provided');
|
|
179
|
+
}
|
|
180
|
+
return { model };
|
|
181
|
+
}
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import { AzureOpenAI, OpenAI } from '../index';
|
|
2
2
|
import { OpenAIError } from '../error';
|
|
3
3
|
import type { RealtimeClientEvent, RealtimeServerEvent } from '../resources/realtime/realtime';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
OpenAIRealtimeEmitter,
|
|
6
|
+
buildRealtimeURL,
|
|
7
|
+
getAzureRealtimeConnection,
|
|
8
|
+
isAzure,
|
|
9
|
+
type AzureRealtimeConnectionConfig,
|
|
10
|
+
type RealtimeConnectionConfig,
|
|
11
|
+
} from './internal-base';
|
|
5
12
|
import { isRunningInBrowser } from '../internal/detect-platform';
|
|
6
13
|
|
|
7
14
|
interface MessageEvent {
|
|
@@ -23,8 +30,7 @@ export class OpenAIRealtimeWebSocket extends OpenAIRealtimeEmitter {
|
|
|
23
30
|
socket: _WebSocket;
|
|
24
31
|
|
|
25
32
|
constructor(
|
|
26
|
-
props: {
|
|
27
|
-
model: string;
|
|
33
|
+
props: RealtimeConnectionConfig & {
|
|
28
34
|
dangerouslyAllowBrowser?: boolean;
|
|
29
35
|
/**
|
|
30
36
|
* Callback to mutate the URL, needed for Azure.
|
|
@@ -54,13 +60,12 @@ export class OpenAIRealtimeWebSocket extends OpenAIRealtimeEmitter {
|
|
|
54
60
|
throw new Error(
|
|
55
61
|
[
|
|
56
62
|
'Cannot open Realtime WebSocket with a function-based apiKey.',
|
|
57
|
-
'Use the .create() method so that the key is resolved before connecting
|
|
58
|
-
'await OpenAIRealtimeWebSocket.create(client, { model })',
|
|
63
|
+
'Use the .create() method so that the key is resolved before connecting.',
|
|
59
64
|
].join('\n'),
|
|
60
65
|
);
|
|
61
66
|
}
|
|
62
67
|
|
|
63
|
-
this.url = buildRealtimeURL(client, props
|
|
68
|
+
this.url = buildRealtimeURL(client, props);
|
|
64
69
|
props.onURL?.(this.url);
|
|
65
70
|
|
|
66
71
|
// @ts-ignore
|
|
@@ -106,15 +111,16 @@ export class OpenAIRealtimeWebSocket extends OpenAIRealtimeEmitter {
|
|
|
106
111
|
|
|
107
112
|
static async create(
|
|
108
113
|
client: Pick<OpenAI, 'apiKey' | 'baseURL' | '_callApiKey'>,
|
|
109
|
-
props:
|
|
114
|
+
props: RealtimeConnectionConfig & { dangerouslyAllowBrowser?: boolean },
|
|
110
115
|
): Promise<OpenAIRealtimeWebSocket> {
|
|
111
116
|
return new OpenAIRealtimeWebSocket({ ...props, __resolvedApiKey: await client._callApiKey() }, client);
|
|
112
117
|
}
|
|
113
118
|
|
|
114
119
|
static async azure(
|
|
115
120
|
client: Pick<AzureOpenAI, '_callApiKey' | 'apiVersion' | 'apiKey' | 'baseURL' | 'deploymentName'>,
|
|
116
|
-
options:
|
|
121
|
+
options: AzureRealtimeConnectionConfig & { dangerouslyAllowBrowser?: boolean } = {},
|
|
117
122
|
): Promise<OpenAIRealtimeWebSocket> {
|
|
123
|
+
const connection = getAzureRealtimeConnection(client, options);
|
|
118
124
|
const isApiKeyProvider = await client._callApiKey();
|
|
119
125
|
const apiKey = client.apiKey;
|
|
120
126
|
if (!apiKey) {
|
|
@@ -128,14 +134,10 @@ export class OpenAIRealtimeWebSocket extends OpenAIRealtimeEmitter {
|
|
|
128
134
|
url.searchParams.set('api-key', azureApiKey);
|
|
129
135
|
}
|
|
130
136
|
}
|
|
131
|
-
const deploymentName = options.deploymentName ?? client.deploymentName;
|
|
132
|
-
if (!deploymentName) {
|
|
133
|
-
throw new Error('No deployment name provided');
|
|
134
|
-
}
|
|
135
137
|
const { dangerouslyAllowBrowser } = options;
|
|
136
138
|
return new OpenAIRealtimeWebSocket(
|
|
137
139
|
{
|
|
138
|
-
|
|
140
|
+
...connection,
|
|
139
141
|
onURL,
|
|
140
142
|
...(dangerouslyAllowBrowser ? { dangerouslyAllowBrowser } : {}),
|
|
141
143
|
__resolvedApiKey: isApiKeyProvider,
|
package/src/realtime/ws.ts
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
import * as WS from 'ws';
|
|
2
2
|
import { AzureOpenAI, OpenAI } from '../index';
|
|
3
3
|
import type { RealtimeClientEvent, RealtimeServerEvent } from '../resources/realtime/realtime';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
OpenAIRealtimeEmitter,
|
|
6
|
+
buildRealtimeURL,
|
|
7
|
+
getAzureRealtimeConnection,
|
|
8
|
+
isAzure,
|
|
9
|
+
type AzureRealtimeConnectionConfig,
|
|
10
|
+
type RealtimeConnectionConfig,
|
|
11
|
+
} from './internal-base';
|
|
5
12
|
|
|
6
13
|
export class OpenAIRealtimeWS extends OpenAIRealtimeEmitter {
|
|
7
14
|
url: URL;
|
|
8
15
|
socket: WS.WebSocket;
|
|
9
16
|
|
|
10
17
|
constructor(
|
|
11
|
-
props: {
|
|
12
|
-
model: string;
|
|
18
|
+
props: RealtimeConnectionConfig & {
|
|
13
19
|
options?: WS.ClientOptions | undefined;
|
|
14
20
|
/** @internal */ __resolvedApiKey?: boolean;
|
|
15
21
|
},
|
|
@@ -22,12 +28,11 @@ export class OpenAIRealtimeWS extends OpenAIRealtimeEmitter {
|
|
|
22
28
|
throw new Error(
|
|
23
29
|
[
|
|
24
30
|
'Cannot open Realtime WebSocket with a function-based apiKey.',
|
|
25
|
-
'Use the .create() method so that the key is resolved before connecting
|
|
26
|
-
'await OpenAIRealtimeWS.create(client, { model })',
|
|
31
|
+
'Use the .create() method so that the key is resolved before connecting.',
|
|
27
32
|
].join('\n'),
|
|
28
33
|
);
|
|
29
34
|
}
|
|
30
|
-
this.url = buildRealtimeURL(client, props
|
|
35
|
+
this.url = buildRealtimeURL(client, props);
|
|
31
36
|
this.socket = new WS.WebSocket(this.url, {
|
|
32
37
|
...props.options,
|
|
33
38
|
headers: {
|
|
@@ -65,27 +70,24 @@ export class OpenAIRealtimeWS extends OpenAIRealtimeEmitter {
|
|
|
65
70
|
|
|
66
71
|
static async create(
|
|
67
72
|
client: Pick<OpenAI, 'apiKey' | 'baseURL' | '_callApiKey'>,
|
|
68
|
-
props:
|
|
73
|
+
props: RealtimeConnectionConfig & { options?: WS.ClientOptions | undefined },
|
|
69
74
|
): Promise<OpenAIRealtimeWS> {
|
|
70
75
|
return new OpenAIRealtimeWS({ ...props, __resolvedApiKey: await client._callApiKey() }, client);
|
|
71
76
|
}
|
|
72
77
|
|
|
73
78
|
static async azure(
|
|
74
79
|
client: Pick<AzureOpenAI, '_callApiKey' | 'apiVersion' | 'apiKey' | 'baseURL' | 'deploymentName'>,
|
|
75
|
-
props:
|
|
80
|
+
props: AzureRealtimeConnectionConfig & { options?: WS.ClientOptions | undefined } = {},
|
|
76
81
|
): Promise<OpenAIRealtimeWS> {
|
|
82
|
+
const connection = getAzureRealtimeConnection(client, props);
|
|
77
83
|
const isApiKeyProvider = await client._callApiKey();
|
|
78
84
|
const apiKey = client.apiKey;
|
|
79
85
|
if (!apiKey) {
|
|
80
86
|
throw new Error('Azure OpenAI Realtime requires an API key');
|
|
81
87
|
}
|
|
82
|
-
const deploymentName = props.deploymentName ?? client.deploymentName;
|
|
83
|
-
if (!deploymentName) {
|
|
84
|
-
throw new Error('No deployment name provided');
|
|
85
|
-
}
|
|
86
88
|
return new OpenAIRealtimeWS(
|
|
87
89
|
{
|
|
88
|
-
|
|
90
|
+
...connection,
|
|
89
91
|
options: {
|
|
90
92
|
...props.options,
|
|
91
93
|
headers: {
|
|
@@ -421,8 +421,8 @@ export namespace RealtimeSessionCreateResponse {
|
|
|
421
421
|
|
|
422
422
|
/**
|
|
423
423
|
* Identifier for service connectors, like those available in ChatGPT. One of
|
|
424
|
-
* `server_url` or `
|
|
425
|
-
* connectors
|
|
424
|
+
* `server_url`, `connector_id`, or `tunnel_id` must be provided. Learn more about
|
|
425
|
+
* service connectors
|
|
426
426
|
* [here](https://platform.openai.com/docs/guides/tools-remote-mcp#connectors).
|
|
427
427
|
*
|
|
428
428
|
* Currently supported `connector_id` values are:
|
|
@@ -468,10 +468,16 @@ export namespace RealtimeSessionCreateResponse {
|
|
|
468
468
|
server_description?: string;
|
|
469
469
|
|
|
470
470
|
/**
|
|
471
|
-
* The URL for the MCP server. One of `server_url` or `
|
|
472
|
-
* provided.
|
|
471
|
+
* The URL for the MCP server. One of `server_url`, `connector_id`, or `tunnel_id`
|
|
472
|
+
* must be provided.
|
|
473
473
|
*/
|
|
474
474
|
server_url?: string;
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* The Secure MCP Tunnel ID to use instead of a direct server URL. One of
|
|
478
|
+
* `server_url`, `connector_id`, or `tunnel_id` must be provided.
|
|
479
|
+
*/
|
|
480
|
+
tunnel_id?: string;
|
|
475
481
|
}
|
|
476
482
|
|
|
477
483
|
export namespace McpTool {
|
|
@@ -2236,8 +2236,8 @@ export interface RealtimeResponseCreateMcpTool {
|
|
|
2236
2236
|
|
|
2237
2237
|
/**
|
|
2238
2238
|
* Identifier for service connectors, like those available in ChatGPT. One of
|
|
2239
|
-
* `server_url` or `
|
|
2240
|
-
* connectors
|
|
2239
|
+
* `server_url`, `connector_id`, or `tunnel_id` must be provided. Learn more about
|
|
2240
|
+
* service connectors
|
|
2241
2241
|
* [here](https://platform.openai.com/docs/guides/tools-remote-mcp#connectors).
|
|
2242
2242
|
*
|
|
2243
2243
|
* Currently supported `connector_id` values are:
|
|
@@ -2283,10 +2283,16 @@ export interface RealtimeResponseCreateMcpTool {
|
|
|
2283
2283
|
server_description?: string;
|
|
2284
2284
|
|
|
2285
2285
|
/**
|
|
2286
|
-
* The URL for the MCP server. One of `server_url` or `
|
|
2287
|
-
* provided.
|
|
2286
|
+
* The URL for the MCP server. One of `server_url`, `connector_id`, or `tunnel_id`
|
|
2287
|
+
* must be provided.
|
|
2288
2288
|
*/
|
|
2289
2289
|
server_url?: string;
|
|
2290
|
+
|
|
2291
|
+
/**
|
|
2292
|
+
* The Secure MCP Tunnel ID to use instead of a direct server URL. One of
|
|
2293
|
+
* `server_url`, `connector_id`, or `tunnel_id` must be provided.
|
|
2294
|
+
*/
|
|
2295
|
+
tunnel_id?: string;
|
|
2290
2296
|
}
|
|
2291
2297
|
|
|
2292
2298
|
export namespace RealtimeResponseCreateMcpTool {
|
|
@@ -3277,8 +3283,8 @@ export namespace RealtimeToolsConfigUnion {
|
|
|
3277
3283
|
|
|
3278
3284
|
/**
|
|
3279
3285
|
* Identifier for service connectors, like those available in ChatGPT. One of
|
|
3280
|
-
* `server_url` or `
|
|
3281
|
-
* connectors
|
|
3286
|
+
* `server_url`, `connector_id`, or `tunnel_id` must be provided. Learn more about
|
|
3287
|
+
* service connectors
|
|
3282
3288
|
* [here](https://platform.openai.com/docs/guides/tools-remote-mcp#connectors).
|
|
3283
3289
|
*
|
|
3284
3290
|
* Currently supported `connector_id` values are:
|
|
@@ -3324,10 +3330,16 @@ export namespace RealtimeToolsConfigUnion {
|
|
|
3324
3330
|
server_description?: string;
|
|
3325
3331
|
|
|
3326
3332
|
/**
|
|
3327
|
-
* The URL for the MCP server. One of `server_url` or `
|
|
3328
|
-
* provided.
|
|
3333
|
+
* The URL for the MCP server. One of `server_url`, `connector_id`, or `tunnel_id`
|
|
3334
|
+
* must be provided.
|
|
3329
3335
|
*/
|
|
3330
3336
|
server_url?: string;
|
|
3337
|
+
|
|
3338
|
+
/**
|
|
3339
|
+
* The Secure MCP Tunnel ID to use instead of a direct server URL. One of
|
|
3340
|
+
* `server_url`, `connector_id`, or `tunnel_id` must be provided.
|
|
3341
|
+
*/
|
|
3342
|
+
tunnel_id?: string;
|
|
3331
3343
|
}
|
|
3332
3344
|
|
|
3333
3345
|
export namespace Mcp {
|
|
@@ -7141,8 +7141,8 @@ export namespace Tool {
|
|
|
7141
7141
|
|
|
7142
7142
|
/**
|
|
7143
7143
|
* Identifier for service connectors, like those available in ChatGPT. One of
|
|
7144
|
-
* `server_url` or `
|
|
7145
|
-
* connectors
|
|
7144
|
+
* `server_url`, `connector_id`, or `tunnel_id` must be provided. Learn more about
|
|
7145
|
+
* service connectors
|
|
7146
7146
|
* [here](https://platform.openai.com/docs/guides/tools-remote-mcp#connectors).
|
|
7147
7147
|
*
|
|
7148
7148
|
* Currently supported `connector_id` values are:
|
|
@@ -7188,10 +7188,16 @@ export namespace Tool {
|
|
|
7188
7188
|
server_description?: string;
|
|
7189
7189
|
|
|
7190
7190
|
/**
|
|
7191
|
-
* The URL for the MCP server. One of `server_url` or `
|
|
7192
|
-
* provided.
|
|
7191
|
+
* The URL for the MCP server. One of `server_url`, `connector_id`, or `tunnel_id`
|
|
7192
|
+
* must be provided.
|
|
7193
7193
|
*/
|
|
7194
7194
|
server_url?: string;
|
|
7195
|
+
|
|
7196
|
+
/**
|
|
7197
|
+
* The Secure MCP Tunnel ID to use instead of a direct server URL. One of
|
|
7198
|
+
* `server_url`, `connector_id`, or `tunnel_id` must be provided.
|
|
7199
|
+
*/
|
|
7200
|
+
tunnel_id?: string;
|
|
7195
7201
|
}
|
|
7196
7202
|
|
|
7197
7203
|
export namespace Mcp {
|
package/src/resources/videos.ts
CHANGED
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '6.
|
|
1
|
+
export const VERSION = '6.45.0'; // x-release-please-version
|
package/version.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "6.
|
|
1
|
+
export declare const VERSION = "6.45.0";
|
|
2
2
|
//# sourceMappingURL=version.d.mts.map
|