ai 3.3.31 → 3.3.33
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 +12 -0
- package/dist/index.d.mts +56 -2
- package/dist/index.d.ts +56 -2
- package/dist/index.js +94 -86
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +94 -86
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/rsc/dist/index.d.ts +7 -1
- package/rsc/dist/rsc-server.d.mts +7 -1
- package/rsc/dist/rsc-server.mjs +82 -82
- 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.3.
|
3
|
+
"version": "3.3.33",
|
4
4
|
"description": "Vercel AI SDK - The AI Toolkit for TypeScript and JavaScript",
|
5
5
|
"license": "Apache-2.0",
|
6
6
|
"sideEffects": false,
|
@@ -101,8 +101,8 @@
|
|
101
101
|
"tsup": "^7.2.0",
|
102
102
|
"typescript": "5.5.4",
|
103
103
|
"zod": "3.23.8",
|
104
|
-
"
|
105
|
-
"
|
104
|
+
"@vercel/ai-tsconfig": "0.0.0",
|
105
|
+
"eslint-config-vercel-ai": "0.0.0"
|
106
106
|
},
|
107
107
|
"peerDependencies": {
|
108
108
|
"openai": "^4.42.0",
|
package/rsc/dist/index.d.ts
CHANGED
@@ -460,7 +460,7 @@ type RenderResult = {
|
|
460
460
|
*/
|
461
461
|
declare function streamUI<TOOLS extends {
|
462
462
|
[name: string]: z.ZodTypeAny;
|
463
|
-
} = {}>({ model, tools, toolChoice, system, prompt, messages, maxRetries, abortSignal, headers, initial, text, onFinish, ...settings }: CallSettings & Prompt & {
|
463
|
+
} = {}>({ model, tools, toolChoice, system, prompt, messages, maxRetries, abortSignal, headers, initial, text, experimental_providerMetadata: providerMetadata, onFinish, ...settings }: CallSettings & Prompt & {
|
464
464
|
/**
|
465
465
|
* The language model to use.
|
466
466
|
*/
|
@@ -478,6 +478,12 @@ declare function streamUI<TOOLS extends {
|
|
478
478
|
text?: RenderText;
|
479
479
|
initial?: ReactNode;
|
480
480
|
/**
|
481
|
+
Additional provider-specific metadata. They are passed through
|
482
|
+
to the provider from the AI SDK and enable provider-specific
|
483
|
+
functionality that can be fully encapsulated in the provider.
|
484
|
+
*/
|
485
|
+
experimental_providerMetadata?: ProviderMetadata;
|
486
|
+
/**
|
481
487
|
* Callback that is called when the LLM response and the final object validation are finished.
|
482
488
|
*/
|
483
489
|
onFinish?: (event: {
|
@@ -458,7 +458,7 @@ type RenderResult = {
|
|
458
458
|
*/
|
459
459
|
declare function streamUI<TOOLS extends {
|
460
460
|
[name: string]: z.ZodTypeAny;
|
461
|
-
} = {}>({ model, tools, toolChoice, system, prompt, messages, maxRetries, abortSignal, headers, initial, text, onFinish, ...settings }: CallSettings & Prompt & {
|
461
|
+
} = {}>({ model, tools, toolChoice, system, prompt, messages, maxRetries, abortSignal, headers, initial, text, experimental_providerMetadata: providerMetadata, onFinish, ...settings }: CallSettings & Prompt & {
|
462
462
|
/**
|
463
463
|
* The language model to use.
|
464
464
|
*/
|
@@ -476,6 +476,12 @@ declare function streamUI<TOOLS extends {
|
|
476
476
|
text?: RenderText;
|
477
477
|
initial?: ReactNode;
|
478
478
|
/**
|
479
|
+
Additional provider-specific metadata. They are passed through
|
480
|
+
to the provider from the AI SDK and enable provider-specific
|
481
|
+
functionality that can be fully encapsulated in the provider.
|
482
|
+
*/
|
483
|
+
experimental_providerMetadata?: ProviderMetadata;
|
484
|
+
/**
|
479
485
|
* Callback that is called when the LLM response and the final object validation are finished.
|
480
486
|
*/
|
481
487
|
onFinish?: (event: {
|
package/rsc/dist/rsc-server.mjs
CHANGED
@@ -480,100 +480,98 @@ function convertToLanguageModelMessage(message, downloadedImages) {
|
|
480
480
|
}
|
481
481
|
return {
|
482
482
|
role: "user",
|
483
|
-
content: message.content.map(
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
if (
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
};
|
511
|
-
}
|
483
|
+
content: message.content.map((part) => {
|
484
|
+
var _a8, _b, _c;
|
485
|
+
switch (part.type) {
|
486
|
+
case "text": {
|
487
|
+
return {
|
488
|
+
type: "text",
|
489
|
+
text: part.text,
|
490
|
+
providerMetadata: part.experimental_providerMetadata
|
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
|
+
};
|
512
510
|
}
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
}
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
}
|
511
|
+
}
|
512
|
+
if (typeof part.image === "string") {
|
513
|
+
try {
|
514
|
+
const url = new URL(part.image);
|
515
|
+
switch (url.protocol) {
|
516
|
+
case "http:":
|
517
|
+
case "https:": {
|
518
|
+
if (downloadedImages == null) {
|
519
|
+
return {
|
520
|
+
type: "image",
|
521
|
+
image: url,
|
522
|
+
mimeType: part.mimeType,
|
523
|
+
providerMetadata: part.experimental_providerMetadata
|
524
|
+
};
|
525
|
+
} else {
|
526
|
+
const downloadedImage = downloadedImages[part.image];
|
527
|
+
return {
|
528
|
+
type: "image",
|
529
|
+
image: downloadedImage.data,
|
530
|
+
mimeType: (_b = part.mimeType) != null ? _b : downloadedImage.mimeType,
|
531
|
+
providerMetadata: part.experimental_providerMetadata
|
532
|
+
};
|
535
533
|
}
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
return {
|
544
|
-
type: "image",
|
545
|
-
image: convertDataContentToUint8Array(base64Content),
|
546
|
-
mimeType,
|
547
|
-
providerMetadata: part.experimental_providerMetadata
|
548
|
-
};
|
549
|
-
} catch (error) {
|
550
|
-
throw new Error(
|
551
|
-
`Error processing data URL: ${getErrorMessage(
|
552
|
-
message
|
553
|
-
)}`
|
554
|
-
);
|
534
|
+
}
|
535
|
+
case "data:": {
|
536
|
+
try {
|
537
|
+
const [header, base64Content] = part.image.split(",");
|
538
|
+
const mimeType = header.split(";")[0].split(":")[1];
|
539
|
+
if (mimeType == null || base64Content == null) {
|
540
|
+
throw new Error("Invalid data URL format");
|
555
541
|
}
|
556
|
-
|
557
|
-
|
542
|
+
return {
|
543
|
+
type: "image",
|
544
|
+
image: convertDataContentToUint8Array(base64Content),
|
545
|
+
mimeType,
|
546
|
+
providerMetadata: part.experimental_providerMetadata
|
547
|
+
};
|
548
|
+
} catch (error) {
|
558
549
|
throw new Error(
|
559
|
-
`
|
550
|
+
`Error processing data URL: ${getErrorMessage(
|
551
|
+
message
|
552
|
+
)}`
|
560
553
|
);
|
561
554
|
}
|
562
555
|
}
|
563
|
-
|
556
|
+
default: {
|
557
|
+
throw new Error(
|
558
|
+
`Unsupported URL protocol: ${url.protocol}`
|
559
|
+
);
|
560
|
+
}
|
564
561
|
}
|
562
|
+
} catch (_ignored) {
|
565
563
|
}
|
566
|
-
const imageUint8 = convertDataContentToUint8Array(part.image);
|
567
|
-
return {
|
568
|
-
type: "image",
|
569
|
-
image: imageUint8,
|
570
|
-
mimeType: (_c = part.mimeType) != null ? _c : detectImageMimeType(imageUint8),
|
571
|
-
providerMetadata: part.experimental_providerMetadata
|
572
|
-
};
|
573
564
|
}
|
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
|
+
};
|
574
572
|
}
|
575
573
|
}
|
576
|
-
),
|
574
|
+
}).filter((part) => part.type !== "text" || part.text !== ""),
|
577
575
|
providerMetadata: message.experimental_providerMetadata
|
578
576
|
};
|
579
577
|
}
|
@@ -1291,6 +1289,7 @@ async function streamUI({
|
|
1291
1289
|
headers,
|
1292
1290
|
initial,
|
1293
1291
|
text,
|
1292
|
+
experimental_providerMetadata: providerMetadata,
|
1294
1293
|
onFinish,
|
1295
1294
|
...settings
|
1296
1295
|
}) {
|
@@ -1368,6 +1367,7 @@ async function streamUI({
|
|
1368
1367
|
prompt: validatedPrompt,
|
1369
1368
|
modelSupportsImageUrls: model.supportsImageUrls
|
1370
1369
|
}),
|
1370
|
+
providerMetadata,
|
1371
1371
|
abortSignal,
|
1372
1372
|
headers
|
1373
1373
|
})
|