feat: @sse-until predicate evaluator (core slice of #46) - #50
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 atsrc/core/sse/until.ts. Given a dispatchedSseEventand 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 trackscount/index/elapsedMsacross 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.event(frozen, withtype/data/id/retry/json), plus flat aliasesdata,text,json,type,id,retry,index,elapsedMs,count.jsonwhen data starts with{/[/"— OpenAI-stylejson.choices[0].finish_reason === 'stop'and[DONE]sentinels both work.src/core/assertions.ts: shadowsglobalThis,process,require,Function,eval, timers,fetch, etc.; exposes only the standard safe globals (Math,JSON,Date, primitive wrappers,RegExp,parse*).undici, no I/O — fully unit-testable.eventbinding + aliases,count/index/elapsedMs,id/retry, empty/compile/runtime errors, sandbox shadowing, event view freezing, andSseUntilGatestate transitions with an injectable clock.Not in this PR (still under #46)
undiciwire-up + reconnect /Last-Event-IDheader.sse.jsonltranscript persistenceparser.tsalready 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)