ai 6.0.271 → 6.0.273
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 +20 -0
- package/dist/index.d.mts +105 -46
- package/dist/index.d.ts +105 -46
- package/dist/index.js +445 -385
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +376 -315
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +1 -1
- package/dist/internal/index.mjs +1 -1
- package/docs/03-ai-sdk-core/15-tools-and-tool-calling.mdx +26 -1
- package/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx +7 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-tool-choice-violation-error.mdx +38 -0
- package/docs/07-reference/05-ai-sdk-errors/index.mdx +1 -0
- package/package.json +3 -3
- package/src/agent/tool-loop-agent-settings.ts +9 -0
- package/src/error/index.ts +1 -0
- package/src/error/tool-choice-violation-error.ts +80 -0
- package/src/generate-text/generate-text.ts +25 -1
- package/src/generate-text/index.ts +2 -0
- package/src/generate-text/stream-text.ts +99 -52
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __export = (target, all) => {
|
|
3
|
-
for (var
|
|
4
|
-
__defProp(target,
|
|
3
|
+
for (var name23 in all)
|
|
4
|
+
__defProp(target, name23, { get: all[name23], enumerable: true });
|
|
5
5
|
};
|
|
6
6
|
|
|
7
7
|
// src/index.ts
|
|
@@ -29,7 +29,7 @@ import {
|
|
|
29
29
|
|
|
30
30
|
// src/error/index.ts
|
|
31
31
|
import {
|
|
32
|
-
AISDKError as
|
|
32
|
+
AISDKError as AISDKError23,
|
|
33
33
|
APICallError,
|
|
34
34
|
EmptyResponseBodyError,
|
|
35
35
|
InvalidPromptError,
|
|
@@ -386,31 +386,62 @@ var NoSuchToolError = class extends AISDKError14 {
|
|
|
386
386
|
};
|
|
387
387
|
_a14 = symbol14;
|
|
388
388
|
|
|
389
|
-
// src/error/tool-
|
|
390
|
-
import {
|
|
391
|
-
|
|
389
|
+
// src/error/tool-choice-violation-error.ts
|
|
390
|
+
import {
|
|
391
|
+
AISDKError as AISDKError15
|
|
392
|
+
} from "@ai-sdk/provider";
|
|
393
|
+
var name15 = "AI_ToolChoiceViolationError";
|
|
392
394
|
var marker15 = `vercel.ai.error.${name15}`;
|
|
393
395
|
var symbol15 = Symbol.for(marker15);
|
|
394
396
|
var _a15;
|
|
395
|
-
var
|
|
397
|
+
var ToolChoiceViolationError = class extends AISDKError15 {
|
|
398
|
+
constructor({
|
|
399
|
+
toolChoice,
|
|
400
|
+
finishReason,
|
|
401
|
+
provider,
|
|
402
|
+
modelId,
|
|
403
|
+
content,
|
|
404
|
+
message = toolChoice.type === "required" ? "Model response did not contain a tool call even though tool choice was required." : `Model response did not contain a call to the required tool '${toolChoice.toolName}'.`
|
|
405
|
+
}) {
|
|
406
|
+
super({ name: name15, message });
|
|
407
|
+
this[_a15] = true;
|
|
408
|
+
this.toolChoice = toolChoice;
|
|
409
|
+
this.finishReason = finishReason;
|
|
410
|
+
this.provider = provider;
|
|
411
|
+
this.modelId = modelId;
|
|
412
|
+
this.content = content;
|
|
413
|
+
}
|
|
414
|
+
static isInstance(error) {
|
|
415
|
+
return AISDKError15.hasMarker(error, marker15);
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
_a15 = symbol15;
|
|
419
|
+
|
|
420
|
+
// src/error/tool-call-repair-error.ts
|
|
421
|
+
import { AISDKError as AISDKError16, getErrorMessage as getErrorMessage2 } from "@ai-sdk/provider";
|
|
422
|
+
var name16 = "AI_ToolCallRepairError";
|
|
423
|
+
var marker16 = `vercel.ai.error.${name16}`;
|
|
424
|
+
var symbol16 = Symbol.for(marker16);
|
|
425
|
+
var _a16;
|
|
426
|
+
var ToolCallRepairError = class extends AISDKError16 {
|
|
396
427
|
constructor({
|
|
397
428
|
cause,
|
|
398
429
|
originalError,
|
|
399
430
|
message = `Error repairing tool call: ${getErrorMessage2(cause)}`
|
|
400
431
|
}) {
|
|
401
|
-
super({ name:
|
|
402
|
-
this[
|
|
432
|
+
super({ name: name16, message, cause });
|
|
433
|
+
this[_a16] = true;
|
|
403
434
|
this.originalError = originalError;
|
|
404
435
|
}
|
|
405
436
|
static isInstance(error) {
|
|
406
|
-
return
|
|
437
|
+
return AISDKError16.hasMarker(error, marker16);
|
|
407
438
|
}
|
|
408
439
|
};
|
|
409
|
-
|
|
440
|
+
_a16 = symbol16;
|
|
410
441
|
|
|
411
442
|
// src/error/unsupported-model-version-error.ts
|
|
412
|
-
import { AISDKError as
|
|
413
|
-
var UnsupportedModelVersionError = class extends
|
|
443
|
+
import { AISDKError as AISDKError17 } from "@ai-sdk/provider";
|
|
444
|
+
var UnsupportedModelVersionError = class extends AISDKError17 {
|
|
414
445
|
constructor(options) {
|
|
415
446
|
super({
|
|
416
447
|
name: "AI_UnsupportedModelVersionError",
|
|
@@ -423,118 +454,118 @@ var UnsupportedModelVersionError = class extends AISDKError16 {
|
|
|
423
454
|
};
|
|
424
455
|
|
|
425
456
|
// src/error/ui-message-stream-error.ts
|
|
426
|
-
import { AISDKError as
|
|
427
|
-
var
|
|
428
|
-
var
|
|
429
|
-
var
|
|
430
|
-
var
|
|
431
|
-
var UIMessageStreamError = class extends
|
|
457
|
+
import { AISDKError as AISDKError18 } from "@ai-sdk/provider";
|
|
458
|
+
var name17 = "AI_UIMessageStreamError";
|
|
459
|
+
var marker17 = `vercel.ai.error.${name17}`;
|
|
460
|
+
var symbol17 = Symbol.for(marker17);
|
|
461
|
+
var _a17;
|
|
462
|
+
var UIMessageStreamError = class extends AISDKError18 {
|
|
432
463
|
constructor({
|
|
433
464
|
chunkType,
|
|
434
465
|
chunkId,
|
|
435
466
|
message
|
|
436
467
|
}) {
|
|
437
|
-
super({ name:
|
|
438
|
-
this[
|
|
468
|
+
super({ name: name17, message });
|
|
469
|
+
this[_a17] = true;
|
|
439
470
|
this.chunkType = chunkType;
|
|
440
471
|
this.chunkId = chunkId;
|
|
441
472
|
}
|
|
442
473
|
static isInstance(error) {
|
|
443
|
-
return
|
|
474
|
+
return AISDKError18.hasMarker(error, marker17);
|
|
444
475
|
}
|
|
445
476
|
};
|
|
446
|
-
|
|
477
|
+
_a17 = symbol17;
|
|
447
478
|
|
|
448
479
|
// src/prompt/invalid-data-content-error.ts
|
|
449
|
-
import { AISDKError as
|
|
450
|
-
var
|
|
451
|
-
var
|
|
452
|
-
var
|
|
453
|
-
var
|
|
454
|
-
var InvalidDataContentError = class extends
|
|
480
|
+
import { AISDKError as AISDKError19 } from "@ai-sdk/provider";
|
|
481
|
+
var name18 = "AI_InvalidDataContentError";
|
|
482
|
+
var marker18 = `vercel.ai.error.${name18}`;
|
|
483
|
+
var symbol18 = Symbol.for(marker18);
|
|
484
|
+
var _a18;
|
|
485
|
+
var InvalidDataContentError = class extends AISDKError19 {
|
|
455
486
|
constructor({
|
|
456
487
|
content,
|
|
457
488
|
cause,
|
|
458
489
|
message = `Invalid data content. Expected a base64 string, Uint8Array, ArrayBuffer, or Buffer, but got ${typeof content}.`
|
|
459
490
|
}) {
|
|
460
|
-
super({ name:
|
|
461
|
-
this[
|
|
491
|
+
super({ name: name18, message, cause });
|
|
492
|
+
this[_a18] = true;
|
|
462
493
|
this.content = content;
|
|
463
494
|
}
|
|
464
495
|
static isInstance(error) {
|
|
465
|
-
return
|
|
496
|
+
return AISDKError19.hasMarker(error, marker18);
|
|
466
497
|
}
|
|
467
498
|
};
|
|
468
|
-
|
|
499
|
+
_a18 = symbol18;
|
|
469
500
|
|
|
470
501
|
// src/prompt/invalid-message-role-error.ts
|
|
471
|
-
import { AISDKError as
|
|
472
|
-
var
|
|
473
|
-
var
|
|
474
|
-
var
|
|
475
|
-
var
|
|
476
|
-
var InvalidMessageRoleError = class extends
|
|
502
|
+
import { AISDKError as AISDKError20 } from "@ai-sdk/provider";
|
|
503
|
+
var name19 = "AI_InvalidMessageRoleError";
|
|
504
|
+
var marker19 = `vercel.ai.error.${name19}`;
|
|
505
|
+
var symbol19 = Symbol.for(marker19);
|
|
506
|
+
var _a19;
|
|
507
|
+
var InvalidMessageRoleError = class extends AISDKError20 {
|
|
477
508
|
constructor({
|
|
478
509
|
role,
|
|
479
510
|
message = `Invalid message role: '${role}'. Must be one of: "system", "user", "assistant", "tool".`
|
|
480
511
|
}) {
|
|
481
|
-
super({ name:
|
|
482
|
-
this[
|
|
512
|
+
super({ name: name19, message });
|
|
513
|
+
this[_a19] = true;
|
|
483
514
|
this.role = role;
|
|
484
515
|
}
|
|
485
516
|
static isInstance(error) {
|
|
486
|
-
return
|
|
517
|
+
return AISDKError20.hasMarker(error, marker19);
|
|
487
518
|
}
|
|
488
519
|
};
|
|
489
|
-
|
|
520
|
+
_a19 = symbol19;
|
|
490
521
|
|
|
491
522
|
// src/prompt/message-conversion-error.ts
|
|
492
|
-
import { AISDKError as
|
|
493
|
-
var
|
|
494
|
-
var
|
|
495
|
-
var
|
|
496
|
-
var
|
|
497
|
-
var MessageConversionError = class extends
|
|
523
|
+
import { AISDKError as AISDKError21 } from "@ai-sdk/provider";
|
|
524
|
+
var name20 = "AI_MessageConversionError";
|
|
525
|
+
var marker20 = `vercel.ai.error.${name20}`;
|
|
526
|
+
var symbol20 = Symbol.for(marker20);
|
|
527
|
+
var _a20;
|
|
528
|
+
var MessageConversionError = class extends AISDKError21 {
|
|
498
529
|
constructor({
|
|
499
530
|
originalMessage,
|
|
500
531
|
message
|
|
501
532
|
}) {
|
|
502
|
-
super({ name:
|
|
503
|
-
this[
|
|
533
|
+
super({ name: name20, message });
|
|
534
|
+
this[_a20] = true;
|
|
504
535
|
this.originalMessage = originalMessage;
|
|
505
536
|
}
|
|
506
537
|
static isInstance(error) {
|
|
507
|
-
return
|
|
538
|
+
return AISDKError21.hasMarker(error, marker20);
|
|
508
539
|
}
|
|
509
540
|
};
|
|
510
|
-
|
|
541
|
+
_a20 = symbol20;
|
|
511
542
|
|
|
512
543
|
// src/error/index.ts
|
|
513
544
|
import { DownloadError } from "@ai-sdk/provider-utils";
|
|
514
545
|
|
|
515
546
|
// src/util/retry-error.ts
|
|
516
|
-
import { AISDKError as
|
|
517
|
-
var
|
|
518
|
-
var
|
|
519
|
-
var
|
|
520
|
-
var
|
|
521
|
-
var RetryError = class extends
|
|
547
|
+
import { AISDKError as AISDKError22 } from "@ai-sdk/provider";
|
|
548
|
+
var name21 = "AI_RetryError";
|
|
549
|
+
var marker21 = `vercel.ai.error.${name21}`;
|
|
550
|
+
var symbol21 = Symbol.for(marker21);
|
|
551
|
+
var _a21;
|
|
552
|
+
var RetryError = class extends AISDKError22 {
|
|
522
553
|
constructor({
|
|
523
554
|
message,
|
|
524
555
|
reason,
|
|
525
556
|
errors
|
|
526
557
|
}) {
|
|
527
|
-
super({ name:
|
|
528
|
-
this[
|
|
558
|
+
super({ name: name21, message });
|
|
559
|
+
this[_a21] = true;
|
|
529
560
|
this.reason = reason;
|
|
530
561
|
this.errors = errors;
|
|
531
562
|
this.lastError = errors[errors.length - 1];
|
|
532
563
|
}
|
|
533
564
|
static isInstance(error) {
|
|
534
|
-
return
|
|
565
|
+
return AISDKError22.hasMarker(error, marker21);
|
|
535
566
|
}
|
|
536
567
|
};
|
|
537
|
-
|
|
568
|
+
_a21 = symbol21;
|
|
538
569
|
|
|
539
570
|
// src/util/as-array.ts
|
|
540
571
|
function asArray(value) {
|
|
@@ -814,7 +845,7 @@ function resolveEmbeddingModel(model) {
|
|
|
814
845
|
return getGlobalProvider().embeddingModel(model);
|
|
815
846
|
}
|
|
816
847
|
function resolveTranscriptionModel(model) {
|
|
817
|
-
var
|
|
848
|
+
var _a23, _b;
|
|
818
849
|
if (typeof model !== "string") {
|
|
819
850
|
if (model.specificationVersion !== "v3" && model.specificationVersion !== "v2") {
|
|
820
851
|
const unsupportedModel = model;
|
|
@@ -826,10 +857,10 @@ function resolveTranscriptionModel(model) {
|
|
|
826
857
|
}
|
|
827
858
|
return asTranscriptionModelV3(model);
|
|
828
859
|
}
|
|
829
|
-
return (_b = (
|
|
860
|
+
return (_b = (_a23 = getGlobalProvider()).transcriptionModel) == null ? void 0 : _b.call(_a23, model);
|
|
830
861
|
}
|
|
831
862
|
function resolveSpeechModel(model) {
|
|
832
|
-
var
|
|
863
|
+
var _a23, _b;
|
|
833
864
|
if (typeof model !== "string") {
|
|
834
865
|
if (model.specificationVersion !== "v3" && model.specificationVersion !== "v2") {
|
|
835
866
|
const unsupportedModel = model;
|
|
@@ -841,7 +872,7 @@ function resolveSpeechModel(model) {
|
|
|
841
872
|
}
|
|
842
873
|
return asSpeechModelV3(model);
|
|
843
874
|
}
|
|
844
|
-
return (_b = (
|
|
875
|
+
return (_b = (_a23 = getGlobalProvider()).speechModel) == null ? void 0 : _b.call(_a23, model);
|
|
845
876
|
}
|
|
846
877
|
function resolveImageModel(model) {
|
|
847
878
|
if (typeof model !== "string") {
|
|
@@ -900,8 +931,8 @@ function resolveRerankingModel(model) {
|
|
|
900
931
|
return model;
|
|
901
932
|
}
|
|
902
933
|
function getGlobalProvider() {
|
|
903
|
-
var
|
|
904
|
-
return (
|
|
934
|
+
var _a23;
|
|
935
|
+
return (_a23 = globalThis.AI_SDK_DEFAULT_PROVIDER) != null ? _a23 : gateway;
|
|
905
936
|
}
|
|
906
937
|
|
|
907
938
|
// src/prompt/call-settings.ts
|
|
@@ -1193,7 +1224,7 @@ import {
|
|
|
1193
1224
|
} from "@ai-sdk/provider-utils";
|
|
1194
1225
|
|
|
1195
1226
|
// src/version.ts
|
|
1196
|
-
var VERSION = true ? "6.0.
|
|
1227
|
+
var VERSION = true ? "6.0.273" : "0.0.0-test";
|
|
1197
1228
|
|
|
1198
1229
|
// src/util/download/download.ts
|
|
1199
1230
|
var download = async ({
|
|
@@ -1201,7 +1232,7 @@ var download = async ({
|
|
|
1201
1232
|
maxBytes,
|
|
1202
1233
|
abortSignal
|
|
1203
1234
|
}) => {
|
|
1204
|
-
var
|
|
1235
|
+
var _a23;
|
|
1205
1236
|
const urlText = url.toString();
|
|
1206
1237
|
try {
|
|
1207
1238
|
const headers = withUserAgentSuffix(
|
|
@@ -1229,7 +1260,7 @@ var download = async ({
|
|
|
1229
1260
|
});
|
|
1230
1261
|
return {
|
|
1231
1262
|
data,
|
|
1232
|
-
mediaType: (
|
|
1263
|
+
mediaType: (_a23 = response.headers.get("content-type")) != null ? _a23 : void 0
|
|
1233
1264
|
};
|
|
1234
1265
|
} catch (error) {
|
|
1235
1266
|
if (DownloadError2.isInstance(error)) {
|
|
@@ -1283,7 +1314,7 @@ function mergeObjects(base, overrides) {
|
|
|
1283
1314
|
}
|
|
1284
1315
|
|
|
1285
1316
|
// src/prompt/data-content.ts
|
|
1286
|
-
import { AISDKError as
|
|
1317
|
+
import { AISDKError as AISDKError24 } from "@ai-sdk/provider";
|
|
1287
1318
|
import {
|
|
1288
1319
|
convertBase64ToUint8Array as convertBase64ToUint8Array2,
|
|
1289
1320
|
convertUint8ArrayToBase64
|
|
@@ -1314,8 +1345,8 @@ var dataContentSchema = z.union([
|
|
|
1314
1345
|
z.custom(
|
|
1315
1346
|
// Buffer might not be available in some environments such as CloudFlare:
|
|
1316
1347
|
(value) => {
|
|
1317
|
-
var
|
|
1318
|
-
return (_b = (
|
|
1348
|
+
var _a23, _b;
|
|
1349
|
+
return (_b = (_a23 = globalThis.Buffer) == null ? void 0 : _a23.isBuffer(value)) != null ? _b : false;
|
|
1319
1350
|
},
|
|
1320
1351
|
{ message: "Must be a Buffer" }
|
|
1321
1352
|
)
|
|
@@ -1338,7 +1369,7 @@ function convertToLanguageModelV3DataContent(content) {
|
|
|
1338
1369
|
content.toString()
|
|
1339
1370
|
);
|
|
1340
1371
|
if (dataUrlMediaType == null || base64Content == null) {
|
|
1341
|
-
throw new
|
|
1372
|
+
throw new AISDKError24({
|
|
1342
1373
|
name: "InvalidDataContentError",
|
|
1343
1374
|
message: `Invalid data URL format in content ${content.toString()}`
|
|
1344
1375
|
});
|
|
@@ -1629,7 +1660,7 @@ function convertToLanguageModelMessage({
|
|
|
1629
1660
|
}
|
|
1630
1661
|
}
|
|
1631
1662
|
async function downloadAssets(messages, download2, supportedUrls) {
|
|
1632
|
-
var
|
|
1663
|
+
var _a23;
|
|
1633
1664
|
const downloadableFiles = [];
|
|
1634
1665
|
for (const message of messages) {
|
|
1635
1666
|
if (message.role === "user" && Array.isArray(message.content)) {
|
|
@@ -1637,7 +1668,7 @@ async function downloadAssets(messages, download2, supportedUrls) {
|
|
|
1637
1668
|
if (part.type === "image" || part.type === "file") {
|
|
1638
1669
|
downloadableFiles.push({
|
|
1639
1670
|
data: part.type === "image" ? part.image : part.data,
|
|
1640
|
-
mediaType: (
|
|
1671
|
+
mediaType: (_a23 = part.mediaType) != null ? _a23 : part.type === "image" ? "image/*" : void 0
|
|
1641
1672
|
});
|
|
1642
1673
|
}
|
|
1643
1674
|
}
|
|
@@ -1689,7 +1720,7 @@ async function downloadAssets(messages, download2, supportedUrls) {
|
|
|
1689
1720
|
);
|
|
1690
1721
|
}
|
|
1691
1722
|
function convertPartToLanguageModelPart(part, downloadedAssets) {
|
|
1692
|
-
var
|
|
1723
|
+
var _a23;
|
|
1693
1724
|
if (part.type === "text") {
|
|
1694
1725
|
return {
|
|
1695
1726
|
type: "text",
|
|
@@ -1722,7 +1753,7 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
|
|
|
1722
1753
|
switch (type) {
|
|
1723
1754
|
case "image": {
|
|
1724
1755
|
if (data instanceof Uint8Array || typeof data === "string") {
|
|
1725
|
-
mediaType = (
|
|
1756
|
+
mediaType = (_a23 = detectMediaType({ data, signatures: imageMediaTypeSignatures })) != null ? _a23 : mediaType;
|
|
1726
1757
|
}
|
|
1727
1758
|
return {
|
|
1728
1759
|
type: "file",
|
|
@@ -1757,14 +1788,14 @@ function mapToolResultOutput({
|
|
|
1757
1788
|
return {
|
|
1758
1789
|
type: "content",
|
|
1759
1790
|
value: output.value.map((item) => {
|
|
1760
|
-
var
|
|
1791
|
+
var _a23, _b;
|
|
1761
1792
|
if (item.type === "image-url") {
|
|
1762
1793
|
const downloadedFile = downloadedAssets[new URL(item.url).toString()];
|
|
1763
1794
|
if (downloadedFile) {
|
|
1764
1795
|
return {
|
|
1765
1796
|
type: "image-data",
|
|
1766
1797
|
data: convertDataContentToBase64String(downloadedFile.data),
|
|
1767
|
-
mediaType: (
|
|
1798
|
+
mediaType: (_a23 = downloadedFile.mediaType) != null ? _a23 : "image/*",
|
|
1768
1799
|
providerOptions: item.providerOptions
|
|
1769
1800
|
};
|
|
1770
1801
|
}
|
|
@@ -1938,10 +1969,10 @@ async function prepareToolsAndToolChoice({
|
|
|
1938
1969
|
};
|
|
1939
1970
|
}
|
|
1940
1971
|
const filteredTools = activeTools != null ? Object.entries(tools).filter(
|
|
1941
|
-
([
|
|
1972
|
+
([name23]) => activeTools.includes(name23)
|
|
1942
1973
|
) : Object.entries(tools);
|
|
1943
1974
|
const languageModelTools = [];
|
|
1944
|
-
for (const [
|
|
1975
|
+
for (const [name23, tool2] of filteredTools) {
|
|
1945
1976
|
const toolType = tool2.type;
|
|
1946
1977
|
switch (toolType) {
|
|
1947
1978
|
case void 0:
|
|
@@ -1949,7 +1980,7 @@ async function prepareToolsAndToolChoice({
|
|
|
1949
1980
|
case "function":
|
|
1950
1981
|
languageModelTools.push({
|
|
1951
1982
|
type: "function",
|
|
1952
|
-
name:
|
|
1983
|
+
name: name23,
|
|
1953
1984
|
description: tool2.description,
|
|
1954
1985
|
inputSchema: await asSchema(tool2.inputSchema).jsonSchema,
|
|
1955
1986
|
...tool2.inputExamples != null ? { inputExamples: tool2.inputExamples } : {},
|
|
@@ -1960,7 +1991,7 @@ async function prepareToolsAndToolChoice({
|
|
|
1960
1991
|
case "provider":
|
|
1961
1992
|
languageModelTools.push({
|
|
1962
1993
|
type: "provider",
|
|
1963
|
-
name:
|
|
1994
|
+
name: name23,
|
|
1964
1995
|
id: tool2.id,
|
|
1965
1996
|
args: tool2.args
|
|
1966
1997
|
});
|
|
@@ -2260,14 +2291,14 @@ async function standardizePrompt({
|
|
|
2260
2291
|
|
|
2261
2292
|
// src/prompt/wrap-gateway-error.ts
|
|
2262
2293
|
import { GatewayAuthenticationError } from "@ai-sdk/gateway";
|
|
2263
|
-
import { AISDKError as
|
|
2294
|
+
import { AISDKError as AISDKError25 } from "@ai-sdk/provider";
|
|
2264
2295
|
function wrapGatewayError(error) {
|
|
2265
2296
|
if (!GatewayAuthenticationError.isInstance(error))
|
|
2266
2297
|
return error;
|
|
2267
2298
|
const isProductionEnv = (process == null ? void 0 : process.env.NODE_ENV) === "production";
|
|
2268
2299
|
const moreInfoURL = "https://ai-sdk.dev/unauthenticated-ai-gateway";
|
|
2269
2300
|
if (isProductionEnv) {
|
|
2270
|
-
return new
|
|
2301
|
+
return new AISDKError25({
|
|
2271
2302
|
name: "GatewayError",
|
|
2272
2303
|
message: `Unauthenticated. Configure AI_GATEWAY_API_KEY or use a provider module. Learn more: ${moreInfoURL}`
|
|
2273
2304
|
});
|
|
@@ -2308,7 +2339,7 @@ function getBaseTelemetryAttributes({
|
|
|
2308
2339
|
telemetry,
|
|
2309
2340
|
headers
|
|
2310
2341
|
}) {
|
|
2311
|
-
var
|
|
2342
|
+
var _a23;
|
|
2312
2343
|
return {
|
|
2313
2344
|
"ai.model.provider": model.provider,
|
|
2314
2345
|
"ai.model.id": model.modelId,
|
|
@@ -2327,7 +2358,7 @@ function getBaseTelemetryAttributes({
|
|
|
2327
2358
|
return attributes;
|
|
2328
2359
|
}, {}),
|
|
2329
2360
|
// add metadata as attributes:
|
|
2330
|
-
...Object.entries((
|
|
2361
|
+
...Object.entries((_a23 = telemetry == null ? void 0 : telemetry.metadata) != null ? _a23 : {}).reduce(
|
|
2331
2362
|
(attributes, [key, value]) => {
|
|
2332
2363
|
attributes[`ai.telemetry.metadata.${key}`] = value;
|
|
2333
2364
|
return attributes;
|
|
@@ -2352,7 +2383,7 @@ var noopTracer = {
|
|
|
2352
2383
|
startSpan() {
|
|
2353
2384
|
return noopSpan;
|
|
2354
2385
|
},
|
|
2355
|
-
startActiveSpan(
|
|
2386
|
+
startActiveSpan(name23, arg1, arg2, arg3) {
|
|
2356
2387
|
if (typeof arg1 === "function") {
|
|
2357
2388
|
return arg1(noopSpan);
|
|
2358
2389
|
}
|
|
@@ -2425,7 +2456,7 @@ import {
|
|
|
2425
2456
|
context
|
|
2426
2457
|
} from "@opentelemetry/api";
|
|
2427
2458
|
async function recordSpan({
|
|
2428
|
-
name:
|
|
2459
|
+
name: name23,
|
|
2429
2460
|
tracer,
|
|
2430
2461
|
attributes,
|
|
2431
2462
|
fn,
|
|
@@ -2433,7 +2464,7 @@ async function recordSpan({
|
|
|
2433
2464
|
endOnError = endWhenDone
|
|
2434
2465
|
}) {
|
|
2435
2466
|
return tracer.startActiveSpan(
|
|
2436
|
-
|
|
2467
|
+
name23,
|
|
2437
2468
|
{ attributes: await attributes },
|
|
2438
2469
|
async (span) => {
|
|
2439
2470
|
const ctx = context.active();
|
|
@@ -2563,15 +2594,15 @@ function registerTelemetryIntegration(integration) {
|
|
|
2563
2594
|
globalThis.AI_SDK_TELEMETRY_INTEGRATIONS.push(integration);
|
|
2564
2595
|
}
|
|
2565
2596
|
function getGlobalTelemetryIntegrations() {
|
|
2566
|
-
var
|
|
2567
|
-
return (
|
|
2597
|
+
var _a23;
|
|
2598
|
+
return (_a23 = globalThis.AI_SDK_TELEMETRY_INTEGRATIONS) != null ? _a23 : [];
|
|
2568
2599
|
}
|
|
2569
2600
|
|
|
2570
2601
|
// src/telemetry/get-global-telemetry-integration.ts
|
|
2571
2602
|
function bindTelemetryIntegration(integration) {
|
|
2572
|
-
var
|
|
2603
|
+
var _a23, _b, _c, _d, _e, _f;
|
|
2573
2604
|
return {
|
|
2574
|
-
onStart: (
|
|
2605
|
+
onStart: (_a23 = integration.onStart) == null ? void 0 : _a23.bind(integration),
|
|
2575
2606
|
onStepStart: (_b = integration.onStepStart) == null ? void 0 : _b.bind(integration),
|
|
2576
2607
|
onToolCallStart: (_c = integration.onToolCallStart) == null ? void 0 : _c.bind(integration),
|
|
2577
2608
|
onToolCallFinish: (_d = integration.onToolCallFinish) == null ? void 0 : _d.bind(integration),
|
|
@@ -2655,12 +2686,12 @@ function createNullLanguageModelUsage() {
|
|
|
2655
2686
|
};
|
|
2656
2687
|
}
|
|
2657
2688
|
function addLanguageModelUsage(usage1, usage2) {
|
|
2658
|
-
var
|
|
2689
|
+
var _a23, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2659
2690
|
return {
|
|
2660
2691
|
inputTokens: addTokenCounts(usage1.inputTokens, usage2.inputTokens),
|
|
2661
2692
|
inputTokenDetails: {
|
|
2662
2693
|
noCacheTokens: addTokenCounts(
|
|
2663
|
-
(
|
|
2694
|
+
(_a23 = usage1.inputTokenDetails) == null ? void 0 : _a23.noCacheTokens,
|
|
2664
2695
|
(_b = usage2.inputTokenDetails) == null ? void 0 : _b.noCacheTokens
|
|
2665
2696
|
),
|
|
2666
2697
|
cacheReadTokens: addTokenCounts(
|
|
@@ -2889,8 +2920,8 @@ import { executeTool } from "@ai-sdk/provider-utils";
|
|
|
2889
2920
|
|
|
2890
2921
|
// src/util/now.ts
|
|
2891
2922
|
function now() {
|
|
2892
|
-
var
|
|
2893
|
-
return (_b = (
|
|
2923
|
+
var _a23, _b;
|
|
2924
|
+
return (_b = (_a23 = globalThis == null ? void 0 : globalThis.performance) == null ? void 0 : _a23.now()) != null ? _b : Date.now();
|
|
2894
2925
|
}
|
|
2895
2926
|
|
|
2896
2927
|
// src/generate-text/execute-tool-call.ts
|
|
@@ -2908,7 +2939,7 @@ async function executeToolCall({
|
|
|
2908
2939
|
onToolCallStart,
|
|
2909
2940
|
onToolCallFinish
|
|
2910
2941
|
}) {
|
|
2911
|
-
var
|
|
2942
|
+
var _a23;
|
|
2912
2943
|
const { toolName, toolCallId, input } = toolCall;
|
|
2913
2944
|
const tool2 = tools == null ? void 0 : tools[toolName];
|
|
2914
2945
|
if ((tool2 == null ? void 0 : tool2.execute) == null) {
|
|
@@ -2934,7 +2965,7 @@ async function executeToolCall({
|
|
|
2934
2965
|
telemetry
|
|
2935
2966
|
}),
|
|
2936
2967
|
...Object.fromEntries(
|
|
2937
|
-
Object.entries((
|
|
2968
|
+
Object.entries((_a23 = telemetry == null ? void 0 : telemetry.metadata) != null ? _a23 : {}).map(([key, value]) => [
|
|
2938
2969
|
`ai.telemetry.metadata.${key}`,
|
|
2939
2970
|
value
|
|
2940
2971
|
])
|
|
@@ -3063,7 +3094,7 @@ function filterActiveTools({
|
|
|
3063
3094
|
}
|
|
3064
3095
|
return Object.fromEntries(
|
|
3065
3096
|
Object.entries(tools).filter(
|
|
3066
|
-
([
|
|
3097
|
+
([name23]) => activeTools.includes(name23)
|
|
3067
3098
|
)
|
|
3068
3099
|
);
|
|
3069
3100
|
}
|
|
@@ -3235,7 +3266,7 @@ async function validateApprovedToolApprovals({
|
|
|
3235
3266
|
experimental_context,
|
|
3236
3267
|
toolApprovalSecret
|
|
3237
3268
|
}) {
|
|
3238
|
-
var
|
|
3269
|
+
var _a23;
|
|
3239
3270
|
const approved = [];
|
|
3240
3271
|
const denied = [];
|
|
3241
3272
|
const invalid = [];
|
|
@@ -3297,7 +3328,7 @@ async function validateApprovedToolApprovals({
|
|
|
3297
3328
|
approvalResponse: {
|
|
3298
3329
|
...approval.approvalResponse,
|
|
3299
3330
|
approved: false,
|
|
3300
|
-
reason: (
|
|
3331
|
+
reason: (_a23 = approval.approvalResponse.reason) != null ? _a23 : `Tool "${toolCall.toolName}" does not require approval`
|
|
3301
3332
|
}
|
|
3302
3333
|
});
|
|
3303
3334
|
}
|
|
@@ -3700,7 +3731,7 @@ var text = () => ({
|
|
|
3700
3731
|
});
|
|
3701
3732
|
var object = ({
|
|
3702
3733
|
schema: inputSchema,
|
|
3703
|
-
name:
|
|
3734
|
+
name: name23,
|
|
3704
3735
|
description
|
|
3705
3736
|
}) => {
|
|
3706
3737
|
const schema = asSchema3(inputSchema);
|
|
@@ -3709,7 +3740,7 @@ var object = ({
|
|
|
3709
3740
|
responseFormat: resolve(schema.jsonSchema).then((jsonSchema2) => ({
|
|
3710
3741
|
type: "json",
|
|
3711
3742
|
schema: jsonSchema2,
|
|
3712
|
-
...
|
|
3743
|
+
...name23 != null && { name: name23 },
|
|
3713
3744
|
...description != null && { description }
|
|
3714
3745
|
})),
|
|
3715
3746
|
async parseCompleteOutput({ text: text2 }, context2) {
|
|
@@ -3763,7 +3794,7 @@ var object = ({
|
|
|
3763
3794
|
};
|
|
3764
3795
|
var array = ({
|
|
3765
3796
|
element: inputElementSchema,
|
|
3766
|
-
name:
|
|
3797
|
+
name: name23,
|
|
3767
3798
|
description
|
|
3768
3799
|
}) => {
|
|
3769
3800
|
const elementSchema = asSchema3(inputElementSchema);
|
|
@@ -3783,7 +3814,7 @@ var array = ({
|
|
|
3783
3814
|
required: ["elements"],
|
|
3784
3815
|
additionalProperties: false
|
|
3785
3816
|
},
|
|
3786
|
-
...
|
|
3817
|
+
...name23 != null && { name: name23 },
|
|
3787
3818
|
...description != null && { description }
|
|
3788
3819
|
};
|
|
3789
3820
|
}),
|
|
@@ -3877,7 +3908,7 @@ var array = ({
|
|
|
3877
3908
|
};
|
|
3878
3909
|
var choice = ({
|
|
3879
3910
|
options: choiceOptions,
|
|
3880
|
-
name:
|
|
3911
|
+
name: name23,
|
|
3881
3912
|
description
|
|
3882
3913
|
}) => {
|
|
3883
3914
|
return {
|
|
@@ -3894,7 +3925,7 @@ var choice = ({
|
|
|
3894
3925
|
required: ["result"],
|
|
3895
3926
|
additionalProperties: false
|
|
3896
3927
|
},
|
|
3897
|
-
...
|
|
3928
|
+
...name23 != null && { name: name23 },
|
|
3898
3929
|
...description != null && { description }
|
|
3899
3930
|
}),
|
|
3900
3931
|
async parseCompleteOutput({ text: text2 }, context2) {
|
|
@@ -3955,14 +3986,14 @@ var choice = ({
|
|
|
3955
3986
|
};
|
|
3956
3987
|
};
|
|
3957
3988
|
var json = ({
|
|
3958
|
-
name:
|
|
3989
|
+
name: name23,
|
|
3959
3990
|
description
|
|
3960
3991
|
} = {}) => {
|
|
3961
3992
|
return {
|
|
3962
3993
|
name: "json",
|
|
3963
3994
|
responseFormat: Promise.resolve({
|
|
3964
3995
|
type: "json",
|
|
3965
|
-
...
|
|
3996
|
+
...name23 != null && { name: name23 },
|
|
3966
3997
|
...description != null && { description }
|
|
3967
3998
|
}),
|
|
3968
3999
|
async parseCompleteOutput({ text: text2 }, context2) {
|
|
@@ -4137,9 +4168,9 @@ function prepareStepCallSettings({
|
|
|
4137
4168
|
callSettings,
|
|
4138
4169
|
stepSettings
|
|
4139
4170
|
}) {
|
|
4140
|
-
var
|
|
4171
|
+
var _a23, _b, _c, _d, _e, _f, _g, _h;
|
|
4141
4172
|
return prepareCallSettings({
|
|
4142
|
-
maxOutputTokens: (
|
|
4173
|
+
maxOutputTokens: (_a23 = stepSettings == null ? void 0 : stepSettings.maxOutputTokens) != null ? _a23 : callSettings.maxOutputTokens,
|
|
4143
4174
|
temperature: (_b = stepSettings == null ? void 0 : stepSettings.temperature) != null ? _b : callSettings.temperature,
|
|
4144
4175
|
topP: (_c = stepSettings == null ? void 0 : stepSettings.topP) != null ? _c : callSettings.topP,
|
|
4145
4176
|
topK: (_d = stepSettings == null ? void 0 : stepSettings.topK) != null ? _d : callSettings.topK,
|
|
@@ -4233,8 +4264,8 @@ function isLoopFinished() {
|
|
|
4233
4264
|
}
|
|
4234
4265
|
function hasToolCall(toolName) {
|
|
4235
4266
|
return ({ steps }) => {
|
|
4236
|
-
var
|
|
4237
|
-
return (_c = (_b = (
|
|
4267
|
+
var _a23, _b, _c;
|
|
4268
|
+
return (_c = (_b = (_a23 = steps[steps.length - 1]) == null ? void 0 : _a23.toolCalls) == null ? void 0 : _b.some(
|
|
4238
4269
|
(toolCall) => toolCall.toolName === toolName
|
|
4239
4270
|
)) != null ? _c : false;
|
|
4240
4271
|
};
|
|
@@ -4564,7 +4595,7 @@ async function generateText({
|
|
|
4564
4595
|
}),
|
|
4565
4596
|
tracer,
|
|
4566
4597
|
fn: async (span) => {
|
|
4567
|
-
var
|
|
4598
|
+
var _a23, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
4568
4599
|
const initialMessages = initialPrompt.messages;
|
|
4569
4600
|
const responseMessages = [];
|
|
4570
4601
|
const {
|
|
@@ -4689,7 +4720,7 @@ async function generateText({
|
|
|
4689
4720
|
experimental_context
|
|
4690
4721
|
}));
|
|
4691
4722
|
const stepModel = resolveLanguageModel(
|
|
4692
|
-
(
|
|
4723
|
+
(_a23 = prepareStepResult == null ? void 0 : prepareStepResult.model) != null ? _a23 : model
|
|
4693
4724
|
);
|
|
4694
4725
|
const stepModelInfo = {
|
|
4695
4726
|
provider: stepModel.provider,
|
|
@@ -4789,7 +4820,7 @@ async function generateText({
|
|
|
4789
4820
|
}),
|
|
4790
4821
|
tracer,
|
|
4791
4822
|
fn: async (span2) => {
|
|
4792
|
-
var
|
|
4823
|
+
var _a24, _b2, _c2, _d2, _e2, _f2, _g2, _h2;
|
|
4793
4824
|
const result = await stepModel.doGenerate({
|
|
4794
4825
|
...stepCallSettings,
|
|
4795
4826
|
tools: stepTools,
|
|
@@ -4801,7 +4832,7 @@ async function generateText({
|
|
|
4801
4832
|
headers: headersWithUserAgent
|
|
4802
4833
|
});
|
|
4803
4834
|
const responseData = {
|
|
4804
|
-
id: (_b2 = (
|
|
4835
|
+
id: (_b2 = (_a24 = result.response) == null ? void 0 : _a24.id) != null ? _b2 : generateId2(),
|
|
4805
4836
|
timestamp: (_d2 = (_c2 = result.response) == null ? void 0 : _c2.timestamp) != null ? _d2 : /* @__PURE__ */ new Date(),
|
|
4806
4837
|
modelId: (_f2 = (_e2 = result.response) == null ? void 0 : _e2.modelId) != null ? _f2 : stepModel.modelId,
|
|
4807
4838
|
headers: (_g2 = result.response) == null ? void 0 : _g2.headers,
|
|
@@ -4869,6 +4900,18 @@ async function generateText({
|
|
|
4869
4900
|
})
|
|
4870
4901
|
)
|
|
4871
4902
|
);
|
|
4903
|
+
const enforcedToolChoice = (stepToolChoice == null ? void 0 : stepToolChoice.type) === "required" || (stepToolChoice == null ? void 0 : stepToolChoice.type) === "tool" ? stepToolChoice : void 0;
|
|
4904
|
+
if (enforcedToolChoice != null && !stepToolCalls.some(
|
|
4905
|
+
(toolCall) => enforcedToolChoice.type === "required" || toolCall.toolName === enforcedToolChoice.toolName
|
|
4906
|
+
)) {
|
|
4907
|
+
throw new ToolChoiceViolationError({
|
|
4908
|
+
toolChoice: enforcedToolChoice,
|
|
4909
|
+
finishReason: currentModelResponse.finishReason.unified,
|
|
4910
|
+
provider: stepModel.provider,
|
|
4911
|
+
modelId: stepModel.modelId,
|
|
4912
|
+
content: currentModelResponse.content
|
|
4913
|
+
});
|
|
4914
|
+
}
|
|
4872
4915
|
const toolApprovalRequests = {};
|
|
4873
4916
|
for (const toolCall of stepToolCalls) {
|
|
4874
4917
|
if (toolCall.invalid) {
|
|
@@ -5793,7 +5836,7 @@ function processUIMessageStream({
|
|
|
5793
5836
|
new TransformStream({
|
|
5794
5837
|
async transform(chunk, controller) {
|
|
5795
5838
|
await runUpdateMessageJob(async ({ state, write }) => {
|
|
5796
|
-
var
|
|
5839
|
+
var _a23, _b, _c, _d;
|
|
5797
5840
|
function getCurrentStepParts() {
|
|
5798
5841
|
const parts = state.message.parts;
|
|
5799
5842
|
let currentStepStartIndex = parts.length - 1;
|
|
@@ -5830,7 +5873,7 @@ function processUIMessageStream({
|
|
|
5830
5873
|
return toolInvocation;
|
|
5831
5874
|
}
|
|
5832
5875
|
function updateToolPart(options, existingPart) {
|
|
5833
|
-
var
|
|
5876
|
+
var _a24;
|
|
5834
5877
|
const part = existingPart != null ? existingPart : getCurrentStepParts().find(
|
|
5835
5878
|
(part2) => isStaticToolUIPart(part2) && part2.toolCallId === options.toolCallId
|
|
5836
5879
|
);
|
|
@@ -5849,7 +5892,7 @@ function processUIMessageStream({
|
|
|
5849
5892
|
if (options.toolMetadata !== void 0) {
|
|
5850
5893
|
anyPart.toolMetadata = options.toolMetadata;
|
|
5851
5894
|
}
|
|
5852
|
-
anyPart.providerExecuted = (
|
|
5895
|
+
anyPart.providerExecuted = (_a24 = anyOptions.providerExecuted) != null ? _a24 : part.providerExecuted;
|
|
5853
5896
|
const providerMetadata = anyOptions.providerMetadata;
|
|
5854
5897
|
if (providerMetadata != null) {
|
|
5855
5898
|
if (options.state === "output-available" || options.state === "output-error") {
|
|
@@ -5878,7 +5921,7 @@ function processUIMessageStream({
|
|
|
5878
5921
|
}
|
|
5879
5922
|
}
|
|
5880
5923
|
function updateDynamicToolPart(options, existingPart) {
|
|
5881
|
-
var
|
|
5924
|
+
var _a24, _b2;
|
|
5882
5925
|
const part = existingPart != null ? existingPart : getCurrentStepParts().find(
|
|
5883
5926
|
(part2) => part2.type === "dynamic-tool" && part2.toolCallId === options.toolCallId
|
|
5884
5927
|
);
|
|
@@ -5890,7 +5933,7 @@ function processUIMessageStream({
|
|
|
5890
5933
|
anyPart.input = anyOptions.input;
|
|
5891
5934
|
anyPart.output = anyOptions.output;
|
|
5892
5935
|
anyPart.errorText = anyOptions.errorText;
|
|
5893
|
-
anyPart.rawInput = (
|
|
5936
|
+
anyPart.rawInput = (_a24 = anyOptions.rawInput) != null ? _a24 : anyPart.rawInput;
|
|
5894
5937
|
anyPart.preliminary = anyOptions.preliminary;
|
|
5895
5938
|
if (options.title !== void 0) {
|
|
5896
5939
|
anyPart.title = options.title;
|
|
@@ -5965,7 +6008,7 @@ function processUIMessageStream({
|
|
|
5965
6008
|
});
|
|
5966
6009
|
}
|
|
5967
6010
|
textPart.text += chunk.delta;
|
|
5968
|
-
textPart.providerMetadata = (
|
|
6011
|
+
textPart.providerMetadata = (_a23 = chunk.providerMetadata) != null ? _a23 : textPart.providerMetadata;
|
|
5969
6012
|
write();
|
|
5970
6013
|
break;
|
|
5971
6014
|
}
|
|
@@ -6432,13 +6475,13 @@ function handleUIMessageStreamFinish({
|
|
|
6432
6475
|
};
|
|
6433
6476
|
let finishCalled = false;
|
|
6434
6477
|
const callOnFinish = async () => {
|
|
6435
|
-
var
|
|
6478
|
+
var _a23;
|
|
6436
6479
|
if (finishCalled || !onFinish) {
|
|
6437
6480
|
return;
|
|
6438
6481
|
}
|
|
6439
6482
|
finishCalled = true;
|
|
6440
6483
|
const isContinuation = state.message.id === (lastMessage == null ? void 0 : lastMessage.id);
|
|
6441
|
-
const declaredOutcome = (
|
|
6484
|
+
const declaredOutcome = (_a23 = getOutcome == null ? void 0 : getOutcome()) != null ? _a23 : { status: "unknown" };
|
|
6442
6485
|
const outcome = hasProcessingFailure ? { status: "failed", error: processingError } : declaredOutcome.status === "unknown" && isAborted ? { status: "aborted" } : declaredOutcome;
|
|
6443
6486
|
await onFinish({
|
|
6444
6487
|
isAborted: isAborted || outcome.status === "aborted",
|
|
@@ -6532,13 +6575,13 @@ function createAsyncIterableStream(source) {
|
|
|
6532
6575
|
const reader = this.getReader();
|
|
6533
6576
|
let finished = false;
|
|
6534
6577
|
async function cleanup(cancelStream) {
|
|
6535
|
-
var
|
|
6578
|
+
var _a23;
|
|
6536
6579
|
if (finished)
|
|
6537
6580
|
return;
|
|
6538
6581
|
finished = true;
|
|
6539
6582
|
try {
|
|
6540
6583
|
if (cancelStream) {
|
|
6541
|
-
await ((
|
|
6584
|
+
await ((_a23 = reader.cancel) == null ? void 0 : _a23.call(reader));
|
|
6542
6585
|
}
|
|
6543
6586
|
} finally {
|
|
6544
6587
|
try {
|
|
@@ -6653,7 +6696,7 @@ function createStitchableStream() {
|
|
|
6653
6696
|
controller == null ? void 0 : controller.close();
|
|
6654
6697
|
};
|
|
6655
6698
|
const processPull = async () => {
|
|
6656
|
-
var
|
|
6699
|
+
var _a23;
|
|
6657
6700
|
if (isCancelled) {
|
|
6658
6701
|
return;
|
|
6659
6702
|
}
|
|
@@ -6686,7 +6729,7 @@ function createStitchableStream() {
|
|
|
6686
6729
|
if (isCancelled) {
|
|
6687
6730
|
return;
|
|
6688
6731
|
}
|
|
6689
|
-
(
|
|
6732
|
+
(_a23 = currentStream.onError) == null ? void 0 : _a23.call(currentStream, error);
|
|
6690
6733
|
controller == null ? void 0 : controller.error(error);
|
|
6691
6734
|
innerStreams.shift();
|
|
6692
6735
|
terminate();
|
|
@@ -6710,9 +6753,9 @@ function createStitchableStream() {
|
|
|
6710
6753
|
}
|
|
6711
6754
|
}),
|
|
6712
6755
|
addStream: (innerStream, callbacks) => {
|
|
6713
|
-
var
|
|
6756
|
+
var _a23;
|
|
6714
6757
|
if (isCancelled) {
|
|
6715
|
-
(
|
|
6758
|
+
(_a23 = callbacks == null ? void 0 : callbacks.onCancel) == null ? void 0 : _a23.call(callbacks);
|
|
6716
6759
|
void innerStream.cancel().catch(() => {
|
|
6717
6760
|
});
|
|
6718
6761
|
return;
|
|
@@ -7193,7 +7236,7 @@ function createOutputTransformStream(output) {
|
|
|
7193
7236
|
}
|
|
7194
7237
|
return new TransformStream({
|
|
7195
7238
|
async transform(chunk, controller) {
|
|
7196
|
-
var
|
|
7239
|
+
var _a23;
|
|
7197
7240
|
if (chunk.type === "finish-step" && textChunk.length > 0) {
|
|
7198
7241
|
publishTextChunk({ controller });
|
|
7199
7242
|
}
|
|
@@ -7220,7 +7263,7 @@ function createOutputTransformStream(output) {
|
|
|
7220
7263
|
}
|
|
7221
7264
|
text2 += chunk.text;
|
|
7222
7265
|
textChunk += chunk.text;
|
|
7223
|
-
textProviderMetadata = (
|
|
7266
|
+
textProviderMetadata = (_a23 = chunk.providerMetadata) != null ? _a23 : textProviderMetadata;
|
|
7224
7267
|
if (chunk.text.length === 0 && chunk.providerMetadata != null) {
|
|
7225
7268
|
controller.enqueue({ part: chunk, partialOutput: void 0 });
|
|
7226
7269
|
return;
|
|
@@ -7326,7 +7369,7 @@ var DefaultStreamTextResult = class {
|
|
|
7326
7369
|
let activeReasoningContent = createIdMap();
|
|
7327
7370
|
const eventProcessor = new TransformStream({
|
|
7328
7371
|
async transform(chunk, controller) {
|
|
7329
|
-
var
|
|
7372
|
+
var _a23, _b, _c, _d;
|
|
7330
7373
|
controller.enqueue(chunk);
|
|
7331
7374
|
const { part } = chunk;
|
|
7332
7375
|
if (part.type === "text-delta" || part.type === "reasoning-delta" || part.type === "source" || part.type === "tool-call" || part.type === "tool-result" || part.type === "tool-input-start" || part.type === "tool-input-delta" || part.type === "raw") {
|
|
@@ -7366,7 +7409,7 @@ var DefaultStreamTextResult = class {
|
|
|
7366
7409
|
return;
|
|
7367
7410
|
}
|
|
7368
7411
|
activeText.text += part.text;
|
|
7369
|
-
activeText.providerMetadata = (
|
|
7412
|
+
activeText.providerMetadata = (_a23 = part.providerMetadata) != null ? _a23 : activeText.providerMetadata;
|
|
7370
7413
|
}
|
|
7371
7414
|
if (part.type === "text-end") {
|
|
7372
7415
|
const activeText = activeTextContent[part.id];
|
|
@@ -7492,7 +7535,7 @@ var DefaultStreamTextResult = class {
|
|
|
7492
7535
|
}
|
|
7493
7536
|
},
|
|
7494
7537
|
async flush(controller) {
|
|
7495
|
-
var
|
|
7538
|
+
var _a23, _b, _c, _d, _e, _f, _g;
|
|
7496
7539
|
try {
|
|
7497
7540
|
if (recordedSteps.length === 0 || recordedNoOutputError != null) {
|
|
7498
7541
|
const error = (abortSignal == null ? void 0 : abortSignal.aborted) ? abortSignal.reason : recordedNoOutputError != null ? recordedNoOutputError : new NoOutputGeneratedError({
|
|
@@ -7511,40 +7554,51 @@ var DefaultStreamTextResult = class {
|
|
|
7511
7554
|
self._totalUsage.resolve(totalUsage);
|
|
7512
7555
|
self._steps.resolve(recordedSteps);
|
|
7513
7556
|
const finalStep = recordedSteps[recordedSteps.length - 1];
|
|
7514
|
-
|
|
7515
|
-
|
|
7516
|
-
|
|
7517
|
-
|
|
7518
|
-
|
|
7519
|
-
|
|
7520
|
-
|
|
7521
|
-
|
|
7522
|
-
|
|
7523
|
-
|
|
7524
|
-
|
|
7525
|
-
|
|
7526
|
-
|
|
7527
|
-
|
|
7528
|
-
|
|
7529
|
-
|
|
7530
|
-
|
|
7531
|
-
|
|
7532
|
-
|
|
7533
|
-
|
|
7534
|
-
|
|
7535
|
-
|
|
7536
|
-
|
|
7537
|
-
|
|
7538
|
-
|
|
7539
|
-
|
|
7540
|
-
|
|
7541
|
-
|
|
7542
|
-
|
|
7543
|
-
|
|
7544
|
-
|
|
7545
|
-
|
|
7546
|
-
|
|
7547
|
-
|
|
7557
|
+
const onFinishEvent = {
|
|
7558
|
+
stepNumber: finalStep.stepNumber,
|
|
7559
|
+
model: finalStep.model,
|
|
7560
|
+
functionId: finalStep.functionId,
|
|
7561
|
+
metadata: finalStep.metadata,
|
|
7562
|
+
experimental_context: finalStep.experimental_context,
|
|
7563
|
+
finishReason: finalStep.finishReason,
|
|
7564
|
+
rawFinishReason: finalStep.rawFinishReason,
|
|
7565
|
+
totalUsage,
|
|
7566
|
+
usage: finalStep.usage,
|
|
7567
|
+
content: finalStep.content,
|
|
7568
|
+
text: finalStep.text,
|
|
7569
|
+
reasoningText: finalStep.reasoningText,
|
|
7570
|
+
reasoning: finalStep.reasoning,
|
|
7571
|
+
files: finalStep.files,
|
|
7572
|
+
sources: finalStep.sources,
|
|
7573
|
+
toolCalls: finalStep.toolCalls,
|
|
7574
|
+
staticToolCalls: finalStep.staticToolCalls,
|
|
7575
|
+
dynamicToolCalls: finalStep.dynamicToolCalls,
|
|
7576
|
+
toolResults: finalStep.toolResults,
|
|
7577
|
+
staticToolResults: finalStep.staticToolResults,
|
|
7578
|
+
dynamicToolResults: finalStep.dynamicToolResults,
|
|
7579
|
+
request: finalStep.request,
|
|
7580
|
+
response: finalStep.response,
|
|
7581
|
+
warnings: finalStep.warnings,
|
|
7582
|
+
providerMetadata: finalStep.providerMetadata,
|
|
7583
|
+
steps: recordedSteps
|
|
7584
|
+
};
|
|
7585
|
+
const onFinishWithOutput = onFinish == null ? void 0 : async (event) => {
|
|
7586
|
+
const parsedOutput = output == null ? void 0 : await self.getOutputPromise().catch(() => void 0);
|
|
7587
|
+
await onFinish({
|
|
7588
|
+
...event,
|
|
7589
|
+
...output != null ? { output: parsedOutput } : {}
|
|
7590
|
+
});
|
|
7591
|
+
};
|
|
7592
|
+
await Promise.all([
|
|
7593
|
+
notify({
|
|
7594
|
+
event: onFinishEvent,
|
|
7595
|
+
callbacks: onFinishWithOutput
|
|
7596
|
+
}),
|
|
7597
|
+
notify({
|
|
7598
|
+
event: onFinishEvent,
|
|
7599
|
+
callbacks: globalTelemetry.onFinish
|
|
7600
|
+
})
|
|
7601
|
+
]);
|
|
7548
7602
|
rootSpan.setAttributes(
|
|
7549
7603
|
await selectTelemetryAttributes({
|
|
7550
7604
|
telemetry,
|
|
@@ -7556,15 +7610,15 @@ var DefaultStreamTextResult = class {
|
|
|
7556
7610
|
},
|
|
7557
7611
|
"ai.response.toolCalls": {
|
|
7558
7612
|
output: () => {
|
|
7559
|
-
var
|
|
7560
|
-
return ((
|
|
7613
|
+
var _a24;
|
|
7614
|
+
return ((_a24 = finalStep.toolCalls) == null ? void 0 : _a24.length) ? JSON.stringify(finalStep.toolCalls) : void 0;
|
|
7561
7615
|
}
|
|
7562
7616
|
},
|
|
7563
7617
|
"ai.response.providerMetadata": JSON.stringify(
|
|
7564
7618
|
finalStep.providerMetadata
|
|
7565
7619
|
),
|
|
7566
7620
|
"ai.usage.inputTokens": totalUsage.inputTokens,
|
|
7567
|
-
"ai.usage.inputTokenDetails.noCacheTokens": (
|
|
7621
|
+
"ai.usage.inputTokenDetails.noCacheTokens": (_a23 = totalUsage.inputTokenDetails) == null ? void 0 : _a23.noCacheTokens,
|
|
7568
7622
|
"ai.usage.inputTokenDetails.cacheReadTokens": (_b = totalUsage.inputTokenDetails) == null ? void 0 : _b.cacheReadTokens,
|
|
7569
7623
|
"ai.usage.inputTokenDetails.cacheWriteTokens": (_c = totalUsage.inputTokenDetails) == null ? void 0 : _c.cacheWriteTokens,
|
|
7570
7624
|
"ai.usage.outputTokens": totalUsage.outputTokens,
|
|
@@ -7854,7 +7908,7 @@ var DefaultStreamTextResult = class {
|
|
|
7854
7908
|
responseMessages,
|
|
7855
7909
|
usage
|
|
7856
7910
|
}) {
|
|
7857
|
-
var
|
|
7911
|
+
var _a23, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
7858
7912
|
const includeRawChunks2 = self.includeRawChunks;
|
|
7859
7913
|
const stepTimeoutId = setAbortTimeout({
|
|
7860
7914
|
abortController: stepAbortController,
|
|
@@ -7905,7 +7959,7 @@ var DefaultStreamTextResult = class {
|
|
|
7905
7959
|
experimental_context
|
|
7906
7960
|
}));
|
|
7907
7961
|
const stepModel = resolveLanguageModel(
|
|
7908
|
-
(
|
|
7962
|
+
(_a23 = prepareStepResult == null ? void 0 : prepareStepResult.model) != null ? _a23 : model
|
|
7909
7963
|
);
|
|
7910
7964
|
const stepModelInfo = {
|
|
7911
7965
|
provider: stepModel.provider,
|
|
@@ -8075,7 +8129,7 @@ var DefaultStreamTextResult = class {
|
|
|
8075
8129
|
streamWithToolResults.pipeThrough(
|
|
8076
8130
|
new TransformStream({
|
|
8077
8131
|
async transform(chunk, controller) {
|
|
8078
|
-
var
|
|
8132
|
+
var _a24, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i2;
|
|
8079
8133
|
resetChunkTimeout();
|
|
8080
8134
|
if (chunk.type === "stream-start") {
|
|
8081
8135
|
warnings = chunk.warnings;
|
|
@@ -8114,7 +8168,7 @@ var DefaultStreamTextResult = class {
|
|
|
8114
8168
|
case "text-end": {
|
|
8115
8169
|
controller.enqueue({
|
|
8116
8170
|
...chunk,
|
|
8117
|
-
id: (
|
|
8171
|
+
id: (_a24 = textPartIds.get(chunk.id)) != null ? _a24 : chunk.id
|
|
8118
8172
|
});
|
|
8119
8173
|
textPartIds.delete(chunk.id);
|
|
8120
8174
|
break;
|
|
@@ -8261,7 +8315,7 @@ var DefaultStreamTextResult = class {
|
|
|
8261
8315
|
},
|
|
8262
8316
|
// invoke onFinish callback and resolve toolResults promise when the stream is about to close:
|
|
8263
8317
|
async flush(controller) {
|
|
8264
|
-
var
|
|
8318
|
+
var _a24, _b2, _c2, _d2, _e2, _f2, _g2;
|
|
8265
8319
|
if (!hasReceivedTerminalChunk && !hasReceivedOutputChunk) {
|
|
8266
8320
|
controller.enqueue({
|
|
8267
8321
|
type: "error",
|
|
@@ -8288,7 +8342,7 @@ var DefaultStreamTextResult = class {
|
|
|
8288
8342
|
"ai.response.model": stepResponse.modelId,
|
|
8289
8343
|
"ai.response.timestamp": stepResponse.timestamp.toISOString(),
|
|
8290
8344
|
"ai.usage.inputTokens": stepUsage.inputTokens,
|
|
8291
|
-
"ai.usage.inputTokenDetails.noCacheTokens": (
|
|
8345
|
+
"ai.usage.inputTokenDetails.noCacheTokens": (_a24 = stepUsage.inputTokenDetails) == null ? void 0 : _a24.noCacheTokens,
|
|
8292
8346
|
"ai.usage.inputTokenDetails.cacheReadTokens": (_b2 = stepUsage.inputTokenDetails) == null ? void 0 : _b2.cacheReadTokens,
|
|
8293
8347
|
"ai.usage.inputTokenDetails.cacheWriteTokens": (_c2 = stepUsage.inputTokenDetails) == null ? void 0 : _c2.cacheWriteTokens,
|
|
8294
8348
|
"ai.usage.outputTokens": stepUsage.outputTokens,
|
|
@@ -8565,19 +8619,19 @@ var DefaultStreamTextResult = class {
|
|
|
8565
8619
|
this._steps.reject(error);
|
|
8566
8620
|
}
|
|
8567
8621
|
async consumeStream(options) {
|
|
8568
|
-
var
|
|
8622
|
+
var _a23;
|
|
8569
8623
|
try {
|
|
8570
8624
|
await consumeStream({
|
|
8571
8625
|
stream: this.fullStream,
|
|
8572
8626
|
onError: (error) => {
|
|
8573
|
-
var
|
|
8627
|
+
var _a24;
|
|
8574
8628
|
this.rejectResultPromises(error);
|
|
8575
|
-
(
|
|
8629
|
+
(_a24 = options == null ? void 0 : options.onError) == null ? void 0 : _a24.call(options, error);
|
|
8576
8630
|
}
|
|
8577
8631
|
});
|
|
8578
8632
|
} catch (error) {
|
|
8579
8633
|
this.rejectResultPromises(error);
|
|
8580
|
-
(
|
|
8634
|
+
(_a23 = options == null ? void 0 : options.onError) == null ? void 0 : _a23.call(options, error);
|
|
8581
8635
|
}
|
|
8582
8636
|
}
|
|
8583
8637
|
get experimental_partialOutputStream() {
|
|
@@ -8597,8 +8651,8 @@ var DefaultStreamTextResult = class {
|
|
|
8597
8651
|
);
|
|
8598
8652
|
}
|
|
8599
8653
|
get elementStream() {
|
|
8600
|
-
var
|
|
8601
|
-
const transform = (
|
|
8654
|
+
var _a23, _b, _c;
|
|
8655
|
+
const transform = (_a23 = this.outputSpecification) == null ? void 0 : _a23.createElementStreamTransform();
|
|
8602
8656
|
if (transform == null) {
|
|
8603
8657
|
throw new UnsupportedFunctionalityError2({
|
|
8604
8658
|
functionality: `element streams in ${(_c = (_b = this.outputSpecification) == null ? void 0 : _b.name) != null ? _c : "text"} mode`
|
|
@@ -8606,19 +8660,25 @@ var DefaultStreamTextResult = class {
|
|
|
8606
8660
|
}
|
|
8607
8661
|
return createAsyncIterableStream(this.teeStream().pipeThrough(transform));
|
|
8608
8662
|
}
|
|
8663
|
+
getOutputPromise() {
|
|
8664
|
+
if (this.outputPromise == null) {
|
|
8665
|
+
this.outputPromise = this.finalStep.then((step) => {
|
|
8666
|
+
var _a23;
|
|
8667
|
+
const output = (_a23 = this.outputSpecification) != null ? _a23 : text();
|
|
8668
|
+
return output.parseCompleteOutput(
|
|
8669
|
+
{ text: step.text },
|
|
8670
|
+
{
|
|
8671
|
+
response: step.response,
|
|
8672
|
+
usage: step.usage,
|
|
8673
|
+
finishReason: step.finishReason
|
|
8674
|
+
}
|
|
8675
|
+
);
|
|
8676
|
+
});
|
|
8677
|
+
}
|
|
8678
|
+
return this.outputPromise;
|
|
8679
|
+
}
|
|
8609
8680
|
get output() {
|
|
8610
|
-
return this.
|
|
8611
|
-
var _a22;
|
|
8612
|
-
const output = (_a22 = this.outputSpecification) != null ? _a22 : text();
|
|
8613
|
-
return output.parseCompleteOutput(
|
|
8614
|
-
{ text: step.text },
|
|
8615
|
-
{
|
|
8616
|
-
response: step.response,
|
|
8617
|
-
usage: step.usage,
|
|
8618
|
-
finishReason: step.finishReason
|
|
8619
|
-
}
|
|
8620
|
-
);
|
|
8621
|
-
});
|
|
8681
|
+
return this.getOutputPromise();
|
|
8622
8682
|
}
|
|
8623
8683
|
toUIMessageStream({
|
|
8624
8684
|
originalMessages,
|
|
@@ -8648,8 +8708,8 @@ var DefaultStreamTextResult = class {
|
|
|
8648
8708
|
responseMessageId: generateMessageId
|
|
8649
8709
|
}) : void 0;
|
|
8650
8710
|
const isDynamic = (part) => {
|
|
8651
|
-
var
|
|
8652
|
-
const tool2 = (
|
|
8711
|
+
var _a23;
|
|
8712
|
+
const tool2 = (_a23 = this.tools) == null ? void 0 : _a23[part.toolName];
|
|
8653
8713
|
if (tool2 == null) {
|
|
8654
8714
|
return part.dynamic;
|
|
8655
8715
|
}
|
|
@@ -9047,7 +9107,7 @@ var ToolLoopAgent = class {
|
|
|
9047
9107
|
return this.settings.tools;
|
|
9048
9108
|
}
|
|
9049
9109
|
async prepareCall(options) {
|
|
9050
|
-
var
|
|
9110
|
+
var _a23, _b, _c, _d;
|
|
9051
9111
|
if (this.settings.callOptionsSchema != null && options.options !== void 0) {
|
|
9052
9112
|
const validatedOptions = await validateTypes2({
|
|
9053
9113
|
value: options.options,
|
|
@@ -9059,7 +9119,7 @@ var ToolLoopAgent = class {
|
|
|
9059
9119
|
const { onStepFinish: _settingsOnStepFinish, ...settingsWithoutCallback } = this.settings;
|
|
9060
9120
|
const baseCallArgs = {
|
|
9061
9121
|
...settingsWithoutCallback,
|
|
9062
|
-
stopWhen: (
|
|
9122
|
+
stopWhen: (_a23 = this.settings.stopWhen) != null ? _a23 : stepCountIs(20),
|
|
9063
9123
|
...options
|
|
9064
9124
|
};
|
|
9065
9125
|
const preparedCallArgs = (_d = await ((_c = (_b = this.settings).prepareCall) == null ? void 0 : _c.call(
|
|
@@ -9273,7 +9333,7 @@ function readUIMessageStream({
|
|
|
9273
9333
|
onError,
|
|
9274
9334
|
terminateOnError = false
|
|
9275
9335
|
}) {
|
|
9276
|
-
var
|
|
9336
|
+
var _a23;
|
|
9277
9337
|
let controller;
|
|
9278
9338
|
let hasErrored = false;
|
|
9279
9339
|
const outputStream = new ReadableStream({
|
|
@@ -9282,7 +9342,7 @@ function readUIMessageStream({
|
|
|
9282
9342
|
}
|
|
9283
9343
|
});
|
|
9284
9344
|
const state = createStreamingUIMessageState({
|
|
9285
|
-
messageId: (
|
|
9345
|
+
messageId: (_a23 = message == null ? void 0 : message.id) != null ? _a23 : "",
|
|
9286
9346
|
lastMessage: message
|
|
9287
9347
|
});
|
|
9288
9348
|
const handleError = (error) => {
|
|
@@ -9351,7 +9411,7 @@ async function convertToModelMessages(messages, options) {
|
|
|
9351
9411
|
modelMessages.push({
|
|
9352
9412
|
role: "user",
|
|
9353
9413
|
content: message.parts.map((part) => {
|
|
9354
|
-
var
|
|
9414
|
+
var _a23;
|
|
9355
9415
|
if (isTextUIPart(part)) {
|
|
9356
9416
|
return {
|
|
9357
9417
|
type: "text",
|
|
@@ -9369,7 +9429,7 @@ async function convertToModelMessages(messages, options) {
|
|
|
9369
9429
|
};
|
|
9370
9430
|
}
|
|
9371
9431
|
if (isDataUIPart(part)) {
|
|
9372
|
-
return (
|
|
9432
|
+
return (_a23 = options == null ? void 0 : options.convertDataPart) == null ? void 0 : _a23.call(
|
|
9373
9433
|
options,
|
|
9374
9434
|
part
|
|
9375
9435
|
);
|
|
@@ -9382,7 +9442,7 @@ async function convertToModelMessages(messages, options) {
|
|
|
9382
9442
|
if (message.parts != null) {
|
|
9383
9443
|
let block = [];
|
|
9384
9444
|
async function processBlock() {
|
|
9385
|
-
var
|
|
9445
|
+
var _a23, _b, _c, _d, _e, _f, _g, _h;
|
|
9386
9446
|
if (block.length === 0) {
|
|
9387
9447
|
return;
|
|
9388
9448
|
}
|
|
@@ -9415,7 +9475,7 @@ async function convertToModelMessages(messages, options) {
|
|
|
9415
9475
|
type: "tool-call",
|
|
9416
9476
|
toolCallId: part.toolCallId,
|
|
9417
9477
|
toolName,
|
|
9418
|
-
input: part.state === "output-error" ? (
|
|
9478
|
+
input: part.state === "output-error" ? (_a23 = part.input) != null ? _a23 : "rawInput" in part ? part.rawInput : void 0 : part.input,
|
|
9419
9479
|
providerExecuted: part.providerExecuted,
|
|
9420
9480
|
...part.callProviderMetadata != null ? { providerOptions: part.callProviderMetadata } : {}
|
|
9421
9481
|
});
|
|
@@ -9465,8 +9525,8 @@ async function convertToModelMessages(messages, options) {
|
|
|
9465
9525
|
}
|
|
9466
9526
|
const toolParts = block.filter(
|
|
9467
9527
|
(part) => {
|
|
9468
|
-
var
|
|
9469
|
-
return isToolUIPart(part) && (part.providerExecuted !== true || ((
|
|
9528
|
+
var _a24;
|
|
9529
|
+
return isToolUIPart(part) && (part.providerExecuted !== true || ((_a24 = part.approval) == null ? void 0 : _a24.approved) != null);
|
|
9470
9530
|
}
|
|
9471
9531
|
);
|
|
9472
9532
|
if (toolParts.length > 0) {
|
|
@@ -10077,7 +10137,7 @@ async function createAgentUIStream({
|
|
|
10077
10137
|
onStepFinish,
|
|
10078
10138
|
...uiMessageStreamOptions
|
|
10079
10139
|
}) {
|
|
10080
|
-
var
|
|
10140
|
+
var _a23;
|
|
10081
10141
|
const validatedMessages = await validateUIMessagesForAgent({
|
|
10082
10142
|
messages: uiMessages,
|
|
10083
10143
|
tools: agent.tools
|
|
@@ -10096,7 +10156,7 @@ async function createAgentUIStream({
|
|
|
10096
10156
|
return result.toUIMessageStream({
|
|
10097
10157
|
...uiMessageStreamOptions,
|
|
10098
10158
|
// TODO reading `originalMessages` is here for bc, always use `validatedMessages` in v7
|
|
10099
|
-
originalMessages: (
|
|
10159
|
+
originalMessages: (_a23 = uiMessageStreamOptions.originalMessages) != null ? _a23 : validatedMessages
|
|
10100
10160
|
});
|
|
10101
10161
|
}
|
|
10102
10162
|
|
|
@@ -10196,7 +10256,7 @@ async function embed({
|
|
|
10196
10256
|
}),
|
|
10197
10257
|
tracer,
|
|
10198
10258
|
fn: async (doEmbedSpan) => {
|
|
10199
|
-
var
|
|
10259
|
+
var _a23, _b;
|
|
10200
10260
|
const modelResponse = await model.doEmbed({
|
|
10201
10261
|
values: [value],
|
|
10202
10262
|
abortSignal,
|
|
@@ -10204,7 +10264,7 @@ async function embed({
|
|
|
10204
10264
|
providerOptions
|
|
10205
10265
|
});
|
|
10206
10266
|
const embedding2 = modelResponse.embeddings[0];
|
|
10207
|
-
const usage2 = (
|
|
10267
|
+
const usage2 = (_a23 = modelResponse.usage) != null ? _a23 : { tokens: NaN };
|
|
10208
10268
|
doEmbedSpan.setAttributes(
|
|
10209
10269
|
await selectTelemetryAttributes({
|
|
10210
10270
|
telemetry,
|
|
@@ -10326,7 +10386,7 @@ async function embedMany({
|
|
|
10326
10386
|
}),
|
|
10327
10387
|
tracer,
|
|
10328
10388
|
fn: async (span) => {
|
|
10329
|
-
var
|
|
10389
|
+
var _a23;
|
|
10330
10390
|
const [
|
|
10331
10391
|
maxEmbeddingsPerCall,
|
|
10332
10392
|
maxInputBytesPerCall,
|
|
@@ -10358,7 +10418,7 @@ async function embedMany({
|
|
|
10358
10418
|
}),
|
|
10359
10419
|
tracer,
|
|
10360
10420
|
fn: async (doEmbedSpan) => {
|
|
10361
|
-
var
|
|
10421
|
+
var _a24, _b;
|
|
10362
10422
|
const modelResponse = await model.doEmbed({
|
|
10363
10423
|
values,
|
|
10364
10424
|
abortSignal,
|
|
@@ -10366,7 +10426,7 @@ async function embedMany({
|
|
|
10366
10426
|
providerOptions
|
|
10367
10427
|
});
|
|
10368
10428
|
const embeddings3 = modelResponse.embeddings;
|
|
10369
|
-
const usage2 = (
|
|
10429
|
+
const usage2 = (_a24 = modelResponse.usage) != null ? _a24 : { tokens: NaN };
|
|
10370
10430
|
doEmbedSpan.setAttributes(
|
|
10371
10431
|
await selectTelemetryAttributes({
|
|
10372
10432
|
telemetry,
|
|
@@ -10451,7 +10511,7 @@ async function embedMany({
|
|
|
10451
10511
|
}),
|
|
10452
10512
|
tracer,
|
|
10453
10513
|
fn: async (doEmbedSpan) => {
|
|
10454
|
-
var
|
|
10514
|
+
var _a24, _b;
|
|
10455
10515
|
const modelResponse = await model.doEmbed({
|
|
10456
10516
|
values: chunk,
|
|
10457
10517
|
abortSignal,
|
|
@@ -10459,7 +10519,7 @@ async function embedMany({
|
|
|
10459
10519
|
providerOptions
|
|
10460
10520
|
});
|
|
10461
10521
|
const embeddings2 = modelResponse.embeddings;
|
|
10462
|
-
const usage = (
|
|
10522
|
+
const usage = (_a24 = modelResponse.usage) != null ? _a24 : { tokens: NaN };
|
|
10463
10523
|
doEmbedSpan.setAttributes(
|
|
10464
10524
|
await selectTelemetryAttributes({
|
|
10465
10525
|
telemetry,
|
|
@@ -10498,7 +10558,7 @@ async function embedMany({
|
|
|
10498
10558
|
result.providerMetadata
|
|
10499
10559
|
)) {
|
|
10500
10560
|
providerMetadata[providerName] = {
|
|
10501
|
-
...(
|
|
10561
|
+
...(_a23 = providerMetadata[providerName]) != null ? _a23 : {},
|
|
10502
10562
|
...metadata
|
|
10503
10563
|
};
|
|
10504
10564
|
}
|
|
@@ -10593,7 +10653,7 @@ async function generateImage({
|
|
|
10593
10653
|
abortSignal,
|
|
10594
10654
|
headers
|
|
10595
10655
|
}) {
|
|
10596
|
-
var
|
|
10656
|
+
var _a23, _b;
|
|
10597
10657
|
const model = resolveImageModel(modelArg);
|
|
10598
10658
|
const headersWithUserAgent = withUserAgentSuffix5(
|
|
10599
10659
|
headers != null ? headers : {},
|
|
@@ -10603,7 +10663,7 @@ async function generateImage({
|
|
|
10603
10663
|
maxRetries: maxRetriesArg,
|
|
10604
10664
|
abortSignal
|
|
10605
10665
|
});
|
|
10606
|
-
const maxImagesPerCallWithDefault = (
|
|
10666
|
+
const maxImagesPerCallWithDefault = (_a23 = maxImagesPerCall != null ? maxImagesPerCall : await invokeModelMaxImagesPerCall(model)) != null ? _a23 : 1;
|
|
10607
10667
|
const callCount = Math.ceil(n / maxImagesPerCallWithDefault);
|
|
10608
10668
|
const callImageCounts = Array.from({ length: callCount }, (_, i) => {
|
|
10609
10669
|
if (i < callCount - 1) {
|
|
@@ -10644,13 +10704,13 @@ async function generateImage({
|
|
|
10644
10704
|
images.push(
|
|
10645
10705
|
...result.images.map(
|
|
10646
10706
|
(image) => {
|
|
10647
|
-
var
|
|
10707
|
+
var _a24;
|
|
10648
10708
|
return new DefaultGeneratedFile({
|
|
10649
10709
|
data: image,
|
|
10650
|
-
mediaType: (
|
|
10710
|
+
mediaType: (_a24 = detectMediaType({
|
|
10651
10711
|
data: image,
|
|
10652
10712
|
signatures: imageMediaTypeSignatures
|
|
10653
|
-
})) != null ?
|
|
10713
|
+
})) != null ? _a24 : "image/png"
|
|
10654
10714
|
});
|
|
10655
10715
|
}
|
|
10656
10716
|
)
|
|
@@ -10850,7 +10910,7 @@ var arrayOutputStrategy = (schema) => {
|
|
|
10850
10910
|
isFirstDelta,
|
|
10851
10911
|
isFinalDelta
|
|
10852
10912
|
}) {
|
|
10853
|
-
var
|
|
10913
|
+
var _a23;
|
|
10854
10914
|
if (!isJSONObject(value) || !isJSONArray(value.elements)) {
|
|
10855
10915
|
return {
|
|
10856
10916
|
success: false,
|
|
@@ -10873,7 +10933,7 @@ var arrayOutputStrategy = (schema) => {
|
|
|
10873
10933
|
}
|
|
10874
10934
|
resultArray.push(result.value);
|
|
10875
10935
|
}
|
|
10876
|
-
const publishedElementCount = (
|
|
10936
|
+
const publishedElementCount = (_a23 = latestObject == null ? void 0 : latestObject.length) != null ? _a23 : 0;
|
|
10877
10937
|
let textDelta = "";
|
|
10878
10938
|
if (isFirstDelta) {
|
|
10879
10939
|
textDelta += "[";
|
|
@@ -11296,7 +11356,7 @@ async function generateObject(options) {
|
|
|
11296
11356
|
}),
|
|
11297
11357
|
tracer,
|
|
11298
11358
|
fn: async (span) => {
|
|
11299
|
-
var
|
|
11359
|
+
var _a23;
|
|
11300
11360
|
let result;
|
|
11301
11361
|
let finishReason;
|
|
11302
11362
|
let usage;
|
|
@@ -11343,7 +11403,7 @@ async function generateObject(options) {
|
|
|
11343
11403
|
}),
|
|
11344
11404
|
tracer,
|
|
11345
11405
|
fn: async (span2) => {
|
|
11346
|
-
var
|
|
11406
|
+
var _a24, _b, _c, _d, _e, _f, _g, _h;
|
|
11347
11407
|
const result2 = await model.doGenerate({
|
|
11348
11408
|
responseFormat: {
|
|
11349
11409
|
type: "json",
|
|
@@ -11358,7 +11418,7 @@ async function generateObject(options) {
|
|
|
11358
11418
|
headers: headersWithUserAgent
|
|
11359
11419
|
});
|
|
11360
11420
|
const responseData = {
|
|
11361
|
-
id: (_b = (
|
|
11421
|
+
id: (_b = (_a24 = result2.response) == null ? void 0 : _a24.id) != null ? _b : generateId2(),
|
|
11362
11422
|
timestamp: (_d = (_c = result2.response) == null ? void 0 : _c.timestamp) != null ? _d : currentDate(),
|
|
11363
11423
|
modelId: (_f = (_e = result2.response) == null ? void 0 : _e.modelId) != null ? _f : model.modelId,
|
|
11364
11424
|
headers: (_g = result2.response) == null ? void 0 : _g.headers,
|
|
@@ -11414,7 +11474,7 @@ async function generateObject(options) {
|
|
|
11414
11474
|
usage = asLanguageModelUsage(generateResult.usage);
|
|
11415
11475
|
warnings = generateResult.warnings;
|
|
11416
11476
|
resultProviderMetadata = generateResult.providerMetadata;
|
|
11417
|
-
request = (
|
|
11477
|
+
request = (_a23 = generateResult.request) != null ? _a23 : {};
|
|
11418
11478
|
response = generateResult.responseData;
|
|
11419
11479
|
reasoning = generateResult.reasoning;
|
|
11420
11480
|
logWarnings({
|
|
@@ -11477,9 +11537,9 @@ var DefaultGenerateObjectResult = class {
|
|
|
11477
11537
|
this.reasoning = options.reasoning;
|
|
11478
11538
|
}
|
|
11479
11539
|
toJsonResponse(init) {
|
|
11480
|
-
var
|
|
11540
|
+
var _a23;
|
|
11481
11541
|
return new Response(JSON.stringify(this.object), {
|
|
11482
|
-
status: (
|
|
11542
|
+
status: (_a23 = init == null ? void 0 : init.status) != null ? _a23 : 200,
|
|
11483
11543
|
headers: prepareHeaders(init == null ? void 0 : init.headers, {
|
|
11484
11544
|
"content-type": "application/json; charset=utf-8"
|
|
11485
11545
|
})
|
|
@@ -11613,8 +11673,8 @@ function simulateReadableStream({
|
|
|
11613
11673
|
chunkDelayInMs = 0,
|
|
11614
11674
|
_internal
|
|
11615
11675
|
}) {
|
|
11616
|
-
var
|
|
11617
|
-
const delay = (
|
|
11676
|
+
var _a23;
|
|
11677
|
+
const delay = (_a23 = _internal == null ? void 0 : _internal.delay) != null ? _a23 : delayFunction;
|
|
11618
11678
|
let index = 0;
|
|
11619
11679
|
return new ReadableStream({
|
|
11620
11680
|
async pull(controller) {
|
|
@@ -11888,7 +11948,7 @@ var DefaultStreamObjectResult = class {
|
|
|
11888
11948
|
const transformedStream = stream.pipeThrough(new TransformStream(transformer)).pipeThrough(
|
|
11889
11949
|
new TransformStream({
|
|
11890
11950
|
async transform(chunk, controller) {
|
|
11891
|
-
var
|
|
11951
|
+
var _a23, _b, _c;
|
|
11892
11952
|
if (typeof chunk === "object" && chunk.type === "stream-start") {
|
|
11893
11953
|
warnings = chunk.warnings;
|
|
11894
11954
|
return;
|
|
@@ -11938,7 +11998,7 @@ var DefaultStreamObjectResult = class {
|
|
|
11938
11998
|
switch (chunk.type) {
|
|
11939
11999
|
case "response-metadata": {
|
|
11940
12000
|
fullResponse = {
|
|
11941
|
-
id: (
|
|
12001
|
+
id: (_a23 = chunk.id) != null ? _a23 : fullResponse.id,
|
|
11942
12002
|
timestamp: (_b = chunk.timestamp) != null ? _b : fullResponse.timestamp,
|
|
11943
12003
|
modelId: (_c = chunk.modelId) != null ? _c : fullResponse.modelId
|
|
11944
12004
|
};
|
|
@@ -12254,7 +12314,7 @@ async function generateSpeech({
|
|
|
12254
12314
|
abortSignal,
|
|
12255
12315
|
headers
|
|
12256
12316
|
}) {
|
|
12257
|
-
var
|
|
12317
|
+
var _a23;
|
|
12258
12318
|
const resolvedModel = resolveSpeechModel(model);
|
|
12259
12319
|
if (!resolvedModel) {
|
|
12260
12320
|
throw new Error("Model could not be resolved");
|
|
@@ -12291,10 +12351,10 @@ async function generateSpeech({
|
|
|
12291
12351
|
return new DefaultSpeechResult({
|
|
12292
12352
|
audio: new DefaultGeneratedAudioFile({
|
|
12293
12353
|
data: result.audio,
|
|
12294
|
-
mediaType: (
|
|
12354
|
+
mediaType: (_a23 = detectMediaType({
|
|
12295
12355
|
data: result.audio,
|
|
12296
12356
|
signatures: audioMediaTypeSignatures
|
|
12297
|
-
})) != null ?
|
|
12357
|
+
})) != null ? _a23 : "audio/mp3"
|
|
12298
12358
|
}),
|
|
12299
12359
|
warnings: result.warnings,
|
|
12300
12360
|
responses: [result.response],
|
|
@@ -12303,11 +12363,11 @@ async function generateSpeech({
|
|
|
12303
12363
|
}
|
|
12304
12364
|
var DefaultSpeechResult = class {
|
|
12305
12365
|
constructor(options) {
|
|
12306
|
-
var
|
|
12366
|
+
var _a23;
|
|
12307
12367
|
this.audio = options.audio;
|
|
12308
12368
|
this.warnings = options.warnings;
|
|
12309
12369
|
this.responses = options.responses;
|
|
12310
|
-
this.providerMetadata = (
|
|
12370
|
+
this.providerMetadata = (_a23 = options.providerMetadata) != null ? _a23 : {};
|
|
12311
12371
|
}
|
|
12312
12372
|
};
|
|
12313
12373
|
|
|
@@ -12530,7 +12590,7 @@ async function experimental_generateVideo({
|
|
|
12530
12590
|
headers,
|
|
12531
12591
|
download: downloadFn = defaultDownload
|
|
12532
12592
|
}) {
|
|
12533
|
-
var
|
|
12593
|
+
var _a23, _b;
|
|
12534
12594
|
const model = resolveVideoModel(modelArg);
|
|
12535
12595
|
const headersWithUserAgent = withUserAgentSuffix8(
|
|
12536
12596
|
headers != null ? headers : {},
|
|
@@ -12557,9 +12617,9 @@ async function experimental_generateVideo({
|
|
|
12557
12617
|
message: "inputReferences were ignored because frameImages were provided; frameImages and inputReferences cannot be combined."
|
|
12558
12618
|
});
|
|
12559
12619
|
}
|
|
12560
|
-
const firstFrameImage = (
|
|
12620
|
+
const firstFrameImage = (_a23 = normalizedFrameImages == null ? void 0 : normalizedFrameImages.find(
|
|
12561
12621
|
(frame) => frame.frameType === "first_frame"
|
|
12562
|
-
)) == null ? void 0 :
|
|
12622
|
+
)) == null ? void 0 : _a23.image;
|
|
12563
12623
|
if (image != null && firstFrameImage != null) {
|
|
12564
12624
|
warnings.push({
|
|
12565
12625
|
type: "other",
|
|
@@ -12703,8 +12763,8 @@ function normalizePrompt2(promptArg) {
|
|
|
12703
12763
|
};
|
|
12704
12764
|
}
|
|
12705
12765
|
function detectFileMediaType(data, restrictToImages) {
|
|
12706
|
-
var
|
|
12707
|
-
const detected = restrictToImages ? detectMediaType({ data, signatures: imageMediaTypeSignatures }) : (
|
|
12766
|
+
var _a23;
|
|
12767
|
+
const detected = restrictToImages ? detectMediaType({ data, signatures: imageMediaTypeSignatures }) : (_a23 = detectMediaType({ data, signatures: imageMediaTypeSignatures })) != null ? _a23 : detectMediaType({ data, signatures: videoMediaTypeSignatures });
|
|
12708
12768
|
return detected != null ? detected : "image/png";
|
|
12709
12769
|
}
|
|
12710
12770
|
function normalizeImageData(dataContent, { restrictToImages = true } = {}) {
|
|
@@ -12798,8 +12858,8 @@ function stripMarkdownCodeFenceSuffix(text2) {
|
|
|
12798
12858
|
return text2.replace(/\n?```\s*$/, "").trimEnd();
|
|
12799
12859
|
}
|
|
12800
12860
|
function extractJsonMiddleware(options) {
|
|
12801
|
-
var
|
|
12802
|
-
const transform = (
|
|
12861
|
+
var _a23;
|
|
12862
|
+
const transform = (_a23 = options == null ? void 0 : options.transform) != null ? _a23 : defaultTransform;
|
|
12803
12863
|
const hasCustomTransform = (options == null ? void 0 : options.transform) !== void 0;
|
|
12804
12864
|
return {
|
|
12805
12865
|
specificationVersion: "v3",
|
|
@@ -13175,13 +13235,13 @@ function addToolInputExamplesMiddleware({
|
|
|
13175
13235
|
return {
|
|
13176
13236
|
specificationVersion: "v3",
|
|
13177
13237
|
transformParams: async ({ params }) => {
|
|
13178
|
-
var
|
|
13179
|
-
if (!((
|
|
13238
|
+
var _a23;
|
|
13239
|
+
if (!((_a23 = params.tools) == null ? void 0 : _a23.length)) {
|
|
13180
13240
|
return params;
|
|
13181
13241
|
}
|
|
13182
13242
|
const transformedTools = params.tools.map((tool2) => {
|
|
13183
|
-
var
|
|
13184
|
-
if (tool2.type !== "function" || !((
|
|
13243
|
+
var _a24;
|
|
13244
|
+
if (tool2.type !== "function" || !((_a24 = tool2.inputExamples) == null ? void 0 : _a24.length)) {
|
|
13185
13245
|
return tool2;
|
|
13186
13246
|
}
|
|
13187
13247
|
const formattedExamples = tool2.inputExamples.map((example, index) => format(example, index)).join("\n");
|
|
@@ -13228,7 +13288,7 @@ var doWrap = ({
|
|
|
13228
13288
|
modelId,
|
|
13229
13289
|
providerId
|
|
13230
13290
|
}) => {
|
|
13231
|
-
var
|
|
13291
|
+
var _a23, _b, _c;
|
|
13232
13292
|
async function doTransform({
|
|
13233
13293
|
params,
|
|
13234
13294
|
type
|
|
@@ -13237,7 +13297,7 @@ var doWrap = ({
|
|
|
13237
13297
|
}
|
|
13238
13298
|
return {
|
|
13239
13299
|
specificationVersion: "v3",
|
|
13240
|
-
provider: (
|
|
13300
|
+
provider: (_a23 = providerId != null ? providerId : overrideProvider == null ? void 0 : overrideProvider({ model })) != null ? _a23 : model.provider,
|
|
13241
13301
|
modelId: (_b = modelId != null ? modelId : overrideModelId == null ? void 0 : overrideModelId({ model })) != null ? _b : model.modelId,
|
|
13242
13302
|
supportedUrls: (_c = overrideSupportedUrls == null ? void 0 : overrideSupportedUrls({ model })) != null ? _c : model.supportedUrls,
|
|
13243
13303
|
async doGenerate(params) {
|
|
@@ -13285,7 +13345,7 @@ var doWrap2 = ({
|
|
|
13285
13345
|
modelId,
|
|
13286
13346
|
providerId
|
|
13287
13347
|
}) => {
|
|
13288
|
-
var
|
|
13348
|
+
var _a23, _b, _c, _d;
|
|
13289
13349
|
async function doTransform({
|
|
13290
13350
|
params
|
|
13291
13351
|
}) {
|
|
@@ -13293,7 +13353,7 @@ var doWrap2 = ({
|
|
|
13293
13353
|
}
|
|
13294
13354
|
return {
|
|
13295
13355
|
specificationVersion: "v3",
|
|
13296
|
-
provider: (
|
|
13356
|
+
provider: (_a23 = providerId != null ? providerId : overrideProvider == null ? void 0 : overrideProvider({ model })) != null ? _a23 : model.provider,
|
|
13297
13357
|
modelId: (_b = modelId != null ? modelId : overrideModelId == null ? void 0 : overrideModelId({ model })) != null ? _b : model.modelId,
|
|
13298
13358
|
maxEmbeddingsPerCall: (_c = overrideMaxEmbeddingsPerCall == null ? void 0 : overrideMaxEmbeddingsPerCall({ model })) != null ? _c : model.maxEmbeddingsPerCall,
|
|
13299
13359
|
[EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL2]: getEmbeddingModelMaxInputBytesPerCall(model),
|
|
@@ -13333,11 +13393,11 @@ var doWrap3 = ({
|
|
|
13333
13393
|
modelId,
|
|
13334
13394
|
providerId
|
|
13335
13395
|
}) => {
|
|
13336
|
-
var
|
|
13396
|
+
var _a23, _b, _c;
|
|
13337
13397
|
async function doTransform({ params }) {
|
|
13338
13398
|
return transformParams ? await transformParams({ params, model }) : params;
|
|
13339
13399
|
}
|
|
13340
|
-
const maxImagesPerCallRaw = (
|
|
13400
|
+
const maxImagesPerCallRaw = (_a23 = overrideMaxImagesPerCall == null ? void 0 : overrideMaxImagesPerCall({ model })) != null ? _a23 : model.maxImagesPerCall;
|
|
13341
13401
|
const maxImagesPerCall = maxImagesPerCallRaw instanceof Function ? maxImagesPerCallRaw.bind(model) : maxImagesPerCallRaw;
|
|
13342
13402
|
return {
|
|
13343
13403
|
specificationVersion: "v3",
|
|
@@ -13487,11 +13547,11 @@ function customProvider({
|
|
|
13487
13547
|
var experimental_customProvider = customProvider;
|
|
13488
13548
|
|
|
13489
13549
|
// src/registry/no-such-provider-error.ts
|
|
13490
|
-
import { AISDKError as
|
|
13491
|
-
var
|
|
13492
|
-
var
|
|
13493
|
-
var
|
|
13494
|
-
var
|
|
13550
|
+
import { AISDKError as AISDKError26, NoSuchModelError as NoSuchModelError3 } from "@ai-sdk/provider";
|
|
13551
|
+
var name22 = "AI_NoSuchProviderError";
|
|
13552
|
+
var marker22 = `vercel.ai.error.${name22}`;
|
|
13553
|
+
var symbol22 = Symbol.for(marker22);
|
|
13554
|
+
var _a22;
|
|
13495
13555
|
var NoSuchProviderError = class extends NoSuchModelError3 {
|
|
13496
13556
|
constructor({
|
|
13497
13557
|
modelId,
|
|
@@ -13500,16 +13560,16 @@ var NoSuchProviderError = class extends NoSuchModelError3 {
|
|
|
13500
13560
|
availableProviders,
|
|
13501
13561
|
message = `No such provider: ${providerId} (available providers: ${availableProviders.join()})`
|
|
13502
13562
|
}) {
|
|
13503
|
-
super({ errorName:
|
|
13504
|
-
this[
|
|
13563
|
+
super({ errorName: name22, modelId, modelType, message });
|
|
13564
|
+
this[_a22] = true;
|
|
13505
13565
|
this.providerId = providerId;
|
|
13506
13566
|
this.availableProviders = availableProviders;
|
|
13507
13567
|
}
|
|
13508
13568
|
static isInstance(error) {
|
|
13509
|
-
return
|
|
13569
|
+
return AISDKError26.hasMarker(error, marker22);
|
|
13510
13570
|
}
|
|
13511
13571
|
};
|
|
13512
|
-
|
|
13572
|
+
_a22 = symbol22;
|
|
13513
13573
|
|
|
13514
13574
|
// src/registry/provider-registry.ts
|
|
13515
13575
|
import {
|
|
@@ -13572,10 +13632,10 @@ var DefaultProviderRegistry = class {
|
|
|
13572
13632
|
return [id.slice(0, index), id.slice(index + this.separator.length)];
|
|
13573
13633
|
}
|
|
13574
13634
|
languageModel(id) {
|
|
13575
|
-
var
|
|
13635
|
+
var _a23, _b;
|
|
13576
13636
|
const [providerId, modelId] = this.splitId(id, "languageModel");
|
|
13577
|
-
let model = (_b = (
|
|
13578
|
-
|
|
13637
|
+
let model = (_b = (_a23 = this.getProvider(providerId, "languageModel")).languageModel) == null ? void 0 : _b.call(
|
|
13638
|
+
_a23,
|
|
13579
13639
|
modelId
|
|
13580
13640
|
);
|
|
13581
13641
|
if (model == null) {
|
|
@@ -13590,10 +13650,10 @@ var DefaultProviderRegistry = class {
|
|
|
13590
13650
|
return model;
|
|
13591
13651
|
}
|
|
13592
13652
|
embeddingModel(id) {
|
|
13593
|
-
var
|
|
13653
|
+
var _a23;
|
|
13594
13654
|
const [providerId, modelId] = this.splitId(id, "embeddingModel");
|
|
13595
13655
|
const provider = this.getProvider(providerId, "embeddingModel");
|
|
13596
|
-
const model = (
|
|
13656
|
+
const model = (_a23 = provider.embeddingModel) == null ? void 0 : _a23.call(provider, modelId);
|
|
13597
13657
|
if (model == null) {
|
|
13598
13658
|
throw new NoSuchModelError4({
|
|
13599
13659
|
modelId: id,
|
|
@@ -13603,10 +13663,10 @@ var DefaultProviderRegistry = class {
|
|
|
13603
13663
|
return model;
|
|
13604
13664
|
}
|
|
13605
13665
|
imageModel(id) {
|
|
13606
|
-
var
|
|
13666
|
+
var _a23;
|
|
13607
13667
|
const [providerId, modelId] = this.splitId(id, "imageModel");
|
|
13608
13668
|
const provider = this.getProvider(providerId, "imageModel");
|
|
13609
|
-
let model = (
|
|
13669
|
+
let model = (_a23 = provider.imageModel) == null ? void 0 : _a23.call(provider, modelId);
|
|
13610
13670
|
if (model == null) {
|
|
13611
13671
|
throw new NoSuchModelError4({ modelId: id, modelType: "imageModel" });
|
|
13612
13672
|
}
|
|
@@ -13619,10 +13679,10 @@ var DefaultProviderRegistry = class {
|
|
|
13619
13679
|
return model;
|
|
13620
13680
|
}
|
|
13621
13681
|
transcriptionModel(id) {
|
|
13622
|
-
var
|
|
13682
|
+
var _a23;
|
|
13623
13683
|
const [providerId, modelId] = this.splitId(id, "transcriptionModel");
|
|
13624
13684
|
const provider = this.getProvider(providerId, "transcriptionModel");
|
|
13625
|
-
const model = (
|
|
13685
|
+
const model = (_a23 = provider.transcriptionModel) == null ? void 0 : _a23.call(provider, modelId);
|
|
13626
13686
|
if (model == null) {
|
|
13627
13687
|
throw new NoSuchModelError4({
|
|
13628
13688
|
modelId: id,
|
|
@@ -13632,20 +13692,20 @@ var DefaultProviderRegistry = class {
|
|
|
13632
13692
|
return model;
|
|
13633
13693
|
}
|
|
13634
13694
|
speechModel(id) {
|
|
13635
|
-
var
|
|
13695
|
+
var _a23;
|
|
13636
13696
|
const [providerId, modelId] = this.splitId(id, "speechModel");
|
|
13637
13697
|
const provider = this.getProvider(providerId, "speechModel");
|
|
13638
|
-
const model = (
|
|
13698
|
+
const model = (_a23 = provider.speechModel) == null ? void 0 : _a23.call(provider, modelId);
|
|
13639
13699
|
if (model == null) {
|
|
13640
13700
|
throw new NoSuchModelError4({ modelId: id, modelType: "speechModel" });
|
|
13641
13701
|
}
|
|
13642
13702
|
return model;
|
|
13643
13703
|
}
|
|
13644
13704
|
rerankingModel(id) {
|
|
13645
|
-
var
|
|
13705
|
+
var _a23;
|
|
13646
13706
|
const [providerId, modelId] = this.splitId(id, "rerankingModel");
|
|
13647
13707
|
const provider = this.getProvider(providerId, "rerankingModel");
|
|
13648
|
-
const model = (
|
|
13708
|
+
const model = (_a23 = provider.rerankingModel) == null ? void 0 : _a23.call(provider, modelId);
|
|
13649
13709
|
if (model == null) {
|
|
13650
13710
|
throw new NoSuchModelError4({ modelId: id, modelType: "rerankingModel" });
|
|
13651
13711
|
}
|
|
@@ -13703,7 +13763,7 @@ async function rerank({
|
|
|
13703
13763
|
}),
|
|
13704
13764
|
tracer,
|
|
13705
13765
|
fn: async () => {
|
|
13706
|
-
var
|
|
13766
|
+
var _a23, _b;
|
|
13707
13767
|
const { ranking, response, providerMetadata, warnings } = await retry(
|
|
13708
13768
|
() => recordSpan({
|
|
13709
13769
|
name: "ai.rerank.doRerank",
|
|
@@ -13767,7 +13827,7 @@ async function rerank({
|
|
|
13767
13827
|
providerMetadata,
|
|
13768
13828
|
response: {
|
|
13769
13829
|
id: response == null ? void 0 : response.id,
|
|
13770
|
-
timestamp: (
|
|
13830
|
+
timestamp: (_a23 = response == null ? void 0 : response.timestamp) != null ? _a23 : /* @__PURE__ */ new Date(),
|
|
13771
13831
|
modelId: (_b = response == null ? void 0 : response.modelId) != null ? _b : model.modelId,
|
|
13772
13832
|
headers: response == null ? void 0 : response.headers,
|
|
13773
13833
|
body: response == null ? void 0 : response.body
|
|
@@ -13817,16 +13877,16 @@ async function transcribe({
|
|
|
13817
13877
|
const audioData = audio instanceof URL ? (await downloadFn({ url: audio, abortSignal })).data : convertDataContentToUint8Array(audio);
|
|
13818
13878
|
const result = await retry(
|
|
13819
13879
|
() => {
|
|
13820
|
-
var
|
|
13880
|
+
var _a23;
|
|
13821
13881
|
return resolvedModel.doGenerate({
|
|
13822
13882
|
audio: audioData,
|
|
13823
13883
|
abortSignal,
|
|
13824
13884
|
headers: headersWithUserAgent,
|
|
13825
13885
|
providerOptions,
|
|
13826
|
-
mediaType: (
|
|
13886
|
+
mediaType: (_a23 = detectMediaType({
|
|
13827
13887
|
data: audioData,
|
|
13828
13888
|
signatures: audioMediaTypeSignatures
|
|
13829
|
-
})) != null ?
|
|
13889
|
+
})) != null ? _a23 : "audio/wav"
|
|
13830
13890
|
});
|
|
13831
13891
|
}
|
|
13832
13892
|
);
|
|
@@ -13850,14 +13910,14 @@ async function transcribe({
|
|
|
13850
13910
|
}
|
|
13851
13911
|
var DefaultTranscriptionResult = class {
|
|
13852
13912
|
constructor(options) {
|
|
13853
|
-
var
|
|
13913
|
+
var _a23;
|
|
13854
13914
|
this.text = options.text;
|
|
13855
13915
|
this.segments = options.segments;
|
|
13856
13916
|
this.language = options.language;
|
|
13857
13917
|
this.durationInSeconds = options.durationInSeconds;
|
|
13858
13918
|
this.warnings = options.warnings;
|
|
13859
13919
|
this.responses = options.responses;
|
|
13860
|
-
this.providerMetadata = (
|
|
13920
|
+
this.providerMetadata = (_a23 = options.providerMetadata) != null ? _a23 : {};
|
|
13861
13921
|
}
|
|
13862
13922
|
};
|
|
13863
13923
|
|
|
@@ -13900,7 +13960,7 @@ async function callCompletionApi({
|
|
|
13900
13960
|
onError,
|
|
13901
13961
|
fetch: fetch2 = getOriginalFetch()
|
|
13902
13962
|
}) {
|
|
13903
|
-
var
|
|
13963
|
+
var _a23;
|
|
13904
13964
|
try {
|
|
13905
13965
|
setLoading(true);
|
|
13906
13966
|
setError(void 0);
|
|
@@ -13928,7 +13988,7 @@ async function callCompletionApi({
|
|
|
13928
13988
|
});
|
|
13929
13989
|
if (!response.ok) {
|
|
13930
13990
|
throw new Error(
|
|
13931
|
-
(
|
|
13991
|
+
(_a23 = await response.text()) != null ? _a23 : "Failed to fetch the chat response."
|
|
13932
13992
|
);
|
|
13933
13993
|
}
|
|
13934
13994
|
if (!response.body) {
|
|
@@ -14014,12 +14074,12 @@ async function convertFileListToFileUIParts(files) {
|
|
|
14014
14074
|
}
|
|
14015
14075
|
return Promise.all(
|
|
14016
14076
|
Array.from(files).map(async (file) => {
|
|
14017
|
-
const { name:
|
|
14077
|
+
const { name: name23, type } = file;
|
|
14018
14078
|
const dataUrl = await new Promise((resolve3, reject) => {
|
|
14019
14079
|
const reader = new FileReader();
|
|
14020
14080
|
reader.onload = (readerEvent) => {
|
|
14021
|
-
var
|
|
14022
|
-
resolve3((
|
|
14081
|
+
var _a23;
|
|
14082
|
+
resolve3((_a23 = readerEvent.target) == null ? void 0 : _a23.result);
|
|
14023
14083
|
};
|
|
14024
14084
|
reader.onerror = (error) => reject(error);
|
|
14025
14085
|
reader.readAsDataURL(file);
|
|
@@ -14027,7 +14087,7 @@ async function convertFileListToFileUIParts(files) {
|
|
|
14027
14087
|
return {
|
|
14028
14088
|
type: "file",
|
|
14029
14089
|
mediaType: type,
|
|
14030
|
-
filename:
|
|
14090
|
+
filename: name23,
|
|
14031
14091
|
url: dataUrl
|
|
14032
14092
|
};
|
|
14033
14093
|
})
|
|
@@ -14064,7 +14124,7 @@ var HttpChatTransport = class {
|
|
|
14064
14124
|
abortSignal,
|
|
14065
14125
|
...options
|
|
14066
14126
|
}) {
|
|
14067
|
-
var
|
|
14127
|
+
var _a23, _b, _c, _d, _e;
|
|
14068
14128
|
const resolvedBody = await resolve2(this.body);
|
|
14069
14129
|
const resolvedHeaders = await resolve2(this.headers);
|
|
14070
14130
|
const resolvedCredentials = await resolve2(this.credentials);
|
|
@@ -14072,7 +14132,7 @@ var HttpChatTransport = class {
|
|
|
14072
14132
|
...normalizeHeaders(resolvedHeaders),
|
|
14073
14133
|
...normalizeHeaders(options.headers)
|
|
14074
14134
|
};
|
|
14075
|
-
const preparedRequest = await ((
|
|
14135
|
+
const preparedRequest = await ((_a23 = this.prepareSendMessagesRequest) == null ? void 0 : _a23.call(this, {
|
|
14076
14136
|
api: this.api,
|
|
14077
14137
|
id: options.chatId,
|
|
14078
14138
|
messages: options.messages,
|
|
@@ -14116,7 +14176,7 @@ var HttpChatTransport = class {
|
|
|
14116
14176
|
return this.processResponseStream(response.body);
|
|
14117
14177
|
}
|
|
14118
14178
|
async reconnectToStream(options) {
|
|
14119
|
-
var
|
|
14179
|
+
var _a23, _b, _c, _d, _e;
|
|
14120
14180
|
const resolvedBody = await resolve2(this.body);
|
|
14121
14181
|
const resolvedHeaders = await resolve2(this.headers);
|
|
14122
14182
|
const resolvedCredentials = await resolve2(this.credentials);
|
|
@@ -14124,7 +14184,7 @@ var HttpChatTransport = class {
|
|
|
14124
14184
|
...normalizeHeaders(resolvedHeaders),
|
|
14125
14185
|
...normalizeHeaders(options.headers)
|
|
14126
14186
|
};
|
|
14127
|
-
const preparedRequest = await ((
|
|
14187
|
+
const preparedRequest = await ((_a23 = this.prepareReconnectToStreamRequest) == null ? void 0 : _a23.call(this, {
|
|
14128
14188
|
api: this.api,
|
|
14129
14189
|
id: options.chatId,
|
|
14130
14190
|
body: { ...resolvedBody, ...options.body },
|
|
@@ -14204,11 +14264,11 @@ var AbstractChat = class {
|
|
|
14204
14264
|
* If a messageId is provided, the message will be replaced.
|
|
14205
14265
|
*/
|
|
14206
14266
|
this.sendMessage = async (message, options) => {
|
|
14207
|
-
var
|
|
14267
|
+
var _a23, _b, _c, _d;
|
|
14208
14268
|
if (message == null) {
|
|
14209
14269
|
await this.makeRequest({
|
|
14210
14270
|
trigger: "submit-message",
|
|
14211
|
-
messageId: (
|
|
14271
|
+
messageId: (_a23 = this.lastMessage) == null ? void 0 : _a23.id,
|
|
14212
14272
|
...options
|
|
14213
14273
|
});
|
|
14214
14274
|
return;
|
|
@@ -14318,11 +14378,11 @@ var AbstractChat = class {
|
|
|
14318
14378
|
}
|
|
14319
14379
|
if (this.status !== "streaming" && this.status !== "submitted" && this.sendAutomaticallyWhen) {
|
|
14320
14380
|
this.shouldSendAutomatically().then((shouldSend) => {
|
|
14321
|
-
var
|
|
14381
|
+
var _a23;
|
|
14322
14382
|
if (shouldSend) {
|
|
14323
14383
|
this.makeRequest({
|
|
14324
14384
|
trigger: "submit-message",
|
|
14325
|
-
messageId: (
|
|
14385
|
+
messageId: (_a23 = this.lastMessage) == null ? void 0 : _a23.id,
|
|
14326
14386
|
...options
|
|
14327
14387
|
});
|
|
14328
14388
|
}
|
|
@@ -14348,11 +14408,11 @@ var AbstractChat = class {
|
|
|
14348
14408
|
}
|
|
14349
14409
|
if (this.status !== "streaming" && this.status !== "submitted" && this.sendAutomaticallyWhen) {
|
|
14350
14410
|
this.shouldSendAutomatically().then((shouldSend) => {
|
|
14351
|
-
var
|
|
14411
|
+
var _a23;
|
|
14352
14412
|
if (shouldSend) {
|
|
14353
14413
|
this.makeRequest({
|
|
14354
14414
|
trigger: "submit-message",
|
|
14355
|
-
messageId: (
|
|
14415
|
+
messageId: (_a23 = this.lastMessage) == null ? void 0 : _a23.id,
|
|
14356
14416
|
...options
|
|
14357
14417
|
});
|
|
14358
14418
|
}
|
|
@@ -14365,8 +14425,8 @@ var AbstractChat = class {
|
|
|
14365
14425
|
* Abort the current request immediately, keep the generated tokens if any.
|
|
14366
14426
|
*/
|
|
14367
14427
|
this.stop = async () => {
|
|
14368
|
-
var
|
|
14369
|
-
(
|
|
14428
|
+
var _a23, _b;
|
|
14429
|
+
(_a23 = this.activeResumeRequest) == null ? void 0 : _a23.abortController.abort();
|
|
14370
14430
|
(_b = this.activeResponse) == null ? void 0 : _b.abortController.abort();
|
|
14371
14431
|
};
|
|
14372
14432
|
this.id = id;
|
|
@@ -14431,11 +14491,11 @@ var AbstractChat = class {
|
|
|
14431
14491
|
body,
|
|
14432
14492
|
messageId
|
|
14433
14493
|
}) {
|
|
14434
|
-
var
|
|
14494
|
+
var _a23, _b, _c;
|
|
14435
14495
|
const abortController = new AbortController();
|
|
14436
14496
|
const activeResumeRequest = trigger === "resume-stream" ? { abortController } : void 0;
|
|
14437
14497
|
if (activeResumeRequest) {
|
|
14438
|
-
(
|
|
14498
|
+
(_a23 = this.activeResumeRequest) == null ? void 0 : _a23.abortController.abort();
|
|
14439
14499
|
this.activeResumeRequest = activeResumeRequest;
|
|
14440
14500
|
}
|
|
14441
14501
|
const isCurrentRequest = () => activeResumeRequest == null || this.activeResumeRequest === activeResumeRequest;
|
|
@@ -14531,14 +14591,14 @@ var AbstractChat = class {
|
|
|
14531
14591
|
return job({
|
|
14532
14592
|
state: response.state,
|
|
14533
14593
|
write: ({ updateStatus = true } = {}) => {
|
|
14534
|
-
var
|
|
14594
|
+
var _a24;
|
|
14535
14595
|
if (response.abortController.signal.aborted) {
|
|
14536
14596
|
return;
|
|
14537
14597
|
}
|
|
14538
14598
|
if (updateStatus) {
|
|
14539
14599
|
this.setStatus({ status: "streaming" });
|
|
14540
14600
|
}
|
|
14541
|
-
const replaceLastMessage = response.state.message.id === ((
|
|
14601
|
+
const replaceLastMessage = response.state.message.id === ((_a24 = this.lastMessage) == null ? void 0 : _a24.id);
|
|
14542
14602
|
if (replaceLastMessage) {
|
|
14543
14603
|
this.state.replaceMessage(
|
|
14544
14604
|
this.state.messages.length - 1,
|
|
@@ -14746,7 +14806,7 @@ var TextStreamChatTransport = class extends HttpChatTransport {
|
|
|
14746
14806
|
}
|
|
14747
14807
|
};
|
|
14748
14808
|
export {
|
|
14749
|
-
|
|
14809
|
+
AISDKError23 as AISDKError,
|
|
14750
14810
|
APICallError,
|
|
14751
14811
|
AbstractChat,
|
|
14752
14812
|
DefaultChatTransport,
|
|
@@ -14788,6 +14848,7 @@ export {
|
|
|
14788
14848
|
TooManyEmbeddingValuesForCallError,
|
|
14789
14849
|
ToolCallNotFoundForApprovalError,
|
|
14790
14850
|
ToolCallRepairError,
|
|
14851
|
+
ToolChoiceViolationError,
|
|
14791
14852
|
ToolLoopAgent,
|
|
14792
14853
|
TypeValidationError,
|
|
14793
14854
|
UIMessageStreamError,
|