@langchain/core 0.3.71-rc.0 → 0.3.72
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.
|
@@ -28,6 +28,13 @@ class JsonOutputParser extends transform_js_1.BaseCumulativeTransformOutputParse
|
|
|
28
28
|
static lc_name() {
|
|
29
29
|
return "JsonOutputParser";
|
|
30
30
|
}
|
|
31
|
+
/** @internal */
|
|
32
|
+
_concatOutputChunks(first, second) {
|
|
33
|
+
if (this.diff) {
|
|
34
|
+
return super._concatOutputChunks(first, second);
|
|
35
|
+
}
|
|
36
|
+
return second;
|
|
37
|
+
}
|
|
31
38
|
_diff(prev, next) {
|
|
32
39
|
if (!next) {
|
|
33
40
|
return undefined;
|
|
@@ -9,6 +9,8 @@ export declare class JsonOutputParser<T extends Record<string, any> = Record<str
|
|
|
9
9
|
static lc_name(): string;
|
|
10
10
|
lc_namespace: string[];
|
|
11
11
|
lc_serializable: boolean;
|
|
12
|
+
/** @internal */
|
|
13
|
+
_concatOutputChunks<T>(first: T, second: T): T;
|
|
12
14
|
protected _diff(prev: unknown | undefined, next: unknown): Operation[] | undefined;
|
|
13
15
|
parsePartialResult(generations: ChatGeneration[] | Generation[]): Promise<T | undefined>;
|
|
14
16
|
parse(text: string): Promise<T>;
|
|
@@ -23,6 +23,13 @@ export class JsonOutputParser extends BaseCumulativeTransformOutputParser {
|
|
|
23
23
|
static lc_name() {
|
|
24
24
|
return "JsonOutputParser";
|
|
25
25
|
}
|
|
26
|
+
/** @internal */
|
|
27
|
+
_concatOutputChunks(first, second) {
|
|
28
|
+
if (this.diff) {
|
|
29
|
+
return super._concatOutputChunks(first, second);
|
|
30
|
+
}
|
|
31
|
+
return second;
|
|
32
|
+
}
|
|
26
33
|
_diff(prev, next) {
|
|
27
34
|
if (!next) {
|
|
28
35
|
return undefined;
|
package/dist/runnables/base.cjs
CHANGED
|
@@ -267,6 +267,10 @@ class Runnable extends serializable_js_1.Serializable {
|
|
|
267
267
|
await Promise.all(runManagers.map((runManager) => runManager?.handleChainEnd(_coerceToDict(outputs, "output"))));
|
|
268
268
|
return outputs;
|
|
269
269
|
}
|
|
270
|
+
/** @internal */
|
|
271
|
+
_concatOutputChunks(first, second) {
|
|
272
|
+
return (0, stream_js_1.concat)(first, second);
|
|
273
|
+
}
|
|
270
274
|
/**
|
|
271
275
|
* Helper method to transform an Iterator of Input values into an Iterator of
|
|
272
276
|
* Output values, with callbacks.
|
|
@@ -279,6 +283,7 @@ class Runnable extends serializable_js_1.Serializable {
|
|
|
279
283
|
let finalOutputSupported = true;
|
|
280
284
|
const config = (0, config_js_1.ensureConfig)(options);
|
|
281
285
|
const callbackManager_ = await (0, config_js_1.getCallbackManagerForConfig)(config);
|
|
286
|
+
const outerThis = this;
|
|
282
287
|
async function* wrapInputForTracing() {
|
|
283
288
|
for await (const chunk of inputGenerator) {
|
|
284
289
|
if (finalInputSupported) {
|
|
@@ -287,8 +292,9 @@ class Runnable extends serializable_js_1.Serializable {
|
|
|
287
292
|
}
|
|
288
293
|
else {
|
|
289
294
|
try {
|
|
295
|
+
finalInput = outerThis._concatOutputChunks(finalInput,
|
|
290
296
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
291
|
-
|
|
297
|
+
chunk);
|
|
292
298
|
}
|
|
293
299
|
catch {
|
|
294
300
|
finalInput = undefined;
|
|
@@ -321,8 +327,9 @@ class Runnable extends serializable_js_1.Serializable {
|
|
|
321
327
|
}
|
|
322
328
|
else {
|
|
323
329
|
try {
|
|
330
|
+
finalOutput = this._concatOutputChunks(finalOutput,
|
|
324
331
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
325
|
-
|
|
332
|
+
chunk);
|
|
326
333
|
}
|
|
327
334
|
catch {
|
|
328
335
|
finalOutput = undefined;
|
|
@@ -404,7 +411,7 @@ class Runnable extends serializable_js_1.Serializable {
|
|
|
404
411
|
// Make a best effort to gather, for any type that supports concat.
|
|
405
412
|
// This method should throw an error if gathering fails.
|
|
406
413
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
407
|
-
finalChunk =
|
|
414
|
+
finalChunk = this._concatOutputChunks(finalChunk, chunk);
|
|
408
415
|
}
|
|
409
416
|
}
|
|
410
417
|
yield* this._streamIterator(finalChunk, (0, config_js_1.ensureConfig)(options));
|
|
@@ -923,6 +930,10 @@ class RunnableBinding extends Runnable {
|
|
|
923
930
|
: await this._mergeConfig((0, config_js_1.ensureConfig)(options), this.kwargs);
|
|
924
931
|
return this.bound.batch(inputs, mergedOptions, batchOptions);
|
|
925
932
|
}
|
|
933
|
+
/** @internal */
|
|
934
|
+
_concatOutputChunks(first, second) {
|
|
935
|
+
return this.bound._concatOutputChunks(first, second);
|
|
936
|
+
}
|
|
926
937
|
async *_streamIterator(input, options) {
|
|
927
938
|
yield* this.bound._streamIterator(input, await this._mergeConfig((0, config_js_1.ensureConfig)(options), this.kwargs));
|
|
928
939
|
}
|
|
@@ -1351,6 +1362,10 @@ class RunnableSequence extends Runnable {
|
|
|
1351
1362
|
await Promise.all(runManagers.map((runManager) => runManager?.handleChainEnd(_coerceToDict(nextStepInputs, "output"))));
|
|
1352
1363
|
return nextStepInputs;
|
|
1353
1364
|
}
|
|
1365
|
+
/** @internal */
|
|
1366
|
+
_concatOutputChunks(first, second) {
|
|
1367
|
+
return this.last._concatOutputChunks(first, second);
|
|
1368
|
+
}
|
|
1354
1369
|
async *_streamIterator(input, options) {
|
|
1355
1370
|
const callbackManager_ = await (0, config_js_1.getCallbackManagerForConfig)(options);
|
|
1356
1371
|
const { runId, ...otherOptions } = options ?? {};
|
|
@@ -1381,7 +1396,7 @@ class RunnableSequence extends Runnable {
|
|
|
1381
1396
|
else {
|
|
1382
1397
|
try {
|
|
1383
1398
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1384
|
-
finalOutput =
|
|
1399
|
+
finalOutput = this._concatOutputChunks(finalOutput, chunk);
|
|
1385
1400
|
}
|
|
1386
1401
|
catch (e) {
|
|
1387
1402
|
finalOutput = undefined;
|
|
@@ -1735,8 +1750,9 @@ class RunnableLambda extends Runnable {
|
|
|
1735
1750
|
else {
|
|
1736
1751
|
// Make a best effort to gather, for any type that supports concat.
|
|
1737
1752
|
try {
|
|
1753
|
+
finalOutput = this._concatOutputChunks(finalOutput,
|
|
1738
1754
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1739
|
-
|
|
1755
|
+
chunk);
|
|
1740
1756
|
}
|
|
1741
1757
|
catch (e) {
|
|
1742
1758
|
finalOutput = chunk;
|
|
@@ -1755,8 +1771,9 @@ class RunnableLambda extends Runnable {
|
|
|
1755
1771
|
else {
|
|
1756
1772
|
// Make a best effort to gather, for any type that supports concat.
|
|
1757
1773
|
try {
|
|
1774
|
+
finalOutput = this._concatOutputChunks(finalOutput,
|
|
1758
1775
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1759
|
-
|
|
1776
|
+
chunk);
|
|
1760
1777
|
}
|
|
1761
1778
|
catch (e) {
|
|
1762
1779
|
finalOutput = chunk;
|
|
@@ -1786,7 +1803,7 @@ class RunnableLambda extends Runnable {
|
|
|
1786
1803
|
// Make a best effort to gather, for any type that supports concat.
|
|
1787
1804
|
try {
|
|
1788
1805
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1789
|
-
finalChunk =
|
|
1806
|
+
finalChunk = this._concatOutputChunks(finalChunk, chunk);
|
|
1790
1807
|
}
|
|
1791
1808
|
catch (e) {
|
|
1792
1809
|
finalChunk = chunk;
|
|
@@ -2060,7 +2077,10 @@ class RunnableWithFallbacks extends Runnable {
|
|
|
2060
2077
|
for await (const chunk of stream) {
|
|
2061
2078
|
yield chunk;
|
|
2062
2079
|
try {
|
|
2063
|
-
output =
|
|
2080
|
+
output =
|
|
2081
|
+
output === undefined
|
|
2082
|
+
? output
|
|
2083
|
+
: this._concatOutputChunks(output, chunk);
|
|
2064
2084
|
}
|
|
2065
2085
|
catch (e) {
|
|
2066
2086
|
output = undefined;
|
package/dist/runnables/base.d.ts
CHANGED
|
@@ -116,6 +116,8 @@ export declare abstract class Runnable<RunInput = any, RunOutput = any, CallOpti
|
|
|
116
116
|
}> | Partial<CallOptions & {
|
|
117
117
|
runType?: string;
|
|
118
118
|
}>[], batchOptions?: RunnableBatchOptions): Promise<(RunOutput | Error)[]>;
|
|
119
|
+
/** @internal */
|
|
120
|
+
_concatOutputChunks<O>(first: O, second: O): O;
|
|
119
121
|
/**
|
|
120
122
|
* Helper method to transform an Iterator of Input values into an Iterator of
|
|
121
123
|
* Output values, with callbacks.
|
|
@@ -395,6 +397,8 @@ export declare class RunnableBinding<RunInput, RunOutput, CallOptions extends Ru
|
|
|
395
397
|
returnExceptions: true;
|
|
396
398
|
}): Promise<(RunOutput | Error)[]>;
|
|
397
399
|
batch(inputs: RunInput[], options?: Partial<CallOptions> | Partial<CallOptions>[], batchOptions?: RunnableBatchOptions): Promise<(RunOutput | Error)[]>;
|
|
400
|
+
/** @internal */
|
|
401
|
+
_concatOutputChunks<O>(first: O, second: O): O;
|
|
398
402
|
_streamIterator(input: RunInput, options?: Partial<CallOptions> | undefined): AsyncGenerator<Awaited<RunOutput>, void, any>;
|
|
399
403
|
stream(input: RunInput, options?: Partial<CallOptions> | undefined): Promise<IterableReadableStream<RunOutput>>;
|
|
400
404
|
transform(generator: AsyncGenerator<RunInput>, options?: Partial<CallOptions>): AsyncGenerator<RunOutput>;
|
|
@@ -604,6 +608,8 @@ export declare class RunnableSequence<RunInput = any, RunOutput = any> extends R
|
|
|
604
608
|
returnExceptions: true;
|
|
605
609
|
}): Promise<(RunOutput | Error)[]>;
|
|
606
610
|
batch(inputs: RunInput[], options?: Partial<RunnableConfig> | Partial<RunnableConfig>[], batchOptions?: RunnableBatchOptions): Promise<(RunOutput | Error)[]>;
|
|
611
|
+
/** @internal */
|
|
612
|
+
_concatOutputChunks<O>(first: O, second: O): O;
|
|
607
613
|
_streamIterator(input: RunInput, options?: RunnableConfig): AsyncGenerator<RunOutput>;
|
|
608
614
|
getGraph(config?: RunnableConfig): Graph;
|
|
609
615
|
pipe<NewRunOutput>(coerceable: RunnableLike<RunOutput, NewRunOutput>): RunnableSequence<RunInput, Exclude<NewRunOutput, Error>>;
|
package/dist/runnables/base.js
CHANGED
|
@@ -258,6 +258,10 @@ export class Runnable extends Serializable {
|
|
|
258
258
|
await Promise.all(runManagers.map((runManager) => runManager?.handleChainEnd(_coerceToDict(outputs, "output"))));
|
|
259
259
|
return outputs;
|
|
260
260
|
}
|
|
261
|
+
/** @internal */
|
|
262
|
+
_concatOutputChunks(first, second) {
|
|
263
|
+
return concat(first, second);
|
|
264
|
+
}
|
|
261
265
|
/**
|
|
262
266
|
* Helper method to transform an Iterator of Input values into an Iterator of
|
|
263
267
|
* Output values, with callbacks.
|
|
@@ -270,6 +274,7 @@ export class Runnable extends Serializable {
|
|
|
270
274
|
let finalOutputSupported = true;
|
|
271
275
|
const config = ensureConfig(options);
|
|
272
276
|
const callbackManager_ = await getCallbackManagerForConfig(config);
|
|
277
|
+
const outerThis = this;
|
|
273
278
|
async function* wrapInputForTracing() {
|
|
274
279
|
for await (const chunk of inputGenerator) {
|
|
275
280
|
if (finalInputSupported) {
|
|
@@ -278,8 +283,9 @@ export class Runnable extends Serializable {
|
|
|
278
283
|
}
|
|
279
284
|
else {
|
|
280
285
|
try {
|
|
286
|
+
finalInput = outerThis._concatOutputChunks(finalInput,
|
|
281
287
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
282
|
-
|
|
288
|
+
chunk);
|
|
283
289
|
}
|
|
284
290
|
catch {
|
|
285
291
|
finalInput = undefined;
|
|
@@ -312,8 +318,9 @@ export class Runnable extends Serializable {
|
|
|
312
318
|
}
|
|
313
319
|
else {
|
|
314
320
|
try {
|
|
321
|
+
finalOutput = this._concatOutputChunks(finalOutput,
|
|
315
322
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
316
|
-
|
|
323
|
+
chunk);
|
|
317
324
|
}
|
|
318
325
|
catch {
|
|
319
326
|
finalOutput = undefined;
|
|
@@ -395,7 +402,7 @@ export class Runnable extends Serializable {
|
|
|
395
402
|
// Make a best effort to gather, for any type that supports concat.
|
|
396
403
|
// This method should throw an error if gathering fails.
|
|
397
404
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
398
|
-
finalChunk =
|
|
405
|
+
finalChunk = this._concatOutputChunks(finalChunk, chunk);
|
|
399
406
|
}
|
|
400
407
|
}
|
|
401
408
|
yield* this._streamIterator(finalChunk, ensureConfig(options));
|
|
@@ -913,6 +920,10 @@ export class RunnableBinding extends Runnable {
|
|
|
913
920
|
: await this._mergeConfig(ensureConfig(options), this.kwargs);
|
|
914
921
|
return this.bound.batch(inputs, mergedOptions, batchOptions);
|
|
915
922
|
}
|
|
923
|
+
/** @internal */
|
|
924
|
+
_concatOutputChunks(first, second) {
|
|
925
|
+
return this.bound._concatOutputChunks(first, second);
|
|
926
|
+
}
|
|
916
927
|
async *_streamIterator(input, options) {
|
|
917
928
|
yield* this.bound._streamIterator(input, await this._mergeConfig(ensureConfig(options), this.kwargs));
|
|
918
929
|
}
|
|
@@ -1338,6 +1349,10 @@ export class RunnableSequence extends Runnable {
|
|
|
1338
1349
|
await Promise.all(runManagers.map((runManager) => runManager?.handleChainEnd(_coerceToDict(nextStepInputs, "output"))));
|
|
1339
1350
|
return nextStepInputs;
|
|
1340
1351
|
}
|
|
1352
|
+
/** @internal */
|
|
1353
|
+
_concatOutputChunks(first, second) {
|
|
1354
|
+
return this.last._concatOutputChunks(first, second);
|
|
1355
|
+
}
|
|
1341
1356
|
async *_streamIterator(input, options) {
|
|
1342
1357
|
const callbackManager_ = await getCallbackManagerForConfig(options);
|
|
1343
1358
|
const { runId, ...otherOptions } = options ?? {};
|
|
@@ -1368,7 +1383,7 @@ export class RunnableSequence extends Runnable {
|
|
|
1368
1383
|
else {
|
|
1369
1384
|
try {
|
|
1370
1385
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1371
|
-
finalOutput =
|
|
1386
|
+
finalOutput = this._concatOutputChunks(finalOutput, chunk);
|
|
1372
1387
|
}
|
|
1373
1388
|
catch (e) {
|
|
1374
1389
|
finalOutput = undefined;
|
|
@@ -1719,8 +1734,9 @@ export class RunnableLambda extends Runnable {
|
|
|
1719
1734
|
else {
|
|
1720
1735
|
// Make a best effort to gather, for any type that supports concat.
|
|
1721
1736
|
try {
|
|
1737
|
+
finalOutput = this._concatOutputChunks(finalOutput,
|
|
1722
1738
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1723
|
-
|
|
1739
|
+
chunk);
|
|
1724
1740
|
}
|
|
1725
1741
|
catch (e) {
|
|
1726
1742
|
finalOutput = chunk;
|
|
@@ -1739,8 +1755,9 @@ export class RunnableLambda extends Runnable {
|
|
|
1739
1755
|
else {
|
|
1740
1756
|
// Make a best effort to gather, for any type that supports concat.
|
|
1741
1757
|
try {
|
|
1758
|
+
finalOutput = this._concatOutputChunks(finalOutput,
|
|
1742
1759
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1743
|
-
|
|
1760
|
+
chunk);
|
|
1744
1761
|
}
|
|
1745
1762
|
catch (e) {
|
|
1746
1763
|
finalOutput = chunk;
|
|
@@ -1770,7 +1787,7 @@ export class RunnableLambda extends Runnable {
|
|
|
1770
1787
|
// Make a best effort to gather, for any type that supports concat.
|
|
1771
1788
|
try {
|
|
1772
1789
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1773
|
-
finalChunk =
|
|
1790
|
+
finalChunk = this._concatOutputChunks(finalChunk, chunk);
|
|
1774
1791
|
}
|
|
1775
1792
|
catch (e) {
|
|
1776
1793
|
finalChunk = chunk;
|
|
@@ -2042,7 +2059,10 @@ export class RunnableWithFallbacks extends Runnable {
|
|
|
2042
2059
|
for await (const chunk of stream) {
|
|
2043
2060
|
yield chunk;
|
|
2044
2061
|
try {
|
|
2045
|
-
output =
|
|
2062
|
+
output =
|
|
2063
|
+
output === undefined
|
|
2064
|
+
? output
|
|
2065
|
+
: this._concatOutputChunks(output, chunk);
|
|
2046
2066
|
}
|
|
2047
2067
|
catch (e) {
|
|
2048
2068
|
output = undefined;
|