@wu529778790/open-im 1.8.3-beta.3 → 1.8.3-beta.5

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
@@ -424,24 +424,64 @@ 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(QClaw/AGP 协议)",
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
+ console.log("\n✅ WorkBuddy 登录成功,配置已保存");
477
+ }
478
+ catch (err) {
479
+ console.error("\n❌ WorkBuddy 登录失败:", err instanceof Error ? err.message : String(err));
480
+ if (platform === "wechat")
481
+ return false;
482
+ }
483
+ }
484
+ else if (wechatModeResp.mode === "qr") {
445
485
  console.log("\n正在启动微信扫码登录...\n");
446
486
  try {
447
487
  const { performWeChatLogin } = await import("./wechat/auth/index.js");
@@ -468,7 +508,7 @@ export async function runInteractiveSetup() {
468
508
  return false;
469
509
  }
470
510
  }
471
- else if (hasToken) {
511
+ else if (hasToken || hasWbCreds) {
472
512
  config.platforms.wechat = {
473
513
  ...wc,
474
514
  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.3",
3
+ "version": "1.8.3-beta.5",
4
4
  "description": "Multi-platform IM bridge for AI CLI tools (Claude, Codex, CodeBuddy)",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",