ai 5.0.0-alpha.12 → 5.0.0-alpha.13
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 +17 -0
- package/dist/index.d.mts +106 -117
- package/dist/index.d.ts +106 -117
- package/dist/index.js +261 -255
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +204 -197
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
@@ -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");
|
@@ -540,42 +541,45 @@ var import_provider_utils = require("@ai-sdk/provider-utils");
|
|
540
541
|
// src/ui-message-stream/ui-message-stream-parts.ts
|
541
542
|
var import_zod = require("zod");
|
542
543
|
var uiMessageStreamPartSchema = import_zod.z.union([
|
543
|
-
import_zod.z.
|
544
|
+
import_zod.z.strictObject({
|
544
545
|
type: import_zod.z.literal("text"),
|
545
546
|
text: import_zod.z.string()
|
546
547
|
}),
|
547
|
-
import_zod.z.
|
548
|
+
import_zod.z.strictObject({
|
548
549
|
type: import_zod.z.literal("error"),
|
549
550
|
errorText: import_zod.z.string()
|
550
551
|
}),
|
551
|
-
import_zod.z.
|
552
|
+
import_zod.z.strictObject({
|
552
553
|
type: import_zod.z.literal("tool-call-streaming-start"),
|
553
554
|
toolCallId: import_zod.z.string(),
|
554
555
|
toolName: import_zod.z.string()
|
555
556
|
}),
|
556
|
-
import_zod.z.
|
557
|
+
import_zod.z.strictObject({
|
557
558
|
type: import_zod.z.literal("tool-call-delta"),
|
558
559
|
toolCallId: import_zod.z.string(),
|
559
560
|
argsTextDelta: import_zod.z.string()
|
560
561
|
}),
|
561
|
-
import_zod.z.
|
562
|
+
import_zod.z.strictObject({
|
562
563
|
type: import_zod.z.literal("tool-call"),
|
563
564
|
toolCallId: import_zod.z.string(),
|
564
565
|
toolName: import_zod.z.string(),
|
565
566
|
args: import_zod.z.unknown()
|
566
567
|
}),
|
567
|
-
import_zod.z.
|
568
|
+
import_zod.z.strictObject({
|
568
569
|
type: import_zod.z.literal("tool-result"),
|
569
570
|
toolCallId: import_zod.z.string(),
|
570
571
|
result: import_zod.z.unknown(),
|
571
572
|
providerMetadata: import_zod.z.any().optional()
|
572
573
|
}),
|
573
|
-
import_zod.z.
|
574
|
+
import_zod.z.strictObject({
|
574
575
|
type: import_zod.z.literal("reasoning"),
|
575
576
|
text: import_zod.z.string(),
|
576
577
|
providerMetadata: import_zod.z.record(import_zod.z.any()).optional()
|
577
578
|
}),
|
578
|
-
import_zod.z.
|
579
|
+
import_zod.z.strictObject({
|
580
|
+
type: import_zod.z.literal("reasoning-part-finish")
|
581
|
+
}),
|
582
|
+
import_zod.z.strictObject({
|
579
583
|
type: import_zod.z.literal("source-url"),
|
580
584
|
sourceId: import_zod.z.string(),
|
581
585
|
url: import_zod.z.string(),
|
@@ -583,7 +587,7 @@ var uiMessageStreamPartSchema = import_zod.z.union([
|
|
583
587
|
providerMetadata: import_zod.z.any().optional()
|
584
588
|
// Use z.any() for generic metadata
|
585
589
|
}),
|
586
|
-
import_zod.z.
|
590
|
+
import_zod.z.strictObject({
|
587
591
|
type: import_zod.z.literal("source-document"),
|
588
592
|
sourceId: import_zod.z.string(),
|
589
593
|
mediaType: import_zod.z.string(),
|
@@ -592,39 +596,34 @@ var uiMessageStreamPartSchema = import_zod.z.union([
|
|
592
596
|
providerMetadata: import_zod.z.any().optional()
|
593
597
|
// Use z.any() for generic metadata
|
594
598
|
}),
|
595
|
-
import_zod.z.
|
599
|
+
import_zod.z.strictObject({
|
596
600
|
type: import_zod.z.literal("file"),
|
597
601
|
url: import_zod.z.string(),
|
598
602
|
mediaType: import_zod.z.string()
|
599
603
|
}),
|
600
|
-
import_zod.z.
|
604
|
+
import_zod.z.strictObject({
|
601
605
|
type: import_zod.z.string().startsWith("data-"),
|
602
606
|
id: import_zod.z.string().optional(),
|
603
607
|
data: import_zod.z.unknown()
|
604
608
|
}),
|
605
|
-
import_zod.z.
|
606
|
-
type: import_zod.z.literal("
|
607
|
-
value: import_zod.z.object({ metadata: import_zod.z.unknown() })
|
609
|
+
import_zod.z.strictObject({
|
610
|
+
type: import_zod.z.literal("start-step")
|
608
611
|
}),
|
609
|
-
import_zod.z.
|
610
|
-
type: import_zod.z.literal("
|
611
|
-
metadata: import_zod.z.unknown().optional()
|
612
|
+
import_zod.z.strictObject({
|
613
|
+
type: import_zod.z.literal("finish-step")
|
612
614
|
}),
|
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({
|
615
|
+
import_zod.z.strictObject({
|
618
616
|
type: import_zod.z.literal("start"),
|
619
617
|
messageId: import_zod.z.string().optional(),
|
620
|
-
|
618
|
+
messageMetadata: import_zod.z.unknown().optional()
|
621
619
|
}),
|
622
|
-
import_zod.z.
|
620
|
+
import_zod.z.strictObject({
|
623
621
|
type: import_zod.z.literal("finish"),
|
624
|
-
|
622
|
+
messageMetadata: import_zod.z.unknown().optional()
|
625
623
|
}),
|
626
|
-
import_zod.z.
|
627
|
-
type: import_zod.z.literal("
|
624
|
+
import_zod.z.strictObject({
|
625
|
+
type: import_zod.z.literal("message-metadata"),
|
626
|
+
messageMetadata: import_zod.z.unknown()
|
628
627
|
})
|
629
628
|
]);
|
630
629
|
function isDataUIMessageStreamPart(part) {
|
@@ -1314,27 +1313,26 @@ async function parsePartialJson(jsonText) {
|
|
1314
1313
|
return { value: void 0, state: "failed-parse" };
|
1315
1314
|
}
|
1316
1315
|
|
1317
|
-
// src/ui/
|
1318
|
-
function
|
1319
|
-
return
|
1320
|
-
|
1321
|
-
|
1316
|
+
// src/ui/ui-messages.ts
|
1317
|
+
function isToolUIPart(part) {
|
1318
|
+
return part.type.startsWith("tool-");
|
1319
|
+
}
|
1320
|
+
function getToolName(part) {
|
1321
|
+
return part.type.split("-")[1];
|
1322
1322
|
}
|
1323
1323
|
|
1324
1324
|
// src/ui/process-ui-message-stream.ts
|
1325
1325
|
function createStreamingUIMessageState({
|
1326
1326
|
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
|
-
};
|
1327
|
+
messageId
|
1328
|
+
}) {
|
1336
1329
|
return {
|
1337
|
-
message
|
1330
|
+
message: (lastMessage == null ? void 0 : lastMessage.role) === "assistant" ? lastMessage : {
|
1331
|
+
id: messageId,
|
1332
|
+
metadata: void 0,
|
1333
|
+
role: "assistant",
|
1334
|
+
parts: []
|
1335
|
+
},
|
1338
1336
|
activeTextPart: void 0,
|
1339
1337
|
activeReasoningPart: void 0,
|
1340
1338
|
partialToolCalls: {}
|
@@ -1351,16 +1349,21 @@ function processUIMessageStream({
|
|
1351
1349
|
new TransformStream({
|
1352
1350
|
async transform(part, controller) {
|
1353
1351
|
await runUpdateMessageJob(async ({ state, write }) => {
|
1354
|
-
function updateToolInvocationPart(
|
1352
|
+
function updateToolInvocationPart(options) {
|
1355
1353
|
const part2 = state.message.parts.find(
|
1356
|
-
(part3) =>
|
1354
|
+
(part3) => isToolUIPart(part3) && part3.toolCallId === options.toolCallId
|
1357
1355
|
);
|
1358
1356
|
if (part2 != null) {
|
1359
|
-
part2.
|
1357
|
+
part2.state = options.state;
|
1358
|
+
part2.args = options.args;
|
1359
|
+
part2.result = options.result;
|
1360
1360
|
} else {
|
1361
1361
|
state.message.parts.push({
|
1362
|
-
type:
|
1363
|
-
|
1362
|
+
type: `tool-${options.toolName}`,
|
1363
|
+
toolCallId: options.toolCallId,
|
1364
|
+
state: options.state,
|
1365
|
+
args: options.args,
|
1366
|
+
result: options.result
|
1364
1367
|
});
|
1365
1368
|
}
|
1366
1369
|
}
|
@@ -1444,16 +1447,16 @@ function processUIMessageStream({
|
|
1444
1447
|
break;
|
1445
1448
|
}
|
1446
1449
|
case "tool-call-streaming-start": {
|
1447
|
-
const toolInvocations =
|
1450
|
+
const toolInvocations = state.message.parts.filter(isToolUIPart);
|
1448
1451
|
state.partialToolCalls[part.toolCallId] = {
|
1449
1452
|
text: "",
|
1450
1453
|
toolName: part.toolName,
|
1451
1454
|
index: toolInvocations.length
|
1452
1455
|
};
|
1453
|
-
updateToolInvocationPart(
|
1454
|
-
state: "partial-call",
|
1456
|
+
updateToolInvocationPart({
|
1455
1457
|
toolCallId: part.toolCallId,
|
1456
1458
|
toolName: part.toolName,
|
1459
|
+
state: "partial-call",
|
1457
1460
|
args: void 0
|
1458
1461
|
});
|
1459
1462
|
write();
|
@@ -1465,20 +1468,20 @@ function processUIMessageStream({
|
|
1465
1468
|
const { value: partialArgs } = await parsePartialJson(
|
1466
1469
|
partialToolCall.text
|
1467
1470
|
);
|
1468
|
-
updateToolInvocationPart(
|
1469
|
-
state: "partial-call",
|
1471
|
+
updateToolInvocationPart({
|
1470
1472
|
toolCallId: part.toolCallId,
|
1471
1473
|
toolName: partialToolCall.toolName,
|
1474
|
+
state: "partial-call",
|
1472
1475
|
args: partialArgs
|
1473
1476
|
});
|
1474
1477
|
write();
|
1475
1478
|
break;
|
1476
1479
|
}
|
1477
1480
|
case "tool-call": {
|
1478
|
-
updateToolInvocationPart(
|
1479
|
-
state: "call",
|
1481
|
+
updateToolInvocationPart({
|
1480
1482
|
toolCallId: part.toolCallId,
|
1481
1483
|
toolName: part.toolName,
|
1484
|
+
state: "call",
|
1482
1485
|
args: part.args
|
1483
1486
|
});
|
1484
1487
|
write();
|
@@ -1487,10 +1490,10 @@ function processUIMessageStream({
|
|
1487
1490
|
toolCall: part
|
1488
1491
|
});
|
1489
1492
|
if (result != null) {
|
1490
|
-
updateToolInvocationPart(
|
1491
|
-
state: "result",
|
1493
|
+
updateToolInvocationPart({
|
1492
1494
|
toolCallId: part.toolCallId,
|
1493
1495
|
toolName: part.toolName,
|
1496
|
+
state: "result",
|
1494
1497
|
args: part.args,
|
1495
1498
|
result
|
1496
1499
|
});
|
@@ -1500,7 +1503,7 @@ function processUIMessageStream({
|
|
1500
1503
|
break;
|
1501
1504
|
}
|
1502
1505
|
case "tool-result": {
|
1503
|
-
const toolInvocations =
|
1506
|
+
const toolInvocations = state.message.parts.filter(isToolUIPart);
|
1504
1507
|
if (toolInvocations == null) {
|
1505
1508
|
throw new Error("tool_result must be preceded by a tool_call");
|
1506
1509
|
}
|
@@ -1512,9 +1515,14 @@ function processUIMessageStream({
|
|
1512
1515
|
"tool_result must be preceded by a tool_call with the same toolCallId"
|
1513
1516
|
);
|
1514
1517
|
}
|
1515
|
-
|
1516
|
-
|
1518
|
+
const toolName = getToolName(
|
1519
|
+
toolInvocations[toolInvocationIndex]
|
1520
|
+
);
|
1521
|
+
updateToolInvocationPart({
|
1522
|
+
toolCallId: part.toolCallId,
|
1523
|
+
toolName,
|
1517
1524
|
state: "result",
|
1525
|
+
args: toolInvocations[toolInvocationIndex].args,
|
1518
1526
|
result: part.result
|
1519
1527
|
});
|
1520
1528
|
write();
|
@@ -1522,39 +1530,33 @@ function processUIMessageStream({
|
|
1522
1530
|
}
|
1523
1531
|
case "start-step": {
|
1524
1532
|
state.message.parts.push({ type: "step-start" });
|
1525
|
-
await updateMessageMetadata(part.metadata);
|
1526
|
-
write();
|
1527
1533
|
break;
|
1528
1534
|
}
|
1529
1535
|
case "finish-step": {
|
1530
1536
|
state.activeTextPart = void 0;
|
1531
1537
|
state.activeReasoningPart = void 0;
|
1532
|
-
await updateMessageMetadata(part.metadata);
|
1533
|
-
if (part.metadata != null) {
|
1534
|
-
write();
|
1535
|
-
}
|
1536
1538
|
break;
|
1537
1539
|
}
|
1538
1540
|
case "start": {
|
1539
1541
|
if (part.messageId != null) {
|
1540
1542
|
state.message.id = part.messageId;
|
1541
1543
|
}
|
1542
|
-
await updateMessageMetadata(part.
|
1543
|
-
if (part.messageId != null || part.
|
1544
|
+
await updateMessageMetadata(part.messageMetadata);
|
1545
|
+
if (part.messageId != null || part.messageMetadata != null) {
|
1544
1546
|
write();
|
1545
1547
|
}
|
1546
1548
|
break;
|
1547
1549
|
}
|
1548
1550
|
case "finish": {
|
1549
|
-
await updateMessageMetadata(part.
|
1550
|
-
if (part.
|
1551
|
+
await updateMessageMetadata(part.messageMetadata);
|
1552
|
+
if (part.messageMetadata != null) {
|
1551
1553
|
write();
|
1552
1554
|
}
|
1553
1555
|
break;
|
1554
1556
|
}
|
1555
|
-
case "metadata": {
|
1556
|
-
await updateMessageMetadata(part.
|
1557
|
-
if (part.
|
1557
|
+
case "message-metadata": {
|
1558
|
+
await updateMessageMetadata(part.messageMetadata);
|
1559
|
+
if (part.messageMetadata != null) {
|
1558
1560
|
write();
|
1559
1561
|
}
|
1560
1562
|
break;
|
@@ -1582,9 +1584,6 @@ function processUIMessageStream({
|
|
1582
1584
|
})
|
1583
1585
|
);
|
1584
1586
|
}
|
1585
|
-
function isToolInvocationUIPart(part) {
|
1586
|
-
return part.type === "tool-invocation";
|
1587
|
-
}
|
1588
1587
|
function isObject(value) {
|
1589
1588
|
return typeof value === "object" && value !== null;
|
1590
1589
|
}
|
@@ -1619,8 +1618,8 @@ function isAssistantMessageWithCompletedToolCalls(message) {
|
|
1619
1618
|
const lastStepStartIndex = message.parts.reduce((lastIndex, part, index) => {
|
1620
1619
|
return part.type === "step-start" ? index : lastIndex;
|
1621
1620
|
}, -1);
|
1622
|
-
const lastStepToolInvocations = message.parts.slice(lastStepStartIndex + 1).filter(
|
1623
|
-
return lastStepToolInvocations.length > 0 && lastStepToolInvocations.every((part) => "result"
|
1621
|
+
const lastStepToolInvocations = message.parts.slice(lastStepStartIndex + 1).filter(isToolUIPart);
|
1622
|
+
return lastStepToolInvocations.length > 0 && lastStepToolInvocations.every((part) => part.state === "result");
|
1624
1623
|
}
|
1625
1624
|
|
1626
1625
|
// src/ui/chat.ts
|
@@ -1697,7 +1696,7 @@ var AbstractChat = class {
|
|
1697
1696
|
result
|
1698
1697
|
}) => {
|
1699
1698
|
this.jobExecutor.run(async () => {
|
1700
|
-
|
1699
|
+
updateToolResult({
|
1701
1700
|
messages: this.state.messages,
|
1702
1701
|
toolCallId,
|
1703
1702
|
toolResult: result
|
@@ -1723,7 +1722,6 @@ var AbstractChat = class {
|
|
1723
1722
|
return;
|
1724
1723
|
if ((_a17 = this.activeResponse) == null ? void 0 : _a17.abortController) {
|
1725
1724
|
this.activeResponse.abortController.abort();
|
1726
|
-
this.activeResponse.abortController = void 0;
|
1727
1725
|
}
|
1728
1726
|
};
|
1729
1727
|
this.id = id;
|
@@ -1784,7 +1782,7 @@ var AbstractChat = class {
|
|
1784
1782
|
const activeResponse = {
|
1785
1783
|
state: createStreamingUIMessageState({
|
1786
1784
|
lastMessage: this.state.snapshot(lastMessage),
|
1787
|
-
|
1785
|
+
messageId: this.generateId()
|
1788
1786
|
}),
|
1789
1787
|
abortController: new AbortController()
|
1790
1788
|
};
|
@@ -1861,23 +1859,20 @@ var AbstractChat = class {
|
|
1861
1859
|
}
|
1862
1860
|
}
|
1863
1861
|
};
|
1864
|
-
function
|
1862
|
+
function updateToolResult({
|
1865
1863
|
messages,
|
1866
1864
|
toolCallId,
|
1867
1865
|
toolResult: result
|
1868
1866
|
}) {
|
1869
1867
|
const lastMessage = messages[messages.length - 1];
|
1870
|
-
const
|
1871
|
-
(part) => part
|
1868
|
+
const toolPart = lastMessage.parts.find(
|
1869
|
+
(part) => isToolUIPart(part) && part.toolCallId === toolCallId
|
1872
1870
|
);
|
1873
|
-
if (
|
1871
|
+
if (toolPart == null) {
|
1874
1872
|
return;
|
1875
1873
|
}
|
1876
|
-
|
1877
|
-
|
1878
|
-
state: "result",
|
1879
|
-
result
|
1880
|
-
};
|
1874
|
+
toolPart.state = "result";
|
1875
|
+
toolPart.result = result;
|
1881
1876
|
}
|
1882
1877
|
|
1883
1878
|
// src/ui/convert-to-model-messages.ts
|
@@ -1918,75 +1913,71 @@ function convertToModelMessages(messages, options) {
|
|
1918
1913
|
}
|
1919
1914
|
const content = [];
|
1920
1915
|
for (const part of block) {
|
1921
|
-
|
1922
|
-
|
1923
|
-
|
1924
|
-
|
1925
|
-
|
1926
|
-
|
1927
|
-
|
1928
|
-
|
1929
|
-
|
1930
|
-
|
1931
|
-
|
1932
|
-
|
1933
|
-
|
1934
|
-
|
1935
|
-
|
1936
|
-
|
1937
|
-
|
1938
|
-
|
1916
|
+
if (part.type === "text") {
|
1917
|
+
content.push(part);
|
1918
|
+
} else if (part.type === "file") {
|
1919
|
+
content.push({
|
1920
|
+
type: "file",
|
1921
|
+
mediaType: part.mediaType,
|
1922
|
+
data: part.url
|
1923
|
+
});
|
1924
|
+
} else if (part.type === "reasoning") {
|
1925
|
+
content.push({
|
1926
|
+
type: "reasoning",
|
1927
|
+
text: part.text,
|
1928
|
+
providerOptions: part.providerMetadata
|
1929
|
+
});
|
1930
|
+
} else if (isToolUIPart(part)) {
|
1931
|
+
const toolName = getToolName(part);
|
1932
|
+
if (part.state === "partial-call") {
|
1933
|
+
throw new MessageConversionError({
|
1934
|
+
originalMessage: message,
|
1935
|
+
message: `Partial tool call is not supported: ${part.toolCallId}`
|
1939
1936
|
});
|
1940
|
-
|
1941
|
-
}
|
1942
|
-
case "tool-invocation":
|
1937
|
+
} else {
|
1943
1938
|
content.push({
|
1944
1939
|
type: "tool-call",
|
1945
|
-
toolCallId: part.
|
1946
|
-
toolName
|
1947
|
-
args: part.
|
1940
|
+
toolCallId: part.toolCallId,
|
1941
|
+
toolName,
|
1942
|
+
args: part.args
|
1948
1943
|
});
|
1949
|
-
break;
|
1950
|
-
default: {
|
1951
|
-
const _exhaustiveCheck = part;
|
1952
|
-
throw new Error(`Unsupported part: ${_exhaustiveCheck}`);
|
1953
1944
|
}
|
1945
|
+
} else {
|
1946
|
+
const _exhaustiveCheck = part;
|
1947
|
+
throw new Error(`Unsupported part: ${_exhaustiveCheck}`);
|
1954
1948
|
}
|
1955
1949
|
}
|
1956
1950
|
modelMessages.push({
|
1957
1951
|
role: "assistant",
|
1958
1952
|
content
|
1959
1953
|
});
|
1960
|
-
const
|
1961
|
-
|
1962
|
-
).map((part) => part.toolInvocation);
|
1963
|
-
if (stepInvocations.length > 0) {
|
1954
|
+
const toolParts = block.filter(isToolUIPart);
|
1955
|
+
if (toolParts.length > 0) {
|
1964
1956
|
modelMessages.push({
|
1965
1957
|
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
|
-
};
|
1958
|
+
content: toolParts.map((toolPart) => {
|
1959
|
+
if (toolPart.state !== "result") {
|
1960
|
+
throw new MessageConversionError({
|
1961
|
+
originalMessage: message,
|
1962
|
+
message: "ToolInvocation must have a result: " + JSON.stringify(toolPart)
|
1963
|
+
});
|
1988
1964
|
}
|
1989
|
-
|
1965
|
+
const toolName = getToolName(toolPart);
|
1966
|
+
const { toolCallId, result } = toolPart;
|
1967
|
+
const tool2 = tools[toolName];
|
1968
|
+
return (tool2 == null ? void 0 : tool2.experimental_toToolResultContent) != null ? {
|
1969
|
+
type: "tool-result",
|
1970
|
+
toolCallId,
|
1971
|
+
toolName,
|
1972
|
+
result: tool2.experimental_toToolResultContent(result),
|
1973
|
+
experimental_content: tool2.experimental_toToolResultContent(result)
|
1974
|
+
} : {
|
1975
|
+
type: "tool-result",
|
1976
|
+
toolCallId,
|
1977
|
+
toolName,
|
1978
|
+
result
|
1979
|
+
};
|
1980
|
+
})
|
1990
1981
|
});
|
1991
1982
|
}
|
1992
1983
|
block = [];
|
@@ -1994,18 +1985,10 @@ function convertToModelMessages(messages, options) {
|
|
1994
1985
|
var processBlock = processBlock2;
|
1995
1986
|
let block = [];
|
1996
1987
|
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
|
-
}
|
1988
|
+
if (part.type === "text" || part.type === "reasoning" || part.type === "file" || isToolUIPart(part)) {
|
1989
|
+
block.push(part);
|
1990
|
+
} else if (part.type === "step-start") {
|
1991
|
+
processBlock2();
|
2009
1992
|
}
|
2010
1993
|
}
|
2011
1994
|
processBlock2();
|
@@ -2135,9 +2118,12 @@ var TextStreamChatTransport = class {
|
|
2135
2118
|
}
|
2136
2119
|
};
|
2137
2120
|
|
2121
|
+
// src/ui-message-stream/create-ui-message-stream.ts
|
2122
|
+
var import_provider_utils6 = require("@ai-sdk/provider-utils");
|
2123
|
+
|
2138
2124
|
// src/ui-message-stream/handle-ui-message-stream-finish.ts
|
2139
2125
|
function handleUIMessageStreamFinish({
|
2140
|
-
|
2126
|
+
messageId,
|
2141
2127
|
originalMessages = [],
|
2142
2128
|
onFinish,
|
2143
2129
|
stream
|
@@ -2145,19 +2131,30 @@ function handleUIMessageStreamFinish({
|
|
2145
2131
|
if (onFinish == null) {
|
2146
2132
|
return stream;
|
2147
2133
|
}
|
2148
|
-
const lastMessage = originalMessages[originalMessages.length - 1];
|
2149
|
-
const isContinuation = (lastMessage == null ? void 0 : lastMessage.role) === "assistant";
|
2150
|
-
const messageId = isContinuation ? lastMessage.id : newMessageId;
|
2134
|
+
const lastMessage = originalMessages == null ? void 0 : originalMessages[originalMessages.length - 1];
|
2151
2135
|
const state = createStreamingUIMessageState({
|
2152
|
-
lastMessage: structuredClone(lastMessage),
|
2153
|
-
|
2136
|
+
lastMessage: lastMessage ? structuredClone(lastMessage) : void 0,
|
2137
|
+
messageId
|
2138
|
+
// will be overridden by the stream
|
2154
2139
|
});
|
2155
2140
|
const runUpdateMessageJob = async (job) => {
|
2156
2141
|
await job({ state, write: () => {
|
2157
2142
|
} });
|
2158
2143
|
};
|
2159
2144
|
return processUIMessageStream({
|
2160
|
-
stream
|
2145
|
+
stream: stream.pipeThrough(
|
2146
|
+
new TransformStream({
|
2147
|
+
transform(chunk, controller) {
|
2148
|
+
if (chunk.type === "start") {
|
2149
|
+
const startChunk = chunk;
|
2150
|
+
if (startChunk.messageId == null) {
|
2151
|
+
startChunk.messageId = messageId;
|
2152
|
+
}
|
2153
|
+
}
|
2154
|
+
controller.enqueue(chunk);
|
2155
|
+
}
|
2156
|
+
})
|
2157
|
+
),
|
2161
2158
|
runUpdateMessageJob
|
2162
2159
|
}).pipeThrough(
|
2163
2160
|
new TransformStream({
|
@@ -2165,12 +2162,12 @@ function handleUIMessageStreamFinish({
|
|
2165
2162
|
controller.enqueue(chunk);
|
2166
2163
|
},
|
2167
2164
|
flush() {
|
2168
|
-
const
|
2165
|
+
const isContinuation = state.message.id === (lastMessage == null ? void 0 : lastMessage.id);
|
2169
2166
|
onFinish({
|
2170
|
-
isContinuation
|
2167
|
+
isContinuation,
|
2171
2168
|
responseMessage: state.message,
|
2172
2169
|
messages: [
|
2173
|
-
...
|
2170
|
+
...isContinuation ? originalMessages.slice(0, -1) : originalMessages,
|
2174
2171
|
state.message
|
2175
2172
|
]
|
2176
2173
|
});
|
@@ -2185,7 +2182,8 @@ function createUIMessageStream({
|
|
2185
2182
|
onError = () => "An error occurred.",
|
2186
2183
|
// mask error messages for safety by default
|
2187
2184
|
originalMessages,
|
2188
|
-
onFinish
|
2185
|
+
onFinish,
|
2186
|
+
generateId: generateId3 = import_provider_utils6.generateId
|
2189
2187
|
}) {
|
2190
2188
|
let controller;
|
2191
2189
|
const ongoingStreamPromises = [];
|
@@ -2257,7 +2255,7 @@ function createUIMessageStream({
|
|
2257
2255
|
});
|
2258
2256
|
return handleUIMessageStreamFinish({
|
2259
2257
|
stream,
|
2260
|
-
|
2258
|
+
messageId: generateId3(),
|
2261
2259
|
originalMessages,
|
2262
2260
|
onFinish
|
2263
2261
|
});
|
@@ -2401,7 +2399,7 @@ function isDeepEqualData(obj1, obj2) {
|
|
2401
2399
|
}
|
2402
2400
|
|
2403
2401
|
// src/util/simulate-readable-stream.ts
|
2404
|
-
var
|
2402
|
+
var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
2405
2403
|
function simulateReadableStream({
|
2406
2404
|
chunks,
|
2407
2405
|
initialDelayInMs = 0,
|
@@ -2409,7 +2407,7 @@ function simulateReadableStream({
|
|
2409
2407
|
_internal
|
2410
2408
|
}) {
|
2411
2409
|
var _a17;
|
2412
|
-
const delay2 = (_a17 = _internal == null ? void 0 : _internal.delay) != null ? _a17 :
|
2410
|
+
const delay2 = (_a17 = _internal == null ? void 0 : _internal.delay) != null ? _a17 : import_provider_utils7.delay;
|
2413
2411
|
let index = 0;
|
2414
2412
|
return new ReadableStream({
|
2415
2413
|
async pull(controller) {
|
@@ -2425,7 +2423,7 @@ function simulateReadableStream({
|
|
2425
2423
|
|
2426
2424
|
// src/util/retry-with-exponential-backoff.ts
|
2427
2425
|
var import_provider17 = require("@ai-sdk/provider");
|
2428
|
-
var
|
2426
|
+
var import_provider_utils8 = require("@ai-sdk/provider-utils");
|
2429
2427
|
var retryWithExponentialBackoff = ({
|
2430
2428
|
maxRetries = 2,
|
2431
2429
|
initialDelayInMs = 2e3,
|
@@ -2443,13 +2441,13 @@ async function _retryWithExponentialBackoff(f, {
|
|
2443
2441
|
try {
|
2444
2442
|
return await f();
|
2445
2443
|
} catch (error) {
|
2446
|
-
if ((0,
|
2444
|
+
if ((0, import_provider_utils8.isAbortError)(error)) {
|
2447
2445
|
throw error;
|
2448
2446
|
}
|
2449
2447
|
if (maxRetries === 0) {
|
2450
2448
|
throw error;
|
2451
2449
|
}
|
2452
|
-
const errorMessage = (0,
|
2450
|
+
const errorMessage = (0, import_provider_utils8.getErrorMessage)(error);
|
2453
2451
|
const newErrors = [...errors, error];
|
2454
2452
|
const tryNumber = newErrors.length;
|
2455
2453
|
if (tryNumber > maxRetries) {
|
@@ -2460,7 +2458,7 @@ async function _retryWithExponentialBackoff(f, {
|
|
2460
2458
|
});
|
2461
2459
|
}
|
2462
2460
|
if (error instanceof Error && import_provider17.APICallError.isInstance(error) && error.isRetryable === true && tryNumber <= maxRetries) {
|
2463
|
-
await (0,
|
2461
|
+
await (0, import_provider_utils8.delay)(delayInMs);
|
2464
2462
|
return _retryWithExponentialBackoff(
|
2465
2463
|
f,
|
2466
2464
|
{ maxRetries, delayInMs: backoffFactor * delayInMs, backoffFactor },
|
@@ -3019,7 +3017,7 @@ var DefaultEmbedManyResult = class {
|
|
3019
3017
|
};
|
3020
3018
|
|
3021
3019
|
// src/util/detect-media-type.ts
|
3022
|
-
var
|
3020
|
+
var import_provider_utils9 = require("@ai-sdk/provider-utils");
|
3023
3021
|
var imageMediaTypeSignatures = [
|
3024
3022
|
{
|
3025
3023
|
mediaType: "image/gif",
|
@@ -3126,7 +3124,7 @@ var audioMediaTypeSignatures = [
|
|
3126
3124
|
}
|
3127
3125
|
];
|
3128
3126
|
var stripID3 = (data) => {
|
3129
|
-
const bytes = typeof data === "string" ? (0,
|
3127
|
+
const bytes = typeof data === "string" ? (0, import_provider_utils9.convertBase64ToUint8Array)(data) : data;
|
3130
3128
|
const id3Size = (bytes[6] & 127) << 21 | (bytes[7] & 127) << 14 | (bytes[8] & 127) << 7 | bytes[9] & 127;
|
3131
3129
|
return bytes.slice(id3Size + 10);
|
3132
3130
|
};
|
@@ -3152,7 +3150,7 @@ function detectMediaType({
|
|
3152
3150
|
}
|
3153
3151
|
|
3154
3152
|
// core/generate-text/generated-file.ts
|
3155
|
-
var
|
3153
|
+
var import_provider_utils10 = require("@ai-sdk/provider-utils");
|
3156
3154
|
var DefaultGeneratedFile = class {
|
3157
3155
|
constructor({
|
3158
3156
|
data,
|
@@ -3166,14 +3164,14 @@ var DefaultGeneratedFile = class {
|
|
3166
3164
|
// lazy conversion with caching to avoid unnecessary conversion overhead:
|
3167
3165
|
get base64() {
|
3168
3166
|
if (this.base64Data == null) {
|
3169
|
-
this.base64Data = (0,
|
3167
|
+
this.base64Data = (0, import_provider_utils10.convertUint8ArrayToBase64)(this.uint8ArrayData);
|
3170
3168
|
}
|
3171
3169
|
return this.base64Data;
|
3172
3170
|
}
|
3173
3171
|
// lazy conversion with caching to avoid unnecessary conversion overhead:
|
3174
3172
|
get uint8Array() {
|
3175
3173
|
if (this.uint8ArrayData == null) {
|
3176
|
-
this.uint8ArrayData = (0,
|
3174
|
+
this.uint8ArrayData = (0, import_provider_utils10.convertBase64ToUint8Array)(this.base64Data);
|
3177
3175
|
}
|
3178
3176
|
return this.uint8ArrayData;
|
3179
3177
|
}
|
@@ -3289,7 +3287,7 @@ async function invokeModelMaxImagesPerCall(model) {
|
|
3289
3287
|
|
3290
3288
|
// core/generate-object/generate-object.ts
|
3291
3289
|
var import_provider22 = require("@ai-sdk/provider");
|
3292
|
-
var
|
3290
|
+
var import_provider_utils15 = require("@ai-sdk/provider-utils");
|
3293
3291
|
|
3294
3292
|
// core/generate-text/extract-content-text.ts
|
3295
3293
|
function extractContentText(content) {
|
@@ -3303,7 +3301,7 @@ function extractContentText(content) {
|
|
3303
3301
|
}
|
3304
3302
|
|
3305
3303
|
// core/prompt/convert-to-language-model-prompt.ts
|
3306
|
-
var
|
3304
|
+
var import_provider_utils12 = require("@ai-sdk/provider-utils");
|
3307
3305
|
|
3308
3306
|
// src/util/download.ts
|
3309
3307
|
async function download({ url }) {
|
@@ -3332,7 +3330,7 @@ async function download({ url }) {
|
|
3332
3330
|
|
3333
3331
|
// core/prompt/data-content.ts
|
3334
3332
|
var import_provider18 = require("@ai-sdk/provider");
|
3335
|
-
var
|
3333
|
+
var import_provider_utils11 = require("@ai-sdk/provider-utils");
|
3336
3334
|
var import_zod2 = require("zod");
|
3337
3335
|
|
3338
3336
|
// core/prompt/split-data-url.ts
|
@@ -3397,9 +3395,9 @@ function convertDataContentToBase64String(content) {
|
|
3397
3395
|
return content;
|
3398
3396
|
}
|
3399
3397
|
if (content instanceof ArrayBuffer) {
|
3400
|
-
return (0,
|
3398
|
+
return (0, import_provider_utils11.convertUint8ArrayToBase64)(new Uint8Array(content));
|
3401
3399
|
}
|
3402
|
-
return (0,
|
3400
|
+
return (0, import_provider_utils11.convertUint8ArrayToBase64)(content);
|
3403
3401
|
}
|
3404
3402
|
function convertDataContentToUint8Array(content) {
|
3405
3403
|
if (content instanceof Uint8Array) {
|
@@ -3407,7 +3405,7 @@ function convertDataContentToUint8Array(content) {
|
|
3407
3405
|
}
|
3408
3406
|
if (typeof content === "string") {
|
3409
3407
|
try {
|
3410
|
-
return (0,
|
3408
|
+
return (0, import_provider_utils11.convertBase64ToUint8Array)(content);
|
3411
3409
|
} catch (error) {
|
3412
3410
|
throw new InvalidDataContentError({
|
3413
3411
|
message: "Invalid data content. Content string is not a base64-encoded media.",
|
@@ -3558,7 +3556,7 @@ async function downloadAssets(messages, downloadImplementation, supportedUrls) {
|
|
3558
3556
|
}
|
3559
3557
|
return { mediaType, data };
|
3560
3558
|
}).filter(
|
3561
|
-
(part) => part.data instanceof URL && part.mediaType != null && !(0,
|
3559
|
+
(part) => part.data instanceof URL && part.mediaType != null && !(0, import_provider_utils12.isUrlSupported)({
|
3562
3560
|
url: part.data.toString(),
|
3563
3561
|
mediaType: part.mediaType,
|
3564
3562
|
supportedUrls
|
@@ -3742,7 +3740,7 @@ function resolveLanguageModel(model) {
|
|
3742
3740
|
|
3743
3741
|
// core/prompt/standardize-prompt.ts
|
3744
3742
|
var import_provider19 = require("@ai-sdk/provider");
|
3745
|
-
var
|
3743
|
+
var import_provider_utils13 = require("@ai-sdk/provider-utils");
|
3746
3744
|
var import_zod8 = require("zod");
|
3747
3745
|
|
3748
3746
|
// core/prompt/message.ts
|
@@ -3914,7 +3912,7 @@ async function standardizePrompt(prompt) {
|
|
3914
3912
|
message: "messages must not be empty"
|
3915
3913
|
});
|
3916
3914
|
}
|
3917
|
-
const validationResult = await (0,
|
3915
|
+
const validationResult = await (0, import_provider_utils13.safeValidateTypes)({
|
3918
3916
|
value: messages,
|
3919
3917
|
schema: import_zod8.z.array(modelMessageSchema)
|
3920
3918
|
});
|
@@ -3962,7 +3960,7 @@ function stringifyForTelemetry(prompt) {
|
|
3962
3960
|
|
3963
3961
|
// core/generate-object/output-strategy.ts
|
3964
3962
|
var import_provider21 = require("@ai-sdk/provider");
|
3965
|
-
var
|
3963
|
+
var import_provider_utils14 = require("@ai-sdk/provider-utils");
|
3966
3964
|
|
3967
3965
|
// src/util/async-iterable-stream.ts
|
3968
3966
|
function createAsyncIterableStream(source) {
|
@@ -4018,7 +4016,7 @@ var objectOutputStrategy = (schema) => ({
|
|
4018
4016
|
};
|
4019
4017
|
},
|
4020
4018
|
async validateFinalResult(value) {
|
4021
|
-
return (0,
|
4019
|
+
return (0, import_provider_utils14.safeValidateTypes)({ value, schema });
|
4022
4020
|
},
|
4023
4021
|
createElementStream() {
|
4024
4022
|
throw new import_provider21.UnsupportedFunctionalityError({
|
@@ -4062,7 +4060,7 @@ var arrayOutputStrategy = (schema) => {
|
|
4062
4060
|
const resultArray = [];
|
4063
4061
|
for (let i = 0; i < inputArray.length; i++) {
|
4064
4062
|
const element = inputArray[i];
|
4065
|
-
const result = await (0,
|
4063
|
+
const result = await (0, import_provider_utils14.safeValidateTypes)({ value: element, schema });
|
4066
4064
|
if (i === inputArray.length - 1 && !isFinalDelta) {
|
4067
4065
|
continue;
|
4068
4066
|
}
|
@@ -4103,7 +4101,7 @@ var arrayOutputStrategy = (schema) => {
|
|
4103
4101
|
}
|
4104
4102
|
const inputArray = value.elements;
|
4105
4103
|
for (const element of inputArray) {
|
4106
|
-
const result = await (0,
|
4104
|
+
const result = await (0, import_provider_utils14.safeValidateTypes)({ value: element, schema });
|
4107
4105
|
if (!result.success) {
|
4108
4106
|
return result;
|
4109
4107
|
}
|
@@ -4221,9 +4219,9 @@ function getOutputStrategy({
|
|
4221
4219
|
}) {
|
4222
4220
|
switch (output) {
|
4223
4221
|
case "object":
|
4224
|
-
return objectOutputStrategy((0,
|
4222
|
+
return objectOutputStrategy((0, import_provider_utils14.asSchema)(schema));
|
4225
4223
|
case "array":
|
4226
|
-
return arrayOutputStrategy((0,
|
4224
|
+
return arrayOutputStrategy((0, import_provider_utils14.asSchema)(schema));
|
4227
4225
|
case "enum":
|
4228
4226
|
return enumOutputStrategy(enumValues);
|
4229
4227
|
case "no-schema":
|
@@ -4354,7 +4352,7 @@ function validateObjectGenerationInput({
|
|
4354
4352
|
}
|
4355
4353
|
|
4356
4354
|
// core/generate-object/generate-object.ts
|
4357
|
-
var originalGenerateId = (0,
|
4355
|
+
var originalGenerateId = (0, import_provider_utils15.createIdGenerator)({ prefix: "aiobj", size: 24 });
|
4358
4356
|
async function generateObject(options) {
|
4359
4357
|
const {
|
4360
4358
|
model: modelArg,
|
@@ -4532,7 +4530,7 @@ async function generateObject(options) {
|
|
4532
4530
|
request = (_a17 = generateResult.request) != null ? _a17 : {};
|
4533
4531
|
response = generateResult.responseData;
|
4534
4532
|
async function processResult(result2) {
|
4535
|
-
const parseResult = await (0,
|
4533
|
+
const parseResult = await (0, import_provider_utils15.safeParseJSON)({ text: result2 });
|
4536
4534
|
if (!parseResult.success) {
|
4537
4535
|
throw new NoObjectGeneratedError({
|
4538
4536
|
message: "No object generated: could not parse the response.",
|
@@ -4631,7 +4629,7 @@ var DefaultGenerateObjectResult = class {
|
|
4631
4629
|
};
|
4632
4630
|
|
4633
4631
|
// core/generate-object/stream-object.ts
|
4634
|
-
var
|
4632
|
+
var import_provider_utils16 = require("@ai-sdk/provider-utils");
|
4635
4633
|
|
4636
4634
|
// src/util/create-resolvable-promise.ts
|
4637
4635
|
function createResolvablePromise() {
|
@@ -4775,7 +4773,7 @@ function now() {
|
|
4775
4773
|
}
|
4776
4774
|
|
4777
4775
|
// core/generate-object/stream-object.ts
|
4778
|
-
var originalGenerateId2 = (0,
|
4776
|
+
var originalGenerateId2 = (0, import_provider_utils16.createIdGenerator)({ prefix: "aiobj", size: 24 });
|
4779
4777
|
function streamObject(options) {
|
4780
4778
|
const {
|
4781
4779
|
model,
|
@@ -5374,7 +5372,7 @@ var DefaultSpeechResult = class {
|
|
5374
5372
|
};
|
5375
5373
|
|
5376
5374
|
// core/generate-text/generate-text.ts
|
5377
|
-
var
|
5375
|
+
var import_provider_utils19 = require("@ai-sdk/provider-utils");
|
5378
5376
|
|
5379
5377
|
// src/util/as-array.ts
|
5380
5378
|
function asArray(value) {
|
@@ -5382,7 +5380,7 @@ function asArray(value) {
|
|
5382
5380
|
}
|
5383
5381
|
|
5384
5382
|
// core/prompt/prepare-tools-and-tool-choice.ts
|
5385
|
-
var
|
5383
|
+
var import_provider_utils17 = require("@ai-sdk/provider-utils");
|
5386
5384
|
|
5387
5385
|
// src/util/is-non-empty-object.ts
|
5388
5386
|
function isNonEmptyObject(object2) {
|
@@ -5414,7 +5412,7 @@ function prepareToolsAndToolChoice({
|
|
5414
5412
|
type: "function",
|
5415
5413
|
name: name17,
|
5416
5414
|
description: tool2.description,
|
5417
|
-
parameters: (0,
|
5415
|
+
parameters: (0, import_provider_utils17.asSchema)(tool2.parameters).jsonSchema
|
5418
5416
|
};
|
5419
5417
|
case "provider-defined":
|
5420
5418
|
return {
|
@@ -5484,7 +5482,7 @@ function asContent({
|
|
5484
5482
|
}
|
5485
5483
|
|
5486
5484
|
// core/generate-text/parse-tool-call.ts
|
5487
|
-
var
|
5485
|
+
var import_provider_utils18 = require("@ai-sdk/provider-utils");
|
5488
5486
|
async function parseToolCall({
|
5489
5487
|
toolCall,
|
5490
5488
|
tools,
|
@@ -5508,7 +5506,7 @@ async function parseToolCall({
|
|
5508
5506
|
tools,
|
5509
5507
|
parameterSchema: ({ toolName }) => {
|
5510
5508
|
const { parameters } = tools[toolName];
|
5511
|
-
return (0,
|
5509
|
+
return (0, import_provider_utils18.asSchema)(parameters).jsonSchema;
|
5512
5510
|
},
|
5513
5511
|
system,
|
5514
5512
|
messages,
|
@@ -5538,8 +5536,8 @@ async function doParseToolCall({
|
|
5538
5536
|
availableTools: Object.keys(tools)
|
5539
5537
|
});
|
5540
5538
|
}
|
5541
|
-
const schema = (0,
|
5542
|
-
const parseResult = toolCall.args.trim() === "" ? await (0,
|
5539
|
+
const schema = (0, import_provider_utils18.asSchema)(tool2.parameters);
|
5540
|
+
const parseResult = toolCall.args.trim() === "" ? await (0, import_provider_utils18.safeValidateTypes)({ value: {}, schema }) : await (0, import_provider_utils18.safeParseJSON)({ text: toolCall.args, schema });
|
5543
5541
|
if (parseResult.success === false) {
|
5544
5542
|
throw new InvalidToolArgumentsError({
|
5545
5543
|
toolName,
|
@@ -5675,7 +5673,7 @@ function toResponseMessages({
|
|
5675
5673
|
}
|
5676
5674
|
|
5677
5675
|
// core/generate-text/generate-text.ts
|
5678
|
-
var originalGenerateId3 = (0,
|
5676
|
+
var originalGenerateId3 = (0, import_provider_utils19.createIdGenerator)({
|
5679
5677
|
prefix: "aitxt",
|
5680
5678
|
size: 24
|
5681
5679
|
});
|
@@ -6134,7 +6132,7 @@ __export(output_exports, {
|
|
6134
6132
|
object: () => object,
|
6135
6133
|
text: () => text
|
6136
6134
|
});
|
6137
|
-
var
|
6135
|
+
var import_provider_utils20 = require("@ai-sdk/provider-utils");
|
6138
6136
|
var text = () => ({
|
6139
6137
|
type: "text",
|
6140
6138
|
responseFormat: { type: "text" },
|
@@ -6148,7 +6146,7 @@ var text = () => ({
|
|
6148
6146
|
var object = ({
|
6149
6147
|
schema: inputSchema
|
6150
6148
|
}) => {
|
6151
|
-
const schema = (0,
|
6149
|
+
const schema = (0, import_provider_utils20.asSchema)(inputSchema);
|
6152
6150
|
return {
|
6153
6151
|
type: "object",
|
6154
6152
|
responseFormat: {
|
@@ -6174,7 +6172,7 @@ var object = ({
|
|
6174
6172
|
}
|
6175
6173
|
},
|
6176
6174
|
async parseOutput({ text: text2 }, context) {
|
6177
|
-
const parseResult = await (0,
|
6175
|
+
const parseResult = await (0, import_provider_utils20.safeParseJSON)({ text: text2 });
|
6178
6176
|
if (!parseResult.success) {
|
6179
6177
|
throw new NoObjectGeneratedError({
|
6180
6178
|
message: "No object generated: could not parse the response.",
|
@@ -6185,7 +6183,7 @@ var object = ({
|
|
6185
6183
|
finishReason: context.finishReason
|
6186
6184
|
});
|
6187
6185
|
}
|
6188
|
-
const validationResult = await (0,
|
6186
|
+
const validationResult = await (0, import_provider_utils20.safeValidateTypes)({
|
6189
6187
|
value: parseResult.value,
|
6190
6188
|
schema
|
6191
6189
|
});
|
@@ -6205,7 +6203,7 @@ var object = ({
|
|
6205
6203
|
};
|
6206
6204
|
|
6207
6205
|
// core/generate-text/smooth-stream.ts
|
6208
|
-
var
|
6206
|
+
var import_provider_utils21 = require("@ai-sdk/provider-utils");
|
6209
6207
|
var import_provider24 = require("@ai-sdk/provider");
|
6210
6208
|
var CHUNKING_REGEXPS = {
|
6211
6209
|
word: /\S+\s+/m,
|
@@ -6214,7 +6212,7 @@ var CHUNKING_REGEXPS = {
|
|
6214
6212
|
function smoothStream({
|
6215
6213
|
delayInMs = 10,
|
6216
6214
|
chunking = "word",
|
6217
|
-
_internal: { delay: delay2 =
|
6215
|
+
_internal: { delay: delay2 = import_provider_utils21.delay } = {}
|
6218
6216
|
} = {}) {
|
6219
6217
|
let detectChunk;
|
6220
6218
|
if (typeof chunking === "function") {
|
@@ -6274,10 +6272,10 @@ function smoothStream({
|
|
6274
6272
|
}
|
6275
6273
|
|
6276
6274
|
// core/generate-text/stream-text.ts
|
6277
|
-
var
|
6275
|
+
var import_provider_utils23 = require("@ai-sdk/provider-utils");
|
6278
6276
|
|
6279
6277
|
// core/generate-text/run-tools-transformation.ts
|
6280
|
-
var
|
6278
|
+
var import_provider_utils22 = require("@ai-sdk/provider-utils");
|
6281
6279
|
function runToolsTransformation({
|
6282
6280
|
tools,
|
6283
6281
|
generatorStream,
|
@@ -6372,7 +6370,7 @@ function runToolsTransformation({
|
|
6372
6370
|
});
|
6373
6371
|
}
|
6374
6372
|
if (tool2.execute != null) {
|
6375
|
-
const toolExecutionId = (0,
|
6373
|
+
const toolExecutionId = (0, import_provider_utils22.generateId)();
|
6376
6374
|
outstandingToolResults.add(toolExecutionId);
|
6377
6375
|
recordSpan({
|
6378
6376
|
name: "ai.toolCall",
|
@@ -6480,8 +6478,20 @@ function runToolsTransformation({
|
|
6480
6478
|
});
|
6481
6479
|
}
|
6482
6480
|
|
6481
|
+
// src/ui-message-stream/get-response-ui-message-id.ts
|
6482
|
+
function getResponseUIMessageId({
|
6483
|
+
originalMessages,
|
6484
|
+
responseMessageId
|
6485
|
+
}) {
|
6486
|
+
if (originalMessages == null) {
|
6487
|
+
return void 0;
|
6488
|
+
}
|
6489
|
+
const lastMessage = originalMessages[originalMessages.length - 1];
|
6490
|
+
return (lastMessage == null ? void 0 : lastMessage.role) === "assistant" ? lastMessage.id : typeof responseMessageId === "function" ? responseMessageId() : responseMessageId;
|
6491
|
+
}
|
6492
|
+
|
6483
6493
|
// core/generate-text/stream-text.ts
|
6484
|
-
var originalGenerateId4 = (0,
|
6494
|
+
var originalGenerateId4 = (0, import_provider_utils23.createIdGenerator)({
|
6485
6495
|
prefix: "aitxt",
|
6486
6496
|
size: 24
|
6487
6497
|
});
|
@@ -6644,7 +6654,7 @@ var DefaultStreamTextResult = class {
|
|
6644
6654
|
async transform(chunk, controller) {
|
6645
6655
|
controller.enqueue(chunk);
|
6646
6656
|
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") {
|
6657
|
+
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
6658
|
await (onChunk == null ? void 0 : onChunk({ chunk: part }));
|
6649
6659
|
}
|
6650
6660
|
if (part.type === "error") {
|
@@ -7093,7 +7103,9 @@ var DefaultStreamTextResult = class {
|
|
7093
7103
|
break;
|
7094
7104
|
}
|
7095
7105
|
case "raw": {
|
7096
|
-
|
7106
|
+
if (includeRawChunks2) {
|
7107
|
+
controller.enqueue(chunk);
|
7108
|
+
}
|
7097
7109
|
break;
|
7098
7110
|
}
|
7099
7111
|
default: {
|
@@ -7316,23 +7328,24 @@ var DefaultStreamTextResult = class {
|
|
7316
7328
|
);
|
7317
7329
|
}
|
7318
7330
|
toUIMessageStream({
|
7319
|
-
|
7320
|
-
originalMessages = [],
|
7331
|
+
originalMessages,
|
7321
7332
|
onFinish,
|
7322
7333
|
messageMetadata,
|
7323
|
-
sendReasoning =
|
7334
|
+
sendReasoning = true,
|
7324
7335
|
sendSources = false,
|
7325
7336
|
sendStart = true,
|
7326
7337
|
sendFinish = true,
|
7327
7338
|
onError = () => "An error occurred."
|
7328
7339
|
// mask error messages for safety by default
|
7329
7340
|
} = {}) {
|
7330
|
-
const
|
7331
|
-
|
7332
|
-
|
7341
|
+
const responseMessageId = getResponseUIMessageId({
|
7342
|
+
originalMessages,
|
7343
|
+
responseMessageId: this.generateId
|
7344
|
+
});
|
7333
7345
|
const baseStream = this.fullStream.pipeThrough(
|
7334
7346
|
new TransformStream({
|
7335
7347
|
transform: async (part, controller) => {
|
7348
|
+
const messageMetadataValue = messageMetadata == null ? void 0 : messageMetadata({ part });
|
7336
7349
|
const partType = part.type;
|
7337
7350
|
switch (partType) {
|
7338
7351
|
case "text": {
|
@@ -7429,38 +7442,28 @@ var DefaultStreamTextResult = class {
|
|
7429
7442
|
break;
|
7430
7443
|
}
|
7431
7444
|
case "start-step": {
|
7432
|
-
|
7433
|
-
controller.enqueue({
|
7434
|
-
type: "start-step",
|
7435
|
-
metadata
|
7436
|
-
});
|
7445
|
+
controller.enqueue({ type: "start-step" });
|
7437
7446
|
break;
|
7438
7447
|
}
|
7439
7448
|
case "finish-step": {
|
7440
|
-
|
7441
|
-
controller.enqueue({
|
7442
|
-
type: "finish-step",
|
7443
|
-
metadata
|
7444
|
-
});
|
7449
|
+
controller.enqueue({ type: "finish-step" });
|
7445
7450
|
break;
|
7446
7451
|
}
|
7447
7452
|
case "start": {
|
7448
7453
|
if (sendStart) {
|
7449
|
-
const metadata = messageMetadata == null ? void 0 : messageMetadata({ part });
|
7450
7454
|
controller.enqueue({
|
7451
7455
|
type: "start",
|
7452
|
-
messageId,
|
7453
|
-
|
7456
|
+
messageId: responseMessageId,
|
7457
|
+
messageMetadata: messageMetadataValue
|
7454
7458
|
});
|
7455
7459
|
}
|
7456
7460
|
break;
|
7457
7461
|
}
|
7458
7462
|
case "finish": {
|
7459
7463
|
if (sendFinish) {
|
7460
|
-
const metadata = messageMetadata == null ? void 0 : messageMetadata({ part });
|
7461
7464
|
controller.enqueue({
|
7462
7465
|
type: "finish",
|
7463
|
-
|
7466
|
+
messageMetadata: messageMetadataValue
|
7464
7467
|
});
|
7465
7468
|
}
|
7466
7469
|
break;
|
@@ -7473,18 +7476,23 @@ var DefaultStreamTextResult = class {
|
|
7473
7476
|
throw new Error(`Unknown chunk type: ${exhaustiveCheck}`);
|
7474
7477
|
}
|
7475
7478
|
}
|
7479
|
+
if (messageMetadataValue != null && partType !== "start" && partType !== "finish") {
|
7480
|
+
controller.enqueue({
|
7481
|
+
type: "message-metadata",
|
7482
|
+
messageMetadata: messageMetadataValue
|
7483
|
+
});
|
7484
|
+
}
|
7476
7485
|
}
|
7477
7486
|
})
|
7478
7487
|
);
|
7479
7488
|
return handleUIMessageStreamFinish({
|
7480
7489
|
stream: baseStream,
|
7481
|
-
|
7490
|
+
messageId: responseMessageId != null ? responseMessageId : this.generateId(),
|
7482
7491
|
originalMessages,
|
7483
7492
|
onFinish
|
7484
7493
|
});
|
7485
7494
|
}
|
7486
7495
|
pipeUIMessageStreamToResponse(response, {
|
7487
|
-
newMessageId,
|
7488
7496
|
originalMessages,
|
7489
7497
|
onFinish,
|
7490
7498
|
messageMetadata,
|
@@ -7498,7 +7506,6 @@ var DefaultStreamTextResult = class {
|
|
7498
7506
|
pipeUIMessageStreamToResponse({
|
7499
7507
|
response,
|
7500
7508
|
stream: this.toUIMessageStream({
|
7501
|
-
newMessageId,
|
7502
7509
|
originalMessages,
|
7503
7510
|
onFinish,
|
7504
7511
|
messageMetadata,
|
@@ -7519,7 +7526,6 @@ var DefaultStreamTextResult = class {
|
|
7519
7526
|
});
|
7520
7527
|
}
|
7521
7528
|
toUIMessageStreamResponse({
|
7522
|
-
newMessageId,
|
7523
7529
|
originalMessages,
|
7524
7530
|
onFinish,
|
7525
7531
|
messageMetadata,
|
@@ -7532,7 +7538,6 @@ var DefaultStreamTextResult = class {
|
|
7532
7538
|
} = {}) {
|
7533
7539
|
return createUIMessageStreamResponse({
|
7534
7540
|
stream: this.toUIMessageStream({
|
7535
|
-
newMessageId,
|
7536
7541
|
originalMessages,
|
7537
7542
|
onFinish,
|
7538
7543
|
messageMetadata,
|
@@ -7929,7 +7934,7 @@ var DefaultProviderRegistry = class {
|
|
7929
7934
|
};
|
7930
7935
|
|
7931
7936
|
// core/tool/mcp/mcp-client.ts
|
7932
|
-
var
|
7937
|
+
var import_provider_utils25 = require("@ai-sdk/provider-utils");
|
7933
7938
|
|
7934
7939
|
// core/tool/tool.ts
|
7935
7940
|
function tool(tool2) {
|
@@ -7937,7 +7942,7 @@ function tool(tool2) {
|
|
7937
7942
|
}
|
7938
7943
|
|
7939
7944
|
// core/tool/mcp/mcp-sse-transport.ts
|
7940
|
-
var
|
7945
|
+
var import_provider_utils24 = require("@ai-sdk/provider-utils");
|
7941
7946
|
|
7942
7947
|
// core/tool/mcp/json-rpc-message.ts
|
7943
7948
|
var import_zod10 = require("zod");
|
@@ -8108,7 +8113,7 @@ var SseMCPTransport = class {
|
|
8108
8113
|
(_b = this.onerror) == null ? void 0 : _b.call(this, error);
|
8109
8114
|
return reject(error);
|
8110
8115
|
}
|
8111
|
-
const stream = response.body.pipeThrough(new TextDecoderStream()).pipeThrough((0,
|
8116
|
+
const stream = response.body.pipeThrough(new TextDecoderStream()).pipeThrough((0, import_provider_utils24.createEventSourceParserStream)());
|
8112
8117
|
const reader = stream.getReader();
|
8113
8118
|
const processEvents = async () => {
|
8114
8119
|
var _a18, _b2, _c2;
|
@@ -8432,7 +8437,7 @@ var MCPClient = class {
|
|
8432
8437
|
if (schemas !== "automatic" && !(name17 in schemas)) {
|
8433
8438
|
continue;
|
8434
8439
|
}
|
8435
|
-
const parameters = schemas === "automatic" ? (0,
|
8440
|
+
const parameters = schemas === "automatic" ? (0, import_provider_utils25.jsonSchema)({
|
8436
8441
|
...inputSchema,
|
8437
8442
|
properties: (_a17 = inputSchema.properties) != null ? _a17 : {},
|
8438
8443
|
additionalProperties: false
|
@@ -8626,9 +8631,10 @@ var DefaultTranscriptionResult = class {
|
|
8626
8631
|
generateObject,
|
8627
8632
|
generateText,
|
8628
8633
|
getTextFromDataUrl,
|
8629
|
-
|
8634
|
+
getToolName,
|
8630
8635
|
hasToolCall,
|
8631
8636
|
isDeepEqualData,
|
8637
|
+
isToolUIPart,
|
8632
8638
|
jsonSchema,
|
8633
8639
|
modelMessageSchema,
|
8634
8640
|
parsePartialJson,
|