"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
fix(ui): reliable session running-status indicator
Haozhe Wua0da6c7727ba
diff --git a/frontend/src/components/layout/Layout.tsx b/frontend/src/components/layout/Layout.tsxindex f952977d4..8dc2a9a4b 100644--- a/frontend/src/components/layout/Layout.tsx+++ b/frontend/src/components/layout/Layout.tsx@@ -1,6 +1,6 @@import { useEffect, useState } from "react";import { Link, Outlet, useLocation, useSearchParams } from "react-router-dom";-import { BarChart3, Bot, Moon, Sun, Plus, Trash2, Pencil, MessageSquare, ChevronsLeft, ChevronsRight, Settings, Layers } from "lucide-react";+import { BarChart3, Bot, Moon, Sun, Plus, Trash2, Pencil, MessageSquare, ChevronsLeft, ChevronsRight, Settings, Layers, Loader2 } from "lucide-react";import { cn } from "@/lib/utils";import { useDarkMode } from "@/hooks/useDarkMode";import { api, type SessionItem } from "@/lib/api";@@ -29,6 +29,7 @@ export function Layout() {const [collapsed, setCollapsed] = useState(() => localStorage.getItem("qa-sidebar") === "collapsed");const activeSessionId = searchParams.get("session");+ const streamingSessionId = useAgentStore(s => s.streamingSessionId);useEffect(() => {localStorage.setItem("qa-sidebar", collapsed ? "collapsed" : "expanded");@@ -160,10 +161,14 @@ export function Layout() {title={s.title || s.session_id}><span className="flex items-center gap-1.5">- <span className={cn(- "h-1.5 w-1.5 rounded-full shrink-0",- s.status === "failed" ? "bg-danger" : isActive ? "bg-warning" : "bg-success/60"- )} />+ {streamingSessionId === s.session_id ? (+ <Loader2 className="h-3 w-3 shrink-0 animate-spin text-primary" />+ ) : (+ <span className={cn(+ "h-1.5 w-1.5 rounded-full shrink-0",+ isActive ? "bg-primary/70" : "bg-muted-foreground/40"+ )} />+ )}{s.title || s.session_id.slice(0, 16)}</span></Link>diff --git a/frontend/src/hooks/useSSE.ts b/frontend/src/hooks/useSSE.tsindex 7e3969c60..357bb12a3 100644--- a/frontend/src/hooks/useSSE.ts+++ b/frontend/src/hooks/useSSE.ts@@ -81,7 +81,9 @@ export function useSSE(config?: SSEConfig) {// Only subscribe to event types the backend actually emitsconst knownTypes = ["text_delta", "thinking_done", "tool_call", "tool_result", "compact",- "attempt.completed", "attempt.failed",+ "tool_heartbeat", "llm_usage",+ "attempt.created", "attempt.started", "attempt.completed", "attempt.failed",+ "message.received", "session.created","goal.created", "goal.evidence", "goal.updated","mandate.proposal", "mandate.committed", "live.halted", "live.resumed", "live.action","heartbeat", "done",diff --git a/frontend/src/index.css b/frontend/src/index.cssindex 31f7121f7..a92b91e34 100644--- a/frontend/src/index.css+++ b/frontend/src/index.css@@ -79,3 +79,10 @@::-webkit-scrollbar-thumb { background: hsl(var(--border)); border-radius: 3px; }::-webkit-scrollbar-thumb:hover { background: hsl(var(--muted-foreground)); }}++/* Streaming pulse-slide animation for the "running" bar */+@keyframes pulse-slide {+ 0% { transform: translateX(-100%); }+ 50% { transform: translateX(200%); }+ 100% { transform: translateX(-100%); }+}diff --git a/frontend/src/pages/Agent.tsx b/frontend/src/pages/Agent.tsxindex fb743e153..c7eb417f3 100644--- a/frontend/src/pages/Agent.tsx+++ b/frontend/src/pages/Agent.tsx@@ -435,6 +435,8 @@ export function Agent() {tool_heartbeat: (d) => {touch();+ // Keep streaming state alive during long-running tools (swarm, backtest)+ if (act().status !== "streaming") act().setStatus("streaming");const toolName = String(d.tool || "");if (!toolName) return;act().updateToolCall(toolName, {@@ -468,6 +470,20 @@ export function Agent() {compact: () => { touch(); },+ "attempt.created": () => {+ touch();+ // Backend has created a new attempt — ensure streaming state is active+ // even if we connected mid-stream (SSE replay / page reload).+ if (act().status !== "streaming") act().setStatus("streaming");+ },++ "attempt.started": () => {+ touch();+ // Backend has begun executing the attempt. Re-affirm streaming state+ // so the UI shows a working indicator for reconnects and fresh loads.+ if (act().status !== "streaming") act().setStatus("streaming");+ },+"attempt.completed": async (d) => {touch();const s = act();@@ -1081,7 +1097,7 @@ export function Agent() {<AgentAvatar /><div className="flex-1 min-w-0 flex items-center gap-2 text-xs text-muted-foreground pt-1"><Loader2 className="h-3 w-3 animate-spin text-primary shrink-0" />- <span>Thinking…</span>+ <span>Agent is working…</span></div></div>)}@@ -1104,6 +1120,16 @@ export function Agent() {</div>)}+ {/* Persistent streaming pulse bar — always visible while agent is working */}+ {status === "streaming" && (+ <div className="flex items-center gap-2 px-1 pt-1">+ <div className="h-0.5 flex-1 rounded-full bg-primary/20 overflow-hidden">+ <div className="h-full w-1/3 bg-primary rounded-full animate-[pulse-slide_2s_ease-in-out_infinite]" />+ </div>+ <span className="text-[10px] text-muted-foreground shrink-0 tabular-nums">running</span>+ </div>+ )}+</div>{/* Scroll to bottom button */}diff --git a/frontend/src/stores/agent.ts b/frontend/src/stores/agent.tsindex bb2c3c227..5ab2cf203 100644--- a/frontend/src/stores/agent.ts+++ b/frontend/src/stores/agent.ts@@ -10,6 +10,10 @@ interface AgentState {status: "idle" | "streaming" | "error";streamingText: string;+ /** The session currently streaming on the backend. Survives switchSession+ * so the sidebar spinner persists when the user navigates away. */+ streamingSessionId: string | null;+toolCalls: ToolCallEntry[];sseStatus: "disconnected" | "connected" | "reconnecting";@@ -46,6 +50,7 @@ export const useAgentStore = create<AgentState>((set) => ({sessionId: null,status: "idle",streamingText: "",+ streamingSessionId: null,toolCalls: [],sseStatus: "disconnected",sseRetryAttempt: 0,@@ -57,7 +62,16 @@ export const useAgentStore = create<AgentState>((set) => ({appendDelta: (delta) =>set((s) => ({ streamingText: s.streamingText + delta })),- setStatus: (status) => set({ status }),+ setStatus: (status) =>+ set((s) => {+ const patch: Partial<AgentState> = { status };+ if (status === "streaming" && s.sessionId) {+ patch.streamingSessionId = s.sessionId;+ } else if (status !== "streaming" && s.streamingSessionId === s.sessionId) {+ patch.streamingSessionId = null;+ }+ return patch;+ }),setSessionId: (sessionId) => set({ sessionId }),loadHistory: (msgs) => set({ messages: msgs }),@@ -85,14 +99,17 @@ export const useAgentStore = create<AgentState>((set) => ({switchSession: (sid, msgs) => {_id = 0;- set({+ set((s) => ({sessionId: sid,messages: msgs || [],status: "idle",streamingText: "",toolCalls: [],sessionLoading: !msgs,- });+ // Preserve streamingSessionId so the sidebar spinner stays visible+ // when switching away from a running session.+ streamingSessionId: s.streamingSessionId,+ }));},setSessionLoading: (sessionLoading) => set({ sessionLoading }),@@ -102,6 +119,7 @@ export const useAgentStore = create<AgentState>((set) => ({set({messages: [], status: "idle", streamingText: "",sessionId: null, toolCalls: [], sessionLoading: false,+ streamingSessionId: null,});},}));