Skip to content

[codex] connect legacy chat route to rag agent#29

Draft
PoshanP wants to merge 1 commit into
add-all-format-supportfrom
yeet-test
Draft

[codex] connect legacy chat route to rag agent#29
PoshanP wants to merge 1 commit into
add-all-format-supportfrom
yeet-test

Conversation

@PoshanP

@PoshanP PoshanP commented Mar 25, 2026

Copy link
Copy Markdown
Owner

This change restores the legacy /api/chat/message endpoint so it behaves like a real document chat API instead of returning a hardcoded placeholder response. Before this patch, any caller still using that route would successfully pass authentication and session ownership checks, but would only receive stubbed assistant text even though the repository already contains a working RAG-backed query path. In practice, that meant older integrations could appear healthy while silently bypassing retrieval, citations, and actual answer generation.

The root cause was duplication and drift in the server routes. The RAG-specific endpoints had their own agent initialization and live query flow, while the legacy chat route had been left behind with a TODO block and placeholder insert logic. That split made the API surface inconsistent: one route used the real retrieval pipeline, and the other route looked complete but never actually queried the paper content.

The fix routes the legacy chat message handler through the existing RAG agent instead of hand-writing placeholder chat_messages. The handler still verifies that the session belongs to the authenticated user, then executes a real RAG query using the session and paper context, and finally returns the latest persisted user and assistant messages together with answer metadata such as sources, citations, query time, and session id. To reduce further drift, this change also introduces a shared getRAGAgent() helper and updates the RAG query/session routes to use the same initialization path rather than each constructing their own agent instance inline.

Validation was performed in the local workspace. git diff --check passed before the commit. After installing dependencies with npm ci, npm run lint and npm run typecheck were rerun once as part of this flow. Both still fail for pre-existing repository issues outside this diff: lint reports a large existing backlog including errors in bundled worker assets, and typecheck currently fails in frontend/components/UploadSection.tsx on a Supabase insert typing mismatch around file_type. No new failures specific to this patch were identified in that check pass.

@vercel

vercel Bot commented Mar 25, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
thinkfolio Error Error Mar 25, 2026 10:40pm

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