ai 7.0.178 → 7.0.179
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 +14 -0
- package/dist/{default-stop-condition-BskNu2xj.js → default-stop-condition-wtuJTiTo.js} +2 -2
- package/dist/{default-stop-condition-BskNu2xj.js.map → default-stop-condition-wtuJTiTo.js.map} +1 -1
- package/dist/{index-kb5wF2kk.d.ts → index-CM_8u8gB.d.ts} +3 -1
- package/dist/{index-kb5wF2kk.d.ts.map → index-CM_8u8gB.d.ts.map} +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +55 -23
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +1 -1
- package/dist/internal/index.js +1 -1
- package/docs/03-ai-sdk-core/36-realtime.mdx +3 -1
- package/docs/03-ai-sdk-core/36-transcription.mdx +2 -2
- package/docs/03-ai-sdk-core/37-speech.mdx +1 -0
- package/docs/07-reference/02-ai-sdk-ui/05-use-realtime.mdx +6 -2
- package/package.json +3 -3
- package/src/realtime/browser-realtime-live-websocket.ts +23 -5
- package/src/realtime/realtime-session.ts +68 -29
package/dist/internal/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $c as LanguageModelCallOptions, Al as addLanguageModelUsage, Ao as ToolApprovalStatus, Ba as GenerateTextOnEndCallback, Bl as LanguageModelResponseMetadata, Ca as TelemetryDispatcher, El as Warning, Eo as ResolvedToolCallers, Ga as GenerateTextOnStepFinishCallback, Go as StaticToolOutputDenied, Ha as GenerateTextOnStartCallback, Hl as LanguageModelRequestMetadata, Jl as ToolChoice, Js as ContentPart, Ka as GenerateTextOnStepStartCallback, Kl as FinishReason, Ks as StepResult, Ml as createNullLanguageModelUsage, Pc as ToolModelMessage$1, So as ToolCallRepairFunction, Ua as GenerateTextOnStepEndCallback, Vl as ResponseMessage, Vo as ToolOrder, Wa as GenerateTextOnStepErrorCallback, Ws as DefaultStepResult, Xs as StaticToolResult, Ys as DynamicToolResult, Zo as createAsyncIterableStream, Zs as TypedToolResult, _a as LanguageModelStreamPart, _c as StandardizedPrompt, _l as DownloadFunction, _o as OnToolExecutionEndCallback, ac as TypedToolCall, dc as IncludedContext, fc as IncludedToolsContext, ga as GenerateTextResult, gc as Callback, ic as StaticToolCall, jl as asLanguageModelUsage, kl as LanguageModelUsage, ko as ToolApprovalConfiguration, mo as ToolInputRefinement, nc as ToolApprovalRequestOutput, oc as ReasoningFileOutput, pc as TelemetryOptions, po as ToolsContextSettings, ql as LanguageModel, qo as InferCompleteOutput, rc as DynamicToolCall, sc as ReasoningOutput, tc as ToolApprovalResponseOutput, to as Output, uc as GeneratedFile, vc as standardizePrompt, vl as createDefaultDownloadFunction, vo as OnToolExecutionStartCallback, wc as AssistantModelMessage$1, wl as logWarnings, wo as InvalidToolInputError, xo as ToolOutput, za as GenerateTextOnAbortCallback, zc as Instructions } from "../index-
|
|
1
|
+
import { $c as LanguageModelCallOptions, Al as addLanguageModelUsage, Ao as ToolApprovalStatus, Ba as GenerateTextOnEndCallback, Bl as LanguageModelResponseMetadata, Ca as TelemetryDispatcher, El as Warning, Eo as ResolvedToolCallers, Ga as GenerateTextOnStepFinishCallback, Go as StaticToolOutputDenied, Ha as GenerateTextOnStartCallback, Hl as LanguageModelRequestMetadata, Jl as ToolChoice, Js as ContentPart, Ka as GenerateTextOnStepStartCallback, Kl as FinishReason, Ks as StepResult, Ml as createNullLanguageModelUsage, Pc as ToolModelMessage$1, So as ToolCallRepairFunction, Ua as GenerateTextOnStepEndCallback, Vl as ResponseMessage, Vo as ToolOrder, Wa as GenerateTextOnStepErrorCallback, Ws as DefaultStepResult, Xs as StaticToolResult, Ys as DynamicToolResult, Zo as createAsyncIterableStream, Zs as TypedToolResult, _a as LanguageModelStreamPart, _c as StandardizedPrompt, _l as DownloadFunction, _o as OnToolExecutionEndCallback, ac as TypedToolCall, dc as IncludedContext, fc as IncludedToolsContext, ga as GenerateTextResult, gc as Callback, ic as StaticToolCall, jl as asLanguageModelUsage, kl as LanguageModelUsage, ko as ToolApprovalConfiguration, mo as ToolInputRefinement, nc as ToolApprovalRequestOutput, oc as ReasoningFileOutput, pc as TelemetryOptions, po as ToolsContextSettings, ql as LanguageModel, qo as InferCompleteOutput, rc as DynamicToolCall, sc as ReasoningOutput, tc as ToolApprovalResponseOutput, to as Output, uc as GeneratedFile, vc as standardizePrompt, vl as createDefaultDownloadFunction, vo as OnToolExecutionStartCallback, wc as AssistantModelMessage$1, wl as logWarnings, wo as InvalidToolInputError, xo as ToolOutput, za as GenerateTextOnAbortCallback, zc as Instructions } from "../index-CM_8u8gB.js";
|
|
2
2
|
import { Arrayable, Context, Experimental_SandboxSession, FlexibleSchema, IdGenerator, InferToolSetContext, ModelMessage, RetryFunction, ShouldRetryFunction, Tool, ToolApprovalRequest, ToolApprovalResponse, ToolResultOutput, ToolResultPart, ToolSet, convertAsyncIteratorToReadableStream } from "@ai-sdk/provider-utils";
|
|
3
3
|
import { EmbeddingModelV4, Experimental_DecisionModelV4, Experimental_ExtractionModelV4, Experimental_SpeechTranslationModelV4, Experimental_VideoModelV4, ImageModelV4, LanguageModelV4, LanguageModelV4Content, LanguageModelV4FunctionTool, LanguageModelV4Prompt, LanguageModelV4ProviderTool, LanguageModelV4ToolCall, LanguageModelV4ToolChoice, LanguageModelV4ToolResultOutput, RerankingModelV4, SharedV4Warning, SpeechModelV4, TranscriptionModelV4 } from "@ai-sdk/provider";
|
|
4
4
|
//#region src/prompt/convert-to-language-model-prompt.d.ts
|
package/dist/internal/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { $ as convertToLanguageModelPrompt, B as setAbortTimeout, C as resolveToolApproval, E as DefaultGenerateTextResult, Et as logWarnings, G as addLanguageModelUsage, H as mergeAbortSignals, J as standardizePrompt, K as asLanguageModelUsage, O as validateToolContext, P as convertLanguageModelContent, Q as createToolModelOutput, R as collectToolApprovals, S as filterIncludedContext, V as prepareRetries, X as prepareToolChoice, Y as prepareTools, Z as prepareLanguageModelCallOptions, _ as createTelemetryDispatcher, a as createAsyncIterableStream, c as validateApprovedToolApprovals, d as verifyToolApprovalSignature, et as downloadAssets, g as DefaultStepResult, h as createRestrictedTelemetryDispatcher, ht as resolveLanguageModel, k as createToolSearchState, n as logDefaultStopConditionWarning, o as mapWithConcurrency, ot as mergeObjects, p as toResponseMessages, q as createNullLanguageModelUsage, r as isOutputChunk, s as prepareToolCallConcurrency, st as createDefaultDownloadFunction, tt as mapToolResultOutput, u as signToolApproval, w as parseToolCall, x as mergeCallbacks, z as calculateTokensPerSecond } from "../default-stop-condition-
|
|
1
|
+
import { $ as convertToLanguageModelPrompt, B as setAbortTimeout, C as resolveToolApproval, E as DefaultGenerateTextResult, Et as logWarnings, G as addLanguageModelUsage, H as mergeAbortSignals, J as standardizePrompt, K as asLanguageModelUsage, O as validateToolContext, P as convertLanguageModelContent, Q as createToolModelOutput, R as collectToolApprovals, S as filterIncludedContext, V as prepareRetries, X as prepareToolChoice, Y as prepareTools, Z as prepareLanguageModelCallOptions, _ as createTelemetryDispatcher, a as createAsyncIterableStream, c as validateApprovedToolApprovals, d as verifyToolApprovalSignature, et as downloadAssets, g as DefaultStepResult, h as createRestrictedTelemetryDispatcher, ht as resolveLanguageModel, k as createToolSearchState, n as logDefaultStopConditionWarning, o as mapWithConcurrency, ot as mergeObjects, p as toResponseMessages, q as createNullLanguageModelUsage, r as isOutputChunk, s as prepareToolCallConcurrency, st as createDefaultDownloadFunction, tt as mapToolResultOutput, u as signToolApproval, w as parseToolCall, x as mergeCallbacks, z as calculateTokensPerSecond } from "../default-stop-condition-wtuJTiTo.js";
|
|
2
2
|
import { convertAsyncIteratorToReadableStream } from "@ai-sdk/provider-utils";
|
|
3
3
|
export { DefaultGenerateTextResult, DefaultStepResult, addLanguageModelUsage, asLanguageModelUsage, calculateTokensPerSecond, collectToolApprovals, convertAsyncIteratorToReadableStream, convertLanguageModelContent, convertToLanguageModelPrompt, createAsyncIterableStream, createDefaultDownloadFunction, createNullLanguageModelUsage, createRestrictedTelemetryDispatcher, createTelemetryDispatcher, createToolModelOutput, createToolSearchState, downloadAssets, filterIncludedContext, isOutputChunk, logDefaultStopConditionWarning, logWarnings, mapToolResultOutput, mapWithConcurrency, mergeAbortSignals, mergeCallbacks, mergeObjects, parseToolCall, prepareLanguageModelCallOptions as prepareCallSettings, prepareLanguageModelCallOptions, prepareRetries, prepareToolCallConcurrency, prepareToolChoice, prepareTools, resolveLanguageModel, resolveToolApproval, setAbortTimeout, signToolApproval, standardizePrompt, toResponseMessages, validateApprovedToolApprovals, validateToolContext, verifyToolApprovalSignature };
|
|
@@ -30,7 +30,9 @@ The typical flow is:
|
|
|
30
30
|
1. Tool calls are handled by your application with `onToolCall`.
|
|
31
31
|
|
|
32
32
|
For continuous **OpenAI Live** conversations, use an application-owned WebSocket
|
|
33
|
-
relay or optional WebRTC via `api.session`.
|
|
33
|
+
relay or optional WebRTC via `api.session`. With
|
|
34
|
+
[AI Gateway](/providers/ai-sdk-providers/ai-gateway#live-models), the browser can
|
|
35
|
+
also connect straight to the Gateway with a token from `api.token`. Live uses client delegation: your
|
|
34
36
|
application handles delegated work and submits context rather than using the
|
|
35
37
|
turn-based tool loop below. See the
|
|
36
38
|
[`experimental_useRealtime` reference](/docs/reference/ai-sdk-ui/use-realtime)
|
|
@@ -417,8 +417,8 @@ try {
|
|
|
417
417
|
| [Deepgram](/providers/ai-sdk-providers/deepgram#transcription-models) | `nova-2` (+ variants) |
|
|
418
418
|
| [Deepgram](/providers/ai-sdk-providers/deepgram#transcription-models) | `nova-3` (+ variants) |
|
|
419
419
|
| [Gladia](/providers/ai-sdk-providers/gladia#transcription-models) | `default` |
|
|
420
|
-
| [AssemblyAI](/providers/ai-sdk-providers/assemblyai#transcription-models) | `
|
|
421
|
-
| [AssemblyAI](/providers/ai-sdk-providers/assemblyai#transcription-models) | `universal-
|
|
420
|
+
| [AssemblyAI](/providers/ai-sdk-providers/assemblyai#transcription-models) | `assemblyai-stt-3-7` |
|
|
421
|
+
| [AssemblyAI](/providers/ai-sdk-providers/assemblyai#transcription-models) | `universal-2` |
|
|
422
422
|
| [Fal](/providers/ai-sdk-providers/fal#transcription-models) | `whisper` |
|
|
423
423
|
| [Fal](/providers/ai-sdk-providers/fal#transcription-models) | `wizper` |
|
|
424
424
|
| [Google Vertex](/providers/ai-sdk-providers/google-vertex#transcription-models) | `chirp_2` |
|
|
@@ -255,5 +255,6 @@ try {
|
|
|
255
255
|
| [Fish Audio](/providers/ai-sdk-providers/fish-audio#speech-models) | `s1` |
|
|
256
256
|
| [Fish Audio](/providers/ai-sdk-providers/fish-audio#speech-models) | `s2-pro` |
|
|
257
257
|
| [Fish Audio](/providers/ai-sdk-providers/fish-audio#speech-models) | `s2.1-pro` |
|
|
258
|
+
| [AssemblyAI](/providers/ai-sdk-providers/assemblyai#speech-models) | `assemblyai-tts-1` |
|
|
258
259
|
|
|
259
260
|
Above are a small subset of the speech models supported by the AI SDK providers. For more, see the respective provider documentation.
|
|
@@ -83,8 +83,12 @@ function LiveConversation() {
|
|
|
83
83
|
}
|
|
84
84
|
```
|
|
85
85
|
|
|
86
|
-
The current continuous browser runtime supports a JSON/PCM16 WebSocket
|
|
87
|
-
profile
|
|
86
|
+
The current continuous browser runtime supports a JSON/PCM16 WebSocket media
|
|
87
|
+
profile, through an application relay (`api.websocket`) or, for models that declare
|
|
88
|
+
the `client-secret-websocket` connection, straight to the provider with a
|
|
89
|
+
short-lived token (`api.token`). AI Gateway Live models support the token flow; see
|
|
90
|
+
[AI Gateway Live models](/providers/ai-sdk-providers/ai-gateway#live-models).
|
|
91
|
+
Continuous conversation semantics alone do not guarantee support for every
|
|
88
92
|
codec or transport. Applications with their own audio pipeline can use the low-level
|
|
89
93
|
provider for other supported codecs. OpenAI-specific settings
|
|
90
94
|
live under `providerOptions.openai` and use camelCase fields; the provider converts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ai",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.179",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "AI SDK by Vercel - build apps like ChatGPT, Claude, Gemini, and more with a single interface for any model using the Vercel AI Gateway or go direct to OpenAI, Anthropic, Google, or any other model provider.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -43,14 +43,14 @@
|
|
|
43
43
|
}
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@ai-sdk/gateway": "4.0.
|
|
46
|
+
"@ai-sdk/gateway": "4.0.152",
|
|
47
47
|
"@ai-sdk/provider": "4.0.39",
|
|
48
48
|
"@ai-sdk/provider-utils": "5.0.83"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@ai-sdk/amazon-bedrock": "5.0.146",
|
|
52
52
|
"@ai-sdk/deepseek": "3.0.89",
|
|
53
|
-
"@ai-sdk/google": "4.0.
|
|
53
|
+
"@ai-sdk/google": "4.0.124",
|
|
54
54
|
"@ai-sdk/groq": "4.0.86",
|
|
55
55
|
"@ai-sdk/huggingface": "2.0.95",
|
|
56
56
|
"@ai-sdk/moonshotai": "3.0.95",
|
|
@@ -8,7 +8,7 @@ import type {
|
|
|
8
8
|
import { BrowserRealtimeAudio } from './browser-realtime-audio';
|
|
9
9
|
import { BrowserRealtimeTransport } from './browser-realtime-transport';
|
|
10
10
|
|
|
11
|
-
/** Continuous PCM16 audio-chunk media
|
|
11
|
+
/** Continuous PCM16 audio-chunk media over a WebSocket relay or client-secret connection. */
|
|
12
12
|
export class BrowserRealtimeLiveWebSocket {
|
|
13
13
|
private readonly transport: BrowserRealtimeTransport;
|
|
14
14
|
private readonly audio: BrowserRealtimeAudio;
|
|
@@ -84,9 +84,20 @@ export class BrowserRealtimeLiveWebSocket {
|
|
|
84
84
|
stream?: MediaStream;
|
|
85
85
|
capture?: boolean;
|
|
86
86
|
}): void {
|
|
87
|
+
const generation = this.prepare(options);
|
|
88
|
+
if (generation !== this.generation) return;
|
|
89
|
+
this.open({
|
|
90
|
+
mode: 'relay',
|
|
91
|
+
url: options.url,
|
|
92
|
+
protocols: options.protocols,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Resets media and primes playback; call while still in the user gesture. */
|
|
97
|
+
prepare(options: { stream?: MediaStream; capture?: boolean }): number {
|
|
87
98
|
const generation = this.generation + 1;
|
|
88
99
|
this.dispose();
|
|
89
|
-
if (generation !== this.generation) return;
|
|
100
|
+
if (generation !== this.generation) return generation;
|
|
90
101
|
for (const format of [
|
|
91
102
|
this.config.inputAudioFormat,
|
|
92
103
|
this.config.outputAudioFormat,
|
|
@@ -111,10 +122,17 @@ export class BrowserRealtimeLiveWebSocket {
|
|
|
111
122
|
void this.audio.resumePlayback().catch(error => {
|
|
112
123
|
if (generation === this.generation) this.options.onError(error);
|
|
113
124
|
});
|
|
125
|
+
return generation;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Opens the socket through an application relay or with a client secret. */
|
|
129
|
+
open(
|
|
130
|
+
connection:
|
|
131
|
+
| { mode: 'relay'; url: string; protocols?: string[] }
|
|
132
|
+
| { mode: 'client-secret'; url: string; token: string },
|
|
133
|
+
): void {
|
|
114
134
|
this.transport.connect({
|
|
115
|
-
|
|
116
|
-
url: options.url,
|
|
117
|
-
protocols: options.protocols,
|
|
135
|
+
...connection,
|
|
118
136
|
onOpen: () => {
|
|
119
137
|
return this.transport.sendEvent({
|
|
120
138
|
type: this.options.model.capabilities?.startup ?? 'session-update',
|
|
@@ -175,9 +175,14 @@ export abstract class AbstractRealtimeSession {
|
|
|
175
175
|
throw new Error('Realtime model does not support WebRTC configuration');
|
|
176
176
|
return;
|
|
177
177
|
}
|
|
178
|
-
|
|
178
|
+
// Continuous token sessions need an explicit declaration, not the legacy default.
|
|
179
|
+
if (
|
|
180
|
+
this.continuous &&
|
|
181
|
+
api.token != null &&
|
|
182
|
+
!model.capabilities?.connections?.includes('client-secret-websocket')
|
|
183
|
+
)
|
|
179
184
|
throw new Error(
|
|
180
|
-
'
|
|
185
|
+
'Realtime model does not support client-secret-websocket',
|
|
181
186
|
);
|
|
182
187
|
if (api.token != null && model.getWebSocketConfig == null)
|
|
183
188
|
throw new Error(
|
|
@@ -340,44 +345,55 @@ export abstract class AbstractRealtimeSession {
|
|
|
340
345
|
capture: connectOptions?.capture,
|
|
341
346
|
timeoutMs: this.options.startupTimeoutMs ?? 30_000,
|
|
342
347
|
});
|
|
343
|
-
} else if (
|
|
344
|
-
|
|
345
|
-
model.capabilities?.conversation === 'continuous'
|
|
346
|
-
) {
|
|
347
|
-
this.pcm = new BrowserRealtimeLiveWebSocket({
|
|
348
|
+
} else if (this.continuous) {
|
|
349
|
+
const pcm = new BrowserRealtimeLiveWebSocket({
|
|
348
350
|
...callbacks,
|
|
349
351
|
sessionConfig,
|
|
350
352
|
sampleRate: this.options.sampleRate,
|
|
351
353
|
maxPlaybackBufferSeconds: this.options.maxPlaybackBufferSeconds,
|
|
352
354
|
});
|
|
353
|
-
this.pcm
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
355
|
+
this.pcm = pcm;
|
|
356
|
+
if (api.websocket != null) {
|
|
357
|
+
pcm.connect({
|
|
358
|
+
url: api.websocket,
|
|
359
|
+
protocols: api.protocols,
|
|
360
|
+
stream: connectOptions?.stream,
|
|
361
|
+
capture: connectOptions?.capture,
|
|
362
|
+
});
|
|
363
|
+
} else if (api.token != null) {
|
|
364
|
+
pcm.prepare({
|
|
365
|
+
stream: connectOptions?.stream,
|
|
366
|
+
capture: connectOptions?.capture,
|
|
367
|
+
});
|
|
368
|
+
const setup = await this.fetchRealtimeSetup(
|
|
369
|
+
api.token,
|
|
370
|
+
sessionConfig,
|
|
371
|
+
attempt,
|
|
372
|
+
);
|
|
373
|
+
if (setup == null || !current() || this.pcm !== pcm) return;
|
|
374
|
+
if (setup.tools != null && setup.tools.length > 0)
|
|
375
|
+
throw new UnsupportedFunctionalityError({
|
|
376
|
+
functionality:
|
|
377
|
+
'Realtime setup tools for continuous sessions; client delegation is application-owned',
|
|
378
|
+
});
|
|
379
|
+
pcm.open({
|
|
380
|
+
mode: 'client-secret',
|
|
381
|
+
token: setup.token,
|
|
382
|
+
url: setup.url,
|
|
383
|
+
});
|
|
384
|
+
}
|
|
359
385
|
} else {
|
|
360
386
|
this.ensureAudio();
|
|
361
387
|
let config: RealtimeSessionConfig = sessionConfig ?? {};
|
|
362
388
|
let token: string | undefined;
|
|
363
389
|
let url = api.websocket;
|
|
364
390
|
if (api.token != null) {
|
|
365
|
-
const
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
if (!current()) return;
|
|
372
|
-
if (!response.ok)
|
|
373
|
-
throw new Error(
|
|
374
|
-
`Failed to fetch realtime setup: ${response.status}`,
|
|
375
|
-
);
|
|
376
|
-
const payload: unknown = await response.json().catch(() => {
|
|
377
|
-
throw new Error('Invalid realtime setup response');
|
|
378
|
-
});
|
|
379
|
-
if (!current() || attempt.closing) return;
|
|
380
|
-
const setup = validateRealtimeSetup(payload);
|
|
391
|
+
const setup = await this.fetchRealtimeSetup(
|
|
392
|
+
api.token,
|
|
393
|
+
sessionConfig,
|
|
394
|
+
attempt,
|
|
395
|
+
);
|
|
396
|
+
if (setup == null) return;
|
|
381
397
|
token = setup.token;
|
|
382
398
|
url = setup.url;
|
|
383
399
|
config = {
|
|
@@ -418,6 +434,29 @@ export abstract class AbstractRealtimeSession {
|
|
|
418
434
|
}
|
|
419
435
|
}
|
|
420
436
|
|
|
437
|
+
/** Fetches the application's token setup; undefined when the attempt ended. */
|
|
438
|
+
private async fetchRealtimeSetup(
|
|
439
|
+
endpoint: string,
|
|
440
|
+
sessionConfig: Partial<RealtimeSessionConfig> | undefined,
|
|
441
|
+
attempt: RealtimeAttempt,
|
|
442
|
+
) {
|
|
443
|
+
const current = () => this.attempt === attempt && attempt.active;
|
|
444
|
+
const response = await fetch(endpoint, {
|
|
445
|
+
method: 'POST',
|
|
446
|
+
headers: { 'Content-Type': 'application/json' },
|
|
447
|
+
body: JSON.stringify({ sessionConfig }),
|
|
448
|
+
signal: attempt.abort.signal,
|
|
449
|
+
});
|
|
450
|
+
if (!current()) return undefined;
|
|
451
|
+
if (!response.ok)
|
|
452
|
+
throw new Error(`Failed to fetch realtime setup: ${response.status}`);
|
|
453
|
+
const payload: unknown = await response.json().catch(() => {
|
|
454
|
+
throw new Error('Invalid realtime setup response');
|
|
455
|
+
});
|
|
456
|
+
if (!current() || attempt.closing) return undefined;
|
|
457
|
+
return validateRealtimeSetup(payload);
|
|
458
|
+
}
|
|
459
|
+
|
|
421
460
|
private fail(error: unknown, drain?: Promise<void>, report = true): void {
|
|
422
461
|
const attempt = this.attempt;
|
|
423
462
|
if (attempt == null || !attempt.active || attempt.cause != null) return;
|