Skip to content

Commit

Permalink
Fix lint, add Node 18 fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoblee93 committed Jan 29, 2025
1 parent c4df945 commit d86cf20
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
28 changes: 25 additions & 3 deletions langchain-core/src/runnables/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -920,11 +920,33 @@ export abstract class Runnable<
const outerThis = this;
async function consumeRunnableStream() {
try {
let signal;
if (options?.signal) {
if ("any" in AbortSignal) {
// Use native AbortSignal.any() if available (Node 19+)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
signal = (AbortSignal as any).any([
abortController.signal,
options.signal,
]);
} else {
// Fallback for Node 18 and below - just use the provided signal
signal = options.signal;
// Ensure we still abort our controller when the parent signal aborts
options.signal.addEventListener(
"abort",
() => {
abortController.abort();
},
{ once: true }
);
}
} else {
signal = abortController.signal;
}
const runnableStream = await outerThis.stream(input, {
...config,
signal: options?.signal
? AbortSignal.any([options.signal, abortController.signal])
: abortController.signal,
signal,
});
const tappedStream = eventStreamer.tapOutputIterable(
runId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2271,6 +2271,7 @@ test("streamEvents method handles errors", async () => {
});

try {
// eslint-disable-next-line no-unreachable-loop
for await (const _ of model.streamEvents("Hello! Tell me about yourself.", {
version: "v2",
})) {
Expand Down

0 comments on commit d86cf20

Please sign in to comment.