Skip to content

Commit dca18e8

Browse files
chore: migrate to agents-ui (#308)
1 parent 84c59a8 commit dca18e8

59 files changed

Lines changed: 6372 additions & 1259 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Agent Starter for React
22

3-
This is a starter template for [LiveKit Agents](https://docs.livekit.io/agents) that provides a simple voice interface using the [LiveKit JavaScript SDK](https://github.com/livekit/client-sdk-js). It supports [voice](https://docs.livekit.io/agents/start/voice-ai), [transcriptions](https://docs.livekit.io/agents/build/text/), and [virtual avatars](https://docs.livekit.io/agents/integrations/avatar).
3+
This is a starter template for [LiveKit Agents](https://docs.livekit.io/agents) that provides a simple voice interface using [Agents UI](https://livekit.io/ui) components and [LiveKit JavaScript SDK](https://github.com/livekit/client-sdk-js). It supports [voice](https://docs.livekit.io/agents/start/voice-ai), [transcriptions](https://docs.livekit.io/agents/build/text/), and [virtual avatars](https://docs.livekit.io/agents/integrations/avatar).
44

55
Also available for:
66
[Android](https://github.com/livekit-examples/agent-starter-android)[Flutter](https://github.com/livekit-examples/agent-starter-flutter)[Swift](https://github.com/livekit-examples/agent-starter-swift)[React Native](https://github.com/livekit-examples/agent-starter-react-native)
@@ -25,27 +25,63 @@ This template is built with Next.js and is free for you to use or modify as you
2525

2626
### Project structure
2727

28+
This starter uses the [Agents UI](https://livekit.io/ui) components for core UI elements like media controls, audio visualizers, chat transcripts, and providing session data. Shadcn installs components into `components/` folder so you can customize them like any other local component.
29+
2830
```
2931
agent-starter-react/
3032
├── app/
31-
│ ├── (app)/
3233
│ ├── api/
33-
│ ├── components/
34-
│ ├── fonts/
35-
│ ├── globals.css
36-
│ └── layout.tsx
3734
├── components/
38-
│ ├── livekit/
39-
│ ├── ui/
40-
│ ├── app.tsx
41-
│ ├── session-view.tsx
42-
│ └── welcome.tsx
35+
│ ├── agents-ui/ - Agents UI components
36+
│ ├── ai-elements/ - AI Elements components
37+
│ ├── app/ - App-specific components
38+
│ ├── ui/ - Primitive shadcn/ui components
39+
── fonts/
4340
├── hooks/
4441
├── lib/
4542
├── public/
4643
└── package.json
4744
```
4845

46+
Business logic lives within the `components/app` folder. It's here where the application's state and behavior is managed and the various Shadcn UI components are composed together.
47+
48+
| File | Description |
49+
| --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
50+
| `session-view.tsx` | Initializes the application, and LiveKit session. Renders the view controller and session UI including chat transcript, media tiles, and control bar. |
51+
| `view-controller.tsx` | Manages the transitions between the welcome and session views based on the LiveKit session state. |
52+
| `welcome-view.tsx` | Renders the welcome UI when the LiveKit session is not connected. |
53+
| `chat-transcript.tsx` | Manages the chat transcript transitions. |
54+
| `tile-layout.tsx` | Manages the layout and transition of media tiles in various application states. |
55+
56+
### Component usage
57+
58+
Most Agents UI components require access to a LiveKit session object for access to values like agent state or audio tracks. A Session object can be created from a [TokenSource](/reference/client-sdk-js/variables/TokenSource.html), and provided by wrapping the component in an [AgentSessionProvider](/reference/components/shadcn/component/agent-session-provider).
59+
60+
See [`components/app/app.tsx`](./components/app/app.tsx) for an example of how this is done in this app.
61+
62+
### Customizing components
63+
64+
Agents UI components, like most Shadcn compopnents, take as many primitive attributes as possible. For example, the [AgentControlBar](/reference/components/shadcn/component/agent-control-bar/page.mdoc) component extends `HTMLAttributes<HTMLDivElement>`, so you can pass any props that a div supports. This makes it easy to extend the component with your own styles or functionality.
65+
66+
You can edit any Agents UI component's source code in the `components/agents-ui` directory. For style changes, we recommend passing in tailwind classes to override the default styles. Take a look at the source code to get a sense of how to override a component's default styles.
67+
68+
### Updating components
69+
70+
To update the Agents UI components to the latest publication, run the following command:
71+
72+
```bash
73+
pnpm shadcn:install
74+
```
75+
76+
> [!NOTE]
77+
> The CLI will ask before overwriting any modified files so you can avoid losing any customizations you might have made.
78+
79+
### Installing components
80+
81+
```bash
82+
pnpm dlx shadcn@latest add @agents-ui/{component-name-a} @agents-ui/{component-name-b}
83+
```
84+
4985
## Getting started
5086

5187
> [!TIP]

app/(app)/layout.tsx

Lines changed: 0 additions & 46 deletions
This file was deleted.

app/layout.tsx

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import localFont from 'next/font/local';
33
import { headers } from 'next/headers';
44
import { ThemeProvider } from '@/components/app/theme-provider';
55
import { ThemeToggle } from '@/components/app/theme-toggle';
6-
import { cn, getAppConfig, getStyles } from '@/lib/utils';
6+
import { cn } from '@/lib/shadcn/utils';
7+
import { getAppConfig, getStyles } from '@/lib/utils';
78
import '@/styles/globals.css';
89

910
const publicSans = Public_Sans({
@@ -45,8 +46,8 @@ interface RootLayoutProps {
4546
export default async function RootLayout({ children }: RootLayoutProps) {
4647
const hdrs = await headers();
4748
const appConfig = await getAppConfig(hdrs);
48-
const { pageTitle, pageDescription } = appConfig;
4949
const styles = getStyles(appConfig);
50+
const { pageTitle, pageDescription, companyName, logo, logoDark } = appConfig;
5051

5152
return (
5253
<html
@@ -70,6 +71,35 @@ export default async function RootLayout({ children }: RootLayoutProps) {
7071
enableSystem
7172
disableTransitionOnChange
7273
>
74+
<header className="fixed top-0 left-0 z-50 hidden w-full flex-row justify-between p-6 md:flex">
75+
<a
76+
target="_blank"
77+
rel="noopener noreferrer"
78+
href="https://livekit.io"
79+
className="scale-100 transition-transform duration-300 hover:scale-110"
80+
>
81+
{/* eslint-disable-next-line @next/next/no-img-element */}
82+
<img src={logo} alt={`${companyName} Logo`} className="block size-6 dark:hidden" />
83+
{/* eslint-disable-next-line @next/next/no-img-element */}
84+
<img
85+
src={logoDark ?? logo}
86+
alt={`${companyName} Logo`}
87+
className="hidden size-6 dark:block"
88+
/>
89+
</a>
90+
<span className="text-foreground font-mono text-xs font-bold tracking-wider uppercase">
91+
Built with{' '}
92+
<a
93+
target="_blank"
94+
rel="noopener noreferrer"
95+
href="https://docs.livekit.io/agents"
96+
className="underline underline-offset-4"
97+
>
98+
LiveKit Agents
99+
</a>
100+
</span>
101+
</header>
102+
73103
{children}
74104
<div className="group fixed bottom-0 left-1/2 z-50 mb-2 -translate-x-1/2">
75105
<ThemeToggle className="translate-y-20 transition-transform delay-150 duration-300 group-hover:translate-y-0" />
File renamed without changes.

components.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@
1010
"cssVariables": true,
1111
"prefix": ""
1212
},
13+
"iconLibrary": "lucide",
1314
"aliases": {
1415
"components": "@/components",
15-
"utils": "@/lib/utils",
16+
"utils": "@/lib/shadcn/utils",
1617
"ui": "@/components/ui",
17-
"lib": "@/lib",
18+
"lib": "@/lib/shadcn",
1819
"hooks": "@/hooks"
1920
},
20-
"iconLibrary": "phosphor"
21+
"registries": {
22+
"@agents-ui": "https://livekit.io/ui/r/{name}.json",
23+
"@ai-elements": "https://registry.ai-sdk.dev/{name}.json"
24+
}
2125
}

0 commit comments

Comments
 (0)