ai 4.1.0 → 4.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # ai
2
2
 
3
+ ## 4.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 0a699f1: feat: add reasoning token support
8
+ - Updated dependencies [e7a9ec9]
9
+ - Updated dependencies [0a699f1]
10
+ - @ai-sdk/ui-utils@1.1.1
11
+ - @ai-sdk/provider-utils@2.1.1
12
+ - @ai-sdk/provider@1.0.5
13
+ - @ai-sdk/react@1.1.1
14
+
3
15
  ## 4.1.0
4
16
 
5
17
  ### Minor Changes
package/dist/index.d.mts CHANGED
@@ -1496,6 +1496,10 @@ type StepResult<TOOLS extends Record<string, CoreTool>> = {
1496
1496
  */
1497
1497
  readonly text: string;
1498
1498
  /**
1499
+ The reasoning that was generated during the generation.
1500
+ */
1501
+ readonly reasoning: string | undefined;
1502
+ /**
1499
1503
  The tool calls that were made during the generation.
1500
1504
  */
1501
1505
  readonly toolCalls: ToolCallArray<TOOLS>;
@@ -1579,10 +1583,15 @@ It contains the generated text, the tool calls that were made during the generat
1579
1583
  */
1580
1584
  interface GenerateTextResult<TOOLS extends Record<string, CoreTool>, OUTPUT> {
1581
1585
  /**
1582
- The generated text.
1586
+ The generated text.
1583
1587
  */
1584
1588
  readonly text: string;
1585
1589
  /**
1590
+ The reasoning text that the model has generated. Can be undefined if the model
1591
+ has only generated text.
1592
+ */
1593
+ readonly reasoning: string | undefined;
1594
+ /**
1586
1595
  The generated structured output. It uses the `experimental_output` specification.
1587
1596
  */
1588
1597
  readonly experimental_output: OUTPUT;
@@ -1898,6 +1907,12 @@ interface StreamTextResult<TOOLS extends Record<string, CoreTool>, PARTIAL_OUTPU
1898
1907
  */
1899
1908
  readonly text: Promise<string>;
1900
1909
  /**
1910
+ The reasoning that has been generated by the last step.
1911
+
1912
+ Resolved when the response is finished.
1913
+ */
1914
+ readonly reasoning: Promise<string | undefined>;
1915
+ /**
1901
1916
  The tool calls that have been executed in the last step.
1902
1917
 
1903
1918
  Resolved when the response is finished.
@@ -2025,6 +2040,9 @@ interface StreamTextResult<TOOLS extends Record<string, CoreTool>, PARTIAL_OUTPU
2025
2040
  type TextStreamPart<TOOLS extends Record<string, CoreTool>> = {
2026
2041
  type: 'text-delta';
2027
2042
  textDelta: string;
2043
+ } | {
2044
+ type: 'reasoning';
2045
+ textDelta: string;
2028
2046
  } | ({
2029
2047
  type: 'tool-call';
2030
2048
  } & ToolCallUnion<TOOLS>) | {
@@ -2220,7 +2238,7 @@ Callback that is called for each chunk of the stream. The stream processing will
2220
2238
  */
2221
2239
  onChunk?: (event: {
2222
2240
  chunk: Extract<TextStreamPart<TOOLS>, {
2223
- type: 'text-delta' | 'tool-call' | 'tool-call-streaming-start' | 'tool-call-delta' | 'tool-result';
2241
+ type: 'text-delta' | 'reasoning' | 'tool-call' | 'tool-call-streaming-start' | 'tool-call-delta' | 'tool-result';
2224
2242
  }>;
2225
2243
  }) => Promise<void> | void;
2226
2244
  /**
package/dist/index.d.ts CHANGED
@@ -1496,6 +1496,10 @@ type StepResult<TOOLS extends Record<string, CoreTool>> = {
1496
1496
  */
1497
1497
  readonly text: string;
1498
1498
  /**
1499
+ The reasoning that was generated during the generation.
1500
+ */
1501
+ readonly reasoning: string | undefined;
1502
+ /**
1499
1503
  The tool calls that were made during the generation.
1500
1504
  */
1501
1505
  readonly toolCalls: ToolCallArray<TOOLS>;
@@ -1579,10 +1583,15 @@ It contains the generated text, the tool calls that were made during the generat
1579
1583
  */
1580
1584
  interface GenerateTextResult<TOOLS extends Record<string, CoreTool>, OUTPUT> {
1581
1585
  /**
1582
- The generated text.
1586
+ The generated text.
1583
1587
  */
1584
1588
  readonly text: string;
1585
1589
  /**
1590
+ The reasoning text that the model has generated. Can be undefined if the model
1591
+ has only generated text.
1592
+ */
1593
+ readonly reasoning: string | undefined;
1594
+ /**
1586
1595
  The generated structured output. It uses the `experimental_output` specification.
1587
1596
  */
1588
1597
  readonly experimental_output: OUTPUT;
@@ -1898,6 +1907,12 @@ interface StreamTextResult<TOOLS extends Record<string, CoreTool>, PARTIAL_OUTPU
1898
1907
  */
1899
1908
  readonly text: Promise<string>;
1900
1909
  /**
1910
+ The reasoning that has been generated by the last step.
1911
+
1912
+ Resolved when the response is finished.
1913
+ */
1914
+ readonly reasoning: Promise<string | undefined>;
1915
+ /**
1901
1916
  The tool calls that have been executed in the last step.
1902
1917
 
1903
1918
  Resolved when the response is finished.
@@ -2025,6 +2040,9 @@ interface StreamTextResult<TOOLS extends Record<string, CoreTool>, PARTIAL_OUTPU
2025
2040
  type TextStreamPart<TOOLS extends Record<string, CoreTool>> = {
2026
2041
  type: 'text-delta';
2027
2042
  textDelta: string;
2043
+ } | {
2044
+ type: 'reasoning';
2045
+ textDelta: string;
2028
2046
  } | ({
2029
2047
  type: 'tool-call';
2030
2048
  } & ToolCallUnion<TOOLS>) | {
@@ -2220,7 +2238,7 @@ Callback that is called for each chunk of the stream. The stream processing will
2220
2238
  */
2221
2239
  onChunk?: (event: {
2222
2240
  chunk: Extract<TextStreamPart<TOOLS>, {
2223
- type: 'text-delta' | 'tool-call' | 'tool-call-streaming-start' | 'tool-call-delta' | 'tool-result';
2241
+ type: 'text-delta' | 'reasoning' | 'tool-call' | 'tool-call-streaming-start' | 'tool-call-delta' | 'tool-result';
2224
2242
  }>;
2225
2243
  }) => Promise<void> | void;
2226
2244
  /**
package/dist/index.js CHANGED
@@ -3910,6 +3910,7 @@ async function generateText({
3910
3910
  const currentStepResult = {
3911
3911
  stepType,
3912
3912
  text: stepText,
3913
+ reasoning: currentModelResponse.reasoning,
3913
3914
  toolCalls: currentToolCalls,
3914
3915
  toolResults: currentToolResults,
3915
3916
  finishReason: currentModelResponse.finishReason,
@@ -3948,6 +3949,7 @@ async function generateText({
3948
3949
  );
3949
3950
  return new DefaultGenerateTextResult({
3950
3951
  text: text2,
3952
+ reasoning: currentModelResponse.reasoning,
3951
3953
  outputResolver: () => {
3952
3954
  if (output == null) {
3953
3955
  throw new NoOutputSpecifiedError();
@@ -4053,6 +4055,7 @@ async function executeTools({
4053
4055
  var DefaultGenerateTextResult = class {
4054
4056
  constructor(options) {
4055
4057
  this.text = options.text;
4058
+ this.reasoning = options.reasoning;
4056
4059
  this.toolCalls = options.toolCalls;
4057
4060
  this.toolResults = options.toolResults;
4058
4061
  this.finishReason = options.finishReason;
@@ -4339,6 +4342,7 @@ function runToolsTransformation({
4339
4342
  const chunkType = chunk.type;
4340
4343
  switch (chunkType) {
4341
4344
  case "text-delta":
4345
+ case "reasoning":
4342
4346
  case "response-metadata":
4343
4347
  case "error": {
4344
4348
  controller.enqueue(chunk);
@@ -4646,6 +4650,7 @@ var DefaultStreamTextResult = class {
4646
4650
  this.finishReasonPromise = new DelayedPromise();
4647
4651
  this.providerMetadataPromise = new DelayedPromise();
4648
4652
  this.textPromise = new DelayedPromise();
4653
+ this.reasoningPromise = new DelayedPromise();
4649
4654
  this.toolCallsPromise = new DelayedPromise();
4650
4655
  this.toolResultsPromise = new DelayedPromise();
4651
4656
  this.requestPromise = new DelayedPromise();
@@ -4663,6 +4668,7 @@ var DefaultStreamTextResult = class {
4663
4668
  let recordedStepText = "";
4664
4669
  let recordedContinuationText = "";
4665
4670
  let recordedFullText = "";
4671
+ let recordedReasoningText = void 0;
4666
4672
  const recordedResponse = {
4667
4673
  id: generateId3(),
4668
4674
  timestamp: currentDate(),
@@ -4680,7 +4686,7 @@ var DefaultStreamTextResult = class {
4680
4686
  async transform(chunk, controller) {
4681
4687
  controller.enqueue(chunk);
4682
4688
  const { part } = chunk;
4683
- if (part.type === "text-delta" || part.type === "tool-call" || part.type === "tool-result" || part.type === "tool-call-streaming-start" || part.type === "tool-call-delta") {
4689
+ if (part.type === "text-delta" || part.type === "reasoning" || part.type === "tool-call" || part.type === "tool-result" || part.type === "tool-call-streaming-start" || part.type === "tool-call-delta") {
4684
4690
  await (onChunk == null ? void 0 : onChunk({ chunk: part }));
4685
4691
  }
4686
4692
  if (part.type === "text-delta") {
@@ -4688,6 +4694,9 @@ var DefaultStreamTextResult = class {
4688
4694
  recordedContinuationText += part.textDelta;
4689
4695
  recordedFullText += part.textDelta;
4690
4696
  }
4697
+ if (part.type === "reasoning") {
4698
+ recordedReasoningText = (recordedReasoningText != null ? recordedReasoningText : "") + part.textDelta;
4699
+ }
4691
4700
  if (part.type === "tool-call") {
4692
4701
  recordedToolCalls.push(part);
4693
4702
  }
@@ -4720,6 +4729,7 @@ var DefaultStreamTextResult = class {
4720
4729
  const currentStepResult = {
4721
4730
  stepType,
4722
4731
  text: recordedStepText,
4732
+ reasoning: recordedReasoningText,
4723
4733
  toolCalls: recordedToolCalls,
4724
4734
  toolResults: recordedToolResults,
4725
4735
  finishReason: part.finishReason,
@@ -4780,12 +4790,14 @@ var DefaultStreamTextResult = class {
4780
4790
  self.finishReasonPromise.resolve(finishReason);
4781
4791
  self.usagePromise.resolve(usage);
4782
4792
  self.textPromise.resolve(recordedFullText);
4793
+ self.reasoningPromise.resolve(recordedReasoningText);
4783
4794
  self.stepsPromise.resolve(recordedSteps);
4784
4795
  await (onFinish == null ? void 0 : onFinish({
4785
4796
  finishReason,
4786
4797
  logprobs: void 0,
4787
4798
  usage,
4788
4799
  text: recordedFullText,
4800
+ reasoning: recordedReasoningText,
4789
4801
  toolCalls: lastStep.toolCalls,
4790
4802
  toolResults: lastStep.toolResults,
4791
4803
  request: (_a15 = lastStep.request) != null ? _a15 : {},
@@ -4982,6 +4994,7 @@ var DefaultStreamTextResult = class {
4982
4994
  let stepProviderMetadata;
4983
4995
  let stepFirstChunk = true;
4984
4996
  let stepText = "";
4997
+ let stepReasoning = "";
4985
4998
  let fullStepText = stepType2 === "continue" ? previousStepText : "";
4986
4999
  let stepLogProbs;
4987
5000
  let stepResponse = {
@@ -5053,6 +5066,11 @@ var DefaultStreamTextResult = class {
5053
5066
  }
5054
5067
  break;
5055
5068
  }
5069
+ case "reasoning": {
5070
+ controller.enqueue(chunk);
5071
+ stepReasoning += chunk.textDelta;
5072
+ break;
5073
+ }
5056
5074
  case "tool-call": {
5057
5075
  controller.enqueue(chunk);
5058
5076
  stepToolCalls.push(chunk);
@@ -5266,6 +5284,9 @@ var DefaultStreamTextResult = class {
5266
5284
  get text() {
5267
5285
  return this.textPromise.value;
5268
5286
  }
5287
+ get reasoning() {
5288
+ return this.reasoningPromise.value;
5289
+ }
5269
5290
  get toolCalls() {
5270
5291
  return this.toolCallsPromise.value;
5271
5292
  }
@@ -5358,6 +5379,12 @@ var DefaultStreamTextResult = class {
5358
5379
  controller.enqueue((0, import_ui_utils8.formatDataStreamPart)("text", chunk.textDelta));
5359
5380
  break;
5360
5381
  }
5382
+ case "reasoning": {
5383
+ controller.enqueue(
5384
+ (0, import_ui_utils8.formatDataStreamPart)("reasoning", chunk.textDelta)
5385
+ );
5386
+ break;
5387
+ }
5361
5388
  case "tool-call-streaming-start": {
5362
5389
  controller.enqueue(
5363
5390
  (0, import_ui_utils8.formatDataStreamPart)("tool_call_streaming_start", {