[codex] connect legacy chat route to rag agent#29
Draft
PoshanP wants to merge 1 commit into
Draft
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This change restores the legacy
/api/chat/messageendpoint 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 sharedgetRAGAgent()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 --checkpassed before the commit. After installing dependencies withnpm ci,npm run lintandnpm run typecheckwere 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 infrontend/components/UploadSection.tsxon a Supabase insert typing mismatch aroundfile_type. No new failures specific to this patch were identified in that check pass.