Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(ui): always show Full Report link when runId exists in session history (#150)

Thiên Toán2a893e1a2691
diff --git a/frontend/src/pages/Agent.tsx b/frontend/src/pages/Agent.tsx
index 0141f203c..f1f411aa1 100644
--- a/frontend/src/pages/Agent.tsx
+++ b/frontend/src/pages/Agent.tsx
@@ -352,20 +352,33 @@ export function Agent() {
if (metrics && Object.keys(metrics).length > 0) {
agentMsgs.push({ id: m.message_id, type: "run_complete", content: "", runId, metrics, timestamp: ts + 1 });
} else {
+ // Fetch run data to check report-worthiness; show fallback card if fetch fails
+ let fetchedMetrics: Record<string, number> | undefined;
+ let fetchedCurve: Array<{ time: string; equity: number }> | undefined;
+ let showCard = false;
try {
const runData = await api.getRun(runId);
if (isReportWorthyRun(runData)) {
- agentMsgs.push({
- id: m.message_id,
- type: "run_complete",
- content: "",
- runId,
- metrics: runData.metrics,
- equityCurve: runData.equity_curve?.map((e) => ({ time: e.time, equity: e.equity })),
- timestamp: ts + 1,
- });
+ fetchedMetrics = runData.metrics;
+ fetchedCurve = runData.equity_curve?.map((e) => ({ time: e.time, equity: Number(e.equity) }));
+ showCard = true;
}
- } catch { /* ignore non-report attempt directories */ }
+ // succeeded but not report-worthy (plain chat turn) → skip card
+ } catch {
+ // fetch failed (auth/404/network) → can't tell, show link as fallback
+ showCard = true;
+ }
+ if (showCard) {
+ agentMsgs.push({
+ id: m.message_id,
+ type: "run_complete",
+ content: "",
+ runId,
+ metrics: fetchedMetrics,
+ equityCurve: fetchedCurve,
+ timestamp: ts + 1,
+ });
+ }
}
} else {
agentMsgs.push({ id: m.message_id, type: "answer", content: m.content, timestamp: ts });
@@ -486,19 +499,28 @@ export function Agent() {
// Show RunCompleteCard when the turn produced backtest metrics or a shadow report
if (runId) {
+ let runMetrics: Record<string, number> | undefined;
+ let runCurve: Array<{ time: string; equity: number }> | undefined;
+ let showCard = false;
try {
const runData = await api.getRun(runId);
- const hasReport = isReportWorthyRun(runData);
- if (hasReport || shadowId) {
- s.addMessage({
- id: "", type: "run_complete", content: "", runId,
- metrics: hasReport ? runData.metrics : undefined,
- equityCurve: runData.equity_curve?.map(e => ({ time: e.time, equity: e.equity })),
- shadowId,
- timestamp: Date.now(),
- });
+ if (isReportWorthyRun(runData)) {
+ runMetrics = runData.metrics;
+ runCurve = runData.equity_curve?.map(e => ({ time: e.time, equity: Number(e.equity) }));
+ showCard = true;
}
- } catch { /* ignore */ }
+ } catch {
+ showCard = true; // fetch failed → show link as fallback
+ }
+ if (showCard || shadowId) {
+ s.addMessage({
+ id: "", type: "run_complete", content: "", runId,
+ metrics: showCard ? runMetrics : undefined,
+ equityCurve: showCard ? runCurve : undefined,
+ shadowId,
+ timestamp: Date.now(),
+ });
+ }
} else if (shadowId) {
s.addMessage({ id: "", type: "run_complete", content: "", shadowId, timestamp: Date.now() });
}
diff --git a/frontend/src/pages/RunDetail.tsx b/frontend/src/pages/RunDetail.tsx
index 728fc40f4..08e69cd89 100644
--- a/frontend/src/pages/RunDetail.tsx
+++ b/frontend/src/pages/RunDetail.tsx
@@ -97,7 +97,21 @@ export function RunDetail() {
</div>
);
}
- if (!run) return <div className="p-8 text-red-500">Run not found</div>;
+ if (!run) return (
+ <div className="p-8 space-y-2">
+ <p className="text-red-500 font-medium">Run not found</p>
+ <p className="text-sm text-muted-foreground">
+ The run directory may have been removed, or your browser may not have API access configured.
+ Check that the API authentication key is set in Settings if accessing remotely.
+ </p>
+ <button
+ onClick={() => navigate(-1)}
+ className="text-sm text-primary hover:underline inline-flex items-center gap-1.5"
+ >
+ <ArrowLeft className="h-3.5 w-3.5" /> Go back
+ </button>
+ </div>
+ );
const ok = run.status === "success";