@xagent-ai/cli 1.1.0 → 1.2.0

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/src/session.ts CHANGED
@@ -169,8 +169,8 @@ export class InteractiveSession {
169
169
  console.log('');
170
170
  console.log(colors.gradient('╔════════════════════════════════════════════════════════════╗'));
171
171
  console.log(colors.gradient('║') + ' '.repeat(58) + colors.gradient(' ║'));
172
- console.log(' '.repeat(14) + '🤖 ' + colors.gradient('XAGENT CLI') + ' '.repeat(32) + colors.gradient(' ║'));
173
- console.log(' '.repeat(17) + colors.textMuted(`v${packageJson.version}`) + ' '.repeat(36) + colors.gradient(' ║'));
172
+ console.log(colors.gradient('║') + ' '.repeat(13) + '🤖 ' + colors.gradient('XAGENT CLI') + ' '.repeat(32) + colors.gradient(' ║'));
173
+ console.log(colors.gradient('║') + ' '.repeat(16) + colors.textMuted(`v${packageJson.version}`) + ' '.repeat(36) + colors.gradient(' ║'));
174
174
  console.log(colors.gradient('║') + ' '.repeat(58) + colors.gradient(' ║'));
175
175
  console.log(colors.gradient('╚════════════════════════════════════════════════════════════╝'));
176
176
  console.log(colors.textMuted(' AI-powered command-line assistant'));
@@ -204,12 +204,15 @@ export class InteractiveSession {
204
204
  logger.debug('\n[SESSION] ========== initialize() 开始 ==========\n');
205
205
 
206
206
  try {
207
- const spinner = ora({
208
- text: colors.textMuted('Initializing XAGENT CLI...'),
209
- spinner: 'dots',
210
- color: 'cyan'
211
- }).start();
212
-
207
+ // Custom spinner for initialization (like Thinking...)
208
+ const frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
209
+ let frameIndex = 0;
210
+ const validatingText = colors.textMuted('Validating authentication...');
211
+
212
+ const spinnerInterval = setInterval(() => {
213
+ process.stdout.write(`\r${colors.primary(frames[frameIndex])} ${validatingText}`);
214
+ frameIndex = (frameIndex + 1) % frames.length;
215
+ }, 120);
213
216
  logger.debug('[SESSION] 调用 configManager.load()...');
214
217
  await this.configManager.load();
215
218
 
@@ -225,14 +228,24 @@ export class InteractiveSession {
225
228
 
226
229
  // Only validate OAuth tokens, skip validation for third-party API keys
227
230
  if (authConfig.apiKey && selectedAuthType === AuthType.OAUTH_XAGENT) {
228
- spinner.text = colors.textMuted('Validating authentication...');
231
+ clearInterval(spinnerInterval);
232
+ process.stdout.write('\r' + ' '.repeat(50) + '\r'); // Clear the line
233
+
229
234
  const baseUrl = authConfig.xagentApiBaseUrl || 'https://154.8.140.52:443';
230
235
  let isValid = await this.validateToken(baseUrl, authConfig.apiKey);
231
236
 
232
237
  // Try refresh token if validation failed
233
238
  if (!isValid && authConfig.refreshToken) {
234
- spinner.text = colors.textMuted('Refreshing authentication...');
239
+ const refreshingText = colors.textMuted('Refreshing authentication...');
240
+ frameIndex = 0;
241
+ const refreshInterval = setInterval(() => {
242
+ process.stdout.write(`\r${colors.primary(frames[frameIndex])} ${refreshingText}`);
243
+ frameIndex = (frameIndex + 1) % frames.length;
244
+ }, 120);
245
+
235
246
  const newToken = await this.refreshToken(baseUrl, authConfig.refreshToken);
247
+ clearInterval(refreshInterval);
248
+ process.stdout.write('\r' + ' '.repeat(50) + '\r');
236
249
 
237
250
  if (newToken) {
238
251
  // Save new token and persist
@@ -244,10 +257,9 @@ export class InteractiveSession {
244
257
  }
245
258
 
246
259
  if (!isValid) {
247
- spinner.stop();
248
260
  console.log('');
249
- console.log(colors.warning('⚠️ Authentication expired or invalid'));
250
- console.log(colors.info('Please log in again to continue.'));
261
+ console.log(colors.warning('Your xAgent session has expired or is not configured'));
262
+ console.log(colors.info('Please select an authentication method to continue.'));
251
263
  console.log('');
252
264
 
253
265
  // Clear invalid credentials and persist
@@ -271,11 +283,11 @@ export class InteractiveSession {
271
283
  this.rl.on('close', () => {
272
284
  // readline closed
273
285
  });
274
- spinner.start();
275
286
  }
276
287
  } else if (!authConfig.apiKey) {
277
288
  // No API key configured, need to set up authentication
278
- spinner.stop();
289
+ clearInterval(spinnerInterval);
290
+ process.stdout.write('\r' + ' '.repeat(50) + '\r');
279
291
  await this.setupAuthentication();
280
292
  authConfig = this.configManager.getAuthConfig();
281
293
  selectedAuthType = this.configManager.get('selectedAuthType');
@@ -290,7 +302,9 @@ export class InteractiveSession {
290
302
  this.rl.on('close', () => {
291
303
  // readline closed
292
304
  });
293
- spinner.start();
305
+ } else {
306
+ clearInterval(spinnerInterval);
307
+ process.stdout.write('\r' + ' '.repeat(50) + '\r');
294
308
  }
295
309
  // For OPENAI_COMPATIBLE with API key, skip validation and proceed directly
296
310
 
@@ -328,7 +342,6 @@ export class InteractiveSession {
328
342
  this.slashCommandHandler.setConversationHistory(this.conversation);
329
343
 
330
344
  const mcpServers = this.configManager.getMcpServers();
331
- console.log(`📋 Loading ${Object.keys(mcpServers).length} MCP servers from config`);
332
345
  Object.entries(mcpServers).forEach(([name, config]) => {
333
346
  console.log(`📝 Registering MCP server: ${name} (${config.transport})`);
334
347
  this.mcpManager.registerServer(name, config);
@@ -364,7 +377,7 @@ export class InteractiveSession {
364
377
 
365
378
  this.currentAgent = this.agentManager.getAgent('general-purpose');
366
379
 
367
- spinner.succeed(colors.success('Initialization complete'));
380
+ console.log(colors.success('Initialization complete'));
368
381
  } catch (error: any) {
369
382
  const spinner = ora({ text: '', spinner: 'dots', color: 'red' }).start();
370
383
  spinner.fail(colors.error(`Initialization failed: ${error.message}`));
@@ -459,11 +472,14 @@ export class InteractiveSession {
459
472
 
460
473
  const authConfig = authService.getAuthConfig();
461
474
 
462
- // VLM configuration is optional - skip for now, can be configured later with /vlm command
463
- console.log('');
464
- console.log(colors.info(`${icons.info} VLM configuration is optional.`));
465
- console.log(colors.info(`You can configure it later using the /vlm command if needed.`));
466
- console.log('');
475
+ // VLM configuration is optional - only show for non-OAuth (local) mode
476
+ // Remote mode uses backend VLM configuration
477
+ if (authType !== AuthType.OAUTH_XAGENT) {
478
+ console.log('');
479
+ console.log(colors.info(`${icons.info} VLM configuration is optional.`));
480
+ console.log(colors.info(`You can configure it later using the /vlm command if needed.`));
481
+ console.log('');
482
+ }
467
483
 
468
484
  // Save LLM config only, skip VLM for now
469
485
  await this.configManager.setAuthConfig(authConfig);
@@ -951,11 +967,7 @@ export class InteractiveSession {
951
967
 
952
968
  const messages: ChatMessage[] = [
953
969
  { role: 'system', content: `${enhancedSystemPrompt}\n\n${memory}`, timestamp: Date.now() },
954
- ...this.conversation.map(msg => ({
955
- role: msg.role,
956
- content: msg.content,
957
- timestamp: msg.timestamp
958
- }))
970
+ ...this.conversation
959
971
  ];
960
972
 
961
973
  const operationId = `ai-response-${Date.now()}`;
@@ -1131,11 +1143,7 @@ export class InteractiveSession {
1131
1143
  // Build messages with system prompt (与本地模式一致)
1132
1144
  const messages: ChatMessage[] = [
1133
1145
  { role: 'system', content: `${enhancedSystemPrompt}\n\n${memory}`, timestamp: Date.now() },
1134
- ...this.conversation.map(msg => ({
1135
- role: msg.role,
1136
- content: msg.content,
1137
- timestamp: msg.timestamp
1138
- }))
1146
+ ...this.conversation
1139
1147
  ];
1140
1148
 
1141
1149
  // Call unified LLM API with cancellation support
@@ -1312,7 +1320,7 @@ export class InteractiveSession {
1312
1320
  parsedParams = params;
1313
1321
  }
1314
1322
 
1315
- return { name, params: parsedParams, index };
1323
+ return { name, params: parsedParams, index, id: toolCall.id };
1316
1324
  });
1317
1325
 
1318
1326
  // Display all tool calls info
@@ -1355,6 +1363,7 @@ export class InteractiveSession {
1355
1363
  this.conversation.push({
1356
1364
  role: 'tool',
1357
1365
  content: JSON.stringify({ error }),
1366
+ tool_call_id: toolCall.id,
1358
1367
  timestamp: Date.now()
1359
1368
  });
1360
1369
  } else {
@@ -1407,6 +1416,7 @@ export class InteractiveSession {
1407
1416
  this.conversation.push({
1408
1417
  role: 'tool',
1409
1418
  content: JSON.stringify(result),
1419
+ tool_call_id: toolCall.id,
1410
1420
  timestamp: Date.now()
1411
1421
  });
1412
1422
  }
@@ -1478,7 +1488,7 @@ export class InteractiveSession {
1478
1488
  const showToolDetails = this.configManager.get('showToolDetails') || false;
1479
1489
  const indent = this.getIndent();
1480
1490
 
1481
- // Prepare all tool calls
1491
+ // Prepare all tool calls (include id for tool result matching)
1482
1492
  const preparedToolCalls = toolCalls.map((toolCall, index) => {
1483
1493
  const { name, arguments: params } = toolCall.function;
1484
1494
 
@@ -1489,7 +1499,7 @@ export class InteractiveSession {
1489
1499
  parsedParams = params;
1490
1500
  }
1491
1501
 
1492
- return { name, params: parsedParams, index };
1502
+ return { name, params: parsedParams, index, id: toolCall.id };
1493
1503
  });
1494
1504
 
1495
1505
  // Display all tool calls info
@@ -1535,6 +1545,7 @@ export class InteractiveSession {
1535
1545
  this.conversation.push({
1536
1546
  role: 'tool',
1537
1547
  content: JSON.stringify({ error }),
1548
+ tool_call_id: toolCall.id,
1538
1549
  timestamp: Date.now()
1539
1550
  });
1540
1551
  } else {
@@ -1585,6 +1596,7 @@ export class InteractiveSession {
1585
1596
  this.conversation.push({
1586
1597
  role: 'tool',
1587
1598
  content: JSON.stringify(result),
1599
+ tool_call_id: toolCall.id,
1588
1600
  timestamp: Date.now()
1589
1601
  });
1590
1602
  }