@sowonai/crewx-cli 0.4.0-dev.28 → 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/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 +14 -1
- package/dist/crewx.tool.js +320 -73
- 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 +1 -1
- package/package.json +2 -2
- package/templates/agents/default.yaml +6 -0
- package/templates/agents/minimal.yaml +6 -0
- package/templates/versions.json +1 -1
package/dist/crewx.tool.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { DocumentLoaderService } from './services/document-loader.service';
|
|
|
11
11
|
import { ToolCallService } from './services/tool-call.service';
|
|
12
12
|
import { AgentLoaderService } from './services/agent-loader.service';
|
|
13
13
|
import { RemoteAgentService } from './services/remote-agent.service';
|
|
14
|
+
import { ProviderBridgeService } from './services/provider-bridge.service';
|
|
14
15
|
export declare class CrewXTool implements OnModuleInit {
|
|
15
16
|
private readonly aiService;
|
|
16
17
|
private readonly aiProviderService;
|
|
@@ -23,6 +24,7 @@ export declare class CrewXTool implements OnModuleInit {
|
|
|
23
24
|
private readonly toolCallService;
|
|
24
25
|
private readonly agentLoaderService;
|
|
25
26
|
private readonly remoteAgentService;
|
|
27
|
+
private readonly providerBridgeService;
|
|
26
28
|
private readonly layoutLoader;
|
|
27
29
|
private readonly layoutRenderer;
|
|
28
30
|
private readonly logger;
|
|
@@ -30,7 +32,7 @@ export declare class CrewXTool implements OnModuleInit {
|
|
|
30
32
|
private generateSecurityKey;
|
|
31
33
|
private buildToolsContext;
|
|
32
34
|
private buildStructuredPayload;
|
|
33
|
-
constructor(aiService: AIService, aiProviderService: AIProviderService, projectService: ProjectService, parallelProcessingService: ParallelProcessingService, taskManagementService: TaskManagementService, resultFormatterService: ResultFormatterService, templateService: TemplateService, documentLoaderService: DocumentLoaderService, toolCallService: ToolCallService, agentLoaderService: AgentLoaderService, remoteAgentService: RemoteAgentService, layoutLoader: LayoutLoader, layoutRenderer: LayoutRenderer);
|
|
35
|
+
constructor(aiService: AIService, aiProviderService: AIProviderService, projectService: ProjectService, parallelProcessingService: ParallelProcessingService, taskManagementService: TaskManagementService, resultFormatterService: ResultFormatterService, templateService: TemplateService, documentLoaderService: DocumentLoaderService, toolCallService: ToolCallService, agentLoaderService: AgentLoaderService, remoteAgentService: RemoteAgentService, providerBridgeService: ProviderBridgeService, layoutLoader: LayoutLoader, layoutRenderer: LayoutRenderer);
|
|
34
36
|
onModuleInit(): void;
|
|
35
37
|
private processAgentSystemPrompt;
|
|
36
38
|
getTaskLogs(input: {
|
|
@@ -54,6 +56,10 @@ export declare class CrewXTool implements OnModuleInit {
|
|
|
54
56
|
gemini: boolean;
|
|
55
57
|
copilot: boolean;
|
|
56
58
|
};
|
|
59
|
+
providerBridge: {
|
|
60
|
+
status: string;
|
|
61
|
+
providers: string[];
|
|
62
|
+
};
|
|
57
63
|
recommendations: string[];
|
|
58
64
|
error?: undefined;
|
|
59
65
|
} | {
|
|
@@ -75,6 +81,10 @@ export declare class CrewXTool implements OnModuleInit {
|
|
|
75
81
|
installed: boolean;
|
|
76
82
|
};
|
|
77
83
|
};
|
|
84
|
+
providerBridge: {
|
|
85
|
+
status: string;
|
|
86
|
+
providers: string[];
|
|
87
|
+
};
|
|
78
88
|
recommendations?: undefined;
|
|
79
89
|
}>;
|
|
80
90
|
private getInstallationRecommendations;
|
|
@@ -110,6 +120,7 @@ export declare class CrewXTool implements OnModuleInit {
|
|
|
110
120
|
metadata?: Record<string, any>;
|
|
111
121
|
}>;
|
|
112
122
|
platform?: 'slack' | 'cli';
|
|
123
|
+
provider?: string;
|
|
113
124
|
}): Promise<any>;
|
|
114
125
|
executeAgent(args: {
|
|
115
126
|
agentId: string;
|
|
@@ -123,8 +134,10 @@ export declare class CrewXTool implements OnModuleInit {
|
|
|
123
134
|
metadata?: Record<string, any>;
|
|
124
135
|
}>;
|
|
125
136
|
platform?: 'slack' | 'cli';
|
|
137
|
+
provider?: string;
|
|
126
138
|
}): Promise<any>;
|
|
127
139
|
private normalizeRemoteResult;
|
|
140
|
+
private toConversationMessages;
|
|
128
141
|
private getOptionsForAgent;
|
|
129
142
|
queryAgentParallel(args: {
|
|
130
143
|
queries: Array<{
|
package/dist/crewx.tool.js
CHANGED
|
@@ -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);
|
|
@@ -184,6 +186,7 @@ let CrewXTool = CrewXTool_1 = class CrewXTool {
|
|
|
184
186
|
tools: templateContext.tools ?? null,
|
|
185
187
|
};
|
|
186
188
|
const renderContext = {
|
|
189
|
+
user_input: templateContext.user_input,
|
|
187
190
|
agent: {
|
|
188
191
|
id: agent.id,
|
|
189
192
|
name: agent.name || agent.id,
|
|
@@ -274,11 +277,29 @@ let CrewXTool = CrewXTool_1 = class CrewXTool {
|
|
|
274
277
|
const availableProviders = await this.aiService.checkAvailableProviders();
|
|
275
278
|
const installation = await this.aiService.validateCLIInstallation();
|
|
276
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
|
+
}
|
|
277
295
|
const responseText = `🤖 **AI Providers Status**
|
|
278
296
|
|
|
279
297
|
**Available Providers:**
|
|
280
298
|
${availableProviders.length > 0 ? availableProviders.map(p => `✅ ${p}`).join('\n') : '❌ No providers available'}
|
|
281
299
|
|
|
300
|
+
**Provider Bridge:**
|
|
301
|
+
${bridgeStatus}${bridgeProviders.length > 0 ? `\nRegistered: ${bridgeProviders.join(', ')}` : ''}
|
|
302
|
+
|
|
282
303
|
**Installation Status:**
|
|
283
304
|
• Claude CLI: ${installation.claude ? '✅ Installed' : '❌ Not Installed'}
|
|
284
305
|
• Gemini CLI: ${installation.gemini ? '✅ Installed' : '❌ Not Installed'}
|
|
@@ -300,6 +321,10 @@ ${recommendations.map(r => `• ${r}`).join('\n')}`;
|
|
|
300
321
|
gemini: installation.gemini,
|
|
301
322
|
copilot: installation.copilot,
|
|
302
323
|
},
|
|
324
|
+
providerBridge: {
|
|
325
|
+
status: bridgeStatus,
|
|
326
|
+
providers: bridgeProviders,
|
|
327
|
+
},
|
|
303
328
|
recommendations,
|
|
304
329
|
};
|
|
305
330
|
}
|
|
@@ -324,7 +349,11 @@ No AI providers could be verified.`
|
|
|
324
349
|
claude: { installed: false },
|
|
325
350
|
gemini: { installed: false },
|
|
326
351
|
copilot: { installed: false }
|
|
327
|
-
}
|
|
352
|
+
},
|
|
353
|
+
providerBridge: {
|
|
354
|
+
status: '❌ ProviderBridge inspection skipped due to error',
|
|
355
|
+
providers: [],
|
|
356
|
+
},
|
|
328
357
|
};
|
|
329
358
|
}
|
|
330
359
|
}
|
|
@@ -528,26 +557,30 @@ ${errorMessage}`,
|
|
|
528
557
|
const securityKey = this.generateSecurityKey();
|
|
529
558
|
const contextMessages = messages && messages.length > 0 ? messages.slice(0, -1) : [];
|
|
530
559
|
const templateContext = {
|
|
531
|
-
|
|
560
|
+
user_input: query,
|
|
561
|
+
messages: contextMessages,
|
|
532
562
|
agent: {
|
|
533
563
|
id: agent.id,
|
|
534
564
|
name: agent.name || agent.id,
|
|
535
565
|
provider: (Array.isArray(agent.provider) ? agent.provider[0] : agent.provider) || 'claude',
|
|
536
566
|
model: model || agent.inline?.model,
|
|
537
567
|
workingDirectory: workingDir,
|
|
538
|
-
|
|
539
|
-
|
|
568
|
+
inline: {
|
|
569
|
+
prompt: agent.inline?.prompt || agent.inline?.system_prompt || agent.systemPrompt || '',
|
|
570
|
+
},
|
|
540
571
|
specialties: agent.specialties,
|
|
541
572
|
capabilities: agent.capabilities,
|
|
542
573
|
description: agent.description,
|
|
543
574
|
},
|
|
544
|
-
|
|
545
|
-
messages: contextMessages,
|
|
546
|
-
platform: platform,
|
|
547
|
-
tools: this.buildToolsContext(),
|
|
575
|
+
documents: {},
|
|
548
576
|
vars: {
|
|
549
577
|
security_key: securityKey,
|
|
550
578
|
},
|
|
579
|
+
props: {},
|
|
580
|
+
mode: 'query',
|
|
581
|
+
platform: platform,
|
|
582
|
+
env: process.env,
|
|
583
|
+
tools: this.buildToolsContext(),
|
|
551
584
|
};
|
|
552
585
|
let systemPrompt = await this.processAgentSystemPrompt(agent, templateContext);
|
|
553
586
|
if (process.env.CREWX_APPEND_LEGACY === 'true') {
|
|
@@ -575,34 +608,83 @@ Working Directory: ${workingDir}`;
|
|
|
575
608
|
workingDirectory: workingDir,
|
|
576
609
|
});
|
|
577
610
|
}
|
|
578
|
-
const wrappedQuery = `
|
|
579
|
-
<user_query key="${securityKey}">
|
|
580
|
-
${query}
|
|
581
|
-
</user_query>`;
|
|
582
611
|
let fullPrompt = systemPrompt;
|
|
583
612
|
if (context) {
|
|
584
613
|
fullPrompt += `\n\n${context}`;
|
|
585
614
|
}
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
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
|
+
});
|
|
597
676
|
}
|
|
598
677
|
else {
|
|
599
|
-
|
|
678
|
+
this.taskManagementService.addTaskLog(taskId, {
|
|
679
|
+
level: 'info',
|
|
680
|
+
message: `Using ProviderBridge fallback provider: ${resolvedProviderName}`,
|
|
681
|
+
});
|
|
600
682
|
}
|
|
601
|
-
const agentOptions = this.getOptionsForAgent(agent, 'query',
|
|
602
|
-
const modelToUse = model || agent.inline?.model;
|
|
683
|
+
const agentOptions = this.getOptionsForAgent(agent, 'query', resolvedProviderName);
|
|
684
|
+
const modelToUse = model || agent.inline?.model || providerResolution.defaultModel;
|
|
603
685
|
const structuredPayload = await this.buildStructuredPayload({
|
|
604
686
|
agentId,
|
|
605
|
-
provider,
|
|
687
|
+
provider: resolvedProviderName,
|
|
606
688
|
mode: 'query',
|
|
607
689
|
prompt: fullPrompt,
|
|
608
690
|
context,
|
|
@@ -610,17 +692,55 @@ ${query}
|
|
|
610
692
|
platform: platform || 'cli',
|
|
611
693
|
model: modelToUse,
|
|
612
694
|
});
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
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
|
+
};
|
|
624
744
|
this.taskManagementService.addTaskLog(taskId, { level: 'info', message: `Query completed. Success: ${response.success}` });
|
|
625
745
|
this.taskManagementService.completeTask(taskId, response, response.success);
|
|
626
746
|
const responseText = response.success
|
|
@@ -757,26 +877,30 @@ Please check the agent ID and try again.`
|
|
|
757
877
|
const securityKey = this.generateSecurityKey();
|
|
758
878
|
const contextMessages = messages && messages.length > 0 ? messages.slice(0, -1) : [];
|
|
759
879
|
const templateContext = {
|
|
760
|
-
|
|
880
|
+
user_input: task,
|
|
881
|
+
messages: contextMessages,
|
|
761
882
|
agent: {
|
|
762
883
|
id: agent.id,
|
|
763
884
|
name: agent.name || agent.id,
|
|
764
885
|
provider: (Array.isArray(agent.provider) ? agent.provider[0] : agent.provider) || 'claude',
|
|
765
886
|
model: model || agent.inline?.model,
|
|
766
887
|
workingDirectory: workingDir,
|
|
767
|
-
|
|
768
|
-
|
|
888
|
+
inline: {
|
|
889
|
+
prompt: agent.inline?.prompt || agent.inline?.system_prompt || agent.systemPrompt || '',
|
|
890
|
+
},
|
|
769
891
|
specialties: agent.specialties,
|
|
770
892
|
capabilities: agent.capabilities,
|
|
771
893
|
description: agent.description,
|
|
772
894
|
},
|
|
773
|
-
|
|
774
|
-
messages: contextMessages,
|
|
775
|
-
platform: platform,
|
|
776
|
-
tools: this.buildToolsContext(),
|
|
895
|
+
documents: {},
|
|
777
896
|
vars: {
|
|
778
897
|
security_key: securityKey,
|
|
779
898
|
},
|
|
899
|
+
props: {},
|
|
900
|
+
mode: 'execute',
|
|
901
|
+
platform: platform,
|
|
902
|
+
env: process.env,
|
|
903
|
+
tools: this.buildToolsContext(),
|
|
780
904
|
};
|
|
781
905
|
let systemPrompt = await this.processAgentSystemPrompt(agent, templateContext);
|
|
782
906
|
if (process.env.CREWX_APPEND_LEGACY === 'true') {
|
|
@@ -813,26 +937,74 @@ Task: ${task}
|
|
|
813
937
|
|
|
814
938
|
Task: ${task}
|
|
815
939
|
`;
|
|
816
|
-
let
|
|
817
|
-
let
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
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
|
+
});
|
|
826
996
|
}
|
|
827
997
|
else {
|
|
828
|
-
|
|
998
|
+
this.taskManagementService.addTaskLog(taskId, {
|
|
999
|
+
level: 'info',
|
|
1000
|
+
message: `Using ProviderBridge fallback provider: ${resolvedProviderName}`,
|
|
1001
|
+
});
|
|
829
1002
|
}
|
|
830
|
-
this.
|
|
831
|
-
const
|
|
832
|
-
const modelToUse = model || agent.inline?.model;
|
|
1003
|
+
const agentOptions = this.getOptionsForAgent(agent, 'execute', resolvedProviderName);
|
|
1004
|
+
const modelToUse = model || agent.inline?.model || providerResolution.defaultModel;
|
|
833
1005
|
const structuredPayload = await this.buildStructuredPayload({
|
|
834
1006
|
agentId,
|
|
835
|
-
provider,
|
|
1007
|
+
provider: resolvedProviderName,
|
|
836
1008
|
mode: 'execute',
|
|
837
1009
|
prompt: fullPrompt,
|
|
838
1010
|
context,
|
|
@@ -840,16 +1012,55 @@ Task: ${task}
|
|
|
840
1012
|
platform: platform || 'cli',
|
|
841
1013
|
model: modelToUse,
|
|
842
1014
|
});
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
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
|
+
};
|
|
853
1064
|
this.taskManagementService.addTaskLog(taskId, { level: 'info', message: `Execution completed. Success: ${response.success}` });
|
|
854
1065
|
this.taskManagementService.completeTask(taskId, response, response.success);
|
|
855
1066
|
const responseText = response.success ? response.content : `❌ Execution Failed: ${response.error}`;
|
|
@@ -921,6 +1132,41 @@ Task: ${task}
|
|
|
921
1132
|
readOnly,
|
|
922
1133
|
};
|
|
923
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
|
+
}
|
|
924
1170
|
getOptionsForAgent(agent, mode, provider) {
|
|
925
1171
|
try {
|
|
926
1172
|
if (agent.options && typeof agent.options === 'object' && !Array.isArray(agent.options)) {
|
|
@@ -1597,8 +1843,8 @@ __decorate([
|
|
|
1597
1843
|
], CrewXTool.prototype, "clearAllLogs", null);
|
|
1598
1844
|
exports.CrewXTool = CrewXTool = CrewXTool_1 = __decorate([
|
|
1599
1845
|
(0, common_1.Injectable)(),
|
|
1600
|
-
__param(
|
|
1601
|
-
__param(
|
|
1846
|
+
__param(12, (0, common_1.Inject)('LAYOUT_LOADER')),
|
|
1847
|
+
__param(13, (0, common_1.Inject)('LAYOUT_RENDERER')),
|
|
1602
1848
|
__metadata("design:paramtypes", [ai_service_1.AIService,
|
|
1603
1849
|
ai_provider_service_1.AIProviderService,
|
|
1604
1850
|
project_service_1.ProjectService,
|
|
@@ -1610,6 +1856,7 @@ exports.CrewXTool = CrewXTool = CrewXTool_1 = __decorate([
|
|
|
1610
1856
|
tool_call_service_1.ToolCallService,
|
|
1611
1857
|
agent_loader_service_1.AgentLoaderService,
|
|
1612
1858
|
remote_agent_service_1.RemoteAgentService,
|
|
1859
|
+
provider_bridge_service_1.ProviderBridgeService,
|
|
1613
1860
|
crewx_sdk_1.LayoutLoader,
|
|
1614
1861
|
crewx_sdk_1.LayoutRenderer])
|
|
1615
1862
|
], CrewXTool);
|