aws-runtime-bridge 1.9.172 → 1.9.179

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 (383) hide show
  1. package/CHANGELOG.md +314 -0
  2. package/README.md +61 -2
  3. package/dist/adapter/AcodeSdkAdapter.d.ts +374 -1
  4. package/dist/adapter/AcodeSdkAdapter.js +3 -3
  5. package/dist/adapter/AdapterRegistry.d.ts +28 -0
  6. package/dist/adapter/ClaudeSdkAdapter.d.ts +71 -0
  7. package/dist/adapter/CodexSdkAdapter.d.ts +14 -0
  8. package/dist/adapter/OpencodeSdkAdapter.d.ts +44 -0
  9. package/dist/adapter/acode-tool-names.d.ts +9 -0
  10. package/dist/adapter/idle-poll-loop.d.ts +20 -0
  11. package/dist/adapter/index.d.ts +3 -0
  12. package/dist/adapter/instance-ai-config-resolver.d.ts +20 -0
  13. package/dist/adapter/prompts.d.ts +12 -0
  14. package/dist/adapter/types.d.ts +184 -0
  15. package/dist/browser/browser-bootstrap.d.ts +15 -0
  16. package/dist/browser/browser-connect-token.d.ts +11 -0
  17. package/dist/browser/browser-frame-encode.d.ts +32 -0
  18. package/dist/browser/browser-pool.d.ts +129 -0
  19. package/dist/browser/browser-profile-store.d.ts +41 -0
  20. package/dist/browser/browser-ws-bridge.d.ts +20 -0
  21. package/dist/browser/built-in-browser-tools.d.ts +44 -0
  22. package/dist/browser/element-locator.d.ts +25 -0
  23. package/dist/browser/element-picker.d.ts +30 -0
  24. package/dist/browser/frame-encode.d.ts +19 -0
  25. package/dist/browser/input-dispatcher.d.ts +35 -0
  26. package/dist/browser/listener-store.d.ts +44 -0
  27. package/dist/browser/page-listener-manager.d.ts +88 -0
  28. package/dist/browser/page-listener-types.d.ts +38 -0
  29. package/dist/browser/screencast-differ.d.ts +10 -0
  30. package/dist/browser/screencast-manager.d.ts +94 -0
  31. package/dist/browser/snapshot-serializer.d.ts +56 -0
  32. package/dist/browser/ssrf-guard.d.ts +44 -0
  33. package/dist/browser/stealth.d.ts +21 -0
  34. package/dist/browser/step-archive.d.ts +13 -0
  35. package/dist/browser/types.d.ts +100 -0
  36. package/dist/browser/ws-server.d.ts +54 -0
  37. package/dist/config.d.ts +138 -2
  38. package/dist/config.js +2 -2
  39. package/dist/desktop/built-in-desktop-tools.d.ts +68 -0
  40. package/dist/desktop/built-in-desktop-tools.js +2 -1
  41. package/dist/desktop/desktop-control.d.ts +142 -0
  42. package/dist/desktop/desktop-control.js +2 -0
  43. package/dist/desktop/desktop-mcp-client.d.ts +28 -0
  44. package/dist/desktop/desktop-staleness.d.ts +66 -0
  45. package/dist/desktop/desktop-staleness.js +2 -0
  46. package/dist/index.d.ts +4 -0
  47. package/dist/index.js +1 -1
  48. package/dist/middleware/auth.d.ts +26 -0
  49. package/dist/middleware/auth.js +1 -1
  50. package/dist/remote-desktop/computer-control.d.ts +3 -0
  51. package/dist/remote-desktop/coords.d.ts +6 -0
  52. package/dist/remote-desktop/frame-backpressure.d.ts +10 -0
  53. package/dist/remote-desktop/frame-encode.d.ts +3 -0
  54. package/dist/remote-desktop/index.js +2 -2
  55. package/dist/remote-desktop/input-dispatcher.d.ts +4 -0
  56. package/dist/remote-desktop/permission-manager.d.ts +3 -0
  57. package/dist/remote-desktop/screen-capture.d.ts +91 -0
  58. package/dist/remote-desktop/session-manager.d.ts +47 -0
  59. package/dist/remote-desktop/session-manager.js +1 -1
  60. package/dist/remote-desktop/system-backend.d.ts +64 -0
  61. package/dist/remote-desktop/types.d.ts +25 -0
  62. package/dist/remote-desktop/ui-automation.d.ts +11 -0
  63. package/dist/remote-desktop/win32-api.d.ts +10 -0
  64. package/dist/routes/acode-todos.d.ts +13 -0
  65. package/dist/routes/agent-state.d.ts +15 -0
  66. package/dist/routes/ai-sources.js +1 -1
  67. package/dist/routes/background-tasks.d.ts +18 -0
  68. package/dist/routes/background-tasks.js +2 -2
  69. package/dist/routes/bridge-temp-files.d.ts +1 -0
  70. package/dist/routes/bridge-temp-files.js +2 -0
  71. package/dist/routes/browser-listeners.d.ts +17 -0
  72. package/dist/routes/browser-sessions.d.ts +10 -0
  73. package/dist/routes/capabilities.js +1 -1
  74. package/dist/routes/dashboard-icon.d.ts +9 -0
  75. package/dist/routes/dashboard-icon.js +2 -0
  76. package/dist/routes/dashboard-theme.d.ts +24 -0
  77. package/dist/routes/dashboard-theme.js +157 -0
  78. package/dist/routes/dashboard.d.ts +9 -0
  79. package/dist/routes/dashboard.js +2021 -628
  80. package/dist/routes/debug-mount.d.ts +16 -0
  81. package/dist/routes/desktop-control.d.ts +15 -0
  82. package/dist/routes/desktop-control.js +2 -0
  83. package/dist/routes/events.d.ts +4 -0
  84. package/dist/routes/file-browser.d.ts +15 -10
  85. package/dist/routes/file-browser.js +1 -1
  86. package/dist/routes/file-change-diff.d.ts +25 -0
  87. package/dist/routes/file-diff-rollback.d.ts +28 -0
  88. package/dist/routes/file-snapshot.d.ts +7 -0
  89. package/dist/routes/git.d.ts +185 -0
  90. package/dist/routes/git.js +34 -34
  91. package/dist/routes/instance-tool-status.d.ts +5 -0
  92. package/dist/routes/instance.d.ts +8 -0
  93. package/dist/routes/instance.js +1 -1
  94. package/dist/routes/jdks.d.ts +4 -0
  95. package/dist/routes/launch.d.ts +5 -0
  96. package/dist/routes/lsp-providers.d.ts +11 -0
  97. package/dist/routes/lsp-providers.js +2 -0
  98. package/dist/routes/lsp.d.ts +41 -0
  99. package/dist/routes/lsp.js +4 -2
  100. package/dist/routes/mcp-extra.d.ts +15 -0
  101. package/dist/routes/mcp.d.ts +16 -0
  102. package/dist/routes/mcp.js +1 -1
  103. package/dist/routes/plugins.d.ts +19 -0
  104. package/dist/routes/plugins.js +1 -1
  105. package/dist/routes/processes.d.ts +4 -0
  106. package/dist/routes/properties.d.ts +4 -0
  107. package/dist/routes/pty.d.ts +29 -0
  108. package/dist/routes/runtime-binding.d.ts +3 -0
  109. package/dist/routes/sessions.d.ts +22 -0
  110. package/dist/routes/sessions.js +1 -1
  111. package/dist/routes/skills.d.ts +15 -0
  112. package/dist/routes/skills.js +1 -1
  113. package/dist/routes/sub-agents.d.ts +11 -0
  114. package/dist/routes/sub-agents.js +1 -1
  115. package/dist/routes/task-context.d.ts +5 -0
  116. package/dist/routes/tech-stack.d.ts +6 -0
  117. package/dist/routes/tech-stack.js +2 -0
  118. package/dist/routes/terminal.d.ts +122 -0
  119. package/dist/routes/terminal.js +22 -22
  120. package/dist/routes/workspace-index.d.ts +12 -0
  121. package/dist/routes/workspace-index.js +2 -0
  122. package/dist/routes/yml.d.ts +4 -0
  123. package/dist/scripts/migrate-user-scopes.d.ts +26 -0
  124. package/dist/scripts/migrate-user-scopes.js +2 -0
  125. package/dist/services/access-control.d.ts +21 -0
  126. package/dist/services/acode-bg-manager.d.ts +21 -0
  127. package/dist/services/acode-package.d.ts +10 -0
  128. package/dist/services/acode-package.js +1 -1
  129. package/dist/services/agent-capability-sync.d.ts +26 -0
  130. package/dist/services/agent-capability-sync.js +1 -1
  131. package/dist/services/agent-event-store.d.ts +20 -0
  132. package/dist/services/agent-ownership.d.ts +58 -0
  133. package/dist/services/agent-ownership.js +3 -0
  134. package/dist/services/agent-process-manager.d.ts +154 -0
  135. package/dist/services/agent-pty-manager.d.ts +39 -0
  136. package/dist/services/agent-pty-manager.js +5 -4
  137. package/dist/services/agent-startup-memory.d.ts +34 -0
  138. package/dist/services/agent-startup-memory.js +4 -4
  139. package/dist/services/ai-config-service.d.ts +26 -52
  140. package/dist/services/ai-config-service.js +1 -3
  141. package/dist/services/ai-source-apply.d.ts +7 -15
  142. package/dist/services/ai-source-apply.js +1 -1
  143. package/dist/services/auto-register.d.ts +165 -1
  144. package/dist/services/auto-register.js +1 -1
  145. package/dist/services/aws-client-agent-mcp.d.ts +14 -0
  146. package/dist/services/aws-client-agent-mcp.js +2 -2
  147. package/dist/services/bridge-package-publish-hooks.d.ts +14 -0
  148. package/dist/services/bridge-pairing.d.ts +82 -0
  149. package/dist/services/bridge-pairing.js +2 -0
  150. package/dist/services/bridge-temp-files.d.ts +65 -0
  151. package/dist/services/bridge-temp-files.js +2 -0
  152. package/dist/services/browser-session-manager.d.ts +71 -0
  153. package/dist/services/capability-config.d.ts +60 -15
  154. package/dist/services/capability-config.js +2 -2
  155. package/dist/services/change-cache-retention.d.ts +9 -0
  156. package/dist/services/changelog.d.ts +9 -0
  157. package/dist/services/cli-commands.d.ts +82 -0
  158. package/dist/services/cli-commands.js +6 -6
  159. package/dist/services/connection-key-rotation.d.ts +27 -0
  160. package/dist/services/connection-key-rotation.js +2 -0
  161. package/dist/services/debug-mount.d.ts +49 -0
  162. package/dist/services/desktop-mcp-manager.d.ts +103 -1
  163. package/dist/services/desktop-mcp-manager.js +1 -1
  164. package/dist/services/event-delta-pusher.d.ts +15 -0
  165. package/dist/services/fileSnapshotStore.d.ts +42 -0
  166. package/dist/services/fileSnapshotStore.js +1 -1
  167. package/dist/services/gitignore.d.ts +21 -0
  168. package/dist/services/gitignore.js +2 -0
  169. package/dist/services/instance-ai-config-service.d.ts +9 -0
  170. package/dist/services/instance-ai-config-service.js +1 -1
  171. package/dist/services/instance-features.d.ts +127 -0
  172. package/dist/services/instance-features.js +1 -1
  173. package/dist/services/instance-init-service.d.ts +3 -0
  174. package/dist/services/instance-init-service.js +1 -1
  175. package/dist/services/instance-state.d.ts +23 -0
  176. package/dist/services/jdk-scanner.d.ts +15 -0
  177. package/dist/services/launch-manager.d.ts +138 -0
  178. package/dist/services/launch-metrics.d.ts +42 -0
  179. package/dist/services/launch-streams.d.ts +19 -0
  180. package/dist/services/lifecycle-state.d.ts +5 -0
  181. package/dist/services/log-retention.d.ts +38 -0
  182. package/dist/services/log-retention.js +1 -1
  183. package/dist/services/lsp/install-manager.d.ts +55 -0
  184. package/dist/services/lsp/install-manager.js +2 -0
  185. package/dist/services/lsp/provider-registry.d.ts +108 -0
  186. package/dist/services/lsp/provider-registry.js +2 -0
  187. package/dist/services/lsp/uri-rewrite.d.ts +44 -0
  188. package/dist/services/lsp/uri-rewrite.js +2 -0
  189. package/dist/services/lsp-stdio-bridge.d.ts +41 -4
  190. package/dist/services/lsp-stdio-bridge.js +3 -3
  191. package/dist/services/mcp-deploy.d.ts +45 -4
  192. package/dist/services/mcp-deploy.js +4 -4
  193. package/dist/services/mcp-env-injector.d.ts +52 -0
  194. package/dist/services/mcp-launch-binding-queue.d.ts +12 -0
  195. package/dist/services/mcp-package.d.ts +22 -0
  196. package/dist/services/mcp-package.js +1 -1
  197. package/dist/services/mcp-probe-client.d.ts +19 -0
  198. package/dist/services/mcp-probe-client.js +1 -1
  199. package/dist/services/open-doc-events.d.ts +43 -0
  200. package/dist/services/open-doc-events.js +2 -0
  201. package/dist/services/open-doc-registry.d.ts +59 -0
  202. package/dist/services/open-doc-registry.js +2 -0
  203. package/dist/services/orphan-monitor.d.ts +43 -0
  204. package/dist/services/panel-auth.d.ts +24 -0
  205. package/dist/services/panel-env.d.ts +28 -0
  206. package/dist/services/plugin-deployment.d.ts +34 -1
  207. package/dist/services/plugin-deployment.js +2 -2
  208. package/dist/services/plugin-event-buffer.d.ts +21 -0
  209. package/dist/services/plugin-fs.d.ts +11 -0
  210. package/dist/services/plugin-handler-adapter.d.ts +13 -0
  211. package/dist/services/plugin-listener-runner.d.ts +10 -0
  212. package/dist/services/plugin-loader.d.ts +15 -0
  213. package/dist/services/plugin-manager.d.ts +95 -9
  214. package/dist/services/plugin-manager.js +4 -4
  215. package/dist/services/plugin-manifest.d.ts +14 -0
  216. package/dist/services/plugin-package.d.ts +13 -0
  217. package/dist/services/plugin-runtime.d.ts +15 -0
  218. package/dist/services/port-detector.d.ts +15 -0
  219. package/dist/services/process-detail.d.ts +3 -0
  220. package/dist/services/process-detector.d.ts +132 -0
  221. package/dist/services/process-registry.d.ts +120 -0
  222. package/dist/services/process-top.d.ts +6 -0
  223. package/dist/services/request-identity.d.ts +77 -0
  224. package/dist/services/request-identity.js +2 -0
  225. package/dist/services/request-invalid-dump.d.ts +4 -0
  226. package/dist/services/request-invalid-dump.js +1 -1
  227. package/dist/services/ring-buffer.d.ts +33 -0
  228. package/dist/services/runtime-binding.d.ts +56 -4
  229. package/dist/services/runtime-binding.js +4 -4
  230. package/dist/services/runtime-lifecycle-policy.d.ts +17 -0
  231. package/dist/services/runtime-resources-snapshot.d.ts +26 -0
  232. package/dist/services/runtime-resources-snapshot.js +2 -2
  233. package/dist/services/sdk-tool-file-change-recorder.d.ts +9 -0
  234. package/dist/services/session-output.d.ts +63 -0
  235. package/dist/services/session-output.js +3 -3
  236. package/dist/services/skill-manager.d.ts +42 -5
  237. package/dist/services/skill-manager.js +3 -3
  238. package/dist/services/snapshot-retention.d.ts +30 -0
  239. package/dist/services/snapshot-retention.js +2 -0
  240. package/dist/services/startup-config-wizard.d.ts +7 -1
  241. package/dist/services/startup-config-wizard.js +10 -10
  242. package/dist/services/system-metrics.d.ts +3 -0
  243. package/dist/services/tech-stack-scanner.d.ts +43 -0
  244. package/dist/services/tech-stack-scanner.js +2 -0
  245. package/dist/services/terminal-persistence.d.ts +43 -0
  246. package/dist/services/tool-installer.d.ts +12 -0
  247. package/dist/services/tunnel-client.d.ts +99 -2
  248. package/dist/services/tunnel-client.js +1 -1
  249. package/dist/services/update-log.d.ts +6 -0
  250. package/dist/services/update-notifier.d.ts +17 -0
  251. package/dist/services/update-notifier.js +2 -2
  252. package/dist/services/user-scope.d.ts +115 -0
  253. package/dist/services/user-scope.js +2 -0
  254. package/dist/services/windows-service-manager.d.ts +12 -0
  255. package/dist/services/workspace-files.d.ts +64 -0
  256. package/dist/services/workspace-index/index-manager.d.ts +46 -0
  257. package/dist/services/workspace-index/index-manager.js +2 -0
  258. package/dist/services/workspace-index/indexer.d.ts +15 -0
  259. package/dist/services/workspace-index/indexer.js +2 -0
  260. package/dist/services/workspace-index/query.d.ts +74 -0
  261. package/dist/services/workspace-index/query.js +5 -0
  262. package/dist/services/workspace-index/resolver.d.ts +26 -0
  263. package/dist/services/workspace-index/resolver.js +2 -0
  264. package/dist/services/workspace-index/types.d.ts +89 -0
  265. package/dist/services/workspace-index/types.js +2 -0
  266. package/dist/services/workspace-watch.d.ts +4 -0
  267. package/dist/services/workspaceTaskChangeWatcher.d.ts +49 -0
  268. package/dist/services/workspaceTaskChangeWatcher.js +2 -2
  269. package/dist/types.d.ts +9 -0
  270. package/dist/utils/config-write-queue.d.ts +11 -0
  271. package/dist/utils/env-safety.d.ts +21 -0
  272. package/dist/utils/file-utils.d.ts +15 -0
  273. package/dist/utils/instance-ai-config-debug-logger.d.ts +15 -0
  274. package/dist/utils/lifecycle-log.d.ts +5 -0
  275. package/dist/utils/logger.d.ts +13 -0
  276. package/dist/utils/logger.js +2 -1
  277. package/dist/utils/npm-version.d.ts +10 -0
  278. package/dist/utils/path-utils.d.ts +12 -0
  279. package/dist/utils/scheduler-url.d.ts +18 -0
  280. package/dist/utils/scheduler-url.js +2 -0
  281. package/dist/utils/sdk-package-loader.d.ts +13 -0
  282. package/dist/utils/sdk-package-loader.js +1 -1
  283. package/dist/utils/target-identity.d.ts +31 -0
  284. package/dist/utils/target-identity.js +2 -0
  285. package/dist/utils/validation.d.ts +17 -0
  286. package/dist/utils/yaml-utils.d.ts +48 -0
  287. package/package/acode/dist/__tests__/summary-request-helper.d.ts +12 -0
  288. package/package/acode/dist/__tests__/summary-request-helper.js +2 -0
  289. package/package/acode/dist/ask-user-question-tool.d.ts +17 -0
  290. package/package/acode/dist/await-complete-tool.d.ts +12 -0
  291. package/package/acode/dist/background-command-manager.d.ts +105 -0
  292. package/package/acode/dist/background-command-store.d.ts +27 -0
  293. package/package/acode/dist/background-command-tools.d.ts +8 -0
  294. package/package/acode/dist/background-output-ringbuffer.d.ts +15 -0
  295. package/package/acode/dist/built-in-file-tools.d.ts +65 -0
  296. package/package/acode/dist/built-in-symbols-tool.d.ts +3 -0
  297. package/package/acode/dist/builtins/commandArtifacts.d.ts +3 -0
  298. package/package/acode/dist/builtins/shellCommandPreparation.d.ts +17 -0
  299. package/package/acode/dist/builtins/shellCommandRunner.d.ts +4 -0
  300. package/package/acode/dist/builtins/shellOutputDecoder.d.ts +15 -0
  301. package/package/acode/dist/cache-control.d.ts +71 -0
  302. package/package/acode/dist/cache-control.js +2 -0
  303. package/package/acode/dist/commands/commandLoader.d.ts +3 -0
  304. package/package/acode/dist/commands/commandParser.d.ts +3 -0
  305. package/package/acode/dist/commands/commandRegistry.d.ts +3 -0
  306. package/package/acode/dist/compaction.d.ts +388 -4
  307. package/package/acode/dist/compaction.js +19 -17
  308. package/package/acode/dist/config.d.ts +3 -0
  309. package/package/acode/dist/context-overflow.d.ts +32 -0
  310. package/package/acode/dist/fs-utils.d.ts +18 -0
  311. package/package/acode/dist/hooks/hookBus.d.ts +3 -0
  312. package/package/acode/dist/image-utils.d.ts +35 -0
  313. package/package/acode/dist/index.d.ts +1 -0
  314. package/package/acode/dist/index.js +1 -1
  315. package/package/acode/dist/mcpToolNames.d.ts +32 -0
  316. package/package/acode/dist/microcompact.d.ts +110 -0
  317. package/package/acode/dist/microcompact.js +2 -0
  318. package/package/acode/dist/parsers/ast-cache.d.ts +41 -0
  319. package/package/acode/dist/parsers/file-index.d.ts +83 -0
  320. package/package/acode/dist/parsers/file-index.js +4 -0
  321. package/package/acode/dist/parsers/language-detector.d.ts +4 -0
  322. package/package/acode/dist/parsers/tree-sitter-loader.d.ts +12 -0
  323. package/package/acode/dist/parsers/types.d.ts +11 -0
  324. package/package/acode/dist/paths.d.ts +14 -0
  325. package/package/acode/dist/plugin-types.d.ts +34 -0
  326. package/package/acode/dist/read-file-state.d.ts +15 -0
  327. package/package/acode/dist/runtime-environment.d.ts +16 -0
  328. package/package/acode/dist/runtime.d.ts +828 -9
  329. package/package/acode/dist/runtime.js +40 -33
  330. package/package/acode/dist/skill-tool.d.ts +20 -0
  331. package/package/acode/dist/sub-agent-manager.d.ts +169 -0
  332. package/package/acode/dist/sub-agent-manager.js +1 -1
  333. package/package/acode/dist/sub-agent-store.d.ts +50 -0
  334. package/package/acode/dist/sub-agent-tools.d.ts +15 -0
  335. package/package/acode/dist/sub-agent-types.d.ts +13 -0
  336. package/package/acode/dist/terminal-tool.d.ts +15 -0
  337. package/package/acode/dist/terminal-types.d.ts +10 -0
  338. package/package/acode/dist/todo-store.d.ts +15 -0
  339. package/package/acode/dist/token-estimator.d.ts +32 -0
  340. package/package/acode/dist/token-estimator.js +2 -0
  341. package/package/acode/dist/tool-allocation.d.ts +113 -0
  342. package/package/acode/dist/tool-concurrency/index.d.ts +8 -0
  343. package/package/acode/dist/tool-concurrency/observability.d.ts +32 -0
  344. package/package/acode/dist/tool-concurrency/resource-lock.d.ts +30 -0
  345. package/package/acode/dist/tool-concurrency/scheduler.d.ts +19 -0
  346. package/package/acode/dist/tool-concurrency/types.d.ts +57 -0
  347. package/package/acode/dist/tool-group-manager.d.ts +195 -0
  348. package/package/acode/dist/tool-group-manager.js +4 -4
  349. package/package/acode/dist/types.d.ts +192 -0
  350. package/package/aws-client-agent-mcp/README.md +130 -215
  351. package/package/aws-client-agent-mcp/dist/ability-market-tools.d.ts +57 -0
  352. package/package/aws-client-agent-mcp/dist/ability-market-tools.js +1 -1
  353. package/package/aws-client-agent-mcp/dist/agent-client.d.ts +290 -3
  354. package/package/aws-client-agent-mcp/dist/agent-client.js +1 -1
  355. package/package/aws-client-agent-mcp/dist/config.d.ts +18 -0
  356. package/package/aws-client-agent-mcp/dist/constants.d.ts +2 -0
  357. package/package/aws-client-agent-mcp/dist/context-manager.d.ts +70 -0
  358. package/package/aws-client-agent-mcp/dist/http-client.d.ts +61 -0
  359. package/package/aws-client-agent-mcp/dist/index.d.ts +10 -0
  360. package/package/aws-client-agent-mcp/dist/logger.d.ts +24 -0
  361. package/package/aws-client-agent-mcp/dist/mcp-server.d.ts +610 -0
  362. package/package/aws-client-agent-mcp/dist/mcp-server.js +25 -23
  363. package/package/aws-client-agent-mcp/dist/mcp-tools.d.ts +158 -0
  364. package/package/aws-client-agent-mcp/dist/mcp-tools.js +38 -22
  365. package/package/aws-client-agent-mcp/dist/memory-store.d.ts +102 -2
  366. package/package/aws-client-agent-mcp/dist/memory-store.js +27 -2
  367. package/package/aws-client-agent-mcp/dist/memory-tools.d.ts +18 -0
  368. package/package/aws-client-agent-mcp/dist/memory-tools.js +13 -9
  369. package/package/aws-client-agent-mcp/dist/message-buffer.d.ts +86 -0
  370. package/package/aws-client-agent-mcp/dist/messageContent.d.ts +24 -0
  371. package/package/aws-client-agent-mcp/dist/office/office-equation.d.ts +19 -0
  372. package/package/aws-client-agent-mcp/dist/office/office-image.d.ts +18 -0
  373. package/package/aws-client-agent-mcp/dist/office/office-workspace.d.ts +29 -0
  374. package/package/aws-client-agent-mcp/dist/parent-lifecycle.d.ts +18 -0
  375. package/package/aws-client-agent-mcp/dist/runtime-launch-binding.d.ts +6 -0
  376. package/package/aws-client-agent-mcp/dist/server-memory-store.d.ts +5 -1
  377. package/package/aws-client-agent-mcp/dist/server-memory-store.js +1 -1
  378. package/package/aws-client-agent-mcp/dist/status-reporter.d.ts +41 -0
  379. package/package/aws-client-agent-mcp/dist/tool-groups.d.ts +136 -0
  380. package/package/aws-client-agent-mcp/dist/types.d.ts +174 -0
  381. package/package/aws-client-agent-mcp/dist/watchdog.d.ts +7 -0
  382. package/package/aws-client-agent-mcp/dist/websocket-client.d.ts +108 -0
  383. package/package.json +1 -1
@@ -1,11 +1,18 @@
1
1
 
2
+
3
+
4
+
2
5
  import type { MemoryStats } from "./memory-store.js";
3
6
  import { StatusReporter } from "./status-reporter.js";
4
- import type { AgentConfig, BrowserListenerEvent, Card, DirectMessage, DmHistoryResponse, FetchUnreadMessagesOptions, FinishTaskRollbackArgs, GroupHistoryResponse, GroupRoomsResponse, HireBatchResult, HireColleagueArgs, MessageHandler, OnlineListResponse, ProfileInfo, ProjectMembersResponse, RegisterResult, ReplyToRef, ServerConfig, SendDmResult, SendMessageResult, StartTaskRollbackArgs, TaskInstanceCommentArgs, UnreadMessagesResult } from "./types.js";
7
+ import type { AgentConfig, BrowserListenerEvent, Card, CurrentActionSnapshot, DirectMessage, DmHistoryResponse, FetchUnreadMessagesOptions, FinishTaskRollbackArgs, GroupHistoryResponse, GroupRoomsResponse, HireBatchResult, HireColleagueArgs, MessageHandler, OnlineListResponse, ProfileInfo, ProjectMembersResponse, RegisterResult, ReplyToRef, ServerConfig, SendDmResult, SendMessageResult, StartTaskRollbackArgs, TaskInstanceCommentArgs, UnreadMessagesResult, VoiceSendOptions } from "./types.js";
5
8
  export type ProfileHandler = (profile: ProfileInfo) => void;
6
9
  export type AgentConfigHandler = (data: Record<string, unknown>) => void;
7
10
  export type SystemNotifyHandler = (data: Record<string, unknown>) => void;
8
11
 
12
+
13
+
14
+
15
+
9
16
  export declare class PollLongPollTimeoutError extends Error {
10
17
  constructor(message: string);
11
18
  }
@@ -29,145 +36,396 @@ export declare class AgentClient {
29
36
 
30
37
  private runtimeTokenRefreshTimer;
31
38
 
39
+
40
+
41
+
42
+
32
43
  private pendingLaunchBindingClaim;
33
44
 
45
+
46
+
47
+
34
48
  private cachedProfile;
35
49
  constructor();
36
50
  initialize(): Promise<void>;
37
51
  private applyLaunchBinding;
38
52
 
53
+
54
+
55
+
39
56
  private retryPendingLaunchBindingClaim;
40
57
  private setupWebSocketListeners;
41
58
 
59
+
60
+
42
61
  register(): Promise<RegisterResult>;
43
62
  private hasPresetAgentId;
44
63
 
64
+
65
+
45
66
  private registerWithExistingAgentId;
46
67
 
68
+
69
+
47
70
  private registerAsNewAgent;
48
71
 
72
+
73
+
49
74
  unregister(): Promise<void>;
50
75
 
76
+
77
+
51
78
  discoverColleagues(): Promise<OnlineListResponse>;
52
79
 
80
+
81
+
53
82
  discoverGroupRooms(): Promise<GroupRoomsResponse>;
54
83
 
84
+
85
+
55
86
  listProjectMembers(): Promise<ProjectMembersResponse>;
56
87
 
88
+
89
+
90
+
91
+
57
92
  hireColleague(args: HireColleagueArgs): Promise<HireBatchResult>;
58
93
 
94
+
95
+
96
+
97
+
98
+
99
+
59
100
  callAgentScopedTool<T = unknown>(toolName: string, args: Record<string, unknown>): Promise<T>;
60
101
 
102
+
103
+
104
+
61
105
  reportMemoryStats(memoryStats: MemoryStats): Promise<void>;
62
106
 
63
- sendGroupMessage(content: string, projectId?: string, roomId?: string, card?: Card, replyTo?: ReplyToRef[]): Promise<SendMessageResult>;
107
+
108
+
109
+
110
+
111
+
112
+
113
+
114
+
115
+
116
+
117
+ sendGroupMessage(content: string, projectId?: string, roomId?: string, card?: Card, replyTo?: ReplyToRef[], voice?: VoiceSendOptions): Promise<SendMessageResult>;
64
118
 
65
- sendDirectMessage(targetId: string, content: string, waitReply?: boolean, replyToCallId?: string, timeoutMs?: number, card?: Card, replyTo?: ReplyToRef[]): Promise<SendDmResult>;
119
+
120
+
121
+
122
+
123
+
124
+
125
+
126
+
127
+ sendDirectMessage(targetId: string, content: string, waitReply?: boolean, replyToCallId?: string, timeoutMs?: number, card?: Card, replyTo?: ReplyToRef[], forceOptions?: {
128
+ priority?: "normal" | "force";
129
+ intent?: "stop" | "redirect" | "constraint";
130
+ ref?: {
131
+ taskInstanceId?: string;
132
+ nodeId?: string;
133
+ messageId?: string;
134
+ };
135
+ reason?: string;
136
+ }, voice?: VoiceSendOptions): Promise<SendDmResult>;
66
137
 
138
+
139
+
67
140
  sendCallAndWaitReply(targetId: string, content: string, timeoutMs?: number): Promise<DirectMessage>;
68
141
 
142
+
143
+
69
144
  replyToCall(callId: string, targetId: string, content: string): Promise<SendDmResult>;
70
145
 
146
+
147
+
148
+
71
149
  sendEmail(args: Record<string, unknown>): Promise<unknown>;
72
150
 
151
+
152
+
73
153
  listEmails(args: Record<string, unknown>): Promise<unknown>;
74
154
 
155
+
156
+
157
+
75
158
  readEmail(mailId: string): Promise<unknown>;
76
159
 
160
+
161
+
162
+
77
163
  replyEmail(args: Record<string, unknown>): Promise<unknown>;
78
164
 
165
+
166
+
79
167
  ackEmail(mailId: string): Promise<unknown>;
80
168
 
169
+
170
+
81
171
  getDmHistory(targetUserId?: string, limit?: number, since?: string): Promise<DmHistoryResponse>;
82
172
 
173
+
174
+
83
175
  getGroupHistory(limit?: number, roomId?: string, since?: string): Promise<GroupHistoryResponse>;
84
176
 
177
+
178
+
179
+
180
+
85
181
  fetchUnreadMessages(options?: FetchUnreadMessagesOptions): Promise<UnreadMessagesResult>;
86
182
 
183
+
184
+
185
+
87
186
  markDmRead(msgIds: string[]): Promise<Set<string>>;
88
187
 
188
+
189
+
190
+
191
+
192
+
193
+
194
+
195
+
196
+ markForceInjected(msgIds: string[]): Promise<Set<string>>;
197
+
198
+
199
+
200
+
89
201
  markGroupRead(roomId: string, msgIds: number[]): Promise<Set<number>>;
90
202
 
203
+
204
+
205
+
206
+
207
+
91
208
  markNotificationRead(msgIds: string[]): Promise<void>;
92
209
 
210
+
211
+
212
+
213
+
214
+
215
+
93
216
  markMeetingRead(msgIds: Array<string | number>): Promise<void>;
94
217
 
218
+
219
+
220
+
221
+
222
+
223
+
224
+
225
+
226
+
227
+
228
+
95
229
  fetchBrowserListenerEvents(): Promise<BrowserListenerEvent[]>;
96
230
 
231
+
232
+
233
+
234
+
235
+
236
+
97
237
  fetchPluginEvents(): Promise<{
98
238
  revision: number;
99
239
  events: DirectMessage[];
100
240
  }>;
101
241
 
242
+
243
+
244
+
245
+
246
+
247
+
102
248
  notifyBridgeForceMessage(): Promise<void>;
103
249
 
250
+
251
+
252
+
253
+
254
+
255
+
256
+
257
+
258
+
259
+
260
+ fetchCurrentAction(): Promise<CurrentActionSnapshot | null>;
261
+
262
+
263
+
264
+
265
+
104
266
  private fetchDirectMessagesWithRecovery;
105
267
 
268
+
269
+
270
+
106
271
  private isRecoverableLongPollError;
107
272
 
273
+
274
+
275
+
108
276
  private normalizeGroupMessages;
109
277
 
278
+
279
+
110
280
  private collectRoomIds;
111
281
 
282
+
283
+
112
284
  getProfile(): Promise<ProfileInfo>;
113
285
  private getProfileByAgentId;
114
286
 
287
+
288
+
115
289
  getMyTasks(): Promise<unknown[]>;
116
290
 
291
+
292
+
293
+
117
294
  listTaskNodeIterations(args?: {
118
295
  offset?: number;
119
296
  limit?: number;
120
297
  nodeTemplateId?: string;
121
298
  }): Promise<unknown>;
122
299
 
300
+
301
+
302
+
123
303
  createTaskInstanceComment(args: TaskInstanceCommentArgs): Promise<unknown>;
124
304
 
305
+
306
+
307
+
308
+
309
+
125
310
  submitTaskResult(nodeId: string, outputPayload: string, changeLog?: unknown[] | string, handoverNote?: string, deliverables?: unknown[]): Promise<unknown>;
126
311
 
312
+
313
+
127
314
  startTaskRollback(args: StartTaskRollbackArgs): Promise<unknown>;
128
315
 
316
+
317
+
129
318
  finishTaskRollback(args: FinishTaskRollbackArgs): Promise<unknown>;
130
319
 
320
+
321
+
131
322
  getDebugLogConfig(): Promise<unknown>;
132
323
 
324
+
325
+
133
326
  queryDebugLogs(args: Record<string, unknown>): Promise<unknown>;
134
327
 
328
+
329
+
330
+
331
+
332
+
135
333
  queryFileChangesHistory(args: Record<string, unknown>): Promise<unknown>;
136
334
 
335
+
336
+
337
+
338
+
339
+
137
340
  listColleagueEvents(args: Record<string, unknown>): Promise<unknown>;
138
341
 
342
+
343
+
344
+
139
345
  getRuntimeFeatures(): Promise<Record<string, unknown>>;
140
346
 
347
+
348
+
141
349
  listLaunchConfigs(): Promise<unknown>;
142
350
 
351
+
352
+
353
+
143
354
  createLaunchConfig(args: Record<string, unknown>): Promise<unknown>;
144
355
 
356
+
357
+
358
+
145
359
  updateLaunchConfig(args: Record<string, unknown>): Promise<unknown>;
146
360
 
361
+
362
+
363
+
147
364
  deleteLaunchConfig(configId: string): Promise<unknown>;
148
365
 
366
+
367
+
368
+
369
+
370
+
149
371
  startLaunchConfig(args: Record<string, unknown>): Promise<unknown>;
150
372
 
373
+
374
+
375
+
151
376
  restartLaunchConfig(args: Record<string, unknown>): Promise<unknown>;
152
377
 
378
+
379
+
380
+
153
381
  stopLaunchConfig(configId: string): Promise<unknown>;
154
382
 
383
+
384
+
385
+
155
386
  getLaunchLogs(args: Record<string, unknown>): Promise<unknown>;
156
387
 
388
+
389
+
157
390
  listLaunchRuns(): Promise<unknown>;
158
391
 
392
+
393
+
394
+
395
+
159
396
  listAbilityMarket(args?: Record<string, unknown>): Promise<unknown>;
160
397
 
398
+
399
+
400
+
401
+
161
402
  installAbilityMarketItem(args: Record<string, unknown>): Promise<unknown>;
162
403
 
404
+
405
+
406
+
163
407
  uninstallAbilityMarketItem(args: Record<string, unknown>): Promise<unknown>;
164
408
 
409
+
410
+
411
+
412
+
413
+
414
+
165
415
  abilityDevIde(args: Record<string, unknown>): Promise<unknown>;
166
416
 
417
+
418
+
419
+
167
420
  formalAbility(args: Record<string, unknown>): Promise<unknown>;
168
421
 
422
+
423
+
424
+
169
425
  listMyAbilities(args?: Record<string, unknown>): Promise<unknown>;
170
426
 
427
+
428
+
171
429
  start(handler: MessageHandler, options?: {
172
430
  pollMode?: boolean;
173
431
  profileHandler?: ProfileHandler;
@@ -175,17 +433,24 @@ export declare class AgentClient {
175
433
  systemNotifyHandler?: SystemNotifyHandler;
176
434
  }): void;
177
435
 
436
+
437
+
178
438
  stop(): void;
179
439
  private messageLoop;
180
440
  private handleIncomingDm;
181
441
  private handleIncomingGroup;
182
442
  private handleIncomingMeeting;
183
443
 
444
+
445
+
446
+
184
447
  private handleProfileInfo;
185
448
  private processMessage;
186
449
  private ensureRegistered;
187
450
  private delay;
188
451
 
452
+
453
+
189
454
  onNewCharacter(handler: () => void): void;
190
455
  getState(): {
191
456
  agentId: string | null;
@@ -198,20 +463,42 @@ export declare class AgentClient {
198
463
  getServerConfig(): ServerConfig;
199
464
  reloadConfig(): void;
200
465
 
466
+
467
+
468
+
201
469
  enterDegradedMode(): void;
202
470
 
471
+
472
+
473
+
203
474
  exitDegradedMode(): void;
204
475
 
476
+
477
+
205
478
  isInDegradedMode(): boolean;
206
479
 
480
+
481
+
482
+
207
483
  retryRegistrationInBackground(retryIntervalMs: number, maxRetries: number): Promise<void>;
208
484
 
485
+
486
+
209
487
  private initializeStatusReporter;
210
488
 
489
+
490
+
491
+
492
+
211
493
  private startRuntimeTokenRefresh;
212
494
  private stopRuntimeTokenRefresh;
213
495
 
496
+
497
+
498
+
214
499
  private reportMcpNodeLog;
215
500
 
501
+
502
+
216
503
  getStatusReporter(): StatusReporter | null;
217
504
  }
@@ -1,2 +1,2 @@
1
- import{configManager as h}from"./config.js";import{MESSAGE_POLL_INTERVAL_MS as I}from"./constants.js";import{HttpClient as f}from"./http-client.js";import{logger as i,setMcpNodeLogSink as w,updateStartupLogIdentity as u}from"./logger.js";import{claimRuntimeLaunchBindingDetailed as m}from"./runtime-launch-binding.js";import{StatusReporter as A}from"./status-reporter.js";import{WebSocketClient as p}from"./websocket-client.js";class T extends Error{constructor(e){super(e),this.name="PollLongPollTimeoutError"}}const C=27e4;class N{wsClient;httpClient;agentConfig;serverConfig;agentId=null;displayName=null;projectId=null;isRunning=!1;isDegradedMode=!1;messageHandler=null;profileHandler=null;configHandler=null;systemNotifyHandler=null;pollTimer=null;statusReporter=null;newCharacterHandler=null;runtimeTokenRefreshTimer=null;pendingLaunchBindingClaim=!1;cachedProfile=null;constructor(){h.loadConfig(),this.agentConfig=h.getAgentConfig(),this.serverConfig=h.getServerConfig(),this.wsClient=new p(this.serverConfig),this.httpClient=new f(this.serverConfig),this.setupWebSocketListeners()}async initialize(){const e=await m(this.agentConfig,this.serverConfig);if(e.status==="claimed"){this.applyLaunchBinding(e.binding);return}if(e.status==="unreachable"){this.pendingLaunchBindingClaim=!0,i.warn("[AgentClient] runtime-bridge \u672A\u5C31\u7EEA\uFF0C\u542F\u52A8\u7ED1\u5B9A\u8BA4\u9886\u5DF2\u6302\u8D77\uFF0C\u5C06\u5728\u6CE8\u518C\u91CD\u8BD5\u4E2D\u91CD\u65B0\u8BA4\u9886: %s",e.message);return}this.serverConfig.runtimeBridgeBaseUrl=void 0}applyLaunchBinding(e){h.applyRuntimeLaunchBinding(e),this.agentConfig=h.getAgentConfig(),this.serverConfig=h.getServerConfig(),this.wsClient=new p(this.serverConfig),this.httpClient=new f(this.serverConfig),this.setupWebSocketListeners()}async retryPendingLaunchBindingClaim(){if(!this.pendingLaunchBindingClaim)return!0;const e=await m(this.agentConfig,this.serverConfig);if(e.status==="claimed")return this.pendingLaunchBindingClaim=!1,i.info("[AgentClient] \u542F\u52A8\u7ED1\u5B9A\u8865\u8BA4\u9886\u6210\u529F\uFF0C\u7EE7\u7EED\u6CE8\u518C\u6D41\u7A0B"),this.applyLaunchBinding(e.binding),!0;if(e.status==="missing")return this.pendingLaunchBindingClaim=!1,this.serverConfig.runtimeBridgeBaseUrl=void 0,i.warn("[AgentClient] \u542F\u52A8\u7ED1\u5B9A\u8865\u8BA4\u9886\u672A\u627E\u5230\u5F85\u8BA4\u9886\u8BB0\u5F55\uFF0C\u6309\u65E0\u7ED1\u5B9A\u6A21\u5F0F\u7EE7\u7EED\u6CE8\u518C"),!1;const t=e.status==="unreachable"?e.message:e.reason;return i.warn("[AgentClient] \u542F\u52A8\u7ED1\u5B9A\u8865\u8BA4\u9886\u5931\u8D25\uFF0C\u4FDD\u7559\u6302\u8D77\u72B6\u6001\u7B49\u5F85\u4E0B\u6B21\u6CE8\u518C\u91CD\u8BD5: %s",t),!1}setupWebSocketListeners(){this.wsClient.on("directMessage",e=>{this.handleIncomingDm(e)}),this.wsClient.on("groupMessage",e=>{this.handleIncomingGroup(e)}),this.wsClient.on("meetingMessage",e=>{this.handleIncomingMeeting(e)}),this.wsClient.on("systemNotify",e=>{this.systemNotifyHandler?.(e)}),this.wsClient.on("profileInfo",e=>{i.info(`[AgentClient] WebSocket profileInfo \u4E8B\u4EF6\u89E6\u53D1\uFF0CdisplayName: ${e.displayName}`),this.handleProfileInfo(e)}),this.wsClient.on("agentConfig",e=>{i.info("[AgentClient] WebSocket agentConfig \u4E8B\u4EF6\u89E6\u53D1"),this.configHandler&&this.configHandler(e??{})}),this.wsClient.on("agentStatus",e=>{i.info(`[AgentClient] WebSocket agentStatus \u4E8B\u4EF6\u89E6\u53D1: ${e.status}`)}),this.wsClient.on("disconnected",(e,t)=>{const n=t?.toString()||"";i.warn("[AgentClient] WebSocket \u65AD\u5F00\u8FDE\u63A5: code=%s, reason=%s, agentId=%s, \u6B63\u5728\u81EA\u52A8\u91CD\u8FDE",e,n,this.agentId)}),this.wsClient.on("error",e=>{i.error("[AgentClient] WebSocket \u9519\u8BEF: %s, stack=%s",e.message,e.stack)}),this.wsClient.on("reconnectFailed",()=>{i.error("[AgentClient] \u91CD\u8FDE\u5931\u8D25\uFF08\u5DF2\u8FBE\u91CD\u8BD5\u4E0A\u9650\uFF09\uFF0C\u505C\u6B62\u6D88\u606F\u5FAA\u73AF, agentId=%s",this.agentId),this.stop()}),this.wsClient.on("tokenRejected",()=>{i.error("[AgentClient] runtime token \u88AB 1008 \u62D2\u7EDD\u4E14\u5237\u65B0\u65E0\u53D8\u5316\uFF0C\u8FDB\u5165\u6162\u901F\u91CD\u8BD5\u7B49\u5F85\u65B0 token \u7B7E\u53D1: agentId=%s",this.agentId)}),this.wsClient.on("tokenRefreshFailed",e=>{i.error("[AgentClient] runtime token \u5237\u65B0\u8FDE\u7EED\u5931\u8D25 %s \u6B21\uFF0C\u8FDB\u5165\u6162\u901F\u91CD\u8BD5\u7B49\u5F85 bridge \u6062\u590D: agentId=%s",e,this.agentId)})}async register(){return i.info("[AgentClient] \u6B63\u5728\u6CE8\u518C Agent..."),await this.retryPendingLaunchBindingClaim(),this.hasPresetAgentId()?await this.registerWithExistingAgentId():await this.registerAsNewAgent()}hasPresetAgentId(){return!!(this.agentConfig.agentId&&this.agentConfig.agentId.trim().length>0)}async registerWithExistingAgentId(){const e=this.agentConfig.agentId;if(!e)throw new Error("Preset agentId is missing");this.agentId=e.trim();let t;try{t=await this.getProfileByAgentId(this.agentId)}catch(r){throw i.error("[AgentClient] getProfileByAgentId \u5931\u8D25 (presetAgentId=%s): %s",this.agentId,r instanceof Error?r.message:String(r)),r}this.displayName=t.displayName,this.projectId=t.projectId||null,i.info(`[AgentClient] \u4F7F\u7528\u9884\u8BBE AgentID \u7ED1\u5B9A\u5B9E\u4F8B: ${this.displayName} (${this.agentId})`),i.info(`[AgentClient] \u6240\u5C5E\u9879\u76EE: ${this.projectId||"(\u672A\u8BBE\u7F6E)"}`);try{await this.wsClient.connect(this.agentId)}catch(r){throw i.error("[AgentClient] WebSocket \u8FDE\u63A5\u5931\u8D25 (agentId=%s): %s",this.agentId,r instanceof Error?r.message:String(r)),r}i.info("[AgentClient] WebSocket \u8FDE\u63A5\u5DF2\u5EFA\u7ACB\uFF0CAgent \u73B0\u5728\u5DF2\u4E0A\u7EBF"),this.initializeStatusReporter();const n=await this.getProfileByAgentId(this.agentId);return this.displayName=n.displayName,this.projectId=n.projectId||null,u(n.roleName||"unknown-role",n.instanceName||this.agentId),{agentId:this.agentId,displayName:this.displayName,status:n.isOnline?"online":"offline",projectId:n.projectId,workspacePath:n.workspacePath,runtimeStatus:n.runtimeStatus,runtimeSessionId:n.runtimeSessionId}}async registerAsNewAgent(){const e=await this.httpClient.callTool("register",{roleName:this.agentConfig.roleName,projectId:this.agentConfig.projectId,workspacePath:this.agentConfig.workspacePath,prompt:this.agentConfig.prompt,runtimeBridgeBaseUrl:this.serverConfig.runtimeBridgeBaseUrl}),t=e.agentId;if(!t)throw new Error("Registration failed: agentId was not returned");return this.agentId=t,this.displayName=e.displayName,this.projectId=e.projectId||null,u(this.agentConfig.roleName||"unknown-role",e.instanceName||t),i.info(`[AgentClient] \u6CE8\u518C\u6210\u529F: ${this.displayName} (${this.agentId})`),i.info(`[AgentClient] \u72B6\u6001: ${e.status}`),i.info(`[AgentClient] \u6240\u5C5E\u9879\u76EE: ${this.projectId||"(\u672A\u8BBE\u7F6E)"}`),await this.wsClient.connect(this.agentId),i.info("[AgentClient] WebSocket \u8FDE\u63A5\u5DF2\u5EFA\u7ACB\uFF0CAgent \u73B0\u5728\u5DF2\u4E0A\u7EBF"),this.initializeStatusReporter(),e.isExisting===!1&&this.newCharacterHandler&&this.newCharacterHandler(),e}async unregister(){i.info("[AgentClient] \u6B63\u5728\u6CE8\u9500 Agent..."),this.agentId&&await this.httpClient.callTool("unregister",{agentId:this.agentId}),this.stopRuntimeTokenRefresh(),this.wsClient.disconnect(),this.agentId=null,this.displayName=null,this.projectId=null,this.isRunning=!1,i.info("[AgentClient] \u5DF2\u6CE8\u9500")}async discoverColleagues(){return await this.httpClient.callTool("discover_colleague",{agentId:this.agentId})}async discoverGroupRooms(){return this.ensureRegistered(),await this.httpClient.callTool("discover_group_rooms",{agentId:this.agentId})}async listProjectMembers(){return this.ensureRegistered(),await this.httpClient.callTool("list_project_members",{agentId:this.agentId})}async hireColleague(e){return this.ensureRegistered(),await this.httpClient.callTool("hire_colleague",{...e,agentId:this.agentId})}async callAgentScopedTool(e,t){this.ensureRegistered();const n={...t,agentId:this.agentId};if(e==="create_meeting"){const r=typeof t.waitTimeoutMs=="number"?t.waitTimeoutMs:Number.NaN,s=Number.isFinite(r)&&r>0?Math.min(r,C):C;return await this.httpClient.callToolOnce(e,{...n,waitTimeoutMs:s},0)}return await this.httpClient.callTool(e,n)}async reportMemoryStats(e){await this.callAgentScopedTool("report_memory_stats",{memoryStats:e})}async sendGroupMessage(e,t,n,r,s){this.ensureRegistered();const a=t||this.projectId||this.agentConfig.projectId;return await this.httpClient.callTool("send_group_message",{agentId:this.agentId,projectId:a,roomId:n,content:e,card:r,replyTo:s})}async sendDirectMessage(e,t,n=!1,r,s,a,c){this.ensureRegistered();const g={agentId:this.agentId,targetId:e,content:t,requireReply:n,waitReply:n,replyToCallId:r,card:a,replyTo:c};if(typeof s=="number"&&s>0&&(g.timeoutMs=s),n){const o=typeof s=="number"&&s>0?s+3e4:0;return await this.httpClient.callToolOnce("send_dm",g,o)}return await this.httpClient.callTool("send_dm",g)}async sendCallAndWaitReply(e,t,n=6e4){const r=await this.sendDirectMessage(e,t,!0,void 0,n);if(r.reply)return r.reply;throw new Error("No reply received for call-style direct message before timeout")}async replyToCall(e,t,n){return await this.sendDirectMessage(t,n,!1,e)}async sendEmail(e){return await this.callAgentScopedTool("send_email",e)}async listEmails(e){return await this.callAgentScopedTool("list_emails",e)}async readEmail(e){return await this.callAgentScopedTool("read_email",{mailId:e})}async replyEmail(e){return await this.callAgentScopedTool("reply_email",e)}async ackEmail(e){return await this.callAgentScopedTool("ack_email",{mailId:e})}async getDmHistory(e,t=50,n){this.ensureRegistered();const r={agentId:this.agentId,targetUserId:e,limit:t};return n&&(r.since=n),await this.httpClient.callTool("get_dm_history",r)}async getGroupHistory(e=50,t,n){if(this.ensureRegistered(),t){const o={projectId:this.projectId||this.agentConfig.projectId,roomId:t,limit:e};return n&&(o.since=n),await this.httpClient.callTool("get_group_history",o)}const r=await this.discoverGroupRooms(),s=this.projectId||this.agentConfig.projectId,a=this.collectRoomIds(r,s);if(a.length===0)return{messages:[],count:0};const g=(await Promise.all(a.map(async o=>{const l={projectId:s,roomId:o,limit:e};return n&&(l.since=n),await this.httpClient.callTool("get_group_history",l)}))).flatMap(o=>o.messages).sort((o,l)=>new Date(o.timestamp).getTime()-new Date(l.timestamp).getTime());return{messages:g,count:g.length}}async fetchUnreadMessages(e={}){this.ensureRegistered();const t=this.projectId||this.agentConfig.projectId,n={agentId:this.agentId,blockIfEmpty:e.blockIfEmpty??!1};e.since&&(n.since=e.since),e.blockTimeoutMs&&e.blockTimeoutMs>0&&(n.blockTimeoutMs=e.blockTimeoutMs),e.preemptiveJoinWaitMs!==void 0&&e.preemptiveJoinWaitMs!==null&&e.preemptiveJoinWaitMs>=0&&(n.preemptiveJoinWaitMs=e.preemptiveJoinWaitMs);const r=e.includePipelineTasks?"poll_message":"get_dm_messages";i.info("[AgentClient] fetchUnreadMessages \u5165\u53E3: tool=%s, blockIfEmpty=%s, blockTimeoutMs=%s, pollMessageTimeoutMs=%s, skipGroupMessages=%s, preemptiveJoinWaitMs=%s, agentId=%s",r,String(e.blockIfEmpty??!1),String(e.blockTimeoutMs??"-"),String(e.pollMessageTimeoutMs??"-"),String(e.skipGroupMessages??!1),String(e.preemptiveJoinWaitMs??"-"),this.agentId);const s=await this.fetchDirectMessagesWithRecovery(r,n,e.pollMessageTimeoutMs,e.propagatePollTimeout===!0);if(i.info("[AgentClient] fetchUnreadMessages \u79C1\u4FE1\u9636\u6BB5\u8FD4\u56DE: %s \u6761",Array.isArray(s.messages)?s.messages.length:0),e.skipGroupMessages)return i.info("[AgentClient] \u4F1A\u8BAE\u5FEB\u901F hydrate \u5DF2\u53D6\u5F97\u79C1\u4FE1\u54CD\u5E94\uFF0C\u8DF3\u8FC7\u7FA4\u804A\u53D1\u73B0\u5E76\u7ACB\u5373\u8FD4\u56DE: directMessages=%s",Array.isArray(s.messages)?s.messages.length:0),{directMessages:Array.isArray(s.messages)?s.messages:[],groupMessages:[]};let a;try{a=await this.discoverGroupRooms()}catch(o){i.warn("[AgentClient] \u53D1\u73B0\u7FA4\u623F\u95F4\u5931\u8D25\uFF0C\u672C\u6B21\u6309\u65E0\u7FA4\u6D88\u606F\u5904\u7406\uFF08\u5DF2\u53D6\u5230\u7684\u79C1\u4FE1\u4E0D\u53D7\u5F71\u54CD\uFF09: %s",o instanceof Error?o.message:String(o)),a={groups:[]}}const c=this.collectRoomIds(a,t),g=await Promise.all(c.map(async o=>{const l={agentId:this.agentId,projectId:t,roomId:o};e.since&&(l.since=e.since);try{return await this.httpClient.callTool("get_group_messages",l)}catch(d){return i.warn("[AgentClient] \u8DF3\u8FC7\u7FA4\u623F\u95F4\u672A\u8BFB\u8865\u62C9\u5931\u8D25: roomId=%s, error=%s",o,d instanceof Error?d.message:String(d)),{messages:[],currentReadPos:0,hasMore:!1}}}));return{directMessages:Array.isArray(s.messages)?s.messages:[],groupMessages:g.flatMap(o=>this.normalizeGroupMessages(o)).sort((o,l)=>new Date(o.timestamp).getTime()-new Date(l.timestamp).getTime())}}async markDmRead(e){if(e.length===0)return new Set;this.ensureRegistered();try{const t=await this.httpClient.callTool("mark_dm_read",{agentId:this.agentId,msgIds:e}),n=new Set(Array.isArray(t?.deliverableMsgIds)?t.deliverableMsgIds:[]),r=e.filter(s=>!n.has(s));return r.length>0?i.warn("[AgentClient] mark_dm_read \u786E\u8BA4\u540E\u5C06\u6709 %d \u6761\u6D88\u606F\u88AB\u4E22\u5F03\u4E0D\u4EA4\u4ED8: \u8BF7\u6C42=%s, \u53EF\u4EA4\u4ED8=%s, \u88AB\u4E22\u5F03=%s",r.length,JSON.stringify(e),JSON.stringify([...n]),JSON.stringify(r)):i.info("[AgentClient] mark_dm_read \u786E\u8BA4\u5B8C\u6210: %d \u6761\u5168\u90E8\u53EF\u4EA4\u4ED8",e.length),n}catch(t){throw i.warn("[AgentClient] mark_dm_read \u8BF7\u6C42\u5931\u8D25\uFF08\u5C06\u964D\u7EA7\u4E3A\u76F4\u63A5\u4EA4\u4ED8\uFF09: %s",t instanceof Error?t.message:String(t)),t}}async markGroupRead(e,t){if(t.length===0)return new Set;this.ensureRegistered();const n=await this.httpClient.callTool("mark_group_read",{agentId:this.agentId,roomId:e,msgIds:t});return new Set(Array.isArray(n?.deliverableMsgIds)?n.deliverableMsgIds:[])}async markNotificationRead(e){if(e.length!==0){this.ensureRegistered();try{await this.httpClient.callTool("mark_notification_read",{agentId:this.agentId,msgIds:e})}catch{}}}async markMeetingRead(e){if(e.length!==0){this.ensureRegistered();try{await this.httpClient.callTool("mark_meeting_read",{agentId:this.agentId,msgIds:e})}catch{}}}async fetchBrowserListenerEvents(){const e=this.serverConfig.runtimeBridgeBaseUrl,t=this.agentId;if(!e||!t)return i.info("[AgentClient] fetchBrowserListenerEvents \u8DF3\u8FC7: bridgeBaseUrl=%s, agentId=%s",e||"(\u7A7A)",t||"(\u7A7A)"),[];try{const n=`${e}/runtime/browser-listeners/${encodeURIComponent(t)}/events`,r=this.serverConfig.runtimeAccessToken||"";i.debug("[AgentClient] \u62C9\u53D6\u76D1\u542C\u5668\u4E8B\u4EF6: url=%s, tokenLen=%d",n,r.length);const s=await fetch(n,{method:"GET",headers:{"X-Runtime-Token":r},signal:AbortSignal.timeout(3e3)});if(!s.ok)return i.warn("[AgentClient] \u62C9\u53D6\u76D1\u542C\u5668\u4E8B\u4EF6\u5931\u8D25: HTTP %s, url=%s",s.status,n),[];const a=await s.json();return!a.ok||!Array.isArray(a.events)?(i.warn("[AgentClient] \u62C9\u53D6\u76D1\u542C\u5668\u4E8B\u4EF6\u54CD\u5E94\u5F02\u5E38: ok=%s, eventsType=%s",a.ok,Array.isArray(a.events)?"array":typeof a.events),[]):(i.debug("[AgentClient] \u62C9\u53D6\u76D1\u542C\u5668\u4E8B\u4EF6\u6210\u529F: %d \u6761\u4E8B\u4EF6",a.events.length),a.events)}catch(n){return i.warn("[AgentClient] \u62C9\u53D6\u76D1\u542C\u5668\u4E8B\u4EF6\u5F02\u5E38: %s",n instanceof Error?n.message:String(n)),[]}}async fetchPluginEvents(){const e=this.serverConfig.runtimeBridgeBaseUrl,t=this.agentId;if(!e||!t)return{revision:0,events:[]};try{const n=`${e}/runtime/plugin-events/${encodeURIComponent(t)}/events`,r=this.serverConfig.runtimeAccessToken||"",s=await fetch(n,{method:"GET",headers:{"X-Runtime-Token":r},signal:AbortSignal.timeout(3e3)});if(!s.ok)return i.warn("[AgentClient] \u62C9\u53D6\u63D2\u4EF6\u4E8B\u4EF6\u5931\u8D25: HTTP %s, url=%s",s.status,n),{revision:0,events:[]};const a=await s.json();return!a.ok||!Array.isArray(a.events)?(i.warn("[AgentClient] \u62C9\u53D6\u63D2\u4EF6\u4E8B\u4EF6\u54CD\u5E94\u5F02\u5E38: ok=%s",String(a.ok)),{revision:0,events:[]}):(i.debug("[AgentClient] \u62C9\u53D6\u63D2\u4EF6\u4E8B\u4EF6\u6210\u529F: %d \u6761\u4E8B\u4EF6, revision=%s",a.events.length,String(a.revision??0)),{revision:a.revision??0,events:a.events})}catch(n){return i.warn("[AgentClient] \u62C9\u53D6\u63D2\u4EF6\u4E8B\u4EF6\u5F02\u5E38: %s",n instanceof Error?n.message:String(n)),{revision:0,events:[]}}}async notifyBridgeForceMessage(){const e=this.serverConfig.runtimeBridgeBaseUrl,t=this.agentId;if(!(!e||!t))try{const n=`${e}/runtime/sessions/${encodeURIComponent(t)}/notify-force-message`,r=this.serverConfig.runtimeAccessToken||"",s=await fetch(n,{method:"POST",headers:{"X-Runtime-Token":r},signal:AbortSignal.timeout(3e3)});s.ok||i.warn("[AgentClient] \u901A\u77E5 bridge \u5F3A\u5236\u6D88\u606F\u5931\u8D25: HTTP %s, url=%s",s.status,n)}catch(n){i.warn("[AgentClient] \u901A\u77E5 bridge \u5F3A\u5236\u6D88\u606F\u5F02\u5E38: %s",n instanceof Error?n.message:String(n))}}async fetchDirectMessagesWithRecovery(e,t,n,r=!1){if(e==="poll_message"){i.info("[AgentClient] fetchDirectMessagesWithRecovery \u5165\u53E3: tool=poll_message, pollMessageTimeoutMs=%s, agentId=%s",String(n??"(\u9ED8\u8BA4)"),String(t?.agentId??""));try{const s=await this.httpClient.callToolOnce(e,t,n);return i.info("[AgentClient] fetchDirectMessagesWithRecovery poll_message \u6210\u529F\u8FD4\u56DE: %s \u6761",Array.isArray(s?.messages)?s.messages.length:0),s}catch(s){if(this.isRecoverableLongPollError(s)){if(r)throw new T(s instanceof Error?s.message:String(s));return i.warn("[AgentClient] poll_message \u5355\u6B21\u957F\u8F6E\u8BE2\u8D85\u65F6\uFF0C\u6309\u7A7A\u7ED3\u679C\u9000\u907F\u540E\u7EE7\u7EED\u7B49\u5F85:",s),{messages:[]}}throw s}}return await this.httpClient.callTool(e,t)}isRecoverableLongPollError(e){return e instanceof Error?/MCP tool poll_message call failed: 503(?:\s|$)/.test(e.message)||/MCP tool poll_message timed out after \d+ms/.test(e.message):!1}normalizeGroupMessages(e){return Array.isArray(e.messages)?e.messages.filter(t=>!!(t&&typeof t=="object"&&typeof t.msgId=="number"&&typeof t.senderId=="string"&&typeof t.content=="string"&&typeof t.timestamp=="string")):[]}collectRoomIds(e,t){const n=e.groups.filter(r=>r.projectId===t).map(r=>r.id);return Array.from(new Set(n))}async getProfile(){this.ensureRegistered();const e=this.agentId;if(!e)throw new Error("Agent is not registered");return{...await this.getProfileByAgentId(e),describe:this.agentConfig.describe}}async getProfileByAgentId(e){return await this.httpClient.callTool("get_profile",{agentId:e})}async getMyTasks(){return this.ensureRegistered(),await this.httpClient.callTool("my_task",{agentId:this.agentId})}async listTaskNodeIterations(e={}){return this.ensureRegistered(),await this.httpClient.callTool("list_task_node_iterations",{agentId:this.agentId,...e})}async createTaskInstanceComment(e){this.ensureRegistered();const t={agentId:this.agentId,...e};return await this.httpClient.callTool("create_task_instance_comment",t)}async submitTaskResult(e,t,n,r,s){this.ensureRegistered();const a={agentId:this.agentId,nodeId:e,outputPayload:t};return(Array.isArray(n)&&n.length>0||typeof n=="string"&&n.trim().length>0)&&(a.changeLog=n),typeof r=="string"&&r.trim().length>0&&(a.handoverNote=r),s&&Array.isArray(s)&&s.length>0&&(a.deliverables=s),await this.httpClient.callTool("submit_task_result",a)}async startTaskRollback(e){return this.ensureRegistered(),await this.httpClient.callTool("start_task_rollback",{agentId:this.agentId,...e})}async finishTaskRollback(e){return this.ensureRegistered(),await this.httpClient.callTool("finish_task_rollback",{agentId:this.agentId,...e})}async getDebugLogConfig(){return await this.httpClient.callTool("get_debug_log_config",{agentId:this.agentId})}async queryDebugLogs(e){return this.ensureRegistered(),await this.httpClient.callTool("query_debug_logs",{...e})}async queryFileChangesHistory(e){return this.ensureRegistered(),await this.httpClient.callTool("query_file_changes_history",{...e})}async listColleagueEvents(e){return this.ensureRegistered(),await this.httpClient.callTool("list_colleague_events",{...e})}async getRuntimeFeatures(){return await this.httpClient.fetchRuntimeFeatures()}async listLaunchConfigs(){return this.ensureRegistered(),await this.httpClient.callTool("launch_config_list",{})}async createLaunchConfig(e){return this.ensureRegistered(),await this.httpClient.callTool("launch_config_create",{...e})}async updateLaunchConfig(e){return this.ensureRegistered(),await this.httpClient.callTool("launch_config_update",{...e})}async deleteLaunchConfig(e){return this.ensureRegistered(),await this.httpClient.callTool("launch_config_delete",{configId:e})}async startLaunchConfig(e){this.ensureRegistered();const t=Math.max(0,Math.min(3e5,Number(e.wait_timeout_ms)||0));return t>0?await this.httpClient.callToolOnce("launch_config_start",e,t+6e4):await this.httpClient.callTool("launch_config_start",{...e})}async restartLaunchConfig(e){this.ensureRegistered();const t=Math.max(0,Math.min(3e5,Number(e.wait_timeout_ms)||0));return t>0?await this.httpClient.callToolOnce("launch_config_restart",e,t+6e4):await this.httpClient.callTool("launch_config_restart",{...e})}async stopLaunchConfig(e){return this.ensureRegistered(),await this.httpClient.callTool("launch_config_stop",{configId:e})}async getLaunchLogs(e){return this.ensureRegistered(),await this.httpClient.callTool("launch_config_logs",{...e})}async listLaunchRuns(){return this.ensureRegistered(),await this.httpClient.callTool("launch_config_status",{})}async listAbilityMarket(e={}){return this.ensureRegistered(),await this.httpClient.callTool("list_ability_market",{...e})}async installAbilityMarketItem(e){return this.ensureRegistered(),await this.httpClient.callTool("install_ability_market_item",{...e})}async uninstallAbilityMarketItem(e){return this.ensureRegistered(),await this.httpClient.callTool("uninstall_ability_market_item",{...e})}async abilityDevIde(e){return this.ensureRegistered(),await this.httpClient.callTool("ability_dev_ide",{...e})}async formalAbility(e){return this.ensureRegistered(),await this.httpClient.callTool("formal_ability",{...e})}async listMyAbilities(e={}){return this.ensureRegistered(),await this.httpClient.callTool("list_my_abilities",{...e})}start(e,t){if(this.isRunning){i.warn("[AgentClient] \u6D88\u606F\u5FAA\u73AF\u5DF2\u5728\u8FD0\u884C\u4E2D");return}this.isDegradedMode||this.ensureRegistered(),this.messageHandler=e,this.profileHandler=t?.profileHandler||null,this.configHandler=t?.configHandler||null,this.systemNotifyHandler=t?.systemNotifyHandler||null,this.isRunning=!0,i.info(`[AgentClient] start() \u88AB\u8C03\u7528\uFF0CcachedProfile: ${this.cachedProfile?"\u5B58\u5728":"\u4E0D\u5B58\u5728"}, profileHandler: ${this.profileHandler?"\u5DF2\u8BBE\u7F6E":"\u672A\u8BBE\u7F6E"}, \u964D\u7EA7\u6A21\u5F0F: ${this.isDegradedMode?"\u662F":"\u5426"}`),this.cachedProfile&&this.profileHandler&&(i.info(`[AgentClient] \u5904\u7406\u7F13\u5B58\u7684 Profile \u4FE1\u606F: ${this.cachedProfile.displayName}`),this.profileHandler(this.cachedProfile),this.cachedProfile=null),t?.pollMode??!1?(i.warn("[AgentClient] \u542F\u52A8\u6D88\u606F\u4E3B\u5FAA\u73AF\uFF08HTTP\u8F6E\u8BE2\u6A21\u5F0F - \u4E0D\u63A8\u8350\uFF09"),this.messageLoop()):i.info("[AgentClient] \u542F\u52A8\u6D88\u606F\u4E3B\u5FAA\u73AF\uFF08WebSocket\u63A8\u9001\u6A21\u5F0F - \u63A8\u8350\uFF09")}stop(){this.isRunning=!1,this.pollTimer&&(clearTimeout(this.pollTimer),this.pollTimer=null),this.stopRuntimeTokenRefresh(),i.info("[AgentClient] \u6D88\u606F\u4E3B\u5FAA\u73AF\u5DF2\u505C\u6B62")}async messageLoop(){for(;this.isRunning;)try{await this.delay(I)}catch(e){i.error("[AgentClient] \u6D88\u606F\u5FAA\u73AF\u9519\u8BEF:",e),await this.delay(5e3)}}handleIncomingDm(e){e.senderId!==this.agentId&&this.processMessage(e)}handleIncomingGroup(e){e.senderId!==this.agentId&&this.processMessage(e)}handleIncomingMeeting(e){!e||e.senderId===this.agentId||this.processMessage(e)}handleProfileInfo(e){i.info(`[AgentClient] \u6536\u5230 Profile \u4FE1\u606F: ${e.displayName} (${e.roleName})`),e.projectId&&(this.projectId=e.projectId,i.info(`[AgentClient] \u66F4\u65B0\u6240\u5C5E\u9879\u76EE: ${this.projectId}`)),e.roleName&&e.roleName!==this.agentConfig.roleName&&(i.info(`[AgentClient] \u540C\u6B65\u89D2\u8272\u540D: "${this.agentConfig.roleName||"(\u7A7A)"}" -> "${e.roleName}"`),this.agentConfig.roleName=e.roleName),e.roleName&&u(e.roleName,e.instanceName||this.agentId||""),this.profileHandler?this.profileHandler(e):(i.info("[AgentClient] profileHandler \u672A\u8BBE\u7F6E\uFF0C\u7F13\u5B58 Profile \u4FE1\u606F"),this.cachedProfile=e)}async processMessage(e){if(!this.messageHandler)return;const t=typeof e.msgId=="string";i.info(`[AgentClient] \u6536\u5230${t?"\u79C1\u4FE1":"\u7FA4\u6D88\u606F"}\u6765\u81EA ${e.senderName}: ${e.content.substring(0,50)}...`);try{const n=await this.messageHandler(e);if(t){const r=e;r.requireReply&&r.callId&&await this.replyToCall(r.callId,r.senderId,n||"\u5DF2\u6536\u5230\u6D88\u606F\uFF0C\u6B63\u5728\u5904\u7406\u4E2D...")}}catch(n){const r=typeof e.msgId=="string";if(i.error("[AgentClient] \u5904\u7406\u6D88\u606F\u5931\u8D25: type=%s, senderId=%s, senderName=%s, msgId=%s, error=%s",r?"\u79C1\u4FE1":"\u7FA4\u6D88\u606F",e.senderId,e.senderName,e.msgId,n instanceof Error?n.message:String(n)),r){const s=e;s.requireReply&&s.callId&&await this.replyToCall(s.callId,s.senderId,`\u5904\u7406\u5931\u8D25: ${n}`)}}}ensureRegistered(){if(!this.agentId)throw new Error("Agent is not registered")}delay(e){return new Promise(t=>{this.pollTimer=setTimeout(t,e)})}onNewCharacter(e){this.newCharacterHandler=e}getState(){return{agentId:this.agentId,displayName:this.displayName,projectId:this.projectId,isConnected:this.wsClient.isConnected(),isRunning:this.isRunning}}getAgentConfig(){return this.agentConfig}getServerConfig(){return this.serverConfig}reloadConfig(){h.loadConfig(),this.agentConfig=h.getAgentConfig(),i.info(`[AgentClient] \u914D\u7F6E\u5DF2\u91CD\u65B0\u52A0\u8F7D\uFF0C\u89D2\u8272: ${this.agentConfig.roleName}`)}enterDegradedMode(){this.isDegradedMode=!0,i.warn("[AgentClient] \u8FDB\u5165\u964D\u7EA7\u6A21\u5F0F\uFF0C\u5C06\u5728\u540E\u53F0\u6301\u7EED\u5C1D\u8BD5\u91CD\u8FDE")}exitDegradedMode(){this.isDegradedMode=!1,i.info("[AgentClient] \u9000\u51FA\u964D\u7EA7\u6A21\u5F0F")}isInDegradedMode(){return this.isDegradedMode}async retryRegistrationInBackground(e,t){let n=0;(async()=>{for(;this.isDegradedMode;)try{i.info(`[AgentClient] \u964D\u7EA7\u6A21\u5F0F\uFF1A\u5C1D\u8BD5\u91CD\u65B0\u6CE8\u518C (${n+1}/${t===-1?"\u65E0\u9650":t})`);const s=await this.register();i.info(`[AgentClient] \u964D\u7EA7\u6A21\u5F0F\uFF1A\u6CE8\u518C\u6210\u529F - ${s.displayName} (${s.agentId})`),this.exitDegradedMode(),this.messageHandler&&this.start(this.messageHandler);return}catch(s){n++;const a=s instanceof Error?s.message:String(s);if(i.warn(`[AgentClient] \u964D\u7EA7\u6A21\u5F0F\uFF1A\u6CE8\u518C\u5931\u8D25 (${n}/${t===-1?"\u65E0\u9650":t}): ${a}`),t>0&&n>=t){i.error("[AgentClient] \u964D\u7EA7\u6A21\u5F0F\uFF1A\u8FBE\u5230\u6700\u5927\u91CD\u8BD5\u6B21\u6570\uFF0C\u505C\u6B62\u91CD\u8FDE"),this.isDegradedMode=!1;return}await new Promise(c=>setTimeout(c,e))}})().catch(s=>{i.error("[AgentClient] \u964D\u7EA7\u6A21\u5F0F\u540E\u53F0\u91CD\u8BD5\u5FAA\u73AF\u5F02\u5E38\u9000\u51FA: error=%s, stack=%s",s instanceof Error?s.message:String(s),s instanceof Error?s.stack:"(no stack)")})}initializeStatusReporter(){if(!this.agentId){i.warn("[AgentClient] \u65E0\u6CD5\u521D\u59CB\u5316\u72B6\u6001\u62A5\u544A\u5668\uFF1AagentId \u4E3A\u7A7A");return}this.statusReporter=new A({agentId:this.agentId,sendStatusUpdate:e=>{this.wsClient.send({type:"AGENT_STATUS",data:e,timestamp:new Date().toISOString()})}}),w(e=>this.reportMcpNodeLog(e)),this.startRuntimeTokenRefresh(),i.info("[AgentClient] \u72B6\u6001\u62A5\u544A\u5668\u5DF2\u521D\u59CB\u5316")}startRuntimeTokenRefresh(){this.stopRuntimeTokenRefresh();const e=this.serverConfig.runtimeTokenRefreshIntervalMs;if(!e||e<=0){i.warn("[AgentClient] runtimeTokenRefreshIntervalMs \u672A\u914D\u7F6E\u6216\u65E0\u6548\uFF0C\u8DF3\u8FC7\u4E3B\u52A8\u7EED\u671F");return}const t=this.agentId;if(!t){i.warn("[AgentClient] agentId \u4E3A\u7A7A\uFF0C\u8DF3\u8FC7\u4E3B\u52A8\u7EED\u671F");return}this.runtimeTokenRefreshTimer=setInterval(async()=>{try{await this.httpClient.refreshRuntimeAccessToken(t)&&i.info("[AgentClient] runtimeAccessToken \u5DF2\u4E3B\u52A8\u7EED\u671F")}catch(n){i.warn("[AgentClient] \u4E3B\u52A8\u7EED\u671F runtimeAccessToken \u5931\u8D25: %s",n instanceof Error?n.message:String(n)),n instanceof Error&&n.stack&&i.warn("[AgentClient] \u4E3B\u52A8\u7EED\u671F\u5F02\u5E38\u5806\u6808:",n.stack)}},e),this.runtimeTokenRefreshTimer.unref?.(),i.info(`[AgentClient] runtime token \u4E3B\u52A8\u7EED\u671F\u5DF2\u542F\u52A8\uFF0C\u95F4\u9694 ${e}ms`)}stopRuntimeTokenRefresh(){this.runtimeTokenRefreshTimer&&(clearInterval(this.runtimeTokenRefreshTimer),this.runtimeTokenRefreshTimer=null)}reportMcpNodeLog(e){const t=this.wsClient;!this.agentId||!this.wsClient.isConnected()||typeof t.sendMcpNodeLog!="function"||t.sendMcpNodeLog(e)}getStatusReporter(){return this.statusReporter}}export{N as AgentClient,T as PollLongPollTimeoutError};
1
+ import{configManager as h}from"./config.js";import{MESSAGE_POLL_INTERVAL_MS as I}from"./constants.js";import{HttpClient as f}from"./http-client.js";import{logger as i,setMcpNodeLogSink as w,updateStartupLogIdentity as u}from"./logger.js";import{claimRuntimeLaunchBindingDetailed as m}from"./runtime-launch-binding.js";import{StatusReporter as A}from"./status-reporter.js";import{WebSocketClient as p}from"./websocket-client.js";class T extends Error{constructor(e){super(e),this.name="PollLongPollTimeoutError"}}const C=27e4;class N{wsClient;httpClient;agentConfig;serverConfig;agentId=null;displayName=null;projectId=null;isRunning=!1;isDegradedMode=!1;messageHandler=null;profileHandler=null;configHandler=null;systemNotifyHandler=null;pollTimer=null;statusReporter=null;newCharacterHandler=null;runtimeTokenRefreshTimer=null;pendingLaunchBindingClaim=!1;cachedProfile=null;constructor(){h.loadConfig(),this.agentConfig=h.getAgentConfig(),this.serverConfig=h.getServerConfig(),this.wsClient=new p(this.serverConfig),this.httpClient=new f(this.serverConfig),this.setupWebSocketListeners()}async initialize(){const e=await m(this.agentConfig,this.serverConfig);if(e.status==="claimed"){this.applyLaunchBinding(e.binding);return}if(e.status==="unreachable"){this.pendingLaunchBindingClaim=!0,i.warn("[AgentClient] runtime-bridge \u672A\u5C31\u7EEA\uFF0C\u542F\u52A8\u7ED1\u5B9A\u8BA4\u9886\u5DF2\u6302\u8D77\uFF0C\u5C06\u5728\u6CE8\u518C\u91CD\u8BD5\u4E2D\u91CD\u65B0\u8BA4\u9886: %s",e.message);return}this.serverConfig.runtimeBridgeBaseUrl=void 0}applyLaunchBinding(e){h.applyRuntimeLaunchBinding(e),this.agentConfig=h.getAgentConfig(),this.serverConfig=h.getServerConfig(),this.wsClient=new p(this.serverConfig),this.httpClient=new f(this.serverConfig),this.setupWebSocketListeners()}async retryPendingLaunchBindingClaim(){if(!this.pendingLaunchBindingClaim)return!0;const e=await m(this.agentConfig,this.serverConfig);if(e.status==="claimed")return this.pendingLaunchBindingClaim=!1,i.info("[AgentClient] \u542F\u52A8\u7ED1\u5B9A\u8865\u8BA4\u9886\u6210\u529F\uFF0C\u7EE7\u7EED\u6CE8\u518C\u6D41\u7A0B"),this.applyLaunchBinding(e.binding),!0;if(e.status==="missing")return this.pendingLaunchBindingClaim=!1,this.serverConfig.runtimeBridgeBaseUrl=void 0,i.warn("[AgentClient] \u542F\u52A8\u7ED1\u5B9A\u8865\u8BA4\u9886\u672A\u627E\u5230\u5F85\u8BA4\u9886\u8BB0\u5F55\uFF0C\u6309\u65E0\u7ED1\u5B9A\u6A21\u5F0F\u7EE7\u7EED\u6CE8\u518C"),!1;const t=e.status==="unreachable"?e.message:e.reason;return i.warn("[AgentClient] \u542F\u52A8\u7ED1\u5B9A\u8865\u8BA4\u9886\u5931\u8D25\uFF0C\u4FDD\u7559\u6302\u8D77\u72B6\u6001\u7B49\u5F85\u4E0B\u6B21\u6CE8\u518C\u91CD\u8BD5: %s",t),!1}setupWebSocketListeners(){this.wsClient.on("directMessage",e=>{this.handleIncomingDm(e)}),this.wsClient.on("groupMessage",e=>{this.handleIncomingGroup(e)}),this.wsClient.on("meetingMessage",e=>{this.handleIncomingMeeting(e)}),this.wsClient.on("systemNotify",e=>{this.systemNotifyHandler?.(e)}),this.wsClient.on("profileInfo",e=>{i.info(`[AgentClient] WebSocket profileInfo \u4E8B\u4EF6\u89E6\u53D1\uFF0CdisplayName: ${e.displayName}`),this.handleProfileInfo(e)}),this.wsClient.on("agentConfig",e=>{i.info("[AgentClient] WebSocket agentConfig \u4E8B\u4EF6\u89E6\u53D1"),this.configHandler&&this.configHandler(e??{})}),this.wsClient.on("agentStatus",e=>{i.info(`[AgentClient] WebSocket agentStatus \u4E8B\u4EF6\u89E6\u53D1: ${e.status}`)}),this.wsClient.on("disconnected",(e,t)=>{const n=t?.toString()||"";i.warn("[AgentClient] WebSocket \u65AD\u5F00\u8FDE\u63A5: code=%s, reason=%s, agentId=%s, \u6B63\u5728\u81EA\u52A8\u91CD\u8FDE",e,n,this.agentId)}),this.wsClient.on("error",e=>{i.error("[AgentClient] WebSocket \u9519\u8BEF: %s, stack=%s",e.message,e.stack)}),this.wsClient.on("reconnectFailed",()=>{i.error("[AgentClient] \u91CD\u8FDE\u5931\u8D25\uFF08\u5DF2\u8FBE\u91CD\u8BD5\u4E0A\u9650\uFF09\uFF0C\u505C\u6B62\u6D88\u606F\u5FAA\u73AF, agentId=%s",this.agentId),this.stop()}),this.wsClient.on("tokenRejected",()=>{i.error("[AgentClient] runtime token \u88AB 1008 \u62D2\u7EDD\u4E14\u5237\u65B0\u65E0\u53D8\u5316\uFF0C\u8FDB\u5165\u6162\u901F\u91CD\u8BD5\u7B49\u5F85\u65B0 token \u7B7E\u53D1: agentId=%s",this.agentId)}),this.wsClient.on("tokenRefreshFailed",e=>{i.error("[AgentClient] runtime token \u5237\u65B0\u8FDE\u7EED\u5931\u8D25 %s \u6B21\uFF0C\u8FDB\u5165\u6162\u901F\u91CD\u8BD5\u7B49\u5F85 bridge \u6062\u590D: agentId=%s",e,this.agentId)})}async register(){return i.info("[AgentClient] \u6B63\u5728\u6CE8\u518C Agent..."),await this.retryPendingLaunchBindingClaim(),this.hasPresetAgentId()?await this.registerWithExistingAgentId():await this.registerAsNewAgent()}hasPresetAgentId(){return!!(this.agentConfig.agentId&&this.agentConfig.agentId.trim().length>0)}async registerWithExistingAgentId(){const e=this.agentConfig.agentId;if(!e)throw new Error("Preset agentId is missing");this.agentId=e.trim();let t;try{t=await this.getProfileByAgentId(this.agentId)}catch(r){throw i.error("[AgentClient] getProfileByAgentId \u5931\u8D25 (presetAgentId=%s): %s",this.agentId,r instanceof Error?r.message:String(r)),r}this.displayName=t.displayName,this.projectId=t.projectId||null,i.info(`[AgentClient] \u4F7F\u7528\u9884\u8BBE AgentID \u7ED1\u5B9A\u5B9E\u4F8B: ${this.displayName} (${this.agentId})`),i.info(`[AgentClient] \u6240\u5C5E\u9879\u76EE: ${this.projectId||"(\u672A\u8BBE\u7F6E)"}`);try{await this.wsClient.connect(this.agentId)}catch(r){throw i.error("[AgentClient] WebSocket \u8FDE\u63A5\u5931\u8D25 (agentId=%s): %s",this.agentId,r instanceof Error?r.message:String(r)),r}i.info("[AgentClient] WebSocket \u8FDE\u63A5\u5DF2\u5EFA\u7ACB\uFF0CAgent \u73B0\u5728\u5DF2\u4E0A\u7EBF"),this.initializeStatusReporter();const n=await this.getProfileByAgentId(this.agentId);return this.displayName=n.displayName,this.projectId=n.projectId||null,u(n.roleName||"unknown-role",n.instanceName||this.agentId),{agentId:this.agentId,displayName:this.displayName,status:n.isOnline?"online":"offline",projectId:n.projectId,workspacePath:n.workspacePath,runtimeStatus:n.runtimeStatus,runtimeSessionId:n.runtimeSessionId}}async registerAsNewAgent(){const e=await this.httpClient.callTool("register",{roleName:this.agentConfig.roleName,projectId:this.agentConfig.projectId,workspacePath:this.agentConfig.workspacePath,prompt:this.agentConfig.prompt,runtimeBridgeBaseUrl:this.serverConfig.runtimeBridgeBaseUrl}),t=e.agentId;if(!t)throw new Error("Registration failed: agentId was not returned");return this.agentId=t,this.displayName=e.displayName,this.projectId=e.projectId||null,u(this.agentConfig.roleName||"unknown-role",e.instanceName||t),i.info(`[AgentClient] \u6CE8\u518C\u6210\u529F: ${this.displayName} (${this.agentId})`),i.info(`[AgentClient] \u72B6\u6001: ${e.status}`),i.info(`[AgentClient] \u6240\u5C5E\u9879\u76EE: ${this.projectId||"(\u672A\u8BBE\u7F6E)"}`),await this.wsClient.connect(this.agentId),i.info("[AgentClient] WebSocket \u8FDE\u63A5\u5DF2\u5EFA\u7ACB\uFF0CAgent \u73B0\u5728\u5DF2\u4E0A\u7EBF"),this.initializeStatusReporter(),e.isExisting===!1&&this.newCharacterHandler&&this.newCharacterHandler(),e}async unregister(){i.info("[AgentClient] \u6B63\u5728\u6CE8\u9500 Agent..."),this.agentId&&await this.httpClient.callTool("unregister",{agentId:this.agentId}),this.stopRuntimeTokenRefresh(),this.wsClient.disconnect(),this.agentId=null,this.displayName=null,this.projectId=null,this.isRunning=!1,i.info("[AgentClient] \u5DF2\u6CE8\u9500")}async discoverColleagues(){return await this.httpClient.callTool("discover_colleague",{agentId:this.agentId})}async discoverGroupRooms(){return this.ensureRegistered(),await this.httpClient.callTool("discover_group_rooms",{agentId:this.agentId})}async listProjectMembers(){return this.ensureRegistered(),await this.httpClient.callTool("list_project_members",{agentId:this.agentId})}async hireColleague(e){return this.ensureRegistered(),await this.httpClient.callTool("hire_colleague",{...e,agentId:this.agentId})}async callAgentScopedTool(e,t){this.ensureRegistered();const n={...t,agentId:this.agentId};if(e==="create_meeting"){const r=typeof t.waitTimeoutMs=="number"?t.waitTimeoutMs:Number.NaN,s=Number.isFinite(r)&&r>0?Math.min(r,C):C;return await this.httpClient.callToolOnce(e,{...n,waitTimeoutMs:s},0)}return await this.httpClient.callTool(e,n)}async reportMemoryStats(e){await this.callAgentScopedTool("report_memory_stats",{memoryStats:e})}async sendGroupMessage(e,t,n,r,s,a){this.ensureRegistered();const c=t||this.projectId||this.agentConfig.projectId;return await this.httpClient.callTool("send_group_message",{agentId:this.agentId,projectId:c,roomId:n,content:e,card:r,replyTo:s,...a?{voice:a}:{}})}async sendDirectMessage(e,t,n=!1,r,s,a,c,g,o){this.ensureRegistered();const l={agentId:this.agentId,targetId:e,content:t,requireReply:n,waitReply:n,replyToCallId:r,card:a,replyTo:c};if(typeof s=="number"&&s>0&&(l.timeoutMs=s),g?.priority&&g.priority!=="normal"&&(l.priority=g.priority,l.force=g.priority==="force",g.intent&&(l.intent=g.intent),g.ref&&(l.ref=g.ref),g.reason&&(l.reason=g.reason)),o&&(l.voice=o),n){const d=typeof s=="number"&&s>0?s+3e4:0;return await this.httpClient.callToolOnce("send_dm",l,d)}return await this.httpClient.callTool("send_dm",l)}async sendCallAndWaitReply(e,t,n=6e4){const r=await this.sendDirectMessage(e,t,!0,void 0,n);if(r.reply)return r.reply;throw new Error("No reply received for call-style direct message before timeout")}async replyToCall(e,t,n){return await this.sendDirectMessage(t,n,!1,e)}async sendEmail(e){return await this.callAgentScopedTool("send_email",e)}async listEmails(e){return await this.callAgentScopedTool("list_emails",e)}async readEmail(e){return await this.callAgentScopedTool("read_email",{mailId:e})}async replyEmail(e){return await this.callAgentScopedTool("reply_email",e)}async ackEmail(e){return await this.callAgentScopedTool("ack_email",{mailId:e})}async getDmHistory(e,t=50,n){this.ensureRegistered();const r={agentId:this.agentId,targetUserId:e,limit:t};return n&&(r.since=n),await this.httpClient.callTool("get_dm_history",r)}async getGroupHistory(e=50,t,n){if(this.ensureRegistered(),t){const o={projectId:this.projectId||this.agentConfig.projectId,roomId:t,limit:e};return n&&(o.since=n),await this.httpClient.callTool("get_group_history",o)}const r=await this.discoverGroupRooms(),s=this.projectId||this.agentConfig.projectId,a=this.collectRoomIds(r,s);if(a.length===0)return{messages:[],count:0};const g=(await Promise.all(a.map(async o=>{const l={projectId:s,roomId:o,limit:e};return n&&(l.since=n),await this.httpClient.callTool("get_group_history",l)}))).flatMap(o=>o.messages).sort((o,l)=>new Date(o.timestamp).getTime()-new Date(l.timestamp).getTime());return{messages:g,count:g.length}}async fetchUnreadMessages(e={}){this.ensureRegistered();const t=this.projectId||this.agentConfig.projectId,n={agentId:this.agentId,blockIfEmpty:e.blockIfEmpty??!1};e.since&&(n.since=e.since),e.blockTimeoutMs&&e.blockTimeoutMs>0&&(n.blockTimeoutMs=e.blockTimeoutMs),e.preemptiveJoinWaitMs!==void 0&&e.preemptiveJoinWaitMs!==null&&e.preemptiveJoinWaitMs>=0&&(n.preemptiveJoinWaitMs=e.preemptiveJoinWaitMs);const r=e.includePipelineTasks?"poll_message":"get_dm_messages";i.info("[AgentClient] fetchUnreadMessages \u5165\u53E3: tool=%s, blockIfEmpty=%s, blockTimeoutMs=%s, pollMessageTimeoutMs=%s, skipGroupMessages=%s, preemptiveJoinWaitMs=%s, agentId=%s",r,String(e.blockIfEmpty??!1),String(e.blockTimeoutMs??"-"),String(e.pollMessageTimeoutMs??"-"),String(e.skipGroupMessages??!1),String(e.preemptiveJoinWaitMs??"-"),this.agentId);const s=await this.fetchDirectMessagesWithRecovery(r,n,e.pollMessageTimeoutMs,e.propagatePollTimeout===!0);if(i.info("[AgentClient] fetchUnreadMessages \u79C1\u4FE1\u9636\u6BB5\u8FD4\u56DE: %s \u6761",Array.isArray(s.messages)?s.messages.length:0),e.skipGroupMessages)return i.info("[AgentClient] \u4F1A\u8BAE\u5FEB\u901F hydrate \u5DF2\u53D6\u5F97\u79C1\u4FE1\u54CD\u5E94\uFF0C\u8DF3\u8FC7\u7FA4\u804A\u53D1\u73B0\u5E76\u7ACB\u5373\u8FD4\u56DE: directMessages=%s",Array.isArray(s.messages)?s.messages.length:0),{directMessages:Array.isArray(s.messages)?s.messages:[],groupMessages:[]};let a;try{a=await this.discoverGroupRooms()}catch(o){i.warn("[AgentClient] \u53D1\u73B0\u7FA4\u623F\u95F4\u5931\u8D25\uFF0C\u672C\u6B21\u6309\u65E0\u7FA4\u6D88\u606F\u5904\u7406\uFF08\u5DF2\u53D6\u5230\u7684\u79C1\u4FE1\u4E0D\u53D7\u5F71\u54CD\uFF09: %s",o instanceof Error?o.message:String(o)),a={groups:[]}}const c=this.collectRoomIds(a,t),g=await Promise.all(c.map(async o=>{const l={agentId:this.agentId,projectId:t,roomId:o};e.since&&(l.since=e.since);try{return await this.httpClient.callTool("get_group_messages",l)}catch(d){return i.warn("[AgentClient] \u8DF3\u8FC7\u7FA4\u623F\u95F4\u672A\u8BFB\u8865\u62C9\u5931\u8D25: roomId=%s, error=%s",o,d instanceof Error?d.message:String(d)),{messages:[],currentReadPos:0,hasMore:!1}}}));return{directMessages:Array.isArray(s.messages)?s.messages:[],groupMessages:g.flatMap(o=>this.normalizeGroupMessages(o)).sort((o,l)=>new Date(o.timestamp).getTime()-new Date(l.timestamp).getTime())}}async markDmRead(e){if(e.length===0)return new Set;this.ensureRegistered();try{const t=await this.httpClient.callTool("mark_dm_read",{agentId:this.agentId,msgIds:e}),n=new Set(Array.isArray(t?.deliverableMsgIds)?t.deliverableMsgIds:[]),r=e.filter(s=>!n.has(s));return r.length>0?i.warn("[AgentClient] mark_dm_read \u786E\u8BA4\u540E\u5C06\u6709 %d \u6761\u6D88\u606F\u88AB\u4E22\u5F03\u4E0D\u4EA4\u4ED8: \u8BF7\u6C42=%s, \u53EF\u4EA4\u4ED8=%s, \u88AB\u4E22\u5F03=%s",r.length,JSON.stringify(e),JSON.stringify([...n]),JSON.stringify(r)):i.info("[AgentClient] mark_dm_read \u786E\u8BA4\u5B8C\u6210: %d \u6761\u5168\u90E8\u53EF\u4EA4\u4ED8",e.length),n}catch(t){throw i.warn("[AgentClient] mark_dm_read \u8BF7\u6C42\u5931\u8D25\uFF08\u5C06\u964D\u7EA7\u4E3A\u76F4\u63A5\u4EA4\u4ED8\uFF09: %s",t instanceof Error?t.message:String(t)),t}}async markForceInjected(e){if(e.length===0)return new Set;this.ensureRegistered();try{const t=await this.httpClient.callTool("mark_force_injected",{agentId:this.agentId,msgIds:e}),n=new Set(Array.isArray(t?.deliverableMsgIds)?t.deliverableMsgIds:[]),r=e.filter(s=>!n.has(s));return r.length>0?i.warn("[AgentClient] mark_force_injected \u786E\u8BA4\u540E\u5C06\u6709 %d \u6761\u5F3A\u5236\u6D88\u606F\u88AB\u4E22\u5F03\u4E0D\u4EA4\u4ED8: \u8BF7\u6C42=%s, \u53EF\u4EA4\u4ED8=%s",r.length,JSON.stringify(e),JSON.stringify([...n])):i.info("[AgentClient] mark_force_injected \u786E\u8BA4\u5B8C\u6210: %d \u6761\u5F3A\u5236\u6D88\u606F\u5DF2\u6CE8\u5165",e.length),n}catch(t){throw i.warn("[AgentClient] mark_force_injected \u8BF7\u6C42\u5931\u8D25\uFF08\u5C06\u964D\u7EA7\u4E3A\u76F4\u63A5\u4EA4\u4ED8\uFF09: %s",t instanceof Error?t.message:String(t)),t}}async markGroupRead(e,t){if(t.length===0)return new Set;this.ensureRegistered();const n=await this.httpClient.callTool("mark_group_read",{agentId:this.agentId,roomId:e,msgIds:t});return new Set(Array.isArray(n?.deliverableMsgIds)?n.deliverableMsgIds:[])}async markNotificationRead(e){if(e.length!==0){this.ensureRegistered();try{await this.httpClient.callTool("mark_notification_read",{agentId:this.agentId,msgIds:e})}catch{}}}async markMeetingRead(e){if(e.length!==0){this.ensureRegistered();try{await this.httpClient.callTool("mark_meeting_read",{agentId:this.agentId,msgIds:e})}catch{}}}async fetchBrowserListenerEvents(){const e=this.serverConfig.runtimeBridgeBaseUrl,t=this.agentId;if(!e||!t)return i.info("[AgentClient] fetchBrowserListenerEvents \u8DF3\u8FC7: bridgeBaseUrl=%s, agentId=%s",e||"(\u7A7A)",t||"(\u7A7A)"),[];try{const n=`${e}/runtime/browser-listeners/${encodeURIComponent(t)}/events`,r=this.serverConfig.runtimeAccessToken||"";i.debug("[AgentClient] \u62C9\u53D6\u76D1\u542C\u5668\u4E8B\u4EF6: url=%s, tokenLen=%d",n,r.length);const s=await fetch(n,{method:"GET",headers:{"X-Runtime-Token":r},signal:AbortSignal.timeout(3e3)});if(!s.ok)return i.warn("[AgentClient] \u62C9\u53D6\u76D1\u542C\u5668\u4E8B\u4EF6\u5931\u8D25: HTTP %s, url=%s",s.status,n),[];const a=await s.json();return!a.ok||!Array.isArray(a.events)?(i.warn("[AgentClient] \u62C9\u53D6\u76D1\u542C\u5668\u4E8B\u4EF6\u54CD\u5E94\u5F02\u5E38: ok=%s, eventsType=%s",a.ok,Array.isArray(a.events)?"array":typeof a.events),[]):(i.debug("[AgentClient] \u62C9\u53D6\u76D1\u542C\u5668\u4E8B\u4EF6\u6210\u529F: %d \u6761\u4E8B\u4EF6",a.events.length),a.events)}catch(n){return i.warn("[AgentClient] \u62C9\u53D6\u76D1\u542C\u5668\u4E8B\u4EF6\u5F02\u5E38: %s",n instanceof Error?n.message:String(n)),[]}}async fetchPluginEvents(){const e=this.serverConfig.runtimeBridgeBaseUrl,t=this.agentId;if(!e||!t)return{revision:0,events:[]};try{const n=`${e}/runtime/plugin-events/${encodeURIComponent(t)}/events`,r=this.serverConfig.runtimeAccessToken||"",s=await fetch(n,{method:"GET",headers:{"X-Runtime-Token":r},signal:AbortSignal.timeout(3e3)});if(!s.ok)return i.warn("[AgentClient] \u62C9\u53D6\u63D2\u4EF6\u4E8B\u4EF6\u5931\u8D25: HTTP %s, url=%s",s.status,n),{revision:0,events:[]};const a=await s.json();return!a.ok||!Array.isArray(a.events)?(i.warn("[AgentClient] \u62C9\u53D6\u63D2\u4EF6\u4E8B\u4EF6\u54CD\u5E94\u5F02\u5E38: ok=%s",String(a.ok)),{revision:0,events:[]}):(i.debug("[AgentClient] \u62C9\u53D6\u63D2\u4EF6\u4E8B\u4EF6\u6210\u529F: %d \u6761\u4E8B\u4EF6, revision=%s",a.events.length,String(a.revision??0)),{revision:a.revision??0,events:a.events})}catch(n){return i.warn("[AgentClient] \u62C9\u53D6\u63D2\u4EF6\u4E8B\u4EF6\u5F02\u5E38: %s",n instanceof Error?n.message:String(n)),{revision:0,events:[]}}}async notifyBridgeForceMessage(){const e=this.serverConfig.runtimeBridgeBaseUrl,t=this.agentId;if(!(!e||!t))try{const n=`${e}/runtime/sessions/${encodeURIComponent(t)}/notify-force-message`,r=this.serverConfig.runtimeAccessToken||"",s=await fetch(n,{method:"POST",headers:{"X-Runtime-Token":r},signal:AbortSignal.timeout(3e3)});s.ok||i.warn("[AgentClient] \u901A\u77E5 bridge \u5F3A\u5236\u6D88\u606F\u5931\u8D25: HTTP %s, url=%s",s.status,n)}catch(n){i.warn("[AgentClient] \u901A\u77E5 bridge \u5F3A\u5236\u6D88\u606F\u5F02\u5E38: %s",n instanceof Error?n.message:String(n))}}async fetchCurrentAction(){const e=this.serverConfig.runtimeBridgeBaseUrl,t=this.agentId;if(!e||!t)return null;try{const n=`${e}/runtime/sessions/${encodeURIComponent(t)}/current-action`,r=this.serverConfig.runtimeAccessToken||"",s=await fetch(n,{method:"GET",headers:{"X-Runtime-Token":r},signal:AbortSignal.timeout(3e3)});if(!s.ok)return i.warn("[AgentClient] \u67E5\u8BE2 bridge \u5F53\u524D\u52A8\u4F5C\u5931\u8D25: HTTP %s, url=%s",s.status,n),null;const a=await s.json();return a?.ok?a:null}catch(n){return i.warn("[AgentClient] \u67E5\u8BE2 bridge \u5F53\u524D\u52A8\u4F5C\u5F02\u5E38: %s",n instanceof Error?n.message:String(n)),null}}async fetchDirectMessagesWithRecovery(e,t,n,r=!1){if(e==="poll_message"){i.info("[AgentClient] fetchDirectMessagesWithRecovery \u5165\u53E3: tool=poll_message, pollMessageTimeoutMs=%s, agentId=%s",String(n??"(\u9ED8\u8BA4)"),String(t?.agentId??""));try{const s=await this.httpClient.callToolOnce(e,t,n);return i.info("[AgentClient] fetchDirectMessagesWithRecovery poll_message \u6210\u529F\u8FD4\u56DE: %s \u6761",Array.isArray(s?.messages)?s.messages.length:0),s}catch(s){if(this.isRecoverableLongPollError(s)){if(r)throw new T(s instanceof Error?s.message:String(s));return i.warn("[AgentClient] poll_message \u5355\u6B21\u957F\u8F6E\u8BE2\u8D85\u65F6\uFF0C\u6309\u7A7A\u7ED3\u679C\u9000\u907F\u540E\u7EE7\u7EED\u7B49\u5F85:",s),{messages:[]}}throw s}}return await this.httpClient.callTool(e,t)}isRecoverableLongPollError(e){return e instanceof Error?/MCP tool poll_message call failed: 503(?:\s|$)/.test(e.message)||/MCP tool poll_message timed out after \d+ms/.test(e.message):!1}normalizeGroupMessages(e){return Array.isArray(e.messages)?e.messages.filter(t=>!!(t&&typeof t=="object"&&typeof t.msgId=="number"&&typeof t.senderId=="string"&&typeof t.content=="string"&&typeof t.timestamp=="string")):[]}collectRoomIds(e,t){const n=e.groups.filter(r=>r.projectId===t).map(r=>r.id);return Array.from(new Set(n))}async getProfile(){this.ensureRegistered();const e=this.agentId;if(!e)throw new Error("Agent is not registered");return{...await this.getProfileByAgentId(e),describe:this.agentConfig.describe}}async getProfileByAgentId(e){return await this.httpClient.callTool("get_profile",{agentId:e})}async getMyTasks(){return this.ensureRegistered(),await this.httpClient.callTool("my_task",{agentId:this.agentId})}async listTaskNodeIterations(e={}){return this.ensureRegistered(),await this.httpClient.callTool("list_task_node_iterations",{agentId:this.agentId,...e})}async createTaskInstanceComment(e){this.ensureRegistered();const t={agentId:this.agentId,...e};return await this.httpClient.callTool("create_task_instance_comment",t)}async submitTaskResult(e,t,n,r,s){this.ensureRegistered();const a={agentId:this.agentId,nodeId:e,outputPayload:t};return(Array.isArray(n)&&n.length>0||typeof n=="string"&&n.trim().length>0)&&(a.changeLog=n),typeof r=="string"&&r.trim().length>0&&(a.handoverNote=r),s&&Array.isArray(s)&&s.length>0&&(a.deliverables=s),await this.httpClient.callTool("submit_task_result",a)}async startTaskRollback(e){return this.ensureRegistered(),await this.httpClient.callTool("start_task_rollback",{agentId:this.agentId,...e})}async finishTaskRollback(e){return this.ensureRegistered(),await this.httpClient.callTool("finish_task_rollback",{agentId:this.agentId,...e})}async getDebugLogConfig(){return await this.httpClient.callTool("get_debug_log_config",{agentId:this.agentId})}async queryDebugLogs(e){return this.ensureRegistered(),await this.httpClient.callTool("query_debug_logs",{...e})}async queryFileChangesHistory(e){return this.ensureRegistered(),await this.httpClient.callTool("query_file_changes_history",{...e})}async listColleagueEvents(e){return this.ensureRegistered(),await this.httpClient.callTool("list_colleague_events",{...e})}async getRuntimeFeatures(){return await this.httpClient.fetchRuntimeFeatures()}async listLaunchConfigs(){return this.ensureRegistered(),await this.httpClient.callTool("launch_config_list",{})}async createLaunchConfig(e){return this.ensureRegistered(),await this.httpClient.callTool("launch_config_create",{...e})}async updateLaunchConfig(e){return this.ensureRegistered(),await this.httpClient.callTool("launch_config_update",{...e})}async deleteLaunchConfig(e){return this.ensureRegistered(),await this.httpClient.callTool("launch_config_delete",{configId:e})}async startLaunchConfig(e){this.ensureRegistered();const t=Math.max(0,Math.min(3e5,Number(e.wait_timeout_ms)||0));return t>0?await this.httpClient.callToolOnce("launch_config_start",e,t+6e4):await this.httpClient.callTool("launch_config_start",{...e})}async restartLaunchConfig(e){this.ensureRegistered();const t=Math.max(0,Math.min(3e5,Number(e.wait_timeout_ms)||0));return t>0?await this.httpClient.callToolOnce("launch_config_restart",e,t+6e4):await this.httpClient.callTool("launch_config_restart",{...e})}async stopLaunchConfig(e){return this.ensureRegistered(),await this.httpClient.callTool("launch_config_stop",{configId:e})}async getLaunchLogs(e){return this.ensureRegistered(),await this.httpClient.callTool("launch_config_logs",{...e})}async listLaunchRuns(){return this.ensureRegistered(),await this.httpClient.callTool("launch_config_status",{})}async listAbilityMarket(e={}){return this.ensureRegistered(),await this.httpClient.callTool("list_ability_market",{...e})}async installAbilityMarketItem(e){return this.ensureRegistered(),await this.httpClient.callTool("install_ability_market_item",{...e})}async uninstallAbilityMarketItem(e){return this.ensureRegistered(),await this.httpClient.callTool("uninstall_ability_market_item",{...e})}async abilityDevIde(e){return this.ensureRegistered(),await this.httpClient.callTool("ability_dev_ide",{...e})}async formalAbility(e){return this.ensureRegistered(),await this.httpClient.callTool("formal_ability",{...e})}async listMyAbilities(e={}){return this.ensureRegistered(),await this.httpClient.callTool("list_my_abilities",{...e})}start(e,t){if(this.isRunning){i.warn("[AgentClient] \u6D88\u606F\u5FAA\u73AF\u5DF2\u5728\u8FD0\u884C\u4E2D");return}this.isDegradedMode||this.ensureRegistered(),this.messageHandler=e,this.profileHandler=t?.profileHandler||null,this.configHandler=t?.configHandler||null,this.systemNotifyHandler=t?.systemNotifyHandler||null,this.isRunning=!0,i.info(`[AgentClient] start() \u88AB\u8C03\u7528\uFF0CcachedProfile: ${this.cachedProfile?"\u5B58\u5728":"\u4E0D\u5B58\u5728"}, profileHandler: ${this.profileHandler?"\u5DF2\u8BBE\u7F6E":"\u672A\u8BBE\u7F6E"}, \u964D\u7EA7\u6A21\u5F0F: ${this.isDegradedMode?"\u662F":"\u5426"}`),this.cachedProfile&&this.profileHandler&&(i.info(`[AgentClient] \u5904\u7406\u7F13\u5B58\u7684 Profile \u4FE1\u606F: ${this.cachedProfile.displayName}`),this.profileHandler(this.cachedProfile),this.cachedProfile=null),t?.pollMode??!1?(i.warn("[AgentClient] \u542F\u52A8\u6D88\u606F\u4E3B\u5FAA\u73AF\uFF08HTTP\u8F6E\u8BE2\u6A21\u5F0F - \u4E0D\u63A8\u8350\uFF09"),this.messageLoop()):i.info("[AgentClient] \u542F\u52A8\u6D88\u606F\u4E3B\u5FAA\u73AF\uFF08WebSocket\u63A8\u9001\u6A21\u5F0F - \u63A8\u8350\uFF09")}stop(){this.isRunning=!1,this.pollTimer&&(clearTimeout(this.pollTimer),this.pollTimer=null),this.stopRuntimeTokenRefresh(),i.info("[AgentClient] \u6D88\u606F\u4E3B\u5FAA\u73AF\u5DF2\u505C\u6B62")}async messageLoop(){for(;this.isRunning;)try{await this.delay(I)}catch(e){i.error("[AgentClient] \u6D88\u606F\u5FAA\u73AF\u9519\u8BEF:",e),await this.delay(5e3)}}handleIncomingDm(e){e.senderId!==this.agentId&&this.processMessage(e)}handleIncomingGroup(e){e.senderId!==this.agentId&&this.processMessage(e)}handleIncomingMeeting(e){!e||e.senderId===this.agentId||this.processMessage(e)}handleProfileInfo(e){i.info(`[AgentClient] \u6536\u5230 Profile \u4FE1\u606F: ${e.displayName} (${e.roleName})`),e.projectId&&(this.projectId=e.projectId,i.info(`[AgentClient] \u66F4\u65B0\u6240\u5C5E\u9879\u76EE: ${this.projectId}`)),e.roleName&&e.roleName!==this.agentConfig.roleName&&(i.info(`[AgentClient] \u540C\u6B65\u89D2\u8272\u540D: "${this.agentConfig.roleName||"(\u7A7A)"}" -> "${e.roleName}"`),this.agentConfig.roleName=e.roleName),e.roleName&&u(e.roleName,e.instanceName||this.agentId||""),this.profileHandler?this.profileHandler(e):(i.info("[AgentClient] profileHandler \u672A\u8BBE\u7F6E\uFF0C\u7F13\u5B58 Profile \u4FE1\u606F"),this.cachedProfile=e)}async processMessage(e){if(!this.messageHandler)return;const t=typeof e.msgId=="string";i.info(`[AgentClient] \u6536\u5230${t?"\u79C1\u4FE1":"\u7FA4\u6D88\u606F"}\u6765\u81EA ${e.senderName}: ${e.content.substring(0,50)}...`);try{const n=await this.messageHandler(e);if(t){const r=e;r.requireReply&&r.callId&&await this.replyToCall(r.callId,r.senderId,n||"\u5DF2\u6536\u5230\u6D88\u606F\uFF0C\u6B63\u5728\u5904\u7406\u4E2D...")}}catch(n){const r=typeof e.msgId=="string";if(i.error("[AgentClient] \u5904\u7406\u6D88\u606F\u5931\u8D25: type=%s, senderId=%s, senderName=%s, msgId=%s, error=%s",r?"\u79C1\u4FE1":"\u7FA4\u6D88\u606F",e.senderId,e.senderName,e.msgId,n instanceof Error?n.message:String(n)),r){const s=e;s.requireReply&&s.callId&&await this.replyToCall(s.callId,s.senderId,`\u5904\u7406\u5931\u8D25: ${n}`)}}}ensureRegistered(){if(!this.agentId)throw new Error("Agent is not registered")}delay(e){return new Promise(t=>{this.pollTimer=setTimeout(t,e)})}onNewCharacter(e){this.newCharacterHandler=e}getState(){return{agentId:this.agentId,displayName:this.displayName,projectId:this.projectId,isConnected:this.wsClient.isConnected(),isRunning:this.isRunning}}getAgentConfig(){return this.agentConfig}getServerConfig(){return this.serverConfig}reloadConfig(){h.loadConfig(),this.agentConfig=h.getAgentConfig(),i.info(`[AgentClient] \u914D\u7F6E\u5DF2\u91CD\u65B0\u52A0\u8F7D\uFF0C\u89D2\u8272: ${this.agentConfig.roleName}`)}enterDegradedMode(){this.isDegradedMode=!0,i.warn("[AgentClient] \u8FDB\u5165\u964D\u7EA7\u6A21\u5F0F\uFF0C\u5C06\u5728\u540E\u53F0\u6301\u7EED\u5C1D\u8BD5\u91CD\u8FDE")}exitDegradedMode(){this.isDegradedMode=!1,i.info("[AgentClient] \u9000\u51FA\u964D\u7EA7\u6A21\u5F0F")}isInDegradedMode(){return this.isDegradedMode}async retryRegistrationInBackground(e,t){let n=0;(async()=>{for(;this.isDegradedMode;)try{i.info(`[AgentClient] \u964D\u7EA7\u6A21\u5F0F\uFF1A\u5C1D\u8BD5\u91CD\u65B0\u6CE8\u518C (${n+1}/${t===-1?"\u65E0\u9650":t})`);const s=await this.register();i.info(`[AgentClient] \u964D\u7EA7\u6A21\u5F0F\uFF1A\u6CE8\u518C\u6210\u529F - ${s.displayName} (${s.agentId})`),this.exitDegradedMode(),this.messageHandler&&this.start(this.messageHandler);return}catch(s){n++;const a=s instanceof Error?s.message:String(s);if(i.warn(`[AgentClient] \u964D\u7EA7\u6A21\u5F0F\uFF1A\u6CE8\u518C\u5931\u8D25 (${n}/${t===-1?"\u65E0\u9650":t}): ${a}`),t>0&&n>=t){i.error("[AgentClient] \u964D\u7EA7\u6A21\u5F0F\uFF1A\u8FBE\u5230\u6700\u5927\u91CD\u8BD5\u6B21\u6570\uFF0C\u505C\u6B62\u91CD\u8FDE"),this.isDegradedMode=!1;return}await new Promise(c=>setTimeout(c,e))}})().catch(s=>{i.error("[AgentClient] \u964D\u7EA7\u6A21\u5F0F\u540E\u53F0\u91CD\u8BD5\u5FAA\u73AF\u5F02\u5E38\u9000\u51FA: error=%s, stack=%s",s instanceof Error?s.message:String(s),s instanceof Error?s.stack:"(no stack)")})}initializeStatusReporter(){if(!this.agentId){i.warn("[AgentClient] \u65E0\u6CD5\u521D\u59CB\u5316\u72B6\u6001\u62A5\u544A\u5668\uFF1AagentId \u4E3A\u7A7A");return}this.statusReporter=new A({agentId:this.agentId,sendStatusUpdate:e=>{this.wsClient.send({type:"AGENT_STATUS",data:e,timestamp:new Date().toISOString()})}}),w(e=>this.reportMcpNodeLog(e)),this.startRuntimeTokenRefresh(),i.info("[AgentClient] \u72B6\u6001\u62A5\u544A\u5668\u5DF2\u521D\u59CB\u5316")}startRuntimeTokenRefresh(){this.stopRuntimeTokenRefresh();const e=this.serverConfig.runtimeTokenRefreshIntervalMs;if(!e||e<=0){i.warn("[AgentClient] runtimeTokenRefreshIntervalMs \u672A\u914D\u7F6E\u6216\u65E0\u6548\uFF0C\u8DF3\u8FC7\u4E3B\u52A8\u7EED\u671F");return}const t=this.agentId;if(!t){i.warn("[AgentClient] agentId \u4E3A\u7A7A\uFF0C\u8DF3\u8FC7\u4E3B\u52A8\u7EED\u671F");return}this.runtimeTokenRefreshTimer=setInterval(async()=>{try{await this.httpClient.refreshRuntimeAccessToken(t)&&i.info("[AgentClient] runtimeAccessToken \u5DF2\u4E3B\u52A8\u7EED\u671F")}catch(n){i.warn("[AgentClient] \u4E3B\u52A8\u7EED\u671F runtimeAccessToken \u5931\u8D25: %s",n instanceof Error?n.message:String(n)),n instanceof Error&&n.stack&&i.warn("[AgentClient] \u4E3B\u52A8\u7EED\u671F\u5F02\u5E38\u5806\u6808:",n.stack)}},e),this.runtimeTokenRefreshTimer.unref?.(),i.info(`[AgentClient] runtime token \u4E3B\u52A8\u7EED\u671F\u5DF2\u542F\u52A8\uFF0C\u95F4\u9694 ${e}ms`)}stopRuntimeTokenRefresh(){this.runtimeTokenRefreshTimer&&(clearInterval(this.runtimeTokenRefreshTimer),this.runtimeTokenRefreshTimer=null)}reportMcpNodeLog(e){const t=this.wsClient;!this.agentId||!this.wsClient.isConnected()||typeof t.sendMcpNodeLog!="function"||t.sendMcpNodeLog(e)}getStatusReporter(){return this.statusReporter}}export{N as AgentClient,T as PollLongPollTimeoutError};
2
2
 
@@ -1,17 +1,35 @@
1
1
 
2
+
3
+
4
+
5
+
6
+
7
+
2
8
  import type { AgentConfig, RuntimeLaunchBinding, ServerConfig } from "./types.js";
3
9
 
10
+
11
+
12
+
13
+
4
14
  export declare function resolveAcodeDataHome(): string;
5
15
  export declare class ConfigManager {
6
16
  private agentConfig;
7
17
  private serverConfig;
8
18
 
19
+
20
+
21
+
9
22
  loadConfig(): void;
10
23
  applyRuntimeLaunchBinding(binding: RuntimeLaunchBinding): void;
11
24
  private parseRuntimeTokenRefreshInterval;
12
25
 
26
+
27
+
28
+
13
29
  private parsePositiveIntegerEnv;
14
30
 
31
+
32
+
15
33
  updateRuntimeAccessToken(newToken: string): boolean;
16
34
  getAgentConfig(): AgentConfig;
17
35
  getServerConfig(): ServerConfig;
@@ -1,4 +1,6 @@
1
1
 
2
+
3
+
2
4
  export declare const DEFAULT_SERVER_URL = "ws://localhost:8080/ws/agent";
3
5
  export declare const DEFAULT_HEARTBEAT_INTERVAL = 15000;
4
6
  export declare const DEFAULT_RECONNECT_INTERVAL = 200;