Conversation
* feat: migrate chat messages get endpoint * refactor: move chat messages handler from memories to chats * fix: harden chat access and memories error handling * fix: move chat error handling to domain handler * refactor: extract validateGetChatMessagesQuery per project conventions Move auth + param parsing to standalone validate function. Handler now calls validateGetChatMessagesQuery then selectMemories. 1670/1670 tests pass. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: format validateGetChatMessagesQuery and handler Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Sweets Sweetman <sweetmantech@gmail.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (6)
📒 Files selected for processing (10)
📝 WalkthroughWalkthroughThis PR introduces new API endpoints and handler functions to retrieve and copy chat messages between conversations. It includes validation utilities for request parameters and body payloads, updates memory persistence operations to support bulk inserts and deletions, and modifies existing chat completion functions to align with the new bulk-insert pattern. Changes
Sequence Diagram(s)sequenceDiagram
actor Client
participant GetRoute as GET /api/chats/[id]/messages
participant GetHandler as getChatMessagesHandler
participant Validate as validateGetChatMessagesQuery
participant CacheCheck as validateChatAccess
participant DB as Supabase (selectMemories)
Client->>GetRoute: GET /api/chats/[id]/messages
GetRoute->>GetHandler: POST(request, id)
GetHandler->>Validate: validateGetChatMessagesQuery(request, id)
Validate->>CacheCheck: validateChatAccess(request, id)
CacheCheck-->>Validate: ValidatedChatAccess or NextResponse
alt Validation Failed
Validate-->>GetHandler: NextResponse (400/401)
else Validation Passed
GetHandler->>DB: selectMemories(room_id, ascending)
DB-->>GetHandler: memories[] or null
alt Query Failed
GetHandler-->>Client: NextResponse (500, error)
else Query Succeeded
GetHandler-->>Client: NextResponse (200, { data: memories })
end
end
sequenceDiagram
actor Client
participant CopyRoute as POST /api/chats/[id]/messages/copy
participant CopyHandler as copyChatMessagesHandler
participant ValidateBody as validateCopyChatMessagesBody
participant ValidateAccess as validateChatAccess
participant DB as Supabase (selectMemories,<br/>deleteMemories,<br/>insertMemories)
Client->>CopyRoute: POST /api/chats/[id]/messages/copy<br/>{ targetChatId, clearExisting }
CopyRoute->>CopyHandler: copyChatMessagesHandler(request, sourceChatId)
CopyHandler->>ValidateBody: validateCopyChatMessagesBody(request, sourceChatId)
alt Body Invalid
ValidateBody-->>CopyHandler: NextResponse (400)
CopyHandler-->>Client: NextResponse (400, error)
else Body Valid
CopyHandler->>ValidateAccess: validateChatAccess (source & target)
alt Access Denied
ValidateAccess-->>CopyHandler: NextResponse (401)
CopyHandler-->>Client: NextResponse (401, error)
else Access Granted
alt clearExisting=true
CopyHandler->>DB: deleteMemories(targetRoomId)
end
CopyHandler->>DB: selectMemories(sourceRoomId)
DB-->>CopyHandler: sourceMemories[] or null
alt Source Query Failed
CopyHandler-->>Client: NextResponse (500, error)
else Source Query Succeeded
CopyHandler->>DB: insertMemories([transformed records])
DB-->>CopyHandler: insertCount
CopyHandler-->>Client: NextResponse (200, { sourceChatId,<br/>targetChatId, copiedCount,<br/>clearedExisting })
end
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
* feat: migrate chat messages copy endpoint * fix: add handler-level error guard for chat copy * refactor: move copy chat access checks into handler * refactor: make copy chat endpoint append-only * Revert "refactor: make copy chat endpoint append-only" This reverts commit eb4f4a7. * refactor: parallelize access checks, rename supabase helpers Address review: - Parallelize source/target validateChatAccess with Promise.all - KISS: deleteMemoriesByRoomId → deleteMemories - KISS: insertCopiedMemories → insertMemories Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: use insertMemoriesBatch to avoid overwriting existing insertMemories An insertMemories.ts already exists on test (single insert). Renamed batch version to insertMemoriesBatch to avoid collision. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: rename to insertMemories, replace existing unused single-insert version The old insertMemories (single insert) was unused. Replace with batch version per KISS feedback. Fix formatting. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: consolidate insertMemories to single array-based function One insertMemories that takes an array — updated all callers (saveChatCompletion, setupConversation, copyChatMessagesHandler) and their tests. Uses TablesInsert type for proper Supabase compat. Build passes. All tests pass. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Sweets Sweetman <sweetmantech@gmail.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sync test to main
Summary by CodeRabbit
Release Notes
New Features
Backend Improvements