diff --git a/src/api/axios.ts b/src/api/axios.ts
index 5bb7162..0e6a733 100644
--- a/src/api/axios.ts
+++ b/src/api/axios.ts
@@ -8,6 +8,7 @@ const api = axios.create({
api.interceptors.request.use((config) => {
const token = localStorage.getItem("token");
+ console.log("Attaching token to request:", token);
config.headers = config.headers || {};
diff --git a/src/components/ChartArtifact.tsx b/src/components/ChartArtifact.tsx
index 01b7832..857c97f 100644
--- a/src/components/ChartArtifact.tsx
+++ b/src/components/ChartArtifact.tsx
@@ -28,7 +28,10 @@ import {
FileText,
ImageIcon,
RefreshCcw,
- Sparkles,
+ Sparkles,
+ CheckCircle2,
+ BarChart3,
+ Database,
} from "lucide-react";
import ErrorBoundary from "@/components/ErrorBoundary";
@@ -785,40 +788,55 @@ function VegaLiteArtifact({
{/* TOP TABS */}
-
-
setActiveTab("answer")}
- className={`rounded-xl px-4 py-2 text-sm font-medium transition ${activeTab === "answer"
- ? "bg-cyan-500 text-white"
- : "bg-white/10 text-slate-300 hover:bg-white/20"
- }`}
- >
- Answer
-
+
+ setActiveTab("answer")}
+ className={`flex items-center gap-2 rounded-xl px-4 py-2 text-sm font-medium transition ${
+ activeTab === "answer"
+ ? "bg-cyan-500 text-white"
+ : "bg-white border border-slate-200 text-black hover:bg-slate-50"
+ }`}
+ >
+
+ Answer
+
- setActiveTab("chart")}
- className={`rounded-xl px-4 py-2 text-sm font-medium transition ${activeTab === "chart"
- ? "bg-cyan-500 text-white"
- : "bg-white/10 text-slate-300 hover:bg-white/20"
- }`}
- >
- Chart
-
+ setActiveTab("chart")}
+ className={`flex items-center gap-2 rounded-xl px-4 py-2 text-sm font-medium transition ${
+ activeTab === "chart"
+ ? "bg-cyan-500 text-white"
+ : "bg-white border border-slate-200 text-black hover:bg-slate-50"
+ }`}
+ >
+
+ Chart
+
- setActiveTab("sql")}
- className={`rounded-xl px-4 py-2 text-sm font-medium transition ${activeTab === "sql"
- ? "bg-cyan-500 text-white"
- : "bg-white/10 text-slate-300 hover:bg-white/20"
- }`}
- >
- SQL
-
-
+
setActiveTab("sql")}
+ className={`flex items-center gap-2 rounded-xl px-4 py-2 text-sm font-medium transition ${
+ activeTab === "sql"
+ ? "bg-cyan-500 text-white"
+ : "bg-white border border-slate-200 text-black hover:bg-slate-50"
+ }`}
+ >
+
+ SQL
+
+
{/* EXPORT BUTTONS */}
-
*/}
diff --git a/src/components/ChatCanvas.tsx b/src/components/ChatCanvas.tsx
index 1b08742..0272776 100644
--- a/src/components/ChatCanvas.tsx
+++ b/src/components/ChatCanvas.tsx
@@ -13,6 +13,7 @@ type ChatMessage = {
role: "user" | "assistant";
content: unknown;
error?: boolean;
+ clarification?: boolean;
};
function createId() {
@@ -34,11 +35,11 @@ function createMessage(role: ChatMessage["role"], content: unknown): ChatMessage
export default function ChatCanvas() {
const [input, setInput] = useState("");
const [messages, setMessages] = useState([]);
- // const [selectedHistoryId, setSelectedHistoryId] = useState(null);
const [error, setError] = useState("");
const [isSending, setIsSending] = useState(false);
const [showHistory, setShowHistory] = useState(true);
const [historyQuestions, setHistoryQuestions] = useState([]);
+ const [showProfileMenu, setShowProfileMenu] = useState(false);
const bottomRef = useRef(null);
@@ -52,28 +53,101 @@ export default function ChatCanvas() {
loadHistory();
}, []);
+
+
+
+ // const loadHistory = async () => {
+ // try {
+ // const token = localStorage.getItem("token");
+
+ // const res = await api.get("/fetchUserHistory", {
+ // headers: {
+ // Authorization: `Bearer ${token}`,
+ // },
+ // });
+
+ // console.log("History Response =>", res.data);
+
+ // if (res.data.success) {
+ // setHistoryQuestions(res.data.data);
+ // }
+ // } catch (err) {
+ // console.error("History Error =>", err);
+ // }
+ // };
+
const loadHistory = async () => {
try {
- const res = await api.get("/suggestions");
+ const res = await api.get("/fetchUserHistory");
+
+ console.log("History Response =>", res.data);
if (res.data.success) {
- setHistoryQuestions(res.data.questions);
+ setHistoryQuestions(res.data.data);
}
} catch (err) {
- console.error(err);
+ console.error("History Error =>", err);
}
};
- // const history = messages.filter((message) => message.role === "user");
+ // const handleHistoryClick = async (item: any) => {
+ // try {
+ // const token = localStorage.getItem("token");
- // const handleSelectHistory = (message: ChatMessage) => {
- // if (typeof message.content === "string") {
- // setInput(message.content);
- // setSelectedHistoryId(message.id);
- // setError("");
+ // const response = await api.post(
+ // "/fetchHistory",
+ // {
+ // response_id: item.response_id,
+ // },
+ // {
+ // headers: {
+ // Authorization: `Bearer ${token}`,
+ // "Content-Type": "application/json",
+ // },
+ // }
+ // );
+
+ // console.log("History Detail =>", response.data);
+
+ // if (response.data.success) {
+ // const historyData = response.data.data;
+
+ // setMessages([
+ // createMessage("user", historyData.prompt),
+ // createMessage("assistant", historyData),
+ // ]);
+ // }
+ // } catch (err) {
+ // console.error("Fetch History Error", err);
// }
// };
+
+ const handleHistoryClick = async (item: any) => {
+ try {
+ const response = await api.post(
+ "/fetchHistory",
+ {
+ response_id: item.response_id,
+ }
+ );
+
+ console.log("History Detail =>", response.data);
+
+ if (response.data.success) {
+ const historyData = response.data.data;
+
+ setMessages([
+ createMessage("user", historyData.prompt),
+ createMessage("assistant", historyData),
+ ]);
+ }
+ } catch (err) {
+ console.error("Fetch History Error", err);
+ }
+ };
+
+
const onSubmit = async (event: React.FormEvent) => {
event.preventDefault();
@@ -96,10 +170,29 @@ export default function ChatCanvas() {
JSON.stringify(response.data, null, 2)
);
- setMessages((current) => [
- ...current,
- createMessage("assistant", response.data),
- ]);
+ // setMessages((current) => [
+ // ...current,
+ // createMessage("assistant", response.data),
+ // ]);
+
+ if (response.data.type === "clarification") {
+ setMessages((current) => [
+ ...current,
+ {
+ id: createId(),
+ role: "assistant",
+ clarification: true,
+ content: response.data.message,
+ },
+ ]);
+ } else {
+ setMessages((current) => [
+ ...current,
+ createMessage("assistant", response.data),
+ ]);
+ }
+
+
}
catch (err) {
console.error(err);
@@ -146,140 +239,260 @@ export default function ChatCanvas() {
};
return (
- //
-
- {/*
-
-
-
GenBI
-
- Chat workspace
-
-
-
-
- Logout
-
-
- */}
+
{/* */}
-
+
{/* */}
- {showHistory && (
-
-
- History
-
-
- Recent prompts
-
-
- Tap a prompt to reload it into the composer.
-
-
+ {showHistory && (
- {/*
- {history.length === 0 ? (
-
- Your latest prompts will appear here as you chat.
-
- ) : (
- history
- .slice(-10)
- .reverse()
- .map((message) => (
-
handleSelectHistory(message)}
- className={cn(
- "w-full rounded-3xl border px-3 py-3 text-left text-sm transition",
- selectedHistoryId === message.id
- ? "border-primary bg-primary/10"
- : "border-border/70 bg-muted/80 hover:bg-muted/90",
- )}
- >
-
- {typeof message.content === "string"
- ? message.content
- : JSON.stringify(message.content, null, 2)}
-
-
- ))
- )}
-
*/}
-
- {historyQuestions.length === 0 ? (
-
- No recent prompts found.
-
- ) : (
- historyQuestions.map((item, index) => (
-
setInput(item.question)}
- className="w-full rounded-2xl border border-slate-200 bg-white px-4 py-3 text-left text-sm transition-all duration-200 hover:-translate-y-1 hover:border-indigo-200 hover:bg-indigo-50/40 hover:shadow-lg"
+ //
+ //
+ //
+ // History
+ //
+ //
+ // Recent prompts
+ //
+ //
+ // Tap a prompt to reload it into the composer.
+ //
+ //
+
+
+ //
+ // {historyQuestions.length === 0 ? (
+ //
+ // No recent prompts found.
+ //
+ // ) : (
+ // historyQuestions.map((item, index) => (
+ //
handleHistoryClick(item)}
+ // className="w-full rounded-2xl border border-slate-200 bg-white px-4 py-3 text-left text-sm transition-all duration-200 hover:-translate-y-1 hover:border-indigo-200 hover:bg-indigo-50/40 hover:shadow-lg"
+ // >
+ //
+ // {item.prompt}
+ //
+
+ //
+ // {new Date(item.created_at).toLocaleString()}
+ //
+ //
+ // ))
+ // )}
+ //
+
+ //
+ //
+ // Logout
+ //
+ //
+ //
+
+
+
+ {/* Dropdown */}
+ {showProfileMenu && (
+
+
+ Logout
+
+
+ )}
+
+
+
+ )}
{messages.length === 0 ? (
- Welcome to GenBI
+ Welcome to Yoda
@@ -288,10 +501,9 @@ export default function ChatCanvas() {
{[
- "Show sales by region",
- "Compare revenue by month",
- "Top 10 products",
- "Customer growth trends",
+ "What was the total stock availability across different store types last month?",
+ "what is the OSA percentage for the month of march 2026?",
+ "Which products had the highest OSA percentage in March 2026?",
].map((item) => (
-
+
- )} */}
+ ) : message.error ? (
+
+
+
+
+
+ Connection Problem
+
+
+
+ {String(message.content)}
+
+
+
+
+ ) : (
+
+ )} */}
{isUser ? (
typeof message.content === "string"
? message.content
: JSON.stringify(message.content, null, 2)
+ ) : message.clarification ? (
+
+
+ {/* Clarification Needed */}
+
+
+
+ {String(message.content)}
+
+
) : message.error ? (
@@ -371,7 +606,7 @@ export default function ChatCanvas() {
- GenBI is typing...
+ Yoda is typing...
@@ -388,10 +623,34 @@ export default function ChatCanvas() {
{/* RIGHT PANEL */}
-
-
+ {/*
+
-
+
+
+
+
+ Quick Prompts
+
+
+
+ {[
+ "What was the total stock availability across different store types last month?",
+ "what is the OSA percentage for the month of march 2026?",
+ "Which products had the highest OSA percentage in March 2026?",
+ ].map((item) => (
+ setInput(item)}
+ className="w-full rounded-lg border p-2 text-left text-sm hover:bg-muted"
+ >
+ {item}
+
+ ))}
+
+
+
+
Ask GenBI
@@ -422,22 +681,29 @@ export default function ChatCanvas() {
-
-
+
+ */}
+
+ {/* RIGHT PANEL */}
+
+
+
{/*