Skip to content

Commit 2050e89

Browse files
committed
update assistant-ui
1 parent 5636527 commit 2050e89

20 files changed

+2918
-1872
lines changed

chat-agent-ui/app/globals.css

Lines changed: 61 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -3,66 +3,68 @@
33
@tailwind utilities;
44

55
@layer base {
6-
:root {
7-
--background: 0 0% 100%;
8-
--foreground: 240 10% 3.9%;
9-
--card: 0 0% 100%;
10-
--card-foreground: 240 10% 3.9%;
11-
--popover: 0 0% 100%;
12-
--popover-foreground: 240 10% 3.9%;
13-
--primary: 240 5.9% 10%;
14-
--primary-foreground: 0 0% 98%;
15-
--secondary: 240 4.8% 95.9%;
16-
--secondary-foreground: 240 5.9% 10%;
17-
--muted: 240 4.8% 95.9%;
18-
--muted-foreground: 240 3.8% 46.1%;
19-
--accent: 240 4.8% 95.9%;
20-
--accent-foreground: 240 5.9% 10%;
21-
--destructive: 0 84.2% 60.2%;
22-
--destructive-foreground: 0 0% 98%;
23-
--border: 240 5.9% 90%;
24-
--input: 240 5.9% 90%;
25-
--ring: 240 10% 3.9%;
26-
--chart-1: 12 76% 61%;
27-
--chart-2: 173 58% 39%;
28-
--chart-3: 197 37% 24%;
29-
--chart-4: 43 74% 66%;
30-
--chart-5: 27 87% 67%;
31-
--radius: 0.5rem
32-
}
33-
.dark {
34-
--background: 240 10% 3.9%;
35-
--foreground: 0 0% 98%;
36-
--card: 240 10% 3.9%;
37-
--card-foreground: 0 0% 98%;
38-
--popover: 240 10% 3.9%;
39-
--popover-foreground: 0 0% 98%;
40-
--primary: 0 0% 98%;
41-
--primary-foreground: 240 5.9% 10%;
42-
--secondary: 240 3.7% 15.9%;
43-
--secondary-foreground: 0 0% 98%;
44-
--muted: 240 3.7% 15.9%;
45-
--muted-foreground: 240 5% 64.9%;
46-
--accent: 240 3.7% 15.9%;
47-
--accent-foreground: 0 0% 98%;
48-
--destructive: 0 62.8% 30.6%;
49-
--destructive-foreground: 0 0% 98%;
50-
--border: 240 3.7% 15.9%;
51-
--input: 240 3.7% 15.9%;
52-
--ring: 240 4.9% 83.9%;
53-
--chart-1: 220 70% 50%;
54-
--chart-2: 160 60% 45%;
55-
--chart-3: 30 80% 55%;
56-
--chart-4: 280 65% 60%;
57-
--chart-5: 340 75% 55%
58-
}
6+
:root {
7+
--background: 0 0% 100%;
8+
--foreground: 240 10% 3.9%;
9+
--card: 0 0% 100%;
10+
--card-foreground: 240 10% 3.9%;
11+
--popover: 0 0% 100%;
12+
--popover-foreground: 240 10% 3.9%;
13+
--primary: 240 5.9% 10%;
14+
--primary-foreground: 0 0% 98%;
15+
--secondary: 240 4.8% 95.9%;
16+
--secondary-foreground: 240 5.9% 10%;
17+
--muted: 240 4.8% 95.9%;
18+
--muted-foreground: 240 3.8% 46.1%;
19+
--accent: 240 4.8% 95.9%;
20+
--accent-foreground: 240 5.9% 10%;
21+
--destructive: 0 84.2% 60.2%;
22+
--destructive-foreground: 0 0% 98%;
23+
--border: 240 5.9% 90%;
24+
--input: 240 5.9% 90%;
25+
--ring: 240 10% 3.9%;
26+
--chart-1: 12 76% 61%;
27+
--chart-2: 173 58% 39%;
28+
--chart-3: 197 37% 24%;
29+
--chart-4: 43 74% 66%;
30+
--chart-5: 27 87% 67%;
31+
--radius: 0.5rem
32+
}
33+
34+
.dark {
35+
--background: 240 10% 3.9%;
36+
--foreground: 0 0% 98%;
37+
--card: 240 10% 3.9%;
38+
--card-foreground: 0 0% 98%;
39+
--popover: 240 10% 3.9%;
40+
--popover-foreground: 0 0% 98%;
41+
--primary: 0 0% 98%;
42+
--primary-foreground: 240 5.9% 10%;
43+
--secondary: 240 3.7% 15.9%;
44+
--secondary-foreground: 0 0% 98%;
45+
--muted: 240 3.7% 15.9%;
46+
--muted-foreground: 240 5% 64.9%;
47+
--accent: 240 3.7% 15.9%;
48+
--accent-foreground: 0 0% 98%;
49+
--destructive: 0 62.8% 30.6%;
50+
--destructive-foreground: 0 0% 98%;
51+
--border: 240 3.7% 15.9%;
52+
--input: 240 3.7% 15.9%;
53+
--ring: 240 4.9% 83.9%;
54+
--chart-1: 220 70% 50%;
55+
--chart-2: 160 60% 45%;
56+
--chart-3: 30 80% 55%;
57+
--chart-4: 280 65% 60%;
58+
--chart-5: 340 75% 55%
59+
}
5960
}
6061

6162
@layer base {
62-
* {
63-
@apply border-border;
64-
}
65-
body {
66-
@apply bg-background text-foreground;
67-
}
63+
* {
64+
@apply border-border;
65+
}
66+
67+
body {
68+
@apply bg-background text-foreground;
69+
}
6870
}

chat-agent-ui/app/layout.tsx

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
1-
import type { Metadata } from "next";
1+
import type {Metadata} from "next";
22
import localFont from "next/font/local";
33
import "./globals.css";
44

55
const geistSans = localFont({
6-
src: "./fonts/GeistVF.woff",
7-
variable: "--font-geist-sans",
8-
weight: "100 900",
6+
src: "./fonts/GeistVF.woff",
7+
variable: "--font-geist-sans",
8+
weight: "100 900",
99
});
1010
const geistMono = localFont({
11-
src: "./fonts/GeistMonoVF.woff",
12-
variable: "--font-geist-mono",
13-
weight: "100 900",
11+
src: "./fonts/GeistMonoVF.woff",
12+
variable: "--font-geist-mono",
13+
weight: "100 900",
1414
});
1515

1616
export const metadata: Metadata = {
17-
title: "Agent UI",
18-
description: "Chat Agent",
17+
title: "Agent UI",
18+
description: "Chat Agent",
1919
};
2020

2121
export default function RootLayout({
22-
children,
23-
}: Readonly<{
24-
children: React.ReactNode;
22+
children,
23+
}: Readonly<{
24+
children: React.ReactNode;
2525
}>) {
26-
return (
27-
<html lang="en">
26+
return (
27+
<html lang="en">
2828
<body
29-
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
29+
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
3030
>
31-
{children}
31+
{children}
3232
</body>
33-
</html>
34-
);
33+
</html>
34+
);
3535
}

chat-agent-ui/app/page.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { AgentUI } from "@/components/AgentUI";
1+
import {AgentUI} from "@/components/AgentUI";
22

33
export default function Home() {
4-
return (
5-
<main className="h-dvh">
6-
<AgentUI />
7-
</main>
8-
);
4+
return (
5+
<main className="h-dvh">
6+
<AgentUI/>
7+
</main>
8+
);
99
}
Lines changed: 52 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,69 @@
11
"use client";
22

3-
import type { ReactNode } from "react";
4-
import {
5-
AssistantRuntimeProvider,
6-
useLocalRuntime,
7-
type ChatModelAdapter,
8-
} from "@assistant-ui/react";
3+
import type {ReactNode} from "react";
4+
import {AssistantRuntimeProvider, type ChatModelAdapter, useLocalRuntime,} from "@assistant-ui/react";
95
import {EventSourceParserStream} from 'eventsource-parser/stream'
106

117
const AgentModelAdapter: ChatModelAdapter = {
12-
async *run({ messages, abortSignal }) {
13-
const response = await fetch("/chat", {
14-
method: "POST",
15-
headers: {
16-
"Content-Type": "application/json",
17-
},
18-
body: JSON.stringify({
19-
messages,
20-
}),
21-
signal: abortSignal,
22-
});
8+
async* run({messages, abortSignal}) {
9+
const response = await fetch("/chat", {
10+
method: "POST",
11+
headers: {
12+
"Content-Type": "application/json",
13+
},
14+
body: JSON.stringify({
15+
messages,
16+
}),
17+
signal: abortSignal,
18+
});
2319

24-
if (!response.ok) {
25-
const error = await response.text();
26-
throw new Error(`Failed (${response.status}): ${error}`);
27-
}
20+
if (!response.ok) {
21+
const error = await response.text();
22+
throw new Error(`Failed (${response.status}): ${error}`);
23+
}
2824

29-
if (!response.body) {
30-
throw new Error(`No response`);
31-
}
25+
if (!response.body) {
26+
throw new Error(`No response`);
27+
}
3228

33-
const eventStream = response.body
34-
.pipeThrough(new TextDecoderStream())
35-
.pipeThrough(new EventSourceParserStream())
36-
.getReader();
29+
const eventStream = response.body
30+
.pipeThrough(new TextDecoderStream())
31+
.pipeThrough(new EventSourceParserStream())
32+
.getReader();
3733

38-
let text = "";
34+
let text = "";
3935

40-
for (;;) {
41-
const {done, value} = await eventStream.read();
42-
if (!done) {
43-
if (!value.data) {
44-
continue;
45-
}
46-
const { content } = JSON.parse(value.data);
47-
if (!content || content.length == 0 || content[0].type !== "text" || !content[0].text) {
48-
continue;
36+
for (; ;) {
37+
const {done, value} = await eventStream.read();
38+
if (!done) {
39+
if (!value.data) {
40+
continue;
41+
}
42+
const {content} = JSON.parse(value.data);
43+
if (!content || content.length == 0 || content[0].type !== "text" || !content[0].text) {
44+
continue;
45+
}
46+
text += content[0].text;
47+
yield {
48+
content: [{type: "text", text}],
49+
};
50+
} else {
51+
break;
52+
}
4953
}
50-
text += content[0].text;
51-
yield {
52-
content: [{ type: "text", text }],
53-
};
54-
} else {
55-
break;
56-
}
57-
}
58-
},
54+
},
5955
};
6056

6157
export function AgentRuntimeProvider({
62-
children,
63-
}: Readonly<{
64-
children: ReactNode;
58+
children,
59+
}: Readonly<{
60+
children: ReactNode;
6561
}>) {
66-
const runtime = useLocalRuntime(AgentModelAdapter);
62+
const runtime = useLocalRuntime(AgentModelAdapter);
6763

68-
return (
69-
<AssistantRuntimeProvider runtime={runtime}>
70-
{children}
71-
</AssistantRuntimeProvider>
72-
);
64+
return (
65+
<AssistantRuntimeProvider runtime={runtime}>
66+
{children}
67+
</AssistantRuntimeProvider>
68+
);
7369
}
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
"use client";
22

3-
import { AgentRuntimeProvider } from "@/components/AgentRuntimeProvider";
4-
import { ThreadList } from "@/components/assistant-ui/thread-list";
5-
import { Thread } from "@/components/assistant-ui/thread";
3+
import {AgentRuntimeProvider} from "@/components/AgentRuntimeProvider";
4+
import {ThreadList} from "@/components/assistant-ui/thread-list";
5+
import {Thread} from "@/components/assistant-ui/thread";
66

77
export function AgentUI() {
8-
return (
9-
<AgentRuntimeProvider>
10-
<main className="grid h-dvh grid-cols-[200px_1fr] gap-x-2 px-4 py-4">
11-
<ThreadList />
12-
<Thread />
13-
</main>
14-
</AgentRuntimeProvider>
15-
);
8+
return (
9+
<AgentRuntimeProvider>
10+
<main className="grid h-dvh grid-cols-[200px_1fr] gap-x-2 px-4 py-4">
11+
<ThreadList/>
12+
<Thread/>
13+
</main>
14+
</AgentRuntimeProvider>
15+
);
1616
}

0 commit comments

Comments
 (0)