Skip to content

feat: wire SSE routes through typelate/sse with --wire-typelate-sse - #114

Draft
crhntr wants to merge 4 commits into
mainfrom
feat/wire-typelate-sse
Draft

crhntr wants to merge 4 commits into
mainfrom
feat/wire-typelate-sse

Conversation

@crhntr

@crhntr crhntr commented Sep 3, 2026

Copy link
Copy Markdown
Member

Implements the first --wire-* flag from decision 00007: --wire-typelate-sse generates SSE handlers that wire the protocol through github.com/typelate/sse instead of generating it.

With the flag, the handler calls sse.New(response, request, http.StatusOK) — which owns the stream headers, flushing, and goroutine safety — so the generated http.Flusher assertion, header block, and sync.Mutex disappear, and SSETemplateData loses its WriteTo wire writer. Each render callback maps the template-set metadata to options (.IDsse.WithID, .Eventsse.WithEvent, .Retrysse.WithRetry) and sends the rendered frame with stream.Message.

Render callbacks may declare a variadic option parameter:

func (Server) Numbers(_ context.Context, sseNum func(int, ...sse.MessageOption) error) error {
	return sseNum(7, sse.WithID("n7"))
}

Resolution accepts func(T, ...O) error and records the option element type; generation validates O is the wired library's MessageOption and the closure forwards the options to Message (receiver options are appended after the template-derived ones, so they win). An options parameter without the flag, a wrong option type, and the not-yet-supported --output-datastar combination are each rejected with byte-exact err_* goldens.

The reference txtar go gets the module, generates, checks, and executes both routes against a live mux, asserting the frames — including the forwarded id: n7.

🤖 Generated with Claude Code

https://claude.ai/code/session_018Phdz9o5BUZMnd643Am5Ef

Copilot AI lite review requested due to automatic review settings September 3, 2026 23:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

There are a couple of user-facing validation/error-path issues (misleading “too many params” SSE callback message; overly strict option-type check rejecting aliases) that should be corrected before merging.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds a new generation mode for SSE routes where Muxt delegates SSE stream wiring to github.com/typelate/sse via a new --wire-typelate-sse flag, enabling cleaner generated handlers and optional forwarding of variadic message options through render callbacks.

Changes:

  • Introduces --wire-typelate-sse (CLI/config/docs) and prevents combining it with --output-datastar.
  • Extends callback-shape resolution to recognize func(T, ...O) error and validates O against sse.MessageOption during SSE generation.
  • Updates SSE handler/codegen to call sse.New(...) and send frames via stream.Message(...), and adds reference/error goldens for the new behavior.
File summaries
File Description
internal/muxt/call.go Records variadic callback option element types and allows func(T, ...O) error callback shapes.
internal/generate/sse.go Wires SSE generation through typelate/sse when enabled; validates callback options type and forwards options into stream.Message.
internal/generate/sse_template_data.go Omits generating SSETemplateData.WriteTo under --wire-typelate-sse.
internal/generate/routes.go Adds WireTypelateSSE to generator configuration.
internal/generate/html.go Rejects callback options on non-SSE (HTML) execute callbacks.
internal/cli/commands.go Adds --wire-typelate-sse flag, config-to-args plumbing, and rejects --wire-typelate-sse with --output-datastar.
docs/reference/commands/generate.md Documents the new --wire-typelate-sse flag and its behavioral implications.
cmd/muxt/testdata/reference_wire_typelate_sse.txt End-to-end reference test that go-gets typelate/sse, generates, and asserts streamed frames (including forwarded id).
cmd/muxt/testdata/err_wire_typelate_sse_with_datastar.txt Golden asserting the mutual-exclusion error for --wire-typelate-sse + --output-datastar.
cmd/muxt/testdata/err_callback_options_wrong_type.txt Golden asserting callback option type must be ...sse.MessageOption.
cmd/muxt/testdata/err_callback_options_without_wire.txt Golden asserting callback options require --wire-typelate-sse.
Review details
  • Files reviewed: 11/11 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread internal/generate/sse.go Outdated
Comment thread internal/muxt/call.go
Add the first --wire-* flag (decision 00007): --wire-typelate-sse
generates SSE handlers that call sse.New and Response.Message instead
of the generated wire protocol. sse.New owns the stream headers,
flushing, and goroutine safety, so the generated mutex and flusher
disappear, the SSETemplateData setters map to MessageOption values, and
the WriteTo wire writer is not emitted. Render callbacks may declare a
variadic func(T, ...sse.MessageOption) error parameter; resolution
records the option element type and the generated closure forwards the
options to Message. Generation validates the option type against the
wired module and rejects an options parameter without the flag;
--output-datastar with the flag is rejected until the patch framing
lands.

Assisted-by: Claude:claude-fable-5 gofumpt
@crhntr
crhntr force-pushed the feat/wire-typelate-sse branch from 245514b to 0c016ae Compare September 3, 2026 23:30
Unalias the callback option element type before the named-type check so
an alias of sse.MessageOption is accepted; say the supported callback
shapes, including the variadic options form, in the too-many-parameters
error. The wire reference txtar asserts frames with testify.

Assisted-by: Claude:claude-fable-5 gofumpt
@crhntr
crhntr marked this pull request as draft September 3, 2026 23:57
A reviewable example of --wire-typelate-sse generated output: an SSE
clock whose execute callback forwards ...sse.MessageOption per frame.
Reverted in the next commit so muxt keeps no dependency on
github.com/typelate/sse; browse this revision to read the code.

Assisted-by: Claude:claude-fable-5 gofumpt
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.

2 participants