ai 5.0.0-alpha.12 → 5.0.0-alpha.14
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 +32 -0
- package/dist/index.d.mts +177 -175
- package/dist/index.d.ts +177 -175
- package/dist/index.js +354 -344
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +301 -290
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +33 -20
- package/dist/internal/index.d.ts +33 -20
- package/dist/internal/index.js +14 -7
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +14 -7
- package/dist/internal/index.mjs.map +1 -1
- package/dist/mcp-stdio/index.d.mts +3 -3
- package/dist/mcp-stdio/index.d.ts +3 -3
- package/dist/mcp-stdio/index.js.map +1 -1
- package/dist/mcp-stdio/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
@@ -33,7 +33,7 @@ __export(src_exports, {
|
|
33
33
|
InvalidPromptError: () => import_provider16.InvalidPromptError,
|
34
34
|
InvalidResponseDataError: () => import_provider16.InvalidResponseDataError,
|
35
35
|
InvalidStreamPartError: () => InvalidStreamPartError,
|
36
|
-
|
36
|
+
InvalidToolInputError: () => InvalidToolInputError,
|
37
37
|
JSONParseError: () => import_provider16.JSONParseError,
|
38
38
|
JsonToSseTransformStream: () => JsonToSseTransformStream,
|
39
39
|
LoadAPIKeyError: () => import_provider16.LoadAPIKeyError,
|
@@ -54,7 +54,7 @@ __export(src_exports, {
|
|
54
54
|
ToolExecutionError: () => ToolExecutionError,
|
55
55
|
TypeValidationError: () => import_provider16.TypeValidationError,
|
56
56
|
UnsupportedFunctionalityError: () => import_provider16.UnsupportedFunctionalityError,
|
57
|
-
asSchema: () =>
|
57
|
+
asSchema: () => import_provider_utils26.asSchema,
|
58
58
|
assistantModelMessageSchema: () => assistantModelMessageSchema,
|
59
59
|
callCompletionApi: () => callCompletionApi,
|
60
60
|
convertFileListToFileUIParts: () => convertFileListToFileUIParts,
|
@@ -66,7 +66,7 @@ __export(src_exports, {
|
|
66
66
|
coreToolMessageSchema: () => coreToolMessageSchema,
|
67
67
|
coreUserMessageSchema: () => coreUserMessageSchema,
|
68
68
|
cosineSimilarity: () => cosineSimilarity,
|
69
|
-
createIdGenerator: () =>
|
69
|
+
createIdGenerator: () => import_provider_utils26.createIdGenerator,
|
70
70
|
createProviderRegistry: () => createProviderRegistry,
|
71
71
|
createTextStreamResponse: () => createTextStreamResponse,
|
72
72
|
createUIMessageStream: () => createUIMessageStream,
|
@@ -82,14 +82,15 @@ __export(src_exports, {
|
|
82
82
|
experimental_generateSpeech: () => generateSpeech,
|
83
83
|
experimental_transcribe: () => transcribe,
|
84
84
|
extractReasoningMiddleware: () => extractReasoningMiddleware,
|
85
|
-
generateId: () =>
|
85
|
+
generateId: () => import_provider_utils26.generateId,
|
86
86
|
generateObject: () => generateObject,
|
87
87
|
generateText: () => generateText,
|
88
88
|
getTextFromDataUrl: () => getTextFromDataUrl,
|
89
|
-
|
89
|
+
getToolName: () => getToolName,
|
90
90
|
hasToolCall: () => hasToolCall,
|
91
91
|
isDeepEqualData: () => isDeepEqualData,
|
92
|
-
|
92
|
+
isToolUIPart: () => isToolUIPart,
|
93
|
+
jsonSchema: () => import_provider_utils26.jsonSchema,
|
93
94
|
modelMessageSchema: () => modelMessageSchema,
|
94
95
|
parsePartialJson: () => parsePartialJson,
|
95
96
|
pipeTextStreamToResponse: () => pipeTextStreamToResponse,
|
@@ -107,7 +108,7 @@ __export(src_exports, {
|
|
107
108
|
wrapLanguageModel: () => wrapLanguageModel
|
108
109
|
});
|
109
110
|
module.exports = __toCommonJS(src_exports);
|
110
|
-
var
|
111
|
+
var import_provider_utils26 = require("@ai-sdk/provider-utils");
|
111
112
|
|
112
113
|
// src/error/index.ts
|
113
114
|
var import_provider16 = require("@ai-sdk/provider");
|
@@ -159,24 +160,22 @@ var InvalidStreamPartError = class extends import_provider2.AISDKError {
|
|
159
160
|
};
|
160
161
|
_a2 = symbol2;
|
161
162
|
|
162
|
-
// src/error/invalid-tool-
|
163
|
+
// src/error/invalid-tool-input-error.ts
|
163
164
|
var import_provider3 = require("@ai-sdk/provider");
|
164
|
-
var name3 = "
|
165
|
+
var name3 = "AI_InvalidToolInputError";
|
165
166
|
var marker3 = `vercel.ai.error.${name3}`;
|
166
167
|
var symbol3 = Symbol.for(marker3);
|
167
168
|
var _a3;
|
168
|
-
var
|
169
|
+
var InvalidToolInputError = class extends import_provider3.AISDKError {
|
169
170
|
constructor({
|
170
|
-
|
171
|
+
toolInput,
|
171
172
|
toolName,
|
172
173
|
cause,
|
173
|
-
message = `Invalid
|
174
|
-
cause
|
175
|
-
)}`
|
174
|
+
message = `Invalid input for tool ${toolName}: ${(0, import_provider3.getErrorMessage)(cause)}`
|
176
175
|
}) {
|
177
176
|
super({ name: name3, message, cause });
|
178
177
|
this[_a3] = true;
|
179
|
-
this.
|
178
|
+
this.toolInput = toolInput;
|
180
179
|
this.toolName = toolName;
|
181
180
|
}
|
182
181
|
static isInstance(error) {
|
@@ -327,7 +326,7 @@ var symbol10 = Symbol.for(marker10);
|
|
327
326
|
var _a10;
|
328
327
|
var ToolExecutionError = class extends import_provider10.AISDKError {
|
329
328
|
constructor({
|
330
|
-
|
329
|
+
toolInput,
|
331
330
|
toolName,
|
332
331
|
toolCallId,
|
333
332
|
cause,
|
@@ -335,7 +334,7 @@ var ToolExecutionError = class extends import_provider10.AISDKError {
|
|
335
334
|
}) {
|
336
335
|
super({ name: name10, message, cause });
|
337
336
|
this[_a10] = true;
|
338
|
-
this.
|
337
|
+
this.toolInput = toolInput;
|
339
338
|
this.toolName = toolName;
|
340
339
|
this.toolCallId = toolCallId;
|
341
340
|
}
|
@@ -540,42 +539,45 @@ var import_provider_utils = require("@ai-sdk/provider-utils");
|
|
540
539
|
// src/ui-message-stream/ui-message-stream-parts.ts
|
541
540
|
var import_zod = require("zod");
|
542
541
|
var uiMessageStreamPartSchema = import_zod.z.union([
|
543
|
-
import_zod.z.
|
542
|
+
import_zod.z.strictObject({
|
544
543
|
type: import_zod.z.literal("text"),
|
545
544
|
text: import_zod.z.string()
|
546
545
|
}),
|
547
|
-
import_zod.z.
|
546
|
+
import_zod.z.strictObject({
|
548
547
|
type: import_zod.z.literal("error"),
|
549
548
|
errorText: import_zod.z.string()
|
550
549
|
}),
|
551
|
-
import_zod.z.
|
552
|
-
type: import_zod.z.literal("tool-
|
550
|
+
import_zod.z.strictObject({
|
551
|
+
type: import_zod.z.literal("tool-input-start"),
|
553
552
|
toolCallId: import_zod.z.string(),
|
554
553
|
toolName: import_zod.z.string()
|
555
554
|
}),
|
556
|
-
import_zod.z.
|
557
|
-
type: import_zod.z.literal("tool-
|
555
|
+
import_zod.z.strictObject({
|
556
|
+
type: import_zod.z.literal("tool-input-delta"),
|
558
557
|
toolCallId: import_zod.z.string(),
|
559
|
-
|
558
|
+
inputTextDelta: import_zod.z.string()
|
560
559
|
}),
|
561
|
-
import_zod.z.
|
562
|
-
type: import_zod.z.literal("tool-
|
560
|
+
import_zod.z.strictObject({
|
561
|
+
type: import_zod.z.literal("tool-input-available"),
|
563
562
|
toolCallId: import_zod.z.string(),
|
564
563
|
toolName: import_zod.z.string(),
|
565
|
-
|
564
|
+
input: import_zod.z.unknown()
|
566
565
|
}),
|
567
|
-
import_zod.z.
|
568
|
-
type: import_zod.z.literal("tool-
|
566
|
+
import_zod.z.strictObject({
|
567
|
+
type: import_zod.z.literal("tool-output-available"),
|
569
568
|
toolCallId: import_zod.z.string(),
|
570
|
-
|
569
|
+
output: import_zod.z.unknown(),
|
571
570
|
providerMetadata: import_zod.z.any().optional()
|
572
571
|
}),
|
573
|
-
import_zod.z.
|
572
|
+
import_zod.z.strictObject({
|
574
573
|
type: import_zod.z.literal("reasoning"),
|
575
574
|
text: import_zod.z.string(),
|
576
575
|
providerMetadata: import_zod.z.record(import_zod.z.any()).optional()
|
577
576
|
}),
|
578
|
-
import_zod.z.
|
577
|
+
import_zod.z.strictObject({
|
578
|
+
type: import_zod.z.literal("reasoning-part-finish")
|
579
|
+
}),
|
580
|
+
import_zod.z.strictObject({
|
579
581
|
type: import_zod.z.literal("source-url"),
|
580
582
|
sourceId: import_zod.z.string(),
|
581
583
|
url: import_zod.z.string(),
|
@@ -583,7 +585,7 @@ var uiMessageStreamPartSchema = import_zod.z.union([
|
|
583
585
|
providerMetadata: import_zod.z.any().optional()
|
584
586
|
// Use z.any() for generic metadata
|
585
587
|
}),
|
586
|
-
import_zod.z.
|
588
|
+
import_zod.z.strictObject({
|
587
589
|
type: import_zod.z.literal("source-document"),
|
588
590
|
sourceId: import_zod.z.string(),
|
589
591
|
mediaType: import_zod.z.string(),
|
@@ -592,39 +594,34 @@ var uiMessageStreamPartSchema = import_zod.z.union([
|
|
592
594
|
providerMetadata: import_zod.z.any().optional()
|
593
595
|
// Use z.any() for generic metadata
|
594
596
|
}),
|
595
|
-
import_zod.z.
|
597
|
+
import_zod.z.strictObject({
|
596
598
|
type: import_zod.z.literal("file"),
|
597
599
|
url: import_zod.z.string(),
|
598
600
|
mediaType: import_zod.z.string()
|
599
601
|
}),
|
600
|
-
import_zod.z.
|
602
|
+
import_zod.z.strictObject({
|
601
603
|
type: import_zod.z.string().startsWith("data-"),
|
602
604
|
id: import_zod.z.string().optional(),
|
603
605
|
data: import_zod.z.unknown()
|
604
606
|
}),
|
605
|
-
import_zod.z.
|
606
|
-
type: import_zod.z.literal("
|
607
|
-
value: import_zod.z.object({ metadata: import_zod.z.unknown() })
|
607
|
+
import_zod.z.strictObject({
|
608
|
+
type: import_zod.z.literal("start-step")
|
608
609
|
}),
|
609
|
-
import_zod.z.
|
610
|
-
type: import_zod.z.literal("
|
611
|
-
metadata: import_zod.z.unknown().optional()
|
610
|
+
import_zod.z.strictObject({
|
611
|
+
type: import_zod.z.literal("finish-step")
|
612
612
|
}),
|
613
|
-
import_zod.z.
|
614
|
-
type: import_zod.z.literal("finish-step"),
|
615
|
-
metadata: import_zod.z.unknown().optional()
|
616
|
-
}),
|
617
|
-
import_zod.z.object({
|
613
|
+
import_zod.z.strictObject({
|
618
614
|
type: import_zod.z.literal("start"),
|
619
615
|
messageId: import_zod.z.string().optional(),
|
620
|
-
|
616
|
+
messageMetadata: import_zod.z.unknown().optional()
|
621
617
|
}),
|
622
|
-
import_zod.z.
|
618
|
+
import_zod.z.strictObject({
|
623
619
|
type: import_zod.z.literal("finish"),
|
624
|
-
|
620
|
+
messageMetadata: import_zod.z.unknown().optional()
|
625
621
|
}),
|
626
|
-
import_zod.z.
|
627
|
-
type: import_zod.z.literal("
|
622
|
+
import_zod.z.strictObject({
|
623
|
+
type: import_zod.z.literal("message-metadata"),
|
624
|
+
messageMetadata: import_zod.z.unknown()
|
628
625
|
})
|
629
626
|
]);
|
630
627
|
function isDataUIMessageStreamPart(part) {
|
@@ -1314,27 +1311,26 @@ async function parsePartialJson(jsonText) {
|
|
1314
1311
|
return { value: void 0, state: "failed-parse" };
|
1315
1312
|
}
|
1316
1313
|
|
1317
|
-
// src/ui/
|
1318
|
-
function
|
1319
|
-
return
|
1320
|
-
|
1321
|
-
|
1314
|
+
// src/ui/ui-messages.ts
|
1315
|
+
function isToolUIPart(part) {
|
1316
|
+
return part.type.startsWith("tool-");
|
1317
|
+
}
|
1318
|
+
function getToolName(part) {
|
1319
|
+
return part.type.split("-")[1];
|
1322
1320
|
}
|
1323
1321
|
|
1324
1322
|
// src/ui/process-ui-message-stream.ts
|
1325
1323
|
function createStreamingUIMessageState({
|
1326
1324
|
lastMessage,
|
1327
|
-
|
1328
|
-
}
|
1329
|
-
const isContinuation = (lastMessage == null ? void 0 : lastMessage.role) === "assistant";
|
1330
|
-
const message = isContinuation ? lastMessage : {
|
1331
|
-
id: newMessageId,
|
1332
|
-
metadata: {},
|
1333
|
-
role: "assistant",
|
1334
|
-
parts: []
|
1335
|
-
};
|
1325
|
+
messageId
|
1326
|
+
}) {
|
1336
1327
|
return {
|
1337
|
-
message
|
1328
|
+
message: (lastMessage == null ? void 0 : lastMessage.role) === "assistant" ? lastMessage : {
|
1329
|
+
id: messageId,
|
1330
|
+
metadata: void 0,
|
1331
|
+
role: "assistant",
|
1332
|
+
parts: []
|
1333
|
+
},
|
1338
1334
|
activeTextPart: void 0,
|
1339
1335
|
activeReasoningPart: void 0,
|
1340
1336
|
partialToolCalls: {}
|
@@ -1351,16 +1347,21 @@ function processUIMessageStream({
|
|
1351
1347
|
new TransformStream({
|
1352
1348
|
async transform(part, controller) {
|
1353
1349
|
await runUpdateMessageJob(async ({ state, write }) => {
|
1354
|
-
function updateToolInvocationPart(
|
1350
|
+
function updateToolInvocationPart(options) {
|
1355
1351
|
const part2 = state.message.parts.find(
|
1356
|
-
(part3) =>
|
1352
|
+
(part3) => isToolUIPart(part3) && part3.toolCallId === options.toolCallId
|
1357
1353
|
);
|
1358
1354
|
if (part2 != null) {
|
1359
|
-
part2.
|
1355
|
+
part2.state = options.state;
|
1356
|
+
part2.input = options.input;
|
1357
|
+
part2.output = options.output;
|
1360
1358
|
} else {
|
1361
1359
|
state.message.parts.push({
|
1362
|
-
type:
|
1363
|
-
|
1360
|
+
type: `tool-${options.toolName}`,
|
1361
|
+
toolCallId: options.toolCallId,
|
1362
|
+
state: options.state,
|
1363
|
+
input: options.input,
|
1364
|
+
output: options.output
|
1364
1365
|
});
|
1365
1366
|
}
|
1366
1367
|
}
|
@@ -1443,43 +1444,43 @@ function processUIMessageStream({
|
|
1443
1444
|
write();
|
1444
1445
|
break;
|
1445
1446
|
}
|
1446
|
-
case "tool-
|
1447
|
-
const toolInvocations =
|
1447
|
+
case "tool-input-start": {
|
1448
|
+
const toolInvocations = state.message.parts.filter(isToolUIPart);
|
1448
1449
|
state.partialToolCalls[part.toolCallId] = {
|
1449
1450
|
text: "",
|
1450
1451
|
toolName: part.toolName,
|
1451
1452
|
index: toolInvocations.length
|
1452
1453
|
};
|
1453
|
-
updateToolInvocationPart(
|
1454
|
-
state: "partial-call",
|
1454
|
+
updateToolInvocationPart({
|
1455
1455
|
toolCallId: part.toolCallId,
|
1456
1456
|
toolName: part.toolName,
|
1457
|
-
|
1457
|
+
state: "input-streaming",
|
1458
|
+
input: void 0
|
1458
1459
|
});
|
1459
1460
|
write();
|
1460
1461
|
break;
|
1461
1462
|
}
|
1462
|
-
case "tool-
|
1463
|
+
case "tool-input-delta": {
|
1463
1464
|
const partialToolCall = state.partialToolCalls[part.toolCallId];
|
1464
|
-
partialToolCall.text += part.
|
1465
|
+
partialToolCall.text += part.inputTextDelta;
|
1465
1466
|
const { value: partialArgs } = await parsePartialJson(
|
1466
1467
|
partialToolCall.text
|
1467
1468
|
);
|
1468
|
-
updateToolInvocationPart(
|
1469
|
-
state: "partial-call",
|
1469
|
+
updateToolInvocationPart({
|
1470
1470
|
toolCallId: part.toolCallId,
|
1471
1471
|
toolName: partialToolCall.toolName,
|
1472
|
-
|
1472
|
+
state: "input-streaming",
|
1473
|
+
input: partialArgs
|
1473
1474
|
});
|
1474
1475
|
write();
|
1475
1476
|
break;
|
1476
1477
|
}
|
1477
|
-
case "tool-
|
1478
|
-
updateToolInvocationPart(
|
1479
|
-
state: "call",
|
1478
|
+
case "tool-input-available": {
|
1479
|
+
updateToolInvocationPart({
|
1480
1480
|
toolCallId: part.toolCallId,
|
1481
1481
|
toolName: part.toolName,
|
1482
|
-
|
1482
|
+
state: "input-available",
|
1483
|
+
input: part.input
|
1483
1484
|
});
|
1484
1485
|
write();
|
1485
1486
|
if (onToolCall) {
|
@@ -1487,20 +1488,20 @@ function processUIMessageStream({
|
|
1487
1488
|
toolCall: part
|
1488
1489
|
});
|
1489
1490
|
if (result != null) {
|
1490
|
-
updateToolInvocationPart(
|
1491
|
-
state: "result",
|
1491
|
+
updateToolInvocationPart({
|
1492
1492
|
toolCallId: part.toolCallId,
|
1493
1493
|
toolName: part.toolName,
|
1494
|
-
|
1495
|
-
|
1494
|
+
state: "output-available",
|
1495
|
+
input: part.input,
|
1496
|
+
output: result
|
1496
1497
|
});
|
1497
1498
|
write();
|
1498
1499
|
}
|
1499
1500
|
}
|
1500
1501
|
break;
|
1501
1502
|
}
|
1502
|
-
case "tool-
|
1503
|
-
const toolInvocations =
|
1503
|
+
case "tool-output-available": {
|
1504
|
+
const toolInvocations = state.message.parts.filter(isToolUIPart);
|
1504
1505
|
if (toolInvocations == null) {
|
1505
1506
|
throw new Error("tool_result must be preceded by a tool_call");
|
1506
1507
|
}
|
@@ -1512,49 +1513,48 @@ function processUIMessageStream({
|
|
1512
1513
|
"tool_result must be preceded by a tool_call with the same toolCallId"
|
1513
1514
|
);
|
1514
1515
|
}
|
1515
|
-
|
1516
|
-
|
1517
|
-
|
1518
|
-
|
1516
|
+
const toolName = getToolName(
|
1517
|
+
toolInvocations[toolInvocationIndex]
|
1518
|
+
);
|
1519
|
+
updateToolInvocationPart({
|
1520
|
+
toolCallId: part.toolCallId,
|
1521
|
+
toolName,
|
1522
|
+
state: "output-available",
|
1523
|
+
input: toolInvocations[toolInvocationIndex].input,
|
1524
|
+
output: part.output
|
1519
1525
|
});
|
1520
1526
|
write();
|
1521
1527
|
break;
|
1522
1528
|
}
|
1523
1529
|
case "start-step": {
|
1524
1530
|
state.message.parts.push({ type: "step-start" });
|
1525
|
-
await updateMessageMetadata(part.metadata);
|
1526
|
-
write();
|
1527
1531
|
break;
|
1528
1532
|
}
|
1529
1533
|
case "finish-step": {
|
1530
1534
|
state.activeTextPart = void 0;
|
1531
1535
|
state.activeReasoningPart = void 0;
|
1532
|
-
await updateMessageMetadata(part.metadata);
|
1533
|
-
if (part.metadata != null) {
|
1534
|
-
write();
|
1535
|
-
}
|
1536
1536
|
break;
|
1537
1537
|
}
|
1538
1538
|
case "start": {
|
1539
1539
|
if (part.messageId != null) {
|
1540
1540
|
state.message.id = part.messageId;
|
1541
1541
|
}
|
1542
|
-
await updateMessageMetadata(part.
|
1543
|
-
if (part.messageId != null || part.
|
1542
|
+
await updateMessageMetadata(part.messageMetadata);
|
1543
|
+
if (part.messageId != null || part.messageMetadata != null) {
|
1544
1544
|
write();
|
1545
1545
|
}
|
1546
1546
|
break;
|
1547
1547
|
}
|
1548
1548
|
case "finish": {
|
1549
|
-
await updateMessageMetadata(part.
|
1550
|
-
if (part.
|
1549
|
+
await updateMessageMetadata(part.messageMetadata);
|
1550
|
+
if (part.messageMetadata != null) {
|
1551
1551
|
write();
|
1552
1552
|
}
|
1553
1553
|
break;
|
1554
1554
|
}
|
1555
|
-
case "metadata": {
|
1556
|
-
await updateMessageMetadata(part.
|
1557
|
-
if (part.
|
1555
|
+
case "message-metadata": {
|
1556
|
+
await updateMessageMetadata(part.messageMetadata);
|
1557
|
+
if (part.messageMetadata != null) {
|
1558
1558
|
write();
|
1559
1559
|
}
|
1560
1560
|
break;
|
@@ -1582,9 +1582,6 @@ function processUIMessageStream({
|
|
1582
1582
|
})
|
1583
1583
|
);
|
1584
1584
|
}
|
1585
|
-
function isToolInvocationUIPart(part) {
|
1586
|
-
return part.type === "tool-invocation";
|
1587
|
-
}
|
1588
1585
|
function isObject(value) {
|
1589
1586
|
return typeof value === "object" && value !== null;
|
1590
1587
|
}
|
@@ -1619,8 +1616,8 @@ function isAssistantMessageWithCompletedToolCalls(message) {
|
|
1619
1616
|
const lastStepStartIndex = message.parts.reduce((lastIndex, part, index) => {
|
1620
1617
|
return part.type === "step-start" ? index : lastIndex;
|
1621
1618
|
}, -1);
|
1622
|
-
const lastStepToolInvocations = message.parts.slice(lastStepStartIndex + 1).filter(
|
1623
|
-
return lastStepToolInvocations.length > 0 && lastStepToolInvocations.every((part) => "
|
1619
|
+
const lastStepToolInvocations = message.parts.slice(lastStepStartIndex + 1).filter(isToolUIPart);
|
1620
|
+
return lastStepToolInvocations.length > 0 && lastStepToolInvocations.every((part) => part.state === "output-available");
|
1624
1621
|
}
|
1625
1622
|
|
1626
1623
|
// src/ui/chat.ts
|
@@ -1694,13 +1691,13 @@ var AbstractChat = class {
|
|
1694
1691
|
};
|
1695
1692
|
this.addToolResult = async ({
|
1696
1693
|
toolCallId,
|
1697
|
-
|
1694
|
+
output
|
1698
1695
|
}) => {
|
1699
1696
|
this.jobExecutor.run(async () => {
|
1700
|
-
|
1697
|
+
updateToolOutput({
|
1701
1698
|
messages: this.state.messages,
|
1702
1699
|
toolCallId,
|
1703
|
-
|
1700
|
+
output
|
1704
1701
|
});
|
1705
1702
|
this.messages = this.state.messages;
|
1706
1703
|
if (this.status === "submitted" || this.status === "streaming") {
|
@@ -1723,7 +1720,6 @@ var AbstractChat = class {
|
|
1723
1720
|
return;
|
1724
1721
|
if ((_a17 = this.activeResponse) == null ? void 0 : _a17.abortController) {
|
1725
1722
|
this.activeResponse.abortController.abort();
|
1726
|
-
this.activeResponse.abortController = void 0;
|
1727
1723
|
}
|
1728
1724
|
};
|
1729
1725
|
this.id = id;
|
@@ -1784,7 +1780,7 @@ var AbstractChat = class {
|
|
1784
1780
|
const activeResponse = {
|
1785
1781
|
state: createStreamingUIMessageState({
|
1786
1782
|
lastMessage: this.state.snapshot(lastMessage),
|
1787
|
-
|
1783
|
+
messageId: this.generateId()
|
1788
1784
|
}),
|
1789
1785
|
abortController: new AbortController()
|
1790
1786
|
};
|
@@ -1861,23 +1857,20 @@ var AbstractChat = class {
|
|
1861
1857
|
}
|
1862
1858
|
}
|
1863
1859
|
};
|
1864
|
-
function
|
1860
|
+
function updateToolOutput({
|
1865
1861
|
messages,
|
1866
1862
|
toolCallId,
|
1867
|
-
|
1863
|
+
output
|
1868
1864
|
}) {
|
1869
1865
|
const lastMessage = messages[messages.length - 1];
|
1870
|
-
const
|
1871
|
-
(part) => part
|
1866
|
+
const toolPart = lastMessage.parts.find(
|
1867
|
+
(part) => isToolUIPart(part) && part.toolCallId === toolCallId
|
1872
1868
|
);
|
1873
|
-
if (
|
1869
|
+
if (toolPart == null) {
|
1874
1870
|
return;
|
1875
1871
|
}
|
1876
|
-
|
1877
|
-
|
1878
|
-
state: "result",
|
1879
|
-
result
|
1880
|
-
};
|
1872
|
+
toolPart.state = "output-available";
|
1873
|
+
toolPart.output = output;
|
1881
1874
|
}
|
1882
1875
|
|
1883
1876
|
// src/ui/convert-to-model-messages.ts
|
@@ -1918,75 +1911,71 @@ function convertToModelMessages(messages, options) {
|
|
1918
1911
|
}
|
1919
1912
|
const content = [];
|
1920
1913
|
for (const part of block) {
|
1921
|
-
|
1922
|
-
|
1923
|
-
|
1924
|
-
|
1925
|
-
|
1926
|
-
|
1927
|
-
|
1928
|
-
|
1929
|
-
|
1930
|
-
|
1931
|
-
|
1932
|
-
|
1933
|
-
|
1934
|
-
|
1935
|
-
|
1936
|
-
|
1937
|
-
|
1938
|
-
|
1914
|
+
if (part.type === "text") {
|
1915
|
+
content.push(part);
|
1916
|
+
} else if (part.type === "file") {
|
1917
|
+
content.push({
|
1918
|
+
type: "file",
|
1919
|
+
mediaType: part.mediaType,
|
1920
|
+
data: part.url
|
1921
|
+
});
|
1922
|
+
} else if (part.type === "reasoning") {
|
1923
|
+
content.push({
|
1924
|
+
type: "reasoning",
|
1925
|
+
text: part.text,
|
1926
|
+
providerOptions: part.providerMetadata
|
1927
|
+
});
|
1928
|
+
} else if (isToolUIPart(part)) {
|
1929
|
+
const toolName = getToolName(part);
|
1930
|
+
if (part.state === "input-streaming") {
|
1931
|
+
throw new MessageConversionError({
|
1932
|
+
originalMessage: message,
|
1933
|
+
message: `incomplete tool input is not supported: ${part.toolCallId}`
|
1939
1934
|
});
|
1940
|
-
|
1941
|
-
}
|
1942
|
-
case "tool-invocation":
|
1935
|
+
} else {
|
1943
1936
|
content.push({
|
1944
1937
|
type: "tool-call",
|
1945
|
-
toolCallId: part.
|
1946
|
-
toolName
|
1947
|
-
|
1938
|
+
toolCallId: part.toolCallId,
|
1939
|
+
toolName,
|
1940
|
+
input: part.input
|
1948
1941
|
});
|
1949
|
-
break;
|
1950
|
-
default: {
|
1951
|
-
const _exhaustiveCheck = part;
|
1952
|
-
throw new Error(`Unsupported part: ${_exhaustiveCheck}`);
|
1953
1942
|
}
|
1943
|
+
} else {
|
1944
|
+
const _exhaustiveCheck = part;
|
1945
|
+
throw new Error(`Unsupported part: ${_exhaustiveCheck}`);
|
1954
1946
|
}
|
1955
1947
|
}
|
1956
1948
|
modelMessages.push({
|
1957
1949
|
role: "assistant",
|
1958
1950
|
content
|
1959
1951
|
});
|
1960
|
-
const
|
1961
|
-
|
1962
|
-
).map((part) => part.toolInvocation);
|
1963
|
-
if (stepInvocations.length > 0) {
|
1952
|
+
const toolParts = block.filter(isToolUIPart);
|
1953
|
+
if (toolParts.length > 0) {
|
1964
1954
|
modelMessages.push({
|
1965
1955
|
role: "tool",
|
1966
|
-
content:
|
1967
|
-
(
|
1968
|
-
|
1969
|
-
|
1970
|
-
|
1971
|
-
|
1972
|
-
});
|
1973
|
-
}
|
1974
|
-
const { toolCallId, toolName, result } = toolInvocation;
|
1975
|
-
const tool2 = tools[toolName];
|
1976
|
-
return (tool2 == null ? void 0 : tool2.experimental_toToolResultContent) != null ? {
|
1977
|
-
type: "tool-result",
|
1978
|
-
toolCallId,
|
1979
|
-
toolName,
|
1980
|
-
result: tool2.experimental_toToolResultContent(result),
|
1981
|
-
experimental_content: tool2.experimental_toToolResultContent(result)
|
1982
|
-
} : {
|
1983
|
-
type: "tool-result",
|
1984
|
-
toolCallId,
|
1985
|
-
toolName,
|
1986
|
-
result
|
1987
|
-
};
|
1956
|
+
content: toolParts.map((toolPart) => {
|
1957
|
+
if (toolPart.state !== "output-available") {
|
1958
|
+
throw new MessageConversionError({
|
1959
|
+
originalMessage: message,
|
1960
|
+
message: "ToolInvocation must have a result: " + JSON.stringify(toolPart)
|
1961
|
+
});
|
1988
1962
|
}
|
1989
|
-
|
1963
|
+
const toolName = getToolName(toolPart);
|
1964
|
+
const { toolCallId, output } = toolPart;
|
1965
|
+
const tool2 = tools[toolName];
|
1966
|
+
return (tool2 == null ? void 0 : tool2.experimental_toToolResultContent) != null ? {
|
1967
|
+
type: "tool-result",
|
1968
|
+
toolCallId,
|
1969
|
+
toolName,
|
1970
|
+
output: tool2.experimental_toToolResultContent(output),
|
1971
|
+
experimental_content: tool2.experimental_toToolResultContent(output)
|
1972
|
+
} : {
|
1973
|
+
type: "tool-result",
|
1974
|
+
toolCallId,
|
1975
|
+
toolName,
|
1976
|
+
output
|
1977
|
+
};
|
1978
|
+
})
|
1990
1979
|
});
|
1991
1980
|
}
|
1992
1981
|
block = [];
|
@@ -1994,18 +1983,10 @@ function convertToModelMessages(messages, options) {
|
|
1994
1983
|
var processBlock = processBlock2;
|
1995
1984
|
let block = [];
|
1996
1985
|
for (const part of message.parts) {
|
1997
|
-
|
1998
|
-
|
1999
|
-
|
2000
|
-
|
2001
|
-
case "tool-invocation": {
|
2002
|
-
block.push(part);
|
2003
|
-
break;
|
2004
|
-
}
|
2005
|
-
case "step-start": {
|
2006
|
-
processBlock2();
|
2007
|
-
break;
|
2008
|
-
}
|
1986
|
+
if (part.type === "text" || part.type === "reasoning" || part.type === "file" || isToolUIPart(part)) {
|
1987
|
+
block.push(part);
|
1988
|
+
} else if (part.type === "step-start") {
|
1989
|
+
processBlock2();
|
2009
1990
|
}
|
2010
1991
|
}
|
2011
1992
|
processBlock2();
|
@@ -2135,9 +2116,12 @@ var TextStreamChatTransport = class {
|
|
2135
2116
|
}
|
2136
2117
|
};
|
2137
2118
|
|
2119
|
+
// src/ui-message-stream/create-ui-message-stream.ts
|
2120
|
+
var import_provider_utils6 = require("@ai-sdk/provider-utils");
|
2121
|
+
|
2138
2122
|
// src/ui-message-stream/handle-ui-message-stream-finish.ts
|
2139
2123
|
function handleUIMessageStreamFinish({
|
2140
|
-
|
2124
|
+
messageId,
|
2141
2125
|
originalMessages = [],
|
2142
2126
|
onFinish,
|
2143
2127
|
stream
|
@@ -2145,19 +2129,30 @@ function handleUIMessageStreamFinish({
|
|
2145
2129
|
if (onFinish == null) {
|
2146
2130
|
return stream;
|
2147
2131
|
}
|
2148
|
-
const lastMessage = originalMessages[originalMessages.length - 1];
|
2149
|
-
const isContinuation = (lastMessage == null ? void 0 : lastMessage.role) === "assistant";
|
2150
|
-
const messageId = isContinuation ? lastMessage.id : newMessageId;
|
2132
|
+
const lastMessage = originalMessages == null ? void 0 : originalMessages[originalMessages.length - 1];
|
2151
2133
|
const state = createStreamingUIMessageState({
|
2152
|
-
lastMessage: structuredClone(lastMessage),
|
2153
|
-
|
2134
|
+
lastMessage: lastMessage ? structuredClone(lastMessage) : void 0,
|
2135
|
+
messageId
|
2136
|
+
// will be overridden by the stream
|
2154
2137
|
});
|
2155
2138
|
const runUpdateMessageJob = async (job) => {
|
2156
2139
|
await job({ state, write: () => {
|
2157
2140
|
} });
|
2158
2141
|
};
|
2159
2142
|
return processUIMessageStream({
|
2160
|
-
stream
|
2143
|
+
stream: stream.pipeThrough(
|
2144
|
+
new TransformStream({
|
2145
|
+
transform(chunk, controller) {
|
2146
|
+
if (chunk.type === "start") {
|
2147
|
+
const startChunk = chunk;
|
2148
|
+
if (startChunk.messageId == null) {
|
2149
|
+
startChunk.messageId = messageId;
|
2150
|
+
}
|
2151
|
+
}
|
2152
|
+
controller.enqueue(chunk);
|
2153
|
+
}
|
2154
|
+
})
|
2155
|
+
),
|
2161
2156
|
runUpdateMessageJob
|
2162
2157
|
}).pipeThrough(
|
2163
2158
|
new TransformStream({
|
@@ -2165,12 +2160,12 @@ function handleUIMessageStreamFinish({
|
|
2165
2160
|
controller.enqueue(chunk);
|
2166
2161
|
},
|
2167
2162
|
flush() {
|
2168
|
-
const
|
2163
|
+
const isContinuation = state.message.id === (lastMessage == null ? void 0 : lastMessage.id);
|
2169
2164
|
onFinish({
|
2170
|
-
isContinuation
|
2165
|
+
isContinuation,
|
2171
2166
|
responseMessage: state.message,
|
2172
2167
|
messages: [
|
2173
|
-
...
|
2168
|
+
...isContinuation ? originalMessages.slice(0, -1) : originalMessages,
|
2174
2169
|
state.message
|
2175
2170
|
]
|
2176
2171
|
});
|
@@ -2185,7 +2180,8 @@ function createUIMessageStream({
|
|
2185
2180
|
onError = () => "An error occurred.",
|
2186
2181
|
// mask error messages for safety by default
|
2187
2182
|
originalMessages,
|
2188
|
-
onFinish
|
2183
|
+
onFinish,
|
2184
|
+
generateId: generateId3 = import_provider_utils6.generateId
|
2189
2185
|
}) {
|
2190
2186
|
let controller;
|
2191
2187
|
const ongoingStreamPromises = [];
|
@@ -2257,7 +2253,7 @@ function createUIMessageStream({
|
|
2257
2253
|
});
|
2258
2254
|
return handleUIMessageStreamFinish({
|
2259
2255
|
stream,
|
2260
|
-
|
2256
|
+
messageId: generateId3(),
|
2261
2257
|
originalMessages,
|
2262
2258
|
onFinish
|
2263
2259
|
});
|
@@ -2401,7 +2397,7 @@ function isDeepEqualData(obj1, obj2) {
|
|
2401
2397
|
}
|
2402
2398
|
|
2403
2399
|
// src/util/simulate-readable-stream.ts
|
2404
|
-
var
|
2400
|
+
var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
2405
2401
|
function simulateReadableStream({
|
2406
2402
|
chunks,
|
2407
2403
|
initialDelayInMs = 0,
|
@@ -2409,7 +2405,7 @@ function simulateReadableStream({
|
|
2409
2405
|
_internal
|
2410
2406
|
}) {
|
2411
2407
|
var _a17;
|
2412
|
-
const delay2 = (_a17 = _internal == null ? void 0 : _internal.delay) != null ? _a17 :
|
2408
|
+
const delay2 = (_a17 = _internal == null ? void 0 : _internal.delay) != null ? _a17 : import_provider_utils7.delay;
|
2413
2409
|
let index = 0;
|
2414
2410
|
return new ReadableStream({
|
2415
2411
|
async pull(controller) {
|
@@ -2425,7 +2421,7 @@ function simulateReadableStream({
|
|
2425
2421
|
|
2426
2422
|
// src/util/retry-with-exponential-backoff.ts
|
2427
2423
|
var import_provider17 = require("@ai-sdk/provider");
|
2428
|
-
var
|
2424
|
+
var import_provider_utils8 = require("@ai-sdk/provider-utils");
|
2429
2425
|
var retryWithExponentialBackoff = ({
|
2430
2426
|
maxRetries = 2,
|
2431
2427
|
initialDelayInMs = 2e3,
|
@@ -2443,13 +2439,13 @@ async function _retryWithExponentialBackoff(f, {
|
|
2443
2439
|
try {
|
2444
2440
|
return await f();
|
2445
2441
|
} catch (error) {
|
2446
|
-
if ((0,
|
2442
|
+
if ((0, import_provider_utils8.isAbortError)(error)) {
|
2447
2443
|
throw error;
|
2448
2444
|
}
|
2449
2445
|
if (maxRetries === 0) {
|
2450
2446
|
throw error;
|
2451
2447
|
}
|
2452
|
-
const errorMessage = (0,
|
2448
|
+
const errorMessage = (0, import_provider_utils8.getErrorMessage)(error);
|
2453
2449
|
const newErrors = [...errors, error];
|
2454
2450
|
const tryNumber = newErrors.length;
|
2455
2451
|
if (tryNumber > maxRetries) {
|
@@ -2460,7 +2456,7 @@ async function _retryWithExponentialBackoff(f, {
|
|
2460
2456
|
});
|
2461
2457
|
}
|
2462
2458
|
if (error instanceof Error && import_provider17.APICallError.isInstance(error) && error.isRetryable === true && tryNumber <= maxRetries) {
|
2463
|
-
await (0,
|
2459
|
+
await (0, import_provider_utils8.delay)(delayInMs);
|
2464
2460
|
return _retryWithExponentialBackoff(
|
2465
2461
|
f,
|
2466
2462
|
{ maxRetries, delayInMs: backoffFactor * delayInMs, backoffFactor },
|
@@ -3019,7 +3015,7 @@ var DefaultEmbedManyResult = class {
|
|
3019
3015
|
};
|
3020
3016
|
|
3021
3017
|
// src/util/detect-media-type.ts
|
3022
|
-
var
|
3018
|
+
var import_provider_utils9 = require("@ai-sdk/provider-utils");
|
3023
3019
|
var imageMediaTypeSignatures = [
|
3024
3020
|
{
|
3025
3021
|
mediaType: "image/gif",
|
@@ -3126,7 +3122,7 @@ var audioMediaTypeSignatures = [
|
|
3126
3122
|
}
|
3127
3123
|
];
|
3128
3124
|
var stripID3 = (data) => {
|
3129
|
-
const bytes = typeof data === "string" ? (0,
|
3125
|
+
const bytes = typeof data === "string" ? (0, import_provider_utils9.convertBase64ToUint8Array)(data) : data;
|
3130
3126
|
const id3Size = (bytes[6] & 127) << 21 | (bytes[7] & 127) << 14 | (bytes[8] & 127) << 7 | bytes[9] & 127;
|
3131
3127
|
return bytes.slice(id3Size + 10);
|
3132
3128
|
};
|
@@ -3152,7 +3148,7 @@ function detectMediaType({
|
|
3152
3148
|
}
|
3153
3149
|
|
3154
3150
|
// core/generate-text/generated-file.ts
|
3155
|
-
var
|
3151
|
+
var import_provider_utils10 = require("@ai-sdk/provider-utils");
|
3156
3152
|
var DefaultGeneratedFile = class {
|
3157
3153
|
constructor({
|
3158
3154
|
data,
|
@@ -3166,14 +3162,14 @@ var DefaultGeneratedFile = class {
|
|
3166
3162
|
// lazy conversion with caching to avoid unnecessary conversion overhead:
|
3167
3163
|
get base64() {
|
3168
3164
|
if (this.base64Data == null) {
|
3169
|
-
this.base64Data = (0,
|
3165
|
+
this.base64Data = (0, import_provider_utils10.convertUint8ArrayToBase64)(this.uint8ArrayData);
|
3170
3166
|
}
|
3171
3167
|
return this.base64Data;
|
3172
3168
|
}
|
3173
3169
|
// lazy conversion with caching to avoid unnecessary conversion overhead:
|
3174
3170
|
get uint8Array() {
|
3175
3171
|
if (this.uint8ArrayData == null) {
|
3176
|
-
this.uint8ArrayData = (0,
|
3172
|
+
this.uint8ArrayData = (0, import_provider_utils10.convertBase64ToUint8Array)(this.base64Data);
|
3177
3173
|
}
|
3178
3174
|
return this.uint8ArrayData;
|
3179
3175
|
}
|
@@ -3289,7 +3285,7 @@ async function invokeModelMaxImagesPerCall(model) {
|
|
3289
3285
|
|
3290
3286
|
// core/generate-object/generate-object.ts
|
3291
3287
|
var import_provider22 = require("@ai-sdk/provider");
|
3292
|
-
var
|
3288
|
+
var import_provider_utils15 = require("@ai-sdk/provider-utils");
|
3293
3289
|
|
3294
3290
|
// core/generate-text/extract-content-text.ts
|
3295
3291
|
function extractContentText(content) {
|
@@ -3303,7 +3299,7 @@ function extractContentText(content) {
|
|
3303
3299
|
}
|
3304
3300
|
|
3305
3301
|
// core/prompt/convert-to-language-model-prompt.ts
|
3306
|
-
var
|
3302
|
+
var import_provider_utils12 = require("@ai-sdk/provider-utils");
|
3307
3303
|
|
3308
3304
|
// src/util/download.ts
|
3309
3305
|
async function download({ url }) {
|
@@ -3332,7 +3328,7 @@ async function download({ url }) {
|
|
3332
3328
|
|
3333
3329
|
// core/prompt/data-content.ts
|
3334
3330
|
var import_provider18 = require("@ai-sdk/provider");
|
3335
|
-
var
|
3331
|
+
var import_provider_utils11 = require("@ai-sdk/provider-utils");
|
3336
3332
|
var import_zod2 = require("zod");
|
3337
3333
|
|
3338
3334
|
// core/prompt/split-data-url.ts
|
@@ -3397,9 +3393,9 @@ function convertDataContentToBase64String(content) {
|
|
3397
3393
|
return content;
|
3398
3394
|
}
|
3399
3395
|
if (content instanceof ArrayBuffer) {
|
3400
|
-
return (0,
|
3396
|
+
return (0, import_provider_utils11.convertUint8ArrayToBase64)(new Uint8Array(content));
|
3401
3397
|
}
|
3402
|
-
return (0,
|
3398
|
+
return (0, import_provider_utils11.convertUint8ArrayToBase64)(content);
|
3403
3399
|
}
|
3404
3400
|
function convertDataContentToUint8Array(content) {
|
3405
3401
|
if (content instanceof Uint8Array) {
|
@@ -3407,7 +3403,7 @@ function convertDataContentToUint8Array(content) {
|
|
3407
3403
|
}
|
3408
3404
|
if (typeof content === "string") {
|
3409
3405
|
try {
|
3410
|
-
return (0,
|
3406
|
+
return (0, import_provider_utils11.convertBase64ToUint8Array)(content);
|
3411
3407
|
} catch (error) {
|
3412
3408
|
throw new InvalidDataContentError({
|
3413
3409
|
message: "Invalid data content. Content string is not a base64-encoded media.",
|
@@ -3511,7 +3507,7 @@ function convertToLanguageModelMessage(message, downloadedAssets) {
|
|
3511
3507
|
type: "tool-call",
|
3512
3508
|
toolCallId: part.toolCallId,
|
3513
3509
|
toolName: part.toolName,
|
3514
|
-
|
3510
|
+
input: part.input,
|
3515
3511
|
providerOptions
|
3516
3512
|
};
|
3517
3513
|
}
|
@@ -3527,7 +3523,7 @@ function convertToLanguageModelMessage(message, downloadedAssets) {
|
|
3527
3523
|
type: "tool-result",
|
3528
3524
|
toolCallId: part.toolCallId,
|
3529
3525
|
toolName: part.toolName,
|
3530
|
-
|
3526
|
+
output: part.output,
|
3531
3527
|
content: part.experimental_content,
|
3532
3528
|
isError: part.isError,
|
3533
3529
|
providerOptions: part.providerOptions
|
@@ -3558,7 +3554,7 @@ async function downloadAssets(messages, downloadImplementation, supportedUrls) {
|
|
3558
3554
|
}
|
3559
3555
|
return { mediaType, data };
|
3560
3556
|
}).filter(
|
3561
|
-
(part) => part.data instanceof URL && part.mediaType != null && !(0,
|
3557
|
+
(part) => part.data instanceof URL && part.mediaType != null && !(0, import_provider_utils12.isUrlSupported)({
|
3562
3558
|
url: part.data.toString(),
|
3563
3559
|
mediaType: part.mediaType,
|
3564
3560
|
supportedUrls
|
@@ -3742,7 +3738,7 @@ function resolveLanguageModel(model) {
|
|
3742
3738
|
|
3743
3739
|
// core/prompt/standardize-prompt.ts
|
3744
3740
|
var import_provider19 = require("@ai-sdk/provider");
|
3745
|
-
var
|
3741
|
+
var import_provider_utils13 = require("@ai-sdk/provider-utils");
|
3746
3742
|
var import_zod8 = require("zod");
|
3747
3743
|
|
3748
3744
|
// core/prompt/message.ts
|
@@ -3814,14 +3810,14 @@ var toolCallPartSchema = import_zod6.z.object({
|
|
3814
3810
|
type: import_zod6.z.literal("tool-call"),
|
3815
3811
|
toolCallId: import_zod6.z.string(),
|
3816
3812
|
toolName: import_zod6.z.string(),
|
3817
|
-
|
3813
|
+
input: import_zod6.z.unknown(),
|
3818
3814
|
providerOptions: providerMetadataSchema.optional()
|
3819
3815
|
});
|
3820
3816
|
var toolResultPartSchema = import_zod6.z.object({
|
3821
3817
|
type: import_zod6.z.literal("tool-result"),
|
3822
3818
|
toolCallId: import_zod6.z.string(),
|
3823
3819
|
toolName: import_zod6.z.string(),
|
3824
|
-
|
3820
|
+
output: import_zod6.z.unknown(),
|
3825
3821
|
content: toolResultContentSchema.optional(),
|
3826
3822
|
isError: import_zod6.z.boolean().optional(),
|
3827
3823
|
providerOptions: providerMetadataSchema.optional()
|
@@ -3914,7 +3910,7 @@ async function standardizePrompt(prompt) {
|
|
3914
3910
|
message: "messages must not be empty"
|
3915
3911
|
});
|
3916
3912
|
}
|
3917
|
-
const validationResult = await (0,
|
3913
|
+
const validationResult = await (0, import_provider_utils13.safeValidateTypes)({
|
3918
3914
|
value: messages,
|
3919
3915
|
schema: import_zod8.z.array(modelMessageSchema)
|
3920
3916
|
});
|
@@ -3962,7 +3958,7 @@ function stringifyForTelemetry(prompt) {
|
|
3962
3958
|
|
3963
3959
|
// core/generate-object/output-strategy.ts
|
3964
3960
|
var import_provider21 = require("@ai-sdk/provider");
|
3965
|
-
var
|
3961
|
+
var import_provider_utils14 = require("@ai-sdk/provider-utils");
|
3966
3962
|
|
3967
3963
|
// src/util/async-iterable-stream.ts
|
3968
3964
|
function createAsyncIterableStream(source) {
|
@@ -4018,7 +4014,7 @@ var objectOutputStrategy = (schema) => ({
|
|
4018
4014
|
};
|
4019
4015
|
},
|
4020
4016
|
async validateFinalResult(value) {
|
4021
|
-
return (0,
|
4017
|
+
return (0, import_provider_utils14.safeValidateTypes)({ value, schema });
|
4022
4018
|
},
|
4023
4019
|
createElementStream() {
|
4024
4020
|
throw new import_provider21.UnsupportedFunctionalityError({
|
@@ -4062,7 +4058,7 @@ var arrayOutputStrategy = (schema) => {
|
|
4062
4058
|
const resultArray = [];
|
4063
4059
|
for (let i = 0; i < inputArray.length; i++) {
|
4064
4060
|
const element = inputArray[i];
|
4065
|
-
const result = await (0,
|
4061
|
+
const result = await (0, import_provider_utils14.safeValidateTypes)({ value: element, schema });
|
4066
4062
|
if (i === inputArray.length - 1 && !isFinalDelta) {
|
4067
4063
|
continue;
|
4068
4064
|
}
|
@@ -4103,7 +4099,7 @@ var arrayOutputStrategy = (schema) => {
|
|
4103
4099
|
}
|
4104
4100
|
const inputArray = value.elements;
|
4105
4101
|
for (const element of inputArray) {
|
4106
|
-
const result = await (0,
|
4102
|
+
const result = await (0, import_provider_utils14.safeValidateTypes)({ value: element, schema });
|
4107
4103
|
if (!result.success) {
|
4108
4104
|
return result;
|
4109
4105
|
}
|
@@ -4221,9 +4217,9 @@ function getOutputStrategy({
|
|
4221
4217
|
}) {
|
4222
4218
|
switch (output) {
|
4223
4219
|
case "object":
|
4224
|
-
return objectOutputStrategy((0,
|
4220
|
+
return objectOutputStrategy((0, import_provider_utils14.asSchema)(schema));
|
4225
4221
|
case "array":
|
4226
|
-
return arrayOutputStrategy((0,
|
4222
|
+
return arrayOutputStrategy((0, import_provider_utils14.asSchema)(schema));
|
4227
4223
|
case "enum":
|
4228
4224
|
return enumOutputStrategy(enumValues);
|
4229
4225
|
case "no-schema":
|
@@ -4354,7 +4350,7 @@ function validateObjectGenerationInput({
|
|
4354
4350
|
}
|
4355
4351
|
|
4356
4352
|
// core/generate-object/generate-object.ts
|
4357
|
-
var originalGenerateId = (0,
|
4353
|
+
var originalGenerateId = (0, import_provider_utils15.createIdGenerator)({ prefix: "aiobj", size: 24 });
|
4358
4354
|
async function generateObject(options) {
|
4359
4355
|
const {
|
4360
4356
|
model: modelArg,
|
@@ -4532,7 +4528,7 @@ async function generateObject(options) {
|
|
4532
4528
|
request = (_a17 = generateResult.request) != null ? _a17 : {};
|
4533
4529
|
response = generateResult.responseData;
|
4534
4530
|
async function processResult(result2) {
|
4535
|
-
const parseResult = await (0,
|
4531
|
+
const parseResult = await (0, import_provider_utils15.safeParseJSON)({ text: result2 });
|
4536
4532
|
if (!parseResult.success) {
|
4537
4533
|
throw new NoObjectGeneratedError({
|
4538
4534
|
message: "No object generated: could not parse the response.",
|
@@ -4631,7 +4627,7 @@ var DefaultGenerateObjectResult = class {
|
|
4631
4627
|
};
|
4632
4628
|
|
4633
4629
|
// core/generate-object/stream-object.ts
|
4634
|
-
var
|
4630
|
+
var import_provider_utils16 = require("@ai-sdk/provider-utils");
|
4635
4631
|
|
4636
4632
|
// src/util/create-resolvable-promise.ts
|
4637
4633
|
function createResolvablePromise() {
|
@@ -4775,7 +4771,7 @@ function now() {
|
|
4775
4771
|
}
|
4776
4772
|
|
4777
4773
|
// core/generate-object/stream-object.ts
|
4778
|
-
var originalGenerateId2 = (0,
|
4774
|
+
var originalGenerateId2 = (0, import_provider_utils16.createIdGenerator)({ prefix: "aiobj", size: 24 });
|
4779
4775
|
function streamObject(options) {
|
4780
4776
|
const {
|
4781
4777
|
model,
|
@@ -5374,7 +5370,7 @@ var DefaultSpeechResult = class {
|
|
5374
5370
|
};
|
5375
5371
|
|
5376
5372
|
// core/generate-text/generate-text.ts
|
5377
|
-
var
|
5373
|
+
var import_provider_utils19 = require("@ai-sdk/provider-utils");
|
5378
5374
|
|
5379
5375
|
// src/util/as-array.ts
|
5380
5376
|
function asArray(value) {
|
@@ -5382,7 +5378,7 @@ function asArray(value) {
|
|
5382
5378
|
}
|
5383
5379
|
|
5384
5380
|
// core/prompt/prepare-tools-and-tool-choice.ts
|
5385
|
-
var
|
5381
|
+
var import_provider_utils17 = require("@ai-sdk/provider-utils");
|
5386
5382
|
|
5387
5383
|
// src/util/is-non-empty-object.ts
|
5388
5384
|
function isNonEmptyObject(object2) {
|
@@ -5414,11 +5410,18 @@ function prepareToolsAndToolChoice({
|
|
5414
5410
|
type: "function",
|
5415
5411
|
name: name17,
|
5416
5412
|
description: tool2.description,
|
5417
|
-
|
5413
|
+
inputSchema: (0, import_provider_utils17.asSchema)(tool2.inputSchema).jsonSchema
|
5414
|
+
};
|
5415
|
+
case "provider-defined-client":
|
5416
|
+
return {
|
5417
|
+
type: "provider-defined-client",
|
5418
|
+
name: name17,
|
5419
|
+
id: tool2.id,
|
5420
|
+
args: tool2.args
|
5418
5421
|
};
|
5419
|
-
case "provider-defined":
|
5422
|
+
case "provider-defined-server":
|
5420
5423
|
return {
|
5421
|
-
type: "provider-defined",
|
5424
|
+
type: "provider-defined-server",
|
5422
5425
|
name: name17,
|
5423
5426
|
id: tool2.id,
|
5424
5427
|
args: tool2.args
|
@@ -5484,7 +5487,7 @@ function asContent({
|
|
5484
5487
|
}
|
5485
5488
|
|
5486
5489
|
// core/generate-text/parse-tool-call.ts
|
5487
|
-
var
|
5490
|
+
var import_provider_utils18 = require("@ai-sdk/provider-utils");
|
5488
5491
|
async function parseToolCall({
|
5489
5492
|
toolCall,
|
5490
5493
|
tools,
|
@@ -5498,7 +5501,7 @@ async function parseToolCall({
|
|
5498
5501
|
try {
|
5499
5502
|
return await doParseToolCall({ toolCall, tools });
|
5500
5503
|
} catch (error) {
|
5501
|
-
if (repairToolCall == null || !(NoSuchToolError.isInstance(error) ||
|
5504
|
+
if (repairToolCall == null || !(NoSuchToolError.isInstance(error) || InvalidToolInputError.isInstance(error))) {
|
5502
5505
|
throw error;
|
5503
5506
|
}
|
5504
5507
|
let repairedToolCall = null;
|
@@ -5506,9 +5509,9 @@ async function parseToolCall({
|
|
5506
5509
|
repairedToolCall = await repairToolCall({
|
5507
5510
|
toolCall,
|
5508
5511
|
tools,
|
5509
|
-
|
5510
|
-
const {
|
5511
|
-
return (0,
|
5512
|
+
inputSchema: ({ toolName }) => {
|
5513
|
+
const { inputSchema } = tools[toolName];
|
5514
|
+
return (0, import_provider_utils18.asSchema)(inputSchema).jsonSchema;
|
5512
5515
|
},
|
5513
5516
|
system,
|
5514
5517
|
messages,
|
@@ -5538,12 +5541,12 @@ async function doParseToolCall({
|
|
5538
5541
|
availableTools: Object.keys(tools)
|
5539
5542
|
});
|
5540
5543
|
}
|
5541
|
-
const schema = (0,
|
5542
|
-
const parseResult = toolCall.
|
5544
|
+
const schema = (0, import_provider_utils18.asSchema)(tool2.inputSchema);
|
5545
|
+
const parseResult = toolCall.input.trim() === "" ? await (0, import_provider_utils18.safeValidateTypes)({ value: {}, schema }) : await (0, import_provider_utils18.safeParseJSON)({ text: toolCall.input, schema });
|
5543
5546
|
if (parseResult.success === false) {
|
5544
|
-
throw new
|
5547
|
+
throw new InvalidToolInputError({
|
5545
5548
|
toolName,
|
5546
|
-
|
5549
|
+
toolInput: toolCall.input,
|
5547
5550
|
cause: parseResult.error
|
5548
5551
|
});
|
5549
5552
|
}
|
@@ -5551,7 +5554,7 @@ async function doParseToolCall({
|
|
5551
5554
|
type: "tool-call",
|
5552
5555
|
toolCallId: toolCall.toolCallId,
|
5553
5556
|
toolName,
|
5554
|
-
|
5557
|
+
input: parseResult.value
|
5555
5558
|
};
|
5556
5559
|
}
|
5557
5560
|
|
@@ -5654,15 +5657,15 @@ function toResponseMessages({
|
|
5654
5657
|
type: "tool-result",
|
5655
5658
|
toolCallId: toolResult.toolCallId,
|
5656
5659
|
toolName: toolResult.toolName,
|
5657
|
-
|
5660
|
+
output: tool2.experimental_toToolResultContent(toolResult.output),
|
5658
5661
|
experimental_content: tool2.experimental_toToolResultContent(
|
5659
|
-
toolResult.
|
5662
|
+
toolResult.output
|
5660
5663
|
)
|
5661
5664
|
} : {
|
5662
5665
|
type: "tool-result",
|
5663
5666
|
toolCallId: toolResult.toolCallId,
|
5664
5667
|
toolName: toolResult.toolName,
|
5665
|
-
|
5668
|
+
output: toolResult.output
|
5666
5669
|
};
|
5667
5670
|
});
|
5668
5671
|
if (toolResultContent.length > 0) {
|
@@ -5675,7 +5678,7 @@ function toResponseMessages({
|
|
5675
5678
|
}
|
5676
5679
|
|
5677
5680
|
// core/generate-text/generate-text.ts
|
5678
|
-
var originalGenerateId3 = (0,
|
5681
|
+
var originalGenerateId3 = (0, import_provider_utils19.createIdGenerator)({
|
5679
5682
|
prefix: "aitxt",
|
5680
5683
|
size: 24
|
5681
5684
|
});
|
@@ -5968,11 +5971,11 @@ async function executeTools({
|
|
5968
5971
|
abortSignal
|
5969
5972
|
}) {
|
5970
5973
|
const toolResults = await Promise.all(
|
5971
|
-
toolCalls.map(async ({ toolCallId, toolName,
|
5974
|
+
toolCalls.map(async ({ toolCallId, toolName, input }) => {
|
5972
5975
|
const tool2 = tools[toolName];
|
5973
|
-
if ((tool2 == null ? void 0 : tool2.
|
5974
|
-
await tool2.
|
5975
|
-
|
5976
|
+
if ((tool2 == null ? void 0 : tool2.onInputAvailable) != null) {
|
5977
|
+
await tool2.onInputAvailable({
|
5978
|
+
input,
|
5976
5979
|
toolCallId,
|
5977
5980
|
messages,
|
5978
5981
|
abortSignal
|
@@ -5992,15 +5995,15 @@ async function executeTools({
|
|
5992
5995
|
}),
|
5993
5996
|
"ai.toolCall.name": toolName,
|
5994
5997
|
"ai.toolCall.id": toolCallId,
|
5995
|
-
"ai.toolCall.
|
5996
|
-
output: () => JSON.stringify(
|
5998
|
+
"ai.toolCall.input": {
|
5999
|
+
output: () => JSON.stringify(input)
|
5997
6000
|
}
|
5998
6001
|
}
|
5999
6002
|
}),
|
6000
6003
|
tracer,
|
6001
6004
|
fn: async (span) => {
|
6002
6005
|
try {
|
6003
|
-
const result2 = await tool2.execute(
|
6006
|
+
const result2 = await tool2.execute(input, {
|
6004
6007
|
toolCallId,
|
6005
6008
|
messages,
|
6006
6009
|
abortSignal
|
@@ -6023,7 +6026,7 @@ async function executeTools({
|
|
6023
6026
|
throw new ToolExecutionError({
|
6024
6027
|
toolCallId,
|
6025
6028
|
toolName,
|
6026
|
-
|
6029
|
+
toolInput: input,
|
6027
6030
|
cause: error
|
6028
6031
|
});
|
6029
6032
|
}
|
@@ -6033,8 +6036,8 @@ async function executeTools({
|
|
6033
6036
|
type: "tool-result",
|
6034
6037
|
toolCallId,
|
6035
6038
|
toolName,
|
6036
|
-
|
6037
|
-
result
|
6039
|
+
input,
|
6040
|
+
output: result
|
6038
6041
|
};
|
6039
6042
|
})
|
6040
6043
|
);
|
@@ -6124,7 +6127,7 @@ function asToolCalls(content) {
|
|
6124
6127
|
toolCallType: toolCall.toolCallType,
|
6125
6128
|
toolCallId: toolCall.toolCallId,
|
6126
6129
|
toolName: toolCall.toolName,
|
6127
|
-
|
6130
|
+
input: toolCall.input
|
6128
6131
|
}));
|
6129
6132
|
}
|
6130
6133
|
|
@@ -6134,7 +6137,7 @@ __export(output_exports, {
|
|
6134
6137
|
object: () => object,
|
6135
6138
|
text: () => text
|
6136
6139
|
});
|
6137
|
-
var
|
6140
|
+
var import_provider_utils20 = require("@ai-sdk/provider-utils");
|
6138
6141
|
var text = () => ({
|
6139
6142
|
type: "text",
|
6140
6143
|
responseFormat: { type: "text" },
|
@@ -6148,7 +6151,7 @@ var text = () => ({
|
|
6148
6151
|
var object = ({
|
6149
6152
|
schema: inputSchema
|
6150
6153
|
}) => {
|
6151
|
-
const schema = (0,
|
6154
|
+
const schema = (0, import_provider_utils20.asSchema)(inputSchema);
|
6152
6155
|
return {
|
6153
6156
|
type: "object",
|
6154
6157
|
responseFormat: {
|
@@ -6174,7 +6177,7 @@ var object = ({
|
|
6174
6177
|
}
|
6175
6178
|
},
|
6176
6179
|
async parseOutput({ text: text2 }, context) {
|
6177
|
-
const parseResult = await (0,
|
6180
|
+
const parseResult = await (0, import_provider_utils20.safeParseJSON)({ text: text2 });
|
6178
6181
|
if (!parseResult.success) {
|
6179
6182
|
throw new NoObjectGeneratedError({
|
6180
6183
|
message: "No object generated: could not parse the response.",
|
@@ -6185,7 +6188,7 @@ var object = ({
|
|
6185
6188
|
finishReason: context.finishReason
|
6186
6189
|
});
|
6187
6190
|
}
|
6188
|
-
const validationResult = await (0,
|
6191
|
+
const validationResult = await (0, import_provider_utils20.safeValidateTypes)({
|
6189
6192
|
value: parseResult.value,
|
6190
6193
|
schema
|
6191
6194
|
});
|
@@ -6205,7 +6208,7 @@ var object = ({
|
|
6205
6208
|
};
|
6206
6209
|
|
6207
6210
|
// core/generate-text/smooth-stream.ts
|
6208
|
-
var
|
6211
|
+
var import_provider_utils21 = require("@ai-sdk/provider-utils");
|
6209
6212
|
var import_provider24 = require("@ai-sdk/provider");
|
6210
6213
|
var CHUNKING_REGEXPS = {
|
6211
6214
|
word: /\S+\s+/m,
|
@@ -6214,7 +6217,7 @@ var CHUNKING_REGEXPS = {
|
|
6214
6217
|
function smoothStream({
|
6215
6218
|
delayInMs = 10,
|
6216
6219
|
chunking = "word",
|
6217
|
-
_internal: { delay: delay2 =
|
6220
|
+
_internal: { delay: delay2 = import_provider_utils21.delay } = {}
|
6218
6221
|
} = {}) {
|
6219
6222
|
let detectChunk;
|
6220
6223
|
if (typeof chunking === "function") {
|
@@ -6274,10 +6277,10 @@ function smoothStream({
|
|
6274
6277
|
}
|
6275
6278
|
|
6276
6279
|
// core/generate-text/stream-text.ts
|
6277
|
-
var
|
6280
|
+
var import_provider_utils23 = require("@ai-sdk/provider-utils");
|
6278
6281
|
|
6279
6282
|
// core/generate-text/run-tools-transformation.ts
|
6280
|
-
var
|
6283
|
+
var import_provider_utils22 = require("@ai-sdk/provider-utils");
|
6281
6284
|
function runToolsTransformation({
|
6282
6285
|
tools,
|
6283
6286
|
generatorStream,
|
@@ -6348,7 +6351,7 @@ function runToolsTransformation({
|
|
6348
6351
|
type: "tool-call-delta",
|
6349
6352
|
toolCallId: chunk.toolCallId,
|
6350
6353
|
toolName: chunk.toolName,
|
6351
|
-
|
6354
|
+
inputTextDelta: chunk.inputTextDelta
|
6352
6355
|
});
|
6353
6356
|
break;
|
6354
6357
|
}
|
@@ -6363,16 +6366,16 @@ function runToolsTransformation({
|
|
6363
6366
|
});
|
6364
6367
|
controller.enqueue(toolCall);
|
6365
6368
|
const tool2 = tools[toolCall.toolName];
|
6366
|
-
if (tool2.
|
6367
|
-
await tool2.
|
6368
|
-
|
6369
|
+
if (tool2.onInputAvailable != null) {
|
6370
|
+
await tool2.onInputAvailable({
|
6371
|
+
input: toolCall.input,
|
6369
6372
|
toolCallId: toolCall.toolCallId,
|
6370
6373
|
messages,
|
6371
6374
|
abortSignal
|
6372
6375
|
});
|
6373
6376
|
}
|
6374
6377
|
if (tool2.execute != null) {
|
6375
|
-
const toolExecutionId = (0,
|
6378
|
+
const toolExecutionId = (0, import_provider_utils22.generateId)();
|
6376
6379
|
outstandingToolResults.add(toolExecutionId);
|
6377
6380
|
recordSpan({
|
6378
6381
|
name: "ai.toolCall",
|
@@ -6385,22 +6388,22 @@ function runToolsTransformation({
|
|
6385
6388
|
}),
|
6386
6389
|
"ai.toolCall.name": toolCall.toolName,
|
6387
6390
|
"ai.toolCall.id": toolCall.toolCallId,
|
6388
|
-
"ai.toolCall.
|
6389
|
-
output: () => JSON.stringify(toolCall.
|
6391
|
+
"ai.toolCall.input": {
|
6392
|
+
output: () => JSON.stringify(toolCall.input)
|
6390
6393
|
}
|
6391
6394
|
}
|
6392
6395
|
}),
|
6393
6396
|
tracer,
|
6394
|
-
fn: async (span) => tool2.execute(toolCall.
|
6397
|
+
fn: async (span) => tool2.execute(toolCall.input, {
|
6395
6398
|
toolCallId: toolCall.toolCallId,
|
6396
6399
|
messages,
|
6397
6400
|
abortSignal
|
6398
6401
|
}).then(
|
6399
|
-
(
|
6402
|
+
(output) => {
|
6400
6403
|
toolResultsStreamController.enqueue({
|
6401
6404
|
...toolCall,
|
6402
6405
|
type: "tool-result",
|
6403
|
-
|
6406
|
+
output
|
6404
6407
|
});
|
6405
6408
|
outstandingToolResults.delete(toolExecutionId);
|
6406
6409
|
attemptClose();
|
@@ -6409,8 +6412,8 @@ function runToolsTransformation({
|
|
6409
6412
|
selectTelemetryAttributes({
|
6410
6413
|
telemetry,
|
6411
6414
|
attributes: {
|
6412
|
-
"ai.toolCall.
|
6413
|
-
output: () => JSON.stringify(
|
6415
|
+
"ai.toolCall.output": {
|
6416
|
+
output: () => JSON.stringify(output)
|
6414
6417
|
}
|
6415
6418
|
}
|
6416
6419
|
})
|
@@ -6424,7 +6427,7 @@ function runToolsTransformation({
|
|
6424
6427
|
error: new ToolExecutionError({
|
6425
6428
|
toolCallId: toolCall.toolCallId,
|
6426
6429
|
toolName: toolCall.toolName,
|
6427
|
-
|
6430
|
+
toolInput: toolCall.input,
|
6428
6431
|
cause: error
|
6429
6432
|
})
|
6430
6433
|
});
|
@@ -6480,8 +6483,20 @@ function runToolsTransformation({
|
|
6480
6483
|
});
|
6481
6484
|
}
|
6482
6485
|
|
6486
|
+
// src/ui-message-stream/get-response-ui-message-id.ts
|
6487
|
+
function getResponseUIMessageId({
|
6488
|
+
originalMessages,
|
6489
|
+
responseMessageId
|
6490
|
+
}) {
|
6491
|
+
if (originalMessages == null) {
|
6492
|
+
return void 0;
|
6493
|
+
}
|
6494
|
+
const lastMessage = originalMessages[originalMessages.length - 1];
|
6495
|
+
return (lastMessage == null ? void 0 : lastMessage.role) === "assistant" ? lastMessage.id : typeof responseMessageId === "function" ? responseMessageId() : responseMessageId;
|
6496
|
+
}
|
6497
|
+
|
6483
6498
|
// core/generate-text/stream-text.ts
|
6484
|
-
var originalGenerateId4 = (0,
|
6499
|
+
var originalGenerateId4 = (0, import_provider_utils23.createIdGenerator)({
|
6485
6500
|
prefix: "aitxt",
|
6486
6501
|
size: 24
|
6487
6502
|
});
|
@@ -6644,7 +6659,7 @@ var DefaultStreamTextResult = class {
|
|
6644
6659
|
async transform(chunk, controller) {
|
6645
6660
|
controller.enqueue(chunk);
|
6646
6661
|
const { part } = chunk;
|
6647
|
-
if (part.type === "text" || part.type === "reasoning" || part.type === "source" || part.type === "tool-call" || part.type === "tool-result" || part.type === "tool-call-streaming-start" || part.type === "tool-call-delta") {
|
6662
|
+
if (part.type === "text" || part.type === "reasoning" || part.type === "source" || part.type === "tool-call" || part.type === "tool-result" || part.type === "tool-call-streaming-start" || part.type === "tool-call-delta" || part.type === "raw") {
|
6648
6663
|
await (onChunk == null ? void 0 : onChunk({ chunk: part }));
|
6649
6664
|
}
|
6650
6665
|
if (part.type === "error") {
|
@@ -7064,8 +7079,8 @@ var DefaultStreamTextResult = class {
|
|
7064
7079
|
}
|
7065
7080
|
case "tool-call-streaming-start": {
|
7066
7081
|
const tool2 = tools == null ? void 0 : tools[chunk.toolName];
|
7067
|
-
if ((tool2 == null ? void 0 : tool2.
|
7068
|
-
await tool2.
|
7082
|
+
if ((tool2 == null ? void 0 : tool2.onInputStart) != null) {
|
7083
|
+
await tool2.onInputStart({
|
7069
7084
|
toolCallId: chunk.toolCallId,
|
7070
7085
|
messages: stepInputMessages,
|
7071
7086
|
abortSignal
|
@@ -7076,9 +7091,9 @@ var DefaultStreamTextResult = class {
|
|
7076
7091
|
}
|
7077
7092
|
case "tool-call-delta": {
|
7078
7093
|
const tool2 = tools == null ? void 0 : tools[chunk.toolName];
|
7079
|
-
if ((tool2 == null ? void 0 : tool2.
|
7080
|
-
await tool2.
|
7081
|
-
|
7094
|
+
if ((tool2 == null ? void 0 : tool2.onInputDelta) != null) {
|
7095
|
+
await tool2.onInputDelta({
|
7096
|
+
inputTextDelta: chunk.inputTextDelta,
|
7082
7097
|
toolCallId: chunk.toolCallId,
|
7083
7098
|
messages: stepInputMessages,
|
7084
7099
|
abortSignal
|
@@ -7093,7 +7108,9 @@ var DefaultStreamTextResult = class {
|
|
7093
7108
|
break;
|
7094
7109
|
}
|
7095
7110
|
case "raw": {
|
7096
|
-
|
7111
|
+
if (includeRawChunks2) {
|
7112
|
+
controller.enqueue(chunk);
|
7113
|
+
}
|
7097
7114
|
break;
|
7098
7115
|
}
|
7099
7116
|
default: {
|
@@ -7316,23 +7333,24 @@ var DefaultStreamTextResult = class {
|
|
7316
7333
|
);
|
7317
7334
|
}
|
7318
7335
|
toUIMessageStream({
|
7319
|
-
|
7320
|
-
originalMessages = [],
|
7336
|
+
originalMessages,
|
7321
7337
|
onFinish,
|
7322
7338
|
messageMetadata,
|
7323
|
-
sendReasoning =
|
7339
|
+
sendReasoning = true,
|
7324
7340
|
sendSources = false,
|
7325
7341
|
sendStart = true,
|
7326
7342
|
sendFinish = true,
|
7327
7343
|
onError = () => "An error occurred."
|
7328
7344
|
// mask error messages for safety by default
|
7329
7345
|
} = {}) {
|
7330
|
-
const
|
7331
|
-
|
7332
|
-
|
7346
|
+
const responseMessageId = getResponseUIMessageId({
|
7347
|
+
originalMessages,
|
7348
|
+
responseMessageId: this.generateId
|
7349
|
+
});
|
7333
7350
|
const baseStream = this.fullStream.pipeThrough(
|
7334
7351
|
new TransformStream({
|
7335
7352
|
transform: async (part, controller) => {
|
7353
|
+
const messageMetadataValue = messageMetadata == null ? void 0 : messageMetadata({ part });
|
7336
7354
|
const partType = part.type;
|
7337
7355
|
switch (partType) {
|
7338
7356
|
case "text": {
|
@@ -7390,7 +7408,7 @@ var DefaultStreamTextResult = class {
|
|
7390
7408
|
}
|
7391
7409
|
case "tool-call-streaming-start": {
|
7392
7410
|
controller.enqueue({
|
7393
|
-
type: "tool-
|
7411
|
+
type: "tool-input-start",
|
7394
7412
|
toolCallId: part.toolCallId,
|
7395
7413
|
toolName: part.toolName
|
7396
7414
|
});
|
@@ -7398,26 +7416,26 @@ var DefaultStreamTextResult = class {
|
|
7398
7416
|
}
|
7399
7417
|
case "tool-call-delta": {
|
7400
7418
|
controller.enqueue({
|
7401
|
-
type: "tool-
|
7419
|
+
type: "tool-input-delta",
|
7402
7420
|
toolCallId: part.toolCallId,
|
7403
|
-
|
7421
|
+
inputTextDelta: part.inputTextDelta
|
7404
7422
|
});
|
7405
7423
|
break;
|
7406
7424
|
}
|
7407
7425
|
case "tool-call": {
|
7408
7426
|
controller.enqueue({
|
7409
|
-
type: "tool-
|
7427
|
+
type: "tool-input-available",
|
7410
7428
|
toolCallId: part.toolCallId,
|
7411
7429
|
toolName: part.toolName,
|
7412
|
-
|
7430
|
+
input: part.input
|
7413
7431
|
});
|
7414
7432
|
break;
|
7415
7433
|
}
|
7416
7434
|
case "tool-result": {
|
7417
7435
|
controller.enqueue({
|
7418
|
-
type: "tool-
|
7436
|
+
type: "tool-output-available",
|
7419
7437
|
toolCallId: part.toolCallId,
|
7420
|
-
|
7438
|
+
output: part.output
|
7421
7439
|
});
|
7422
7440
|
break;
|
7423
7441
|
}
|
@@ -7429,38 +7447,28 @@ var DefaultStreamTextResult = class {
|
|
7429
7447
|
break;
|
7430
7448
|
}
|
7431
7449
|
case "start-step": {
|
7432
|
-
|
7433
|
-
controller.enqueue({
|
7434
|
-
type: "start-step",
|
7435
|
-
metadata
|
7436
|
-
});
|
7450
|
+
controller.enqueue({ type: "start-step" });
|
7437
7451
|
break;
|
7438
7452
|
}
|
7439
7453
|
case "finish-step": {
|
7440
|
-
|
7441
|
-
controller.enqueue({
|
7442
|
-
type: "finish-step",
|
7443
|
-
metadata
|
7444
|
-
});
|
7454
|
+
controller.enqueue({ type: "finish-step" });
|
7445
7455
|
break;
|
7446
7456
|
}
|
7447
7457
|
case "start": {
|
7448
7458
|
if (sendStart) {
|
7449
|
-
const metadata = messageMetadata == null ? void 0 : messageMetadata({ part });
|
7450
7459
|
controller.enqueue({
|
7451
7460
|
type: "start",
|
7452
|
-
messageId,
|
7453
|
-
|
7461
|
+
messageId: responseMessageId,
|
7462
|
+
messageMetadata: messageMetadataValue
|
7454
7463
|
});
|
7455
7464
|
}
|
7456
7465
|
break;
|
7457
7466
|
}
|
7458
7467
|
case "finish": {
|
7459
7468
|
if (sendFinish) {
|
7460
|
-
const metadata = messageMetadata == null ? void 0 : messageMetadata({ part });
|
7461
7469
|
controller.enqueue({
|
7462
7470
|
type: "finish",
|
7463
|
-
|
7471
|
+
messageMetadata: messageMetadataValue
|
7464
7472
|
});
|
7465
7473
|
}
|
7466
7474
|
break;
|
@@ -7473,18 +7481,23 @@ var DefaultStreamTextResult = class {
|
|
7473
7481
|
throw new Error(`Unknown chunk type: ${exhaustiveCheck}`);
|
7474
7482
|
}
|
7475
7483
|
}
|
7484
|
+
if (messageMetadataValue != null && partType !== "start" && partType !== "finish") {
|
7485
|
+
controller.enqueue({
|
7486
|
+
type: "message-metadata",
|
7487
|
+
messageMetadata: messageMetadataValue
|
7488
|
+
});
|
7489
|
+
}
|
7476
7490
|
}
|
7477
7491
|
})
|
7478
7492
|
);
|
7479
7493
|
return handleUIMessageStreamFinish({
|
7480
7494
|
stream: baseStream,
|
7481
|
-
|
7495
|
+
messageId: responseMessageId != null ? responseMessageId : this.generateId(),
|
7482
7496
|
originalMessages,
|
7483
7497
|
onFinish
|
7484
7498
|
});
|
7485
7499
|
}
|
7486
7500
|
pipeUIMessageStreamToResponse(response, {
|
7487
|
-
newMessageId,
|
7488
7501
|
originalMessages,
|
7489
7502
|
onFinish,
|
7490
7503
|
messageMetadata,
|
@@ -7498,7 +7511,6 @@ var DefaultStreamTextResult = class {
|
|
7498
7511
|
pipeUIMessageStreamToResponse({
|
7499
7512
|
response,
|
7500
7513
|
stream: this.toUIMessageStream({
|
7501
|
-
newMessageId,
|
7502
7514
|
originalMessages,
|
7503
7515
|
onFinish,
|
7504
7516
|
messageMetadata,
|
@@ -7519,7 +7531,6 @@ var DefaultStreamTextResult = class {
|
|
7519
7531
|
});
|
7520
7532
|
}
|
7521
7533
|
toUIMessageStreamResponse({
|
7522
|
-
newMessageId,
|
7523
7534
|
originalMessages,
|
7524
7535
|
onFinish,
|
7525
7536
|
messageMetadata,
|
@@ -7532,7 +7543,6 @@ var DefaultStreamTextResult = class {
|
|
7532
7543
|
} = {}) {
|
7533
7544
|
return createUIMessageStreamResponse({
|
7534
7545
|
stream: this.toUIMessageStream({
|
7535
|
-
newMessageId,
|
7536
7546
|
originalMessages,
|
7537
7547
|
onFinish,
|
7538
7548
|
messageMetadata,
|
@@ -7929,7 +7939,7 @@ var DefaultProviderRegistry = class {
|
|
7929
7939
|
};
|
7930
7940
|
|
7931
7941
|
// core/tool/mcp/mcp-client.ts
|
7932
|
-
var
|
7942
|
+
var import_provider_utils25 = require("@ai-sdk/provider-utils");
|
7933
7943
|
|
7934
7944
|
// core/tool/tool.ts
|
7935
7945
|
function tool(tool2) {
|
@@ -7937,7 +7947,7 @@ function tool(tool2) {
|
|
7937
7947
|
}
|
7938
7948
|
|
7939
7949
|
// core/tool/mcp/mcp-sse-transport.ts
|
7940
|
-
var
|
7950
|
+
var import_provider_utils24 = require("@ai-sdk/provider-utils");
|
7941
7951
|
|
7942
7952
|
// core/tool/mcp/json-rpc-message.ts
|
7943
7953
|
var import_zod10 = require("zod");
|
@@ -8108,7 +8118,7 @@ var SseMCPTransport = class {
|
|
8108
8118
|
(_b = this.onerror) == null ? void 0 : _b.call(this, error);
|
8109
8119
|
return reject(error);
|
8110
8120
|
}
|
8111
|
-
const stream = response.body.pipeThrough(new TextDecoderStream()).pipeThrough((0,
|
8121
|
+
const stream = response.body.pipeThrough(new TextDecoderStream()).pipeThrough((0, import_provider_utils24.createEventSourceParserStream)());
|
8112
8122
|
const reader = stream.getReader();
|
8113
8123
|
const processEvents = async () => {
|
8114
8124
|
var _a18, _b2, _c2;
|
@@ -8432,15 +8442,14 @@ var MCPClient = class {
|
|
8432
8442
|
if (schemas !== "automatic" && !(name17 in schemas)) {
|
8433
8443
|
continue;
|
8434
8444
|
}
|
8435
|
-
const parameters = schemas === "automatic" ? (0, import_provider_utils24.jsonSchema)({
|
8436
|
-
...inputSchema,
|
8437
|
-
properties: (_a17 = inputSchema.properties) != null ? _a17 : {},
|
8438
|
-
additionalProperties: false
|
8439
|
-
}) : schemas[name17].parameters;
|
8440
8445
|
const self = this;
|
8441
8446
|
const toolWithExecute = tool({
|
8442
8447
|
description,
|
8443
|
-
|
8448
|
+
inputSchema: schemas === "automatic" ? (0, import_provider_utils25.jsonSchema)({
|
8449
|
+
...inputSchema,
|
8450
|
+
properties: (_a17 = inputSchema.properties) != null ? _a17 : {},
|
8451
|
+
additionalProperties: false
|
8452
|
+
}) : schemas[name17].inputSchema,
|
8444
8453
|
execute: async (args, options) => {
|
8445
8454
|
var _a18;
|
8446
8455
|
(_a18 = options == null ? void 0 : options.abortSignal) == null ? void 0 : _a18.throwIfAborted();
|
@@ -8573,7 +8582,7 @@ var DefaultTranscriptionResult = class {
|
|
8573
8582
|
InvalidPromptError,
|
8574
8583
|
InvalidResponseDataError,
|
8575
8584
|
InvalidStreamPartError,
|
8576
|
-
|
8585
|
+
InvalidToolInputError,
|
8577
8586
|
JSONParseError,
|
8578
8587
|
JsonToSseTransformStream,
|
8579
8588
|
LoadAPIKeyError,
|
@@ -8626,9 +8635,10 @@ var DefaultTranscriptionResult = class {
|
|
8626
8635
|
generateObject,
|
8627
8636
|
generateText,
|
8628
8637
|
getTextFromDataUrl,
|
8629
|
-
|
8638
|
+
getToolName,
|
8630
8639
|
hasToolCall,
|
8631
8640
|
isDeepEqualData,
|
8641
|
+
isToolUIPart,
|
8632
8642
|
jsonSchema,
|
8633
8643
|
modelMessageSchema,
|
8634
8644
|
parsePartialJson,
|