forked from lynx-family/lynx-stack
-
Notifications
You must be signed in to change notification settings - Fork 0
feat(a2ui-playground): add per-conversation share button #549
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| # A2UI Playground | ||
|
|
||
| Interactive playground for the Lynx **GenUI** toolchain. Chat with an agent to | ||
| generate A2UI / OpenUI surfaces, browse ready-made examples, and preview the | ||
| result on the web or a real device — then rename, delete, or **share** any | ||
| conversation as a durable preview link. | ||
|
|
||
| > Private development app; it is not published to npm. For the published library | ||
| > see [`@lynx-js/genui`](../README.md). | ||
|
|
||
| ## Quick Start | ||
|
|
||
| Run everything from the **repo root**. | ||
|
|
||
| ```bash | ||
| # 1. Install workspace dependencies (first time only) | ||
| pnpm install | ||
| ``` | ||
|
|
||
| The **Create** (chat) tab talks to the GenUI server for agent responses and | ||
| preview publishing. Start it on port `3060` with at least an OpenAI key: | ||
|
|
||
| ```bash | ||
| # 2. Start the GenUI server → http://localhost:3060 | ||
| OPENAI_API_KEY=sk-... pnpm -C packages/genui/server dev | ||
| ``` | ||
|
|
||
| Then start the playground and open the URL it prints (defaults to | ||
| `http://localhost:3000`): | ||
|
|
||
| ```bash | ||
| # 3. Start the playground | ||
| pnpm -C packages/genui/a2ui-playground dev | ||
| ``` | ||
|
|
||
| On `localhost`, the Create tab automatically targets your local server on | ||
| `:3060`. To use the **hosted** agent without running a server of your own, | ||
| append the endpoint override to the playground URL: | ||
|
|
||
| ```text | ||
| ?a2uiEndpoint=https://genui-server.vercel.app/a2ui/stream | ||
| ``` | ||
|
|
||
| ### Server environment | ||
|
|
||
| | Variable | Purpose | Default | | ||
| | ---------------------------------------------------------------------------- | -------------------------------------------------- | ------------------- | | ||
| | `OPENAI_API_KEY` | Agent model access (required for the Create tab) | — | | ||
| | `OPENAI_MODEL` | Model id | `gpt-4o-mini` | | ||
| | `OPENAI_BASE_URL` | Custom OpenAI-compatible endpoint | OpenAI | | ||
| | `SUPABASE_URL`, `SUPABASE_S3_ACCESS_KEY_ID`, `SUPABASE_S3_SECRET_ACCESS_KEY` | Short, shareable preview URLs via Supabase Storage | in-memory dev store | | ||
| | `PEXELS_API_KEY` | Stock-image search in generated UIs | — | | ||
|
|
||
| Conversation **share** links and Web / Native Preview reuse the Supabase Storage | ||
| payload-publishing path — see [`examples/README.md`](./examples/README.md) for | ||
| the bucket setup and local toggles. | ||
|
|
||
| ## Scripts | ||
|
|
||
| | Command | Description | | ||
| | -------------- | -------------------------------------------------------- | | ||
| | `pnpm dev` | Build the Lynx preview bundle, then start the dev server | | ||
| | `pnpm build` | Production build | | ||
| | `pnpm preview` | Serve the production build locally | | ||
| | `pnpm test` | Run the `rstest` suite | |
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
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
67 changes: 67 additions & 0 deletions
67
packages/genui/a2ui-playground/src/utils/publishPayload.ts
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,67 @@ | ||
| // 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. | ||
|
|
||
| const ONLINE_A2UI_SERVER_ORIGIN = 'https://genui-server.vercel.app'; | ||
| const LOCAL_A2UI_SERVER_PORT = '3060'; | ||
|
|
||
| export interface PublishedPayload { | ||
| messagesUrl: string; | ||
| actionMocksUrl?: string; | ||
| } | ||
|
|
||
| function isDevHost(hostname: string): boolean { | ||
| return ( | ||
| hostname === 'localhost' | ||
| || hostname === '127.0.0.1' | ||
| || hostname === '0.0.0.0' | ||
| || hostname.startsWith('10.') | ||
| || hostname.startsWith('192.168.') | ||
| || /^172\.(?:1[6-9]|2\d|3[01])\./u.test(hostname) | ||
| ); | ||
| } | ||
|
|
||
| export function getA2UIPayloadEndpoint(): string { | ||
| if ( | ||
| window.location.protocol === 'http:' && isDevHost(window.location.hostname) | ||
| ) { | ||
| return `http://${window.location.hostname}:${LOCAL_A2UI_SERVER_PORT}/a2ui/payload`; | ||
| } | ||
| return `${ONLINE_A2UI_SERVER_ORIGIN}/a2ui/payload`; | ||
| } | ||
|
|
||
| /** | ||
| * Upload an A2UI payload to the GenUI server (Supabase Storage) and return the | ||
| * durable public URLs. The returned `messagesUrl` can be fed to | ||
| * `buildRenderUrl()` to produce a shareable `render.html` link. | ||
| */ | ||
| export async function publishA2UIPayload( | ||
| messages: unknown, | ||
| actionMocks?: Record<string, unknown>, | ||
| ): Promise<PublishedPayload> { | ||
| const res = await window.fetch(getA2UIPayloadEndpoint(), { | ||
| method: 'POST', | ||
| headers: { 'Content-Type': 'application/json' }, | ||
| body: JSON.stringify({ messages, actionMocks }), | ||
| }); | ||
| const payload = await res.json().catch(() => ({})) as { | ||
| preview?: { | ||
| messagesUrl?: unknown; | ||
| actionMocksUrl?: unknown; | ||
| }; | ||
| error?: unknown; | ||
| }; | ||
| if (!res.ok || typeof payload.preview?.messagesUrl !== 'string') { | ||
| throw new Error( | ||
| typeof payload.error === 'string' | ||
| ? payload.error | ||
| : 'Failed to publish A2UI messages', | ||
| ); | ||
| } | ||
| return { | ||
| messagesUrl: payload.preview.messagesUrl, | ||
| actionMocksUrl: typeof payload.preview.actionMocksUrl === 'string' | ||
| ? payload.preview.actionMocksUrl | ||
| : undefined, | ||
| }; | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.