Skip to content

Commit d0bf3f3

Browse files
committed
[NEB-179] Nebula: Update context UI when context event type is received (#6770)
<!-- ## title your PR with this format: "[SDK/Dashboard/Portal] Feature/Fix: Concise title for the changes" If you did not copy the branch name from Linear, paste the issue tag here (format is TEAM-0000): ## Notes for the reviewer Anything important to call out? Be sure to also clarify these in your comments. ## How to test Unit tests, playground, etc. --> <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on enhancing the `ChatSidebar`, `ChatPageContent`, and `FloatingChatContent` components by adding new properties and functionality related to context management and event handling within the chat application. ### Detailed summary - Updated `<NebulaConnectWallet />` to accept `detailsButtonClassName` prop. - Improved `code` component to handle class names and text length conditions. - Added new event handling for "context" in the chat API. - Extended `ChatStreamedResponse` and `ChatStreamedEvent` types to include "context" data. - Integrated `setContextFilters` functionality in `ChatPageContent` and `FloatingChatContent` components. - Refactored `contextFilters` state management in `FloatingChatContent`. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent 96689c6 commit d0bf3f3

File tree

5 files changed

+63
-7
lines changed

5 files changed

+63
-7
lines changed

apps/dashboard/src/app/nebula-app/(app)/api/chat.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,29 @@ export async function promptNebula(params: {
105105
});
106106
break;
107107
}
108+
109+
case "context": {
110+
const data = JSON.parse(event.data) as {
111+
data: string;
112+
request_id: string;
113+
session_id: string;
114+
};
115+
116+
const contextData = JSON.parse(data.data) as {
117+
wallet_address: string;
118+
chain_ids: number[];
119+
};
120+
121+
params.handleStream({
122+
event: "context",
123+
data: contextData,
124+
});
125+
break;
126+
}
127+
128+
default: {
129+
console.warn("unhandled event", event);
130+
}
108131
}
109132
}
110133
}
@@ -136,6 +159,13 @@ type ChatStreamedResponse =
136159
event: "action";
137160
type: "sign_transaction" & (string & {});
138161
data: NebulaTxData;
162+
}
163+
| {
164+
event: "context";
165+
data: {
166+
wallet_address: string;
167+
chain_ids: number[];
168+
};
139169
};
140170

141171
type ChatStreamedEvent =
@@ -155,4 +185,8 @@ type ChatStreamedEvent =
155185
event: "action";
156186
type: "sign_transaction" & (string & {});
157187
data: string;
188+
}
189+
| {
190+
event: "context";
191+
data: string;
158192
};

apps/dashboard/src/app/nebula-app/(app)/components/ChatPageContent.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ export function ChatPageContent(props: {
251251
authToken: props.authToken,
252252
setMessages,
253253
contextFilters: contextFilters,
254+
setContextFilters,
254255
});
255256
} catch (error) {
256257
if (abortController.signal.aborted) {
@@ -266,7 +267,14 @@ export function ChatPageContent(props: {
266267
setEnableAutoScroll(false);
267268
}
268269
},
269-
[sessionId, contextFilters, props.authToken, messages.length, initSession],
270+
[
271+
sessionId,
272+
contextFilters,
273+
props.authToken,
274+
messages.length,
275+
initSession,
276+
setContextFilters,
277+
],
270278
);
271279

272280
const hasDoneAutoPrompt = useRef(false);
@@ -450,6 +458,7 @@ export async function handleNebulaPrompt(params: {
450458
authToken: string;
451459
setMessages: React.Dispatch<React.SetStateAction<ChatMessage[]>>;
452460
contextFilters: NebulaContext | undefined;
461+
setContextFilters: (v: NebulaContext | undefined) => void;
453462
}) {
454463
const {
455464
abortController,
@@ -458,6 +467,7 @@ export async function handleNebulaPrompt(params: {
458467
authToken,
459468
setMessages,
460469
contextFilters,
470+
setContextFilters,
461471
} = params;
462472
let requestIdForMessage = "";
463473

@@ -548,6 +558,13 @@ export async function handleNebulaPrompt(params: {
548558
});
549559
}
550560
}
561+
562+
if (res.event === "context") {
563+
setContextFilters({
564+
chainIds: res.data.chain_ids.map((x) => x.toString()),
565+
walletAddress: res.data.wallet_address,
566+
});
567+
}
551568
},
552569
context: contextFilters,
553570
});

apps/dashboard/src/app/nebula-app/(app)/components/ChatSidebar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export function ChatSidebar(props: {
123123
</div>
124124

125125
<div className="[&>*]:!w-full p-4">
126-
<NebulaConnectWallet />
126+
<NebulaConnectWallet detailsButtonClassName="!bg-background hover:!border-active-border" />
127127
</div>
128128
</div>
129129
);

apps/dashboard/src/app/nebula-app/(app)/components/FloatingChat/FloatingChatContent.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ArrowRightIcon, ArrowUpRightIcon } from "lucide-react";
22
import Link from "next/link";
33
import { usePathname } from "next/navigation";
4-
import { useCallback, useMemo, useState } from "react";
4+
import { useCallback, useState } from "react";
55
import type { ThirdwebClient } from "thirdweb";
66
import { Button } from "../../../../../@/components/ui/button";
77
import type { NebulaContext } from "../../api/chat";
@@ -63,14 +63,16 @@ function FloatingChatContentLoggedIn(props: {
6363
const [isChatStreaming, setIsChatStreaming] = useState(false);
6464
const [enableAutoScroll, setEnableAutoScroll] = useState(false);
6565

66-
const contextFilters: NebulaContext = useMemo(() => {
66+
const [contextFilters, setContextFilters] = useState<
67+
NebulaContext | undefined
68+
>(() => {
6769
return {
6870
chainIds:
6971
props.nebulaParams?.chainIds.map((chainId) => chainId.toString()) ||
7072
null,
7173
walletAddress: props.nebulaParams?.wallet || null,
7274
};
73-
}, [props.nebulaParams]);
75+
});
7476

7577
const initSession = useCallback(async () => {
7678
const session = await createSession({
@@ -120,6 +122,7 @@ function FloatingChatContentLoggedIn(props: {
120122
authToken: props.authToken,
121123
setMessages,
122124
contextFilters: contextFilters,
125+
setContextFilters: setContextFilters,
123126
});
124127
} catch (error) {
125128
if (abortController.signal.aborted) {

apps/dashboard/src/components/contract-components/published-contract/markdown-renderer.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,10 @@ export const MarkdownRenderer: React.FC<{
106106
),
107107

108108
code: ({ ...props }) => {
109-
if (props?.className) {
110-
if (code?.disableCodeHighlight) {
109+
const codeStr = onlyText(props.children);
110+
111+
if (props?.className || codeStr.length > 100) {
112+
if (code?.disableCodeHighlight || !props.className) {
111113
return (
112114
<div className="my-4">
113115
{/* @ts-expect-error - TODO: fix this */}

0 commit comments

Comments
 (0)