@animastor/installer 0.1.1 → 0.2.9
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 +153 -1
- package/ai/install-manifests/audio/qwen-tts.json +6 -7
- package/ai/install-manifests/image/qwen-image.json +3 -3
- package/ai/install-manifests/video/ltx-2.3.json +9 -9
- package/package.json +3 -3
- package/src/installer/cli.js +1493 -214
- package/src/installer/compatibility-resolver.js +58 -11
- package/src/installer/engine/comfy-owner.js +385 -0
- package/src/installer/engine/downloader.js +26 -0
- package/src/installer/engine/engine.js +600 -61
- package/src/installer/engine/fixes.js +96 -0
- package/src/installer/engine/io.js +33 -2
- package/src/installer/engine/node-deps.js +560 -0
- package/src/installer/engine/overrides.js +375 -0
- package/src/installer/engine/prereq.js +176 -0
- package/src/installer/engine/probe.js +265 -8
- package/src/installer/engine/pydeps.js +204 -0
- package/src/installer/engine/summary.js +124 -0
- package/src/installer/engine/tty.js +214 -0
- package/src/installer/engine/worker.js +736 -52
- package/src/installer/install-plan.js +99 -15
- package/src/installer/management.js +342 -13
- package/src/installer/platform/linux.js +17 -0
- package/src/installer/setup-contract.js +35 -23
- package/src/installer/verification-report.js +21 -5
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Interactive terminal for the installer prompts.
|
|
5
|
+
*
|
|
6
|
+
* The canonical way to run the installer is `curl -fsSL "<url>" | bash`:
|
|
7
|
+
* there stdin is the script pipe, NOT the keyboard. Every question (including
|
|
8
|
+
* the hidden Worker Key input) is therefore read from the controlling
|
|
9
|
+
* terminal /dev/tty, never from stdin. Without any terminal the installer
|
|
10
|
+
* fails with a clear message instead of silently reading the script as
|
|
11
|
+
* answers.
|
|
12
|
+
*
|
|
13
|
+
* Prompt rules (one question = one prompt, printed once):
|
|
14
|
+
* - no readline: every answer is read by one small raw-mode line editor
|
|
15
|
+
* (readline re-renders multi-line prompts and, with several interfaces
|
|
16
|
+
* on one input, echoes keystrokes twice — the old "double menu");
|
|
17
|
+
* - the question text is written ONCE, the prompt itself is one line;
|
|
18
|
+
* - CR, LF and CRLF end a line; type-ahead is kept for the next question;
|
|
19
|
+
* - hidden input uses the same editor without echo; pasted chunks are
|
|
20
|
+
* processed character by character.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
const fs = require('fs');
|
|
24
|
+
const tty = require('tty');
|
|
25
|
+
|
|
26
|
+
class NoTerminalError extends Error {
|
|
27
|
+
constructor(message) {
|
|
28
|
+
super(message);
|
|
29
|
+
this.name = 'NoTerminalError';
|
|
30
|
+
this.code = 'NO_TTY';
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const NO_TTY_MESSAGE = [
|
|
35
|
+
'No interactive terminal: the installer needs one to ask questions and the Worker Key (hidden input).',
|
|
36
|
+
'Run the install command in an SSH session or a local terminal (curl -fsSL "<url>" | bash reads answers from /dev/tty),',
|
|
37
|
+
'or add --yes when the Worker Key is already in the worker .env.',
|
|
38
|
+
].join('\n');
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Open the prompt streams: stdin/stdout when stdin is a TTY, else
|
|
42
|
+
* /dev/tty (piped `curl | bash`). Returns null when no terminal exists.
|
|
43
|
+
* Injectable for tests.
|
|
44
|
+
*/
|
|
45
|
+
function openTerminal({ stdin = process.stdin, stdout = process.stdout, fsMod = fs, ttyMod = tty, devTty = '/dev/tty' } = {}) {
|
|
46
|
+
if (stdin && stdin.isTTY) {
|
|
47
|
+
return { input: stdin, output: stdout, owned: false };
|
|
48
|
+
}
|
|
49
|
+
let inFd = null;
|
|
50
|
+
let outFd = null;
|
|
51
|
+
try {
|
|
52
|
+
inFd = fsMod.openSync(devTty, 'r');
|
|
53
|
+
outFd = fsMod.openSync(devTty, 'w');
|
|
54
|
+
const input = new ttyMod.ReadStream(inFd);
|
|
55
|
+
const output = stdout && stdout.isTTY ? stdout : new ttyMod.WriteStream(outFd);
|
|
56
|
+
return { input, output, owned: true, fds: [inFd, outFd] };
|
|
57
|
+
} catch (_) {
|
|
58
|
+
for (const fd of [inFd, outFd]) {
|
|
59
|
+
if (fd !== null) { try { fsMod.closeSync(fd); } catch (__) { /* ignore */ } }
|
|
60
|
+
}
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Line editor state machine for raw-mode input — pure (unit-tested).
|
|
67
|
+
* Feeds characters into `st` until a line is complete; characters after the
|
|
68
|
+
* end of the line stay in `st.rest` (type-ahead for the NEXT question — never
|
|
69
|
+
* lost, never mistaken for this answer). CR, LF and CRLF all end a line; the
|
|
70
|
+
* LF of a CRLF pair is swallowed.
|
|
71
|
+
* Returns the text to echo (nothing for hidden input).
|
|
72
|
+
*/
|
|
73
|
+
function feedLine(st, chunk, { hidden = false } = {}) {
|
|
74
|
+
let echo = '';
|
|
75
|
+
const chars = Array.from(String(chunk));
|
|
76
|
+
let i = 0;
|
|
77
|
+
for (; i < chars.length && !st.done; i++) {
|
|
78
|
+
const c = chars[i];
|
|
79
|
+
if (st.skipLf) {
|
|
80
|
+
st.skipLf = false;
|
|
81
|
+
if (c === '\n') continue;
|
|
82
|
+
}
|
|
83
|
+
if (c === '\r' || c === '\n') { st.done = true; st.endedWithCr = c === '\r'; break; }
|
|
84
|
+
if (c === '\u0003') { st.cancelled = true; st.done = true; break; } // Ctrl+C
|
|
85
|
+
if (c === '\u0004') { if (!st.value) st.eof = true; st.done = true; break; } // Ctrl+D
|
|
86
|
+
if (c === '\u007F' || c === '\b') {
|
|
87
|
+
if (st.value.length > 0) {
|
|
88
|
+
st.value = st.value.slice(0, -1);
|
|
89
|
+
if (!hidden) echo += '\b \b';
|
|
90
|
+
}
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
if (c === '\u001b') { st.inEscape = true; continue; } // arrow keys etc.: ignored
|
|
94
|
+
if (st.inEscape) { if (/[A-Za-z~]/.test(c)) st.inEscape = false; continue; }
|
|
95
|
+
if (c < ' ') continue; // other control chars
|
|
96
|
+
st.value += c;
|
|
97
|
+
if (!hidden) echo += c;
|
|
98
|
+
}
|
|
99
|
+
st.rest = chars.slice(i + 1).join('');
|
|
100
|
+
return echo;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Backwards-compatible helper for hidden input chunks (pure). */
|
|
104
|
+
function applySecretChunk(state, chunk) {
|
|
105
|
+
feedLine(state, chunk, { hidden: true });
|
|
106
|
+
return { value: state.value, done: state.done, cancelled: !!state.cancelled };
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Parse a Yes/No answer; empty → `def` (null = ask again). */
|
|
110
|
+
function parseYesNo(answer, def = null) {
|
|
111
|
+
const a = String(answer || '').trim();
|
|
112
|
+
if (!a) return def;
|
|
113
|
+
if (/^(y|yes|д|да)$/i.test(a)) return true;
|
|
114
|
+
if (/^(n|no|н|нет)$/i.test(a)) return false;
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Create the prompt API on top of a terminal (openTerminal()). With
|
|
120
|
+
* `term === null` every question throws NoTerminalError.
|
|
121
|
+
*/
|
|
122
|
+
function createPrompt(term = openTerminal()) {
|
|
123
|
+
let pending = ''; // type-ahead carried over between questions
|
|
124
|
+
let carrySkipLf = false;
|
|
125
|
+
const need = () => {
|
|
126
|
+
if (!term) throw new NoTerminalError(NO_TTY_MESSAGE);
|
|
127
|
+
return term;
|
|
128
|
+
};
|
|
129
|
+
/** Read one line in raw mode (echo unless hidden). null on Ctrl+D. */
|
|
130
|
+
const readLine = (promptText, { hidden = false } = {}) => new Promise((resolve) => {
|
|
131
|
+
const t = need();
|
|
132
|
+
const input = t.input;
|
|
133
|
+
if (!input.isTTY || typeof input.setRawMode !== 'function') {
|
|
134
|
+
throw new NoTerminalError(NO_TTY_MESSAGE);
|
|
135
|
+
}
|
|
136
|
+
t.output.write(promptText);
|
|
137
|
+
const st = { value: '', done: false, skipLf: carrySkipLf, rest: '' };
|
|
138
|
+
const finish = () => {
|
|
139
|
+
input.removeListener('data', onData);
|
|
140
|
+
input.setRawMode(false);
|
|
141
|
+
input.pause();
|
|
142
|
+
pending = st.rest;
|
|
143
|
+
carrySkipLf = !!st.endedWithCr && st.rest === '';
|
|
144
|
+
t.output.write('\n');
|
|
145
|
+
if (st.cancelled) {
|
|
146
|
+
// Ctrl+C keeps its meaning: interrupt the installer (the
|
|
147
|
+
// engine's SIGINT guard saves resumable state).
|
|
148
|
+
process.kill(process.pid, 'SIGINT');
|
|
149
|
+
resolve(null);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
resolve(st.eof ? null : st.value);
|
|
153
|
+
};
|
|
154
|
+
const onData = (chunk) => {
|
|
155
|
+
const echo = feedLine(st, chunk, { hidden });
|
|
156
|
+
if (echo) t.output.write(echo);
|
|
157
|
+
if (st.done) finish();
|
|
158
|
+
};
|
|
159
|
+
if (pending) {
|
|
160
|
+
const carried = pending;
|
|
161
|
+
pending = '';
|
|
162
|
+
const echo = feedLine(st, carried, { hidden });
|
|
163
|
+
if (echo) t.output.write(echo);
|
|
164
|
+
if (st.done) { finish(); return; }
|
|
165
|
+
}
|
|
166
|
+
input.setRawMode(true);
|
|
167
|
+
input.on('data', onData);
|
|
168
|
+
input.resume();
|
|
169
|
+
});
|
|
170
|
+
return {
|
|
171
|
+
available: !!term,
|
|
172
|
+
/**
|
|
173
|
+
* Yes/No question. `defaultYes`: Enter alone means Yes ([Y/n]).
|
|
174
|
+
* Unrecognized answers re-ask (at most 3 times, then No).
|
|
175
|
+
*/
|
|
176
|
+
async confirm(question, { defaultYes = false } = {}) {
|
|
177
|
+
const t = need();
|
|
178
|
+
const lines = String(question).split('\n');
|
|
179
|
+
const last = lines.pop();
|
|
180
|
+
if (lines.length > 0) t.output.write(`${lines.join('\n')}\n`);
|
|
181
|
+
for (let i = 0; i < 3; i++) {
|
|
182
|
+
const answer = await readLine(`${last} ${defaultYes ? '[Y/n]' : '[y/N]'} `);
|
|
183
|
+
if (answer === null) return false; // input closed (Ctrl+D)
|
|
184
|
+
const v = parseYesNo(answer, defaultYes);
|
|
185
|
+
if (v !== null) return v;
|
|
186
|
+
}
|
|
187
|
+
return false;
|
|
188
|
+
},
|
|
189
|
+
/** Numbered menu: printed once, then a single-line "> " prompt. */
|
|
190
|
+
async select(question, options) {
|
|
191
|
+
const t = need();
|
|
192
|
+
t.output.write(`${question}\n${options.map((o, i) => ` [${i + 1}] ${o}`).join('\n')}\n`);
|
|
193
|
+
const answer = await readLine('> ');
|
|
194
|
+
const n = parseInt(answer, 10);
|
|
195
|
+
return options[(n - 1)] || options[0];
|
|
196
|
+
},
|
|
197
|
+
/**
|
|
198
|
+
* Hidden input (raw mode, no echo). The value is never echoed, logged,
|
|
199
|
+
* stored in state or passed via argv.
|
|
200
|
+
*/
|
|
201
|
+
async secret(question) {
|
|
202
|
+
const value = await readLine(`${question}: `, { hidden: true });
|
|
203
|
+
return value && value.trim() ? value.trim() : null;
|
|
204
|
+
},
|
|
205
|
+
close() {
|
|
206
|
+
if (term && term.owned) {
|
|
207
|
+
try { term.input.destroy(); } catch (_) { /* ignore */ }
|
|
208
|
+
if (term.output !== process.stdout) { try { term.output.destroy(); } catch (_) { /* ignore */ } }
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
module.exports = { openTerminal, createPrompt, feedLine, applySecretChunk, parseYesNo, NoTerminalError, NO_TTY_MESSAGE };
|