@nodetool-ai/config 0.8.10 → 0.8.13
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/dist/.nodetool-build-stamp +1 -1
- package/dist/__tests__/deployment.test.d.ts +2 -0
- package/dist/__tests__/deployment.test.d.ts.map +1 -0
- package/dist/__tests__/deployment.test.js +32 -0
- package/dist/__tests__/deployment.test.js.map +1 -0
- package/dist/__tests__/google-workspace.test.js +12 -1
- package/dist/__tests__/google-workspace.test.js.map +1 -1
- package/dist/deployment.d.ts +12 -3
- package/dist/deployment.d.ts.map +1 -1
- package/dist/deployment.js +17 -4
- package/dist/deployment.js.map +1 -1
- package/dist/google-workspace.js +4 -4
- package/dist/google-workspace.js.map +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/package-asset-registry.d.ts.map +1 -1
- package/dist/package-asset-registry.js +2 -0
- package/dist/package-asset-registry.js.map +1 -1
- package/dist/package-media.d.ts +71 -0
- package/dist/package-media.d.ts.map +1 -0
- package/dist/package-media.js +192 -0
- package/dist/package-media.js.map +1 -0
- package/dist/runtime-locations.d.ts +10 -0
- package/dist/runtime-locations.d.ts.map +1 -1
- package/dist/runtime-locations.js +20 -5
- package/dist/runtime-locations.js.map +1 -1
- package/dist/setting-catalog.js +18 -4
- package/dist/setting-catalog.js.map +1 -1
- package/dist/wan2gp-helper.d.ts +87 -0
- package/dist/wan2gp-helper.d.ts.map +1 -0
- package/dist/wan2gp-helper.js +471 -0
- package/dist/wan2gp-helper.js.map +1 -0
- package/dist/wan2gp-lock.d.ts +10 -0
- package/dist/wan2gp-lock.d.ts.map +1 -0
- package/dist/wan2gp-lock.js +57 -0
- package/dist/wan2gp-lock.js.map +1 -0
- package/dist/wan2gp-runtime.d.ts +54 -0
- package/dist/wan2gp-runtime.d.ts.map +1 -0
- package/dist/wan2gp-runtime.js +255 -0
- package/dist/wan2gp-runtime.js.map +1 -0
- package/package.json +7 -1
|
@@ -0,0 +1,471 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NodeTool's helper inside the installed Wan2GP, and the model catalog it
|
|
3
|
+
* writes.
|
|
4
|
+
*
|
|
5
|
+
* The helper runs in Wan2GP's own environment. It uses Wan2GP's public API
|
|
6
|
+
* (`shared.api`) and its own download functions, the ones the Wan2GP UI uses.
|
|
7
|
+
* Nothing in Wan2GP is changed.
|
|
8
|
+
*
|
|
9
|
+
* - `catalog <path>` writes every model with its capabilities, voices or
|
|
10
|
+
* languages, and whether its weights are on disk. The installer runs it
|
|
11
|
+
* once, so the model menus read a file instead of starting Wan2GP.
|
|
12
|
+
* - `prepare <model>` downloads one model's weights into `ckpts/`. It first
|
|
13
|
+
* reports the size of the files still missing, from Hugging Face's
|
|
14
|
+
* headers, then the bytes written each second.
|
|
15
|
+
*/
|
|
16
|
+
import { z } from "zod";
|
|
17
|
+
import { wan2gpInstallDir, withWan2GPLock } from "./wan2gp-lock.js";
|
|
18
|
+
import { importNodeBuiltin, safeProcessEnv } from "./node-import.js";
|
|
19
|
+
/** The helper, written next to the release it runs in. Python 3.10+. */
|
|
20
|
+
export const WAN2GP_HELPER_SOURCE = String.raw `"""NodeTool's helper inside Wan2GP's environment.
|
|
21
|
+
|
|
22
|
+
catalog <path> write every model with its capabilities and file status
|
|
23
|
+
prepare <model> download one model's files, reporting progress
|
|
24
|
+
|
|
25
|
+
Protocol lines go to stdout as JSON. Wan2GP's own output goes to stderr.
|
|
26
|
+
"""
|
|
27
|
+
import contextlib
|
|
28
|
+
import json
|
|
29
|
+
import os
|
|
30
|
+
import sys
|
|
31
|
+
import threading
|
|
32
|
+
import time
|
|
33
|
+
from pathlib import Path
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@contextlib.contextmanager
|
|
37
|
+
def working_directory(path):
|
|
38
|
+
previous = os.getcwd()
|
|
39
|
+
os.chdir(path)
|
|
40
|
+
try:
|
|
41
|
+
yield
|
|
42
|
+
finally:
|
|
43
|
+
os.chdir(previous)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def true_keys(value):
|
|
47
|
+
return [key for key, flag in value.items() if flag is True] if isinstance(value, dict) else list(value or [])
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def catalog_row(record, status):
|
|
51
|
+
"""One model in the shape Wan2GP's MCP model search returns."""
|
|
52
|
+
media_inputs = {}
|
|
53
|
+
for kind, roles in (record.get("media_inputs") or {}).items():
|
|
54
|
+
if isinstance(roles, dict) and all(isinstance(flag, bool) for flag in roles.values()):
|
|
55
|
+
enabled = true_keys(roles)
|
|
56
|
+
if enabled:
|
|
57
|
+
media_inputs[kind] = enabled
|
|
58
|
+
elif roles:
|
|
59
|
+
media_inputs[kind] = roles
|
|
60
|
+
row = {
|
|
61
|
+
"model_type": record.get("model_type"),
|
|
62
|
+
"name": record.get("name") or record.get("model_type"),
|
|
63
|
+
"family": record.get("family"),
|
|
64
|
+
"base_model_type": record.get("base_model_type"),
|
|
65
|
+
"main_output": list(record.get("main_output") or record.get("outputs") or []),
|
|
66
|
+
"capabilities": true_keys(record.get("capabilities")),
|
|
67
|
+
"media_inputs": media_inputs,
|
|
68
|
+
"status": status,
|
|
69
|
+
}
|
|
70
|
+
mode = (record.get("setting_values") or {}).get("model_mode")
|
|
71
|
+
if isinstance(mode, dict) and mode.get("choices"):
|
|
72
|
+
row["model_modes"] = {
|
|
73
|
+
"label": str(mode.get("label") or ""),
|
|
74
|
+
"values": [str(choice.get("value")) if isinstance(choice, dict) else str(choice) for choice in mode["choices"]],
|
|
75
|
+
}
|
|
76
|
+
return row
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def model_files(module, model_type):
|
|
80
|
+
"""Wan2GP's own pre-load file selection, stopping before loading a model."""
|
|
81
|
+
model_def = module.get_model_def(model_type)
|
|
82
|
+
if model_def is None:
|
|
83
|
+
raise ValueError(f"Unknown Wan2GP model_type: {model_type}")
|
|
84
|
+
quantization = module.transformer_quantization
|
|
85
|
+
dtype_policy = module.transformer_dtype_policy
|
|
86
|
+
selected = []
|
|
87
|
+
primary = module.get_model_filename(model_type=model_type, quantization=quantization, dtype_policy=dtype_policy, model_def=model_def)
|
|
88
|
+
if primary:
|
|
89
|
+
selected.append((primary, 0, 1))
|
|
90
|
+
if "URLs2" in model_def:
|
|
91
|
+
secondary = module.get_model_filename(model_type=model_type, quantization=quantization, dtype_policy=dtype_policy, submodel_no=2, model_def=model_def)
|
|
92
|
+
if secondary:
|
|
93
|
+
selected.append((secondary, 0, 2))
|
|
94
|
+
for module_type in module.get_model_recursive_prop(model_type, "modules", return_list=True, model_def=model_def):
|
|
95
|
+
if isinstance(module_type, dict):
|
|
96
|
+
for submodel_no, key in ((1, "URLs"), (2, "URLs2")):
|
|
97
|
+
urls = module_type.get(key)
|
|
98
|
+
if urls is None:
|
|
99
|
+
raise ValueError(f"Wan2GP module is missing {key}: {module_type}")
|
|
100
|
+
filename = module.get_model_filename(model_type, quantization, dtype_policy, URLs=urls)
|
|
101
|
+
if filename:
|
|
102
|
+
selected.append((filename, 1, submodel_no))
|
|
103
|
+
else:
|
|
104
|
+
filename = module.get_model_filename(model_type, quantization, dtype_policy, module_type=module_type)
|
|
105
|
+
if filename:
|
|
106
|
+
selected.append((filename, 1, 0))
|
|
107
|
+
text_encoder = None
|
|
108
|
+
text_encoder_urls = module.get_model_recursive_prop(model_type, "text_encoder_URLs", return_list=True, model_def=model_def)
|
|
109
|
+
if text_encoder_urls:
|
|
110
|
+
text_encoder = module.get_model_filename(
|
|
111
|
+
model_type=model_type,
|
|
112
|
+
quantization=module.text_encoder_quantization,
|
|
113
|
+
dtype_policy=module.transformer_dtype_policy,
|
|
114
|
+
URLs=text_encoder_urls,
|
|
115
|
+
)
|
|
116
|
+
return model_def, selected, text_encoder
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def planned_size(module, model_type, model_def, filenames, weights):
|
|
120
|
+
"""Bytes still to fetch, from Hugging Face. Covers the files download_models fetches:
|
|
121
|
+
the model's own URLs, its preload and VAE URLs, and its family's repository files."""
|
|
122
|
+
from huggingface_hub import HfApi, get_hf_file_metadata
|
|
123
|
+
|
|
124
|
+
present = set()
|
|
125
|
+
for _directory, _dirs, files in os.walk(weights, followlinks=True):
|
|
126
|
+
present.update(files)
|
|
127
|
+
urls = list(filenames)
|
|
128
|
+
urls += module.get_model_recursive_prop(model_type, "preload_URLs", return_list=True, model_def=model_def) or []
|
|
129
|
+
vae = model_def.get("VAE_URLs", [])
|
|
130
|
+
urls += [vae] if isinstance(vae, str) else list(vae or [])
|
|
131
|
+
total = 0
|
|
132
|
+
count = 0
|
|
133
|
+
for url in dict.fromkeys(urls):
|
|
134
|
+
if not isinstance(url, str) or not url.startswith("https://") or os.path.basename(url) in present:
|
|
135
|
+
continue
|
|
136
|
+
try:
|
|
137
|
+
total += int(get_hf_file_metadata(url).size or 0)
|
|
138
|
+
count += 1
|
|
139
|
+
except Exception:
|
|
140
|
+
continue
|
|
141
|
+
api = HfApi()
|
|
142
|
+
base_model_type = module.get_base_model_type(model_type)
|
|
143
|
+
repos = module.model_types_handlers[base_model_type].query_model_files(
|
|
144
|
+
lambda filename: [] if filename is None else [filename[filename.rfind("/") + 1:]], base_model_type, model_def
|
|
145
|
+
)
|
|
146
|
+
for repo in repos if isinstance(repos, list) else [repos]:
|
|
147
|
+
if not repo or not repo.get("repoId"):
|
|
148
|
+
continue
|
|
149
|
+
for source, files in zip(repo.get("sourceFolderList") or [], repo.get("fileList") or []):
|
|
150
|
+
prefix = f"{source.rstrip('/')}/" if source else ""
|
|
151
|
+
try:
|
|
152
|
+
if files:
|
|
153
|
+
paths = [prefix + name for name in files if os.path.basename(name) not in present]
|
|
154
|
+
entries = api.get_paths_info(repo["repoId"], paths) if paths else []
|
|
155
|
+
else:
|
|
156
|
+
entries = [
|
|
157
|
+
entry
|
|
158
|
+
for entry in api.list_repo_tree(repo["repoId"], path_in_repo=source or None, recursive=True)
|
|
159
|
+
if os.path.basename(entry.path) not in present
|
|
160
|
+
]
|
|
161
|
+
except Exception:
|
|
162
|
+
continue
|
|
163
|
+
for entry in entries:
|
|
164
|
+
size = getattr(entry, "size", None)
|
|
165
|
+
if isinstance(size, int) and getattr(entry, "type", "file") != "directory":
|
|
166
|
+
total += size
|
|
167
|
+
count += 1
|
|
168
|
+
return total, count
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def prepare(module, model_type, model_def, selected, text_encoder):
|
|
172
|
+
if not selected:
|
|
173
|
+
module.download_models("", model_type, 0, -1, model_def=model_def)
|
|
174
|
+
for filename, file_type, submodel_no in selected:
|
|
175
|
+
module.download_models(filename, model_type, file_type, submodel_no, model_def=model_def)
|
|
176
|
+
if text_encoder:
|
|
177
|
+
module.download_models(text_encoder, model_type, 2, -1, force_path=model_def.get("text_encoder_folder"), model_def=model_def)
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
def folder_state(root):
|
|
181
|
+
"""Bytes under root and the files written in the last seconds."""
|
|
182
|
+
total = 0
|
|
183
|
+
recent = []
|
|
184
|
+
now = time.time()
|
|
185
|
+
for directory, _dirs, files in os.walk(root, followlinks=True):
|
|
186
|
+
for name in files:
|
|
187
|
+
try:
|
|
188
|
+
stat = os.stat(os.path.join(directory, name))
|
|
189
|
+
except OSError:
|
|
190
|
+
continue
|
|
191
|
+
total += stat.st_size
|
|
192
|
+
if now - stat.st_mtime < 5:
|
|
193
|
+
recent.append(name)
|
|
194
|
+
return total, recent[:8]
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def main():
|
|
198
|
+
out = os.fdopen(os.dup(sys.stdout.fileno()), "w", encoding="utf-8", buffering=1)
|
|
199
|
+
sys.stdout.flush()
|
|
200
|
+
os.dup2(sys.stderr.fileno(), sys.stdout.fileno())
|
|
201
|
+
|
|
202
|
+
def emit(payload):
|
|
203
|
+
out.write(json.dumps(payload, separators=(",", ":")) + "\n")
|
|
204
|
+
out.flush()
|
|
205
|
+
|
|
206
|
+
command = sys.argv[1] if len(sys.argv) > 1 else ""
|
|
207
|
+
argument = sys.argv[2] if len(sys.argv) > 2 else ""
|
|
208
|
+
root = Path.cwd()
|
|
209
|
+
sys.path.insert(0, str(root))
|
|
210
|
+
with contextlib.redirect_stdout(sys.stderr):
|
|
211
|
+
from shared.api import init
|
|
212
|
+
|
|
213
|
+
session = init(root=str(root), console_output=True, console_isatty=False)
|
|
214
|
+
session.ensure_ready()
|
|
215
|
+
if command == "catalog" and argument:
|
|
216
|
+
records = session.list_model_metadata()
|
|
217
|
+
status = {record["model_type"]: record["status"] for record in session.list_model_availability()}
|
|
218
|
+
rows = [catalog_row(record, status.get(record.get("model_type"), "missing")) for record in records]
|
|
219
|
+
target = Path(argument)
|
|
220
|
+
partial = target.with_name(target.name + ".partial")
|
|
221
|
+
partial.write_text(json.dumps({"version": 1, "models": rows}), encoding="utf-8")
|
|
222
|
+
os.replace(partial, target)
|
|
223
|
+
emit({"type": "catalog", "count": len(rows)})
|
|
224
|
+
return 0
|
|
225
|
+
if command == "prepare" and argument:
|
|
226
|
+
runtime = session._ensure_runtime()
|
|
227
|
+
module = runtime.module
|
|
228
|
+
weights = root / "ckpts"
|
|
229
|
+
with working_directory(runtime.root):
|
|
230
|
+
model_def, selected, text_encoder = model_files(module, argument)
|
|
231
|
+
filenames = [filename for filename, _, _ in selected] + ([text_encoder] if text_encoder else [])
|
|
232
|
+
try:
|
|
233
|
+
total, count = planned_size(module, argument, model_def, filenames, weights)
|
|
234
|
+
except Exception as error:
|
|
235
|
+
# The estimate is optional. Without it the bar shows bytes only.
|
|
236
|
+
print(f"No download size estimate: {error}", file=sys.stderr)
|
|
237
|
+
total, count = 0, 0
|
|
238
|
+
emit({"type": "total", "total_bytes": total, "total_files": count})
|
|
239
|
+
start, _ = folder_state(weights)
|
|
240
|
+
stop = threading.Event()
|
|
241
|
+
|
|
242
|
+
def observe():
|
|
243
|
+
while not stop.wait(1.0):
|
|
244
|
+
size, recent = folder_state(weights)
|
|
245
|
+
emit({"type": "progress", "downloaded_bytes": max(0, size - start), "current_files": recent})
|
|
246
|
+
|
|
247
|
+
observer = threading.Thread(target=observe, daemon=True)
|
|
248
|
+
observer.start()
|
|
249
|
+
try:
|
|
250
|
+
prepare(module, argument, model_def, selected, text_encoder)
|
|
251
|
+
finally:
|
|
252
|
+
stop.set()
|
|
253
|
+
observer.join(timeout=2)
|
|
254
|
+
emit({"type": "done", "status": session.get_model_availability(argument)["status"]})
|
|
255
|
+
return 0
|
|
256
|
+
raise SystemExit(f"Unknown command: {' '.join(sys.argv[1:])}")
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
if __name__ == "__main__":
|
|
260
|
+
try:
|
|
261
|
+
raise SystemExit(main())
|
|
262
|
+
except Exception as error:
|
|
263
|
+
print(f"Wan2GP helper failed: {error}", file=sys.stderr)
|
|
264
|
+
raise SystemExit(1) from error
|
|
265
|
+
`;
|
|
266
|
+
/** One protocol line of the helper's stdout. */
|
|
267
|
+
export const Wan2GPHelperLineSchema = z.discriminatedUnion("type", [
|
|
268
|
+
z.object({ type: z.literal("catalog"), count: z.number() }),
|
|
269
|
+
z.object({ type: z.literal("total"), total_bytes: z.number(), total_files: z.number() }),
|
|
270
|
+
z.object({ type: z.literal("progress"), downloaded_bytes: z.number(), current_files: z.array(z.string()) }),
|
|
271
|
+
z.object({ type: z.literal("done"), status: z.string() })
|
|
272
|
+
]);
|
|
273
|
+
/**
|
|
274
|
+
* Run the helper with `args` and pass each protocol line to `onLine`.
|
|
275
|
+
* Rejects with Wan2GP's last lines of output when it fails.
|
|
276
|
+
*/
|
|
277
|
+
export async function runWan2GPHelper(target, args, onLine, signal) {
|
|
278
|
+
const { python, sourceDir } = target;
|
|
279
|
+
if (!python || !sourceDir)
|
|
280
|
+
throw new Error("Wan2GP is not installed.");
|
|
281
|
+
const fs = await importNodeBuiltin("node:fs/promises");
|
|
282
|
+
const path = await importNodeBuiltin("node:path");
|
|
283
|
+
const childProcess = await importNodeBuiltin("node:child_process");
|
|
284
|
+
if (!fs || !path || !childProcess)
|
|
285
|
+
throw new Error("The Wan2GP helper needs Node.js");
|
|
286
|
+
const script = path.join(path.dirname(sourceDir), "nodetool_wan2gp.py");
|
|
287
|
+
await fs.writeFile(script, WAN2GP_HELPER_SOURCE);
|
|
288
|
+
const env = {};
|
|
289
|
+
for (const [key, value] of Object.entries(safeProcessEnv())) {
|
|
290
|
+
if (value !== undefined)
|
|
291
|
+
env[key] = value;
|
|
292
|
+
}
|
|
293
|
+
for (const key of ["PYTHONPATH", "PYTHONHOME", "VIRTUAL_ENV"])
|
|
294
|
+
delete env[key];
|
|
295
|
+
env.PYTHONUNBUFFERED = "1";
|
|
296
|
+
signal?.throwIfAborted();
|
|
297
|
+
await new Promise((resolve, reject) => {
|
|
298
|
+
const child = childProcess.spawn(python, [script, ...args], {
|
|
299
|
+
cwd: sourceDir,
|
|
300
|
+
env,
|
|
301
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
302
|
+
windowsHide: true
|
|
303
|
+
});
|
|
304
|
+
const tail = [];
|
|
305
|
+
let buffer = "";
|
|
306
|
+
child.stdout?.on("data", (chunk) => {
|
|
307
|
+
buffer += chunk.toString("utf8");
|
|
308
|
+
let newline;
|
|
309
|
+
while ((newline = buffer.indexOf("\n")) >= 0) {
|
|
310
|
+
const text = buffer.slice(0, newline).trim();
|
|
311
|
+
buffer = buffer.slice(newline + 1);
|
|
312
|
+
if (!text)
|
|
313
|
+
continue;
|
|
314
|
+
let parsed;
|
|
315
|
+
try {
|
|
316
|
+
parsed = JSON.parse(text);
|
|
317
|
+
}
|
|
318
|
+
catch {
|
|
319
|
+
// Wan2GP's own output that reached stdout.
|
|
320
|
+
}
|
|
321
|
+
const line = Wan2GPHelperLineSchema.safeParse(parsed);
|
|
322
|
+
if (line.success)
|
|
323
|
+
onLine(line.data);
|
|
324
|
+
else
|
|
325
|
+
tail.push(text);
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
child.stderr?.on("data", (chunk) => {
|
|
329
|
+
for (const line of chunk.toString("utf8").split(/\r?\n/)) {
|
|
330
|
+
if (!line.trim())
|
|
331
|
+
continue;
|
|
332
|
+
tail.push(line);
|
|
333
|
+
if (tail.length > 30)
|
|
334
|
+
tail.shift();
|
|
335
|
+
}
|
|
336
|
+
});
|
|
337
|
+
const onAbort = () => {
|
|
338
|
+
child.kill();
|
|
339
|
+
};
|
|
340
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
341
|
+
child.once("error", (error) => {
|
|
342
|
+
signal?.removeEventListener("abort", onAbort);
|
|
343
|
+
reject(new Error(`Could not run Wan2GP's interpreter: ${error.message}`));
|
|
344
|
+
});
|
|
345
|
+
child.once("close", (code) => {
|
|
346
|
+
signal?.removeEventListener("abort", onAbort);
|
|
347
|
+
if (signal?.aborted)
|
|
348
|
+
reject(signal.reason instanceof Error ? signal.reason : new Error("Cancelled"));
|
|
349
|
+
else if (code === 0)
|
|
350
|
+
resolve();
|
|
351
|
+
else
|
|
352
|
+
reject(new Error(`Wan2GP stopped with exit code ${code}:\n${tail.join("\n")}`));
|
|
353
|
+
});
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
/** The weights of one model, as Wan2GP's model selector reports them. */
|
|
357
|
+
export const Wan2GPFileStatusSchema = z.enum(["available", "partial", "missing"]);
|
|
358
|
+
/** One model, in the shape of a row of Wan2GP's MCP model search. */
|
|
359
|
+
export const Wan2GPCatalogRowSchema = z
|
|
360
|
+
.object({
|
|
361
|
+
model_type: z.string(),
|
|
362
|
+
name: z.string(),
|
|
363
|
+
family: z.string().nullish(),
|
|
364
|
+
base_model_type: z.string().nullish(),
|
|
365
|
+
main_output: z.array(z.string()),
|
|
366
|
+
capabilities: z.array(z.string()),
|
|
367
|
+
media_inputs: z.record(z.string(), z.unknown()),
|
|
368
|
+
model_modes: z.object({ label: z.string(), values: z.array(z.string()) }).optional(),
|
|
369
|
+
status: Wan2GPFileStatusSchema
|
|
370
|
+
})
|
|
371
|
+
.passthrough();
|
|
372
|
+
const CatalogSchema = z.object({
|
|
373
|
+
version: z.literal(1),
|
|
374
|
+
generation: z.string().optional(),
|
|
375
|
+
models: z.array(Wan2GPCatalogRowSchema)
|
|
376
|
+
});
|
|
377
|
+
/** The catalog sits beside the release's source, so an update writes a new one. */
|
|
378
|
+
export async function wan2gpCatalogPath(sourceDir) {
|
|
379
|
+
const path = await importNodeBuiltin("node:path");
|
|
380
|
+
if (!path)
|
|
381
|
+
throw new Error("The Wan2GP catalog needs Node.js");
|
|
382
|
+
return path.join(path.dirname(sourceDir), "catalog.json");
|
|
383
|
+
}
|
|
384
|
+
/** Source replacement marks a new install even at the same pinned commit. */
|
|
385
|
+
export async function wan2gpSourceIdentity(sourceDir) {
|
|
386
|
+
const fs = await importNodeBuiltin("node:fs/promises");
|
|
387
|
+
if (!fs)
|
|
388
|
+
throw new Error("Wan2GP needs Node.js to read its installed models.");
|
|
389
|
+
const stat = await fs.stat(sourceDir, { bigint: true });
|
|
390
|
+
return `${stat.dev}:${stat.ino}:${stat.birthtimeNs}`;
|
|
391
|
+
}
|
|
392
|
+
/** Source and catalog revisions shared by cached reads and conditional writes. */
|
|
393
|
+
export async function wan2gpCatalogKey(sourceDir, identity) {
|
|
394
|
+
const fs = await importNodeBuiltin("node:fs/promises");
|
|
395
|
+
if (!fs)
|
|
396
|
+
throw new Error("Wan2GP needs Node.js to read its installed models.");
|
|
397
|
+
try {
|
|
398
|
+
const file = await wan2gpCatalogPath(sourceDir);
|
|
399
|
+
const stat = await fs.stat(file, { bigint: true });
|
|
400
|
+
const fingerprint = `${stat.ino}:${stat.mtimeNs}:${stat.ctimeNs}:${stat.size}`;
|
|
401
|
+
const catalog = await readWan2GPCatalogDocument(sourceDir);
|
|
402
|
+
// A legacy catalog's first status update preserves its original revision
|
|
403
|
+
// as its generation, so another holder of that snapshot can still record.
|
|
404
|
+
return `${sourceDir}|${identity}|${catalog?.generation ?? fingerprint}|${fingerprint}`;
|
|
405
|
+
}
|
|
406
|
+
catch (error) {
|
|
407
|
+
if (error instanceof Error && "code" in error && error.code === "ENOENT")
|
|
408
|
+
return `${sourceDir}|${identity}|missing`;
|
|
409
|
+
throw error;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
/** Write the installed Wan2GP's catalog. Wan2GP starts its runtime for it but loads no model. */
|
|
413
|
+
export async function writeWan2GPCatalog(target, signal) {
|
|
414
|
+
if (!target.sourceDir)
|
|
415
|
+
throw new Error("Wan2GP is not installed.");
|
|
416
|
+
return withWan2GPLock(await wan2gpInstallDir(target.sourceDir), () => writeWan2GPCatalogUnlocked(target, signal), { signal });
|
|
417
|
+
}
|
|
418
|
+
/** The installer already holds the lifecycle lock when generating its catalog. */
|
|
419
|
+
export async function writeWan2GPCatalogUnlocked(target, signal) {
|
|
420
|
+
if (!target.sourceDir)
|
|
421
|
+
throw new Error("Wan2GP is not installed.");
|
|
422
|
+
let count = -1;
|
|
423
|
+
await runWan2GPHelper(target, ["catalog", await wan2gpCatalogPath(target.sourceDir)], (line) => {
|
|
424
|
+
if (line.type === "catalog")
|
|
425
|
+
count = line.count;
|
|
426
|
+
}, signal);
|
|
427
|
+
if (count < 0)
|
|
428
|
+
throw new Error("Wan2GP's helper wrote no model catalog");
|
|
429
|
+
return count;
|
|
430
|
+
}
|
|
431
|
+
/** The installed Wan2GP's catalog, or null when there is none or it does not parse. */
|
|
432
|
+
export async function readWan2GPCatalog(sourceDir) {
|
|
433
|
+
return (await readWan2GPCatalogDocument(sourceDir))?.models ?? null;
|
|
434
|
+
}
|
|
435
|
+
async function readWan2GPCatalogDocument(sourceDir) {
|
|
436
|
+
const fs = await importNodeBuiltin("node:fs/promises");
|
|
437
|
+
if (!fs)
|
|
438
|
+
return null;
|
|
439
|
+
try {
|
|
440
|
+
const parsed = CatalogSchema.safeParse(JSON.parse(await fs.readFile(await wan2gpCatalogPath(sourceDir), "utf8")));
|
|
441
|
+
return parsed.success ? parsed.data : null;
|
|
442
|
+
}
|
|
443
|
+
catch {
|
|
444
|
+
return null;
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
/** Record a model's file status in the catalog, after a download or a generation. */
|
|
448
|
+
export async function setWan2GPCatalogStatus(sourceDir, modelType, status, expectedKey) {
|
|
449
|
+
return withWan2GPLock(await wan2gpInstallDir(sourceDir), async () => {
|
|
450
|
+
// Validate after acquiring the same lock that guards repair and uninstall.
|
|
451
|
+
const identity = await wan2gpSourceIdentity(sourceDir);
|
|
452
|
+
const key = await wan2gpCatalogKey(sourceDir, identity);
|
|
453
|
+
const generationKey = (value) => value.slice(0, value.lastIndexOf("|"));
|
|
454
|
+
if (expectedKey !== undefined && generationKey(key) !== generationKey(expectedKey))
|
|
455
|
+
return null;
|
|
456
|
+
const fs = await importNodeBuiltin("node:fs/promises");
|
|
457
|
+
const catalog = await readWan2GPCatalogDocument(sourceDir);
|
|
458
|
+
const row = catalog?.models.find((model) => model.model_type === modelType);
|
|
459
|
+
if (!fs || !catalog || !row)
|
|
460
|
+
return null;
|
|
461
|
+
if (row.status === status)
|
|
462
|
+
return key;
|
|
463
|
+
row.status = status;
|
|
464
|
+
catalog.generation ??= key.slice(key.lastIndexOf("|") + 1);
|
|
465
|
+
const file = await wan2gpCatalogPath(sourceDir);
|
|
466
|
+
await fs.writeFile(`${file}.partial`, JSON.stringify(catalog));
|
|
467
|
+
await fs.rename(`${file}.partial`, file);
|
|
468
|
+
return wan2gpCatalogKey(sourceDir, identity);
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
//# sourceMappingURL=wan2gp-helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wan2gp-helper.js","sourceRoot":"","sources":["../src/wan2gp-helper.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,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+
readonly timeoutMs?: number;
|
|
5
|
+
}
|
|
6
|
+
/** Keep this lock outside the install, which uninstall removes while holding it. */
|
|
7
|
+
export declare function withWan2GPLock<T>(installDir: string, action: () => Promise<T>, options?: Wan2GPLockOptions): Promise<T>;
|
|
8
|
+
export declare function wan2gpInstallDir(sourceDir: string): Promise<string>;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=wan2gp-lock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wan2gp-lock.d.ts","sourceRoot":"","sources":["../src/wan2gp-lock.ts"],"names":[],"mappings":"AAEA,UAAU,iBAAiB;IACzB,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;IAC9B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IAC7B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,oFAAoF;AACpF,wBAAsB,cAAc,CAAC,CAAC,EACpC,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACxB,OAAO,GAAE,iBAAsB,GAC9B,OAAO,CAAC,CAAC,CAAC,CAyCZ;AAED,wBAAsB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAIzE"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { importNodeBuiltin } from "./node-import.js";
|
|
2
|
+
/** Keep this lock outside the install, which uninstall removes while holding it. */
|
|
3
|
+
export async function withWan2GPLock(installDir, action, options = {}) {
|
|
4
|
+
const fs = await importNodeBuiltin("node:fs/promises");
|
|
5
|
+
const path = await importNodeBuiltin("node:path");
|
|
6
|
+
const timers = await importNodeBuiltin("node:timers/promises");
|
|
7
|
+
if (!fs || !path || !timers)
|
|
8
|
+
throw new Error("Managing Wan2GP requires Node.js");
|
|
9
|
+
const target = path.resolve(installDir);
|
|
10
|
+
await fs.mkdir(path.dirname(target), { recursive: true });
|
|
11
|
+
let canonical;
|
|
12
|
+
try {
|
|
13
|
+
canonical = await fs.realpath(target);
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
if (!(error instanceof Error && "code" in error && error.code === "ENOENT"))
|
|
17
|
+
throw error;
|
|
18
|
+
canonical = path.join(await fs.realpath(path.dirname(target)), path.basename(target));
|
|
19
|
+
}
|
|
20
|
+
const lock = `${canonical}.nodetool-lock`;
|
|
21
|
+
const deadline = Date.now() + (options.timeoutMs ?? 10 * 60 * 1000);
|
|
22
|
+
let notified = false;
|
|
23
|
+
while (true) {
|
|
24
|
+
options.signal?.throwIfAborted();
|
|
25
|
+
try {
|
|
26
|
+
await fs.mkdir(lock);
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
if (!(error instanceof Error && "code" in error && error.code === "EEXIST"))
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
if (Date.now() >= deadline) {
|
|
34
|
+
// A timeout never permits deleting a lock another process may still own.
|
|
35
|
+
throw new Error(`Timed out waiting for Wan2GP at ${lock}. If its owner stopped, remove this directory and retry.`);
|
|
36
|
+
}
|
|
37
|
+
if (!notified) {
|
|
38
|
+
options.onWait?.();
|
|
39
|
+
notified = true;
|
|
40
|
+
}
|
|
41
|
+
await timers.setTimeout(100, undefined, { signal: options.signal });
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
options.signal?.throwIfAborted();
|
|
45
|
+
return await action();
|
|
46
|
+
}
|
|
47
|
+
finally {
|
|
48
|
+
await fs.rmdir(lock);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
export async function wan2gpInstallDir(sourceDir) {
|
|
52
|
+
const path = await importNodeBuiltin("node:path");
|
|
53
|
+
if (!path)
|
|
54
|
+
throw new Error("Managing Wan2GP requires Node.js");
|
|
55
|
+
return path.dirname(path.dirname(sourceDir));
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=wan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AAM,IAAI,GAAG,MAAM,iBAAiB,CAA6B,WAAW,CAAC,CAAC;IAC9E,IAAI,CAAC,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;IAC/D,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC;AAC/C,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/** Wan2GP v19.02, MCP API v2.1. */
|
|
2
|
+
export declare const WAN2GP_COMMIT = "616e60506aff10086bbbde02a3bf4554c572adde";
|
|
3
|
+
export declare const WAN2GP_VERSION = "v19.02";
|
|
4
|
+
export interface Wan2GPInstallStatus {
|
|
5
|
+
installed: boolean;
|
|
6
|
+
version?: string;
|
|
7
|
+
commit?: string;
|
|
8
|
+
/** The Wan2GP source directory, which `wgp.py` runs from. */
|
|
9
|
+
sourceDir?: string;
|
|
10
|
+
/** The interpreter of Wan2GP's environment. */
|
|
11
|
+
python?: string;
|
|
12
|
+
}
|
|
13
|
+
export declare function wan2gpInstallStatus(installDir: string, platform: string): Promise<Wan2GPInstallStatus>;
|
|
14
|
+
export type Wan2GPInstallEvent = {
|
|
15
|
+
type: "stage";
|
|
16
|
+
label: string;
|
|
17
|
+
} | {
|
|
18
|
+
type: "percent";
|
|
19
|
+
value: number;
|
|
20
|
+
} | {
|
|
21
|
+
type: "log";
|
|
22
|
+
line: string;
|
|
23
|
+
};
|
|
24
|
+
export interface Wan2GPInstallOptions {
|
|
25
|
+
installDir: string;
|
|
26
|
+
platform: string;
|
|
27
|
+
/** A Python 3.10 or newer to run Wan2GP's installer with. */
|
|
28
|
+
python: string;
|
|
29
|
+
/** The uv executable Wan2GP's installer creates its environment with. */
|
|
30
|
+
uv: string;
|
|
31
|
+
/** One of Wan2GP's hardware profiles, such as RTX_40, instead of the detected one. */
|
|
32
|
+
profile?: string;
|
|
33
|
+
signal?: AbortSignal;
|
|
34
|
+
onEvent?: (event: Wan2GPInstallEvent) => void;
|
|
35
|
+
/** Injected in tests. */
|
|
36
|
+
fetchImpl?: typeof fetch;
|
|
37
|
+
/** Injected in tests: a commit other than the pinned one. */
|
|
38
|
+
commit?: string;
|
|
39
|
+
archiveUrl?: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The installer's error, in plain words for the cases a user can act on:
|
|
43
|
+
* no supported GPU found, or a profile this operating system cannot use.
|
|
44
|
+
*/
|
|
45
|
+
export declare function installerFailure(exit: number | string | null, tail: string[]): string;
|
|
46
|
+
/**
|
|
47
|
+
* Download the pinned source, run Wan2GP's unattended installer, and make
|
|
48
|
+
* the result the current release. Rejects with the installer's last lines
|
|
49
|
+
* of output when it fails, for example on a machine whose GPU has no
|
|
50
|
+
* Wan2GP profile.
|
|
51
|
+
*/
|
|
52
|
+
export declare function installWan2GP(options: Wan2GPInstallOptions): Promise<Wan2GPInstallStatus>;
|
|
53
|
+
export declare function uninstallWan2GP(installDir: string): Promise<void>;
|
|
54
|
+
//# sourceMappingURL=wan2gp-runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wan2gp-runtime.d.ts","sourceRoot":"","sources":["../src/wan2gp-runtime.ts"],"names":[],"mappings":"AAyBA,mCAAmC;AACnC,eAAO,MAAM,aAAa,6CAA6C,CAAC;AACxE,eAAO,MAAM,cAAc,WAAW,CAAC;AAYvC,MAAM,WAAW,mBAAmB;IAClC,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,6DAA6D;IAC7D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,+CAA+C;IAC/C,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAQD,wBAAsB,mBAAmB,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAc5G;AAED,MAAM,MAAM,kBAA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