ai 4.0.22 → 4.0.24
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 +12 -0
- package/dist/index.d.mts +49 -21
- package/dist/index.d.ts +49 -21
- package/dist/index.js +307 -180
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +293 -164
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
@@ -4,8 +4,8 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
6
|
var __export = (target, all) => {
|
7
|
-
for (var
|
8
|
-
__defProp(target,
|
7
|
+
for (var name14 in all)
|
8
|
+
__defProp(target, name14, { get: all[name14], enumerable: true });
|
9
9
|
};
|
10
10
|
var __copyProps = (to, from, except, desc) => {
|
11
11
|
if (from && typeof from === "object" || typeof from === "function") {
|
@@ -20,25 +20,26 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
20
20
|
// streams/index.ts
|
21
21
|
var streams_exports = {};
|
22
22
|
__export(streams_exports, {
|
23
|
-
AISDKError: () =>
|
24
|
-
APICallError: () =>
|
23
|
+
AISDKError: () => import_provider16.AISDKError,
|
24
|
+
APICallError: () => import_provider16.APICallError,
|
25
25
|
AssistantResponse: () => AssistantResponse,
|
26
26
|
DownloadError: () => DownloadError,
|
27
|
-
EmptyResponseBodyError: () =>
|
27
|
+
EmptyResponseBodyError: () => import_provider16.EmptyResponseBodyError,
|
28
28
|
InvalidArgumentError: () => InvalidArgumentError,
|
29
29
|
InvalidDataContentError: () => InvalidDataContentError,
|
30
30
|
InvalidMessageRoleError: () => InvalidMessageRoleError,
|
31
|
-
InvalidPromptError: () =>
|
32
|
-
InvalidResponseDataError: () =>
|
31
|
+
InvalidPromptError: () => import_provider16.InvalidPromptError,
|
32
|
+
InvalidResponseDataError: () => import_provider16.InvalidResponseDataError,
|
33
33
|
InvalidToolArgumentsError: () => InvalidToolArgumentsError,
|
34
|
-
JSONParseError: () =>
|
34
|
+
JSONParseError: () => import_provider16.JSONParseError,
|
35
35
|
LangChainAdapter: () => langchain_adapter_exports,
|
36
36
|
LlamaIndexAdapter: () => llamaindex_adapter_exports,
|
37
|
-
LoadAPIKeyError: () =>
|
37
|
+
LoadAPIKeyError: () => import_provider16.LoadAPIKeyError,
|
38
38
|
MessageConversionError: () => MessageConversionError,
|
39
|
-
NoContentGeneratedError: () =>
|
39
|
+
NoContentGeneratedError: () => import_provider16.NoContentGeneratedError,
|
40
40
|
NoObjectGeneratedError: () => NoObjectGeneratedError,
|
41
|
-
|
41
|
+
NoOutputSpecifiedError: () => NoOutputSpecifiedError,
|
42
|
+
NoSuchModelError: () => import_provider16.NoSuchModelError,
|
42
43
|
NoSuchProviderError: () => NoSuchProviderError,
|
43
44
|
NoSuchToolError: () => NoSuchToolError,
|
44
45
|
Output: () => output_exports,
|
@@ -46,8 +47,8 @@ __export(streams_exports, {
|
|
46
47
|
StreamData: () => StreamData,
|
47
48
|
ToolCallRepairError: () => ToolCallRepairError,
|
48
49
|
ToolExecutionError: () => ToolExecutionError,
|
49
|
-
TypeValidationError: () =>
|
50
|
-
UnsupportedFunctionalityError: () =>
|
50
|
+
TypeValidationError: () => import_provider16.TypeValidationError,
|
51
|
+
UnsupportedFunctionalityError: () => import_provider16.UnsupportedFunctionalityError,
|
51
52
|
convertToCoreMessages: () => convertToCoreMessages,
|
52
53
|
cosineSimilarity: () => cosineSimilarity,
|
53
54
|
createDataStream: () => createDataStream,
|
@@ -417,7 +418,7 @@ function getBaseTelemetryAttributes({
|
|
417
418
|
telemetry,
|
418
419
|
headers
|
419
420
|
}) {
|
420
|
-
var
|
421
|
+
var _a14;
|
421
422
|
return {
|
422
423
|
"ai.model.provider": model.provider,
|
423
424
|
"ai.model.id": model.modelId,
|
@@ -427,7 +428,7 @@ function getBaseTelemetryAttributes({
|
|
427
428
|
return attributes;
|
428
429
|
}, {}),
|
429
430
|
// add metadata as attributes:
|
430
|
-
...Object.entries((
|
431
|
+
...Object.entries((_a14 = telemetry == null ? void 0 : telemetry.metadata) != null ? _a14 : {}).reduce(
|
431
432
|
(attributes, [key, value]) => {
|
432
433
|
attributes[`ai.telemetry.metadata.${key}`] = value;
|
433
434
|
return attributes;
|
@@ -452,7 +453,7 @@ var noopTracer = {
|
|
452
453
|
startSpan() {
|
453
454
|
return noopSpan;
|
454
455
|
},
|
455
|
-
startActiveSpan(
|
456
|
+
startActiveSpan(name14, arg1, arg2, arg3) {
|
456
457
|
if (typeof arg1 === "function") {
|
457
458
|
return arg1(noopSpan);
|
458
459
|
}
|
@@ -522,13 +523,13 @@ function getTracer({
|
|
522
523
|
// core/telemetry/record-span.ts
|
523
524
|
var import_api2 = require("@opentelemetry/api");
|
524
525
|
function recordSpan({
|
525
|
-
name:
|
526
|
+
name: name14,
|
526
527
|
tracer,
|
527
528
|
attributes,
|
528
529
|
fn,
|
529
530
|
endWhenDone = true
|
530
531
|
}) {
|
531
|
-
return tracer.startActiveSpan(
|
532
|
+
return tracer.startActiveSpan(name14, { attributes }, async (span) => {
|
532
533
|
try {
|
533
534
|
const result = await fn(span);
|
534
535
|
if (endWhenDone) {
|
@@ -636,14 +637,14 @@ async function embed({
|
|
636
637
|
}),
|
637
638
|
tracer,
|
638
639
|
fn: async (doEmbedSpan) => {
|
639
|
-
var
|
640
|
+
var _a14;
|
640
641
|
const modelResponse = await model.doEmbed({
|
641
642
|
values: [value],
|
642
643
|
abortSignal,
|
643
644
|
headers
|
644
645
|
});
|
645
646
|
const embedding2 = modelResponse.embeddings[0];
|
646
|
-
const usage2 = (
|
647
|
+
const usage2 = (_a14 = modelResponse.usage) != null ? _a14 : { tokens: NaN };
|
647
648
|
doEmbedSpan.setAttributes(
|
648
649
|
selectTelemetryAttributes({
|
649
650
|
telemetry,
|
@@ -753,14 +754,14 @@ async function embedMany({
|
|
753
754
|
}),
|
754
755
|
tracer,
|
755
756
|
fn: async (doEmbedSpan) => {
|
756
|
-
var
|
757
|
+
var _a14;
|
757
758
|
const modelResponse = await model.doEmbed({
|
758
759
|
values,
|
759
760
|
abortSignal,
|
760
761
|
headers
|
761
762
|
});
|
762
763
|
const embeddings3 = modelResponse.embeddings;
|
763
|
-
const usage2 = (
|
764
|
+
const usage2 = (_a14 = modelResponse.usage) != null ? _a14 : { tokens: NaN };
|
764
765
|
doEmbedSpan.setAttributes(
|
765
766
|
selectTelemetryAttributes({
|
766
767
|
telemetry,
|
@@ -812,14 +813,14 @@ async function embedMany({
|
|
812
813
|
}),
|
813
814
|
tracer,
|
814
815
|
fn: async (doEmbedSpan) => {
|
815
|
-
var
|
816
|
+
var _a14;
|
816
817
|
const modelResponse = await model.doEmbed({
|
817
818
|
values: chunk,
|
818
819
|
abortSignal,
|
819
820
|
headers
|
820
821
|
});
|
821
822
|
const embeddings2 = modelResponse.embeddings;
|
822
|
-
const usage2 = (
|
823
|
+
const usage2 = (_a14 = modelResponse.usage) != null ? _a14 : { tokens: NaN };
|
823
824
|
doEmbedSpan.setAttributes(
|
824
825
|
selectTelemetryAttributes({
|
825
826
|
telemetry,
|
@@ -964,7 +965,7 @@ async function download({
|
|
964
965
|
url,
|
965
966
|
fetchImplementation = fetch
|
966
967
|
}) {
|
967
|
-
var
|
968
|
+
var _a14;
|
968
969
|
const urlText = url.toString();
|
969
970
|
try {
|
970
971
|
const response = await fetchImplementation(urlText);
|
@@ -977,7 +978,7 @@ async function download({
|
|
977
978
|
}
|
978
979
|
return {
|
979
980
|
data: new Uint8Array(await response.arrayBuffer()),
|
980
|
-
mimeType: (
|
981
|
+
mimeType: (_a14 = response.headers.get("content-type")) != null ? _a14 : void 0
|
981
982
|
};
|
982
983
|
} catch (error) {
|
983
984
|
if (DownloadError.isInstance(error)) {
|
@@ -1037,8 +1038,8 @@ var dataContentSchema = import_zod.z.union([
|
|
1037
1038
|
import_zod.z.custom(
|
1038
1039
|
// Buffer might not be available in some environments such as CloudFlare:
|
1039
1040
|
(value) => {
|
1040
|
-
var
|
1041
|
-
return (_b = (
|
1041
|
+
var _a14, _b;
|
1042
|
+
return (_b = (_a14 = globalThis.Buffer) == null ? void 0 : _a14.isBuffer(value)) != null ? _b : false;
|
1042
1043
|
},
|
1043
1044
|
{ message: "Must be a Buffer" }
|
1044
1045
|
)
|
@@ -1229,7 +1230,7 @@ async function downloadAssets(messages, downloadImplementation, modelSupportsIma
|
|
1229
1230
|
);
|
1230
1231
|
}
|
1231
1232
|
function convertPartToLanguageModelPart(part, downloadedAssets) {
|
1232
|
-
var
|
1233
|
+
var _a14;
|
1233
1234
|
if (part.type === "text") {
|
1234
1235
|
return {
|
1235
1236
|
type: "text",
|
@@ -1282,7 +1283,7 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
|
|
1282
1283
|
switch (type) {
|
1283
1284
|
case "image": {
|
1284
1285
|
if (normalizedData instanceof Uint8Array) {
|
1285
|
-
mimeType = (
|
1286
|
+
mimeType = (_a14 = detectImageMimeType(normalizedData)) != null ? _a14 : mimeType;
|
1286
1287
|
}
|
1287
1288
|
return {
|
1288
1289
|
type: "image",
|
@@ -1549,7 +1550,7 @@ function detectSingleMessageCharacteristics(message) {
|
|
1549
1550
|
|
1550
1551
|
// core/prompt/attachments-to-parts.ts
|
1551
1552
|
function attachmentsToParts(attachments) {
|
1552
|
-
var
|
1553
|
+
var _a14, _b, _c;
|
1553
1554
|
const parts = [];
|
1554
1555
|
for (const attachment of attachments) {
|
1555
1556
|
let url;
|
@@ -1561,7 +1562,7 @@ function attachmentsToParts(attachments) {
|
|
1561
1562
|
switch (url.protocol) {
|
1562
1563
|
case "http:":
|
1563
1564
|
case "https:": {
|
1564
|
-
if ((
|
1565
|
+
if ((_a14 = attachment.contentType) == null ? void 0 : _a14.startsWith("image/")) {
|
1565
1566
|
parts.push({ type: "image", image: url });
|
1566
1567
|
} else {
|
1567
1568
|
if (!attachment.contentType) {
|
@@ -1647,8 +1648,8 @@ _a7 = symbol7;
|
|
1647
1648
|
|
1648
1649
|
// core/prompt/convert-to-core-messages.ts
|
1649
1650
|
function convertToCoreMessages(messages, options) {
|
1650
|
-
var
|
1651
|
-
const tools = (
|
1651
|
+
var _a14;
|
1652
|
+
const tools = (_a14 = options == null ? void 0 : options.tools) != null ? _a14 : {};
|
1652
1653
|
const coreMessages = [];
|
1653
1654
|
for (const message of messages) {
|
1654
1655
|
const { role, content, toolInvocations, experimental_attachments } = message;
|
@@ -1925,7 +1926,7 @@ var arrayOutputStrategy = (schema) => {
|
|
1925
1926
|
additionalProperties: false
|
1926
1927
|
},
|
1927
1928
|
validatePartialResult({ value, latestObject, isFirstDelta, isFinalDelta }) {
|
1928
|
-
var
|
1929
|
+
var _a14;
|
1929
1930
|
if (!(0, import_provider10.isJSONObject)(value) || !(0, import_provider10.isJSONArray)(value.elements)) {
|
1930
1931
|
return {
|
1931
1932
|
success: false,
|
@@ -1948,7 +1949,7 @@ var arrayOutputStrategy = (schema) => {
|
|
1948
1949
|
}
|
1949
1950
|
resultArray.push(result.value);
|
1950
1951
|
}
|
1951
|
-
const publishedElementCount = (
|
1952
|
+
const publishedElementCount = (_a14 = latestObject == null ? void 0 : latestObject.length) != null ? _a14 : 0;
|
1952
1953
|
let textDelta = "";
|
1953
1954
|
if (isFirstDelta) {
|
1954
1955
|
textDelta += "[";
|
@@ -2286,7 +2287,7 @@ async function generateObject({
|
|
2286
2287
|
}),
|
2287
2288
|
tracer,
|
2288
2289
|
fn: async (span) => {
|
2289
|
-
var
|
2290
|
+
var _a14, _b;
|
2290
2291
|
if (mode === "auto" || mode == null) {
|
2291
2292
|
mode = model.defaultObjectGenerationMode;
|
2292
2293
|
}
|
@@ -2348,7 +2349,7 @@ async function generateObject({
|
|
2348
2349
|
}),
|
2349
2350
|
tracer,
|
2350
2351
|
fn: async (span2) => {
|
2351
|
-
var
|
2352
|
+
var _a15, _b2, _c, _d, _e, _f;
|
2352
2353
|
const result2 = await model.doGenerate({
|
2353
2354
|
mode: {
|
2354
2355
|
type: "object-json",
|
@@ -2364,7 +2365,7 @@ async function generateObject({
|
|
2364
2365
|
headers
|
2365
2366
|
});
|
2366
2367
|
const responseData = {
|
2367
|
-
id: (_b2 = (
|
2368
|
+
id: (_b2 = (_a15 = result2.response) == null ? void 0 : _a15.id) != null ? _b2 : generateId3(),
|
2368
2369
|
timestamp: (_d = (_c = result2.response) == null ? void 0 : _c.timestamp) != null ? _d : currentDate(),
|
2369
2370
|
modelId: (_f = (_e = result2.response) == null ? void 0 : _e.modelId) != null ? _f : model.modelId
|
2370
2371
|
};
|
@@ -2406,7 +2407,7 @@ async function generateObject({
|
|
2406
2407
|
rawResponse = generateResult.rawResponse;
|
2407
2408
|
logprobs = generateResult.logprobs;
|
2408
2409
|
resultProviderMetadata = generateResult.providerMetadata;
|
2409
|
-
request = (
|
2410
|
+
request = (_a14 = generateResult.request) != null ? _a14 : {};
|
2410
2411
|
response = generateResult.responseData;
|
2411
2412
|
break;
|
2412
2413
|
}
|
@@ -2452,7 +2453,7 @@ async function generateObject({
|
|
2452
2453
|
}),
|
2453
2454
|
tracer,
|
2454
2455
|
fn: async (span2) => {
|
2455
|
-
var
|
2456
|
+
var _a15, _b2, _c, _d, _e, _f, _g, _h;
|
2456
2457
|
const result2 = await model.doGenerate({
|
2457
2458
|
mode: {
|
2458
2459
|
type: "object-tool",
|
@@ -2470,7 +2471,7 @@ async function generateObject({
|
|
2470
2471
|
abortSignal,
|
2471
2472
|
headers
|
2472
2473
|
});
|
2473
|
-
const objectText = (_b2 = (
|
2474
|
+
const objectText = (_b2 = (_a15 = result2.toolCalls) == null ? void 0 : _a15[0]) == null ? void 0 : _b2.args;
|
2474
2475
|
const responseData = {
|
2475
2476
|
id: (_d = (_c = result2.response) == null ? void 0 : _c.id) != null ? _d : generateId3(),
|
2476
2477
|
timestamp: (_f = (_e = result2.response) == null ? void 0 : _e.timestamp) != null ? _f : currentDate(),
|
@@ -2596,9 +2597,9 @@ var DefaultGenerateObjectResult = class {
|
|
2596
2597
|
this.logprobs = options.logprobs;
|
2597
2598
|
}
|
2598
2599
|
toJsonResponse(init) {
|
2599
|
-
var
|
2600
|
+
var _a14;
|
2600
2601
|
return new Response(JSON.stringify(this.object), {
|
2601
|
-
status: (
|
2602
|
+
status: (_a14 = init == null ? void 0 : init.status) != null ? _a14 : 200,
|
2602
2603
|
headers: prepareResponseHeaders(init == null ? void 0 : init.headers, {
|
2603
2604
|
contentType: "application/json; charset=utf-8"
|
2604
2605
|
})
|
@@ -2633,17 +2634,17 @@ var DelayedPromise = class {
|
|
2633
2634
|
return this.promise;
|
2634
2635
|
}
|
2635
2636
|
resolve(value) {
|
2636
|
-
var
|
2637
|
+
var _a14;
|
2637
2638
|
this.status = { type: "resolved", value };
|
2638
2639
|
if (this.promise) {
|
2639
|
-
(
|
2640
|
+
(_a14 = this._resolve) == null ? void 0 : _a14.call(this, value);
|
2640
2641
|
}
|
2641
2642
|
}
|
2642
2643
|
reject(error) {
|
2643
|
-
var
|
2644
|
+
var _a14;
|
2644
2645
|
this.status = { type: "rejected", error };
|
2645
2646
|
if (this.promise) {
|
2646
|
-
(
|
2647
|
+
(_a14 = this._reject) == null ? void 0 : _a14.call(this, error);
|
2647
2648
|
}
|
2648
2649
|
}
|
2649
2650
|
};
|
@@ -2732,8 +2733,8 @@ function createStitchableStream() {
|
|
2732
2733
|
|
2733
2734
|
// core/util/now.ts
|
2734
2735
|
function now() {
|
2735
|
-
var
|
2736
|
-
return (_b = (
|
2736
|
+
var _a14, _b;
|
2737
|
+
return (_b = (_a14 = globalThis == null ? void 0 : globalThis.performance) == null ? void 0 : _a14.now()) != null ? _b : Date.now();
|
2737
2738
|
}
|
2738
2739
|
|
2739
2740
|
// core/generate-object/stream-object.ts
|
@@ -3022,7 +3023,7 @@ var DefaultStreamObjectResult = class {
|
|
3022
3023
|
const transformedStream = stream.pipeThrough(new TransformStream(transformer)).pipeThrough(
|
3023
3024
|
new TransformStream({
|
3024
3025
|
async transform(chunk, controller) {
|
3025
|
-
var
|
3026
|
+
var _a14, _b, _c;
|
3026
3027
|
if (isFirstChunk) {
|
3027
3028
|
const msToFirstChunk = now2() - startTimestampMs;
|
3028
3029
|
isFirstChunk = false;
|
@@ -3068,7 +3069,7 @@ var DefaultStreamObjectResult = class {
|
|
3068
3069
|
switch (chunk.type) {
|
3069
3070
|
case "response-metadata": {
|
3070
3071
|
response = {
|
3071
|
-
id: (
|
3072
|
+
id: (_a14 = chunk.id) != null ? _a14 : response.id,
|
3072
3073
|
timestamp: (_b = chunk.timestamp) != null ? _b : response.timestamp,
|
3073
3074
|
modelId: (_c = chunk.modelId) != null ? _c : response.modelId
|
3074
3075
|
};
|
@@ -3282,9 +3283,9 @@ var DefaultStreamObjectResult = class {
|
|
3282
3283
|
});
|
3283
3284
|
}
|
3284
3285
|
toTextStreamResponse(init) {
|
3285
|
-
var
|
3286
|
+
var _a14;
|
3286
3287
|
return new Response(this.textStream.pipeThrough(new TextEncoderStream()), {
|
3287
|
-
status: (
|
3288
|
+
status: (_a14 = init == null ? void 0 : init.status) != null ? _a14 : 200,
|
3288
3289
|
headers: prepareResponseHeaders(init == null ? void 0 : init.headers, {
|
3289
3290
|
contentType: "text/plain; charset=utf-8"
|
3290
3291
|
})
|
@@ -3296,7 +3297,7 @@ var DefaultStreamObjectResult = class {
|
|
3296
3297
|
var import_provider_utils9 = require("@ai-sdk/provider-utils");
|
3297
3298
|
|
3298
3299
|
// errors/index.ts
|
3299
|
-
var
|
3300
|
+
var import_provider16 = require("@ai-sdk/provider");
|
3300
3301
|
|
3301
3302
|
// errors/invalid-tool-arguments-error.ts
|
3302
3303
|
var import_provider11 = require("@ai-sdk/provider");
|
@@ -3324,22 +3325,17 @@ var InvalidToolArgumentsError = class extends import_provider11.AISDKError {
|
|
3324
3325
|
};
|
3325
3326
|
_a8 = symbol8;
|
3326
3327
|
|
3327
|
-
// errors/no-
|
3328
|
+
// errors/no-output-specified-error.ts
|
3328
3329
|
var import_provider12 = require("@ai-sdk/provider");
|
3329
|
-
var name9 = "
|
3330
|
+
var name9 = "AI_NoOutputSpecifiedError";
|
3330
3331
|
var marker9 = `vercel.ai.error.${name9}`;
|
3331
3332
|
var symbol9 = Symbol.for(marker9);
|
3332
3333
|
var _a9;
|
3333
|
-
var
|
3334
|
-
|
3335
|
-
|
3336
|
-
availableTools = void 0,
|
3337
|
-
message = `Model tried to call unavailable tool '${toolName}'. ${availableTools === void 0 ? "No tools are available." : `Available tools: ${availableTools.join(", ")}.`}`
|
3338
|
-
}) {
|
3334
|
+
var NoOutputSpecifiedError = class extends import_provider12.AISDKError {
|
3335
|
+
// used in isInstance
|
3336
|
+
constructor({ message = "No output specified." } = {}) {
|
3339
3337
|
super({ name: name9, message });
|
3340
3338
|
this[_a9] = true;
|
3341
|
-
this.toolName = toolName;
|
3342
|
-
this.availableTools = availableTools;
|
3343
3339
|
}
|
3344
3340
|
static isInstance(error) {
|
3345
3341
|
return import_provider12.AISDKError.hasMarker(error, marker9);
|
@@ -3347,21 +3343,22 @@ var NoSuchToolError = class extends import_provider12.AISDKError {
|
|
3347
3343
|
};
|
3348
3344
|
_a9 = symbol9;
|
3349
3345
|
|
3350
|
-
// errors/
|
3346
|
+
// errors/no-such-tool-error.ts
|
3351
3347
|
var import_provider13 = require("@ai-sdk/provider");
|
3352
|
-
var name10 = "
|
3348
|
+
var name10 = "AI_NoSuchToolError";
|
3353
3349
|
var marker10 = `vercel.ai.error.${name10}`;
|
3354
3350
|
var symbol10 = Symbol.for(marker10);
|
3355
3351
|
var _a10;
|
3356
|
-
var
|
3352
|
+
var NoSuchToolError = class extends import_provider13.AISDKError {
|
3357
3353
|
constructor({
|
3358
|
-
|
3359
|
-
|
3360
|
-
message = `
|
3354
|
+
toolName,
|
3355
|
+
availableTools = void 0,
|
3356
|
+
message = `Model tried to call unavailable tool '${toolName}'. ${availableTools === void 0 ? "No tools are available." : `Available tools: ${availableTools.join(", ")}.`}`
|
3361
3357
|
}) {
|
3362
|
-
super({ name: name10, message
|
3358
|
+
super({ name: name10, message });
|
3363
3359
|
this[_a10] = true;
|
3364
|
-
this.
|
3360
|
+
this.toolName = toolName;
|
3361
|
+
this.availableTools = availableTools;
|
3365
3362
|
}
|
3366
3363
|
static isInstance(error) {
|
3367
3364
|
return import_provider13.AISDKError.hasMarker(error, marker10);
|
@@ -3369,23 +3366,21 @@ var ToolCallRepairError = class extends import_provider13.AISDKError {
|
|
3369
3366
|
};
|
3370
3367
|
_a10 = symbol10;
|
3371
3368
|
|
3372
|
-
// errors/tool-
|
3369
|
+
// errors/tool-call-repair-error.ts
|
3373
3370
|
var import_provider14 = require("@ai-sdk/provider");
|
3374
|
-
var name11 = "
|
3371
|
+
var name11 = "AI_ToolCallRepairError";
|
3375
3372
|
var marker11 = `vercel.ai.error.${name11}`;
|
3376
3373
|
var symbol11 = Symbol.for(marker11);
|
3377
3374
|
var _a11;
|
3378
|
-
var
|
3375
|
+
var ToolCallRepairError = class extends import_provider14.AISDKError {
|
3379
3376
|
constructor({
|
3380
|
-
toolArgs,
|
3381
|
-
toolName,
|
3382
3377
|
cause,
|
3383
|
-
|
3378
|
+
originalError,
|
3379
|
+
message = `Error repairing tool call: ${(0, import_provider14.getErrorMessage)(cause)}`
|
3384
3380
|
}) {
|
3385
3381
|
super({ name: name11, message, cause });
|
3386
3382
|
this[_a11] = true;
|
3387
|
-
this.
|
3388
|
-
this.toolName = toolName;
|
3383
|
+
this.originalError = originalError;
|
3389
3384
|
}
|
3390
3385
|
static isInstance(error) {
|
3391
3386
|
return import_provider14.AISDKError.hasMarker(error, marker11);
|
@@ -3393,6 +3388,30 @@ var ToolExecutionError = class extends import_provider14.AISDKError {
|
|
3393
3388
|
};
|
3394
3389
|
_a11 = symbol11;
|
3395
3390
|
|
3391
|
+
// errors/tool-execution-error.ts
|
3392
|
+
var import_provider15 = require("@ai-sdk/provider");
|
3393
|
+
var name12 = "AI_ToolExecutionError";
|
3394
|
+
var marker12 = `vercel.ai.error.${name12}`;
|
3395
|
+
var symbol12 = Symbol.for(marker12);
|
3396
|
+
var _a12;
|
3397
|
+
var ToolExecutionError = class extends import_provider15.AISDKError {
|
3398
|
+
constructor({
|
3399
|
+
toolArgs,
|
3400
|
+
toolName,
|
3401
|
+
cause,
|
3402
|
+
message = `Error executing tool ${toolName}: ${(0, import_provider15.getErrorMessage)(cause)}`
|
3403
|
+
}) {
|
3404
|
+
super({ name: name12, message, cause });
|
3405
|
+
this[_a12] = true;
|
3406
|
+
this.toolArgs = toolArgs;
|
3407
|
+
this.toolName = toolName;
|
3408
|
+
}
|
3409
|
+
static isInstance(error) {
|
3410
|
+
return import_provider15.AISDKError.hasMarker(error, marker12);
|
3411
|
+
}
|
3412
|
+
};
|
3413
|
+
_a12 = symbol12;
|
3414
|
+
|
3396
3415
|
// core/prompt/prepare-tools-and-tool-choice.ts
|
3397
3416
|
var import_ui_utils4 = require("@ai-sdk/ui-utils");
|
3398
3417
|
|
@@ -3414,24 +3433,24 @@ function prepareToolsAndToolChoice({
|
|
3414
3433
|
};
|
3415
3434
|
}
|
3416
3435
|
const filteredTools = activeTools != null ? Object.entries(tools).filter(
|
3417
|
-
([
|
3436
|
+
([name14]) => activeTools.includes(name14)
|
3418
3437
|
) : Object.entries(tools);
|
3419
3438
|
return {
|
3420
|
-
tools: filteredTools.map(([
|
3439
|
+
tools: filteredTools.map(([name14, tool2]) => {
|
3421
3440
|
const toolType = tool2.type;
|
3422
3441
|
switch (toolType) {
|
3423
3442
|
case void 0:
|
3424
3443
|
case "function":
|
3425
3444
|
return {
|
3426
3445
|
type: "function",
|
3427
|
-
name:
|
3446
|
+
name: name14,
|
3428
3447
|
description: tool2.description,
|
3429
3448
|
parameters: (0, import_ui_utils4.asSchema)(tool2.parameters).jsonSchema
|
3430
3449
|
};
|
3431
3450
|
case "provider-defined":
|
3432
3451
|
return {
|
3433
3452
|
type: "provider-defined",
|
3434
|
-
name:
|
3453
|
+
name: name14,
|
3435
3454
|
id: tool2.id,
|
3436
3455
|
args: tool2.args
|
3437
3456
|
};
|
@@ -3591,7 +3610,7 @@ async function generateText({
|
|
3591
3610
|
onStepFinish,
|
3592
3611
|
...settings
|
3593
3612
|
}) {
|
3594
|
-
var
|
3613
|
+
var _a14;
|
3595
3614
|
if (maxSteps < 1) {
|
3596
3615
|
throw new InvalidArgumentError({
|
3597
3616
|
parameter: "maxSteps",
|
@@ -3608,7 +3627,7 @@ async function generateText({
|
|
3608
3627
|
});
|
3609
3628
|
const initialPrompt = standardizePrompt({
|
3610
3629
|
prompt: {
|
3611
|
-
system: (
|
3630
|
+
system: (_a14 = output == null ? void 0 : output.injectIntoSystemPrompt({ system, model })) != null ? _a14 : system,
|
3612
3631
|
prompt,
|
3613
3632
|
messages
|
3614
3633
|
},
|
@@ -3634,7 +3653,7 @@ async function generateText({
|
|
3634
3653
|
}),
|
3635
3654
|
tracer,
|
3636
3655
|
fn: async (span) => {
|
3637
|
-
var
|
3656
|
+
var _a15, _b, _c, _d, _e, _f;
|
3638
3657
|
const mode = {
|
3639
3658
|
type: "regular",
|
3640
3659
|
...prepareToolsAndToolChoice({ tools, toolChoice, activeTools })
|
@@ -3686,8 +3705,8 @@ async function generateText({
|
|
3686
3705
|
"ai.prompt.tools": {
|
3687
3706
|
// convert the language model level tools:
|
3688
3707
|
input: () => {
|
3689
|
-
var
|
3690
|
-
return (
|
3708
|
+
var _a16;
|
3709
|
+
return (_a16 = mode.tools) == null ? void 0 : _a16.map((tool2) => JSON.stringify(tool2));
|
3691
3710
|
}
|
3692
3711
|
},
|
3693
3712
|
"ai.prompt.toolChoice": {
|
@@ -3707,7 +3726,7 @@ async function generateText({
|
|
3707
3726
|
}),
|
3708
3727
|
tracer,
|
3709
3728
|
fn: async (span2) => {
|
3710
|
-
var
|
3729
|
+
var _a16, _b2, _c2, _d2, _e2, _f2;
|
3711
3730
|
const result = await model.doGenerate({
|
3712
3731
|
mode,
|
3713
3732
|
...callSettings,
|
@@ -3719,7 +3738,7 @@ async function generateText({
|
|
3719
3738
|
headers
|
3720
3739
|
});
|
3721
3740
|
const responseData = {
|
3722
|
-
id: (_b2 = (
|
3741
|
+
id: (_b2 = (_a16 = result.response) == null ? void 0 : _a16.id) != null ? _b2 : generateId3(),
|
3723
3742
|
timestamp: (_d2 = (_c2 = result.response) == null ? void 0 : _c2.timestamp) != null ? _d2 : currentDate(),
|
3724
3743
|
modelId: (_f2 = (_e2 = result.response) == null ? void 0 : _e2.modelId) != null ? _f2 : model.modelId
|
3725
3744
|
};
|
@@ -3753,7 +3772,7 @@ async function generateText({
|
|
3753
3772
|
})
|
3754
3773
|
);
|
3755
3774
|
currentToolCalls = await Promise.all(
|
3756
|
-
((
|
3775
|
+
((_a15 = currentModelResponse.toolCalls) != null ? _a15 : []).map(
|
3757
3776
|
(toolCall) => parseToolCall({
|
3758
3777
|
toolCall,
|
3759
3778
|
tools,
|
@@ -3984,6 +4003,9 @@ var text = () => ({
|
|
3984
4003
|
injectIntoSystemPrompt({ system }) {
|
3985
4004
|
return system;
|
3986
4005
|
},
|
4006
|
+
parsePartial({ text: text2 }) {
|
4007
|
+
return { partial: text2 };
|
4008
|
+
},
|
3987
4009
|
parseOutput({ text: text2 }) {
|
3988
4010
|
return text2;
|
3989
4011
|
}
|
@@ -4004,6 +4026,24 @@ var object = ({
|
|
4004
4026
|
schema: schema.jsonSchema
|
4005
4027
|
});
|
4006
4028
|
},
|
4029
|
+
parsePartial({ text: text2 }) {
|
4030
|
+
const result = (0, import_ui_utils6.parsePartialJson)(text2);
|
4031
|
+
switch (result.state) {
|
4032
|
+
case "failed-parse":
|
4033
|
+
case "undefined-input":
|
4034
|
+
return void 0;
|
4035
|
+
case "repaired-parse":
|
4036
|
+
case "successful-parse":
|
4037
|
+
return {
|
4038
|
+
// Note: currently no validation of partial results:
|
4039
|
+
partial: result.value
|
4040
|
+
};
|
4041
|
+
default: {
|
4042
|
+
const _exhaustiveCheck = result.state;
|
4043
|
+
throw new Error(`Unsupported parse state: ${_exhaustiveCheck}`);
|
4044
|
+
}
|
4045
|
+
}
|
4046
|
+
},
|
4007
4047
|
parseOutput({ text: text2 }, context) {
|
4008
4048
|
const parseResult = (0, import_provider_utils10.safeParseJSON)({ text: text2 });
|
4009
4049
|
if (!parseResult.success) {
|
@@ -4327,6 +4367,7 @@ function streamText({
|
|
4327
4367
|
abortSignal,
|
4328
4368
|
headers,
|
4329
4369
|
maxSteps = 1,
|
4370
|
+
experimental_output: output,
|
4330
4371
|
experimental_continueSteps: continueSteps = false,
|
4331
4372
|
experimental_telemetry: telemetry,
|
4332
4373
|
experimental_providerMetadata: providerMetadata,
|
@@ -4361,6 +4402,7 @@ function streamText({
|
|
4361
4402
|
activeTools,
|
4362
4403
|
repairToolCall,
|
4363
4404
|
maxSteps,
|
4405
|
+
output,
|
4364
4406
|
continueSteps,
|
4365
4407
|
providerMetadata,
|
4366
4408
|
onChunk,
|
@@ -4371,6 +4413,57 @@ function streamText({
|
|
4371
4413
|
generateId: generateId3
|
4372
4414
|
});
|
4373
4415
|
}
|
4416
|
+
function createOutputTransformStream(output) {
|
4417
|
+
if (!output) {
|
4418
|
+
return new TransformStream({
|
4419
|
+
transform(chunk, controller) {
|
4420
|
+
controller.enqueue({ part: chunk, partialOutput: void 0 });
|
4421
|
+
}
|
4422
|
+
});
|
4423
|
+
}
|
4424
|
+
let text2 = "";
|
4425
|
+
let textChunk = "";
|
4426
|
+
let lastPublishedJson = "";
|
4427
|
+
return new TransformStream({
|
4428
|
+
transform(chunk, controller) {
|
4429
|
+
if (chunk.type !== "text-delta") {
|
4430
|
+
controller.enqueue({
|
4431
|
+
part: chunk,
|
4432
|
+
partialOutput: void 0
|
4433
|
+
});
|
4434
|
+
return;
|
4435
|
+
}
|
4436
|
+
text2 += chunk.textDelta;
|
4437
|
+
textChunk += chunk.textDelta;
|
4438
|
+
const result = output.parsePartial({ text: text2 });
|
4439
|
+
if (result != null) {
|
4440
|
+
const currentJson = JSON.stringify(result.partial);
|
4441
|
+
if (currentJson !== lastPublishedJson) {
|
4442
|
+
controller.enqueue({
|
4443
|
+
part: {
|
4444
|
+
type: "text-delta",
|
4445
|
+
textDelta: textChunk
|
4446
|
+
},
|
4447
|
+
partialOutput: result.partial
|
4448
|
+
});
|
4449
|
+
lastPublishedJson = currentJson;
|
4450
|
+
textChunk = "";
|
4451
|
+
}
|
4452
|
+
}
|
4453
|
+
},
|
4454
|
+
flush(controller) {
|
4455
|
+
if (textChunk.length > 0) {
|
4456
|
+
controller.enqueue({
|
4457
|
+
part: {
|
4458
|
+
type: "text-delta",
|
4459
|
+
textDelta: textChunk
|
4460
|
+
},
|
4461
|
+
partialOutput: void 0
|
4462
|
+
});
|
4463
|
+
}
|
4464
|
+
}
|
4465
|
+
});
|
4466
|
+
}
|
4374
4467
|
var DefaultStreamTextResult = class {
|
4375
4468
|
constructor({
|
4376
4469
|
model,
|
@@ -4389,6 +4482,7 @@ var DefaultStreamTextResult = class {
|
|
4389
4482
|
activeTools,
|
4390
4483
|
repairToolCall,
|
4391
4484
|
maxSteps,
|
4485
|
+
output,
|
4392
4486
|
continueSteps,
|
4393
4487
|
providerMetadata,
|
4394
4488
|
onChunk,
|
@@ -4408,6 +4502,7 @@ var DefaultStreamTextResult = class {
|
|
4408
4502
|
this.requestPromise = new DelayedPromise();
|
4409
4503
|
this.responsePromise = new DelayedPromise();
|
4410
4504
|
this.stepsPromise = new DelayedPromise();
|
4505
|
+
var _a14;
|
4411
4506
|
if (maxSteps < 1) {
|
4412
4507
|
throw new InvalidArgumentError({
|
4413
4508
|
parameter: "maxSteps",
|
@@ -4415,10 +4510,10 @@ var DefaultStreamTextResult = class {
|
|
4415
4510
|
message: "maxSteps must be at least 1"
|
4416
4511
|
});
|
4417
4512
|
}
|
4513
|
+
this.output = output;
|
4418
4514
|
let recordedStepText = "";
|
4419
4515
|
let recordedContinuationText = "";
|
4420
4516
|
let recordedFullText = "";
|
4421
|
-
let recordedRequest = void 0;
|
4422
4517
|
const recordedResponse = {
|
4423
4518
|
id: generateId3(),
|
4424
4519
|
timestamp: currentDate(),
|
@@ -4429,28 +4524,28 @@ var DefaultStreamTextResult = class {
|
|
4429
4524
|
let recordedToolResults = [];
|
4430
4525
|
let recordedFinishReason = void 0;
|
4431
4526
|
let recordedUsage = void 0;
|
4432
|
-
let recordedProviderMetadata = void 0;
|
4433
4527
|
let stepType = "initial";
|
4434
4528
|
const recordedSteps = [];
|
4435
4529
|
let rootSpan;
|
4436
4530
|
const eventProcessor = new TransformStream({
|
4437
4531
|
async transform(chunk, controller) {
|
4438
4532
|
controller.enqueue(chunk);
|
4439
|
-
|
4440
|
-
|
4533
|
+
const { part } = chunk;
|
4534
|
+
if (part.type === "text-delta" || part.type === "tool-call" || part.type === "tool-result" || part.type === "tool-call-streaming-start" || part.type === "tool-call-delta") {
|
4535
|
+
await (onChunk == null ? void 0 : onChunk({ chunk: part }));
|
4441
4536
|
}
|
4442
|
-
if (
|
4443
|
-
recordedStepText +=
|
4444
|
-
recordedContinuationText +=
|
4445
|
-
recordedFullText +=
|
4537
|
+
if (part.type === "text-delta") {
|
4538
|
+
recordedStepText += part.textDelta;
|
4539
|
+
recordedContinuationText += part.textDelta;
|
4540
|
+
recordedFullText += part.textDelta;
|
4446
4541
|
}
|
4447
|
-
if (
|
4448
|
-
recordedToolCalls.push(
|
4542
|
+
if (part.type === "tool-call") {
|
4543
|
+
recordedToolCalls.push(part);
|
4449
4544
|
}
|
4450
|
-
if (
|
4451
|
-
recordedToolResults.push(
|
4545
|
+
if (part.type === "tool-result") {
|
4546
|
+
recordedToolResults.push(part);
|
4452
4547
|
}
|
4453
|
-
if (
|
4548
|
+
if (part.type === "step-finish") {
|
4454
4549
|
const stepMessages = toResponseMessages({
|
4455
4550
|
text: recordedContinuationText,
|
4456
4551
|
tools: tools != null ? tools : {},
|
@@ -4460,7 +4555,7 @@ var DefaultStreamTextResult = class {
|
|
4460
4555
|
const currentStep = recordedSteps.length;
|
4461
4556
|
let nextStepType = "done";
|
4462
4557
|
if (currentStep + 1 < maxSteps) {
|
4463
|
-
if (continueSteps &&
|
4558
|
+
if (continueSteps && part.finishReason === "length" && // only use continue when there are no tool calls:
|
4464
4559
|
recordedToolCalls.length === 0) {
|
4465
4560
|
nextStepType = "continue";
|
4466
4561
|
} else if (
|
@@ -4476,24 +4571,23 @@ var DefaultStreamTextResult = class {
|
|
4476
4571
|
text: recordedStepText,
|
4477
4572
|
toolCalls: recordedToolCalls,
|
4478
4573
|
toolResults: recordedToolResults,
|
4479
|
-
finishReason:
|
4480
|
-
usage:
|
4481
|
-
warnings:
|
4482
|
-
logprobs:
|
4483
|
-
request:
|
4574
|
+
finishReason: part.finishReason,
|
4575
|
+
usage: part.usage,
|
4576
|
+
warnings: part.warnings,
|
4577
|
+
logprobs: part.logprobs,
|
4578
|
+
request: part.request,
|
4484
4579
|
response: {
|
4485
|
-
...
|
4580
|
+
...part.response,
|
4486
4581
|
messages: [...recordedResponse.messages, ...stepMessages]
|
4487
4582
|
},
|
4488
|
-
experimental_providerMetadata:
|
4489
|
-
isContinued:
|
4583
|
+
experimental_providerMetadata: part.experimental_providerMetadata,
|
4584
|
+
isContinued: part.isContinued
|
4490
4585
|
};
|
4491
4586
|
await (onStepFinish == null ? void 0 : onStepFinish(currentStepResult));
|
4492
4587
|
recordedSteps.push(currentStepResult);
|
4493
4588
|
recordedToolCalls = [];
|
4494
4589
|
recordedToolResults = [];
|
4495
4590
|
recordedStepText = "";
|
4496
|
-
recordedRequest = chunk.request;
|
4497
4591
|
if (nextStepType !== "done") {
|
4498
4592
|
stepType = nextStepType;
|
4499
4593
|
}
|
@@ -4502,18 +4596,17 @@ var DefaultStreamTextResult = class {
|
|
4502
4596
|
recordedContinuationText = "";
|
4503
4597
|
}
|
4504
4598
|
}
|
4505
|
-
if (
|
4506
|
-
recordedResponse.id =
|
4507
|
-
recordedResponse.timestamp =
|
4508
|
-
recordedResponse.modelId =
|
4509
|
-
recordedResponse.headers =
|
4510
|
-
recordedUsage =
|
4511
|
-
recordedFinishReason =
|
4512
|
-
recordedProviderMetadata = chunk.experimental_providerMetadata;
|
4599
|
+
if (part.type === "finish") {
|
4600
|
+
recordedResponse.id = part.response.id;
|
4601
|
+
recordedResponse.timestamp = part.response.timestamp;
|
4602
|
+
recordedResponse.modelId = part.response.modelId;
|
4603
|
+
recordedResponse.headers = part.response.headers;
|
4604
|
+
recordedUsage = part.usage;
|
4605
|
+
recordedFinishReason = part.finishReason;
|
4513
4606
|
}
|
4514
4607
|
},
|
4515
4608
|
async flush(controller) {
|
4516
|
-
var
|
4609
|
+
var _a15;
|
4517
4610
|
try {
|
4518
4611
|
const lastStep = recordedSteps[recordedSteps.length - 1];
|
4519
4612
|
if (lastStep) {
|
@@ -4543,7 +4636,7 @@ var DefaultStreamTextResult = class {
|
|
4543
4636
|
text: recordedFullText,
|
4544
4637
|
toolCalls: lastStep.toolCalls,
|
4545
4638
|
toolResults: lastStep.toolResults,
|
4546
|
-
request: (
|
4639
|
+
request: (_a15 = lastStep.request) != null ? _a15 : {},
|
4547
4640
|
response: lastStep.response,
|
4548
4641
|
warnings: lastStep.warnings,
|
4549
4642
|
experimental_providerMetadata: lastStep.experimental_providerMetadata,
|
@@ -4557,8 +4650,8 @@ var DefaultStreamTextResult = class {
|
|
4557
4650
|
"ai.response.text": { output: () => recordedFullText },
|
4558
4651
|
"ai.response.toolCalls": {
|
4559
4652
|
output: () => {
|
4560
|
-
var
|
4561
|
-
return ((
|
4653
|
+
var _a16;
|
4654
|
+
return ((_a16 = lastStep.toolCalls) == null ? void 0 : _a16.length) ? JSON.stringify(lastStep.toolCalls) : void 0;
|
4562
4655
|
}
|
4563
4656
|
},
|
4564
4657
|
"ai.usage.promptTokens": usage.promptTokens,
|
@@ -4576,7 +4669,11 @@ var DefaultStreamTextResult = class {
|
|
4576
4669
|
const stitchableStream = createStitchableStream();
|
4577
4670
|
this.addStream = stitchableStream.addStream;
|
4578
4671
|
this.closeStream = stitchableStream.close;
|
4579
|
-
|
4672
|
+
let stream = stitchableStream.stream;
|
4673
|
+
if (transform) {
|
4674
|
+
stream = stream.pipeThrough(transform);
|
4675
|
+
}
|
4676
|
+
this.baseStream = stream.pipeThrough(createOutputTransformStream(output)).pipeThrough(eventProcessor);
|
4580
4677
|
const { maxRetries, retry } = prepareRetries({
|
4581
4678
|
maxRetries: maxRetriesArg
|
4582
4679
|
});
|
@@ -4588,7 +4685,11 @@ var DefaultStreamTextResult = class {
|
|
4588
4685
|
settings: { ...settings, maxRetries }
|
4589
4686
|
});
|
4590
4687
|
const initialPrompt = standardizePrompt({
|
4591
|
-
prompt: {
|
4688
|
+
prompt: {
|
4689
|
+
system: (_a14 = output == null ? void 0 : output.injectIntoSystemPrompt({ system, model })) != null ? _a14 : system,
|
4690
|
+
prompt,
|
4691
|
+
messages
|
4692
|
+
},
|
4592
4693
|
tools
|
4593
4694
|
});
|
4594
4695
|
const self = this;
|
@@ -4637,7 +4738,7 @@ var DefaultStreamTextResult = class {
|
|
4637
4738
|
...prepareToolsAndToolChoice({ tools, toolChoice, activeTools })
|
4638
4739
|
};
|
4639
4740
|
const {
|
4640
|
-
result: { stream, warnings, rawResponse, request },
|
4741
|
+
result: { stream: stream2, warnings, rawResponse, request },
|
4641
4742
|
doStreamSpan,
|
4642
4743
|
startTimestampMs
|
4643
4744
|
} = await retry(
|
@@ -4660,8 +4761,8 @@ var DefaultStreamTextResult = class {
|
|
4660
4761
|
"ai.prompt.tools": {
|
4661
4762
|
// convert the language model level tools:
|
4662
4763
|
input: () => {
|
4663
|
-
var
|
4664
|
-
return (
|
4764
|
+
var _a15;
|
4765
|
+
return (_a15 = mode.tools) == null ? void 0 : _a15.map((tool2) => JSON.stringify(tool2));
|
4665
4766
|
}
|
4666
4767
|
},
|
4667
4768
|
"ai.prompt.toolChoice": {
|
@@ -4689,6 +4790,7 @@ var DefaultStreamTextResult = class {
|
|
4689
4790
|
mode,
|
4690
4791
|
...prepareCallSettings(settings),
|
4691
4792
|
inputFormat: promptFormat,
|
4793
|
+
responseFormat: output == null ? void 0 : output.responseFormat({ model }),
|
4692
4794
|
prompt: promptMessages,
|
4693
4795
|
providerMetadata,
|
4694
4796
|
abortSignal,
|
@@ -4699,7 +4801,7 @@ var DefaultStreamTextResult = class {
|
|
4699
4801
|
);
|
4700
4802
|
const transformedStream = runToolsTransformation({
|
4701
4803
|
tools,
|
4702
|
-
generatorStream:
|
4804
|
+
generatorStream: stream2,
|
4703
4805
|
toolCallStreaming,
|
4704
4806
|
tracer,
|
4705
4807
|
telemetry,
|
@@ -4745,7 +4847,7 @@ var DefaultStreamTextResult = class {
|
|
4745
4847
|
transformedStream.pipeThrough(
|
4746
4848
|
new TransformStream({
|
4747
4849
|
async transform(chunk, controller) {
|
4748
|
-
var
|
4850
|
+
var _a15, _b, _c;
|
4749
4851
|
if (stepFirstChunk) {
|
4750
4852
|
const msToFirstChunk = now2() - startTimestampMs;
|
4751
4853
|
stepFirstChunk = false;
|
@@ -4797,7 +4899,7 @@ var DefaultStreamTextResult = class {
|
|
4797
4899
|
}
|
4798
4900
|
case "response-metadata": {
|
4799
4901
|
stepResponse = {
|
4800
|
-
id: (
|
4902
|
+
id: (_a15 = chunk.id) != null ? _a15 : stepResponse.id,
|
4801
4903
|
timestamp: (_b = chunk.timestamp) != null ? _b : stepResponse.timestamp,
|
4802
4904
|
modelId: (_c = chunk.modelId) != null ? _c : stepResponse.modelId
|
4803
4905
|
};
|
@@ -5022,11 +5124,11 @@ var DefaultStreamTextResult = class {
|
|
5022
5124
|
return createAsyncIterableStream(
|
5023
5125
|
this.teeStream().pipeThrough(
|
5024
5126
|
new TransformStream({
|
5025
|
-
transform(
|
5026
|
-
if (
|
5027
|
-
controller.enqueue(
|
5028
|
-
} else if (
|
5029
|
-
controller.error(
|
5127
|
+
transform({ part }, controller) {
|
5128
|
+
if (part.type === "text-delta") {
|
5129
|
+
controller.enqueue(part.textDelta);
|
5130
|
+
} else if (part.type === "error") {
|
5131
|
+
controller.error(part.error);
|
5030
5132
|
}
|
5031
5133
|
}
|
5032
5134
|
})
|
@@ -5034,7 +5136,31 @@ var DefaultStreamTextResult = class {
|
|
5034
5136
|
);
|
5035
5137
|
}
|
5036
5138
|
get fullStream() {
|
5037
|
-
return createAsyncIterableStream(
|
5139
|
+
return createAsyncIterableStream(
|
5140
|
+
this.teeStream().pipeThrough(
|
5141
|
+
new TransformStream({
|
5142
|
+
transform({ part }, controller) {
|
5143
|
+
controller.enqueue(part);
|
5144
|
+
}
|
5145
|
+
})
|
5146
|
+
)
|
5147
|
+
);
|
5148
|
+
}
|
5149
|
+
get experimental_partialOutputStream() {
|
5150
|
+
if (this.output == null) {
|
5151
|
+
throw new NoOutputSpecifiedError();
|
5152
|
+
}
|
5153
|
+
return createAsyncIterableStream(
|
5154
|
+
this.teeStream().pipeThrough(
|
5155
|
+
new TransformStream({
|
5156
|
+
transform({ partialOutput }, controller) {
|
5157
|
+
if (partialOutput != null) {
|
5158
|
+
controller.enqueue(partialOutput);
|
5159
|
+
}
|
5160
|
+
}
|
5161
|
+
})
|
5162
|
+
)
|
5163
|
+
);
|
5038
5164
|
}
|
5039
5165
|
toDataStreamInternal({
|
5040
5166
|
getErrorMessage: getErrorMessage5 = () => "An error occurred.",
|
@@ -5201,9 +5327,9 @@ var DefaultStreamTextResult = class {
|
|
5201
5327
|
);
|
5202
5328
|
}
|
5203
5329
|
toTextStreamResponse(init) {
|
5204
|
-
var
|
5330
|
+
var _a14;
|
5205
5331
|
return new Response(this.textStream.pipeThrough(new TextEncoderStream()), {
|
5206
|
-
status: (
|
5332
|
+
status: (_a14 = init == null ? void 0 : init.status) != null ? _a14 : 200,
|
5207
5333
|
headers: prepareResponseHeaders(init == null ? void 0 : init.headers, {
|
5208
5334
|
contentType: "text/plain; charset=utf-8"
|
5209
5335
|
})
|
@@ -5232,11 +5358,11 @@ function smoothStream({
|
|
5232
5358
|
return;
|
5233
5359
|
}
|
5234
5360
|
buffer += chunk.textDelta;
|
5235
|
-
|
5236
|
-
|
5237
|
-
const
|
5238
|
-
controller.enqueue({ type: "text-delta", textDelta:
|
5239
|
-
buffer = buffer.slice(
|
5361
|
+
const regexp = /\s*\S+\s+/m;
|
5362
|
+
while (regexp.test(buffer)) {
|
5363
|
+
const chunk2 = buffer.match(regexp)[0];
|
5364
|
+
controller.enqueue({ type: "text-delta", textDelta: chunk2 });
|
5365
|
+
buffer = buffer.slice(chunk2.length);
|
5240
5366
|
if (delayInMs > 0) {
|
5241
5367
|
await delay2(delayInMs);
|
5242
5368
|
}
|
@@ -5280,7 +5406,7 @@ var experimental_wrapLanguageModel = ({
|
|
5280
5406
|
};
|
5281
5407
|
|
5282
5408
|
// core/registry/custom-provider.ts
|
5283
|
-
var
|
5409
|
+
var import_provider17 = require("@ai-sdk/provider");
|
5284
5410
|
function experimental_customProvider({
|
5285
5411
|
languageModels,
|
5286
5412
|
textEmbeddingModels,
|
@@ -5294,7 +5420,7 @@ function experimental_customProvider({
|
|
5294
5420
|
if (fallbackProvider) {
|
5295
5421
|
return fallbackProvider.languageModel(modelId);
|
5296
5422
|
}
|
5297
|
-
throw new
|
5423
|
+
throw new import_provider17.NoSuchModelError({ modelId, modelType: "languageModel" });
|
5298
5424
|
},
|
5299
5425
|
textEmbeddingModel(modelId) {
|
5300
5426
|
if (textEmbeddingModels != null && modelId in textEmbeddingModels) {
|
@@ -5303,18 +5429,18 @@ function experimental_customProvider({
|
|
5303
5429
|
if (fallbackProvider) {
|
5304
5430
|
return fallbackProvider.textEmbeddingModel(modelId);
|
5305
5431
|
}
|
5306
|
-
throw new
|
5432
|
+
throw new import_provider17.NoSuchModelError({ modelId, modelType: "textEmbeddingModel" });
|
5307
5433
|
}
|
5308
5434
|
};
|
5309
5435
|
}
|
5310
5436
|
|
5311
5437
|
// core/registry/no-such-provider-error.ts
|
5312
|
-
var
|
5313
|
-
var
|
5314
|
-
var
|
5315
|
-
var
|
5316
|
-
var
|
5317
|
-
var NoSuchProviderError = class extends
|
5438
|
+
var import_provider18 = require("@ai-sdk/provider");
|
5439
|
+
var name13 = "AI_NoSuchProviderError";
|
5440
|
+
var marker13 = `vercel.ai.error.${name13}`;
|
5441
|
+
var symbol13 = Symbol.for(marker13);
|
5442
|
+
var _a13;
|
5443
|
+
var NoSuchProviderError = class extends import_provider18.NoSuchModelError {
|
5318
5444
|
constructor({
|
5319
5445
|
modelId,
|
5320
5446
|
modelType,
|
@@ -5322,19 +5448,19 @@ var NoSuchProviderError = class extends import_provider17.NoSuchModelError {
|
|
5322
5448
|
availableProviders,
|
5323
5449
|
message = `No such provider: ${providerId} (available providers: ${availableProviders.join()})`
|
5324
5450
|
}) {
|
5325
|
-
super({ errorName:
|
5326
|
-
this[
|
5451
|
+
super({ errorName: name13, modelId, modelType, message });
|
5452
|
+
this[_a13] = true;
|
5327
5453
|
this.providerId = providerId;
|
5328
5454
|
this.availableProviders = availableProviders;
|
5329
5455
|
}
|
5330
5456
|
static isInstance(error) {
|
5331
|
-
return
|
5457
|
+
return import_provider18.AISDKError.hasMarker(error, marker13);
|
5332
5458
|
}
|
5333
5459
|
};
|
5334
|
-
|
5460
|
+
_a13 = symbol13;
|
5335
5461
|
|
5336
5462
|
// core/registry/provider-registry.ts
|
5337
|
-
var
|
5463
|
+
var import_provider19 = require("@ai-sdk/provider");
|
5338
5464
|
function experimental_createProviderRegistry(providers) {
|
5339
5465
|
const registry = new DefaultProviderRegistry();
|
5340
5466
|
for (const [id, provider] of Object.entries(providers)) {
|
@@ -5364,7 +5490,7 @@ var DefaultProviderRegistry = class {
|
|
5364
5490
|
splitId(id, modelType) {
|
5365
5491
|
const index = id.indexOf(":");
|
5366
5492
|
if (index === -1) {
|
5367
|
-
throw new
|
5493
|
+
throw new import_provider19.NoSuchModelError({
|
5368
5494
|
modelId: id,
|
5369
5495
|
modelType,
|
5370
5496
|
message: `Invalid ${modelType} id for registry: ${id} (must be in the format "providerId:modelId")`
|
@@ -5373,21 +5499,21 @@ var DefaultProviderRegistry = class {
|
|
5373
5499
|
return [id.slice(0, index), id.slice(index + 1)];
|
5374
5500
|
}
|
5375
5501
|
languageModel(id) {
|
5376
|
-
var
|
5502
|
+
var _a14, _b;
|
5377
5503
|
const [providerId, modelId] = this.splitId(id, "languageModel");
|
5378
|
-
const model = (_b = (
|
5504
|
+
const model = (_b = (_a14 = this.getProvider(providerId)).languageModel) == null ? void 0 : _b.call(_a14, modelId);
|
5379
5505
|
if (model == null) {
|
5380
|
-
throw new
|
5506
|
+
throw new import_provider19.NoSuchModelError({ modelId: id, modelType: "languageModel" });
|
5381
5507
|
}
|
5382
5508
|
return model;
|
5383
5509
|
}
|
5384
5510
|
textEmbeddingModel(id) {
|
5385
|
-
var
|
5511
|
+
var _a14;
|
5386
5512
|
const [providerId, modelId] = this.splitId(id, "textEmbeddingModel");
|
5387
5513
|
const provider = this.getProvider(providerId);
|
5388
|
-
const model = (
|
5514
|
+
const model = (_a14 = provider.textEmbeddingModel) == null ? void 0 : _a14.call(provider, modelId);
|
5389
5515
|
if (model == null) {
|
5390
|
-
throw new
|
5516
|
+
throw new import_provider19.NoSuchModelError({
|
5391
5517
|
modelId: id,
|
5392
5518
|
modelType: "textEmbeddingModel"
|
5393
5519
|
});
|
@@ -5431,7 +5557,7 @@ var import_ui_utils10 = require("@ai-sdk/ui-utils");
|
|
5431
5557
|
function AssistantResponse({ threadId, messageId }, process2) {
|
5432
5558
|
const stream = new ReadableStream({
|
5433
5559
|
async start(controller) {
|
5434
|
-
var
|
5560
|
+
var _a14;
|
5435
5561
|
const textEncoder = new TextEncoder();
|
5436
5562
|
const sendMessage = (message) => {
|
5437
5563
|
controller.enqueue(
|
@@ -5453,7 +5579,7 @@ function AssistantResponse({ threadId, messageId }, process2) {
|
|
5453
5579
|
);
|
5454
5580
|
};
|
5455
5581
|
const forwardStream = async (stream2) => {
|
5456
|
-
var
|
5582
|
+
var _a15, _b;
|
5457
5583
|
let result = void 0;
|
5458
5584
|
for await (const value of stream2) {
|
5459
5585
|
switch (value.event) {
|
@@ -5470,7 +5596,7 @@ function AssistantResponse({ threadId, messageId }, process2) {
|
|
5470
5596
|
break;
|
5471
5597
|
}
|
5472
5598
|
case "thread.message.delta": {
|
5473
|
-
const content = (
|
5599
|
+
const content = (_a15 = value.data.delta.content) == null ? void 0 : _a15[0];
|
5474
5600
|
if ((content == null ? void 0 : content.type) === "text" && ((_b = content.text) == null ? void 0 : _b.value) != null) {
|
5475
5601
|
controller.enqueue(
|
5476
5602
|
textEncoder.encode(
|
@@ -5504,7 +5630,7 @@ function AssistantResponse({ threadId, messageId }, process2) {
|
|
5504
5630
|
forwardStream
|
5505
5631
|
});
|
5506
5632
|
} catch (error) {
|
5507
|
-
sendError((
|
5633
|
+
sendError((_a14 = error.message) != null ? _a14 : `${error}`);
|
5508
5634
|
} finally {
|
5509
5635
|
controller.close();
|
5510
5636
|
}
|
@@ -5565,7 +5691,7 @@ function toDataStreamInternal(stream, callbacks) {
|
|
5565
5691
|
return stream.pipeThrough(
|
5566
5692
|
new TransformStream({
|
5567
5693
|
transform: async (value, controller) => {
|
5568
|
-
var
|
5694
|
+
var _a14;
|
5569
5695
|
if (typeof value === "string") {
|
5570
5696
|
controller.enqueue(value);
|
5571
5697
|
return;
|
@@ -5573,7 +5699,7 @@ function toDataStreamInternal(stream, callbacks) {
|
|
5573
5699
|
if ("event" in value) {
|
5574
5700
|
if (value.event === "on_chat_model_stream") {
|
5575
5701
|
forwardAIMessageChunk(
|
5576
|
-
(
|
5702
|
+
(_a14 = value.data) == null ? void 0 : _a14.chunk,
|
5577
5703
|
controller
|
5578
5704
|
);
|
5579
5705
|
}
|
@@ -5596,7 +5722,7 @@ function toDataStream(stream, callbacks) {
|
|
5596
5722
|
);
|
5597
5723
|
}
|
5598
5724
|
function toDataStreamResponse(stream, options) {
|
5599
|
-
var
|
5725
|
+
var _a14;
|
5600
5726
|
const dataStream = toDataStreamInternal(
|
5601
5727
|
stream,
|
5602
5728
|
options == null ? void 0 : options.callbacks
|
@@ -5605,7 +5731,7 @@ function toDataStreamResponse(stream, options) {
|
|
5605
5731
|
const init = options == null ? void 0 : options.init;
|
5606
5732
|
const responseStream = data ? mergeStreams(data.stream, dataStream) : dataStream;
|
5607
5733
|
return new Response(responseStream, {
|
5608
|
-
status: (
|
5734
|
+
status: (_a14 = init == null ? void 0 : init.status) != null ? _a14 : 200,
|
5609
5735
|
statusText: init == null ? void 0 : init.statusText,
|
5610
5736
|
headers: prepareResponseHeaders(init == null ? void 0 : init.headers, {
|
5611
5737
|
contentType: "text/plain; charset=utf-8",
|
@@ -5660,14 +5786,14 @@ function toDataStream2(stream, callbacks) {
|
|
5660
5786
|
);
|
5661
5787
|
}
|
5662
5788
|
function toDataStreamResponse2(stream, options = {}) {
|
5663
|
-
var
|
5789
|
+
var _a14;
|
5664
5790
|
const { init, data, callbacks } = options;
|
5665
5791
|
const dataStream = toDataStreamInternal2(stream, callbacks).pipeThrough(
|
5666
5792
|
new TextEncoderStream()
|
5667
5793
|
);
|
5668
5794
|
const responseStream = data ? mergeStreams(data.stream, dataStream) : dataStream;
|
5669
5795
|
return new Response(responseStream, {
|
5670
|
-
status: (
|
5796
|
+
status: (_a14 = init == null ? void 0 : init.status) != null ? _a14 : 200,
|
5671
5797
|
statusText: init == null ? void 0 : init.statusText,
|
5672
5798
|
headers: prepareResponseHeaders(init == null ? void 0 : init.headers, {
|
5673
5799
|
contentType: "text/plain; charset=utf-8",
|
@@ -5778,6 +5904,7 @@ var StreamData = class {
|
|
5778
5904
|
MessageConversionError,
|
5779
5905
|
NoContentGeneratedError,
|
5780
5906
|
NoObjectGeneratedError,
|
5907
|
+
NoOutputSpecifiedError,
|
5781
5908
|
NoSuchModelError,
|
5782
5909
|
NoSuchProviderError,
|
5783
5910
|
NoSuchToolError,
|