feat(web): Study Buddy panel — api, hook, component (AI-038a)#329
Merged
Conversation
api/studybuddy.ts (runStudyBuddy over SSE + getStudyBuddyRun); useStudyBuddy hook (live steps, answer on done, status, 401->auth); StudyBuddyPanel (passage echo, answer, collapsible step transcript, auth-gated). postSse now sends credentials + maps 401 to SseUnauthorizedError. Reader wiring is AI-038b. 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.
Phase 6 AI-038, slice a — the web UI for the agent: an api client, a streaming hook, and the panel. Wiring it into the reader's selection toolbar is slice b (touches the complex
ReaderPage/ReaderHighlights, kept separate for a reviewable diff).Changes
api/studybuddy.ts—runStudyBuddy(editionId, passage, chapter, callbacks)consumes the AI-037 SSE (step/done/error) viapostSse;getStudyBuddyRun(runId)fetches a persisted run for the "show steps" view.useStudyBuddyhook —stepsgrow live as the agent works,answerlands ondone,status(idle/running/done/error); a new run aborts the in-flight one (and on unmount); 401 surfaces aserror: 'auth'.StudyBuddyPanel— right slide-in panel (mirrorsAskPanel): passage echoed at top, final answer, a spinner while running, and a collapsible step transcript (each step summarized — tool name + ✓/✗, or the model's text /Looking up: …). Auth-gated with a sign-in CTA.lib/sse.ts—postSsenow sendscredentials: 'include'(needed for the authed Study Buddy stream; harmless for the public Explain one) and maps 401 → newSseUnauthorizedError.Verification
useStudyBuddy: step accumulation → answer on done; terminal error keeps the partial steps; 401 →auth; no-op on empty passage / missing edition; reset.postSse: 401 →SseUnauthorizedErrorandcredentials: 'include'sent.tsc --noEmit+pnpm buildclean. The panel renders end-to-end once wired (AI-038b); a live run is exercised on prod / AI-039.🤖 Generated with Claude Code