ai 6.0.24 → 6.0.26
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 +12 -0
- package/dist/index.d.mts +1780 -1739
- package/dist/index.d.ts +1780 -1739
- package/dist/index.js +166 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +171 -6
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +1 -1
- package/dist/internal/index.mjs +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -921,7 +921,7 @@ import {
|
|
|
921
921
|
} from "@ai-sdk/provider-utils";
|
|
922
922
|
|
|
923
923
|
// src/version.ts
|
|
924
|
-
var VERSION = true ? "6.0.
|
|
924
|
+
var VERSION = true ? "6.0.26" : "0.0.0-test";
|
|
925
925
|
|
|
926
926
|
// src/util/download/download.ts
|
|
927
927
|
var download = async ({ url }) => {
|
|
@@ -2907,12 +2907,16 @@ async function parsePartialJson(jsonText) {
|
|
|
2907
2907
|
|
|
2908
2908
|
// src/generate-text/output.ts
|
|
2909
2909
|
var text = () => ({
|
|
2910
|
+
name: "text",
|
|
2910
2911
|
responseFormat: Promise.resolve({ type: "text" }),
|
|
2911
2912
|
async parseCompleteOutput({ text: text2 }) {
|
|
2912
2913
|
return text2;
|
|
2913
2914
|
},
|
|
2914
2915
|
async parsePartialOutput({ text: text2 }) {
|
|
2915
2916
|
return { partial: text2 };
|
|
2917
|
+
},
|
|
2918
|
+
createElementStreamTransform() {
|
|
2919
|
+
return void 0;
|
|
2916
2920
|
}
|
|
2917
2921
|
});
|
|
2918
2922
|
var object = ({
|
|
@@ -2922,6 +2926,7 @@ var object = ({
|
|
|
2922
2926
|
}) => {
|
|
2923
2927
|
const schema = asSchema2(inputSchema);
|
|
2924
2928
|
return {
|
|
2929
|
+
name: "object",
|
|
2925
2930
|
responseFormat: resolve(schema.jsonSchema).then((jsonSchema2) => ({
|
|
2926
2931
|
type: "json",
|
|
2927
2932
|
schema: jsonSchema2,
|
|
@@ -2971,6 +2976,9 @@ var object = ({
|
|
|
2971
2976
|
};
|
|
2972
2977
|
}
|
|
2973
2978
|
}
|
|
2979
|
+
},
|
|
2980
|
+
createElementStreamTransform() {
|
|
2981
|
+
return void 0;
|
|
2974
2982
|
}
|
|
2975
2983
|
};
|
|
2976
2984
|
};
|
|
@@ -2981,6 +2989,7 @@ var array = ({
|
|
|
2981
2989
|
}) => {
|
|
2982
2990
|
const elementSchema = asSchema2(inputElementSchema);
|
|
2983
2991
|
return {
|
|
2992
|
+
name: "array",
|
|
2984
2993
|
// JSON schema that describes an array of elements:
|
|
2985
2994
|
responseFormat: resolve(elementSchema.jsonSchema).then((jsonSchema2) => {
|
|
2986
2995
|
const { $schema, ...itemSchema } = jsonSchema2;
|
|
@@ -3070,6 +3079,18 @@ var array = ({
|
|
|
3070
3079
|
return { partial: parsedElements };
|
|
3071
3080
|
}
|
|
3072
3081
|
}
|
|
3082
|
+
},
|
|
3083
|
+
createElementStreamTransform() {
|
|
3084
|
+
let publishedElements = 0;
|
|
3085
|
+
return new TransformStream({
|
|
3086
|
+
transform({ partialOutput }, controller) {
|
|
3087
|
+
if (partialOutput != null) {
|
|
3088
|
+
for (; publishedElements < partialOutput.length; publishedElements++) {
|
|
3089
|
+
controller.enqueue(partialOutput[publishedElements]);
|
|
3090
|
+
}
|
|
3091
|
+
}
|
|
3092
|
+
}
|
|
3093
|
+
});
|
|
3073
3094
|
}
|
|
3074
3095
|
};
|
|
3075
3096
|
};
|
|
@@ -3079,6 +3100,7 @@ var choice = ({
|
|
|
3079
3100
|
description
|
|
3080
3101
|
}) => {
|
|
3081
3102
|
return {
|
|
3103
|
+
name: "choice",
|
|
3082
3104
|
// JSON schema that describes an enumeration:
|
|
3083
3105
|
responseFormat: Promise.resolve({
|
|
3084
3106
|
type: "json",
|
|
@@ -3145,6 +3167,9 @@ var choice = ({
|
|
|
3145
3167
|
}
|
|
3146
3168
|
}
|
|
3147
3169
|
}
|
|
3170
|
+
},
|
|
3171
|
+
createElementStreamTransform() {
|
|
3172
|
+
return void 0;
|
|
3148
3173
|
}
|
|
3149
3174
|
};
|
|
3150
3175
|
};
|
|
@@ -3153,6 +3178,7 @@ var json = ({
|
|
|
3153
3178
|
description
|
|
3154
3179
|
} = {}) => {
|
|
3155
3180
|
return {
|
|
3181
|
+
name: "json",
|
|
3156
3182
|
responseFormat: Promise.resolve({
|
|
3157
3183
|
type: "json",
|
|
3158
3184
|
...name16 != null && { name: name16 },
|
|
@@ -3184,6 +3210,9 @@ var json = ({
|
|
|
3184
3210
|
return result.value === void 0 ? void 0 : { partial: result.value };
|
|
3185
3211
|
}
|
|
3186
3212
|
}
|
|
3213
|
+
},
|
|
3214
|
+
createElementStreamTransform() {
|
|
3215
|
+
return void 0;
|
|
3187
3216
|
}
|
|
3188
3217
|
};
|
|
3189
3218
|
};
|
|
@@ -4306,7 +4335,8 @@ function asContent({
|
|
|
4306
4335
|
|
|
4307
4336
|
// src/generate-text/stream-text.ts
|
|
4308
4337
|
import {
|
|
4309
|
-
getErrorMessage as getErrorMessage7
|
|
4338
|
+
getErrorMessage as getErrorMessage7,
|
|
4339
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
4310
4340
|
} from "@ai-sdk/provider";
|
|
4311
4341
|
import {
|
|
4312
4342
|
createIdGenerator as createIdGenerator2,
|
|
@@ -6860,6 +6890,16 @@ var DefaultStreamTextResult = class {
|
|
|
6860
6890
|
)
|
|
6861
6891
|
);
|
|
6862
6892
|
}
|
|
6893
|
+
get elementStream() {
|
|
6894
|
+
var _a16, _b, _c;
|
|
6895
|
+
const transform = (_a16 = this.outputSpecification) == null ? void 0 : _a16.createElementStreamTransform();
|
|
6896
|
+
if (transform == null) {
|
|
6897
|
+
throw new UnsupportedFunctionalityError2({
|
|
6898
|
+
functionality: `element streams in ${(_c = (_b = this.outputSpecification) == null ? void 0 : _b.name) != null ? _c : "text"} mode`
|
|
6899
|
+
});
|
|
6900
|
+
}
|
|
6901
|
+
return createAsyncIterableStream(this.teeStream().pipeThrough(transform));
|
|
6902
|
+
}
|
|
6863
6903
|
get output() {
|
|
6864
6904
|
return this.finalStep.then((step) => {
|
|
6865
6905
|
var _a16;
|
|
@@ -8685,7 +8725,7 @@ import {
|
|
|
8685
8725
|
isJSONArray,
|
|
8686
8726
|
isJSONObject,
|
|
8687
8727
|
TypeValidationError as TypeValidationError4,
|
|
8688
|
-
UnsupportedFunctionalityError as
|
|
8728
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError3
|
|
8689
8729
|
} from "@ai-sdk/provider";
|
|
8690
8730
|
import {
|
|
8691
8731
|
asSchema as asSchema4,
|
|
@@ -8710,7 +8750,7 @@ var noSchemaOutputStrategy = {
|
|
|
8710
8750
|
} : { success: true, value };
|
|
8711
8751
|
},
|
|
8712
8752
|
createElementStream() {
|
|
8713
|
-
throw new
|
|
8753
|
+
throw new UnsupportedFunctionalityError3({
|
|
8714
8754
|
functionality: "element streams in no-schema mode"
|
|
8715
8755
|
});
|
|
8716
8756
|
}
|
|
@@ -8732,7 +8772,7 @@ var objectOutputStrategy = (schema) => ({
|
|
|
8732
8772
|
return safeValidateTypes4({ value, schema });
|
|
8733
8773
|
},
|
|
8734
8774
|
createElementStream() {
|
|
8735
|
-
throw new
|
|
8775
|
+
throw new UnsupportedFunctionalityError3({
|
|
8736
8776
|
functionality: "element streams in object mode"
|
|
8737
8777
|
});
|
|
8738
8778
|
}
|
|
@@ -8921,7 +8961,7 @@ var enumOutputStrategy = (enumValues) => {
|
|
|
8921
8961
|
};
|
|
8922
8962
|
},
|
|
8923
8963
|
createElementStream() {
|
|
8924
|
-
throw new
|
|
8964
|
+
throw new UnsupportedFunctionalityError3({
|
|
8925
8965
|
functionality: "element streams in enum mode"
|
|
8926
8966
|
});
|
|
8927
8967
|
}
|
|
@@ -10344,6 +10384,130 @@ function defaultSettingsMiddleware({
|
|
|
10344
10384
|
};
|
|
10345
10385
|
}
|
|
10346
10386
|
|
|
10387
|
+
// src/middleware/extract-json-middleware.ts
|
|
10388
|
+
function defaultTransform(text2) {
|
|
10389
|
+
return text2.replace(/^```(?:json)?\s*\n?/, "").replace(/\n?```\s*$/, "").trim();
|
|
10390
|
+
}
|
|
10391
|
+
function extractJsonMiddleware(options) {
|
|
10392
|
+
var _a16;
|
|
10393
|
+
const transform = (_a16 = options == null ? void 0 : options.transform) != null ? _a16 : defaultTransform;
|
|
10394
|
+
const hasCustomTransform = (options == null ? void 0 : options.transform) !== void 0;
|
|
10395
|
+
return {
|
|
10396
|
+
specificationVersion: "v3",
|
|
10397
|
+
wrapGenerate: async ({ doGenerate }) => {
|
|
10398
|
+
const { content, ...rest } = await doGenerate();
|
|
10399
|
+
const transformedContent = [];
|
|
10400
|
+
for (const part of content) {
|
|
10401
|
+
if (part.type !== "text") {
|
|
10402
|
+
transformedContent.push(part);
|
|
10403
|
+
continue;
|
|
10404
|
+
}
|
|
10405
|
+
transformedContent.push({
|
|
10406
|
+
...part,
|
|
10407
|
+
text: transform(part.text)
|
|
10408
|
+
});
|
|
10409
|
+
}
|
|
10410
|
+
return { content: transformedContent, ...rest };
|
|
10411
|
+
},
|
|
10412
|
+
wrapStream: async ({ doStream }) => {
|
|
10413
|
+
const { stream, ...rest } = await doStream();
|
|
10414
|
+
const textBlocks = {};
|
|
10415
|
+
const SUFFIX_BUFFER_SIZE = 12;
|
|
10416
|
+
return {
|
|
10417
|
+
stream: stream.pipeThrough(
|
|
10418
|
+
new TransformStream({
|
|
10419
|
+
transform: (chunk, controller) => {
|
|
10420
|
+
if (chunk.type === "text-start") {
|
|
10421
|
+
textBlocks[chunk.id] = {
|
|
10422
|
+
startEvent: chunk,
|
|
10423
|
+
// Custom transforms need to buffer all content
|
|
10424
|
+
phase: hasCustomTransform ? "buffering" : "prefix",
|
|
10425
|
+
buffer: "",
|
|
10426
|
+
prefixStripped: false
|
|
10427
|
+
};
|
|
10428
|
+
return;
|
|
10429
|
+
}
|
|
10430
|
+
if (chunk.type === "text-delta") {
|
|
10431
|
+
const block = textBlocks[chunk.id];
|
|
10432
|
+
if (!block) {
|
|
10433
|
+
controller.enqueue(chunk);
|
|
10434
|
+
return;
|
|
10435
|
+
}
|
|
10436
|
+
block.buffer += chunk.delta;
|
|
10437
|
+
if (block.phase === "buffering") {
|
|
10438
|
+
return;
|
|
10439
|
+
}
|
|
10440
|
+
if (block.phase === "prefix") {
|
|
10441
|
+
if (block.buffer.length > 0 && !block.buffer.startsWith("`")) {
|
|
10442
|
+
block.phase = "streaming";
|
|
10443
|
+
controller.enqueue(block.startEvent);
|
|
10444
|
+
} else if (block.buffer.startsWith("```")) {
|
|
10445
|
+
if (block.buffer.includes("\n")) {
|
|
10446
|
+
const prefixMatch = block.buffer.match(/^```(?:json)?\s*\n/);
|
|
10447
|
+
if (prefixMatch) {
|
|
10448
|
+
block.buffer = block.buffer.slice(
|
|
10449
|
+
prefixMatch[0].length
|
|
10450
|
+
);
|
|
10451
|
+
block.prefixStripped = true;
|
|
10452
|
+
block.phase = "streaming";
|
|
10453
|
+
controller.enqueue(block.startEvent);
|
|
10454
|
+
} else {
|
|
10455
|
+
block.phase = "streaming";
|
|
10456
|
+
controller.enqueue(block.startEvent);
|
|
10457
|
+
}
|
|
10458
|
+
}
|
|
10459
|
+
} else if (block.buffer.length >= 3 && !block.buffer.startsWith("```")) {
|
|
10460
|
+
block.phase = "streaming";
|
|
10461
|
+
controller.enqueue(block.startEvent);
|
|
10462
|
+
}
|
|
10463
|
+
}
|
|
10464
|
+
if (block.phase === "streaming" && block.buffer.length > SUFFIX_BUFFER_SIZE) {
|
|
10465
|
+
const toStream = block.buffer.slice(0, -SUFFIX_BUFFER_SIZE);
|
|
10466
|
+
block.buffer = block.buffer.slice(-SUFFIX_BUFFER_SIZE);
|
|
10467
|
+
controller.enqueue({
|
|
10468
|
+
type: "text-delta",
|
|
10469
|
+
id: chunk.id,
|
|
10470
|
+
delta: toStream
|
|
10471
|
+
});
|
|
10472
|
+
}
|
|
10473
|
+
return;
|
|
10474
|
+
}
|
|
10475
|
+
if (chunk.type === "text-end") {
|
|
10476
|
+
const block = textBlocks[chunk.id];
|
|
10477
|
+
if (block) {
|
|
10478
|
+
if (block.phase === "prefix" || block.phase === "buffering") {
|
|
10479
|
+
controller.enqueue(block.startEvent);
|
|
10480
|
+
}
|
|
10481
|
+
let remaining = block.buffer;
|
|
10482
|
+
if (block.phase === "buffering") {
|
|
10483
|
+
remaining = transform(remaining);
|
|
10484
|
+
} else if (block.prefixStripped) {
|
|
10485
|
+
remaining = remaining.replace(/\n?```\s*$/, "").trimEnd();
|
|
10486
|
+
} else {
|
|
10487
|
+
remaining = transform(remaining);
|
|
10488
|
+
}
|
|
10489
|
+
if (remaining.length > 0) {
|
|
10490
|
+
controller.enqueue({
|
|
10491
|
+
type: "text-delta",
|
|
10492
|
+
id: chunk.id,
|
|
10493
|
+
delta: remaining
|
|
10494
|
+
});
|
|
10495
|
+
}
|
|
10496
|
+
controller.enqueue(chunk);
|
|
10497
|
+
delete textBlocks[chunk.id];
|
|
10498
|
+
return;
|
|
10499
|
+
}
|
|
10500
|
+
}
|
|
10501
|
+
controller.enqueue(chunk);
|
|
10502
|
+
}
|
|
10503
|
+
})
|
|
10504
|
+
),
|
|
10505
|
+
...rest
|
|
10506
|
+
};
|
|
10507
|
+
}
|
|
10508
|
+
};
|
|
10509
|
+
}
|
|
10510
|
+
|
|
10347
10511
|
// src/util/get-potential-start-index.ts
|
|
10348
10512
|
function getPotentialStartIndex(text2, searchedText) {
|
|
10349
10513
|
if (searchedText.length === 0) {
|
|
@@ -12145,6 +12309,7 @@ export {
|
|
|
12145
12309
|
experimental_generateImage,
|
|
12146
12310
|
generateSpeech as experimental_generateSpeech,
|
|
12147
12311
|
transcribe as experimental_transcribe,
|
|
12312
|
+
extractJsonMiddleware,
|
|
12148
12313
|
extractReasoningMiddleware,
|
|
12149
12314
|
gateway2 as gateway,
|
|
12150
12315
|
generateId,
|