Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 3 additions & 23 deletions apps/web/src/components/agent-header.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as stylex from "@stylexjs/stylex";
import { Link, useRouter } from "@tanstack/react-router";
import { type ReactNode, useEffect } from "react";
import { Link } from "@tanstack/react-router";
import type { ReactNode } from "react";
import type { Agent } from "../features/agents/schema";
import { useDashboardsEnabled } from "../features/dashboards/preference";
import { motion } from "../styles/motion.stylex";
Expand All @@ -19,26 +19,6 @@ export function AgentHeader({
children?: ReactNode;
}) {
const dashboardsEnabled = useDashboardsEnabled();
const showDashboard = dashboard || dashboardsEnabled;
const router = useRouter();
// Warm every tab so a click or tap renders from the router cache at once;
// the destination then refreshes in the background. Preloads within the
// router's preload stale time are free, so remounting the header is cheap.
useEffect(() => {
const timer = setTimeout(() => {
const params = { agentId: agent.id };
const tabs = [
"/agents/$agentId",
"/agents/$agentId/note",
...(agent.kind === "coding" ? ["/agents/$agentId/jobs" as const] : []),
...(showDashboard ? ["/agents/$agentId/dashboard" as const] : []),
] as const;
for (const to of tabs)
if (!router.matchRoute({ to, params }))
void router.preloadRoute({ to, params }).catch(() => {});
}, 250);
return () => clearTimeout(timer);
}, [router, agent.id, agent.kind, showDashboard]);
return (
<header {...stylex.props(styles.header)}>
<div {...stylex.props(styles.identity)}>
Expand Down Expand Up @@ -75,7 +55,7 @@ export function AgentHeader({
Jobs
</Link>
)}
{showDashboard && (
{(dashboard || dashboardsEnabled) && (
<Link
to="/agents/$agentId/dashboard"
params={{ agentId: agent.id }}
Expand Down
56 changes: 56 additions & 0 deletions apps/web/src/components/conversation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { Appear } from "./ui/appear";
import { Button } from "./ui/button";
import { Icon } from "./ui/primitives";
import { ScrollArea } from "./ui/scroll-area";
import { Skeleton, SkeletonGroup } from "./ui/skeleton";

const ComputerPanel = lazy(() =>
import("./computer-panel").then((module) => ({
Expand Down Expand Up @@ -683,6 +684,43 @@ const fadeIn = stylex.keyframes({
to: { opacity: 1 },
});

/** Holds the conversation's layout while its first snapshot loads. */
export function ConversationSkeleton({
agent,
embedded = false,
}: {
agent: Agent;
embedded?: boolean;
}) {
return (
<section
{...stylex.props(styles.conversation, embedded && styles.embedded)}
aria-label={`Conversation with ${agent.name}`}
>
{embedded ? (
<header {...stylex.props(styles.chatHeader)}>
<h2 {...stylex.props(styles.chatTitle)}>Conversation</h2>
</header>
) : (
<AgentHeader agent={agent} />
)}
<SkeletonGroup
label="Loading conversation"
xstyle={[styles.history, styles.skeletonHistory]}
>
<Skeleton xstyle={[styles.skeletonBubble, styles.skeletonMine]} />
<Skeleton xstyle={[styles.skeletonLine, styles.skeletonWide]} />
<Skeleton xstyle={styles.skeletonLine} />
<Skeleton xstyle={[styles.skeletonLine, styles.skeletonShort]} />
<Skeleton xstyle={[styles.skeletonBubble, styles.skeletonMine]} />
<Skeleton xstyle={[styles.skeletonLine, styles.skeletonWide]} />
<Skeleton xstyle={[styles.skeletonLine, styles.skeletonShort]} />
</SkeletonGroup>
<Skeleton xstyle={styles.skeletonComposer} />
</section>
);
}

// Polls and scroll bookkeeping re-render the conversation every second, so
// unchanged messages must not re-render with it.
const ConversationRow = memo(function ConversationRow({
Expand Down Expand Up @@ -895,6 +933,24 @@ const styles = stylex.create({
animationTimingFunction: motion.easeOut,
animationFillMode: "backwards",
},
skeletonHistory: {
display: "flex",
flexDirection: "column",
justifyContent: "flex-end",
gap: 12,
overflow: "hidden",
},
skeletonBubble: { height: 40, width: "40%", borderRadius: 18 },
skeletonMine: { alignSelf: "flex-end" },
skeletonLine: { width: "70%" },
skeletonWide: { width: "85%", marginTop: 8 },
skeletonShort: { width: "45%" },
skeletonComposer: {
flexShrink: 0,
height: 56,
borderRadius: 24,
marginBottom: { default: 16, "@media (max-width: 700px)": 8 },
},
empty: { paddingTop: 60, color: colors.muted, textAlign: "center" },
error: {
display: "block",
Expand Down
65 changes: 65 additions & 0 deletions apps/web/src/components/ui/skeleton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import * as stylex from "@stylexjs/stylex";
import type { ReactNode } from "react";
import { colors } from "../../styles/tokens.stylex";

/** A placeholder block for content that is still loading. */
export function Skeleton({ xstyle }: { xstyle?: stylex.StyleXStyles }) {
return <div aria-hidden="true" {...stylex.props(styles.block, xstyle)} />;
}

/**
* Announces a loading region and fades its placeholders in after a short
* delay, so data that arrives quickly replaces them without a flash.
*/
export function SkeletonGroup({
label,
xstyle,
children,
}: {
label: string;
xstyle?: stylex.StyleXStyles;
children: ReactNode;
}) {
return (
<div
role="status"
aria-label={label}
aria-busy="true"
{...stylex.props(styles.group, xstyle)}
>
{children}
</div>
);
}

const pulse = stylex.keyframes({
"0%": { opacity: 1 },
"50%": { opacity: 0.55 },
"100%": { opacity: 1 },
});

const fadeIn = stylex.keyframes({
from: { opacity: 0 },
to: { opacity: 1 },
});

const styles = stylex.create({
group: {
animationName: fadeIn,
animationDuration: "200ms",
animationDelay: "150ms",
animationFillMode: "backwards",
},
block: {
backgroundColor: colors.bubble,
borderRadius: 8,
height: 14,
animationName: {
default: pulse,
"@media (prefers-reduced-motion: reduce)": "none",
},
animationDuration: "1.6s",
animationTimingFunction: "ease-in-out",
animationIterationCount: "infinite",
},
});
4 changes: 0 additions & 4 deletions apps/web/src/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ import { routeTree } from "./routeTree.gen";
export function getRouter() {
return createRouter({
routeTree,
// Agent tabs preload each other, so keep visited and preloaded loader data
// long enough that switching tabs renders from cache and revalidates.
defaultGcTime: 30 * 60_000,
defaultPreloadGcTime: 30 * 60_000,
// Conversations follow their latest message and manage older-history scroll.
scrollRestoration: ({ location }) =>
!/^\/agents\/[0-9a-f-]{36}(?:\/dashboard)?$/i.test(location.pathname),
Expand Down
14 changes: 14 additions & 0 deletions apps/web/src/routes/agents.$agentId.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createFileRoute } from "@tanstack/react-router";
import { ConversationSkeleton } from "../components/conversation";
import { ThreadConversations } from "../components/thread-conversations";
import { getConversationSnapshot } from "../features/chat/functions";
import { Route as RootRoute } from "./__root";
Expand All @@ -21,6 +22,10 @@ export const Route = createFileRoute("/agents/$agentId")({
}),
),
headers: () => ({ "Cache-Control": "private, no-store" }),
// Show the tab at once with a skeleton while its data loads.
pendingMs: 0,
pendingMinMs: 0,
pendingComponent: AgentPending,
component: AgentPage,
});

Expand All @@ -40,3 +45,12 @@ function AgentPage() {
/>
);
}

function AgentPending() {
const { agentId } = Route.useParams();
const result = RootRoute.useLoaderData();
const agent = result.ok
? result.value.find((agent) => agent.id === agentId)
: undefined;
return agent ? <ConversationSkeleton agent={agent} /> : null;
}
61 changes: 60 additions & 1 deletion apps/web/src/routes/agents.$agentId_.dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { createFileRoute, Link } from "@tanstack/react-router";
import { type CSSProperties, useEffect, useRef, useState } from "react";
import { AdaptiveDashboard } from "../components/adaptive-dashboard";
import { AgentHeader } from "../components/agent-header";
import { Conversation } from "../components/conversation";
import { Conversation, ConversationSkeleton } from "../components/conversation";
import { CreateTracker } from "../components/create-tracker";
import { DashboardTrackerDrafts } from "../components/dashboard-tracker";
import { Button } from "../components/ui/button";
import { Skeleton, SkeletonGroup } from "../components/ui/skeleton";
import type { Agent } from "../features/agents/schema";
import { getConversationSnapshot } from "../features/chat/functions";
import {
Expand All @@ -31,6 +32,10 @@ export const Route = createFileRoute("/agents/$agentId_/dashboard")({
return { dashboard, conversation };
},
headers: () => ({ "Cache-Control": "private, no-store" }),
// Show the tab at once with a skeleton while its data loads.
pendingMs: 0,
pendingMinMs: 0,
pendingComponent: DashboardPending,
component: DashboardPage,
});

Expand Down Expand Up @@ -361,6 +366,37 @@ function AgentDashboard({
);
}

function DashboardPending() {
const { agentId } = Route.useParams();
const agents = RootRoute.useLoaderData();
const agent = agents.ok
? agents.value.find((agent) => agent.id === agentId)
: undefined;
if (!agent) return null;
return (
<section {...stylex.props(styles.page)}>
<AgentHeader agent={agent} dashboard />
<div {...stylex.props(styles.workspace, styles.skeletonWorkspace)}>
<SkeletonGroup
label="Loading dashboard"
xstyle={[styles.content, styles.skeleton]}
>
<Skeleton xstyle={styles.skeletonToolbar} />
<div {...stylex.props(styles.skeletonGrid)}>
<Skeleton xstyle={styles.skeletonCard} />
<Skeleton xstyle={styles.skeletonCard} />
<Skeleton xstyle={styles.skeletonCard} />
<Skeleton xstyle={styles.skeletonCard} />
</div>
</SkeletonGroup>
<div {...stylex.props(styles.skeletonChat)}>
<ConversationSkeleton agent={agent} embedded />
</div>
</div>
</section>
);
}

// Polls that began before a save must not roll the selected view back.
function newerDashboard(
previous: Awaited<ReturnType<typeof loadDashboard>>,
Expand All @@ -377,6 +413,29 @@ function newerDashboard(
}

const styles = stylex.create({
skeletonWorkspace: {
gridTemplateColumns: {
default: "minmax(0, 1fr) 360px",
"@media (max-width: 1100px)": "minmax(0, 1fr)",
},
},
skeleton: { display: "flex", flexDirection: "column", gap: 16 },
skeletonToolbar: { height: 36, borderRadius: 10 },
// Mirrors the adaptive dashboard's card grid.
skeletonGrid: {
display: "grid",
gridTemplateColumns: "repeat(auto-fit, minmax(min(100%, 340px), 1fr))",
gap: 16,
},
skeletonCard: { height: 180, borderRadius: 12 },
skeletonChat: {
display: { default: "block", "@media (max-width: 1100px)": "none" },
minHeight: 0,
paddingLeft: 20,
borderLeftWidth: 1,
borderLeftStyle: "solid",
borderLeftColor: colors.border,
},
page: {
display: "flex",
flexDirection: "column",
Expand Down
42 changes: 42 additions & 0 deletions apps/web/src/routes/agents.$agentId_.note.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as stylex from "@stylexjs/stylex";
import { createFileRoute } from "@tanstack/react-router";
import { AgentHeader } from "../components/agent-header";
import { NoteWorkspace } from "../components/note-workspace";
import { Skeleton, SkeletonGroup } from "../components/ui/skeleton";
import { getNote } from "../features/notes/functions";
import { Route as RootRoute } from "./__root";

Expand All @@ -12,6 +13,10 @@ export const Route = createFileRoute("/agents/$agentId_/note")({
error: "Could not load this note. Check your connection and reload.",
})),
headers: () => ({ "Cache-Control": "private, no-store" }),
// Show the tab at once with a skeleton while its data loads.
pendingMs: 0,
pendingMinMs: 0,
pendingComponent: NotePending,
component: NotePage,
});

Expand Down Expand Up @@ -40,7 +45,44 @@ function NotePage() {
);
}

function NotePending() {
const { agentId } = Route.useParams();
const agents = RootRoute.useLoaderData();
const agent = agents.ok
? agents.value.find((a) => a.id === agentId)
: undefined;
if (!agent) return null;
return (
<section {...stylex.props(styles.page)}>
<AgentHeader agent={agent} />
<SkeletonGroup label="Loading note" xstyle={styles.skeleton}>
<Skeleton xstyle={styles.skeletonTitle} />
<Skeleton />
<Skeleton />
<Skeleton xstyle={styles.skeletonShort} />
<Skeleton xstyle={styles.skeletonGap} />
<Skeleton xstyle={styles.skeletonMedium} />
</SkeletonGroup>
</section>
);
}

const styles = stylex.create({
// Matches the note paper's measure so content lands where the skeleton was.
skeleton: {
display: "flex",
flexDirection: "column",
gap: 12,
width: "100%",
maxWidth: 880,
marginInline: "auto",
paddingInline: { default: 32, "@media (max-width: 700px)": 16 },
paddingTop: { default: 24, "@media (max-width: 700px)": 16 },
},
skeletonTitle: { height: 24, width: "35%", marginBottom: 8 },
skeletonShort: { width: "55%" },
skeletonMedium: { width: "75%" },
skeletonGap: { marginTop: 12 },
page: {
display: "flex",
flexDirection: "column",
Expand Down
Loading