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/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,
@@ -4275,7 +4214,7 @@ async function generateObject({
4275
4214
  let response;
4276
4215
  let request;
4277
4216
  let resultProviderMetadata;
4278
- const standardizedPrompt = standardizePrompt({
4217
+ const standardizedPrompt = await standardizePrompt({
4279
4218
  prompt: { system, prompt, messages },
4280
4219
  tools: void 0
4281
4220
  });
@@ -4376,8 +4315,8 @@ async function generateObject({
4376
4315
  resultProviderMetadata = generateResult.providerMetadata;
4377
4316
  request = (_a17 = generateResult.request) != null ? _a17 : {};
4378
4317
  response = generateResult.responseData;
4379
- function processResult(result2) {
4380
- 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 });
4381
4320
  if (!parseResult.success) {
4382
4321
  throw new NoObjectGeneratedError({
4383
4322
  message: "No object generated: could not parse the response.",
@@ -4388,7 +4327,7 @@ async function generateObject({
4388
4327
  finishReason
4389
4328
  });
4390
4329
  }
4391
- const validationResult = outputStrategy.validateFinalResult(
4330
+ const validationResult = await outputStrategy.validateFinalResult(
4392
4331
  parseResult.value,
4393
4332
  {
4394
4333
  text: result2,
@@ -4410,7 +4349,7 @@ async function generateObject({
4410
4349
  }
4411
4350
  let object2;
4412
4351
  try {
4413
- object2 = processResult(result);
4352
+ object2 = await processResult(result);
4414
4353
  } catch (error) {
4415
4354
  if (repairText != null && NoObjectGeneratedError.isInstance(error) && (import_provider13.JSONParseError.isInstance(error.cause) || import_provider13.TypeValidationError.isInstance(error.cause))) {
4416
4355
  const repairedText = await repairText({
@@ -4420,7 +4359,7 @@ async function generateObject({
4420
4359
  if (repairedText === null) {
4421
4360
  throw error;
4422
4361
  }
4423
- object2 = processResult(repairedText);
4362
+ object2 = await processResult(repairedText);
4424
4363
  } else {
4425
4364
  throw error;
4426
4365
  }
@@ -4741,7 +4680,7 @@ var DefaultStreamObjectResult = class {
4741
4680
  tracer,
4742
4681
  endWhenDone: false,
4743
4682
  fn: async (rootSpan) => {
4744
- const standardizedPrompt = standardizePrompt({
4683
+ const standardizedPrompt = await standardizePrompt({
4745
4684
  prompt: { system, prompt, messages },
4746
4685
  tools: void 0
4747
4686
  });
@@ -4856,9 +4795,9 @@ var DefaultStreamObjectResult = class {
4856
4795
  if (typeof chunk === "string") {
4857
4796
  accumulatedText += chunk;
4858
4797
  textDelta += chunk;
4859
- const { value: currentObjectJson, state: parseState } = parsePartialJson(accumulatedText);
4798
+ const { value: currentObjectJson, state: parseState } = await parsePartialJson(accumulatedText);
4860
4799
  if (currentObjectJson !== void 0 && !isDeepEqualData(latestObjectJson, currentObjectJson)) {
4861
- const validationResult = outputStrategy.validatePartialResult({
4800
+ const validationResult = await outputStrategy.validatePartialResult({
4862
4801
  value: currentObjectJson,
4863
4802
  textDelta,
4864
4803
  latestObject,
@@ -4912,7 +4851,7 @@ var DefaultStreamObjectResult = class {
4912
4851
  ...fullResponse,
4913
4852
  headers: response == null ? void 0 : response.headers
4914
4853
  });
4915
- const validationResult = outputStrategy.validateFinalResult(
4854
+ const validationResult = await outputStrategy.validateFinalResult(
4916
4855
  latestObjectJson,
4917
4856
  {
4918
4857
  text: accumulatedText,
@@ -5350,7 +5289,7 @@ async function doParseToolCall({
5350
5289
  });
5351
5290
  }
5352
5291
  const schema = asSchema(tool2.parameters);
5353
- 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 });
5354
5293
  if (parseResult.success === false) {
5355
5294
  throw new InvalidToolArgumentsError({
5356
5295
  toolName,
@@ -5367,10 +5306,17 @@ async function doParseToolCall({
5367
5306
  }
5368
5307
 
5369
5308
  // core/generate-text/reasoning.ts
5370
- function asReasoningText(reasoning) {
5371
- 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("");
5372
5311
  return reasoningText.length > 0 ? reasoningText : void 0;
5373
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
+ }
5374
5320
 
5375
5321
  // core/generate-text/to-response-messages.ts
5376
5322
  function toResponseMessages({
@@ -5385,12 +5331,8 @@ function toResponseMessages({
5385
5331
  }) {
5386
5332
  const responseMessages = [];
5387
5333
  const content = [];
5388
- if (reasoning.length > 0) {
5389
- content.push(
5390
- ...reasoning.map(
5391
- (part) => part.type === "text" ? { ...part, type: "reasoning" } : { ...part, type: "redacted-reasoning" }
5392
- )
5393
- );
5334
+ for (const part of reasoning) {
5335
+ content.push(part);
5394
5336
  }
5395
5337
  if (files.length > 0) {
5396
5338
  content.push(
@@ -5489,7 +5431,7 @@ async function generateText({
5489
5431
  headers,
5490
5432
  settings: { ...callSettings, maxRetries }
5491
5433
  });
5492
- const initialPrompt = standardizePrompt({
5434
+ const initialPrompt = await standardizePrompt({
5493
5435
  prompt: { system, prompt, messages },
5494
5436
  tools
5495
5437
  });
@@ -5520,7 +5462,7 @@ async function generateText({
5520
5462
  let currentModelResponse;
5521
5463
  let currentToolCalls = [];
5522
5464
  let currentToolResults = [];
5523
- let currentReasoningDetails = [];
5465
+ let currentReasoning = [];
5524
5466
  let stepCount = 0;
5525
5467
  const responseMessages = [];
5526
5468
  let text2 = "";
@@ -5682,7 +5624,7 @@ async function generateText({
5682
5624
  text2.trimEnd() !== text2 ? originalText.trimStart() : originalText;
5683
5625
  const stepText = nextStepType === "continue" ? removeTextAfterLastWhitespace(stepTextLeadingWhitespaceTrimmed) : stepTextLeadingWhitespaceTrimmed;
5684
5626
  text2 = nextStepType === "continue" || stepType === "continue" ? text2 + stepText : stepText;
5685
- currentReasoningDetails = asReasoningDetails(
5627
+ currentReasoning = convertReasoningContentToParts(
5686
5628
  currentModelResponse.content
5687
5629
  );
5688
5630
  sources.push(
@@ -5705,7 +5647,9 @@ async function generateText({
5705
5647
  ...toResponseMessages({
5706
5648
  text: text2,
5707
5649
  files: asFiles(currentModelResponse.content),
5708
- reasoning: asReasoningDetails(currentModelResponse.content),
5650
+ reasoning: convertReasoningContentToParts(
5651
+ currentModelResponse.content
5652
+ ),
5709
5653
  tools: tools != null ? tools : {},
5710
5654
  toolCalls: currentToolCalls,
5711
5655
  toolResults: currentToolResults,
@@ -5717,8 +5661,8 @@ async function generateText({
5717
5661
  const currentStepResult = {
5718
5662
  stepType,
5719
5663
  text: stepText,
5720
- reasoningText: asReasoningText(currentReasoningDetails),
5721
- reasoning: currentReasoningDetails,
5664
+ reasoningText: asReasoningText(currentReasoning),
5665
+ reasoning: currentReasoning,
5722
5666
  files: asFiles(currentModelResponse.content),
5723
5667
  sources: currentModelResponse.content.filter(
5724
5668
  (part) => part.type === "source"
@@ -5761,25 +5705,21 @@ async function generateText({
5761
5705
  }
5762
5706
  })
5763
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
+ ));
5764
5716
  return new DefaultGenerateTextResult({
5765
5717
  text: text2,
5766
5718
  files: asFiles(currentModelResponse.content),
5767
- reasoning: asReasoningText(currentReasoningDetails),
5768
- reasoningDetails: currentReasoningDetails,
5719
+ reasoning: asReasoningText(currentReasoning),
5720
+ reasoningDetails: currentReasoning,
5769
5721
  sources,
5770
- outputResolver: () => {
5771
- if (output == null) {
5772
- throw new NoOutputSpecifiedError();
5773
- }
5774
- return output.parseOutput(
5775
- { text: text2 },
5776
- {
5777
- response: currentModelResponse.response,
5778
- usage,
5779
- finishReason: currentModelResponse.finishReason
5780
- }
5781
- );
5782
- },
5722
+ resolvedOutput,
5783
5723
  toolCalls: currentToolCalls,
5784
5724
  toolResults: currentToolResults,
5785
5725
  finishReason: currentModelResponse.finishReason,
@@ -5886,41 +5826,16 @@ var DefaultGenerateTextResult = class {
5886
5826
  this.response = options.response;
5887
5827
  this.steps = options.steps;
5888
5828
  this.providerMetadata = options.providerMetadata;
5889
- this.outputResolver = options.outputResolver;
5829
+ this.resolvedOutput = options.resolvedOutput;
5890
5830
  this.sources = options.sources;
5891
5831
  }
5892
5832
  get experimental_output() {
5893
- return this.outputResolver();
5894
- }
5895
- };
5896
- function asReasoningDetails(content) {
5897
- const reasoning = content.filter((part) => part.type === "reasoning");
5898
- if (reasoning.length === 0) {
5899
- return [];
5900
- }
5901
- const result = [];
5902
- let activeReasoningText;
5903
- for (const part of reasoning) {
5904
- if (part.reasoningType === "text") {
5905
- if (activeReasoningText == null) {
5906
- activeReasoningText = { type: "text", text: part.text };
5907
- result.push(activeReasoningText);
5908
- } else {
5909
- activeReasoningText.text += part.text;
5910
- }
5911
- } else if (part.reasoningType === "signature") {
5912
- if (activeReasoningText == null) {
5913
- activeReasoningText = { type: "text", text: "" };
5914
- result.push(activeReasoningText);
5915
- }
5916
- activeReasoningText.signature = part.signature;
5917
- activeReasoningText = void 0;
5918
- } else if (part.reasoningType === "redacted") {
5919
- result.push({ type: "redacted", data: part.data });
5833
+ if (this.resolvedOutput == null) {
5834
+ throw new NoOutputSpecifiedError();
5920
5835
  }
5836
+ return this.resolvedOutput;
5921
5837
  }
5922
- return result;
5923
- }
5838
+ };
5924
5839
  function asFiles(content) {
5925
5840
  return content.filter((part) => part.type === "file").map((part) => new DefaultGeneratedFile(part));
5926
5841
  }
@@ -5996,10 +5911,10 @@ _a15 = symbol15;
5996
5911
  var text = () => ({
5997
5912
  type: "text",
5998
5913
  responseFormat: { type: "text" },
5999
- parsePartial({ text: text2 }) {
5914
+ async parsePartial({ text: text2 }) {
6000
5915
  return { partial: text2 };
6001
5916
  },
6002
- parseOutput({ text: text2 }) {
5917
+ async parseOutput({ text: text2 }) {
6003
5918
  return text2;
6004
5919
  }
6005
5920
  });
@@ -6013,8 +5928,8 @@ var object = ({
6013
5928
  type: "json",
6014
5929
  schema: schema.jsonSchema
6015
5930
  },
6016
- parsePartial({ text: text2 }) {
6017
- const result = parsePartialJson(text2);
5931
+ async parsePartial({ text: text2 }) {
5932
+ const result = await parsePartialJson(text2);
6018
5933
  switch (result.state) {
6019
5934
  case "failed-parse":
6020
5935
  case "undefined-input":
@@ -6031,8 +5946,8 @@ var object = ({
6031
5946
  }
6032
5947
  }
6033
5948
  },
6034
- parseOutput({ text: text2 }, context) {
6035
- 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 });
6036
5951
  if (!parseResult.success) {
6037
5952
  throw new NoObjectGeneratedError({
6038
5953
  message: "No object generated: could not parse the response.",
@@ -6043,7 +5958,7 @@ var object = ({
6043
5958
  finishReason: context.finishReason
6044
5959
  });
6045
5960
  }
6046
- const validationResult = (0, import_provider_utils17.safeValidateTypes)({
5961
+ const validationResult = await (0, import_provider_utils17.safeValidateTypes)({
6047
5962
  value: parseResult.value,
6048
5963
  schema
6049
5964
  });
@@ -6132,7 +6047,6 @@ function smoothStream({
6132
6047
  }
6133
6048
 
6134
6049
  // core/generate-text/stream-text.ts
6135
- var import_provider23 = require("@ai-sdk/provider");
6136
6050
  var import_provider_utils19 = require("@ai-sdk/provider-utils");
6137
6051
 
6138
6052
  // util/as-array.ts
@@ -6284,6 +6198,7 @@ function runToolsTransformation({
6284
6198
  case "stream-start":
6285
6199
  case "text":
6286
6200
  case "reasoning":
6201
+ case "reasoning-part-finish":
6287
6202
  case "source":
6288
6203
  case "response-metadata":
6289
6204
  case "error": {
@@ -6541,7 +6456,7 @@ function createOutputTransformStream(output) {
6541
6456
  textChunk = "";
6542
6457
  }
6543
6458
  return new TransformStream({
6544
- transform(chunk, controller) {
6459
+ async transform(chunk, controller) {
6545
6460
  if (chunk.type === "step-finish") {
6546
6461
  publishTextChunk({ controller });
6547
6462
  }
@@ -6551,7 +6466,7 @@ function createOutputTransformStream(output) {
6551
6466
  }
6552
6467
  text2 += chunk.text;
6553
6468
  textChunk += chunk.text;
6554
- const result = output.parsePartial({ text: text2 });
6469
+ const result = await output.parsePartial({ text: text2 });
6555
6470
  if (result != null) {
6556
6471
  const currentJson = JSON.stringify(result.partial);
6557
6472
  if (currentJson !== lastPublishedJson) {
@@ -6624,7 +6539,7 @@ var DefaultStreamTextResult = class {
6624
6539
  let recordedFullText = "";
6625
6540
  let stepReasoning = [];
6626
6541
  let stepFiles = [];
6627
- let activeReasoningText = void 0;
6542
+ let activeReasoningPart = void 0;
6628
6543
  let recordedStepSources = [];
6629
6544
  const recordedSources = [];
6630
6545
  const recordedResponse = {
@@ -6656,26 +6571,21 @@ var DefaultStreamTextResult = class {
6656
6571
  recordedFullText += part.text;
6657
6572
  }
6658
6573
  if (part.type === "reasoning") {
6659
- if (part.reasoningType === "text") {
6660
- if (activeReasoningText == null) {
6661
- activeReasoningText = { type: "text", text: part.text };
6662
- stepReasoning.push(activeReasoningText);
6663
- } else {
6664
- activeReasoningText.text += part.text;
6665
- }
6666
- } else if (part.reasoningType === "signature") {
6667
- if (activeReasoningText == null) {
6668
- throw new import_provider23.AISDKError({
6669
- name: "InvalidStreamPart",
6670
- message: "reasoning-signature without reasoning"
6671
- });
6672
- }
6673
- activeReasoningText.signature = part.signature;
6674
- activeReasoningText = void 0;
6675
- } else if (part.reasoningType === "redacted") {
6676
- 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;
6677
6584
  }
6678
6585
  }
6586
+ if (part.type === "reasoning-part-finish") {
6587
+ activeReasoningPart = void 0;
6588
+ }
6679
6589
  if (part.type === "file") {
6680
6590
  stepFiles.push(part.file);
6681
6591
  }
@@ -6742,7 +6652,7 @@ var DefaultStreamTextResult = class {
6742
6652
  recordedStepSources = [];
6743
6653
  stepReasoning = [];
6744
6654
  stepFiles = [];
6745
- activeReasoningText = void 0;
6655
+ activeReasoningPart = void 0;
6746
6656
  if (nextStepType !== "done") {
6747
6657
  stepType = nextStepType;
6748
6658
  }
@@ -6853,10 +6763,6 @@ var DefaultStreamTextResult = class {
6853
6763
  headers,
6854
6764
  settings: { ...callSettings, maxRetries }
6855
6765
  });
6856
- const initialPrompt = standardizePrompt({
6857
- prompt: { system, prompt, messages },
6858
- tools
6859
- });
6860
6766
  const self = this;
6861
6767
  recordSpan({
6862
6768
  name: "ai.streamText",
@@ -6885,6 +6791,10 @@ var DefaultStreamTextResult = class {
6885
6791
  hasLeadingWhitespace,
6886
6792
  messageId
6887
6793
  }) {
6794
+ const initialPrompt = await standardizePrompt({
6795
+ prompt: { system, prompt, messages },
6796
+ tools
6797
+ });
6888
6798
  const promptFormat = responseMessages.length === 0 ? initialPrompt.type : "messages";
6889
6799
  const stepInputMessages = [
6890
6800
  ...initialPrompt.messages,
@@ -6984,7 +6894,7 @@ var DefaultStreamTextResult = class {
6984
6894
  let warnings;
6985
6895
  const stepReasoning2 = [];
6986
6896
  const stepFiles2 = [];
6987
- let activeReasoningText2 = void 0;
6897
+ let activeReasoningPart2 = void 0;
6988
6898
  let stepFinishReason = "unknown";
6989
6899
  let stepUsage = {
6990
6900
  promptTokens: 0,
@@ -7070,33 +6980,24 @@ var DefaultStreamTextResult = class {
7070
6980
  }
7071
6981
  case "reasoning": {
7072
6982
  controller.enqueue(chunk);
7073
- if (chunk.reasoningType === "text") {
7074
- if (activeReasoningText2 == null) {
7075
- activeReasoningText2 = {
7076
- type: "text",
7077
- text: chunk.text
7078
- };
7079
- stepReasoning2.push(activeReasoningText2);
7080
- } else {
7081
- activeReasoningText2.text += chunk.text;
7082
- }
7083
- } else if (chunk.reasoningType === "signature") {
7084
- if (activeReasoningText2 == null) {
7085
- throw new InvalidStreamPartError({
7086
- chunk,
7087
- message: "reasoning-signature without reasoning"
7088
- });
7089
- }
7090
- activeReasoningText2.signature = chunk.signature;
7091
- activeReasoningText2 = void 0;
7092
- } else if (chunk.reasoningType === "redacted") {
7093
- stepReasoning2.push({
7094
- type: "redacted",
7095
- data: chunk.data
7096
- });
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;
7097
6993
  }
7098
6994
  break;
7099
6995
  }
6996
+ case "reasoning-part-finish": {
6997
+ activeReasoningPart2 = void 0;
6998
+ controller.enqueue(chunk);
6999
+ break;
7000
+ }
7100
7001
  case "tool-call": {
7101
7002
  controller.enqueue(chunk);
7102
7003
  stepToolCalls.push(chunk);
@@ -7422,23 +7323,15 @@ var DefaultStreamTextResult = class {
7422
7323
  }
7423
7324
  case "reasoning": {
7424
7325
  if (sendReasoning) {
7425
- if (chunk.reasoningType === "text") {
7426
- controller.enqueue(
7427
- formatDataStreamPart("reasoning", chunk.text)
7428
- );
7429
- } else if (chunk.reasoningType === "signature") {
7430
- controller.enqueue(
7431
- formatDataStreamPart("reasoning_signature", {
7432
- signature: chunk.signature
7433
- })
7434
- );
7435
- } else if (chunk.reasoningType === "redacted") {
7436
- controller.enqueue(
7437
- formatDataStreamPart("redacted_reasoning", {
7438
- data: chunk.data
7439
- })
7440
- );
7441
- }
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
+ );
7442
7335
  }
7443
7336
  break;
7444
7337
  }
@@ -7649,8 +7542,8 @@ var DefaultStreamTextResult = class {
7649
7542
  };
7650
7543
 
7651
7544
  // errors/no-speech-generated-error.ts
7652
- var import_provider24 = require("@ai-sdk/provider");
7653
- var NoSpeechGeneratedError = class extends import_provider24.AISDKError {
7545
+ var import_provider23 = require("@ai-sdk/provider");
7546
+ var NoSpeechGeneratedError = class extends import_provider23.AISDKError {
7654
7547
  constructor(options) {
7655
7548
  super({
7656
7549
  name: "AI_NoSpeechGeneratedError",
@@ -7739,8 +7632,8 @@ var DefaultSpeechResult = class {
7739
7632
  };
7740
7633
 
7741
7634
  // errors/no-transcript-generated-error.ts
7742
- var import_provider25 = require("@ai-sdk/provider");
7743
- var NoTranscriptGeneratedError = class extends import_provider25.AISDKError {
7635
+ var import_provider24 = require("@ai-sdk/provider");
7636
+ var NoTranscriptGeneratedError = class extends import_provider24.AISDKError {
7744
7637
  constructor(options) {
7745
7638
  super({
7746
7639
  name: "AI_NoTranscriptGeneratedError",
@@ -7928,7 +7821,6 @@ function extractReasoningMiddleware({
7928
7821
  }
7929
7822
  transformedContent.push({
7930
7823
  type: "reasoning",
7931
- reasoningType: "text",
7932
7824
  text: reasoningText
7933
7825
  });
7934
7826
  transformedContent.push({
@@ -7960,7 +7852,6 @@ function extractReasoningMiddleware({
7960
7852
  controller.enqueue(
7961
7853
  isReasoning ? {
7962
7854
  type: "reasoning",
7963
- reasoningType: "text",
7964
7855
  text: prefix + text2
7965
7856
  } : {
7966
7857
  type: "text",
@@ -7987,6 +7878,9 @@ function extractReasoningMiddleware({
7987
7878
  const foundFullMatch = startIndex + nextTag.length <= buffer.length;
7988
7879
  if (foundFullMatch) {
7989
7880
  buffer = buffer.slice(startIndex + nextTag.length);
7881
+ if (isReasoning) {
7882
+ controller.enqueue({ type: "reasoning-part-finish" });
7883
+ }
7990
7884
  isReasoning = !isReasoning;
7991
7885
  afterSwitch = true;
7992
7886
  } else {
@@ -8100,7 +7994,7 @@ function appendClientMessage({
8100
7994
  }
8101
7995
 
8102
7996
  // core/prompt/append-response-messages.ts
8103
- var import_provider26 = require("@ai-sdk/provider");
7997
+ var import_provider25 = require("@ai-sdk/provider");
8104
7998
  function appendResponseMessages({
8105
7999
  messages,
8106
8000
  responseMessages,
@@ -8150,40 +8044,20 @@ function appendResponseMessages({
8150
8044
  if (reasoningPart == null) {
8151
8045
  reasoningPart = {
8152
8046
  type: "reasoning",
8153
- reasoning: "",
8154
- details: []
8047
+ reasoning: ""
8155
8048
  };
8156
8049
  parts.push(reasoningPart);
8157
8050
  }
8158
8051
  reasoningTextContent = (reasoningTextContent != null ? reasoningTextContent : "") + part.text;
8159
8052
  reasoningPart.reasoning += part.text;
8160
- reasoningPart.details.push({
8161
- type: "text",
8162
- text: part.text,
8163
- signature: part.signature
8164
- });
8165
- break;
8166
- }
8167
- case "redacted-reasoning": {
8168
- if (reasoningPart == null) {
8169
- reasoningPart = {
8170
- type: "reasoning",
8171
- reasoning: "",
8172
- details: []
8173
- };
8174
- parts.push(reasoningPart);
8175
- }
8176
- reasoningPart.details.push({
8177
- type: "redacted",
8178
- data: part.data
8179
- });
8053
+ reasoningPart.providerMetadata = part.providerOptions;
8180
8054
  break;
8181
8055
  }
8182
8056
  case "tool-call":
8183
8057
  break;
8184
8058
  case "file":
8185
8059
  if (part.data instanceof URL) {
8186
- throw new import_provider26.AISDKError({
8060
+ throw new import_provider25.AISDKError({
8187
8061
  name: "InvalidAssistantFileData",
8188
8062
  message: "File data cannot be a URL"
8189
8063
  });
@@ -8277,7 +8151,7 @@ function appendResponseMessages({
8277
8151
  }
8278
8152
 
8279
8153
  // core/registry/custom-provider.ts
8280
- var import_provider27 = require("@ai-sdk/provider");
8154
+ var import_provider26 = require("@ai-sdk/provider");
8281
8155
  function customProvider({
8282
8156
  languageModels,
8283
8157
  textEmbeddingModels,
@@ -8292,7 +8166,7 @@ function customProvider({
8292
8166
  if (fallbackProvider) {
8293
8167
  return fallbackProvider.languageModel(modelId);
8294
8168
  }
8295
- throw new import_provider27.NoSuchModelError({ modelId, modelType: "languageModel" });
8169
+ throw new import_provider26.NoSuchModelError({ modelId, modelType: "languageModel" });
8296
8170
  },
8297
8171
  textEmbeddingModel(modelId) {
8298
8172
  if (textEmbeddingModels != null && modelId in textEmbeddingModels) {
@@ -8301,7 +8175,7 @@ function customProvider({
8301
8175
  if (fallbackProvider) {
8302
8176
  return fallbackProvider.textEmbeddingModel(modelId);
8303
8177
  }
8304
- throw new import_provider27.NoSuchModelError({ modelId, modelType: "textEmbeddingModel" });
8178
+ throw new import_provider26.NoSuchModelError({ modelId, modelType: "textEmbeddingModel" });
8305
8179
  },
8306
8180
  imageModel(modelId) {
8307
8181
  if (imageModels != null && modelId in imageModels) {
@@ -8310,19 +8184,19 @@ function customProvider({
8310
8184
  if (fallbackProvider == null ? void 0 : fallbackProvider.imageModel) {
8311
8185
  return fallbackProvider.imageModel(modelId);
8312
8186
  }
8313
- throw new import_provider27.NoSuchModelError({ modelId, modelType: "imageModel" });
8187
+ throw new import_provider26.NoSuchModelError({ modelId, modelType: "imageModel" });
8314
8188
  }
8315
8189
  };
8316
8190
  }
8317
8191
  var experimental_customProvider = customProvider;
8318
8192
 
8319
8193
  // core/registry/no-such-provider-error.ts
8320
- var import_provider28 = require("@ai-sdk/provider");
8194
+ var import_provider27 = require("@ai-sdk/provider");
8321
8195
  var name16 = "AI_NoSuchProviderError";
8322
8196
  var marker16 = `vercel.ai.error.${name16}`;
8323
8197
  var symbol16 = Symbol.for(marker16);
8324
8198
  var _a16;
8325
- var NoSuchProviderError = class extends import_provider28.NoSuchModelError {
8199
+ var NoSuchProviderError = class extends import_provider27.NoSuchModelError {
8326
8200
  constructor({
8327
8201
  modelId,
8328
8202
  modelType,
@@ -8336,13 +8210,13 @@ var NoSuchProviderError = class extends import_provider28.NoSuchModelError {
8336
8210
  this.availableProviders = availableProviders;
8337
8211
  }
8338
8212
  static isInstance(error) {
8339
- return import_provider28.AISDKError.hasMarker(error, marker16);
8213
+ return import_provider27.AISDKError.hasMarker(error, marker16);
8340
8214
  }
8341
8215
  };
8342
8216
  _a16 = symbol16;
8343
8217
 
8344
8218
  // core/registry/provider-registry.ts
8345
- var import_provider29 = require("@ai-sdk/provider");
8219
+ var import_provider28 = require("@ai-sdk/provider");
8346
8220
  function createProviderRegistry(providers, {
8347
8221
  separator = ":"
8348
8222
  } = {}) {
@@ -8381,7 +8255,7 @@ var DefaultProviderRegistry = class {
8381
8255
  splitId(id, modelType) {
8382
8256
  const index = id.indexOf(this.separator);
8383
8257
  if (index === -1) {
8384
- throw new import_provider29.NoSuchModelError({
8258
+ throw new import_provider28.NoSuchModelError({
8385
8259
  modelId: id,
8386
8260
  modelType,
8387
8261
  message: `Invalid ${modelType} id for registry: ${id} (must be in the format "providerId${this.separator}modelId")`
@@ -8394,7 +8268,7 @@ var DefaultProviderRegistry = class {
8394
8268
  const [providerId, modelId] = this.splitId(id, "languageModel");
8395
8269
  const model = (_b = (_a17 = this.getProvider(providerId)).languageModel) == null ? void 0 : _b.call(_a17, modelId);
8396
8270
  if (model == null) {
8397
- throw new import_provider29.NoSuchModelError({ modelId: id, modelType: "languageModel" });
8271
+ throw new import_provider28.NoSuchModelError({ modelId: id, modelType: "languageModel" });
8398
8272
  }
8399
8273
  return model;
8400
8274
  }
@@ -8404,7 +8278,7 @@ var DefaultProviderRegistry = class {
8404
8278
  const provider = this.getProvider(providerId);
8405
8279
  const model = (_a17 = provider.textEmbeddingModel) == null ? void 0 : _a17.call(provider, modelId);
8406
8280
  if (model == null) {
8407
- throw new import_provider29.NoSuchModelError({
8281
+ throw new import_provider28.NoSuchModelError({
8408
8282
  modelId: id,
8409
8283
  modelType: "textEmbeddingModel"
8410
8284
  });
@@ -8417,7 +8291,7 @@ var DefaultProviderRegistry = class {
8417
8291
  const provider = this.getProvider(providerId);
8418
8292
  const model = (_a17 = provider.imageModel) == null ? void 0 : _a17.call(provider, modelId);
8419
8293
  if (model == null) {
8420
- throw new import_provider29.NoSuchModelError({ modelId: id, modelType: "imageModel" });
8294
+ throw new import_provider28.NoSuchModelError({ modelId: id, modelType: "imageModel" });
8421
8295
  }
8422
8296
  return model;
8423
8297
  }
@@ -9027,172 +8901,6 @@ function simulateReadableStream({
9027
8901
  });
9028
8902
  }
9029
8903
 
9030
- // streams/langchain-adapter.ts
9031
- var langchain_adapter_exports = {};
9032
- __export(langchain_adapter_exports, {
9033
- mergeIntoDataStream: () => mergeIntoDataStream,
9034
- toDataStream: () => toDataStream,
9035
- toDataStreamResponse: () => toDataStreamResponse
9036
- });
9037
-
9038
- // streams/stream-callbacks.ts
9039
- function createCallbacksTransformer(callbacks = {}) {
9040
- const textEncoder = new TextEncoder();
9041
- let aggregatedResponse = "";
9042
- return new TransformStream({
9043
- async start() {
9044
- if (callbacks.onStart)
9045
- await callbacks.onStart();
9046
- },
9047
- async transform(message, controller) {
9048
- controller.enqueue(textEncoder.encode(message));
9049
- aggregatedResponse += message;
9050
- if (callbacks.onToken)
9051
- await callbacks.onToken(message);
9052
- if (callbacks.onText && typeof message === "string") {
9053
- await callbacks.onText(message);
9054
- }
9055
- },
9056
- async flush() {
9057
- if (callbacks.onCompletion) {
9058
- await callbacks.onCompletion(aggregatedResponse);
9059
- }
9060
- if (callbacks.onFinal) {
9061
- await callbacks.onFinal(aggregatedResponse);
9062
- }
9063
- }
9064
- });
9065
- }
9066
-
9067
- // streams/langchain-adapter.ts
9068
- function toDataStreamInternal(stream, callbacks) {
9069
- return stream.pipeThrough(
9070
- new TransformStream({
9071
- transform: async (value, controller) => {
9072
- var _a17;
9073
- if (typeof value === "string") {
9074
- controller.enqueue(value);
9075
- return;
9076
- }
9077
- if ("event" in value) {
9078
- if (value.event === "on_chat_model_stream") {
9079
- forwardAIMessageChunk(
9080
- (_a17 = value.data) == null ? void 0 : _a17.chunk,
9081
- controller
9082
- );
9083
- }
9084
- return;
9085
- }
9086
- forwardAIMessageChunk(value, controller);
9087
- }
9088
- })
9089
- ).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(new TextDecoderStream()).pipeThrough(
9090
- new TransformStream({
9091
- transform: async (chunk, controller) => {
9092
- controller.enqueue(formatDataStreamPart("text", chunk));
9093
- }
9094
- })
9095
- );
9096
- }
9097
- function toDataStream(stream, callbacks) {
9098
- return toDataStreamInternal(stream, callbacks).pipeThrough(
9099
- new TextEncoderStream()
9100
- );
9101
- }
9102
- function toDataStreamResponse(stream, options) {
9103
- var _a17;
9104
- const dataStream = toDataStreamInternal(
9105
- stream,
9106
- options == null ? void 0 : options.callbacks
9107
- ).pipeThrough(new TextEncoderStream());
9108
- const data = options == null ? void 0 : options.data;
9109
- const init = options == null ? void 0 : options.init;
9110
- const responseStream = data ? mergeStreams(data.stream, dataStream) : dataStream;
9111
- return new Response(responseStream, {
9112
- status: (_a17 = init == null ? void 0 : init.status) != null ? _a17 : 200,
9113
- statusText: init == null ? void 0 : init.statusText,
9114
- headers: prepareResponseHeaders(init == null ? void 0 : init.headers, {
9115
- contentType: "text/plain; charset=utf-8",
9116
- dataStreamVersion: "v1"
9117
- })
9118
- });
9119
- }
9120
- function mergeIntoDataStream(stream, options) {
9121
- options.dataStream.merge(toDataStreamInternal(stream, options.callbacks));
9122
- }
9123
- function forwardAIMessageChunk(chunk, controller) {
9124
- if (typeof chunk.content === "string") {
9125
- controller.enqueue(chunk.content);
9126
- } else {
9127
- const content = chunk.content;
9128
- for (const item of content) {
9129
- if (item.type === "text") {
9130
- controller.enqueue(item.text);
9131
- }
9132
- }
9133
- }
9134
- }
9135
-
9136
- // streams/llamaindex-adapter.ts
9137
- var llamaindex_adapter_exports = {};
9138
- __export(llamaindex_adapter_exports, {
9139
- mergeIntoDataStream: () => mergeIntoDataStream2,
9140
- toDataStream: () => toDataStream2,
9141
- toDataStreamResponse: () => toDataStreamResponse2
9142
- });
9143
- var import_provider_utils23 = require("@ai-sdk/provider-utils");
9144
- function toDataStreamInternal2(stream, callbacks) {
9145
- const trimStart = trimStartOfStream();
9146
- return (0, import_provider_utils23.convertAsyncIteratorToReadableStream)(stream[Symbol.asyncIterator]()).pipeThrough(
9147
- new TransformStream({
9148
- async transform(message, controller) {
9149
- controller.enqueue(trimStart(message.delta));
9150
- }
9151
- })
9152
- ).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(new TextDecoderStream()).pipeThrough(
9153
- new TransformStream({
9154
- transform: async (chunk, controller) => {
9155
- controller.enqueue(formatDataStreamPart("text", chunk));
9156
- }
9157
- })
9158
- );
9159
- }
9160
- function toDataStream2(stream, callbacks) {
9161
- return toDataStreamInternal2(stream, callbacks).pipeThrough(
9162
- new TextEncoderStream()
9163
- );
9164
- }
9165
- function toDataStreamResponse2(stream, options = {}) {
9166
- var _a17;
9167
- const { init, data, callbacks } = options;
9168
- const dataStream = toDataStreamInternal2(stream, callbacks).pipeThrough(
9169
- new TextEncoderStream()
9170
- );
9171
- const responseStream = data ? mergeStreams(data.stream, dataStream) : dataStream;
9172
- return new Response(responseStream, {
9173
- status: (_a17 = init == null ? void 0 : init.status) != null ? _a17 : 200,
9174
- statusText: init == null ? void 0 : init.statusText,
9175
- headers: prepareResponseHeaders(init == null ? void 0 : init.headers, {
9176
- contentType: "text/plain; charset=utf-8",
9177
- dataStreamVersion: "v1"
9178
- })
9179
- });
9180
- }
9181
- function mergeIntoDataStream2(stream, options) {
9182
- options.dataStream.merge(toDataStreamInternal2(stream, options.callbacks));
9183
- }
9184
- function trimStartOfStream() {
9185
- let isStreamStart = true;
9186
- return (text2) => {
9187
- if (isStreamStart) {
9188
- text2 = text2.trimStart();
9189
- if (text2)
9190
- isStreamStart = false;
9191
- }
9192
- return text2;
9193
- };
9194
- }
9195
-
9196
8904
  // util/constants.ts
9197
8905
  var HANGING_STREAM_WARNING_TIME_MS = 15 * 1e3;
9198
8906
 
@@ -9272,8 +8980,6 @@ var StreamData = class {
9272
8980
  InvalidStreamPartError,
9273
8981
  InvalidToolArgumentsError,
9274
8982
  JSONParseError,
9275
- LangChainAdapter,
9276
- LlamaIndexAdapter,
9277
8983
  LoadAPIKeyError,
9278
8984
  MCPClientError,
9279
8985
  MessageConversionError,