@defai.digital/ax-cli 3.14.16 → 3.14.17

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.
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Agent Executor - Executes tasks through AutomatosX agents
3
+ *
4
+ * Spawns `ax run <agent> "message"` and streams the output back.
5
+ *
6
+ * @module agent-executor
7
+ */
8
+ /**
9
+ * Result chunk from agent execution
10
+ */
11
+ export interface AgentExecutionChunk {
12
+ type: 'output' | 'error' | 'done';
13
+ content?: string;
14
+ exitCode?: number;
15
+ }
16
+ /**
17
+ * Options for agent execution
18
+ */
19
+ export interface AgentExecutionOptions {
20
+ /** Agent name to use */
21
+ agent: string;
22
+ /** Task/message to send to the agent */
23
+ task: string;
24
+ /** Working directory (defaults to cwd) */
25
+ cwd?: string;
26
+ /** Timeout in milliseconds (default: 10 minutes) */
27
+ timeout?: number;
28
+ /** Additional environment variables */
29
+ env?: Record<string, string>;
30
+ /** Enable streaming mode */
31
+ streaming?: boolean;
32
+ /** Disable memory for this execution */
33
+ noMemory?: boolean;
34
+ }
35
+ /**
36
+ * Agent execution result
37
+ */
38
+ export interface AgentExecutionResult {
39
+ success: boolean;
40
+ output: string;
41
+ exitCode: number;
42
+ duration: number;
43
+ }
44
+ /**
45
+ * Executes a task through an AutomatosX agent
46
+ *
47
+ * @param options - Execution options
48
+ * @returns AsyncGenerator that yields execution chunks
49
+ */
50
+ export declare function executeAgent(options: AgentExecutionOptions): AsyncGenerator<AgentExecutionChunk>;
51
+ /**
52
+ * Executes a task through an AutomatosX agent and returns the full result
53
+ *
54
+ * @param options - Execution options
55
+ * @returns Promise with execution result
56
+ */
57
+ export declare function executeAgentSync(options: AgentExecutionOptions): Promise<AgentExecutionResult>;
58
+ /**
59
+ * Check if ax command is available (cross-platform)
60
+ */
61
+ export declare function isAxAvailable(): Promise<boolean>;
@@ -0,0 +1,185 @@
1
+ /**
2
+ * Agent Executor - Executes tasks through AutomatosX agents
3
+ *
4
+ * Spawns `ax run <agent> "message"` and streams the output back.
5
+ *
6
+ * @module agent-executor
7
+ */
8
+ import { spawn } from 'child_process';
9
+ import { EventEmitter } from 'events';
10
+ /**
11
+ * Executes a task through an AutomatosX agent
12
+ *
13
+ * @param options - Execution options
14
+ * @returns AsyncGenerator that yields execution chunks
15
+ */
16
+ export async function* executeAgent(options) {
17
+ const { agent, task, cwd = process.cwd(), timeout = 600000, // 10 minutes default
18
+ env = {}, streaming = true, noMemory = false, } = options;
19
+ // Build command arguments
20
+ const args = ['run', agent, task];
21
+ if (streaming) {
22
+ args.push('--streaming');
23
+ }
24
+ if (noMemory) {
25
+ args.push('--no-memory');
26
+ }
27
+ // Create abort controller for timeout
28
+ const abortController = new AbortController();
29
+ const timeoutId = setTimeout(() => {
30
+ abortController.abort();
31
+ }, timeout);
32
+ let process_ = null;
33
+ let abortHandler = null;
34
+ try {
35
+ // Spawn ax process
36
+ process_ = spawn('ax', args, {
37
+ cwd,
38
+ env: { ...process.env, ...env },
39
+ stdio: ['pipe', 'pipe', 'pipe'],
40
+ shell: false,
41
+ });
42
+ // Handle process spawn error
43
+ if (!process_.stdout || !process_.stderr) {
44
+ throw new Error('Failed to create process streams');
45
+ }
46
+ // Create event emitter for async iteration
47
+ const emitter = new EventEmitter();
48
+ let buffer = '';
49
+ // Handle stdout
50
+ process_.stdout.on('data', (data) => {
51
+ const text = data.toString();
52
+ buffer += text;
53
+ // Emit complete lines
54
+ const lines = buffer.split('\n');
55
+ buffer = lines.pop() || '';
56
+ for (const line of lines) {
57
+ if (line.trim()) {
58
+ emitter.emit('chunk', { type: 'output', content: line + '\n' });
59
+ }
60
+ }
61
+ });
62
+ // Handle stderr
63
+ process_.stderr.on('data', (data) => {
64
+ const text = data.toString();
65
+ // Filter out common noise from stderr
66
+ if (!text.includes('npm warn') && !text.includes('ExperimentalWarning')) {
67
+ emitter.emit('chunk', { type: 'error', content: text });
68
+ }
69
+ });
70
+ // Handle process close
71
+ process_.on('close', (code) => {
72
+ // Emit any remaining buffer content
73
+ if (buffer.trim()) {
74
+ emitter.emit('chunk', { type: 'output', content: buffer });
75
+ }
76
+ emitter.emit('chunk', { type: 'done', exitCode: code ?? 0 });
77
+ emitter.emit('done');
78
+ });
79
+ // Handle process error
80
+ process_.on('error', (err) => {
81
+ emitter.emit('chunk', { type: 'error', content: err.message });
82
+ emitter.emit('chunk', { type: 'done', exitCode: 1 });
83
+ emitter.emit('done');
84
+ });
85
+ // Handle abort signal
86
+ abortHandler = () => {
87
+ if (process_ && !process_.killed) {
88
+ process_.kill('SIGTERM');
89
+ emitter.emit('chunk', { type: 'error', content: 'Agent execution timed out' });
90
+ emitter.emit('chunk', { type: 'done', exitCode: 124 });
91
+ emitter.emit('done');
92
+ }
93
+ };
94
+ abortController.signal.addEventListener('abort', abortHandler);
95
+ // Yield chunks as they arrive
96
+ const chunkQueue = [];
97
+ let isDone = false;
98
+ let resolveWait = null;
99
+ emitter.on('chunk', (chunk) => {
100
+ chunkQueue.push(chunk);
101
+ if (resolveWait) {
102
+ resolveWait();
103
+ resolveWait = null;
104
+ }
105
+ });
106
+ emitter.on('done', () => {
107
+ isDone = true;
108
+ if (resolveWait) {
109
+ resolveWait();
110
+ resolveWait = null;
111
+ }
112
+ });
113
+ while (!isDone || chunkQueue.length > 0) {
114
+ if (chunkQueue.length > 0) {
115
+ yield chunkQueue.shift();
116
+ }
117
+ else if (!isDone) {
118
+ await new Promise((resolve) => {
119
+ resolveWait = resolve;
120
+ });
121
+ }
122
+ }
123
+ }
124
+ finally {
125
+ clearTimeout(timeoutId);
126
+ // Clean up abort handler to prevent memory leak
127
+ if (abortHandler) {
128
+ abortController.signal.removeEventListener('abort', abortHandler);
129
+ }
130
+ if (process_ && !process_.killed) {
131
+ process_.kill('SIGTERM');
132
+ }
133
+ }
134
+ }
135
+ /**
136
+ * Executes a task through an AutomatosX agent and returns the full result
137
+ *
138
+ * @param options - Execution options
139
+ * @returns Promise with execution result
140
+ */
141
+ export async function executeAgentSync(options) {
142
+ const startTime = Date.now();
143
+ let output = '';
144
+ let exitCode = 0;
145
+ for await (const chunk of executeAgent(options)) {
146
+ switch (chunk.type) {
147
+ case 'output':
148
+ output += chunk.content || '';
149
+ break;
150
+ case 'error':
151
+ output += chunk.content || '';
152
+ break;
153
+ case 'done':
154
+ exitCode = chunk.exitCode ?? 0;
155
+ break;
156
+ }
157
+ }
158
+ return {
159
+ success: exitCode === 0,
160
+ output: output.trim(),
161
+ exitCode,
162
+ duration: Date.now() - startTime,
163
+ };
164
+ }
165
+ /**
166
+ * Check if ax command is available (cross-platform)
167
+ */
168
+ export async function isAxAvailable() {
169
+ return new Promise((resolve) => {
170
+ // Use 'where' on Windows, 'which' on Unix-like systems
171
+ const isWindows = process.platform === 'win32';
172
+ const command = isWindows ? 'where' : 'which';
173
+ const process_ = spawn(command, ['ax'], {
174
+ stdio: 'pipe',
175
+ shell: isWindows, // Windows needs shell for 'where'
176
+ });
177
+ process_.on('close', (code) => {
178
+ resolve(code === 0);
179
+ });
180
+ process_.on('error', () => {
181
+ resolve(false);
182
+ });
183
+ });
184
+ }
185
+ //# sourceMappingURL=agent-executor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-executor.js","sourceRoot":"","sources":["../../src/agent/agent-executor.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,KAAK,EAAqB,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAyCtC;;;;;GAKG;AACH,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,YAAY,CACjC,OAA8B;IAE9B,MAAM,EACJ,KAAK,EACL,IAAI,EACJ,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,EACnB,OAAO,GAAG,MAAM,EAAE,qBAAqB;IACvC,GAAG,GAAG,EAAE,EACR,SAAS,GAAG,IAAI,EAChB,QAAQ,GAAG,KAAK,GACjB,GAAG,OAAO,CAAC;IAEZ,0BAA0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,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Agent-First Router - MVP Implementation
3
+ *
4
+ * Lightweight router that matches user input to AutomatosX agents.
5
+ * Pure functions, session-cached availability, keyword-based matching.
6
+ *
7
+ * @module agent-router
8
+ */
9
+ import type { AgentFirstSettings } from '../schemas/settings-schemas.js';
10
+ /**
11
+ * Result of agent routing decision
12
+ */
13
+ export interface AgentRoutingResult {
14
+ /** Selected agent name, or null to use direct LLM */
15
+ agent: string | null;
16
+ /** System prefix to inject into conversation */
17
+ systemPrefix: string;
18
+ /** Transparency note shown in UI */
19
+ transparencyNote: string;
20
+ /** Confidence score (0-1) */
21
+ confidence: number;
22
+ /** Matched keywords that triggered the routing */
23
+ matchedKeywords: string[];
24
+ }
25
+ /**
26
+ * Configuration for agent routing
27
+ */
28
+ export interface AgentRouterConfig {
29
+ /** Enable/disable agent-first mode */
30
+ enabled: boolean;
31
+ /** Default agent when no keyword match */
32
+ defaultAgent: string | null;
33
+ /** Minimum confidence threshold for auto-routing */
34
+ confidenceThreshold: number;
35
+ /** Agents to exclude from auto-selection */
36
+ excludedAgents: string[];
37
+ }
38
+ /**
39
+ * Check if AutomatosX agents are available (cached per session)
40
+ */
41
+ export declare function checkAgentAvailability(): {
42
+ available: boolean;
43
+ agents: string[];
44
+ };
45
+ /**
46
+ * Reset availability cache (for testing or session reset)
47
+ */
48
+ export declare function resetAgentAvailabilityCache(): void;
49
+ /**
50
+ * Match user input to agent based on keywords
51
+ */
52
+ export declare function matchAgentByKeywords(userInput: string, availableAgents: string[], excludedAgents?: string[]): AgentRoutingResult | null;
53
+ /**
54
+ * Get default router config from settings
55
+ */
56
+ export declare function getDefaultRouterConfig(settings?: AgentFirstSettings): AgentRouterConfig;
57
+ /**
58
+ * Main routing function - determines which agent should handle the task
59
+ */
60
+ export declare function routeToAgent(userInput: string, config: AgentRouterConfig): AgentRoutingResult;
61
+ /**
62
+ * Get list of available agents for display
63
+ */
64
+ export declare function getAvailableAgents(): string[];
65
+ /**
66
+ * Check if a specific agent is available
67
+ */
68
+ export declare function isAgentAvailable(agentName: string): boolean;
@@ -0,0 +1,250 @@
1
+ /**
2
+ * Agent-First Router - MVP Implementation
3
+ *
4
+ * Lightweight router that matches user input to AutomatosX agents.
5
+ * Pure functions, session-cached availability, keyword-based matching.
6
+ *
7
+ * @module agent-router
8
+ */
9
+ import { existsSync, readdirSync } from 'fs';
10
+ import { join } from 'path';
11
+ // Session cache for availability (avoid repeated filesystem checks)
12
+ let availabilityCache = null;
13
+ const AVAILABILITY_CACHE_TTL = 60000; // 1 minute
14
+ /**
15
+ * Keyword to agent mapping (ordered by specificity)
16
+ * High-confidence keywords that strongly indicate domain
17
+ */
18
+ const AGENT_KEYWORD_RULES = [
19
+ // Security - highest priority (security concerns override domain)
20
+ {
21
+ agent: 'security',
22
+ keywords: /\b(security|vulnerab|cve|xss|csrf|injection|auth(?:entication|orization)|encrypt|owasp|pentest|threat|exploit)\b/i,
23
+ confidence: 0.9,
24
+ matchedTerms: ['security', 'vulnerability', 'cve', 'xss', 'csrf', 'injection', 'authentication', 'authorization', 'encryption', 'owasp', 'pentest', 'threat', 'exploit'],
25
+ },
26
+ // Quality/Testing
27
+ {
28
+ agent: 'quality',
29
+ keywords: /\b(test(?:ing)?|vitest|jest|cypress|playwright|coverage|qa|bug|regression|e2e|unit[\s-]?test|integration[\s-]?test|spec)\b/i,
30
+ confidence: 0.85,
31
+ matchedTerms: ['test', 'testing', 'vitest', 'jest', 'cypress', 'playwright', 'coverage', 'qa', 'bug', 'regression', 'e2e', 'unit test', 'integration test', 'spec'],
32
+ },
33
+ // DevOps
34
+ {
35
+ agent: 'devops',
36
+ keywords: /\b(docker|kubernetes|k8s|helm|terraform|ansible|ci[\s\/]?cd|github[\s-]?action|jenkins|deploy|infrastructure|aws|gcp|azure|nginx|load[\s-]?balanc)\b/i,
37
+ confidence: 0.85,
38
+ matchedTerms: ['docker', 'kubernetes', 'k8s', 'helm', 'terraform', 'ansible', 'ci/cd', 'github actions', 'jenkins', 'deploy', 'infrastructure', 'aws', 'gcp', 'azure', 'nginx', 'load balancer'],
39
+ },
40
+ // Backend - specific technologies
41
+ {
42
+ agent: 'backend',
43
+ keywords: /\b(api|rest(?:ful)?|graphql|grpc|database|postgresql|mysql|mongodb|redis|microservice|golang|rust|server[\s-]?side|endpoint|middleware|orm|prisma)\b/i,
44
+ confidence: 0.8,
45
+ matchedTerms: ['api', 'rest', 'restful', 'graphql', 'grpc', 'database', 'postgresql', 'mysql', 'mongodb', 'redis', 'microservice', 'golang', 'rust', 'server-side', 'endpoint', 'middleware', 'orm', 'prisma'],
46
+ },
47
+ // Frontend - specific technologies
48
+ {
49
+ agent: 'frontend',
50
+ keywords: /\b(react|vue|angular|svelte|next\.?js|nuxt|css|tailwind|component|ui[\s-]?component|dom|html|responsive|scss|sass|styled[\s-]?component|animation)\b/i,
51
+ confidence: 0.8,
52
+ matchedTerms: ['react', 'vue', 'angular', 'svelte', 'next.js', 'nuxt', 'css', 'tailwind', 'component', 'ui component', 'dom', 'html', 'responsive', 'scss', 'sass', 'styled-component', 'animation'],
53
+ },
54
+ // Mobile
55
+ {
56
+ agent: 'mobile',
57
+ keywords: /\b(ios|android|swift|kotlin|flutter|react[\s-]?native|mobile[\s-]?app|xcode|gradle|cocoapod|expo)\b/i,
58
+ confidence: 0.8,
59
+ matchedTerms: ['ios', 'android', 'swift', 'kotlin', 'flutter', 'react native', 'mobile app', 'xcode', 'gradle', 'cocoapod', 'expo'],
60
+ },
61
+ // Data
62
+ {
63
+ agent: 'data',
64
+ keywords: /\b(etl|data[\s-]?pipeline|analytics|sql|data[\s-]?model|warehouse|bigquery|spark|kafka|airflow|dbt)\b/i,
65
+ confidence: 0.75,
66
+ matchedTerms: ['etl', 'data pipeline', 'analytics', 'sql', 'data model', 'warehouse', 'bigquery', 'spark', 'kafka', 'airflow', 'dbt'],
67
+ },
68
+ // Architecture
69
+ {
70
+ agent: 'architecture',
71
+ keywords: /\b(architect|system[\s-]?design|adr|scalab|microservice[\s-]?architect|event[\s-]?driven|domain[\s-]?driven|ddd|cqrs)\b/i,
72
+ confidence: 0.75,
73
+ matchedTerms: ['architecture', 'system design', 'adr', 'scalability', 'microservice architecture', 'event-driven', 'domain-driven', 'ddd', 'cqrs'],
74
+ },
75
+ // Product
76
+ {
77
+ agent: 'product',
78
+ keywords: /\b(prd|product[\s-]?requirement|user[\s-]?story|feature[\s-]?spec|roadmap|stakeholder|acceptance[\s-]?criteria)\b/i,
79
+ confidence: 0.7,
80
+ matchedTerms: ['prd', 'product requirement', 'user story', 'feature spec', 'roadmap', 'stakeholder', 'acceptance criteria'],
81
+ },
82
+ // Documentation/Writing
83
+ {
84
+ agent: 'writer',
85
+ keywords: /\b(document(?:ation)?|readme|changelog|technical[\s-]?writ|api[\s-]?doc|jsdoc|typedoc|wiki)\b/i,
86
+ confidence: 0.7,
87
+ matchedTerms: ['documentation', 'readme', 'changelog', 'technical writing', 'api doc', 'jsdoc', 'typedoc', 'wiki'],
88
+ },
89
+ // Design
90
+ {
91
+ agent: 'design',
92
+ keywords: /\b(figma|ui[\s\/]?ux|wireframe|mockup|prototype|design[\s-]?system|user[\s-]?experience|accessibility|a11y)\b/i,
93
+ confidence: 0.7,
94
+ matchedTerms: ['figma', 'ui/ux', 'wireframe', 'mockup', 'prototype', 'design system', 'user experience', 'accessibility', 'a11y'],
95
+ },
96
+ // Standards/Review (fallback for code-related queries)
97
+ {
98
+ agent: 'standard',
99
+ keywords: /\b(solid|design[\s-]?pattern|clean[\s-]?code|refactor|code[\s-]?review|best[\s-]?practice|lint|eslint|prettier|code[\s-]?quality)\b/i,
100
+ confidence: 0.65,
101
+ matchedTerms: ['solid', 'design pattern', 'clean code', 'refactor', 'code review', 'best practice', 'lint', 'eslint', 'prettier', 'code quality'],
102
+ },
103
+ ];
104
+ /**
105
+ * Check if AutomatosX agents are available (cached per session)
106
+ */
107
+ export function checkAgentAvailability() {
108
+ const now = Date.now();
109
+ // Return cached result if still valid
110
+ if (availabilityCache?.checked &&
111
+ (now - availabilityCache.timestamp) < AVAILABILITY_CACHE_TTL) {
112
+ return { available: availabilityCache.available, agents: availabilityCache.agents };
113
+ }
114
+ try {
115
+ const agentsDir = join(process.cwd(), '.automatosx', 'agents');
116
+ if (!existsSync(agentsDir)) {
117
+ availabilityCache = { checked: true, available: false, agents: [], timestamp: now };
118
+ return { available: false, agents: [] };
119
+ }
120
+ const agents = readdirSync(agentsDir)
121
+ .filter(f => f.endsWith('.yaml') || f.endsWith('.yml'))
122
+ .map(f => f.replace(/\.ya?ml$/, ''));
123
+ availabilityCache = {
124
+ checked: true,
125
+ available: agents.length > 0,
126
+ agents,
127
+ timestamp: now,
128
+ };
129
+ return { available: agents.length > 0, agents };
130
+ }
131
+ catch {
132
+ availabilityCache = { checked: true, available: false, agents: [], timestamp: now };
133
+ return { available: false, agents: [] };
134
+ }
135
+ }
136
+ /**
137
+ * Reset availability cache (for testing or session reset)
138
+ */
139
+ export function resetAgentAvailabilityCache() {
140
+ availabilityCache = null;
141
+ }
142
+ /**
143
+ * Extract matched keywords from user input
144
+ */
145
+ function extractMatchedKeywords(userInput, rule) {
146
+ const input = userInput.toLowerCase();
147
+ return rule.matchedTerms.filter(term => input.includes(term.toLowerCase()));
148
+ }
149
+ /**
150
+ * Match user input to agent based on keywords
151
+ */
152
+ export function matchAgentByKeywords(userInput, availableAgents, excludedAgents = []) {
153
+ for (const rule of AGENT_KEYWORD_RULES) {
154
+ // Skip excluded agents
155
+ if (excludedAgents.includes(rule.agent)) {
156
+ continue;
157
+ }
158
+ // Check if agent is available
159
+ if (!availableAgents.includes(rule.agent)) {
160
+ continue;
161
+ }
162
+ // Test for keyword match
163
+ if (rule.keywords.test(userInput)) {
164
+ const matchedKeywords = extractMatchedKeywords(userInput, rule);
165
+ return {
166
+ agent: rule.agent,
167
+ confidence: rule.confidence,
168
+ systemPrefix: `[Routed to ${rule.agent} agent for specialized assistance]`,
169
+ transparencyNote: `Agent: ${rule.agent}`,
170
+ matchedKeywords,
171
+ };
172
+ }
173
+ }
174
+ return null; // No confident match
175
+ }
176
+ /**
177
+ * Get default router config from settings
178
+ */
179
+ export function getDefaultRouterConfig(settings) {
180
+ return {
181
+ enabled: settings?.enabled ?? true,
182
+ defaultAgent: settings?.defaultAgent ?? 'standard',
183
+ confidenceThreshold: settings?.confidenceThreshold ?? 0.6,
184
+ excludedAgents: settings?.excludedAgents ?? [],
185
+ };
186
+ }
187
+ /**
188
+ * Main routing function - determines which agent should handle the task
189
+ */
190
+ export function routeToAgent(userInput, config) {
191
+ // Check if routing is enabled
192
+ if (!config.enabled) {
193
+ return {
194
+ agent: null,
195
+ systemPrefix: '',
196
+ transparencyNote: '',
197
+ confidence: 0,
198
+ matchedKeywords: [],
199
+ };
200
+ }
201
+ // Check agent availability
202
+ const { available, agents } = checkAgentAvailability();
203
+ if (!available || agents.length === 0) {
204
+ return {
205
+ agent: null,
206
+ systemPrefix: '',
207
+ transparencyNote: '',
208
+ confidence: 0,
209
+ matchedKeywords: [],
210
+ };
211
+ }
212
+ // Try to match agent by keywords
213
+ const match = matchAgentByKeywords(userInput, agents, config.excludedAgents);
214
+ if (match && match.confidence >= config.confidenceThreshold) {
215
+ return match;
216
+ }
217
+ // Use default agent if configured and available
218
+ if (config.defaultAgent && agents.includes(config.defaultAgent)) {
219
+ return {
220
+ agent: config.defaultAgent,
221
+ confidence: 0.5,
222
+ systemPrefix: `[Using ${config.defaultAgent} agent]`,
223
+ transparencyNote: `Agent: ${config.defaultAgent}`,
224
+ matchedKeywords: [],
225
+ };
226
+ }
227
+ // No match, use direct LLM
228
+ return {
229
+ agent: null,
230
+ systemPrefix: '',
231
+ transparencyNote: '',
232
+ confidence: 0,
233
+ matchedKeywords: [],
234
+ };
235
+ }
236
+ /**
237
+ * Get list of available agents for display
238
+ */
239
+ export function getAvailableAgents() {
240
+ const { agents } = checkAgentAvailability();
241
+ return agents;
242
+ }
243
+ /**
244
+ * Check if a specific agent is available
245
+ */
246
+ export function isAgentAvailable(agentName) {
247
+ const { agents } = checkAgentAvailability();
248
+ return agents.includes(agentName);
249
+ }
250
+ //# sourceMappingURL=agent-router.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-router.js","sourceRoot":"","sources":["../../src/agent/agent-router.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,IAAI,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AA2C5B,oEAAoE;AACpE,IAAI,iBAAiB,GAKV,IAAI,CAAC;AAEhB,MAAM,sBAAsB,GAAG,KAAK,CAAC,CAAC,WAAW;AAEjD;;;GAGG;AACH,MAAM,mBAAmB,GAAuB;IAC9C,kEAAkE;IAClE;QACE,KAAK,EAAE,UAAU;QACjB,QAAQ,EAAE,mHAAmH;QAC7H,UAAU,EAAE,GAAG;QACf,YAAY,EAAE,CAAC,UAAU,EAAE,eAAe,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,gBAAgB,EAAE,eAAe,EAAE,YAAY,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,CAAC;KACzK;IAED,kBAAkB;IAClB;QACE,KAAK,EAAE,SAAS;QAChB,QAAQ,EAAE,6HAA6H;QACvI,UAAU,EAAE,IAAI;QAChB,YAAY,EAAE,CAAC,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,CAAC;KACpK;IAED,SAAS;IACT;QACE,KAAK,EAAE,QAAQ;QACf,QAAQ,EAAE,uJAAuJ;QACjK,UAAU,EAAE,IAAI;QAChB,YAAY,EAAE,CAAC,QAAQ,EAAE,YAAY,EAAE,KAAK,EAAE,MAA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U,IAAI,MAAM,CAAC,mBAAmB,EAAE,CAAC;QAC5D,OAAO,KAAK,CAAC;IACf,CAAC;IAED,gDAAgD;IAChD,IAAI,MAAM,CAAC,YAAY,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC;QAChE,OAAO;YACL,KAAK,EAAE,MAAM,CAAC,YAAY;YAC1B,UAAU,EAAE,GAAG;YACf,YAAY,EAAE,UAAU,MAAM,CAAC,YAAY,SAAS;YACpD,gBAAgB,EAAE,UAAU,MAAM,CAAC,YAAY,EAAE;YACjD,eAAe,EAAE,EAAE;SACpB,CAAC;IACJ,CAAC;IAED,2BAA2B;IAC3B,OAAO;QACL,KAAK,EAAE,IAAI;QACX,YAAY,EAAE,EAAE;QAChB,gBAAgB,EAAE,EAAE;QACpB,UAAU,EAAE,CAAC;QACb,eAAe,EAAE,EAAE;KACpB,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB;IAChC,MAAM,EAAE,MAAM,EAAE,GAAG,sBAAsB,EAAE,CAAC;IAC5C,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,SAAiB;IAChD,MAAM,EAAE,MAAM,EAAE,GAAG,sBAAsB,EAAE,CAAC;IAC5C,OAAO,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;AACpC,CAAC"}
@@ -359,49 +359,38 @@ export function createSetupCommand() {
359
359
  // Persist using settings manager to ensure encryption + permissions
360
360
  settingsManager.saveUserSettings(mergedConfig);
361
361
  console.log(chalk.green('\nāœ… Configuration saved successfully!\n'));
362
- // Offer Z.AI MCP setup for Z.AI providers
362
+ // Automatically enable Z.AI MCP servers for Z.AI providers (enabled by default)
363
363
  if (selectedProvider.name === 'z.ai' || selectedProvider.name === 'z.ai-free') {
364
364
  console.log(chalk.cyan('šŸ”Œ Z.AI MCP Integration\n'));
365
- console.log(chalk.dim(' Z.AI offers MCP servers for enhanced capabilities:'));
365
+ console.log(chalk.dim(' Enabling Z.AI MCP servers for enhanced capabilities:'));
366
366
  console.log(chalk.dim(' • Web Search - Real-time web search'));
367
367
  console.log(chalk.dim(' • Web Reader - Extract content from web pages'));
368
368
  console.log(chalk.dim(' • Vision - Image/video analysis (Node.js 22+)\n'));
369
- const enableMCP = await enquirer.prompt({
370
- type: 'confirm',
371
- name: 'enable',
372
- message: 'Enable Z.AI MCP servers?',
373
- initial: true,
374
- });
375
- if (enableMCP.enable) {
376
- try {
377
- const status = await detectZAIServices();
378
- const serversToAdd = getRecommendedServers(status);
379
- console.log(chalk.blue('\nSetting up Z.AI MCP servers...'));
380
- let successCount = 0;
381
- for (const serverName of serversToAdd) {
382
- const template = ZAI_MCP_TEMPLATES[serverName];
383
- try {
384
- const config = generateZAIServerConfig(serverName, apiKey);
385
- // Only save config during setup - don't connect (server will be connected when ax-cli runs)
386
- addMCPServer(config);
387
- console.log(chalk.green(`āœ“ ${template.displayName}`));
388
- successCount++;
389
- }
390
- catch {
391
- console.log(chalk.yellow(`⚠ ${template.displayName} (skipped)`));
392
- }
369
+ try {
370
+ const status = await detectZAIServices();
371
+ const serversToAdd = getRecommendedServers(status);
372
+ console.log(chalk.blue('Setting up Z.AI MCP servers...'));
373
+ let successCount = 0;
374
+ for (const serverName of serversToAdd) {
375
+ const template = ZAI_MCP_TEMPLATES[serverName];
376
+ try {
377
+ const config = generateZAIServerConfig(serverName, apiKey);
378
+ // Only save config during setup - don't connect (server will be connected when ax-cli runs)
379
+ addMCPServer(config);
380
+ console.log(chalk.green(`āœ“ ${template.displayName}`));
381
+ successCount++;
393
382
  }
394
- if (successCount > 0) {
395
- console.log(chalk.green(`\n✨ ${successCount} Z.AI MCP server${successCount !== 1 ? 's' : ''} enabled!\n`));
383
+ catch {
384
+ console.log(chalk.yellow(`⚠ ${template.displayName} (skipped)`));
396
385
  }
397
386
  }
398
- catch (error) {
399
- console.log(chalk.yellow('\nāš ļø Could not set up Z.AI MCP servers:'), extractErrorMessage(error));
400
- console.log(chalk.dim(' You can enable them later with: ax-cli mcp add-zai\n'));
387
+ if (successCount > 0) {
388
+ console.log(chalk.green(`\n✨ ${successCount} Z.AI MCP server${successCount !== 1 ? 's' : ''} enabled!\n`));
401
389
  }
402
390
  }
403
- else {
404
- console.log(chalk.dim('\n You can enable Z.AI MCP later with: ax-cli mcp add-zai\n'));
391
+ catch (error) {
392
+ console.log(chalk.yellow('\nāš ļø Could not set up Z.AI MCP servers:'), extractErrorMessage(error));
393
+ console.log(chalk.dim(' You can enable them later with: ax-cli mcp add-zai\n'));
405
394
  }
406
395
  }
407
396
  // AutomatosX Integration