Skip to content

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

Add ui

Marc Klingenb1b9a36a22c5
diff --git a/package-lock.json b/package-lock.json
index dd8ce085ca..2b5b29ff86 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -18,6 +18,8 @@
"@next-auth/prisma-adapter": "^1.0.5",
"@openapitools/openapi-generator-cli": "^2.6.0",
"@prisma/client": "^4.11.0",
+ "@radix-ui/react-collapsible": "^1.0.2",
+ "@radix-ui/react-slot": "^1.0.1",
"@t3-oss/env-nextjs": "^0.2.1",
"@tailwindcss/forms": "^0.5.3",
"@tanstack/react-query": "^4.28.0",
@@ -25,7 +27,9 @@
"@trpc/next": "^10.18.0",
"@trpc/react-query": "^10.18.0",
"@trpc/server": "^10.18.0",
+ "class-variance-authority": "^0.6.0",
"clsx": "^1.2.1",
+ "lucide-react": "^0.220.0",
"next": "^13.4.1",
"next-auth": "^4.21.0",
"next-swagger-doc": "^0.3.6",
@@ -34,6 +38,8 @@
"react-icons": "^4.8.0",
"superjson": "1.12.2",
"swagger-ui-react": "^4.18.3",
+ "tailwind-merge": "^1.12.0",
+ "tailwindcss-animate": "^1.0.5",
"zod": "^3.21.4"
},
"devDependencies": {
@@ -1324,6 +1330,141 @@
"resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-4.14.0-67.d9a4c5988f480fa576d43970d5a23641aa77bc9c.tgz",
"integrity": "sha512-3jum8/YSudeSN0zGW5qkpz+wAN2V/NYCQ+BPjvHYDfWatLWlQkqy99toX0GysDeaUoBIJg1vaz2yKqiA3CFcQw=="
},
+ "node_modules/@radix-ui/primitive": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/@radix-ui/primitive/-/primitive-1.0.0.tgz",
+ "integrity": "sha512-3e7rn8FDMin4CgeL7Z/49smCA3rFYY3Ha2rUQ7HRWFadS5iCRw08ZgVT1LaNTCNqgvrUiyczLflrVrF0SRQtNA==",
+ "dependencies": {
+ "@babel/runtime": "^7.13.10"
+ }
+ },
+ "node_modules/@radix-ui/react-collapsible": {
+ "version": "1.0.2",
+ "resolved": "https://registry.npmjs.org/@radix-ui/react-collapsible/-/react-collapsible-1.0.2.tgz",
+ "integrity": "sha512-QNiDT6Au8jUU0K1WV+HEd4loH7C5CKQjeXxskwqyiyAkyCmW7qlQM5vSSJCIoQC+OVPyhgafSmGudRP8Qm1/gA==",
+ "dependencies": {
+ "@babel/runtime": "^7.13.10",
+ "@radix-ui/primitive": "1.0.0",
+ "@radix-ui/react-compose-refs": "1.0.0",
+ "@radix-ui/react-context": "1.0.0",
+ "@radix-ui/react-id": "1.0.0",
+ "@radix-ui/react-presence": "1.0.0",
+ "@radix-ui/react-primitive": "1.0.2",
+ "@radix-ui/react-use-controllable-state": "1.0.0",
+ "@radix-ui/react-use-layout-effect": "1.0.0"
+ },
+ "peerDependencies": {
+ "react": "^16.8 || ^17.0 || ^18.0",
+ "react-dom": "^16.8 || ^17.0 || ^18.0"
+ }
+ },
+ "node_modules/@radix-ui/react-compose-refs": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/@radix-ui/react-compose-refs/-/react-compose-refs-1.0.0.tgz",
+ "integrity": "sha512-0KaSv6sx787/hK3eF53iOkiSLwAGlFMx5lotrqD2pTjB18KbybKoEIgkNZTKC60YECDQTKGTRcDBILwZVqVKvA==",
+ "dependencies": {
+ "@babel/runtime": "^7.13.10"
+ },
+ "peerDependencies": {
+ "react": "^16.8 || ^17.0 || ^18.0"
+ }
+ },
+ "node_modules/@radix-ui/react-context": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/@radix-ui/react-context/-/react-context-1.0.0.tgz",
+ "integrity": "sha512-1pVM9RfOQ+n/N5PJK33kRSKsr1glNxomxONs5c49MliinBY6Yw2Q995qfBUUo0/Mbg05B/sGA0gkgPI7kmSHBg==",
+ "dependencies": {
+ "@babel/runtime": "^7.13.10"
+ },
+ "peerDependencies": {
+ "react": "^16.8 || ^17.0 || ^18.0"
+ }
+ },
+ "node_modules/@radix-ui/react-id": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/@radix-ui/react-id/-/react-id-1.0.0.tgz",
+ "integrity": "sha512-Q6iAB/U7Tq3NTolBBQbHTgclPmGWE3OlktGGqrClPozSw4vkQ1DfQAOtzgRPecKsMdJINE05iaoDUG8tRzCBjw==",
+ "dependencies": {
+ "@babel/runtime": "^7.13.10",
+ "@radix-ui/react-use-layout-effect": "1.0.0"
+ },
+ "peerDependencies": {
+ "react": "^16.8 || ^17.0 || ^18.0"
+ }
+ },
+ "node_modules/@radix-ui/react-presence": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/@radix-ui/react-presence/-/react-presence-1.0.0.tgz",
+ "integrity": "sha512-A+6XEvN01NfVWiKu38ybawfHsBjWum42MRPnEuqPsBZ4eV7e/7K321B5VgYMPv3Xx5An6o1/l9ZuDBgmcmWK3w==",
+ "dependencies": {
+ "@babel/runtime": "^7.13.10",
+ "@radix-ui/react-compose-refs": "1.0.0",
+ "@radix-ui/react-use-layout-effect": "1.0.0"
+ },
+ "peerDependencies": {
+ "react": "^16.8 || ^17.0 || ^18.0",
+ "react-dom": "^16.8 || ^17.0 || ^18.0"
+ }
+ },
+ "node_modules/@radix-ui/react-primitive": {
+ "version": "1.0.2",
+ "resolved": "https://registry.npmjs.org/@radix-ui/react-primitive/-/react-primitive-1.0.2.tgz",
+ "integrity": "sha512-zY6G5Qq4R8diFPNwtyoLRZBxzu1Z+SXMlfYpChN7Dv8gvmx9X3qhDqiLWvKseKVJMuedFeU/Sa0Sy/Ia+t06Dw==",
+ "dependencies": {
+ "@babel/runtime": "^7.13.10",
+ "@radix-ui/react-slot": "1.0.1"
+ },
+ "peerDependencies": {
+ "react": "^16.8 || ^17.0 || ^18.0",
+ "react-dom": "^16.8 || ^17.0 || ^18.0"
+ }
+ },
+ "node_modules/@radix-ui/react-slot": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/@radix-ui/react-slot/-/react-slot-1.0.1.tgz",
+ "integrity": "sha512-avutXAFL1ehGvAXtPquu0YK5oz6ctS474iM3vNGQIkswrVhdrS52e3uoMQBzZhNRAIE0jBnUyXWNmSjGHhCFcw==",
+ "dependencies": {
+ "@babel/runtime": "^7.13.10",
+ "@radix-ui/react-compose-refs": "1.0.0"
+ },
+ "peerDependencies": {
+ "react": "^16.8 || ^17.0 || ^18.0"
+ }
+ },
+ "node_modules/@radix-ui/react-use-callback-ref": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/@radix-ui/react-use-callback-ref/-/react-use-callback-ref-1.0.0.tgz",
+ "integrity": "sha512-GZtyzoHz95Rhs6S63D2t/eqvdFCm7I+yHMLVQheKM7nBD8mbZIt+ct1jz4536MDnaOGKIxynJ8eHTkVGVVkoTg==",
+ "dependencies": {
+ "@babel/runtime": "^7.13.10"
+ },
+ "peerDependencies": {
+ "react": "^16.8 || ^17.0 || ^18.0"
+ }
+ },
+ "node_modules/@radix-ui/react-use-controllable-state": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/@radix-ui/react-use-controllable-state/-/react-use-controllable-state-1.0.0.tgz",
+ "integrity": "sha512-FohDoZvk3mEXh9AWAVyRTYR4Sq7/gavuofglmiXB2g1aKyboUD4YtgWxKj8O5n+Uak52gXQ4wKz5IFST4vtJHg==",
+ "dependencies": {
+ "@babel/runtime": "^7.13.10",
+ "@radix-ui/react-use-callback-ref": "1.0.0"
+ },
+ "peerDependencies": {
+ "react": "^16.8 || ^17.0 || ^18.0"
+ }
+ },
+ "node_modules/@radix-ui/react-use-layout-effect": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/@radix-ui/react-use-layout-effect/-/react-use-layout-effect-1.0.0.tgz",
+ "integrity": "sha512-6Tpkq+R6LOlmQb1R5NNETLG0B4YP0wc+klfXafpUCj6JGyaUc8il7/kUZ7m59rGbXGczE9Bs+iz2qloqsZBduQ==",
+ "dependencies": {
+ "@babel/runtime": "^7.13.10"
+ },
+ "peerDependencies": {
+ "react": "^16.8 || ^17.0 || ^18.0"
+ }
+ },
"node_modules/@rushstack/eslint-patch": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/@rushstack/eslint-patch/-/eslint-patch-1.2.0.tgz",
@@ -2853,6 +2994,25 @@
"resolved": "https://registry.npmjs.org/ci-info/-/ci-info-2.0.0.tgz",
"integrity": "sha512-5tK7EtrZ0N+OLFMthtqOj4fI2Jeb88C4CAZPu25LDVUgXJ0A3Js4PMGqrn0JU1W0Mh1/Z8wZzYPxqUrXeBboCQ=="
},
+ "node_modules/class-variance-authority": {
+ "version": "0.6.0",
+ "resolved": "https://registry.npmjs.org/class-variance-authority/-/class-variance-authority-0.6.0.tgz",
+ "integrity": "sha512-qdRDgfjx3GRb9fpwpSvn+YaidnT7IUJNe4wt5/SWwM+PmUwJUhQRk/8zAyNro0PmVfmen2635UboTjIBXXxy5A==",
+ "dependencies": {
+ "clsx": "1.2.1"
+ },
+ "funding": {
+ "url": "https://joebell.co.uk"
+ },
+ "peerDependencies": {
+ "typescript": ">= 4.5.5 < 6"
+ },
+ "peerDependenciesMeta": {
+ "typescript": {
+ "optional": true
+ }
+ }
+ },
"node_modules/classnames": {
"version": "2.3.2",
"resolved": "https://registry.npmjs.org/classnames/-/classnames-2.3.2.tgz",
@@ -5698,6 +5858,14 @@
"node": ">=10"
}
},
+ "node_modules/lucide-react": {
+ "version": "0.220.0",
+ "resolved": "https://registry.npmjs.org/lucide-react/-/lucide-react-0.220.0.tgz",
+ "integrity": "sha512-bYtGUsLAWBvZu+BzAU/ziP1gzE4LwMEXLnlgSr1yUKEPPalLG77JLd5GdYebOVkpm+GtqRqnp6tEKDX7Bm8ZlQ==",
+ "peerDependencies": {
+ "react": "^16.5.1 || ^17.0.0 || ^18.0.0"
+ }
+ },
"node_modules/make-error": {
"version": "1.3.6",
"resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz",
@@ -8445,6 +8613,15 @@
"url": "https://opencollective.com/unts"
}
},
+ "node_modules/tailwind-merge": {
+ "version": "1.12.0",
+ "resolved": "https://registry.npmjs.org/tailwind-merge/-/tailwind-merge-1.12.0.tgz",
+ "integrity": "sha512-Y17eDp7FtN1+JJ4OY0Bqv9OA41O+MS8c1Iyr3T6JFLnOgLg3EvcyMKZAnQ8AGyvB5Nxm3t9Xb5Mhe139m8QT/g==",
+ "funding": {
+ "type": "github",
+ "url": "https://github.com/sponsors/dcastil"
+ }
+ },
"node_modules/tailwindcss": {
"version": "3.3.2",
"resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.3.2.tgz",
@@ -8482,6 +8659,14 @@
"node": ">=14.0.0"
}
},
+ "node_modules/tailwindcss-animate": {
+ "version": "1.0.5",
+ "resolved": "https://registry.npmjs.org/tailwindcss-animate/-/tailwindcss-animate-1.0.5.tgz",
+ "integrity": "sha512-UU3qrOJ4lFQABY+MVADmBm+0KW3xZyhMdRvejwtXqYOL7YjHYxmuREFAZdmVG5LPe5E9CAst846SLC4j5I3dcw==",
+ "peerDependencies": {
+ "tailwindcss": ">=3.0.0 || insiders"
+ }
+ },
"node_modules/tailwindcss/node_modules/object-hash": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/object-hash/-/object-hash-3.0.0.tgz",
diff --git a/package.json b/package.json
index bec5a3e44c..de200f0707 100644
--- a/package.json
+++ b/package.json
@@ -22,6 +22,8 @@
"@next-auth/prisma-adapter": "^1.0.5",
"@openapitools/openapi-generator-cli": "^2.6.0",
"@prisma/client": "^4.11.0",
+ "@radix-ui/react-collapsible": "^1.0.2",
+ "@radix-ui/react-slot": "^1.0.1",
"@t3-oss/env-nextjs": "^0.2.1",
"@tailwindcss/forms": "^0.5.3",
"@tanstack/react-query": "^4.28.0",
@@ -29,7 +31,9 @@
"@trpc/next": "^10.18.0",
"@trpc/react-query": "^10.18.0",
"@trpc/server": "^10.18.0",
+ "class-variance-authority": "^0.6.0",
"clsx": "^1.2.1",
+ "lucide-react": "^0.220.0",
"next": "^13.4.1",
"next-auth": "^4.21.0",
"next-swagger-doc": "^0.3.6",
@@ -38,6 +42,8 @@
"react-icons": "^4.8.0",
"superjson": "1.12.2",
"swagger-ui-react": "^4.18.3",
+ "tailwind-merge": "^1.12.0",
+ "tailwindcss-animate": "^1.0.5",
"zod": "^3.21.4"
},
"devDependencies": {
diff --git a/src/components/ui/button.tsx b/src/components/ui/button.tsx
new file mode 100644
index 0000000000..bfea27070e
--- /dev/null
+++ b/src/components/ui/button.tsx
@@ -0,0 +1,54 @@
+import * as React from "react";
+import { Slot } from "@radix-ui/react-slot";
+import { type VariantProps, cva } from "class-variance-authority";
+import { cn } from "@/src/utils/tailwind";
+
+const buttonVariants = cva(
+ "inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:opacity-50 disabled:pointer-events-none ring-offset-background",
+ {
+ variants: {
+ variant: {
+ default: "bg-primary text-primary-foreground hover:bg-primary/90",
+ destructive:
+ "bg-destructive text-destructive-foreground hover:bg-destructive/90",
+ outline:
+ "border border-input hover:bg-accent hover:text-accent-foreground",
+ secondary:
+ "bg-secondary text-secondary-foreground hover:bg-secondary/80",
+ ghost: "hover:bg-accent hover:text-accent-foreground",
+ link: "underline-offset-4 hover:underline text-primary",
+ },
+ size: {
+ default: "h-10 py-2 px-4",
+ sm: "h-9 px-3 rounded-md",
+ lg: "h-11 px-8 rounded-md",
+ },
+ },
+ defaultVariants: {
+ variant: "default",
+ size: "default",
+ },
+ }
+);
+
+export interface ButtonProps
+ extends React.ButtonHTMLAttributes<HTMLButtonElement>,
+ VariantProps<typeof buttonVariants> {
+ asChild?: boolean;
+}
+
+const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
+ ({ className, variant, size, asChild = false, ...props }, ref) => {
+ const Comp = asChild ? Slot : "button";
+ return (
+ <Comp
+ className={cn(buttonVariants({ variant, size, className }))}
+ ref={ref}
+ {...props}
+ />
+ );
+ }
+);
+Button.displayName = "Button";
+
+export { Button, buttonVariants };
diff --git a/src/components/ui/collapsible.tsx b/src/components/ui/collapsible.tsx
new file mode 100644
index 0000000000..cb003d1756
--- /dev/null
+++ b/src/components/ui/collapsible.tsx
@@ -0,0 +1,11 @@
+"use client";
+
+import * as CollapsiblePrimitive from "@radix-ui/react-collapsible";
+
+const Collapsible = CollapsiblePrimitive.Root;
+
+const CollapsibleTrigger = CollapsiblePrimitive.CollapsibleTrigger;
+
+const CollapsibleContent = CollapsiblePrimitive.CollapsibleContent;
+
+export { Collapsible, CollapsibleTrigger, CollapsibleContent };
diff --git a/src/components/ui/descriptionLists.tsx b/src/components/ui/descriptionLists.tsx
new file mode 100644
index 0000000000..7ea89f2018
--- /dev/null
+++ b/src/components/ui/descriptionLists.tsx
@@ -0,0 +1,43 @@
+// https://tailwindui.com/components/application-ui/data-display/description-lists
+
+import { type ReactNode } from "react";
+
+export default function DescriptionList(props: {
+ header?: {
+ title: string;
+ description: string;
+ };
+ items: { label: string; value: string | ReactNode }[];
+}) {
+ return (
+ <div>
+ {props.header ? (
+ <div className="px-4 sm:px-0">
+ <h3 className="text-base font-semibold leading-7 text-gray-900">
+ {props.header.title}
+ </h3>
+ <p className="mt-1 max-w-2xl text-sm leading-6 text-gray-500">
+ {props.header.description}
+ </p>
+ </div>
+ ) : null}
+ <div className="mt-6 border-t border-gray-100">
+ <dl className="divide-y divide-gray-100">
+ {props.items.map((item) => (
+ <div
+ key={item.label}
+ className="px-4 py-6 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0"
+ >
+ <dt className="text-sm font-medium leading-6 text-gray-900">
+ {item.label}
+ </dt>
+ <dd className="mt-1 text-sm leading-6 text-gray-700 sm:col-span-2 sm:mt-0">
+ {item.value}
+ </dd>
+ </div>
+ ))}
+ </dl>
+ </div>
+ </div>
+ );
+}
diff --git a/src/pages/demo.tsx b/src/pages/demo.tsx
new file mode 100644
index 0000000000..bcd5615ef8
--- /dev/null
+++ b/src/pages/demo.tsx
@@ -0,0 +1,46 @@
+"use client";
+
+import * as React from "react";
+import { ChevronsUpDown, Plus, X } from "lucide-react";
+
+import { Button } from "~/components/ui/button";
+import {
+ Collapsible,
+ CollapsibleContent,
+ CollapsibleTrigger,
+} from "~/components/ui/collapsible";
+
+export default function CollapsibleDemo() {
+ const [isOpen, setIsOpen] = React.useState(false);
+
+ return (
+ <Collapsible
+ open={isOpen}
+ onOpenChange={setIsOpen}
+ className="w-[350px] space-y-2"
+ >
+ <div className="flex items-center justify-between space-x-4 px-4">
+ <h4 className="text-sm font-semibold">
+ @peduarte starred 3 repositories
+ </h4>
+ <CollapsibleTrigger asChild>
+ <Button variant="ghost" size="sm" className="w-9 p-0">
+ <ChevronsUpDown className="h-4 w-4" />
+ <span className="sr-only">Toggle</span>
+ </Button>
+ </CollapsibleTrigger>
+ </div>
+ <div className="rounded-md border px-4 py-3 font-mono text-sm">
+ @radix-ui/primitives
+ </div>
+ <CollapsibleContent className="space-y-2">
+ <div className="rounded-md border px-4 py-3 font-mono text-sm">
+ @radix-ui/colors
+ </div>
+ <div className="rounded-md border px-4 py-3 font-mono text-sm">
+ @stitches/react
+ </div>
+ </CollapsibleContent>
+ </Collapsible>
+ );
+}
diff --git a/src/pages/traces/[traceId].tsx b/src/pages/traces/[traceId].tsx
index b6468b5586..3ea00187e0 100644
--- a/src/pages/traces/[traceId].tsx
+++ b/src/pages/traces/[traceId].tsx
@@ -1,7 +1,17 @@
import { useRouter } from "next/router";
import Header from "~/components/layouts/header";
-
+import { Button } from "~/components/ui/button";
+import {
+ Collapsible,
+ CollapsibleContent,
+ CollapsibleTrigger,
+} from "~/components/ui/collapsible";
import { api } from "~/utils/api";
+import { ChevronsUpDown, ArrowUpRight } from "lucide-react";
+import { useState } from "react";
+import { type NestedObservation } from "@/src/utils/types";
+import Link from "next/link";
+import DescriptionList from "@/src/components/ui/descriptionLists";
export default function TracePage() {
const router = useRouter();
@@ -11,39 +21,94 @@ export default function TracePage() {
enabled: traceId !== undefined,
});
- const obs =
- trace.data?.Observations.map(({ id, name, type, parentObservationId }) => ({
- id,
- name,
- type,
- parentId: parentObservationId ?? undefined,
- })) ?? [];
- const nestedObs = transformToNestedObservations(obs);
-
return (
<>
<Header
- title="Traces"
+ title="Trace Detail"
breadcrumb={[
{ name: "Traces", href: "/traces" },
{ name: traceId as string },
]}
/>
- <div>
- {nestedObs.map((obs) => (
- <ObservationDisplay key={obs.id} obs={obs} />
- ))}
- </div>
- <pre>{JSON.stringify(nestedObs, null, 2)}</pre>
- <pre>{JSON.stringify(trace.data, null, 2)}</pre>
+ {trace.data ? (
+ <DescriptionList
+ items={[
+ {
+ label: "Timestamp",
+ value: trace.data.timestamp.toLocaleString(),
+ },
+ {
+ label: "Name",
+ value: trace.data.name,
+ },
+ {
+ label: "Status",
+ value:
+ trace.data.status +
+ (trace.data.statusMessage
+ ? ` (${trace.data.statusMessage})`
+ : ""),
+ },
+ {
+ label: "Attributes",
+ value: (
+ <span className="font-mono">
+ {JSON.stringify(trace.data.attributes, null, 2)}
+ </span>
+ ),
+ },
+ {
+ label: "Detailed trace",
+ value: (
+ <div className="space-y-2">
+ {trace.data?.nestedObservations.map((obs) => (
+ <ObservationDisplay key={obs.id} obs={obs} />
+ )) ?? null}
+ </div>
+ ),
+ },
+ ]}
+ />
+ ) : null}
</>
);
}
function ObservationDisplay(props: { obs: NestedObservation }) {
+ const [isOpen, setIsOpen] = useState(false);
+
return (
<div>
- <div>{props.obs.name}</div>
+ <Collapsible open={isOpen} onOpenChange={setIsOpen} className="space-y-2">
+ <div className="flex items-center space-x-2 px-4">
+ <span className="p-2 text-xs text-gray-500">{props.obs.type}:</span>
+ <h4 className="text-sm font-semibold">{props.obs.name}</h4>
+ {props.obs.endTime ? (
+ <span className="text-gray-500">{`${
+ props.obs.endTime.getTime() - props.obs.startTime.getTime()
+ } ms`}</span>
+ ) : null}
+ {props.obs.type === "LLMCALL" ? (
+ <Button size="sm" variant="ghost" asChild>
+ <Link href={`/llm-calls/${props.obs.id}`}>
+ <ArrowUpRight className="h-4 w-4" />
+ </Link>
+ </Button>
+ ) : null}
+ <CollapsibleTrigger asChild>
+ <Button variant="ghost" size="sm" className="w-9 p-0">
+ <ChevronsUpDown className="h-4 w-4" />
+ <span className="sr-only">Toggle</span>
+ </Button>
+ </CollapsibleTrigger>
+ </div>
+ <CollapsibleContent className="ml-6 space-y-2">
+ <span className="text-sm font-semibold">Attributes</span>
+ <pre className="rounded-md border px-4 py-3 font-mono text-sm">
+ {JSON.stringify(props.obs.attributes, null, 2)}
+ </pre>
+ </CollapsibleContent>
+ </Collapsible>
<div className="ml-5">
{props.obs.children.map((obs) => (
<ObservationDisplay key={obs.name} obs={obs} />
@@ -52,51 +117,3 @@ function ObservationDisplay(props: { obs: NestedObservation }) {
</div>
);
}
-
-type Observation = {
- id: string;
- name: string;
- type: string;
-};
-
-type UnnestedObservation = Observation & {
- parentId?: string;
-};
-
-type NestedObservation = Observation & {
- children: NestedObservation[];
-};
-
-function transformToNestedObservations(
- unnestedObservations: UnnestedObservation[]
-): NestedObservation[] {
- const nestedObservationsMap: { [id: string]: NestedObservation } = {};
-
- unnestedObservations.forEach((obs) => {
- const { id, name, type, parentId } = obs;
- const nestedObservation: NestedObservation = {
- id,
- name,
- type,
- children: [],
- };
-
- nestedObservationsMap[id] = nestedObservation;
-
- if (parentId && (nestedObservationsMap[parentId] as NestedObservation)) {
- (nestedObservationsMap[parentId] as NestedObservation).children.push(
- nestedObservation
- );
- }
- });
-
- const rootObservations: NestedObservation[] = [];
-
- unnestedObservations.forEach((obs) => {
- if (!obs.parentId) {
- rootObservations.push(nestedObservationsMap[obs.id] as NestedObservation);
- }
- });
-
- return rootObservations;
-}
diff --git a/src/server/api/routers/traces.ts b/src/server/api/routers/traces.ts
index 436257676b..1c4a3e8a46 100644
--- a/src/server/api/routers/traces.ts
+++ b/src/server/api/routers/traces.ts
@@ -1,3 +1,5 @@
+import { type NestedObservation } from "@/src/utils/types";
+import { type Observation } from "@prisma/client";
import { z } from "zod";
import { createTRPCRouter, publicProcedure } from "~/server/api/trpc";
@@ -14,14 +16,52 @@ export const traceRouter = createTRPCRouter({
return traces;
}),
- byId: publicProcedure.input(z.string()).query(({ input }) => {
- return prisma.trace.findUniqueOrThrow({
- where: {
- id: input,
- },
- include: {
- Observations: true,
- },
- });
+ byId: publicProcedure.input(z.string()).query(async ({ input }) => {
+ const [trace, observations] = await Promise.all([
+ prisma.trace.findUniqueOrThrow({
+ where: {
+ id: input,
+ },
+ }),
+ prisma.observation.findMany({
+ where: {
+ traceId: input,
+ },
+ }),
+ ]);
+
+ const nestedObservations = nestObservations(observations);
+
+ return {
+ ...trace,
+ nestedObservations,
+ };
}),
});
+
+function nestObservations(list: Observation[]): NestedObservation[] {
+ // Step 1: Create a map where the keys are object IDs, and the values are
+ // the corresponding objects with an added 'children' property.
+ const map = new Map<string, NestedObservation>();
+ for (const obj of list) {
+ map.set(obj.id, { ...obj, children: [] });
+ }
+
+ // Step 2: Create another map for the roots of all trees.
+ const roots = new Map<string, NestedObservation>();
+
+ // Step 3: Populate the 'children' arrays and root map.
+ for (const obj of map.values()) {
+ if (obj.parentObservationId) {
+ const parent = map.get(obj.parentObservationId);
+ if (parent) {
+ parent.children.push(obj);
+ }
+ } else {
+ roots.set(obj.id, obj);
+ }
+ }
+
+ // Step 4: Return the roots as an array.
+ return Array.from(roots.values());
+}
diff --git a/src/styles/globals.css b/src/styles/globals.css
index 6bbc8ccccb..c3df8d509c 100644
--- a/src/styles/globals.css
+++ b/src/styles/globals.css
@@ -3,6 +3,82 @@
@tailwind utilities;
@layer base {
+ :root {
+ --background: 0 0% 100%;
+ --foreground: 222.2 47.4% 11.2%;
+
+ --muted: 210 40% 96.1%;
+ --muted-foreground: 215.4 16.3% 46.9%;
+
+ --popover: 0 0% 100%;
+ --popover-foreground: 222.2 47.4% 11.2%;
+
+ --card: 0 0% 100%;
+ --card-foreground: 222.2 47.4% 11.2%;
+
+ --border: 214.3 31.8% 91.4%;
+ --input: 214.3 31.8% 91.4%;
+
+ --primary: 222.2 47.4% 11.2%;
+ --primary-foreground: 210 40% 98%;
+
+ --secondary: 210 40% 96.1%;
+ --secondary-foreground: 222.2 47.4% 11.2%;
+
+ --accent: 210 40% 96.1%;
+ --accent-foreground: 222.2 47.4% 11.2%;
+
+ --destructive: 0 100% 50%;
+ --destructive-foreground: 210 40% 98%;
+
+ --ring: 215 20.2% 65.1%;
+
+ --radius: 0.5rem;
+ }
+
+ .dark {
+ --background: 224 71% 4%;
+ --foreground: 213 31% 91%;
+
+ --muted: 223 47% 11%;
+ --muted-foreground: 215.4 16.3% 56.9%;
+
+ --popover: 224 71% 4%;
+ --popover-foreground: 215 20.2% 65.1%;
+
+ --card: 224 71% 4%;
+ --card-foreground: 213 31% 91%;
+
+ --border: 216 34% 17%;
+ --input: 216 34% 17%;
+
+ --primary: 210 40% 98%;
+ --primary-foreground: 222.2 47.4% 1.2%;
+
+ --secondary: 222.2 47.4% 11.2%;
+ --secondary-foreground: 210 40% 98%;
+
+ --accent: 216 34% 17%;
+ --accent-foreground: 210 40% 98%;
+
+ --destructive: 0 63% 31%;
+ --destructive-foreground: 210 40% 98%;
+
+ --ring: 216 34% 17%;
+
+ --radius: 0.5rem;
+ }
+}
+
+@layer base {
+ * {
+ @apply border-border;
+ }
+ body {
+ @apply bg-background text-foreground;
+ font-feature-settings: "rlig" 1, "calt" 1;
+ }
+
html,
body,
body > div:first-child,
diff --git a/src/utils/tailwind.ts b/src/utils/tailwind.ts
new file mode 100644
index 0000000000..a5ef193506
--- /dev/null
+++ b/src/utils/tailwind.ts
@@ -0,0 +1,6 @@
+import { clsx, type ClassValue } from "clsx";
+import { twMerge } from "tailwind-merge";
+
+export function cn(...inputs: ClassValue[]) {
+ return twMerge(clsx(inputs));
+}
diff --git a/src/utils/types.ts b/src/utils/types.ts
index 53141fb7bf..184cfb0c23 100644
--- a/src/utils/types.ts
+++ b/src/utils/types.ts
@@ -1,5 +1,9 @@
import { type Observation, type Prisma } from "@prisma/client";
+export type NestedObservation = Observation & {
+ children: NestedObservation[];
+};
+
export type LlmCall = Observation & {
attributes: {
prompt?: string;
diff --git a/tailwind.config.ts b/tailwind.config.ts
index da6db39a16..24301ad18c 100644
--- a/tailwind.config.ts
+++ b/tailwind.config.ts
@@ -1,11 +1,77 @@
import { type Config } from "tailwindcss";
+import { fontFamily } from "tailwindcss/defaultTheme";
+// Based on: https://ui.shadcn.com/docs/installation#configure-tailwindconfigjs
export default {
content: ["./src/**/*.{js,ts,jsx,tsx}"],
+ darkMode: ["class"],
theme: {
- extend: {},
+ container: {
+ center: true,
+ padding: "2rem",
+ screens: {
+ "2xl": "1400px",
+ },
+ },
+ extend: {
+ colors: {
+ border: "hsl(var(--border))",
+ input: "hsl(var(--input))",
+ ring: "hsl(var(--ring))",
+ background: "hsl(var(--background))",
+ foreground: "hsl(var(--foreground))",
+ primary: {
+ DEFAULT: "hsl(var(--primary))",
+ foreground: "hsl(var(--primary-foreground))",
+ },
+ secondary: {
+ DEFAULT: "hsl(var(--secondary))",
+ foreground: "hsl(var(--secondary-foreground))",
+ },
+ destructive: {
+ DEFAULT: "hsl(var(--destructive))",
+ foreground: "hsl(var(--destructive-foreground))",
+ },
+ muted: {
+ DEFAULT: "hsl(var(--muted))",
+ foreground: "hsl(var(--muted-foreground))",
+ },
+ accent: {
+ DEFAULT: "hsl(var(--accent))",
+ foreground: "hsl(var(--accent-foreground))",
+ },
+ popover: {
+ DEFAULT: "hsl(var(--popover))",
+ foreground: "hsl(var(--popover-foreground))",
+ },
+ card: {
+ DEFAULT: "hsl(var(--card))",
+ foreground: "hsl(var(--card-foreground))",
+ },
+ },
+ borderRadius: {
+ lg: `var(--radius)`,
+ md: `calc(var(--radius) - 2px)`,
+ sm: "calc(var(--radius) - 4px)",
+ },
+ // fontFamily: {
+ // sans: ["var(--font-sans)", ...fontFamily.sans],
+ // },
+ keyframes: {
+ "accordion-down": {
+ from: { height: "0" },
+ to: { height: "var(--radix-accordion-content-height)" },
+ },
+ "accordion-up": {
+ from: { height: "var(--radix-accordion-content-height)" },
+ to: { height: "0" },
+ },
+ },
+ animation: {
+ "accordion-down": "accordion-down 0.2s ease-out",
+ "accordion-up": "accordion-up 0.2s ease-out",
+ },
+ },
},
- plugins: [
- require('@tailwindcss/forms'),
- ],
+ plugins: [require("@tailwindcss/forms"), require("tailwindcss-animate")],
} satisfies Config;
diff --git a/tsconfig.json b/tsconfig.json
index 8562de8576..3c53d0197c 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -18,6 +18,7 @@
"noUncheckedIndexedAccess": true,
"baseUrl": ".",
"paths": {
+ "@/*": ["./*"],
"~/*": ["./src/*"]
}
},