ai 5.0.0-canary.11 → 5.0.0-canary.13
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 +21 -0
- package/dist/index.d.mts +38 -215
- package/dist/index.d.ts +38 -215
- package/dist/index.js +185 -494
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +175 -484
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +196 -32
- package/dist/internal/index.d.ts +196 -32
- package/dist/internal/index.js +468 -33
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +463 -33
- package/dist/internal/index.mjs.map +1 -1
- package/internal.d.ts +1 -0
- package/mcp-stdio.d.ts +1 -0
- package/package.json +7 -4
- package/test.d.ts +1 -0
package/dist/index.mjs
CHANGED
@@ -347,15 +347,15 @@ function fixJson(input) {
|
|
347
347
|
}
|
348
348
|
|
349
349
|
// core/util/parse-partial-json.ts
|
350
|
-
function parsePartialJson(jsonText) {
|
350
|
+
async function parsePartialJson(jsonText) {
|
351
351
|
if (jsonText === void 0) {
|
352
352
|
return { value: void 0, state: "undefined-input" };
|
353
353
|
}
|
354
|
-
let result = safeParseJSON({ text: jsonText });
|
354
|
+
let result = await safeParseJSON({ text: jsonText });
|
355
355
|
if (result.success) {
|
356
356
|
return { value: result.value, state: "successful-parse" };
|
357
357
|
}
|
358
|
-
result = safeParseJSON({ text: fixJson(jsonText) });
|
358
|
+
result = await safeParseJSON({ text: fixJson(jsonText) });
|
359
359
|
if (result.success) {
|
360
360
|
return { value: result.value, state: "repaired-parse" };
|
361
361
|
}
|
@@ -536,10 +536,18 @@ var reasoningStreamPart = {
|
|
536
536
|
code: "g",
|
537
537
|
name: "reasoning",
|
538
538
|
parse: (value) => {
|
539
|
-
if (typeof value !== "string") {
|
540
|
-
throw new Error(
|
539
|
+
if (value == null || typeof value !== "object" || !("text" in value) || typeof value.text !== "string" || "providerMetadata" in value && typeof value.providerMetadata !== "object") {
|
540
|
+
throw new Error(
|
541
|
+
'"reasoning" parts expect an object with a "text" property.'
|
542
|
+
);
|
541
543
|
}
|
542
|
-
return {
|
544
|
+
return {
|
545
|
+
type: "reasoning",
|
546
|
+
value: {
|
547
|
+
text: value.text,
|
548
|
+
providerMetadata: value.providerMetadata
|
549
|
+
}
|
550
|
+
};
|
543
551
|
}
|
544
552
|
};
|
545
553
|
var sourcePart = {
|
@@ -555,33 +563,6 @@ var sourcePart = {
|
|
555
563
|
};
|
556
564
|
}
|
557
565
|
};
|
558
|
-
var redactedReasoningStreamPart = {
|
559
|
-
code: "i",
|
560
|
-
name: "redacted_reasoning",
|
561
|
-
parse: (value) => {
|
562
|
-
if (value == null || typeof value !== "object" || !("data" in value) || typeof value.data !== "string") {
|
563
|
-
throw new Error(
|
564
|
-
'"redacted_reasoning" parts expect an object with a "data" property.'
|
565
|
-
);
|
566
|
-
}
|
567
|
-
return { type: "redacted_reasoning", value: { data: value.data } };
|
568
|
-
}
|
569
|
-
};
|
570
|
-
var reasoningSignatureStreamPart = {
|
571
|
-
code: "j",
|
572
|
-
name: "reasoning_signature",
|
573
|
-
parse: (value) => {
|
574
|
-
if (value == null || typeof value !== "object" || !("signature" in value) || typeof value.signature !== "string") {
|
575
|
-
throw new Error(
|
576
|
-
'"reasoning_signature" parts expect an object with a "signature" property.'
|
577
|
-
);
|
578
|
-
}
|
579
|
-
return {
|
580
|
-
type: "reasoning_signature",
|
581
|
-
value: { signature: value.signature }
|
582
|
-
};
|
583
|
-
}
|
584
|
-
};
|
585
566
|
var fileStreamPart = {
|
586
567
|
code: "k",
|
587
568
|
name: "file",
|
@@ -594,6 +575,16 @@ var fileStreamPart = {
|
|
594
575
|
return { type: "file", value };
|
595
576
|
}
|
596
577
|
};
|
578
|
+
var reasoningPartFinishStreamPart = {
|
579
|
+
code: "l",
|
580
|
+
name: "reasoning_part_finish",
|
581
|
+
parse: () => {
|
582
|
+
return {
|
583
|
+
type: "reasoning_part_finish",
|
584
|
+
value: {}
|
585
|
+
};
|
586
|
+
}
|
587
|
+
};
|
597
588
|
var dataStreamParts = [
|
598
589
|
textStreamPart,
|
599
590
|
dataStreamPart,
|
@@ -608,8 +599,7 @@ var dataStreamParts = [
|
|
608
599
|
startStepStreamPart,
|
609
600
|
reasoningStreamPart,
|
610
601
|
sourcePart,
|
611
|
-
|
612
|
-
reasoningSignatureStreamPart,
|
602
|
+
reasoningPartFinishStreamPart,
|
613
603
|
fileStreamPart
|
614
604
|
];
|
615
605
|
var dataStreamPartsByCode = Object.fromEntries(
|
@@ -658,8 +648,7 @@ async function processDataStream({
|
|
658
648
|
stream,
|
659
649
|
onTextPart,
|
660
650
|
onReasoningPart,
|
661
|
-
|
662
|
-
onRedactedReasoningPart,
|
651
|
+
onReasoningPartFinish,
|
663
652
|
onSourcePart,
|
664
653
|
onFilePart,
|
665
654
|
onDataPart,
|
@@ -700,11 +689,8 @@ async function processDataStream({
|
|
700
689
|
case "reasoning":
|
701
690
|
await (onReasoningPart == null ? void 0 : onReasoningPart(value2));
|
702
691
|
break;
|
703
|
-
case "
|
704
|
-
await (
|
705
|
-
break;
|
706
|
-
case "redacted_reasoning":
|
707
|
-
await (onRedactedReasoningPart == null ? void 0 : onRedactedReasoningPart(value2));
|
692
|
+
case "reasoning_part_finish":
|
693
|
+
await (onReasoningPartFinish == null ? void 0 : onReasoningPartFinish(value2));
|
708
694
|
break;
|
709
695
|
case "file":
|
710
696
|
await (onFilePart == null ? void 0 : onFilePart(value2));
|
@@ -777,7 +763,6 @@ async function processChatResponse({
|
|
777
763
|
};
|
778
764
|
let currentTextPart = void 0;
|
779
765
|
let currentReasoningPart = void 0;
|
780
|
-
let currentReasoningTextDetail = void 0;
|
781
766
|
function updateToolInvocationPart(toolCallId, invocation) {
|
782
767
|
const part = message.parts.find(
|
783
768
|
(part2) => part2.type === "tool-invocation" && part2.toolInvocation.toolCallId === toolCallId
|
@@ -839,47 +824,24 @@ async function processChatResponse({
|
|
839
824
|
},
|
840
825
|
onReasoningPart(value) {
|
841
826
|
var _a18;
|
842
|
-
if (currentReasoningTextDetail == null) {
|
843
|
-
currentReasoningTextDetail = { type: "text", text: value };
|
844
|
-
if (currentReasoningPart != null) {
|
845
|
-
currentReasoningPart.details.push(currentReasoningTextDetail);
|
846
|
-
}
|
847
|
-
} else {
|
848
|
-
currentReasoningTextDetail.text += value;
|
849
|
-
}
|
850
827
|
if (currentReasoningPart == null) {
|
851
828
|
currentReasoningPart = {
|
852
829
|
type: "reasoning",
|
853
|
-
reasoning: value,
|
854
|
-
|
830
|
+
reasoning: value.text,
|
831
|
+
providerMetadata: value.providerMetadata
|
855
832
|
};
|
856
833
|
message.parts.push(currentReasoningPart);
|
857
834
|
} else {
|
858
|
-
currentReasoningPart.reasoning += value;
|
835
|
+
currentReasoningPart.reasoning += value.text;
|
836
|
+
currentReasoningPart.providerMetadata = value.providerMetadata;
|
859
837
|
}
|
860
|
-
message.reasoning = ((_a18 = message.reasoning) != null ? _a18 : "") + value;
|
838
|
+
message.reasoning = ((_a18 = message.reasoning) != null ? _a18 : "") + value.text;
|
861
839
|
execUpdate();
|
862
840
|
},
|
863
|
-
|
864
|
-
if (
|
865
|
-
|
866
|
-
}
|
867
|
-
},
|
868
|
-
onRedactedReasoningPart(value) {
|
869
|
-
if (currentReasoningPart == null) {
|
870
|
-
currentReasoningPart = {
|
871
|
-
type: "reasoning",
|
872
|
-
reasoning: "",
|
873
|
-
details: []
|
874
|
-
};
|
875
|
-
message.parts.push(currentReasoningPart);
|
841
|
+
onReasoningPartFinish(value) {
|
842
|
+
if (currentReasoningPart != null) {
|
843
|
+
currentReasoningPart = void 0;
|
876
844
|
}
|
877
|
-
currentReasoningPart.details.push({
|
878
|
-
type: "redacted",
|
879
|
-
data: value.data
|
880
|
-
});
|
881
|
-
currentReasoningTextDetail = void 0;
|
882
|
-
execUpdate();
|
883
845
|
},
|
884
846
|
onFilePart(value) {
|
885
847
|
message.parts.push({
|
@@ -917,10 +879,12 @@ async function processChatResponse({
|
|
917
879
|
updateToolInvocationPart(value.toolCallId, invocation);
|
918
880
|
execUpdate();
|
919
881
|
},
|
920
|
-
onToolCallDeltaPart(value) {
|
882
|
+
async onToolCallDeltaPart(value) {
|
921
883
|
const partialToolCall = partialToolCalls[value.toolCallId];
|
922
884
|
partialToolCall.text += value.argsTextDelta;
|
923
|
-
const { value: partialArgs } = parsePartialJson(
|
885
|
+
const { value: partialArgs } = await parsePartialJson(
|
886
|
+
partialToolCall.text
|
887
|
+
);
|
924
888
|
const invocation = {
|
925
889
|
state: "partial-call",
|
926
890
|
step: partialToolCall.step,
|
@@ -1001,7 +965,6 @@ async function processChatResponse({
|
|
1001
965
|
step += 1;
|
1002
966
|
currentTextPart = value.isContinued ? currentTextPart : void 0;
|
1003
967
|
currentReasoningPart = void 0;
|
1004
|
-
currentReasoningTextDetail = void 0;
|
1005
968
|
},
|
1006
969
|
onStartStepPart(value) {
|
1007
970
|
if (!replaceLastMessage) {
|
@@ -1298,8 +1261,7 @@ function getMessageParts(message) {
|
|
1298
1261
|
...message.reasoning ? [
|
1299
1262
|
{
|
1300
1263
|
type: "reasoning",
|
1301
|
-
reasoning: message.reasoning
|
1302
|
-
details: [{ type: "text", text: message.reasoning }]
|
1264
|
+
reasoning: message.reasoning
|
1303
1265
|
}
|
1304
1266
|
] : [],
|
1305
1267
|
...message.content ? [{ type: "text", text: message.content }] : []
|
@@ -2884,14 +2846,6 @@ function convertToLanguageModelMessage(message, downloadedAssets) {
|
|
2884
2846
|
return {
|
2885
2847
|
type: "reasoning",
|
2886
2848
|
text: part.text,
|
2887
|
-
signature: part.signature,
|
2888
|
-
providerOptions
|
2889
|
-
};
|
2890
|
-
}
|
2891
|
-
case "redacted-reasoning": {
|
2892
|
-
return {
|
2893
|
-
type: "redacted-reasoning",
|
2894
|
-
data: part.data,
|
2895
2849
|
providerOptions
|
2896
2850
|
};
|
2897
2851
|
}
|
@@ -3285,23 +3239,11 @@ function convertToCoreMessages(messages, options) {
|
|
3285
3239
|
break;
|
3286
3240
|
}
|
3287
3241
|
case "reasoning": {
|
3288
|
-
|
3289
|
-
|
3290
|
-
|
3291
|
-
|
3292
|
-
|
3293
|
-
text: detail.text,
|
3294
|
-
signature: detail.signature
|
3295
|
-
});
|
3296
|
-
break;
|
3297
|
-
case "redacted":
|
3298
|
-
content2.push({
|
3299
|
-
type: "redacted-reasoning",
|
3300
|
-
data: detail.data
|
3301
|
-
});
|
3302
|
-
break;
|
3303
|
-
}
|
3304
|
-
}
|
3242
|
+
content2.push({
|
3243
|
+
type: "reasoning",
|
3244
|
+
text: part.reasoning,
|
3245
|
+
providerOptions: part.providerMetadata
|
3246
|
+
});
|
3305
3247
|
break;
|
3306
3248
|
}
|
3307
3249
|
case "tool-invocation":
|
@@ -3571,11 +3513,6 @@ var reasoningPartSchema = z5.object({
|
|
3571
3513
|
text: z5.string(),
|
3572
3514
|
providerOptions: providerMetadataSchema.optional()
|
3573
3515
|
});
|
3574
|
-
var redactedReasoningPartSchema = z5.object({
|
3575
|
-
type: z5.literal("redacted-reasoning"),
|
3576
|
-
data: z5.string(),
|
3577
|
-
providerOptions: providerMetadataSchema.optional()
|
3578
|
-
});
|
3579
3516
|
var toolCallPartSchema = z5.object({
|
3580
3517
|
type: z5.literal("tool-call"),
|
3581
3518
|
toolCallId: z5.string(),
|
@@ -3616,7 +3553,6 @@ var coreAssistantMessageSchema = z6.object({
|
|
3616
3553
|
textPartSchema,
|
3617
3554
|
filePartSchema,
|
3618
3555
|
reasoningPartSchema,
|
3619
|
-
redactedReasoningPartSchema,
|
3620
3556
|
toolCallPartSchema
|
3621
3557
|
])
|
3622
3558
|
)
|
@@ -3636,7 +3572,7 @@ var coreMessageSchema = z6.union([
|
|
3636
3572
|
]);
|
3637
3573
|
|
3638
3574
|
// core/prompt/standardize-prompt.ts
|
3639
|
-
function standardizePrompt({
|
3575
|
+
async function standardizePrompt({
|
3640
3576
|
prompt,
|
3641
3577
|
tools
|
3642
3578
|
}) {
|
@@ -3693,7 +3629,7 @@ function standardizePrompt({
|
|
3693
3629
|
message: "messages must not be empty"
|
3694
3630
|
});
|
3695
3631
|
}
|
3696
|
-
const validationResult = safeValidateTypes({
|
3632
|
+
const validationResult = await safeValidateTypes({
|
3697
3633
|
value: messages,
|
3698
3634
|
schema: z7.array(coreMessageSchema)
|
3699
3635
|
});
|
@@ -3760,10 +3696,10 @@ function createAsyncIterableStream(source) {
|
|
3760
3696
|
var noSchemaOutputStrategy = {
|
3761
3697
|
type: "no-schema",
|
3762
3698
|
jsonSchema: void 0,
|
3763
|
-
validatePartialResult({ value, textDelta }) {
|
3699
|
+
async validatePartialResult({ value, textDelta }) {
|
3764
3700
|
return { success: true, value: { partial: value, textDelta } };
|
3765
3701
|
},
|
3766
|
-
validateFinalResult(value, context) {
|
3702
|
+
async validateFinalResult(value, context) {
|
3767
3703
|
return value === void 0 ? {
|
3768
3704
|
success: false,
|
3769
3705
|
error: new NoObjectGeneratedError({
|
@@ -3784,7 +3720,7 @@ var noSchemaOutputStrategy = {
|
|
3784
3720
|
var objectOutputStrategy = (schema) => ({
|
3785
3721
|
type: "object",
|
3786
3722
|
jsonSchema: schema.jsonSchema,
|
3787
|
-
validatePartialResult({ value, textDelta }) {
|
3723
|
+
async validatePartialResult({ value, textDelta }) {
|
3788
3724
|
return {
|
3789
3725
|
success: true,
|
3790
3726
|
value: {
|
@@ -3794,7 +3730,7 @@ var objectOutputStrategy = (schema) => ({
|
|
3794
3730
|
}
|
3795
3731
|
};
|
3796
3732
|
},
|
3797
|
-
validateFinalResult(value) {
|
3733
|
+
async validateFinalResult(value) {
|
3798
3734
|
return safeValidateTypes2({ value, schema });
|
3799
3735
|
},
|
3800
3736
|
createElementStream() {
|
@@ -3819,7 +3755,12 @@ var arrayOutputStrategy = (schema) => {
|
|
3819
3755
|
required: ["elements"],
|
3820
3756
|
additionalProperties: false
|
3821
3757
|
},
|
3822
|
-
validatePartialResult({
|
3758
|
+
async validatePartialResult({
|
3759
|
+
value,
|
3760
|
+
latestObject,
|
3761
|
+
isFirstDelta,
|
3762
|
+
isFinalDelta
|
3763
|
+
}) {
|
3823
3764
|
var _a17;
|
3824
3765
|
if (!isJSONObject(value) || !isJSONArray(value.elements)) {
|
3825
3766
|
return {
|
@@ -3834,7 +3775,7 @@ var arrayOutputStrategy = (schema) => {
|
|
3834
3775
|
const resultArray = [];
|
3835
3776
|
for (let i = 0; i < inputArray.length; i++) {
|
3836
3777
|
const element = inputArray[i];
|
3837
|
-
const result = safeValidateTypes2({ value: element, schema });
|
3778
|
+
const result = await safeValidateTypes2({ value: element, schema });
|
3838
3779
|
if (i === inputArray.length - 1 && !isFinalDelta) {
|
3839
3780
|
continue;
|
3840
3781
|
}
|
@@ -3863,7 +3804,7 @@ var arrayOutputStrategy = (schema) => {
|
|
3863
3804
|
}
|
3864
3805
|
};
|
3865
3806
|
},
|
3866
|
-
validateFinalResult(value) {
|
3807
|
+
async validateFinalResult(value) {
|
3867
3808
|
if (!isJSONObject(value) || !isJSONArray(value.elements)) {
|
3868
3809
|
return {
|
3869
3810
|
success: false,
|
@@ -3875,7 +3816,7 @@ var arrayOutputStrategy = (schema) => {
|
|
3875
3816
|
}
|
3876
3817
|
const inputArray = value.elements;
|
3877
3818
|
for (const element of inputArray) {
|
3878
|
-
const result = safeValidateTypes2({ value: element, schema });
|
3819
|
+
const result = await safeValidateTypes2({ value: element, schema });
|
3879
3820
|
if (!result.success) {
|
3880
3821
|
return result;
|
3881
3822
|
}
|
@@ -3929,7 +3870,7 @@ var enumOutputStrategy = (enumValues) => {
|
|
3929
3870
|
required: ["result"],
|
3930
3871
|
additionalProperties: false
|
3931
3872
|
},
|
3932
|
-
validateFinalResult(value) {
|
3873
|
+
async validateFinalResult(value) {
|
3933
3874
|
if (!isJSONObject(value) || typeof value.result !== "string") {
|
3934
3875
|
return {
|
3935
3876
|
success: false,
|
@@ -4174,9 +4115,8 @@ async function generateObject({
|
|
4174
4115
|
let warnings;
|
4175
4116
|
let response;
|
4176
4117
|
let request;
|
4177
|
-
let logprobs;
|
4178
4118
|
let resultProviderMetadata;
|
4179
|
-
const standardizedPrompt = standardizePrompt({
|
4119
|
+
const standardizedPrompt = await standardizePrompt({
|
4180
4120
|
prompt: { system, prompt, messages },
|
4181
4121
|
tools: void 0
|
4182
4122
|
});
|
@@ -4274,12 +4214,11 @@ async function generateObject({
|
|
4274
4214
|
finishReason = generateResult.finishReason;
|
4275
4215
|
usage = generateResult.usage;
|
4276
4216
|
warnings = generateResult.warnings;
|
4277
|
-
logprobs = generateResult.logprobs;
|
4278
4217
|
resultProviderMetadata = generateResult.providerMetadata;
|
4279
4218
|
request = (_a17 = generateResult.request) != null ? _a17 : {};
|
4280
4219
|
response = generateResult.responseData;
|
4281
|
-
function processResult(result2) {
|
4282
|
-
const parseResult = safeParseJSON2({ text: result2 });
|
4220
|
+
async function processResult(result2) {
|
4221
|
+
const parseResult = await safeParseJSON2({ text: result2 });
|
4283
4222
|
if (!parseResult.success) {
|
4284
4223
|
throw new NoObjectGeneratedError({
|
4285
4224
|
message: "No object generated: could not parse the response.",
|
@@ -4290,7 +4229,7 @@ async function generateObject({
|
|
4290
4229
|
finishReason
|
4291
4230
|
});
|
4292
4231
|
}
|
4293
|
-
const validationResult = outputStrategy.validateFinalResult(
|
4232
|
+
const validationResult = await outputStrategy.validateFinalResult(
|
4294
4233
|
parseResult.value,
|
4295
4234
|
{
|
4296
4235
|
text: result2,
|
@@ -4312,7 +4251,7 @@ async function generateObject({
|
|
4312
4251
|
}
|
4313
4252
|
let object2;
|
4314
4253
|
try {
|
4315
|
-
object2 = processResult(result);
|
4254
|
+
object2 = await processResult(result);
|
4316
4255
|
} catch (error) {
|
4317
4256
|
if (repairText != null && NoObjectGeneratedError.isInstance(error) && (JSONParseError.isInstance(error.cause) || TypeValidationError2.isInstance(error.cause))) {
|
4318
4257
|
const repairedText = await repairText({
|
@@ -4322,7 +4261,7 @@ async function generateObject({
|
|
4322
4261
|
if (repairedText === null) {
|
4323
4262
|
throw error;
|
4324
4263
|
}
|
4325
|
-
object2 = processResult(repairedText);
|
4264
|
+
object2 = await processResult(repairedText);
|
4326
4265
|
} else {
|
4327
4266
|
throw error;
|
4328
4267
|
}
|
@@ -4348,7 +4287,6 @@ async function generateObject({
|
|
4348
4287
|
warnings,
|
4349
4288
|
request,
|
4350
4289
|
response,
|
4351
|
-
logprobs,
|
4352
4290
|
providerMetadata: resultProviderMetadata
|
4353
4291
|
});
|
4354
4292
|
}
|
@@ -4363,7 +4301,6 @@ var DefaultGenerateObjectResult = class {
|
|
4363
4301
|
this.providerMetadata = options.providerMetadata;
|
4364
4302
|
this.response = options.response;
|
4365
4303
|
this.request = options.request;
|
4366
|
-
this.logprobs = options.logprobs;
|
4367
4304
|
}
|
4368
4305
|
toJsonResponse(init) {
|
4369
4306
|
var _a17;
|
@@ -4645,7 +4582,7 @@ var DefaultStreamObjectResult = class {
|
|
4645
4582
|
tracer,
|
4646
4583
|
endWhenDone: false,
|
4647
4584
|
fn: async (rootSpan) => {
|
4648
|
-
const standardizedPrompt = standardizePrompt({
|
4585
|
+
const standardizedPrompt = await standardizePrompt({
|
4649
4586
|
prompt: { system, prompt, messages },
|
4650
4587
|
tools: void 0
|
4651
4588
|
});
|
@@ -4760,9 +4697,9 @@ var DefaultStreamObjectResult = class {
|
|
4760
4697
|
if (typeof chunk === "string") {
|
4761
4698
|
accumulatedText += chunk;
|
4762
4699
|
textDelta += chunk;
|
4763
|
-
const { value: currentObjectJson, state: parseState } = parsePartialJson(accumulatedText);
|
4700
|
+
const { value: currentObjectJson, state: parseState } = await parsePartialJson(accumulatedText);
|
4764
4701
|
if (currentObjectJson !== void 0 && !isDeepEqualData(latestObjectJson, currentObjectJson)) {
|
4765
|
-
const validationResult = outputStrategy.validatePartialResult({
|
4702
|
+
const validationResult = await outputStrategy.validatePartialResult({
|
4766
4703
|
value: currentObjectJson,
|
4767
4704
|
textDelta,
|
4768
4705
|
latestObject,
|
@@ -4816,7 +4753,7 @@ var DefaultStreamObjectResult = class {
|
|
4816
4753
|
...fullResponse,
|
4817
4754
|
headers: response == null ? void 0 : response.headers
|
4818
4755
|
});
|
4819
|
-
const validationResult = outputStrategy.validateFinalResult(
|
4756
|
+
const validationResult = await outputStrategy.validateFinalResult(
|
4820
4757
|
latestObjectJson,
|
4821
4758
|
{
|
4822
4759
|
text: accumulatedText,
|
@@ -5254,7 +5191,7 @@ async function doParseToolCall({
|
|
5254
5191
|
});
|
5255
5192
|
}
|
5256
5193
|
const schema = asSchema(tool2.parameters);
|
5257
|
-
const parseResult = toolCall.args.trim() === "" ? safeValidateTypes3({ value: {}, schema }) : safeParseJSON3({ text: toolCall.args, schema });
|
5194
|
+
const parseResult = toolCall.args.trim() === "" ? await safeValidateTypes3({ value: {}, schema }) : await safeParseJSON3({ text: toolCall.args, schema });
|
5258
5195
|
if (parseResult.success === false) {
|
5259
5196
|
throw new InvalidToolArgumentsError({
|
5260
5197
|
toolName,
|
@@ -5271,10 +5208,17 @@ async function doParseToolCall({
|
|
5271
5208
|
}
|
5272
5209
|
|
5273
5210
|
// core/generate-text/reasoning.ts
|
5274
|
-
function asReasoningText(
|
5275
|
-
const reasoningText =
|
5211
|
+
function asReasoningText(reasoningParts) {
|
5212
|
+
const reasoningText = reasoningParts.map((part) => part.text).join("");
|
5276
5213
|
return reasoningText.length > 0 ? reasoningText : void 0;
|
5277
5214
|
}
|
5215
|
+
function convertReasoningContentToParts(content) {
|
5216
|
+
return content.filter((part) => part.type === "reasoning").map((part) => ({
|
5217
|
+
type: "reasoning",
|
5218
|
+
text: part.text,
|
5219
|
+
providerOptions: part.providerMetadata
|
5220
|
+
}));
|
5221
|
+
}
|
5278
5222
|
|
5279
5223
|
// core/generate-text/to-response-messages.ts
|
5280
5224
|
function toResponseMessages({
|
@@ -5289,12 +5233,8 @@ function toResponseMessages({
|
|
5289
5233
|
}) {
|
5290
5234
|
const responseMessages = [];
|
5291
5235
|
const content = [];
|
5292
|
-
|
5293
|
-
content.push(
|
5294
|
-
...reasoning.map(
|
5295
|
-
(part) => part.type === "text" ? { ...part, type: "reasoning" } : { ...part, type: "redacted-reasoning" }
|
5296
|
-
)
|
5297
|
-
);
|
5236
|
+
for (const part of reasoning) {
|
5237
|
+
content.push(part);
|
5298
5238
|
}
|
5299
5239
|
if (files.length > 0) {
|
5300
5240
|
content.push(
|
@@ -5393,7 +5333,7 @@ async function generateText({
|
|
5393
5333
|
headers,
|
5394
5334
|
settings: { ...callSettings, maxRetries }
|
5395
5335
|
});
|
5396
|
-
const initialPrompt = standardizePrompt({
|
5336
|
+
const initialPrompt = await standardizePrompt({
|
5397
5337
|
prompt: { system, prompt, messages },
|
5398
5338
|
tools
|
5399
5339
|
});
|
@@ -5424,7 +5364,7 @@ async function generateText({
|
|
5424
5364
|
let currentModelResponse;
|
5425
5365
|
let currentToolCalls = [];
|
5426
5366
|
let currentToolResults = [];
|
5427
|
-
let
|
5367
|
+
let currentReasoning = [];
|
5428
5368
|
let stepCount = 0;
|
5429
5369
|
const responseMessages = [];
|
5430
5370
|
let text2 = "";
|
@@ -5586,7 +5526,7 @@ async function generateText({
|
|
5586
5526
|
text2.trimEnd() !== text2 ? originalText.trimStart() : originalText;
|
5587
5527
|
const stepText = nextStepType === "continue" ? removeTextAfterLastWhitespace(stepTextLeadingWhitespaceTrimmed) : stepTextLeadingWhitespaceTrimmed;
|
5588
5528
|
text2 = nextStepType === "continue" || stepType === "continue" ? text2 + stepText : stepText;
|
5589
|
-
|
5529
|
+
currentReasoning = convertReasoningContentToParts(
|
5590
5530
|
currentModelResponse.content
|
5591
5531
|
);
|
5592
5532
|
sources.push(
|
@@ -5609,7 +5549,9 @@ async function generateText({
|
|
5609
5549
|
...toResponseMessages({
|
5610
5550
|
text: text2,
|
5611
5551
|
files: asFiles(currentModelResponse.content),
|
5612
|
-
reasoning:
|
5552
|
+
reasoning: convertReasoningContentToParts(
|
5553
|
+
currentModelResponse.content
|
5554
|
+
),
|
5613
5555
|
tools: tools != null ? tools : {},
|
5614
5556
|
toolCalls: currentToolCalls,
|
5615
5557
|
toolResults: currentToolResults,
|
@@ -5621,8 +5563,8 @@ async function generateText({
|
|
5621
5563
|
const currentStepResult = {
|
5622
5564
|
stepType,
|
5623
5565
|
text: stepText,
|
5624
|
-
reasoningText: asReasoningText(
|
5625
|
-
reasoning:
|
5566
|
+
reasoningText: asReasoningText(currentReasoning),
|
5567
|
+
reasoning: currentReasoning,
|
5626
5568
|
files: asFiles(currentModelResponse.content),
|
5627
5569
|
sources: currentModelResponse.content.filter(
|
5628
5570
|
(part) => part.type === "source"
|
@@ -5632,7 +5574,6 @@ async function generateText({
|
|
5632
5574
|
finishReason: currentModelResponse.finishReason,
|
5633
5575
|
usage: currentUsage,
|
5634
5576
|
warnings: currentModelResponse.warnings,
|
5635
|
-
logprobs: currentModelResponse.logprobs,
|
5636
5577
|
request: (_b = currentModelResponse.request) != null ? _b : {},
|
5637
5578
|
response: {
|
5638
5579
|
...currentModelResponse.response,
|
@@ -5666,25 +5607,21 @@ async function generateText({
|
|
5666
5607
|
}
|
5667
5608
|
})
|
5668
5609
|
);
|
5610
|
+
const resolvedOutput = await (output == null ? void 0 : output.parseOutput(
|
5611
|
+
{ text: text2 },
|
5612
|
+
{
|
5613
|
+
response: currentModelResponse.response,
|
5614
|
+
usage,
|
5615
|
+
finishReason: currentModelResponse.finishReason
|
5616
|
+
}
|
5617
|
+
));
|
5669
5618
|
return new DefaultGenerateTextResult({
|
5670
5619
|
text: text2,
|
5671
5620
|
files: asFiles(currentModelResponse.content),
|
5672
|
-
reasoning: asReasoningText(
|
5673
|
-
reasoningDetails:
|
5621
|
+
reasoning: asReasoningText(currentReasoning),
|
5622
|
+
reasoningDetails: currentReasoning,
|
5674
5623
|
sources,
|
5675
|
-
|
5676
|
-
if (output == null) {
|
5677
|
-
throw new NoOutputSpecifiedError();
|
5678
|
-
}
|
5679
|
-
return output.parseOutput(
|
5680
|
-
{ text: text2 },
|
5681
|
-
{
|
5682
|
-
response: currentModelResponse.response,
|
5683
|
-
usage,
|
5684
|
-
finishReason: currentModelResponse.finishReason
|
5685
|
-
}
|
5686
|
-
);
|
5687
|
-
},
|
5624
|
+
resolvedOutput,
|
5688
5625
|
toolCalls: currentToolCalls,
|
5689
5626
|
toolResults: currentToolResults,
|
5690
5627
|
finishReason: currentModelResponse.finishReason,
|
@@ -5695,7 +5632,6 @@ async function generateText({
|
|
5695
5632
|
...currentModelResponse.response,
|
5696
5633
|
messages: responseMessages
|
5697
5634
|
},
|
5698
|
-
logprobs: currentModelResponse.logprobs,
|
5699
5635
|
steps,
|
5700
5636
|
providerMetadata: currentModelResponse.providerMetadata
|
5701
5637
|
});
|
@@ -5792,42 +5728,16 @@ var DefaultGenerateTextResult = class {
|
|
5792
5728
|
this.response = options.response;
|
5793
5729
|
this.steps = options.steps;
|
5794
5730
|
this.providerMetadata = options.providerMetadata;
|
5795
|
-
this.
|
5796
|
-
this.outputResolver = options.outputResolver;
|
5731
|
+
this.resolvedOutput = options.resolvedOutput;
|
5797
5732
|
this.sources = options.sources;
|
5798
5733
|
}
|
5799
5734
|
get experimental_output() {
|
5800
|
-
|
5801
|
-
|
5802
|
-
};
|
5803
|
-
function asReasoningDetails(content) {
|
5804
|
-
const reasoning = content.filter((part) => part.type === "reasoning");
|
5805
|
-
if (reasoning.length === 0) {
|
5806
|
-
return [];
|
5807
|
-
}
|
5808
|
-
const result = [];
|
5809
|
-
let activeReasoningText;
|
5810
|
-
for (const part of reasoning) {
|
5811
|
-
if (part.reasoningType === "text") {
|
5812
|
-
if (activeReasoningText == null) {
|
5813
|
-
activeReasoningText = { type: "text", text: part.text };
|
5814
|
-
result.push(activeReasoningText);
|
5815
|
-
} else {
|
5816
|
-
activeReasoningText.text += part.text;
|
5817
|
-
}
|
5818
|
-
} else if (part.reasoningType === "signature") {
|
5819
|
-
if (activeReasoningText == null) {
|
5820
|
-
activeReasoningText = { type: "text", text: "" };
|
5821
|
-
result.push(activeReasoningText);
|
5822
|
-
}
|
5823
|
-
activeReasoningText.signature = part.signature;
|
5824
|
-
activeReasoningText = void 0;
|
5825
|
-
} else if (part.reasoningType === "redacted") {
|
5826
|
-
result.push({ type: "redacted", data: part.data });
|
5735
|
+
if (this.resolvedOutput == null) {
|
5736
|
+
throw new NoOutputSpecifiedError();
|
5827
5737
|
}
|
5738
|
+
return this.resolvedOutput;
|
5828
5739
|
}
|
5829
|
-
|
5830
|
-
}
|
5740
|
+
};
|
5831
5741
|
function asFiles(content) {
|
5832
5742
|
return content.filter((part) => part.type === "file").map((part) => new DefaultGeneratedFile(part));
|
5833
5743
|
}
|
@@ -5915,10 +5825,10 @@ _a15 = symbol15;
|
|
5915
5825
|
var text = () => ({
|
5916
5826
|
type: "text",
|
5917
5827
|
responseFormat: { type: "text" },
|
5918
|
-
parsePartial({ text: text2 }) {
|
5828
|
+
async parsePartial({ text: text2 }) {
|
5919
5829
|
return { partial: text2 };
|
5920
5830
|
},
|
5921
|
-
parseOutput({ text: text2 }) {
|
5831
|
+
async parseOutput({ text: text2 }) {
|
5922
5832
|
return text2;
|
5923
5833
|
}
|
5924
5834
|
});
|
@@ -5932,8 +5842,8 @@ var object = ({
|
|
5932
5842
|
type: "json",
|
5933
5843
|
schema: schema.jsonSchema
|
5934
5844
|
},
|
5935
|
-
parsePartial({ text: text2 }) {
|
5936
|
-
const result = parsePartialJson(text2);
|
5845
|
+
async parsePartial({ text: text2 }) {
|
5846
|
+
const result = await parsePartialJson(text2);
|
5937
5847
|
switch (result.state) {
|
5938
5848
|
case "failed-parse":
|
5939
5849
|
case "undefined-input":
|
@@ -5950,8 +5860,8 @@ var object = ({
|
|
5950
5860
|
}
|
5951
5861
|
}
|
5952
5862
|
},
|
5953
|
-
parseOutput({ text: text2 }, context) {
|
5954
|
-
const parseResult = safeParseJSON4({ text: text2 });
|
5863
|
+
async parseOutput({ text: text2 }, context) {
|
5864
|
+
const parseResult = await safeParseJSON4({ text: text2 });
|
5955
5865
|
if (!parseResult.success) {
|
5956
5866
|
throw new NoObjectGeneratedError({
|
5957
5867
|
message: "No object generated: could not parse the response.",
|
@@ -5962,7 +5872,7 @@ var object = ({
|
|
5962
5872
|
finishReason: context.finishReason
|
5963
5873
|
});
|
5964
5874
|
}
|
5965
|
-
const validationResult = safeValidateTypes4({
|
5875
|
+
const validationResult = await safeValidateTypes4({
|
5966
5876
|
value: parseResult.value,
|
5967
5877
|
schema
|
5968
5878
|
});
|
@@ -6051,9 +5961,6 @@ function smoothStream({
|
|
6051
5961
|
}
|
6052
5962
|
|
6053
5963
|
// core/generate-text/stream-text.ts
|
6054
|
-
import {
|
6055
|
-
AISDKError as AISDKError18
|
6056
|
-
} from "@ai-sdk/provider";
|
6057
5964
|
import { createIdGenerator as createIdGenerator4 } from "@ai-sdk/provider-utils";
|
6058
5965
|
|
6059
5966
|
// util/as-array.ts
|
@@ -6205,6 +6112,7 @@ function runToolsTransformation({
|
|
6205
6112
|
case "stream-start":
|
6206
6113
|
case "text":
|
6207
6114
|
case "reasoning":
|
6115
|
+
case "reasoning-part-finish":
|
6208
6116
|
case "source":
|
6209
6117
|
case "response-metadata":
|
6210
6118
|
case "error": {
|
@@ -6326,7 +6234,6 @@ function runToolsTransformation({
|
|
6326
6234
|
finishChunk = {
|
6327
6235
|
type: "finish",
|
6328
6236
|
finishReason: chunk.finishReason,
|
6329
|
-
logprobs: chunk.logprobs,
|
6330
6237
|
usage: calculateLanguageModelUsage2(chunk.usage),
|
6331
6238
|
providerMetadata: chunk.providerMetadata
|
6332
6239
|
};
|
@@ -6463,7 +6370,7 @@ function createOutputTransformStream(output) {
|
|
6463
6370
|
textChunk = "";
|
6464
6371
|
}
|
6465
6372
|
return new TransformStream({
|
6466
|
-
transform(chunk, controller) {
|
6373
|
+
async transform(chunk, controller) {
|
6467
6374
|
if (chunk.type === "step-finish") {
|
6468
6375
|
publishTextChunk({ controller });
|
6469
6376
|
}
|
@@ -6473,7 +6380,7 @@ function createOutputTransformStream(output) {
|
|
6473
6380
|
}
|
6474
6381
|
text2 += chunk.text;
|
6475
6382
|
textChunk += chunk.text;
|
6476
|
-
const result = output.parsePartial({ text: text2 });
|
6383
|
+
const result = await output.parsePartial({ text: text2 });
|
6477
6384
|
if (result != null) {
|
6478
6385
|
const currentJson = JSON.stringify(result.partial);
|
6479
6386
|
if (currentJson !== lastPublishedJson) {
|
@@ -6546,7 +6453,7 @@ var DefaultStreamTextResult = class {
|
|
6546
6453
|
let recordedFullText = "";
|
6547
6454
|
let stepReasoning = [];
|
6548
6455
|
let stepFiles = [];
|
6549
|
-
let
|
6456
|
+
let activeReasoningPart = void 0;
|
6550
6457
|
let recordedStepSources = [];
|
6551
6458
|
const recordedSources = [];
|
6552
6459
|
const recordedResponse = {
|
@@ -6578,26 +6485,21 @@ var DefaultStreamTextResult = class {
|
|
6578
6485
|
recordedFullText += part.text;
|
6579
6486
|
}
|
6580
6487
|
if (part.type === "reasoning") {
|
6581
|
-
if (
|
6582
|
-
|
6583
|
-
|
6584
|
-
|
6585
|
-
|
6586
|
-
|
6587
|
-
|
6588
|
-
} else
|
6589
|
-
|
6590
|
-
|
6591
|
-
name: "InvalidStreamPart",
|
6592
|
-
message: "reasoning-signature without reasoning"
|
6593
|
-
});
|
6594
|
-
}
|
6595
|
-
activeReasoningText.signature = part.signature;
|
6596
|
-
activeReasoningText = void 0;
|
6597
|
-
} else if (part.reasoningType === "redacted") {
|
6598
|
-
stepReasoning.push({ type: "redacted", data: part.data });
|
6488
|
+
if (activeReasoningPart == null) {
|
6489
|
+
activeReasoningPart = {
|
6490
|
+
type: "reasoning",
|
6491
|
+
text: part.text,
|
6492
|
+
providerOptions: part.providerMetadata
|
6493
|
+
};
|
6494
|
+
stepReasoning.push(activeReasoningPart);
|
6495
|
+
} else {
|
6496
|
+
activeReasoningPart.text += part.text;
|
6497
|
+
activeReasoningPart.providerOptions = part.providerMetadata;
|
6599
6498
|
}
|
6600
6499
|
}
|
6500
|
+
if (part.type === "reasoning-part-finish") {
|
6501
|
+
activeReasoningPart = void 0;
|
6502
|
+
}
|
6601
6503
|
if (part.type === "file") {
|
6602
6504
|
stepFiles.push(part.file);
|
6603
6505
|
}
|
@@ -6648,7 +6550,6 @@ var DefaultStreamTextResult = class {
|
|
6648
6550
|
finishReason: part.finishReason,
|
6649
6551
|
usage: part.usage,
|
6650
6552
|
warnings: part.warnings,
|
6651
|
-
logprobs: part.logprobs,
|
6652
6553
|
request: part.request,
|
6653
6554
|
response: {
|
6654
6555
|
...part.response,
|
@@ -6665,7 +6566,7 @@ var DefaultStreamTextResult = class {
|
|
6665
6566
|
recordedStepSources = [];
|
6666
6567
|
stepReasoning = [];
|
6667
6568
|
stepFiles = [];
|
6668
|
-
|
6569
|
+
activeReasoningPart = void 0;
|
6669
6570
|
if (nextStepType !== "done") {
|
6670
6571
|
stepType = nextStepType;
|
6671
6572
|
}
|
@@ -6712,7 +6613,6 @@ var DefaultStreamTextResult = class {
|
|
6712
6613
|
self.stepsPromise.resolve(recordedSteps);
|
6713
6614
|
await (onFinish == null ? void 0 : onFinish({
|
6714
6615
|
finishReason,
|
6715
|
-
logprobs: void 0,
|
6716
6616
|
usage,
|
6717
6617
|
text: recordedFullText,
|
6718
6618
|
reasoningText: lastStep.reasoningText,
|
@@ -6777,10 +6677,6 @@ var DefaultStreamTextResult = class {
|
|
6777
6677
|
headers,
|
6778
6678
|
settings: { ...callSettings, maxRetries }
|
6779
6679
|
});
|
6780
|
-
const initialPrompt = standardizePrompt({
|
6781
|
-
prompt: { system, prompt, messages },
|
6782
|
-
tools
|
6783
|
-
});
|
6784
6680
|
const self = this;
|
6785
6681
|
recordSpan({
|
6786
6682
|
name: "ai.streamText",
|
@@ -6809,6 +6705,10 @@ var DefaultStreamTextResult = class {
|
|
6809
6705
|
hasLeadingWhitespace,
|
6810
6706
|
messageId
|
6811
6707
|
}) {
|
6708
|
+
const initialPrompt = await standardizePrompt({
|
6709
|
+
prompt: { system, prompt, messages },
|
6710
|
+
tools
|
6711
|
+
});
|
6812
6712
|
const promptFormat = responseMessages.length === 0 ? initialPrompt.type : "messages";
|
6813
6713
|
const stepInputMessages = [
|
6814
6714
|
...initialPrompt.messages,
|
@@ -6908,7 +6808,7 @@ var DefaultStreamTextResult = class {
|
|
6908
6808
|
let warnings;
|
6909
6809
|
const stepReasoning2 = [];
|
6910
6810
|
const stepFiles2 = [];
|
6911
|
-
let
|
6811
|
+
let activeReasoningPart2 = void 0;
|
6912
6812
|
let stepFinishReason = "unknown";
|
6913
6813
|
let stepUsage = {
|
6914
6814
|
promptTokens: 0,
|
@@ -6919,7 +6819,6 @@ var DefaultStreamTextResult = class {
|
|
6919
6819
|
let stepFirstChunk = true;
|
6920
6820
|
let stepText = "";
|
6921
6821
|
let fullStepText = stepType2 === "continue" ? previousStepText : "";
|
6922
|
-
let stepLogProbs;
|
6923
6822
|
let stepResponse = {
|
6924
6823
|
id: generateId3(),
|
6925
6824
|
timestamp: currentDate(),
|
@@ -6995,33 +6894,24 @@ var DefaultStreamTextResult = class {
|
|
6995
6894
|
}
|
6996
6895
|
case "reasoning": {
|
6997
6896
|
controller.enqueue(chunk);
|
6998
|
-
if (
|
6999
|
-
|
7000
|
-
|
7001
|
-
|
7002
|
-
|
7003
|
-
|
7004
|
-
|
7005
|
-
|
7006
|
-
|
7007
|
-
|
7008
|
-
} else if (chunk.reasoningType === "signature") {
|
7009
|
-
if (activeReasoningText2 == null) {
|
7010
|
-
throw new InvalidStreamPartError({
|
7011
|
-
chunk,
|
7012
|
-
message: "reasoning-signature without reasoning"
|
7013
|
-
});
|
7014
|
-
}
|
7015
|
-
activeReasoningText2.signature = chunk.signature;
|
7016
|
-
activeReasoningText2 = void 0;
|
7017
|
-
} else if (chunk.reasoningType === "redacted") {
|
7018
|
-
stepReasoning2.push({
|
7019
|
-
type: "redacted",
|
7020
|
-
data: chunk.data
|
7021
|
-
});
|
6897
|
+
if (activeReasoningPart2 == null) {
|
6898
|
+
activeReasoningPart2 = {
|
6899
|
+
type: "reasoning",
|
6900
|
+
text: chunk.text,
|
6901
|
+
providerOptions: chunk.providerMetadata
|
6902
|
+
};
|
6903
|
+
stepReasoning2.push(activeReasoningPart2);
|
6904
|
+
} else {
|
6905
|
+
activeReasoningPart2.text += chunk.text;
|
6906
|
+
activeReasoningPart2.providerOptions = chunk.providerMetadata;
|
7022
6907
|
}
|
7023
6908
|
break;
|
7024
6909
|
}
|
6910
|
+
case "reasoning-part-finish": {
|
6911
|
+
activeReasoningPart2 = void 0;
|
6912
|
+
controller.enqueue(chunk);
|
6913
|
+
break;
|
6914
|
+
}
|
7025
6915
|
case "tool-call": {
|
7026
6916
|
controller.enqueue(chunk);
|
7027
6917
|
stepToolCalls.push(chunk);
|
@@ -7044,7 +6934,6 @@ var DefaultStreamTextResult = class {
|
|
7044
6934
|
stepUsage = chunk.usage;
|
7045
6935
|
stepFinishReason = chunk.finishReason;
|
7046
6936
|
stepProviderMetadata = chunk.providerMetadata;
|
7047
|
-
stepLogProbs = chunk.logprobs;
|
7048
6937
|
const msToFinish = now2() - startTimestampMs;
|
7049
6938
|
doStreamSpan.addEvent("ai.stream.finish");
|
7050
6939
|
doStreamSpan.setAttributes({
|
@@ -7132,7 +7021,6 @@ var DefaultStreamTextResult = class {
|
|
7132
7021
|
finishReason: stepFinishReason,
|
7133
7022
|
usage: stepUsage,
|
7134
7023
|
providerMetadata: stepProviderMetadata,
|
7135
|
-
logprobs: stepLogProbs,
|
7136
7024
|
request: stepRequest,
|
7137
7025
|
response: {
|
7138
7026
|
...stepResponse,
|
@@ -7149,7 +7037,6 @@ var DefaultStreamTextResult = class {
|
|
7149
7037
|
finishReason: stepFinishReason,
|
7150
7038
|
usage: combinedUsage,
|
7151
7039
|
providerMetadata: stepProviderMetadata,
|
7152
|
-
logprobs: stepLogProbs,
|
7153
7040
|
response: {
|
7154
7041
|
...stepResponse,
|
7155
7042
|
headers: response == null ? void 0 : response.headers
|
@@ -7350,23 +7237,15 @@ var DefaultStreamTextResult = class {
|
|
7350
7237
|
}
|
7351
7238
|
case "reasoning": {
|
7352
7239
|
if (sendReasoning) {
|
7353
|
-
|
7354
|
-
|
7355
|
-
|
7356
|
-
|
7357
|
-
|
7358
|
-
|
7359
|
-
|
7360
|
-
|
7361
|
-
|
7362
|
-
);
|
7363
|
-
} else if (chunk.reasoningType === "redacted") {
|
7364
|
-
controller.enqueue(
|
7365
|
-
formatDataStreamPart("redacted_reasoning", {
|
7366
|
-
data: chunk.data
|
7367
|
-
})
|
7368
|
-
);
|
7369
|
-
}
|
7240
|
+
controller.enqueue(formatDataStreamPart("reasoning", chunk));
|
7241
|
+
}
|
7242
|
+
break;
|
7243
|
+
}
|
7244
|
+
case "reasoning-part-finish": {
|
7245
|
+
if (sendReasoning) {
|
7246
|
+
controller.enqueue(
|
7247
|
+
formatDataStreamPart("reasoning_part_finish", {})
|
7248
|
+
);
|
7370
7249
|
}
|
7371
7250
|
break;
|
7372
7251
|
}
|
@@ -7577,8 +7456,8 @@ var DefaultStreamTextResult = class {
|
|
7577
7456
|
};
|
7578
7457
|
|
7579
7458
|
// errors/no-speech-generated-error.ts
|
7580
|
-
import { AISDKError as
|
7581
|
-
var NoSpeechGeneratedError = class extends
|
7459
|
+
import { AISDKError as AISDKError18 } from "@ai-sdk/provider";
|
7460
|
+
var NoSpeechGeneratedError = class extends AISDKError18 {
|
7582
7461
|
constructor(options) {
|
7583
7462
|
super({
|
7584
7463
|
name: "AI_NoSpeechGeneratedError",
|
@@ -7667,8 +7546,8 @@ var DefaultSpeechResult = class {
|
|
7667
7546
|
};
|
7668
7547
|
|
7669
7548
|
// errors/no-transcript-generated-error.ts
|
7670
|
-
import { AISDKError as
|
7671
|
-
var NoTranscriptGeneratedError = class extends
|
7549
|
+
import { AISDKError as AISDKError19 } from "@ai-sdk/provider";
|
7550
|
+
var NoTranscriptGeneratedError = class extends AISDKError19 {
|
7672
7551
|
constructor(options) {
|
7673
7552
|
super({
|
7674
7553
|
name: "AI_NoTranscriptGeneratedError",
|
@@ -7856,7 +7735,6 @@ function extractReasoningMiddleware({
|
|
7856
7735
|
}
|
7857
7736
|
transformedContent.push({
|
7858
7737
|
type: "reasoning",
|
7859
|
-
reasoningType: "text",
|
7860
7738
|
text: reasoningText
|
7861
7739
|
});
|
7862
7740
|
transformedContent.push({
|
@@ -7888,7 +7766,6 @@ function extractReasoningMiddleware({
|
|
7888
7766
|
controller.enqueue(
|
7889
7767
|
isReasoning ? {
|
7890
7768
|
type: "reasoning",
|
7891
|
-
reasoningType: "text",
|
7892
7769
|
text: prefix + text2
|
7893
7770
|
} : {
|
7894
7771
|
type: "text",
|
@@ -7915,6 +7792,9 @@ function extractReasoningMiddleware({
|
|
7915
7792
|
const foundFullMatch = startIndex + nextTag.length <= buffer.length;
|
7916
7793
|
if (foundFullMatch) {
|
7917
7794
|
buffer = buffer.slice(startIndex + nextTag.length);
|
7795
|
+
if (isReasoning) {
|
7796
|
+
controller.enqueue({ type: "reasoning-part-finish" });
|
7797
|
+
}
|
7918
7798
|
isReasoning = !isReasoning;
|
7919
7799
|
afterSwitch = true;
|
7920
7800
|
} else {
|
@@ -7951,7 +7831,6 @@ function simulateStreamingMiddleware() {
|
|
7951
7831
|
type: "finish",
|
7952
7832
|
finishReason: result.finishReason,
|
7953
7833
|
usage: result.usage,
|
7954
|
-
logprobs: result.logprobs,
|
7955
7834
|
providerMetadata: result.providerMetadata
|
7956
7835
|
});
|
7957
7836
|
controller.close();
|
@@ -8029,7 +7908,7 @@ function appendClientMessage({
|
|
8029
7908
|
}
|
8030
7909
|
|
8031
7910
|
// core/prompt/append-response-messages.ts
|
8032
|
-
import { AISDKError as
|
7911
|
+
import { AISDKError as AISDKError20 } from "@ai-sdk/provider";
|
8033
7912
|
function appendResponseMessages({
|
8034
7913
|
messages,
|
8035
7914
|
responseMessages,
|
@@ -8079,40 +7958,20 @@ function appendResponseMessages({
|
|
8079
7958
|
if (reasoningPart == null) {
|
8080
7959
|
reasoningPart = {
|
8081
7960
|
type: "reasoning",
|
8082
|
-
reasoning: ""
|
8083
|
-
details: []
|
7961
|
+
reasoning: ""
|
8084
7962
|
};
|
8085
7963
|
parts.push(reasoningPart);
|
8086
7964
|
}
|
8087
7965
|
reasoningTextContent = (reasoningTextContent != null ? reasoningTextContent : "") + part.text;
|
8088
7966
|
reasoningPart.reasoning += part.text;
|
8089
|
-
reasoningPart.
|
8090
|
-
type: "text",
|
8091
|
-
text: part.text,
|
8092
|
-
signature: part.signature
|
8093
|
-
});
|
8094
|
-
break;
|
8095
|
-
}
|
8096
|
-
case "redacted-reasoning": {
|
8097
|
-
if (reasoningPart == null) {
|
8098
|
-
reasoningPart = {
|
8099
|
-
type: "reasoning",
|
8100
|
-
reasoning: "",
|
8101
|
-
details: []
|
8102
|
-
};
|
8103
|
-
parts.push(reasoningPart);
|
8104
|
-
}
|
8105
|
-
reasoningPart.details.push({
|
8106
|
-
type: "redacted",
|
8107
|
-
data: part.data
|
8108
|
-
});
|
7967
|
+
reasoningPart.providerMetadata = part.providerOptions;
|
8109
7968
|
break;
|
8110
7969
|
}
|
8111
7970
|
case "tool-call":
|
8112
7971
|
break;
|
8113
7972
|
case "file":
|
8114
7973
|
if (part.data instanceof URL) {
|
8115
|
-
throw new
|
7974
|
+
throw new AISDKError20({
|
8116
7975
|
name: "InvalidAssistantFileData",
|
8117
7976
|
message: "File data cannot be a URL"
|
8118
7977
|
});
|
@@ -8246,7 +8105,7 @@ function customProvider({
|
|
8246
8105
|
var experimental_customProvider = customProvider;
|
8247
8106
|
|
8248
8107
|
// core/registry/no-such-provider-error.ts
|
8249
|
-
import { AISDKError as
|
8108
|
+
import { AISDKError as AISDKError21, NoSuchModelError as NoSuchModelError3 } from "@ai-sdk/provider";
|
8250
8109
|
var name16 = "AI_NoSuchProviderError";
|
8251
8110
|
var marker16 = `vercel.ai.error.${name16}`;
|
8252
8111
|
var symbol16 = Symbol.for(marker16);
|
@@ -8265,7 +8124,7 @@ var NoSuchProviderError = class extends NoSuchModelError3 {
|
|
8265
8124
|
this.availableProviders = availableProviders;
|
8266
8125
|
}
|
8267
8126
|
static isInstance(error) {
|
8268
|
-
return
|
8127
|
+
return AISDKError21.hasMarker(error, marker16);
|
8269
8128
|
}
|
8270
8129
|
};
|
8271
8130
|
_a16 = symbol16;
|
@@ -8956,172 +8815,6 @@ function simulateReadableStream({
|
|
8956
8815
|
});
|
8957
8816
|
}
|
8958
8817
|
|
8959
|
-
// streams/langchain-adapter.ts
|
8960
|
-
var langchain_adapter_exports = {};
|
8961
|
-
__export(langchain_adapter_exports, {
|
8962
|
-
mergeIntoDataStream: () => mergeIntoDataStream,
|
8963
|
-
toDataStream: () => toDataStream,
|
8964
|
-
toDataStreamResponse: () => toDataStreamResponse
|
8965
|
-
});
|
8966
|
-
|
8967
|
-
// streams/stream-callbacks.ts
|
8968
|
-
function createCallbacksTransformer(callbacks = {}) {
|
8969
|
-
const textEncoder = new TextEncoder();
|
8970
|
-
let aggregatedResponse = "";
|
8971
|
-
return new TransformStream({
|
8972
|
-
async start() {
|
8973
|
-
if (callbacks.onStart)
|
8974
|
-
await callbacks.onStart();
|
8975
|
-
},
|
8976
|
-
async transform(message, controller) {
|
8977
|
-
controller.enqueue(textEncoder.encode(message));
|
8978
|
-
aggregatedResponse += message;
|
8979
|
-
if (callbacks.onToken)
|
8980
|
-
await callbacks.onToken(message);
|
8981
|
-
if (callbacks.onText && typeof message === "string") {
|
8982
|
-
await callbacks.onText(message);
|
8983
|
-
}
|
8984
|
-
},
|
8985
|
-
async flush() {
|
8986
|
-
if (callbacks.onCompletion) {
|
8987
|
-
await callbacks.onCompletion(aggregatedResponse);
|
8988
|
-
}
|
8989
|
-
if (callbacks.onFinal) {
|
8990
|
-
await callbacks.onFinal(aggregatedResponse);
|
8991
|
-
}
|
8992
|
-
}
|
8993
|
-
});
|
8994
|
-
}
|
8995
|
-
|
8996
|
-
// streams/langchain-adapter.ts
|
8997
|
-
function toDataStreamInternal(stream, callbacks) {
|
8998
|
-
return stream.pipeThrough(
|
8999
|
-
new TransformStream({
|
9000
|
-
transform: async (value, controller) => {
|
9001
|
-
var _a17;
|
9002
|
-
if (typeof value === "string") {
|
9003
|
-
controller.enqueue(value);
|
9004
|
-
return;
|
9005
|
-
}
|
9006
|
-
if ("event" in value) {
|
9007
|
-
if (value.event === "on_chat_model_stream") {
|
9008
|
-
forwardAIMessageChunk(
|
9009
|
-
(_a17 = value.data) == null ? void 0 : _a17.chunk,
|
9010
|
-
controller
|
9011
|
-
);
|
9012
|
-
}
|
9013
|
-
return;
|
9014
|
-
}
|
9015
|
-
forwardAIMessageChunk(value, controller);
|
9016
|
-
}
|
9017
|
-
})
|
9018
|
-
).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(new TextDecoderStream()).pipeThrough(
|
9019
|
-
new TransformStream({
|
9020
|
-
transform: async (chunk, controller) => {
|
9021
|
-
controller.enqueue(formatDataStreamPart("text", chunk));
|
9022
|
-
}
|
9023
|
-
})
|
9024
|
-
);
|
9025
|
-
}
|
9026
|
-
function toDataStream(stream, callbacks) {
|
9027
|
-
return toDataStreamInternal(stream, callbacks).pipeThrough(
|
9028
|
-
new TextEncoderStream()
|
9029
|
-
);
|
9030
|
-
}
|
9031
|
-
function toDataStreamResponse(stream, options) {
|
9032
|
-
var _a17;
|
9033
|
-
const dataStream = toDataStreamInternal(
|
9034
|
-
stream,
|
9035
|
-
options == null ? void 0 : options.callbacks
|
9036
|
-
).pipeThrough(new TextEncoderStream());
|
9037
|
-
const data = options == null ? void 0 : options.data;
|
9038
|
-
const init = options == null ? void 0 : options.init;
|
9039
|
-
const responseStream = data ? mergeStreams(data.stream, dataStream) : dataStream;
|
9040
|
-
return new Response(responseStream, {
|
9041
|
-
status: (_a17 = init == null ? void 0 : init.status) != null ? _a17 : 200,
|
9042
|
-
statusText: init == null ? void 0 : init.statusText,
|
9043
|
-
headers: prepareResponseHeaders(init == null ? void 0 : init.headers, {
|
9044
|
-
contentType: "text/plain; charset=utf-8",
|
9045
|
-
dataStreamVersion: "v1"
|
9046
|
-
})
|
9047
|
-
});
|
9048
|
-
}
|
9049
|
-
function mergeIntoDataStream(stream, options) {
|
9050
|
-
options.dataStream.merge(toDataStreamInternal(stream, options.callbacks));
|
9051
|
-
}
|
9052
|
-
function forwardAIMessageChunk(chunk, controller) {
|
9053
|
-
if (typeof chunk.content === "string") {
|
9054
|
-
controller.enqueue(chunk.content);
|
9055
|
-
} else {
|
9056
|
-
const content = chunk.content;
|
9057
|
-
for (const item of content) {
|
9058
|
-
if (item.type === "text") {
|
9059
|
-
controller.enqueue(item.text);
|
9060
|
-
}
|
9061
|
-
}
|
9062
|
-
}
|
9063
|
-
}
|
9064
|
-
|
9065
|
-
// streams/llamaindex-adapter.ts
|
9066
|
-
var llamaindex_adapter_exports = {};
|
9067
|
-
__export(llamaindex_adapter_exports, {
|
9068
|
-
mergeIntoDataStream: () => mergeIntoDataStream2,
|
9069
|
-
toDataStream: () => toDataStream2,
|
9070
|
-
toDataStreamResponse: () => toDataStreamResponse2
|
9071
|
-
});
|
9072
|
-
import { convertAsyncIteratorToReadableStream } from "@ai-sdk/provider-utils";
|
9073
|
-
function toDataStreamInternal2(stream, callbacks) {
|
9074
|
-
const trimStart = trimStartOfStream();
|
9075
|
-
return convertAsyncIteratorToReadableStream(stream[Symbol.asyncIterator]()).pipeThrough(
|
9076
|
-
new TransformStream({
|
9077
|
-
async transform(message, controller) {
|
9078
|
-
controller.enqueue(trimStart(message.delta));
|
9079
|
-
}
|
9080
|
-
})
|
9081
|
-
).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(new TextDecoderStream()).pipeThrough(
|
9082
|
-
new TransformStream({
|
9083
|
-
transform: async (chunk, controller) => {
|
9084
|
-
controller.enqueue(formatDataStreamPart("text", chunk));
|
9085
|
-
}
|
9086
|
-
})
|
9087
|
-
);
|
9088
|
-
}
|
9089
|
-
function toDataStream2(stream, callbacks) {
|
9090
|
-
return toDataStreamInternal2(stream, callbacks).pipeThrough(
|
9091
|
-
new TextEncoderStream()
|
9092
|
-
);
|
9093
|
-
}
|
9094
|
-
function toDataStreamResponse2(stream, options = {}) {
|
9095
|
-
var _a17;
|
9096
|
-
const { init, data, callbacks } = options;
|
9097
|
-
const dataStream = toDataStreamInternal2(stream, callbacks).pipeThrough(
|
9098
|
-
new TextEncoderStream()
|
9099
|
-
);
|
9100
|
-
const responseStream = data ? mergeStreams(data.stream, dataStream) : dataStream;
|
9101
|
-
return new Response(responseStream, {
|
9102
|
-
status: (_a17 = init == null ? void 0 : init.status) != null ? _a17 : 200,
|
9103
|
-
statusText: init == null ? void 0 : init.statusText,
|
9104
|
-
headers: prepareResponseHeaders(init == null ? void 0 : init.headers, {
|
9105
|
-
contentType: "text/plain; charset=utf-8",
|
9106
|
-
dataStreamVersion: "v1"
|
9107
|
-
})
|
9108
|
-
});
|
9109
|
-
}
|
9110
|
-
function mergeIntoDataStream2(stream, options) {
|
9111
|
-
options.dataStream.merge(toDataStreamInternal2(stream, options.callbacks));
|
9112
|
-
}
|
9113
|
-
function trimStartOfStream() {
|
9114
|
-
let isStreamStart = true;
|
9115
|
-
return (text2) => {
|
9116
|
-
if (isStreamStart) {
|
9117
|
-
text2 = text2.trimStart();
|
9118
|
-
if (text2)
|
9119
|
-
isStreamStart = false;
|
9120
|
-
}
|
9121
|
-
return text2;
|
9122
|
-
};
|
9123
|
-
}
|
9124
|
-
|
9125
8818
|
// util/constants.ts
|
9126
8819
|
var HANGING_STREAM_WARNING_TIME_MS = 15 * 1e3;
|
9127
8820
|
|
@@ -9200,8 +8893,6 @@ export {
|
|
9200
8893
|
InvalidStreamPartError,
|
9201
8894
|
InvalidToolArgumentsError,
|
9202
8895
|
JSONParseError2 as JSONParseError,
|
9203
|
-
langchain_adapter_exports as LangChainAdapter,
|
9204
|
-
llamaindex_adapter_exports as LlamaIndexAdapter,
|
9205
8896
|
LoadAPIKeyError,
|
9206
8897
|
MCPClientError,
|
9207
8898
|
MessageConversionError,
|