Use external DB/Redis in compose and preserve auth session across rebuilds

This commit is contained in:
Ruslan Bakiev
2026-02-19 17:01:00 +07:00
parent f6fd11b3c4
commit a25049989c
4 changed files with 37 additions and 44 deletions

View File

@@ -24,6 +24,7 @@ OPENAI_MODEL="gpt-4o-mini"
CF_AGENT_MODE="langgraph"
CF_WHISPER_MODEL="Xenova/whisper-small"
CF_WHISPER_LANGUAGE="ru"
CF_RUN_SEED_ON_START="0"
TELEGRAM_BOT_TOKEN=""
TELEGRAM_WEBHOOK_SECRET=""

View File

@@ -37,6 +37,8 @@ done
npx prisma db push
node prisma/seed.mjs
if [ "${CF_RUN_SEED_ON_START:-0}" = "1" ]; then
node prisma/seed.mjs
fi
exec npm run dev -- --host 0.0.0.0 --port 3000

View File

@@ -69,7 +69,24 @@ export async function getAuthContext(event: H3Event): Promise<AuthContext> {
});
if (!conv) {
throw createError({ statusCode: 401, statusMessage: "Unauthorized" });
// Recover from stale conversation cookie after rebuild/reset:
// reuse latest available conversation (or recreate default one) and refresh cookie.
const fallback =
(await prisma.chatConversation.findFirst({
where: { teamId: team.id, createdByUserId: user.id },
orderBy: { updatedAt: "desc" },
})) ||
(await prisma.chatConversation.create({
data: { id: `pilot-${team.id}`, teamId: team.id, createdByUserId: user.id, title: "Pilot" },
}));
setSession(event, {
teamId: team.id,
userId: user.id,
conversationId: fallback.id,
});
return { teamId: team.id, userId: user.id, conversationId: fallback.id };
}
return { teamId: team.id, userId: user.id, conversationId: conv.id };