odant-work 1.0.71 → 1.0.73
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 +30 -27
- package/$server/$folder/$class/$structure/handlers/pages/form/calendar/$handler/calendar.js +1004 -1011
- package/$server/$folder/$class/$structure/handlers/pages/form/chat/$handler/chat.js +51 -23
- package/$server/$folder/$class/$structure/handlers/pages/form/email/$handler/class.js +7 -90
- package/$server/$folder/$class/$structure/handlers/pages/form/email/$handler/email.js +913 -705
- package/$server/$folder/$class/$structure/handlers/pages/form/email/$handler/methods/refresh/$method/class.js +30 -1
- package/$server/$folder/$class/$structure/handlers/pages/form/search/$handler/class.js +10 -0
- package/$server/$folder/$class/$structure/handlers/pages/form/{system/$handler/tabs → search/$handler}/search.js +14 -0
- package/$server/$folder/$class/$structure/handlers/pages/form/system/$handler/system.js +53 -30
- package/$server/$folder/$class/$structure/handlers/pages/form/system/$handler/tabs/staff.js +1 -1
- package/$server/$folder/$class/ai/skills/email-mailbox.md +10 -7
- package/$server/$folder/$class/ai/skills/meeting-minutes.md +1 -1
- package/$server/$folder/$file/$eml/triggers/on_save/$trigger/class.js +17 -1
- package/$server/$folder/$file/$task/handlers/pages/form/file/$handler/ui/voice-ui.js +5 -5
- package/$server/$folder/lib/calendar-form/calendar-form.js +482 -296
- package/$server/$folder/lib/tree/tree.js +1 -1
- package/oda/oda.js +8 -4
- package/package.json +1 -1
- package/sources/client.js +42 -6
- package/sources/host/email-utils.js +25 -1
- package/sources/modules/agent/index.js +3 -1
- package/sources/modules/agent/node-rules.js +60 -3
- package/sources/modules/agent/scheduler.js +7 -0
- package/sources/modules/agent/tools/calendar-mail.js +273 -0
- package/sources/server/access/gateway.js +3 -0
- package/sources/server/chat-threads.js +77 -23
- package/sources/server/class/feed.js +46 -0
- package/sources/server/class/mail-calendar.js +867 -0
|
@@ -536,7 +536,7 @@ export default {
|
|
|
536
536
|
return;
|
|
537
537
|
const target = this.$item || globalThis.WORK;
|
|
538
538
|
if (target && typeof window?.execute === 'function')
|
|
539
|
-
window.execute(target, { view: '
|
|
539
|
+
window.execute(target, { view: 'search', q });
|
|
540
540
|
},
|
|
541
541
|
_onTreeScroll() {
|
|
542
542
|
if (this._scrollRaf)
|
package/oda/oda.js
CHANGED
|
@@ -184,10 +184,14 @@ Node:{
|
|
|
184
184
|
Node.prototype.render = function (wake) {
|
|
185
185
|
if (!this.__vnode__ || !this.isConnected)
|
|
186
186
|
return;
|
|
187
|
-
this.throttle('render', ()=>{
|
|
188
|
-
|
|
189
|
-
if(
|
|
190
|
-
|
|
187
|
+
this.throttle('render', async ()=>{
|
|
188
|
+
let el = this.__vnode__.render(this) || this;
|
|
189
|
+
if (el?.then)
|
|
190
|
+
el = (await el) || this;
|
|
191
|
+
if (!el?.isConnected)
|
|
192
|
+
return;
|
|
193
|
+
if (!el?.[R]?.states?.sleep || wake)
|
|
194
|
+
if (el?.nodeType === 1)
|
|
191
195
|
el.renderChildren(wake);
|
|
192
196
|
})
|
|
193
197
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "odant-work",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.73",
|
|
4
4
|
"description": "ODANT-WORK — платформа цифровой организации (встроенная система учёта, документооборот, управление процессами и приватный мультимодальный ИИ)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "sources/work.js",
|
package/sources/client.js
CHANGED
|
@@ -480,6 +480,37 @@ WORK.login = async function(force = false){
|
|
|
480
480
|
WORK.notifyAuth?.({ uid: '', reason: 'logout' });
|
|
481
481
|
})();
|
|
482
482
|
}
|
|
483
|
+
WORK.applyChatReadLocal = function ({ threadId = '', kind = '', nodePath = '', peerId = '' } = {}) {
|
|
484
|
+
const u = WORK.chatUnread;
|
|
485
|
+
if (!u)
|
|
486
|
+
return;
|
|
487
|
+
let delta = 0;
|
|
488
|
+
if (threadId && u.byThread?.[threadId]) {
|
|
489
|
+
delta = Number(u.byThread[threadId]) || 0;
|
|
490
|
+
delete u.byThread[threadId];
|
|
491
|
+
}
|
|
492
|
+
const normNode = nodePath ? String(nodePath).replace(/\/+$/, '') || '/' : '';
|
|
493
|
+
if ((kind === 'twin' || normNode) && normNode && u.byNode?.[normNode]) {
|
|
494
|
+
const prevNode = Number(u.byNode[normNode]) || 0;
|
|
495
|
+
const drop = delta > 0 ? Math.min(prevNode, delta) : prevNode;
|
|
496
|
+
if (!delta) delta = drop;
|
|
497
|
+
const nextNode = prevNode - drop;
|
|
498
|
+
if (nextNode > 0) u.byNode[normNode] = nextNode;
|
|
499
|
+
else delete u.byNode[normNode];
|
|
500
|
+
}
|
|
501
|
+
if ((kind === 'dm' || peerId) && peerId && u.byPeer?.[peerId]) {
|
|
502
|
+
const prevPeer = Number(u.byPeer[peerId]) || 0;
|
|
503
|
+
const drop = delta > 0 ? Math.min(prevPeer, delta) : prevPeer;
|
|
504
|
+
if (!delta) delta = drop;
|
|
505
|
+
const nextPeer = prevPeer - drop;
|
|
506
|
+
if (nextPeer > 0) u.byPeer[peerId] = nextPeer;
|
|
507
|
+
else delete u.byPeer[peerId];
|
|
508
|
+
}
|
|
509
|
+
if (delta > 0)
|
|
510
|
+
u.total = Math.max(0, (Number(u.total) || 0) - delta);
|
|
511
|
+
WORK.chatEvents ??= new EventTarget();
|
|
512
|
+
WORK.chatEvents.dispatchEvent(new CustomEvent('chat:read', { detail: { threadId, kind, nodePath: normNode, peerId } }));
|
|
513
|
+
};
|
|
483
514
|
WORK.refreshChatUnread = async function () {
|
|
484
515
|
if (!WORK.uid || typeof WORK.fetch !== 'function')
|
|
485
516
|
return null;
|
|
@@ -638,14 +669,19 @@ class WebSocketEvents {
|
|
|
638
669
|
WORK.chatUnread ??= { total: 0, byThread: {}, byNode: {}, byPeer: {} };
|
|
639
670
|
if (data.threadId)
|
|
640
671
|
WORK.chatUnread.byThread[data.threadId] = (WORK.chatUnread.byThread[data.threadId] || 0) + 1;
|
|
641
|
-
if (data.kind === 'twin' && data.nodePath)
|
|
642
|
-
|
|
672
|
+
if (data.kind === 'twin' && data.nodePath) {
|
|
673
|
+
const np = String(data.nodePath).replace(/\/+$/, '') || '/';
|
|
674
|
+
WORK.chatUnread.byNode[np] = (WORK.chatUnread.byNode[np] || 0) + 1;
|
|
675
|
+
}
|
|
676
|
+
else if (data.kind === 'dm' && data.message?.sender) {
|
|
677
|
+
const peer = String(data.message.sender);
|
|
678
|
+
WORK.chatUnread.byPeer[peer] = (WORK.chatUnread.byPeer[peer] || 0) + 1;
|
|
679
|
+
}
|
|
643
680
|
WORK.chatUnread.total = (WORK.chatUnread.total || 0) + 1;
|
|
644
681
|
}
|
|
645
|
-
else if (data.type === 'chat:read' && data.threadId
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
WORK.chatUnread.total = Math.max(0, (WORK.chatUnread.total || 0) - prev);
|
|
682
|
+
else if (data.type === 'chat:read' && data.threadId) {
|
|
683
|
+
WORK.applyChatReadLocal?.(data);
|
|
684
|
+
break;
|
|
649
685
|
}
|
|
650
686
|
WORK.chatEvents.dispatchEvent(new CustomEvent(data.type, { detail: data }));
|
|
651
687
|
} break;
|
|
@@ -92,21 +92,43 @@ export function createMailboxTransport(box) {
|
|
|
92
92
|
});
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
export async function sendOutboxEml(box, data) {
|
|
95
|
+
export async function sendOutboxEml(box, data, opts = {}) {
|
|
96
96
|
const json = parseJsonEml(data);
|
|
97
97
|
const from = json.from || box.auth?.user || box.address;
|
|
98
98
|
const to = json.to;
|
|
99
99
|
if (!to)
|
|
100
100
|
throw new Error('Не указан получатель');
|
|
101
|
+
const attachments = [];
|
|
102
|
+
if (Array.isArray(json.attachments)) {
|
|
103
|
+
for (const att of json.attachments) {
|
|
104
|
+
if (!att) continue;
|
|
105
|
+
const filename = String(att.name || att.filename || 'file').trim() || 'file';
|
|
106
|
+
if (att.content != null) {
|
|
107
|
+
attachments.push({
|
|
108
|
+
filename,
|
|
109
|
+
content: att.content,
|
|
110
|
+
encoding: att.encoding || undefined,
|
|
111
|
+
contentType: att.contentType || undefined,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
else if (att.path && typeof opts.resolveAttachment === 'function') {
|
|
115
|
+
const resolved = await opts.resolveAttachment(att.path, att).catch(() => null);
|
|
116
|
+
if (resolved)
|
|
117
|
+
attachments.push({ filename, ...resolved });
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
101
121
|
const transport = createMailboxTransport(box);
|
|
102
122
|
await transport.sendMail({
|
|
103
123
|
from,
|
|
104
124
|
to,
|
|
125
|
+
cc: json.cc || undefined,
|
|
105
126
|
subject: json.subject || '(без темы)',
|
|
106
127
|
text: json.body || '',
|
|
107
128
|
html: json.html || undefined,
|
|
108
129
|
inReplyTo: json.inReplyTo || undefined,
|
|
109
130
|
references: json.inReplyTo || undefined,
|
|
131
|
+
...(attachments.length ? { attachments } : {}),
|
|
110
132
|
});
|
|
111
133
|
}
|
|
112
134
|
|
|
@@ -141,6 +163,8 @@ export function imapFolderToBox(imapPath) {
|
|
|
141
163
|
return '';
|
|
142
164
|
if (name === 'inbox')
|
|
143
165
|
return 'inbox';
|
|
166
|
+
if (/draft|черновик/.test(name))
|
|
167
|
+
return 'drafts';
|
|
144
168
|
if (/outbox|sent|отправленные/.test(name))
|
|
145
169
|
return 'outbox';
|
|
146
170
|
if (/trash|deleted|bin|удаленные/.test(name))
|
|
@@ -10,6 +10,7 @@ import { log } from './log.js';
|
|
|
10
10
|
import { runLoop, pickAllowedEffort } from './loop.js';
|
|
11
11
|
import { workTools, accountingTools, classTools, contextConeOf } from './tools/work.js';
|
|
12
12
|
import { twinTools } from './twin-bus.js';
|
|
13
|
+
import { calendarMailTools } from './tools/calendar-mail.js';
|
|
13
14
|
import { webTools, serviceTools, mcpTools } from './tools/services.js';
|
|
14
15
|
import { metaTools, listing, MAX_DEPTH } from './tools/meta.js';
|
|
15
16
|
import { connectTools } from './tools/connect.js';
|
|
@@ -449,7 +450,7 @@ export async function createEnv({ place, contextPath, session, host, tz, locatio
|
|
|
449
450
|
* restrict — ограничение call родителя, пережившее перезапуск (body.callRestrict дочерней задачи, R3/8.31).
|
|
450
451
|
*/
|
|
451
452
|
async makeTools(def, depth = 0, parent = null, restrict = null) {
|
|
452
|
-
let all = [...workTools, ...accountingTools, ...classTools, ...twinTools, ...devSearchTools, ...devPatchTools, ...devGitTools, ...devCheckTools, ...devLspTools, ...branchTools, ...pluginTools, ...docTools, ...memoryTools, ...webTools, ...connectTools, ...browseTools, ...metaTools, ...scheduleTools, ...await env.extTools()];
|
|
453
|
+
let all = [...workTools, ...accountingTools, ...classTools, ...twinTools, ...calendarMailTools, ...devSearchTools, ...devPatchTools, ...devGitTools, ...devCheckTools, ...devLspTools, ...branchTools, ...pluginTools, ...docTools, ...memoryTools, ...webTools, ...connectTools, ...browseTools, ...metaTools, ...scheduleTools, ...await env.extTools()];
|
|
453
454
|
// не-администратор этих инструментов даже не видит
|
|
454
455
|
if (await system())
|
|
455
456
|
all.push(...SYSTEM_TOOLS);
|
|
@@ -477,6 +478,7 @@ export async function createEnv({ place, contextPath, session, host, tz, locatio
|
|
|
477
478
|
'create_class', 'update_class', 'move_class', 'delete_class',
|
|
478
479
|
'assign', 'escalate', 'delete',
|
|
479
480
|
'twin_rule_list', 'twin_rule_save', 'twin_schedule_save',
|
|
481
|
+
'mail_send', 'mail_draft', 'mail_refresh',
|
|
480
482
|
'dev_write', 'dev_edit', 'dev_patch', 'dev_git', 'dev_shell',
|
|
481
483
|
'shell', 'restart_server', 'os_write', 'os_rm',
|
|
482
484
|
]);
|
|
@@ -223,14 +223,20 @@ export async function collectQuietDigest(storage) {
|
|
|
223
223
|
events.push(`Ожидает решения: «${String(a.content || '').slice(0, 90)}»`);
|
|
224
224
|
}
|
|
225
225
|
|
|
226
|
-
// 2. Неотвеченные обращения пользователей/клиентов в twin-диалогах этого узла
|
|
226
|
+
// 2. Неотвеченные текстовые обращения пользователей/клиентов в twin-диалогах этого узла (без .task-карточек, за последние 3 дня)
|
|
227
|
+
const threeDaysAgo = now - 3 * 86400_000;
|
|
227
228
|
const threads = db.prepare(`
|
|
228
229
|
SELECT id FROM chat_threads WHERE kind = 'twin' AND node_path = ?
|
|
229
230
|
`).all(nodePath);
|
|
230
231
|
let unansweredCount = 0;
|
|
231
232
|
for (const t of threads) {
|
|
232
|
-
const lastMsg = db.prepare('SELECT sender, created FROM chat_messages WHERE thread_id = ? ORDER BY id DESC LIMIT 1').get(t.id);
|
|
233
|
-
if (lastMsg
|
|
233
|
+
const lastMsg = db.prepare('SELECT sender, kind, task_path, created FROM chat_messages WHERE thread_id = ? ORDER BY id DESC LIMIT 1').get(t.id);
|
|
234
|
+
if (lastMsg
|
|
235
|
+
&& lastMsg.sender !== '$twin'
|
|
236
|
+
&& lastMsg.kind === 'text'
|
|
237
|
+
&& !lastMsg.task_path
|
|
238
|
+
&& Number(lastMsg.created) <= min15Ago
|
|
239
|
+
&& Number(lastMsg.created) >= threeDaysAgo)
|
|
234
240
|
unansweredCount++;
|
|
235
241
|
}
|
|
236
242
|
if (unansweredCount > 0)
|
|
@@ -308,3 +314,54 @@ export async function runQuietDigests({ now = Date.now(), nodes = null } = {}) {
|
|
|
308
314
|
}
|
|
309
315
|
return sent;
|
|
310
316
|
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Фоновая проверка входящей почты (IMAP) для узлов, у которых настроен хотя бы один ящик с imap.host
|
|
320
|
+
* и не отключён mailAutoRefresh.
|
|
321
|
+
*/
|
|
322
|
+
export async function runMailAutoRefresh({ nodes = null } = {}) {
|
|
323
|
+
const WORK = globalThis.WORK;
|
|
324
|
+
if (!WORK && !Array.isArray(nodes))
|
|
325
|
+
return [];
|
|
326
|
+
const list = Array.isArray(nodes) ? nodes : [WORK];
|
|
327
|
+
if (!Array.isArray(nodes) && WORK) {
|
|
328
|
+
const collectTargets = async (containerPath) => {
|
|
329
|
+
const c = await WORK.get_item(containerPath).catch(() => null);
|
|
330
|
+
const items = (await c?.items) || [];
|
|
331
|
+
for (const item of items) {
|
|
332
|
+
if (!item || item.id?.[0] === '$') continue;
|
|
333
|
+
list.push(item);
|
|
334
|
+
if (item.type === '$base' || item.type === '$project') {
|
|
335
|
+
const sub = (await item.items) || [];
|
|
336
|
+
for (const child of sub) {
|
|
337
|
+
if (child && child.type === '$structure' && child.id?.[0] !== '$')
|
|
338
|
+
list.push(child);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
await collectTargets('/ORGANIZATIONS');
|
|
344
|
+
await collectTargets('/PROJECTS');
|
|
345
|
+
await collectTargets('/USERS');
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
const { readEmailSettings } = await import('../../../$server/$folder/lib/email/settings.js');
|
|
349
|
+
const MAILCAL = await import('../../server/class/mail-calendar.js');
|
|
350
|
+
const refreshed = [];
|
|
351
|
+
for (const nodeItem of list) {
|
|
352
|
+
if (!nodeItem || nodeItem.DATA?.mailAutoRefresh === false)
|
|
353
|
+
continue;
|
|
354
|
+
const settings = readEmailSettings(nodeItem);
|
|
355
|
+
const hasImap = Object.values(settings?.mailboxes || {}).some(b => b?.imap?.host && b?.auth?.pass);
|
|
356
|
+
if (!hasImap)
|
|
357
|
+
continue;
|
|
358
|
+
try {
|
|
359
|
+
const res = await MAILCAL.mailRefresh(nodeItem, { session: { uid: nodeItem.id || 'WORK', $user: WORK } });
|
|
360
|
+
refreshed.push({ path: nodeItem.path || '/', ok: Boolean(res?.ok !== false) });
|
|
361
|
+
}
|
|
362
|
+
catch (e) {
|
|
363
|
+
console.warn('[mailAutoRefresh]', nodeItem.path || '/', e?.message || e);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
return refreshed;
|
|
367
|
+
}
|
|
@@ -347,6 +347,7 @@ export async function cancelSchedule({ uid, id }) {
|
|
|
347
347
|
}
|
|
348
348
|
|
|
349
349
|
let lastQuietDigestAt = 0;
|
|
350
|
+
let lastMailRefreshAt = 0;
|
|
350
351
|
|
|
351
352
|
/** Выполнить наступившие запуски (вызывается таймером; тесты — напрямую). */
|
|
352
353
|
export async function runDue(now = Date.now(), runner = defaultRunner) {
|
|
@@ -377,6 +378,12 @@ export async function runDue(now = Date.now(), runner = defaultRunner) {
|
|
|
377
378
|
.then(m => m.runQuietDigests?.({ now }))
|
|
378
379
|
.catch(() => {});
|
|
379
380
|
}
|
|
381
|
+
if (runner === defaultRunner && now - lastMailRefreshAt >= 10 * 60_000) {
|
|
382
|
+
lastMailRefreshAt = now;
|
|
383
|
+
import('./node-rules.js')
|
|
384
|
+
.then(m => m.runMailAutoRefresh?.({ now }))
|
|
385
|
+
.catch(() => {});
|
|
386
|
+
}
|
|
380
387
|
return done;
|
|
381
388
|
}
|
|
382
389
|
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Штатные инструменты ИИ-агента для работы с Календарём (.ics) и Почтой (.eml) WORK:
|
|
3
|
+
* - calendar_list, calendar_save
|
|
4
|
+
* - mail_list, mail_read, mail_refresh, mail_draft, mail_send
|
|
5
|
+
*/
|
|
6
|
+
import * as MAILCAL from '../../../server/class/mail-calendar.js';
|
|
7
|
+
|
|
8
|
+
async function resolveTargetPlace(pathArg, ctx) {
|
|
9
|
+
const p = String(pathArg || '').trim();
|
|
10
|
+
if (!p)
|
|
11
|
+
return ctx?.place || globalThis.WORK;
|
|
12
|
+
if (ctx?.place && (ctx.place.path === p || ctx.place.short === p))
|
|
13
|
+
return ctx.place;
|
|
14
|
+
const item = await globalThis.WORK?.get_item?.(p).catch(() => null);
|
|
15
|
+
if (!item)
|
|
16
|
+
throw new Error(`Узел не найден: ${p}`);
|
|
17
|
+
return item;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const calendarListTool = {
|
|
21
|
+
name: 'calendar_list',
|
|
22
|
+
label: 'Просмотр календаря',
|
|
23
|
+
description: 'Показать события календаря узла за диапазон дат (включая повторяющиеся встречи, задачи со сроком, расписания ИИ и свободные окна).',
|
|
24
|
+
readonly: true,
|
|
25
|
+
parameters: {
|
|
26
|
+
type: 'object',
|
|
27
|
+
properties: {
|
|
28
|
+
path: { type: 'string', description: 'WORK-путь узла (по умолчанию текущий узел)' },
|
|
29
|
+
from: { type: 'string', description: 'Начало периода YYYY-MM-DD (по умолчанию сегодня)' },
|
|
30
|
+
to: { type: 'string', description: 'Конец периода YYYY-MM-DD (по умолчанию равен from)' },
|
|
31
|
+
includeTasks: { type: 'boolean', description: 'Включить задачи со сроком' },
|
|
32
|
+
includeSchedules: { type: 'boolean', description: 'Включить регулярные расписания ИИ' },
|
|
33
|
+
withFreeSlots: { type: 'boolean', description: 'Рассчитать свободные окна (09:00–18:00)' },
|
|
34
|
+
attendee: { type: 'string', description: 'Фильтр по uid участника/организатора' },
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
async run(args, ctx) {
|
|
38
|
+
const place = await resolveTargetPlace(args?.path, ctx);
|
|
39
|
+
return MAILCAL.calendarList(place, {
|
|
40
|
+
...args,
|
|
41
|
+
session: ctx?.session,
|
|
42
|
+
});
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export const calendarSaveTool = {
|
|
47
|
+
name: 'calendar_save',
|
|
48
|
+
label: 'Сохранение встречи в календаре',
|
|
49
|
+
description: 'Создать, изменить, перенести или отменить событие календаря (.ics) с проверкой накладок по времени и синхронизацией приглашений участникам.',
|
|
50
|
+
risk: 'write',
|
|
51
|
+
parameters: {
|
|
52
|
+
type: 'object',
|
|
53
|
+
properties: {
|
|
54
|
+
path: { type: 'string', description: 'WORK-путь узла (по умолчанию текущий узел)' },
|
|
55
|
+
uid: { type: 'string', description: 'UID существующей встречи для изменения/переноса/отмены' },
|
|
56
|
+
summary: { type: 'string', description: 'Название события/встречи' },
|
|
57
|
+
start: { type: 'string', description: 'Дата/время начала (ISO, например 2026-11-26T10:00:00+03:00)' },
|
|
58
|
+
end: { type: 'string', description: 'Дата/время окончания (ISO)' },
|
|
59
|
+
allDay: { type: 'boolean', description: 'Событие на весь день' },
|
|
60
|
+
location: { type: 'string', description: 'Место или ссылка на созвон' },
|
|
61
|
+
description: { type: 'string', description: 'Описание / повестка' },
|
|
62
|
+
attendees: { type: 'array', items: { type: 'string' }, description: 'Список uid коллег-участников' },
|
|
63
|
+
externalEmails: { type: 'array', items: { type: 'string' }, description: 'Внешние email участников' },
|
|
64
|
+
recurrence: { type: 'string', enum: ['none', 'daily', 'weekly', 'monthly', 'yearly'], description: 'Правило повторения' },
|
|
65
|
+
reminderMin: { type: 'number', description: 'Напоминание за N минут (0, 15, 60, 1440)' },
|
|
66
|
+
category: { type: 'string', enum: ['meeting', 'important', 'personal', 'client'], description: 'Категория/цвет события' },
|
|
67
|
+
status: { type: 'string', enum: ['confirmed', 'cancelled'], description: 'cancelled — отменить встречу' },
|
|
68
|
+
allowConflict: { type: 'boolean', description: 'true — сохранить даже при наложении по времени с другой встречей' },
|
|
69
|
+
},
|
|
70
|
+
required: ['start', 'end'],
|
|
71
|
+
},
|
|
72
|
+
async run(args, ctx) {
|
|
73
|
+
const place = await resolveTargetPlace(args?.path, ctx);
|
|
74
|
+
if (args?.status !== 'cancelled' && !args?.allowConflict && !args?.allDay) {
|
|
75
|
+
const fromDay = String(args.start).slice(0, 10);
|
|
76
|
+
const toDay = String(args.end).slice(0, 10);
|
|
77
|
+
const existing = await MAILCAL.calendarList(place, { from: fromDay, to: toDay, session: ctx?.session });
|
|
78
|
+
const reqStart = Date.parse(args.start);
|
|
79
|
+
const reqEnd = Date.parse(args.end);
|
|
80
|
+
const conflicts = (existing?.events || []).filter(ev => {
|
|
81
|
+
if (ev.kind !== 'event' || ev.allDay)
|
|
82
|
+
return false;
|
|
83
|
+
if (args.uid && ev.uid === args.uid)
|
|
84
|
+
return false;
|
|
85
|
+
const s = Date.parse(ev.start);
|
|
86
|
+
const e = Date.parse(ev.end);
|
|
87
|
+
return Number.isFinite(s) && Number.isFinite(e) && s < reqEnd && e > reqStart;
|
|
88
|
+
});
|
|
89
|
+
if (conflicts.length) {
|
|
90
|
+
return {
|
|
91
|
+
ok: false,
|
|
92
|
+
conflict: true,
|
|
93
|
+
message: `Обнаружено пересечение по времени (${conflicts.length}): ${conflicts.map(c => `${c.summary} (${c.start})`).join('; ')}. Выберите свободное окно или передайте allowConflict: true.`,
|
|
94
|
+
conflicts: conflicts.map(c => ({ uid: c.uid, summary: c.summary, start: c.start, end: c.end })),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return MAILCAL.calendarSave(place, {
|
|
99
|
+
...args,
|
|
100
|
+
session: ctx?.session,
|
|
101
|
+
});
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export const mailListTool = {
|
|
106
|
+
name: 'mail_list',
|
|
107
|
+
label: 'Список писем',
|
|
108
|
+
description: 'Показать список писем узла по папкам (inbox, drafts, outbox, trash, all) с поиском и фильтром непрочитанных.',
|
|
109
|
+
readonly: true,
|
|
110
|
+
parameters: {
|
|
111
|
+
type: 'object',
|
|
112
|
+
properties: {
|
|
113
|
+
path: { type: 'string', description: 'WORK-путь узла (по умолчанию текущий узел)' },
|
|
114
|
+
box: { type: 'string', enum: ['all', 'inbox', 'drafts', 'outbox', 'trash'], description: 'Папка (по умолчанию inbox)' },
|
|
115
|
+
q: { type: 'string', description: 'Поиск по теме, адресу или тексту' },
|
|
116
|
+
address: { type: 'string', description: 'Фильтр по подключённому ящику' },
|
|
117
|
+
unreadOnly: { type: 'boolean', description: 'Только непрочитанные' },
|
|
118
|
+
limit: { type: 'number', description: 'Максимум писем (по умолчанию 50)' },
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
async run(args, ctx) {
|
|
122
|
+
const place = await resolveTargetPlace(args?.path, ctx);
|
|
123
|
+
const [acc, list] = await Promise.all([
|
|
124
|
+
MAILCAL.mailAccounts(place, { session: ctx?.session }).catch(() => ({ accounts: [] })),
|
|
125
|
+
MAILCAL.mailList(place, {
|
|
126
|
+
box: args?.box || 'inbox',
|
|
127
|
+
q: args?.q || '',
|
|
128
|
+
address: args?.address || '',
|
|
129
|
+
unreadOnly: args?.unreadOnly === true,
|
|
130
|
+
limit: args?.limit || 50,
|
|
131
|
+
session: ctx?.session,
|
|
132
|
+
}),
|
|
133
|
+
]);
|
|
134
|
+
return { accounts: acc.accounts, ...list };
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
export const mailReadTool = {
|
|
139
|
+
name: 'mail_read',
|
|
140
|
+
label: 'Чтение письма',
|
|
141
|
+
description: 'Прочитать полное содержимое письма (.eml) по path или uid. Содержимое писем помечается как внешние данные (<untrusted>).',
|
|
142
|
+
readonly: true,
|
|
143
|
+
parameters: {
|
|
144
|
+
type: 'object',
|
|
145
|
+
properties: {
|
|
146
|
+
path: { type: 'string', description: 'WORK-путь файла письма .eml' },
|
|
147
|
+
uid: { type: 'string', description: 'UID письма (если path неизвестен)' },
|
|
148
|
+
nodePath: { type: 'string', description: 'WORK-путь узла (по умолчанию текущий узел)' },
|
|
149
|
+
markRead: { type: 'boolean', description: 'Отметить прочитанным (по умолчанию false при чтении агентом)' },
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
async run(args, ctx) {
|
|
153
|
+
const place = await resolveTargetPlace(args?.nodePath, ctx);
|
|
154
|
+
const msg = await MAILCAL.mailRead(place, {
|
|
155
|
+
path: args?.path,
|
|
156
|
+
uid: args?.uid,
|
|
157
|
+
markRead: args?.markRead === true,
|
|
158
|
+
session: ctx?.session,
|
|
159
|
+
});
|
|
160
|
+
if (ctx?.entry)
|
|
161
|
+
ctx.entry.untrusted = true;
|
|
162
|
+
return msg;
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
export const mailRefreshTool = {
|
|
167
|
+
name: 'mail_refresh',
|
|
168
|
+
label: 'Проверка новой почты',
|
|
169
|
+
description: 'Запросить свежие входящие письма с почтового сервера (IMAP) для настроенных ящиков узла.',
|
|
170
|
+
risk: 'write',
|
|
171
|
+
parameters: {
|
|
172
|
+
type: 'object',
|
|
173
|
+
properties: {
|
|
174
|
+
path: { type: 'string', description: 'WORK-путь узла (по умолчанию текущий узел)' },
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
async run(args, ctx) {
|
|
178
|
+
const place = await resolveTargetPlace(args?.path, ctx);
|
|
179
|
+
return MAILCAL.mailRefresh(place, { session: ctx?.session });
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
export const mailDraftTool = {
|
|
184
|
+
name: 'mail_draft',
|
|
185
|
+
label: 'Черновик и статус письма',
|
|
186
|
+
description: 'Сохранить/обновить черновик письма в папке «Черновики» (action=draft) или изменить статус/папку письма (read/unread/trash/restore).',
|
|
187
|
+
risk: 'write',
|
|
188
|
+
parameters: {
|
|
189
|
+
type: 'object',
|
|
190
|
+
properties: {
|
|
191
|
+
path: { type: 'string', description: 'WORK-путь узла (по умолчанию текущий узел)' },
|
|
192
|
+
action: { type: 'string', enum: ['draft', 'read', 'unread', 'trash', 'restore'], description: 'Действие (по умолчанию draft)' },
|
|
193
|
+
messagePath: { type: 'string', description: 'Путь письма для read/unread/trash/restore' },
|
|
194
|
+
uid: { type: 'string', description: 'UID черновика или письма' },
|
|
195
|
+
from: { type: 'string', description: 'Адрес отправителя (из ящиков узла)' },
|
|
196
|
+
to: { type: 'string', description: 'Получатель(и) через запятую' },
|
|
197
|
+
cc: { type: 'string', description: 'Копия (через запятую)' },
|
|
198
|
+
subject: { type: 'string', description: 'Тема письма' },
|
|
199
|
+
body: { type: 'string', description: 'Текст письма' },
|
|
200
|
+
inReplyTo: { type: 'string', description: 'Message-ID исходного письма при ответе' },
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
async run(args, ctx) {
|
|
204
|
+
const place = await resolveTargetPlace(args?.path, ctx);
|
|
205
|
+
const act = String(args?.action || 'draft');
|
|
206
|
+
if (act === 'draft') {
|
|
207
|
+
return MAILCAL.mailDraftSave(place, {
|
|
208
|
+
uid: args?.uid,
|
|
209
|
+
from: args?.from,
|
|
210
|
+
to: args?.to,
|
|
211
|
+
cc: args?.cc,
|
|
212
|
+
subject: args?.subject,
|
|
213
|
+
body: args?.body,
|
|
214
|
+
inReplyTo: args?.inReplyTo,
|
|
215
|
+
session: ctx?.session,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
return MAILCAL.mailState(place, {
|
|
219
|
+
path: args?.messagePath,
|
|
220
|
+
uid: args?.uid,
|
|
221
|
+
...(act === 'read' ? { read: true } : {}),
|
|
222
|
+
...(act === 'unread' ? { read: false } : {}),
|
|
223
|
+
...(act === 'trash' ? { box: 'trash' } : {}),
|
|
224
|
+
...(act === 'restore' ? { restore: true } : {}),
|
|
225
|
+
session: ctx?.session,
|
|
226
|
+
});
|
|
227
|
+
},
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
export const mailSendTool = {
|
|
231
|
+
name: 'mail_send',
|
|
232
|
+
label: 'Отправка письма наружу',
|
|
233
|
+
description: 'Отправить письмо по электронной почте через настроенный ящик узла. Всегда требует явного подтверждения человека (для черновика без отправки используй mail_draft).',
|
|
234
|
+
risk: 'danger',
|
|
235
|
+
outbound: true,
|
|
236
|
+
parameters: {
|
|
237
|
+
type: 'object',
|
|
238
|
+
properties: {
|
|
239
|
+
path: { type: 'string', description: 'WORK-путь узла (по умолчанию текущий узел)' },
|
|
240
|
+
from: { type: 'string', description: 'Адрес отправителя' },
|
|
241
|
+
to: { type: 'string', description: 'Получатель(и) через запятую' },
|
|
242
|
+
cc: { type: 'string', description: 'Копия' },
|
|
243
|
+
subject: { type: 'string', description: 'Тема письма' },
|
|
244
|
+
body: { type: 'string', description: 'Текст письма' },
|
|
245
|
+
draftUid: { type: 'string', description: 'UID черновика (если отправляем сохранённый черновик)' },
|
|
246
|
+
inReplyTo: { type: 'string', description: 'Message-ID исходного письма' },
|
|
247
|
+
},
|
|
248
|
+
required: ['to', 'subject', 'body'],
|
|
249
|
+
},
|
|
250
|
+
async run(args, ctx) {
|
|
251
|
+
const place = await resolveTargetPlace(args?.path, ctx);
|
|
252
|
+
return MAILCAL.mailSend(place, {
|
|
253
|
+
from: args?.from,
|
|
254
|
+
to: args?.to,
|
|
255
|
+
cc: args?.cc,
|
|
256
|
+
subject: args?.subject,
|
|
257
|
+
body: args?.body,
|
|
258
|
+
draftUid: args?.draftUid,
|
|
259
|
+
inReplyTo: args?.inReplyTo,
|
|
260
|
+
session: ctx?.session,
|
|
261
|
+
});
|
|
262
|
+
},
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
export const calendarMailTools = [
|
|
266
|
+
calendarListTool,
|
|
267
|
+
calendarSaveTool,
|
|
268
|
+
mailListTool,
|
|
269
|
+
mailReadTool,
|
|
270
|
+
mailRefreshTool,
|
|
271
|
+
mailDraftTool,
|
|
272
|
+
mailSendTool,
|
|
273
|
+
];
|
|
@@ -42,6 +42,9 @@ export const MEMBERS = Object.freeze({
|
|
|
42
42
|
read_log_entry: L.READ, log_index: L.READ, chatSource: L.READ,
|
|
43
43
|
chat_thread_open: L.CALL, chat_threads_list: L.READ, chat_messages_list: L.READ,
|
|
44
44
|
chat_send: L.WRITE, chat_mark_read: L.WRITE, chat_action: L.WRITE, chat_unread_summary: L.USER, visible_contacts: L.USER,
|
|
45
|
+
mail_accounts: L.READ, mail_list: L.READ, mail_read: L.READ,
|
|
46
|
+
mail_draft_save: L.WRITE, mail_send: L.WRITE, mail_state: L.WRITE, mail_refresh: L.WRITE,
|
|
47
|
+
calendar_list: L.READ, calendar_save: L.WRITE,
|
|
45
48
|
agent_rules_list: L.READ, agent_rule_save: L.ADMIN, agent_schedule_save: L.ADMIN, agent_proactivity_save: L.ADMIN,
|
|
46
49
|
roles: L.READ, members: L.READ, is_data_type: L.READ, reset: L.READ,
|
|
47
50
|
work_zone: L.READ, places: L.READ,
|