Skip to content

feat: @sse-until predicate evaluator (core slice of #46) - #50

Merged
rwrife merged 1 commit into
mainfrom
feat/issue-46-sse-until-predicate
Jul 16, 2026
Merged

feat: @sse-until predicate evaluator (core slice of #46)#50
rwrife merged 1 commit into
mainfrom
feat/issue-46-sse-until-predicate

Conversation

@rwrife

@rwrife rwrife commented Jul 15, 2026

Copy link
Copy Markdown
Owner

Part of #46 — next shippable slice on top of the SSE frame parser (#49).

What

Pure, sandboxed predicate evaluator for the # @sse-until <expr> directive at src/core/sse/until.ts. Given a dispatched SseEvent and stream context, evaluates a single-line JS expression and reports whether the stream should stop.

Highlights

  • evaluateSseUntil(expr, event, ctx) — one-shot evaluator.
  • SseUntilGate — stateful helper that tracks count / index / elapsedMs across events, latches on first truthy result, and captures (but does not act on) predicate errors so a broken expression can't silently truncate a stream.
  • Bindings exposed: event (frozen, with type/data/id/retry/json), plus flat aliases data, text, json, type, id, retry, index, elapsedMs, count.
  • JSON payload auto-parsed into json when data starts with {/[/" — OpenAI-style json.choices[0].finish_reason === 'stop' and [DONE] sentinels both work.
  • Sandbox mirrors src/core/assertions.ts: shadows globalThis, process, require, Function, eval, timers, fetch, etc.; exposes only the standard safe globals (Math, JSON, Date, primitive wrappers, RegExp, parse*).
  • No VS Code, no undici, no I/O — fully unit-testable.
  • 27 vitest cases covering: JSON parsing (valid / non-JSON / malformed / empty), event binding + aliases, count/index/elapsedMs, id/retry, empty/compile/runtime errors, sandbox shadowing, event view freezing, and SseUntilGate state transitions with an injectable clock.

Not in this PR (still under #46)

  • Response viewer streaming mode
  • undici wire-up + reconnect / Last-Event-ID header
  • .sse.jsonl transcript persistence
  • README section
  • Directive-level plumbing (parser.ts already collects directives generically; this PR ships the evaluator the transport will call)

Checks

  • npm run lint
  • npm run typecheck
  • npm run test:unit ✅ (458 passed, 27 new)

@rwrife
rwrife merged commit 838234a into main Jul 16, 2026
8 checks passed
@rwrife
rwrife deleted the feat/issue-46-sse-until-predicate branch July 16, 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