dsh-ssh-hub 0.0.0-stage → 0.2.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 (133) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +271 -2
  3. package/cordis.patch.yml +16 -0
  4. package/icon.svg +3 -0
  5. package/lib/client.js +13975 -0
  6. package/lib/index.js +6908 -0
  7. package/lib/types/activity/history.d.ts +50 -0
  8. package/lib/types/alerting/notify.d.ts +89 -0
  9. package/lib/types/alerting/prompt-summary.d.ts +28 -0
  10. package/lib/types/alerting/rules.d.ts +135 -0
  11. package/lib/types/alerting/tools.d.ts +30 -0
  12. package/lib/types/audit/audit-log.d.ts +84 -0
  13. package/lib/types/audit/recorder.d.ts +50 -0
  14. package/lib/types/client/api.d.ts +222 -0
  15. package/lib/types/client/index.d.ts +45 -0
  16. package/lib/types/client/locales.d.ts +319 -0
  17. package/lib/types/client/native-panel.d.ts +70 -0
  18. package/lib/types/client/panel/ClusterTab.d.ts +7 -0
  19. package/lib/types/client/panel/DeployTab.d.ts +10 -0
  20. package/lib/types/client/panel/FleetTab.d.ts +10 -0
  21. package/lib/types/client/panel/HostFormDialog.d.ts +12 -0
  22. package/lib/types/client/panel/HostsTab.d.ts +25 -0
  23. package/lib/types/client/panel/LogsTab.d.ts +10 -0
  24. package/lib/types/client/panel/SshPanel.d.ts +14 -0
  25. package/lib/types/client/panel/TerminalTab.d.ts +27 -0
  26. package/lib/types/client/panel/TransferTab.d.ts +7 -0
  27. package/lib/types/client/panel/TunnelEditDialog.d.ts +15 -0
  28. package/lib/types/client/panel/TunnelsTab.d.ts +27 -0
  29. package/lib/types/client/panel/controller.d.ts +253 -0
  30. package/lib/types/client/panel/helpers.d.ts +45 -0
  31. package/lib/types/client/panel/tabs.d.ts +62 -0
  32. package/lib/types/client/panel/xterm.css.d.ts +2 -0
  33. package/lib/types/client/settings-binding.d.ts +71 -0
  34. package/lib/types/deploy/orchestrator.d.ts +158 -0
  35. package/lib/types/deploy/tools.d.ts +14 -0
  36. package/lib/types/dsh-home.d.ts +16 -0
  37. package/lib/types/engine/cluster.d.ts +19 -0
  38. package/lib/types/engine/connection-pool.d.ts +183 -0
  39. package/lib/types/engine/proxy-command.d.ts +36 -0
  40. package/lib/types/engine/pty.d.ts +32 -0
  41. package/lib/types/engine/sftp.d.ts +20 -0
  42. package/lib/types/engine/terminal-sessions.d.ts +67 -0
  43. package/lib/types/engine/tunnel-discovery.d.ts +89 -0
  44. package/lib/types/engine/tunnel-remarks.d.ts +49 -0
  45. package/lib/types/engine/tunnel.d.ts +76 -0
  46. package/lib/types/engine.d.ts +103 -0
  47. package/lib/types/http.d.ts +59 -0
  48. package/lib/types/index.d.ts +128 -0
  49. package/lib/types/inspect/checks.d.ts +118 -0
  50. package/lib/types/inspect/inspection.d.ts +111 -0
  51. package/lib/types/inspect/tools.d.ts +50 -0
  52. package/lib/types/logs/search.d.ts +131 -0
  53. package/lib/types/logs/tools.d.ts +6 -0
  54. package/lib/types/loopback.d.ts +64 -0
  55. package/lib/types/monitor/loop.d.ts +133 -0
  56. package/lib/types/monitor/metrics.d.ts +151 -0
  57. package/lib/types/mount-once.d.ts +55 -0
  58. package/lib/types/protocol.d.ts +524 -0
  59. package/lib/types/routes.d.ts +82 -0
  60. package/lib/types/security/known-hosts.d.ts +153 -0
  61. package/lib/types/security/master-secret.d.ts +157 -0
  62. package/lib/types/security/redact.d.ts +44 -0
  63. package/lib/types/security/secrets.d.ts +70 -0
  64. package/lib/types/ssh-config.d.ts +42 -0
  65. package/lib/types/store.d.ts +183 -0
  66. package/lib/types/tool-surface.d.ts +72 -0
  67. package/lib/types/tools.d.ts +56 -0
  68. package/locale/en.json +6 -0
  69. package/locale/zh.json +6 -0
  70. package/package.json +126 -6
  71. package/src/activity/history.ts +117 -0
  72. package/src/alerting/notify.ts +212 -0
  73. package/src/alerting/prompt-summary.ts +71 -0
  74. package/src/alerting/rules.ts +281 -0
  75. package/src/alerting/tools.ts +263 -0
  76. package/src/audit/audit-log.ts +199 -0
  77. package/src/audit/recorder.ts +73 -0
  78. package/src/client/api.ts +782 -0
  79. package/src/client/css-modules.d.ts +5 -0
  80. package/src/client/index.ts +150 -0
  81. package/src/client/locales.ts +654 -0
  82. package/src/client/native-panel.tsx +141 -0
  83. package/src/client/panel/ClusterTab.tsx +141 -0
  84. package/src/client/panel/DeployTab.tsx +314 -0
  85. package/src/client/panel/FleetTab.tsx +494 -0
  86. package/src/client/panel/HostFormDialog.tsx +289 -0
  87. package/src/client/panel/HostsTab.tsx +395 -0
  88. package/src/client/panel/LogsTab.tsx +208 -0
  89. package/src/client/panel/SshPanel.tsx +105 -0
  90. package/src/client/panel/TerminalTab.tsx +550 -0
  91. package/src/client/panel/TransferTab.tsx +238 -0
  92. package/src/client/panel/TunnelEditDialog.tsx +174 -0
  93. package/src/client/panel/TunnelsTab.tsx +328 -0
  94. package/src/client/panel/controller.ts +507 -0
  95. package/src/client/panel/helpers.ts +84 -0
  96. package/src/client/panel/panel.module.css +1734 -0
  97. package/src/client/panel/tabs.ts +52 -0
  98. package/src/client/panel/xterm.css.ts +2 -0
  99. package/src/client/settings-binding.ts +184 -0
  100. package/src/deploy/orchestrator.ts +326 -0
  101. package/src/deploy/tools.ts +225 -0
  102. package/src/dsh-home.ts +42 -0
  103. package/src/engine/cluster.ts +60 -0
  104. package/src/engine/connection-pool.ts +721 -0
  105. package/src/engine/proxy-command.ts +248 -0
  106. package/src/engine/pty.ts +78 -0
  107. package/src/engine/sftp.ts +229 -0
  108. package/src/engine/terminal-sessions.ts +280 -0
  109. package/src/engine/tunnel-discovery.ts +353 -0
  110. package/src/engine/tunnel-remarks.ts +120 -0
  111. package/src/engine/tunnel.ts +300 -0
  112. package/src/engine.ts +195 -0
  113. package/src/http.ts +127 -0
  114. package/src/index.ts +690 -0
  115. package/src/inspect/checks.ts +251 -0
  116. package/src/inspect/inspection.ts +321 -0
  117. package/src/inspect/tools.ts +366 -0
  118. package/src/logs/search.ts +251 -0
  119. package/src/logs/tools.ts +160 -0
  120. package/src/loopback.ts +119 -0
  121. package/src/monitor/loop.ts +265 -0
  122. package/src/monitor/metrics.ts +333 -0
  123. package/src/mount-once.ts +142 -0
  124. package/src/protocol.ts +534 -0
  125. package/src/routes.ts +998 -0
  126. package/src/security/known-hosts.ts +342 -0
  127. package/src/security/master-secret.ts +334 -0
  128. package/src/security/redact.ts +119 -0
  129. package/src/security/secrets.ts +152 -0
  130. package/src/ssh-config.ts +182 -0
  131. package/src/store.ts +757 -0
  132. package/src/tool-surface.ts +96 -0
  133. package/src/tools.ts +550 -0
package/src/http.ts ADDED
@@ -0,0 +1,127 @@
1
+ // Generated by scripts/sync-shared.mjs from shared/host/http.ts. Do not edit this copy; edit the shared source and run "node scripts/sync-shared.mjs".
2
+ /**
3
+ * Shared JSON body/response helpers for the host route families: one strict
4
+ * bounded body reader, one lenient bounded body reader, one JSON object
5
+ * narrow, one JSON writer, and the outbound request-init helper that keeps a
6
+ * host fetch body decodable (withIdentityEncoding). Previously the readers
7
+ * were copy-pasted across the
8
+ * package route files (routes.ts, update-routes.ts, mobile-api.ts, and each
9
+ * family's route module) with drifting contracts: body caps ranging 4 KiB to
10
+ * 1 MiB and four distinct overflow behaviors (reject, undefined, null, throw).
11
+ *
12
+ * Packages receive this file as a generated copy via scripts/sync-shared.mjs;
13
+ * edit this shared source and re-run the sync instead of editing a copy.
14
+ * Consumer code is migrated onto it in follow-up waves; no call site changes
15
+ * belong in the same change as its introduction.
16
+ * @module dsh-web-shared/host/http
17
+ */
18
+
19
+ import type { IncomingMessage, OutgoingHttpHeaders, ServerResponse } from 'node:http'
20
+
21
+ /** Default body cap for readJsonBody: 64 KiB. */
22
+ const DEFAULT_JSON_BODY_MAX_BYTES = 64 * 1024
23
+
24
+ /** Family-default JSON response headers; callers may append or override. */
25
+ const JSON_HEADERS = {
26
+ 'content-type': 'application/json; charset=utf-8',
27
+ 'referrer-policy': 'no-referrer',
28
+ } satisfies OutgoingHttpHeaders
29
+
30
+ /**
31
+ * Strict bounded body reader: parse a request body of at most maxBytes as
32
+ * JSON.
33
+ * @throws 'body too large' past the cap, or the JSON.parse error for an
34
+ * invalid or empty payload.
35
+ */
36
+ export async function readBoundedJson(req: IncomingMessage, maxBytes: number): Promise<unknown> {
37
+ const chunks: Buffer[] = []
38
+ let size = 0
39
+ for await (const chunk of req) {
40
+ const buffer = chunk as Buffer
41
+ size += buffer.length
42
+ if (size > maxBytes) throw new Error('body too large')
43
+ chunks.push(buffer)
44
+ }
45
+ return JSON.parse(Buffer.concat(chunks).toString('utf8'))
46
+ }
47
+
48
+ /**
49
+ * Lenient bounded body reader: parse a request body as JSON, or null on an
50
+ * empty body, invalid JSON, or a body past maxBytes (default 64 KiB).
51
+ * Overflow destroys the request instead of draining the remainder (no drain
52
+ * call, matching the current repo-wide behavior); callers must not keep
53
+ * reading the request afterwards. With objectOnly, non-JSON-object payloads
54
+ * also yield null.
55
+ */
56
+ export async function readJsonBody(
57
+ req: IncomingMessage,
58
+ opts: { maxBytes?: number; objectOnly?: boolean } = {},
59
+ ): Promise<unknown | null> {
60
+ const maxBytes = opts.maxBytes ?? DEFAULT_JSON_BODY_MAX_BYTES
61
+ const chunks: Buffer[] = []
62
+ let size = 0
63
+ for await (const chunk of req) {
64
+ const buffer = chunk as Buffer
65
+ size += buffer.length
66
+ if (size > maxBytes) {
67
+ req.destroy()
68
+ return null
69
+ }
70
+ chunks.push(buffer)
71
+ }
72
+ const text = Buffer.concat(chunks).toString('utf8')
73
+ if (text === '') return null
74
+ try {
75
+ const parsed: unknown = JSON.parse(text)
76
+ if (opts.objectOnly && !isJsonObject(parsed)) return null
77
+ return parsed
78
+ } catch {
79
+ return null
80
+ }
81
+ }
82
+
83
+ /** Whether a value is a JSON object: typeof object, not null, not an array. */
84
+ function isJsonObject(value: unknown): value is Record<string, unknown> {
85
+ return typeof value === 'object' && value !== null && !Array.isArray(value)
86
+ }
87
+
88
+ /** Narrow a value to a JSON object, or undefined when it is not one. */
89
+ export function asJsonObject(value: unknown): Record<string, unknown> | undefined {
90
+ return isJsonObject(value) ? value : undefined
91
+ }
92
+
93
+ /**
94
+ * Request init that asks a remote origin for an uncompressed body.
95
+ *
96
+ * The DSH host boots `@deepseek-ai/dsh-http-proxy`, whose top-level import of
97
+ * the npm `undici` copy replaces the legacy `undici.globalDispatcher.1` slot
98
+ * Node's built-in `fetch()` reads. That cross-major wrapper drops the
99
+ * `content-encoding` header and automatic decompression, so a plain fetch
100
+ * resolves to raw gzip/brotli/zstd bytes — compressed noise no JSON or text
101
+ * consumer can read. Every host fetch that parses a remote body must request
102
+ * identity encoding. Caller headers survive; `accept-encoding` is forced to
103
+ * `identity` because a caller value has no decoder behind it in this host.
104
+ * @param init - the caller's request init (signal, headers, method, ...).
105
+ * @returns a copy with `accept-encoding: identity` merged in.
106
+ */
107
+ export function withIdentityEncoding(init: RequestInit = {}): RequestInit {
108
+ const headers = new Headers(init.headers)
109
+ headers.set('accept-encoding', 'identity')
110
+ return { ...init, headers }
111
+ }
112
+
113
+ /**
114
+ * Write one JSON response. Default headers are the family defaults
115
+ * (content-type and referrer-policy); caller headers are appended or
116
+ * override them.
117
+ */
118
+ export function writeJson(
119
+ res: ServerResponse,
120
+ status: number,
121
+ body: unknown,
122
+ headers: OutgoingHttpHeaders = {},
123
+ ): void {
124
+ const payload = JSON.stringify(body)
125
+ res.writeHead(status, { ...JSON_HEADERS, ...headers })
126
+ res.end(payload)
127
+ }