From f734a5d46fe8bb610f12561ef0de500664a26dcb Mon Sep 17 00:00:00 2001 From: na-trium-144 <100704180+na-trium-144@users.noreply.github.com> Date: Mon, 10 Nov 2025 00:53:29 +0900 Subject: [PATCH 1/2] =?UTF-8?q?observability=E6=9C=89=E5=8A=B9=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wrangler.jsonc | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/wrangler.jsonc b/wrangler.jsonc index 2b5b387..85b8217 100644 --- a/wrangler.jsonc +++ b/wrangler.jsonc @@ -2,13 +2,18 @@ "main": ".open-next/worker.js", "name": "my-code", "compatibility_date": "2025-03-25", - "compatibility_flags": [ - "nodejs_compat", - "global_fetch_strictly_public", - ], + "compatibility_flags": ["nodejs_compat", "global_fetch_strictly_public"], + "observability": { + "logs": { + "enabled": true, + "head_sampling_rate": 1, + "invocation_logs": true, + "persist": true, + }, + }, "assets": { "directory": ".open-next/assets", - "binding": "ASSETS" + "binding": "ASSETS", }, "services": [ { From d2fb7a7ec0f792095a940d690731633301023599 Mon Sep 17 00:00:00 2001 From: na-trium-144 <100704180+na-trium-144@users.noreply.github.com> Date: Mon, 10 Nov 2025 00:53:57 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=E3=83=A6=E3=83=BC=E3=82=B6=E3=83=BC?= =?UTF-8?q?=E3=81=8C=E3=83=AD=E3=82=B0=E3=82=A4=E3=83=B3=E3=81=97=E3=81=A6?= =?UTF-8?q?=E3=81=84=E3=81=AA=E3=81=84=E3=81=A8=E3=81=8D=E3=82=A8=E3=83=A9?= =?UTF-8?q?=E3=83=BC=E3=82=92=E5=87=BA=E3=81=95=E3=81=AA=E3=81=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/lib/chatHistory.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/app/lib/chatHistory.ts b/app/lib/chatHistory.ts index 915f435..1025ed6 100644 --- a/app/lib/chatHistory.ts +++ b/app/lib/chatHistory.ts @@ -19,7 +19,7 @@ const CACHE_KEY_BASE = "https://my-code.utcode.net/chatHistory"; interface Context { drizzle: Awaited>; auth: Auth; - userId: string; + userId?: string; } /** * drizzleが初期化されてなければ初期化し、 @@ -40,10 +40,9 @@ async function initAll(ctx?: Partial): Promise { const session = await ctx.auth.api.getSession({ headers: await headers(), }); - if (!session) { - throw new Error("Not authenticated"); + if (session) { + ctx.userId = session.user.id; } - ctx.userId = session.user.id; } return ctx as Context; } @@ -64,7 +63,9 @@ export async function addChat( context?: Partial ) { const { drizzle, userId } = await initAll(context); - + if (!userId) { + throw new Error("Not authenticated"); + } const [newChat] = await drizzle .insert(chat) .values({ @@ -106,6 +107,9 @@ export async function getChat( context?: Partial ): Promise { const { drizzle, userId } = await initAll(context); + if (!userId) { + return []; + } const chats = await drizzle.query.chat.findMany({ where: and(eq(chat.userId, userId), eq(chat.docsId, docsId)), @@ -131,6 +135,9 @@ export async function getChatFromCache( context?: Partial ) { const { drizzle, auth, userId } = await initAll(context); + if (!userId) { + return []; + } const cache = await getCache(); const cachedResponse = await cache.match(