Проектные каналы: тихий режим, recap для Daily Log; Huddle через message_changed; короткие напоминания
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,6 +6,7 @@ import { loadFragment, loadPrompt, type PromptSide } from "../agents/prompts.js"
|
||||
import { saveProblems } from "../agents/step2.js";
|
||||
import type { DriveSync } from "./drive.js";
|
||||
import type { SlackApi } from "./api.js";
|
||||
import { applyRecapOutput, getRecapState, loadChannelDialog, parseReactions, recapBlock } from "./recap.js";
|
||||
import { saveChatTiming, type ChatTiming } from "./timing.js";
|
||||
import { normalizeVoice, speechText, type ReplyMode, type Tts } from "./tts.js";
|
||||
|
||||
@@ -46,7 +47,7 @@ export interface IncomingMessage {
|
||||
|
||||
export interface ChatDeps {
|
||||
ctx: AgentContext;
|
||||
slack: Pick<SlackApi, "postMessage" | "postMessageTs" | "fileInfo" | "download" | "uploadFile">;
|
||||
slack: Pick<SlackApi, "postMessage" | "postMessageTs" | "fileInfo" | "download" | "uploadFile" | "history" | "userName" | "botUserId" | "addReaction">;
|
||||
/** Синтез речи; без него ответы всегда текстовые. */
|
||||
tts?: Tts;
|
||||
defaultVoice?: string;
|
||||
@@ -87,7 +88,7 @@ export async function handleManagerMessages(
|
||||
deps: ChatDeps,
|
||||
manager: ManagerInfo,
|
||||
messages: IncomingMessage[],
|
||||
opts: { systemEvent?: string } = {},
|
||||
opts: { systemEvent?: string; project?: ProjectContext; channel?: string } = {},
|
||||
): Promise<ChatResult> {
|
||||
const { ctx } = deps;
|
||||
const t0 = Date.now();
|
||||
@@ -100,7 +101,7 @@ export async function handleManagerMessages(
|
||||
};
|
||||
const now = (deps.now ?? (() => new Date()))();
|
||||
const today = localDate(now, deps.timezone);
|
||||
const channel = messages[0]?.channel ?? manager.slackChannelId;
|
||||
const channel = opts.channel ?? messages[0]?.channel ?? manager.slackChannelId;
|
||||
const sub = `${isoStamp(now)}_${channel ?? "nochannel"}`;
|
||||
const mediaDir = join(managerWorkDir(ctx.settings, manager.personId), "media", sub);
|
||||
mkdirSync(mediaDir, { recursive: true });
|
||||
@@ -192,7 +193,7 @@ export async function handleManagerMessages(
|
||||
const attBlock = attachments.length
|
||||
? attachments.map((a) => `- ${a.path} (${a.mimetype || "?"}, ${a.size} байт)${a.link ? ` | Drive: ${a.link}` : ""}`).join("\n")
|
||||
: "(вложений нет)";
|
||||
const proj = messages.find((m) => m.project)?.project;
|
||||
const proj = opts.project ?? messages.find((m) => m.project)?.project;
|
||||
// Новая версия (долгоживущий агент) читает промты из proposed, прежняя (остальные менеджеры) - из approved
|
||||
const live = useLive(ctx, manager.personId);
|
||||
const side: PromptSide = live ? "proposed" : "approved";
|
||||
@@ -261,6 +262,16 @@ export async function handleManagerMessages(
|
||||
const sqlEnv = Object.keys(agentEnv).length ? agentEnv : undefined;
|
||||
const replyKey = isCeo ? "ответ arthur" : "ответ менеджеру";
|
||||
const listText = isCeo ? "" : await todayList(ctx, manager.personId, today);
|
||||
// проектный канал: диалог за сутки с временем (по Тампе) и накопленное для Daily Log
|
||||
const channelBlocks: string[] = [];
|
||||
const recapOn = !!proj && !!channel && live; // тихий режим и recap - только новая версия агента (промты proposed)
|
||||
if (recapOn && proj && channel) {
|
||||
const dialogText = await loadChannelDialog(deps.slack, channel, now, deps.timezone);
|
||||
const st = await getRecapState(ctx.pool, channel);
|
||||
channelBlocks.push("", `# Диалог канала за последние сутки (время по Тампе)
|
||||
${dialogText}`, "", `# Накопленное для Daily Log
|
||||
${recapBlock(st, deps.timezone)}`);
|
||||
}
|
||||
const buildPrompt = (dialog: boolean): string => [
|
||||
...(dialog
|
||||
? [`# Продолжение диалога\n${fragment("p-long-living-agents.md", "Продолжение диалога")}`]
|
||||
@@ -270,6 +281,7 @@ export async function handleManagerMessages(
|
||||
...freqBlocks,
|
||||
...(opts.systemEvent ? ["", `# Системное событие\n${opts.systemEvent}`] : []),
|
||||
...projectBlock,
|
||||
...channelBlocks,
|
||||
...(dialog
|
||||
? []
|
||||
: isCeo
|
||||
@@ -309,6 +321,11 @@ export async function handleManagerMessages(
|
||||
// 5. результат
|
||||
await saveMemory(ctx.pool, manager.personId, out.sections.get("память")!);
|
||||
await saveProblems(ctx, manager.personId, "step4", out.sections);
|
||||
if (recapOn && proj && channel) {
|
||||
await applyRecapOutput(ctx.pool, { channel, managerId: manager.personId, jobId: proj.jobId, sections: out.sections, humanMessage: messages.length > 0, now });
|
||||
if (!deps.dryPublish && deps.slack.addReaction)
|
||||
for (const r of parseReactions(out.sections.get("реакции"))) await deps.slack.addReaction(channel, r.ts, r.emoji).catch((e) => ctx.log.warn({ err: String(e) }, "реакция не поставлена"));
|
||||
}
|
||||
const replyRaw = out.sections.get(replyKey)!;
|
||||
const reply = /^\(без ответа\)\.?$/i.test(replyRaw) ? null : replyRaw;
|
||||
let published = false;
|
||||
|
||||
Reference in New Issue
Block a user