xiaozhou-chat 1.0.24 → 1.0.26

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.
Files changed (3) hide show
  1. package/bin/cli.js +27 -2
  2. package/lib/chat.js +6 -12
  3. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -103,6 +103,18 @@ if (args._[0] === "config") {
103
103
  changed = true;
104
104
  }
105
105
 
106
+ if (args.profile || args.p) {
107
+ const val = args.profile || args.p;
108
+ if (config.profiles && config.profiles[val]) {
109
+ updateConfig("currentProfile", val);
110
+ console.log(`✅ 已切换到配置环境 (Profile): ${val}`);
111
+ changed = true;
112
+ } else {
113
+ console.error(`❌ 配置环境 '${val}' 不存在。可用环境: ${Object.keys(config.profiles || {}).join(", ")}`);
114
+ process.exit(1);
115
+ }
116
+ }
117
+
106
118
  if (!changed) {
107
119
  console.log("当前生效配置 (Active Profile):");
108
120
  console.log(JSON.stringify(getActiveConfig(config), null, 2));
@@ -110,6 +122,7 @@ if (args._[0] === "config") {
110
122
  console.log(" npx xiaozhou-chat config --key=sk-xxxx");
111
123
  console.log(" npx xiaozhou-chat config --url=https://api.example.com/v1");
112
124
  console.log(" npx xiaozhou-chat config --model=gpt-4");
125
+ console.log(" npx xiaozhou-chat config --profile=default # 切换配置环境");
113
126
  }
114
127
 
115
128
  process.exit(0);
@@ -240,6 +253,13 @@ async function mainChat(input) {
240
253
  // 准备 Tools
241
254
  const tools = [...builtInTools];
242
255
 
256
+ // 合并 MCP Tools
257
+ for (const client of mcpClients.values()) {
258
+ if (client.initialized && client.tools.length > 0) {
259
+ tools.push(...client.getOpenAITools());
260
+ }
261
+ }
262
+
243
263
  abortController = new AbortController();
244
264
 
245
265
  const ctx = {
@@ -484,8 +504,13 @@ ${JSON.stringify(toCompress)}
484
504
  }
485
505
 
486
506
  // Default: Chat
487
- await mainChat(input);
488
- rl.prompt();
507
+ isProcessing = true;
508
+ try {
509
+ await mainChat(input);
510
+ } finally {
511
+ isProcessing = false;
512
+ rl.prompt();
513
+ }
489
514
  });
490
515
 
491
516
  function addToContext(content) {
package/lib/chat.js CHANGED
@@ -438,25 +438,19 @@ export async function chatStream(context, userInput = null, options = {}) {
438
438
 
439
439
  // 2. Try MCP
440
440
  if (!result && mcpClients) {
441
- // Find which client has this tool?
442
- // We assume caller knows or we iterate.
443
- // For now, simplify: mcpClients is a Map<name, client>
444
- // We need to know which client provides which tool.
445
- // Or we iterate all clients (slow?).
446
- // In original cli.js, it wasn't fully implemented for *execution* via MCP map iteration?
447
- // Ah, original cli.js didn't iterate mcpClients for execution in the snippet I saw.
448
- // It only had `builtInTools`.
449
- // But the todo said "integrate MCP support".
450
- // I should check if I missed MCP execution logic.
451
- // Assuming mcpClients have a `callTool` method.
452
441
  for (const client of mcpClients.values()) {
442
+ // Optimization: Check if client has the tool before calling
443
+ if (!client.tools.some(t => t.name === funcName)) continue;
444
+
453
445
  try {
454
446
  const mcpRes = await client.callTool(funcName, args);
455
447
  if (mcpRes) {
456
448
  result = JSON.stringify(mcpRes);
457
449
  break;
458
450
  }
459
- } catch {}
451
+ } catch (e) {
452
+ console.error(`MCP Call Error (${funcName}):`, e.message);
453
+ }
460
454
  }
461
455
  }
462
456
  } catch (e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xiaozhou-chat",
3
- "version": "1.0.24",
3
+ "version": "1.0.26",
4
4
  "description": "CLI chatbot based on NewAPI",
5
5
  "bin": {
6
6
  "xiaozhou-chat": "bin/cli.js"