ai 7.0.181 → 7.0.183
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 +21 -0
- package/dist/{default-stop-condition-D8PwkeWe.js → default-stop-condition-CKhd4H3S.js} +2 -2
- package/dist/{default-stop-condition-D8PwkeWe.js.map → default-stop-condition-CKhd4H3S.js.map} +1 -1
- package/dist/{index-CKEJqCzY.d.ts → index-D1zb0Eh5.d.ts} +1 -2
- package/dist/{index-CKEJqCzY.d.ts.map → index-D1zb0Eh5.d.ts.map} +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +51 -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/02-foundations/02-providers-and-models.mdx +3 -3
- package/docs/03-ai-sdk-harnesses/02-harness-agent.mdx +22 -0
- package/docs/07-reference/01-ai-sdk-core/24-mcp-events.mdx +3 -2
- package/package.json +11 -11
- package/src/realtime/browser-realtime-audio.ts +76 -17
- package/src/realtime/realtime-session.ts +5 -9
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.js";
|
|
2
|
-
import { $ as convertToLanguageModelPrompt, A as toolSearch, At as InvalidMessageRoleError, B as setAbortTimeout, Bt as InvalidToolApprovalError, C as resolveToolApproval, Ct as asLanguageModelV4, D as convertToReasoningOutputs, Dt as logWarnings, E as DefaultGenerateTextResult, Et as createLogWarnings, F as resolveGeneratedFileData, Ft as NoOutputGeneratedError, G as addLanguageModelUsage, H as mergeAbortSignals, I as DefaultGeneratedFile, It as MissingToolResultsError, J as standardizePrompt, K as asLanguageModelUsage, L as DefaultGeneratedFileWithType, Lt as ToolCallNotFoundForApprovalError, M as prepareToolsForToolCallers, Mt as UnsupportedModelVersionError, N as resolveToolCallerConfiguration, Nt as ToolCallRepairError, O as validateToolContext, Ot as notify, P as convertLanguageModelContent, Pt as NoSuchToolError, Q as createToolModelOutput, R as collectToolApprovals, Rt as InvalidToolInputError, S as filterIncludedContext, St as asVideoModelV4, T as getToolCallInputSchemaInput, Tt as asEmbeddingModelV4, U as getOwn, V as prepareRetries, Vt as InvalidArgumentError, W as addImageModelUsage, X as prepareToolChoice, Y as prepareTools, Z as prepareLanguageModelCallOptions, _ as createTelemetryDispatcher, _t as resolveSpeechModel, a as createAsyncIterableStream, at as convertDataContentToUint8Array, b as AI_SDK_TELEMETRY_TRACING_CHANNEL, bt as resolveVideoModel, c as validateApprovedToolApprovals, ct as download, dt as resolveDecisionModel, f as hashCanonical, ft as resolveEmbeddingModel, g as DefaultStepResult, gt as resolveRerankingModel, h as createRestrictedTelemetryDispatcher$4, ht as resolveLanguageModel, i as asAsyncIterableStream, it as convertDataContentToBase64String, j as appendToolCallerMessages, jt as InvalidDataContentError, k as createToolSearchState, kt as RetryError, l as maybeSignApproval, lt as VERSION, m as isDeepEqualData, mt as resolveImageModel, nt as convertToLanguageModelV4FilePart, o as mapWithConcurrency, ot as mergeObjects, p as toResponseMessages, pt as resolveExtractionModel, q as createNullLanguageModelUsage, r as isOutputChunk$1, rt as splitDataUrl, s as prepareToolCallConcurrency, t as createDefaultStopCondition, ut as asEvaluationModel, v as getGlobalTelemetryIntegrations, vt as resolveSpeechTranslationModel, w as parseToolCall, wt as asImageModelV4, x as mergeCallbacks, xt as asProviderV4, y as registerTelemetry, yt as resolveTranscriptionModel, z as calculateTokensPerSecond, zt as InvalidToolApprovalSignatureError } from "./default-stop-condition-
|
|
2
|
+
import { $ as convertToLanguageModelPrompt, A as toolSearch, At as InvalidMessageRoleError, B as setAbortTimeout, Bt as InvalidToolApprovalError, C as resolveToolApproval, Ct as asLanguageModelV4, D as convertToReasoningOutputs, Dt as logWarnings, E as DefaultGenerateTextResult, Et as createLogWarnings, F as resolveGeneratedFileData, Ft as NoOutputGeneratedError, G as addLanguageModelUsage, H as mergeAbortSignals, I as DefaultGeneratedFile, It as MissingToolResultsError, J as standardizePrompt, K as asLanguageModelUsage, L as DefaultGeneratedFileWithType, Lt as ToolCallNotFoundForApprovalError, M as prepareToolsForToolCallers, Mt as UnsupportedModelVersionError, N as resolveToolCallerConfiguration, Nt as ToolCallRepairError, O as validateToolContext, Ot as notify, P as convertLanguageModelContent, Pt as NoSuchToolError, Q as createToolModelOutput, R as collectToolApprovals, Rt as InvalidToolInputError, S as filterIncludedContext, St as asVideoModelV4, T as getToolCallInputSchemaInput, Tt as asEmbeddingModelV4, U as getOwn, V as prepareRetries, Vt as InvalidArgumentError, W as addImageModelUsage, X as prepareToolChoice, Y as prepareTools, Z as prepareLanguageModelCallOptions, _ as createTelemetryDispatcher, _t as resolveSpeechModel, a as createAsyncIterableStream, at as convertDataContentToUint8Array, b as AI_SDK_TELEMETRY_TRACING_CHANNEL, bt as resolveVideoModel, c as validateApprovedToolApprovals, ct as download, dt as resolveDecisionModel, f as hashCanonical, ft as resolveEmbeddingModel, g as DefaultStepResult, gt as resolveRerankingModel, h as createRestrictedTelemetryDispatcher$4, ht as resolveLanguageModel, i as asAsyncIterableStream, it as convertDataContentToBase64String, j as appendToolCallerMessages, jt as InvalidDataContentError, k as createToolSearchState, kt as RetryError, l as maybeSignApproval, lt as VERSION, m as isDeepEqualData, mt as resolveImageModel, nt as convertToLanguageModelV4FilePart, o as mapWithConcurrency, ot as mergeObjects, p as toResponseMessages, pt as resolveExtractionModel, q as createNullLanguageModelUsage, r as isOutputChunk$1, rt as splitDataUrl, s as prepareToolCallConcurrency, t as createDefaultStopCondition, ut as asEvaluationModel, v as getGlobalTelemetryIntegrations, vt as resolveSpeechTranslationModel, w as parseToolCall, wt as asImageModelV4, x as mergeCallbacks, xt as asProviderV4, y as registerTelemetry, yt as resolveTranscriptionModel, z as calculateTokensPerSecond, zt as InvalidToolApprovalSignatureError } from "./default-stop-condition-CKhd4H3S.js";
|
|
3
3
|
import { t as simulateReadableStream } from "./simulate-readable-stream-Bi5kQKbv.js";
|
|
4
4
|
import { GatewayAuthenticationError, createGateway, gateway, gateway as gateway$1 } from "@ai-sdk/gateway";
|
|
5
5
|
import { DelayedPromise, DownloadError, DownloadError as DownloadError$1, EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL, EXPERIMENTAL_EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER, asArray, asSchema, asSchema as asSchema$1, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertUint8ArrayToBase64, createIdGenerator, createIdGenerator as createIdGenerator$1, delay, detectMediaType, dynamicTool, executeTool, experimental_toolCaller, filterNullable, generateId, generateId as generateId$1, getErrorMessage, getRuntimeEnvironmentUserAgent, getTopLevelMediaType, getWebSocketConstructor, isAbortError, isArrayBuffer, isBuffer, isExecutableTool, isFullMediaType, isNonNullable, isProviderReference, isProviderStreamError, isUint8Array, jsonSchema, lazySchema, normalizeHeaders, parseJsonEventStream, parseJsonEventStream as parseJsonEventStream$1, readWebSocketMessageText, resolve, safeParseJSON, safeValidateTypes, toWebSocketUrl, tool, validateTypes, waitForWebSocketBufferDrain, withUserAgentSuffix, zodSchema, zodSchema as zodSchema$1 } from "@ai-sdk/provider-utils";
|
|
@@ -14196,8 +14196,7 @@ var BrowserRealtimeAudio = class {
|
|
|
14196
14196
|
this.playbackContext = null;
|
|
14197
14197
|
this.playbackQueue = [];
|
|
14198
14198
|
this.playbackTime = 0;
|
|
14199
|
-
this.
|
|
14200
|
-
this.activeSources = /* @__PURE__ */ new Set();
|
|
14199
|
+
this.activeSources = /* @__PURE__ */ new Map();
|
|
14201
14200
|
this.isPlaying = false;
|
|
14202
14201
|
this.playbackPaused = false;
|
|
14203
14202
|
this.captureSampleRate = options.captureSampleRate;
|
|
@@ -14283,7 +14282,7 @@ var BrowserRealtimeAudio = class {
|
|
|
14283
14282
|
this.captureStream = null;
|
|
14284
14283
|
this.onCapturingChange(false);
|
|
14285
14284
|
}
|
|
14286
|
-
playAudio(base64Audio) {
|
|
14285
|
+
playAudio(base64Audio, itemId) {
|
|
14287
14286
|
if (this.playbackPaused) return;
|
|
14288
14287
|
this.ensurePlaybackContext();
|
|
14289
14288
|
const samples = decodeRealtimeAudio(base64Audio);
|
|
@@ -14293,12 +14292,15 @@ var BrowserRealtimeAudio = class {
|
|
|
14293
14292
|
this.onError?.(/* @__PURE__ */ new Error("Realtime audio playback buffer is full; playback paused, call resumePlayback() to resume at the live edge"));
|
|
14294
14293
|
return;
|
|
14295
14294
|
}
|
|
14296
|
-
this.playbackQueue.push(
|
|
14295
|
+
this.playbackQueue.push({
|
|
14296
|
+
samples,
|
|
14297
|
+
itemId
|
|
14298
|
+
});
|
|
14297
14299
|
this.schedulePlayback();
|
|
14298
14300
|
}
|
|
14299
14301
|
stopPlayback() {
|
|
14300
14302
|
this.playbackQueue = [];
|
|
14301
|
-
for (const source of this.activeSources) try {
|
|
14303
|
+
for (const source of this.activeSources.keys()) try {
|
|
14302
14304
|
source.onended = null;
|
|
14303
14305
|
source.stop();
|
|
14304
14306
|
source.disconnect();
|
|
@@ -14307,10 +14309,30 @@ var BrowserRealtimeAudio = class {
|
|
|
14307
14309
|
if (this.playbackContext != null) this.playbackTime = this.playbackContext.currentTime;
|
|
14308
14310
|
this.setPlaying(false);
|
|
14309
14311
|
}
|
|
14310
|
-
|
|
14312
|
+
/**
|
|
14313
|
+
* The item the user is currently hearing and how far into that item
|
|
14314
|
+
* playback is, in whole milliseconds. Queued items play back to back, so
|
|
14315
|
+
* this is resolved from the scheduled chunk under the playback clock, not
|
|
14316
|
+
* from the most recently received item.
|
|
14317
|
+
*/
|
|
14318
|
+
getPlaybackPosition() {
|
|
14311
14319
|
const ctx = this.playbackContext;
|
|
14312
|
-
if (ctx == null) return 0;
|
|
14313
|
-
|
|
14320
|
+
if (ctx == null) return void 0;
|
|
14321
|
+
const now = ctx.currentTime;
|
|
14322
|
+
let current;
|
|
14323
|
+
for (const playback of this.activeSources.values()) {
|
|
14324
|
+
if (current != null && playback.startTime > now) break;
|
|
14325
|
+
current = playback;
|
|
14326
|
+
}
|
|
14327
|
+
if (current?.itemId == null) return void 0;
|
|
14328
|
+
const rate = this.playbackSampleRate;
|
|
14329
|
+
const played = Math.min(Math.max(now - current.startTime, 0), current.sampleCount / rate);
|
|
14330
|
+
const heardMs = Math.round((current.itemOffset / rate + played) * 1e3);
|
|
14331
|
+
const scheduledMs = Math.floor((current.itemOffset + current.sampleCount) * 1e3 / rate);
|
|
14332
|
+
return {
|
|
14333
|
+
itemId: current.itemId,
|
|
14334
|
+
audioEndMs: Math.min(heardMs, scheduledMs)
|
|
14335
|
+
};
|
|
14314
14336
|
}
|
|
14315
14337
|
dispose() {
|
|
14316
14338
|
this.stopCapture();
|
|
@@ -14319,10 +14341,10 @@ var BrowserRealtimeAudio = class {
|
|
|
14319
14341
|
this.playbackContext?.close().catch(() => {});
|
|
14320
14342
|
this.playbackContext = null;
|
|
14321
14343
|
this.playbackTime = 0;
|
|
14344
|
+
this.scheduledItem = void 0;
|
|
14322
14345
|
this.playbackPaused = false;
|
|
14323
14346
|
}
|
|
14324
14347
|
setPlaying(isPlaying) {
|
|
14325
|
-
if (isPlaying && !this.isPlaying) this.playbackStartTime = this.playbackContext?.currentTime ?? 0;
|
|
14326
14348
|
if (this.isPlaying !== isPlaying) {
|
|
14327
14349
|
this.isPlaying = isPlaying;
|
|
14328
14350
|
this.onPlayingChange(isPlaying);
|
|
@@ -14332,7 +14354,7 @@ var BrowserRealtimeAudio = class {
|
|
|
14332
14354
|
const ctx = this.playbackContext;
|
|
14333
14355
|
if (ctx == null || this.playbackQueue.length === 0) return;
|
|
14334
14356
|
while (this.playbackQueue.length > 0) {
|
|
14335
|
-
const samples = this.playbackQueue.shift();
|
|
14357
|
+
const { samples, itemId } = this.playbackQueue.shift();
|
|
14336
14358
|
const buffer = ctx.createBuffer(1, samples.length, this.playbackSampleRate);
|
|
14337
14359
|
buffer.getChannelData(0).set(samples);
|
|
14338
14360
|
const source = ctx.createBufferSource();
|
|
@@ -14341,14 +14363,24 @@ var BrowserRealtimeAudio = class {
|
|
|
14341
14363
|
const startTime = Math.max(this.playbackTime, ctx.currentTime);
|
|
14342
14364
|
source.start(startTime);
|
|
14343
14365
|
this.playbackTime = startTime + buffer.duration;
|
|
14344
|
-
this.
|
|
14345
|
-
this.
|
|
14346
|
-
|
|
14366
|
+
const itemOffset = itemId != null && this.scheduledItem?.id === itemId ? this.scheduledItem.samples : 0;
|
|
14367
|
+
if (itemId != null) this.scheduledItem = {
|
|
14368
|
+
id: itemId,
|
|
14369
|
+
samples: itemOffset + samples.length
|
|
14370
|
+
};
|
|
14371
|
+
this.activeSources.set(source, {
|
|
14372
|
+
itemId,
|
|
14373
|
+
startTime,
|
|
14374
|
+
sampleCount: samples.length,
|
|
14375
|
+
itemOffset
|
|
14376
|
+
});
|
|
14347
14377
|
source.onended = () => {
|
|
14348
14378
|
source.disconnect();
|
|
14349
14379
|
this.activeSources.delete(source);
|
|
14350
14380
|
if (this.playbackQueue.length === 0 && this.activeSources.size === 0) this.setPlaying(false);
|
|
14351
14381
|
};
|
|
14382
|
+
this.setPlaying(ctx.state === "running");
|
|
14383
|
+
if (this.playbackContext !== ctx) return;
|
|
14352
14384
|
}
|
|
14353
14385
|
}
|
|
14354
14386
|
};
|
|
@@ -15792,7 +15824,6 @@ var AbstractRealtimeSession = class {
|
|
|
15792
15824
|
this.publication = 0;
|
|
15793
15825
|
this.captureGeneration = 0;
|
|
15794
15826
|
this.captureRequested = false;
|
|
15795
|
-
this.currentResponseItemId = null;
|
|
15796
15827
|
this.toolCallsInResponse = /* @__PURE__ */ new Set();
|
|
15797
15828
|
this.submittedToolOutputs = /* @__PURE__ */ new Set();
|
|
15798
15829
|
this.responseToolCallsClosed = false;
|
|
@@ -15850,7 +15881,6 @@ var AbstractRealtimeSession = class {
|
|
|
15850
15881
|
}
|
|
15851
15882
|
if (!current()) return;
|
|
15852
15883
|
this.reducer = new RealtimeEventReducer(this.maxEvents);
|
|
15853
|
-
this.currentResponseItemId = null;
|
|
15854
15884
|
this.toolCallsInResponse.clear();
|
|
15855
15885
|
this.submittedToolOutputs.clear();
|
|
15856
15886
|
this.responseToolCallsClosed = false;
|
|
@@ -16439,20 +16469,18 @@ var AbstractRealtimeSession = class {
|
|
|
16439
16469
|
handleReducerEffect(effect, attempt) {
|
|
16440
16470
|
switch (effect.type) {
|
|
16441
16471
|
case "play-audio":
|
|
16442
|
-
this.
|
|
16443
|
-
this.audio?.playAudio(effect.delta);
|
|
16472
|
+
this.audio?.playAudio(effect.delta, effect.itemId);
|
|
16444
16473
|
break;
|
|
16445
16474
|
case "speech-started":
|
|
16446
16475
|
if (!this.continuous && this.state.isPlaying) {
|
|
16447
|
-
const
|
|
16448
|
-
const itemId = this.currentResponseItemId;
|
|
16476
|
+
const position = this.audio?.getPlaybackPosition();
|
|
16449
16477
|
this.audio?.stopPlayback();
|
|
16450
16478
|
if (this.attempt !== attempt || !attempt.active) return;
|
|
16451
|
-
if (
|
|
16479
|
+
if (position != null && !attempt.closing && attempt.cause == null) this.sendEvent({
|
|
16452
16480
|
type: "conversation-item-truncate",
|
|
16453
|
-
itemId,
|
|
16481
|
+
itemId: position.itemId,
|
|
16454
16482
|
contentIndex: 0,
|
|
16455
|
-
audioEndMs:
|
|
16483
|
+
audioEndMs: position.audioEndMs
|
|
16456
16484
|
});
|
|
16457
16485
|
}
|
|
16458
16486
|
break;
|