odant-work 1.0.29 → 1.0.30
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 +34 -28
- package/$server/$folder/$class/ai/agents/builder.md +34 -24
- package/$server/$folder/$class/ai/agents/org-architect.md +40 -0
- package/$server/$folder/$class/ai/agents/readme.md +3 -1
- package/$server/$folder/$class/ai/agents/schema-validator.md +35 -0
- package/$server/$folder/$class/ai/skills/accounting-design.md +21 -0
- package/$server/$folder/$class/ai/skills/data-modeling.md +25 -0
- package/$server/$folder/$class/ai/skills/readme.md +3 -0
- package/$server/$folder/$class/ai/skills/schema-migration.md +23 -0
- package/$server/$folder/$class/handlers/pages/form/objects/$handler/objects.js +2 -0
- package/$server/$folder/$file/$task/handlers/pages/form/file/$handler/ui/util.js +4 -0
- package/$server/$folder/lib/consultant/consultant.js +1 -1
- package/$server/$folder/lib/tree/tree.js +2 -1
- package/MODELS/$ai/$folder/$class/$ai/class.js +17 -3
- package/MODELS/$ai/$folder/$class/$ai/handlers/pages/form/trainer/$handler/trainer.js +103 -6
- package/MODELS/$ai/$folder/$class/$provider/handlers/pages/form/trainer/$handler/trainer.js +37 -14
- package/oda/components/layouts/editor-form/editor-form.js +16 -3
- package/package.json +1 -1
- package/sources/data/progress.md +16 -0
- package/sources/data/schema.js +66 -2
- package/sources/host/auto-updater.js +1 -1
- package/sources/modules/agent/index.js +4 -3
- package/sources/modules/agent/tools/work/classes.js +1081 -0
- package/sources/modules/agent/tools/work.js +1 -0
- package/sources/modules/trainer/halogen.js +350 -32
- package/sources/modules/trainer/huggingface.js +80 -6
- package/sources/modules/trainer/index.js +139 -3
- package/sources/modules/trainer/local-engine.js +26 -29
- package/sources/modules/trainer/paths.js +119 -0
- package/sources/modules/trainer/providers.js +51 -36
- package/sources/modules/trainer/runner.js +72 -31
- package/sources/server/class/security.js +10 -3
- package/sources/server/class.js +6 -0
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import fs from 'node:fs';
|
|
10
10
|
import fsp from 'node:fs/promises';
|
|
11
|
+
import os from 'node:os';
|
|
11
12
|
import path from 'node:path';
|
|
12
13
|
import crypto from 'node:crypto';
|
|
13
14
|
import {
|
|
@@ -27,6 +28,8 @@ import {
|
|
|
27
28
|
modelWeightsDir as getModelWeightsDir,
|
|
28
29
|
migrateLocalModelsLayoutSync,
|
|
29
30
|
hasReadyWeightFilesSync,
|
|
31
|
+
LINUX_ONLY_HALOGEN_EXT_RE,
|
|
32
|
+
getFreeDiskSpaceGb,
|
|
30
33
|
} from './paths.js';
|
|
31
34
|
|
|
32
35
|
const HF_ORIGIN = DEFAULT_HF_ORIGIN;
|
|
@@ -185,19 +188,39 @@ export const CURATED_HF_MODELS = Object.freeze([
|
|
|
185
188
|
{
|
|
186
189
|
id: 'peonist-ai/halogen-qwen3.8-flash-next',
|
|
187
190
|
author: 'peonist-ai',
|
|
188
|
-
modelName: 'Qwen3.8-Flash-Next (Halogen
|
|
191
|
+
modelName: 'Qwen3.8-Flash-Next (Halogen Linux ROCm)',
|
|
189
192
|
modality: 'llm',
|
|
190
|
-
format: '
|
|
193
|
+
format: 'hgn',
|
|
194
|
+
platforms: ['linux'],
|
|
191
195
|
paramsB: 180,
|
|
192
|
-
ramRequiredGb:
|
|
196
|
+
ramRequiredGb: 112.0,
|
|
193
197
|
trainRamGb: 138.0,
|
|
194
198
|
capabilities: ['chat', 'tools', 'thinking', 'coding', 'vision'],
|
|
195
|
-
whatItDoes: 'Флагманская модель 180B MoE (4.16 bpw + FP8 lookup table) для
|
|
196
|
-
recommendedFor: '
|
|
199
|
+
whatItDoes: 'Флагманская модель 180B MoE (4.16 bpw + FP8 lookup table) для Linux Strix Halo (halogen-flash-server): 73–94 tok/s decode, 1800 tok/s prefill',
|
|
200
|
+
recommendedFor: 'Только для Linux ПАК WORK на AMD Ryzen AI 495 Pro 192 ГБ RAM',
|
|
197
201
|
tags: ['qwen3', 'qwen3.8', 'halogen', 'strix-halo', 'ryzen-ai', 'gfx1151', 'moe', 'tool-calling', 'vision'],
|
|
198
202
|
downloads: 128000,
|
|
199
203
|
likes: 1890,
|
|
200
204
|
},
|
|
205
|
+
{
|
|
206
|
+
id: 'unsloth/Qwen3.8-Flash-Next-GGUF',
|
|
207
|
+
author: 'unsloth',
|
|
208
|
+
modelName: 'Qwen3.8-Flash-Next (180B MoE · Windows Halowin Bubo)',
|
|
209
|
+
modality: 'llm',
|
|
210
|
+
format: 'gguf',
|
|
211
|
+
platforms: ['win32'],
|
|
212
|
+
buboPackage: true,
|
|
213
|
+
haloNodeName: 'Qwen3.8-Flash-Next',
|
|
214
|
+
paramsB: 180,
|
|
215
|
+
ramRequiredGb: 116.6,
|
|
216
|
+
trainRamGb: 150.0,
|
|
217
|
+
capabilities: ['chat', 'tools', 'thinking', 'coding', 'vision'],
|
|
218
|
+
whatItDoes: 'Флагманская модель 180B MoE (UD-Q4_K_XL + MTP + Dense Twin + Vision) для Windows 11 Strix Halo через встроенный движок Halowin Bubo (ROCm 10.0 gfx1151)',
|
|
219
|
+
recommendedFor: 'Оптимально для Windows 11 на AMD Ryzen AI Max+ PRO 495 (128–192 ГБ)',
|
|
220
|
+
tags: ['qwen3', 'qwen3.8', 'gguf', 'bubo', 'strix-halo', 'ryzen-ai', 'gfx1151', 'moe', 'tool-calling', 'vision'],
|
|
221
|
+
downloads: 142000,
|
|
222
|
+
likes: 1950,
|
|
223
|
+
},
|
|
201
224
|
{
|
|
202
225
|
id: 'Qwen/Qwen3-235B-A22B-GGUF',
|
|
203
226
|
author: 'Qwen',
|
|
@@ -704,6 +727,7 @@ export async function searchHuggingFaceModels({
|
|
|
704
727
|
limit = 25,
|
|
705
728
|
token = '',
|
|
706
729
|
usableMemoryGb = 24,
|
|
730
|
+
platform = os.platform(),
|
|
707
731
|
rootDir = process.cwd(),
|
|
708
732
|
endpointUrl,
|
|
709
733
|
proxyUrl,
|
|
@@ -716,6 +740,10 @@ export async function searchHuggingFaceModels({
|
|
|
716
740
|
const fLower = String(filter || '').trim().toLowerCase();
|
|
717
741
|
|
|
718
742
|
const curatedMatches = CURATED_HF_MODELS.filter(m => {
|
|
743
|
+
if (Array.isArray(m.platforms) && m.platforms.length && !m.platforms.includes(platform))
|
|
744
|
+
return false;
|
|
745
|
+
if (platform === 'win32' && (m.format === 'hgn' || m.format === 'hnpw' || /^peonist-ai\/halogen-/i.test(m.id)))
|
|
746
|
+
return false;
|
|
719
747
|
if (modLower && modLower !== 'all' && m.modality !== modLower)
|
|
720
748
|
return false;
|
|
721
749
|
if (capLower && capLower !== 'all' && !(m.capabilities || []).includes(capLower))
|
|
@@ -778,8 +806,10 @@ export async function searchHuggingFaceModels({
|
|
|
778
806
|
const id = String(row.id || row.modelId || '').trim();
|
|
779
807
|
if (!id || seen.has(id))
|
|
780
808
|
continue;
|
|
781
|
-
seen.add(id);
|
|
782
809
|
const tags = Array.isArray(row.tags) ? row.tags : [];
|
|
810
|
+
if (platform === 'win32' && (/^peonist-ai\/halogen-/i.test(id) || tags.includes('halogen') || tags.includes('halogen-flash')))
|
|
811
|
+
continue;
|
|
812
|
+
seen.add(id);
|
|
783
813
|
const isGguf = tags.includes('gguf') || /gguf/i.test(id);
|
|
784
814
|
const format = isGguf ? 'gguf' : 'safetensors';
|
|
785
815
|
const est = estimateModelMemoryFromId(id, format);
|
|
@@ -963,6 +993,21 @@ export function selectFilesToDownload(repoMeta, { files = null, quant = '' } = {
|
|
|
963
993
|
const q4 = ggufs.filter(f => f.quant === 'Q4_K_M' || /Q4_K_M/i.test(f.name));
|
|
964
994
|
return q4.length ? q4 : [ggufs[0]];
|
|
965
995
|
}
|
|
996
|
+
// Для репозиториев Halogen (.hgn) не качаем устаревшие дублирующие чекпоинты (w4b, ht43, mtp) —
|
|
997
|
+
// выбираем только актуальный v2 + ngram + drafter-r2 + vision + конфиги/токенизатор (~112 ГБ вместо 308 ГБ).
|
|
998
|
+
const hgnFiles = all.filter(f => f.name.toLowerCase().endsWith('.hgn'));
|
|
999
|
+
if (hgnFiles.length) {
|
|
1000
|
+
const hasV2 = hgnFiles.some(f => /v2\.hgn$/i.test(f.name));
|
|
1001
|
+
if (hasV2) {
|
|
1002
|
+
return all.filter(f => {
|
|
1003
|
+
const low = f.name.toLowerCase();
|
|
1004
|
+
if (low.endsWith('.hgn')) {
|
|
1005
|
+
return /-(v2|ngram|drafter-r2|vision)\.hgn$/i.test(low);
|
|
1006
|
+
}
|
|
1007
|
+
return f.kind === 'config' || low.includes('tokenizer') || low === 'vocab.json' || low === 'merges.txt' || low.endsWith('.jinja');
|
|
1008
|
+
});
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
966
1011
|
return all.filter(f => f.kind === 'config' || f.kind === 'safetensors');
|
|
967
1012
|
}
|
|
968
1013
|
|
|
@@ -1153,6 +1198,7 @@ export async function startHuggingFaceDownload({
|
|
|
1153
1198
|
quant = 'Q8_0',
|
|
1154
1199
|
revision = 'main',
|
|
1155
1200
|
token = '',
|
|
1201
|
+
platform = os.platform(),
|
|
1156
1202
|
rootDir = process.cwd(),
|
|
1157
1203
|
providerFolder = 'Local',
|
|
1158
1204
|
targetNodeName = '',
|
|
@@ -1171,6 +1217,10 @@ export async function startHuggingFaceDownload({
|
|
|
1171
1217
|
const cleanId = validateRepoId(repoId);
|
|
1172
1218
|
const safeProvider = String(providerFolder || 'Local').replace(/[<>:"/\\|?*]/g, '-');
|
|
1173
1219
|
|
|
1220
|
+
if (platform === 'win32' && /^peonist-ai\/halogen-/i.test(cleanId)) {
|
|
1221
|
+
throw new Error(`Репозиторий ${cleanId} содержит веса формата Linux (.hgn/.hnpw), которые не поддерживаются на Windows. Для Windows используйте нативный стек Halowin Bubo (GGUF) или .safetensors.`);
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1174
1224
|
// Если эта модель уже скачивается прямо сейчас — возвращаем активную задачу без дублирования
|
|
1175
1225
|
for (const entry of _downloads.values()) {
|
|
1176
1226
|
if (
|
|
@@ -1202,6 +1252,21 @@ export async function startHuggingFaceDownload({
|
|
|
1202
1252
|
if (!selected.length)
|
|
1203
1253
|
throw new Error(`В репозитории ${cleanId} не найдено подходящих файлов весов (.gguf / .safetensors)`);
|
|
1204
1254
|
|
|
1255
|
+
const hasLinuxOnlyWeights = selected.some(f => LINUX_ONLY_HALOGEN_EXT_RE.test(f.name));
|
|
1256
|
+
const hasCrossPlatformWeights = selected.some(f => /\.(gguf|safetensors)$/i.test(f.name));
|
|
1257
|
+
if (platform === 'win32' && hasLinuxOnlyWeights && !hasCrossPlatformWeights) {
|
|
1258
|
+
throw new Error(`В репозитории ${cleanId} найдены только веса Linux (.hgn/.hnpw), несовместимые с Windows.`);
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1261
|
+
const totalExpectedBytes = selected.reduce((acc, f) => acc + (Number(f.size) || 0), 0);
|
|
1262
|
+
if (totalExpectedBytes > 512 * 1024 * 1024) {
|
|
1263
|
+
const freeGb = getFreeDiskSpaceGb(rootDir);
|
|
1264
|
+
const needGb = +(totalExpectedBytes / (1024 ** 3)).toFixed(1);
|
|
1265
|
+
if (freeGb !== null && freeGb < needGb + 1) {
|
|
1266
|
+
throw new Error(`Недостаточно свободного места на диске для загрузки ${cleanId}: свободно ${freeGb} ГБ, требуется не менее ${needGb} ГБ.`);
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1205
1270
|
const folderName = targetNodeName
|
|
1206
1271
|
? String(targetNodeName).replace(/[<>:"/\\|?*]/g, '-')
|
|
1207
1272
|
: safeModelFolderName(cleanId, quant && selected.some(f => f.kind === 'gguf') ? quant : '');
|
|
@@ -1886,6 +1951,15 @@ export async function resumeInterruptedDownloads({
|
|
|
1886
1951
|
catch { continue; }
|
|
1887
1952
|
if (state?.status !== 'downloading' || !state?.repoId)
|
|
1888
1953
|
continue;
|
|
1954
|
+
if (os.platform() === 'win32' && /^peonist-ai\/halogen-/i.test(String(state.repoId))) {
|
|
1955
|
+
try {
|
|
1956
|
+
state.status = 'failed';
|
|
1957
|
+
state.error = 'Веса формата Linux (.hgn/.hnpw) не поддерживаются на Windows. Сбросьте эту загрузку и установите Windows-версию (Halowin Bubo GGUF).';
|
|
1958
|
+
fs.writeFileSync(stateFile, JSON.stringify(state, null, 2), 'utf-8');
|
|
1959
|
+
}
|
|
1960
|
+
catch { /* ignore */ }
|
|
1961
|
+
continue;
|
|
1962
|
+
}
|
|
1889
1963
|
try {
|
|
1890
1964
|
const job = await resumeHuggingFaceDownload({
|
|
1891
1965
|
folderName: e.name,
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Публичный API подсистемы локальных моделей Hugging Face и встроенного дообучения Unsloth (`trainer_*`).
|
|
3
3
|
*/
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import os from 'node:os';
|
|
6
|
+
import path from 'node:path';
|
|
4
7
|
import {
|
|
5
8
|
CURATED_HF_MODELS,
|
|
6
9
|
MODEL_MODALITIES,
|
|
@@ -52,6 +55,8 @@ import {
|
|
|
52
55
|
BUBO_WINDOWS_RELEASE,
|
|
53
56
|
HALOGEN_MODELS_CATALOG,
|
|
54
57
|
HALOGEN_TTS_VOICES,
|
|
58
|
+
getHalogenCatalogForPlatform,
|
|
59
|
+
checkWindowsHalogenPreflight,
|
|
55
60
|
recordHalogenSessionHandle,
|
|
56
61
|
listHalogenSessionHandles,
|
|
57
62
|
releaseHalogenSessionHandle,
|
|
@@ -62,6 +67,7 @@ import {
|
|
|
62
67
|
probeHalogenServer,
|
|
63
68
|
startHalogenBackend,
|
|
64
69
|
stopHalogenBackend,
|
|
70
|
+
ensureHalogenBackendRunning,
|
|
65
71
|
synthesizeFallbackWav,
|
|
66
72
|
computeFallbackEmbeddings,
|
|
67
73
|
computeFallbackRerank,
|
|
@@ -108,6 +114,11 @@ import {
|
|
|
108
114
|
listTransferJobs,
|
|
109
115
|
cancelTransferJob,
|
|
110
116
|
} from './transfer.js';
|
|
117
|
+
import {
|
|
118
|
+
inspectWeightsDirectorySync,
|
|
119
|
+
modelWeightsDir,
|
|
120
|
+
LINUX_ONLY_HALOGEN_EXT_RE,
|
|
121
|
+
} from './paths.js';
|
|
111
122
|
|
|
112
123
|
export const halogenFallback = Object.freeze({
|
|
113
124
|
normalizeHalogenTtsPayload,
|
|
@@ -151,6 +162,8 @@ export {
|
|
|
151
162
|
BUBO_WINDOWS_RELEASE,
|
|
152
163
|
HALOGEN_MODELS_CATALOG,
|
|
153
164
|
HALOGEN_TTS_VOICES,
|
|
165
|
+
getHalogenCatalogForPlatform,
|
|
166
|
+
checkWindowsHalogenPreflight,
|
|
154
167
|
recordHalogenSessionHandle,
|
|
155
168
|
listHalogenSessionHandles,
|
|
156
169
|
releaseHalogenSessionHandle,
|
|
@@ -161,6 +174,7 @@ export {
|
|
|
161
174
|
probeHalogenServer,
|
|
162
175
|
startHalogenBackend,
|
|
163
176
|
stopHalogenBackend,
|
|
177
|
+
ensureHalogenBackendRunning,
|
|
164
178
|
synthesizeFallbackWav,
|
|
165
179
|
computeFallbackEmbeddings,
|
|
166
180
|
computeFallbackRerank,
|
|
@@ -310,9 +324,16 @@ export const TRAINER_METHODS = Object.freeze({
|
|
|
310
324
|
totalRamGb: hardware?.totalRamGb >= 120 ? hardware.totalRamGb : 192,
|
|
311
325
|
platform: hardware?.platform,
|
|
312
326
|
});
|
|
327
|
+
const platform = hardware?.platform || os.platform();
|
|
328
|
+
const probe = await probeHalogenServer(HALOGEN_DEFAULT_BASE_URL).catch(() => null);
|
|
313
329
|
const runtime = getLocalEngineStatus({
|
|
314
330
|
totalRamGb: hardware?.totalRamGb,
|
|
331
|
+
halogenOnline: Boolean(probe?.online),
|
|
315
332
|
});
|
|
333
|
+
const curatedCompatible = CURATED_HF_MODELS.filter(m =>
|
|
334
|
+
(!Array.isArray(m.platforms) || !m.platforms.length || m.platforms.includes(platform))
|
|
335
|
+
&& !(platform === 'win32' && (m.format === 'hgn' || m.format === 'hnpw'))
|
|
336
|
+
);
|
|
316
337
|
return {
|
|
317
338
|
hardware,
|
|
318
339
|
runtime,
|
|
@@ -325,16 +346,129 @@ export const TRAINER_METHODS = Object.freeze({
|
|
|
325
346
|
network: sanitizeTrainerNetworkForClient(loadTrainerNetworkSettings()),
|
|
326
347
|
modalities: MODEL_MODALITIES,
|
|
327
348
|
capabilities: Object.values(MODEL_CAPABILITIES),
|
|
328
|
-
curated:
|
|
349
|
+
curated: curatedCompatible,
|
|
329
350
|
halogen: {
|
|
351
|
+
online: Boolean(probe?.online),
|
|
352
|
+
mode: probe?.mode || '',
|
|
353
|
+
modeLabel: probe?.modeLabel || '',
|
|
330
354
|
memoryPlan: halogenPlan,
|
|
331
|
-
catalog: inspectHalogenCatalogWithStatus(),
|
|
355
|
+
catalog: inspectHalogenCatalogWithStatus(process.cwd(), { platform }),
|
|
332
356
|
handles: listHalogenSessionHandles(),
|
|
333
|
-
windowsEnv: inspectWindowsHalogenEnvironment(),
|
|
357
|
+
windowsEnv: probe?.windowsEnv || inspectWindowsHalogenEnvironment(),
|
|
334
358
|
},
|
|
335
359
|
};
|
|
336
360
|
},
|
|
337
361
|
},
|
|
362
|
+
trainer_model_info: {
|
|
363
|
+
level: 'read',
|
|
364
|
+
fn: async function () {
|
|
365
|
+
await this?.init;
|
|
366
|
+
const d = this?.DATA || {};
|
|
367
|
+
const itemPath = String(this?.path || this?.short || '');
|
|
368
|
+
const parts = itemPath.split('/').filter(Boolean);
|
|
369
|
+
const providerId = parts[1] || 'MODELS';
|
|
370
|
+
const isLocal = providerId === 'Local' || d.protocol === 'local' || d.protocol === 'halogen';
|
|
371
|
+
const act = evaluateAiNodeActivitySync(this);
|
|
372
|
+
|
|
373
|
+
let weightInfo = null;
|
|
374
|
+
let halogenProbe = null;
|
|
375
|
+
let sizeGb = 0;
|
|
376
|
+
let needsRuntime = false;
|
|
377
|
+
|
|
378
|
+
if (isLocal) {
|
|
379
|
+
const wDirRel = d.weightsDir || path.join('MODELS', 'Local', this?.id || '', '$ai', '#weights');
|
|
380
|
+
const wDirAbs = path.resolve(process.cwd(), wDirRel);
|
|
381
|
+
weightInfo = inspectWeightsDirectorySync(wDirAbs, os.platform());
|
|
382
|
+
if (weightInfo.exists) {
|
|
383
|
+
let bytes = 0;
|
|
384
|
+
for (const f of weightInfo.files) {
|
|
385
|
+
try {
|
|
386
|
+
bytes += fs.statSync(path.join(wDirAbs, f)).size || 0;
|
|
387
|
+
}
|
|
388
|
+
catch { /* ignore */ }
|
|
389
|
+
}
|
|
390
|
+
sizeGb = +(bytes / (1024 ** 3)).toFixed(2);
|
|
391
|
+
}
|
|
392
|
+
if (d.protocol === 'halogen' || weightInfo?.hasGguf || weightInfo?.hasBuboManifest) {
|
|
393
|
+
halogenProbe = await probeHalogenServer(d.baseUrl || HALOGEN_DEFAULT_BASE_URL).catch(() => null);
|
|
394
|
+
const winEnv = halogenProbe?.windowsEnv || inspectWindowsHalogenEnvironment();
|
|
395
|
+
if (os.platform() === 'win32' && !halogenProbe?.online && !winEnv.buboInstalled && !winEnv.gufoInstalled) {
|
|
396
|
+
needsRuntime = true;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
return {
|
|
402
|
+
id: this?.id || '',
|
|
403
|
+
label: d.label || this?.label || this?.id || '',
|
|
404
|
+
icon: d.icon || this?.icon || 'carbon:machine-learning-model',
|
|
405
|
+
path: itemPath,
|
|
406
|
+
providerName: providerId,
|
|
407
|
+
isLocal,
|
|
408
|
+
protocol: d.protocol || (isLocal ? 'local' : 'openai'),
|
|
409
|
+
model: d.model || this?.id || '',
|
|
410
|
+
baseUrl: d.baseUrl || '',
|
|
411
|
+
modality: d.modality || 'llm',
|
|
412
|
+
maxTokens: Number(d.maxTokens || d.$public?.maxTokens) || 32768,
|
|
413
|
+
maxOutput: Number(d.maxOutput || d.$public?.maxOutput) || 8192,
|
|
414
|
+
capabilities: Array.isArray(d.capabilities) ? d.capabilities : (d.$public?.capabilities || ['chat', 'stream']),
|
|
415
|
+
efforts: Array.isArray(d.efforts) ? d.efforts : [],
|
|
416
|
+
weightsDir: d.weightsDir || '',
|
|
417
|
+
primaryFile: d.primaryFile || '',
|
|
418
|
+
enabled: d.enabled !== false,
|
|
419
|
+
aiActive: act.active,
|
|
420
|
+
aiStatusReason: act.reason,
|
|
421
|
+
weightFormat: weightInfo?.weightFormat || '',
|
|
422
|
+
incompatibleOnPlatform: Boolean(act.incompatibleOnPlatform || weightInfo?.incompatibleOnPlatform),
|
|
423
|
+
incompatibleReason: act.incompatibleOnPlatform ? act.reason : (weightInfo?.incompatibleReason || ''),
|
|
424
|
+
sizeGb,
|
|
425
|
+
needsRuntime,
|
|
426
|
+
halogenOnline: Boolean(halogenProbe?.online),
|
|
427
|
+
halogenMode: halogenProbe?.mode || '',
|
|
428
|
+
halogenModeLabel: halogenProbe?.modeLabel || '',
|
|
429
|
+
windowsEnv: halogenProbe?.windowsEnv || null,
|
|
430
|
+
};
|
|
431
|
+
},
|
|
432
|
+
},
|
|
433
|
+
trainer_delete_incompatible: {
|
|
434
|
+
level: 'admin',
|
|
435
|
+
fn: async function (p = {}) {
|
|
436
|
+
await this?.init;
|
|
437
|
+
const modelId = p.modelId || p.id || this?.id || '';
|
|
438
|
+
const cleanId = String(modelId).replace(/^\/?MODELS\/Local\//i, '').replace(/[<>:"/\\|?*]/g, '').trim();
|
|
439
|
+
if (!cleanId)
|
|
440
|
+
throw new Error('Не указана модель');
|
|
441
|
+
const wDir = modelWeightsDir(process.cwd(), cleanId, 'Local');
|
|
442
|
+
const info = inspectWeightsDirectorySync(wDir, os.platform());
|
|
443
|
+
if (info.exists && !info.hasGguf && !info.hasSafetensors && !info.hasBuboManifest) {
|
|
444
|
+
const res = await deleteLocalModel({ modelId: cleanId });
|
|
445
|
+
try {
|
|
446
|
+
const localNode = await globalThis.WORK?.get_item?.('/MODELS/Local');
|
|
447
|
+
localNode?.reset?.();
|
|
448
|
+
const modelsRoot = await globalThis.WORK?.get_item?.('/MODELS');
|
|
449
|
+
modelsRoot?.reset?.();
|
|
450
|
+
}
|
|
451
|
+
catch { /* ignore */ }
|
|
452
|
+
return { ...res, mode: 'deleted_model' };
|
|
453
|
+
}
|
|
454
|
+
let removedCount = 0;
|
|
455
|
+
if (fs.existsSync(wDir)) {
|
|
456
|
+
for (const f of fs.readdirSync(wDir)) {
|
|
457
|
+
if (LINUX_ONLY_HALOGEN_EXT_RE.test(f) || (LINUX_ONLY_HALOGEN_EXT_RE.test(f.replace(/\.part$/i, '')))) {
|
|
458
|
+
fs.rmSync(path.join(wDir, f), { force: true });
|
|
459
|
+
removedCount++;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
try {
|
|
464
|
+
this?.reset?.();
|
|
465
|
+
const localNode = await globalThis.WORK?.get_item?.('/MODELS/Local');
|
|
466
|
+
localNode?.reset?.();
|
|
467
|
+
}
|
|
468
|
+
catch { /* ignore */ }
|
|
469
|
+
return { ok: true, removedCount, mode: 'removed_files' };
|
|
470
|
+
},
|
|
471
|
+
},
|
|
338
472
|
trainer_delete_model: {
|
|
339
473
|
level: 'admin',
|
|
340
474
|
fn: async function (p = {}) {
|
|
@@ -395,10 +529,12 @@ export const TRAINER_METHODS = Object.freeze({
|
|
|
395
529
|
halogen_download_bundle: {
|
|
396
530
|
level: 'admin',
|
|
397
531
|
fn: async function (p = {}) {
|
|
532
|
+
const hw = await detectHardware().catch(() => null);
|
|
398
533
|
const res = await downloadHalogenBundle({
|
|
399
534
|
models: p.models || p.nodeName || p.model || null,
|
|
400
535
|
token: p.token || '',
|
|
401
536
|
waitForCompletion: p.wait === true || p.wait === 'true',
|
|
537
|
+
totalMemoryGb: hw?.totalRamGb ?? null,
|
|
402
538
|
});
|
|
403
539
|
try {
|
|
404
540
|
const localNode = await globalThis.WORK?.get_item?.('/MODELS/Local');
|
|
@@ -15,7 +15,8 @@ import { dataStore } from '../../data/api.js';
|
|
|
15
15
|
import { classesOfType } from '../../data/classes.js';
|
|
16
16
|
import { classSchema } from '../../data/schema.js';
|
|
17
17
|
import { trialBalance } from '../../data/reports.js';
|
|
18
|
-
import { recordHalogenSessionHandle, stopHalogenBackend } from './halogen.js';
|
|
18
|
+
import { ensureHalogenBackendRunning, recordHalogenSessionHandle, stopHalogenBackend } from './halogen.js';
|
|
19
|
+
import { inspectWeightsDirectorySync } from './paths.js';
|
|
19
20
|
|
|
20
21
|
const money = v => Number(v || 0).toLocaleString('ru-RU', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
|
21
22
|
|
|
@@ -100,12 +101,6 @@ function resolveWeightsDir(ai, rootDir = process.cwd()) {
|
|
|
100
101
|
const legacy = path.resolve(rootDir, `MODELS/Local/${modelId}/#weights`);
|
|
101
102
|
if (fs.existsSync(legacy))
|
|
102
103
|
return legacy;
|
|
103
|
-
const isHalogen = ai?.protocol === 'halogen' || String(ai?.path || ai?.short || '').startsWith('/MODELS/Halogen/');
|
|
104
|
-
if (isHalogen) {
|
|
105
|
-
const fallback06 = path.resolve(rootDir, 'MODELS/Local/Qwen3-0.6B/$ai/#weights');
|
|
106
|
-
if (fs.existsSync(fallback06))
|
|
107
|
-
return fallback06;
|
|
108
|
-
}
|
|
109
104
|
return primary;
|
|
110
105
|
}
|
|
111
106
|
|
|
@@ -399,27 +394,29 @@ export async function* localStreamChat(ai, body = {}, options = {}) {
|
|
|
399
394
|
return;
|
|
400
395
|
}
|
|
401
396
|
|
|
402
|
-
const
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
tokens: 24,
|
|
407
|
-
});
|
|
397
|
+
const wInsp = inspectWeightsDirectorySync(weightsDir);
|
|
398
|
+
if (wInsp.incompatibleOnPlatform) {
|
|
399
|
+
throw new Error(wInsp.incompatibleReason);
|
|
400
|
+
}
|
|
408
401
|
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
402
|
+
if (wInsp.hasGguf || wInsp.hasBuboManifest || ai?.protocol === 'halogen' || ai?.DATA?.protocol === 'halogen') {
|
|
403
|
+
const backend = await ensureHalogenBackendRunning({
|
|
404
|
+
baseUrl: ai?.baseUrl || ai?.DATA?.baseUrl,
|
|
405
|
+
ai,
|
|
406
|
+
});
|
|
407
|
+
if (!backend.ready) {
|
|
408
|
+
throw new Error(backend.reason || 'Сервер локального ИИ (:8731) не запущен.');
|
|
409
|
+
}
|
|
410
|
+
throw new Error('Встроенный движок :8731 запущен — повторите запрос для подключения по HTTP.');
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
if (wInsp.pendingDownload) {
|
|
414
|
+
throw new Error('Загрузка весов модели ещё не завершена (проверьте вкладку «Модели» в /MODELS/Local).');
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
if (wInsp.hasSafetensors && !wInsp.hasConfig) {
|
|
418
|
+
throw new Error('В папке весов модели отсутствует config.json или tokenizer.json.');
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
throw new Error('Файлы весов модели ещё не скачаны в $ai/#weights (откройте /MODELS/Local для установки).');
|
|
425
422
|
}
|
|
@@ -11,9 +11,11 @@
|
|
|
11
11
|
* лежит строго внутри её метапапки `MODELS/Local/<Модель>/$ai/#weights/`.
|
|
12
12
|
*/
|
|
13
13
|
import fs from 'node:fs';
|
|
14
|
+
import os from 'node:os';
|
|
14
15
|
import path from 'node:path';
|
|
15
16
|
|
|
16
17
|
export const WEIGHT_FILE_EXT_RE = /\.(gguf|safetensors|hgn|hnpw|bin|onnx|pt|pth)$/i;
|
|
18
|
+
export const LINUX_ONLY_HALOGEN_EXT_RE = /\.(hgn|hnpw)$/i;
|
|
17
19
|
|
|
18
20
|
export function localRootDir(rootDir = process.cwd()) {
|
|
19
21
|
return path.join(rootDir, 'MODELS', 'Local');
|
|
@@ -73,6 +75,123 @@ export function hasReadyWeightFilesSync(dirPath) {
|
|
|
73
75
|
}
|
|
74
76
|
}
|
|
75
77
|
|
|
78
|
+
/**
|
|
79
|
+
* Детально проинспектировать директорию весов модели: формат, готовность и совместимость с текущей ОС.
|
|
80
|
+
*/
|
|
81
|
+
export function inspectWeightsDirectorySync(dirPath, platform = os.platform()) {
|
|
82
|
+
const empty = {
|
|
83
|
+
exists: false,
|
|
84
|
+
pendingDownload: false,
|
|
85
|
+
hasReadyWeights: false,
|
|
86
|
+
weightFormat: '',
|
|
87
|
+
files: [],
|
|
88
|
+
hasSafetensors: false,
|
|
89
|
+
hasGguf: false,
|
|
90
|
+
hasBuboManifest: false,
|
|
91
|
+
hasHgn: false,
|
|
92
|
+
hasHnpw: false,
|
|
93
|
+
hasConfig: false,
|
|
94
|
+
hasTokenizer: false,
|
|
95
|
+
incompatibleOnPlatform: false,
|
|
96
|
+
incompatibleReason: '',
|
|
97
|
+
};
|
|
98
|
+
if (!dirPath || !fs.existsSync(dirPath))
|
|
99
|
+
return empty;
|
|
100
|
+
try {
|
|
101
|
+
const raw = fs.readdirSync(dirPath);
|
|
102
|
+
const hasParts = raw.some(f => f.endsWith('.part'));
|
|
103
|
+
let pendingState = false;
|
|
104
|
+
if (raw.includes('download-state.json')) {
|
|
105
|
+
try {
|
|
106
|
+
const st = JSON.parse(fs.readFileSync(path.join(dirPath, 'download-state.json'), 'utf-8'));
|
|
107
|
+
pendingState = st?.status !== 'completed';
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
pendingState = true;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
const files = raw.filter(f =>
|
|
114
|
+
!f.endsWith('.part')
|
|
115
|
+
&& !f.endsWith('.tmp')
|
|
116
|
+
&& f !== 'hf-manifest.json'
|
|
117
|
+
&& f !== 'download-state.json'
|
|
118
|
+
);
|
|
119
|
+
const hasSafetensors = files.some(f => f.toLowerCase().endsWith('.safetensors'));
|
|
120
|
+
const hasGguf = files.some(f => f.toLowerCase().endsWith('.gguf'));
|
|
121
|
+
const hasBuboManifest = files.includes('bubo-package.json');
|
|
122
|
+
const hasHgn = files.some(f => f.toLowerCase().endsWith('.hgn'));
|
|
123
|
+
const hasHnpw = files.some(f => f.toLowerCase().endsWith('.hnpw'));
|
|
124
|
+
const hasOther = files.some(f => /\.(bin|onnx|pt|pth)$/i.test(f));
|
|
125
|
+
const hasConfig = files.includes('config.json');
|
|
126
|
+
const hasTokenizer = files.includes('tokenizer.json');
|
|
127
|
+
const pendingDownload = hasParts || pendingState;
|
|
128
|
+
const hasReadyWeights = !pendingDownload && (hasSafetensors || hasGguf || hasBuboManifest || hasHgn || hasHnpw || hasOther);
|
|
129
|
+
|
|
130
|
+
let weightFormat = '';
|
|
131
|
+
if (hasBuboManifest)
|
|
132
|
+
weightFormat = 'bubo';
|
|
133
|
+
else if (hasGguf)
|
|
134
|
+
weightFormat = 'gguf';
|
|
135
|
+
else if (hasSafetensors)
|
|
136
|
+
weightFormat = 'safetensors';
|
|
137
|
+
else if (hasHgn)
|
|
138
|
+
weightFormat = 'hgn';
|
|
139
|
+
else if (hasHnpw)
|
|
140
|
+
weightFormat = 'hnpw';
|
|
141
|
+
else if (hasOther)
|
|
142
|
+
weightFormat = 'other';
|
|
143
|
+
|
|
144
|
+
const isWin = platform === 'win32';
|
|
145
|
+
const incompatibleOnPlatform = isWin && (hasHgn || hasHnpw) && !hasGguf && !hasBuboManifest && !hasSafetensors;
|
|
146
|
+
const incompatibleReason = incompatibleOnPlatform
|
|
147
|
+
? 'Скачаны веса формата Linux (.hgn/.hnpw), несовместимые с Windows. Удалите их и установите Windows-версию (GGUF / .safetensors).'
|
|
148
|
+
: '';
|
|
149
|
+
|
|
150
|
+
return {
|
|
151
|
+
exists: true,
|
|
152
|
+
pendingDownload,
|
|
153
|
+
hasReadyWeights,
|
|
154
|
+
weightFormat,
|
|
155
|
+
files,
|
|
156
|
+
hasSafetensors,
|
|
157
|
+
hasGguf,
|
|
158
|
+
hasBuboManifest,
|
|
159
|
+
hasHgn,
|
|
160
|
+
hasHnpw,
|
|
161
|
+
hasConfig,
|
|
162
|
+
hasTokenizer,
|
|
163
|
+
incompatibleOnPlatform,
|
|
164
|
+
incompatibleReason,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
catch {
|
|
168
|
+
return empty;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Узнать объём свободного места (в ГБ) на диске, содержащем `targetPath`.
|
|
174
|
+
*/
|
|
175
|
+
export function getFreeDiskSpaceGb(targetPath = process.cwd()) {
|
|
176
|
+
try {
|
|
177
|
+
let probe = path.resolve(targetPath);
|
|
178
|
+
while (!fs.existsSync(probe)) {
|
|
179
|
+
const parent = path.dirname(probe);
|
|
180
|
+
if (!parent || parent === probe)
|
|
181
|
+
break;
|
|
182
|
+
probe = parent;
|
|
183
|
+
}
|
|
184
|
+
if (typeof fs.statfsSync === 'function' && fs.existsSync(probe)) {
|
|
185
|
+
const st = fs.statfsSync(probe);
|
|
186
|
+
const freeBytes = Number(st.bavail || st.bfree || 0) * Number(st.bsize || 0);
|
|
187
|
+
if (freeBytes > 0)
|
|
188
|
+
return +(freeBytes / (1024 ** 3)).toFixed(1);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
catch { /* ignore */ }
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
|
|
76
195
|
/**
|
|
77
196
|
* Безопасно перенести/слить старую папку `src` в `dest` без потери файлов.
|
|
78
197
|
* На одном томе использует мгновенный `renameSync`; при занятых файлах (`EBUSY`) не падает.
|