ai 3.4.4 → 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 +26 -0
- package/dist/index.d.mts +30 -2
- package/dist/index.d.ts +30 -2
- package/dist/index.js +125 -85
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +125 -85
- 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/CHANGELOG.md
CHANGED
@@ -1,5 +1,31 @@
|
|
1
1
|
# ai
|
2
2
|
|
3
|
+
## 3.4.6
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- d595d0d: feat (ai/core): file content parts
|
8
|
+
- Updated dependencies [d595d0d]
|
9
|
+
- @ai-sdk/provider@0.0.24
|
10
|
+
- @ai-sdk/provider-utils@1.0.20
|
11
|
+
- @ai-sdk/ui-utils@0.0.46
|
12
|
+
- @ai-sdk/react@0.0.62
|
13
|
+
- @ai-sdk/solid@0.0.49
|
14
|
+
- @ai-sdk/svelte@0.0.51
|
15
|
+
- @ai-sdk/vue@0.0.53
|
16
|
+
|
17
|
+
## 3.4.5
|
18
|
+
|
19
|
+
### Patch Changes
|
20
|
+
|
21
|
+
- cd77c5d: feat (ai/core): add isContinued to steps
|
22
|
+
- Updated dependencies [cd77c5d]
|
23
|
+
- @ai-sdk/ui-utils@0.0.45
|
24
|
+
- @ai-sdk/react@0.0.61
|
25
|
+
- @ai-sdk/solid@0.0.48
|
26
|
+
- @ai-sdk/svelte@0.0.50
|
27
|
+
- @ai-sdk/vue@0.0.52
|
28
|
+
|
3
29
|
## 3.4.4
|
4
30
|
|
5
31
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
@@ -438,6 +438,29 @@ interface ImagePart {
|
|
438
438
|
experimental_providerMetadata?: ProviderMetadata;
|
439
439
|
}
|
440
440
|
/**
|
441
|
+
File content part of a prompt. It contains a file.
|
442
|
+
*/
|
443
|
+
interface FilePart {
|
444
|
+
type: 'file';
|
445
|
+
/**
|
446
|
+
File data. Can either be:
|
447
|
+
|
448
|
+
- data: a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer
|
449
|
+
- URL: a URL that points to the image
|
450
|
+
*/
|
451
|
+
data: DataContent | URL;
|
452
|
+
/**
|
453
|
+
Mime type of the file.
|
454
|
+
*/
|
455
|
+
mimeType: string;
|
456
|
+
/**
|
457
|
+
Additional provider-specific metadata. They are passed through
|
458
|
+
to the provider from the AI SDK and enable provider-specific
|
459
|
+
functionality that can be fully encapsulated in the provider.
|
460
|
+
*/
|
461
|
+
experimental_providerMetadata?: ProviderMetadata;
|
462
|
+
}
|
463
|
+
/**
|
441
464
|
Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
|
442
465
|
*/
|
443
466
|
interface ToolCallPart {
|
@@ -531,7 +554,7 @@ type ExperimentalUserMessage = CoreUserMessage;
|
|
531
554
|
/**
|
532
555
|
Content of a user message. It can be a string or an array of text and image parts.
|
533
556
|
*/
|
534
|
-
type UserContent = string | Array<TextPart$1 | ImagePart>;
|
557
|
+
type UserContent = string | Array<TextPart$1 | ImagePart | FilePart>;
|
535
558
|
/**
|
536
559
|
An assistant message. It can contain text, tool calls, or a combination of text and tool calls.
|
537
560
|
*/
|
@@ -1368,6 +1391,10 @@ type StepResult<TOOLS extends Record<string, CoreTool>> = {
|
|
1368
1391
|
or "tool-result" steps.
|
1369
1392
|
*/
|
1370
1393
|
readonly stepType: 'initial' | 'continue' | 'tool-result';
|
1394
|
+
/**
|
1395
|
+
True when there will be a continuation step with a continuation text.
|
1396
|
+
*/
|
1397
|
+
readonly isContinued: boolean;
|
1371
1398
|
};
|
1372
1399
|
|
1373
1400
|
/**
|
@@ -1788,6 +1815,7 @@ type TextStreamPart<TOOLS extends Record<string, CoreTool>> = {
|
|
1788
1815
|
usage: LanguageModelUsage$1;
|
1789
1816
|
response: LanguageModelResponseMetadata;
|
1790
1817
|
experimental_providerMetadata?: ProviderMetadata;
|
1818
|
+
isContinued: boolean;
|
1791
1819
|
} | {
|
1792
1820
|
type: 'finish';
|
1793
1821
|
finishReason: FinishReason;
|
@@ -1917,7 +1945,7 @@ Callback that is called when the LLM response and all request tool executions
|
|
1917
1945
|
|
1918
1946
|
The usage is the combined usage of all steps.
|
1919
1947
|
*/
|
1920
|
-
onFinish?: (event: Omit<StepResult<TOOLS>, 'stepType'> & {
|
1948
|
+
onFinish?: (event: Omit<StepResult<TOOLS>, 'stepType' | 'isContinued'> & {
|
1921
1949
|
/**
|
1922
1950
|
Details for all steps.
|
1923
1951
|
*/
|
package/dist/index.d.ts
CHANGED
@@ -438,6 +438,29 @@ interface ImagePart {
|
|
438
438
|
experimental_providerMetadata?: ProviderMetadata;
|
439
439
|
}
|
440
440
|
/**
|
441
|
+
File content part of a prompt. It contains a file.
|
442
|
+
*/
|
443
|
+
interface FilePart {
|
444
|
+
type: 'file';
|
445
|
+
/**
|
446
|
+
File data. Can either be:
|
447
|
+
|
448
|
+
- data: a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer
|
449
|
+
- URL: a URL that points to the image
|
450
|
+
*/
|
451
|
+
data: DataContent | URL;
|
452
|
+
/**
|
453
|
+
Mime type of the file.
|
454
|
+
*/
|
455
|
+
mimeType: string;
|
456
|
+
/**
|
457
|
+
Additional provider-specific metadata. They are passed through
|
458
|
+
to the provider from the AI SDK and enable provider-specific
|
459
|
+
functionality that can be fully encapsulated in the provider.
|
460
|
+
*/
|
461
|
+
experimental_providerMetadata?: ProviderMetadata;
|
462
|
+
}
|
463
|
+
/**
|
441
464
|
Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
|
442
465
|
*/
|
443
466
|
interface ToolCallPart {
|
@@ -531,7 +554,7 @@ type ExperimentalUserMessage = CoreUserMessage;
|
|
531
554
|
/**
|
532
555
|
Content of a user message. It can be a string or an array of text and image parts.
|
533
556
|
*/
|
534
|
-
type UserContent = string | Array<TextPart$1 | ImagePart>;
|
557
|
+
type UserContent = string | Array<TextPart$1 | ImagePart | FilePart>;
|
535
558
|
/**
|
536
559
|
An assistant message. It can contain text, tool calls, or a combination of text and tool calls.
|
537
560
|
*/
|
@@ -1368,6 +1391,10 @@ type StepResult<TOOLS extends Record<string, CoreTool>> = {
|
|
1368
1391
|
or "tool-result" steps.
|
1369
1392
|
*/
|
1370
1393
|
readonly stepType: 'initial' | 'continue' | 'tool-result';
|
1394
|
+
/**
|
1395
|
+
True when there will be a continuation step with a continuation text.
|
1396
|
+
*/
|
1397
|
+
readonly isContinued: boolean;
|
1371
1398
|
};
|
1372
1399
|
|
1373
1400
|
/**
|
@@ -1788,6 +1815,7 @@ type TextStreamPart<TOOLS extends Record<string, CoreTool>> = {
|
|
1788
1815
|
usage: LanguageModelUsage$1;
|
1789
1816
|
response: LanguageModelResponseMetadata;
|
1790
1817
|
experimental_providerMetadata?: ProviderMetadata;
|
1818
|
+
isContinued: boolean;
|
1791
1819
|
} | {
|
1792
1820
|
type: 'finish';
|
1793
1821
|
finishReason: FinishReason;
|
@@ -1917,7 +1945,7 @@ Callback that is called when the LLM response and all request tool executions
|
|
1917
1945
|
|
1918
1946
|
The usage is the combined usage of all steps.
|
1919
1947
|
*/
|
1920
|
-
onFinish?: (event: Omit<StepResult<TOOLS>, 'stepType'> & {
|
1948
|
+
onFinish?: (event: Omit<StepResult<TOOLS>, 'stepType' | 'isContinued'> & {
|
1921
1949
|
/**
|
1922
1950
|
Details for all steps.
|
1923
1951
|
*/
|
package/dist/index.js
CHANGED
@@ -825,6 +825,15 @@ var dataContentSchema = import_zod.z.union([
|
|
825
825
|
{ message: "Must be a Buffer" }
|
826
826
|
)
|
827
827
|
]);
|
828
|
+
function convertDataContentToBase64String(content) {
|
829
|
+
if (typeof content === "string") {
|
830
|
+
return content;
|
831
|
+
}
|
832
|
+
if (content instanceof ArrayBuffer) {
|
833
|
+
return (0, import_provider_utils2.convertUint8ArrayToBase64)(new Uint8Array(content));
|
834
|
+
}
|
835
|
+
return (0, import_provider_utils2.convertUint8ArrayToBase64)(content);
|
836
|
+
}
|
828
837
|
function convertDataContentToUint8Array(content) {
|
829
838
|
if (content instanceof Uint8Array) {
|
830
839
|
return content;
|
@@ -946,98 +955,119 @@ function convertToLanguageModelMessage(message, downloadedImages) {
|
|
946
955
|
}
|
947
956
|
return {
|
948
957
|
role: "user",
|
949
|
-
content: message.content.map(
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
case "image": {
|
960
|
-
if (part.image instanceof URL) {
|
961
|
-
if (downloadedImages == null) {
|
962
|
-
return {
|
963
|
-
type: "image",
|
964
|
-
image: part.image,
|
965
|
-
mimeType: part.mimeType,
|
966
|
-
providerMetadata: part.experimental_providerMetadata
|
967
|
-
};
|
968
|
-
} else {
|
969
|
-
const downloadedImage = downloadedImages[part.image.toString()];
|
970
|
-
return {
|
971
|
-
type: "image",
|
972
|
-
image: downloadedImage.data,
|
973
|
-
mimeType: (_a11 = part.mimeType) != null ? _a11 : downloadedImage.mimeType,
|
974
|
-
providerMetadata: part.experimental_providerMetadata
|
975
|
-
};
|
976
|
-
}
|
958
|
+
content: message.content.map(
|
959
|
+
(part) => {
|
960
|
+
var _a11, _b, _c;
|
961
|
+
switch (part.type) {
|
962
|
+
case "text": {
|
963
|
+
return {
|
964
|
+
type: "text",
|
965
|
+
text: part.text,
|
966
|
+
providerMetadata: part.experimental_providerMetadata
|
967
|
+
};
|
977
968
|
}
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
|
994
|
-
|
995
|
-
|
996
|
-
|
997
|
-
|
998
|
-
|
969
|
+
case "image": {
|
970
|
+
if (part.image instanceof URL) {
|
971
|
+
if (downloadedImages == null) {
|
972
|
+
return {
|
973
|
+
type: "image",
|
974
|
+
image: part.image,
|
975
|
+
mimeType: part.mimeType,
|
976
|
+
providerMetadata: part.experimental_providerMetadata
|
977
|
+
};
|
978
|
+
} else {
|
979
|
+
const downloadedImage = downloadedImages[part.image.toString()];
|
980
|
+
return {
|
981
|
+
type: "image",
|
982
|
+
image: downloadedImage.data,
|
983
|
+
mimeType: (_a11 = part.mimeType) != null ? _a11 : downloadedImage.mimeType,
|
984
|
+
providerMetadata: part.experimental_providerMetadata
|
985
|
+
};
|
986
|
+
}
|
987
|
+
}
|
988
|
+
if (typeof part.image === "string") {
|
989
|
+
try {
|
990
|
+
const url = new URL(part.image);
|
991
|
+
switch (url.protocol) {
|
992
|
+
case "http:":
|
993
|
+
case "https:": {
|
994
|
+
if (downloadedImages == null) {
|
995
|
+
return {
|
996
|
+
type: "image",
|
997
|
+
image: url,
|
998
|
+
mimeType: part.mimeType,
|
999
|
+
providerMetadata: part.experimental_providerMetadata
|
1000
|
+
};
|
1001
|
+
} else {
|
1002
|
+
const downloadedImage = downloadedImages[part.image];
|
1003
|
+
return {
|
1004
|
+
type: "image",
|
1005
|
+
image: downloadedImage.data,
|
1006
|
+
mimeType: (_b = part.mimeType) != null ? _b : downloadedImage.mimeType,
|
1007
|
+
providerMetadata: part.experimental_providerMetadata
|
1008
|
+
};
|
1009
|
+
}
|
999
1010
|
}
|
1000
|
-
|
1001
|
-
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
1011
|
+
case "data:": {
|
1012
|
+
try {
|
1013
|
+
const [header, base64Content] = part.image.split(",");
|
1014
|
+
const mimeType = header.split(";")[0].split(":")[1];
|
1015
|
+
if (mimeType == null || base64Content == null) {
|
1016
|
+
throw new Error("Invalid data URL format");
|
1017
|
+
}
|
1018
|
+
return {
|
1019
|
+
type: "image",
|
1020
|
+
image: convertDataContentToUint8Array(base64Content),
|
1021
|
+
mimeType,
|
1022
|
+
providerMetadata: part.experimental_providerMetadata
|
1023
|
+
};
|
1024
|
+
} catch (error) {
|
1025
|
+
throw new Error(
|
1026
|
+
`Error processing data URL: ${(0, import_provider_utils3.getErrorMessage)(
|
1027
|
+
message
|
1028
|
+
)}`
|
1029
|
+
);
|
1007
1030
|
}
|
1008
|
-
|
1009
|
-
|
1010
|
-
image: convertDataContentToUint8Array(base64Content),
|
1011
|
-
mimeType,
|
1012
|
-
providerMetadata: part.experimental_providerMetadata
|
1013
|
-
};
|
1014
|
-
} catch (error) {
|
1031
|
+
}
|
1032
|
+
default: {
|
1015
1033
|
throw new Error(
|
1016
|
-
`
|
1017
|
-
message
|
1018
|
-
)}`
|
1034
|
+
`Unsupported URL protocol: ${url.protocol}`
|
1019
1035
|
);
|
1020
1036
|
}
|
1021
1037
|
}
|
1022
|
-
|
1023
|
-
throw new Error(
|
1024
|
-
`Unsupported URL protocol: ${url.protocol}`
|
1025
|
-
);
|
1026
|
-
}
|
1038
|
+
} catch (_ignored) {
|
1027
1039
|
}
|
1028
|
-
} catch (_ignored) {
|
1029
1040
|
}
|
1041
|
+
const imageUint8 = convertDataContentToUint8Array(part.image);
|
1042
|
+
return {
|
1043
|
+
type: "image",
|
1044
|
+
image: imageUint8,
|
1045
|
+
mimeType: (_c = part.mimeType) != null ? _c : detectImageMimeType(imageUint8),
|
1046
|
+
providerMetadata: part.experimental_providerMetadata
|
1047
|
+
};
|
1048
|
+
}
|
1049
|
+
case "file": {
|
1050
|
+
if (part.data instanceof URL) {
|
1051
|
+
return {
|
1052
|
+
type: "file",
|
1053
|
+
data: part.data,
|
1054
|
+
mimeType: part.mimeType,
|
1055
|
+
providerMetadata: part.experimental_providerMetadata
|
1056
|
+
};
|
1057
|
+
}
|
1058
|
+
const imageBase64 = convertDataContentToBase64String(
|
1059
|
+
part.data
|
1060
|
+
);
|
1061
|
+
return {
|
1062
|
+
type: "file",
|
1063
|
+
data: imageBase64,
|
1064
|
+
mimeType: part.mimeType,
|
1065
|
+
providerMetadata: part.experimental_providerMetadata
|
1066
|
+
};
|
1030
1067
|
}
|
1031
|
-
const imageUint8 = convertDataContentToUint8Array(part.image);
|
1032
|
-
return {
|
1033
|
-
type: "image",
|
1034
|
-
image: imageUint8,
|
1035
|
-
mimeType: (_c = part.mimeType) != null ? _c : detectImageMimeType(imageUint8),
|
1036
|
-
providerMetadata: part.experimental_providerMetadata
|
1037
|
-
};
|
1038
1068
|
}
|
1039
1069
|
}
|
1040
|
-
|
1070
|
+
).filter((part) => part.type !== "text" || part.text !== ""),
|
1041
1071
|
providerMetadata: message.experimental_providerMetadata
|
1042
1072
|
};
|
1043
1073
|
}
|
@@ -1298,6 +1328,12 @@ var imagePartSchema = import_zod4.z.object({
|
|
1298
1328
|
mimeType: import_zod4.z.string().optional(),
|
1299
1329
|
experimental_providerMetadata: providerMetadataSchema.optional()
|
1300
1330
|
});
|
1331
|
+
var filePartSchema = import_zod4.z.object({
|
1332
|
+
type: import_zod4.z.literal("file"),
|
1333
|
+
data: import_zod4.z.union([dataContentSchema, import_zod4.z.instanceof(URL)]),
|
1334
|
+
mimeType: import_zod4.z.string(),
|
1335
|
+
experimental_providerMetadata: providerMetadataSchema.optional()
|
1336
|
+
});
|
1301
1337
|
var toolCallPartSchema = import_zod4.z.object({
|
1302
1338
|
type: import_zod4.z.literal("tool-call"),
|
1303
1339
|
toolCallId: import_zod4.z.string(),
|
@@ -1323,7 +1359,7 @@ var coreUserMessageSchema = import_zod5.z.object({
|
|
1323
1359
|
role: import_zod5.z.literal("user"),
|
1324
1360
|
content: import_zod5.z.union([
|
1325
1361
|
import_zod5.z.string(),
|
1326
|
-
import_zod5.z.array(import_zod5.z.union([textPartSchema, imagePartSchema]))
|
1362
|
+
import_zod5.z.array(import_zod5.z.union([textPartSchema, imagePartSchema, filePartSchema]))
|
1327
1363
|
]),
|
1328
1364
|
experimental_providerMetadata: providerMetadataSchema.optional()
|
1329
1365
|
});
|
@@ -3265,7 +3301,8 @@ async function generateText({
|
|
3265
3301
|
...currentModelResponse.response,
|
3266
3302
|
headers: (_d = currentModelResponse.rawResponse) == null ? void 0 : _d.headers
|
3267
3303
|
},
|
3268
|
-
experimental_providerMetadata: currentModelResponse.providerMetadata
|
3304
|
+
experimental_providerMetadata: currentModelResponse.providerMetadata,
|
3305
|
+
isContinued: nextStepType === "continue"
|
3269
3306
|
};
|
3270
3307
|
steps.push(currentStep);
|
3271
3308
|
await (onStepFinish == null ? void 0 : onStepFinish(currentStep));
|
@@ -4205,7 +4242,8 @@ var DefaultStreamTextResult = class {
|
|
4205
4242
|
usage: stepUsage,
|
4206
4243
|
experimental_providerMetadata: stepProviderMetadata,
|
4207
4244
|
logprobs: stepLogProbs,
|
4208
|
-
response: stepResponse
|
4245
|
+
response: stepResponse,
|
4246
|
+
isContinued: nextStepType === "continue"
|
4209
4247
|
});
|
4210
4248
|
const stepResult = {
|
4211
4249
|
stepType,
|
@@ -4218,7 +4256,8 @@ var DefaultStreamTextResult = class {
|
|
4218
4256
|
logprobs: stepLogProbs,
|
4219
4257
|
response: stepResponse,
|
4220
4258
|
rawResponse: self.rawResponse,
|
4221
|
-
experimental_providerMetadata: stepProviderMetadata
|
4259
|
+
experimental_providerMetadata: stepProviderMetadata,
|
4260
|
+
isContinued: nextStepType === "continue"
|
4222
4261
|
};
|
4223
4262
|
stepResults.push(stepResult);
|
4224
4263
|
await (onStepFinish == null ? void 0 : onStepFinish(stepResult));
|
@@ -4494,7 +4533,8 @@ var DefaultStreamTextResult = class {
|
|
4494
4533
|
usage: sendUsage ? {
|
4495
4534
|
promptTokens: chunk.usage.promptTokens,
|
4496
4535
|
completionTokens: chunk.usage.completionTokens
|
4497
|
-
} : void 0
|
4536
|
+
} : void 0,
|
4537
|
+
isContinued: chunk.isContinued
|
4498
4538
|
})
|
4499
4539
|
);
|
4500
4540
|
break;
|