Skip to content

Merge pull request #1620 from recoupable/codex/arpit-migrate-memories…#1630

Merged
arpitgupta1214 merged 1 commit into
mainfrom
test
Apr 2, 2026
Merged

Merge pull request #1620 from recoupable/codex/arpit-migrate-memories…#1630
arpitgupta1214 merged 1 commit into
mainfrom
test

Conversation

@arpitgupta1214

@arpitgupta1214 arpitgupta1214 commented Apr 2, 2026

Copy link
Copy Markdown
Collaborator

…-delete-trailing-chat

feat: migrate trailing message deletes to dedicated endpoint

Summary by CodeRabbit

  • Refactor

    • Refactored the message deletion and editing workflow to improve overall system maintainability and reliability.
    • Modernized the API communication layer for all chat message-related operations.
    • Enhanced the message editor component with improved deletion handling and better error management.
  • Chores

    • Removed legacy code paths and unused functions from the codebase.
    • Consolidated redundant message management logic.

…-delete-trailing-chat

feat: migrate trailing message deletes to dedicated endpoint
@vercel

vercel Bot commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
recoup-chat Building Building Preview Apr 2, 2026 8:23pm

Request Review

@coderabbitai

coderabbitai Bot commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 7439cec2-3cb6-41ee-9f41-9b04715f8ef0

📥 Commits

Reviewing files that changed from the base of the PR and between f31c2f4 and 3bc8f34.

📒 Files selected for processing (9)
  • app/api/memories/delete-trailing/route.ts
  • components/VercelChat/message-editor.tsx
  • hooks/useDeleteTrailingMessages.ts
  • hooks/useVercelChat.ts
  • lib/api/getClientApiBaseUrl.ts
  • lib/messages/clientDeleteTrailingMessages.ts
  • lib/messages/deleteTrailingMessages.ts
  • lib/supabase/deleteMemoriesByChatIdAfterTimestamp.ts
  • lib/supabase/getMemoryById.ts

📝 Walkthrough

Walkthrough

This PR refactors trailing message deletion from a Supabase-direct pattern to an HTTP-based approach using chat-specific endpoints. The old single memory ID route is removed, replaced with a new useDeleteTrailingMessages React hook using TanStack Query. Deletion logic shifts from direct database queries to HTTP requests with Privy access token authentication.

Changes

Cohort / File(s) Summary
API Route Removal
app/api/memories/delete-trailing/route.ts
Removed the DELETE endpoint that handled memory ID-based trailing message deletion with error handling and validation.
New Hook & Query Integration
hooks/useDeleteTrailingMessages.ts
Added a new React hook wrapping TanStack Query mutation for trailing message deletion; retrieves Privy access token and exposes deleteTrailingMessages function and isDeletingTrailingMessages state.
Component Updates
components/VercelChat/message-editor.tsx, hooks/useVercelChat.ts
Replaced direct clientDeleteTrailingMessages calls with useDeleteTrailingMessages hook; updated MessageEditor to use new hook with improved state management; refactored useVercelChat to compute earliestFailedUserMessageId via memo and integrate new deletion pattern with message truncation logic.
Client Library Refactoring
lib/messages/deleteTrailingMessages.ts, lib/messages/clientDeleteTrailingMessages.ts
Removed client-side clientDeleteTrailingMessages function; refactored deleteTrailingMessages to issue HTTP DELETE request to chat-specific endpoint with chatId, fromMessageId, and Bearer token instead of Supabase operations.
Supabase Utilities Removal
lib/supabase/deleteMemoriesByChatIdAfterTimestamp.ts, lib/supabase/getMemoryById.ts
Removed getMemoryById and deleteMemoriesByRoomIdAfterTimestamp functions that previously handled memory lookups and timestamp-based deletions directly from Supabase.
API Configuration
lib/api/getClientApiBaseUrl.ts
Added utility function to retrieve API base URL with sessionStorage override support; validates overrides via URL constructor and falls back to default endpoint.

Sequence Diagram

sequenceDiagram
    participant MessageEditor as MessageEditor
    participant Hook as useDeleteTrailingMessages
    participant Query as TanStack Query
    participant Auth as Privy
    participant API as HTTP API
    
    MessageEditor->>Hook: deleteTrailingMessages({chatId, fromMessageId})
    Hook->>Query: mutateAsync() triggered
    Query->>Auth: getAccessToken()
    Auth-->>Query: accessToken
    Query->>API: DELETE /api/chats/{chatId}/trailing-messages?fromMessageId={id}<br/>(with Bearer token)
    API-->>Query: Success / Error response
    Query-->>Hook: Returns promise
    Hook-->>MessageEditor: Mutation complete, isDeletingTrailingMessages state updated
    MessageEditor->>MessageEditor: Update message state with edited content,<br/>switch to view mode, conditionally reload
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • sweetmantech

Poem

🗑️ Trailing messages take flight,
From database rows to endpoints bright,
A hook orchestrates the dance,
With tokens and queries advance—
The old path fades from sight. ✨

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@arpitgupta1214 arpitgupta1214 merged commit 3bc6d7d into main Apr 2, 2026
1 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant