Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions packages/genui/a2ui-playground/lynx-src/a2ui/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ interface InitData {
playbackMode?: boolean;
theme?: 'light' | 'dark';
playbackPaused?: boolean;
liveAction?: boolean;
}

type Theme = 'light' | 'dark';
Expand Down Expand Up @@ -211,6 +212,12 @@ function normalizeInitDataLike(raw: unknown): InitData {
out.theme = theme.toLowerCase() as Theme;
}

const liveAction = obj.liveAction;
if (liveAction !== undefined) {
out.liveAction = liveAction === true || liveAction === '1'
|| liveAction === 1;
}

return out;
}

Expand All @@ -224,6 +231,7 @@ function mergeInitDataPreferLeft(a: InitData, b: InitData): InitData {
playbackMode: a.playbackMode ?? b.playbackMode,
playbackPaused: a.playbackPaused ?? b.playbackPaused,
theme: a.theme ?? b.theme,
liveAction: a.liveAction ?? b.liveAction,
};
}

Expand Down Expand Up @@ -414,6 +422,18 @@ export function App() {
},
);

useLynxGlobalEventListener(
'A2UI_ACTION_RESPONSE',
(messages: unknown) => {
const currentStore = storeRef.current;
if (!currentStore) return;
const normalized = normalizeProtocolMessages(messages);
for (const msg of normalized) {
currentStore.push(msg);
}
},
);

useEffect(() => {
playbackPausedRef.current = isPlaybackPaused;
}, [isPlaybackPaused]);
Expand Down Expand Up @@ -516,6 +536,14 @@ export function App() {
messageStore={store}
catalogs={ALL_BUILTINS}
onAction={(action) => {
if (effectiveData.liveAction) {
NativeModules.bridge.call(
'A2UI_USER_ACTION',
action as unknown as Record<string, unknown>,
() => undefined,
);
return;
}
// Forward user actions to the mock agent — it pushes
// the canned response messages back into the same store.
void agentRef.current?.onAction(action);
Expand Down
251 changes: 241 additions & 10 deletions packages/genui/a2ui-playground/src/pages/AIChatPage.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
display: flex;
flex-direction: column;
min-width: 0;
min-height: 0;
}

.chatHeader {
Expand Down Expand Up @@ -62,6 +63,7 @@

.chatMessages {
flex: 1;
min-height: 0;
overflow-y: auto;
padding: 20px;
display: flex;
Expand All @@ -76,6 +78,7 @@
font-size: 14px;
line-height: 1.5;
word-break: break-word;
flex-shrink: 0;
}

.chatMessageUser {
Expand All @@ -92,14 +95,202 @@
border-bottom-left-radius: 4px;
}

.chatGeneratedJson {
.chatMessageAction {
align-self: center;
max-width: 90%;
padding: 6px 12px;
background: transparent;
border: 1px dashed var(--geist-border);
border-radius: 999px;
color: var(--geist-secondary);
font-size: 12px;
font-family: var(--geist-mono);
}

.chatMessageActionPending {
display: inline-flex;
align-items: center;
gap: 8px;
}

.chatMessageActionSpinner {
width: 12px;
height: 12px;
border: 1.5px solid
color-mix(in srgb, var(--geist-secondary) 35%, transparent);
border-top-color: var(--geist-secondary);
border-radius: 50%;
display: inline-block;
animation: chat-message-action-spin 0.8s linear infinite;
flex-shrink: 0;
}

@keyframes chat-message-action-spin {
to {
transform: rotate(360deg);
}
}

.chatMessageAction.chatMessageActionExpanded {
align-self: flex-start;
width: 100%;
max-width: 100%;
max-width: 80%;
padding: 0;
border: 1px solid var(--geist-border);
border-radius: var(--geist-radius-md);
background: var(--geist-surface);
overflow: hidden;
}

.chatMessageStatus {
align-self: stretch;
display: flex;
align-items: center;
gap: 8px;
max-width: 100%;
padding: 6px 10px;
border: none;
border-radius: var(--geist-radius-md);
background: transparent;
color: var(--geist-secondary);
font-size: 12px;
font-family: var(--geist-mono);
line-height: 1.5;
}

.chatMessageStatus .chatMessageBody {
display: inline-flex;
align-items: center;
gap: 8px;
flex-wrap: wrap;
}

.chatMessageStatusIcon {
font-size: 14px;
line-height: 1;
flex-shrink: 0;
}

.chatMessageStatusInline {
padding: 1px 6px;
border: 1px solid var(--geist-border);
border-radius: 4px;
background: var(--geist-surface);
color: var(--geist-foreground);
font-family: var(--geist-mono);
font-size: 11px;
}

.chatMessageStatus-info {
color: var(--geist-secondary);
}

.chatMessageStatus-pending {
color: var(--geist-foreground);
}

.chatMessageStatus-success {
color: color-mix(
in srgb,
var(--geist-success, #0a7d2c) 92%,
var(--geist-foreground)
);
}

.chatMessageStatus-error {
color: color-mix(
in srgb,
var(--geist-error, #c0392b) 92%,
var(--geist-foreground)
);
}

.chatMessageAction.chatMessageActionExpanded .chatMessageBody {
padding: 8px 12px;
border-bottom: 1px solid var(--geist-border);
background: var(--geist-background);
color: var(--geist-foreground);
}

.chatMessageJson {
align-self: flex-start;
width: 100%;
max-width: 80%;
padding: 0;
border: 1px solid var(--geist-border);
border-radius: var(--geist-radius-md);
background: var(--geist-surface);
overflow: hidden;
background: var(--geist-code-bg);
}

.chatMessageJson .chatMessageBody {
display: flex;
align-items: center;
min-height: 34px;
padding: 0 12px;
border-bottom: 1px solid var(--geist-border);
background: var(--geist-background);
color: var(--geist-secondary);
font-size: 11px;
font-weight: 700;
letter-spacing: 0.04em;
text-transform: uppercase;
}

.chatMessagePayload {
display: flex;
flex-direction: column;
}

.chatMessagePayloadLabel {
padding: 6px 12px;
border-bottom: 1px solid var(--geist-border);
background: var(--geist-background);
color: var(--geist-secondary);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.06em;
text-transform: uppercase;
}

.chatMessagePayloadEditor .cm-editor {
height: auto;
max-height: 320px;
font-family: var(--geist-mono);
font-size: 12px;
background: var(--geist-surface);
color: var(--geist-foreground);
}

.chatMessagePayloadEditor .cm-scroller {
max-height: 320px;
overflow: auto;
}

.chatMessagePayloadEditor .cm-gutters {
background: color-mix(in srgb, var(--geist-surface) 88%, var(--geist-border));
color: var(--geist-secondary);
border-right: 1px solid
color-mix(in srgb, var(--geist-border) 82%, transparent);
}

.chatMessagePayloadEditor .cm-content {
caret-color: var(--geist-foreground);
}

.chatMessagePayloadEditor .cm-activeLine,
.chatMessagePayloadEditor .cm-activeLineGutter {
background: color-mix(in srgb, var(--geist-foreground) 4%, transparent);
}

.chatGeneratedJson {
width: 100%;
max-width: 80%;
align-self: flex-start;
border: 1px solid var(--geist-border);
border-radius: var(--geist-radius-md);
overflow: hidden;
background: var(--geist-surface);
flex-shrink: 0;
}

Expand Down Expand Up @@ -131,39 +322,79 @@

.chatGeneratedJsonEditor .cm-editor {
height: auto;
max-height: 400px;
max-height: 480px;
font-family: var(--geist-mono);
font-size: 13px;
background: var(--geist-code-bg);
color: var(--geist-code-fg);
background: var(--geist-surface);
color: var(--geist-foreground);
}

.chatGeneratedJsonEditor .cm-scroller {
max-height: 400px;
max-height: 480px;
overflow: auto;
}

.chatGeneratedJsonEditor .cm-gutters {
background: color-mix(in srgb, var(--geist-code-bg) 88%, black);
color: color-mix(in srgb, var(--geist-code-fg) 58%, white);
background: color-mix(in srgb, var(--geist-surface) 88%, var(--geist-border));
color: var(--geist-secondary);
border-right: 1px solid
color-mix(in srgb, var(--geist-border) 82%, transparent);
}

.chatGeneratedJsonEditor .cm-activeLine,
.chatGeneratedJsonEditor .cm-activeLineGutter {
background: color-mix(in srgb, var(--geist-background) 12%, transparent);
background: color-mix(in srgb, var(--geist-foreground) 4%, transparent);
}

.chatInputArea {
padding: 12px 20px;
border-top: 1px solid var(--geist-border);
background: var(--geist-background);
display: flex;
flex-direction: column;
gap: 8px;
flex-shrink: 0;
}

.chatSuggestionsRow {
display: flex;
flex-wrap: wrap;
gap: 6px;
}

.chatSuggestionChip {
display: inline-flex;
align-items: center;
height: 28px;
padding: 0 12px;
border: 1px solid var(--geist-border);
border-radius: 999px;
background: var(--geist-surface);
color: var(--geist-foreground);
font-size: 12px;
font-weight: 500;
cursor: pointer;
transition:
background var(--geist-transition),
border-color var(--geist-transition);
white-space: nowrap;
}

.chatSuggestionChip:hover {
background: color-mix(in srgb, var(--geist-surface) 80%, var(--geist-border));
border-color: var(--geist-foreground);
}

.chatSuggestionChip:disabled {
opacity: 0.45;
cursor: not-allowed;
}

.chatInputRow {
display: flex;
gap: 8px;
}

.chatInput {
flex: 1;
height: 40px;
Expand Down
Loading
Loading