@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,22 @@
1
+ export { CODINGNS_CONTROL_BASE_URL_FIELD, CODINGNS_CONTROL_BASE_URLS_FIELD, CODINGNS_LAN_ACCESS_DSH_FIELD, CODINGNS_TERMINAL_ENHANCEMENT_FIELD, CODINGNS_WORKSPACE_SESSION_ENHANCEMENT_FIELD, CODINGNS_MODULES_FIELD, CODINGNS_SETTINGS_NAMESPACE, DEFAULT_CODINGNS_CONTROL_BASE_URL, DEFAULT_CODINGNS_CONTROL_BASE_URLS, DEFAULT_CODINGNS_SETTINGS, DEFAULT_TERMINAL_ENHANCEMENT_SETTINGS, DEFAULT_WORKSPACE_SESSION_ENHANCEMENT_SETTINGS, captureRestartFeatureStates, enabledFeatureNames, isFeatureDshVersionCompatible, isFeatureEnabled, type CodingNsSettings, type CodingNsCliAdapterPreference, type LanAccessDshSettings, type LanAccessDshLoginSettings, type LoginProtectionScopes, type RestartFeatureStates, type TerminalAppearanceSettings, type TerminalAppearanceTheme, type TerminalBindingScope, type TerminalCursorStyle, type TerminalEnhancementSettings, type TerminalProfileId, type WorkspaceSessionEnhancementSettings, } from './contracts/config.js';
2
+ export type { FeatureContext, FeatureActivation, FeatureDescriptor, FeatureDisposer, FeatureModule, FeatureResourceScope, FeatureRuntime, FeatureState, FeatureUiDescriptor, } from './contracts/feature.js';
3
+ export { CODINGNS_DSH_ERROR_CODES, CodingNsDshError, SUPPORTED_DSH_COMPATIBILITY, SUPPORTED_DSH_VERSION, assertSupportedDshVersion, type CodingNsDshErrorCode, } from './contracts/errors.js';
4
+ export { CODINGNS_VERSION, DSH_COMPATIBILITY, DSH_PROTOCOL_VERSION, CODINGNS_DSH_VERSION_GLOBAL, DSH_TESTED_VERSION, DSH_VERSION, isDshVersionAtLeast, isLegacyDshVersion, isDshVersionCompatible, } from './contracts/version.js';
5
+ export type { CodingNsRpcRequest, CodingNsStreamRequest, CodingNsTransport, CodingNsTransportErrorShape, CodingNsTransportGeneration, CodingNsTransportHooks, } from './contracts/transport.js';
6
+ export { DSH_ENVELOPE_PROTOCOL, DSH_ENVELOPE_VERSION, DEFAULT_MAX_DSH_ENVELOPE_BYTES, DEFAULT_MAX_DSH_META_BYTES, decodeDshEnvelope, encodeDshEnvelope, validateDshEnvelope, type DshChannel, type DshEnvelope, type DshEnvelopeCodecOptions, type DshEnvelopeFlags, type DshHostScope, } from '../transport/dsh-envelope.js';
7
+ export { CODINGNS_RPC_CHANNEL } from './contracts/transport.js';
8
+ export type { CodingNsCliAdapterDescriptor, CodingNsCliAdapterId, CodingNsCliCapability, CodingNsAgentEvent, CodingNsAgentQuestion, CodingNsAgentQuestionResponse, CodingNsAgentToolEvent, CodingNsCliMessage, CodingNsCliModel, CodingNsCliModelCatalog, CodingNsCliModelGroup, CodingNsAgentPermissionResponse, CodingNsCliSessionConfig, CodingNsCliSessionRecord, CodingNsCliProviderSessionState, CodingNsCliSessionStatus, CodingNsSessionAdapterBinding, CodingNsCliTurnInput, } from './contracts/cli-adapter.js';
9
+ export type { CommandCodeSubscriptionUsage, CommandCodeSubscriptionWindow, } from './contracts/command-code.js';
10
+ export type { CliSubscriptionUsage, CliSubscriptionWindow, Sub2ApiDailyUsage, Sub2ApiModelUsage, Sub2ApiUsage, Sub2ApiUsagePoint, } from './contracts/subscription.js';
11
+ export type { PeerHostRecord, PeerHostStatus, ResourceScopeDisposer, ResourceScopeInput, ResourceScopeRef, ResourceScopeSnapshot, } from './contracts/peer-host.js';
12
+ export { ResourceScopeStaleError } from './contracts/peer-host.js';
13
+ export { DEBUG_ERROR_CODES, DEBUG_RPC_ENDPOINTS, parseDebugMutationScope, parseDebugPtyLaunchRequest, parseDebugRpcScope, type DebugAiFallbackState, type DebugCompatibilityLevel, type DebugErrorCode, type DebugMutationScope, type DebugPortState, type DebugProcessInstance, type DebugProcessOwnership, type DebugPlanState, type DebugProxyProtocol, type DebugPtyLaunchRequest, type DebugRpcEndpoint, type DebugRpcScope, type DebugRuntimeMode, type DebugRuntimeState, } from './contracts/debug.js';
14
+ export type { LanAccessDshConfig, LanAccessDshLoginConfig, LanAccessDshSnapshot, LanAccessDshState, } from './contracts/lan-access-dsh.js';
15
+ export type { CodingNsTerminalCreateRequest, CodingNsTerminalEnvironment, CodingNsTerminalFrame, CodingNsTerminalRetentionFrame, CodingNsTerminalRuntimeType, CodingNsTerminalShell, CodingNsTerminalShellOption, CodingNsTerminalStatus, CodingNsTerminalState, CodingNsWebTerminalInfo, PersistentTerminalRecord, TerminalAttachmentRecord, TerminalOwnerScope, TerminalRecordIdentity, } from './contracts/terminal.js';
16
+ export { EMPTY_DEBUG_CONFIG, parseDebugConfig, type DebugConfig, type DebugProfile, type DebugProxyConfig, type DebugRuntimeType, type DebugShell, } from './contracts/debug-config.js';
17
+ export type { DshDeviceSummary, DshDeviceRegistrationRequest, DshDeviceRegistrationResponse, DshDeviceListResponse, DshDeviceHeartbeatResponse, DshRelayTicketRequest, DshRelayTicketResponse, DshRelayTicketLike, DshIceServer, DshDeviceCredentialRecord, } from './contracts/dsh-device.js';
18
+ export type { TerminalLaunchProfile, TerminalProcessInstance, TerminalProcessLaunchRequest, TerminalProcessLaunchResult, TerminalProcessState, } from './contracts/terminal-process.js';
19
+ export type { AccountProfile, AuthClientType, AuthDeviceManagementSnapshotDto, AuthDeviceViewDto, CodingNsAuthLoginResult, CodingNsAuthSessionSnapshot, CodingNsAuthStatus, HostBindRequest, HostBindResponse, HostBindingsResponse, HostLabelAvailabilityResponse, HostUnbindResponse, LoginByEmailRequest, TunnelBindingSummary, } from './contracts/auth.js';
20
+ export type { RelayIceServer, RelaySignalingTicketRequest, RelaySignalingClientMessage, RelaySignalingServerMessage, RelaySignalingTicketResponse, } from './contracts/signaling.js';
21
+ export type { DshHostStatus } from './contracts/host-status.js';
22
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,9 @@
1
+ export { CODINGNS_CONTROL_BASE_URL_FIELD, CODINGNS_CONTROL_BASE_URLS_FIELD, CODINGNS_LAN_ACCESS_DSH_FIELD, CODINGNS_TERMINAL_ENHANCEMENT_FIELD, CODINGNS_WORKSPACE_SESSION_ENHANCEMENT_FIELD, CODINGNS_MODULES_FIELD, CODINGNS_SETTINGS_NAMESPACE, DEFAULT_CODINGNS_CONTROL_BASE_URL, DEFAULT_CODINGNS_CONTROL_BASE_URLS, DEFAULT_CODINGNS_SETTINGS, DEFAULT_TERMINAL_ENHANCEMENT_SETTINGS, DEFAULT_WORKSPACE_SESSION_ENHANCEMENT_SETTINGS, captureRestartFeatureStates, enabledFeatureNames, isFeatureDshVersionCompatible, isFeatureEnabled, } from './contracts/config.js';
2
+ export { CODINGNS_DSH_ERROR_CODES, CodingNsDshError, SUPPORTED_DSH_COMPATIBILITY, SUPPORTED_DSH_VERSION, assertSupportedDshVersion, } from './contracts/errors.js';
3
+ export { CODINGNS_VERSION, DSH_COMPATIBILITY, DSH_PROTOCOL_VERSION, CODINGNS_DSH_VERSION_GLOBAL, DSH_TESTED_VERSION, DSH_VERSION, isDshVersionAtLeast, isLegacyDshVersion, isDshVersionCompatible, } from './contracts/version.js';
4
+ export { DSH_ENVELOPE_PROTOCOL, DSH_ENVELOPE_VERSION, DEFAULT_MAX_DSH_ENVELOPE_BYTES, DEFAULT_MAX_DSH_META_BYTES, decodeDshEnvelope, encodeDshEnvelope, validateDshEnvelope, } from '../transport/dsh-envelope.js';
5
+ export { CODINGNS_RPC_CHANNEL } from './contracts/transport.js';
6
+ export { ResourceScopeStaleError } from './contracts/peer-host.js';
7
+ export { DEBUG_ERROR_CODES, DEBUG_RPC_ENDPOINTS, parseDebugMutationScope, parseDebugPtyLaunchRequest, parseDebugRpcScope, } from './contracts/debug.js';
8
+ export { EMPTY_DEBUG_CONFIG, parseDebugConfig, } from './contracts/debug-config.js';
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,38 @@
1
+ import { type DshTransportDebugLogger } from './debug.js';
2
+ export declare const TUNNEL_DATA_CHANNEL_LABEL = "codingns-tunnel";
3
+ /** DataChannel 单消息保守上限;实际对端协商值可能只有 256 KiB。 */
4
+ export declare const DATA_CHANNEL_FRAGMENT_PAYLOAD_BYTES: number;
5
+ export declare const DATA_CHANNEL_FRAGMENT_HEADER_BYTES = 20;
6
+ export declare const DATA_CHANNEL_MAX_REASSEMBLY_BYTES: number;
7
+ export interface CodingNsCarrier {
8
+ readonly state: 'connecting' | 'open' | 'closed';
9
+ send(data: Uint8Array): Promise<void>;
10
+ subscribe(listener: (data: Uint8Array) => void): () => void;
11
+ /** 物理 carrier 关闭时通知上层重建 generation;不会携带业务正文。 */
12
+ onClosed?(listener: (reason?: string) => void): () => void;
13
+ close(reason?: string): Promise<void>;
14
+ }
15
+ export interface DataChannelLike {
16
+ readonly label?: string;
17
+ readonly readyState: string;
18
+ binaryType?: string;
19
+ readonly bufferedAmount?: number;
20
+ bufferedAmountLowThreshold?: number;
21
+ send(data: ArrayBuffer | ArrayBufferView): void;
22
+ close(): void;
23
+ addEventListener(type: 'message' | 'close' | 'open' | 'bufferedamountlow', listener: (event: Event) => void): void;
24
+ removeEventListener(type: 'message' | 'close' | 'open' | 'bufferedamountlow', listener: (event: Event) => void): void;
25
+ }
26
+ export interface DataChannelCarrierOptions {
27
+ highWaterMark?: number;
28
+ lowWaterMark?: number;
29
+ backpressureTimeoutMs?: number;
30
+ debug?: DshTransportDebugLogger;
31
+ reassemblyTimeoutMs?: number;
32
+ maxReassemblyBytes?: number;
33
+ }
34
+ /** Host 侧剥离父仓库 relay-tunnel-wire 的首个 hello,随后只转发 DSH Envelope 二进制。 */
35
+ export declare function createRelayTunnelHostCarrier(base: CodingNsCarrier, debug?: DshTransportDebugLogger): CodingNsCarrier;
36
+ /** 将浏览器或 Node WebRTC DataChannel 包装为带背压的二进制 Carrier。 */
37
+ export declare function createDataChannelCarrier(channel: DataChannelLike, options?: DataChannelCarrierOptions): CodingNsCarrier;
38
+ //# sourceMappingURL=carrier.d.ts.map
@@ -0,0 +1,268 @@
1
+ /** DataChannel 二进制 Carrier。所有上层数据必须是 Uint8Array。 */
2
+ import { decodeFrame } from './frame.js';
3
+ import { createDshTransportDebugLogger } from './debug.js';
4
+ export const TUNNEL_DATA_CHANNEL_LABEL = 'codingns-tunnel';
5
+ /** DataChannel 单消息保守上限;实际对端协商值可能只有 256 KiB。 */
6
+ export const DATA_CHANNEL_FRAGMENT_PAYLOAD_BYTES = 64 * 1024;
7
+ export const DATA_CHANNEL_FRAGMENT_HEADER_BYTES = 20;
8
+ export const DATA_CHANNEL_MAX_REASSEMBLY_BYTES = 16 * 1024 * 1024;
9
+ const DATA_CHANNEL_FRAGMENT_MAGIC = new Uint8Array([0x44, 0x53, 0x46, 0x01]);
10
+ /** Host 侧剥离父仓库 relay-tunnel-wire 的首个 hello,随后只转发 DSH Envelope 二进制。 */
11
+ export function createRelayTunnelHostCarrier(base, debug) {
12
+ const logger = debug ?? createDshTransportDebugLogger({ component: 'relay-carrier' });
13
+ let helloSeen = false;
14
+ let failed = false;
15
+ const listeners = new Set();
16
+ const unsubscribe = base.subscribe((data) => {
17
+ if (failed)
18
+ return;
19
+ if (!helloSeen) {
20
+ try {
21
+ const frame = decodeFrame(data);
22
+ if (frame?.type !== 'hello')
23
+ throw new Error('Relay Tunnel 首帧必须是 hello');
24
+ helloSeen = true;
25
+ logger.log('relay.hello.received', { bytes: data.byteLength, frameType: frame.type });
26
+ }
27
+ catch (error) {
28
+ failed = true;
29
+ logger.log('relay.hello.invalid', { bytes: data.byteLength, error: error instanceof Error ? error.message : String(error) });
30
+ void base.close(error instanceof Error ? error.message : 'Relay Tunnel hello 无效');
31
+ }
32
+ return;
33
+ }
34
+ logger.log('carrier.receive', { bytes: data.byteLength });
35
+ for (const listener of [...listeners])
36
+ listener(data);
37
+ });
38
+ return {
39
+ get state() { return failed ? 'closed' : base.state; },
40
+ send(data) {
41
+ if (!helloSeen)
42
+ return Promise.reject(new Error('Relay Tunnel hello 尚未完成'));
43
+ logger.log('carrier.send', { bytes: data.byteLength });
44
+ return base.send(data);
45
+ },
46
+ subscribe(listener) { listeners.add(listener); return () => listeners.delete(listener); },
47
+ onClosed(listener) { return base.onClosed?.(listener) ?? (() => undefined); },
48
+ async close(reason) { unsubscribe(); listeners.clear(); await base.close(reason); },
49
+ };
50
+ }
51
+ /** 将浏览器或 Node WebRTC DataChannel 包装为带背压的二进制 Carrier。 */
52
+ export function createDataChannelCarrier(channel, options = {}) {
53
+ const logger = options.debug ?? createDshTransportDebugLogger({ component: 'data-channel' });
54
+ let state = channel.readyState === 'open' ? 'open' : 'connecting';
55
+ const listeners = new Set();
56
+ const closeListeners = new Set();
57
+ const high = options.highWaterMark ?? 1024 * 1024;
58
+ const low = options.lowWaterMark ?? 256 * 1024;
59
+ const timeoutMs = options.backpressureTimeoutMs ?? 30_000;
60
+ const reassemblyTimeoutMs = options.reassemblyTimeoutMs ?? 30_000;
61
+ const maxReassemblyBytes = options.maxReassemblyBytes ?? DATA_CHANNEL_MAX_REASSEMBLY_BYTES;
62
+ let chain = Promise.resolve();
63
+ let receiveChain = Promise.resolve();
64
+ let nextFragmentId = 0;
65
+ const fragments = new Map();
66
+ try {
67
+ channel.binaryType = 'arraybuffer';
68
+ }
69
+ catch { /* 某些 WebRTC 实现不允许修改 binaryType */ }
70
+ const clearFragments = () => {
71
+ for (const fragment of fragments.values())
72
+ clearTimeout(fragment.timer);
73
+ fragments.clear();
74
+ };
75
+ const onOpen = () => { state = 'open'; logger.log('data-channel.open', { label: channel.label ?? null }); };
76
+ let closeNotified = false;
77
+ const notifyClosed = (reason) => {
78
+ if (closeNotified)
79
+ return;
80
+ closeNotified = true;
81
+ for (const listener of [...closeListeners])
82
+ listener(reason);
83
+ closeListeners.clear();
84
+ };
85
+ const onClose = () => { state = 'closed'; clearFragments(); logger.log('data-channel.close', { label: channel.label ?? null }); notifyClosed('DataChannel closed'); listeners.clear(); };
86
+ const processBytes = (bytes, value) => {
87
+ if (!bytes) {
88
+ logger.log('carrier.receive.invalid', { dataType: Object.prototype.toString.call(value), valueType: typeof value });
89
+ return;
90
+ }
91
+ try {
92
+ const complete = acceptFragment(bytes);
93
+ if (complete === null)
94
+ return;
95
+ logger.log('carrier.receive', { bytes: complete.byteLength, physicalBytes: bytes.byteLength, prefix: bytesToHex(bytes.subarray(0, 8)) });
96
+ for (const listener of [...listeners])
97
+ listener(complete);
98
+ }
99
+ catch (error) {
100
+ logger.log('carrier.fragment.error', { physicalBytes: bytes.byteLength, prefix: bytesToHex(bytes.subarray(0, 8)), error: error instanceof Error ? error.message : String(error) });
101
+ state = 'closed';
102
+ clearFragments();
103
+ listeners.clear();
104
+ channel.close();
105
+ }
106
+ };
107
+ const onMessage = (event) => {
108
+ const value = event.data;
109
+ const result = toBytes(value);
110
+ if (!(result instanceof Promise)) {
111
+ processBytes(result, value);
112
+ return;
113
+ }
114
+ receiveChain = receiveChain.then(() => result).then((bytes) => processBytes(bytes, value)).catch((error) => {
115
+ logger.log('carrier.receive.error', { error: error instanceof Error ? error.message : String(error) });
116
+ });
117
+ };
118
+ channel.addEventListener('open', onOpen);
119
+ channel.addEventListener('close', onClose);
120
+ channel.addEventListener('message', onMessage);
121
+ const waitOpen = () => state === 'open' ? Promise.resolve() : new Promise((resolve, reject) => {
122
+ const timer = setTimeout(() => { cleanup(); reject(new Error('等待 DataChannel open 超时')); }, timeoutMs);
123
+ const cleanup = () => { clearTimeout(timer); channel.removeEventListener('open', onReady); channel.removeEventListener('close', onFail); };
124
+ const onReady = () => { cleanup(); resolve(); };
125
+ const onFail = () => { cleanup(); reject(new Error('DataChannel 已关闭')); };
126
+ channel.addEventListener('open', onReady);
127
+ channel.addEventListener('close', onFail);
128
+ });
129
+ const waitBackpressure = () => {
130
+ if ((channel.bufferedAmount ?? 0) <= high)
131
+ return Promise.resolve();
132
+ logger.log('carrier.backpressure.wait', { bufferedAmount: channel.bufferedAmount ?? 0, highWaterMark: high, lowWaterMark: low });
133
+ return new Promise((resolve, reject) => {
134
+ const timer = setTimeout(() => { cleanup(); reject(new Error('DataChannel 背压等待超时')); }, timeoutMs);
135
+ const check = () => { if ((channel.bufferedAmount ?? 0) <= low) {
136
+ cleanup();
137
+ resolve();
138
+ } };
139
+ const cleanup = () => { clearTimeout(timer); channel.removeEventListener('bufferedamountlow', check); channel.removeEventListener('close', fail); };
140
+ const fail = () => { cleanup(); reject(new Error('DataChannel 已关闭')); };
141
+ channel.bufferedAmountLowThreshold = low;
142
+ channel.addEventListener('bufferedamountlow', check);
143
+ channel.addEventListener('close', fail);
144
+ check();
145
+ });
146
+ };
147
+ const sendPhysical = async (data) => {
148
+ await waitOpen();
149
+ if (state !== 'open')
150
+ throw new Error('Codingns4DSH DataChannel 尚未 ready');
151
+ await waitBackpressure();
152
+ channel.send(data);
153
+ logger.log('carrier.send', { bytes: data.byteLength, bufferedAmount: channel.bufferedAmount ?? 0 });
154
+ };
155
+ const sendLogical = async (data) => {
156
+ if (data.byteLength <= DATA_CHANNEL_FRAGMENT_PAYLOAD_BYTES) {
157
+ await sendPhysical(data);
158
+ return;
159
+ }
160
+ const chunkCount = Math.ceil(data.byteLength / DATA_CHANNEL_FRAGMENT_PAYLOAD_BYTES);
161
+ const fragmentId = nextFragmentId = (nextFragmentId + 1) >>> 0;
162
+ logger.log('carrier.fragment.send', { fragmentId, chunkCount, totalBytes: data.byteLength, payloadBytes: DATA_CHANNEL_FRAGMENT_PAYLOAD_BYTES });
163
+ for (let index = 0; index < chunkCount; index += 1) {
164
+ const start = index * DATA_CHANNEL_FRAGMENT_PAYLOAD_BYTES;
165
+ const chunk = data.subarray(start, Math.min(data.byteLength, start + DATA_CHANNEL_FRAGMENT_PAYLOAD_BYTES));
166
+ await sendPhysical(encodeFragment(fragmentId, index, chunkCount, data.byteLength, chunk));
167
+ }
168
+ };
169
+ const acceptFragment = (data) => {
170
+ if (!isFragment(data))
171
+ return data;
172
+ const parsed = decodeFragment(data, maxReassemblyBytes);
173
+ let assembly = fragments.get(parsed.fragmentId);
174
+ if (!assembly) {
175
+ const timer = setTimeout(() => fragments.delete(parsed.fragmentId), reassemblyTimeoutMs);
176
+ assembly = { totalBytes: parsed.totalBytes, chunkCount: parsed.chunkCount, chunks: new Map(), receivedBytes: 0, timer };
177
+ fragments.set(parsed.fragmentId, assembly);
178
+ logger.log('carrier.fragment.receive', { fragmentId: parsed.fragmentId, chunkCount: parsed.chunkCount, totalBytes: parsed.totalBytes });
179
+ }
180
+ if (assembly.totalBytes !== parsed.totalBytes || assembly.chunkCount !== parsed.chunkCount)
181
+ throw new Error('DataChannel 分片元数据不一致');
182
+ if (assembly.chunks.has(parsed.index))
183
+ return null;
184
+ assembly.chunks.set(parsed.index, parsed.body);
185
+ assembly.receivedBytes += parsed.body.byteLength;
186
+ if (assembly.chunks.size !== assembly.chunkCount)
187
+ return null;
188
+ clearTimeout(assembly.timer);
189
+ fragments.delete(parsed.fragmentId);
190
+ const result = new Uint8Array(assembly.totalBytes);
191
+ let offset = 0;
192
+ for (let index = 0; index < assembly.chunkCount; index += 1) {
193
+ const chunk = assembly.chunks.get(index);
194
+ if (!chunk)
195
+ throw new Error('DataChannel 分片缺失');
196
+ result.set(chunk, offset);
197
+ offset += chunk.byteLength;
198
+ }
199
+ if (offset !== assembly.totalBytes)
200
+ throw new Error('DataChannel 分片总长度不一致');
201
+ logger.log('carrier.fragment.complete', { fragmentId: parsed.fragmentId, chunks: assembly.chunkCount, totalBytes: result.byteLength });
202
+ return result;
203
+ };
204
+ return {
205
+ get state() { return state; },
206
+ send(data) {
207
+ if (!(data instanceof Uint8Array))
208
+ return Promise.reject(new TypeError('Carrier 只接受 Uint8Array'));
209
+ chain = chain.then(() => sendLogical(data));
210
+ return chain;
211
+ },
212
+ subscribe(listener) { listeners.add(listener); return () => listeners.delete(listener); },
213
+ onClosed(listener) { if (closeNotified) {
214
+ listener('DataChannel closed');
215
+ return () => undefined;
216
+ } closeListeners.add(listener); return () => closeListeners.delete(listener); },
217
+ async close(reason) { if (state === 'closed')
218
+ return; state = 'closed'; clearFragments(); notifyClosed(reason ?? 'DataChannel closed'); channel.close(); channel.removeEventListener('open', onOpen); channel.removeEventListener('close', onClose); channel.removeEventListener('message', onMessage); listeners.clear(); },
219
+ };
220
+ }
221
+ function isFragment(data) {
222
+ return data.byteLength >= DATA_CHANNEL_FRAGMENT_HEADER_BYTES
223
+ && DATA_CHANNEL_FRAGMENT_MAGIC.every((value, index) => data[index] === value);
224
+ }
225
+ function encodeFragment(fragmentId, index, chunkCount, totalBytes, body) {
226
+ const result = new Uint8Array(DATA_CHANNEL_FRAGMENT_HEADER_BYTES + body.byteLength);
227
+ result.set(DATA_CHANNEL_FRAGMENT_MAGIC);
228
+ const view = new DataView(result.buffer);
229
+ view.setUint32(4, fragmentId);
230
+ view.setUint32(8, index);
231
+ view.setUint32(12, chunkCount);
232
+ view.setUint32(16, totalBytes);
233
+ result.set(body, DATA_CHANNEL_FRAGMENT_HEADER_BYTES);
234
+ return result;
235
+ }
236
+ function decodeFragment(data, maxReassemblyBytes) {
237
+ const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
238
+ const fragmentId = view.getUint32(4);
239
+ const index = view.getUint32(8);
240
+ const chunkCount = view.getUint32(12);
241
+ const totalBytes = view.getUint32(16);
242
+ if (chunkCount === 0 || totalBytes <= DATA_CHANNEL_FRAGMENT_PAYLOAD_BYTES || totalBytes > maxReassemblyBytes || index >= chunkCount)
243
+ throw new Error('DataChannel 分片头无效');
244
+ const expectedCount = Math.ceil(totalBytes / DATA_CHANNEL_FRAGMENT_PAYLOAD_BYTES);
245
+ if (chunkCount !== expectedCount)
246
+ throw new Error('DataChannel 分片数量无效');
247
+ const offset = index * DATA_CHANNEL_FRAGMENT_PAYLOAD_BYTES;
248
+ const expectedBytes = Math.min(DATA_CHANNEL_FRAGMENT_PAYLOAD_BYTES, totalBytes - offset);
249
+ const body = data.subarray(DATA_CHANNEL_FRAGMENT_HEADER_BYTES);
250
+ if (body.byteLength !== expectedBytes)
251
+ throw new Error('DataChannel 分片长度无效');
252
+ return { fragmentId, index, chunkCount, totalBytes, body: body.slice() };
253
+ }
254
+ function toBytes(value) {
255
+ if (value instanceof Uint8Array)
256
+ return new Uint8Array(value);
257
+ if (value instanceof ArrayBuffer)
258
+ return new Uint8Array(value.slice(0));
259
+ if (ArrayBuffer.isView(value))
260
+ return new Uint8Array(value.buffer.slice(value.byteOffset, value.byteOffset + value.byteLength));
261
+ if (typeof Blob !== 'undefined' && value instanceof Blob)
262
+ return value.arrayBuffer().then((body) => new Uint8Array(body));
263
+ return null;
264
+ }
265
+ function bytesToHex(value) {
266
+ return [...value].map((item) => item.toString(16).padStart(2, '0')).join('');
267
+ }
268
+ //# sourceMappingURL=carrier.js.map
@@ -0,0 +1,22 @@
1
+ /**
2
+ * DSH Tunnel 调试日志。
3
+ *
4
+ * 日志只接受调用方明确传入的协议元数据,禁止把 Envelope body、票据、Cookie
5
+ * 或本地 Web 响应正文交给这个模块。默认关闭,生产环境不会产生额外输出。
6
+ */
7
+ export type DshTransportDebugSide = 'h5' | 'host' | 'relay' | 'unknown';
8
+ export interface DshTransportDebugLogger {
9
+ readonly enabled: boolean;
10
+ log(event: string, fields?: Readonly<Record<string, unknown>>): void;
11
+ }
12
+ export interface DshTransportDebugOptions {
13
+ readonly enabled?: boolean;
14
+ readonly side?: DshTransportDebugSide;
15
+ readonly component?: string;
16
+ readonly sink?: (record: Readonly<Record<string, unknown>>) => void;
17
+ }
18
+ /** 创建一个可注入测试 sink 的调试 logger。默认开关由当前运行环境决定。 */
19
+ export declare function createDshTransportDebugLogger(options?: DshTransportDebugOptions): DshTransportDebugLogger;
20
+ /** 解析 Host 环境变量、H5 URL/localStorage 和调试全局变量。 */
21
+ export declare function resolveDshTransportDebugEnabled(): boolean;
22
+ //# sourceMappingURL=debug.d.ts.map
@@ -0,0 +1,57 @@
1
+ const DEBUG_ENV = 'CODINGNS4DSH_TUNNEL_DEBUG';
2
+ /** 创建一个可注入测试 sink 的调试 logger。默认开关由当前运行环境决定。 */
3
+ export function createDshTransportDebugLogger(options = {}) {
4
+ const enabled = options.enabled ?? resolveDshTransportDebugEnabled();
5
+ const side = options.side ?? 'unknown';
6
+ const component = options.component ?? 'transport';
7
+ const sink = options.sink ?? ((record) => {
8
+ // console.info 在 Node 和浏览器中都能稳定显示,并且不会把正文拼进字符串。
9
+ console.info('[codingns4dsh:tunnel]', record);
10
+ });
11
+ return {
12
+ enabled,
13
+ log(event, fields = {}) {
14
+ if (!enabled)
15
+ return;
16
+ sink({
17
+ at: new Date().toISOString(),
18
+ side,
19
+ component,
20
+ event,
21
+ ...fields,
22
+ });
23
+ },
24
+ };
25
+ }
26
+ /** 解析 Host 环境变量、H5 URL/localStorage 和调试全局变量。 */
27
+ export function resolveDshTransportDebugEnabled() {
28
+ const globalValue = globalThis.__CODINGNS4DSH_TUNNEL_DEBUG__;
29
+ if (globalValue !== undefined)
30
+ return parseDebugValue(globalValue);
31
+ if (typeof location !== 'undefined') {
32
+ const queryValue = new URL(location.href).searchParams.get('dshDebug');
33
+ if (queryValue !== null)
34
+ return parseDebugValue(queryValue);
35
+ }
36
+ if (typeof localStorage !== 'undefined') {
37
+ try {
38
+ const stored = localStorage.getItem('codingns4dsh-tunnel-debug');
39
+ if (stored !== null)
40
+ return parseDebugValue(stored);
41
+ }
42
+ catch {
43
+ // 隐私模式或受限 iframe 可能禁止读取 localStorage,继续检查其他来源。
44
+ }
45
+ }
46
+ if (typeof process !== 'undefined')
47
+ return parseDebugValue(process.env[DEBUG_ENV]);
48
+ return false;
49
+ }
50
+ function parseDebugValue(value) {
51
+ if (typeof value === 'boolean')
52
+ return value;
53
+ if (typeof value !== 'string')
54
+ return false;
55
+ return /^(1|true|yes|on)$/iu.test(value.trim());
56
+ }
57
+ //# sourceMappingURL=debug.js.map
@@ -0,0 +1,41 @@
1
+ /** DSH 多路复用层使用的 Host 作用域。 */
2
+ export interface DshHostScope {
3
+ hostId: string;
4
+ hostLabel?: string;
5
+ workspaceId?: string;
6
+ sessionId?: string;
7
+ kind: 'local' | 'remote';
8
+ }
9
+ export type DshChannel = 'session' | 'rpc' | 'adapter' | 'pty' | 'task' | 'file' | 'port' | 'peerhost' | 'plugin' | 'web';
10
+ export interface DshEnvelopeFlags {
11
+ endOfStream?: boolean;
12
+ cancelled?: boolean;
13
+ binary?: boolean;
14
+ }
15
+ /** DSH 业务层的统一消息格式。body 永远是原始二进制,不在这里做 Base64。 */
16
+ export interface DshEnvelope {
17
+ version: 1;
18
+ messageId: string;
19
+ streamId: string;
20
+ channel: DshChannel;
21
+ type: string;
22
+ sequence: number;
23
+ generation: string;
24
+ hostScope: DshHostScope;
25
+ flags?: DshEnvelopeFlags;
26
+ meta: Record<string, unknown>;
27
+ body?: Uint8Array;
28
+ }
29
+ export interface DshEnvelopeCodecOptions {
30
+ maxBytes?: number;
31
+ maxMetaBytes?: number;
32
+ }
33
+ export declare const DSH_ENVELOPE_VERSION: 1;
34
+ export declare const DSH_ENVELOPE_PROTOCOL = "dsh-transport-v1";
35
+ export declare const DEFAULT_MAX_DSH_ENVELOPE_BYTES: number;
36
+ export declare const DEFAULT_MAX_DSH_META_BYTES: number;
37
+ /** 编码为 `DSH1 | 4 字节 JSON 头长度 | JSON 头 | 原始 body`。 */
38
+ export declare function encodeDshEnvelope(envelope: DshEnvelope, options?: DshEnvelopeCodecOptions): Uint8Array;
39
+ export declare function decodeDshEnvelope(data: Uint8Array, options?: DshEnvelopeCodecOptions): DshEnvelope;
40
+ export declare function validateDshEnvelope(value: unknown): asserts value is DshEnvelope;
41
+ //# sourceMappingURL=dsh-envelope.d.ts.map
@@ -0,0 +1,107 @@
1
+ export const DSH_ENVELOPE_VERSION = 1;
2
+ export const DSH_ENVELOPE_PROTOCOL = 'dsh-transport-v1';
3
+ // Web 插件聚合 bundle 可能达到数 MiB;物理 DataChannel 已负责 64 KiB 分片,
4
+ // Envelope 层只限制单条逻辑消息,和 Host 资源上限保持 16 MiB 一致。
5
+ export const DEFAULT_MAX_DSH_ENVELOPE_BYTES = 16 * 1024 * 1024;
6
+ export const DEFAULT_MAX_DSH_META_BYTES = 64 * 1024;
7
+ const MAGIC = new Uint8Array([0x44, 0x53, 0x48, 0x01]);
8
+ const channels = new Set(['session', 'rpc', 'adapter', 'pty', 'task', 'file', 'port', 'peerhost', 'plugin', 'web']);
9
+ /** 编码为 `DSH1 | 4 字节 JSON 头长度 | JSON 头 | 原始 body`。 */
10
+ export function encodeDshEnvelope(envelope, options = {}) {
11
+ validateDshEnvelope(envelope);
12
+ const maxBytes = options.maxBytes ?? DEFAULT_MAX_DSH_ENVELOPE_BYTES;
13
+ const maxMetaBytes = options.maxMetaBytes ?? DEFAULT_MAX_DSH_META_BYTES;
14
+ validateLimit(maxBytes, 'Envelope');
15
+ validateLimit(maxMetaBytes, 'Envelope meta');
16
+ const body = envelope.body ?? new Uint8Array();
17
+ const header = { ...envelope, bodyLength: body.byteLength };
18
+ delete header.body;
19
+ const headerBytes = new TextEncoder().encode(JSON.stringify(header));
20
+ if (headerBytes.byteLength > maxMetaBytes)
21
+ throw new Error('DSH Envelope meta 超过大小限制');
22
+ const result = new Uint8Array(MAGIC.byteLength + 4 + headerBytes.byteLength + body.byteLength);
23
+ result.set(MAGIC, 0);
24
+ new DataView(result.buffer).setUint32(MAGIC.byteLength, headerBytes.byteLength);
25
+ result.set(headerBytes, MAGIC.byteLength + 4);
26
+ result.set(body, MAGIC.byteLength + 4 + headerBytes.byteLength);
27
+ if (result.byteLength > maxBytes)
28
+ throw new Error('DSH Envelope 超过大小限制');
29
+ return result;
30
+ }
31
+ export function decodeDshEnvelope(data, options = {}) {
32
+ const maxBytes = options.maxBytes ?? DEFAULT_MAX_DSH_ENVELOPE_BYTES;
33
+ const maxMetaBytes = options.maxMetaBytes ?? DEFAULT_MAX_DSH_META_BYTES;
34
+ validateLimit(maxBytes, 'Envelope');
35
+ validateLimit(maxMetaBytes, 'Envelope meta');
36
+ if (!(data instanceof Uint8Array))
37
+ throw new Error('DSH Envelope 必须是 Uint8Array');
38
+ if (data.byteLength > maxBytes)
39
+ throw new Error('DSH Envelope 超过大小限制');
40
+ if (data.byteLength < MAGIC.byteLength + 4 || !MAGIC.every((value, index) => data[index] === value)) {
41
+ throw new Error('DSH Envelope magic 无效');
42
+ }
43
+ const headerLength = new DataView(data.buffer, data.byteOffset, data.byteLength).getUint32(MAGIC.byteLength);
44
+ if (headerLength > maxMetaBytes || MAGIC.byteLength + 4 + headerLength > data.byteLength) {
45
+ throw new Error('DSH Envelope 头部长度无效');
46
+ }
47
+ let header;
48
+ try {
49
+ header = JSON.parse(new TextDecoder().decode(data.subarray(MAGIC.byteLength + 4, MAGIC.byteLength + 4 + headerLength)));
50
+ }
51
+ catch (error) {
52
+ throw new Error('DSH Envelope 头部不是有效 JSON', { cause: error });
53
+ }
54
+ if (!header || typeof header !== 'object')
55
+ throw new Error('DSH Envelope 头部无效');
56
+ const value = header;
57
+ const bodyLength = value.bodyLength;
58
+ if (typeof bodyLength !== 'number' || !Number.isSafeInteger(bodyLength) || bodyLength < 0 || MAGIC.byteLength + 4 + headerLength + bodyLength !== data.byteLength) {
59
+ throw new Error('DSH Envelope body 长度无效');
60
+ }
61
+ delete value.bodyLength;
62
+ validateDshEnvelope(value);
63
+ const body = data.subarray(MAGIC.byteLength + 4 + headerLength);
64
+ return body.byteLength === 0 ? value : { ...value, body: body.slice() };
65
+ }
66
+ export function validateDshEnvelope(value) {
67
+ if (!value || typeof value !== 'object')
68
+ throw new Error('DSH Envelope 必须是对象');
69
+ const envelope = value;
70
+ if (envelope.version !== DSH_ENVELOPE_VERSION)
71
+ throw new Error('DSH Envelope 版本不兼容');
72
+ if (typeof envelope.messageId !== 'string' || envelope.messageId.length === 0)
73
+ throw new Error('DSH Envelope messageId 无效');
74
+ if (typeof envelope.streamId !== 'string' || envelope.streamId.length === 0)
75
+ throw new Error('DSH Envelope streamId 无效');
76
+ if (!channels.has(envelope.channel))
77
+ throw new Error('DSH Envelope channel 无效');
78
+ if (typeof envelope.type !== 'string' || envelope.type.length === 0)
79
+ throw new Error('DSH Envelope type 无效');
80
+ if (!Number.isSafeInteger(envelope.sequence) || envelope.sequence < 0)
81
+ throw new Error('DSH Envelope sequence 无效');
82
+ if (typeof envelope.generation !== 'string' || envelope.generation.length === 0)
83
+ throw new Error('DSH Envelope generation 无效');
84
+ validateHostScope(envelope.hostScope);
85
+ if (!envelope.meta || typeof envelope.meta !== 'object' || Array.isArray(envelope.meta))
86
+ throw new Error('DSH Envelope meta 无效');
87
+ if (envelope.body !== undefined && !(envelope.body instanceof Uint8Array))
88
+ throw new Error('DSH Envelope body 必须是 Uint8Array');
89
+ }
90
+ function validateHostScope(scope) {
91
+ if (!scope || typeof scope !== 'object')
92
+ throw new Error('DSH Envelope hostScope 无效');
93
+ const value = scope;
94
+ if (typeof value.hostId !== 'string' || value.hostId.length === 0)
95
+ throw new Error('DSH Envelope hostScope.hostId 无效');
96
+ if (value.kind !== 'local' && value.kind !== 'remote')
97
+ throw new Error('DSH Envelope hostScope.kind 无效');
98
+ for (const key of ['hostLabel', 'workspaceId', 'sessionId']) {
99
+ if (value[key] !== undefined && typeof value[key] !== 'string')
100
+ throw new Error(`DSH Envelope hostScope.${key} 无效`);
101
+ }
102
+ }
103
+ function validateLimit(value, name) {
104
+ if (!Number.isSafeInteger(value) || value <= 0)
105
+ throw new Error(`${name} 大小限制无效`);
106
+ }
107
+ //# sourceMappingURL=dsh-envelope.js.map
@@ -0,0 +1,64 @@
1
+ import type { CodingNsCarrier } from './carrier.js';
2
+ import { type DshChannel, type DshEnvelope, type DshHostScope } from './dsh-envelope.js';
3
+ import { DshSession, type DshSessionOptions } from './dsh-session.js';
4
+ import { type DshTransportDebugLogger } from './debug.js';
5
+ export declare const DSH_GATEWAY_PATH = "/__dsh__/transport/v1";
6
+ export interface DshStreamContext {
7
+ readonly envelope: DshEnvelope;
8
+ readonly session: DshSession;
9
+ send(type: string, meta?: Record<string, unknown>, body?: Uint8Array): void;
10
+ close(): void;
11
+ }
12
+ export interface DshGatewayFeature {
13
+ readonly channel?: DshChannel;
14
+ readonly operation?: string;
15
+ canHandle?(envelope: DshEnvelope): boolean | Promise<boolean>;
16
+ handleStream?(context: DshStreamContext): void | Promise<void> | AsyncIterable<DshEnvelope>;
17
+ handleMessage?(context: DshStreamContext, envelope: DshEnvelope): void | Promise<void>;
18
+ handleWindow?(context: DshStreamContext, envelope: DshEnvelope): void | Promise<void>;
19
+ }
20
+ export interface DshGatewayOptions {
21
+ carrier: CodingNsCarrier;
22
+ session?: DshSession;
23
+ sessionOptions?: Omit<DshSessionOptions, 'carrier'>;
24
+ /** 只依赖 FeatureRegistry 的 modules(),避免把具体 Host services 类型泄漏到传输层。 */
25
+ registry?: {
26
+ modules(): readonly unknown[];
27
+ };
28
+ features?: readonly DshGatewayFeature[];
29
+ hostScope: DshHostScope;
30
+ generation: string;
31
+ /** 当前 DSH 宿主版本;用于没有显式 session 的默认 Gateway。 */
32
+ dshVersion?: string;
33
+ maxStreams?: number;
34
+ debug?: DshTransportDebugLogger;
35
+ }
36
+ /** 将 DSH Session 后的 Envelope 按 streamId 路由到 FeatureRegistry 模块。 */
37
+ export declare class DshGateway {
38
+ private readonly options;
39
+ readonly session: DshSession;
40
+ private readonly streams;
41
+ /**
42
+ * stream.open 的 feature 选择和本地资源创建可能异步完成。
43
+ * 取消帧可以在这段窗口内到达,必须先登记 opening,不能让取消穿透后又把旧流插入 streams。
44
+ */
45
+ private readonly opening;
46
+ private readonly cancelledOpening;
47
+ private readonly maxStreams;
48
+ private readonly features;
49
+ private sequence;
50
+ private started;
51
+ private unsubscribe;
52
+ private readonly debug;
53
+ constructor(options: DshGatewayOptions);
54
+ start(): void;
55
+ close(reason?: string): Promise<void>;
56
+ get path(): string;
57
+ private route;
58
+ private openStream;
59
+ private findFeature;
60
+ private sendError;
61
+ private send;
62
+ private nextSequence;
63
+ }
64
+ //# sourceMappingURL=dsh-gateway.d.ts.map