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.
Files changed (56) hide show
  1. package/$server/$folder/$class/$structure/$user/handlers/pages/form/system/agent/$handler/class.js +11 -1
  2. package/$server/$folder/$class/$structure/$user/handlers/pages/form/system/messengers/$handler/class.js +11 -1
  3. package/$server/$folder/$class/$structure/$user/handlers/pages/form/system/settings/$handler/class.js +292 -0
  4. package/$server/$folder/$class/$structure/$user/handlers/pages/form/system/skills/$handler/class.js +11 -1
  5. package/$server/$folder/$class/$structure/handlers/pages/form/chat/$handler/chat-task.js +17 -6
  6. package/$server/$folder/$class/$structure/handlers/pages/form/chat/$handler/class.js +24 -2
  7. package/$server/$folder/$class/$structure/handlers/pages/form/system/agent/$handler/class.js +14 -11
  8. package/$server/$folder/$file/$html/handlers/preview/$handler/preview.js +7 -0
  9. package/$server/$folder/$file/$image/handlers/preview/$handler/preview.js +11 -0
  10. package/$server/$folder/$file/$md/handlers/preview/$handler/preview.js +29 -8
  11. package/$server/$folder/$file/$office/handlers/preview/$handler/preview.js +6 -0
  12. package/$server/$folder/$file/$task/handlers/pages/form/file/$handler/class.js +65 -10
  13. package/$server/$folder/$file/$task/handlers/pages/form/file/$handler/ui/feed.js +14 -11
  14. package/$server/$folder/$file/$task/handlers/pages/form/file/$handler/ui/util.js +32 -0
  15. package/$server/$folder/$file/$task/handlers/preview/$handler/preview.js +1 -0
  16. package/$server/$folder/$file/$txt/handlers/preview/$handler/preview.js +9 -0
  17. package/$server/$folder/$file/$video/handlers/preview/$handler/preview.js +15 -0
  18. package/$server/$folder/handlers/pages/form/$handler/class.js +10 -2
  19. package/$server/$folder/handlers/pages/form/folder/$handler/class.js +523 -25
  20. package/$server/$folder/lib/consultant/consultant.js +80 -3
  21. package/$server/$folder/lib/explorer/explorer.js +63 -0
  22. package/$server/$folder/lib/tree/tree.js +47 -16
  23. package/NODES/$node/handlers/pages/form/network/$handler/class.js +552 -36
  24. package/autostart.bat +28 -0
  25. package/autostart.sh +17 -0
  26. package/oda/components/icon/icon.js +20 -7
  27. package/package.json +1 -1
  28. package/run.mjs +19 -0
  29. package/scripts/autostart.mjs +281 -0
  30. package/scripts/watchdog.mjs +496 -0
  31. package/sources/client.js +146 -2
  32. package/sources/host/auth-methods.js +2 -0
  33. package/sources/host/auto-updater.js +23 -1
  34. package/sources/host/http-server.js +5 -3
  35. package/sources/host/push.js +43 -14
  36. package/sources/host/websocket.js +69 -3
  37. package/sources/modules/agent/index.js +50 -19
  38. package/sources/modules/agent/permissions.js +4 -2
  39. package/sources/modules/agent/scope.js +72 -5
  40. package/sources/modules/agent/session.js +97 -14
  41. package/sources/modules/agent/tools/work/classes.js +16 -1
  42. package/sources/modules/license/index.js +120 -0
  43. package/sources/modules/nodes/registry.js +57 -7
  44. package/sources/modules/trainer/local-engine.js +22 -9
  45. package/sources/modules/user-profile/user-tokens.js +426 -85
  46. package/sources/server/access/gateway.js +3 -1
  47. package/sources/server/class/feed.js +6 -0
  48. package/sources/server/folder.js +5 -1
  49. package/sources/server/node.js +16 -0
  50. package/sources/server/server.js +59 -1
  51. package/sources/server/user.js +48 -0
  52. package/start.bat +25 -0
  53. package/start.sh +27 -0
  54. package/stop.bat +25 -0
  55. package/stop.sh +16 -0
  56. package/sw.js +3 -11
@@ -12,7 +12,7 @@ import './ui/dock.js';
12
12
  import './ui/voice-ui.js';
13
13
  import { VoiceController } from './ui/voice.js';
14
14
  import { collectDocs, computeStats, stableDocs, activityOf, taskFiles, computerUse, realPathOfSnapshot } from './ui/docs.js';
15
- import { pathOfWorkHref, workHref } from './ui/util.js';
15
+ import { pathOfWorkHref, workHref, playTaskCompletionClick } from './ui/util.js';
16
16
 
17
17
  /**
18
18
  * Клик по WORK-ссылке в markdown (событие md-link от oda-markdown-viewer):
@@ -56,6 +56,10 @@ export default {
56
56
  padding: 6px 14px; border-radius: 999px; font-size: small; @apply --raised; @apply --content;
57
57
  }
58
58
  .legacy { @apply --muted; font-size: x-small; text-align: center; padding-bottom: 12px; }
59
+ .missing {
60
+ padding: 10px 14px; border-radius: var(--radius-m); border: 1px solid var(--subtle-border);
61
+ background: var(--code-background); @apply --muted; font-size: small; text-align: center; margin-top: 8px;
62
+ }
59
63
  </style>
60
64
  <div class="main" flex vertical ~if="showMain">
61
65
  <microchat-header no-flex ~if="!inForm"></microchat-header>
@@ -63,12 +67,13 @@ export default {
63
67
  <div class="col">
64
68
  <div class="legacy" ~if="data?.legacy">Задача из прежней версии агента — показана упрощённо; продолжить можно как обычно.</div>
65
69
  <microchat-feed :items="feedItems"></microchat-feed>
66
- <div class="working" ~if="activity">
70
+ <div class="missing" ~if="missing">Задача или её узел удалены.</div>
71
+ <div class="working" ~if="activity && !missing">
67
72
  <oda-icon icon="spinners:3-dots-scale" :icon-size="16"></oda-icon><span>{{activity.text}}</span>
68
73
  </div>
69
74
  </div>
70
75
  </div>
71
- <div class="bottom" vertical no-flex>
76
+ <div class="bottom" vertical no-flex ~if="!missing">
72
77
  <oda-button class="down" ~if="!pinned && !needsHuman" icon="carbon:arrow-down" :icon-size="18" title="К последнему" @tap="toBottom"></oda-button>
73
78
  <oda-button class="down attn" ~if="!pinned && needsHuman" accent-invert icon="carbon:arrow-down" :icon-size="16" label="Агент ждёт вас" title="Перейти к вопросу или разрешению" @tap="toBottom"></oda-button>
74
79
  <microchat-todos ~if="showTodos" :todos="data.todos"></microchat-todos>
@@ -83,6 +88,7 @@ export default {
83
88
  data: null,
84
89
  streams: {},
85
90
  status: 'idle',
91
+ missing: false,
86
92
  optimistic: null,
87
93
  toastText: '',
88
94
  pinned: true,
@@ -146,19 +152,33 @@ export default {
146
152
  this.computerChecked = false;
147
153
  }
148
154
  this._bound = n || null;
155
+ this._hasActiveRun = false;
149
156
  if (!n) return;
150
157
  this._h = {
151
158
  'changed': () => this._reload(),
152
159
  'task.delta': e => this._onDelta(e.detail?.value),
160
+ 'chat.start': () => {
161
+ this._hasActiveRun = true;
162
+ },
153
163
  'task.state': e => {
154
164
  const s = e.detail?.value?.status;
155
165
  if (s) {
166
+ const prevStatus = this.status;
156
167
  this.status = s;
157
168
  this._lastDelta = Date.now();
169
+ if (s === 'running') this._hasActiveRun = true;
170
+ else if (s === 'waiting' && (this._hasActiveRun || prevStatus === 'running') && this._isOnScreen()) {
171
+ this._hasActiveRun = false;
172
+ playTaskCompletionClick();
173
+ }
158
174
  }
159
175
  },
160
176
  'task.moved': e => this._handleTaskMoved(e.detail?.value || e.detail),
161
- 'chat.done': () => this._reload()
177
+ 'chat.done': () => {
178
+ if (this._hasActiveRun && this._isOnScreen()) playTaskCompletionClick();
179
+ this._hasActiveRun = false;
180
+ this._reload();
181
+ }
162
182
  };
163
183
  for (const [k, fn] of Object.entries(this._h)) n.listen(k, fn);
164
184
  this._reload();
@@ -183,7 +203,7 @@ export default {
183
203
  */
184
204
  _watchPresence() {
185
205
  this._presenceIO ??= new IntersectionObserver(entries => {
186
- if (entries.some(e => e.isIntersecting)) this._notifyPresence();
206
+ this._notifyPresence(entries.some(e => e.isIntersecting));
187
207
  });
188
208
  this._presenceIO.observe(this);
189
209
  this._presenceOnVis = () => this._notifyPresence();
@@ -192,10 +212,11 @@ export default {
192
212
  // (в чате адрес не содержит путь задачи — сравнивать URL недостаточно)
193
213
  this._presenceOnSw = e => {
194
214
  const msg = e?.data;
215
+ const port = e?.ports?.[0] || msg?.port;
195
216
  const mine = this._bound?.path || this.$item?.path;
196
- if (msg?.type !== 'work:is-task-visible' || !msg.port || !mine || msg.path !== mine) return;
217
+ if (msg?.type !== 'work:is-task-visible' || !port || !mine || msg.path !== mine) return;
197
218
  if (this._isOnScreen()) try {
198
- msg.port.postMessage({
219
+ port.postMessage({
199
220
  visible: true
200
221
  });
201
222
  } catch {/* порт закрыт */}
@@ -204,6 +225,8 @@ export default {
204
225
  this.async(() => this._notifyPresence(), 150);
205
226
  },
206
227
  _unwatchPresence() {
228
+ const p = this._bound?.path || this.$item?.path;
229
+ if (p) globalThis.WORK?.setTaskPresence?.(p, false);
207
230
  this._presenceIO?.disconnect();
208
231
  this._presenceIO = null;
209
232
  if (this._presenceOnVis) document.removeEventListener('visibilitychange', this._presenceOnVis);
@@ -220,9 +243,12 @@ export default {
220
243
  h = window.innerHeight || 0;
221
244
  return r.bottom > 0 && r.right > 0 && r.top < h && r.left < w;
222
245
  },
223
- _notifyPresence() {
246
+ _notifyPresence(intersecting) {
224
247
  const path = this._bound?.path || this.$item?.path;
225
- if (!path || document.visibilityState !== 'visible') return;
248
+ if (!path) return;
249
+ const visible = intersecting === false ? false : this._isOnScreen();
250
+ globalThis.WORK?.setTaskPresence?.(path, visible);
251
+ if (!visible) return;
226
252
  try {
227
253
  navigator.serviceWorker?.ready?.then(reg => reg.active?.postMessage({
228
254
  type: 'work:task-visible',
@@ -273,8 +299,25 @@ export default {
273
299
  }, 50);
274
300
  this._startPcPoll();
275
301
  this._watchPresence();
302
+ if (!this._onNodeDeleted && WORK.chatEvents) {
303
+ this._onNodeDeleted = ev => {
304
+ const delPath = String(ev?.detail?.path || '').replace(/\/+$/, '');
305
+ const mine = String(this._bound?.path || this.$item?.path || '').replace(/\/+$/, '');
306
+ if (delPath && mine && (mine === delPath || mine.startsWith(delPath + '/'))) {
307
+ this.missing = true;
308
+ this.status = 'idle';
309
+ this._hasActiveRun = false;
310
+ this.optimistic = null;
311
+ }
312
+ };
313
+ WORK.chatEvents.addEventListener('node.deleted', this._onNodeDeleted);
314
+ }
276
315
  },
277
316
  detached() {
317
+ if (this._onNodeDeleted && WORK.chatEvents) {
318
+ WORK.chatEvents.removeEventListener('node.deleted', this._onNodeDeleted);
319
+ this._onNodeDeleted = null;
320
+ }
278
321
  this._unbindItem();
279
322
  this._unwatchPresence();
280
323
  this._voice?.disable();
@@ -496,6 +539,7 @@ export default {
496
539
  }
497
540
  };
498
541
  this._lastDelta = Date.now();
542
+ this._hasActiveRun = true;
499
543
  if (this.status !== 'running') this.status = 'running';
500
544
  if (/^(?:computer_|sandbox_)/.test(String(d.name || '')) && d.name !== 'computer_destroy') this._openMonitorOnce();
501
545
  this._stick();
@@ -533,6 +577,7 @@ export default {
533
577
  this._again = false;
534
578
  try {
535
579
  const raw = await this.$item?.load();
580
+ this.missing = false;
536
581
  const data = typeof raw === 'string' ? JSON.parse(raw || '{}') : raw || {};
537
582
  const done = new Set((data.items || []).filter(i => i.type === 'assistant' && (i.durationMs || i.stopped || i.interrupted)).map(i => i.id));
538
583
  if (Object.keys(this.streams).some(id => done.has(id))) {
@@ -544,6 +589,7 @@ export default {
544
589
  const prevComputerUsed = Boolean(this._cu?.used);
545
590
  this.data = data;
546
591
  this.status = data.status || 'idle';
592
+ if (this.status === 'running') this._hasActiveRun = true;
547
593
  this._lastDelta = Date.now();
548
594
  this._noticeDocs(before);
549
595
  if (this.computer.used) {
@@ -555,6 +601,14 @@ export default {
555
601
  this._voice?.onData(data);
556
602
  tries = 0;
557
603
  } catch (e) {
604
+ const msg = String(e?.message || e || '');
605
+ if (/not found|ENOENT|404/i.test(msg)) {
606
+ this.missing = true;
607
+ this.status = 'idle';
608
+ this._hasActiveRun = false;
609
+ this.optimistic = null;
610
+ break;
611
+ }
558
612
  if (++tries > 5) break;
559
613
  this._again = true;
560
614
  await new Promise(r => setTimeout(r, 300 * tries));
@@ -672,6 +726,7 @@ export default {
672
726
  };
673
727
  this.pinned = true;
674
728
  this.status = 'running';
729
+ this._hasActiveRun = true;
675
730
  this._stick();
676
731
  },
677
732
  toast(text) {
@@ -689,7 +744,7 @@ export default {
689
744
  try {
690
745
  navigator.serviceWorker.controller.postMessage({
691
746
  type: 'work:task-visible',
692
- task: this.$item.path
747
+ path: this.$item.path
693
748
  });
694
749
  } catch {/* ignore */}
695
750
  }
@@ -350,6 +350,11 @@ ODA({ is: 'microchat-tool',
350
350
  .btns { @apply --horizontal; flex-wrap: wrap; gap: 8px; }
351
351
  .btns oda-button { border-radius: var(--radius-s); padding: 4px 12px; box-sizing: border-box; }
352
352
  .btns .help-btn { padding: 4px 9px; font-weight: 700; min-width: 28px; }
353
+ .always-chk {
354
+ @apply --horizontal; align-items: center; gap: 6px;
355
+ font-size: x-small; @apply --muted; cursor: pointer; user-select: none;
356
+ }
357
+ .always-chk input { width: auto; margin: 0; padding: 0; accent-color: var(--accent-color); cursor: pointer; }
353
358
  .auto-tag { padding: 1px 6px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-color); font-weight: 600; }
354
359
  .explain-box {
355
360
  padding: 8px 10px;
@@ -407,13 +412,15 @@ ODA({ is: 'microchat-tool',
407
412
  <div class="ask" ~if="isApproval">
408
413
  <div class="q">Разрешить «{{meta.label}}»{{target ? ': ' + target : ''}}?</div>
409
414
  <div class="why" ~if="data?.reason">{{data.reason}}</div>
415
+ <label class="always-chk" ~if="!data?.noAlways">
416
+ <input type="checkbox" :checked="rememberInTask" @change="rememberInTask = $event.target.checked">
417
+ <span>Больше не спрашивать в этой задаче{{alwaysScopeText ? ' (' + alwaysScopeText + ')' : ''}}</span>
418
+ </label>
410
419
  <div class="btns">
411
- <oda-button hide-icon accent-invert label="Разрешить" @tap="approve(true)"></oda-button>
412
- <oda-button hide-icon class="ghost" ~if="!data?.noAlways" :label="alwaysBtnLabel" :title="alwaysBtnTitle" @tap="approve(true, true)"></oda-button>
413
- <oda-button hide-icon class="ghost danger" label="Отклонить" @tap="approve(false)"></oda-button>
420
+ <oda-button hide-icon accent-invert label="Разрешить" @tap="approve(true, rememberInTask)"></oda-button>
421
+ <oda-button hide-icon class="ghost danger" label="Отклонить" @tap="approve(false, false)"></oda-button>
414
422
  <oda-button hide-icon class="ghost help-btn" label="?" :disabled="explainLoading" title="Кратко объяснить действие и последствия с помощью ИИ" @tap="toggleExplain()"></oda-button>
415
423
  </div>
416
- <div class="why" ~if="!data?.noAlways && data?.approvalLabel">Общее разрешение: {{data.approvalLabel}}</div>
417
424
  <div class="explain-box" ~if="explainLoading">Анализирую действие…</div>
418
425
  <div class="explain-err" ~if="explainError && !explainLoading">{{explainError}}</div>
419
426
  <div class="explain-box" ~if="explainOpen && !explainLoading && explainText">
@@ -685,16 +692,12 @@ ODA({ is: 'microchat-tool',
685
692
  explainLoading: false,
686
693
  explainError: '',
687
694
  explainLocal: '',
695
+ rememberInTask: false,
688
696
  get explainText() {
689
697
  return this.explainLocal || this.data?.explanation || '';
690
698
  },
691
- get alwaysBtnLabel() {
692
- return this.data?.alwaysLabel || 'Разрешить подобные';
693
- },
694
- get alwaysBtnTitle() {
695
- return this.data?.approvalLabel
696
- ? 'Не спрашивать в этой задаче: ' + this.data.approvalLabel
697
- : 'Не спрашивать про «' + (this.meta?.label || '') + '» в этой задаче';
699
+ get alwaysScopeText() {
700
+ return String(this.data?.approvalLabel || '').trim();
698
701
  },
699
702
  async toggleExplain() {
700
703
  if (this.explainLoading)
@@ -546,3 +546,35 @@ export function resultMarkdown(t) {
546
546
  return r;
547
547
  return '```\n' + r.replace(/```/g, '``\u200b`') + '\n```';
548
548
  }
549
+
550
+ let _clickAudioCtx = null;
551
+ /** Тихий короткий звуковой щелчок по завершении ответа или переходе в ожидание при открытом чате. */
552
+ export function playTaskCompletionClick() {
553
+ try {
554
+ if (globalThis.WORK?.userSettings?.chatSound === false)
555
+ return false;
556
+ const AC = globalThis.AudioContext || globalThis.webkitAudioContext;
557
+ if (!AC)
558
+ return false;
559
+ const ctx = _clickAudioCtx ??= new AC();
560
+ if (ctx.state === 'suspended')
561
+ ctx.resume?.().catch(() => {});
562
+ const now = ctx.currentTime;
563
+ const osc = ctx.createOscillator();
564
+ const gain = ctx.createGain();
565
+ osc.type = 'triangle';
566
+ osc.frequency.setValueAtTime(920, now);
567
+ osc.frequency.exponentialRampToValueAtTime(420, now + 0.032);
568
+ gain.gain.setValueAtTime(0.001, now);
569
+ gain.gain.linearRampToValueAtTime(0.055, now + 0.004);
570
+ gain.gain.exponentialRampToValueAtTime(0.0001, now + 0.038);
571
+ osc.connect(gain);
572
+ gain.connect(ctx.destination);
573
+ osc.start(now);
574
+ osc.stop(now + 0.042);
575
+ return true;
576
+ }
577
+ catch {
578
+ return false;
579
+ }
580
+ }
@@ -36,6 +36,7 @@ export default {
36
36
  template: /*html*/ `
37
37
  <style>
38
38
  :host { @apply --vertical; gap: 6px; padding: 8px 10px; min-width: 0; overflow: hidden; }
39
+ :host([full-height]) { height: 100%; overflow: auto; box-sizing: border-box; }
39
40
  .bar {
40
41
  @apply --horizontal; align-items: center; gap: 8px; font-size: small; min-width: 0;
41
42
  padding: 6px 10px; border-radius: var(--radius-m, 8px); position: relative; overflow: hidden;
@@ -5,6 +5,12 @@ export default{
5
5
  @apply --vertical;
6
6
  padding: 4px 16px;
7
7
  }
8
+ :host([full-height]) {
9
+ height: 100%;
10
+ overflow: auto;
11
+ padding: 10px 16px;
12
+ box-sizing: border-box;
13
+ }
8
14
  div {
9
15
  white-space: break-spaces;
10
16
  padding-top: 4px;
@@ -15,6 +21,9 @@ export default{
15
21
  -ms-user-select: text; /* Для старых версий Internet Explorer */
16
22
  user-select: text; /* Стандартное свойство */
17
23
  }
24
+ :host([full-height]) div {
25
+ overflow: visible;
26
+ }
18
27
  </style>
19
28
  <div flex ~html="value"></div>
20
29
  `,
@@ -5,6 +5,21 @@ export default {
5
5
  :host {
6
6
  background-color: black;
7
7
  }
8
+ :host([full-height]) {
9
+ display: flex;
10
+ width: 100%;
11
+ height: 100%;
12
+ justify-content: center;
13
+ align-items: center;
14
+ overflow: hidden;
15
+ }
16
+ :host([full-height]) video {
17
+ width: 100%;
18
+ height: 100%;
19
+ max-width: 100%;
20
+ max-height: 100%;
21
+ object-fit: contain;
22
+ }
8
23
  </style>
9
24
  <video :src width="300" height="200" muted controls style="align-self: center;"></video>
10
25
  `,
@@ -1217,8 +1217,16 @@ ODA({is: 'work-form',
1217
1217
  return localCons;
1218
1218
  },
1219
1219
  openView(e) {
1220
- if (e.button === 0 && this.view)
1221
- window.open(this.view.short + '/');
1220
+ if (e.button === 0 && this.view) {
1221
+ const target = this.currentItem || this.$item;
1222
+ const short = String(target?.short || target?.path || '').replace(/\/+$/, '');
1223
+ const base = short === '/' ? '' : short;
1224
+ const sub = (this.view_control?.localName === 'work-subview-container' && this.view_control?.activeId)
1225
+ ? '/' + this.view_control.activeId
1226
+ : '';
1227
+ const viewSeg = this.view.id ? ('/' + this.view.id + sub) : '';
1228
+ window.open(encodeURI(base + '/~/handlers/pages/form' + viewSeg + '/index.html'));
1229
+ }
1222
1230
  },
1223
1231
  back(e) {
1224
1232
  alert('надо скрыть')