odant-work 1.0.109 → 1.0.110
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.
|
@@ -1397,12 +1397,15 @@ ODA({
|
|
|
1397
1397
|
this.taskItem = task;
|
|
1398
1398
|
this.streams = {};
|
|
1399
1399
|
if (!task) return;
|
|
1400
|
+
globalThis.WORK?._subscribeWsPath?.(task.short || task.path);
|
|
1400
1401
|
const reload = async () => {
|
|
1401
1402
|
try {
|
|
1402
|
-
const
|
|
1403
|
+
const stateRes = await task.fetch?.('state').catch(() => null);
|
|
1404
|
+
const isLiveObj = Boolean(stateRes && typeof stateRes === 'object' && 'body' in stateRes);
|
|
1405
|
+
const raw = isLiveObj ? stateRes.body : await task.load();
|
|
1403
1406
|
const data = typeof raw === 'string' ? JSON.parse(raw || '{}') : raw || {};
|
|
1404
1407
|
this.data = data;
|
|
1405
|
-
this.status = data.status || 'idle';
|
|
1408
|
+
this.status = (isLiveObj && stateRes.running) ? 'running' : (data.status || 'idle');
|
|
1406
1409
|
this._voice?.onData(data);
|
|
1407
1410
|
} catch {/* ignore */}
|
|
1408
1411
|
};
|
|
@@ -154,19 +154,27 @@ export default {
|
|
|
154
154
|
this._bound = n || null;
|
|
155
155
|
this._hasActiveRun = false;
|
|
156
156
|
if (!n) return;
|
|
157
|
+
globalThis.WORK?._subscribeWsPath?.(n.short || n.path);
|
|
157
158
|
this._h = {
|
|
158
|
-
'changed': () => this._reload(),
|
|
159
|
-
'task.delta': e => this._onDelta(e.detail?.value),
|
|
159
|
+
'changed': () => { this._lastWsEvent = Date.now(); this._reload(); },
|
|
160
|
+
'task.delta': e => { this._lastWsEvent = Date.now(); this._onDelta(e.detail?.value); },
|
|
160
161
|
'chat.start': () => {
|
|
162
|
+
this._lastWsEvent = Date.now();
|
|
161
163
|
this._hasActiveRun = true;
|
|
164
|
+
if (this.status !== 'running') this.status = 'running';
|
|
165
|
+
this._ensureRunPoll();
|
|
162
166
|
},
|
|
163
167
|
'task.state': e => {
|
|
168
|
+
this._lastWsEvent = Date.now();
|
|
164
169
|
const s = e.detail?.value?.status;
|
|
165
170
|
if (s) {
|
|
166
171
|
const prevStatus = this.status;
|
|
167
172
|
this.status = s;
|
|
168
173
|
this._lastDelta = Date.now();
|
|
169
|
-
if (s === 'running')
|
|
174
|
+
if (s === 'running') {
|
|
175
|
+
this._hasActiveRun = true;
|
|
176
|
+
this._ensureRunPoll();
|
|
177
|
+
}
|
|
170
178
|
else if (s === 'waiting' && (this._hasActiveRun || prevStatus === 'running') && this._isOnScreen()) {
|
|
171
179
|
this._hasActiveRun = false;
|
|
172
180
|
playTaskCompletionClick();
|
|
@@ -175,6 +183,7 @@ export default {
|
|
|
175
183
|
},
|
|
176
184
|
'task.moved': e => this._handleTaskMoved(e.detail?.value || e.detail),
|
|
177
185
|
'chat.done': () => {
|
|
186
|
+
this._lastWsEvent = Date.now();
|
|
178
187
|
if (this._hasActiveRun && this._isOnScreen()) playTaskCompletionClick();
|
|
179
188
|
this._hasActiveRun = false;
|
|
180
189
|
this._reload();
|
|
@@ -182,6 +191,7 @@ export default {
|
|
|
182
191
|
};
|
|
183
192
|
for (const [k, fn] of Object.entries(this._h)) n.listen(k, fn);
|
|
184
193
|
this._reload();
|
|
194
|
+
this._ensureRunPoll();
|
|
185
195
|
this.ownerPoint = null;
|
|
186
196
|
Promise.resolve(n.$class).catch(() => null).then(async pt => {
|
|
187
197
|
if (!pt) pt = await Promise.resolve(n.$owner).catch(() => null);
|
|
@@ -191,7 +201,27 @@ export default {
|
|
|
191
201
|
if (this._bound === n && l) this.look = l;
|
|
192
202
|
}).catch(() => {});
|
|
193
203
|
},
|
|
204
|
+
_ensureRunPoll() {
|
|
205
|
+
if (this._runPollTimer) return;
|
|
206
|
+
this._runPollTimer = setInterval(() => {
|
|
207
|
+
if (!this._bound) {
|
|
208
|
+
clearInterval(this._runPollTimer);
|
|
209
|
+
this._runPollTimer = null;
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
const active = this.status === 'running' || this.starting || Boolean(this.optimistic);
|
|
213
|
+
if (!active) {
|
|
214
|
+
clearInterval(this._runPollTimer);
|
|
215
|
+
this._runPollTimer = null;
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
if (Date.now() - (this._lastWsEvent || 0) >= 1200)
|
|
219
|
+
this._reload();
|
|
220
|
+
}, 1400);
|
|
221
|
+
},
|
|
194
222
|
_unbindItem() {
|
|
223
|
+
clearInterval(this._runPollTimer);
|
|
224
|
+
this._runPollTimer = null;
|
|
195
225
|
const n = this._bound;
|
|
196
226
|
if (n && this._h) for (const [k, fn] of Object.entries(this._h)) n.unlisten(k, fn);
|
|
197
227
|
this._bound = null;
|
|
@@ -576,9 +606,12 @@ export default {
|
|
|
576
606
|
do {
|
|
577
607
|
this._again = false;
|
|
578
608
|
try {
|
|
579
|
-
const
|
|
609
|
+
const stateRes = await this.$item?.fetch?.('state').catch(() => null);
|
|
610
|
+
const isLiveObj = Boolean(stateRes && typeof stateRes === 'object' && 'body' in stateRes);
|
|
611
|
+
const raw = isLiveObj ? stateRes.body : await this.$item?.load();
|
|
580
612
|
this.missing = false;
|
|
581
613
|
const data = typeof raw === 'string' ? JSON.parse(raw || '{}') : raw || {};
|
|
614
|
+
const isRunning = isLiveObj ? Boolean(stateRes.running) : (data.status === 'running');
|
|
582
615
|
const done = new Set((data.items || []).filter(i => i.type === 'assistant' && (i.durationMs || i.stopped || i.interrupted)).map(i => i.id));
|
|
583
616
|
if (Object.keys(this.streams).some(id => done.has(id))) {
|
|
584
617
|
const s = {};
|
|
@@ -588,8 +621,17 @@ export default {
|
|
|
588
621
|
const before = this._docKeys;
|
|
589
622
|
const prevComputerUsed = Boolean(this._cu?.used);
|
|
590
623
|
this.data = data;
|
|
591
|
-
|
|
592
|
-
|
|
624
|
+
const hasAssistant = (data.items || []).some(i => i.type === 'assistant');
|
|
625
|
+
const recentStart = Boolean(data.created && (Date.now() - (+data.created || 0) < 15000) && !hasAssistant);
|
|
626
|
+
this.status = isRunning
|
|
627
|
+
? (data.status === 'waiting' ? 'waiting' : 'running')
|
|
628
|
+
: (data.status && data.status !== 'idle'
|
|
629
|
+
? data.status
|
|
630
|
+
: ((this.optimistic || (recentStart && data.status !== 'error' && data.status !== 'stopped')) ? 'running' : (data.status || 'idle')));
|
|
631
|
+
if (this.status === 'running') {
|
|
632
|
+
this._hasActiveRun = true;
|
|
633
|
+
this._ensureRunPoll();
|
|
634
|
+
}
|
|
593
635
|
this._lastDelta = Date.now();
|
|
594
636
|
this._noticeDocs(before);
|
|
595
637
|
if (this.computer.used) {
|
|
@@ -438,9 +438,8 @@ export default {
|
|
|
438
438
|
this.bookmarks = validItems;
|
|
439
439
|
const activeUrl = parsed.activeUrl || validItems.at(-1)?.url || '';
|
|
440
440
|
setTimeout(() => {
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
}, 1200);
|
|
441
|
+
this._verifyBookmarksAlive();
|
|
442
|
+
}, 600);
|
|
444
443
|
return {
|
|
445
444
|
activeUrl,
|
|
446
445
|
items: validItems,
|
|
@@ -450,6 +449,47 @@ export default {
|
|
|
450
449
|
return null;
|
|
451
450
|
}
|
|
452
451
|
},
|
|
452
|
+
async _verifyBookmarksAlive() {
|
|
453
|
+
if (!WORK?.uid && !WORK?.DEV_MODE)
|
|
454
|
+
return;
|
|
455
|
+
const list = Array.isArray(this.bookmarks) ? [...this.bookmarks] : [];
|
|
456
|
+
if (!list.length)
|
|
457
|
+
return;
|
|
458
|
+
const deadUrls = new Set();
|
|
459
|
+
await Promise.all(list.map(async (entry) => {
|
|
460
|
+
const short = entry?.short;
|
|
461
|
+
if (!short || short === '/')
|
|
462
|
+
return;
|
|
463
|
+
try {
|
|
464
|
+
const url = location.origin + (short.startsWith('/') ? short : '/' + short);
|
|
465
|
+
await WORK.fetch(url, 'info', {});
|
|
466
|
+
await this._hydrateBookmarkMeta(entry, { cachedOnly: true });
|
|
467
|
+
}
|
|
468
|
+
catch (err) {
|
|
469
|
+
const msg = String(err?.message || err || '');
|
|
470
|
+
const isServerMissing = err?.name === 'WORK_ServerError'
|
|
471
|
+
|| /not found|enoent|не найден|отсутств|удален|удалён|доступ запрещ|нет доступа|404/i.test(msg);
|
|
472
|
+
if (isServerMissing && entry?.url)
|
|
473
|
+
deadUrls.add(entry.url);
|
|
474
|
+
}
|
|
475
|
+
}));
|
|
476
|
+
if (!deadUrls.size)
|
|
477
|
+
return;
|
|
478
|
+
for (const u of deadUrls)
|
|
479
|
+
this.pages.remove(u);
|
|
480
|
+
const nextList = (this.bookmarks || []).filter(b => b && !deadUrls.has(b.url));
|
|
481
|
+
this.bookmarks = nextList;
|
|
482
|
+
this._saveBookmarksState();
|
|
483
|
+
if (deadUrls.has(this.focusedPage)) {
|
|
484
|
+
const next = nextList.at(-1);
|
|
485
|
+
if (next)
|
|
486
|
+
this.activateBookmark(next);
|
|
487
|
+
else {
|
|
488
|
+
this.focusedPage = '';
|
|
489
|
+
this.render?.();
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
},
|
|
453
493
|
async _hydrateBookmarkMeta(entry, { cachedOnly = false } = {}) {
|
|
454
494
|
if (!entry?.short)
|
|
455
495
|
return;
|
|
@@ -849,6 +889,12 @@ export default {
|
|
|
849
889
|
this._refreshSupportBadge();
|
|
850
890
|
this._syncExplorerTreeScope();
|
|
851
891
|
this.$('#consultant')?._refreshUserScope?.();
|
|
892
|
+
if (WORK.uid || WORK.DEV_MODE) {
|
|
893
|
+
if (!this.bookmarks?.length)
|
|
894
|
+
this._restoreBookmarksState();
|
|
895
|
+
else
|
|
896
|
+
this._verifyBookmarksAlive();
|
|
897
|
+
}
|
|
852
898
|
this.render?.();
|
|
853
899
|
});
|
|
854
900
|
if (!this._onNodeDeleted && WORK.chatEvents) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "odant-work",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.110",
|
|
4
4
|
"description": "ODANT-WORK — платформа цифровой организации (встроенная система учёта, документооборот, управление процессами и приватный мультимодальный ИИ)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "sources/work.js",
|
package/sources/client.js
CHANGED