@wu529778790/open-im 1.8.3-beta.4 → 1.8.3-beta.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/setup.js CHANGED
@@ -308,7 +308,7 @@ export async function runInteractiveSetup() {
308
308
  value: "dingtalk",
309
309
  },
310
310
  {
311
- title: "微信 (WeChat) - 扫码登录获取 token(QClaw/AGP 协议,测试中)" +
311
+ title: "微信 (WeChat)" +
312
312
  (hasWc ? " ✓已配置" : ""),
313
313
  value: "wechat",
314
314
  },
@@ -424,24 +424,84 @@ export async function runInteractiveSetup() {
424
424
  if (selectedPlatforms.includes("wechat")) {
425
425
  const wc = existing?.platforms?.wechat;
426
426
  const hasToken = !!(wc?.token && wc?.guid && wc?.userId);
427
+ const hasWbCreds = !!(wc?.workbuddyAccessToken && wc?.workbuddyRefreshToken);
427
428
  const wechatModeResp = await prompts({
428
429
  type: "select",
429
430
  name: "mode",
430
431
  message: "微信登录方式",
431
432
  choices: [
432
433
  {
433
- title: "扫码登录(推荐)- 用微信扫描二维码,自动获取 token",
434
+ title: "WorkBuddy OAuth - 在浏览器中完成 CodeBuddy 登录(推荐)",
435
+ value: "workbuddy",
436
+ },
437
+ {
438
+ title: "扫码登录 - 用微信扫描二维码获取 token",
434
439
  value: "qr",
435
440
  },
436
441
  {
437
- title: "使用已有配置" + (hasToken ? " ✓" : "(需已通过扫码登录获取)"),
442
+ title: "使用已有配置" + (hasToken || hasWbCreds ? " ✓" : "(需已配置)"),
438
443
  value: "keep",
439
- disabled: !hasToken,
444
+ disabled: !hasToken && !hasWbCreds,
440
445
  },
441
446
  ],
442
- initial: hasToken ? 1 : 0,
447
+ initial: hasWbCreds ? 0 : (hasToken ? 1 : 0),
443
448
  }, { onCancel });
444
- if (wechatModeResp.mode === "qr") {
449
+ if (wechatModeResp.mode === "workbuddy") {
450
+ console.log("\n正在启动 WorkBuddy OAuth 登录...\n");
451
+ try {
452
+ const { WorkBuddyOAuth } = await import("./workbuddy/oauth.js");
453
+ const oauth = new WorkBuddyOAuth();
454
+ console.log("步骤 1/3: 获取登录链接...");
455
+ const { authUrl, state } = await oauth.fetchAuthState();
456
+ console.log("\n请在浏览器中打开以下链接完成登录:");
457
+ console.log(authUrl);
458
+ console.log("\n等待登录完成(最长 5 分钟)...\n");
459
+ const tokenResult = await oauth.pollToken(state);
460
+ console.log("✅ 登录成功! 正在获取账号信息...");
461
+ let accountInfo = {};
462
+ try {
463
+ accountInfo = await oauth.getAccount(state);
464
+ }
465
+ catch {
466
+ // account info is optional
467
+ }
468
+ const userId = accountInfo?.uid?.toString() ?? "";
469
+ config.platforms.wechat = {
470
+ loginMode: 'workbuddy',
471
+ enabled: true,
472
+ workbuddyAccessToken: tokenResult.accessToken,
473
+ workbuddyRefreshToken: tokenResult.refreshToken,
474
+ userId,
475
+ };
476
+ // Step 3: WeChat KF binding
477
+ console.log("\n正在获取微信客服绑定链接...");
478
+ const sessionId = oauth.buildSessionId();
479
+ const linkResult = await oauth.getWeChatKfLink(sessionId);
480
+ if (linkResult.success && linkResult.url) {
481
+ console.log("\n━━━ 微信客服绑定 ━━━");
482
+ console.log("请复制以下链接,在微信中发给「文件传输助手」并点击打开:");
483
+ console.log(linkResult.url);
484
+ console.log("\n等待绑定完成(最长 5 分钟)...\n");
485
+ const bindResult = await oauth.pollBindStatus(sessionId);
486
+ if (bindResult.bound) {
487
+ console.log(`✅ 微信客服绑定成功!${bindResult.nickname ? ` 用户: ${bindResult.nickname}` : ""}`);
488
+ }
489
+ else {
490
+ console.log("⚠️ 绑定超时,你可以稍后重新运行 open-im init 完成绑定");
491
+ }
492
+ }
493
+ else {
494
+ console.log("⚠️ 获取微信客服链接失败,你可以稍后重新运行 open-im init 完成绑定");
495
+ }
496
+ console.log("\n✅ WorkBuddy 登录成功,配置已保存");
497
+ }
498
+ catch (err) {
499
+ console.error("\n❌ WorkBuddy 登录失败:", err instanceof Error ? err.message : String(err));
500
+ if (platform === "wechat")
501
+ return false;
502
+ }
503
+ }
504
+ else if (wechatModeResp.mode === "qr") {
445
505
  console.log("\n正在启动微信扫码登录...\n");
446
506
  try {
447
507
  const { performWeChatLogin } = await import("./wechat/auth/index.js");
@@ -468,7 +528,7 @@ export async function runInteractiveSetup() {
468
528
  return false;
469
529
  }
470
530
  }
471
- else if (hasToken) {
531
+ else if (hasToken || hasWbCreds) {
472
532
  config.platforms.wechat = {
473
533
  ...wc,
474
534
  enabled: true,
@@ -5,6 +5,9 @@
5
5
  * 订阅频道接收消息,通过 HTTP POST 发送回复。
6
6
  */
7
7
  import { randomUUID } from 'node:crypto';
8
+ import { hostname } from 'node:os';
9
+ import { homedir } from 'node:os';
10
+ import { join } from 'node:path';
8
11
  import { createLogger } from '../logger.js';
9
12
  import { WorkBuddyCentrifugeClient } from '../workbuddy/centrifuge-client.js';
10
13
  import { WorkBuddyOAuth } from '../workbuddy/oauth.js';
@@ -29,13 +32,18 @@ export class WorkBuddyTransport {
29
32
  this.oauth.userId = this.config.userId;
30
33
  // Register workspace to get Centrifuge tokens
31
34
  log.info('Registering workspace for Centrifuge tokens...');
35
+ const hostId = this.config.hostId ?? hostname();
36
+ const workspaceId = randomUUID();
32
37
  const tokens = await this.oauth.registerWorkspace({
33
38
  userId: this.config.userId,
34
- hostId: this.config.hostId ?? randomUUID(),
35
- workspaceId: randomUUID(),
39
+ hostId,
40
+ workspaceId,
36
41
  workspaceName: 'open-im-wechat',
37
42
  });
38
43
  log.info(`Workspace registered: channel=${tokens.channel}`);
44
+ // Build workspaceSessionId for HTTP COPILOT_RESPONSE metadata
45
+ const workspacePath = this.config.workspacePath ?? join(homedir(), 'WorkBuddy', 'Claw');
46
+ const workspaceSessionId = `${this.config.userId}_${hostId}_${workspacePath}`;
39
47
  // Create Centrifuge client
40
48
  const clientConfig = {
41
49
  url: tokens.url,
@@ -46,6 +54,7 @@ export class WorkBuddyTransport {
46
54
  userId: this.config.userId,
47
55
  httpBaseUrl: this.config.baseUrl ?? 'https://copilot.tencent.com',
48
56
  httpAccessToken: this.config.accessToken,
57
+ workspaceSessionId,
49
58
  };
50
59
  const callbacks = {
51
60
  onConnected: () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wu529778790/open-im",
3
- "version": "1.8.3-beta.4",
3
+ "version": "1.8.3-beta.6",
4
4
  "description": "Multi-platform IM bridge for AI CLI tools (Claude, Codex, CodeBuddy)",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",