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.js
CHANGED
@@ -56,10 +56,11 @@ __export(streams_exports, {
|
|
56
56
|
embedMany: () => embedMany,
|
57
57
|
experimental_createProviderRegistry: () => experimental_createProviderRegistry,
|
58
58
|
experimental_customProvider: () => experimental_customProvider,
|
59
|
+
experimental_generateImage: () => generateImage,
|
59
60
|
experimental_wrapLanguageModel: () => experimental_wrapLanguageModel,
|
60
61
|
formatAssistantStreamPart: () => import_ui_utils14.formatAssistantStreamPart,
|
61
62
|
formatDataStreamPart: () => import_ui_utils14.formatDataStreamPart,
|
62
|
-
generateId: () =>
|
63
|
+
generateId: () => import_provider_utils13.generateId,
|
63
64
|
generateObject: () => generateObject,
|
64
65
|
generateText: () => generateText,
|
65
66
|
jsonSchema: () => import_ui_utils9.jsonSchema,
|
@@ -68,13 +69,14 @@ __export(streams_exports, {
|
|
68
69
|
pipeDataStreamToResponse: () => pipeDataStreamToResponse,
|
69
70
|
processDataStream: () => import_ui_utils14.processDataStream,
|
70
71
|
processTextStream: () => import_ui_utils14.processTextStream,
|
72
|
+
smoothStream: () => smoothStream,
|
71
73
|
streamObject: () => streamObject,
|
72
74
|
streamText: () => streamText,
|
73
75
|
tool: () => tool
|
74
76
|
});
|
75
77
|
module.exports = __toCommonJS(streams_exports);
|
76
78
|
var import_ui_utils14 = require("@ai-sdk/ui-utils");
|
77
|
-
var
|
79
|
+
var import_provider_utils13 = require("@ai-sdk/provider-utils");
|
78
80
|
|
79
81
|
// core/index.ts
|
80
82
|
var import_ui_utils9 = require("@ai-sdk/ui-utils");
|
@@ -856,8 +858,47 @@ var DefaultEmbedManyResult = class {
|
|
856
858
|
}
|
857
859
|
};
|
858
860
|
|
861
|
+
// core/generate-image/generate-image.ts
|
862
|
+
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
863
|
+
async function generateImage({
|
864
|
+
model,
|
865
|
+
prompt,
|
866
|
+
n,
|
867
|
+
size,
|
868
|
+
providerOptions,
|
869
|
+
maxRetries: maxRetriesArg,
|
870
|
+
abortSignal,
|
871
|
+
headers
|
872
|
+
}) {
|
873
|
+
const { retry } = prepareRetries({ maxRetries: maxRetriesArg });
|
874
|
+
const { images } = await retry(
|
875
|
+
() => model.doGenerate({
|
876
|
+
prompt,
|
877
|
+
n: n != null ? n : 1,
|
878
|
+
abortSignal,
|
879
|
+
headers,
|
880
|
+
size,
|
881
|
+
providerOptions: providerOptions != null ? providerOptions : {}
|
882
|
+
})
|
883
|
+
);
|
884
|
+
return new DefaultGenerateImageResult({ base64Images: images });
|
885
|
+
}
|
886
|
+
var DefaultGenerateImageResult = class {
|
887
|
+
constructor(options) {
|
888
|
+
this.images = options.base64Images.map((base64) => ({
|
889
|
+
base64,
|
890
|
+
get uint8Array() {
|
891
|
+
return (0, import_provider_utils2.convertBase64ToUint8Array)(this.base64);
|
892
|
+
}
|
893
|
+
}));
|
894
|
+
}
|
895
|
+
get image() {
|
896
|
+
return this.images[0];
|
897
|
+
}
|
898
|
+
};
|
899
|
+
|
859
900
|
// core/generate-object/generate-object.ts
|
860
|
-
var
|
901
|
+
var import_provider_utils6 = require("@ai-sdk/provider-utils");
|
861
902
|
|
862
903
|
// util/download-error.ts
|
863
904
|
var import_provider4 = require("@ai-sdk/provider");
|
@@ -930,7 +971,7 @@ function detectImageMimeType(image) {
|
|
930
971
|
}
|
931
972
|
|
932
973
|
// core/prompt/data-content.ts
|
933
|
-
var
|
974
|
+
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
934
975
|
|
935
976
|
// core/prompt/invalid-data-content-error.ts
|
936
977
|
var import_provider5 = require("@ai-sdk/provider");
|
@@ -974,9 +1015,9 @@ function convertDataContentToBase64String(content) {
|
|
974
1015
|
return content;
|
975
1016
|
}
|
976
1017
|
if (content instanceof ArrayBuffer) {
|
977
|
-
return (0,
|
1018
|
+
return (0, import_provider_utils3.convertUint8ArrayToBase64)(new Uint8Array(content));
|
978
1019
|
}
|
979
|
-
return (0,
|
1020
|
+
return (0, import_provider_utils3.convertUint8ArrayToBase64)(content);
|
980
1021
|
}
|
981
1022
|
function convertDataContentToUint8Array(content) {
|
982
1023
|
if (content instanceof Uint8Array) {
|
@@ -984,7 +1025,7 @@ function convertDataContentToUint8Array(content) {
|
|
984
1025
|
}
|
985
1026
|
if (typeof content === "string") {
|
986
1027
|
try {
|
987
|
-
return (0,
|
1028
|
+
return (0, import_provider_utils3.convertBase64ToUint8Array)(content);
|
988
1029
|
} catch (error) {
|
989
1030
|
throw new InvalidDataContentError({
|
990
1031
|
message: "Invalid data content. Content string is not a base64-encoded media.",
|
@@ -1323,7 +1364,7 @@ function prepareCallSettings({
|
|
1323
1364
|
|
1324
1365
|
// core/prompt/standardize-prompt.ts
|
1325
1366
|
var import_provider8 = require("@ai-sdk/provider");
|
1326
|
-
var
|
1367
|
+
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
1327
1368
|
var import_zod7 = require("zod");
|
1328
1369
|
|
1329
1370
|
// core/prompt/message.ts
|
@@ -1706,7 +1747,7 @@ function standardizePrompt({
|
|
1706
1747
|
const messages = promptType === "ui-messages" ? convertToCoreMessages(prompt.messages, {
|
1707
1748
|
tools
|
1708
1749
|
}) : prompt.messages;
|
1709
|
-
const validationResult = (0,
|
1750
|
+
const validationResult = (0, import_provider_utils4.safeValidateTypes)({
|
1710
1751
|
value: messages,
|
1711
1752
|
schema: import_zod7.z.array(coreMessageSchema)
|
1712
1753
|
});
|
@@ -1778,7 +1819,7 @@ _a7 = symbol7;
|
|
1778
1819
|
|
1779
1820
|
// core/generate-object/output-strategy.ts
|
1780
1821
|
var import_provider10 = require("@ai-sdk/provider");
|
1781
|
-
var
|
1822
|
+
var import_provider_utils5 = require("@ai-sdk/provider-utils");
|
1782
1823
|
var import_ui_utils2 = require("@ai-sdk/ui-utils");
|
1783
1824
|
|
1784
1825
|
// core/util/async-iterable-stream.ts
|
@@ -1828,7 +1869,7 @@ var objectOutputStrategy = (schema) => ({
|
|
1828
1869
|
};
|
1829
1870
|
},
|
1830
1871
|
validateFinalResult(value) {
|
1831
|
-
return (0,
|
1872
|
+
return (0, import_provider_utils5.safeValidateTypes)({ value, schema });
|
1832
1873
|
},
|
1833
1874
|
createElementStream() {
|
1834
1875
|
throw new import_provider10.UnsupportedFunctionalityError({
|
@@ -1867,7 +1908,7 @@ var arrayOutputStrategy = (schema) => {
|
|
1867
1908
|
const resultArray = [];
|
1868
1909
|
for (let i = 0; i < inputArray.length; i++) {
|
1869
1910
|
const element = inputArray[i];
|
1870
|
-
const result = (0,
|
1911
|
+
const result = (0, import_provider_utils5.safeValidateTypes)({ value: element, schema });
|
1871
1912
|
if (i === inputArray.length - 1 && !isFinalDelta) {
|
1872
1913
|
continue;
|
1873
1914
|
}
|
@@ -1908,7 +1949,7 @@ var arrayOutputStrategy = (schema) => {
|
|
1908
1949
|
}
|
1909
1950
|
const inputArray = value.elements;
|
1910
1951
|
for (const element of inputArray) {
|
1911
|
-
const result = (0,
|
1952
|
+
const result = (0, import_provider_utils5.safeValidateTypes)({ value: element, schema });
|
1912
1953
|
if (!result.success) {
|
1913
1954
|
return result;
|
1914
1955
|
}
|
@@ -2137,7 +2178,7 @@ function validateObjectGenerationInput({
|
|
2137
2178
|
}
|
2138
2179
|
|
2139
2180
|
// core/generate-object/generate-object.ts
|
2140
|
-
var originalGenerateId = (0,
|
2181
|
+
var originalGenerateId = (0, import_provider_utils6.createIdGenerator)({ prefix: "aiobj", size: 24 });
|
2141
2182
|
async function generateObject({
|
2142
2183
|
model,
|
2143
2184
|
enum: enumValues,
|
@@ -2442,7 +2483,7 @@ async function generateObject({
|
|
2442
2483
|
throw new Error(`Unsupported mode: ${_exhaustiveCheck}`);
|
2443
2484
|
}
|
2444
2485
|
}
|
2445
|
-
const parseResult = (0,
|
2486
|
+
const parseResult = (0, import_provider_utils6.safeParseJSON)({ text: result });
|
2446
2487
|
if (!parseResult.success) {
|
2447
2488
|
throw parseResult.error;
|
2448
2489
|
}
|
@@ -2504,7 +2545,7 @@ var DefaultGenerateObjectResult = class {
|
|
2504
2545
|
};
|
2505
2546
|
|
2506
2547
|
// core/generate-object/stream-object.ts
|
2507
|
-
var
|
2548
|
+
var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
2508
2549
|
var import_ui_utils3 = require("@ai-sdk/ui-utils");
|
2509
2550
|
|
2510
2551
|
// util/delayed-promise.ts
|
@@ -2634,7 +2675,7 @@ function now() {
|
|
2634
2675
|
}
|
2635
2676
|
|
2636
2677
|
// core/generate-object/stream-object.ts
|
2637
|
-
var originalGenerateId2 = (0,
|
2678
|
+
var originalGenerateId2 = (0, import_provider_utils7.createIdGenerator)({ prefix: "aiobj", size: 24 });
|
2638
2679
|
function streamObject({
|
2639
2680
|
model,
|
2640
2681
|
schema: inputSchema,
|
@@ -3173,7 +3214,7 @@ var DefaultStreamObjectResult = class {
|
|
3173
3214
|
};
|
3174
3215
|
|
3175
3216
|
// core/generate-text/generate-text.ts
|
3176
|
-
var
|
3217
|
+
var import_provider_utils9 = require("@ai-sdk/provider-utils");
|
3177
3218
|
|
3178
3219
|
// errors/index.ts
|
3179
3220
|
var import_provider15 = require("@ai-sdk/provider");
|
@@ -3339,7 +3380,7 @@ function removeTextAfterLastWhitespace(text2) {
|
|
3339
3380
|
}
|
3340
3381
|
|
3341
3382
|
// core/generate-text/parse-tool-call.ts
|
3342
|
-
var
|
3383
|
+
var import_provider_utils8 = require("@ai-sdk/provider-utils");
|
3343
3384
|
var import_ui_utils5 = require("@ai-sdk/ui-utils");
|
3344
3385
|
async function parseToolCall({
|
3345
3386
|
toolCall,
|
@@ -3392,7 +3433,7 @@ async function doParseToolCall({
|
|
3392
3433
|
});
|
3393
3434
|
}
|
3394
3435
|
const schema = (0, import_ui_utils5.asSchema)(tool2.parameters);
|
3395
|
-
const parseResult = toolCall.args.trim() === "" ? (0,
|
3436
|
+
const parseResult = toolCall.args.trim() === "" ? (0, import_provider_utils8.safeValidateTypes)({ value: {}, schema }) : (0, import_provider_utils8.safeParseJSON)({ text: toolCall.args, schema });
|
3396
3437
|
if (parseResult.success === false) {
|
3397
3438
|
throw new InvalidToolArgumentsError({
|
3398
3439
|
toolName,
|
@@ -3446,7 +3487,7 @@ function toResponseMessages({
|
|
3446
3487
|
}
|
3447
3488
|
|
3448
3489
|
// core/generate-text/generate-text.ts
|
3449
|
-
var originalGenerateId3 = (0,
|
3490
|
+
var originalGenerateId3 = (0, import_provider_utils9.createIdGenerator)({ prefix: "aitxt", size: 24 });
|
3450
3491
|
async function generateText({
|
3451
3492
|
model,
|
3452
3493
|
tools,
|
@@ -3851,7 +3892,7 @@ __export(output_exports, {
|
|
3851
3892
|
object: () => object,
|
3852
3893
|
text: () => text
|
3853
3894
|
});
|
3854
|
-
var
|
3895
|
+
var import_provider_utils10 = require("@ai-sdk/provider-utils");
|
3855
3896
|
var import_ui_utils6 = require("@ai-sdk/ui-utils");
|
3856
3897
|
var text = () => ({
|
3857
3898
|
type: "text",
|
@@ -3880,13 +3921,13 @@ var object = ({
|
|
3880
3921
|
});
|
3881
3922
|
},
|
3882
3923
|
parseOutput({ text: text2 }) {
|
3883
|
-
return (0,
|
3924
|
+
return (0, import_provider_utils10.parseJSON)({ text: text2, schema });
|
3884
3925
|
}
|
3885
3926
|
};
|
3886
3927
|
};
|
3887
3928
|
|
3888
3929
|
// core/generate-text/stream-text.ts
|
3889
|
-
var
|
3930
|
+
var import_provider_utils11 = require("@ai-sdk/provider-utils");
|
3890
3931
|
var import_ui_utils8 = require("@ai-sdk/ui-utils");
|
3891
3932
|
|
3892
3933
|
// core/util/merge-streams.ts
|
@@ -4185,7 +4226,7 @@ function runToolsTransformation({
|
|
4185
4226
|
}
|
4186
4227
|
|
4187
4228
|
// core/generate-text/stream-text.ts
|
4188
|
-
var originalGenerateId4 = (0,
|
4229
|
+
var originalGenerateId4 = (0, import_provider_utils11.createIdGenerator)({ prefix: "aitxt", size: 24 });
|
4189
4230
|
function streamText({
|
4190
4231
|
model,
|
4191
4232
|
tools,
|
@@ -4203,6 +4244,7 @@ function streamText({
|
|
4203
4244
|
experimental_toolCallStreaming: toolCallStreaming = false,
|
4204
4245
|
experimental_activeTools: activeTools,
|
4205
4246
|
experimental_repairToolCall: repairToolCall,
|
4247
|
+
experimental_transform: transform,
|
4206
4248
|
onChunk,
|
4207
4249
|
onFinish,
|
4208
4250
|
onStepFinish,
|
@@ -4226,6 +4268,7 @@ function streamText({
|
|
4226
4268
|
tools,
|
4227
4269
|
toolChoice,
|
4228
4270
|
toolCallStreaming,
|
4271
|
+
transform,
|
4229
4272
|
activeTools,
|
4230
4273
|
repairToolCall,
|
4231
4274
|
maxSteps,
|
@@ -4253,6 +4296,7 @@ var DefaultStreamTextResult = class {
|
|
4253
4296
|
tools,
|
4254
4297
|
toolChoice,
|
4255
4298
|
toolCallStreaming,
|
4299
|
+
transform,
|
4256
4300
|
activeTools,
|
4257
4301
|
repairToolCall,
|
4258
4302
|
maxSteps,
|
@@ -4275,7 +4319,6 @@ var DefaultStreamTextResult = class {
|
|
4275
4319
|
this.requestPromise = new DelayedPromise();
|
4276
4320
|
this.responsePromise = new DelayedPromise();
|
4277
4321
|
this.stepsPromise = new DelayedPromise();
|
4278
|
-
this.stitchableStream = createStitchableStream();
|
4279
4322
|
if (maxSteps < 1) {
|
4280
4323
|
throw new InvalidArgumentError({
|
4281
4324
|
parameter: "maxSteps",
|
@@ -4283,6 +4326,10 @@ var DefaultStreamTextResult = class {
|
|
4283
4326
|
message: "maxSteps must be at least 1"
|
4284
4327
|
});
|
4285
4328
|
}
|
4329
|
+
const stitchableStream = createStitchableStream();
|
4330
|
+
this.addStream = stitchableStream.addStream;
|
4331
|
+
this.closeStream = stitchableStream.close;
|
4332
|
+
this.baseStream = transform ? stitchableStream.stream.pipeThrough(transform) : stitchableStream.stream;
|
4286
4333
|
const { maxRetries, retry } = prepareRetries({
|
4287
4334
|
maxRetries: maxRetriesArg
|
4288
4335
|
});
|
@@ -4448,7 +4495,7 @@ var DefaultStreamTextResult = class {
|
|
4448
4495
|
hasWhitespaceSuffix = chunk.textDelta.trimEnd() !== chunk.textDelta;
|
4449
4496
|
await (onChunk == null ? void 0 : onChunk({ chunk }));
|
4450
4497
|
}
|
4451
|
-
self.
|
4498
|
+
self.addStream(
|
4452
4499
|
transformedStream.pipeThrough(
|
4453
4500
|
new TransformStream({
|
4454
4501
|
async transform(chunk, controller) {
|
@@ -4676,7 +4723,7 @@ var DefaultStreamTextResult = class {
|
|
4676
4723
|
...stepResponse
|
4677
4724
|
}
|
4678
4725
|
});
|
4679
|
-
self.
|
4726
|
+
self.closeStream();
|
4680
4727
|
rootSpan.setAttributes(
|
4681
4728
|
selectTelemetryAttributes({
|
4682
4729
|
telemetry,
|
@@ -4750,7 +4797,7 @@ var DefaultStreamTextResult = class {
|
|
4750
4797
|
});
|
4751
4798
|
}
|
4752
4799
|
}).catch((error) => {
|
4753
|
-
self.
|
4800
|
+
self.addStream(
|
4754
4801
|
new ReadableStream({
|
4755
4802
|
start(controller) {
|
4756
4803
|
controller.enqueue({ type: "error", error });
|
@@ -4758,7 +4805,7 @@ var DefaultStreamTextResult = class {
|
|
4758
4805
|
}
|
4759
4806
|
})
|
4760
4807
|
);
|
4761
|
-
self.
|
4808
|
+
self.closeStream();
|
4762
4809
|
});
|
4763
4810
|
}
|
4764
4811
|
get warnings() {
|
@@ -4800,8 +4847,8 @@ var DefaultStreamTextResult = class {
|
|
4800
4847
|
However, the LLM results are expected to be small enough to not cause issues.
|
4801
4848
|
*/
|
4802
4849
|
teeStream() {
|
4803
|
-
const [stream1, stream2] = this.
|
4804
|
-
this.
|
4850
|
+
const [stream1, stream2] = this.baseStream.tee();
|
4851
|
+
this.baseStream = stream2;
|
4805
4852
|
return stream1;
|
4806
4853
|
}
|
4807
4854
|
get textStream() {
|
@@ -4997,6 +5044,40 @@ var DefaultStreamTextResult = class {
|
|
4997
5044
|
}
|
4998
5045
|
};
|
4999
5046
|
|
5047
|
+
// core/generate-text/smooth-stream.ts
|
5048
|
+
function smoothStream({
|
5049
|
+
delayInMs = 40,
|
5050
|
+
_internal: { delay: delay2 = delay } = {}
|
5051
|
+
} = {}) {
|
5052
|
+
let buffer = "";
|
5053
|
+
return new TransformStream({
|
5054
|
+
async transform(chunk, controller) {
|
5055
|
+
if (chunk.type === "step-finish") {
|
5056
|
+
if (buffer.length > 0) {
|
5057
|
+
controller.enqueue({ type: "text-delta", textDelta: buffer });
|
5058
|
+
buffer = "";
|
5059
|
+
}
|
5060
|
+
controller.enqueue(chunk);
|
5061
|
+
return;
|
5062
|
+
}
|
5063
|
+
if (chunk.type !== "text-delta") {
|
5064
|
+
controller.enqueue(chunk);
|
5065
|
+
return;
|
5066
|
+
}
|
5067
|
+
buffer += chunk.textDelta;
|
5068
|
+
while (buffer.match(/\s/)) {
|
5069
|
+
const whitespaceIndex = buffer.search(/\s/);
|
5070
|
+
const word = buffer.slice(0, whitespaceIndex + 1);
|
5071
|
+
controller.enqueue({ type: "text-delta", textDelta: word });
|
5072
|
+
buffer = buffer.slice(whitespaceIndex + 1);
|
5073
|
+
if (delayInMs > 0) {
|
5074
|
+
await delay2(delayInMs);
|
5075
|
+
}
|
5076
|
+
}
|
5077
|
+
}
|
5078
|
+
});
|
5079
|
+
}
|
5080
|
+
|
5000
5081
|
// core/middleware/wrap-language-model.ts
|
5001
5082
|
var experimental_wrapLanguageModel = ({
|
5002
5083
|
model,
|
@@ -5388,11 +5469,11 @@ __export(llamaindex_adapter_exports, {
|
|
5388
5469
|
toDataStream: () => toDataStream2,
|
5389
5470
|
toDataStreamResponse: () => toDataStreamResponse2
|
5390
5471
|
});
|
5391
|
-
var
|
5472
|
+
var import_provider_utils12 = require("@ai-sdk/provider-utils");
|
5392
5473
|
var import_ui_utils12 = require("@ai-sdk/ui-utils");
|
5393
5474
|
function toDataStreamInternal2(stream, callbacks) {
|
5394
5475
|
const trimStart = trimStartOfStream();
|
5395
|
-
return (0,
|
5476
|
+
return (0, import_provider_utils12.convertAsyncIteratorToReadableStream)(stream[Symbol.asyncIterator]()).pipeThrough(
|
5396
5477
|
new TransformStream({
|
5397
5478
|
async transform(message, controller) {
|
5398
5479
|
controller.enqueue(trimStart(message.delta));
|
@@ -5548,6 +5629,7 @@ var StreamData = class {
|
|
5548
5629
|
embedMany,
|
5549
5630
|
experimental_createProviderRegistry,
|
5550
5631
|
experimental_customProvider,
|
5632
|
+
experimental_generateImage,
|
5551
5633
|
experimental_wrapLanguageModel,
|
5552
5634
|
formatAssistantStreamPart,
|
5553
5635
|
formatDataStreamPart,
|
@@ -5560,6 +5642,7 @@ var StreamData = class {
|
|
5560
5642
|
pipeDataStreamToResponse,
|
5561
5643
|
processDataStream,
|
5562
5644
|
processTextStream,
|
5645
|
+
smoothStream,
|
5563
5646
|
streamObject,
|
5564
5647
|
streamText,
|
5565
5648
|
tool
|