dsh-quay-bot 0.7.4 → 1.0.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 +21 -0
- package/README.md +105 -28
- package/bin/doctor.mjs +148 -0
- package/botscreen/requirements-offline.txt +11 -0
- package/client.js +1 -2
- package/cordis.patch.yml +1 -1
- package/host/api.js +0 -4
- package/host/remote.js +2 -140
- package/host/screen.js +85 -21
- package/market/index.json +41 -0
- package/package.json +32 -13
- package/vendor/wheels/any/annotated_doc-0.0.7-py3-none-any.whl +0 -0
- package/vendor/wheels/any/annotated_types-0.8.0-py3-none-any.whl +0 -0
- package/vendor/wheels/any/anyio-4.16.0-py3-none-any.whl +0 -0
- package/vendor/wheels/any/certifi-2026.11.20-py3-none-any.whl +0 -0
- package/vendor/wheels/any/click-8.5.1-py3-none-any.whl +0 -0
- package/vendor/wheels/any/fastapi-0.165.0-py3-none-any.whl +0 -0
- package/vendor/wheels/any/h11-0.16.0-py3-none-any.whl +0 -0
- package/vendor/wheels/any/httpcore-1.0.9-py3-none-any.whl +0 -0
- package/vendor/wheels/any/httpx-0.29.0-py3-none-any.whl +0 -0
- package/vendor/wheels/any/idna-3.20-py3-none-any.whl +0 -0
- package/vendor/wheels/any/mss-10.2.0-py3-none-any.whl +0 -0
- package/vendor/wheels/any/opentelemetry_api-1.45.2-py3-none-any.whl +0 -0
- package/vendor/wheels/any/pydantic-2.14.4-py3-none-any.whl +0 -0
- package/vendor/wheels/any/python_multipart-0.0.34-py3-none-any.whl +0 -0
- package/vendor/wheels/any/python_xlib-0.33-py2.py3-none-any.whl +0 -0
- package/vendor/wheels/any/six-1.17.0-py2.py3-none-any.whl +0 -0
- package/vendor/wheels/any/starlette-1.10.0-py3-none-any.whl +0 -0
- package/vendor/wheels/any/typing_extensions-4.16.0-py3-none-any.whl +0 -0
- package/vendor/wheels/any/typing_inspection-0.4.5-py3-none-any.whl +0 -0
- package/vendor/wheels/any/uvicorn-0.54.0-py3-none-any.whl +0 -0
- package/vendor/wheels/linux-aarch64/pillow-12.2.0-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl +0 -0
- package/vendor/wheels/linux-aarch64/pydantic_core-2.50.5-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl +0 -0
- package/vendor/wheels/linux-aarch64/websockets-17.4-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl +0 -0
- package/vendor/wheels/linux-x86_64/pillow-12.2.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl +0 -0
- package/vendor/wheels/linux-x86_64/pydantic_core-2.50.5-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl +0 -0
- package/vendor/wheels/linux-x86_64/websockets-17.4-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl +0 -0
- package/botscreen/botscreen/__init__.py +0 -2
- package/botscreen/botscreen/__main__.py +0 -5
- package/botscreen/botscreen/artifacts.py +0 -388
- package/botscreen/botscreen/audit.py +0 -94
- package/botscreen/botscreen/cgroup.py +0 -293
- package/botscreen/botscreen/config.py +0 -320
- package/botscreen/botscreen/desktop/assets/chrome.png +0 -0
- package/botscreen/botscreen/desktop/assets/codex.png +0 -0
- package/botscreen/botscreen/desktop/assets/drive.png +0 -0
- package/botscreen/botscreen/desktop/assets/folder.png +0 -0
- package/botscreen/botscreen/desktop/assets/search.png +0 -0
- package/botscreen/botscreen/desktop/assets/terminal.png +0 -0
- package/botscreen/botscreen/desktop/assets/trash.png +0 -0
- package/botscreen/botscreen/desktop/assets/wallpaper.png +0 -0
- package/botscreen/botscreen/desktop.py +0 -244
- package/botscreen/botscreen/driver.py +0 -832
- package/botscreen/botscreen/gateway.py +0 -2089
- package/botscreen/botscreen/iconlayer.py +0 -841
- package/botscreen/botscreen/mcp_server.py +0 -435
- package/botscreen/botscreen/resources.py +0 -494
- package/botscreen/botscreen/screen.py +0 -1282
- package/botscreen/botscreen/session.py +0 -706
- package/botscreen/botscreen/state.py +0 -330
- package/botscreen/botscreen/streamer.py +0 -388
- package/remote/bin/dsh-remote.mjs +0 -418
- package/remote/package.json +0 -27
- package/remote/src/config.mjs +0 -183
- package/remote/src/crypto.mjs +0 -220
- package/remote/src/keys.mjs +0 -226
- package/remote/src/proxy.mjs +0 -1028
- package/remote/src/sessions.mjs +0 -163
- package/remote/src/shim.js +0 -838
- package/remote/src/supervisor.mjs +0 -207
- package/remote/src/tunnel.mjs +0 -489
- package/remote/src/upstream.mjs +0 -372
- package/remote/src/util.mjs +0 -139
- package/remote/src/ws.mjs +0 -313
- package/requirements.txt +0 -8
package/remote/src/ws.mjs
DELETED
|
@@ -1,313 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 零依赖 WebSocket(RFC 6455)最小实现,同时提供服务端 accept 与客户端 connect。
|
|
3
|
-
*
|
|
4
|
-
* 只覆盖 DSH Web UI 需要的能力:文本/二进制帧、ping/pong、close、分片接收、掩码校验。
|
|
5
|
-
* 不支持 permessage-deflate(不协商即不压缩,语义安全)。
|
|
6
|
-
*/
|
|
7
|
-
import { createHash, randomBytes } from 'node:crypto'
|
|
8
|
-
import { EventEmitter } from 'node:events'
|
|
9
|
-
import { connect as netConnect } from 'node:net'
|
|
10
|
-
import { connect as tlsConnect } from 'node:tls'
|
|
11
|
-
|
|
12
|
-
const GUID = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11'
|
|
13
|
-
export const OPCODE = { CONTINUATION: 0x0, TEXT: 0x1, BINARY: 0x2, CLOSE: 0x8, PING: 0x9, PONG: 0xa }
|
|
14
|
-
|
|
15
|
-
export function acceptKey(key) {
|
|
16
|
-
return createHash('sha1').update(`${key}${GUID}`).digest('base64')
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/** 增量帧解析器:push(chunk) → [{opcode, payload, fin, rsv}]。 */
|
|
20
|
-
export class FrameParser {
|
|
21
|
-
constructor({ maxPayload = 64 * 1024 * 1024, expectMasked = null } = {}) {
|
|
22
|
-
this.buffer = Buffer.alloc(0)
|
|
23
|
-
this.maxPayload = maxPayload
|
|
24
|
-
this.expectMasked = expectMasked
|
|
25
|
-
this.fragments = []
|
|
26
|
-
this.fragmentOpcode = null
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
push(chunk) {
|
|
30
|
-
this.buffer = this.buffer.length === 0 ? Buffer.from(chunk) : Buffer.concat([this.buffer, chunk])
|
|
31
|
-
const messages = []
|
|
32
|
-
for (;;) {
|
|
33
|
-
if (this.buffer.length < 2) break
|
|
34
|
-
const first = this.buffer[0]
|
|
35
|
-
const second = this.buffer[1]
|
|
36
|
-
const fin = (first & 0x80) !== 0
|
|
37
|
-
const rsv = first & 0x70
|
|
38
|
-
const opcode = first & 0x0f
|
|
39
|
-
const masked = (second & 0x80) !== 0
|
|
40
|
-
let length = second & 0x7f
|
|
41
|
-
let offset = 2
|
|
42
|
-
if (rsv !== 0) throw new Error('RSV 位必须为 0(不支持扩展协商)')
|
|
43
|
-
if (this.expectMasked === true && !masked) throw new Error('客户端帧必须掩码')
|
|
44
|
-
if (this.expectMasked === false && masked) throw new Error('服务端帧不应掩码')
|
|
45
|
-
if (length === 126) {
|
|
46
|
-
if (this.buffer.length < offset + 2) break
|
|
47
|
-
length = this.buffer.readUInt16BE(offset)
|
|
48
|
-
offset += 2
|
|
49
|
-
} else if (length === 127) {
|
|
50
|
-
if (this.buffer.length < offset + 8) break
|
|
51
|
-
const big = this.buffer.readBigUInt64BE(offset)
|
|
52
|
-
if (big > BigInt(this.maxPayload)) throw new Error(`WS 帧过大: ${big}`)
|
|
53
|
-
length = Number(big)
|
|
54
|
-
offset += 8
|
|
55
|
-
}
|
|
56
|
-
if (length > this.maxPayload) throw new Error(`WS 帧过大: ${length}`)
|
|
57
|
-
let maskKey = null
|
|
58
|
-
if (masked) {
|
|
59
|
-
if (this.buffer.length < offset + 4) break
|
|
60
|
-
maskKey = this.buffer.subarray(offset, offset + 4)
|
|
61
|
-
offset += 4
|
|
62
|
-
}
|
|
63
|
-
if (this.buffer.length < offset + length) break
|
|
64
|
-
let payload = Buffer.from(this.buffer.subarray(offset, offset + length))
|
|
65
|
-
this.buffer = this.buffer.subarray(offset + length)
|
|
66
|
-
if (maskKey) {
|
|
67
|
-
for (let i = 0; i < payload.length; i += 1) payload[i] ^= maskKey[i & 3]
|
|
68
|
-
}
|
|
69
|
-
if (opcode === OPCODE.PING || opcode === OPCODE.PONG || opcode === OPCODE.CLOSE) {
|
|
70
|
-
messages.push({ opcode, payload, fin: true })
|
|
71
|
-
continue
|
|
72
|
-
}
|
|
73
|
-
if (opcode === OPCODE.CONTINUATION) {
|
|
74
|
-
if (this.fragmentOpcode === null) throw new Error('非法 continuation 帧')
|
|
75
|
-
this.fragments.push(payload)
|
|
76
|
-
const total = this.fragments.reduce((sum, part) => sum + part.length, 0)
|
|
77
|
-
if (total > this.maxPayload) throw new Error('WS 分片消息过大')
|
|
78
|
-
if (fin) {
|
|
79
|
-
messages.push({ opcode: this.fragmentOpcode, payload: Buffer.concat(this.fragments) })
|
|
80
|
-
this.fragments = []
|
|
81
|
-
this.fragmentOpcode = null
|
|
82
|
-
}
|
|
83
|
-
continue
|
|
84
|
-
}
|
|
85
|
-
if (fin) {
|
|
86
|
-
messages.push({ opcode, payload })
|
|
87
|
-
} else {
|
|
88
|
-
this.fragmentOpcode = opcode
|
|
89
|
-
this.fragments = [payload]
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return messages
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export function encodeFrame({ opcode, payload, fin = true, mask = false }) {
|
|
97
|
-
const body = Buffer.isBuffer(payload) ? payload : Buffer.from(payload ?? '')
|
|
98
|
-
const header = []
|
|
99
|
-
header.push((fin ? 0x80 : 0) | (opcode & 0x0f))
|
|
100
|
-
const maskBit = mask ? 0x80 : 0
|
|
101
|
-
if (body.length < 126) {
|
|
102
|
-
header.push(maskBit | body.length)
|
|
103
|
-
} else if (body.length < 65536) {
|
|
104
|
-
header.push(maskBit | 126, body.length >> 8, body.length & 0xff)
|
|
105
|
-
} else {
|
|
106
|
-
header.push(maskBit | 127)
|
|
107
|
-
const lengthHeader = Buffer.alloc(8)
|
|
108
|
-
lengthHeader.writeBigUInt64BE(BigInt(body.length))
|
|
109
|
-
header.push(...lengthHeader)
|
|
110
|
-
}
|
|
111
|
-
const head = Buffer.from(header)
|
|
112
|
-
if (!mask) return Buffer.concat([head, body])
|
|
113
|
-
const key = randomBytes(4)
|
|
114
|
-
const masked = Buffer.from(body)
|
|
115
|
-
for (let i = 0; i < masked.length; i += 1) masked[i] ^= key[i & 3]
|
|
116
|
-
return Buffer.concat([head, key, masked])
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export class WebSocketConnection extends EventEmitter {
|
|
120
|
-
constructor(socket, { role, maxPayload = 64 * 1024 * 1024, leftover = Buffer.alloc(0) }) {
|
|
121
|
-
super()
|
|
122
|
-
this.socket = socket
|
|
123
|
-
this.role = role
|
|
124
|
-
this.closed = false
|
|
125
|
-
this.parser = new FrameParser({ maxPayload, expectMasked: role === 'server' })
|
|
126
|
-
socket.setNoDelay?.(true)
|
|
127
|
-
socket.on('data', (chunk) => this.#onData(chunk))
|
|
128
|
-
socket.on('close', () => this.#finish(1006, 'socket closed'))
|
|
129
|
-
socket.on('error', (error) => {
|
|
130
|
-
this.emit('error', error)
|
|
131
|
-
this.#finish(1006, 'socket error')
|
|
132
|
-
})
|
|
133
|
-
if (leftover.length > 0) this.#onData(leftover)
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
#onData(chunk) {
|
|
137
|
-
if (this.closed) return
|
|
138
|
-
let messages
|
|
139
|
-
try {
|
|
140
|
-
messages = this.parser.push(chunk)
|
|
141
|
-
} catch (error) {
|
|
142
|
-
this.emit('error', error)
|
|
143
|
-
this.close(1002, 'protocol error')
|
|
144
|
-
return
|
|
145
|
-
}
|
|
146
|
-
for (const message of messages) {
|
|
147
|
-
if (message.opcode === OPCODE.CLOSE) {
|
|
148
|
-
const code = message.payload.length >= 2 ? message.payload.readUInt16BE(0) : 1005
|
|
149
|
-
this.#finish(code, message.payload.subarray(2).toString('utf8'))
|
|
150
|
-
return
|
|
151
|
-
}
|
|
152
|
-
if (message.opcode === OPCODE.PING) {
|
|
153
|
-
this.#write({ opcode: OPCODE.PONG, payload: message.payload })
|
|
154
|
-
this.emit('ping', message.payload)
|
|
155
|
-
continue
|
|
156
|
-
}
|
|
157
|
-
if (message.opcode === OPCODE.PONG) {
|
|
158
|
-
this.emit('pong', message.payload)
|
|
159
|
-
continue
|
|
160
|
-
}
|
|
161
|
-
this.emit('message', message.payload, message.opcode === OPCODE.TEXT)
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
#write({ opcode, payload }) {
|
|
166
|
-
if (this.closed || !this.socket.writable) return false
|
|
167
|
-
try {
|
|
168
|
-
this.socket.write(encodeFrame({ opcode, payload, mask: this.role === 'client' }))
|
|
169
|
-
return true
|
|
170
|
-
} catch {
|
|
171
|
-
return false
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
sendText(text) {
|
|
176
|
-
return this.#write({ opcode: OPCODE.TEXT, payload: Buffer.from(String(text), 'utf8') })
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
sendBinary(buffer) {
|
|
180
|
-
return this.#write({ opcode: OPCODE.BINARY, payload: buffer })
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
ping(payload = Buffer.alloc(0)) {
|
|
184
|
-
return this.#write({ opcode: OPCODE.PING, payload })
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
close(code = 1000, reason = '') {
|
|
188
|
-
if (this.closed) return
|
|
189
|
-
const reasonBuffer = Buffer.from(reason, 'utf8').subarray(0, 123)
|
|
190
|
-
const payload = Buffer.alloc(2 + reasonBuffer.length)
|
|
191
|
-
payload.writeUInt16BE(code, 0)
|
|
192
|
-
reasonBuffer.copy(payload, 2)
|
|
193
|
-
this.#write({ opcode: OPCODE.CLOSE, payload })
|
|
194
|
-
setTimeout(() => this.#finish(code, reason), 200).unref?.()
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
#finish(code, reason) {
|
|
198
|
-
if (this.closed) return
|
|
199
|
-
this.closed = true
|
|
200
|
-
try {
|
|
201
|
-
this.socket.end()
|
|
202
|
-
} catch {}
|
|
203
|
-
this.emit('close', code, reason)
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/** 服务端:把已 upgrade 的 socket 包装成连接。 */
|
|
208
|
-
export function acceptUpgrade(req, socket, head = Buffer.alloc(0), options = {}) {
|
|
209
|
-
const key = req.headers['sec-websocket-key']
|
|
210
|
-
if (!key || String(req.headers.upgrade ?? '').toLowerCase() !== 'websocket') {
|
|
211
|
-
socket.end('HTTP/1.1 400 Bad Request\r\n\r\n')
|
|
212
|
-
return null
|
|
213
|
-
}
|
|
214
|
-
const protocol = String(req.headers['sec-websocket-protocol'] ?? '').split(',').map((part) => part.trim()).filter(Boolean)
|
|
215
|
-
const lines = [
|
|
216
|
-
'HTTP/1.1 101 Switching Protocols',
|
|
217
|
-
'Upgrade: websocket',
|
|
218
|
-
'Connection: Upgrade',
|
|
219
|
-
`Sec-WebSocket-Accept: ${acceptKey(String(key))}`,
|
|
220
|
-
]
|
|
221
|
-
if (protocol.length > 0) lines.push(`Sec-WebSocket-Protocol: ${protocol[0]}`)
|
|
222
|
-
socket.write(`${lines.join('\r\n')}\r\n\r\n`)
|
|
223
|
-
return new WebSocketConnection(socket, { role: 'server', ...options, leftover: head })
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
/** 客户端:带自定义头(Cookie/Origin)连接上游 WS。 */
|
|
227
|
-
export function connectWebSocket(target, { headers = {}, timeoutMs = 15_000, maxPayload } = {}) {
|
|
228
|
-
return new Promise((resolve, reject) => {
|
|
229
|
-
let url
|
|
230
|
-
try {
|
|
231
|
-
url = new URL(target)
|
|
232
|
-
} catch {
|
|
233
|
-
reject(new Error(`WS 地址非法: ${target}`))
|
|
234
|
-
return
|
|
235
|
-
}
|
|
236
|
-
const secure = url.protocol === 'wss:' || url.protocol === 'https:'
|
|
237
|
-
const host = url.hostname.replace(/^\[|\]$/g, '')
|
|
238
|
-
const port = Number(url.port || (secure ? 443 : 80))
|
|
239
|
-
const key = randomBytes(16).toString('base64')
|
|
240
|
-
const options = { host, port, servername: secure ? host : undefined }
|
|
241
|
-
const socket = secure ? tlsConnect(options) : netConnect(options)
|
|
242
|
-
let settled = false
|
|
243
|
-
const timer = setTimeout(() => {
|
|
244
|
-
if (settled) return
|
|
245
|
-
settled = true
|
|
246
|
-
socket.destroy()
|
|
247
|
-
reject(new Error('WS 握手超时'))
|
|
248
|
-
}, timeoutMs)
|
|
249
|
-
const defaults = {
|
|
250
|
-
Host: url.host,
|
|
251
|
-
Upgrade: 'websocket',
|
|
252
|
-
Connection: 'Upgrade',
|
|
253
|
-
'Sec-WebSocket-Key': key,
|
|
254
|
-
'Sec-WebSocket-Version': '13',
|
|
255
|
-
}
|
|
256
|
-
// 大小写无关合并,且不允许调用方覆盖握手必需头(避免重复 Host 触发 400)
|
|
257
|
-
const merged = new Map()
|
|
258
|
-
for (const [name, value] of Object.entries(defaults)) merged.set(name.toLowerCase(), [name, value])
|
|
259
|
-
for (const [name, value] of Object.entries(headers ?? {})) {
|
|
260
|
-
const key = name.toLowerCase()
|
|
261
|
-
if (key === 'sec-websocket-key' || key === 'sec-websocket-version' || value === undefined || value === null) continue
|
|
262
|
-
merged.set(key, [name, value])
|
|
263
|
-
}
|
|
264
|
-
const headerLines = [...merged.values()].map(([name, value]) => `${name}: ${value}`)
|
|
265
|
-
socket.on(secure ? 'secureConnect' : 'connect', () => {
|
|
266
|
-
socket.write(`GET ${url.pathname}${url.search} HTTP/1.1\r\n${headerLines.join('\r\n')}\r\n\r\n`)
|
|
267
|
-
})
|
|
268
|
-
let pending = Buffer.alloc(0)
|
|
269
|
-
const onData = (chunk) => {
|
|
270
|
-
pending = Buffer.concat([pending, chunk])
|
|
271
|
-
const split = pending.indexOf('\r\n\r\n')
|
|
272
|
-
if (split === -1) {
|
|
273
|
-
if (pending.length > 64 * 1024) {
|
|
274
|
-
settled = true
|
|
275
|
-
clearTimeout(timer)
|
|
276
|
-
socket.destroy()
|
|
277
|
-
reject(new Error('WS 握应头过大'))
|
|
278
|
-
}
|
|
279
|
-
return
|
|
280
|
-
}
|
|
281
|
-
socket.removeListener('data', onData)
|
|
282
|
-
const head = pending.subarray(0, split).toString('latin1')
|
|
283
|
-
const rest = pending.subarray(split + 4)
|
|
284
|
-
const statusLine = head.split('\r\n')[0] ?? ''
|
|
285
|
-
if (!/^HTTP\/1\.1 101/u.test(statusLine)) {
|
|
286
|
-
settled = true
|
|
287
|
-
clearTimeout(timer)
|
|
288
|
-
socket.destroy()
|
|
289
|
-
reject(new Error(`WS 升级失败: ${statusLine}`))
|
|
290
|
-
return
|
|
291
|
-
}
|
|
292
|
-
const expected = acceptKey(key)
|
|
293
|
-
const acceptHeader = /sec-websocket-accept:\s*(\S+)/i.exec(head)?.[1]
|
|
294
|
-
if (acceptHeader && acceptHeader !== expected) {
|
|
295
|
-
settled = true
|
|
296
|
-
clearTimeout(timer)
|
|
297
|
-
socket.destroy()
|
|
298
|
-
reject(new Error('WS 握手校验失败(Sec-WebSocket-Accept 不匹配)'))
|
|
299
|
-
return
|
|
300
|
-
}
|
|
301
|
-
settled = true
|
|
302
|
-
clearTimeout(timer)
|
|
303
|
-
resolve(new WebSocketConnection(socket, { role: 'client', maxPayload, leftover: rest }))
|
|
304
|
-
}
|
|
305
|
-
socket.on('data', onData)
|
|
306
|
-
socket.on('error', (error) => {
|
|
307
|
-
if (settled) return
|
|
308
|
-
settled = true
|
|
309
|
-
clearTimeout(timer)
|
|
310
|
-
reject(error)
|
|
311
|
-
})
|
|
312
|
-
})
|
|
313
|
-
}
|