odant-work 1.0.102 → 1.0.104
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/$user/handlers/pages/form/system/agent/$handler/class.js +11 -1
- package/$server/$folder/$class/$structure/$user/handlers/pages/form/system/messengers/$handler/class.js +11 -1
- package/$server/$folder/$class/$structure/$user/handlers/pages/form/system/settings/$handler/class.js +292 -0
- package/$server/$folder/$class/$structure/$user/handlers/pages/form/system/skills/$handler/class.js +11 -1
- 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 +24 -2
- package/$server/$folder/$class/$structure/handlers/pages/form/system/agent/$handler/class.js +14 -11
- package/$server/$folder/$file/$html/handlers/preview/$handler/preview.js +7 -0
- package/$server/$folder/$file/$image/handlers/preview/$handler/preview.js +11 -0
- package/$server/$folder/$file/$md/handlers/preview/$handler/preview.js +29 -8
- package/$server/$folder/$file/$office/handlers/preview/$handler/preview.js +6 -0
- package/$server/$folder/$file/$task/handlers/pages/form/file/$handler/class.js +65 -10
- package/$server/$folder/$file/$task/handlers/pages/form/file/$handler/ui/feed.js +14 -11
- package/$server/$folder/$file/$task/handlers/pages/form/file/$handler/ui/util.js +32 -0
- package/$server/$folder/$file/$task/handlers/preview/$handler/preview.js +1 -0
- package/$server/$folder/$file/$txt/handlers/preview/$handler/preview.js +9 -0
- package/$server/$folder/$file/$video/handlers/preview/$handler/preview.js +15 -0
- package/$server/$folder/handlers/pages/form/$handler/class.js +10 -2
- package/$server/$folder/handlers/pages/form/folder/$handler/class.js +523 -25
- package/$server/$folder/lib/consultant/consultant.js +80 -3
- package/$server/$folder/lib/explorer/explorer.js +63 -0
- package/$server/$folder/lib/tree/tree.js +47 -16
- package/NODES/$node/handlers/pages/form/network/$handler/class.js +552 -36
- package/autostart.bat +28 -0
- package/autostart.sh +17 -0
- package/oda/components/icon/icon.js +20 -7
- package/package.json +1 -1
- package/run.mjs +19 -0
- package/scripts/autostart.mjs +281 -0
- package/scripts/watchdog.mjs +496 -0
- package/sources/client.js +146 -2
- package/sources/host/auth-methods.js +2 -0
- 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 +69 -3
- package/sources/modules/agent/index.js +50 -19
- package/sources/modules/agent/permissions.js +4 -2
- package/sources/modules/agent/scope.js +72 -5
- package/sources/modules/agent/session.js +97 -14
- package/sources/modules/agent/tools/work/classes.js +16 -1
- package/sources/modules/license/index.js +120 -0
- package/sources/modules/nodes/registry.js +57 -7
- package/sources/modules/trainer/local-engine.js +22 -9
- package/sources/modules/user-profile/user-tokens.js +426 -85
- package/sources/server/access/gateway.js +3 -1
- package/sources/server/class/feed.js +6 -0
- package/sources/server/folder.js +5 -1
- package/sources/server/node.js +16 -0
- package/sources/server/server.js +59 -1
- package/sources/server/user.js +48 -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/client.js
CHANGED
|
@@ -438,6 +438,8 @@ WORK.login = async function(force = false){
|
|
|
438
438
|
WORK.credentials = window.top.WORK.credentials;
|
|
439
439
|
WORK.uid = window.top.WORK.uid || '';
|
|
440
440
|
WORK.USER = window.top.WORK.USER;
|
|
441
|
+
WORK.userSettings = window.top.WORK.userSettings || WORK.userSettings;
|
|
442
|
+
WORK._userSettingsLoaded = Boolean(window.top.WORK._userSettingsLoaded);
|
|
441
443
|
WORK._loginError = null;
|
|
442
444
|
return res;
|
|
443
445
|
}
|
|
@@ -485,6 +487,7 @@ WORK.login = async function(force = false){
|
|
|
485
487
|
WORK._anonExitSynced = false;
|
|
486
488
|
if (authChanged || !WORK.USER)
|
|
487
489
|
await WORK.syncAuthUI();
|
|
490
|
+
await WORK.loadUserSettings?.();
|
|
488
491
|
WORK.refreshChatUnread?.();
|
|
489
492
|
if (authChanged) {
|
|
490
493
|
WORK._authNotifiedOnce = true;
|
|
@@ -500,6 +503,8 @@ WORK.login = async function(force = false){
|
|
|
500
503
|
WORK._pushSyncedUid = '';
|
|
501
504
|
WORK._loginError = null;
|
|
502
505
|
WORK.USER = undefined;
|
|
506
|
+
WORK.userSettings = { chatSound: true, aiModel: '' };
|
|
507
|
+
WORK._userSettingsLoaded = false;
|
|
503
508
|
WORK.chatUnread = { total: 0, byThread: {}, byNode: {}, byPeer: {} };
|
|
504
509
|
if (hadAuth || !WORK._anonExitSynced) {
|
|
505
510
|
WORK._anonExitSynced = true;
|
|
@@ -592,12 +597,117 @@ WORK.getPublicVapid = async function () {
|
|
|
592
597
|
key = WORK.urlBase64ToUint8Array(key);
|
|
593
598
|
return WORK.arrayBufferToBase64(key);
|
|
594
599
|
}
|
|
600
|
+
function getPushDeviceId() {
|
|
601
|
+
try {
|
|
602
|
+
let id = globalThis.localStorage?.getItem('work.push.deviceId') || '';
|
|
603
|
+
if (!id) {
|
|
604
|
+
id = globalThis.crypto?.randomUUID?.() || (Date.now().toString(36) + '-' + Math.random().toString(36).slice(2));
|
|
605
|
+
globalThis.localStorage?.setItem('work.push.deviceId', id);
|
|
606
|
+
}
|
|
607
|
+
return id;
|
|
608
|
+
}
|
|
609
|
+
catch {
|
|
610
|
+
return '';
|
|
611
|
+
}
|
|
612
|
+
}
|
|
595
613
|
WORK.storePushSubscription = function (subscription) {
|
|
596
|
-
|
|
614
|
+
const sub = typeof subscription?.toJSON === 'function' ? subscription.toJSON() : { ...(subscription || {}) };
|
|
615
|
+
const deviceId = getPushDeviceId();
|
|
616
|
+
let replaceEndpoint = '';
|
|
617
|
+
try { replaceEndpoint = globalThis.localStorage?.getItem('work.push.endpoint') || ''; } catch {}
|
|
618
|
+
const payload = {
|
|
619
|
+
...sub,
|
|
620
|
+
...(deviceId ? { deviceId } : {}),
|
|
621
|
+
...(replaceEndpoint && replaceEndpoint !== sub.endpoint ? { replaceEndpoint } : {}),
|
|
622
|
+
};
|
|
623
|
+
try {
|
|
624
|
+
if (sub.endpoint)
|
|
625
|
+
globalThis.localStorage?.setItem('work.push.endpoint', sub.endpoint);
|
|
626
|
+
} catch {}
|
|
627
|
+
return WORK.fetch("/", 'store_push_subscription', {}, payload);
|
|
597
628
|
}
|
|
598
629
|
WORK.removePushSubscription = function (subscription) {
|
|
599
|
-
|
|
630
|
+
const sub = typeof subscription?.toJSON === 'function' ? subscription.toJSON() : { ...(subscription || {}) };
|
|
631
|
+
const deviceId = getPushDeviceId();
|
|
632
|
+
try { globalThis.localStorage?.removeItem('work.push.endpoint'); } catch {}
|
|
633
|
+
return WORK.fetch("/", 'remove_push_subscription', {}, { ...sub, ...(deviceId ? { deviceId } : {}) });
|
|
600
634
|
}
|
|
635
|
+
WORK.userSettings = { chatSound: true, aiModel: '' };
|
|
636
|
+
WORK._userSettingsLoaded = false;
|
|
637
|
+
WORK._applyUserSettings = function (next, { broadcast = false } = {}) {
|
|
638
|
+
if (!next || typeof next !== 'object')
|
|
639
|
+
return WORK.userSettings;
|
|
640
|
+
WORK.userSettings = {
|
|
641
|
+
...WORK.userSettings,
|
|
642
|
+
...next,
|
|
643
|
+
chatSound: next.chatSound !== false,
|
|
644
|
+
aiModel: typeof next.aiModel === 'string' ? next.aiModel : (WORK.userSettings?.aiModel || ''),
|
|
645
|
+
};
|
|
646
|
+
if (WORK.USER?.DATA)
|
|
647
|
+
WORK.USER.DATA.settings = { ...WORK.userSettings };
|
|
648
|
+
if (broadcast) {
|
|
649
|
+
try { WORK._settingsChannel?.postMessage?.(WORK.userSettings); } catch {}
|
|
650
|
+
}
|
|
651
|
+
try {
|
|
652
|
+
WORK.authEvents?.dispatchEvent?.(new CustomEvent('user-settings', { detail: WORK.userSettings }));
|
|
653
|
+
} catch {}
|
|
654
|
+
return WORK.userSettings;
|
|
655
|
+
};
|
|
656
|
+
if (typeof BroadcastChannel !== 'undefined') {
|
|
657
|
+
try {
|
|
658
|
+
WORK._settingsChannel ??= new BroadcastChannel('work-user-settings');
|
|
659
|
+
WORK._settingsChannel.addEventListener('message', (e) => {
|
|
660
|
+
if (e.data && typeof e.data === 'object')
|
|
661
|
+
WORK._applyUserSettings(e.data, { broadcast: false });
|
|
662
|
+
});
|
|
663
|
+
} catch {}
|
|
664
|
+
}
|
|
665
|
+
WORK.loadUserSettings = async function () {
|
|
666
|
+
if (!WORK.uid || typeof WORK.fetch !== 'function')
|
|
667
|
+
return WORK.userSettings;
|
|
668
|
+
try {
|
|
669
|
+
const res = await WORK.fetch('/', 'user_settings_get');
|
|
670
|
+
if (res && typeof res === 'object') {
|
|
671
|
+
WORK._userSettingsLoaded = true;
|
|
672
|
+
WORK._applyUserSettings(res, { broadcast: false });
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
catch { /* ignore */ }
|
|
676
|
+
return WORK.userSettings;
|
|
677
|
+
};
|
|
678
|
+
WORK.saveUserSettings = async function (patch = {}) {
|
|
679
|
+
if (!patch || typeof patch !== 'object')
|
|
680
|
+
return WORK.userSettings;
|
|
681
|
+
WORK._applyUserSettings(patch, { broadcast: true });
|
|
682
|
+
if (!WORK.uid || typeof WORK.fetch !== 'function')
|
|
683
|
+
return WORK.userSettings;
|
|
684
|
+
try {
|
|
685
|
+
const saved = await WORK.fetch('/', 'user_settings_save', {}, patch);
|
|
686
|
+
if (saved && typeof saved === 'object') {
|
|
687
|
+
WORK._userSettingsLoaded = true;
|
|
688
|
+
WORK._applyUserSettings(saved, { broadcast: true });
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
catch (err) {
|
|
692
|
+
console.warn('[user-settings] save', err?.message || err);
|
|
693
|
+
}
|
|
694
|
+
return WORK.userSettings;
|
|
695
|
+
};
|
|
696
|
+
WORK._visibleTasks = new Set();
|
|
697
|
+
WORK.setTaskPresence = function (taskPath, visible) {
|
|
698
|
+
const p = String(taskPath || '').replace(/\/+$/, '');
|
|
699
|
+
if (!p)
|
|
700
|
+
return;
|
|
701
|
+
if (visible)
|
|
702
|
+
WORK._visibleTasks.add(p);
|
|
703
|
+
else
|
|
704
|
+
WORK._visibleTasks.delete(p);
|
|
705
|
+
try {
|
|
706
|
+
if (WORK._ws?.readyState === 1)
|
|
707
|
+
WORK._ws.send(JSON.stringify({ type: 'task.presence', path: p, visible: Boolean(visible) }));
|
|
708
|
+
}
|
|
709
|
+
catch { /* ignore */ }
|
|
710
|
+
};
|
|
601
711
|
/** Перед выходом убрать подписку у прежнего uid, иначе следующий пользователь получит его push. */
|
|
602
712
|
WORK.removeCurrentPushSubscription = async function () {
|
|
603
713
|
if (!WORK.uid || !navigator.serviceWorker || typeof Notification === 'undefined' || Notification.permission !== 'granted')
|
|
@@ -650,11 +760,17 @@ class WebSocketEvents {
|
|
|
650
760
|
}
|
|
651
761
|
}
|
|
652
762
|
onopen(e) {
|
|
763
|
+
WORK._ws = this;
|
|
653
764
|
this.send(JSON.stringify(Object.keys(CORE.$item.ITEMS)));
|
|
765
|
+
for (const tp of WORK._visibleTasks || []) {
|
|
766
|
+
try { this.send(JSON.stringify({ type: 'task.presence', path: tp, visible: true })); } catch {}
|
|
767
|
+
}
|
|
654
768
|
WORK.connected = true;
|
|
655
769
|
WORK.login().catch(() => {});
|
|
656
770
|
}
|
|
657
771
|
onclose(e) {
|
|
772
|
+
if (WORK._ws === this)
|
|
773
|
+
WORK._ws = null;
|
|
658
774
|
WORK.connected = false;
|
|
659
775
|
WORK.wsid = '';
|
|
660
776
|
WORK._loginPromise = null;
|
|
@@ -680,6 +796,10 @@ class WebSocketEvents {
|
|
|
680
796
|
case 'connect':{
|
|
681
797
|
WORK.wsid = this.id = data.wsid
|
|
682
798
|
} break;
|
|
799
|
+
case 'user-settings': {
|
|
800
|
+
if (data.settings && (!WORK.uid || data.uid === WORK.uid))
|
|
801
|
+
WORK._applyUserSettings?.(data.settings, { broadcast: false });
|
|
802
|
+
} break;
|
|
683
803
|
case 'auth-changed': {
|
|
684
804
|
WORK.onAuthChanged(data);
|
|
685
805
|
} break;
|
|
@@ -723,6 +843,30 @@ class WebSocketEvents {
|
|
|
723
843
|
}
|
|
724
844
|
WORK.chatEvents.dispatchEvent(new CustomEvent('task.moved', { detail: data }));
|
|
725
845
|
} break;
|
|
846
|
+
case 'node.deleted': {
|
|
847
|
+
WORK.chatEvents ??= new EventTarget();
|
|
848
|
+
const delPath = String(data.path || '').replace(/\/+$/, '');
|
|
849
|
+
const parentPath = String(data.parentPath || '/').replace(/\/+$/, '') || '/';
|
|
850
|
+
if (delPath) {
|
|
851
|
+
for (const [k, item] of Object.entries(CORE.$item.ITEMS || {})) {
|
|
852
|
+
const ip = String(item?.short || item?.path || k).replace(/\/+$/, '');
|
|
853
|
+
if (ip === delPath || ip.startsWith(delPath + '/')) {
|
|
854
|
+
try { item.fire?.('node.deleted', data); } catch { /* ignore */ }
|
|
855
|
+
delete CORE.$item.ITEMS[k];
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
const parentItem = CORE.$item.ITEMS[parentPath] || (parentPath === '/' ? CORE.$item.ITEMS[''] : null);
|
|
859
|
+
if (parentItem) {
|
|
860
|
+
const LISTS = parentItem.constructor.LISTS || CORE.$item.LISTS;
|
|
861
|
+
for (const key of LISTS) {
|
|
862
|
+
delete parentItem[key];
|
|
863
|
+
Reactor.invalidate(parentItem, key);
|
|
864
|
+
}
|
|
865
|
+
parentItem.fire?.('changed');
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
WORK.chatEvents.dispatchEvent(new CustomEvent('node.deleted', { detail: data }));
|
|
869
|
+
} break;
|
|
726
870
|
case 'chat:message':
|
|
727
871
|
case 'chat:read': {
|
|
728
872
|
WORK.chatEvents ??= new EventTarget();
|
|
@@ -300,6 +300,8 @@ export const authMethods = {
|
|
|
300
300
|
let $user_item = await $users._get_next_item(uid, CORE.$user);
|
|
301
301
|
credentials.keys = $user_item.keys || {};
|
|
302
302
|
credentials.keys[time] = publicKey;
|
|
303
|
+
if ($user_item.DATA?.settings && typeof $user_item.DATA.settings === 'object')
|
|
304
|
+
credentials.settings = $user_item.DATA.settings;
|
|
303
305
|
|
|
304
306
|
if (iconBytes)
|
|
305
307
|
credentials.icon = '/USERS//' + uid + '/$user/icon.png';
|
|
@@ -138,9 +138,23 @@ export function isProtectedUserPath(relPath) {
|
|
|
138
138
|
* Проверить, является ли файл частью системного ядра (движок сервера и фреймворк ODA),
|
|
139
139
|
* которое должно обновляться до новой версии релиза всегда.
|
|
140
140
|
*/
|
|
141
|
+
const CORE_ROOT_SCRIPTS = new Set([
|
|
142
|
+
'run.mjs',
|
|
143
|
+
'package.json',
|
|
144
|
+
'package-lock.json',
|
|
145
|
+
'start.bat',
|
|
146
|
+
'stop.bat',
|
|
147
|
+
'autostart.bat',
|
|
148
|
+
'start.sh',
|
|
149
|
+
'stop.sh',
|
|
150
|
+
'autostart.sh',
|
|
151
|
+
'scripts/watchdog.mjs',
|
|
152
|
+
'scripts/autostart.mjs',
|
|
153
|
+
]);
|
|
154
|
+
|
|
141
155
|
export function isCoreEnginePath(relPath) {
|
|
142
156
|
const rel = normalizeRelPath(relPath);
|
|
143
|
-
if (
|
|
157
|
+
if (CORE_ROOT_SCRIPTS.has(rel))
|
|
144
158
|
return true;
|
|
145
159
|
if (rel.startsWith('sources/') || rel.startsWith('oda/') || rel.startsWith('vendor/'))
|
|
146
160
|
return true;
|
|
@@ -154,6 +168,14 @@ const TRACKED_ROOTS = [
|
|
|
154
168
|
'run.mjs',
|
|
155
169
|
'package.json',
|
|
156
170
|
'package-lock.json',
|
|
171
|
+
'start.bat',
|
|
172
|
+
'stop.bat',
|
|
173
|
+
'autostart.bat',
|
|
174
|
+
'start.sh',
|
|
175
|
+
'stop.sh',
|
|
176
|
+
'autostart.sh',
|
|
177
|
+
'scripts/watchdog.mjs',
|
|
178
|
+
'scripts/autostart.mjs',
|
|
157
179
|
'sources',
|
|
158
180
|
'oda',
|
|
159
181
|
'$server',
|
|
@@ -181,15 +181,17 @@ function onListenError(port, err) {
|
|
|
181
181
|
}
|
|
182
182
|
|
|
183
183
|
export function shouldAutoOpenBrowser(env = process.env, execArgv = process.execArgv, argv = process.argv) {
|
|
184
|
-
if (env.WORK_OPEN_BROWSER === '1' || env.WORK_OPEN_BROWSER === 'true')
|
|
185
|
-
return true;
|
|
186
184
|
if (env.WORK_NO_BROWSER === '1' || env.WORK_OPEN_BROWSER === '0' || env.WORK_TEST || env.CI || env.NODE_TEST_CONTEXT)
|
|
187
185
|
return false;
|
|
188
186
|
if (Array.isArray(execArgv) && execArgv.some(a => a === '--test' || a.startsWith('--test-')))
|
|
189
187
|
return false;
|
|
190
188
|
if (Array.isArray(argv) && argv.some(a => /[\\/]tests[\\/]/i.test(String(a)) || /\.test\.m?js$/i.test(String(a))))
|
|
191
189
|
return false;
|
|
192
|
-
|
|
190
|
+
if (env.WORK_OPEN_BROWSER === '1' || env.WORK_OPEN_BROWSER === 'true')
|
|
191
|
+
return true;
|
|
192
|
+
if (Array.isArray(argv) && argv.includes('--open'))
|
|
193
|
+
return true;
|
|
194
|
+
return false;
|
|
193
195
|
}
|
|
194
196
|
|
|
195
197
|
export function openBrowser(url) {
|
package/sources/host/push.js
CHANGED
|
@@ -32,25 +32,49 @@ export async function storePushSubscription(params) {
|
|
|
32
32
|
if (!params.session?.uid) {
|
|
33
33
|
throw new Error('No user id on store_push_subscription');
|
|
34
34
|
}
|
|
35
|
-
const
|
|
35
|
+
const raw = params.post || {};
|
|
36
|
+
const endpoint = String(raw.endpoint || '');
|
|
37
|
+
const replaceEndpoint = String(raw.replaceEndpoint || '');
|
|
38
|
+
const deviceId = String(raw.deviceId || '').slice(0, 128);
|
|
39
|
+
const subscription = {
|
|
40
|
+
endpoint,
|
|
41
|
+
...(raw.expirationTime !== undefined ? { expirationTime: raw.expirationTime } : {}),
|
|
42
|
+
...(raw.keys ? { keys: raw.keys } : {}),
|
|
43
|
+
...(deviceId ? { deviceId } : {}),
|
|
44
|
+
};
|
|
36
45
|
const subscriptions = await loadPushSubscriptions(params.session.uid);
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
46
|
+
const filtered = subscriptions.filter(s => {
|
|
47
|
+
if (!s?.endpoint)
|
|
48
|
+
return false;
|
|
49
|
+
if (s.endpoint === endpoint)
|
|
50
|
+
return false;
|
|
51
|
+
if (replaceEndpoint && s.endpoint === replaceEndpoint)
|
|
52
|
+
return false;
|
|
53
|
+
if (deviceId && s.deviceId && s.deviceId === deviceId)
|
|
54
|
+
return false;
|
|
55
|
+
return true;
|
|
56
|
+
});
|
|
57
|
+
filtered.push(subscription);
|
|
58
|
+
await savePushSubscriptions(params.session.uid, filtered);
|
|
44
59
|
return true;
|
|
45
60
|
}
|
|
46
61
|
|
|
47
62
|
export async function removePushSubscription(params) {
|
|
48
|
-
const
|
|
63
|
+
const raw = params.post || {};
|
|
64
|
+
const endpoint = String(raw.endpoint || '');
|
|
65
|
+
const deviceId = String(raw.deviceId || '').slice(0, 128);
|
|
49
66
|
const subscriptions = await loadPushSubscriptions(params.session.uid);
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
67
|
+
const next = subscriptions.filter(s => {
|
|
68
|
+
if (!s?.endpoint)
|
|
69
|
+
return false;
|
|
70
|
+
if (endpoint && s.endpoint === endpoint)
|
|
71
|
+
return false;
|
|
72
|
+
if (deviceId && s.deviceId && s.deviceId === deviceId)
|
|
73
|
+
return false;
|
|
74
|
+
return true;
|
|
75
|
+
});
|
|
76
|
+
if (next.length !== subscriptions.length) {
|
|
77
|
+
await savePushSubscriptions(params.session.uid, next);
|
|
54
78
|
}
|
|
55
79
|
return true;
|
|
56
80
|
}
|
|
@@ -69,7 +93,12 @@ export async function sendPushNotification(params, removeFn) {
|
|
|
69
93
|
const subscriptions = await loadPushSubscriptions(uid);
|
|
70
94
|
return Promise.all(subscriptions.map(async s => {
|
|
71
95
|
try {
|
|
72
|
-
|
|
96
|
+
const sub = {
|
|
97
|
+
endpoint: s.endpoint,
|
|
98
|
+
...(s.expirationTime !== undefined ? { expirationTime: s.expirationTime } : {}),
|
|
99
|
+
...(s.keys ? { keys: s.keys } : {}),
|
|
100
|
+
};
|
|
101
|
+
await webPush.sendNotification(sub, message);
|
|
73
102
|
}
|
|
74
103
|
catch (err) {
|
|
75
104
|
console.warn(err);
|
|
@@ -24,6 +24,8 @@ export function sameOrigin(req) {
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
const allSessions = () => Object.values($server?.sessions || {});
|
|
28
|
+
|
|
27
29
|
/** Уведомить сессии о смене presence пользователя (online).
|
|
28
30
|
* F24: анонимным сессиям (без вошедшего) местоположение людей не рассылаем.
|
|
29
31
|
* Экспортировано для теста фильтра. */
|
|
@@ -31,7 +33,7 @@ export function broadcastUserPath($user) {
|
|
|
31
33
|
if (!$user?.short)
|
|
32
34
|
return;
|
|
33
35
|
const message = JSON.stringify({ path: $user.short, initiator: $user.id });
|
|
34
|
-
for (const session of
|
|
36
|
+
for (const session of allSessions()) {
|
|
35
37
|
if (!session?.$user)
|
|
36
38
|
continue; // анонимная сессия — без присутствия
|
|
37
39
|
for (const sock of Object.values(session.sockets || {})) {
|
|
@@ -52,7 +54,7 @@ export function broadcastChatEvent(uids, payload) {
|
|
|
52
54
|
if (!targets.size || !payload || typeof payload !== 'object')
|
|
53
55
|
return;
|
|
54
56
|
const raw = JSON.stringify(payload);
|
|
55
|
-
for (const session of
|
|
57
|
+
for (const session of allSessions()) {
|
|
56
58
|
const uid = session?.$user?.id;
|
|
57
59
|
if (!uid || !targets.has(uid))
|
|
58
60
|
continue;
|
|
@@ -71,6 +73,54 @@ function notifyUserOnline(session) {
|
|
|
71
73
|
broadcastUserPath(session.$user);
|
|
72
74
|
}
|
|
73
75
|
|
|
76
|
+
export function isTaskVisibleToUser(uid, taskPath) {
|
|
77
|
+
if (!uid || !taskPath)
|
|
78
|
+
return false;
|
|
79
|
+
const norm = String(taskPath).replace(/\/+$/, '');
|
|
80
|
+
for (const session of allSessions()) {
|
|
81
|
+
if (session?.uid !== uid)
|
|
82
|
+
continue;
|
|
83
|
+
for (const sock of Object.values(session.sockets || {})) {
|
|
84
|
+
if (sock?.ws?.readyState !== 1)
|
|
85
|
+
continue;
|
|
86
|
+
if (sock.visibleTasks?.has?.(norm))
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function broadcastUserSettings(uid, settings) {
|
|
94
|
+
if (!uid || !settings || typeof settings !== 'object')
|
|
95
|
+
return;
|
|
96
|
+
const raw = JSON.stringify({ type: 'user-settings', uid, settings });
|
|
97
|
+
for (const session of allSessions()) {
|
|
98
|
+
if (session?.uid !== uid)
|
|
99
|
+
continue;
|
|
100
|
+
for (const sock of Object.values(session.sockets || {})) {
|
|
101
|
+
if (sock?.ws?.readyState === 1)
|
|
102
|
+
sock.ws.send(raw);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Разослать активным сессиям событие удаления узла/класса дерева. */
|
|
108
|
+
export function broadcastNodeDeleted(nodePath, parentPath = '/') {
|
|
109
|
+
const clean = String(nodePath || '').replace(/\/+$/, '');
|
|
110
|
+
if (!clean || clean === '/')
|
|
111
|
+
return;
|
|
112
|
+
const parentClean = String(parentPath || '/').replace(/\/+$/, '') || '/';
|
|
113
|
+
const raw = JSON.stringify({ type: 'node.deleted', path: clean, parentPath: parentClean });
|
|
114
|
+
for (const session of allSessions()) {
|
|
115
|
+
if (!session?.uid)
|
|
116
|
+
continue;
|
|
117
|
+
for (const sock of Object.values(session.sockets || {})) {
|
|
118
|
+
if (sock?.ws?.readyState === 1)
|
|
119
|
+
sock.ws.send(raw);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
74
124
|
export function onWebSocketConnect(ws, request) {
|
|
75
125
|
// Настоящий Chrome пользователя через расширение MV3: авторизуется токеном wmcp. (без cookies)
|
|
76
126
|
if (String(request?.url || '').split('?')[0] === '/~chrome') {
|
|
@@ -97,13 +147,29 @@ export function onWebSocketConnect(ws, request) {
|
|
|
97
147
|
const cookies = parseCookies(request);
|
|
98
148
|
let session = $server.get_session(cookies.ssid);
|
|
99
149
|
let wsid = $server.genGUID();
|
|
100
|
-
session.sockets[wsid] = { ws, events: [] };
|
|
150
|
+
session.sockets[wsid] = { ws, events: [], visibleTasks: new Set() };
|
|
101
151
|
ws.send(JSON.stringify({ type: 'connect', wsid }));
|
|
102
152
|
notifyUserOnline(session);
|
|
103
153
|
ws.on('message', async (message) => {
|
|
104
154
|
try {
|
|
105
155
|
let str = new TextDecoder('utf-8').decode(message);
|
|
106
156
|
let events = JSON.parse(str);
|
|
157
|
+
if (events && typeof events === 'object' && !Array.isArray(events)) {
|
|
158
|
+
if (events.type === 'task.presence') {
|
|
159
|
+
const sock = session.sockets[wsid];
|
|
160
|
+
if (sock) {
|
|
161
|
+
sock.visibleTasks ??= new Set();
|
|
162
|
+
const p = typeof events.path === 'string' ? events.path.replace(/\/+$/, '').slice(0, 2048) : '';
|
|
163
|
+
if (p && events.visible)
|
|
164
|
+
sock.visibleTasks.add(p);
|
|
165
|
+
else if (p)
|
|
166
|
+
sock.visibleTasks.delete(p);
|
|
167
|
+
else if (!events.visible)
|
|
168
|
+
sock.visibleTasks.clear();
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
107
173
|
if (!Array.isArray(events))
|
|
108
174
|
return;
|
|
109
175
|
const { assertPathProps, canRead } = await import('../server/access/gateway.js');
|
|
@@ -278,16 +278,15 @@ export async function llmWithFallback(primaryPath, fallbackPaths = []) {
|
|
|
278
278
|
}
|
|
279
279
|
const CLASSIFIER_MODEL_RE = /(классификатор|classifier|rerank|0\.6b)/i;
|
|
280
280
|
|
|
281
|
-
/**
|
|
282
|
-
export async function
|
|
281
|
+
/** Список доступных чат-моделей (используется в настройках профиля и автовыборе по умолчанию). */
|
|
282
|
+
export async function listAvailableChatModels() {
|
|
283
283
|
const root = await WORK.get_item('/MODULES/Модели').catch(() => null);
|
|
284
|
-
|
|
285
|
-
let firstActive = '';
|
|
286
|
-
let firstPrimary = '';
|
|
284
|
+
const out = [];
|
|
287
285
|
for (const provider of (await root?.items) || []) {
|
|
288
286
|
await provider?.init?.catch?.(() => {});
|
|
289
287
|
if (provider?.DATA?.enabled === false)
|
|
290
288
|
continue;
|
|
289
|
+
const provLabel = String(provider.DATA?.label || provider.label || provider.id || '');
|
|
291
290
|
for (const m of (await provider.items) || []) {
|
|
292
291
|
await m.init?.catch?.(() => {});
|
|
293
292
|
if (m?.DATA?.enabled === false)
|
|
@@ -297,18 +296,38 @@ export async function findFirstAvailableChatModel() {
|
|
|
297
296
|
continue;
|
|
298
297
|
const active = (m.aiActive ?? m.DATA?.aiActive) !== false;
|
|
299
298
|
const name = String(m.id || m.DATA?.label || m.label || m.path || '');
|
|
300
|
-
const
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
299
|
+
const label = String(m.DATA?.label || m.label || m.id || m.path || '');
|
|
300
|
+
const proto = String(m.protocol || m.DATA?.protocol || '').toLowerCase();
|
|
301
|
+
const wfmt = String(m.weightFormat || m.DATA?.weightFormat || '').toLowerCase();
|
|
302
|
+
const isCompactOrPythonLocal = /(?:^|[-_\s])(4b|2b|1\.7b|0\.6b)(?:$|[-_\s])/i.test(name)
|
|
303
|
+
|| (String(provider.id || '').toLowerCase() === 'local' && proto !== 'halogen' && wfmt !== 'gguf' && !/flash-next/i.test(name));
|
|
304
|
+
const isPrimary = active && !CLASSIFIER_MODEL_RE.test(name) && !isCompactOrPythonLocal;
|
|
305
|
+
out.push({
|
|
306
|
+
path: m.path,
|
|
307
|
+
label: provLabel ? `${label} (${provLabel})` : label,
|
|
308
|
+
active,
|
|
309
|
+
default: m.DATA?.default === true,
|
|
310
|
+
isPrimary,
|
|
311
|
+
});
|
|
309
312
|
}
|
|
310
313
|
}
|
|
311
|
-
return
|
|
314
|
+
return out;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/** Первая доступная чат-модель в /MODULES/Модели (приоритетно default:true и основная LLM, не классификатор и не Python-малютка). */
|
|
318
|
+
export async function findFirstAvailableChatModel() {
|
|
319
|
+
const list = await listAvailableChatModels();
|
|
320
|
+
const def = list.find(m => m.active && m.default);
|
|
321
|
+
if (def)
|
|
322
|
+
return def.path;
|
|
323
|
+
const flash = list.find(m => m.active && /flash-next/i.test(m.path));
|
|
324
|
+
if (flash)
|
|
325
|
+
return flash.path;
|
|
326
|
+
const primary = list.find(m => m.isPrimary);
|
|
327
|
+
if (primary)
|
|
328
|
+
return primary.path;
|
|
329
|
+
const active = list.find(m => m.active);
|
|
330
|
+
return (active || list[0])?.path || '';
|
|
312
331
|
}
|
|
313
332
|
/** Найти активную локальную модель в /MODULES/Модели/Local по capabilities (или id). */
|
|
314
333
|
async function findActiveLocalModel({ caps = [], ids = [], method = '' } = {}) {
|
|
@@ -617,14 +636,26 @@ export async function createEnv({ place, contextPath, session, host, tz, locatio
|
|
|
617
636
|
return [stable, volatile].filter(Boolean).join('\n\n');
|
|
618
637
|
},
|
|
619
638
|
async defaultModel() {
|
|
620
|
-
|
|
621
|
-
|
|
639
|
+
if (config.model) {
|
|
640
|
+
const candidate = remapModelPath(config.model);
|
|
641
|
+
const item = await WORK.get_item(candidate).catch(() => null);
|
|
642
|
+
if (item) {
|
|
643
|
+
await item.init?.catch?.(() => {});
|
|
644
|
+
if (typeof item.streamChat === 'function')
|
|
645
|
+
return candidate;
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
const first = await findFirstAvailableChatModel();
|
|
649
|
+
if (first)
|
|
650
|
+
return first;
|
|
651
|
+
const fallback = remapModelPath(DEFAULT_MODEL);
|
|
652
|
+
const item = await WORK.get_item(fallback).catch(() => null);
|
|
622
653
|
if (item) {
|
|
623
654
|
await item.init?.catch?.(() => {});
|
|
624
655
|
if (typeof item.streamChat === 'function')
|
|
625
|
-
return
|
|
656
|
+
return fallback;
|
|
626
657
|
}
|
|
627
|
-
return
|
|
658
|
+
return fallback;
|
|
628
659
|
},
|
|
629
660
|
/** Память изменена инструментом memory — пересобрать блок на следующем ходе. */
|
|
630
661
|
resetMemory() {
|
|
@@ -193,11 +193,13 @@ export function resolveApprovalScope(tool, args, ctx) {
|
|
|
193
193
|
}
|
|
194
194
|
if (tool.name === 'shell')
|
|
195
195
|
return classifyShellCommand(args?.command);
|
|
196
|
+
if (tool.risk === 'danger')
|
|
197
|
+
return { noAlways: true, key: tool.name, label: '', buttonLabel: '' };
|
|
196
198
|
const title = tool.label || tool.name;
|
|
197
199
|
return {
|
|
198
200
|
key: tool.name,
|
|
199
201
|
label: 'все вызовы «' + title + '» в этой задаче',
|
|
200
|
-
buttonLabel: '
|
|
202
|
+
buttonLabel: 'Больше не спрашивать в этой задаче',
|
|
201
203
|
};
|
|
202
204
|
}
|
|
203
205
|
|
|
@@ -262,7 +264,7 @@ export async function decide(tool, args, ctx) {
|
|
|
262
264
|
if (hit)
|
|
263
265
|
return { verdict: 'ask', noAlways: true, reason: 'изменение системы: ' + hit };
|
|
264
266
|
if (tool.risk === 'danger')
|
|
265
|
-
return { verdict: 'ask', reason: 'необратимое или внешнее действие'
|
|
267
|
+
return { verdict: 'ask', noAlways: true, reason: 'необратимое или внешнее действие' };
|
|
266
268
|
if (allowedMatches(host, tool.name, scope))
|
|
267
269
|
return { verdict: 'allow', autoAllowed: true, scopeKey: scope?.key || tool.name, scopeLabel: scope?.label || '' };
|
|
268
270
|
if (mode === 'ask')
|