@codebolt/agent 6.1.20 → 6.1.22
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/README.md +1 -0
- package/dist/processor-pieces/messageModifiers/argumentProcessorModifier.js +11 -15
- package/dist/processor-pieces/messageModifiers/atFileProcessorModifier.d.ts +0 -1
- package/dist/processor-pieces/messageModifiers/atFileProcessorModifier.js +16 -33
- package/dist/processor-pieces/messageModifiers/capabilityContextModifier.js +3 -2
- package/dist/processor-pieces/messageModifiers/chatHistoryMessageModifier.d.ts +8 -0
- package/dist/processor-pieces/messageModifiers/chatHistoryMessageModifier.js +150 -27
- package/dist/processor-pieces/messageModifiers/chatRecordingModifier.js +3 -3
- package/dist/processor-pieces/messageModifiers/contextAssemblyModifier.js +18 -12
- package/dist/processor-pieces/messageModifiers/directoryContextModifier.d.ts +1 -0
- package/dist/processor-pieces/messageModifiers/directoryContextModifier.js +15 -15
- package/dist/processor-pieces/messageModifiers/environmentContextModifier.d.ts +1 -0
- package/dist/processor-pieces/messageModifiers/environmentContextModifier.js +48 -2
- package/dist/processor-pieces/messageModifiers/ideContextModifier.js +3 -2
- package/dist/processor-pieces/messageModifiers/index.d.ts +1 -0
- package/dist/processor-pieces/messageModifiers/index.js +3 -1
- package/dist/processor-pieces/messageModifiers/memoryImportModifier.js +9 -15
- package/dist/processor-pieces/messageModifiers/toolInjectionModifier.js +17 -20
- package/dist/processor-pieces/messageModifiers/toolManifestPromptModifier.d.ts +18 -0
- package/dist/processor-pieces/messageModifiers/toolManifestPromptModifier.js +57 -0
- package/dist/processor-pieces/postInferenceProcessors/loopDetectionModifier.js +8 -19
- package/dist/processor-pieces/postToolCallProcessors/conversationCompactorModifier.d.ts +1 -1
- package/dist/processor-pieces/postToolCallProcessors/conversationCompactorModifier.js +28 -20
- package/dist/processor-pieces/postToolCallProcessors/shellProcessorModifier.js +3 -3
- package/dist/processor-pieces/preInferenceProcessors/chatCompressionModifier.js +2 -2
- package/dist/processor-pieces/utils/messageModifierHelper.js +3 -3
- package/dist/types/libFunctionTypes.d.ts +139 -7
- package/dist/unified/agent/agent.d.ts +13 -0
- package/dist/unified/agent/agent.js +180 -19
- package/dist/unified/agent/tools.d.ts +14 -0
- package/dist/unified/agent/tools.js +82 -51
- package/dist/unified/base/agentStep.d.ts +2 -1
- package/dist/unified/base/agentStep.js +47 -16
- package/dist/unified/base/initialPromptGenerator.d.ts +2 -0
- package/dist/unified/base/initialPromptGenerator.js +42 -19
- package/dist/unified/base/promptContext.d.ts +3 -0
- package/dist/unified/base/promptContext.js +193 -15
- package/dist/unified/base/responseExecutor.d.ts +6 -0
- package/dist/unified/base/responseExecutor.js +256 -69
- package/dist/unified/index.d.ts +1 -0
- package/dist/unified/index.js +3 -1
- package/dist/unified/services/CompressionCoordinator.js +9 -9
- package/dist/unified/services/compaction/autoCompact.d.ts +2 -1
- package/dist/unified/services/compaction/autoCompact.js +19 -11
- package/dist/unified/services/compaction/compactionOrchestrator.d.ts +1 -0
- package/dist/unified/services/compaction/compactionOrchestrator.js +8 -0
- package/dist/unified/services/compaction/contextCollapse.d.ts +2 -1
- package/dist/unified/services/compaction/contextCollapse.js +17 -9
- package/dist/unified/services/compaction/reactiveCompact.d.ts +3 -0
- package/dist/unified/services/compaction/reactiveCompact.js +17 -8
- package/dist/unified/types/libTypes.d.ts +189 -10
- package/dist/unified/utils/agentToolLoader.d.ts +17 -1
- package/dist/unified/utils/agentToolLoader.js +182 -31
- package/package.json +5 -1
|
@@ -7,11 +7,14 @@ exports.LocalToolConfigurationError = void 0;
|
|
|
7
7
|
exports.normalizeToolForModel = normalizeToolForModel;
|
|
8
8
|
exports.resolveToolExecutionName = resolveToolExecutionName;
|
|
9
9
|
exports.normalizeToolResponse = normalizeToolResponse;
|
|
10
|
+
exports.normalizeRuntimeToolResponse = normalizeRuntimeToolResponse;
|
|
10
11
|
exports.mergeTools = mergeTools;
|
|
12
|
+
exports.mergeRuntimeTools = mergeRuntimeTools;
|
|
11
13
|
exports.createAgentLocalToolRegistry = createAgentLocalToolRegistry;
|
|
12
14
|
exports.assertNoLocalToolSchemaCollisions = assertNoLocalToolSchemaCollisions;
|
|
13
15
|
exports.listProjectLocalTools = listProjectLocalTools;
|
|
14
16
|
exports.listAgentAvailableTools = listAgentAvailableTools;
|
|
17
|
+
exports.listAgentRuntimeTools = listAgentRuntimeTools;
|
|
15
18
|
exports.appendUniqueTools = appendUniqueTools;
|
|
16
19
|
const codeboltjs_1 = __importDefault(require("@codebolt/codeboltjs"));
|
|
17
20
|
const MODEL_TOOL_NAME_PATTERN = /^[a-zA-Z0-9_-]+$/;
|
|
@@ -30,7 +33,90 @@ function isTool(value) {
|
|
|
30
33
|
return false;
|
|
31
34
|
}
|
|
32
35
|
const candidate = value;
|
|
33
|
-
return candidate.type === 'function' &&
|
|
36
|
+
return candidate.type === 'function' &&
|
|
37
|
+
typeof ((_a = candidate.function) === null || _a === void 0 ? void 0 : _a.name) === 'string' &&
|
|
38
|
+
candidate.function.name.trim().length > 0;
|
|
39
|
+
}
|
|
40
|
+
function getToolName(tool) {
|
|
41
|
+
var _a, _b;
|
|
42
|
+
return ((_b = (_a = tool.function) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.trim()) || '';
|
|
43
|
+
}
|
|
44
|
+
function splitQualifiedToolName(toolName) {
|
|
45
|
+
const separatorIndex = toolName.indexOf('--');
|
|
46
|
+
if (separatorIndex === -1) {
|
|
47
|
+
return { toolName };
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
sourceId: toolName.slice(0, separatorIndex),
|
|
51
|
+
toolName: toolName.slice(separatorIndex + 2),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function inferSourceType(sourceId) {
|
|
55
|
+
if (sourceId === 'codebolt') {
|
|
56
|
+
return 'built-in';
|
|
57
|
+
}
|
|
58
|
+
if (sourceId === 'agent-local') {
|
|
59
|
+
return 'agent-local';
|
|
60
|
+
}
|
|
61
|
+
if (sourceId.startsWith('local/')) {
|
|
62
|
+
return 'project-local';
|
|
63
|
+
}
|
|
64
|
+
if (sourceId.startsWith('plugin:')) {
|
|
65
|
+
return 'plugin';
|
|
66
|
+
}
|
|
67
|
+
return 'mcp';
|
|
68
|
+
}
|
|
69
|
+
function deriveBuiltInNamespace(toolName) {
|
|
70
|
+
const dottedNamespace = toolName.split('.')[0];
|
|
71
|
+
if (dottedNamespace && dottedNamespace !== toolName) {
|
|
72
|
+
return dottedNamespace;
|
|
73
|
+
}
|
|
74
|
+
return toolName.split('_')[0] || 'codebolt';
|
|
75
|
+
}
|
|
76
|
+
function deriveNamespace(toolName, sourceType, sourceId) {
|
|
77
|
+
const parsed = splitQualifiedToolName(toolName);
|
|
78
|
+
if (parsed.sourceId && parsed.sourceId !== 'codebolt') {
|
|
79
|
+
return parsed.sourceId;
|
|
80
|
+
}
|
|
81
|
+
if (sourceType === 'built-in') {
|
|
82
|
+
return deriveBuiltInNamespace(parsed.toolName);
|
|
83
|
+
}
|
|
84
|
+
return parsed.sourceId || sourceId || parsed.toolName;
|
|
85
|
+
}
|
|
86
|
+
function toolToRuntimeDescriptor(tool, fallbackSourceType, fallbackSourceId) {
|
|
87
|
+
var _a, _b;
|
|
88
|
+
const parsed = splitQualifiedToolName(getToolName(tool));
|
|
89
|
+
const sourceId = parsed.sourceId || fallbackSourceId || 'codebolt';
|
|
90
|
+
const sourceType = fallbackSourceType || inferSourceType(sourceId);
|
|
91
|
+
return {
|
|
92
|
+
name: getToolName(tool),
|
|
93
|
+
toolName: parsed.toolName,
|
|
94
|
+
namespace: deriveNamespace(getToolName(tool), sourceType, sourceId),
|
|
95
|
+
sourceType,
|
|
96
|
+
sourceId,
|
|
97
|
+
displayName: parsed.toolName,
|
|
98
|
+
description: ((_a = tool.function) === null || _a === void 0 ? void 0 : _a.description) || '',
|
|
99
|
+
inputSchema: ((_b = tool.function) === null || _b === void 0 ? void 0 : _b.parameters) || { type: 'object', properties: {} },
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
function isRuntimeToolDescriptor(value) {
|
|
103
|
+
const candidate = value;
|
|
104
|
+
return !!candidate &&
|
|
105
|
+
typeof candidate.name === 'string' &&
|
|
106
|
+
typeof candidate.toolName === 'string';
|
|
107
|
+
}
|
|
108
|
+
function runtimeDescriptorToTool(tool) {
|
|
109
|
+
return normalizeToolForModel({
|
|
110
|
+
type: 'function',
|
|
111
|
+
function: {
|
|
112
|
+
name: tool.name,
|
|
113
|
+
description: tool.description || '',
|
|
114
|
+
parameters: tool.inputSchema || { type: 'object', properties: {} },
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
function compareToolsByName(leftTool, rightTool) {
|
|
119
|
+
return getToolName(leftTool).localeCompare(getToolName(rightTool));
|
|
34
120
|
}
|
|
35
121
|
function hashString(value) {
|
|
36
122
|
let hash = 0;
|
|
@@ -49,9 +135,9 @@ function normalizeToolForModel(tool) {
|
|
|
49
135
|
if (!MODEL_TOOL_NAME_PATTERN.test(originalName)) {
|
|
50
136
|
const separatorIndex = originalName.indexOf('--');
|
|
51
137
|
if (originalName.startsWith(LOCAL_TOOL_PREFIX) && separatorIndex > LOCAL_TOOL_PREFIX.length) {
|
|
52
|
-
const
|
|
138
|
+
const namespaceName = originalName.slice(LOCAL_TOOL_PREFIX.length, separatorIndex);
|
|
53
139
|
const actualToolName = originalName.slice(separatorIndex + 2);
|
|
54
|
-
modelName = `local_${sanitizeToolNamePart(
|
|
140
|
+
modelName = `local_${sanitizeToolNamePart(namespaceName)}--${sanitizeToolNamePart(actualToolName)}`;
|
|
55
141
|
}
|
|
56
142
|
else {
|
|
57
143
|
modelName = sanitizeToolNamePart(originalName);
|
|
@@ -85,18 +171,53 @@ function normalizeToolResponse(response) {
|
|
|
85
171
|
: [];
|
|
86
172
|
return tools.filter(isTool).map(normalizeToolForModel);
|
|
87
173
|
}
|
|
174
|
+
function normalizeRuntimeToolResponse(response) {
|
|
175
|
+
const data = response === null || response === void 0 ? void 0 : response.data;
|
|
176
|
+
const tools = Array.isArray(data === null || data === void 0 ? void 0 : data.tools)
|
|
177
|
+
? data.tools
|
|
178
|
+
: Array.isArray(data)
|
|
179
|
+
? data
|
|
180
|
+
: [];
|
|
181
|
+
return tools
|
|
182
|
+
.map((tool) => {
|
|
183
|
+
if (isRuntimeToolDescriptor(tool)) {
|
|
184
|
+
const sourceType = tool.sourceType || (tool.sourceId ? inferSourceType(tool.sourceId) : 'unknown');
|
|
185
|
+
return {
|
|
186
|
+
...tool,
|
|
187
|
+
namespace: tool.namespace || deriveNamespace(tool.name, sourceType, tool.sourceId),
|
|
188
|
+
sourceType,
|
|
189
|
+
inputSchema: tool.inputSchema || { type: 'object', properties: {} },
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
if (isTool(tool)) {
|
|
193
|
+
return toolToRuntimeDescriptor(normalizeToolForModel(tool));
|
|
194
|
+
}
|
|
195
|
+
return undefined;
|
|
196
|
+
})
|
|
197
|
+
.filter((tool) => !!tool);
|
|
198
|
+
}
|
|
88
199
|
function mergeTools(...toolGroups) {
|
|
89
|
-
var _a;
|
|
90
200
|
const mergedTools = new Map();
|
|
91
201
|
for (const tools of toolGroups) {
|
|
92
202
|
for (const tool of tools) {
|
|
93
|
-
const toolName = (
|
|
203
|
+
const toolName = getToolName(tool);
|
|
94
204
|
if (toolName && !mergedTools.has(toolName)) {
|
|
95
205
|
mergedTools.set(toolName, tool);
|
|
96
206
|
}
|
|
97
207
|
}
|
|
98
208
|
}
|
|
99
|
-
return Array.from(mergedTools.values());
|
|
209
|
+
return Array.from(mergedTools.values()).sort(compareToolsByName);
|
|
210
|
+
}
|
|
211
|
+
function mergeRuntimeTools(...toolGroups) {
|
|
212
|
+
const mergedTools = new Map();
|
|
213
|
+
for (const tools of toolGroups) {
|
|
214
|
+
for (const tool of tools) {
|
|
215
|
+
if (tool.name && !mergedTools.has(tool.name)) {
|
|
216
|
+
mergedTools.set(tool.name, tool);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return Array.from(mergedTools.values()).sort((left, right) => left.name.localeCompare(right.name));
|
|
100
221
|
}
|
|
101
222
|
function isAgentLocalTool(value) {
|
|
102
223
|
if (!value || typeof value !== 'object') {
|
|
@@ -150,50 +271,80 @@ function assertNoLocalToolSchemaCollisions(localSchemas, externalSchemas) {
|
|
|
150
271
|
}
|
|
151
272
|
}
|
|
152
273
|
async function listProjectLocalTools() {
|
|
153
|
-
const
|
|
154
|
-
if (typeof
|
|
155
|
-
|
|
274
|
+
const tools = codeboltjs_1.default.tools;
|
|
275
|
+
if (typeof (tools === null || tools === void 0 ? void 0 : tools.listExternalTools) === 'function') {
|
|
276
|
+
try {
|
|
277
|
+
return normalizeRuntimeToolResponse(await tools.listExternalTools())
|
|
278
|
+
.map(runtimeDescriptorToTool);
|
|
279
|
+
}
|
|
280
|
+
catch (error) {
|
|
281
|
+
console.error('[AgentToolLoader] Failed to load external tools:', error);
|
|
282
|
+
}
|
|
156
283
|
}
|
|
157
|
-
|
|
158
|
-
|
|
284
|
+
return [];
|
|
285
|
+
}
|
|
286
|
+
function getMentionedNamespace(value) {
|
|
287
|
+
if (typeof value === 'string') {
|
|
288
|
+
return value;
|
|
159
289
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
return [];
|
|
290
|
+
if (!value || typeof value !== 'object') {
|
|
291
|
+
return undefined;
|
|
163
292
|
}
|
|
293
|
+
const candidate = value;
|
|
294
|
+
return typeof candidate.namespace === 'string'
|
|
295
|
+
? candidate.namespace
|
|
296
|
+
: typeof candidate.sourceId === 'string'
|
|
297
|
+
? candidate.sourceId
|
|
298
|
+
: undefined;
|
|
164
299
|
}
|
|
165
|
-
async function listAgentAvailableTools(
|
|
300
|
+
async function listAgentAvailableTools(mentionedNamespaces = []) {
|
|
166
301
|
let codeboltTools = [];
|
|
167
302
|
let mentionedTools = [];
|
|
303
|
+
const toolGateway = codeboltjs_1.default.tools;
|
|
168
304
|
try {
|
|
169
|
-
|
|
305
|
+
if (typeof (toolGateway === null || toolGateway === void 0 ? void 0 : toolGateway.listBuiltInTools) === 'function') {
|
|
306
|
+
codeboltTools = normalizeRuntimeToolResponse(await toolGateway.listBuiltInTools())
|
|
307
|
+
.map(runtimeDescriptorToTool);
|
|
308
|
+
}
|
|
170
309
|
}
|
|
171
310
|
catch (error) {
|
|
172
311
|
console.error('[AgentToolLoader] Failed to load CodeBolt tools:', error);
|
|
173
312
|
}
|
|
174
313
|
const localTools = await listProjectLocalTools();
|
|
175
|
-
if (
|
|
314
|
+
if (mentionedNamespaces.length > 0 && typeof (toolGateway === null || toolGateway === void 0 ? void 0 : toolGateway.listToolsByNamespace) === 'function') {
|
|
176
315
|
try {
|
|
177
|
-
const
|
|
178
|
-
|
|
316
|
+
const namespaceTools = await Promise.all(mentionedNamespaces
|
|
317
|
+
.map(getMentionedNamespace)
|
|
318
|
+
.filter((namespace) => typeof namespace === 'string' && namespace.length > 0)
|
|
319
|
+
.map(namespace => toolGateway.listToolsByNamespace(namespace)));
|
|
320
|
+
mentionedTools = namespaceTools
|
|
321
|
+
.flatMap(response => normalizeRuntimeToolResponse(response))
|
|
322
|
+
.map(runtimeDescriptorToTool);
|
|
179
323
|
}
|
|
180
324
|
catch (error) {
|
|
181
|
-
console.error('[AgentToolLoader] Failed to load mentioned
|
|
325
|
+
console.error('[AgentToolLoader] Failed to load mentioned namespace tools:', error);
|
|
182
326
|
}
|
|
183
327
|
}
|
|
184
328
|
return mergeTools(codeboltTools, localTools, mentionedTools);
|
|
185
329
|
}
|
|
186
|
-
function
|
|
187
|
-
|
|
188
|
-
const
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
330
|
+
async function listAgentRuntimeTools(localTools = []) {
|
|
331
|
+
const toolGateway = codeboltjs_1.default.tools;
|
|
332
|
+
const agentLocalSchemas = localTools.map(localTool => normalizeToolForModel(localTool.toOpenAITool()));
|
|
333
|
+
if (typeof (toolGateway === null || toolGateway === void 0 ? void 0 : toolGateway.listRuntimeTools) === 'function') {
|
|
334
|
+
try {
|
|
335
|
+
return normalizeRuntimeToolResponse(await toolGateway.listRuntimeTools({
|
|
336
|
+
agentLocalTools: agentLocalSchemas,
|
|
337
|
+
}));
|
|
338
|
+
}
|
|
339
|
+
catch (error) {
|
|
340
|
+
console.error('[AgentToolLoader] Failed to load runtime tool descriptors:', error);
|
|
195
341
|
}
|
|
196
|
-
targetTools.push(tool);
|
|
197
|
-
existingToolNames.add(toolName);
|
|
198
342
|
}
|
|
343
|
+
const runtimeTools = (await listAgentAvailableTools()).map(tool => toolToRuntimeDescriptor(tool));
|
|
344
|
+
const agentLocalRuntimeTools = agentLocalSchemas.map(tool => toolToRuntimeDescriptor(tool, 'agent-local', 'agent-local'));
|
|
345
|
+
return mergeRuntimeTools(runtimeTools, agentLocalRuntimeTools);
|
|
346
|
+
}
|
|
347
|
+
function appendUniqueTools(targetTools, toolsToAppend) {
|
|
348
|
+
const mergedTools = mergeTools(targetTools, toolsToAppend);
|
|
349
|
+
targetTools.splice(0, targetTools.length, ...mergedTools);
|
|
199
350
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codebolt/agent",
|
|
3
|
-
"version": "6.1.
|
|
3
|
+
"version": "6.1.22",
|
|
4
4
|
"description": "CodeBolt Agent utilities for building and managing AI agents",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -72,6 +72,10 @@
|
|
|
72
72
|
"./unified": {
|
|
73
73
|
"types": "./dist/unified/index.d.ts",
|
|
74
74
|
"default": "./dist/unified/index.js"
|
|
75
|
+
},
|
|
76
|
+
"./unified/tools": {
|
|
77
|
+
"types": "./dist/unified/agent/tools.d.ts",
|
|
78
|
+
"default": "./dist/unified/agent/tools.js"
|
|
75
79
|
}
|
|
76
80
|
}
|
|
77
81
|
}
|