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.
- package/LICENSE +202 -0
- package/README.md +271 -2
- package/cordis.patch.yml +16 -0
- package/icon.svg +3 -0
- package/lib/client.js +13975 -0
- package/lib/index.js +6908 -0
- package/lib/types/activity/history.d.ts +50 -0
- package/lib/types/alerting/notify.d.ts +89 -0
- package/lib/types/alerting/prompt-summary.d.ts +28 -0
- package/lib/types/alerting/rules.d.ts +135 -0
- package/lib/types/alerting/tools.d.ts +30 -0
- package/lib/types/audit/audit-log.d.ts +84 -0
- package/lib/types/audit/recorder.d.ts +50 -0
- package/lib/types/client/api.d.ts +222 -0
- package/lib/types/client/index.d.ts +45 -0
- package/lib/types/client/locales.d.ts +319 -0
- package/lib/types/client/native-panel.d.ts +70 -0
- package/lib/types/client/panel/ClusterTab.d.ts +7 -0
- package/lib/types/client/panel/DeployTab.d.ts +10 -0
- package/lib/types/client/panel/FleetTab.d.ts +10 -0
- package/lib/types/client/panel/HostFormDialog.d.ts +12 -0
- package/lib/types/client/panel/HostsTab.d.ts +25 -0
- package/lib/types/client/panel/LogsTab.d.ts +10 -0
- package/lib/types/client/panel/SshPanel.d.ts +14 -0
- package/lib/types/client/panel/TerminalTab.d.ts +27 -0
- package/lib/types/client/panel/TransferTab.d.ts +7 -0
- package/lib/types/client/panel/TunnelEditDialog.d.ts +15 -0
- package/lib/types/client/panel/TunnelsTab.d.ts +27 -0
- package/lib/types/client/panel/controller.d.ts +253 -0
- package/lib/types/client/panel/helpers.d.ts +45 -0
- package/lib/types/client/panel/tabs.d.ts +62 -0
- package/lib/types/client/panel/xterm.css.d.ts +2 -0
- package/lib/types/client/settings-binding.d.ts +71 -0
- package/lib/types/deploy/orchestrator.d.ts +158 -0
- package/lib/types/deploy/tools.d.ts +14 -0
- package/lib/types/dsh-home.d.ts +16 -0
- package/lib/types/engine/cluster.d.ts +19 -0
- package/lib/types/engine/connection-pool.d.ts +183 -0
- package/lib/types/engine/proxy-command.d.ts +36 -0
- package/lib/types/engine/pty.d.ts +32 -0
- package/lib/types/engine/sftp.d.ts +20 -0
- package/lib/types/engine/terminal-sessions.d.ts +67 -0
- package/lib/types/engine/tunnel-discovery.d.ts +89 -0
- package/lib/types/engine/tunnel-remarks.d.ts +49 -0
- package/lib/types/engine/tunnel.d.ts +76 -0
- package/lib/types/engine.d.ts +103 -0
- package/lib/types/http.d.ts +59 -0
- package/lib/types/index.d.ts +128 -0
- package/lib/types/inspect/checks.d.ts +118 -0
- package/lib/types/inspect/inspection.d.ts +111 -0
- package/lib/types/inspect/tools.d.ts +50 -0
- package/lib/types/logs/search.d.ts +131 -0
- package/lib/types/logs/tools.d.ts +6 -0
- package/lib/types/loopback.d.ts +64 -0
- package/lib/types/monitor/loop.d.ts +133 -0
- package/lib/types/monitor/metrics.d.ts +151 -0
- package/lib/types/mount-once.d.ts +55 -0
- package/lib/types/protocol.d.ts +524 -0
- package/lib/types/routes.d.ts +82 -0
- package/lib/types/security/known-hosts.d.ts +153 -0
- package/lib/types/security/master-secret.d.ts +157 -0
- package/lib/types/security/redact.d.ts +44 -0
- package/lib/types/security/secrets.d.ts +70 -0
- package/lib/types/ssh-config.d.ts +42 -0
- package/lib/types/store.d.ts +183 -0
- package/lib/types/tool-surface.d.ts +72 -0
- package/lib/types/tools.d.ts +56 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +126 -6
- package/src/activity/history.ts +117 -0
- package/src/alerting/notify.ts +212 -0
- package/src/alerting/prompt-summary.ts +71 -0
- package/src/alerting/rules.ts +281 -0
- package/src/alerting/tools.ts +263 -0
- package/src/audit/audit-log.ts +199 -0
- package/src/audit/recorder.ts +73 -0
- package/src/client/api.ts +782 -0
- package/src/client/css-modules.d.ts +5 -0
- package/src/client/index.ts +150 -0
- package/src/client/locales.ts +654 -0
- package/src/client/native-panel.tsx +141 -0
- package/src/client/panel/ClusterTab.tsx +141 -0
- package/src/client/panel/DeployTab.tsx +314 -0
- package/src/client/panel/FleetTab.tsx +494 -0
- package/src/client/panel/HostFormDialog.tsx +289 -0
- package/src/client/panel/HostsTab.tsx +395 -0
- package/src/client/panel/LogsTab.tsx +208 -0
- package/src/client/panel/SshPanel.tsx +105 -0
- package/src/client/panel/TerminalTab.tsx +550 -0
- package/src/client/panel/TransferTab.tsx +238 -0
- package/src/client/panel/TunnelEditDialog.tsx +174 -0
- package/src/client/panel/TunnelsTab.tsx +328 -0
- package/src/client/panel/controller.ts +507 -0
- package/src/client/panel/helpers.ts +84 -0
- package/src/client/panel/panel.module.css +1734 -0
- package/src/client/panel/tabs.ts +52 -0
- package/src/client/panel/xterm.css.ts +2 -0
- package/src/client/settings-binding.ts +184 -0
- package/src/deploy/orchestrator.ts +326 -0
- package/src/deploy/tools.ts +225 -0
- package/src/dsh-home.ts +42 -0
- package/src/engine/cluster.ts +60 -0
- package/src/engine/connection-pool.ts +721 -0
- package/src/engine/proxy-command.ts +248 -0
- package/src/engine/pty.ts +78 -0
- package/src/engine/sftp.ts +229 -0
- package/src/engine/terminal-sessions.ts +280 -0
- package/src/engine/tunnel-discovery.ts +353 -0
- package/src/engine/tunnel-remarks.ts +120 -0
- package/src/engine/tunnel.ts +300 -0
- package/src/engine.ts +195 -0
- package/src/http.ts +127 -0
- package/src/index.ts +690 -0
- package/src/inspect/checks.ts +251 -0
- package/src/inspect/inspection.ts +321 -0
- package/src/inspect/tools.ts +366 -0
- package/src/logs/search.ts +251 -0
- package/src/logs/tools.ts +160 -0
- package/src/loopback.ts +119 -0
- package/src/monitor/loop.ts +265 -0
- package/src/monitor/metrics.ts +333 -0
- package/src/mount-once.ts +142 -0
- package/src/protocol.ts +534 -0
- package/src/routes.ts +998 -0
- package/src/security/known-hosts.ts +342 -0
- package/src/security/master-secret.ts +334 -0
- package/src/security/redact.ts +119 -0
- package/src/security/secrets.ts +152 -0
- package/src/ssh-config.ts +182 -0
- package/src/store.ts +757 -0
- package/src/tool-surface.ts +96 -0
- 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
|
+
}
|