@librechat/agents 3.1.77-dev.1 → 3.1.78-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.
- package/dist/cjs/common/enum.cjs +54 -0
- package/dist/cjs/common/enum.cjs.map +1 -1
- package/dist/cjs/graphs/Graph.cjs +148 -4
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/hooks/createWorkspacePolicyHook.cjs +291 -0
- package/dist/cjs/hooks/createWorkspacePolicyHook.cjs.map +1 -0
- package/dist/cjs/llm/openai/index.cjs +317 -1
- package/dist/cjs/llm/openai/index.cjs.map +1 -1
- package/dist/cjs/main.cjs +90 -0
- package/dist/cjs/main.cjs.map +1 -1
- package/dist/cjs/messages/anthropicToolCache.cjs +102 -0
- package/dist/cjs/messages/anthropicToolCache.cjs.map +1 -0
- package/dist/cjs/messages/prune.cjs +27 -0
- package/dist/cjs/messages/prune.cjs.map +1 -1
- package/dist/cjs/messages/recency.cjs +99 -0
- package/dist/cjs/messages/recency.cjs.map +1 -0
- package/dist/cjs/run.cjs +30 -0
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/summarization/node.cjs +100 -6
- package/dist/cjs/summarization/node.cjs.map +1 -1
- package/dist/cjs/tools/ToolNode.cjs +635 -23
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/tools/local/CompileCheckTool.cjs +227 -0
- package/dist/cjs/tools/local/CompileCheckTool.cjs.map +1 -0
- package/dist/cjs/tools/local/FileCheckpointer.cjs +90 -0
- package/dist/cjs/tools/local/FileCheckpointer.cjs.map +1 -0
- package/dist/cjs/tools/local/LocalCodingTools.cjs +1098 -0
- package/dist/cjs/tools/local/LocalCodingTools.cjs.map +1 -0
- package/dist/cjs/tools/local/LocalExecutionEngine.cjs +1042 -0
- package/dist/cjs/tools/local/LocalExecutionEngine.cjs.map +1 -0
- package/dist/cjs/tools/local/LocalExecutionTools.cjs +122 -0
- package/dist/cjs/tools/local/LocalExecutionTools.cjs.map +1 -0
- package/dist/cjs/tools/local/LocalProgrammaticToolCalling.cjs +453 -0
- package/dist/cjs/tools/local/LocalProgrammaticToolCalling.cjs.map +1 -0
- package/dist/cjs/tools/local/attachments.cjs +183 -0
- package/dist/cjs/tools/local/attachments.cjs.map +1 -0
- package/dist/cjs/tools/local/bashAst.cjs +129 -0
- package/dist/cjs/tools/local/bashAst.cjs.map +1 -0
- package/dist/cjs/tools/local/editStrategies.cjs +188 -0
- package/dist/cjs/tools/local/editStrategies.cjs.map +1 -0
- package/dist/cjs/tools/local/resolveLocalExecutionTools.cjs +141 -0
- package/dist/cjs/tools/local/resolveLocalExecutionTools.cjs.map +1 -0
- package/dist/cjs/tools/local/syntaxCheck.cjs +182 -0
- package/dist/cjs/tools/local/syntaxCheck.cjs.map +1 -0
- package/dist/cjs/tools/local/textEncoding.cjs +30 -0
- package/dist/cjs/tools/local/textEncoding.cjs.map +1 -0
- package/dist/cjs/tools/local/workspaceFS.cjs +51 -0
- package/dist/cjs/tools/local/workspaceFS.cjs.map +1 -0
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs +1 -0
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs.map +1 -1
- package/dist/esm/common/enum.mjs +53 -1
- package/dist/esm/common/enum.mjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +149 -5
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/hooks/createWorkspacePolicyHook.mjs +289 -0
- package/dist/esm/hooks/createWorkspacePolicyHook.mjs.map +1 -0
- package/dist/esm/llm/openai/index.mjs +318 -2
- package/dist/esm/llm/openai/index.mjs.map +1 -1
- package/dist/esm/main.mjs +17 -2
- package/dist/esm/main.mjs.map +1 -1
- package/dist/esm/messages/anthropicToolCache.mjs +99 -0
- package/dist/esm/messages/anthropicToolCache.mjs.map +1 -0
- package/dist/esm/messages/prune.mjs +26 -1
- package/dist/esm/messages/prune.mjs.map +1 -1
- package/dist/esm/messages/recency.mjs +97 -0
- package/dist/esm/messages/recency.mjs.map +1 -0
- package/dist/esm/run.mjs +30 -0
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/summarization/node.mjs +100 -6
- package/dist/esm/summarization/node.mjs.map +1 -1
- package/dist/esm/tools/ToolNode.mjs +635 -23
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/local/CompileCheckTool.mjs +223 -0
- package/dist/esm/tools/local/CompileCheckTool.mjs.map +1 -0
- package/dist/esm/tools/local/FileCheckpointer.mjs +87 -0
- package/dist/esm/tools/local/FileCheckpointer.mjs.map +1 -0
- package/dist/esm/tools/local/LocalCodingTools.mjs +1075 -0
- package/dist/esm/tools/local/LocalCodingTools.mjs.map +1 -0
- package/dist/esm/tools/local/LocalExecutionEngine.mjs +1022 -0
- package/dist/esm/tools/local/LocalExecutionEngine.mjs.map +1 -0
- package/dist/esm/tools/local/LocalExecutionTools.mjs +117 -0
- package/dist/esm/tools/local/LocalExecutionTools.mjs.map +1 -0
- package/dist/esm/tools/local/LocalProgrammaticToolCalling.mjs +448 -0
- package/dist/esm/tools/local/LocalProgrammaticToolCalling.mjs.map +1 -0
- package/dist/esm/tools/local/attachments.mjs +180 -0
- package/dist/esm/tools/local/attachments.mjs.map +1 -0
- package/dist/esm/tools/local/bashAst.mjs +126 -0
- package/dist/esm/tools/local/bashAst.mjs.map +1 -0
- package/dist/esm/tools/local/editStrategies.mjs +185 -0
- package/dist/esm/tools/local/editStrategies.mjs.map +1 -0
- package/dist/esm/tools/local/resolveLocalExecutionTools.mjs +137 -0
- package/dist/esm/tools/local/resolveLocalExecutionTools.mjs.map +1 -0
- package/dist/esm/tools/local/syntaxCheck.mjs +179 -0
- package/dist/esm/tools/local/syntaxCheck.mjs.map +1 -0
- package/dist/esm/tools/local/textEncoding.mjs +27 -0
- package/dist/esm/tools/local/textEncoding.mjs.map +1 -0
- package/dist/esm/tools/local/workspaceFS.mjs +49 -0
- package/dist/esm/tools/local/workspaceFS.mjs.map +1 -0
- package/dist/esm/tools/subagent/SubagentExecutor.mjs +1 -0
- package/dist/esm/tools/subagent/SubagentExecutor.mjs.map +1 -1
- package/dist/types/common/enum.d.ts +39 -1
- package/dist/types/graphs/Graph.d.ts +34 -0
- package/dist/types/hooks/createWorkspacePolicyHook.d.ts +95 -0
- package/dist/types/hooks/index.d.ts +2 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/llm/openai/index.d.ts +17 -0
- package/dist/types/messages/anthropicToolCache.d.ts +51 -0
- package/dist/types/messages/index.d.ts +2 -0
- package/dist/types/messages/prune.d.ts +11 -0
- package/dist/types/messages/recency.d.ts +64 -0
- package/dist/types/run.d.ts +21 -0
- package/dist/types/tools/ToolNode.d.ts +145 -2
- package/dist/types/tools/local/CompileCheckTool.d.ts +31 -0
- package/dist/types/tools/local/FileCheckpointer.d.ts +39 -0
- package/dist/types/tools/local/LocalCodingTools.d.ts +57 -0
- package/dist/types/tools/local/LocalExecutionEngine.d.ts +149 -0
- package/dist/types/tools/local/LocalExecutionTools.d.ts +9 -0
- package/dist/types/tools/local/LocalProgrammaticToolCalling.d.ts +21 -0
- package/dist/types/tools/local/attachments.d.ts +84 -0
- package/dist/types/tools/local/bashAst.d.ts +11 -0
- package/dist/types/tools/local/editStrategies.d.ts +28 -0
- package/dist/types/tools/local/index.d.ts +12 -0
- package/dist/types/tools/local/resolveLocalExecutionTools.d.ts +38 -0
- package/dist/types/tools/local/syntaxCheck.d.ts +42 -0
- package/dist/types/tools/local/textEncoding.d.ts +21 -0
- package/dist/types/tools/local/workspaceFS.d.ts +49 -0
- package/dist/types/types/hitl.d.ts +56 -27
- package/dist/types/types/run.d.ts +8 -1
- package/dist/types/types/summarize.d.ts +30 -0
- package/dist/types/types/tools.d.ts +341 -6
- package/package.json +21 -2
- package/src/common/enum.ts +54 -0
- package/src/graphs/Graph.ts +164 -6
- package/src/hooks/__tests__/compactHooks.test.ts +38 -2
- package/src/hooks/__tests__/createWorkspacePolicyHook.test.ts +393 -0
- package/src/hooks/createWorkspacePolicyHook.ts +355 -0
- package/src/hooks/index.ts +6 -0
- package/src/index.ts +1 -0
- package/src/llm/openai/deepseek.test.ts +479 -0
- package/src/llm/openai/index.ts +484 -1
- package/src/messages/__tests__/anthropicToolCache.test.ts +125 -0
- package/src/messages/__tests__/recency.test.ts +267 -0
- package/src/messages/anthropicToolCache.ts +116 -0
- package/src/messages/index.ts +2 -0
- package/src/messages/prune.ts +27 -1
- package/src/messages/recency.ts +155 -0
- package/src/run.ts +31 -0
- package/src/scripts/compare_pi_vs_ours.ts +840 -0
- package/src/scripts/local_engine.ts +166 -0
- package/src/scripts/local_engine_checkpointer.ts +205 -0
- package/src/scripts/local_engine_compile.ts +263 -0
- package/src/scripts/local_engine_hooks.ts +226 -0
- package/src/scripts/local_engine_image.ts +201 -0
- package/src/scripts/local_engine_ptc.ts +151 -0
- package/src/scripts/local_engine_workspace.ts +258 -0
- package/src/scripts/summarization-recency.ts +462 -0
- package/src/specs/prune.test.ts +39 -0
- package/src/summarization/__tests__/node.test.ts +499 -3
- package/src/summarization/node.ts +124 -7
- package/src/tools/ToolNode.ts +769 -20
- package/src/tools/__tests__/LocalExecutionTools.test.ts +2647 -0
- package/src/tools/__tests__/ProgrammaticToolCalling.test.ts +175 -0
- package/src/tools/__tests__/ToolNode.outputReferences.test.ts +114 -0
- package/src/tools/__tests__/ToolNode.session.test.ts +84 -0
- package/src/tools/__tests__/directToolHITLResumeScope.test.ts +467 -0
- package/src/tools/__tests__/directToolHooks.test.ts +411 -0
- package/src/tools/__tests__/localToolNames.test.ts +73 -0
- package/src/tools/__tests__/workspaceSeam.test.ts +134 -0
- package/src/tools/local/CompileCheckTool.ts +278 -0
- package/src/tools/local/FileCheckpointer.ts +93 -0
- package/src/tools/local/LocalCodingTools.ts +1342 -0
- package/src/tools/local/LocalExecutionEngine.ts +1329 -0
- package/src/tools/local/LocalExecutionTools.ts +167 -0
- package/src/tools/local/LocalProgrammaticToolCalling.ts +594 -0
- package/src/tools/local/__tests__/FileCheckpointer.test.ts +120 -0
- package/src/tools/local/__tests__/editStrategies.test.ts +134 -0
- package/src/tools/local/attachments.ts +251 -0
- package/src/tools/local/bashAst.ts +151 -0
- package/src/tools/local/editStrategies.ts +188 -0
- package/src/tools/local/index.ts +12 -0
- package/src/tools/local/resolveLocalExecutionTools.ts +208 -0
- package/src/tools/local/syntaxCheck.ts +243 -0
- package/src/tools/local/textEncoding.ts +37 -0
- package/src/tools/local/workspaceFS.ts +89 -0
- package/src/types/hitl.ts +56 -27
- package/src/types/run.ts +12 -1
- package/src/types/summarize.ts +31 -0
- package/src/types/tools.ts +359 -7
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Anthropic prompt-caching helper for the `tools[]` request field.
|
|
5
|
+
*
|
|
6
|
+
* Anthropic accepts `cache_control: { type: 'ephemeral' }` on individual
|
|
7
|
+
* tool definitions. Whichever tool carries the marker becomes the end of
|
|
8
|
+
* a cached prefix: `tools[0..N]` (everything up to and including the
|
|
9
|
+
* marked tool) is cached and rebated on subsequent matching requests.
|
|
10
|
+
*
|
|
11
|
+
* For agents that mix static and deferred (lazily-discovered) tools, the
|
|
12
|
+
* winning configuration is:
|
|
13
|
+
*
|
|
14
|
+
* 1. Stable-partition tools so all *static* (non-deferred) tools come
|
|
15
|
+
* first and discovered-deferred tools come last.
|
|
16
|
+
* 2. Stamp `cache_control` on the LAST static tool.
|
|
17
|
+
*
|
|
18
|
+
* That way, the cached prefix covers exactly the static tool inventory.
|
|
19
|
+
* Discovered tools that show up later (or vary turn-to-turn as new ones
|
|
20
|
+
* get discovered) never invalidate the prefix because they sit *after*
|
|
21
|
+
* the breakpoint.
|
|
22
|
+
*
|
|
23
|
+
* LangChain's Anthropic adapter passes the marker through via
|
|
24
|
+
* `tool.extras.cache_control` (`AnthropicToolExtrasSchema`), so we set
|
|
25
|
+
* it as an `extras` field on a fresh wrapper around the tool — never
|
|
26
|
+
* mutating the original tool instance, since callers may share them
|
|
27
|
+
* across runs.
|
|
28
|
+
*/
|
|
29
|
+
/**
|
|
30
|
+
* Returns a callable that reports whether a given tool *name* is deferred
|
|
31
|
+
* according to the supplied registry of tool definitions. Tools without
|
|
32
|
+
* a registry entry are treated as non-deferred (i.e. static), matching
|
|
33
|
+
* the host-supplied `graphTools` semantics elsewhere in the SDK.
|
|
34
|
+
*/
|
|
35
|
+
function makeIsDeferred(toolDefinitions) {
|
|
36
|
+
if (toolDefinitions == null || toolDefinitions.length === 0) {
|
|
37
|
+
return () => false;
|
|
38
|
+
}
|
|
39
|
+
const deferred = new Set();
|
|
40
|
+
for (const def of toolDefinitions) {
|
|
41
|
+
if (def.defer_loading === true)
|
|
42
|
+
deferred.add(def.name);
|
|
43
|
+
}
|
|
44
|
+
if (deferred.size === 0)
|
|
45
|
+
return () => false;
|
|
46
|
+
return (name) => deferred.has(name);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Stable-partition `tools` into [static..., deferred...] and stamp the
|
|
50
|
+
* Anthropic `cache_control: ephemeral` marker on the last static tool.
|
|
51
|
+
*
|
|
52
|
+
* If `tools` is undefined or empty, or no entry has a usable `.name`,
|
|
53
|
+
* returns the input unchanged. If there are no static tools at all,
|
|
54
|
+
* also returns unchanged (nothing to cache).
|
|
55
|
+
*
|
|
56
|
+
* The original tool instances are never mutated. The marked entry is a
|
|
57
|
+
* shallow wrapper that preserves the prototype chain so downstream
|
|
58
|
+
* `instanceof` checks still pass. `extras` is merged so any existing
|
|
59
|
+
* `providerToolDefinition` / other extras the host attached are kept.
|
|
60
|
+
*/
|
|
61
|
+
function partitionAndMarkAnthropicToolCache(tools, isDeferred) {
|
|
62
|
+
if (tools == null || tools.length === 0)
|
|
63
|
+
return tools;
|
|
64
|
+
// Use unknown[] internally to avoid GraphTools' union-array variance
|
|
65
|
+
// (each member is one of three array types). We cast back to
|
|
66
|
+
// GraphTools when returning.
|
|
67
|
+
const staticTools = [];
|
|
68
|
+
const deferredTools = [];
|
|
69
|
+
for (const tool of tools) {
|
|
70
|
+
const name = tool.name;
|
|
71
|
+
if (typeof name === 'string' && isDeferred(name)) {
|
|
72
|
+
deferredTools.push(tool);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
staticTools.push(tool);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (staticTools.length === 0) {
|
|
79
|
+
return tools;
|
|
80
|
+
}
|
|
81
|
+
const last = staticTools[staticTools.length - 1];
|
|
82
|
+
// Already marked? Don't double-clone.
|
|
83
|
+
if (last.extras != null &&
|
|
84
|
+
'cache_control' in last.extras &&
|
|
85
|
+
last.extras.cache_control != null) {
|
|
86
|
+
if (deferredTools.length === 0)
|
|
87
|
+
return tools;
|
|
88
|
+
return [...staticTools, ...deferredTools];
|
|
89
|
+
}
|
|
90
|
+
const wrapped = Object.assign(Object.create(Object.getPrototypeOf(last) ?? Object.prototype), last, {
|
|
91
|
+
extras: {
|
|
92
|
+
...(last.extras ?? {}),
|
|
93
|
+
cache_control: { type: 'ephemeral' },
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
staticTools[staticTools.length - 1] = wrapped;
|
|
97
|
+
return [...staticTools, ...deferredTools];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
exports.makeIsDeferred = makeIsDeferred;
|
|
101
|
+
exports.partitionAndMarkAnthropicToolCache = partitionAndMarkAnthropicToolCache;
|
|
102
|
+
//# sourceMappingURL=anthropicToolCache.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropicToolCache.cjs","sources":["../../../src/messages/anthropicToolCache.ts"],"sourcesContent":["/**\n * Anthropic prompt-caching helper for the `tools[]` request field.\n *\n * Anthropic accepts `cache_control: { type: 'ephemeral' }` on individual\n * tool definitions. Whichever tool carries the marker becomes the end of\n * a cached prefix: `tools[0..N]` (everything up to and including the\n * marked tool) is cached and rebated on subsequent matching requests.\n *\n * For agents that mix static and deferred (lazily-discovered) tools, the\n * winning configuration is:\n *\n * 1. Stable-partition tools so all *static* (non-deferred) tools come\n * first and discovered-deferred tools come last.\n * 2. Stamp `cache_control` on the LAST static tool.\n *\n * That way, the cached prefix covers exactly the static tool inventory.\n * Discovered tools that show up later (or vary turn-to-turn as new ones\n * get discovered) never invalidate the prefix because they sit *after*\n * the breakpoint.\n *\n * LangChain's Anthropic adapter passes the marker through via\n * `tool.extras.cache_control` (`AnthropicToolExtrasSchema`), so we set\n * it as an `extras` field on a fresh wrapper around the tool — never\n * mutating the original tool instance, since callers may share them\n * across runs.\n */\n\nimport type { GraphTools } from '@/types';\n\n/**\n * Returns a callable that reports whether a given tool *name* is deferred\n * according to the supplied registry of tool definitions. Tools without\n * a registry entry are treated as non-deferred (i.e. static), matching\n * the host-supplied `graphTools` semantics elsewhere in the SDK.\n */\nexport function makeIsDeferred(\n toolDefinitions:\n | ReadonlyArray<{ name: string; defer_loading?: boolean }>\n | undefined\n): (toolName: string) => boolean {\n if (toolDefinitions == null || toolDefinitions.length === 0) {\n return () => false;\n }\n const deferred = new Set<string>();\n for (const def of toolDefinitions) {\n if (def.defer_loading === true) deferred.add(def.name);\n }\n if (deferred.size === 0) return () => false;\n return (name) => deferred.has(name);\n}\n\n/**\n * Stable-partition `tools` into [static..., deferred...] and stamp the\n * Anthropic `cache_control: ephemeral` marker on the last static tool.\n *\n * If `tools` is undefined or empty, or no entry has a usable `.name`,\n * returns the input unchanged. If there are no static tools at all,\n * also returns unchanged (nothing to cache).\n *\n * The original tool instances are never mutated. The marked entry is a\n * shallow wrapper that preserves the prototype chain so downstream\n * `instanceof` checks still pass. `extras` is merged so any existing\n * `providerToolDefinition` / other extras the host attached are kept.\n */\nexport function partitionAndMarkAnthropicToolCache(\n tools: GraphTools | undefined,\n isDeferred: (toolName: string) => boolean\n): GraphTools | undefined {\n if (tools == null || tools.length === 0) return tools;\n\n // Use unknown[] internally to avoid GraphTools' union-array variance\n // (each member is one of three array types). We cast back to\n // GraphTools when returning.\n const staticTools: unknown[] = [];\n const deferredTools: unknown[] = [];\n\n for (const tool of tools) {\n const name = (tool as { name?: unknown }).name;\n if (typeof name === 'string' && isDeferred(name)) {\n deferredTools.push(tool);\n } else {\n staticTools.push(tool);\n }\n }\n\n if (staticTools.length === 0) {\n return tools;\n }\n\n const last = staticTools[staticTools.length - 1] as {\n extras?: Record<string, unknown>;\n };\n // Already marked? Don't double-clone.\n if (\n last.extras != null &&\n 'cache_control' in last.extras &&\n (last.extras as { cache_control?: unknown }).cache_control != null\n ) {\n if (deferredTools.length === 0) return tools;\n return [...staticTools, ...deferredTools] as GraphTools;\n }\n\n const wrapped = Object.assign(\n Object.create(Object.getPrototypeOf(last) ?? Object.prototype),\n last,\n {\n extras: {\n ...((last.extras as Record<string, unknown> | undefined) ?? {}),\n cache_control: { type: 'ephemeral' as const },\n },\n }\n );\n\n staticTools[staticTools.length - 1] = wrapped;\n return [...staticTools, ...deferredTools] as GraphTools;\n}\n"],"names":[],"mappings":";;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;AAyBG;AAIH;;;;;AAKG;AACG,SAAU,cAAc,CAC5B,eAEa,EAAA;IAEb,IAAI,eAAe,IAAI,IAAI,IAAI,eAAe,CAAC,MAAM,KAAK,CAAC,EAAE;AAC3D,QAAA,OAAO,MAAM,KAAK;IACpB;AACA,IAAA,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAU;AAClC,IAAA,KAAK,MAAM,GAAG,IAAI,eAAe,EAAE;AACjC,QAAA,IAAI,GAAG,CAAC,aAAa,KAAK,IAAI;AAAE,YAAA,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC;IACxD;AACA,IAAA,IAAI,QAAQ,CAAC,IAAI,KAAK,CAAC;AAAE,QAAA,OAAO,MAAM,KAAK;IAC3C,OAAO,CAAC,IAAI,KAAK,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC;AACrC;AAEA;;;;;;;;;;;;AAYG;AACG,SAAU,kCAAkC,CAChD,KAA6B,EAC7B,UAAyC,EAAA;IAEzC,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;AAAE,QAAA,OAAO,KAAK;;;;IAKrD,MAAM,WAAW,GAAc,EAAE;IACjC,MAAM,aAAa,GAAc,EAAE;AAEnC,IAAA,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;AACxB,QAAA,MAAM,IAAI,GAAI,IAA2B,CAAC,IAAI;QAC9C,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,UAAU,CAAC,IAAI,CAAC,EAAE;AAChD,YAAA,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC;QAC1B;aAAO;AACL,YAAA,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC;QACxB;IACF;AAEA,IAAA,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE;AAC5B,QAAA,OAAO,KAAK;IACd;IAEA,MAAM,IAAI,GAAG,WAAW,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,CAE9C;;AAED,IAAA,IACE,IAAI,CAAC,MAAM,IAAI,IAAI;QACnB,eAAe,IAAI,IAAI,CAAC,MAAM;AAC7B,QAAA,IAAI,CAAC,MAAsC,CAAC,aAAa,IAAI,IAAI,EAClE;AACA,QAAA,IAAI,aAAa,CAAC,MAAM,KAAK,CAAC;AAAE,YAAA,OAAO,KAAK;AAC5C,QAAA,OAAO,CAAC,GAAG,WAAW,EAAE,GAAG,aAAa,CAAe;IACzD;IAEA,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAC3B,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,SAAS,CAAC,EAC9D,IAAI,EACJ;AACE,QAAA,MAAM,EAAE;AACN,YAAA,IAAK,IAAI,CAAC,MAA8C,IAAI,EAAE,CAAC;AAC/D,YAAA,aAAa,EAAE,EAAE,IAAI,EAAE,WAAoB,EAAE;AAC9C,SAAA;AACF,KAAA,CACF;IAED,WAAW,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,OAAO;AAC7C,IAAA,OAAO,CAAC,GAAG,WAAW,EAAE,GAAG,aAAa,CAAe;AACzD;;;;;"}
|
|
@@ -29,6 +29,31 @@ const PRESSURE_BANDS = [
|
|
|
29
29
|
const MASKED_RESULT_MAX_CHARS = 300;
|
|
30
30
|
/** Hard cap for the originalToolContent store (~2 MB estimated from char length). */
|
|
31
31
|
const ORIGINAL_CONTENT_MAX_CHARS = 2_000_000;
|
|
32
|
+
/**
|
|
33
|
+
* Evicts oldest entries from `map` (in Map-iteration / insertion order) until
|
|
34
|
+
* the cumulative char length of remaining values fits within
|
|
35
|
+
* `ORIGINAL_CONTENT_MAX_CHARS`. Used by the recency-window carry-over merge
|
|
36
|
+
* path in Graph.ts to bound long-running session memory: the pruner enforces
|
|
37
|
+
* the cap inside its own `originalToolContent` map, but a key-wise union with
|
|
38
|
+
* recency carry-over bypasses that cap unless re-applied here.
|
|
39
|
+
*/
|
|
40
|
+
function enforceOriginalContentCap(map) {
|
|
41
|
+
let total = 0;
|
|
42
|
+
for (const v of map.values()) {
|
|
43
|
+
total += v.length;
|
|
44
|
+
}
|
|
45
|
+
while (total > ORIGINAL_CONTENT_MAX_CHARS && map.size > 0) {
|
|
46
|
+
const oldest = map.keys().next();
|
|
47
|
+
if (oldest.done === true) {
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
const removed = map.get(oldest.value);
|
|
51
|
+
if (removed != null) {
|
|
52
|
+
total -= removed.length;
|
|
53
|
+
}
|
|
54
|
+
map.delete(oldest.value);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
32
57
|
/** Minimum cumulative calibration ratio — provider can't count fewer tokens
|
|
33
58
|
* than our raw estimate (within reason). Prevents divide-by-zero edge cases. */
|
|
34
59
|
const CALIBRATION_RATIO_MIN = 0.5;
|
|
@@ -1506,9 +1531,11 @@ function createPruneMessages(factoryParams) {
|
|
|
1506
1531
|
}
|
|
1507
1532
|
|
|
1508
1533
|
exports.DEFAULT_RESERVE_RATIO = DEFAULT_RESERVE_RATIO;
|
|
1534
|
+
exports.ORIGINAL_CONTENT_MAX_CHARS = ORIGINAL_CONTENT_MAX_CHARS;
|
|
1509
1535
|
exports.calculateTotalTokens = calculateTotalTokens;
|
|
1510
1536
|
exports.checkValidNumber = checkValidNumber;
|
|
1511
1537
|
exports.createPruneMessages = createPruneMessages;
|
|
1538
|
+
exports.enforceOriginalContentCap = enforceOriginalContentCap;
|
|
1512
1539
|
exports.getMessagesWithinTokenLimit = getMessagesWithinTokenLimit;
|
|
1513
1540
|
exports.maskConsumedToolResults = maskConsumedToolResults;
|
|
1514
1541
|
exports.preFlightTruncateToolCallInputs = preFlightTruncateToolCallInputs;
|