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/dist/index.js CHANGED
@@ -42,8 +42,6 @@ __export(ai_exports, {
42
42
  InvalidStreamPartError: () => InvalidStreamPartError,
43
43
  InvalidToolArgumentsError: () => InvalidToolArgumentsError,
44
44
  JSONParseError: () => import_provider21.JSONParseError,
45
- LangChainAdapter: () => langchain_adapter_exports,
46
- LlamaIndexAdapter: () => llamaindex_adapter_exports,
47
45
  LoadAPIKeyError: () => import_provider21.LoadAPIKeyError,
48
46
  MCPClientError: () => MCPClientError,
49
47
  MessageConversionError: () => MessageConversionError,
@@ -461,15 +459,15 @@ function fixJson(input) {
461
459
  }
462
460
 
463
461
  // core/util/parse-partial-json.ts
464
- function parsePartialJson(jsonText) {
462
+ async function parsePartialJson(jsonText) {
465
463
  if (jsonText === void 0) {
466
464
  return { value: void 0, state: "undefined-input" };
467
465
  }
468
- let result = (0, import_provider_utils.safeParseJSON)({ text: jsonText });
466
+ let result = await (0, import_provider_utils.safeParseJSON)({ text: jsonText });
469
467
  if (result.success) {
470
468
  return { value: result.value, state: "successful-parse" };
471
469
  }
472
- result = (0, import_provider_utils.safeParseJSON)({ text: fixJson(jsonText) });
470
+ result = await (0, import_provider_utils.safeParseJSON)({ text: fixJson(jsonText) });
473
471
  if (result.success) {
474
472
  return { value: result.value, state: "repaired-parse" };
475
473
  }
@@ -650,10 +648,18 @@ var reasoningStreamPart = {
650
648
  code: "g",
651
649
  name: "reasoning",
652
650
  parse: (value) => {
653
- if (typeof value !== "string") {
654
- throw new Error('"reasoning" parts expect a string value.');
651
+ if (value == null || typeof value !== "object" || !("text" in value) || typeof value.text !== "string" || "providerMetadata" in value && typeof value.providerMetadata !== "object") {
652
+ throw new Error(
653
+ '"reasoning" parts expect an object with a "text" property.'
654
+ );
655
655
  }
656
- return { type: "reasoning", value };
656
+ return {
657
+ type: "reasoning",
658
+ value: {
659
+ text: value.text,
660
+ providerMetadata: value.providerMetadata
661
+ }
662
+ };
657
663
  }
658
664
  };
659
665
  var sourcePart = {
@@ -669,33 +675,6 @@ var sourcePart = {
669
675
  };
670
676
  }
671
677
  };
672
- var redactedReasoningStreamPart = {
673
- code: "i",
674
- name: "redacted_reasoning",
675
- parse: (value) => {
676
- if (value == null || typeof value !== "object" || !("data" in value) || typeof value.data !== "string") {
677
- throw new Error(
678
- '"redacted_reasoning" parts expect an object with a "data" property.'
679
- );
680
- }
681
- return { type: "redacted_reasoning", value: { data: value.data } };
682
- }
683
- };
684
- var reasoningSignatureStreamPart = {
685
- code: "j",
686
- name: "reasoning_signature",
687
- parse: (value) => {
688
- if (value == null || typeof value !== "object" || !("signature" in value) || typeof value.signature !== "string") {
689
- throw new Error(
690
- '"reasoning_signature" parts expect an object with a "signature" property.'
691
- );
692
- }
693
- return {
694
- type: "reasoning_signature",
695
- value: { signature: value.signature }
696
- };
697
- }
698
- };
699
678
  var fileStreamPart = {
700
679
  code: "k",
701
680
  name: "file",
@@ -708,6 +687,16 @@ var fileStreamPart = {
708
687
  return { type: "file", value };
709
688
  }
710
689
  };
690
+ var reasoningPartFinishStreamPart = {
691
+ code: "l",
692
+ name: "reasoning_part_finish",
693
+ parse: () => {
694
+ return {
695
+ type: "reasoning_part_finish",
696
+ value: {}
697
+ };
698
+ }
699
+ };
711
700
  var dataStreamParts = [
712
701
  textStreamPart,
713
702
  dataStreamPart,
@@ -722,8 +711,7 @@ var dataStreamParts = [
722
711
  startStepStreamPart,
723
712
  reasoningStreamPart,
724
713
  sourcePart,
725
- redactedReasoningStreamPart,
726
- reasoningSignatureStreamPart,
714
+ reasoningPartFinishStreamPart,
727
715
  fileStreamPart
728
716
  ];
729
717
  var dataStreamPartsByCode = Object.fromEntries(
@@ -772,8 +760,7 @@ async function processDataStream({
772
760
  stream,
773
761
  onTextPart,
774
762
  onReasoningPart,
775
- onReasoningSignaturePart,
776
- onRedactedReasoningPart,
763
+ onReasoningPartFinish,
777
764
  onSourcePart,
778
765
  onFilePart,
779
766
  onDataPart,
@@ -814,11 +801,8 @@ async function processDataStream({
814
801
  case "reasoning":
815
802
  await (onReasoningPart == null ? void 0 : onReasoningPart(value2));
816
803
  break;
817
- case "reasoning_signature":
818
- await (onReasoningSignaturePart == null ? void 0 : onReasoningSignaturePart(value2));
819
- break;
820
- case "redacted_reasoning":
821
- await (onRedactedReasoningPart == null ? void 0 : onRedactedReasoningPart(value2));
804
+ case "reasoning_part_finish":
805
+ await (onReasoningPartFinish == null ? void 0 : onReasoningPartFinish(value2));
822
806
  break;
823
807
  case "file":
824
808
  await (onFilePart == null ? void 0 : onFilePart(value2));
@@ -891,7 +875,6 @@ async function processChatResponse({
891
875
  };
892
876
  let currentTextPart = void 0;
893
877
  let currentReasoningPart = void 0;
894
- let currentReasoningTextDetail = void 0;
895
878
  function updateToolInvocationPart(toolCallId, invocation) {
896
879
  const part = message.parts.find(
897
880
  (part2) => part2.type === "tool-invocation" && part2.toolInvocation.toolCallId === toolCallId
@@ -953,48 +936,25 @@ async function processChatResponse({
953
936
  },
954
937
  onReasoningPart(value) {
955
938
  var _a18;
956
- if (currentReasoningTextDetail == null) {
957
- currentReasoningTextDetail = { type: "text", text: value };
958
- if (currentReasoningPart != null) {
959
- currentReasoningPart.details.push(currentReasoningTextDetail);
960
- }
961
- } else {
962
- currentReasoningTextDetail.text += value;
963
- }
964
939
  if (currentReasoningPart == null) {
965
940
  currentReasoningPart = {
966
941
  type: "reasoning",
967
- reasoning: value,
968
- details: [currentReasoningTextDetail]
942
+ reasoning: value.text,
943
+ providerMetadata: value.providerMetadata
969
944
  };
970
945
  message.parts.push(currentReasoningPart);
971
946
  } else {
972
- currentReasoningPart.reasoning += value;
947
+ currentReasoningPart.reasoning += value.text;
948
+ currentReasoningPart.providerMetadata = value.providerMetadata;
973
949
  }
974
- message.reasoning = ((_a18 = message.reasoning) != null ? _a18 : "") + value;
950
+ message.reasoning = ((_a18 = message.reasoning) != null ? _a18 : "") + value.text;
975
951
  execUpdate();
976
952
  },
977
- onReasoningSignaturePart(value) {
978
- if (currentReasoningTextDetail != null) {
979
- currentReasoningTextDetail.signature = value.signature;
953
+ onReasoningPartFinish(value) {
954
+ if (currentReasoningPart != null) {
955
+ currentReasoningPart = void 0;
980
956
  }
981
957
  },
982
- onRedactedReasoningPart(value) {
983
- if (currentReasoningPart == null) {
984
- currentReasoningPart = {
985
- type: "reasoning",
986
- reasoning: "",
987
- details: []
988
- };
989
- message.parts.push(currentReasoningPart);
990
- }
991
- currentReasoningPart.details.push({
992
- type: "redacted",
993
- data: value.data
994
- });
995
- currentReasoningTextDetail = void 0;
996
- execUpdate();
997
- },
998
958
  onFilePart(value) {
999
959
  message.parts.push({
1000
960
  type: "file",
@@ -1031,10 +991,12 @@ async function processChatResponse({
1031
991
  updateToolInvocationPart(value.toolCallId, invocation);
1032
992
  execUpdate();
1033
993
  },
1034
- onToolCallDeltaPart(value) {
994
+ async onToolCallDeltaPart(value) {
1035
995
  const partialToolCall = partialToolCalls[value.toolCallId];
1036
996
  partialToolCall.text += value.argsTextDelta;
1037
- const { value: partialArgs } = parsePartialJson(partialToolCall.text);
997
+ const { value: partialArgs } = await parsePartialJson(
998
+ partialToolCall.text
999
+ );
1038
1000
  const invocation = {
1039
1001
  state: "partial-call",
1040
1002
  step: partialToolCall.step,
@@ -1115,7 +1077,6 @@ async function processChatResponse({
1115
1077
  step += 1;
1116
1078
  currentTextPart = value.isContinued ? currentTextPart : void 0;
1117
1079
  currentReasoningPart = void 0;
1118
- currentReasoningTextDetail = void 0;
1119
1080
  },
1120
1081
  onStartStepPart(value) {
1121
1082
  if (!replaceLastMessage) {
@@ -1412,8 +1373,7 @@ function getMessageParts(message) {
1412
1373
  ...message.reasoning ? [
1413
1374
  {
1414
1375
  type: "reasoning",
1415
- reasoning: message.reasoning,
1416
- details: [{ type: "text", text: message.reasoning }]
1376
+ reasoning: message.reasoning
1417
1377
  }
1418
1378
  ] : [],
1419
1379
  ...message.content ? [{ type: "text", text: message.content }] : []
@@ -2989,14 +2949,6 @@ function convertToLanguageModelMessage(message, downloadedAssets) {
2989
2949
  return {
2990
2950
  type: "reasoning",
2991
2951
  text: part.text,
2992
- signature: part.signature,
2993
- providerOptions
2994
- };
2995
- }
2996
- case "redacted-reasoning": {
2997
- return {
2998
- type: "redacted-reasoning",
2999
- data: part.data,
3000
2952
  providerOptions
3001
2953
  };
3002
2954
  }
@@ -3390,23 +3342,11 @@ function convertToCoreMessages(messages, options) {
3390
3342
  break;
3391
3343
  }
3392
3344
  case "reasoning": {
3393
- for (const detail of part.details) {
3394
- switch (detail.type) {
3395
- case "text":
3396
- content2.push({
3397
- type: "reasoning",
3398
- text: detail.text,
3399
- signature: detail.signature
3400
- });
3401
- break;
3402
- case "redacted":
3403
- content2.push({
3404
- type: "redacted-reasoning",
3405
- data: detail.data
3406
- });
3407
- break;
3408
- }
3409
- }
3345
+ content2.push({
3346
+ type: "reasoning",
3347
+ text: part.reasoning,
3348
+ providerOptions: part.providerMetadata
3349
+ });
3410
3350
  break;
3411
3351
  }
3412
3352
  case "tool-invocation":
@@ -3676,11 +3616,6 @@ var reasoningPartSchema = import_zod5.z.object({
3676
3616
  text: import_zod5.z.string(),
3677
3617
  providerOptions: providerMetadataSchema.optional()
3678
3618
  });
3679
- var redactedReasoningPartSchema = import_zod5.z.object({
3680
- type: import_zod5.z.literal("redacted-reasoning"),
3681
- data: import_zod5.z.string(),
3682
- providerOptions: providerMetadataSchema.optional()
3683
- });
3684
3619
  var toolCallPartSchema = import_zod5.z.object({
3685
3620
  type: import_zod5.z.literal("tool-call"),
3686
3621
  toolCallId: import_zod5.z.string(),
@@ -3721,7 +3656,6 @@ var coreAssistantMessageSchema = import_zod6.z.object({
3721
3656
  textPartSchema,
3722
3657
  filePartSchema,
3723
3658
  reasoningPartSchema,
3724
- redactedReasoningPartSchema,
3725
3659
  toolCallPartSchema
3726
3660
  ])
3727
3661
  )
@@ -3741,7 +3675,7 @@ var coreMessageSchema = import_zod6.z.union([
3741
3675
  ]);
3742
3676
 
3743
3677
  // core/prompt/standardize-prompt.ts
3744
- function standardizePrompt({
3678
+ async function standardizePrompt({
3745
3679
  prompt,
3746
3680
  tools
3747
3681
  }) {
@@ -3798,7 +3732,7 @@ function standardizePrompt({
3798
3732
  message: "messages must not be empty"
3799
3733
  });
3800
3734
  }
3801
- const validationResult = (0, import_provider_utils11.safeValidateTypes)({
3735
+ const validationResult = await (0, import_provider_utils11.safeValidateTypes)({
3802
3736
  value: messages,
3803
3737
  schema: import_zod7.z.array(coreMessageSchema)
3804
3738
  });
@@ -3860,10 +3794,10 @@ function createAsyncIterableStream(source) {
3860
3794
  var noSchemaOutputStrategy = {
3861
3795
  type: "no-schema",
3862
3796
  jsonSchema: void 0,
3863
- validatePartialResult({ value, textDelta }) {
3797
+ async validatePartialResult({ value, textDelta }) {
3864
3798
  return { success: true, value: { partial: value, textDelta } };
3865
3799
  },
3866
- validateFinalResult(value, context) {
3800
+ async validateFinalResult(value, context) {
3867
3801
  return value === void 0 ? {
3868
3802
  success: false,
3869
3803
  error: new NoObjectGeneratedError({
@@ -3884,7 +3818,7 @@ var noSchemaOutputStrategy = {
3884
3818
  var objectOutputStrategy = (schema) => ({
3885
3819
  type: "object",
3886
3820
  jsonSchema: schema.jsonSchema,
3887
- validatePartialResult({ value, textDelta }) {
3821
+ async validatePartialResult({ value, textDelta }) {
3888
3822
  return {
3889
3823
  success: true,
3890
3824
  value: {
@@ -3894,7 +3828,7 @@ var objectOutputStrategy = (schema) => ({
3894
3828
  }
3895
3829
  };
3896
3830
  },
3897
- validateFinalResult(value) {
3831
+ async validateFinalResult(value) {
3898
3832
  return (0, import_provider_utils12.safeValidateTypes)({ value, schema });
3899
3833
  },
3900
3834
  createElementStream() {
@@ -3919,7 +3853,12 @@ var arrayOutputStrategy = (schema) => {
3919
3853
  required: ["elements"],
3920
3854
  additionalProperties: false
3921
3855
  },
3922
- validatePartialResult({ value, latestObject, isFirstDelta, isFinalDelta }) {
3856
+ async validatePartialResult({
3857
+ value,
3858
+ latestObject,
3859
+ isFirstDelta,
3860
+ isFinalDelta
3861
+ }) {
3923
3862
  var _a17;
3924
3863
  if (!(0, import_provider12.isJSONObject)(value) || !(0, import_provider12.isJSONArray)(value.elements)) {
3925
3864
  return {
@@ -3934,7 +3873,7 @@ var arrayOutputStrategy = (schema) => {
3934
3873
  const resultArray = [];
3935
3874
  for (let i = 0; i < inputArray.length; i++) {
3936
3875
  const element = inputArray[i];
3937
- const result = (0, import_provider_utils12.safeValidateTypes)({ value: element, schema });
3876
+ const result = await (0, import_provider_utils12.safeValidateTypes)({ value: element, schema });
3938
3877
  if (i === inputArray.length - 1 && !isFinalDelta) {
3939
3878
  continue;
3940
3879
  }
@@ -3963,7 +3902,7 @@ var arrayOutputStrategy = (schema) => {
3963
3902
  }
3964
3903
  };
3965
3904
  },
3966
- validateFinalResult(value) {
3905
+ async validateFinalResult(value) {
3967
3906
  if (!(0, import_provider12.isJSONObject)(value) || !(0, import_provider12.isJSONArray)(value.elements)) {
3968
3907
  return {
3969
3908
  success: false,
@@ -3975,7 +3914,7 @@ var arrayOutputStrategy = (schema) => {
3975
3914
  }
3976
3915
  const inputArray = value.elements;
3977
3916
  for (const element of inputArray) {
3978
- const result = (0, import_provider_utils12.safeValidateTypes)({ value: element, schema });
3917
+ const result = await (0, import_provider_utils12.safeValidateTypes)({ value: element, schema });
3979
3918
  if (!result.success) {
3980
3919
  return result;
3981
3920
  }
@@ -4029,7 +3968,7 @@ var enumOutputStrategy = (enumValues) => {
4029
3968
  required: ["result"],
4030
3969
  additionalProperties: false
4031
3970
  },
4032
- validateFinalResult(value) {
3971
+ async validateFinalResult(value) {
4033
3972
  if (!(0, import_provider12.isJSONObject)(value) || typeof value.result !== "string") {
4034
3973
  return {
4035
3974
  success: false,
@@ -4274,9 +4213,8 @@ async function generateObject({
4274
4213
  let warnings;
4275
4214
  let response;
4276
4215
  let request;
4277
- let logprobs;
4278
4216
  let resultProviderMetadata;
4279
- const standardizedPrompt = standardizePrompt({
4217
+ const standardizedPrompt = await standardizePrompt({
4280
4218
  prompt: { system, prompt, messages },
4281
4219
  tools: void 0
4282
4220
  });
@@ -4374,12 +4312,11 @@ async function generateObject({
4374
4312
  finishReason = generateResult.finishReason;
4375
4313
  usage = generateResult.usage;
4376
4314
  warnings = generateResult.warnings;
4377
- logprobs = generateResult.logprobs;
4378
4315
  resultProviderMetadata = generateResult.providerMetadata;
4379
4316
  request = (_a17 = generateResult.request) != null ? _a17 : {};
4380
4317
  response = generateResult.responseData;
4381
- function processResult(result2) {
4382
- const parseResult = (0, import_provider_utils13.safeParseJSON)({ text: result2 });
4318
+ async function processResult(result2) {
4319
+ const parseResult = await (0, import_provider_utils13.safeParseJSON)({ text: result2 });
4383
4320
  if (!parseResult.success) {
4384
4321
  throw new NoObjectGeneratedError({
4385
4322
  message: "No object generated: could not parse the response.",
@@ -4390,7 +4327,7 @@ async function generateObject({
4390
4327
  finishReason
4391
4328
  });
4392
4329
  }
4393
- const validationResult = outputStrategy.validateFinalResult(
4330
+ const validationResult = await outputStrategy.validateFinalResult(
4394
4331
  parseResult.value,
4395
4332
  {
4396
4333
  text: result2,
@@ -4412,7 +4349,7 @@ async function generateObject({
4412
4349
  }
4413
4350
  let object2;
4414
4351
  try {
4415
- object2 = processResult(result);
4352
+ object2 = await processResult(result);
4416
4353
  } catch (error) {
4417
4354
  if (repairText != null && NoObjectGeneratedError.isInstance(error) && (import_provider13.JSONParseError.isInstance(error.cause) || import_provider13.TypeValidationError.isInstance(error.cause))) {
4418
4355
  const repairedText = await repairText({
@@ -4422,7 +4359,7 @@ async function generateObject({
4422
4359
  if (repairedText === null) {
4423
4360
  throw error;
4424
4361
  }
4425
- object2 = processResult(repairedText);
4362
+ object2 = await processResult(repairedText);
4426
4363
  } else {
4427
4364
  throw error;
4428
4365
  }
@@ -4448,7 +4385,6 @@ async function generateObject({
4448
4385
  warnings,
4449
4386
  request,
4450
4387
  response,
4451
- logprobs,
4452
4388
  providerMetadata: resultProviderMetadata
4453
4389
  });
4454
4390
  }
@@ -4463,7 +4399,6 @@ var DefaultGenerateObjectResult = class {
4463
4399
  this.providerMetadata = options.providerMetadata;
4464
4400
  this.response = options.response;
4465
4401
  this.request = options.request;
4466
- this.logprobs = options.logprobs;
4467
4402
  }
4468
4403
  toJsonResponse(init) {
4469
4404
  var _a17;
@@ -4745,7 +4680,7 @@ var DefaultStreamObjectResult = class {
4745
4680
  tracer,
4746
4681
  endWhenDone: false,
4747
4682
  fn: async (rootSpan) => {
4748
- const standardizedPrompt = standardizePrompt({
4683
+ const standardizedPrompt = await standardizePrompt({
4749
4684
  prompt: { system, prompt, messages },
4750
4685
  tools: void 0
4751
4686
  });
@@ -4860,9 +4795,9 @@ var DefaultStreamObjectResult = class {
4860
4795
  if (typeof chunk === "string") {
4861
4796
  accumulatedText += chunk;
4862
4797
  textDelta += chunk;
4863
- const { value: currentObjectJson, state: parseState } = parsePartialJson(accumulatedText);
4798
+ const { value: currentObjectJson, state: parseState } = await parsePartialJson(accumulatedText);
4864
4799
  if (currentObjectJson !== void 0 && !isDeepEqualData(latestObjectJson, currentObjectJson)) {
4865
- const validationResult = outputStrategy.validatePartialResult({
4800
+ const validationResult = await outputStrategy.validatePartialResult({
4866
4801
  value: currentObjectJson,
4867
4802
  textDelta,
4868
4803
  latestObject,
@@ -4916,7 +4851,7 @@ var DefaultStreamObjectResult = class {
4916
4851
  ...fullResponse,
4917
4852
  headers: response == null ? void 0 : response.headers
4918
4853
  });
4919
- const validationResult = outputStrategy.validateFinalResult(
4854
+ const validationResult = await outputStrategy.validateFinalResult(
4920
4855
  latestObjectJson,
4921
4856
  {
4922
4857
  text: accumulatedText,
@@ -5354,7 +5289,7 @@ async function doParseToolCall({
5354
5289
  });
5355
5290
  }
5356
5291
  const schema = asSchema(tool2.parameters);
5357
- const parseResult = toolCall.args.trim() === "" ? (0, import_provider_utils15.safeValidateTypes)({ value: {}, schema }) : (0, import_provider_utils15.safeParseJSON)({ text: toolCall.args, schema });
5292
+ const parseResult = toolCall.args.trim() === "" ? await (0, import_provider_utils15.safeValidateTypes)({ value: {}, schema }) : await (0, import_provider_utils15.safeParseJSON)({ text: toolCall.args, schema });
5358
5293
  if (parseResult.success === false) {
5359
5294
  throw new InvalidToolArgumentsError({
5360
5295
  toolName,
@@ -5371,10 +5306,17 @@ async function doParseToolCall({
5371
5306
  }
5372
5307
 
5373
5308
  // core/generate-text/reasoning.ts
5374
- function asReasoningText(reasoning) {
5375
- const reasoningText = reasoning.filter((part) => part.type === "text").map((part) => part.text).join("");
5309
+ function asReasoningText(reasoningParts) {
5310
+ const reasoningText = reasoningParts.map((part) => part.text).join("");
5376
5311
  return reasoningText.length > 0 ? reasoningText : void 0;
5377
5312
  }
5313
+ function convertReasoningContentToParts(content) {
5314
+ return content.filter((part) => part.type === "reasoning").map((part) => ({
5315
+ type: "reasoning",
5316
+ text: part.text,
5317
+ providerOptions: part.providerMetadata
5318
+ }));
5319
+ }
5378
5320
 
5379
5321
  // core/generate-text/to-response-messages.ts
5380
5322
  function toResponseMessages({
@@ -5389,12 +5331,8 @@ function toResponseMessages({
5389
5331
  }) {
5390
5332
  const responseMessages = [];
5391
5333
  const content = [];
5392
- if (reasoning.length > 0) {
5393
- content.push(
5394
- ...reasoning.map(
5395
- (part) => part.type === "text" ? { ...part, type: "reasoning" } : { ...part, type: "redacted-reasoning" }
5396
- )
5397
- );
5334
+ for (const part of reasoning) {
5335
+ content.push(part);
5398
5336
  }
5399
5337
  if (files.length > 0) {
5400
5338
  content.push(
@@ -5493,7 +5431,7 @@ async function generateText({
5493
5431
  headers,
5494
5432
  settings: { ...callSettings, maxRetries }
5495
5433
  });
5496
- const initialPrompt = standardizePrompt({
5434
+ const initialPrompt = await standardizePrompt({
5497
5435
  prompt: { system, prompt, messages },
5498
5436
  tools
5499
5437
  });
@@ -5524,7 +5462,7 @@ async function generateText({
5524
5462
  let currentModelResponse;
5525
5463
  let currentToolCalls = [];
5526
5464
  let currentToolResults = [];
5527
- let currentReasoningDetails = [];
5465
+ let currentReasoning = [];
5528
5466
  let stepCount = 0;
5529
5467
  const responseMessages = [];
5530
5468
  let text2 = "";
@@ -5686,7 +5624,7 @@ async function generateText({
5686
5624
  text2.trimEnd() !== text2 ? originalText.trimStart() : originalText;
5687
5625
  const stepText = nextStepType === "continue" ? removeTextAfterLastWhitespace(stepTextLeadingWhitespaceTrimmed) : stepTextLeadingWhitespaceTrimmed;
5688
5626
  text2 = nextStepType === "continue" || stepType === "continue" ? text2 + stepText : stepText;
5689
- currentReasoningDetails = asReasoningDetails(
5627
+ currentReasoning = convertReasoningContentToParts(
5690
5628
  currentModelResponse.content
5691
5629
  );
5692
5630
  sources.push(
@@ -5709,7 +5647,9 @@ async function generateText({
5709
5647
  ...toResponseMessages({
5710
5648
  text: text2,
5711
5649
  files: asFiles(currentModelResponse.content),
5712
- reasoning: asReasoningDetails(currentModelResponse.content),
5650
+ reasoning: convertReasoningContentToParts(
5651
+ currentModelResponse.content
5652
+ ),
5713
5653
  tools: tools != null ? tools : {},
5714
5654
  toolCalls: currentToolCalls,
5715
5655
  toolResults: currentToolResults,
@@ -5721,8 +5661,8 @@ async function generateText({
5721
5661
  const currentStepResult = {
5722
5662
  stepType,
5723
5663
  text: stepText,
5724
- reasoningText: asReasoningText(currentReasoningDetails),
5725
- reasoning: currentReasoningDetails,
5664
+ reasoningText: asReasoningText(currentReasoning),
5665
+ reasoning: currentReasoning,
5726
5666
  files: asFiles(currentModelResponse.content),
5727
5667
  sources: currentModelResponse.content.filter(
5728
5668
  (part) => part.type === "source"
@@ -5732,7 +5672,6 @@ async function generateText({
5732
5672
  finishReason: currentModelResponse.finishReason,
5733
5673
  usage: currentUsage,
5734
5674
  warnings: currentModelResponse.warnings,
5735
- logprobs: currentModelResponse.logprobs,
5736
5675
  request: (_b = currentModelResponse.request) != null ? _b : {},
5737
5676
  response: {
5738
5677
  ...currentModelResponse.response,
@@ -5766,25 +5705,21 @@ async function generateText({
5766
5705
  }
5767
5706
  })
5768
5707
  );
5708
+ const resolvedOutput = await (output == null ? void 0 : output.parseOutput(
5709
+ { text: text2 },
5710
+ {
5711
+ response: currentModelResponse.response,
5712
+ usage,
5713
+ finishReason: currentModelResponse.finishReason
5714
+ }
5715
+ ));
5769
5716
  return new DefaultGenerateTextResult({
5770
5717
  text: text2,
5771
5718
  files: asFiles(currentModelResponse.content),
5772
- reasoning: asReasoningText(currentReasoningDetails),
5773
- reasoningDetails: currentReasoningDetails,
5719
+ reasoning: asReasoningText(currentReasoning),
5720
+ reasoningDetails: currentReasoning,
5774
5721
  sources,
5775
- outputResolver: () => {
5776
- if (output == null) {
5777
- throw new NoOutputSpecifiedError();
5778
- }
5779
- return output.parseOutput(
5780
- { text: text2 },
5781
- {
5782
- response: currentModelResponse.response,
5783
- usage,
5784
- finishReason: currentModelResponse.finishReason
5785
- }
5786
- );
5787
- },
5722
+ resolvedOutput,
5788
5723
  toolCalls: currentToolCalls,
5789
5724
  toolResults: currentToolResults,
5790
5725
  finishReason: currentModelResponse.finishReason,
@@ -5795,7 +5730,6 @@ async function generateText({
5795
5730
  ...currentModelResponse.response,
5796
5731
  messages: responseMessages
5797
5732
  },
5798
- logprobs: currentModelResponse.logprobs,
5799
5733
  steps,
5800
5734
  providerMetadata: currentModelResponse.providerMetadata
5801
5735
  });
@@ -5892,42 +5826,16 @@ var DefaultGenerateTextResult = class {
5892
5826
  this.response = options.response;
5893
5827
  this.steps = options.steps;
5894
5828
  this.providerMetadata = options.providerMetadata;
5895
- this.logprobs = options.logprobs;
5896
- this.outputResolver = options.outputResolver;
5829
+ this.resolvedOutput = options.resolvedOutput;
5897
5830
  this.sources = options.sources;
5898
5831
  }
5899
5832
  get experimental_output() {
5900
- return this.outputResolver();
5901
- }
5902
- };
5903
- function asReasoningDetails(content) {
5904
- const reasoning = content.filter((part) => part.type === "reasoning");
5905
- if (reasoning.length === 0) {
5906
- return [];
5907
- }
5908
- const result = [];
5909
- let activeReasoningText;
5910
- for (const part of reasoning) {
5911
- if (part.reasoningType === "text") {
5912
- if (activeReasoningText == null) {
5913
- activeReasoningText = { type: "text", text: part.text };
5914
- result.push(activeReasoningText);
5915
- } else {
5916
- activeReasoningText.text += part.text;
5917
- }
5918
- } else if (part.reasoningType === "signature") {
5919
- if (activeReasoningText == null) {
5920
- activeReasoningText = { type: "text", text: "" };
5921
- result.push(activeReasoningText);
5922
- }
5923
- activeReasoningText.signature = part.signature;
5924
- activeReasoningText = void 0;
5925
- } else if (part.reasoningType === "redacted") {
5926
- result.push({ type: "redacted", data: part.data });
5833
+ if (this.resolvedOutput == null) {
5834
+ throw new NoOutputSpecifiedError();
5927
5835
  }
5836
+ return this.resolvedOutput;
5928
5837
  }
5929
- return result;
5930
- }
5838
+ };
5931
5839
  function asFiles(content) {
5932
5840
  return content.filter((part) => part.type === "file").map((part) => new DefaultGeneratedFile(part));
5933
5841
  }
@@ -6003,10 +5911,10 @@ _a15 = symbol15;
6003
5911
  var text = () => ({
6004
5912
  type: "text",
6005
5913
  responseFormat: { type: "text" },
6006
- parsePartial({ text: text2 }) {
5914
+ async parsePartial({ text: text2 }) {
6007
5915
  return { partial: text2 };
6008
5916
  },
6009
- parseOutput({ text: text2 }) {
5917
+ async parseOutput({ text: text2 }) {
6010
5918
  return text2;
6011
5919
  }
6012
5920
  });
@@ -6020,8 +5928,8 @@ var object = ({
6020
5928
  type: "json",
6021
5929
  schema: schema.jsonSchema
6022
5930
  },
6023
- parsePartial({ text: text2 }) {
6024
- const result = parsePartialJson(text2);
5931
+ async parsePartial({ text: text2 }) {
5932
+ const result = await parsePartialJson(text2);
6025
5933
  switch (result.state) {
6026
5934
  case "failed-parse":
6027
5935
  case "undefined-input":
@@ -6038,8 +5946,8 @@ var object = ({
6038
5946
  }
6039
5947
  }
6040
5948
  },
6041
- parseOutput({ text: text2 }, context) {
6042
- const parseResult = (0, import_provider_utils17.safeParseJSON)({ text: text2 });
5949
+ async parseOutput({ text: text2 }, context) {
5950
+ const parseResult = await (0, import_provider_utils17.safeParseJSON)({ text: text2 });
6043
5951
  if (!parseResult.success) {
6044
5952
  throw new NoObjectGeneratedError({
6045
5953
  message: "No object generated: could not parse the response.",
@@ -6050,7 +5958,7 @@ var object = ({
6050
5958
  finishReason: context.finishReason
6051
5959
  });
6052
5960
  }
6053
- const validationResult = (0, import_provider_utils17.safeValidateTypes)({
5961
+ const validationResult = await (0, import_provider_utils17.safeValidateTypes)({
6054
5962
  value: parseResult.value,
6055
5963
  schema
6056
5964
  });
@@ -6139,7 +6047,6 @@ function smoothStream({
6139
6047
  }
6140
6048
 
6141
6049
  // core/generate-text/stream-text.ts
6142
- var import_provider23 = require("@ai-sdk/provider");
6143
6050
  var import_provider_utils19 = require("@ai-sdk/provider-utils");
6144
6051
 
6145
6052
  // util/as-array.ts
@@ -6291,6 +6198,7 @@ function runToolsTransformation({
6291
6198
  case "stream-start":
6292
6199
  case "text":
6293
6200
  case "reasoning":
6201
+ case "reasoning-part-finish":
6294
6202
  case "source":
6295
6203
  case "response-metadata":
6296
6204
  case "error": {
@@ -6412,7 +6320,6 @@ function runToolsTransformation({
6412
6320
  finishChunk = {
6413
6321
  type: "finish",
6414
6322
  finishReason: chunk.finishReason,
6415
- logprobs: chunk.logprobs,
6416
6323
  usage: calculateLanguageModelUsage2(chunk.usage),
6417
6324
  providerMetadata: chunk.providerMetadata
6418
6325
  };
@@ -6549,7 +6456,7 @@ function createOutputTransformStream(output) {
6549
6456
  textChunk = "";
6550
6457
  }
6551
6458
  return new TransformStream({
6552
- transform(chunk, controller) {
6459
+ async transform(chunk, controller) {
6553
6460
  if (chunk.type === "step-finish") {
6554
6461
  publishTextChunk({ controller });
6555
6462
  }
@@ -6559,7 +6466,7 @@ function createOutputTransformStream(output) {
6559
6466
  }
6560
6467
  text2 += chunk.text;
6561
6468
  textChunk += chunk.text;
6562
- const result = output.parsePartial({ text: text2 });
6469
+ const result = await output.parsePartial({ text: text2 });
6563
6470
  if (result != null) {
6564
6471
  const currentJson = JSON.stringify(result.partial);
6565
6472
  if (currentJson !== lastPublishedJson) {
@@ -6632,7 +6539,7 @@ var DefaultStreamTextResult = class {
6632
6539
  let recordedFullText = "";
6633
6540
  let stepReasoning = [];
6634
6541
  let stepFiles = [];
6635
- let activeReasoningText = void 0;
6542
+ let activeReasoningPart = void 0;
6636
6543
  let recordedStepSources = [];
6637
6544
  const recordedSources = [];
6638
6545
  const recordedResponse = {
@@ -6664,26 +6571,21 @@ var DefaultStreamTextResult = class {
6664
6571
  recordedFullText += part.text;
6665
6572
  }
6666
6573
  if (part.type === "reasoning") {
6667
- if (part.reasoningType === "text") {
6668
- if (activeReasoningText == null) {
6669
- activeReasoningText = { type: "text", text: part.text };
6670
- stepReasoning.push(activeReasoningText);
6671
- } else {
6672
- activeReasoningText.text += part.text;
6673
- }
6674
- } else if (part.reasoningType === "signature") {
6675
- if (activeReasoningText == null) {
6676
- throw new import_provider23.AISDKError({
6677
- name: "InvalidStreamPart",
6678
- message: "reasoning-signature without reasoning"
6679
- });
6680
- }
6681
- activeReasoningText.signature = part.signature;
6682
- activeReasoningText = void 0;
6683
- } else if (part.reasoningType === "redacted") {
6684
- stepReasoning.push({ type: "redacted", data: part.data });
6574
+ if (activeReasoningPart == null) {
6575
+ activeReasoningPart = {
6576
+ type: "reasoning",
6577
+ text: part.text,
6578
+ providerOptions: part.providerMetadata
6579
+ };
6580
+ stepReasoning.push(activeReasoningPart);
6581
+ } else {
6582
+ activeReasoningPart.text += part.text;
6583
+ activeReasoningPart.providerOptions = part.providerMetadata;
6685
6584
  }
6686
6585
  }
6586
+ if (part.type === "reasoning-part-finish") {
6587
+ activeReasoningPart = void 0;
6588
+ }
6687
6589
  if (part.type === "file") {
6688
6590
  stepFiles.push(part.file);
6689
6591
  }
@@ -6734,7 +6636,6 @@ var DefaultStreamTextResult = class {
6734
6636
  finishReason: part.finishReason,
6735
6637
  usage: part.usage,
6736
6638
  warnings: part.warnings,
6737
- logprobs: part.logprobs,
6738
6639
  request: part.request,
6739
6640
  response: {
6740
6641
  ...part.response,
@@ -6751,7 +6652,7 @@ var DefaultStreamTextResult = class {
6751
6652
  recordedStepSources = [];
6752
6653
  stepReasoning = [];
6753
6654
  stepFiles = [];
6754
- activeReasoningText = void 0;
6655
+ activeReasoningPart = void 0;
6755
6656
  if (nextStepType !== "done") {
6756
6657
  stepType = nextStepType;
6757
6658
  }
@@ -6798,7 +6699,6 @@ var DefaultStreamTextResult = class {
6798
6699
  self.stepsPromise.resolve(recordedSteps);
6799
6700
  await (onFinish == null ? void 0 : onFinish({
6800
6701
  finishReason,
6801
- logprobs: void 0,
6802
6702
  usage,
6803
6703
  text: recordedFullText,
6804
6704
  reasoningText: lastStep.reasoningText,
@@ -6863,10 +6763,6 @@ var DefaultStreamTextResult = class {
6863
6763
  headers,
6864
6764
  settings: { ...callSettings, maxRetries }
6865
6765
  });
6866
- const initialPrompt = standardizePrompt({
6867
- prompt: { system, prompt, messages },
6868
- tools
6869
- });
6870
6766
  const self = this;
6871
6767
  recordSpan({
6872
6768
  name: "ai.streamText",
@@ -6895,6 +6791,10 @@ var DefaultStreamTextResult = class {
6895
6791
  hasLeadingWhitespace,
6896
6792
  messageId
6897
6793
  }) {
6794
+ const initialPrompt = await standardizePrompt({
6795
+ prompt: { system, prompt, messages },
6796
+ tools
6797
+ });
6898
6798
  const promptFormat = responseMessages.length === 0 ? initialPrompt.type : "messages";
6899
6799
  const stepInputMessages = [
6900
6800
  ...initialPrompt.messages,
@@ -6994,7 +6894,7 @@ var DefaultStreamTextResult = class {
6994
6894
  let warnings;
6995
6895
  const stepReasoning2 = [];
6996
6896
  const stepFiles2 = [];
6997
- let activeReasoningText2 = void 0;
6897
+ let activeReasoningPart2 = void 0;
6998
6898
  let stepFinishReason = "unknown";
6999
6899
  let stepUsage = {
7000
6900
  promptTokens: 0,
@@ -7005,7 +6905,6 @@ var DefaultStreamTextResult = class {
7005
6905
  let stepFirstChunk = true;
7006
6906
  let stepText = "";
7007
6907
  let fullStepText = stepType2 === "continue" ? previousStepText : "";
7008
- let stepLogProbs;
7009
6908
  let stepResponse = {
7010
6909
  id: generateId3(),
7011
6910
  timestamp: currentDate(),
@@ -7081,33 +6980,24 @@ var DefaultStreamTextResult = class {
7081
6980
  }
7082
6981
  case "reasoning": {
7083
6982
  controller.enqueue(chunk);
7084
- if (chunk.reasoningType === "text") {
7085
- if (activeReasoningText2 == null) {
7086
- activeReasoningText2 = {
7087
- type: "text",
7088
- text: chunk.text
7089
- };
7090
- stepReasoning2.push(activeReasoningText2);
7091
- } else {
7092
- activeReasoningText2.text += chunk.text;
7093
- }
7094
- } else if (chunk.reasoningType === "signature") {
7095
- if (activeReasoningText2 == null) {
7096
- throw new InvalidStreamPartError({
7097
- chunk,
7098
- message: "reasoning-signature without reasoning"
7099
- });
7100
- }
7101
- activeReasoningText2.signature = chunk.signature;
7102
- activeReasoningText2 = void 0;
7103
- } else if (chunk.reasoningType === "redacted") {
7104
- stepReasoning2.push({
7105
- type: "redacted",
7106
- data: chunk.data
7107
- });
6983
+ if (activeReasoningPart2 == null) {
6984
+ activeReasoningPart2 = {
6985
+ type: "reasoning",
6986
+ text: chunk.text,
6987
+ providerOptions: chunk.providerMetadata
6988
+ };
6989
+ stepReasoning2.push(activeReasoningPart2);
6990
+ } else {
6991
+ activeReasoningPart2.text += chunk.text;
6992
+ activeReasoningPart2.providerOptions = chunk.providerMetadata;
7108
6993
  }
7109
6994
  break;
7110
6995
  }
6996
+ case "reasoning-part-finish": {
6997
+ activeReasoningPart2 = void 0;
6998
+ controller.enqueue(chunk);
6999
+ break;
7000
+ }
7111
7001
  case "tool-call": {
7112
7002
  controller.enqueue(chunk);
7113
7003
  stepToolCalls.push(chunk);
@@ -7130,7 +7020,6 @@ var DefaultStreamTextResult = class {
7130
7020
  stepUsage = chunk.usage;
7131
7021
  stepFinishReason = chunk.finishReason;
7132
7022
  stepProviderMetadata = chunk.providerMetadata;
7133
- stepLogProbs = chunk.logprobs;
7134
7023
  const msToFinish = now2() - startTimestampMs;
7135
7024
  doStreamSpan.addEvent("ai.stream.finish");
7136
7025
  doStreamSpan.setAttributes({
@@ -7218,7 +7107,6 @@ var DefaultStreamTextResult = class {
7218
7107
  finishReason: stepFinishReason,
7219
7108
  usage: stepUsage,
7220
7109
  providerMetadata: stepProviderMetadata,
7221
- logprobs: stepLogProbs,
7222
7110
  request: stepRequest,
7223
7111
  response: {
7224
7112
  ...stepResponse,
@@ -7235,7 +7123,6 @@ var DefaultStreamTextResult = class {
7235
7123
  finishReason: stepFinishReason,
7236
7124
  usage: combinedUsage,
7237
7125
  providerMetadata: stepProviderMetadata,
7238
- logprobs: stepLogProbs,
7239
7126
  response: {
7240
7127
  ...stepResponse,
7241
7128
  headers: response == null ? void 0 : response.headers
@@ -7436,23 +7323,15 @@ var DefaultStreamTextResult = class {
7436
7323
  }
7437
7324
  case "reasoning": {
7438
7325
  if (sendReasoning) {
7439
- if (chunk.reasoningType === "text") {
7440
- controller.enqueue(
7441
- formatDataStreamPart("reasoning", chunk.text)
7442
- );
7443
- } else if (chunk.reasoningType === "signature") {
7444
- controller.enqueue(
7445
- formatDataStreamPart("reasoning_signature", {
7446
- signature: chunk.signature
7447
- })
7448
- );
7449
- } else if (chunk.reasoningType === "redacted") {
7450
- controller.enqueue(
7451
- formatDataStreamPart("redacted_reasoning", {
7452
- data: chunk.data
7453
- })
7454
- );
7455
- }
7326
+ controller.enqueue(formatDataStreamPart("reasoning", chunk));
7327
+ }
7328
+ break;
7329
+ }
7330
+ case "reasoning-part-finish": {
7331
+ if (sendReasoning) {
7332
+ controller.enqueue(
7333
+ formatDataStreamPart("reasoning_part_finish", {})
7334
+ );
7456
7335
  }
7457
7336
  break;
7458
7337
  }
@@ -7663,8 +7542,8 @@ var DefaultStreamTextResult = class {
7663
7542
  };
7664
7543
 
7665
7544
  // errors/no-speech-generated-error.ts
7666
- var import_provider24 = require("@ai-sdk/provider");
7667
- var NoSpeechGeneratedError = class extends import_provider24.AISDKError {
7545
+ var import_provider23 = require("@ai-sdk/provider");
7546
+ var NoSpeechGeneratedError = class extends import_provider23.AISDKError {
7668
7547
  constructor(options) {
7669
7548
  super({
7670
7549
  name: "AI_NoSpeechGeneratedError",
@@ -7753,8 +7632,8 @@ var DefaultSpeechResult = class {
7753
7632
  };
7754
7633
 
7755
7634
  // errors/no-transcript-generated-error.ts
7756
- var import_provider25 = require("@ai-sdk/provider");
7757
- var NoTranscriptGeneratedError = class extends import_provider25.AISDKError {
7635
+ var import_provider24 = require("@ai-sdk/provider");
7636
+ var NoTranscriptGeneratedError = class extends import_provider24.AISDKError {
7758
7637
  constructor(options) {
7759
7638
  super({
7760
7639
  name: "AI_NoTranscriptGeneratedError",
@@ -7942,7 +7821,6 @@ function extractReasoningMiddleware({
7942
7821
  }
7943
7822
  transformedContent.push({
7944
7823
  type: "reasoning",
7945
- reasoningType: "text",
7946
7824
  text: reasoningText
7947
7825
  });
7948
7826
  transformedContent.push({
@@ -7974,7 +7852,6 @@ function extractReasoningMiddleware({
7974
7852
  controller.enqueue(
7975
7853
  isReasoning ? {
7976
7854
  type: "reasoning",
7977
- reasoningType: "text",
7978
7855
  text: prefix + text2
7979
7856
  } : {
7980
7857
  type: "text",
@@ -8001,6 +7878,9 @@ function extractReasoningMiddleware({
8001
7878
  const foundFullMatch = startIndex + nextTag.length <= buffer.length;
8002
7879
  if (foundFullMatch) {
8003
7880
  buffer = buffer.slice(startIndex + nextTag.length);
7881
+ if (isReasoning) {
7882
+ controller.enqueue({ type: "reasoning-part-finish" });
7883
+ }
8004
7884
  isReasoning = !isReasoning;
8005
7885
  afterSwitch = true;
8006
7886
  } else {
@@ -8037,7 +7917,6 @@ function simulateStreamingMiddleware() {
8037
7917
  type: "finish",
8038
7918
  finishReason: result.finishReason,
8039
7919
  usage: result.usage,
8040
- logprobs: result.logprobs,
8041
7920
  providerMetadata: result.providerMetadata
8042
7921
  });
8043
7922
  controller.close();
@@ -8115,7 +7994,7 @@ function appendClientMessage({
8115
7994
  }
8116
7995
 
8117
7996
  // core/prompt/append-response-messages.ts
8118
- var import_provider26 = require("@ai-sdk/provider");
7997
+ var import_provider25 = require("@ai-sdk/provider");
8119
7998
  function appendResponseMessages({
8120
7999
  messages,
8121
8000
  responseMessages,
@@ -8165,40 +8044,20 @@ function appendResponseMessages({
8165
8044
  if (reasoningPart == null) {
8166
8045
  reasoningPart = {
8167
8046
  type: "reasoning",
8168
- reasoning: "",
8169
- details: []
8047
+ reasoning: ""
8170
8048
  };
8171
8049
  parts.push(reasoningPart);
8172
8050
  }
8173
8051
  reasoningTextContent = (reasoningTextContent != null ? reasoningTextContent : "") + part.text;
8174
8052
  reasoningPart.reasoning += part.text;
8175
- reasoningPart.details.push({
8176
- type: "text",
8177
- text: part.text,
8178
- signature: part.signature
8179
- });
8180
- break;
8181
- }
8182
- case "redacted-reasoning": {
8183
- if (reasoningPart == null) {
8184
- reasoningPart = {
8185
- type: "reasoning",
8186
- reasoning: "",
8187
- details: []
8188
- };
8189
- parts.push(reasoningPart);
8190
- }
8191
- reasoningPart.details.push({
8192
- type: "redacted",
8193
- data: part.data
8194
- });
8053
+ reasoningPart.providerMetadata = part.providerOptions;
8195
8054
  break;
8196
8055
  }
8197
8056
  case "tool-call":
8198
8057
  break;
8199
8058
  case "file":
8200
8059
  if (part.data instanceof URL) {
8201
- throw new import_provider26.AISDKError({
8060
+ throw new import_provider25.AISDKError({
8202
8061
  name: "InvalidAssistantFileData",
8203
8062
  message: "File data cannot be a URL"
8204
8063
  });
@@ -8292,7 +8151,7 @@ function appendResponseMessages({
8292
8151
  }
8293
8152
 
8294
8153
  // core/registry/custom-provider.ts
8295
- var import_provider27 = require("@ai-sdk/provider");
8154
+ var import_provider26 = require("@ai-sdk/provider");
8296
8155
  function customProvider({
8297
8156
  languageModels,
8298
8157
  textEmbeddingModels,
@@ -8307,7 +8166,7 @@ function customProvider({
8307
8166
  if (fallbackProvider) {
8308
8167
  return fallbackProvider.languageModel(modelId);
8309
8168
  }
8310
- throw new import_provider27.NoSuchModelError({ modelId, modelType: "languageModel" });
8169
+ throw new import_provider26.NoSuchModelError({ modelId, modelType: "languageModel" });
8311
8170
  },
8312
8171
  textEmbeddingModel(modelId) {
8313
8172
  if (textEmbeddingModels != null && modelId in textEmbeddingModels) {
@@ -8316,7 +8175,7 @@ function customProvider({
8316
8175
  if (fallbackProvider) {
8317
8176
  return fallbackProvider.textEmbeddingModel(modelId);
8318
8177
  }
8319
- throw new import_provider27.NoSuchModelError({ modelId, modelType: "textEmbeddingModel" });
8178
+ throw new import_provider26.NoSuchModelError({ modelId, modelType: "textEmbeddingModel" });
8320
8179
  },
8321
8180
  imageModel(modelId) {
8322
8181
  if (imageModels != null && modelId in imageModels) {
@@ -8325,19 +8184,19 @@ function customProvider({
8325
8184
  if (fallbackProvider == null ? void 0 : fallbackProvider.imageModel) {
8326
8185
  return fallbackProvider.imageModel(modelId);
8327
8186
  }
8328
- throw new import_provider27.NoSuchModelError({ modelId, modelType: "imageModel" });
8187
+ throw new import_provider26.NoSuchModelError({ modelId, modelType: "imageModel" });
8329
8188
  }
8330
8189
  };
8331
8190
  }
8332
8191
  var experimental_customProvider = customProvider;
8333
8192
 
8334
8193
  // core/registry/no-such-provider-error.ts
8335
- var import_provider28 = require("@ai-sdk/provider");
8194
+ var import_provider27 = require("@ai-sdk/provider");
8336
8195
  var name16 = "AI_NoSuchProviderError";
8337
8196
  var marker16 = `vercel.ai.error.${name16}`;
8338
8197
  var symbol16 = Symbol.for(marker16);
8339
8198
  var _a16;
8340
- var NoSuchProviderError = class extends import_provider28.NoSuchModelError {
8199
+ var NoSuchProviderError = class extends import_provider27.NoSuchModelError {
8341
8200
  constructor({
8342
8201
  modelId,
8343
8202
  modelType,
@@ -8351,13 +8210,13 @@ var NoSuchProviderError = class extends import_provider28.NoSuchModelError {
8351
8210
  this.availableProviders = availableProviders;
8352
8211
  }
8353
8212
  static isInstance(error) {
8354
- return import_provider28.AISDKError.hasMarker(error, marker16);
8213
+ return import_provider27.AISDKError.hasMarker(error, marker16);
8355
8214
  }
8356
8215
  };
8357
8216
  _a16 = symbol16;
8358
8217
 
8359
8218
  // core/registry/provider-registry.ts
8360
- var import_provider29 = require("@ai-sdk/provider");
8219
+ var import_provider28 = require("@ai-sdk/provider");
8361
8220
  function createProviderRegistry(providers, {
8362
8221
  separator = ":"
8363
8222
  } = {}) {
@@ -8396,7 +8255,7 @@ var DefaultProviderRegistry = class {
8396
8255
  splitId(id, modelType) {
8397
8256
  const index = id.indexOf(this.separator);
8398
8257
  if (index === -1) {
8399
- throw new import_provider29.NoSuchModelError({
8258
+ throw new import_provider28.NoSuchModelError({
8400
8259
  modelId: id,
8401
8260
  modelType,
8402
8261
  message: `Invalid ${modelType} id for registry: ${id} (must be in the format "providerId${this.separator}modelId")`
@@ -8409,7 +8268,7 @@ var DefaultProviderRegistry = class {
8409
8268
  const [providerId, modelId] = this.splitId(id, "languageModel");
8410
8269
  const model = (_b = (_a17 = this.getProvider(providerId)).languageModel) == null ? void 0 : _b.call(_a17, modelId);
8411
8270
  if (model == null) {
8412
- throw new import_provider29.NoSuchModelError({ modelId: id, modelType: "languageModel" });
8271
+ throw new import_provider28.NoSuchModelError({ modelId: id, modelType: "languageModel" });
8413
8272
  }
8414
8273
  return model;
8415
8274
  }
@@ -8419,7 +8278,7 @@ var DefaultProviderRegistry = class {
8419
8278
  const provider = this.getProvider(providerId);
8420
8279
  const model = (_a17 = provider.textEmbeddingModel) == null ? void 0 : _a17.call(provider, modelId);
8421
8280
  if (model == null) {
8422
- throw new import_provider29.NoSuchModelError({
8281
+ throw new import_provider28.NoSuchModelError({
8423
8282
  modelId: id,
8424
8283
  modelType: "textEmbeddingModel"
8425
8284
  });
@@ -8432,7 +8291,7 @@ var DefaultProviderRegistry = class {
8432
8291
  const provider = this.getProvider(providerId);
8433
8292
  const model = (_a17 = provider.imageModel) == null ? void 0 : _a17.call(provider, modelId);
8434
8293
  if (model == null) {
8435
- throw new import_provider29.NoSuchModelError({ modelId: id, modelType: "imageModel" });
8294
+ throw new import_provider28.NoSuchModelError({ modelId: id, modelType: "imageModel" });
8436
8295
  }
8437
8296
  return model;
8438
8297
  }
@@ -9042,172 +8901,6 @@ function simulateReadableStream({
9042
8901
  });
9043
8902
  }
9044
8903
 
9045
- // streams/langchain-adapter.ts
9046
- var langchain_adapter_exports = {};
9047
- __export(langchain_adapter_exports, {
9048
- mergeIntoDataStream: () => mergeIntoDataStream,
9049
- toDataStream: () => toDataStream,
9050
- toDataStreamResponse: () => toDataStreamResponse
9051
- });
9052
-
9053
- // streams/stream-callbacks.ts
9054
- function createCallbacksTransformer(callbacks = {}) {
9055
- const textEncoder = new TextEncoder();
9056
- let aggregatedResponse = "";
9057
- return new TransformStream({
9058
- async start() {
9059
- if (callbacks.onStart)
9060
- await callbacks.onStart();
9061
- },
9062
- async transform(message, controller) {
9063
- controller.enqueue(textEncoder.encode(message));
9064
- aggregatedResponse += message;
9065
- if (callbacks.onToken)
9066
- await callbacks.onToken(message);
9067
- if (callbacks.onText && typeof message === "string") {
9068
- await callbacks.onText(message);
9069
- }
9070
- },
9071
- async flush() {
9072
- if (callbacks.onCompletion) {
9073
- await callbacks.onCompletion(aggregatedResponse);
9074
- }
9075
- if (callbacks.onFinal) {
9076
- await callbacks.onFinal(aggregatedResponse);
9077
- }
9078
- }
9079
- });
9080
- }
9081
-
9082
- // streams/langchain-adapter.ts
9083
- function toDataStreamInternal(stream, callbacks) {
9084
- return stream.pipeThrough(
9085
- new TransformStream({
9086
- transform: async (value, controller) => {
9087
- var _a17;
9088
- if (typeof value === "string") {
9089
- controller.enqueue(value);
9090
- return;
9091
- }
9092
- if ("event" in value) {
9093
- if (value.event === "on_chat_model_stream") {
9094
- forwardAIMessageChunk(
9095
- (_a17 = value.data) == null ? void 0 : _a17.chunk,
9096
- controller
9097
- );
9098
- }
9099
- return;
9100
- }
9101
- forwardAIMessageChunk(value, controller);
9102
- }
9103
- })
9104
- ).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(new TextDecoderStream()).pipeThrough(
9105
- new TransformStream({
9106
- transform: async (chunk, controller) => {
9107
- controller.enqueue(formatDataStreamPart("text", chunk));
9108
- }
9109
- })
9110
- );
9111
- }
9112
- function toDataStream(stream, callbacks) {
9113
- return toDataStreamInternal(stream, callbacks).pipeThrough(
9114
- new TextEncoderStream()
9115
- );
9116
- }
9117
- function toDataStreamResponse(stream, options) {
9118
- var _a17;
9119
- const dataStream = toDataStreamInternal(
9120
- stream,
9121
- options == null ? void 0 : options.callbacks
9122
- ).pipeThrough(new TextEncoderStream());
9123
- const data = options == null ? void 0 : options.data;
9124
- const init = options == null ? void 0 : options.init;
9125
- const responseStream = data ? mergeStreams(data.stream, dataStream) : dataStream;
9126
- return new Response(responseStream, {
9127
- status: (_a17 = init == null ? void 0 : init.status) != null ? _a17 : 200,
9128
- statusText: init == null ? void 0 : init.statusText,
9129
- headers: prepareResponseHeaders(init == null ? void 0 : init.headers, {
9130
- contentType: "text/plain; charset=utf-8",
9131
- dataStreamVersion: "v1"
9132
- })
9133
- });
9134
- }
9135
- function mergeIntoDataStream(stream, options) {
9136
- options.dataStream.merge(toDataStreamInternal(stream, options.callbacks));
9137
- }
9138
- function forwardAIMessageChunk(chunk, controller) {
9139
- if (typeof chunk.content === "string") {
9140
- controller.enqueue(chunk.content);
9141
- } else {
9142
- const content = chunk.content;
9143
- for (const item of content) {
9144
- if (item.type === "text") {
9145
- controller.enqueue(item.text);
9146
- }
9147
- }
9148
- }
9149
- }
9150
-
9151
- // streams/llamaindex-adapter.ts
9152
- var llamaindex_adapter_exports = {};
9153
- __export(llamaindex_adapter_exports, {
9154
- mergeIntoDataStream: () => mergeIntoDataStream2,
9155
- toDataStream: () => toDataStream2,
9156
- toDataStreamResponse: () => toDataStreamResponse2
9157
- });
9158
- var import_provider_utils23 = require("@ai-sdk/provider-utils");
9159
- function toDataStreamInternal2(stream, callbacks) {
9160
- const trimStart = trimStartOfStream();
9161
- return (0, import_provider_utils23.convertAsyncIteratorToReadableStream)(stream[Symbol.asyncIterator]()).pipeThrough(
9162
- new TransformStream({
9163
- async transform(message, controller) {
9164
- controller.enqueue(trimStart(message.delta));
9165
- }
9166
- })
9167
- ).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(new TextDecoderStream()).pipeThrough(
9168
- new TransformStream({
9169
- transform: async (chunk, controller) => {
9170
- controller.enqueue(formatDataStreamPart("text", chunk));
9171
- }
9172
- })
9173
- );
9174
- }
9175
- function toDataStream2(stream, callbacks) {
9176
- return toDataStreamInternal2(stream, callbacks).pipeThrough(
9177
- new TextEncoderStream()
9178
- );
9179
- }
9180
- function toDataStreamResponse2(stream, options = {}) {
9181
- var _a17;
9182
- const { init, data, callbacks } = options;
9183
- const dataStream = toDataStreamInternal2(stream, callbacks).pipeThrough(
9184
- new TextEncoderStream()
9185
- );
9186
- const responseStream = data ? mergeStreams(data.stream, dataStream) : dataStream;
9187
- return new Response(responseStream, {
9188
- status: (_a17 = init == null ? void 0 : init.status) != null ? _a17 : 200,
9189
- statusText: init == null ? void 0 : init.statusText,
9190
- headers: prepareResponseHeaders(init == null ? void 0 : init.headers, {
9191
- contentType: "text/plain; charset=utf-8",
9192
- dataStreamVersion: "v1"
9193
- })
9194
- });
9195
- }
9196
- function mergeIntoDataStream2(stream, options) {
9197
- options.dataStream.merge(toDataStreamInternal2(stream, options.callbacks));
9198
- }
9199
- function trimStartOfStream() {
9200
- let isStreamStart = true;
9201
- return (text2) => {
9202
- if (isStreamStart) {
9203
- text2 = text2.trimStart();
9204
- if (text2)
9205
- isStreamStart = false;
9206
- }
9207
- return text2;
9208
- };
9209
- }
9210
-
9211
8904
  // util/constants.ts
9212
8905
  var HANGING_STREAM_WARNING_TIME_MS = 15 * 1e3;
9213
8906
 
@@ -9287,8 +8980,6 @@ var StreamData = class {
9287
8980
  InvalidStreamPartError,
9288
8981
  InvalidToolArgumentsError,
9289
8982
  JSONParseError,
9290
- LangChainAdapter,
9291
- LlamaIndexAdapter,
9292
8983
  LoadAPIKeyError,
9293
8984
  MCPClientError,
9294
8985
  MessageConversionError,