log chat sessions to database

This commit is contained in:
Owen
2026-08-11 12:19:17 -04:00
parent 68a84181d9
commit 48c4b44f72
13 changed files with 749 additions and 116 deletions
+2
View File
@@ -19,6 +19,7 @@ import { flushConnectionLogToDb } from "#private/routers/newt";
import { flushSiteBandwidthToDb } from "@server/routers/gerbil/receiveBandwidth";
import { stopPingAccumulator } from "@server/routers/newt/pingAccumulator";
import { shutdownUsageRecorder } from "@server/lib/aiBudgetEnforcement";
import { shutdownAiSessionLogger } from "@server/routers/aiGateway/logAiSession";
async function cleanup() {
await stopPingAccumulator();
@@ -26,6 +27,7 @@ async function cleanup() {
await flushConnectionLogToDb();
await flushSiteBandwidthToDb();
await shutdownUsageRecorder();
await shutdownAiSessionLogger();
await rateLimitService.cleanup();
await wsCleanup();
await logStreamingManager.shutdown();
@@ -134,6 +134,17 @@ async function capRetentionDays(
);
}
if (
org.settingsLogRetentionDaysAISessions !== null &&
org.settingsLogRetentionDaysAISessions > maxRetentionDays
) {
updates.settingsLogRetentionDaysAISessions = maxRetentionDays;
needsUpdate = true;
logger.info(
`Capping AI session log retention from ${org.settingsLogRetentionDaysAISessions} to ${maxRetentionDays} days for org ${orgId}`
);
}
// Apply updates if needed
if (needsUpdate) {
await db.update(orgs).set(updates).where(eq(orgs.orgId, orgId));