@xagent-ai/cli 1.3.4 → 1.3.6
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/agents.d.ts.map +1 -1
- package/dist/agents.js +0 -4
- package/dist/agents.js.map +1 -1
- package/dist/ai-client/providers/anthropic.d.ts +4 -0
- package/dist/ai-client/providers/anthropic.d.ts.map +1 -1
- package/dist/ai-client/providers/anthropic.js +55 -2
- package/dist/ai-client/providers/anthropic.js.map +1 -1
- package/dist/ai-client/providers/openai.d.ts +4 -0
- package/dist/ai-client/providers/openai.d.ts.map +1 -1
- package/dist/ai-client/providers/openai.js +47 -0
- package/dist/ai-client/providers/openai.js.map +1 -1
- package/dist/ai-client/providers/remote.d.ts.map +1 -1
- package/dist/ai-client/providers/remote.js +34 -4
- package/dist/ai-client/providers/remote.js.map +1 -1
- package/dist/ai-client-factory.d.ts.map +1 -1
- package/dist/ai-client-factory.js +3 -0
- package/dist/ai-client-factory.js.map +1 -1
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +0 -3
- package/dist/session.js.map +1 -1
- package/dist/smart-approval.d.ts.map +1 -1
- package/dist/smart-approval.js +2 -1
- package/dist/smart-approval.js.map +1 -1
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +7 -27
- package/dist/tools.js.map +1 -1
- package/package.json +1 -1
- package/src/agents.ts +0 -4
- package/src/ai-client/providers/anthropic.ts +62 -1
- package/src/ai-client/providers/openai.ts +56 -0
- package/src/ai-client/providers/remote.ts +43 -4
- package/src/ai-client-factory.ts +3 -0
- package/src/session.ts +0 -4
- package/src/smart-approval.ts +2 -1
- package/src/tools.ts +8 -38
|
@@ -121,6 +121,10 @@ export class AnthropicProvider implements AIProvider {
|
|
|
121
121
|
return this.convertResponse(response.data, model);
|
|
122
122
|
}, retryConfig);
|
|
123
123
|
|
|
124
|
+
if (showDebug && result.data) {
|
|
125
|
+
this.debugResponse(result.data);
|
|
126
|
+
}
|
|
127
|
+
|
|
124
128
|
if (result.success) {
|
|
125
129
|
return result.data!;
|
|
126
130
|
}
|
|
@@ -425,11 +429,68 @@ export class AnthropicProvider implements AIProvider {
|
|
|
425
429
|
console.log(`╚══════════════════════════════════════════════════════════╝`);
|
|
426
430
|
console.log(`📦 Model: ${model}`);
|
|
427
431
|
console.log(`💬 Messages: ${messages.length}`);
|
|
428
|
-
if (system)
|
|
432
|
+
if (system) {
|
|
433
|
+
console.log(`📝 System: ${system}`);
|
|
434
|
+
}
|
|
429
435
|
console.log('─'.repeat(60));
|
|
436
|
+
|
|
437
|
+
// Print each message content
|
|
438
|
+
messages.forEach((msg, idx) => {
|
|
439
|
+
const role = msg.role || 'unknown';
|
|
440
|
+
console.log(`\n[${idx + 1}] Role: ${role}`);
|
|
441
|
+
|
|
442
|
+
if (msg.content && Array.isArray(msg.content)) {
|
|
443
|
+
msg.content.forEach((block: ContentBlock) => {
|
|
444
|
+
if (block.type === 'text') {
|
|
445
|
+
console.log(` Text: ${block.text}`);
|
|
446
|
+
} else if (block.type === 'tool_use') {
|
|
447
|
+
console.log(` [Tool Use] ${block.name}: ${JSON.stringify(block.input || {})}`);
|
|
448
|
+
} else if (block.type === 'tool_result') {
|
|
449
|
+
console.log(` [Tool Result] ${block.tool_use_id}: ${block.content}`);
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
});
|
|
454
|
+
|
|
430
455
|
console.log('\n📤 Sending request...\n');
|
|
431
456
|
}
|
|
432
457
|
|
|
458
|
+
/**
|
|
459
|
+
* Debug response output
|
|
460
|
+
*/
|
|
461
|
+
private debugResponse(response: CompletionResponse): void {
|
|
462
|
+
console.log(`\n╔══════════════════════════════════════════════════════════╗`);
|
|
463
|
+
console.log(`║ AI RESPONSE DEBUG (Anthropic) ║`);
|
|
464
|
+
console.log(`╚══════════════════════════════════════════════════════════╝`);
|
|
465
|
+
console.log(`🆔 ID: ${response.id}`);
|
|
466
|
+
console.log(`📦 Model: ${response.model}`);
|
|
467
|
+
console.log(`⏱️ Created: ${response.created}`);
|
|
468
|
+
console.log('─'.repeat(60));
|
|
469
|
+
|
|
470
|
+
// Print each choice
|
|
471
|
+
response.choices?.forEach((choice, idx) => {
|
|
472
|
+
const msg = choice.message;
|
|
473
|
+
const content = msg?.content || '';
|
|
474
|
+
const reasoning = msg?.reasoning_content ? `\n [Reasoning] ${msg.reasoning_content}` : '';
|
|
475
|
+
const toolCalls = msg?.tool_calls ? `\n [Tool Calls] ${JSON.stringify(msg.tool_calls, null, 2)}` : '';
|
|
476
|
+
|
|
477
|
+
console.log(`\n[Choice ${idx}] Finish Reason: ${choice.finish_reason}${reasoning}${toolCalls}`);
|
|
478
|
+
if (content) {
|
|
479
|
+
// No truncation
|
|
480
|
+
console.log(` Content: ${content}`);
|
|
481
|
+
}
|
|
482
|
+
});
|
|
483
|
+
|
|
484
|
+
if (response.usage) {
|
|
485
|
+
console.log('\n📊 Usage:');
|
|
486
|
+
console.log(` Input tokens: ${response.usage.prompt_tokens}`);
|
|
487
|
+
console.log(` Output tokens: ${response.usage.completion_tokens}`);
|
|
488
|
+
console.log(` Total tokens: ${response.usage.total_tokens}`);
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
console.log('\n📥 Response received.\n');
|
|
492
|
+
}
|
|
493
|
+
|
|
433
494
|
/**
|
|
434
495
|
* Handle errors
|
|
435
496
|
*/
|
|
@@ -103,6 +103,10 @@ export class OpenAIProvider implements AIProvider {
|
|
|
103
103
|
return this.convertResponse(response.data, model);
|
|
104
104
|
}, retryConfig);
|
|
105
105
|
|
|
106
|
+
if (showDebug && result.data) {
|
|
107
|
+
this.debugResponse(result.data);
|
|
108
|
+
}
|
|
109
|
+
|
|
106
110
|
if (result.success) {
|
|
107
111
|
return result.data!;
|
|
108
112
|
}
|
|
@@ -304,9 +308,61 @@ export class OpenAIProvider implements AIProvider {
|
|
|
304
308
|
console.log(`📦 Model: ${model}`);
|
|
305
309
|
console.log(`💬 Messages: ${messages.length}`);
|
|
306
310
|
console.log('─'.repeat(60));
|
|
311
|
+
|
|
312
|
+
// Print each message content
|
|
313
|
+
messages.forEach((msg, idx) => {
|
|
314
|
+
const role = msg.role || 'unknown';
|
|
315
|
+
const content = msg.content || '';
|
|
316
|
+
const reasoning = msg.reasoning_content ? `\n [Reasoning] ${msg.reasoning_content}` : '';
|
|
317
|
+
const toolCalls = msg.tool_calls ? `\n [Tool Calls] ${JSON.stringify(msg.tool_calls, null, 2)}` : '';
|
|
318
|
+
const toolCallId = msg.tool_call_id ? `\n [Tool Call ID] ${msg.tool_call_id}` : '';
|
|
319
|
+
|
|
320
|
+
console.log(`\n[${idx + 1}] Role: ${role}${reasoning}${toolCalls}${toolCallId}`);
|
|
321
|
+
if (content) {
|
|
322
|
+
// No truncation for system messages or any content
|
|
323
|
+
console.log(` Content: ${content}`);
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
|
|
307
327
|
console.log('\n📤 Sending request...\n');
|
|
308
328
|
}
|
|
309
329
|
|
|
330
|
+
/**
|
|
331
|
+
* Debug response output
|
|
332
|
+
*/
|
|
333
|
+
private debugResponse(response: CompletionResponse): void {
|
|
334
|
+
console.log(`\n╔══════════════════════════════════════════════════════════╗`);
|
|
335
|
+
console.log(`║ AI RESPONSE DEBUG (OpenAI) ║`);
|
|
336
|
+
console.log(`╚══════════════════════════════════════════════════════════╝`);
|
|
337
|
+
console.log(`🆔 ID: ${response.id}`);
|
|
338
|
+
console.log(`📦 Model: ${response.model}`);
|
|
339
|
+
console.log(`⏱️ Created: ${response.created}`);
|
|
340
|
+
console.log('─'.repeat(60));
|
|
341
|
+
|
|
342
|
+
// Print each choice
|
|
343
|
+
response.choices?.forEach((choice, idx) => {
|
|
344
|
+
const msg = choice.message;
|
|
345
|
+
const content = msg?.content || '';
|
|
346
|
+
const reasoning = msg?.reasoning_content ? `\n [Reasoning] ${msg.reasoning_content}` : '';
|
|
347
|
+
const toolCalls = msg?.tool_calls ? `\n [Tool Calls] ${JSON.stringify(msg.tool_calls, null, 2)}` : '';
|
|
348
|
+
|
|
349
|
+
console.log(`\n[Choice ${idx}] Finish Reason: ${choice.finish_reason}${reasoning}${toolCalls}`);
|
|
350
|
+
if (content) {
|
|
351
|
+
// No truncation
|
|
352
|
+
console.log(` Content: ${content}`);
|
|
353
|
+
}
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
if (response.usage) {
|
|
357
|
+
console.log('\n📊 Usage:');
|
|
358
|
+
console.log(` Prompt tokens: ${response.usage.prompt_tokens}`);
|
|
359
|
+
console.log(` Completion tokens: ${response.usage.completion_tokens}`);
|
|
360
|
+
console.log(` Total tokens: ${response.usage.total_tokens}`);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
console.log('\n📥 Response received.\n');
|
|
364
|
+
}
|
|
365
|
+
|
|
310
366
|
/**
|
|
311
367
|
* Handle errors
|
|
312
368
|
*/
|
|
@@ -275,6 +275,22 @@ export class RemoteProvider implements AIProvider {
|
|
|
275
275
|
console.log(`🌐 Base URL: ${this.webBaseUrl}`);
|
|
276
276
|
console.log(`💬 Messages: ${messages.length}`);
|
|
277
277
|
console.log('─'.repeat(60));
|
|
278
|
+
|
|
279
|
+
// Print each message content
|
|
280
|
+
messages.forEach((msg, idx) => {
|
|
281
|
+
const role = msg.role || 'unknown';
|
|
282
|
+
const content = msg.content || '';
|
|
283
|
+
const reasoning = msg.reasoning_content ? `\n [Reasoning] ${msg.reasoning_content}` : '';
|
|
284
|
+
const toolCalls = msg.tool_calls ? `\n [Tool Calls] ${JSON.stringify(msg.tool_calls, null, 2)}` : '';
|
|
285
|
+
const toolCallId = msg.tool_call_id ? `\n [Tool Call ID] ${msg.tool_call_id}` : '';
|
|
286
|
+
|
|
287
|
+
console.log(`\n[${idx + 1}] Role: ${role}${reasoning}${toolCalls}${toolCallId}`);
|
|
288
|
+
if (content) {
|
|
289
|
+
// No truncation
|
|
290
|
+
console.log(` Content: ${content}`);
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
|
|
278
294
|
console.log('\n📤 Sending request to Remote API...\n');
|
|
279
295
|
}
|
|
280
296
|
|
|
@@ -285,11 +301,34 @@ export class RemoteProvider implements AIProvider {
|
|
|
285
301
|
console.log('\n╔══════════════════════════════════════════════════════════╗');
|
|
286
302
|
console.log('║ AI RESPONSE DEBUG (REMOTE) ║');
|
|
287
303
|
console.log('╚══════════════════════════════════════════════════════════╝');
|
|
288
|
-
console.log(`🆔 ID: remote-${Date.now()}`);
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
304
|
+
console.log(`🆔 ID: ${data.id || `remote-${Date.now()}`}`);
|
|
305
|
+
|
|
306
|
+
const content = data?.message || data?.content || '';
|
|
307
|
+
const reasoning = data?.reasoning_content || data?.reasoningContent || '';
|
|
308
|
+
const toolCalls = data?.tool_calls || data?.toolCalls || [];
|
|
309
|
+
|
|
310
|
+
if (reasoning) {
|
|
311
|
+
console.log(`\n💭 Reasoning: ${reasoning}`);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
if (content) {
|
|
315
|
+
console.log(`\n📝 Content: ${content}`);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
if (toolCalls?.length) {
|
|
319
|
+
console.log(`\n🔧 Tool calls: ${toolCalls.length}`);
|
|
320
|
+
toolCalls.forEach((tc: any, idx: number) => {
|
|
321
|
+
console.log(` [${idx + 1}] ${tc.function?.name || tc.name}: ${tc.function?.arguments || tc.arguments}`);
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
if (data?.usage) {
|
|
326
|
+
console.log('\n📊 Usage:');
|
|
327
|
+
console.log(` Prompt tokens: ${data.usage.prompt_tokens}`);
|
|
328
|
+
console.log(` Completion tokens: ${data.usage.completion_tokens}`);
|
|
329
|
+
console.log(` Total tokens: ${data.usage.total_tokens}`);
|
|
292
330
|
}
|
|
331
|
+
|
|
293
332
|
console.log('\n📥 Response received.\n');
|
|
294
333
|
}
|
|
295
334
|
|
package/src/ai-client-factory.ts
CHANGED
|
@@ -150,6 +150,7 @@ export function createAIClient(authConfig: AuthConfig): AIClientInterface {
|
|
|
150
150
|
type: 'remote',
|
|
151
151
|
authToken: authConfig.apiKey || '',
|
|
152
152
|
baseUrl: authConfig.xagentApiBaseUrl || 'https://app.xagent.cn',
|
|
153
|
+
showDebugInfo: authConfig.showAIDebugInfo,
|
|
153
154
|
};
|
|
154
155
|
} else if (authConfig.baseUrl?.includes('anthropic') ||
|
|
155
156
|
authConfig.baseUrl?.includes('minimax') ||
|
|
@@ -160,6 +161,7 @@ export function createAIClient(authConfig: AuthConfig): AIClientInterface {
|
|
|
160
161
|
apiKey: authConfig.apiKey || '',
|
|
161
162
|
baseUrl: authConfig.baseUrl || 'https://api.anthropic.com',
|
|
162
163
|
model: authConfig.modelName || 'claude-sonnet-4-20250514',
|
|
164
|
+
showDebugInfo: authConfig.showAIDebugInfo,
|
|
163
165
|
};
|
|
164
166
|
} else {
|
|
165
167
|
// Default to OpenAI compatible mode
|
|
@@ -168,6 +170,7 @@ export function createAIClient(authConfig: AuthConfig): AIClientInterface {
|
|
|
168
170
|
apiKey: authConfig.apiKey || '',
|
|
169
171
|
baseUrl: authConfig.baseUrl || 'https://api.openai.com/v1',
|
|
170
172
|
model: authConfig.modelName || 'gpt-4o',
|
|
173
|
+
showDebugInfo: authConfig.showAIDebugInfo,
|
|
171
174
|
};
|
|
172
175
|
}
|
|
173
176
|
|
package/src/session.ts
CHANGED
package/src/smart-approval.ts
CHANGED
package/src/tools.ts
CHANGED
|
@@ -3525,6 +3525,14 @@ export class InvokeSkillTool implements Tool {
|
|
|
3525
3525
|
}> {
|
|
3526
3526
|
const { skillId, taskDescription, inputFile, outputFile, options } = params;
|
|
3527
3527
|
|
|
3528
|
+
// Validate required parameters
|
|
3529
|
+
if (!skillId || skillId.trim() === '') {
|
|
3530
|
+
throw new Error('Missing required parameter: skillId is required to invoke a skill');
|
|
3531
|
+
}
|
|
3532
|
+
if (!taskDescription || taskDescription.trim() === '') {
|
|
3533
|
+
throw new Error('Missing required parameter: taskDescription is required to invoke a skill');
|
|
3534
|
+
}
|
|
3535
|
+
|
|
3528
3536
|
try {
|
|
3529
3537
|
const { getSkillInvoker } = await import('./skill-invoker.js');
|
|
3530
3538
|
const skillInvoker = getSkillInvoker();
|
|
@@ -4470,44 +4478,6 @@ export class ToolRegistry {
|
|
|
4470
4478
|
if (executionMode === ExecutionMode.SMART) {
|
|
4471
4479
|
const debugMode = process.env.DEBUG === 'smart-approval';
|
|
4472
4480
|
|
|
4473
|
-
// task tool bypasses smart approval entirely
|
|
4474
|
-
if (toolName === 'task') {
|
|
4475
|
-
if (debugMode) {
|
|
4476
|
-
const { getLogger } = await import('./logger.js');
|
|
4477
|
-
const logger = getLogger();
|
|
4478
|
-
logger.debug(
|
|
4479
|
-
`[SmartApprovalEngine] Tool '${toolName}' bypassed smart approval completely`
|
|
4480
|
-
);
|
|
4481
|
-
}
|
|
4482
|
-
return await cancellationManager.withCancellation(
|
|
4483
|
-
tool.execute(params, executionMode),
|
|
4484
|
-
`tool-${toolName}`
|
|
4485
|
-
);
|
|
4486
|
-
}
|
|
4487
|
-
|
|
4488
|
-
// Remote mode (OAuth XAGENT): remote LLM has already approved the tool
|
|
4489
|
-
// Auto-approve InvokeSkill tools without local AI review
|
|
4490
|
-
const { getConfigManager } = await import('./config.js');
|
|
4491
|
-
const configManager = getConfigManager();
|
|
4492
|
-
const authConfig = configManager.getAuthConfig();
|
|
4493
|
-
const isRemoteMode = authConfig.type === AuthType.OAUTH_XAGENT;
|
|
4494
|
-
if (isRemoteMode && toolName === 'InvokeSkill') {
|
|
4495
|
-
console.log('');
|
|
4496
|
-
if (isSdkMode && sdkOutputAdapter) {
|
|
4497
|
-
sdkOutputAdapter.outputInfo(`[Smart Mode] Remote mode: tool '${toolName}' auto-approved (remote LLM already approved)`);
|
|
4498
|
-
} else {
|
|
4499
|
-
console.log('');
|
|
4500
|
-
console.log(
|
|
4501
|
-
`${indent}${colors.success(`✅ [Smart Mode] Remote mode: tool '${toolName}' auto-approved (remote LLM already approved)`)}`
|
|
4502
|
-
);
|
|
4503
|
-
console.log('');
|
|
4504
|
-
}
|
|
4505
|
-
return await cancellationManager.withCancellation(
|
|
4506
|
-
tool.execute(params, executionMode),
|
|
4507
|
-
`tool-${toolName}`
|
|
4508
|
-
);
|
|
4509
|
-
}
|
|
4510
|
-
|
|
4511
4481
|
const { getSmartApprovalEngine } = await import('./smart-approval.js');
|
|
4512
4482
|
|
|
4513
4483
|
const approvalEngine = getSmartApprovalEngine(debugMode);
|