@codebolt/agent 6.1.14 → 6.1.16

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.
@@ -1,11 +1,8 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.ToolInjectionModifier = void 0;
7
4
  const base_1 = require("../base");
8
- const codeboltjs_1 = __importDefault(require("@codebolt/codeboltjs"));
5
+ const agentToolLoader_1 = require("../../unified/utils/agentToolLoader");
9
6
  class ToolInjectionModifier extends base_1.BaseMessageModifier {
10
7
  constructor(options = {}) {
11
8
  super();
@@ -14,16 +11,16 @@ class ToolInjectionModifier extends base_1.BaseMessageModifier {
14
11
  includeToolDescriptions: options.includeToolDescriptions !== false,
15
12
  maxToolsInMessage: options.maxToolsInMessage || 30,
16
13
  giveToolExamples: options.giveToolExamples || false,
17
- maxToolExamples: options.maxToolExamples || 2
14
+ maxToolExamples: options.maxToolExamples || 2,
18
15
  };
16
+ if (options.allowedTools) {
17
+ this.options.allowedTools = options.allowedTools;
18
+ }
19
19
  }
20
20
  async modify(originalRequest, createdMessage) {
21
21
  try {
22
- const toolsResponse = await codeboltjs_1.default.mcp.listMcpFromServers(['codebolt']);
23
- let tools = (toolsResponse === null || toolsResponse === void 0 ? void 0 : toolsResponse.data.tools) || (toolsResponse === null || toolsResponse === void 0 ? void 0 : toolsResponse.data) || [];
24
22
  let mentionedMCPs = originalRequest.mentionedMCPs || [];
25
- const { data: mentionedTools } = await codeboltjs_1.default.mcp.getTools(mentionedMCPs);
26
- tools = [...tools, ...(mentionedTools || [])];
23
+ let tools = await (0, agentToolLoader_1.listAgentAvailableTools)(Array.isArray(mentionedMCPs) ? mentionedMCPs : []);
27
24
  // Filter tools if allowedTools is specified
28
25
  if (this.options.allowedTools && this.options.allowedTools.length > 0) {
29
26
  tools = tools.filter((tool) => this.options.allowedTools.includes(tool.function.name));
@@ -20,7 +20,6 @@ export declare class Agent implements AgentInterface {
20
20
  private applyCompaction;
21
21
  private tryRecoverPrompt;
22
22
  private refreshAvailableTools;
23
- private mergeTools;
24
23
  private getAllowedToolNames;
25
24
  private getRecoverableResponseError;
26
25
  private collectResponseMessages;
@@ -1,15 +1,12 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.Agent = void 0;
7
- const codeboltjs_1 = __importDefault(require("@codebolt/codeboltjs"));
8
4
  const base_1 = require("../base");
9
5
  const agentStep_1 = require("../base/agentStep");
10
6
  const responseExecutor_1 = require("../base/responseExecutor");
11
7
  const promptContext_1 = require("../base/promptContext");
12
8
  const compactionOrchestrator_1 = require("../services/compaction/compactionOrchestrator");
9
+ const agentToolLoader_1 = require("../utils/agentToolLoader");
13
10
  class Agent {
14
11
  constructor(config) {
15
12
  var _a, _b, _c, _d, _e, _f;
@@ -157,7 +154,7 @@ class Agent {
157
154
  };
158
155
  }
159
156
  async refreshAvailableTools(originalRequest, prompt) {
160
- var _a, _b, _c, _d;
157
+ var _a, _b, _c;
161
158
  if (((_a = prompt.metadata) === null || _a === void 0 ? void 0 : _a['toolsInjected']) !== true ||
162
159
  ((_b = prompt.metadata) === null || _b === void 0 ? void 0 : _b['toolsLocation']) !== 'Tool') {
163
160
  return prompt;
@@ -166,28 +163,23 @@ class Agent {
166
163
  ? prompt.message.tools
167
164
  : [];
168
165
  try {
169
- const toolsResponse = await codeboltjs_1.default.mcp.listMcpFromServers(['codebolt']);
170
- let refreshedTools = ((_c = toolsResponse === null || toolsResponse === void 0 ? void 0 : toolsResponse.data) === null || _c === void 0 ? void 0 : _c.tools) || (toolsResponse === null || toolsResponse === void 0 ? void 0 : toolsResponse.data) || [];
171
166
  const mentionedMCPs = Array.isArray(originalRequest.mentionedMCPs)
172
167
  ? originalRequest.mentionedMCPs
173
168
  : [];
174
- if (mentionedMCPs.length > 0) {
175
- const { data: mentionedTools } = await codeboltjs_1.default.mcp.getTools(mentionedMCPs);
176
- refreshedTools = [...refreshedTools, ...(mentionedTools || [])];
177
- }
169
+ let refreshedTools = await (0, agentToolLoader_1.listAgentAvailableTools)(mentionedMCPs);
178
170
  const allowedToolNames = this.getAllowedToolNames(prompt);
179
171
  if (allowedToolNames && allowedToolNames.length > 0) {
180
172
  const allowed = new Set(allowedToolNames);
181
173
  refreshedTools = refreshedTools.filter((tool) => { var _a; return !!((_a = tool.function) === null || _a === void 0 ? void 0 : _a.name) && allowed.has(tool.function.name); });
182
174
  }
183
- const mergedTools = this.mergeTools(existingTools, refreshedTools);
175
+ const mergedTools = (0, agentToolLoader_1.mergeTools)(refreshedTools, existingTools);
184
176
  return {
185
177
  ...prompt,
186
178
  message: {
187
179
  ...prompt.message,
188
180
  tools: mergedTools,
189
181
  ...(mergedTools.length > 0
190
- ? { tool_choice: (_d = prompt.message.tool_choice) !== null && _d !== void 0 ? _d : 'auto' }
182
+ ? { tool_choice: (_c = prompt.message.tool_choice) !== null && _c !== void 0 ? _c : 'auto' }
191
183
  : {}),
192
184
  },
193
185
  metadata: {
@@ -204,23 +196,6 @@ class Agent {
204
196
  return prompt;
205
197
  }
206
198
  }
207
- mergeTools(existingTools, refreshedTools) {
208
- var _a, _b;
209
- const mergedTools = new Map();
210
- for (const tool of refreshedTools) {
211
- const toolName = (_a = tool.function) === null || _a === void 0 ? void 0 : _a.name;
212
- if (toolName) {
213
- mergedTools.set(toolName, tool);
214
- }
215
- }
216
- for (const tool of existingTools) {
217
- const toolName = (_b = tool.function) === null || _b === void 0 ? void 0 : _b.name;
218
- if (toolName && !mergedTools.has(toolName)) {
219
- mergedTools.set(toolName, tool);
220
- }
221
- }
222
- return Array.from(mergedTools.values());
223
- }
224
199
  getAllowedToolNames(prompt) {
225
200
  var _a;
226
201
  const metadataAllowedTools = (_a = prompt.metadata) === null || _a === void 0 ? void 0 : _a['allowedTools'];
@@ -43,7 +43,6 @@ export declare class CodeboltAgent {
43
43
  private applyCompaction;
44
44
  private tryRecoverPrompt;
45
45
  private refreshAvailableTools;
46
- private mergeTools;
47
46
  private getAllowedToolNames;
48
47
  private getRecoverableResponseError;
49
48
  private collectResponseMessages;
@@ -1,16 +1,13 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.CodeboltAgent = void 0;
7
4
  exports.createCodeboltAgent = createCodeboltAgent;
8
- const codeboltjs_1 = __importDefault(require("@codebolt/codeboltjs"));
9
5
  const base_1 = require("../base");
10
6
  const agentStep_1 = require("../base/agentStep");
11
7
  const responseExecutor_1 = require("../base/responseExecutor");
12
8
  const promptContext_1 = require("../base/promptContext");
13
9
  const compactionOrchestrator_1 = require("../services/compaction/compactionOrchestrator");
10
+ const agentToolLoader_1 = require("../utils/agentToolLoader");
14
11
  const processor_pieces_1 = require("../../processor-pieces");
15
12
  class CodeboltAgent {
16
13
  constructor(config) {
@@ -228,7 +225,7 @@ class CodeboltAgent {
228
225
  };
229
226
  }
230
227
  async refreshAvailableTools(originalRequest, prompt) {
231
- var _a, _b, _c, _d;
228
+ var _a, _b, _c;
232
229
  if (((_a = prompt.metadata) === null || _a === void 0 ? void 0 : _a['toolsInjected']) !== true ||
233
230
  ((_b = prompt.metadata) === null || _b === void 0 ? void 0 : _b['toolsLocation']) !== 'Tool') {
234
231
  return prompt;
@@ -237,28 +234,23 @@ class CodeboltAgent {
237
234
  ? prompt.message.tools
238
235
  : [];
239
236
  try {
240
- const toolsResponse = await codeboltjs_1.default.mcp.listMcpFromServers(['codebolt']);
241
- let refreshedTools = ((_c = toolsResponse === null || toolsResponse === void 0 ? void 0 : toolsResponse.data) === null || _c === void 0 ? void 0 : _c.tools) || (toolsResponse === null || toolsResponse === void 0 ? void 0 : toolsResponse.data) || [];
242
237
  const mentionedMCPs = Array.isArray(originalRequest.mentionedMCPs)
243
238
  ? originalRequest.mentionedMCPs
244
239
  : [];
245
- if (mentionedMCPs.length > 0) {
246
- const { data: mentionedTools } = await codeboltjs_1.default.mcp.getTools(mentionedMCPs);
247
- refreshedTools = [...refreshedTools, ...(mentionedTools || [])];
248
- }
240
+ let refreshedTools = await (0, agentToolLoader_1.listAgentAvailableTools)(mentionedMCPs);
249
241
  const allowedToolNames = this.getAllowedToolNames(prompt);
250
242
  if (allowedToolNames && allowedToolNames.length > 0) {
251
243
  const allowed = new Set(allowedToolNames);
252
244
  refreshedTools = refreshedTools.filter((tool) => { var _a; return !!((_a = tool.function) === null || _a === void 0 ? void 0 : _a.name) && allowed.has(tool.function.name); });
253
245
  }
254
- const mergedTools = this.mergeTools(existingTools, refreshedTools);
246
+ const mergedTools = (0, agentToolLoader_1.mergeTools)(refreshedTools, existingTools);
255
247
  return {
256
248
  ...prompt,
257
249
  message: {
258
250
  ...prompt.message,
259
251
  tools: mergedTools,
260
252
  ...(mergedTools.length > 0
261
- ? { tool_choice: (_d = prompt.message.tool_choice) !== null && _d !== void 0 ? _d : 'auto' }
253
+ ? { tool_choice: (_c = prompt.message.tool_choice) !== null && _c !== void 0 ? _c : 'auto' }
262
254
  : {}),
263
255
  },
264
256
  metadata: {
@@ -275,23 +267,6 @@ class CodeboltAgent {
275
267
  return prompt;
276
268
  }
277
269
  }
278
- mergeTools(existingTools, refreshedTools) {
279
- var _a, _b;
280
- const mergedTools = new Map();
281
- for (const tool of refreshedTools) {
282
- const toolName = (_a = tool.function) === null || _a === void 0 ? void 0 : _a.name;
283
- if (toolName) {
284
- mergedTools.set(toolName, tool);
285
- }
286
- }
287
- for (const tool of existingTools) {
288
- const toolName = (_b = tool.function) === null || _b === void 0 ? void 0 : _b.name;
289
- if (toolName && !mergedTools.has(toolName)) {
290
- mergedTools.set(toolName, tool);
291
- }
292
- }
293
- return Array.from(mergedTools.values());
294
- }
295
270
  getAllowedToolNames(prompt) {
296
271
  var _a;
297
272
  const metadataAllowedTools = (_a = prompt.metadata) === null || _a === void 0 ? void 0 : _a['allowedTools'];
@@ -63,7 +63,7 @@ class AgentStep {
63
63
  }
64
64
  }
65
65
  async generateResponse(messageForLLM) {
66
- var _a, _b;
66
+ var _a, _b, _c, _d;
67
67
  const response = await codeboltjs_1.default.llm.inference(messageForLLM);
68
68
  const completion = response.completion;
69
69
  // Add tokenLimit and maxOutputTokens to completion object if available in response
@@ -75,6 +75,12 @@ class AgentStep {
75
75
  if (response.maxOutputTokens !== undefined) {
76
76
  completion.maxOutputTokens = response.maxOutputTokens;
77
77
  }
78
+ if (response.contextCompaction !== undefined) {
79
+ completion.contextCompaction = response.contextCompaction;
80
+ }
81
+ if (response.compactionRequired !== undefined) {
82
+ completion.compactionRequired = response.compactionRequired;
83
+ }
78
84
  // Also check inside completion object itself (from LLM provider response)
79
85
  if (((_a = completion.completion) === null || _a === void 0 ? void 0 : _a.tokenLimit) !== undefined) {
80
86
  completion.tokenLimit = completion.completion.tokenLimit;
@@ -82,6 +88,12 @@ class AgentStep {
82
88
  if (((_b = completion.completion) === null || _b === void 0 ? void 0 : _b.maxOutputTokens) !== undefined) {
83
89
  completion.maxOutputTokens = completion.completion.maxOutputTokens;
84
90
  }
91
+ if (((_c = completion.completion) === null || _c === void 0 ? void 0 : _c.contextCompaction) !== undefined) {
92
+ completion.contextCompaction = completion.completion.contextCompaction;
93
+ }
94
+ if (((_d = completion.completion) === null || _d === void 0 ? void 0 : _d.compactionRequired) !== undefined) {
95
+ completion.compactionRequired = completion.completion.compactionRequired;
96
+ }
85
97
  }
86
98
  return completion;
87
99
  }
@@ -15,6 +15,8 @@ export declare class ResponseExecutor implements AgentResponseExecutor {
15
15
  private parseToolCall;
16
16
  private extractLastMessageContent;
17
17
  private getToolCalls;
18
+ private hasExecutableToolCalls;
19
+ private runRequiredCompaction;
18
20
  private executeTools;
19
21
  private sendFinalMessageToChat;
20
22
  private executeSingleToolCall;
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.ResponseExecutor = void 0;
7
7
  const codeboltjs_1 = __importDefault(require("@codebolt/codeboltjs"));
8
8
  const promptContext_1 = require("./promptContext");
9
+ const agentToolLoader_1 = require("../utils/agentToolLoader");
9
10
  class ResponseExecutor {
10
11
  constructor(options) {
11
12
  this.preToolCallProcessors = [];
@@ -38,10 +39,15 @@ class ResponseExecutor {
38
39
  console.error(`[ResponseExecutor] Error in pre tool call processor:`, error);
39
40
  }
40
41
  }
42
+ const compactionMessagePromise = this.runRequiredCompaction(input.rawLLMOutput);
41
43
  const toolExecution = await this.executeTools(input.rawLLMOutput);
44
+ const compactionCompleted = await compactionMessagePromise;
45
+ if (compactionCompleted) {
46
+ await Promise.resolve(codeboltjs_1.default.chat.sendMessage('Conversation Compacted'));
47
+ }
42
48
  this.completed = this.completed || toolExecution.completed;
43
49
  this.finalMessage = (_a = toolExecution.finalMessage) !== null && _a !== void 0 ? _a : this.finalMessage;
44
- this.injectDiscoveredTools(input.rawLLMOutput, toolExecution.toolResults, nextMessage);
50
+ await this.injectDiscoveredTools(input.rawLLMOutput, toolExecution.toolResults, nextMessage);
45
51
  if (toolExecution.toolResults.length > 0 || toolExecution.followUpMessages.length > 0) {
46
52
  nextMessage = (0, promptContext_1.appendTranscriptMessages)(nextMessage, [
47
53
  ...toolExecution.toolResults.map((toolResult) => ({
@@ -142,6 +148,33 @@ class ResponseExecutor {
142
148
  }
143
149
  return Array.from(toolCallsById.values());
144
150
  }
151
+ hasExecutableToolCalls(llmResponse) {
152
+ return this.getToolCalls(llmResponse).some((toolCall) => {
153
+ var _a;
154
+ const toolName = ((_a = toolCall.function) === null || _a === void 0 ? void 0 : _a.name) || '';
155
+ return !toolName.includes('attempt_completion') &&
156
+ !toolName.includes('context_compaction') &&
157
+ !toolName.includes('contextCompaction');
158
+ });
159
+ }
160
+ async runRequiredCompaction(llmResponse) {
161
+ var _a;
162
+ const decision = llmResponse.contextCompaction;
163
+ if (!(decision === null || decision === void 0 ? void 0 : decision.required) || decision.hasToolCalls === false || !this.hasExecutableToolCalls(llmResponse)) {
164
+ return false;
165
+ }
166
+ try {
167
+ await codeboltjs_1.default.contextCompaction.run({
168
+ ...(decision.runRequest || {}),
169
+ reason: String(((_a = decision.runRequest) === null || _a === void 0 ? void 0 : _a['reason']) || decision.reason || 'llm_response_tool_calls'),
170
+ });
171
+ return true;
172
+ }
173
+ catch (error) {
174
+ console.error('[ResponseExecutor] Context compaction failed:', error);
175
+ return false;
176
+ }
177
+ }
145
178
  async executeTools(llmResponse) {
146
179
  const lastMessageContent = this.extractLastMessageContent(llmResponse);
147
180
  const toolCalls = this.getToolCalls(llmResponse);
@@ -271,7 +304,8 @@ class ResponseExecutor {
271
304
  }
272
305
  async executeTool(toolName, toolInput) {
273
306
  var _a, _b, _c;
274
- const parts = toolName.split('--');
307
+ const executionToolName = (0, agentToolLoader_1.resolveToolExecutionName)(toolName);
308
+ const parts = executionToolName.split('--');
275
309
  const toolboxName = parts.length > 1 ? ((_a = parts[0]) !== null && _a !== void 0 ? _a : '') : 'codebolt';
276
310
  const actualToolName = parts.length > 1 ? ((_b = parts[1]) !== null && _b !== void 0 ? _b : '') : ((_c = parts[0]) !== null && _c !== void 0 ? _c : '');
277
311
  const { data } = await codeboltjs_1.default.mcp.executeTool(toolboxName, actualToolName, toolInput);
@@ -323,7 +357,7 @@ class ResponseExecutor {
323
357
  getPostToolCallProcessors() {
324
358
  return this.postToolCallProcessors;
325
359
  }
326
- injectDiscoveredTools(llmResponse, toolResults, nextMessage) {
360
+ async injectDiscoveredTools(llmResponse, toolResults, nextMessage) {
327
361
  var _a, _b;
328
362
  try {
329
363
  const toolCalls = this.getToolCalls(llmResponse);
@@ -335,9 +369,16 @@ class ResponseExecutor {
335
369
  const toolName = ((_b = toolCall.function) === null || _b === void 0 ? void 0 : _b.name) || '';
336
370
  const isToolSearch = toolName === 'tool_search' ||
337
371
  toolName === 'codebolt--tool_search' ||
338
- toolName.endsWith('--tool_search');
372
+ toolName.endsWith('--tool_search') ||
373
+ toolName === 'search_mcp_tool' ||
374
+ toolName === 'codebolt--search_mcp_tool' ||
375
+ toolName.endsWith('--search_mcp_tool') ||
376
+ toolName === 'codebase_search_mcp_tool' ||
377
+ toolName === 'codebolt--codebase_search_mcp_tool' ||
378
+ toolName.endsWith('--codebase_search_mcp_tool');
339
379
  if (!isToolSearch)
340
380
  continue;
381
+ (0, agentToolLoader_1.appendUniqueTools)(nextMessage.message.tools, await (0, agentToolLoader_1.listProjectLocalTools)());
341
382
  const toolCallId = toolCall.id;
342
383
  const toolResult = toolResults.find(r => r.tool_call_id === toolCallId);
343
384
  if (!(toolResult === null || toolResult === void 0 ? void 0 : toolResult.content))
@@ -363,7 +404,7 @@ class ResponseExecutor {
363
404
  const rawName = schemaFunction === null || schemaFunction === void 0 ? void 0 : schemaFunction.name;
364
405
  if (!rawName)
365
406
  continue;
366
- const prefixedName = rawName.startsWith('codebolt--') ? rawName : `codebolt--${rawName}`;
407
+ const prefixedName = rawName.includes('--') ? rawName : `codebolt--${rawName}`;
367
408
  if (existingToolNames.has(prefixedName))
368
409
  continue;
369
410
  const prefixedSchema = {
@@ -0,0 +1,14 @@
1
+ import type { Tool } from '@codebolt/types/sdk';
2
+ type ToolResponse = {
3
+ data?: {
4
+ tools?: unknown;
5
+ } | unknown;
6
+ };
7
+ export declare function normalizeToolForModel(tool: Tool): Tool;
8
+ export declare function resolveToolExecutionName(modelToolName: string): string;
9
+ export declare function normalizeToolResponse(response: ToolResponse | undefined): Tool[];
10
+ export declare function mergeTools(...toolGroups: Tool[][]): Tool[];
11
+ export declare function listProjectLocalTools(): Promise<Tool[]>;
12
+ export declare function listAgentAvailableTools(mentionedMCPs?: unknown[]): Promise<Tool[]>;
13
+ export declare function appendUniqueTools(targetTools: Tool[], toolsToAppend: Tool[]): void;
14
+ export {};
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.normalizeToolForModel = normalizeToolForModel;
7
+ exports.resolveToolExecutionName = resolveToolExecutionName;
8
+ exports.normalizeToolResponse = normalizeToolResponse;
9
+ exports.mergeTools = mergeTools;
10
+ exports.listProjectLocalTools = listProjectLocalTools;
11
+ exports.listAgentAvailableTools = listAgentAvailableTools;
12
+ exports.appendUniqueTools = appendUniqueTools;
13
+ const codeboltjs_1 = __importDefault(require("@codebolt/codeboltjs"));
14
+ const MODEL_TOOL_NAME_PATTERN = /^[a-zA-Z0-9_-]+$/;
15
+ const LOCAL_TOOL_PREFIX = 'local/';
16
+ const toolExecutionNameByModelName = new Map();
17
+ function isTool(value) {
18
+ var _a;
19
+ if (!value || typeof value !== 'object') {
20
+ return false;
21
+ }
22
+ const candidate = value;
23
+ return candidate.type === 'function' && typeof ((_a = candidate.function) === null || _a === void 0 ? void 0 : _a.name) === 'string';
24
+ }
25
+ function hashString(value) {
26
+ let hash = 0;
27
+ for (let index = 0; index < value.length; index += 1) {
28
+ hash = ((hash << 5) - hash + value.charCodeAt(index)) | 0;
29
+ }
30
+ return Math.abs(hash).toString(36);
31
+ }
32
+ function sanitizeToolNamePart(value) {
33
+ const sanitized = value.replace(/[^a-zA-Z0-9_-]/g, '_').replace(/_+/g, '_');
34
+ return sanitized.replace(/^_+|_+$/g, '') || 'tool';
35
+ }
36
+ function normalizeToolForModel(tool) {
37
+ const originalName = tool.function.name;
38
+ let modelName = originalName;
39
+ if (!MODEL_TOOL_NAME_PATTERN.test(originalName)) {
40
+ const separatorIndex = originalName.indexOf('--');
41
+ if (originalName.startsWith(LOCAL_TOOL_PREFIX) && separatorIndex > LOCAL_TOOL_PREFIX.length) {
42
+ const toolboxName = originalName.slice(LOCAL_TOOL_PREFIX.length, separatorIndex);
43
+ const actualToolName = originalName.slice(separatorIndex + 2);
44
+ modelName = `local_${sanitizeToolNamePart(toolboxName)}--${sanitizeToolNamePart(actualToolName)}`;
45
+ }
46
+ else {
47
+ modelName = sanitizeToolNamePart(originalName);
48
+ }
49
+ const mappedName = toolExecutionNameByModelName.get(modelName);
50
+ if (mappedName && mappedName !== originalName) {
51
+ modelName = `${modelName}_${hashString(originalName)}`;
52
+ }
53
+ toolExecutionNameByModelName.set(modelName, originalName);
54
+ }
55
+ if (modelName === originalName) {
56
+ return tool;
57
+ }
58
+ return {
59
+ ...tool,
60
+ function: {
61
+ ...tool.function,
62
+ name: modelName,
63
+ },
64
+ };
65
+ }
66
+ function resolveToolExecutionName(modelToolName) {
67
+ return toolExecutionNameByModelName.get(modelToolName) || modelToolName;
68
+ }
69
+ function normalizeToolResponse(response) {
70
+ const data = response === null || response === void 0 ? void 0 : response.data;
71
+ const tools = Array.isArray(data === null || data === void 0 ? void 0 : data.tools)
72
+ ? data.tools
73
+ : Array.isArray(data)
74
+ ? data
75
+ : [];
76
+ return tools.filter(isTool).map(normalizeToolForModel);
77
+ }
78
+ function mergeTools(...toolGroups) {
79
+ var _a;
80
+ const mergedTools = new Map();
81
+ for (const tools of toolGroups) {
82
+ for (const tool of tools) {
83
+ const toolName = (_a = tool.function) === null || _a === void 0 ? void 0 : _a.name;
84
+ if (toolName && !mergedTools.has(toolName)) {
85
+ mergedTools.set(toolName, tool);
86
+ }
87
+ }
88
+ }
89
+ return Array.from(mergedTools.values());
90
+ }
91
+ async function listProjectLocalTools() {
92
+ const mcp = codeboltjs_1.default.mcp;
93
+ if (typeof mcp.getLocalMCPServers !== 'function') {
94
+ return [];
95
+ }
96
+ try {
97
+ return normalizeToolResponse(await mcp.getLocalMCPServers());
98
+ }
99
+ catch (error) {
100
+ console.error('[AgentToolLoader] Failed to load project-local tools:', error);
101
+ return [];
102
+ }
103
+ }
104
+ async function listAgentAvailableTools(mentionedMCPs = []) {
105
+ let codeboltTools = [];
106
+ let mentionedTools = [];
107
+ try {
108
+ codeboltTools = normalizeToolResponse(await codeboltjs_1.default.mcp.listMcpFromServers(['codebolt']));
109
+ }
110
+ catch (error) {
111
+ console.error('[AgentToolLoader] Failed to load CodeBolt tools:', error);
112
+ }
113
+ const localTools = await listProjectLocalTools();
114
+ if (mentionedMCPs.length > 0) {
115
+ try {
116
+ const response = await codeboltjs_1.default.mcp.getTools(mentionedMCPs);
117
+ mentionedTools = normalizeToolResponse(response);
118
+ }
119
+ catch (error) {
120
+ console.error('[AgentToolLoader] Failed to load mentioned MCP tools:', error);
121
+ }
122
+ }
123
+ return mergeTools(codeboltTools, localTools, mentionedTools);
124
+ }
125
+ function appendUniqueTools(targetTools, toolsToAppend) {
126
+ var _a;
127
+ const existingToolNames = new Set(targetTools
128
+ .map((tool) => { var _a; return (_a = tool.function) === null || _a === void 0 ? void 0 : _a.name; })
129
+ .filter((toolName) => typeof toolName === 'string' && toolName.length > 0));
130
+ for (const tool of toolsToAppend) {
131
+ const toolName = (_a = tool.function) === null || _a === void 0 ? void 0 : _a.name;
132
+ if (!toolName || existingToolNames.has(toolName)) {
133
+ continue;
134
+ }
135
+ targetTools.push(tool);
136
+ existingToolNames.add(toolName);
137
+ }
138
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codebolt/agent",
3
- "version": "6.1.14",
3
+ "version": "6.1.16",
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",