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
45 changes: 43 additions & 2 deletions packages/genui/a2ui-playground/lynx-src/a2ui/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ export function App() {

const storeRef = useRef<MessageStore | null>(null);
const agentRef = useRef<ReturnType<typeof createMockAgent> | null>(null);
const pendingLiveMessagesRef = useRef<unknown[] | null>(null);
const [store, setStore] = useState<MessageStore | null>(null);
const [error, setError] = useState<string>('');
const playbackMode = useMemo(
Expand Down Expand Up @@ -378,6 +379,15 @@ export function App() {
() => effectiveData.playbackPaused === true,
[effectiveData.playbackPaused],
);
const pushLiveMessagesToStore = useCallback(
(targetStore: MessageStore, messages: unknown) => {
const normalized = normalizeProtocolMessages(messages);
for (const msg of normalized) {
targetStore.push(msg);
}
},
[],
);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
const postPlaybackSync = useCallback((state: MockAgentProgress) => {
NativeModules.bridge?.call?.(
'A2UI_PLAYBACK_SYNC',
Expand Down Expand Up @@ -442,6 +452,22 @@ export function App() {
},
);

useLynxGlobalEventListener(
'A2UI_LIVE_MESSAGES',
(messages: unknown) => {
const currentStore = storeRef.current;
if (!currentStore) {
pendingLiveMessagesRef.current = Array.isArray(messages)
? messages
: [messages];
return;
}
pushLiveMessagesToStore(currentStore, messages);
agentRef.current?.stop();
agentRef.current = null;
},
);
Comment thread
coderabbitai[bot] marked this conversation as resolved.

useEffect(() => {
playbackPausedRef.current = isPlaybackPaused;
}, [isPlaybackPaused]);
Expand Down Expand Up @@ -493,9 +519,18 @@ export function App() {
storeRef.current = next;
agentRef.current = agent;
setStore(next);
const pendingLiveMessages = pendingLiveMessagesRef.current;
if (pendingLiveMessages) {
pendingLiveMessagesRef.current = null;
pushLiveMessagesToStore(next, pendingLiveMessages);
agent.stop();
agentRef.current = null;
}
syncPlaybackAgent();
// Begin streaming the demo's initial messages into the buffer.
void agent.start();
if (agentRef.current === agent) {
void agent.start();
}
};

run()
Expand All @@ -512,7 +547,13 @@ export function App() {
storeRef.current = null;
agentRef.current = null;
};
}, [isInstantPreview, postPlaybackSync, streamConfig, streamDelay]);
}, [
isInstantPreview,
postPlaybackSync,
pushLiveMessagesToStore,
streamConfig,
streamDelay,
]);

return (
<view
Expand Down
55 changes: 55 additions & 0 deletions packages/genui/a2ui-playground/src/components/CopyToast.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright 2026 The Lynx Authors. All rights reserved.
// Licensed under the Apache License Version 2.0 that can be found in the
// LICENSE file in the root directory of this source tree.
import { useCallback, useEffect, useRef, useState } from 'react';

interface CopyToastState {
message: string;
tone: 'success' | 'error';
id: number;
}

export function useCopyToast(timeoutMs = 1400) {
const [toast, setToast] = useState<CopyToastState | null>(null);
const timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);

const showCopyToast = useCallback(
(ok: boolean) => {
if (timeoutRef.current) {
window.clearTimeout(timeoutRef.current);
}
setToast({
id: Date.now(),
message: ok ? 'Copy succeeded' : 'Copy failed',
tone: ok ? 'success' : 'error',
});
timeoutRef.current = window.setTimeout(() => {
setToast(null);
timeoutRef.current = null;
}, timeoutMs);
},
[timeoutMs],
);

useEffect(() => {
return () => {
if (timeoutRef.current) {
window.clearTimeout(timeoutRef.current);
}
};
}, []);

return { toast, showCopyToast };
}

export function CopyToast(props: { toast: CopyToastState | null }) {
const { toast } = props;
if (!toast) return null;
return (
<div className='copyToastViewport' role='status' aria-live='polite'>
<div className={`copyToast copyToast-${toast.tone}`} key={toast.id}>
{toast.message}
</div>
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from 'react';
import type { CSSProperties, ReactNode } from 'react';

import { CopyToast, useCopyToast } from './CopyToast.js';
import { PreviewSimulationBar } from './PreviewSimulationBar.js';
import { QrCode } from './QrCode.js';
import { componentsByMessage } from '../demos.js';
Expand Down Expand Up @@ -198,6 +199,7 @@ export function PreviewPanel(props: PreviewPanelProps) {
const [nativeCopied, setNativeCopied] = useState(false);
const [nativeCopyFailed, setNativeCopyFailed] = useState(false);
const [nativeQrError, setNativeQrError] = useState('');
const { showCopyToast, toast: copyToast } = useCopyToast();
const [liveComponents, setLiveComponents] = useState<string[]>([]);
const liveTimersRef = useRef<ReturnType<typeof setTimeout>[]>([]);
const buildSeqRef = useRef(0);
Expand Down Expand Up @@ -483,6 +485,7 @@ export function PreviewPanel(props: PreviewPanelProps) {
const handleCopyUrl = (key: string, value: string) => {
if (key === 'webPreview') {
void copyToClipboard(value).then((ok) => {
showCopyToast(ok);
setWebCopyFailed(false);
if (!ok) {
setWebCopied(false);
Expand All @@ -497,6 +500,7 @@ export function PreviewPanel(props: PreviewPanelProps) {
}

void copyToClipboard(value).then((ok) => {
showCopyToast(ok);
setNativeCopyFailed(false);
if (!ok) {
setNativeCopied(false);
Expand All @@ -520,6 +524,7 @@ export function PreviewPanel(props: PreviewPanelProps) {
: 'previewPanel')}
style={panelStyle}
>
<CopyToast toast={copyToast} />
<div className='previewPanelHeader'>
<span className='previewPanelTitle'>{title}</span>
{headerAfterTitle}
Expand Down
121 changes: 62 additions & 59 deletions packages/genui/a2ui-playground/src/pages/AIChatPage.css
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,8 @@
border-radius: var(--geist-radius-lg);
font-size: 14px;
line-height: 1.5;
word-break: break-word;
overflow-wrap: anywhere;
word-break: normal;
flex-shrink: 0;
}

Expand Down Expand Up @@ -724,6 +725,9 @@
}

.chatMessageAction.chatMessageActionExpanded .chatMessageBody {
display: flex;
align-items: center;
gap: 8px;
padding: 8px 12px;
border-bottom: 1px solid var(--geist-border);
background: var(--geist-background);
Expand Down Expand Up @@ -760,45 +764,61 @@
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;
.chatMessageChunks {
display: flex;
flex-direction: column;
gap: 8px;
padding: 10px;
max-height: 520px;
overflow-y: auto;
background: var(--geist-surface);
}

.chatMessagePayloadEditor .cm-editor {
height: auto;
max-height: 320px;
font-family: var(--geist-mono);
font-size: 12px;
background: var(--geist-surface);
color: var(--geist-foreground);
.chatMessageChunk {
border: 1px solid var(--geist-border);
border-radius: var(--geist-radius-md);
overflow: hidden;
background: var(--geist-background);
flex-shrink: 0;
}

.chatMessagePayloadEditor .cm-scroller {
max-height: 320px;
overflow: auto;
.chatMessageSingleChunk {
margin: 10px;
border: 1px solid var(--geist-border);
border-radius: var(--geist-radius-md);
overflow: hidden;
background: var(--geist-background);
}

.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);
.chatMessageChunkHeader {
display: flex;
align-items: center;
gap: 8px;
min-height: 32px;
padding: 4px 10px;
border-bottom: 1px solid var(--geist-border);
background: color-mix(in srgb, var(--geist-surface) 88%, transparent);
}

.chatMessagePayloadEditor .cm-content {
caret-color: var(--geist-foreground);
.chatMessageChunkIndex {
font-family: var(--geist-mono);
font-size: 11px;
font-weight: 700;
color: var(--geist-secondary);
}

.chatMessagePayloadEditor .cm-activeLine,
.chatMessagePayloadEditor .cm-activeLineGutter {
background: color-mix(in srgb, var(--geist-foreground) 4%, transparent);
.chatMessageChunkJson {
margin: 0;
max-height: 260px;
overflow: auto;
padding: 8px 10px;
color: var(--geist-secondary);
font-family: var(--geist-mono);
font-size: 12px;
line-height: 1.55;
white-space: pre-wrap;
overflow-wrap: anywhere;
word-break: normal;
}

.chatGeneratedJson {
Expand Down Expand Up @@ -827,41 +847,24 @@
text-transform: uppercase;
}

.chatGeneratedJsonBadge {
padding: 1px 6px;
.chatJsonCopyButton {
margin-left: auto;
min-width: 52px;
height: 24px;
padding: 0 8px;
border: 1px solid var(--geist-border);
border-radius: 4px;
background: var(--geist-surface);
color: var(--geist-secondary);
font-size: 10px;
font-weight: 500;
letter-spacing: 0;
}

.chatGeneratedJsonEditor .cm-editor {
height: auto;
max-height: 480px;
font-family: var(--geist-mono);
font-size: 13px;
background: var(--geist-surface);
color: var(--geist-foreground);
font-size: 11px;
font-weight: 600;
letter-spacing: 0;
text-transform: none;
cursor: pointer;
}

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

.chatGeneratedJsonEditor .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);
}

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

.chatInputArea {
Expand Down
Loading
Loading