ai 3.3.5 → 3.3.6
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/dist/index.d.mts +82 -60
- package/dist/index.d.ts +82 -60
- package/dist/index.js +231 -213
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +181 -152
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -8
- package/rsc/dist/rsc-server.mjs +5 -37
- package/rsc/dist/rsc-server.mjs.map +1 -1
package/dist/index.js
CHANGED
@@ -1,13 +1,11 @@
|
|
1
1
|
"use strict";
|
2
|
-
var __create = Object.create;
|
3
2
|
var __defProp = Object.defineProperty;
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
6
|
var __export = (target, all) => {
|
9
|
-
for (var
|
10
|
-
__defProp(target,
|
7
|
+
for (var name12 in all)
|
8
|
+
__defProp(target, name12, { get: all[name12], enumerable: true });
|
11
9
|
};
|
12
10
|
var __copyProps = (to, from, except, desc) => {
|
13
11
|
if (from && typeof from === "object" || typeof from === "function") {
|
@@ -17,22 +15,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
17
15
|
}
|
18
16
|
return to;
|
19
17
|
};
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
-
mod
|
27
|
-
));
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
19
|
|
30
20
|
// streams/index.ts
|
31
21
|
var streams_exports = {};
|
32
22
|
__export(streams_exports, {
|
33
|
-
AISDKError: () =>
|
23
|
+
AISDKError: () => import_provider14.AISDKError,
|
34
24
|
AIStream: () => AIStream,
|
35
|
-
APICallError: () =>
|
25
|
+
APICallError: () => import_provider14.APICallError,
|
36
26
|
AWSBedrockAnthropicMessagesStream: () => AWSBedrockAnthropicMessagesStream,
|
37
27
|
AWSBedrockAnthropicStream: () => AWSBedrockAnthropicStream,
|
38
28
|
AWSBedrockCohereStream: () => AWSBedrockCohereStream,
|
@@ -42,7 +32,7 @@ __export(streams_exports, {
|
|
42
32
|
AssistantResponse: () => AssistantResponse,
|
43
33
|
CohereStream: () => CohereStream,
|
44
34
|
DownloadError: () => DownloadError,
|
45
|
-
EmptyResponseBodyError: () =>
|
35
|
+
EmptyResponseBodyError: () => import_provider14.EmptyResponseBodyError,
|
46
36
|
GoogleGenerativeAIStream: () => GoogleGenerativeAIStream,
|
47
37
|
HuggingFaceStream: () => HuggingFaceStream,
|
48
38
|
InkeepStream: () => InkeepStream,
|
@@ -50,13 +40,13 @@ __export(streams_exports, {
|
|
50
40
|
InvalidDataContentError: () => InvalidDataContentError,
|
51
41
|
InvalidMessageRoleError: () => InvalidMessageRoleError,
|
52
42
|
InvalidModelIdError: () => InvalidModelIdError,
|
53
|
-
InvalidPromptError: () =>
|
54
|
-
InvalidResponseDataError: () =>
|
43
|
+
InvalidPromptError: () => import_provider14.InvalidPromptError,
|
44
|
+
InvalidResponseDataError: () => import_provider14.InvalidResponseDataError,
|
55
45
|
InvalidToolArgumentsError: () => InvalidToolArgumentsError,
|
56
|
-
JSONParseError: () =>
|
46
|
+
JSONParseError: () => import_provider14.JSONParseError,
|
57
47
|
LangChainAdapter: () => langchain_adapter_exports,
|
58
48
|
LangChainStream: () => LangChainStream,
|
59
|
-
LoadAPIKeyError: () =>
|
49
|
+
LoadAPIKeyError: () => import_provider14.LoadAPIKeyError,
|
60
50
|
MistralStream: () => MistralStream,
|
61
51
|
NoObjectGeneratedError: () => NoObjectGeneratedError,
|
62
52
|
NoSuchModelError: () => NoSuchModelError,
|
@@ -67,8 +57,8 @@ __export(streams_exports, {
|
|
67
57
|
RetryError: () => RetryError,
|
68
58
|
StreamData: () => StreamData2,
|
69
59
|
StreamingTextResponse: () => StreamingTextResponse,
|
70
|
-
TypeValidationError: () =>
|
71
|
-
UnsupportedFunctionalityError: () =>
|
60
|
+
TypeValidationError: () => import_provider14.TypeValidationError,
|
61
|
+
UnsupportedFunctionalityError: () => import_provider14.UnsupportedFunctionalityError,
|
72
62
|
convertDataContentToBase64String: () => convertDataContentToBase64String,
|
73
63
|
convertDataContentToUint8Array: () => convertDataContentToUint8Array,
|
74
64
|
convertToCoreMessages: () => convertToCoreMessages,
|
@@ -87,15 +77,15 @@ __export(streams_exports, {
|
|
87
77
|
experimental_generateText: () => experimental_generateText,
|
88
78
|
experimental_streamObject: () => experimental_streamObject,
|
89
79
|
experimental_streamText: () => experimental_streamText,
|
90
|
-
formatStreamPart: () =>
|
80
|
+
formatStreamPart: () => import_ui_utils10.formatStreamPart,
|
91
81
|
generateId: () => generateId2,
|
92
82
|
generateObject: () => generateObject,
|
93
83
|
generateText: () => generateText,
|
94
|
-
jsonSchema: () => jsonSchema,
|
84
|
+
jsonSchema: () => import_ui_utils6.jsonSchema,
|
95
85
|
nanoid: () => nanoid,
|
96
|
-
parseComplexResponse: () =>
|
97
|
-
parseStreamPart: () =>
|
98
|
-
readDataStream: () =>
|
86
|
+
parseComplexResponse: () => import_ui_utils10.parseComplexResponse,
|
87
|
+
parseStreamPart: () => import_ui_utils10.parseStreamPart,
|
88
|
+
readDataStream: () => import_ui_utils10.readDataStream,
|
99
89
|
readableFromAsyncIterable: () => readableFromAsyncIterable,
|
100
90
|
streamObject: () => streamObject,
|
101
91
|
streamText: () => streamText,
|
@@ -104,8 +94,11 @@ __export(streams_exports, {
|
|
104
94
|
trimStartOfStreamHelper: () => trimStartOfStreamHelper
|
105
95
|
});
|
106
96
|
module.exports = __toCommonJS(streams_exports);
|
97
|
+
var import_ui_utils10 = require("@ai-sdk/ui-utils");
|
98
|
+
var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
99
|
+
|
100
|
+
// core/index.ts
|
107
101
|
var import_ui_utils6 = require("@ai-sdk/ui-utils");
|
108
|
-
var import_provider_utils8 = require("@ai-sdk/provider-utils");
|
109
102
|
|
110
103
|
// util/retry-with-exponential-backoff.ts
|
111
104
|
var import_provider2 = require("@ai-sdk/provider");
|
@@ -228,7 +221,7 @@ function getBaseTelemetryAttributes({
|
|
228
221
|
telemetry,
|
229
222
|
headers
|
230
223
|
}) {
|
231
|
-
var
|
224
|
+
var _a12;
|
232
225
|
return {
|
233
226
|
"ai.model.provider": model.provider,
|
234
227
|
"ai.model.id": model.modelId,
|
@@ -241,7 +234,7 @@ function getBaseTelemetryAttributes({
|
|
241
234
|
"resource.name": telemetry == null ? void 0 : telemetry.functionId,
|
242
235
|
"ai.telemetry.functionId": telemetry == null ? void 0 : telemetry.functionId,
|
243
236
|
// add metadata as attributes:
|
244
|
-
...Object.entries((
|
237
|
+
...Object.entries((_a12 = telemetry == null ? void 0 : telemetry.metadata) != null ? _a12 : {}).reduce(
|
245
238
|
(attributes, [key, value]) => {
|
246
239
|
attributes[`ai.telemetry.metadata.${key}`] = value;
|
247
240
|
return attributes;
|
@@ -266,7 +259,7 @@ var noopTracer = {
|
|
266
259
|
startSpan() {
|
267
260
|
return noopSpan;
|
268
261
|
},
|
269
|
-
startActiveSpan(
|
262
|
+
startActiveSpan(name12, arg1, arg2, arg3) {
|
270
263
|
if (typeof arg1 === "function") {
|
271
264
|
return arg1(noopSpan);
|
272
265
|
}
|
@@ -334,13 +327,13 @@ function getTracer({ isEnabled }) {
|
|
334
327
|
// core/telemetry/record-span.ts
|
335
328
|
var import_api2 = require("@opentelemetry/api");
|
336
329
|
function recordSpan({
|
337
|
-
name:
|
330
|
+
name: name12,
|
338
331
|
tracer,
|
339
332
|
attributes,
|
340
333
|
fn,
|
341
334
|
endWhenDone = true
|
342
335
|
}) {
|
343
|
-
return tracer.startActiveSpan(
|
336
|
+
return tracer.startActiveSpan(name12, { attributes }, async (span) => {
|
344
337
|
try {
|
345
338
|
const result = await fn(span);
|
346
339
|
if (endWhenDone) {
|
@@ -406,14 +399,14 @@ async function embed({
|
|
406
399
|
headers,
|
407
400
|
experimental_telemetry: telemetry
|
408
401
|
}) {
|
409
|
-
var
|
402
|
+
var _a12;
|
410
403
|
const baseTelemetryAttributes = getBaseTelemetryAttributes({
|
411
404
|
model,
|
412
405
|
telemetry,
|
413
406
|
headers,
|
414
407
|
settings: { maxRetries }
|
415
408
|
});
|
416
|
-
const tracer = getTracer({ isEnabled: (
|
409
|
+
const tracer = getTracer({ isEnabled: (_a12 = telemetry == null ? void 0 : telemetry.isEnabled) != null ? _a12 : false });
|
417
410
|
return recordSpan({
|
418
411
|
name: "ai.embed",
|
419
412
|
attributes: selectTelemetryAttributes({
|
@@ -446,14 +439,14 @@ async function embed({
|
|
446
439
|
}),
|
447
440
|
tracer,
|
448
441
|
fn: async (doEmbedSpan) => {
|
449
|
-
var
|
442
|
+
var _a13;
|
450
443
|
const modelResponse = await model.doEmbed({
|
451
444
|
values: [value],
|
452
445
|
abortSignal,
|
453
446
|
headers
|
454
447
|
});
|
455
448
|
const embedding2 = modelResponse.embeddings[0];
|
456
|
-
const usage2 = (
|
449
|
+
const usage2 = (_a13 = modelResponse.usage) != null ? _a13 : { tokens: NaN };
|
457
450
|
doEmbedSpan.setAttributes(
|
458
451
|
selectTelemetryAttributes({
|
459
452
|
telemetry,
|
@@ -519,14 +512,14 @@ async function embedMany({
|
|
519
512
|
headers,
|
520
513
|
experimental_telemetry: telemetry
|
521
514
|
}) {
|
522
|
-
var
|
515
|
+
var _a12;
|
523
516
|
const baseTelemetryAttributes = getBaseTelemetryAttributes({
|
524
517
|
model,
|
525
518
|
telemetry,
|
526
519
|
headers,
|
527
520
|
settings: { maxRetries }
|
528
521
|
});
|
529
|
-
const tracer = getTracer({ isEnabled: (
|
522
|
+
const tracer = getTracer({ isEnabled: (_a12 = telemetry == null ? void 0 : telemetry.isEnabled) != null ? _a12 : false });
|
530
523
|
return recordSpan({
|
531
524
|
name: "ai.embedMany",
|
532
525
|
attributes: selectTelemetryAttributes({
|
@@ -564,14 +557,14 @@ async function embedMany({
|
|
564
557
|
}),
|
565
558
|
tracer,
|
566
559
|
fn: async (doEmbedSpan) => {
|
567
|
-
var
|
560
|
+
var _a13;
|
568
561
|
const modelResponse = await model.doEmbed({
|
569
562
|
values,
|
570
563
|
abortSignal,
|
571
564
|
headers
|
572
565
|
});
|
573
566
|
const embeddings3 = modelResponse.embeddings;
|
574
|
-
const usage2 = (
|
567
|
+
const usage2 = (_a13 = modelResponse.usage) != null ? _a13 : { tokens: NaN };
|
575
568
|
doEmbedSpan.setAttributes(
|
576
569
|
selectTelemetryAttributes({
|
577
570
|
telemetry,
|
@@ -623,14 +616,14 @@ async function embedMany({
|
|
623
616
|
}),
|
624
617
|
tracer,
|
625
618
|
fn: async (doEmbedSpan) => {
|
626
|
-
var
|
619
|
+
var _a13;
|
627
620
|
const modelResponse = await model.doEmbed({
|
628
621
|
values: chunk,
|
629
622
|
abortSignal,
|
630
623
|
headers
|
631
624
|
});
|
632
625
|
const embeddings2 = modelResponse.embeddings;
|
633
|
-
const usage2 = (
|
626
|
+
const usage2 = (_a13 = modelResponse.usage) != null ? _a13 : { tokens: NaN };
|
634
627
|
doEmbedSpan.setAttributes(
|
635
628
|
selectTelemetryAttributes({
|
636
629
|
telemetry,
|
@@ -677,7 +670,8 @@ var DefaultEmbedManyResult = class {
|
|
677
670
|
};
|
678
671
|
|
679
672
|
// core/generate-object/generate-object.ts
|
680
|
-
var
|
673
|
+
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
674
|
+
var import_ui_utils = require("@ai-sdk/ui-utils");
|
681
675
|
|
682
676
|
// core/prompt/convert-to-language-model-prompt.ts
|
683
677
|
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
@@ -732,7 +726,7 @@ async function download({
|
|
732
726
|
url,
|
733
727
|
fetchImplementation = fetch
|
734
728
|
}) {
|
735
|
-
var
|
729
|
+
var _a12;
|
736
730
|
const urlText = url.toString();
|
737
731
|
try {
|
738
732
|
const response = await fetchImplementation(urlText);
|
@@ -745,7 +739,7 @@ async function download({
|
|
745
739
|
}
|
746
740
|
return {
|
747
741
|
data: new Uint8Array(await response.arrayBuffer()),
|
748
|
-
mimeType: (
|
742
|
+
mimeType: (_a12 = response.headers.get("content-type")) != null ? _a12 : void 0
|
749
743
|
};
|
750
744
|
} catch (error) {
|
751
745
|
if (DownloadError.isInstance(error)) {
|
@@ -942,7 +936,7 @@ function convertToLanguageModelMessage(message, downloadedImages) {
|
|
942
936
|
role: "user",
|
943
937
|
content: message.content.map(
|
944
938
|
(part) => {
|
945
|
-
var
|
939
|
+
var _a12, _b, _c;
|
946
940
|
switch (part.type) {
|
947
941
|
case "text": {
|
948
942
|
return part;
|
@@ -960,7 +954,7 @@ function convertToLanguageModelMessage(message, downloadedImages) {
|
|
960
954
|
return {
|
961
955
|
type: "image",
|
962
956
|
image: downloadedImage.data,
|
963
|
-
mimeType: (
|
957
|
+
mimeType: (_a12 = part.mimeType) != null ? _a12 : downloadedImage.mimeType
|
964
958
|
};
|
965
959
|
}
|
966
960
|
}
|
@@ -1264,8 +1258,8 @@ function prepareResponseHeaders(init, {
|
|
1264
1258
|
contentType,
|
1265
1259
|
dataStreamVersion
|
1266
1260
|
}) {
|
1267
|
-
var
|
1268
|
-
const headers = new Headers((
|
1261
|
+
var _a12;
|
1262
|
+
const headers = new Headers((_a12 = init == null ? void 0 : init.headers) != null ? _a12 : {});
|
1269
1263
|
if (!headers.has("Content-Type")) {
|
1270
1264
|
headers.set("Content-Type", contentType);
|
1271
1265
|
}
|
@@ -1275,41 +1269,6 @@ function prepareResponseHeaders(init, {
|
|
1275
1269
|
return headers;
|
1276
1270
|
}
|
1277
1271
|
|
1278
|
-
// core/util/schema.ts
|
1279
|
-
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
1280
|
-
var import_zod_to_json_schema = __toESM(require("zod-to-json-schema"));
|
1281
|
-
var schemaSymbol = Symbol.for("vercel.ai.schema");
|
1282
|
-
function jsonSchema(jsonSchema2, {
|
1283
|
-
validate
|
1284
|
-
} = {}) {
|
1285
|
-
return {
|
1286
|
-
[schemaSymbol]: true,
|
1287
|
-
_type: void 0,
|
1288
|
-
// should never be used directly
|
1289
|
-
[import_provider_utils4.validatorSymbol]: true,
|
1290
|
-
jsonSchema: jsonSchema2,
|
1291
|
-
validate
|
1292
|
-
};
|
1293
|
-
}
|
1294
|
-
function isSchema(value) {
|
1295
|
-
return typeof value === "object" && value !== null && schemaSymbol in value && value[schemaSymbol] === true && "jsonSchema" in value && "validate" in value;
|
1296
|
-
}
|
1297
|
-
function asSchema(schema) {
|
1298
|
-
return isSchema(schema) ? schema : zodSchema(schema);
|
1299
|
-
}
|
1300
|
-
function zodSchema(zodSchema2) {
|
1301
|
-
return jsonSchema(
|
1302
|
-
// we assume that zodToJsonSchema will return a valid JSONSchema7:
|
1303
|
-
(0, import_zod_to_json_schema.default)(zodSchema2),
|
1304
|
-
{
|
1305
|
-
validate: (value) => {
|
1306
|
-
const result = zodSchema2.safeParse(value);
|
1307
|
-
return result.success ? { success: true, value: result.data } : { success: false, error: result.error };
|
1308
|
-
}
|
1309
|
-
}
|
1310
|
-
);
|
1311
|
-
}
|
1312
|
-
|
1313
1272
|
// core/generate-object/inject-json-schema-into-system.ts
|
1314
1273
|
var DEFAULT_SCHEMA_PREFIX = "JSON schema:";
|
1315
1274
|
var DEFAULT_SCHEMA_SUFFIX = "You MUST answer with a JSON object that matches the JSON schema above.";
|
@@ -1380,15 +1339,15 @@ async function generateObject({
|
|
1380
1339
|
experimental_telemetry: telemetry,
|
1381
1340
|
...settings
|
1382
1341
|
}) {
|
1383
|
-
var
|
1342
|
+
var _a12;
|
1384
1343
|
const baseTelemetryAttributes = getBaseTelemetryAttributes({
|
1385
1344
|
model,
|
1386
1345
|
telemetry,
|
1387
1346
|
headers,
|
1388
1347
|
settings: { ...settings, maxRetries }
|
1389
1348
|
});
|
1390
|
-
const schema = asSchema(inputSchema);
|
1391
|
-
const tracer = getTracer({ isEnabled: (
|
1349
|
+
const schema = (0, import_ui_utils.asSchema)(inputSchema);
|
1350
|
+
const tracer = getTracer({ isEnabled: (_a12 = telemetry == null ? void 0 : telemetry.isEnabled) != null ? _a12 : false });
|
1392
1351
|
return recordSpan({
|
1393
1352
|
name: "ai.generateObject",
|
1394
1353
|
attributes: selectTelemetryAttributes({
|
@@ -1548,7 +1507,7 @@ async function generateObject({
|
|
1548
1507
|
}),
|
1549
1508
|
tracer,
|
1550
1509
|
fn: async (span2) => {
|
1551
|
-
var
|
1510
|
+
var _a13, _b;
|
1552
1511
|
const result2 = await model.doGenerate({
|
1553
1512
|
mode: {
|
1554
1513
|
type: "object-tool",
|
@@ -1565,7 +1524,7 @@ async function generateObject({
|
|
1565
1524
|
abortSignal,
|
1566
1525
|
headers
|
1567
1526
|
});
|
1568
|
-
const objectText = (_b = (
|
1527
|
+
const objectText = (_b = (_a13 = result2.toolCalls) == null ? void 0 : _a13[0]) == null ? void 0 : _b.args;
|
1569
1528
|
if (objectText === void 0) {
|
1570
1529
|
throw new NoObjectGeneratedError();
|
1571
1530
|
}
|
@@ -1606,7 +1565,7 @@ async function generateObject({
|
|
1606
1565
|
throw new Error(`Unsupported mode: ${_exhaustiveCheck}`);
|
1607
1566
|
}
|
1608
1567
|
}
|
1609
|
-
const parseResult = (0,
|
1568
|
+
const parseResult = (0, import_provider_utils4.safeParseJSON)({ text: result, schema });
|
1610
1569
|
if (!parseResult.success) {
|
1611
1570
|
throw parseResult.error;
|
1612
1571
|
}
|
@@ -1644,9 +1603,9 @@ var DefaultGenerateObjectResult = class {
|
|
1644
1603
|
this.logprobs = options.logprobs;
|
1645
1604
|
}
|
1646
1605
|
toJsonResponse(init) {
|
1647
|
-
var
|
1606
|
+
var _a12;
|
1648
1607
|
return new Response(JSON.stringify(this.object), {
|
1649
|
-
status: (
|
1608
|
+
status: (_a12 = init == null ? void 0 : init.status) != null ? _a12 : 200,
|
1650
1609
|
headers: prepareResponseHeaders(init, {
|
1651
1610
|
contentType: "application/json; charset=utf-8"
|
1652
1611
|
})
|
@@ -1656,8 +1615,8 @@ var DefaultGenerateObjectResult = class {
|
|
1656
1615
|
var experimental_generateObject = generateObject;
|
1657
1616
|
|
1658
1617
|
// core/generate-object/stream-object.ts
|
1659
|
-
var
|
1660
|
-
var
|
1618
|
+
var import_provider_utils5 = require("@ai-sdk/provider-utils");
|
1619
|
+
var import_ui_utils2 = require("@ai-sdk/ui-utils");
|
1661
1620
|
|
1662
1621
|
// util/create-resolvable-promise.ts
|
1663
1622
|
function createResolvablePromise() {
|
@@ -1697,17 +1656,17 @@ var DelayedPromise = class {
|
|
1697
1656
|
return this.promise;
|
1698
1657
|
}
|
1699
1658
|
resolve(value) {
|
1700
|
-
var
|
1659
|
+
var _a12;
|
1701
1660
|
this.status = { type: "resolved", value };
|
1702
1661
|
if (this.promise) {
|
1703
|
-
(
|
1662
|
+
(_a12 = this._resolve) == null ? void 0 : _a12.call(this, value);
|
1704
1663
|
}
|
1705
1664
|
}
|
1706
1665
|
reject(error) {
|
1707
|
-
var
|
1666
|
+
var _a12;
|
1708
1667
|
this.status = { type: "rejected", error };
|
1709
1668
|
if (this.promise) {
|
1710
|
-
(
|
1669
|
+
(_a12 = this._reject) == null ? void 0 : _a12.call(this, error);
|
1711
1670
|
}
|
1712
1671
|
}
|
1713
1672
|
};
|
@@ -1746,16 +1705,16 @@ async function streamObject({
|
|
1746
1705
|
onFinish,
|
1747
1706
|
...settings
|
1748
1707
|
}) {
|
1749
|
-
var
|
1708
|
+
var _a12;
|
1750
1709
|
const baseTelemetryAttributes = getBaseTelemetryAttributes({
|
1751
1710
|
model,
|
1752
1711
|
telemetry,
|
1753
1712
|
headers,
|
1754
1713
|
settings: { ...settings, maxRetries }
|
1755
1714
|
});
|
1756
|
-
const tracer = getTracer({ isEnabled: (
|
1715
|
+
const tracer = getTracer({ isEnabled: (_a12 = telemetry == null ? void 0 : telemetry.isEnabled) != null ? _a12 : false });
|
1757
1716
|
const retry = retryWithExponentialBackoff({ maxRetries });
|
1758
|
-
const schema = asSchema(inputSchema);
|
1717
|
+
const schema = (0, import_ui_utils2.asSchema)(inputSchema);
|
1759
1718
|
return recordSpan({
|
1760
1719
|
name: "ai.streamObject",
|
1761
1720
|
attributes: selectTelemetryAttributes({
|
@@ -1960,10 +1919,10 @@ var DefaultStreamObjectResult = class {
|
|
1960
1919
|
if (typeof chunk === "string") {
|
1961
1920
|
accumulatedText += chunk;
|
1962
1921
|
delta += chunk;
|
1963
|
-
const currentObject = (0,
|
1922
|
+
const currentObject = (0, import_ui_utils2.parsePartialJson)(
|
1964
1923
|
accumulatedText
|
1965
1924
|
);
|
1966
|
-
if (!(0,
|
1925
|
+
if (!(0, import_ui_utils2.isDeepEqualData)(latestObject, currentObject)) {
|
1967
1926
|
latestObject = currentObject;
|
1968
1927
|
controller.enqueue({
|
1969
1928
|
type: "object",
|
@@ -1989,7 +1948,7 @@ var DefaultStreamObjectResult = class {
|
|
1989
1948
|
usage = calculateCompletionTokenUsage(chunk.usage);
|
1990
1949
|
controller.enqueue({ ...chunk, usage });
|
1991
1950
|
resolveUsage(usage);
|
1992
|
-
const validationResult = (0,
|
1951
|
+
const validationResult = (0, import_provider_utils5.safeValidateTypes)({
|
1993
1952
|
value: latestObject,
|
1994
1953
|
schema
|
1995
1954
|
});
|
@@ -2115,8 +2074,8 @@ var DefaultStreamObjectResult = class {
|
|
2115
2074
|
});
|
2116
2075
|
}
|
2117
2076
|
pipeTextStreamToResponse(response, init) {
|
2118
|
-
var
|
2119
|
-
response.writeHead((
|
2077
|
+
var _a12;
|
2078
|
+
response.writeHead((_a12 = init == null ? void 0 : init.status) != null ? _a12 : 200, {
|
2120
2079
|
"Content-Type": "text/plain; charset=utf-8",
|
2121
2080
|
...init == null ? void 0 : init.headers
|
2122
2081
|
});
|
@@ -2138,9 +2097,9 @@ var DefaultStreamObjectResult = class {
|
|
2138
2097
|
read();
|
2139
2098
|
}
|
2140
2099
|
toTextStreamResponse(init) {
|
2141
|
-
var
|
2100
|
+
var _a12;
|
2142
2101
|
return new Response(this.textStream.pipeThrough(new TextEncoderStream()), {
|
2143
|
-
status: (
|
2102
|
+
status: (_a12 = init == null ? void 0 : init.status) != null ? _a12 : 200,
|
2144
2103
|
headers: prepareResponseHeaders(init, {
|
2145
2104
|
contentType: "text/plain; charset=utf-8"
|
2146
2105
|
})
|
@@ -2149,6 +2108,9 @@ var DefaultStreamObjectResult = class {
|
|
2149
2108
|
};
|
2150
2109
|
var experimental_streamObject = streamObject;
|
2151
2110
|
|
2111
|
+
// core/prompt/prepare-tools-and-tool-choice.ts
|
2112
|
+
var import_ui_utils3 = require("@ai-sdk/ui-utils");
|
2113
|
+
|
2152
2114
|
// core/util/is-non-empty-object.ts
|
2153
2115
|
function isNonEmptyObject(object) {
|
2154
2116
|
return object != null && Object.keys(object).length > 0;
|
@@ -2166,18 +2128,19 @@ function prepareToolsAndToolChoice({
|
|
2166
2128
|
};
|
2167
2129
|
}
|
2168
2130
|
return {
|
2169
|
-
tools: Object.entries(tools).map(([
|
2131
|
+
tools: Object.entries(tools).map(([name12, tool2]) => ({
|
2170
2132
|
type: "function",
|
2171
|
-
name:
|
2133
|
+
name: name12,
|
2172
2134
|
description: tool2.description,
|
2173
|
-
parameters: asSchema(tool2.parameters).jsonSchema
|
2135
|
+
parameters: (0, import_ui_utils3.asSchema)(tool2.parameters).jsonSchema
|
2174
2136
|
})),
|
2175
2137
|
toolChoice: toolChoice == null ? { type: "auto" } : typeof toolChoice === "string" ? { type: toolChoice } : { type: "tool", toolName: toolChoice.toolName }
|
2176
2138
|
};
|
2177
2139
|
}
|
2178
2140
|
|
2179
2141
|
// core/generate-text/tool-call.ts
|
2180
|
-
var
|
2142
|
+
var import_provider_utils6 = require("@ai-sdk/provider-utils");
|
2143
|
+
var import_ui_utils4 = require("@ai-sdk/ui-utils");
|
2181
2144
|
|
2182
2145
|
// errors/invalid-tool-arguments-error.ts
|
2183
2146
|
var import_provider9 = require("@ai-sdk/provider");
|
@@ -2281,9 +2244,9 @@ function parseToolCall({
|
|
2281
2244
|
availableTools: Object.keys(tools)
|
2282
2245
|
});
|
2283
2246
|
}
|
2284
|
-
const parseResult = (0,
|
2247
|
+
const parseResult = (0, import_provider_utils6.safeParseJSON)({
|
2285
2248
|
text: toolCall.args,
|
2286
|
-
schema: asSchema(tool2.parameters)
|
2249
|
+
schema: (0, import_ui_utils4.asSchema)(tool2.parameters)
|
2287
2250
|
});
|
2288
2251
|
if (parseResult.success === false) {
|
2289
2252
|
throw new InvalidToolArgumentsError({
|
@@ -2316,14 +2279,14 @@ async function generateText({
|
|
2316
2279
|
experimental_telemetry: telemetry,
|
2317
2280
|
...settings
|
2318
2281
|
}) {
|
2319
|
-
var
|
2282
|
+
var _a12;
|
2320
2283
|
const baseTelemetryAttributes = getBaseTelemetryAttributes({
|
2321
2284
|
model,
|
2322
2285
|
telemetry,
|
2323
2286
|
headers,
|
2324
2287
|
settings: { ...settings, maxRetries }
|
2325
2288
|
});
|
2326
|
-
const tracer = getTracer({ isEnabled: (
|
2289
|
+
const tracer = getTracer({ isEnabled: (_a12 = telemetry == null ? void 0 : telemetry.isEnabled) != null ? _a12 : false });
|
2327
2290
|
return recordSpan({
|
2328
2291
|
name: "ai.generateText",
|
2329
2292
|
attributes: selectTelemetryAttributes({
|
@@ -2343,7 +2306,7 @@ async function generateText({
|
|
2343
2306
|
}),
|
2344
2307
|
tracer,
|
2345
2308
|
fn: async (span) => {
|
2346
|
-
var
|
2309
|
+
var _a13, _b, _c, _d;
|
2347
2310
|
const retry = retryWithExponentialBackoff({ maxRetries });
|
2348
2311
|
const validatedPrompt = getValidatedPrompt({
|
2349
2312
|
system,
|
@@ -2429,7 +2392,7 @@ async function generateText({
|
|
2429
2392
|
}
|
2430
2393
|
})
|
2431
2394
|
);
|
2432
|
-
currentToolCalls = ((
|
2395
|
+
currentToolCalls = ((_a13 = currentModelResponse.toolCalls) != null ? _a13 : []).map(
|
2433
2396
|
(modelToolCall) => parseToolCall({ toolCall: modelToolCall, tools })
|
2434
2397
|
);
|
2435
2398
|
currentToolResults = tools == null ? [] : await executeTools({
|
@@ -2691,7 +2654,7 @@ function mergeStreams(stream1, stream2) {
|
|
2691
2654
|
}
|
2692
2655
|
|
2693
2656
|
// core/generate-text/run-tools-transformation.ts
|
2694
|
-
var
|
2657
|
+
var import_ui_utils5 = require("@ai-sdk/ui-utils");
|
2695
2658
|
function runToolsTransformation({
|
2696
2659
|
tools,
|
2697
2660
|
generatorStream,
|
@@ -2763,7 +2726,7 @@ function runToolsTransformation({
|
|
2763
2726
|
});
|
2764
2727
|
controller.enqueue(toolCall);
|
2765
2728
|
if (tool2.execute != null) {
|
2766
|
-
const toolExecutionId = (0,
|
2729
|
+
const toolExecutionId = (0, import_ui_utils5.generateId)();
|
2767
2730
|
outstandingToolCalls.add(toolExecutionId);
|
2768
2731
|
recordSpan({
|
2769
2732
|
name: "ai.toolCall",
|
@@ -2893,14 +2856,14 @@ async function streamText({
|
|
2893
2856
|
onFinish,
|
2894
2857
|
...settings
|
2895
2858
|
}) {
|
2896
|
-
var
|
2859
|
+
var _a12;
|
2897
2860
|
const baseTelemetryAttributes = getBaseTelemetryAttributes({
|
2898
2861
|
model,
|
2899
2862
|
telemetry,
|
2900
2863
|
headers,
|
2901
2864
|
settings: { ...settings, maxRetries }
|
2902
2865
|
});
|
2903
|
-
const tracer = getTracer({ isEnabled: (
|
2866
|
+
const tracer = getTracer({ isEnabled: (_a12 = telemetry == null ? void 0 : telemetry.isEnabled) != null ? _a12 : false });
|
2904
2867
|
return recordSpan({
|
2905
2868
|
name: "ai.streamText",
|
2906
2869
|
attributes: selectTelemetryAttributes({
|
@@ -3058,7 +3021,7 @@ var DefaultStreamTextResult = class {
|
|
3058
3021
|
},
|
3059
3022
|
// invoke onFinish callback and resolve toolResults promise when the stream is about to close:
|
3060
3023
|
async flush(controller) {
|
3061
|
-
var
|
3024
|
+
var _a12;
|
3062
3025
|
try {
|
3063
3026
|
const finalUsage = usage != null ? usage : {
|
3064
3027
|
promptTokens: NaN,
|
@@ -3097,7 +3060,7 @@ var DefaultStreamTextResult = class {
|
|
3097
3060
|
})
|
3098
3061
|
);
|
3099
3062
|
resolveToolResults(toolResults);
|
3100
|
-
await ((
|
3063
|
+
await ((_a12 = self.onFinish) == null ? void 0 : _a12.call(self, {
|
3101
3064
|
finishReason: finalFinishReason,
|
3102
3065
|
usage: finalUsage,
|
3103
3066
|
text,
|
@@ -3195,11 +3158,11 @@ var DefaultStreamTextResult = class {
|
|
3195
3158
|
const chunkType = chunk.type;
|
3196
3159
|
switch (chunkType) {
|
3197
3160
|
case "text-delta":
|
3198
|
-
controller.enqueue((0,
|
3161
|
+
controller.enqueue((0, import_ui_utils10.formatStreamPart)("text", chunk.textDelta));
|
3199
3162
|
break;
|
3200
3163
|
case "tool-call-streaming-start":
|
3201
3164
|
controller.enqueue(
|
3202
|
-
(0,
|
3165
|
+
(0, import_ui_utils10.formatStreamPart)("tool_call_streaming_start", {
|
3203
3166
|
toolCallId: chunk.toolCallId,
|
3204
3167
|
toolName: chunk.toolName
|
3205
3168
|
})
|
@@ -3207,7 +3170,7 @@ var DefaultStreamTextResult = class {
|
|
3207
3170
|
break;
|
3208
3171
|
case "tool-call-delta":
|
3209
3172
|
controller.enqueue(
|
3210
|
-
(0,
|
3173
|
+
(0, import_ui_utils10.formatStreamPart)("tool_call_delta", {
|
3211
3174
|
toolCallId: chunk.toolCallId,
|
3212
3175
|
argsTextDelta: chunk.argsTextDelta
|
3213
3176
|
})
|
@@ -3215,7 +3178,7 @@ var DefaultStreamTextResult = class {
|
|
3215
3178
|
break;
|
3216
3179
|
case "tool-call":
|
3217
3180
|
controller.enqueue(
|
3218
|
-
(0,
|
3181
|
+
(0, import_ui_utils10.formatStreamPart)("tool_call", {
|
3219
3182
|
toolCallId: chunk.toolCallId,
|
3220
3183
|
toolName: chunk.toolName,
|
3221
3184
|
args: chunk.args
|
@@ -3224,7 +3187,7 @@ var DefaultStreamTextResult = class {
|
|
3224
3187
|
break;
|
3225
3188
|
case "tool-result":
|
3226
3189
|
controller.enqueue(
|
3227
|
-
(0,
|
3190
|
+
(0, import_ui_utils10.formatStreamPart)("tool_result", {
|
3228
3191
|
toolCallId: chunk.toolCallId,
|
3229
3192
|
result: chunk.result
|
3230
3193
|
})
|
@@ -3232,12 +3195,12 @@ var DefaultStreamTextResult = class {
|
|
3232
3195
|
break;
|
3233
3196
|
case "error":
|
3234
3197
|
controller.enqueue(
|
3235
|
-
(0,
|
3198
|
+
(0, import_ui_utils10.formatStreamPart)("error", getErrorMessage4(chunk.error))
|
3236
3199
|
);
|
3237
3200
|
break;
|
3238
3201
|
case "finish":
|
3239
3202
|
controller.enqueue(
|
3240
|
-
(0,
|
3203
|
+
(0, import_ui_utils10.formatStreamPart)("finish_message", {
|
3241
3204
|
finishReason: chunk.finishReason,
|
3242
3205
|
usage: {
|
3243
3206
|
promptTokens: chunk.usage.promptTokens,
|
@@ -3259,8 +3222,8 @@ var DefaultStreamTextResult = class {
|
|
3259
3222
|
return this.pipeDataStreamToResponse(response, init);
|
3260
3223
|
}
|
3261
3224
|
pipeDataStreamToResponse(response, init) {
|
3262
|
-
var
|
3263
|
-
response.writeHead((
|
3225
|
+
var _a12;
|
3226
|
+
response.writeHead((_a12 = init == null ? void 0 : init.status) != null ? _a12 : 200, {
|
3264
3227
|
"Content-Type": "text/plain; charset=utf-8",
|
3265
3228
|
...init == null ? void 0 : init.headers
|
3266
3229
|
});
|
@@ -3282,8 +3245,8 @@ var DefaultStreamTextResult = class {
|
|
3282
3245
|
read();
|
3283
3246
|
}
|
3284
3247
|
pipeTextStreamToResponse(response, init) {
|
3285
|
-
var
|
3286
|
-
response.writeHead((
|
3248
|
+
var _a12;
|
3249
|
+
response.writeHead((_a12 = init == null ? void 0 : init.status) != null ? _a12 : 200, {
|
3287
3250
|
"Content-Type": "text/plain; charset=utf-8",
|
3288
3251
|
...init == null ? void 0 : init.headers
|
3289
3252
|
});
|
@@ -3308,7 +3271,7 @@ var DefaultStreamTextResult = class {
|
|
3308
3271
|
return this.toDataStreamResponse(options);
|
3309
3272
|
}
|
3310
3273
|
toDataStreamResponse(options) {
|
3311
|
-
var
|
3274
|
+
var _a12;
|
3312
3275
|
const init = options == null ? void 0 : "init" in options ? options.init : {
|
3313
3276
|
headers: "headers" in options ? options.headers : void 0,
|
3314
3277
|
status: "status" in options ? options.status : void 0,
|
@@ -3318,7 +3281,7 @@ var DefaultStreamTextResult = class {
|
|
3318
3281
|
const getErrorMessage4 = options == null ? void 0 : "getErrorMessage" in options ? options.getErrorMessage : void 0;
|
3319
3282
|
const stream = data ? mergeStreams(data.stream, this.toDataStream({ getErrorMessage: getErrorMessage4 })) : this.toDataStream({ getErrorMessage: getErrorMessage4 });
|
3320
3283
|
return new Response(stream, {
|
3321
|
-
status: (
|
3284
|
+
status: (_a12 = init == null ? void 0 : init.status) != null ? _a12 : 200,
|
3322
3285
|
statusText: init == null ? void 0 : init.statusText,
|
3323
3286
|
headers: prepareResponseHeaders(init, {
|
3324
3287
|
contentType: "text/plain; charset=utf-8",
|
@@ -3327,9 +3290,9 @@ var DefaultStreamTextResult = class {
|
|
3327
3290
|
});
|
3328
3291
|
}
|
3329
3292
|
toTextStreamResponse(init) {
|
3330
|
-
var
|
3293
|
+
var _a12;
|
3331
3294
|
return new Response(this.textStream.pipeThrough(new TextEncoderStream()), {
|
3332
|
-
status: (
|
3295
|
+
status: (_a12 = init == null ? void 0 : init.status) != null ? _a12 : 200,
|
3333
3296
|
headers: prepareResponseHeaders(init, {
|
3334
3297
|
contentType: "text/plain; charset=utf-8"
|
3335
3298
|
})
|
@@ -3340,7 +3303,7 @@ var experimental_streamText = streamText;
|
|
3340
3303
|
|
3341
3304
|
// core/prompt/attachments-to-parts.ts
|
3342
3305
|
function attachmentsToParts(attachments) {
|
3343
|
-
var
|
3306
|
+
var _a12, _b, _c;
|
3344
3307
|
const parts = [];
|
3345
3308
|
for (const attachment of attachments) {
|
3346
3309
|
let url;
|
@@ -3352,7 +3315,7 @@ function attachmentsToParts(attachments) {
|
|
3352
3315
|
switch (url.protocol) {
|
3353
3316
|
case "http:":
|
3354
3317
|
case "https:": {
|
3355
|
-
if ((
|
3318
|
+
if ((_a12 = attachment.contentType) == null ? void 0 : _a12.startsWith("image/")) {
|
3356
3319
|
parts.push({ type: "image", image: url });
|
3357
3320
|
}
|
3358
3321
|
break;
|
@@ -3461,18 +3424,32 @@ function convertToCoreMessages(messages) {
|
|
3461
3424
|
}
|
3462
3425
|
|
3463
3426
|
// core/registry/invalid-model-id-error.ts
|
3464
|
-
var
|
3427
|
+
var import_provider11 = require("@ai-sdk/provider");
|
3428
|
+
var name9 = "AI_InvalidModelIdError";
|
3429
|
+
var marker9 = `vercel.ai.error.${name9}`;
|
3430
|
+
var symbol9 = Symbol.for(marker9);
|
3431
|
+
var _a9;
|
3432
|
+
var InvalidModelIdError = class extends import_provider11.AISDKError {
|
3465
3433
|
constructor({
|
3466
3434
|
id,
|
3467
3435
|
message = `Invalid model id: ${id}`
|
3468
3436
|
}) {
|
3469
|
-
super(message);
|
3470
|
-
this
|
3437
|
+
super({ name: name9, message });
|
3438
|
+
this[_a9] = true;
|
3471
3439
|
this.id = id;
|
3472
3440
|
}
|
3441
|
+
static isInstance(error) {
|
3442
|
+
return import_provider11.AISDKError.hasMarker(error, marker9);
|
3443
|
+
}
|
3444
|
+
/**
|
3445
|
+
* @deprecated use `isInstance` instead
|
3446
|
+
*/
|
3473
3447
|
static isInvalidModelIdError(error) {
|
3474
|
-
return error instanceof Error && error.name ===
|
3448
|
+
return error instanceof Error && error.name === name9 && typeof error.id === "string";
|
3475
3449
|
}
|
3450
|
+
/**
|
3451
|
+
* @deprecated Do not use this method. It will be removed in the next major version.
|
3452
|
+
*/
|
3476
3453
|
toJSON() {
|
3477
3454
|
return {
|
3478
3455
|
name: this.name,
|
@@ -3482,22 +3459,37 @@ var InvalidModelIdError = class extends Error {
|
|
3482
3459
|
};
|
3483
3460
|
}
|
3484
3461
|
};
|
3462
|
+
_a9 = symbol9;
|
3485
3463
|
|
3486
3464
|
// core/registry/no-such-model-error.ts
|
3487
|
-
var
|
3465
|
+
var import_provider12 = require("@ai-sdk/provider");
|
3466
|
+
var name10 = "AI_NoSuchModelError";
|
3467
|
+
var marker10 = `vercel.ai.error.${name10}`;
|
3468
|
+
var symbol10 = Symbol.for(marker10);
|
3469
|
+
var _a10;
|
3470
|
+
var NoSuchModelError = class extends import_provider12.AISDKError {
|
3488
3471
|
constructor({
|
3489
3472
|
modelId,
|
3490
3473
|
modelType,
|
3491
3474
|
message = `No such ${modelType}: ${modelId}`
|
3492
3475
|
}) {
|
3493
|
-
super(message);
|
3494
|
-
this
|
3476
|
+
super({ name: name10, message });
|
3477
|
+
this[_a10] = true;
|
3495
3478
|
this.modelId = modelId;
|
3496
3479
|
this.modelType = modelType;
|
3497
3480
|
}
|
3481
|
+
static isInstance(error) {
|
3482
|
+
return import_provider12.AISDKError.hasMarker(error, marker10);
|
3483
|
+
}
|
3484
|
+
/**
|
3485
|
+
* @deprecated use `isInstance` instead
|
3486
|
+
*/
|
3498
3487
|
static isNoSuchModelError(error) {
|
3499
|
-
return error instanceof Error && error.name ===
|
3488
|
+
return error instanceof Error && error.name === name10 && typeof error.modelId === "string" && typeof error.modelType === "string";
|
3500
3489
|
}
|
3490
|
+
/**
|
3491
|
+
* @deprecated Do not use this method. It will be removed in the next major version.
|
3492
|
+
*/
|
3501
3493
|
toJSON() {
|
3502
3494
|
return {
|
3503
3495
|
name: this.name,
|
@@ -3508,22 +3500,37 @@ var NoSuchModelError = class extends Error {
|
|
3508
3500
|
};
|
3509
3501
|
}
|
3510
3502
|
};
|
3503
|
+
_a10 = symbol10;
|
3511
3504
|
|
3512
3505
|
// core/registry/no-such-provider-error.ts
|
3513
|
-
var
|
3506
|
+
var import_provider13 = require("@ai-sdk/provider");
|
3507
|
+
var name11 = "AI_NoSuchProviderError";
|
3508
|
+
var marker11 = `vercel.ai.error.${name11}`;
|
3509
|
+
var symbol11 = Symbol.for(marker11);
|
3510
|
+
var _a11;
|
3511
|
+
var NoSuchProviderError = class extends import_provider13.AISDKError {
|
3514
3512
|
constructor({
|
3515
3513
|
providerId,
|
3516
3514
|
availableProviders,
|
3517
3515
|
message = `No such provider: ${providerId} (available providers: ${availableProviders.join()})`
|
3518
3516
|
}) {
|
3519
|
-
super(message);
|
3520
|
-
this
|
3517
|
+
super({ name: name11, message });
|
3518
|
+
this[_a11] = true;
|
3521
3519
|
this.providerId = providerId;
|
3522
3520
|
this.availableProviders = availableProviders;
|
3523
3521
|
}
|
3522
|
+
static isInstance(error) {
|
3523
|
+
return import_provider13.AISDKError.hasMarker(error, marker11);
|
3524
|
+
}
|
3525
|
+
/**
|
3526
|
+
* @deprecated use `isInstance` instead
|
3527
|
+
*/
|
3524
3528
|
static isNoSuchProviderError(error) {
|
3525
|
-
return error instanceof Error && error.name ===
|
3529
|
+
return error instanceof Error && error.name === name11 && typeof error.providerId === "string" && Array.isArray(error.availableProviders);
|
3526
3530
|
}
|
3531
|
+
/**
|
3532
|
+
* @deprecated Do not use this method. It will be removed in the next major version.
|
3533
|
+
*/
|
3527
3534
|
toJSON() {
|
3528
3535
|
return {
|
3529
3536
|
name: this.name,
|
@@ -3534,6 +3541,7 @@ var NoSuchProviderError = class extends Error {
|
|
3534
3541
|
};
|
3535
3542
|
}
|
3536
3543
|
};
|
3544
|
+
_a11 = symbol11;
|
3537
3545
|
|
3538
3546
|
// core/registry/provider-registry.ts
|
3539
3547
|
function experimental_createProviderRegistry(providers) {
|
@@ -3548,7 +3556,10 @@ var DefaultProviderRegistry = class {
|
|
3548
3556
|
constructor() {
|
3549
3557
|
this.providers = {};
|
3550
3558
|
}
|
3551
|
-
registerProvider({
|
3559
|
+
registerProvider({
|
3560
|
+
id,
|
3561
|
+
provider
|
3562
|
+
}) {
|
3552
3563
|
this.providers[id] = provider;
|
3553
3564
|
}
|
3554
3565
|
getProvider(id) {
|
@@ -3569,26 +3580,33 @@ var DefaultProviderRegistry = class {
|
|
3569
3580
|
return [id.slice(0, index), id.slice(index + 1)];
|
3570
3581
|
}
|
3571
3582
|
languageModel(id) {
|
3572
|
-
var
|
3583
|
+
var _a12, _b;
|
3573
3584
|
const [providerId, modelId] = this.splitId(id);
|
3574
|
-
const model = (_b = (
|
3585
|
+
const model = (_b = (_a12 = this.getProvider(providerId)).languageModel) == null ? void 0 : _b.call(_a12, modelId);
|
3575
3586
|
if (model == null) {
|
3576
|
-
throw new NoSuchModelError({ modelId: id, modelType: "
|
3587
|
+
throw new NoSuchModelError({ modelId: id, modelType: "languageModel" });
|
3577
3588
|
}
|
3578
3589
|
return model;
|
3579
3590
|
}
|
3580
3591
|
textEmbeddingModel(id) {
|
3581
|
-
var
|
3592
|
+
var _a12, _b, _c;
|
3582
3593
|
const [providerId, modelId] = this.splitId(id);
|
3583
|
-
const
|
3594
|
+
const provider = this.getProvider(providerId);
|
3595
|
+
const model = (_c = (_a12 = provider.textEmbeddingModel) == null ? void 0 : _a12.call(provider, modelId)) != null ? _c : (_b = provider.textEmbedding) == null ? void 0 : _b.call(provider, modelId);
|
3584
3596
|
if (model == null) {
|
3585
3597
|
throw new NoSuchModelError({
|
3586
3598
|
modelId: id,
|
3587
|
-
modelType: "
|
3599
|
+
modelType: "textEmbeddingModel"
|
3588
3600
|
});
|
3589
3601
|
}
|
3590
3602
|
return model;
|
3591
3603
|
}
|
3604
|
+
/**
|
3605
|
+
* @deprecated Use `textEmbeddingModel` instead.
|
3606
|
+
*/
|
3607
|
+
textEmbedding(id) {
|
3608
|
+
return this.textEmbeddingModel(id);
|
3609
|
+
}
|
3592
3610
|
};
|
3593
3611
|
|
3594
3612
|
// core/tool/tool.ts
|
@@ -3616,7 +3634,7 @@ function magnitude(vector) {
|
|
3616
3634
|
}
|
3617
3635
|
|
3618
3636
|
// errors/index.ts
|
3619
|
-
var
|
3637
|
+
var import_provider14 = require("@ai-sdk/provider");
|
3620
3638
|
|
3621
3639
|
// streams/ai-stream.ts
|
3622
3640
|
var import_eventsource_parser = require("eventsource-parser");
|
@@ -3734,14 +3752,14 @@ function readableFromAsyncIterable(iterable) {
|
|
3734
3752
|
controller.enqueue(value);
|
3735
3753
|
},
|
3736
3754
|
async cancel(reason) {
|
3737
|
-
var
|
3738
|
-
await ((
|
3755
|
+
var _a12;
|
3756
|
+
await ((_a12 = it.return) == null ? void 0 : _a12.call(it, reason));
|
3739
3757
|
}
|
3740
3758
|
});
|
3741
3759
|
}
|
3742
3760
|
|
3743
3761
|
// streams/stream-data.ts
|
3744
|
-
var
|
3762
|
+
var import_ui_utils7 = require("@ai-sdk/ui-utils");
|
3745
3763
|
var STREAM_DATA_WARNING_TIME_MS = 15 * 1e3;
|
3746
3764
|
var StreamData2 = class {
|
3747
3765
|
constructor() {
|
@@ -3789,7 +3807,7 @@ var StreamData2 = class {
|
|
3789
3807
|
throw new Error("Stream controller is not initialized.");
|
3790
3808
|
}
|
3791
3809
|
this.controller.enqueue(
|
3792
|
-
this.encoder.encode((0,
|
3810
|
+
this.encoder.encode((0, import_ui_utils7.formatStreamPart)("data", [value]))
|
3793
3811
|
);
|
3794
3812
|
}
|
3795
3813
|
appendMessageAnnotation(value) {
|
@@ -3800,7 +3818,7 @@ var StreamData2 = class {
|
|
3800
3818
|
throw new Error("Stream controller is not initialized.");
|
3801
3819
|
}
|
3802
3820
|
this.controller.enqueue(
|
3803
|
-
this.encoder.encode((0,
|
3821
|
+
this.encoder.encode((0, import_ui_utils7.formatStreamPart)("message_annotations", [value]))
|
3804
3822
|
);
|
3805
3823
|
}
|
3806
3824
|
};
|
@@ -3810,7 +3828,7 @@ function createStreamDataTransformer() {
|
|
3810
3828
|
return new TransformStream({
|
3811
3829
|
transform: async (chunk, controller) => {
|
3812
3830
|
const message = decoder.decode(chunk);
|
3813
|
-
controller.enqueue(encoder.encode((0,
|
3831
|
+
controller.enqueue(encoder.encode((0, import_ui_utils7.formatStreamPart)("text", message)));
|
3814
3832
|
}
|
3815
3833
|
});
|
3816
3834
|
}
|
@@ -3864,36 +3882,36 @@ function AnthropicStream(res, cb) {
|
|
3864
3882
|
}
|
3865
3883
|
|
3866
3884
|
// streams/assistant-response.ts
|
3867
|
-
var
|
3885
|
+
var import_ui_utils8 = require("@ai-sdk/ui-utils");
|
3868
3886
|
function AssistantResponse({ threadId, messageId }, process2) {
|
3869
3887
|
const stream = new ReadableStream({
|
3870
3888
|
async start(controller) {
|
3871
|
-
var
|
3889
|
+
var _a12;
|
3872
3890
|
const textEncoder = new TextEncoder();
|
3873
3891
|
const sendMessage = (message) => {
|
3874
3892
|
controller.enqueue(
|
3875
|
-
textEncoder.encode((0,
|
3893
|
+
textEncoder.encode((0, import_ui_utils8.formatStreamPart)("assistant_message", message))
|
3876
3894
|
);
|
3877
3895
|
};
|
3878
3896
|
const sendDataMessage = (message) => {
|
3879
3897
|
controller.enqueue(
|
3880
|
-
textEncoder.encode((0,
|
3898
|
+
textEncoder.encode((0, import_ui_utils8.formatStreamPart)("data_message", message))
|
3881
3899
|
);
|
3882
3900
|
};
|
3883
3901
|
const sendError = (errorMessage) => {
|
3884
3902
|
controller.enqueue(
|
3885
|
-
textEncoder.encode((0,
|
3903
|
+
textEncoder.encode((0, import_ui_utils8.formatStreamPart)("error", errorMessage))
|
3886
3904
|
);
|
3887
3905
|
};
|
3888
3906
|
const forwardStream = async (stream2) => {
|
3889
|
-
var
|
3907
|
+
var _a13, _b;
|
3890
3908
|
let result = void 0;
|
3891
3909
|
for await (const value of stream2) {
|
3892
3910
|
switch (value.event) {
|
3893
3911
|
case "thread.message.created": {
|
3894
3912
|
controller.enqueue(
|
3895
3913
|
textEncoder.encode(
|
3896
|
-
(0,
|
3914
|
+
(0, import_ui_utils8.formatStreamPart)("assistant_message", {
|
3897
3915
|
id: value.data.id,
|
3898
3916
|
role: "assistant",
|
3899
3917
|
content: [{ type: "text", text: { value: "" } }]
|
@@ -3903,11 +3921,11 @@ function AssistantResponse({ threadId, messageId }, process2) {
|
|
3903
3921
|
break;
|
3904
3922
|
}
|
3905
3923
|
case "thread.message.delta": {
|
3906
|
-
const content = (
|
3924
|
+
const content = (_a13 = value.data.delta.content) == null ? void 0 : _a13[0];
|
3907
3925
|
if ((content == null ? void 0 : content.type) === "text" && ((_b = content.text) == null ? void 0 : _b.value) != null) {
|
3908
3926
|
controller.enqueue(
|
3909
3927
|
textEncoder.encode(
|
3910
|
-
(0,
|
3928
|
+
(0, import_ui_utils8.formatStreamPart)("text", content.text.value)
|
3911
3929
|
)
|
3912
3930
|
);
|
3913
3931
|
}
|
@@ -3924,7 +3942,7 @@ function AssistantResponse({ threadId, messageId }, process2) {
|
|
3924
3942
|
};
|
3925
3943
|
controller.enqueue(
|
3926
3944
|
textEncoder.encode(
|
3927
|
-
(0,
|
3945
|
+
(0, import_ui_utils8.formatStreamPart)("assistant_control_data", {
|
3928
3946
|
threadId,
|
3929
3947
|
messageId
|
3930
3948
|
})
|
@@ -3939,7 +3957,7 @@ function AssistantResponse({ threadId, messageId }, process2) {
|
|
3939
3957
|
forwardStream
|
3940
3958
|
});
|
3941
3959
|
} catch (error) {
|
3942
|
-
sendError((
|
3960
|
+
sendError((_a12 = error.message) != null ? _a12 : `${error}`);
|
3943
3961
|
} finally {
|
3944
3962
|
controller.close();
|
3945
3963
|
}
|
@@ -3960,9 +3978,9 @@ var experimental_AssistantResponse = AssistantResponse;
|
|
3960
3978
|
|
3961
3979
|
// streams/aws-bedrock-stream.ts
|
3962
3980
|
async function* asDeltaIterable(response, extractTextDeltaFromChunk) {
|
3963
|
-
var
|
3981
|
+
var _a12, _b;
|
3964
3982
|
const decoder = new TextDecoder();
|
3965
|
-
for await (const chunk of (
|
3983
|
+
for await (const chunk of (_a12 = response.body) != null ? _a12 : []) {
|
3966
3984
|
const bytes = (_b = chunk.chunk) == null ? void 0 : _b.bytes;
|
3967
3985
|
if (bytes != null) {
|
3968
3986
|
const chunkText = decoder.decode(bytes);
|
@@ -3976,8 +3994,8 @@ async function* asDeltaIterable(response, extractTextDeltaFromChunk) {
|
|
3976
3994
|
}
|
3977
3995
|
function AWSBedrockAnthropicMessagesStream(response, callbacks) {
|
3978
3996
|
return AWSBedrockStream(response, callbacks, (chunk) => {
|
3979
|
-
var
|
3980
|
-
return (
|
3997
|
+
var _a12;
|
3998
|
+
return (_a12 = chunk.delta) == null ? void 0 : _a12.text;
|
3981
3999
|
});
|
3982
4000
|
}
|
3983
4001
|
function AWSBedrockAnthropicStream(response, callbacks) {
|
@@ -4024,8 +4042,8 @@ async function readAndProcessLines(reader, controller) {
|
|
4024
4042
|
controller.close();
|
4025
4043
|
}
|
4026
4044
|
function createParser2(res) {
|
4027
|
-
var
|
4028
|
-
const reader = (
|
4045
|
+
var _a12;
|
4046
|
+
const reader = (_a12 = res.body) == null ? void 0 : _a12.getReader();
|
4029
4047
|
return new ReadableStream({
|
4030
4048
|
async start(controller) {
|
4031
4049
|
if (!reader) {
|
@@ -4055,9 +4073,9 @@ function CohereStream(reader, callbacks) {
|
|
4055
4073
|
|
4056
4074
|
// streams/google-generative-ai-stream.ts
|
4057
4075
|
async function* streamable3(response) {
|
4058
|
-
var
|
4076
|
+
var _a12, _b, _c;
|
4059
4077
|
for await (const chunk of response.stream) {
|
4060
|
-
const parts = (_c = (_b = (
|
4078
|
+
const parts = (_c = (_b = (_a12 = chunk.candidates) == null ? void 0 : _a12[0]) == null ? void 0 : _b.content) == null ? void 0 : _c.parts;
|
4061
4079
|
if (parts === void 0) {
|
4062
4080
|
continue;
|
4063
4081
|
}
|
@@ -4076,13 +4094,13 @@ function createParser3(res) {
|
|
4076
4094
|
const trimStartOfStream = trimStartOfStreamHelper();
|
4077
4095
|
return new ReadableStream({
|
4078
4096
|
async pull(controller) {
|
4079
|
-
var
|
4097
|
+
var _a12, _b;
|
4080
4098
|
const { value, done } = await res.next();
|
4081
4099
|
if (done) {
|
4082
4100
|
controller.close();
|
4083
4101
|
return;
|
4084
4102
|
}
|
4085
|
-
const text = trimStartOfStream((_b = (
|
4103
|
+
const text = trimStartOfStream((_b = (_a12 = value.token) == null ? void 0 : _a12.text) != null ? _b : "");
|
4086
4104
|
if (!text)
|
4087
4105
|
return;
|
4088
4106
|
if (value.generated_text != null && value.generated_text.length > 0) {
|
@@ -4107,11 +4125,11 @@ function InkeepStream(res, callbacks) {
|
|
4107
4125
|
let chat_session_id = "";
|
4108
4126
|
let records_cited;
|
4109
4127
|
const inkeepEventParser = (data, options) => {
|
4110
|
-
var
|
4128
|
+
var _a12, _b;
|
4111
4129
|
const { event } = options;
|
4112
4130
|
if (event === "records_cited") {
|
4113
4131
|
records_cited = JSON.parse(data);
|
4114
|
-
(
|
4132
|
+
(_a12 = callbacks == null ? void 0 : callbacks.onRecordsCited) == null ? void 0 : _a12.call(callbacks, records_cited);
|
4115
4133
|
}
|
4116
4134
|
if (event === "message_chunk") {
|
4117
4135
|
const inkeepMessageChunk = JSON.parse(data);
|
@@ -4124,12 +4142,12 @@ function InkeepStream(res, callbacks) {
|
|
4124
4142
|
passThroughCallbacks = {
|
4125
4143
|
...passThroughCallbacks,
|
4126
4144
|
onFinal: (completion) => {
|
4127
|
-
var
|
4145
|
+
var _a12;
|
4128
4146
|
const inkeepOnFinalMetadata = {
|
4129
4147
|
chat_session_id,
|
4130
4148
|
records_cited
|
4131
4149
|
};
|
4132
|
-
(
|
4150
|
+
(_a12 = callbacks == null ? void 0 : callbacks.onFinal) == null ? void 0 : _a12.call(callbacks, completion, inkeepOnFinalMetadata);
|
4133
4151
|
}
|
4134
4152
|
};
|
4135
4153
|
return AIStream(res, inkeepEventParser, passThroughCallbacks).pipeThrough(
|
@@ -4151,7 +4169,7 @@ function toDataStream(stream, callbacks) {
|
|
4151
4169
|
return stream.pipeThrough(
|
4152
4170
|
new TransformStream({
|
4153
4171
|
transform: async (value, controller) => {
|
4154
|
-
var
|
4172
|
+
var _a12;
|
4155
4173
|
if (typeof value === "string") {
|
4156
4174
|
controller.enqueue(value);
|
4157
4175
|
return;
|
@@ -4159,7 +4177,7 @@ function toDataStream(stream, callbacks) {
|
|
4159
4177
|
if ("event" in value) {
|
4160
4178
|
if (value.event === "on_chat_model_stream") {
|
4161
4179
|
forwardAIMessageChunk(
|
4162
|
-
(
|
4180
|
+
(_a12 = value.data) == null ? void 0 : _a12.chunk,
|
4163
4181
|
controller
|
4164
4182
|
);
|
4165
4183
|
}
|
@@ -4171,13 +4189,13 @@ function toDataStream(stream, callbacks) {
|
|
4171
4189
|
).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(createStreamDataTransformer());
|
4172
4190
|
}
|
4173
4191
|
function toDataStreamResponse(stream, options) {
|
4174
|
-
var
|
4192
|
+
var _a12;
|
4175
4193
|
const dataStream = toDataStream(stream, options == null ? void 0 : options.callbacks);
|
4176
4194
|
const data = options == null ? void 0 : options.data;
|
4177
4195
|
const init = options == null ? void 0 : options.init;
|
4178
4196
|
const responseStream = data ? mergeStreams(data.stream, dataStream) : dataStream;
|
4179
4197
|
return new Response(responseStream, {
|
4180
|
-
status: (
|
4198
|
+
status: (_a12 = init == null ? void 0 : init.status) != null ? _a12 : 200,
|
4181
4199
|
statusText: init == null ? void 0 : init.statusText,
|
4182
4200
|
headers: prepareResponseHeaders(init, {
|
4183
4201
|
contentType: "text/plain; charset=utf-8",
|
@@ -4259,9 +4277,9 @@ function LangChainStream(callbacks) {
|
|
4259
4277
|
|
4260
4278
|
// streams/mistral-stream.ts
|
4261
4279
|
async function* streamable4(stream) {
|
4262
|
-
var
|
4280
|
+
var _a12, _b;
|
4263
4281
|
for await (const chunk of stream) {
|
4264
|
-
const content = (_b = (
|
4282
|
+
const content = (_b = (_a12 = chunk.choices[0]) == null ? void 0 : _a12.delta) == null ? void 0 : _b.content;
|
4265
4283
|
if (content === void 0 || content === "") {
|
4266
4284
|
continue;
|
4267
4285
|
}
|
@@ -4274,7 +4292,7 @@ function MistralStream(response, callbacks) {
|
|
4274
4292
|
}
|
4275
4293
|
|
4276
4294
|
// streams/openai-stream.ts
|
4277
|
-
var
|
4295
|
+
var import_ui_utils9 = require("@ai-sdk/ui-utils");
|
4278
4296
|
function parseOpenAIStream() {
|
4279
4297
|
const extract = chunkToText();
|
4280
4298
|
return (data) => extract(JSON.parse(data));
|
@@ -4291,10 +4309,10 @@ async function* streamable5(stream) {
|
|
4291
4309
|
model: chunk.model,
|
4292
4310
|
// not exposed by Azure API
|
4293
4311
|
choices: chunk.choices.map((choice) => {
|
4294
|
-
var
|
4312
|
+
var _a12, _b, _c, _d, _e, _f, _g;
|
4295
4313
|
return {
|
4296
4314
|
delta: {
|
4297
|
-
content: (
|
4315
|
+
content: (_a12 = choice.delta) == null ? void 0 : _a12.content,
|
4298
4316
|
function_call: (_b = choice.delta) == null ? void 0 : _b.functionCall,
|
4299
4317
|
role: (_c = choice.delta) == null ? void 0 : _c.role,
|
4300
4318
|
tool_calls: ((_e = (_d = choice.delta) == null ? void 0 : _d.toolCalls) == null ? void 0 : _e.length) ? (_g = (_f = choice.delta) == null ? void 0 : _f.toolCalls) == null ? void 0 : _g.map((toolCall, index) => ({
|
@@ -4319,9 +4337,9 @@ function chunkToText() {
|
|
4319
4337
|
const trimStartOfStream = trimStartOfStreamHelper();
|
4320
4338
|
let isFunctionStreamingIn;
|
4321
4339
|
return (json) => {
|
4322
|
-
var
|
4340
|
+
var _a12, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
|
4323
4341
|
if (isChatCompletionChunk(json)) {
|
4324
|
-
const delta = (
|
4342
|
+
const delta = (_a12 = json.choices[0]) == null ? void 0 : _a12.delta;
|
4325
4343
|
if ((_b = delta.function_call) == null ? void 0 : _b.name) {
|
4326
4344
|
isFunctionStreamingIn = true;
|
4327
4345
|
return {
|
@@ -4425,7 +4443,7 @@ function createFunctionCallTransformer(callbacks) {
|
|
4425
4443
|
let aggregatedFinalCompletionResponse = "";
|
4426
4444
|
let isFunctionStreamingIn = false;
|
4427
4445
|
let functionCallMessages = callbacks[__internal__OpenAIFnMessagesSymbol] || [];
|
4428
|
-
const decode = (0,
|
4446
|
+
const decode = (0, import_ui_utils9.createChunkDecoder)();
|
4429
4447
|
return new TransformStream({
|
4430
4448
|
async transform(chunk, controller) {
|
4431
4449
|
const message = decode(chunk);
|
@@ -4439,7 +4457,7 @@ function createFunctionCallTransformer(callbacks) {
|
|
4439
4457
|
}
|
4440
4458
|
if (!isFunctionStreamingIn) {
|
4441
4459
|
controller.enqueue(
|
4442
|
-
textEncoder.encode((0,
|
4460
|
+
textEncoder.encode((0, import_ui_utils9.formatStreamPart)("text", message))
|
4443
4461
|
);
|
4444
4462
|
return;
|
4445
4463
|
} else {
|
@@ -4550,7 +4568,7 @@ function createFunctionCallTransformer(callbacks) {
|
|
4550
4568
|
if (!functionResponse) {
|
4551
4569
|
controller.enqueue(
|
4552
4570
|
textEncoder.encode(
|
4553
|
-
(0,
|
4571
|
+
(0, import_ui_utils9.formatStreamPart)(
|
4554
4572
|
payload.function_call ? "function_call" : "tool_calls",
|
4555
4573
|
// parse to prevent double-encoding:
|
4556
4574
|
JSON.parse(aggregatedResponse)
|
@@ -4560,7 +4578,7 @@ function createFunctionCallTransformer(callbacks) {
|
|
4560
4578
|
return;
|
4561
4579
|
} else if (typeof functionResponse === "string") {
|
4562
4580
|
controller.enqueue(
|
4563
|
-
textEncoder.encode((0,
|
4581
|
+
textEncoder.encode((0, import_ui_utils9.formatStreamPart)("text", functionResponse))
|
4564
4582
|
);
|
4565
4583
|
aggregatedFinalCompletionResponse = functionResponse;
|
4566
4584
|
return;
|
@@ -4594,8 +4612,8 @@ function createFunctionCallTransformer(callbacks) {
|
|
4594
4612
|
|
4595
4613
|
// streams/replicate-stream.ts
|
4596
4614
|
async function ReplicateStream(res, cb, options) {
|
4597
|
-
var
|
4598
|
-
const url = (
|
4615
|
+
var _a12;
|
4616
|
+
const url = (_a12 = res.urls) == null ? void 0 : _a12.stream;
|
4599
4617
|
if (!url) {
|
4600
4618
|
if (res.error)
|
4601
4619
|
throw new Error(res.error);
|
@@ -4616,8 +4634,8 @@ async function ReplicateStream(res, cb, options) {
|
|
4616
4634
|
|
4617
4635
|
// streams/stream-to-response.ts
|
4618
4636
|
function streamToResponse(res, response, init, data) {
|
4619
|
-
var
|
4620
|
-
response.writeHead((
|
4637
|
+
var _a12;
|
4638
|
+
response.writeHead((_a12 = init == null ? void 0 : init.status) != null ? _a12 : 200, {
|
4621
4639
|
"Content-Type": "text/plain; charset=utf-8",
|
4622
4640
|
...init == null ? void 0 : init.headers
|
4623
4641
|
});
|
@@ -4657,8 +4675,8 @@ var StreamingTextResponse = class extends Response {
|
|
4657
4675
|
};
|
4658
4676
|
|
4659
4677
|
// streams/index.ts
|
4660
|
-
var generateId2 =
|
4661
|
-
var nanoid =
|
4678
|
+
var generateId2 = import_provider_utils7.generateId;
|
4679
|
+
var nanoid = import_provider_utils7.generateId;
|
4662
4680
|
// Annotate the CommonJS export names for ESM import in node:
|
4663
4681
|
0 && (module.exports = {
|
4664
4682
|
AISDKError,
|