@langchain/core 0.1.33-rc.1 → 0.1.33-rc.3

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.
@@ -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 callbackManager_ = await (0, config_js_1.getCallbackManagerForConfig)(options);
1019
- const runManager = await callbackManager_?.handleChainStart(this.toJSON(), _coerceToDict(input, "input"), undefined, undefined, undefined, undefined, options?.runName);
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)(options, {
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)(options, {
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 callbackManager_ = await (0, config_js_1.getCallbackManagerForConfig)(options);
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, options?.runName);
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)(options, {
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 ?? index_js_1.AsyncLocalStorageProviderSingleton.getInstance().getStore());
1307
+ return this._callWithConfig(this._invoke, input, options);
1306
1308
  }
1307
1309
  async *_transform(generator, runManager, config) {
1308
1310
  let finalChunk;
@@ -1321,36 +1323,38 @@ class RunnableLambda extends Runnable {
1321
1323
  }
1322
1324
  }
1323
1325
  }
1324
- // eslint-disable-next-line prefer-destructuring
1325
- const func = this.func;
1326
- async function* generatorWrapper() {
1327
- const output = await func(finalChunk, { ...config, config });
1328
- if (output && Runnable.isRunnable(output)) {
1329
- if (config?.recursionLimit === 0) {
1330
- throw new Error("Recursion limit reached.");
1326
+ const output = await new Promise((resolve, reject) => {
1327
+ void index_js_1.AsyncLocalStorageProviderSingleton.getInstance().run(config, async () => {
1328
+ try {
1329
+ const res = await this.func(finalChunk, {
1330
+ ...config,
1331
+ config,
1332
+ });
1333
+ resolve(res);
1331
1334
  }
1332
- const stream = await output.stream(finalChunk, (0, config_js_1.patchConfig)(config, {
1333
- callbacks: runManager?.getChild(),
1334
- recursionLimit: (config?.recursionLimit ?? config_js_1.DEFAULT_RECURSION_LIMIT) - 1,
1335
- }));
1336
- for await (const chunk of stream) {
1337
- yield chunk;
1335
+ catch (e) {
1336
+ reject(e);
1338
1337
  }
1338
+ });
1339
+ });
1340
+ if (output && Runnable.isRunnable(output)) {
1341
+ if (config?.recursionLimit === 0) {
1342
+ throw new Error("Recursion limit reached.");
1339
1343
  }
1340
- else {
1341
- yield output;
1344
+ const stream = await output.stream(finalChunk, (0, config_js_1.patchConfig)(config, {
1345
+ callbacks: runManager?.getChild(),
1346
+ recursionLimit: (config?.recursionLimit ?? config_js_1.DEFAULT_RECURSION_LIMIT) - 1,
1347
+ }));
1348
+ for await (const chunk of stream) {
1349
+ yield chunk;
1342
1350
  }
1343
1351
  }
1344
- const finalGenerator = await new Promise((resolve) => {
1345
- void index_js_1.AsyncLocalStorageProviderSingleton.getInstance().run(config, async () => {
1346
- const wrappedGenerator = generatorWrapper();
1347
- resolve(wrappedGenerator);
1348
- });
1349
- });
1350
- yield* finalGenerator;
1352
+ else {
1353
+ yield output;
1354
+ }
1351
1355
  }
1352
1356
  transform(generator, options) {
1353
- return this._transformStreamWithConfig(generator, this._transform.bind(this), options ?? index_js_1.AsyncLocalStorageProviderSingleton.getInstance().getStore());
1357
+ return this._transformStreamWithConfig(generator, this._transform.bind(this), options);
1354
1358
  }
1355
1359
  async stream(input, options) {
1356
1360
  async function* generator() {
@@ -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 callbackManager_ = await getCallbackManagerForConfig(options);
1008
- const runManager = await callbackManager_?.handleChainStart(this.toJSON(), _coerceToDict(input, "input"), undefined, undefined, undefined, undefined, options?.runName);
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(options, {
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(options, {
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 callbackManager_ = await getCallbackManagerForConfig(options);
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, options?.runName);
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(options, {
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 ?? AsyncLocalStorageProviderSingleton.getInstance().getStore());
1294
+ return this._callWithConfig(this._invoke, input, options);
1293
1295
  }
1294
1296
  async *_transform(generator, runManager, config) {
1295
1297
  let finalChunk;
@@ -1308,36 +1310,38 @@ export class RunnableLambda extends Runnable {
1308
1310
  }
1309
1311
  }
1310
1312
  }
1311
- // eslint-disable-next-line prefer-destructuring
1312
- const func = this.func;
1313
- async function* generatorWrapper() {
1314
- const output = await func(finalChunk, { ...config, config });
1315
- if (output && Runnable.isRunnable(output)) {
1316
- if (config?.recursionLimit === 0) {
1317
- throw new Error("Recursion limit reached.");
1313
+ const output = await new Promise((resolve, reject) => {
1314
+ void AsyncLocalStorageProviderSingleton.getInstance().run(config, async () => {
1315
+ try {
1316
+ const res = await this.func(finalChunk, {
1317
+ ...config,
1318
+ config,
1319
+ });
1320
+ resolve(res);
1318
1321
  }
1319
- const stream = await output.stream(finalChunk, patchConfig(config, {
1320
- callbacks: runManager?.getChild(),
1321
- recursionLimit: (config?.recursionLimit ?? DEFAULT_RECURSION_LIMIT) - 1,
1322
- }));
1323
- for await (const chunk of stream) {
1324
- yield chunk;
1322
+ catch (e) {
1323
+ reject(e);
1325
1324
  }
1325
+ });
1326
+ });
1327
+ if (output && Runnable.isRunnable(output)) {
1328
+ if (config?.recursionLimit === 0) {
1329
+ throw new Error("Recursion limit reached.");
1326
1330
  }
1327
- else {
1328
- yield output;
1331
+ const stream = await output.stream(finalChunk, patchConfig(config, {
1332
+ callbacks: runManager?.getChild(),
1333
+ recursionLimit: (config?.recursionLimit ?? DEFAULT_RECURSION_LIMIT) - 1,
1334
+ }));
1335
+ for await (const chunk of stream) {
1336
+ yield chunk;
1329
1337
  }
1330
1338
  }
1331
- const finalGenerator = await new Promise((resolve) => {
1332
- void AsyncLocalStorageProviderSingleton.getInstance().run(config, async () => {
1333
- const wrappedGenerator = generatorWrapper();
1334
- resolve(wrappedGenerator);
1335
- });
1336
- });
1337
- yield* finalGenerator;
1339
+ else {
1340
+ yield output;
1341
+ }
1338
1342
  }
1339
1343
  transform(generator, options) {
1340
- return this._transformStreamWithConfig(generator, this._transform.bind(this), options ?? AsyncLocalStorageProviderSingleton.getInstance().getStore());
1344
+ return this._transformStreamWithConfig(generator, this._transform.bind(this), options);
1341
1345
  }
1342
1346
  async stream(input, options) {
1343
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 (config) {
93
- empty = { ...empty, ...config };
94
+ if (loadedConfig) {
95
+ empty = { ...empty, ...loadedConfig };
94
96
  }
95
- if (config?.configurable) {
96
- for (const key of Object.keys(config.configurable)) {
97
- if (PRIMITIVES.has(typeof config.configurable[key]) &&
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] = config.configurable[key];
104
+ empty.metadata[key] = loadedConfig.configurable[key];
103
105
  }
104
106
  }
105
107
  }
@@ -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 (config) {
88
- empty = { ...empty, ...config };
89
+ if (loadedConfig) {
90
+ empty = { ...empty, ...loadedConfig };
89
91
  }
90
- if (config?.configurable) {
91
- for (const key of Object.keys(config.configurable)) {
92
- if (PRIMITIVES.has(typeof config.configurable[key]) &&
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] = config.configurable[key];
99
+ empty.metadata[key] = loadedConfig.configurable[key];
98
100
  }
99
101
  }
100
102
  }
@@ -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";
@@ -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, options);
64
+ await this.func(input, config);
63
65
  }
64
- return this._callWithConfig((input) => Promise.resolve(input), input, options);
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, options)) {
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, options);
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 { RunnableConfig } from "./config.js";
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, options);
61
+ await this.func(input, config);
60
62
  }
61
- return this._callWithConfig((input) => Promise.resolve(input), input, options);
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, options)) {
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, options);
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 { RunnableConfig } from "./runnables/config.js";
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/core",
3
- "version": "0.1.33-rc.1",
3
+ "version": "0.1.33-rc.3",
4
4
  "description": "Core LangChain.js abstractions and schemas",
5
5
  "type": "module",
6
6
  "engines": {