Repository navigation
feat(agui): project the durable Thread log to AG-UI events - #62
Open
systemfsoftware-bot wants to merge 5 commits into
Open
systemfsoftware-bot wants to merge 5 commits into
systemfsoftware-bot wants to merge 5 commits into
Conversation
Add `projectDurableAgUi` and `toDurableAgUiEvents` to the `./agui` export: a pure projection of a durable Thread's canonical record log (plus in-flight provisional text) into cursor-indexed AG-UI events. Settled Runs end in RUN_FINISHED or RUN_ERROR, aborted and host-halted Runs end as a stopped RUN_FINISHED (cancelled), steering transitions are emitted as `agent.steering` custom events, and structured run output travels in RUN_FINISHED.result with a typed decode extension. The projector lives in `durable/` because the `engine` layer may not import `durable`; `./agui` now targets a top-level barrel that re-exports both `engine/AgUi` and the projector, preserving the existing AG-UI helpers.
…neutral Address review findings on the durable projector: fold every supplied record so a cursor replay rebuilds steering, subagent and committed-turn state and emits only sequences after `afterSequence`; dedupe repeated envelopes in the streaming fold; unify committed and draft message ids per Run/Turn so a live render and a reload agree; emit tool calls for provider-executed tools and `TOOL_CALL_RESULT` for inline tool results; map failed and interrupted subagents to `SUBAGENT_ERROR`/suspended rather than success; open a draft message before emitting content; emit `RUN_STARTED` before a terminal when a projection starts mid-Run; and make the projector's `Records` imports type-only so `./agui` no longer pulls durable record schemas into browser bundles.
Round-2 review fixes: (1) provisional text events are no longer filtered by afterSequence, so a cursor at the last committed sequence still streams live drafts while record-derived events stay cursor-filtered; (2) every run-scoped record marks the Run started before emitting, so a projection that begins mid-Run emits RUN_STARTED ahead of STEP/TEXT/TOOL events; (3) approval-decided, subagent-started/joined, model-aborted and compaction handlers now honor run termination; (4) a draft delta closes the opposite modality so text and reasoning blocks cannot stay interleaved. The streaming form stays the record-only fold with a non-generic options type (the typed output extension remains on the pure projector): a generic stream options type is rejected by the repository's missing-pipeable-signature lint when the generic is not reflected in the returned function, and moving it outward would break pipe inference for errorful streams.
…eering, shape inline failed tool results
The durable AG-UI stream kept every projected event in one projector for the stream's whole life; each record's events now leave the projector as they are emitted. A steering input recorded for a run whose start the slice never saw queued before RUN_STARTED; it now goes through the same live-run path as other run events, and a finished run still answers not-joined. An inline tool-result part that failed was emitted without the { error, code } shape the settled-call path gives it.
This branch has not been deployed
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.
What
Adds
projectDurableAgUiandtoDurableAgUiEventsto@systemfsoftware/agent/agui: a pure projection of a durable Thread's canonical record log plus in-flight provisional text into cursor-indexed{ sequence, event }AG-UI events, using the same event shapestoAgUiEventsemits.afterSequence; the projector folds every record (rebuilding steering, subagent and committed-turn state) and emits only events whose originating sequence is after the cursor. Provisional-text events are emitted unfiltered, so live drafts keep streaming while the cursor sits at the last committed sequence.RUN_STARTEDbefore anySTEP/TEXT/TOOLevent. Settled Runs end inRUN_FINISHED(completed) orRUN_ERROR(failed); aborted and host-halted (stopped) settle as a stoppedRUN_FINISHEDwith thecancelledoutcome, since AG-UI has nostoppedoutcome.agent.steeringcustom events —queuedwhen a steeringUserInputRecordedcommits,appliedat the next committedModelResponseRecordedfor the Run (the seam that consumes it),not-joinedat settlement for any still-pending steering input.TOOL_CALL_START/ARGS/END(provider-executed included) and inline tool results emitTOOL_CALL_RESULT; a failed result is shaped{ error, code }like the reference mapper. Subagent outcomes mapcompleted -> SUBAGENT_FINISHED(success),failed -> SUBAGENT_ERROR,aborted/stopped -> suspended.RUN_FINISHED.result(matchingtoAgUiEvents). The optional typedoutputextension decodes it through the consumer's own Schema and lets it emit extra events, fail-closed.Extension-point placement
The typed
outputextension lives on the pureprojectDurableAgUi.toDurableAgUiEventsis the record-only fold with a non-generic options type. Giving the stream a generic options type is rejected by the repository'smissing-pipeable-signaturelint (a generic that is only inferred from the options must be carried on the returned function, which forcesE/Rand breakspipe(stream, toDurableAgUiEvents(options))for errorful streams), so the typed extension stays on the pure projector, whose returned function has noE/R.Why in
durable/DurableAgUi.ts, notengine/AgUi.tspnpm check:exportsrestricts theenginelayer to imports fromcoreandengine, so a module there cannot importdurable/Records. The projector lives indurable/DurableAgUi.ts, and./aguitargets a top-level barrelsrc/AgUi.tsthat re-exports bothengine/AgUiand the projector — the same top-level cross-layer pattern assrc/index.ts. EveryRecordsimport in the projector is type-only (erased at runtime), so./aguipulls no durable record schema/runtime code into a browser bundle. The existingtoAgUiEvents,fromAgUiInputandmakeAgUiHandlernames are unchanged.Verification (head 8dfdca1)
pnpm --filter @systemfsoftware/agent typecheck— exit 0pnpm run check:exports— exit 0 (11 packages, 212 entries)pnpm run check:package-purity— exit 0 (198 entrypoints, 8019 bundled modules)pnpm --filter @systemfsoftware/agent test— exit 0 (161 tests)dprint checkon changed files — exit 0