@agent-native/dispatch 0.1.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. package/dist/actions/index.d.ts.map +1 -1
  2. package/dist/actions/index.js +2 -0
  3. package/dist/actions/index.js.map +1 -1
  4. package/dist/actions/list-dispatch-usage-metrics.d.ts +3 -0
  5. package/dist/actions/list-dispatch-usage-metrics.d.ts.map +1 -0
  6. package/dist/actions/list-dispatch-usage-metrics.js +18 -0
  7. package/dist/actions/list-dispatch-usage-metrics.js.map +1 -0
  8. package/dist/actions/navigate.d.ts +1 -0
  9. package/dist/actions/navigate.d.ts.map +1 -1
  10. package/dist/actions/navigate.js +3 -17
  11. package/dist/actions/navigate.js.map +1 -1
  12. package/dist/actions/view-screen.d.ts.map +1 -1
  13. package/dist/actions/view-screen.js +19 -0
  14. package/dist/actions/view-screen.js.map +1 -1
  15. package/dist/components/agents-panel.js +3 -3
  16. package/dist/components/app-keys-popover.js +2 -2
  17. package/dist/components/create-app-popover.js +2 -2
  18. package/dist/components/dispatch-shell.js +2 -2
  19. package/dist/components/index.d.ts +1 -0
  20. package/dist/components/index.d.ts.map +1 -1
  21. package/dist/components/index.js.map +1 -1
  22. package/dist/components/layout/Header.js +4 -4
  23. package/dist/components/layout/Header.js.map +1 -1
  24. package/dist/components/layout/Layout.d.ts +28 -3
  25. package/dist/components/layout/Layout.d.ts.map +1 -1
  26. package/dist/components/layout/Layout.js +137 -26
  27. package/dist/components/layout/Layout.js.map +1 -1
  28. package/dist/components/messaging-setup-panel.js +4 -4
  29. package/dist/components/ui/accordion.js +1 -1
  30. package/dist/components/ui/alert-dialog.js +2 -2
  31. package/dist/components/ui/alert.js +1 -1
  32. package/dist/components/ui/avatar.js +1 -1
  33. package/dist/components/ui/badge.js +1 -1
  34. package/dist/components/ui/breadcrumb.js +1 -1
  35. package/dist/components/ui/button.js +1 -1
  36. package/dist/components/ui/calendar.js +2 -2
  37. package/dist/components/ui/card.js +1 -1
  38. package/dist/components/ui/carousel.d.ts +2 -2
  39. package/dist/components/ui/carousel.js +2 -2
  40. package/dist/components/ui/chart.js +1 -1
  41. package/dist/components/ui/checkbox.js +1 -1
  42. package/dist/components/ui/command.js +2 -2
  43. package/dist/components/ui/context-menu.js +1 -1
  44. package/dist/components/ui/dialog.js +1 -1
  45. package/dist/components/ui/drawer.js +1 -1
  46. package/dist/components/ui/dropdown-menu.js +1 -1
  47. package/dist/components/ui/form.js +2 -2
  48. package/dist/components/ui/hover-card.js +1 -1
  49. package/dist/components/ui/input-otp.js +1 -1
  50. package/dist/components/ui/input.js +1 -1
  51. package/dist/components/ui/label.js +1 -1
  52. package/dist/components/ui/menubar.js +1 -1
  53. package/dist/components/ui/navigation-menu.js +1 -1
  54. package/dist/components/ui/pagination.d.ts +1 -1
  55. package/dist/components/ui/pagination.js +2 -2
  56. package/dist/components/ui/popover.js +1 -1
  57. package/dist/components/ui/progress.js +1 -1
  58. package/dist/components/ui/radio-group.js +1 -1
  59. package/dist/components/ui/resizable.js +1 -1
  60. package/dist/components/ui/scroll-area.js +1 -1
  61. package/dist/components/ui/select.js +1 -1
  62. package/dist/components/ui/separator.js +1 -1
  63. package/dist/components/ui/sheet.js +1 -1
  64. package/dist/components/ui/sidebar.d.ts +2 -2
  65. package/dist/components/ui/sidebar.js +8 -8
  66. package/dist/components/ui/skeleton.js +1 -1
  67. package/dist/components/ui/slider.js +1 -1
  68. package/dist/components/ui/sonner.js +1 -1
  69. package/dist/components/ui/spinner.js +1 -1
  70. package/dist/components/ui/switch.js +1 -1
  71. package/dist/components/ui/table.js +1 -1
  72. package/dist/components/ui/tabs.js +1 -1
  73. package/dist/components/ui/textarea.js +1 -1
  74. package/dist/components/ui/toast.js +1 -1
  75. package/dist/components/ui/toaster.js +2 -2
  76. package/dist/components/ui/toggle-group.js +2 -2
  77. package/dist/components/ui/toggle.js +1 -1
  78. package/dist/components/ui/tooltip.js +1 -1
  79. package/dist/components/ui/use-toast.d.ts +1 -1
  80. package/dist/components/ui/use-toast.js +1 -1
  81. package/dist/hooks/use-navigation-state.d.ts +2 -1
  82. package/dist/hooks/use-navigation-state.d.ts.map +1 -1
  83. package/dist/hooks/use-navigation-state.js +36 -8
  84. package/dist/hooks/use-navigation-state.js.map +1 -1
  85. package/dist/hooks/use-toast.d.ts +1 -1
  86. package/dist/routes/index.d.ts.map +1 -1
  87. package/dist/routes/index.js +3 -2
  88. package/dist/routes/index.js.map +1 -1
  89. package/dist/routes/pages/_index.js +1 -1
  90. package/dist/routes/pages/agents.js +2 -2
  91. package/dist/routes/pages/approval.js +2 -2
  92. package/dist/routes/pages/approvals.js +4 -4
  93. package/dist/routes/pages/apps.$appId.js +3 -3
  94. package/dist/routes/pages/apps.js +5 -5
  95. package/dist/routes/pages/audit.js +1 -1
  96. package/dist/routes/pages/destinations.js +6 -6
  97. package/dist/routes/pages/extensions.$id.d.ts +2 -0
  98. package/dist/routes/pages/extensions.$id.d.ts.map +1 -0
  99. package/dist/routes/pages/extensions.$id.js +6 -0
  100. package/dist/routes/pages/extensions.$id.js.map +1 -0
  101. package/dist/routes/pages/extensions._index.d.ts +2 -0
  102. package/dist/routes/pages/extensions._index.d.ts.map +1 -0
  103. package/dist/routes/pages/extensions._index.js +6 -0
  104. package/dist/routes/pages/extensions._index.js.map +1 -0
  105. package/dist/routes/pages/identities.js +2 -2
  106. package/dist/routes/pages/integrations.js +4 -4
  107. package/dist/routes/pages/messaging.js +2 -2
  108. package/dist/routes/pages/metrics.d.ts +5 -0
  109. package/dist/routes/pages/metrics.d.ts.map +1 -0
  110. package/dist/routes/pages/metrics.js +135 -0
  111. package/dist/routes/pages/metrics.js.map +1 -0
  112. package/dist/routes/pages/new-app.js +1 -1
  113. package/dist/routes/pages/overview.d.ts.map +1 -1
  114. package/dist/routes/pages/overview.js +9 -17
  115. package/dist/routes/pages/overview.js.map +1 -1
  116. package/dist/routes/pages/team.js +1 -1
  117. package/dist/routes/pages/vault.js +10 -10
  118. package/dist/routes/pages/workspace.js +10 -10
  119. package/dist/server/lib/pre-auth-routing.d.ts.map +1 -1
  120. package/dist/server/lib/pre-auth-routing.js +9 -2
  121. package/dist/server/lib/pre-auth-routing.js.map +1 -1
  122. package/dist/server/lib/usage-metrics-store.d.ts +93 -0
  123. package/dist/server/lib/usage-metrics-store.d.ts.map +1 -0
  124. package/dist/server/lib/usage-metrics-store.js +386 -0
  125. package/dist/server/lib/usage-metrics-store.js.map +1 -0
  126. package/package.json +9 -5
  127. package/src/actions/index.ts +2 -0
  128. package/src/actions/list-dispatch-usage-metrics.ts +19 -0
  129. package/src/actions/navigate.ts +5 -17
  130. package/src/actions/view-screen.ts +18 -0
  131. package/src/components/index.ts +6 -0
  132. package/src/components/layout/Header.tsx +1 -1
  133. package/src/components/layout/Layout.tsx +194 -37
  134. package/src/hooks/use-navigation-state.ts +57 -8
  135. package/src/routes/index.ts +3 -2
  136. package/src/routes/pages/extensions.$id.tsx +5 -0
  137. package/src/routes/pages/extensions._index.tsx +5 -0
  138. package/src/routes/pages/metrics.tsx +667 -0
  139. package/src/routes/pages/overview.tsx +0 -10
  140. package/src/server/lib/pre-auth-routing.ts +10 -2
  141. package/src/server/lib/usage-metrics-store.ts +605 -0
@@ -2,12 +2,12 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useState } from "react";
3
3
  import { useActionMutation, useActionQuery } from "@agent-native/core/client";
4
4
  import { toast } from "sonner";
5
- import { DispatchShell } from "../../components/dispatch-shell";
6
- import { Button } from "../../components/ui/button";
7
- import { Input } from "../../components/ui/input";
8
- import { Textarea } from "../../components/ui/textarea";
9
- import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "../../components/ui/select";
10
- import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, } from "../../components/ui/alert-dialog";
5
+ import { DispatchShell } from "../../components/dispatch-shell.js";
6
+ import { Button } from "../../components/ui/button.js";
7
+ import { Input } from "../../components/ui/input.js";
8
+ import { Textarea } from "../../components/ui/textarea.js";
9
+ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "../../components/ui/select.js";
10
+ import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, } from "../../components/ui/alert-dialog.js";
11
11
  export function meta() {
12
12
  return [{ title: "Destinations — Dispatch" }];
13
13
  }
@@ -0,0 +1,2 @@
1
+ export default function ExtensionViewerRoute(): import("react/jsx-runtime").JSX.Element;
2
+ //# sourceMappingURL=extensions.$id.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extensions.$id.d.ts","sourceRoot":"","sources":["../../../src/routes/pages/extensions.$id.tsx"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,UAAU,oBAAoB,4CAE3C"}
@@ -0,0 +1,6 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { ToolViewerPage } from "@agent-native/core/client/tools";
3
+ export default function ExtensionViewerRoute() {
4
+ return _jsx(ToolViewerPage, {});
5
+ }
6
+ //# sourceMappingURL=extensions.$id.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extensions.$id.js","sourceRoot":"","sources":["../../../src/routes/pages/extensions.$id.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAEjE,MAAM,CAAC,OAAO,UAAU,oBAAoB;IAC1C,OAAO,KAAC,cAAc,KAAG,CAAC;AAC5B,CAAC","sourcesContent":["import { ToolViewerPage } from \"@agent-native/core/client/tools\";\n\nexport default function ExtensionViewerRoute() {\n return <ToolViewerPage />;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export default function ExtensionsRoute(): import("react/jsx-runtime").JSX.Element;
2
+ //# sourceMappingURL=extensions._index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extensions._index.d.ts","sourceRoot":"","sources":["../../../src/routes/pages/extensions._index.tsx"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,UAAU,eAAe,4CAEtC"}
@@ -0,0 +1,6 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { ToolsListPage } from "@agent-native/core/client/tools";
3
+ export default function ExtensionsRoute() {
4
+ return _jsx(ToolsListPage, {});
5
+ }
6
+ //# sourceMappingURL=extensions._index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extensions._index.js","sourceRoot":"","sources":["../../../src/routes/pages/extensions._index.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAEhE,MAAM,CAAC,OAAO,UAAU,eAAe;IACrC,OAAO,KAAC,aAAa,KAAG,CAAC;AAC3B,CAAC","sourcesContent":["import { ToolsListPage } from \"@agent-native/core/client/tools\";\n\nexport default function ExtensionsRoute() {\n return <ToolsListPage />;\n}\n"]}
@@ -1,8 +1,8 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useActionMutation, useActionQuery } from "@agent-native/core/client";
3
3
  import { toast } from "sonner";
4
- import { DispatchShell } from "../../components/dispatch-shell";
5
- import { Button } from "../../components/ui/button";
4
+ import { DispatchShell } from "../../components/dispatch-shell.js";
5
+ import { Button } from "../../components/ui/button.js";
6
6
  export function meta() {
7
7
  return [{ title: "Identities — Dispatch" }];
8
8
  }
@@ -2,10 +2,10 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
2
2
  import { useActionMutation, useActionQuery } from "@agent-native/core/client";
3
3
  import { toast } from "sonner";
4
4
  import { IconCheck, IconCircleDashed, IconKey, IconRefresh, IconShieldCheck, IconWifi, IconWifiOff, } from "@tabler/icons-react";
5
- import { DispatchShell } from "../../components/dispatch-shell";
6
- import { Badge } from "../../components/ui/badge";
7
- import { Button } from "../../components/ui/button";
8
- import { Progress } from "../../components/ui/progress";
5
+ import { DispatchShell } from "../../components/dispatch-shell.js";
6
+ import { Badge } from "../../components/ui/badge.js";
7
+ import { Button } from "../../components/ui/button.js";
8
+ import { Progress } from "../../components/ui/progress.js";
9
9
  export function meta() {
10
10
  return [{ title: "Integrations — Dispatch" }];
11
11
  }
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { MessagingSetupPanel } from "../../components/messaging-setup-panel";
3
- import { DispatchShell } from "../../components/dispatch-shell";
2
+ import { MessagingSetupPanel } from "../../components/messaging-setup-panel.js";
3
+ import { DispatchShell } from "../../components/dispatch-shell.js";
4
4
  export function meta() {
5
5
  return [{ title: "Messaging — Dispatch" }];
6
6
  }
@@ -0,0 +1,5 @@
1
+ export declare function meta(): {
2
+ title: string;
3
+ }[];
4
+ export default function MetricsRoute(): import("react/jsx-runtime").JSX.Element;
5
+ //# sourceMappingURL=metrics.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../../../src/routes/pages/metrics.tsx"],"names":[],"mappings":"AAmBA,wBAAgB,IAAI;;IAEnB;AA6gBD,MAAM,CAAC,OAAO,UAAU,YAAY,4CAwHnC"}
@@ -0,0 +1,135 @@
1
+ import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { useMemo, useState } from "react";
3
+ import { useActionQuery } from "@agent-native/core/client";
4
+ import { IconActivity, IconAlertTriangle, IconApps, IconChartBar, IconClockHour4, IconCoin, IconMessages, IconUsersGroup, } from "@tabler/icons-react";
5
+ import { DispatchShell } from "../../components/dispatch-shell.js";
6
+ import { Alert, AlertDescription, AlertTitle } from "../../components/ui/alert.js";
7
+ import { Badge } from "../../components/ui/badge.js";
8
+ import { Button } from "../../components/ui/button.js";
9
+ import { Skeleton } from "../../components/ui/skeleton.js";
10
+ import { cn } from "../../lib/utils.js";
11
+ export function meta() {
12
+ return [{ title: "Metrics — Dispatch" }];
13
+ }
14
+ const RANGES = [7, 30, 90];
15
+ function formatCost(cents) {
16
+ if (!Number.isFinite(cents) || cents === 0)
17
+ return "$0.00";
18
+ if (Math.abs(cents) < 1)
19
+ return `${cents.toFixed(3)}¢`;
20
+ if (Math.abs(cents) < 100)
21
+ return `${cents.toFixed(2)}¢`;
22
+ return (cents / 100).toLocaleString(undefined, {
23
+ style: "currency",
24
+ currency: "USD",
25
+ maximumFractionDigits: 2,
26
+ });
27
+ }
28
+ function formatNumber(value) {
29
+ return new Intl.NumberFormat(undefined, {
30
+ notation: value >= 10_000 ? "compact" : "standard",
31
+ maximumFractionDigits: value >= 10_000 ? 1 : 0,
32
+ }).format(value);
33
+ }
34
+ function formatTokens(value) {
35
+ return new Intl.NumberFormat(undefined, {
36
+ notation: "compact",
37
+ maximumFractionDigits: 1,
38
+ }).format(value);
39
+ }
40
+ function timeAgo(timestamp) {
41
+ if (!timestamp)
42
+ return "No activity";
43
+ const diff = Date.now() - timestamp;
44
+ if (diff < 60_000)
45
+ return "just now";
46
+ if (diff < 3_600_000)
47
+ return `${Math.floor(diff / 60_000)}m ago`;
48
+ if (diff < 86_400_000)
49
+ return `${Math.floor(diff / 3_600_000)}h ago`;
50
+ return `${Math.floor(diff / 86_400_000)}d ago`;
51
+ }
52
+ function displayApp(value) {
53
+ const trimmed = value?.trim();
54
+ if (!trimmed || trimmed === "unattributed")
55
+ return "Unattributed";
56
+ return trimmed;
57
+ }
58
+ function maxCost(rows) {
59
+ return rows.reduce((max, row) => Math.max(max, row.costCents), 0);
60
+ }
61
+ function barWidth(value, max) {
62
+ if (max <= 0 || value <= 0)
63
+ return "0%";
64
+ return `${Math.max(4, Math.round((value / max) * 100))}%`;
65
+ }
66
+ function RangeSelector({ value, onChange, }) {
67
+ return (_jsx("div", { className: "flex rounded-md border bg-card p-0.5", children: RANGES.map((range) => (_jsxs(Button, { type: "button", variant: value === range ? "secondary" : "ghost", size: "sm", className: "h-7 px-3 text-xs", onClick: () => onChange(range), children: [range, "d"] }, range))) }));
68
+ }
69
+ function MetricCard({ label, value, detail, icon, }) {
70
+ return (_jsxs("div", { className: "rounded-lg border bg-card p-4", children: [_jsxs("div", { className: "mb-3 flex items-center justify-between gap-3", children: [_jsx("span", { className: "text-xs font-medium text-muted-foreground", children: label }), _jsx("span", { className: "text-muted-foreground", children: icon })] }), _jsx("div", { className: "text-2xl font-semibold tabular-nums text-foreground", children: value }), _jsx("div", { className: "mt-1 truncate text-xs text-muted-foreground", children: detail })] }));
71
+ }
72
+ function Panel({ title, icon, children, action, }) {
73
+ return (_jsxs("section", { className: "rounded-lg border bg-card", children: [_jsxs("div", { className: "flex items-center justify-between gap-3 border-b px-4 py-3", children: [_jsxs("div", { className: "flex min-w-0 items-center gap-2", children: [_jsx("span", { className: "text-muted-foreground", children: icon }), _jsx("h2", { className: "truncate text-sm font-semibold text-foreground", children: title })] }), action] }), _jsx("div", { className: "p-4", children: children })] }));
74
+ }
75
+ function LoadingMetrics() {
76
+ return (_jsxs("div", { className: "space-y-4", children: [_jsx("div", { className: "grid gap-3 md:grid-cols-2 xl:grid-cols-5", children: Array.from({ length: 5 }).map((_, index) => (_jsxs("div", { className: "rounded-lg border bg-card p-4", children: [_jsx(Skeleton, { className: "mb-4 h-4 w-24" }), _jsx(Skeleton, { className: "h-7 w-20" }), _jsx(Skeleton, { className: "mt-3 h-3 w-28" })] }, index))) }), _jsx(Skeleton, { className: "h-80 rounded-lg" })] }));
77
+ }
78
+ function AppSpendRows({ rows }) {
79
+ const max = maxCost(rows);
80
+ if (rows.length === 0) {
81
+ return (_jsx("div", { className: "rounded-lg border border-dashed px-4 py-8 text-sm text-muted-foreground", children: "No LLM usage recorded for this window." }));
82
+ }
83
+ return (_jsx("div", { className: "space-y-3", children: rows.map((row) => (_jsxs("div", { className: "space-y-1.5", children: [_jsxs("div", { className: "flex items-center justify-between gap-3 text-sm", children: [_jsxs("div", { className: "min-w-0", children: [_jsx("div", { className: "truncate font-medium text-foreground", children: displayApp(row.key) }), _jsxs("div", { className: "text-xs text-muted-foreground", children: [formatNumber(row.chatCalls), " chats \u00B7", " ", formatNumber(row.activeUsers), " users"] })] }), _jsxs("div", { className: "shrink-0 text-right", children: [_jsx("div", { className: "font-medium tabular-nums text-foreground", children: formatCost(row.costCents) }), _jsxs("div", { className: "text-xs text-muted-foreground", children: [formatNumber(row.calls), " calls"] })] })] }), _jsx("div", { className: "h-2 overflow-hidden rounded-full bg-muted", children: _jsx("div", { className: "h-full rounded-full bg-foreground", style: { width: barWidth(row.costCents, max) } }) })] }, row.key))) }));
84
+ }
85
+ function DailyActivity({ rows }) {
86
+ const max = Math.max(1, rows.reduce((value, row) => Math.max(value, row.calls), 0));
87
+ if (rows.length === 0) {
88
+ return (_jsx("div", { className: "rounded-lg border border-dashed px-4 py-8 text-sm text-muted-foreground", children: "No activity in this window." }));
89
+ }
90
+ return (_jsx("div", { className: "flex h-44 items-end gap-1", children: rows.map((row) => (_jsxs("div", { className: "group flex min-w-0 flex-1 flex-col items-center gap-2", children: [_jsx("div", { className: "relative flex h-36 w-full items-end rounded-sm bg-muted/60", children: _jsx("div", { className: "w-full rounded-sm bg-foreground transition group-hover:bg-primary", style: { height: `${Math.max(4, (row.calls / max) * 100)}%` } }) }), _jsx("div", { className: "hidden text-[10px] text-muted-foreground sm:block", children: row.date.slice(5) })] }, row.date))) }));
91
+ }
92
+ function AppAccessTable({ rows }) {
93
+ const visibleRows = rows.filter((row) => !row.isDispatch);
94
+ if (visibleRows.length === 0) {
95
+ return (_jsx("div", { className: "rounded-lg border border-dashed px-4 py-8 text-sm text-muted-foreground", children: "No workspace apps discovered yet." }));
96
+ }
97
+ return (_jsx("div", { className: "overflow-x-auto", children: _jsxs("table", { className: "w-full min-w-[720px] text-left text-xs", children: [_jsx("thead", { children: _jsxs("tr", { className: "border-b text-muted-foreground", children: [_jsx("th", { className: "px-2 py-2 font-medium", children: "App" }), _jsx("th", { className: "px-2 py-2 font-medium", children: "Access" }), _jsx("th", { className: "px-2 py-2 text-right font-medium", children: "Users" }), _jsx("th", { className: "px-2 py-2 text-right font-medium", children: "Chats" }), _jsx("th", { className: "px-2 py-2 text-right font-medium", children: "Cost" }), _jsx("th", { className: "px-2 py-2 text-right font-medium", children: "Last activity" })] }) }), _jsx("tbody", { children: visibleRows.map((row) => (_jsxs("tr", { className: "border-b last:border-0", children: [_jsxs("td", { className: "px-2 py-3", children: [_jsx("div", { className: "font-medium text-foreground", children: row.name }), _jsx("div", { className: "font-mono text-[11px] text-muted-foreground", children: row.path })] }), _jsx("td", { className: "px-2 py-3", children: _jsx(Badge, { variant: "outline", className: cn(row.status === "pending" &&
98
+ "border-amber-500/30 bg-amber-500/10 text-amber-700 dark:text-amber-300"), children: row.status === "pending" ? "Building" : row.accessLabel }) }), _jsxs("td", { className: "px-2 py-3 text-right tabular-nums", children: [formatNumber(row.usersWithUsage), " /", " ", formatNumber(row.accessUsers)] }), _jsx("td", { className: "px-2 py-3 text-right tabular-nums", children: formatNumber(row.chatCalls) }), _jsx("td", { className: "px-2 py-3 text-right tabular-nums", children: formatCost(row.costCents) }), _jsx("td", { className: "px-2 py-3 text-right text-muted-foreground", children: timeAgo(row.lastActiveAt) })] }, row.id))) })] }) }));
99
+ }
100
+ function UserTable({ rows }) {
101
+ if (rows.length === 0) {
102
+ return (_jsx("div", { className: "rounded-lg border border-dashed px-4 py-8 text-sm text-muted-foreground", children: "No users have triggered LLM usage in this window." }));
103
+ }
104
+ return (_jsx("div", { className: "overflow-x-auto", children: _jsxs("table", { className: "w-full min-w-[760px] text-left text-xs", children: [_jsx("thead", { children: _jsxs("tr", { className: "border-b text-muted-foreground", children: [_jsx("th", { className: "px-2 py-2 font-medium", children: "User" }), _jsx("th", { className: "px-2 py-2 font-medium", children: "Role" }), _jsx("th", { className: "px-2 py-2 font-medium", children: "Top app" }), _jsx("th", { className: "px-2 py-2 text-right font-medium", children: "Chats" }), _jsx("th", { className: "px-2 py-2 text-right font-medium", children: "Threads" }), _jsx("th", { className: "px-2 py-2 text-right font-medium", children: "Tokens" }), _jsx("th", { className: "px-2 py-2 text-right font-medium", children: "Cost" })] }) }), _jsx("tbody", { children: rows.slice(0, 12).map((row) => (_jsxs("tr", { className: "border-b last:border-0", children: [_jsxs("td", { className: "max-w-64 px-2 py-3", children: [_jsx("div", { className: "truncate font-medium text-foreground", children: row.ownerEmail }), _jsx("div", { className: "text-muted-foreground", children: timeAgo(row.lastActiveAt ?? row.lastChatAt) })] }), _jsx("td", { className: "px-2 py-3", children: _jsx(Badge, { variant: "secondary", children: row.role ?? "user" }) }), _jsx("td", { className: "px-2 py-3 text-muted-foreground", children: displayApp(row.topApp) }), _jsx("td", { className: "px-2 py-3 text-right tabular-nums", children: formatNumber(row.chatCalls) }), _jsx("td", { className: "px-2 py-3 text-right tabular-nums", children: formatNumber(row.chatThreads) }), _jsx("td", { className: "px-2 py-3 text-right tabular-nums", children: formatTokens(row.inputTokens + row.outputTokens) }), _jsx("td", { className: "px-2 py-3 text-right tabular-nums", children: formatCost(row.costCents) })] }, row.ownerEmail))) })] }) }));
105
+ }
106
+ function CompactBreakdown({ rows, empty, }) {
107
+ const max = maxCost(rows);
108
+ if (rows.length === 0) {
109
+ return _jsx("div", { className: "text-sm text-muted-foreground", children: empty });
110
+ }
111
+ return (_jsx("div", { className: "space-y-3", children: rows.slice(0, 6).map((row) => (_jsxs("div", { className: "space-y-1", children: [_jsxs("div", { className: "flex items-center justify-between gap-3 text-xs", children: [_jsx("span", { className: "truncate font-medium text-foreground", children: row.label }), _jsx("span", { className: "shrink-0 tabular-nums text-muted-foreground", children: formatCost(row.costCents) })] }), _jsx("div", { className: "h-1.5 overflow-hidden rounded-full bg-muted", children: _jsx("div", { className: "h-full rounded-full bg-muted-foreground", style: { width: barWidth(row.costCents, max) } }) })] }, row.key))) }));
112
+ }
113
+ function RecentTable({ rows }) {
114
+ if (rows.length === 0) {
115
+ return (_jsx("div", { className: "rounded-lg border border-dashed px-4 py-8 text-sm text-muted-foreground", children: "No recent LLM calls." }));
116
+ }
117
+ return (_jsx("div", { className: "overflow-x-auto", children: _jsxs("table", { className: "w-full min-w-[760px] text-left text-xs", children: [_jsx("thead", { children: _jsxs("tr", { className: "border-b text-muted-foreground", children: [_jsx("th", { className: "px-2 py-2 font-medium", children: "When" }), _jsx("th", { className: "px-2 py-2 font-medium", children: "User" }), _jsx("th", { className: "px-2 py-2 font-medium", children: "App" }), _jsx("th", { className: "px-2 py-2 font-medium", children: "Label" }), _jsx("th", { className: "px-2 py-2 font-medium", children: "Model" }), _jsx("th", { className: "px-2 py-2 text-right font-medium", children: "Cost" })] }) }), _jsx("tbody", { children: rows.slice(0, 10).map((row) => (_jsxs("tr", { className: "border-b last:border-0", children: [_jsx("td", { className: "px-2 py-3 text-muted-foreground", children: timeAgo(row.createdAt) }), _jsx("td", { className: "max-w-56 px-2 py-3", children: _jsx("div", { className: "truncate text-foreground", children: row.ownerEmail }) }), _jsx("td", { className: "px-2 py-3 text-muted-foreground", children: displayApp(row.app) }), _jsx("td", { className: "px-2 py-3", children: _jsx(Badge, { variant: "outline", children: row.label }) }), _jsx("td", { className: "max-w-48 px-2 py-3", children: _jsx("div", { className: "truncate text-muted-foreground", children: row.model }) }), _jsx("td", { className: "px-2 py-3 text-right tabular-nums", children: formatCost(row.costCents) })] }, row.id))) })] }) }));
118
+ }
119
+ export default function MetricsRoute() {
120
+ const [sinceDays, setSinceDays] = useState(30);
121
+ const { data, isLoading, error } = useActionQuery("list-dispatch-usage-metrics", { sinceDays }, { refetchInterval: 30_000 });
122
+ const metrics = data;
123
+ const totalTokens = useMemo(() => {
124
+ if (!metrics)
125
+ return 0;
126
+ return (metrics.totals.inputTokens +
127
+ metrics.totals.outputTokens +
128
+ metrics.totals.cacheReadTokens +
129
+ metrics.totals.cacheWriteTokens);
130
+ }, [metrics]);
131
+ return (_jsx(DispatchShell, { title: "Metrics", description: "Workspace-wide LLM spend, chat volume, user activity, and app access.", children: _jsxs("div", { className: "space-y-4", children: [_jsxs("div", { className: "flex flex-wrap items-center justify-between gap-3", children: [_jsx("div", { className: "text-sm text-muted-foreground", children: metrics?.access.scope === "organization"
132
+ ? `${metrics.access.totalUsers} workspace users`
133
+ : `${metrics?.access.totalUsers ?? 0} signed-in users` }), _jsx(RangeSelector, { value: sinceDays, onChange: setSinceDays })] }), error ? (_jsxs(Alert, { variant: "destructive", children: [_jsx(IconAlertTriangle, { className: "h-4 w-4" }), _jsx(AlertTitle, { children: "Metrics unavailable" }), _jsx(AlertDescription, { children: error instanceof Error ? error.message : "Unable to load usage." })] })) : null, isLoading && !metrics ? _jsx(LoadingMetrics, {}) : null, metrics ? (_jsxs(_Fragment, { children: [_jsxs("div", { className: "grid gap-3 md:grid-cols-2 xl:grid-cols-5", children: [_jsx(MetricCard, { label: "Estimated spend", value: formatCost(metrics.totals.costCents), detail: `${formatTokens(totalTokens)} total tokens`, icon: _jsx(IconCoin, { size: 17 }) }), _jsx(MetricCard, { label: "LLM calls", value: formatNumber(metrics.totals.calls), detail: `${formatNumber(metrics.totals.chatCalls)} chat turns`, icon: _jsx(IconActivity, { size: 17 }) }), _jsx(MetricCard, { label: "Active users", value: formatNumber(metrics.totals.activeUsers), detail: `${formatNumber(metrics.access.totalUsers)} users with access`, icon: _jsx(IconUsersGroup, { size: 17 }) }), _jsx(MetricCard, { label: "Workspace apps", value: formatNumber(metrics.totals.workspaceApps), detail: `${formatNumber(metrics.byApp.length)} with usage`, icon: _jsx(IconApps, { size: 17 }) }), _jsx(MetricCard, { label: "Chat threads", value: formatNumber(metrics.totals.chatThreads), detail: `${formatNumber(metrics.totals.chatMessages)} messages`, icon: _jsx(IconMessages, { size: 17 }) })] }), _jsxs("div", { className: "grid gap-4 xl:grid-cols-[minmax(0,1.35fr)_minmax(320px,0.65fr)]", children: [_jsx(Panel, { title: "Spend By App", icon: _jsx(IconChartBar, { size: 16 }), children: _jsx(AppSpendRows, { rows: metrics.byApp }) }), _jsx(Panel, { title: "Daily Activity", icon: _jsx(IconClockHour4, { size: 16 }), children: _jsx(DailyActivity, { rows: metrics.daily }) })] }), _jsx(Panel, { title: "Access By App", icon: _jsx(IconApps, { size: 16 }), children: _jsx(AppAccessTable, { rows: metrics.appAccess }) }), _jsx(Panel, { title: "Users", icon: _jsx(IconUsersGroup, { size: 16 }), children: _jsx(UserTable, { rows: metrics.byUser }) }), _jsxs("div", { className: "grid gap-4 lg:grid-cols-2", children: [_jsx(Panel, { title: "Models", icon: _jsx(IconChartBar, { size: 16 }), children: _jsx(CompactBreakdown, { rows: metrics.byModel, empty: "No model usage in this window." }) }), _jsx(Panel, { title: "Work Types", icon: _jsx(IconActivity, { size: 16 }), children: _jsx(CompactBreakdown, { rows: metrics.byLabel, empty: "No labeled usage in this window." }) })] }), _jsx(Panel, { title: "Recent LLM Calls", icon: _jsx(IconActivity, { size: 16 }), children: _jsx(RecentTable, { rows: metrics.recent }) })] })) : null] }) }));
134
+ }
135
+ //# sourceMappingURL=metrics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metrics.js","sourceRoot":"","sources":["../../../src/routes/pages/metrics.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,QAAQ,EACR,YAAY,EACZ,cAAc,EACd,QAAQ,EACR,YAAY,EACZ,cAAc,GACf,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAC5E,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;A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Q,IAAC,IAAI,EAAE,EAAE,GAAI,YACvD,KAAC,cAAc,IAAC,IAAI,EAAE,OAAO,CAAC,SAAS,GAAI,GACrC,EAER,KAAC,KAAK,IAAC,KAAK,EAAC,OAAO,EAAC,IAAI,EAAE,KAAC,cAAc,IAAC,IAAI,EAAE,EAAE,GAAI,YACrD,KAAC,SAAS,IAAC,IAAI,EAAE,OAAO,CAAC,MAAM,GAAI,GAC7B,EAER,eAAK,SAAS,EAAC,2BAA2B,aACxC,KAAC,KAAK,IAAC,KAAK,EAAC,QAAQ,EAAC,IAAI,EAAE,KAAC,YAAY,IAAC,IAAI,EAAE,EAAE,GAAI,YACpD,KAAC,gBAAgB,IACf,IAAI,EAAE,OAAO,CAAC,OAAO,EACrB,KAAK,EAAC,gCAAgC,GACtC,GACI,EACR,KAAC,KAAK,IAAC,KAAK,EAAC,YAAY,EAAC,IAAI,EAAE,KAAC,YAAY,IAAC,IAAI,EAAE,EAAE,GAAI,YACxD,KAAC,gBAAgB,IACf,IAAI,EAAE,OAAO,CAAC,OAAO,EACrB,KAAK,EAAC,kCAAkC,GACxC,GACI,IACJ,EAEN,KAAC,KAAK,IAAC,KAAK,EAAC,kBAAkB,EAAC,IAAI,EAAE,KAAC,YAAY,IAAC,IAAI,EAAE,EAAE,GAAI,YAC9D,KAAC,WAAW,IAAC,IAAI,EAAE,OAAO,CAAC,MAAM,GAAI,GAC/B,IACP,CACJ,CAAC,CAAC,CAAC,IAAI,IACJ,GACQ,CACjB,CAAC;AACJ,CAAC","sourcesContent":["import { useMemo, useState, type ReactNode } from \"react\";\nimport { useActionQuery } from \"@agent-native/core/client\";\nimport {\n IconActivity,\n IconAlertTriangle,\n IconApps,\n IconChartBar,\n IconClockHour4,\n IconCoin,\n IconMessages,\n IconUsersGroup,\n} from \"@tabler/icons-react\";\nimport { DispatchShell } from \"@/components/dispatch-shell\";\nimport { Alert, AlertDescription, AlertTitle } from \"@/components/ui/alert\";\nimport { Badge } from \"@/components/ui/badge\";\nimport { Button } from \"@/components/ui/button\";\nimport { Skeleton } from \"@/components/ui/skeleton\";\nimport { cn } from \"@/lib/utils\";\n\nexport function meta() {\n return [{ title: \"Metrics — Dispatch\" }];\n}\n\ninterface UsageMetricBucket {\n key: string;\n label: string;\n costCents: number;\n calls: number;\n chatCalls: number;\n inputTokens: number;\n outputTokens: number;\n activeUsers: number;\n lastActiveAt: number | null;\n}\n\ninterface UserUsageMetric extends UsageMetricBucket {\n ownerEmail: string;\n chatThreads: number;\n chatMessages: number;\n lastChatAt: number | null;\n topApp: string | null;\n role: string | null;\n}\n\ninterface AppAccessMetric {\n id: string;\n name: string;\n path: string;\n status?: \"ready\" | \"pending\";\n isDispatch: boolean;\n accessLabel: string;\n accessUsers: number;\n usersWithUsage: number;\n usageCalls: number;\n chatCalls: number;\n costCents: number;\n lastActiveAt: number | null;\n}\n\ninterface DailyUsageMetric {\n date: string;\n costCents: number;\n calls: number;\n chatCalls: number;\n activeUsers: number;\n}\n\ninterface RecentUsageMetric {\n id: number;\n createdAt: number;\n ownerEmail: string;\n app: string;\n label: string;\n model: string;\n inputTokens: number;\n outputTokens: number;\n costCents: number;\n}\n\ninterface DispatchUsageMetrics {\n sinceDays: number;\n access: {\n viewerEmail: string;\n orgId: string | null;\n role: string | null;\n scope: \"organization\" | \"solo\";\n totalUsers: number;\n };\n totals: {\n costCents: number;\n calls: number;\n chatCalls: number;\n inputTokens: number;\n outputTokens: number;\n cacheReadTokens: number;\n cacheWriteTokens: number;\n activeUsers: number;\n chatThreads: number;\n chatMessages: number;\n workspaceApps: number;\n };\n byApp: UsageMetricBucket[];\n byUser: UserUsageMetric[];\n byLabel: UsageMetricBucket[];\n byModel: UsageMetricBucket[];\n daily: DailyUsageMetric[];\n appAccess: AppAccessMetric[];\n recent: RecentUsageMetric[];\n}\n\nconst RANGES = [7, 30, 90] as const;\n\nfunction formatCost(cents: number): string {\n if (!Number.isFinite(cents) || cents === 0) return \"$0.00\";\n if (Math.abs(cents) < 1) return `${cents.toFixed(3)}¢`;\n if (Math.abs(cents) < 100) return `${cents.toFixed(2)}¢`;\n return (cents / 100).toLocaleString(undefined, {\n style: \"currency\",\n currency: \"USD\",\n maximumFractionDigits: 2,\n });\n}\n\nfunction formatNumber(value: number): string {\n return new Intl.NumberFormat(undefined, {\n notation: value >= 10_000 ? \"compact\" : \"standard\",\n maximumFractionDigits: value >= 10_000 ? 1 : 0,\n }).format(value);\n}\n\nfunction formatTokens(value: number): string {\n return new Intl.NumberFormat(undefined, {\n notation: \"compact\",\n maximumFractionDigits: 1,\n }).format(value);\n}\n\nfunction timeAgo(timestamp: number | null): string {\n if (!timestamp) return \"No activity\";\n const diff = Date.now() - timestamp;\n if (diff < 60_000) return \"just now\";\n if (diff < 3_600_000) return `${Math.floor(diff / 60_000)}m ago`;\n if (diff < 86_400_000) return `${Math.floor(diff / 3_600_000)}h ago`;\n return `${Math.floor(diff / 86_400_000)}d ago`;\n}\n\nfunction displayApp(value: string | null | undefined): string {\n const trimmed = value?.trim();\n if (!trimmed || trimmed === \"unattributed\") return \"Unattributed\";\n return trimmed;\n}\n\nfunction maxCost(rows: Array<{ costCents: number }>): number {\n return rows.reduce((max, row) => Math.max(max, row.costCents), 0);\n}\n\nfunction barWidth(value: number, max: number): string {\n if (max <= 0 || value <= 0) return \"0%\";\n return `${Math.max(4, Math.round((value / max) * 100))}%`;\n}\n\nfunction RangeSelector({\n value,\n onChange,\n}: {\n value: number;\n onChange: (value: number) => void;\n}) {\n return (\n <div className=\"flex rounded-md border bg-card p-0.5\">\n {RANGES.map((range) => (\n <Button\n key={range}\n type=\"button\"\n variant={value === range ? \"secondary\" : \"ghost\"}\n size=\"sm\"\n className=\"h-7 px-3 text-xs\"\n onClick={() => onChange(range)}\n >\n {range}d\n </Button>\n ))}\n </div>\n );\n}\n\nfunction MetricCard({\n label,\n value,\n detail,\n icon,\n}: {\n label: string;\n value: string;\n detail: string;\n icon: ReactNode;\n}) {\n return (\n <div className=\"rounded-lg border bg-card p-4\">\n <div className=\"mb-3 flex items-center justify-between gap-3\">\n <span className=\"text-xs font-medium text-muted-foreground\">\n {label}\n </span>\n <span className=\"text-muted-foreground\">{icon}</span>\n </div>\n <div className=\"text-2xl font-semibold tabular-nums text-foreground\">\n {value}\n </div>\n <div className=\"mt-1 truncate text-xs text-muted-foreground\">\n {detail}\n </div>\n </div>\n );\n}\n\nfunction Panel({\n title,\n icon,\n children,\n action,\n}: {\n title: string;\n icon: ReactNode;\n children: ReactNode;\n action?: ReactNode;\n}) {\n return (\n <section className=\"rounded-lg border bg-card\">\n <div className=\"flex items-center justify-between gap-3 border-b px-4 py-3\">\n <div className=\"flex min-w-0 items-center gap-2\">\n <span className=\"text-muted-foreground\">{icon}</span>\n <h2 className=\"truncate text-sm font-semibold text-foreground\">\n {title}\n </h2>\n </div>\n {action}\n </div>\n <div className=\"p-4\">{children}</div>\n </section>\n );\n}\n\nfunction LoadingMetrics() {\n return (\n <div className=\"space-y-4\">\n <div className=\"grid gap-3 md:grid-cols-2 xl:grid-cols-5\">\n {Array.from({ length: 5 }).map((_, index) => (\n <div key={index} className=\"rounded-lg border bg-card p-4\">\n <Skeleton className=\"mb-4 h-4 w-24\" />\n <Skeleton className=\"h-7 w-20\" />\n <Skeleton className=\"mt-3 h-3 w-28\" />\n </div>\n ))}\n </div>\n <Skeleton className=\"h-80 rounded-lg\" />\n </div>\n );\n}\n\nfunction AppSpendRows({ rows }: { rows: UsageMetricBucket[] }) {\n const max = maxCost(rows);\n if (rows.length === 0) {\n return (\n <div className=\"rounded-lg border border-dashed px-4 py-8 text-sm text-muted-foreground\">\n No LLM usage recorded for this window.\n </div>\n );\n }\n return (\n <div className=\"space-y-3\">\n {rows.map((row) => (\n <div key={row.key} className=\"space-y-1.5\">\n <div className=\"flex items-center justify-between gap-3 text-sm\">\n <div className=\"min-w-0\">\n <div className=\"truncate font-medium text-foreground\">\n {displayApp(row.key)}\n </div>\n <div className=\"text-xs text-muted-foreground\">\n {formatNumber(row.chatCalls)} chats ·{\" \"}\n {formatNumber(row.activeUsers)} users\n </div>\n </div>\n <div className=\"shrink-0 text-right\">\n <div className=\"font-medium tabular-nums text-foreground\">\n {formatCost(row.costCents)}\n </div>\n <div className=\"text-xs text-muted-foreground\">\n {formatNumber(row.calls)} calls\n </div>\n </div>\n </div>\n <div className=\"h-2 overflow-hidden rounded-full bg-muted\">\n <div\n className=\"h-full rounded-full bg-foreground\"\n style={{ width: barWidth(row.costCents, max) }}\n />\n </div>\n </div>\n ))}\n </div>\n );\n}\n\nfunction DailyActivity({ rows }: { rows: DailyUsageMetric[] }) {\n const max = Math.max(\n 1,\n rows.reduce((value, row) => Math.max(value, row.calls), 0),\n );\n if (rows.length === 0) {\n return (\n <div className=\"rounded-lg border border-dashed px-4 py-8 text-sm text-muted-foreground\">\n No activity in this window.\n </div>\n );\n }\n return (\n <div className=\"flex h-44 items-end gap-1\">\n {rows.map((row) => (\n <div\n key={row.date}\n className=\"group flex min-w-0 flex-1 flex-col items-center gap-2\"\n >\n <div className=\"relative flex h-36 w-full items-end rounded-sm bg-muted/60\">\n <div\n className=\"w-full rounded-sm bg-foreground transition group-hover:bg-primary\"\n style={{ height: `${Math.max(4, (row.calls / max) * 100)}%` }}\n />\n </div>\n <div className=\"hidden text-[10px] text-muted-foreground sm:block\">\n {row.date.slice(5)}\n </div>\n </div>\n ))}\n </div>\n );\n}\n\nfunction AppAccessTable({ rows }: { rows: AppAccessMetric[] }) {\n const visibleRows = rows.filter((row) => !row.isDispatch);\n if (visibleRows.length === 0) {\n return (\n <div className=\"rounded-lg border border-dashed px-4 py-8 text-sm text-muted-foreground\">\n No workspace apps discovered yet.\n </div>\n );\n }\n return (\n <div className=\"overflow-x-auto\">\n <table className=\"w-full min-w-[720px] text-left text-xs\">\n <thead>\n <tr className=\"border-b text-muted-foreground\">\n <th className=\"px-2 py-2 font-medium\">App</th>\n <th className=\"px-2 py-2 font-medium\">Access</th>\n <th className=\"px-2 py-2 text-right font-medium\">Users</th>\n <th className=\"px-2 py-2 text-right font-medium\">Chats</th>\n <th className=\"px-2 py-2 text-right font-medium\">Cost</th>\n <th className=\"px-2 py-2 text-right font-medium\">Last activity</th>\n </tr>\n </thead>\n <tbody>\n {visibleRows.map((row) => (\n <tr key={row.id} className=\"border-b last:border-0\">\n <td className=\"px-2 py-3\">\n <div className=\"font-medium text-foreground\">{row.name}</div>\n <div className=\"font-mono text-[11px] text-muted-foreground\">\n {row.path}\n </div>\n </td>\n <td className=\"px-2 py-3\">\n <Badge\n variant=\"outline\"\n className={cn(\n row.status === \"pending\" &&\n \"border-amber-500/30 bg-amber-500/10 text-amber-700 dark:text-amber-300\",\n )}\n >\n {row.status === \"pending\" ? \"Building\" : row.accessLabel}\n </Badge>\n </td>\n <td className=\"px-2 py-3 text-right tabular-nums\">\n {formatNumber(row.usersWithUsage)} /{\" \"}\n {formatNumber(row.accessUsers)}\n </td>\n <td className=\"px-2 py-3 text-right tabular-nums\">\n {formatNumber(row.chatCalls)}\n </td>\n <td className=\"px-2 py-3 text-right tabular-nums\">\n {formatCost(row.costCents)}\n </td>\n <td className=\"px-2 py-3 text-right text-muted-foreground\">\n {timeAgo(row.lastActiveAt)}\n </td>\n </tr>\n ))}\n </tbody>\n </table>\n </div>\n );\n}\n\nfunction UserTable({ rows }: { rows: UserUsageMetric[] }) {\n if (rows.length === 0) {\n return (\n <div className=\"rounded-lg border border-dashed px-4 py-8 text-sm text-muted-foreground\">\n No users have triggered LLM usage in this window.\n </div>\n );\n }\n return (\n <div className=\"overflow-x-auto\">\n <table className=\"w-full min-w-[760px] text-left text-xs\">\n <thead>\n <tr className=\"border-b text-muted-foreground\">\n <th className=\"px-2 py-2 font-medium\">User</th>\n <th className=\"px-2 py-2 font-medium\">Role</th>\n <th className=\"px-2 py-2 font-medium\">Top app</th>\n <th className=\"px-2 py-2 text-right font-medium\">Chats</th>\n <th className=\"px-2 py-2 text-right font-medium\">Threads</th>\n <th className=\"px-2 py-2 text-right font-medium\">Tokens</th>\n <th className=\"px-2 py-2 text-right font-medium\">Cost</th>\n </tr>\n </thead>\n <tbody>\n {rows.slice(0, 12).map((row) => (\n <tr key={row.ownerEmail} className=\"border-b last:border-0\">\n <td className=\"max-w-64 px-2 py-3\">\n <div className=\"truncate font-medium text-foreground\">\n {row.ownerEmail}\n </div>\n <div className=\"text-muted-foreground\">\n {timeAgo(row.lastActiveAt ?? row.lastChatAt)}\n </div>\n </td>\n <td className=\"px-2 py-3\">\n <Badge variant=\"secondary\">{row.role ?? \"user\"}</Badge>\n </td>\n <td className=\"px-2 py-3 text-muted-foreground\">\n {displayApp(row.topApp)}\n </td>\n <td className=\"px-2 py-3 text-right tabular-nums\">\n {formatNumber(row.chatCalls)}\n </td>\n <td className=\"px-2 py-3 text-right tabular-nums\">\n {formatNumber(row.chatThreads)}\n </td>\n <td className=\"px-2 py-3 text-right tabular-nums\">\n {formatTokens(row.inputTokens + row.outputTokens)}\n </td>\n <td className=\"px-2 py-3 text-right tabular-nums\">\n {formatCost(row.costCents)}\n </td>\n </tr>\n ))}\n </tbody>\n </table>\n </div>\n );\n}\n\nfunction CompactBreakdown({\n rows,\n empty,\n}: {\n rows: UsageMetricBucket[];\n empty: string;\n}) {\n const max = maxCost(rows);\n if (rows.length === 0) {\n return <div className=\"text-sm text-muted-foreground\">{empty}</div>;\n }\n return (\n <div className=\"space-y-3\">\n {rows.slice(0, 6).map((row) => (\n <div key={row.key} className=\"space-y-1\">\n <div className=\"flex items-center justify-between gap-3 text-xs\">\n <span className=\"truncate font-medium text-foreground\">\n {row.label}\n </span>\n <span className=\"shrink-0 tabular-nums text-muted-foreground\">\n {formatCost(row.costCents)}\n </span>\n </div>\n <div className=\"h-1.5 overflow-hidden rounded-full bg-muted\">\n <div\n className=\"h-full rounded-full bg-muted-foreground\"\n style={{ width: barWidth(row.costCents, max) }}\n />\n </div>\n </div>\n ))}\n </div>\n );\n}\n\nfunction RecentTable({ rows }: { rows: RecentUsageMetric[] }) {\n if (rows.length === 0) {\n return (\n <div className=\"rounded-lg border border-dashed px-4 py-8 text-sm text-muted-foreground\">\n No recent LLM calls.\n </div>\n );\n }\n return (\n <div className=\"overflow-x-auto\">\n <table className=\"w-full min-w-[760px] text-left text-xs\">\n <thead>\n <tr className=\"border-b text-muted-foreground\">\n <th className=\"px-2 py-2 font-medium\">When</th>\n <th className=\"px-2 py-2 font-medium\">User</th>\n <th className=\"px-2 py-2 font-medium\">App</th>\n <th className=\"px-2 py-2 font-medium\">Label</th>\n <th className=\"px-2 py-2 font-medium\">Model</th>\n <th className=\"px-2 py-2 text-right font-medium\">Cost</th>\n </tr>\n </thead>\n <tbody>\n {rows.slice(0, 10).map((row) => (\n <tr key={row.id} className=\"border-b last:border-0\">\n <td className=\"px-2 py-3 text-muted-foreground\">\n {timeAgo(row.createdAt)}\n </td>\n <td className=\"max-w-56 px-2 py-3\">\n <div className=\"truncate text-foreground\">{row.ownerEmail}</div>\n </td>\n <td className=\"px-2 py-3 text-muted-foreground\">\n {displayApp(row.app)}\n </td>\n <td className=\"px-2 py-3\">\n <Badge variant=\"outline\">{row.label}</Badge>\n </td>\n <td className=\"max-w-48 px-2 py-3\">\n <div className=\"truncate text-muted-foreground\">\n {row.model}\n </div>\n </td>\n <td className=\"px-2 py-3 text-right tabular-nums\">\n {formatCost(row.costCents)}\n </td>\n </tr>\n ))}\n </tbody>\n </table>\n </div>\n );\n}\n\nexport default function MetricsRoute() {\n const [sinceDays, setSinceDays] = useState(30);\n const { data, isLoading, error } = useActionQuery(\n \"list-dispatch-usage-metrics\",\n { sinceDays },\n { refetchInterval: 30_000 },\n );\n const metrics = data as DispatchUsageMetrics | undefined;\n const totalTokens = useMemo(() => {\n if (!metrics) return 0;\n return (\n metrics.totals.inputTokens +\n metrics.totals.outputTokens +\n metrics.totals.cacheReadTokens +\n metrics.totals.cacheWriteTokens\n );\n }, [metrics]);\n\n return (\n <DispatchShell\n title=\"Metrics\"\n description=\"Workspace-wide LLM spend, chat volume, user activity, and app access.\"\n >\n <div className=\"space-y-4\">\n <div className=\"flex flex-wrap items-center justify-between gap-3\">\n <div className=\"text-sm text-muted-foreground\">\n {metrics?.access.scope === \"organization\"\n ? `${metrics.access.totalUsers} workspace users`\n : `${metrics?.access.totalUsers ?? 0} signed-in users`}\n </div>\n <RangeSelector value={sinceDays} onChange={setSinceDays} />\n </div>\n\n {error ? (\n <Alert variant=\"destructive\">\n <IconAlertTriangle className=\"h-4 w-4\" />\n <AlertTitle>Metrics unavailable</AlertTitle>\n <AlertDescription>\n {error instanceof Error ? error.message : \"Unable to load usage.\"}\n </AlertDescription>\n </Alert>\n ) : null}\n\n {isLoading && !metrics ? <LoadingMetrics /> : null}\n\n {metrics ? (\n <>\n <div className=\"grid gap-3 md:grid-cols-2 xl:grid-cols-5\">\n <MetricCard\n label=\"Estimated spend\"\n value={formatCost(metrics.totals.costCents)}\n detail={`${formatTokens(totalTokens)} total tokens`}\n icon={<IconCoin size={17} />}\n />\n <MetricCard\n label=\"LLM calls\"\n value={formatNumber(metrics.totals.calls)}\n detail={`${formatNumber(metrics.totals.chatCalls)} chat turns`}\n icon={<IconActivity size={17} />}\n />\n <MetricCard\n label=\"Active users\"\n value={formatNumber(metrics.totals.activeUsers)}\n detail={`${formatNumber(metrics.access.totalUsers)} users with access`}\n icon={<IconUsersGroup size={17} />}\n />\n <MetricCard\n label=\"Workspace apps\"\n value={formatNumber(metrics.totals.workspaceApps)}\n detail={`${formatNumber(metrics.byApp.length)} with usage`}\n icon={<IconApps size={17} />}\n />\n <MetricCard\n label=\"Chat threads\"\n value={formatNumber(metrics.totals.chatThreads)}\n detail={`${formatNumber(metrics.totals.chatMessages)} messages`}\n icon={<IconMessages size={17} />}\n />\n </div>\n\n <div className=\"grid gap-4 xl:grid-cols-[minmax(0,1.35fr)_minmax(320px,0.65fr)]\">\n <Panel title=\"Spend By App\" icon={<IconChartBar size={16} />}>\n <AppSpendRows rows={metrics.byApp} />\n </Panel>\n <Panel title=\"Daily Activity\" icon={<IconClockHour4 size={16} />}>\n <DailyActivity rows={metrics.daily} />\n </Panel>\n </div>\n\n <Panel title=\"Access By App\" icon={<IconApps size={16} />}>\n <AppAccessTable rows={metrics.appAccess} />\n </Panel>\n\n <Panel title=\"Users\" icon={<IconUsersGroup size={16} />}>\n <UserTable rows={metrics.byUser} />\n </Panel>\n\n <div className=\"grid gap-4 lg:grid-cols-2\">\n <Panel title=\"Models\" icon={<IconChartBar size={16} />}>\n <CompactBreakdown\n rows={metrics.byModel}\n empty=\"No model usage in this window.\"\n />\n </Panel>\n <Panel title=\"Work Types\" icon={<IconActivity size={16} />}>\n <CompactBreakdown\n rows={metrics.byLabel}\n empty=\"No labeled usage in this window.\"\n />\n </Panel>\n </div>\n\n <Panel title=\"Recent LLM Calls\" icon={<IconActivity size={16} />}>\n <RecentTable rows={metrics.recent} />\n </Panel>\n </>\n ) : null}\n </div>\n </DispatchShell>\n );\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { NewWorkspaceAppFlow } from "@agent-native/core/client";
3
- import { DispatchShell } from "../../components/dispatch-shell";
3
+ import { DispatchShell } from "../../components/dispatch-shell.js";
4
4
  export function meta() {
5
5
  return [{ title: "New App — Dispatch" }];
6
6
  }
@@ -1 +1 @@
1
- {"version":3,"file":"overview.d.ts","sourceRoot":"","sources":["../../../src/routes/pages/overview.tsx"],"names":[],"mappings":"AAyeA,wBAAgB,IAAI;;IAEnB;AAED,MAAM,CAAC,OAAO,UAAU,aAAa,4CA0SpC"}
1
+ {"version":3,"file":"overview.d.ts","sourceRoot":"","sources":["../../../src/routes/pages/overview.tsx"],"names":[],"mappings":"AA+dA,wBAAgB,IAAI;;IAEnB;AAED,MAAM,CAAC,OAAO,UAAU,aAAa,4CA0SpC"}
@@ -1,16 +1,16 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useEffect, useMemo, useState } from "react";
3
3
  import { Link } from "react-router";
4
- import { PromptComposer, isInBuilderFrame, sendToAgentChat, sendToBuilderChat, useActionQuery, useChatModels, agentNativePath, } from "@agent-native/core/client";
4
+ import { PromptComposer, sendToAgentChat, useActionQuery, useChatModels, agentNativePath, } from "@agent-native/core/client";
5
5
  import { IconActivity, IconAlertTriangle, IconApps, IconArrowUpRight, IconCheck, IconClockHour4, IconInfoCircle, IconKey, IconListCheck, IconRocket, IconPlugConnected, IconShieldCheck, } from "@tabler/icons-react";
6
- import { AppKeysPopover } from "../../components/app-keys-popover";
7
- import { CreateAppPopover } from "../../components/create-app-popover";
8
- import { DispatchShell } from "../../components/dispatch-shell";
9
- import { Alert, AlertDescription, AlertTitle } from "../../components/ui/alert";
10
- import { Badge } from "../../components/ui/badge";
11
- import { Button } from "../../components/ui/button";
12
- import { Skeleton } from "../../components/ui/skeleton";
13
- import { Tooltip, TooltipContent, TooltipTrigger, } from "../../components/ui/tooltip";
6
+ import { AppKeysPopover } from "../../components/app-keys-popover.js";
7
+ import { CreateAppPopover } from "../../components/create-app-popover.js";
8
+ import { DispatchShell } from "../../components/dispatch-shell.js";
9
+ import { Alert, AlertDescription, AlertTitle } from "../../components/ui/alert.js";
10
+ import { Badge } from "../../components/ui/badge.js";
11
+ import { Button } from "../../components/ui/button.js";
12
+ import { Skeleton } from "../../components/ui/skeleton.js";
13
+ import { Tooltip, TooltipContent, TooltipTrigger, } from "../../components/ui/tooltip.js";
14
14
  const ZERO_TASK_QUEUE_STATS = {
15
15
  pending: 0,
16
16
  processing: 0,
@@ -35,14 +35,6 @@ const HOME_CHAT_SUGGESTIONS = [
35
35
  function HomeChatPanel() {
36
36
  const { selectedModel } = useChatModels();
37
37
  const send = (message) => {
38
- // When mounted inside builder.io's webview, the parent frame is the
39
- // code-writing agent. Route home-chat submissions up to Builder's chat
40
- // instead of the local dispatch agent — the local sidebar is in this
41
- // same iframe and would never receive a postMessage we send to parent.
42
- if (isInBuilderFrame()) {
43
- sendToBuilderChat({ message, submit: true });
44
- return;
45
- }
46
38
  sendToAgentChat({
47
39
  message,
48
40
  submit: true,