From 0639d0d9eaf7d953b0365b4795f2b4d2959edcb8 Mon Sep 17 00:00:00 2001 From: Yash094 <67926590+Yash094@users.noreply.github.com> Date: Fri, 30 May 2025 07:58:58 +0000 Subject: [PATCH] siwa updates and new article (#7197) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ## PR-Codex overview This PR focuses on enhancing the chat functionality within the application by adding a feedback system, updating icons, and improving the knowledge base content related to ERC20 token transfers. ### Detailed summary - Added a new knowledge base entry for "Transfer Amount Exceeds Allowance". - Updated `Header` and `Hero` components to replace `BotIcon` with `MessageCircleIcon`. - Introduced `sendFeedback` function to handle user feedback on chat messages. - Modified `Chat` component to include feedback buttons (thumbs up/down) for messages. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` ## Summary by CodeRabbit - **New Features** - Introduced feedback buttons (thumbs up/down) for assistant messages in the AI chat, allowing users to rate responses. - Added a new "Ask AI" button on the main page, providing quick access to the chat assistant. - Added a new knowledge base article explaining the "ERC20: transfer amount exceeds allowance" error and its resolution. - **Improvements** - Enhanced chat message payloads with source identifiers for better context. - Updated sidebar navigation with a new troubleshooting entry for ERC20 transfer allowance issues. - Updated chat and header icons to use a consistent message circle icon for AI-related features. --- .../CustomChat/CustomChatContent.tsx | 1 + apps/portal/src/app/Header.tsx | 7 +-- .../portal/src/app/knowledge-base/sidebar.tsx | 4 ++ .../erc20-transfer-allowance/page.mdx | 15 +++++ apps/portal/src/app/page.tsx | 9 +++ apps/portal/src/components/AI/api.ts | 29 +++++++++ apps/portal/src/components/AI/chat.tsx | 59 +++++++++++++++--- apps/portal/src/icons/siwa-icon.png | Bin 0 -> 1326 bytes 8 files changed, 112 insertions(+), 12 deletions(-) create mode 100644 apps/portal/src/app/knowledge-base/troubleshoot/contracts/erc20-transfer-allowance/page.mdx create mode 100644 apps/portal/src/icons/siwa-icon.png diff --git a/apps/dashboard/src/app/nebula-app/(app)/components/CustomChat/CustomChatContent.tsx b/apps/dashboard/src/app/nebula-app/(app)/components/CustomChat/CustomChatContent.tsx index 2547afc0db0..8fab0e3fd72 100644 --- a/apps/dashboard/src/app/nebula-app/(app)/components/CustomChat/CustomChatContent.tsx +++ b/apps/dashboard/src/app/nebula-app/(app)/components/CustomChat/CustomChatContent.tsx @@ -102,6 +102,7 @@ function CustomChatContentLoggedIn(props: { message: messageToSend.content.find((x) => x.type === "text")?.text ?? "", conversationId: sessionId, + source: "dashboard-support", }; const apiUrl = process.env.NEXT_PUBLIC_SIWA_URL; const response = await fetch(`${apiUrl}/v1/chat`, { diff --git a/apps/portal/src/app/Header.tsx b/apps/portal/src/app/Header.tsx index 35f4b5f11ac..f4a2b0bf5d3 100644 --- a/apps/portal/src/app/Header.tsx +++ b/apps/portal/src/app/Header.tsx @@ -10,9 +10,9 @@ import { } from "@/components/ui/dropdown-menu"; import clsx from "clsx"; import { - BotIcon, ChevronDownIcon, MenuIcon, + MessageCircleIcon, TableOfContentsIcon, } from "lucide-react"; import Link from "next/link"; @@ -222,12 +222,11 @@ export function Header() {
@@ -254,7 +253,7 @@ export function Header() { className="p-2" onClick={() => router.push("/chat")} > - + + diff --git a/apps/portal/src/components/AI/api.ts b/apps/portal/src/components/AI/api.ts index 247063ffdc0..4024d693967 100644 --- a/apps/portal/src/components/AI/api.ts +++ b/apps/portal/src/components/AI/api.ts @@ -11,6 +11,7 @@ export const getChatResponse = async ( const payload = { message: userMessage, conversationId: sessionId, + source: "portal", }; const response = await fetch(`${apiUrl}/v1/chat`, { method: "POST", @@ -41,3 +42,31 @@ export const getChatResponse = async ( return null; } }; + +export const sendFeedback = async ( + conversationId: string, + feedbackRating: 1 | -1, +) => { + try { + const response = await fetch(`${apiUrl}/v1/chat/feedback`, { + method: "POST", + headers: { + "Content-Type": "application/json", + "x-service-api-key": serviceKey, + }, + body: JSON.stringify({ conversationId, feedbackRating }), + }); + + if (!response.ok) { + const error = await response.text(); + throw new Error(`Failed to send feedback: ${response.status} - ${error}`); + } + return true; + } catch (error) { + console.error( + "Feedback API error:", + error instanceof Error ? error.message : "Unknown error", + ); + return false; + } +}; diff --git a/apps/portal/src/components/AI/chat.tsx b/apps/portal/src/components/AI/chat.tsx index a72d8521b7a..a3c6aabdc90 100644 --- a/apps/portal/src/components/AI/chat.tsx +++ b/apps/portal/src/components/AI/chat.tsx @@ -5,7 +5,8 @@ import { LoadingDots } from "@/components/ui/LoadingDots"; import { Button } from "@/components/ui/button"; import { AutoResizeTextarea } from "@/components/ui/textarea"; import { cn } from "@/lib/utils"; -import { ArrowUpIcon, BotIcon } from "lucide-react"; +import { MessageCircleIcon } from "lucide-react"; +import { ArrowUpIcon, ThumbsDownIcon, ThumbsUpIcon } from "lucide-react"; import { usePostHog } from "posthog-js/react"; import { type ChangeEvent, @@ -15,13 +16,14 @@ import { useRef, useState, } from "react"; -import { getChatResponse } from "./api"; +import { getChatResponse, sendFeedback } from "./api"; interface Message { id: string; role: "user" | "assistant"; content: string; isLoading?: boolean; + feedback?: 1 | -1; } const predefinedPrompts = [ @@ -36,7 +38,7 @@ function ChatEmptyState({ }: { onPromptClick: (prompt: string) => void }) { return (
- +

How can I help you
@@ -153,6 +155,21 @@ export function Chat() { } }; + const handleFeedback = async (messageId: string, feedback: 1 | -1) => { + if (!conversationId) return; // Don't send feedback if no conversation + + try { + await sendFeedback(conversationId, feedback); + setMessages((prevMessages) => + prevMessages.map((msg) => + msg.id === messageId ? { ...msg, feedback } : msg, + ), + ); + } catch (_e) { + // Optionally handle error + } + }; + return (
) : ( - + <> + + {message.role === "assistant" && !message.isLoading && ( +
+ {!message.feedback && ( + <> + + + + )} +
+ )} + )}

diff --git a/apps/portal/src/icons/siwa-icon.png b/apps/portal/src/icons/siwa-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..60b8027bd422e12cd5538fbdcd544d89e00eba25 GIT binary patch literal 1326 zcmV+}1=0G6P)aQbCjoL|2eY1-TBaRG@POk}IH6fszU+S0K3p(iKRq;5F6&eP`+j z?2;hJ^YEG3;mwf*$tAE~0Et#sR#sM4el*S~BLFV!hUMJK@BVMo*)|8K@b6Dnp7{6K z+1V4#z+_6Y3SmVQRxbV4kW^)}1OK*)d!bW;6=UVfN`-t>R<>3QEg5@*1@bDU zk9#W{S`u(?@DaHc;vy~Ew3@f+c+q%QBo?K%p1MhE4qnKN`UNL(0#F{__r7PGL@$m47t>t(hf7Txe;GPOkU!ZiPexgozY|rMuArmB zh_uC?w?R1a&(f=;H_Nt1>aqB^Xy6GqWLfb>aDC(3tcCYbB4@||=h9Ov=NjKDy@nud zI8c@ZZqv}zKyI9GA$W6ML7}W&G*rB@B*Uq#I1jjUieQbM5=)3S_nK;~3`X%KC z@tCNFvXBK?oV8Q7`4;i;B>iyn7e9y4hCtY>5Vv);vaJen#BB}&ahH8~BU@pcyFeQk zg7ew7m5}iWWJ-YH;vfk%~EtME@rINo%Pec1+|L24Me7XLJa6tQz6P5X9e>u$tiJalLDEP)s|xnoifm^Mv+n>^TLduX<8Z@PeX3SE!V{V zn_~ucY9;mYVC5a{3;vvtZhDR#yh07GLh&bkzdV|~>HlM<&69%u{H*F6caHuz=vh0o zAWL*>EMZlQR7w8WtH1-@D6XlU1FSHo@z*HHA0JAf3&HiI#k?*x0=-pIbj!&+XNmYy2KdHHud%l^w-3mDK|rv(tK*QUCmpn>nWfRPqd7>eB;O_ni>cR!KZdTkXv2LBKMV2)r77q!|5{NE{iMJJ zZAp7lr~O!(5n?%CS>br(yrG16W!*zI3@a#W