@codebolt/agent 6.1.21 → 6.1.23
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/chatHistoryMessageModifier.d.ts +2 -1
- package/dist/processor-pieces/messageModifiers/chatHistoryMessageModifier.js +24 -9
- package/dist/processor-pieces/messageModifiers/index.d.ts +1 -0
- package/dist/processor-pieces/messageModifiers/index.js +3 -1
- package/dist/processor-pieces/messageModifiers/toolManifestPromptModifier.d.ts +18 -0
- package/dist/processor-pieces/messageModifiers/toolManifestPromptModifier.js +57 -0
- package/dist/processor-pieces/postToolCallProcessors/conversationCompactorModifier.js +13 -5
- package/dist/types/libFunctionTypes.d.ts +147 -10
- package/dist/types/socketMessageTypes.d.ts +10 -2
- package/dist/unified/agent/agent.d.ts +3 -0
- package/dist/unified/agent/agent.js +14 -4
- package/dist/unified/base/agentStep.d.ts +1 -1
- package/dist/unified/base/agentStep.js +8 -5
- package/dist/unified/base/initialPromptGenerator.js +2 -1
- package/dist/unified/base/responseExecutor.js +49 -26
- package/dist/unified/index.d.ts +1 -0
- package/dist/unified/index.js +3 -1
- package/dist/unified/services/compaction/autoCompact.d.ts +2 -1
- package/dist/unified/services/compaction/autoCompact.js +14 -6
- 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 +15 -7
- package/dist/unified/services/compaction/reactiveCompact.d.ts +3 -0
- package/dist/unified/services/compaction/reactiveCompact.js +12 -3
- package/dist/unified/types/libTypes.d.ts +187 -14
- package/dist/unified/utils/agentToolLoader.d.ts +17 -1
- package/dist/unified/utils/agentToolLoader.js +166 -20
- package/package.json +1 -1
|
@@ -5,6 +5,19 @@ type ToolResponse = {
|
|
|
5
5
|
tools?: unknown;
|
|
6
6
|
} | unknown;
|
|
7
7
|
};
|
|
8
|
+
export type ToolSourceType = 'built-in' | 'mcp' | 'plugin' | 'project-local' | 'agent-local' | 'unknown';
|
|
9
|
+
export interface RuntimeToolDescriptor {
|
|
10
|
+
name: string;
|
|
11
|
+
toolName: string;
|
|
12
|
+
namespace: string;
|
|
13
|
+
sourceType: ToolSourceType;
|
|
14
|
+
sourceId?: string;
|
|
15
|
+
displayName?: string;
|
|
16
|
+
description?: string;
|
|
17
|
+
inputSchema: Record<string, unknown>;
|
|
18
|
+
outputSchema?: Record<string, unknown>;
|
|
19
|
+
metadata?: Record<string, unknown>;
|
|
20
|
+
}
|
|
8
21
|
export declare class LocalToolConfigurationError extends Error {
|
|
9
22
|
constructor(message: string);
|
|
10
23
|
}
|
|
@@ -15,10 +28,13 @@ export interface AgentLocalToolRegistry {
|
|
|
15
28
|
export declare function normalizeToolForModel(tool: Tool): Tool;
|
|
16
29
|
export declare function resolveToolExecutionName(modelToolName: string): string;
|
|
17
30
|
export declare function normalizeToolResponse(response: ToolResponse | undefined): Tool[];
|
|
31
|
+
export declare function normalizeRuntimeToolResponse(response: ToolResponse | undefined): RuntimeToolDescriptor[];
|
|
18
32
|
export declare function mergeTools(...toolGroups: Tool[][]): Tool[];
|
|
33
|
+
export declare function mergeRuntimeTools(...toolGroups: RuntimeToolDescriptor[][]): RuntimeToolDescriptor[];
|
|
19
34
|
export declare function createAgentLocalToolRegistry(localTools?: AgentLocalTool[]): AgentLocalToolRegistry;
|
|
20
35
|
export declare function assertNoLocalToolSchemaCollisions(localSchemas: Tool[], externalSchemas: Tool[]): void;
|
|
21
36
|
export declare function listProjectLocalTools(): Promise<Tool[]>;
|
|
22
|
-
export declare function listAgentAvailableTools(
|
|
37
|
+
export declare function listAgentAvailableTools(mentionedNamespaces?: unknown[]): Promise<Tool[]>;
|
|
38
|
+
export declare function listAgentRuntimeTools(localTools?: AgentLocalTool[]): Promise<RuntimeToolDescriptor[]>;
|
|
23
39
|
export declare function appendUniqueTools(targetTools: Tool[], toolsToAppend: Tool[]): void;
|
|
24
40
|
export {};
|
|
@@ -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_-]+$/;
|
|
@@ -38,6 +41,80 @@ function getToolName(tool) {
|
|
|
38
41
|
var _a, _b;
|
|
39
42
|
return ((_b = (_a = tool.function) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.trim()) || '';
|
|
40
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
|
+
}
|
|
41
118
|
function compareToolsByName(leftTool, rightTool) {
|
|
42
119
|
return getToolName(leftTool).localeCompare(getToolName(rightTool));
|
|
43
120
|
}
|
|
@@ -58,9 +135,9 @@ function normalizeToolForModel(tool) {
|
|
|
58
135
|
if (!MODEL_TOOL_NAME_PATTERN.test(originalName)) {
|
|
59
136
|
const separatorIndex = originalName.indexOf('--');
|
|
60
137
|
if (originalName.startsWith(LOCAL_TOOL_PREFIX) && separatorIndex > LOCAL_TOOL_PREFIX.length) {
|
|
61
|
-
const
|
|
138
|
+
const namespaceName = originalName.slice(LOCAL_TOOL_PREFIX.length, separatorIndex);
|
|
62
139
|
const actualToolName = originalName.slice(separatorIndex + 2);
|
|
63
|
-
modelName = `local_${sanitizeToolNamePart(
|
|
140
|
+
modelName = `local_${sanitizeToolNamePart(namespaceName)}--${sanitizeToolNamePart(actualToolName)}`;
|
|
64
141
|
}
|
|
65
142
|
else {
|
|
66
143
|
modelName = sanitizeToolNamePart(originalName);
|
|
@@ -94,6 +171,31 @@ function normalizeToolResponse(response) {
|
|
|
94
171
|
: [];
|
|
95
172
|
return tools.filter(isTool).map(normalizeToolForModel);
|
|
96
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
|
+
}
|
|
97
199
|
function mergeTools(...toolGroups) {
|
|
98
200
|
const mergedTools = new Map();
|
|
99
201
|
for (const tools of toolGroups) {
|
|
@@ -106,6 +208,17 @@ function mergeTools(...toolGroups) {
|
|
|
106
208
|
}
|
|
107
209
|
return Array.from(mergedTools.values()).sort(compareToolsByName);
|
|
108
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));
|
|
221
|
+
}
|
|
109
222
|
function isAgentLocalTool(value) {
|
|
110
223
|
if (!value || typeof value !== 'object') {
|
|
111
224
|
return false;
|
|
@@ -158,46 +271,79 @@ function assertNoLocalToolSchemaCollisions(localSchemas, externalSchemas) {
|
|
|
158
271
|
}
|
|
159
272
|
}
|
|
160
273
|
async function listProjectLocalTools() {
|
|
161
|
-
const
|
|
162
|
-
if (typeof
|
|
163
|
-
try {
|
|
164
|
-
return normalizeToolResponse(await mcp.getRegisteredTools());
|
|
165
|
-
}
|
|
166
|
-
catch (error) {
|
|
167
|
-
console.error('[AgentToolLoader] Failed to load registered MCP tools:', error);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
if (typeof mcp.getLocalMCPServers === 'function') {
|
|
274
|
+
const tools = codeboltjs_1.default.tools;
|
|
275
|
+
if (typeof (tools === null || tools === void 0 ? void 0 : tools.listExternalTools) === 'function') {
|
|
171
276
|
try {
|
|
172
|
-
return
|
|
277
|
+
return normalizeRuntimeToolResponse(await tools.listExternalTools())
|
|
278
|
+
.map(runtimeDescriptorToTool);
|
|
173
279
|
}
|
|
174
280
|
catch (error) {
|
|
175
|
-
console.error('[AgentToolLoader] Failed to load
|
|
281
|
+
console.error('[AgentToolLoader] Failed to load external tools:', error);
|
|
176
282
|
}
|
|
177
283
|
}
|
|
178
284
|
return [];
|
|
179
285
|
}
|
|
180
|
-
|
|
286
|
+
function getMentionedNamespace(value) {
|
|
287
|
+
if (typeof value === 'string') {
|
|
288
|
+
return value;
|
|
289
|
+
}
|
|
290
|
+
if (!value || typeof value !== 'object') {
|
|
291
|
+
return undefined;
|
|
292
|
+
}
|
|
293
|
+
const candidate = value;
|
|
294
|
+
return typeof candidate.namespace === 'string'
|
|
295
|
+
? candidate.namespace
|
|
296
|
+
: typeof candidate.sourceId === 'string'
|
|
297
|
+
? candidate.sourceId
|
|
298
|
+
: undefined;
|
|
299
|
+
}
|
|
300
|
+
async function listAgentAvailableTools(mentionedNamespaces = []) {
|
|
181
301
|
let codeboltTools = [];
|
|
182
302
|
let mentionedTools = [];
|
|
303
|
+
const toolGateway = codeboltjs_1.default.tools;
|
|
183
304
|
try {
|
|
184
|
-
|
|
305
|
+
if (typeof (toolGateway === null || toolGateway === void 0 ? void 0 : toolGateway.listBuiltInTools) === 'function') {
|
|
306
|
+
codeboltTools = normalizeRuntimeToolResponse(await toolGateway.listBuiltInTools())
|
|
307
|
+
.map(runtimeDescriptorToTool);
|
|
308
|
+
}
|
|
185
309
|
}
|
|
186
310
|
catch (error) {
|
|
187
311
|
console.error('[AgentToolLoader] Failed to load CodeBolt tools:', error);
|
|
188
312
|
}
|
|
189
313
|
const localTools = await listProjectLocalTools();
|
|
190
|
-
if (
|
|
314
|
+
if (mentionedNamespaces.length > 0 && typeof (toolGateway === null || toolGateway === void 0 ? void 0 : toolGateway.listToolsByNamespace) === 'function') {
|
|
191
315
|
try {
|
|
192
|
-
const
|
|
193
|
-
|
|
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);
|
|
194
323
|
}
|
|
195
324
|
catch (error) {
|
|
196
|
-
console.error('[AgentToolLoader] Failed to load mentioned
|
|
325
|
+
console.error('[AgentToolLoader] Failed to load mentioned namespace tools:', error);
|
|
197
326
|
}
|
|
198
327
|
}
|
|
199
328
|
return mergeTools(codeboltTools, localTools, mentionedTools);
|
|
200
329
|
}
|
|
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);
|
|
341
|
+
}
|
|
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
|
+
}
|
|
201
347
|
function appendUniqueTools(targetTools, toolsToAppend) {
|
|
202
348
|
const mergedTools = mergeTools(targetTools, toolsToAppend);
|
|
203
349
|
targetTools.splice(0, targetTools.length, ...mergedTools);
|