@@ -456,6 +456,11 @@ export abstract class Runnable<
456456 return outputs ;
457457 }
458458
459+ /** @internal */
460+ _concatOutputChunks < O > ( first : O , second : O ) : O {
461+ return concat ( first , second ) ;
462+ }
463+
459464 /**
460465 * Helper method to transform an Iterator of Input values into an Iterator of
461466 * Output values, with callbacks.
@@ -480,15 +485,19 @@ export abstract class Runnable<
480485
481486 const config = ensureConfig ( options ) ;
482487 const callbackManager_ = await getCallbackManagerForConfig ( config ) ;
488+ const outerThis = this ;
483489 async function * wrapInputForTracing ( ) {
484490 for await ( const chunk of inputGenerator ) {
485491 if ( finalInputSupported ) {
486492 if ( finalInput === undefined ) {
487493 finalInput = chunk ;
488494 } else {
489495 try {
490- // eslint-disable-next-line @typescript-eslint/no-explicit-any
491- finalInput = concat ( finalInput , chunk as any ) ;
496+ finalInput = outerThis . _concatOutputChunks (
497+ finalInput ,
498+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
499+ chunk as any
500+ ) ;
492501 } catch {
493502 finalInput = undefined ;
494503 finalInputSupported = false ;
@@ -546,8 +555,11 @@ export abstract class Runnable<
546555 finalOutput = chunk ;
547556 } else {
548557 try {
549- // eslint-disable-next-line @typescript-eslint/no-explicit-any
550- finalOutput = concat ( finalOutput , chunk as any ) ;
558+ finalOutput = this . _concatOutputChunks (
559+ finalOutput ,
560+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
561+ chunk as any
562+ ) ;
551563 } catch {
552564 finalOutput = undefined ;
553565 finalOutputSupported = false ;
@@ -650,7 +662,7 @@ export abstract class Runnable<
650662 // Make a best effort to gather, for any type that supports concat.
651663 // This method should throw an error if gathering fails.
652664 // eslint-disable-next-line @typescript-eslint/no-explicit-any
653- finalChunk = concat ( finalChunk , chunk as any ) ;
665+ finalChunk = this . _concatOutputChunks ( finalChunk , chunk as any ) ;
654666 }
655667 }
656668 yield * this . _streamIterator ( finalChunk , ensureConfig ( options ) ) ;
@@ -1365,6 +1377,11 @@ export class RunnableBinding<
13651377 return this . bound . batch ( inputs , mergedOptions , batchOptions ) ;
13661378 }
13671379
1380+ /** @internal */
1381+ override _concatOutputChunks < O > ( first : O , second : O ) : O {
1382+ return this . bound . _concatOutputChunks ( first , second ) ;
1383+ }
1384+
13681385 async * _streamIterator (
13691386 input : RunInput ,
13701387 options ?: Partial < CallOptions > | undefined
@@ -1979,6 +1996,11 @@ export class RunnableSequence<
19791996 return nextStepInputs ;
19801997 }
19811998
1999+ /** @internal */
2000+ override _concatOutputChunks < O > ( first : O , second : O ) : O {
2001+ return this . last . _concatOutputChunks ( first , second ) ;
2002+ }
2003+
19822004 async * _streamIterator (
19832005 input : RunInput ,
19842006 options ?: RunnableConfig
@@ -2029,7 +2051,7 @@ export class RunnableSequence<
20292051 } else {
20302052 try {
20312053 // eslint-disable-next-line @typescript-eslint/no-explicit-any
2032- finalOutput = concat ( finalOutput , chunk as any ) ;
2054+ finalOutput = this . _concatOutputChunks ( finalOutput , chunk as any ) ;
20332055 } catch {
20342056 finalOutput = undefined ;
20352057 concatSupported = false ;
@@ -2563,8 +2585,11 @@ export class RunnableLambda<
25632585 } else {
25642586 // Make a best effort to gather, for any type that supports concat.
25652587 try {
2566- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2567- finalOutput = concat ( finalOutput , chunk as any ) ;
2588+ finalOutput = this . _concatOutputChunks (
2589+ finalOutput ,
2590+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2591+ chunk as any
2592+ ) ;
25682593 } catch {
25692594 finalOutput = chunk as RunOutput ;
25702595 }
@@ -2583,8 +2608,11 @@ export class RunnableLambda<
25832608 } else {
25842609 // Make a best effort to gather, for any type that supports concat.
25852610 try {
2586- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2587- finalOutput = concat ( finalOutput , chunk as any ) ;
2611+ finalOutput = this . _concatOutputChunks (
2612+ finalOutput ,
2613+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2614+ chunk as any
2615+ ) ;
25882616 } catch {
25892617 finalOutput = chunk as RunOutput ;
25902618 }
@@ -2621,7 +2649,7 @@ export class RunnableLambda<
26212649 // Make a best effort to gather, for any type that supports concat.
26222650 try {
26232651 // eslint-disable-next-line @typescript-eslint/no-explicit-any
2624- finalChunk = concat ( finalChunk , chunk as any ) ;
2652+ finalChunk = this . _concatOutputChunks ( finalChunk , chunk as any ) ;
26252653 } catch {
26262654 finalChunk = chunk ;
26272655 }
@@ -2928,7 +2956,10 @@ export class RunnableWithFallbacks<RunInput, RunOutput> extends Runnable<
29282956 for await ( const chunk of stream ) {
29292957 yield chunk ;
29302958 try {
2931- output = output === undefined ? output : concat ( output , chunk ) ;
2959+ output =
2960+ output === undefined
2961+ ? output
2962+ : this . _concatOutputChunks ( output , chunk ) ;
29322963 } catch {
29332964 output = undefined ;
29342965 }
0 commit comments