ai 7.0.127 → 7.0.129
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 +53 -0
- package/dist/index.d.ts +230 -155
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +386 -209
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +288 -70
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +407 -76
- package/dist/internal/index.js.map +1 -1
- package/dist/test/index.d.ts +25 -17
- package/dist/test/index.d.ts.map +1 -1
- package/dist/test/index.js +27 -21
- package/dist/test/index.js.map +1 -1
- package/docs/02-foundations/06-provider-options.mdx +11 -10
- package/docs/02-getting-started/03-nextjs-pages-router.mdx +1 -1
- package/docs/02-getting-started/07-expo.mdx +1 -1
- package/docs/03-agents/02-building-agents.mdx +16 -11
- package/docs/03-agents/07-workflow-agent.mdx +83 -15
- package/docs/03-ai-sdk-core/16-mcp-tools.mdx +44 -0
- package/docs/03-ai-sdk-core/17-runtime-and-tool-context.mdx +18 -14
- package/docs/03-ai-sdk-core/25-settings.mdx +3 -2
- package/docs/03-ai-sdk-core/26-reasoning.mdx +12 -5
- package/docs/03-ai-sdk-core/{32-evaluation.mdx → 32-decisions.mdx} +64 -67
- package/docs/03-ai-sdk-core/35-image-generation.mdx +3 -1
- package/docs/03-ai-sdk-core/45-provider-management.mdx +8 -8
- package/docs/03-ai-sdk-core/60-telemetry.mdx +40 -31
- package/docs/03-ai-sdk-core/65-lifecycle-callbacks.mdx +21 -22
- package/docs/03-ai-sdk-harnesses/08-terminal-ui.mdx +2 -2
- package/docs/04-ai-sdk-ui/21-error-handling.mdx +28 -3
- package/docs/06-advanced/09-multistep-interfaces.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/01-generate-text.mdx +2 -2
- package/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx +2 -2
- package/docs/07-reference/01-ai-sdk-core/14-decide.mdx +74 -0
- package/docs/07-reference/01-ai-sdk-core/23-create-mcp-client.mdx +58 -4
- package/docs/07-reference/01-ai-sdk-core/40-provider-registry.mdx +11 -11
- package/docs/07-reference/01-ai-sdk-core/42-custom-provider.mdx +9 -9
- package/docs/07-reference/01-ai-sdk-core/66-extract-reasoning-middleware.mdx +24 -8
- package/docs/07-reference/02-ai-sdk-ui/32-prune-messages.mdx +1 -1
- package/docs/07-reference/03-ai-sdk-rsc/01-stream-ui.mdx +1 -0
- package/docs/07-reference/04-ai-sdk-workflow/01-workflow-agent.mdx +39 -2
- package/docs/07-reference/05-ai-sdk-errors/ai-decision-unsupported-question-type-error.mdx +31 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-no-such-model-error.mdx +3 -3
- package/docs/07-reference/05-ai-sdk-errors/ai-no-such-provider-error.mdx +3 -3
- package/docs/08-migration-guides/23-migration-guide-7-0.mdx +1 -1
- package/docs/08-migration-guides/29-migration-guide-4-0.mdx +1 -1
- package/docs/09-troubleshooting/05-tool-invocation-missing-result.mdx +2 -2
- package/package.json +15 -15
- package/src/decide/decide-events.ts +129 -0
- package/src/{evaluate/evaluate.ts → decide/decide.ts} +36 -38
- package/src/decide/decision-provider.ts +11 -0
- package/src/decide/decision-result.ts +39 -0
- package/src/decide/index.ts +64 -0
- package/src/{evaluate → decide}/restricted-telemetry-dispatcher.ts +7 -7
- package/src/{evaluate/validate-evaluation.ts → decide/validate-decision.ts} +9 -9
- package/src/error/index.ts +10 -1
- package/src/generate-object/generate-object.ts +10 -0
- package/src/generate-object/stream-object.ts +10 -0
- package/src/generate-speech/generated-audio-file.ts +5 -4
- package/src/generate-speech/index.ts +13 -1
- package/src/generate-text/default-generate-text-result.ts +127 -0
- package/src/generate-text/generate-text.ts +5 -123
- package/src/generate-text/tool-approval-signature.ts +7 -4
- package/src/global.ts +3 -2
- package/src/index.ts +1 -1
- package/src/logger/deprecations.ts +72 -0
- package/src/logger/log-warnings.ts +25 -3
- package/src/middleware/extract-reasoning-middleware.ts +25 -6
- package/src/model/as-language-model-v3.ts +4 -0
- package/src/model/resolve-model.ts +45 -14
- package/src/prompt/convert-to-language-model-prompt.ts +7 -1
- package/src/realtime/encode-realtime-frame.ts +7 -2
- package/src/registry/custom-provider.ts +38 -26
- package/src/registry/index.ts +13 -1
- package/src/registry/no-such-provider-error.ts +2 -0
- package/src/registry/provider-registry.ts +56 -29
- package/src/telemetry/create-telemetry-dispatcher.ts +17 -5
- package/src/telemetry/telemetry.ts +35 -19
- package/src/telemetry/tracing-channel.ts +1 -1
- package/src/test/decision-mock-model-v4.ts +35 -0
- package/src/transcribe/index.ts +13 -1
- package/src/transcribe/transcribe.ts +1 -1
- package/src/types/index.ts +1 -0
- package/src/types/language-model.ts +9 -1
- package/src/types/usage.ts +21 -0
- package/src/ui/chat.ts +25 -9
- package/src/ui/convert-to-model-messages.ts +40 -8
- package/src/ui/http-chat-transport.ts +5 -3
- package/src/ui/process-text-stream.ts +5 -1
- package/src/ui/process-ui-message-stream.ts +21 -0
- package/src/ui/text-stream-chat-transport.ts +3 -1
- package/src/ui/ui-messages.ts +8 -0
- package/src/ui/unavailable-tool.ts +17 -0
- package/src/ui/validate-ui-messages.ts +10 -2
- package/docs/07-reference/01-ai-sdk-core/14-evaluate.mdx +0 -74
- package/docs/07-reference/05-ai-sdk-errors/ai-evaluation-unsupported-question-type-error.mdx +0 -31
- package/src/evaluate/evaluate-events.ts +0 -131
- package/src/evaluate/evaluation-provider.ts +0 -6
- package/src/evaluate/evaluation-result.ts +0 -39
- package/src/evaluate/index.ts +0 -13
- package/src/test/evaluation-mock-model-v4.ts +0 -27
package/dist/internal/index.js
CHANGED
|
@@ -111,7 +111,7 @@ function asAsyncIterableStream(stream) {
|
|
|
111
111
|
}
|
|
112
112
|
//#endregion
|
|
113
113
|
//#region src/version.ts
|
|
114
|
-
const VERSION = "7.0.
|
|
114
|
+
const VERSION = "7.0.129";
|
|
115
115
|
//#endregion
|
|
116
116
|
//#region src/util/download/download.ts
|
|
117
117
|
/**
|
|
@@ -203,21 +203,21 @@ function mergeObjects(base, overrides) {
|
|
|
203
203
|
}
|
|
204
204
|
//#endregion
|
|
205
205
|
//#region src/prompt/invalid-data-content-error.ts
|
|
206
|
-
const name$
|
|
207
|
-
const marker$
|
|
208
|
-
const symbol$
|
|
206
|
+
const name$11 = "AI_InvalidDataContentError";
|
|
207
|
+
const marker$11 = `vercel.ai.error.${name$11}`;
|
|
208
|
+
const symbol$11 = Symbol.for(marker$11);
|
|
209
209
|
var InvalidDataContentError = class extends AISDKError {
|
|
210
210
|
constructor({ content, cause, message = `Invalid data content. Expected a base64 string, Uint8Array, ArrayBuffer, or Buffer, but got ${typeof content}.` }) {
|
|
211
211
|
super({
|
|
212
|
-
name: name$
|
|
212
|
+
name: name$11,
|
|
213
213
|
message,
|
|
214
214
|
cause
|
|
215
215
|
});
|
|
216
|
-
this[symbol$
|
|
216
|
+
this[symbol$11] = true;
|
|
217
217
|
this.content = content;
|
|
218
218
|
}
|
|
219
219
|
static isInstance(error) {
|
|
220
|
-
return AISDKError.hasMarker(error, marker$
|
|
220
|
+
return AISDKError.hasMarker(error, marker$11);
|
|
221
221
|
}
|
|
222
222
|
};
|
|
223
223
|
//#endregion
|
|
@@ -349,6 +349,35 @@ function convertToLanguageModelV4FilePart(content) {
|
|
|
349
349
|
return convertInlineDataToFilePartData(content);
|
|
350
350
|
}
|
|
351
351
|
//#endregion
|
|
352
|
+
//#region src/logger/deprecations.ts
|
|
353
|
+
const deprecationCodes = /* @__PURE__ */ new Map([
|
|
354
|
+
["generateObject", "AISDK_DEP_GENERATE_OBJECT"],
|
|
355
|
+
["streamObject", "AISDK_DEP_STREAM_OBJECT"],
|
|
356
|
+
["experimental_generateSpeech", "AISDK_DEP_EXPERIMENTAL_GENERATE_SPEECH"],
|
|
357
|
+
["experimental_transcribe", "AISDK_DEP_EXPERIMENTAL_TRANSCRIBE"],
|
|
358
|
+
["\"image\" content part", "AISDK_DEP_IMAGE_CONTENT_PART"],
|
|
359
|
+
["\"tool-result\" content of type \"file-data\"", "AISDK_DEP_TOOL_RESULT_FILE_DATA"],
|
|
360
|
+
["\"tool-result\" content of type \"file-url\"", "AISDK_DEP_TOOL_RESULT_FILE_URL"],
|
|
361
|
+
["\"tool-result\" content of type \"file-id\"", "AISDK_DEP_TOOL_RESULT_FILE_ID"],
|
|
362
|
+
["\"tool-result\" content of type \"file-reference\"", "AISDK_DEP_TOOL_RESULT_FILE_REFERENCE"],
|
|
363
|
+
["\"tool-result\" content of type \"image-data\"", "AISDK_DEP_TOOL_RESULT_IMAGE_DATA"],
|
|
364
|
+
["\"tool-result\" content of type \"image-url\"", "AISDK_DEP_TOOL_RESULT_IMAGE_URL"],
|
|
365
|
+
["\"tool-result\" content of type \"image-file-id\"", "AISDK_DEP_TOOL_RESULT_IMAGE_FILE_ID"],
|
|
366
|
+
["\"tool-result\" content of type \"image-file-reference\"", "AISDK_DEP_TOOL_RESULT_IMAGE_FILE_REFERENCE"],
|
|
367
|
+
["rawInput in output-error UI message parts", "AISDK_DEP_UI_MESSAGE_RAW_INPUT"]
|
|
368
|
+
]);
|
|
369
|
+
/**
|
|
370
|
+
* Escape punctuation and UTF-16 code units without losing case or collapsing
|
|
371
|
+
* distinct settings. Underscores are escaped too, so `__` separates code parts.
|
|
372
|
+
*/
|
|
373
|
+
function encodeCodePart(value) {
|
|
374
|
+
return value.replace(/[^a-zA-Z0-9]/g, (character) => `_${character.charCodeAt(0).toString(16).toUpperCase().padStart(4, "0")}`);
|
|
375
|
+
}
|
|
376
|
+
function getDeprecationCode({ setting, provider }) {
|
|
377
|
+
if (provider == null) return deprecationCodes.get(setting) ?? `AISDK_DEP_SETTING_${encodeCodePart(setting)}`;
|
|
378
|
+
return `AISDK_DEP_PROVIDER_${encodeCodePart(provider)}__${encodeCodePart(setting)}`;
|
|
379
|
+
}
|
|
380
|
+
//#endregion
|
|
352
381
|
//#region src/logger/log-warnings.ts
|
|
353
382
|
/**
|
|
354
383
|
* Formats a warning object into a human-readable string with clear AI SDK branding.
|
|
@@ -379,9 +408,13 @@ function formatWarning({ warning, provider, model }) {
|
|
|
379
408
|
}
|
|
380
409
|
const FIRST_WARNING_INFO_MESSAGE = "AI SDK Warning System: To turn off warning logging, set the AI_SDK_LOG_WARNINGS global to false.";
|
|
381
410
|
let hasLoggedBefore = false;
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
411
|
+
const emittedDeprecationCodes = /* @__PURE__ */ new Set();
|
|
412
|
+
function emitWarning({ message, type, code }) {
|
|
413
|
+
if (typeof process !== "undefined" && typeof process.emitWarning === "function") process.emitWarning(message, code == null ? { type } : {
|
|
414
|
+
type,
|
|
415
|
+
code
|
|
416
|
+
});
|
|
417
|
+
else console.warn(code == null ? message : `[${code}] ${message}`);
|
|
385
418
|
}
|
|
386
419
|
/**
|
|
387
420
|
* Logs warnings to the console or uses a custom logger if configured.
|
|
@@ -389,7 +422,9 @@ function emitWarning({ message, type }) {
|
|
|
389
422
|
* The behavior can be customized via the `AI_SDK_LOG_WARNINGS` global variable:
|
|
390
423
|
* - If set to `false`, warnings are suppressed.
|
|
391
424
|
* - If set to a function, that function is called with the warnings.
|
|
392
|
-
* - Otherwise, warnings
|
|
425
|
+
* - Otherwise, warnings use `process.emitWarning` when available, falling back
|
|
426
|
+
* to `console.warn`. Deprecations have stable codes and are emitted once per
|
|
427
|
+
* code by the default logger. Custom loggers receive every warning.
|
|
393
428
|
*
|
|
394
429
|
* @param options - The options containing warnings and context.
|
|
395
430
|
* @param options.warnings - The warnings to log.
|
|
@@ -411,49 +446,60 @@ const logWarnings = (options) => {
|
|
|
411
446
|
type: "Warning"
|
|
412
447
|
});
|
|
413
448
|
}
|
|
414
|
-
for (const warning of options.warnings)
|
|
415
|
-
|
|
416
|
-
warning,
|
|
417
|
-
provider: options.provider
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
449
|
+
for (const warning of options.warnings) {
|
|
450
|
+
const code = warning.type === "deprecated" ? getDeprecationCode({
|
|
451
|
+
setting: warning.setting,
|
|
452
|
+
provider: options.provider
|
|
453
|
+
}) : void 0;
|
|
454
|
+
if (code != null) {
|
|
455
|
+
if (emittedDeprecationCodes.has(code)) continue;
|
|
456
|
+
emittedDeprecationCodes.add(code);
|
|
457
|
+
}
|
|
458
|
+
emitWarning({
|
|
459
|
+
message: formatWarning({
|
|
460
|
+
warning,
|
|
461
|
+
provider: options.provider,
|
|
462
|
+
model: options.model
|
|
463
|
+
}),
|
|
464
|
+
type: warning.type === "deprecated" ? "DeprecationWarning" : "Warning",
|
|
465
|
+
code
|
|
466
|
+
});
|
|
467
|
+
}
|
|
422
468
|
};
|
|
423
469
|
//#endregion
|
|
424
470
|
//#region src/prompt/invalid-message-role-error.ts
|
|
425
|
-
const name$
|
|
426
|
-
const marker$
|
|
427
|
-
const symbol$
|
|
471
|
+
const name$10 = "AI_InvalidMessageRoleError";
|
|
472
|
+
const marker$10 = `vercel.ai.error.${name$10}`;
|
|
473
|
+
const symbol$10 = Symbol.for(marker$10);
|
|
428
474
|
var InvalidMessageRoleError = class extends AISDKError {
|
|
429
475
|
constructor({ role, message = `Invalid message role: '${role}'. Must be one of: "system", "user", "assistant", "tool".` }) {
|
|
430
476
|
super({
|
|
431
|
-
name: name$
|
|
477
|
+
name: name$10,
|
|
432
478
|
message
|
|
433
479
|
});
|
|
434
|
-
this[symbol$
|
|
480
|
+
this[symbol$10] = true;
|
|
435
481
|
this.role = role;
|
|
436
482
|
}
|
|
437
483
|
static isInstance(error) {
|
|
438
|
-
return AISDKError.hasMarker(error, marker$
|
|
484
|
+
return AISDKError.hasMarker(error, marker$10);
|
|
439
485
|
}
|
|
440
486
|
};
|
|
441
487
|
//#endregion
|
|
442
488
|
//#region src/error/missing-tool-result-error.ts
|
|
443
|
-
const name$
|
|
444
|
-
const marker$
|
|
445
|
-
const symbol$
|
|
489
|
+
const name$9 = "AI_MissingToolResultsError";
|
|
490
|
+
const marker$9 = `vercel.ai.error.${name$9}`;
|
|
491
|
+
const symbol$9 = Symbol.for(marker$9);
|
|
446
492
|
var MissingToolResultsError = class extends AISDKError {
|
|
447
493
|
constructor({ toolCallIds }) {
|
|
448
494
|
super({
|
|
449
|
-
name: name$
|
|
495
|
+
name: name$9,
|
|
450
496
|
message: `Tool result${toolCallIds.length > 1 ? "s are" : " is"} missing for tool call${toolCallIds.length > 1 ? "s" : ""} ${toolCallIds.join(", ")}.`
|
|
451
497
|
});
|
|
452
|
-
this[symbol$
|
|
498
|
+
this[symbol$9] = true;
|
|
453
499
|
this.toolCallIds = toolCallIds;
|
|
454
500
|
}
|
|
455
501
|
static isInstance(error) {
|
|
456
|
-
return AISDKError.hasMarker(error, marker$
|
|
502
|
+
return AISDKError.hasMarker(error, marker$9);
|
|
457
503
|
}
|
|
458
504
|
};
|
|
459
505
|
//#endregion
|
|
@@ -494,7 +540,7 @@ async function convertToLanguageModelPrompt({ prompt, supportedUrls, download, a
|
|
|
494
540
|
const lastContentPart = lastCombinedMessage.content.at(-1);
|
|
495
541
|
if (lastContentPart != null && lastCombinedMessage.providerOptions != null) lastContentPart.providerOptions = mergeObjects(lastCombinedMessage.providerOptions, lastContentPart.providerOptions);
|
|
496
542
|
lastCombinedMessage.content.push(...message.content);
|
|
497
|
-
lastCombinedMessage.providerOptions = message.providerOptions;
|
|
543
|
+
lastCombinedMessage.providerOptions = lastContentPart == null ? mergeObjects(lastCombinedMessage.providerOptions, message.providerOptions) : message.providerOptions;
|
|
498
544
|
} else combinedMessages.push(message);
|
|
499
545
|
}
|
|
500
546
|
const toolCallIds = /* @__PURE__ */ new Set();
|
|
@@ -1432,21 +1478,21 @@ async function standardizePrompt({ allowSystemInMessages = false, system, instru
|
|
|
1432
1478
|
}
|
|
1433
1479
|
//#endregion
|
|
1434
1480
|
//#region src/error/invalid-argument-error.ts
|
|
1435
|
-
const name$
|
|
1436
|
-
const marker$
|
|
1437
|
-
const symbol$
|
|
1481
|
+
const name$8 = "AI_InvalidArgumentError";
|
|
1482
|
+
const marker$8 = `vercel.ai.error.${name$8}`;
|
|
1483
|
+
const symbol$8 = Symbol.for(marker$8);
|
|
1438
1484
|
var InvalidArgumentError = class extends AISDKError {
|
|
1439
1485
|
constructor({ parameter, value, message }) {
|
|
1440
1486
|
super({
|
|
1441
|
-
name: name$
|
|
1487
|
+
name: name$8,
|
|
1442
1488
|
message: `Invalid argument for parameter ${parameter}: ${message}`
|
|
1443
1489
|
});
|
|
1444
|
-
this[symbol$
|
|
1490
|
+
this[symbol$8] = true;
|
|
1445
1491
|
this.parameter = parameter;
|
|
1446
1492
|
this.value = value;
|
|
1447
1493
|
}
|
|
1448
1494
|
static isInstance(error) {
|
|
1449
|
-
return AISDKError.hasMarker(error, marker$
|
|
1495
|
+
return AISDKError.hasMarker(error, marker$8);
|
|
1450
1496
|
}
|
|
1451
1497
|
};
|
|
1452
1498
|
//#endregion
|
|
@@ -1523,22 +1569,22 @@ function prepareLanguageModelCallOptions({ maxOutputTokens, temperature, topP, t
|
|
|
1523
1569
|
}
|
|
1524
1570
|
//#endregion
|
|
1525
1571
|
//#region src/util/retry-error.ts
|
|
1526
|
-
const name$
|
|
1527
|
-
const marker$
|
|
1528
|
-
const symbol$
|
|
1572
|
+
const name$7 = "AI_RetryError";
|
|
1573
|
+
const marker$7 = `vercel.ai.error.${name$7}`;
|
|
1574
|
+
const symbol$7 = Symbol.for(marker$7);
|
|
1529
1575
|
var RetryError = class extends AISDKError {
|
|
1530
1576
|
constructor({ message, reason, errors }) {
|
|
1531
1577
|
super({
|
|
1532
|
-
name: name$
|
|
1578
|
+
name: name$7,
|
|
1533
1579
|
message
|
|
1534
1580
|
});
|
|
1535
|
-
this[symbol$
|
|
1581
|
+
this[symbol$7] = true;
|
|
1536
1582
|
this.reason = reason;
|
|
1537
1583
|
this.errors = errors;
|
|
1538
1584
|
this.lastError = errors[errors.length - 1];
|
|
1539
1585
|
}
|
|
1540
1586
|
static isInstance(error) {
|
|
1541
|
-
return AISDKError.hasMarker(error, marker$
|
|
1587
|
+
return AISDKError.hasMarker(error, marker$7);
|
|
1542
1588
|
}
|
|
1543
1589
|
};
|
|
1544
1590
|
//#endregion
|
|
@@ -1647,6 +1693,7 @@ function createNullLanguageModelUsage() {
|
|
|
1647
1693
|
};
|
|
1648
1694
|
}
|
|
1649
1695
|
function addLanguageModelUsage(usage1, usage2) {
|
|
1696
|
+
const raw = isNullLanguageModelUsage(usage1) ? usage2.raw : isNullLanguageModelUsage(usage2) ? usage1.raw : void 0;
|
|
1650
1697
|
return {
|
|
1651
1698
|
inputTokens: addTokenCounts(usage1.inputTokens, usage2.inputTokens),
|
|
1652
1699
|
inputTokenDetails: {
|
|
@@ -1659,84 +1706,109 @@ function addLanguageModelUsage(usage1, usage2) {
|
|
|
1659
1706
|
textTokens: addTokenCounts(usage1.outputTokenDetails?.textTokens, usage2.outputTokenDetails?.textTokens),
|
|
1660
1707
|
reasoningTokens: addTokenCounts(usage1.outputTokenDetails?.reasoningTokens, usage2.outputTokenDetails?.reasoningTokens)
|
|
1661
1708
|
},
|
|
1662
|
-
totalTokens: addTokenCounts(usage1.totalTokens, usage2.totalTokens)
|
|
1709
|
+
totalTokens: addTokenCounts(usage1.totalTokens, usage2.totalTokens),
|
|
1710
|
+
...raw == null ? {} : { raw }
|
|
1663
1711
|
};
|
|
1664
1712
|
}
|
|
1713
|
+
function isNullLanguageModelUsage(usage) {
|
|
1714
|
+
return usage.inputTokens == null && usage.inputTokenDetails?.noCacheTokens == null && usage.inputTokenDetails?.cacheReadTokens == null && usage.inputTokenDetails?.cacheWriteTokens == null && usage.outputTokens == null && usage.outputTokenDetails?.textTokens == null && usage.outputTokenDetails?.reasoningTokens == null && usage.totalTokens == null && usage.raw == null;
|
|
1715
|
+
}
|
|
1665
1716
|
function addTokenCounts(tokenCount1, tokenCount2) {
|
|
1666
1717
|
return tokenCount1 == null && tokenCount2 == null ? void 0 : (tokenCount1 ?? 0) + (tokenCount2 ?? 0);
|
|
1667
1718
|
}
|
|
1668
1719
|
//#endregion
|
|
1669
1720
|
//#region src/error/invalid-tool-approval-error.ts
|
|
1670
|
-
const name$
|
|
1671
|
-
const marker$
|
|
1672
|
-
const symbol$
|
|
1721
|
+
const name$6 = "AI_InvalidToolApprovalError";
|
|
1722
|
+
const marker$6 = `vercel.ai.error.${name$6}`;
|
|
1723
|
+
const symbol$6 = Symbol.for(marker$6);
|
|
1673
1724
|
var InvalidToolApprovalError = class extends AISDKError {
|
|
1674
1725
|
constructor({ approvalId }) {
|
|
1675
1726
|
super({
|
|
1676
|
-
name: name$
|
|
1727
|
+
name: name$6,
|
|
1677
1728
|
message: `Tool approval response references unknown approvalId: "${approvalId}". No matching tool-approval-request found in message history.`
|
|
1678
1729
|
});
|
|
1679
|
-
this[symbol$
|
|
1730
|
+
this[symbol$6] = true;
|
|
1680
1731
|
this.approvalId = approvalId;
|
|
1681
1732
|
}
|
|
1682
1733
|
static isInstance(error) {
|
|
1683
|
-
return AISDKError.hasMarker(error, marker$
|
|
1734
|
+
return AISDKError.hasMarker(error, marker$6);
|
|
1684
1735
|
}
|
|
1685
1736
|
};
|
|
1686
1737
|
//#endregion
|
|
1687
1738
|
//#region src/error/invalid-tool-approval-signature-error.ts
|
|
1688
|
-
const name$
|
|
1689
|
-
const marker$
|
|
1690
|
-
const symbol$
|
|
1739
|
+
const name$5 = "AI_InvalidToolApprovalSignatureError";
|
|
1740
|
+
const marker$5 = `vercel.ai.error.${name$5}`;
|
|
1741
|
+
const symbol$5 = Symbol.for(marker$5);
|
|
1691
1742
|
var InvalidToolApprovalSignatureError = class extends AISDKError {
|
|
1692
1743
|
constructor({ approvalId, toolCallId, reason }) {
|
|
1693
1744
|
super({
|
|
1694
|
-
name: name$
|
|
1745
|
+
name: name$5,
|
|
1695
1746
|
message: `Tool approval signature verification failed for approval "${approvalId}" (tool call "${toolCallId}"): ${reason}`
|
|
1696
1747
|
});
|
|
1697
|
-
this[symbol$
|
|
1748
|
+
this[symbol$5] = true;
|
|
1698
1749
|
this.approvalId = approvalId;
|
|
1699
1750
|
this.toolCallId = toolCallId;
|
|
1700
1751
|
}
|
|
1701
1752
|
static isInstance(error) {
|
|
1702
|
-
return AISDKError.hasMarker(error, marker$
|
|
1753
|
+
return AISDKError.hasMarker(error, marker$5);
|
|
1703
1754
|
}
|
|
1704
1755
|
};
|
|
1705
1756
|
//#endregion
|
|
1706
1757
|
//#region src/error/invalid-tool-input-error.ts
|
|
1707
|
-
const name$
|
|
1708
|
-
const marker$
|
|
1709
|
-
const symbol$
|
|
1758
|
+
const name$4 = "AI_InvalidToolInputError";
|
|
1759
|
+
const marker$4 = `vercel.ai.error.${name$4}`;
|
|
1760
|
+
const symbol$4 = Symbol.for(marker$4);
|
|
1710
1761
|
var InvalidToolInputError = class extends AISDKError {
|
|
1711
1762
|
constructor({ toolInput, toolName, cause, message = `Invalid input for tool ${toolName}: ${getErrorMessage(cause)}` }) {
|
|
1712
1763
|
super({
|
|
1713
|
-
name: name$
|
|
1764
|
+
name: name$4,
|
|
1714
1765
|
message,
|
|
1715
1766
|
cause
|
|
1716
1767
|
});
|
|
1717
|
-
this[symbol$
|
|
1768
|
+
this[symbol$4] = true;
|
|
1718
1769
|
this.toolInput = toolInput;
|
|
1719
1770
|
this.toolName = toolName;
|
|
1720
1771
|
}
|
|
1721
1772
|
static isInstance(error) {
|
|
1722
|
-
return AISDKError.hasMarker(error, marker$
|
|
1773
|
+
return AISDKError.hasMarker(error, marker$4);
|
|
1723
1774
|
}
|
|
1724
1775
|
};
|
|
1725
1776
|
//#endregion
|
|
1726
1777
|
//#region src/error/tool-call-not-found-for-approval-error.ts
|
|
1727
|
-
const name$
|
|
1728
|
-
const marker$
|
|
1729
|
-
const symbol$
|
|
1778
|
+
const name$3 = "AI_ToolCallNotFoundForApprovalError";
|
|
1779
|
+
const marker$3 = `vercel.ai.error.${name$3}`;
|
|
1780
|
+
const symbol$3 = Symbol.for(marker$3);
|
|
1730
1781
|
var ToolCallNotFoundForApprovalError = class extends AISDKError {
|
|
1731
1782
|
constructor({ toolCallId, approvalId }) {
|
|
1732
1783
|
super({
|
|
1733
|
-
name: name$
|
|
1784
|
+
name: name$3,
|
|
1734
1785
|
message: `Tool call "${toolCallId}" not found for approval request "${approvalId}".`
|
|
1735
1786
|
});
|
|
1736
|
-
this[symbol$
|
|
1787
|
+
this[symbol$3] = true;
|
|
1737
1788
|
this.toolCallId = toolCallId;
|
|
1738
1789
|
this.approvalId = approvalId;
|
|
1739
1790
|
}
|
|
1791
|
+
static isInstance(error) {
|
|
1792
|
+
return AISDKError.hasMarker(error, marker$3);
|
|
1793
|
+
}
|
|
1794
|
+
};
|
|
1795
|
+
//#endregion
|
|
1796
|
+
//#region src/error/no-output-generated-error.ts
|
|
1797
|
+
const name$2 = "AI_NoOutputGeneratedError";
|
|
1798
|
+
const marker$2 = `vercel.ai.error.${name$2}`;
|
|
1799
|
+
const symbol$2 = Symbol.for(marker$2);
|
|
1800
|
+
/**
|
|
1801
|
+
* Thrown when no LLM output was generated, e.g. because of errors.
|
|
1802
|
+
*/
|
|
1803
|
+
var NoOutputGeneratedError = class extends AISDKError {
|
|
1804
|
+
constructor({ message = "No output generated.", cause } = {}) {
|
|
1805
|
+
super({
|
|
1806
|
+
name: name$2,
|
|
1807
|
+
message,
|
|
1808
|
+
cause
|
|
1809
|
+
});
|
|
1810
|
+
this[symbol$2] = true;
|
|
1811
|
+
}
|
|
1740
1812
|
static isInstance(error) {
|
|
1741
1813
|
return AISDKError.hasMarker(error, marker$2);
|
|
1742
1814
|
}
|
|
@@ -1916,7 +1988,8 @@ function convertV2UsageToV3(usage) {
|
|
|
1916
1988
|
total: usage.outputTokens,
|
|
1917
1989
|
text: void 0,
|
|
1918
1990
|
reasoning: usage.reasoningTokens
|
|
1919
|
-
}
|
|
1991
|
+
},
|
|
1992
|
+
raw: usage.totalTokens == null ? void 0 : { totalTokens: usage.totalTokens }
|
|
1920
1993
|
};
|
|
1921
1994
|
}
|
|
1922
1995
|
//#endregion
|
|
@@ -2364,8 +2437,11 @@ function createTelemetryDispatcher({ telemetry }) {
|
|
|
2364
2437
|
includeRuntimeContext: telemetry?.includeRuntimeContext,
|
|
2365
2438
|
includeToolsContext: telemetry?.includeToolsContext
|
|
2366
2439
|
};
|
|
2367
|
-
const mergeTelemetryCallback = (key) => {
|
|
2368
|
-
const integrationCallbacks = integrations.map((integration) =>
|
|
2440
|
+
const mergeTelemetryCallback = (key, deprecatedKey) => {
|
|
2441
|
+
const integrationCallbacks = integrations.map((integration) => {
|
|
2442
|
+
const callback = integration[key] ?? (deprecatedKey == null ? void 0 : integration[deprecatedKey]);
|
|
2443
|
+
return typeof callback === "function" ? callback.bind(integration) : void 0;
|
|
2444
|
+
}).filter(Boolean).map((callback) => ((event) => callback(augmentEvent(event, telemetryMetadata))));
|
|
2369
2445
|
if (integrationCallbacks.length === 0) return;
|
|
2370
2446
|
const mergedIntegrationCallback = mergeCallbacks(...integrationCallbacks);
|
|
2371
2447
|
return async (event) => {
|
|
@@ -2401,10 +2477,10 @@ function createTelemetryDispatcher({ telemetry }) {
|
|
|
2401
2477
|
onEmbedEnd: mergeTelemetryCallback("onEmbedEnd"),
|
|
2402
2478
|
onRerankStart: mergeTelemetryCallback("onRerankStart"),
|
|
2403
2479
|
onRerankEnd: mergeTelemetryCallback("onRerankEnd"),
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2480
|
+
experimental_onDecideStart: mergeTelemetryCallback("experimental_onDecideStart", "experimental_onEvaluateStart"),
|
|
2481
|
+
experimental_onDecisionModelCallStart: mergeTelemetryCallback("experimental_onDecisionModelCallStart", "experimental_onEvaluationModelCallStart"),
|
|
2482
|
+
experimental_onDecisionModelCallEnd: mergeTelemetryCallback("experimental_onDecisionModelCallEnd", "experimental_onEvaluationModelCallEnd"),
|
|
2483
|
+
experimental_onDecideEnd: mergeTelemetryCallback("experimental_onDecideEnd", "experimental_onEvaluateEnd"),
|
|
2408
2484
|
experimental_onStreamTranscriptionStart: mergeTelemetryCallback("experimental_onStreamTranscriptionStart"),
|
|
2409
2485
|
experimental_onStreamTranscriptionEnd: mergeTelemetryCallback("experimental_onStreamTranscriptionEnd"),
|
|
2410
2486
|
onEnd: mergeTelemetryCallback("onEnd"),
|
|
@@ -2456,7 +2532,30 @@ function asReasoningText(reasoningParts) {
|
|
|
2456
2532
|
return reasoningText.length > 0 ? reasoningText : void 0;
|
|
2457
2533
|
}
|
|
2458
2534
|
//#endregion
|
|
2535
|
+
//#region src/generate-text/generated-file.ts
|
|
2536
|
+
var DefaultGeneratedFile = class {
|
|
2537
|
+
constructor({ data, mediaType, providerMetadata }) {
|
|
2538
|
+
const isUint8Array = data instanceof Uint8Array;
|
|
2539
|
+
this.base64Data = isUint8Array ? void 0 : data;
|
|
2540
|
+
this.uint8ArrayData = isUint8Array ? data : void 0;
|
|
2541
|
+
this.mediaType = mediaType;
|
|
2542
|
+
this.providerMetadata = providerMetadata;
|
|
2543
|
+
}
|
|
2544
|
+
get base64() {
|
|
2545
|
+
if (this.base64Data == null) this.base64Data = convertUint8ArrayToBase64(this.uint8ArrayData);
|
|
2546
|
+
return this.base64Data;
|
|
2547
|
+
}
|
|
2548
|
+
get uint8Array() {
|
|
2549
|
+
if (this.uint8ArrayData == null) this.uint8ArrayData = convertBase64ToUint8Array(this.base64Data);
|
|
2550
|
+
return this.uint8ArrayData;
|
|
2551
|
+
}
|
|
2552
|
+
};
|
|
2553
|
+
//#endregion
|
|
2459
2554
|
//#region src/generate-text/reasoning-output.ts
|
|
2555
|
+
function unwrapReasoningFileData(data) {
|
|
2556
|
+
if (typeof data === "object" && data !== null && "type" in data) return data.type === "data" ? data.data : data.url;
|
|
2557
|
+
return data;
|
|
2558
|
+
}
|
|
2460
2559
|
function convertFromReasoningOutputs(parts) {
|
|
2461
2560
|
return parts.map((part) => {
|
|
2462
2561
|
if (part.type === "reasoning") return {
|
|
@@ -2472,6 +2571,24 @@ function convertFromReasoningOutputs(parts) {
|
|
|
2472
2571
|
};
|
|
2473
2572
|
});
|
|
2474
2573
|
}
|
|
2574
|
+
function convertToReasoningOutputs(parts) {
|
|
2575
|
+
return parts.map((part) => {
|
|
2576
|
+
if (part.type === "reasoning") return {
|
|
2577
|
+
type: "reasoning",
|
|
2578
|
+
text: part.text,
|
|
2579
|
+
...part.providerOptions != null ? { providerMetadata: part.providerOptions } : {}
|
|
2580
|
+
};
|
|
2581
|
+
const rawData = unwrapReasoningFileData(part.data);
|
|
2582
|
+
return {
|
|
2583
|
+
type: "reasoning-file",
|
|
2584
|
+
file: new DefaultGeneratedFile({
|
|
2585
|
+
data: rawData instanceof ArrayBuffer ? new Uint8Array(rawData) : rawData instanceof URL ? rawData.toString() : rawData,
|
|
2586
|
+
mediaType: part.mediaType
|
|
2587
|
+
}),
|
|
2588
|
+
...part.providerOptions != null ? { providerMetadata: part.providerOptions } : {}
|
|
2589
|
+
};
|
|
2590
|
+
});
|
|
2591
|
+
}
|
|
2475
2592
|
//#endregion
|
|
2476
2593
|
//#region src/generate-text/step-result.ts
|
|
2477
2594
|
var DefaultStepResult = class {
|
|
@@ -3407,6 +3524,220 @@ function sortToolResultContentByToolCallOrder({ toolResultContent, toolCallOrder
|
|
|
3407
3524
|
return toolResultContent.map((part) => part.type === "tool-result" ? sortedToolResults[toolResultIndex++] : part);
|
|
3408
3525
|
}
|
|
3409
3526
|
//#endregion
|
|
3410
|
-
|
|
3527
|
+
//#region src/generate-text/default-generate-text-result.ts
|
|
3528
|
+
var DefaultGenerateTextResult = class {
|
|
3529
|
+
constructor(options) {
|
|
3530
|
+
this.initialResponseMessages = options.initialResponseMessages;
|
|
3531
|
+
this.steps = options.steps;
|
|
3532
|
+
this._output = options.output;
|
|
3533
|
+
this.totalUsage = options.totalUsage;
|
|
3534
|
+
}
|
|
3535
|
+
get finalStep() {
|
|
3536
|
+
return this.steps.at(-1);
|
|
3537
|
+
}
|
|
3538
|
+
get content() {
|
|
3539
|
+
return this.steps.flatMap((step) => step.content);
|
|
3540
|
+
}
|
|
3541
|
+
get text() {
|
|
3542
|
+
return this.finalStep.text;
|
|
3543
|
+
}
|
|
3544
|
+
get files() {
|
|
3545
|
+
return this.steps.flatMap((step) => step.files);
|
|
3546
|
+
}
|
|
3547
|
+
get reasoningText() {
|
|
3548
|
+
return this.finalStep.reasoningText;
|
|
3549
|
+
}
|
|
3550
|
+
get reasoning() {
|
|
3551
|
+
return convertToReasoningOutputs(this.finalStep.reasoning);
|
|
3552
|
+
}
|
|
3553
|
+
get toolCalls() {
|
|
3554
|
+
return this.steps.flatMap((step) => step.toolCalls);
|
|
3555
|
+
}
|
|
3556
|
+
get staticToolCalls() {
|
|
3557
|
+
return this.steps.flatMap((step) => step.staticToolCalls);
|
|
3558
|
+
}
|
|
3559
|
+
get dynamicToolCalls() {
|
|
3560
|
+
return this.steps.flatMap((step) => step.dynamicToolCalls);
|
|
3561
|
+
}
|
|
3562
|
+
get toolResults() {
|
|
3563
|
+
return this.steps.flatMap((step) => step.toolResults);
|
|
3564
|
+
}
|
|
3565
|
+
get staticToolResults() {
|
|
3566
|
+
return this.steps.flatMap((step) => step.staticToolResults);
|
|
3567
|
+
}
|
|
3568
|
+
get dynamicToolResults() {
|
|
3569
|
+
return this.steps.flatMap((step) => step.dynamicToolResults);
|
|
3570
|
+
}
|
|
3571
|
+
get sources() {
|
|
3572
|
+
return this.steps.flatMap((step) => step.sources);
|
|
3573
|
+
}
|
|
3574
|
+
get finishReason() {
|
|
3575
|
+
return this.finalStep.finishReason;
|
|
3576
|
+
}
|
|
3577
|
+
get rawFinishReason() {
|
|
3578
|
+
return this.finalStep.rawFinishReason;
|
|
3579
|
+
}
|
|
3580
|
+
get warnings() {
|
|
3581
|
+
return this.steps.flatMap((step) => step.warnings ?? []);
|
|
3582
|
+
}
|
|
3583
|
+
get providerMetadata() {
|
|
3584
|
+
return this.finalStep.providerMetadata;
|
|
3585
|
+
}
|
|
3586
|
+
get response() {
|
|
3587
|
+
return this.finalStep.response;
|
|
3588
|
+
}
|
|
3589
|
+
get responseMessages() {
|
|
3590
|
+
return [...this.initialResponseMessages, ...this.steps.flatMap((step) => step.response.messages)];
|
|
3591
|
+
}
|
|
3592
|
+
get request() {
|
|
3593
|
+
return this.finalStep.request;
|
|
3594
|
+
}
|
|
3595
|
+
get usage() {
|
|
3596
|
+
return this.totalUsage;
|
|
3597
|
+
}
|
|
3598
|
+
get output() {
|
|
3599
|
+
if (this._output == null) throw new NoOutputGeneratedError();
|
|
3600
|
+
return this._output;
|
|
3601
|
+
}
|
|
3602
|
+
};
|
|
3603
|
+
//#endregion
|
|
3604
|
+
//#region src/generate-text/resolve-generated-file-data.ts
|
|
3605
|
+
async function resolveGeneratedFileData({ data, abortSignal, cache }) {
|
|
3606
|
+
if (data.type === "data") return data.data;
|
|
3607
|
+
const cachedData = cache?.get(data);
|
|
3608
|
+
if (cachedData != null) return cachedData;
|
|
3609
|
+
const downloadedData = (await download({
|
|
3610
|
+
url: data.url,
|
|
3611
|
+
abortSignal
|
|
3612
|
+
})).data;
|
|
3613
|
+
cache?.set(data, downloadedData);
|
|
3614
|
+
return downloadedData;
|
|
3615
|
+
}
|
|
3616
|
+
//#endregion
|
|
3617
|
+
//#region src/generate-text/convert-language-model-content.ts
|
|
3618
|
+
async function convertLanguageModelContent({ content, toolCalls, toolOutputs, toolApprovalRequests, toolApprovalResponses, tools, abortSignal, generatedFileDataCache }) {
|
|
3619
|
+
const contentParts = [];
|
|
3620
|
+
const toolOutputsWithApprovalResponses = [];
|
|
3621
|
+
const toolOutputsWithoutApprovalResponses = [];
|
|
3622
|
+
const toolCallIdsWithApprovalResponses = new Set(toolApprovalResponses.map((toolApprovalResponse) => toolApprovalResponse.toolCall.toolCallId));
|
|
3623
|
+
for (const part of content) switch (part.type) {
|
|
3624
|
+
case "text":
|
|
3625
|
+
case "reasoning":
|
|
3626
|
+
case "custom":
|
|
3627
|
+
case "source":
|
|
3628
|
+
contentParts.push(part);
|
|
3629
|
+
break;
|
|
3630
|
+
case "file":
|
|
3631
|
+
case "reasoning-file":
|
|
3632
|
+
contentParts.push({
|
|
3633
|
+
type: part.type,
|
|
3634
|
+
file: new DefaultGeneratedFile({
|
|
3635
|
+
data: await resolveGeneratedFileData({
|
|
3636
|
+
data: part.data,
|
|
3637
|
+
abortSignal,
|
|
3638
|
+
cache: generatedFileDataCache
|
|
3639
|
+
}),
|
|
3640
|
+
mediaType: part.mediaType
|
|
3641
|
+
}),
|
|
3642
|
+
...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {}
|
|
3643
|
+
});
|
|
3644
|
+
break;
|
|
3645
|
+
case "tool-call": {
|
|
3646
|
+
const toolCall = toolCalls.find((toolCall) => toolCall.toolCallId === part.toolCallId);
|
|
3647
|
+
if (toolCall == null) throw new Error(`Tool call ${part.toolCallId} not found.`);
|
|
3648
|
+
contentParts.push(toolCall);
|
|
3649
|
+
break;
|
|
3650
|
+
}
|
|
3651
|
+
case "tool-result": {
|
|
3652
|
+
const toolCall = toolCalls.find((toolCall) => toolCall.toolCallId === part.toolCallId);
|
|
3653
|
+
if (toolCall == null) {
|
|
3654
|
+
const tool = getOwn(tools, part.toolName);
|
|
3655
|
+
if (!(tool?.type === "provider" && tool.supportsDeferredResults)) throw new Error(`Tool call ${part.toolCallId} not found.`);
|
|
3656
|
+
if (part.isError) contentParts.push({
|
|
3657
|
+
type: "tool-error",
|
|
3658
|
+
toolCallId: part.toolCallId,
|
|
3659
|
+
toolName: part.toolName,
|
|
3660
|
+
input: void 0,
|
|
3661
|
+
error: part.result,
|
|
3662
|
+
providerExecuted: true,
|
|
3663
|
+
dynamic: part.dynamic,
|
|
3664
|
+
...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {},
|
|
3665
|
+
...tool?.metadata != null ? { toolMetadata: tool.metadata } : {}
|
|
3666
|
+
});
|
|
3667
|
+
else contentParts.push({
|
|
3668
|
+
type: "tool-result",
|
|
3669
|
+
toolCallId: part.toolCallId,
|
|
3670
|
+
toolName: part.toolName,
|
|
3671
|
+
input: void 0,
|
|
3672
|
+
output: part.result,
|
|
3673
|
+
providerExecuted: true,
|
|
3674
|
+
dynamic: part.dynamic,
|
|
3675
|
+
...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {},
|
|
3676
|
+
...tool?.metadata != null ? { toolMetadata: tool.metadata } : {}
|
|
3677
|
+
});
|
|
3678
|
+
break;
|
|
3679
|
+
}
|
|
3680
|
+
if (part.isError) contentParts.push({
|
|
3681
|
+
type: "tool-error",
|
|
3682
|
+
toolCallId: part.toolCallId,
|
|
3683
|
+
toolName: part.toolName,
|
|
3684
|
+
input: toolCall.input,
|
|
3685
|
+
error: part.result,
|
|
3686
|
+
providerExecuted: true,
|
|
3687
|
+
dynamic: toolCall.dynamic,
|
|
3688
|
+
...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {},
|
|
3689
|
+
...toolCall.toolMetadata != null ? { toolMetadata: toolCall.toolMetadata } : {}
|
|
3690
|
+
});
|
|
3691
|
+
else contentParts.push({
|
|
3692
|
+
type: "tool-result",
|
|
3693
|
+
toolCallId: part.toolCallId,
|
|
3694
|
+
toolName: part.toolName,
|
|
3695
|
+
input: toolCall.input,
|
|
3696
|
+
output: part.result,
|
|
3697
|
+
providerExecuted: true,
|
|
3698
|
+
dynamic: toolCall.dynamic,
|
|
3699
|
+
...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {},
|
|
3700
|
+
...toolCall.toolMetadata != null ? { toolMetadata: toolCall.toolMetadata } : {}
|
|
3701
|
+
});
|
|
3702
|
+
break;
|
|
3703
|
+
}
|
|
3704
|
+
case "tool-approval-request": {
|
|
3705
|
+
const toolCall = toolCalls.find((toolCall) => toolCall.toolCallId === part.toolCallId);
|
|
3706
|
+
if (toolCall == null) throw new ToolCallNotFoundForApprovalError({
|
|
3707
|
+
toolCallId: part.toolCallId,
|
|
3708
|
+
approvalId: part.approvalId
|
|
3709
|
+
});
|
|
3710
|
+
contentParts.push({
|
|
3711
|
+
type: "tool-approval-request",
|
|
3712
|
+
approvalId: part.approvalId,
|
|
3713
|
+
toolCall
|
|
3714
|
+
});
|
|
3715
|
+
break;
|
|
3716
|
+
}
|
|
3717
|
+
}
|
|
3718
|
+
for (const toolOutput of toolOutputs) if (toolCallIdsWithApprovalResponses.has(toolOutput.toolCallId)) toolOutputsWithApprovalResponses.push(toolOutput);
|
|
3719
|
+
else toolOutputsWithoutApprovalResponses.push(toolOutput);
|
|
3720
|
+
return [
|
|
3721
|
+
...contentParts,
|
|
3722
|
+
...toolOutputsWithoutApprovalResponses,
|
|
3723
|
+
...toolApprovalRequests,
|
|
3724
|
+
...toolApprovalResponses,
|
|
3725
|
+
...toolOutputsWithApprovalResponses
|
|
3726
|
+
];
|
|
3727
|
+
}
|
|
3728
|
+
//#endregion
|
|
3729
|
+
//#region src/generate-text/calculate-tokens-per-second.ts
|
|
3730
|
+
/**
|
|
3731
|
+
* Calculates a token rate in tokens per second.
|
|
3732
|
+
*
|
|
3733
|
+
* Returns 0 when the token count is unknown, the duration is unknown or 0, or
|
|
3734
|
+
* the computed rate cannot be represented as a finite JSON-safe number.
|
|
3735
|
+
*/
|
|
3736
|
+
function calculateTokensPerSecond({ tokens, durationMs }) {
|
|
3737
|
+
const tokenRate = 1e3 * (tokens ?? 0) / (durationMs ?? 0);
|
|
3738
|
+
return Number.isFinite(tokenRate) ? tokenRate : 0;
|
|
3739
|
+
}
|
|
3740
|
+
//#endregion
|
|
3741
|
+
export { DefaultGenerateTextResult, DefaultStepResult, addLanguageModelUsage, asLanguageModelUsage, calculateTokensPerSecond, collectToolApprovals, convertAsyncIteratorToReadableStream, convertLanguageModelContent, convertToLanguageModelPrompt, createAsyncIterableStream, createDefaultDownloadFunction, createNullLanguageModelUsage, createRestrictedTelemetryDispatcher, createTelemetryDispatcher, createToolModelOutput, createToolSearchState, downloadAssets, mapToolResultOutput, mergeAbortSignals, mergeCallbacks, parseToolCall, prepareLanguageModelCallOptions as prepareCallSettings, prepareLanguageModelCallOptions, prepareRetries, prepareToolChoice, prepareTools, resolveLanguageModel, signToolApproval, standardizePrompt, toResponseMessages, validateApprovedToolApprovals, validateToolContext, verifyToolApprovalSignature };
|
|
3411
3742
|
|
|
3412
3743
|
//# sourceMappingURL=index.js.map
|