ai 4.3.13 → 4.3.15
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 +15 -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 +5 -5
- package/rsc/dist/rsc-server.mjs +54 -43
- package/rsc/dist/rsc-server.mjs.map +1 -1
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,20 @@
|
|
1
1
|
# ai
|
2
2
|
|
3
|
+
## 4.3.15
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- Updated dependencies [d87b9d1]
|
8
|
+
- @ai-sdk/provider-utils@2.2.8
|
9
|
+
- @ai-sdk/react@1.2.12
|
10
|
+
- @ai-sdk/ui-utils@1.2.11
|
11
|
+
|
12
|
+
## 4.3.14
|
13
|
+
|
14
|
+
### Patch Changes
|
15
|
+
|
16
|
+
- a295521: feat(message-validator): include more details in error messages
|
17
|
+
|
3
18
|
## 4.3.13
|
4
19
|
|
5
20
|
### Patch Changes
|
package/README.md
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
|
3
3
|
# AI SDK
|
4
4
|
|
5
|
-
The [AI SDK](https://sdk.
|
5
|
+
The [AI SDK](https://ai-sdk.dev/docs) is a TypeScript toolkit designed to help you build AI-powered applications using popular frameworks like Next.js, React, Svelte, Vue and runtimes like Node.js.
|
6
6
|
|
7
|
-
To learn more about how to use the AI SDK, check out our [API Reference](https://sdk.
|
7
|
+
To learn more about how to use the AI SDK, check out our [API Reference](https://ai-sdk.dev/docs/reference) and [Documentation](https://ai-sdk.dev/docs).
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
@@ -18,7 +18,7 @@ npm install ai
|
|
18
18
|
|
19
19
|
### AI SDK Core
|
20
20
|
|
21
|
-
The [AI SDK Core](https://sdk.
|
21
|
+
The [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core/overview) module provides a unified API to interact with model providers like [OpenAI](https://ai-sdk.dev/providers/ai-sdk-providers/openai), [Anthropic](https://ai-sdk.dev/providers/ai-sdk-providers/anthropic), [Google](https://ai-sdk.dev/providers/ai-sdk-providers/google-generative-ai), and more.
|
22
22
|
|
23
23
|
You will then install the model provider of your choice.
|
24
24
|
|
@@ -43,7 +43,7 @@ console.log(text);
|
|
43
43
|
|
44
44
|
### AI SDK UI
|
45
45
|
|
46
|
-
The [AI SDK UI](https://sdk.
|
46
|
+
The [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui/overview) module provides a set of hooks that help you build chatbots and generative user interfaces. These hooks are framework agnostic, so they can be used in Next.js, React, Svelte, and Vue.
|
47
47
|
|
48
48
|
You need to install the package for your framework:
|
49
49
|
|
package/dist/index.js
CHANGED
@@ -2016,42 +2016,6 @@ function convertToCoreMessages(messages, options) {
|
|
2016
2016
|
return coreMessages;
|
2017
2017
|
}
|
2018
2018
|
|
2019
|
-
// core/prompt/detect-prompt-type.ts
|
2020
|
-
function detectPromptType(prompt) {
|
2021
|
-
if (!Array.isArray(prompt)) {
|
2022
|
-
return "other";
|
2023
|
-
}
|
2024
|
-
if (prompt.length === 0) {
|
2025
|
-
return "messages";
|
2026
|
-
}
|
2027
|
-
const characteristics = prompt.map(detectSingleMessageCharacteristics);
|
2028
|
-
if (characteristics.some((c) => c === "has-ui-specific-parts")) {
|
2029
|
-
return "ui-messages";
|
2030
|
-
} else if (characteristics.every(
|
2031
|
-
(c) => c === "has-core-specific-parts" || c === "message"
|
2032
|
-
)) {
|
2033
|
-
return "messages";
|
2034
|
-
} else {
|
2035
|
-
return "other";
|
2036
|
-
}
|
2037
|
-
}
|
2038
|
-
function detectSingleMessageCharacteristics(message) {
|
2039
|
-
if (typeof message === "object" && message !== null && (message.role === "function" || // UI-only role
|
2040
|
-
message.role === "data" || // UI-only role
|
2041
|
-
"toolInvocations" in message || // UI-specific field
|
2042
|
-
"parts" in message || // UI-specific field
|
2043
|
-
"experimental_attachments" in message)) {
|
2044
|
-
return "has-ui-specific-parts";
|
2045
|
-
} else if (typeof message === "object" && message !== null && "content" in message && (Array.isArray(message.content) || // Core messages can have array content
|
2046
|
-
"experimental_providerMetadata" in message || "providerOptions" in message)) {
|
2047
|
-
return "has-core-specific-parts";
|
2048
|
-
} else if (typeof message === "object" && message !== null && "role" in message && "content" in message && typeof message.content === "string" && ["system", "user", "assistant", "tool"].includes(message.role)) {
|
2049
|
-
return "message";
|
2050
|
-
} else {
|
2051
|
-
return "other";
|
2052
|
-
}
|
2053
|
-
}
|
2054
|
-
|
2055
2019
|
// core/prompt/message.ts
|
2056
2020
|
var import_zod6 = require("zod");
|
2057
2021
|
|
@@ -2235,12 +2199,6 @@ function standardizePrompt({
|
|
2235
2199
|
}
|
2236
2200
|
if (prompt.messages != null) {
|
2237
2201
|
const promptType = detectPromptType(prompt.messages);
|
2238
|
-
if (promptType === "other") {
|
2239
|
-
throw new import_provider10.InvalidPromptError({
|
2240
|
-
prompt,
|
2241
|
-
message: "messages must be an array of CoreMessage or UIMessage"
|
2242
|
-
});
|
2243
|
-
}
|
2244
2202
|
const messages = promptType === "ui-messages" ? convertToCoreMessages(prompt.messages, {
|
2245
2203
|
tools
|
2246
2204
|
}) : prompt.messages;
|
@@ -2257,7 +2215,10 @@ function standardizePrompt({
|
|
2257
2215
|
if (!validationResult.success) {
|
2258
2216
|
throw new import_provider10.InvalidPromptError({
|
2259
2217
|
prompt,
|
2260
|
-
message:
|
2218
|
+
message: [
|
2219
|
+
"message must be a CoreMessage or a UI message",
|
2220
|
+
`Validation error: ${validationResult.error.message}`
|
2221
|
+
].join("\n"),
|
2261
2222
|
cause: validationResult.error
|
2262
2223
|
});
|
2263
2224
|
}
|
@@ -2269,6 +2230,56 @@ function standardizePrompt({
|
|
2269
2230
|
}
|
2270
2231
|
throw new Error("unreachable");
|
2271
2232
|
}
|
2233
|
+
function detectPromptType(prompt) {
|
2234
|
+
if (!Array.isArray(prompt)) {
|
2235
|
+
throw new import_provider10.InvalidPromptError({
|
2236
|
+
prompt,
|
2237
|
+
message: [
|
2238
|
+
"messages must be an array of CoreMessage or UIMessage",
|
2239
|
+
`Received non-array value: ${JSON.stringify(prompt)}`
|
2240
|
+
].join("\n"),
|
2241
|
+
cause: prompt
|
2242
|
+
});
|
2243
|
+
}
|
2244
|
+
if (prompt.length === 0) {
|
2245
|
+
return "messages";
|
2246
|
+
}
|
2247
|
+
const characteristics = prompt.map(detectSingleMessageCharacteristics);
|
2248
|
+
if (characteristics.some((c) => c === "has-ui-specific-parts")) {
|
2249
|
+
return "ui-messages";
|
2250
|
+
}
|
2251
|
+
const nonMessageIndex = characteristics.findIndex(
|
2252
|
+
(c) => c !== "has-core-specific-parts" && c !== "message"
|
2253
|
+
);
|
2254
|
+
if (nonMessageIndex === -1) {
|
2255
|
+
return "messages";
|
2256
|
+
}
|
2257
|
+
throw new import_provider10.InvalidPromptError({
|
2258
|
+
prompt,
|
2259
|
+
message: [
|
2260
|
+
"messages must be an array of CoreMessage or UIMessage",
|
2261
|
+
`Received message of type: "${characteristics[nonMessageIndex]}" at index ${nonMessageIndex}`,
|
2262
|
+
`messages[${nonMessageIndex}]: ${JSON.stringify(prompt[nonMessageIndex])}`
|
2263
|
+
].join("\n"),
|
2264
|
+
cause: prompt
|
2265
|
+
});
|
2266
|
+
}
|
2267
|
+
function detectSingleMessageCharacteristics(message) {
|
2268
|
+
if (typeof message === "object" && message !== null && (message.role === "function" || // UI-only role
|
2269
|
+
message.role === "data" || // UI-only role
|
2270
|
+
"toolInvocations" in message || // UI-specific field
|
2271
|
+
"parts" in message || // UI-specific field
|
2272
|
+
"experimental_attachments" in message)) {
|
2273
|
+
return "has-ui-specific-parts";
|
2274
|
+
} else if (typeof message === "object" && message !== null && "content" in message && (Array.isArray(message.content) || // Core messages can have array content
|
2275
|
+
"experimental_providerMetadata" in message || "providerOptions" in message)) {
|
2276
|
+
return "has-core-specific-parts";
|
2277
|
+
} else if (typeof message === "object" && message !== null && "role" in message && "content" in message && typeof message.content === "string" && ["system", "user", "assistant", "tool"].includes(message.role)) {
|
2278
|
+
return "message";
|
2279
|
+
} else {
|
2280
|
+
return "other";
|
2281
|
+
}
|
2282
|
+
}
|
2272
2283
|
|
2273
2284
|
// core/types/usage.ts
|
2274
2285
|
function calculateLanguageModelUsage({
|