@librechat/agents 3.1.70 → 3.1.71-dev.0

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.
Files changed (54) hide show
  1. package/dist/cjs/graphs/Graph.cjs +45 -0
  2. package/dist/cjs/graphs/Graph.cjs.map +1 -1
  3. package/dist/cjs/main.cjs +4 -0
  4. package/dist/cjs/main.cjs.map +1 -1
  5. package/dist/cjs/messages/prune.cjs +9 -2
  6. package/dist/cjs/messages/prune.cjs.map +1 -1
  7. package/dist/cjs/run.cjs +4 -0
  8. package/dist/cjs/run.cjs.map +1 -1
  9. package/dist/cjs/tools/BashExecutor.cjs +43 -0
  10. package/dist/cjs/tools/BashExecutor.cjs.map +1 -1
  11. package/dist/cjs/tools/ToolNode.cjs +453 -45
  12. package/dist/cjs/tools/ToolNode.cjs.map +1 -1
  13. package/dist/cjs/tools/toolOutputReferences.cjs +475 -0
  14. package/dist/cjs/tools/toolOutputReferences.cjs.map +1 -0
  15. package/dist/cjs/utils/truncation.cjs +28 -0
  16. package/dist/cjs/utils/truncation.cjs.map +1 -1
  17. package/dist/esm/graphs/Graph.mjs +45 -0
  18. package/dist/esm/graphs/Graph.mjs.map +1 -1
  19. package/dist/esm/main.mjs +2 -2
  20. package/dist/esm/messages/prune.mjs +9 -2
  21. package/dist/esm/messages/prune.mjs.map +1 -1
  22. package/dist/esm/run.mjs +4 -0
  23. package/dist/esm/run.mjs.map +1 -1
  24. package/dist/esm/tools/BashExecutor.mjs +42 -1
  25. package/dist/esm/tools/BashExecutor.mjs.map +1 -1
  26. package/dist/esm/tools/ToolNode.mjs +453 -45
  27. package/dist/esm/tools/ToolNode.mjs.map +1 -1
  28. package/dist/esm/tools/toolOutputReferences.mjs +468 -0
  29. package/dist/esm/tools/toolOutputReferences.mjs.map +1 -0
  30. package/dist/esm/utils/truncation.mjs +27 -1
  31. package/dist/esm/utils/truncation.mjs.map +1 -1
  32. package/dist/types/graphs/Graph.d.ts +21 -0
  33. package/dist/types/run.d.ts +1 -0
  34. package/dist/types/tools/BashExecutor.d.ts +31 -0
  35. package/dist/types/tools/ToolNode.d.ts +86 -3
  36. package/dist/types/tools/toolOutputReferences.d.ts +205 -0
  37. package/dist/types/types/run.d.ts +9 -1
  38. package/dist/types/types/tools.d.ts +70 -0
  39. package/dist/types/utils/truncation.d.ts +21 -0
  40. package/package.json +1 -1
  41. package/src/graphs/Graph.ts +48 -0
  42. package/src/messages/prune.ts +9 -2
  43. package/src/run.ts +4 -0
  44. package/src/specs/prune.test.ts +413 -0
  45. package/src/tools/BashExecutor.ts +45 -0
  46. package/src/tools/ToolNode.ts +618 -55
  47. package/src/tools/__tests__/BashExecutor.test.ts +36 -0
  48. package/src/tools/__tests__/ToolNode.outputReferences.test.ts +1395 -0
  49. package/src/tools/__tests__/toolOutputReferences.test.ts +415 -0
  50. package/src/tools/toolOutputReferences.ts +590 -0
  51. package/src/types/run.ts +9 -1
  52. package/src/types/tools.ts +71 -0
  53. package/src/utils/__tests__/truncation.test.ts +66 -0
  54. package/src/utils/truncation.ts +30 -0
@@ -0,0 +1,66 @@
1
+ import { describe, it, expect } from '@jest/globals';
2
+ import {
3
+ HARD_MAX_TOOL_RESULT_CHARS,
4
+ HARD_MAX_TOTAL_TOOL_OUTPUT_SIZE,
5
+ calculateMaxToolResultChars,
6
+ calculateMaxTotalToolOutputSize,
7
+ } from '@/utils/truncation';
8
+
9
+ describe('truncation helpers', () => {
10
+ describe('calculateMaxToolResultChars', () => {
11
+ it('returns the hard cap when context tokens are missing', () => {
12
+ expect(calculateMaxToolResultChars()).toBe(HARD_MAX_TOOL_RESULT_CHARS);
13
+ expect(calculateMaxToolResultChars(undefined)).toBe(
14
+ HARD_MAX_TOOL_RESULT_CHARS
15
+ );
16
+ expect(calculateMaxToolResultChars(0)).toBe(HARD_MAX_TOOL_RESULT_CHARS);
17
+ expect(calculateMaxToolResultChars(-100)).toBe(
18
+ HARD_MAX_TOOL_RESULT_CHARS
19
+ );
20
+ });
21
+
22
+ it('computes 30% of context-window characters for normal inputs', () => {
23
+ // 100k tokens * 0.3 = 30k tokens * 4 chars/token = 120k chars
24
+ expect(calculateMaxToolResultChars(100_000)).toBe(120_000);
25
+ });
26
+
27
+ it('clamps to the hard cap for large context windows', () => {
28
+ // 1M tokens * 0.3 * 4 = 1.2M chars, exceeds 400k cap
29
+ expect(calculateMaxToolResultChars(1_000_000)).toBe(
30
+ HARD_MAX_TOOL_RESULT_CHARS
31
+ );
32
+ });
33
+ });
34
+
35
+ describe('calculateMaxTotalToolOutputSize', () => {
36
+ it('returns the absolute hard cap when no per-output is provided', () => {
37
+ expect(calculateMaxTotalToolOutputSize()).toBe(
38
+ HARD_MAX_TOTAL_TOOL_OUTPUT_SIZE
39
+ );
40
+ expect(calculateMaxTotalToolOutputSize(0)).toBe(
41
+ HARD_MAX_TOTAL_TOOL_OUTPUT_SIZE
42
+ );
43
+ expect(calculateMaxTotalToolOutputSize(-1)).toBe(
44
+ HARD_MAX_TOTAL_TOOL_OUTPUT_SIZE
45
+ );
46
+ });
47
+
48
+ it('doubles the per-output cap by default', () => {
49
+ expect(calculateMaxTotalToolOutputSize(100_000)).toBe(200_000);
50
+ expect(calculateMaxTotalToolOutputSize(1)).toBe(2);
51
+ });
52
+
53
+ it('clamps the doubled value to HARD_MAX_TOTAL_TOOL_OUTPUT_SIZE', () => {
54
+ // 4M * 2 = 8M, exceeds 5M
55
+ expect(calculateMaxTotalToolOutputSize(4_000_000)).toBe(
56
+ HARD_MAX_TOTAL_TOOL_OUTPUT_SIZE
57
+ );
58
+ // Right at the boundary: 2.5M * 2 = 5M (no clamp).
59
+ expect(calculateMaxTotalToolOutputSize(2_500_000)).toBe(5_000_000);
60
+ // Just past it: 2_500_001 * 2 = 5_000_002 -> clamped.
61
+ expect(calculateMaxTotalToolOutputSize(2_500_001)).toBe(
62
+ HARD_MAX_TOTAL_TOOL_OUTPUT_SIZE
63
+ );
64
+ });
65
+ });
66
+ });
@@ -12,6 +12,16 @@
12
12
  */
13
13
  export const HARD_MAX_TOOL_RESULT_CHARS = 400_000;
14
14
 
15
+ /**
16
+ * Absolute hard cap on the aggregate size (characters) of all registered
17
+ * tool outputs kept for `{{tool<i>turn<n>}}` substitution. Set at 5 MB
18
+ * because the registry stores *raw, untruncated* tool output — full
19
+ * fidelity for piping into downstream bash/jq — so the budget needs
20
+ * enough headroom to keep a handful of large responses without
21
+ * ballooning unbounded.
22
+ */
23
+ export const HARD_MAX_TOTAL_TOOL_OUTPUT_SIZE = 5_000_000;
24
+
15
25
  /**
16
26
  * Computes the dynamic max tool result size based on the model's context window.
17
27
  * Uses 30% of the context window (in estimated characters, ~4 chars/token)
@@ -32,6 +42,26 @@ export function calculateMaxToolResultChars(
32
42
  );
33
43
  }
34
44
 
45
+ /**
46
+ * Computes the default aggregate size (characters) for the tool output
47
+ * reference registry based on the per-output budget. Mirrors
48
+ * `calculateMaxToolResultChars`'s shape: a multiple of the per-output
49
+ * cap, clamped to `HARD_MAX_TOTAL_TOOL_OUTPUT_SIZE`.
50
+ *
51
+ * @param maxOutputSize - Per-output maximum characters (e.g., the
52
+ * ToolNode's `maxToolResultChars`). When omitted or non-positive,
53
+ * falls back to the absolute total cap.
54
+ * @returns Maximum total characters retained across the registry.
55
+ */
56
+ export function calculateMaxTotalToolOutputSize(
57
+ maxOutputSize?: number
58
+ ): number {
59
+ if (maxOutputSize == null || maxOutputSize <= 0) {
60
+ return HARD_MAX_TOTAL_TOOL_OUTPUT_SIZE;
61
+ }
62
+ return Math.min(maxOutputSize * 2, HARD_MAX_TOTAL_TOOL_OUTPUT_SIZE);
63
+ }
64
+
35
65
  /**
36
66
  * Truncates a tool-call input (the arguments/payload of a tool_use block)
37
67
  * using head+tail strategy. Returns an object with `_truncated` (the