@langchain/core 0.2.18 → 0.2.20
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/manager.cjs +94 -19
- package/dist/callbacks/manager.d.ts +3 -1
- package/dist/callbacks/manager.js +94 -19
- package/dist/language_models/base.d.ts +0 -10
- package/dist/language_models/chat_models.cjs +5 -6
- package/dist/language_models/chat_models.d.ts +9 -10
- package/dist/language_models/chat_models.js +5 -6
- package/dist/language_models/llms.cjs +5 -6
- package/dist/language_models/llms.d.ts +10 -12
- package/dist/language_models/llms.js +5 -6
- package/dist/messages/base.cjs +16 -1
- package/dist/messages/base.d.ts +9 -0
- package/dist/messages/base.js +14 -0
- package/dist/messages/tool.cjs +23 -0
- package/dist/messages/tool.d.ts +15 -0
- package/dist/messages/tool.js +24 -1
- package/dist/messages/utils.cjs +1 -1
- package/dist/messages/utils.js +1 -1
- package/dist/output_parsers/string.cjs +1 -0
- package/dist/output_parsers/string.js +1 -0
- package/dist/runnables/base.cjs +35 -12
- package/dist/runnables/base.js +35 -12
- package/dist/runnables/config.cjs +41 -0
- package/dist/runnables/config.js +41 -0
- package/dist/runnables/remote.cjs +17 -14
- package/dist/runnables/remote.js +17 -14
- package/dist/runnables/types.d.ts +10 -0
- package/dist/tools/index.cjs +15 -6
- package/dist/tools/index.d.ts +21 -12
- package/dist/tools/index.js +15 -6
- package/dist/utils/math.cjs +6 -4
- package/dist/utils/math.js +6 -4
- package/dist/utils/ml-distance/distances.cjs +18 -0
- package/dist/utils/ml-distance/distances.d.ts +8 -0
- package/dist/utils/ml-distance/distances.js +14 -0
- package/dist/utils/ml-distance/similarities.cjs +21 -0
- package/dist/utils/ml-distance/similarities.d.ts +7 -0
- package/dist/utils/ml-distance/similarities.js +17 -0
- package/dist/utils/ml-distance-euclidean/euclidean.cjs +15 -0
- package/dist/utils/ml-distance-euclidean/euclidean.d.ts +2 -0
- package/dist/utils/ml-distance-euclidean/euclidean.js +10 -0
- package/dist/utils/signal.cjs +28 -0
- package/dist/utils/signal.d.ts +1 -0
- package/dist/utils/signal.js +24 -0
- package/dist/utils/stream.cjs +19 -4
- package/dist/utils/stream.d.ts +3 -1
- package/dist/utils/stream.js +19 -4
- package/dist/utils/testing/index.cjs +168 -4
- package/dist/utils/testing/index.d.ts +100 -6
- package/dist/utils/testing/index.js +167 -4
- package/package.json +4 -4
- package/dist/caches/tests/in_memory_cache.test.d.ts +0 -1
- package/dist/caches/tests/in_memory_cache.test.js +0 -33
- package/dist/callbacks/tests/callbacks.test.d.ts +0 -1
- package/dist/callbacks/tests/callbacks.test.js +0 -495
- package/dist/callbacks/tests/manager.int.test.d.ts +0 -1
- package/dist/callbacks/tests/manager.int.test.js +0 -29
- package/dist/callbacks/tests/run_collector.test.d.ts +0 -1
- package/dist/callbacks/tests/run_collector.test.js +0 -58
- package/dist/language_models/tests/chat_models.test.d.ts +0 -1
- package/dist/language_models/tests/chat_models.test.js +0 -204
- package/dist/language_models/tests/count_tokens.test.d.ts +0 -1
- package/dist/language_models/tests/count_tokens.test.js +0 -19
- package/dist/language_models/tests/llms.test.d.ts +0 -1
- package/dist/language_models/tests/llms.test.js +0 -52
- package/dist/messages/tests/base_message.test.d.ts +0 -1
- package/dist/messages/tests/base_message.test.js +0 -245
- package/dist/messages/tests/message_utils.test.d.ts +0 -1
- package/dist/messages/tests/message_utils.test.js +0 -434
- package/dist/output_parsers/openai_tools/tests/json_output_tools_parser.test.d.ts +0 -1
- package/dist/output_parsers/openai_tools/tests/json_output_tools_parser.test.js +0 -81
- package/dist/output_parsers/tests/json.test.d.ts +0 -1
- package/dist/output_parsers/tests/json.test.js +0 -427
- package/dist/output_parsers/tests/output_parser.test.d.ts +0 -1
- package/dist/output_parsers/tests/output_parser.test.js +0 -78
- package/dist/output_parsers/tests/string.test.d.ts +0 -1
- package/dist/output_parsers/tests/string.test.js +0 -68
- package/dist/output_parsers/tests/structured.test.d.ts +0 -1
- package/dist/output_parsers/tests/structured.test.js +0 -166
- package/dist/output_parsers/tests/xml.test.d.ts +0 -1
- package/dist/output_parsers/tests/xml.test.js +0 -81
- package/dist/prompts/tests/chat.mustache.test.d.ts +0 -1
- package/dist/prompts/tests/chat.mustache.test.js +0 -129
- package/dist/prompts/tests/chat.test.d.ts +0 -1
- package/dist/prompts/tests/chat.test.js +0 -557
- package/dist/prompts/tests/few_shot.test.d.ts +0 -1
- package/dist/prompts/tests/few_shot.test.js +0 -224
- package/dist/prompts/tests/pipeline.test.d.ts +0 -1
- package/dist/prompts/tests/pipeline.test.js +0 -101
- package/dist/prompts/tests/prompt.mustache.test.d.ts +0 -1
- package/dist/prompts/tests/prompt.mustache.test.js +0 -105
- package/dist/prompts/tests/prompt.test.d.ts +0 -1
- package/dist/prompts/tests/prompt.test.js +0 -78
- package/dist/prompts/tests/structured.test.d.ts +0 -1
- package/dist/prompts/tests/structured.test.js +0 -37
- package/dist/prompts/tests/template.test.d.ts +0 -1
- package/dist/prompts/tests/template.test.js +0 -24
- package/dist/runnables/tests/runnable.test.d.ts +0 -1
- package/dist/runnables/tests/runnable.test.js +0 -491
- package/dist/runnables/tests/runnable_binding.test.d.ts +0 -1
- package/dist/runnables/tests/runnable_binding.test.js +0 -46
- package/dist/runnables/tests/runnable_branch.test.d.ts +0 -1
- package/dist/runnables/tests/runnable_branch.test.js +0 -116
- package/dist/runnables/tests/runnable_graph.test.d.ts +0 -1
- package/dist/runnables/tests/runnable_graph.test.js +0 -100
- package/dist/runnables/tests/runnable_history.test.d.ts +0 -1
- package/dist/runnables/tests/runnable_history.test.js +0 -177
- package/dist/runnables/tests/runnable_interface.test.d.ts +0 -1
- package/dist/runnables/tests/runnable_interface.test.js +0 -209
- package/dist/runnables/tests/runnable_map.test.d.ts +0 -1
- package/dist/runnables/tests/runnable_map.test.js +0 -238
- package/dist/runnables/tests/runnable_passthrough.test.d.ts +0 -1
- package/dist/runnables/tests/runnable_passthrough.test.js +0 -96
- package/dist/runnables/tests/runnable_remote.int.test.d.ts +0 -1
- package/dist/runnables/tests/runnable_remote.int.test.js +0 -138
- package/dist/runnables/tests/runnable_remote.test.d.ts +0 -1
- package/dist/runnables/tests/runnable_remote.test.js +0 -200
- package/dist/runnables/tests/runnable_retry.test.d.ts +0 -1
- package/dist/runnables/tests/runnable_retry.test.js +0 -125
- package/dist/runnables/tests/runnable_stream_events.test.d.ts +0 -1
- package/dist/runnables/tests/runnable_stream_events.test.js +0 -1013
- package/dist/runnables/tests/runnable_stream_events_v2.test.d.ts +0 -1
- package/dist/runnables/tests/runnable_stream_events_v2.test.js +0 -2022
- package/dist/runnables/tests/runnable_stream_log.test.d.ts +0 -1
- package/dist/runnables/tests/runnable_stream_log.test.js +0 -71
- package/dist/runnables/tests/runnable_tools.test.d.ts +0 -1
- package/dist/runnables/tests/runnable_tools.test.js +0 -149
- package/dist/runnables/tests/runnable_tracing.int.test.d.ts +0 -1
- package/dist/runnables/tests/runnable_tracing.int.test.js +0 -37
- package/dist/runnables/tests/runnable_with_fallbacks.test.d.ts +0 -1
- package/dist/runnables/tests/runnable_with_fallbacks.test.js +0 -36
- package/dist/singletons/tests/async_local_storage.test.d.ts +0 -1
- package/dist/singletons/tests/async_local_storage.test.js +0 -153
- package/dist/structured_query/tests/utils.test.d.ts +0 -1
- package/dist/structured_query/tests/utils.test.js +0 -47
- package/dist/tools/tests/tools.test.d.ts +0 -1
- package/dist/tools/tests/tools.test.js +0 -85
- package/dist/tracers/tests/langchain_tracer.int.test.d.ts +0 -1
- package/dist/tracers/tests/langchain_tracer.int.test.js +0 -74
- package/dist/tracers/tests/langsmith_interop.test.d.ts +0 -1
- package/dist/tracers/tests/langsmith_interop.test.js +0 -551
- package/dist/tracers/tests/tracer.test.d.ts +0 -1
- package/dist/tracers/tests/tracer.test.js +0 -378
- package/dist/utils/testing/tests/chatfake.test.d.ts +0 -1
- package/dist/utils/testing/tests/chatfake.test.js +0 -112
- package/dist/utils/tests/async_caller.test.d.ts +0 -1
- package/dist/utils/tests/async_caller.test.js +0 -27
- package/dist/utils/tests/enviroment.test.d.ts +0 -1
- package/dist/utils/tests/enviroment.test.js +0 -6
- package/dist/utils/tests/function_calling.test.d.ts +0 -1
- package/dist/utils/tests/function_calling.test.js +0 -107
- package/dist/utils/tests/math_utils.test.d.ts +0 -1
- package/dist/utils/tests/math_utils.test.js +0 -139
- package/dist/utils/tests/polyfill_stream.test.d.ts +0 -1
- package/dist/utils/tests/polyfill_stream.test.js +0 -15
|
@@ -39,11 +39,10 @@ class BaseLLM extends base_js_1.BaseLanguageModel {
|
|
|
39
39
|
async *_streamResponseChunks(_input, _options, _runManager) {
|
|
40
40
|
throw new Error("Not implemented.");
|
|
41
41
|
}
|
|
42
|
-
|
|
42
|
+
_separateRunnableConfigFromCallOptionsCompat(options) {
|
|
43
|
+
// For backwards compat, keep `signal` in both runnableConfig and callOptions
|
|
43
44
|
const [runnableConfig, callOptions] = super._separateRunnableConfigFromCallOptions(options);
|
|
44
|
-
|
|
45
|
-
callOptions.signal = AbortSignal.timeout(callOptions.timeout);
|
|
46
|
-
}
|
|
45
|
+
callOptions.signal = runnableConfig.signal;
|
|
47
46
|
return [runnableConfig, callOptions];
|
|
48
47
|
}
|
|
49
48
|
async *_streamIterator(input, options) {
|
|
@@ -53,7 +52,7 @@ class BaseLLM extends base_js_1.BaseLanguageModel {
|
|
|
53
52
|
}
|
|
54
53
|
else {
|
|
55
54
|
const prompt = BaseLLM._convertInputToPromptValue(input);
|
|
56
|
-
const [runnableConfig, callOptions] = this.
|
|
55
|
+
const [runnableConfig, callOptions] = this._separateRunnableConfigFromCallOptionsCompat(options);
|
|
57
56
|
const callbackManager_ = await manager_js_1.CallbackManager.configure(runnableConfig.callbacks, this.callbacks, runnableConfig.tags, this.tags, runnableConfig.metadata, this.metadata, { verbose: this.verbose });
|
|
58
57
|
const extra = {
|
|
59
58
|
options: callOptions,
|
|
@@ -261,7 +260,7 @@ class BaseLLM extends base_js_1.BaseLanguageModel {
|
|
|
261
260
|
else {
|
|
262
261
|
parsedOptions = options;
|
|
263
262
|
}
|
|
264
|
-
const [runnableConfig, callOptions] = this.
|
|
263
|
+
const [runnableConfig, callOptions] = this._separateRunnableConfigFromCallOptionsCompat(parsedOptions);
|
|
265
264
|
runnableConfig.callbacks = runnableConfig.callbacks ?? callbacks;
|
|
266
265
|
if (!this.cache) {
|
|
267
266
|
return this._generateUncached(prompts, callOptions, runnableConfig);
|
|
@@ -17,19 +17,11 @@ export interface BaseLLMParams extends BaseLanguageModelParams {
|
|
|
17
17
|
}
|
|
18
18
|
export interface BaseLLMCallOptions extends BaseLanguageModelCallOptions {
|
|
19
19
|
}
|
|
20
|
-
interface LLMGenerateCachedParameters<T extends BaseLLM<CallOptions>, CallOptions extends BaseLLMCallOptions = BaseLLMCallOptions> {
|
|
21
|
-
prompts: string[];
|
|
22
|
-
cache: BaseCache<Generation[]>;
|
|
23
|
-
llmStringKey: string;
|
|
24
|
-
parsedOptions: T["ParsedCallOptions"];
|
|
25
|
-
handledOptions: RunnableConfig;
|
|
26
|
-
runId?: string;
|
|
27
|
-
}
|
|
28
20
|
/**
|
|
29
21
|
* LLM Wrapper. Takes in a prompt (or prompts) and returns a string.
|
|
30
22
|
*/
|
|
31
23
|
export declare abstract class BaseLLM<CallOptions extends BaseLLMCallOptions = BaseLLMCallOptions> extends BaseLanguageModel<string, CallOptions> {
|
|
32
|
-
ParsedCallOptions: Omit<CallOptions, keyof RunnableConfig
|
|
24
|
+
ParsedCallOptions: Omit<CallOptions, Exclude<keyof RunnableConfig, "signal" | "timeout" | "maxConcurrency">>;
|
|
33
25
|
lc_namespace: string[];
|
|
34
26
|
constructor({ concurrency, ...rest }: BaseLLMParams);
|
|
35
27
|
/**
|
|
@@ -42,7 +34,7 @@ export declare abstract class BaseLLM<CallOptions extends BaseLLMCallOptions = B
|
|
|
42
34
|
*/
|
|
43
35
|
invoke(input: BaseLanguageModelInput, options?: CallOptions): Promise<string>;
|
|
44
36
|
_streamResponseChunks(_input: string, _options: this["ParsedCallOptions"], _runManager?: CallbackManagerForLLMRun): AsyncGenerator<GenerationChunk>;
|
|
45
|
-
protected
|
|
37
|
+
protected _separateRunnableConfigFromCallOptionsCompat(options?: Partial<CallOptions>): [RunnableConfig, this["ParsedCallOptions"]];
|
|
46
38
|
_streamIterator(input: BaseLanguageModelInput, options?: CallOptions): AsyncGenerator<string>;
|
|
47
39
|
/**
|
|
48
40
|
* This method takes prompt values, options, and callbacks, and generates
|
|
@@ -64,7 +56,14 @@ export declare abstract class BaseLLM<CallOptions extends BaseLLMCallOptions = B
|
|
|
64
56
|
_flattenLLMResult(llmResult: LLMResult): LLMResult[];
|
|
65
57
|
/** @ignore */
|
|
66
58
|
_generateUncached(prompts: string[], parsedOptions: this["ParsedCallOptions"], handledOptions: BaseCallbackConfig): Promise<LLMResult>;
|
|
67
|
-
_generateCached({ prompts, cache, llmStringKey, parsedOptions, handledOptions, runId, }:
|
|
59
|
+
_generateCached({ prompts, cache, llmStringKey, parsedOptions, handledOptions, runId, }: {
|
|
60
|
+
prompts: string[];
|
|
61
|
+
cache: BaseCache<Generation[]>;
|
|
62
|
+
llmStringKey: string;
|
|
63
|
+
parsedOptions: any;
|
|
64
|
+
handledOptions: RunnableConfig;
|
|
65
|
+
runId?: string;
|
|
66
|
+
}): Promise<LLMResult & {
|
|
68
67
|
missingPromptIndices: number[];
|
|
69
68
|
}>;
|
|
70
69
|
/**
|
|
@@ -127,4 +126,3 @@ export declare abstract class LLM<CallOptions extends BaseLLMCallOptions = BaseL
|
|
|
127
126
|
abstract _call(prompt: string, options: this["ParsedCallOptions"], runManager?: CallbackManagerForLLMRun): Promise<string>;
|
|
128
127
|
_generate(prompts: string[], options: this["ParsedCallOptions"], runManager?: CallbackManagerForLLMRun): Promise<LLMResult>;
|
|
129
128
|
}
|
|
130
|
-
export {};
|
|
@@ -36,11 +36,10 @@ export class BaseLLM extends BaseLanguageModel {
|
|
|
36
36
|
async *_streamResponseChunks(_input, _options, _runManager) {
|
|
37
37
|
throw new Error("Not implemented.");
|
|
38
38
|
}
|
|
39
|
-
|
|
39
|
+
_separateRunnableConfigFromCallOptionsCompat(options) {
|
|
40
|
+
// For backwards compat, keep `signal` in both runnableConfig and callOptions
|
|
40
41
|
const [runnableConfig, callOptions] = super._separateRunnableConfigFromCallOptions(options);
|
|
41
|
-
|
|
42
|
-
callOptions.signal = AbortSignal.timeout(callOptions.timeout);
|
|
43
|
-
}
|
|
42
|
+
callOptions.signal = runnableConfig.signal;
|
|
44
43
|
return [runnableConfig, callOptions];
|
|
45
44
|
}
|
|
46
45
|
async *_streamIterator(input, options) {
|
|
@@ -50,7 +49,7 @@ export class BaseLLM extends BaseLanguageModel {
|
|
|
50
49
|
}
|
|
51
50
|
else {
|
|
52
51
|
const prompt = BaseLLM._convertInputToPromptValue(input);
|
|
53
|
-
const [runnableConfig, callOptions] = this.
|
|
52
|
+
const [runnableConfig, callOptions] = this._separateRunnableConfigFromCallOptionsCompat(options);
|
|
54
53
|
const callbackManager_ = await CallbackManager.configure(runnableConfig.callbacks, this.callbacks, runnableConfig.tags, this.tags, runnableConfig.metadata, this.metadata, { verbose: this.verbose });
|
|
55
54
|
const extra = {
|
|
56
55
|
options: callOptions,
|
|
@@ -258,7 +257,7 @@ export class BaseLLM extends BaseLanguageModel {
|
|
|
258
257
|
else {
|
|
259
258
|
parsedOptions = options;
|
|
260
259
|
}
|
|
261
|
-
const [runnableConfig, callOptions] = this.
|
|
260
|
+
const [runnableConfig, callOptions] = this._separateRunnableConfigFromCallOptionsCompat(parsedOptions);
|
|
262
261
|
runnableConfig.callbacks = runnableConfig.callbacks ?? callbacks;
|
|
263
262
|
if (!this.cache) {
|
|
264
263
|
return this._generateUncached(prompts, callOptions, runnableConfig);
|
package/dist/messages/base.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isBaseMessageChunk = exports.isBaseMessage = exports.BaseMessageChunk = exports._mergeObj = exports._mergeLists = exports._mergeDicts = exports.isOpenAIToolCallArray = exports.BaseMessage = exports.mergeContent = void 0;
|
|
3
|
+
exports.isBaseMessageChunk = exports.isBaseMessage = exports.BaseMessageChunk = exports._mergeObj = exports._mergeLists = exports._mergeDicts = exports.isOpenAIToolCallArray = exports.BaseMessage = exports._mergeStatus = exports.mergeContent = void 0;
|
|
4
4
|
const serializable_js_1 = require("../load/serializable.cjs");
|
|
5
5
|
function mergeContent(firstContent, secondContent) {
|
|
6
6
|
// If first content is a string
|
|
@@ -25,6 +25,21 @@ function mergeContent(firstContent, secondContent) {
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
exports.mergeContent = mergeContent;
|
|
28
|
+
/**
|
|
29
|
+
* 'Merge' two statuses. If either value passed is 'error', it will return 'error'. Else
|
|
30
|
+
* it will return 'success'.
|
|
31
|
+
*
|
|
32
|
+
* @param {"success" | "error" | undefined} left The existing value to 'merge' with the new value.
|
|
33
|
+
* @param {"success" | "error" | undefined} right The new value to 'merge' with the existing value
|
|
34
|
+
* @returns {"success" | "error"} The 'merged' value.
|
|
35
|
+
*/
|
|
36
|
+
function _mergeStatus(left, right) {
|
|
37
|
+
if (left === "error" || right === "error") {
|
|
38
|
+
return "error";
|
|
39
|
+
}
|
|
40
|
+
return "success";
|
|
41
|
+
}
|
|
42
|
+
exports._mergeStatus = _mergeStatus;
|
|
28
43
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
29
44
|
function stringifyWithDepthLimit(obj, depthLimit) {
|
|
30
45
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
package/dist/messages/base.d.ts
CHANGED
|
@@ -90,6 +90,15 @@ export type BaseMessageFields = {
|
|
|
90
90
|
id?: string;
|
|
91
91
|
};
|
|
92
92
|
export declare function mergeContent(firstContent: MessageContent, secondContent: MessageContent): MessageContent;
|
|
93
|
+
/**
|
|
94
|
+
* 'Merge' two statuses. If either value passed is 'error', it will return 'error'. Else
|
|
95
|
+
* it will return 'success'.
|
|
96
|
+
*
|
|
97
|
+
* @param {"success" | "error" | undefined} left The existing value to 'merge' with the new value.
|
|
98
|
+
* @param {"success" | "error" | undefined} right The new value to 'merge' with the existing value
|
|
99
|
+
* @returns {"success" | "error"} The 'merged' value.
|
|
100
|
+
*/
|
|
101
|
+
export declare function _mergeStatus(left?: "success" | "error", right?: "success" | "error"): "success" | "error" | undefined;
|
|
93
102
|
/**
|
|
94
103
|
* Base class for all types of messages in a conversation. It includes
|
|
95
104
|
* properties like `content`, `name`, and `additional_kwargs`. It also
|
package/dist/messages/base.js
CHANGED
|
@@ -21,6 +21,20 @@ export function mergeContent(firstContent, secondContent) {
|
|
|
21
21
|
return [...firstContent, { type: "text", text: secondContent }];
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* 'Merge' two statuses. If either value passed is 'error', it will return 'error'. Else
|
|
26
|
+
* it will return 'success'.
|
|
27
|
+
*
|
|
28
|
+
* @param {"success" | "error" | undefined} left The existing value to 'merge' with the new value.
|
|
29
|
+
* @param {"success" | "error" | undefined} right The new value to 'merge' with the existing value
|
|
30
|
+
* @returns {"success" | "error"} The 'merged' value.
|
|
31
|
+
*/
|
|
32
|
+
export function _mergeStatus(left, right) {
|
|
33
|
+
if (left === "error" || right === "error") {
|
|
34
|
+
return "error";
|
|
35
|
+
}
|
|
36
|
+
return "success";
|
|
37
|
+
}
|
|
24
38
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
25
39
|
function stringifyWithDepthLimit(obj, depthLimit) {
|
|
26
40
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
package/dist/messages/tool.cjs
CHANGED
|
@@ -19,6 +19,16 @@ class ToolMessage extends base_js_1.BaseMessage {
|
|
|
19
19
|
fields = { content: fields, name, tool_call_id: tool_call_id };
|
|
20
20
|
}
|
|
21
21
|
super(fields);
|
|
22
|
+
/**
|
|
23
|
+
* Status of the tool invocation.
|
|
24
|
+
* @version 0.2.19
|
|
25
|
+
*/
|
|
26
|
+
Object.defineProperty(this, "status", {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
configurable: true,
|
|
29
|
+
writable: true,
|
|
30
|
+
value: void 0
|
|
31
|
+
});
|
|
22
32
|
Object.defineProperty(this, "tool_call_id", {
|
|
23
33
|
enumerable: true,
|
|
24
34
|
configurable: true,
|
|
@@ -41,6 +51,7 @@ class ToolMessage extends base_js_1.BaseMessage {
|
|
|
41
51
|
});
|
|
42
52
|
this.tool_call_id = fields.tool_call_id;
|
|
43
53
|
this.artifact = fields.artifact;
|
|
54
|
+
this.status = fields.status;
|
|
44
55
|
}
|
|
45
56
|
_getType() {
|
|
46
57
|
return "tool";
|
|
@@ -70,6 +81,16 @@ class ToolMessageChunk extends base_js_1.BaseMessageChunk {
|
|
|
70
81
|
writable: true,
|
|
71
82
|
value: void 0
|
|
72
83
|
});
|
|
84
|
+
/**
|
|
85
|
+
* Status of the tool invocation.
|
|
86
|
+
* @version 0.2.19
|
|
87
|
+
*/
|
|
88
|
+
Object.defineProperty(this, "status", {
|
|
89
|
+
enumerable: true,
|
|
90
|
+
configurable: true,
|
|
91
|
+
writable: true,
|
|
92
|
+
value: void 0
|
|
93
|
+
});
|
|
73
94
|
/**
|
|
74
95
|
* Artifact of the Tool execution which is not meant to be sent to the model.
|
|
75
96
|
*
|
|
@@ -86,6 +107,7 @@ class ToolMessageChunk extends base_js_1.BaseMessageChunk {
|
|
|
86
107
|
});
|
|
87
108
|
this.tool_call_id = fields.tool_call_id;
|
|
88
109
|
this.artifact = fields.artifact;
|
|
110
|
+
this.status = fields.status;
|
|
89
111
|
}
|
|
90
112
|
static lc_name() {
|
|
91
113
|
return "ToolMessageChunk";
|
|
@@ -101,6 +123,7 @@ class ToolMessageChunk extends base_js_1.BaseMessageChunk {
|
|
|
101
123
|
artifact: (0, base_js_1._mergeObj)(this.artifact, chunk.artifact),
|
|
102
124
|
tool_call_id: this.tool_call_id,
|
|
103
125
|
id: this.id ?? chunk.id,
|
|
126
|
+
status: (0, base_js_1._mergeStatus)(this.status, chunk.status),
|
|
104
127
|
});
|
|
105
128
|
}
|
|
106
129
|
get _printableFields() {
|
package/dist/messages/tool.d.ts
CHANGED
|
@@ -9,6 +9,11 @@ export interface ToolMessageFieldsWithToolCallId extends BaseMessageFields {
|
|
|
9
9
|
*/
|
|
10
10
|
artifact?: any;
|
|
11
11
|
tool_call_id: string;
|
|
12
|
+
/**
|
|
13
|
+
* Status of the tool invocation.
|
|
14
|
+
* @version 0.2.19
|
|
15
|
+
*/
|
|
16
|
+
status?: "success" | "error";
|
|
12
17
|
}
|
|
13
18
|
/**
|
|
14
19
|
* Represents a tool message in a conversation.
|
|
@@ -16,6 +21,11 @@ export interface ToolMessageFieldsWithToolCallId extends BaseMessageFields {
|
|
|
16
21
|
export declare class ToolMessage extends BaseMessage {
|
|
17
22
|
static lc_name(): string;
|
|
18
23
|
get lc_aliases(): Record<string, string>;
|
|
24
|
+
/**
|
|
25
|
+
* Status of the tool invocation.
|
|
26
|
+
* @version 0.2.19
|
|
27
|
+
*/
|
|
28
|
+
status?: "success" | "error";
|
|
19
29
|
tool_call_id: string;
|
|
20
30
|
/**
|
|
21
31
|
* Artifact of the Tool execution which is not meant to be sent to the model.
|
|
@@ -37,6 +47,11 @@ export declare class ToolMessage extends BaseMessage {
|
|
|
37
47
|
*/
|
|
38
48
|
export declare class ToolMessageChunk extends BaseMessageChunk {
|
|
39
49
|
tool_call_id: string;
|
|
50
|
+
/**
|
|
51
|
+
* Status of the tool invocation.
|
|
52
|
+
* @version 0.2.19
|
|
53
|
+
*/
|
|
54
|
+
status?: "success" | "error";
|
|
40
55
|
/**
|
|
41
56
|
* Artifact of the Tool execution which is not meant to be sent to the model.
|
|
42
57
|
*
|
package/dist/messages/tool.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseMessage, BaseMessageChunk, mergeContent, _mergeDicts, _mergeObj, } from "./base.js";
|
|
1
|
+
import { BaseMessage, BaseMessageChunk, mergeContent, _mergeDicts, _mergeObj, _mergeStatus, } from "./base.js";
|
|
2
2
|
/**
|
|
3
3
|
* Represents a tool message in a conversation.
|
|
4
4
|
*/
|
|
@@ -16,6 +16,16 @@ export class ToolMessage extends BaseMessage {
|
|
|
16
16
|
fields = { content: fields, name, tool_call_id: tool_call_id };
|
|
17
17
|
}
|
|
18
18
|
super(fields);
|
|
19
|
+
/**
|
|
20
|
+
* Status of the tool invocation.
|
|
21
|
+
* @version 0.2.19
|
|
22
|
+
*/
|
|
23
|
+
Object.defineProperty(this, "status", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
writable: true,
|
|
27
|
+
value: void 0
|
|
28
|
+
});
|
|
19
29
|
Object.defineProperty(this, "tool_call_id", {
|
|
20
30
|
enumerable: true,
|
|
21
31
|
configurable: true,
|
|
@@ -38,6 +48,7 @@ export class ToolMessage extends BaseMessage {
|
|
|
38
48
|
});
|
|
39
49
|
this.tool_call_id = fields.tool_call_id;
|
|
40
50
|
this.artifact = fields.artifact;
|
|
51
|
+
this.status = fields.status;
|
|
41
52
|
}
|
|
42
53
|
_getType() {
|
|
43
54
|
return "tool";
|
|
@@ -66,6 +77,16 @@ export class ToolMessageChunk extends BaseMessageChunk {
|
|
|
66
77
|
writable: true,
|
|
67
78
|
value: void 0
|
|
68
79
|
});
|
|
80
|
+
/**
|
|
81
|
+
* Status of the tool invocation.
|
|
82
|
+
* @version 0.2.19
|
|
83
|
+
*/
|
|
84
|
+
Object.defineProperty(this, "status", {
|
|
85
|
+
enumerable: true,
|
|
86
|
+
configurable: true,
|
|
87
|
+
writable: true,
|
|
88
|
+
value: void 0
|
|
89
|
+
});
|
|
69
90
|
/**
|
|
70
91
|
* Artifact of the Tool execution which is not meant to be sent to the model.
|
|
71
92
|
*
|
|
@@ -82,6 +103,7 @@ export class ToolMessageChunk extends BaseMessageChunk {
|
|
|
82
103
|
});
|
|
83
104
|
this.tool_call_id = fields.tool_call_id;
|
|
84
105
|
this.artifact = fields.artifact;
|
|
106
|
+
this.status = fields.status;
|
|
85
107
|
}
|
|
86
108
|
static lc_name() {
|
|
87
109
|
return "ToolMessageChunk";
|
|
@@ -97,6 +119,7 @@ export class ToolMessageChunk extends BaseMessageChunk {
|
|
|
97
119
|
artifact: _mergeObj(this.artifact, chunk.artifact),
|
|
98
120
|
tool_call_id: this.tool_call_id,
|
|
99
121
|
id: this.id ?? chunk.id,
|
|
122
|
+
status: _mergeStatus(this.status, chunk.status),
|
|
100
123
|
});
|
|
101
124
|
}
|
|
102
125
|
get _printableFields() {
|
package/dist/messages/utils.cjs
CHANGED
|
@@ -121,7 +121,7 @@ function mapStoredMessageToChatMessage(message) {
|
|
|
121
121
|
throw new Error("Tool call ID must be defined for tool messages");
|
|
122
122
|
}
|
|
123
123
|
return new tool_js_1.ToolMessage(storedMessage.data);
|
|
124
|
-
case "
|
|
124
|
+
case "generic": {
|
|
125
125
|
if (storedMessage.data.role === undefined) {
|
|
126
126
|
throw new Error("Role must be defined for chat messages");
|
|
127
127
|
}
|
package/dist/messages/utils.js
CHANGED
|
@@ -116,7 +116,7 @@ export function mapStoredMessageToChatMessage(message) {
|
|
|
116
116
|
throw new Error("Tool call ID must be defined for tool messages");
|
|
117
117
|
}
|
|
118
118
|
return new ToolMessage(storedMessage.data);
|
|
119
|
-
case "
|
|
119
|
+
case "generic": {
|
|
120
120
|
if (storedMessage.data.role === undefined) {
|
|
121
121
|
throw new Error("Role must be defined for chat messages");
|
|
122
122
|
}
|
|
@@ -62,6 +62,7 @@ class StringOutputParser extends transform_js_1.BaseTransformOutputParser {
|
|
|
62
62
|
_messageContentComplexToString(content) {
|
|
63
63
|
switch (content.type) {
|
|
64
64
|
case "text":
|
|
65
|
+
case "text_delta":
|
|
65
66
|
if ("text" in content) {
|
|
66
67
|
// Type guard for MessageContentText
|
|
67
68
|
return this._textContentToString(content);
|
|
@@ -59,6 +59,7 @@ export class StringOutputParser extends BaseTransformOutputParser {
|
|
|
59
59
|
_messageContentComplexToString(content) {
|
|
60
60
|
switch (content.type) {
|
|
61
61
|
case "text":
|
|
62
|
+
case "text_delta":
|
|
62
63
|
if ("text" in content) {
|
|
63
64
|
// Type guard for MessageContentText
|
|
64
65
|
return this._textContentToString(content);
|
package/dist/runnables/base.cjs
CHANGED
|
@@ -12,6 +12,7 @@ const log_stream_js_1 = require("../tracers/log_stream.cjs");
|
|
|
12
12
|
const event_stream_js_1 = require("../tracers/event_stream.cjs");
|
|
13
13
|
const serializable_js_1 = require("../load/serializable.cjs");
|
|
14
14
|
const stream_js_1 = require("../utils/stream.cjs");
|
|
15
|
+
const signal_js_1 = require("../utils/signal.cjs");
|
|
15
16
|
const config_js_1 = require("./config.cjs");
|
|
16
17
|
const async_caller_js_1 = require("../utils/async_caller.cjs");
|
|
17
18
|
const root_listener_js_1 = require("../tracers/root_listener.cjs");
|
|
@@ -194,6 +195,8 @@ class Runnable extends serializable_js_1.Serializable {
|
|
|
194
195
|
recursionLimit: options.recursionLimit,
|
|
195
196
|
maxConcurrency: options.maxConcurrency,
|
|
196
197
|
runId: options.runId,
|
|
198
|
+
timeout: options.timeout,
|
|
199
|
+
signal: options.signal,
|
|
197
200
|
});
|
|
198
201
|
}
|
|
199
202
|
const callOptions = { ...options };
|
|
@@ -205,6 +208,8 @@ class Runnable extends serializable_js_1.Serializable {
|
|
|
205
208
|
delete callOptions.recursionLimit;
|
|
206
209
|
delete callOptions.maxConcurrency;
|
|
207
210
|
delete callOptions.runId;
|
|
211
|
+
delete callOptions.timeout;
|
|
212
|
+
delete callOptions.signal;
|
|
208
213
|
return [runnableConfig, callOptions];
|
|
209
214
|
}
|
|
210
215
|
async _callWithConfig(func, input, options) {
|
|
@@ -214,7 +219,8 @@ class Runnable extends serializable_js_1.Serializable {
|
|
|
214
219
|
delete config.runId;
|
|
215
220
|
let output;
|
|
216
221
|
try {
|
|
217
|
-
|
|
222
|
+
const promise = func.call(this, input, config, runManager);
|
|
223
|
+
output = await (0, signal_js_1.raceWithSignal)(promise, options?.signal);
|
|
218
224
|
}
|
|
219
225
|
catch (e) {
|
|
220
226
|
await runManager?.handleChainError(e);
|
|
@@ -242,7 +248,8 @@ class Runnable extends serializable_js_1.Serializable {
|
|
|
242
248
|
}));
|
|
243
249
|
let outputs;
|
|
244
250
|
try {
|
|
245
|
-
|
|
251
|
+
const promise = func.call(this, inputs, optionsList, runManagers, batchOptions);
|
|
252
|
+
outputs = await (0, signal_js_1.raceWithSignal)(promise, optionsList?.[0]?.signal);
|
|
246
253
|
}
|
|
247
254
|
catch (e) {
|
|
248
255
|
await Promise.all(runManagers.map((runManager) => runManager?.handleChainError(e)));
|
|
@@ -285,7 +292,7 @@ class Runnable extends serializable_js_1.Serializable {
|
|
|
285
292
|
}
|
|
286
293
|
let runManager;
|
|
287
294
|
try {
|
|
288
|
-
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);
|
|
295
|
+
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()), options?.signal, config);
|
|
289
296
|
delete config.runId;
|
|
290
297
|
runManager = pipe.setup;
|
|
291
298
|
const streamEventsHandler = runManager?.handlers.find(event_stream_js_1.isStreamEventsHandler);
|
|
@@ -834,9 +841,7 @@ class RunnableBinding extends Runnable {
|
|
|
834
841
|
async stream(input, options) {
|
|
835
842
|
return this.bound.stream(input, await this._mergeConfig((0, config_js_1.ensureConfig)(options), this.kwargs));
|
|
836
843
|
}
|
|
837
|
-
async *transform(
|
|
838
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
839
|
-
generator, options) {
|
|
844
|
+
async *transform(generator, options) {
|
|
840
845
|
yield* this.bound.transform(generator, await this._mergeConfig((0, config_js_1.ensureConfig)(options), this.kwargs));
|
|
841
846
|
}
|
|
842
847
|
streamEvents(input, options, streamOptions) {
|
|
@@ -1143,11 +1148,15 @@ class RunnableSequence extends Runnable {
|
|
|
1143
1148
|
const initialSteps = [this.first, ...this.middle];
|
|
1144
1149
|
for (let i = 0; i < initialSteps.length; i += 1) {
|
|
1145
1150
|
const step = initialSteps[i];
|
|
1146
|
-
|
|
1151
|
+
const promise = step.invoke(nextStepInput, (0, config_js_1.patchConfig)(config, {
|
|
1147
1152
|
callbacks: runManager?.getChild(`seq:step:${i + 1}`),
|
|
1148
1153
|
}));
|
|
1154
|
+
nextStepInput = await (0, signal_js_1.raceWithSignal)(promise, options?.signal);
|
|
1149
1155
|
}
|
|
1150
1156
|
// TypeScript can't detect that the last output of the sequence returns RunOutput, so call it out of the loop here
|
|
1157
|
+
if (options?.signal?.aborted) {
|
|
1158
|
+
throw new Error("Aborted");
|
|
1159
|
+
}
|
|
1151
1160
|
finalOutput = await this.last.invoke(nextStepInput, (0, config_js_1.patchConfig)(config, {
|
|
1152
1161
|
callbacks: runManager?.getChild(`seq:step:${this.steps.length}`),
|
|
1153
1162
|
}));
|
|
@@ -1172,10 +1181,11 @@ class RunnableSequence extends Runnable {
|
|
|
1172
1181
|
try {
|
|
1173
1182
|
for (let i = 0; i < this.steps.length; i += 1) {
|
|
1174
1183
|
const step = this.steps[i];
|
|
1175
|
-
|
|
1184
|
+
const promise = step.batch(nextStepInputs, runManagers.map((runManager, j) => {
|
|
1176
1185
|
const childRunManager = runManager?.getChild(`seq:step:${i + 1}`);
|
|
1177
1186
|
return (0, config_js_1.patchConfig)(configList[j], { callbacks: childRunManager });
|
|
1178
1187
|
}), batchOptions);
|
|
1188
|
+
nextStepInputs = await (0, signal_js_1.raceWithSignal)(promise, configList[0]?.signal);
|
|
1179
1189
|
}
|
|
1180
1190
|
}
|
|
1181
1191
|
catch (e) {
|
|
@@ -1206,6 +1216,7 @@ class RunnableSequence extends Runnable {
|
|
|
1206
1216
|
}));
|
|
1207
1217
|
}
|
|
1208
1218
|
for await (const chunk of finalGenerator) {
|
|
1219
|
+
options?.signal?.throwIfAborted();
|
|
1209
1220
|
yield chunk;
|
|
1210
1221
|
if (concatSupported) {
|
|
1211
1222
|
if (finalOutput === undefined) {
|
|
@@ -1352,11 +1363,12 @@ class RunnableMap extends Runnable {
|
|
|
1352
1363
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1353
1364
|
const output = {};
|
|
1354
1365
|
try {
|
|
1355
|
-
|
|
1366
|
+
const promises = Object.entries(this.steps).map(async ([key, runnable]) => {
|
|
1356
1367
|
output[key] = await runnable.invoke(input, (0, config_js_1.patchConfig)(config, {
|
|
1357
1368
|
callbacks: runManager?.getChild(`map:key:${key}`),
|
|
1358
1369
|
}));
|
|
1359
|
-
})
|
|
1370
|
+
});
|
|
1371
|
+
await (0, signal_js_1.raceWithSignal)(Promise.all(promises), options?.signal);
|
|
1360
1372
|
}
|
|
1361
1373
|
catch (e) {
|
|
1362
1374
|
await runManager?.handleChainError(e);
|
|
@@ -1381,7 +1393,8 @@ class RunnableMap extends Runnable {
|
|
|
1381
1393
|
// starting new iterations as needed,
|
|
1382
1394
|
// until all iterators are done
|
|
1383
1395
|
while (tasks.size) {
|
|
1384
|
-
const
|
|
1396
|
+
const promise = Promise.race(tasks.values());
|
|
1397
|
+
const { key, result, gen } = await (0, signal_js_1.raceWithSignal)(promise, options?.signal);
|
|
1385
1398
|
tasks.delete(key);
|
|
1386
1399
|
if (!result.done) {
|
|
1387
1400
|
yield { [key]: result.value };
|
|
@@ -1438,18 +1451,22 @@ class RunnableTraceable extends Runnable {
|
|
|
1438
1451
|
async invoke(input, options) {
|
|
1439
1452
|
const [config] = this._getOptionsList(options ?? {}, 1);
|
|
1440
1453
|
const callbacks = await (0, config_js_1.getCallbackManagerForConfig)(config);
|
|
1441
|
-
|
|
1454
|
+
const promise = this.func((0, config_js_1.patchConfig)(config, { callbacks }), input);
|
|
1455
|
+
return (0, signal_js_1.raceWithSignal)(promise, config?.signal);
|
|
1442
1456
|
}
|
|
1443
1457
|
async *_streamIterator(input, options) {
|
|
1458
|
+
const [config] = this._getOptionsList(options ?? {}, 1);
|
|
1444
1459
|
const result = await this.invoke(input, options);
|
|
1445
1460
|
if ((0, iter_js_1.isAsyncIterable)(result)) {
|
|
1446
1461
|
for await (const item of result) {
|
|
1462
|
+
config?.signal?.throwIfAborted();
|
|
1447
1463
|
yield item;
|
|
1448
1464
|
}
|
|
1449
1465
|
return;
|
|
1450
1466
|
}
|
|
1451
1467
|
if ((0, iter_js_1.isIterator)(result)) {
|
|
1452
1468
|
while (true) {
|
|
1469
|
+
config?.signal?.throwIfAborted();
|
|
1453
1470
|
const state = result.next();
|
|
1454
1471
|
if (state.done)
|
|
1455
1472
|
break;
|
|
@@ -1526,6 +1543,7 @@ class RunnableLambda extends Runnable {
|
|
|
1526
1543
|
else if ((0, iter_js_1.isAsyncIterable)(output)) {
|
|
1527
1544
|
let finalOutput;
|
|
1528
1545
|
for await (const chunk of (0, iter_js_1.consumeAsyncIterableInContext)(childConfig, output)) {
|
|
1546
|
+
config?.signal?.throwIfAborted();
|
|
1529
1547
|
if (finalOutput === undefined) {
|
|
1530
1548
|
finalOutput = chunk;
|
|
1531
1549
|
}
|
|
@@ -1545,6 +1563,7 @@ class RunnableLambda extends Runnable {
|
|
|
1545
1563
|
else if ((0, iter_js_1.isIterableIterator)(output)) {
|
|
1546
1564
|
let finalOutput;
|
|
1547
1565
|
for (const chunk of (0, iter_js_1.consumeIteratorInContext)(childConfig, output)) {
|
|
1566
|
+
config?.signal?.throwIfAborted();
|
|
1548
1567
|
if (finalOutput === undefined) {
|
|
1549
1568
|
finalOutput = chunk;
|
|
1550
1569
|
}
|
|
@@ -1618,11 +1637,13 @@ class RunnableLambda extends Runnable {
|
|
|
1618
1637
|
}
|
|
1619
1638
|
else if ((0, iter_js_1.isAsyncIterable)(output)) {
|
|
1620
1639
|
for await (const chunk of (0, iter_js_1.consumeAsyncIterableInContext)(childConfig, output)) {
|
|
1640
|
+
config?.signal?.throwIfAborted();
|
|
1621
1641
|
yield chunk;
|
|
1622
1642
|
}
|
|
1623
1643
|
}
|
|
1624
1644
|
else if ((0, iter_js_1.isIterableIterator)(output)) {
|
|
1625
1645
|
for (const chunk of (0, iter_js_1.consumeIteratorInContext)(childConfig, output)) {
|
|
1646
|
+
config?.signal?.throwIfAborted();
|
|
1626
1647
|
yield chunk;
|
|
1627
1648
|
}
|
|
1628
1649
|
}
|
|
@@ -1699,6 +1720,7 @@ class RunnableWithFallbacks extends Runnable {
|
|
|
1699
1720
|
const runManager = await callbackManager_?.handleChainStart(this.toJSON(), _coerceToDict(input, "input"), runId, undefined, undefined, undefined, otherConfigFields?.runName);
|
|
1700
1721
|
let firstError;
|
|
1701
1722
|
for (const runnable of this.runnables()) {
|
|
1723
|
+
config?.signal?.throwIfAborted();
|
|
1702
1724
|
try {
|
|
1703
1725
|
const output = await runnable.invoke(input, (0, config_js_1.patchConfig)(otherConfigFields, { callbacks: runManager?.getChild() }));
|
|
1704
1726
|
await runManager?.handleChainEnd(_coerceToDict(output, "output"));
|
|
@@ -1730,6 +1752,7 @@ class RunnableWithFallbacks extends Runnable {
|
|
|
1730
1752
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1731
1753
|
let firstError;
|
|
1732
1754
|
for (const runnable of this.runnables()) {
|
|
1755
|
+
configList[0].signal?.throwIfAborted();
|
|
1733
1756
|
try {
|
|
1734
1757
|
const outputs = await runnable.batch(inputs, runManagers.map((runManager, j) => (0, config_js_1.patchConfig)(configList[j], {
|
|
1735
1758
|
callbacks: runManager?.getChild(),
|