Долгоживущий агент чата (только для managerIds, тестовый менеджер) и тайминг чата (chat_timing, миграция 016); тесты; docs
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user