maka-agent 0.2.0-dev.22.20260905 → 0.2.0-dev.24.20260907

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 (194) hide show
  1. package/dist/acp/maka-acp-agent.js +2 -1
  2. package/dist/acp/session-configuration.js +143 -0
  3. package/dist/acp/session-registry.js +90 -4
  4. package/dist/cli-core.js +2 -0
  5. package/dist/pi-transcript.js +5 -12
  6. package/dist/pi-tui-runner.js +74 -4
  7. package/dist/runtime-host-cli-context.js +167 -78
  8. package/dist/runtime-host-cli-installation.js +8 -2
  9. package/dist/runtime-host-cli.js +31 -1
  10. package/dist/runtime-host-handoff-surface.js +81 -0
  11. package/dist/runtime-host-installed-update-bootstrap.js +13 -0
  12. package/dist/runtime-host-installed-update-coordinator.js +33 -0
  13. package/dist/runtime-host-lifecycle-transaction.js +9 -1
  14. package/dist/runtime-host-local-handoff.js +37 -4
  15. package/dist/runtime-host-local-managed-activation.js +84 -0
  16. package/dist/runtime-host-local-source-retirement.js +18 -2
  17. package/dist/runtime-host-managed-lifecycle-manager.js +1 -0
  18. package/dist/runtime-host-operator-retirement.js +50 -0
  19. package/dist/runtime-host-service-manager.js +3 -0
  20. package/dist/runtime-host-session-driver.js +4 -25
  21. package/dist/runtime-host-session-update.js +62 -0
  22. package/dist/runtime-host-tui-command.js +38 -73
  23. package/dist/runtime-host-tui-context.js +1 -0
  24. package/dist/runtime-host-tui-owner.js +226 -0
  25. package/dist/tui-copy-catalog.js +140 -3
  26. package/dist/tui-host-owner-copy.js +24 -0
  27. package/native/runtime-host-peer/prebuilds/darwin-arm64/maka_runtime_host_peer.node +0 -0
  28. package/native/runtime-host-peer/prebuilds/linux-arm64/maka_runtime_host_peer.node +0 -0
  29. package/native/runtime-host-peer/prebuilds/linux-x64/maka_runtime_host_peer.node +0 -0
  30. package/native/runtime-host-peer/prebuilds/win32-x64/maka_runtime_host_peer.node +0 -0
  31. package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
  32. package/node_modules/@maka/core/dist/bot-events.js +18 -63
  33. package/node_modules/@maka/core/dist/canonical-runtime-event.js +3 -1
  34. package/node_modules/@maka/core/dist/model-call-attempt.js +0 -82
  35. package/node_modules/@maka/core/dist/model-call-usage-projection.js +0 -186
  36. package/node_modules/@maka/core/dist/model-failure.js +40 -0
  37. package/node_modules/@maka/core/dist/model-metadata.generated.js +4 -4
  38. package/node_modules/@maka/core/dist/model-metadata.js +3 -3
  39. package/node_modules/@maka/core/dist/model-web-search.js +5 -4
  40. package/node_modules/@maka/core/dist/provider-registry.js +45 -4
  41. package/node_modules/@maka/core/dist/record-schema.js +22 -2
  42. package/node_modules/@maka/core/dist/redaction.js +41 -58
  43. package/node_modules/@maka/core/dist/runtime-boundary.js +31 -11
  44. package/node_modules/@maka/core/dist/runtime-event.js +37 -6
  45. package/node_modules/@maka/core/dist/runtime-handoff.js +98 -0
  46. package/node_modules/@maka/core/dist/runtime-invocation.js +1 -1
  47. package/node_modules/@maka/core/dist/runtime-logical-execution.js +112 -0
  48. package/node_modules/@maka/core/dist/session-trace.js +5 -1
  49. package/node_modules/@maka/core/dist/session.js +54 -52
  50. package/node_modules/@maka/core/dist/slash-command-catalog.js +2 -0
  51. package/node_modules/@maka/core/dist/tool-result-archive-evidence.js +20 -0
  52. package/node_modules/@maka/core/dist/usage-ledger-merge.js +7 -9
  53. package/node_modules/@maka/core/dist/usage-record-schema.js +26 -35
  54. package/node_modules/@maka/core/dist/workhub-creation-intent.js +34 -20
  55. package/node_modules/@maka/core/package.json +4 -0
  56. package/node_modules/@maka/eval/harbor/egress-proxy/entrypoint.sh +2 -1
  57. package/node_modules/@maka/mcp/dist/index.js +131 -1
  58. package/node_modules/@maka/runtime/dist/agent-run.js +272 -105
  59. package/node_modules/@maka/runtime/dist/ai-sdk-backend.js +13 -5
  60. package/node_modules/@maka/runtime/dist/ai-sdk-compaction.js +109 -34
  61. package/node_modules/@maka/runtime/dist/ai-sdk-turn.js +155 -134
  62. package/node_modules/@maka/runtime/dist/bots/base-adapter.js +17 -0
  63. package/node_modules/@maka/runtime/dist/bots/bot-test.js +38 -22
  64. package/node_modules/@maka/runtime/dist/bots/dingtalk-bridge.js +7 -5
  65. package/node_modules/@maka/runtime/dist/bots/discord-bridge.js +4 -4
  66. package/node_modules/@maka/runtime/dist/bots/feishu-bridge.js +4 -5
  67. package/node_modules/@maka/runtime/dist/bots/qq-bridge.js +6 -4
  68. package/node_modules/@maka/runtime/dist/bots/slack-bridge.js +3 -4
  69. package/node_modules/@maka/runtime/dist/bots/telegram-bridge.js +4 -5
  70. package/node_modules/@maka/runtime/dist/bots/wechat-bridge.js +17 -19
  71. package/node_modules/@maka/runtime/dist/bots/wecom-bridge.js +5 -6
  72. package/node_modules/@maka/runtime/dist/bots/ws-bridge-base.js +2 -3
  73. package/node_modules/@maka/runtime/dist/context-budget.js +14 -9
  74. package/node_modules/@maka/runtime/dist/conversation-copy.js +5 -4
  75. package/node_modules/@maka/runtime/dist/goal-continuation.js +36 -4
  76. package/node_modules/@maka/runtime/dist/history-compact-checkpoint.js +18 -9
  77. package/node_modules/@maka/runtime/dist/history-compact-summarizer.js +30 -22
  78. package/node_modules/@maka/runtime/dist/history-compaction.js +29 -4
  79. package/node_modules/@maka/runtime/dist/ledger-tool-result-archive-reader.js +106 -0
  80. package/node_modules/@maka/runtime/dist/message-authority.js +9 -0
  81. package/node_modules/@maka/runtime/dist/model-adapter.js +19 -98
  82. package/node_modules/@maka/runtime/dist/model-factory.js +19 -81
  83. package/node_modules/@maka/runtime/dist/model-fetcher.js +7 -0
  84. package/node_modules/@maka/runtime/dist/model-runtime.js +85 -111
  85. package/node_modules/@maka/runtime/dist/native-web-search-tool.js +2 -1
  86. package/node_modules/@maka/runtime/dist/openai-codex-history-compactor.js +2 -2
  87. package/node_modules/@maka/runtime/dist/opencode-session-header.js +4 -2
  88. package/node_modules/@maka/runtime/dist/provider-error-classification.js +84 -123
  89. package/node_modules/@maka/runtime/dist/provider-request-telemetry.js +68 -108
  90. package/node_modules/@maka/runtime/dist/run-handoff-gate.js +97 -0
  91. package/node_modules/@maka/runtime/dist/runtime-event-backfill.js +82 -54
  92. package/node_modules/@maka/runtime/dist/runtime-event-read-model.js +117 -159
  93. package/node_modules/@maka/runtime/dist/runtime-kernel.js +150 -112
  94. package/node_modules/@maka/runtime/dist/runtime-ledger-repair.js +160 -79
  95. package/node_modules/@maka/runtime/dist/runtime-read-model.js +30 -89
  96. package/node_modules/@maka/runtime/dist/runtime-resume.js +80 -4
  97. package/node_modules/@maka/runtime/dist/session-event-runtime-mapper.js +5 -0
  98. package/node_modules/@maka/runtime/dist/session-manager.js +171 -288
  99. package/node_modules/@maka/runtime/dist/session-projection-helpers.js +0 -27
  100. package/node_modules/@maka/runtime/dist/session-trace-projection.js +3 -30
  101. package/node_modules/@maka/runtime/dist/subscription-model-fetch.js +3 -4
  102. package/node_modules/@maka/runtime/dist/test-connection.js +16 -16
  103. package/node_modules/@maka/runtime/dist/tool-result-archive-encoding.js +38 -0
  104. package/node_modules/@maka/runtime/dist/tool-runtime.js +3 -61
  105. package/node_modules/@maka/runtime/package.json +1 -0
  106. package/node_modules/@maka/runtime-host/dist/adapter/session-projector.js +35 -0
  107. package/node_modules/@maka/runtime-host/dist/candidate-entry.js +4 -1
  108. package/node_modules/@maka/runtime-host/dist/client/connect-or-spawn.js +9 -1
  109. package/node_modules/@maka/runtime-host/dist/client/connection.js +3 -0
  110. package/node_modules/@maka/runtime-host/dist/client/host-handoff-copy.js +156 -0
  111. package/node_modules/@maka/runtime-host/dist/client/host-handoff.js +273 -0
  112. package/node_modules/@maka/runtime-host/dist/client/host-retirement.js +26 -5
  113. package/node_modules/@maka/runtime-host/dist/client/index.js +3 -1
  114. package/node_modules/@maka/runtime-host/dist/client/launcher.js +3 -0
  115. package/node_modules/@maka/runtime-host/dist/client/peer-client.js +13 -0
  116. package/node_modules/@maka/runtime-host/dist/client/registered-host-termination.js +0 -59
  117. package/node_modules/@maka/runtime-host/dist/client/remote-compatibility-error.js +2 -0
  118. package/node_modules/@maka/runtime-host/dist/client/session-subscription.js +27 -5
  119. package/node_modules/@maka/runtime-host/dist/operator/index.js +2 -1
  120. package/node_modules/@maka/runtime-host/dist/operator/retirement-cancellation.js +20 -0
  121. package/node_modules/@maka/runtime-host/dist/peer-mesh/node.js +28 -16
  122. package/node_modules/@maka/runtime-host/dist/protocol/external-session.js +4 -0
  123. package/node_modules/@maka/runtime-host/dist/protocol/host-status.js +29 -12
  124. package/node_modules/@maka/runtime-host/dist/protocol/index.js +37 -1
  125. package/node_modules/@maka/runtime-host/dist/protocol/operations.js +2 -0
  126. package/node_modules/@maka/runtime-host/dist/protocol/session-collaboration.js +28 -1
  127. package/node_modules/@maka/runtime-host/dist/protocol/session-continuity.js +40 -20
  128. package/node_modules/@maka/runtime-host/dist/protocol/session-transcript.js +0 -5
  129. package/node_modules/@maka/runtime-host/dist/protocol/session-turns.js +29 -58
  130. package/node_modules/@maka/runtime-host/dist/protocol/turn.js +11 -1
  131. package/node_modules/@maka/runtime-host/dist/protocol/workhub-coordination.js +33 -0
  132. package/node_modules/@maka/runtime-host/dist/server/access-authority.js +26 -1
  133. package/node_modules/@maka/runtime-host/dist/server/access-credential-store.js +6 -1
  134. package/node_modules/@maka/runtime-host/dist/server/canonical-turn-snapshot.js +19 -4
  135. package/node_modules/@maka/runtime-host/dist/server/canonical-usage-reader.js +24 -11
  136. package/node_modules/@maka/runtime-host/dist/server/connection-session.js +7 -6
  137. package/node_modules/@maka/runtime-host/dist/server/daily-review-coordinator.js +7 -4
  138. package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +168 -28
  139. package/node_modules/@maka/runtime-host/dist/server/execution-model-authority.js +5 -5
  140. package/node_modules/@maka/runtime-host/dist/server/execution-model-composition.js +3 -2
  141. package/node_modules/@maka/runtime-host/dist/server/external-session-coordinator.js +6 -3
  142. package/node_modules/@maka/runtime-host/dist/server/goal-coordinator.js +40 -1
  143. package/node_modules/@maka/runtime-host/dist/server/host-kernel.js +108 -23
  144. package/node_modules/@maka/runtime-host/dist/server/host-residency-registry.js +13 -7
  145. package/node_modules/@maka/runtime-host/dist/server/hosted-execution-admission-registry.js +3 -1
  146. package/node_modules/@maka/runtime-host/dist/server/hosted-execution-recovery.js +124 -62
  147. package/node_modules/@maka/runtime-host/dist/server/message-coordinator.js +85 -8
  148. package/node_modules/@maka/runtime-host/dist/server/root-admission-owner.js +7 -0
  149. package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +344 -71
  150. package/node_modules/@maka/runtime-host/dist/server/scheduled-task-coordinator.js +37 -2
  151. package/node_modules/@maka/runtime-host/dist/server/serial-outbound-writer.js +45 -3
  152. package/node_modules/@maka/runtime-host/dist/server/session-catalog-coordinator.js +201 -12
  153. package/node_modules/@maka/runtime-host/dist/server/session-continuity-coordinator.js +87 -25
  154. package/node_modules/@maka/runtime-host/dist/server/session-revision-coordinator.js +8 -55
  155. package/node_modules/@maka/runtime-host/dist/server/session-sidecar-purge.js +1 -16
  156. package/node_modules/@maka/runtime-host/dist/server/session-transcript-pager.js +0 -1
  157. package/node_modules/@maka/runtime-host/dist/server/session-transcript-reader.js +460 -70
  158. package/node_modules/@maka/runtime-host/dist/server/shared-session-transcript.js +1 -1
  159. package/node_modules/@maka/runtime-host/dist/server/storage-maintenance.js +109 -0
  160. package/node_modules/@maka/runtime-host/dist/server/usage-pricing-coordinator.js +4 -11
  161. package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-action-gate.js +44 -15
  162. package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-coordinator.js +6 -2
  163. package/node_modules/@maka/storage/dist/agent-run-store.js +44 -0
  164. package/node_modules/@maka/storage/dist/artifact-store.js +21 -10
  165. package/node_modules/@maka/storage/dist/artifact-stores.js +1 -1
  166. package/node_modules/@maka/storage/dist/claude-code-session-adapter.js +0 -4
  167. package/node_modules/@maka/storage/dist/codex-session-adapter.js +0 -2
  168. package/node_modules/@maka/storage/dist/context-offload-snapshot.js +325 -0
  169. package/node_modules/@maka/storage/dist/conversation-operational-state.js +4 -0
  170. package/node_modules/@maka/storage/dist/execution-stores.js +11 -7
  171. package/node_modules/@maka/storage/dist/file-session-repository.js +1012 -0
  172. package/node_modules/@maka/storage/dist/model-call-ledger.js +199 -32
  173. package/node_modules/@maka/storage/dist/model-call-usage-sql.js +136 -0
  174. package/node_modules/@maka/storage/dist/opencode-session-adapter.js +0 -4
  175. package/node_modules/@maka/storage/dist/operational-state-backup.js +9 -5
  176. package/node_modules/@maka/storage/dist/operational-state-store-public.js +1 -1
  177. package/node_modules/@maka/storage/dist/operational-state-store.js +5 -3
  178. package/node_modules/@maka/storage/dist/runtime-event-persistence.js +1 -0
  179. package/node_modules/@maka/storage/dist/runtime-transcript-query.js +308 -0
  180. package/node_modules/@maka/storage/dist/session-bundle-policy.js +24 -4
  181. package/node_modules/@maka/storage/dist/session-message-projection.js +15 -0
  182. package/node_modules/@maka/storage/dist/session-repository.js +767 -0
  183. package/node_modules/@maka/storage/dist/session-store.js +25 -99
  184. package/node_modules/@maka/storage/dist/sqlite-artifact-metadata.js +10 -3
  185. package/node_modules/@maka/storage/dist/sqlite-context-offload-store.js +24 -8
  186. package/node_modules/@maka/storage/dist/sqlite-core-execution-schema.js +17 -1
  187. package/node_modules/@maka/storage/dist/sqlite-runtime-schema.js +44 -1
  188. package/node_modules/@maka/storage/dist/sqlite-runtime-store.js +129 -25
  189. package/node_modules/@maka/storage/dist/sqlite-session-metadata-store.js +109 -892
  190. package/node_modules/@maka/storage/dist/sqlite-usage-schema.js +200 -20
  191. package/node_modules/@maka/storage/dist/tool-result-archive-evidence.js +111 -0
  192. package/node_modules/@maka/storage/dist/usage-stores.js +6 -2
  193. package/node_modules/@maka/storage/package.json +2 -0
  194. package/package.json +1 -1
@@ -16,9 +16,9 @@
16
16
  * specific language governing permissions and limitations
17
17
  * under the License.
18
18
  */
19
- import { generalizedErrorMessage } from '@maka/core/redaction';
20
19
  import { WebClient } from '@slack/web-api';
21
20
  import { proxiedFetch } from './proxied-fetch.js';
21
+ import { botDiagnosticMessage } from './base-adapter.js';
22
22
  import { normalizeWechatIlinkBaseUrl, testWechatBridge, testWechatIlinkCredentials, } from './wechat-bridge.js';
23
23
  const BOT_TEST_TIMEOUT_MS = 10_000;
24
24
  /**
@@ -31,6 +31,16 @@ export function feishuOpenApiHost(domain) {
31
31
  return domain?.trim() === 'larksuite.com' ? 'open.larksuite.com' : 'open.feishu.cn';
32
32
  }
33
33
  export async function testBotChannel(provider, channel) {
34
+ const result = await probeBotChannel(provider, channel);
35
+ if (result.ok)
36
+ return result;
37
+ const errorCode = result.errorCode ?? 'connection_failed';
38
+ const error = result.error ? botDiagnosticMessage(channel, result.error) : undefined;
39
+ if (error)
40
+ console.warn(`[bots:${provider}] ${errorCode}: ${error}`);
41
+ return { ...result, errorCode, ...(error ? { error } : {}) };
42
+ }
43
+ async function probeBotChannel(provider, channel) {
34
44
  if (provider !== 'feishu' &&
35
45
  provider !== 'wecom' &&
36
46
  provider !== 'wechat' &&
@@ -38,7 +48,7 @@ export async function testBotChannel(provider, channel) {
38
48
  provider !== 'qq' &&
39
49
  provider !== 'slack' &&
40
50
  !channel.token.trim()) {
41
- return { ok: false, error: 'Bot token is required' };
51
+ return { ok: false, errorCode: 'token_missing' };
42
52
  }
43
53
  switch (provider) {
44
54
  case 'telegram':
@@ -63,7 +73,7 @@ async function testSlack(channel) {
63
73
  const botToken = channel.token.trim();
64
74
  const appToken = channel.appSecret?.trim() ?? '';
65
75
  if (!botToken || !appToken) {
66
- return { ok: false, error: 'Slack 需要 Bot Token 与 App-Level Token' };
76
+ return { ok: false, errorCode: 'slack_tokens_missing' };
67
77
  }
68
78
  try {
69
79
  const identity = await new WebClient(botToken).auth.test();
@@ -80,15 +90,14 @@ async function testSlack(channel) {
80
90
  ...(identity.user ? { username: identity.user, displayName: identity.user } : {}),
81
91
  },
82
92
  capabilities: { auth: true, socketMode: true },
83
- hint: '凭据有效,Socket Mode 连接可用。',
84
93
  };
85
94
  }
86
95
  catch (error) {
87
- return { ok: false, error: generalizedErrorMessage(error) };
96
+ return { ok: false, error: error instanceof Error ? error.message : String(error) };
88
97
  }
89
98
  }
90
99
  async function testWechat(channel) {
91
- if (channel.token.trim() && normalizeWechatIlinkBaseUrl(channel.webhookUrl)) {
100
+ if (normalizeWechatIlinkBaseUrl(channel.webhookUrl)) {
92
101
  return testWechatIlinkCredentials(channel);
93
102
  }
94
103
  const appId = channel.appId?.trim() ?? '';
@@ -113,7 +122,6 @@ async function testWechat(channel) {
113
122
  ok: true,
114
123
  identity: { id: appId, username: appId, displayName: appId },
115
124
  capabilities: { auth: true },
116
- hint: '凭据有效;消息收发还需要公众号服务器配置和回调验证。',
117
125
  };
118
126
  }
119
127
  catch (error) {
@@ -123,9 +131,21 @@ async function testWechat(channel) {
123
131
  async function testTelegram(channel) {
124
132
  const base = `https://api.telegram.org/bot${channel.token}`;
125
133
  try {
126
- const me = await (await proxiedFetch(`${base}/getMe`, { method: 'GET', timeoutMs: BOT_TEST_TIMEOUT_MS })).json();
127
- if (!me.ok)
128
- return { ok: false, error: me.description ?? 'Invalid bot token' };
134
+ const response = await proxiedFetch(`${base}/getMe`, {
135
+ method: 'GET',
136
+ timeoutMs: BOT_TEST_TIMEOUT_MS,
137
+ });
138
+ const me = await response.json().catch(() => null);
139
+ if (!response.ok || me?.ok !== true)
140
+ return {
141
+ ok: false,
142
+ errorCode: response.status === 401 || (response.ok && me?.error_code === 401)
143
+ ? 'token_invalid'
144
+ : 'connection_failed',
145
+ error: typeof me?.description === 'string' && me.description.trim()
146
+ ? me.description
147
+ : `Telegram getMe failed (HTTP ${response.status})`,
148
+ };
129
149
  return {
130
150
  ok: true,
131
151
  identity: {
@@ -134,7 +154,6 @@ async function testTelegram(channel) {
134
154
  displayName: me.result.first_name,
135
155
  },
136
156
  messageSent: false,
137
- hint: '发送 /start 给机器人后可在运行态接收消息。',
138
157
  };
139
158
  }
140
159
  catch (error) {
@@ -184,14 +203,13 @@ async function testWeCom(channel) {
184
203
  const botId = channel.appId?.trim() ?? '';
185
204
  const secret = channel.appSecret?.trim() ?? '';
186
205
  if (!botId || !secret) {
187
- return { ok: false, error: '企业微信 AI 机器人需要 Bot ID 与 Secret', verified: false };
206
+ return { ok: false, errorCode: 'wecom_credentials_missing', verified: false };
188
207
  }
189
208
  return {
190
209
  ok: true,
191
210
  verified: false,
192
211
  identity: { id: botId, username: botId, displayName: botId },
193
212
  capabilities: { auth: false },
194
- hint: '已保存凭据;企业微信 AI 机器人的连接状态以运行态长连接为准。',
195
213
  };
196
214
  }
197
215
  /**
@@ -213,7 +231,7 @@ async function testDingTalk(channel) {
213
231
  const appkey = channel.appId?.trim() ?? '';
214
232
  const appsecret = channel.appSecret?.trim() ?? '';
215
233
  if (!appkey || !appsecret) {
216
- return { ok: false, error: '钉钉需要 appkey 与 appsecret' };
234
+ return { ok: false, errorCode: 'dingtalk_credentials_missing' };
217
235
  }
218
236
  const url = 'https://oapi.dingtalk.com/gettoken?appkey=' +
219
237
  encodeURIComponent(appkey) +
@@ -228,17 +246,16 @@ async function testDingTalk(channel) {
228
246
  if (json.errcode && json.errcode !== 0) {
229
247
  return {
230
248
  ok: false,
231
- error: json.errmsg ? `钉钉: ${json.errmsg}` : `钉钉 errcode ${json.errcode}`,
249
+ error: json.errmsg ? String(json.errmsg) : `errcode ${json.errcode}`,
232
250
  };
233
251
  }
234
252
  if (typeof json.access_token !== 'string' || json.access_token.length === 0) {
235
- return { ok: false, error: '钉钉凭据测试未返回 access_token' };
253
+ return { ok: false, errorCode: 'dingtalk_no_access_token' };
236
254
  }
237
255
  return {
238
256
  ok: true,
239
257
  identity: { id: appkey, username: appkey, displayName: appkey },
240
258
  capabilities: { auth: true },
241
- hint: '凭据有效;接收消息需要 outgoing 机器人或 Stream 模式配置。',
242
259
  };
243
260
  }
244
261
  catch (error) {
@@ -264,7 +281,7 @@ async function testQQ(channel) {
264
281
  const appId = channel.appId?.trim() ?? '';
265
282
  const clientSecret = channel.appSecret?.trim() ?? '';
266
283
  if (!appId || !clientSecret) {
267
- return { ok: false, error: 'QQ 官方机器人需要 App ID 与 Client Secret' };
284
+ return { ok: false, errorCode: 'qq_credentials_missing' };
268
285
  }
269
286
  try {
270
287
  const response = await proxiedFetch('https://bots.qq.com/app/getAppAccessToken', {
@@ -276,18 +293,17 @@ async function testQQ(channel) {
276
293
  const json = await response.json().catch(() => ({}));
277
294
  if (!response.ok) {
278
295
  const message = typeof json.message === 'string' && json.message.length > 0
279
- ? `QQ: ${json.message}`
296
+ ? json.message
280
297
  : `HTTP ${response.status}`;
281
298
  return { ok: false, error: message };
282
299
  }
283
300
  if (typeof json.access_token !== 'string' || json.access_token.length === 0) {
284
- return { ok: false, error: 'QQ 官方机器人凭据测试未返回 access_token' };
301
+ return { ok: false, errorCode: 'qq_no_access_token' };
285
302
  }
286
303
  return {
287
304
  ok: true,
288
305
  identity: { id: appId, username: appId, displayName: appId },
289
306
  capabilities: { auth: true },
290
- hint: '凭据有效;接收消息需要 QQ Gateway WebSocket 接入。',
291
307
  };
292
308
  }
293
309
  catch (error) {
@@ -298,7 +314,7 @@ async function testFeishu(channel) {
298
314
  const appId = channel.appId ?? '';
299
315
  const appSecret = channel.appSecret || channel.token;
300
316
  if (!appId || !appSecret)
301
- return { ok: false, error: 'Feishu appId and appSecret are required' };
317
+ return { ok: false, errorCode: 'feishu_credentials_missing' };
302
318
  // PR1197 review (P1-4): brand-switch the account host by the channel domain,
303
319
  // exactly like the onboarding flow does. A Lark tenant (larksuite.com) cannot
304
320
  // issue a tenant_access_token from the feishu.cn host, so a hardcoded host
@@ -163,7 +163,9 @@ export class DingTalkBotBridge extends WsBridgeBase {
163
163
  token = null;
164
164
  closeReasonPrefix = 'stream';
165
165
  checkCredentials() {
166
- return this.settings.appId?.trim() && this.settings.appSecret?.trim() ? null : 'no-credentials';
166
+ return this.settings.appId?.trim() && this.settings.appSecret?.trim()
167
+ ? null
168
+ : 'dingtalk_credentials_missing';
167
169
  }
168
170
  decideClose(code, explicitlyStopped) {
169
171
  const decision = decideDingTalkClose(code, explicitlyStopped);
@@ -221,7 +223,7 @@ export class DingTalkBotBridge extends WsBridgeBase {
221
223
  this.connect(`${json.endpoint}?ticket=${encodeURIComponent(json.ticket)}`);
222
224
  }
223
225
  catch (error) {
224
- this.reason = error instanceof Error ? error.message : String(error);
226
+ this.recordFailure(error);
225
227
  this.readiness = 'configured';
226
228
  this.emitStatusChange();
227
229
  this.scheduleReconnect();
@@ -295,7 +297,7 @@ export class DingTalkBotBridge extends WsBridgeBase {
295
297
  }
296
298
  if (classification.kind !== 'ok') {
297
299
  this.readiness = this.readiness === 'operational' ? 'degraded' : 'credentials_valid';
298
- this.reason = classification.kind === 'retry' ? 'rate-limited' : classification.description;
300
+ this.recordFailure(classification.kind === 'retry' ? 'rate-limited' : classification.description, classification.kind === 'retry' ? 'rate-limited' : 'send-failed');
299
301
  this.emitStatusChange();
300
302
  return null;
301
303
  }
@@ -340,7 +342,7 @@ export class DingTalkBotBridge extends WsBridgeBase {
340
342
  const response = await proxiedFetch(url, { method: 'GET', timeoutMs: 10_000 });
341
343
  const json = (await response.json().catch(() => null));
342
344
  if (!json || (json.errcode !== undefined && json.errcode !== 0)) {
343
- this.reason = json?.errmsg ?? 'gettoken failed';
345
+ this.recordFailure(json?.errmsg ?? 'gettoken failed', 'dingtalk_no_access_token');
344
346
  return null;
345
347
  }
346
348
  if (typeof json.access_token !== 'string')
@@ -353,7 +355,7 @@ export class DingTalkBotBridge extends WsBridgeBase {
353
355
  return this.token.value;
354
356
  }
355
357
  catch (error) {
356
- this.reason = error instanceof Error ? error.message : String(error);
358
+ this.recordFailure(error);
357
359
  return null;
358
360
  }
359
361
  }
@@ -153,7 +153,7 @@ function sleep(ms) {
153
153
  export class DiscordBotBridge extends GatewayBridgeBase {
154
154
  resumeGatewayUrl = null;
155
155
  checkCredentials() {
156
- return this.settings.token.trim() ? null : 'no-token';
156
+ return this.settings.token.trim() ? null : 'token_missing';
157
157
  }
158
158
  decideClose(code, explicitlyStopped) {
159
159
  return decideDiscordClose(code, explicitlyStopped);
@@ -176,7 +176,7 @@ export class DiscordBotBridge extends GatewayBridgeBase {
176
176
  const json = await response.json().catch(() => null);
177
177
  if (!response.ok || !json || typeof json.url !== 'string') {
178
178
  const message = json?.message;
179
- this.reason = typeof message === 'string' ? message : `gateway-bot-${response.status}`;
179
+ this.recordFailure(message, `gateway-bot-${response.status}`);
180
180
  this.readiness = 'configured';
181
181
  this.emitStatusChange();
182
182
  // Usually a transient outage — openConnection schedules the retry.
@@ -186,7 +186,7 @@ export class DiscordBotBridge extends GatewayBridgeBase {
186
186
  return `${gatewayUrl}/?v=${DISCORD_GATEWAY_VERSION}&encoding=json`;
187
187
  }
188
188
  catch (error) {
189
- this.reason = error instanceof Error ? error.message : String(error);
189
+ this.recordFailure(error);
190
190
  this.readiness = 'configured';
191
191
  this.emitStatusChange();
192
192
  return null;
@@ -257,7 +257,7 @@ export class DiscordBotBridge extends GatewayBridgeBase {
257
257
  }
258
258
  if (classification.kind !== 'ok') {
259
259
  this.readiness = this.readiness === 'operational' ? 'degraded' : 'credentials_valid';
260
- this.reason = classification.kind === 'retry' ? 'rate-limited' : classification.description;
260
+ this.recordFailure(classification.kind === 'retry' ? 'rate-limited' : classification.description, classification.kind === 'retry' ? 'rate-limited' : 'send-failed');
261
261
  this.emitStatusChange();
262
262
  return null;
263
263
  }
@@ -17,7 +17,6 @@
17
17
  * under the License.
18
18
  */
19
19
  import { Domain, LoggerLevel, createLarkChannel, } from '@larksuiteoapi/node-sdk';
20
- import { generalizedErrorMessage } from '@maka/core/redaction';
21
20
  import { BaseBotAdapter, botReadinessFromSettings } from './base-adapter.js';
22
21
  const HANDSHAKE_TIMEOUT_MS = 15_000;
23
22
  /**
@@ -76,7 +75,7 @@ export class FeishuBotBridge extends BaseBotAdapter {
76
75
  const appId = this.settings.appId?.trim() ?? '';
77
76
  const appSecret = this.settings.appSecret?.trim() || this.settings.token.trim();
78
77
  if (!appId || !appSecret) {
79
- this.reason = 'missing-feishu-credentials';
78
+ this.reason = 'feishu_credentials_missing';
80
79
  this.readiness = 'scaffolded';
81
80
  this.emitStatusChange();
82
81
  return;
@@ -110,7 +109,7 @@ export class FeishuBotBridge extends BaseBotAdapter {
110
109
  if (this.explicitlyStopped || this.channel !== channel)
111
110
  return;
112
111
  this.running = false;
113
- this.reason = generalizedErrorMessage(error);
112
+ this.recordFailure(error);
114
113
  this.readiness = 'configured';
115
114
  this.emitStatusChange();
116
115
  await this.disconnectChannel(channel);
@@ -142,7 +141,7 @@ export class FeishuBotBridge extends BaseBotAdapter {
142
141
  }
143
142
  catch (error) {
144
143
  this.readiness = this.readiness === 'operational' ? 'degraded' : 'credentials_valid';
145
- this.reason = generalizedErrorMessage(error);
144
+ this.recordFailure(error, 'send-failed');
146
145
  this.emitStatusChange();
147
146
  return null;
148
147
  }
@@ -179,7 +178,7 @@ export class FeishuBotBridge extends BaseBotAdapter {
179
178
  }), channel.on('error', (error) => {
180
179
  if (this.channel !== channel || this.explicitlyStopped)
181
180
  return;
182
- this.reason = generalizedErrorMessage(error);
181
+ this.recordFailure(error);
183
182
  this.readiness = this.readiness === 'operational' ? 'degraded' : 'configured';
184
183
  this.emitStatusChange();
185
184
  }), channel.on('reconnecting', () => {
@@ -199,7 +199,9 @@ function sleep(ms) {
199
199
  export class QQBotBridge extends GatewayBridgeBase {
200
200
  token = null;
201
201
  checkCredentials() {
202
- return this.settings.appId?.trim() && this.settings.appSecret?.trim() ? null : 'no-credentials';
202
+ return this.settings.appId?.trim() && this.settings.appSecret?.trim()
203
+ ? null
204
+ : 'qq_credentials_missing';
203
205
  }
204
206
  decideClose(code, explicitlyStopped) {
205
207
  return decideQQClose(code, explicitlyStopped);
@@ -227,7 +229,7 @@ export class QQBotBridge extends GatewayBridgeBase {
227
229
  return json.url;
228
230
  }
229
231
  catch (error) {
230
- this.reason = error instanceof Error ? error.message : String(error);
232
+ this.recordFailure(error);
231
233
  this.readiness = 'configured';
232
234
  this.emitStatusChange();
233
235
  return null;
@@ -311,7 +313,7 @@ export class QQBotBridge extends GatewayBridgeBase {
311
313
  }
312
314
  if (classification.kind !== 'ok') {
313
315
  this.readiness = this.readiness === 'operational' ? 'degraded' : 'credentials_valid';
314
- this.reason = classification.kind === 'retry' ? 'rate-limited' : classification.description;
316
+ this.recordFailure(classification.kind === 'retry' ? 'rate-limited' : classification.description, classification.kind === 'retry' ? 'rate-limited' : 'send-failed');
315
317
  this.emitStatusChange();
316
318
  return null;
317
319
  }
@@ -399,7 +401,7 @@ export class QQBotBridge extends GatewayBridgeBase {
399
401
  return this.token.value;
400
402
  }
401
403
  catch (error) {
402
- this.reason = error instanceof Error ? error.message : String(error);
404
+ this.recordFailure(error);
403
405
  return null;
404
406
  }
405
407
  }
@@ -16,7 +16,6 @@
16
16
  * specific language governing permissions and limitations
17
17
  * under the License.
18
18
  */
19
- import { generalizedErrorMessage } from '@maka/core/redaction';
20
19
  import { SocketModeClient } from '@slack/socket-mode';
21
20
  import { WebClient } from '@slack/web-api';
22
21
  import { BaseBotAdapter, botReadinessFromSettings } from './base-adapter.js';
@@ -54,7 +53,7 @@ export class SlackBotBridge extends BaseBotAdapter {
54
53
  if (!botToken || !appToken) {
55
54
  this.running = false;
56
55
  this.readiness = botReadinessFromSettings(this.settings);
57
- this.reason = 'missing-slack-tokens';
56
+ this.reason = 'slack_tokens_missing';
58
57
  this.emitStatusChange();
59
58
  return;
60
59
  }
@@ -106,7 +105,7 @@ export class SlackBotBridge extends BaseBotAdapter {
106
105
  catch (error) {
107
106
  this.running = false;
108
107
  this.readiness = 'degraded';
109
- this.reason = generalizedErrorMessage(error);
108
+ this.recordFailure(error);
110
109
  this.emitStatusChange();
111
110
  await this.stopTransport();
112
111
  throw error;
@@ -132,7 +131,7 @@ export class SlackBotBridge extends BaseBotAdapter {
132
131
  }
133
132
  catch (error) {
134
133
  this.readiness = 'degraded';
135
- this.reason = generalizedErrorMessage(error);
134
+ this.recordFailure(error, 'send-failed');
136
135
  this.emitStatusChange();
137
136
  return null;
138
137
  }
@@ -16,7 +16,6 @@
16
16
  * specific language governing permissions and limitations
17
17
  * under the License.
18
18
  */
19
- import { generalizedErrorMessage } from '@maka/core/redaction';
20
19
  import { truncateUtf16Safe } from '@maka/core/text-sanitize';
21
20
  import { BaseBotAdapter, botReadinessFromSettings } from './base-adapter.js';
22
21
  import { proxiedFetch } from './proxied-fetch.js';
@@ -216,7 +215,7 @@ export class TelegramBotBridge extends BaseBotAdapter {
216
215
  return;
217
216
  }
218
217
  if (!this.settings.token.trim()) {
219
- this.reason = 'no-token';
218
+ this.reason = 'token_missing';
220
219
  this.readiness = 'scaffolded';
221
220
  return;
222
221
  }
@@ -255,7 +254,7 @@ export class TelegramBotBridge extends BaseBotAdapter {
255
254
  }
256
255
  if (classification.kind !== 'ok') {
257
256
  this.readiness = this.readiness === 'operational' ? 'degraded' : 'credentials_valid';
258
- this.reason = classification.kind === 'retry' ? 'rate-limited' : classification.description;
257
+ this.recordFailure(classification.kind === 'retry' ? 'rate-limited' : classification.description, classification.kind === 'retry' ? 'rate-limited' : 'send-failed');
259
258
  this.emitStatusChange();
260
259
  return null;
261
260
  }
@@ -331,7 +330,7 @@ export class TelegramBotBridge extends BaseBotAdapter {
331
330
  try {
332
331
  const me = await telegramApi(this.settings.token, 'getMe');
333
332
  if (!me.ok) {
334
- this.reason = me.description ?? 'get-me-failed';
333
+ this.recordFailure(me.description ?? 'get-me-failed', me.error_code === 401 ? 'token_invalid' : 'get-me-failed');
335
334
  this.readiness = 'configured';
336
335
  this.emitStatusChange();
337
336
  return;
@@ -351,7 +350,7 @@ export class TelegramBotBridge extends BaseBotAdapter {
351
350
  void this.pollTelegram();
352
351
  }
353
352
  catch (error) {
354
- this.reason = generalizedErrorMessage(error);
353
+ this.recordFailure(error);
355
354
  this.readiness =
356
355
  this.readiness === 'operational' ? 'degraded' : botReadinessFromSettings(this.settings);
357
356
  this.emitStatusChange();
@@ -19,7 +19,7 @@
19
19
  import { generalizedErrorMessage } from '@maka/core/redaction';
20
20
  import { randomBytes, randomUUID } from 'node:crypto';
21
21
  import { createRequire } from 'node:module';
22
- import { BaseBotAdapter, botReadinessFromSettings } from './base-adapter.js';
22
+ import { BaseBotAdapter, botDiagnosticMessage, botReadinessFromSettings } from './base-adapter.js';
23
23
  import { proxiedFetch } from './proxied-fetch.js';
24
24
  const DEFAULT_WECHAT_BRIDGE_URL = 'http://127.0.0.1:18400';
25
25
  const WECHAT_BRIDGE_TIMEOUT_MS = 5_000;
@@ -90,7 +90,9 @@ export class WechatBridge extends BaseBotAdapter {
90
90
  : await testWechatBridge(this.settings);
91
91
  if (!probe.ok) {
92
92
  this.running = false;
93
- this.reason = probe.error;
93
+ this.reason = probe.errorCode ?? 'connection_failed';
94
+ if (probe.error)
95
+ this.recordFailure(probe.error, this.reason);
94
96
  this.readiness = botReadinessFromSettings(this.settings);
95
97
  this.emitStatusChange();
96
98
  return;
@@ -109,7 +111,7 @@ export class WechatBridge extends BaseBotAdapter {
109
111
  // marked degraded instead of crashing the main process.
110
112
  const fail = (err) => {
111
113
  this.running = false;
112
- this.reason = err instanceof Error ? err.message : 'stream-failed';
114
+ this.recordFailure(err, 'stream-failed');
113
115
  this.readiness = 'degraded';
114
116
  this.emitStatusChange();
115
117
  };
@@ -145,8 +147,7 @@ export class WechatBridge extends BaseBotAdapter {
145
147
  const status = typeof response.status === 'string' ? response.status : '';
146
148
  if (status === 'failed') {
147
149
  this.readiness = 'degraded';
148
- this.reason =
149
- typeof response.diagnostic === 'string' ? response.diagnostic : 'wechat-send-failed';
150
+ this.recordFailure(response.diagnostic ?? 'wechat-send-failed', 'send-failed');
150
151
  this.emitStatusChange();
151
152
  return null;
152
153
  }
@@ -159,7 +160,7 @@ export class WechatBridge extends BaseBotAdapter {
159
160
  }
160
161
  catch (error) {
161
162
  this.readiness = 'degraded';
162
- this.reason = generalizedErrorMessage(error);
163
+ this.recordFailure(error);
163
164
  this.emitStatusChange();
164
165
  return null;
165
166
  }
@@ -205,7 +206,7 @@ export class WechatBridge extends BaseBotAdapter {
205
206
  return;
206
207
  this.readiness =
207
208
  this.readiness === 'operational' ? 'degraded' : botReadinessFromSettings(this.settings);
208
- this.reason = generalizedErrorMessage(error);
209
+ this.recordFailure(error);
209
210
  this.emitStatusChange();
210
211
  await sleep(3_000);
211
212
  }
@@ -230,7 +231,7 @@ export class WechatBridge extends BaseBotAdapter {
230
231
  continue;
231
232
  if (errcode !== 0) {
232
233
  this.readiness = this.readiness === 'operational' ? 'degraded' : 'credentials_valid';
233
- this.reason = stringField(response.errmsg) ?? `ilink-${errcode}`;
234
+ this.recordFailure(stringField(response.errmsg) ?? `ilink-${errcode}`, 'stream-failed');
234
235
  this.emitStatusChange();
235
236
  await sleep(5_000);
236
237
  continue;
@@ -259,7 +260,7 @@ export class WechatBridge extends BaseBotAdapter {
259
260
  return;
260
261
  consecutiveErrors += 1;
261
262
  this.readiness = this.readiness === 'operational' ? 'degraded' : 'credentials_valid';
262
- this.reason = generalizedErrorMessage(error);
263
+ this.recordFailure(error);
263
264
  this.emitStatusChange();
264
265
  await sleep(consecutiveErrors >= 3 ? 30_000 : 2_000);
265
266
  if (consecutiveErrors >= 3)
@@ -298,7 +299,7 @@ export async function getWechatBridgeQrCode(channel) {
298
299
  return {
299
300
  ok: false,
300
301
  error: 'WeChat bridge URL must be http://127.0.0.1 or http://localhost',
301
- hint: '微信扫码登录只允许访问本机 wechat-bridge,不能指向远端 URL。',
302
+ hintCode: 'wechat_bridge_remote_url',
302
303
  };
303
304
  }
304
305
  let lastError;
@@ -316,7 +317,7 @@ export async function getWechatBridgeQrCode(channel) {
316
317
  return {
317
318
  ok: false,
318
319
  error: generalizedErrorMessage(lastError),
319
- hint: '先启动本机 wechat-bridge,并确认它暴露了 iLink 兼容的 /api/weixin/qrcode 或 /qrcode 接口。',
320
+ hintCode: 'wechat_bridge_unreachable',
320
321
  };
321
322
  }
322
323
  export function mapWechatBridgeMessage(raw) {
@@ -425,8 +426,7 @@ export async function testWechatBridge(channel) {
425
426
  if (!baseUrl) {
426
427
  return {
427
428
  ok: false,
428
- error: 'WeChat bridge URL must be http://127.0.0.1 or http://localhost',
429
- hint: '微信本地桥接只允许访问本机 wechat-bridge,不能指向远端 URL。',
429
+ errorCode: 'wechat_bridge_url_invalid',
430
430
  };
431
431
  }
432
432
  try {
@@ -455,8 +455,8 @@ export async function testWechatBridge(channel) {
455
455
  catch (error) {
456
456
  return {
457
457
  ok: false,
458
- error: generalizedErrorMessage(error),
459
- hint: '先在本机启动 wechat-bridge,并确认 WeChat 已登录;发送能力需要 wxp_act_ 激活码。',
458
+ errorCode: 'connection_failed',
459
+ error: botDiagnosticMessage(channel, error),
460
460
  };
461
461
  }
462
462
  }
@@ -486,8 +486,7 @@ export async function testWechatIlinkCredentials(channel) {
486
486
  if (!baseUrl || !token) {
487
487
  return {
488
488
  ok: false,
489
- error: 'WeChat iLink credentials are incomplete',
490
- hint: '请先完成微信扫码登录,保存 iLink bot token 与 base URL。',
489
+ errorCode: 'wechat_ilink_credentials_incomplete',
491
490
  };
492
491
  }
493
492
  return {
@@ -498,11 +497,10 @@ export async function testWechatIlinkCredentials(channel) {
498
497
  displayName: channel.botUserId ? `iLink ${channel.botUserId}` : 'WeChat iLink',
499
498
  },
500
499
  capabilities: { auth: true, send: true },
501
- hint: '扫码登录凭据已保存;运行态会通过 iLink 长轮询接收消息。',
502
500
  };
503
501
  }
504
502
  function isWechatIlinkChannel(channel) {
505
- return Boolean(channel.token.trim() && normalizeWechatIlinkBaseUrl(channel.webhookUrl));
503
+ return Boolean(normalizeWechatIlinkBaseUrl(channel.webhookUrl));
506
504
  }
507
505
  async function wechatIlinkPost(baseUrl, path, body, token, signal) {
508
506
  const response = await proxiedFetch(`${baseUrl}${path}`, {
@@ -17,7 +17,6 @@
17
17
  * under the License.
18
18
  */
19
19
  import { WSClient } from '@wecom/aibot-node-sdk';
20
- import { generalizedErrorMessage } from '@maka/core/redaction';
21
20
  import { BaseBotAdapter, botReadinessFromSettings } from './base-adapter.js';
22
21
  const AUTH_TIMEOUT_MS = 15_000;
23
22
  /** Detach bridge callbacks before disconnect can synchronously emit. */
@@ -73,7 +72,7 @@ export class WeComBotBridge extends BaseBotAdapter {
73
72
  const botId = this.settings.appId?.trim() ?? '';
74
73
  const secret = this.settings.appSecret?.trim() ?? '';
75
74
  if (!botId || !secret) {
76
- this.reason = 'no-credentials';
75
+ this.reason = 'wecom_credentials_missing';
77
76
  this.readiness = 'scaffolded';
78
77
  this.emitStatusChange();
79
78
  return;
@@ -122,7 +121,7 @@ export class WeComBotBridge extends BaseBotAdapter {
122
121
  if (this.explicitlyStopped || this.client !== client)
123
122
  return;
124
123
  this.running = false;
125
- this.reason = generalizedErrorMessage(error);
124
+ this.recordFailure(error);
126
125
  this.readiness = 'configured';
127
126
  this.emitStatusChange();
128
127
  this.client = null;
@@ -157,7 +156,7 @@ export class WeComBotBridge extends BaseBotAdapter {
157
156
  }
158
157
  catch (error) {
159
158
  this.readiness = this.readiness === 'operational' ? 'degraded' : 'credentials_valid';
160
- this.reason = generalizedErrorMessage(error);
159
+ this.recordFailure(error, 'send-failed');
161
160
  this.emitStatusChange();
162
161
  return null;
163
162
  }
@@ -197,7 +196,7 @@ export class WeComBotBridge extends BaseBotAdapter {
197
196
  if (this.client !== client || this.explicitlyStopped)
198
197
  return;
199
198
  this.running = false;
200
- this.reason = reason || 'disconnected';
199
+ this.recordFailure(reason || 'disconnected', 'disconnected');
201
200
  this.readiness = this.readiness === 'operational' ? 'degraded' : 'configured';
202
201
  this.emitStatusChange();
203
202
  });
@@ -210,7 +209,7 @@ export class WeComBotBridge extends BaseBotAdapter {
210
209
  client.on('error', (error) => {
211
210
  if (this.client !== client || this.explicitlyStopped)
212
211
  return;
213
- this.reason = generalizedErrorMessage(error);
212
+ this.recordFailure(error);
214
213
  this.readiness = this.readiness === 'operational' ? 'degraded' : 'configured';
215
214
  this.emitStatusChange();
216
215
  });
@@ -103,7 +103,7 @@ export class WsBridgeBase extends BaseBotAdapter {
103
103
  ws = this.createWebSocket(url);
104
104
  }
105
105
  catch (error) {
106
- this.reason = error instanceof Error ? error.message : String(error);
106
+ this.recordFailure(error);
107
107
  this.readiness = 'configured';
108
108
  this.emitStatusChange();
109
109
  this.scheduleReconnect();
@@ -147,9 +147,9 @@ export class WsBridgeBase extends BaseBotAdapter {
147
147
  const decision = this.decideClose(code, this.explicitlyStopped);
148
148
  if (decision.kind === 'stopped')
149
149
  return;
150
+ this.recordFailure(reason, `${this.closeReasonPrefix}-closed-${code}`);
150
151
  if (decision.kind === 'fatal') {
151
152
  this.readiness = 'configured';
152
- this.reason = `${this.closeReasonPrefix}-closed-${code}`;
153
153
  this.resetSession();
154
154
  this.emitStatusChange();
155
155
  return;
@@ -158,7 +158,6 @@ export class WsBridgeBase extends BaseBotAdapter {
158
158
  this.resetSession();
159
159
  }
160
160
  this.readiness = 'degraded';
161
- this.reason = reason || `${this.closeReasonPrefix}-closed-${code}`;
162
161
  this.emitStatusChange();
163
162
  this.scheduleReconnect();
164
163
  }