odant-work 1.0.29 → 1.0.31
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 +36 -30
- 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 +41 -16
- package/oda/components/layouts/editor-form/editor-form.js +16 -3
- package/package.json +1 -1
- package/sources/data/progress.md +20 -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 +532 -32
- package/sources/modules/trainer/huggingface.js +86 -6
- package/sources/modules/trainer/index.js +141 -3
- package/sources/modules/trainer/local-engine.js +26 -29
- package/sources/modules/trainer/paths.js +119 -0
- package/sources/modules/trainer/providers.js +60 -36
- package/sources/modules/trainer/runner.js +142 -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,7 @@ import {
|
|
|
27
28
|
modelWeightsDir as getModelWeightsDir,
|
|
28
29
|
migrateLocalModelsLayoutSync,
|
|
29
30
|
hasReadyWeightFilesSync,
|
|
31
|
+
LINUX_ONLY_HALOGEN_EXT_RE,
|
|
30
32
|
} from './paths.js';
|
|
31
33
|
|
|
32
34
|
const HF_ORIGIN = DEFAULT_HF_ORIGIN;
|
|
@@ -70,6 +72,22 @@ export const MODEL_CAPABILITIES = Object.freeze({
|
|
|
70
72
|
*/
|
|
71
73
|
export const CURATED_HF_MODELS = Object.freeze([
|
|
72
74
|
// --- ТЕКСТ И КОД (LLM / АГЕНТЫ) ---
|
|
75
|
+
{
|
|
76
|
+
id: 'Qwen/Qwen3-0.6B',
|
|
77
|
+
author: 'Qwen',
|
|
78
|
+
modelName: 'Qwen3-0.6B (Сверхлёгкий маршрутизатор)',
|
|
79
|
+
modality: 'llm',
|
|
80
|
+
format: 'safetensors',
|
|
81
|
+
paramsB: 0.6,
|
|
82
|
+
ramRequiredGb: 1.0,
|
|
83
|
+
trainRamGb: 2.2,
|
|
84
|
+
capabilities: ['chat', 'classify', 'decide'],
|
|
85
|
+
whatItDoes: 'Мгновенная классификация запросов, маршрутизация и быстрые короткие ответы на CPU/GPU',
|
|
86
|
+
recommendedFor: 'Работает на любом ПК (<1 ГБ памяти)',
|
|
87
|
+
tags: ['qwen3', '0.6b', 'safetensors', 'fast'],
|
|
88
|
+
downloads: 190000,
|
|
89
|
+
likes: 720,
|
|
90
|
+
},
|
|
73
91
|
{
|
|
74
92
|
id: 'Qwen/Qwen3-4B',
|
|
75
93
|
author: 'Qwen',
|
|
@@ -185,19 +203,39 @@ export const CURATED_HF_MODELS = Object.freeze([
|
|
|
185
203
|
{
|
|
186
204
|
id: 'peonist-ai/halogen-qwen3.8-flash-next',
|
|
187
205
|
author: 'peonist-ai',
|
|
188
|
-
modelName: 'Qwen3.8-Flash-Next (Halogen
|
|
206
|
+
modelName: 'Qwen3.8-Flash-Next (Halogen Linux ROCm)',
|
|
189
207
|
modality: 'llm',
|
|
190
|
-
format: '
|
|
208
|
+
format: 'hgn',
|
|
209
|
+
platforms: ['linux'],
|
|
191
210
|
paramsB: 180,
|
|
192
|
-
ramRequiredGb:
|
|
211
|
+
ramRequiredGb: 112.0,
|
|
193
212
|
trainRamGb: 138.0,
|
|
194
213
|
capabilities: ['chat', 'tools', 'thinking', 'coding', 'vision'],
|
|
195
|
-
whatItDoes: 'Флагманская модель 180B MoE (4.16 bpw + FP8 lookup table) для
|
|
196
|
-
recommendedFor: '
|
|
214
|
+
whatItDoes: 'Флагманская модель 180B MoE (4.16 bpw + FP8 lookup table) для Linux Strix Halo (halogen-flash-server): 73–94 tok/s decode, 1800 tok/s prefill',
|
|
215
|
+
recommendedFor: 'Только для Linux ПАК WORK на AMD Ryzen AI 495 Pro 192 ГБ RAM',
|
|
197
216
|
tags: ['qwen3', 'qwen3.8', 'halogen', 'strix-halo', 'ryzen-ai', 'gfx1151', 'moe', 'tool-calling', 'vision'],
|
|
198
217
|
downloads: 128000,
|
|
199
218
|
likes: 1890,
|
|
200
219
|
},
|
|
220
|
+
{
|
|
221
|
+
id: 'unsloth/Qwen3.8-Flash-Next-GGUF',
|
|
222
|
+
author: 'unsloth',
|
|
223
|
+
modelName: 'Qwen3.8-Flash-Next (180B MoE · Windows Halowin Bubo)',
|
|
224
|
+
modality: 'llm',
|
|
225
|
+
format: 'gguf',
|
|
226
|
+
platforms: ['win32'],
|
|
227
|
+
buboPackage: true,
|
|
228
|
+
haloNodeName: 'Qwen3.8-Flash-Next',
|
|
229
|
+
paramsB: 180,
|
|
230
|
+
ramRequiredGb: 116.6,
|
|
231
|
+
trainRamGb: 150.0,
|
|
232
|
+
capabilities: ['chat', 'tools', 'thinking', 'coding', 'vision'],
|
|
233
|
+
whatItDoes: 'Флагманская модель 180B MoE (UD-Q4_K_XL + MTP + Dense Twin + Vision) для Windows 11 Strix Halo через встроенный движок Halowin Bubo (ROCm 10.0 gfx1151)',
|
|
234
|
+
recommendedFor: 'Оптимально для Windows 11 на AMD Ryzen AI Max+ PRO 495 (128–192 ГБ)',
|
|
235
|
+
tags: ['qwen3', 'qwen3.8', 'gguf', 'bubo', 'strix-halo', 'ryzen-ai', 'gfx1151', 'moe', 'tool-calling', 'vision'],
|
|
236
|
+
downloads: 142000,
|
|
237
|
+
likes: 1950,
|
|
238
|
+
},
|
|
201
239
|
{
|
|
202
240
|
id: 'Qwen/Qwen3-235B-A22B-GGUF',
|
|
203
241
|
author: 'Qwen',
|
|
@@ -704,6 +742,7 @@ export async function searchHuggingFaceModels({
|
|
|
704
742
|
limit = 25,
|
|
705
743
|
token = '',
|
|
706
744
|
usableMemoryGb = 24,
|
|
745
|
+
platform = os.platform(),
|
|
707
746
|
rootDir = process.cwd(),
|
|
708
747
|
endpointUrl,
|
|
709
748
|
proxyUrl,
|
|
@@ -716,6 +755,10 @@ export async function searchHuggingFaceModels({
|
|
|
716
755
|
const fLower = String(filter || '').trim().toLowerCase();
|
|
717
756
|
|
|
718
757
|
const curatedMatches = CURATED_HF_MODELS.filter(m => {
|
|
758
|
+
if (Array.isArray(m.platforms) && m.platforms.length && !m.platforms.includes(platform))
|
|
759
|
+
return false;
|
|
760
|
+
if (platform === 'win32' && (m.format === 'hgn' || m.format === 'hnpw' || /^peonist-ai\/halogen-/i.test(m.id)))
|
|
761
|
+
return false;
|
|
719
762
|
if (modLower && modLower !== 'all' && m.modality !== modLower)
|
|
720
763
|
return false;
|
|
721
764
|
if (capLower && capLower !== 'all' && !(m.capabilities || []).includes(capLower))
|
|
@@ -778,8 +821,10 @@ export async function searchHuggingFaceModels({
|
|
|
778
821
|
const id = String(row.id || row.modelId || '').trim();
|
|
779
822
|
if (!id || seen.has(id))
|
|
780
823
|
continue;
|
|
781
|
-
seen.add(id);
|
|
782
824
|
const tags = Array.isArray(row.tags) ? row.tags : [];
|
|
825
|
+
if (platform === 'win32' && (/^peonist-ai\/halogen-/i.test(id) || tags.includes('halogen') || tags.includes('halogen-flash')))
|
|
826
|
+
continue;
|
|
827
|
+
seen.add(id);
|
|
783
828
|
const isGguf = tags.includes('gguf') || /gguf/i.test(id);
|
|
784
829
|
const format = isGguf ? 'gguf' : 'safetensors';
|
|
785
830
|
const est = estimateModelMemoryFromId(id, format);
|
|
@@ -963,6 +1008,21 @@ export function selectFilesToDownload(repoMeta, { files = null, quant = '' } = {
|
|
|
963
1008
|
const q4 = ggufs.filter(f => f.quant === 'Q4_K_M' || /Q4_K_M/i.test(f.name));
|
|
964
1009
|
return q4.length ? q4 : [ggufs[0]];
|
|
965
1010
|
}
|
|
1011
|
+
// Для репозиториев Halogen (.hgn) не качаем устаревшие дублирующие чекпоинты (w4b, ht43, mtp) —
|
|
1012
|
+
// выбираем только актуальный v2 + ngram + drafter-r2 + vision + конфиги/токенизатор (~112 ГБ вместо 308 ГБ).
|
|
1013
|
+
const hgnFiles = all.filter(f => f.name.toLowerCase().endsWith('.hgn'));
|
|
1014
|
+
if (hgnFiles.length) {
|
|
1015
|
+
const hasV2 = hgnFiles.some(f => /v2\.hgn$/i.test(f.name));
|
|
1016
|
+
if (hasV2) {
|
|
1017
|
+
return all.filter(f => {
|
|
1018
|
+
const low = f.name.toLowerCase();
|
|
1019
|
+
if (low.endsWith('.hgn')) {
|
|
1020
|
+
return /-(v2|ngram|drafter-r2|vision)\.hgn$/i.test(low);
|
|
1021
|
+
}
|
|
1022
|
+
return f.kind === 'config' || low.includes('tokenizer') || low === 'vocab.json' || low === 'merges.txt' || low.endsWith('.jinja');
|
|
1023
|
+
});
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
966
1026
|
return all.filter(f => f.kind === 'config' || f.kind === 'safetensors');
|
|
967
1027
|
}
|
|
968
1028
|
|
|
@@ -1153,6 +1213,7 @@ export async function startHuggingFaceDownload({
|
|
|
1153
1213
|
quant = 'Q8_0',
|
|
1154
1214
|
revision = 'main',
|
|
1155
1215
|
token = '',
|
|
1216
|
+
platform = os.platform(),
|
|
1156
1217
|
rootDir = process.cwd(),
|
|
1157
1218
|
providerFolder = 'Local',
|
|
1158
1219
|
targetNodeName = '',
|
|
@@ -1171,6 +1232,10 @@ export async function startHuggingFaceDownload({
|
|
|
1171
1232
|
const cleanId = validateRepoId(repoId);
|
|
1172
1233
|
const safeProvider = String(providerFolder || 'Local').replace(/[<>:"/\\|?*]/g, '-');
|
|
1173
1234
|
|
|
1235
|
+
if (platform === 'win32' && /^peonist-ai\/halogen-/i.test(cleanId)) {
|
|
1236
|
+
throw new Error(`Репозиторий ${cleanId} содержит веса формата Linux (.hgn/.hnpw), которые не поддерживаются на Windows. Для Windows используйте нативный стек Halowin Bubo (GGUF) или .safetensors.`);
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1174
1239
|
// Если эта модель уже скачивается прямо сейчас — возвращаем активную задачу без дублирования
|
|
1175
1240
|
for (const entry of _downloads.values()) {
|
|
1176
1241
|
if (
|
|
@@ -1202,6 +1267,12 @@ export async function startHuggingFaceDownload({
|
|
|
1202
1267
|
if (!selected.length)
|
|
1203
1268
|
throw new Error(`В репозитории ${cleanId} не найдено подходящих файлов весов (.gguf / .safetensors)`);
|
|
1204
1269
|
|
|
1270
|
+
const hasLinuxOnlyWeights = selected.some(f => LINUX_ONLY_HALOGEN_EXT_RE.test(f.name));
|
|
1271
|
+
const hasCrossPlatformWeights = selected.some(f => /\.(gguf|safetensors)$/i.test(f.name));
|
|
1272
|
+
if (platform === 'win32' && hasLinuxOnlyWeights && !hasCrossPlatformWeights) {
|
|
1273
|
+
throw new Error(`В репозитории ${cleanId} найдены только веса Linux (.hgn/.hnpw), несовместимые с Windows.`);
|
|
1274
|
+
}
|
|
1275
|
+
|
|
1205
1276
|
const folderName = targetNodeName
|
|
1206
1277
|
? String(targetNodeName).replace(/[<>:"/\\|?*]/g, '-')
|
|
1207
1278
|
: safeModelFolderName(cleanId, quant && selected.some(f => f.kind === 'gguf') ? quant : '');
|
|
@@ -1886,6 +1957,15 @@ export async function resumeInterruptedDownloads({
|
|
|
1886
1957
|
catch { continue; }
|
|
1887
1958
|
if (state?.status !== 'downloading' || !state?.repoId)
|
|
1888
1959
|
continue;
|
|
1960
|
+
if (os.platform() === 'win32' && /^peonist-ai\/halogen-/i.test(String(state.repoId))) {
|
|
1961
|
+
try {
|
|
1962
|
+
state.status = 'failed';
|
|
1963
|
+
state.error = 'Веса формата Linux (.hgn/.hnpw) не поддерживаются на Windows. Сбросьте эту загрузку и установите Windows-версию (Halowin Bubo GGUF).';
|
|
1964
|
+
fs.writeFileSync(stateFile, JSON.stringify(state, null, 2), 'utf-8');
|
|
1965
|
+
}
|
|
1966
|
+
catch { /* ignore */ }
|
|
1967
|
+
continue;
|
|
1968
|
+
}
|
|
1889
1969
|
try {
|
|
1890
1970
|
const job = await resumeHuggingFaceDownload({
|
|
1891
1971
|
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,
|
|
@@ -51,7 +54,10 @@ import {
|
|
|
51
54
|
HALOGEN_IMAGE_TAG,
|
|
52
55
|
BUBO_WINDOWS_RELEASE,
|
|
53
56
|
HALOGEN_MODELS_CATALOG,
|
|
57
|
+
HALOGEN_WINDOWS_COMPANIONS,
|
|
54
58
|
HALOGEN_TTS_VOICES,
|
|
59
|
+
getHalogenCatalogForPlatform,
|
|
60
|
+
checkWindowsHalogenPreflight,
|
|
55
61
|
recordHalogenSessionHandle,
|
|
56
62
|
listHalogenSessionHandles,
|
|
57
63
|
releaseHalogenSessionHandle,
|
|
@@ -62,6 +68,7 @@ import {
|
|
|
62
68
|
probeHalogenServer,
|
|
63
69
|
startHalogenBackend,
|
|
64
70
|
stopHalogenBackend,
|
|
71
|
+
ensureHalogenBackendRunning,
|
|
65
72
|
synthesizeFallbackWav,
|
|
66
73
|
computeFallbackEmbeddings,
|
|
67
74
|
computeFallbackRerank,
|
|
@@ -108,6 +115,11 @@ import {
|
|
|
108
115
|
listTransferJobs,
|
|
109
116
|
cancelTransferJob,
|
|
110
117
|
} from './transfer.js';
|
|
118
|
+
import {
|
|
119
|
+
inspectWeightsDirectorySync,
|
|
120
|
+
modelWeightsDir,
|
|
121
|
+
LINUX_ONLY_HALOGEN_EXT_RE,
|
|
122
|
+
} from './paths.js';
|
|
111
123
|
|
|
112
124
|
export const halogenFallback = Object.freeze({
|
|
113
125
|
normalizeHalogenTtsPayload,
|
|
@@ -150,7 +162,10 @@ export {
|
|
|
150
162
|
HALOGEN_IMAGE_TAG,
|
|
151
163
|
BUBO_WINDOWS_RELEASE,
|
|
152
164
|
HALOGEN_MODELS_CATALOG,
|
|
165
|
+
HALOGEN_WINDOWS_COMPANIONS,
|
|
153
166
|
HALOGEN_TTS_VOICES,
|
|
167
|
+
getHalogenCatalogForPlatform,
|
|
168
|
+
checkWindowsHalogenPreflight,
|
|
154
169
|
recordHalogenSessionHandle,
|
|
155
170
|
listHalogenSessionHandles,
|
|
156
171
|
releaseHalogenSessionHandle,
|
|
@@ -161,6 +176,7 @@ export {
|
|
|
161
176
|
probeHalogenServer,
|
|
162
177
|
startHalogenBackend,
|
|
163
178
|
stopHalogenBackend,
|
|
179
|
+
ensureHalogenBackendRunning,
|
|
164
180
|
synthesizeFallbackWav,
|
|
165
181
|
computeFallbackEmbeddings,
|
|
166
182
|
computeFallbackRerank,
|
|
@@ -310,9 +326,16 @@ export const TRAINER_METHODS = Object.freeze({
|
|
|
310
326
|
totalRamGb: hardware?.totalRamGb >= 120 ? hardware.totalRamGb : 192,
|
|
311
327
|
platform: hardware?.platform,
|
|
312
328
|
});
|
|
329
|
+
const platform = hardware?.platform || os.platform();
|
|
330
|
+
const probe = await probeHalogenServer(HALOGEN_DEFAULT_BASE_URL).catch(() => null);
|
|
313
331
|
const runtime = getLocalEngineStatus({
|
|
314
332
|
totalRamGb: hardware?.totalRamGb,
|
|
333
|
+
halogenOnline: Boolean(probe?.online),
|
|
315
334
|
});
|
|
335
|
+
const curatedCompatible = CURATED_HF_MODELS.filter(m =>
|
|
336
|
+
(!Array.isArray(m.platforms) || !m.platforms.length || m.platforms.includes(platform))
|
|
337
|
+
&& !(platform === 'win32' && (m.format === 'hgn' || m.format === 'hnpw'))
|
|
338
|
+
);
|
|
316
339
|
return {
|
|
317
340
|
hardware,
|
|
318
341
|
runtime,
|
|
@@ -325,16 +348,129 @@ export const TRAINER_METHODS = Object.freeze({
|
|
|
325
348
|
network: sanitizeTrainerNetworkForClient(loadTrainerNetworkSettings()),
|
|
326
349
|
modalities: MODEL_MODALITIES,
|
|
327
350
|
capabilities: Object.values(MODEL_CAPABILITIES),
|
|
328
|
-
curated:
|
|
351
|
+
curated: curatedCompatible,
|
|
329
352
|
halogen: {
|
|
353
|
+
online: Boolean(probe?.online),
|
|
354
|
+
mode: probe?.mode || '',
|
|
355
|
+
modeLabel: probe?.modeLabel || '',
|
|
330
356
|
memoryPlan: halogenPlan,
|
|
331
|
-
catalog: inspectHalogenCatalogWithStatus(),
|
|
357
|
+
catalog: inspectHalogenCatalogWithStatus(process.cwd(), { platform }),
|
|
332
358
|
handles: listHalogenSessionHandles(),
|
|
333
|
-
windowsEnv: inspectWindowsHalogenEnvironment(),
|
|
359
|
+
windowsEnv: probe?.windowsEnv || inspectWindowsHalogenEnvironment(),
|
|
334
360
|
},
|
|
335
361
|
};
|
|
336
362
|
},
|
|
337
363
|
},
|
|
364
|
+
trainer_model_info: {
|
|
365
|
+
level: 'read',
|
|
366
|
+
fn: async function () {
|
|
367
|
+
await this?.init;
|
|
368
|
+
const d = this?.DATA || {};
|
|
369
|
+
const itemPath = String(this?.path || this?.short || '');
|
|
370
|
+
const parts = itemPath.split('/').filter(Boolean);
|
|
371
|
+
const providerId = parts[1] || 'MODELS';
|
|
372
|
+
const isLocal = providerId === 'Local' || d.protocol === 'local' || d.protocol === 'halogen';
|
|
373
|
+
const act = evaluateAiNodeActivitySync(this);
|
|
374
|
+
|
|
375
|
+
let weightInfo = null;
|
|
376
|
+
let halogenProbe = null;
|
|
377
|
+
let sizeGb = 0;
|
|
378
|
+
let needsRuntime = false;
|
|
379
|
+
|
|
380
|
+
if (isLocal) {
|
|
381
|
+
const wDirRel = d.weightsDir || path.join('MODELS', 'Local', this?.id || '', '$ai', '#weights');
|
|
382
|
+
const wDirAbs = path.resolve(process.cwd(), wDirRel);
|
|
383
|
+
weightInfo = inspectWeightsDirectorySync(wDirAbs, os.platform());
|
|
384
|
+
if (weightInfo.exists) {
|
|
385
|
+
let bytes = 0;
|
|
386
|
+
for (const f of weightInfo.files) {
|
|
387
|
+
try {
|
|
388
|
+
bytes += fs.statSync(path.join(wDirAbs, f)).size || 0;
|
|
389
|
+
}
|
|
390
|
+
catch { /* ignore */ }
|
|
391
|
+
}
|
|
392
|
+
sizeGb = +(bytes / (1024 ** 3)).toFixed(2);
|
|
393
|
+
}
|
|
394
|
+
if (d.protocol === 'halogen' || weightInfo?.hasGguf || weightInfo?.hasBuboManifest) {
|
|
395
|
+
halogenProbe = await probeHalogenServer(d.baseUrl || HALOGEN_DEFAULT_BASE_URL).catch(() => null);
|
|
396
|
+
const winEnv = halogenProbe?.windowsEnv || inspectWindowsHalogenEnvironment();
|
|
397
|
+
if (os.platform() === 'win32' && !halogenProbe?.online && !winEnv.buboInstalled && !winEnv.gufoInstalled) {
|
|
398
|
+
needsRuntime = true;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
return {
|
|
404
|
+
id: this?.id || '',
|
|
405
|
+
label: d.label || this?.label || this?.id || '',
|
|
406
|
+
icon: d.icon || this?.icon || 'carbon:machine-learning-model',
|
|
407
|
+
path: itemPath,
|
|
408
|
+
providerName: providerId,
|
|
409
|
+
isLocal,
|
|
410
|
+
protocol: d.protocol || (isLocal ? 'local' : 'openai'),
|
|
411
|
+
model: d.model || this?.id || '',
|
|
412
|
+
baseUrl: d.baseUrl || '',
|
|
413
|
+
modality: d.modality || 'llm',
|
|
414
|
+
maxTokens: Number(d.maxTokens || d.$public?.maxTokens) || 32768,
|
|
415
|
+
maxOutput: Number(d.maxOutput || d.$public?.maxOutput) || 8192,
|
|
416
|
+
capabilities: Array.isArray(d.capabilities) ? d.capabilities : (d.$public?.capabilities || ['chat', 'stream']),
|
|
417
|
+
efforts: Array.isArray(d.efforts) ? d.efforts : [],
|
|
418
|
+
weightsDir: d.weightsDir || '',
|
|
419
|
+
primaryFile: d.primaryFile || '',
|
|
420
|
+
enabled: d.enabled !== false,
|
|
421
|
+
aiActive: act.active,
|
|
422
|
+
aiStatusReason: act.reason,
|
|
423
|
+
weightFormat: weightInfo?.weightFormat || '',
|
|
424
|
+
incompatibleOnPlatform: Boolean(act.incompatibleOnPlatform || weightInfo?.incompatibleOnPlatform),
|
|
425
|
+
incompatibleReason: act.incompatibleOnPlatform ? act.reason : (weightInfo?.incompatibleReason || ''),
|
|
426
|
+
sizeGb,
|
|
427
|
+
needsRuntime,
|
|
428
|
+
halogenOnline: Boolean(halogenProbe?.online),
|
|
429
|
+
halogenMode: halogenProbe?.mode || '',
|
|
430
|
+
halogenModeLabel: halogenProbe?.modeLabel || '',
|
|
431
|
+
windowsEnv: halogenProbe?.windowsEnv || null,
|
|
432
|
+
};
|
|
433
|
+
},
|
|
434
|
+
},
|
|
435
|
+
trainer_delete_incompatible: {
|
|
436
|
+
level: 'admin',
|
|
437
|
+
fn: async function (p = {}) {
|
|
438
|
+
await this?.init;
|
|
439
|
+
const modelId = p.modelId || p.id || this?.id || '';
|
|
440
|
+
const cleanId = String(modelId).replace(/^\/?MODELS\/Local\//i, '').replace(/[<>:"/\\|?*]/g, '').trim();
|
|
441
|
+
if (!cleanId)
|
|
442
|
+
throw new Error('Не указана модель');
|
|
443
|
+
const wDir = modelWeightsDir(process.cwd(), cleanId, 'Local');
|
|
444
|
+
const info = inspectWeightsDirectorySync(wDir, os.platform());
|
|
445
|
+
if (info.exists && !info.hasGguf && !info.hasSafetensors && !info.hasBuboManifest) {
|
|
446
|
+
const res = await deleteLocalModel({ modelId: cleanId });
|
|
447
|
+
try {
|
|
448
|
+
const localNode = await globalThis.WORK?.get_item?.('/MODELS/Local');
|
|
449
|
+
localNode?.reset?.();
|
|
450
|
+
const modelsRoot = await globalThis.WORK?.get_item?.('/MODELS');
|
|
451
|
+
modelsRoot?.reset?.();
|
|
452
|
+
}
|
|
453
|
+
catch { /* ignore */ }
|
|
454
|
+
return { ...res, mode: 'deleted_model' };
|
|
455
|
+
}
|
|
456
|
+
let removedCount = 0;
|
|
457
|
+
if (fs.existsSync(wDir)) {
|
|
458
|
+
for (const f of fs.readdirSync(wDir)) {
|
|
459
|
+
if (LINUX_ONLY_HALOGEN_EXT_RE.test(f) || (LINUX_ONLY_HALOGEN_EXT_RE.test(f.replace(/\.part$/i, '')))) {
|
|
460
|
+
fs.rmSync(path.join(wDir, f), { force: true });
|
|
461
|
+
removedCount++;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
try {
|
|
466
|
+
this?.reset?.();
|
|
467
|
+
const localNode = await globalThis.WORK?.get_item?.('/MODELS/Local');
|
|
468
|
+
localNode?.reset?.();
|
|
469
|
+
}
|
|
470
|
+
catch { /* ignore */ }
|
|
471
|
+
return { ok: true, removedCount, mode: 'removed_files' };
|
|
472
|
+
},
|
|
473
|
+
},
|
|
338
474
|
trainer_delete_model: {
|
|
339
475
|
level: 'admin',
|
|
340
476
|
fn: async function (p = {}) {
|
|
@@ -395,10 +531,12 @@ export const TRAINER_METHODS = Object.freeze({
|
|
|
395
531
|
halogen_download_bundle: {
|
|
396
532
|
level: 'admin',
|
|
397
533
|
fn: async function (p = {}) {
|
|
534
|
+
const hw = await detectHardware().catch(() => null);
|
|
398
535
|
const res = await downloadHalogenBundle({
|
|
399
536
|
models: p.models || p.nodeName || p.model || null,
|
|
400
537
|
token: p.token || '',
|
|
401
538
|
waitForCompletion: p.wait === true || p.wait === 'true',
|
|
539
|
+
totalMemoryGb: hw?.totalRamGb ?? null,
|
|
402
540
|
});
|
|
403
541
|
try {
|
|
404
542
|
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;
|
|
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`) не падает.
|