odant-work 1.0.72 → 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 +22 -20
- package/$server/$folder/$class/$structure/handlers/pages/form/calendar/$handler/calendar.js +1004 -1011
- 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 +1 -1
- 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/lib/calendar-form/calendar-form.js +482 -296
- package/package.json +1 -1
- package/sources/host/email-utils.js +25 -1
- package/sources/modules/agent/index.js +3 -1
- package/sources/modules/agent/node-rules.js +51 -0
- 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/class/feed.js +46 -0
- package/sources/server/class/mail-calendar.js +867 -0
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",
|
|
@@ -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
|
]);
|
|
@@ -314,3 +314,54 @@ export async function runQuietDigests({ now = Date.now(), nodes = null } = {}) {
|
|
|
314
314
|
}
|
|
315
315
|
return sent;
|
|
316
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,
|
|
@@ -5,6 +5,7 @@ import * as fs from 'node:fs';
|
|
|
5
5
|
import { FS } from '../index.js';
|
|
6
6
|
import * as LOGS from '../logs.js';
|
|
7
7
|
import * as CHAT from '../chat-threads.js';
|
|
8
|
+
import * as MAILCAL from './mail-calendar.js';
|
|
8
9
|
import * as POLICY from '../access/policy.js';
|
|
9
10
|
import { DEV_MODE } from '../../host/config.js';
|
|
10
11
|
|
|
@@ -223,6 +224,51 @@ export const classFeedMethods = {
|
|
|
223
224
|
return saveNodeProactivity(this, params);
|
|
224
225
|
},
|
|
225
226
|
|
|
227
|
+
/** Публичный список настроенных почтовых ящиков узла (без паролей и секретов). */
|
|
228
|
+
async mail_accounts(params = {}) {
|
|
229
|
+
return MAILCAL.mailAccounts(this, params);
|
|
230
|
+
},
|
|
231
|
+
|
|
232
|
+
/** Список писем узла (.eml) с фильтрацией по папке, поиском и счётчиками непрочитанных. */
|
|
233
|
+
async mail_list(params = {}) {
|
|
234
|
+
return MAILCAL.mailList(this, params);
|
|
235
|
+
},
|
|
236
|
+
|
|
237
|
+
/** Прочитать полное письмо (.eml) с автопометкой прочитанности. */
|
|
238
|
+
async mail_read(params = {}) {
|
|
239
|
+
return MAILCAL.mailRead(this, params);
|
|
240
|
+
},
|
|
241
|
+
|
|
242
|
+
/** Сохранить/обновить черновик письма в папке drafts. */
|
|
243
|
+
async mail_draft_save(params = {}) {
|
|
244
|
+
return MAILCAL.mailDraftSave(this, params);
|
|
245
|
+
},
|
|
246
|
+
|
|
247
|
+
/** Отправить письмо через SMTP-конвейер узла. */
|
|
248
|
+
async mail_send(params = {}) {
|
|
249
|
+
return MAILCAL.mailSend(this, params);
|
|
250
|
+
},
|
|
251
|
+
|
|
252
|
+
/** Изменить состояние письма (read/unread, в корзину, восстановить, удалить). */
|
|
253
|
+
async mail_state(params = {}) {
|
|
254
|
+
return MAILCAL.mailState(this, params);
|
|
255
|
+
},
|
|
256
|
+
|
|
257
|
+
/** Запросить свежие входящие письма с IMAP-сервера узла. */
|
|
258
|
+
async mail_refresh(params = {}) {
|
|
259
|
+
return MAILCAL.mailRefresh(this, params);
|
|
260
|
+
},
|
|
261
|
+
|
|
262
|
+
/** События календаря узла (.ics), включая повторения, задачи и расписания ИИ. */
|
|
263
|
+
async calendar_list(params = {}) {
|
|
264
|
+
return MAILCAL.calendarList(this, params);
|
|
265
|
+
},
|
|
266
|
+
|
|
267
|
+
/** Сохранить, перенести или отменить событие календаря (.ics) + синхронизация участникам. */
|
|
268
|
+
async calendar_save(params = {}) {
|
|
269
|
+
return MAILCAL.calendarSave(this, params);
|
|
270
|
+
},
|
|
271
|
+
|
|
226
272
|
/** @deprecated используй append_log_includes({ entryPath, includePaths }) */
|
|
227
273
|
async appendLogIncludes(entryPath, includePaths = [], params = {}) {
|
|
228
274
|
if (entryPath && typeof entryPath === 'object' && entryPath.entryPath) {
|