dsh-quay-bot 1.0.2 → 1.0.4
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/README.md +28 -105
- package/botscreen/requirements.txt +1 -1
- package/client.js +3 -2
- package/cordis.patch.yml +1 -1
- package/host/api.js +4 -0
- package/host/remote.js +285 -8
- package/host/screen.js +22 -86
- package/package.json +35 -32
- package/remote/bin/dsh-remote.mjs +435 -0
- package/remote/package.json +27 -0
- package/remote/src/config.mjs +183 -0
- package/remote/src/crypto.mjs +220 -0
- package/remote/src/keys.mjs +226 -0
- package/remote/src/proxy.mjs +1028 -0
- package/remote/src/sessions.mjs +163 -0
- package/remote/src/shim.js +838 -0
- package/remote/src/supervisor.mjs +207 -0
- package/remote/src/tunnel.mjs +533 -0
- package/remote/src/upstream.mjs +403 -0
- package/remote/src/util.mjs +149 -0
- package/remote/src/ws.mjs +313 -0
- package/LICENSE +0 -21
- package/avatar/build.mjs +0 -81
- package/avatar/gallery/droid.json +0 -14
- package/avatar/gallery/ghost.json +0 -14
- package/avatar/gallery/grok-pod.json +0 -14
- package/avatar/gallery/guardian.json +0 -14
- package/avatar/gallery/mecha.json +0 -14
- package/avatar/gallery/mochi.json +0 -14
- package/avatar/gallery/neko.json +0 -14
- package/avatar/gallery/orbiter.json +0 -14
- package/avatar/gallery/relay.json +0 -14
- package/avatar/gallery/spark.json +0 -14
- package/avatar/src/bot/clay.ts +0 -135
- package/avatar/src/bot/effects.ts +0 -100
- package/avatar/src/bot/grok-bot.ts +0 -626
- package/avatar/src/bot/index.ts +0 -15
- package/avatar/src/bot/palettes.ts +0 -62
- package/avatar/src/bot/ring.ts +0 -219
- package/avatar/src/bot/scheduler.ts +0 -239
- package/avatar/src/bot/shapes.ts +0 -277
- package/avatar/src/bot/spring.ts +0 -196
- package/avatar/src/core/color.ts +0 -92
- package/avatar/src/core/eyes.ts +0 -297
- package/avatar/src/core/field.ts +0 -482
- package/avatar/src/core/frame.ts +0 -655
- package/avatar/src/core/fx.ts +0 -375
- package/avatar/src/core/index.ts +0 -49
- package/avatar/src/core/paint.ts +0 -331
- package/avatar/src/core/path.ts +0 -495
- package/avatar/src/core/pose.ts +0 -581
- package/avatar/src/core/svg.ts +0 -98
- package/avatar/src/core/types.ts +0 -153
- package/avatar/src/core/validate.ts +0 -296
- package/avatar/src/core/volume.ts +0 -681
- package/avatar/src/entry.ts +0 -260
- package/bin/doctor.mjs +0 -148
- package/botscreen/requirements-offline.txt +0 -11
- package/market/index.json +0 -41
|
@@ -0,0 +1,313 @@
|
|
|
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
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 kdczyz
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
package/avatar/build.mjs
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Build script for the embedded Image-bot (Avatar Forge) module.
|
|
3
|
-
*
|
|
4
|
-
* Outputs:
|
|
5
|
-
* 1. `avatar/dist/avatar-engine.js` — zero-dependency browser bundle (IIFE) exposing
|
|
6
|
-
* `<grok-bot>` and `window.__DSH_AVATAR_ENGINE__`.
|
|
7
|
-
* 2. `avatar/catalog.json` — static 19-avatar catalog + 12 clay palettes consumed by
|
|
8
|
-
* the zero-dependency Node Host (`host/avatar.js`) and `/botmode/api/avatar/catalog`.
|
|
9
|
-
*
|
|
10
|
-
* Usage:
|
|
11
|
-
* node packages/dsh-botmode/avatar/build.mjs
|
|
12
|
-
*/
|
|
13
|
-
import { execFileSync } from 'node:child_process'
|
|
14
|
-
import { existsSync, mkdirSync, writeFileSync } from 'node:fs'
|
|
15
|
-
import { dirname, join, resolve } from 'node:path'
|
|
16
|
-
import { fileURLToPath } from 'node:url'
|
|
17
|
-
import { createRequire } from 'node:module'
|
|
18
|
-
|
|
19
|
-
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
20
|
-
const entryPath = join(__dirname, 'src', 'entry.ts')
|
|
21
|
-
const distDir = join(__dirname, 'dist')
|
|
22
|
-
const bundlePath = join(distDir, 'avatar-engine.js')
|
|
23
|
-
const catalogPath = join(__dirname, 'catalog.json')
|
|
24
|
-
|
|
25
|
-
const esbuildCandidates = [
|
|
26
|
-
process.env.ESBUILD_BIN,
|
|
27
|
-
resolve(__dirname, 'node_modules/.bin/esbuild'),
|
|
28
|
-
'/home/ubuntu/Desktop/Image-bot/node_modules/.bin/esbuild',
|
|
29
|
-
].filter(Boolean)
|
|
30
|
-
|
|
31
|
-
const esbuildBin = esbuildCandidates.find((p) => existsSync(p))
|
|
32
|
-
if (!esbuildBin) {
|
|
33
|
-
throw new Error(`esbuild binary not found in: ${esbuildCandidates.join(', ')}`)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
mkdirSync(distDir, { recursive: true })
|
|
37
|
-
|
|
38
|
-
// 1. Build browser IIFE bundle
|
|
39
|
-
execFileSync(esbuildBin, [
|
|
40
|
-
entryPath,
|
|
41
|
-
'--bundle',
|
|
42
|
-
'--format=iife',
|
|
43
|
-
'--global-name=__DSH_AVATAR_BUNDLE__',
|
|
44
|
-
'--target=es2020',
|
|
45
|
-
'--minify',
|
|
46
|
-
`--outfile=${bundlePath}`,
|
|
47
|
-
], { stdio: 'inherit' })
|
|
48
|
-
|
|
49
|
-
// 2. Build a temporary CJS bundle to evaluate and emit `catalog.json` cleanly without tsx
|
|
50
|
-
const tmpCjs = join(distDir, '.catalog-gen.cjs')
|
|
51
|
-
execFileSync(esbuildBin, [
|
|
52
|
-
entryPath,
|
|
53
|
-
'--bundle',
|
|
54
|
-
'--platform=node',
|
|
55
|
-
'--format=cjs',
|
|
56
|
-
'--target=node20',
|
|
57
|
-
`--outfile=${tmpCjs}`,
|
|
58
|
-
], { stdio: 'inherit' })
|
|
59
|
-
|
|
60
|
-
if (typeof globalThis.HTMLElement === 'undefined') {
|
|
61
|
-
globalThis.HTMLElement = class {}
|
|
62
|
-
}
|
|
63
|
-
const require = createRequire(import.meta.url)
|
|
64
|
-
const mod = require(tmpCjs)
|
|
65
|
-
const catalog = {
|
|
66
|
-
version: 1,
|
|
67
|
-
defaultAvatarId: mod.DEFAULT_AVATAR_ID,
|
|
68
|
-
defaultColor: mod.DEFAULT_AVATAR_COLOR,
|
|
69
|
-
defaultEyeColor: mod.DEFAULT_AVATAR_EYE_COLOR,
|
|
70
|
-
items: mod.ALL_AVATARS,
|
|
71
|
-
palettes: mod.PALETTES,
|
|
72
|
-
eyeSwatches: ['#151515', '#1b1b1b', '#ffffff', '#0a7cff', '#e11d48'],
|
|
73
|
-
materials: ['flat', 'fluffy'],
|
|
74
|
-
states: ['idle', 'thinking', 'working', 'waiting', 'blocked', 'done', 'alert'],
|
|
75
|
-
moods: mod.EXPRESSIONS,
|
|
76
|
-
}
|
|
77
|
-
writeFileSync(catalogPath, `${JSON.stringify(catalog, null, 2)}\n`, 'utf8')
|
|
78
|
-
|
|
79
|
-
// Clean up temporary CJS artifact
|
|
80
|
-
execFileSync('rm', ['-f', tmpCjs])
|
|
81
|
-
console.log(`Built avatar-engine.js and catalog.json (${catalog.items.length} avatars, ${catalog.palettes.length} palettes).`)
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 1,
|
|
3
|
-
"id": "droid",
|
|
4
|
-
"name": "Droid",
|
|
5
|
-
"body": {
|
|
6
|
-
"path": "M37 14H63A18 18 0 0 1 81 32V38A18 18 0 0 1 63 56H37A18 18 0 0 1 19 38V32A18 18 0 0 1 37 14ZM45 52H55A4 4 0 0 1 59 56V58A4 4 0 0 1 55 62H45A4 4 0 0 1 41 58V56A4 4 0 0 1 45 52ZM40 59H60A12 12 0 0 1 72 71V76A12 12 0 0 1 60 88H40A12 12 0 0 1 28 76V71A12 12 0 0 1 40 59Z"
|
|
7
|
-
},
|
|
8
|
-
"eyes": {
|
|
9
|
-
"x": 50,
|
|
10
|
-
"y": 34,
|
|
11
|
-
"spacing": 17,
|
|
12
|
-
"scale": 1.08
|
|
13
|
-
}
|
|
14
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 1,
|
|
3
|
-
"id": "ghost",
|
|
4
|
-
"name": "Phantom",
|
|
5
|
-
"body": {
|
|
6
|
-
"path": "M24 50C24 27 35 12 50 12C65 12 76 27 76 50L77 78C77 84 72 87 67 87C62 87 60 83 58 80C56 84 53 87 50 87C47 87 44 84 42 80C40 83 38 87 33 87C28 87 23 84 23 78Z"
|
|
7
|
-
},
|
|
8
|
-
"eyes": {
|
|
9
|
-
"x": 50,
|
|
10
|
-
"y": 43,
|
|
11
|
-
"spacing": 16,
|
|
12
|
-
"scale": 1.15
|
|
13
|
-
}
|
|
14
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 1,
|
|
3
|
-
"id": "grok-pod",
|
|
4
|
-
"name": "Grok Pod",
|
|
5
|
-
"body": {
|
|
6
|
-
"path": "M14 46A36 33 0 1 1 86 46A36 33 0 1 1 14 46ZM34 70H66A8 8 0 0 1 74 78V78A8 8 0 0 1 66 86H34A8 8 0 0 1 26 78V78A8 8 0 0 1 34 70Z"
|
|
7
|
-
},
|
|
8
|
-
"eyes": {
|
|
9
|
-
"x": 50,
|
|
10
|
-
"y": 45,
|
|
11
|
-
"spacing": 18,
|
|
12
|
-
"scale": 1.15
|
|
13
|
-
}
|
|
14
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 1,
|
|
3
|
-
"id": "guardian",
|
|
4
|
-
"name": "Guardian",
|
|
5
|
-
"body": {
|
|
6
|
-
"path": "M50 11C59.82 11 75.62 13.67 81 20C86.38 26.33 85.58 42.13 84 51C82.42 59.87 76.38 69.98 71 76C65.62 82.02 56.65 89 50 89C43.35 89 34.38 82.02 29 76C23.62 69.98 17.58 59.87 16 51C14.42 42.13 13.62 26.33 19 20C24.38 13.67 40.18 11 50 11Z"
|
|
7
|
-
},
|
|
8
|
-
"eyes": {
|
|
9
|
-
"x": 50,
|
|
10
|
-
"y": 46,
|
|
11
|
-
"spacing": 17,
|
|
12
|
-
"scale": 1.12
|
|
13
|
-
}
|
|
14
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 1,
|
|
3
|
-
"id": "mecha",
|
|
4
|
-
"name": "Mecha",
|
|
5
|
-
"body": {
|
|
6
|
-
"path": "M42 20H58A22 22 0 0 1 80 42V60A22 22 0 0 1 58 82H42A22 22 0 0 1 20 60V42A22 22 0 0 1 42 20ZM17 36H17A7 7 0 0 1 24 43V59A7 7 0 0 1 17 66H17A7 7 0 0 1 10 59V43A7 7 0 0 1 17 36ZM83 36H83A7 7 0 0 1 90 43V59A7 7 0 0 1 83 66H83A7 7 0 0 1 76 59V43A7 7 0 0 1 83 36Z"
|
|
7
|
-
},
|
|
8
|
-
"eyes": {
|
|
9
|
-
"x": 50,
|
|
10
|
-
"y": 49,
|
|
11
|
-
"spacing": 17,
|
|
12
|
-
"scale": 1.1
|
|
13
|
-
}
|
|
14
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 1,
|
|
3
|
-
"id": "mochi",
|
|
4
|
-
"name": "Mochi",
|
|
5
|
-
"body": {
|
|
6
|
-
"path": "M50 14C56.65 14 65.46 15.25 71 20C76.54 24.75 82.47 36.4 85 44C87.53 51.6 89.22 61.35 87 68C84.78 74.65 76.86 82.83 71 86C65.14 89.17 56.65 88 50 88C43.35 88 34.86 89.17 29 86C23.14 82.83 15.22 74.65 13 68C10.78 61.35 12.47 51.6 15 44C17.53 36.4 23.46 24.75 29 20C34.54 15.25 43.35 14 50 14Z"
|
|
7
|
-
},
|
|
8
|
-
"eyes": {
|
|
9
|
-
"x": 50,
|
|
10
|
-
"y": 50,
|
|
11
|
-
"spacing": 17,
|
|
12
|
-
"scale": 1.15
|
|
13
|
-
}
|
|
14
|
-
}
|
package/avatar/gallery/neko.json
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 1,
|
|
3
|
-
"id": "neko",
|
|
4
|
-
"name": "Neko",
|
|
5
|
-
"body": {
|
|
6
|
-
"path": "M16 54A34 31 0 1 1 84 54A34 31 0 1 1 16 54ZM20 42C17.02 39.88 17.88 15.84 21 14C24.12 12.16 42.14 25.03 42 29C41.86 32.97 22.98 44.13 20 42ZM80 42C82.98 39.88 82.12 15.84 79 14C75.88 12.16 57.86 25.03 58 29C58.14 32.97 77.03 44.13 80 42Z"
|
|
7
|
-
},
|
|
8
|
-
"eyes": {
|
|
9
|
-
"x": 50,
|
|
10
|
-
"y": 52,
|
|
11
|
-
"spacing": 17,
|
|
12
|
-
"scale": 1.1
|
|
13
|
-
}
|
|
14
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 1,
|
|
3
|
-
"id": "orbiter",
|
|
4
|
-
"name": "Orbiter",
|
|
5
|
-
"body": {
|
|
6
|
-
"path": "M23 49A27 27 0 1 1 77 49A27 27 0 1 1 23 49ZM46.92 42.4L51.37 41.3L55.81 40.35L60.17 39.57L64.41 38.98L68.47 38.57L72.29 38.36L75.84 38.35L79.05 38.53L81.91 38.91L84.36 39.47L86.38 40.22L87.94 41.14L89.03 42.23L89.62 43.46L89.72 44.82L89.32 46.3L88.42 47.88L87.04 49.54L85.19 51.25L82.9 52.99L80.2 54.75L77.12 56.49L73.69 58.21L69.97 59.87L66 61.46L61.82 62.96L57.5 64.34L53.08 65.6L48.63 66.7L44.19 67.65L39.83 68.43L35.59 69.02L31.53 69.43L27.71 69.64L24.16 69.65L20.95 69.47L18.09 69.09L15.64 68.53L13.62 67.78L12.06 66.86L10.97 65.77L10.38 64.54L10.28 63.18L10.68 61.7L11.58 60.12L12.96 58.46L14.81 56.75L17.1 55.01L19.8 53.25L22.88 51.51L26.31 49.79L30.03 48.13L34 46.54L38.18 45.04L42.5 43.66ZM44.86 49.71L41.2 50.79L37.65 51.91L34.26 53.06L31.06 54.22L28.11 55.37L25.42 56.51L23.05 57.62L21.02 58.68L19.35 59.68L18.06 60.62L17.18 61.46L16.71 62.22L16.66 62.87L17.03 63.41L17.81 63.83L19 64.13L20.57 64.3L22.52 64.34L24.81 64.25L27.42 64.03L30.32 63.69L33.46 63.22L36.81 62.64L40.32 61.95L43.96 61.16L47.67 60.27L51.41 59.32L55.14 58.29L58.8 57.21L62.35 56.09L65.74 54.94L68.94 53.78L71.89 52.63L74.58 51.49L76.95 50.38L78.98 49.32L80.65 48.32L81.94 47.38L82.82 46.54L83.29 45.78L83.34 45.13L82.97 44.59L82.19 44.17L81 43.87L79.43 43.7L77.48 43.66L75.19 43.75L72.58 43.97L69.68 44.31L66.54 44.78L63.19 45.36L59.68 46.05L56.04 46.84L52.33 47.73L48.59 48.68Z"
|
|
7
|
-
},
|
|
8
|
-
"eyes": {
|
|
9
|
-
"x": 50,
|
|
10
|
-
"y": 46,
|
|
11
|
-
"spacing": 15,
|
|
12
|
-
"scale": 1.05
|
|
13
|
-
}
|
|
14
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 1,
|
|
3
|
-
"id": "relay",
|
|
4
|
-
"name": "Relay",
|
|
5
|
-
"body": {
|
|
6
|
-
"path": "M40 30H60A24 24 0 0 1 84 54V62A24 24 0 0 1 60 86H40A24 24 0 0 1 16 62V54A24 24 0 0 1 40 30ZM49 16H51A4 4 0 0 1 55 20V30A4 4 0 0 1 51 34H49A4 4 0 0 1 45 30V20A4 4 0 0 1 49 16ZM43 15A7 7 0 1 1 57 15A7 7 0 1 1 43 15Z"
|
|
7
|
-
},
|
|
8
|
-
"eyes": {
|
|
9
|
-
"x": 50,
|
|
10
|
-
"y": 56,
|
|
11
|
-
"spacing": 18,
|
|
12
|
-
"scale": 1.12
|
|
13
|
-
}
|
|
14
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 1,
|
|
3
|
-
"id": "spark",
|
|
4
|
-
"name": "Spark",
|
|
5
|
-
"body": {
|
|
6
|
-
"path": "M50 10C53.6 10 56 28 62 34C68 40 90 45.2 90 50C90 54.8 68 60 62 66C56 72 53.6 90 50 90C46.4 90 44 72 38 66C32 60 10 54.8 10 50C10 45.2 32 40 38 34C44 28 46.4 10 50 10Z"
|
|
7
|
-
},
|
|
8
|
-
"eyes": {
|
|
9
|
-
"x": 50,
|
|
10
|
-
"y": 50,
|
|
11
|
-
"spacing": 15,
|
|
12
|
-
"scale": 1.05
|
|
13
|
-
}
|
|
14
|
-
}
|