Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

perf: load trace i/o separately from rest of session (#1706)

Marc Klingenc60d1cc5d934
diff --git a/web/src/components/session/index.tsx b/web/src/components/session/index.tsx
index 3788489fa7..2a12a40584 100644
--- a/web/src/components/session/index.tsx
+++ b/web/src/components/session/index.tsx
@@ -4,6 +4,7 @@ import { NoAccessError } from "@/src/components/no-access";
import { PublishSessionSwitch } from "@/src/components/publish-object-switch";
import { StarSessionToggle } from "@/src/components/star-toggle";
import { IOPreview } from "@/src/components/trace/IOPreview";
+import { JsonSkeleton } from "@/src/components/ui/CodeJsonViewer";
import { Badge } from "@/src/components/ui/badge";
import { Card } from "@/src/components/ui/card";
import { ManualScoreButton } from "@/src/features/manual-scoring/components/ManualScoreButton";
@@ -101,20 +102,7 @@ export const SessionPage: React.FC<{
className="border-border-gray-150 group grid gap-3 p-2 shadow-none hover:border-gray-300 md:grid-cols-3"
key={trace.id}
>
- <div className="col-span-2 flex flex-col gap-2 p-0">
- {trace.input || trace.output ? (
- <IOPreview
- key={trace.id}
- input={trace.input}
- output={trace.output}
- hideIfNull
- />
- ) : (
- <div className="p-2 text-xs text-gray-500">
- This trace has no input or output.
- </div>
- )}
- </div>
+ <SessionIO traceId={trace.id} />
<div className="-mt-1 p-1 opacity-50 transition-opacity group-hover:opacity-100">
<Link
href={`/project/${projectId}/traces/${trace.id}`}
@@ -142,3 +130,39 @@ export const SessionPage: React.FC<{
</div>
);
};
+
+const SessionIO = ({ traceId }: { traceId: string }) => {
+ const trace = api.traces.byId.useQuery(
+ { traceId: traceId },
+ {
+ enabled: typeof traceId === "string",
+ trpc: {
+ context: {
+ skipBatch: true,
+ },
+ },
+ refetchOnMount: false, // prevents refetching loops
+ },
+ );
+ return (
+ <div className="col-span-2 flex flex-col gap-2 p-0">
+ {!trace.data ? (
+ <JsonSkeleton
+ className="h-full w-full overflow-hidden px-2 py-1"
+ numRows={4}
+ />
+ ) : trace.data.input || trace.data.output ? (
+ <IOPreview
+ key={traceId}
+ input={trace.data.input}
+ output={trace.data.output}
+ hideIfNull
+ />
+ ) : (
+ <div className="p-2 text-xs text-gray-500">
+ This trace has no input or output.
+ </div>
+ )}
+ </div>
+ );
+};
diff --git a/web/src/components/ui/CodeJsonViewer.tsx b/web/src/components/ui/CodeJsonViewer.tsx
index 26724e489f..37958fca32 100644
--- a/web/src/components/ui/CodeJsonViewer.tsx
+++ b/web/src/components/ui/CodeJsonViewer.tsx
@@ -5,7 +5,6 @@ import { cn } from "@/src/utils/tailwind";
import { default as React18JsonView } from "react18-json-view";
import { deepParseJson } from "@/src/utils/json";
import { Skeleton } from "@/src/components/ui/skeleton";
-import { randomIntFromInterval } from "@/src/utils/numbers";
export function JSONView(props: {
json?: unknown;
@@ -141,24 +140,18 @@ export const JsonSkeleton = ({
numRows?: number;
className?: string;
}) => {
- const sizingOptions = [
- "h-4 w-full",
- "h-4 w-[400px]",
- "h-4 w-[450px]",
- "h-4 w-[475px]",
- ];
-
- const generateRandomSize = () =>
- sizingOptions[randomIntFromInterval(0, sizingOptions.length - 1)];
-
return (
<div className={cn("w-[400px] rounded-md border", className)}>
<div className="flex flex-col gap-1">
- <Skeleton className="h-4 w-full" />
{[...Array<number>(numRows)].map((_, i) => (
- <Skeleton className={generateRandomSize()} key={i} />
+ <Skeleton
+ className={cn(
+ "h-4 w-full",
+ i === numRows - 1 ? "w-3/4" : undefined,
+ )}
+ key={i}
+ />
))}
- <br />
</div>
</div>
);
diff --git a/web/src/features/manual-scoring/components/ManualScoreButton.tsx b/web/src/features/manual-scoring/components/ManualScoreButton.tsx
index e55b51a57b..c33a51606e 100644
--- a/web/src/features/manual-scoring/components/ManualScoreButton.tsx
+++ b/web/src/features/manual-scoring/components/ManualScoreButton.tsx
@@ -26,7 +26,6 @@ import { useForm } from "react-hook-form";
import { Slider } from "@/src/components/ui/slider";
import { useHasAccess } from "@/src/features/rbac/utils/checkAccess";
import { LockIcon } from "lucide-react";
-import { Badge } from "@/src/components/ui/badge";
const SCORE_NAME = "manual-score";
@@ -138,9 +137,9 @@ export function ManualScoreButton({
{!hasAccess ? <LockIcon className="ml-2 h-3 w-3" /> : null}
</Button>
) : (
- <Badge className="cursor-pointer">
+ <Button className="h-6 rounded-full px-3 text-xs">
{score ? "Update score" : "Add score"}
- </Badge>
+ </Button>
)}
</DialogTrigger>
<DialogContent>
diff --git a/web/src/server/api/routers/sessions.ts b/web/src/server/api/routers/sessions.ts
index 3e906b24ad..2d9c2d4c8b 100644
--- a/web/src/server/api/routers/sessions.ts
+++ b/web/src/server/api/routers/sessions.ts
@@ -163,8 +163,12 @@ export const sessionRouter = createTRPCRouter({
orderBy: {
timestamp: "asc",
},
- include: {
+ select: {
+ id: true,
+ userId: true,
scores: true,
+ name: true,
+ timestamp: true,
},
},
},