@sowonai/crewx-cli 0.4.0-dev.27 → 0.4.0-dev.29
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 +4 -0
- package/dist/app.module.js +3 -1
- package/dist/app.module.js.map +1 -1
- package/dist/cli/chat.handler.d.ts +2 -1
- package/dist/cli/chat.handler.js +17 -6
- package/dist/cli/chat.handler.js.map +1 -1
- package/dist/cli/doctor.handler.js +8 -40
- package/dist/cli/doctor.handler.js.map +1 -1
- package/dist/cli/execute.handler.js +2 -0
- package/dist/cli/execute.handler.js.map +1 -1
- package/dist/cli/query.handler.js +4 -2
- package/dist/cli/query.handler.js.map +1 -1
- package/dist/cli-options.d.ts +2 -0
- package/dist/cli-options.js +10 -0
- package/dist/cli-options.js.map +1 -1
- package/dist/crewx.tool.d.ts +15 -2
- package/dist/crewx.tool.js +370 -75
- package/dist/crewx.tool.js.map +1 -1
- package/dist/services/agent-loader.service.d.ts +1 -0
- package/dist/services/agent-loader.service.js +93 -25
- package/dist/services/agent-loader.service.js.map +1 -1
- package/dist/services/config.service.d.ts +7 -27
- package/dist/services/config.service.js +80 -38
- package/dist/services/config.service.js.map +1 -1
- package/dist/services/parallel-processing.service.d.ts +2 -0
- package/dist/services/parallel-processing.service.js +35 -3
- package/dist/services/parallel-processing.service.js.map +1 -1
- package/dist/services/provider-bridge.service.d.ts +35 -0
- package/dist/services/provider-bridge.service.js +224 -0
- package/dist/services/provider-bridge.service.js.map +1 -0
- package/dist/utils/template-processor.d.ts +2 -29
- package/dist/utils/template-processor.js +1 -1
- package/dist/utils/template-processor.js.map +1 -1
- package/package.json +2 -2
- package/templates/agents/default.yaml +110 -81
- package/templates/agents/minimal.yaml +6 -0
- package/templates/versions.json +1 -1
package/dist/crewx.tool.js
CHANGED
|
@@ -47,6 +47,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
47
47
|
var CrewXTool_1;
|
|
48
48
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
49
49
|
exports.CrewXTool = void 0;
|
|
50
|
+
const crewx_sdk_1 = require("@sowonai/crewx-sdk");
|
|
50
51
|
const common_1 = require("@nestjs/common");
|
|
51
52
|
const nestjs_mcp_adapter_1 = require("@sowonai/nestjs-mcp-adapter");
|
|
52
53
|
const zod_1 = require("zod");
|
|
@@ -56,7 +57,6 @@ const crypto = __importStar(require("crypto"));
|
|
|
56
57
|
const ai_service_1 = require("./ai.service");
|
|
57
58
|
const ai_provider_service_1 = require("./ai-provider.service");
|
|
58
59
|
const project_service_1 = require("./project.service");
|
|
59
|
-
const crewx_sdk_1 = require("@sowonai/crewx-sdk");
|
|
60
60
|
const parallel_processing_service_1 = require("./services/parallel-processing.service");
|
|
61
61
|
const task_management_service_1 = require("./services/task-management.service");
|
|
62
62
|
const result_formatter_service_1 = require("./services/result-formatter.service");
|
|
@@ -65,6 +65,7 @@ const document_loader_service_1 = require("./services/document-loader.service");
|
|
|
65
65
|
const tool_call_service_1 = require("./services/tool-call.service");
|
|
66
66
|
const agent_loader_service_1 = require("./services/agent-loader.service");
|
|
67
67
|
const remote_agent_service_1 = require("./services/remote-agent.service");
|
|
68
|
+
const provider_bridge_service_1 = require("./services/provider-bridge.service");
|
|
68
69
|
let CrewXTool = CrewXTool_1 = class CrewXTool {
|
|
69
70
|
generateSecurityKey() {
|
|
70
71
|
return crypto.randomBytes(8).toString('hex');
|
|
@@ -125,7 +126,7 @@ let CrewXTool = CrewXTool_1 = class CrewXTool {
|
|
|
125
126
|
};
|
|
126
127
|
return JSON.stringify(payload);
|
|
127
128
|
}
|
|
128
|
-
constructor(aiService, aiProviderService, projectService, parallelProcessingService, taskManagementService, resultFormatterService, templateService, documentLoaderService, toolCallService, agentLoaderService, remoteAgentService, layoutLoader, layoutRenderer) {
|
|
129
|
+
constructor(aiService, aiProviderService, projectService, parallelProcessingService, taskManagementService, resultFormatterService, templateService, documentLoaderService, toolCallService, agentLoaderService, remoteAgentService, providerBridgeService, layoutLoader, layoutRenderer) {
|
|
129
130
|
this.aiService = aiService;
|
|
130
131
|
this.aiProviderService = aiProviderService;
|
|
131
132
|
this.projectService = projectService;
|
|
@@ -137,6 +138,7 @@ let CrewXTool = CrewXTool_1 = class CrewXTool {
|
|
|
137
138
|
this.toolCallService = toolCallService;
|
|
138
139
|
this.agentLoaderService = agentLoaderService;
|
|
139
140
|
this.remoteAgentService = remoteAgentService;
|
|
141
|
+
this.providerBridgeService = providerBridgeService;
|
|
140
142
|
this.layoutLoader = layoutLoader;
|
|
141
143
|
this.layoutRenderer = layoutRenderer;
|
|
142
144
|
this.logger = new common_1.Logger(CrewXTool_1.name);
|
|
@@ -174,9 +176,7 @@ let CrewXTool = CrewXTool_1 = class CrewXTool {
|
|
|
174
176
|
const inlineConfig = agent.inline
|
|
175
177
|
? { ...agent.inline, prompt: baseSystemPrompt }
|
|
176
178
|
: { prompt: baseSystemPrompt };
|
|
177
|
-
const templateOptions =
|
|
178
|
-
? templateContext.options
|
|
179
|
-
: [];
|
|
179
|
+
const templateOptions = [];
|
|
180
180
|
const sessionInfo = {
|
|
181
181
|
mode: templateContext.mode ?? 'query',
|
|
182
182
|
platform: templateContext.platform ?? 'cli',
|
|
@@ -186,6 +186,7 @@ let CrewXTool = CrewXTool_1 = class CrewXTool {
|
|
|
186
186
|
tools: templateContext.tools ?? null,
|
|
187
187
|
};
|
|
188
188
|
const renderContext = {
|
|
189
|
+
user_input: templateContext.user_input,
|
|
189
190
|
agent: {
|
|
190
191
|
id: agent.id,
|
|
191
192
|
name: agent.name || agent.id,
|
|
@@ -276,11 +277,29 @@ let CrewXTool = CrewXTool_1 = class CrewXTool {
|
|
|
276
277
|
const availableProviders = await this.aiService.checkAvailableProviders();
|
|
277
278
|
const installation = await this.aiService.validateCLIInstallation();
|
|
278
279
|
const recommendations = this.getInstallationRecommendations(installation);
|
|
280
|
+
const bridgeProviders = this.providerBridgeService.listAvailableProviders();
|
|
281
|
+
let bridgeStatus = '⚠️ ProviderBridge: no providers registered.';
|
|
282
|
+
if (bridgeProviders.length > 0) {
|
|
283
|
+
try {
|
|
284
|
+
const { resolution } = await this.providerBridgeService.createAgentRuntime({
|
|
285
|
+
provider: bridgeProviders[0],
|
|
286
|
+
defaultAgentId: 'provider-bridge-check',
|
|
287
|
+
});
|
|
288
|
+
bridgeStatus = `✅ ProviderBridge ready (${resolution.provider.name})`;
|
|
289
|
+
}
|
|
290
|
+
catch (error) {
|
|
291
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
292
|
+
bridgeStatus = `❌ ProviderBridge error: ${message}`;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
279
295
|
const responseText = `🤖 **AI Providers Status**
|
|
280
296
|
|
|
281
297
|
**Available Providers:**
|
|
282
298
|
${availableProviders.length > 0 ? availableProviders.map(p => `✅ ${p}`).join('\n') : '❌ No providers available'}
|
|
283
299
|
|
|
300
|
+
**Provider Bridge:**
|
|
301
|
+
${bridgeStatus}${bridgeProviders.length > 0 ? `\nRegistered: ${bridgeProviders.join(', ')}` : ''}
|
|
302
|
+
|
|
284
303
|
**Installation Status:**
|
|
285
304
|
• Claude CLI: ${installation.claude ? '✅ Installed' : '❌ Not Installed'}
|
|
286
305
|
• Gemini CLI: ${installation.gemini ? '✅ Installed' : '❌ Not Installed'}
|
|
@@ -302,6 +321,10 @@ ${recommendations.map(r => `• ${r}`).join('\n')}`;
|
|
|
302
321
|
gemini: installation.gemini,
|
|
303
322
|
copilot: installation.copilot,
|
|
304
323
|
},
|
|
324
|
+
providerBridge: {
|
|
325
|
+
status: bridgeStatus,
|
|
326
|
+
providers: bridgeProviders,
|
|
327
|
+
},
|
|
305
328
|
recommendations,
|
|
306
329
|
};
|
|
307
330
|
}
|
|
@@ -326,7 +349,11 @@ No AI providers could be verified.`
|
|
|
326
349
|
claude: { installed: false },
|
|
327
350
|
gemini: { installed: false },
|
|
328
351
|
copilot: { installed: false }
|
|
329
|
-
}
|
|
352
|
+
},
|
|
353
|
+
providerBridge: {
|
|
354
|
+
status: '❌ ProviderBridge inspection skipped due to error',
|
|
355
|
+
providers: [],
|
|
356
|
+
},
|
|
330
357
|
};
|
|
331
358
|
}
|
|
332
359
|
}
|
|
@@ -530,56 +557,134 @@ ${errorMessage}`,
|
|
|
530
557
|
const securityKey = this.generateSecurityKey();
|
|
531
558
|
const contextMessages = messages && messages.length > 0 ? messages.slice(0, -1) : [];
|
|
532
559
|
const templateContext = {
|
|
533
|
-
|
|
560
|
+
user_input: query,
|
|
561
|
+
messages: contextMessages,
|
|
534
562
|
agent: {
|
|
535
563
|
id: agent.id,
|
|
536
564
|
name: agent.name || agent.id,
|
|
537
565
|
provider: (Array.isArray(agent.provider) ? agent.provider[0] : agent.provider) || 'claude',
|
|
538
566
|
model: model || agent.inline?.model,
|
|
539
567
|
workingDirectory: workingDir,
|
|
568
|
+
inline: {
|
|
569
|
+
prompt: agent.inline?.prompt || agent.inline?.system_prompt || agent.systemPrompt || '',
|
|
570
|
+
},
|
|
571
|
+
specialties: agent.specialties,
|
|
572
|
+
capabilities: agent.capabilities,
|
|
573
|
+
description: agent.description,
|
|
540
574
|
},
|
|
541
|
-
|
|
542
|
-
messages: contextMessages,
|
|
543
|
-
platform: platform,
|
|
544
|
-
tools: this.buildToolsContext(),
|
|
575
|
+
documents: {},
|
|
545
576
|
vars: {
|
|
546
577
|
security_key: securityKey,
|
|
547
578
|
},
|
|
579
|
+
props: {},
|
|
580
|
+
mode: 'query',
|
|
581
|
+
platform: platform,
|
|
582
|
+
env: process.env,
|
|
583
|
+
tools: this.buildToolsContext(),
|
|
548
584
|
};
|
|
549
585
|
let systemPrompt = await this.processAgentSystemPrompt(agent, templateContext);
|
|
550
|
-
|
|
586
|
+
if (process.env.CREWX_APPEND_LEGACY === 'true') {
|
|
587
|
+
this.logger.debug('[WBS-14] Legacy append mode enabled (query)', {
|
|
588
|
+
agentId: agent.id,
|
|
589
|
+
layoutId: typeof agent.inline?.layout === 'string'
|
|
590
|
+
? agent.inline?.layout
|
|
591
|
+
: agent.inline?.layout?.id ?? 'crewx/default',
|
|
592
|
+
});
|
|
593
|
+
systemPrompt += `
|
|
551
594
|
|
|
552
595
|
Specialties: ${agent.specialties?.join(', ') || 'General'}
|
|
553
596
|
Capabilities: ${agent.capabilities?.join(', ') || 'Analysis'}
|
|
554
597
|
Working Directory: ${workingDir}`;
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
598
|
+
}
|
|
599
|
+
else if (process.env.CREWX_WBS14_TELEMETRY === 'true') {
|
|
600
|
+
this.logger.debug('[WBS-14] Metadata delegated to layout (query mode)', {
|
|
601
|
+
agentId: agent.id,
|
|
602
|
+
hasLayout: Boolean(agent.inline?.layout),
|
|
603
|
+
layoutId: typeof agent.inline?.layout === 'string'
|
|
604
|
+
? agent.inline?.layout
|
|
605
|
+
: agent.inline?.layout?.id ?? 'crewx/default',
|
|
606
|
+
specialtiesCount: agent.specialties?.length ?? 0,
|
|
607
|
+
capabilitiesCount: agent.capabilities?.length ?? 0,
|
|
608
|
+
workingDirectory: workingDir,
|
|
609
|
+
});
|
|
610
|
+
}
|
|
559
611
|
let fullPrompt = systemPrompt;
|
|
560
612
|
if (context) {
|
|
561
613
|
fullPrompt += `\n\n${context}`;
|
|
562
614
|
}
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
615
|
+
if (!systemPrompt.includes('<user_query')) {
|
|
616
|
+
this.logger.debug('[Legacy] Adding <user_query> wrapper manually (layout not used)');
|
|
617
|
+
fullPrompt += `\n\n<user_query key="${securityKey}">
|
|
618
|
+
${query}
|
|
619
|
+
</user_query>`;
|
|
620
|
+
}
|
|
621
|
+
let runtimeResult;
|
|
622
|
+
let providerResolution;
|
|
623
|
+
let providerInput;
|
|
624
|
+
if (args.provider) {
|
|
625
|
+
providerInput = args.provider;
|
|
626
|
+
}
|
|
627
|
+
else if (Array.isArray(agent.provider)) {
|
|
628
|
+
providerInput = await this.getAvailableProvider(agent.provider);
|
|
629
|
+
}
|
|
630
|
+
else if (typeof agent.provider === 'string' && agent.provider.trim().length > 0) {
|
|
631
|
+
providerInput = agent.provider;
|
|
632
|
+
}
|
|
633
|
+
try {
|
|
634
|
+
runtimeResult = await this.providerBridgeService.createAgentRuntime({
|
|
635
|
+
provider: providerInput,
|
|
636
|
+
defaultAgentId: agentId,
|
|
637
|
+
validAgents: agents.map(a => a.id),
|
|
638
|
+
});
|
|
639
|
+
providerResolution = runtimeResult.resolution;
|
|
640
|
+
}
|
|
641
|
+
catch (error) {
|
|
642
|
+
const errorMsg = error instanceof Error ? error.message : 'Unknown provider error';
|
|
643
|
+
this.taskManagementService.addTaskLog(taskId, {
|
|
644
|
+
level: 'error',
|
|
645
|
+
message: `Provider resolution failed: ${errorMsg}`,
|
|
646
|
+
});
|
|
647
|
+
this.taskManagementService.completeTask(taskId, { success: false, error: errorMsg }, false);
|
|
648
|
+
return {
|
|
649
|
+
content: [
|
|
650
|
+
{
|
|
651
|
+
type: 'text',
|
|
652
|
+
text: `❌ **Provider Error**\n\n${errorMsg}\n\nAvailable providers: ${this.providerBridgeService.listAvailableProviders().join(', ')}`,
|
|
653
|
+
},
|
|
654
|
+
],
|
|
655
|
+
success: false,
|
|
656
|
+
agent: agentId,
|
|
657
|
+
provider: 'none',
|
|
658
|
+
error: errorMsg,
|
|
659
|
+
taskId,
|
|
660
|
+
readOnlyMode: true,
|
|
661
|
+
readOnly: true,
|
|
662
|
+
};
|
|
663
|
+
}
|
|
664
|
+
const resolvedProviderName = providerResolution.provider.name;
|
|
665
|
+
if (args.provider) {
|
|
666
|
+
this.taskManagementService.addTaskLog(taskId, {
|
|
667
|
+
level: 'info',
|
|
668
|
+
message: `Using CLI-specified provider: ${args.provider} (resolved to ${resolvedProviderName})`
|
|
669
|
+
});
|
|
670
|
+
}
|
|
671
|
+
else if (providerInput) {
|
|
672
|
+
this.taskManagementService.addTaskLog(taskId, {
|
|
673
|
+
level: 'info',
|
|
674
|
+
message: `Agent provider resolved to ${resolvedProviderName} (input: ${providerInput})`
|
|
675
|
+
});
|
|
574
676
|
}
|
|
575
677
|
else {
|
|
576
|
-
|
|
678
|
+
this.taskManagementService.addTaskLog(taskId, {
|
|
679
|
+
level: 'info',
|
|
680
|
+
message: `Using ProviderBridge fallback provider: ${resolvedProviderName}`,
|
|
681
|
+
});
|
|
577
682
|
}
|
|
578
|
-
const agentOptions = this.getOptionsForAgent(agent, 'query',
|
|
579
|
-
const modelToUse = model || agent.inline?.model;
|
|
683
|
+
const agentOptions = this.getOptionsForAgent(agent, 'query', resolvedProviderName);
|
|
684
|
+
const modelToUse = model || agent.inline?.model || providerResolution.defaultModel;
|
|
580
685
|
const structuredPayload = await this.buildStructuredPayload({
|
|
581
686
|
agentId,
|
|
582
|
-
provider,
|
|
687
|
+
provider: resolvedProviderName,
|
|
583
688
|
mode: 'query',
|
|
584
689
|
prompt: fullPrompt,
|
|
585
690
|
context,
|
|
@@ -587,17 +692,55 @@ ${query}
|
|
|
587
692
|
platform: platform || 'cli',
|
|
588
693
|
model: modelToUse,
|
|
589
694
|
});
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
695
|
+
const runtimeMessages = this.toConversationMessages(messages);
|
|
696
|
+
let agentResult;
|
|
697
|
+
try {
|
|
698
|
+
agentResult = await runtimeResult.runtime.agent.query({
|
|
699
|
+
agentId,
|
|
700
|
+
prompt: fullPrompt,
|
|
701
|
+
context,
|
|
702
|
+
messages: runtimeMessages,
|
|
703
|
+
model: modelToUse,
|
|
704
|
+
options: {
|
|
705
|
+
workingDirectory: workingDir,
|
|
706
|
+
timeout: this.timeoutConfig.parallel,
|
|
707
|
+
additionalArgs: agentOptions,
|
|
708
|
+
taskId,
|
|
709
|
+
securityKey,
|
|
710
|
+
pipedContext: structuredPayload,
|
|
711
|
+
},
|
|
712
|
+
});
|
|
713
|
+
}
|
|
714
|
+
catch (error) {
|
|
715
|
+
const errorMsg = error instanceof Error ? error.message : 'Agent runtime query failed';
|
|
716
|
+
this.taskManagementService.addTaskLog(taskId, {
|
|
717
|
+
level: 'error',
|
|
718
|
+
message: `Agent runtime query failed: ${errorMsg}`,
|
|
719
|
+
});
|
|
720
|
+
this.taskManagementService.completeTask(taskId, { success: false, error: errorMsg }, false);
|
|
721
|
+
return {
|
|
722
|
+
content: [
|
|
723
|
+
{
|
|
724
|
+
type: 'text',
|
|
725
|
+
text: `❌ **Provider Error**\n\n${errorMsg}\n\nAvailable providers: ${this.providerBridgeService.listAvailableProviders().join(', ')}`,
|
|
726
|
+
},
|
|
727
|
+
],
|
|
728
|
+
success: false,
|
|
729
|
+
agent: agentId,
|
|
730
|
+
provider: resolvedProviderName,
|
|
731
|
+
error: errorMsg,
|
|
732
|
+
taskId,
|
|
733
|
+
readOnlyMode: true,
|
|
734
|
+
readOnly: true,
|
|
735
|
+
};
|
|
736
|
+
}
|
|
737
|
+
const response = {
|
|
738
|
+
success: agentResult.success,
|
|
739
|
+
content: agentResult.content,
|
|
740
|
+
provider: agentResult.metadata?.provider ?? resolvedProviderName,
|
|
741
|
+
taskId: agentResult.metadata?.taskId ?? taskId,
|
|
742
|
+
error: agentResult.metadata?.error,
|
|
743
|
+
};
|
|
601
744
|
this.taskManagementService.addTaskLog(taskId, { level: 'info', message: `Query completed. Success: ${response.success}` });
|
|
602
745
|
this.taskManagementService.completeTask(taskId, response, response.success);
|
|
603
746
|
const responseText = response.success
|
|
@@ -734,27 +877,56 @@ Please check the agent ID and try again.`
|
|
|
734
877
|
const securityKey = this.generateSecurityKey();
|
|
735
878
|
const contextMessages = messages && messages.length > 0 ? messages.slice(0, -1) : [];
|
|
736
879
|
const templateContext = {
|
|
737
|
-
|
|
880
|
+
user_input: task,
|
|
881
|
+
messages: contextMessages,
|
|
738
882
|
agent: {
|
|
739
883
|
id: agent.id,
|
|
740
884
|
name: agent.name || agent.id,
|
|
741
885
|
provider: (Array.isArray(agent.provider) ? agent.provider[0] : agent.provider) || 'claude',
|
|
742
886
|
model: model || agent.inline?.model,
|
|
743
887
|
workingDirectory: workingDir,
|
|
888
|
+
inline: {
|
|
889
|
+
prompt: agent.inline?.prompt || agent.inline?.system_prompt || agent.systemPrompt || '',
|
|
890
|
+
},
|
|
891
|
+
specialties: agent.specialties,
|
|
892
|
+
capabilities: agent.capabilities,
|
|
893
|
+
description: agent.description,
|
|
744
894
|
},
|
|
745
|
-
|
|
746
|
-
messages: contextMessages,
|
|
747
|
-
platform: platform,
|
|
748
|
-
tools: this.buildToolsContext(),
|
|
895
|
+
documents: {},
|
|
749
896
|
vars: {
|
|
750
897
|
security_key: securityKey,
|
|
751
898
|
},
|
|
899
|
+
props: {},
|
|
900
|
+
mode: 'execute',
|
|
901
|
+
platform: platform,
|
|
902
|
+
env: process.env,
|
|
903
|
+
tools: this.buildToolsContext(),
|
|
752
904
|
};
|
|
753
905
|
let systemPrompt = await this.processAgentSystemPrompt(agent, templateContext);
|
|
754
|
-
|
|
906
|
+
if (process.env.CREWX_APPEND_LEGACY === 'true') {
|
|
907
|
+
this.logger.debug('[WBS-14] Legacy append mode enabled (execute)', {
|
|
908
|
+
agentId: agent.id,
|
|
909
|
+
layoutId: typeof agent.inline?.layout === 'string'
|
|
910
|
+
? agent.inline?.layout
|
|
911
|
+
: agent.inline?.layout?.id ?? 'crewx/default',
|
|
912
|
+
});
|
|
913
|
+
systemPrompt += `
|
|
755
914
|
Specialties: ${agent.specialties?.join(', ') || 'General'}
|
|
756
915
|
Capabilities: ${agent.capabilities?.join(', ') || 'Implementation'}
|
|
757
916
|
Working Directory: ${workingDir}`;
|
|
917
|
+
}
|
|
918
|
+
else if (process.env.CREWX_WBS14_TELEMETRY === 'true') {
|
|
919
|
+
this.logger.debug('[WBS-14] Metadata delegated to layout (execute mode)', {
|
|
920
|
+
agentId: agent.id,
|
|
921
|
+
hasLayout: Boolean(agent.inline?.layout),
|
|
922
|
+
layoutId: typeof agent.inline?.layout === 'string'
|
|
923
|
+
? agent.inline?.layout
|
|
924
|
+
: agent.inline?.layout?.id ?? 'crewx/default',
|
|
925
|
+
specialtiesCount: agent.specialties?.length ?? 0,
|
|
926
|
+
capabilitiesCount: agent.capabilities?.length ?? 0,
|
|
927
|
+
workingDirectory: workingDir,
|
|
928
|
+
});
|
|
929
|
+
}
|
|
758
930
|
const fullPrompt = context
|
|
759
931
|
? `${systemPrompt}
|
|
760
932
|
${context}
|
|
@@ -765,26 +937,74 @@ Task: ${task}
|
|
|
765
937
|
|
|
766
938
|
Task: ${task}
|
|
767
939
|
`;
|
|
768
|
-
let
|
|
769
|
-
let
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
940
|
+
let runtimeResult;
|
|
941
|
+
let providerResolution;
|
|
942
|
+
let providerInput;
|
|
943
|
+
if (args.provider) {
|
|
944
|
+
providerInput = args.provider;
|
|
945
|
+
}
|
|
946
|
+
else if (Array.isArray(agent.provider)) {
|
|
947
|
+
providerInput = await this.getAvailableProvider(agent.provider);
|
|
948
|
+
}
|
|
949
|
+
else if (typeof agent.provider === 'string' && agent.provider.trim().length > 0) {
|
|
950
|
+
providerInput = agent.provider;
|
|
951
|
+
}
|
|
952
|
+
try {
|
|
953
|
+
runtimeResult = await this.providerBridgeService.createAgentRuntime({
|
|
954
|
+
provider: providerInput,
|
|
955
|
+
defaultAgentId: agentId,
|
|
956
|
+
validAgents: agents.map(a => a.id),
|
|
957
|
+
enableCallStack: true,
|
|
958
|
+
});
|
|
959
|
+
providerResolution = runtimeResult.resolution;
|
|
960
|
+
}
|
|
961
|
+
catch (error) {
|
|
962
|
+
const errorMsg = error instanceof Error ? error.message : 'Unknown provider error';
|
|
963
|
+
this.taskManagementService.addTaskLog(taskId, {
|
|
964
|
+
level: 'error',
|
|
965
|
+
message: `Provider resolution failed: ${errorMsg}`,
|
|
966
|
+
});
|
|
967
|
+
this.taskManagementService.completeTask(taskId, { success: false, error: errorMsg }, false);
|
|
968
|
+
return {
|
|
969
|
+
content: [
|
|
970
|
+
{
|
|
971
|
+
type: 'text',
|
|
972
|
+
text: `❌ **Provider Error**\n\n${errorMsg}\n\nAvailable providers: ${this.providerBridgeService.listAvailableProviders().join(', ')}`,
|
|
973
|
+
},
|
|
974
|
+
],
|
|
975
|
+
success: false,
|
|
976
|
+
agent: agentId,
|
|
977
|
+
provider: 'none',
|
|
978
|
+
error: errorMsg,
|
|
979
|
+
taskId,
|
|
980
|
+
readOnlyMode: false,
|
|
981
|
+
readOnly: false,
|
|
982
|
+
};
|
|
983
|
+
}
|
|
984
|
+
const resolvedProviderName = providerResolution.provider.name;
|
|
985
|
+
if (args.provider) {
|
|
986
|
+
this.taskManagementService.addTaskLog(taskId, {
|
|
987
|
+
level: 'info',
|
|
988
|
+
message: `Using CLI-specified provider: ${args.provider} (resolved to ${resolvedProviderName})`
|
|
989
|
+
});
|
|
990
|
+
}
|
|
991
|
+
else if (providerInput) {
|
|
992
|
+
this.taskManagementService.addTaskLog(taskId, {
|
|
993
|
+
level: 'info',
|
|
994
|
+
message: `Agent provider resolved to ${resolvedProviderName} (input: ${providerInput})`
|
|
995
|
+
});
|
|
778
996
|
}
|
|
779
997
|
else {
|
|
780
|
-
|
|
998
|
+
this.taskManagementService.addTaskLog(taskId, {
|
|
999
|
+
level: 'info',
|
|
1000
|
+
message: `Using ProviderBridge fallback provider: ${resolvedProviderName}`,
|
|
1001
|
+
});
|
|
781
1002
|
}
|
|
782
|
-
this.
|
|
783
|
-
const
|
|
784
|
-
const modelToUse = model || agent.inline?.model;
|
|
1003
|
+
const agentOptions = this.getOptionsForAgent(agent, 'execute', resolvedProviderName);
|
|
1004
|
+
const modelToUse = model || agent.inline?.model || providerResolution.defaultModel;
|
|
785
1005
|
const structuredPayload = await this.buildStructuredPayload({
|
|
786
1006
|
agentId,
|
|
787
|
-
provider,
|
|
1007
|
+
provider: resolvedProviderName,
|
|
788
1008
|
mode: 'execute',
|
|
789
1009
|
prompt: fullPrompt,
|
|
790
1010
|
context,
|
|
@@ -792,16 +1012,55 @@ Task: ${task}
|
|
|
792
1012
|
platform: platform || 'cli',
|
|
793
1013
|
model: modelToUse,
|
|
794
1014
|
});
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
1015
|
+
const runtimeMessages = this.toConversationMessages(messages);
|
|
1016
|
+
let agentResult;
|
|
1017
|
+
try {
|
|
1018
|
+
agentResult = await runtimeResult.runtime.agent.execute({
|
|
1019
|
+
agentId,
|
|
1020
|
+
prompt: fullPrompt,
|
|
1021
|
+
context,
|
|
1022
|
+
messages: runtimeMessages,
|
|
1023
|
+
model: modelToUse,
|
|
1024
|
+
options: {
|
|
1025
|
+
workingDirectory: workingDir,
|
|
1026
|
+
timeout: 1200000,
|
|
1027
|
+
additionalArgs: agentOptions,
|
|
1028
|
+
taskId,
|
|
1029
|
+
pipedContext: structuredPayload,
|
|
1030
|
+
securityKey,
|
|
1031
|
+
},
|
|
1032
|
+
});
|
|
1033
|
+
}
|
|
1034
|
+
catch (error) {
|
|
1035
|
+
const errorMsg = error instanceof Error ? error.message : 'Agent runtime execution failed';
|
|
1036
|
+
this.taskManagementService.addTaskLog(taskId, {
|
|
1037
|
+
level: 'error',
|
|
1038
|
+
message: `Agent runtime execution failed: ${errorMsg}`,
|
|
1039
|
+
});
|
|
1040
|
+
this.taskManagementService.completeTask(taskId, { success: false, error: errorMsg }, false);
|
|
1041
|
+
return {
|
|
1042
|
+
content: [
|
|
1043
|
+
{
|
|
1044
|
+
type: 'text',
|
|
1045
|
+
text: `❌ **Provider Error**\n\n${errorMsg}\n\nAvailable providers: ${this.providerBridgeService.listAvailableProviders().join(', ')}`,
|
|
1046
|
+
},
|
|
1047
|
+
],
|
|
1048
|
+
success: false,
|
|
1049
|
+
agent: agentId,
|
|
1050
|
+
provider: resolvedProviderName,
|
|
1051
|
+
error: errorMsg,
|
|
1052
|
+
taskId,
|
|
1053
|
+
readOnlyMode: false,
|
|
1054
|
+
readOnly: false,
|
|
1055
|
+
};
|
|
1056
|
+
}
|
|
1057
|
+
const response = {
|
|
1058
|
+
success: agentResult.success,
|
|
1059
|
+
content: agentResult.content,
|
|
1060
|
+
provider: agentResult.metadata?.provider ?? resolvedProviderName,
|
|
1061
|
+
taskId: agentResult.metadata?.taskId ?? taskId,
|
|
1062
|
+
error: agentResult.metadata?.error,
|
|
1063
|
+
};
|
|
805
1064
|
this.taskManagementService.addTaskLog(taskId, { level: 'info', message: `Execution completed. Success: ${response.success}` });
|
|
806
1065
|
this.taskManagementService.completeTask(taskId, response, response.success);
|
|
807
1066
|
const responseText = response.success ? response.content : `❌ Execution Failed: ${response.error}`;
|
|
@@ -873,6 +1132,41 @@ Task: ${task}
|
|
|
873
1132
|
readOnly,
|
|
874
1133
|
};
|
|
875
1134
|
}
|
|
1135
|
+
toConversationMessages(messages) {
|
|
1136
|
+
if (!messages || messages.length === 0) {
|
|
1137
|
+
return [];
|
|
1138
|
+
}
|
|
1139
|
+
return messages.map((message, index) => {
|
|
1140
|
+
const metadata = message.metadata ?? {};
|
|
1141
|
+
const rawTimestamp = metadata.timestamp;
|
|
1142
|
+
let timestamp;
|
|
1143
|
+
if (rawTimestamp instanceof Date) {
|
|
1144
|
+
timestamp = rawTimestamp;
|
|
1145
|
+
}
|
|
1146
|
+
else if (typeof rawTimestamp === 'number') {
|
|
1147
|
+
timestamp = new Date(rawTimestamp);
|
|
1148
|
+
}
|
|
1149
|
+
else if (typeof rawTimestamp === 'string') {
|
|
1150
|
+
const parsed = new Date(rawTimestamp);
|
|
1151
|
+
timestamp = Number.isNaN(parsed.getTime()) ? new Date() : parsed;
|
|
1152
|
+
}
|
|
1153
|
+
else {
|
|
1154
|
+
timestamp = new Date();
|
|
1155
|
+
}
|
|
1156
|
+
return {
|
|
1157
|
+
id: typeof metadata.id === 'string' ? metadata.id : `cli-msg-${index}`,
|
|
1158
|
+
userId: typeof metadata.userId === 'string'
|
|
1159
|
+
? metadata.userId
|
|
1160
|
+
: message.isAssistant
|
|
1161
|
+
? 'assistant'
|
|
1162
|
+
: 'user',
|
|
1163
|
+
text: message.text,
|
|
1164
|
+
timestamp,
|
|
1165
|
+
isAssistant: message.isAssistant,
|
|
1166
|
+
metadata: metadata,
|
|
1167
|
+
};
|
|
1168
|
+
});
|
|
1169
|
+
}
|
|
876
1170
|
getOptionsForAgent(agent, mode, provider) {
|
|
877
1171
|
try {
|
|
878
1172
|
if (agent.options && typeof agent.options === 'object' && !Array.isArray(agent.options)) {
|
|
@@ -1549,8 +1843,8 @@ __decorate([
|
|
|
1549
1843
|
], CrewXTool.prototype, "clearAllLogs", null);
|
|
1550
1844
|
exports.CrewXTool = CrewXTool = CrewXTool_1 = __decorate([
|
|
1551
1845
|
(0, common_1.Injectable)(),
|
|
1552
|
-
__param(
|
|
1553
|
-
__param(
|
|
1846
|
+
__param(12, (0, common_1.Inject)('LAYOUT_LOADER')),
|
|
1847
|
+
__param(13, (0, common_1.Inject)('LAYOUT_RENDERER')),
|
|
1554
1848
|
__metadata("design:paramtypes", [ai_service_1.AIService,
|
|
1555
1849
|
ai_provider_service_1.AIProviderService,
|
|
1556
1850
|
project_service_1.ProjectService,
|
|
@@ -1562,6 +1856,7 @@ exports.CrewXTool = CrewXTool = CrewXTool_1 = __decorate([
|
|
|
1562
1856
|
tool_call_service_1.ToolCallService,
|
|
1563
1857
|
agent_loader_service_1.AgentLoaderService,
|
|
1564
1858
|
remote_agent_service_1.RemoteAgentService,
|
|
1859
|
+
provider_bridge_service_1.ProviderBridgeService,
|
|
1565
1860
|
crewx_sdk_1.LayoutLoader,
|
|
1566
1861
|
crewx_sdk_1.LayoutRenderer])
|
|
1567
1862
|
], CrewXTool);
|