ai 4.0.13 → 4.0.15
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 +18 -0
- package/dist/index.d.mts +106 -3
- package/dist/index.d.ts +106 -3
- package/dist/index.js +117 -34
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +90 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
- package/test/dist/index.js +7 -8
- package/test/dist/index.js.map +1 -1
- package/test/dist/index.mjs +7 -8
- package/test/dist/index.mjs.map +1 -1
package/dist/index.mjs
CHANGED
@@ -795,6 +795,45 @@ var DefaultEmbedManyResult = class {
|
|
795
795
|
}
|
796
796
|
};
|
797
797
|
|
798
|
+
// core/generate-image/generate-image.ts
|
799
|
+
import { convertBase64ToUint8Array } from "@ai-sdk/provider-utils";
|
800
|
+
async function generateImage({
|
801
|
+
model,
|
802
|
+
prompt,
|
803
|
+
n,
|
804
|
+
size,
|
805
|
+
providerOptions,
|
806
|
+
maxRetries: maxRetriesArg,
|
807
|
+
abortSignal,
|
808
|
+
headers
|
809
|
+
}) {
|
810
|
+
const { retry } = prepareRetries({ maxRetries: maxRetriesArg });
|
811
|
+
const { images } = await retry(
|
812
|
+
() => model.doGenerate({
|
813
|
+
prompt,
|
814
|
+
n: n != null ? n : 1,
|
815
|
+
abortSignal,
|
816
|
+
headers,
|
817
|
+
size,
|
818
|
+
providerOptions: providerOptions != null ? providerOptions : {}
|
819
|
+
})
|
820
|
+
);
|
821
|
+
return new DefaultGenerateImageResult({ base64Images: images });
|
822
|
+
}
|
823
|
+
var DefaultGenerateImageResult = class {
|
824
|
+
constructor(options) {
|
825
|
+
this.images = options.base64Images.map((base64) => ({
|
826
|
+
base64,
|
827
|
+
get uint8Array() {
|
828
|
+
return convertBase64ToUint8Array(this.base64);
|
829
|
+
}
|
830
|
+
}));
|
831
|
+
}
|
832
|
+
get image() {
|
833
|
+
return this.images[0];
|
834
|
+
}
|
835
|
+
};
|
836
|
+
|
798
837
|
// core/generate-object/generate-object.ts
|
799
838
|
import { createIdGenerator, safeParseJSON } from "@ai-sdk/provider-utils";
|
800
839
|
|
@@ -870,7 +909,7 @@ function detectImageMimeType(image) {
|
|
870
909
|
|
871
910
|
// core/prompt/data-content.ts
|
872
911
|
import {
|
873
|
-
convertBase64ToUint8Array,
|
912
|
+
convertBase64ToUint8Array as convertBase64ToUint8Array2,
|
874
913
|
convertUint8ArrayToBase64
|
875
914
|
} from "@ai-sdk/provider-utils";
|
876
915
|
|
@@ -926,7 +965,7 @@ function convertDataContentToUint8Array(content) {
|
|
926
965
|
}
|
927
966
|
if (typeof content === "string") {
|
928
967
|
try {
|
929
|
-
return
|
968
|
+
return convertBase64ToUint8Array2(content);
|
930
969
|
} catch (error) {
|
931
970
|
throw new InvalidDataContentError({
|
932
971
|
message: "Invalid data content. Content string is not a base64-encoded media.",
|
@@ -4165,6 +4204,7 @@ function streamText({
|
|
4165
4204
|
experimental_toolCallStreaming: toolCallStreaming = false,
|
4166
4205
|
experimental_activeTools: activeTools,
|
4167
4206
|
experimental_repairToolCall: repairToolCall,
|
4207
|
+
experimental_transform: transform,
|
4168
4208
|
onChunk,
|
4169
4209
|
onFinish,
|
4170
4210
|
onStepFinish,
|
@@ -4188,6 +4228,7 @@ function streamText({
|
|
4188
4228
|
tools,
|
4189
4229
|
toolChoice,
|
4190
4230
|
toolCallStreaming,
|
4231
|
+
transform,
|
4191
4232
|
activeTools,
|
4192
4233
|
repairToolCall,
|
4193
4234
|
maxSteps,
|
@@ -4215,6 +4256,7 @@ var DefaultStreamTextResult = class {
|
|
4215
4256
|
tools,
|
4216
4257
|
toolChoice,
|
4217
4258
|
toolCallStreaming,
|
4259
|
+
transform,
|
4218
4260
|
activeTools,
|
4219
4261
|
repairToolCall,
|
4220
4262
|
maxSteps,
|
@@ -4237,7 +4279,6 @@ var DefaultStreamTextResult = class {
|
|
4237
4279
|
this.requestPromise = new DelayedPromise();
|
4238
4280
|
this.responsePromise = new DelayedPromise();
|
4239
4281
|
this.stepsPromise = new DelayedPromise();
|
4240
|
-
this.stitchableStream = createStitchableStream();
|
4241
4282
|
if (maxSteps < 1) {
|
4242
4283
|
throw new InvalidArgumentError({
|
4243
4284
|
parameter: "maxSteps",
|
@@ -4245,6 +4286,10 @@ var DefaultStreamTextResult = class {
|
|
4245
4286
|
message: "maxSteps must be at least 1"
|
4246
4287
|
});
|
4247
4288
|
}
|
4289
|
+
const stitchableStream = createStitchableStream();
|
4290
|
+
this.addStream = stitchableStream.addStream;
|
4291
|
+
this.closeStream = stitchableStream.close;
|
4292
|
+
this.baseStream = transform ? stitchableStream.stream.pipeThrough(transform) : stitchableStream.stream;
|
4248
4293
|
const { maxRetries, retry } = prepareRetries({
|
4249
4294
|
maxRetries: maxRetriesArg
|
4250
4295
|
});
|
@@ -4410,7 +4455,7 @@ var DefaultStreamTextResult = class {
|
|
4410
4455
|
hasWhitespaceSuffix = chunk.textDelta.trimEnd() !== chunk.textDelta;
|
4411
4456
|
await (onChunk == null ? void 0 : onChunk({ chunk }));
|
4412
4457
|
}
|
4413
|
-
self.
|
4458
|
+
self.addStream(
|
4414
4459
|
transformedStream.pipeThrough(
|
4415
4460
|
new TransformStream({
|
4416
4461
|
async transform(chunk, controller) {
|
@@ -4638,7 +4683,7 @@ var DefaultStreamTextResult = class {
|
|
4638
4683
|
...stepResponse
|
4639
4684
|
}
|
4640
4685
|
});
|
4641
|
-
self.
|
4686
|
+
self.closeStream();
|
4642
4687
|
rootSpan.setAttributes(
|
4643
4688
|
selectTelemetryAttributes({
|
4644
4689
|
telemetry,
|
@@ -4712,7 +4757,7 @@ var DefaultStreamTextResult = class {
|
|
4712
4757
|
});
|
4713
4758
|
}
|
4714
4759
|
}).catch((error) => {
|
4715
|
-
self.
|
4760
|
+
self.addStream(
|
4716
4761
|
new ReadableStream({
|
4717
4762
|
start(controller) {
|
4718
4763
|
controller.enqueue({ type: "error", error });
|
@@ -4720,7 +4765,7 @@ var DefaultStreamTextResult = class {
|
|
4720
4765
|
}
|
4721
4766
|
})
|
4722
4767
|
);
|
4723
|
-
self.
|
4768
|
+
self.closeStream();
|
4724
4769
|
});
|
4725
4770
|
}
|
4726
4771
|
get warnings() {
|
@@ -4762,8 +4807,8 @@ var DefaultStreamTextResult = class {
|
|
4762
4807
|
However, the LLM results are expected to be small enough to not cause issues.
|
4763
4808
|
*/
|
4764
4809
|
teeStream() {
|
4765
|
-
const [stream1, stream2] = this.
|
4766
|
-
this.
|
4810
|
+
const [stream1, stream2] = this.baseStream.tee();
|
4811
|
+
this.baseStream = stream2;
|
4767
4812
|
return stream1;
|
4768
4813
|
}
|
4769
4814
|
get textStream() {
|
@@ -4959,6 +5004,40 @@ var DefaultStreamTextResult = class {
|
|
4959
5004
|
}
|
4960
5005
|
};
|
4961
5006
|
|
5007
|
+
// core/generate-text/smooth-stream.ts
|
5008
|
+
function smoothStream({
|
5009
|
+
delayInMs = 40,
|
5010
|
+
_internal: { delay: delay2 = delay } = {}
|
5011
|
+
} = {}) {
|
5012
|
+
let buffer = "";
|
5013
|
+
return new TransformStream({
|
5014
|
+
async transform(chunk, controller) {
|
5015
|
+
if (chunk.type === "step-finish") {
|
5016
|
+
if (buffer.length > 0) {
|
5017
|
+
controller.enqueue({ type: "text-delta", textDelta: buffer });
|
5018
|
+
buffer = "";
|
5019
|
+
}
|
5020
|
+
controller.enqueue(chunk);
|
5021
|
+
return;
|
5022
|
+
}
|
5023
|
+
if (chunk.type !== "text-delta") {
|
5024
|
+
controller.enqueue(chunk);
|
5025
|
+
return;
|
5026
|
+
}
|
5027
|
+
buffer += chunk.textDelta;
|
5028
|
+
while (buffer.match(/\s/)) {
|
5029
|
+
const whitespaceIndex = buffer.search(/\s/);
|
5030
|
+
const word = buffer.slice(0, whitespaceIndex + 1);
|
5031
|
+
controller.enqueue({ type: "text-delta", textDelta: word });
|
5032
|
+
buffer = buffer.slice(whitespaceIndex + 1);
|
5033
|
+
if (delayInMs > 0) {
|
5034
|
+
await delay2(delayInMs);
|
5035
|
+
}
|
5036
|
+
}
|
5037
|
+
}
|
5038
|
+
});
|
5039
|
+
}
|
5040
|
+
|
4962
5041
|
// core/middleware/wrap-language-model.ts
|
4963
5042
|
var experimental_wrapLanguageModel = ({
|
4964
5043
|
model,
|
@@ -5511,6 +5590,7 @@ export {
|
|
5511
5590
|
embedMany,
|
5512
5591
|
experimental_createProviderRegistry,
|
5513
5592
|
experimental_customProvider,
|
5593
|
+
generateImage as experimental_generateImage,
|
5514
5594
|
experimental_wrapLanguageModel,
|
5515
5595
|
formatAssistantStreamPart2 as formatAssistantStreamPart,
|
5516
5596
|
formatDataStreamPart6 as formatDataStreamPart,
|
@@ -5523,6 +5603,7 @@ export {
|
|
5523
5603
|
pipeDataStreamToResponse,
|
5524
5604
|
processDataStream,
|
5525
5605
|
processTextStream,
|
5606
|
+
smoothStream,
|
5526
5607
|
streamObject,
|
5527
5608
|
streamText,
|
5528
5609
|
tool
|