Repository navigation
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the A2UI extension spec's message list wrapper key from envelopes to messages in the Python package, aligning it with Dart, JS, and Go plugins. It maintains backward compatibility by continuing to read the legacy envelopes key if messages is absent or null. Corresponding tests and documentation have been updated and added to verify this behavior. I have no feedback to provide.
|
@pavelgj @huangjeff5 heads up — since Python SDK development has moved to https://github.com/genkit-ai/genkit-python, this Python A2UI companion PR (alongside JS #7091 and Go #7092) will need to move over to genkit-ai/genkit-python. |
chrisraygill
left a comment
There was a problem hiding this comment.
The implementation itself looks good and matches Dart/JS/Go (_messages_of handles None explicitly without falling into the Python or empty-list trap, shares validation between is_a2ui_part and envelopes_from_parts, and tests/helpers.py verifies the new messages write key).
Seconding @MichaelDoyle's note to close this here and re-open against genkit-ai/genkit-python (under packages/genkit-a2ui/). Left one small test coverage suggestion inline to fold in when moving it over.
|
Closing in favor of genkit-ai/genkit-python#150 (with @chrisraygill's extra test cases folded in). |
What's new
The Python a2ui part now carries its A2UI messages under the spec's
messageskey instead of our ownenvelopes, matching the Dart, JS and Go plugins:{ "data": { "messages": [ { "version": "v0.9", "createSurface": { "surfaceId": "tokyo-weather", "catalogId": "..." } } ] }, "metadata": { "mimeType": "application/a2ui+json" } }a2ui_partwrites{"messages": [...]}.is_a2ui_partandenvelopes_from_partsread either key, so parts written before this change (persisted sessions, older clients) still work.messageswins when both are present, and amessagesthat is present butNonefalls back toenvelopes. Calling code is unchanged:Why
The A2UI extension spec puts the message list in a data part's
data. Genkit needsdatato be an object, so we wrapped the list, but under a key we made up. The spec's own{messages: [...]}wrapper does the same job and is what renderers read.This keeps the plugins in step:
messagesmessagesorenvelopesmessagesmessagesorenvelopesmessagesmessagesorenvelopesmessagesmessagesorenvelopesIt also means user actions from a client on the new key (a Dart client using the genkit_a2ui 0.5 README helpers sends
{messages: [{version, action}]}) reach the model as[UI action ...]lines instead of a bare[UI].Breaking Changes
The package is experimental, but code that reads
part.data['envelopes']directly must switch toenvelopes_from_parts(...)(or readmessages). Code that usesenvelopes_from_partsneeds no change.Not in this PR
envelopesfallback. Reading it is free and keeps old sessions replaying.envelopes_from_partsor other identifiers. Only the wire key changes.Testing
New
tests/part_test.pycovers the written key, the legacy key, precedence when both are present, theNonefallback and a non-list value. The inbound click test runs with both keys. Test helpers readmessages, so every existing output test now checks the written key (21 fail without the change). 66 pass; ruff, ty and pyright clean.