ai 5.0.0-canary.12 → 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 +13 -0
- package/dist/index.d.mts +38 -183
- package/dist/index.d.ts +38 -183
- package/dist/index.js +185 -479
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +175 -469
- 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,
|
@@ -4175,7 +4116,7 @@ async function generateObject({
|
|
4175
4116
|
let response;
|
4176
4117
|
let request;
|
4177
4118
|
let resultProviderMetadata;
|
4178
|
-
const standardizedPrompt = standardizePrompt({
|
4119
|
+
const standardizedPrompt = await standardizePrompt({
|
4179
4120
|
prompt: { system, prompt, messages },
|
4180
4121
|
tools: void 0
|
4181
4122
|
});
|
@@ -4276,8 +4217,8 @@ async function generateObject({
|
|
4276
4217
|
resultProviderMetadata = generateResult.providerMetadata;
|
4277
4218
|
request = (_a17 = generateResult.request) != null ? _a17 : {};
|
4278
4219
|
response = generateResult.responseData;
|
4279
|
-
function processResult(result2) {
|
4280
|
-
const parseResult = safeParseJSON2({ text: result2 });
|
4220
|
+
async function processResult(result2) {
|
4221
|
+
const parseResult = await safeParseJSON2({ text: result2 });
|
4281
4222
|
if (!parseResult.success) {
|
4282
4223
|
throw new NoObjectGeneratedError({
|
4283
4224
|
message: "No object generated: could not parse the response.",
|
@@ -4288,7 +4229,7 @@ async function generateObject({
|
|
4288
4229
|
finishReason
|
4289
4230
|
});
|
4290
4231
|
}
|
4291
|
-
const validationResult = outputStrategy.validateFinalResult(
|
4232
|
+
const validationResult = await outputStrategy.validateFinalResult(
|
4292
4233
|
parseResult.value,
|
4293
4234
|
{
|
4294
4235
|
text: result2,
|
@@ -4310,7 +4251,7 @@ async function generateObject({
|
|
4310
4251
|
}
|
4311
4252
|
let object2;
|
4312
4253
|
try {
|
4313
|
-
object2 = processResult(result);
|
4254
|
+
object2 = await processResult(result);
|
4314
4255
|
} catch (error) {
|
4315
4256
|
if (repairText != null && NoObjectGeneratedError.isInstance(error) && (JSONParseError.isInstance(error.cause) || TypeValidationError2.isInstance(error.cause))) {
|
4316
4257
|
const repairedText = await repairText({
|
@@ -4320,7 +4261,7 @@ async function generateObject({
|
|
4320
4261
|
if (repairedText === null) {
|
4321
4262
|
throw error;
|
4322
4263
|
}
|
4323
|
-
object2 = processResult(repairedText);
|
4264
|
+
object2 = await processResult(repairedText);
|
4324
4265
|
} else {
|
4325
4266
|
throw error;
|
4326
4267
|
}
|
@@ -4641,7 +4582,7 @@ var DefaultStreamObjectResult = class {
|
|
4641
4582
|
tracer,
|
4642
4583
|
endWhenDone: false,
|
4643
4584
|
fn: async (rootSpan) => {
|
4644
|
-
const standardizedPrompt = standardizePrompt({
|
4585
|
+
const standardizedPrompt = await standardizePrompt({
|
4645
4586
|
prompt: { system, prompt, messages },
|
4646
4587
|
tools: void 0
|
4647
4588
|
});
|
@@ -4756,9 +4697,9 @@ var DefaultStreamObjectResult = class {
|
|
4756
4697
|
if (typeof chunk === "string") {
|
4757
4698
|
accumulatedText += chunk;
|
4758
4699
|
textDelta += chunk;
|
4759
|
-
const { value: currentObjectJson, state: parseState } = parsePartialJson(accumulatedText);
|
4700
|
+
const { value: currentObjectJson, state: parseState } = await parsePartialJson(accumulatedText);
|
4760
4701
|
if (currentObjectJson !== void 0 && !isDeepEqualData(latestObjectJson, currentObjectJson)) {
|
4761
|
-
const validationResult = outputStrategy.validatePartialResult({
|
4702
|
+
const validationResult = await outputStrategy.validatePartialResult({
|
4762
4703
|
value: currentObjectJson,
|
4763
4704
|
textDelta,
|
4764
4705
|
latestObject,
|
@@ -4812,7 +4753,7 @@ var DefaultStreamObjectResult = class {
|
|
4812
4753
|
...fullResponse,
|
4813
4754
|
headers: response == null ? void 0 : response.headers
|
4814
4755
|
});
|
4815
|
-
const validationResult = outputStrategy.validateFinalResult(
|
4756
|
+
const validationResult = await outputStrategy.validateFinalResult(
|
4816
4757
|
latestObjectJson,
|
4817
4758
|
{
|
4818
4759
|
text: accumulatedText,
|
@@ -5250,7 +5191,7 @@ async function doParseToolCall({
|
|
5250
5191
|
});
|
5251
5192
|
}
|
5252
5193
|
const schema = asSchema(tool2.parameters);
|
5253
|
-
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 });
|
5254
5195
|
if (parseResult.success === false) {
|
5255
5196
|
throw new InvalidToolArgumentsError({
|
5256
5197
|
toolName,
|
@@ -5267,10 +5208,17 @@ async function doParseToolCall({
|
|
5267
5208
|
}
|
5268
5209
|
|
5269
5210
|
// core/generate-text/reasoning.ts
|
5270
|
-
function asReasoningText(
|
5271
|
-
const reasoningText =
|
5211
|
+
function asReasoningText(reasoningParts) {
|
5212
|
+
const reasoningText = reasoningParts.map((part) => part.text).join("");
|
5272
5213
|
return reasoningText.length > 0 ? reasoningText : void 0;
|
5273
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
|
+
}
|
5274
5222
|
|
5275
5223
|
// core/generate-text/to-response-messages.ts
|
5276
5224
|
function toResponseMessages({
|
@@ -5285,12 +5233,8 @@ function toResponseMessages({
|
|
5285
5233
|
}) {
|
5286
5234
|
const responseMessages = [];
|
5287
5235
|
const content = [];
|
5288
|
-
|
5289
|
-
content.push(
|
5290
|
-
...reasoning.map(
|
5291
|
-
(part) => part.type === "text" ? { ...part, type: "reasoning" } : { ...part, type: "redacted-reasoning" }
|
5292
|
-
)
|
5293
|
-
);
|
5236
|
+
for (const part of reasoning) {
|
5237
|
+
content.push(part);
|
5294
5238
|
}
|
5295
5239
|
if (files.length > 0) {
|
5296
5240
|
content.push(
|
@@ -5389,7 +5333,7 @@ async function generateText({
|
|
5389
5333
|
headers,
|
5390
5334
|
settings: { ...callSettings, maxRetries }
|
5391
5335
|
});
|
5392
|
-
const initialPrompt = standardizePrompt({
|
5336
|
+
const initialPrompt = await standardizePrompt({
|
5393
5337
|
prompt: { system, prompt, messages },
|
5394
5338
|
tools
|
5395
5339
|
});
|
@@ -5420,7 +5364,7 @@ async function generateText({
|
|
5420
5364
|
let currentModelResponse;
|
5421
5365
|
let currentToolCalls = [];
|
5422
5366
|
let currentToolResults = [];
|
5423
|
-
let
|
5367
|
+
let currentReasoning = [];
|
5424
5368
|
let stepCount = 0;
|
5425
5369
|
const responseMessages = [];
|
5426
5370
|
let text2 = "";
|
@@ -5582,7 +5526,7 @@ async function generateText({
|
|
5582
5526
|
text2.trimEnd() !== text2 ? originalText.trimStart() : originalText;
|
5583
5527
|
const stepText = nextStepType === "continue" ? removeTextAfterLastWhitespace(stepTextLeadingWhitespaceTrimmed) : stepTextLeadingWhitespaceTrimmed;
|
5584
5528
|
text2 = nextStepType === "continue" || stepType === "continue" ? text2 + stepText : stepText;
|
5585
|
-
|
5529
|
+
currentReasoning = convertReasoningContentToParts(
|
5586
5530
|
currentModelResponse.content
|
5587
5531
|
);
|
5588
5532
|
sources.push(
|
@@ -5605,7 +5549,9 @@ async function generateText({
|
|
5605
5549
|
...toResponseMessages({
|
5606
5550
|
text: text2,
|
5607
5551
|
files: asFiles(currentModelResponse.content),
|
5608
|
-
reasoning:
|
5552
|
+
reasoning: convertReasoningContentToParts(
|
5553
|
+
currentModelResponse.content
|
5554
|
+
),
|
5609
5555
|
tools: tools != null ? tools : {},
|
5610
5556
|
toolCalls: currentToolCalls,
|
5611
5557
|
toolResults: currentToolResults,
|
@@ -5617,8 +5563,8 @@ async function generateText({
|
|
5617
5563
|
const currentStepResult = {
|
5618
5564
|
stepType,
|
5619
5565
|
text: stepText,
|
5620
|
-
reasoningText: asReasoningText(
|
5621
|
-
reasoning:
|
5566
|
+
reasoningText: asReasoningText(currentReasoning),
|
5567
|
+
reasoning: currentReasoning,
|
5622
5568
|
files: asFiles(currentModelResponse.content),
|
5623
5569
|
sources: currentModelResponse.content.filter(
|
5624
5570
|
(part) => part.type === "source"
|
@@ -5661,25 +5607,21 @@ async function generateText({
|
|
5661
5607
|
}
|
5662
5608
|
})
|
5663
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
|
+
));
|
5664
5618
|
return new DefaultGenerateTextResult({
|
5665
5619
|
text: text2,
|
5666
5620
|
files: asFiles(currentModelResponse.content),
|
5667
|
-
reasoning: asReasoningText(
|
5668
|
-
reasoningDetails:
|
5621
|
+
reasoning: asReasoningText(currentReasoning),
|
5622
|
+
reasoningDetails: currentReasoning,
|
5669
5623
|
sources,
|
5670
|
-
|
5671
|
-
if (output == null) {
|
5672
|
-
throw new NoOutputSpecifiedError();
|
5673
|
-
}
|
5674
|
-
return output.parseOutput(
|
5675
|
-
{ text: text2 },
|
5676
|
-
{
|
5677
|
-
response: currentModelResponse.response,
|
5678
|
-
usage,
|
5679
|
-
finishReason: currentModelResponse.finishReason
|
5680
|
-
}
|
5681
|
-
);
|
5682
|
-
},
|
5624
|
+
resolvedOutput,
|
5683
5625
|
toolCalls: currentToolCalls,
|
5684
5626
|
toolResults: currentToolResults,
|
5685
5627
|
finishReason: currentModelResponse.finishReason,
|
@@ -5786,41 +5728,16 @@ var DefaultGenerateTextResult = class {
|
|
5786
5728
|
this.response = options.response;
|
5787
5729
|
this.steps = options.steps;
|
5788
5730
|
this.providerMetadata = options.providerMetadata;
|
5789
|
-
this.
|
5731
|
+
this.resolvedOutput = options.resolvedOutput;
|
5790
5732
|
this.sources = options.sources;
|
5791
5733
|
}
|
5792
5734
|
get experimental_output() {
|
5793
|
-
|
5794
|
-
|
5795
|
-
};
|
5796
|
-
function asReasoningDetails(content) {
|
5797
|
-
const reasoning = content.filter((part) => part.type === "reasoning");
|
5798
|
-
if (reasoning.length === 0) {
|
5799
|
-
return [];
|
5800
|
-
}
|
5801
|
-
const result = [];
|
5802
|
-
let activeReasoningText;
|
5803
|
-
for (const part of reasoning) {
|
5804
|
-
if (part.reasoningType === "text") {
|
5805
|
-
if (activeReasoningText == null) {
|
5806
|
-
activeReasoningText = { type: "text", text: part.text };
|
5807
|
-
result.push(activeReasoningText);
|
5808
|
-
} else {
|
5809
|
-
activeReasoningText.text += part.text;
|
5810
|
-
}
|
5811
|
-
} else if (part.reasoningType === "signature") {
|
5812
|
-
if (activeReasoningText == null) {
|
5813
|
-
activeReasoningText = { type: "text", text: "" };
|
5814
|
-
result.push(activeReasoningText);
|
5815
|
-
}
|
5816
|
-
activeReasoningText.signature = part.signature;
|
5817
|
-
activeReasoningText = void 0;
|
5818
|
-
} else if (part.reasoningType === "redacted") {
|
5819
|
-
result.push({ type: "redacted", data: part.data });
|
5735
|
+
if (this.resolvedOutput == null) {
|
5736
|
+
throw new NoOutputSpecifiedError();
|
5820
5737
|
}
|
5738
|
+
return this.resolvedOutput;
|
5821
5739
|
}
|
5822
|
-
|
5823
|
-
}
|
5740
|
+
};
|
5824
5741
|
function asFiles(content) {
|
5825
5742
|
return content.filter((part) => part.type === "file").map((part) => new DefaultGeneratedFile(part));
|
5826
5743
|
}
|
@@ -5908,10 +5825,10 @@ _a15 = symbol15;
|
|
5908
5825
|
var text = () => ({
|
5909
5826
|
type: "text",
|
5910
5827
|
responseFormat: { type: "text" },
|
5911
|
-
parsePartial({ text: text2 }) {
|
5828
|
+
async parsePartial({ text: text2 }) {
|
5912
5829
|
return { partial: text2 };
|
5913
5830
|
},
|
5914
|
-
parseOutput({ text: text2 }) {
|
5831
|
+
async parseOutput({ text: text2 }) {
|
5915
5832
|
return text2;
|
5916
5833
|
}
|
5917
5834
|
});
|
@@ -5925,8 +5842,8 @@ var object = ({
|
|
5925
5842
|
type: "json",
|
5926
5843
|
schema: schema.jsonSchema
|
5927
5844
|
},
|
5928
|
-
parsePartial({ text: text2 }) {
|
5929
|
-
const result = parsePartialJson(text2);
|
5845
|
+
async parsePartial({ text: text2 }) {
|
5846
|
+
const result = await parsePartialJson(text2);
|
5930
5847
|
switch (result.state) {
|
5931
5848
|
case "failed-parse":
|
5932
5849
|
case "undefined-input":
|
@@ -5943,8 +5860,8 @@ var object = ({
|
|
5943
5860
|
}
|
5944
5861
|
}
|
5945
5862
|
},
|
5946
|
-
parseOutput({ text: text2 }, context) {
|
5947
|
-
const parseResult = safeParseJSON4({ text: text2 });
|
5863
|
+
async parseOutput({ text: text2 }, context) {
|
5864
|
+
const parseResult = await safeParseJSON4({ text: text2 });
|
5948
5865
|
if (!parseResult.success) {
|
5949
5866
|
throw new NoObjectGeneratedError({
|
5950
5867
|
message: "No object generated: could not parse the response.",
|
@@ -5955,7 +5872,7 @@ var object = ({
|
|
5955
5872
|
finishReason: context.finishReason
|
5956
5873
|
});
|
5957
5874
|
}
|
5958
|
-
const validationResult = safeValidateTypes4({
|
5875
|
+
const validationResult = await safeValidateTypes4({
|
5959
5876
|
value: parseResult.value,
|
5960
5877
|
schema
|
5961
5878
|
});
|
@@ -6044,9 +5961,6 @@ function smoothStream({
|
|
6044
5961
|
}
|
6045
5962
|
|
6046
5963
|
// core/generate-text/stream-text.ts
|
6047
|
-
import {
|
6048
|
-
AISDKError as AISDKError18
|
6049
|
-
} from "@ai-sdk/provider";
|
6050
5964
|
import { createIdGenerator as createIdGenerator4 } from "@ai-sdk/provider-utils";
|
6051
5965
|
|
6052
5966
|
// util/as-array.ts
|
@@ -6198,6 +6112,7 @@ function runToolsTransformation({
|
|
6198
6112
|
case "stream-start":
|
6199
6113
|
case "text":
|
6200
6114
|
case "reasoning":
|
6115
|
+
case "reasoning-part-finish":
|
6201
6116
|
case "source":
|
6202
6117
|
case "response-metadata":
|
6203
6118
|
case "error": {
|
@@ -6455,7 +6370,7 @@ function createOutputTransformStream(output) {
|
|
6455
6370
|
textChunk = "";
|
6456
6371
|
}
|
6457
6372
|
return new TransformStream({
|
6458
|
-
transform(chunk, controller) {
|
6373
|
+
async transform(chunk, controller) {
|
6459
6374
|
if (chunk.type === "step-finish") {
|
6460
6375
|
publishTextChunk({ controller });
|
6461
6376
|
}
|
@@ -6465,7 +6380,7 @@ function createOutputTransformStream(output) {
|
|
6465
6380
|
}
|
6466
6381
|
text2 += chunk.text;
|
6467
6382
|
textChunk += chunk.text;
|
6468
|
-
const result = output.parsePartial({ text: text2 });
|
6383
|
+
const result = await output.parsePartial({ text: text2 });
|
6469
6384
|
if (result != null) {
|
6470
6385
|
const currentJson = JSON.stringify(result.partial);
|
6471
6386
|
if (currentJson !== lastPublishedJson) {
|
@@ -6538,7 +6453,7 @@ var DefaultStreamTextResult = class {
|
|
6538
6453
|
let recordedFullText = "";
|
6539
6454
|
let stepReasoning = [];
|
6540
6455
|
let stepFiles = [];
|
6541
|
-
let
|
6456
|
+
let activeReasoningPart = void 0;
|
6542
6457
|
let recordedStepSources = [];
|
6543
6458
|
const recordedSources = [];
|
6544
6459
|
const recordedResponse = {
|
@@ -6570,26 +6485,21 @@ var DefaultStreamTextResult = class {
|
|
6570
6485
|
recordedFullText += part.text;
|
6571
6486
|
}
|
6572
6487
|
if (part.type === "reasoning") {
|
6573
|
-
if (
|
6574
|
-
|
6575
|
-
|
6576
|
-
|
6577
|
-
|
6578
|
-
|
6579
|
-
|
6580
|
-
} else
|
6581
|
-
|
6582
|
-
|
6583
|
-
name: "InvalidStreamPart",
|
6584
|
-
message: "reasoning-signature without reasoning"
|
6585
|
-
});
|
6586
|
-
}
|
6587
|
-
activeReasoningText.signature = part.signature;
|
6588
|
-
activeReasoningText = void 0;
|
6589
|
-
} else if (part.reasoningType === "redacted") {
|
6590
|
-
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;
|
6591
6498
|
}
|
6592
6499
|
}
|
6500
|
+
if (part.type === "reasoning-part-finish") {
|
6501
|
+
activeReasoningPart = void 0;
|
6502
|
+
}
|
6593
6503
|
if (part.type === "file") {
|
6594
6504
|
stepFiles.push(part.file);
|
6595
6505
|
}
|
@@ -6656,7 +6566,7 @@ var DefaultStreamTextResult = class {
|
|
6656
6566
|
recordedStepSources = [];
|
6657
6567
|
stepReasoning = [];
|
6658
6568
|
stepFiles = [];
|
6659
|
-
|
6569
|
+
activeReasoningPart = void 0;
|
6660
6570
|
if (nextStepType !== "done") {
|
6661
6571
|
stepType = nextStepType;
|
6662
6572
|
}
|
@@ -6767,10 +6677,6 @@ var DefaultStreamTextResult = class {
|
|
6767
6677
|
headers,
|
6768
6678
|
settings: { ...callSettings, maxRetries }
|
6769
6679
|
});
|
6770
|
-
const initialPrompt = standardizePrompt({
|
6771
|
-
prompt: { system, prompt, messages },
|
6772
|
-
tools
|
6773
|
-
});
|
6774
6680
|
const self = this;
|
6775
6681
|
recordSpan({
|
6776
6682
|
name: "ai.streamText",
|
@@ -6799,6 +6705,10 @@ var DefaultStreamTextResult = class {
|
|
6799
6705
|
hasLeadingWhitespace,
|
6800
6706
|
messageId
|
6801
6707
|
}) {
|
6708
|
+
const initialPrompt = await standardizePrompt({
|
6709
|
+
prompt: { system, prompt, messages },
|
6710
|
+
tools
|
6711
|
+
});
|
6802
6712
|
const promptFormat = responseMessages.length === 0 ? initialPrompt.type : "messages";
|
6803
6713
|
const stepInputMessages = [
|
6804
6714
|
...initialPrompt.messages,
|
@@ -6898,7 +6808,7 @@ var DefaultStreamTextResult = class {
|
|
6898
6808
|
let warnings;
|
6899
6809
|
const stepReasoning2 = [];
|
6900
6810
|
const stepFiles2 = [];
|
6901
|
-
let
|
6811
|
+
let activeReasoningPart2 = void 0;
|
6902
6812
|
let stepFinishReason = "unknown";
|
6903
6813
|
let stepUsage = {
|
6904
6814
|
promptTokens: 0,
|
@@ -6984,33 +6894,24 @@ var DefaultStreamTextResult = class {
|
|
6984
6894
|
}
|
6985
6895
|
case "reasoning": {
|
6986
6896
|
controller.enqueue(chunk);
|
6987
|
-
if (
|
6988
|
-
|
6989
|
-
|
6990
|
-
|
6991
|
-
|
6992
|
-
|
6993
|
-
|
6994
|
-
|
6995
|
-
|
6996
|
-
|
6997
|
-
} else if (chunk.reasoningType === "signature") {
|
6998
|
-
if (activeReasoningText2 == null) {
|
6999
|
-
throw new InvalidStreamPartError({
|
7000
|
-
chunk,
|
7001
|
-
message: "reasoning-signature without reasoning"
|
7002
|
-
});
|
7003
|
-
}
|
7004
|
-
activeReasoningText2.signature = chunk.signature;
|
7005
|
-
activeReasoningText2 = void 0;
|
7006
|
-
} else if (chunk.reasoningType === "redacted") {
|
7007
|
-
stepReasoning2.push({
|
7008
|
-
type: "redacted",
|
7009
|
-
data: chunk.data
|
7010
|
-
});
|
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;
|
7011
6907
|
}
|
7012
6908
|
break;
|
7013
6909
|
}
|
6910
|
+
case "reasoning-part-finish": {
|
6911
|
+
activeReasoningPart2 = void 0;
|
6912
|
+
controller.enqueue(chunk);
|
6913
|
+
break;
|
6914
|
+
}
|
7014
6915
|
case "tool-call": {
|
7015
6916
|
controller.enqueue(chunk);
|
7016
6917
|
stepToolCalls.push(chunk);
|
@@ -7336,23 +7237,15 @@ var DefaultStreamTextResult = class {
|
|
7336
7237
|
}
|
7337
7238
|
case "reasoning": {
|
7338
7239
|
if (sendReasoning) {
|
7339
|
-
|
7340
|
-
|
7341
|
-
|
7342
|
-
|
7343
|
-
|
7344
|
-
|
7345
|
-
|
7346
|
-
|
7347
|
-
|
7348
|
-
);
|
7349
|
-
} else if (chunk.reasoningType === "redacted") {
|
7350
|
-
controller.enqueue(
|
7351
|
-
formatDataStreamPart("redacted_reasoning", {
|
7352
|
-
data: chunk.data
|
7353
|
-
})
|
7354
|
-
);
|
7355
|
-
}
|
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
|
+
);
|
7356
7249
|
}
|
7357
7250
|
break;
|
7358
7251
|
}
|
@@ -7563,8 +7456,8 @@ var DefaultStreamTextResult = class {
|
|
7563
7456
|
};
|
7564
7457
|
|
7565
7458
|
// errors/no-speech-generated-error.ts
|
7566
|
-
import { AISDKError as
|
7567
|
-
var NoSpeechGeneratedError = class extends
|
7459
|
+
import { AISDKError as AISDKError18 } from "@ai-sdk/provider";
|
7460
|
+
var NoSpeechGeneratedError = class extends AISDKError18 {
|
7568
7461
|
constructor(options) {
|
7569
7462
|
super({
|
7570
7463
|
name: "AI_NoSpeechGeneratedError",
|
@@ -7653,8 +7546,8 @@ var DefaultSpeechResult = class {
|
|
7653
7546
|
};
|
7654
7547
|
|
7655
7548
|
// errors/no-transcript-generated-error.ts
|
7656
|
-
import { AISDKError as
|
7657
|
-
var NoTranscriptGeneratedError = class extends
|
7549
|
+
import { AISDKError as AISDKError19 } from "@ai-sdk/provider";
|
7550
|
+
var NoTranscriptGeneratedError = class extends AISDKError19 {
|
7658
7551
|
constructor(options) {
|
7659
7552
|
super({
|
7660
7553
|
name: "AI_NoTranscriptGeneratedError",
|
@@ -7842,7 +7735,6 @@ function extractReasoningMiddleware({
|
|
7842
7735
|
}
|
7843
7736
|
transformedContent.push({
|
7844
7737
|
type: "reasoning",
|
7845
|
-
reasoningType: "text",
|
7846
7738
|
text: reasoningText
|
7847
7739
|
});
|
7848
7740
|
transformedContent.push({
|
@@ -7874,7 +7766,6 @@ function extractReasoningMiddleware({
|
|
7874
7766
|
controller.enqueue(
|
7875
7767
|
isReasoning ? {
|
7876
7768
|
type: "reasoning",
|
7877
|
-
reasoningType: "text",
|
7878
7769
|
text: prefix + text2
|
7879
7770
|
} : {
|
7880
7771
|
type: "text",
|
@@ -7901,6 +7792,9 @@ function extractReasoningMiddleware({
|
|
7901
7792
|
const foundFullMatch = startIndex + nextTag.length <= buffer.length;
|
7902
7793
|
if (foundFullMatch) {
|
7903
7794
|
buffer = buffer.slice(startIndex + nextTag.length);
|
7795
|
+
if (isReasoning) {
|
7796
|
+
controller.enqueue({ type: "reasoning-part-finish" });
|
7797
|
+
}
|
7904
7798
|
isReasoning = !isReasoning;
|
7905
7799
|
afterSwitch = true;
|
7906
7800
|
} else {
|
@@ -8014,7 +7908,7 @@ function appendClientMessage({
|
|
8014
7908
|
}
|
8015
7909
|
|
8016
7910
|
// core/prompt/append-response-messages.ts
|
8017
|
-
import { AISDKError as
|
7911
|
+
import { AISDKError as AISDKError20 } from "@ai-sdk/provider";
|
8018
7912
|
function appendResponseMessages({
|
8019
7913
|
messages,
|
8020
7914
|
responseMessages,
|
@@ -8064,40 +7958,20 @@ function appendResponseMessages({
|
|
8064
7958
|
if (reasoningPart == null) {
|
8065
7959
|
reasoningPart = {
|
8066
7960
|
type: "reasoning",
|
8067
|
-
reasoning: ""
|
8068
|
-
details: []
|
7961
|
+
reasoning: ""
|
8069
7962
|
};
|
8070
7963
|
parts.push(reasoningPart);
|
8071
7964
|
}
|
8072
7965
|
reasoningTextContent = (reasoningTextContent != null ? reasoningTextContent : "") + part.text;
|
8073
7966
|
reasoningPart.reasoning += part.text;
|
8074
|
-
reasoningPart.
|
8075
|
-
type: "text",
|
8076
|
-
text: part.text,
|
8077
|
-
signature: part.signature
|
8078
|
-
});
|
8079
|
-
break;
|
8080
|
-
}
|
8081
|
-
case "redacted-reasoning": {
|
8082
|
-
if (reasoningPart == null) {
|
8083
|
-
reasoningPart = {
|
8084
|
-
type: "reasoning",
|
8085
|
-
reasoning: "",
|
8086
|
-
details: []
|
8087
|
-
};
|
8088
|
-
parts.push(reasoningPart);
|
8089
|
-
}
|
8090
|
-
reasoningPart.details.push({
|
8091
|
-
type: "redacted",
|
8092
|
-
data: part.data
|
8093
|
-
});
|
7967
|
+
reasoningPart.providerMetadata = part.providerOptions;
|
8094
7968
|
break;
|
8095
7969
|
}
|
8096
7970
|
case "tool-call":
|
8097
7971
|
break;
|
8098
7972
|
case "file":
|
8099
7973
|
if (part.data instanceof URL) {
|
8100
|
-
throw new
|
7974
|
+
throw new AISDKError20({
|
8101
7975
|
name: "InvalidAssistantFileData",
|
8102
7976
|
message: "File data cannot be a URL"
|
8103
7977
|
});
|
@@ -8231,7 +8105,7 @@ function customProvider({
|
|
8231
8105
|
var experimental_customProvider = customProvider;
|
8232
8106
|
|
8233
8107
|
// core/registry/no-such-provider-error.ts
|
8234
|
-
import { AISDKError as
|
8108
|
+
import { AISDKError as AISDKError21, NoSuchModelError as NoSuchModelError3 } from "@ai-sdk/provider";
|
8235
8109
|
var name16 = "AI_NoSuchProviderError";
|
8236
8110
|
var marker16 = `vercel.ai.error.${name16}`;
|
8237
8111
|
var symbol16 = Symbol.for(marker16);
|
@@ -8250,7 +8124,7 @@ var NoSuchProviderError = class extends NoSuchModelError3 {
|
|
8250
8124
|
this.availableProviders = availableProviders;
|
8251
8125
|
}
|
8252
8126
|
static isInstance(error) {
|
8253
|
-
return
|
8127
|
+
return AISDKError21.hasMarker(error, marker16);
|
8254
8128
|
}
|
8255
8129
|
};
|
8256
8130
|
_a16 = symbol16;
|
@@ -8941,172 +8815,6 @@ function simulateReadableStream({
|
|
8941
8815
|
});
|
8942
8816
|
}
|
8943
8817
|
|
8944
|
-
// streams/langchain-adapter.ts
|
8945
|
-
var langchain_adapter_exports = {};
|
8946
|
-
__export(langchain_adapter_exports, {
|
8947
|
-
mergeIntoDataStream: () => mergeIntoDataStream,
|
8948
|
-
toDataStream: () => toDataStream,
|
8949
|
-
toDataStreamResponse: () => toDataStreamResponse
|
8950
|
-
});
|
8951
|
-
|
8952
|
-
// streams/stream-callbacks.ts
|
8953
|
-
function createCallbacksTransformer(callbacks = {}) {
|
8954
|
-
const textEncoder = new TextEncoder();
|
8955
|
-
let aggregatedResponse = "";
|
8956
|
-
return new TransformStream({
|
8957
|
-
async start() {
|
8958
|
-
if (callbacks.onStart)
|
8959
|
-
await callbacks.onStart();
|
8960
|
-
},
|
8961
|
-
async transform(message, controller) {
|
8962
|
-
controller.enqueue(textEncoder.encode(message));
|
8963
|
-
aggregatedResponse += message;
|
8964
|
-
if (callbacks.onToken)
|
8965
|
-
await callbacks.onToken(message);
|
8966
|
-
if (callbacks.onText && typeof message === "string") {
|
8967
|
-
await callbacks.onText(message);
|
8968
|
-
}
|
8969
|
-
},
|
8970
|
-
async flush() {
|
8971
|
-
if (callbacks.onCompletion) {
|
8972
|
-
await callbacks.onCompletion(aggregatedResponse);
|
8973
|
-
}
|
8974
|
-
if (callbacks.onFinal) {
|
8975
|
-
await callbacks.onFinal(aggregatedResponse);
|
8976
|
-
}
|
8977
|
-
}
|
8978
|
-
});
|
8979
|
-
}
|
8980
|
-
|
8981
|
-
// streams/langchain-adapter.ts
|
8982
|
-
function toDataStreamInternal(stream, callbacks) {
|
8983
|
-
return stream.pipeThrough(
|
8984
|
-
new TransformStream({
|
8985
|
-
transform: async (value, controller) => {
|
8986
|
-
var _a17;
|
8987
|
-
if (typeof value === "string") {
|
8988
|
-
controller.enqueue(value);
|
8989
|
-
return;
|
8990
|
-
}
|
8991
|
-
if ("event" in value) {
|
8992
|
-
if (value.event === "on_chat_model_stream") {
|
8993
|
-
forwardAIMessageChunk(
|
8994
|
-
(_a17 = value.data) == null ? void 0 : _a17.chunk,
|
8995
|
-
controller
|
8996
|
-
);
|
8997
|
-
}
|
8998
|
-
return;
|
8999
|
-
}
|
9000
|
-
forwardAIMessageChunk(value, controller);
|
9001
|
-
}
|
9002
|
-
})
|
9003
|
-
).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(new TextDecoderStream()).pipeThrough(
|
9004
|
-
new TransformStream({
|
9005
|
-
transform: async (chunk, controller) => {
|
9006
|
-
controller.enqueue(formatDataStreamPart("text", chunk));
|
9007
|
-
}
|
9008
|
-
})
|
9009
|
-
);
|
9010
|
-
}
|
9011
|
-
function toDataStream(stream, callbacks) {
|
9012
|
-
return toDataStreamInternal(stream, callbacks).pipeThrough(
|
9013
|
-
new TextEncoderStream()
|
9014
|
-
);
|
9015
|
-
}
|
9016
|
-
function toDataStreamResponse(stream, options) {
|
9017
|
-
var _a17;
|
9018
|
-
const dataStream = toDataStreamInternal(
|
9019
|
-
stream,
|
9020
|
-
options == null ? void 0 : options.callbacks
|
9021
|
-
).pipeThrough(new TextEncoderStream());
|
9022
|
-
const data = options == null ? void 0 : options.data;
|
9023
|
-
const init = options == null ? void 0 : options.init;
|
9024
|
-
const responseStream = data ? mergeStreams(data.stream, dataStream) : dataStream;
|
9025
|
-
return new Response(responseStream, {
|
9026
|
-
status: (_a17 = init == null ? void 0 : init.status) != null ? _a17 : 200,
|
9027
|
-
statusText: init == null ? void 0 : init.statusText,
|
9028
|
-
headers: prepareResponseHeaders(init == null ? void 0 : init.headers, {
|
9029
|
-
contentType: "text/plain; charset=utf-8",
|
9030
|
-
dataStreamVersion: "v1"
|
9031
|
-
})
|
9032
|
-
});
|
9033
|
-
}
|
9034
|
-
function mergeIntoDataStream(stream, options) {
|
9035
|
-
options.dataStream.merge(toDataStreamInternal(stream, options.callbacks));
|
9036
|
-
}
|
9037
|
-
function forwardAIMessageChunk(chunk, controller) {
|
9038
|
-
if (typeof chunk.content === "string") {
|
9039
|
-
controller.enqueue(chunk.content);
|
9040
|
-
} else {
|
9041
|
-
const content = chunk.content;
|
9042
|
-
for (const item of content) {
|
9043
|
-
if (item.type === "text") {
|
9044
|
-
controller.enqueue(item.text);
|
9045
|
-
}
|
9046
|
-
}
|
9047
|
-
}
|
9048
|
-
}
|
9049
|
-
|
9050
|
-
// streams/llamaindex-adapter.ts
|
9051
|
-
var llamaindex_adapter_exports = {};
|
9052
|
-
__export(llamaindex_adapter_exports, {
|
9053
|
-
mergeIntoDataStream: () => mergeIntoDataStream2,
|
9054
|
-
toDataStream: () => toDataStream2,
|
9055
|
-
toDataStreamResponse: () => toDataStreamResponse2
|
9056
|
-
});
|
9057
|
-
import { convertAsyncIteratorToReadableStream } from "@ai-sdk/provider-utils";
|
9058
|
-
function toDataStreamInternal2(stream, callbacks) {
|
9059
|
-
const trimStart = trimStartOfStream();
|
9060
|
-
return convertAsyncIteratorToReadableStream(stream[Symbol.asyncIterator]()).pipeThrough(
|
9061
|
-
new TransformStream({
|
9062
|
-
async transform(message, controller) {
|
9063
|
-
controller.enqueue(trimStart(message.delta));
|
9064
|
-
}
|
9065
|
-
})
|
9066
|
-
).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(new TextDecoderStream()).pipeThrough(
|
9067
|
-
new TransformStream({
|
9068
|
-
transform: async (chunk, controller) => {
|
9069
|
-
controller.enqueue(formatDataStreamPart("text", chunk));
|
9070
|
-
}
|
9071
|
-
})
|
9072
|
-
);
|
9073
|
-
}
|
9074
|
-
function toDataStream2(stream, callbacks) {
|
9075
|
-
return toDataStreamInternal2(stream, callbacks).pipeThrough(
|
9076
|
-
new TextEncoderStream()
|
9077
|
-
);
|
9078
|
-
}
|
9079
|
-
function toDataStreamResponse2(stream, options = {}) {
|
9080
|
-
var _a17;
|
9081
|
-
const { init, data, callbacks } = options;
|
9082
|
-
const dataStream = toDataStreamInternal2(stream, callbacks).pipeThrough(
|
9083
|
-
new TextEncoderStream()
|
9084
|
-
);
|
9085
|
-
const responseStream = data ? mergeStreams(data.stream, dataStream) : dataStream;
|
9086
|
-
return new Response(responseStream, {
|
9087
|
-
status: (_a17 = init == null ? void 0 : init.status) != null ? _a17 : 200,
|
9088
|
-
statusText: init == null ? void 0 : init.statusText,
|
9089
|
-
headers: prepareResponseHeaders(init == null ? void 0 : init.headers, {
|
9090
|
-
contentType: "text/plain; charset=utf-8",
|
9091
|
-
dataStreamVersion: "v1"
|
9092
|
-
})
|
9093
|
-
});
|
9094
|
-
}
|
9095
|
-
function mergeIntoDataStream2(stream, options) {
|
9096
|
-
options.dataStream.merge(toDataStreamInternal2(stream, options.callbacks));
|
9097
|
-
}
|
9098
|
-
function trimStartOfStream() {
|
9099
|
-
let isStreamStart = true;
|
9100
|
-
return (text2) => {
|
9101
|
-
if (isStreamStart) {
|
9102
|
-
text2 = text2.trimStart();
|
9103
|
-
if (text2)
|
9104
|
-
isStreamStart = false;
|
9105
|
-
}
|
9106
|
-
return text2;
|
9107
|
-
};
|
9108
|
-
}
|
9109
|
-
|
9110
8818
|
// util/constants.ts
|
9111
8819
|
var HANGING_STREAM_WARNING_TIME_MS = 15 * 1e3;
|
9112
8820
|
|
@@ -9185,8 +8893,6 @@ export {
|
|
9185
8893
|
InvalidStreamPartError,
|
9186
8894
|
InvalidToolArgumentsError,
|
9187
8895
|
JSONParseError2 as JSONParseError,
|
9188
|
-
langchain_adapter_exports as LangChainAdapter,
|
9189
|
-
llamaindex_adapter_exports as LlamaIndexAdapter,
|
9190
8896
|
LoadAPIKeyError,
|
9191
8897
|
MCPClientError,
|
9192
8898
|
MessageConversionError,
|