Skip to content

feat(ai): Study Buddy endpoint — SSE + run history (AI-037b)#328

Merged
mrviduus merged 1 commit into
mainfrom
ai-037b-studybuddy-endpoint
Jun 15, 2026
Merged

feat(ai): Study Buddy endpoint — SSE + run history (AI-037b)#328
mrviduus merged 1 commit into
mainfrom
ai-037b-studybuddy-endpoint

Conversation

@mrviduus

Copy link
Copy Markdown
Owner

Phase 6 AI-037, slice b — the reader can now run the agent and watch it work. The panel UI is AI-038.

Changes

  • POST /me/books/{editionId}/studybuddy — authenticated; runs StudyBuddyAgent on a highlighted passage and streams its progress over SSE: a step event per recorded step (index / kind / payload), a done event with the final answer (+ iterations + cost), or a terminal error event when the agent fails or exhausts its budget. The run is persisted (AI-036) on completion with the right status — a budget-exhausted run keeps its partial transcript. X-Accel-Buffering: no for the Cloudflare tunnel; client disconnect propagates untraced (no false trace); rate-limited (studybuddy, 8/min/IP — each run is several LLM calls).
  • GET /me/studybuddy/runs/{runId} — returns a persisted run (scoped to the requesting user) with its step transcript parsed from jsonb, for the "show steps" view.

Design notes

  • The SSE generator owns persistence: it resolves the scoped IAgentRunWriter from the request services (alive for the duration of the stream), accumulates the outcome, and writes one agent_run row in a best-effort terminal block — a failed write never breaks the response the client already received (surfaced as persisted:false on the error event).
  • Tool DB access is safe under the streamed run: the dispatcher already creates a fresh DI scope per tool call (fix(ai): per-tool DI scope + streamed tool calls traced (AI-031b follow-up) #314), so parallel tools don't share the request DbContext.

Verification

  • StreamRunAsync over the real agent + loop + scripted LLM: direct answer → stepdone + a persisted completed run with the output; a never-terminating model → partial steps → terminal error + a persisted budget_exhausted run that keeps its transcript.
  • Live-API integration (skip-friendly): no-auth → 401, authed empty passage → 400, no-auth GET → 401, unknown run → 404.
  • Full TextStack.UnitTests (272) green; solution builds; dotnet format clean. The real streamed run (key + corpus) is exercised on prod / AI-039 eval.

🤖 Generated with Claude Code

POST /me/books/{id}/studybuddy runs StudyBuddyAgent on a passage and streams
its steps over SSE (step* -> done | error), persisting the run (AI-036) with
the right status (budget-exhausted keeps its transcript). GET
/me/studybuddy/runs/{id} returns a persisted run for the show-steps UI.
Rate-limited (studybuddy, 8/min), X-Accel-Buffering off, client disconnect
untraced. Panel UI is AI-038.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@mrviduus mrviduus merged commit d0e6b16 into main Jun 15, 2026
5 checks passed
@mrviduus mrviduus deleted the ai-037b-studybuddy-endpoint branch June 15, 2026 02:24
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