Skip to content

refactor(agui): decode a run's frames back into typed events - #1719

Merged
edenreich merged 1 commit into
mainfrom
refactor/issue-1713-typed-decode
Nov 6, 2026
Merged

edenreich merged 1 commit into
mainfrom
refactor/issue-1713-typed-decode

Conversation

@edenreich

Copy link
Copy Markdown
Contributor

Part of #1713

Summary

First step of rendering the chat TUI's agent runs from AG-UI events: internal/protocols/agui gains Decode, the client side of Run. It reads one frame back into its typed event, so a client switches on Go types instead of keeping its own JSON structs. Nothing consumes it yet, so no behavior changes.

Changes

  • agui.Decode(frame) (Event, error) wraps the SDK's events.EventFromJSON. A frame that is not an AG-UI event is an error, which is how a client tells the binding's lowercase app frames apart.
  • The 18 event types a Run and the Write functions produce are aliased in the package, so a client names them without importing the SDK, which depguard confines to this package. No new import, so the closed import list is unchanged.
  • The package README describes Decode.
  • Tests: a run driven through every event kind decodes to each aliased type, and an app frame is refused.

Plan

The refactor is staged so each step ships alone:

  1. Typed decode (this PR)
  2. Close the wire gaps the TUI needs: per-turn metrics, optimization status, tool cancelled, computer-use events
  3. A TUI reducer over AG-UI events, daemon chats first, and delete headless/run_decoder.go
  4. The serve loop over any reader and writer
  5. A local in-memory thread, local chats move to the same path
  6. Delete the ChatEvent dispatch from the TUI handlers

Downstream

  • no docs ticket: internal-only refactor

A client of the AG-UI stream had no typed way to read it: the only decoder was
hand-written against its own JSON structs. Decode wraps the SDK's decoder and
the event types are aliased, so a client switches on them without importing
the SDK. First step of rendering the chat TUI from AG-UI events.
@edenreich
edenreich force-pushed the refactor/issue-1713-typed-decode branch from f77bee7 to 5071f8b Compare November 6, 2026 19:37
@edenreich
edenreich merged commit 29623e6 into main Nov 6, 2026
1 check passed
@edenreich
edenreich deleted the refactor/issue-1713-typed-decode branch November 6, 2026 22:30
edenreich added a commit that referenced this pull request Nov 6, 2026
Part of #1713. Stacked on #1722 (which stacks on #1721 and #1719).

## Summary

Phase 3 of the plan: the client side of the AG-UI stream moves into the
TUI and onto typed events. `headless.RunDecoder` is gone.
`tui/runview.Reducer` replaces it, built on `agui.Decode`, and the
daemon chat uses it.

## Changes

- `internal/presentation/tui/runview` (new): `Reducer` folds a thread's
AG-UI events into the chat events the TUI handlers render. `Reduce`
takes a typed `agui.Event`, `Decode` takes a raw frame. The step
reconstruction, the held completion and the mid-run attach tolerance are
unchanged.
- The hand-written frame structs (`decodedFrame`, `decodedPatch`) are
deleted. The reducer switches on the SDK's event types through the
`agui` aliases.
- `internal/presentation/headless/run_decoder.go` and its test are
deleted from `headless`, which now only writes the protocol.
- `agui.InterruptPlanApproval` joins the other interrupt reasons in
`agui`, replacing the unexported `headless` constant both sides needed.
- The reducer reads the two activities #1722 added, so a daemon chat now
shows a cancelled tool call and a conversation optimization.
- `tui/daemonthread.Agent` uses the reducer. Nothing else in the TUI
changes.

## Deviation from the plan

The plan had the reducer return `tui.*` messages directly and bypass the
handlers for daemon chats. That would leave two run renderers in the TUI
(handlers for local chats, reducer for daemon chats) until the last
phase. The reducer keeps returning the chat events the handlers already
take, so there is one renderer at every step. The handlers stop
depending on agent-owned event types in the last phase, once local chats
also arrive as frames.

## Verification

- The reducer's round-trip tests against `RunEncoder` moved with it and
pass, with one new case for the two activities.
- `go test ./...`, `task precommit:run` (0 issues) and the e2e suite
with `-race` (`ok tests/e2e 168s`), which covers a daemon chat turn,
reattach, direct commands and teleport.

## Downstream

- no docs ticket: internal-only refactor
@inference-gateway-releaser

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.246.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@inference-gateway-releaser inference-gateway-releaser Bot added the released Shipped in a release label Nov 7, 2026
@edenreich edenreich moved this from Todo to Done in 2026 Nov 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released Shipped in a release

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant