ai 4.0.23 → 4.0.25
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 +361 -225
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +360 -222
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
var __defProp = Object.defineProperty;
|
2
2
|
var __export = (target, all) => {
|
3
|
-
for (var
|
4
|
-
__defProp(target,
|
3
|
+
for (var name14 in all)
|
4
|
+
__defProp(target, name14, { get: all[name14], enumerable: true });
|
5
5
|
};
|
6
6
|
|
7
7
|
// streams/index.ts
|
@@ -354,7 +354,7 @@ function getBaseTelemetryAttributes({
|
|
354
354
|
telemetry,
|
355
355
|
headers
|
356
356
|
}) {
|
357
|
-
var
|
357
|
+
var _a14;
|
358
358
|
return {
|
359
359
|
"ai.model.provider": model.provider,
|
360
360
|
"ai.model.id": model.modelId,
|
@@ -364,7 +364,7 @@ function getBaseTelemetryAttributes({
|
|
364
364
|
return attributes;
|
365
365
|
}, {}),
|
366
366
|
// add metadata as attributes:
|
367
|
-
...Object.entries((
|
367
|
+
...Object.entries((_a14 = telemetry == null ? void 0 : telemetry.metadata) != null ? _a14 : {}).reduce(
|
368
368
|
(attributes, [key, value]) => {
|
369
369
|
attributes[`ai.telemetry.metadata.${key}`] = value;
|
370
370
|
return attributes;
|
@@ -389,7 +389,7 @@ var noopTracer = {
|
|
389
389
|
startSpan() {
|
390
390
|
return noopSpan;
|
391
391
|
},
|
392
|
-
startActiveSpan(
|
392
|
+
startActiveSpan(name14, arg1, arg2, arg3) {
|
393
393
|
if (typeof arg1 === "function") {
|
394
394
|
return arg1(noopSpan);
|
395
395
|
}
|
@@ -459,13 +459,13 @@ function getTracer({
|
|
459
459
|
// core/telemetry/record-span.ts
|
460
460
|
import { SpanStatusCode } from "@opentelemetry/api";
|
461
461
|
function recordSpan({
|
462
|
-
name:
|
462
|
+
name: name14,
|
463
463
|
tracer,
|
464
464
|
attributes,
|
465
465
|
fn,
|
466
466
|
endWhenDone = true
|
467
467
|
}) {
|
468
|
-
return tracer.startActiveSpan(
|
468
|
+
return tracer.startActiveSpan(name14, { attributes }, async (span) => {
|
469
469
|
try {
|
470
470
|
const result = await fn(span);
|
471
471
|
if (endWhenDone) {
|
@@ -573,14 +573,14 @@ async function embed({
|
|
573
573
|
}),
|
574
574
|
tracer,
|
575
575
|
fn: async (doEmbedSpan) => {
|
576
|
-
var
|
576
|
+
var _a14;
|
577
577
|
const modelResponse = await model.doEmbed({
|
578
578
|
values: [value],
|
579
579
|
abortSignal,
|
580
580
|
headers
|
581
581
|
});
|
582
582
|
const embedding2 = modelResponse.embeddings[0];
|
583
|
-
const usage2 = (
|
583
|
+
const usage2 = (_a14 = modelResponse.usage) != null ? _a14 : { tokens: NaN };
|
584
584
|
doEmbedSpan.setAttributes(
|
585
585
|
selectTelemetryAttributes({
|
586
586
|
telemetry,
|
@@ -690,14 +690,14 @@ async function embedMany({
|
|
690
690
|
}),
|
691
691
|
tracer,
|
692
692
|
fn: async (doEmbedSpan) => {
|
693
|
-
var
|
693
|
+
var _a14;
|
694
694
|
const modelResponse = await model.doEmbed({
|
695
695
|
values,
|
696
696
|
abortSignal,
|
697
697
|
headers
|
698
698
|
});
|
699
699
|
const embeddings3 = modelResponse.embeddings;
|
700
|
-
const usage2 = (
|
700
|
+
const usage2 = (_a14 = modelResponse.usage) != null ? _a14 : { tokens: NaN };
|
701
701
|
doEmbedSpan.setAttributes(
|
702
702
|
selectTelemetryAttributes({
|
703
703
|
telemetry,
|
@@ -749,14 +749,14 @@ async function embedMany({
|
|
749
749
|
}),
|
750
750
|
tracer,
|
751
751
|
fn: async (doEmbedSpan) => {
|
752
|
-
var
|
752
|
+
var _a14;
|
753
753
|
const modelResponse = await model.doEmbed({
|
754
754
|
values: chunk,
|
755
755
|
abortSignal,
|
756
756
|
headers
|
757
757
|
});
|
758
758
|
const embeddings2 = modelResponse.embeddings;
|
759
|
-
const usage2 = (
|
759
|
+
const usage2 = (_a14 = modelResponse.usage) != null ? _a14 : { tokens: NaN };
|
760
760
|
doEmbedSpan.setAttributes(
|
761
761
|
selectTelemetryAttributes({
|
762
762
|
telemetry,
|
@@ -901,7 +901,7 @@ async function download({
|
|
901
901
|
url,
|
902
902
|
fetchImplementation = fetch
|
903
903
|
}) {
|
904
|
-
var
|
904
|
+
var _a14;
|
905
905
|
const urlText = url.toString();
|
906
906
|
try {
|
907
907
|
const response = await fetchImplementation(urlText);
|
@@ -914,7 +914,7 @@ async function download({
|
|
914
914
|
}
|
915
915
|
return {
|
916
916
|
data: new Uint8Array(await response.arrayBuffer()),
|
917
|
-
mimeType: (
|
917
|
+
mimeType: (_a14 = response.headers.get("content-type")) != null ? _a14 : void 0
|
918
918
|
};
|
919
919
|
} catch (error) {
|
920
920
|
if (DownloadError.isInstance(error)) {
|
@@ -977,8 +977,8 @@ var dataContentSchema = z.union([
|
|
977
977
|
z.custom(
|
978
978
|
// Buffer might not be available in some environments such as CloudFlare:
|
979
979
|
(value) => {
|
980
|
-
var
|
981
|
-
return (_b = (
|
980
|
+
var _a14, _b;
|
981
|
+
return (_b = (_a14 = globalThis.Buffer) == null ? void 0 : _a14.isBuffer(value)) != null ? _b : false;
|
982
982
|
},
|
983
983
|
{ message: "Must be a Buffer" }
|
984
984
|
)
|
@@ -1169,7 +1169,7 @@ async function downloadAssets(messages, downloadImplementation, modelSupportsIma
|
|
1169
1169
|
);
|
1170
1170
|
}
|
1171
1171
|
function convertPartToLanguageModelPart(part, downloadedAssets) {
|
1172
|
-
var
|
1172
|
+
var _a14;
|
1173
1173
|
if (part.type === "text") {
|
1174
1174
|
return {
|
1175
1175
|
type: "text",
|
@@ -1222,7 +1222,7 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
|
|
1222
1222
|
switch (type) {
|
1223
1223
|
case "image": {
|
1224
1224
|
if (normalizedData instanceof Uint8Array) {
|
1225
|
-
mimeType = (
|
1225
|
+
mimeType = (_a14 = detectImageMimeType(normalizedData)) != null ? _a14 : mimeType;
|
1226
1226
|
}
|
1227
1227
|
return {
|
1228
1228
|
type: "image",
|
@@ -1489,7 +1489,7 @@ function detectSingleMessageCharacteristics(message) {
|
|
1489
1489
|
|
1490
1490
|
// core/prompt/attachments-to-parts.ts
|
1491
1491
|
function attachmentsToParts(attachments) {
|
1492
|
-
var
|
1492
|
+
var _a14, _b, _c;
|
1493
1493
|
const parts = [];
|
1494
1494
|
for (const attachment of attachments) {
|
1495
1495
|
let url;
|
@@ -1501,7 +1501,7 @@ function attachmentsToParts(attachments) {
|
|
1501
1501
|
switch (url.protocol) {
|
1502
1502
|
case "http:":
|
1503
1503
|
case "https:": {
|
1504
|
-
if ((
|
1504
|
+
if ((_a14 = attachment.contentType) == null ? void 0 : _a14.startsWith("image/")) {
|
1505
1505
|
parts.push({ type: "image", image: url });
|
1506
1506
|
} else {
|
1507
1507
|
if (!attachment.contentType) {
|
@@ -1587,8 +1587,8 @@ _a7 = symbol7;
|
|
1587
1587
|
|
1588
1588
|
// core/prompt/convert-to-core-messages.ts
|
1589
1589
|
function convertToCoreMessages(messages, options) {
|
1590
|
-
var
|
1591
|
-
const tools = (
|
1590
|
+
var _a14;
|
1591
|
+
const tools = (_a14 = options == null ? void 0 : options.tools) != null ? _a14 : {};
|
1592
1592
|
const coreMessages = [];
|
1593
1593
|
for (const message of messages) {
|
1594
1594
|
const { role, content, toolInvocations, experimental_attachments } = message;
|
@@ -1870,7 +1870,7 @@ var arrayOutputStrategy = (schema) => {
|
|
1870
1870
|
additionalProperties: false
|
1871
1871
|
},
|
1872
1872
|
validatePartialResult({ value, latestObject, isFirstDelta, isFinalDelta }) {
|
1873
|
-
var
|
1873
|
+
var _a14;
|
1874
1874
|
if (!isJSONObject(value) || !isJSONArray(value.elements)) {
|
1875
1875
|
return {
|
1876
1876
|
success: false,
|
@@ -1893,7 +1893,7 @@ var arrayOutputStrategy = (schema) => {
|
|
1893
1893
|
}
|
1894
1894
|
resultArray.push(result.value);
|
1895
1895
|
}
|
1896
|
-
const publishedElementCount = (
|
1896
|
+
const publishedElementCount = (_a14 = latestObject == null ? void 0 : latestObject.length) != null ? _a14 : 0;
|
1897
1897
|
let textDelta = "";
|
1898
1898
|
if (isFirstDelta) {
|
1899
1899
|
textDelta += "[";
|
@@ -2231,7 +2231,7 @@ async function generateObject({
|
|
2231
2231
|
}),
|
2232
2232
|
tracer,
|
2233
2233
|
fn: async (span) => {
|
2234
|
-
var
|
2234
|
+
var _a14, _b;
|
2235
2235
|
if (mode === "auto" || mode == null) {
|
2236
2236
|
mode = model.defaultObjectGenerationMode;
|
2237
2237
|
}
|
@@ -2293,7 +2293,7 @@ async function generateObject({
|
|
2293
2293
|
}),
|
2294
2294
|
tracer,
|
2295
2295
|
fn: async (span2) => {
|
2296
|
-
var
|
2296
|
+
var _a15, _b2, _c, _d, _e, _f;
|
2297
2297
|
const result2 = await model.doGenerate({
|
2298
2298
|
mode: {
|
2299
2299
|
type: "object-json",
|
@@ -2309,7 +2309,7 @@ async function generateObject({
|
|
2309
2309
|
headers
|
2310
2310
|
});
|
2311
2311
|
const responseData = {
|
2312
|
-
id: (_b2 = (
|
2312
|
+
id: (_b2 = (_a15 = result2.response) == null ? void 0 : _a15.id) != null ? _b2 : generateId3(),
|
2313
2313
|
timestamp: (_d = (_c = result2.response) == null ? void 0 : _c.timestamp) != null ? _d : currentDate(),
|
2314
2314
|
modelId: (_f = (_e = result2.response) == null ? void 0 : _e.modelId) != null ? _f : model.modelId
|
2315
2315
|
};
|
@@ -2351,7 +2351,7 @@ async function generateObject({
|
|
2351
2351
|
rawResponse = generateResult.rawResponse;
|
2352
2352
|
logprobs = generateResult.logprobs;
|
2353
2353
|
resultProviderMetadata = generateResult.providerMetadata;
|
2354
|
-
request = (
|
2354
|
+
request = (_a14 = generateResult.request) != null ? _a14 : {};
|
2355
2355
|
response = generateResult.responseData;
|
2356
2356
|
break;
|
2357
2357
|
}
|
@@ -2397,7 +2397,7 @@ async function generateObject({
|
|
2397
2397
|
}),
|
2398
2398
|
tracer,
|
2399
2399
|
fn: async (span2) => {
|
2400
|
-
var
|
2400
|
+
var _a15, _b2, _c, _d, _e, _f, _g, _h;
|
2401
2401
|
const result2 = await model.doGenerate({
|
2402
2402
|
mode: {
|
2403
2403
|
type: "object-tool",
|
@@ -2415,7 +2415,7 @@ async function generateObject({
|
|
2415
2415
|
abortSignal,
|
2416
2416
|
headers
|
2417
2417
|
});
|
2418
|
-
const objectText = (_b2 = (
|
2418
|
+
const objectText = (_b2 = (_a15 = result2.toolCalls) == null ? void 0 : _a15[0]) == null ? void 0 : _b2.args;
|
2419
2419
|
const responseData = {
|
2420
2420
|
id: (_d = (_c = result2.response) == null ? void 0 : _c.id) != null ? _d : generateId3(),
|
2421
2421
|
timestamp: (_f = (_e = result2.response) == null ? void 0 : _e.timestamp) != null ? _f : currentDate(),
|
@@ -2541,9 +2541,9 @@ var DefaultGenerateObjectResult = class {
|
|
2541
2541
|
this.logprobs = options.logprobs;
|
2542
2542
|
}
|
2543
2543
|
toJsonResponse(init) {
|
2544
|
-
var
|
2544
|
+
var _a14;
|
2545
2545
|
return new Response(JSON.stringify(this.object), {
|
2546
|
-
status: (
|
2546
|
+
status: (_a14 = init == null ? void 0 : init.status) != null ? _a14 : 200,
|
2547
2547
|
headers: prepareResponseHeaders(init == null ? void 0 : init.headers, {
|
2548
2548
|
contentType: "application/json; charset=utf-8"
|
2549
2549
|
})
|
@@ -2581,17 +2581,17 @@ var DelayedPromise = class {
|
|
2581
2581
|
return this.promise;
|
2582
2582
|
}
|
2583
2583
|
resolve(value) {
|
2584
|
-
var
|
2584
|
+
var _a14;
|
2585
2585
|
this.status = { type: "resolved", value };
|
2586
2586
|
if (this.promise) {
|
2587
|
-
(
|
2587
|
+
(_a14 = this._resolve) == null ? void 0 : _a14.call(this, value);
|
2588
2588
|
}
|
2589
2589
|
}
|
2590
2590
|
reject(error) {
|
2591
|
-
var
|
2591
|
+
var _a14;
|
2592
2592
|
this.status = { type: "rejected", error };
|
2593
2593
|
if (this.promise) {
|
2594
|
-
(
|
2594
|
+
(_a14 = this._reject) == null ? void 0 : _a14.call(this, error);
|
2595
2595
|
}
|
2596
2596
|
}
|
2597
2597
|
};
|
@@ -2680,8 +2680,8 @@ function createStitchableStream() {
|
|
2680
2680
|
|
2681
2681
|
// core/util/now.ts
|
2682
2682
|
function now() {
|
2683
|
-
var
|
2684
|
-
return (_b = (
|
2683
|
+
var _a14, _b;
|
2684
|
+
return (_b = (_a14 = globalThis == null ? void 0 : globalThis.performance) == null ? void 0 : _a14.now()) != null ? _b : Date.now();
|
2685
2685
|
}
|
2686
2686
|
|
2687
2687
|
// core/generate-object/stream-object.ts
|
@@ -2970,7 +2970,7 @@ var DefaultStreamObjectResult = class {
|
|
2970
2970
|
const transformedStream = stream.pipeThrough(new TransformStream(transformer)).pipeThrough(
|
2971
2971
|
new TransformStream({
|
2972
2972
|
async transform(chunk, controller) {
|
2973
|
-
var
|
2973
|
+
var _a14, _b, _c;
|
2974
2974
|
if (isFirstChunk) {
|
2975
2975
|
const msToFirstChunk = now2() - startTimestampMs;
|
2976
2976
|
isFirstChunk = false;
|
@@ -3016,7 +3016,7 @@ var DefaultStreamObjectResult = class {
|
|
3016
3016
|
switch (chunk.type) {
|
3017
3017
|
case "response-metadata": {
|
3018
3018
|
response = {
|
3019
|
-
id: (
|
3019
|
+
id: (_a14 = chunk.id) != null ? _a14 : response.id,
|
3020
3020
|
timestamp: (_b = chunk.timestamp) != null ? _b : response.timestamp,
|
3021
3021
|
modelId: (_c = chunk.modelId) != null ? _c : response.modelId
|
3022
3022
|
};
|
@@ -3230,9 +3230,9 @@ var DefaultStreamObjectResult = class {
|
|
3230
3230
|
});
|
3231
3231
|
}
|
3232
3232
|
toTextStreamResponse(init) {
|
3233
|
-
var
|
3233
|
+
var _a14;
|
3234
3234
|
return new Response(this.textStream.pipeThrough(new TextEncoderStream()), {
|
3235
|
-
status: (
|
3235
|
+
status: (_a14 = init == null ? void 0 : init.status) != null ? _a14 : 200,
|
3236
3236
|
headers: prepareResponseHeaders(init == null ? void 0 : init.headers, {
|
3237
3237
|
contentType: "text/plain; charset=utf-8"
|
3238
3238
|
})
|
@@ -3243,40 +3243,17 @@ var DefaultStreamObjectResult = class {
|
|
3243
3243
|
// core/generate-text/generate-text.ts
|
3244
3244
|
import { createIdGenerator as createIdGenerator3 } from "@ai-sdk/provider-utils";
|
3245
3245
|
|
3246
|
-
// errors/
|
3247
|
-
import {
|
3248
|
-
|
3249
|
-
APICallError as APICallError2,
|
3250
|
-
EmptyResponseBodyError,
|
3251
|
-
InvalidPromptError as InvalidPromptError2,
|
3252
|
-
InvalidResponseDataError,
|
3253
|
-
JSONParseError,
|
3254
|
-
LoadAPIKeyError,
|
3255
|
-
NoContentGeneratedError,
|
3256
|
-
NoSuchModelError,
|
3257
|
-
TypeValidationError as TypeValidationError2,
|
3258
|
-
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
3259
|
-
} from "@ai-sdk/provider";
|
3260
|
-
|
3261
|
-
// errors/invalid-tool-arguments-error.ts
|
3262
|
-
import { AISDKError as AISDKError8, getErrorMessage as getErrorMessage2 } from "@ai-sdk/provider";
|
3263
|
-
var name8 = "AI_InvalidToolArgumentsError";
|
3246
|
+
// errors/no-output-specified-error.ts
|
3247
|
+
import { AISDKError as AISDKError8 } from "@ai-sdk/provider";
|
3248
|
+
var name8 = "AI_NoOutputSpecifiedError";
|
3264
3249
|
var marker8 = `vercel.ai.error.${name8}`;
|
3265
3250
|
var symbol8 = Symbol.for(marker8);
|
3266
3251
|
var _a8;
|
3267
|
-
var
|
3268
|
-
|
3269
|
-
|
3270
|
-
|
3271
|
-
cause,
|
3272
|
-
message = `Invalid arguments for tool ${toolName}: ${getErrorMessage2(
|
3273
|
-
cause
|
3274
|
-
)}`
|
3275
|
-
}) {
|
3276
|
-
super({ name: name8, message, cause });
|
3252
|
+
var NoOutputSpecifiedError = class extends AISDKError8 {
|
3253
|
+
// used in isInstance
|
3254
|
+
constructor({ message = "No output specified." } = {}) {
|
3255
|
+
super({ name: name8, message });
|
3277
3256
|
this[_a8] = true;
|
3278
|
-
this.toolArgs = toolArgs;
|
3279
|
-
this.toolName = toolName;
|
3280
3257
|
}
|
3281
3258
|
static isInstance(error) {
|
3282
3259
|
return AISDKError8.hasMarker(error, marker8);
|
@@ -3284,74 +3261,29 @@ var InvalidToolArgumentsError = class extends AISDKError8 {
|
|
3284
3261
|
};
|
3285
3262
|
_a8 = symbol8;
|
3286
3263
|
|
3287
|
-
// errors/
|
3288
|
-
import { AISDKError as AISDKError9 } from "@ai-sdk/provider";
|
3289
|
-
var name9 = "
|
3264
|
+
// errors/tool-execution-error.ts
|
3265
|
+
import { AISDKError as AISDKError9, getErrorMessage as getErrorMessage2 } from "@ai-sdk/provider";
|
3266
|
+
var name9 = "AI_ToolExecutionError";
|
3290
3267
|
var marker9 = `vercel.ai.error.${name9}`;
|
3291
3268
|
var symbol9 = Symbol.for(marker9);
|
3292
3269
|
var _a9;
|
3293
|
-
var
|
3294
|
-
constructor({
|
3295
|
-
toolName,
|
3296
|
-
availableTools = void 0,
|
3297
|
-
message = `Model tried to call unavailable tool '${toolName}'. ${availableTools === void 0 ? "No tools are available." : `Available tools: ${availableTools.join(", ")}.`}`
|
3298
|
-
}) {
|
3299
|
-
super({ name: name9, message });
|
3300
|
-
this[_a9] = true;
|
3301
|
-
this.toolName = toolName;
|
3302
|
-
this.availableTools = availableTools;
|
3303
|
-
}
|
3304
|
-
static isInstance(error) {
|
3305
|
-
return AISDKError9.hasMarker(error, marker9);
|
3306
|
-
}
|
3307
|
-
};
|
3308
|
-
_a9 = symbol9;
|
3309
|
-
|
3310
|
-
// errors/tool-call-repair-error.ts
|
3311
|
-
import { AISDKError as AISDKError10, getErrorMessage as getErrorMessage3 } from "@ai-sdk/provider";
|
3312
|
-
var name10 = "AI_ToolCallRepairError";
|
3313
|
-
var marker10 = `vercel.ai.error.${name10}`;
|
3314
|
-
var symbol10 = Symbol.for(marker10);
|
3315
|
-
var _a10;
|
3316
|
-
var ToolCallRepairError = class extends AISDKError10 {
|
3317
|
-
constructor({
|
3318
|
-
cause,
|
3319
|
-
originalError,
|
3320
|
-
message = `Error repairing tool call: ${getErrorMessage3(cause)}`
|
3321
|
-
}) {
|
3322
|
-
super({ name: name10, message, cause });
|
3323
|
-
this[_a10] = true;
|
3324
|
-
this.originalError = originalError;
|
3325
|
-
}
|
3326
|
-
static isInstance(error) {
|
3327
|
-
return AISDKError10.hasMarker(error, marker10);
|
3328
|
-
}
|
3329
|
-
};
|
3330
|
-
_a10 = symbol10;
|
3331
|
-
|
3332
|
-
// errors/tool-execution-error.ts
|
3333
|
-
import { AISDKError as AISDKError11, getErrorMessage as getErrorMessage4 } from "@ai-sdk/provider";
|
3334
|
-
var name11 = "AI_ToolExecutionError";
|
3335
|
-
var marker11 = `vercel.ai.error.${name11}`;
|
3336
|
-
var symbol11 = Symbol.for(marker11);
|
3337
|
-
var _a11;
|
3338
|
-
var ToolExecutionError = class extends AISDKError11 {
|
3270
|
+
var ToolExecutionError = class extends AISDKError9 {
|
3339
3271
|
constructor({
|
3340
3272
|
toolArgs,
|
3341
3273
|
toolName,
|
3342
3274
|
cause,
|
3343
|
-
message = `Error executing tool ${toolName}: ${
|
3275
|
+
message = `Error executing tool ${toolName}: ${getErrorMessage2(cause)}`
|
3344
3276
|
}) {
|
3345
|
-
super({ name:
|
3346
|
-
this[
|
3277
|
+
super({ name: name9, message, cause });
|
3278
|
+
this[_a9] = true;
|
3347
3279
|
this.toolArgs = toolArgs;
|
3348
3280
|
this.toolName = toolName;
|
3349
3281
|
}
|
3350
3282
|
static isInstance(error) {
|
3351
|
-
return
|
3283
|
+
return AISDKError9.hasMarker(error, marker9);
|
3352
3284
|
}
|
3353
3285
|
};
|
3354
|
-
|
3286
|
+
_a9 = symbol9;
|
3355
3287
|
|
3356
3288
|
// core/prompt/prepare-tools-and-tool-choice.ts
|
3357
3289
|
import { asSchema as asSchema2 } from "@ai-sdk/ui-utils";
|
@@ -3374,24 +3306,24 @@ function prepareToolsAndToolChoice({
|
|
3374
3306
|
};
|
3375
3307
|
}
|
3376
3308
|
const filteredTools = activeTools != null ? Object.entries(tools).filter(
|
3377
|
-
([
|
3309
|
+
([name14]) => activeTools.includes(name14)
|
3378
3310
|
) : Object.entries(tools);
|
3379
3311
|
return {
|
3380
|
-
tools: filteredTools.map(([
|
3312
|
+
tools: filteredTools.map(([name14, tool2]) => {
|
3381
3313
|
const toolType = tool2.type;
|
3382
3314
|
switch (toolType) {
|
3383
3315
|
case void 0:
|
3384
3316
|
case "function":
|
3385
3317
|
return {
|
3386
3318
|
type: "function",
|
3387
|
-
name:
|
3319
|
+
name: name14,
|
3388
3320
|
description: tool2.description,
|
3389
3321
|
parameters: asSchema2(tool2.parameters).jsonSchema
|
3390
3322
|
};
|
3391
3323
|
case "provider-defined":
|
3392
3324
|
return {
|
3393
3325
|
type: "provider-defined",
|
3394
|
-
name:
|
3326
|
+
name: name14,
|
3395
3327
|
id: tool2.id,
|
3396
3328
|
args: tool2.args
|
3397
3329
|
};
|
@@ -3421,6 +3353,79 @@ function removeTextAfterLastWhitespace(text2) {
|
|
3421
3353
|
// core/generate-text/parse-tool-call.ts
|
3422
3354
|
import { safeParseJSON as safeParseJSON2, safeValidateTypes as safeValidateTypes3 } from "@ai-sdk/provider-utils";
|
3423
3355
|
import { asSchema as asSchema3 } from "@ai-sdk/ui-utils";
|
3356
|
+
|
3357
|
+
// errors/invalid-tool-arguments-error.ts
|
3358
|
+
import { AISDKError as AISDKError10, getErrorMessage as getErrorMessage3 } from "@ai-sdk/provider";
|
3359
|
+
var name10 = "AI_InvalidToolArgumentsError";
|
3360
|
+
var marker10 = `vercel.ai.error.${name10}`;
|
3361
|
+
var symbol10 = Symbol.for(marker10);
|
3362
|
+
var _a10;
|
3363
|
+
var InvalidToolArgumentsError = class extends AISDKError10 {
|
3364
|
+
constructor({
|
3365
|
+
toolArgs,
|
3366
|
+
toolName,
|
3367
|
+
cause,
|
3368
|
+
message = `Invalid arguments for tool ${toolName}: ${getErrorMessage3(
|
3369
|
+
cause
|
3370
|
+
)}`
|
3371
|
+
}) {
|
3372
|
+
super({ name: name10, message, cause });
|
3373
|
+
this[_a10] = true;
|
3374
|
+
this.toolArgs = toolArgs;
|
3375
|
+
this.toolName = toolName;
|
3376
|
+
}
|
3377
|
+
static isInstance(error) {
|
3378
|
+
return AISDKError10.hasMarker(error, marker10);
|
3379
|
+
}
|
3380
|
+
};
|
3381
|
+
_a10 = symbol10;
|
3382
|
+
|
3383
|
+
// errors/no-such-tool-error.ts
|
3384
|
+
import { AISDKError as AISDKError11 } from "@ai-sdk/provider";
|
3385
|
+
var name11 = "AI_NoSuchToolError";
|
3386
|
+
var marker11 = `vercel.ai.error.${name11}`;
|
3387
|
+
var symbol11 = Symbol.for(marker11);
|
3388
|
+
var _a11;
|
3389
|
+
var NoSuchToolError = class extends AISDKError11 {
|
3390
|
+
constructor({
|
3391
|
+
toolName,
|
3392
|
+
availableTools = void 0,
|
3393
|
+
message = `Model tried to call unavailable tool '${toolName}'. ${availableTools === void 0 ? "No tools are available." : `Available tools: ${availableTools.join(", ")}.`}`
|
3394
|
+
}) {
|
3395
|
+
super({ name: name11, message });
|
3396
|
+
this[_a11] = true;
|
3397
|
+
this.toolName = toolName;
|
3398
|
+
this.availableTools = availableTools;
|
3399
|
+
}
|
3400
|
+
static isInstance(error) {
|
3401
|
+
return AISDKError11.hasMarker(error, marker11);
|
3402
|
+
}
|
3403
|
+
};
|
3404
|
+
_a11 = symbol11;
|
3405
|
+
|
3406
|
+
// errors/tool-call-repair-error.ts
|
3407
|
+
import { AISDKError as AISDKError12, getErrorMessage as getErrorMessage4 } from "@ai-sdk/provider";
|
3408
|
+
var name12 = "AI_ToolCallRepairError";
|
3409
|
+
var marker12 = `vercel.ai.error.${name12}`;
|
3410
|
+
var symbol12 = Symbol.for(marker12);
|
3411
|
+
var _a12;
|
3412
|
+
var ToolCallRepairError = class extends AISDKError12 {
|
3413
|
+
constructor({
|
3414
|
+
cause,
|
3415
|
+
originalError,
|
3416
|
+
message = `Error repairing tool call: ${getErrorMessage4(cause)}`
|
3417
|
+
}) {
|
3418
|
+
super({ name: name12, message, cause });
|
3419
|
+
this[_a12] = true;
|
3420
|
+
this.originalError = originalError;
|
3421
|
+
}
|
3422
|
+
static isInstance(error) {
|
3423
|
+
return AISDKError12.hasMarker(error, marker12);
|
3424
|
+
}
|
3425
|
+
};
|
3426
|
+
_a12 = symbol12;
|
3427
|
+
|
3428
|
+
// core/generate-text/parse-tool-call.ts
|
3424
3429
|
async function parseToolCall({
|
3425
3430
|
toolCall,
|
3426
3431
|
tools,
|
@@ -3551,7 +3556,7 @@ async function generateText({
|
|
3551
3556
|
onStepFinish,
|
3552
3557
|
...settings
|
3553
3558
|
}) {
|
3554
|
-
var
|
3559
|
+
var _a14;
|
3555
3560
|
if (maxSteps < 1) {
|
3556
3561
|
throw new InvalidArgumentError({
|
3557
3562
|
parameter: "maxSteps",
|
@@ -3568,7 +3573,7 @@ async function generateText({
|
|
3568
3573
|
});
|
3569
3574
|
const initialPrompt = standardizePrompt({
|
3570
3575
|
prompt: {
|
3571
|
-
system: (
|
3576
|
+
system: (_a14 = output == null ? void 0 : output.injectIntoSystemPrompt({ system, model })) != null ? _a14 : system,
|
3572
3577
|
prompt,
|
3573
3578
|
messages
|
3574
3579
|
},
|
@@ -3594,7 +3599,7 @@ async function generateText({
|
|
3594
3599
|
}),
|
3595
3600
|
tracer,
|
3596
3601
|
fn: async (span) => {
|
3597
|
-
var
|
3602
|
+
var _a15, _b, _c, _d, _e, _f;
|
3598
3603
|
const mode = {
|
3599
3604
|
type: "regular",
|
3600
3605
|
...prepareToolsAndToolChoice({ tools, toolChoice, activeTools })
|
@@ -3646,8 +3651,8 @@ async function generateText({
|
|
3646
3651
|
"ai.prompt.tools": {
|
3647
3652
|
// convert the language model level tools:
|
3648
3653
|
input: () => {
|
3649
|
-
var
|
3650
|
-
return (
|
3654
|
+
var _a16;
|
3655
|
+
return (_a16 = mode.tools) == null ? void 0 : _a16.map((tool2) => JSON.stringify(tool2));
|
3651
3656
|
}
|
3652
3657
|
},
|
3653
3658
|
"ai.prompt.toolChoice": {
|
@@ -3667,7 +3672,7 @@ async function generateText({
|
|
3667
3672
|
}),
|
3668
3673
|
tracer,
|
3669
3674
|
fn: async (span2) => {
|
3670
|
-
var
|
3675
|
+
var _a16, _b2, _c2, _d2, _e2, _f2;
|
3671
3676
|
const result = await model.doGenerate({
|
3672
3677
|
mode,
|
3673
3678
|
...callSettings,
|
@@ -3679,7 +3684,7 @@ async function generateText({
|
|
3679
3684
|
headers
|
3680
3685
|
});
|
3681
3686
|
const responseData = {
|
3682
|
-
id: (_b2 = (
|
3687
|
+
id: (_b2 = (_a16 = result.response) == null ? void 0 : _a16.id) != null ? _b2 : generateId3(),
|
3683
3688
|
timestamp: (_d2 = (_c2 = result.response) == null ? void 0 : _c2.timestamp) != null ? _d2 : currentDate(),
|
3684
3689
|
modelId: (_f2 = (_e2 = result.response) == null ? void 0 : _e2.modelId) != null ? _f2 : model.modelId
|
3685
3690
|
};
|
@@ -3713,7 +3718,7 @@ async function generateText({
|
|
3713
3718
|
})
|
3714
3719
|
);
|
3715
3720
|
currentToolCalls = await Promise.all(
|
3716
|
-
((
|
3721
|
+
((_a15 = currentModelResponse.toolCalls) != null ? _a15 : []).map(
|
3717
3722
|
(toolCall) => parseToolCall({
|
3718
3723
|
toolCall,
|
3719
3724
|
tools,
|
@@ -3814,13 +3819,15 @@ async function generateText({
|
|
3814
3819
|
);
|
3815
3820
|
return new DefaultGenerateTextResult({
|
3816
3821
|
text: text2,
|
3817
|
-
|
3818
|
-
|
3819
|
-
|
3820
|
-
response: currentModelResponse.response,
|
3821
|
-
usage
|
3822
|
+
outputResolver: () => {
|
3823
|
+
if (output == null) {
|
3824
|
+
throw new NoOutputSpecifiedError();
|
3822
3825
|
}
|
3823
|
-
|
3826
|
+
return output.parseOutput(
|
3827
|
+
{ text: text2 },
|
3828
|
+
{ response: currentModelResponse.response, usage }
|
3829
|
+
);
|
3830
|
+
},
|
3824
3831
|
toolCalls: currentToolCalls,
|
3825
3832
|
toolResults: currentToolResults,
|
3826
3833
|
finishReason: currentModelResponse.finishReason,
|
@@ -3926,7 +3933,10 @@ var DefaultGenerateTextResult = class {
|
|
3926
3933
|
this.steps = options.steps;
|
3927
3934
|
this.experimental_providerMetadata = options.providerMetadata;
|
3928
3935
|
this.logprobs = options.logprobs;
|
3929
|
-
this.
|
3936
|
+
this.outputResolver = options.outputResolver;
|
3937
|
+
}
|
3938
|
+
get experimental_output() {
|
3939
|
+
return this.outputResolver();
|
3930
3940
|
}
|
3931
3941
|
};
|
3932
3942
|
|
@@ -3937,13 +3947,36 @@ __export(output_exports, {
|
|
3937
3947
|
text: () => text
|
3938
3948
|
});
|
3939
3949
|
import { safeParseJSON as safeParseJSON3, safeValidateTypes as safeValidateTypes4 } from "@ai-sdk/provider-utils";
|
3940
|
-
import {
|
3950
|
+
import {
|
3951
|
+
asSchema as asSchema4,
|
3952
|
+
parsePartialJson as parsePartialJson2
|
3953
|
+
} from "@ai-sdk/ui-utils";
|
3954
|
+
|
3955
|
+
// errors/index.ts
|
3956
|
+
import {
|
3957
|
+
AISDKError as AISDKError13,
|
3958
|
+
APICallError as APICallError2,
|
3959
|
+
EmptyResponseBodyError,
|
3960
|
+
InvalidPromptError as InvalidPromptError2,
|
3961
|
+
InvalidResponseDataError,
|
3962
|
+
JSONParseError,
|
3963
|
+
LoadAPIKeyError,
|
3964
|
+
NoContentGeneratedError,
|
3965
|
+
NoSuchModelError,
|
3966
|
+
TypeValidationError as TypeValidationError2,
|
3967
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
3968
|
+
} from "@ai-sdk/provider";
|
3969
|
+
|
3970
|
+
// core/generate-text/output.ts
|
3941
3971
|
var text = () => ({
|
3942
3972
|
type: "text",
|
3943
3973
|
responseFormat: () => ({ type: "text" }),
|
3944
3974
|
injectIntoSystemPrompt({ system }) {
|
3945
3975
|
return system;
|
3946
3976
|
},
|
3977
|
+
parsePartial({ text: text2 }) {
|
3978
|
+
return { partial: text2 };
|
3979
|
+
},
|
3947
3980
|
parseOutput({ text: text2 }) {
|
3948
3981
|
return text2;
|
3949
3982
|
}
|
@@ -3964,6 +3997,24 @@ var object = ({
|
|
3964
3997
|
schema: schema.jsonSchema
|
3965
3998
|
});
|
3966
3999
|
},
|
4000
|
+
parsePartial({ text: text2 }) {
|
4001
|
+
const result = parsePartialJson2(text2);
|
4002
|
+
switch (result.state) {
|
4003
|
+
case "failed-parse":
|
4004
|
+
case "undefined-input":
|
4005
|
+
return void 0;
|
4006
|
+
case "repaired-parse":
|
4007
|
+
case "successful-parse":
|
4008
|
+
return {
|
4009
|
+
// Note: currently no validation of partial results:
|
4010
|
+
partial: result.value
|
4011
|
+
};
|
4012
|
+
default: {
|
4013
|
+
const _exhaustiveCheck = result.state;
|
4014
|
+
throw new Error(`Unsupported parse state: ${_exhaustiveCheck}`);
|
4015
|
+
}
|
4016
|
+
}
|
4017
|
+
},
|
3967
4018
|
parseOutput({ text: text2 }, context) {
|
3968
4019
|
const parseResult = safeParseJSON3({ text: text2 });
|
3969
4020
|
if (!parseResult.success) {
|
@@ -4287,6 +4338,7 @@ function streamText({
|
|
4287
4338
|
abortSignal,
|
4288
4339
|
headers,
|
4289
4340
|
maxSteps = 1,
|
4341
|
+
experimental_output: output,
|
4290
4342
|
experimental_continueSteps: continueSteps = false,
|
4291
4343
|
experimental_telemetry: telemetry,
|
4292
4344
|
experimental_providerMetadata: providerMetadata,
|
@@ -4321,6 +4373,7 @@ function streamText({
|
|
4321
4373
|
activeTools,
|
4322
4374
|
repairToolCall,
|
4323
4375
|
maxSteps,
|
4376
|
+
output,
|
4324
4377
|
continueSteps,
|
4325
4378
|
providerMetadata,
|
4326
4379
|
onChunk,
|
@@ -4331,6 +4384,57 @@ function streamText({
|
|
4331
4384
|
generateId: generateId3
|
4332
4385
|
});
|
4333
4386
|
}
|
4387
|
+
function createOutputTransformStream(output) {
|
4388
|
+
if (!output) {
|
4389
|
+
return new TransformStream({
|
4390
|
+
transform(chunk, controller) {
|
4391
|
+
controller.enqueue({ part: chunk, partialOutput: void 0 });
|
4392
|
+
}
|
4393
|
+
});
|
4394
|
+
}
|
4395
|
+
let text2 = "";
|
4396
|
+
let textChunk = "";
|
4397
|
+
let lastPublishedJson = "";
|
4398
|
+
return new TransformStream({
|
4399
|
+
transform(chunk, controller) {
|
4400
|
+
if (chunk.type !== "text-delta") {
|
4401
|
+
controller.enqueue({
|
4402
|
+
part: chunk,
|
4403
|
+
partialOutput: void 0
|
4404
|
+
});
|
4405
|
+
return;
|
4406
|
+
}
|
4407
|
+
text2 += chunk.textDelta;
|
4408
|
+
textChunk += chunk.textDelta;
|
4409
|
+
const result = output.parsePartial({ text: text2 });
|
4410
|
+
if (result != null) {
|
4411
|
+
const currentJson = JSON.stringify(result.partial);
|
4412
|
+
if (currentJson !== lastPublishedJson) {
|
4413
|
+
controller.enqueue({
|
4414
|
+
part: {
|
4415
|
+
type: "text-delta",
|
4416
|
+
textDelta: textChunk
|
4417
|
+
},
|
4418
|
+
partialOutput: result.partial
|
4419
|
+
});
|
4420
|
+
lastPublishedJson = currentJson;
|
4421
|
+
textChunk = "";
|
4422
|
+
}
|
4423
|
+
}
|
4424
|
+
},
|
4425
|
+
flush(controller) {
|
4426
|
+
if (textChunk.length > 0) {
|
4427
|
+
controller.enqueue({
|
4428
|
+
part: {
|
4429
|
+
type: "text-delta",
|
4430
|
+
textDelta: textChunk
|
4431
|
+
},
|
4432
|
+
partialOutput: void 0
|
4433
|
+
});
|
4434
|
+
}
|
4435
|
+
}
|
4436
|
+
});
|
4437
|
+
}
|
4334
4438
|
var DefaultStreamTextResult = class {
|
4335
4439
|
constructor({
|
4336
4440
|
model,
|
@@ -4349,6 +4453,7 @@ var DefaultStreamTextResult = class {
|
|
4349
4453
|
activeTools,
|
4350
4454
|
repairToolCall,
|
4351
4455
|
maxSteps,
|
4456
|
+
output,
|
4352
4457
|
continueSteps,
|
4353
4458
|
providerMetadata,
|
4354
4459
|
onChunk,
|
@@ -4368,6 +4473,7 @@ var DefaultStreamTextResult = class {
|
|
4368
4473
|
this.requestPromise = new DelayedPromise();
|
4369
4474
|
this.responsePromise = new DelayedPromise();
|
4370
4475
|
this.stepsPromise = new DelayedPromise();
|
4476
|
+
var _a14;
|
4371
4477
|
if (maxSteps < 1) {
|
4372
4478
|
throw new InvalidArgumentError({
|
4373
4479
|
parameter: "maxSteps",
|
@@ -4375,10 +4481,10 @@ var DefaultStreamTextResult = class {
|
|
4375
4481
|
message: "maxSteps must be at least 1"
|
4376
4482
|
});
|
4377
4483
|
}
|
4484
|
+
this.output = output;
|
4378
4485
|
let recordedStepText = "";
|
4379
4486
|
let recordedContinuationText = "";
|
4380
4487
|
let recordedFullText = "";
|
4381
|
-
let recordedRequest = void 0;
|
4382
4488
|
const recordedResponse = {
|
4383
4489
|
id: generateId3(),
|
4384
4490
|
timestamp: currentDate(),
|
@@ -4389,28 +4495,28 @@ var DefaultStreamTextResult = class {
|
|
4389
4495
|
let recordedToolResults = [];
|
4390
4496
|
let recordedFinishReason = void 0;
|
4391
4497
|
let recordedUsage = void 0;
|
4392
|
-
let recordedProviderMetadata = void 0;
|
4393
4498
|
let stepType = "initial";
|
4394
4499
|
const recordedSteps = [];
|
4395
4500
|
let rootSpan;
|
4396
4501
|
const eventProcessor = new TransformStream({
|
4397
4502
|
async transform(chunk, controller) {
|
4398
4503
|
controller.enqueue(chunk);
|
4399
|
-
|
4400
|
-
|
4504
|
+
const { part } = chunk;
|
4505
|
+
if (part.type === "text-delta" || part.type === "tool-call" || part.type === "tool-result" || part.type === "tool-call-streaming-start" || part.type === "tool-call-delta") {
|
4506
|
+
await (onChunk == null ? void 0 : onChunk({ chunk: part }));
|
4401
4507
|
}
|
4402
|
-
if (
|
4403
|
-
recordedStepText +=
|
4404
|
-
recordedContinuationText +=
|
4405
|
-
recordedFullText +=
|
4508
|
+
if (part.type === "text-delta") {
|
4509
|
+
recordedStepText += part.textDelta;
|
4510
|
+
recordedContinuationText += part.textDelta;
|
4511
|
+
recordedFullText += part.textDelta;
|
4406
4512
|
}
|
4407
|
-
if (
|
4408
|
-
recordedToolCalls.push(
|
4513
|
+
if (part.type === "tool-call") {
|
4514
|
+
recordedToolCalls.push(part);
|
4409
4515
|
}
|
4410
|
-
if (
|
4411
|
-
recordedToolResults.push(
|
4516
|
+
if (part.type === "tool-result") {
|
4517
|
+
recordedToolResults.push(part);
|
4412
4518
|
}
|
4413
|
-
if (
|
4519
|
+
if (part.type === "step-finish") {
|
4414
4520
|
const stepMessages = toResponseMessages({
|
4415
4521
|
text: recordedContinuationText,
|
4416
4522
|
tools: tools != null ? tools : {},
|
@@ -4420,7 +4526,7 @@ var DefaultStreamTextResult = class {
|
|
4420
4526
|
const currentStep = recordedSteps.length;
|
4421
4527
|
let nextStepType = "done";
|
4422
4528
|
if (currentStep + 1 < maxSteps) {
|
4423
|
-
if (continueSteps &&
|
4529
|
+
if (continueSteps && part.finishReason === "length" && // only use continue when there are no tool calls:
|
4424
4530
|
recordedToolCalls.length === 0) {
|
4425
4531
|
nextStepType = "continue";
|
4426
4532
|
} else if (
|
@@ -4436,24 +4542,23 @@ var DefaultStreamTextResult = class {
|
|
4436
4542
|
text: recordedStepText,
|
4437
4543
|
toolCalls: recordedToolCalls,
|
4438
4544
|
toolResults: recordedToolResults,
|
4439
|
-
finishReason:
|
4440
|
-
usage:
|
4441
|
-
warnings:
|
4442
|
-
logprobs:
|
4443
|
-
request:
|
4545
|
+
finishReason: part.finishReason,
|
4546
|
+
usage: part.usage,
|
4547
|
+
warnings: part.warnings,
|
4548
|
+
logprobs: part.logprobs,
|
4549
|
+
request: part.request,
|
4444
4550
|
response: {
|
4445
|
-
...
|
4551
|
+
...part.response,
|
4446
4552
|
messages: [...recordedResponse.messages, ...stepMessages]
|
4447
4553
|
},
|
4448
|
-
experimental_providerMetadata:
|
4449
|
-
isContinued:
|
4554
|
+
experimental_providerMetadata: part.experimental_providerMetadata,
|
4555
|
+
isContinued: part.isContinued
|
4450
4556
|
};
|
4451
4557
|
await (onStepFinish == null ? void 0 : onStepFinish(currentStepResult));
|
4452
4558
|
recordedSteps.push(currentStepResult);
|
4453
4559
|
recordedToolCalls = [];
|
4454
4560
|
recordedToolResults = [];
|
4455
4561
|
recordedStepText = "";
|
4456
|
-
recordedRequest = chunk.request;
|
4457
4562
|
if (nextStepType !== "done") {
|
4458
4563
|
stepType = nextStepType;
|
4459
4564
|
}
|
@@ -4462,18 +4567,17 @@ var DefaultStreamTextResult = class {
|
|
4462
4567
|
recordedContinuationText = "";
|
4463
4568
|
}
|
4464
4569
|
}
|
4465
|
-
if (
|
4466
|
-
recordedResponse.id =
|
4467
|
-
recordedResponse.timestamp =
|
4468
|
-
recordedResponse.modelId =
|
4469
|
-
recordedResponse.headers =
|
4470
|
-
recordedUsage =
|
4471
|
-
recordedFinishReason =
|
4472
|
-
recordedProviderMetadata = chunk.experimental_providerMetadata;
|
4570
|
+
if (part.type === "finish") {
|
4571
|
+
recordedResponse.id = part.response.id;
|
4572
|
+
recordedResponse.timestamp = part.response.timestamp;
|
4573
|
+
recordedResponse.modelId = part.response.modelId;
|
4574
|
+
recordedResponse.headers = part.response.headers;
|
4575
|
+
recordedUsage = part.usage;
|
4576
|
+
recordedFinishReason = part.finishReason;
|
4473
4577
|
}
|
4474
4578
|
},
|
4475
4579
|
async flush(controller) {
|
4476
|
-
var
|
4580
|
+
var _a15;
|
4477
4581
|
try {
|
4478
4582
|
const lastStep = recordedSteps[recordedSteps.length - 1];
|
4479
4583
|
if (lastStep) {
|
@@ -4503,7 +4607,7 @@ var DefaultStreamTextResult = class {
|
|
4503
4607
|
text: recordedFullText,
|
4504
4608
|
toolCalls: lastStep.toolCalls,
|
4505
4609
|
toolResults: lastStep.toolResults,
|
4506
|
-
request: (
|
4610
|
+
request: (_a15 = lastStep.request) != null ? _a15 : {},
|
4507
4611
|
response: lastStep.response,
|
4508
4612
|
warnings: lastStep.warnings,
|
4509
4613
|
experimental_providerMetadata: lastStep.experimental_providerMetadata,
|
@@ -4517,8 +4621,8 @@ var DefaultStreamTextResult = class {
|
|
4517
4621
|
"ai.response.text": { output: () => recordedFullText },
|
4518
4622
|
"ai.response.toolCalls": {
|
4519
4623
|
output: () => {
|
4520
|
-
var
|
4521
|
-
return ((
|
4624
|
+
var _a16;
|
4625
|
+
return ((_a16 = lastStep.toolCalls) == null ? void 0 : _a16.length) ? JSON.stringify(lastStep.toolCalls) : void 0;
|
4522
4626
|
}
|
4523
4627
|
},
|
4524
4628
|
"ai.usage.promptTokens": usage.promptTokens,
|
@@ -4536,7 +4640,11 @@ var DefaultStreamTextResult = class {
|
|
4536
4640
|
const stitchableStream = createStitchableStream();
|
4537
4641
|
this.addStream = stitchableStream.addStream;
|
4538
4642
|
this.closeStream = stitchableStream.close;
|
4539
|
-
|
4643
|
+
let stream = stitchableStream.stream;
|
4644
|
+
if (transform) {
|
4645
|
+
stream = stream.pipeThrough(transform);
|
4646
|
+
}
|
4647
|
+
this.baseStream = stream.pipeThrough(createOutputTransformStream(output)).pipeThrough(eventProcessor);
|
4540
4648
|
const { maxRetries, retry } = prepareRetries({
|
4541
4649
|
maxRetries: maxRetriesArg
|
4542
4650
|
});
|
@@ -4548,7 +4656,11 @@ var DefaultStreamTextResult = class {
|
|
4548
4656
|
settings: { ...settings, maxRetries }
|
4549
4657
|
});
|
4550
4658
|
const initialPrompt = standardizePrompt({
|
4551
|
-
prompt: {
|
4659
|
+
prompt: {
|
4660
|
+
system: (_a14 = output == null ? void 0 : output.injectIntoSystemPrompt({ system, model })) != null ? _a14 : system,
|
4661
|
+
prompt,
|
4662
|
+
messages
|
4663
|
+
},
|
4552
4664
|
tools
|
4553
4665
|
});
|
4554
4666
|
const self = this;
|
@@ -4597,7 +4709,7 @@ var DefaultStreamTextResult = class {
|
|
4597
4709
|
...prepareToolsAndToolChoice({ tools, toolChoice, activeTools })
|
4598
4710
|
};
|
4599
4711
|
const {
|
4600
|
-
result: { stream, warnings, rawResponse, request },
|
4712
|
+
result: { stream: stream2, warnings, rawResponse, request },
|
4601
4713
|
doStreamSpan,
|
4602
4714
|
startTimestampMs
|
4603
4715
|
} = await retry(
|
@@ -4620,8 +4732,8 @@ var DefaultStreamTextResult = class {
|
|
4620
4732
|
"ai.prompt.tools": {
|
4621
4733
|
// convert the language model level tools:
|
4622
4734
|
input: () => {
|
4623
|
-
var
|
4624
|
-
return (
|
4735
|
+
var _a15;
|
4736
|
+
return (_a15 = mode.tools) == null ? void 0 : _a15.map((tool2) => JSON.stringify(tool2));
|
4625
4737
|
}
|
4626
4738
|
},
|
4627
4739
|
"ai.prompt.toolChoice": {
|
@@ -4649,6 +4761,7 @@ var DefaultStreamTextResult = class {
|
|
4649
4761
|
mode,
|
4650
4762
|
...prepareCallSettings(settings),
|
4651
4763
|
inputFormat: promptFormat,
|
4764
|
+
responseFormat: output == null ? void 0 : output.responseFormat({ model }),
|
4652
4765
|
prompt: promptMessages,
|
4653
4766
|
providerMetadata,
|
4654
4767
|
abortSignal,
|
@@ -4659,7 +4772,7 @@ var DefaultStreamTextResult = class {
|
|
4659
4772
|
);
|
4660
4773
|
const transformedStream = runToolsTransformation({
|
4661
4774
|
tools,
|
4662
|
-
generatorStream:
|
4775
|
+
generatorStream: stream2,
|
4663
4776
|
toolCallStreaming,
|
4664
4777
|
tracer,
|
4665
4778
|
telemetry,
|
@@ -4705,7 +4818,7 @@ var DefaultStreamTextResult = class {
|
|
4705
4818
|
transformedStream.pipeThrough(
|
4706
4819
|
new TransformStream({
|
4707
4820
|
async transform(chunk, controller) {
|
4708
|
-
var
|
4821
|
+
var _a15, _b, _c;
|
4709
4822
|
if (stepFirstChunk) {
|
4710
4823
|
const msToFirstChunk = now2() - startTimestampMs;
|
4711
4824
|
stepFirstChunk = false;
|
@@ -4757,7 +4870,7 @@ var DefaultStreamTextResult = class {
|
|
4757
4870
|
}
|
4758
4871
|
case "response-metadata": {
|
4759
4872
|
stepResponse = {
|
4760
|
-
id: (
|
4873
|
+
id: (_a15 = chunk.id) != null ? _a15 : stepResponse.id,
|
4761
4874
|
timestamp: (_b = chunk.timestamp) != null ? _b : stepResponse.timestamp,
|
4762
4875
|
modelId: (_c = chunk.modelId) != null ? _c : stepResponse.modelId
|
4763
4876
|
};
|
@@ -4982,11 +5095,11 @@ var DefaultStreamTextResult = class {
|
|
4982
5095
|
return createAsyncIterableStream(
|
4983
5096
|
this.teeStream().pipeThrough(
|
4984
5097
|
new TransformStream({
|
4985
|
-
transform(
|
4986
|
-
if (
|
4987
|
-
controller.enqueue(
|
4988
|
-
} else if (
|
4989
|
-
controller.error(
|
5098
|
+
transform({ part }, controller) {
|
5099
|
+
if (part.type === "text-delta") {
|
5100
|
+
controller.enqueue(part.textDelta);
|
5101
|
+
} else if (part.type === "error") {
|
5102
|
+
controller.error(part.error);
|
4990
5103
|
}
|
4991
5104
|
}
|
4992
5105
|
})
|
@@ -4994,7 +5107,31 @@ var DefaultStreamTextResult = class {
|
|
4994
5107
|
);
|
4995
5108
|
}
|
4996
5109
|
get fullStream() {
|
4997
|
-
return createAsyncIterableStream(
|
5110
|
+
return createAsyncIterableStream(
|
5111
|
+
this.teeStream().pipeThrough(
|
5112
|
+
new TransformStream({
|
5113
|
+
transform({ part }, controller) {
|
5114
|
+
controller.enqueue(part);
|
5115
|
+
}
|
5116
|
+
})
|
5117
|
+
)
|
5118
|
+
);
|
5119
|
+
}
|
5120
|
+
get experimental_partialOutputStream() {
|
5121
|
+
if (this.output == null) {
|
5122
|
+
throw new NoOutputSpecifiedError();
|
5123
|
+
}
|
5124
|
+
return createAsyncIterableStream(
|
5125
|
+
this.teeStream().pipeThrough(
|
5126
|
+
new TransformStream({
|
5127
|
+
transform({ partialOutput }, controller) {
|
5128
|
+
if (partialOutput != null) {
|
5129
|
+
controller.enqueue(partialOutput);
|
5130
|
+
}
|
5131
|
+
}
|
5132
|
+
})
|
5133
|
+
)
|
5134
|
+
);
|
4998
5135
|
}
|
4999
5136
|
toDataStreamInternal({
|
5000
5137
|
getErrorMessage: getErrorMessage5 = () => "An error occurred.",
|
@@ -5161,9 +5298,9 @@ var DefaultStreamTextResult = class {
|
|
5161
5298
|
);
|
5162
5299
|
}
|
5163
5300
|
toTextStreamResponse(init) {
|
5164
|
-
var
|
5301
|
+
var _a14;
|
5165
5302
|
return new Response(this.textStream.pipeThrough(new TextEncoderStream()), {
|
5166
|
-
status: (
|
5303
|
+
status: (_a14 = init == null ? void 0 : init.status) != null ? _a14 : 200,
|
5167
5304
|
headers: prepareResponseHeaders(init == null ? void 0 : init.headers, {
|
5168
5305
|
contentType: "text/plain; charset=utf-8"
|
5169
5306
|
})
|
@@ -5269,11 +5406,11 @@ function experimental_customProvider({
|
|
5269
5406
|
}
|
5270
5407
|
|
5271
5408
|
// core/registry/no-such-provider-error.ts
|
5272
|
-
import { AISDKError as
|
5273
|
-
var
|
5274
|
-
var
|
5275
|
-
var
|
5276
|
-
var
|
5409
|
+
import { AISDKError as AISDKError14, NoSuchModelError as NoSuchModelError3 } from "@ai-sdk/provider";
|
5410
|
+
var name13 = "AI_NoSuchProviderError";
|
5411
|
+
var marker13 = `vercel.ai.error.${name13}`;
|
5412
|
+
var symbol13 = Symbol.for(marker13);
|
5413
|
+
var _a13;
|
5277
5414
|
var NoSuchProviderError = class extends NoSuchModelError3 {
|
5278
5415
|
constructor({
|
5279
5416
|
modelId,
|
@@ -5282,16 +5419,16 @@ var NoSuchProviderError = class extends NoSuchModelError3 {
|
|
5282
5419
|
availableProviders,
|
5283
5420
|
message = `No such provider: ${providerId} (available providers: ${availableProviders.join()})`
|
5284
5421
|
}) {
|
5285
|
-
super({ errorName:
|
5286
|
-
this[
|
5422
|
+
super({ errorName: name13, modelId, modelType, message });
|
5423
|
+
this[_a13] = true;
|
5287
5424
|
this.providerId = providerId;
|
5288
5425
|
this.availableProviders = availableProviders;
|
5289
5426
|
}
|
5290
5427
|
static isInstance(error) {
|
5291
|
-
return
|
5428
|
+
return AISDKError14.hasMarker(error, marker13);
|
5292
5429
|
}
|
5293
5430
|
};
|
5294
|
-
|
5431
|
+
_a13 = symbol13;
|
5295
5432
|
|
5296
5433
|
// core/registry/provider-registry.ts
|
5297
5434
|
import { NoSuchModelError as NoSuchModelError4 } from "@ai-sdk/provider";
|
@@ -5333,19 +5470,19 @@ var DefaultProviderRegistry = class {
|
|
5333
5470
|
return [id.slice(0, index), id.slice(index + 1)];
|
5334
5471
|
}
|
5335
5472
|
languageModel(id) {
|
5336
|
-
var
|
5473
|
+
var _a14, _b;
|
5337
5474
|
const [providerId, modelId] = this.splitId(id, "languageModel");
|
5338
|
-
const model = (_b = (
|
5475
|
+
const model = (_b = (_a14 = this.getProvider(providerId)).languageModel) == null ? void 0 : _b.call(_a14, modelId);
|
5339
5476
|
if (model == null) {
|
5340
5477
|
throw new NoSuchModelError4({ modelId: id, modelType: "languageModel" });
|
5341
5478
|
}
|
5342
5479
|
return model;
|
5343
5480
|
}
|
5344
5481
|
textEmbeddingModel(id) {
|
5345
|
-
var
|
5482
|
+
var _a14;
|
5346
5483
|
const [providerId, modelId] = this.splitId(id, "textEmbeddingModel");
|
5347
5484
|
const provider = this.getProvider(providerId);
|
5348
|
-
const model = (
|
5485
|
+
const model = (_a14 = provider.textEmbeddingModel) == null ? void 0 : _a14.call(provider, modelId);
|
5349
5486
|
if (model == null) {
|
5350
5487
|
throw new NoSuchModelError4({
|
5351
5488
|
modelId: id,
|
@@ -5393,7 +5530,7 @@ import {
|
|
5393
5530
|
function AssistantResponse({ threadId, messageId }, process2) {
|
5394
5531
|
const stream = new ReadableStream({
|
5395
5532
|
async start(controller) {
|
5396
|
-
var
|
5533
|
+
var _a14;
|
5397
5534
|
const textEncoder = new TextEncoder();
|
5398
5535
|
const sendMessage = (message) => {
|
5399
5536
|
controller.enqueue(
|
@@ -5415,7 +5552,7 @@ function AssistantResponse({ threadId, messageId }, process2) {
|
|
5415
5552
|
);
|
5416
5553
|
};
|
5417
5554
|
const forwardStream = async (stream2) => {
|
5418
|
-
var
|
5555
|
+
var _a15, _b;
|
5419
5556
|
let result = void 0;
|
5420
5557
|
for await (const value of stream2) {
|
5421
5558
|
switch (value.event) {
|
@@ -5432,7 +5569,7 @@ function AssistantResponse({ threadId, messageId }, process2) {
|
|
5432
5569
|
break;
|
5433
5570
|
}
|
5434
5571
|
case "thread.message.delta": {
|
5435
|
-
const content = (
|
5572
|
+
const content = (_a15 = value.data.delta.content) == null ? void 0 : _a15[0];
|
5436
5573
|
if ((content == null ? void 0 : content.type) === "text" && ((_b = content.text) == null ? void 0 : _b.value) != null) {
|
5437
5574
|
controller.enqueue(
|
5438
5575
|
textEncoder.encode(
|
@@ -5466,7 +5603,7 @@ function AssistantResponse({ threadId, messageId }, process2) {
|
|
5466
5603
|
forwardStream
|
5467
5604
|
});
|
5468
5605
|
} catch (error) {
|
5469
|
-
sendError((
|
5606
|
+
sendError((_a14 = error.message) != null ? _a14 : `${error}`);
|
5470
5607
|
} finally {
|
5471
5608
|
controller.close();
|
5472
5609
|
}
|
@@ -5527,7 +5664,7 @@ function toDataStreamInternal(stream, callbacks) {
|
|
5527
5664
|
return stream.pipeThrough(
|
5528
5665
|
new TransformStream({
|
5529
5666
|
transform: async (value, controller) => {
|
5530
|
-
var
|
5667
|
+
var _a14;
|
5531
5668
|
if (typeof value === "string") {
|
5532
5669
|
controller.enqueue(value);
|
5533
5670
|
return;
|
@@ -5535,7 +5672,7 @@ function toDataStreamInternal(stream, callbacks) {
|
|
5535
5672
|
if ("event" in value) {
|
5536
5673
|
if (value.event === "on_chat_model_stream") {
|
5537
5674
|
forwardAIMessageChunk(
|
5538
|
-
(
|
5675
|
+
(_a14 = value.data) == null ? void 0 : _a14.chunk,
|
5539
5676
|
controller
|
5540
5677
|
);
|
5541
5678
|
}
|
@@ -5558,7 +5695,7 @@ function toDataStream(stream, callbacks) {
|
|
5558
5695
|
);
|
5559
5696
|
}
|
5560
5697
|
function toDataStreamResponse(stream, options) {
|
5561
|
-
var
|
5698
|
+
var _a14;
|
5562
5699
|
const dataStream = toDataStreamInternal(
|
5563
5700
|
stream,
|
5564
5701
|
options == null ? void 0 : options.callbacks
|
@@ -5567,7 +5704,7 @@ function toDataStreamResponse(stream, options) {
|
|
5567
5704
|
const init = options == null ? void 0 : options.init;
|
5568
5705
|
const responseStream = data ? mergeStreams(data.stream, dataStream) : dataStream;
|
5569
5706
|
return new Response(responseStream, {
|
5570
|
-
status: (
|
5707
|
+
status: (_a14 = init == null ? void 0 : init.status) != null ? _a14 : 200,
|
5571
5708
|
statusText: init == null ? void 0 : init.statusText,
|
5572
5709
|
headers: prepareResponseHeaders(init == null ? void 0 : init.headers, {
|
5573
5710
|
contentType: "text/plain; charset=utf-8",
|
@@ -5622,14 +5759,14 @@ function toDataStream2(stream, callbacks) {
|
|
5622
5759
|
);
|
5623
5760
|
}
|
5624
5761
|
function toDataStreamResponse2(stream, options = {}) {
|
5625
|
-
var
|
5762
|
+
var _a14;
|
5626
5763
|
const { init, data, callbacks } = options;
|
5627
5764
|
const dataStream = toDataStreamInternal2(stream, callbacks).pipeThrough(
|
5628
5765
|
new TextEncoderStream()
|
5629
5766
|
);
|
5630
5767
|
const responseStream = data ? mergeStreams(data.stream, dataStream) : dataStream;
|
5631
5768
|
return new Response(responseStream, {
|
5632
|
-
status: (
|
5769
|
+
status: (_a14 = init == null ? void 0 : init.status) != null ? _a14 : 200,
|
5633
5770
|
statusText: init == null ? void 0 : init.statusText,
|
5634
5771
|
headers: prepareResponseHeaders(init == null ? void 0 : init.headers, {
|
5635
5772
|
contentType: "text/plain; charset=utf-8",
|
@@ -5721,7 +5858,7 @@ var StreamData = class {
|
|
5721
5858
|
}
|
5722
5859
|
};
|
5723
5860
|
export {
|
5724
|
-
|
5861
|
+
AISDKError13 as AISDKError,
|
5725
5862
|
APICallError2 as APICallError,
|
5726
5863
|
AssistantResponse,
|
5727
5864
|
DownloadError,
|
@@ -5739,6 +5876,7 @@ export {
|
|
5739
5876
|
MessageConversionError,
|
5740
5877
|
NoContentGeneratedError,
|
5741
5878
|
NoObjectGeneratedError,
|
5879
|
+
NoOutputSpecifiedError,
|
5742
5880
|
NoSuchModelError,
|
5743
5881
|
NoSuchProviderError,
|
5744
5882
|
NoSuchToolError,
|