Долгоживущий агент чата (только для managerIds, тестовый менеджер) и тайминг чата (chat_timing, миграция 016); тесты; docs
All checks were successful
ci / test (push) Successful in 23s
ci / deploy (push) Successful in 1m46s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-16 12:55:18 +03:00
parent 81634fbfa9
commit 65ab75d378
17 changed files with 733 additions and 29 deletions

View File

@@ -1,6 +1,7 @@
import { join } from "node:path";
import { createLogger, createPool, itNotify, loadServiceSettings } from "khb_common";
import { createCliRunner } from "./agents/cli-runner.js";
import { createLiveRunner } from "./agents/live-runner.js";
import { KeyedMutex, Semaphore } from "./agents/pool.js";
import { closeOrphanRuns, type AgentContext } from "./agents/session.js";
import { buildApi } from "./http-api.js";
@@ -22,6 +23,13 @@ const ctx: AgentContext = {
log,
settings: service.agent,
runner: createCliRunner({ bin: service.agent.claudeBin, timeoutMs: service.agent.timeoutMs, model: service.agent.model }),
liveRunner: service.agent.live?.managerIds.length
? createLiveRunner({
bin: service.agent.claudeBin, model: service.agent.model, timeoutMs: service.agent.timeoutMs,
idleMs: service.agent.live.idleMinutes * 60_000, warmupMs: service.agent.live.warmupSeconds * 1000,
onEvent: (e) => log.info({ ...e }, "долгоживущий агент"),
})
: undefined,
gate: new Semaphore(service.agent.concurrency),
locks: new KeyedMutex(),
notifyIt: async (text) => {
@@ -118,3 +126,9 @@ if (service.slack && chatDeps) {
log.info({ everySeconds: d.inboxScanSeconds }, "опрос папок приёма Drive запущен");
}
}
for (const sig of ["SIGTERM", "SIGINT"] as const)
process.on(sig, () => {
ctx.liveRunner?.closeAll();
process.exit(0);
});