xinghe-muse 0.0.0-stage → 2.2.2
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 +161 -2
- package/cordis.patch.yml +4 -0
- package/docs/DETAIL.md +159 -0
- package/icon.svg +14 -0
- package/install.ps1 +40 -0
- package/install.sh +27 -0
- package/lib/drive.mjs +94 -0
- package/lib/index.js +403 -0
- package/lib/platform.mjs +176 -0
- package/lib/run-muse.mjs +335 -0
- package/lib/setup.mjs +235 -0
- package/locale/en.json +8 -0
- package/locale/zh.json +8 -0
- package/package.json +42 -3
package/lib/run-muse.mjs
ADDED
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* xinghe-muse 浏览器驱动 —— 在 ego lite 里操作 muse.ai 出图 / 出视频。
|
|
3
|
+
*
|
|
4
|
+
* 作者:星禾
|
|
5
|
+
*
|
|
6
|
+
* 由 lib/drive.mjs 从 stdin 喂给 `ego-browser nodejs` 执行,因此这里拿不到 argv,
|
|
7
|
+
* 也读不到 shell 环境变量:所有输入都在 globalThis.__museArgv 里。
|
|
8
|
+
*
|
|
9
|
+
* argv: <指令> <保存目录> <超时秒> <文件名提示> <任务空间名> <类型 image|video>
|
|
10
|
+
*
|
|
11
|
+
* stdout 只打一行 JSON 作为结果,诊断信息一律走 stderr,调用方靠这个分界。
|
|
12
|
+
*
|
|
13
|
+
* 三条实测教训,改这里之前先看:
|
|
14
|
+
* 1. 图片产物是 <button aria-label="打开生成的图片…">,视频产物是
|
|
15
|
+
* <div role="button" aria-label="打开动画视频 ….mp4">。只查 button 会漏掉视频。
|
|
16
|
+
* 2. ego 的 loc=css 对 [role="button"] 这类属性选择器不稳,点不动。
|
|
17
|
+
* 所以产物一律先 evaluate 取包围盒,再用 mouse.click 按坐标点。
|
|
18
|
+
* 3. 直接 goto /thread/new 时好时坏,第二次常拿到空白页。
|
|
19
|
+
* 先进首页、点「新旁聊」,拿不到再退回直接开。
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
const [prompt, outDir, timeoutSec, nameHint, spaceName, kindRaw] = globalThis.__museArgv ?? []
|
|
23
|
+
const KIND = kindRaw === 'video' ? 'video' : 'image'
|
|
24
|
+
const IS_VIDEO = KIND === 'video'
|
|
25
|
+
|
|
26
|
+
/** 视频比图片慢得多,同一套轮询逻辑给更宽的上限。 */
|
|
27
|
+
const GEN_TIMEOUT = (IS_VIDEO
|
|
28
|
+
? Math.max(60, Math.min(Number(timeoutSec) || 420, 1800))
|
|
29
|
+
: Math.max(60, Math.min(Number(timeoutSec) || 180, 600))) * 1000
|
|
30
|
+
|
|
31
|
+
const COMPOSER = 'loc=css:textarea[placeholder="消息"]'
|
|
32
|
+
const SEND = 'loc=css:button[aria-label="发送"]'
|
|
33
|
+
const STOP = 'button[aria-label="停止"]'
|
|
34
|
+
const NEW_THREAD = 'https://muse.ai/thread/new'
|
|
35
|
+
const HOME = 'https://muse.ai/'
|
|
36
|
+
|
|
37
|
+
const say = (msg) => process.stderr.write(`${msg}\n`)
|
|
38
|
+
|
|
39
|
+
/** 生成中 Chrome 会挂一个停止按钮,它消失就是这轮结束。 */
|
|
40
|
+
const stillGenerating = `() => !!document.querySelector('${STOP}, button[aria-label*="中断"]')`
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* 找最新那条产物的可点元素,返回它的中心坐标。
|
|
44
|
+
*
|
|
45
|
+
* 先按 aria 文案挑(图片含「图片」,视频含「视频/动画视频」或 .mp4),
|
|
46
|
+
* 挑不到再按结构兜底:页面里最后一个够大的 video / img 的可点祖先。
|
|
47
|
+
* 返回矩形是给 mouse.click 用的,不走 CSS 选择器。
|
|
48
|
+
*/
|
|
49
|
+
const findMedia = `(kind) => {
|
|
50
|
+
const nodes = [...document.querySelectorAll('[role="button"], button, a')];
|
|
51
|
+
const isVideo = (a) => /(动画视频|视频|影片|video)/i.test(a) || /\\.(mp4|webm|mov)\\b/i.test(a);
|
|
52
|
+
const isImage = (a) => /(图片|图像|照片|image)/i.test(a) || /\\.(png|jpe?g|webp|gif)\\b/i.test(a);
|
|
53
|
+
const wanted = kind === 'video' ? isVideo : isImage;
|
|
54
|
+
|
|
55
|
+
const boxOf = (el) => {
|
|
56
|
+
const r = el.getBoundingClientRect();
|
|
57
|
+
return { x: Math.round(r.x), y: Math.round(r.y), w: Math.round(r.width), h: Math.round(r.height) };
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// 一:按文案,从后往前(最新的在后面)
|
|
61
|
+
for (let i = nodes.length - 1; i >= 0; i -= 1) {
|
|
62
|
+
const el = nodes[i];
|
|
63
|
+
const aria = (el.getAttribute('aria-label') || '') + ' ' + (el.getAttribute('title') || '');
|
|
64
|
+
if (!aria.trim()) continue;
|
|
65
|
+
if (!wanted(aria)) continue;
|
|
66
|
+
const b = boxOf(el);
|
|
67
|
+
if (b.w < 80 || b.h < 80) continue;
|
|
68
|
+
return { aria: el.getAttribute('aria-label') || '', ...b, how: 'aria' };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// 二:按结构兜底
|
|
72
|
+
const media = [...document.querySelectorAll(kind === 'video' ? 'video' : 'img')];
|
|
73
|
+
for (let i = media.length - 1; i >= 0; i -= 1) {
|
|
74
|
+
const host = media[i].closest('[role="button"], button, a');
|
|
75
|
+
if (!host) continue;
|
|
76
|
+
const b = boxOf(host);
|
|
77
|
+
if (b.w < 80 || b.h < 80) continue;
|
|
78
|
+
return { aria: host.getAttribute('aria-label') || '', ...b, how: 'dom' };
|
|
79
|
+
}
|
|
80
|
+
return null;
|
|
81
|
+
}`
|
|
82
|
+
|
|
83
|
+
/** 弹层里所有可点项的文字与 aria,用来找下载入口。 */
|
|
84
|
+
const dialogItems = `() => {
|
|
85
|
+
const scope = document.querySelector('[role="dialog"]') || document.body;
|
|
86
|
+
const items = [...scope.querySelectorAll('button, [role="button"], a')]
|
|
87
|
+
.map((el) => {
|
|
88
|
+
const r = el.getBoundingClientRect();
|
|
89
|
+
if (!r.width || !r.height) return null;
|
|
90
|
+
return {
|
|
91
|
+
label: (el.getAttribute('aria-label') || '').trim(),
|
|
92
|
+
text: (el.textContent || '').trim().slice(0, 24),
|
|
93
|
+
x: Math.round(r.x + r.width / 2),
|
|
94
|
+
y: Math.round(r.y + r.height / 2),
|
|
95
|
+
};
|
|
96
|
+
})
|
|
97
|
+
.filter(Boolean);
|
|
98
|
+
const dlgText = scope === document.body ? '' : (scope.textContent || '').trim().slice(0, 120);
|
|
99
|
+
return { items, dlgText };
|
|
100
|
+
}`
|
|
101
|
+
|
|
102
|
+
/** Muse 自己说的话,取最新的几条。 */
|
|
103
|
+
const replies = `() => {
|
|
104
|
+
const nodes = [...document.querySelectorAll('p, div')]
|
|
105
|
+
.map((n) => (n.textContent || '').trim())
|
|
106
|
+
.filter((t) => t.length > 8 && t.length < 400);
|
|
107
|
+
return [...new Set(nodes)].slice(-6);
|
|
108
|
+
}`
|
|
109
|
+
|
|
110
|
+
/** 文件名安全化:去掉路径分隔符与 Windows 保留字符。 */
|
|
111
|
+
const slug = (text) => text
|
|
112
|
+
.replace(/[\\/:*?"<>|\\s]+/g, '')
|
|
113
|
+
.replace(/^[.]+/, '')
|
|
114
|
+
.slice(0, 40) || (IS_VIDEO ? '视频' : '图片')
|
|
115
|
+
|
|
116
|
+
/** 把 aria 里那串机器名换成人能看的名,剥不掉就用兜底名。 */
|
|
117
|
+
const niceName = (aria) => {
|
|
118
|
+
const stripped = (aria || '')
|
|
119
|
+
.replace(/^打开/, '')
|
|
120
|
+
.replace(/^动画/, '')
|
|
121
|
+
.replace(/^生成的?/, '')
|
|
122
|
+
.replace(/^(图片|视频|影像|影片)/, '')
|
|
123
|
+
.replace(/^[\s::-]+/, '')
|
|
124
|
+
.replace(/\.(png|jpe?g|webp|gif|mp4|webm|mov)$/i, '')
|
|
125
|
+
.replace(/^media-generation[\w-]*$/i, '')
|
|
126
|
+
.trim()
|
|
127
|
+
return stripped && !/^media-generation/i.test(stripped) ? stripped : ''
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const stampOf = (date) => {
|
|
131
|
+
const p = (n) => String(n).padStart(2, '0')
|
|
132
|
+
return `${date.getFullYear()}${p(date.getMonth() + 1)}${p(date.getDate())}_${p(date.getHours())}${p(date.getMinutes())}${p(date.getSeconds())}`
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** 图片与视频各认一套扩展名,取下载文件名里真实的那个。 */
|
|
136
|
+
const EXT_RE = IS_VIDEO
|
|
137
|
+
? /\.(mp4|webm|mov|m4v)$/i
|
|
138
|
+
: /\.(png|jpe?g|webp|gif)$/i
|
|
139
|
+
const DEFAULT_EXT = IS_VIDEO ? '.mp4' : '.webp'
|
|
140
|
+
|
|
141
|
+
const empty = {
|
|
142
|
+
ok: false, threadUrl: '', media: null, kind: KIND, reply: '', caption: '', detail: '',
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function emit(value) {
|
|
146
|
+
process.stdout.write(`${JSON.stringify({ ...empty, ...value })}\n`)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* 一条真正的旁聊地址长什么样。
|
|
151
|
+
*
|
|
152
|
+
* 只判 `includes('/thread/')` 是不够的:占位页 `/thread/new` 本身就含 `/thread/`,
|
|
153
|
+
* 会把它当成功。所以要求 `/thread/` 后面还跟着一段 id。
|
|
154
|
+
*/
|
|
155
|
+
const THREAD_RE = /\/thread\/(?!new(\/|$|\?|#))[^/?#]+/
|
|
156
|
+
|
|
157
|
+
const isThread = (url) => THREAD_RE.test(url ?? '')
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* 进一条新旁聊。
|
|
161
|
+
*
|
|
162
|
+
* 直开 /thread/new 最快,偶尔会停在空白页,所以第一次不成时退到首页点入口。
|
|
163
|
+
* 首页那个入口在侧栏,是 <button>旁聊</button>(纯文字、没有 aria-label),
|
|
164
|
+
* 不是「新旁聊」几个字,所以 loc=text 只对「旁聊」才有戏。
|
|
165
|
+
* 无论走哪条路,最后都以 URL 变成真旁聊地址为成功判据。
|
|
166
|
+
*/
|
|
167
|
+
async function openNewThread(page) {
|
|
168
|
+
const landed = () => page.url().then(isThread)
|
|
169
|
+
|
|
170
|
+
const waitLanding = async (rounds) => {
|
|
171
|
+
for (let i = 0; i < rounds; i += 1) {
|
|
172
|
+
if (await landed()) return true
|
|
173
|
+
await page.waitForTimeout(700)
|
|
174
|
+
}
|
|
175
|
+
return landed()
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
await page.goto(NEW_THREAD, { waitUntil: 'domcontentloaded', timeout: 60_000 })
|
|
179
|
+
if (await waitLanding(12)) return page.url()
|
|
180
|
+
|
|
181
|
+
say('/thread/new 没跳成真旁聊,退到首页点入口')
|
|
182
|
+
await page.goto(HOME, { waitUntil: 'domcontentloaded', timeout: 60_000 })
|
|
183
|
+
await page.waitForTimeout(2000)
|
|
184
|
+
for (const label of ['旁聊', '新旁聊', '新建对话']) {
|
|
185
|
+
try {
|
|
186
|
+
await page.click(`loc=text=${label}`, { label, timeout: 4000 })
|
|
187
|
+
if (await waitLanding(12)) return page.url()
|
|
188
|
+
} catch {
|
|
189
|
+
// 试下一个文案
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
await page.goto(NEW_THREAD, { waitUntil: 'domcontentloaded', timeout: 60_000 })
|
|
193
|
+
await waitLanding(12)
|
|
194
|
+
return page.url()
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
async function main() {
|
|
198
|
+
const fs = await import('node:fs/promises')
|
|
199
|
+
const { join } = await import('node:path')
|
|
200
|
+
|
|
201
|
+
if (!prompt || prompt.trim() === '') {
|
|
202
|
+
emit({ detail: '指令是空的。填一句想让它做的事再调一次。' })
|
|
203
|
+
return
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
await fs.mkdir(outDir, { recursive: true })
|
|
207
|
+
|
|
208
|
+
// 每轮开一个独立空间,免得继承上一个任务的标签页;同名残留说明是上一轮,
|
|
209
|
+
// 直接接管而不是报错。
|
|
210
|
+
let task
|
|
211
|
+
try {
|
|
212
|
+
task = await taskSpace(spaceName)
|
|
213
|
+
} catch (error) {
|
|
214
|
+
if (!String(error?.message ?? error).includes('IN_USE')) throw error
|
|
215
|
+
task = await takeOverTaskSpace(spaceName)
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
try {
|
|
219
|
+
const page = task.page('p1')
|
|
220
|
+
|
|
221
|
+
await openNewThread(page)
|
|
222
|
+
await page.waitForSelector(COMPOSER, { state: 'visible', timeout: 30_000 })
|
|
223
|
+
|
|
224
|
+
// 写死:prompt 原样递交 Muse,不 trim、不扩写、不改一个字(上面的 trim 只用来判空)。
|
|
225
|
+
await page.fill(COMPOSER, prompt)
|
|
226
|
+
await page.waitForTimeout(500)
|
|
227
|
+
await page.click(SEND, { label: IS_VIDEO ? '发送视频指令' : '发送生成指令' })
|
|
228
|
+
await page.waitForTimeout(3000)
|
|
229
|
+
|
|
230
|
+
const threadUrl = await page.url()
|
|
231
|
+
|
|
232
|
+
// 没登录会被打回落地页,那里没有 thread id。在这里就判掉,不等满超时。
|
|
233
|
+
if (!isThread(threadUrl)) {
|
|
234
|
+
say('当前页面不是一条旁聊,多半是登录态过期')
|
|
235
|
+
emit({
|
|
236
|
+
threadUrl,
|
|
237
|
+
detail: '先在 ego lite 里登录 muse.ai,再调一次就好。',
|
|
238
|
+
})
|
|
239
|
+
return
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// 等这一轮结束:停止按钮出现又消失,或者干脆没出现过
|
|
243
|
+
const deadline = Date.now() + GEN_TIMEOUT
|
|
244
|
+
let generating = true
|
|
245
|
+
let sawStop = false
|
|
246
|
+
while (Date.now() < deadline) {
|
|
247
|
+
await page.waitForTimeout(IS_VIDEO ? 4000 : 2500)
|
|
248
|
+
generating = await page.evaluate(new Function(`return (${stillGenerating})()`))
|
|
249
|
+
if (generating) sawStop = true
|
|
250
|
+
else if (sawStop || Date.now() > deadline - GEN_TIMEOUT + 15_000) break
|
|
251
|
+
}
|
|
252
|
+
if (generating) {
|
|
253
|
+
say(`${GEN_TIMEOUT / 1000}s 后还在生成`)
|
|
254
|
+
emit({
|
|
255
|
+
threadUrl,
|
|
256
|
+
detail: `这一轮还在进行中,已经等了 ${Math.round(GEN_TIMEOUT / 1000)} 秒。`
|
|
257
|
+
+ '旁聊原样留着,可以调大 timeoutSeconds 再调一次,也能自己打开那条旁聊看。',
|
|
258
|
+
})
|
|
259
|
+
return
|
|
260
|
+
}
|
|
261
|
+
// 收尾动画还在跑,给它一点时间把产物挂上 DOM
|
|
262
|
+
await page.waitForTimeout(IS_VIDEO ? 5000 : 3000)
|
|
263
|
+
|
|
264
|
+
const found = await page.evaluate(new Function(`return (${findMedia})(${JSON.stringify(KIND)})`))
|
|
265
|
+
if (!found) {
|
|
266
|
+
const text = await page.evaluate(new Function(`return (${replies})()`))
|
|
267
|
+
const said = (text || []).slice(-2).join(' | ') || '(没有可读文字)'
|
|
268
|
+
emit({
|
|
269
|
+
threadUrl,
|
|
270
|
+
reply: said,
|
|
271
|
+
detail: `这一轮 Muse 回的是:${said} 旁聊留着,可以直接打开看,也可以再调一次。`,
|
|
272
|
+
})
|
|
273
|
+
return
|
|
274
|
+
}
|
|
275
|
+
say(`命中产物(${found.how}):${found.aria} @ ${found.x},${found.y} ${found.w}x${found.h}`)
|
|
276
|
+
|
|
277
|
+
// 走坐标点,不用 CSS 选择器:role=button 的选择器 ego 解析不了
|
|
278
|
+
await page.mouse.click(found.x + Math.round(found.w / 2), found.y + Math.round(found.h / 2))
|
|
279
|
+
await page.waitForTimeout(IS_VIDEO ? 4000 : 2500)
|
|
280
|
+
|
|
281
|
+
// 弹层里找下载入口:图片是「下载」,视频预览也是「下载」
|
|
282
|
+
const dialog = await page.evaluate(new Function(`return (${dialogItems})()`))
|
|
283
|
+
const dl = dialog.items.find((it) => /下载|保存|download/i.test(it.label + it.text))
|
|
284
|
+
if (!dl) {
|
|
285
|
+
const list = dialog.items.map((it) => it.label || it.text).filter(Boolean).slice(0, 12)
|
|
286
|
+
emit({
|
|
287
|
+
threadUrl,
|
|
288
|
+
caption: niceName(found.aria),
|
|
289
|
+
detail: '弹层里可点的项变了,取下载入口的规则要跟着调。'
|
|
290
|
+
+ `当前弹层标题:${dialog.dlgText || '(空)'};可点项:${list.join('、') || '(无)'}`,
|
|
291
|
+
})
|
|
292
|
+
return
|
|
293
|
+
}
|
|
294
|
+
say(`下载入口:${dl.label || dl.text} @ ${dl.x},${dl.y}`)
|
|
295
|
+
|
|
296
|
+
const download = page.waitForEvent('download', { timeout: IS_VIDEO ? 240_000 : 120_000 })
|
|
297
|
+
await page.mouse.click(dl.x, dl.y)
|
|
298
|
+
const file = await download
|
|
299
|
+
|
|
300
|
+
const suggested = file.suggestedFilename() || ''
|
|
301
|
+
const ext = EXT_RE.exec(suggested)?.[0] ?? DEFAULT_EXT
|
|
302
|
+
const caption = niceName(found.aria)
|
|
303
|
+
const base = slug(nameHint || caption || (IS_VIDEO ? 'muse生成视频' : 'muse生成图片'))
|
|
304
|
+
let target = join(outDir, `${base}_${stampOf(new Date())}${ext}`)
|
|
305
|
+
// 不覆盖已有文件:同一秒跑两次就加序号。
|
|
306
|
+
for (let i = 2; ; i += 1) {
|
|
307
|
+
try {
|
|
308
|
+
await fs.access(target)
|
|
309
|
+
target = join(outDir, `${base}_${stampOf(new Date())}_${i}${ext}`)
|
|
310
|
+
} catch {
|
|
311
|
+
break
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
await file.saveAs(target)
|
|
315
|
+
const stat = await fs.stat(target)
|
|
316
|
+
const text = await page.evaluate(new Function(`return (${replies})()`))
|
|
317
|
+
|
|
318
|
+
emit({
|
|
319
|
+
ok: true,
|
|
320
|
+
threadUrl,
|
|
321
|
+
media: target,
|
|
322
|
+
bytes: stat.size,
|
|
323
|
+
caption,
|
|
324
|
+
reply: (text || []).slice(-2).join(' | '),
|
|
325
|
+
detail: '',
|
|
326
|
+
})
|
|
327
|
+
} catch (error) {
|
|
328
|
+
emit({ detail: `驱动这一步没走完:${String(error?.message ?? error).split('\n')[0]}。再调一次通常就过去了。` })
|
|
329
|
+
} finally {
|
|
330
|
+
// 失败的轮次什么都不留;成功的已经把文件拷出来了。
|
|
331
|
+
await task.finish({ keep: [] }).catch(() => {})
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
await main()
|
package/lib/setup.mjs
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* xinghe-muse 的一键依赖安装 —— 把 ego lite 装到这台机器上。
|
|
3
|
+
*
|
|
4
|
+
* 作者:星禾
|
|
5
|
+
*
|
|
6
|
+
* node lib/setup.mjs 装(已经装了就只做体检)
|
|
7
|
+
* node lib/setup.mjs --check 只体检,不下载不装
|
|
8
|
+
*
|
|
9
|
+
* 干的事,按顺序:
|
|
10
|
+
* 1. 认平台与架构,挑对应的官方安装包
|
|
11
|
+
* 2. 已经装好且 ego-browser 能跑 → 直接收工
|
|
12
|
+
* 3. 下载到临时目录,边下边算 SHA256,和内置值对不上就丢弃
|
|
13
|
+
* 4. 静默安装(Windows 免 UAC,只装当前用户)
|
|
14
|
+
* 5. 重新定位 ego-browser,报告结果
|
|
15
|
+
*
|
|
16
|
+
* 只认官方 CDN。装的是浏览器本体,不含任何 muse 侧的东西;登录仍然要人工做一次。
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { spawn } from 'node:child_process'
|
|
20
|
+
import { createHash } from 'node:crypto'
|
|
21
|
+
import { access, constants, mkdtemp, readFile, rm, stat } from 'node:fs/promises'
|
|
22
|
+
import { createWriteStream } from 'node:fs'
|
|
23
|
+
import { homedir, platform, tmpdir } from 'node:os'
|
|
24
|
+
import { join } from 'node:path'
|
|
25
|
+
import { pipeline } from 'node:stream/promises'
|
|
26
|
+
|
|
27
|
+
import { findEgoApp, findEgoBrowser, IS_MAC, IS_WIN, platformNote } from './platform.mjs'
|
|
28
|
+
|
|
29
|
+
const CHECK_ONLY = process.argv.includes('--check')
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 官方安装包清单。
|
|
33
|
+
*
|
|
34
|
+
* 地址在 lite.ego.app 的下载页里不直接给,藏在打包好的 JS 里;这几个是其中的直链。
|
|
35
|
+
* 大小与 SHA256 是 2026-11-26 实测值,用来确认拿到的文件没被换过。
|
|
36
|
+
* 大小写成 0 表示只比对能拿到的那部分校验信息。
|
|
37
|
+
*/
|
|
38
|
+
const PACKAGES = {
|
|
39
|
+
'darwin-arm64': {
|
|
40
|
+
url: 'https://cdn.ego.app/setup/macos/arm64/egolite.dmg',
|
|
41
|
+
bytes: 149089310,
|
|
42
|
+
sha256: '',
|
|
43
|
+
},
|
|
44
|
+
'darwin-x64': {
|
|
45
|
+
url: 'https://cdn.ego.app/setup/macos/x64/egolite.dmg',
|
|
46
|
+
bytes: 167776176,
|
|
47
|
+
sha256: '',
|
|
48
|
+
},
|
|
49
|
+
'win32-x64': {
|
|
50
|
+
url: 'https://cdn.ego.app/setup/windows/x64/egoliteSetup.exe',
|
|
51
|
+
bytes: 19251800,
|
|
52
|
+
sha256: '0141c57275285da833e63d9ad0488b341bfe2227c3979db78e62dc0315d7f2ee',
|
|
53
|
+
},
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const log = (msg) => process.stdout.write(`${msg}\n`)
|
|
57
|
+
|
|
58
|
+
function pkgKey() {
|
|
59
|
+
if (IS_MAC) return platform() === 'darwin' ? `darwin-${process.arch}` : ''
|
|
60
|
+
if (IS_WIN) return `win32-${process.arch}`
|
|
61
|
+
return ''
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** 已经能用就不用再装。 */
|
|
65
|
+
async function alreadyReady() {
|
|
66
|
+
const browser = await findEgoBrowser()
|
|
67
|
+
if (!browser) return null
|
|
68
|
+
return browser
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** 下载并算哈希;大小对不上直接失败。 */
|
|
72
|
+
async function download(spec, target) {
|
|
73
|
+
log(`下载 ${spec.url}`)
|
|
74
|
+
const res = await fetch(spec.url, { redirect: 'follow' })
|
|
75
|
+
if (!res.ok) throw new Error(`下载失败:HTTP ${res.status} ${res.statusText}`)
|
|
76
|
+
if (!res.body) throw new Error('下载失败:响应没有内容')
|
|
77
|
+
|
|
78
|
+
const hash = createHash('sha256')
|
|
79
|
+
let total = 0
|
|
80
|
+
const sink = createWriteStream(target)
|
|
81
|
+
// 逐块落盘并同步喂给哈希,避免再读一遍整个安装包。
|
|
82
|
+
const reader = res.body.getReader?.()
|
|
83
|
+
if (reader) {
|
|
84
|
+
for (;;) {
|
|
85
|
+
const { done, value } = await reader.read()
|
|
86
|
+
if (done) break
|
|
87
|
+
const buf = Buffer.from(value)
|
|
88
|
+
total += buf.length
|
|
89
|
+
hash.update(buf)
|
|
90
|
+
if (!sink.write(buf)) {
|
|
91
|
+
await new Promise((resolve) => sink.once('drain', resolve))
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
await new Promise((resolve, reject) => sink.end((err) => (err ? reject(err) : resolve())))
|
|
95
|
+
} else {
|
|
96
|
+
await pipeline(res.body, sink)
|
|
97
|
+
const bytes = await readFile(target)
|
|
98
|
+
total = bytes.length
|
|
99
|
+
hash.update(bytes)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const digest = hash.digest('hex')
|
|
103
|
+
log(` 拿到 ${total.toLocaleString()} 字节,sha256=${digest}`)
|
|
104
|
+
|
|
105
|
+
if (spec.bytes > 0 && total !== spec.bytes) {
|
|
106
|
+
throw new Error(`大小不符:期望 ${spec.bytes},实际 ${total}`)
|
|
107
|
+
}
|
|
108
|
+
if (spec.sha256 && digest !== spec.sha256) {
|
|
109
|
+
throw new Error(`校验失败:期望 ${spec.sha256},实际 ${digest}`)
|
|
110
|
+
}
|
|
111
|
+
return { total, digest }
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** 跑一个外部命令,实时把输出转出来。 */
|
|
115
|
+
function run(cmd, args, options = {}) {
|
|
116
|
+
return new Promise((resolve) => {
|
|
117
|
+
const child = spawn(cmd, args, { stdio: 'inherit', windowsHide: true, ...options })
|
|
118
|
+
child.on('close', (code) => resolve(code ?? -1))
|
|
119
|
+
child.on('error', (error) => {
|
|
120
|
+
log(` 起不来:${error.message}`)
|
|
121
|
+
resolve(-1)
|
|
122
|
+
})
|
|
123
|
+
})
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** macOS:挂载 DMG,把 .app 拷进目录,再卸载。 */
|
|
127
|
+
async function installMac(dmg) {
|
|
128
|
+
const mountPoint = await mkdtemp(join(tmpdir(), 'xinghe-muse-dmg-'))
|
|
129
|
+
log(`挂载 DMG → ${mountPoint}`)
|
|
130
|
+
const attached = await run('hdiutil', [
|
|
131
|
+
'attach', dmg,
|
|
132
|
+
'-nobrowse', '-quiet', '-noverify',
|
|
133
|
+
'-mountpoint', mountPoint,
|
|
134
|
+
])
|
|
135
|
+
if (attached !== 0) throw new Error('挂载 DMG 失败')
|
|
136
|
+
|
|
137
|
+
try {
|
|
138
|
+
const source = join(mountPoint, 'ego lite.app')
|
|
139
|
+
await access(source, constants.F_OK)
|
|
140
|
+
const destDir = join(homedir(), 'Applications')
|
|
141
|
+
await run('mkdir', ['-p', destDir])
|
|
142
|
+
const dest = join(destDir, 'ego lite.app')
|
|
143
|
+
log(`复制 ego lite.app → ${dest}`)
|
|
144
|
+
await rm(dest, { recursive: true, force: true })
|
|
145
|
+
const copied = await run('cp', ['-R', source, dest])
|
|
146
|
+
if (copied !== 0) throw new Error('复制 ego lite.app 失败')
|
|
147
|
+
// 从网上下载的包会被打上隔离标记,不清掉首次启动会被拦。
|
|
148
|
+
await run('xattr', ['-dr', 'com.apple.quarantine', dest])
|
|
149
|
+
log('完成')
|
|
150
|
+
} finally {
|
|
151
|
+
await run('hdiutil', ['detach', mountPoint, '-quiet'])
|
|
152
|
+
await rm(mountPoint, { recursive: true, force: true })
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Windows:走官方 stager 的静默开关。
|
|
158
|
+
*
|
|
159
|
+
* /silent 不带 --system-level 就是「只装当前用户、不弹 UAC」,
|
|
160
|
+
* 这样整套流程不需要管理员权限。
|
|
161
|
+
*/
|
|
162
|
+
async function installWin(exe) {
|
|
163
|
+
log('静默安装(仅当前用户,不弹 UAC)')
|
|
164
|
+
const code = await run(exe, ['/silent'])
|
|
165
|
+
if (code !== 0) throw new Error(`安装程序退出码 ${code}`)
|
|
166
|
+
log('完成')
|
|
167
|
+
|
|
168
|
+
// Omaha 是异步的:stager 退出时文件可能还没铺完,给一点时间再定位。
|
|
169
|
+
for (let i = 0; i < 60; i += 1) {
|
|
170
|
+
if (await findEgoBrowser()) return
|
|
171
|
+
await new Promise((resolve) => setTimeout(resolve, 2000))
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
async function main() {
|
|
176
|
+
log('xinghe-muse 依赖安装')
|
|
177
|
+
log(`平台 ${platform()} / ${process.arch}`)
|
|
178
|
+
|
|
179
|
+
const browser = await alreadyReady()
|
|
180
|
+
if (browser) {
|
|
181
|
+
log(`ego-browser 已就绪:${browser}`)
|
|
182
|
+
if (CHECK_ONLY) return report(true)
|
|
183
|
+
log('ego lite 已经装好了,不需要再装。')
|
|
184
|
+
log('下一步:打开 ego lite,登录 muse.ai,然后就可以出图了。')
|
|
185
|
+
return report(true)
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (CHECK_ONLY) {
|
|
189
|
+
log(`缺依赖:找不到 ego-browser。${platformNote()}`)
|
|
190
|
+
return report(false)
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const key = pkgKey()
|
|
194
|
+
const spec = PACKAGES[key]
|
|
195
|
+
if (!spec) {
|
|
196
|
+
log(`这台机器(${platform()} / ${process.arch})没有对应的安装包。`)
|
|
197
|
+
log('ego lite 目前只出 macOS 与 Windows 版;Linux 官方仍在路线图上。')
|
|
198
|
+
return report(false)
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const work = await mkdtemp(join(tmpdir(), 'xinghe-muse-'))
|
|
202
|
+
const suffix = IS_MAC ? '.dmg' : '.exe'
|
|
203
|
+
const file = join(work, `egoliteSetup${suffix}`)
|
|
204
|
+
|
|
205
|
+
try {
|
|
206
|
+
await download(spec, file)
|
|
207
|
+
const size = (await stat(file)).size
|
|
208
|
+
log(`落盘 ${file}(${size.toLocaleString()} 字节)`)
|
|
209
|
+
|
|
210
|
+
if (IS_MAC) await installMac(file)
|
|
211
|
+
else if (IS_WIN) await installWin(file)
|
|
212
|
+
} finally {
|
|
213
|
+
await rm(work, { recursive: true, force: true })
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const after = await findEgoBrowser()
|
|
217
|
+
if (after) {
|
|
218
|
+
log(`ego-browser 就绪:${after}`)
|
|
219
|
+
report(true)
|
|
220
|
+
} else {
|
|
221
|
+
log('装完了但没找到 ego-browser。可能装在非默认位置。')
|
|
222
|
+
log('把它所在的目录加进 PATH,或用环境变量 EGO_BROWSER_BIN 指到它的绝对路径。')
|
|
223
|
+
report(false)
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function report(ok) {
|
|
228
|
+
log('')
|
|
229
|
+
log(ok ? '体检结果:可用。' : '体检结果:还不可用。')
|
|
230
|
+
log(`ego lite:${platformNote()}`)
|
|
231
|
+
log('登录:打开 ego lite,在 muse.ai 上登录一次,之后出图出视频都不用再管它了。')
|
|
232
|
+
process.exitCode = ok ? 0 : 1
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
await main()
|
package/locale/en.json
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"title": "xinghe-muse 出图-出视频",
|
|
4
|
+
"description": "Drive muse.ai inside the ego lite browser for images and video: open a new side thread, send the request, wait for the turn to finish, then download the original file into a folder. Nothing is clicked on screen, so a covered or minimised window and focus stealing cannot break a run. Works on macOS and Windows. Author: 星禾.",
|
|
5
|
+
"detail": "docs/DETAIL.md",
|
|
6
|
+
"author": "星禾"
|
|
7
|
+
}
|
|
8
|
+
}
|
package/locale/zh.json
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xinghe-muse",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
3
|
+
"version": "2.2.2",
|
|
4
|
+
"displayName": "xinghe-muse 出图-出视频",
|
|
5
|
+
"description": "Generate images and video through muse.ai in the ego lite browser, saving the downloaded file to a folder. Works on macOS and Windows.",
|
|
6
|
+
"author": "星禾",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"main": "./lib/index.js",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": "./lib/index.js",
|
|
12
|
+
"./locale/*.json": "./locale/*.json",
|
|
13
|
+
"./icon": "./icon.svg",
|
|
14
|
+
"./package.json": "./package.json"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"lib",
|
|
18
|
+
"locale/*.json",
|
|
19
|
+
"docs",
|
|
20
|
+
"icon.svg",
|
|
21
|
+
"README.md",
|
|
22
|
+
"cordis.patch.yml",
|
|
23
|
+
"install.sh",
|
|
24
|
+
"install.ps1"
|
|
25
|
+
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"install:deps": "node lib/setup.mjs",
|
|
28
|
+
"status": "node lib/setup.mjs --check"
|
|
29
|
+
},
|
|
30
|
+
"dsh": {
|
|
31
|
+
"bundle": {
|
|
32
|
+
"patch": "./cordis.patch.yml"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"engines": {
|
|
36
|
+
"dsh": ">=0.2.2-rc.5"
|
|
37
|
+
},
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"@deepseek-ai/dsh-tools": "0.2.2-rc.5",
|
|
40
|
+
"@deepseek-ai/cordis": "4.1.0"
|
|
41
|
+
},
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
}
|
|
6
45
|
}
|