@langchain/core 0.1.33-rc.2 → 0.1.33
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.cjs +13 -11
- package/dist/runnables/base.js +13 -11
- package/dist/runnables/config.cjs +8 -6
- package/dist/runnables/config.js +8 -6
- package/dist/runnables/index.cjs +2 -1
- package/dist/runnables/index.d.ts +1 -1
- package/dist/runnables/index.js +1 -1
- package/dist/runnables/passthrough.cjs +7 -4
- package/dist/runnables/passthrough.d.ts +1 -1
- package/dist/runnables/passthrough.js +7 -4
- package/dist/tools.cjs +2 -1
- package/dist/tools.d.ts +1 -1
- package/dist/tools.js +2 -1
- package/package.json +1 -1
package/dist/runnables/base.cjs
CHANGED
|
@@ -159,7 +159,7 @@ class Runnable extends serializable_js_1.Serializable {
|
|
|
159
159
|
async stream(input, options) {
|
|
160
160
|
// Buffer the first streamed chunk to allow for initial errors
|
|
161
161
|
// to surface immediately.
|
|
162
|
-
const wrappedGenerator = new stream_js_1.AsyncGeneratorWithSetup(this._streamIterator(input, options));
|
|
162
|
+
const wrappedGenerator = new stream_js_1.AsyncGeneratorWithSetup(this._streamIterator(input, (0, config_js_1.ensureConfig)(options)));
|
|
163
163
|
await wrappedGenerator.setup;
|
|
164
164
|
return stream_js_1.IterableReadableStream.fromAsyncGenerator(wrappedGenerator);
|
|
165
165
|
}
|
|
@@ -341,7 +341,7 @@ class Runnable extends serializable_js_1.Serializable {
|
|
|
341
341
|
finalChunk = (0, stream_js_1.concat)(finalChunk, chunk);
|
|
342
342
|
}
|
|
343
343
|
}
|
|
344
|
-
yield* this._streamIterator(finalChunk, options);
|
|
344
|
+
yield* this._streamIterator(finalChunk, (0, config_js_1.ensureConfig)(options));
|
|
345
345
|
}
|
|
346
346
|
/**
|
|
347
347
|
* Stream all output from a runnable, as reported to the callback system.
|
|
@@ -1015,20 +1015,21 @@ class RunnableSequence extends Runnable {
|
|
|
1015
1015
|
return [this.first, ...this.middle, this.last];
|
|
1016
1016
|
}
|
|
1017
1017
|
async invoke(input, options) {
|
|
1018
|
-
const
|
|
1019
|
-
const
|
|
1018
|
+
const config = (0, config_js_1.ensureConfig)(options);
|
|
1019
|
+
const callbackManager_ = await (0, config_js_1.getCallbackManagerForConfig)(config);
|
|
1020
|
+
const runManager = await callbackManager_?.handleChainStart(this.toJSON(), _coerceToDict(input, "input"), undefined, undefined, undefined, undefined, config?.runName);
|
|
1020
1021
|
let nextStepInput = input;
|
|
1021
1022
|
let finalOutput;
|
|
1022
1023
|
try {
|
|
1023
1024
|
const initialSteps = [this.first, ...this.middle];
|
|
1024
1025
|
for (let i = 0; i < initialSteps.length; i += 1) {
|
|
1025
1026
|
const step = initialSteps[i];
|
|
1026
|
-
nextStepInput = await step.invoke(nextStepInput, (0, config_js_1.patchConfig)(
|
|
1027
|
+
nextStepInput = await step.invoke(nextStepInput, (0, config_js_1.patchConfig)(config, {
|
|
1027
1028
|
callbacks: runManager?.getChild(`seq:step:${i + 1}`),
|
|
1028
1029
|
}));
|
|
1029
1030
|
}
|
|
1030
1031
|
// TypeScript can't detect that the last output of the sequence returns RunOutput, so call it out of the loop here
|
|
1031
|
-
finalOutput = await this.last.invoke(nextStepInput, (0, config_js_1.patchConfig)(
|
|
1032
|
+
finalOutput = await this.last.invoke(nextStepInput, (0, config_js_1.patchConfig)(config, {
|
|
1032
1033
|
callbacks: runManager?.getChild(`seq:step:${this.steps.length}`),
|
|
1033
1034
|
}));
|
|
1034
1035
|
}
|
|
@@ -1194,15 +1195,16 @@ class RunnableMap extends Runnable {
|
|
|
1194
1195
|
return new RunnableMap({ steps });
|
|
1195
1196
|
}
|
|
1196
1197
|
async invoke(input, options) {
|
|
1197
|
-
const
|
|
1198
|
+
const config = (0, config_js_1.ensureConfig)(options);
|
|
1199
|
+
const callbackManager_ = await (0, config_js_1.getCallbackManagerForConfig)(config);
|
|
1198
1200
|
const runManager = await callbackManager_?.handleChainStart(this.toJSON(), {
|
|
1199
1201
|
input,
|
|
1200
|
-
}, undefined, undefined, undefined, undefined,
|
|
1202
|
+
}, undefined, undefined, undefined, undefined, config?.runName);
|
|
1201
1203
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1202
1204
|
const output = {};
|
|
1203
1205
|
try {
|
|
1204
1206
|
await Promise.all(Object.entries(this.steps).map(async ([key, runnable]) => {
|
|
1205
|
-
output[key] = await runnable.invoke(input, (0, config_js_1.patchConfig)(
|
|
1207
|
+
output[key] = await runnable.invoke(input, (0, config_js_1.patchConfig)(config, {
|
|
1206
1208
|
callbacks: runManager?.getChild(`map:key:${key}`),
|
|
1207
1209
|
}));
|
|
1208
1210
|
}));
|
|
@@ -1302,7 +1304,7 @@ class RunnableLambda extends Runnable {
|
|
|
1302
1304
|
});
|
|
1303
1305
|
}
|
|
1304
1306
|
async invoke(input, options) {
|
|
1305
|
-
return this._callWithConfig(this._invoke, input, options
|
|
1307
|
+
return this._callWithConfig(this._invoke, input, options);
|
|
1306
1308
|
}
|
|
1307
1309
|
async *_transform(generator, runManager, config) {
|
|
1308
1310
|
let finalChunk;
|
|
@@ -1352,7 +1354,7 @@ class RunnableLambda extends Runnable {
|
|
|
1352
1354
|
}
|
|
1353
1355
|
}
|
|
1354
1356
|
transform(generator, options) {
|
|
1355
|
-
return this._transformStreamWithConfig(generator, this._transform.bind(this), options
|
|
1357
|
+
return this._transformStreamWithConfig(generator, this._transform.bind(this), options);
|
|
1356
1358
|
}
|
|
1357
1359
|
async stream(input, options) {
|
|
1358
1360
|
async function* generator() {
|
package/dist/runnables/base.js
CHANGED
|
@@ -152,7 +152,7 @@ export class Runnable extends Serializable {
|
|
|
152
152
|
async stream(input, options) {
|
|
153
153
|
// Buffer the first streamed chunk to allow for initial errors
|
|
154
154
|
// to surface immediately.
|
|
155
|
-
const wrappedGenerator = new AsyncGeneratorWithSetup(this._streamIterator(input, options));
|
|
155
|
+
const wrappedGenerator = new AsyncGeneratorWithSetup(this._streamIterator(input, ensureConfig(options)));
|
|
156
156
|
await wrappedGenerator.setup;
|
|
157
157
|
return IterableReadableStream.fromAsyncGenerator(wrappedGenerator);
|
|
158
158
|
}
|
|
@@ -334,7 +334,7 @@ export class Runnable extends Serializable {
|
|
|
334
334
|
finalChunk = concat(finalChunk, chunk);
|
|
335
335
|
}
|
|
336
336
|
}
|
|
337
|
-
yield* this._streamIterator(finalChunk, options);
|
|
337
|
+
yield* this._streamIterator(finalChunk, ensureConfig(options));
|
|
338
338
|
}
|
|
339
339
|
/**
|
|
340
340
|
* Stream all output from a runnable, as reported to the callback system.
|
|
@@ -1004,20 +1004,21 @@ export class RunnableSequence extends Runnable {
|
|
|
1004
1004
|
return [this.first, ...this.middle, this.last];
|
|
1005
1005
|
}
|
|
1006
1006
|
async invoke(input, options) {
|
|
1007
|
-
const
|
|
1008
|
-
const
|
|
1007
|
+
const config = ensureConfig(options);
|
|
1008
|
+
const callbackManager_ = await getCallbackManagerForConfig(config);
|
|
1009
|
+
const runManager = await callbackManager_?.handleChainStart(this.toJSON(), _coerceToDict(input, "input"), undefined, undefined, undefined, undefined, config?.runName);
|
|
1009
1010
|
let nextStepInput = input;
|
|
1010
1011
|
let finalOutput;
|
|
1011
1012
|
try {
|
|
1012
1013
|
const initialSteps = [this.first, ...this.middle];
|
|
1013
1014
|
for (let i = 0; i < initialSteps.length; i += 1) {
|
|
1014
1015
|
const step = initialSteps[i];
|
|
1015
|
-
nextStepInput = await step.invoke(nextStepInput, patchConfig(
|
|
1016
|
+
nextStepInput = await step.invoke(nextStepInput, patchConfig(config, {
|
|
1016
1017
|
callbacks: runManager?.getChild(`seq:step:${i + 1}`),
|
|
1017
1018
|
}));
|
|
1018
1019
|
}
|
|
1019
1020
|
// TypeScript can't detect that the last output of the sequence returns RunOutput, so call it out of the loop here
|
|
1020
|
-
finalOutput = await this.last.invoke(nextStepInput, patchConfig(
|
|
1021
|
+
finalOutput = await this.last.invoke(nextStepInput, patchConfig(config, {
|
|
1021
1022
|
callbacks: runManager?.getChild(`seq:step:${this.steps.length}`),
|
|
1022
1023
|
}));
|
|
1023
1024
|
}
|
|
@@ -1182,15 +1183,16 @@ export class RunnableMap extends Runnable {
|
|
|
1182
1183
|
return new RunnableMap({ steps });
|
|
1183
1184
|
}
|
|
1184
1185
|
async invoke(input, options) {
|
|
1185
|
-
const
|
|
1186
|
+
const config = ensureConfig(options);
|
|
1187
|
+
const callbackManager_ = await getCallbackManagerForConfig(config);
|
|
1186
1188
|
const runManager = await callbackManager_?.handleChainStart(this.toJSON(), {
|
|
1187
1189
|
input,
|
|
1188
|
-
}, undefined, undefined, undefined, undefined,
|
|
1190
|
+
}, undefined, undefined, undefined, undefined, config?.runName);
|
|
1189
1191
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1190
1192
|
const output = {};
|
|
1191
1193
|
try {
|
|
1192
1194
|
await Promise.all(Object.entries(this.steps).map(async ([key, runnable]) => {
|
|
1193
|
-
output[key] = await runnable.invoke(input, patchConfig(
|
|
1195
|
+
output[key] = await runnable.invoke(input, patchConfig(config, {
|
|
1194
1196
|
callbacks: runManager?.getChild(`map:key:${key}`),
|
|
1195
1197
|
}));
|
|
1196
1198
|
}));
|
|
@@ -1289,7 +1291,7 @@ export class RunnableLambda extends Runnable {
|
|
|
1289
1291
|
});
|
|
1290
1292
|
}
|
|
1291
1293
|
async invoke(input, options) {
|
|
1292
|
-
return this._callWithConfig(this._invoke, input, options
|
|
1294
|
+
return this._callWithConfig(this._invoke, input, options);
|
|
1293
1295
|
}
|
|
1294
1296
|
async *_transform(generator, runManager, config) {
|
|
1295
1297
|
let finalChunk;
|
|
@@ -1339,7 +1341,7 @@ export class RunnableLambda extends Runnable {
|
|
|
1339
1341
|
}
|
|
1340
1342
|
}
|
|
1341
1343
|
transform(generator, options) {
|
|
1342
|
-
return this._transformStreamWithConfig(generator, this._transform.bind(this), options
|
|
1344
|
+
return this._transformStreamWithConfig(generator, this._transform.bind(this), options);
|
|
1343
1345
|
}
|
|
1344
1346
|
async stream(input, options) {
|
|
1345
1347
|
async function* generator() {
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.patchConfig = exports.ensureConfig = exports.mergeConfigs = exports.getCallbackManagerForConfig = exports.DEFAULT_RECURSION_LIMIT = void 0;
|
|
4
4
|
const manager_js_1 = require("../callbacks/manager.cjs");
|
|
5
|
+
const index_js_1 = require("../singletons/index.cjs");
|
|
5
6
|
exports.DEFAULT_RECURSION_LIMIT = 25;
|
|
6
7
|
async function getCallbackManagerForConfig(config) {
|
|
7
8
|
return manager_js_1.CallbackManager.configure(config?.callbacks, undefined, config?.tags, undefined, config?.metadata);
|
|
@@ -83,23 +84,24 @@ const PRIMITIVES = new Set(["string", "number", "boolean"]);
|
|
|
83
84
|
* Ensure that a passed config is an object with all required keys present.
|
|
84
85
|
*/
|
|
85
86
|
function ensureConfig(config) {
|
|
87
|
+
const loadedConfig = config ?? index_js_1.AsyncLocalStorageProviderSingleton.getInstance().getStore();
|
|
86
88
|
let empty = {
|
|
87
89
|
tags: [],
|
|
88
90
|
metadata: {},
|
|
89
91
|
callbacks: undefined,
|
|
90
92
|
recursionLimit: 25,
|
|
91
93
|
};
|
|
92
|
-
if (
|
|
93
|
-
empty = { ...empty, ...
|
|
94
|
+
if (loadedConfig) {
|
|
95
|
+
empty = { ...empty, ...loadedConfig };
|
|
94
96
|
}
|
|
95
|
-
if (
|
|
96
|
-
for (const key of Object.keys(
|
|
97
|
-
if (PRIMITIVES.has(typeof
|
|
97
|
+
if (loadedConfig?.configurable) {
|
|
98
|
+
for (const key of Object.keys(loadedConfig.configurable)) {
|
|
99
|
+
if (PRIMITIVES.has(typeof loadedConfig.configurable[key]) &&
|
|
98
100
|
!empty.metadata?.[key]) {
|
|
99
101
|
if (!empty.metadata) {
|
|
100
102
|
empty.metadata = {};
|
|
101
103
|
}
|
|
102
|
-
empty.metadata[key] =
|
|
104
|
+
empty.metadata[key] = loadedConfig.configurable[key];
|
|
103
105
|
}
|
|
104
106
|
}
|
|
105
107
|
}
|
package/dist/runnables/config.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CallbackManager, ensureHandler, } from "../callbacks/manager.js";
|
|
2
|
+
import { AsyncLocalStorageProviderSingleton } from "../singletons/index.js";
|
|
2
3
|
export const DEFAULT_RECURSION_LIMIT = 25;
|
|
3
4
|
export async function getCallbackManagerForConfig(config) {
|
|
4
5
|
return CallbackManager.configure(config?.callbacks, undefined, config?.tags, undefined, config?.metadata);
|
|
@@ -78,23 +79,24 @@ const PRIMITIVES = new Set(["string", "number", "boolean"]);
|
|
|
78
79
|
* Ensure that a passed config is an object with all required keys present.
|
|
79
80
|
*/
|
|
80
81
|
export function ensureConfig(config) {
|
|
82
|
+
const loadedConfig = config ?? AsyncLocalStorageProviderSingleton.getInstance().getStore();
|
|
81
83
|
let empty = {
|
|
82
84
|
tags: [],
|
|
83
85
|
metadata: {},
|
|
84
86
|
callbacks: undefined,
|
|
85
87
|
recursionLimit: 25,
|
|
86
88
|
};
|
|
87
|
-
if (
|
|
88
|
-
empty = { ...empty, ...
|
|
89
|
+
if (loadedConfig) {
|
|
90
|
+
empty = { ...empty, ...loadedConfig };
|
|
89
91
|
}
|
|
90
|
-
if (
|
|
91
|
-
for (const key of Object.keys(
|
|
92
|
-
if (PRIMITIVES.has(typeof
|
|
92
|
+
if (loadedConfig?.configurable) {
|
|
93
|
+
for (const key of Object.keys(loadedConfig.configurable)) {
|
|
94
|
+
if (PRIMITIVES.has(typeof loadedConfig.configurable[key]) &&
|
|
93
95
|
!empty.metadata?.[key]) {
|
|
94
96
|
if (!empty.metadata) {
|
|
95
97
|
empty.metadata = {};
|
|
96
98
|
}
|
|
97
|
-
empty.metadata[key] =
|
|
99
|
+
empty.metadata[key] = loadedConfig.configurable[key];
|
|
98
100
|
}
|
|
99
101
|
}
|
|
100
102
|
}
|
package/dist/runnables/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RunnableWithMessageHistory = exports.RunnableBranch = exports.RouterRunnable = exports.RunnablePassthrough = exports.patchConfig = exports.getCallbackManagerForConfig = exports._coerceToRunnable = exports.RunnablePick = exports.RunnableAssign = exports.RunnableWithFallbacks = exports.RunnableLambda = exports.RunnableParallel = exports.RunnableMap = exports.RunnableSequence = exports.RunnableRetry = exports.RunnableEach = exports.RunnableBinding = exports.Runnable = void 0;
|
|
3
|
+
exports.RunnableWithMessageHistory = exports.RunnableBranch = exports.RouterRunnable = exports.RunnablePassthrough = exports.ensureConfig = exports.patchConfig = exports.getCallbackManagerForConfig = exports._coerceToRunnable = exports.RunnablePick = exports.RunnableAssign = exports.RunnableWithFallbacks = exports.RunnableLambda = exports.RunnableParallel = exports.RunnableMap = exports.RunnableSequence = exports.RunnableRetry = exports.RunnableEach = exports.RunnableBinding = exports.Runnable = void 0;
|
|
4
4
|
var base_js_1 = require("./base.cjs");
|
|
5
5
|
Object.defineProperty(exports, "Runnable", { enumerable: true, get: function () { return base_js_1.Runnable; } });
|
|
6
6
|
Object.defineProperty(exports, "RunnableBinding", { enumerable: true, get: function () { return base_js_1.RunnableBinding; } });
|
|
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "_coerceToRunnable", { enumerable: true, get: fun
|
|
|
17
17
|
var config_js_1 = require("./config.cjs");
|
|
18
18
|
Object.defineProperty(exports, "getCallbackManagerForConfig", { enumerable: true, get: function () { return config_js_1.getCallbackManagerForConfig; } });
|
|
19
19
|
Object.defineProperty(exports, "patchConfig", { enumerable: true, get: function () { return config_js_1.patchConfig; } });
|
|
20
|
+
Object.defineProperty(exports, "ensureConfig", { enumerable: true, get: function () { return config_js_1.ensureConfig; } });
|
|
20
21
|
var passthrough_js_1 = require("./passthrough.cjs");
|
|
21
22
|
Object.defineProperty(exports, "RunnablePassthrough", { enumerable: true, get: function () { return passthrough_js_1.RunnablePassthrough; } });
|
|
22
23
|
var router_js_1 = require("./router.cjs");
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { type RunnableFunc, type RunnableLike, type RunnableBatchOptions, type RunnableRetryFailedAttemptHandler, Runnable, type RunnableInterface, type RunnableBindingArgs, RunnableBinding, RunnableEach, RunnableRetry, RunnableSequence, RunnableMap, RunnableParallel, RunnableLambda, RunnableWithFallbacks, RunnableAssign, RunnablePick, _coerceToRunnable, } from "./base.js";
|
|
2
|
-
export { type RunnableConfig, getCallbackManagerForConfig, patchConfig, } from "./config.js";
|
|
2
|
+
export { type RunnableConfig, getCallbackManagerForConfig, patchConfig, ensureConfig, } from "./config.js";
|
|
3
3
|
export { RunnablePassthrough } from "./passthrough.js";
|
|
4
4
|
export { type RouterInput, RouterRunnable } from "./router.js";
|
|
5
5
|
export { RunnableBranch, type Branch, type BranchLike } from "./branch.js";
|
package/dist/runnables/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { Runnable, RunnableBinding, RunnableEach, RunnableRetry, RunnableSequence, RunnableMap, RunnableParallel, RunnableLambda, RunnableWithFallbacks, RunnableAssign, RunnablePick, _coerceToRunnable, } from "./base.js";
|
|
2
|
-
export { getCallbackManagerForConfig, patchConfig, } from "./config.js";
|
|
2
|
+
export { getCallbackManagerForConfig, patchConfig, ensureConfig, } from "./config.js";
|
|
3
3
|
export { RunnablePassthrough } from "./passthrough.js";
|
|
4
4
|
export { RouterRunnable } from "./router.js";
|
|
5
5
|
export { RunnableBranch } from "./branch.js";
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.RunnablePassthrough = void 0;
|
|
4
4
|
const stream_js_1 = require("../utils/stream.cjs");
|
|
5
5
|
const base_js_1 = require("./base.cjs");
|
|
6
|
+
const config_js_1 = require("./config.cjs");
|
|
6
7
|
/**
|
|
7
8
|
* A runnable to passthrough inputs unchanged or with additional keys.
|
|
8
9
|
*
|
|
@@ -58,15 +59,17 @@ class RunnablePassthrough extends base_js_1.Runnable {
|
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
61
|
async invoke(input, options) {
|
|
62
|
+
const config = (0, config_js_1.ensureConfig)(options);
|
|
61
63
|
if (this.func) {
|
|
62
|
-
await this.func(input,
|
|
64
|
+
await this.func(input, config);
|
|
63
65
|
}
|
|
64
|
-
return this._callWithConfig((input) => Promise.resolve(input), input,
|
|
66
|
+
return this._callWithConfig((input) => Promise.resolve(input), input, config);
|
|
65
67
|
}
|
|
66
68
|
async *transform(generator, options) {
|
|
69
|
+
const config = (0, config_js_1.ensureConfig)(options);
|
|
67
70
|
let finalOutput;
|
|
68
71
|
let finalOutputSupported = true;
|
|
69
|
-
for await (const chunk of this._transformStreamWithConfig(generator, (input) => input,
|
|
72
|
+
for await (const chunk of this._transformStreamWithConfig(generator, (input) => input, config)) {
|
|
70
73
|
yield chunk;
|
|
71
74
|
if (finalOutputSupported) {
|
|
72
75
|
if (finalOutput === undefined) {
|
|
@@ -85,7 +88,7 @@ class RunnablePassthrough extends base_js_1.Runnable {
|
|
|
85
88
|
}
|
|
86
89
|
}
|
|
87
90
|
if (this.func && finalOutput !== undefined) {
|
|
88
|
-
await this.func(finalOutput,
|
|
91
|
+
await this.func(finalOutput, config);
|
|
89
92
|
}
|
|
90
93
|
}
|
|
91
94
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Runnable, RunnableAssign, RunnableMapLike } from "./base.js";
|
|
2
|
-
import type
|
|
2
|
+
import { type RunnableConfig } from "./config.js";
|
|
3
3
|
type RunnablePassthroughFunc<RunInput = any> = ((input: RunInput) => void) | ((input: RunInput, config?: RunnableConfig) => void) | ((input: RunInput) => Promise<void>) | ((input: RunInput, config?: RunnableConfig) => Promise<void>);
|
|
4
4
|
/**
|
|
5
5
|
* A runnable to passthrough inputs unchanged or with additional keys.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { concat } from "../utils/stream.js";
|
|
2
2
|
import { Runnable, RunnableAssign, RunnableMap, } from "./base.js";
|
|
3
|
+
import { ensureConfig } from "./config.js";
|
|
3
4
|
/**
|
|
4
5
|
* A runnable to passthrough inputs unchanged or with additional keys.
|
|
5
6
|
*
|
|
@@ -55,15 +56,17 @@ export class RunnablePassthrough extends Runnable {
|
|
|
55
56
|
}
|
|
56
57
|
}
|
|
57
58
|
async invoke(input, options) {
|
|
59
|
+
const config = ensureConfig(options);
|
|
58
60
|
if (this.func) {
|
|
59
|
-
await this.func(input,
|
|
61
|
+
await this.func(input, config);
|
|
60
62
|
}
|
|
61
|
-
return this._callWithConfig((input) => Promise.resolve(input), input,
|
|
63
|
+
return this._callWithConfig((input) => Promise.resolve(input), input, config);
|
|
62
64
|
}
|
|
63
65
|
async *transform(generator, options) {
|
|
66
|
+
const config = ensureConfig(options);
|
|
64
67
|
let finalOutput;
|
|
65
68
|
let finalOutputSupported = true;
|
|
66
|
-
for await (const chunk of this._transformStreamWithConfig(generator, (input) => input,
|
|
69
|
+
for await (const chunk of this._transformStreamWithConfig(generator, (input) => input, config)) {
|
|
67
70
|
yield chunk;
|
|
68
71
|
if (finalOutputSupported) {
|
|
69
72
|
if (finalOutput === undefined) {
|
|
@@ -82,7 +85,7 @@ export class RunnablePassthrough extends Runnable {
|
|
|
82
85
|
}
|
|
83
86
|
}
|
|
84
87
|
if (this.func && finalOutput !== undefined) {
|
|
85
|
-
await this.func(finalOutput,
|
|
88
|
+
await this.func(finalOutput, config);
|
|
86
89
|
}
|
|
87
90
|
}
|
|
88
91
|
/**
|
package/dist/tools.cjs
CHANGED
|
@@ -4,6 +4,7 @@ exports.DynamicStructuredTool = exports.DynamicTool = exports.Tool = exports.Str
|
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
const manager_js_1 = require("./callbacks/manager.cjs");
|
|
6
6
|
const base_js_1 = require("./language_models/base.cjs");
|
|
7
|
+
const config_js_1 = require("./runnables/config.cjs");
|
|
7
8
|
/**
|
|
8
9
|
* Custom error class used to handle exceptions related to tool input parsing.
|
|
9
10
|
* It extends the built-in `Error` class and adds an optional `output`
|
|
@@ -45,7 +46,7 @@ class StructuredTool extends base_js_1.BaseLangChain {
|
|
|
45
46
|
* @returns A Promise that resolves with a string.
|
|
46
47
|
*/
|
|
47
48
|
async invoke(input, config) {
|
|
48
|
-
return this.call(input, config);
|
|
49
|
+
return this.call(input, (0, config_js_1.ensureConfig)(config));
|
|
49
50
|
}
|
|
50
51
|
/**
|
|
51
52
|
* Calls the tool with the provided argument, configuration, and tags. It
|
package/dist/tools.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { CallbackManagerForToolRun, Callbacks } from "./callbacks/manager.js";
|
|
3
3
|
import { BaseLangChain, type BaseLangChainParams } from "./language_models/base.js";
|
|
4
|
-
import type
|
|
4
|
+
import { type RunnableConfig } from "./runnables/config.js";
|
|
5
5
|
import type { RunnableInterface } from "./runnables/base.js";
|
|
6
6
|
/**
|
|
7
7
|
* Parameters for the Tool classes.
|
package/dist/tools.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { CallbackManager, parseCallbackConfigArg, } from "./callbacks/manager.js";
|
|
3
3
|
import { BaseLangChain, } from "./language_models/base.js";
|
|
4
|
+
import { ensureConfig } from "./runnables/config.js";
|
|
4
5
|
/**
|
|
5
6
|
* Custom error class used to handle exceptions related to tool input parsing.
|
|
6
7
|
* It extends the built-in `Error` class and adds an optional `output`
|
|
@@ -41,7 +42,7 @@ export class StructuredTool extends BaseLangChain {
|
|
|
41
42
|
* @returns A Promise that resolves with a string.
|
|
42
43
|
*/
|
|
43
44
|
async invoke(input, config) {
|
|
44
|
-
return this.call(input, config);
|
|
45
|
+
return this.call(input, ensureConfig(config));
|
|
45
46
|
}
|
|
46
47
|
/**
|
|
47
48
|
* Calls the tool with the provided argument, configuration, and tags. It
|