Skip to content

Add a generic AG-UI browser response stream helper - #1198

Merged
kojiwakayama merged 1 commit into
mainfrom
feat/ag-ui-browser-response-stream
Apr 21, 2026
Merged

kojiwakayama merged 1 commit into
mainfrom
feat/ag-ui-browser-response-stream

Conversation

@kojiwakayama

Copy link
Copy Markdown
Contributor

Summary

  • add a generic AG-UI browser response stream helper for custom execution paths
  • keep package-owned bootstrap events, SSE framing, and terminal error handling while hosts supply their own encoder/final-state callback
  • document the helper and bump the package version to 0.1.226

Testing

  • deno test --no-check --allow-all src/agent/ag-ui-browser-response-stream.test.ts src/agent/ag-ui-runtime-handler.test.ts
  • deno check src/agent/ag-ui-browser-response-stream.ts src/agent/ag-ui-runtime-handler.ts src/agent/index.ts

…ion paths

Some hosts already own their own chunk type and execution loop but still need
canonical AG-UI bootstrap events, SSE framing, and terminal error handling.
A generic browser-response stream helper lets those hosts supply an encoder and
final-response callback while keeping the package responsible for the public
AG-UI stream shape.

Constraint: Public AG-UI helpers must stay generic and must not depend on host-specific chunk types
Rejected: Tell every host to keep its own AG-UI SSE wrapper | duplicates package-owned browser framing and stream error handling
Confidence: high
Scope-risk: moderate
Reversibility: clean
Directive: Prefer generic encoder/callback-based stream helpers over exposing host-specific AG-UI wrappers
Tested: deno test --no-check --allow-all src/agent/ag-ui-browser-response-stream.test.ts src/agent/ag-ui-runtime-handler.test.ts; deno check src/agent/ag-ui-browser-response-stream.ts src/agent/ag-ui-runtime-handler.ts src/agent/index.ts
Not-tested: full repo verification suite
@kojiwakayama
kojiwakayama enabled auto-merge (squash) April 21, 2026 04:50

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f449c28231

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +112 to +116
for await (const chunk of input.execution.agentUIStream) {
input.onChunk?.(state, chunk);
for (const event of input.encoder.encode(chunk)) {
writeEvent(event);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Stop execution when SSE stream is no longer writable

When the client disconnects or the controller is closed, writeEvent() returns false, but the chunk loop keeps running and still calls onChunk, encoder.encode, and waitForFinish. Because cancel() only flips streamClosed, this path can continue consuming the upstream agentUIStream after the response is detached, wasting compute and keeping long-running executions alive with no receiver.

Useful? React with 👍 / 👎.

Comment on lines +99 to +102
event: "StateSnapshot",
payload: {
snapshot: input.agUiInput.state,
},

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Normalize missing state before emitting StateSnapshot

agUiInput.state is optional, but this payload forwards it directly as snapshot. If state is undefined, JSON serialization drops the property and emits {} for StateSnapshot rather than {"snapshot":{}}, which violates the expected AG-UI event shape in strict validators and causes the initial snapshot event to be rejected.

Useful? React with 👍 / 👎.

@kojiwakayama
kojiwakayama merged commit b77cf98 into main Apr 21, 2026
17 checks passed
@kojiwakayama
kojiwakayama deleted the feat/ag-ui-browser-response-stream branch April 21, 2026 04:53
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