Skip to content

armgit / crm

Public Imported from GitHub
0

Comp AI CRM is an open source, CRM designed for AI agents. Agentic-first CRM.

TypeScript

fix(app): CMP-47 consolidate agent builder presentation (#64)

grim1809d277c31f
diff --git a/apps/app/app/(app)/[slug]/(agent-builder)/agents/loading.tsx b/apps/app/app/(app)/[slug]/(agent-builder)/agents/loading.tsx
deleted file mode 100644
index 6884992b..00000000
--- a/apps/app/app/(app)/[slug]/(agent-builder)/agents/loading.tsx
+++ /dev/null
@@ -1,5 +0,0 @@
-import { PageShellFallback } from "@/components/page-shell";
-
-export default function AgentsLoading() {
- return <PageShellFallback />;
-}
diff --git a/apps/app/app/(app)/[slug]/(agent-builder)/chat/[chatId]/page.tsx b/apps/app/app/(app)/[slug]/(agent-builder)/chat/[chatId]/page.tsx
index 2f08c456..23ac83c2 100644
--- a/apps/app/app/(app)/[slug]/(agent-builder)/chat/[chatId]/page.tsx
+++ b/apps/app/app/(app)/[slug]/(agent-builder)/chat/[chatId]/page.tsx
@@ -1,6 +1,7 @@
import type { Metadata } from "next";
import { Suspense } from "react";
import { AgentBuilderChat } from "@/components/agent-builder/agent-builder-chat";
+import { AgentBuilderChatFallback } from "@/components/agent-builder/agent-builder-route-fallback";
import { isSharedChatToken } from "@/lib/chat-route";
import { getServerQueryClient, getServerTrpc } from "@/lib/trpc/server";
@@ -12,7 +13,7 @@ export default function AgentChatPage({
params: Promise<{ chatId: string }>;
}) {
return (
- <Suspense fallback={<ChatFallback />}>
+ <Suspense fallback={<AgentBuilderChatFallback />}>
<PrefetchedAgentChat params={params} />
</Suspense>
);
@@ -28,25 +29,15 @@ async function PrefetchedAgentChat({
const queryClient = getServerQueryClient();
const sharedChat = isSharedChatToken(chatId);
- if (sharedChat) {
- await queryClient.prefetchQuery(
- trpc.conversations.shared.queryOptions({ token: chatId }),
- );
- } else {
- await queryClient.prefetchQuery(
- trpc.conversations.builderById.queryOptions({
- id: chatId,
- }),
- );
- }
+ const initialData = sharedChat
+ ? await queryClient
+ .fetchQuery(trpc.conversations.shared.queryOptions({ token: chatId }))
+ .catch(() => null)
+ : await queryClient.fetchQuery(
+ trpc.conversations.builderById.queryOptions({
+ id: chatId,
+ }),
+ );
- return <AgentBuilderChat conversationId={chatId} />;
-}
-
-function ChatFallback() {
- return (
- <main className="flex min-h-0 flex-1 items-center justify-center">
- <span className="text-muted-foreground text-sm">Opening chat…</span>
- </main>
- );
+ return <AgentBuilderChat conversationId={chatId} initialData={initialData} />;
}
diff --git a/apps/app/app/(app)/[slug]/(agent-builder)/chat/page.tsx b/apps/app/app/(app)/[slug]/(agent-builder)/chat/page.tsx
index 5358a0c3..0a3a39f6 100644
--- a/apps/app/app/(app)/[slug]/(agent-builder)/chat/page.tsx
+++ b/apps/app/app/(app)/[slug]/(agent-builder)/chat/page.tsx
@@ -1,6 +1,7 @@
import type { Metadata } from "next";
import { Suspense } from "react";
import { AgentBuilderHome } from "@/components/agent-builder/agent-builder-home";
+import { AgentBuilderHomeFallback } from "@/components/agent-builder/agent-builder-route-fallback";
import { requireSession } from "@/lib/session";
import { HydrateClient } from "@/lib/trpc/hydrate";
import { getServerQueryClient, getServerTrpc } from "@/lib/trpc/server";
@@ -9,7 +10,7 @@ export const metadata: Metadata = { title: "Chat" };
export default function ChatPage() {
return (
- <Suspense fallback={<ChatHomeFallback />}>
+ <Suspense fallback={<AgentBuilderHomeFallback />}>
<ChatHome />
</Suspense>
);
@@ -33,11 +34,3 @@ async function ChatHome() {
</HydrateClient>
);
}
-
-function ChatHomeFallback() {
- return (
- <main className="flex min-h-0 flex-1 items-center justify-center">
- <span className="text-muted-foreground text-sm">Opening chat…</span>
- </main>
- );
-}
diff --git a/apps/app/app/(app)/[slug]/(agent-builder)/layout.tsx b/apps/app/app/(app)/[slug]/(agent-builder)/layout.tsx
index 229b5844..fa038833 100644
--- a/apps/app/app/(app)/[slug]/(agent-builder)/layout.tsx
+++ b/apps/app/app/(app)/[slug]/(agent-builder)/layout.tsx
@@ -1,5 +1,9 @@
import { Suspense } from "react";
-import { AgentBuilderShell } from "@/components/agent-builder/agent-builder-shell";
+import {
+ AgentBuilderShell,
+ AgentBuilderSidebarFallback,
+} from "@/components/agent-builder/agent-builder-shell";
+import { AgentBuilderSidebar } from "@/components/agent-builder/agent-builder-sidebar";
import { HydrateClient } from "@/lib/trpc/hydrate";
import { getServerQueryClient, getServerTrpc } from "@/lib/trpc/server";
@@ -7,29 +11,19 @@ export default function AgentBuilderLayout({
children,
}: Readonly<{ children: React.ReactNode }>) {
return (
- <Suspense
- fallback={
- <AgentBuilderShell>
- <AgentBuilderContentFallback />
- </AgentBuilderShell>
+ <AgentBuilderShell
+ sidebar={
+ <Suspense fallback={<AgentBuilderSidebarFallback />}>
+ <PrefetchedAgentBuilderSidebar />
+ </Suspense>
}
>
- <PrefetchedAgentBuilderShell>{children}</PrefetchedAgentBuilderShell>
- </Suspense>
+ {children}
+ </AgentBuilderShell>
);
}
-function AgentBuilderContentFallback() {
- return (
- <main className="flex min-h-0 flex-1 items-center justify-center">
- <span className="text-muted-foreground text-sm">Loading chat…</span>
- </main>
- );
-}
-
-async function PrefetchedAgentBuilderShell({
- children,
-}: Readonly<{ children: React.ReactNode }>) {
+async function PrefetchedAgentBuilderSidebar() {
const trpc = getServerTrpc();
const queryClient = getServerQueryClient();
const conversationsQuery = trpc.conversations.builderList.queryOptions();
@@ -46,9 +40,10 @@ async function PrefetchedAgentBuilderShell({
return (
<HydrateClient>
- <AgentBuilderShell sidebarData={{ conversations, agents, updatedAt }}>
- {children}
- </AgentBuilderShell>
+ <AgentBuilderSidebar
+ className="hidden w-[213px] flex-none border-r md:flex"
+ initialData={{ conversations, agents, updatedAt }}
+ />
</HydrateClient>
);
}
diff --git a/apps/app/app/(app)/[slug]/(agent-builder)/loading.tsx b/apps/app/app/(app)/[slug]/(agent-builder)/loading.tsx
deleted file mode 100644
index 6e32c15e..00000000
--- a/apps/app/app/(app)/[slug]/(agent-builder)/loading.tsx
+++ /dev/null
@@ -1,24 +0,0 @@
-import { Skeleton } from "@crm/ui/components/skeleton";
-
-export default function AgentBuilderRouteLoading() {
- return (
- <main className="flex min-h-0 flex-1 flex-col" aria-busy="true">
- <header className="flex h-12 shrink-0 items-center border-b px-4 sm:px-5">
- <Skeleton className="h-4 w-40 max-w-full" />
- </header>
- <div className="min-h-0 flex-1 overflow-hidden">
- <div className="mx-auto flex w-full max-w-3xl flex-col gap-5 px-4 py-6 sm:px-5 sm:py-9">
- <Skeleton className="ms-auto h-16 w-2/3 max-w-[520px]" />
- <div className="flex max-w-[640px] flex-col gap-2">
- <Skeleton className="h-4 w-full" />
- <Skeleton className="h-4 w-11/12" />
- <Skeleton className="h-4 w-8/12" />
- </div>
- </div>
- </div>
- <span role="status" className="sr-only">
- Opening chat
- </span>
- </main>
- );
-}
diff --git a/apps/app/app/(app)/[slug]/loading.tsx b/apps/app/app/(app)/[slug]/loading.tsx
deleted file mode 100644
index cbdc12bf..00000000
--- a/apps/app/app/(app)/[slug]/loading.tsx
+++ /dev/null
@@ -1,5 +0,0 @@
-import { PageShellFallback } from "@/components/page-shell";
-
-export default function WorkspaceRouteLoading() {
- return <PageShellFallback />;
-}
diff --git a/apps/app/components/agent-builder/agent-builder-chat.tsx b/apps/app/components/agent-builder/agent-builder-chat.tsx
index 887f65c2..6bca17f7 100644
--- a/apps/app/components/agent-builder/agent-builder-chat.tsx
+++ b/apps/app/components/agent-builder/agent-builder-chat.tsx
@@ -23,7 +23,6 @@ import { Button } from "@crm/ui/components/button";
import { Icon } from "@crm/ui/components/icon";
import { Markdown } from "@crm/ui/components/markdown";
import { Reasoning } from "@crm/ui/components/reasoning";
-import { Skeleton } from "@crm/ui/components/skeleton";
import { useMountEffect } from "@crm/ui/hooks/use-mount-effect";
import { cn } from "@crm/ui/lib/utils";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
@@ -66,6 +65,7 @@ import type { RouterOutputs } from "@/lib/trpc/types";
import { useWorkspaceUrl } from "@/lib/use-workspace-url";
import { AgentCodeWorkspace } from "./agent-code-workspace";
import { AgentComposer, type BuilderPrompt } from "./agent-composer";
+import { AgentScopeBadges } from "./agent-scope-badges";
import {
ChatAttachmentChip,
ChatCommandChip,
@@ -96,8 +96,10 @@ type BuilderSubmission = {
export function AgentBuilderChat({
conversationId,
+ initialData,
}: {
conversationId: string;
+ initialData: Conversation | SharedConversation | null;
}) {
const trpc = useTRPC();
const queryClient = useQueryClient();
@@ -109,6 +111,7 @@ export function AgentBuilderChat({
const conversation = useQuery({
...trpc.conversations.builderById.queryOptions({ id: conversationId }),
enabled: !sharedChat,
+ initialData: sharedChat ? undefined : (initialData as Conversation),
refetchInterval: (query) => {
const data = query.state.data;
return data && builderConversationNeedsPolling(data) ? 2500 : false;
@@ -117,6 +120,10 @@ export function AgentBuilderChat({
const shared = useQuery({
...trpc.conversations.shared.queryOptions({ token: conversationId }),
enabled: sharedChat,
+ initialData:
+ sharedChat && initialData
+ ? (initialData as SharedConversation)
+ : undefined,
refetchInterval: (query) =>
sharedConversationNeedsPolling(query.state.data) ? 5000 : false,
});
@@ -175,23 +182,26 @@ export function AgentBuilderChat({
}),
);
- if (sharedChat && shared.isPending) {
- return <ChatLoading />;
- }
-
if (sharedChat) {
- if (shared.data) return <SharedAgentChat conversation={shared.data} />;
-
- return <ChatUnavailable shared />;
+ if (shared.isPending) {
+ return (
+ <main
+ className="flex flex-1 items-center justify-center p-8"
+ aria-busy="true"
+ >
+ <span className="text-muted-foreground text-sm">Opening chat…</span>
+ </main>
+ );
+ }
+ if (shared.isError || !shared.data) return <ChatUnavailable />;
+ return <SharedAgentChat conversation={shared.data} />;
}
- if (conversation.isPending) return <ChatLoading />;
-
- if (conversation.isError) {
+ if (conversation.isError && !conversation.data) {
return <ChatUnavailable />;
}
- const data = conversation.data;
+ const data = conversation.data ?? (initialData as Conversation);
const submissions = data.submissions as BuilderSubmission[];
const persistedEvents = (events.data ??
[]) as unknown as MessageStreamEvent[];
@@ -1064,8 +1074,7 @@ function ReviewAgentCard({
return (
<div className="flex flex-col gap-5">
<p className="max-w-[640px] text-pretty text-sm leading-5">
- I’ve drafted the agent. Review its details while it stays private to
- you.
+ Your private draft is ready to review.
</p>
<div className="overflow-hidden rounded-lg border bg-card">
<div className="border-b px-4 py-3 sm:px-5 sm:py-4">
@@ -1081,16 +1090,19 @@ function ReviewAgentCard({
<ReviewRow label="Trigger" value={manifest.trigger} />
<ReviewRow label="Looks at" value={manifest.looksAt} />
<ReviewRow label="Action" value={manifest.action} />
- <ReviewRow label="Access" value={manifest.access} />
+ <ReviewRow label="Access">
+ <AgentScopeBadges
+ scopes={manifest.access}
+ fallback="Bounded CRM read access"
+ />
+ </ReviewRow>
<p className="border-t px-4 py-2 text-pretty text-muted-foreground text-xs sm:px-5">
- The sandbox has no network access. CRM and connected data are
- available only through the listed tools, and credentials stay in the
- app runtime.
+ Runs in an isolated sandbox. CRM access is limited to the scopes
+ above, and credentials never enter the sandbox.
</p>
<div className="flex min-h-14 flex-col items-stretch gap-3 border-t px-4 py-3 sm:flex-row sm:items-center sm:justify-between sm:gap-4 sm:px-5">
<p className="text-pretty text-muted-foreground text-xs">
- Inspect this version, scope, and its listed actions before making it
- available to the team.
+ Review the draft before sharing it with your team.
</p>
<div className="sm:shrink-0">
<Button asChild>
@@ -1109,15 +1121,23 @@ function ReviewAgentCard({
);
}
-function ReviewRow({ label, value }: { label: string; value: string }) {
+function ReviewRow({
+ label,
+ value,
+ children,
+}: {
+ label: string;
+ value?: string;
+ children?: ReactNode;
+}) {
return (
<div className="flex min-h-8 flex-col items-start gap-0.5 border-b px-4 py-2 last:border-b-0 sm:flex-row sm:items-center sm:gap-4 sm:px-5 sm:py-1.5">
<span className="text-muted-foreground text-xs sm:w-[104px] sm:shrink-0">
{label}
</span>
- <span className="min-w-0 flex-1 wrap-break-word font-medium text-sm">
- {value}
- </span>
+ <div className="min-w-0 flex-1 wrap-break-word font-medium text-sm">
+ {children ?? value}
+ </div>
</div>
);
}
@@ -1286,30 +1306,7 @@ function DeployedStat({
);
}
-function ChatLoading() {
- return (
- <main className="flex min-h-0 flex-1 flex-col" aria-busy="true">
- <header className="flex h-12 shrink-0 items-center border-b px-5">
- <Skeleton className="h-4 w-40" />
- </header>
- <div className="min-h-0 flex-1 overflow-hidden">
- <div className="mx-auto flex w-full max-w-3xl flex-col gap-5 px-4 py-6 sm:px-5 sm:py-9">
- <Skeleton className="ml-auto h-16 w-2/3 max-w-[520px]" />
- <div className="flex max-w-[640px] flex-col gap-2">
- <Skeleton className="h-4 w-full" />
- <Skeleton className="h-4 w-11/12" />
- <Skeleton className="h-4 w-8/12" />
- </div>
- </div>
- </div>
- <span role="status" className="sr-only">
- Loading chat…
- </span>
- </main>
- );
-}
-
-function ChatUnavailable({ shared = false }: { shared?: boolean }) {
+function ChatUnavailable() {
const workspaceUrl = useWorkspaceUrl();
return (
@@ -1317,9 +1314,7 @@ function ChatUnavailable({ shared = false }: { shared?: boolean }) {
<div className="max-w-md text-center">
<h1 className="font-medium text-lg">Chat unavailable</h1>
<p className="mt-2 text-muted-foreground text-sm">
- {shared
- ? "This shared chat no longer exists or is not available."
- : "This chat does not exist or you do not have access to it."}
+ This chat does not exist or you do not have access to it.
</p>
<Button asChild variant="outline" className="mt-5">
<Link href={workspaceUrl("/chat")}>Start a new chat</Link>
@@ -1436,13 +1431,23 @@ function manifestOf(value: unknown) {
typeof manifest.description === "string" && manifest.description.trim()
? manifest.description.trim()
: null,
- trigger: textOf(trigger.summary, "Manual or configured schedule"),
+ trigger:
+ trigger.type === "MANUAL"
+ ? "On demand"
+ : compactSummary(trigger.summary, "On schedule"),
looksAt: textOf(dataScope.summary, "CRM records in the approved scope"),
- action: textOf(actions[0]?.summary, "Perform the requested team action"),
- access: access.length > 0 ? access.join(" · ") : "Bounded CRM read access",
+ action: compactSummary(
+ actions[0]?.summary,
+ "Perform the requested team action",
+ ),
+ access,
};
}
+function compactSummary(value: unknown, fallback: string): string {
+ return textOf(value, fallback).replace(/\s+\([^()]+\)\s*\.?$/, "");
+}
+
function recordOf(value: unknown): Record<string, unknown> {
return value && typeof value === "object" && !Array.isArray(value)
? (value as Record<string, unknown>)
diff --git a/apps/app/components/agent-builder/agent-builder-route-fallback.tsx b/apps/app/components/agent-builder/agent-builder-route-fallback.tsx
new file mode 100644
index 00000000..28ee52ca
--- /dev/null
+++ b/apps/app/components/agent-builder/agent-builder-route-fallback.tsx
@@ -0,0 +1,50 @@
+import { Skeleton } from "@crm/ui/components/skeleton";
+
+export function AgentBuilderHomeFallback() {
+ return (
+ <main
+ className="flex min-h-0 flex-1 items-center justify-center px-4"
+ aria-busy="true"
+ >
+ <div className="flex w-full max-w-2xl flex-col items-center gap-5">
+ <div
+ className="flex w-full flex-col items-center gap-2"
+ aria-hidden="true"
+ >
+ <Skeleton className="h-6 w-52 max-w-full" />
+ <Skeleton className="h-4 w-80 max-w-full" />
+ </div>
+ <Skeleton className="h-24 w-full rounded-lg" aria-hidden="true" />
+ </div>
+ <span role="status" className="sr-only">
+ Opening chat…
+ </span>
+ </main>
+ );
+}
+
+export function AgentBuilderChatFallback() {
+ return (
+ <main className="flex min-h-0 flex-1 flex-col" aria-busy="true">
+ <header className="flex h-12 shrink-0 items-center px-4 sm:px-5">
+ <Skeleton className="h-4 w-40 max-w-full" aria-hidden="true" />
+ </header>
+ <div className="min-h-0 flex-1 overflow-hidden">
+ <div
+ className="mx-auto flex w-full max-w-3xl flex-col gap-5 px-4 py-6 sm:px-5 sm:py-9"
+ aria-hidden="true"
+ >
+ <Skeleton className="ms-auto h-16 w-2/3 max-w-[520px] rounded-lg" />
+ <div className="flex max-w-[640px] flex-col gap-2">
+ <Skeleton className="h-4 w-full" />
+ <Skeleton className="h-4 w-11/12" />
+ <Skeleton className="h-4 w-8/12" />
+ </div>
+ </div>
+ </div>
+ <span role="status" className="sr-only">
+ Opening chat…
+ </span>
+ </main>
+ );
+}
diff --git a/apps/app/components/agent-builder/agent-builder-shell.tsx b/apps/app/components/agent-builder/agent-builder-shell.tsx
index ff2f2e47..d0d9a000 100644
--- a/apps/app/components/agent-builder/agent-builder-shell.tsx
+++ b/apps/app/components/agent-builder/agent-builder-shell.tsx
@@ -1,37 +1,25 @@
import { Skeleton } from "@crm/ui/components/skeleton";
-import { AgentBuilderSidebar } from "./agent-builder-sidebar";
-
-type SidebarData = React.ComponentProps<
- typeof AgentBuilderSidebar
->["initialData"];
export function AgentBuilderShell({
children,
- sidebarData,
+ sidebar,
}: {
children: React.ReactNode;
- sidebarData?: SidebarData;
+ sidebar: React.ReactNode;
}) {
return (
<div className="flex min-h-0 min-w-0 flex-1">
- {sidebarData ? (
- <AgentBuilderSidebar
- className="hidden w-[213px] flex-none border-r md:flex"
- initialData={sidebarData}
- />
- ) : (
- <AgentBuilderSidebarFallback />
- )}
+ {sidebar}
<div className="flex min-w-0 flex-1 flex-col">{children}</div>
</div>
);
}
-function AgentBuilderSidebarFallback() {
+export function AgentBuilderSidebarFallback() {
return (
<aside
- aria-busy="true"
className="hidden w-[213px] flex-none flex-col border-r p-4 md:flex"
+ aria-busy="true"
>
<div className="flex h-7 items-center pl-2 font-medium text-xs">
Chats
@@ -41,6 +29,9 @@ function AgentBuilderSidebarFallback() {
<Skeleton className="h-7 w-full" />
<Skeleton className="h-7 w-full" />
</div>
+ <span role="status" className="sr-only">
+ Loading agent navigation…
+ </span>
</aside>
);
}
diff --git a/apps/app/components/agent-builder/agent-builder-sidebar.tsx b/apps/app/components/agent-builder/agent-builder-sidebar.tsx
index 5b9dd957..b8502b4d 100644
--- a/apps/app/components/agent-builder/agent-builder-sidebar.tsx
+++ b/apps/app/components/agent-builder/agent-builder-sidebar.tsx
@@ -170,6 +170,7 @@ function TeamAgents({
<div className="mt-3 border-t pt-1">
<Link
href={workspaceUrl("/agents")}
+ transitionTypes={["nav-lateral"]}
onClick={onNavigate}
className="flex h-8 items-end gap-2 rounded-sm px-2 pb-1 font-medium text-[11px] text-muted-foreground uppercase tracking-[0.08em] outline-none hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/60"
>
diff --git a/apps/app/components/agent-builder/agent-code-workspace.tsx b/apps/app/components/agent-builder/agent-code-workspace.tsx
index 31c6bf93..5200bae6 100644
--- a/apps/app/components/agent-builder/agent-code-workspace.tsx
+++ b/apps/app/components/agent-builder/agent-code-workspace.tsx
@@ -10,8 +10,10 @@ import {
useFileTree,
useFileTreeSelection,
} from "@pierre/trees/react";
+import { useTheme } from "next-themes";
import { useState } from "react";
import { latestBuilderArtifacts } from "@/lib/agent-builder-state";
+import { useHydrated } from "@/lib/use-hydrated";
export type AgentCodeArtifact = {
id: string;
@@ -60,6 +62,8 @@ function AgentCodeWorkspaceSurface({
working: boolean;
}) {
const [mode, setMode] = useState<"code" | "changes">("code");
+ const hydrated = useHydrated();
+ const { resolvedTheme } = useTheme();
const { model } = useFileTree({
paths,
initialExpansion: "open",
@@ -77,6 +81,20 @@ function AgentCodeWorkspaceSurface({
const showChanges = mode === "changes" && previous !== null;
if (!artifact) return null;
+ if (!hydrated || (resolvedTheme !== "light" && resolvedTheme !== "dark")) {
+ return (
+ <section
+ aria-label="Generated agent files"
+ aria-busy="true"
+ className="h-[412px] overflow-hidden rounded-lg bg-muted/40"
+ >
+ <span role="status" className="sr-only">
+ Loading agent code
+ </span>
+ </section>
+ );
+ }
+ const themeType = resolvedTheme;
const file = {
name: artifact.path,
@@ -138,7 +156,7 @@ function AgentCodeWorkspaceSurface({
<FileTree
model={model}
aria-label="Agent files"
- style={{ height: "100%", width: "100%" }}
+ style={{ colorScheme: themeType, height: "100%", width: "100%" }}
/>
</div>
<div className="h-80 min-w-0 overflow-auto bg-background md:h-[360px]">
@@ -154,14 +172,14 @@ function AgentCodeWorkspaceSurface({
options={{
diffStyle: "unified",
overflow: "wrap",
- themeType: "system",
+ themeType,
}}
disableWorkerPool
/>
) : (
<File
file={file}
- options={{ overflow: "wrap", themeType: "system" }}
+ options={{ overflow: "wrap", themeType }}
disableWorkerPool
/>
)}
diff --git a/apps/app/components/agent-builder/agent-scope-badges.tsx b/apps/app/components/agent-builder/agent-scope-badges.tsx
new file mode 100644
index 00000000..ac3bf0d2
--- /dev/null
+++ b/apps/app/components/agent-builder/agent-scope-badges.tsx
@@ -0,0 +1,28 @@
+import { Badge } from "@crm/ui/components/badge";
+
+export function AgentScopeBadges({
+ scopes,
+ fallback,
+}: {
+ scopes: string[];
+ fallback: string;
+}) {
+ const uniqueScopes = [...new Set(scopes)];
+ if (uniqueScopes.length === 0) return <span>{fallback}</span>;
+
+ return (
+ <div className="flex min-w-0 flex-wrap gap-1">
+ {uniqueScopes.map((scope) => (
+ <Badge
+ key={scope}
+ variant="outline"
+ translate="no"
+ title={scope}
+ className="max-w-full rounded-sm text-ellipsis transition-colors focus-visible:ring-2"
+ >
+ {scope}
+ </Badge>
+ ))}
+ </div>
+ );
+}
diff --git a/apps/app/components/agent-builder/chat-chips.tsx b/apps/app/components/agent-builder/chat-chips.tsx
index 4286c482..8e7a1ba5 100644
--- a/apps/app/components/agent-builder/chat-chips.tsx
+++ b/apps/app/components/agent-builder/chat-chips.tsx
@@ -1,5 +1,13 @@
import Close from "@carbon/icons-react/es/Close";
import Document from "@carbon/icons-react/es/Document";
+import {
+ Attachment,
+ AttachmentAction,
+ AttachmentActions,
+ AttachmentContent,
+ AttachmentMedia,
+ AttachmentTitle,
+} from "@crm/ui/components/attachment";
import { Avatar, AvatarFallback, AvatarImage } from "@crm/ui/components/avatar";
import { type CarbonIcon, Icon } from "@crm/ui/components/icon";
import Image from "next/image";
@@ -31,8 +39,12 @@ export function ChatReferenceChip({
onRemove?: () => void;
}) {
return (
- <span className="flex min-w-0 max-w-full items-center gap-2 rounded-md border bg-background py-1 pr-2 pl-1 text-left shadow-xs">
- <ChatReferenceIdentity resource={resource} icon={icon} />
+ <span className="flex min-w-0 max-w-full items-center gap-1 rounded-sm border bg-background py-0.5 pr-1 pl-0.5 text-left">
+ <ChatReferenceIdentity
+ resource={resource}
+ icon={icon}
+ showDetail={false}
+ />
{onRemove ? (
<button
type="button"
@@ -50,9 +62,11 @@ export function ChatReferenceChip({
export function ChatReferenceIdentity({
resource,
icon,
+ showDetail = true,
}: {
resource: ChatChipResource;
icon: CarbonIcon;
+ showDetail?: boolean;
}) {
return (
<>
@@ -68,7 +82,7 @@ export function ChatReferenceIdentity({
<span className="block truncate font-medium text-xs">
{resource.label}
</span>
- {resource.detail ? (
+ {showDetail && resource.detail ? (
<span className="block truncate text-[11px] text-muted-foreground">
{resource.detail}
</span>
@@ -85,6 +99,7 @@ export function ChatAttachmentChip({
attachment: ChatChipAttachment;
onRemove?: () => void;
}) {
+ const label = `${attachment.name} · ${formatBytes(attachment.size)}`;
const image = isPreviewableImage(attachment.type)
? (attachment.previewUrl ??
(attachment.contentBase64
@@ -93,40 +108,36 @@ export function ChatAttachmentChip({
: null;
return (
- <span className="flex min-w-0 max-w-full items-center gap-2 rounded-md border bg-background py-1 pr-2 pl-1 text-left shadow-xs">
- <span className="flex size-6 shrink-0 items-center justify-center overflow-hidden rounded-sm bg-muted text-muted-foreground">
+ <Attachment size="compact" state="done">
+ <AttachmentMedia variant={image ? "image" : "icon"}>
{image ? (
<Image
src={image}
alt=""
- width={24}
- height={24}
+ width={20}
+ height={20}
unoptimized
className="size-full object-cover"
/>
) : (
- <Icon icon={Document} className="size-3.5" />
+ <Icon icon={Document} />
)}
- </span>
- <span className="min-w-0 max-w-48">
- <span className="block truncate font-medium text-xs">
- {attachment.name}
- </span>
- <span className="block text-[11px] text-muted-foreground">
- {formatBytes(attachment.size)}
- </span>
- </span>
+ </AttachmentMedia>
+ <AttachmentContent>
+ <AttachmentTitle title={label}>{label}</AttachmentTitle>
+ </AttachmentContent>
{onRemove ? (
- <button
- type="button"
- aria-label={`Remove ${attachment.name}`}
- onClick={onRemove}
- className="flex size-6 shrink-0 items-center justify-center rounded-sm text-muted-foreground outline-none hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/60"
- >
- <Icon icon={Close} className="size-3" />
- </button>
+ <AttachmentActions>
+ <AttachmentAction
+ type="button"
+ aria-label={`Remove ${attachment.name}`}
+ onClick={onRemove}
+ >
+ <Icon icon={Close} />
+ </AttachmentAction>
+ </AttachmentActions>
) : null}
- </span>
+ </Attachment>
);
}
diff --git a/apps/app/components/agent-builder/team-agent-detail.tsx b/apps/app/components/agent-builder/team-agent-detail.tsx
index 2b49b4a3..a9ca2f89 100644
--- a/apps/app/components/agent-builder/team-agent-detail.tsx
+++ b/apps/app/components/agent-builder/team-agent-detail.tsx
@@ -32,7 +32,7 @@ import { cn } from "@crm/ui/lib/utils";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import Link from "next/link";
import { useRouter } from "next/navigation";
-import { useState } from "react";
+import { type ReactNode, useState } from "react";
import { toast } from "sonner";
import {
PageShell,
@@ -46,6 +46,7 @@ import {
import { useTRPC } from "@/lib/trpc/client";
import type { RouterOutputs } from "@/lib/trpc/types";
import { useWorkspaceUrl } from "@/lib/use-workspace-url";
+import { AgentScopeBadges } from "./agent-scope-badges";
type AgentTab = "overview" | "runs" | "activity";
type AgentDetail = RouterOutputs["agents"]["byId"];
@@ -631,21 +632,26 @@ function AgentOverview({ agent }: { agent: AgentDetail }) {
/>
<DetailRow
label="Access"
- value={access.join(" · ") || "Bounded CRM read access"}
+ value={
+ <AgentScopeBadges
+ scopes={access}
+ fallback="Bounded CRM read access"
+ />
+ }
/>
</div>
);
}
-function DetailRow({ label, value }: { label: string; value: string }) {
+function DetailRow({ label, value }: { label: string; value: ReactNode }) {
return (
<div className="flex min-h-11 flex-col items-start gap-1 border-t px-4 py-3 first:border-t-0 sm:flex-row sm:items-center sm:gap-5 sm:px-5 sm:py-2">
<span className="text-muted-foreground text-xs sm:w-36 sm:shrink-0">
{label}
</span>
- <span className="min-w-0 max-w-full flex-1 wrap-break-word text-sm">
+ <div className="min-w-0 max-w-full flex-1 wrap-break-word text-sm">
{value}
- </span>
+ </div>
</div>
);
}
diff --git a/apps/app/components/agent-builder/team-agents-index.tsx b/apps/app/components/agent-builder/team-agents-index.tsx
index ac9572e9..4d4b5bf5 100644
--- a/apps/app/components/agent-builder/team-agents-index.tsx
+++ b/apps/app/components/agent-builder/team-agents-index.tsx
@@ -3,7 +3,6 @@
import ArrowRight from "@carbon/icons-react/es/ArrowRight";
import Bot from "@carbon/icons-react/es/Bot";
import { Icon } from "@crm/ui/components/icon";
-import { Skeleton } from "@crm/ui/components/skeleton";
import { useQuery } from "@tanstack/react-query";
import Link from "next/link";
import { useTRPC } from "@/lib/trpc/client";
@@ -19,13 +18,11 @@ export function TeamAgentsIndex({ initialAgents }: { initialAgents: Agents }) {
...trpc.agents.list.queryOptions(),
initialData: initialAgents,
});
- const rows = agents.data;
+ const rows = agents.data ?? initialAgents;
return (
<>
- {rows === undefined ? (
- <AgentListFallback />
- ) : rows.length ? (
+ {rows.length ? (
<div className="overflow-hidden rounded-lg border bg-card">
{rows.map((agent) => (
<Link
@@ -82,30 +79,3 @@ export function TeamAgentsIndex({ initialAgents }: { initialAgents: Agents }) {
</>
);
}
-
-function AgentListFallback() {
- return (
- <>
- <div
- className="overflow-hidden rounded-lg border bg-card"
- aria-hidden="true"
- >
- {[0, 1].map((row) => (
- <div
- key={row}
- className="flex min-h-16 items-center gap-4 border-t px-4 py-3 first:border-t-0 sm:px-5"
- >
- <Skeleton className="size-8 shrink-0 rounded-md" />
- <span className="min-w-0 flex-1 space-y-2">
- <Skeleton className="h-3 w-32 max-w-full" />
- <Skeleton className="h-2.5 w-full max-w-96" />
- </span>
- </div>
- ))}
- </div>
- <span role="status" className="sr-only">
- Loading team agents
- </span>
- </>
- );
-}
diff --git a/apps/app/components/app-header.tsx b/apps/app/components/app-header.tsx
index c74f7d75..b2762247 100644
--- a/apps/app/components/app-header.tsx
+++ b/apps/app/components/app-header.tsx
@@ -76,7 +76,10 @@ export function AppHeader({ user }: { user: User }) {
export function AppHeaderFallback() {
return (
- <header className="flex h-12 shrink-0 items-center gap-2 border-b px-3 [view-transition-name:app-header]">
+ <header
+ className="flex h-12 shrink-0 items-center gap-2 border-b px-3 [view-transition-name:app-header]"
+ aria-busy="true"
+ >
<div className="flex shrink-0 items-center gap-1">
<span className="hidden size-8 items-center justify-center text-foreground md:flex">
<Logo className="size-5" />
@@ -90,6 +93,9 @@ export function AppHeaderFallback() {
<AvatarFallback />
</Avatar>
</div>
+ <span role="status" className="sr-only">
+ Loading workspace header…
+ </span>
</header>
);
}
diff --git a/apps/app/components/page-shell.tsx b/apps/app/components/page-shell.tsx
index 8cd82710..d4090654 100644
--- a/apps/app/components/page-shell.tsx
+++ b/apps/app/components/page-shell.tsx
@@ -133,26 +133,19 @@ function PageShellLoading() {
function PageShellFallback() {
return (
<PageShell aria-busy="true">
- <div className="flex flex-col gap-3" aria-hidden="true">
- <Skeleton className="h-8 w-48 max-w-full" />
- <Skeleton className="h-4 w-72 max-w-full" />
- </div>
- <div className="overflow-hidden rounded-lg border">
- {[0, 1, 2, 3, 4].map((row) => (
- <div
- key={row}
- className="flex min-h-14 items-center gap-4 border-t px-4 first:border-t-0 sm:px-5"
- >
- <Skeleton className="size-7 shrink-0 rounded-md" />
- <div className="min-w-0 flex-1 space-y-2">
- <Skeleton className="h-3 w-40 max-w-full" />
- <Skeleton className="h-2.5 w-64 max-w-full" />
- </div>
- </div>
- ))}
+ <div className="flex flex-col gap-6" aria-hidden="true">
+ <div className="flex flex-col gap-3">
+ <Skeleton className="h-8 w-48 max-w-full" />
+ <Skeleton className="h-4 w-72 max-w-full" />
+ </div>
+ <div className="flex flex-col gap-3">
+ <Skeleton className="h-14 w-full rounded-lg" />
+ <Skeleton className="h-14 w-full rounded-lg" />
+ <Skeleton className="h-40 w-full rounded-lg" />
+ </div>
</div>
<span role="status" className="sr-only">
- Loading page
+ Loading page…
</span>
</PageShell>
);
diff --git a/packages/ui/src/components/attachment.tsx b/packages/ui/src/components/attachment.tsx
index b3bb6fdd..ca592560 100644
--- a/packages/ui/src/components/attachment.tsx
+++ b/packages/ui/src/components/attachment.tsx
@@ -14,12 +14,21 @@ const attachmentVariants = cva(
"gap-2 text-xs has-data-[slot=attachment-content]:px-2.5 has-data-[slot=attachment-content]:py-2 has-data-[slot=attachment-media]:p-2",
sm: "gap-2.5 text-xs has-data-[slot=attachment-content]:px-2 has-data-[slot=attachment-content]:py-1.5 has-data-[slot=attachment-media]:p-1.5",
xs: "gap-1.5 rounded-sm text-xs has-data-[slot=attachment-content]:px-1.5 has-data-[slot=attachment-content]:py-1 has-data-[slot=attachment-media]:p-1",
+ compact:
+ "gap-1 rounded-sm text-xs has-data-[slot=attachment-content]:px-1.5 has-data-[slot=attachment-content]:py-0.5 has-data-[slot=attachment-media]:p-0.5",
},
orientation: {
horizontal: "min-w-40 items-center",
vertical: "w-24 flex-col has-data-[slot=attachment-content]:w-30",
},
},
+ compoundVariants: [
+ {
+ size: "compact",
+ orientation: "horizontal",
+ className: "min-w-0",
+ },
+ ],
}
)
@@ -46,7 +55,7 @@ function Attachment({
}
const attachmentMediaVariants = cva(
- "relative flex aspect-square w-10 shrink-0 items-center justify-center overflow-hidden rounded-none bg-muted text-foreground group-data-[orientation=vertical]/attachment:w-full group-data-[size=sm]/attachment:w-8 group-data-[size=xs]/attachment:w-7 group-data-[size=xs]/attachment:rounded-none group-data-[state=error]/attachment:bg-destructive/10 group-data-[state=error]/attachment:text-destructive group-data-[orientation=vertical]/attachment:*:data-[slot=spinner]:size-6! [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 group-data-[orientation=vertical]/attachment:[&_svg:not([class*='size-'])]:size-6 group-data-[size=xs]/attachment:[&_svg:not([class*='size-'])]:size-3.5",
+ "relative flex aspect-square w-10 shrink-0 items-center justify-center overflow-hidden rounded-none bg-muted text-foreground group-data-[orientation=vertical]/attachment:w-full group-data-[size=sm]/attachment:w-8 group-data-[size=xs]/attachment:w-7 group-data-[size=compact]/attachment:w-5 group-data-[size=xs]/attachment:rounded-none group-data-[size=compact]/attachment:rounded-none group-data-[state=error]/attachment:bg-destructive/10 group-data-[state=error]/attachment:text-destructive group-data-[orientation=vertical]/attachment:*:data-[slot=spinner]:size-6! [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 group-data-[orientation=vertical]/attachment:[&_svg:not([class*='size-'])]:size-6 group-data-[size=xs]/attachment:[&_svg:not([class*='size-'])]:size-3.5 group-data-[size=compact]/attachment:[&_svg:not([class*='size-'])]:size-3",
{
variants: {
variant: {
diff --git a/packages/ui/src/components/dashboard.tsx b/packages/ui/src/components/dashboard.tsx
index 48eac58a..bb6b714f 100644
--- a/packages/ui/src/components/dashboard.tsx
+++ b/packages/ui/src/components/dashboard.tsx
@@ -1,4 +1,3 @@
-import { Skeleton } from "@crm/ui/components/skeleton";
import { cn } from "@crm/ui/lib/utils";
import type * as React from "react";
@@ -176,48 +175,11 @@ function DashboardSection({
);
}
-function DashboardSkeleton({
- stats = 4,
- className,
-}: {
- stats?: number;
- className?: string;
-}) {
- return (
- <div
- data-slot="dashboard-skeleton"
- className={cn("flex flex-col gap-6", className)}
- aria-hidden
- >
- <StatGroup>
- {Array.from({ length: stats }).map((_, i) => (
- <div key={i} className="flex flex-col gap-3 p-4 md:p-6">
- <Skeleton className="h-4 w-24" />
- <Skeleton className="h-8 w-16" />
- <Skeleton className="h-3 w-28" />
- </div>
- ))}
- </StatGroup>
- <DashboardRow>
- <div className="flex flex-col gap-4 border p-5 md:p-6">
- <Skeleton className="h-4 w-40" />
- <Skeleton className="h-[200px] w-full" />
- </div>
- <div className="flex flex-col items-center gap-4 border p-5 md:p-6">
- <Skeleton className="h-4 w-32 self-start" />
- <Skeleton className="size-[200px] rounded-full" />
- </div>
- </DashboardRow>
- </div>
- );
-}
-
export {
ChartCard,
DashboardGrid,
DashboardRow,
DashboardSection,
- DashboardSkeleton,
KpiCard,
StatGroup,
};
diff --git a/packages/ui/src/components/skeleton.tsx b/packages/ui/src/components/skeleton.tsx
index 03bdb55d..1d5a1820 100644
--- a/packages/ui/src/components/skeleton.tsx
+++ b/packages/ui/src/components/skeleton.tsx
@@ -4,7 +4,10 @@ function Skeleton({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="skeleton"
- className={cn("animate-pulse rounded-sm bg-muted", className)}
+ className={cn(
+ "animate-pulse rounded-sm bg-muted motion-reduce:animate-none",
+ className,
+ )}
{...props}
/>
);