feat(rag): Ask this book on mobile — user books + on-demand index (AI-027 mobile)#390
Merged
Conversation
…-027 mobile)
Wire "Ask this book" into the mobile reader for BOTH catalog editions and the
user's OWN uploaded books (previously hidden — explainBookId undefined on user
books, contradicting user-books-first). AskSheet takes an AskTarget {kind,id};
routes catalog /books/{id}/ask vs user /me/books/{id}/ask. On-demand index
gating: GET status -> prepare -> poll until Ready, with "Indexing…" state, so a
0-chunk/fresh book no longer looks broken. JSON one-shot (streaming = follow-up).
Robustness: stop polling + show sign-in on 401 (no silent spin); stall-based
timeout (90s no forward progress) instead of a flat 5min cap so large books keep
indexing while advancing. Shared rag.ts additive (catalog ask() unchanged; web
unaffected). 149 shared tests green, mobile tsc clean.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Makes "Ask this book" actually work in the mobile app (PM → architect → engineer → adversarial QA → fix cycle). Scope B1+B2; streaming + multi-turn are a follow-up.
Why
The mobile
AskSheetwas wired for catalog editions only, and even there it looked broken because nothing triggered on-demand indexing (the catalog has 0 chunks). On the user's own uploaded books — the priority surface — the Ask button didn't render at all (explainBookIdis undefined for user books). This closes both gaps.What
AskSheetnow takes anAskTarget {kind:'edition'|'userbook', id}and routesPOST /books/{id}/askvsPOST /me/books/{id}/ask. The user-book reader source sets the target with the user-book id;showAskis true for both kinds. Explain wiring untouched.GET …/index→ if notReady,POST …/indexthen poll, showing an "Indexing this book…" state; the composer enables only whenReady. A fresh upload / 0-chunk catalog book no longer returns a confusing "couldn't find this in the book."embeddedCount) replaces the flat 5-min cap, so large books keep indexing while they advance but a genuinely stuck job still fails.expo/fetch+ multi-turn/starters = next slice).Contract / safety
packages/shared/src/api/rag.tsis additive — catalogask(editionId, …)signature unchanged; web has its ownask.tsand imports only shared types, so no web regression. Index status strings (NotIndexed|Indexing|Ready|Failed) andBookIndexStatusDtoverified byte-for-byte against the backend.Verification
apps/mobiletsc --noEmitclean;packages/sharedvitest 149 green; web tsc unaffected.CHANGELOG updated (AI-027 mobile).
🤖 Generated with Claude Code