ai 3.4.5 → 3.4.6
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/dist/index.d.mts +24 -1
- package/dist/index.d.ts +24 -1
- package/dist/index.js +117 -81
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +117 -81
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -8
- package/rsc/dist/index.d.ts +24 -1
- package/rsc/dist/rsc-server.d.mts +24 -1
- package/rsc/dist/rsc-server.mjs +117 -81
- 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.4.
|
3
|
+
"version": "3.4.6",
|
4
4
|
"description": "AI SDK by Vercel - The AI Toolkit for TypeScript and JavaScript",
|
5
5
|
"license": "Apache-2.0",
|
6
6
|
"sideEffects": false,
|
@@ -64,13 +64,13 @@
|
|
64
64
|
}
|
65
65
|
},
|
66
66
|
"dependencies": {
|
67
|
-
"@ai-sdk/provider": "0.0.
|
68
|
-
"@ai-sdk/provider-utils": "1.0.
|
69
|
-
"@ai-sdk/react": "0.0.
|
70
|
-
"@ai-sdk/solid": "0.0.
|
71
|
-
"@ai-sdk/svelte": "0.0.
|
72
|
-
"@ai-sdk/ui-utils": "0.0.
|
73
|
-
"@ai-sdk/vue": "0.0.
|
67
|
+
"@ai-sdk/provider": "0.0.24",
|
68
|
+
"@ai-sdk/provider-utils": "1.0.20",
|
69
|
+
"@ai-sdk/react": "0.0.62",
|
70
|
+
"@ai-sdk/solid": "0.0.49",
|
71
|
+
"@ai-sdk/svelte": "0.0.51",
|
72
|
+
"@ai-sdk/ui-utils": "0.0.46",
|
73
|
+
"@ai-sdk/vue": "0.0.53",
|
74
74
|
"@opentelemetry/api": "1.9.0",
|
75
75
|
"eventsource-parser": "1.1.2",
|
76
76
|
"jsondiffpatch": "0.6.0",
|
package/rsc/dist/index.d.ts
CHANGED
@@ -274,6 +274,29 @@ interface ImagePart {
|
|
274
274
|
experimental_providerMetadata?: ProviderMetadata;
|
275
275
|
}
|
276
276
|
/**
|
277
|
+
File content part of a prompt. It contains a file.
|
278
|
+
*/
|
279
|
+
interface FilePart {
|
280
|
+
type: 'file';
|
281
|
+
/**
|
282
|
+
File data. Can either be:
|
283
|
+
|
284
|
+
- data: a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer
|
285
|
+
- URL: a URL that points to the image
|
286
|
+
*/
|
287
|
+
data: DataContent | URL;
|
288
|
+
/**
|
289
|
+
Mime type of the file.
|
290
|
+
*/
|
291
|
+
mimeType: string;
|
292
|
+
/**
|
293
|
+
Additional provider-specific metadata. They are passed through
|
294
|
+
to the provider from the AI SDK and enable provider-specific
|
295
|
+
functionality that can be fully encapsulated in the provider.
|
296
|
+
*/
|
297
|
+
experimental_providerMetadata?: ProviderMetadata;
|
298
|
+
}
|
299
|
+
/**
|
277
300
|
Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
|
278
301
|
*/
|
279
302
|
interface ToolCallPart {
|
@@ -359,7 +382,7 @@ type CoreUserMessage = {
|
|
359
382
|
/**
|
360
383
|
Content of a user message. It can be a string or an array of text and image parts.
|
361
384
|
*/
|
362
|
-
type UserContent = string | Array<TextPart | ImagePart>;
|
385
|
+
type UserContent = string | Array<TextPart | ImagePart | FilePart>;
|
363
386
|
/**
|
364
387
|
An assistant message. It can contain text, tool calls, or a combination of text and tool calls.
|
365
388
|
*/
|
@@ -272,6 +272,29 @@ interface ImagePart {
|
|
272
272
|
experimental_providerMetadata?: ProviderMetadata;
|
273
273
|
}
|
274
274
|
/**
|
275
|
+
File content part of a prompt. It contains a file.
|
276
|
+
*/
|
277
|
+
interface FilePart {
|
278
|
+
type: 'file';
|
279
|
+
/**
|
280
|
+
File data. Can either be:
|
281
|
+
|
282
|
+
- data: a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer
|
283
|
+
- URL: a URL that points to the image
|
284
|
+
*/
|
285
|
+
data: DataContent | URL;
|
286
|
+
/**
|
287
|
+
Mime type of the file.
|
288
|
+
*/
|
289
|
+
mimeType: string;
|
290
|
+
/**
|
291
|
+
Additional provider-specific metadata. They are passed through
|
292
|
+
to the provider from the AI SDK and enable provider-specific
|
293
|
+
functionality that can be fully encapsulated in the provider.
|
294
|
+
*/
|
295
|
+
experimental_providerMetadata?: ProviderMetadata;
|
296
|
+
}
|
297
|
+
/**
|
275
298
|
Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
|
276
299
|
*/
|
277
300
|
interface ToolCallPart {
|
@@ -357,7 +380,7 @@ type CoreUserMessage = {
|
|
357
380
|
/**
|
358
381
|
Content of a user message. It can be a string or an array of text and image parts.
|
359
382
|
*/
|
360
|
-
type UserContent = string | Array<TextPart | ImagePart>;
|
383
|
+
type UserContent = string | Array<TextPart | ImagePart | FilePart>;
|
361
384
|
/**
|
362
385
|
An assistant message. It can contain text, tool calls, or a combination of text and tool calls.
|
363
386
|
*/
|
package/rsc/dist/rsc-server.mjs
CHANGED
@@ -366,6 +366,15 @@ var dataContentSchema = z.union([
|
|
366
366
|
{ message: "Must be a Buffer" }
|
367
367
|
)
|
368
368
|
]);
|
369
|
+
function convertDataContentToBase64String(content) {
|
370
|
+
if (typeof content === "string") {
|
371
|
+
return content;
|
372
|
+
}
|
373
|
+
if (content instanceof ArrayBuffer) {
|
374
|
+
return convertUint8ArrayToBase64(new Uint8Array(content));
|
375
|
+
}
|
376
|
+
return convertUint8ArrayToBase64(content);
|
377
|
+
}
|
369
378
|
function convertDataContentToUint8Array(content) {
|
370
379
|
if (content instanceof Uint8Array) {
|
371
380
|
return content;
|
@@ -480,98 +489,119 @@ function convertToLanguageModelMessage(message, downloadedImages) {
|
|
480
489
|
}
|
481
490
|
return {
|
482
491
|
role: "user",
|
483
|
-
content: message.content.map(
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
case "image": {
|
494
|
-
if (part.image instanceof URL) {
|
495
|
-
if (downloadedImages == null) {
|
496
|
-
return {
|
497
|
-
type: "image",
|
498
|
-
image: part.image,
|
499
|
-
mimeType: part.mimeType,
|
500
|
-
providerMetadata: part.experimental_providerMetadata
|
501
|
-
};
|
502
|
-
} else {
|
503
|
-
const downloadedImage = downloadedImages[part.image.toString()];
|
504
|
-
return {
|
505
|
-
type: "image",
|
506
|
-
image: downloadedImage.data,
|
507
|
-
mimeType: (_a8 = part.mimeType) != null ? _a8 : downloadedImage.mimeType,
|
508
|
-
providerMetadata: part.experimental_providerMetadata
|
509
|
-
};
|
510
|
-
}
|
492
|
+
content: message.content.map(
|
493
|
+
(part) => {
|
494
|
+
var _a8, _b, _c;
|
495
|
+
switch (part.type) {
|
496
|
+
case "text": {
|
497
|
+
return {
|
498
|
+
type: "text",
|
499
|
+
text: part.text,
|
500
|
+
providerMetadata: part.experimental_providerMetadata
|
501
|
+
};
|
511
502
|
}
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
503
|
+
case "image": {
|
504
|
+
if (part.image instanceof URL) {
|
505
|
+
if (downloadedImages == null) {
|
506
|
+
return {
|
507
|
+
type: "image",
|
508
|
+
image: part.image,
|
509
|
+
mimeType: part.mimeType,
|
510
|
+
providerMetadata: part.experimental_providerMetadata
|
511
|
+
};
|
512
|
+
} else {
|
513
|
+
const downloadedImage = downloadedImages[part.image.toString()];
|
514
|
+
return {
|
515
|
+
type: "image",
|
516
|
+
image: downloadedImage.data,
|
517
|
+
mimeType: (_a8 = part.mimeType) != null ? _a8 : downloadedImage.mimeType,
|
518
|
+
providerMetadata: part.experimental_providerMetadata
|
519
|
+
};
|
520
|
+
}
|
521
|
+
}
|
522
|
+
if (typeof part.image === "string") {
|
523
|
+
try {
|
524
|
+
const url = new URL(part.image);
|
525
|
+
switch (url.protocol) {
|
526
|
+
case "http:":
|
527
|
+
case "https:": {
|
528
|
+
if (downloadedImages == null) {
|
529
|
+
return {
|
530
|
+
type: "image",
|
531
|
+
image: url,
|
532
|
+
mimeType: part.mimeType,
|
533
|
+
providerMetadata: part.experimental_providerMetadata
|
534
|
+
};
|
535
|
+
} else {
|
536
|
+
const downloadedImage = downloadedImages[part.image];
|
537
|
+
return {
|
538
|
+
type: "image",
|
539
|
+
image: downloadedImage.data,
|
540
|
+
mimeType: (_b = part.mimeType) != null ? _b : downloadedImage.mimeType,
|
541
|
+
providerMetadata: part.experimental_providerMetadata
|
542
|
+
};
|
543
|
+
}
|
533
544
|
}
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
545
|
+
case "data:": {
|
546
|
+
try {
|
547
|
+
const [header, base64Content] = part.image.split(",");
|
548
|
+
const mimeType = header.split(";")[0].split(":")[1];
|
549
|
+
if (mimeType == null || base64Content == null) {
|
550
|
+
throw new Error("Invalid data URL format");
|
551
|
+
}
|
552
|
+
return {
|
553
|
+
type: "image",
|
554
|
+
image: convertDataContentToUint8Array(base64Content),
|
555
|
+
mimeType,
|
556
|
+
providerMetadata: part.experimental_providerMetadata
|
557
|
+
};
|
558
|
+
} catch (error) {
|
559
|
+
throw new Error(
|
560
|
+
`Error processing data URL: ${getErrorMessage(
|
561
|
+
message
|
562
|
+
)}`
|
563
|
+
);
|
541
564
|
}
|
542
|
-
|
543
|
-
|
544
|
-
image: convertDataContentToUint8Array(base64Content),
|
545
|
-
mimeType,
|
546
|
-
providerMetadata: part.experimental_providerMetadata
|
547
|
-
};
|
548
|
-
} catch (error) {
|
565
|
+
}
|
566
|
+
default: {
|
549
567
|
throw new Error(
|
550
|
-
`
|
551
|
-
message
|
552
|
-
)}`
|
568
|
+
`Unsupported URL protocol: ${url.protocol}`
|
553
569
|
);
|
554
570
|
}
|
555
571
|
}
|
556
|
-
|
557
|
-
throw new Error(
|
558
|
-
`Unsupported URL protocol: ${url.protocol}`
|
559
|
-
);
|
560
|
-
}
|
572
|
+
} catch (_ignored) {
|
561
573
|
}
|
562
|
-
} catch (_ignored) {
|
563
574
|
}
|
575
|
+
const imageUint8 = convertDataContentToUint8Array(part.image);
|
576
|
+
return {
|
577
|
+
type: "image",
|
578
|
+
image: imageUint8,
|
579
|
+
mimeType: (_c = part.mimeType) != null ? _c : detectImageMimeType(imageUint8),
|
580
|
+
providerMetadata: part.experimental_providerMetadata
|
581
|
+
};
|
582
|
+
}
|
583
|
+
case "file": {
|
584
|
+
if (part.data instanceof URL) {
|
585
|
+
return {
|
586
|
+
type: "file",
|
587
|
+
data: part.data,
|
588
|
+
mimeType: part.mimeType,
|
589
|
+
providerMetadata: part.experimental_providerMetadata
|
590
|
+
};
|
591
|
+
}
|
592
|
+
const imageBase64 = convertDataContentToBase64String(
|
593
|
+
part.data
|
594
|
+
);
|
595
|
+
return {
|
596
|
+
type: "file",
|
597
|
+
data: imageBase64,
|
598
|
+
mimeType: part.mimeType,
|
599
|
+
providerMetadata: part.experimental_providerMetadata
|
600
|
+
};
|
564
601
|
}
|
565
|
-
const imageUint8 = convertDataContentToUint8Array(part.image);
|
566
|
-
return {
|
567
|
-
type: "image",
|
568
|
-
image: imageUint8,
|
569
|
-
mimeType: (_c = part.mimeType) != null ? _c : detectImageMimeType(imageUint8),
|
570
|
-
providerMetadata: part.experimental_providerMetadata
|
571
|
-
};
|
572
602
|
}
|
573
603
|
}
|
574
|
-
|
604
|
+
).filter((part) => part.type !== "text" || part.text !== ""),
|
575
605
|
providerMetadata: message.experimental_providerMetadata
|
576
606
|
};
|
577
607
|
}
|
@@ -862,6 +892,12 @@ var imagePartSchema = z4.object({
|
|
862
892
|
mimeType: z4.string().optional(),
|
863
893
|
experimental_providerMetadata: providerMetadataSchema.optional()
|
864
894
|
});
|
895
|
+
var filePartSchema = z4.object({
|
896
|
+
type: z4.literal("file"),
|
897
|
+
data: z4.union([dataContentSchema, z4.instanceof(URL)]),
|
898
|
+
mimeType: z4.string(),
|
899
|
+
experimental_providerMetadata: providerMetadataSchema.optional()
|
900
|
+
});
|
865
901
|
var toolCallPartSchema = z4.object({
|
866
902
|
type: z4.literal("tool-call"),
|
867
903
|
toolCallId: z4.string(),
|
@@ -887,7 +923,7 @@ var coreUserMessageSchema = z5.object({
|
|
887
923
|
role: z5.literal("user"),
|
888
924
|
content: z5.union([
|
889
925
|
z5.string(),
|
890
|
-
z5.array(z5.union([textPartSchema, imagePartSchema]))
|
926
|
+
z5.array(z5.union([textPartSchema, imagePartSchema, filePartSchema]))
|
891
927
|
]),
|
892
928
|
experimental_providerMetadata: providerMetadataSchema.optional()
|
893
929
|
});
|