Open-source status page, incident response and uptime monitoring
TypeScript alertingincident-managementmcpmcp-servermonitoringmonitoring-as-codeobservabilityon-callopen-sourcesrestatus-pagestatuspagesynthetic-monitoringterraformtinybirdtursouptimeuptime-checkeruptime-monitor
feat(dashboard): show entity ids as hover-card references (#2929)
Maximilian Kaske6f07e2ffeeb1
diff --git a/apps/dashboard/AGENTS.md b/apps/dashboard/AGENTS.mdindex 8d55adcae..c3c6b78ff 100644--- a/apps/dashboard/AGENTS.md+++ b/apps/dashboard/AGENTS.md@@ -41,6 +41,14 @@ part into a sibling file. `import type` from the barrel is fine; types erase.Reuse the dashboard's own primitives — `TableCell*`, `ResultTable`,`ChangesTable`. Do not build bespoke chrome for a tool result.+Mapped entity ids render as `EntityRef` (hover card per entity); unmapped ids+such as `commanderId` stay text. `ChangesTable` resolves them+by field name and the audit log by `entityType`, both through `entityKinds` in+`src/data/entity-refs.client.ts`. A new entity is one entry there plus one card+in `src/components/common/entity-ref/cards/`; the `cards` map fails typecheck+without it. In read-tool tables, swap the foreign-key cell for `EntityRef`+yourself and build links with `entityKinds.<kind>.href`.+Persisted chat messages are validated on write, which is what makes the`asUIMessages` cast in `apps/dashboard/src/components/chat/use-chat-session.ts`safe. Keep casts of that kind in one named helper.diff --git a/apps/dashboard/src/components/chat/chat-tool-part.tsx b/apps/dashboard/src/components/chat/chat-tool-part.tsxindex 74ba4173b..10505333f 100644--- a/apps/dashboard/src/components/chat/chat-tool-part.tsx+++ b/apps/dashboard/src/components/chat/chat-tool-part.tsx@@ -73,6 +73,8 @@ function ApprovalCard({}, []);const onKeyDown = (e: KeyboardEvent<HTMLDivElement>) => {+ // An open popover (e.g. an entity hover card) already handled this key.+ if (e.defaultPrevented) return;if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) {e.preventDefault();confirmTool(approvalId);diff --git a/apps/dashboard/src/components/chat/tool-renderers/add-status-report-update.tsx b/apps/dashboard/src/components/chat/tool-renderers/add-status-report-update.tsxindex 586fe8808..273de07ee 100644--- a/apps/dashboard/src/components/chat/tool-renderers/add-status-report-update.tsx+++ b/apps/dashboard/src/components/chat/tool-renderers/add-status-report-update.tsx@@ -1,5 +1,4 @@import type { AgentToolInput } from "@openstatus/services/agent-tools";-import { formatComponentImpacts } from "@openstatus/services/status-report/utils";import type { ChangeRow } from "@/components/common/changes-table";@@ -26,7 +25,7 @@ export function addStatusReportUpdateChanges(if (input.componentImpacts?.length) {changes.push({field: "componentImpacts",- after: formatComponentImpacts(input.componentImpacts),+ after: input.componentImpacts,});}if (input.date) {diff --git a/apps/dashboard/src/components/chat/tool-renderers/create-status-report.tsx b/apps/dashboard/src/components/chat/tool-renderers/create-status-report.tsxindex 6cc118d4b..13521c422 100644--- a/apps/dashboard/src/components/chat/tool-renderers/create-status-report.tsx+++ b/apps/dashboard/src/components/chat/tool-renderers/create-status-report.tsx@@ -1,5 +1,4 @@import type { AgentToolInput } from "@openstatus/services/agent-tools";-import { formatComponentImpacts } from "@openstatus/services/status-report/utils";import type { ChangeRow } from "@/components/common/changes-table";@@ -40,7 +39,7 @@ export function createStatusReportChanges(if (input.componentImpacts?.length) {changes.push({field: "componentImpacts",- after: formatComponentImpacts(input.componentImpacts),+ after: input.componentImpacts,});}diff --git a/apps/dashboard/src/components/chat/tool-renderers/details.test.tsx b/apps/dashboard/src/components/chat/tool-renderers/details.test.tsxindex de58fc7bc..0605463ff 100644--- a/apps/dashboard/src/components/chat/tool-renderers/details.test.tsx+++ b/apps/dashboard/src/components/chat/tool-renderers/details.test.tsx@@ -48,7 +48,7 @@ describe("getMonitorDetails", () => {followRedirects: true,public: false,tags: [{ name: "prod" }, { name: "api" }],- notifications: [{ name: "Ops", provider: "slack" }],+ notifications: [{ id: 3, name: "Ops", provider: "slack" }],privateLocationIds: [7, 8],};const input = asFixture<Input>({ id: 1 });@@ -65,8 +65,19 @@ describe("getMonitorDetails", () => {expect(value(data, "Regions")).toBe("ams, iad");expect(value(data, "Degraded after")).toBe("3000ms");expect(value(data, "Tags")).toBe("prod, api");- expect(value(data, "Notifications")).toBe("Ops (slack)");- expect(value(data, "IDs")).toBe("7, 8");+ expect(value(data, "Notifications")).toBe("Ops");+ const notifications = data.sections+ .flatMap((s) => s.rows)+ .find((r) => r.label === "Notifications");+ expect(renderToStaticMarkup(<>{notifications?.value}</>)).toContain(+ 'data-slot="entity-ref"',+ );+ const ids = data.sections+ .flatMap((s) => s.rows)+ .find((r) => r.label === "IDs");+ const markup = renderToStaticMarkup(<>{ids?.value}</>);+ expect(markup).toContain('aria-label="Private location 7"');+ expect(markup).toContain('aria-label="Private location 8"');});it("drops optional rows and sections when absent", () => {diff --git a/apps/dashboard/src/components/chat/tool-renderers/get-monitor-summary.tsx b/apps/dashboard/src/components/chat/tool-renderers/get-monitor-summary.tsxindex 597bbe6c2..1e1fbebcf 100644--- a/apps/dashboard/src/components/chat/tool-renderers/get-monitor-summary.tsx+++ b/apps/dashboard/src/components/chat/tool-renderers/get-monitor-summary.tsx@@ -3,6 +3,7 @@ import type {AgentToolOutput,} from "@openstatus/services/agent-tools";+import { EntityRef } from "@/components/common/entity-ref/entity-ref";import { TableCellDate } from "@/components/data-table/table-cell-date";import { TableCellNumber } from "@/components/data-table/table-cell-number";import { TableCellText } from "@/components/data-table/table-cell-text";@@ -24,7 +25,7 @@ export function getMonitorSummaryDetails(rows: [{label: "ID",- value: <TableCellNumber value={output.monitorId} />,+ value: <EntityRef kind="monitor" id={output.monitorId} />,},{ label: "Window", value: <TableCellText value={input.timeRange} /> },{diff --git a/apps/dashboard/src/components/chat/tool-renderers/get-monitor.tsx b/apps/dashboard/src/components/chat/tool-renderers/get-monitor.tsxindex 4e5846154..9abbc8c84 100644--- a/apps/dashboard/src/components/chat/tool-renderers/get-monitor.tsx+++ b/apps/dashboard/src/components/chat/tool-renderers/get-monitor.tsx@@ -3,6 +3,7 @@ import type {AgentToolOutput,} from "@openstatus/services/agent-tools";+import { EntityRefList } from "@/components/common/entity-ref/entity-ref";import { TableCellBoolean } from "@/components/data-table/table-cell-boolean";import { TableCellNumber } from "@/components/data-table/table-cell-number";import { TableCellText } from "@/components/data-table/table-cell-text";@@ -78,12 +79,13 @@ export function getMonitorDetails(},{label: "Notifications",- value: (- <TableCellText- value={output.notifications- .map((n) => `${n.name} (${n.provider})`)- .join(", ")}+ value: output.notifications.length ? (+ <EntityRefList+ kind="notification"+ refs={output.notifications.map((n) => ({ id: n.id, label: n.name }))}/>+ ) : (+ <TableCellText value={null} empty="None" />),},];@@ -99,7 +101,12 @@ export function getMonitorDetails(rows: [{label: "IDs",- value: <TableCellText value={output.privateLocationIds.join(", ")} />,+ value: (+ <EntityRefList+ kind="privateLocation"+ refs={output.privateLocationIds}+ />+ ),},],});diff --git a/apps/dashboard/src/components/chat/tool-renderers/get-response-log.tsx b/apps/dashboard/src/components/chat/tool-renderers/get-response-log.tsxindex 687bc56e7..a8c049b52 100644--- a/apps/dashboard/src/components/chat/tool-renderers/get-response-log.tsx+++ b/apps/dashboard/src/components/chat/tool-renderers/get-response-log.tsx@@ -3,11 +3,13 @@ import type {AgentToolOutput,} from "@openstatus/services/agent-tools";+import { EntityRef } from "@/components/common/entity-ref/entity-ref";import { TableCellBoolean } from "@/components/data-table/table-cell-boolean";import { TableCellDate } from "@/components/data-table/table-cell-date";import { TableCellNumber } from "@/components/data-table/table-cell-number";import { TableCellRegion } from "@/components/data-table/table-cell-region";import { TableCellText } from "@/components/data-table/table-cell-text";+import { toEntityId } from "@/data/entity-refs.client";import type {DetailsRow,@@ -19,13 +21,25 @@ type Input = AgentToolInput<"get_response_log">;type Output = AgentToolOutput<"get_response_log">;type Timing = NonNullable<Output["timing"]>;+function MonitorRef({ value }: { value: string }) {+ const id = toEntityId(value);+ return id ? (+ <EntityRef kind="monitor" id={id} />+ ) : (+ <TableCellText value={value} />+ );+}+export function getResponseLogDetails(_input: Input,output: Output,): DetailsTableData {const request: DetailsRow[] = [{ label: "Log ID", value: <TableCellText value={output.id} /> },- { label: "Monitor", value: <TableCellText value={output.monitorId} /> },+ {+ label: "Monitor",+ value: <MonitorRef value={output.monitorId} />,+ },{ label: "Region", value: <TableCellRegion value={output.region} /> },{ label: "URL", value: <TableCellText value={output.url} /> },{diff --git a/apps/dashboard/src/components/chat/tool-renderers/get-status-report.tsx b/apps/dashboard/src/components/chat/tool-renderers/get-status-report.tsxindex d674af124..60c0e53ee 100644--- a/apps/dashboard/src/components/chat/tool-renderers/get-status-report.tsx+++ b/apps/dashboard/src/components/chat/tool-renderers/get-status-report.tsx@@ -1,10 +1,12 @@import type { AgentToolOutput } from "@openstatus/services/agent-tools";import { cn } from "@openstatus/ui/lib/utils";+import { EntityRef } from "@/components/common/entity-ref/entity-ref";import { TableCellDate } from "@/components/data-table/table-cell-date";import { TableCellLink } from "@/components/data-table/table-cell-link";import { TableCellNumber } from "@/components/data-table/table-cell-number";import { TableCellText } from "@/components/data-table/table-cell-text";+import { entityKinds } from "@/data/entity-refs.client";import { colors } from "@/data/status-report-updates.client";import type { DetailsTableData } from "./details-table";@@ -35,7 +37,10 @@ export function getStatusReportDetails(value:output.pageId !== null ? (<TableCellLink- href={`/status-pages/${output.pageId}/status-reports/${output.id}`}+ href={entityKinds.statusReport.href({+ id: output.id,+ pageId: output.pageId,+ })}value={output.title}/>) : (@@ -47,7 +52,7 @@ export function getStatusReportDetails(label: "Page",value:output.pageId !== null ? (- <TableCellNumber value={output.pageId} />+ <EntityRef kind="page" id={output.pageId} />) : (<TableCellText value={null} />),diff --git a/apps/dashboard/src/components/chat/tool-renderers/incidents.tsx b/apps/dashboard/src/components/chat/tool-renderers/incidents.tsxindex 4d577bfaf..ab72a9660 100644--- a/apps/dashboard/src/components/chat/tool-renderers/incidents.tsx+++ b/apps/dashboard/src/components/chat/tool-renderers/incidents.tsx@@ -4,6 +4,7 @@ import type {} from "@openstatus/services/agent-tools";import type { ChangeRow } from "@/components/common/changes-table";+import { EntityRef } from "@/components/common/entity-ref/entity-ref";import { TableCellDate } from "@/components/data-table/table-cell-date";import { TableCellNumber } from "@/components/data-table/table-cell-number";import { TableCellText } from "@/components/data-table/table-cell-text";@@ -74,7 +75,13 @@ export function getIncidentDetails(},{label: "Status report",- value: <TableCellText value={output.statusReport?.title ?? null} />,+ value: output.statusReport ? (+ <EntityRef kind="statusReport" id={output.statusReport.id}>+ {output.statusReport.title}+ </EntityRef>+ ) : (+ <TableCellText value={null} />+ ),},],},diff --git a/apps/dashboard/src/components/chat/tool-renderers/list-audit-logs.tsx b/apps/dashboard/src/components/chat/tool-renderers/list-audit-logs.tsxindex ea3fad4d8..a09465aca 100644--- a/apps/dashboard/src/components/chat/tool-renderers/list-audit-logs.tsx+++ b/apps/dashboard/src/components/chat/tool-renderers/list-audit-logs.tsx@@ -1,14 +1,31 @@import type { AgentToolOutput } from "@openstatus/services/agent-tools";import { Badge } from "@openstatus/ui/components/ui/badge";+import { EntityRef } from "@/components/common/entity-ref/entity-ref";import { TableCellDate } from "@/components/data-table/table-cell-date";import { TableCellText } from "@/components/data-table/table-cell-text";+import { auditEntityKind, toEntityId } from "@/data/entity-refs.client";import { cn } from "@/lib/utils";import type { ResultTableData } from "./result-table";type Output = AgentToolOutput<"list_audit_logs">;+function AuditLogEntity({ type, id }: { type: string; id: string }) {+ const kind = auditEntityKind(type);+ const entityId = toEntityId(id);+ return (+ <span className="text-muted-foreground font-mono">+ {type}#+ {kind && entityId ? (+ <EntityRef kind={kind} id={entityId} className="text-foreground" />+ ) : (+ id+ )}+ </span>+ );+}+function getActionBadgeColor(action: string) {if (action.endsWith(".create"))return "bg-success/10 text-success border-success/20";@@ -44,12 +61,7 @@ export function listAuditLogsTable({item.action}</Badge>),- entity: (- <TableCellText- value={`${item.entityType}#${item.entityId}`}- className="text-muted-foreground font-mono"- />- ),+ entity: <AuditLogEntity type={item.entityType} id={item.entityId} />,actor: (<TableCellTextvalue={item.actor}diff --git a/apps/dashboard/src/components/chat/tool-renderers/list-maintenances.tsx b/apps/dashboard/src/components/chat/tool-renderers/list-maintenances.tsxindex 2b6145010..0e7860a70 100644--- a/apps/dashboard/src/components/chat/tool-renderers/list-maintenances.tsx+++ b/apps/dashboard/src/components/chat/tool-renderers/list-maintenances.tsx@@ -1,6 +1,7 @@import type { AgentToolOutput } from "@openstatus/services/agent-tools";import { formatDistanceStrict } from "date-fns";+import { EntityRef } from "@/components/common/entity-ref/entity-ref";import { TableCellDate } from "@/components/data-table/table-cell-date";import { TableCellNumber } from "@/components/data-table/table-cell-number";import { TableCellText } from "@/components/data-table/table-cell-text";@@ -34,7 +35,7 @@ export function listMaintenancesTable(duration: <TableCellNumber value={amount} unit={unit} />,page:m.pageId !== null ? (- <TableCellNumber value={m.pageId} />+ <EntityRef kind="page" id={m.pageId} />) : (<TableCellText value={null} empty="No page" />),diff --git a/apps/dashboard/src/components/chat/tool-renderers/list-monitors.tsx b/apps/dashboard/src/components/chat/tool-renderers/list-monitors.tsxindex 41e42e3d0..10d1f7517 100644--- a/apps/dashboard/src/components/chat/tool-renderers/list-monitors.tsx+++ b/apps/dashboard/src/components/chat/tool-renderers/list-monitors.tsx@@ -4,6 +4,7 @@ import { TableCellBoolean } from "@/components/data-table/table-cell-boolean";import { TableCellLink } from "@/components/data-table/table-cell-link";import { TableCellNumber } from "@/components/data-table/table-cell-number";import { TableCellText } from "@/components/data-table/table-cell-text";+import { entityKinds } from "@/data/entity-refs.client";import type { ResultTableData } from "./result-table";@@ -29,7 +30,7 @@ export function listMonitorsTable(id: m.id,cells: {name: (- <TableCellLink href={`/monitors/${m.id}/overview`} value={m.name} />+ <TableCellLink href={entityKinds.monitor.href(m)} value={m.name} />),jobType: (<TableCellTextdiff --git a/apps/dashboard/src/components/chat/tool-renderers/list-notifications.tsx b/apps/dashboard/src/components/chat/tool-renderers/list-notifications.tsxindex 358eacf01..f1ac09ad1 100644--- a/apps/dashboard/src/components/chat/tool-renderers/list-notifications.tsx+++ b/apps/dashboard/src/components/chat/tool-renderers/list-notifications.tsx@@ -1,8 +1,10 @@import type { AgentToolOutput } from "@openstatus/services/agent-tools";+import { EntityRefList } from "@/components/common/entity-ref/entity-ref";import { TableCellLink } from "@/components/data-table/table-cell-link";import { TableCellNumber } from "@/components/data-table/table-cell-number";import { TableCellText } from "@/components/data-table/table-cell-text";+import { entityKinds } from "@/data/entity-refs.client";import type { ResultTableData } from "./result-table";@@ -23,23 +25,24 @@ export function listNotificationsTable(rows: items.map((n) => ({id: n.id,cells: {- name: <TableCellLink href={`/notifications/${n.id}`} value={n.name} />,- provider: (- <TableCellText- value={n.provider}- className="text-muted-foreground font-mono"+ name: (+ <TableCellLink+ href={entityKinds.notification.href()}+ value={n.name}/>),- monitors: (+ provider: (<TableCellText- value={- n.monitorIds.length === 0- ? "none"- : `${n.monitorIds.length} (${n.monitorIds.join(", ")})`- }+ value={n.provider}className="text-muted-foreground font-mono"/>),+ monitors:+ n.monitorIds.length === 0 ? (+ <TableCellText value={null} empty="None" />+ ) : (+ <EntityRefList kind="monitor" refs={n.monitorIds} />+ ),id: <TableCellNumber value={n.id} />,},})),diff --git a/apps/dashboard/src/components/chat/tool-renderers/list-page-components.tsx b/apps/dashboard/src/components/chat/tool-renderers/list-page-components.tsxindex 155879408..586fbca28 100644--- a/apps/dashboard/src/components/chat/tool-renderers/list-page-components.tsx+++ b/apps/dashboard/src/components/chat/tool-renderers/list-page-components.tsx@@ -1,8 +1,10 @@import type { AgentToolOutput } from "@openstatus/services/agent-tools";+import { EntityRef } from "@/components/common/entity-ref/entity-ref";import { TableCellLink } from "@/components/data-table/table-cell-link";import { TableCellNumber } from "@/components/data-table/table-cell-number";import { TableCellText } from "@/components/data-table/table-cell-text";+import { entityKinds } from "@/data/entity-refs.client";import type { ResultTableData } from "./result-table";@@ -26,7 +28,7 @@ export function listPageComponentsTable(cells: {name: (<TableCellLink- href={`/status-pages/${c.pageId}/components`}+ href={entityKinds.pageComponent.href(c)}value={c.name}/>),@@ -36,10 +38,10 @@ export function listPageComponentsTable(className="text-muted-foreground font-mono"/>),- page: <TableCellNumber value={c.pageId} />,+ page: <EntityRef kind="page" id={c.pageId} />,monitor:c.monitorId !== null ? (- <TableCellNumber value={c.monitorId} />+ <EntityRef kind="monitor" id={c.monitorId} />) : (<TableCellText value={null} empty="No monitor" />),diff --git a/apps/dashboard/src/components/chat/tool-renderers/list-private-locations.tsx b/apps/dashboard/src/components/chat/tool-renderers/list-private-locations.tsxindex 4be9d5608..7c23af396 100644--- a/apps/dashboard/src/components/chat/tool-renderers/list-private-locations.tsx+++ b/apps/dashboard/src/components/chat/tool-renderers/list-private-locations.tsx@@ -1,11 +1,13 @@import type { AgentToolOutput } from "@openstatus/services/agent-tools";+import { EntityRefList } from "@/components/common/entity-ref/entity-ref";import { TableCellDate } from "@/components/data-table/table-cell-date";import { TableCellEmpty } from "@/components/data-table/table-cell-empty";import { TableCellLink } from "@/components/data-table/table-cell-link";import { TableCellMetadata } from "@/components/data-table/table-cell-metadata";import { TableCellNumber } from "@/components/data-table/table-cell-number";import { TableCellText } from "@/components/data-table/table-cell-text";+import { entityKinds } from "@/data/entity-refs.client";import type { ResultTableData } from "./result-table";@@ -29,20 +31,16 @@ export function listPrivateLocationsTable(cells: {name: (<TableCellLink- href={"/settings/private-locations"}+ href={entityKinds.privateLocation.href()}value={location.name}/>),- monitors: (- <TableCellText- value={- location.monitorIds.length === 0- ? "none"- : `${location.monitorIds.length} (${location.monitorIds.join(", ")})`- }- className="text-muted-foreground font-mono"- />- ),+ monitors:+ location.monitorIds.length === 0 ? (+ <TableCellText value={null} empty="None" />+ ) : (+ <EntityRefList kind="monitor" refs={location.monitorIds} />+ ),metadata: <TableCellMetadata value={location.metadata} />,lastSeenAt: location.lastSeenAt ? (<TableCellDate value={new Date(location.lastSeenAt)} />diff --git a/apps/dashboard/src/components/chat/tool-renderers/list-status-pages.tsx b/apps/dashboard/src/components/chat/tool-renderers/list-status-pages.tsxindex b573c70ed..7ba2de015 100644--- a/apps/dashboard/src/components/chat/tool-renderers/list-status-pages.tsx+++ b/apps/dashboard/src/components/chat/tool-renderers/list-status-pages.tsx@@ -3,6 +3,7 @@ import type { AgentToolOutput } from "@openstatus/services/agent-tools";import { TableCellLink } from "@/components/data-table/table-cell-link";import { TableCellNumber } from "@/components/data-table/table-cell-number";import { TableCellText } from "@/components/data-table/table-cell-text";+import { entityKinds } from "@/data/entity-refs.client";import type { ResultTableData } from "./result-table";@@ -23,10 +24,7 @@ export function listStatusPagesTable(id: p.id,cells: {title: (- <TableCellLink- href={`/status-pages/${p.id}/status-reports`}- value={p.title}- />+ <TableCellLink href={entityKinds.page.href(p)} value={p.title} />),slug: (<TableCellTextdiff --git a/apps/dashboard/src/components/chat/tool-renderers/list-status-reports.tsx b/apps/dashboard/src/components/chat/tool-renderers/list-status-reports.tsxindex 3b449dde2..1e61ee983 100644--- a/apps/dashboard/src/components/chat/tool-renderers/list-status-reports.tsx+++ b/apps/dashboard/src/components/chat/tool-renderers/list-status-reports.tsx@@ -1,9 +1,11 @@import type { AgentToolOutput } from "@openstatus/services/agent-tools";import { cn } from "@openstatus/ui/lib/utils";+import { EntityRef } from "@/components/common/entity-ref/entity-ref";import { TableCellLink } from "@/components/data-table/table-cell-link";import { TableCellNumber } from "@/components/data-table/table-cell-number";import { TableCellText } from "@/components/data-table/table-cell-text";+import { entityKinds } from "@/data/entity-refs.client";import { colors } from "@/data/status-report-updates.client";import type { ResultTableData } from "./result-table";@@ -28,7 +30,10 @@ export function listStatusReportsTable(title:r.pageId !== null ? (<TableCellLink- href={`/status-pages/${r.pageId}/status-reports/${r.id}`}+ href={entityKinds.statusReport.href({+ id: r.id,+ pageId: r.pageId,+ })}value={r.title}/>) : (@@ -46,7 +51,7 @@ export function listStatusReportsTable(),page:r.pageId !== null ? (- <TableCellNumber value={r.pageId} />+ <EntityRef kind="page" id={r.pageId} />) : (<TableCellText value={null} empty="No page" />),diff --git a/apps/dashboard/src/components/chat/tool-renderers/list-tables.test.tsx b/apps/dashboard/src/components/chat/tool-renderers/list-tables.test.tsxindex 2fb81e690..2d8a97e17 100644--- a/apps/dashboard/src/components/chat/tool-renderers/list-tables.test.tsx+++ b/apps/dashboard/src/components/chat/tool-renderers/list-tables.test.tsx@@ -25,6 +25,12 @@ function text(node: ReactNode) {return html(node).replace(/<[^>]+>/g, "");}+function refsOf(node: ReactNode) {+ return [+ ...html(node).matchAll(/data-slot="entity-ref"[^>]*aria-label="([^"]+)"/g),+ ].map((m) => m[1]);+}+function hrefOf(node: ReactNode) {return html(node).match(/<a [^>]*href="([^"]+)"/)?.[1];}@@ -71,13 +77,17 @@ describe("listNotificationsTable", () => {}),);- it("links to the notification", () => {- expect(hrefOf(table.rows[0].cells.name)).toBe("/notifications/1");+ it("links to the notifications list", () => {+ // Notifiers have no detail page; they open in a sheet on the list.+ expect(hrefOf(table.rows[0].cells.name)).toBe("/notifications");});- it("summarises attached monitors", () => {- expect(text(table.rows[0].cells.monitors)).toBe("2 (4, 5)");- expect(text(table.rows[1].cells.monitors)).toBe("none");+ it("references attached monitors", () => {+ expect(refsOf(table.rows[0].cells.monitors)).toEqual([+ "Monitor 4",+ "Monitor 5",+ ]);+ expect(text(table.rows[1].cells.monitors)).toBe("None");});});@@ -95,8 +105,9 @@ describe("listPageComponentsTable", () => {expect(hrefOf(table.rows[0].cells.name)).toBe("/status-pages/2/components");});- it("shows the monitor id, or a placeholder for static components", () => {- expect(text(table.rows[0].cells.monitor)).toContain("4");+ it("references the page and monitor, or a placeholder for static components", () => {+ expect(refsOf(table.rows[0].cells.page)).toEqual(["Status page 2"]);+ expect(refsOf(table.rows[0].cells.monitor)).toEqual(["Monitor 4"]);expect(text(table.rows[1].cells.monitor).trim()).toBe("No monitor");});});@@ -124,7 +135,7 @@ describe("listPrivateLocationsTable", () => {it("shows 'Never' for a location that never reported", () => {expect(text(table.rows[0].cells.lastSeenAt)).toBe("Never");- expect(text(table.rows[0].cells.monitors)).toBe("none");+ expect(text(table.rows[0].cells.monitors)).toBe("None");});it("renders metadata as pills", () => {diff --git a/apps/dashboard/src/components/chat/tool-renderers/status-report-changes.test.ts b/apps/dashboard/src/components/chat/tool-renderers/status-report-changes.test.tsindex 1e7417799..bf3d1f6cf 100644--- a/apps/dashboard/src/components/chat/tool-renderers/status-report-changes.test.ts+++ b/apps/dashboard/src/components/chat/tool-renderers/status-report-changes.test.ts@@ -48,7 +48,10 @@ describe("createStatusReportChanges", () => {);expect(rows.slice(5)).toEqual([{ field: "pageComponentIds", after: [1, 2] },- { field: "componentImpacts", after: ["1 → major_outage"] },+ {+ field: "componentImpacts",+ after: [{ pageComponentId: 1, impact: "major_outage" }],+ },{ field: "date", after: "2024-01-01T00:00:00Z" },]);});@@ -110,7 +113,7 @@ describe("addStatusReportUpdateChanges", () => {]);});- it("formats impacts, keeps the date and uses the applied notify flag", () => {+ it("keeps impacts structured, keeps the date and uses the applied notify flag", () => {const rows = addStatusReportUpdateChanges(asInput<AddInput>({...base,@@ -121,7 +124,10 @@ describe("addStatusReportUpdateChanges", () => {);expect(rows.find((r) => r.field === "notify")?.after).toBe(true);expect(rows.slice(4)).toEqual([- { field: "componentImpacts", after: ["4 → operational"] },+ {+ field: "componentImpacts",+ after: [{ pageComponentId: 4, impact: "operational" }],+ },{ field: "date", after: "2024-01-01T00:00:00Z" },]);});diff --git a/apps/dashboard/src/components/chat/tool-renderers/status-report-update.tsx b/apps/dashboard/src/components/chat/tool-renderers/status-report-update.tsxindex c7be2c6c5..717166dcd 100644--- a/apps/dashboard/src/components/chat/tool-renderers/status-report-update.tsx+++ b/apps/dashboard/src/components/chat/tool-renderers/status-report-update.tsx@@ -1,5 +1,4 @@import type { AgentToolInput } from "@openstatus/services/agent-tools";-import { formatComponentImpacts } from "@openstatus/services/status-report/utils";import type { ChangeRow } from "@/components/common/changes-table";@@ -15,9 +14,7 @@ export function updateStatusReportUpdateChanges(? [{field: "componentImpacts",- after: input.componentImpacts.length- ? formatComponentImpacts(input.componentImpacts)- : [],+ after: input.componentImpacts,},]: []),diff --git a/apps/dashboard/src/components/common/changes-table.test.tsx b/apps/dashboard/src/components/common/changes-table.test.tsxindex f3aff5032..036df330a 100644--- a/apps/dashboard/src/components/common/changes-table.test.tsx+++ b/apps/dashboard/src/components/common/changes-table.test.tsx@@ -107,3 +107,66 @@ describe("ChangesTable", () => {expect(html).not.toContain('data-kind="added"');});});++describe("ChangesTable entity refs", () => {+ function refs(changes: Parameters<typeof ChangesTable>[0]["changes"]) {+ const html = renderToStaticMarkup(<ChangesTable changes={changes} />);+ return [+ ...html.matchAll(/data-slot="entity-ref"[^>]*aria-label="([^"]+)"/g),+ ].map((m) => m[1]);+ }++ it("renders a known id field as a ref", () => {+ expect(refs([{ field: "pageId", after: 1 }])).toEqual(["Status page 1"]);+ });++ it("renders every id of an id array", () => {+ expect(refs([{ field: "pageComponentIds", after: [3, 4] }])).toEqual([+ "Component 3",+ "Component 4",+ ]);+ });++ it("renders refs on removed lines too", () => {+ expect(refs([{ field: "monitorId", before: 2, after: 5 }])).toEqual([+ "Monitor 2",+ "Monitor 5",+ ]);+ });++ it("renders component impacts as ref and impact label", () => {+ const html = renderToStaticMarkup(+ <ChangesTable+ changes={[+ {+ field: "componentImpacts",+ after: [{ pageComponentId: 7, impact: "major_outage" }],+ },+ ]}+ />,+ );+ expect(html).toContain('aria-label="Component 7"');+ expect(html).toContain("Major outage");+ });++ it("falls back to text for unknown fields and non-id values", () => {+ expect(+ refs([+ { field: "retry", after: 3 },+ { field: "pageId", after: null },+ { field: "monitorIds", after: [] },+ { field: "pageComponentIds", after: ["a"] },+ { field: "componentImpacts", after: ["1 → major_outage"] },+ ]),+ ).toEqual([]);+ });++ it("treats inherited object keys as plain fields", () => {+ expect(+ refs([+ { field: "toString", after: 1 },+ { field: "constructor", after: 2 },+ ]),+ ).toEqual([]);+ });+});diff --git a/apps/dashboard/src/components/common/changes-table.tsx b/apps/dashboard/src/components/common/changes-table.tsxindex 25f8bd806..1315957fe 100644--- a/apps/dashboard/src/components/common/changes-table.tsx+++ b/apps/dashboard/src/components/common/changes-table.tsx@@ -1,5 +1,18 @@+import {+ fieldRefKind,+ toEntityId,+ toEntityIds,+} from "@/data/entity-refs.client";+import {+ type ComponentImpact,+ impactDisplay,+ isComponentImpactList,+} from "@/data/status-report-updates.client";import { cn } from "@/lib/utils";+import { EntityRef, EntityRefList } from "./entity-ref/entity-ref";+import { StatusBadge } from "./status-badge";+/*** Field-level diff row used by the audit-log "CHANGES" view and the* chat tool draft/result cards.@@ -33,12 +46,20 @@ export function ChangesTable({ changes }: { changes: ChangeRow[] }) {<div className="bg-muted/40 text-muted-foreground truncate border-r px-3 py-2 font-mono md:col-span-1">{change.field}</div>- <div className="grid truncate md:col-span-3">+ <div className="grid min-w-0 md:col-span-3">{"before" in change ? (- <DiffLine kind="removed" value={change.before} />+ <DiffLine+ kind="removed"+ field={change.field}+ value={change.before}+ />) : null}{"after" in change ? (- <DiffLine kind="added" value={change.after} />+ <DiffLine+ kind="added"+ field={change.field}+ value={change.after}+ />) : null}</div></div>@@ -49,9 +70,11 @@ export function ChangesTable({ changes }: { changes: ChangeRow[] }) {function DiffLine({kind,+ field,value,}: {kind: "added" | "removed";+ field: string;value: unknown;}) {const sign = kind === "added" ? "+" : "-";@@ -63,13 +86,49 @@ function DiffLine({<span className="text-muted-foreground group-data-[kind=added]:text-success group-data-[kind=removed]:text-destructive select-none">{sign}</span>- <span className="group-data-[kind=added]:text-foreground group-data-[kind=removed]:text-muted-foreground break-all whitespace-pre-wrap group-data-[kind=removed]:line-through">- {formatValue(value)}+ {/* Refs and badges are inline boxes; the removed strikethrough has to be set on them. */}+ <span className="group-data-[kind=added]:text-foreground group-data-[kind=removed]:text-muted-foreground min-w-0 break-all whitespace-pre-wrap group-data-[kind=removed]:line-through group-data-[kind=removed]:[&_[data-slot=badge]]:line-through group-data-[kind=removed]:[&_[data-slot=entity-ref]]:[text-decoration-line:underline_line-through]">+ <DiffValue field={field} value={value} /></span></div>);}+function DiffValue({ field, value }: { field: string; value: unknown }) {+ const kind = fieldRefKind(field);+ if (kind === "componentImpacts") {+ if (isComponentImpactList(value) && value.length > 0) {+ return <ImpactList impacts={value} />;+ }+ } else if (kind) {+ // Strings stay text: a diff value of "4" is not a reference.+ const id = typeof value === "number" ? toEntityId(value) : undefined;+ if (id) return <EntityRef kind={kind} id={id} />;+ const ids = toEntityIds(value);+ if (ids) return <EntityRefList kind={kind} refs={ids} />;+ }+ return formatValue(value);+}++function ImpactList({ impacts }: { impacts: ComponentImpact[] }) {+ return (+ <span className="flex flex-col gap-1">+ {impacts.map(({ pageComponentId, impact }) => {+ const display = impactDisplay(impact);+ return (+ <span key={pageComponentId} className="flex items-center gap-2">+ <EntityRef kind="pageComponent" id={pageComponentId} />+ <span className="text-muted-foreground">→</span>+ <StatusBadge plain variant={display.variant} className="font-mono">+ {display.label}+ </StatusBadge>+ </span>+ );+ })}+ </span>+ );+}+const HIDDEN_FIELDS = new Set(["workspaceId","createdAt",diff --git a/apps/dashboard/src/components/common/entity-card.tsx b/apps/dashboard/src/components/common/entity-card.tsxnew file mode 100644index 000000000..baf022d6a--- /dev/null+++ b/apps/dashboard/src/components/common/entity-card.tsx@@ -0,0 +1,96 @@+import { cn } from "@/lib/utils";++export function EntityCard({+ children,+ className,+ ...props+}: React.ComponentProps<"div">) {+ return (+ <div+ data-slot="entity-card"+ className={cn("flex flex-col text-sm", className)}+ {...props}+ >+ {children}+ </div>+ );+}++export function EntityCardHeader({+ children,+ className,+ ...props+}: React.ComponentProps<"div">) {+ return (+ <div+ data-slot="entity-card-header"+ className={cn(+ "[&>svg]:text-muted-foreground flex min-w-0 items-start gap-2 px-3 py-2.5 [&>[data-slot=badge]]:shrink-0 [&>svg]:mt-0.5 [&>svg]:size-4 [&>svg]:shrink-0",+ className,+ )}+ {...props}+ >+ {children}+ </div>+ );+}++export function EntityCardTitle({+ children,+ className,+ ...props+}: React.ComponentProps<"span">) {+ return (+ <span+ data-slot="entity-card-title"+ className={cn(+ "line-clamp-2 min-w-0 flex-1 font-medium break-words",+ className,+ )}+ {...props}+ >+ {children}+ </span>+ );+}++export function EntityCardContent({+ children,+ className,+ ...props+}: React.ComponentProps<"dl">) {+ return (+ <dl+ data-slot="entity-card-content"+ className={cn(+ "grid grid-cols-[auto_minmax(0,1fr)] gap-x-4 gap-y-1.5 border-t px-3 py-2.5",+ className,+ )}+ {...props}+ >+ {children}+ </dl>+ );+}++export function EntityCardRow({+ label,+ children,+ className,+ ...props+}: React.ComponentProps<"dd"> & { label: string }) {+ return (+ <>+ <dt data-slot="entity-card-label" className="text-muted-foreground">+ {label}+ </dt>+ <dd+ data-slot="entity-card-row"+ className={cn("min-w-0 truncate text-right font-mono", className)}+ {...props}+ >+ {children}+ </dd>+ </>+ );+}diff --git a/apps/dashboard/src/components/common/entity-ref/cards/incident.tsx b/apps/dashboard/src/components/common/entity-ref/cards/incident.tsxnew file mode 100644index 000000000..6aff09514--- /dev/null+++ b/apps/dashboard/src/components/common/entity-ref/cards/incident.tsx@@ -0,0 +1,58 @@+import { useQuery } from "@tanstack/react-query";++import {+ EntityCard,+ EntityCardContent,+ EntityCardRow,+} from "@/components/common/entity-card";+import { entityKinds } from "@/data/entity-refs.client";+import { severityConfig, statusConfig } from "@/data/managed-incidents.client";+import { useTRPC } from "@/lib/trpc/client";++import {+ EntityRefFallback,+ EntityRefHeader,+ RelativeTime,+ lookupOptions,+} from "../parts";++export function IncidentCard({ id }: { id: number }) {+ const trpc = useTRPC();+ const incident = useQuery(+ trpc.incident.get.queryOptions({ id }, lookupOptions),+ );++ if (!incident.data) {+ return <EntityRefFallback kind="incident" id={id} query={incident} />;+ }+ const { data } = incident;++ return (+ <EntityCard>+ <EntityRefHeader kind="incident" href={entityKinds.incident.href(data)}>+ {data.title}+ </EntityRefHeader>+ <EntityCardContent>+ <EntityCardRow label="Status">+ {statusConfig[data.status].label}+ </EntityCardRow>+ <EntityCardRow label="Severity">+ {severityConfig[data.severity].label}+ </EntityCardRow>+ <EntityCardRow label="Started">+ <RelativeTime date={data.startedAt} />+ </EntityCardRow>+ <EntityCardRow label="Commander">+ {data.commander+ ? (data.commander.name ?? data.commander.email)+ : "Unassigned"}+ </EntityCardRow>+ {data.statusReport ? (+ <EntityCardRow label="Report">+ {data.statusReport.title}+ </EntityCardRow>+ ) : null}+ </EntityCardContent>+ </EntityCard>+ );+}diff --git a/apps/dashboard/src/components/common/entity-ref/cards/maintenance.tsx b/apps/dashboard/src/components/common/entity-ref/cards/maintenance.tsxnew file mode 100644index 000000000..fb810c9cb--- /dev/null+++ b/apps/dashboard/src/components/common/entity-ref/cards/maintenance.tsx@@ -0,0 +1,59 @@+import { useQuery } from "@tanstack/react-query";++import {+ EntityCard,+ EntityCardContent,+ EntityCardRow,+} from "@/components/common/entity-card";+import { entityKinds } from "@/data/entity-refs.client";+import {+ getMaintenanceStatus,+ maintenanceStatusConfig,+} from "@/data/overview-events.client";+import { formatDateRange } from "@/lib/formatter";+import { useTRPC } from "@/lib/trpc/client";++import { EntityRefFallback, EntityRefHeader, lookupOptions } from "../parts";++export function MaintenanceCard({ id }: { id: number }) {+ const trpc = useTRPC();+ const maintenance = useQuery(+ trpc.maintenance.get.queryOptions({ id }, lookupOptions),+ );++ if (!maintenance.data) {+ return <EntityRefFallback kind="maintenance" id={id} query={maintenance} />;+ }+ const { data } = maintenance;+ const components = data.pageComponents.map((c) => c.name).join(", ");++ return (+ <EntityCard>+ <EntityRefHeader+ kind="maintenance"+ href={+ data.pageId === null+ ? undefined+ : entityKinds.maintenance.href({ id, pageId: data.pageId })+ }+ >+ {data.title}+ </EntityRefHeader>+ <EntityCardContent>+ <EntityCardRow label="Status">+ {maintenanceStatusConfig[getMaintenanceStatus(data)].label}+ </EntityCardRow>+ <EntityCardRow label="Window" className="whitespace-normal">+ <time dateTime={data.from.toISOString()}>+ {formatDateRange(data.from, data.to)}+ </time>+ </EntityCardRow>+ {components ? (+ <EntityCardRow label="Components" title={components}>+ {components}+ </EntityCardRow>+ ) : null}+ </EntityCardContent>+ </EntityCard>+ );+}diff --git a/apps/dashboard/src/components/common/entity-ref/cards/monitor.tsx b/apps/dashboard/src/components/common/entity-ref/cards/monitor.tsxnew file mode 100644index 000000000..576f7fe16--- /dev/null+++ b/apps/dashboard/src/components/common/entity-ref/cards/monitor.tsx@@ -0,0 +1,43 @@+import { useQuery } from "@tanstack/react-query";++import {+ EntityCard,+ EntityCardContent,+ EntityCardRow,+} from "@/components/common/entity-card";+import { entityKinds, findById } from "@/data/entity-refs.client";+import { getMonitorHealth, monitorHealthConfig } from "@/data/monitors.client";+import { useTRPC } from "@/lib/trpc/client";++import { EntityRefFallback, EntityRefHeader } from "../parts";++export function MonitorCard({ id }: { id: number }) {+ const trpc = useTRPC();+ const monitor = useQuery({+ ...trpc.monitor.list.queryOptions(),+ select: findById(id),+ });++ if (!monitor.data) {+ return <EntityRefFallback kind="monitor" id={id} query={monitor} />;+ }+ const { data } = monitor;++ return (+ <EntityCard>+ <EntityRefHeader kind="monitor" href={entityKinds.monitor.href(data)}>+ {data.name}+ </EntityRefHeader>+ <EntityCardContent>+ <EntityCardRow label="Status">+ {monitorHealthConfig[getMonitorHealth(data)].label}+ </EntityCardRow>+ <EntityCardRow label={data.jobType.toUpperCase()} title={data.url}>+ {data.url}+ </EntityCardRow>+ <EntityCardRow label="Frequency">{data.periodicity}</EntityCardRow>+ <EntityCardRow label="Regions">{data.regions.length}</EntityCardRow>+ </EntityCardContent>+ </EntityCard>+ );+}diff --git a/apps/dashboard/src/components/common/entity-ref/cards/notification.tsx b/apps/dashboard/src/components/common/entity-ref/cards/notification.tsxnew file mode 100644index 000000000..f3be64727--- /dev/null+++ b/apps/dashboard/src/components/common/entity-ref/cards/notification.tsx@@ -0,0 +1,45 @@+import { useQuery } from "@tanstack/react-query";++import {+ EntityCard,+ EntityCardContent,+ EntityCardRow,+} from "@/components/common/entity-card";+import { entityKinds, findById } from "@/data/entity-refs.client";+import { useTRPC } from "@/lib/trpc/client";++import { EntityRefFallback, EntityRefHeader } from "../parts";++export function NotificationCard({ id }: { id: number }) {+ const trpc = useTRPC();+ const notification = useQuery({+ ...trpc.notification.list.queryOptions(),+ select: findById(id),+ });++ if (!notification.data) {+ return (+ <EntityRefFallback kind="notification" id={id} query={notification} />+ );+ }+ const { data } = notification;+ const monitors = data.monitors.map((m) => m.name).join(", ");++ return (+ <EntityCard>+ <EntityRefHeader+ kind="notification"+ href={entityKinds.notification.href()}+ >+ {data.name}+ </EntityRefHeader>+ <EntityCardContent>+ {/* Raw provider id: the provider config would pull every notifier form into this bundle. */}+ <EntityCardRow label="Provider">{data.provider}</EntityCardRow>+ <EntityCardRow label="Monitors" title={monitors || undefined}>+ {monitors || "None"}+ </EntityCardRow>+ </EntityCardContent>+ </EntityCard>+ );+}diff --git a/apps/dashboard/src/components/common/entity-ref/cards/page-component.tsx b/apps/dashboard/src/components/common/entity-ref/cards/page-component.tsxnew file mode 100644index 000000000..dcfc40d00--- /dev/null+++ b/apps/dashboard/src/components/common/entity-ref/cards/page-component.tsx@@ -0,0 +1,54 @@+import { useQuery } from "@tanstack/react-query";++import {+ EntityCard,+ EntityCardContent,+ EntityCardRow,+} from "@/components/common/entity-card";+import { entityKinds, findById } from "@/data/entity-refs.client";+import { useTRPC } from "@/lib/trpc/client";++import { EntityRefFallback, EntityRefHeader } from "../parts";++export function PageComponentCard({ id }: { id: number }) {+ const trpc = useTRPC();+ const component = useQuery({+ ...trpc.pageComponent.list.queryOptions(),+ select: findById(id),+ });+ const page = useQuery({+ ...trpc.page.list.queryOptions(),+ select: findById(component.data?.pageId ?? 0),+ enabled: component.data !== undefined,+ });++ if (!component.data) {+ return <EntityRefFallback kind="pageComponent" id={id} query={component} />;+ }+ const { data } = component;++ return (+ <EntityCard>+ <EntityRefHeader+ kind="pageComponent"+ href={entityKinds.pageComponent.href(data)}+ >+ {data.name}+ </EntityRefHeader>+ <EntityCardContent>+ <EntityCardRow label="Type">+ {data.type === "monitor" ? "Monitor" : "Static"}+ </EntityCardRow>+ {page.data ? (+ <EntityCardRow label="Page">{page.data.title}</EntityCardRow>+ ) : null}+ {data.group ? (+ <EntityCardRow label="Group">{data.group.name}</EntityCardRow>+ ) : null}+ {data.monitor ? (+ <EntityCardRow label="Monitor">{data.monitor.name}</EntityCardRow>+ ) : null}+ </EntityCardContent>+ </EntityCard>+ );+}diff --git a/apps/dashboard/src/components/common/entity-ref/cards/page.tsx b/apps/dashboard/src/components/common/entity-ref/cards/page.tsxnew file mode 100644index 000000000..326729073--- /dev/null+++ b/apps/dashboard/src/components/common/entity-ref/cards/page.tsx@@ -0,0 +1,48 @@+import { Skeleton } from "@openstatus/ui/components/ui/skeleton";+import { useQuery } from "@tanstack/react-query";++import {+ EntityCard,+ EntityCardContent,+ EntityCardRow,+} from "@/components/common/entity-card";+import { entityKinds, findById } from "@/data/entity-refs.client";+import { useTRPC } from "@/lib/trpc/client";++import { EntityRefFallback, EntityRefHeader } from "../parts";++export function PageCard({ id }: { id: number }) {+ const trpc = useTRPC();+ const page = useQuery({+ ...trpc.page.list.queryOptions(),+ select: findById(id),+ });+ const components = useQuery({+ ...trpc.pageComponent.list.queryOptions({ pageId: id }),+ select: (rows) => rows?.length,+ });++ if (!page.data) {+ return <EntityRefFallback kind="page" id={id} query={page} />;+ }+ const { data } = page;++ return (+ <EntityCard>+ <EntityRefHeader kind="page" href={entityKinds.page.href(data)}>+ {data.title}+ </EntityRefHeader>+ <EntityCardContent>+ <EntityCardRow label="Slug">{data.slug}</EntityCardRow>+ {data.customDomain ? (+ <EntityCardRow label="Domain">{data.customDomain}</EntityCardRow>+ ) : null}+ <EntityCardRow label="Components">+ {components.isError+ ? "—"+ : (components.data ?? <Skeleton className="ml-auto h-4 w-6" />)}+ </EntityCardRow>+ </EntityCardContent>+ </EntityCard>+ );+}diff --git a/apps/dashboard/src/components/common/entity-ref/cards/private-location.tsx b/apps/dashboard/src/components/common/entity-ref/cards/private-location.tsxnew file mode 100644index 000000000..dc685e976--- /dev/null+++ b/apps/dashboard/src/components/common/entity-ref/cards/private-location.tsx@@ -0,0 +1,48 @@+import { useQuery } from "@tanstack/react-query";++import {+ EntityCard,+ EntityCardContent,+ EntityCardRow,+} from "@/components/common/entity-card";+import { entityKinds, findById } from "@/data/entity-refs.client";+import { useTRPC } from "@/lib/trpc/client";++import { EntityRefFallback, EntityRefHeader, RelativeTime } from "../parts";++export function PrivateLocationCard({ id }: { id: number }) {+ const trpc = useTRPC();+ const location = useQuery({+ // Schema max; there is no `get`, so locations past the newest 100 show+ // "not found". Accepted: the settings page itself only lists 50.+ ...trpc.privateLocation.list.queryOptions({ limit: 100 }),+ select: findById(id),+ });++ if (!location.data) {+ return (+ <EntityRefFallback kind="privateLocation" id={id} query={location} />+ );+ }+ const { data } = location;++ return (+ <EntityCard>+ <EntityRefHeader+ kind="privateLocation"+ href={entityKinds.privateLocation.href()}+ >+ {data.name}+ </EntityRefHeader>+ <EntityCardContent>+ <EntityCardRow label="Status">+ {data.status === "active" ? "Online" : "Offline"}+ </EntityCardRow>+ <EntityCardRow label="Monitors">{data.monitors.length}</EntityCardRow>+ <EntityCardRow label="Last seen">+ {data.lastSeenAt ? <RelativeTime date={data.lastSeenAt} /> : "Never"}+ </EntityCardRow>+ </EntityCardContent>+ </EntityCard>+ );+}diff --git a/apps/dashboard/src/components/common/entity-ref/cards/status-report.tsx b/apps/dashboard/src/components/common/entity-ref/cards/status-report.tsxnew file mode 100644index 000000000..5c04dc70d--- /dev/null+++ b/apps/dashboard/src/components/common/entity-ref/cards/status-report.tsx@@ -0,0 +1,61 @@+import { useQuery } from "@tanstack/react-query";++import {+ EntityCard,+ EntityCardContent,+ EntityCardRow,+} from "@/components/common/entity-card";+import { entityKinds } from "@/data/entity-refs.client";+import { useTRPC } from "@/lib/trpc/client";++import {+ EntityRefFallback,+ EntityRefHeader,+ RelativeTime,+ lookupOptions,+} from "../parts";++export function StatusReportCard({ id }: { id: number }) {+ const trpc = useTRPC();+ const report = useQuery(+ trpc.statusReport.get.queryOptions({ id }, lookupOptions),+ );++ if (!report.data) {+ return <EntityRefFallback kind="statusReport" id={id} query={report} />;+ }+ const { data } = report;+ const latest = data.updates[0];+ const components = data.pageComponents.map((c) => c.name).join(", ");++ return (+ <EntityCard>+ <EntityRefHeader+ kind="statusReport"+ href={+ data.pageId === null+ ? undefined+ : entityKinds.statusReport.href({ id, pageId: data.pageId })+ }+ >+ {data.title}+ </EntityRefHeader>+ <EntityCardContent>+ <EntityCardRow label="Status" className="capitalize">+ {data.status}+ </EntityCardRow>+ <EntityCardRow label="Page">{data.page.title}</EntityCardRow>+ {components ? (+ <EntityCardRow label="Components" title={components}>+ {components}+ </EntityCardRow>+ ) : null}+ {latest ? (+ <EntityCardRow label="Updated">+ <RelativeTime date={latest.date} />+ </EntityCardRow>+ ) : null}+ </EntityCardContent>+ </EntityCard>+ );+}diff --git a/apps/dashboard/src/components/common/entity-ref/entity-ref.tsx b/apps/dashboard/src/components/common/entity-ref/entity-ref.tsxnew file mode 100644index 000000000..fb00ce33d--- /dev/null+++ b/apps/dashboard/src/components/common/entity-ref/entity-ref.tsx@@ -0,0 +1,113 @@+"use client";++import {+ HoverCard,+ HoverCardContent,+ HoverCardTrigger,+} from "@openstatus/ui/components/ui/hover-card";+import { useState } from "react";++import { type EntityKind, entityKinds } from "@/data/entity-refs.client";+import { cn } from "@/lib/utils";++import { IncidentCard } from "./cards/incident";+import { MaintenanceCard } from "./cards/maintenance";+import { MonitorCard } from "./cards/monitor";+import { NotificationCard } from "./cards/notification";+import { PageCard } from "./cards/page";+import { PageComponentCard } from "./cards/page-component";+import { PrivateLocationCard } from "./cards/private-location";+import { StatusReportCard } from "./cards/status-report";++const cards = {+ page: PageCard,+ pageComponent: PageComponentCard,+ monitor: MonitorCard,+ statusReport: StatusReportCard,+ maintenance: MaintenanceCard,+ incident: IncidentCard,+ privateLocation: PrivateLocationCard,+ notification: NotificationCard,+} satisfies Record<EntityKind, React.ComponentType<{ id: number }>>;++/** An entity id that opens a card with the entity on hover, focus or tap. */+export function EntityRef({+ kind,+ id,+ children,+ className,+ onClick,+ ...props+}: Omit<React.ComponentProps<"button">, "id"> & {+ kind: EntityKind;+ id: number;+}) {+ const [open, setOpen] = useState(false);+ const Card = cards[kind];+ return (+ <HoverCard+ open={open}+ onOpenChange={setOpen}+ openDelay={150}+ closeDelay={100}+ >+ <HoverCardTrigger asChild>+ <button+ type="button"+ data-slot="entity-ref"+ aria-label={children ? undefined : `${entityKinds[kind].label} ${id}`}+ onClick={(e) => {+ setOpen(true);+ onClick?.(e);+ }}+ className={cn(+ "decoration-muted-foreground/50 data-[state=open]:decoration-foreground focus-visible:ring-ring/50 cursor-default rounded-xs font-mono tabular-nums underline decoration-dashed underline-offset-2 transition-[text-decoration-color] ease-[ease] outline-none focus-visible:ring-[3px]",+ className,+ )}+ {...props}+ >+ {children ?? id}+ </button>+ </HoverCardTrigger>+ <HoverCardContent align="start" className="w-72 overflow-hidden p-0">+ <Card id={id} />+ </HoverCardContent>+ </HoverCard>+ );+}++/** A bare id, or an id shown by its label (e.g. a name the payload already has). */+export type EntityRefItem = number | { id: number; label: React.ReactNode };++export function EntityRefList({+ kind,+ refs,+ className,+ ...props+}: React.ComponentProps<"span"> & {+ kind: EntityKind;+ refs: readonly EntityRefItem[];+}) {+ return (+ <span+ data-slot="entity-ref-list"+ className={cn("inline-flex flex-wrap gap-y-1", className)}+ {...props}+ >+ {refs.map((ref, i) => {+ const { id, label } =+ typeof ref === "number" ? { id: ref, label: undefined } : ref;+ return (+ <span key={`${id}-${i}`}>+ <EntityRef kind={kind} id={id}>+ {label}+ </EntityRef>+ {i < refs.length - 1 ? (+ <span className="text-muted-foreground mr-2">,</span>+ ) : null}+ </span>+ );+ })}+ </span>+ );+}diff --git a/apps/dashboard/src/components/common/entity-ref/parts.tsx b/apps/dashboard/src/components/common/entity-ref/parts.tsxnew file mode 100644index 000000000..2bd9d93c7--- /dev/null+++ b/apps/dashboard/src/components/common/entity-ref/parts.tsx@@ -0,0 +1,117 @@+import { ArrowUpRight } from "@openstatus/icons";+import { Skeleton } from "@openstatus/ui/components/ui/skeleton";+import type { UseQueryResult } from "@tanstack/react-query";+import NextLink from "next/link";++import {+ EntityCard,+ EntityCardContent,+ EntityCardHeader,+ EntityCardRow,+ EntityCardTitle,+} from "@/components/common/entity-card";+import { type EntityKind, entityKinds } from "@/data/entity-refs.client";+import { formatDateTime, formatDistanceToNowShort } from "@/lib/formatter";+import { isNotFound } from "@/lib/trpc/error";++/** Options for a `get` lookup: a 404 is the not-found card, not a bug. */+export const lookupOptions = {+ retry: false,+ meta: { expectNotFound: true },+ trpc: { context: { expectNotFound: true } },+} as const;++/** Kind icon and title; with `href` the title opens the entity in a new tab. */+export function EntityRefHeader({+ kind,+ href,+ children,+}: {+ kind: EntityKind;+ href?: string;+ children: React.ReactNode;+}) {+ const Icon = entityKinds[kind].icon;+ return (+ <EntityCardHeader>+ <Icon />+ {href ? (+ <NextLink+ href={href}+ target="_blank"+ rel="noopener"+ className="group/link focus-visible:ring-ring/50 flex min-w-0 flex-1 items-start gap-2 rounded-xs outline-none focus-visible:ring-[3px]"+ >+ <EntityCardTitle>{children}</EntityCardTitle>+ <ArrowUpRight className="text-muted-foreground/60 group-hover/link:text-foreground mt-0.5 size-3.5 shrink-0 transition-colors ease-[ease]" />+ </NextLink>+ ) : (+ <EntityCardTitle>{children}</EntityCardTitle>+ )}+ </EntityCardHeader>+ );+}++/** Loading, not-found or failed state for a card whose query has no data. */+export function EntityRefFallback({+ kind,+ id,+ query,+}: {+ kind: EntityKind;+ id: number;+ query: Pick<+ UseQueryResult<unknown, unknown>,+ "isPending" | "isError" | "error"+ >;+}) {+ const Icon = entityKinds[kind].icon;+ if (query.isPending) {+ return (+ <EntityCard aria-busy="true">+ <EntityCardHeader>+ <Icon />+ <Skeleton className="h-4 w-32" />+ </EntityCardHeader>+ <EntityCardContent>+ <Skeleton className="h-4 w-14" />+ <Skeleton className="ml-auto h-4 w-24" />+ <Skeleton className="h-4 w-16" />+ <Skeleton className="ml-auto h-4 w-20" />+ </EntityCardContent>+ </EntityCard>+ );+ }+ // Any 404 here means the entity is gone; `lookupOptions` only decides Sentry.+ const failed = query.isError && !isNotFound(query.error);+ const { label } = entityKinds[kind];+ return (+ <EntityCard>+ <EntityCardHeader>+ <Icon />+ <EntityCardTitle className="text-muted-foreground">+ {failed+ ? `Couldn't load ${label.toLowerCase()}`+ : `${label} not found`}+ </EntityCardTitle>+ </EntityCardHeader>+ <EntityCardContent>+ <EntityCardRow label="ID">{id}</EntityCardRow>+ <EntityCardRow+ label="Reason"+ className="text-muted-foreground whitespace-normal"+ >+ {failed ? "Try again" : "Deleted or no access"}+ </EntityCardRow>+ </EntityCardContent>+ </EntityCard>+ );+}++export function RelativeTime({ date }: { date: Date }) {+ return (+ <time dateTime={date.toISOString()} title={formatDateTime(date)}>+ {formatDistanceToNowShort(date)}+ </time>+ );+}diff --git a/apps/dashboard/src/components/common/monitor-status-dot.tsx b/apps/dashboard/src/components/common/monitor-status-dot.tsxindex 9f8c03099..6089588b1 100644--- a/apps/dashboard/src/components/common/monitor-status-dot.tsx+++ b/apps/dashboard/src/components/common/monitor-status-dot.tsx@@ -5,43 +5,46 @@ import {} from "@openstatus/ui/components/ui/tooltip";import { cn } from "@openstatus/ui/lib/utils";+import {+ type MonitorHealth,+ getMonitorHealth,+ monitorHealthConfig,+} from "@/data/monitors.client";++const dotColor = {+ inactive: "bg-muted-foreground/70",+ active: "bg-success",+ degraded: "bg-warning",+ error: "bg-destructive",+} as const satisfies Record<MonitorHealth, string>;+export function MonitorStatusDot({monitor,label,className,}: {- monitor: { active: boolean | null; status: string };+ monitor: Parameters<typeof getMonitorHealth>[0];/** Overrides the default tooltip text */label?: React.ReactNode;className?: string;}) {- const text =- label ??- (!monitor.active- ? "Inactive"- : monitor.status === "active"- ? "Normal"- : monitor.status === "error"- ? "Failing"- : "Degraded");+ const health = getMonitorHealth(monitor);+ const text = label ?? monitorHealthConfig[health].label;return (<Tooltip><TooltipTrigger asChild>{/* biome-ignore lint/a11y/noNoninteractiveTabindex: focusable so keyboard users can open the tooltip */}<span tabIndex={0} className={cn("relative inline-flex", className)}>- {!monitor.active ? (- <span className="bg-muted-foreground/70 relative inline-flex h-2.5 w-2.5 rounded-full" />- ) : monitor.status === "active" ? (- <>- <span className="bg-success/80 absolute inline-flex h-full w-full animate-ping rounded-full opacity-75" />- <span className="bg-success relative inline-flex h-2.5 w-2.5 rounded-full" />- </>- ) : monitor.status === "error" ? (- <span className="bg-destructive relative inline-flex h-2.5 w-2.5 rounded-full" />- ) : (- <span className="bg-warning relative inline-flex h-2.5 w-2.5 rounded-full" />- )}+ {health === "active" ? (+ <span className="bg-success/80 absolute inline-flex h-full w-full animate-ping rounded-full opacity-75" />+ ) : null}+ <span+ className={cn(+ "relative inline-flex h-2.5 w-2.5 rounded-full",+ dotColor[health],+ )}+ /><span className="sr-only">{text}</span></span></TooltipTrigger>diff --git a/apps/dashboard/src/data/entity-refs.client.test.ts b/apps/dashboard/src/data/entity-refs.client.test.tsnew file mode 100644index 000000000..1238723cf--- /dev/null+++ b/apps/dashboard/src/data/entity-refs.client.test.ts@@ -0,0 +1,67 @@+import { expect } from "@std/expect";+import { describe, it } from "@std/testing/bdd";++import {+ auditEntityKind,+ fieldRefKind,+ toEntityId,+ toEntityIds,+} from "./entity-refs.client";++describe("toEntityId", () => {+ for (const [value, expected] of [+ [4, 4],+ ["42", 42],+ [0, undefined],+ [-1, undefined],+ [1.5, undefined],+ ["", undefined],+ ["4a", undefined],+ [" 4", undefined],+ [null, undefined],+ [Number.MAX_SAFE_INTEGER + 1, undefined],+ ] as const) {+ it(`parses ${JSON.stringify(value)}`, () => {+ expect(toEntityId(value)).toBe(expected);+ });+ }+});++describe("toEntityIds", () => {+ it("returns every id of a numeric list", () => {+ expect(toEntityIds([3, 4])).toEqual([3, 4]);+ });++ it("rejects empty lists, strings and lists with one bad entry", () => {+ expect(toEntityIds([])).toBeUndefined();+ expect(toEntityIds(["3"])).toBeUndefined();+ expect(toEntityIds([3, 0])).toBeUndefined();+ expect(toEntityIds("3,4")).toBeUndefined();+ });+});++describe("fieldRefKind", () => {+ it("maps known id fields", () => {+ expect(fieldRefKind("pageId")).toBe("page");+ expect(fieldRefKind("monitorIds")).toBe("monitor");+ expect(fieldRefKind("componentImpacts")).toBe("componentImpacts");+ });++ it("ignores unknown and inherited keys", () => {+ expect(fieldRefKind("retry")).toBeUndefined();+ expect(fieldRefKind("constructor")).toBeUndefined();+ expect(fieldRefKind("toString")).toBeUndefined();+ });+});++describe("auditEntityKind", () => {+ it("maps audit entity types with a card", () => {+ expect(auditEntityKind("status_report")).toBe("statusReport");+ expect(auditEntityKind("private_location")).toBe("privateLocation");+ });++ it("returns undefined for types without a card", () => {+ expect(auditEntityKind("api_key")).toBeUndefined();+ expect(auditEntityKind("__proto__")).toBeUndefined();+ });+});diff --git a/apps/dashboard/src/data/entity-refs.client.ts b/apps/dashboard/src/data/entity-refs.client.tsnew file mode 100644index 000000000..d4aabfaab--- /dev/null+++ b/apps/dashboard/src/data/entity-refs.client.ts@@ -0,0 +1,145 @@+import type { AuditEntityType } from "@openstatus/db/src/schema/audit_logs/validation";+import {+ Components,+ Incident,+ type IconType,+ Maintenance,+ Monitor,+ Notification,+ PrivateLocation,+ Report,+ StatusPage,+} from "@openstatus/icons";++type EntityKindConfig = {+ label: string;+ icon: IconType;+ /** Change-row and tool-schema fields that hold this kind's id(s). */+ fields: readonly string[];+ /** The audit-log `entityType` for this kind. */+ auditType: AuditEntityType;+ /** Dashboard page for the entity. */+ href: (entity: never) => string;+};++/** One entry per referenceable entity; add a card in `entity-ref/cards` too. */+export const entityKinds = {+ page: {+ label: "Status page",+ icon: StatusPage,+ fields: ["pageId"],+ auditType: "page",+ href: (page: { id: number }) => `/status-pages/${page.id}/status-reports`,+ },+ pageComponent: {+ label: "Component",+ icon: Components,+ fields: ["pageComponentId", "pageComponentIds"],+ auditType: "page_component",+ href: (component: { pageId: number }) =>+ `/status-pages/${component.pageId}/components`,+ },+ monitor: {+ label: "Monitor",+ icon: Monitor,+ fields: ["monitorId", "monitorIds"],+ auditType: "monitor",+ href: (monitor: { id: number }) => `/monitors/${monitor.id}/overview`,+ },+ statusReport: {+ label: "Status report",+ icon: Report,+ fields: ["statusReportId"],+ auditType: "status_report",+ href: (report: { id: number; pageId: number }) =>+ `/status-pages/${report.pageId}/status-reports/${report.id}`,+ },+ maintenance: {+ label: "Maintenance",+ icon: Maintenance,+ fields: ["maintenanceId"],+ auditType: "maintenance",+ href: (maintenance: { id: number; pageId: number }) =>+ `/status-pages/${maintenance.pageId}/maintenances/${maintenance.id}`,+ },+ incident: {+ label: "Incident",+ icon: Incident,+ fields: ["incidentId"],+ auditType: "incident",+ href: (incident: { id: number }) => `/incidents/${incident.id}`,+ },+ privateLocation: {+ label: "Private location",+ icon: PrivateLocation,+ fields: ["privateLocationId", "privateLocationIds"],+ auditType: "private_location",+ href: () => "/settings/private-locations",+ },+ notification: {+ label: "Notification",+ icon: Notification,+ fields: ["notificationId", "notificationIds"],+ auditType: "notification",+ // Notifiers are edited in a sheet on the list; there is no detail page.+ href: () => "/notifications",+ },+} as const satisfies Record<string, EntityKindConfig>;++export type EntityKind = keyof typeof entityKinds;++// Safe because the keys of a `satisfies`-checked literal are exactly `EntityKind`.+export const entityKindList = Object.keys(entityKinds) as EntityKind[];++export type FieldRefKind = EntityKind | "componentImpacts";++// Maps, not object lookups, so inherited keys (`constructor`) never match.+const fieldKinds = new Map<string, FieldRefKind>([+ ...entityKindList.flatMap((kind) =>+ entityKinds[kind].fields.map((field) => [field, kind] as const),+ ),+ ["componentImpacts", "componentImpacts"],+]);++const auditKinds = new Map<string, EntityKind>(+ entityKindList.map((kind) => [entityKinds[kind].auditType, kind]),+);++/** What a change-row field references, by its name. */+export function fieldRefKind(field: string): FieldRefKind | undefined {+ return fieldKinds.get(field);+}++/** The ref kind for an audit-log `entityType`; `undefined` when it has no card. */+export function auditEntityKind(type: string): EntityKind | undefined {+ return auditKinds.get(type);+}++/** A positive integer id from a number or digit string, else `undefined`. */+export function toEntityId(value: unknown): number | undefined {+ const id =+ typeof value === "string" && /^\d+$/.test(value) ? Number(value) : value;+ return typeof id === "number" && Number.isSafeInteger(id) && id > 0+ ? id+ : undefined;+}++/** A non-empty list of ids, else `undefined` (one bad entry fails the list). */+export function toEntityIds(value: unknown): number[] | undefined {+ if (!Array.isArray(value) || value.length === 0) return undefined;+ const ids: number[] = [];+ for (const item of value) {+ // Strings stay text here: a diff value of "4" is not a reference.+ if (typeof item !== "number") return undefined;+ const id = toEntityId(item);+ if (id === undefined) return undefined;+ ids.push(id);+ }+ return ids;+}++/** `select` for list queries: the row with `id`, or `undefined`. */+export function findById(id: number) {+ return <T extends { id: number }>(rows: readonly T[] | undefined) =>+ rows?.find((row) => row.id === id);+}diff --git a/apps/dashboard/src/data/entity-refs.coverage.test.ts b/apps/dashboard/src/data/entity-refs.coverage.test.tsnew file mode 100644index 000000000..3c9a91b5d--- /dev/null+++ b/apps/dashboard/src/data/entity-refs.coverage.test.ts@@ -0,0 +1,98 @@+import { expect } from "@std/expect";+import { describe, it } from "@std/testing/bdd";++import {+ entityKindList,+ entityKinds,+ fieldRefKind,+} from "./entity-refs.client";++// The tool registry validates env and opens a db client on import; mirror the+// services test script. Nothing here queries, so the URL is never dialled.+// Next types NODE_ENV as read-only; widen to assign the test defaults.+const env: Record<string, string | undefined> = process.env;+for (const [key, value] of [+ ["NODE_ENV", "test"],+ ["RESEND_API_KEY", "test-key"],+ ["DATABASE_URL", "http://127.0.0.1:0"],+] as const) {+ env[key] ||= value;+}+const { agentTools } = await import("@openstatus/services/agent-tools");+const { z } = await import("zod");++/** Id fields that are not entity refs, with the reason they stay text. */+const notEntityRefs: Record<string, string> = {+ actorId: "user; no member lookup yet",+ commanderId: "user; no member lookup yet",+ entityId: "polymorphic; rendered through auditEntityKind",+ eventId: "incident timeline event, lives inside the incident",+ initialUpdateId: "status report update, lives inside the report",+ statusReportUpdateId: "status report update, lives inside the report",+ logId: "response log in Tinybird, no card",+ slackChannelId: "external Slack id",+};++function propertyKeys(node: unknown, keys = new Set<string>()): Set<string> {+ if (Array.isArray(node)) {+ for (const item of node) propertyKeys(item, keys);+ } else if (node && typeof node === "object") {+ if (+ "properties" in node &&+ node.properties &&+ typeof node.properties === "object"+ ) {+ for (const key of Object.keys(node.properties)) keys.add(key);+ }+ for (const value of Object.values(node)) propertyKeys(value, keys);+ }+ return keys;+}++function toolIdFields(): string[] {+ const keys = new Set<string>();+ for (const tool of Object.values(agentTools)) {+ for (const [schema, io] of [+ [tool.inputSchema, "input"],+ [tool.outputSchema, "output"],+ ] as const) {+ propertyKeys(+ z.toJSONSchema(schema, { unrepresentable: "any", io }),+ keys,+ );+ }+ }+ return [...keys].filter((key) => /.Ids?$/.test(key)).sort();+}++describe("entity ref coverage", () => {+ it("maps every agent-tool id field to a kind or lists why it stays text", () => {+ const unmapped = toolIdFields().filter(+ (field) => !fieldRefKind(field) && !(field in notEntityRefs),+ );+ expect(unmapped).toEqual([]);+ });++ it("keeps the ignore list honest", () => {+ const fields = new Set(toolIdFields());+ for (const field of Object.keys(notEntityRefs)) {+ expect({ field, mapped: fieldRefKind(field) }).toEqual({+ field,+ mapped: undefined,+ });+ expect({ field, inSchemas: fields.has(field) }).toEqual({+ field,+ inSchemas: true,+ });+ }+ });++ it("claims each field and audit type for one kind only", () => {+ const fields = entityKindList.flatMap((kind) => entityKinds[kind].fields);+ expect(new Set(fields).size).toBe(fields.length);+ const auditTypes = entityKindList.map(+ (kind) => entityKinds[kind].auditType,+ );+ expect(new Set(auditTypes).size).toBe(auditTypes.length);+ });+});diff --git a/apps/dashboard/src/data/monitors.client.test.ts b/apps/dashboard/src/data/monitors.client.test.tsnew file mode 100644index 000000000..7b1865c39--- /dev/null+++ b/apps/dashboard/src/data/monitors.client.test.ts@@ -0,0 +1,23 @@+import { expect } from "@std/expect";+import { describe, it } from "@std/testing/bdd";++import { getMonitorHealth } from "./monitors.client";++describe("getMonitorHealth", () => {+ it("follows the last check while active", () => {+ expect(getMonitorHealth({ active: true, status: "active" })).toBe("active");+ expect(getMonitorHealth({ active: true, status: "error" })).toBe("error");+ expect(getMonitorHealth({ active: true, status: "degraded" })).toBe(+ "degraded",+ );+ });++ it("reads as inactive when paused, whatever the last check said", () => {+ expect(getMonitorHealth({ active: false, status: "error" })).toBe(+ "inactive",+ );+ expect(getMonitorHealth({ active: null, status: "active" })).toBe(+ "inactive",+ );+ });+});diff --git a/apps/dashboard/src/data/monitors.client.ts b/apps/dashboard/src/data/monitors.client.tsindex 970fcf033..7ebcc4595 100644--- a/apps/dashboard/src/data/monitors.client.ts+++ b/apps/dashboard/src/data/monitors.client.ts@@ -1,3 +1,4 @@+import type { monitorStatus } from "@openstatus/db/src/schema/monitors/constants";import {Api,Settings,@@ -88,3 +89,22 @@ export const getActions = (onClick: props[action.id as keyof typeof props],}));};++type MonitorStatus = (typeof monitorStatus)[number];++export const monitorHealthConfig = {+ inactive: { label: "Inactive" },+ active: { label: "Normal" },+ degraded: { label: "Degraded" },+ error: { label: "Failing" },+} as const satisfies Record<MonitorStatus | "inactive", { label: string }>;++export type MonitorHealth = keyof typeof monitorHealthConfig;++/** A paused monitor reads as inactive whatever its last check said. */+export function getMonitorHealth(monitor: {+ active: boolean | null;+ status: MonitorStatus;+}): MonitorHealth {+ return monitor.active ? monitor.status : "inactive";+}diff --git a/apps/dashboard/src/data/overview-events.client.ts b/apps/dashboard/src/data/overview-events.client.tsindex 7974b57cf..285c0643e 100644--- a/apps/dashboard/src/data/overview-events.client.ts+++ b/apps/dashboard/src/data/overview-events.client.ts@@ -47,7 +47,7 @@ export type IncidentStatus = keyof typeof incidentStatusConfig;export const maintenanceStatusConfig = {scheduled: { label: "Scheduled", color: "text-info/80", variant: "info" },"in-progress": {- label: "In Progress",+ label: "In progress",color: "text-info/80",variant: "warning",},diff --git a/apps/dashboard/src/data/status-report-updates.client.test.ts b/apps/dashboard/src/data/status-report-updates.client.test.tsnew file mode 100644index 000000000..b9aa9b4a3--- /dev/null+++ b/apps/dashboard/src/data/status-report-updates.client.test.ts@@ -0,0 +1,34 @@+import { expect } from "@std/expect";+import { describe, it } from "@std/testing/bdd";++import {+ isComponentImpactList,+ isPageComponentImpact,+} from "./status-report-updates.client";++describe("isPageComponentImpact", () => {+ it("accepts known impacts only", () => {+ expect(isPageComponentImpact("major_outage")).toBe(true);+ expect(isPageComponentImpact("down")).toBe(false);+ expect(isPageComponentImpact(1)).toBe(false);+ });+});++describe("isComponentImpactList", () => {+ it("accepts structured impacts, including an empty list", () => {+ expect(+ isComponentImpactList([{ pageComponentId: 1, impact: "operational" }]),+ ).toBe(true);+ expect(isComponentImpactList([])).toBe(true);+ });++ it("rejects formatted strings, bad ids and unknown impacts", () => {+ expect(isComponentImpactList(["1 → major_outage"])).toBe(false);+ expect(+ isComponentImpactList([{ pageComponentId: 0, impact: "operational" }]),+ ).toBe(false);+ expect(+ isComponentImpactList([{ pageComponentId: 1, impact: "down" }]),+ ).toBe(false);+ });+});diff --git a/apps/dashboard/src/data/status-report-updates.client.ts b/apps/dashboard/src/data/status-report-updates.client.tsindex 9d21ea24d..dfcb10edd 100644--- a/apps/dashboard/src/data/status-report-updates.client.ts+++ b/apps/dashboard/src/data/status-report-updates.client.ts@@ -1,9 +1,13 @@import type { StatusReportStatus } from "@openstatus/db/src/schema";-import type { PageComponentImpact } from "@openstatus/db/src/schema/page_components/constants";+import {+ type PageComponentImpact,+ pageComponentImpact,+} from "@openstatus/db/src/schema/page_components/constants";import { Settings, Delete } from "@openstatus/icons";import type { StatusVariant } from "@/components/common/status-dot";import type { FormValues as StatusReportUpdateFormValues } from "@/components/forms/status-report-update/form";+import { toEntityId } from "@/data/entity-refs.client";export const impactConfig = {operational: {@@ -27,6 +31,38 @@ export const impactConfig = {{ label: string; variant: StatusVariant }>;+export type ComponentImpact = {+ pageComponentId: number;+ impact: PageComponentImpact;+};++export function isPageComponentImpact(+ value: unknown,+): value is PageComponentImpact {+ return (+ typeof value === "string" &&+ (pageComponentImpact as readonly string[]).includes(value)+ );+}++export function isComponentImpactList(+ value: unknown,+): value is ComponentImpact[] {+ return (+ Array.isArray(value) &&+ value.every(+ (item: unknown) =>+ typeof item === "object" &&+ item !== null &&+ "pageComponentId" in item &&+ "impact" in item &&+ typeof item.pageComponentId === "number" &&+ toEntityId(item.pageComponentId) !== undefined &&+ isPageComponentImpact(item.impact),+ )+ );+}+/** Set equality regardless of order — used to skip no-op impact writes. */export function impactsEqual(a: { pageComponentId: number; impact: string }[],diff --git a/apps/dashboard/src/lib/trpc/error.ts b/apps/dashboard/src/lib/trpc/error.tsindex 3074b978c..22199bdb4 100644--- a/apps/dashboard/src/lib/trpc/error.ts+++ b/apps/dashboard/src/lib/trpc/error.ts@@ -1,4 +1,5 @@import { isTRPCClientError } from "@trpc/client";+import { TRPCError } from "@trpc/server";/** What to show for a failed call: the server's message, else `fallback`. */export function errorMessage(@@ -7,3 +8,14 @@ export function errorMessage(): string {return isTRPCClientError(error) ? error.message : fallback;}++/** A NOT_FOUND from the browser client (`TRPCClientError`) or a server prefetch (`TRPCError`). */+export function isNotFound(error: unknown) {+ if (error instanceof TRPCError) return error.code === "NOT_FOUND";+ return isTRPCClientError(error) && error.data?.code === "NOT_FOUND";+}++/** A 404 the caller opted into (`expectNotFound`): a reference to a deleted entity, not a bug. */+export function isExpectedNotFound(error: unknown, expected: unknown) {+ return expected === true && isNotFound(error);+}diff --git a/apps/dashboard/src/lib/trpc/query-client.ts b/apps/dashboard/src/lib/trpc/query-client.tsindex 2eb918378..7758e46ff 100644--- a/apps/dashboard/src/lib/trpc/query-client.ts+++ b/apps/dashboard/src/lib/trpc/query-client.ts@@ -5,15 +5,19 @@ import {defaultShouldDehydrateQuery,} from "@tanstack/react-query";+import { isExpectedNotFound } from "./error";+export function makeQueryClient() {return new QueryClient({// `prefetchQuery` swallows rejections, so the cache is the only place left// to observe a failed server-side prefetch.queryCache: new QueryCache({- onError: (error, query) =>+ onError: (error, query) => {+ if (isExpectedNotFound(error, query.meta?.expectNotFound)) return;Sentry.captureException(error, {extra: { queryHash: query.queryHash },- }),+ });+ },}),defaultOptions: {queries: {diff --git a/apps/dashboard/src/lib/trpc/shared.ts b/apps/dashboard/src/lib/trpc/shared.tsindex 501d3afa1..8da1b5847 100644--- a/apps/dashboard/src/lib/trpc/shared.ts+++ b/apps/dashboard/src/lib/trpc/shared.ts@@ -4,6 +4,8 @@ import type { HTTPHeaders, TRPCLink } from "@trpc/client";import { httpBatchStreamLink, loggerLink } from "@trpc/client";import superjson from "superjson";+import { isExpectedNotFound } from "./error";+/*** tRPC logger link that reports failed queries to Sentry directly instead of* letting captureConsoleIntegration scrape tRPC's styled console.error format@@ -19,6 +21,9 @@ export const sentryLoggerLink = (): TRPCLink<AppRouter> =>(opts.direction === "down" && opts.result instanceof Error),logger: (opts) => {if (opts.direction === "down" && opts.result instanceof Error) {+ if (isExpectedNotFound(opts.result, opts.context.expectNotFound)) {+ return;+ }Sentry.captureException(opts.result, {extra: { path: opts.path },});diff --git a/packages/services/AGENTS.md b/packages/services/AGENTS.mdindex 8822dd6cb..75bc4c810 100644--- a/packages/services/AGENTS.md+++ b/packages/services/AGENTS.md@@ -39,6 +39,11 @@ Fail-closed: a failed audit insert rolls the mutation back.- **Strip secrets from snapshots** — credentials, bot tokens, raw API keys.- Action names are `{entity}.{verb}`; new variants go in the discriminated unionat `packages/db/src/schema/audit_logs/validation.ts`.+- An entity type the dashboard can show also gets an `entityKinds` entry in+ `apps/dashboard/src/data/entity-refs.client.ts`. Its `auditType` resolves the+ audit row's entity cell; its `fields` resolve diff fields by name. These are+ separate: list every `*Id`/`*Ids` field, or diffs show raw ids. A new `*Id`/`*Ids` field in an agent-tool schema fails+ `entity-refs.coverage.test.ts` until it is mapped there or listed as not a ref.A missing `emitAudit` or `requireScope` is a defect, not a style nit. Both arelint-enforced; if a verb genuinely needs neither, the inline disable must carrydiff --git a/packages/services/package.json b/packages/services/package.jsonindex acbc1917b..5a53925f7 100644--- a/packages/services/package.json+++ b/packages/services/package.json@@ -13,10 +13,6 @@"import": "./src/status-report/index.ts","types": "./src/status-report/index.ts"},- "./status-report/utils": {- "import": "./src/status-report/utils.ts",- "types": "./src/status-report/utils.ts"- },"./maintenance": {"import": "./src/maintenance/index.ts","types": "./src/maintenance/index.ts"diff --git a/packages/services/src/status-report/utils.ts b/packages/services/src/status-report/utils.tsindex c0035d6a7..b7e8d3484 100644--- a/packages/services/src/status-report/utils.ts+++ b/packages/services/src/status-report/utils.ts@@ -1,4 +1,3 @@-// dependency-free: imported by client bundles via the package subpath export.export function formatComponentImpacts(impacts: readonly { pageComponentId: number; impact: string }[],): string[] {