An AI-powered search engine with a generative UI
TypeScript generative-aigenerative-uinextjsollamareactsearxngshadcn-uitailwindcsstavilytypescriptupstashvercel-ai-sdk
docs: address Copilot review feedback
Yoshiki Miura65f5007d7d45
diff --git a/app/api/chat/route.ts b/app/api/chat/route.tsindex c424a834..8955b467 100644--- a/app/api/chat/route.ts+++ b/app/api/chat/route.ts@@ -20,8 +20,10 @@ export async function POST(req: Request) {const startTime = performance.now()const abortSignal = req.signal- // Reset counters for new request- resetAllCounters()+ // Reset counters for new request (development only)+ if (process.env.ENABLE_PERF_LOGGING === 'true') {+ resetAllCounters()+ }try {const body = await req.json()diff --git a/lib/actions/chat.ts b/lib/actions/chat.tsindex ee3a5127..9b6d95b8 100644--- a/lib/actions/chat.ts+++ b/lib/actions/chat.ts@@ -149,6 +149,14 @@ export async function createChatWithFirstMessage(/*** Upsert a message to a chat* @param userId - Required but not used for access check (assumes already authorized)+ *+ * IMPORTANT: This function assumes the caller has already performed authorization checks.+ * It is only called from:+ * 1. API routes after authentication (app/api/chat/route.ts)+ * 2. Stream handlers after chat ownership verification+ * 3. Internal functions that have already verified access+ *+ * DO NOT call this function directly from untrusted contexts.*/export async function upsertMessage(chatId: string,@@ -156,7 +164,7 @@ export async function upsertMessage(userId: string): Promise<Message> {// Skip access check - userId is required for audit/logging but not for authorization- // Caller is responsible for ensuring authorization+ // Caller MUST ensure authorization before calling this functionconst messageId = message.id || generateId()const dbMessage = await dbActions.upsertMessage({...message,diff --git a/lib/utils/perf-tracking.ts b/lib/utils/perf-tracking.tsindex cf3e89e1..0a685d25 100644--- a/lib/utils/perf-tracking.ts+++ b/lib/utils/perf-tracking.ts@@ -1,4 +1,15 @@-// Performance tracking utilities (not server actions)+/**+ * Performance tracking utilities for DEVELOPMENT ONLY+ *+ * WARNING: These global counters are not thread-safe and should only be used+ * for debugging in development environments with ENABLE_PERF_LOGGING=true.+ *+ * In production, these counters are not used as performance logging is disabled.+ * The global state will cause issues with concurrent requests, but this is+ * acceptable for local development debugging.+ *+ * DO NOT use these counters for any production logic or metrics.+ */let authCallCount = 0let dbOperationCount = 0