@librechat/agents 3.8.5 → 3.8.7
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/agents/AgentContext.cjs +1 -1
- package/dist/cjs/common/constants.cjs +2 -0
- package/dist/cjs/common/constants.cjs.map +1 -1
- package/dist/cjs/graphs/Graph.cjs +18 -9
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/hitl/approvalReview.cjs +1 -1
- package/dist/cjs/hooks/types.cjs.map +1 -1
- package/dist/cjs/main.cjs +8 -6
- package/dist/cjs/messages/index.cjs +1 -1
- package/dist/cjs/messages/prune.cjs +1 -1
- package/dist/cjs/run.cjs +7 -3
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/stream.cjs +13 -3
- package/dist/cjs/stream.cjs.map +1 -1
- package/dist/cjs/summarization/node.cjs +3 -1
- package/dist/cjs/summarization/node.cjs.map +1 -1
- package/dist/cjs/tools/BashExecutor.cjs +79 -27
- package/dist/cjs/tools/BashExecutor.cjs.map +1 -1
- package/dist/cjs/tools/BashProgrammaticToolCalling.cjs +47 -7
- package/dist/cjs/tools/BashProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/CodeExecutor.cjs +5 -2
- package/dist/cjs/tools/CodeExecutor.cjs.map +1 -1
- package/dist/cjs/tools/CodeSessionFileSummary.cjs +11 -1
- package/dist/cjs/tools/CodeSessionFileSummary.cjs.map +1 -1
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs +54 -8
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/ToolNode.cjs +176 -43
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/tools/local/LocalProgrammaticToolCalling.cjs +1 -0
- package/dist/cjs/tools/local/LocalProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/subagent/SubagentExecutionRegistry.cjs +0 -1
- package/dist/cjs/tools/subagent/SubagentExecutionRegistry.cjs.map +1 -1
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs +120 -26
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs.map +1 -1
- package/dist/cjs/tools/toolBatchReplay.cjs +4 -2
- package/dist/cjs/tools/toolBatchReplay.cjs.map +1 -1
- package/dist/cjs/utils/index.cjs +1 -1
- package/dist/esm/agents/AgentContext.mjs +1 -1
- package/dist/esm/common/constants.mjs +2 -1
- package/dist/esm/common/constants.mjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +17 -8
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/hitl/approvalReview.mjs +1 -1
- package/dist/esm/hooks/types.mjs.map +1 -1
- package/dist/esm/main.mjs +7 -7
- package/dist/esm/messages/index.mjs +1 -1
- package/dist/esm/messages/prune.mjs +1 -1
- package/dist/esm/run.mjs +7 -3
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/stream.mjs +13 -3
- package/dist/esm/stream.mjs.map +1 -1
- package/dist/esm/summarization/node.mjs +3 -1
- package/dist/esm/summarization/node.mjs.map +1 -1
- package/dist/esm/tools/BashExecutor.mjs +81 -29
- package/dist/esm/tools/BashExecutor.mjs.map +1 -1
- package/dist/esm/tools/BashProgrammaticToolCalling.mjs +48 -9
- package/dist/esm/tools/BashProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/CodeExecutor.mjs +5 -2
- package/dist/esm/tools/CodeExecutor.mjs.map +1 -1
- package/dist/esm/tools/CodeSessionFileSummary.mjs +11 -2
- package/dist/esm/tools/CodeSessionFileSummary.mjs.map +1 -1
- package/dist/esm/tools/ProgrammaticToolCalling.mjs +55 -9
- package/dist/esm/tools/ProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/ToolNode.mjs +176 -43
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/local/LocalProgrammaticToolCalling.mjs +1 -0
- package/dist/esm/tools/local/LocalProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/subagent/SubagentExecutionRegistry.mjs +0 -1
- package/dist/esm/tools/subagent/SubagentExecutionRegistry.mjs.map +1 -1
- package/dist/esm/tools/subagent/SubagentExecutor.mjs +120 -26
- package/dist/esm/tools/subagent/SubagentExecutor.mjs.map +1 -1
- package/dist/esm/tools/toolBatchReplay.mjs +4 -2
- package/dist/esm/tools/toolBatchReplay.mjs.map +1 -1
- package/dist/esm/utils/index.mjs +1 -1
- package/dist/types/common/constants.d.ts +2 -0
- package/dist/types/graphs/Graph.d.ts +3 -2
- package/dist/types/hooks/types.d.ts +3 -0
- package/dist/types/run.d.ts +1 -0
- package/dist/types/summarization/node.d.ts +1 -0
- package/dist/types/tools/BashExecutor.d.ts +2 -0
- package/dist/types/tools/BashProgrammaticToolCalling.d.ts +1 -0
- package/dist/types/tools/CodeExecutor.d.ts +1 -1
- package/dist/types/tools/CodeSessionFileSummary.d.ts +3 -0
- package/dist/types/tools/ProgrammaticToolCalling.d.ts +2 -2
- package/dist/types/tools/ToolNode.d.ts +6 -2
- package/dist/types/tools/subagent/SubagentExecutor.d.ts +7 -4
- package/dist/types/tools/toolBatchReplay.d.ts +2 -0
- package/dist/types/types/graph.d.ts +28 -0
- package/dist/types/types/run.d.ts +2 -0
- package/dist/types/types/tools.d.ts +27 -3
- package/package.json +2 -2
- package/src/common/constants.ts +3 -0
- package/src/graphs/Graph.ts +32 -18
- package/src/hooks/types.ts +3 -0
- package/src/run.ts +30 -15
- package/src/stream.ts +27 -5
- package/src/summarization/node.ts +3 -0
- package/src/tools/BashExecutor.ts +143 -40
- package/src/tools/BashProgrammaticToolCalling.ts +82 -10
- package/src/tools/CodeExecutor.ts +12 -2
- package/src/tools/CodeSessionFileSummary.ts +25 -1
- package/src/tools/ProgrammaticToolCalling.ts +77 -6
- package/src/tools/ToolNode.ts +665 -170
- package/src/tools/local/LocalProgrammaticToolCalling.ts +1 -0
- package/src/tools/subagent/SubagentExecutionRegistry.ts +0 -1
- package/src/tools/subagent/SubagentExecutor.ts +214 -55
- package/src/tools/toolBatchReplay.ts +23 -1
- package/src/types/graph.ts +37 -0
- package/src/types/run.ts +2 -0
- package/src/types/tools.ts +30 -3
- package/src/utils/llmConfig.ts +0 -1
|
@@ -15,6 +15,8 @@ const IMAGE_FILE_EXTENSIONS = new Set([
|
|
|
15
15
|
|
|
16
16
|
const CODE_SESSION_FILE_SUMMARY_PATTERN =
|
|
17
17
|
/^Generated files:\nSession files: \d+ persisted file\(s\) are available in \/mnt\/data, including \d+ image\(s\)\. Use known \/mnt\/data paths directly in later code-tool calls\. The app displays files\/images automatically; do not invent download links or wrap generated images in Markdown\.$/;
|
|
18
|
+
const EXECUTION_ARTIFACT_FILE_SUMMARY_PATTERN =
|
|
19
|
+
/^Generated files:\nExecution artifacts: \d+ file\(s\), including \d+ image\(s\), were delivered to the app\. They are not retained in the attached project; write durable files to the project root when later commands must reuse them\. The app displays files\/images automatically; do not invent download links or wrap generated images in Markdown\.$/;
|
|
18
20
|
|
|
19
21
|
function getFileExtension(name: string): string {
|
|
20
22
|
const lastSlash = name.lastIndexOf('/');
|
|
@@ -53,7 +55,12 @@ export function stripCodeSessionFileSummary(output: string): string {
|
|
|
53
55
|
const beforeSummary = output.slice(0, summaryStart);
|
|
54
56
|
if (beforeSummary !== '' && !beforeSummary.endsWith('\n\n')) return output;
|
|
55
57
|
const maybeSummary = output.slice(summaryStart);
|
|
56
|
-
if (
|
|
58
|
+
if (
|
|
59
|
+
!CODE_SESSION_FILE_SUMMARY_PATTERN.test(maybeSummary) &&
|
|
60
|
+
!EXECUTION_ARTIFACT_FILE_SUMMARY_PATTERN.test(maybeSummary)
|
|
61
|
+
) {
|
|
62
|
+
return output;
|
|
63
|
+
}
|
|
57
64
|
return beforeSummary.trimEnd();
|
|
58
65
|
}
|
|
59
66
|
|
|
@@ -78,3 +85,20 @@ export function appendCodeSessionFileSummary(
|
|
|
78
85
|
|
|
79
86
|
return `${output.trimEnd()}\n\n${summary}`.trim();
|
|
80
87
|
}
|
|
88
|
+
|
|
89
|
+
/** Attached-worker artifacts are delivered out of execution-private scratch,
|
|
90
|
+
* not retained in the selected project or a reusable `/mnt/data` session. */
|
|
91
|
+
export function appendExecutionArtifactFileSummary(
|
|
92
|
+
output: string,
|
|
93
|
+
files: t.FileRefs | undefined
|
|
94
|
+
): string {
|
|
95
|
+
const generatedFiles = files?.filter(isGeneratedFile) ?? [];
|
|
96
|
+
if (generatedFiles.length === 0) return output.trim();
|
|
97
|
+
const imageCount = generatedFiles.filter(isImageFile).length;
|
|
98
|
+
const summary =
|
|
99
|
+
'Generated files:\n' +
|
|
100
|
+
`Execution artifacts: ${generatedFiles.length} file(s), including ${imageCount} image(s), were delivered to the app. ` +
|
|
101
|
+
'They are not retained in the attached project; write durable files to the project root when later commands must reuse them. ' +
|
|
102
|
+
'The app displays files/images automatically; do not invent download links or wrap generated images in Markdown.';
|
|
103
|
+
return `${output.trimEnd()}\n\n${summary}`.trim();
|
|
104
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// src/tools/ProgrammaticToolCalling.ts
|
|
2
2
|
import { config } from 'dotenv';
|
|
3
|
+
import { randomUUID } from 'node:crypto';
|
|
3
4
|
import fetch, { RequestInit } from 'node-fetch';
|
|
4
5
|
import { tool, DynamicStructuredTool } from '@langchain/core/tools';
|
|
5
6
|
import type { ToolCall } from '@langchain/core/messages/tool';
|
|
@@ -21,6 +22,7 @@ import {
|
|
|
21
22
|
resolveCodeApiAuthHeaders,
|
|
22
23
|
selectRuntimeSessionHint,
|
|
23
24
|
} from './CodeExecutor';
|
|
25
|
+
import { appendExecutionArtifactFileSummary } from './CodeSessionFileSummary';
|
|
24
26
|
import {
|
|
25
27
|
assertUnambiguousIdentifiers,
|
|
26
28
|
projectProgrammaticToolMap,
|
|
@@ -51,6 +53,9 @@ config();
|
|
|
51
53
|
const DEFAULT_MAX_ROUND_TRIPS = 20;
|
|
52
54
|
|
|
53
55
|
const DEFAULT_RUN_TIMEOUT_MS = resolveCodeApiRunTimeoutMs();
|
|
56
|
+
const CODE_API_PROGRAMMATIC_REQUEST_HEADER =
|
|
57
|
+
'X-LibreChat-Code-Request-ID';
|
|
58
|
+
const CANCELLATION_REQUEST_TIMEOUT_MS = 2_000;
|
|
54
59
|
|
|
55
60
|
// ============================================================================
|
|
56
61
|
// Description Components (Single Source of Truth)
|
|
@@ -513,10 +518,12 @@ export async function makeRequest(
|
|
|
513
518
|
body: Record<string, unknown>,
|
|
514
519
|
proxy?: string,
|
|
515
520
|
authHeaders?: t.CodeApiAuthHeaders,
|
|
516
|
-
executionProfile?: t.CodeApiExecutionProfile
|
|
521
|
+
executionProfile?: t.CodeApiExecutionProfile,
|
|
522
|
+
signal?: AbortSignal
|
|
517
523
|
): Promise<t.ProgrammaticExecutionResponse> {
|
|
518
524
|
try {
|
|
519
525
|
const resolvedAuthHeaders = await resolveCodeApiAuthHeaders(authHeaders);
|
|
526
|
+
const requestId = signal != null ? randomUUID() : undefined;
|
|
520
527
|
const fetchOptions: RequestInit = {
|
|
521
528
|
method: 'POST',
|
|
522
529
|
headers: {
|
|
@@ -526,8 +533,12 @@ export async function makeRequest(
|
|
|
526
533
|
resolvedAuthHeaders,
|
|
527
534
|
executionProfile
|
|
528
535
|
),
|
|
536
|
+
...(requestId != null
|
|
537
|
+
? { [CODE_API_PROGRAMMATIC_REQUEST_HEADER]: requestId }
|
|
538
|
+
: {}),
|
|
529
539
|
},
|
|
530
540
|
body: JSON.stringify(body),
|
|
541
|
+
signal: signal as RequestInit['signal'],
|
|
531
542
|
};
|
|
532
543
|
|
|
533
544
|
const proxyAgent = resolveFetchProxyAgent(endpoint, proxy);
|
|
@@ -535,7 +546,59 @@ export async function makeRequest(
|
|
|
535
546
|
fetchOptions.agent = proxyAgent;
|
|
536
547
|
}
|
|
537
548
|
|
|
538
|
-
|
|
549
|
+
let cancellationRequest: Promise<void> | undefined;
|
|
550
|
+
const requestCancellation = (): void => {
|
|
551
|
+
if (requestId == null || cancellationRequest != null) {
|
|
552
|
+
return;
|
|
553
|
+
}
|
|
554
|
+
cancellationRequest = (async (): Promise<void> => {
|
|
555
|
+
const cancellationController = new AbortController();
|
|
556
|
+
const timeout = setTimeout(
|
|
557
|
+
() => cancellationController.abort(),
|
|
558
|
+
CANCELLATION_REQUEST_TIMEOUT_MS
|
|
559
|
+
);
|
|
560
|
+
try {
|
|
561
|
+
const cancelOptions: RequestInit = {
|
|
562
|
+
method: 'POST',
|
|
563
|
+
headers: {
|
|
564
|
+
'Content-Type': 'application/json',
|
|
565
|
+
'User-Agent': 'LibreChat/1.0',
|
|
566
|
+
...addCodeApiExecutionProfileHeader(
|
|
567
|
+
resolvedAuthHeaders,
|
|
568
|
+
executionProfile
|
|
569
|
+
),
|
|
570
|
+
},
|
|
571
|
+
body: JSON.stringify({ request_id: requestId }),
|
|
572
|
+
signal: cancellationController.signal as RequestInit['signal'],
|
|
573
|
+
};
|
|
574
|
+
if (proxyAgent != null) {
|
|
575
|
+
cancelOptions.agent = proxyAgent;
|
|
576
|
+
}
|
|
577
|
+
await fetch(`${endpoint}/cancel`, cancelOptions);
|
|
578
|
+
} catch {
|
|
579
|
+
// Cancellation is best effort for older Code API versions and
|
|
580
|
+
// transient network failures. The original abort remains the public
|
|
581
|
+
// result while the server-side execution deadline is the fallback.
|
|
582
|
+
} finally {
|
|
583
|
+
clearTimeout(timeout);
|
|
584
|
+
}
|
|
585
|
+
})();
|
|
586
|
+
};
|
|
587
|
+
signal?.addEventListener('abort', requestCancellation, { once: true });
|
|
588
|
+
if (signal?.aborted === true) requestCancellation();
|
|
589
|
+
|
|
590
|
+
let response;
|
|
591
|
+
try {
|
|
592
|
+
response = await fetch(endpoint, fetchOptions);
|
|
593
|
+
} catch (error) {
|
|
594
|
+
if (signal?.aborted === true) {
|
|
595
|
+
requestCancellation();
|
|
596
|
+
await cancellationRequest;
|
|
597
|
+
}
|
|
598
|
+
throw error;
|
|
599
|
+
} finally {
|
|
600
|
+
signal?.removeEventListener('abort', requestCancellation);
|
|
601
|
+
}
|
|
539
602
|
|
|
540
603
|
if (!response.ok) {
|
|
541
604
|
throw new CodeApiRequestError(
|
|
@@ -860,7 +923,8 @@ export async function executeTools(
|
|
|
860
923
|
*/
|
|
861
924
|
export function formatCompletedResponse(
|
|
862
925
|
response: t.ProgrammaticExecutionResponse,
|
|
863
|
-
sourceCode = ''
|
|
926
|
+
sourceCode = '',
|
|
927
|
+
filePersistence: 'session' | 'execution' = 'session'
|
|
864
928
|
): [string, t.ProgrammaticExecutionArtifact] {
|
|
865
929
|
let formatted = '';
|
|
866
930
|
|
|
@@ -884,10 +948,15 @@ export function formatCompletedResponse(
|
|
|
884
948
|
);
|
|
885
949
|
|
|
886
950
|
return [
|
|
887
|
-
|
|
951
|
+
filePersistence === 'execution'
|
|
952
|
+
? appendExecutionArtifactFileSummary(outputWithDeliveryWarning, response.files)
|
|
953
|
+
: appendCodeSessionFileSummary(outputWithDeliveryWarning, response.files),
|
|
888
954
|
{
|
|
889
955
|
session_id: response.session_id,
|
|
890
956
|
files: response.files,
|
|
957
|
+
...(response.deleted_files != null
|
|
958
|
+
? { deleted_files: response.deleted_files }
|
|
959
|
+
: {}),
|
|
891
960
|
...(artifactDelivery != null
|
|
892
961
|
? { artifact_delivery: artifactDelivery }
|
|
893
962
|
: {}),
|
|
@@ -1161,7 +1230,8 @@ export function createProgrammaticToolCallingTool(
|
|
|
1161
1230
|
},
|
|
1162
1231
|
proxy,
|
|
1163
1232
|
initParams.authHeaders,
|
|
1164
|
-
initParams.executionProfile
|
|
1233
|
+
initParams.executionProfile,
|
|
1234
|
+
config.signal
|
|
1165
1235
|
);
|
|
1166
1236
|
|
|
1167
1237
|
// ====================================================================
|
|
@@ -1199,7 +1269,8 @@ export function createProgrammaticToolCallingTool(
|
|
|
1199
1269
|
},
|
|
1200
1270
|
proxy,
|
|
1201
1271
|
initParams.authHeaders,
|
|
1202
|
-
initParams.executionProfile
|
|
1272
|
+
initParams.executionProfile,
|
|
1273
|
+
config.signal
|
|
1203
1274
|
);
|
|
1204
1275
|
}
|
|
1205
1276
|
|