ai 6.0.328 → 6.0.330
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 +14 -0
- package/dist/index.js +308 -167
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +204 -60
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +1 -1
- package/dist/internal/index.mjs +1 -1
- package/docs/02-foundations/02-providers-and-models.mdx +1 -0
- package/docs/07-reference/02-ai-sdk-ui/32-prune-messages.mdx +9 -0
- package/package.json +4 -3
- package/src/generate-object/output-strategy.ts +8 -0
- package/src/generate-object/stream-object.ts +22 -0
- package/src/generate-text/output.ts +21 -25
- package/src/generate-text/stream-text.ts +23 -0
- package/src/util/array-output-stream.ts +161 -0
package/dist/index.mjs
CHANGED
|
@@ -1225,7 +1225,7 @@ import {
|
|
|
1225
1225
|
} from "@ai-sdk/provider-utils";
|
|
1226
1226
|
|
|
1227
1227
|
// src/version.ts
|
|
1228
|
-
var VERSION = true ? "6.0.
|
|
1228
|
+
var VERSION = true ? "6.0.330" : "0.0.0-test";
|
|
1229
1229
|
|
|
1230
1230
|
// src/util/download/download.ts
|
|
1231
1231
|
var download = async ({
|
|
@@ -3462,12 +3462,124 @@ import {
|
|
|
3462
3462
|
import {
|
|
3463
3463
|
asSchema as asSchema3,
|
|
3464
3464
|
resolve,
|
|
3465
|
-
safeParseJSON as
|
|
3465
|
+
safeParseJSON as safeParseJSON3,
|
|
3466
|
+
safeValidateTypes as safeValidateTypes4
|
|
3467
|
+
} from "@ai-sdk/provider-utils";
|
|
3468
|
+
|
|
3469
|
+
// src/util/array-output-stream.ts
|
|
3470
|
+
import {
|
|
3471
|
+
safeParseJSON,
|
|
3466
3472
|
safeValidateTypes as safeValidateTypes3
|
|
3467
3473
|
} from "@ai-sdk/provider-utils";
|
|
3474
|
+
var arrayStreamParserFactories = /* @__PURE__ */ new WeakMap();
|
|
3475
|
+
function createArrayStreamParser(output) {
|
|
3476
|
+
var _a23;
|
|
3477
|
+
return (_a23 = arrayStreamParserFactories.get(output)) == null ? void 0 : _a23();
|
|
3478
|
+
}
|
|
3479
|
+
function createArrayOutputStreamParser(schema, skipInvalidElements) {
|
|
3480
|
+
let phase = 0 /* Prefix */;
|
|
3481
|
+
let prefix = "";
|
|
3482
|
+
let elementText = "";
|
|
3483
|
+
let depth = 0;
|
|
3484
|
+
let inString = false;
|
|
3485
|
+
let escaped = false;
|
|
3486
|
+
let afterComma = false;
|
|
3487
|
+
let pending = [];
|
|
3488
|
+
const elements = [];
|
|
3489
|
+
let publishedCount;
|
|
3490
|
+
async function finishElement() {
|
|
3491
|
+
const parsed = await safeParseJSON({ text: elementText });
|
|
3492
|
+
if (!parsed.success) {
|
|
3493
|
+
return false;
|
|
3494
|
+
}
|
|
3495
|
+
const validated = await safeValidateTypes3({ value: parsed.value, schema });
|
|
3496
|
+
if (validated.success) {
|
|
3497
|
+
pending = [validated.value];
|
|
3498
|
+
} else if (!skipInvalidElements) {
|
|
3499
|
+
return false;
|
|
3500
|
+
}
|
|
3501
|
+
elementText = "";
|
|
3502
|
+
return true;
|
|
3503
|
+
}
|
|
3504
|
+
function publishPending() {
|
|
3505
|
+
elements.push(...pending);
|
|
3506
|
+
pending = [];
|
|
3507
|
+
}
|
|
3508
|
+
return async (textDelta) => {
|
|
3509
|
+
for (const char of textDelta) {
|
|
3510
|
+
if (phase === 0 /* Prefix */) {
|
|
3511
|
+
prefix += char;
|
|
3512
|
+
if (char === "[") {
|
|
3513
|
+
if (!/^\s*\{\s*"elements"\s*:\s*\[$/.test(prefix)) {
|
|
3514
|
+
return "fallback";
|
|
3515
|
+
}
|
|
3516
|
+
phase = 1 /* Elements */;
|
|
3517
|
+
} else if (prefix.length > 256) {
|
|
3518
|
+
return "fallback";
|
|
3519
|
+
}
|
|
3520
|
+
continue;
|
|
3521
|
+
}
|
|
3522
|
+
if (phase === 2 /* Suffix */ || phase === 3 /* Done */) {
|
|
3523
|
+
if (/\s/.test(char)) {
|
|
3524
|
+
continue;
|
|
3525
|
+
}
|
|
3526
|
+
if (phase === 2 /* Suffix */ && char === "}") {
|
|
3527
|
+
publishPending();
|
|
3528
|
+
phase = 3 /* Done */;
|
|
3529
|
+
continue;
|
|
3530
|
+
}
|
|
3531
|
+
return "fallback";
|
|
3532
|
+
}
|
|
3533
|
+
if (!inString && depth === 0 && (char === "," || char === "]")) {
|
|
3534
|
+
if (elementText.length > 0) {
|
|
3535
|
+
if (!await finishElement()) {
|
|
3536
|
+
return "fallback";
|
|
3537
|
+
}
|
|
3538
|
+
} else if (char === "," || afterComma) {
|
|
3539
|
+
return "fallback";
|
|
3540
|
+
}
|
|
3541
|
+
afterComma = char === ",";
|
|
3542
|
+
if (char === "]") {
|
|
3543
|
+
phase = 2 /* Suffix */;
|
|
3544
|
+
}
|
|
3545
|
+
continue;
|
|
3546
|
+
}
|
|
3547
|
+
if (elementText.length === 0) {
|
|
3548
|
+
if (/\s/.test(char)) {
|
|
3549
|
+
continue;
|
|
3550
|
+
}
|
|
3551
|
+
publishPending();
|
|
3552
|
+
afterComma = false;
|
|
3553
|
+
}
|
|
3554
|
+
elementText += char;
|
|
3555
|
+
if (inString) {
|
|
3556
|
+
if (escaped) {
|
|
3557
|
+
escaped = false;
|
|
3558
|
+
} else if (char === "\\") {
|
|
3559
|
+
escaped = true;
|
|
3560
|
+
} else if (char === '"') {
|
|
3561
|
+
inString = false;
|
|
3562
|
+
}
|
|
3563
|
+
} else if (char === '"') {
|
|
3564
|
+
inString = true;
|
|
3565
|
+
} else if (char === "{" || char === "[") {
|
|
3566
|
+
depth++;
|
|
3567
|
+
} else if (char === "}" || char === "]") {
|
|
3568
|
+
depth--;
|
|
3569
|
+
}
|
|
3570
|
+
}
|
|
3571
|
+
if (phase === 0 /* Prefix */ || publishedCount === elements.length) {
|
|
3572
|
+
return void 0;
|
|
3573
|
+
}
|
|
3574
|
+
const previousCount = publishedCount != null ? publishedCount : 0;
|
|
3575
|
+
const delta = (publishedCount == null ? "[" : "") + (previousCount > 0 && elements.length > previousCount ? "," : "") + elements.slice(previousCount).map((value) => JSON.stringify(value)).join(",") + (phase === 3 /* Done */ ? "]" : "");
|
|
3576
|
+
publishedCount = elements.length;
|
|
3577
|
+
return { partial: elements.slice(), textDelta: delta };
|
|
3578
|
+
};
|
|
3579
|
+
}
|
|
3468
3580
|
|
|
3469
3581
|
// src/util/parse-partial-json.ts
|
|
3470
|
-
import { safeParseJSON } from "@ai-sdk/provider-utils";
|
|
3582
|
+
import { safeParseJSON as safeParseJSON2 } from "@ai-sdk/provider-utils";
|
|
3471
3583
|
|
|
3472
3584
|
// src/util/fix-json.ts
|
|
3473
3585
|
function fixJson(input) {
|
|
@@ -3811,11 +3923,11 @@ async function parsePartialJson(jsonText) {
|
|
|
3811
3923
|
if (jsonText === void 0) {
|
|
3812
3924
|
return { value: void 0, state: "undefined-input" };
|
|
3813
3925
|
}
|
|
3814
|
-
let result = await
|
|
3926
|
+
let result = await safeParseJSON2({ text: jsonText });
|
|
3815
3927
|
if (result.success) {
|
|
3816
3928
|
return { value: result.value, state: "successful-parse" };
|
|
3817
3929
|
}
|
|
3818
|
-
result = await
|
|
3930
|
+
result = await safeParseJSON2({ text: fixJson(jsonText) });
|
|
3819
3931
|
if (result.success) {
|
|
3820
3932
|
return { value: result.value, state: "repaired-parse" };
|
|
3821
3933
|
}
|
|
@@ -3851,29 +3963,25 @@ var object = ({
|
|
|
3851
3963
|
...description != null && { description }
|
|
3852
3964
|
})),
|
|
3853
3965
|
async parseCompleteOutput({ text: text2 }, context2) {
|
|
3854
|
-
const parseResult = await
|
|
3966
|
+
const parseResult = await safeParseJSON3({ text: text2 });
|
|
3855
3967
|
if (!parseResult.success) {
|
|
3856
3968
|
throw new NoObjectGeneratedError({
|
|
3969
|
+
...context2,
|
|
3857
3970
|
message: "No object generated: could not parse the response.",
|
|
3858
3971
|
cause: parseResult.error,
|
|
3859
|
-
text: text2
|
|
3860
|
-
response: context2.response,
|
|
3861
|
-
usage: context2.usage,
|
|
3862
|
-
finishReason: context2.finishReason
|
|
3972
|
+
text: text2
|
|
3863
3973
|
});
|
|
3864
3974
|
}
|
|
3865
|
-
const validationResult = await
|
|
3975
|
+
const validationResult = await safeValidateTypes4({
|
|
3866
3976
|
value: parseResult.value,
|
|
3867
3977
|
schema
|
|
3868
3978
|
});
|
|
3869
3979
|
if (!validationResult.success) {
|
|
3870
3980
|
throw new NoObjectGeneratedError({
|
|
3981
|
+
...context2,
|
|
3871
3982
|
message: "No object generated: response did not match schema.",
|
|
3872
3983
|
cause: validationResult.error,
|
|
3873
|
-
text: text2
|
|
3874
|
-
response: context2.response,
|
|
3875
|
-
usage: context2.usage,
|
|
3876
|
-
finishReason: context2.finishReason
|
|
3984
|
+
text: text2
|
|
3877
3985
|
});
|
|
3878
3986
|
}
|
|
3879
3987
|
return validationResult.value;
|
|
@@ -3905,7 +4013,7 @@ var array = ({
|
|
|
3905
4013
|
description
|
|
3906
4014
|
}) => {
|
|
3907
4015
|
const elementSchema = asSchema3(inputElementSchema);
|
|
3908
|
-
|
|
4016
|
+
const output = {
|
|
3909
4017
|
name: "array",
|
|
3910
4018
|
// JSON schema that describes an array of elements:
|
|
3911
4019
|
responseFormat: resolve(elementSchema.jsonSchema).then((jsonSchema2) => {
|
|
@@ -3926,45 +4034,39 @@ var array = ({
|
|
|
3926
4034
|
};
|
|
3927
4035
|
}),
|
|
3928
4036
|
async parseCompleteOutput({ text: text2 }, context2) {
|
|
3929
|
-
const parseResult = await
|
|
4037
|
+
const parseResult = await safeParseJSON3({ text: text2 });
|
|
3930
4038
|
if (!parseResult.success) {
|
|
3931
4039
|
throw new NoObjectGeneratedError({
|
|
4040
|
+
...context2,
|
|
3932
4041
|
message: "No object generated: could not parse the response.",
|
|
3933
4042
|
cause: parseResult.error,
|
|
3934
|
-
text: text2
|
|
3935
|
-
response: context2.response,
|
|
3936
|
-
usage: context2.usage,
|
|
3937
|
-
finishReason: context2.finishReason
|
|
4043
|
+
text: text2
|
|
3938
4044
|
});
|
|
3939
4045
|
}
|
|
3940
4046
|
const outerValue = parseResult.value;
|
|
3941
4047
|
if (outerValue == null || typeof outerValue !== "object" || !("elements" in outerValue) || !Array.isArray(outerValue.elements)) {
|
|
3942
4048
|
throw new NoObjectGeneratedError({
|
|
4049
|
+
...context2,
|
|
3943
4050
|
message: "No object generated: response did not match schema.",
|
|
3944
4051
|
cause: new TypeValidationError2({
|
|
3945
4052
|
value: outerValue,
|
|
3946
4053
|
cause: "response must be an object with an elements array"
|
|
3947
4054
|
}),
|
|
3948
|
-
text: text2
|
|
3949
|
-
response: context2.response,
|
|
3950
|
-
usage: context2.usage,
|
|
3951
|
-
finishReason: context2.finishReason
|
|
4055
|
+
text: text2
|
|
3952
4056
|
});
|
|
3953
4057
|
}
|
|
3954
4058
|
const validatedElements = [];
|
|
3955
4059
|
for (const element of outerValue.elements) {
|
|
3956
|
-
const validationResult = await
|
|
4060
|
+
const validationResult = await safeValidateTypes4({
|
|
3957
4061
|
value: element,
|
|
3958
4062
|
schema: elementSchema
|
|
3959
4063
|
});
|
|
3960
4064
|
if (!validationResult.success) {
|
|
3961
4065
|
throw new NoObjectGeneratedError({
|
|
4066
|
+
...context2,
|
|
3962
4067
|
message: "No object generated: response did not match schema.",
|
|
3963
4068
|
cause: validationResult.error,
|
|
3964
|
-
text: text2
|
|
3965
|
-
response: context2.response,
|
|
3966
|
-
usage: context2.usage,
|
|
3967
|
-
finishReason: context2.finishReason
|
|
4069
|
+
text: text2
|
|
3968
4070
|
});
|
|
3969
4071
|
}
|
|
3970
4072
|
validatedElements.push(validationResult.value);
|
|
@@ -3987,7 +4089,7 @@ var array = ({
|
|
|
3987
4089
|
const rawElements = result.state === "repaired-parse" && outerValue.elements.length > 0 ? outerValue.elements.slice(0, -1) : outerValue.elements;
|
|
3988
4090
|
const parsedElements = [];
|
|
3989
4091
|
for (const rawElement of rawElements) {
|
|
3990
|
-
const validationResult = await
|
|
4092
|
+
const validationResult = await safeValidateTypes4({
|
|
3991
4093
|
value: rawElement,
|
|
3992
4094
|
schema: elementSchema
|
|
3993
4095
|
});
|
|
@@ -4012,6 +4114,12 @@ var array = ({
|
|
|
4012
4114
|
});
|
|
4013
4115
|
}
|
|
4014
4116
|
};
|
|
4117
|
+
const parsePartialOutput = output.parsePartialOutput;
|
|
4118
|
+
arrayStreamParserFactories.set(
|
|
4119
|
+
output,
|
|
4120
|
+
() => output.parsePartialOutput === parsePartialOutput ? createArrayOutputStreamParser(elementSchema, true) : void 0
|
|
4121
|
+
);
|
|
4122
|
+
return output;
|
|
4015
4123
|
};
|
|
4016
4124
|
var choice = ({
|
|
4017
4125
|
options: choiceOptions,
|
|
@@ -4036,29 +4144,25 @@ var choice = ({
|
|
|
4036
4144
|
...description != null && { description }
|
|
4037
4145
|
}),
|
|
4038
4146
|
async parseCompleteOutput({ text: text2 }, context2) {
|
|
4039
|
-
const parseResult = await
|
|
4147
|
+
const parseResult = await safeParseJSON3({ text: text2 });
|
|
4040
4148
|
if (!parseResult.success) {
|
|
4041
4149
|
throw new NoObjectGeneratedError({
|
|
4150
|
+
...context2,
|
|
4042
4151
|
message: "No object generated: could not parse the response.",
|
|
4043
4152
|
cause: parseResult.error,
|
|
4044
|
-
text: text2
|
|
4045
|
-
response: context2.response,
|
|
4046
|
-
usage: context2.usage,
|
|
4047
|
-
finishReason: context2.finishReason
|
|
4153
|
+
text: text2
|
|
4048
4154
|
});
|
|
4049
4155
|
}
|
|
4050
4156
|
const outerValue = parseResult.value;
|
|
4051
4157
|
if (outerValue == null || typeof outerValue !== "object" || !("result" in outerValue) || typeof outerValue.result !== "string" || !choiceOptions.includes(outerValue.result)) {
|
|
4052
4158
|
throw new NoObjectGeneratedError({
|
|
4159
|
+
...context2,
|
|
4053
4160
|
message: "No object generated: response did not match schema.",
|
|
4054
4161
|
cause: new TypeValidationError2({
|
|
4055
4162
|
value: outerValue,
|
|
4056
4163
|
cause: "response must be an object that contains a choice value."
|
|
4057
4164
|
}),
|
|
4058
|
-
text: text2
|
|
4059
|
-
response: context2.response,
|
|
4060
|
-
usage: context2.usage,
|
|
4061
|
-
finishReason: context2.finishReason
|
|
4165
|
+
text: text2
|
|
4062
4166
|
});
|
|
4063
4167
|
}
|
|
4064
4168
|
return outerValue.result;
|
|
@@ -4104,15 +4208,13 @@ var json = ({
|
|
|
4104
4208
|
...description != null && { description }
|
|
4105
4209
|
}),
|
|
4106
4210
|
async parseCompleteOutput({ text: text2 }, context2) {
|
|
4107
|
-
const parseResult = await
|
|
4211
|
+
const parseResult = await safeParseJSON3({ text: text2 });
|
|
4108
4212
|
if (!parseResult.success) {
|
|
4109
4213
|
throw new NoObjectGeneratedError({
|
|
4214
|
+
...context2,
|
|
4110
4215
|
message: "No object generated: could not parse the response.",
|
|
4111
4216
|
cause: parseResult.error,
|
|
4112
|
-
text: text2
|
|
4113
|
-
response: context2.response,
|
|
4114
|
-
usage: context2.usage,
|
|
4115
|
-
finishReason: context2.finishReason
|
|
4217
|
+
text: text2
|
|
4116
4218
|
});
|
|
4117
4219
|
}
|
|
4118
4220
|
return parseResult.value;
|
|
@@ -4139,8 +4241,8 @@ var json = ({
|
|
|
4139
4241
|
// src/generate-text/parse-tool-call.ts
|
|
4140
4242
|
import {
|
|
4141
4243
|
asSchema as asSchema4,
|
|
4142
|
-
safeParseJSON as
|
|
4143
|
-
safeValidateTypes as
|
|
4244
|
+
safeParseJSON as safeParseJSON4,
|
|
4245
|
+
safeValidateTypes as safeValidateTypes5
|
|
4144
4246
|
} from "@ai-sdk/provider-utils";
|
|
4145
4247
|
|
|
4146
4248
|
// src/generate-text/tool-call.ts
|
|
@@ -4203,7 +4305,7 @@ async function parseToolCall({
|
|
|
4203
4305
|
return await doParseToolCall({ toolCall: repairedToolCall, tools });
|
|
4204
4306
|
}
|
|
4205
4307
|
} catch (error) {
|
|
4206
|
-
const parsedInput = await
|
|
4308
|
+
const parsedInput = await safeParseJSON4({ text: toolCall.input });
|
|
4207
4309
|
const input = parsedInput.success ? parsedInput.value : toolCall.input;
|
|
4208
4310
|
const tool2 = tools == null ? void 0 : tools[toolCall.toolName];
|
|
4209
4311
|
return {
|
|
@@ -4222,7 +4324,7 @@ async function parseToolCall({
|
|
|
4222
4324
|
}
|
|
4223
4325
|
}
|
|
4224
4326
|
async function parseProviderExecutedDynamicToolCall(toolCall) {
|
|
4225
|
-
const parseResult = toolCall.input.trim() === "" ? { success: true, value: {} } : await
|
|
4327
|
+
const parseResult = toolCall.input.trim() === "" ? { success: true, value: {} } : await safeParseJSON4({ text: toolCall.input });
|
|
4226
4328
|
if (parseResult.success === false) {
|
|
4227
4329
|
throw new InvalidToolInputError({
|
|
4228
4330
|
toolName: toolCall.toolName,
|
|
@@ -4256,7 +4358,7 @@ async function doParseToolCall({
|
|
|
4256
4358
|
});
|
|
4257
4359
|
}
|
|
4258
4360
|
const schema = asSchema4(tool2.inputSchema);
|
|
4259
|
-
const parseResult = toolCall.input.trim() === "" ? await
|
|
4361
|
+
const parseResult = toolCall.input.trim() === "" ? await safeValidateTypes5({ value: {}, schema }) : await safeParseJSON4({ text: toolCall.input, schema });
|
|
4260
4362
|
if (parseResult.success === false) {
|
|
4261
4363
|
throw new InvalidToolInputError({
|
|
4262
4364
|
toolName,
|
|
@@ -7570,9 +7672,13 @@ function createOutputTransformStream(output) {
|
|
|
7570
7672
|
let text2 = "";
|
|
7571
7673
|
let textChunk = "";
|
|
7572
7674
|
let textProviderMetadata = void 0;
|
|
7675
|
+
let arrayStreamParser = createArrayStreamParser(output);
|
|
7676
|
+
let lastArrayPartial;
|
|
7573
7677
|
let lastPublishedValue = void 0;
|
|
7574
7678
|
let hasPublishedValue = false;
|
|
7575
7679
|
function resetOutputState() {
|
|
7680
|
+
arrayStreamParser = createArrayStreamParser(output);
|
|
7681
|
+
lastArrayPartial = void 0;
|
|
7576
7682
|
firstTextChunkId = void 0;
|
|
7577
7683
|
text2 = "";
|
|
7578
7684
|
textChunk = "";
|
|
@@ -7631,6 +7737,21 @@ function createOutputTransformStream(output) {
|
|
|
7631
7737
|
controller.enqueue({ part: chunk, partialOutput: void 0 });
|
|
7632
7738
|
return;
|
|
7633
7739
|
}
|
|
7740
|
+
if (arrayStreamParser != null) {
|
|
7741
|
+
const result2 = await arrayStreamParser(chunk.text);
|
|
7742
|
+
if (result2 !== "fallback") {
|
|
7743
|
+
if (result2 != null) {
|
|
7744
|
+
lastArrayPartial = result2.partial;
|
|
7745
|
+
publishTextChunk({ controller, partialOutput: lastArrayPartial });
|
|
7746
|
+
}
|
|
7747
|
+
return;
|
|
7748
|
+
}
|
|
7749
|
+
arrayStreamParser = void 0;
|
|
7750
|
+
if (lastArrayPartial != null) {
|
|
7751
|
+
lastPublishedValue = JSON.stringify(lastArrayPartial);
|
|
7752
|
+
hasPublishedValue = true;
|
|
7753
|
+
}
|
|
7754
|
+
}
|
|
7634
7755
|
const result = await output.parsePartialOutput({ text: text2 });
|
|
7635
7756
|
if (result !== void 0) {
|
|
7636
7757
|
const currentValue = typeof result.partial === "string" ? result.partial : JSON.stringify(result.partial);
|
|
@@ -10038,7 +10159,7 @@ import {
|
|
|
10038
10159
|
} from "@ai-sdk/provider";
|
|
10039
10160
|
import {
|
|
10040
10161
|
lazySchema as lazySchema2,
|
|
10041
|
-
safeValidateTypes as
|
|
10162
|
+
safeValidateTypes as safeValidateTypes6,
|
|
10042
10163
|
validateTypes as validateTypes3,
|
|
10043
10164
|
zodSchema as zodSchema2
|
|
10044
10165
|
} from "@ai-sdk/provider-utils";
|
|
@@ -10446,7 +10567,7 @@ async function safeValidateUIMessagesInternal({
|
|
|
10446
10567
|
const inputToValidate = inputSchemaInput == null ? toolPart.input : inputSchemaInput.value;
|
|
10447
10568
|
let convertToDynamic = false;
|
|
10448
10569
|
if (toolPart.state !== "input-streaming" && (toolPart.state !== "output-error" || inputSchemaInput != null || toolPart.input !== void 0)) {
|
|
10449
|
-
const result = await
|
|
10570
|
+
const result = await safeValidateTypes6({
|
|
10450
10571
|
value: inputToValidate,
|
|
10451
10572
|
schema: tool2.inputSchema,
|
|
10452
10573
|
context: inputValidationContext
|
|
@@ -11302,7 +11423,7 @@ import {
|
|
|
11302
11423
|
} from "@ai-sdk/provider";
|
|
11303
11424
|
import {
|
|
11304
11425
|
asSchema as asSchema5,
|
|
11305
|
-
safeValidateTypes as
|
|
11426
|
+
safeValidateTypes as safeValidateTypes7
|
|
11306
11427
|
} from "@ai-sdk/provider-utils";
|
|
11307
11428
|
var noSchemaOutputStrategy = {
|
|
11308
11429
|
type: "no-schema",
|
|
@@ -11342,7 +11463,7 @@ var objectOutputStrategy = (schema) => ({
|
|
|
11342
11463
|
};
|
|
11343
11464
|
},
|
|
11344
11465
|
async validateFinalResult(value) {
|
|
11345
|
-
return
|
|
11466
|
+
return safeValidateTypes7({ value, schema });
|
|
11346
11467
|
},
|
|
11347
11468
|
createElementStream() {
|
|
11348
11469
|
throw new UnsupportedFunctionalityError3({
|
|
@@ -11353,6 +11474,7 @@ var objectOutputStrategy = (schema) => ({
|
|
|
11353
11474
|
var arrayOutputStrategy = (schema) => {
|
|
11354
11475
|
return {
|
|
11355
11476
|
type: "array",
|
|
11477
|
+
createArrayStreamParser: () => createArrayOutputStreamParser(schema, false),
|
|
11356
11478
|
// wrap in object that contains array of elements, since most LLMs will not
|
|
11357
11479
|
// be able to generate an array directly:
|
|
11358
11480
|
// possible future optimization: use arrays directly when model supports grammar-guided generation
|
|
@@ -11388,7 +11510,7 @@ var arrayOutputStrategy = (schema) => {
|
|
|
11388
11510
|
const resultArray = [];
|
|
11389
11511
|
for (let i = 0; i < inputArray.length; i++) {
|
|
11390
11512
|
const element = inputArray[i];
|
|
11391
|
-
const result = await
|
|
11513
|
+
const result = await safeValidateTypes7({ value: element, schema });
|
|
11392
11514
|
if (i === inputArray.length - 1 && !isFinalDelta) {
|
|
11393
11515
|
continue;
|
|
11394
11516
|
}
|
|
@@ -11430,7 +11552,7 @@ var arrayOutputStrategy = (schema) => {
|
|
|
11430
11552
|
const inputArray = value.elements;
|
|
11431
11553
|
const resultArray = [];
|
|
11432
11554
|
for (const element of inputArray) {
|
|
11433
|
-
const result = await
|
|
11555
|
+
const result = await safeValidateTypes7({ value: element, schema });
|
|
11434
11556
|
if (!result.success) {
|
|
11435
11557
|
return result;
|
|
11436
11558
|
}
|
|
@@ -11565,9 +11687,9 @@ function getOutputStrategy({
|
|
|
11565
11687
|
|
|
11566
11688
|
// src/generate-object/parse-and-validate-object-result.ts
|
|
11567
11689
|
import { JSONParseError as JSONParseError2, TypeValidationError as TypeValidationError5 } from "@ai-sdk/provider";
|
|
11568
|
-
import { safeParseJSON as
|
|
11690
|
+
import { safeParseJSON as safeParseJSON5 } from "@ai-sdk/provider-utils";
|
|
11569
11691
|
async function parseAndValidateObjectResult(result, outputStrategy, context2) {
|
|
11570
|
-
const parseResult = await
|
|
11692
|
+
const parseResult = await safeParseJSON5({ text: result });
|
|
11571
11693
|
if (!parseResult.success) {
|
|
11572
11694
|
throw new NoObjectGeneratedError({
|
|
11573
11695
|
message: "No object generated: could not parse the response.",
|
|
@@ -12294,6 +12416,7 @@ var DefaultStreamObjectResult = class {
|
|
|
12294
12416
|
endWhenDone: false,
|
|
12295
12417
|
endOnError: true,
|
|
12296
12418
|
fn: async (rootSpan) => {
|
|
12419
|
+
var _a23;
|
|
12297
12420
|
const standardizedPrompt = await standardizePrompt({
|
|
12298
12421
|
system,
|
|
12299
12422
|
prompt,
|
|
@@ -12381,6 +12504,7 @@ var DefaultStreamObjectResult = class {
|
|
|
12381
12504
|
let object2;
|
|
12382
12505
|
let error;
|
|
12383
12506
|
let terminalError;
|
|
12507
|
+
let arrayStreamParser = (_a23 = outputStrategy.createArrayStreamParser) == null ? void 0 : _a23.call(outputStrategy);
|
|
12384
12508
|
let accumulatedText = "";
|
|
12385
12509
|
let textDelta = "";
|
|
12386
12510
|
let fullResponse = {
|
|
@@ -12395,7 +12519,7 @@ var DefaultStreamObjectResult = class {
|
|
|
12395
12519
|
const transformedStream = stream.pipeThrough(new TransformStream(transformer)).pipeThrough(
|
|
12396
12520
|
new TransformStream({
|
|
12397
12521
|
async transform(chunk, controller) {
|
|
12398
|
-
var
|
|
12522
|
+
var _a24, _b, _c;
|
|
12399
12523
|
if (typeof chunk === "object" && chunk.type === "stream-start") {
|
|
12400
12524
|
warnings = chunk.warnings;
|
|
12401
12525
|
return;
|
|
@@ -12413,6 +12537,26 @@ var DefaultStreamObjectResult = class {
|
|
|
12413
12537
|
if (typeof chunk === "string") {
|
|
12414
12538
|
accumulatedText += chunk;
|
|
12415
12539
|
textDelta += chunk;
|
|
12540
|
+
if (arrayStreamParser != null) {
|
|
12541
|
+
const result = await arrayStreamParser(chunk);
|
|
12542
|
+
if (result !== "fallback") {
|
|
12543
|
+
if (result != null) {
|
|
12544
|
+
latestObject = result.partial;
|
|
12545
|
+
controller.enqueue({
|
|
12546
|
+
type: "object",
|
|
12547
|
+
object: latestObject
|
|
12548
|
+
});
|
|
12549
|
+
controller.enqueue({
|
|
12550
|
+
type: "text-delta",
|
|
12551
|
+
textDelta: result.textDelta
|
|
12552
|
+
});
|
|
12553
|
+
textDelta = "";
|
|
12554
|
+
isFirstDelta = false;
|
|
12555
|
+
}
|
|
12556
|
+
return;
|
|
12557
|
+
}
|
|
12558
|
+
arrayStreamParser = void 0;
|
|
12559
|
+
}
|
|
12416
12560
|
const { value: currentObjectJson, state: parseState } = await parsePartialJson(accumulatedText);
|
|
12417
12561
|
if (currentObjectJson !== void 0 && !isDeepEqualData(latestObjectJson, currentObjectJson)) {
|
|
12418
12562
|
const validationResult = await outputStrategy.validatePartialResult({
|
|
@@ -12445,7 +12589,7 @@ var DefaultStreamObjectResult = class {
|
|
|
12445
12589
|
switch (chunk.type) {
|
|
12446
12590
|
case "response-metadata": {
|
|
12447
12591
|
fullResponse = {
|
|
12448
|
-
id: (
|
|
12592
|
+
id: (_a24 = chunk.id) != null ? _a24 : fullResponse.id,
|
|
12449
12593
|
timestamp: (_b = chunk.timestamp) != null ? _b : fullResponse.timestamp,
|
|
12450
12594
|
modelId: (_c = chunk.modelId) != null ? _c : fullResponse.modelId
|
|
12451
12595
|
};
|