Режим passive при отключении агента: молчит по своей инициативе, на сообщения менеджера отвечает как обычно (миграция 018); off - вообще ничего; тесты; docs
All checks were successful
ci / test (push) Successful in 24s
ci / deploy (push) Successful in 1m29s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-19 20:23:15 +03:00
parent 3cbcfb506a
commit c59ac87486
9 changed files with 59 additions and 22 deletions

View File

@@ -24,7 +24,7 @@ export function registerAgentRoutes(app: FastifyInstance, pool: Pool): void {
app.get("/agents", async () => {
const { rows } = await pool.query(
`select cm.person_id as id, p.display_name as name, cm.slack_channel_id, cm.is_active,
(not ${NOT_PAUSED_SQL("cm")}) as paused, cm.agent_paused as paused_indefinitely, cm.paused_until, cm.pause_reason, cm.paused_by,
(not ${NOT_PAUSED_SQL("cm")}) as paused, cm.pause_mode, cm.agent_paused as paused_indefinitely, cm.paused_until, cm.pause_reason, cm.paused_by,
coalesce(length(m.memory_text), 0)::int as memory_chars, m.updated_at as memory_updated_at, (m.claude_session_id is not null) as has_session,
(select jsonb_build_object('step', r.step, 'status', r.status, 'started_at', r.started_at, 'error', r.error)
from agent_run r where r.manager_person_id = cm.person_id order by r.started_at desc limit 1) as last_run
@@ -56,15 +56,21 @@ export function registerAgentRoutes(app: FastifyInstance, pool: Pool): void {
if (until && until.getTime() > Date.now() + 366 * 86_400_000) return { error: "срок отключения больше года - для долгого отключения не задавайте срок (до команды владельца)" };
return { until };
};
type PauseBody = { until?: unknown; hours?: unknown; days?: unknown; reason?: string; by?: string };
type PauseBody = { until?: unknown; hours?: unknown; days?: unknown; reason?: string; by?: string; mode?: string };
const parseMode = (m: unknown): "passive" | "off" | null => (m === undefined || m === null || m === "" || m === "passive" ? "passive" : m === "off" ? "off" : null);
/** Отключить агента менеджера: на время (until / hours / days) или до команды владельца (срок не задан). Ассистент ничего не пишет и не обрабатывает его сообщения. */
/**
* Отключить агента менеджера: на время (until / hours / days) или до команды владельца (срок не задан).
* mode: passive (по умолчанию) - сам ничего не пишет, но на сообщения менеджера отвечает как обычно; off - вообще ничего.
*/
app.post<{ Params: { id: string }; Body: PauseBody }>("/agents/:id/pause", async (req, reply) => {
if (!(await knownManager(req.params.id))) return reply.code(404).send({ error: "менеджер не найден" });
const b = req.body ?? {};
const u = parseUntil(b);
if ("error" in u) return reply.code(400).send({ error: u.error });
await setPause(pool, req.params.id, { until: u.until, reason: b.reason ?? null, by: b.by ?? "api" });
const mode = parseMode(b.mode);
if (!mode) return reply.code(400).send({ error: "mode: passive (по умолчанию) или off" });
await setPause(pool, req.params.id, { until: u.until, reason: b.reason ?? null, by: b.by ?? "api", mode });
return { ok: true, ...(await pauseState(pool, req.params.id)) };
});
@@ -80,8 +86,10 @@ export function registerAgentRoutes(app: FastifyInstance, pool: Pool): void {
const b = req.body ?? {};
const u = parseUntil(b);
if ("error" in u) return reply.code(400).send({ error: u.error });
const n = await setPauseAll(pool, { until: u.until, reason: b.reason ?? null, by: b.by ?? "api" });
return { ok: true, managers: n, until: u.until };
const mode = parseMode(b.mode);
if (!mode) return reply.code(400).send({ error: "mode: passive (по умолчанию) или off" });
const n = await setPauseAll(pool, { until: u.until, reason: b.reason ?? null, by: b.by ?? "api", mode });
return { ok: true, managers: n, mode, until: u.until };
});
app.post("/agents/resume-all", async () => ({ ok: true, managers: await resumeAll(pool) }));