@langchain/core 0.3.36 → 0.3.38

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.
@@ -59,6 +59,14 @@ function _constructMessageFromParams(params) {
59
59
  className === "SystemMessageChunk") {
60
60
  type = "system";
61
61
  }
62
+ else if (className === "FunctionMessage" ||
63
+ className === "FunctionMessageChunk") {
64
+ type = "function";
65
+ }
66
+ else if (className === "ToolMessage" ||
67
+ className === "ToolMessageChunk") {
68
+ type = "tool";
69
+ }
62
70
  else {
63
71
  type = "unknown";
64
72
  }
@@ -56,6 +56,14 @@ function _constructMessageFromParams(params) {
56
56
  className === "SystemMessageChunk") {
57
57
  type = "system";
58
58
  }
59
+ else if (className === "FunctionMessage" ||
60
+ className === "FunctionMessageChunk") {
61
+ type = "function";
62
+ }
63
+ else if (className === "ToolMessage" ||
64
+ className === "ToolMessageChunk") {
65
+ type = "tool";
66
+ }
59
67
  else {
60
68
  type = "unknown";
61
69
  }
@@ -507,16 +507,44 @@ class Runnable extends serializable_js_1.Serializable {
507
507
  // eslint-disable-next-line no-param-reassign
508
508
  config.callbacks = copiedCallbacks;
509
509
  }
510
+ const abortController = new AbortController();
510
511
  // Call the runnable in streaming mode,
511
512
  // add each chunk to the output stream
512
513
  const outerThis = this;
513
514
  async function consumeRunnableStream() {
514
515
  try {
515
- const runnableStream = await outerThis.stream(input, config);
516
+ let signal;
517
+ if (options?.signal) {
518
+ if ("any" in AbortSignal) {
519
+ // Use native AbortSignal.any() if available (Node 19+)
520
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
521
+ signal = AbortSignal.any([
522
+ abortController.signal,
523
+ options.signal,
524
+ ]);
525
+ }
526
+ else {
527
+ // Fallback for Node 18 and below - just use the provided signal
528
+ signal = options.signal;
529
+ // Ensure we still abort our controller when the parent signal aborts
530
+ options.signal.addEventListener("abort", () => {
531
+ abortController.abort();
532
+ }, { once: true });
533
+ }
534
+ }
535
+ else {
536
+ signal = abortController.signal;
537
+ }
538
+ const runnableStream = await outerThis.stream(input, {
539
+ ...config,
540
+ signal,
541
+ });
516
542
  const tappedStream = eventStreamer.tapOutputIterable(runId, runnableStream);
517
543
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
518
544
  for await (const _ of tappedStream) {
519
545
  // Just iterate so that the callback handler picks up events
546
+ if (abortController.signal.aborted)
547
+ break;
520
548
  }
521
549
  }
522
550
  finally {
@@ -551,6 +579,7 @@ class Runnable extends serializable_js_1.Serializable {
551
579
  }
552
580
  }
553
581
  finally {
582
+ abortController.abort();
554
583
  await runnableStreamConsumePromise;
555
584
  }
556
585
  }
@@ -500,16 +500,44 @@ export class Runnable extends Serializable {
500
500
  // eslint-disable-next-line no-param-reassign
501
501
  config.callbacks = copiedCallbacks;
502
502
  }
503
+ const abortController = new AbortController();
503
504
  // Call the runnable in streaming mode,
504
505
  // add each chunk to the output stream
505
506
  const outerThis = this;
506
507
  async function consumeRunnableStream() {
507
508
  try {
508
- const runnableStream = await outerThis.stream(input, config);
509
+ let signal;
510
+ if (options?.signal) {
511
+ if ("any" in AbortSignal) {
512
+ // Use native AbortSignal.any() if available (Node 19+)
513
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
514
+ signal = AbortSignal.any([
515
+ abortController.signal,
516
+ options.signal,
517
+ ]);
518
+ }
519
+ else {
520
+ // Fallback for Node 18 and below - just use the provided signal
521
+ signal = options.signal;
522
+ // Ensure we still abort our controller when the parent signal aborts
523
+ options.signal.addEventListener("abort", () => {
524
+ abortController.abort();
525
+ }, { once: true });
526
+ }
527
+ }
528
+ else {
529
+ signal = abortController.signal;
530
+ }
531
+ const runnableStream = await outerThis.stream(input, {
532
+ ...config,
533
+ signal,
534
+ });
509
535
  const tappedStream = eventStreamer.tapOutputIterable(runId, runnableStream);
510
536
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
511
537
  for await (const _ of tappedStream) {
512
538
  // Just iterate so that the callback handler picks up events
539
+ if (abortController.signal.aborted)
540
+ break;
513
541
  }
514
542
  }
515
543
  finally {
@@ -544,6 +572,7 @@ export class Runnable extends Serializable {
544
572
  }
545
573
  }
546
574
  finally {
575
+ abortController.abort();
547
576
  await runnableStreamConsumePromise;
548
577
  }
549
578
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/core",
3
- "version": "0.3.36",
3
+ "version": "0.3.38",
4
4
  "description": "Core LangChain.js abstractions and schemas",
5
5
  "type": "module",
6
6
  "engines": {