ai 4.0.20 → 4.0.22
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 +17 -0
- package/dist/index.js +99 -87
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +99 -87
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
- package/rsc/dist/rsc-server.mjs +7 -4
- package/rsc/dist/rsc-server.mjs.map +1 -1
package/dist/index.mjs
CHANGED
@@ -1169,6 +1169,7 @@ async function downloadAssets(messages, downloadImplementation, modelSupportsIma
|
|
1169
1169
|
);
|
1170
1170
|
}
|
1171
1171
|
function convertPartToLanguageModelPart(part, downloadedAssets) {
|
1172
|
+
var _a13;
|
1172
1173
|
if (part.type === "text") {
|
1173
1174
|
return {
|
1174
1175
|
type: "text",
|
@@ -1219,9 +1220,9 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
|
|
1219
1220
|
normalizedData = convertDataContentToUint8Array(content);
|
1220
1221
|
}
|
1221
1222
|
switch (type) {
|
1222
|
-
case "image":
|
1223
|
-
if (
|
1224
|
-
mimeType = detectImageMimeType(normalizedData);
|
1223
|
+
case "image": {
|
1224
|
+
if (normalizedData instanceof Uint8Array) {
|
1225
|
+
mimeType = (_a13 = detectImageMimeType(normalizedData)) != null ? _a13 : mimeType;
|
1225
1226
|
}
|
1226
1227
|
return {
|
1227
1228
|
type: "image",
|
@@ -1229,7 +1230,8 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
|
|
1229
1230
|
mimeType,
|
1230
1231
|
providerMetadata: part.experimental_providerMetadata
|
1231
1232
|
};
|
1232
|
-
|
1233
|
+
}
|
1234
|
+
case "file": {
|
1233
1235
|
if (mimeType == null) {
|
1234
1236
|
throw new Error(`Mime type is missing for file part`);
|
1235
1237
|
}
|
@@ -1239,6 +1241,7 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
|
|
1239
1241
|
mimeType,
|
1240
1242
|
providerMetadata: part.experimental_providerMetadata
|
1241
1243
|
};
|
1244
|
+
}
|
1242
1245
|
}
|
1243
1246
|
}
|
1244
1247
|
|
@@ -1790,12 +1793,10 @@ import { safeValidateTypes as safeValidateTypes2 } from "@ai-sdk/provider-utils"
|
|
1790
1793
|
import { asSchema } from "@ai-sdk/ui-utils";
|
1791
1794
|
|
1792
1795
|
// core/util/async-iterable-stream.ts
|
1793
|
-
function createAsyncIterableStream(source
|
1794
|
-
const
|
1795
|
-
|
1796
|
-
|
1797
|
-
transformedStream[Symbol.asyncIterator] = () => {
|
1798
|
-
const reader = transformedStream.getReader();
|
1796
|
+
function createAsyncIterableStream(source) {
|
1797
|
+
const stream = source.pipeThrough(new TransformStream());
|
1798
|
+
stream[Symbol.asyncIterator] = () => {
|
1799
|
+
const reader = stream.getReader();
|
1799
1800
|
return {
|
1800
1801
|
async next() {
|
1801
1802
|
const { done, value } = await reader.read();
|
@@ -1803,7 +1804,7 @@ function createAsyncIterableStream(source, transformer) {
|
|
1803
1804
|
}
|
1804
1805
|
};
|
1805
1806
|
};
|
1806
|
-
return
|
1807
|
+
return stream;
|
1807
1808
|
}
|
1808
1809
|
|
1809
1810
|
// core/generate-object/output-strategy.ts
|
@@ -1933,29 +1934,35 @@ var arrayOutputStrategy = (schema) => {
|
|
1933
1934
|
},
|
1934
1935
|
createElementStream(originalStream) {
|
1935
1936
|
let publishedElements = 0;
|
1936
|
-
return createAsyncIterableStream(
|
1937
|
-
|
1938
|
-
|
1939
|
-
|
1940
|
-
|
1941
|
-
|
1942
|
-
|
1937
|
+
return createAsyncIterableStream(
|
1938
|
+
originalStream.pipeThrough(
|
1939
|
+
new TransformStream({
|
1940
|
+
transform(chunk, controller) {
|
1941
|
+
switch (chunk.type) {
|
1942
|
+
case "object": {
|
1943
|
+
const array = chunk.object;
|
1944
|
+
for (; publishedElements < array.length; publishedElements++) {
|
1945
|
+
controller.enqueue(array[publishedElements]);
|
1946
|
+
}
|
1947
|
+
break;
|
1948
|
+
}
|
1949
|
+
case "text-delta":
|
1950
|
+
case "finish":
|
1951
|
+
break;
|
1952
|
+
case "error":
|
1953
|
+
controller.error(chunk.error);
|
1954
|
+
break;
|
1955
|
+
default: {
|
1956
|
+
const _exhaustiveCheck = chunk;
|
1957
|
+
throw new Error(
|
1958
|
+
`Unsupported chunk type: ${_exhaustiveCheck}`
|
1959
|
+
);
|
1960
|
+
}
|
1943
1961
|
}
|
1944
|
-
break;
|
1945
1962
|
}
|
1946
|
-
|
1947
|
-
|
1948
|
-
|
1949
|
-
case "error":
|
1950
|
-
controller.error(chunk.error);
|
1951
|
-
break;
|
1952
|
-
default: {
|
1953
|
-
const _exhaustiveCheck = chunk;
|
1954
|
-
throw new Error(`Unsupported chunk type: ${_exhaustiveCheck}`);
|
1955
|
-
}
|
1956
|
-
}
|
1957
|
-
}
|
1958
|
-
});
|
1963
|
+
})
|
1964
|
+
)
|
1965
|
+
);
|
1959
1966
|
}
|
1960
1967
|
};
|
1961
1968
|
};
|
@@ -3154,25 +3161,29 @@ var DefaultStreamObjectResult = class {
|
|
3154
3161
|
return this.responsePromise.value;
|
3155
3162
|
}
|
3156
3163
|
get partialObjectStream() {
|
3157
|
-
return createAsyncIterableStream(
|
3158
|
-
|
3159
|
-
|
3160
|
-
|
3161
|
-
|
3162
|
-
|
3163
|
-
|
3164
|
-
|
3165
|
-
|
3166
|
-
|
3167
|
-
|
3168
|
-
|
3169
|
-
|
3170
|
-
|
3171
|
-
|
3164
|
+
return createAsyncIterableStream(
|
3165
|
+
this.stitchableStream.stream.pipeThrough(
|
3166
|
+
new TransformStream({
|
3167
|
+
transform(chunk, controller) {
|
3168
|
+
switch (chunk.type) {
|
3169
|
+
case "object":
|
3170
|
+
controller.enqueue(chunk.object);
|
3171
|
+
break;
|
3172
|
+
case "text-delta":
|
3173
|
+
case "finish":
|
3174
|
+
break;
|
3175
|
+
case "error":
|
3176
|
+
controller.error(chunk.error);
|
3177
|
+
break;
|
3178
|
+
default: {
|
3179
|
+
const _exhaustiveCheck = chunk;
|
3180
|
+
throw new Error(`Unsupported chunk type: ${_exhaustiveCheck}`);
|
3181
|
+
}
|
3182
|
+
}
|
3172
3183
|
}
|
3173
|
-
}
|
3174
|
-
|
3175
|
-
|
3184
|
+
})
|
3185
|
+
)
|
3186
|
+
);
|
3176
3187
|
}
|
3177
3188
|
get elementStream() {
|
3178
3189
|
return this.outputStrategy.createElementStream(
|
@@ -3180,32 +3191,32 @@ var DefaultStreamObjectResult = class {
|
|
3180
3191
|
);
|
3181
3192
|
}
|
3182
3193
|
get textStream() {
|
3183
|
-
return createAsyncIterableStream(
|
3184
|
-
|
3185
|
-
|
3186
|
-
|
3187
|
-
|
3188
|
-
|
3189
|
-
|
3190
|
-
|
3191
|
-
|
3192
|
-
|
3193
|
-
|
3194
|
-
|
3195
|
-
|
3196
|
-
|
3197
|
-
|
3194
|
+
return createAsyncIterableStream(
|
3195
|
+
this.stitchableStream.stream.pipeThrough(
|
3196
|
+
new TransformStream({
|
3197
|
+
transform(chunk, controller) {
|
3198
|
+
switch (chunk.type) {
|
3199
|
+
case "text-delta":
|
3200
|
+
controller.enqueue(chunk.textDelta);
|
3201
|
+
break;
|
3202
|
+
case "object":
|
3203
|
+
case "finish":
|
3204
|
+
break;
|
3205
|
+
case "error":
|
3206
|
+
controller.error(chunk.error);
|
3207
|
+
break;
|
3208
|
+
default: {
|
3209
|
+
const _exhaustiveCheck = chunk;
|
3210
|
+
throw new Error(`Unsupported chunk type: ${_exhaustiveCheck}`);
|
3211
|
+
}
|
3212
|
+
}
|
3198
3213
|
}
|
3199
|
-
}
|
3200
|
-
|
3201
|
-
|
3214
|
+
})
|
3215
|
+
)
|
3216
|
+
);
|
3202
3217
|
}
|
3203
3218
|
get fullStream() {
|
3204
|
-
return createAsyncIterableStream(this.stitchableStream.stream
|
3205
|
-
transform(chunk, controller) {
|
3206
|
-
controller.enqueue(chunk);
|
3207
|
-
}
|
3208
|
-
});
|
3219
|
+
return createAsyncIterableStream(this.stitchableStream.stream);
|
3209
3220
|
}
|
3210
3221
|
pipeTextStreamToResponse(response, init) {
|
3211
3222
|
writeToServerResponse({
|
@@ -3890,6 +3901,7 @@ async function executeTools({
|
|
3890
3901
|
}
|
3891
3902
|
});
|
3892
3903
|
return {
|
3904
|
+
type: "tool-result",
|
3893
3905
|
toolCallId,
|
3894
3906
|
toolName,
|
3895
3907
|
args,
|
@@ -4967,22 +4979,22 @@ var DefaultStreamTextResult = class {
|
|
4967
4979
|
return stream1;
|
4968
4980
|
}
|
4969
4981
|
get textStream() {
|
4970
|
-
return createAsyncIterableStream(
|
4971
|
-
|
4972
|
-
|
4973
|
-
|
4974
|
-
|
4975
|
-
|
4976
|
-
|
4977
|
-
|
4978
|
-
|
4982
|
+
return createAsyncIterableStream(
|
4983
|
+
this.teeStream().pipeThrough(
|
4984
|
+
new TransformStream({
|
4985
|
+
transform(chunk, controller) {
|
4986
|
+
if (chunk.type === "text-delta") {
|
4987
|
+
controller.enqueue(chunk.textDelta);
|
4988
|
+
} else if (chunk.type === "error") {
|
4989
|
+
controller.error(chunk.error);
|
4990
|
+
}
|
4991
|
+
}
|
4992
|
+
})
|
4993
|
+
)
|
4994
|
+
);
|
4979
4995
|
}
|
4980
4996
|
get fullStream() {
|
4981
|
-
return createAsyncIterableStream(this.teeStream()
|
4982
|
-
transform(chunk, controller) {
|
4983
|
-
controller.enqueue(chunk);
|
4984
|
-
}
|
4985
|
-
});
|
4997
|
+
return createAsyncIterableStream(this.teeStream());
|
4986
4998
|
}
|
4987
4999
|
toDataStreamInternal({
|
4988
5000
|
getErrorMessage: getErrorMessage5 = () => "An error occurred.",
|