odant-work 1.0.31 → 1.0.33
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 +12 -12
- package/MODELS/$ai/$folder/$class/$provider/handlers/pages/form/trainer/$handler/trainer.js +1 -1
- package/package.json +1 -1
- package/sources/data/progress.md +7 -0
- package/sources/modules/trainer/halogen.js +259 -185
- package/sources/modules/trainer/huggingface.js +105 -19
- package/sources/modules/trainer/index.js +39 -8
- package/sources/modules/trainer/paths.js +52 -4
- package/sources/modules/trainer/providers.js +4 -8
- package/sources/modules/trainer/runner.js +12 -9
|
@@ -1141,8 +1141,12 @@ async function writeDownloadStateSafe(stagingDir, job, extra = {}) {
|
|
|
1141
1141
|
threads: Number(job.threads) || 1,
|
|
1142
1142
|
registerInWork: extra.registerInWork !== false,
|
|
1143
1143
|
nodeMeta: extra.nodeMeta || null,
|
|
1144
|
+
customFilesDir: extra.customFilesDir || '',
|
|
1145
|
+
buboFinalize: Boolean(extra.buboFinalize),
|
|
1144
1146
|
files: (job.files || []).map(f => ({
|
|
1145
1147
|
name: f.name,
|
|
1148
|
+
...(f.url ? { url: f.url } : {}),
|
|
1149
|
+
...(f.destRelPath ? { destRelPath: f.destRelPath } : {}),
|
|
1146
1150
|
size: Number(f.size) || 0,
|
|
1147
1151
|
downloaded: Number(f.downloaded) || 0,
|
|
1148
1152
|
done: Boolean(f.done),
|
|
@@ -1210,6 +1214,9 @@ export function computeDownloadEta({ remainingBytes = 0, avgBytesPerSec = 0, sho
|
|
|
1210
1214
|
export async function startHuggingFaceDownload({
|
|
1211
1215
|
repoId,
|
|
1212
1216
|
files = null,
|
|
1217
|
+
customFiles = null,
|
|
1218
|
+
customFilesDir = '',
|
|
1219
|
+
onComplete = null,
|
|
1213
1220
|
quant = 'Q8_0',
|
|
1214
1221
|
revision = 'main',
|
|
1215
1222
|
token = '',
|
|
@@ -1255,15 +1262,28 @@ export async function startHuggingFaceDownload({
|
|
|
1255
1262
|
const effToken = token || netCfg.token || '';
|
|
1256
1263
|
const netFetch = createNetworkFetch({ proxyUrl: effProxy, fetchImpl });
|
|
1257
1264
|
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1265
|
+
let repoMeta = { modality: nodeMeta?.modality || 'llm', capabilities: nodeMeta?.capabilities || ['chat'], files: [] };
|
|
1266
|
+
let selected = [];
|
|
1267
|
+
if (Array.isArray(customFiles) && customFiles.length) {
|
|
1268
|
+
selected = customFiles.map(cf => ({
|
|
1269
|
+
name: String(cf.name || ''),
|
|
1270
|
+
url: String(cf.url || ''),
|
|
1271
|
+
destRelPath: String(cf.destRelPath || path.basename(cf.name || '')),
|
|
1272
|
+
size: Number(cf.size) || 0,
|
|
1273
|
+
kind: /\.gguf$/i.test(cf.name || '') ? 'gguf' : 'safetensors',
|
|
1274
|
+
}));
|
|
1275
|
+
}
|
|
1276
|
+
else {
|
|
1277
|
+
repoMeta = await inspectHuggingFaceRepo(cleanId, {
|
|
1278
|
+
revision,
|
|
1279
|
+
token: effToken,
|
|
1280
|
+
rootDir,
|
|
1281
|
+
endpointUrl: effEndpoint,
|
|
1282
|
+
proxyUrl: effProxy,
|
|
1283
|
+
fetchImpl,
|
|
1284
|
+
});
|
|
1285
|
+
selected = selectFilesToDownload(repoMeta, { files, quant });
|
|
1286
|
+
}
|
|
1267
1287
|
if (!selected.length)
|
|
1268
1288
|
throw new Error(`В репозитории ${cleanId} не найдено подходящих файлов весов (.gguf / .safetensors)`);
|
|
1269
1289
|
|
|
@@ -1282,6 +1302,8 @@ export async function startHuggingFaceDownload({
|
|
|
1282
1302
|
const modelDir = getModelDir(rootDir, folderName, safeProvider);
|
|
1283
1303
|
const weightsDir = getModelWeightsDir(rootDir, folderName, safeProvider);
|
|
1284
1304
|
const stagingDir = weightsDir;
|
|
1305
|
+
const filesRootDir = customFilesDir ? path.resolve(rootDir, customFilesDir) : stagingDir;
|
|
1306
|
+
const customFilesDirRel = customFilesDir ? path.relative(rootDir, filesRootDir).replace(/\\/g, '/') : '';
|
|
1285
1307
|
const primary = selected.find(f => f.name.endsWith('.gguf'))?.name
|
|
1286
1308
|
|| selected.find(f => f.name.endsWith('.safetensors') || f.name.endsWith('.hgn') || f.name.endsWith('.hnpw'))?.name
|
|
1287
1309
|
|| selected[0]?.name || '';
|
|
@@ -1290,6 +1312,8 @@ export async function startHuggingFaceDownload({
|
|
|
1290
1312
|
|| `${cleanId.split('/')[1] || cleanId}${quant && primary.endsWith('.gguf') ? ' (' + quant + ')' : ''}`;
|
|
1291
1313
|
|
|
1292
1314
|
await fsp.mkdir(weightsDir, { recursive: true });
|
|
1315
|
+
if (filesRootDir !== stagingDir)
|
|
1316
|
+
await fsp.mkdir(filesRootDir, { recursive: true });
|
|
1293
1317
|
|
|
1294
1318
|
// Если осталась недокачанная старая папка в #downloads/<folderName>, аккуратно перенесём её в $ai/#weights
|
|
1295
1319
|
const legacyStaging = path.join(rootDir, 'MODELS', safeProvider, '#downloads', folderName);
|
|
@@ -1335,7 +1359,8 @@ export async function startHuggingFaceDownload({
|
|
|
1335
1359
|
const jobFiles = [];
|
|
1336
1360
|
for (const f of selected) {
|
|
1337
1361
|
const size = Number(f.size) || 0;
|
|
1338
|
-
const
|
|
1362
|
+
const destRelPath = f.destRelPath || path.basename(f.name);
|
|
1363
|
+
const stagedFile = path.join(filesRootDir, destRelPath);
|
|
1339
1364
|
const partFile = stagedFile + '.part';
|
|
1340
1365
|
let downloaded = 0;
|
|
1341
1366
|
let done = false;
|
|
@@ -1367,7 +1392,15 @@ export async function startHuggingFaceDownload({
|
|
|
1367
1392
|
}
|
|
1368
1393
|
catch { /* .part ещё нет */ }
|
|
1369
1394
|
}
|
|
1370
|
-
jobFiles.push({
|
|
1395
|
+
jobFiles.push({
|
|
1396
|
+
name: f.name,
|
|
1397
|
+
...(f.url ? { url: f.url } : {}),
|
|
1398
|
+
...(f.destRelPath ? { destRelPath: f.destRelPath } : {}),
|
|
1399
|
+
size: size || (done ? downloaded : 0),
|
|
1400
|
+
downloaded,
|
|
1401
|
+
done,
|
|
1402
|
+
ranges,
|
|
1403
|
+
});
|
|
1371
1404
|
}
|
|
1372
1405
|
|
|
1373
1406
|
const jobId = 'hf_' + crypto.randomUUID().slice(0, 8);
|
|
@@ -1397,6 +1430,8 @@ export async function startHuggingFaceDownload({
|
|
|
1397
1430
|
rootDir,
|
|
1398
1431
|
stagingDir,
|
|
1399
1432
|
weightsDir,
|
|
1433
|
+
filesRootDir,
|
|
1434
|
+
customFilesDir: customFilesDirRel,
|
|
1400
1435
|
endpointUrl: effEndpoint,
|
|
1401
1436
|
sourceLabel: describeSourceLabel(effEndpoint),
|
|
1402
1437
|
threads: effThreads,
|
|
@@ -1428,12 +1463,15 @@ export async function startHuggingFaceDownload({
|
|
|
1428
1463
|
registerInWork,
|
|
1429
1464
|
quant,
|
|
1430
1465
|
files,
|
|
1466
|
+
customFiles: Array.isArray(customFiles) && customFiles.length ? customFiles : null,
|
|
1467
|
+
customFilesDir: customFilesDirRel,
|
|
1468
|
+
onComplete,
|
|
1431
1469
|
fetchImpl,
|
|
1432
1470
|
runPromise: null,
|
|
1433
1471
|
setKeepFiles: (v) => { keepFilesOnAbort = Boolean(v); },
|
|
1434
1472
|
};
|
|
1435
1473
|
_downloads.set(jobId, entryMeta);
|
|
1436
|
-
await writeDownloadStateSafe(stagingDir, job, { nodeMeta, registerInWork });
|
|
1474
|
+
await writeDownloadStateSafe(stagingDir, job, { nodeMeta, registerInWork, customFilesDir: customFilesDirRel, buboFinalize: Boolean(onComplete) });
|
|
1437
1475
|
|
|
1438
1476
|
const runPromise = (async () => {
|
|
1439
1477
|
const t0 = Date.now();
|
|
@@ -1449,7 +1487,7 @@ export async function startHuggingFaceDownload({
|
|
|
1449
1487
|
stateWriteChain = stateWriteChain.then(() => {
|
|
1450
1488
|
if (downloadFinished)
|
|
1451
1489
|
return;
|
|
1452
|
-
return writeDownloadStateSafe(weightsDir, job, { nodeMeta, registerInWork });
|
|
1490
|
+
return writeDownloadStateSafe(weightsDir, job, { nodeMeta, registerInWork, customFilesDir: customFilesDirRel, buboFinalize: Boolean(onComplete) });
|
|
1453
1491
|
}).catch(() => {});
|
|
1454
1492
|
};
|
|
1455
1493
|
|
|
@@ -1517,10 +1555,18 @@ export async function startHuggingFaceDownload({
|
|
|
1517
1555
|
if (controller.signal.aborted)
|
|
1518
1556
|
throw new Error('Загрузка приостановлена пользователем');
|
|
1519
1557
|
job.currentFile = fileEntry.name;
|
|
1520
|
-
const
|
|
1558
|
+
const destRelPath = fileEntry.destRelPath || path.basename(fileEntry.name);
|
|
1559
|
+
const stagedFile = path.join(filesRootDir, destRelPath);
|
|
1560
|
+
await fsp.mkdir(path.dirname(stagedFile), { recursive: true });
|
|
1521
1561
|
const partFile = stagedFile + '.part';
|
|
1522
|
-
|
|
1523
|
-
|
|
1562
|
+
let url;
|
|
1563
|
+
if (fileEntry.url) {
|
|
1564
|
+
url = String(fileEntry.url).replace(/^https:\/\/huggingface\.co(?=\/)/i, effEndpoint);
|
|
1565
|
+
}
|
|
1566
|
+
else {
|
|
1567
|
+
const encodedPath = fileEntry.name.split('/').map(encodeURIComponent).join('/');
|
|
1568
|
+
url = `${effEndpoint}/${cleanId}/resolve/${encodeURIComponent(job.revision)}/${encodedPath}`;
|
|
1569
|
+
}
|
|
1524
1570
|
const headers = hfHeaders(effToken, url, effEndpoint);
|
|
1525
1571
|
|
|
1526
1572
|
const res = await downloadFileMultipart({
|
|
@@ -1613,11 +1659,16 @@ export async function startHuggingFaceDownload({
|
|
|
1613
1659
|
maxTokens: nodeMeta?.maxTokens,
|
|
1614
1660
|
maxOutput: nodeMeta?.maxOutput,
|
|
1615
1661
|
baseUrl: nodeMeta?.baseUrl,
|
|
1616
|
-
weightsDir,
|
|
1617
|
-
primaryFile: path.basename(primary),
|
|
1662
|
+
weightsDir: filesRootDir,
|
|
1663
|
+
primaryFile: nodeMeta?.primaryFile || path.basename(primary),
|
|
1618
1664
|
});
|
|
1619
1665
|
}
|
|
1620
1666
|
|
|
1667
|
+
if (typeof onComplete === 'function') {
|
|
1668
|
+
job.currentFile = 'Настройка встроенного движка…';
|
|
1669
|
+
await onComplete({ job, weightsDir, filesRootDir, rootDir });
|
|
1670
|
+
}
|
|
1671
|
+
|
|
1621
1672
|
job.progress = 100;
|
|
1622
1673
|
job.etaSeconds = 0;
|
|
1623
1674
|
job.status = 'completed';
|
|
@@ -1745,6 +1796,11 @@ export function listHuggingFaceDownloads(rootDir = process.cwd()) {
|
|
|
1745
1796
|
}
|
|
1746
1797
|
catch { /* ignore */ }
|
|
1747
1798
|
}
|
|
1799
|
+
if (diskBytes <= 0 && Array.isArray(state.files)) {
|
|
1800
|
+
for (const sf of state.files) {
|
|
1801
|
+
diskBytes += Number(sf?.downloaded) || 0;
|
|
1802
|
+
}
|
|
1803
|
+
}
|
|
1748
1804
|
if (diskBytes <= 0 && !state.repoId)
|
|
1749
1805
|
continue;
|
|
1750
1806
|
const totalBytes = Number(state.totalBytes) || 0;
|
|
@@ -1797,7 +1853,12 @@ export function pauseHuggingFaceDownload(jobId) {
|
|
|
1797
1853
|
entry.job.status = 'paused';
|
|
1798
1854
|
entry.job.etaSeconds = null;
|
|
1799
1855
|
entry.job.finishedAt = Date.now();
|
|
1800
|
-
writeDownloadStateSafe(entry.job.stagingDir, entry.job, {
|
|
1856
|
+
writeDownloadStateSafe(entry.job.stagingDir, entry.job, {
|
|
1857
|
+
nodeMeta: entry.nodeMeta,
|
|
1858
|
+
registerInWork: entry.registerInWork,
|
|
1859
|
+
customFilesDir: entry.customFilesDir || '',
|
|
1860
|
+
buboFinalize: Boolean(entry.onComplete),
|
|
1861
|
+
});
|
|
1801
1862
|
return { ...entry.job };
|
|
1802
1863
|
}
|
|
1803
1864
|
|
|
@@ -1816,6 +1877,18 @@ export async function discardHuggingFaceDownload({ jobId = '', folderName = '',
|
|
|
1816
1877
|
targetFolder = key.slice(5);
|
|
1817
1878
|
if (targetFolder) {
|
|
1818
1879
|
const weightsDir = getModelWeightsDir(rootDir, targetFolder, 'Local');
|
|
1880
|
+
let customDirAbs = entry?.customFilesDir ? path.resolve(rootDir, entry.customFilesDir) : '';
|
|
1881
|
+
if (!customDirAbs && fs.existsSync(path.join(weightsDir, DOWNLOAD_STATE_FILE))) {
|
|
1882
|
+
try {
|
|
1883
|
+
const st = JSON.parse(await fsp.readFile(path.join(weightsDir, DOWNLOAD_STATE_FILE), 'utf-8'));
|
|
1884
|
+
if (st?.customFilesDir)
|
|
1885
|
+
customDirAbs = path.resolve(rootDir, st.customFilesDir);
|
|
1886
|
+
}
|
|
1887
|
+
catch { /* ignore */ }
|
|
1888
|
+
}
|
|
1889
|
+
if (customDirAbs && fs.existsSync(customDirAbs)) {
|
|
1890
|
+
await fsp.rm(customDirAbs, { recursive: true, force: true }).catch(() => {});
|
|
1891
|
+
}
|
|
1819
1892
|
if (fs.existsSync(weightsDir)) {
|
|
1820
1893
|
await fsp.rm(path.join(weightsDir, DOWNLOAD_STATE_FILE), { force: true }).catch(() => {});
|
|
1821
1894
|
const files = await fsp.readdir(weightsDir).catch(() => []);
|
|
@@ -1837,6 +1910,9 @@ export async function resumeHuggingFaceDownload({
|
|
|
1837
1910
|
folderName = '',
|
|
1838
1911
|
repoId = '',
|
|
1839
1912
|
files = null,
|
|
1913
|
+
customFiles = null,
|
|
1914
|
+
customFilesDir = '',
|
|
1915
|
+
onComplete = null,
|
|
1840
1916
|
quant = 'Q8_0',
|
|
1841
1917
|
token = '',
|
|
1842
1918
|
nodeMeta = null,
|
|
@@ -1865,6 +1941,10 @@ export async function resumeHuggingFaceDownload({
|
|
|
1865
1941
|
if (!resolvedRepo)
|
|
1866
1942
|
throw new Error(`Не удалось определить репозиторий Hugging Face для докачки «${cleanFolder || key}»`);
|
|
1867
1943
|
|
|
1944
|
+
const stateHasCustomUrls = Array.isArray(state.files) && state.files.some(f => f?.url || f?.destRelPath);
|
|
1945
|
+
const resolvedCustomFiles = customFiles ?? entry?.customFiles ?? (stateHasCustomUrls ? state.files : null);
|
|
1946
|
+
const rawCustomDir = customFilesDir || entry?.customFilesDir || state.customFilesDir || '';
|
|
1947
|
+
const resolvedCustomDir = /^MODELS[\\/]+Local[\\/]+models([\\/]|$)/i.test(rawCustomDir) ? '' : rawCustomDir;
|
|
1868
1948
|
const stateFileNames = Array.isArray(state.files) && state.files.length
|
|
1869
1949
|
? state.files.map(f => f?.name).filter(Boolean)
|
|
1870
1950
|
: null;
|
|
@@ -1872,6 +1952,9 @@ export async function resumeHuggingFaceDownload({
|
|
|
1872
1952
|
return startHuggingFaceDownload({
|
|
1873
1953
|
repoId: resolvedRepo,
|
|
1874
1954
|
files: files ?? entry?.files ?? stateFileNames ?? null,
|
|
1955
|
+
customFiles: resolvedCustomFiles,
|
|
1956
|
+
customFilesDir: resolvedCustomDir,
|
|
1957
|
+
onComplete: onComplete || entry?.onComplete || null,
|
|
1875
1958
|
quant: quant || entry?.quant || 'Q8_0',
|
|
1876
1959
|
revision: entry?.job?.revision || state.revision || 'main',
|
|
1877
1960
|
token,
|
|
@@ -1904,6 +1987,9 @@ export async function restartActiveHuggingFaceDownloads({ rootDir = '' } = {}) {
|
|
|
1904
1987
|
folderName: entry.job.folderName,
|
|
1905
1988
|
repoId: entry.job.repoId,
|
|
1906
1989
|
files: entry.files ?? null,
|
|
1990
|
+
customFiles: entry.customFiles ?? null,
|
|
1991
|
+
customFilesDir: entry.customFilesDir || '',
|
|
1992
|
+
onComplete: entry.onComplete || null,
|
|
1907
1993
|
quant: entry.quant || 'Q8_0',
|
|
1908
1994
|
nodeMeta: entry.nodeMeta || null,
|
|
1909
1995
|
rootDir: entry.job.rootDir || process.cwd(),
|
|
@@ -65,6 +65,11 @@ import {
|
|
|
65
65
|
computeHalogenMemoryPlan,
|
|
66
66
|
inspectWindowsHalogenEnvironment,
|
|
67
67
|
prepareWindowsBuboRuntime,
|
|
68
|
+
ensureWindowsBuboEngineInstalled,
|
|
69
|
+
finalizeWindowsBuboModel,
|
|
70
|
+
resolveBuboModelFiles,
|
|
71
|
+
QWEN_FLASH_NEXT_GGUF_FILES,
|
|
72
|
+
BUBO_ORIGINAL_MODEL_FILES,
|
|
68
73
|
probeHalogenServer,
|
|
69
74
|
startHalogenBackend,
|
|
70
75
|
stopHalogenBackend,
|
|
@@ -118,6 +123,7 @@ import {
|
|
|
118
123
|
import {
|
|
119
124
|
inspectWeightsDirectorySync,
|
|
120
125
|
modelWeightsDir,
|
|
126
|
+
migrateLocalModelsLayoutSync,
|
|
121
127
|
LINUX_ONLY_HALOGEN_EXT_RE,
|
|
122
128
|
} from './paths.js';
|
|
123
129
|
|
|
@@ -173,6 +179,11 @@ export {
|
|
|
173
179
|
computeHalogenMemoryPlan,
|
|
174
180
|
inspectWindowsHalogenEnvironment,
|
|
175
181
|
prepareWindowsBuboRuntime,
|
|
182
|
+
ensureWindowsBuboEngineInstalled,
|
|
183
|
+
finalizeWindowsBuboModel,
|
|
184
|
+
resolveBuboModelFiles,
|
|
185
|
+
QWEN_FLASH_NEXT_GGUF_FILES,
|
|
186
|
+
BUBO_ORIGINAL_MODEL_FILES,
|
|
176
187
|
probeHalogenServer,
|
|
177
188
|
startHalogenBackend,
|
|
178
189
|
stopHalogenBackend,
|
|
@@ -370,17 +381,30 @@ export const TRAINER_METHODS = Object.freeze({
|
|
|
370
381
|
const parts = itemPath.split('/').filter(Boolean);
|
|
371
382
|
const providerId = parts[1] || 'MODELS';
|
|
372
383
|
const isLocal = providerId === 'Local' || d.protocol === 'local' || d.protocol === 'halogen';
|
|
384
|
+
if (isLocal) {
|
|
385
|
+
migrateLocalModelsLayoutSync(process.cwd());
|
|
386
|
+
}
|
|
373
387
|
const act = evaluateAiNodeActivitySync(this);
|
|
374
388
|
|
|
375
389
|
let weightInfo = null;
|
|
376
390
|
let halogenProbe = null;
|
|
377
391
|
let sizeGb = 0;
|
|
378
392
|
let needsRuntime = false;
|
|
393
|
+
let resolvedWeightsRel = d.weightsDir || '';
|
|
394
|
+
let resolvedPrimaryFile = d.primaryFile || '';
|
|
379
395
|
|
|
380
396
|
if (isLocal) {
|
|
381
|
-
const
|
|
382
|
-
const
|
|
397
|
+
const canonicalWeightsRel = path.join('MODELS', 'Local', this?.id || '', '$ai', '#weights');
|
|
398
|
+
const canonicalWeightsAbs = path.resolve(process.cwd(), canonicalWeightsRel);
|
|
399
|
+
const configuredAbs = d.weightsDir ? path.resolve(process.cwd(), d.weightsDir) : '';
|
|
400
|
+
const wDirAbs = fs.existsSync(canonicalWeightsAbs) ? canonicalWeightsAbs : (configuredAbs || canonicalWeightsAbs);
|
|
401
|
+
resolvedWeightsRel = path.relative(process.cwd(), wDirAbs).replace(/\\/g, '/');
|
|
383
402
|
weightInfo = inspectWeightsDirectorySync(wDirAbs, os.platform());
|
|
403
|
+
if (resolvedPrimaryFile === 'bubo-package.json' || (!resolvedPrimaryFile && weightInfo?.hasGguf)) {
|
|
404
|
+
const resolvedGguf = resolveBuboModelFiles(wDirAbs);
|
|
405
|
+
if (resolvedGguf.mainModel)
|
|
406
|
+
resolvedPrimaryFile = path.basename(resolvedGguf.mainModel);
|
|
407
|
+
}
|
|
384
408
|
if (weightInfo.exists) {
|
|
385
409
|
let bytes = 0;
|
|
386
410
|
for (const f of weightInfo.files) {
|
|
@@ -415,8 +439,8 @@ export const TRAINER_METHODS = Object.freeze({
|
|
|
415
439
|
maxOutput: Number(d.maxOutput || d.$public?.maxOutput) || 8192,
|
|
416
440
|
capabilities: Array.isArray(d.capabilities) ? d.capabilities : (d.$public?.capabilities || ['chat', 'stream']),
|
|
417
441
|
efforts: Array.isArray(d.efforts) ? d.efforts : [],
|
|
418
|
-
weightsDir:
|
|
419
|
-
primaryFile:
|
|
442
|
+
weightsDir: resolvedWeightsRel,
|
|
443
|
+
primaryFile: resolvedPrimaryFile,
|
|
420
444
|
enabled: d.enabled !== false,
|
|
421
445
|
aiActive: act.active,
|
|
422
446
|
aiStatusReason: act.reason,
|
|
@@ -762,27 +786,34 @@ export const TRAINER_METHODS = Object.freeze({
|
|
|
762
786
|
fn: async function (p = {}) {
|
|
763
787
|
const args = mergeTrainerArgs(p);
|
|
764
788
|
const folderName = args.folderName || '';
|
|
765
|
-
const
|
|
789
|
+
const platformCatalog = getHalogenCatalogForPlatform(os.platform());
|
|
790
|
+
const haloSpec = platformCatalog.find(m =>
|
|
766
791
|
(folderName && m.nodeName === folderName)
|
|
767
792
|
|| (args.repoId && m.hfRepo === args.repoId)
|
|
768
793
|
);
|
|
794
|
+
const isWinBubo = os.platform() === 'win32' && (haloSpec?.runtimeType === 'bubo' || folderName === 'Qwen3.8-Flash-Next');
|
|
769
795
|
const job = await resumeHuggingFaceDownload({
|
|
770
796
|
jobId: args.jobId ?? args.id ?? '',
|
|
771
797
|
folderName,
|
|
772
|
-
repoId: args.repoId || haloSpec?.hfRepo || '',
|
|
798
|
+
repoId: isWinBubo ? (haloSpec?.windowsBuboRepo || 'unsloth/Qwen3.8-Flash-Next-GGUF') : (args.repoId || haloSpec?.hfRepo || ''),
|
|
799
|
+
...(isWinBubo ? {
|
|
800
|
+
customFiles: QWEN_FLASH_NEXT_GGUF_FILES,
|
|
801
|
+
onComplete: ({ rootDir: rd }) => ensureWindowsBuboEngineInstalled({ rootDir: rd }),
|
|
802
|
+
} : {}),
|
|
773
803
|
quant: args.quant || 'Q8_0',
|
|
774
804
|
token: args.token || '',
|
|
775
805
|
nodeMeta: haloSpec ? {
|
|
776
806
|
label: haloSpec.label || haloSpec.nodeName,
|
|
777
807
|
model: haloSpec.model,
|
|
778
|
-
protocol: '
|
|
808
|
+
protocol: haloSpec.protocol || 'local',
|
|
779
809
|
icon: haloSpec.icon || 'ai:qwen',
|
|
780
810
|
modality: haloSpec.modality,
|
|
781
811
|
capabilities: haloSpec.capabilities,
|
|
782
812
|
efforts: haloSpec.efforts,
|
|
783
813
|
maxTokens: haloSpec.maxTokens,
|
|
784
814
|
maxOutput: haloSpec.maxOutput,
|
|
785
|
-
baseUrl: haloSpec.baseUrl
|
|
815
|
+
baseUrl: haloSpec.baseUrl ?? '',
|
|
816
|
+
...(isWinBubo ? { primaryFile: 'Qwen3.8-Flash-Next-UD-Q4_K_XL-00001-of-00004.gguf' } : {}),
|
|
786
817
|
} : null,
|
|
787
818
|
});
|
|
788
819
|
try {
|
|
@@ -16,6 +16,28 @@ import path from 'node:path';
|
|
|
16
16
|
|
|
17
17
|
export const WEIGHT_FILE_EXT_RE = /\.(gguf|safetensors|hgn|hnpw|bin|onnx|pt|pth)$/i;
|
|
18
18
|
export const LINUX_ONLY_HALOGEN_EXT_RE = /\.(hgn|hnpw)$/i;
|
|
19
|
+
export const WEIGHT_SIDECAR_SUBDIRS = Object.freeze(['mtp', 'mmproj', 'twin', 'draft_head']);
|
|
20
|
+
|
|
21
|
+
function collectWeightDirRawEntriesSync(dirPath) {
|
|
22
|
+
const out = [];
|
|
23
|
+
const rootEntries = fs.readdirSync(dirPath, { withFileTypes: true });
|
|
24
|
+
for (const ent of rootEntries) {
|
|
25
|
+
if (ent.isFile()) {
|
|
26
|
+
out.push(ent.name);
|
|
27
|
+
}
|
|
28
|
+
else if (ent.isDirectory() && WEIGHT_SIDECAR_SUBDIRS.includes(ent.name)) {
|
|
29
|
+
try {
|
|
30
|
+
const subEntries = fs.readdirSync(path.join(dirPath, ent.name), { withFileTypes: true });
|
|
31
|
+
for (const sub of subEntries) {
|
|
32
|
+
if (sub.isFile())
|
|
33
|
+
out.push(`${ent.name}/${sub.name}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
catch { /* ignore */ }
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return out;
|
|
40
|
+
}
|
|
19
41
|
|
|
20
42
|
export function localRootDir(rootDir = process.cwd()) {
|
|
21
43
|
return path.join(rootDir, 'MODELS', 'Local');
|
|
@@ -68,7 +90,7 @@ export function hasReadyWeightFilesSync(dirPath) {
|
|
|
68
90
|
if (!dirPath || !fs.existsSync(dirPath))
|
|
69
91
|
return false;
|
|
70
92
|
try {
|
|
71
|
-
return
|
|
93
|
+
return collectWeightDirRawEntriesSync(dirPath).some(f => !f.endsWith('.part') && WEIGHT_FILE_EXT_RE.test(f));
|
|
72
94
|
}
|
|
73
95
|
catch {
|
|
74
96
|
return false;
|
|
@@ -98,7 +120,7 @@ export function inspectWeightsDirectorySync(dirPath, platform = os.platform()) {
|
|
|
98
120
|
if (!dirPath || !fs.existsSync(dirPath))
|
|
99
121
|
return empty;
|
|
100
122
|
try {
|
|
101
|
-
const raw =
|
|
123
|
+
const raw = collectWeightDirRawEntriesSync(dirPath);
|
|
102
124
|
const hasParts = raw.some(f => f.endsWith('.part'));
|
|
103
125
|
let pendingState = false;
|
|
104
126
|
if (raw.includes('download-state.json')) {
|
|
@@ -330,7 +352,23 @@ export function migrateLocalModelsLayoutSync(rootDir = process.cwd(), { skipMode
|
|
|
330
352
|
catch { /* ignore */ }
|
|
331
353
|
}
|
|
332
354
|
|
|
333
|
-
//
|
|
355
|
+
// 2.5. Перенос весов из ошибочной папки v1.0.32 `MODELS/Local/models/qwen38-*` в `MODELS/Local/Qwen3.8-Flash-Next/$ai/#weights`
|
|
356
|
+
const legacyModelsDir = path.join(localRoot, 'models');
|
|
357
|
+
if (fs.existsSync(legacyModelsDir) && !(skipModels && skipModels.has('Qwen3.8-Flash-Next'))) {
|
|
358
|
+
try {
|
|
359
|
+
const flashWeightsDir = modelWeightsDir(rootDir, 'Qwen3.8-Flash-Next');
|
|
360
|
+
for (const pkgName of ['qwen38-flash-next-base-ud-q4-k-xl-v1', 'huihui-qwen38-flash-next-ud-q4-k-xl-v1']) {
|
|
361
|
+
const pkgDir = path.join(legacyModelsDir, pkgName);
|
|
362
|
+
if (fs.existsSync(pkgDir))
|
|
363
|
+
mergeMoveDirSync(pkgDir, flashWeightsDir);
|
|
364
|
+
}
|
|
365
|
+
if (fs.existsSync(legacyModelsDir) && !fs.readdirSync(legacyModelsDir).length)
|
|
366
|
+
fs.rmdirSync(legacyModelsDir);
|
|
367
|
+
}
|
|
368
|
+
catch { /* ignore */ }
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
// 3. Папки моделей со старым #weights на уровне модели (рядом с $ai) переносим в $ai/#weights и чиним пути в class.js
|
|
334
372
|
try {
|
|
335
373
|
const entries = fs.readdirSync(localRoot, { withFileTypes: true });
|
|
336
374
|
for (const e of entries) {
|
|
@@ -352,10 +390,20 @@ export function migrateLocalModelsLayoutSync(rootDir = process.cwd(), { skipMode
|
|
|
352
390
|
const meta = JSON.parse(jsonPart);
|
|
353
391
|
let changed = false;
|
|
354
392
|
const expectedWeightsRel = path.relative(rootDir, newWeights).replace(/\\/g, '/');
|
|
355
|
-
if (meta.weightsDir &&
|
|
393
|
+
if (meta.weightsDir && meta.weightsDir !== expectedWeightsRel && fs.existsSync(newWeights)) {
|
|
356
394
|
meta.weightsDir = expectedWeightsRel;
|
|
357
395
|
changed = true;
|
|
358
396
|
}
|
|
397
|
+
if (meta.primaryFile === 'bubo-package.json' && fs.existsSync(newWeights)) {
|
|
398
|
+
const wFiles = collectWeightDirRawEntriesSync(newWeights);
|
|
399
|
+
const primaryGguf = wFiles
|
|
400
|
+
.filter(f => f.toLowerCase().endsWith('.gguf') && !f.endsWith('.part') && !/^(mtp|mmproj|twin|draft|iq4-nofullattn)/i.test(path.basename(f)))
|
|
401
|
+
.sort((a, b) => (/-00001-of-/i.test(a) ? -1 : /-00001-of-/i.test(b) ? 1 : a.localeCompare(b)))[0];
|
|
402
|
+
if (primaryGguf) {
|
|
403
|
+
meta.primaryFile = path.basename(primaryGguf);
|
|
404
|
+
changed = true;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
359
407
|
if (meta.adapterPath && !meta.adapterPath.includes('/$provider/#adapters/')) {
|
|
360
408
|
const adName = path.basename(String(meta.adapterPath));
|
|
361
409
|
const newAdPath = path.join(localAdaptersDir(rootDir), adName);
|
|
@@ -865,9 +865,6 @@ export function evaluateAiNodeActivitySync(item, rootDir = process.cwd()) {
|
|
|
865
865
|
// 1. Локальный провайдер /MODELS/Local и его модели
|
|
866
866
|
if (providerId === 'Local' || data.protocol === 'local' || data.protocol === 'halogen') {
|
|
867
867
|
const platform = os.platform();
|
|
868
|
-
const buboManifest1 = path.join(rootDir, 'MODELS', 'Local', 'models', 'qwen38-flash-next-base-ud-q4-k-xl-v1', 'bubo-package.json');
|
|
869
|
-
const buboManifest2 = path.join(rootDir, 'MODELS', 'Local', 'models', 'huihui-qwen38-flash-next-ud-q4-k-xl-v1', 'bubo-package.json');
|
|
870
|
-
const hasBuboGlobal = fs.existsSync(buboManifest1) || fs.existsSync(buboManifest2);
|
|
871
868
|
|
|
872
869
|
if (type === '$provider') {
|
|
873
870
|
const localDir = path.join(rootDir, 'MODELS', 'Local');
|
|
@@ -888,8 +885,8 @@ export function evaluateAiNodeActivitySync(item, rootDir = process.cwd()) {
|
|
|
888
885
|
}
|
|
889
886
|
}
|
|
890
887
|
catch { /* ignore */ }
|
|
891
|
-
if (installedCount > 0
|
|
892
|
-
return { active: true, reason: `Активен (моделей: ${installedCount
|
|
888
|
+
if (installedCount > 0) {
|
|
889
|
+
return { active: true, reason: `Активен (моделей: ${installedCount})`, configuredKey: true };
|
|
893
890
|
}
|
|
894
891
|
return { active: false, reason: 'Нет совместимых скачанных локальных моделей (откройте для установки)', configuredKey: false };
|
|
895
892
|
}
|
|
@@ -899,7 +896,6 @@ export function evaluateAiNodeActivitySync(item, rootDir = process.cwd()) {
|
|
|
899
896
|
const canonicalWeightsRel = path.join('MODELS', 'Local', modelName, '$ai', '#weights');
|
|
900
897
|
const legacyWeightsRel = path.join('MODELS', 'Local', modelName, '#weights');
|
|
901
898
|
const adapterRel = data.adapterPath || path.join('MODELS', 'Local', '$provider', '#adapters', modelName);
|
|
902
|
-
const isFlashNext = modelName === 'Qwen3.8-Flash-Next';
|
|
903
899
|
|
|
904
900
|
const check = inspectDirCandidatesSync([
|
|
905
901
|
data.weightsDir ? path.resolve(rootDir, data.weightsDir) : '',
|
|
@@ -909,7 +905,7 @@ export function evaluateAiNodeActivitySync(item, rootDir = process.cwd()) {
|
|
|
909
905
|
], platform);
|
|
910
906
|
|
|
911
907
|
const isHalogenLinuxRepo = /^peonist-ai\/halogen-/i.test(String(data.hfRepo || ''));
|
|
912
|
-
if (platform === 'win32' && isHalogenLinuxRepo && !
|
|
908
|
+
if (platform === 'win32' && isHalogenLinuxRepo && !check.info?.hasGguf && !check.info?.hasBuboManifest) {
|
|
913
909
|
return {
|
|
914
910
|
active: false,
|
|
915
911
|
reason: check.info?.incompatibleReason || 'Веса формата Linux (.hgn/.hnpw) несовместимы с Windows',
|
|
@@ -917,7 +913,7 @@ export function evaluateAiNodeActivitySync(item, rootDir = process.cwd()) {
|
|
|
917
913
|
configuredKey: false,
|
|
918
914
|
};
|
|
919
915
|
}
|
|
920
|
-
if (check.ready
|
|
916
|
+
if (check.ready) {
|
|
921
917
|
return { active: true, reason: 'Активна (веса модели на диске)', configuredKey: true };
|
|
922
918
|
}
|
|
923
919
|
if (check.incompatible) {
|
|
@@ -410,13 +410,9 @@ export async function listLocalModelsAndAdapters(rootDir = process.cwd()) {
|
|
|
410
410
|
}
|
|
411
411
|
|
|
412
412
|
const isAdapterNode = Boolean(meta.adapterPath);
|
|
413
|
-
const hasBuboExternal = e.name === 'Qwen3.8-Flash-Next' && (
|
|
414
|
-
fs.existsSync(path.join(localRoot, 'models', 'qwen38-flash-next-base-ud-q4-k-xl-v1', 'bubo-package.json'))
|
|
415
|
-
|| fs.existsSync(path.join(localRoot, 'models', 'huihui-qwen38-flash-next-ud-q4-k-xl-v1', 'bubo-package.json'))
|
|
416
|
-
);
|
|
417
413
|
|
|
418
414
|
// Если папка модели пустая (ни готовых весов, ни незавершённой загрузки, ни адаптера) — убираем мусор
|
|
419
|
-
if (!isDownloading && !hasPendingDownload && !hasRealWeightBinary && !isAdapterNode
|
|
415
|
+
if (!isDownloading && !hasPendingDownload && !hasRealWeightBinary && !isAdapterNode) {
|
|
420
416
|
try {
|
|
421
417
|
await fsp.rm(path.join(localRoot, e.name), { recursive: true, force: true });
|
|
422
418
|
}
|
|
@@ -429,10 +425,10 @@ export async function listLocalModelsAndAdapters(rootDir = process.cwd()) {
|
|
|
429
425
|
continue;
|
|
430
426
|
}
|
|
431
427
|
|
|
432
|
-
if (hasRealWeightBinary || isAdapterNode
|
|
428
|
+
if (hasRealWeightBinary || isAdapterNode) {
|
|
433
429
|
const enabled = meta.enabled !== false;
|
|
434
430
|
const isHalogenLinuxRepo = platform === 'win32' && /^peonist-ai\/halogen-/i.test(String(meta.hfRepo || ''));
|
|
435
|
-
const incompatible =
|
|
431
|
+
const incompatible = wInsp.incompatibleOnPlatform || (isHalogenLinuxRepo && !wInsp.hasGguf && !wInsp.hasBuboManifest);
|
|
436
432
|
const incompatibleReason = wInsp.incompatibleReason || (incompatible ? 'Веса формата Linux (.hgn/.hnpw) несовместимы с Windows. Удалите их и установите Windows-версию.' : '');
|
|
437
433
|
models.push({
|
|
438
434
|
id: e.name,
|
|
@@ -444,10 +440,10 @@ export async function listLocalModelsAndAdapters(rootDir = process.cwd()) {
|
|
|
444
440
|
capabilities: Array.isArray(meta.capabilities) ? meta.capabilities : ['chat', 'stream'],
|
|
445
441
|
maxTokens: meta.maxTokens || 16384,
|
|
446
442
|
enabled,
|
|
447
|
-
active: enabled && (hasRealWeightBinary || isAdapterNode
|
|
443
|
+
active: enabled && (hasRealWeightBinary || isAdapterNode) && !incompatible,
|
|
448
444
|
incompatibleOnPlatform: incompatible,
|
|
449
445
|
incompatibleReason: incompatible ? incompatibleReason : '',
|
|
450
|
-
weightFormat:
|
|
446
|
+
weightFormat: wInsp.weightFormat,
|
|
451
447
|
path: `/MODELS/Local/${e.name}`,
|
|
452
448
|
hasClass: fs.existsSync(aiClassFile),
|
|
453
449
|
weightFiles,
|
|
@@ -473,6 +469,13 @@ export async function deleteLocalModel({ rootDir = process.cwd(), modelId } = {}
|
|
|
473
469
|
if (fs.existsSync(targetDir)) {
|
|
474
470
|
await fsp.rm(targetDir, { recursive: true, force: true });
|
|
475
471
|
}
|
|
472
|
+
if (cleanId === 'Qwen3.8-Flash-Next') {
|
|
473
|
+
for (const sub of ['qwen38-flash-next-base-ud-q4-k-xl-v1', 'huihui-qwen38-flash-next-ud-q4-k-xl-v1']) {
|
|
474
|
+
const buboDir = path.join(localRoot, 'models', sub);
|
|
475
|
+
if (fs.existsSync(buboDir))
|
|
476
|
+
await fsp.rm(buboDir, { recursive: true, force: true }).catch(() => {});
|
|
477
|
+
}
|
|
478
|
+
}
|
|
476
479
|
return { ok: true, deletedId: cleanId, deletedPath: `/MODELS/Local/${cleanId}` };
|
|
477
480
|
}
|
|
478
481
|
|