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
@@ -0,0 +1,43 @@
1
+
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+ export type LaunchStackType = "generic" | "java" | "python" | "node" | "go" | "php";
12
+ export interface TechStackCandidate {
13
+
14
+ id: string;
15
+
16
+ name: string;
17
+ type: LaunchStackType;
18
+
19
+ command: string;
20
+
21
+ cwd: string;
22
+
23
+ relativeCwd: string;
24
+
25
+ stack: string;
26
+
27
+ markers: string[];
28
+ confidence: "high" | "medium" | "low";
29
+ }
30
+ export interface TechStackScanResult {
31
+ workspacePath: string;
32
+
33
+ scannedDirs: number;
34
+
35
+ truncated: boolean;
36
+ candidates: TechStackCandidate[];
37
+ }
38
+
39
+
40
+
41
+
42
+
43
+ export declare function scanTechStack(workspacePath: string): Promise<TechStackScanResult>;
@@ -0,0 +1,2 @@
1
+ import N from"node:crypto";import{promises as k}from"node:fs";import d from"node:path";import{createLogger as R}from"../utils/logger.js";import{isIgnoredByGitIgnore as A,loadGitIgnoreRules as B}from"./gitignore.js";const w=R("tech-stack-scanner"),E=64*1024,T=4e3,C=2e3,F=5,M=new Set([".git",".svn",".hg",".idea",".vscode","node_modules","bower_components","vendor","target","dist","build","out","bin","obj",".gradle",".venv","venv","env","__pycache__",".mypy_cache",".pytest_cache",".next",".nuxt",".svelte-kit",".turbo",".cache","coverage"]);function q(e,n){return e==="."?n:`${e}/${n}`}async function g(e){try{const n=await k.open(e,"r");try{const t=await n.stat();if(!t.isFile())return null;const p=Math.min(t.size,E),o=Buffer.alloc(p);return await n.read(o,0,p,0),o.toString("utf8")}finally{await n.close()}}catch{return null}}async function D(e){try{return(await k.stat(e)).isFile()}catch{return!1}}function _(e){if(!e)return null;try{const n=JSON.parse(e);return n&&typeof n=="object"?n:null}catch{return null}}function L(e,n,t){return N.createHash("sha1").update(`${e}|${n}|${t}`).digest("hex").slice(0,12)}function I(e){return process.platform==="win32"?`${e}.cmd`:`./${e}`}function O(e,n,t){return n.has("mvnw")||n.has("mvnw.cmd")?`${I("mvnw")} ${t}`:`mvn ${t}`}function W(e,n){return e.has("gradlew")||e.has("gradlew.bat")?`${I("gradlew")} ${n}`:`gradle ${n}`}function G(e){if(!e)return"";const t=e.replace(/<parent>[\s\S]*?<\/parent>/gi,"").match(/<artifactId>\s*([^<\s]+)\s*<\/artifactId>/i);return t?t[1].trim():""}function J(e){if(!e)return"";const n=e.match(/rootProject\.name\s*=\s*['"]([^'"]+)['"]/);return n?n[1].trim():""}function X(e){if(!e)return"";const n=e.match(/\[package\][\s\S]*?(?=\n\[|$)/),p=(n?n[0]:e).match(/^\s*name\s*=\s*["']([^"']+)["']/m);return p?p[1].trim():""}function x(e){return d.basename(e)||"workspace"}function Y(e){return e.has("pnpm-lock.yaml")||e.has("pnpm-workspace.yaml")?{runner:"pnpm",runCommand:n=>`pnpm run ${n}`}:e.has("yarn.lock")?{runner:"yarn",runCommand:n=>`yarn run ${n}`}:e.has("bun.lockb")||e.has("bun.lock")?{runner:"bun",runCommand:n=>`bun run ${n}`}:{runner:"npm",runCommand:n=>`npm run ${n}`}}const K=["dev","develop","serve","start"];function z(e){for(const n of K)if(typeof e[n]=="string"&&e[n].trim())return n;return null}function H(e,n){return e.has("uv.lock")?"uv run ":n&&/\[tool\.poetry\]/i.test(n)?"poetry run ":""}function m(e){const{facts:n,stack:t,type:p,command:o,name:i,markers:h,confidence:f}=e;return{id:L(n.relativeDir,t,o),name:i||x(n.absoluteDir),type:p,command:o,cwd:n.absoluteDir,relativeCwd:n.relativeDir,stack:t,markers:h,confidence:f}}async function Q(e){const{absoluteDir:n,entryNames:t,subdirectories:p}=e,o=[],i=x(n);if(t.has("pom.xml")){const a=await g(d.join(n,"pom.xml")),s=G(a)||i,c=!!(a&&/spring-boot/i.test(a));o.push(m({facts:e,stack:c?"spring-boot":"maven",type:"java",command:O(n,t,c?"spring-boot:run":"-DskipTests package"),name:s,markers:["pom.xml"],confidence:c?"high":"medium"}))}else if(t.has("build.gradle")||t.has("build.gradle.kts")){const a=t.has("build.gradle.kts")?"build.gradle.kts":"build.gradle",s=await g(d.join(n,a)),c=J(s)||i,r=!!(s&&/org\.springframework\.boot/i.test(s));o.push(m({facts:e,stack:r?"spring-boot":"gradle",type:"java",command:W(t,r?"bootRun":"build"),name:c,markers:[a],confidence:r?"high":"medium"}))}if(t.has("package.json")){const a=_(await g(d.join(n,"package.json"))),s=a&&typeof a.scripts=="object"&&a.scripts!==null?a.scripts:{},c=z(s);if(c){const{runCommand:r}=Y(t),l=a&&typeof a.name=="string"?a.name.trim():"";o.push(m({facts:e,stack:"node",type:"node",command:r(c),name:l||i,markers:["package.json"],confidence:"high"}))}}if(t.has("manage.py"))o.push(m({facts:e,stack:"django",type:"python",command:"python manage.py runserver",name:`${i} (Django)`,markers:["manage.py"],confidence:"high"}));else if(t.has("pyproject.toml")||t.has("requirements.txt")||t.has("setup.py")){const a=t.has("pyproject.toml")?await g(d.join(n,"pyproject.toml")):null,s=H(t,a),c=t.has("pyproject.toml")?"pyproject.toml":t.has("requirements.txt")?"requirements.txt":"setup.py";!!(a&&/fastapi/i.test(a))&&t.has("main.py")?o.push(m({facts:e,stack:"fastapi",type:"python",command:`${s}uvicorn main:app --reload`,name:`${i} (FastAPI)`,markers:[c,"main.py"],confidence:"high"})):t.has("main.py")?o.push(m({facts:e,stack:"python",type:"python",command:`${s}python main.py`,name:i,markers:[c,"main.py"],confidence:"medium"})):t.has("app.py")&&o.push(m({facts:e,stack:"python",type:"python",command:`${s}python app.py`,name:i,markers:[c,"app.py"],confidence:"medium"}))}if(t.has("go.mod")){if(t.has("main.go"))o.push(m({facts:e,stack:"go",type:"go",command:"go run .",name:i,markers:["go.mod","main.go"],confidence:"high"}));else if(p.includes("cmd")){const a=d.join(n,"cmd");let s=[];try{s=await k.readdir(a,{withFileTypes:!0})}catch{s=[]}const c=s.filter(r=>r.isDirectory()).map(r=>r.name).sort().slice(0,F);for(const r of c)await D(d.join(a,r,"main.go"))&&o.push(m({facts:e,stack:"go",type:"go",command:`go run ./cmd/${r}`,name:`${i}/${r}`,markers:["go.mod",`cmd/${r}/main.go`],confidence:"high"}))}}if(t.has("composer.json")){const a=_(await g(d.join(n,"composer.json"))),s=a&&typeof a.name=="string"?a.name.trim():"";!!(a&&(/laravel\/framework/i.test(JSON.stringify(a.require??{}))||/laravel\/framework/i.test(JSON.stringify(a["require-dev"]??{}))))&&t.has("artisan")?o.push(m({facts:e,stack:"laravel",type:"php",command:"php artisan serve",name:s||i,markers:["composer.json","artisan"],confidence:"high"})):e.directoryNames.has("public")&&e.directoryNames.has("bin")?o.push(m({facts:e,stack:"symfony",type:"php",command:"php -S localhost:8000 -t public",name:s||i,markers:["composer.json"],confidence:"medium"})):t.has("index.php")&&o.push(m({facts:e,stack:"php",type:"php",command:"php -S localhost:8000",name:s||i,markers:["composer.json","index.php"],confidence:"medium"}))}else t.has("index.php")&&o.push(m({facts:e,stack:"php",type:"php",command:"php -S localhost:8000",name:i,markers:["index.php"],confidence:"low"}));if(t.has("Cargo.toml")){const a=await g(d.join(n,"Cargo.toml")),s=!!(a&&/^\s*\[package\]/m.test(a)),c=!!(a&&/^\s*\[\[bin\]\]/m.test(a)||await D(d.join(n,"src","main.rs")));if(s&&c){const r=X(a);o.push(m({facts:e,stack:"cargo",type:"generic",command:"cargo run",name:r||i,markers:["Cargo.toml"],confidence:"medium"}))}}const h=t.has("deno.json")?"deno.json":t.has("deno.jsonc")?"deno.jsonc":"";if(h){const a=await g(d.join(n,h));a&&/["']?start["']?\s*:/.test(a)&&o.push(m({facts:e,stack:"deno",type:"generic",command:"deno task start",name:i,markers:[h],confidence:"medium"}))}const f=["docker-compose.yml","docker-compose.yaml","compose.yml","compose.yaml"].find(a=>t.has(a));return f&&o.push(m({facts:e,stack:"docker-compose",type:"generic",command:"docker compose up",name:`${i} (compose)`,markers:[f],confidence:"medium"})),o}function U(e,n,t,p){return M.has(t.toLowerCase())?!0:p.length===0?!1:A(n,!0,p)}async function ae(e){const n=String(e||"").trim();if(!n)throw new Error("workspacePath is required");const t=d.resolve(n);if(!(await k.stat(t)).isDirectory())throw new Error(`Workspace path is not a directory: ${t}`);const o=await B(t),i=[];let h=0,f=!1;const a=[[t,"."]];for(;a.length>0;){if(h>=T){f=!0;break}const r=a.shift();if(!r)break;const[l,v]=r;h+=1;let y=[];try{y=await k.readdir(l,{withFileTypes:!0})}catch(u){w.warn(`[scan] readdir failed: dir=${l} error=${u.message}`);continue}y.length>C&&(f=!0,y=y.slice(0,C));const b=new Set,j=new Set,$=[];for(const u of y)if(u.isDirectory()){j.add(u.name);const S=q(v,u.name);if(U(t,S,u.name,o))continue;$.push(u.name),a.push([d.join(l,u.name),S])}else u.isFile()&&b.add(u.name);const P={absoluteDir:l,relativeDir:v,entryNames:b,directoryNames:j,subdirectories:$};try{i.push(...await Q(P))}catch(u){w.warn(`[scan] detect failed: dir=${l} error=${u.message}`)}}const s=new Set,c=i.filter(r=>s.has(r.id)?!1:(s.add(r.id),!0));return c.sort((r,l)=>r.relativeCwd!==l.relativeCwd?r.relativeCwd.localeCompare(l.relativeCwd):r.stack.localeCompare(l.stack)),w.info(`[scan] workspace=${t} dirs=${h} candidates=${c.length} truncated=${f}`),{workspacePath:t,scannedDirs:h,truncated:f,candidates:c}}export{ae as scanTechStack};
2
+
@@ -1,19 +1,48 @@
1
1
 
2
+
3
+
4
+
5
+
2
6
  import type { PersistedSession } from '../types.js';
3
7
 
8
+
9
+
10
+
11
+
4
12
  export declare function getPersistedSessionsFile(): string;
5
13
 
14
+
15
+
16
+
17
+
6
18
  export declare function loadPersistedSessions(): Promise<PersistedSession[]>;
7
19
 
20
+
21
+
22
+
23
+
8
24
  export declare function savePersistedSessions(sessions: PersistedSession[]): Promise<void>;
9
25
 
26
+
27
+
28
+
29
+
10
30
  export declare function upsertPersistedSession(session: PersistedSession): Promise<void>;
11
31
 
32
+
33
+
34
+
35
+
12
36
  export declare function updatePersistedSessionAutoCommands(agentId: string, commands: {
13
37
  idleInputAutoCommand: string;
14
38
  nonInputAutoCommand: string;
15
39
  }): Promise<boolean>;
16
40
 
41
+
42
+
43
+
44
+
45
+
17
46
  export declare function updatePersistedSessionRuntimeState(sessionId: string, runtimeState: {
18
47
  runtimeStatus: string;
19
48
  runtimeActionType?: string;
@@ -21,8 +50,22 @@ export declare function updatePersistedSessionRuntimeState(sessionId: string, ru
21
50
  runtimeActionDetail?: string;
22
51
  }): Promise<boolean>;
23
52
 
53
+
54
+
55
+
56
+
24
57
  export declare function removePersistedSession(sessionId: string): Promise<void>;
25
58
 
59
+
60
+
61
+
62
+
63
+
26
64
  export declare function findPersistedSessionByAgentId(agentId: string): Promise<PersistedSession | undefined>;
27
65
 
66
+
67
+
68
+
69
+
70
+
28
71
  export declare function removePersistedSessionByAgentId(agentId: string): Promise<void>;
@@ -11,8 +11,12 @@ type ToolCommand = {
11
11
  export declare const SUPPORTED_INSTALLABLE_TOOLS: readonly string[];
12
12
  export declare const SUPPORTED_UNINSTALLABLE_TOOLS: readonly string[];
13
13
 
14
+
15
+
14
16
  export declare function getToolUninstallCommands(tool: string): string[];
15
17
 
18
+
19
+
16
20
  export declare function getToolCommandSpecs(tool: string, phase: "install" | "uninstall"): Array<{
17
21
  command: string;
18
22
  args: string[];
@@ -29,11 +33,19 @@ export declare function buildSdkCliInstallStatus(tool: string, sdkResult: {
29
33
  error: string | null;
30
34
  }, requiresCli: boolean): ToolInstallStatus;
31
35
 
36
+
37
+
32
38
  export declare function detectToolInstallStatus(tool: string): Promise<ToolInstallStatus>;
33
39
 
40
+
41
+
34
42
  export declare function detectToolStatuses(tools: string[]): Promise<Record<string, ToolInstallStatus>>;
35
43
 
44
+
45
+
36
46
  export declare function ensureToolsInstalled(tools: string[]): Promise<Record<string, ToolInstallStatus>>;
37
47
 
48
+
49
+
38
50
  export declare function uninstallTools(tools: string[]): Promise<Record<string, ToolInstallStatus>>;
39
51
  export {};
@@ -1,9 +1,106 @@
1
1
 
2
2
 
3
- export declare function startTunnelClient(serverUrl: string, instanceId: string): void;
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+ import WebSocket from "ws";
17
+ interface LocalStream {
18
+ ws: WebSocket;
19
+
20
+ pending: Array<{
21
+ data: Buffer;
22
+ bin: boolean;
23
+ }>;
24
+ }
25
+ interface TunnelState {
26
+
27
+ serverUrl: string;
28
+
29
+
30
+
31
+
32
+ targetKey: string;
33
+
34
+ userKey?: string;
35
+ instanceId: string;
36
+ ws?: WebSocket;
37
+
38
+ streams: Map<string, LocalStream>;
39
+
40
+ pendingReqChunks: Map<string, PendingRequestChunks>;
41
+ timer?: NodeJS.Timeout;
42
+ reconnectTimer?: NodeJS.Timeout;
43
+
44
+ reconnectAttempts?: number;
45
+ shuttingDown: boolean;
46
+ }
47
+
48
+
49
+
50
+
51
+
52
+ interface PendingRequestChunks {
53
+ method: string;
54
+ path: string;
55
+ headers?: Record<string, string[]>;
56
+ parts: Buffer[];
57
+ timer: NodeJS.Timeout;
58
+ }
59
+
60
+
61
+
62
+
63
+ export declare function startTunnelClient(serverUrl: string, instanceId: string, userKey?: string): void;
4
64
 
5
65
  export declare function stopTunnelClient(): void;
6
66
 
67
+
68
+
69
+
70
+
71
+ export declare function stopTunnelClientForTarget(serverUrl: string, userKey?: string): void;
72
+
73
+
74
+
75
+
7
76
  export declare function stopTunnelClientForServer(serverUrl: string): void;
8
77
 
9
- export declare function stopTunnelClientsExcept(serverUrls: string[]): void;
78
+
79
+
80
+
81
+
82
+
83
+
84
+ export declare function stopTunnelClientsExcept(targetKeys: string[]): void;
85
+
86
+
87
+
88
+
89
+
90
+
91
+
92
+
93
+
94
+ export declare const __tunnelClientTestHooks: {
95
+ createState(serverUrl?: string, instanceId?: string): TunnelState;
96
+ dispatch(state: TunnelState, msg: Record<string, unknown>): void;
97
+
98
+ pendingChunkIds(state: TunnelState): string[];
99
+
100
+ activeTargetKeys(): string[];
101
+
102
+ cleanup(state: TunnelState): void;
103
+
104
+ teardown(state: TunnelState): void;
105
+ };
106
+ export {};
@@ -1,2 +1,2 @@
1
- import I,{AxiosError as O}from"axios";import p from"ws";import{getActiveBridgeHttpPort as _}from"../config.js";import{logger as i}from"../utils/logger.js";import{loadConfigs as x,loadPrimaryLifecycleConfig as D}from"./auto-register.js";import{getRuntimeAccessToken as L,normalizeSchedulerBaseUrl as S}from"./runtime-binding.js";const W=15e3,P=5e3,$=3e4,k=.2,J=200,q=1*1024*1024,G=4001,H=768*1024,K=384*1024,h=new Map;function X(e){const r=e.serverUrl,n=e.instanceId;if(!r||!n)return null;try{const t=new URL(r),o=t.protocol==="https:"?"wss:":"ws:",c=L(r),l=x().find(m=>S(m.serverUrl)===r)||D(),s=c||l.userKey;if(c?i.debug("[TunnelClient] \u4F7F\u7528 runtime access token \u8FDE\u63A5\u96A7\u9053"):l.userKey&&i.warn("[TunnelClient] getRuntimeAccessToken \u8FD4\u56DE\u7A7A\uFF0C\u56DE\u9000\u5230 userKey\uFF08\u975E runtime token\uFF0C\u9274\u6743\u53EF\u80FD\u5931\u8D25\uFF09: targetUrl=",r),!s)return i.warn("[TunnelClient] \u7F3A\u5C11 runtime token\uFF0C\u65E0\u6CD5\u5EFA\u7ACB\u96A7\u9053: targetUrl=",r),null;const a=new URLSearchParams({instanceId:n});return{url:`${o}//${t.host}/ws/bridge-tunnel?${a.toString()}`,token:s}}catch(t){return i.warn("[TunnelClient] \u65E0\u6CD5\u89E3\u6790 serverUrl:",String(t)),null}}function oe(e,r){const n=S(e);if(!n){i.warn("[TunnelClient] serverUrl \u65E0\u6548\uFF0C\u65E0\u6CD5\u542F\u52A8\u96A7\u9053:",e);return}const t=h.get(n);t&&(t.shuttingDown=!0,C(t),h.delete(n));const o={serverUrl:n,instanceId:r,streams:new Map,shuttingDown:!1};h.set(n,o),A(o)}function se(){for(const e of h.values())e.shuttingDown=!0,C(e);h.clear()}function ie(e){const r=S(e);if(!r)return;const n=h.get(r);n&&(n.shuttingDown=!0,C(n),h.delete(r),i.info(`[TunnelClient] tunnel stopped: ${r}`))}function ce(e){const r=new Set(e.map(n=>S(n)).filter(n=>!!n));for(const[n,t]of h.entries())r.has(n)||(i.info(`[TunnelClient] serverUrl \u5DF2\u4E0D\u5728\u914D\u7F6E\u4E2D\uFF0C\u505C\u6B62\u65E7\u96A7\u9053: ${n}`),t.shuttingDown=!0,C(t),h.delete(n))}function C(e){e.timer&&(clearInterval(e.timer),e.timer=void 0),e.reconnectTimer&&(clearTimeout(e.reconnectTimer),e.reconnectTimer=void 0);for(const[r,n]of e.streams.entries()){try{n.ws.close(1e3,"tunnel client stopped")}catch{}e.streams.delete(r)}if(e.ws){e.ws.removeAllListeners();try{e.ws.close(1e3,"tunnel client stopped")}catch{}e.ws=void 0}}function A(e){if(e.shuttingDown)return;const r=e.instanceId;if(!r)return;const n=X(e);if(!n){b(e);return}i.info("[TunnelClient] \u8FDE\u63A5\u96A7\u9053\u670D\u52A1\u7AEF:",n.url);const t=new p(n.url,{handshakeTimeout:15e3,headers:{"X-Runtime-Token":n.token}});e.ws=t,t.on("open",()=>{i.info("[TunnelClient] \u96A7\u9053\u8FDE\u63A5\u5DF2\u5EFA\u7ACB: server=",e.serverUrl,"instanceId=",r),e.reconnectTimer&&clearTimeout(e.reconnectTimer),e.reconnectTimer=void 0,e.reconnectAttempts=0,e.timer=setInterval(()=>{t.readyState===p.OPEN&&t.send(JSON.stringify({t:"ping"}))},W)}),t.on("unexpected-response",(o,c)=>{i.error("[TunnelClient] \u670D\u52A1\u7AEF\u62D2\u7EDD\u8FDE\u63A5\uFF08\u975E 101 \u54CD\u5E94\uFF09: server=",e.serverUrl,"statusCode=",c.statusCode,"statusMessage=",c.statusMessage)}),t.on("upgrade",o=>{i.debug("[TunnelClient] \u6536\u5230\u5347\u7EA7\u54CD\u5E94: statusCode=",o.statusCode)}),t.on("message",o=>{let c;typeof o=="string"?c=o:Buffer.isBuffer(o)?c=o.toString("utf-8"):c=Buffer.from(o).toString("utf-8");try{const l=JSON.parse(c);Y(e,l)}catch(l){i.warn("[TunnelClient] \u89E3\u6790\u96A7\u9053\u6D88\u606F\u5931\u8D25:",String(l))}}),t.on("close",(o,c)=>{if(i.warn("[TunnelClient] \u96A7\u9053\u8FDE\u63A5\u5173\u95ED: server=",e.serverUrl,"code=",o,"reason=",String(c)),B(e),o===G){i.warn("[TunnelClient] \u9274\u6743\u5931\u8D25\uFF084001\uFF09\uFF0C\u505C\u6B62\u81EA\u52A8\u91CD\u8FDE\uFF1B\u5F85\u91CD\u65B0\u6CE8\u518C\u540E\u518D\u542F\u52A8\u96A7\u9053: server=",e.serverUrl);return}b(e)}),t.on("error",o=>{i.warn("[TunnelClient] \u96A7\u9053\u8FDE\u63A5\u9519\u8BEF: server=",e.serverUrl,"err=",o.message,"code=",o.code),B(e),b(e)})}function B(e){e.timer&&(clearInterval(e.timer),e.timer=void 0);for(const[r,n]of e.streams.entries()){try{n.ws.close(1011,"tunnel disconnected")}catch{}e.streams.delete(r)}e.ws=void 0}function b(e){if(e.shuttingDown||e.reconnectTimer)return;const r=(e.reconnectAttempts??0)+1;e.reconnectAttempts=r;const n=Math.min(P*Math.pow(2,r-1),$),t=1-k+Math.random()*k*2,o=Math.round(n*t);i.debug("[TunnelClient] \u8BA1\u5212\u91CD\u8FDE: server=",e.serverUrl,"attempt=",r,"delayMs=",o),e.reconnectTimer=setTimeout(()=>{e.reconnectTimer=void 0,A(e)},o)}function Y(e,r){switch(r.t){case"req":j(e,r);break;case"wsopen":z(e,r);break;case"wsmsg":F(e,r);break;case"wsclose":V(e,r);break;case"ping":f(e,{t:"pong"});break;case"pong":break;default:i.debug("[TunnelClient] \u672A\u77E5\u6D88\u606F\u7C7B\u578B: t=",r.t)}}async function j(e,r){const n=r.id,t=r.method||"GET",o=r.path||"/",c=`http://127.0.0.1:${_()}${o}`;try{const l=r.body?Buffer.from(r.body,"base64"):void 0,s={};if(r.headers)for(const[d,u]of Object.entries(r.headers))u&&u.length>0&&(s[d]=u[0]);s["x-bridge-tunnel-source"]=e.serverUrl;const a=await I.request({url:c,method:t,headers:s,data:l,timeout:0,responseType:"stream",validateStatus:()=>!0}),m={};for(const[d,u]of Object.entries(a.headers))u!==void 0&&(m[d]=Array.isArray(u)?u:[String(u)]);const v=a.data,M=String(m["content-type"]?.[0]||"").toLowerCase().includes("text/event-stream"),g=[];let w=0,T=!1,y=!1;try{if(v)for await(const d of v){const u=Buffer.isBuffer(d)?d:Buffer.from(d);if(u.length!==0){if(T){if(!E(e,n,u))return}else if(M){if(T=!0,y=!0,!f(e,{t:"res",id:n,status:a.status,headers:m,body:null,chunked:!0})||!E(e,n,u))return}else if(g.push(u),w+=u.length,w>H){if(T=!0,y=!0,!f(e,{t:"res",id:n,status:a.status,headers:m,body:null,chunked:!0}))return;for(const R of g)if(!E(e,n,R))return;g.length=0,w=0}}}}catch(d){const u=d instanceof Error?d.message:String(d);i.warn("[TunnelClient] \u672C\u5730\u6D41\u8BFB\u53D6\u4E2D\u65AD:",t,o,"->",u),y?f(e,{t:"resend",id:n,error:u}):f(e,{t:"res",id:n,status:502,headers:{"content-type":["text/plain; charset=utf-8"]},body:Buffer.from(u).toString("base64")});return}if(T){f(e,{t:"resend",id:n});return}const N=w>0?Buffer.concat(g).toString("base64"):"";f(e,{t:"res",id:n,status:a.status,headers:m,body:N||null})}catch(l){const s=l instanceof O?l.message:String(l);i.warn("[TunnelClient] \u672C\u5730\u8F6C\u53D1\u5931\u8D25:",t,o,"->",s),f(e,{t:"res",id:n,status:502,headers:{"content-type":["text/plain; charset=utf-8"]},body:Buffer.from(s).toString("base64")})}}function E(e,r,n){let t=0;for(;t<n.length;){const o=n.subarray(t,t+K);if(!f(e,{t:"reschunk",id:r,d:o.toString("base64")}))return!1;t+=o.length}return!0}function z(e,r){const n=r.id,t=r.path||"/",o=`ws://127.0.0.1:${_()}${t}`;let c;try{c=new p(o,{handshakeTimeout:1e4})}catch(s){i.warn("[TunnelClient] \u672C\u5730 WS \u8FDE\u63A5\u5931\u8D25:",String(s)),f(e,{t:"wsclose",id:n,code:1011,reason:"local ws connect failed"});return}const l={ws:c,pending:[]};e.streams.set(n,l),c.on("open",()=>{for(const s of l.pending)U(l,s.data,s.bin);l.pending=[],f(e,{t:"wsopened",id:n})}),c.on("message",(s,a)=>{const m=Buffer.isBuffer(s)?s:Buffer.from(s);a&&e.ws&&e.ws.bufferedAmount>q||f(e,{t:"wsmsg",id:n,bin:a,d:m.toString("base64")})}),c.on("close",(s,a)=>{e.streams.delete(n),f(e,{t:"wsclose",id:n,code:s,reason:String(a)})}),c.on("error",s=>{i.warn("[TunnelClient] \u672C\u5730 WS \u9519\u8BEF: id=",n,"err=",s.message),e.streams.delete(n);try{c.close(1011,s.message)}catch{}f(e,{t:"wsclose",id:n,code:1011,reason:s.message})})}function U(e,r,n){n?e.ws.send(r):e.ws.send(r.toString("utf-8"))}function F(e,r){const n=e.streams.get(r.id);if(!n)return;const t=r.d?Buffer.from(r.d,"base64"):Buffer.alloc(0);if(n.ws.readyState!==p.OPEN){n.pending.length>=J&&(n.pending.shift(),i.warn("[TunnelClient] \u672C\u5730 WS \u672A\u5C31\u7EEA\uFF0C\u6392\u961F\u6D88\u606F\u8D85\u4E0A\u9650\uFF0C\u4E22\u5F03\u6700\u65E7\u4E00\u6761: id=",r.id)),n.pending.push({data:t,bin:!!r.bin});return}U(n,t,!!r.bin)}function V(e,r){const n=e.streams.get(r.id);if(n){e.streams.delete(r.id);try{n.ws.close(r.code??1e3,r.reason||"")}catch{}}}function f(e,r){if(!e.ws||e.ws.readyState!==p.OPEN)return!1;try{return e.ws.send(JSON.stringify(r)),!0}catch(n){return i.warn("[TunnelClient] sendJson \u5931\u8D25:",String(n)),!1}}export{oe as startTunnelClient,se as stopTunnelClient,ie as stopTunnelClientForServer,ce as stopTunnelClientsExcept};
1
+ import O,{AxiosError as L}from"axios";import m from"ws";import{getActiveBridgeHttpPort as v}from"../config.js";import{logger as i}from"../utils/logger.js";import{buildTargetKey as S}from"../utils/target-identity.js";import{getRuntimeAccessToken as W,normalizeSchedulerBaseUrl as A}from"./runtime-binding.js";const P=15e3,$=5e3,K=3e4,B=.2,G=200,H=1*1024*1024,J=4001,F=768*1024,X=384*1024,Y=5*6e4,f=new Map;function j(e){const n=e.serverUrl,t=e.instanceId;if(!n||!t)return null;try{const r=new URL(n),o=r.protocol==="https:"?"wss:":"ws:",s=W(n,e.userKey);if(!s)return i.warn("[TunnelClient] \u7F3A\u5C11\u8BE5\u76EE\u6807\u8EAB\u4EFD\u7684 runtime token\uFF0C\u65E0\u6CD5\u5EFA\u7ACB\u96A7\u9053\uFF08\u8BF7\u91CD\u65B0\u6CE8\u518C bridge\uFF09: targetUrl=",n),null;i.debug("[TunnelClient] \u4F7F\u7528 runtime access token \u8FDE\u63A5\u96A7\u9053");const c=new URLSearchParams({instanceId:t});return{url:`${o}//${r.host}/ws/bridge-tunnel?${c.toString()}`,token:s}}catch(r){return i.warn("[TunnelClient] \u65E0\u6CD5\u89E3\u6790 serverUrl:",String(r)),null}}function ce(e,n,t){const r=A(e);if(!r){i.warn("[TunnelClient] serverUrl \u65E0\u6548\uFF0C\u65E0\u6CD5\u542F\u52A8\u96A7\u9053:",e);return}const o=S(r,t),s=f.get(o);s&&(s.shuttingDown=!0,g(s),f.delete(o));const c={serverUrl:r,targetKey:o,userKey:String(t||"").trim()||void 0,instanceId:n,streams:new Map,pendingReqChunks:new Map,shuttingDown:!1};f.set(o,c),M(c)}function le(){for(const e of f.values())e.shuttingDown=!0,g(e);f.clear()}function de(e,n){const t=S(e,n),r=f.get(t);r&&(r.shuttingDown=!0,g(r),f.delete(t),i.info(`[TunnelClient] tunnel stopped: ${t}`))}function fe(e){const n=A(e);if(!n)return;const t=`${n}#`;for(const[r,o]of[...f.entries()])r!==n&&!r.startsWith(t)||(o.shuttingDown=!0,g(o),f.delete(r),i.info(`[TunnelClient] tunnel stopped: ${r}`))}function ae(e){const n=new Set(e.map(t=>String(t||"").trim()).filter(t=>!!t));for(const[t,r]of f.entries())n.has(t)||(i.info(`[TunnelClient] \u76EE\u6807\u5DF2\u4E0D\u5728\u914D\u7F6E\u4E2D\uFF0C\u505C\u6B62\u65E7\u96A7\u9053: ${t}`),r.shuttingDown=!0,g(r),f.delete(t))}function g(e){e.timer&&(clearInterval(e.timer),e.timer=void 0),e.reconnectTimer&&(clearTimeout(e.reconnectTimer),e.reconnectTimer=void 0);for(const[n,t]of e.streams.entries()){try{t.ws.close(1e3,"tunnel client stopped")}catch{}e.streams.delete(n)}if(e.ws){const n=e.ws;e.ws=void 0,n.removeAllListeners(),n.on("error",()=>{});try{n.close(1e3,"tunnel client stopped")}catch{}}}function M(e){if(e.shuttingDown)return;const n=e.instanceId;if(!n)return;const t=j(e);if(!t){k(e);return}i.info("[TunnelClient] \u8FDE\u63A5\u96A7\u9053\u670D\u52A1\u7AEF:",t.url);const r=new m(t.url,{handshakeTimeout:15e3,headers:{"X-Runtime-Token":t.token}});e.ws=r,r.on("open",()=>{i.info("[TunnelClient] \u96A7\u9053\u8FDE\u63A5\u5DF2\u5EFA\u7ACB: server=",e.serverUrl,"instanceId=",n),e.reconnectTimer&&clearTimeout(e.reconnectTimer),e.reconnectTimer=void 0,e.reconnectAttempts=0,e.timer=setInterval(()=>{r.readyState===m.OPEN&&r.send(JSON.stringify({t:"ping"}))},P)}),r.on("unexpected-response",(o,s)=>{i.error("[TunnelClient] \u670D\u52A1\u7AEF\u62D2\u7EDD\u8FDE\u63A5\uFF08\u975E 101 \u54CD\u5E94\uFF09: server=",e.serverUrl,"statusCode=",s.statusCode,"statusMessage=",s.statusMessage)}),r.on("upgrade",o=>{i.debug("[TunnelClient] \u6536\u5230\u5347\u7EA7\u54CD\u5E94: statusCode=",o.statusCode)}),r.on("message",o=>{let s;typeof o=="string"?s=o:Buffer.isBuffer(o)?s=o.toString("utf-8"):s=Buffer.from(o).toString("utf-8");try{const c=JSON.parse(s);q(e,c)}catch(c){i.warn("[TunnelClient] \u89E3\u6790\u96A7\u9053\u6D88\u606F\u5931\u8D25:",String(c))}}),r.on("close",(o,s)=>{if(i.warn("[TunnelClient] \u96A7\u9053\u8FDE\u63A5\u5173\u95ED: server=",e.serverUrl,"code=",o,"reason=",String(s)),b(e),o===J){i.warn("[TunnelClient] \u9274\u6743\u5931\u8D25\uFF084001\uFF09\uFF0C\u505C\u6B62\u81EA\u52A8\u91CD\u8FDE\uFF1B\u5F85\u91CD\u65B0\u6CE8\u518C\u540E\u518D\u542F\u52A8\u96A7\u9053: server=",e.serverUrl);return}k(e)}),r.on("error",o=>{i.warn("[TunnelClient] \u96A7\u9053\u8FDE\u63A5\u9519\u8BEF: server=",e.serverUrl,"err=",o.message,"code=",o.code),b(e),k(e)})}function b(e){e.timer&&(clearInterval(e.timer),e.timer=void 0);for(const[n,t]of e.streams.entries()){try{t.ws.close(1011,"tunnel disconnected")}catch{}e.streams.delete(n)}for(const n of Array.from(e.pendingReqChunks.keys()))E(e,n);e.ws=void 0}function k(e){if(e.shuttingDown||e.reconnectTimer)return;const n=(e.reconnectAttempts??0)+1;e.reconnectAttempts=n;const t=Math.min($*Math.pow(2,n-1),K),r=1-B+Math.random()*B*2,o=Math.round(t*r);i.debug("[TunnelClient] \u8BA1\u5212\u91CD\u8FDE: server=",e.serverUrl,"attempt=",n,"delayMs=",o),e.reconnectTimer=setTimeout(()=>{e.reconnectTimer=void 0,M(e)},o)}function q(e,n){switch(n.t){case"req":n.chunked?z(e,n):I(e,n);break;case"reqchunk":V(e,n);break;case"reqend":Q(e,n);break;case"wsopen":Z(e,n);break;case"wsmsg":ee(e,n);break;case"wsclose":ne(e,n);break;case"ping":d(e,{t:"pong"});break;case"pong":break;default:i.debug("[TunnelClient] \u672A\u77E5\u6D88\u606F\u7C7B\u578B: t=",n.t)}}function z(e,n){E(e,n.id);const t=setTimeout(()=>{i.warn("[TunnelClient] \u8BF7\u6C42\u4F53\u62C6\u5E27\u8D85\u65F6\uFF0C\u4E22\u5F03\u534A\u5305:",n.id),e.pendingReqChunks.delete(n.id)},Y);t.unref?.(),e.pendingReqChunks.set(n.id,{method:n.method||"GET",path:n.path||"/",headers:n.headers,parts:[],timer:t})}function V(e,n){const t=e.pendingReqChunks.get(n.id);if(!t){i.debug("[TunnelClient] \u6536\u5230\u65E0\u4E3B reqchunk\uFF0C\u5DF2\u5FFD\u7565:",n.id);return}n.d&&t.parts.push(Buffer.from(n.d,"base64"))}async function Q(e,n){const t=e.pendingReqChunks.get(n.id);if(!t){i.debug("[TunnelClient] \u6536\u5230\u65E0\u4E3B reqend\uFF0C\u5DF2\u5FFD\u7565:",n.id);return}E(e,n.id);const r=Buffer.concat(t.parts);await I(e,{t:"req",id:n.id,method:t.method,path:t.path,headers:t.headers,body:r.length>0?r.toString("base64"):null})}function E(e,n){const t=e.pendingReqChunks.get(n);t&&(clearTimeout(t.timer),e.pendingReqChunks.delete(n))}async function I(e,n){const t=n.id,r=n.method||"GET",o=n.path||"/",s=`http://127.0.0.1:${v()}${o}`;try{const c=n.body?Buffer.from(n.body,"base64"):void 0,u={};if(n.headers)for(const[a,l]of Object.entries(n.headers))l&&l.length>0&&(u[a]=l[0]);u["x-bridge-tunnel-source"]=e.serverUrl;const h=await O.request({url:s,method:r,headers:u,data:c,timeout:0,responseType:"stream",validateStatus:()=>!0}),p={};for(const[a,l]of Object.entries(h.headers))l!==void 0&&(p[a]=Array.isArray(l)?l:[String(l)]);const R=h.data,U=String(p["content-type"]?.[0]||"").toLowerCase().includes("text/event-stream"),T=[];let w=0,C=!1,y=!1;try{if(R)for await(const a of R){const l=Buffer.isBuffer(a)?a:Buffer.from(a);if(l.length!==0){if(C){if(!_(e,t,l))return}else if(U){if(C=!0,y=!0,!d(e,{t:"res",id:t,status:h.status,headers:p,body:null,chunked:!0})||!_(e,t,l))return}else if(T.push(l),w+=l.length,w>F){if(C=!0,y=!0,!d(e,{t:"res",id:t,status:h.status,headers:p,body:null,chunked:!0}))return;for(const x of T)if(!_(e,t,x))return;T.length=0,w=0}}}}catch(a){const l=a instanceof Error?a.message:String(a);i.warn("[TunnelClient] \u672C\u5730\u6D41\u8BFB\u53D6\u4E2D\u65AD:",r,o,"->",l),y?d(e,{t:"resend",id:t,error:l}):d(e,{t:"res",id:t,status:502,headers:{"content-type":["text/plain; charset=utf-8"]},body:Buffer.from(l).toString("base64")});return}if(C){d(e,{t:"resend",id:t});return}const D=w>0?Buffer.concat(T).toString("base64"):"";d(e,{t:"res",id:t,status:h.status,headers:p,body:D||null})}catch(c){const u=c instanceof L?c.message:String(c);i.warn("[TunnelClient] \u672C\u5730\u8F6C\u53D1\u5931\u8D25:",r,o,"->",u),d(e,{t:"res",id:t,status:502,headers:{"content-type":["text/plain; charset=utf-8"]},body:Buffer.from(u).toString("base64")})}}function _(e,n,t){let r=0;for(;r<t.length;){const o=t.subarray(r,r+X);if(!d(e,{t:"reschunk",id:n,d:o.toString("base64")}))return!1;r+=o.length}return!0}function Z(e,n){const t=n.id,r=n.path||"/",o=`ws://127.0.0.1:${v()}${r}`;let s;try{s=new m(o,{handshakeTimeout:1e4})}catch(u){i.warn("[TunnelClient] \u672C\u5730 WS \u8FDE\u63A5\u5931\u8D25:",String(u)),d(e,{t:"wsclose",id:t,code:1011,reason:"local ws connect failed"});return}const c={ws:s,pending:[]};e.streams.set(t,c),s.on("open",()=>{for(const u of c.pending)N(c,u.data,u.bin);c.pending=[],d(e,{t:"wsopened",id:t})}),s.on("message",(u,h)=>{const p=Buffer.isBuffer(u)?u:Buffer.from(u);h&&e.ws&&e.ws.bufferedAmount>H||d(e,{t:"wsmsg",id:t,bin:h,d:p.toString("base64")})}),s.on("close",(u,h)=>{e.streams.delete(t),d(e,{t:"wsclose",id:t,code:u,reason:String(h)})}),s.on("error",u=>{i.warn("[TunnelClient] \u672C\u5730 WS \u9519\u8BEF: id=",t,"err=",u.message),e.streams.delete(t);try{s.close(1011,u.message)}catch{}d(e,{t:"wsclose",id:t,code:1011,reason:u.message})})}function N(e,n,t){t?e.ws.send(n):e.ws.send(n.toString("utf-8"))}function ee(e,n){const t=e.streams.get(n.id);if(!t)return;const r=n.d?Buffer.from(n.d,"base64"):Buffer.alloc(0);if(t.ws.readyState!==m.OPEN){t.pending.length>=G&&(t.pending.shift(),i.warn("[TunnelClient] \u672C\u5730 WS \u672A\u5C31\u7EEA\uFF0C\u6392\u961F\u6D88\u606F\u8D85\u4E0A\u9650\uFF0C\u4E22\u5F03\u6700\u65E7\u4E00\u6761: id=",n.id)),t.pending.push({data:r,bin:!!n.bin});return}N(t,r,!!n.bin)}function ne(e,n){const t=e.streams.get(n.id);if(t){e.streams.delete(n.id);try{t.ws.close(n.code??1e3,n.reason||"")}catch{}}}function d(e,n){if(!e.ws||e.ws.readyState!==m.OPEN)return!1;try{return e.ws.send(JSON.stringify(n)),!0}catch(t){return i.warn("[TunnelClient] sendJson \u5931\u8D25:",String(t)),!1}}const he={createState(e="http://server.test",n="test-instance"){return{serverUrl:e,targetKey:S(e,void 0),instanceId:n,streams:new Map,pendingReqChunks:new Map,shuttingDown:!1}},dispatch(e,n){q(e,n)},pendingChunkIds(e){return Array.from(e.pendingReqChunks.keys())},activeTargetKeys(){return[...f.keys()]},cleanup(e){b(e)},teardown(e){g(e)}};export{he as __tunnelClientTestHooks,ce as startTunnelClient,le as stopTunnelClient,fe as stopTunnelClientForServer,de as stopTunnelClientForTarget,ae as stopTunnelClientsExcept};
2
2
 
@@ -1,8 +1,14 @@
1
1
 
2
2
  export declare function getUpdateLogPath(): Promise<string>;
3
3
 
4
+
5
+
6
+
4
7
  export declare function appendUpdateLog(text: string): Promise<string>;
5
8
 
9
+
10
+
11
+
6
12
  export declare function readUpdateLog(): Promise<{
7
13
  path: string;
8
14
  content: string;
@@ -1,7 +1,24 @@
1
1
 
2
2
 
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
3
15
  export declare function runUpdateCheck(): Promise<boolean>;
4
16
 
17
+
18
+
19
+
20
+
21
+
5
22
  export declare function startUpdateNotifier(): void;
6
23
 
7
24
  export declare function stopUpdateNotifier(): void;
@@ -1,3 +1,3 @@
1
- import f from"node:fs/promises";import g from"node:path";import E from"axios";import{getRuntimeHomeDir as w}from"../config.js";import{createLogger as A}from"../utils/logger.js";import{checkBridgeUpdate as S}from"../utils/npm-version.js";import{loadConfigs as U,resolveRuntimeBridgeBaseUrl as $}from"./auto-register.js";import{getRuntimeAccessToken as D}from"./runtime-binding.js";import{appendUpdateLog as N}from"./update-log.js";const r=A("update-notifier"),h=6*60*60*1e3,y=3e4,T="\u5F53\u524D\u5BA2\u6237\u7AEFbridge\u53EF\u66F4\u65B0\uFF0C\u8BF7\u53CA\u65F6\u66F4\u65B0~";function v(){return g.join(w(),".aws-bridge","update-notify-state.json")}async function b(){try{const e=await f.readFile(v(),"utf8"),n=JSON.parse(e);return{latestVersion:n.latestVersion,notifiedAt:n.notifiedAt}}catch{return{}}}async function B(e){const n=v();await f.mkdir(g.dirname(n),{recursive:!0}),await f.writeFile(n,`${JSON.stringify(e,null,2)}
2
- `,{encoding:"utf8",mode:384})}async function I(){const e=await S();if(!e.ok||!e.hasUpdate||!e.latestVersion||(await b()).latestVersion===e.latestVersion)return!1;const a=U().filter(t=>t.enabled&&!!t.serverUrl);if(a.length===0)return r.info(`[update-notifier] \u68C0\u6D4B\u5230\u65B0\u7248\u672C v${e.latestVersion}\uFF08\u5F53\u524D v${e.currentVersion}\uFF09\uFF0C\u4F46\u672A\u914D\u7F6E\u4EFB\u4F55\u8C03\u5EA6\u4E2D\u5FC3\uFF0C\u8DF3\u8FC7\u901A\u77E5`),!1;const i=e.currentVersion,l=e.latestVersion,d=a[0]?.instanceName||"",u={eventType:"update-available",bridgeInstanceId:a[0]?.instanceId||"",bridgeInstanceName:d,currentVersion:i,latestVersion:l,message:T},c=await Promise.allSettled(a.map(async t=>{const o=String(t.serverUrl).replace(/\/+$/,""),p=D(o);if(!p)throw r.warn(`[update-notifier] \u8DF3\u8FC7 ${o}\uFF1A\u7F3A\u5C11 runtime access token\uFF08\u672A\u6CE8\u518C\uFF09`),new Error("\u7F3A\u5C11 runtime access token\uFF08\u672A\u6CE8\u518C\uFF09");const _=$(t);await E.post(`${o}/api/runtime/callback/bridge-update-notify`,{...u,bridgeInstanceId:t.instanceId||u.bridgeInstanceId,bridgeInstanceName:t.instanceName||d,runtimeBridgeBaseUrl:_},{headers:{"X-Runtime-Token":p},timeout:1e4})})),m=c.some(t=>t.status==="fulfilled");if(m)await B({latestVersion:l,notifiedAt:new Date().toISOString()}),r.info(`[update-notifier] \u5DF2\u901A\u77E5 ${c.filter(t=>t.status==="fulfilled").length}/${c.length} \u4E2A\u8C03\u5EA6\u4E2D\u5FC3\uFF1Av${i} -> v${l}`),N(`\u68C0\u6D4B\u5230\u65B0\u7248\u672C v${l}\uFF08\u5F53\u524D v${i}\uFF09\uFF0C\u5DF2\u53D1\u9001\u53EF\u66F4\u65B0\u901A\u77E5`).catch(()=>{});else{r.warn(`[update-notifier] \u5411 ${c.length} \u4E2A\u8C03\u5EA6\u4E2D\u5FC3\u53D1\u9001\u66F4\u65B0\u901A\u77E5\u5747\u5931\u8D25\uFF0C\u5C06\u5728\u4E0B\u4E2A\u5468\u671F\u91CD\u8BD5`);for(const[t,o]of c.entries())o.status==="rejected"&&r.warn(`[update-notifier] \u901A\u77E5\u5931\u8D25: ${a[t]?.serverUrl}, ${o.reason?.message}`)}return m}let s=null;function M(){if(process.env.AWS_BRIDGE_UPDATE_CHECK_DISABLED==="true"){r.info("[update-notifier] \u7248\u672C\u68C0\u67E5\u5DF2\u901A\u8FC7 AWS_BRIDGE_UPDATE_CHECK_DISABLED \u5173\u95ED");return}if(s)return;const e=Number(process.env.AWS_BRIDGE_UPDATE_CHECK_INTERVAL_HOURS),n=Number.isFinite(e)&&e>0?e*60*60*1e3:h;setTimeout(()=>{I().catch(i=>{r.warn(`[update-notifier] \u68C0\u67E5\u5F02\u5E38: ${i?.message}`)})},y).unref?.(),s=setInterval(()=>{I().catch(i=>{r.warn(`[update-notifier] \u68C0\u67E5\u5F02\u5E38: ${i?.message}`)})},n),s.unref?.(),r.info(`[update-notifier] \u7248\u672C\u68C0\u67E5\u5B9A\u65F6\u4EFB\u52A1\u5DF2\u542F\u52A8\uFF0C\u95F4\u9694 ${Math.round(n/36e5)} \u5C0F\u65F6`)}function O(){s&&(clearInterval(s),s=null)}export{I as runUpdateCheck,M as startUpdateNotifier,O as stopUpdateNotifier};
1
+ import d from"node:fs/promises";import g from"node:path";import E from"axios";import{getRuntimeHomeDir as w}from"../config.js";import{createLogger as A}from"../utils/logger.js";import{checkBridgeUpdate as S}from"../utils/npm-version.js";import{loadConfigs as U,resolveRuntimeBridgeBaseUrl as $}from"./auto-register.js";import{getRuntimeAccessToken as D}from"./runtime-binding.js";import{appendUpdateLog as N}from"./update-log.js";const r=A("update-notifier"),h=6*60*60*1e3,y=3e4,T="\u5F53\u524D\u5BA2\u6237\u7AEFbridge\u53EF\u66F4\u65B0\uFF0C\u8BF7\u53CA\u65F6\u66F4\u65B0~";function v(){return g.join(w(),".aws-bridge","update-notify-state.json")}async function b(){try{const e=await d.readFile(v(),"utf8"),n=JSON.parse(e);return{latestVersion:n.latestVersion,notifiedAt:n.notifiedAt}}catch{return{}}}async function B(e){const n=v();await d.mkdir(g.dirname(n),{recursive:!0}),await d.writeFile(n,`${JSON.stringify(e,null,2)}
2
+ `,{encoding:"utf8",mode:384})}async function I(){const e=await S();if(!e.ok||!e.hasUpdate||!e.latestVersion||(await b()).latestVersion===e.latestVersion)return!1;const a=U().filter(t=>t.enabled&&!!t.serverUrl);if(a.length===0)return r.info(`[update-notifier] \u68C0\u6D4B\u5230\u65B0\u7248\u672C v${e.latestVersion}\uFF08\u5F53\u524D v${e.currentVersion}\uFF09\uFF0C\u4F46\u672A\u914D\u7F6E\u4EFB\u4F55\u8C03\u5EA6\u4E2D\u5FC3\uFF0C\u8DF3\u8FC7\u901A\u77E5`),!1;const i=e.currentVersion,l=e.latestVersion,f=a[0]?.instanceName||"",u={eventType:"update-available",bridgeInstanceId:a[0]?.instanceId||"",bridgeInstanceName:f,currentVersion:i,latestVersion:l,message:T},c=await Promise.allSettled(a.map(async t=>{const s=String(t.serverUrl).replace(/\/+$/,""),p=D(s,t.userKey);if(!p)throw r.warn(`[update-notifier] \u8DF3\u8FC7 ${s}\uFF1A\u7F3A\u5C11 runtime access token\uFF08\u672A\u6CE8\u518C\uFF09`),new Error("\u7F3A\u5C11 runtime access token\uFF08\u672A\u6CE8\u518C\uFF09");const _=$(t);await E.post(`${s}/api/runtime/callback/bridge-update-notify`,{...u,bridgeInstanceId:t.instanceId||u.bridgeInstanceId,bridgeInstanceName:t.instanceName||f,runtimeBridgeBaseUrl:_},{headers:{"X-Runtime-Token":p},timeout:1e4})})),m=c.some(t=>t.status==="fulfilled");if(m)await B({latestVersion:l,notifiedAt:new Date().toISOString()}),r.info(`[update-notifier] \u5DF2\u901A\u77E5 ${c.filter(t=>t.status==="fulfilled").length}/${c.length} \u4E2A\u8C03\u5EA6\u4E2D\u5FC3\uFF1Av${i} -> v${l}`),N(`\u68C0\u6D4B\u5230\u65B0\u7248\u672C v${l}\uFF08\u5F53\u524D v${i}\uFF09\uFF0C\u5DF2\u53D1\u9001\u53EF\u66F4\u65B0\u901A\u77E5`).catch(()=>{});else{r.warn(`[update-notifier] \u5411 ${c.length} \u4E2A\u8C03\u5EA6\u4E2D\u5FC3\u53D1\u9001\u66F4\u65B0\u901A\u77E5\u5747\u5931\u8D25\uFF0C\u5C06\u5728\u4E0B\u4E2A\u5468\u671F\u91CD\u8BD5`);for(const[t,s]of c.entries())s.status==="rejected"&&r.warn(`[update-notifier] \u901A\u77E5\u5931\u8D25: ${a[t]?.serverUrl}, ${s.reason?.message}`)}return m}let o=null;function M(){if(process.env.AWS_BRIDGE_UPDATE_CHECK_DISABLED==="true"){r.info("[update-notifier] \u7248\u672C\u68C0\u67E5\u5DF2\u901A\u8FC7 AWS_BRIDGE_UPDATE_CHECK_DISABLED \u5173\u95ED");return}if(o)return;const e=Number(process.env.AWS_BRIDGE_UPDATE_CHECK_INTERVAL_HOURS),n=Number.isFinite(e)&&e>0?e*60*60*1e3:h;setTimeout(()=>{I().catch(i=>{r.warn(`[update-notifier] \u68C0\u67E5\u5F02\u5E38: ${i?.message}`)})},y).unref?.(),o=setInterval(()=>{I().catch(i=>{r.warn(`[update-notifier] \u68C0\u67E5\u5F02\u5E38: ${i?.message}`)})},n),o.unref?.(),r.info(`[update-notifier] \u7248\u672C\u68C0\u67E5\u5B9A\u65F6\u4EFB\u52A1\u5DF2\u542F\u52A8\uFF0C\u95F4\u9694 ${Math.round(n/36e5)} \u5C0F\u65F6`)}function O(){o&&(clearInterval(o),o=null)}export{I as runUpdateCheck,M as startUpdateNotifier,O as stopUpdateNotifier};
3
3
 
@@ -0,0 +1,115 @@
1
+
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+ import type { NextFunction, Request, Response } from "express";
27
+ export interface UserScope {
28
+ tenantId: string;
29
+ userId: string;
30
+ }
31
+ export declare const SCOPE_ID_PATTERN: RegExp;
32
+
33
+ export declare const LEGACY_SCOPE: Readonly<UserScope>;
34
+
35
+ export declare const TENANT_HEADER = "x-tenant-id";
36
+ export declare const USER_HEADER = "x-user-id";
37
+ declare module "express-serve-static-core" {
38
+ interface Request {
39
+
40
+ userScope?: UserScope;
41
+ }
42
+ }
43
+
44
+
45
+
46
+
47
+
48
+
49
+
50
+
51
+
52
+ export declare function sanitizeScopeId(id: unknown): string;
53
+
54
+ export declare function isValidScopeId(id: unknown): id is string;
55
+
56
+
57
+
58
+
59
+ export declare function normalizeUserScope(tenantId: unknown, userId: unknown): UserScope | null;
60
+
61
+ export declare function scopeEquals(a: UserScope | null, b: UserScope | null): boolean;
62
+
63
+ export declare function isLegacyScope(scope: UserScope | null): boolean;
64
+
65
+
66
+
67
+
68
+ export declare function isLegacyScopeAllowed(): boolean;
69
+
70
+ export declare function isLegacyFallbackDisabled(): boolean;
71
+
72
+ export declare function getUserScopeRoot(scope: UserScope): string;
73
+
74
+ export declare function getUserAiConfigFile(scope: UserScope): string;
75
+
76
+ export declare function getUserSkillsDir(scope: UserScope): string;
77
+
78
+ export declare function getUserSkillsDeployedDir(scope: UserScope): string;
79
+
80
+ export declare function getUserMcpDir(scope: UserScope): string;
81
+
82
+ export declare function getUserMcpDeployedDir(scope: UserScope): string;
83
+
84
+ export declare function getUserMcpPackagesDir(scope: UserScope): string;
85
+
86
+ export declare function getUserPluginsDir(scope: UserScope): string;
87
+
88
+ export declare function getUserPluginsDeployedDir(scope: UserScope): string;
89
+ export type CapabilityType = "skills" | "mcp" | "plugins";
90
+
91
+ export declare function getUserCapabilityDir(scope: UserScope, type: CapabilityType): string;
92
+
93
+ export declare function getUserCapabilityDefaultsFile(scope: UserScope, type: CapabilityType): string;
94
+
95
+ export declare function getUserCapabilityAgentFile(scope: UserScope, type: CapabilityType, agentId: string): string;
96
+
97
+
98
+
99
+
100
+ export declare function extractUserScope(req: Request): UserScope | null;
101
+
102
+
103
+
104
+
105
+ export declare function resolveUserScope(req: Request, _res: Response, next: NextFunction): void;
106
+
107
+
108
+
109
+
110
+ export declare function requireUserScope(req: Request, res: Response, next: NextFunction): void;
111
+
112
+ export declare function getUserScopeOrThrow(req: Request): UserScope;
113
+
114
+ export declare function setAgentOwnershipChecker(checker: (agentId: string, scope: UserScope) => boolean): void;
115
+ export declare function requireAgentOwnership(req: Request, res: Response, next: NextFunction): void;
@@ -0,0 +1,2 @@
1
+ import n from"node:path";import{getBridgeDataHome as I}from"../config.js";import{loadRuntimeBinding as x}from"./runtime-binding.js";const m=/^[a-zA-Z0-9_.-]+$/,c=Object.freeze({tenantId:"_legacy",userId:"_legacy"}),y="x-tenant-id",U="x-user-id";function s(e){const r=String(e??"").replace(/[^a-zA-Z0-9_.-]/g,"_");return/^\.+$/.test(r)?"_":r.replace(/^\.+/g,"")}function w(e){return typeof e=="string"&&e.length>0&&m.test(e)}function p(e,r){const t=String(e??"").trim(),o=String(r??"").trim();return!t||!o?null:{tenantId:t,userId:o}}function D(e,r){return!e||!r?!1:s(e.tenantId)===s(r.tenantId)&&s(e.userId)===s(r.userId)}function b(e){return D(e,c)}function l(){return String(process.env.AWS_BRIDGE_LEGACY_SCOPE||"").trim().toLowerCase()==="1"}function L(){return String(process.env.AWS_BRIDGE_DISABLE_LEGACY_FALLBACK||"").trim().toLowerCase()==="1"}function _(e){return[s(e.tenantId),s(e.userId)]}function i(e){return n.join(I(),"users",..._(e))}function R(e){return n.join(i(e),"ai","acode.json")}function j(e){return n.join(i(e),"skills")}function O(e){return n.join(j(e),"deployed")}function d(e){return n.join(i(e),"mcp")}function P(e){return n.join(d(e),"deployed")}function B(e){return n.join(d(e),"packages")}function A(e){return n.join(i(e),"plugins")}function F(e){return n.join(A(e),"deployed")}function g(e,r){return n.join(i(e),"capability",r)}function T(e,r){return n.join(g(e,r),"config.json")}function z(e,r,t){return n.join(g(e,r),"agents",`${s(t)}.json`)}function E(...e){for(const r of e){const t=String(r??"").trim();if(t)return t}return""}function u(e){const r=p(e.header(y),e.header(U));if(r)return r;const t=e.body??{};return p(t.tenantId,E(t.ownerUserId,t.userId))}function S(){try{const e=x();return e?.userId?p("_local",e.userId):null}catch{return null}}function G(e,r,t){const o=u(e)??S();o?e.userScope=o:l()&&(e.userScope={...c}),t()}function v(e,r,t){const o=u(e)??S();if(o){e.userScope=o,t();return}if(l()){e.userScope={...c},t();return}r.status(400).json({ok:!1,error:"user-scope-required",message:"\u8BF7\u6C42\u7F3A\u5C11 X-Tenant-Id / X-User-Id\uFF08\u6216\u4F53 tenantId + ownerUserId\uFF09\u8EAB\u4EFD"})}function H(e){const r=e.userScope??u(e);if(!r)throw new Error("user-scope-required: \u8BF7\u6C42\u7F3A\u5C11 (tenantId, userId) \u8EAB\u4EFD");return r}let a=null;function N(e){a=e}function M(e,r,t){const o=String(e.params?.agentId??e.body?.agentId??"").trim();if(!o){t();return}const f=e.userScope??u(e);if(!f){r.status(400).json({ok:!1,error:"user-scope-required",message:"agent \u7EA7\u64CD\u4F5C\u7F3A\u5C11 (tenantId, userId) \u8EAB\u4EFD"});return}if(a&&!a(o,f)){r.status(403).json({ok:!1,error:"agent-ownership-mismatch",message:"\u8BE5\u5B9E\u4F8B\u4E0D\u5C5E\u4E8E\u5F53\u524D\u7528\u6237"});return}t()}export{c as LEGACY_SCOPE,m as SCOPE_ID_PATTERN,y as TENANT_HEADER,U as USER_HEADER,u as extractUserScope,R as getUserAiConfigFile,z as getUserCapabilityAgentFile,T as getUserCapabilityDefaultsFile,g as getUserCapabilityDir,P as getUserMcpDeployedDir,d as getUserMcpDir,B as getUserMcpPackagesDir,F as getUserPluginsDeployedDir,A as getUserPluginsDir,H as getUserScopeOrThrow,i as getUserScopeRoot,O as getUserSkillsDeployedDir,j as getUserSkillsDir,L as isLegacyFallbackDisabled,b as isLegacyScope,l as isLegacyScopeAllowed,w as isValidScopeId,p as normalizeUserScope,M as requireAgentOwnership,v as requireUserScope,G as resolveUserScope,s as sanitizeScopeId,D as scopeEquals,N as setAgentOwnershipChecker};
2
+
@@ -1,4 +1,16 @@
1
1
 
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
2
14
  export interface WindowsServiceConfig {
3
15
  name: string;
4
16
  description: string;
@@ -1,4 +1,7 @@
1
1
 
2
+
3
+
4
+
2
5
  export interface WorkspaceFileItem {
3
6
  name: string;
4
7
  path: string;
@@ -185,16 +188,38 @@ export interface ChmodWorkspaceEntryResult {
185
188
  changedCount: number;
186
189
  }
187
190
 
191
+
192
+
193
+
194
+
195
+
196
+
188
197
  export declare function listWorkspaceDirectory(params: WorkspacePathParams): Promise<ListWorkspaceDirectoryResult>;
189
198
 
199
+
200
+
190
201
  export declare function readWorkspaceFile(params: WorkspaceFileParams): Promise<ReadWorkspaceFileResult>;
191
202
 
203
+
204
+
205
+
206
+
192
207
  export declare function getWorkspaceEntryProperties(params: DeleteWorkspaceEntryParams): Promise<WorkspaceEntryPropertiesResult>;
193
208
 
209
+
210
+
211
+
194
212
  export declare function chmodWorkspaceEntry(params: ChmodWorkspaceEntryParams): Promise<ChmodWorkspaceEntryResult>;
195
213
 
214
+
215
+
216
+
217
+
218
+
196
219
  export declare function previewWorkspaceDocument(params: WorkspaceFileParams): Promise<WorkspaceDocumentPreviewResult>;
197
220
 
221
+
222
+
198
223
  export declare function writeWorkspaceFile(params: WriteWorkspaceFileParams): Promise<{
199
224
  ok: true;
200
225
  workspacePath: string;
@@ -202,6 +227,8 @@ export declare function writeWorkspaceFile(params: WriteWorkspaceFileParams): Pr
202
227
  mtimeMs: number;
203
228
  }>;
204
229
 
230
+
231
+
205
232
  export declare function createWorkspaceEntry(params: CreateWorkspaceEntryParams): Promise<{
206
233
  ok: true;
207
234
  workspacePath: string;
@@ -209,6 +236,8 @@ export declare function createWorkspaceEntry(params: CreateWorkspaceEntryParams)
209
236
  isDirectory: boolean;
210
237
  }>;
211
238
 
239
+
240
+
212
241
  export declare function renameWorkspaceEntry(params: RenameWorkspaceEntryParams): Promise<{
213
242
  ok: true;
214
243
  workspacePath: string;
@@ -216,6 +245,8 @@ export declare function renameWorkspaceEntry(params: RenameWorkspaceEntryParams)
216
245
  targetPath: string;
217
246
  }>;
218
247
 
248
+
249
+
219
250
  export declare function moveWorkspaceEntry(params: MoveWorkspaceEntryParams): Promise<{
220
251
  ok: true;
221
252
  workspacePath: string;
@@ -224,12 +255,16 @@ export declare function moveWorkspaceEntry(params: MoveWorkspaceEntryParams): Pr
224
255
  destinationPath: string;
225
256
  }>;
226
257
 
258
+
259
+
227
260
  export declare function deleteWorkspaceEntry(params: DeleteWorkspaceEntryParams): Promise<{
228
261
  ok: true;
229
262
  workspacePath: string;
230
263
  targetPath: string;
231
264
  }>;
232
265
 
266
+
267
+
233
268
  export declare function uploadWorkspaceFiles(params: UploadWorkspaceFilesParams): Promise<{
234
269
  ok: true;
235
270
  workspacePath: string;
@@ -242,17 +277,46 @@ export declare function uploadWorkspaceFiles(params: UploadWorkspaceFilesParams)
242
277
  }>;
243
278
  }>;
244
279
 
280
+
281
+
245
282
  export declare function resolveWorkspaceDownloadTarget(params: DownloadWorkspaceEntryParams): Promise<WorkspaceDownloadTarget>;
246
283
 
284
+
285
+
247
286
  export declare function streamWorkspaceDirectoryZip(directoryPath: string, output: NodeJS.WritableStream): Promise<void>;
248
287
 
288
+
289
+
290
+
291
+
292
+
293
+
294
+
295
+
296
+
297
+
298
+
249
299
  export declare function zipWorkspaceDirectoryToTemp(directoryPath: string, zipName: string, onProgress?: (zippedBytes: number) => void, shouldCancel?: () => boolean): Promise<string>;
250
300
 
301
+
302
+
251
303
  export declare function extractWorkspaceArchive(params: ExtractWorkspaceArchiveParams): Promise<WorkspaceArchiveExtractResult>;
252
304
 
305
+
306
+
307
+
253
308
  export declare function searchWorkspaceFiles(params: SearchWorkspaceFilesParams): Promise<SearchWorkspaceFilesResult>;
254
309
 
310
+
311
+
312
+
313
+
314
+
315
+
255
316
  export declare function searchWorkspacePaths(params: SearchWorkspacePathsParams): Promise<SearchWorkspacePathsResult>;
256
317
 
318
+
319
+
320
+
257
321
  export declare function replaceWorkspaceFiles(params: ReplaceWorkspaceFilesParams): Promise<ReplaceWorkspaceFilesResult>;
258
322
  export {};