Skip to content

feat: pure SSE transport driver with reconnect + stop conditions (#46) - #51

Merged
rwrife merged 1 commit into
mainfrom
feat/issue-46-sse-transport
Jul 17, 2026
Merged

feat: pure SSE transport driver with reconnect + stop conditions (#46)#51
rwrife merged 1 commit into
mainfrom
feat/issue-46-sse-transport

Conversation

@rwrife

@rwrife rwrife commented Jul 16, 2026

Copy link
Copy Markdown
Owner

Refs #46

Adds a pure, VS Code-free SSE transport driver on top of the existing frame parser and @sse-until gate. Complements #46 without pulling in the response-viewer UI in the same PR.

What changed

  • src/core/sse/transport.ts — new module:
    • runSseTransport({ input, onEvent, ... }) drives an async iterable of decoded string chunks through SseParser, calling onEvent per dispatched event with { index, elapsedMs, reconnect } meta.
    • Stop conditions: AbortSignal, @sse-until match, maxEvents, maxDurationMs, idleMs — all enforced between events so a multi-frame chunk can't blast past a cap.
    • SseReconnectState tracks lastEventId and server-suggested retryMs across attempts.
    • reconnectHeaders(state) produces the Last-Event-ID header per spec (omitted when unset/empty).
    • clampRetryMs(...) bounds absurd server values into 100 ms – 30 s by default.
    • formatSseTranscriptLine(...) emits one JSON record per line for the .sse.jsonl transcript format.
    • SseTransportUserOptionsSchema (zod, .strict()) validates directive-sourced options before they touch the driver.
  • src/core/sse/index.ts — re-exports.
  • test/sse.transport.test.ts — 22 vitest cases covering happy paths, chunk-boundary framing, every stop condition (with injected clocks + AbortController), @sse-until errors, transcript formatting, header omission, retry clamping, and schema validation.
  • README.md — Streaming responses (SSE) section with an OpenAI-style example and links to [feature] Server-Sent Events (SSE) request support #46 for the UI follow-up.

Acceptance criteria progress (#46)

  • Pure SSE frame parser in src/core/sse/ with vitest coverage — already existed; kept intact.
  • Zod schema for parsed events — SseEventSchema (parser) + SseTransportUserOptionsSchema (driver options).
  • Response viewer streaming mode with live event list — follow-up PR (needs webview work).
  • # @sse-until <expr> directive parsed + evaluated in sandboxed context — parsed generically today; now wired through the transport driver.
  • Reconnect + Last-Event-ID behavior — implemented as pure state; integration test against a real HTTP server lands with the undici wiring PR.
  • README section with an OpenAI-style streaming example.
  • No plaintext auth material logged in transcripts — driver never writes; formatSseTranscriptLine only reflects event fields.

What's left

Follow-up PR: wire runSseTransport into the undici request path (text/event-stream detection, response-viewer streaming mode, Stop button, transcript save command, reconnect loop honoring clampRetryMs).

Checks

  • npm run lint
  • npm run typecheck
  • npm run test:unit — 480 tests pass (was 458).

@rwrife
rwrife merged commit c518c8d into main Jul 17, 2026
8 checks passed
@rwrife
rwrife deleted the feat/issue-46-sse-transport branch July 17, 2026 09:01
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