@vrs-soft/wecom-aibot-mcp 3.3.0 → 3.3.2

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.
@@ -16,7 +16,7 @@ import * as fs from 'fs';
16
16
  import * as path from 'path';
17
17
  import { execSync } from 'child_process';
18
18
  import { VERSION, installSkill } from './config-wizard.js';
19
- import { addPermissionHook, registerActiveProject, unregisterActiveProject, updateWechatModeConfig } from './project-config.js';
19
+ import { addPermissionHook, registerActiveProject, unregisterActiveProject, updateWechatModeConfig, loadWechatModeConfig } from './project-config.js';
20
20
  import { logger } from './logger.js';
21
21
  /**
22
22
  * 沿进程树向上查找 Claude Code TUI 的 PID。
@@ -89,18 +89,20 @@ async function sendWecomMediaFromFile(args) {
89
89
  }
90
90
  const filename = args.filename || path.basename(abs);
91
91
  const buf = fs.readFileSync(abs);
92
+ // v3.3.1: 所有可能包含 CJK 的 header 值必须 encodeURIComponent —— HTTP header 值受 ISO-8859-1 限制,
93
+ // node fetch 见到 char > 255 直接抛 ByteString TypeError。daemon 端 getHeaderStr 会 decodeURIComponent。
92
94
  const headers = {
93
95
  'Content-Type': 'application/octet-stream',
94
96
  'Content-Length': String(buf.length),
95
- 'X-Target-User': args.target_user,
97
+ 'X-Target-User': encodeURIComponent(args.target_user),
96
98
  'X-Media-Type': args.media_type,
97
99
  'X-Filename': encodeURIComponent(filename),
98
- 'X-Cc-Id': args.cc_id, // v3.2.5: daemon 用 ccId 查 registry 找到正确的 robot(群聊必须用 CC 自己的机器人)
100
+ 'X-Cc-Id': encodeURIComponent(args.cc_id),
99
101
  };
100
102
  if (MCP_AUTH_TOKEN)
101
103
  headers['Authorization'] = `Bearer ${MCP_AUTH_TOKEN}`;
102
104
  if (args.robot_name)
103
- headers['X-Robot'] = args.robot_name;
105
+ headers['X-Robot'] = encodeURIComponent(args.robot_name);
104
106
  if (args.video_title)
105
107
  headers['X-Video-Title'] = encodeURIComponent(args.video_title);
106
108
  if (args.video_description)
@@ -146,14 +148,15 @@ async function uploadFileToHttp(args) {
146
148
  headers['Authorization'] = `Bearer ${MCP_AUTH_TOKEN}`;
147
149
  if (args.ttl_seconds)
148
150
  headers['X-TTL'] = String(args.ttl_seconds);
151
+ // v3.3.1: 同上,CJK ccId / tags 必须 URL 编码
149
152
  if (args.kind === 'document') {
150
- headers['X-From-CC'] = args.cc_id;
151
- headers['X-To-CC'] = args.to_cc || '';
153
+ headers['X-From-CC'] = encodeURIComponent(args.cc_id);
154
+ headers['X-To-CC'] = encodeURIComponent(args.to_cc || '');
152
155
  }
153
156
  else {
154
- headers['X-Owner-CC'] = args.cc_id;
157
+ headers['X-Owner-CC'] = encodeURIComponent(args.cc_id);
155
158
  if (args.tags && args.tags.length > 0)
156
- headers['X-Tags'] = args.tags.join(',');
159
+ headers['X-Tags'] = encodeURIComponent(args.tags.join(','));
157
160
  }
158
161
  try {
159
162
  const res = await fetch(`${MCP_URL}${endpoint}`, { method: 'POST', headers, body: buf });
@@ -844,12 +847,24 @@ function registerChannelTools(server) {
844
847
  .describe('运行模式:channel=SSE推送(推荐),http=轮询(兼容)'),
845
848
  auto_approve_timeout: z.number().optional().default(600).describe('超时自动决策等待时间(秒,默认 600 即 10 分钟)'),
846
849
  }, async ({ agent_name, cc_id, robot_id, project_dir, mode, auto_approve_timeout }) => {
850
+ // v3.3.2: 远端 daemon 看不到本地 .claude/wecom-aibot.json,无法走 existingConfig 复用 ccId 的路径。
851
+ // 这里在 channel-server 本地读保存的 ccId,没有传入 cc_id 时自动塞进去 —— 避免每次 enter
852
+ // 都因 stale registry entry 撞冲突,生成 商务机器人-2 / -3 之类的奇怪 ccId。
853
+ const effectiveProjectDir = project_dir || process.cwd();
854
+ let effectiveCcId = cc_id;
855
+ if (!effectiveCcId) {
856
+ const saved = loadWechatModeConfig(effectiveProjectDir);
857
+ if (saved?.ccId) {
858
+ effectiveCcId = saved.ccId;
859
+ logger.info('reuse saved ccId from local wecom-aibot.json', { projectDir: effectiveProjectDir, ccId: saved.ccId });
860
+ }
861
+ }
847
862
  // 转发请求
848
863
  const result = await forwardToHttpMcp('enter_headless_mode', {
849
864
  agent_name,
850
- cc_id,
865
+ cc_id: effectiveCcId,
851
866
  robot_id,
852
- project_dir: project_dir || process.cwd(),
867
+ project_dir: effectiveProjectDir,
853
868
  mode,
854
869
  auto_approve_timeout,
855
870
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vrs-soft/wecom-aibot-mcp",
3
- "version": "3.3.0",
3
+ "version": "3.3.2",
4
4
  "description": "企业微信智能机器人 MCP 客户端 - 连接 wecom-aibot-server daemon",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",