Короткое напоминание только если осмысленное сообщение было менее 24 часов назад (last_meaningful, миграция 039, п.86)
All checks were successful
ci / test (push) Successful in 38s
ci / deploy (push) Successful in 2m37s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-18 08:47:46 +03:00
parent 198eafa86f
commit 213ef36bcf
9 changed files with 35 additions and 13 deletions

View File

@@ -271,13 +271,14 @@ export async function handleManagerMessages(
const { rows: fr } = await ctx.pool.query(
`select (select max(reply_at) from chat_timing where manager_person_id = $1) as last_assistant,
(select max(received_at) from slack_message_log where manager_person_id = $1) as last_human,
(select max(reply_at) from chat_timing where manager_person_id = $1 and (reply_words is null or reply_words > $3)) as last_meaningful,
(select count(*)::int from chat_timing where manager_person_id = $1 and reply_at >= $2::timestamptz) as assistant_today,
exists(select 1 from slack_message_log where manager_person_id = $1 and received_at >= $2::timestamptz) as replied_today,
(select count(*)::int from chat_timing where manager_person_id = $1 and reply_at > coalesce((select max(received_at) from slack_message_log where manager_person_id = $1), '-infinity')) as unanswered`,
[manager.personId, startOfLocalDay(now, deps.timezone)],
[manager.personId, startOfLocalDay(now, deps.timezone), SHORT_REPLY_WORDS],
);
const mgrText = optFragment("p-chat-environment.md", "Менеджер", { name: manager.name, mention: manager.slackUserId ? `<@${manager.slackUserId}>` : manager.name });
const freqText = optFragment("p-chat-environment.md", "Частота сообщений", { last_assistant: iso(fr[0]?.last_assistant), last_human: iso(fr[0]?.last_human), unanswered: String(fr[0]?.unanswered ?? 0), assistant_today: String(fr[0]?.assistant_today ?? 0), replied_today: fr[0]?.replied_today ? "да" : "нет" });
const freqText = optFragment("p-chat-environment.md", "Частота сообщений", { last_assistant: iso(fr[0]?.last_assistant), last_human: iso(fr[0]?.last_human), unanswered: String(fr[0]?.unanswered ?? 0), last_meaningful: iso(fr[0]?.last_meaningful), assistant_today: String(fr[0]?.assistant_today ?? 0), replied_today: fr[0]?.replied_today ? "да" : "нет" });
if (mgrText) freqBlocks.push("", `# Менеджер\n${mgrText}`);
if (freqText) freqBlocks.push("", `# Частота сообщений\n${freqText}`);
}
@@ -374,6 +375,7 @@ ${recapBlock(st, deps.timezone)}`);
const pr = await publishReply(deps, manager, channel, reply);
({ published, audioSent } = pr);
tm.replySlackTs = pr.replyTs;
tm.replyWords = replyWordCount(reply);
tm.publishMs = Date.now() - tp;
}
if (reply && opts.systemEvent) {
@@ -396,6 +398,12 @@ ${recapBlock(st, deps.timezone)}`);
}
/** Публикует ответ по настройке чата: текст / текст и аудио / только аудио. Любой сбой аудио - ответ уходит текстом, ИТ видит проблему в логе. */
/** Короткое напоминание - до 12 слов (4-8 слов фразы и упоминание); длиннее - осмысленное сообщение. */
export const SHORT_REPLY_WORDS = 12;
/** Число слов ответа без упоминаний Slack (<@U…>). */
export const replyWordCount = (text: string): number => text.replace(/<@[^>]+>/g, " ").split(/\s+/).filter(Boolean).length;
export async function publishReply(deps: ChatDeps, manager: ManagerInfo, channel: string, reply: string): Promise<{ published: boolean; audioSent: boolean; replyTs: string | null }> {
const mode = manager.replyMode ?? "text";
const voice = normalizeVoice(manager.ttsVoice) ?? normalizeVoice(deps.defaultVoice) ?? "Aoede";