Conversation
Add new @genkit-ai/a2ui plugin with corresponding testapp including web frontend using @a2ui/lit components. Update pnpm-lock.yaml with new workspace dependencies and bump genkit version to 1.40.1.
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
Change the a2ui middleware to accept a catalog id resolved from the Genkit registry instead of a catalog object, defaulting to the bundled 'basic' catalog. Add `loadCatalog` to register in-memory or file-based catalogs under the new `a2ui-catalog` registry value type, and export `HasRegistry` from genkit registry. Update README to document catalog registration and usage.
Replace unsafe `any` type assertions with proper type guards and typed interfaces throughout the a2ui plugin. Introduce `isTextPart` type guard for narrowing parts, add `SummarizableEnvelope` interface for envelope summarization, and use `node:crypto` `randomUUID` instead of a custom fallback UUID generator.
Introduce a new 'warn' validation option that logs warnings and drops offending blocks/envelopes instead of throwing, keeping the turn alive. Update README and status to experimental, and replace hardcoded MIME type with the A2UI_MIME_TYPE constant.
|
/gemini review |
2 similar comments
|
/gemini review |
|
/gemini review |
Generate style tips, examples, and forms guidance based on the components a catalog actually provides, preventing custom catalogs from being told to emit components they lack (which would fail `validate: 'strict'`). Also clarify that middleware validates component types but not individual Icon name values.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces the @genkit-ai/a2ui plugin, which enables Genkit agents to stream rich, interactive UI surfaces using the A2UI protocol. It includes the server-side a2ui() middleware, browser-safe client helpers, a streaming parser, and a complete runnable test application. The review feedback highlights several critical robustness issues where the code lacks defensive checks when handling message content and parts, which could lead to runtime TypeErrors or data corruption if the input structures are not arrays or valid objects.
Change the a2ui data part to carry `{ envelopes }` instead of a bare
array, aligning the payload shape across client, middleware, and part
helpers. Also simplify the `surfaceId` option to accept only a fixed
string, removing the non-serializable factory function support.
Replace the hard `node:crypto` import with `globalThis.crypto.randomUUID()` to keep the middleware portable across runtimes like Cloudflare Workers. Change the default `validate` option from `'strict'` to `'warn'` so malformed blocks are dropped instead of throwing, keeping turns alive. Update README and inline docs to reflect the new defaults and behavior.
Replace low-level streamFlow with the higher-level remoteAgent client for consuming A2UI-enabled agents. This simplifies session handling via chat sessions and extracts text and A2UI envelopes directly from stream chunks.
Add validation to prevent runtime errors when action is undefined in actionToMessage, and ensure isTextPart safely handles null or non-object parts before accessing properties.
Rename the envelope extraction helper to `a2uiEnvelopesFromParts` and update it to accept model chunk content parts directly. Also add `SupportedVersion` type casts in the stream parser for stronger typing. Update README, client, and index exports accordingly.
Adds
@genkit-ai/a2ui, a Genkit plugin that lets an agent stream A2UI ("Agent to UI") surfaces — rich, interactive UI rendered incrementally by the client — instead of just prose. Also adds a runnablejs/testapps/a2uisample (Express backend + Vite/Lit frontend).How it works
A2UI travels on its own channel: a Genkit
datapart with mime typeapplication/a2ui+jsonwhose payload is an array of A2UI envelope messages (1:1 with the A2UI spec's A2A binding). The whole server integration is a single model middleware,a2ui(), added to an agent'susearray. It injects the catalog's capabilities into the system prompt, then intercepts model output (streamed chunks and the final message), extractsa2uifenced blocks, validates them against the catalog, and rewrites them into a2ui data parts.Server usage
Client usage
@genkit-ai/a2ui/clientis browser-safe. Pull envelopes off each chunk witha2uiEnvelopesand feed them to a renderer (e.g.@a2ui/lit); send user actions (button presses, form submits) back withactionToMessage:What's included
js/plugins/a2ui):a2ui()middleware, envelope parser/validator, the basic catalog + model-facing instructions, and the browser-safe/cliententrypoint (a2uiEnvelopes,actionToMessage,streamA2uiAgent). Options:catalog(required),instructions('system'),validate('strict'),surfaceId,version('v0.9'). Unit tests for the middleware and parser.js/testapps/a2ui): Express server exposing the agent + a Vite/Lit chat UI that renders surfaces, with agetWeatherdemo tool and suggested prompts.Testing
pnpm -C js/plugins/a2ui testcd js/testapps/a2ui && genkit start -- pnpm start, open http://localhost:8080 — tried weather, comparisons, and a signup form (values round-trip back to the agent).