Skip to content

Commit 135e014

Browse files
mvp
1 parent 204d08f commit 135e014

File tree

14 files changed

+602
-147
lines changed

14 files changed

+602
-147
lines changed

apps/playground-web/src/app/ai/api/chat.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import { stream } from "fetch-event-stream";
22
import type { NebulaTxData, NebulaUserMessage } from "./types";
33

4-
// Mock URL for playground - you'll need to configure this
5-
const NEBULA_URL = process.env.NEXT_PUBLIC_NEBULA_URL || "https://nebula-api.thirdweb-dev.com";
4+
const API_URL = `https://${process.env.NEXT_PUBLIC_API_URL || "api.thirdweb.com"}`;
65

76
export type NebulaContext = {
87
chainIds: string[] | null;
98
walletAddress: string | null;
10-
networks: "mainnet" | "testnet" | "all" | null;
9+
sessionId: string | null;
1110
};
1211

1312
export type NebulaSwapData = {
@@ -44,30 +43,31 @@ export type NebulaSwapData = {
4443

4544
export async function promptNebula(params: {
4645
message: NebulaUserMessage;
47-
sessionId: string;
4846
authToken: string;
4947
handleStream: (res: ChatStreamedResponse) => void;
5048
abortController: AbortController;
5149
context: undefined | NebulaContext;
5250
}) {
5351
const body: Record<string, string | boolean | object> = {
5452
messages: [params.message],
55-
session_id: params.sessionId,
5653
stream: true,
5754
};
5855

5956
if (params.context) {
6057
body.context = {
61-
chain_ids: params.context.chainIds || [],
62-
networks: params.context.networks,
58+
chain_ids: params.context.chainIds?.map(Number) || [],
59+
session_id: params.context.sessionId ?? undefined,
6360
wallet_address: params.context.walletAddress,
6461
};
6562
}
6663

67-
const events = await stream(`${NEBULA_URL}/chat`, {
64+
const events = await stream(`${API_URL}/ai/chat`, {
6865
body: JSON.stringify(body),
6966
headers: {
70-
Authorization: `Bearer ${params.authToken}`,
67+
"x-client-id": process.env.NEXT_PUBLIC_THIRDWEB_CLIENT_ID!,
68+
// FIXME REMOVE
69+
"x-secret-key":
70+
"7NFrTzBN9Y2Eca6Rl60uxT3Dwew4D9YaYHjoD_3Y2GDvkaejLFiodFDcuzGJqu0mc8PVCAi9M4Y3j6Ql_ZVRyQ",
7171
"Content-Type": "application/json",
7272
},
7373
method: "POST",
@@ -192,7 +192,7 @@ export async function promptNebula(params: {
192192
const contextData = JSON.parse(data.data) as {
193193
wallet_address: string;
194194
chain_ids: number[];
195-
networks: NebulaContext["networks"];
195+
session_id: string;
196196
};
197197

198198
params.handleStream({
@@ -262,7 +262,7 @@ type ChatStreamedResponse =
262262
data: {
263263
wallet_address: string;
264264
chain_ids: number[];
265-
networks: NebulaContext["networks"];
265+
session_id: string;
266266
};
267267
}
268268
| {
@@ -306,4 +306,4 @@ type ChatStreamedEvent =
306306
| {
307307
event: "ping";
308308
data: string;
309-
};
309+
};

apps/playground-web/src/app/ai/api/fetchWithAuthToken.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ export async function fetchWithAuthToken(options: FetchWithKeyOptions) {
4747
} finally {
4848
clearTimeout(timeoutId);
4949
}
50-
}
50+
}

apps/playground-web/src/app/ai/api/session.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import type {
77
UpdatedSessionInfo,
88
} from "./types";
99

10-
const NEBULA_URL = process.env.NEXT_PUBLIC_NEBULA_URL || "https://nebula-api.thirdweb-dev.com";
10+
const NEBULA_URL =
11+
process.env.NEXT_PUBLIC_NEBULA_URL || "https://nebula-api.thirdweb-dev.com";
1112

1213
export async function createSession(params: {
1314
authToken: string;
@@ -117,4 +118,4 @@ export async function getSessionById(params: {
117118
const data = await res.json();
118119

119120
return data.result as SessionInfo;
120-
}
121+
}

apps/playground-web/src/app/ai/api/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,4 @@ export type NebulaTxData = {
7777
data: `0x${string}`;
7878
to: string;
7979
value?: string;
80-
};
80+
};
Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,29 @@
1-
import { createThirdwebClient } from "thirdweb";
1+
import ThirdwebProvider from "../../../components/thirdweb-provider";
2+
import { THIRDWEB_CLIENT } from "../../../lib/client";
23
import { ChatPageContent } from "../components/ChatPageContent";
34

4-
// Mock client for playground - you'll need to configure this with your actual client ID
5-
const client = createThirdwebClient({
6-
clientId: process.env.NEXT_PUBLIC_THIRDWEB_CLIENT_ID || "your-client-id-here",
7-
});
8-
95
export default function ChatPage() {
106
// Mock auth data - in a real app, you'd get this from your auth system
117
const mockAuthToken = "mock-auth-token";
128
const mockAccountAddress = "0x1234567890123456789012345678901234567890";
139

1410
return (
1511
<div className="min-h-screen">
16-
<ChatPageContent
17-
accountAddress={mockAccountAddress}
18-
authToken={mockAuthToken}
19-
client={client}
20-
initialParams={undefined}
21-
session={undefined}
22-
type="new-chat"
23-
/>
12+
<ThirdwebProvider>
13+
<ChatPageContent
14+
accountAddress={mockAccountAddress}
15+
authToken={mockAuthToken}
16+
client={THIRDWEB_CLIENT}
17+
initialParams={undefined}
18+
session={undefined}
19+
type="new-chat"
20+
/>
21+
</ThirdwebProvider>
2422
</div>
2523
);
2624
}
2725

2826
export const metadata = {
29-
title: "AI Chat - Playground",
30-
description: "Chat with Nebula AI for blockchain interactions",
31-
};
27+
title: "AI Chat API - Playground",
28+
description: "Chat with thirdweb AI for blockchain interactions",
29+
};

0 commit comments

Comments
 (0)