@langchain/core 0.2.31 → 0.2.32

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.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AIMessageChunk = exports.isAIMessage = exports.AIMessage = void 0;
3
+ exports.AIMessageChunk = exports.isAIMessageChunk = exports.isAIMessage = exports.AIMessage = void 0;
4
4
  const json_js_1 = require("../utils/json.cjs");
5
5
  const base_js_1 = require("./base.cjs");
6
6
  const tool_js_1 = require("./tool.cjs");
@@ -112,6 +112,10 @@ function isAIMessage(x) {
112
112
  return x._getType() === "ai";
113
113
  }
114
114
  exports.isAIMessage = isAIMessage;
115
+ function isAIMessageChunk(x) {
116
+ return x._getType() === "ai";
117
+ }
118
+ exports.isAIMessageChunk = isAIMessageChunk;
115
119
  /**
116
120
  * Represents a chunk of an AI message, which can be concatenated with
117
121
  * other AI message chunks.
@@ -41,6 +41,7 @@ export declare class AIMessage extends BaseMessage {
41
41
  get _printableFields(): Record<string, unknown>;
42
42
  }
43
43
  export declare function isAIMessage(x: BaseMessage): x is AIMessage;
44
+ export declare function isAIMessageChunk(x: BaseMessageChunk): x is AIMessageChunk;
44
45
  export type AIMessageChunkFields = AIMessageFields & {
45
46
  tool_call_chunks?: ToolCallChunk[];
46
47
  };
@@ -107,6 +107,9 @@ export class AIMessage extends BaseMessage {
107
107
  export function isAIMessage(x) {
108
108
  return x._getType() === "ai";
109
109
  }
110
+ export function isAIMessageChunk(x) {
111
+ return x._getType() === "ai";
112
+ }
110
113
  /**
111
114
  * Represents a chunk of an AI message, which can be concatenated with
112
115
  * other AI message chunks.
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.JsonOutputKeyToolsParser = exports.JsonOutputToolsParser = exports.makeInvalidToolCall = exports.convertLangChainToolCallToOpenAI = exports.parseToolCall = void 0;
4
4
  const base_js_1 = require("../base.cjs");
5
5
  const json_js_1 = require("../json.cjs");
6
+ const transform_js_1 = require("../transform.cjs");
7
+ const ai_js_1 = require("../../messages/ai.cjs");
6
8
  function parseToolCall(
7
9
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
8
10
  rawToolCall, options) {
@@ -74,7 +76,7 @@ exports.makeInvalidToolCall = makeInvalidToolCall;
74
76
  /**
75
77
  * Class for parsing the output of a tool-calling LLM into a JSON object.
76
78
  */
77
- class JsonOutputToolsParser extends base_js_1.BaseLLMOutputParser {
79
+ class JsonOutputToolsParser extends transform_js_1.BaseCumulativeTransformOutputParser {
78
80
  static lc_name() {
79
81
  return "JsonOutputToolsParser";
80
82
  }
@@ -100,29 +102,58 @@ class JsonOutputToolsParser extends base_js_1.BaseLLMOutputParser {
100
102
  });
101
103
  this.returnId = fields?.returnId ?? this.returnId;
102
104
  }
105
+ _diff() {
106
+ throw new Error("Not supported.");
107
+ }
108
+ async parse() {
109
+ throw new Error("Not implemented.");
110
+ }
111
+ async parseResult(generations) {
112
+ const result = await this.parsePartialResult(generations, false);
113
+ return result;
114
+ }
103
115
  /**
104
116
  * Parses the output and returns a JSON object. If `argsOnly` is true,
105
117
  * only the arguments of the function call are returned.
106
118
  * @param generations The output of the LLM to parse.
107
119
  * @returns A JSON object representation of the function call or its arguments.
108
120
  */
109
- async parseResult(generations) {
110
- const toolCalls = generations[0].message.additional_kwargs.tool_calls;
121
+ async parsePartialResult(generations, partial = true
122
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
123
+ ) {
124
+ const message = generations[0].message;
125
+ let toolCalls;
126
+ if ((0, ai_js_1.isAIMessage)(message) && message.tool_calls?.length) {
127
+ toolCalls = message.tool_calls.map((toolCall) => {
128
+ const { id, ...rest } = toolCall;
129
+ if (!this.returnId) {
130
+ return rest;
131
+ }
132
+ return {
133
+ id,
134
+ ...rest,
135
+ };
136
+ });
137
+ }
138
+ else if (message.additional_kwargs.tool_calls !== undefined) {
139
+ const rawToolCalls = JSON.parse(JSON.stringify(message.additional_kwargs.tool_calls));
140
+ toolCalls = rawToolCalls.map((rawToolCall) => {
141
+ return parseToolCall(rawToolCall, { returnId: this.returnId, partial });
142
+ });
143
+ }
111
144
  if (!toolCalls) {
112
- throw new Error(`No tools_call in message ${JSON.stringify(generations)}`);
145
+ return [];
113
146
  }
114
- const clonedToolCalls = JSON.parse(JSON.stringify(toolCalls));
115
147
  const parsedToolCalls = [];
116
- for (const toolCall of clonedToolCalls) {
117
- const parsedToolCall = parseToolCall(toolCall, { partial: true });
118
- if (parsedToolCall !== undefined) {
148
+ for (const toolCall of toolCalls) {
149
+ if (toolCall !== undefined) {
119
150
  // backward-compatibility with previous
120
151
  // versions of Langchain JS, which uses `name` and `arguments`
121
152
  // @ts-expect-error name and arguemnts are defined by Object.defineProperty
122
153
  const backwardsCompatibleToolCall = {
123
- type: parsedToolCall.name,
124
- args: parsedToolCall.args,
125
- id: parsedToolCall.id,
154
+ type: toolCall.name,
155
+ args: toolCall.args,
156
+ id: toolCall.id,
126
157
  };
127
158
  Object.defineProperty(backwardsCompatibleToolCall, "name", {
128
159
  get() {
@@ -145,7 +176,7 @@ exports.JsonOutputToolsParser = JsonOutputToolsParser;
145
176
  * Class for parsing the output of a tool-calling LLM into a JSON object if you are
146
177
  * expecting only a single tool to be called.
147
178
  */
148
- class JsonOutputKeyToolsParser extends base_js_1.BaseLLMOutputParser {
179
+ class JsonOutputKeyToolsParser extends JsonOutputToolsParser {
149
180
  static lc_name() {
150
181
  return "JsonOutputKeyToolsParser";
151
182
  }
@@ -183,12 +214,6 @@ class JsonOutputKeyToolsParser extends base_js_1.BaseLLMOutputParser {
183
214
  writable: true,
184
215
  value: false
185
216
  });
186
- Object.defineProperty(this, "initialParser", {
187
- enumerable: true,
188
- configurable: true,
189
- writable: true,
190
- value: void 0
191
- });
192
217
  Object.defineProperty(this, "zodSchema", {
193
218
  enumerable: true,
194
219
  configurable: true,
@@ -197,7 +222,6 @@ class JsonOutputKeyToolsParser extends base_js_1.BaseLLMOutputParser {
197
222
  });
198
223
  this.keyName = params.keyName;
199
224
  this.returnSingle = params.returnSingle ?? this.returnSingle;
200
- this.initialParser = new JsonOutputToolsParser(params);
201
225
  this.zodSchema = params.zodSchema;
202
226
  }
203
227
  async _validateResult(result) {
@@ -213,11 +237,31 @@ class JsonOutputKeyToolsParser extends base_js_1.BaseLLMOutputParser {
213
237
  }
214
238
  }
215
239
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
240
+ async parsePartialResult(generations) {
241
+ const results = await super.parsePartialResult(generations);
242
+ const matchingResults = results.filter((result) => result.type === this.keyName);
243
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
244
+ let returnedValues = matchingResults;
245
+ if (!matchingResults.length) {
246
+ return undefined;
247
+ }
248
+ if (!this.returnId) {
249
+ returnedValues = matchingResults.map((result) => result.args);
250
+ }
251
+ if (this.returnSingle) {
252
+ return returnedValues[0];
253
+ }
254
+ return returnedValues;
255
+ }
256
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
216
257
  async parseResult(generations) {
217
- const results = await this.initialParser.parseResult(generations);
258
+ const results = await super.parsePartialResult(generations, false);
218
259
  const matchingResults = results.filter((result) => result.type === this.keyName);
219
260
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
220
261
  let returnedValues = matchingResults;
262
+ if (!matchingResults.length) {
263
+ return undefined;
264
+ }
221
265
  if (!this.returnId) {
222
266
  returnedValues = matchingResults.map((result) => result.args);
223
267
  }
@@ -1,7 +1,7 @@
1
1
  import { z } from "zod";
2
- import { ChatGeneration } from "../../outputs.js";
3
- import { BaseLLMOutputParser } from "../base.js";
2
+ import { ChatGeneration, ChatGenerationChunk } from "../../outputs.js";
4
3
  import { InvalidToolCall, ToolCall } from "../../messages/tool.js";
4
+ import { BaseCumulativeTransformOutputParser, BaseCumulativeTransformOutputParserInput } from "../transform.js";
5
5
  export type ParsedToolCall = {
6
6
  id?: string;
7
7
  type: string;
@@ -14,7 +14,7 @@ export type ParsedToolCall = {
14
14
  export type JsonOutputToolsParserParams = {
15
15
  /** Whether to return the tool call id. */
16
16
  returnId?: boolean;
17
- };
17
+ } & BaseCumulativeTransformOutputParserInput;
18
18
  export declare function parseToolCall(rawToolCall: Record<string, any>, options: {
19
19
  returnId?: boolean;
20
20
  partial: true;
@@ -23,6 +23,10 @@ export declare function parseToolCall(rawToolCall: Record<string, any>, options?
23
23
  returnId?: boolean;
24
24
  partial?: false;
25
25
  }): ToolCall;
26
+ export declare function parseToolCall(rawToolCall: Record<string, any>, options?: {
27
+ returnId?: boolean;
28
+ partial?: boolean;
29
+ }): ToolCall | undefined;
26
30
  export declare function convertLangChainToolCallToOpenAI(toolCall: ToolCall): {
27
31
  id: string;
28
32
  type: string;
@@ -35,32 +39,33 @@ export declare function makeInvalidToolCall(rawToolCall: Record<string, any>, er
35
39
  /**
36
40
  * Class for parsing the output of a tool-calling LLM into a JSON object.
37
41
  */
38
- export declare class JsonOutputToolsParser extends BaseLLMOutputParser<ParsedToolCall[]> {
42
+ export declare class JsonOutputToolsParser<T> extends BaseCumulativeTransformOutputParser<T> {
39
43
  static lc_name(): string;
40
44
  returnId: boolean;
41
45
  lc_namespace: string[];
42
46
  lc_serializable: boolean;
43
47
  constructor(fields?: JsonOutputToolsParserParams);
48
+ protected _diff(): void;
49
+ parse(): Promise<T>;
50
+ parseResult(generations: ChatGeneration[]): Promise<T>;
44
51
  /**
45
52
  * Parses the output and returns a JSON object. If `argsOnly` is true,
46
53
  * only the arguments of the function call are returned.
47
54
  * @param generations The output of the LLM to parse.
48
55
  * @returns A JSON object representation of the function call or its arguments.
49
56
  */
50
- parseResult(generations: ChatGeneration[]): Promise<ParsedToolCall[]>;
57
+ parsePartialResult(generations: ChatGenerationChunk[] | ChatGeneration[], partial?: boolean): Promise<any>;
51
58
  }
52
59
  export type JsonOutputKeyToolsParserParams<T extends Record<string, any> = Record<string, any>> = {
53
60
  keyName: string;
54
61
  returnSingle?: boolean;
55
- /** Whether to return the tool call id. */
56
- returnId?: boolean;
57
62
  zodSchema?: z.ZodType<T>;
58
- };
63
+ } & JsonOutputToolsParserParams;
59
64
  /**
60
65
  * Class for parsing the output of a tool-calling LLM into a JSON object if you are
61
66
  * expecting only a single tool to be called.
62
67
  */
63
- export declare class JsonOutputKeyToolsParser<T extends Record<string, any> = Record<string, any>> extends BaseLLMOutputParser<T> {
68
+ export declare class JsonOutputKeyToolsParser<T extends Record<string, any> = Record<string, any>> extends JsonOutputToolsParser<T> {
64
69
  static lc_name(): string;
65
70
  lc_namespace: string[];
66
71
  lc_serializable: boolean;
@@ -69,9 +74,9 @@ export declare class JsonOutputKeyToolsParser<T extends Record<string, any> = Re
69
74
  keyName: string;
70
75
  /** Whether to return only the first tool call. */
71
76
  returnSingle: boolean;
72
- initialParser: JsonOutputToolsParser;
73
77
  zodSchema?: z.ZodType<T>;
74
78
  constructor(params: JsonOutputKeyToolsParserParams<T>);
75
79
  protected _validateResult(result: unknown): Promise<T>;
80
+ parsePartialResult(generations: ChatGeneration[]): Promise<any>;
76
81
  parseResult(generations: ChatGeneration[]): Promise<any>;
77
82
  }
@@ -1,5 +1,7 @@
1
- import { BaseLLMOutputParser, OutputParserException } from "../base.js";
1
+ import { OutputParserException } from "../base.js";
2
2
  import { parsePartialJson } from "../json.js";
3
+ import { BaseCumulativeTransformOutputParser, } from "../transform.js";
4
+ import { isAIMessage } from "../../messages/ai.js";
3
5
  export function parseToolCall(
4
6
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
5
7
  rawToolCall, options) {
@@ -68,7 +70,7 @@ rawToolCall, errorMsg) {
68
70
  /**
69
71
  * Class for parsing the output of a tool-calling LLM into a JSON object.
70
72
  */
71
- export class JsonOutputToolsParser extends BaseLLMOutputParser {
73
+ export class JsonOutputToolsParser extends BaseCumulativeTransformOutputParser {
72
74
  static lc_name() {
73
75
  return "JsonOutputToolsParser";
74
76
  }
@@ -94,29 +96,58 @@ export class JsonOutputToolsParser extends BaseLLMOutputParser {
94
96
  });
95
97
  this.returnId = fields?.returnId ?? this.returnId;
96
98
  }
99
+ _diff() {
100
+ throw new Error("Not supported.");
101
+ }
102
+ async parse() {
103
+ throw new Error("Not implemented.");
104
+ }
105
+ async parseResult(generations) {
106
+ const result = await this.parsePartialResult(generations, false);
107
+ return result;
108
+ }
97
109
  /**
98
110
  * Parses the output and returns a JSON object. If `argsOnly` is true,
99
111
  * only the arguments of the function call are returned.
100
112
  * @param generations The output of the LLM to parse.
101
113
  * @returns A JSON object representation of the function call or its arguments.
102
114
  */
103
- async parseResult(generations) {
104
- const toolCalls = generations[0].message.additional_kwargs.tool_calls;
115
+ async parsePartialResult(generations, partial = true
116
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
117
+ ) {
118
+ const message = generations[0].message;
119
+ let toolCalls;
120
+ if (isAIMessage(message) && message.tool_calls?.length) {
121
+ toolCalls = message.tool_calls.map((toolCall) => {
122
+ const { id, ...rest } = toolCall;
123
+ if (!this.returnId) {
124
+ return rest;
125
+ }
126
+ return {
127
+ id,
128
+ ...rest,
129
+ };
130
+ });
131
+ }
132
+ else if (message.additional_kwargs.tool_calls !== undefined) {
133
+ const rawToolCalls = JSON.parse(JSON.stringify(message.additional_kwargs.tool_calls));
134
+ toolCalls = rawToolCalls.map((rawToolCall) => {
135
+ return parseToolCall(rawToolCall, { returnId: this.returnId, partial });
136
+ });
137
+ }
105
138
  if (!toolCalls) {
106
- throw new Error(`No tools_call in message ${JSON.stringify(generations)}`);
139
+ return [];
107
140
  }
108
- const clonedToolCalls = JSON.parse(JSON.stringify(toolCalls));
109
141
  const parsedToolCalls = [];
110
- for (const toolCall of clonedToolCalls) {
111
- const parsedToolCall = parseToolCall(toolCall, { partial: true });
112
- if (parsedToolCall !== undefined) {
142
+ for (const toolCall of toolCalls) {
143
+ if (toolCall !== undefined) {
113
144
  // backward-compatibility with previous
114
145
  // versions of Langchain JS, which uses `name` and `arguments`
115
146
  // @ts-expect-error name and arguemnts are defined by Object.defineProperty
116
147
  const backwardsCompatibleToolCall = {
117
- type: parsedToolCall.name,
118
- args: parsedToolCall.args,
119
- id: parsedToolCall.id,
148
+ type: toolCall.name,
149
+ args: toolCall.args,
150
+ id: toolCall.id,
120
151
  };
121
152
  Object.defineProperty(backwardsCompatibleToolCall, "name", {
122
153
  get() {
@@ -138,7 +169,7 @@ export class JsonOutputToolsParser extends BaseLLMOutputParser {
138
169
  * Class for parsing the output of a tool-calling LLM into a JSON object if you are
139
170
  * expecting only a single tool to be called.
140
171
  */
141
- export class JsonOutputKeyToolsParser extends BaseLLMOutputParser {
172
+ export class JsonOutputKeyToolsParser extends JsonOutputToolsParser {
142
173
  static lc_name() {
143
174
  return "JsonOutputKeyToolsParser";
144
175
  }
@@ -176,12 +207,6 @@ export class JsonOutputKeyToolsParser extends BaseLLMOutputParser {
176
207
  writable: true,
177
208
  value: false
178
209
  });
179
- Object.defineProperty(this, "initialParser", {
180
- enumerable: true,
181
- configurable: true,
182
- writable: true,
183
- value: void 0
184
- });
185
210
  Object.defineProperty(this, "zodSchema", {
186
211
  enumerable: true,
187
212
  configurable: true,
@@ -190,7 +215,6 @@ export class JsonOutputKeyToolsParser extends BaseLLMOutputParser {
190
215
  });
191
216
  this.keyName = params.keyName;
192
217
  this.returnSingle = params.returnSingle ?? this.returnSingle;
193
- this.initialParser = new JsonOutputToolsParser(params);
194
218
  this.zodSchema = params.zodSchema;
195
219
  }
196
220
  async _validateResult(result) {
@@ -206,11 +230,31 @@ export class JsonOutputKeyToolsParser extends BaseLLMOutputParser {
206
230
  }
207
231
  }
208
232
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
233
+ async parsePartialResult(generations) {
234
+ const results = await super.parsePartialResult(generations);
235
+ const matchingResults = results.filter((result) => result.type === this.keyName);
236
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
237
+ let returnedValues = matchingResults;
238
+ if (!matchingResults.length) {
239
+ return undefined;
240
+ }
241
+ if (!this.returnId) {
242
+ returnedValues = matchingResults.map((result) => result.args);
243
+ }
244
+ if (this.returnSingle) {
245
+ return returnedValues[0];
246
+ }
247
+ return returnedValues;
248
+ }
249
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
209
250
  async parseResult(generations) {
210
- const results = await this.initialParser.parseResult(generations);
251
+ const results = await super.parsePartialResult(generations, false);
211
252
  const matchingResults = results.filter((result) => result.type === this.keyName);
212
253
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
213
254
  let returnedValues = matchingResults;
255
+ if (!matchingResults.length) {
256
+ return undefined;
257
+ }
214
258
  if (!this.returnId) {
215
259
  returnedValues = matchingResults.map((result) => result.args);
216
260
  }
@@ -105,5 +105,8 @@ class BaseCumulativeTransformOutputParser extends BaseTransformOutputParser {
105
105
  }
106
106
  }
107
107
  }
108
+ getFormatInstructions() {
109
+ return "";
110
+ }
108
111
  }
109
112
  exports.BaseCumulativeTransformOutputParser = BaseCumulativeTransformOutputParser;
@@ -30,4 +30,5 @@ export declare abstract class BaseCumulativeTransformOutputParser<T = unknown> e
30
30
  protected abstract _diff(prev: any | undefined, next: any): any;
31
31
  abstract parsePartialResult(generations: Generation[] | ChatGeneration[]): Promise<T | undefined>;
32
32
  _transform(inputGenerator: AsyncGenerator<string | BaseMessage>): AsyncGenerator<T>;
33
+ getFormatInstructions(): string;
33
34
  }
@@ -101,4 +101,7 @@ export class BaseCumulativeTransformOutputParser extends BaseTransformOutputPars
101
101
  }
102
102
  }
103
103
  }
104
+ getFormatInstructions() {
105
+ return "";
106
+ }
104
107
  }
@@ -68,6 +68,11 @@ class IterableReadableStream extends ReadableStream {
68
68
  [Symbol.asyncIterator]() {
69
69
  return this;
70
70
  }
71
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
72
+ // @ts-ignore Not present in Node 18 types, required in latest Node 22
73
+ async [Symbol.asyncDispose]() {
74
+ await this.return();
75
+ }
71
76
  static fromReadableStream(stream) {
72
77
  // From https://developer.mozilla.org/en-US/docs/Web/API/Streams_API/Using_readable_streams#reading_the_stream
73
78
  const reader = stream.getReader();
@@ -249,6 +254,11 @@ class AsyncGeneratorWithSetup {
249
254
  [Symbol.asyncIterator]() {
250
255
  return this;
251
256
  }
257
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
258
+ // @ts-ignore Not present in Node 18 types, required in latest Node 22
259
+ async [Symbol.asyncDispose]() {
260
+ await this.return();
261
+ }
252
262
  }
253
263
  exports.AsyncGeneratorWithSetup = AsyncGeneratorWithSetup;
254
264
  async function pipeGeneratorWithSetup(to, generator, startSetup, signal, ...args) {
@@ -6,6 +6,7 @@ export declare class IterableReadableStream<T> extends ReadableStream<T> impleme
6
6
  return(): Promise<IteratorResult<T>>;
7
7
  throw(e: any): Promise<IteratorResult<T>>;
8
8
  [Symbol.asyncIterator](): this;
9
+ [Symbol.asyncDispose](): Promise<void>;
9
10
  static fromReadableStream<T>(stream: ReadableStream<T>): IterableReadableStream<T>;
10
11
  static fromAsyncGenerator<T>(generator: AsyncGenerator<T>): IterableReadableStream<T>;
11
12
  }
@@ -25,9 +26,10 @@ export declare class AsyncGeneratorWithSetup<S = unknown, T = unknown, TReturn =
25
26
  signal?: AbortSignal;
26
27
  });
27
28
  next(...args: [] | [TNext]): Promise<IteratorResult<T>>;
28
- return(value: TReturn | PromiseLike<TReturn>): Promise<IteratorResult<T>>;
29
+ return(value?: TReturn | PromiseLike<TReturn>): Promise<IteratorResult<T>>;
29
30
  throw(e: Error): Promise<IteratorResult<T>>;
30
31
  [Symbol.asyncIterator](): this;
32
+ [Symbol.asyncDispose](): Promise<void>;
31
33
  }
32
34
  export declare function pipeGeneratorWithSetup<S, A extends unknown[], T, TReturn, TNext, U, UReturn, UNext>(to: (g: AsyncGenerator<T, TReturn, TNext>, s: S, ...args: A) => AsyncGenerator<U, UReturn, UNext>, generator: AsyncGenerator<T, TReturn, TNext>, startSetup: () => Promise<S>, signal: AbortSignal | undefined, ...args: A): Promise<{
33
35
  output: AsyncGenerator<U, UReturn, UNext>;
@@ -65,6 +65,11 @@ export class IterableReadableStream extends ReadableStream {
65
65
  [Symbol.asyncIterator]() {
66
66
  return this;
67
67
  }
68
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
69
+ // @ts-ignore Not present in Node 18 types, required in latest Node 22
70
+ async [Symbol.asyncDispose]() {
71
+ await this.return();
72
+ }
68
73
  static fromReadableStream(stream) {
69
74
  // From https://developer.mozilla.org/en-US/docs/Web/API/Streams_API/Using_readable_streams#reading_the_stream
70
75
  const reader = stream.getReader();
@@ -243,6 +248,11 @@ export class AsyncGeneratorWithSetup {
243
248
  [Symbol.asyncIterator]() {
244
249
  return this;
245
250
  }
251
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
252
+ // @ts-ignore Not present in Node 18 types, required in latest Node 22
253
+ async [Symbol.asyncDispose]() {
254
+ await this.return();
255
+ }
246
256
  }
247
257
  export async function pipeGeneratorWithSetup(to, generator, startSetup, signal, ...args) {
248
258
  const gen = new AsyncGeneratorWithSetup({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/core",
3
- "version": "0.2.31",
3
+ "version": "0.2.32",
4
4
  "description": "Core LangChain.js abstractions and schemas",
5
5
  "type": "module",
6
6
  "engines": {