@langchain/core 0.1.13 → 0.1.14
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.
package/dist/runnables/base.d.ts
CHANGED
|
@@ -147,15 +147,15 @@ export declare abstract class Runnable<RunInput = any, RunOutput = any, CallOpti
|
|
|
147
147
|
* @param coerceable A runnable, function, or object whose values are functions or runnables.
|
|
148
148
|
* @returns A new runnable sequence.
|
|
149
149
|
*/
|
|
150
|
-
pipe<NewRunOutput>(coerceable: RunnableLike<RunOutput, NewRunOutput>):
|
|
150
|
+
pipe<NewRunOutput>(coerceable: RunnableLike<RunOutput, NewRunOutput>): Runnable<RunInput, Exclude<NewRunOutput, Error>>;
|
|
151
151
|
/**
|
|
152
152
|
* Pick keys from the dict output of this runnable. Returns a new runnable.
|
|
153
153
|
*/
|
|
154
|
-
pick(keys: string | string[]):
|
|
154
|
+
pick(keys: string | string[]): Runnable;
|
|
155
155
|
/**
|
|
156
156
|
* Assigns new fields to the dict output of this runnable. Returns a new runnable.
|
|
157
157
|
*/
|
|
158
|
-
assign(mapping: RunnableMapLike<Record<string, unknown>, Record<string, unknown>>):
|
|
158
|
+
assign(mapping: RunnableMapLike<Record<string, unknown>, Record<string, unknown>>): Runnable;
|
|
159
159
|
/**
|
|
160
160
|
* Default implementation of transform, which buffers input and then calls stream.
|
|
161
161
|
* Subclasses should override this method if they can start producing output while
|
|
@@ -357,7 +357,7 @@ export declare class RunnableSequence<RunInput = any, RunOutput = any> extends R
|
|
|
357
357
|
last: Runnable<any, RunOutput>;
|
|
358
358
|
name?: string;
|
|
359
359
|
});
|
|
360
|
-
get steps(): Runnable<
|
|
360
|
+
get steps(): Runnable<any, any, RunnableConfig>[];
|
|
361
361
|
invoke(input: RunInput, options?: RunnableConfig): Promise<RunOutput>;
|
|
362
362
|
batch(inputs: RunInput[], options?: Partial<RunnableConfig> | Partial<RunnableConfig>[], batchOptions?: RunnableBatchOptions & {
|
|
363
363
|
returnExceptions?: false;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RunnablePassthrough = void 0;
|
|
4
|
+
const stream_js_1 = require("../utils/stream.cjs");
|
|
4
5
|
const base_js_1 = require("./base.cjs");
|
|
5
6
|
/**
|
|
6
7
|
* A runnable to passthrough inputs unchanged or with additional keys.
|
|
@@ -29,8 +30,11 @@ const base_js_1 = require("./base.cjs");
|
|
|
29
30
|
* ```
|
|
30
31
|
*/
|
|
31
32
|
class RunnablePassthrough extends base_js_1.Runnable {
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
static lc_name() {
|
|
34
|
+
return "RunnablePassthrough";
|
|
35
|
+
}
|
|
36
|
+
constructor(fields) {
|
|
37
|
+
super(fields);
|
|
34
38
|
Object.defineProperty(this, "lc_namespace", {
|
|
35
39
|
enumerable: true,
|
|
36
40
|
configurable: true,
|
|
@@ -43,15 +47,46 @@ class RunnablePassthrough extends base_js_1.Runnable {
|
|
|
43
47
|
writable: true,
|
|
44
48
|
value: true
|
|
45
49
|
});
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
50
|
+
Object.defineProperty(this, "func", {
|
|
51
|
+
enumerable: true,
|
|
52
|
+
configurable: true,
|
|
53
|
+
writable: true,
|
|
54
|
+
value: void 0
|
|
55
|
+
});
|
|
56
|
+
if (fields) {
|
|
57
|
+
this.func = fields.func;
|
|
58
|
+
}
|
|
49
59
|
}
|
|
50
60
|
async invoke(input, options) {
|
|
61
|
+
if (this.func) {
|
|
62
|
+
await this.func(input, options);
|
|
63
|
+
}
|
|
51
64
|
return this._callWithConfig((input) => Promise.resolve(input), input, options);
|
|
52
65
|
}
|
|
53
|
-
transform(generator, options) {
|
|
54
|
-
|
|
66
|
+
async *transform(generator, options) {
|
|
67
|
+
let finalOutput;
|
|
68
|
+
let finalOutputSupported = true;
|
|
69
|
+
for await (const chunk of this._transformStreamWithConfig(generator, (input) => input, options)) {
|
|
70
|
+
yield chunk;
|
|
71
|
+
if (finalOutputSupported) {
|
|
72
|
+
if (finalOutput === undefined) {
|
|
73
|
+
finalOutput = chunk;
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
try {
|
|
77
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
78
|
+
finalOutput = (0, stream_js_1.concat)(finalOutput, chunk);
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
finalOutput = undefined;
|
|
82
|
+
finalOutputSupported = false;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (this.func && finalOutput !== undefined) {
|
|
88
|
+
await this.func(finalOutput, options);
|
|
89
|
+
}
|
|
55
90
|
}
|
|
56
91
|
/**
|
|
57
92
|
* A runnable that assigns key-value pairs to the input.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Runnable, RunnableAssign, RunnableMapLike } from "./base.js";
|
|
2
2
|
import type { RunnableConfig } from "./config.js";
|
|
3
|
+
type RunnablePassthroughFunc<RunInput = any> = ((input: RunInput) => void) | ((input: RunInput, config?: RunnableConfig) => void) | ((input: RunInput) => Promise<void>) | ((input: RunInput, config?: RunnableConfig) => Promise<void>);
|
|
3
4
|
/**
|
|
4
5
|
* A runnable to passthrough inputs unchanged or with additional keys.
|
|
5
6
|
*
|
|
@@ -30,6 +31,10 @@ export declare class RunnablePassthrough<RunInput> extends Runnable<RunInput, Ru
|
|
|
30
31
|
static lc_name(): string;
|
|
31
32
|
lc_namespace: string[];
|
|
32
33
|
lc_serializable: boolean;
|
|
34
|
+
func?: RunnablePassthroughFunc<RunInput>;
|
|
35
|
+
constructor(fields?: {
|
|
36
|
+
func?: RunnablePassthroughFunc<RunInput>;
|
|
37
|
+
});
|
|
33
38
|
invoke(input: RunInput, options?: Partial<RunnableConfig>): Promise<RunInput>;
|
|
34
39
|
transform(generator: AsyncGenerator<RunInput>, options: Partial<RunnableConfig>): AsyncGenerator<RunInput>;
|
|
35
40
|
/**
|
|
@@ -62,3 +67,4 @@ export declare class RunnablePassthrough<RunInput> extends Runnable<RunInput, Ru
|
|
|
62
67
|
*/
|
|
63
68
|
static assign<RunInput extends Record<string, unknown>, RunOutput extends Record<string, unknown>>(mapping: RunnableMapLike<RunInput, RunOutput>): RunnableAssign<RunInput, RunInput & RunOutput>;
|
|
64
69
|
}
|
|
70
|
+
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { concat } from "../utils/stream.js";
|
|
1
2
|
import { Runnable, RunnableAssign, RunnableMap, } from "./base.js";
|
|
2
3
|
/**
|
|
3
4
|
* A runnable to passthrough inputs unchanged or with additional keys.
|
|
@@ -26,8 +27,11 @@ import { Runnable, RunnableAssign, RunnableMap, } from "./base.js";
|
|
|
26
27
|
* ```
|
|
27
28
|
*/
|
|
28
29
|
export class RunnablePassthrough extends Runnable {
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
static lc_name() {
|
|
31
|
+
return "RunnablePassthrough";
|
|
32
|
+
}
|
|
33
|
+
constructor(fields) {
|
|
34
|
+
super(fields);
|
|
31
35
|
Object.defineProperty(this, "lc_namespace", {
|
|
32
36
|
enumerable: true,
|
|
33
37
|
configurable: true,
|
|
@@ -40,15 +44,46 @@ export class RunnablePassthrough extends Runnable {
|
|
|
40
44
|
writable: true,
|
|
41
45
|
value: true
|
|
42
46
|
});
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
47
|
+
Object.defineProperty(this, "func", {
|
|
48
|
+
enumerable: true,
|
|
49
|
+
configurable: true,
|
|
50
|
+
writable: true,
|
|
51
|
+
value: void 0
|
|
52
|
+
});
|
|
53
|
+
if (fields) {
|
|
54
|
+
this.func = fields.func;
|
|
55
|
+
}
|
|
46
56
|
}
|
|
47
57
|
async invoke(input, options) {
|
|
58
|
+
if (this.func) {
|
|
59
|
+
await this.func(input, options);
|
|
60
|
+
}
|
|
48
61
|
return this._callWithConfig((input) => Promise.resolve(input), input, options);
|
|
49
62
|
}
|
|
50
|
-
transform(generator, options) {
|
|
51
|
-
|
|
63
|
+
async *transform(generator, options) {
|
|
64
|
+
let finalOutput;
|
|
65
|
+
let finalOutputSupported = true;
|
|
66
|
+
for await (const chunk of this._transformStreamWithConfig(generator, (input) => input, options)) {
|
|
67
|
+
yield chunk;
|
|
68
|
+
if (finalOutputSupported) {
|
|
69
|
+
if (finalOutput === undefined) {
|
|
70
|
+
finalOutput = chunk;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
try {
|
|
74
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
75
|
+
finalOutput = concat(finalOutput, chunk);
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
finalOutput = undefined;
|
|
79
|
+
finalOutputSupported = false;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (this.func && finalOutput !== undefined) {
|
|
85
|
+
await this.func(finalOutput, options);
|
|
86
|
+
}
|
|
52
87
|
}
|
|
53
88
|
/**
|
|
54
89
|
* A runnable that assigns key-value pairs to the input.
|