@langchain/core 0.1.52 → 0.1.54
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/callbacks/base.d.ts +1 -1
- package/dist/callbacks/manager.cjs +13 -11
- package/dist/callbacks/manager.d.ts +8 -3
- package/dist/callbacks/manager.js +13 -11
- package/dist/example_selectors/conditional.d.ts +1 -1
- package/dist/language_models/chat_models.cjs +3 -3
- package/dist/language_models/chat_models.js +3 -3
- package/dist/language_models/llms.cjs +5 -4
- package/dist/language_models/llms.d.ts +2 -1
- package/dist/language_models/llms.js +5 -4
- package/dist/load/import_map.cjs +2 -2
- package/dist/load/import_map.d.ts +2 -2
- package/dist/load/import_map.js +2 -2
- package/dist/messages/index.d.ts +10 -3
- package/dist/output_parsers/string.cjs +12 -5
- package/dist/output_parsers/string.js +12 -5
- package/dist/prompts/base.d.ts +1 -1
- package/dist/prompts/chat.cjs +32 -3
- package/dist/prompts/chat.d.ts +1 -1
- package/dist/prompts/chat.js +32 -3
- package/dist/prompts/few_shot.d.ts +1 -1
- package/dist/prompts/image.d.ts +1 -1
- package/dist/prompts/pipeline.d.ts +1 -1
- package/dist/prompts/prompt.d.ts +1 -1
- package/dist/prompts/string.d.ts +1 -1
- package/dist/prompts/structured.d.ts +1 -1
- package/dist/prompts/template.d.ts +1 -1
- package/dist/retrievers/document_compressors/base.cjs +13 -0
- package/dist/retrievers/document_compressors/base.d.ts +18 -0
- package/dist/retrievers/document_compressors/base.js +9 -0
- package/dist/{retrievers.cjs → retrievers/index.cjs} +4 -4
- package/dist/{retrievers.d.ts → retrievers/index.d.ts} +4 -4
- package/dist/{retrievers.js → retrievers/index.js} +4 -4
- package/dist/runnables/base.cjs +36 -11
- package/dist/runnables/base.js +36 -11
- package/dist/runnables/branch.cjs +1 -1
- package/dist/runnables/branch.js +1 -1
- package/dist/runnables/config.cjs +5 -1
- package/dist/runnables/config.d.ts +1 -1
- package/dist/runnables/config.js +5 -1
- package/dist/runnables/remote.cjs +120 -79
- package/dist/runnables/remote.d.ts +3 -3
- package/dist/runnables/remote.js +123 -82
- package/dist/tools.cjs +2 -1
- package/dist/tools.js +2 -1
- package/dist/tracers/base.d.ts +1 -1
- package/dist/tracers/tracer_langchain_v1.d.ts +1 -1
- package/dist/utils/testing/index.cjs +37 -3
- package/dist/utils/testing/index.d.ts +10 -1
- package/dist/utils/testing/index.js +34 -1
- package/dist/utils/types/index.cjs +17 -0
- package/dist/utils/{types.d.ts → types/index.d.ts} +1 -0
- package/dist/utils/types/index.js +1 -0
- package/dist/utils/types/is_zod_schema.cjs +16 -0
- package/dist/utils/types/is_zod_schema.d.ts +8 -0
- package/dist/utils/types/is_zod_schema.js +12 -0
- package/dist/vectorstores.cjs +2 -2
- package/dist/vectorstores.d.ts +1 -1
- package/dist/vectorstores.js +1 -1
- package/package.json +27 -14
- package/retrievers/document_compressors.cjs +1 -0
- package/retrievers/document_compressors.d.cts +1 -0
- package/retrievers/document_compressors.d.ts +1 -0
- package/retrievers/document_compressors.js +1 -0
- package/retrievers.cjs +1 -1
- package/retrievers.d.cts +1 -1
- package/retrievers.d.ts +1 -1
- package/retrievers.js +1 -1
- package/utils/types.cjs +1 -1
- package/utils/types.d.cts +1 -1
- package/utils/types.d.ts +1 -1
- package/utils/types.js +1 -1
- package/dist/utils/types.cjs +0 -5
- package/dist/utils/types.js +0 -4
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ChatPromptValueInterface } from "../prompt_values.js";
|
|
2
2
|
import { RunnableLike, Runnable } from "../runnables/base.js";
|
|
3
3
|
import { RunnableConfig } from "../runnables/config.js";
|
|
4
|
-
import { InputValues } from "../utils/types.js";
|
|
4
|
+
import { InputValues } from "../utils/types/index.js";
|
|
5
5
|
import { BaseMessagePromptTemplateLike, ChatPromptTemplate, ChatPromptTemplateInput } from "./chat.js";
|
|
6
6
|
/**
|
|
7
7
|
* Interface for the input of a ChatPromptTemplate.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MessageContent } from "../messages/index.js";
|
|
2
|
-
import type { InputValues } from "../utils/types.js";
|
|
2
|
+
import type { InputValues } from "../utils/types/index.js";
|
|
3
3
|
/**
|
|
4
4
|
* Type that specifies the format of a template. Only
|
|
5
5
|
* "f-string" is supported currently.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseDocumentCompressor = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Base Document Compression class. All compressors should extend this class.
|
|
6
|
+
*/
|
|
7
|
+
class BaseDocumentCompressor {
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
|
+
static isBaseDocumentCompressor(x) {
|
|
10
|
+
return x?.compressDocuments !== undefined;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.BaseDocumentCompressor = BaseDocumentCompressor;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Callbacks } from "../../callbacks/manager.js";
|
|
2
|
+
import { DocumentInterface } from "../../documents/document.js";
|
|
3
|
+
/**
|
|
4
|
+
* Base Document Compression class. All compressors should extend this class.
|
|
5
|
+
*/
|
|
6
|
+
export declare abstract class BaseDocumentCompressor {
|
|
7
|
+
/**
|
|
8
|
+
* Abstract method that must be implemented by any class that extends
|
|
9
|
+
* `BaseDocumentCompressor`. This method takes an array of `Document`
|
|
10
|
+
* objects and a query string as parameters and returns a Promise that
|
|
11
|
+
* resolves with an array of compressed `Document` objects.
|
|
12
|
+
* @param documents An array of `Document` objects to be compressed.
|
|
13
|
+
* @param query A query string.
|
|
14
|
+
* @returns A Promise that resolves with an array of compressed `Document` objects.
|
|
15
|
+
*/
|
|
16
|
+
abstract compressDocuments(documents: DocumentInterface[], query: string, callbacks?: Callbacks): Promise<DocumentInterface[]>;
|
|
17
|
+
static isBaseDocumentCompressor(x: any): x is BaseDocumentCompressor;
|
|
18
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base Document Compression class. All compressors should extend this class.
|
|
3
|
+
*/
|
|
4
|
+
export class BaseDocumentCompressor {
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
6
|
+
static isBaseDocumentCompressor(x) {
|
|
7
|
+
return x?.compressDocuments !== undefined;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BaseRetriever = void 0;
|
|
4
|
-
const manager_js_1 = require("
|
|
5
|
-
const base_js_1 = require("
|
|
6
|
-
const config_js_1 = require("
|
|
4
|
+
const manager_js_1 = require("../callbacks/manager.cjs");
|
|
5
|
+
const base_js_1 = require("../runnables/base.cjs");
|
|
6
|
+
const config_js_1 = require("../runnables/config.cjs");
|
|
7
7
|
/**
|
|
8
8
|
* Abstract base class for a Document retrieval system. A retrieval system
|
|
9
9
|
* is defined as something that can take string queries and return the
|
|
@@ -65,7 +65,7 @@ class BaseRetriever extends base_js_1.Runnable {
|
|
|
65
65
|
async getRelevantDocuments(query, config) {
|
|
66
66
|
const parsedConfig = (0, config_js_1.ensureConfig)((0, manager_js_1.parseCallbackConfigArg)(config));
|
|
67
67
|
const callbackManager_ = await manager_js_1.CallbackManager.configure(parsedConfig.callbacks, this.callbacks, parsedConfig.tags, this.tags, parsedConfig.metadata, this.metadata, { verbose: this.verbose });
|
|
68
|
-
const runManager = await callbackManager_?.handleRetrieverStart(this.toJSON(), query,
|
|
68
|
+
const runManager = await callbackManager_?.handleRetrieverStart(this.toJSON(), query, parsedConfig.runId, undefined, undefined, undefined, parsedConfig.runName);
|
|
69
69
|
try {
|
|
70
70
|
const results = await this._getRelevantDocuments(query, runManager);
|
|
71
71
|
await runManager?.handleRetrieverEnd(results);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { BaseCallbackConfig, CallbackManagerForRetrieverRun, Callbacks } from "
|
|
2
|
-
import type { DocumentInterface } from "
|
|
3
|
-
import { Runnable, type RunnableInterface } from "
|
|
4
|
-
import { RunnableConfig } from "
|
|
1
|
+
import { BaseCallbackConfig, CallbackManagerForRetrieverRun, Callbacks } from "../callbacks/manager.js";
|
|
2
|
+
import type { DocumentInterface } from "../documents/document.js";
|
|
3
|
+
import { Runnable, type RunnableInterface } from "../runnables/base.js";
|
|
4
|
+
import { RunnableConfig } from "../runnables/config.js";
|
|
5
5
|
/**
|
|
6
6
|
* Base Retriever class. All indexes should extend this class.
|
|
7
7
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { CallbackManager, parseCallbackConfigArg, } from "
|
|
2
|
-
import { Runnable } from "
|
|
3
|
-
import { ensureConfig } from "
|
|
1
|
+
import { CallbackManager, parseCallbackConfigArg, } from "../callbacks/manager.js";
|
|
2
|
+
import { Runnable } from "../runnables/base.js";
|
|
3
|
+
import { ensureConfig } from "../runnables/config.js";
|
|
4
4
|
/**
|
|
5
5
|
* Abstract base class for a Document retrieval system. A retrieval system
|
|
6
6
|
* is defined as something that can take string queries and return the
|
|
@@ -62,7 +62,7 @@ export class BaseRetriever extends Runnable {
|
|
|
62
62
|
async getRelevantDocuments(query, config) {
|
|
63
63
|
const parsedConfig = ensureConfig(parseCallbackConfigArg(config));
|
|
64
64
|
const callbackManager_ = await CallbackManager.configure(parsedConfig.callbacks, this.callbacks, parsedConfig.tags, this.tags, parsedConfig.metadata, this.metadata, { verbose: this.verbose });
|
|
65
|
-
const runManager = await callbackManager_?.handleRetrieverStart(this.toJSON(), query,
|
|
65
|
+
const runManager = await callbackManager_?.handleRetrieverStart(this.toJSON(), query, parsedConfig.runId, undefined, undefined, undefined, parsedConfig.runName);
|
|
66
66
|
try {
|
|
67
67
|
const results = await this._getRelevantDocuments(query, runManager);
|
|
68
68
|
await runManager?.handleRetrieverEnd(results);
|
package/dist/runnables/base.cjs
CHANGED
|
@@ -112,12 +112,17 @@ class Runnable extends serializable_js_1.Serializable {
|
|
|
112
112
|
});
|
|
113
113
|
}
|
|
114
114
|
_getOptionsList(options, length = 0) {
|
|
115
|
+
if (Array.isArray(options) && options.length !== length) {
|
|
116
|
+
throw new Error(`Passed "options" must be an array with the same length as the inputs, but got ${options.length} options for ${length} inputs`);
|
|
117
|
+
}
|
|
115
118
|
if (Array.isArray(options)) {
|
|
116
|
-
if (options.length !== length) {
|
|
117
|
-
throw new Error(`Passed "options" must be an array with the same length as the inputs, but got ${options.length} options for ${length} inputs`);
|
|
118
|
-
}
|
|
119
119
|
return options.map(config_js_1.ensureConfig);
|
|
120
120
|
}
|
|
121
|
+
if (length > 1 && !Array.isArray(options) && options.runId) {
|
|
122
|
+
console.warn("Provided runId will be used only for the first element of the batch.");
|
|
123
|
+
const subsequent = Object.fromEntries(Object.entries(options).filter(([key]) => key !== "runId"));
|
|
124
|
+
return Array.from({ length }, (_, i) => (0, config_js_1.ensureConfig)(i === 0 ? options : subsequent));
|
|
125
|
+
}
|
|
121
126
|
return Array.from({ length }, () => (0, config_js_1.ensureConfig)(options));
|
|
122
127
|
}
|
|
123
128
|
async batch(inputs, options, batchOptions) {
|
|
@@ -179,6 +184,7 @@ class Runnable extends serializable_js_1.Serializable {
|
|
|
179
184
|
configurable: options.configurable,
|
|
180
185
|
recursionLimit: options.recursionLimit,
|
|
181
186
|
maxConcurrency: options.maxConcurrency,
|
|
187
|
+
runId: options.runId,
|
|
182
188
|
});
|
|
183
189
|
}
|
|
184
190
|
const callOptions = { ...options };
|
|
@@ -189,12 +195,14 @@ class Runnable extends serializable_js_1.Serializable {
|
|
|
189
195
|
delete callOptions.configurable;
|
|
190
196
|
delete callOptions.recursionLimit;
|
|
191
197
|
delete callOptions.maxConcurrency;
|
|
198
|
+
delete callOptions.runId;
|
|
192
199
|
return [runnableConfig, callOptions];
|
|
193
200
|
}
|
|
194
201
|
async _callWithConfig(func, input, options) {
|
|
195
202
|
const config = (0, config_js_1.ensureConfig)(options);
|
|
196
203
|
const callbackManager_ = await (0, config_js_1.getCallbackManagerForConfig)(config);
|
|
197
|
-
const runManager = await callbackManager_?.handleChainStart(this.toJSON(), _coerceToDict(input, "input"),
|
|
204
|
+
const runManager = await callbackManager_?.handleChainStart(this.toJSON(), _coerceToDict(input, "input"), config.runId, config?.runType, undefined, undefined, config?.runName ?? this.getName());
|
|
205
|
+
delete config.runId;
|
|
198
206
|
let output;
|
|
199
207
|
try {
|
|
200
208
|
output = await func.call(this, input, config, runManager);
|
|
@@ -218,7 +226,11 @@ class Runnable extends serializable_js_1.Serializable {
|
|
|
218
226
|
async _batchWithConfig(func, inputs, options, batchOptions) {
|
|
219
227
|
const optionsList = this._getOptionsList(options ?? {}, inputs.length);
|
|
220
228
|
const callbackManagers = await Promise.all(optionsList.map(config_js_1.getCallbackManagerForConfig));
|
|
221
|
-
const runManagers = await Promise.all(callbackManagers.map((callbackManager, i) =>
|
|
229
|
+
const runManagers = await Promise.all(callbackManagers.map(async (callbackManager, i) => {
|
|
230
|
+
const handleStartRes = await callbackManager?.handleChainStart(this.toJSON(), _coerceToDict(inputs[i], "input"), optionsList[i].runId, optionsList[i].runType, undefined, undefined, optionsList[i].runName ?? this.getName());
|
|
231
|
+
delete optionsList[i].runId;
|
|
232
|
+
return handleStartRes;
|
|
233
|
+
}));
|
|
222
234
|
let outputs;
|
|
223
235
|
try {
|
|
224
236
|
outputs = await func.call(this, inputs, optionsList, runManagers, batchOptions);
|
|
@@ -264,7 +276,8 @@ class Runnable extends serializable_js_1.Serializable {
|
|
|
264
276
|
}
|
|
265
277
|
let runManager;
|
|
266
278
|
try {
|
|
267
|
-
const pipe = await (0, stream_js_1.pipeGeneratorWithSetup)(transformer.bind(this), wrapInputForTracing(), async () => callbackManager_?.handleChainStart(this.toJSON(), { input: "" },
|
|
279
|
+
const pipe = await (0, stream_js_1.pipeGeneratorWithSetup)(transformer.bind(this), wrapInputForTracing(), async () => callbackManager_?.handleChainStart(this.toJSON(), { input: "" }, config.runId, config.runType, undefined, undefined, config.runName ?? this.getName()), config);
|
|
280
|
+
delete config.runId;
|
|
268
281
|
runManager = pipe.setup;
|
|
269
282
|
const isLogStreamHandler = (handler) => handler.name === "log_stream_tracer";
|
|
270
283
|
const streamLogHandler = runManager?.handlers.find(isLogStreamHandler);
|
|
@@ -1042,7 +1055,8 @@ class RunnableSequence extends Runnable {
|
|
|
1042
1055
|
async invoke(input, options) {
|
|
1043
1056
|
const config = (0, config_js_1.ensureConfig)(options);
|
|
1044
1057
|
const callbackManager_ = await (0, config_js_1.getCallbackManagerForConfig)(config);
|
|
1045
|
-
const runManager = await callbackManager_?.handleChainStart(this.toJSON(), _coerceToDict(input, "input"),
|
|
1058
|
+
const runManager = await callbackManager_?.handleChainStart(this.toJSON(), _coerceToDict(input, "input"), config.runId, undefined, undefined, undefined, config?.runName);
|
|
1059
|
+
delete config.runId;
|
|
1046
1060
|
let nextStepInput = input;
|
|
1047
1061
|
let finalOutput;
|
|
1048
1062
|
try {
|
|
@@ -1068,7 +1082,11 @@ class RunnableSequence extends Runnable {
|
|
|
1068
1082
|
async batch(inputs, options, batchOptions) {
|
|
1069
1083
|
const configList = this._getOptionsList(options ?? {}, inputs.length);
|
|
1070
1084
|
const callbackManagers = await Promise.all(configList.map(config_js_1.getCallbackManagerForConfig));
|
|
1071
|
-
const runManagers = await Promise.all(callbackManagers.map((callbackManager, i) =>
|
|
1085
|
+
const runManagers = await Promise.all(callbackManagers.map(async (callbackManager, i) => {
|
|
1086
|
+
const handleStartRes = await callbackManager?.handleChainStart(this.toJSON(), _coerceToDict(inputs[i], "input"), configList[i].runId, undefined, undefined, undefined, configList[i].runName);
|
|
1087
|
+
delete configList[i].runId;
|
|
1088
|
+
return handleStartRes;
|
|
1089
|
+
}));
|
|
1072
1090
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1073
1091
|
let nextStepInputs = inputs;
|
|
1074
1092
|
try {
|
|
@@ -1248,7 +1266,8 @@ class RunnableMap extends Runnable {
|
|
|
1248
1266
|
const callbackManager_ = await (0, config_js_1.getCallbackManagerForConfig)(config);
|
|
1249
1267
|
const runManager = await callbackManager_?.handleChainStart(this.toJSON(), {
|
|
1250
1268
|
input,
|
|
1251
|
-
},
|
|
1269
|
+
}, config.runId, undefined, undefined, undefined, config?.runName);
|
|
1270
|
+
delete config.runId;
|
|
1252
1271
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1253
1272
|
const output = {};
|
|
1254
1273
|
try {
|
|
@@ -1469,7 +1488,9 @@ class RunnableWithFallbacks extends Runnable {
|
|
|
1469
1488
|
}
|
|
1470
1489
|
async invoke(input, options) {
|
|
1471
1490
|
const callbackManager_ = await manager_js_1.CallbackManager.configure(options?.callbacks, undefined, options?.tags, undefined, options?.metadata);
|
|
1472
|
-
const runManager = await callbackManager_?.handleChainStart(this.toJSON(), _coerceToDict(input, "input"),
|
|
1491
|
+
const runManager = await callbackManager_?.handleChainStart(this.toJSON(), _coerceToDict(input, "input"), options?.runId, undefined, undefined, undefined, options?.runName);
|
|
1492
|
+
// eslint-disable-next-line no-param-reassign
|
|
1493
|
+
delete options?.runId;
|
|
1473
1494
|
let firstError;
|
|
1474
1495
|
for (const runnable of this.runnables()) {
|
|
1475
1496
|
try {
|
|
@@ -1495,7 +1516,11 @@ class RunnableWithFallbacks extends Runnable {
|
|
|
1495
1516
|
}
|
|
1496
1517
|
const configList = this._getOptionsList(options ?? {}, inputs.length);
|
|
1497
1518
|
const callbackManagers = await Promise.all(configList.map((config) => manager_js_1.CallbackManager.configure(config?.callbacks, undefined, config?.tags, undefined, config?.metadata)));
|
|
1498
|
-
const runManagers = await Promise.all(callbackManagers.map((callbackManager, i) =>
|
|
1519
|
+
const runManagers = await Promise.all(callbackManagers.map(async (callbackManager, i) => {
|
|
1520
|
+
const handleStartRes = await callbackManager?.handleChainStart(this.toJSON(), _coerceToDict(inputs[i], "input"), configList[i].runId, undefined, undefined, undefined, configList[i].runName);
|
|
1521
|
+
delete configList[i].runId;
|
|
1522
|
+
return handleStartRes;
|
|
1523
|
+
}));
|
|
1499
1524
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1500
1525
|
let firstError;
|
|
1501
1526
|
for (const runnable of this.runnables()) {
|
package/dist/runnables/base.js
CHANGED
|
@@ -105,12 +105,17 @@ export class Runnable extends Serializable {
|
|
|
105
105
|
});
|
|
106
106
|
}
|
|
107
107
|
_getOptionsList(options, length = 0) {
|
|
108
|
+
if (Array.isArray(options) && options.length !== length) {
|
|
109
|
+
throw new Error(`Passed "options" must be an array with the same length as the inputs, but got ${options.length} options for ${length} inputs`);
|
|
110
|
+
}
|
|
108
111
|
if (Array.isArray(options)) {
|
|
109
|
-
if (options.length !== length) {
|
|
110
|
-
throw new Error(`Passed "options" must be an array with the same length as the inputs, but got ${options.length} options for ${length} inputs`);
|
|
111
|
-
}
|
|
112
112
|
return options.map(ensureConfig);
|
|
113
113
|
}
|
|
114
|
+
if (length > 1 && !Array.isArray(options) && options.runId) {
|
|
115
|
+
console.warn("Provided runId will be used only for the first element of the batch.");
|
|
116
|
+
const subsequent = Object.fromEntries(Object.entries(options).filter(([key]) => key !== "runId"));
|
|
117
|
+
return Array.from({ length }, (_, i) => ensureConfig(i === 0 ? options : subsequent));
|
|
118
|
+
}
|
|
114
119
|
return Array.from({ length }, () => ensureConfig(options));
|
|
115
120
|
}
|
|
116
121
|
async batch(inputs, options, batchOptions) {
|
|
@@ -172,6 +177,7 @@ export class Runnable extends Serializable {
|
|
|
172
177
|
configurable: options.configurable,
|
|
173
178
|
recursionLimit: options.recursionLimit,
|
|
174
179
|
maxConcurrency: options.maxConcurrency,
|
|
180
|
+
runId: options.runId,
|
|
175
181
|
});
|
|
176
182
|
}
|
|
177
183
|
const callOptions = { ...options };
|
|
@@ -182,12 +188,14 @@ export class Runnable extends Serializable {
|
|
|
182
188
|
delete callOptions.configurable;
|
|
183
189
|
delete callOptions.recursionLimit;
|
|
184
190
|
delete callOptions.maxConcurrency;
|
|
191
|
+
delete callOptions.runId;
|
|
185
192
|
return [runnableConfig, callOptions];
|
|
186
193
|
}
|
|
187
194
|
async _callWithConfig(func, input, options) {
|
|
188
195
|
const config = ensureConfig(options);
|
|
189
196
|
const callbackManager_ = await getCallbackManagerForConfig(config);
|
|
190
|
-
const runManager = await callbackManager_?.handleChainStart(this.toJSON(), _coerceToDict(input, "input"),
|
|
197
|
+
const runManager = await callbackManager_?.handleChainStart(this.toJSON(), _coerceToDict(input, "input"), config.runId, config?.runType, undefined, undefined, config?.runName ?? this.getName());
|
|
198
|
+
delete config.runId;
|
|
191
199
|
let output;
|
|
192
200
|
try {
|
|
193
201
|
output = await func.call(this, input, config, runManager);
|
|
@@ -211,7 +219,11 @@ export class Runnable extends Serializable {
|
|
|
211
219
|
async _batchWithConfig(func, inputs, options, batchOptions) {
|
|
212
220
|
const optionsList = this._getOptionsList(options ?? {}, inputs.length);
|
|
213
221
|
const callbackManagers = await Promise.all(optionsList.map(getCallbackManagerForConfig));
|
|
214
|
-
const runManagers = await Promise.all(callbackManagers.map((callbackManager, i) =>
|
|
222
|
+
const runManagers = await Promise.all(callbackManagers.map(async (callbackManager, i) => {
|
|
223
|
+
const handleStartRes = await callbackManager?.handleChainStart(this.toJSON(), _coerceToDict(inputs[i], "input"), optionsList[i].runId, optionsList[i].runType, undefined, undefined, optionsList[i].runName ?? this.getName());
|
|
224
|
+
delete optionsList[i].runId;
|
|
225
|
+
return handleStartRes;
|
|
226
|
+
}));
|
|
215
227
|
let outputs;
|
|
216
228
|
try {
|
|
217
229
|
outputs = await func.call(this, inputs, optionsList, runManagers, batchOptions);
|
|
@@ -257,7 +269,8 @@ export class Runnable extends Serializable {
|
|
|
257
269
|
}
|
|
258
270
|
let runManager;
|
|
259
271
|
try {
|
|
260
|
-
const pipe = await pipeGeneratorWithSetup(transformer.bind(this), wrapInputForTracing(), async () => callbackManager_?.handleChainStart(this.toJSON(), { input: "" },
|
|
272
|
+
const pipe = await pipeGeneratorWithSetup(transformer.bind(this), wrapInputForTracing(), async () => callbackManager_?.handleChainStart(this.toJSON(), { input: "" }, config.runId, config.runType, undefined, undefined, config.runName ?? this.getName()), config);
|
|
273
|
+
delete config.runId;
|
|
261
274
|
runManager = pipe.setup;
|
|
262
275
|
const isLogStreamHandler = (handler) => handler.name === "log_stream_tracer";
|
|
263
276
|
const streamLogHandler = runManager?.handlers.find(isLogStreamHandler);
|
|
@@ -1031,7 +1044,8 @@ export class RunnableSequence extends Runnable {
|
|
|
1031
1044
|
async invoke(input, options) {
|
|
1032
1045
|
const config = ensureConfig(options);
|
|
1033
1046
|
const callbackManager_ = await getCallbackManagerForConfig(config);
|
|
1034
|
-
const runManager = await callbackManager_?.handleChainStart(this.toJSON(), _coerceToDict(input, "input"),
|
|
1047
|
+
const runManager = await callbackManager_?.handleChainStart(this.toJSON(), _coerceToDict(input, "input"), config.runId, undefined, undefined, undefined, config?.runName);
|
|
1048
|
+
delete config.runId;
|
|
1035
1049
|
let nextStepInput = input;
|
|
1036
1050
|
let finalOutput;
|
|
1037
1051
|
try {
|
|
@@ -1057,7 +1071,11 @@ export class RunnableSequence extends Runnable {
|
|
|
1057
1071
|
async batch(inputs, options, batchOptions) {
|
|
1058
1072
|
const configList = this._getOptionsList(options ?? {}, inputs.length);
|
|
1059
1073
|
const callbackManagers = await Promise.all(configList.map(getCallbackManagerForConfig));
|
|
1060
|
-
const runManagers = await Promise.all(callbackManagers.map((callbackManager, i) =>
|
|
1074
|
+
const runManagers = await Promise.all(callbackManagers.map(async (callbackManager, i) => {
|
|
1075
|
+
const handleStartRes = await callbackManager?.handleChainStart(this.toJSON(), _coerceToDict(inputs[i], "input"), configList[i].runId, undefined, undefined, undefined, configList[i].runName);
|
|
1076
|
+
delete configList[i].runId;
|
|
1077
|
+
return handleStartRes;
|
|
1078
|
+
}));
|
|
1061
1079
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1062
1080
|
let nextStepInputs = inputs;
|
|
1063
1081
|
try {
|
|
@@ -1236,7 +1254,8 @@ export class RunnableMap extends Runnable {
|
|
|
1236
1254
|
const callbackManager_ = await getCallbackManagerForConfig(config);
|
|
1237
1255
|
const runManager = await callbackManager_?.handleChainStart(this.toJSON(), {
|
|
1238
1256
|
input,
|
|
1239
|
-
},
|
|
1257
|
+
}, config.runId, undefined, undefined, undefined, config?.runName);
|
|
1258
|
+
delete config.runId;
|
|
1240
1259
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1241
1260
|
const output = {};
|
|
1242
1261
|
try {
|
|
@@ -1454,7 +1473,9 @@ export class RunnableWithFallbacks extends Runnable {
|
|
|
1454
1473
|
}
|
|
1455
1474
|
async invoke(input, options) {
|
|
1456
1475
|
const callbackManager_ = await CallbackManager.configure(options?.callbacks, undefined, options?.tags, undefined, options?.metadata);
|
|
1457
|
-
const runManager = await callbackManager_?.handleChainStart(this.toJSON(), _coerceToDict(input, "input"),
|
|
1476
|
+
const runManager = await callbackManager_?.handleChainStart(this.toJSON(), _coerceToDict(input, "input"), options?.runId, undefined, undefined, undefined, options?.runName);
|
|
1477
|
+
// eslint-disable-next-line no-param-reassign
|
|
1478
|
+
delete options?.runId;
|
|
1458
1479
|
let firstError;
|
|
1459
1480
|
for (const runnable of this.runnables()) {
|
|
1460
1481
|
try {
|
|
@@ -1480,7 +1501,11 @@ export class RunnableWithFallbacks extends Runnable {
|
|
|
1480
1501
|
}
|
|
1481
1502
|
const configList = this._getOptionsList(options ?? {}, inputs.length);
|
|
1482
1503
|
const callbackManagers = await Promise.all(configList.map((config) => CallbackManager.configure(config?.callbacks, undefined, config?.tags, undefined, config?.metadata)));
|
|
1483
|
-
const runManagers = await Promise.all(callbackManagers.map((callbackManager, i) =>
|
|
1504
|
+
const runManagers = await Promise.all(callbackManagers.map(async (callbackManager, i) => {
|
|
1505
|
+
const handleStartRes = await callbackManager?.handleChainStart(this.toJSON(), _coerceToDict(inputs[i], "input"), configList[i].runId, undefined, undefined, undefined, configList[i].runName);
|
|
1506
|
+
delete configList[i].runId;
|
|
1507
|
+
return handleStartRes;
|
|
1508
|
+
}));
|
|
1484
1509
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1485
1510
|
let firstError;
|
|
1486
1511
|
for (const runnable of this.runnables()) {
|
|
@@ -140,7 +140,7 @@ class RunnableBranch extends base_js_1.Runnable {
|
|
|
140
140
|
}
|
|
141
141
|
async *_streamIterator(input, config) {
|
|
142
142
|
const callbackManager_ = await (0, config_js_1.getCallbackManagerForConfig)(config);
|
|
143
|
-
const runManager = await callbackManager_?.handleChainStart(this.toJSON(), (0, base_js_1._coerceToDict)(input, "input"),
|
|
143
|
+
const runManager = await callbackManager_?.handleChainStart(this.toJSON(), (0, base_js_1._coerceToDict)(input, "input"), config?.runId, undefined, undefined, undefined, config?.runName);
|
|
144
144
|
let finalOutput;
|
|
145
145
|
let finalOutputSupported = true;
|
|
146
146
|
let stream;
|
package/dist/runnables/branch.js
CHANGED
|
@@ -137,7 +137,7 @@ export class RunnableBranch extends Runnable {
|
|
|
137
137
|
}
|
|
138
138
|
async *_streamIterator(input, config) {
|
|
139
139
|
const callbackManager_ = await getCallbackManagerForConfig(config);
|
|
140
|
-
const runManager = await callbackManager_?.handleChainStart(this.toJSON(), _coerceToDict(input, "input"),
|
|
140
|
+
const runManager = await callbackManager_?.handleChainStart(this.toJSON(), _coerceToDict(input, "input"), config?.runId, undefined, undefined, undefined, config?.runName);
|
|
141
141
|
let finalOutput;
|
|
142
142
|
let finalOutputSupported = true;
|
|
143
143
|
let stream;
|
|
@@ -95,6 +95,7 @@ function ensureConfig(config) {
|
|
|
95
95
|
metadata: {},
|
|
96
96
|
callbacks: undefined,
|
|
97
97
|
recursionLimit: 25,
|
|
98
|
+
runId: undefined,
|
|
98
99
|
};
|
|
99
100
|
if (loadedConfig) {
|
|
100
101
|
empty = { ...empty, ...loadedConfig };
|
|
@@ -116,7 +117,7 @@ exports.ensureConfig = ensureConfig;
|
|
|
116
117
|
/**
|
|
117
118
|
* Helper function that patches runnable configs with updated properties.
|
|
118
119
|
*/
|
|
119
|
-
function patchConfig(config = {}, { callbacks, maxConcurrency, recursionLimit, runName, configurable, } = {}) {
|
|
120
|
+
function patchConfig(config = {}, { callbacks, maxConcurrency, recursionLimit, runName, configurable, runId, } = {}) {
|
|
120
121
|
const newConfig = ensureConfig(config);
|
|
121
122
|
if (callbacks !== undefined) {
|
|
122
123
|
/**
|
|
@@ -138,6 +139,9 @@ function patchConfig(config = {}, { callbacks, maxConcurrency, recursionLimit, r
|
|
|
138
139
|
if (configurable !== undefined) {
|
|
139
140
|
newConfig.configurable = { ...newConfig.configurable, ...configurable };
|
|
140
141
|
}
|
|
142
|
+
if (runId !== undefined) {
|
|
143
|
+
delete newConfig.runId;
|
|
144
|
+
}
|
|
141
145
|
return newConfig;
|
|
142
146
|
}
|
|
143
147
|
exports.patchConfig = patchConfig;
|
|
@@ -25,4 +25,4 @@ export declare function ensureConfig<CallOptions extends RunnableConfig>(config?
|
|
|
25
25
|
/**
|
|
26
26
|
* Helper function that patches runnable configs with updated properties.
|
|
27
27
|
*/
|
|
28
|
-
export declare function patchConfig<CallOptions extends RunnableConfig>(config?: Partial<CallOptions>, { callbacks, maxConcurrency, recursionLimit, runName, configurable, }?: RunnableConfig): Partial<CallOptions>;
|
|
28
|
+
export declare function patchConfig<CallOptions extends RunnableConfig>(config?: Partial<CallOptions>, { callbacks, maxConcurrency, recursionLimit, runName, configurable, runId, }?: RunnableConfig): Partial<CallOptions>;
|
package/dist/runnables/config.js
CHANGED
|
@@ -90,6 +90,7 @@ export function ensureConfig(config) {
|
|
|
90
90
|
metadata: {},
|
|
91
91
|
callbacks: undefined,
|
|
92
92
|
recursionLimit: 25,
|
|
93
|
+
runId: undefined,
|
|
93
94
|
};
|
|
94
95
|
if (loadedConfig) {
|
|
95
96
|
empty = { ...empty, ...loadedConfig };
|
|
@@ -110,7 +111,7 @@ export function ensureConfig(config) {
|
|
|
110
111
|
/**
|
|
111
112
|
* Helper function that patches runnable configs with updated properties.
|
|
112
113
|
*/
|
|
113
|
-
export function patchConfig(config = {}, { callbacks, maxConcurrency, recursionLimit, runName, configurable, } = {}) {
|
|
114
|
+
export function patchConfig(config = {}, { callbacks, maxConcurrency, recursionLimit, runName, configurable, runId, } = {}) {
|
|
114
115
|
const newConfig = ensureConfig(config);
|
|
115
116
|
if (callbacks !== undefined) {
|
|
116
117
|
/**
|
|
@@ -132,5 +133,8 @@ export function patchConfig(config = {}, { callbacks, maxConcurrency, recursionL
|
|
|
132
133
|
if (configurable !== undefined) {
|
|
133
134
|
newConfig.configurable = { ...newConfig.configurable, ...configurable };
|
|
134
135
|
}
|
|
136
|
+
if (runId !== undefined) {
|
|
137
|
+
delete newConfig.runId;
|
|
138
|
+
}
|
|
135
139
|
return newConfig;
|
|
136
140
|
}
|