@librechat/agents 3.1.89 → 3.1.91
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 +9 -5
- package/dist/cjs/agents/AgentContext.cjs.map +1 -1
- package/dist/cjs/graphs/Graph.cjs +53 -14
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/hooks/executeHooks.cjs +14 -7
- package/dist/cjs/hooks/executeHooks.cjs.map +1 -1
- package/dist/cjs/langfuse.cjs +234 -0
- package/dist/cjs/langfuse.cjs.map +1 -0
- package/dist/cjs/llm/anthropic/index.cjs +8 -2
- package/dist/cjs/llm/anthropic/index.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs +34 -0
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs.map +1 -1
- package/dist/cjs/main.cjs +34 -0
- package/dist/cjs/main.cjs.map +1 -1
- package/dist/cjs/run.cjs +44 -27
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/stream.cjs +10 -3
- package/dist/cjs/stream.cjs.map +1 -1
- package/dist/cjs/tools/BashExecutor.cjs +10 -9
- package/dist/cjs/tools/BashExecutor.cjs.map +1 -1
- package/dist/cjs/tools/BashProgrammaticToolCalling.cjs +12 -8
- package/dist/cjs/tools/BashProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/CodeExecutor.cjs +35 -11
- package/dist/cjs/tools/CodeExecutor.cjs.map +1 -1
- package/dist/cjs/tools/CodeSessionFileSummary.cjs +63 -0
- package/dist/cjs/tools/CodeSessionFileSummary.cjs.map +1 -0
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs +16 -12
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/ToolNode.cjs +8 -5
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/tools/cloudflare/CloudflareBridgeRuntime.cjs +380 -0
- package/dist/cjs/tools/cloudflare/CloudflareBridgeRuntime.cjs.map +1 -0
- package/dist/cjs/tools/cloudflare/CloudflareProgrammaticToolCalling.cjs +997 -0
- package/dist/cjs/tools/cloudflare/CloudflareProgrammaticToolCalling.cjs.map +1 -0
- package/dist/cjs/tools/cloudflare/CloudflareSandboxExecutionEngine.cjs +575 -0
- package/dist/cjs/tools/cloudflare/CloudflareSandboxExecutionEngine.cjs.map +1 -0
- package/dist/cjs/tools/cloudflare/CloudflareSandboxTools.cjs +165 -0
- package/dist/cjs/tools/cloudflare/CloudflareSandboxTools.cjs.map +1 -0
- package/dist/cjs/tools/local/LocalExecutionEngine.cjs +17 -5
- package/dist/cjs/tools/local/LocalExecutionEngine.cjs.map +1 -1
- package/dist/cjs/tools/local/resolveLocalExecutionTools.cjs +110 -6
- package/dist/cjs/tools/local/resolveLocalExecutionTools.cjs.map +1 -1
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs +319 -29
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs.map +1 -1
- package/dist/esm/agents/AgentContext.mjs +9 -5
- package/dist/esm/agents/AgentContext.mjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +53 -14
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/hooks/executeHooks.mjs +14 -7
- package/dist/esm/hooks/executeHooks.mjs.map +1 -1
- package/dist/esm/langfuse.mjs +226 -0
- package/dist/esm/langfuse.mjs.map +1 -0
- package/dist/esm/llm/anthropic/index.mjs +9 -3
- package/dist/esm/llm/anthropic/index.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/message_inputs.mjs +33 -1
- package/dist/esm/llm/anthropic/utils/message_inputs.mjs.map +1 -1
- package/dist/esm/main.mjs +7 -2
- package/dist/esm/main.mjs.map +1 -1
- package/dist/esm/run.mjs +44 -27
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/stream.mjs +10 -3
- package/dist/esm/stream.mjs.map +1 -1
- package/dist/esm/tools/BashExecutor.mjs +11 -10
- package/dist/esm/tools/BashExecutor.mjs.map +1 -1
- package/dist/esm/tools/BashProgrammaticToolCalling.mjs +13 -9
- package/dist/esm/tools/BashProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/CodeExecutor.mjs +29 -12
- package/dist/esm/tools/CodeExecutor.mjs.map +1 -1
- package/dist/esm/tools/CodeSessionFileSummary.mjs +60 -0
- package/dist/esm/tools/CodeSessionFileSummary.mjs.map +1 -0
- package/dist/esm/tools/ProgrammaticToolCalling.mjs +17 -13
- package/dist/esm/tools/ProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/ToolNode.mjs +8 -5
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/cloudflare/CloudflareBridgeRuntime.mjs +378 -0
- package/dist/esm/tools/cloudflare/CloudflareBridgeRuntime.mjs.map +1 -0
- package/dist/esm/tools/cloudflare/CloudflareProgrammaticToolCalling.mjs +994 -0
- package/dist/esm/tools/cloudflare/CloudflareProgrammaticToolCalling.mjs.map +1 -0
- package/dist/esm/tools/cloudflare/CloudflareSandboxExecutionEngine.mjs +566 -0
- package/dist/esm/tools/cloudflare/CloudflareSandboxExecutionEngine.mjs.map +1 -0
- package/dist/esm/tools/cloudflare/CloudflareSandboxTools.mjs +155 -0
- package/dist/esm/tools/cloudflare/CloudflareSandboxTools.mjs.map +1 -0
- package/dist/esm/tools/local/LocalExecutionEngine.mjs +17 -6
- package/dist/esm/tools/local/LocalExecutionEngine.mjs.map +1 -1
- package/dist/esm/tools/local/resolveLocalExecutionTools.mjs +111 -7
- package/dist/esm/tools/local/resolveLocalExecutionTools.mjs.map +1 -1
- package/dist/esm/tools/subagent/SubagentExecutor.mjs +320 -31
- package/dist/esm/tools/subagent/SubagentExecutor.mjs.map +1 -1
- package/dist/types/agents/AgentContext.d.ts +4 -1
- package/dist/types/graphs/Graph.d.ts +6 -5
- package/dist/types/index.d.ts +1 -0
- package/dist/types/langfuse.d.ts +48 -0
- package/dist/types/llm/anthropic/index.d.ts +3 -1
- package/dist/types/llm/anthropic/utils/message_inputs.d.ts +4 -0
- package/dist/types/tools/BashExecutor.d.ts +3 -3
- package/dist/types/tools/CodeExecutor.d.ts +10 -3
- package/dist/types/tools/CodeSessionFileSummary.d.ts +3 -0
- package/dist/types/tools/ProgrammaticToolCalling.d.ts +4 -4
- package/dist/types/tools/cloudflare/CloudflareBridgeRuntime.d.ts +23 -0
- package/dist/types/tools/cloudflare/CloudflareProgrammaticToolCalling.d.ts +4 -0
- package/dist/types/tools/cloudflare/CloudflareSandboxExecutionEngine.d.ts +21 -0
- package/dist/types/tools/cloudflare/CloudflareSandboxTools.d.ts +22 -0
- package/dist/types/tools/cloudflare/index.d.ts +4 -0
- package/dist/types/tools/local/LocalExecutionEngine.d.ts +1 -0
- package/dist/types/tools/subagent/SubagentExecutor.d.ts +8 -5
- package/dist/types/types/graph.d.ts +8 -0
- package/dist/types/types/tools.d.ts +120 -5
- package/package.json +4 -4
- package/src/__tests__/stream.eagerEventExecution.test.ts +66 -0
- package/src/agents/AgentContext.ts +13 -3
- package/src/graphs/Graph.ts +60 -16
- package/src/hooks/__tests__/executeHooks.test.ts +38 -0
- package/src/hooks/executeHooks.ts +27 -7
- package/src/index.ts +1 -0
- package/src/langfuse.ts +358 -0
- package/src/llm/anthropic/index.ts +27 -3
- package/src/llm/anthropic/llm.spec.ts +60 -1
- package/src/llm/anthropic/utils/message_inputs.ts +46 -0
- package/src/run.ts +60 -38
- package/src/specs/langfuse-config.test.ts +57 -0
- package/src/specs/langfuse-metadata.test.ts +19 -1
- package/src/stream.ts +13 -3
- package/src/tools/BashExecutor.ts +21 -10
- package/src/tools/BashProgrammaticToolCalling.ts +21 -9
- package/src/tools/CodeExecutor.ts +55 -12
- package/src/tools/CodeSessionFileSummary.ts +80 -0
- package/src/tools/ProgrammaticToolCalling.ts +25 -12
- package/src/tools/ToolNode.ts +8 -5
- package/src/tools/__tests__/BashExecutor.test.ts +9 -0
- package/src/tools/__tests__/CloudflareSandboxExecution.test.ts +537 -0
- package/src/tools/__tests__/CodeApiAuthHeaders.test.ts +43 -0
- package/src/tools/__tests__/ProgrammaticToolCalling.test.ts +100 -16
- package/src/tools/__tests__/SubagentExecutor.test.ts +540 -6
- package/src/tools/__tests__/ToolNode.outputReferences.test.ts +52 -0
- package/src/tools/__tests__/subagentHooks.test.ts +237 -0
- package/src/tools/cloudflare/CloudflareBridgeRuntime.ts +480 -0
- package/src/tools/cloudflare/CloudflareProgrammaticToolCalling.ts +1162 -0
- package/src/tools/cloudflare/CloudflareSandboxExecutionEngine.ts +744 -0
- package/src/tools/cloudflare/CloudflareSandboxTools.ts +225 -0
- package/src/tools/cloudflare/index.ts +4 -0
- package/src/tools/local/LocalExecutionEngine.ts +20 -4
- package/src/tools/local/resolveLocalExecutionTools.ts +169 -7
- package/src/tools/subagent/SubagentExecutor.ts +514 -36
- package/src/types/graph.ts +9 -0
- package/src/types/tools.ts +143 -5
|
@@ -4,13 +4,53 @@ var _enum = require('../../common/enum.cjs');
|
|
|
4
4
|
var LocalExecutionTools = require('./LocalExecutionTools.cjs');
|
|
5
5
|
var LocalCodingTools = require('./LocalCodingTools.cjs');
|
|
6
6
|
var LocalProgrammaticToolCalling = require('./LocalProgrammaticToolCalling.cjs');
|
|
7
|
+
require('path');
|
|
8
|
+
require('../cloudflare/CloudflareProgrammaticToolCalling.cjs');
|
|
9
|
+
require('events');
|
|
10
|
+
require('stream');
|
|
11
|
+
require('./LocalExecutionEngine.cjs');
|
|
12
|
+
var CloudflareSandboxTools = require('../cloudflare/CloudflareSandboxTools.cjs');
|
|
7
13
|
|
|
8
14
|
function shouldUseLocalExecution(config) {
|
|
9
15
|
return config?.engine === 'local';
|
|
10
16
|
}
|
|
17
|
+
function shouldUseCloudflareSandboxExecution(config) {
|
|
18
|
+
return config?.engine === 'cloudflare-sandbox';
|
|
19
|
+
}
|
|
11
20
|
function shouldIncludeCodingTools(config) {
|
|
12
|
-
return (shouldUseLocalExecution(config) &&
|
|
13
|
-
config?.local?.includeCodingTools !== false)
|
|
21
|
+
return ((shouldUseLocalExecution(config) &&
|
|
22
|
+
config?.local?.includeCodingTools !== false) ||
|
|
23
|
+
(shouldUseCloudflareSandboxExecution(config) &&
|
|
24
|
+
config?.cloudflare?.includeCodingTools !== false));
|
|
25
|
+
}
|
|
26
|
+
function getCloudflareConfig(config) {
|
|
27
|
+
if (config?.cloudflare == null) {
|
|
28
|
+
throw new Error('toolExecution.cloudflare is required when engine is "cloudflare-sandbox".');
|
|
29
|
+
}
|
|
30
|
+
return config.cloudflare;
|
|
31
|
+
}
|
|
32
|
+
function getSelectedCloudflareCodingToolNames(config) {
|
|
33
|
+
return new Set(config.codingToolNames ?? _enum.LOCAL_CODING_BUNDLE_NAMES);
|
|
34
|
+
}
|
|
35
|
+
function filterCloudflareCodingToolAllowlist(tools, selectedNames) {
|
|
36
|
+
const existingTools = tools ?? [];
|
|
37
|
+
if (existingTools.length === 0) {
|
|
38
|
+
return tools;
|
|
39
|
+
}
|
|
40
|
+
return existingTools.filter((existingTool) => {
|
|
41
|
+
if (!('name' in existingTool) || typeof existingTool.name !== 'string') {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
return (!_enum.LOCAL_CODING_BUNDLE_NAMES.includes(existingTool.name) ||
|
|
45
|
+
selectedNames.has(existingTool.name));
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
function pruneCloudflareCodingToolAllowlist(toolMap, selectedNames) {
|
|
49
|
+
for (const name of _enum.LOCAL_CODING_BUNDLE_NAMES) {
|
|
50
|
+
if (!selectedNames.has(name)) {
|
|
51
|
+
toolMap.delete(name);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
14
54
|
}
|
|
15
55
|
function createLocalExecutionTool(name, config) {
|
|
16
56
|
switch (name) {
|
|
@@ -47,9 +87,26 @@ function mergeToolsByName(baseTools, localTools) {
|
|
|
47
87
|
return orderedTools;
|
|
48
88
|
}
|
|
49
89
|
function resolveLocalToolsForBinding(args) {
|
|
50
|
-
if (!shouldUseLocalExecution(args.toolExecution)
|
|
90
|
+
if (!shouldUseLocalExecution(args.toolExecution) &&
|
|
91
|
+
!shouldUseCloudflareSandboxExecution(args.toolExecution)) {
|
|
51
92
|
return args.tools;
|
|
52
93
|
}
|
|
94
|
+
if (shouldUseCloudflareSandboxExecution(args.toolExecution)) {
|
|
95
|
+
const cloudflareConfig = getCloudflareConfig(args.toolExecution);
|
|
96
|
+
if (shouldIncludeCodingTools(args.toolExecution)) {
|
|
97
|
+
const selectedNames = getSelectedCloudflareCodingToolNames(cloudflareConfig);
|
|
98
|
+
return mergeToolsByName(filterCloudflareCodingToolAllowlist(args.tools, selectedNames), CloudflareSandboxTools.createCloudflareCodingTools(cloudflareConfig));
|
|
99
|
+
}
|
|
100
|
+
const replacements = (args.tools ?? [])
|
|
101
|
+
.filter((existingTool) => 'name' in existingTool &&
|
|
102
|
+
typeof existingTool.name === 'string' &&
|
|
103
|
+
_enum.CODE_EXECUTION_TOOLS.has(existingTool.name))
|
|
104
|
+
.map((existingTool) => CloudflareSandboxTools.createCloudflareExecutionTool(existingTool.name, cloudflareConfig))
|
|
105
|
+
.filter((cloudflareTool) => cloudflareTool != null);
|
|
106
|
+
return replacements.length === 0
|
|
107
|
+
? args.tools
|
|
108
|
+
: mergeToolsByName(args.tools, replacements);
|
|
109
|
+
}
|
|
53
110
|
const localConfig = args.toolExecution?.local ?? {};
|
|
54
111
|
if (shouldIncludeCodingTools(args.toolExecution)) {
|
|
55
112
|
return mergeToolsByName(args.tools, LocalCodingTools.createLocalCodingTools(localConfig));
|
|
@@ -69,22 +126,68 @@ function resolveLocalToolRegistry(args) {
|
|
|
69
126
|
return args.toolRegistry;
|
|
70
127
|
}
|
|
71
128
|
const registry = new Map(args.toolRegistry ?? []);
|
|
129
|
+
const selectedNames = shouldUseCloudflareSandboxExecution(args.toolExecution)
|
|
130
|
+
? getSelectedCloudflareCodingToolNames(getCloudflareConfig(args.toolExecution))
|
|
131
|
+
: undefined;
|
|
72
132
|
for (const definition of LocalCodingTools.createLocalCodingToolDefinitions()) {
|
|
133
|
+
if (selectedNames != null && !selectedNames.has(definition.name)) {
|
|
134
|
+
registry.delete(definition.name);
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
73
137
|
registry.set(definition.name, definition);
|
|
74
138
|
}
|
|
75
139
|
return registry;
|
|
76
140
|
}
|
|
77
141
|
function resolveLocalExecutionTools(args) {
|
|
78
142
|
const directToolNames = new Set();
|
|
79
|
-
if (!shouldUseLocalExecution(args.toolExecution)
|
|
143
|
+
if (!shouldUseLocalExecution(args.toolExecution) &&
|
|
144
|
+
!shouldUseCloudflareSandboxExecution(args.toolExecution)) {
|
|
80
145
|
return {
|
|
81
146
|
toolMap: args.toolMap,
|
|
82
147
|
directToolNames,
|
|
83
148
|
};
|
|
84
149
|
}
|
|
85
|
-
const localConfig = args.toolExecution?.local ?? {};
|
|
86
150
|
const toolMap = new Map(args.toolMap);
|
|
87
151
|
let fileCheckpointer;
|
|
152
|
+
if (shouldUseCloudflareSandboxExecution(args.toolExecution)) {
|
|
153
|
+
const cloudflareConfig = getCloudflareConfig(args.toolExecution);
|
|
154
|
+
if (shouldIncludeCodingTools(args.toolExecution)) {
|
|
155
|
+
const selectedNames = getSelectedCloudflareCodingToolNames(cloudflareConfig);
|
|
156
|
+
pruneCloudflareCodingToolAllowlist(toolMap, selectedNames);
|
|
157
|
+
if (cloudflareConfig.fileCheckpointing === true ||
|
|
158
|
+
args.fileCheckpointer != null) {
|
|
159
|
+
const bundle = CloudflareSandboxTools.createCloudflareCodingToolBundle(cloudflareConfig, {
|
|
160
|
+
checkpointer: args.fileCheckpointer,
|
|
161
|
+
});
|
|
162
|
+
fileCheckpointer = bundle.checkpointer;
|
|
163
|
+
for (const cloudflareTool of bundle.tools) {
|
|
164
|
+
toolMap.set(cloudflareTool.name, cloudflareTool);
|
|
165
|
+
directToolNames.add(cloudflareTool.name);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
for (const cloudflareTool of CloudflareSandboxTools.createCloudflareCodingTools(cloudflareConfig)) {
|
|
170
|
+
toolMap.set(cloudflareTool.name, cloudflareTool);
|
|
171
|
+
directToolNames.add(cloudflareTool.name);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
const includeCodingTools = shouldIncludeCodingTools(args.toolExecution);
|
|
176
|
+
for (const name of _enum.CODE_EXECUTION_TOOLS) {
|
|
177
|
+
if (includeCodingTools)
|
|
178
|
+
continue;
|
|
179
|
+
if (!toolMap.has(name))
|
|
180
|
+
continue;
|
|
181
|
+
const cloudflareTool = CloudflareSandboxTools.createCloudflareExecutionTool(name, cloudflareConfig);
|
|
182
|
+
if (cloudflareTool == null) {
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
toolMap.set(name, cloudflareTool);
|
|
186
|
+
directToolNames.add(name);
|
|
187
|
+
}
|
|
188
|
+
return { toolMap, directToolNames, fileCheckpointer };
|
|
189
|
+
}
|
|
190
|
+
const localConfig = args.toolExecution?.local ?? {};
|
|
88
191
|
if (shouldIncludeCodingTools(args.toolExecution)) {
|
|
89
192
|
// Use the bundle factory when fileCheckpointing is on so we can
|
|
90
193
|
// surface the checkpointer back to the caller — without this, the
|
|
@@ -92,7 +195,8 @@ function resolveLocalExecutionTools(args) {
|
|
|
92
195
|
// immediately discarded, making the public `fileCheckpointing`
|
|
93
196
|
// config flag a silent no-op outside of direct
|
|
94
197
|
// `createLocalCodingToolBundle()` use.
|
|
95
|
-
if (localConfig.fileCheckpointing === true ||
|
|
198
|
+
if (localConfig.fileCheckpointing === true ||
|
|
199
|
+
args.fileCheckpointer != null) {
|
|
96
200
|
const bundle = LocalCodingTools.createLocalCodingToolBundle(localConfig, {
|
|
97
201
|
checkpointer: args.fileCheckpointer,
|
|
98
202
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveLocalExecutionTools.cjs","sources":["../../../../src/tools/local/resolveLocalExecutionTools.ts"],"sourcesContent":["import { Constants, CODE_EXECUTION_TOOLS } from '@/common';\nimport {\n createLocalBashExecutionTool,\n createLocalCodeExecutionTool,\n} from './LocalExecutionTools';\nimport {\n createLocalCodingToolBundle,\n createLocalCodingToolDefinitions,\n createLocalCodingTools,\n} from './LocalCodingTools';\nimport {\n createLocalBashProgrammaticToolCallingTool,\n createLocalProgrammaticToolCallingTool,\n} from './LocalProgrammaticToolCalling';\nimport type * as t from '@/types';\n\ntype ResolveLocalToolsResult = {\n toolMap: t.ToolMap;\n directToolNames: Set<string>;\n /**\n * Set when `local.fileCheckpointing === true` AND the auto-bind\n * coding suite is in use. ToolNode stashes this on the node and\n * exposes it via `getFileCheckpointer()` so the host can call\n * `rewind()` after a failed batch. Manual review (finding E)\n * flagged that the config flag was previously a no-op in the\n * Run/ToolNode auto-bind path — only direct\n * `createLocalCodingToolBundle()` callers could access the\n * checkpointer.\n */\n fileCheckpointer?: t.LocalFileCheckpointer;\n};\n\nfunction shouldUseLocalExecution(config?: t.ToolExecutionConfig): boolean {\n return config?.engine === 'local';\n}\n\nfunction shouldIncludeCodingTools(config?: t.ToolExecutionConfig): boolean {\n return (\n shouldUseLocalExecution(config) &&\n config?.local?.includeCodingTools !== false\n );\n}\n\nfunction createLocalExecutionTool(\n name: string,\n config: t.LocalExecutionConfig\n): t.GenericTool | undefined {\n switch (name) {\n case Constants.EXECUTE_CODE:\n return createLocalCodeExecutionTool(config);\n case Constants.BASH_TOOL:\n return createLocalBashExecutionTool({ config });\n case Constants.PROGRAMMATIC_TOOL_CALLING:\n return createLocalProgrammaticToolCallingTool(config);\n case Constants.BASH_PROGRAMMATIC_TOOL_CALLING:\n return createLocalBashProgrammaticToolCallingTool(config);\n default:\n return undefined;\n }\n}\n\nfunction mergeToolsByName(\n baseTools: t.GraphTools | undefined,\n localTools: t.GenericTool[]\n): t.GraphTools {\n const orderedTools: t.GenericTool[] = [];\n const indexByName = new Map<string, number>();\n\n for (const tool of (baseTools as t.GenericTool[] | undefined) ?? []) {\n if ('name' in tool && typeof tool.name === 'string') {\n indexByName.set(tool.name, orderedTools.length);\n }\n orderedTools.push(tool);\n }\n\n for (const tool of localTools) {\n const existingIndex = indexByName.get(tool.name);\n if (existingIndex == null) {\n indexByName.set(tool.name, orderedTools.length);\n orderedTools.push(tool);\n continue;\n }\n orderedTools[existingIndex] = tool;\n }\n\n return orderedTools;\n}\n\nexport function resolveLocalToolsForBinding(args: {\n tools?: t.GraphTools;\n toolExecution?: t.ToolExecutionConfig;\n}): t.GraphTools | undefined {\n if (!shouldUseLocalExecution(args.toolExecution)) {\n return args.tools;\n }\n\n const localConfig = args.toolExecution?.local ?? {};\n if (shouldIncludeCodingTools(args.toolExecution)) {\n return mergeToolsByName(args.tools, createLocalCodingTools(localConfig));\n }\n\n const replacements = ((args.tools as t.GenericTool[] | undefined) ?? [])\n .filter(\n (existingTool): existingTool is t.GenericTool & { name: string } =>\n 'name' in existingTool &&\n typeof existingTool.name === 'string' &&\n CODE_EXECUTION_TOOLS.has(existingTool.name)\n )\n .map((existingTool) =>\n createLocalExecutionTool(existingTool.name, localConfig)\n )\n .filter((localTool): localTool is t.GenericTool => localTool != null);\n\n return replacements.length === 0\n ? args.tools\n : mergeToolsByName(args.tools, replacements);\n}\n\nexport function resolveLocalToolRegistry(args: {\n toolRegistry?: t.LCToolRegistry;\n toolExecution?: t.ToolExecutionConfig;\n}): t.LCToolRegistry | undefined {\n if (!shouldIncludeCodingTools(args.toolExecution)) {\n return args.toolRegistry;\n }\n\n const registry = new Map(args.toolRegistry ?? []);\n for (const definition of createLocalCodingToolDefinitions()) {\n registry.set(definition.name, definition);\n }\n return registry;\n}\n\nexport function resolveLocalExecutionTools(args: {\n toolMap: t.ToolMap;\n toolExecution?: t.ToolExecutionConfig;\n /**\n * Caller-provided checkpointer that overrides the bundle's\n * auto-created one. The Graph layer threads a single per-Run\n * instance so every ToolNode it compiles shares one snapshot\n * store — without that, a multi-agent graph would each get a\n * private checkpointer and `Run.rewindFiles()` couldn't reach\n * any of them.\n */\n fileCheckpointer?: t.LocalFileCheckpointer;\n}): ResolveLocalToolsResult {\n const directToolNames = new Set<string>();\n if (!shouldUseLocalExecution(args.toolExecution)) {\n return {\n toolMap: args.toolMap,\n directToolNames,\n };\n }\n\n const localConfig = args.toolExecution?.local ?? {};\n const toolMap = new Map(args.toolMap);\n let fileCheckpointer: t.LocalFileCheckpointer | undefined;\n\n if (shouldIncludeCodingTools(args.toolExecution)) {\n // Use the bundle factory when fileCheckpointing is on so we can\n // surface the checkpointer back to the caller — without this, the\n // execution-path tools each captured into a checkpointer that was\n // immediately discarded, making the public `fileCheckpointing`\n // config flag a silent no-op outside of direct\n // `createLocalCodingToolBundle()` use.\n if (localConfig.fileCheckpointing === true || args.fileCheckpointer != null) {\n const bundle = createLocalCodingToolBundle(localConfig, {\n checkpointer: args.fileCheckpointer,\n });\n fileCheckpointer = bundle.checkpointer;\n for (const localTool of bundle.tools) {\n toolMap.set(localTool.name, localTool);\n directToolNames.add(localTool.name);\n }\n } else {\n for (const localTool of createLocalCodingTools(localConfig)) {\n toolMap.set(localTool.name, localTool);\n directToolNames.add(localTool.name);\n }\n }\n }\n\n // When the coding-tool bundle was already installed above, it\n // already created `bash_tool` / `execute_code` / programmatic-tool\n // variants. Skip re-creating them here — the audit-of-audit (manual\n // finding #4) flagged that the original loop overwrote those bundle\n // instances with fresh ones via `createLocalExecutionTool`, wasting\n // work and (more importantly) replacing tools the bundle had\n // already wired up with shared state. The CODE_EXECUTION_TOOLS\n // loop is now only relevant when the host pre-bound a tool with\n // one of these names (the `toolMap.has(name)` branch) and coding\n // tools are off.\n const includeCodingTools = shouldIncludeCodingTools(args.toolExecution);\n for (const name of CODE_EXECUTION_TOOLS) {\n if (includeCodingTools) continue;\n if (!toolMap.has(name)) continue;\n\n const localTool = createLocalExecutionTool(name, localConfig);\n if (localTool == null) {\n continue;\n }\n\n toolMap.set(name, localTool);\n directToolNames.add(name);\n }\n\n return { toolMap, directToolNames, fileCheckpointer };\n}\n"],"names":["Constants","createLocalCodeExecutionTool","createLocalBashExecutionTool","createLocalProgrammaticToolCallingTool","createLocalBashProgrammaticToolCallingTool","createLocalCodingTools","CODE_EXECUTION_TOOLS","createLocalCodingToolDefinitions","createLocalCodingToolBundle"],"mappings":";;;;;;;AAgCA,SAAS,uBAAuB,CAAC,MAA8B,EAAA;AAC7D,IAAA,OAAO,MAAM,EAAE,MAAM,KAAK,OAAO;AACnC;AAEA,SAAS,wBAAwB,CAAC,MAA8B,EAAA;AAC9D,IAAA,QACE,uBAAuB,CAAC,MAAM,CAAC;AAC/B,QAAA,MAAM,EAAE,KAAK,EAAE,kBAAkB,KAAK,KAAK;AAE/C;AAEA,SAAS,wBAAwB,CAC/B,IAAY,EACZ,MAA8B,EAAA;IAE9B,QAAQ,IAAI;QACZ,KAAKA,eAAS,CAAC,YAAY;AACzB,YAAA,OAAOC,gDAA4B,CAAC,MAAM,CAAC;QAC7C,KAAKD,eAAS,CAAC,SAAS;AACtB,YAAA,OAAOE,gDAA4B,CAAC,EAAE,MAAM,EAAE,CAAC;QACjD,KAAKF,eAAS,CAAC,yBAAyB;AACtC,YAAA,OAAOG,mEAAsC,CAAC,MAAM,CAAC;QACvD,KAAKH,eAAS,CAAC,8BAA8B;AAC3C,YAAA,OAAOI,uEAA0C,CAAC,MAAM,CAAC;AAC3D,QAAA;AACE,YAAA,OAAO,SAAS;;AAEpB;AAEA,SAAS,gBAAgB,CACvB,SAAmC,EACnC,UAA2B,EAAA;IAE3B,MAAM,YAAY,GAAoB,EAAE;AACxC,IAAA,MAAM,WAAW,GAAG,IAAI,GAAG,EAAkB;AAE7C,IAAA,KAAK,MAAM,IAAI,IAAK,SAAyC,IAAI,EAAE,EAAE;QACnE,IAAI,MAAM,IAAI,IAAI,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,EAAE;YACnD,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,YAAY,CA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EAAE;gBACpC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,EAAE,SAAS,CAAC;AACtC,gBAAA,eAAe,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC;YACrC;QACF;aAAO;YACL,KAAK,MAAM,SAAS,IAAIH,uCAAsB,CAAC,WAAW,CAAC,EAAE;gBAC3D,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,EAAE,SAAS,CAAC;AACtC,gBAAA,eAAe,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC;YACrC;QACF;IACF;;;;;;;;;;;IAYA,MAAM,kBAAkB,GAAG,wBAAwB,CAAC,IAAI,CAAC,aAAa,CAAC;AACvE,IAAA,KAAK,MAAM,IAAI,IAAIC,0BAAoB,EAAE;AACvC,QAAA,IAAI,kBAAkB;YAAE;AACxB,QAAA,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC;YAAE;QAExB,MAAM,SAAS,GAAG,wBAAwB,CAAC,IAAI,EAAE,WAAW,CAAC;AAC7D,QAAA,IAAI,SAAS,IAAI,IAAI,EAAE;YACrB;QACF;AAEA,QAAA,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,SAAS,CAAC;AAC5B,QAAA,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC;IAC3B;AAEA,IAAA,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE;AACvD;;;;;;"}
|
|
1
|
+
{"version":3,"file":"resolveLocalExecutionTools.cjs","sources":["../../../../src/tools/local/resolveLocalExecutionTools.ts"],"sourcesContent":["import {\n Constants,\n CODE_EXECUTION_TOOLS,\n LOCAL_CODING_BUNDLE_NAMES,\n} from '@/common';\nimport {\n createLocalBashExecutionTool,\n createLocalCodeExecutionTool,\n} from './LocalExecutionTools';\nimport {\n createLocalCodingToolBundle,\n createLocalCodingToolDefinitions,\n createLocalCodingTools,\n} from './LocalCodingTools';\nimport {\n createLocalBashProgrammaticToolCallingTool,\n createLocalProgrammaticToolCallingTool,\n} from './LocalProgrammaticToolCalling';\nimport {\n createCloudflareCodingToolBundle,\n createCloudflareCodingTools,\n createCloudflareExecutionTool,\n} from '@/tools/cloudflare';\nimport type * as t from '@/types';\n\ntype ResolveLocalToolsResult = {\n toolMap: t.ToolMap;\n directToolNames: Set<string>;\n /**\n * Set when `local.fileCheckpointing === true` AND the auto-bind\n * coding suite is in use. ToolNode stashes this on the node and\n * exposes it via `getFileCheckpointer()` so the host can call\n * `rewind()` after a failed batch. Manual review (finding E)\n * flagged that the config flag was previously a no-op in the\n * Run/ToolNode auto-bind path — only direct\n * `createLocalCodingToolBundle()` callers could access the\n * checkpointer.\n */\n fileCheckpointer?: t.LocalFileCheckpointer;\n};\n\nfunction shouldUseLocalExecution(config?: t.ToolExecutionConfig): boolean {\n return config?.engine === 'local';\n}\n\nfunction shouldUseCloudflareSandboxExecution(\n config?: t.ToolExecutionConfig\n): boolean {\n return config?.engine === 'cloudflare-sandbox';\n}\n\nfunction shouldIncludeCodingTools(config?: t.ToolExecutionConfig): boolean {\n return (\n (shouldUseLocalExecution(config) &&\n config?.local?.includeCodingTools !== false) ||\n (shouldUseCloudflareSandboxExecution(config) &&\n config?.cloudflare?.includeCodingTools !== false)\n );\n}\n\nfunction getCloudflareConfig(\n config?: t.ToolExecutionConfig\n): t.CloudflareSandboxExecutionConfig {\n if (config?.cloudflare == null) {\n throw new Error(\n 'toolExecution.cloudflare is required when engine is \"cloudflare-sandbox\".'\n );\n }\n return config.cloudflare;\n}\n\nfunction getSelectedCloudflareCodingToolNames(\n config: t.CloudflareSandboxExecutionConfig\n): Set<string> {\n return new Set(config.codingToolNames ?? LOCAL_CODING_BUNDLE_NAMES);\n}\n\nfunction filterCloudflareCodingToolAllowlist(\n tools: t.GraphTools | undefined,\n selectedNames: Set<string>\n): t.GraphTools | undefined {\n const existingTools = (tools as t.GenericTool[] | undefined) ?? [];\n if (existingTools.length === 0) {\n return tools;\n }\n return existingTools.filter((existingTool) => {\n if (!('name' in existingTool) || typeof existingTool.name !== 'string') {\n return true;\n }\n return (\n !LOCAL_CODING_BUNDLE_NAMES.includes(existingTool.name) ||\n selectedNames.has(existingTool.name)\n );\n });\n}\n\nfunction pruneCloudflareCodingToolAllowlist(\n toolMap: t.ToolMap,\n selectedNames: Set<string>\n): void {\n for (const name of LOCAL_CODING_BUNDLE_NAMES) {\n if (!selectedNames.has(name)) {\n toolMap.delete(name);\n }\n }\n}\n\nfunction createLocalExecutionTool(\n name: string,\n config: t.LocalExecutionConfig\n): t.GenericTool | undefined {\n switch (name) {\n case Constants.EXECUTE_CODE:\n return createLocalCodeExecutionTool(config);\n case Constants.BASH_TOOL:\n return createLocalBashExecutionTool({ config });\n case Constants.PROGRAMMATIC_TOOL_CALLING:\n return createLocalProgrammaticToolCallingTool(config);\n case Constants.BASH_PROGRAMMATIC_TOOL_CALLING:\n return createLocalBashProgrammaticToolCallingTool(config);\n default:\n return undefined;\n }\n}\n\nfunction mergeToolsByName(\n baseTools: t.GraphTools | undefined,\n localTools: t.GenericTool[]\n): t.GraphTools {\n const orderedTools: t.GenericTool[] = [];\n const indexByName = new Map<string, number>();\n\n for (const tool of (baseTools as t.GenericTool[] | undefined) ?? []) {\n if ('name' in tool && typeof tool.name === 'string') {\n indexByName.set(tool.name, orderedTools.length);\n }\n orderedTools.push(tool);\n }\n\n for (const tool of localTools) {\n const existingIndex = indexByName.get(tool.name);\n if (existingIndex == null) {\n indexByName.set(tool.name, orderedTools.length);\n orderedTools.push(tool);\n continue;\n }\n orderedTools[existingIndex] = tool;\n }\n\n return orderedTools;\n}\n\nexport function resolveLocalToolsForBinding(args: {\n tools?: t.GraphTools;\n toolExecution?: t.ToolExecutionConfig;\n}): t.GraphTools | undefined {\n if (\n !shouldUseLocalExecution(args.toolExecution) &&\n !shouldUseCloudflareSandboxExecution(args.toolExecution)\n ) {\n return args.tools;\n }\n\n if (shouldUseCloudflareSandboxExecution(args.toolExecution)) {\n const cloudflareConfig = getCloudflareConfig(args.toolExecution);\n if (shouldIncludeCodingTools(args.toolExecution)) {\n const selectedNames =\n getSelectedCloudflareCodingToolNames(cloudflareConfig);\n return mergeToolsByName(\n filterCloudflareCodingToolAllowlist(args.tools, selectedNames),\n createCloudflareCodingTools(cloudflareConfig)\n );\n }\n\n const replacements = ((args.tools as t.GenericTool[] | undefined) ?? [])\n .filter(\n (existingTool): existingTool is t.GenericTool & { name: string } =>\n 'name' in existingTool &&\n typeof existingTool.name === 'string' &&\n CODE_EXECUTION_TOOLS.has(existingTool.name)\n )\n .map((existingTool) =>\n createCloudflareExecutionTool(existingTool.name, cloudflareConfig)\n )\n .filter(\n (cloudflareTool): cloudflareTool is t.GenericTool =>\n cloudflareTool != null\n );\n\n return replacements.length === 0\n ? args.tools\n : mergeToolsByName(args.tools, replacements);\n }\n\n const localConfig = args.toolExecution?.local ?? {};\n if (shouldIncludeCodingTools(args.toolExecution)) {\n return mergeToolsByName(args.tools, createLocalCodingTools(localConfig));\n }\n\n const replacements = ((args.tools as t.GenericTool[] | undefined) ?? [])\n .filter(\n (existingTool): existingTool is t.GenericTool & { name: string } =>\n 'name' in existingTool &&\n typeof existingTool.name === 'string' &&\n CODE_EXECUTION_TOOLS.has(existingTool.name)\n )\n .map((existingTool) =>\n createLocalExecutionTool(existingTool.name, localConfig)\n )\n .filter((localTool): localTool is t.GenericTool => localTool != null);\n\n return replacements.length === 0\n ? args.tools\n : mergeToolsByName(args.tools, replacements);\n}\n\nexport function resolveLocalToolRegistry(args: {\n toolRegistry?: t.LCToolRegistry;\n toolExecution?: t.ToolExecutionConfig;\n}): t.LCToolRegistry | undefined {\n if (!shouldIncludeCodingTools(args.toolExecution)) {\n return args.toolRegistry;\n }\n\n const registry = new Map(args.toolRegistry ?? []);\n const selectedNames = shouldUseCloudflareSandboxExecution(args.toolExecution)\n ? getSelectedCloudflareCodingToolNames(\n getCloudflareConfig(args.toolExecution)\n )\n : undefined;\n for (const definition of createLocalCodingToolDefinitions()) {\n if (selectedNames != null && !selectedNames.has(definition.name)) {\n registry.delete(definition.name);\n continue;\n }\n registry.set(definition.name, definition);\n }\n return registry;\n}\n\nexport function resolveLocalExecutionTools(args: {\n toolMap: t.ToolMap;\n toolExecution?: t.ToolExecutionConfig;\n /**\n * Caller-provided checkpointer that overrides the bundle's\n * auto-created one. The Graph layer threads a single per-Run\n * instance so every ToolNode it compiles shares one snapshot\n * store — without that, a multi-agent graph would each get a\n * private checkpointer and `Run.rewindFiles()` couldn't reach\n * any of them.\n */\n fileCheckpointer?: t.LocalFileCheckpointer;\n}): ResolveLocalToolsResult {\n const directToolNames = new Set<string>();\n if (\n !shouldUseLocalExecution(args.toolExecution) &&\n !shouldUseCloudflareSandboxExecution(args.toolExecution)\n ) {\n return {\n toolMap: args.toolMap,\n directToolNames,\n };\n }\n\n const toolMap = new Map(args.toolMap);\n let fileCheckpointer: t.LocalFileCheckpointer | undefined;\n\n if (shouldUseCloudflareSandboxExecution(args.toolExecution)) {\n const cloudflareConfig = getCloudflareConfig(args.toolExecution);\n if (shouldIncludeCodingTools(args.toolExecution)) {\n const selectedNames =\n getSelectedCloudflareCodingToolNames(cloudflareConfig);\n pruneCloudflareCodingToolAllowlist(toolMap, selectedNames);\n if (\n cloudflareConfig.fileCheckpointing === true ||\n args.fileCheckpointer != null\n ) {\n const bundle = createCloudflareCodingToolBundle(cloudflareConfig, {\n checkpointer: args.fileCheckpointer,\n });\n fileCheckpointer = bundle.checkpointer;\n for (const cloudflareTool of bundle.tools) {\n toolMap.set(cloudflareTool.name, cloudflareTool);\n directToolNames.add(cloudflareTool.name);\n }\n } else {\n for (const cloudflareTool of createCloudflareCodingTools(\n cloudflareConfig\n )) {\n toolMap.set(cloudflareTool.name, cloudflareTool);\n directToolNames.add(cloudflareTool.name);\n }\n }\n }\n\n const includeCodingTools = shouldIncludeCodingTools(args.toolExecution);\n for (const name of CODE_EXECUTION_TOOLS) {\n if (includeCodingTools) continue;\n if (!toolMap.has(name)) continue;\n\n const cloudflareTool = createCloudflareExecutionTool(\n name,\n cloudflareConfig\n );\n if (cloudflareTool == null) {\n continue;\n }\n\n toolMap.set(name, cloudflareTool);\n directToolNames.add(name);\n }\n\n return { toolMap, directToolNames, fileCheckpointer };\n }\n\n const localConfig = args.toolExecution?.local ?? {};\n\n if (shouldIncludeCodingTools(args.toolExecution)) {\n // Use the bundle factory when fileCheckpointing is on so we can\n // surface the checkpointer back to the caller — without this, the\n // execution-path tools each captured into a checkpointer that was\n // immediately discarded, making the public `fileCheckpointing`\n // config flag a silent no-op outside of direct\n // `createLocalCodingToolBundle()` use.\n if (\n localConfig.fileCheckpointing === true ||\n args.fileCheckpointer != null\n ) {\n const bundle = createLocalCodingToolBundle(localConfig, {\n checkpointer: args.fileCheckpointer,\n });\n fileCheckpointer = bundle.checkpointer;\n for (const localTool of bundle.tools) {\n toolMap.set(localTool.name, localTool);\n directToolNames.add(localTool.name);\n }\n } else {\n for (const localTool of createLocalCodingTools(localConfig)) {\n toolMap.set(localTool.name, localTool);\n directToolNames.add(localTool.name);\n }\n }\n }\n\n // When the coding-tool bundle was already installed above, it\n // already created `bash_tool` / `execute_code` / programmatic-tool\n // variants. Skip re-creating them here — the audit-of-audit (manual\n // finding #4) flagged that the original loop overwrote those bundle\n // instances with fresh ones via `createLocalExecutionTool`, wasting\n // work and (more importantly) replacing tools the bundle had\n // already wired up with shared state. The CODE_EXECUTION_TOOLS\n // loop is now only relevant when the host pre-bound a tool with\n // one of these names (the `toolMap.has(name)` branch) and coding\n // tools are off.\n const includeCodingTools = shouldIncludeCodingTools(args.toolExecution);\n for (const name of CODE_EXECUTION_TOOLS) {\n if (includeCodingTools) continue;\n if (!toolMap.has(name)) continue;\n\n const localTool = createLocalExecutionTool(name, localConfig);\n if (localTool == null) {\n continue;\n }\n\n toolMap.set(name, localTool);\n directToolNames.add(name);\n }\n\n return { toolMap, directToolNames, fileCheckpointer };\n}\n"],"names":["LOCAL_CODING_BUNDLE_NAMES","Constants","createLocalCodeExecutionTool","createLocalBashExecutionTool","createLocalProgrammaticToolCallingTool","createLocalBashProgrammaticToolCallingTool","createCloudflareCodingTools","CODE_EXECUTION_TOOLS","createCloudflareExecutionTool","createLocalCodingTools","createLocalCodingToolDefinitions","createCloudflareCodingToolBundle","createLocalCodingToolBundle"],"mappings":";;;;;;;;;;;;;AAyCA,SAAS,uBAAuB,CAAC,MAA8B,EAAA;AAC7D,IAAA,OAAO,MAAM,EAAE,MAAM,KAAK,OAAO;AACnC;AAEA,SAAS,mCAAmC,CAC1C,MAA8B,EAAA;AAE9B,IAAA,OAAO,MAAM,EAAE,MAAM,KAAK,oBAAoB;AAChD;AAEA,SAAS,wBAAwB,CAAC,MAA8B,EAAA;AAC9D,IAAA,QACE,CAAC,uBAAuB,CAAC,MAAM,CAAC;AAC9B,QAAA,MAAM,EAAE,KAAK,EAAE,kBAAkB,KAAK,KAAK;SAC5C,mCAAmC,CAAC,MAAM,CAAC;YAC1C,MAAM,EAAE,UAAU,EAAE,kBAAkB,KAAK,KAAK,CAAC;AAEvD;AAEA,SAAS,mBAAmB,CAC1B,MAA8B,EAAA;AAE9B,IAAA,IAAI,MAAM,EAAE,UAAU,IAAI,IAAI,EAAE;AAC9B,QAAA,MAAM,IAAI,KAAK,CACb,2EAA2E,CAC5E;IACH;IACA,OAAO,MAAM,CAAC,UAAU;AAC1B;AAEA,SAAS,oCAAoC,CAC3C,MAA0C,EAAA;IAE1C,OAAO,IAAI,GAAG,CAAC,MAAM,CAAC,eAAe,IAAIA,+BAAyB,CAAC;AACrE;AAEA,SAAS,mCAAmC,CAC1C,KAA+B,EAC/B,aAA0B,EAAA;AAE1B,IAAA,MAAM,aAAa,GAAI,KAAqC,IAAI,EAAE;AAClE,IAAA,IAAI,aAAa,CAAC,MAAM,KAAK,CAAC,EAAE;AAC9B,QAAA,OAAO,KAAK;IACd;AACA,IAAA,OAAO,aAAa,CAAC,MAAM,CAAC,CAAC,YAAY,KAAI;AAC3C,QAAA,IAAI,EAAE,MAAM,IAAI,YAA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