feat: LangChain auto-instrumentation + dashboard UI

- LangChain: AgentLensCallbackHandler with auto-span creation for
  LLM calls, tool calls, chains, and agent decision logging
- Dashboard: trace list with search, status filters, pagination
- Dashboard: trace detail with Decision/Span/Event tabs
- Dashboard: sidebar layout, responsive design, dark theme
This commit is contained in:
Vectry
2026-02-09 23:36:28 +00:00
parent 3fe9013838
commit 21b4f9f316
7 changed files with 1677 additions and 23 deletions

View File

@@ -0,0 +1,87 @@
import { notFound } from "next/navigation";
import { TraceDetail } from "@/components/trace-detail";
interface TraceResponse {
trace: {
id: string;
name: string;
status: "RUNNING" | "COMPLETED" | "ERROR";
startedAt: string;
endedAt: string | null;
durationMs: number | null;
tags: string[];
metadata: Record<string, unknown>;
costUsd: number | null;
};
decisionPoints: Array<{
id: string;
type: string;
chosenAction: string;
alternatives: string[];
reasoning: string | null;
contextSnapshot: Record<string, unknown> | null;
confidence: number | null;
timestamp: string;
}>;
spans: Array<{
id: string;
name: string;
type: string;
status: "OK" | "ERROR" | "CANCELLED";
startedAt: string;
endedAt: string | null;
durationMs: number | null;
input: unknown;
output: unknown;
metadata: Record<string, unknown>;
}>;
events: Array<{
id: string;
type: string;
name: string;
timestamp: string;
metadata: Record<string, unknown>;
}>;
}
async function getTrace(id: string): Promise<TraceResponse | null> {
try {
const res = await fetch(`http://localhost:3000/api/traces/${id}`, {
cache: "no-store",
});
if (!res.ok) {
if (res.status === 404) {
return null;
}
throw new Error(`Failed to fetch trace: ${res.status}`);
}
return res.json();
} catch (error) {
console.error("Error fetching trace:", error);
return null;
}
}
interface TraceDetailPageProps {
params: Promise<{ id: string }>;
}
export default async function TraceDetailPage({ params }: TraceDetailPageProps) {
const { id } = await params;
const data = await getTrace(id);
if (!data) {
notFound();
}
return (
<TraceDetail
trace={data.trace}
decisionPoints={data.decisionPoints}
spans={data.spans}
events={data.events}
/>
);
}