ai 4.1.58 → 4.1.60

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.60
4
+
5
+ ### Patch Changes
6
+
7
+ - 0b8797f: feat (ai/core): expose response body for each generateText step
8
+
9
+ ## 4.1.59
10
+
11
+ ### Patch Changes
12
+
13
+ - dd18049: fix (ai/core): suppress next.js warnings for node.js specific code path
14
+
3
15
  ## 4.1.58
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1570,16 +1570,6 @@ Callback that is called when the LLM response and the final object validation ar
1570
1570
  };
1571
1571
  }): StreamObjectResult<JSONValue, JSONValue, never>;
1572
1572
 
1573
- /**
1574
- * Appends a client message to the messages array.
1575
- * If the last message in the array has the same id as the new message, it will be replaced.
1576
- * Otherwise, the new message will be appended.
1577
- */
1578
- declare function appendClientMessage({ messages, message, }: {
1579
- messages: Message[];
1580
- message: Message;
1581
- }): Message[];
1582
-
1583
1573
  type ReasoningDetail = {
1584
1574
  type: 'text';
1585
1575
  text: string;
@@ -2552,8 +2542,8 @@ It can be either an assistant message or a tool message.
2552
2542
  */
2553
2543
  type ResponseMessage = (CoreAssistantMessage | CoreToolMessage) & {
2554
2544
  /**
2555
- Message ID generated by the AI SDK.
2556
- */
2545
+ Message ID generated by the AI SDK.
2546
+ */
2557
2547
  id: string;
2558
2548
  };
2559
2549
  /**
@@ -2612,6 +2602,10 @@ type StepResult<TOOLS extends ToolSet> = {
2612
2602
  They contain a generated id.
2613
2603
  */
2614
2604
  readonly messages: Array<ResponseMessage>;
2605
+ /**
2606
+ Response body (available only for providers that use HTTP requests).
2607
+ */
2608
+ body?: unknown;
2615
2609
  };
2616
2610
  /**
2617
2611
  Additional provider-specific metadata. They are passed through
@@ -2635,32 +2629,6 @@ type StepResult<TOOLS extends ToolSet> = {
2635
2629
  readonly isContinued: boolean;
2636
2630
  };
2637
2631
 
2638
- /**
2639
- * Appends the ResponseMessage[] from the response to a Message[] (for useChat).
2640
- * The messages are converted to Messages before being appended.
2641
- * Timestamps are generated for the new messages.
2642
- *
2643
- * @returns A new Message[] with the response messages appended.
2644
- */
2645
- declare function appendResponseMessages({ messages, responseMessages, _internal: { currentDate }, }: {
2646
- messages: Message[];
2647
- responseMessages: ResponseMessage[];
2648
- /**
2649
- Internal. For test use only. May change without notice.
2650
- */
2651
- _internal?: {
2652
- currentDate?: () => Date;
2653
- };
2654
- }): Message[];
2655
-
2656
- /**
2657
- Converts an array of messages from useChat into an array of CoreMessages that can be used
2658
- with the AI core functions (e.g. `streamText`).
2659
- */
2660
- declare function convertToCoreMessages<TOOLS extends ToolSet = never>(messages: Array<Omit<Message, 'id'>>, options?: {
2661
- tools?: TOOLS;
2662
- }): CoreMessage[];
2663
-
2664
2632
  /**
2665
2633
  The result of a `generateText` call.
2666
2634
  It contains the generated text, the tool calls that were made during the generation, and the results of the tool calls.
@@ -2730,7 +2698,7 @@ interface GenerateTextResult<TOOLS extends ToolSet, OUTPUT> {
2730
2698
  If there are tools that do not have execute functions, they are not included in the tool results and
2731
2699
  need to be added separately.
2732
2700
  */
2733
- messages: Array<CoreAssistantMessage | CoreToolMessage>;
2701
+ messages: Array<ResponseMessage>;
2734
2702
  /**
2735
2703
  Response body (available only for providers that use HTTP requests).
2736
2704
  */
@@ -2819,6 +2787,42 @@ declare class NoSuchToolError extends AISDKError {
2819
2787
  static isInstance(error: unknown): error is NoSuchToolError;
2820
2788
  }
2821
2789
 
2790
+ /**
2791
+ * Appends a client message to the messages array.
2792
+ * If the last message in the array has the same id as the new message, it will be replaced.
2793
+ * Otherwise, the new message will be appended.
2794
+ */
2795
+ declare function appendClientMessage({ messages, message, }: {
2796
+ messages: Message[];
2797
+ message: Message;
2798
+ }): Message[];
2799
+
2800
+ /**
2801
+ * Appends the ResponseMessage[] from the response to a Message[] (for useChat).
2802
+ * The messages are converted to Messages before being appended.
2803
+ * Timestamps are generated for the new messages.
2804
+ *
2805
+ * @returns A new Message[] with the response messages appended.
2806
+ */
2807
+ declare function appendResponseMessages({ messages, responseMessages, _internal: { currentDate }, }: {
2808
+ messages: Message[];
2809
+ responseMessages: ResponseMessage[];
2810
+ /**
2811
+ Internal. For test use only. May change without notice.
2812
+ */
2813
+ _internal?: {
2814
+ currentDate?: () => Date;
2815
+ };
2816
+ }): Message[];
2817
+
2818
+ /**
2819
+ Converts an array of messages from useChat into an array of CoreMessages that can be used
2820
+ with the AI core functions (e.g. `streamText`).
2821
+ */
2822
+ declare function convertToCoreMessages<TOOLS extends ToolSet = never>(messages: Array<Omit<Message, 'id'>>, options?: {
2823
+ tools?: TOOLS;
2824
+ }): CoreMessage[];
2825
+
2822
2826
  /**
2823
2827
  * A function that attempts to repair a tool call that failed to parse.
2824
2828
  *
@@ -3110,7 +3114,7 @@ interface StreamTextResult<TOOLS extends ToolSet, PARTIAL_OUTPUT> {
3110
3114
  If there are tools that do not have execute functions, they are not included in the tool results and
3111
3115
  need to be added separately.
3112
3116
  */
3113
- messages: Array<CoreAssistantMessage | CoreToolMessage>;
3117
+ messages: Array<ResponseMessage>;
3114
3118
  }>;
3115
3119
  /**
3116
3120
  A text stream that returns only the generated text deltas. You can use it
package/dist/index.d.ts CHANGED
@@ -1570,16 +1570,6 @@ Callback that is called when the LLM response and the final object validation ar
1570
1570
  };
1571
1571
  }): StreamObjectResult<JSONValue, JSONValue, never>;
1572
1572
 
1573
- /**
1574
- * Appends a client message to the messages array.
1575
- * If the last message in the array has the same id as the new message, it will be replaced.
1576
- * Otherwise, the new message will be appended.
1577
- */
1578
- declare function appendClientMessage({ messages, message, }: {
1579
- messages: Message[];
1580
- message: Message;
1581
- }): Message[];
1582
-
1583
1573
  type ReasoningDetail = {
1584
1574
  type: 'text';
1585
1575
  text: string;
@@ -2552,8 +2542,8 @@ It can be either an assistant message or a tool message.
2552
2542
  */
2553
2543
  type ResponseMessage = (CoreAssistantMessage | CoreToolMessage) & {
2554
2544
  /**
2555
- Message ID generated by the AI SDK.
2556
- */
2545
+ Message ID generated by the AI SDK.
2546
+ */
2557
2547
  id: string;
2558
2548
  };
2559
2549
  /**
@@ -2612,6 +2602,10 @@ type StepResult<TOOLS extends ToolSet> = {
2612
2602
  They contain a generated id.
2613
2603
  */
2614
2604
  readonly messages: Array<ResponseMessage>;
2605
+ /**
2606
+ Response body (available only for providers that use HTTP requests).
2607
+ */
2608
+ body?: unknown;
2615
2609
  };
2616
2610
  /**
2617
2611
  Additional provider-specific metadata. They are passed through
@@ -2635,32 +2629,6 @@ type StepResult<TOOLS extends ToolSet> = {
2635
2629
  readonly isContinued: boolean;
2636
2630
  };
2637
2631
 
2638
- /**
2639
- * Appends the ResponseMessage[] from the response to a Message[] (for useChat).
2640
- * The messages are converted to Messages before being appended.
2641
- * Timestamps are generated for the new messages.
2642
- *
2643
- * @returns A new Message[] with the response messages appended.
2644
- */
2645
- declare function appendResponseMessages({ messages, responseMessages, _internal: { currentDate }, }: {
2646
- messages: Message[];
2647
- responseMessages: ResponseMessage[];
2648
- /**
2649
- Internal. For test use only. May change without notice.
2650
- */
2651
- _internal?: {
2652
- currentDate?: () => Date;
2653
- };
2654
- }): Message[];
2655
-
2656
- /**
2657
- Converts an array of messages from useChat into an array of CoreMessages that can be used
2658
- with the AI core functions (e.g. `streamText`).
2659
- */
2660
- declare function convertToCoreMessages<TOOLS extends ToolSet = never>(messages: Array<Omit<Message, 'id'>>, options?: {
2661
- tools?: TOOLS;
2662
- }): CoreMessage[];
2663
-
2664
2632
  /**
2665
2633
  The result of a `generateText` call.
2666
2634
  It contains the generated text, the tool calls that were made during the generation, and the results of the tool calls.
@@ -2730,7 +2698,7 @@ interface GenerateTextResult<TOOLS extends ToolSet, OUTPUT> {
2730
2698
  If there are tools that do not have execute functions, they are not included in the tool results and
2731
2699
  need to be added separately.
2732
2700
  */
2733
- messages: Array<CoreAssistantMessage | CoreToolMessage>;
2701
+ messages: Array<ResponseMessage>;
2734
2702
  /**
2735
2703
  Response body (available only for providers that use HTTP requests).
2736
2704
  */
@@ -2819,6 +2787,42 @@ declare class NoSuchToolError extends AISDKError {
2819
2787
  static isInstance(error: unknown): error is NoSuchToolError;
2820
2788
  }
2821
2789
 
2790
+ /**
2791
+ * Appends a client message to the messages array.
2792
+ * If the last message in the array has the same id as the new message, it will be replaced.
2793
+ * Otherwise, the new message will be appended.
2794
+ */
2795
+ declare function appendClientMessage({ messages, message, }: {
2796
+ messages: Message[];
2797
+ message: Message;
2798
+ }): Message[];
2799
+
2800
+ /**
2801
+ * Appends the ResponseMessage[] from the response to a Message[] (for useChat).
2802
+ * The messages are converted to Messages before being appended.
2803
+ * Timestamps are generated for the new messages.
2804
+ *
2805
+ * @returns A new Message[] with the response messages appended.
2806
+ */
2807
+ declare function appendResponseMessages({ messages, responseMessages, _internal: { currentDate }, }: {
2808
+ messages: Message[];
2809
+ responseMessages: ResponseMessage[];
2810
+ /**
2811
+ Internal. For test use only. May change without notice.
2812
+ */
2813
+ _internal?: {
2814
+ currentDate?: () => Date;
2815
+ };
2816
+ }): Message[];
2817
+
2818
+ /**
2819
+ Converts an array of messages from useChat into an array of CoreMessages that can be used
2820
+ with the AI core functions (e.g. `streamText`).
2821
+ */
2822
+ declare function convertToCoreMessages<TOOLS extends ToolSet = never>(messages: Array<Omit<Message, 'id'>>, options?: {
2823
+ tools?: TOOLS;
2824
+ }): CoreMessage[];
2825
+
2822
2826
  /**
2823
2827
  * A function that attempts to repair a tool call that failed to parse.
2824
2828
  *
@@ -3110,7 +3114,7 @@ interface StreamTextResult<TOOLS extends ToolSet, PARTIAL_OUTPUT> {
3110
3114
  If there are tools that do not have execute functions, they are not included in the tool results and
3111
3115
  need to be added separately.
3112
3116
  */
3113
- messages: Array<CoreAssistantMessage | CoreToolMessage>;
3117
+ messages: Array<ResponseMessage>;
3114
3118
  }>;
3115
3119
  /**
3116
3120
  A text stream that returns only the generated text deltas. You can use it
package/dist/index.js CHANGED
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name17 in all)
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
 
30
20
  // streams/index.ts
@@ -4009,7 +3999,7 @@ async function generateText({
4009
3999
  }),
4010
4000
  tracer,
4011
4001
  fn: async (span) => {
4012
- var _a18, _b, _c, _d, _e, _f, _g, _h, _i, _j;
4002
+ var _a18, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
4013
4003
  const mode = {
4014
4004
  type: "regular",
4015
4005
  ...prepareToolsAndToolChoice({ tools, toolChoice, activeTools })
@@ -4215,6 +4205,7 @@ async function generateText({
4215
4205
  response: {
4216
4206
  ...currentModelResponse.response,
4217
4207
  headers: (_g = currentModelResponse.rawResponse) == null ? void 0 : _g.headers,
4208
+ body: (_h = currentModelResponse.rawResponse) == null ? void 0 : _h.body,
4218
4209
  // deep clone msgs to avoid mutating past messages in multi-step:
4219
4210
  messages: structuredClone(responseMessages)
4220
4211
  },
@@ -4261,11 +4252,11 @@ async function generateText({
4261
4252
  finishReason: currentModelResponse.finishReason,
4262
4253
  usage,
4263
4254
  warnings: currentModelResponse.warnings,
4264
- request: (_h = currentModelResponse.request) != null ? _h : {},
4255
+ request: (_i = currentModelResponse.request) != null ? _i : {},
4265
4256
  response: {
4266
4257
  ...currentModelResponse.response,
4267
- headers: (_i = currentModelResponse.rawResponse) == null ? void 0 : _i.headers,
4268
- body: (_j = currentModelResponse.rawResponse) == null ? void 0 : _j.body,
4258
+ headers: (_j = currentModelResponse.rawResponse) == null ? void 0 : _j.headers,
4259
+ body: (_k = currentModelResponse.rawResponse) == null ? void 0 : _k.body,
4269
4260
  messages: responseMessages
4270
4261
  },
4271
4262
  logprobs: currentModelResponse.logprobs,
@@ -6690,11 +6681,12 @@ async function createChildProcess(config, signal) {
6690
6681
  });
6691
6682
  }
6692
6683
  let childProcess;
6684
+ const nodePrefix = "node:";
6693
6685
  try {
6694
- childProcess = await import("child_process");
6686
+ childProcess = await import(`${nodePrefix}child_process`);
6695
6687
  } catch (error) {
6696
6688
  try {
6697
- childProcess = require("child_process");
6689
+ childProcess = require(`${nodePrefix}child_process`);
6698
6690
  } catch (innerError) {
6699
6691
  throw new MCPClientError({
6700
6692
  message: "Failed to load child_process module dynamically",