odant-work 1.0.93 → 1.0.95
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 +618 -649
- package/$server/$folder/$class/$ai/class.js +1 -0
- package/$server/$folder/$class/$ai/handlers/pages/form/system/ai/$handler/class.js +4 -1
- package/$server/$folder/$class/$data/$catalog/$virtual/class.js +1 -0
- package/$server/$folder/$class/$data/$catalog/class.js +1 -0
- package/$server/$folder/$class/$data/$operation/class.js +1 -0
- package/$server/$folder/$class/$data/$register/$account/class.js +1 -0
- package/$server/$folder/$class/$data/$register/class.js +1 -0
- package/$server/$folder/$class/$data/$struct/class.js +1 -0
- package/$server/$folder/$class/$domain/class.js +1 -0
- package/$server/$folder/$class/$module/$mcp/class.js +1 -0
- package/$server/$folder/$class/$module/$provider/class.js +1 -0
- package/$server/$folder/$class/$module/$provider/handlers/pages/form/system/ai/$handler/class.js +38 -6
- package/$server/$folder/$class/$module/class.js +1 -0
- package/$server/$folder/$class/$structure/$project/class.js +1 -0
- package/$server/$folder/$class/$structure/$server/class.js +1 -0
- package/$server/$folder/$class/$structure/$user/class.js +2 -0
- package/$server/$folder/$class/$structure/class.js +1 -0
- package/$server/$folder/$class/$structure/handlers/pages/form/chat/$handler/chat-task.js +20 -6
- package/$server/$folder/$class/$structure/handlers/pages/form/chat/$handler/class.js +23 -17
- package/$server/$folder/$class/$structure/handlers/pages/form/system/agent/$handler/class.js +35 -3
- package/$server/$folder/$class/$structure/handlers/pages/form/system/messengers/$handler/class.js +38 -3
- package/$server/$folder/$class/$users/class.js +1 -0
- package/$server/$folder/$class/handlers/pages/form/system/requisites/$handler/class.js +95 -24
- package/$server/$folder/$class/handlers/pages/storage/$handler/class.js +22 -4
- package/$server/$folder/$file/$task/handlers/pages/form/file/$handler/class.js +4 -3
- package/$server/$folder/handlers/pages/form/$handler/class.js +167 -13
- package/$server/$folder/lib/explorer/explorer.js +2 -1
- package/$server/$folder/lib/icon/icon.js +2 -2
- package/$server/$folder/lib/node/node.js +3 -11
- package/$server/$folder/lib/prompt-bar/prompt-bar.js +4 -2
- package/$server/$folder/lib/tree/tree.js +12 -1
- package/MODULES//320/224/320/260/320/275/320/275/321/213/320/265/Geo/$module/class.js +1 -0
- package/MODULES//320/234/320/276/320/264/320/265/320/273/320/270/Local/$provider/handlers/pages/form/system/engine/$handler/class.js +445 -0
- package/MODULES//320/243/321/207/321/221/321/202 /320/270 /320/277/321/200/320/276/321/206/320/265/321/201/321/201/321/213/Register/$module/class.js" +1 -0
- package/package.json +1 -1
- package/run.mjs +11 -0
- package/scripts/agent-eval.mjs +1 -1
- package/scripts/migrate-tree.mjs +9 -438
- package/sources/client/class.js +1 -1
- package/sources/host/auth-methods.js +16 -2
- package/sources/host/auto-updater.js +34 -24
- package/sources/host/tree-migration.js +580 -0
- package/sources/host/tree-migration.json +85 -0
- package/sources/modules/agent/index.js +23 -10
- package/sources/modules/agent/session.js +22 -2
- package/sources/modules/agent/tools/meta.js +1 -1
- package/sources/modules/agent/voice.js +6 -2
- package/sources/modules/license/index.js +53 -0
- package/sources/modules/trainer/dataset.js +6 -4
- package/sources/modules/trainer/halogen.js +9 -9
- package/sources/modules/trainer/huggingface.js +1 -1
- package/sources/modules/trainer/index.js +25 -5
- package/sources/modules/trainer/local-engine.js +17 -11
- package/sources/modules/trainer/runner.js +32 -9
- package/sources/server/class/distro.js +1 -1
- package/sources/server/class.js +8 -0
- package/sources/server/folder.js +9 -2
- package/$server/$folder/$class/$data/$catalog/$folder/$class/$data/$catalog/$virtual/class.js +0 -4
- package/$server/$folder/$class/$data/$catalog/$folder/$class/$data/$catalog/class.js +0 -4
- package/$server/$folder/$class/$data/$catalog/$virtual/$folder/$class/$data/$catalog/$virtual/class.js +0 -4
- package/$server/$folder/$class/$data/$operation/$folder/$class/$data/$operation/class.js +0 -4
- package/$server/$folder/$class/$data/$register/$account/$folder/$class/$data/$register/$account/class.js +0 -4
- package/$server/$folder/$class/$data/$register/$folder/$class/$data/$register/$account/class.js +0 -4
- package/$server/$folder/$class/$data/$register/$folder/$class/$data/$register/class.js +0 -4
- package/$server/$folder/$class/$data/$struct/$folder/$class/$data/$struct/class.js +0 -4
- package/$server/$folder/$class/$domain/$folder/$class/$domain/class.js +0 -4
- package/$server/$folder/$class/$module/$folder/$class/$data/$catalog/class.js +0 -4
- package/$server/$folder/$class/$module/$folder/$class/$data/$operation/class.js +0 -4
- package/$server/$folder/$class/$module/$folder/$class/$data/$register/class.js +0 -4
- package/$server/$folder/$class/$module/$folder/$class/$data/$struct/class.js +0 -4
- package/$server/$folder/$class/$module/$folder/$class/$domain/class.js +0 -4
- package/$server/$folder/$class/$module/$folder/$class/$module/class.js +0 -4
- package/$server/$folder/$class/$structure/$folder/$class/$structure/class.js +0 -4
- package/$server/$folder/$class/$structure/$project/$folder/$class/$data/$catalog/class.js +0 -4
- package/$server/$folder/$class/$structure/$project/$folder/$class/$data/$operation/class.js +0 -4
- package/$server/$folder/$class/$structure/$project/$folder/$class/$data/$register/class.js +0 -4
- package/$server/$folder/$class/$structure/$project/$folder/$class/$data/$struct/class.js +0 -4
- package/$server/$folder/$class/$structure/$project/$folder/$class/$domain/class.js +0 -4
- package/$server/$folder/$class/$structure/$project/$folder/$class/$structure/$project/class.js +0 -4
- package/$server/$folder/$class/$structure/$project/$folder/$class/$structure/class.js +0 -4
- package/$server/$folder/$class/$structure/$server/$folder/$class/$domain/class.js +0 -4
- package/$server/$folder/$class/$users/$folder/$class/$structure/$user/class.js +0 -4
|
@@ -0,0 +1,580 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Безопасная идемпотентная миграция дерева WORK под актуальную архитектуру (v1.0.93+):
|
|
3
|
+
* - перенос старых корней и плоских модулей по группам;
|
|
4
|
+
* - бережное слияние локальных моделей без затирания актуального провайдера;
|
|
5
|
+
* - переписывание путей в текстовых файлах и SQLite work.db.
|
|
6
|
+
*/
|
|
7
|
+
import fs from 'node:fs';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import { DatabaseSync } from 'node:sqlite';
|
|
10
|
+
|
|
11
|
+
const CFG = JSON.parse(fs.readFileSync(new URL('./tree-migration.json', import.meta.url), 'utf8'));
|
|
12
|
+
|
|
13
|
+
export const MODULE_GROUP_MAP = Object.freeze(CFG.moduleGroupMap);
|
|
14
|
+
export const STANDARD_GROUPS = Object.freeze(CFG.standardGroups);
|
|
15
|
+
|
|
16
|
+
const R = CFG.roots;
|
|
17
|
+
const G = CFG.groups;
|
|
18
|
+
const T = CFG.types;
|
|
19
|
+
const RUNTIME_SUBDIRS = new Set(CFG.runtimeSubdirs);
|
|
20
|
+
const OBSOLETE_TYPIZER_DIRS = Array.isArray(CFG.obsoleteTypizerDirs) ? CFG.obsoleteTypizerDirs : [];
|
|
21
|
+
const SKIP_TEXT_DIRS = new Set(['node_modules', '.git', '.svn', '#weights', '#runtime', '#datasets', '#cache', '#tmp', '.RAG', 'logs', 'history']);
|
|
22
|
+
|
|
23
|
+
const escapeRe = (s) => String(s).replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
24
|
+
const RE_ORG_PATH = new RegExp(`\\/${escapeRe(R.orgs)}(?=\\/|$|['"\`\\s),;\\]}])`, 'g');
|
|
25
|
+
const RE_ORG_TYPE = new RegExp(`(?<![A-Za-z0-9_])${escapeRe(T.organization)}(?![A-Za-z0-9_])`, 'g');
|
|
26
|
+
const RE_MODELS_PATH = new RegExp(`\\/${escapeRe(R.models)}(?=\\/|$|['"\`\\s),;\\]}])`, 'g');
|
|
27
|
+
const RE_MP_PATH = new RegExp(`\\/${escapeRe(R.modules)}\\/${escapeRe(G.marketplacesOld)}(?=\\/|$|['"\`\\s),;\\]}])`, 'g');
|
|
28
|
+
const MODULE_REWRITE_RULES = Object.entries(MODULE_GROUP_MAP).map(([modId, group]) => ({
|
|
29
|
+
re: new RegExp(`(\\/${escapeRe(R.modules)}\\/)${escapeRe(modId)}(?=\\/|$|['"\`\\s),;\\]}])`, 'g'),
|
|
30
|
+
replacement: `$1${group}/${modId}`,
|
|
31
|
+
}));
|
|
32
|
+
|
|
33
|
+
/** Переписать прежние WORK-пути внутри текста. */
|
|
34
|
+
export function rewriteWorkPaths(text) {
|
|
35
|
+
if (typeof text !== 'string' || !text)
|
|
36
|
+
return text;
|
|
37
|
+
let out = text;
|
|
38
|
+
out = out.replace(RE_ORG_PATH, '/' + R.projects);
|
|
39
|
+
out = out.replace(RE_ORG_TYPE, T.project);
|
|
40
|
+
out = out.replace(RE_MODELS_PATH, `/${R.modules}/${G.models}`);
|
|
41
|
+
out = out.replace(RE_MP_PATH, `/${R.modules}/${G.marketplacesNew}`);
|
|
42
|
+
for (const { re, replacement } of MODULE_REWRITE_RULES)
|
|
43
|
+
out = out.replace(re, replacement);
|
|
44
|
+
return out;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function isDirEmptyOrMetaOnly(dir) {
|
|
48
|
+
if (!fs.existsSync(dir))
|
|
49
|
+
return true;
|
|
50
|
+
return fs.readdirSync(dir, { withFileTypes: true }).length === 0;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function removeIfEmpty(dir, dryRun) {
|
|
54
|
+
if (!fs.existsSync(dir))
|
|
55
|
+
return false;
|
|
56
|
+
try {
|
|
57
|
+
if (fs.readdirSync(dir).length === 0) {
|
|
58
|
+
if (!dryRun)
|
|
59
|
+
fs.rmdirSync(dir);
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
catch { /* ignore */ }
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function mergeDirSafe(src, dst, dryRun, { overwrite = false, skipNames = null } = {}) {
|
|
68
|
+
if (!fs.existsSync(src) || src === dst)
|
|
69
|
+
return false;
|
|
70
|
+
if (dryRun)
|
|
71
|
+
return true;
|
|
72
|
+
|
|
73
|
+
if (!fs.existsSync(dst)) {
|
|
74
|
+
fs.mkdirSync(path.dirname(dst), { recursive: true });
|
|
75
|
+
try {
|
|
76
|
+
fs.renameSync(src, dst);
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
fs.cpSync(src, dst, { recursive: true });
|
|
81
|
+
fs.rmSync(src, { recursive: true, force: true });
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
let movedAny = false;
|
|
87
|
+
for (const e of fs.readdirSync(src, { withFileTypes: true })) {
|
|
88
|
+
if (skipNames && skipNames.has(e.name))
|
|
89
|
+
continue;
|
|
90
|
+
const s = path.join(src, e.name);
|
|
91
|
+
const d = path.join(dst, e.name);
|
|
92
|
+
if (e.isDirectory()) {
|
|
93
|
+
if (mergeDirSafe(s, d, dryRun, { overwrite }))
|
|
94
|
+
movedAny = true;
|
|
95
|
+
removeIfEmpty(s, dryRun);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
if (!fs.existsSync(d) || overwrite) {
|
|
99
|
+
fs.mkdirSync(path.dirname(d), { recursive: true });
|
|
100
|
+
try {
|
|
101
|
+
if (fs.existsSync(d))
|
|
102
|
+
fs.rmSync(d, { force: true });
|
|
103
|
+
fs.renameSync(s, d);
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
fs.copyFileSync(s, d);
|
|
107
|
+
fs.rmSync(s, { force: true });
|
|
108
|
+
}
|
|
109
|
+
movedAny = true;
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
try {
|
|
113
|
+
const sb = fs.readFileSync(s);
|
|
114
|
+
const db = fs.readFileSync(d);
|
|
115
|
+
if (sb.equals(db))
|
|
116
|
+
fs.rmSync(s, { force: true });
|
|
117
|
+
}
|
|
118
|
+
catch { /* оставляем на месте */ }
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
removeIfEmpty(src, dryRun);
|
|
123
|
+
return movedAny;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function migrateLocalProviderDir(srcLocalDir, dstLocalDir, dryRun) {
|
|
127
|
+
if (!fs.existsSync(srcLocalDir) || srcLocalDir === dstLocalDir)
|
|
128
|
+
return false;
|
|
129
|
+
if (dryRun)
|
|
130
|
+
return true;
|
|
131
|
+
|
|
132
|
+
fs.mkdirSync(dstLocalDir, { recursive: true });
|
|
133
|
+
let changed = false;
|
|
134
|
+
|
|
135
|
+
for (const e of fs.readdirSync(srcLocalDir, { withFileTypes: true })) {
|
|
136
|
+
const s = path.join(srcLocalDir, e.name);
|
|
137
|
+
const d = path.join(dstLocalDir, e.name);
|
|
138
|
+
if (e.name === T.provider) {
|
|
139
|
+
if (fs.existsSync(d)) {
|
|
140
|
+
for (const sub of fs.readdirSync(s, { withFileTypes: true })) {
|
|
141
|
+
if (sub.isDirectory() && RUNTIME_SUBDIRS.has(sub.name)) {
|
|
142
|
+
if (mergeDirSafe(path.join(s, sub.name), path.join(d, sub.name), dryRun))
|
|
143
|
+
changed = true;
|
|
144
|
+
}
|
|
145
|
+
else if (sub.isDirectory()) {
|
|
146
|
+
mergeDirSafe(path.join(s, sub.name), path.join(d, sub.name), dryRun, { overwrite: false });
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
for (const sub of fs.readdirSync(s, { withFileTypes: true })) {
|
|
150
|
+
if (!sub.isDirectory() && fs.existsSync(path.join(d, sub.name))) {
|
|
151
|
+
fs.rmSync(path.join(s, sub.name), { force: true });
|
|
152
|
+
}
|
|
153
|
+
else if (sub.name === 'handlers' && fs.existsSync(path.join(d, 'handlers'))) {
|
|
154
|
+
fs.rmSync(path.join(s, sub.name), { recursive: true, force: true });
|
|
155
|
+
}
|
|
156
|
+
else if (sub.name === T.folder && fs.existsSync(path.join(d, T.folder))) {
|
|
157
|
+
fs.rmSync(path.join(s, sub.name), { recursive: true, force: true });
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
removeIfEmpty(s, dryRun);
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
mergeDirSafe(s, d, dryRun);
|
|
164
|
+
changed = true;
|
|
165
|
+
}
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
if (e.isDirectory()) {
|
|
169
|
+
if (mergeDirSafe(s, d, dryRun))
|
|
170
|
+
changed = true;
|
|
171
|
+
}
|
|
172
|
+
else if (!fs.existsSync(d)) {
|
|
173
|
+
fs.renameSync(s, d);
|
|
174
|
+
changed = true;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
removeIfEmpty(srcLocalDir, dryRun);
|
|
178
|
+
return changed;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function rewriteTextFilesInDir(dir, dryRun) {
|
|
182
|
+
if (!fs.existsSync(dir))
|
|
183
|
+
return 0;
|
|
184
|
+
let changed = 0;
|
|
185
|
+
const walk = (cur) => {
|
|
186
|
+
for (const e of fs.readdirSync(cur, { withFileTypes: true })) {
|
|
187
|
+
if (SKIP_TEXT_DIRS.has(e.name))
|
|
188
|
+
continue;
|
|
189
|
+
const full = path.join(cur, e.name);
|
|
190
|
+
if (e.isDirectory()) {
|
|
191
|
+
walk(full);
|
|
192
|
+
}
|
|
193
|
+
else if (/\.(js|mjs|json|md|task)$/.test(e.name)) {
|
|
194
|
+
let stat;
|
|
195
|
+
try { stat = fs.statSync(full); }
|
|
196
|
+
catch { continue; }
|
|
197
|
+
if (stat.size > 2 * 1024 * 1024)
|
|
198
|
+
continue;
|
|
199
|
+
let orig;
|
|
200
|
+
try { orig = fs.readFileSync(full, 'utf8'); }
|
|
201
|
+
catch { continue; }
|
|
202
|
+
const next = rewriteWorkPaths(orig);
|
|
203
|
+
if (next !== orig) {
|
|
204
|
+
changed++;
|
|
205
|
+
if (!dryRun)
|
|
206
|
+
fs.writeFileSync(full, next, 'utf8');
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
walk(dir);
|
|
212
|
+
return changed;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export function migrateSqliteDb(dbPath, dryRun = false) {
|
|
216
|
+
if (!fs.existsSync(dbPath))
|
|
217
|
+
return 0;
|
|
218
|
+
if (dryRun)
|
|
219
|
+
return 1;
|
|
220
|
+
let db;
|
|
221
|
+
let updatedRows = 0;
|
|
222
|
+
try {
|
|
223
|
+
db = new DatabaseSync(dbPath);
|
|
224
|
+
db.exec('PRAGMA foreign_keys = OFF;');
|
|
225
|
+
const tables = db.prepare("SELECT name FROM sqlite_master WHERE type='table'").all()
|
|
226
|
+
.map(r => r.name)
|
|
227
|
+
.filter(n => !n.startsWith('sqlite_') && !n.startsWith('objects_fts'));
|
|
228
|
+
db.exec('BEGIN TRANSACTION;');
|
|
229
|
+
for (const tbl of tables) {
|
|
230
|
+
const cols = db.prepare(`PRAGMA table_info("${tbl}")`).all();
|
|
231
|
+
const textCols = cols.filter(c => /TEXT|CHAR|CLOB/i.test(String(c.type || ''))).map(c => c.name);
|
|
232
|
+
if (!textCols.length)
|
|
233
|
+
continue;
|
|
234
|
+
const pkCols = cols.filter(c => c.pk > 0).sort((a, b) => a.pk - b.pk).map(c => c.name);
|
|
235
|
+
const usePk = pkCols.length > 0;
|
|
236
|
+
const selectCols = usePk
|
|
237
|
+
? [...new Set([...pkCols, ...textCols])]
|
|
238
|
+
: ['rowid', ...textCols];
|
|
239
|
+
const rows = db.prepare(`SELECT ${selectCols.map(c => c === 'rowid' ? 'rowid' : `"${c}"`).join(', ')} FROM "${tbl}"`).all();
|
|
240
|
+
for (const row of rows) {
|
|
241
|
+
const sets = [];
|
|
242
|
+
const vals = [];
|
|
243
|
+
for (const col of textCols) {
|
|
244
|
+
const v = row[col];
|
|
245
|
+
if (typeof v !== 'string' || !v)
|
|
246
|
+
continue;
|
|
247
|
+
const next = rewriteWorkPaths(v);
|
|
248
|
+
if (next !== v) {
|
|
249
|
+
sets.push(`"${col}" = ?`);
|
|
250
|
+
vals.push(next);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
if (sets.length) {
|
|
254
|
+
try {
|
|
255
|
+
if (usePk) {
|
|
256
|
+
const where = pkCols.map(c => `"${c}" = ?`).join(' AND ');
|
|
257
|
+
for (const c of pkCols) vals.push(row[c]);
|
|
258
|
+
db.prepare(`UPDATE "${tbl}" SET ${sets.join(', ')} WHERE ${where}`).run(...vals);
|
|
259
|
+
}
|
|
260
|
+
else {
|
|
261
|
+
vals.push(row.rowid);
|
|
262
|
+
db.prepare(`UPDATE "${tbl}" SET ${sets.join(', ')} WHERE rowid = ?`).run(...vals);
|
|
263
|
+
}
|
|
264
|
+
updatedRows++;
|
|
265
|
+
}
|
|
266
|
+
catch (e) {
|
|
267
|
+
if (/UNIQUE/i.test(String(e?.message || ''))) {
|
|
268
|
+
if (usePk) {
|
|
269
|
+
const where = pkCols.map(c => `"${c}" = ?`).join(' AND ');
|
|
270
|
+
db.prepare(`DELETE FROM "${tbl}" WHERE ${where}`).run(...pkCols.map(c => row[c]));
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
db.prepare(`DELETE FROM "${tbl}" WHERE rowid = ?`).run(row.rowid);
|
|
274
|
+
}
|
|
275
|
+
updatedRows++;
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
throw e;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
db.exec('COMMIT;');
|
|
285
|
+
db.exec('PRAGMA foreign_keys = ON;');
|
|
286
|
+
}
|
|
287
|
+
catch { /* ignore locked sqlite */ }
|
|
288
|
+
finally {
|
|
289
|
+
try { db?.close?.(); } catch { /* ignore */ }
|
|
290
|
+
}
|
|
291
|
+
return updatedRows;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
function isMcpModuleDir(modDir) {
|
|
295
|
+
const cls = path.join(modDir, T.module, 'class.js');
|
|
296
|
+
if (!fs.existsSync(cls))
|
|
297
|
+
return false;
|
|
298
|
+
try {
|
|
299
|
+
return /\bmcp\s*:\s*\{/.test(fs.readFileSync(cls, 'utf8'));
|
|
300
|
+
}
|
|
301
|
+
catch {
|
|
302
|
+
return false;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/** Быстрая O(1) проверка — нужна ли миграция раскладки на диске. */
|
|
307
|
+
export function needsTreeMigration(rootDir = '.') {
|
|
308
|
+
const absRoot = path.resolve(rootDir);
|
|
309
|
+
if (fs.existsSync(path.join(absRoot, R.models)))
|
|
310
|
+
return true;
|
|
311
|
+
if (fs.existsSync(path.join(absRoot, R.orgs)))
|
|
312
|
+
return true;
|
|
313
|
+
for (const rel of OBSOLETE_TYPIZER_DIRS) {
|
|
314
|
+
if (fs.existsSync(path.join(absRoot, rel)))
|
|
315
|
+
return true;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
const modulesDir = path.join(absRoot, R.modules);
|
|
319
|
+
if (fs.existsSync(modulesDir)) {
|
|
320
|
+
if (fs.existsSync(path.join(modulesDir, G.marketplacesOld)) || fs.existsSync(path.join(modulesDir, G.halogen)))
|
|
321
|
+
return true;
|
|
322
|
+
if (fs.existsSync(path.join(modulesDir, G.models, G.halogen)))
|
|
323
|
+
return true;
|
|
324
|
+
try {
|
|
325
|
+
for (const e of fs.readdirSync(modulesDir, { withFileTypes: true })) {
|
|
326
|
+
if (e.isDirectory() && MODULE_GROUP_MAP[e.name])
|
|
327
|
+
return true;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
catch { /* ignore */ }
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
const projsDir = path.join(absRoot, R.projects);
|
|
334
|
+
if (fs.existsSync(projsDir)) {
|
|
335
|
+
try {
|
|
336
|
+
for (const p of fs.readdirSync(projsDir, { withFileTypes: true })) {
|
|
337
|
+
if (!p.isDirectory() || p.name.startsWith('$') || p.name.startsWith('#'))
|
|
338
|
+
continue;
|
|
339
|
+
const pDir = path.join(projsDir, p.name);
|
|
340
|
+
if (fs.existsSync(path.join(pDir, T.organization)))
|
|
341
|
+
return true;
|
|
342
|
+
const pMods = path.join(pDir, R.modules);
|
|
343
|
+
if (fs.existsSync(pMods)) {
|
|
344
|
+
for (const me of fs.readdirSync(pMods, { withFileTypes: true })) {
|
|
345
|
+
if (me.isDirectory() && MODULE_GROUP_MAP[me.name])
|
|
346
|
+
return true;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
catch { /* ignore */ }
|
|
352
|
+
}
|
|
353
|
+
return false;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Безопасная идемпотентная миграция дерева под архитектуру v1.0.93+.
|
|
358
|
+
* Не удаляет пользовательские папки, если они не опустели после переноса.
|
|
359
|
+
*/
|
|
360
|
+
export function migrateTreeSync(rootDir = '.', { dryRun = false } = {}) {
|
|
361
|
+
const absRoot = path.resolve(rootDir);
|
|
362
|
+
const report = {
|
|
363
|
+
dryRun,
|
|
364
|
+
movedModules: [],
|
|
365
|
+
movedModels: [],
|
|
366
|
+
movedOrgs: [],
|
|
367
|
+
convertedMcp: [],
|
|
368
|
+
rewrittenFiles: 0,
|
|
369
|
+
updatedDbRows: 0,
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
const modelsDir = path.join(absRoot, R.models);
|
|
373
|
+
const modulesDir = path.join(absRoot, R.modules);
|
|
374
|
+
const projsDir = path.join(absRoot, R.projects);
|
|
375
|
+
const orgsDir = path.join(absRoot, R.orgs);
|
|
376
|
+
|
|
377
|
+
const orgTypeDir = path.join(absRoot, R.server, T.folder, T.class, T.structure, T.organization);
|
|
378
|
+
const projTypeDir = path.join(absRoot, R.server, T.folder, T.class, T.structure, T.project);
|
|
379
|
+
if (fs.existsSync(orgTypeDir) && fs.existsSync(projTypeDir) && !dryRun) {
|
|
380
|
+
fs.rmSync(orgTypeDir, { recursive: true, force: true });
|
|
381
|
+
}
|
|
382
|
+
if (!dryRun) {
|
|
383
|
+
for (const rel of OBSOLETE_TYPIZER_DIRS) {
|
|
384
|
+
const abs = path.resolve(absRoot, rel);
|
|
385
|
+
if (abs.startsWith(absRoot + path.sep + R.server + path.sep) && fs.existsSync(abs))
|
|
386
|
+
fs.rmSync(abs, { recursive: true, force: true });
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
const modTypeDir = path.join(absRoot, R.server, T.folder, T.class, T.module);
|
|
391
|
+
const providerTypeDst = path.join(modTypeDir, T.provider);
|
|
392
|
+
const aiTypeDst = path.join(providerTypeDst, T.folder, T.class, T.ai);
|
|
393
|
+
const oldModelsAiTypeDir = path.join(modelsDir, T.ai);
|
|
394
|
+
if (fs.existsSync(oldModelsAiTypeDir)) {
|
|
395
|
+
const oldProviderType = path.join(oldModelsAiTypeDir, T.folder, T.class, T.provider);
|
|
396
|
+
const oldAiType = path.join(oldModelsAiTypeDir, T.folder, T.class, T.ai);
|
|
397
|
+
if (fs.existsSync(oldProviderType))
|
|
398
|
+
mergeDirSafe(oldProviderType, providerTypeDst, dryRun, { overwrite: false });
|
|
399
|
+
if (fs.existsSync(oldAiType))
|
|
400
|
+
mergeDirSafe(oldAiType, aiTypeDst, dryRun, { overwrite: false });
|
|
401
|
+
if (!dryRun && fs.existsSync(providerTypeDst))
|
|
402
|
+
fs.rmSync(oldModelsAiTypeDir, { recursive: true, force: true });
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
if (fs.existsSync(modulesDir) || fs.existsSync(modelsDir)) {
|
|
406
|
+
if (!dryRun)
|
|
407
|
+
fs.mkdirSync(modulesDir, { recursive: true });
|
|
408
|
+
for (const g of STANDARD_GROUPS) {
|
|
409
|
+
const gDir = path.join(modulesDir, g);
|
|
410
|
+
if (!fs.existsSync(gDir) && !dryRun)
|
|
411
|
+
fs.mkdirSync(gDir, { recursive: true });
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
const oldMpDir = path.join(modulesDir, G.marketplacesOld);
|
|
415
|
+
if (fs.existsSync(oldMpDir)) {
|
|
416
|
+
for (const e of fs.readdirSync(oldMpDir, { withFileTypes: true })) {
|
|
417
|
+
if (!e.isDirectory() || e.name.startsWith('$'))
|
|
418
|
+
continue;
|
|
419
|
+
if (mergeDirSafe(path.join(oldMpDir, e.name), path.join(modulesDir, G.marketplacesNew, e.name), dryRun))
|
|
420
|
+
report.movedModules.push(`${G.marketplacesOld}/${e.name} -> ${G.marketplacesNew}/${e.name}`);
|
|
421
|
+
}
|
|
422
|
+
if (!dryRun && isDirEmptyOrMetaOnly(oldMpDir))
|
|
423
|
+
fs.rmSync(oldMpDir, { recursive: true, force: true });
|
|
424
|
+
else if (!dryRun) {
|
|
425
|
+
const rest = fs.readdirSync(oldMpDir).filter(n => !n.startsWith('$'));
|
|
426
|
+
if (rest.length === 0)
|
|
427
|
+
fs.rmSync(oldMpDir, { recursive: true, force: true });
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
if (fs.existsSync(modulesDir)) {
|
|
432
|
+
for (const e of fs.readdirSync(modulesDir, { withFileTypes: true })) {
|
|
433
|
+
if (!e.isDirectory() || e.name.startsWith('$') || e.name.startsWith('#'))
|
|
434
|
+
continue;
|
|
435
|
+
if (STANDARD_GROUPS.includes(e.name))
|
|
436
|
+
continue;
|
|
437
|
+
const src = path.join(modulesDir, e.name);
|
|
438
|
+
let group = MODULE_GROUP_MAP[e.name];
|
|
439
|
+
if (!group && (e.name.startsWith('plugin-') || isMcpModuleDir(src)))
|
|
440
|
+
group = G.mcp;
|
|
441
|
+
if (!group)
|
|
442
|
+
continue;
|
|
443
|
+
const dst = path.join(modulesDir, group, e.name);
|
|
444
|
+
if (mergeDirSafe(src, dst, dryRun))
|
|
445
|
+
report.movedModules.push(`${e.name} -> ${group}/${e.name}`);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
const isLocalModelsProviderDir = (dir) => {
|
|
450
|
+
try {
|
|
451
|
+
for (const sub of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
452
|
+
if (!sub.isDirectory() || sub.name.startsWith('$') || sub.name.startsWith('#'))
|
|
453
|
+
continue;
|
|
454
|
+
const subDir = path.join(dir, sub.name);
|
|
455
|
+
if (fs.existsSync(path.join(subDir, T.ai, '#weights')) || fs.existsSync(path.join(subDir, '#weights')))
|
|
456
|
+
return true;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
catch { /* ignore */ }
|
|
460
|
+
return false;
|
|
461
|
+
};
|
|
462
|
+
const dstLocal = path.join(modulesDir, G.models, G.local);
|
|
463
|
+
if (fs.existsSync(modelsDir)) {
|
|
464
|
+
for (const e of fs.readdirSync(modelsDir, { withFileTypes: true })) {
|
|
465
|
+
if (!e.isDirectory() || e.name.startsWith('$') || e.name.startsWith('#'))
|
|
466
|
+
continue;
|
|
467
|
+
const src = path.join(modelsDir, e.name);
|
|
468
|
+
if (e.name === G.local || e.name === G.halogen || isLocalModelsProviderDir(src)) {
|
|
469
|
+
if (migrateLocalProviderDir(src, dstLocal, dryRun))
|
|
470
|
+
report.movedModels.push(`${R.models}/${e.name} -> ${R.modules}/${G.models}/${G.local}`);
|
|
471
|
+
continue;
|
|
472
|
+
}
|
|
473
|
+
const dst = path.join(modulesDir, G.models, e.name);
|
|
474
|
+
if (mergeDirSafe(src, dst, dryRun))
|
|
475
|
+
report.movedModels.push(`${R.models}/${e.name} -> ${R.modules}/${G.models}/${e.name}`);
|
|
476
|
+
}
|
|
477
|
+
removeIfEmpty(modelsDir, dryRun);
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
for (const oldHal of [path.join(modulesDir, G.halogen), path.join(modulesDir, G.models, G.halogen)]) {
|
|
481
|
+
if (fs.existsSync(oldHal)) {
|
|
482
|
+
if (migrateLocalProviderDir(oldHal, dstLocal, dryRun))
|
|
483
|
+
report.movedModels.push(`${path.relative(absRoot, oldHal)} -> ${R.modules}/${G.models}/${G.local}`);
|
|
484
|
+
removeIfEmpty(oldHal, dryRun);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
for (const g of STANDARD_GROUPS) {
|
|
489
|
+
const gDir = path.join(modulesDir, g);
|
|
490
|
+
if (!fs.existsSync(gDir))
|
|
491
|
+
continue;
|
|
492
|
+
for (const e of fs.readdirSync(gDir, { withFileTypes: true })) {
|
|
493
|
+
if (!e.isDirectory() || e.name.startsWith('$'))
|
|
494
|
+
continue;
|
|
495
|
+
const modDir = path.join(gDir, e.name);
|
|
496
|
+
if (isMcpModuleDir(modDir)) {
|
|
497
|
+
const srcMeta = path.join(modDir, T.module);
|
|
498
|
+
const dstMeta = path.join(modDir, T.mcp);
|
|
499
|
+
if (mergeDirSafe(srcMeta, dstMeta, dryRun))
|
|
500
|
+
report.convertedMcp.push(`${g}/${e.name}`);
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
if (fs.existsSync(orgsDir)) {
|
|
507
|
+
if (!dryRun)
|
|
508
|
+
fs.mkdirSync(projsDir, { recursive: true });
|
|
509
|
+
for (const e of fs.readdirSync(orgsDir, { withFileTypes: true })) {
|
|
510
|
+
if (e.name === T.domain) {
|
|
511
|
+
if (!dryRun && fs.existsSync(path.join(projsDir, T.domain)))
|
|
512
|
+
fs.rmSync(path.join(orgsDir, e.name), { recursive: true, force: true });
|
|
513
|
+
continue;
|
|
514
|
+
}
|
|
515
|
+
if (!e.isDirectory() || e.name.startsWith('$') || e.name.startsWith('#'))
|
|
516
|
+
continue;
|
|
517
|
+
const src = path.join(orgsDir, e.name);
|
|
518
|
+
const dst = path.join(projsDir, e.name);
|
|
519
|
+
if (mergeDirSafe(src, dst, dryRun)) {
|
|
520
|
+
report.movedOrgs.push(e.name);
|
|
521
|
+
const oldMeta = path.join(dst, T.organization);
|
|
522
|
+
const newMeta = path.join(dst, T.project);
|
|
523
|
+
if (fs.existsSync(oldMeta))
|
|
524
|
+
mergeDirSafe(oldMeta, newMeta, dryRun);
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
removeIfEmpty(orgsDir, dryRun);
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
if (fs.existsSync(projsDir)) {
|
|
531
|
+
for (const proj of fs.readdirSync(projsDir, { withFileTypes: true })) {
|
|
532
|
+
if (!proj.isDirectory() || proj.name.startsWith('$') || proj.name.startsWith('#'))
|
|
533
|
+
continue;
|
|
534
|
+
const pDir = path.join(projsDir, proj.name);
|
|
535
|
+
const oldMeta = path.join(pDir, T.organization);
|
|
536
|
+
const newMeta = path.join(pDir, T.project);
|
|
537
|
+
if (fs.existsSync(oldMeta))
|
|
538
|
+
mergeDirSafe(oldMeta, newMeta, dryRun);
|
|
539
|
+
|
|
540
|
+
const pMods = path.join(pDir, R.modules);
|
|
541
|
+
if (fs.existsSync(pMods)) {
|
|
542
|
+
for (const me of fs.readdirSync(pMods, { withFileTypes: true })) {
|
|
543
|
+
if (!me.isDirectory() || me.name.startsWith('$') || me.name.startsWith('#'))
|
|
544
|
+
continue;
|
|
545
|
+
if (STANDARD_GROUPS.includes(me.name))
|
|
546
|
+
continue;
|
|
547
|
+
const group = MODULE_GROUP_MAP[me.name];
|
|
548
|
+
if (group) {
|
|
549
|
+
mergeDirSafe(path.join(pMods, me.name), path.join(pMods, group, me.name), dryRun);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
const dbPath = path.join(pDir, T.project, '#system', 'work.db');
|
|
555
|
+
report.updatedDbRows += migrateSqliteDb(dbPath, dryRun);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
report.rewrittenFiles += rewriteTextFilesInDir(modulesDir, dryRun);
|
|
560
|
+
report.rewrittenFiles += rewriteTextFilesInDir(projsDir, dryRun);
|
|
561
|
+
report.rewrittenFiles += rewriteTextFilesInDir(path.join(absRoot, R.users), dryRun);
|
|
562
|
+
report.rewrittenFiles += rewriteTextFilesInDir(providerTypeDst, dryRun);
|
|
563
|
+
|
|
564
|
+
const sysSettings = path.join(absRoot, '#system', 'settings.json');
|
|
565
|
+
if (fs.existsSync(sysSettings)) {
|
|
566
|
+
const orig = fs.readFileSync(sysSettings, 'utf8');
|
|
567
|
+
const next = rewriteWorkPaths(orig);
|
|
568
|
+
if (next !== orig) {
|
|
569
|
+
report.rewrittenFiles++;
|
|
570
|
+
if (!dryRun)
|
|
571
|
+
fs.writeFileSync(sysSettings, next, 'utf8');
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
const rootDb = path.join(absRoot, '.data', 'work.db');
|
|
576
|
+
if (fs.existsSync(rootDb))
|
|
577
|
+
report.updatedDbRows += migrateSqliteDb(rootDb, dryRun);
|
|
578
|
+
|
|
579
|
+
return report;
|
|
580
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
{
|
|
2
|
+
"moduleGroupMap": {
|
|
3
|
+
"DuckDuckGo": "Поиск",
|
|
4
|
+
"SearXNG": "Поиск",
|
|
5
|
+
"Yandex": "Поиск",
|
|
6
|
+
"CBR": "Данные",
|
|
7
|
+
"DaData": "Данные",
|
|
8
|
+
"Geo": "Данные",
|
|
9
|
+
"KLADR": "Данные",
|
|
10
|
+
"RuCalendar": "Данные",
|
|
11
|
+
"Weather": "Данные",
|
|
12
|
+
"1C": "Коннекторы",
|
|
13
|
+
"2GIS": "Коннекторы",
|
|
14
|
+
"Bitrix24": "Коннекторы",
|
|
15
|
+
"Telegram": "Коннекторы",
|
|
16
|
+
"YandexDisk": "Коннекторы",
|
|
17
|
+
"Ozon": "Маркетплейсы",
|
|
18
|
+
"Wildberries": "Маркетплейсы",
|
|
19
|
+
"YandexMarket": "Маркетплейсы",
|
|
20
|
+
"Register": "Учёт и процессы",
|
|
21
|
+
"Process": "Учёт и процессы"
|
|
22
|
+
},
|
|
23
|
+
"standardGroups": [
|
|
24
|
+
"Модели",
|
|
25
|
+
"Поиск",
|
|
26
|
+
"Данные",
|
|
27
|
+
"Коннекторы",
|
|
28
|
+
"Маркетплейсы",
|
|
29
|
+
"Учёт и процессы",
|
|
30
|
+
"MCP"
|
|
31
|
+
],
|
|
32
|
+
"roots": {
|
|
33
|
+
"models": "MODELS",
|
|
34
|
+
"modules": "MODULES",
|
|
35
|
+
"orgs": "ORGANIZATIONS",
|
|
36
|
+
"projects": "PROJECTS",
|
|
37
|
+
"users": "USERS",
|
|
38
|
+
"server": "$server"
|
|
39
|
+
},
|
|
40
|
+
"groups": {
|
|
41
|
+
"models": "Модели",
|
|
42
|
+
"marketplacesOld": "Marketplaces",
|
|
43
|
+
"marketplacesNew": "Маркетплейсы",
|
|
44
|
+
"mcp": "MCP",
|
|
45
|
+
"local": "Local",
|
|
46
|
+
"halogen": "Halogen"
|
|
47
|
+
},
|
|
48
|
+
"types": {
|
|
49
|
+
"folder": "$folder",
|
|
50
|
+
"class": "$class",
|
|
51
|
+
"domain": "$domain",
|
|
52
|
+
"structure": "$structure",
|
|
53
|
+
"organization": "$organization",
|
|
54
|
+
"project": "$project",
|
|
55
|
+
"module": "$module",
|
|
56
|
+
"provider": "$provider",
|
|
57
|
+
"mcp": "$mcp",
|
|
58
|
+
"ai": "$ai"
|
|
59
|
+
},
|
|
60
|
+
"runtimeSubdirs": [
|
|
61
|
+
"#runtime",
|
|
62
|
+
"#adapters",
|
|
63
|
+
"#datasets",
|
|
64
|
+
"#cache",
|
|
65
|
+
"#tmp",
|
|
66
|
+
"#weights",
|
|
67
|
+
"#downloads"
|
|
68
|
+
],
|
|
69
|
+
"obsoleteTypizerDirs": [
|
|
70
|
+
"$server/$folder/$class/$domain/$folder",
|
|
71
|
+
"$server/$folder/$class/$module/$folder",
|
|
72
|
+
"$server/$folder/$class/$structure/$folder",
|
|
73
|
+
"$server/$folder/$class/$structure/$server/$folder",
|
|
74
|
+
"$server/$folder/$class/$structure/$project/$folder/$class/$structure",
|
|
75
|
+
"$server/$folder/$class/$structure/$project/$folder/$class/$domain",
|
|
76
|
+
"$server/$folder/$class/$structure/$project/$folder/$class/$data",
|
|
77
|
+
"$server/$folder/$class/$users/$folder",
|
|
78
|
+
"$server/$folder/$class/$data/$catalog/$folder",
|
|
79
|
+
"$server/$folder/$class/$data/$catalog/$virtual/$folder",
|
|
80
|
+
"$server/$folder/$class/$data/$register/$folder",
|
|
81
|
+
"$server/$folder/$class/$data/$register/$account/$folder",
|
|
82
|
+
"$server/$folder/$class/$data/$operation/$folder",
|
|
83
|
+
"$server/$folder/$class/$data/$struct/$folder"
|
|
84
|
+
]
|
|
85
|
+
}
|