Skip to content

Add streaming recipe generation via SSE#72

Merged
windoze95 merged 2 commits intomainfrom
feat/streaming-generation
Apr 5, 2026
Merged

Add streaming recipe generation via SSE#72
windoze95 merged 2 commits intomainfrom
feat/streaming-generation

Conversation

@windoze95
Copy link
Copy Markdown
Owner

Summary

  • New POST /v1/recipes/chat/stream endpoint that streams SSE progress events during recipe generation
  • Uses Anthropic's Messages.NewStreaming() API with event accumulation
  • Emits lifecycle events: recipe.startedrecipe.generatingrecipe.progressrecipe.complete (or recipe.error)
  • Existing non-streaming POST /v1/recipes/chat endpoint unchanged for backward compatibility
  • Image generation runs in background goroutine after SSE stream closes

Test plan

  • go build ./... passes
  • go vet ./... passes
  • go test ./internal/... all pass
  • Manual test: curl -N -X POST -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" -d '{"user_prompt":"simple pasta"}' http://localhost:8080/v1/recipes/chat/stream streams SSE events
  • Existing /recipes/chat endpoint still works

🤖 Generated with Claude Code

New POST /v1/recipes/chat/stream endpoint that streams progress events
during recipe generation using Anthropic's streaming API.

- internal/ai/stream.go: StreamEvent types (started, generating, progress, complete, error)
- internal/ai/anthropic.go: StreamGenerateRecipe() using Messages.NewStreaming()
  with event accumulation, progress throttling, and middleware hooks
- internal/service/recipeChat.go: StreamGenerateRecipe() orchestrates recipe
  creation, streaming AI call, post-processing, and background image gen
- internal/handlers/recipe.go: SSE handler with 5-minute timeout and
  client disconnect detection
- internal/router/router.go: Wire /recipes/chat/stream route

The existing non-streaming endpoint is unchanged for backward compatibility.
Image generation runs in background after SSE stream closes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a7a52c4c64

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread internal/ai/anthropic.go Outdated
Comment thread internal/ai/anthropic.go Outdated
1. Remove StreamEventComplete from AI layer — only the service layer
   emits complete after persistence succeeds, preventing clients from
   observing success when DB writes later fail.

2. Replace all blocking channel sends with TrySendEvent() which selects
   on ctx.Done(), preventing producer goroutines from blocking forever
   when the SSE client disconnects or the handler stops consuming.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@windoze95 windoze95 merged commit dffcf2e into main Apr 5, 2026
1 check passed
@windoze95 windoze95 deleted the feat/streaming-generation branch April 5, 2026 02:44
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