ai 4.1.62 → 4.1.63
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 +11 -0
- package/dist/index.d.mts +1828 -1807
- package/dist/index.d.ts +1828 -1807
- package/dist/index.js +261 -70
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +254 -63
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
- package/rsc/dist/index.d.ts +3 -2
- package/rsc/dist/rsc-server.d.mts +3 -2
- package/rsc/dist/rsc-server.mjs +129 -20
- package/rsc/dist/rsc-server.mjs.map +1 -1
package/dist/index.js
CHANGED
@@ -885,9 +885,6 @@ var DefaultEmbedManyResult = class {
|
|
885
885
|
}
|
886
886
|
};
|
887
887
|
|
888
|
-
// core/generate-image/generate-image.ts
|
889
|
-
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
890
|
-
|
891
888
|
// errors/no-image-generated-error.ts
|
892
889
|
var import_provider4 = require("@ai-sdk/provider");
|
893
890
|
var name3 = "AI_NoImageGeneratedError";
|
@@ -910,6 +907,123 @@ var NoImageGeneratedError = class extends import_provider4.AISDKError {
|
|
910
907
|
};
|
911
908
|
_a3 = symbol3;
|
912
909
|
|
910
|
+
// core/generate-text/generated-file.ts
|
911
|
+
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
912
|
+
var DefaultGeneratedFile = class {
|
913
|
+
constructor({
|
914
|
+
data,
|
915
|
+
mimeType
|
916
|
+
}) {
|
917
|
+
const isUint8Array = data instanceof Uint8Array;
|
918
|
+
this.base64Data = isUint8Array ? void 0 : data;
|
919
|
+
this.uint8ArrayData = isUint8Array ? data : void 0;
|
920
|
+
this.mimeType = mimeType;
|
921
|
+
}
|
922
|
+
// lazy conversion with caching to avoid unnecessary conversion overhead:
|
923
|
+
get base64() {
|
924
|
+
if (this.base64Data == null) {
|
925
|
+
this.base64Data = (0, import_provider_utils2.convertUint8ArrayToBase64)(this.uint8ArrayData);
|
926
|
+
}
|
927
|
+
return this.base64Data;
|
928
|
+
}
|
929
|
+
// lazy conversion with caching to avoid unnecessary conversion overhead:
|
930
|
+
get uint8Array() {
|
931
|
+
if (this.uint8ArrayData == null) {
|
932
|
+
this.uint8ArrayData = (0, import_provider_utils2.convertBase64ToUint8Array)(this.base64Data);
|
933
|
+
}
|
934
|
+
return this.uint8ArrayData;
|
935
|
+
}
|
936
|
+
};
|
937
|
+
var DefaultGeneratedFileWithType = class extends DefaultGeneratedFile {
|
938
|
+
constructor(options) {
|
939
|
+
super(options);
|
940
|
+
this.type = "file";
|
941
|
+
}
|
942
|
+
};
|
943
|
+
|
944
|
+
// core/util/detect-image-mimetype.ts
|
945
|
+
var mimeTypeSignatures = [
|
946
|
+
{
|
947
|
+
mimeType: "image/gif",
|
948
|
+
bytesPrefix: [71, 73, 70],
|
949
|
+
base64Prefix: "R0lG"
|
950
|
+
},
|
951
|
+
{
|
952
|
+
mimeType: "image/png",
|
953
|
+
bytesPrefix: [137, 80, 78, 71],
|
954
|
+
base64Prefix: "iVBORw"
|
955
|
+
},
|
956
|
+
{
|
957
|
+
mimeType: "image/jpeg",
|
958
|
+
bytesPrefix: [255, 216],
|
959
|
+
base64Prefix: "/9j/"
|
960
|
+
},
|
961
|
+
{
|
962
|
+
mimeType: "image/webp",
|
963
|
+
bytesPrefix: [82, 73, 70, 70],
|
964
|
+
base64Prefix: "UklGRg"
|
965
|
+
},
|
966
|
+
{
|
967
|
+
mimeType: "image/bmp",
|
968
|
+
bytesPrefix: [66, 77],
|
969
|
+
base64Prefix: "Qk"
|
970
|
+
},
|
971
|
+
{
|
972
|
+
mimeType: "image/tiff",
|
973
|
+
bytesPrefix: [73, 73, 42, 0],
|
974
|
+
base64Prefix: "SUkqAA"
|
975
|
+
},
|
976
|
+
{
|
977
|
+
mimeType: "image/tiff",
|
978
|
+
bytesPrefix: [77, 77, 0, 42],
|
979
|
+
base64Prefix: "TU0AKg"
|
980
|
+
},
|
981
|
+
{
|
982
|
+
mimeType: "image/avif",
|
983
|
+
bytesPrefix: [
|
984
|
+
0,
|
985
|
+
0,
|
986
|
+
0,
|
987
|
+
32,
|
988
|
+
102,
|
989
|
+
116,
|
990
|
+
121,
|
991
|
+
112,
|
992
|
+
97,
|
993
|
+
118,
|
994
|
+
105,
|
995
|
+
102
|
996
|
+
],
|
997
|
+
base64Prefix: "AAAAIGZ0eXBhdmlm"
|
998
|
+
},
|
999
|
+
{
|
1000
|
+
mimeType: "image/heic",
|
1001
|
+
bytesPrefix: [
|
1002
|
+
0,
|
1003
|
+
0,
|
1004
|
+
0,
|
1005
|
+
32,
|
1006
|
+
102,
|
1007
|
+
116,
|
1008
|
+
121,
|
1009
|
+
112,
|
1010
|
+
104,
|
1011
|
+
101,
|
1012
|
+
105,
|
1013
|
+
99
|
1014
|
+
],
|
1015
|
+
base64Prefix: "AAAAIGZ0eXBoZWlj"
|
1016
|
+
}
|
1017
|
+
];
|
1018
|
+
function detectImageMimeType(image) {
|
1019
|
+
for (const signature of mimeTypeSignatures) {
|
1020
|
+
if (typeof image === "string" ? image.startsWith(signature.base64Prefix) : image.length >= signature.bytesPrefix.length && signature.bytesPrefix.every((byte, index) => image[index] === byte)) {
|
1021
|
+
return signature.mimeType;
|
1022
|
+
}
|
1023
|
+
}
|
1024
|
+
return void 0;
|
1025
|
+
}
|
1026
|
+
|
913
1027
|
// core/generate-image/generate-image.ts
|
914
1028
|
async function generateImage({
|
915
1029
|
model,
|
@@ -921,10 +1035,7 @@ async function generateImage({
|
|
921
1035
|
providerOptions,
|
922
1036
|
maxRetries: maxRetriesArg,
|
923
1037
|
abortSignal,
|
924
|
-
headers
|
925
|
-
_internal = {
|
926
|
-
currentDate: () => /* @__PURE__ */ new Date()
|
927
|
-
}
|
1038
|
+
headers
|
928
1039
|
}) {
|
929
1040
|
var _a17;
|
930
1041
|
const { retry } = prepareRetries({ maxRetries: maxRetriesArg });
|
@@ -958,7 +1069,15 @@ async function generateImage({
|
|
958
1069
|
const responses = [];
|
959
1070
|
for (const result of results) {
|
960
1071
|
images.push(
|
961
|
-
...result.images.map(
|
1072
|
+
...result.images.map(
|
1073
|
+
(image) => {
|
1074
|
+
var _a18;
|
1075
|
+
return new DefaultGeneratedFile({
|
1076
|
+
data: image,
|
1077
|
+
mimeType: (_a18 = detectImageMimeType(image)) != null ? _a18 : "image/png"
|
1078
|
+
});
|
1079
|
+
}
|
1080
|
+
)
|
962
1081
|
);
|
963
1082
|
warnings.push(...result.warnings);
|
964
1083
|
responses.push(result.response);
|
@@ -978,27 +1097,6 @@ var DefaultGenerateImageResult = class {
|
|
978
1097
|
return this.images[0];
|
979
1098
|
}
|
980
1099
|
};
|
981
|
-
var DefaultGeneratedImage = class {
|
982
|
-
constructor({ image }) {
|
983
|
-
const isUint8Array = image instanceof Uint8Array;
|
984
|
-
this.base64Data = isUint8Array ? void 0 : image;
|
985
|
-
this.uint8ArrayData = isUint8Array ? image : void 0;
|
986
|
-
}
|
987
|
-
// lazy conversion with caching to avoid unnecessary conversion overhead:
|
988
|
-
get base64() {
|
989
|
-
if (this.base64Data == null) {
|
990
|
-
this.base64Data = (0, import_provider_utils2.convertUint8ArrayToBase64)(this.uint8ArrayData);
|
991
|
-
}
|
992
|
-
return this.base64Data;
|
993
|
-
}
|
994
|
-
// lazy conversion with caching to avoid unnecessary conversion overhead:
|
995
|
-
get uint8Array() {
|
996
|
-
if (this.uint8ArrayData == null) {
|
997
|
-
this.uint8ArrayData = (0, import_provider_utils2.convertBase64ToUint8Array)(this.base64Data);
|
998
|
-
}
|
999
|
-
return this.uint8ArrayData;
|
1000
|
-
}
|
1001
|
-
};
|
1002
1100
|
|
1003
1101
|
// core/generate-object/generate-object.ts
|
1004
1102
|
var import_provider12 = require("@ai-sdk/provider");
|
@@ -1084,22 +1182,6 @@ async function download({
|
|
1084
1182
|
}
|
1085
1183
|
}
|
1086
1184
|
|
1087
|
-
// core/util/detect-image-mimetype.ts
|
1088
|
-
var mimeTypeSignatures = [
|
1089
|
-
{ mimeType: "image/gif", bytes: [71, 73, 70] },
|
1090
|
-
{ mimeType: "image/png", bytes: [137, 80, 78, 71] },
|
1091
|
-
{ mimeType: "image/jpeg", bytes: [255, 216] },
|
1092
|
-
{ mimeType: "image/webp", bytes: [82, 73, 70, 70] }
|
1093
|
-
];
|
1094
|
-
function detectImageMimeType(image) {
|
1095
|
-
for (const { bytes, mimeType } of mimeTypeSignatures) {
|
1096
|
-
if (image.length >= bytes.length && bytes.every((byte, index) => image[index] === byte)) {
|
1097
|
-
return mimeType;
|
1098
|
-
}
|
1099
|
-
}
|
1100
|
-
return void 0;
|
1101
|
-
}
|
1102
|
-
|
1103
1185
|
// core/prompt/data-content.ts
|
1104
1186
|
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
1105
1187
|
|
@@ -1273,11 +1355,50 @@ function convertToLanguageModelMessage(message, downloadedAssets) {
|
|
1273
1355
|
// remove empty text parts:
|
1274
1356
|
(part) => part.type !== "text" || part.text !== ""
|
1275
1357
|
).map((part) => {
|
1276
|
-
|
1277
|
-
|
1278
|
-
|
1279
|
-
|
1280
|
-
|
1358
|
+
var _a18;
|
1359
|
+
const providerOptions = (_a18 = part.providerOptions) != null ? _a18 : part.experimental_providerMetadata;
|
1360
|
+
switch (part.type) {
|
1361
|
+
case "file": {
|
1362
|
+
return {
|
1363
|
+
type: "file",
|
1364
|
+
data: part.data instanceof URL ? part.data : convertDataContentToBase64String(part.data),
|
1365
|
+
filename: part.filename,
|
1366
|
+
mimeType: part.mimeType,
|
1367
|
+
providerMetadata: providerOptions
|
1368
|
+
};
|
1369
|
+
}
|
1370
|
+
case "reasoning": {
|
1371
|
+
return {
|
1372
|
+
type: "reasoning",
|
1373
|
+
text: part.text,
|
1374
|
+
signature: part.signature,
|
1375
|
+
providerMetadata: providerOptions
|
1376
|
+
};
|
1377
|
+
}
|
1378
|
+
case "redacted-reasoning": {
|
1379
|
+
return {
|
1380
|
+
type: "redacted-reasoning",
|
1381
|
+
data: part.data,
|
1382
|
+
providerMetadata: providerOptions
|
1383
|
+
};
|
1384
|
+
}
|
1385
|
+
case "text": {
|
1386
|
+
return {
|
1387
|
+
type: "text",
|
1388
|
+
text: part.text,
|
1389
|
+
providerMetadata: providerOptions
|
1390
|
+
};
|
1391
|
+
}
|
1392
|
+
case "tool-call": {
|
1393
|
+
return {
|
1394
|
+
type: "tool-call",
|
1395
|
+
toolCallId: part.toolCallId,
|
1396
|
+
toolName: part.toolName,
|
1397
|
+
args: part.args,
|
1398
|
+
providerMetadata: providerOptions
|
1399
|
+
};
|
1400
|
+
}
|
1401
|
+
}
|
1281
1402
|
}),
|
1282
1403
|
providerMetadata: (_e = message.providerOptions) != null ? _e : message.experimental_providerMetadata
|
1283
1404
|
};
|
@@ -1637,12 +1758,11 @@ function convertToCoreMessages(messages, options) {
|
|
1637
1758
|
const content2 = [];
|
1638
1759
|
for (const part of block) {
|
1639
1760
|
switch (part.type) {
|
1640
|
-
case "
|
1641
|
-
|
1642
|
-
|
1643
|
-
text: part.text
|
1644
|
-
});
|
1761
|
+
case "file":
|
1762
|
+
case "text": {
|
1763
|
+
content2.push(part);
|
1645
1764
|
break;
|
1765
|
+
}
|
1646
1766
|
case "reasoning": {
|
1647
1767
|
for (const detail of part.details) {
|
1648
1768
|
switch (detail.type) {
|
@@ -1723,9 +1843,6 @@ function convertToCoreMessages(messages, options) {
|
|
1723
1843
|
let block = [];
|
1724
1844
|
for (const part of message.parts) {
|
1725
1845
|
switch (part.type) {
|
1726
|
-
case "reasoning":
|
1727
|
-
block.push(part);
|
1728
|
-
break;
|
1729
1846
|
case "text": {
|
1730
1847
|
if (blockHasToolInvocations) {
|
1731
1848
|
processBlock2();
|
@@ -1733,6 +1850,11 @@ function convertToCoreMessages(messages, options) {
|
|
1733
1850
|
block.push(part);
|
1734
1851
|
break;
|
1735
1852
|
}
|
1853
|
+
case "file":
|
1854
|
+
case "reasoning": {
|
1855
|
+
block.push(part);
|
1856
|
+
break;
|
1857
|
+
}
|
1736
1858
|
case "tool-invocation": {
|
1737
1859
|
if (((_b = part.toolInvocation.step) != null ? _b : 0) !== currentStep) {
|
1738
1860
|
processBlock2();
|
@@ -1848,6 +1970,7 @@ function detectSingleMessageCharacteristics(message) {
|
|
1848
1970
|
if (typeof message === "object" && message !== null && (message.role === "function" || // UI-only role
|
1849
1971
|
message.role === "data" || // UI-only role
|
1850
1972
|
"toolInvocations" in message || // UI-specific field
|
1973
|
+
"parts" in message || // UI-specific field
|
1851
1974
|
"experimental_attachments" in message)) {
|
1852
1975
|
return "has-ui-specific-parts";
|
1853
1976
|
} else if (typeof message === "object" && message !== null && "content" in message && (Array.isArray(message.content) || // Core messages can have array content
|
@@ -1977,6 +2100,7 @@ var coreAssistantMessageSchema = import_zod6.z.object({
|
|
1977
2100
|
import_zod6.z.array(
|
1978
2101
|
import_zod6.z.union([
|
1979
2102
|
textPartSchema,
|
2103
|
+
filePartSchema,
|
1980
2104
|
reasoningPartSchema,
|
1981
2105
|
redactedReasoningPartSchema,
|
1982
2106
|
toolCallPartSchema
|
@@ -3878,6 +4002,7 @@ function asReasoningText(reasoning) {
|
|
3878
4002
|
// core/generate-text/to-response-messages.ts
|
3879
4003
|
function toResponseMessages({
|
3880
4004
|
text: text2 = "",
|
4005
|
+
files,
|
3881
4006
|
reasoning,
|
3882
4007
|
tools,
|
3883
4008
|
toolCalls,
|
@@ -3892,6 +4017,12 @@ function toResponseMessages({
|
|
3892
4017
|
...reasoning.map(
|
3893
4018
|
(part) => part.type === "text" ? { ...part, type: "reasoning" } : { ...part, type: "redacted-reasoning" }
|
3894
4019
|
),
|
4020
|
+
// TODO language model v2: switch to order response content (instead of type-based ordering)
|
4021
|
+
...files.map((file) => ({
|
4022
|
+
type: "file",
|
4023
|
+
data: file.base64,
|
4024
|
+
mimeType: file.mimeType
|
4025
|
+
})),
|
3895
4026
|
{ type: "text", text: text2 },
|
3896
4027
|
...toolCalls
|
3897
4028
|
],
|
@@ -4181,6 +4312,7 @@ async function generateText({
|
|
4181
4312
|
responseMessages.push(
|
4182
4313
|
...toResponseMessages({
|
4183
4314
|
text: text2,
|
4315
|
+
files: asFiles(currentModelResponse.files),
|
4184
4316
|
reasoning: asReasoningDetails(currentModelResponse.reasoning),
|
4185
4317
|
tools: tools != null ? tools : {},
|
4186
4318
|
toolCalls: currentToolCalls,
|
@@ -4196,6 +4328,7 @@ async function generateText({
|
|
4196
4328
|
// TODO v5: rename reasoning to reasoningText (and use reasoning for composite array)
|
4197
4329
|
reasoning: asReasoningText(currentReasoningDetails),
|
4198
4330
|
reasoningDetails: currentReasoningDetails,
|
4331
|
+
files: asFiles(currentModelResponse.files),
|
4199
4332
|
sources: (_e = currentModelResponse.sources) != null ? _e : [],
|
4200
4333
|
toolCalls: currentToolCalls,
|
4201
4334
|
toolResults: currentToolResults,
|
@@ -4237,6 +4370,7 @@ async function generateText({
|
|
4237
4370
|
);
|
4238
4371
|
return new DefaultGenerateTextResult({
|
4239
4372
|
text: text2,
|
4373
|
+
files: asFiles(currentModelResponse.files),
|
4240
4374
|
reasoning: asReasoningText(currentReasoningDetails),
|
4241
4375
|
reasoningDetails: currentReasoningDetails,
|
4242
4376
|
sources,
|
@@ -4346,6 +4480,7 @@ async function executeTools({
|
|
4346
4480
|
var DefaultGenerateTextResult = class {
|
4347
4481
|
constructor(options) {
|
4348
4482
|
this.text = options.text;
|
4483
|
+
this.files = options.files;
|
4349
4484
|
this.reasoning = options.reasoning;
|
4350
4485
|
this.reasoningDetails = options.reasoningDetails;
|
4351
4486
|
this.toolCalls = options.toolCalls;
|
@@ -4375,6 +4510,10 @@ function asReasoningDetails(reasoning) {
|
|
4375
4510
|
}
|
4376
4511
|
return reasoning;
|
4377
4512
|
}
|
4513
|
+
function asFiles(files) {
|
4514
|
+
var _a17;
|
4515
|
+
return (_a17 = files == null ? void 0 : files.map((file) => new DefaultGeneratedFile(file))) != null ? _a17 : [];
|
4516
|
+
}
|
4378
4517
|
|
4379
4518
|
// core/generate-text/output.ts
|
4380
4519
|
var output_exports = {};
|
@@ -4698,6 +4837,15 @@ function runToolsTransformation({
|
|
4698
4837
|
controller.enqueue(chunk);
|
4699
4838
|
break;
|
4700
4839
|
}
|
4840
|
+
case "file": {
|
4841
|
+
controller.enqueue(
|
4842
|
+
new DefaultGeneratedFileWithType({
|
4843
|
+
data: chunk.data,
|
4844
|
+
mimeType: chunk.mimeType
|
4845
|
+
})
|
4846
|
+
);
|
4847
|
+
break;
|
4848
|
+
}
|
4701
4849
|
case "tool-call-delta": {
|
4702
4850
|
if (toolCallStreaming) {
|
4703
4851
|
if (!activeToolCalls[chunk.toolCallId]) {
|
@@ -5005,6 +5153,7 @@ var DefaultStreamTextResult = class {
|
|
5005
5153
|
this.reasoningPromise = new DelayedPromise();
|
5006
5154
|
this.reasoningDetailsPromise = new DelayedPromise();
|
5007
5155
|
this.sourcesPromise = new DelayedPromise();
|
5156
|
+
this.filesPromise = new DelayedPromise();
|
5008
5157
|
this.toolCallsPromise = new DelayedPromise();
|
5009
5158
|
this.toolResultsPromise = new DelayedPromise();
|
5010
5159
|
this.requestPromise = new DelayedPromise();
|
@@ -5023,6 +5172,7 @@ var DefaultStreamTextResult = class {
|
|
5023
5172
|
let recordedContinuationText = "";
|
5024
5173
|
let recordedFullText = "";
|
5025
5174
|
let stepReasoning = [];
|
5175
|
+
let stepFiles = [];
|
5026
5176
|
let activeReasoningText = void 0;
|
5027
5177
|
let recordedStepSources = [];
|
5028
5178
|
const recordedSources = [];
|
@@ -5075,6 +5225,9 @@ var DefaultStreamTextResult = class {
|
|
5075
5225
|
if (part.type === "redacted-reasoning") {
|
5076
5226
|
stepReasoning.push({ type: "redacted", data: part.data });
|
5077
5227
|
}
|
5228
|
+
if (part.type === "file") {
|
5229
|
+
stepFiles.push(part);
|
5230
|
+
}
|
5078
5231
|
if (part.type === "source") {
|
5079
5232
|
recordedSources.push(part.source);
|
5080
5233
|
recordedStepSources.push(part.source);
|
@@ -5088,6 +5241,7 @@ var DefaultStreamTextResult = class {
|
|
5088
5241
|
if (part.type === "step-finish") {
|
5089
5242
|
const stepMessages = toResponseMessages({
|
5090
5243
|
text: recordedContinuationText,
|
5244
|
+
files: stepFiles,
|
5091
5245
|
reasoning: stepReasoning,
|
5092
5246
|
tools: tools != null ? tools : {},
|
5093
5247
|
toolCalls: recordedToolCalls,
|
@@ -5114,6 +5268,7 @@ var DefaultStreamTextResult = class {
|
|
5114
5268
|
text: recordedStepText,
|
5115
5269
|
reasoning: asReasoningText(stepReasoning),
|
5116
5270
|
reasoningDetails: stepReasoning,
|
5271
|
+
files: stepFiles,
|
5117
5272
|
sources: recordedStepSources,
|
5118
5273
|
toolCalls: recordedToolCalls,
|
5119
5274
|
toolResults: recordedToolResults,
|
@@ -5137,6 +5292,7 @@ var DefaultStreamTextResult = class {
|
|
5137
5292
|
recordedStepText = "";
|
5138
5293
|
recordedStepSources = [];
|
5139
5294
|
stepReasoning = [];
|
5295
|
+
stepFiles = [];
|
5140
5296
|
activeReasoningText = void 0;
|
5141
5297
|
if (nextStepType !== "done") {
|
5142
5298
|
stepType = nextStepType;
|
@@ -5182,6 +5338,7 @@ var DefaultStreamTextResult = class {
|
|
5182
5338
|
self.usagePromise.resolve(usage);
|
5183
5339
|
self.textPromise.resolve(recordedFullText);
|
5184
5340
|
self.sourcesPromise.resolve(recordedSources);
|
5341
|
+
self.filesPromise.resolve(lastStep.files);
|
5185
5342
|
self.stepsPromise.resolve(recordedSteps);
|
5186
5343
|
await (onFinish == null ? void 0 : onFinish({
|
5187
5344
|
finishReason,
|
@@ -5190,6 +5347,7 @@ var DefaultStreamTextResult = class {
|
|
5190
5347
|
text: recordedFullText,
|
5191
5348
|
reasoning: lastStep.reasoning,
|
5192
5349
|
reasoningDetails: lastStep.reasoningDetails,
|
5350
|
+
files: lastStep.files,
|
5193
5351
|
sources: lastStep.sources,
|
5194
5352
|
toolCalls: lastStep.toolCalls,
|
5195
5353
|
toolResults: lastStep.toolResults,
|
@@ -5382,6 +5540,7 @@ var DefaultStreamTextResult = class {
|
|
5382
5540
|
const stepToolCalls = [];
|
5383
5541
|
const stepToolResults = [];
|
5384
5542
|
const stepReasoning2 = [];
|
5543
|
+
const stepFiles2 = [];
|
5385
5544
|
let activeReasoningText2 = void 0;
|
5386
5545
|
let stepFinishReason = "unknown";
|
5387
5546
|
let stepUsage = {
|
@@ -5527,6 +5686,11 @@ var DefaultStreamTextResult = class {
|
|
5527
5686
|
});
|
5528
5687
|
break;
|
5529
5688
|
}
|
5689
|
+
case "file": {
|
5690
|
+
stepFiles2.push(chunk);
|
5691
|
+
controller.enqueue(chunk);
|
5692
|
+
break;
|
5693
|
+
}
|
5530
5694
|
case "source":
|
5531
5695
|
case "tool-call-streaming-start":
|
5532
5696
|
case "tool-call-delta": {
|
@@ -5645,6 +5809,7 @@ var DefaultStreamTextResult = class {
|
|
5645
5809
|
responseMessages.push(
|
5646
5810
|
...toResponseMessages({
|
5647
5811
|
text: stepText,
|
5812
|
+
files: stepFiles2,
|
5648
5813
|
reasoning: stepReasoning2,
|
5649
5814
|
tools: tools != null ? tools : {},
|
5650
5815
|
toolCalls: stepToolCalls,
|
@@ -5725,6 +5890,9 @@ var DefaultStreamTextResult = class {
|
|
5725
5890
|
get sources() {
|
5726
5891
|
return this.sourcesPromise.value;
|
5727
5892
|
}
|
5893
|
+
get files() {
|
5894
|
+
return this.filesPromise.value;
|
5895
|
+
}
|
5728
5896
|
get toolCalls() {
|
5729
5897
|
return this.toolCallsPromise.value;
|
5730
5898
|
}
|
@@ -5843,6 +6011,15 @@ var DefaultStreamTextResult = class {
|
|
5843
6011
|
}
|
5844
6012
|
break;
|
5845
6013
|
}
|
6014
|
+
case "file": {
|
6015
|
+
controller.enqueue(
|
6016
|
+
(0, import_ui_utils8.formatDataStreamPart)("file", {
|
6017
|
+
mimeType: chunk.mimeType,
|
6018
|
+
data: chunk.base64
|
6019
|
+
})
|
6020
|
+
);
|
6021
|
+
break;
|
6022
|
+
}
|
5846
6023
|
case "source": {
|
5847
6024
|
if (sendSources) {
|
5848
6025
|
controller.enqueue(
|
@@ -6356,6 +6533,7 @@ function appendClientMessage({
|
|
6356
6533
|
|
6357
6534
|
// core/prompt/append-response-messages.ts
|
6358
6535
|
var import_ui_utils9 = require("@ai-sdk/ui-utils");
|
6536
|
+
var import_provider23 = require("@ai-sdk/provider");
|
6359
6537
|
function appendResponseMessages({
|
6360
6538
|
messages,
|
6361
6539
|
responseMessages,
|
@@ -6436,6 +6614,19 @@ function appendResponseMessages({
|
|
6436
6614
|
}
|
6437
6615
|
case "tool-call":
|
6438
6616
|
break;
|
6617
|
+
case "file":
|
6618
|
+
if (part.data instanceof URL) {
|
6619
|
+
throw new import_provider23.AISDKError({
|
6620
|
+
name: "InvalidAssistantFileData",
|
6621
|
+
message: "File data cannot be a URL"
|
6622
|
+
});
|
6623
|
+
}
|
6624
|
+
parts.push({
|
6625
|
+
type: "file",
|
6626
|
+
mimeType: part.mimeType,
|
6627
|
+
data: convertDataContentToBase64String(part.data)
|
6628
|
+
});
|
6629
|
+
break;
|
6439
6630
|
}
|
6440
6631
|
}
|
6441
6632
|
}
|
@@ -6519,7 +6710,7 @@ function appendResponseMessages({
|
|
6519
6710
|
}
|
6520
6711
|
|
6521
6712
|
// core/registry/custom-provider.ts
|
6522
|
-
var
|
6713
|
+
var import_provider24 = require("@ai-sdk/provider");
|
6523
6714
|
function customProvider({
|
6524
6715
|
languageModels,
|
6525
6716
|
textEmbeddingModels,
|
@@ -6534,7 +6725,7 @@ function customProvider({
|
|
6534
6725
|
if (fallbackProvider) {
|
6535
6726
|
return fallbackProvider.languageModel(modelId);
|
6536
6727
|
}
|
6537
|
-
throw new
|
6728
|
+
throw new import_provider24.NoSuchModelError({ modelId, modelType: "languageModel" });
|
6538
6729
|
},
|
6539
6730
|
textEmbeddingModel(modelId) {
|
6540
6731
|
if (textEmbeddingModels != null && modelId in textEmbeddingModels) {
|
@@ -6543,7 +6734,7 @@ function customProvider({
|
|
6543
6734
|
if (fallbackProvider) {
|
6544
6735
|
return fallbackProvider.textEmbeddingModel(modelId);
|
6545
6736
|
}
|
6546
|
-
throw new
|
6737
|
+
throw new import_provider24.NoSuchModelError({ modelId, modelType: "textEmbeddingModel" });
|
6547
6738
|
},
|
6548
6739
|
imageModel(modelId) {
|
6549
6740
|
if (imageModels != null && modelId in imageModels) {
|
@@ -6552,19 +6743,19 @@ function customProvider({
|
|
6552
6743
|
if (fallbackProvider == null ? void 0 : fallbackProvider.imageModel) {
|
6553
6744
|
return fallbackProvider.imageModel(modelId);
|
6554
6745
|
}
|
6555
|
-
throw new
|
6746
|
+
throw new import_provider24.NoSuchModelError({ modelId, modelType: "imageModel" });
|
6556
6747
|
}
|
6557
6748
|
};
|
6558
6749
|
}
|
6559
6750
|
var experimental_customProvider = customProvider;
|
6560
6751
|
|
6561
6752
|
// core/registry/no-such-provider-error.ts
|
6562
|
-
var
|
6753
|
+
var import_provider25 = require("@ai-sdk/provider");
|
6563
6754
|
var name16 = "AI_NoSuchProviderError";
|
6564
6755
|
var marker16 = `vercel.ai.error.${name16}`;
|
6565
6756
|
var symbol16 = Symbol.for(marker16);
|
6566
6757
|
var _a16;
|
6567
|
-
var NoSuchProviderError = class extends
|
6758
|
+
var NoSuchProviderError = class extends import_provider25.NoSuchModelError {
|
6568
6759
|
constructor({
|
6569
6760
|
modelId,
|
6570
6761
|
modelType,
|
@@ -6578,13 +6769,13 @@ var NoSuchProviderError = class extends import_provider24.NoSuchModelError {
|
|
6578
6769
|
this.availableProviders = availableProviders;
|
6579
6770
|
}
|
6580
6771
|
static isInstance(error) {
|
6581
|
-
return
|
6772
|
+
return import_provider25.AISDKError.hasMarker(error, marker16);
|
6582
6773
|
}
|
6583
6774
|
};
|
6584
6775
|
_a16 = symbol16;
|
6585
6776
|
|
6586
6777
|
// core/registry/provider-registry.ts
|
6587
|
-
var
|
6778
|
+
var import_provider26 = require("@ai-sdk/provider");
|
6588
6779
|
function experimental_createProviderRegistry(providers) {
|
6589
6780
|
const registry = new DefaultProviderRegistry();
|
6590
6781
|
for (const [id, provider] of Object.entries(providers)) {
|
@@ -6617,7 +6808,7 @@ var DefaultProviderRegistry = class {
|
|
6617
6808
|
splitId(id, modelType) {
|
6618
6809
|
const index = id.indexOf(":");
|
6619
6810
|
if (index === -1) {
|
6620
|
-
throw new
|
6811
|
+
throw new import_provider26.NoSuchModelError({
|
6621
6812
|
modelId: id,
|
6622
6813
|
modelType,
|
6623
6814
|
message: `Invalid ${modelType} id for registry: ${id} (must be in the format "providerId:modelId")`
|
@@ -6630,7 +6821,7 @@ var DefaultProviderRegistry = class {
|
|
6630
6821
|
const [providerId, modelId] = this.splitId(id, "languageModel");
|
6631
6822
|
const model = (_b = (_a17 = this.getProvider(providerId)).languageModel) == null ? void 0 : _b.call(_a17, modelId);
|
6632
6823
|
if (model == null) {
|
6633
|
-
throw new
|
6824
|
+
throw new import_provider26.NoSuchModelError({ modelId: id, modelType: "languageModel" });
|
6634
6825
|
}
|
6635
6826
|
return model;
|
6636
6827
|
}
|
@@ -6640,7 +6831,7 @@ var DefaultProviderRegistry = class {
|
|
6640
6831
|
const provider = this.getProvider(providerId);
|
6641
6832
|
const model = (_a17 = provider.textEmbeddingModel) == null ? void 0 : _a17.call(provider, modelId);
|
6642
6833
|
if (model == null) {
|
6643
|
-
throw new
|
6834
|
+
throw new import_provider26.NoSuchModelError({
|
6644
6835
|
modelId: id,
|
6645
6836
|
modelType: "textEmbeddingModel"
|
6646
6837
|
});
|
@@ -6653,7 +6844,7 @@ var DefaultProviderRegistry = class {
|
|
6653
6844
|
const provider = this.getProvider(providerId);
|
6654
6845
|
const model = (_a17 = provider.imageModel) == null ? void 0 : _a17.call(provider, modelId);
|
6655
6846
|
if (model == null) {
|
6656
|
-
throw new
|
6847
|
+
throw new import_provider26.NoSuchModelError({ modelId: id, modelType: "imageModel" });
|
6657
6848
|
}
|
6658
6849
|
return model;
|
6659
6850
|
}
|