ai 4.3.12 → 4.3.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 +14 -0
- package/README.md +4 -4
- package/dist/index.js +54 -43
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +54 -43
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/rsc/dist/rsc-server.mjs +54 -43
- package/rsc/dist/rsc-server.mjs.map +1 -1
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "ai",
|
3
|
-
"version": "4.3.
|
3
|
+
"version": "4.3.14",
|
4
4
|
"description": "AI SDK by Vercel - The AI Toolkit for TypeScript and JavaScript",
|
5
5
|
"license": "Apache-2.0",
|
6
6
|
"sideEffects": false,
|
@@ -48,8 +48,8 @@
|
|
48
48
|
"dependencies": {
|
49
49
|
"@ai-sdk/provider": "1.1.3",
|
50
50
|
"@ai-sdk/provider-utils": "2.2.7",
|
51
|
-
"@ai-sdk/react": "1.2.
|
52
|
-
"@ai-sdk/ui-utils": "1.2.
|
51
|
+
"@ai-sdk/react": "1.2.11",
|
52
|
+
"@ai-sdk/ui-utils": "1.2.10",
|
53
53
|
"@opentelemetry/api": "1.9.0",
|
54
54
|
"jsondiffpatch": "0.6.0"
|
55
55
|
},
|
@@ -83,7 +83,7 @@
|
|
83
83
|
"publishConfig": {
|
84
84
|
"access": "public"
|
85
85
|
},
|
86
|
-
"homepage": "https://sdk.
|
86
|
+
"homepage": "https://ai-sdk.dev/docs",
|
87
87
|
"repository": {
|
88
88
|
"type": "git",
|
89
89
|
"url": "git+https://github.com/vercel/ai.git"
|
package/rsc/dist/rsc-server.mjs
CHANGED
@@ -1333,42 +1333,6 @@ function convertToCoreMessages(messages, options) {
|
|
1333
1333
|
return coreMessages;
|
1334
1334
|
}
|
1335
1335
|
|
1336
|
-
// core/prompt/detect-prompt-type.ts
|
1337
|
-
function detectPromptType(prompt) {
|
1338
|
-
if (!Array.isArray(prompt)) {
|
1339
|
-
return "other";
|
1340
|
-
}
|
1341
|
-
if (prompt.length === 0) {
|
1342
|
-
return "messages";
|
1343
|
-
}
|
1344
|
-
const characteristics = prompt.map(detectSingleMessageCharacteristics);
|
1345
|
-
if (characteristics.some((c) => c === "has-ui-specific-parts")) {
|
1346
|
-
return "ui-messages";
|
1347
|
-
} else if (characteristics.every(
|
1348
|
-
(c) => c === "has-core-specific-parts" || c === "message"
|
1349
|
-
)) {
|
1350
|
-
return "messages";
|
1351
|
-
} else {
|
1352
|
-
return "other";
|
1353
|
-
}
|
1354
|
-
}
|
1355
|
-
function detectSingleMessageCharacteristics(message) {
|
1356
|
-
if (typeof message === "object" && message !== null && (message.role === "function" || // UI-only role
|
1357
|
-
message.role === "data" || // UI-only role
|
1358
|
-
"toolInvocations" in message || // UI-specific field
|
1359
|
-
"parts" in message || // UI-specific field
|
1360
|
-
"experimental_attachments" in message)) {
|
1361
|
-
return "has-ui-specific-parts";
|
1362
|
-
} else if (typeof message === "object" && message !== null && "content" in message && (Array.isArray(message.content) || // Core messages can have array content
|
1363
|
-
"experimental_providerMetadata" in message || "providerOptions" in message)) {
|
1364
|
-
return "has-core-specific-parts";
|
1365
|
-
} else if (typeof message === "object" && message !== null && "role" in message && "content" in message && typeof message.content === "string" && ["system", "user", "assistant", "tool"].includes(message.role)) {
|
1366
|
-
return "message";
|
1367
|
-
} else {
|
1368
|
-
return "other";
|
1369
|
-
}
|
1370
|
-
}
|
1371
|
-
|
1372
1336
|
// core/prompt/message.ts
|
1373
1337
|
import { z as z6 } from "zod";
|
1374
1338
|
|
@@ -1552,12 +1516,6 @@ function standardizePrompt({
|
|
1552
1516
|
}
|
1553
1517
|
if (prompt.messages != null) {
|
1554
1518
|
const promptType = detectPromptType(prompt.messages);
|
1555
|
-
if (promptType === "other") {
|
1556
|
-
throw new InvalidPromptError({
|
1557
|
-
prompt,
|
1558
|
-
message: "messages must be an array of CoreMessage or UIMessage"
|
1559
|
-
});
|
1560
|
-
}
|
1561
1519
|
const messages = promptType === "ui-messages" ? convertToCoreMessages(prompt.messages, {
|
1562
1520
|
tools
|
1563
1521
|
}) : prompt.messages;
|
@@ -1574,7 +1532,10 @@ function standardizePrompt({
|
|
1574
1532
|
if (!validationResult.success) {
|
1575
1533
|
throw new InvalidPromptError({
|
1576
1534
|
prompt,
|
1577
|
-
message:
|
1535
|
+
message: [
|
1536
|
+
"message must be a CoreMessage or a UI message",
|
1537
|
+
`Validation error: ${validationResult.error.message}`
|
1538
|
+
].join("\n"),
|
1578
1539
|
cause: validationResult.error
|
1579
1540
|
});
|
1580
1541
|
}
|
@@ -1586,6 +1547,56 @@ function standardizePrompt({
|
|
1586
1547
|
}
|
1587
1548
|
throw new Error("unreachable");
|
1588
1549
|
}
|
1550
|
+
function detectPromptType(prompt) {
|
1551
|
+
if (!Array.isArray(prompt)) {
|
1552
|
+
throw new InvalidPromptError({
|
1553
|
+
prompt,
|
1554
|
+
message: [
|
1555
|
+
"messages must be an array of CoreMessage or UIMessage",
|
1556
|
+
`Received non-array value: ${JSON.stringify(prompt)}`
|
1557
|
+
].join("\n"),
|
1558
|
+
cause: prompt
|
1559
|
+
});
|
1560
|
+
}
|
1561
|
+
if (prompt.length === 0) {
|
1562
|
+
return "messages";
|
1563
|
+
}
|
1564
|
+
const characteristics = prompt.map(detectSingleMessageCharacteristics);
|
1565
|
+
if (characteristics.some((c) => c === "has-ui-specific-parts")) {
|
1566
|
+
return "ui-messages";
|
1567
|
+
}
|
1568
|
+
const nonMessageIndex = characteristics.findIndex(
|
1569
|
+
(c) => c !== "has-core-specific-parts" && c !== "message"
|
1570
|
+
);
|
1571
|
+
if (nonMessageIndex === -1) {
|
1572
|
+
return "messages";
|
1573
|
+
}
|
1574
|
+
throw new InvalidPromptError({
|
1575
|
+
prompt,
|
1576
|
+
message: [
|
1577
|
+
"messages must be an array of CoreMessage or UIMessage",
|
1578
|
+
`Received message of type: "${characteristics[nonMessageIndex]}" at index ${nonMessageIndex}`,
|
1579
|
+
`messages[${nonMessageIndex}]: ${JSON.stringify(prompt[nonMessageIndex])}`
|
1580
|
+
].join("\n"),
|
1581
|
+
cause: prompt
|
1582
|
+
});
|
1583
|
+
}
|
1584
|
+
function detectSingleMessageCharacteristics(message) {
|
1585
|
+
if (typeof message === "object" && message !== null && (message.role === "function" || // UI-only role
|
1586
|
+
message.role === "data" || // UI-only role
|
1587
|
+
"toolInvocations" in message || // UI-specific field
|
1588
|
+
"parts" in message || // UI-specific field
|
1589
|
+
"experimental_attachments" in message)) {
|
1590
|
+
return "has-ui-specific-parts";
|
1591
|
+
} else if (typeof message === "object" && message !== null && "content" in message && (Array.isArray(message.content) || // Core messages can have array content
|
1592
|
+
"experimental_providerMetadata" in message || "providerOptions" in message)) {
|
1593
|
+
return "has-core-specific-parts";
|
1594
|
+
} else if (typeof message === "object" && message !== null && "role" in message && "content" in message && typeof message.content === "string" && ["system", "user", "assistant", "tool"].includes(message.role)) {
|
1595
|
+
return "message";
|
1596
|
+
} else {
|
1597
|
+
return "other";
|
1598
|
+
}
|
1599
|
+
}
|
1589
1600
|
|
1590
1601
|
// core/types/usage.ts
|
1591
1602
|
function calculateLanguageModelUsage({
|