ai 4.0.26 → 4.0.28
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 +24 -0
- package/dist/index.d.mts +51 -9
- package/dist/index.d.ts +51 -9
- package/dist/index.js +110 -50
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +106 -44
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
- package/rsc/dist/rsc-server.mjs +1 -1
- package/rsc/dist/rsc-server.mjs.map +1 -1
- package/test/dist/index.d.mts +11 -6
- package/test/dist/index.d.ts +11 -6
- package/test/dist/index.js +6 -3
- package/test/dist/index.js.map +1 -1
- package/test/dist/index.mjs +6 -3
- package/test/dist/index.mjs.map +1 -1
package/dist/index.mjs
CHANGED
@@ -225,7 +225,7 @@ import { getErrorMessage, isAbortError } from "@ai-sdk/provider-utils";
|
|
225
225
|
|
226
226
|
// util/delay.ts
|
227
227
|
async function delay(delayInMs) {
|
228
|
-
return delayInMs
|
228
|
+
return delayInMs == null ? Promise.resolve() : new Promise((resolve) => setTimeout(resolve, delayInMs));
|
229
229
|
}
|
230
230
|
|
231
231
|
// util/retry-error.ts
|
@@ -803,43 +803,70 @@ var DefaultEmbedManyResult = class {
|
|
803
803
|
};
|
804
804
|
|
805
805
|
// core/generate-image/generate-image.ts
|
806
|
-
import {
|
806
|
+
import {
|
807
|
+
convertBase64ToUint8Array,
|
808
|
+
convertUint8ArrayToBase64
|
809
|
+
} from "@ai-sdk/provider-utils";
|
807
810
|
async function generateImage({
|
808
811
|
model,
|
809
812
|
prompt,
|
810
813
|
n,
|
811
814
|
size,
|
815
|
+
aspectRatio,
|
816
|
+
seed,
|
812
817
|
providerOptions,
|
813
818
|
maxRetries: maxRetriesArg,
|
814
819
|
abortSignal,
|
815
820
|
headers
|
816
821
|
}) {
|
817
822
|
const { retry } = prepareRetries({ maxRetries: maxRetriesArg });
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
823
|
+
return new DefaultGenerateImageResult(
|
824
|
+
await retry(
|
825
|
+
() => model.doGenerate({
|
826
|
+
prompt,
|
827
|
+
n: n != null ? n : 1,
|
828
|
+
abortSignal,
|
829
|
+
headers,
|
830
|
+
size,
|
831
|
+
aspectRatio,
|
832
|
+
seed,
|
833
|
+
providerOptions: providerOptions != null ? providerOptions : {}
|
834
|
+
})
|
835
|
+
)
|
827
836
|
);
|
828
|
-
return new DefaultGenerateImageResult({ base64Images: images });
|
829
837
|
}
|
830
838
|
var DefaultGenerateImageResult = class {
|
831
839
|
constructor(options) {
|
832
|
-
this.images = options.
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
}
|
837
|
-
}));
|
840
|
+
this.images = options.images.map(
|
841
|
+
(image) => new DefaultGeneratedImage({ imageData: image })
|
842
|
+
);
|
843
|
+
this.warnings = options.warnings;
|
838
844
|
}
|
839
845
|
get image() {
|
840
846
|
return this.images[0];
|
841
847
|
}
|
842
848
|
};
|
849
|
+
var DefaultGeneratedImage = class {
|
850
|
+
constructor({ imageData }) {
|
851
|
+
const isUint8Array = imageData instanceof Uint8Array;
|
852
|
+
this.base64Data = isUint8Array ? void 0 : imageData;
|
853
|
+
this.uint8ArrayData = isUint8Array ? imageData : void 0;
|
854
|
+
}
|
855
|
+
// lazy conversion with caching to avoid unnecessary conversion overhead:
|
856
|
+
get base64() {
|
857
|
+
if (this.base64Data == null) {
|
858
|
+
this.base64Data = convertUint8ArrayToBase64(this.uint8ArrayData);
|
859
|
+
}
|
860
|
+
return this.base64Data;
|
861
|
+
}
|
862
|
+
// lazy conversion with caching to avoid unnecessary conversion overhead:
|
863
|
+
get uint8Array() {
|
864
|
+
if (this.uint8ArrayData == null) {
|
865
|
+
this.uint8ArrayData = convertBase64ToUint8Array(this.base64Data);
|
866
|
+
}
|
867
|
+
return this.uint8ArrayData;
|
868
|
+
}
|
869
|
+
};
|
843
870
|
|
844
871
|
// core/generate-object/generate-object.ts
|
845
872
|
import { createIdGenerator, safeParseJSON } from "@ai-sdk/provider-utils";
|
@@ -943,7 +970,7 @@ function detectImageMimeType(image) {
|
|
943
970
|
// core/prompt/data-content.ts
|
944
971
|
import {
|
945
972
|
convertBase64ToUint8Array as convertBase64ToUint8Array2,
|
946
|
-
convertUint8ArrayToBase64
|
973
|
+
convertUint8ArrayToBase64 as convertUint8ArrayToBase642
|
947
974
|
} from "@ai-sdk/provider-utils";
|
948
975
|
|
949
976
|
// core/prompt/invalid-data-content-error.ts
|
@@ -988,9 +1015,9 @@ function convertDataContentToBase64String(content) {
|
|
988
1015
|
return content;
|
989
1016
|
}
|
990
1017
|
if (content instanceof ArrayBuffer) {
|
991
|
-
return
|
1018
|
+
return convertUint8ArrayToBase642(new Uint8Array(content));
|
992
1019
|
}
|
993
|
-
return
|
1020
|
+
return convertUint8ArrayToBase642(content);
|
994
1021
|
}
|
995
1022
|
function convertDataContentToUint8Array(content) {
|
996
1023
|
if (content instanceof Uint8Array) {
|
@@ -5309,38 +5336,50 @@ var DefaultStreamTextResult = class {
|
|
5309
5336
|
};
|
5310
5337
|
|
5311
5338
|
// core/generate-text/smooth-stream.ts
|
5339
|
+
import { InvalidArgumentError as InvalidArgumentError2 } from "@ai-sdk/provider";
|
5340
|
+
var CHUNKING_REGEXPS = {
|
5341
|
+
word: /\s*\S+\s+/m,
|
5342
|
+
line: /[^\n]*\n/m
|
5343
|
+
};
|
5312
5344
|
function smoothStream({
|
5313
5345
|
delayInMs = 10,
|
5314
5346
|
chunking = "word",
|
5315
5347
|
_internal: { delay: delay2 = delay } = {}
|
5316
5348
|
} = {}) {
|
5317
|
-
|
5318
|
-
|
5319
|
-
|
5320
|
-
|
5321
|
-
|
5322
|
-
|
5323
|
-
|
5349
|
+
const chunkingRegexp = typeof chunking === "string" ? CHUNKING_REGEXPS[chunking] : chunking;
|
5350
|
+
if (chunkingRegexp == null) {
|
5351
|
+
throw new InvalidArgumentError2({
|
5352
|
+
argument: "chunking",
|
5353
|
+
message: `Chunking must be "word" or "line" or a RegExp. Received: ${chunking}`
|
5354
|
+
});
|
5355
|
+
}
|
5356
|
+
return () => {
|
5357
|
+
let buffer = "";
|
5358
|
+
return new TransformStream({
|
5359
|
+
async transform(chunk, controller) {
|
5360
|
+
if (chunk.type === "step-finish") {
|
5361
|
+
if (buffer.length > 0) {
|
5362
|
+
controller.enqueue({ type: "text-delta", textDelta: buffer });
|
5363
|
+
buffer = "";
|
5364
|
+
}
|
5365
|
+
controller.enqueue(chunk);
|
5366
|
+
return;
|
5324
5367
|
}
|
5325
|
-
|
5326
|
-
|
5327
|
-
|
5328
|
-
|
5329
|
-
|
5330
|
-
|
5331
|
-
|
5332
|
-
|
5333
|
-
|
5334
|
-
|
5335
|
-
const chunk2 = buffer.match(regexp)[0];
|
5336
|
-
controller.enqueue({ type: "text-delta", textDelta: chunk2 });
|
5337
|
-
buffer = buffer.slice(chunk2.length);
|
5338
|
-
if (delayInMs > 0) {
|
5368
|
+
if (chunk.type !== "text-delta") {
|
5369
|
+
controller.enqueue(chunk);
|
5370
|
+
return;
|
5371
|
+
}
|
5372
|
+
buffer += chunk.textDelta;
|
5373
|
+
let match;
|
5374
|
+
while ((match = chunkingRegexp.exec(buffer)) != null) {
|
5375
|
+
const chunk2 = match[0];
|
5376
|
+
controller.enqueue({ type: "text-delta", textDelta: chunk2 });
|
5377
|
+
buffer = buffer.slice(chunk2.length);
|
5339
5378
|
await delay2(delayInMs);
|
5340
5379
|
}
|
5341
5380
|
}
|
5342
|
-
}
|
5343
|
-
}
|
5381
|
+
});
|
5382
|
+
};
|
5344
5383
|
}
|
5345
5384
|
|
5346
5385
|
// core/middleware/wrap-language-model.ts
|
@@ -5524,6 +5563,28 @@ function magnitude(vector) {
|
|
5524
5563
|
return Math.sqrt(dotProduct(vector, vector));
|
5525
5564
|
}
|
5526
5565
|
|
5566
|
+
// core/util/simulate-readable-stream.ts
|
5567
|
+
function simulateReadableStream({
|
5568
|
+
chunks,
|
5569
|
+
initialDelayInMs = 0,
|
5570
|
+
chunkDelayInMs = 0,
|
5571
|
+
_internal
|
5572
|
+
}) {
|
5573
|
+
var _a14;
|
5574
|
+
const delay2 = (_a14 = _internal == null ? void 0 : _internal.delay) != null ? _a14 : delay;
|
5575
|
+
let index = 0;
|
5576
|
+
return new ReadableStream({
|
5577
|
+
async pull(controller) {
|
5578
|
+
if (index < chunks.length) {
|
5579
|
+
await delay2(index === 0 ? initialDelayInMs : chunkDelayInMs);
|
5580
|
+
controller.enqueue(chunks[index++]);
|
5581
|
+
} else {
|
5582
|
+
controller.close();
|
5583
|
+
}
|
5584
|
+
}
|
5585
|
+
});
|
5586
|
+
}
|
5587
|
+
|
5527
5588
|
// streams/assistant-response.ts
|
5528
5589
|
import {
|
5529
5590
|
formatAssistantStreamPart
|
@@ -5909,6 +5970,7 @@ export {
|
|
5909
5970
|
pipeDataStreamToResponse,
|
5910
5971
|
processDataStream,
|
5911
5972
|
processTextStream,
|
5973
|
+
simulateReadableStream,
|
5912
5974
|
smoothStream,
|
5913
5975
|
streamObject,
|
5914
5976
|
streamText,
|