odant-work 1.0.24 → 1.0.26
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/#system/package-manifest.json +18 -16
- package/MODELS/$ai/$folder/$class/$provider/handlers/pages/form/trainer/$handler/trainer.js +18 -3
- package/MODELS/Local/$provider/class.js +2 -2
- package/package.json +1 -1
- package/scripts/check-ignored-code.mjs +4 -2
- package/sources/data/progress.md +5 -1
- package/sources/host/auto-updater.js +1 -0
- package/sources/modules/license/index.js +4 -2
- package/sources/modules/trainer/dataset.js +5 -2
- package/sources/modules/trainer/halogen.js +48 -23
- package/sources/modules/trainer/huggingface.js +109 -36
- package/sources/modules/trainer/local-engine.js +8 -2
- package/sources/modules/trainer/paths.js +257 -0
- package/sources/modules/trainer/providers.js +23 -6
- package/sources/modules/trainer/runner.js +57 -31
- package/sources/modules/trainer/transfer.js +142 -136
|
@@ -9,6 +9,15 @@ import crypto from 'node:crypto';
|
|
|
9
9
|
import { spawn } from 'node:child_process';
|
|
10
10
|
import { registerLocalModelNode, estimateModelMemoryFromId, listHuggingFaceDownloads } from './huggingface.js';
|
|
11
11
|
import { verifyCompletion } from './dataset.js';
|
|
12
|
+
import {
|
|
13
|
+
localRootDir,
|
|
14
|
+
localAdaptersDir,
|
|
15
|
+
localDatasetsDir,
|
|
16
|
+
modelWeightsDir,
|
|
17
|
+
modelClassFile,
|
|
18
|
+
migrateLocalModelsLayoutSync,
|
|
19
|
+
WEIGHT_FILE_EXT_RE,
|
|
20
|
+
} from './paths.js';
|
|
12
21
|
|
|
13
22
|
const _jobs = new Map();
|
|
14
23
|
let _hwCache = null;
|
|
@@ -200,7 +209,7 @@ export async function detectHardware({ force = false } = {}) {
|
|
|
200
209
|
* Инвентарь локальных моделей и обученных LoRA-адаптеров в `/MODELS/Local`.
|
|
201
210
|
*/
|
|
202
211
|
export async function listLocalModelsAndAdapters(rootDir = process.cwd()) {
|
|
203
|
-
const localRoot =
|
|
212
|
+
const localRoot = localRootDir(rootDir);
|
|
204
213
|
const legacyHalogenRoot = path.join(rootDir, 'MODELS', 'Halogen');
|
|
205
214
|
|
|
206
215
|
// Автоматическая миграция и очистка устаревшей дублирующей папки MODELS/Halogen
|
|
@@ -213,7 +222,7 @@ export async function listLocalModelsAndAdapters(rootDir = process.cwd()) {
|
|
|
213
222
|
const oldWeights = path.join(legacyHalogenRoot, he.name, '#weights');
|
|
214
223
|
if (fs.existsSync(oldWeights)) {
|
|
215
224
|
const wf = await fsp.readdir(oldWeights).catch(() => []);
|
|
216
|
-
const hasRealWeight = wf.some(f => !f.endsWith('.part') &&
|
|
225
|
+
const hasRealWeight = wf.some(f => !f.endsWith('.part') && WEIGHT_FILE_EXT_RE.test(f));
|
|
217
226
|
if (hasRealWeight) {
|
|
218
227
|
const targetModelDir = path.join(localRoot, he.name);
|
|
219
228
|
if (!fs.existsSync(targetModelDir)) {
|
|
@@ -228,46 +237,62 @@ export async function listLocalModelsAndAdapters(rootDir = process.cwd()) {
|
|
|
228
237
|
catch { /* ignore */ }
|
|
229
238
|
}
|
|
230
239
|
|
|
240
|
+
const activeDownloads = listHuggingFaceDownloads(rootDir).filter(d => d.status === 'downloading');
|
|
241
|
+
migrateLocalModelsLayoutSync(rootDir, { skipModels: new Set(activeDownloads.map(d => d.folderName)) });
|
|
242
|
+
|
|
231
243
|
const models = [];
|
|
232
244
|
const adapters = [];
|
|
245
|
+
|
|
246
|
+
// Адаптеры хранятся внутри метапапки провайдера Local: MODELS/Local/$provider/#adapters
|
|
247
|
+
const adaptersDir = localAdaptersDir(rootDir);
|
|
248
|
+
if (fs.existsSync(adaptersDir)) {
|
|
249
|
+
const adEntries = await fsp.readdir(adaptersDir, { withFileTypes: true }).catch(() => []);
|
|
250
|
+
for (const ad of adEntries) {
|
|
251
|
+
if (!ad.isDirectory())
|
|
252
|
+
continue;
|
|
253
|
+
const cfgPath = path.join(adaptersDir, ad.name, 'adapter_config.json');
|
|
254
|
+
if (fs.existsSync(cfgPath)) {
|
|
255
|
+
try {
|
|
256
|
+
adapters.push(JSON.parse(await fsp.readFile(cfgPath, 'utf-8')));
|
|
257
|
+
}
|
|
258
|
+
catch { /* ignore */ }
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
233
263
|
if (!fs.existsSync(localRoot))
|
|
234
264
|
return { models, adapters };
|
|
235
265
|
|
|
236
|
-
const activeDownloads = listHuggingFaceDownloads().filter(d => d.status === 'downloading');
|
|
237
266
|
const entries = await fsp.readdir(localRoot, { withFileTypes: true });
|
|
238
267
|
for (const e of entries) {
|
|
239
|
-
if (!e.isDirectory() || e.name.startsWith('$'))
|
|
240
|
-
continue;
|
|
241
|
-
if (e.name === '#adapters') {
|
|
242
|
-
const adEntries = await fsp.readdir(path.join(localRoot, '#adapters'), { withFileTypes: true }).catch(() => []);
|
|
243
|
-
for (const ad of adEntries) {
|
|
244
|
-
if (!ad.isDirectory())
|
|
245
|
-
continue;
|
|
246
|
-
const cfgPath = path.join(localRoot, '#adapters', ad.name, 'adapter_config.json');
|
|
247
|
-
if (fs.existsSync(cfgPath)) {
|
|
248
|
-
try {
|
|
249
|
-
adapters.push(JSON.parse(await fsp.readFile(cfgPath, 'utf-8')));
|
|
250
|
-
}
|
|
251
|
-
catch { /* ignore */ }
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
continue;
|
|
255
|
-
}
|
|
256
|
-
if (e.name.startsWith('#'))
|
|
268
|
+
if (!e.isDirectory() || e.name.startsWith('$') || e.name.startsWith('#'))
|
|
257
269
|
continue;
|
|
258
270
|
|
|
259
271
|
const isDownloading = activeDownloads.some(
|
|
260
272
|
d => d.folderName === e.name || d.modelPath === `/MODELS/Local/${e.name}`
|
|
261
273
|
);
|
|
262
|
-
const aiClassFile =
|
|
263
|
-
const weightsDir =
|
|
274
|
+
const aiClassFile = modelClassFile(rootDir, e.name, 'Local');
|
|
275
|
+
const weightsDir = modelWeightsDir(rootDir, e.name, 'Local');
|
|
264
276
|
let weightFiles = [];
|
|
265
277
|
let hasRealWeightBinary = false;
|
|
278
|
+
let hasPendingDownload = false;
|
|
266
279
|
let sizeBytes = 0;
|
|
267
280
|
if (fs.existsSync(weightsDir)) {
|
|
268
281
|
const wf = await fsp.readdir(weightsDir).catch(() => []);
|
|
269
|
-
|
|
270
|
-
|
|
282
|
+
const hasParts = wf.some(f => f.endsWith('.part'));
|
|
283
|
+
let pendingState = false;
|
|
284
|
+
if (wf.includes('download-state.json')) {
|
|
285
|
+
try {
|
|
286
|
+
const st = JSON.parse(await fsp.readFile(path.join(weightsDir, 'download-state.json'), 'utf-8'));
|
|
287
|
+
pendingState = st?.status !== 'completed';
|
|
288
|
+
}
|
|
289
|
+
catch {
|
|
290
|
+
pendingState = true;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
hasPendingDownload = hasParts || pendingState;
|
|
294
|
+
weightFiles = wf.filter(f => !f.endsWith('.part') && f !== 'hf-manifest.json' && f !== 'download-state.json' && !f.endsWith('.tmp'));
|
|
295
|
+
hasRealWeightBinary = weightFiles.some(f => WEIGHT_FILE_EXT_RE.test(f));
|
|
271
296
|
for (const f of weightFiles) {
|
|
272
297
|
try {
|
|
273
298
|
const st = await fsp.stat(path.join(weightsDir, f));
|
|
@@ -288,8 +313,8 @@ export async function listLocalModelsAndAdapters(rootDir = process.cwd()) {
|
|
|
288
313
|
|
|
289
314
|
const isAdapterNode = Boolean(meta.adapterPath);
|
|
290
315
|
|
|
291
|
-
// Если папка модели
|
|
292
|
-
if (!isDownloading && !hasRealWeightBinary && !isAdapterNode) {
|
|
316
|
+
// Если папка модели пустая (ни готовых весов, ни незавершённой загрузки, ни адаптера) — убираем мусор
|
|
317
|
+
if (!isDownloading && !hasPendingDownload && !hasRealWeightBinary && !isAdapterNode) {
|
|
293
318
|
try {
|
|
294
319
|
await fsp.rm(path.join(localRoot, e.name), { recursive: true, force: true });
|
|
295
320
|
}
|
|
@@ -297,8 +322,8 @@ export async function listLocalModelsAndAdapters(rootDir = process.cwd()) {
|
|
|
297
322
|
continue;
|
|
298
323
|
}
|
|
299
324
|
|
|
300
|
-
// Пока модель
|
|
301
|
-
if (isDownloading
|
|
325
|
+
// Пока модель качается или стоит на паузе/обрыве, она отображается только в загрузках, а не в «Установленных»
|
|
326
|
+
if ((isDownloading || hasPendingDownload) && !isAdapterNode) {
|
|
302
327
|
continue;
|
|
303
328
|
}
|
|
304
329
|
|
|
@@ -370,8 +395,9 @@ export async function startTrainingJob({
|
|
|
370
395
|
const resolvedMaxSeq = Number(maxSeqLength) || hw.recommendedMaxSeq || 8192;
|
|
371
396
|
|
|
372
397
|
const safeAdapter = String(adapterName || 'work-lora').replace(/[<>:"/\\|?*]/g, '-').trim();
|
|
373
|
-
|
|
374
|
-
const
|
|
398
|
+
migrateLocalModelsLayoutSync(rootDir);
|
|
399
|
+
const datasetFile = path.join(localDatasetsDir(rootDir), `${datasetName}.jsonl`);
|
|
400
|
+
const outputDir = path.join(localAdaptersDir(rootDir), safeAdapter);
|
|
375
401
|
await fsp.mkdir(outputDir, { recursive: true });
|
|
376
402
|
|
|
377
403
|
let datasetLines = 0;
|
|
@@ -15,6 +15,19 @@ import crypto from 'node:crypto';
|
|
|
15
15
|
import { spawn } from 'node:child_process';
|
|
16
16
|
import { registerLocalModelNode } from './huggingface.js';
|
|
17
17
|
import { createTarExportStream, extractTarStream, sanitizeTarRelPath } from './tar-stream.js';
|
|
18
|
+
import {
|
|
19
|
+
localRootDir,
|
|
20
|
+
localAdaptersDir,
|
|
21
|
+
localDatasetsDir,
|
|
22
|
+
localRuntimeDir,
|
|
23
|
+
localTempDir,
|
|
24
|
+
modelDir as getModelDir,
|
|
25
|
+
modelWeightsDir as getModelWeightsDir,
|
|
26
|
+
modelClassFile as getModelClassFile,
|
|
27
|
+
migrateLocalModelsLayoutSync,
|
|
28
|
+
mergeMoveDirSync,
|
|
29
|
+
hasReadyWeightFilesSync,
|
|
30
|
+
} from './paths.js';
|
|
18
31
|
|
|
19
32
|
export const TRANSFER_MANIFEST_FILE = 'work-models-manifest.json';
|
|
20
33
|
const COPY_CHUNK_BYTES = 4 * 1024 * 1024;
|
|
@@ -186,11 +199,11 @@ function hasBackupContentSync(dirPath) {
|
|
|
186
199
|
for (const e of entries) {
|
|
187
200
|
if (!e.isDirectory())
|
|
188
201
|
continue;
|
|
189
|
-
if (e.name === '#adapters' || e.name === '#datasets' || e.name === '#runtime')
|
|
202
|
+
if (e.name === '#adapters' || e.name === '#datasets' || e.name === '#runtime' || e.name === '$provider')
|
|
190
203
|
return true;
|
|
191
204
|
if (e.name.startsWith('$') || e.name.startsWith('#'))
|
|
192
205
|
continue;
|
|
193
|
-
if (fs.existsSync(path.join(dirPath, e.name, '#weights')) || fs.existsSync(path.join(dirPath, e.name, '$ai', 'class.js')))
|
|
206
|
+
if (fs.existsSync(path.join(dirPath, e.name, '$ai', '#weights')) || fs.existsSync(path.join(dirPath, e.name, '#weights')) || fs.existsSync(path.join(dirPath, e.name, '$ai', 'class.js')))
|
|
194
207
|
return true;
|
|
195
208
|
}
|
|
196
209
|
}
|
|
@@ -270,7 +283,7 @@ async function collectFilesRecursive(baseDir, relPrefix = '', { skipPart = true,
|
|
|
270
283
|
const cur = stack.pop();
|
|
271
284
|
const entries = await fsp.readdir(cur.abs, { withFileTypes: true }).catch(() => []);
|
|
272
285
|
for (const e of entries) {
|
|
273
|
-
if (skipPart && e.name.endsWith('.part'))
|
|
286
|
+
if (skipPart && (e.name.endsWith('.part') || e.name.endsWith('.tmp') || e.name === 'download-state.json'))
|
|
274
287
|
continue;
|
|
275
288
|
if (skipLogs && e.isDirectory() && e.name === 'logs')
|
|
276
289
|
continue;
|
|
@@ -312,123 +325,113 @@ function parseAiClassMetaSync(classFilePath) {
|
|
|
312
325
|
* Получить полный инвентарь переносимых элементов в `MODELS/Local`.
|
|
313
326
|
*/
|
|
314
327
|
export async function listTransferableLocalItems(rootDir = process.cwd()) {
|
|
315
|
-
|
|
328
|
+
migrateLocalModelsLayoutSync(rootDir);
|
|
329
|
+
const localRoot = localRootDir(rootDir);
|
|
316
330
|
const models = [];
|
|
317
331
|
const adapters = [];
|
|
318
332
|
const datasets = [];
|
|
319
333
|
let runtime = { present: false, filesCount: 0, sizeBytes: 0, sizeGb: 0, files: [] };
|
|
320
334
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
continue;
|
|
337
|
-
const adDir = path.join(localRoot, '#adapters', ad.name);
|
|
338
|
-
const files = await collectFilesRecursive(adDir, '', { skipPart: true, skipLogs: true });
|
|
339
|
-
if (!files.length)
|
|
340
|
-
continue;
|
|
341
|
-
const cfgPath = path.join(adDir, 'adapter_config.json');
|
|
342
|
-
let cfg = {};
|
|
343
|
-
if (fs.existsSync(cfgPath)) {
|
|
344
|
-
try { cfg = JSON.parse(await fsp.readFile(cfgPath, 'utf-8')); } catch { /* ignore */ }
|
|
345
|
-
}
|
|
346
|
-
const sizeBytes = files.reduce((s, f) => s + f.size, 0);
|
|
347
|
-
adapters.push({
|
|
348
|
-
id: ad.name,
|
|
349
|
-
label: cfg.name || ad.name,
|
|
350
|
-
baseModel: cfg.base_model_name_or_path || '',
|
|
351
|
-
mode: cfg.mode || '',
|
|
352
|
-
filesCount: files.length,
|
|
353
|
-
sizeBytes,
|
|
354
|
-
sizeGb: formatGb(sizeBytes),
|
|
355
|
-
files,
|
|
356
|
-
});
|
|
335
|
+
// Адаптеры из MODELS/Local/$provider/#adapters
|
|
336
|
+
const adaptersDir = localAdaptersDir(rootDir);
|
|
337
|
+
if (fs.existsSync(adaptersDir)) {
|
|
338
|
+
const adEntries = await fsp.readdir(adaptersDir, { withFileTypes: true }).catch(() => []);
|
|
339
|
+
for (const ad of adEntries) {
|
|
340
|
+
if (!ad.isDirectory())
|
|
341
|
+
continue;
|
|
342
|
+
const adDir = path.join(adaptersDir, ad.name);
|
|
343
|
+
const files = await collectFilesRecursive(adDir, '', { skipPart: true, skipLogs: true });
|
|
344
|
+
if (!files.length)
|
|
345
|
+
continue;
|
|
346
|
+
const cfgPath = path.join(adDir, 'adapter_config.json');
|
|
347
|
+
let cfg = {};
|
|
348
|
+
if (fs.existsSync(cfgPath)) {
|
|
349
|
+
try { cfg = JSON.parse(await fsp.readFile(cfgPath, 'utf-8')); } catch { /* ignore */ }
|
|
357
350
|
}
|
|
358
|
-
|
|
351
|
+
const sizeBytes = files.reduce((s, f) => s + f.size, 0);
|
|
352
|
+
adapters.push({
|
|
353
|
+
id: ad.name,
|
|
354
|
+
label: cfg.name || ad.name,
|
|
355
|
+
baseModel: cfg.base_model_name_or_path || '',
|
|
356
|
+
mode: cfg.mode || '',
|
|
357
|
+
filesCount: files.length,
|
|
358
|
+
sizeBytes,
|
|
359
|
+
sizeGb: formatGb(sizeBytes),
|
|
360
|
+
files,
|
|
361
|
+
});
|
|
359
362
|
}
|
|
363
|
+
}
|
|
360
364
|
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
else if (f.name.endsWith('.meta.json')) {
|
|
377
|
-
const id = f.name.slice(0, -10);
|
|
378
|
-
const rec = byName.get(id) || { id, files: [] };
|
|
379
|
-
const fullPath = path.join(dsDir, f.name);
|
|
380
|
-
const st = await fsp.stat(fullPath);
|
|
381
|
-
rec.files.push({ relPath: f.name, insideRel: f.name, fullPath, size: st.size || 0, mtimeMs: st.mtimeMs || Date.now() });
|
|
382
|
-
byName.set(id, rec);
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
for (const rec of byName.values()) {
|
|
386
|
-
const sizeBytes = rec.files.reduce((s, f) => s + f.size, 0);
|
|
387
|
-
datasets.push({
|
|
388
|
-
id: rec.id,
|
|
389
|
-
label: rec.id,
|
|
390
|
-
filesCount: rec.files.length,
|
|
391
|
-
sizeBytes,
|
|
392
|
-
sizeGb: formatGb(sizeBytes),
|
|
393
|
-
files: rec.files,
|
|
394
|
-
});
|
|
365
|
+
// Датасеты из MODELS/Local/$provider/#datasets
|
|
366
|
+
const dsDir = localDatasetsDir(rootDir);
|
|
367
|
+
if (fs.existsSync(dsDir)) {
|
|
368
|
+
const dsEntries = await fsp.readdir(dsDir, { withFileTypes: true }).catch(() => []);
|
|
369
|
+
const byName = new Map();
|
|
370
|
+
for (const f of dsEntries) {
|
|
371
|
+
if (!f.isFile())
|
|
372
|
+
continue;
|
|
373
|
+
if (f.name.endsWith('.jsonl') || f.name.endsWith('.meta.json')) {
|
|
374
|
+
const id = f.name.endsWith('.jsonl') ? f.name.slice(0, -6) : f.name.slice(0, -10);
|
|
375
|
+
const rec = byName.get(id) || { id, files: [] };
|
|
376
|
+
const fullPath = path.join(dsDir, f.name);
|
|
377
|
+
const st = await fsp.stat(fullPath);
|
|
378
|
+
rec.files.push({ relPath: f.name, insideRel: f.name, fullPath, size: st.size || 0, mtimeMs: st.mtimeMs || Date.now() });
|
|
379
|
+
byName.set(id, rec);
|
|
395
380
|
}
|
|
396
|
-
continue;
|
|
397
381
|
}
|
|
382
|
+
for (const rec of byName.values()) {
|
|
383
|
+
const sizeBytes = rec.files.reduce((s, f) => s + f.size, 0);
|
|
384
|
+
datasets.push({
|
|
385
|
+
id: rec.id,
|
|
386
|
+
label: rec.id,
|
|
387
|
+
filesCount: rec.files.length,
|
|
388
|
+
sizeBytes,
|
|
389
|
+
sizeGb: formatGb(sizeBytes),
|
|
390
|
+
files: rec.files,
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
}
|
|
398
394
|
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
}
|
|
412
|
-
continue;
|
|
395
|
+
// Рантайм из MODELS/Local/$provider/#runtime
|
|
396
|
+
const rtDir = localRuntimeDir(rootDir);
|
|
397
|
+
if (fs.existsSync(rtDir)) {
|
|
398
|
+
const files = await collectFilesRecursive(rtDir, '', { skipPart: true, skipLogs: true });
|
|
399
|
+
if (files.length) {
|
|
400
|
+
const sizeBytes = files.reduce((s, f) => s + f.size, 0);
|
|
401
|
+
runtime = {
|
|
402
|
+
present: true,
|
|
403
|
+
filesCount: files.length,
|
|
404
|
+
sizeBytes,
|
|
405
|
+
sizeGb: formatGb(sizeBytes),
|
|
406
|
+
files,
|
|
407
|
+
};
|
|
413
408
|
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
if (!fs.existsSync(localRoot))
|
|
412
|
+
return { localRoot, models, adapters, datasets, runtime };
|
|
414
413
|
|
|
415
|
-
|
|
414
|
+
const entries = await fsp.readdir(localRoot, { withFileTypes: true });
|
|
415
|
+
for (const e of entries) {
|
|
416
|
+
if (!e.isDirectory() || e.name.startsWith('$') || e.name.startsWith('#'))
|
|
416
417
|
continue;
|
|
417
418
|
|
|
418
|
-
const
|
|
419
|
-
const aiClassFile =
|
|
420
|
-
const weightsDir =
|
|
419
|
+
const mDir = getModelDir(rootDir, e.name, 'Local');
|
|
420
|
+
const aiClassFile = getModelClassFile(rootDir, e.name, 'Local');
|
|
421
|
+
const weightsDir = getModelWeightsDir(rootDir, e.name, 'Local');
|
|
421
422
|
const meta = parseAiClassMetaSync(aiClassFile);
|
|
422
423
|
const isAdapterNode = Boolean(meta.adapterPath);
|
|
424
|
+
let hasPendingDownload = false;
|
|
423
425
|
let hasRealWeightBinary = false;
|
|
424
426
|
if (fs.existsSync(weightsDir)) {
|
|
425
427
|
const wf = await fsp.readdir(weightsDir).catch(() => []);
|
|
428
|
+
hasPendingDownload = wf.some(f => f.endsWith('.part') || f === 'download-state.json');
|
|
426
429
|
hasRealWeightBinary = wf.some(f => !f.endsWith('.part') && WEIGHT_EXT_RE.test(f));
|
|
427
430
|
}
|
|
428
|
-
if (!hasRealWeightBinary && !isAdapterNode)
|
|
431
|
+
if ((hasPendingDownload || !hasRealWeightBinary) && !isAdapterNode)
|
|
429
432
|
continue;
|
|
430
433
|
|
|
431
|
-
const files = await collectFilesRecursive(
|
|
434
|
+
const files = await collectFilesRecursive(mDir, '', { skipPart: true, skipLogs: true });
|
|
432
435
|
if (!files.length)
|
|
433
436
|
continue;
|
|
434
437
|
const sizeBytes = files.reduce((s, f) => s + f.size, 0);
|
|
@@ -467,18 +470,12 @@ export async function listTransferableLocalItems(rootDir = process.cwd()) {
|
|
|
467
470
|
};
|
|
468
471
|
}
|
|
469
472
|
|
|
470
|
-
function isModelInstalledSync(
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
if (
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
if (wf.some(f => !f.endsWith('.part') && WEIGHT_EXT_RE.test(f)))
|
|
477
|
-
return true;
|
|
478
|
-
}
|
|
479
|
-
catch { /* ignore */ }
|
|
480
|
-
}
|
|
481
|
-
const meta = parseAiClassMetaSync(path.join(modelDir, '$ai', 'class.js'));
|
|
473
|
+
function isModelInstalledSync(rootDir, modelId) {
|
|
474
|
+
if (hasReadyWeightFilesSync(getModelWeightsDir(rootDir, modelId, 'Local')))
|
|
475
|
+
return true;
|
|
476
|
+
if (hasReadyWeightFilesSync(path.join(getModelDir(rootDir, modelId, 'Local'), '#weights')))
|
|
477
|
+
return true;
|
|
478
|
+
const meta = parseAiClassMetaSync(getModelClassFile(rootDir, modelId, 'Local'));
|
|
482
479
|
return Boolean(meta.adapterPath);
|
|
483
480
|
}
|
|
484
481
|
|
|
@@ -486,16 +483,20 @@ function isModelInstalledSync(localRoot, modelId) {
|
|
|
486
483
|
* Проанализировать папку-источник на диске/флешке (манифест или автообнаружение папок).
|
|
487
484
|
*/
|
|
488
485
|
export async function inspectTransferSource(sourceDir, rootDir = process.cwd()) {
|
|
486
|
+
migrateLocalModelsLayoutSync(rootDir);
|
|
489
487
|
const resolved = path.resolve(String(sourceDir || ''));
|
|
490
488
|
if (!fs.existsSync(resolved))
|
|
491
489
|
throw new Error(`Папка источника не найдена: ${resolved}`);
|
|
492
|
-
const localRoot =
|
|
490
|
+
const localRoot = localRootDir(rootDir);
|
|
491
|
+
const adaptersTarget = localAdaptersDir(rootDir);
|
|
492
|
+
const datasetsTarget = localDatasetsDir(rootDir);
|
|
493
|
+
const runtimeTarget = localRuntimeDir(rootDir);
|
|
493
494
|
const manifestPath = path.join(resolved, TRANSFER_MANIFEST_FILE);
|
|
494
495
|
|
|
495
496
|
const models = [];
|
|
496
497
|
const adapters = [];
|
|
497
498
|
const datasets = [];
|
|
498
|
-
let runtime = { present: false, filesCount: 0, sizeBytes: 0, sizeGb: 0, files: [], alreadyInstalled: fs.existsSync(
|
|
499
|
+
let runtime = { present: false, filesCount: 0, sizeBytes: 0, sizeGb: 0, files: [], alreadyInstalled: fs.existsSync(runtimeTarget) };
|
|
499
500
|
let hasManifest = false;
|
|
500
501
|
let createdAt = null;
|
|
501
502
|
let sourceHost = '';
|
|
@@ -532,7 +533,7 @@ export async function inspectTransferSource(sourceDir, rootDir = process.cwd())
|
|
|
532
533
|
filesCount: files.length,
|
|
533
534
|
sizeBytes,
|
|
534
535
|
sizeGb: formatGb(sizeBytes),
|
|
535
|
-
alreadyInstalled: isModelInstalledSync(
|
|
536
|
+
alreadyInstalled: isModelInstalledSync(rootDir, id),
|
|
536
537
|
files,
|
|
537
538
|
});
|
|
538
539
|
}
|
|
@@ -552,7 +553,7 @@ export async function inspectTransferSource(sourceDir, rootDir = process.cwd())
|
|
|
552
553
|
filesCount: files.length,
|
|
553
554
|
sizeBytes,
|
|
554
555
|
sizeGb: formatGb(sizeBytes),
|
|
555
|
-
alreadyInstalled: fs.existsSync(path.join(
|
|
556
|
+
alreadyInstalled: fs.existsSync(path.join(adaptersTarget, id, 'adapter_config.json')),
|
|
556
557
|
files,
|
|
557
558
|
});
|
|
558
559
|
}
|
|
@@ -572,7 +573,7 @@ export async function inspectTransferSource(sourceDir, rootDir = process.cwd())
|
|
|
572
573
|
filesCount: files.length,
|
|
573
574
|
sizeBytes,
|
|
574
575
|
sizeGb: formatGb(sizeBytes),
|
|
575
|
-
alreadyInstalled: fs.existsSync(path.join(
|
|
576
|
+
alreadyInstalled: fs.existsSync(path.join(datasetsTarget, `${id}.jsonl`)),
|
|
576
577
|
files,
|
|
577
578
|
});
|
|
578
579
|
}
|
|
@@ -588,7 +589,7 @@ export async function inspectTransferSource(sourceDir, rootDir = process.cwd())
|
|
|
588
589
|
filesCount: files.length,
|
|
589
590
|
sizeBytes,
|
|
590
591
|
sizeGb: formatGb(sizeBytes),
|
|
591
|
-
alreadyInstalled: fs.existsSync(path.join(
|
|
592
|
+
alreadyInstalled: fs.existsSync(path.join(runtimeTarget, 'bubo')),
|
|
592
593
|
files,
|
|
593
594
|
};
|
|
594
595
|
}
|
|
@@ -616,7 +617,7 @@ export async function inspectTransferSource(sourceDir, rootDir = process.cwd())
|
|
|
616
617
|
filesCount: files.length,
|
|
617
618
|
sizeBytes,
|
|
618
619
|
sizeGb: formatGb(sizeBytes),
|
|
619
|
-
alreadyInstalled: fs.existsSync(path.join(
|
|
620
|
+
alreadyInstalled: fs.existsSync(path.join(adaptersTarget, ad.name)),
|
|
620
621
|
files,
|
|
621
622
|
});
|
|
622
623
|
}
|
|
@@ -646,7 +647,7 @@ export async function inspectTransferSource(sourceDir, rootDir = process.cwd())
|
|
|
646
647
|
filesCount: rec.files.length,
|
|
647
648
|
sizeBytes,
|
|
648
649
|
sizeGb: formatGb(sizeBytes),
|
|
649
|
-
alreadyInstalled: fs.existsSync(path.join(
|
|
650
|
+
alreadyInstalled: fs.existsSync(path.join(datasetsTarget, `${rec.id}.jsonl`)),
|
|
650
651
|
files: rec.files,
|
|
651
652
|
});
|
|
652
653
|
}
|
|
@@ -661,7 +662,7 @@ export async function inspectTransferSource(sourceDir, rootDir = process.cwd())
|
|
|
661
662
|
filesCount: files.length,
|
|
662
663
|
sizeBytes,
|
|
663
664
|
sizeGb: formatGb(sizeBytes),
|
|
664
|
-
alreadyInstalled: fs.existsSync(path.join(
|
|
665
|
+
alreadyInstalled: fs.existsSync(path.join(runtimeTarget, 'bubo')),
|
|
665
666
|
files,
|
|
666
667
|
};
|
|
667
668
|
}
|
|
@@ -670,12 +671,12 @@ export async function inspectTransferSource(sourceDir, rootDir = process.cwd())
|
|
|
670
671
|
if (e.name.startsWith('#'))
|
|
671
672
|
continue;
|
|
672
673
|
|
|
673
|
-
const
|
|
674
|
-
const meta = parseAiClassMetaSync(path.join(
|
|
675
|
-
const hasWeights = fs.existsSync(path.join(
|
|
674
|
+
const mDir = path.join(resolved, e.name);
|
|
675
|
+
const meta = parseAiClassMetaSync(path.join(mDir, '$ai', 'class.js'));
|
|
676
|
+
const hasWeights = fs.existsSync(path.join(mDir, '$ai', '#weights')) || fs.existsSync(path.join(mDir, '#weights'));
|
|
676
677
|
if (!hasWeights && !meta.adapterPath)
|
|
677
678
|
continue;
|
|
678
|
-
const files = await collectFilesRecursive(
|
|
679
|
+
const files = await collectFilesRecursive(mDir);
|
|
679
680
|
if (!files.length)
|
|
680
681
|
continue;
|
|
681
682
|
const sizeBytes = files.reduce((s, f) => s + f.size, 0);
|
|
@@ -688,7 +689,7 @@ export async function inspectTransferSource(sourceDir, rootDir = process.cwd())
|
|
|
688
689
|
filesCount: files.length,
|
|
689
690
|
sizeBytes,
|
|
690
691
|
sizeGb: formatGb(sizeBytes),
|
|
691
|
-
alreadyInstalled: isModelInstalledSync(
|
|
692
|
+
alreadyInstalled: isModelInstalledSync(rootDir, e.name),
|
|
692
693
|
files,
|
|
693
694
|
});
|
|
694
695
|
}
|
|
@@ -788,9 +789,14 @@ async function copyFileWithVerify(src, dest, { expectedSize = null, expectedSha2
|
|
|
788
789
|
}
|
|
789
790
|
|
|
790
791
|
async function ensureImportedModelNode(rootDir, modelId) {
|
|
791
|
-
const
|
|
792
|
-
const aiClassFile =
|
|
793
|
-
const weightsDir =
|
|
792
|
+
const mDir = getModelDir(rootDir, modelId, 'Local');
|
|
793
|
+
const aiClassFile = getModelClassFile(rootDir, modelId, 'Local');
|
|
794
|
+
const weightsDir = getModelWeightsDir(rootDir, modelId, 'Local');
|
|
795
|
+
const legacyWeightsDir = path.join(mDir, '#weights');
|
|
796
|
+
// Если импортирован старый бэкап, где #weights лежали рядом с $ai — переносим внутрь метапапки $ai/#weights
|
|
797
|
+
if (fs.existsSync(legacyWeightsDir))
|
|
798
|
+
mergeMoveDirSync(legacyWeightsDir, weightsDir);
|
|
799
|
+
|
|
794
800
|
const hasWeightsDir = fs.existsSync(weightsDir);
|
|
795
801
|
const meta = parseAiClassMetaSync(aiClassFile);
|
|
796
802
|
|
|
@@ -805,7 +811,7 @@ async function ensureImportedModelNode(rootDir, modelId) {
|
|
|
805
811
|
}
|
|
806
812
|
if (meta.adapterPath) {
|
|
807
813
|
const adapterName = path.basename(String(meta.adapterPath));
|
|
808
|
-
const relAdapter = path.relative(rootDir, path.join(rootDir,
|
|
814
|
+
const relAdapter = path.relative(rootDir, path.join(localAdaptersDir(rootDir), adapterName)).replace(/\\/g, '/');
|
|
809
815
|
if (meta.adapterPath !== relAdapter) {
|
|
810
816
|
meta.adapterPath = relAdapter;
|
|
811
817
|
changed = true;
|
|
@@ -1110,7 +1116,7 @@ export async function startImportFromDisk({
|
|
|
1110
1116
|
|
|
1111
1117
|
const jobId = 'imp_' + crypto.randomUUID().slice(0, 8);
|
|
1112
1118
|
const controller = new AbortController();
|
|
1113
|
-
const stagingRoot = path.join(
|
|
1119
|
+
const stagingRoot = path.join(localTempDir(rootDir), `_import_${jobId}`);
|
|
1114
1120
|
const job = {
|
|
1115
1121
|
id: jobId,
|
|
1116
1122
|
type: 'import_disk',
|
|
@@ -1175,7 +1181,7 @@ export async function startImportFromDisk({
|
|
|
1175
1181
|
},
|
|
1176
1182
|
});
|
|
1177
1183
|
}
|
|
1178
|
-
await moveDirReplace(adStaging, path.join(
|
|
1184
|
+
await moveDirReplace(adStaging, path.join(localAdaptersDir(rootDir), ad.id));
|
|
1179
1185
|
job.imported.adapters.push(ad.id);
|
|
1180
1186
|
}
|
|
1181
1187
|
|
|
@@ -1195,7 +1201,7 @@ export async function startImportFromDisk({
|
|
|
1195
1201
|
},
|
|
1196
1202
|
});
|
|
1197
1203
|
}
|
|
1198
|
-
const targetDsDir =
|
|
1204
|
+
const targetDsDir = localDatasetsDir(rootDir);
|
|
1199
1205
|
await fsp.mkdir(targetDsDir, { recursive: true });
|
|
1200
1206
|
for (const f of ds.files) {
|
|
1201
1207
|
const srcF = path.join(dsStaging, f.insideRel);
|
|
@@ -1225,7 +1231,7 @@ export async function startImportFromDisk({
|
|
|
1225
1231
|
},
|
|
1226
1232
|
});
|
|
1227
1233
|
}
|
|
1228
|
-
await moveDirReplace(rtStaging,
|
|
1234
|
+
await moveDirReplace(rtStaging, localRuntimeDir(rootDir));
|
|
1229
1235
|
job.imported.runtime = true;
|
|
1230
1236
|
}
|
|
1231
1237
|
|
|
@@ -1401,7 +1407,7 @@ export async function importTarFromStream({
|
|
|
1401
1407
|
|
|
1402
1408
|
const jobId = 'tar_imp_' + crypto.randomUUID().slice(0, 8);
|
|
1403
1409
|
const controller = new AbortController();
|
|
1404
|
-
const stagingRoot = path.join(
|
|
1410
|
+
const stagingRoot = path.join(localTempDir(rootDir), `_tar_import_${jobId}`);
|
|
1405
1411
|
const job = {
|
|
1406
1412
|
id: jobId,
|
|
1407
1413
|
type: 'import_tar',
|
|
@@ -1478,7 +1484,7 @@ export async function importTarFromStream({
|
|
|
1478
1484
|
for (const ad of ads) {
|
|
1479
1485
|
if (!ad.isDirectory())
|
|
1480
1486
|
continue;
|
|
1481
|
-
const destAd = path.join(
|
|
1487
|
+
const destAd = path.join(localAdaptersDir(rootDir), ad.name);
|
|
1482
1488
|
if (!overwrite && fs.existsSync(destAd)) {
|
|
1483
1489
|
job.skipped.push(ad.name);
|
|
1484
1490
|
continue;
|
|
@@ -1491,7 +1497,7 @@ export async function importTarFromStream({
|
|
|
1491
1497
|
if (e.name === '#datasets') {
|
|
1492
1498
|
const dsDir = path.join(stagingRoot, '#datasets');
|
|
1493
1499
|
const files = await fsp.readdir(dsDir, { withFileTypes: true }).catch(() => []);
|
|
1494
|
-
const targetDsDir =
|
|
1500
|
+
const targetDsDir = localDatasetsDir(rootDir);
|
|
1495
1501
|
await fsp.mkdir(targetDsDir, { recursive: true });
|
|
1496
1502
|
for (const f of files) {
|
|
1497
1503
|
if (!f.isFile())
|
|
@@ -1506,7 +1512,7 @@ export async function importTarFromStream({
|
|
|
1506
1512
|
continue;
|
|
1507
1513
|
}
|
|
1508
1514
|
if (e.name === '#runtime') {
|
|
1509
|
-
const destRt =
|
|
1515
|
+
const destRt = localRuntimeDir(rootDir);
|
|
1510
1516
|
if (overwrite || !fs.existsSync(path.join(destRt, 'bubo'))) {
|
|
1511
1517
|
await moveDirReplace(path.join(stagingRoot, '#runtime'), destRt);
|
|
1512
1518
|
job.imported.runtime = true;
|
|
@@ -1517,11 +1523,11 @@ export async function importTarFromStream({
|
|
|
1517
1523
|
continue;
|
|
1518
1524
|
|
|
1519
1525
|
const srcModel = path.join(stagingRoot, e.name);
|
|
1520
|
-
const hasWeights = fs.existsSync(path.join(srcModel, '#weights'));
|
|
1526
|
+
const hasWeights = fs.existsSync(path.join(srcModel, '$ai', '#weights')) || fs.existsSync(path.join(srcModel, '#weights'));
|
|
1521
1527
|
const meta = parseAiClassMetaSync(path.join(srcModel, '$ai', 'class.js'));
|
|
1522
1528
|
if (!hasWeights && !meta.adapterPath)
|
|
1523
1529
|
continue;
|
|
1524
|
-
if (!overwrite && isModelInstalledSync(
|
|
1530
|
+
if (!overwrite && isModelInstalledSync(rootDir, e.name)) {
|
|
1525
1531
|
job.skipped.push(e.name);
|
|
1526
1532
|
continue;
|
|
1527
1533
|
}
|