Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions apps/dashboard/src/app/nebula-app/(app)/api/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,29 @@ export async function promptNebula(params: {
});
break;
}

case "context": {
const data = JSON.parse(event.data) as {
data: string;
request_id: string;
session_id: string;
};

const contextData = JSON.parse(data.data) as {
wallet_address: string;
chain_ids: number[];
};

params.handleStream({
event: "context",
data: contextData,
});
break;
}

default: {
console.warn("unhandled event", event);
}
}
}
}
Expand Down Expand Up @@ -136,6 +159,13 @@ type ChatStreamedResponse =
event: "action";
type: "sign_transaction" & (string & {});
data: NebulaTxData;
}
| {
event: "context";
data: {
wallet_address: string;
chain_ids: number[];
};
};

type ChatStreamedEvent =
Expand All @@ -155,4 +185,8 @@ type ChatStreamedEvent =
event: "action";
type: "sign_transaction" & (string & {});
data: string;
}
| {
event: "context";
data: string;
};
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ export function ChatPageContent(props: {
authToken: props.authToken,
setMessages,
contextFilters: contextFilters,
setContextFilters,
});
} catch (error) {
if (abortController.signal.aborted) {
Expand All @@ -266,7 +267,14 @@ export function ChatPageContent(props: {
setEnableAutoScroll(false);
}
},
[sessionId, contextFilters, props.authToken, messages.length, initSession],
[
sessionId,
contextFilters,
props.authToken,
messages.length,
initSession,
setContextFilters,
],
);

const hasDoneAutoPrompt = useRef(false);
Expand Down Expand Up @@ -450,6 +458,7 @@ export async function handleNebulaPrompt(params: {
authToken: string;
setMessages: React.Dispatch<React.SetStateAction<ChatMessage[]>>;
contextFilters: NebulaContext | undefined;
setContextFilters: (v: NebulaContext | undefined) => void;
}) {
const {
abortController,
Expand All @@ -458,6 +467,7 @@ export async function handleNebulaPrompt(params: {
authToken,
setMessages,
contextFilters,
setContextFilters,
} = params;
let requestIdForMessage = "";

Expand Down Expand Up @@ -548,6 +558,13 @@ export async function handleNebulaPrompt(params: {
});
}
}

if (res.event === "context") {
setContextFilters({
chainIds: res.data.chain_ids.map((x) => x.toString()),
walletAddress: res.data.wallet_address,
});
}
},
context: contextFilters,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export function ChatSidebar(props: {
</div>

<div className="[&>*]:!w-full p-4">
<NebulaConnectWallet />
<NebulaConnectWallet detailsButtonClassName="!bg-background hover:!border-active-border" />
</div>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ArrowRightIcon, ArrowUpRightIcon } from "lucide-react";
import Link from "next/link";
import { usePathname } from "next/navigation";
import { useCallback, useMemo, useState } from "react";
import { useCallback, useState } from "react";
import type { ThirdwebClient } from "thirdweb";
import { Button } from "../../../../../@/components/ui/button";
import type { NebulaContext } from "../../api/chat";
Expand Down Expand Up @@ -63,14 +63,16 @@ function FloatingChatContentLoggedIn(props: {
const [isChatStreaming, setIsChatStreaming] = useState(false);
const [enableAutoScroll, setEnableAutoScroll] = useState(false);

const contextFilters: NebulaContext = useMemo(() => {
const [contextFilters, setContextFilters] = useState<
NebulaContext | undefined
>(() => {
return {
chainIds:
props.nebulaParams?.chainIds.map((chainId) => chainId.toString()) ||
null,
walletAddress: props.nebulaParams?.wallet || null,
};
}, [props.nebulaParams]);
});

const initSession = useCallback(async () => {
const session = await createSession({
Expand Down Expand Up @@ -120,6 +122,7 @@ function FloatingChatContentLoggedIn(props: {
authToken: props.authToken,
setMessages,
contextFilters: contextFilters,
setContextFilters: setContextFilters,
});
} catch (error) {
if (abortController.signal.aborted) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,10 @@ export const MarkdownRenderer: React.FC<{
),

code: ({ ...props }) => {
if (props?.className) {
if (code?.disableCodeHighlight) {
const codeStr = onlyText(props.children);

if (props?.className || codeStr.length > 100) {
if (code?.disableCodeHighlight || !props.className) {
return (
<div className="my-4">
{/* @ts-expect-error - TODO: fix this */}
Expand Down
Loading