@librechat/agents 3.8.1 → 3.8.2
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/cjs/graphs/Graph.cjs +2 -2
- package/dist/cjs/graphs/MultiAgentGraph.cjs +1 -1
- package/dist/cjs/hitl/approvalReview.cjs +89 -0
- package/dist/cjs/hitl/approvalReview.cjs.map +1 -0
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs +1 -1
- package/dist/cjs/main.cjs +3 -3
- package/dist/cjs/messages/core.cjs +1 -1
- package/dist/cjs/messages/format.cjs +1 -1
- package/dist/cjs/messages/prune.cjs +2 -2
- package/dist/cjs/run.cjs +17 -6
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/session/AgentSession.cjs +1 -1
- package/dist/cjs/stream.cjs +2 -2
- package/dist/cjs/summarization/node.cjs +1 -1
- package/dist/cjs/tools/ToolNode.cjs +256 -84
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs +24 -9
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs.map +1 -1
- package/dist/cjs/tools/subagent/SubagentReplay.cjs +2 -0
- package/dist/cjs/tools/subagent/SubagentReplay.cjs.map +1 -1
- package/dist/cjs/tools/toolBatchReplay.cjs +187 -0
- package/dist/cjs/tools/toolBatchReplay.cjs.map +1 -0
- package/dist/cjs/tools/toolOutputReferences.cjs +12 -0
- package/dist/cjs/tools/toolOutputReferences.cjs.map +1 -1
- package/dist/cjs/types/hitl.cjs +4 -0
- package/dist/cjs/types/hitl.cjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +2 -2
- package/dist/esm/graphs/MultiAgentGraph.mjs +1 -1
- package/dist/esm/hitl/approvalReview.mjs +83 -0
- package/dist/esm/hitl/approvalReview.mjs.map +1 -0
- package/dist/esm/llm/anthropic/utils/message_inputs.mjs +1 -1
- package/dist/esm/main.mjs +3 -3
- package/dist/esm/messages/core.mjs +1 -1
- package/dist/esm/messages/format.mjs +1 -1
- package/dist/esm/messages/prune.mjs +2 -2
- package/dist/esm/run.mjs +18 -7
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/session/AgentSession.mjs +1 -1
- package/dist/esm/stream.mjs +2 -2
- package/dist/esm/summarization/node.mjs +1 -1
- package/dist/esm/tools/ToolNode.mjs +256 -84
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/subagent/SubagentExecutor.mjs +24 -9
- package/dist/esm/tools/subagent/SubagentExecutor.mjs.map +1 -1
- package/dist/esm/tools/subagent/SubagentReplay.mjs +1 -1
- package/dist/esm/tools/subagent/SubagentReplay.mjs.map +1 -1
- package/dist/esm/tools/toolBatchReplay.mjs +176 -0
- package/dist/esm/tools/toolBatchReplay.mjs.map +1 -0
- package/dist/esm/tools/toolOutputReferences.mjs +12 -0
- package/dist/esm/tools/toolOutputReferences.mjs.map +1 -1
- package/dist/esm/types/hitl.mjs +4 -1
- package/dist/esm/types/hitl.mjs.map +1 -1
- package/dist/types/hitl/approvalReview.d.ts +32 -0
- package/dist/types/tools/ToolNode.d.ts +12 -6
- package/dist/types/tools/subagent/SubagentReplay.d.ts +2 -0
- package/dist/types/tools/toolBatchReplay.d.ts +54 -0
- package/dist/types/tools/toolOutputReferences.d.ts +2 -0
- package/package.json +1 -1
- package/src/hitl/approvalReview.ts +209 -0
- package/src/run.ts +34 -20
- package/src/tools/ToolNode.ts +518 -184
- package/src/tools/subagent/SubagentExecutor.ts +35 -6
- package/src/tools/subagent/SubagentReplay.ts +2 -2
- package/src/tools/toolBatchReplay.ts +395 -0
- package/src/tools/toolOutputReferences.ts +16 -0
package/src/run.ts
CHANGED
|
@@ -22,7 +22,6 @@ import type {
|
|
|
22
22
|
} from '@langchain/core/messages';
|
|
23
23
|
import type { StringPromptValue } from '@langchain/core/prompt_values';
|
|
24
24
|
import type { RunnableConfig } from '@langchain/core/runnables';
|
|
25
|
-
import { isFadingTier } from '@/messages/fading';
|
|
26
25
|
import type { AggregatedHookResult, HookRegistry } from '@/hooks';
|
|
27
26
|
import type { MultiAgentGraph } from '@/graphs/MultiAgentGraph';
|
|
28
27
|
import type { StandardGraph } from '@/graphs/Graph';
|
|
@@ -40,7 +39,6 @@ import {
|
|
|
40
39
|
} from '@/common';
|
|
41
40
|
import {
|
|
42
41
|
requireValidSubagentResumeManifest,
|
|
43
|
-
stripSubagentResumeManifest,
|
|
44
42
|
SUBAGENT_RESUME_ATTEMPT_CONFIG_KEY,
|
|
45
43
|
SUBAGENT_RESUME_MANIFEST_CONFIG_KEY,
|
|
46
44
|
} from '@/tools/subagent/SubagentReplay';
|
|
@@ -70,6 +68,16 @@ import {
|
|
|
70
68
|
resolveLangfuseConfig,
|
|
71
69
|
resolveToolOutputTracingConfig,
|
|
72
70
|
} from '@/langfuseConfig';
|
|
71
|
+
import {
|
|
72
|
+
cloneToolApprovalInterruptPayload,
|
|
73
|
+
TOOL_APPROVAL_REVIEW_CONFIG_KEY,
|
|
74
|
+
} from '@/hitl/approvalReview';
|
|
75
|
+
import {
|
|
76
|
+
TOOL_BATCH_REPLAY_KEY,
|
|
77
|
+
restoreToolReplayConfig,
|
|
78
|
+
stripToolBatchReplayState,
|
|
79
|
+
getPublicToolInterruptPayload,
|
|
80
|
+
} from '@/tools/toolBatchReplay';
|
|
73
81
|
import {
|
|
74
82
|
resolveLangfuseDestinationKey,
|
|
75
83
|
resolveLangfuseTraceAnchorParent,
|
|
@@ -104,6 +112,7 @@ import { seedRunInitialSessions } from '@/utils/toolSessions';
|
|
|
104
112
|
import { getTraceIdSeed } from '@/langfuseRuntimeContext';
|
|
105
113
|
import { resolveClientOptionsModel } from '@/llm/request';
|
|
106
114
|
import { createGraph } from '@/graphs/createGraph';
|
|
115
|
+
import { isFadingTier } from '@/messages/fading';
|
|
107
116
|
import { resolveMaxSeals } from '@/llm/preempt';
|
|
108
117
|
import { isBuiltRuntime } from '@/lazyRequire';
|
|
109
118
|
import { initializeModel } from '@/llm/init';
|
|
@@ -169,9 +178,7 @@ function materializeStopContinuation(
|
|
|
169
178
|
return messages;
|
|
170
179
|
}
|
|
171
180
|
|
|
172
|
-
function advanceCheckpointCursor(
|
|
173
|
-
config: t.RunStreamConfig
|
|
174
|
-
): t.RunStreamConfig {
|
|
181
|
+
function advanceCheckpointCursor(config: t.RunStreamConfig): t.RunStreamConfig {
|
|
175
182
|
const configurable = { ...config.configurable };
|
|
176
183
|
delete configurable.checkpoint_id;
|
|
177
184
|
delete configurable.checkpoint_map;
|
|
@@ -186,9 +193,7 @@ function assertFinalAdmissionSucceeded(result: AggregatedHookResult): void {
|
|
|
186
193
|
result.errors.length > 0
|
|
187
194
|
? result.errors.join('; ')
|
|
188
195
|
: 'one or more internal finalizers failed';
|
|
189
|
-
throw new Error(
|
|
190
|
-
`StopFinalize terminal admission failed: ${detail}`
|
|
191
|
-
);
|
|
196
|
+
throw new Error(`StopFinalize terminal admission failed: ${detail}`);
|
|
192
197
|
}
|
|
193
198
|
|
|
194
199
|
const CUSTOM_GRAPH_EVENTS = new Set<string>([
|
|
@@ -268,9 +273,7 @@ function isLangGraphResumeMapForInterrupt(
|
|
|
268
273
|
}
|
|
269
274
|
|
|
270
275
|
function getInterruptHookSessionId(payload: unknown): string | undefined {
|
|
271
|
-
const publicPayload =
|
|
272
|
-
stripRunStepResumeState(payload)
|
|
273
|
-
);
|
|
276
|
+
const publicPayload = getPublicToolInterruptPayload(payload);
|
|
274
277
|
if (
|
|
275
278
|
publicPayload == null ||
|
|
276
279
|
typeof publicPayload !== 'object' ||
|
|
@@ -423,7 +426,7 @@ function overwriteResumeRunStepState(
|
|
|
423
426
|
const update = Array.isArray(command.update)
|
|
424
427
|
? [
|
|
425
428
|
...command.update.filter(([key]) => key !== 'runStepState'),
|
|
426
|
-
|
|
429
|
+
['runStepState', overwrite] as [string, unknown],
|
|
427
430
|
]
|
|
428
431
|
: { ...(command.update ?? {}), runStepState: overwrite };
|
|
429
432
|
const resumed = new Command({
|
|
@@ -1266,6 +1269,8 @@ export class Run<_T extends t.BaseGraphState> {
|
|
|
1266
1269
|
recursionLimit,
|
|
1267
1270
|
configurable: { ...callerConfig.configurable },
|
|
1268
1271
|
};
|
|
1272
|
+
delete config.configurable?.[TOOL_APPROVAL_REVIEW_CONFIG_KEY];
|
|
1273
|
+
delete config.configurable?.[TOOL_BATCH_REPLAY_KEY];
|
|
1269
1274
|
if (!isResume) {
|
|
1270
1275
|
delete config.configurable?.[SUBAGENT_RESUME_ATTEMPT_CONFIG_KEY];
|
|
1271
1276
|
delete config.configurable?.[SUBAGENT_RESUME_MANIFEST_CONFIG_KEY];
|
|
@@ -1276,6 +1281,10 @@ export class Run<_T extends t.BaseGraphState> {
|
|
|
1276
1281
|
config,
|
|
1277
1282
|
(inputs as Command).update
|
|
1278
1283
|
);
|
|
1284
|
+
const publicPayload = stripRunStepResumeState(this._interrupt?.payload);
|
|
1285
|
+
if (config.configurable != null) {
|
|
1286
|
+
restoreToolReplayConfig(config.configurable, this._interrupt?.interruptId, publicPayload);
|
|
1287
|
+
}
|
|
1279
1288
|
if (graph.getStopContinuationExecutionId() === '') {
|
|
1280
1289
|
graph.startStopContinuationExecution(nanoid());
|
|
1281
1290
|
overwriteLegacyResumeState = this.hasCheckpointer;
|
|
@@ -1514,7 +1523,7 @@ export class Run<_T extends t.BaseGraphState> {
|
|
|
1514
1523
|
this._interrupt = {
|
|
1515
1524
|
interruptId: first.id ?? '',
|
|
1516
1525
|
threadId,
|
|
1517
|
-
payload: first.value,
|
|
1526
|
+
payload: cloneToolApprovalInterruptPayload(first.value),
|
|
1518
1527
|
};
|
|
1519
1528
|
}
|
|
1520
1529
|
}
|
|
@@ -1558,7 +1567,8 @@ export class Run<_T extends t.BaseGraphState> {
|
|
|
1558
1567
|
stopReason = OUTPUT_TRUNCATED_HALT_REASON;
|
|
1559
1568
|
}
|
|
1560
1569
|
|
|
1561
|
-
const stopMessages =
|
|
1570
|
+
const stopMessages =
|
|
1571
|
+
graph.getRunMessages() ?? stateInputs?.messages ?? [];
|
|
1562
1572
|
const stopContinuationCount = graph.getStopContinuationCount();
|
|
1563
1573
|
const continuationBudgetRemaining = Math.max(
|
|
1564
1574
|
0,
|
|
@@ -1881,8 +1891,8 @@ export class Run<_T extends t.BaseGraphState> {
|
|
|
1881
1891
|
}
|
|
1882
1892
|
return {
|
|
1883
1893
|
...this._interrupt,
|
|
1884
|
-
payload:
|
|
1885
|
-
|
|
1894
|
+
payload: cloneToolApprovalInterruptPayload(
|
|
1895
|
+
getPublicToolInterruptPayload(this._interrupt.payload)
|
|
1886
1896
|
),
|
|
1887
1897
|
} as t.RunInterruptResult<TPayload>;
|
|
1888
1898
|
}
|
|
@@ -2004,16 +2014,20 @@ export class Run<_T extends t.BaseGraphState> {
|
|
|
2004
2014
|
): Promise<t.RunStreamConfig> {
|
|
2005
2015
|
await this.restoreInterruptFromCheckpoint(callerConfig, resumeUpdate);
|
|
2006
2016
|
const interrupt = this._interrupt;
|
|
2007
|
-
const
|
|
2008
|
-
|
|
2009
|
-
|
|
2017
|
+
const replayPayload = stripRunStepResumeState(interrupt?.payload);
|
|
2018
|
+
const resumeManifest = requireValidSubagentResumeManifest(replayPayload) ??
|
|
2019
|
+
requireValidSubagentResumeManifest(stripToolBatchReplayState(replayPayload));
|
|
2010
2020
|
const resumeConfigurable = { ...callerConfig.configurable };
|
|
2021
|
+
delete resumeConfigurable[TOOL_APPROVAL_REVIEW_CONFIG_KEY];
|
|
2022
|
+
delete resumeConfigurable[TOOL_BATCH_REPLAY_KEY];
|
|
2011
2023
|
delete resumeConfigurable[SUBAGENT_RESUME_ATTEMPT_CONFIG_KEY];
|
|
2012
2024
|
delete resumeConfigurable[SUBAGENT_RESUME_MANIFEST_CONFIG_KEY];
|
|
2013
2025
|
resumeConfigurable[SUBAGENT_RESUME_ATTEMPT_CONFIG_KEY] = nanoid();
|
|
2014
2026
|
if (resumeManifest != null) {
|
|
2015
2027
|
resumeConfigurable[SUBAGENT_RESUME_MANIFEST_CONFIG_KEY] = resumeManifest;
|
|
2016
2028
|
}
|
|
2029
|
+
const publicPayload = stripRunStepResumeState(interrupt?.payload);
|
|
2030
|
+
restoreToolReplayConfig(resumeConfigurable, interrupt?.interruptId, publicPayload);
|
|
2017
2031
|
const manifestConfig = {
|
|
2018
2032
|
...callerConfig,
|
|
2019
2033
|
configurable: resumeConfigurable,
|
|
@@ -2130,7 +2144,7 @@ export class Run<_T extends t.BaseGraphState> {
|
|
|
2130
2144
|
const threadId = callerConfig.configurable?.thread_id;
|
|
2131
2145
|
this._interrupt = {
|
|
2132
2146
|
interruptId: persistedInterrupt.id,
|
|
2133
|
-
payload: persistedInterrupt.value,
|
|
2147
|
+
payload: cloneToolApprovalInterruptPayload(persistedInterrupt.value),
|
|
2134
2148
|
...(typeof threadId === 'string' ? { threadId } : {}),
|
|
2135
2149
|
...(typeof checkpointId === 'string' ? { checkpointId } : {}),
|
|
2136
2150
|
...(typeof checkpointNs === 'string' ? { checkpointNs } : {}),
|