@wu529778790/open-im 1.10.9-beta.2 → 1.10.9-beta.21

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 (56) hide show
  1. package/README.md +43 -62
  2. package/README.zh-CN.md +43 -62
  3. package/dist/adapters/claude-sdk-adapter.d.ts +13 -0
  4. package/dist/adapters/claude-sdk-adapter.js +221 -23
  5. package/dist/adapters/registry.js +3 -0
  6. package/dist/channels/capabilities.js +5 -0
  7. package/dist/clawbot/client.d.ts +14 -0
  8. package/dist/clawbot/client.js +299 -0
  9. package/dist/clawbot/event-handler.d.ts +12 -0
  10. package/dist/clawbot/event-handler.js +85 -0
  11. package/dist/clawbot/message-sender.d.ts +18 -0
  12. package/dist/clawbot/message-sender.js +109 -0
  13. package/dist/clawbot/qr-login.d.ts +33 -0
  14. package/dist/clawbot/qr-login.js +120 -0
  15. package/dist/clawbot/types.d.ts +111 -0
  16. package/dist/clawbot/types.js +7 -0
  17. package/dist/codebuddy/cli-runner.js +31 -2
  18. package/dist/codex/cli-runner.js +28 -2
  19. package/dist/config/file-io.d.ts +6 -3
  20. package/dist/config/file-io.js +12 -7
  21. package/dist/config/types.d.ts +17 -1
  22. package/dist/config-web-page-i18n.d.ts +24 -2
  23. package/dist/config-web-page-i18n.js +24 -2
  24. package/dist/config-web.js +79 -0
  25. package/dist/config.d.ts +1 -1
  26. package/dist/config.js +38 -2
  27. package/dist/constants.d.ts +6 -0
  28. package/dist/constants.js +6 -0
  29. package/dist/dingtalk/client.js +2 -1
  30. package/dist/dingtalk/event-handler.js +1 -1
  31. package/dist/index.js +50 -0
  32. package/dist/qq/client.js +7 -1
  33. package/dist/queue/request-queue.js +11 -10
  34. package/dist/setup.js +131 -3
  35. package/dist/shared/active-chats.d.ts +2 -2
  36. package/dist/shared/ai-task.d.ts +14 -0
  37. package/dist/shared/ai-task.js +57 -9
  38. package/dist/shared/process-kill.d.ts +24 -0
  39. package/dist/shared/process-kill.js +79 -0
  40. package/dist/shared/reconnect.d.ts +28 -0
  41. package/dist/shared/reconnect.js +56 -0
  42. package/dist/shared/task-cleanup.d.ts +16 -0
  43. package/dist/shared/task-cleanup.js +34 -1
  44. package/dist/telegram/client.js +7 -1
  45. package/dist/telemetry/telemetry-upload.js +1 -1
  46. package/dist/wework/client.js +17 -5
  47. package/dist/wework/event-handler.js +3 -0
  48. package/dist/workbuddy/centrifuge-client.d.ts +4 -0
  49. package/dist/workbuddy/centrifuge-client.js +76 -28
  50. package/dist/workbuddy/client.js +39 -2
  51. package/package.json +1 -1
  52. package/web/dist/assets/index-BaLTMeeF.js +57 -0
  53. package/web/dist/index.html +1 -1
  54. package/dist/config/credentials.d.ts +0 -19
  55. package/dist/config/credentials.js +0 -36
  56. package/web/dist/assets/index-B-oVSMUp.js +0 -57
@@ -9,6 +9,7 @@ import { existsSync, mkdirSync } from 'node:fs';
9
9
  import { join } from 'node:path';
10
10
  import { hostname, homedir } from 'node:os';
11
11
  import { createLogger } from '../logger.js';
12
+ import { jitteredDelay, SLOW_PROBE_MS, isFatalReconnectError } from '../shared/reconnect.js';
12
13
  import { WorkBuddyOAuth } from './oauth.js';
13
14
  import { WorkBuddyCentrifugeClient } from './centrifuge-client.js';
14
15
  const log = createLogger('WorkBuddy');
@@ -23,8 +24,11 @@ let stateChangeHandler = null;
23
24
  let heartbeatTimer = null;
24
25
  let reconnectTimer = null;
25
26
  let reconnectAttempt = 0;
27
+ let fatalSlowProbe = false;
26
28
  let stopped = false;
27
29
  let platformConfig = null;
30
+ /** 单飞刷新 token 的在途 Promise,避免并发 401 重复刷新 */
31
+ let refreshInFlight = null;
28
32
  export function getChannelState() {
29
33
  return channelState;
30
34
  }
@@ -78,6 +82,10 @@ async function connect() {
78
82
  }
79
83
  catch (err) {
80
84
  log.error('Host workspace registration failed:', err);
85
+ if (isFatalReconnectError(err)) {
86
+ fatalSlowProbe = true;
87
+ log.warn('WorkBuddy 致命错误(鉴权失败),转慢探测(token 可能已过期):', err);
88
+ }
81
89
  scheduleReconnect();
82
90
  return;
83
91
  }
@@ -120,6 +128,8 @@ async function connect() {
120
128
  userId: pc.userId ?? '',
121
129
  httpBaseUrl: baseUrl,
122
130
  httpAccessToken: pc.accessToken ?? '',
131
+ getAccessToken: () => oauthClient?.accessToken ?? pc.accessToken ?? '',
132
+ refreshToken: refreshWorkBuddyToken,
123
133
  workspaceSessionId,
124
134
  registerChannelFn,
125
135
  releaseChannelLockFn,
@@ -128,6 +138,7 @@ async function connect() {
128
138
  log.info('WorkBuddy Centrifuge connected');
129
139
  log.info(`WeChat KF sessionId: ${workspaceSessionId}`);
130
140
  reconnectAttempt = 0;
141
+ fatalSlowProbe = false;
131
142
  updateState('connected');
132
143
  // Step 2: Register Claw workspace to get WeChat KF routing channel + sessionId
133
144
  oauth.registerWorkspace({
@@ -234,9 +245,10 @@ function scheduleReconnect() {
234
245
  clearTimeout(reconnectTimer);
235
246
  reconnectTimer = null;
236
247
  }
237
- const delay = RECONNECT_DELAYS_MS[Math.min(reconnectAttempt, RECONNECT_DELAYS_MS.length - 1)];
248
+ const baseDelay = RECONNECT_DELAYS_MS[Math.min(reconnectAttempt, RECONNECT_DELAYS_MS.length - 1)];
249
+ const delay = fatalSlowProbe ? jitteredDelay(SLOW_PROBE_MS) : jitteredDelay(baseDelay);
238
250
  reconnectAttempt++;
239
- log.info(`Reconnecting in ${delay}ms (attempt ${reconnectAttempt})...`);
251
+ log.info(`Reconnecting in ${delay}ms (attempt ${reconnectAttempt})${fatalSlowProbe ? ' [slow-probe]' : ''}...`);
240
252
  reconnectTimer = setTimeout(async () => {
241
253
  reconnectTimer = null;
242
254
  if (stopped)
@@ -261,6 +273,31 @@ export function getCentrifugeClient() {
261
273
  export function getOAuth() {
262
274
  return oauthClient;
263
275
  }
276
+ /**
277
+ * 单飞刷新 WorkBuddy access token:并发 401 只触发一次刷新,复用同一 Promise。
278
+ * 刷新成功后 oauthClient.accessToken 原地更新,所有 HTTP 调用(含心跳)自动用新 token。
279
+ */
280
+ async function refreshWorkBuddyToken() {
281
+ if (!oauthClient)
282
+ return;
283
+ if (refreshInFlight)
284
+ return refreshInFlight;
285
+ refreshInFlight = (async () => {
286
+ try {
287
+ log.info('Refreshing WorkBuddy access token...');
288
+ await oauthClient.refreshTokenAuth();
289
+ log.info('WorkBuddy access token refreshed');
290
+ }
291
+ catch (err) {
292
+ log.error('WorkBuddy token refresh failed:', err);
293
+ throw err;
294
+ }
295
+ finally {
296
+ refreshInFlight = null;
297
+ }
298
+ })();
299
+ return refreshInFlight;
300
+ }
264
301
  export function stopWorkBuddy() {
265
302
  log.info('Stopping WorkBuddy client...');
266
303
  stopped = true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wu529778790/open-im",
3
- "version": "1.10.9-beta.2",
3
+ "version": "1.10.9-beta.21",
4
4
  "description": "Multi-platform IM bridge for AI CLI tools (Claude, Codex, CodeBuddy)",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",