@sowonai/crewx-cli 0.4.0-dev.1
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 +529 -0
- package/dist/ai-provider.service.d.ts +36 -0
- package/dist/ai-provider.service.js +191 -0
- package/dist/ai-provider.service.js.map +1 -0
- package/dist/ai.service.d.ts +57 -0
- package/dist/ai.service.js +628 -0
- package/dist/ai.service.js.map +1 -0
- package/dist/app.module.d.ts +5 -0
- package/dist/app.module.js +103 -0
- package/dist/app.module.js.map +1 -0
- package/dist/cli/agent.handler.d.ts +2 -0
- package/dist/cli/agent.handler.js +140 -0
- package/dist/cli/agent.handler.js.map +1 -0
- package/dist/cli/chat.handler.d.ts +19 -0
- package/dist/cli/chat.handler.js +431 -0
- package/dist/cli/chat.handler.js.map +1 -0
- package/dist/cli/cli.handler.d.ts +4 -0
- package/dist/cli/cli.handler.js +97 -0
- package/dist/cli/cli.handler.js.map +1 -0
- package/dist/cli/doctor.handler.d.ts +36 -0
- package/dist/cli/doctor.handler.js +382 -0
- package/dist/cli/doctor.handler.js.map +1 -0
- package/dist/cli/execute.handler.d.ts +2 -0
- package/dist/cli/execute.handler.js +319 -0
- package/dist/cli/execute.handler.js.map +1 -0
- package/dist/cli/help.handler.d.ts +2 -0
- package/dist/cli/help.handler.js +10 -0
- package/dist/cli/help.handler.js.map +1 -0
- package/dist/cli/init.handler.d.ts +26 -0
- package/dist/cli/init.handler.js +450 -0
- package/dist/cli/init.handler.js.map +1 -0
- package/dist/cli/mcp.handler.d.ts +3 -0
- package/dist/cli/mcp.handler.js +121 -0
- package/dist/cli/mcp.handler.js.map +1 -0
- package/dist/cli/query.handler.d.ts +2 -0
- package/dist/cli/query.handler.js +380 -0
- package/dist/cli/query.handler.js.map +1 -0
- package/dist/cli/templates.handler.d.ts +2 -0
- package/dist/cli/templates.handler.js +100 -0
- package/dist/cli/templates.handler.js.map +1 -0
- package/dist/cli-options.d.ts +29 -0
- package/dist/cli-options.js +234 -0
- package/dist/cli-options.js.map +1 -0
- package/dist/config/timeout.config.d.ts +14 -0
- package/dist/config/timeout.config.js +34 -0
- package/dist/config/timeout.config.js.map +1 -0
- package/dist/conversation/base-conversation-history.provider.d.ts +12 -0
- package/dist/conversation/base-conversation-history.provider.js +45 -0
- package/dist/conversation/base-conversation-history.provider.js.map +1 -0
- package/dist/conversation/cli-conversation-history.provider.d.ts +16 -0
- package/dist/conversation/cli-conversation-history.provider.js +111 -0
- package/dist/conversation/cli-conversation-history.provider.js.map +1 -0
- package/dist/conversation/conversation-provider.factory.d.ts +10 -0
- package/dist/conversation/conversation-provider.factory.js +50 -0
- package/dist/conversation/conversation-provider.factory.js.map +1 -0
- package/dist/conversation/index.d.ts +6 -0
- package/dist/conversation/index.js +27 -0
- package/dist/conversation/index.js.map +1 -0
- package/dist/conversation/slack-conversation-history.provider.d.ts +28 -0
- package/dist/conversation/slack-conversation-history.provider.js +278 -0
- package/dist/conversation/slack-conversation-history.provider.js.map +1 -0
- package/dist/crewx.tool.d.ts +332 -0
- package/dist/crewx.tool.js +1461 -0
- package/dist/crewx.tool.js.map +1 -0
- package/dist/guards/bearer-auth.guard.d.ts +7 -0
- package/dist/guards/bearer-auth.guard.js +44 -0
- package/dist/guards/bearer-auth.guard.js.map +1 -0
- package/dist/health.controller.d.ts +6 -0
- package/dist/health.controller.js +32 -0
- package/dist/health.controller.js.map +1 -0
- package/dist/main.d.ts +1 -0
- package/dist/main.js +267 -0
- package/dist/main.js.map +1 -0
- package/dist/mcp.controller.d.ts +8 -0
- package/dist/mcp.controller.js +62 -0
- package/dist/mcp.controller.js.map +1 -0
- package/dist/project.service.d.ts +44 -0
- package/dist/project.service.js +299 -0
- package/dist/project.service.js.map +1 -0
- package/dist/providers/base-ai.provider.d.ts +50 -0
- package/dist/providers/base-ai.provider.js +624 -0
- package/dist/providers/base-ai.provider.js.map +1 -0
- package/dist/providers/claude.provider.d.ts +25 -0
- package/dist/providers/claude.provider.js +362 -0
- package/dist/providers/claude.provider.js.map +1 -0
- package/dist/providers/codex.provider.d.ts +17 -0
- package/dist/providers/codex.provider.js +99 -0
- package/dist/providers/codex.provider.js.map +1 -0
- package/dist/providers/copilot.provider.d.ts +25 -0
- package/dist/providers/copilot.provider.js +266 -0
- package/dist/providers/copilot.provider.js.map +1 -0
- package/dist/providers/dynamic-provider.factory.d.ts +55 -0
- package/dist/providers/dynamic-provider.factory.js +586 -0
- package/dist/providers/dynamic-provider.factory.js.map +1 -0
- package/dist/providers/gemini.provider.d.ts +22 -0
- package/dist/providers/gemini.provider.js +147 -0
- package/dist/providers/gemini.provider.js.map +1 -0
- package/dist/services/agent-loader.service.d.ts +29 -0
- package/dist/services/agent-loader.service.js +370 -0
- package/dist/services/agent-loader.service.js.map +1 -0
- package/dist/services/auth.service.d.ts +9 -0
- package/dist/services/auth.service.js +47 -0
- package/dist/services/auth.service.js.map +1 -0
- package/dist/services/config-validator.service.d.ts +28 -0
- package/dist/services/config-validator.service.js +467 -0
- package/dist/services/config-validator.service.js.map +1 -0
- package/dist/services/config.service.d.ts +45 -0
- package/dist/services/config.service.js +180 -0
- package/dist/services/config.service.js.map +1 -0
- package/dist/services/context-enhancement.service.d.ts +13 -0
- package/dist/services/context-enhancement.service.js +169 -0
- package/dist/services/context-enhancement.service.js.map +1 -0
- package/dist/services/document-loader.service.d.ts +16 -0
- package/dist/services/document-loader.service.js +137 -0
- package/dist/services/document-loader.service.js.map +1 -0
- package/dist/services/help.service.d.ts +5 -0
- package/dist/services/help.service.js +117 -0
- package/dist/services/help.service.js.map +1 -0
- package/dist/services/intelligent-compression.service.d.ts +20 -0
- package/dist/services/intelligent-compression.service.js +179 -0
- package/dist/services/intelligent-compression.service.js.map +1 -0
- package/dist/services/mcp-client.service.d.ts +26 -0
- package/dist/services/mcp-client.service.js +81 -0
- package/dist/services/mcp-client.service.js.map +1 -0
- package/dist/services/parallel-processing.service.d.ts +108 -0
- package/dist/services/parallel-processing.service.js +268 -0
- package/dist/services/parallel-processing.service.js.map +1 -0
- package/dist/services/remote-agent.service.d.ts +49 -0
- package/dist/services/remote-agent.service.js +215 -0
- package/dist/services/remote-agent.service.js.map +1 -0
- package/dist/services/result-formatter.service.d.ts +27 -0
- package/dist/services/result-formatter.service.js +126 -0
- package/dist/services/result-formatter.service.js.map +1 -0
- package/dist/services/task-management.service.d.ts +63 -0
- package/dist/services/task-management.service.js +272 -0
- package/dist/services/task-management.service.js.map +1 -0
- package/dist/services/template.service.d.ts +36 -0
- package/dist/services/template.service.js +195 -0
- package/dist/services/template.service.js.map +1 -0
- package/dist/services/tool-call.service.d.ts +53 -0
- package/dist/services/tool-call.service.js +1061 -0
- package/dist/services/tool-call.service.js.map +1 -0
- package/dist/slack/formatters/message.formatter.d.ts +25 -0
- package/dist/slack/formatters/message.formatter.js +246 -0
- package/dist/slack/formatters/message.formatter.js.map +1 -0
- package/dist/slack/slack-bot.d.ts +24 -0
- package/dist/slack/slack-bot.js +467 -0
- package/dist/slack/slack-bot.js.map +1 -0
- package/dist/stderr.logger.d.ts +8 -0
- package/dist/stderr.logger.js +26 -0
- package/dist/stderr.logger.js.map +1 -0
- package/dist/utils/config-utils.d.ts +15 -0
- package/dist/utils/config-utils.js +69 -0
- package/dist/utils/config-utils.js.map +1 -0
- package/dist/utils/mcp-installer.d.ts +20 -0
- package/dist/utils/mcp-installer.js +199 -0
- package/dist/utils/mcp-installer.js.map +1 -0
- package/dist/utils/mention-parser.d.ts +18 -0
- package/dist/utils/mention-parser.js +136 -0
- package/dist/utils/mention-parser.js.map +1 -0
- package/dist/utils/simple-security.d.ts +3 -0
- package/dist/utils/simple-security.js +20 -0
- package/dist/utils/simple-security.js.map +1 -0
- package/dist/utils/stdin-utils.d.ts +27 -0
- package/dist/utils/stdin-utils.js +130 -0
- package/dist/utils/stdin-utils.js.map +1 -0
- package/dist/utils/template-processor.d.ts +32 -0
- package/dist/utils/template-processor.js +202 -0
- package/dist/utils/template-processor.js.map +1 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +17 -0
- package/dist/version.js.map +1 -0
- package/package.json +122 -0
|
@@ -0,0 +1,1461 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
22
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
+
};
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
42
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
43
|
+
};
|
|
44
|
+
var CrewXTool_1;
|
|
45
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
+
exports.CrewXTool = void 0;
|
|
47
|
+
const common_1 = require("@nestjs/common");
|
|
48
|
+
const nestjs_mcp_adapter_1 = require("@sowonai/nestjs-mcp-adapter");
|
|
49
|
+
const zod_1 = require("zod");
|
|
50
|
+
const fs = __importStar(require("fs"));
|
|
51
|
+
const path = __importStar(require("path"));
|
|
52
|
+
const crypto = __importStar(require("crypto"));
|
|
53
|
+
const ai_service_1 = require("./ai.service");
|
|
54
|
+
const ai_provider_service_1 = require("./ai-provider.service");
|
|
55
|
+
const project_service_1 = require("./project.service");
|
|
56
|
+
const crewx_sdk_1 = require("@sowonai/crewx-sdk");
|
|
57
|
+
const parallel_processing_service_1 = require("./services/parallel-processing.service");
|
|
58
|
+
const task_management_service_1 = require("./services/task-management.service");
|
|
59
|
+
const result_formatter_service_1 = require("./services/result-formatter.service");
|
|
60
|
+
const template_service_1 = require("./services/template.service");
|
|
61
|
+
const document_loader_service_1 = require("./services/document-loader.service");
|
|
62
|
+
const tool_call_service_1 = require("./services/tool-call.service");
|
|
63
|
+
const agent_loader_service_1 = require("./services/agent-loader.service");
|
|
64
|
+
const remote_agent_service_1 = require("./services/remote-agent.service");
|
|
65
|
+
let CrewXTool = CrewXTool_1 = class CrewXTool {
|
|
66
|
+
generateSecurityKey() {
|
|
67
|
+
return crypto.randomBytes(8).toString('hex');
|
|
68
|
+
}
|
|
69
|
+
buildToolsContext() {
|
|
70
|
+
const tools = this.toolCallService.list();
|
|
71
|
+
if (!tools || tools.length === 0) {
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
list: tools.map(t => ({
|
|
76
|
+
name: t.name,
|
|
77
|
+
description: t.description,
|
|
78
|
+
input_schema: t.input_schema,
|
|
79
|
+
output_schema: t.output_schema,
|
|
80
|
+
})),
|
|
81
|
+
json: JSON.stringify(tools, null, 2),
|
|
82
|
+
count: tools.length,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
async buildStructuredPayload(params) {
|
|
86
|
+
const { agentId, provider, mode, prompt, context, messages, platform, model } = params;
|
|
87
|
+
const safeMessages = Array.isArray(messages) ? messages : [];
|
|
88
|
+
let formattedHistory = '';
|
|
89
|
+
try {
|
|
90
|
+
if (safeMessages.length > 0) {
|
|
91
|
+
const template = '{{{formatConversation messages platform}}}';
|
|
92
|
+
const { processDocumentTemplate } = await Promise.resolve().then(() => __importStar(require('./utils/template-processor')));
|
|
93
|
+
formattedHistory = await processDocumentTemplate(template, this.documentLoaderService, {
|
|
94
|
+
messages: safeMessages,
|
|
95
|
+
platform: platform ?? 'cli',
|
|
96
|
+
});
|
|
97
|
+
formattedHistory = formattedHistory?.trim() ?? '';
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
this.logger.warn(`Failed to format conversation history for structured payload: ${error?.message || error}`);
|
|
102
|
+
}
|
|
103
|
+
const normalizedContext = context?.trim() ?? '';
|
|
104
|
+
const payload = {
|
|
105
|
+
version: '1.0',
|
|
106
|
+
agent: {
|
|
107
|
+
id: agentId,
|
|
108
|
+
provider,
|
|
109
|
+
mode,
|
|
110
|
+
model: model || null,
|
|
111
|
+
},
|
|
112
|
+
prompt,
|
|
113
|
+
context: normalizedContext,
|
|
114
|
+
messages: safeMessages,
|
|
115
|
+
metadata: {
|
|
116
|
+
platform: platform ?? 'cli',
|
|
117
|
+
formattedHistory,
|
|
118
|
+
messageCount: safeMessages.length,
|
|
119
|
+
generatedAt: new Date().toISOString(),
|
|
120
|
+
originalContext: normalizedContext,
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
return JSON.stringify(payload);
|
|
124
|
+
}
|
|
125
|
+
constructor(aiService, aiProviderService, projectService, parallelProcessingService, taskManagementService, resultFormatterService, templateService, documentLoaderService, toolCallService, agentLoaderService, remoteAgentService) {
|
|
126
|
+
this.aiService = aiService;
|
|
127
|
+
this.aiProviderService = aiProviderService;
|
|
128
|
+
this.projectService = projectService;
|
|
129
|
+
this.parallelProcessingService = parallelProcessingService;
|
|
130
|
+
this.taskManagementService = taskManagementService;
|
|
131
|
+
this.resultFormatterService = resultFormatterService;
|
|
132
|
+
this.templateService = templateService;
|
|
133
|
+
this.documentLoaderService = documentLoaderService;
|
|
134
|
+
this.toolCallService = toolCallService;
|
|
135
|
+
this.agentLoaderService = agentLoaderService;
|
|
136
|
+
this.remoteAgentService = remoteAgentService;
|
|
137
|
+
this.logger = new common_1.Logger(CrewXTool_1.name);
|
|
138
|
+
this.timeoutConfig = (0, crewx_sdk_1.getTimeoutConfig)();
|
|
139
|
+
}
|
|
140
|
+
onModuleInit() {
|
|
141
|
+
this.toolCallService.setCrewXTool(this);
|
|
142
|
+
this.logger.log('CrewXTool registered to ToolCallService');
|
|
143
|
+
}
|
|
144
|
+
async getTaskLogs(input) {
|
|
145
|
+
this.logger.log('=== getTaskLogs called ===');
|
|
146
|
+
this.logger.log(`Input taskId: ${input.taskId}`);
|
|
147
|
+
try {
|
|
148
|
+
const logsContent = this.taskManagementService.getTaskLogsFromFile(input.taskId);
|
|
149
|
+
return {
|
|
150
|
+
content: [{ type: 'text', text: logsContent }],
|
|
151
|
+
isError: false
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
this.logger.error('Error reading logs:', error);
|
|
156
|
+
return {
|
|
157
|
+
content: [{ type: 'text', text: `Error reading logs: ${error.message}` }],
|
|
158
|
+
isError: true
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
async checkAIProviders() {
|
|
163
|
+
this.logger.log('Checking AI provider availability');
|
|
164
|
+
try {
|
|
165
|
+
const availableProviders = await this.aiService.checkAvailableProviders();
|
|
166
|
+
const installation = await this.aiService.validateCLIInstallation();
|
|
167
|
+
const recommendations = this.getInstallationRecommendations(installation);
|
|
168
|
+
const responseText = `🤖 **AI Providers Status**
|
|
169
|
+
|
|
170
|
+
**Available Providers:**
|
|
171
|
+
${availableProviders.length > 0 ? availableProviders.map(p => `✅ ${p}`).join('\n') : '❌ No providers available'}
|
|
172
|
+
|
|
173
|
+
**Installation Status:**
|
|
174
|
+
• Claude CLI: ${installation.claude ? '✅ Installed' : '❌ Not Installed'}
|
|
175
|
+
• Gemini CLI: ${installation.gemini ? '✅ Installed' : '❌ Not Installed'}
|
|
176
|
+
• Copilot CLI: ${installation.copilot ? '✅ Installed' : '❌ Not Installed'}
|
|
177
|
+
|
|
178
|
+
**Recommendations:**
|
|
179
|
+
${recommendations.map(r => `• ${r}`).join('\n')}`;
|
|
180
|
+
return {
|
|
181
|
+
content: [
|
|
182
|
+
{
|
|
183
|
+
type: 'text',
|
|
184
|
+
text: responseText
|
|
185
|
+
}
|
|
186
|
+
],
|
|
187
|
+
success: true,
|
|
188
|
+
availableProviders,
|
|
189
|
+
installation: {
|
|
190
|
+
claude: installation.claude,
|
|
191
|
+
gemini: installation.gemini,
|
|
192
|
+
copilot: installation.copilot,
|
|
193
|
+
},
|
|
194
|
+
recommendations,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
catch (error) {
|
|
198
|
+
const errorMessage = (0, crewx_sdk_1.getErrorMessage)(error);
|
|
199
|
+
this.logger.error(`Provider check failed: ${errorMessage}`, (0, crewx_sdk_1.getErrorStack)(error));
|
|
200
|
+
return {
|
|
201
|
+
content: [
|
|
202
|
+
{
|
|
203
|
+
type: 'text',
|
|
204
|
+
text: `❌ **AI Providers Check Failed**
|
|
205
|
+
|
|
206
|
+
**Error:** ${errorMessage}
|
|
207
|
+
|
|
208
|
+
No AI providers could be verified.`
|
|
209
|
+
}
|
|
210
|
+
],
|
|
211
|
+
success: false,
|
|
212
|
+
error: errorMessage,
|
|
213
|
+
availableProviders: [],
|
|
214
|
+
installation: {
|
|
215
|
+
claude: { installed: false },
|
|
216
|
+
gemini: { installed: false },
|
|
217
|
+
copilot: { installed: false }
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
getInstallationRecommendations(installation) {
|
|
223
|
+
const recommendations = [];
|
|
224
|
+
if (!installation.claude) {
|
|
225
|
+
recommendations.push('Claude CLI installation: npm install -g @anthropic-ai/claude-code');
|
|
226
|
+
}
|
|
227
|
+
if (!installation.gemini) {
|
|
228
|
+
recommendations.push('Gemini CLI installation: npm install -g @google/gemini-cli');
|
|
229
|
+
}
|
|
230
|
+
if (!installation.copilot) {
|
|
231
|
+
recommendations.push('GitHub Copilot CLI installation: npm install -g @github/copilot-cli or gh extension install github/gh-copilot');
|
|
232
|
+
}
|
|
233
|
+
if (installation.claude && installation.gemini && installation.copilot) {
|
|
234
|
+
recommendations.push('All AI providers are available!');
|
|
235
|
+
}
|
|
236
|
+
return recommendations;
|
|
237
|
+
}
|
|
238
|
+
async listAgents() {
|
|
239
|
+
try {
|
|
240
|
+
const agents = await this.agentLoaderService.getAllAgents();
|
|
241
|
+
this.logger.log(`Retrieved ${agents.length} available agents`);
|
|
242
|
+
const agentsConfigPath = process.env.CREWX_CONFIG;
|
|
243
|
+
let yamlContent = '';
|
|
244
|
+
if (agentsConfigPath) {
|
|
245
|
+
try {
|
|
246
|
+
const { readFile } = await Promise.resolve().then(() => __importStar(require('fs/promises')));
|
|
247
|
+
yamlContent = await readFile(agentsConfigPath, 'utf-8');
|
|
248
|
+
}
|
|
249
|
+
catch (error) {
|
|
250
|
+
this.logger.warn('Could not read YAML file for display:', (0, crewx_sdk_1.getErrorMessage)(error));
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
const responseText = `🤖 **Available AI Agents (${agents.length} total)**
|
|
254
|
+
|
|
255
|
+
**Configuration Source:** ${process.env.CREWX_CONFIG ? 'External YAML file' : 'Built-in defaults'}
|
|
256
|
+
${process.env.CREWX_CONFIG ? `**Config Path:** \`${process.env.CREWX_CONFIG}\`` : ''}
|
|
257
|
+
|
|
258
|
+
**Parsed Agent Summary:**
|
|
259
|
+
${agents.map((agent, index) => `${index + 1}. **${agent.id}**
|
|
260
|
+
- Provider: ${agent.provider}
|
|
261
|
+
- Working Dir: ${agent.workingDirectory}
|
|
262
|
+
${agent.name ? `- Name: ${agent.name}` : ''}
|
|
263
|
+
${agent.role ? `- Role: ${agent.role}` : ''}
|
|
264
|
+
${agent.team ? `- Team: ${agent.team}` : ''}
|
|
265
|
+
`).join('')}
|
|
266
|
+
|
|
267
|
+
${yamlContent ? `**Full YAML Configuration:**
|
|
268
|
+
\`\`\`yaml
|
|
269
|
+
${yamlContent}
|
|
270
|
+
\`\`\`
|
|
271
|
+
|
|
272
|
+
**💡 Customization Guide:**
|
|
273
|
+
You can customize agents by modifying the YAML file. Required fields:
|
|
274
|
+
- \`id\`: Unique identifier
|
|
275
|
+
- \`working_directory\`: Path for agent operations
|
|
276
|
+
- \`inline.provider\`: AI provider (claude/gemini/copilot)
|
|
277
|
+
- \`inline.system_prompt\`: Agent's specialized instructions
|
|
278
|
+
|
|
279
|
+
Optional fields (like \`name\`, \`role\`, \`team\`, etc.) can be added for better organization.` : `**Default Configuration:**
|
|
280
|
+
No external YAML file configured. Using built-in agents.
|
|
281
|
+
Set \`CREWX_CONFIG\` environment variable to use custom agents.
|
|
282
|
+
|
|
283
|
+
**Example YAML Structure:**
|
|
284
|
+
\`\`\`yaml
|
|
285
|
+
agents:
|
|
286
|
+
- id: "your_agent_id"
|
|
287
|
+
name: "Your Agent Name"
|
|
288
|
+
role: "specialist"
|
|
289
|
+
working_directory: "/path/to/project"
|
|
290
|
+
inline:
|
|
291
|
+
type: "agent"
|
|
292
|
+
provider: "claude"
|
|
293
|
+
system_prompt: |
|
|
294
|
+
You are a specialized AI agent for...
|
|
295
|
+
\`\`\``}
|
|
296
|
+
|
|
297
|
+
**Recommendations:**
|
|
298
|
+
|
|
299
|
+
**🚀 Performance Tip:** For optimal results, formulate queries in English. Testing shows English queries typically produce more detailed responses, faster processing times (20% improvement), and higher success rates compared to other languages.
|
|
300
|
+
|
|
301
|
+
**Configuration Source:** ${process.env.CREWX_CONFIG ? 'External YAML file' : 'Default hardcoded values'}`;
|
|
302
|
+
return {
|
|
303
|
+
content: [
|
|
304
|
+
{
|
|
305
|
+
type: 'text',
|
|
306
|
+
text: responseText
|
|
307
|
+
}
|
|
308
|
+
],
|
|
309
|
+
success: true,
|
|
310
|
+
availableAgents: agents,
|
|
311
|
+
totalCount: agents.length,
|
|
312
|
+
configurationSource: process.env.CREWX_CONFIG ? 'External YAML file' : 'Default hardcoded values'
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
catch (error) {
|
|
316
|
+
const errorMessage = (0, crewx_sdk_1.getErrorMessage)(error);
|
|
317
|
+
this.logger.error('Agent listing failed:', errorMessage);
|
|
318
|
+
return {
|
|
319
|
+
content: [
|
|
320
|
+
{
|
|
321
|
+
type: 'text',
|
|
322
|
+
text: `❌ **Error loading agents:** ${errorMessage}
|
|
323
|
+
|
|
324
|
+
**Fallback:** No agents available due to configuration error.`
|
|
325
|
+
}
|
|
326
|
+
],
|
|
327
|
+
success: false,
|
|
328
|
+
error: errorMessage,
|
|
329
|
+
availableAgents: [],
|
|
330
|
+
totalCount: 0
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
async queryAgent(args) {
|
|
335
|
+
const taskId = this.taskManagementService.createTask({
|
|
336
|
+
type: 'query',
|
|
337
|
+
provider: 'claude',
|
|
338
|
+
prompt: args.query,
|
|
339
|
+
agentId: args.agentId
|
|
340
|
+
});
|
|
341
|
+
const agentDescriptor = args.model ? `${args.agentId} (model: ${args.model})` : args.agentId;
|
|
342
|
+
this.taskManagementService.addTaskLog(taskId, { level: 'info', message: `Started query agent ${agentDescriptor}` });
|
|
343
|
+
try {
|
|
344
|
+
const { agentId, query, context, model, messages, platform } = args;
|
|
345
|
+
this.logger.log(`[${taskId}] Querying agent ${agentId}: ${query.substring(0, 50)}...`);
|
|
346
|
+
this.taskManagementService.addTaskLog(taskId, { level: 'info', message: `Query: ${query.substring(0, 100)}...` });
|
|
347
|
+
if (model) {
|
|
348
|
+
this.taskManagementService.addTaskLog(taskId, { level: 'info', message: `Model: ${model}` });
|
|
349
|
+
}
|
|
350
|
+
const agents = await this.agentLoaderService.getAllAgents();
|
|
351
|
+
const agent = agents.find(a => a.id === agentId);
|
|
352
|
+
if (!agent) {
|
|
353
|
+
return {
|
|
354
|
+
content: [
|
|
355
|
+
{
|
|
356
|
+
type: 'text',
|
|
357
|
+
text: `❌ **Agent Not Found**
|
|
358
|
+
|
|
359
|
+
**Error:** Agent '${agentId}' not found.
|
|
360
|
+
|
|
361
|
+
**Available Agents:** ${agents.map(a => a.id).join(', ')}
|
|
362
|
+
|
|
363
|
+
Please check the agent ID and try again.`
|
|
364
|
+
}
|
|
365
|
+
],
|
|
366
|
+
success: false,
|
|
367
|
+
agent: agentId,
|
|
368
|
+
error: `Agent '${agentId}' not found`,
|
|
369
|
+
availableAgents: agents.map(a => a.id),
|
|
370
|
+
readOnlyMode: true
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
if (agent.remote?.type === 'mcp-http') {
|
|
374
|
+
try {
|
|
375
|
+
const remoteResult = await this.remoteAgentService.queryRemoteAgent(agent, {
|
|
376
|
+
query,
|
|
377
|
+
context,
|
|
378
|
+
model,
|
|
379
|
+
platform,
|
|
380
|
+
messages,
|
|
381
|
+
});
|
|
382
|
+
const normalized = this.normalizeRemoteResult(agent, taskId, remoteResult, true);
|
|
383
|
+
const logLevel = normalized.success ? 'info' : 'error';
|
|
384
|
+
this.taskManagementService.addTaskLog(taskId, {
|
|
385
|
+
level: logLevel,
|
|
386
|
+
message: normalized.success
|
|
387
|
+
? 'Remote agent query completed successfully'
|
|
388
|
+
: `Remote agent query failed: ${normalized.error || 'Unknown error'}`,
|
|
389
|
+
});
|
|
390
|
+
this.taskManagementService.completeTask(taskId, normalized, normalized.success !== false);
|
|
391
|
+
return normalized;
|
|
392
|
+
}
|
|
393
|
+
catch (error) {
|
|
394
|
+
const errorMessage = (0, crewx_sdk_1.getErrorMessage)(error);
|
|
395
|
+
this.taskManagementService.addTaskLog(taskId, {
|
|
396
|
+
level: 'error',
|
|
397
|
+
message: `Remote agent query failed: ${errorMessage}`,
|
|
398
|
+
});
|
|
399
|
+
this.taskManagementService.completeTask(taskId, { success: false, error: errorMessage }, false);
|
|
400
|
+
return {
|
|
401
|
+
content: [
|
|
402
|
+
{
|
|
403
|
+
type: 'text',
|
|
404
|
+
text: `❌ **Remote agent error**\n\n\
|
|
405
|
+
${errorMessage}`,
|
|
406
|
+
},
|
|
407
|
+
],
|
|
408
|
+
success: false,
|
|
409
|
+
agent: agentId,
|
|
410
|
+
provider: 'remote',
|
|
411
|
+
error: errorMessage,
|
|
412
|
+
taskId,
|
|
413
|
+
readOnlyMode: true,
|
|
414
|
+
readOnly: true,
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
const workingDir = agent.workingDirectory || process.cwd();
|
|
419
|
+
let systemPrompt = agent.systemPrompt || agent.description || `You are an expert ${agentId}.`;
|
|
420
|
+
const securityKey = this.generateSecurityKey();
|
|
421
|
+
if (systemPrompt) {
|
|
422
|
+
const { processDocumentTemplate } = await Promise.resolve().then(() => __importStar(require('./utils/template-processor')));
|
|
423
|
+
const contextMessages = messages && messages.length > 0 ? messages.slice(0, -1) : [];
|
|
424
|
+
const templateContext = {
|
|
425
|
+
env: process.env,
|
|
426
|
+
agent: {
|
|
427
|
+
id: agent.id,
|
|
428
|
+
name: agent.name || agent.id,
|
|
429
|
+
provider: (Array.isArray(agent.provider) ? agent.provider[0] : agent.provider) || 'claude',
|
|
430
|
+
model: model || agent.inline?.model,
|
|
431
|
+
workingDirectory: workingDir,
|
|
432
|
+
},
|
|
433
|
+
mode: 'query',
|
|
434
|
+
messages: contextMessages,
|
|
435
|
+
platform: platform,
|
|
436
|
+
tools: this.buildToolsContext(),
|
|
437
|
+
vars: {
|
|
438
|
+
security_key: securityKey,
|
|
439
|
+
},
|
|
440
|
+
};
|
|
441
|
+
systemPrompt = await processDocumentTemplate(systemPrompt, this.documentLoaderService, templateContext);
|
|
442
|
+
}
|
|
443
|
+
systemPrompt += `
|
|
444
|
+
|
|
445
|
+
Specialties: ${agent.specialties?.join(', ') || 'General'}
|
|
446
|
+
Capabilities: ${agent.capabilities?.join(', ') || 'Analysis'}
|
|
447
|
+
Working Directory: ${workingDir}`;
|
|
448
|
+
const wrappedQuery = `
|
|
449
|
+
<user_query key="${securityKey}">
|
|
450
|
+
${query}
|
|
451
|
+
</user_query>`;
|
|
452
|
+
let fullPrompt = systemPrompt;
|
|
453
|
+
if (context) {
|
|
454
|
+
fullPrompt += `\n\n${context}`;
|
|
455
|
+
}
|
|
456
|
+
fullPrompt += `\n\n${wrappedQuery}`;
|
|
457
|
+
let response;
|
|
458
|
+
let provider;
|
|
459
|
+
if (Array.isArray(agent.provider)) {
|
|
460
|
+
if (agent.inline?.model || model) {
|
|
461
|
+
provider = agent.provider[0] || 'claude';
|
|
462
|
+
}
|
|
463
|
+
else {
|
|
464
|
+
provider = await this.getAvailableProvider(agent.provider);
|
|
465
|
+
this.taskManagementService.addTaskLog(taskId, { level: 'info', message: `Using fallback provider: ${provider}` });
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
else {
|
|
469
|
+
provider = agent.provider || 'claude';
|
|
470
|
+
}
|
|
471
|
+
const agentOptions = this.getOptionsForAgent(agent, 'query', provider);
|
|
472
|
+
const modelToUse = model || agent.inline?.model;
|
|
473
|
+
const structuredPayload = await this.buildStructuredPayload({
|
|
474
|
+
agentId,
|
|
475
|
+
provider,
|
|
476
|
+
mode: 'query',
|
|
477
|
+
prompt: fullPrompt,
|
|
478
|
+
context,
|
|
479
|
+
messages,
|
|
480
|
+
platform: platform || 'cli',
|
|
481
|
+
model: modelToUse,
|
|
482
|
+
});
|
|
483
|
+
response = await this.aiService.queryAI(fullPrompt, provider, {
|
|
484
|
+
workingDirectory: workingDir,
|
|
485
|
+
timeout: this.timeoutConfig.parallel,
|
|
486
|
+
additionalArgs: agentOptions,
|
|
487
|
+
taskId,
|
|
488
|
+
model: modelToUse,
|
|
489
|
+
agentId,
|
|
490
|
+
securityKey,
|
|
491
|
+
messages,
|
|
492
|
+
pipedContext: structuredPayload,
|
|
493
|
+
});
|
|
494
|
+
this.taskManagementService.addTaskLog(taskId, { level: 'info', message: `Query completed. Success: ${response.success}` });
|
|
495
|
+
this.taskManagementService.completeTask(taskId, response, response.success);
|
|
496
|
+
const responseText = response.success
|
|
497
|
+
? response.content
|
|
498
|
+
: `❌ **Error**\n\`\`\`${response.error}\`\`\`\n\nAgent: ${agentId} (${response.provider}) · Task ID: \`${taskId}\``;
|
|
499
|
+
return {
|
|
500
|
+
content: [
|
|
501
|
+
{
|
|
502
|
+
type: 'text',
|
|
503
|
+
text: responseText
|
|
504
|
+
}
|
|
505
|
+
],
|
|
506
|
+
taskId: taskId,
|
|
507
|
+
success: response.success,
|
|
508
|
+
agent: agentId,
|
|
509
|
+
provider: response.provider,
|
|
510
|
+
query: query,
|
|
511
|
+
response: response.content,
|
|
512
|
+
readOnlyMode: true,
|
|
513
|
+
error: response.error,
|
|
514
|
+
workingDirectory: workingDir
|
|
515
|
+
};
|
|
516
|
+
}
|
|
517
|
+
catch (error) {
|
|
518
|
+
const errorMessage = (0, crewx_sdk_1.getErrorMessage)(error);
|
|
519
|
+
this.taskManagementService.addTaskLog(taskId, { level: 'error', message: `Query failed: ${errorMessage}` });
|
|
520
|
+
this.taskManagementService.completeTask(taskId, { error: errorMessage }, false);
|
|
521
|
+
this.logger.error(`[${taskId}] Agent query failed for ${args.agentId}:`, errorMessage);
|
|
522
|
+
return {
|
|
523
|
+
content: [
|
|
524
|
+
{
|
|
525
|
+
type: 'text',
|
|
526
|
+
text: `❌ **Agent Query Failed**
|
|
527
|
+
|
|
528
|
+
**Task ID:** ${taskId}
|
|
529
|
+
**Agent:** ${args.agentId}
|
|
530
|
+
**Error:** ${errorMessage}
|
|
531
|
+
**Query:** ${args.query}
|
|
532
|
+
|
|
533
|
+
Read-Only Mode: No files were modified.`
|
|
534
|
+
}
|
|
535
|
+
],
|
|
536
|
+
success: false,
|
|
537
|
+
agent: args.agentId,
|
|
538
|
+
error: errorMessage,
|
|
539
|
+
readOnlyMode: true
|
|
540
|
+
};
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
async executeAgent(args) {
|
|
544
|
+
const taskId = this.taskManagementService.createTask({
|
|
545
|
+
type: 'execute',
|
|
546
|
+
provider: 'claude',
|
|
547
|
+
prompt: args.task,
|
|
548
|
+
agentId: args.agentId
|
|
549
|
+
});
|
|
550
|
+
const agentDescriptor = args.model ? `${args.agentId} (model: ${args.model})` : args.agentId;
|
|
551
|
+
this.taskManagementService.addTaskLog(taskId, { level: 'info', message: `Started execute agent ${agentDescriptor}` });
|
|
552
|
+
try {
|
|
553
|
+
const { agentId, task, projectPath, context, model, messages, platform } = args;
|
|
554
|
+
this.logger.log(`[${taskId}] Executing agent ${agentId}: ${task.substring(0, 50)}...`);
|
|
555
|
+
this.taskManagementService.addTaskLog(taskId, { level: 'info', message: `Task: ${task.substring(0, 100)}...` });
|
|
556
|
+
if (model) {
|
|
557
|
+
this.taskManagementService.addTaskLog(taskId, { level: 'info', message: `Model: ${model}` });
|
|
558
|
+
}
|
|
559
|
+
const agents = await this.agentLoaderService.getAllAgents();
|
|
560
|
+
const agent = agents.find(a => a.id === agentId);
|
|
561
|
+
if (!agent) {
|
|
562
|
+
return {
|
|
563
|
+
content: [
|
|
564
|
+
{
|
|
565
|
+
type: 'text',
|
|
566
|
+
text: `❌ **Agent Not Found**
|
|
567
|
+
|
|
568
|
+
**Error:** Agent '${agentId}' not found.
|
|
569
|
+
|
|
570
|
+
**Available Agents:** ${agents.map(a => a.id).join(', ')}
|
|
571
|
+
|
|
572
|
+
Please check the agent ID and try again.`
|
|
573
|
+
}
|
|
574
|
+
],
|
|
575
|
+
success: false,
|
|
576
|
+
agent: agentId,
|
|
577
|
+
error: `Agent '${agentId}' not found`,
|
|
578
|
+
availableAgents: agents.map(a => a.id),
|
|
579
|
+
executionMode: true
|
|
580
|
+
};
|
|
581
|
+
}
|
|
582
|
+
if (agent.remote?.type === 'mcp-http') {
|
|
583
|
+
try {
|
|
584
|
+
const remoteResult = await this.remoteAgentService.executeRemoteAgent(agent, {
|
|
585
|
+
task,
|
|
586
|
+
context,
|
|
587
|
+
model,
|
|
588
|
+
platform,
|
|
589
|
+
messages,
|
|
590
|
+
});
|
|
591
|
+
const normalized = this.normalizeRemoteResult(agent, taskId, remoteResult, false);
|
|
592
|
+
const logLevel = normalized.success ? 'info' : 'error';
|
|
593
|
+
this.taskManagementService.addTaskLog(taskId, {
|
|
594
|
+
level: logLevel,
|
|
595
|
+
message: normalized.success
|
|
596
|
+
? 'Remote agent execute completed successfully'
|
|
597
|
+
: `Remote agent execute failed: ${normalized.error || 'Unknown error'}`,
|
|
598
|
+
});
|
|
599
|
+
this.taskManagementService.completeTask(taskId, normalized, normalized.success !== false);
|
|
600
|
+
return normalized;
|
|
601
|
+
}
|
|
602
|
+
catch (error) {
|
|
603
|
+
const errorMessage = (0, crewx_sdk_1.getErrorMessage)(error);
|
|
604
|
+
this.taskManagementService.addTaskLog(taskId, {
|
|
605
|
+
level: 'error',
|
|
606
|
+
message: `Remote agent execute failed: ${errorMessage}`,
|
|
607
|
+
});
|
|
608
|
+
this.taskManagementService.completeTask(taskId, { success: false, error: errorMessage }, false);
|
|
609
|
+
return {
|
|
610
|
+
content: [
|
|
611
|
+
{
|
|
612
|
+
type: 'text',
|
|
613
|
+
text: `❌ **Remote agent error**\n\n${errorMessage}`,
|
|
614
|
+
},
|
|
615
|
+
],
|
|
616
|
+
success: false,
|
|
617
|
+
agent: agentId,
|
|
618
|
+
provider: 'remote',
|
|
619
|
+
error: errorMessage,
|
|
620
|
+
taskId,
|
|
621
|
+
executionMode: true,
|
|
622
|
+
readOnly: false,
|
|
623
|
+
};
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
const workingDir = projectPath || agent.workingDirectory || './';
|
|
627
|
+
let systemPrompt = agent.systemPrompt || agent.description || `You are an expert ${agentId}.`;
|
|
628
|
+
const securityKey = this.generateSecurityKey();
|
|
629
|
+
if (systemPrompt) {
|
|
630
|
+
const { processDocumentTemplate } = await Promise.resolve().then(() => __importStar(require('./utils/template-processor')));
|
|
631
|
+
const contextMessages = messages && messages.length > 0 ? messages.slice(0, -1) : [];
|
|
632
|
+
const templateContext = {
|
|
633
|
+
env: process.env,
|
|
634
|
+
agent: {
|
|
635
|
+
id: agent.id,
|
|
636
|
+
name: agent.name || agent.id,
|
|
637
|
+
provider: (Array.isArray(agent.provider) ? agent.provider[0] : agent.provider) || 'claude',
|
|
638
|
+
model: model || agent.inline?.model,
|
|
639
|
+
workingDirectory: workingDir,
|
|
640
|
+
},
|
|
641
|
+
mode: 'execute',
|
|
642
|
+
messages: contextMessages,
|
|
643
|
+
platform: platform,
|
|
644
|
+
tools: this.buildToolsContext(),
|
|
645
|
+
vars: {
|
|
646
|
+
security_key: securityKey,
|
|
647
|
+
},
|
|
648
|
+
};
|
|
649
|
+
systemPrompt = await processDocumentTemplate(systemPrompt, this.documentLoaderService, templateContext);
|
|
650
|
+
}
|
|
651
|
+
systemPrompt += `
|
|
652
|
+
Specialties: ${agent.specialties?.join(', ') || 'General'}
|
|
653
|
+
Capabilities: ${agent.capabilities?.join(', ') || 'Implementation'}
|
|
654
|
+
Working Directory: ${workingDir}`;
|
|
655
|
+
const fullPrompt = context
|
|
656
|
+
? `${systemPrompt}
|
|
657
|
+
${context}
|
|
658
|
+
|
|
659
|
+
Task: ${task}
|
|
660
|
+
`
|
|
661
|
+
: `${systemPrompt}
|
|
662
|
+
|
|
663
|
+
Task: ${task}
|
|
664
|
+
`;
|
|
665
|
+
let response;
|
|
666
|
+
let provider;
|
|
667
|
+
if (Array.isArray(agent.provider)) {
|
|
668
|
+
if (agent.inline?.model || model) {
|
|
669
|
+
provider = agent.provider[0] || 'claude';
|
|
670
|
+
}
|
|
671
|
+
else {
|
|
672
|
+
provider = await this.getAvailableProvider(agent.provider);
|
|
673
|
+
this.taskManagementService.addTaskLog(taskId, { level: 'info', message: `Using fallback provider: ${provider}` });
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
else {
|
|
677
|
+
provider = agent.provider || 'claude';
|
|
678
|
+
}
|
|
679
|
+
this.taskManagementService.addTaskLog(taskId, { level: 'info', message: `Using provider: ${provider}` });
|
|
680
|
+
const agentOptions = this.getOptionsForAgent(agent, 'execute', provider);
|
|
681
|
+
const modelToUse = model || agent.inline?.model;
|
|
682
|
+
const structuredPayload = await this.buildStructuredPayload({
|
|
683
|
+
agentId,
|
|
684
|
+
provider,
|
|
685
|
+
mode: 'execute',
|
|
686
|
+
prompt: fullPrompt,
|
|
687
|
+
context,
|
|
688
|
+
messages,
|
|
689
|
+
platform: platform || 'cli',
|
|
690
|
+
model: modelToUse,
|
|
691
|
+
});
|
|
692
|
+
response = await this.aiService.executeAI(fullPrompt, provider, {
|
|
693
|
+
workingDirectory: workingDir,
|
|
694
|
+
timeout: 1200000,
|
|
695
|
+
taskId: taskId,
|
|
696
|
+
additionalArgs: agentOptions,
|
|
697
|
+
model: modelToUse,
|
|
698
|
+
agentId,
|
|
699
|
+
messages,
|
|
700
|
+
pipedContext: structuredPayload,
|
|
701
|
+
});
|
|
702
|
+
this.taskManagementService.addTaskLog(taskId, { level: 'info', message: `Execution completed. Success: ${response.success}` });
|
|
703
|
+
this.taskManagementService.completeTask(taskId, response, response.success);
|
|
704
|
+
const responseText = response.success ? response.content : `❌ Execution Failed: ${response.error}`;
|
|
705
|
+
return {
|
|
706
|
+
content: [
|
|
707
|
+
{
|
|
708
|
+
type: 'text',
|
|
709
|
+
text: responseText
|
|
710
|
+
}
|
|
711
|
+
],
|
|
712
|
+
success: response.success,
|
|
713
|
+
taskId: taskId,
|
|
714
|
+
agent: agentId,
|
|
715
|
+
provider: response.provider,
|
|
716
|
+
implementation: response.content,
|
|
717
|
+
error: response.error,
|
|
718
|
+
recommendations: []
|
|
719
|
+
};
|
|
720
|
+
}
|
|
721
|
+
catch (error) {
|
|
722
|
+
const errorMessage = (0, crewx_sdk_1.getErrorMessage)(error);
|
|
723
|
+
this.taskManagementService.addTaskLog(taskId, { level: 'error', message: `Execution failed: ${errorMessage}` });
|
|
724
|
+
this.taskManagementService.completeTask(taskId, { error: errorMessage }, false);
|
|
725
|
+
this.logger.error(`[${taskId}] Agent execution failed for ${args.agentId}:`, errorMessage);
|
|
726
|
+
return {
|
|
727
|
+
content: [
|
|
728
|
+
{
|
|
729
|
+
type: 'text',
|
|
730
|
+
text: `❌ Execution Failed: ${errorMessage}`
|
|
731
|
+
}
|
|
732
|
+
],
|
|
733
|
+
success: false,
|
|
734
|
+
taskId: taskId,
|
|
735
|
+
agent: args.agentId,
|
|
736
|
+
provider: 'unknown',
|
|
737
|
+
implementation: null,
|
|
738
|
+
error: errorMessage,
|
|
739
|
+
recommendations: []
|
|
740
|
+
};
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
normalizeRemoteResult(agent, taskId, remoteResult, readOnly) {
|
|
744
|
+
const normalizedAgentId = remoteResult?.agent ?? agent.remote?.agentId ?? agent.id;
|
|
745
|
+
const provider = remoteResult?.provider ?? 'remote';
|
|
746
|
+
let content = remoteResult?.content;
|
|
747
|
+
if (!Array.isArray(content) || content.length === 0) {
|
|
748
|
+
const fallback = remoteResult?.response ??
|
|
749
|
+
remoteResult?.implementation ??
|
|
750
|
+
remoteResult?.message ??
|
|
751
|
+
remoteResult?.output;
|
|
752
|
+
const text = typeof fallback === 'string'
|
|
753
|
+
? fallback
|
|
754
|
+
: JSON.stringify(fallback ?? remoteResult, null, 2);
|
|
755
|
+
content = [
|
|
756
|
+
{
|
|
757
|
+
type: 'text',
|
|
758
|
+
text,
|
|
759
|
+
},
|
|
760
|
+
];
|
|
761
|
+
}
|
|
762
|
+
return {
|
|
763
|
+
...remoteResult,
|
|
764
|
+
content,
|
|
765
|
+
agent: normalizedAgentId,
|
|
766
|
+
provider,
|
|
767
|
+
taskId: remoteResult?.taskId ?? taskId,
|
|
768
|
+
success: remoteResult?.success !== false,
|
|
769
|
+
readOnlyMode: readOnly,
|
|
770
|
+
readOnly,
|
|
771
|
+
};
|
|
772
|
+
}
|
|
773
|
+
getOptionsForAgent(agent, mode, provider) {
|
|
774
|
+
try {
|
|
775
|
+
if (agent.options && typeof agent.options === 'object' && !Array.isArray(agent.options)) {
|
|
776
|
+
const modeOptions = agent.options[mode];
|
|
777
|
+
if (modeOptions && typeof modeOptions === 'object' && !Array.isArray(modeOptions)) {
|
|
778
|
+
if (provider) {
|
|
779
|
+
const simpleProviderName = provider.includes('/') ? provider.split('/').pop() : provider;
|
|
780
|
+
if (simpleProviderName && modeOptions[simpleProviderName]) {
|
|
781
|
+
return modeOptions[simpleProviderName];
|
|
782
|
+
}
|
|
783
|
+
if (modeOptions[provider]) {
|
|
784
|
+
return modeOptions[provider];
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
if (modeOptions['default']) {
|
|
788
|
+
return modeOptions['default'];
|
|
789
|
+
}
|
|
790
|
+
return [];
|
|
791
|
+
}
|
|
792
|
+
return modeOptions || [];
|
|
793
|
+
}
|
|
794
|
+
if (agent.options && Array.isArray(agent.options)) {
|
|
795
|
+
return agent.options;
|
|
796
|
+
}
|
|
797
|
+
return [];
|
|
798
|
+
}
|
|
799
|
+
catch (error) {
|
|
800
|
+
this.logger.warn(`Failed to get options for agent ${agent.id}: ${error}`);
|
|
801
|
+
return [];
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
async queryAgentParallel(args) {
|
|
805
|
+
try {
|
|
806
|
+
const { queries } = args;
|
|
807
|
+
this.logger.log(`Starting parallel agent queries (${queries.length} queries)`);
|
|
808
|
+
if (!queries || queries.length === 0) {
|
|
809
|
+
return {
|
|
810
|
+
content: [
|
|
811
|
+
{
|
|
812
|
+
type: 'text',
|
|
813
|
+
text: `❌ **No Queries Provided**
|
|
814
|
+
|
|
815
|
+
Please provide at least one query in the queries array.
|
|
816
|
+
|
|
817
|
+
**Example:**
|
|
818
|
+
\`\`\`json
|
|
819
|
+
{
|
|
820
|
+
"queries": [
|
|
821
|
+
{
|
|
822
|
+
"agentId": "gmail_mcp_developer",
|
|
823
|
+
"query": "Analyze the README"
|
|
824
|
+
},
|
|
825
|
+
{
|
|
826
|
+
"agentId": "frontend_developer",
|
|
827
|
+
"query": "Explain the component structure"
|
|
828
|
+
}
|
|
829
|
+
]
|
|
830
|
+
}
|
|
831
|
+
\`\`\``
|
|
832
|
+
}
|
|
833
|
+
],
|
|
834
|
+
success: false,
|
|
835
|
+
error: 'No queries provided',
|
|
836
|
+
results: []
|
|
837
|
+
};
|
|
838
|
+
}
|
|
839
|
+
queries.forEach((q, index) => {
|
|
840
|
+
this.logger.log(`Query ${index + 1}: ${q.agentId} -> "${q.query.substring(0, 50)}..."`);
|
|
841
|
+
});
|
|
842
|
+
const startTime = Date.now();
|
|
843
|
+
const queryPromises = queries.map(async (q, index) => {
|
|
844
|
+
const queryStart = Date.now();
|
|
845
|
+
try {
|
|
846
|
+
const result = await this.queryAgent({
|
|
847
|
+
agentId: q.agentId,
|
|
848
|
+
query: q.query,
|
|
849
|
+
context: q.context,
|
|
850
|
+
model: q.model,
|
|
851
|
+
messages: q.messages,
|
|
852
|
+
platform: q.platform
|
|
853
|
+
});
|
|
854
|
+
const duration = Date.now() - queryStart;
|
|
855
|
+
return {
|
|
856
|
+
index: index + 1,
|
|
857
|
+
agentId: q.agentId,
|
|
858
|
+
query: q.query,
|
|
859
|
+
success: result.success !== false,
|
|
860
|
+
response: result.response || result.content?.[0]?.text,
|
|
861
|
+
provider: result.provider,
|
|
862
|
+
duration,
|
|
863
|
+
taskId: result.taskId
|
|
864
|
+
};
|
|
865
|
+
}
|
|
866
|
+
catch (error) {
|
|
867
|
+
const duration = Date.now() - queryStart;
|
|
868
|
+
return {
|
|
869
|
+
index: index + 1,
|
|
870
|
+
agentId: q.agentId,
|
|
871
|
+
query: q.query,
|
|
872
|
+
success: false,
|
|
873
|
+
error: error.message,
|
|
874
|
+
duration
|
|
875
|
+
};
|
|
876
|
+
}
|
|
877
|
+
});
|
|
878
|
+
const results = await Promise.all(queryPromises);
|
|
879
|
+
const totalDuration = Date.now() - startTime;
|
|
880
|
+
const successCount = results.filter(r => r.success).length;
|
|
881
|
+
const failureCount = results.length - successCount;
|
|
882
|
+
const summary = {
|
|
883
|
+
total: results.length,
|
|
884
|
+
successful: successCount,
|
|
885
|
+
failed: failureCount,
|
|
886
|
+
totalDuration,
|
|
887
|
+
averageDuration: results.reduce((sum, r) => sum + r.duration, 0) / results.length
|
|
888
|
+
};
|
|
889
|
+
this.logger.log(`Parallel queries completed: ${successCount} success, ${failureCount} failed, ${totalDuration}ms total`);
|
|
890
|
+
const enhancedResults = results;
|
|
891
|
+
const formattedResult = this.resultFormatterService.formatParallelResult(enhancedResults, {
|
|
892
|
+
total: summary.total,
|
|
893
|
+
success: summary.successful,
|
|
894
|
+
failed: summary.failed,
|
|
895
|
+
totalDuration: summary.totalDuration,
|
|
896
|
+
averageDuration: summary.averageDuration,
|
|
897
|
+
fastest: Math.min(...results.map(r => r.duration)),
|
|
898
|
+
slowest: Math.max(...results.map(r => r.duration)),
|
|
899
|
+
timeSaved: Math.max(0, results.reduce((sum, r) => sum + r.duration, 0) - summary.totalDuration)
|
|
900
|
+
}, true);
|
|
901
|
+
return {
|
|
902
|
+
content: [
|
|
903
|
+
{
|
|
904
|
+
type: 'text',
|
|
905
|
+
text: formattedResult.mcp
|
|
906
|
+
}
|
|
907
|
+
],
|
|
908
|
+
success: true,
|
|
909
|
+
summary: {
|
|
910
|
+
totalQueries: summary.total,
|
|
911
|
+
successful: summary.successful,
|
|
912
|
+
failed: summary.failed,
|
|
913
|
+
totalDuration: summary.totalDuration,
|
|
914
|
+
averageDuration: summary.averageDuration
|
|
915
|
+
},
|
|
916
|
+
results: enhancedResults,
|
|
917
|
+
performance: {
|
|
918
|
+
fastestQuery: Math.min(...results.map(r => r.duration)),
|
|
919
|
+
slowestQuery: Math.max(...results.map(r => r.duration)),
|
|
920
|
+
timeSaved: Math.max(0, results.reduce((sum, r) => sum + r.duration, 0) - summary.totalDuration)
|
|
921
|
+
},
|
|
922
|
+
readOnlyMode: true
|
|
923
|
+
};
|
|
924
|
+
}
|
|
925
|
+
catch (error) {
|
|
926
|
+
const errorMessage = (0, crewx_sdk_1.getErrorMessage)(error);
|
|
927
|
+
this.logger.error('Parallel agent queries failed:', errorMessage);
|
|
928
|
+
return {
|
|
929
|
+
content: [
|
|
930
|
+
{
|
|
931
|
+
type: 'text',
|
|
932
|
+
text: `❌ **Parallel Agent Queries Failed**
|
|
933
|
+
|
|
934
|
+
**Error:** ${errorMessage}
|
|
935
|
+
|
|
936
|
+
**Total Queries:** ${args.queries?.length || 0}
|
|
937
|
+
|
|
938
|
+
Read-Only Mode: No files were modified.`
|
|
939
|
+
}
|
|
940
|
+
],
|
|
941
|
+
success: false,
|
|
942
|
+
error: errorMessage,
|
|
943
|
+
results: [],
|
|
944
|
+
readOnlyMode: true
|
|
945
|
+
};
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
async executeAgentParallel(args) {
|
|
949
|
+
try {
|
|
950
|
+
const { tasks } = args;
|
|
951
|
+
this.logger.log(`Starting parallel agent execution (${tasks.length} tasks)`);
|
|
952
|
+
if (!tasks || tasks.length === 0) {
|
|
953
|
+
return {
|
|
954
|
+
content: [
|
|
955
|
+
{
|
|
956
|
+
type: 'text',
|
|
957
|
+
text: `❌ **No Tasks Provided**
|
|
958
|
+
|
|
959
|
+
Please provide at least one task in the tasks array.
|
|
960
|
+
|
|
961
|
+
**Example:**
|
|
962
|
+
\`\`\`json
|
|
963
|
+
{
|
|
964
|
+
"tasks": [
|
|
965
|
+
{
|
|
966
|
+
"task": "Create a utility function for handling timeouts"
|
|
967
|
+
},
|
|
968
|
+
{
|
|
969
|
+
"agentId": "crewx_developer_claude",
|
|
970
|
+
"task": "Write unit tests for the new utility function"
|
|
971
|
+
},
|
|
972
|
+
{
|
|
973
|
+
"agentId": "crewx_developer_gemini",
|
|
974
|
+
"task": "Review the implementation for edge cases"
|
|
975
|
+
}
|
|
976
|
+
]
|
|
977
|
+
}
|
|
978
|
+
\`\`\``
|
|
979
|
+
}
|
|
980
|
+
],
|
|
981
|
+
success: false,
|
|
982
|
+
error: 'No tasks provided',
|
|
983
|
+
results: []
|
|
984
|
+
};
|
|
985
|
+
}
|
|
986
|
+
tasks.forEach((t, index) => {
|
|
987
|
+
this.logger.log(`Task ${index + 1}: ${t.agentId} -> "${t.task.substring(0, 50)}..."`);
|
|
988
|
+
});
|
|
989
|
+
const startTime = Date.now();
|
|
990
|
+
const results = await Promise.all(tasks.map(async (taskItem, index) => {
|
|
991
|
+
const taskStartTime = Date.now();
|
|
992
|
+
try {
|
|
993
|
+
const result = await this.executeAgent({
|
|
994
|
+
agentId: taskItem.agentId,
|
|
995
|
+
task: taskItem.task,
|
|
996
|
+
projectPath: taskItem.projectPath,
|
|
997
|
+
context: taskItem.context,
|
|
998
|
+
});
|
|
999
|
+
const taskDuration = Date.now() - taskStartTime;
|
|
1000
|
+
return {
|
|
1001
|
+
index: index + 1,
|
|
1002
|
+
agentId: taskItem.agentId,
|
|
1003
|
+
task: taskItem.task,
|
|
1004
|
+
success: result.success,
|
|
1005
|
+
implementation: result.implementation || result.error,
|
|
1006
|
+
provider: result.provider,
|
|
1007
|
+
duration: taskDuration,
|
|
1008
|
+
error: result.error,
|
|
1009
|
+
context: taskItem.context,
|
|
1010
|
+
workingDirectory: taskItem.projectPath || `Default for ${taskItem.agentId}`,
|
|
1011
|
+
recommendations: result.recommendations || [],
|
|
1012
|
+
taskId: result.taskId
|
|
1013
|
+
};
|
|
1014
|
+
}
|
|
1015
|
+
catch (error) {
|
|
1016
|
+
const taskDuration = Date.now() - taskStartTime;
|
|
1017
|
+
return {
|
|
1018
|
+
index: index + 1,
|
|
1019
|
+
agentId: taskItem.agentId,
|
|
1020
|
+
task: taskItem.task,
|
|
1021
|
+
success: false,
|
|
1022
|
+
implementation: null,
|
|
1023
|
+
provider: 'unknown',
|
|
1024
|
+
duration: taskDuration,
|
|
1025
|
+
error: error.message || 'Unknown error occurred',
|
|
1026
|
+
context: taskItem.context,
|
|
1027
|
+
workingDirectory: taskItem.projectPath || `Default for ${taskItem.agentId}`,
|
|
1028
|
+
recommendations: [],
|
|
1029
|
+
taskId: null
|
|
1030
|
+
};
|
|
1031
|
+
}
|
|
1032
|
+
}));
|
|
1033
|
+
const totalDuration = Date.now() - startTime;
|
|
1034
|
+
const successCount = results.filter(r => r.success).length;
|
|
1035
|
+
const failureCount = results.length - successCount;
|
|
1036
|
+
this.logger.log(`Parallel execution completed: ${successCount} success, ${failureCount} failed, ${totalDuration}ms total`);
|
|
1037
|
+
const responseText = `⚡ **Parallel Agent Execution Results**
|
|
1038
|
+
|
|
1039
|
+
**Summary:**
|
|
1040
|
+
- Total Tasks: ${results.length}
|
|
1041
|
+
- Successful: ${successCount}
|
|
1042
|
+
- Failed: ${failureCount}
|
|
1043
|
+
- Total Duration: ${totalDuration}ms
|
|
1044
|
+
- Average Duration: ${Math.round(totalDuration / results.length)}ms per task
|
|
1045
|
+
|
|
1046
|
+
**Individual Results:**
|
|
1047
|
+
|
|
1048
|
+
${results.map(result => `---
|
|
1049
|
+
**${result.index}. Agent: ${result.agentId}** (${result.provider}) - ${result.duration}ms
|
|
1050
|
+
**Task:** ${result.task}
|
|
1051
|
+
**Status:** ${result.success ? '✅ Success' : '❌ Failed'}
|
|
1052
|
+
**Working Directory:** ${result.workingDirectory}
|
|
1053
|
+
${result.context ? `**Context:** ${result.context}\n` : ''}
|
|
1054
|
+
**Implementation:**
|
|
1055
|
+
${result.success ? result.implementation : `Error: ${result.error}`}
|
|
1056
|
+
|
|
1057
|
+
${result.recommendations.length > 0 ? `**Recommendations:**
|
|
1058
|
+
${result.recommendations.map((recommendation) => `• ${recommendation}`).join('\n')}` : ''}
|
|
1059
|
+
`).join('\n')}
|
|
1060
|
+
|
|
1061
|
+
**Performance Insights:**
|
|
1062
|
+
- Fastest Task: ${Math.min(...results.map(r => r.duration))}ms
|
|
1063
|
+
- Slowest Task: ${Math.max(...results.map(r => r.duration))}ms
|
|
1064
|
+
- Parallel processing saved approximately ${Math.max(0, results.reduce((sum, r) => sum + r.duration, 0) - totalDuration)}ms compared to sequential execution
|
|
1065
|
+
|
|
1066
|
+
**⚠️ Important Notes:**
|
|
1067
|
+
- All tasks were executed in IMPLEMENTATION MODE with potential file modifications
|
|
1068
|
+
- Review all provided implementations before applying changes
|
|
1069
|
+
- Test in development environment first
|
|
1070
|
+
- Consider backing up files before making modifications`;
|
|
1071
|
+
return {
|
|
1072
|
+
content: [
|
|
1073
|
+
{
|
|
1074
|
+
type: 'text',
|
|
1075
|
+
text: responseText
|
|
1076
|
+
}
|
|
1077
|
+
],
|
|
1078
|
+
success: true,
|
|
1079
|
+
summary: {
|
|
1080
|
+
totalTasks: results.length,
|
|
1081
|
+
successful: successCount,
|
|
1082
|
+
failed: failureCount,
|
|
1083
|
+
totalDuration,
|
|
1084
|
+
averageDuration: Math.round(totalDuration / results.length)
|
|
1085
|
+
},
|
|
1086
|
+
results: results,
|
|
1087
|
+
performance: {
|
|
1088
|
+
fastestTask: Math.min(...results.map(r => r.duration)),
|
|
1089
|
+
slowestTask: Math.max(...results.map(r => r.duration)),
|
|
1090
|
+
timeSaved: Math.max(0, results.reduce((sum, r) => sum + r.duration, 0) - totalDuration)
|
|
1091
|
+
},
|
|
1092
|
+
executionMode: true
|
|
1093
|
+
};
|
|
1094
|
+
}
|
|
1095
|
+
catch (error) {
|
|
1096
|
+
const errorMessage = (0, crewx_sdk_1.getErrorMessage)(error);
|
|
1097
|
+
this.logger.error('Parallel agent execution failed:', errorMessage);
|
|
1098
|
+
return {
|
|
1099
|
+
content: [
|
|
1100
|
+
{
|
|
1101
|
+
type: 'text',
|
|
1102
|
+
text: `❌ **Parallel Agent Execution Failed**
|
|
1103
|
+
|
|
1104
|
+
**Error:** ${errorMessage}
|
|
1105
|
+
|
|
1106
|
+
**Total Tasks:** ${args.tasks?.length || 0}
|
|
1107
|
+
|
|
1108
|
+
Execution Mode: Implementation guidance could not be provided.`
|
|
1109
|
+
}
|
|
1110
|
+
],
|
|
1111
|
+
success: false,
|
|
1112
|
+
error: errorMessage,
|
|
1113
|
+
results: [],
|
|
1114
|
+
executionMode: true
|
|
1115
|
+
};
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
async clearAllLogs() {
|
|
1119
|
+
try {
|
|
1120
|
+
const logsDir = path.join(process.cwd(), '.crewx', 'logs');
|
|
1121
|
+
if (!fs.existsSync(logsDir)) {
|
|
1122
|
+
return {
|
|
1123
|
+
content: [
|
|
1124
|
+
{
|
|
1125
|
+
type: 'text',
|
|
1126
|
+
text: `📁 **Log Directory Status**
|
|
1127
|
+
|
|
1128
|
+
❌ **No logs directory found**
|
|
1129
|
+
|
|
1130
|
+
The logs directory \`.crewx/logs\` does not exist. Nothing to clean.
|
|
1131
|
+
|
|
1132
|
+
**Path checked:** \`${logsDir}\`
|
|
1133
|
+
`
|
|
1134
|
+
}
|
|
1135
|
+
],
|
|
1136
|
+
success: true,
|
|
1137
|
+
message: 'No logs directory found',
|
|
1138
|
+
path: logsDir
|
|
1139
|
+
};
|
|
1140
|
+
}
|
|
1141
|
+
const files = fs.readdirSync(logsDir);
|
|
1142
|
+
const logFiles = files.filter(file => file.endsWith('.log'));
|
|
1143
|
+
if (logFiles.length === 0) {
|
|
1144
|
+
return {
|
|
1145
|
+
content: [
|
|
1146
|
+
{
|
|
1147
|
+
type: 'text',
|
|
1148
|
+
text: `📁 **Log Directory Status**
|
|
1149
|
+
|
|
1150
|
+
✅ **Already clean**
|
|
1151
|
+
|
|
1152
|
+
The logs directory exists but contains no log files to clean.
|
|
1153
|
+
|
|
1154
|
+
**Directory:** \`${logsDir}\`
|
|
1155
|
+
**Total files:** ${files.length}
|
|
1156
|
+
**Log files:** 0
|
|
1157
|
+
`
|
|
1158
|
+
}
|
|
1159
|
+
],
|
|
1160
|
+
success: true,
|
|
1161
|
+
message: 'No log files to clean',
|
|
1162
|
+
path: logsDir,
|
|
1163
|
+
totalFiles: files.length,
|
|
1164
|
+
logFiles: 0
|
|
1165
|
+
};
|
|
1166
|
+
}
|
|
1167
|
+
let totalSize = 0;
|
|
1168
|
+
let deletedCount = 0;
|
|
1169
|
+
const deletedFiles = [];
|
|
1170
|
+
for (const file of logFiles) {
|
|
1171
|
+
const filePath = path.join(logsDir, file);
|
|
1172
|
+
try {
|
|
1173
|
+
const stats = fs.statSync(filePath);
|
|
1174
|
+
totalSize += stats.size;
|
|
1175
|
+
fs.unlinkSync(filePath);
|
|
1176
|
+
deletedCount++;
|
|
1177
|
+
deletedFiles.push(file);
|
|
1178
|
+
}
|
|
1179
|
+
catch (error) {
|
|
1180
|
+
this.logger.warn(`Failed to delete log file ${file}:`, error);
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
const formatSize = (bytes) => {
|
|
1184
|
+
if (bytes === 0)
|
|
1185
|
+
return '0 B';
|
|
1186
|
+
const k = 1024;
|
|
1187
|
+
const sizes = ['B', 'KB', 'MB', 'GB'];
|
|
1188
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
1189
|
+
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
|
|
1190
|
+
};
|
|
1191
|
+
return {
|
|
1192
|
+
content: [
|
|
1193
|
+
{
|
|
1194
|
+
type: 'text',
|
|
1195
|
+
text: `🗑️ **Log Cleanup Complete**
|
|
1196
|
+
|
|
1197
|
+
✅ **Successfully cleared all log files**
|
|
1198
|
+
|
|
1199
|
+
**Directory:** \`${logsDir}\`
|
|
1200
|
+
**Files deleted:** ${deletedCount}
|
|
1201
|
+
**Total space freed:** ${formatSize(totalSize)}
|
|
1202
|
+
|
|
1203
|
+
${deletedCount > 10 ?
|
|
1204
|
+
`**Sample deleted files:**
|
|
1205
|
+
${deletedFiles.slice(0, 10).map(f => ` • ${f}`).join('\n')}
|
|
1206
|
+
• ... and ${deletedCount - 10} more files` :
|
|
1207
|
+
`**Deleted files:**
|
|
1208
|
+
${deletedFiles.map(f => ` • ${f}`).join('\n')}`}
|
|
1209
|
+
|
|
1210
|
+
The logs directory is now clean and ready for new task logs. 🧹✨
|
|
1211
|
+
`
|
|
1212
|
+
}
|
|
1213
|
+
],
|
|
1214
|
+
success: true,
|
|
1215
|
+
message: 'All log files cleared successfully',
|
|
1216
|
+
path: logsDir,
|
|
1217
|
+
deletedCount,
|
|
1218
|
+
totalSize,
|
|
1219
|
+
deletedFiles: deletedFiles.slice(0, 20)
|
|
1220
|
+
};
|
|
1221
|
+
}
|
|
1222
|
+
catch (error) {
|
|
1223
|
+
this.logger.error('Failed to clear logs:', error);
|
|
1224
|
+
return {
|
|
1225
|
+
content: [
|
|
1226
|
+
{
|
|
1227
|
+
type: 'text',
|
|
1228
|
+
text: `❌ **Log Cleanup Failed**
|
|
1229
|
+
|
|
1230
|
+
**Error:** ${error.message}
|
|
1231
|
+
|
|
1232
|
+
Please check permissions and try again, or manually delete files from \`.crewx/logs/\` directory.
|
|
1233
|
+
`
|
|
1234
|
+
}
|
|
1235
|
+
],
|
|
1236
|
+
success: false,
|
|
1237
|
+
error: error.message
|
|
1238
|
+
};
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
async getAvailableProvider(providerConfig) {
|
|
1242
|
+
const defaultFallbackOrder = ['claude', 'gemini', 'copilot'];
|
|
1243
|
+
let fallbackOrder;
|
|
1244
|
+
if (!providerConfig) {
|
|
1245
|
+
fallbackOrder = defaultFallbackOrder;
|
|
1246
|
+
}
|
|
1247
|
+
else if (Array.isArray(providerConfig)) {
|
|
1248
|
+
fallbackOrder = providerConfig;
|
|
1249
|
+
}
|
|
1250
|
+
else {
|
|
1251
|
+
fallbackOrder = [providerConfig, ...defaultFallbackOrder.filter(p => p !== providerConfig)];
|
|
1252
|
+
}
|
|
1253
|
+
for (const providerName of fallbackOrder) {
|
|
1254
|
+
const provider = this.aiProviderService.getProvider(providerName);
|
|
1255
|
+
if (provider) {
|
|
1256
|
+
const isAvailable = await provider.isAvailable();
|
|
1257
|
+
if (isAvailable) {
|
|
1258
|
+
if (fallbackOrder.indexOf(providerName) > 0) {
|
|
1259
|
+
this.logger.log(`Using fallback provider: ${providerName} (tried: ${fallbackOrder.slice(0, fallbackOrder.indexOf(providerName)).join(', ')})`);
|
|
1260
|
+
}
|
|
1261
|
+
return providerName;
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
this.logger.warn('No providers available, defaulting to claude');
|
|
1266
|
+
return 'claude';
|
|
1267
|
+
}
|
|
1268
|
+
};
|
|
1269
|
+
exports.CrewXTool = CrewXTool;
|
|
1270
|
+
__decorate([
|
|
1271
|
+
(0, nestjs_mcp_adapter_1.McpTool)({
|
|
1272
|
+
server: crewx_sdk_1.SERVER_NAME,
|
|
1273
|
+
name: `${crewx_sdk_1.PREFIX_TOOL_NAME}getTaskLogs`,
|
|
1274
|
+
description: 'Get task logs by task ID to monitor progress and detailed execution logs.',
|
|
1275
|
+
input: {
|
|
1276
|
+
taskId: zod_1.z.string().optional().describe('Task ID to get logs for. If not provided, returns all recent tasks.')
|
|
1277
|
+
},
|
|
1278
|
+
annotations: {
|
|
1279
|
+
title: 'Get Task Logs',
|
|
1280
|
+
readOnlyHint: true,
|
|
1281
|
+
desctructiveHint: false
|
|
1282
|
+
}
|
|
1283
|
+
}),
|
|
1284
|
+
__metadata("design:type", Function),
|
|
1285
|
+
__metadata("design:paramtypes", [Object]),
|
|
1286
|
+
__metadata("design:returntype", Promise)
|
|
1287
|
+
], CrewXTool.prototype, "getTaskLogs", null);
|
|
1288
|
+
__decorate([
|
|
1289
|
+
(0, nestjs_mcp_adapter_1.McpTool)({
|
|
1290
|
+
server: crewx_sdk_1.SERVER_NAME,
|
|
1291
|
+
name: `${crewx_sdk_1.PREFIX_TOOL_NAME}checkAIProviders`,
|
|
1292
|
+
description: 'Check the status of available AI CLI tools (Claude, Gemini, GitHub Copilot).',
|
|
1293
|
+
input: {},
|
|
1294
|
+
annotations: {
|
|
1295
|
+
title: 'Check AI Providers Status',
|
|
1296
|
+
readOnlyHint: true,
|
|
1297
|
+
desctructiveHint: false
|
|
1298
|
+
}
|
|
1299
|
+
}),
|
|
1300
|
+
__metadata("design:type", Function),
|
|
1301
|
+
__metadata("design:paramtypes", []),
|
|
1302
|
+
__metadata("design:returntype", Promise)
|
|
1303
|
+
], CrewXTool.prototype, "checkAIProviders", null);
|
|
1304
|
+
__decorate([
|
|
1305
|
+
(0, nestjs_mcp_adapter_1.McpTool)({
|
|
1306
|
+
server: crewx_sdk_1.SERVER_NAME,
|
|
1307
|
+
name: `${crewx_sdk_1.PREFIX_TOOL_NAME}listAgents`,
|
|
1308
|
+
description: 'List available specialist AI agents that can be utilized. Each agent is specialized in a specific domain.',
|
|
1309
|
+
input: {},
|
|
1310
|
+
annotations: {
|
|
1311
|
+
title: 'List Available AI Agents',
|
|
1312
|
+
readOnlyHint: true,
|
|
1313
|
+
desctructiveHint: false
|
|
1314
|
+
}
|
|
1315
|
+
}),
|
|
1316
|
+
__metadata("design:type", Function),
|
|
1317
|
+
__metadata("design:paramtypes", []),
|
|
1318
|
+
__metadata("design:returntype", Promise)
|
|
1319
|
+
], CrewXTool.prototype, "listAgents", null);
|
|
1320
|
+
__decorate([
|
|
1321
|
+
(0, nestjs_mcp_adapter_1.McpTool)({
|
|
1322
|
+
server: crewx_sdk_1.SERVER_NAME,
|
|
1323
|
+
name: `${crewx_sdk_1.PREFIX_TOOL_NAME}queryAgent`,
|
|
1324
|
+
description: 'Query a specific specialist agent (read-only mode). You can request code analysis, explanations, reviews, etc. No file modifications will be performed.',
|
|
1325
|
+
input: {
|
|
1326
|
+
agentId: zod_1.z.string().describe('Agent ID to query (e.g., frontend_developer, backend_developer, devops_engineer, security_analyst, or custom agents)'),
|
|
1327
|
+
query: zod_1.z.string().describe('Question or request to ask the agent'),
|
|
1328
|
+
projectPath: zod_1.z.string().describe('Absolute path of the project to analyze').optional(),
|
|
1329
|
+
context: zod_1.z.string().describe('Additional context or background information').optional(),
|
|
1330
|
+
model: zod_1.z.string().describe('Model to use for this query (e.g., sonnet, gemini-2.5-pro, gpt-5)').optional(),
|
|
1331
|
+
messages: zod_1.z.array(zod_1.z.object({
|
|
1332
|
+
text: zod_1.z.string(),
|
|
1333
|
+
isAssistant: zod_1.z.boolean(),
|
|
1334
|
+
metadata: zod_1.z.record(zod_1.z.any()).optional(),
|
|
1335
|
+
})).describe('Conversation history to provide as context (oldest → newest)').optional(),
|
|
1336
|
+
},
|
|
1337
|
+
annotations: {
|
|
1338
|
+
title: 'Query Specialist Agent (Read-Only)',
|
|
1339
|
+
readOnlyHint: true,
|
|
1340
|
+
desctructiveHint: false
|
|
1341
|
+
}
|
|
1342
|
+
}),
|
|
1343
|
+
__metadata("design:type", Function),
|
|
1344
|
+
__metadata("design:paramtypes", [Object]),
|
|
1345
|
+
__metadata("design:returntype", Promise)
|
|
1346
|
+
], CrewXTool.prototype, "queryAgent", null);
|
|
1347
|
+
__decorate([
|
|
1348
|
+
(0, nestjs_mcp_adapter_1.McpTool)({
|
|
1349
|
+
server: crewx_sdk_1.SERVER_NAME,
|
|
1350
|
+
name: `${crewx_sdk_1.PREFIX_TOOL_NAME}executeAgent`,
|
|
1351
|
+
description: 'Execute tasks through a specialist agent. Can provide implementation guidance, code examples, and actionable solutions.',
|
|
1352
|
+
input: {
|
|
1353
|
+
agentId: zod_1.z.string().describe('Agent ID to execute (e.g., frontend_developer, backend_developer, devops_engineer, security_analyst, or custom agents)'),
|
|
1354
|
+
task: zod_1.z.string().describe('Task or implementation request for the agent to perform'),
|
|
1355
|
+
projectPath: zod_1.z.string().describe('Absolute path of the project to work on').optional(),
|
|
1356
|
+
context: zod_1.z.string().describe('Additional context or background information').optional(),
|
|
1357
|
+
model: zod_1.z.string().describe('Model to use for this execution (e.g., sonnet, gemini-2.5-pro, gpt-5)').optional(),
|
|
1358
|
+
messages: zod_1.z.array(zod_1.z.object({
|
|
1359
|
+
text: zod_1.z.string(),
|
|
1360
|
+
isAssistant: zod_1.z.boolean(),
|
|
1361
|
+
metadata: zod_1.z.record(zod_1.z.any()).optional(),
|
|
1362
|
+
})).describe('Conversation history to provide as context (oldest → newest)').optional(),
|
|
1363
|
+
},
|
|
1364
|
+
annotations: {
|
|
1365
|
+
title: 'Execute Agent Task (Can Modify Files)',
|
|
1366
|
+
readOnlyHint: false,
|
|
1367
|
+
desctructiveHint: true
|
|
1368
|
+
}
|
|
1369
|
+
}),
|
|
1370
|
+
__metadata("design:type", Function),
|
|
1371
|
+
__metadata("design:paramtypes", [Object]),
|
|
1372
|
+
__metadata("design:returntype", Promise)
|
|
1373
|
+
], CrewXTool.prototype, "executeAgent", null);
|
|
1374
|
+
__decorate([
|
|
1375
|
+
(0, nestjs_mcp_adapter_1.McpTool)({
|
|
1376
|
+
server: crewx_sdk_1.SERVER_NAME,
|
|
1377
|
+
name: `${crewx_sdk_1.PREFIX_TOOL_NAME}queryAgentParallel`,
|
|
1378
|
+
description: 'Query multiple specialist agents simultaneously in parallel (read-only mode). Efficiently send multiple tasks to the same agent or different questions to various agents.',
|
|
1379
|
+
input: {
|
|
1380
|
+
queries: zod_1.z.array(zod_1.z.object({
|
|
1381
|
+
agentId: zod_1.z.string().describe('Agent ID to query (e.g., frontend_developer, backend_developer, gmail_mcp_developer, etc.)'),
|
|
1382
|
+
query: zod_1.z.string().describe('Question or request to ask the agent'),
|
|
1383
|
+
projectPath: zod_1.z.string().describe('Absolute path of the project to analyze').optional(),
|
|
1384
|
+
context: zod_1.z.string().describe('Additional context or background information').optional(),
|
|
1385
|
+
model: zod_1.z.string().describe('Model to use for this query').optional(),
|
|
1386
|
+
messages: zod_1.z.array(zod_1.z.object({
|
|
1387
|
+
text: zod_1.z.string(),
|
|
1388
|
+
isAssistant: zod_1.z.boolean(),
|
|
1389
|
+
metadata: zod_1.z.record(zod_1.z.any()).optional(),
|
|
1390
|
+
})).describe('Conversation history to provide as context (oldest → newest)').optional(),
|
|
1391
|
+
})).describe('Array of queries to process in parallel'),
|
|
1392
|
+
},
|
|
1393
|
+
annotations: {
|
|
1394
|
+
title: 'Query Multiple Agents in Parallel (Read-Only)',
|
|
1395
|
+
readOnlyHint: true,
|
|
1396
|
+
desctructiveHint: false
|
|
1397
|
+
}
|
|
1398
|
+
}),
|
|
1399
|
+
__metadata("design:type", Function),
|
|
1400
|
+
__metadata("design:paramtypes", [Object]),
|
|
1401
|
+
__metadata("design:returntype", Promise)
|
|
1402
|
+
], CrewXTool.prototype, "queryAgentParallel", null);
|
|
1403
|
+
__decorate([
|
|
1404
|
+
(0, nestjs_mcp_adapter_1.McpTool)({
|
|
1405
|
+
server: crewx_sdk_1.SERVER_NAME,
|
|
1406
|
+
name: `${crewx_sdk_1.PREFIX_TOOL_NAME}executeAgentParallel`,
|
|
1407
|
+
description: 'Execute multiple tasks through specialist agents simultaneously in parallel (execution mode). Efficiently distribute implementation work across multiple agents.',
|
|
1408
|
+
input: {
|
|
1409
|
+
tasks: zod_1.z.array(zod_1.z.object({
|
|
1410
|
+
agentId: zod_1.z.string().describe('Agent ID to execute (e.g., frontend_developer, backend_developer, crewx_developer_claude, etc.)'),
|
|
1411
|
+
task: zod_1.z.string().describe('Task or implementation request for the agent to perform'),
|
|
1412
|
+
projectPath: zod_1.z.string().describe('Absolute path of the project to work on').optional(),
|
|
1413
|
+
context: zod_1.z.string().describe('Additional context or background information').optional(),
|
|
1414
|
+
model: zod_1.z.string().describe('Model to use for this execution').optional(),
|
|
1415
|
+
messages: zod_1.z.array(zod_1.z.object({
|
|
1416
|
+
text: zod_1.z.string(),
|
|
1417
|
+
isAssistant: zod_1.z.boolean(),
|
|
1418
|
+
metadata: zod_1.z.record(zod_1.z.any()).optional(),
|
|
1419
|
+
})).describe('Conversation history to provide as context (oldest → newest)').optional(),
|
|
1420
|
+
})).describe('Array of tasks to execute in parallel'),
|
|
1421
|
+
},
|
|
1422
|
+
annotations: {
|
|
1423
|
+
title: 'Execute Multiple Agent Tasks in Parallel (Can Modify Files)',
|
|
1424
|
+
readOnlyHint: false,
|
|
1425
|
+
desctructiveHint: true
|
|
1426
|
+
}
|
|
1427
|
+
}),
|
|
1428
|
+
__metadata("design:type", Function),
|
|
1429
|
+
__metadata("design:paramtypes", [Object]),
|
|
1430
|
+
__metadata("design:returntype", Promise)
|
|
1431
|
+
], CrewXTool.prototype, "executeAgentParallel", null);
|
|
1432
|
+
__decorate([
|
|
1433
|
+
(0, nestjs_mcp_adapter_1.McpTool)({
|
|
1434
|
+
server: crewx_sdk_1.SERVER_NAME,
|
|
1435
|
+
name: `${crewx_sdk_1.PREFIX_TOOL_NAME}clearAllLogs`,
|
|
1436
|
+
description: 'Clear all log files from the .crewx/logs directory to clean up accumulated task logs',
|
|
1437
|
+
input: {},
|
|
1438
|
+
annotations: {
|
|
1439
|
+
title: 'Clear All Logs',
|
|
1440
|
+
readOnlyHint: false,
|
|
1441
|
+
}
|
|
1442
|
+
}),
|
|
1443
|
+
__metadata("design:type", Function),
|
|
1444
|
+
__metadata("design:paramtypes", []),
|
|
1445
|
+
__metadata("design:returntype", Promise)
|
|
1446
|
+
], CrewXTool.prototype, "clearAllLogs", null);
|
|
1447
|
+
exports.CrewXTool = CrewXTool = CrewXTool_1 = __decorate([
|
|
1448
|
+
(0, common_1.Injectable)(),
|
|
1449
|
+
__metadata("design:paramtypes", [ai_service_1.AIService,
|
|
1450
|
+
ai_provider_service_1.AIProviderService,
|
|
1451
|
+
project_service_1.ProjectService,
|
|
1452
|
+
parallel_processing_service_1.ParallelProcessingService,
|
|
1453
|
+
task_management_service_1.TaskManagementService,
|
|
1454
|
+
result_formatter_service_1.ResultFormatterService,
|
|
1455
|
+
template_service_1.TemplateService,
|
|
1456
|
+
document_loader_service_1.DocumentLoaderService,
|
|
1457
|
+
tool_call_service_1.ToolCallService,
|
|
1458
|
+
agent_loader_service_1.AgentLoaderService,
|
|
1459
|
+
remote_agent_service_1.RemoteAgentService])
|
|
1460
|
+
], CrewXTool);
|
|
1461
|
+
//# sourceMappingURL=crewx.tool.js.map
|