Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 | 2x 10x 10x 10x 2x 2x 2x 2x 2x 2x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 5x 10x 5x 10x 5x 10x 10x 10x 3x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 2x 1x 1x 1x | import { OriginBadge } from "@/components/owner";
import BuiltInBadge from "@/components/badge/BuiltInBadge";
import GeneratedMark from "@/components/badge/GeneratedMark";
import { SectionHeading } from "@/components/collection";
import BoardSettings, {
BoardSettingsValues,
} from "@/components/dashboard/BoardSettings";
import { boardIcon as iconFor } from "@/components/appearance/icons";
import GenerateDashboard from "@/components/dashboard/GenerateDashboard";
import { toneOf, TONES } from "@/components/appearance/tones";
import MainPage from "@/components/page/MainPage/MainPage";
import { Agent } from "@/objects/Agent";
import {
CreateDashboardBody,
Dashboard,
GenerationProposal,
WidgetTarget,
} from "@/objects/Dashboard";
import { isSystemManaged } from "@/objects/Doc";
import { Model } from "@/objects/Model";
import { APP_ROUTES, ROUTE_PARAMS } from "@/routes/const";
import { INCLUDE_SYSTEM, QUERY_KEYS } from "@/services/query_keys";
import { useApiHandler } from "@/services/useApiHandler";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import {
Home,
LayoutGrid,
Loader2,
Pencil,
Plus,
Wand2,
X,
} from "lucide-react";
import React from "react";
import { Link, useNavigate } from "react-router-dom";
import {
buildTemplateBody,
DashboardTemplate,
TEMPLATES,
} from "./dashboards/templates";
/** Pick something for a template's dynamic widgets to run on.
*
* Prefers one of the user's own agents — it brings their tools, knowledge and
* rules — and falls back to any available chat model. Returns null when the
* account has neither, in which case the template seeds only its static
* tiles rather than failing.
*/
const resolveTarget = (
agents: Agent[],
models: Model[],
): WidgetTarget | null => {
Iif (agents.length > 0) return { type: "agent", agent_id: agents[0].id };
const model = models.find((m) => m.is_chat && m.is_available);
return model ? { type: "model", model_id: model.id } : null;
};
// ─── Create modal ─────────────────────────────────────────────────────────────
interface CreateModalProps {
creating: boolean;
error: string | null;
targetAvailable: boolean;
onCancel: () => void;
onCreate: (
template: DashboardTemplate,
name: string,
) => void;
}
const CreateModal: React.FC<CreateModalProps> = ({
creating,
error,
targetAvailable,
onCancel,
onCreate,
}) => {
const [selected, setSelected] = React.useState<DashboardTemplate>(
TEMPLATES[0],
);
const [name, setName] = React.useState("");
// The name defaults to the template's, so picking one and pressing create
// is a complete flow.
const effectiveName = name.trim() || selected.name;
return (
<div
className="fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4"
onClick={onCancel}
>
<div
className="w-full max-w-xl max-h-[85vh] flex flex-col rounded-xl bg-white dark:bg-gray-800 shadow-xl"
onClick={(e) => e.stopPropagation()}
>
<div className="flex items-center justify-between px-4 py-3 border-b border-gray-100 dark:border-gray-700">
<h3 className="text-sm font-semibold text-gray-900 dark:text-white">
New dashboard
</h3>
<button
type="button"
onClick={onCancel}
className="rounded-lg p-1 text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700"
>
<X className="w-4 h-4" />
</button>
</div>
<div className="flex-1 overflow-auto px-4 py-3">
<p className="mb-1 text-xs font-medium text-gray-700 dark:text-gray-200">
Start from
</p>
{/* The fleet, governance, knowledge and usage boards used to be
templates here; they are built in now, and a copy is how a user
starts from one. */}
<p className="mb-2 text-[11px] text-gray-500 dark:text-gray-400">
For your agent fleet, governance, knowledge or spend, open the
built-in board and copy it.
</p>
<div className="grid gap-2 sm:grid-cols-2 mb-4">
{TEMPLATES.map((template) => {
const Icon = iconFor(template.icon);
const tone = TONES[toneOf(template.accent)];
const active = selected.key === template.key;
return (
<button
key={template.key}
type="button"
onClick={() => setSelected(template)}
className={`flex items-start gap-2.5 rounded-lg border p-2.5 text-left transition-colors ${
active
? "border-blue-500 bg-blue-50/60 dark:bg-blue-900/20"
: "border-gray-200 dark:border-gray-700 hover:bg-gray-50 dark:hover:bg-gray-700/40"
}`}
>
<span className={`shrink-0 rounded-lg p-1.5 ${tone.bg}`}>
<Icon className={`w-4 h-4 ${tone.fg}`} />
</span>
<span className="min-w-0">
<span className="block text-xs font-medium text-gray-900 dark:text-white">
{template.name}
</span>
<span className="block text-[11px] leading-snug text-gray-500 dark:text-gray-400">
{template.description}
</span>
</span>
</button>
);
})}
</div>
<p className="mb-1 text-xs font-medium text-gray-700 dark:text-gray-200">
Name
</p>
<input
className="w-full rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-900 px-2.5 py-1.5 text-xs text-gray-900 dark:text-gray-100 focus:outline-none focus:ring-2 focus:ring-blue-500/40"
placeholder={selected.name}
value={name}
onChange={(e) => setName(e.target.value)}
/>
{selected.needsTarget && !targetAvailable && (
<p className="mt-3 rounded-lg bg-amber-50 dark:bg-amber-900/20 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300">
This template's live tiles need an agent or a chat model, and you
have neither yet. The board will be created with its static
widgets only — add the live ones once you have an agent.
</p>
)}
{error && (
<p className="mt-3 rounded-lg bg-red-50 dark:bg-red-900/20 px-3 py-2 text-[11px] text-red-600 dark:text-red-400">
{error}
</p>
)}
</div>
<div className="flex justify-end gap-2 px-4 py-3 border-t border-gray-100 dark:border-gray-700">
<button
type="button"
onClick={onCancel}
className="rounded-lg px-3 py-1.5 text-xs font-medium text-gray-600 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-700"
>
Cancel
</button>
<button
type="button"
disabled={creating}
onClick={() => onCreate(selected, effectiveName)}
className="rounded-lg bg-gray-900 dark:bg-white px-3 py-1.5 text-xs font-medium text-white dark:text-gray-900 hover:opacity-80 disabled:opacity-50 transition-opacity"
>
{creating ? "Creating…" : "Create dashboard"}
</button>
</div>
</div>
</div>
);
};
// ─── Built-in board card ──────────────────────────────────────────────────────
/** A board CHAIN-R maintains. No rename: the API refuses it, and the board's
* page offers a copy instead. */
const BuiltInBoardCard: React.FC<{ board: Dashboard }> = ({ board }) => {
const Icon = iconFor(board.icon);
const tone = TONES[toneOf(board.accent)];
return (
<Link
to={APP_ROUTES.USER.DASHBOARDS.id.replace(
ROUTE_PARAMS.DASHBOARD.id,
board.id,
)}
className="group rounded-xl border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 p-4 hover:border-gray-300 dark:hover:border-gray-600 hover:shadow-sm transition-all"
>
<div className="flex items-start justify-between gap-2">
<span className={`rounded-lg p-2 ${tone.bg}`}>
<Icon className={`w-4 h-4 ${tone.fg}`} />
</span>
<BuiltInBadge size="sm" />
</div>
<p className="mt-3 text-sm font-semibold text-gray-900 dark:text-white truncate">
{board.name}
</p>
{board.description && (
<p className="mt-0.5 text-xs leading-snug text-gray-500 dark:text-gray-400 line-clamp-2">
{board.description}
</p>
)}
<p className="mt-3 text-[11px] text-gray-400 dark:text-gray-500">
{board.widget_count}{" "}
{board.widget_count === 1 ? "widget" : "widgets"}
</p>
</Link>
);
};
// ─── Gallery ──────────────────────────────────────────────────────────────────
const Dashboards: React.FC = () => {
const { getApiHandler } = useApiHandler();
const queryClient = useQueryClient();
const navigate = useNavigate();
const [creating, setCreating] = React.useState(false);
const [createError, setCreateError] = React.useState<string | null>(null);
const [renaming, setRenaming] = React.useState<Dashboard | null>(null);
const [renameError, setRenameError] = React.useState<string | null>(null);
const [designing, setDesigning] = React.useState(false);
const [proposal, setProposal] = React.useState<GenerationProposal | null>(null);
const [designError, setDesignError] = React.useState<string | null>(null);
// The built-in boards come with the user's own and are split out below;
// the Overview counts the user's boards from the plain listing.
const boardsQuery = useQuery({
queryKey: [QUERY_KEYS.GET.DASHBOARDS, INCLUDE_SYSTEM],
queryFn: () =>
getApiHandler().dashboard_router.list({ includeSystem: true }),
});
const agentsQuery = useQuery({
queryKey: [QUERY_KEYS.GET.AGENTS],
queryFn: () => getApiHandler().agent_router.list(),
});
const modelsQuery = useQuery({
queryKey: [QUERY_KEYS.GET.MODELS],
queryFn: () => getApiHandler().model_router.list(),
});
const { boards, builtIn } = React.useMemo(() => {
const rows: Dashboard[] = (boardsQuery.data as Dashboard[]) ?? [];
return {
boards: rows.filter((board) => !isSystemManaged(board)),
builtIn: rows.filter(isSystemManaged),
};
}, [boardsQuery.data]);
const agents: Agent[] = (agentsQuery.data as Agent[] | null) ?? [];
const models: Model[] = (modelsQuery.data as Model[] | null) ?? [];
const target = resolveTarget(agents, models);
const readDetail = (error: unknown, fallback: string): string => {
const detail = (error as { response?: { data?: { detail?: unknown } } })
?.response?.data?.detail;
return typeof detail === "string" ? detail : fallback;
};
const generate = useMutation({
mutationFn: (description: string) =>
getApiHandler().dashboard_router.generate(description),
onSuccess: (result) => {
setProposal(result);
setDesignError(null);
},
onError: (error) => {
setProposal(null);
setDesignError(
readDetail(
error,
"Could not design that dashboard. Try describing it differently.",
),
);
},
});
// A reviewed proposal is created through the ordinary create endpoint —
// generated and hand-built boards take exactly the same path.
const createFromProposal = useMutation({
mutationFn: (body: CreateDashboardBody) =>
getApiHandler().dashboard_router.create(body),
onSuccess: (board) => {
queryClient.invalidateQueries({ queryKey: [QUERY_KEYS.GET.DASHBOARDS] });
setDesigning(false);
setProposal(null);
if (board) {
navigate(
APP_ROUTES.USER.DASHBOARDS.id.replace(
ROUTE_PARAMS.DASHBOARD.id,
board.id,
),
);
}
},
onError: (error) =>
setDesignError(readDetail(error, "Could not create that dashboard.")),
});
const rename = useMutation({
mutationFn: ({
id,
values,
}: {
id: string;
values: BoardSettingsValues;
}) => getApiHandler().dashboard_router.update(id, values),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: [QUERY_KEYS.GET.DASHBOARDS] });
setRenaming(null);
setRenameError(null);
},
onError: (error) => {
const detail = (error as { response?: { data?: { detail?: unknown } } })
?.response?.data?.detail;
setRenameError(
typeof detail === "string" ? detail : "Could not rename that dashboard.",
);
},
});
const removeBoard = useMutation({
mutationFn: (id: string) => getApiHandler().dashboard_router.delete(id),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: [QUERY_KEYS.GET.DASHBOARDS] });
setRenaming(null);
},
});
const create = useMutation({
mutationFn: ({
template,
name,
}: {
template: DashboardTemplate;
name: string;
}) =>
// Made in the workspace this page shows (svc-core puts it there).
getApiHandler().dashboard_router.create(
buildTemplateBody(template, name, target) as CreateDashboardBody,
),
onSuccess: (board) => {
queryClient.invalidateQueries({ queryKey: [QUERY_KEYS.GET.DASHBOARDS] });
setCreating(false);
if (board) {
navigate(
APP_ROUTES.USER.DASHBOARDS.id.replace(
ROUTE_PARAMS.DASHBOARD.id,
board.id,
),
);
}
},
onError: (error) => {
const detail = (error as { response?: { data?: { detail?: unknown } } })
?.response?.data?.detail;
// The API returns an actionable message for name collisions and other
// conflicts; fall back only when it did not.
setCreateError(
typeof detail === "string"
? detail
: "Could not create that dashboard. Please try again.",
);
},
});
return (
<MainPage title="Dashboards">
<p className="-mt-4 mb-5 text-sm text-gray-500 dark:text-gray-400">
The built-in boards show your own activity from day one. Compose your
own to pin answers worth keeping, watch your usage, and set agents
running on a schedule so a board is current before you open it.
</p>
<div className="mb-5 flex flex-wrap items-center gap-2">
<button
type="button"
onClick={() => {
setDesignError(null);
setProposal(null);
setDesigning(true);
}}
className="inline-flex items-center gap-1.5 rounded-lg bg-gray-900 dark:bg-white px-3 py-1.5 text-xs font-medium text-white dark:text-gray-900 hover:opacity-80 transition-opacity"
>
<Wand2 className="w-3.5 h-3.5" /> Describe a dashboard
</button>
<button
type="button"
onClick={() => {
setCreateError(null);
setCreating(true);
}}
className="inline-flex items-center gap-1.5 rounded-lg border border-gray-200 dark:border-gray-700 px-3 py-1.5 text-xs font-medium text-gray-600 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700/50 transition-colors"
>
<Plus className="w-3.5 h-3.5" /> Start from a template
</button>
</div>
{builtIn.length > 0 && (
<section className="mb-8">
<SectionHeading
label="Built-in"
count={builtIn.length}
action={
<span className="text-xs text-gray-500 dark:text-gray-400">
Ready to use, and never show anyone else's data
</span>
}
/>
<div className="grid gap-3 sm:grid-cols-2 lg:grid-cols-3">
{builtIn.map((board) => (
<BuiltInBoardCard key={board.id} board={board} />
))}
</div>
</section>
)}
{builtIn.length > 0 && (
<SectionHeading label="Your dashboards" count={boards.length} />
)}
{boardsQuery.isLoading ? (
<div className="flex items-center gap-2 text-sm text-gray-400">
<Loader2 className="w-4 h-4 animate-spin" /> Loading dashboards…
</div>
) : boards.length === 0 ? (
<div className="rounded-xl border border-dashed border-gray-300 dark:border-gray-700 py-16 text-center">
<LayoutGrid className="mx-auto w-8 h-8 text-gray-300 dark:text-gray-600" />
<p className="mt-3 text-sm font-medium text-gray-700 dark:text-gray-200">
No dashboards of your own yet
</p>
<p className="mt-1 text-xs text-gray-500 dark:text-gray-400">
{builtIn.length > 0
? "The built-in boards are ready now. Copy one to change it, describe what you want to watch, or start from a template."
: "Describe what you want to watch and one will be designed for you, or start from a template."}
</p>
</div>
) : (
<div className="grid gap-3 sm:grid-cols-2 lg:grid-cols-3">
{boards.map((board) => {
const Icon = iconFor(board.icon);
const tone = TONES[toneOf(board.accent)];
return (
<Link
key={board.id}
to={APP_ROUTES.USER.DASHBOARDS.id.replace(
ROUTE_PARAMS.DASHBOARD.id,
board.id,
)}
className="group rounded-xl border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 p-4 hover:border-gray-300 dark:hover:border-gray-600 hover:shadow-sm transition-all"
>
<div className="flex items-start justify-between gap-2">
<GeneratedMark
generated={board.is_ai_generated}
size="sm"
label="AI generated dashboard"
>
<span className={`rounded-lg p-2 ${tone.bg}`}>
<Icon className={`w-4 h-4 ${tone.fg}`} />
</span>
</GeneratedMark>
<span className="flex items-center gap-1">
{board.is_home && (
<span className="inline-flex items-center gap-1 rounded-full bg-gray-100 dark:bg-gray-700 px-2 py-0.5 text-[10px] font-medium text-gray-600 dark:text-gray-300">
<Home className="w-2.5 h-2.5" /> Home
</span>
)}
<button
type="button"
title="Rename"
onClick={(e) => {
// The card is a Link; renaming must not navigate.
e.preventDefault();
e.stopPropagation();
setRenameError(null);
setRenaming(board);
}}
className="rounded-lg p-1 text-gray-300 opacity-0 group-hover:opacity-100 hover:text-gray-600 dark:text-gray-600 dark:hover:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-700 transition-all"
>
<Pencil className="w-3 h-3" />
</button>
</span>
</div>
<p className="mt-3 text-sm font-semibold text-gray-900 dark:text-white truncate">
{board.name}
</p>
<OriginBadge resource={board} className="mt-1" />
{board.description && (
<p className="mt-0.5 text-xs leading-snug text-gray-500 dark:text-gray-400 line-clamp-2">
{board.description}
</p>
)}
<p className="mt-3 text-[11px] text-gray-400 dark:text-gray-500">
{board.widget_count}{" "}
{board.widget_count === 1 ? "widget" : "widgets"}
</p>
</Link>
);
})}
</div>
)}
{designing && (
<GenerateDashboard
generating={generate.isPending}
creating={createFromProposal.isPending}
proposal={proposal}
error={designError}
onCancel={() => {
setDesigning(false);
setProposal(null);
}}
onGenerate={(description) => {
setDesignError(null);
generate.mutate(description);
}}
onCreate={(body) => {
setDesignError(null);
createFromProposal.mutate(body);
}}
/>
)}
{renaming && (
<BoardSettings
board={renaming}
saving={rename.isPending}
error={renameError}
onCancel={() => setRenaming(null)}
onSave={(values) => rename.mutate({ id: renaming.id, values })}
onDelete={() => removeBoard.mutate(renaming.id)}
/>
)}
{creating && (
<CreateModal
creating={create.isPending}
error={createError}
targetAvailable={target !== null}
onCancel={() => setCreating(false)}
onCreate={(template, name) => {
setCreateError(null);
create.mutate({ template, name });
}}
/>
)}
</MainPage>
);
};
export default Dashboards;
|