@jingyi0605/codingns4dsh 0.1.0

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 (312) hide show
  1. package/README.md +1114 -0
  2. package/assets/provider-icons/claude-code.png +0 -0
  3. package/assets/provider-icons/codex.png +0 -0
  4. package/assets/provider-icons/command-code.svg +5 -0
  5. package/assets/provider-icons/deepseek-harness.svg +9 -0
  6. package/assets/provider-icons/gemini.png +0 -0
  7. package/assets/provider-icons/grok.png +0 -0
  8. package/assets/provider-icons/kimi.png +0 -0
  9. package/assets/provider-icons/opencode.png +0 -0
  10. package/assets/provider-icons/pi.svg +7 -0
  11. package/data/build/dist/bootstrap/dsh-connection-adapter.d.ts +97 -0
  12. package/data/build/dist/bootstrap/dsh-connection-adapter.js +169 -0
  13. package/data/build/dist/bootstrap/index.d.ts +38 -0
  14. package/data/build/dist/bootstrap/index.js +44 -0
  15. package/data/build/dist/client/account-bar.d.ts +9 -0
  16. package/data/build/dist/client/account-bar.js +398 -0
  17. package/data/build/dist/client/bundle.js +26167 -0
  18. package/data/build/dist/client/cli-catalog.d.ts +24 -0
  19. package/data/build/dist/client/cli-catalog.js +108 -0
  20. package/data/build/dist/client/cli-slots.d.ts +38 -0
  21. package/data/build/dist/client/cli-slots.js +297 -0
  22. package/data/build/dist/client/debug/ui.d.ts +12 -0
  23. package/data/build/dist/client/debug/ui.js +451 -0
  24. package/data/build/dist/client/dsh-h5-bootstrap.d.ts +64 -0
  25. package/data/build/dist/client/dsh-h5-bootstrap.js +293 -0
  26. package/data/build/dist/client/dsh-runtime-version.d.ts +3 -0
  27. package/data/build/dist/client/dsh-runtime-version.js +11 -0
  28. package/data/build/dist/client/external-tool-stream.d.ts +24 -0
  29. package/data/build/dist/client/external-tool-stream.js +114 -0
  30. package/data/build/dist/client/features/cli-adapters.d.ts +7 -0
  31. package/data/build/dist/client/features/cli-adapters.js +215 -0
  32. package/data/build/dist/client/features/debug.d.ts +4 -0
  33. package/data/build/dist/client/features/debug.js +24 -0
  34. package/data/build/dist/client/features/index.d.ts +33 -0
  35. package/data/build/dist/client/features/index.js +44 -0
  36. package/data/build/dist/client/features/lan-access-panel.d.ts +5 -0
  37. package/data/build/dist/client/features/lan-access-panel.js +146 -0
  38. package/data/build/dist/client/features/lan-access.d.ts +9 -0
  39. package/data/build/dist/client/features/lan-access.js +30 -0
  40. package/data/build/dist/client/features/login-protection-panel.d.ts +5 -0
  41. package/data/build/dist/client/features/login-protection-panel.js +91 -0
  42. package/data/build/dist/client/features/login-protection-session.d.ts +6 -0
  43. package/data/build/dist/client/features/login-protection-session.js +25 -0
  44. package/data/build/dist/client/features/login-protection.d.ts +4 -0
  45. package/data/build/dist/client/features/login-protection.js +23 -0
  46. package/data/build/dist/client/features/reverse-proxy-panel.d.ts +9 -0
  47. package/data/build/dist/client/features/reverse-proxy-panel.js +159 -0
  48. package/data/build/dist/client/features/reverse-proxy.d.ts +12 -0
  49. package/data/build/dist/client/features/reverse-proxy.js +112 -0
  50. package/data/build/dist/client/features/terminal-enhancement-panel.d.ts +5 -0
  51. package/data/build/dist/client/features/terminal-enhancement-panel.js +160 -0
  52. package/data/build/dist/client/features/terminal-enhancement.d.ts +4 -0
  53. package/data/build/dist/client/features/terminal-enhancement.js +24 -0
  54. package/data/build/dist/client/features/types.d.ts +58 -0
  55. package/data/build/dist/client/features/types.js +2 -0
  56. package/data/build/dist/client/features/workspace-session-enhancement-panel.d.ts +5 -0
  57. package/data/build/dist/client/features/workspace-session-enhancement-panel.js +66 -0
  58. package/data/build/dist/client/features/workspace-session-enhancement.d.ts +4 -0
  59. package/data/build/dist/client/features/workspace-session-enhancement.js +101 -0
  60. package/data/build/dist/client/h5-bootstrap-entry.d.ts +2 -0
  61. package/data/build/dist/client/h5-bootstrap-entry.js +17 -0
  62. package/data/build/dist/client/index.d.ts +31 -0
  63. package/data/build/dist/client/index.js +98 -0
  64. package/data/build/dist/client/lan-access.d.ts +28 -0
  65. package/data/build/dist/client/lan-access.js +68 -0
  66. package/data/build/dist/client/locale.d.ts +20 -0
  67. package/data/build/dist/client/locale.js +393 -0
  68. package/data/build/dist/client/provider-icon-assets.d.ts +2 -0
  69. package/data/build/dist/client/provider-icon-assets.js +23 -0
  70. package/data/build/dist/client/provider-icons.d.ts +19 -0
  71. package/data/build/dist/client/provider-icons.js +39 -0
  72. package/data/build/dist/client/remote-web-context.d.ts +57 -0
  73. package/data/build/dist/client/remote-web-context.js +939 -0
  74. package/data/build/dist/client/session-adapter-cache.d.ts +18 -0
  75. package/data/build/dist/client/session-adapter-cache.js +84 -0
  76. package/data/build/dist/client/settings-bridge.d.ts +32 -0
  77. package/data/build/dist/client/settings-bridge.js +126 -0
  78. package/data/build/dist/client/settings-section.d.ts +30 -0
  79. package/data/build/dist/client/settings-section.js +93 -0
  80. package/data/build/dist/client/subscription-slot.d.ts +18 -0
  81. package/data/build/dist/client/subscription-slot.js +223 -0
  82. package/data/build/dist/client/terminal/index.d.ts +4 -0
  83. package/data/build/dist/client/terminal/index.js +3 -0
  84. package/data/build/dist/client/terminal/model.d.ts +116 -0
  85. package/data/build/dist/client/terminal/model.js +435 -0
  86. package/data/build/dist/client/terminal/styles.d.ts +21 -0
  87. package/data/build/dist/client/terminal/styles.js +51 -0
  88. package/data/build/dist/client/terminal/ui.d.ts +19 -0
  89. package/data/build/dist/client/terminal/ui.js +257 -0
  90. package/data/build/dist/client/terminal/xterm-view.d.ts +13 -0
  91. package/data/build/dist/client/terminal/xterm-view.js +213 -0
  92. package/data/build/dist/client/theme.d.ts +56 -0
  93. package/data/build/dist/client/theme.js +186 -0
  94. package/data/build/dist/client/workspace-session-archive-dom.d.ts +29 -0
  95. package/data/build/dist/client/workspace-session-archive-dom.js +525 -0
  96. package/data/build/dist/client/workspace-session-fiber.d.ts +3 -0
  97. package/data/build/dist/client/workspace-session-fiber.js +33 -0
  98. package/data/build/dist/client/workspace-session-logo-dom.d.ts +26 -0
  99. package/data/build/dist/client/workspace-session-logo-dom.js +128 -0
  100. package/data/build/dist/features/index.d.ts +3 -0
  101. package/data/build/dist/features/index.js +2 -0
  102. package/data/build/dist/features/registry.d.ts +74 -0
  103. package/data/build/dist/features/registry.js +382 -0
  104. package/data/build/dist/features/resource-scope/index.d.ts +39 -0
  105. package/data/build/dist/features/resource-scope/index.js +161 -0
  106. package/data/build/dist/host/auth-session.d.ts +42 -0
  107. package/data/build/dist/host/auth-session.js +186 -0
  108. package/data/build/dist/host/cli-adapters/claude-driver.d.ts +14 -0
  109. package/data/build/dist/host/cli-adapters/claude-driver.js +103 -0
  110. package/data/build/dist/host/cli-adapters/codex-driver.d.ts +45 -0
  111. package/data/build/dist/host/cli-adapters/codex-driver.js +534 -0
  112. package/data/build/dist/host/cli-adapters/command-code-driver.d.ts +38 -0
  113. package/data/build/dist/host/cli-adapters/command-code-driver.js +394 -0
  114. package/data/build/dist/host/cli-adapters/command-code-subscription.d.ts +19 -0
  115. package/data/build/dist/host/cli-adapters/command-code-subscription.js +126 -0
  116. package/data/build/dist/host/cli-adapters/driver.d.ts +41 -0
  117. package/data/build/dist/host/cli-adapters/driver.js +2 -0
  118. package/data/build/dist/host/cli-adapters/dsh-message-projector.d.ts +37 -0
  119. package/data/build/dist/host/cli-adapters/dsh-message-projector.js +180 -0
  120. package/data/build/dist/host/cli-adapters/dsh-tool-history.d.ts +48 -0
  121. package/data/build/dist/host/cli-adapters/dsh-tool-history.js +373 -0
  122. package/data/build/dist/host/cli-adapters/feature.d.ts +7 -0
  123. package/data/build/dist/host/cli-adapters/feature.js +335 -0
  124. package/data/build/dist/host/cli-adapters/gemini-driver.d.ts +24 -0
  125. package/data/build/dist/host/cli-adapters/gemini-driver.js +427 -0
  126. package/data/build/dist/host/cli-adapters/grok-driver.d.ts +38 -0
  127. package/data/build/dist/host/cli-adapters/grok-driver.js +372 -0
  128. package/data/build/dist/host/cli-adapters/http-sse-client.d.ts +22 -0
  129. package/data/build/dist/host/cli-adapters/http-sse-client.js +99 -0
  130. package/data/build/dist/host/cli-adapters/interaction-events.d.ts +11 -0
  131. package/data/build/dist/host/cli-adapters/interaction-events.js +80 -0
  132. package/data/build/dist/host/cli-adapters/json-rpc-process.d.ts +65 -0
  133. package/data/build/dist/host/cli-adapters/json-rpc-process.js +256 -0
  134. package/data/build/dist/host/cli-adapters/kimi-driver.d.ts +21 -0
  135. package/data/build/dist/host/cli-adapters/kimi-driver.js +382 -0
  136. package/data/build/dist/host/cli-adapters/model-catalog.d.ts +22 -0
  137. package/data/build/dist/host/cli-adapters/model-catalog.js +89 -0
  138. package/data/build/dist/host/cli-adapters/opencode-driver.d.ts +55 -0
  139. package/data/build/dist/host/cli-adapters/opencode-driver.js +728 -0
  140. package/data/build/dist/host/cli-adapters/pi-driver.d.ts +43 -0
  141. package/data/build/dist/host/cli-adapters/pi-driver.js +312 -0
  142. package/data/build/dist/host/cli-adapters/process-utils.d.ts +16 -0
  143. package/data/build/dist/host/cli-adapters/process-utils.js +27 -0
  144. package/data/build/dist/host/cli-adapters/provider-subscription.d.ts +82 -0
  145. package/data/build/dist/host/cli-adapters/provider-subscription.js +610 -0
  146. package/data/build/dist/host/cli-adapters/registry.d.ts +95 -0
  147. package/data/build/dist/host/cli-adapters/registry.js +659 -0
  148. package/data/build/dist/host/cli-adapters/rpc-driver-utils.d.ts +24 -0
  149. package/data/build/dist/host/cli-adapters/rpc-driver-utils.js +119 -0
  150. package/data/build/dist/host/cli-adapters/session-probe.d.ts +20 -0
  151. package/data/build/dist/host/cli-adapters/session-probe.js +139 -0
  152. package/data/build/dist/host/cli-adapters/session-store.d.ts +68 -0
  153. package/data/build/dist/host/cli-adapters/session-store.js +180 -0
  154. package/data/build/dist/host/cli-adapters/standard-stream-driver.d.ts +45 -0
  155. package/data/build/dist/host/cli-adapters/standard-stream-driver.js +205 -0
  156. package/data/build/dist/host/cli-adapters/stream-normalizer.d.ts +25 -0
  157. package/data/build/dist/host/cli-adapters/stream-normalizer.js +83 -0
  158. package/data/build/dist/host/cli-adapters/tool-observation.d.ts +9 -0
  159. package/data/build/dist/host/cli-adapters/tool-observation.js +39 -0
  160. package/data/build/dist/host/control-api-client.d.ts +84 -0
  161. package/data/build/dist/host/control-api-client.js +130 -0
  162. package/data/build/dist/host/credential-store.d.ts +54 -0
  163. package/data/build/dist/host/credential-store.js +114 -0
  164. package/data/build/dist/host/debug.d.ts +79 -0
  165. package/data/build/dist/host/debug.js +295 -0
  166. package/data/build/dist/host/dsh-device-runtime.d.ts +39 -0
  167. package/data/build/dist/host/dsh-device-runtime.js +118 -0
  168. package/data/build/dist/host/dsh-gateway-feature.d.ts +5 -0
  169. package/data/build/dist/host/dsh-gateway-feature.js +55 -0
  170. package/data/build/dist/host/dsh-runtime-version.d.ts +12 -0
  171. package/data/build/dist/host/dsh-runtime-version.js +69 -0
  172. package/data/build/dist/host/features/auth.d.ts +11 -0
  173. package/data/build/dist/host/features/auth.js +273 -0
  174. package/data/build/dist/host/features/debug.d.ts +5 -0
  175. package/data/build/dist/host/features/debug.js +90 -0
  176. package/data/build/dist/host/features/host-status.d.ts +12 -0
  177. package/data/build/dist/host/features/host-status.js +54 -0
  178. package/data/build/dist/host/features/index.d.ts +19 -0
  179. package/data/build/dist/host/features/index.js +29 -0
  180. package/data/build/dist/host/features/lan-access-dsh.d.ts +8 -0
  181. package/data/build/dist/host/features/lan-access-dsh.js +45 -0
  182. package/data/build/dist/host/features/terminal-process.d.ts +5 -0
  183. package/data/build/dist/host/features/terminal-process.js +110 -0
  184. package/data/build/dist/host/features/terminal-status.d.ts +18 -0
  185. package/data/build/dist/host/features/terminal-status.js +56 -0
  186. package/data/build/dist/host/features/types.d.ts +41 -0
  187. package/data/build/dist/host/features/types.js +2 -0
  188. package/data/build/dist/host/index.d.ts +43 -0
  189. package/data/build/dist/host/index.js +135 -0
  190. package/data/build/dist/host/lan-access-dsh.d.ts +83 -0
  191. package/data/build/dist/host/lan-access-dsh.js +831 -0
  192. package/data/build/dist/host/native-session-bridge.d.ts +130 -0
  193. package/data/build/dist/host/native-session-bridge.js +317 -0
  194. package/data/build/dist/host/relay-tunnel-runtime.d.ts +97 -0
  195. package/data/build/dist/host/relay-tunnel-runtime.js +361 -0
  196. package/data/build/dist/host/remote-web-runtime.d.ts +78 -0
  197. package/data/build/dist/host/remote-web-runtime.js +559 -0
  198. package/data/build/dist/host/rpc-table.d.ts +32 -0
  199. package/data/build/dist/host/rpc-table.js +47 -0
  200. package/data/build/dist/host/rpc.d.ts +18 -0
  201. package/data/build/dist/host/rpc.js +248 -0
  202. package/data/build/dist/host/settings.d.ts +19 -0
  203. package/data/build/dist/host/settings.js +80 -0
  204. package/data/build/dist/host/terminal/attachment-registry.d.ts +17 -0
  205. package/data/build/dist/host/terminal/attachment-registry.js +49 -0
  206. package/data/build/dist/host/terminal/backends/conpty-backend.d.ts +39 -0
  207. package/data/build/dist/host/terminal/backends/conpty-backend.js +160 -0
  208. package/data/build/dist/host/terminal/backends/local-pty-backend.d.ts +36 -0
  209. package/data/build/dist/host/terminal/backends/local-pty-backend.js +178 -0
  210. package/data/build/dist/host/terminal/backends/tmux-backend.d.ts +40 -0
  211. package/data/build/dist/host/terminal/backends/tmux-backend.js +191 -0
  212. package/data/build/dist/host/terminal/broker/conpty-broker-client.d.ts +27 -0
  213. package/data/build/dist/host/terminal/broker/conpty-broker-client.js +154 -0
  214. package/data/build/dist/host/terminal/broker/conpty-broker-process.d.ts +10 -0
  215. package/data/build/dist/host/terminal/broker/conpty-broker-process.js +147 -0
  216. package/data/build/dist/host/terminal/broker/conpty-broker-protocol.d.ts +92 -0
  217. package/data/build/dist/host/terminal/broker/conpty-broker-protocol.js +134 -0
  218. package/data/build/dist/host/terminal/controller-factory.d.ts +37 -0
  219. package/data/build/dist/host/terminal/controller-factory.js +82 -0
  220. package/data/build/dist/host/terminal/index.d.ts +17 -0
  221. package/data/build/dist/host/terminal/index.js +17 -0
  222. package/data/build/dist/host/terminal/runtime-adapter.d.ts +77 -0
  223. package/data/build/dist/host/terminal/runtime-adapter.js +18 -0
  224. package/data/build/dist/host/terminal/runtime-manager.d.ts +41 -0
  225. package/data/build/dist/host/terminal/runtime-manager.js +179 -0
  226. package/data/build/dist/host/terminal/shell-detection.d.ts +23 -0
  227. package/data/build/dist/host/terminal/shell-detection.js +105 -0
  228. package/data/build/dist/host/terminal/startup.d.ts +33 -0
  229. package/data/build/dist/host/terminal/startup.js +100 -0
  230. package/data/build/dist/host/terminal/terminal-controller.d.ts +78 -0
  231. package/data/build/dist/host/terminal/terminal-controller.js +324 -0
  232. package/data/build/dist/host/terminal/terminal-process-service.d.ts +30 -0
  233. package/data/build/dist/host/terminal/terminal-process-service.js +194 -0
  234. package/data/build/dist/host/terminal/terminal-process-store.d.ts +45 -0
  235. package/data/build/dist/host/terminal/terminal-process-store.js +183 -0
  236. package/data/build/dist/host/terminal/terminal-service.d.ts +87 -0
  237. package/data/build/dist/host/terminal/terminal-service.js +528 -0
  238. package/data/build/dist/host/terminal/terminal-store.d.ts +49 -0
  239. package/data/build/dist/host/terminal/terminal-store.js +242 -0
  240. package/data/build/dist/index.d.ts +37 -0
  241. package/data/build/dist/index.js +26 -0
  242. package/data/build/dist/shared/contracts/auth.d.ts +122 -0
  243. package/data/build/dist/shared/contracts/auth.js +8 -0
  244. package/data/build/dist/shared/contracts/cli-adapter.d.ts +192 -0
  245. package/data/build/dist/shared/contracts/cli-adapter.js +2 -0
  246. package/data/build/dist/shared/contracts/command-code.d.ts +5 -0
  247. package/data/build/dist/shared/contracts/command-code.js +2 -0
  248. package/data/build/dist/shared/contracts/config.d.ts +113 -0
  249. package/data/build/dist/shared/contracts/config.js +86 -0
  250. package/data/build/dist/shared/contracts/debug-config.d.ts +28 -0
  251. package/data/build/dist/shared/contracts/debug-config.js +78 -0
  252. package/data/build/dist/shared/contracts/debug.d.ts +75 -0
  253. package/data/build/dist/shared/contracts/debug.js +121 -0
  254. package/data/build/dist/shared/contracts/dsh-device.d.ts +72 -0
  255. package/data/build/dist/shared/contracts/dsh-device.js +2 -0
  256. package/data/build/dist/shared/contracts/errors.d.ts +33 -0
  257. package/data/build/dist/shared/contracts/errors.js +41 -0
  258. package/data/build/dist/shared/contracts/feature.d.ts +71 -0
  259. package/data/build/dist/shared/contracts/feature.js +2 -0
  260. package/data/build/dist/shared/contracts/host-status.d.ts +14 -0
  261. package/data/build/dist/shared/contracts/host-status.js +2 -0
  262. package/data/build/dist/shared/contracts/lan-access-dsh.d.ts +30 -0
  263. package/data/build/dist/shared/contracts/lan-access-dsh.js +2 -0
  264. package/data/build/dist/shared/contracts/peer-host.d.ts +37 -0
  265. package/data/build/dist/shared/contracts/peer-host.js +9 -0
  266. package/data/build/dist/shared/contracts/signaling.d.ts +67 -0
  267. package/data/build/dist/shared/contracts/signaling.js +2 -0
  268. package/data/build/dist/shared/contracts/subscription.d.ts +69 -0
  269. package/data/build/dist/shared/contracts/subscription.js +2 -0
  270. package/data/build/dist/shared/contracts/terminal-process.d.ts +65 -0
  271. package/data/build/dist/shared/contracts/terminal-process.js +2 -0
  272. package/data/build/dist/shared/contracts/terminal.d.ts +127 -0
  273. package/data/build/dist/shared/contracts/terminal.js +2 -0
  274. package/data/build/dist/shared/contracts/transport.d.ts +45 -0
  275. package/data/build/dist/shared/contracts/transport.js +3 -0
  276. package/data/build/dist/shared/contracts/version.d.ts +19 -0
  277. package/data/build/dist/shared/contracts/version.js +74 -0
  278. package/data/build/dist/shared/index.d.ts +22 -0
  279. package/data/build/dist/shared/index.js +9 -0
  280. package/data/build/dist/transport/carrier.d.ts +38 -0
  281. package/data/build/dist/transport/carrier.js +268 -0
  282. package/data/build/dist/transport/debug.d.ts +22 -0
  283. package/data/build/dist/transport/debug.js +57 -0
  284. package/data/build/dist/transport/dsh-envelope.d.ts +41 -0
  285. package/data/build/dist/transport/dsh-envelope.js +107 -0
  286. package/data/build/dist/transport/dsh-gateway.d.ts +64 -0
  287. package/data/build/dist/transport/dsh-gateway.js +254 -0
  288. package/data/build/dist/transport/dsh-session.d.ts +55 -0
  289. package/data/build/dist/transport/dsh-session.js +256 -0
  290. package/data/build/dist/transport/dsh-transport.d.ts +57 -0
  291. package/data/build/dist/transport/dsh-transport.js +125 -0
  292. package/data/build/dist/transport/frame.d.ts +132 -0
  293. package/data/build/dist/transport/frame.js +168 -0
  294. package/data/build/dist/transport/index.d.ts +11 -0
  295. package/data/build/dist/transport/index.js +11 -0
  296. package/data/build/dist/transport/multiplexer.d.ts +63 -0
  297. package/data/build/dist/transport/multiplexer.js +323 -0
  298. package/data/build/dist/transport/webrtc-client.d.ts +65 -0
  299. package/data/build/dist/transport/webrtc-client.js +255 -0
  300. package/data/build/dist/transport/webrtc-host.d.ts +58 -0
  301. package/data/build/dist/transport/webrtc-host.js +252 -0
  302. package/data/build/dist/typert.host.d.ts +25 -0
  303. package/data/build/dist/typert.host.js +150 -0
  304. package/dsh.bundle.patch +12 -0
  305. package/package.json +135 -0
  306. package/profile/README.md +27 -0
  307. package/profile/cordis.patch.yml +2 -0
  308. package/profile/package.json +20 -0
  309. package/profile/scripts/check-dsh-install.mjs +71 -0
  310. package/profile/version.json +5 -0
  311. package/scripts/check-dsh-install.mjs +88 -0
  312. package/version.json +6 -0
@@ -0,0 +1,293 @@
1
+ import { assertSupportedDshVersion } from '../shared/index.js';
2
+ import { installDshTransport } from '../bootstrap/dsh-connection-adapter.js';
3
+ import { DshSession } from '../transport/dsh-session.js';
4
+ import { DshCodingNsTransport } from '../transport/dsh-transport.js';
5
+ import { connectWebRtcClient } from '../transport/webrtc-client.js';
6
+ import { RemoteDshWebContext } from './remote-web-context.js';
7
+ import { createDshTransportDebugLogger } from '../transport/debug.js';
8
+ import { assertInjectedDshVersion } from './dsh-runtime-version.js';
9
+ /**
10
+ * DSH H5 的最小入口:选择独立 DSH 设备、申请票据、建立 WebRTC,最后才启动远程 DSH。
11
+ * 账号凭据只在 Host RPC 内部使用,浏览器只看到设备摘要和短期票据。
12
+ */
13
+ export async function startDshH5Bootstrap(options) {
14
+ const dshVersion = assertInjectedDshVersion();
15
+ assertSupportedDshVersion(dshVersion);
16
+ const signal = options.signal;
17
+ const debug = createDshTransportDebugLogger({ side: 'h5', component: 'h5-bootstrap' });
18
+ const devices = await callRpc(options.rpc, 'auth/dsh/device/list', {}, signal);
19
+ const device = chooseDshDevice(devices, options.dshDeviceId);
20
+ const ticket = await callRpc(options.rpc, 'auth/dsh/relayTicket', {
21
+ dshDeviceId: device.dshDeviceId,
22
+ ...(options.loginProtectionToken === undefined ? {} : { loginProtectionToken: options.loginProtectionToken }),
23
+ }, signal);
24
+ const connection = await connectWebRtcClient({
25
+ signalingTicket: ticket,
26
+ signalingSocketFactory: (url) => new WebSocket(url),
27
+ peerConnectionFactory: ({ iceServers, iceTransportPolicy }) => createPeerConnection({ iceServers, iceTransportPolicy }),
28
+ debug,
29
+ });
30
+ const generation = 1;
31
+ const hostScope = resolveDshHostScope(ticket);
32
+ const session = new DshSession({ carrier: connection.carrier, role: 'client', generation: String(generation), hostScope, dshVersion, debug });
33
+ const transport = new DshCodingNsTransport({
34
+ carrier: connection.carrier,
35
+ generation: { id: generation, host: { home: '/' } },
36
+ hostScope,
37
+ session,
38
+ requireSessionReady: true,
39
+ debug,
40
+ });
41
+ let registration;
42
+ try {
43
+ session.start();
44
+ await session.waitReady(signal);
45
+ registration = installDshTransport({ dshVersion, transport });
46
+ if (options.boot)
47
+ await options.boot();
48
+ const dispose = async () => {
49
+ registration?.dispose();
50
+ session.close();
51
+ await transport.close();
52
+ await connection.close();
53
+ };
54
+ return { dshDeviceId: device.dshDeviceId, relayMode: ticket.iceTransportPolicy === 'relay' ? 'relay' : 'direct', registration, dispose };
55
+ }
56
+ catch (error) {
57
+ registration?.dispose();
58
+ session.close();
59
+ await transport.close();
60
+ await connection.close();
61
+ throw error;
62
+ }
63
+ }
64
+ /** 独立 H5 页面使用的入口;Control API 会话通过 HttpOnly Cookie 提供。 */
65
+ export async function startDshH5BrowserBootstrap(options) {
66
+ const signal = options.signal;
67
+ const debug = createDshTransportDebugLogger({ side: 'h5', component: 'h5-bootstrap' });
68
+ options.onStatus?.('ticket');
69
+ const devices = await options.controlApi.listDevices(signal);
70
+ const device = chooseDshDevice(devices, options.dshDeviceId);
71
+ let generation = options.generation ?? 1;
72
+ let connection;
73
+ let session;
74
+ let reconnecting = false;
75
+ let stopped = false;
76
+ let reconnectTimer;
77
+ let reconnectRef;
78
+ const clientSessionId = options.clientSessionId?.trim() || undefined;
79
+ const firstTicket = await options.controlApi.createClientTicket(device.dshDeviceId, signal, clientSessionId);
80
+ options.onStatus?.('webrtc');
81
+ connection = await connectWebRtcClient(createWebRtcClientOptions(firstTicket, debug));
82
+ const hostScope = resolveDshHostScope(firstTicket);
83
+ session = new DshSession({ carrier: connection.carrier, role: 'client', generation: String(generation), hostScope, debug });
84
+ const transport = new DshCodingNsTransport({
85
+ carrier: connection.carrier,
86
+ generation: { id: generation, host: { home: '/' } },
87
+ hostScope,
88
+ session,
89
+ requireSessionReady: true,
90
+ reconnect: (reconnectSignal) => reconnectRef?.(reconnectSignal) ?? Promise.reject(new Error('H5 重连尚未就绪')),
91
+ debug,
92
+ });
93
+ const reconnect = async () => {
94
+ if (stopped || reconnecting)
95
+ return;
96
+ reconnecting = true;
97
+ debug.log('bootstrap.reconnect.start', { generation });
98
+ transport.invalidateConnection(new Error('WebRTC connection closed'));
99
+ session?.close('旧 WebRTC generation 已失效');
100
+ try {
101
+ for (let attempt = 0; !stopped; attempt += 1) {
102
+ try {
103
+ const waitMs = Math.min(10_000, 500 * (attempt + 1));
104
+ if (attempt > 0)
105
+ await delay(waitMs, signal);
106
+ options.onStatus?.('ticket');
107
+ const ticket = await options.controlApi.createClientTicket(device.dshDeviceId, signal, clientSessionId);
108
+ debug.log('bootstrap.reconnect.ticket', { generation: generation + 1 });
109
+ options.onStatus?.('webrtc');
110
+ const nextConnection = await connectWebRtcClient(createWebRtcClientOptions(ticket, debug));
111
+ const nextSession = new DshSession({ carrier: nextConnection.carrier, role: 'client', generation: String(generation + 1), hostScope: resolveDshHostScope(ticket), debug });
112
+ nextSession.start();
113
+ await waitForSessionReady(nextSession, signal, 15_000);
114
+ const previous = connection;
115
+ connection = nextConnection;
116
+ session = nextSession;
117
+ generation += 1;
118
+ transport.replaceConnection(nextConnection.carrier, nextSession, { id: generation, host: { home: '/' } });
119
+ attachConnectionClose(nextConnection);
120
+ await previous?.close();
121
+ debug.log('bootstrap.reconnect.ready', { generation });
122
+ options.onStatus?.('remote-web');
123
+ return;
124
+ }
125
+ catch (error) {
126
+ debug.log('bootstrap.reconnect.error', { generation, error: error instanceof Error ? error.message : String(error) });
127
+ if (stopped || signal?.aborted)
128
+ throw error;
129
+ }
130
+ }
131
+ }
132
+ finally {
133
+ reconnecting = false;
134
+ }
135
+ };
136
+ const attachConnectionClose = (current) => {
137
+ current.onClosed((error) => {
138
+ if (stopped || current !== connection)
139
+ return;
140
+ debug.log('bootstrap.connection.closed', { generation, error: error?.message ?? 'closed' });
141
+ reconnectTimer = setTimeout(() => { reconnectTimer = undefined; void reconnect(); }, 50);
142
+ });
143
+ };
144
+ reconnectRef = reconnect;
145
+ attachConnectionClose(connection);
146
+ let webContext;
147
+ try {
148
+ session.start();
149
+ await waitForSessionReady(session, signal, 15_000);
150
+ options.onStatus?.('session-ready');
151
+ if (options.webContext) {
152
+ webContext = new RemoteDshWebContext({ ...options.webContext, transport });
153
+ options.onStatus?.('remote-web');
154
+ await withTimeout(webContext.open(signal), signal, 30_000, '读取远程 DSH Web 超时');
155
+ }
156
+ return {
157
+ dshDeviceId: device.dshDeviceId,
158
+ transport,
159
+ get session() { return session; },
160
+ ...(webContext ? { webContext } : {}),
161
+ dispose: async () => {
162
+ stopped = true;
163
+ if (reconnectTimer !== undefined)
164
+ clearTimeout(reconnectTimer);
165
+ await webContext?.dispose();
166
+ session?.close();
167
+ await transport.close();
168
+ await connection?.close();
169
+ },
170
+ };
171
+ }
172
+ catch (error) {
173
+ await webContext?.dispose();
174
+ stopped = true;
175
+ session?.close();
176
+ await transport.close();
177
+ await connection?.close();
178
+ throw error;
179
+ }
180
+ }
181
+ function createWebRtcClientOptions(ticket, debug) {
182
+ return {
183
+ signalingTicket: ticket,
184
+ signalingSocketFactory: (url) => new WebSocket(url),
185
+ peerConnectionFactory: ({ iceServers, iceTransportPolicy }) => createPeerConnection({ iceServers, iceTransportPolicy }),
186
+ debug,
187
+ };
188
+ }
189
+ async function delay(ms, signal) {
190
+ if (signal?.aborted)
191
+ throw signal.reason instanceof Error ? signal.reason : new Error('请求已取消');
192
+ await new Promise((resolve, reject) => {
193
+ const timer = setTimeout(() => { signal?.removeEventListener('abort', abort); resolve(); }, ms);
194
+ const abort = () => { clearTimeout(timer); signal?.removeEventListener('abort', abort); reject(signal?.reason instanceof Error ? signal.reason : new Error('请求已取消')); };
195
+ signal?.addEventListener('abort', abort, { once: true });
196
+ });
197
+ }
198
+ async function waitForSessionReady(session, signal, timeoutMs) {
199
+ await withTimeout(session.waitReady(signal), signal, timeoutMs, '等待 DSH session.ready 超时');
200
+ }
201
+ async function withTimeout(promise, signal, timeoutMs, message) {
202
+ if (signal?.aborted)
203
+ throw signal.reason instanceof Error ? signal.reason : new Error('请求已取消');
204
+ let timer;
205
+ let removeAbort;
206
+ try {
207
+ return await Promise.race([
208
+ promise,
209
+ new Promise((_, reject) => {
210
+ timer = setTimeout(() => reject(new Error(message)), timeoutMs);
211
+ if (signal) {
212
+ const onAbort = () => reject(signal.reason instanceof Error ? signal.reason : new Error('请求已取消'));
213
+ signal.addEventListener('abort', onAbort, { once: true });
214
+ removeAbort = () => signal.removeEventListener('abort', onAbort);
215
+ }
216
+ }),
217
+ ]);
218
+ }
219
+ finally {
220
+ if (timer !== undefined)
221
+ clearTimeout(timer);
222
+ removeAbort?.();
223
+ }
224
+ }
225
+ /** 使用同源或跨域 HttpOnly Cookie 调用控制站,不读取 Cookie 内容。 */
226
+ export function createHttpDshH5ControlApi(baseUrl = '') {
227
+ const normalizedBaseUrl = baseUrl.replace(/\/+$/u, '');
228
+ return {
229
+ async listDevices(signal) {
230
+ return requestJson(`${normalizedBaseUrl}/api/v1/dsh/devices`, signal === undefined ? {} : { signal });
231
+ },
232
+ async createClientTicket(dshDeviceId, signal, sessionId) {
233
+ return requestJson(`${normalizedBaseUrl}/api/v1/dsh/relay/ticket`, {
234
+ method: 'POST',
235
+ ...(signal === undefined ? {} : { signal }),
236
+ body: { dshDeviceId, role: 'client', ...(sessionId?.trim() ? { sessionId: sessionId.trim() } : {}) },
237
+ });
238
+ },
239
+ };
240
+ }
241
+ export function chooseDshDevice(response, requested) {
242
+ const device = requested === undefined
243
+ ? response.devices.find((item) => item.online && item.status === 'active')
244
+ : response.devices.find((item) => item.dshDeviceId === requested && item.online && item.status === 'active');
245
+ if (!device)
246
+ throw new Error(requested ? `DSH 设备不可用: ${requested}` : '没有可用的 DSH Host');
247
+ return device;
248
+ }
249
+ /**
250
+ * HostScope 是线上 Tunnel 的共享身份,不是两端各自的视角。
251
+ * Host Runtime 当前以 local 作为 canonical kind;旧 Control API 未下发
252
+ * hostScope 时也必须回退到同一值,否则首个 session.hello 会被 Host 拒绝。
253
+ */
254
+ export function resolveDshHostScope(ticket) {
255
+ const scope = ticket.hostScope;
256
+ if (scope !== undefined) {
257
+ if (scope.hostId !== ticket.dshDeviceId)
258
+ throw new Error('DSH Ticket HostScope 与设备不一致');
259
+ return scope;
260
+ }
261
+ return { hostId: ticket.dshDeviceId, kind: 'local' };
262
+ }
263
+ function createPeerConnection(options) {
264
+ const Constructor = globalThis.RTCPeerConnection;
265
+ if (!Constructor)
266
+ throw new Error('当前浏览器不支持 RTCPeerConnection');
267
+ return new Constructor({ iceServers: [...options.iceServers], iceTransportPolicy: options.iceTransportPolicy });
268
+ }
269
+ async function callRpc(rpc, endpoint, payload, signal) {
270
+ let result = await rpc.call('/codingns', endpoint, payload, signal);
271
+ // 旧 Host 在 auth 命名空间下暂时暴露 DSH 动作;迁移期间只允许此兼容回退,
272
+ // 数据和身份仍然使用 DSH 独立 DTO,不会回退到 Codingns4DSH binding。
273
+ if (!result.ok && (result.error.code === 'CODINGNS_RPC_NOT_FOUND' || /未知 Codingns4DSH RPC/u.test(result.error.message))) {
274
+ result = await rpc.call('/codingns', `auth/${endpoint}`, payload, signal);
275
+ }
276
+ if (!result.ok)
277
+ throw new Error(result.error.message);
278
+ return result.value;
279
+ }
280
+ async function requestJson(url, options = {}) {
281
+ const response = await fetch(url, {
282
+ method: options.method ?? 'GET',
283
+ credentials: 'include',
284
+ ...(options.signal === undefined ? {} : { signal: options.signal }),
285
+ headers: { accept: 'application/json', ...(options.body === undefined ? {} : { 'content-type': 'application/json' }) },
286
+ ...(options.body === undefined ? {} : { body: JSON.stringify(options.body) }),
287
+ });
288
+ const data = await response.json().catch(() => ({}));
289
+ if (!response.ok)
290
+ throw new Error(data.detail ?? data.errorCode ?? `Control API 请求失败 (${response.status})`);
291
+ return data;
292
+ }
293
+ //# sourceMappingURL=dsh-h5-bootstrap.js.map
@@ -0,0 +1,3 @@
1
+ /** 读取 Host 注入的真实 DSH 版本,并在无法读取时拒绝启用 Client。 */
2
+ export declare function assertInjectedDshVersion(): string;
3
+ //# sourceMappingURL=dsh-runtime-version.d.ts.map
@@ -0,0 +1,11 @@
1
+ import { assertSupportedDshVersion, CODINGNS_DSH_ERROR_CODES, CODINGNS_DSH_VERSION_GLOBAL, CodingNsDshError, } from '../shared/index.js';
2
+ /** 读取 Host 注入的真实 DSH 版本,并在无法读取时拒绝启用 Client。 */
3
+ export function assertInjectedDshVersion() {
4
+ const value = globalThis[CODINGNS_DSH_VERSION_GLOBAL];
5
+ if (typeof value !== 'string' || value.trim() === '') {
6
+ throw new CodingNsDshError(CODINGNS_DSH_ERROR_CODES.DSH_VERSION_UNSUPPORTED, '无法读取当前 DSH 版本;为避免 Client API 不兼容,已拒绝启用 codingns4dsh');
7
+ }
8
+ assertSupportedDshVersion(value);
9
+ return value;
10
+ }
11
+ //# sourceMappingURL=dsh-runtime-version.js.map
@@ -0,0 +1,24 @@
1
+ import type { CodingNsClientServices } from './features/types.js';
2
+ /** 浏览器收到的 Host 外部工具临时标记。 */
3
+ interface ExternalToolMarker {
4
+ readonly source: 'codingns-external-tool';
5
+ readonly phase: 'start' | 'update';
6
+ readonly callId: string;
7
+ readonly name: string;
8
+ readonly arguments: string;
9
+ readonly status: 'running' | 'completed' | 'failed';
10
+ readonly output?: string;
11
+ readonly error?: string;
12
+ }
13
+ export interface CodingNsExternalToolChatData {
14
+ readonly callId: string;
15
+ readonly name: string;
16
+ readonly arguments: string;
17
+ readonly status: ExternalToolMarker['status'];
18
+ readonly output?: string;
19
+ readonly error?: string;
20
+ }
21
+ /** 启用外部 Agent 时安装实时工具节点;模块停用时同时撤销 Definition 和 Renderer。 */
22
+ export declare function registerExternalToolStreamUi(services: CodingNsClientServices): () => void;
23
+ export {};
24
+ //# sourceMappingURL=external-tool-stream.d.ts.map
@@ -0,0 +1,114 @@
1
+ import { createElement } from 'react';
2
+ import { dshThemeColor } from './theme.js';
3
+ /**
4
+ * 把实时 assistant/live-chunk 工具标记投影成 Chat 节点。
5
+ * assistant/attempt 读取仅为兼容已经存在的旧历史;新 Host 的持久时间线使用原生
6
+ * tool/call 与 tool/result,避免把工具事件误当成模型结算。
7
+ */
8
+ const externalToolDefinition = {
9
+ kind: 'codingns-external-tool',
10
+ target: 'chat',
11
+ match(event) {
12
+ const marker = readMarker(event);
13
+ return marker === null ? null : { id: marker.callId, role: marker.phase === 'start' ? 'start' : 'update' };
14
+ },
15
+ start(_context, match) {
16
+ const marker = readMarker(match.event);
17
+ if (marker === null)
18
+ throw new Error('外部工具节点缺少起始标记');
19
+ return { marker };
20
+ },
21
+ update(context, match) {
22
+ const marker = readMarker(match.event);
23
+ return marker === null ? context.state : { marker };
24
+ },
25
+ buildViewNode(context) {
26
+ const state = context.state;
27
+ if (state === undefined)
28
+ return null;
29
+ const location = context.start?.location ?? context.matches[0]?.location ?? { kind: 'unresolved' };
30
+ return {
31
+ key: context.key,
32
+ kind: 'codingns-external-tool',
33
+ id: context.id,
34
+ target: 'chat',
35
+ anchorSeq: context.start?.event.seq ?? context.matches[0]?.event.seq ?? 0,
36
+ location,
37
+ visibility: 'visible',
38
+ data: state.marker,
39
+ };
40
+ },
41
+ };
42
+ /** 外部工具临时节点的紧凑渲染;持久化后由 DSH 原生工具节点接管。 */
43
+ function ExternalToolNodeView(props) {
44
+ const data = props.node.data;
45
+ const statusLabel = data.status === 'failed' ? '失败' : data.status === 'completed' ? '已完成' : '运行中';
46
+ const output = data.error ?? data.output;
47
+ return createElement('div', {
48
+ style: {
49
+ alignSelf: 'stretch',
50
+ margin: '4px 0',
51
+ padding: '8px 10px',
52
+ border: `1px solid ${data.status === 'failed' ? dshThemeColor.error : dshThemeColor.border}`,
53
+ borderRadius: 6,
54
+ color: dshThemeColor.labelPrimary,
55
+ background: dshThemeColor.inputBackground,
56
+ fontSize: 13,
57
+ lineHeight: 1.45,
58
+ },
59
+ 'data-codingns-external-tool': data.callId,
60
+ }, createElement('div', { style: { display: 'flex', justifyContent: 'space-between', gap: 12, fontWeight: 600 } }, createElement('span', undefined, data.name), createElement('span', { style: { color: data.status === 'failed' ? dshThemeColor.error : dshThemeColor.labelTertiary, fontWeight: 400 } }, statusLabel)), createElement('pre', { style: { margin: '4px 0 0', whiteSpace: 'pre-wrap', wordBreak: 'break-word', fontFamily: 'var(--dsw-font-family-mono, monospace)', color: dshThemeColor.labelSecondary } }, data.arguments), output === undefined || output === '' ? null : createElement('pre', { style: { margin: '6px 0 0', maxHeight: 180, overflow: 'auto', whiteSpace: 'pre-wrap', wordBreak: 'break-word', fontFamily: 'var(--dsw-font-family-mono, monospace)', color: data.status === 'failed' ? dshThemeColor.error : dshThemeColor.labelSecondary } }, output));
61
+ }
62
+ /** 启用外部 Agent 时安装实时工具节点;模块停用时同时撤销 Definition 和 Renderer。 */
63
+ export function registerExternalToolStreamUi(services) {
64
+ const uiConversation = services.uiConversation;
65
+ const slots = services.slots;
66
+ if (uiConversation?.events?.register === undefined || slots === undefined)
67
+ return () => undefined;
68
+ const removeDefinition = uiConversation.events.register(externalToolDefinition);
69
+ const slotRegistry = slots;
70
+ const removeRenderer = slotRegistry.inject('conversation.chat.node', () => slotRegistry.register({
71
+ name: 'conversation.chat.node',
72
+ key: 'codingns-external-tool',
73
+ }, ExternalToolNodeView));
74
+ return () => {
75
+ removeRenderer();
76
+ removeDefinition();
77
+ };
78
+ }
79
+ function readMarker(event) {
80
+ if (!isRecord(event))
81
+ return null;
82
+ const data = event.data;
83
+ if (!isRecord(data))
84
+ return null;
85
+ const candidate = event.type === 'assistant/live-chunk'
86
+ ? isRecord(data.chunk) ? data.chunk.codingnsExternalTool : undefined
87
+ : event.type === 'assistant/attempt'
88
+ ? data.codingnsExternalTool
89
+ : undefined;
90
+ if (!isRecord(candidate) || candidate.source !== 'codingns-external-tool')
91
+ return null;
92
+ if (typeof candidate.callId !== 'string' || candidate.callId === '')
93
+ return null;
94
+ if (typeof candidate.name !== 'string' || typeof candidate.arguments !== 'string')
95
+ return null;
96
+ if (candidate.phase !== 'start' && candidate.phase !== 'update')
97
+ return null;
98
+ if (candidate.status !== 'running' && candidate.status !== 'completed' && candidate.status !== 'failed')
99
+ return null;
100
+ return {
101
+ source: 'codingns-external-tool',
102
+ phase: candidate.phase,
103
+ callId: candidate.callId,
104
+ name: candidate.name,
105
+ arguments: candidate.arguments,
106
+ status: candidate.status,
107
+ ...(typeof candidate.output === 'string' ? { output: candidate.output } : {}),
108
+ ...(typeof candidate.error === 'string' ? { error: candidate.error } : {}),
109
+ };
110
+ }
111
+ function isRecord(value) {
112
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
113
+ }
114
+ //# sourceMappingURL=external-tool-stream.js.map
@@ -0,0 +1,7 @@
1
+ import type { ReactElement } from 'react';
2
+ import type { FeaturePanelProps, CodingNsClientFeatureModule } from './types.js';
3
+ /** 外部 Agent 集成模块。Agent 进程在 Host 运行,浏览器只读取目录和状态。 */
4
+ export declare const cliAdaptersFeature: CodingNsClientFeatureModule;
5
+ /** 设置页中的 Agent 列表和详情模态框。 */
6
+ export declare function CliAdaptersPanel({ services, enabled }: FeaturePanelProps): ReactElement;
7
+ //# sourceMappingURL=cli-adapters.d.ts.map