ai 3.1.33 → 3.1.35
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/dist/index.d.mts +28 -1
- package/dist/index.d.ts +28 -1
- package/dist/index.js +101 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +90 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/rsc/dist/rsc-server.mjs +69 -3
- 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": "3.1.
|
3
|
+
"version": "3.1.35",
|
4
4
|
"license": "Apache-2.0",
|
5
5
|
"sideEffects": false,
|
6
6
|
"main": "./dist/index.js",
|
@@ -98,8 +98,8 @@
|
|
98
98
|
"tsup": "^7.2.0",
|
99
99
|
"typescript": "5.1.3",
|
100
100
|
"zod": "3.23.8",
|
101
|
-
"
|
102
|
-
"
|
101
|
+
"@vercel/ai-tsconfig": "0.0.0",
|
102
|
+
"eslint-config-vercel-ai": "0.0.0"
|
103
103
|
},
|
104
104
|
"peerDependencies": {
|
105
105
|
"openai": "^4.42.0",
|
package/rsc/dist/rsc-server.mjs
CHANGED
@@ -253,7 +253,31 @@ function convertDataContentToUint8Array(content) {
|
|
253
253
|
throw new InvalidDataContentError({ content });
|
254
254
|
}
|
255
255
|
|
256
|
+
// core/prompt/invalid-message-role-error.ts
|
257
|
+
var InvalidMessageRoleError = class extends Error {
|
258
|
+
constructor({
|
259
|
+
role,
|
260
|
+
message = `Invalid message role: '${role}'. Must be one of: "system", "user", "assistant", "tool".`
|
261
|
+
}) {
|
262
|
+
super(message);
|
263
|
+
this.name = "AI_InvalidMessageRoleError";
|
264
|
+
this.role = role;
|
265
|
+
}
|
266
|
+
static isInvalidMessageRoleError(error) {
|
267
|
+
return error instanceof Error && error.name === "AI_InvalidMessageRoleError" && typeof error.role === "string";
|
268
|
+
}
|
269
|
+
toJSON() {
|
270
|
+
return {
|
271
|
+
name: this.name,
|
272
|
+
message: this.message,
|
273
|
+
stack: this.stack,
|
274
|
+
role: this.role
|
275
|
+
};
|
276
|
+
}
|
277
|
+
};
|
278
|
+
|
256
279
|
// core/prompt/convert-to-language-model-prompt.ts
|
280
|
+
import { getErrorMessage as getErrorMessage2 } from "@ai-sdk/provider-utils";
|
257
281
|
function convertToLanguageModelPrompt(prompt) {
|
258
282
|
const languageModelMessages = [];
|
259
283
|
if (prompt.system != null) {
|
@@ -282,7 +306,8 @@ function convertToLanguageModelPrompt(prompt) {
|
|
282
306
|
return languageModelMessages;
|
283
307
|
}
|
284
308
|
function convertToLanguageModelMessage(message) {
|
285
|
-
|
309
|
+
const role = message.role;
|
310
|
+
switch (role) {
|
286
311
|
case "system": {
|
287
312
|
return { role: "system", content: message.content };
|
288
313
|
}
|
@@ -310,6 +335,47 @@ function convertToLanguageModelMessage(message) {
|
|
310
335
|
mimeType: part.mimeType
|
311
336
|
};
|
312
337
|
}
|
338
|
+
if (typeof part.image === "string") {
|
339
|
+
try {
|
340
|
+
const url = new URL(part.image);
|
341
|
+
switch (url.protocol) {
|
342
|
+
case "http:":
|
343
|
+
case "https:": {
|
344
|
+
return {
|
345
|
+
type: "image",
|
346
|
+
image: url,
|
347
|
+
mimeType: part.mimeType
|
348
|
+
};
|
349
|
+
}
|
350
|
+
case "data:": {
|
351
|
+
try {
|
352
|
+
const [header, base64Content] = part.image.split(",");
|
353
|
+
const mimeType = header.split(";")[0].split(":")[1];
|
354
|
+
if (mimeType == null || base64Content == null) {
|
355
|
+
throw new Error("Invalid data URL format");
|
356
|
+
}
|
357
|
+
return {
|
358
|
+
type: "image",
|
359
|
+
image: convertDataContentToUint8Array(base64Content),
|
360
|
+
mimeType
|
361
|
+
};
|
362
|
+
} catch (error) {
|
363
|
+
throw new Error(
|
364
|
+
`Error processing data URL: ${getErrorMessage2(
|
365
|
+
message
|
366
|
+
)}`
|
367
|
+
);
|
368
|
+
}
|
369
|
+
}
|
370
|
+
default: {
|
371
|
+
throw new Error(
|
372
|
+
`Unsupported URL protocol: ${url.protocol}`
|
373
|
+
);
|
374
|
+
}
|
375
|
+
}
|
376
|
+
} catch (_ignored) {
|
377
|
+
}
|
378
|
+
}
|
313
379
|
const imageUint8 = convertDataContentToUint8Array(part.image);
|
314
380
|
return {
|
315
381
|
type: "image",
|
@@ -341,8 +407,8 @@ function convertToLanguageModelMessage(message) {
|
|
341
407
|
return message;
|
342
408
|
}
|
343
409
|
default: {
|
344
|
-
const _exhaustiveCheck =
|
345
|
-
throw new
|
410
|
+
const _exhaustiveCheck = role;
|
411
|
+
throw new InvalidMessageRoleError({ role: _exhaustiveCheck });
|
346
412
|
}
|
347
413
|
}
|
348
414
|
}
|