odant-work 1.0.101 → 1.0.103
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/$server/$folder/$class/$structure/$department/ai/config.js +9 -0
- package/$server/$folder/$class/$structure/$department/ai/system.md +11 -0
- package/$server/$folder/$class/$structure/$department/class.js +9 -0
- package/$server/$folder/$class/$structure/$project/ai/config.js +9 -0
- package/$server/$folder/$class/$structure/$project/ai/system.md +12 -0
- package/$server/$folder/$class/$structure/$project/class.js +4 -1
- package/$server/$folder/$class/$structure/$project/handlers/pages/site/$handler/class.js +1 -1
- package/$server/$folder/$class/$structure/$server/ai/config.js +9 -0
- package/$server/$folder/$class/$structure/$server/ai/system.md +10 -0
- package/$server/$folder/$class/$structure/$server/class.js +2 -0
- package/$server/$folder/$class/$structure/$user/ai/config.js +9 -0
- package/$server/$folder/$class/$structure/$user/ai/system.md +8 -0
- package/$server/$folder/$class/$structure/$user/class.js +2 -0
- package/$server/$folder/$class/$structure/ai/system.md +1 -1
- package/$server/$folder/$class/$structure/class.js +4 -2
- package/$server/$folder/$class/$structure/handlers/pages/form/chat/$handler/chat-task.js +17 -6
- package/$server/$folder/$class/$structure/handlers/pages/form/chat/$handler/class.js +91 -22
- package/$server/$folder/$class/$structure/handlers/pages/form/system/agent/$handler/class.js +132 -3
- package/$server/$folder/$class/$structure/handlers/pages/form/system/staff/$handler/class.js +2 -2
- package/$server/$folder/$class/$structure/handlers/pages/site/$handler/class.js +2 -1
- package/$server/$folder/$class/ai/system.md +2 -2
- package/$server/$folder/$file/$task/handlers/pages/form/file/$handler/class.js +38 -8
- package/$server/$folder/$file/$task/handlers/pages/form/file/$handler/ui/dock.js +22 -31
- package/$server/$folder/$file/$task/handlers/pages/form/file/$handler/ui/util.js +32 -0
- package/$server/$folder/handlers/pages/form/$handler/class.js +47 -5
- package/$server/$folder/lib/chat-item/chat-item.js +14 -2
- package/$server/$folder/lib/consultant/consultant.js +81 -4
- package/$server/$folder/lib/explorer/explorer.js +20 -11
- package/$server/$folder/lib/icon/icon.js +1 -1
- package/$server/$folder/lib/node/node.js +3 -3
- package/$server/$folder/lib/site-loc/site-loc.js +8 -3
- package/$server/$folder/lib/tree/tree.js +8 -8
- package/AGENTS.md +3 -3
- package/autostart.bat +28 -0
- package/autostart.sh +17 -0
- package/package.json +1 -1
- package/run.mjs +19 -0
- package/scripts/autostart.mjs +281 -0
- package/scripts/import-bis.mjs +5 -5
- package/scripts/import-delovaya.mjs +5 -5
- package/scripts/watchdog.mjs +496 -0
- package/sources/client/class.js +1 -1
- package/sources/client.js +141 -8
- package/sources/data/api.js +1 -1
- package/sources/data/classes.js +2 -1
- package/sources/data/schema.js +2 -0
- package/sources/host/auth-methods.js +3 -1
- package/sources/host/auto-updater.js +23 -1
- package/sources/host/http-server.js +5 -3
- package/sources/host/push.js +43 -14
- package/sources/host/websocket.js +52 -3
- package/sources/modules/agent/index.js +38 -10
- package/sources/modules/agent/node-rules.js +353 -9
- package/sources/modules/agent/scheduler.js +7 -0
- package/sources/modules/agent/scope.js +8 -6
- package/sources/modules/agent/session.js +38 -8
- package/sources/modules/agent/tools/work/access.js +1 -1
- package/sources/modules/agent/tools/work/classes.js +1 -1
- package/sources/modules/agent/triggers.js +1 -1
- package/sources/modules/agent/twin-bus.js +2 -1
- package/sources/modules/notify/index.js +5 -2
- package/sources/modules/trainer/local-engine.js +3 -1
- package/sources/modules/user-profile/user-profile.js +129 -0
- package/sources/server/access/gateway.js +5 -3
- package/sources/server/access/links.js +9 -6
- package/sources/server/chat-threads.js +1 -1
- package/sources/server/class/base-template.js +3 -2
- package/sources/server/class/feed.js +36 -0
- package/sources/server/class/scaffold.js +137 -0
- package/sources/server/class/search.js +2 -2
- package/sources/server/class/security.js +1 -1
- package/sources/server/class.js +5 -3
- package/sources/server/folder.js +10 -6
- package/sources/server/logs.js +14 -0
- package/sources/server/node.js +1 -1
- package/sources/server/server.js +50 -1
- package/sources/server/user.js +45 -0
- package/sources/work.js +7 -0
- package/start.bat +25 -0
- package/start.sh +27 -0
- package/stop.bat +25 -0
- package/stop.sh +16 -0
- package/sw.js +3 -11
package/sources/server/node.js
CHANGED
|
@@ -107,7 +107,7 @@ export class $node extends $class {
|
|
|
107
107
|
if (t === '$virtual') return 'virtual';
|
|
108
108
|
if (t === '$register') return 'sheet';
|
|
109
109
|
if (t === '$account') return 'postings';
|
|
110
|
-
if (t === '$project' || t === '$structure') return 'chat';
|
|
110
|
+
if (t === '$project' || t === '$structure' || this.DATA?.isDepartment) return 'chat';
|
|
111
111
|
if (t === '$file') return 'file';
|
|
112
112
|
}
|
|
113
113
|
return undefined;
|
package/sources/server/server.js
CHANGED
|
@@ -284,6 +284,41 @@ export class $server extends $class {
|
|
|
284
284
|
throw new Error('push: требуется вход');
|
|
285
285
|
}
|
|
286
286
|
|
|
287
|
+
async _resolveSelfUserItem(params = {}) {
|
|
288
|
+
const uid = $class.resolveUid(params);
|
|
289
|
+
if (!uid)
|
|
290
|
+
throw new Error('Требуется вход');
|
|
291
|
+
const usersRoot = await this.$users;
|
|
292
|
+
const list = await usersRoot?.items;
|
|
293
|
+
const found = Array.isArray(list) ? list.find(u => u?.id === uid) : null;
|
|
294
|
+
return found || await usersRoot?.get_item?.(uid).catch(() => null) || null;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
async user_settings_get(params = {}) {
|
|
298
|
+
const uItem = await this._resolveSelfUserItem(params);
|
|
299
|
+
if (!uItem)
|
|
300
|
+
return { chatSound: true, aiModel: '' };
|
|
301
|
+
await uItem.init;
|
|
302
|
+
const raw = uItem.DATA?.settings;
|
|
303
|
+
return {
|
|
304
|
+
chatSound: raw?.chatSound !== false,
|
|
305
|
+
aiModel: typeof raw?.aiModel === 'string' ? raw.aiModel : '',
|
|
306
|
+
...(raw && typeof raw === 'object' ? raw : {}),
|
|
307
|
+
...(raw?.chatSound === undefined ? { chatSound: true } : {}),
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
async user_settings_save(params = {}) {
|
|
312
|
+
const uItem = await this._resolveSelfUserItem(params);
|
|
313
|
+
if (!uItem || typeof uItem.writeOwnSettings !== 'function')
|
|
314
|
+
throw new Error('Профиль пользователя не найден');
|
|
315
|
+
const patch = (params.post && typeof params.post === 'object' && !Array.isArray(params.post)) ? params.post : {};
|
|
316
|
+
const nextSettings = await uItem.writeOwnSettings(patch);
|
|
317
|
+
const { broadcastUserSettings } = await import('../host/websocket.js');
|
|
318
|
+
broadcastUserSettings(uItem.id, nextSettings);
|
|
319
|
+
return nextSettings;
|
|
320
|
+
}
|
|
321
|
+
|
|
287
322
|
get pageHTML() {
|
|
288
323
|
return fs.readFileSync('./sources/page.html', {encoding: 'utf-8'});
|
|
289
324
|
}
|
|
@@ -692,6 +727,13 @@ export class $server extends $class {
|
|
|
692
727
|
throw new Error('Доступ запрещён');
|
|
693
728
|
if (!DEV_MODE)
|
|
694
729
|
throw new Error('Сервер уже работает в обычном режиме');
|
|
730
|
+
if (process.env.WORK_WATCHDOG === '1') {
|
|
731
|
+
const reqFile = path.join(this.dir || process.cwd(), '#system', 'restart-request.json');
|
|
732
|
+
fs.mkdirSync(path.dirname(reqFile), { recursive: true });
|
|
733
|
+
fs.writeFileSync(reqFile, JSON.stringify({ env: { WORK_DEV: 'false' }, reason: 'restart_normal', time: Date.now() }), 'utf8');
|
|
734
|
+
setTimeout(() => process.exit(75), 1000).unref?.();
|
|
735
|
+
return true;
|
|
736
|
+
}
|
|
695
737
|
const { spawn } = await import('node:child_process');
|
|
696
738
|
const env = { ...process.env, WORK_DEV: 'false' };
|
|
697
739
|
// отладочные флаги не должны пережить перезапуск
|
|
@@ -794,13 +836,20 @@ export class $server extends $class {
|
|
|
794
836
|
}
|
|
795
837
|
|
|
796
838
|
async _scheduleProcessRestart({ cwd = process.cwd(), entryArgs, delayMs: rawDelay } = {}) {
|
|
839
|
+
const delayMs = Math.max(1500, Math.min(10000, Number(rawDelay) || 2500));
|
|
840
|
+
if (process.env.WORK_WATCHDOG === '1') {
|
|
841
|
+
const reqFile = path.join(cwd, '#system', 'restart-request.json');
|
|
842
|
+
fs.mkdirSync(path.dirname(reqFile), { recursive: true });
|
|
843
|
+
fs.writeFileSync(reqFile, JSON.stringify({ reason: 'server_restart', time: Date.now() }), 'utf8');
|
|
844
|
+
setTimeout(() => process.exit(75), delayMs).unref?.();
|
|
845
|
+
return delayMs;
|
|
846
|
+
}
|
|
797
847
|
const { spawn } = await import('node:child_process');
|
|
798
848
|
const env = { ...process.env };
|
|
799
849
|
delete env.NODE_OPTIONS;
|
|
800
850
|
const args = Array.isArray(entryArgs) && entryArgs.length
|
|
801
851
|
? entryArgs
|
|
802
852
|
: (process.argv.slice(1).length ? process.argv.slice(1) : ['run.mjs']);
|
|
803
|
-
const delayMs = Math.max(1500, Math.min(10000, Number(rawDelay) || 2500));
|
|
804
853
|
const helper = `
|
|
805
854
|
const fs = await import('node:fs');
|
|
806
855
|
const path = await import('node:path');
|
package/sources/server/user.js
CHANGED
|
@@ -53,6 +53,9 @@ export class $user extends $class {
|
|
|
53
53
|
/** Быстрое включение/отключение пользователя супер-админом (BOSS корня WORK `/`). */
|
|
54
54
|
async set_enabled(params = {}) {
|
|
55
55
|
await globalThis.WORK.assertAccess(params, $class.ACCESS_LEVEL.BOSS);
|
|
56
|
+
await this.init;
|
|
57
|
+
if (this.DATA?.usersContainer === true)
|
|
58
|
+
throw new Error('Нельзя отключить общий раздел пользователей');
|
|
56
59
|
const nextEnabled = !(params.enabled === false || params.enabled === 'false' || params.enabled === 0 || params.enabled === '0');
|
|
57
60
|
if (!nextEnabled && params?.session?.uid && params.session.uid === this.id)
|
|
58
61
|
throw new Error('Нельзя отключить собственную учётную запись');
|
|
@@ -98,6 +101,48 @@ export class $user extends $class {
|
|
|
98
101
|
return { enabled: nextEnabled };
|
|
99
102
|
}
|
|
100
103
|
|
|
104
|
+
async writeOwnSettings(patch = {}) {
|
|
105
|
+
await this.init;
|
|
106
|
+
const metaDir = this.meta_folder?.real_dir;
|
|
107
|
+
if (!metaDir)
|
|
108
|
+
throw new Error('Не найдена папка профиля');
|
|
109
|
+
const ownFile = path.join(metaDir, 'class.js');
|
|
110
|
+
let ownObj = {};
|
|
111
|
+
if (fs.existsSync(ownFile)) {
|
|
112
|
+
try {
|
|
113
|
+
ownObj = (await this.constructor.importScript(fs.readFileSync(ownFile, 'utf-8'), this.path)) || {};
|
|
114
|
+
}
|
|
115
|
+
catch { ownObj = {}; }
|
|
116
|
+
}
|
|
117
|
+
const cur = (ownObj.settings && typeof ownObj.settings === 'object' && !Array.isArray(ownObj.settings))
|
|
118
|
+
? { ...ownObj.settings }
|
|
119
|
+
: {};
|
|
120
|
+
if ('chatSound' in patch)
|
|
121
|
+
cur.chatSound = patch.chatSound !== false;
|
|
122
|
+
if ('aiModel' in patch)
|
|
123
|
+
cur.aiModel = typeof patch.aiModel === 'string' ? patch.aiModel.trim().slice(0, 512) : '';
|
|
124
|
+
for (const [k, v] of Object.entries(patch)) {
|
|
125
|
+
if (k === 'chatSound' || k === 'aiModel' || k === '__proto__' || k === 'constructor' || k === 'prototype')
|
|
126
|
+
continue;
|
|
127
|
+
if (!/^[a-zA-Z0-9_-]{1,64}$/.test(k))
|
|
128
|
+
continue;
|
|
129
|
+
if (v === null || v === undefined)
|
|
130
|
+
delete cur[k];
|
|
131
|
+
else if (typeof v === 'boolean' || typeof v === 'number' || typeof v === 'string')
|
|
132
|
+
cur[k] = typeof v === 'string' ? v.slice(0, 1024) : v;
|
|
133
|
+
}
|
|
134
|
+
const nextSettings = { chatSound: cur.chatSound !== false, aiModel: cur.aiModel || '', ...cur };
|
|
135
|
+
ownObj.settings = nextSettings;
|
|
136
|
+
const post = 'export default ' + this.constructor.toScript(ownObj) + '\n';
|
|
137
|
+
await fs.promises.mkdir(metaDir, { recursive: true });
|
|
138
|
+
await fs.promises.writeFile(ownFile, post, 'utf8');
|
|
139
|
+
this.reset();
|
|
140
|
+
await this.init;
|
|
141
|
+
if (this.DATA)
|
|
142
|
+
this.DATA.settings = nextSettings;
|
|
143
|
+
return nextSettings;
|
|
144
|
+
}
|
|
145
|
+
|
|
101
146
|
async allowAccess(params) {
|
|
102
147
|
await this.init;
|
|
103
148
|
if (this.DATA?.usersContainer === true)
|
package/sources/work.js
CHANGED
|
@@ -13,6 +13,7 @@ import './server/server.js';
|
|
|
13
13
|
import { $server } from './server/server.js';
|
|
14
14
|
import { createRequestHandler, startServers } from './host/http-server.js';
|
|
15
15
|
import { attachWebSocket } from './host/websocket.js';
|
|
16
|
+
import { migrateDepartmentMetasSync } from './server/class/scaffold.js';
|
|
16
17
|
|
|
17
18
|
webPush.setVapidDetails(
|
|
18
19
|
'https://odant.org',
|
|
@@ -20,6 +21,12 @@ webPush.setVapidDetails(
|
|
|
20
21
|
vapidKeys.privateKey
|
|
21
22
|
);
|
|
22
23
|
|
|
24
|
+
if (process.env.WORK_MIGRATE_DEPT !== '0') {
|
|
25
|
+
const moved = migrateDepartmentMetasSync(process.cwd());
|
|
26
|
+
if (moved.length)
|
|
27
|
+
console.log('[WORK] мигрированы подразделения:', moved.length);
|
|
28
|
+
}
|
|
29
|
+
|
|
23
30
|
globalThis.WORK = new $server();
|
|
24
31
|
globalThis.ssid = $server.genGUID();
|
|
25
32
|
|
package/start.bat
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
@echo off
|
|
2
|
+
setlocal
|
|
3
|
+
set "WORK_DIR=%~dp0"
|
|
4
|
+
if "%WORK_DIR:~-1%"=="\" set "WORK_DIR=%WORK_DIR:~0,-1%"
|
|
5
|
+
pushd "%WORK_DIR%" >nul
|
|
6
|
+
|
|
7
|
+
where node >nul 2>nul
|
|
8
|
+
if errorlevel 1 (
|
|
9
|
+
echo [WORK] Node.js не найден в PATH. Установите Node.js 22+ и повторите запуск.
|
|
10
|
+
popd >nul
|
|
11
|
+
exit /b 1
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
set "WD_SCRIPT=%WORK_DIR%\scripts\watchdog.mjs"
|
|
15
|
+
if not exist "%WD_SCRIPT%" set "WD_SCRIPT=%WORK_DIR%\node_modules\odant-work\scripts\watchdog.mjs"
|
|
16
|
+
if not exist "%WD_SCRIPT%" (
|
|
17
|
+
echo [WORK] Не найден scripts\watchdog.mjs
|
|
18
|
+
popd >nul
|
|
19
|
+
exit /b 1
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
node "%WD_SCRIPT%" --start "--root=%WORK_DIR%"
|
|
23
|
+
set "RC=%ERRORLEVEL%"
|
|
24
|
+
popd >nul
|
|
25
|
+
exit /b %RC%
|
package/start.sh
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/usr/bin/env sh
|
|
2
|
+
set -eu
|
|
3
|
+
WORK_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
|
|
4
|
+
cd "$WORK_DIR"
|
|
5
|
+
|
|
6
|
+
if ! command -v node >/dev/null 2>&1; then
|
|
7
|
+
echo "[WORK] Node.js не найден в PATH." >&2
|
|
8
|
+
exit 1
|
|
9
|
+
fi
|
|
10
|
+
|
|
11
|
+
if [ -d /run/systemd/system ] && command -v systemctl >/dev/null 2>&1; then
|
|
12
|
+
if [ -f /etc/systemd/system/odant-work.service ] && [ "$(id -u)" -eq 0 ]; then
|
|
13
|
+
systemctl start odant-work
|
|
14
|
+
exit 0
|
|
15
|
+
fi
|
|
16
|
+
if [ -f "$HOME/.config/systemd/user/odant-work.service" ]; then
|
|
17
|
+
systemctl --user start odant-work
|
|
18
|
+
exit 0
|
|
19
|
+
fi
|
|
20
|
+
fi
|
|
21
|
+
|
|
22
|
+
WD_SCRIPT="$WORK_DIR/scripts/watchdog.mjs"
|
|
23
|
+
if [ ! -f "$WD_SCRIPT" ]; then
|
|
24
|
+
WD_SCRIPT="$WORK_DIR/node_modules/odant-work/scripts/watchdog.mjs"
|
|
25
|
+
fi
|
|
26
|
+
|
|
27
|
+
exec node "$WD_SCRIPT" --start "--root=$WORK_DIR"
|
package/stop.bat
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
@echo off
|
|
2
|
+
setlocal
|
|
3
|
+
set "WORK_DIR=%~dp0"
|
|
4
|
+
if "%WORK_DIR:~-1%"=="\" set "WORK_DIR=%WORK_DIR:~0,-1%"
|
|
5
|
+
pushd "%WORK_DIR%" >nul
|
|
6
|
+
|
|
7
|
+
where node >nul 2>nul
|
|
8
|
+
if errorlevel 1 (
|
|
9
|
+
echo [WORK] Node.js не найден в PATH.
|
|
10
|
+
popd >nul
|
|
11
|
+
exit /b 1
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
set "WD_SCRIPT=%WORK_DIR%\scripts\watchdog.mjs"
|
|
15
|
+
if not exist "%WD_SCRIPT%" set "WD_SCRIPT=%WORK_DIR%\node_modules\odant-work\scripts\watchdog.mjs"
|
|
16
|
+
if not exist "%WD_SCRIPT%" (
|
|
17
|
+
echo [WORK] Не найден scripts\watchdog.mjs
|
|
18
|
+
popd >nul
|
|
19
|
+
exit /b 1
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
node "%WD_SCRIPT%" --stop "--root=%WORK_DIR%"
|
|
23
|
+
set "RC=%ERRORLEVEL%"
|
|
24
|
+
popd >nul
|
|
25
|
+
exit /b %RC%
|
package/stop.sh
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env sh
|
|
2
|
+
set -eu
|
|
3
|
+
WORK_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
|
|
4
|
+
cd "$WORK_DIR"
|
|
5
|
+
|
|
6
|
+
if ! command -v node >/dev/null 2>&1; then
|
|
7
|
+
echo "[WORK] Node.js не найден в PATH." >&2
|
|
8
|
+
exit 1
|
|
9
|
+
fi
|
|
10
|
+
|
|
11
|
+
WD_SCRIPT="$WORK_DIR/scripts/watchdog.mjs"
|
|
12
|
+
if [ ! -f "$WD_SCRIPT" ]; then
|
|
13
|
+
WD_SCRIPT="$WORK_DIR/node_modules/odant-work/scripts/watchdog.mjs"
|
|
14
|
+
fi
|
|
15
|
+
|
|
16
|
+
exec node "$WD_SCRIPT" --stop "--root=$WORK_DIR"
|
package/sw.js
CHANGED
|
@@ -131,9 +131,10 @@
|
|
|
131
131
|
// по ней уже лишнее — закрываем, даже если оно висело с requireInteraction.
|
|
132
132
|
self.addEventListener('message', async (event) => {
|
|
133
133
|
const msg = event.data || {};
|
|
134
|
-
|
|
134
|
+
const p = msg.path || msg.task;
|
|
135
|
+
if (msg.type !== 'work:task-visible' || !p)
|
|
135
136
|
return;
|
|
136
|
-
const tag = 'task:' + String(
|
|
137
|
+
const tag = 'task:' + String(p);
|
|
137
138
|
delete pushHandlers[tag];
|
|
138
139
|
try {
|
|
139
140
|
const list = await self.registration.getNotifications({ tag });
|
|
@@ -314,15 +315,6 @@ const OFFLINE_PAGE = `<!DOCTYPE html><html lang="ru"><head><meta charset="utf-8"
|
|
|
314
315
|
// задача открыта в ленте чата/вкладкой — форма на экране отвечает сама
|
|
315
316
|
if (await taskOnScreen(taskPath, wins))
|
|
316
317
|
return;
|
|
317
|
-
const target = data.data?.url && new URL(data.data.url, self.location.origin).pathname;
|
|
318
|
-
const isViewingExplorer = c => {
|
|
319
|
-
if (c.visibilityState !== 'visible' || !c.focused)
|
|
320
|
-
return false;
|
|
321
|
-
const p = new URL(c.url).pathname;
|
|
322
|
-
return p === target || p === '/' || p === '/index.html' || p.startsWith('/~/handlers/pages/explorer');
|
|
323
|
-
};
|
|
324
|
-
if (wins.some(isViewingExplorer))
|
|
325
|
-
return;
|
|
326
318
|
// 9.7: ожидающее разрешение — кнопки «Разрешить/Отклонить» прямо в уведомлении:
|
|
327
319
|
// подтверждение уходит на сервер (POST file?approve — те же права, что в интерфейсе),
|
|
328
320
|
// без кнопок (вопрос/прочее) — клик открывает задачу, как раньше
|