-
Notifications
You must be signed in to change notification settings - Fork 33
add a2ui message rendering #5838
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
5149865
add a2ui message rendering
dnbrwstr 950f7bd
add a2ui fixture examples
dnbrwstr 036b5d8
simplify a2ui app changes
dnbrwstr 5b2bb23
update a2ui approval fixtures
dnbrwstr 0eba1bd
refine a2ui approval fixtures
dnbrwstr bdf01ae
format a2ui fixtures
dnbrwstr c996b29
clean up a2ui api namespace
dnbrwstr b073592
tune a2ui button styles
dnbrwstr 8f6105f
split a2ui validation helpers
dnbrwstr 1f7ffa9
chore(api): release 0.0.8
dnbrwstr 37ae198
rename a2ui action handler
dnbrwstr 2761d34
name a2ui button action types
dnbrwstr a9fba84
always pass a2ui action handler
dnbrwstr ba4570f
check a2ui action before draft state
dnbrwstr dfd87c1
remove a2ui card shadow
dnbrwstr 4b955d5
format a2ui content utils import
dnbrwstr 7f6b07d
address a2ui review comments
dnbrwstr 0f902df
revert a2ui action availability flag
dnbrwstr 0d6a439
fix nested a2ui card styling
dnbrwstr e163a07
tighten a2ui validation
dnbrwstr fb962b4
fix a2ui review comments
dnbrwstr 5f0aac4
disable a2ui actions without draft access
dnbrwstr 9e7cbce
render a2ui only in dms
dnbrwstr f0309c2
document a2ui post blobs
dnbrwstr acad299
restrict a2ui rendering paths
dnbrwstr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| { | ||
| "name": "@tloncorp/api", | ||
| "version": "0.0.6", | ||
| "version": "0.0.8", | ||
| "type": "module", | ||
| "files": [ | ||
| "dist", | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,264 @@ | ||
| import { describe, expect, test } from 'vitest'; | ||
|
|
||
| import { A2UI } from '../client/a2ui'; | ||
| import { appendToPostBlob, parsePostBlob } from '../client/content-helpers'; | ||
|
|
||
| const a2uiBlobEntry: A2UI.BlobEntry = { | ||
| type: 'a2ui', | ||
| version: 1, | ||
| messages: [ | ||
| { | ||
| version: 'v0.9', | ||
| createSurface: { | ||
| surfaceId: 'weather-card', | ||
| catalogId: 'tlon.a2ui.basic.v1', | ||
| }, | ||
| }, | ||
| { | ||
| version: 'v0.9', | ||
| updateComponents: { | ||
| surfaceId: 'weather-card', | ||
| root: 'root', | ||
| components: [ | ||
| { id: 'root', component: 'Card', child: 'body' }, | ||
| { | ||
| id: 'body', | ||
| component: 'Column', | ||
| children: ['title', 'summary', 'refreshButton'], | ||
| }, | ||
| { id: 'title', component: 'Text', text: 'Weather' }, | ||
| { id: 'summary', component: 'Text', text: '72F and clear' }, | ||
| { | ||
| id: 'refreshButton', | ||
| component: 'Button', | ||
| child: 'refreshLabel', | ||
| action: { | ||
| event: { | ||
| name: 'tlon.sendMessage', | ||
| context: { text: 'refresh weather' }, | ||
| }, | ||
| }, | ||
| }, | ||
| { id: 'refreshLabel', component: 'Text', text: 'Refresh' }, | ||
| ], | ||
| }, | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| describe('a2ui blob entries', () => { | ||
| test('validates supported a2ui payloads', () => { | ||
| expect(A2UI.validateBlobEntry(a2uiBlobEntry)).toBe(true); | ||
| }); | ||
|
|
||
| test('parsePostBlob parses supported a2ui entries', () => { | ||
| const blob = appendToPostBlob(undefined, a2uiBlobEntry); | ||
|
|
||
| expect(parsePostBlob(blob)).toEqual([a2uiBlobEntry]); | ||
| }); | ||
|
|
||
| test('rejects unsupported a2ui components and actions', () => { | ||
| expect( | ||
| parsePostBlob( | ||
| JSON.stringify([ | ||
| { | ||
| ...a2uiBlobEntry, | ||
| messages: [ | ||
| a2uiBlobEntry.messages[0], | ||
| { | ||
| version: 'v0.9', | ||
| updateComponents: { | ||
| surfaceId: 'weather-card', | ||
| components: [ | ||
| { id: 'root', component: 'Badge', text: 'unsupported' }, | ||
| ], | ||
| }, | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| ...a2uiBlobEntry, | ||
| messages: [ | ||
| a2uiBlobEntry.messages[0], | ||
| { | ||
| version: 'v0.9', | ||
| updateComponents: { | ||
| surfaceId: 'weather-card', | ||
| components: [ | ||
| { id: 'root', component: 'Button', child: 'label' }, | ||
| { id: 'label', component: 'Text', text: 'Call function' }, | ||
| ], | ||
| }, | ||
| }, | ||
| ], | ||
| }, | ||
| ]) | ||
| ) | ||
| ).toEqual([{ type: 'unknown' }, { type: 'unknown' }]); | ||
| }); | ||
|
|
||
| test('rejects malformed a2ui button optional fields', () => { | ||
| expect( | ||
| A2UI.validateBlobEntry({ | ||
| ...a2uiBlobEntry, | ||
| messages: [ | ||
| a2uiBlobEntry.messages[0], | ||
| { | ||
| version: 'v0.9', | ||
| updateComponents: { | ||
| surfaceId: 'weather-card', | ||
| root: 'root', | ||
| components: [ | ||
| { | ||
| id: 'root', | ||
| component: 'Button', | ||
| child: 'label', | ||
| disabled: 'false', | ||
| action: { | ||
| event: { | ||
| name: 'tlon.sendMessage', | ||
| context: { text: 'refresh weather' }, | ||
| }, | ||
| }, | ||
| }, | ||
| { id: 'label', component: 'Text', text: 'Refresh' }, | ||
| ], | ||
| }, | ||
| }, | ||
| ], | ||
| }) | ||
| ).toBe(false); | ||
|
|
||
| expect( | ||
| A2UI.validateBlobEntry({ | ||
| ...a2uiBlobEntry, | ||
| messages: [ | ||
| a2uiBlobEntry.messages[0], | ||
| { | ||
| version: 'v0.9', | ||
| updateComponents: { | ||
| surfaceId: 'weather-card', | ||
| root: 'root', | ||
| components: [ | ||
| { | ||
| id: 'root', | ||
| component: 'Button', | ||
| child: 'label', | ||
| variant: 'danger', | ||
| action: { | ||
| event: { | ||
| name: 'tlon.sendMessage', | ||
| context: { text: 'refresh weather' }, | ||
| }, | ||
| }, | ||
| }, | ||
| { id: 'label', component: 'Text', text: 'Refresh' }, | ||
| ], | ||
| }, | ||
| }, | ||
| ], | ||
| }) | ||
| ).toBe(false); | ||
| }); | ||
|
|
||
| test('rejects malformed a2ui text optional fields', () => { | ||
| expect( | ||
| A2UI.validateBlobEntry({ | ||
| ...a2uiBlobEntry, | ||
| messages: [ | ||
| a2uiBlobEntry.messages[0], | ||
| { | ||
| version: 'v0.9', | ||
| updateComponents: { | ||
| surfaceId: 'weather-card', | ||
| root: 'root', | ||
| components: [ | ||
| { | ||
| id: 'root', | ||
| component: 'Text', | ||
| text: 'Weather', | ||
| variant: 999, | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| ], | ||
| }) | ||
| ).toBe(false); | ||
| }); | ||
|
|
||
| test('rejects duplicate child references in containers', () => { | ||
| expect( | ||
| A2UI.validateBlobEntry({ | ||
| ...a2uiBlobEntry, | ||
| messages: [ | ||
| a2uiBlobEntry.messages[0], | ||
| { | ||
| version: 'v0.9', | ||
| updateComponents: { | ||
| surfaceId: 'weather-card', | ||
| root: 'root', | ||
| components: [ | ||
| { | ||
| id: 'root', | ||
| component: 'Column', | ||
| children: ['summary', 'summary'], | ||
| }, | ||
| { id: 'summary', component: 'Text', text: '72F and clear' }, | ||
| ], | ||
| }, | ||
| }, | ||
| ], | ||
| }) | ||
| ).toBe(false); | ||
| }); | ||
|
|
||
| test('rejects shared child references that expand beyond render limits', () => { | ||
| const layerIds = ['a', 'b', 'c', 'd', 'e', 'f', 'g'].map((prefix) => | ||
| Array.from({ length: 7 }, (_, index) => `${prefix}${index}`) | ||
| ); | ||
| const components: A2UI.Component[] = [ | ||
| { id: 'root', component: 'Column', children: layerIds[0] }, | ||
| ...layerIds.flatMap((ids, layerIndex) => | ||
| ids.map((id) => | ||
| layerIndex === layerIds.length - 1 | ||
| ? ({ id, component: 'Text', text: 'x' } as const) | ||
| : ({ | ||
| id, | ||
| component: 'Column', | ||
| children: layerIds[layerIndex + 1], | ||
| } as const) | ||
| ) | ||
| ), | ||
| ]; | ||
|
|
||
| expect(components).toHaveLength(50); | ||
| expect( | ||
| A2UI.validateBlobEntry({ | ||
| ...a2uiBlobEntry, | ||
| messages: [ | ||
| a2uiBlobEntry.messages[0], | ||
| { | ||
| version: 'v0.9', | ||
| updateComponents: { | ||
| surfaceId: 'weather-card', | ||
| root: 'root', | ||
| components, | ||
| }, | ||
| }, | ||
| ], | ||
| }) | ||
| ).toBe(false); | ||
| }); | ||
|
|
||
| test('ignores non-object messages when finding update message', () => { | ||
| const entry = { | ||
| ...a2uiBlobEntry, | ||
| messages: [42, ...a2uiBlobEntry.messages], | ||
| } as unknown as A2UI.BlobEntry; | ||
|
|
||
| expect(A2UI.validateBlobEntry(entry)).toBe(true); | ||
| expect(A2UI.getUpdateMessage(entry)).toEqual(a2uiBlobEntry.messages[1]); | ||
| expect(A2UI.getRootComponentId(entry)).toBe('root'); | ||
| }); | ||
| }); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import { expect, test } from 'vitest'; | ||
|
|
||
| import { convertContent } from '../client/postContent'; | ||
|
|
||
| test('convertContent renders supported a2ui blob entries before story content', () => { | ||
| const a2ui = { | ||
| type: 'a2ui', | ||
| version: 1, | ||
| messages: [ | ||
| { | ||
| version: 'v0.9', | ||
| createSurface: { | ||
| surfaceId: 'approval-card', | ||
| catalogId: 'tlon.a2ui.basic.v1', | ||
| }, | ||
| }, | ||
| { | ||
| version: 'v0.9', | ||
| updateComponents: { | ||
| surfaceId: 'approval-card', | ||
| root: 'root', | ||
| components: [ | ||
| { id: 'root', component: 'Card', child: 'body' }, | ||
| { id: 'body', component: 'Column', children: ['title'] }, | ||
| { id: 'title', component: 'Text', text: 'Approve DM?' }, | ||
| ], | ||
| }, | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| const content = convertContent( | ||
| [{ inline: ['Fallback text'] }], | ||
| JSON.stringify([a2ui]) | ||
| ); | ||
|
|
||
| expect(content[0]).toEqual({ type: 'a2ui', a2ui }); | ||
| expect(content[1]).toMatchObject({ type: 'paragraph' }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0.0.7 was published but the version bump wasn't committed