Skip to content

Commit fa6c9cf

Browse files
committed
Assistant-cloud integration
1 parent 776d851 commit fa6c9cf

File tree

5 files changed

+54
-11
lines changed

5 files changed

+54
-11
lines changed

course-matrix/frontend/package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

course-matrix/frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"dependencies": {
1313
"@ai-sdk/openai": "^1.1.13",
14-
"@assistant-ui/react": "^0.7.86",
14+
"@assistant-ui/react": "^0.7.91",
1515
"@assistant-ui/react-ai-sdk": "^0.7.16",
1616
"@assistant-ui/react-markdown": "^0.7.20",
1717
"@assistant-ui/react-ui": "^0.1.7",

course-matrix/frontend/src/components/assistant-ui/thread-list.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const ThreadListItem: FC = () => {
4848

4949
const ThreadListItemTitle: FC = () => {
5050
return (
51-
<p className="text-sm">
51+
<p className="text-sm overflow-hidden text-ellipsis whitespace-nowrap">
5252
<ThreadListItemPrimitive.Title fallback="New Chat" />
5353
</p>
5454
);

course-matrix/frontend/src/pages/Assistant/assistant.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,16 @@ import { useChatRuntime } from "@assistant-ui/react-ai-sdk";
33
import { Thread } from "@/components/assistant-ui/thread";
44
import { ThreadList } from "@/components/assistant-ui/thread-list";
55
import { SERVER_URL } from "@/api/config";
6+
import { RuntimeProvider } from "./runtime-provider";
67

78
export const Assistant = () => {
8-
const runtime = useChatRuntime({
9-
api: `${SERVER_URL}/api/ai/chat`,
10-
});
119

1210
return (
13-
<AssistantRuntimeProvider runtime={runtime}>
11+
<RuntimeProvider>
1412
<div className="grid h-dvh grid-cols-[200px_1fr] gap-x-2 px-4 py-4">
1513
<ThreadList />
1614
<Thread />
1715
</div>
18-
</AssistantRuntimeProvider>
16+
</RuntimeProvider>
1917
);
2018
};
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { SERVER_URL } from "@/api/config";
2+
import { AssistantCloud, AssistantRuntimeProvider } from "@assistant-ui/react";
3+
import { useChatRuntime } from "@assistant-ui/react-ai-sdk";
4+
5+
const PUBLIC_ASSISTANT_BASE_URL = import.meta.env.VITE_PUBLIC_ASSISTANT_BASE_URL;
6+
const ASSISTANT_UI_KEY = import.meta.env.VITE_ASSISTANT_UI_KEY;
7+
8+
const user = JSON.parse(localStorage.getItem("userInfo") ?? "{}")
9+
const userId = (user?.user?.id);
10+
11+
const getAuthToken = async () => {
12+
const client = new AssistantCloud({
13+
apiKey: ASSISTANT_UI_KEY!,
14+
userId,
15+
workspaceId: userId,
16+
});
17+
const { token } = await client.auth.tokens.create();
18+
return token
19+
}
20+
21+
const cloud = new AssistantCloud({
22+
baseUrl: PUBLIC_ASSISTANT_BASE_URL!,
23+
// authToken: () =>
24+
// fetch("/api/assistant-ui-token", { method: "POST" })
25+
// .then((r) => r.json())
26+
// .then((r) => r.token),
27+
authToken: () => getAuthToken()
28+
});
29+
30+
export function RuntimeProvider({
31+
children,
32+
}: Readonly<{
33+
children: React.ReactNode;
34+
}>) {
35+
const runtime = useChatRuntime({
36+
cloud,
37+
api: `${SERVER_URL}/api/ai/chat`,
38+
});
39+
40+
return (
41+
<AssistantRuntimeProvider runtime={runtime}>
42+
{children}
43+
</AssistantRuntimeProvider>
44+
);
45+
}

0 commit comments

Comments
 (0)