llmtop 0.1.4 → 0.1.6

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 (145) hide show
  1. package/README.md +70 -67
  2. package/dashboard/dist/assets/be-vietnam-pro-latin-400-normal-PpnXBOrz.woff2 +0 -0
  3. package/dashboard/dist/assets/be-vietnam-pro-latin-500-normal-B6LVzGNe.woff2 +0 -0
  4. package/dashboard/dist/assets/be-vietnam-pro-latin-600-normal-BZDkUTrt.woff2 +0 -0
  5. package/dashboard/dist/assets/be-vietnam-pro-latin-700-normal-DlW1Zbsh.woff2 +0 -0
  6. package/dashboard/dist/assets/be-vietnam-pro-latin-800-normal-BpHZASpI.woff2 +0 -0
  7. package/dashboard/dist/assets/be-vietnam-pro-latin-ext-400-normal-CiZNW1ec.woff2 +0 -0
  8. package/dashboard/dist/assets/be-vietnam-pro-latin-ext-500-normal-h0Fp6aX0.woff2 +0 -0
  9. package/dashboard/dist/assets/be-vietnam-pro-latin-ext-600-normal-BNd8euf0.woff2 +0 -0
  10. package/dashboard/dist/assets/be-vietnam-pro-latin-ext-700-normal-C8_gqRu2.woff2 +0 -0
  11. package/dashboard/dist/assets/be-vietnam-pro-latin-ext-800-normal-GEpNgheG.woff2 +0 -0
  12. package/dashboard/dist/assets/be-vietnam-pro-vietnamese-400-normal-CRcqvyg1.woff2 +0 -0
  13. package/dashboard/dist/assets/be-vietnam-pro-vietnamese-500-normal-DREgrEoJ.woff2 +0 -0
  14. package/dashboard/dist/assets/be-vietnam-pro-vietnamese-600-normal-nyU-ZL2p.woff2 +0 -0
  15. package/dashboard/dist/assets/be-vietnam-pro-vietnamese-700-normal-Csr0PCuG.woff2 +0 -0
  16. package/dashboard/dist/assets/be-vietnam-pro-vietnamese-800-normal-D4LFh2W4.woff2 +0 -0
  17. package/dashboard/dist/assets/index-C6JlgSDz.js +9 -0
  18. package/dashboard/dist/assets/index-CeDllzpB.css +1 -0
  19. package/dashboard/dist/assets/jetbrains-mono-latin-ext-wght-normal-DBQx-q_a.woff2 +0 -0
  20. package/dashboard/dist/assets/jetbrains-mono-latin-wght-normal-B9CIFXIH.woff2 +0 -0
  21. package/dashboard/dist/assets/jetbrains-mono-vietnamese-wght-normal-Bt-aOZkq.woff2 +0 -0
  22. package/dashboard/dist/index.html +2 -2
  23. package/dashboard/src/App.tsx +224 -88
  24. package/dashboard/src/controls/DateRange.tsx +3 -3
  25. package/dashboard/src/controls/Search.tsx +2 -2
  26. package/dashboard/src/controls/popover.tsx +24 -4
  27. package/dashboard/src/format.ts +1 -1
  28. package/dashboard/src/i18n.tsx +32 -4
  29. package/dashboard/src/main.tsx +11 -2
  30. package/dashboard/src/model.ts +1 -1
  31. package/dashboard/src/overview-flow.css +24 -0
  32. package/dashboard/src/overviewFlow.tsx +76 -0
  33. package/dashboard/src/sessionDetail.test.ts +19 -0
  34. package/dashboard/src/sessionScope.tsx +28 -0
  35. package/dashboard/src/shell/ConsoleFilters.tsx +203 -0
  36. package/dashboard/src/shell/Header.tsx +29 -0
  37. package/dashboard/src/shell/MobileSheet.tsx +29 -0
  38. package/dashboard/src/shell/Palette.tsx +114 -0
  39. package/dashboard/src/shell/Settings.tsx +37 -0
  40. package/dashboard/src/shell/SpecialStates.tsx +145 -0
  41. package/dashboard/src/shell/preferences.ts +71 -0
  42. package/dashboard/src/shell/styleColors.ts +5 -0
  43. package/dashboard/src/shell/useShortcuts.ts +67 -0
  44. package/dashboard/src/state.test.ts +9 -0
  45. package/dashboard/src/state.ts +13 -2
  46. package/dashboard/src/styles/commands.css +61 -0
  47. package/dashboard/src/styles/console.css +149 -0
  48. package/dashboard/src/styles/donut.css +83 -0
  49. package/dashboard/src/styles/fonts/be-vietnam-pro-LICENSE +93 -0
  50. package/dashboard/src/styles/fonts/be-vietnam-pro-latin-400-normal.woff2 +0 -0
  51. package/dashboard/src/styles/fonts/be-vietnam-pro-latin-500-normal.woff2 +0 -0
  52. package/dashboard/src/styles/fonts/be-vietnam-pro-latin-600-normal.woff2 +0 -0
  53. package/dashboard/src/styles/fonts/be-vietnam-pro-latin-700-normal.woff2 +0 -0
  54. package/dashboard/src/styles/fonts/be-vietnam-pro-latin-800-normal.woff2 +0 -0
  55. package/dashboard/src/styles/fonts/be-vietnam-pro-latin-ext-400-normal.woff2 +0 -0
  56. package/dashboard/src/styles/fonts/be-vietnam-pro-latin-ext-500-normal.woff2 +0 -0
  57. package/dashboard/src/styles/fonts/be-vietnam-pro-latin-ext-600-normal.woff2 +0 -0
  58. package/dashboard/src/styles/fonts/be-vietnam-pro-latin-ext-700-normal.woff2 +0 -0
  59. package/dashboard/src/styles/fonts/be-vietnam-pro-latin-ext-800-normal.woff2 +0 -0
  60. package/dashboard/src/styles/fonts/be-vietnam-pro-vietnamese-400-normal.woff2 +0 -0
  61. package/dashboard/src/styles/fonts/be-vietnam-pro-vietnamese-500-normal.woff2 +0 -0
  62. package/dashboard/src/styles/fonts/be-vietnam-pro-vietnamese-600-normal.woff2 +0 -0
  63. package/dashboard/src/styles/fonts/be-vietnam-pro-vietnamese-700-normal.woff2 +0 -0
  64. package/dashboard/src/styles/fonts/be-vietnam-pro-vietnamese-800-normal.woff2 +0 -0
  65. package/dashboard/src/styles/fonts/jetbrains-mono-LICENSE +93 -0
  66. package/dashboard/src/styles/fonts/jetbrains-mono-latin-ext-wght-normal.woff2 +0 -0
  67. package/dashboard/src/styles/fonts/jetbrains-mono-latin-wght-normal.woff2 +0 -0
  68. package/dashboard/src/styles/fonts/jetbrains-mono-vietnamese-wght-normal.woff2 +0 -0
  69. package/dashboard/src/styles/fonts.css +240 -0
  70. package/dashboard/src/styles/shell.css +151 -0
  71. package/dashboard/src/styles/states.css +32 -0
  72. package/dashboard/src/styles/tokens.css +159 -0
  73. package/dashboard/src/styles.css +13 -44
  74. package/dashboard/src/tip.ts +3 -1
  75. package/dashboard/src/treemap.ts +3 -0
  76. package/dashboard/src/ui.tsx +21 -32
  77. package/dashboard/src/views/Breakdown.tsx +46 -0
  78. package/dashboard/src/views/SessionDetail.tsx +67 -0
  79. package/dashboard/src/views/breakdown.css +33 -0
  80. package/dashboard/src/views/{Activity.tsx → classic/Activity.tsx} +31 -50
  81. package/dashboard/src/views/classic/Context.tsx +140 -0
  82. package/dashboard/src/views/{Models.tsx → classic/Models.tsx} +18 -35
  83. package/dashboard/src/views/classic/Overview.tsx +80 -0
  84. package/dashboard/src/views/classic/Projects.tsx +98 -0
  85. package/dashboard/src/views/{Sessions.tsx → classic/Sessions.tsx} +14 -17
  86. package/dashboard/src/views/{Subagents.tsx → classic/Subagents.tsx} +10 -34
  87. package/dashboard/src/views/console/Activity.tsx +241 -0
  88. package/dashboard/src/views/console/ConsoleBoot.tsx +73 -0
  89. package/dashboard/src/views/console/Context.tsx +162 -0
  90. package/dashboard/src/views/console/Models.tsx +187 -0
  91. package/dashboard/src/views/console/Overview.tsx +91 -0
  92. package/dashboard/src/views/console/Projects.tsx +6 -0
  93. package/dashboard/src/views/console/ProviderMeters.tsx +35 -0
  94. package/dashboard/src/views/console/Sessions.tsx +6 -0
  95. package/dashboard/src/views/console/Subagents.tsx +137 -0
  96. package/dashboard/src/views/console/activity-context.css +92 -0
  97. package/dashboard/src/views/console/console-boot.css +137 -0
  98. package/dashboard/src/views/console/modelVisuals.tsx +29 -0
  99. package/dashboard/src/views/console/models-subagents.css +203 -0
  100. package/dashboard/src/views/donut/Activity.tsx +247 -0
  101. package/dashboard/src/views/donut/Context.tsx +169 -0
  102. package/dashboard/src/views/donut/DonutBoot.tsx +68 -0
  103. package/dashboard/src/views/donut/Models.tsx +58 -0
  104. package/dashboard/src/views/donut/Overview.tsx +49 -0
  105. package/dashboard/src/views/donut/Projects.tsx +6 -0
  106. package/dashboard/src/views/donut/Ring.tsx +30 -0
  107. package/dashboard/src/views/donut/Sessions.tsx +6 -0
  108. package/dashboard/src/views/donut/Subagents.tsx +131 -0
  109. package/dashboard/src/views/donut/activity-context.css +154 -0
  110. package/dashboard/src/views/donut/donut-boot.css +165 -0
  111. package/dashboard/src/views/donut/models-subagents.css +157 -0
  112. package/dashboard/src/views/records/Projects.tsx +140 -0
  113. package/dashboard/src/views/records/Sessions.tsx +125 -0
  114. package/dashboard/src/views/records/records.css +119 -0
  115. package/dashboard/src/views/session-detail.css +44 -0
  116. package/dashboard/src/vm/activity.ts +72 -0
  117. package/dashboard/src/vm/colors.ts +57 -0
  118. package/dashboard/src/vm/context.ts +81 -0
  119. package/dashboard/src/vm/filterChoices.ts +27 -0
  120. package/dashboard/src/vm/models.ts +50 -0
  121. package/dashboard/src/vm/overview.ts +46 -0
  122. package/dashboard/src/vm/palette.ts +63 -0
  123. package/dashboard/src/vm/projects.ts +63 -0
  124. package/dashboard/src/vm/providerBreakdown.ts +19 -0
  125. package/dashboard/src/vm/sessionDetail.ts +16 -0
  126. package/dashboard/src/vm/sessions.ts +36 -0
  127. package/dashboard/src/vm/specialStates.ts +64 -0
  128. package/dashboard/src/vm/subagents.ts +36 -0
  129. package/dashboard/src/vm.test.ts +183 -0
  130. package/package.json +1 -1
  131. package/src/api.mjs +6 -1
  132. package/src/dashboard.mjs +4 -1
  133. package/src/db.mjs +5 -2
  134. package/src/providers/codex.mjs +121 -19
  135. package/src/serve.mjs +20 -10
  136. package/dashboard/dist/assets/index-Ba0kF2tG.js +0 -9
  137. package/dashboard/dist/assets/index-NQzaBVIY.css +0 -1
  138. package/dashboard/dist/assets/montserrat-cyrillic-ext-wght-normal-CO5hGrJv.woff2 +0 -0
  139. package/dashboard/dist/assets/montserrat-cyrillic-wght-normal-EAA9jha_.woff2 +0 -0
  140. package/dashboard/dist/assets/roboto-mono-cyrillic-ext-wght-normal-BUDPrIko.woff2 +0 -0
  141. package/dashboard/dist/assets/roboto-mono-cyrillic-wght-normal-HUlVHixE.woff2 +0 -0
  142. package/dashboard/dist/assets/roboto-mono-greek-wght-normal-BJJTbwTT.woff2 +0 -0
  143. package/dashboard/src/views/Context.tsx +0 -183
  144. package/dashboard/src/views/Overview.tsx +0 -83
  145. package/dashboard/src/views/Projects.tsx +0 -116
@@ -0,0 +1,24 @@
1
+ .overview-cost-notes {
2
+ margin: 0;
3
+ line-height: 1.5;
4
+ }
5
+ .overview-cost-notes strong:not(:first-child) {
6
+ margin-inline-start: 0.6em;
7
+ }
8
+ .overview-day-sessions {
9
+ justify-content: flex-start;
10
+ margin-block: 0.75rem;
11
+ }
12
+ .overview-day-sessions select {
13
+ flex-shrink: 0;
14
+ }
15
+
16
+ @media (min-width: 360px) and (max-width: 639px) {
17
+ .app .overview-kpis.overview-kpis-primary {
18
+ grid-template-columns: repeat(3, minmax(0, 1fr));
19
+ gap: var(--space-2);
20
+ }
21
+ .app .overview-kpis-primary .kpi {
22
+ padding-inline: var(--space-2);
23
+ }
24
+ }
@@ -0,0 +1,76 @@
1
+ import { Fragment, useId, useState, useSyncExternalStore, type ReactNode } from "react";
2
+ import { useDash } from "./dash.ts";
3
+ import type { Fact, Metric } from "./model.ts";
4
+ import "./overview-flow.css";
5
+
6
+ const mobileOverview = "(max-width: 639px)";
7
+ const isMobileOverview = () => window.matchMedia(mobileOverview).matches;
8
+
9
+ function subscribeToOverviewWidth(onChange: () => void) {
10
+ const media = window.matchMedia(mobileOverview);
11
+ media.addEventListener("change", onChange);
12
+ return () => media.removeEventListener("change", onChange);
13
+ }
14
+
15
+ export function OverviewLayout({ primary, secondary, trend, breakdown, kpiClass }: {
16
+ primary: ReactNode;
17
+ secondary: ReactNode;
18
+ trend: ReactNode;
19
+ breakdown?: ReactNode;
20
+ kpiClass: string;
21
+ }) {
22
+ const mobile = useSyncExternalStore(subscribeToOverviewWidth, isMobileOverview, () => false);
23
+ const chart = <Fragment key="trend">{trend}</Fragment>;
24
+ const notes = <OverviewCostNotes key="cost-notes" />;
25
+ const sources = <Fragment key="breakdown">{breakdown}</Fragment>;
26
+ return [
27
+ <div key="metrics" className={mobile ? `${kpiClass} overview-kpis-primary` : kpiClass}>{primary}{!mobile && secondary}</div>,
28
+ ...(mobile ? [chart, <div key="secondary" className={kpiClass}>{secondary}</div>, notes, sources] : [notes, sources, chart]),
29
+ ];
30
+ }
31
+
32
+ export function OverviewSessionsLink() {
33
+ const { S, t, set } = useDash();
34
+ const cost = S.metric === "cost";
35
+ return <button type="button" className="link" onClick={() => set({
36
+ view: "sessions", sort: cost ? "cost" : "out", dir: -1, q: "", sessionsBy: "",
37
+ })}>{t(cost ? "sessionsByCost" : "sessionsByOutput")} →</button>;
38
+ }
39
+
40
+ export function OverviewDaySessions({ F }: { F: Fact[] }) {
41
+ const { filter, S } = useDash();
42
+ return <DaySessions key={JSON.stringify(filter)} F={F} metric={S.metric} />;
43
+ }
44
+
45
+ function DaySessions({ F, metric }: { F: Fact[]; metric: Metric }) {
46
+ const { f, t, set } = useDash();
47
+ const [day, setDay] = useState("");
48
+ const id = useId();
49
+ const dates = [...new Set(F.map(({ d }) => d))].sort().reverse();
50
+ const selected = dates.includes(day) ? day : dates[0];
51
+ if (!selected) return null;
52
+ return (
53
+ <div className="segs overview-day-sessions">
54
+ {dates.length > 1 ? <>
55
+ <label htmlFor={id}>{t("activeDay")}</label>
56
+ <select id={id} className="field" value={selected} onChange={(event) => setDay(event.currentTarget.value)}>
57
+ {dates.map((date) => <option key={date} value={date}>{f.dshort(date)}</option>)}
58
+ </select>
59
+ </> : <span>{f.dshort(selected)}</span>}
60
+ <button type="button" className="field" onClick={() => set({
61
+ view: "sessions", range: "", from: selected, to: selected, sort: metric === "cost" ? "cost" : "out",
62
+ dir: -1, q: "", sessionsBy: "",
63
+ })}>{t("viewDaySessions")}</button>
64
+ </div>
65
+ );
66
+ }
67
+
68
+ function OverviewCostNotes() {
69
+ const { t } = useDash();
70
+ return (
71
+ <p className="hint overview-cost-notes">
72
+ <strong>{t("usageCost")}</strong> · {t("costExplanation")}{" "}
73
+ <strong>{t("saved")}</strong> · {t("savedTip")}.
74
+ </p>
75
+ );
76
+ }
@@ -0,0 +1,19 @@
1
+ import assert from "node:assert/strict";
2
+ import { test } from "node:test";
3
+ import { findSessionIndex, sessionKey } from "./vm/sessionDetail.ts";
4
+
5
+ test("selects the exact session even when abbreviated IDs and titles match", () => {
6
+ const sessions = [
7
+ { id: "12345678", key: "12345678-first", title: "Build demo", pr: 0 },
8
+ { id: "12345678", key: "12345678-second", title: "Build demo", pr: 0 },
9
+ ];
10
+ assert.equal(findSessionIndex(sessions, sessionKey(sessions[1])), 1);
11
+ assert.equal(findSessionIndex(sessions, "12345678"), -1);
12
+ assert.equal(findSessionIndex([{ ...sessions[1], pr: -1 }], "12345678-second"), -1);
13
+ });
14
+
15
+ test("can open a unique abbreviated ID from an older dashboard payload", () => {
16
+ const legacy = [{ id: "12345678" }, { id: "87654321" }];
17
+ assert.equal(findSessionIndex(legacy, "87654321"), 1);
18
+ assert.equal(findSessionIndex([legacy[0], legacy[0]], "12345678"), -1);
19
+ });
@@ -0,0 +1,28 @@
1
+ import { useDash } from "./dash.ts";
2
+ import type { Fact } from "./model.ts";
3
+ import { scopedSessionIds, type RelatedSessionScope } from "./vm/sessions.ts";
4
+
5
+ const LABELS = {
6
+ rebuild: "sessionsWithRebuild",
7
+ compaction: "sessionsWithCompaction",
8
+ subagent: "sessionsWithSubagent",
9
+ } as const;
10
+
11
+ export function RelatedSessions({ F, scope }: { F: Fact[]; scope: RelatedSessionScope }) {
12
+ const { M, filter, t, set } = useDash();
13
+ if (!scopedSessionIds(M, F, scope, filter).size) return null;
14
+ return <button type="button" className="link" onClick={() => set({
15
+ view: "sessions", sessionsBy: scope, q: "", sort: "cost", dir: -1,
16
+ })}>{t(LABELS[scope])} →</button>;
17
+ }
18
+
19
+ export function ActiveSessionScope() {
20
+ const { S, t, set } = useDash();
21
+ if (!S.sessionsBy) return null;
22
+ return (
23
+ <p className="session-scope">
24
+ <strong>{t(LABELS[S.sessionsBy])}</strong>
25
+ <button type="button" className="link" onClick={() => set({ sessionsBy: "" })}>{t("clearSessionScope")}</button>
26
+ </p>
27
+ );
28
+ }
@@ -0,0 +1,203 @@
1
+ import { effortColor } from "../vm/colors.ts";
2
+ import { useEffect, useId, useRef, useState } from "react";
3
+ import { DateRange } from "../controls/DateRange.tsx";
4
+ import { Search } from "../controls/Search.tsx";
5
+ import { Chevron, usePopover } from "../controls/popover.tsx";
6
+ import { useDash } from "../dash.ts";
7
+ import { dayAdd, slice, type Filter } from "../model.ts";
8
+ import type { UrlState } from "../state.ts";
9
+ import { choices, FILTER_KEYS, providerForModel, windowFor, type FilterKey } from "../vm/filterChoices.ts";
10
+ import { MobileSheet } from "./MobileSheet.tsx";
11
+ import { useStyleColors } from "./styleColors.ts";
12
+
13
+ const empty = { provider: "", project: "", model: "", effort: "" };
14
+ const labels = { provider: "allProviders", project: "allProjects", model: "allModels", effort: "allEfforts" } as const;
15
+ const quickRanges = [["1", "today"], ["7", "d7"], ["14", "d14"], ["30", "d30"], ["all", "all"]] as const;
16
+
17
+ function resolveFilter(M: ReturnType<typeof useDash>["M"], state: UrlState): Filter {
18
+ return { ...windowFor(M, state), provider: M.providers.indexOf(state.provider), project: M.projects.indexOf(state.project),
19
+ model: M.models.indexOf(state.model), effort: M.efforts.indexOf(state.effort) };
20
+ }
21
+
22
+ function DateChoices({ draft, set }: { draft: UrlState; set: (patch: Partial<UrlState>) => void }) {
23
+ const { M, f, t, L } = useDash();
24
+ const { from, to } = windowFor(M, draft);
25
+ const count = Math.round((Date.parse(to) - Date.parse(from)) / 864e5) + 1;
26
+ const start = dayAdd(from, -count), end = dayAdd(from, -1);
27
+
28
+ return (
29
+ <div className="console-date-choices">
30
+ <div className="seg">{quickRanges.map(([value, label]) => <button type="button" key={value} aria-pressed={draft.range === value}
31
+ onClick={() => set({ range: value, from: "", to: "" })}>{t(label)}</button>)}</div>
32
+ <DateRange from={from} to={to} min={M.first} max={M.today} onChange={(from, to) => set({ range: "", from, to })}
33
+ locale={f.locale} weekdays={L.wdShort} label={t("dates")} prevLabel={t("prevMonth")} nextLabel={t("nextMonth")} containFocus />
34
+ <p className="console-hint">{start >= M.first ? L.comparedWith(`${f.dshort(start)} – ${f.dshort(end)}`) : t("noPrev")}</p>
35
+ </div>
36
+ );
37
+ }
38
+
39
+ function ChoiceList({ field, draft, pick }: { field: FilterKey; draft: UrlState; pick: (value: string) => void }) {
40
+ const { M, f, t } = useDash();
41
+ const colors = useStyleColors();
42
+ const [query, setQuery] = useState("");
43
+ const [active, setActive] = useState(0);
44
+ const names = field === "provider" ? M.providers : field === "project" ? M.projects : field === "model" ? M.models : M.efforts;
45
+ const output = choices(M, resolveFilter(M, draft), field);
46
+ const rows = names.flatMap((name, id) => {
47
+ if (!name.toLocaleLowerCase().includes(query.trim().toLocaleLowerCase()) || !output.has(id)) return [];
48
+ const providerIndex = field === "model" ? colors.modelProviders[id] : -1;
49
+ const family = M.providers.includes(colors.providerNames[providerIndex]) ? colors.providerNames[providerIndex] : "";
50
+ const token = field === "provider" ? colors.providers[colors.providerNames.indexOf(name)] : field === "project" ? colors.projects[id] :
51
+ field === "model" ? colors.models[id] : effortColor(id);
52
+ return [{ name, family, token, output: output.get(id)! }];
53
+ }).sort((a, b) => a.family.localeCompare(b.family) || b.output - a.output);
54
+ const namesToPick = ["", ...rows.map(({ name }) => name)];
55
+ return (
56
+ <div className="console-choices" onKeyDown={(event) => {
57
+ if (event.key === "ArrowDown" || event.key === "ArrowUp") {
58
+ event.preventDefault();
59
+ setActive((index) => Math.max(0, Math.min(namesToPick.length - 1, index + (event.key === "ArrowDown" ? 1 : -1))));
60
+ }
61
+ if (event.key === "Enter" && event.target instanceof HTMLInputElement) { event.preventDefault(); pick(namesToPick[active]); }
62
+ }}>
63
+ <Search value={query} placeholder={t(field === "model" ? "filterModels" : "search")} clearLabel={t("clear")}
64
+ onChange={(value) => { setActive(0); setQuery(value); }} />
65
+ <button type="button" className="console-choice" aria-pressed={!draft[field]} data-active={active === 0}
66
+ onClick={() => pick("")}>{t(labels[field])}</button>
67
+ {rows.map(({ name, family, token, output: value }, i) => (
68
+ <div key={name}>
69
+ {family && family !== rows[i - 1]?.family ? <p className="console-choice-group">{family}</p> : null}
70
+ <button type="button" className="console-choice" aria-pressed={draft[field] === name} data-active={active === i + 1}
71
+ title={name} onClick={() => pick(name)}>
72
+ <i className="console-swatch" style={{ background: `var(${token})` }} /><span>{name}</span><b className="num">{f.cmp(value)}</b>
73
+ </button>
74
+ </div>
75
+ ))}
76
+ </div>
77
+ );
78
+ }
79
+
80
+ function FilterSegment({ field, choose }: { field: FilterKey; choose: (field: FilterKey, value: string) => void }) {
81
+ const { S, t } = useDash();
82
+ const p = usePopover(true);
83
+ const label = useId();
84
+ return (
85
+ <div className="ctl console-segment" data-filter-key={field} ref={p.root}>
86
+ <button type="button" ref={p.trigger} className={`field pick${S[field] ? " on" : ""}`} aria-haspopup="dialog" aria-expanded={p.open}
87
+ aria-label={t(field)} aria-controls={p.open ? label : undefined} onClick={() => p.setOpen(!p.open)}
88
+ onKeyDown={(event) => { if (event.key === "ArrowDown") { event.preventDefault(); p.setOpen(true); } }}>
89
+ <span className="pv">{S[field] || t(labels[field])}</span><Chevron />
90
+ </button>
91
+ {S[field] ? <button type="button" className="console-drop" aria-label={`${t("clear")} ${t(field)}`} onClick={() => choose(field, "")}>×</button> : null}
92
+ {p.open ? <div ref={p.pop} className="pop console-filter-pop" style={p.place} id={label} role="dialog" aria-label={t(field)}>
93
+ <ChoiceList field={field} draft={S} pick={(value) => { choose(field, value); p.close(); }} />
94
+ </div> : null}
95
+ </div>
96
+ );
97
+ }
98
+
99
+ function DateSegment() {
100
+ const { S, M, f, t, set } = useDash();
101
+ const p = usePopover(true);
102
+ const { from, to } = windowFor(M, S);
103
+ const range = quickRanges.find(([value]) => value === S.range);
104
+ return (
105
+ <div className="ctl console-segment" ref={p.root}>
106
+ <button type="button" ref={p.trigger} className="field pick on" aria-haspopup="dialog" aria-expanded={p.open} aria-label={t("dates")}
107
+ onClick={() => p.setOpen(!p.open)} onKeyDown={(event) => { if (event.key === "ArrowDown") { event.preventDefault(); p.setOpen(true); } }}>
108
+ <span className="pv">{range ? t(range[1]) : `${f.dshort(from)} – ${f.dshort(to)}`}</span><Chevron />
109
+ </button>
110
+ {p.open ? <div ref={p.pop} className="pop console-filter-pop" style={p.place} role="dialog" aria-label={t("dates")}>
111
+ <DateChoices draft={S} set={(patch) => { set(patch); p.close(); }} />
112
+ </div> : null}
113
+ </div>
114
+ );
115
+ }
116
+
117
+ function AddFilter({ select }: { select: (field: FilterKey, value: string) => void }) {
118
+ const { S, t } = useDash();
119
+ const p = usePopover(true);
120
+ const [field, setField] = useState<"model" | "effort">();
121
+ const available = (["model", "effort"] as const).filter((key) => !S[key]);
122
+ useEffect(() => {
123
+ if (p.open) p.pop.current?.querySelector<HTMLElement>(field ? "input" : "button")?.focus();
124
+ }, [p.open, field]);
125
+ if (!available.length) return null;
126
+ return (
127
+ <div className="ctl console-segment" ref={p.root}>
128
+ <button ref={p.trigger} type="button" className="field pick" aria-haspopup="dialog" aria-expanded={p.open}
129
+ onClick={() => { setField(undefined); p.setOpen(!p.open); }}>{t("addFilter")}</button>
130
+ {p.open ? <div ref={p.pop} className="pop console-filter-pop" style={p.place} role="dialog" aria-label={t("addFilter")}>
131
+ {field ? <><button type="button" className="console-choice" onClick={() => setField(undefined)}>{t("back")}</button>
132
+ <ChoiceList field={field} draft={S} pick={(value) => { select(field, value); p.close(!value); }} /></> :
133
+ available.map((key) => <button type="button" key={key} className="console-choice" onClick={() => setField(key)}>{t(key)}</button>)}
134
+ </div> : null}
135
+ </div>
136
+ );
137
+ }
138
+
139
+ export function ConsoleFilters({ variant = "console", onPalette }: { variant?: "console" | "donut"; onPalette: () => void }) {
140
+ const { M, S, t, L, f, set } = useDash();
141
+ const bar = useRef<HTMLDivElement>(null);
142
+ const [draft, setDraft] = useState<UrlState>();
143
+ const [desktopSearch, setDesktopSearch] = useState(false);
144
+ const [page, setPage] = useState<FilterKey | "dates" | "search">();
145
+ const keys = FILTER_KEYS.filter((key) => key !== "provider" || M.providers.length > 1);
146
+ const count = FILTER_KEYS.filter((key) => S[key]).length;
147
+ const range = quickRanges.find(([value]) => value === S.range);
148
+ const choicePatch = (field: FilterKey, value: string): Partial<UrlState> => {
149
+ const provider = field === "model" && value ? providerForModel(M, M.models.indexOf(value)) : undefined;
150
+ return { [field]: value, ...(provider && M.providers.length > 1 ? { provider } : {}) };
151
+ };
152
+ const applyDraft = () => {
153
+ if (!draft) return;
154
+ const { provider, project, model, effort, range, from, to, q } = draft;
155
+ set({ provider, project, model, effort, range, from, to, ...(page === "search" ? { view: "sessions", q, sessionsBy: "" } : {}) });
156
+ setDraft(undefined);
157
+ setPage(undefined);
158
+ };
159
+ const open = (target?: typeof page) => { setDraft(S); setPage(target); };
160
+ const patch = (value: Partial<UrlState>) => setDraft((current) => current && { ...current, ...value });
161
+
162
+ return (
163
+ <>
164
+ <div ref={bar} className="console-filter-bar">
165
+ {variant === "console" ? <span className="console-prompt" aria-hidden="true">❯</span> : null}<DateSegment />
166
+ {keys.filter((key) => variant === "console" || key === "provider" || key === "project" || S[key]).map((key) =>
167
+ <div className="console-filter-slot" key={key}>{variant === "console" ? <span aria-hidden="true">›</span> : null}
168
+ <FilterSegment field={key} choose={(field, value) => set(choicePatch(field, value))} />
169
+ </div>)}
170
+ {variant === "donut" ? <AddFilter select={(field, value) => {
171
+ set(choicePatch(field, value));
172
+ if (value) requestAnimationFrame(() => bar.current?.querySelector<HTMLButtonElement>(`[data-filter-key="${field}"] .pick`)?.focus());
173
+ }} /> : null}
174
+ {desktopSearch && variant === "donut" ? <Search shortcutTarget value={S.q} placeholder={t("search")} clearLabel={t("clear")}
175
+ onChange={(q) => set({ view: "sessions", q, sessionsBy: "" }, { replace: S.view === "sessions" })} /> :
176
+ <button type="button" className="field" data-dashboard-search aria-haspopup={variant === "console" ? "dialog" : undefined}
177
+ onClick={() => {
178
+ if (variant === "console") onPalette();
179
+ else { setDesktopSearch(true); requestAnimationFrame(() => bar.current?.querySelector("input")?.focus()); }
180
+ }}>{t("search")}</button>}
181
+ <button type="button" className="field" aria-label={t("palette")} onClick={onPalette}>⌘K</button>
182
+ {count ? <button type="button" className="field clearall" onClick={() => set(empty)}>{t("reset")}</button> : null}
183
+ </div>
184
+ <div className="console-filter-mobile">
185
+ <button type="button" className="shell-button" onClick={() => open("dates")}>{range ? t(range[1]) : t("dates")}</button>
186
+ <button type="button" className="shell-button" onClick={() => open()}>{t("filters")}{count ? ` (${count})` : ""}</button>
187
+ <button type="button" className="shell-button" data-dashboard-search onClick={() => open("search")}>{t("search")}</button>
188
+ </div>
189
+ {draft ? <MobileSheet title={page ? t(page) : t("filters")} closeLabel={t("close")} onClose={() => setDraft(undefined)}>
190
+ {page === "dates" ? <DateChoices draft={draft} set={patch} /> : page === "search" ?
191
+ <Search value={draft.q} placeholder={t("search")} clearLabel={t("clear")} onChange={(q) => patch({ q })} /> :
192
+ page ? <ChoiceList key={page} field={page} draft={draft} pick={(value) => patch(choicePatch(page, value))} /> :
193
+ <div className="console-mobile-choices">{keys.map((key) => <button className="shell-button" key={key} onClick={() => setPage(key)}>
194
+ {t(key)} · {draft[key] || t(labels[key])}
195
+ </button>)}<button className="shell-button" onClick={() => patch(empty)}>{t("reset")}</button></div>}
196
+ <div className="console-mobile-submit">
197
+ {page ? <button className="shell-button" onClick={() => setPage(undefined)}>{t("back")}</button> : null}
198
+ <button className="shell-button" onClick={applyDraft}>{page ? t("apply") : L.showSessions(f.int(new Set(slice(M, resolveFilter(M, draft)).map(({ s }) => s)).size))}</button>
199
+ </div>
200
+ </MobileSheet> : null}
201
+ </>
202
+ );
203
+ }
@@ -0,0 +1,29 @@
1
+ import type { ReactNode } from "react";
2
+ import type { Lang } from "../i18n.tsx";
3
+ import type { Theme } from "./preferences.ts";
4
+
5
+ export function Header({ brand, navigation, status, refresh, lang, theme, themeLabel, settingsLabel, onLanguage, onTheme, onSettings, help, helpLabel }: {
6
+ brand?: ReactNode; navigation?: ReactNode; status: ReactNode; refresh: ReactNode; lang: Lang; theme: Theme; themeLabel: string; settingsLabel: string;
7
+ onLanguage: () => void; onTheme: () => void; onSettings: () => void; help?: () => void; helpLabel: string;
8
+ }) {
9
+ return (
10
+ <header className="shell-header">
11
+ {brand}
12
+ {navigation}
13
+ <div className="shell-actions">
14
+ <div className="shell-status">{status}{refresh}</div>
15
+ <button type="button" className="shell-button" aria-label={lang === "vi" ? "English" : "Tiếng Việt"} onClick={onLanguage}>{lang.toUpperCase()}</button>
16
+ <button type="button" className="shell-button" aria-label={themeLabel} title={themeLabel} onClick={onTheme}>
17
+ <svg viewBox="0 0 24 24" aria-hidden="true">
18
+ {theme === "dark" ? <><circle cx="12" cy="12" r="4" /><path d="M12 2v2M12 20v2M2 12h2M20 12h2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4" /></>
19
+ : <path d="M20 14.5A8 8 0 0 1 9.5 4a8 8 0 1 0 10.5 10.5z" />}
20
+ </svg>
21
+ </button>
22
+ {help ? <button type="button" className="shell-button shell-help" aria-label={helpLabel} aria-haspopup="dialog" onClick={help}>?</button> : null}
23
+ <button type="button" className="shell-button" aria-label={settingsLabel} title={settingsLabel} aria-haspopup="dialog" onClick={(event) => { event.currentTarget.focus(); onSettings(); }}>
24
+ <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M10 3h4l.6 2.4 1.7 1 2.4-.7 2 3.5-1.8 1.7v2l1.8 1.7-2 3.5-2.4-.7-1.7 1L14 21h-4l-.6-2.6-1.7-1-2.4.7-2-3.5 1.8-1.7v-2L3.3 9.2l2-3.5 2.4.7 1.7-1L10 3z" /><circle cx="12" cy="12" r="3" /></svg>
25
+ </button>
26
+ </div>
27
+ </header>
28
+ );
29
+ }
@@ -0,0 +1,29 @@
1
+ import { useId, useLayoutEffect, useRef, type ReactNode } from "react";
2
+
3
+ export function MobileSheet({ title, closeLabel, onClose, children }: {
4
+ title: string; closeLabel: string; onClose: () => void; children: ReactNode;
5
+ }) {
6
+ const ref = useRef<HTMLDialogElement>(null);
7
+ const label = useId();
8
+
9
+ useLayoutEffect(() => {
10
+ const dialog = ref.current!;
11
+ const trigger = document.activeElement;
12
+ dialog.showModal();
13
+ return () => {
14
+ dialog.close();
15
+ if (trigger instanceof HTMLElement) trigger.focus();
16
+ };
17
+ }, []);
18
+
19
+ return (
20
+ <dialog ref={ref} className="mobile-sheet" aria-labelledby={label}
21
+ onCancel={(event) => { event.preventDefault(); onClose(); }}
22
+ onClick={(event) => { if (event.target === event.currentTarget) onClose(); }}>
23
+ <div className="mobile-sheet-content">
24
+ <header><h2 id={label}>{title}</h2><button type="button" className="shell-button" onClick={onClose}>{closeLabel}</button></header>
25
+ {children}
26
+ </div>
27
+ </dialog>
28
+ );
29
+ }
@@ -0,0 +1,114 @@
1
+ import { useEffect, useId, useMemo, useRef, useState } from "react";
2
+ import { useDash } from "../dash.ts";
3
+ import type { Key } from "../i18n.tsx";
4
+ import { slice } from "../model.ts";
5
+ import { providerForModel } from "../vm/filterChoices.ts";
6
+ import { paletteFilters, searchable, suggestFilters } from "../vm/palette.ts";
7
+ import { sessionKey, sessionReference } from "../vm/sessionDetail.ts";
8
+ import { MobileSheet } from "./MobileSheet.tsx";
9
+ import "../styles/commands.css";
10
+
11
+ type Actions = {
12
+ refresh: () => void;
13
+ settings: () => void;
14
+ theme: () => void;
15
+ language: () => void;
16
+ };
17
+ type Result = { label: string; meta?: string; run: () => void };
18
+
19
+ export function Palette({ onClose, refresh, settings, theme, language }: Actions & { onClose: () => void }) {
20
+ const { M, filter, t, f, set } = useDash();
21
+ const [query, setQuery] = useState("");
22
+ const [index, setIndex] = useState<number | null>(null);
23
+ const input = useRef<HTMLInputElement>(null);
24
+ const id = useId();
25
+ const candidates = useMemo(() => paletteFilters(M), [M]);
26
+ const sessions = useMemo(() => [...new Set(slice(M, filter).map(({ s }) => s))].map((s) => M.sessions[s]), [M, filter]);
27
+ const search = searchable(query).trim();
28
+ const filters = suggestFilters(candidates, query).map((proposal): Result => ({
29
+ label: proposal.map(({ key, value }) => `${t(key)} · ${value}`).join(" + "),
30
+ run: () => {
31
+ const patch = Object.fromEntries(proposal.map(({ key, value }) => [key, value]));
32
+ if (patch.model && !patch.provider && M.providers.length > 1) {
33
+ const provider = providerForModel(M, M.models.indexOf(patch.model));
34
+ if (provider) patch.provider = provider;
35
+ }
36
+ set(patch);
37
+ },
38
+ }));
39
+ const found = search ? sessions.filter((session) =>
40
+ searchable([session.title, M.projects[session.p], sessionKey(session)].join(" ")).includes(search)).slice(0, 8).map((session): Result => ({
41
+ label: session.title || t("untitled"),
42
+ meta: [M.projects[session.p], M.providers[session.pr ?? 0], f.startText(session), sessionReference(sessions, session)].filter(Boolean).join(" · "),
43
+ run: () => set({ session: sessionKey(session) }),
44
+ })) : [];
45
+ const commands: (Result & { terms: string })[] = [
46
+ { label: t("kRescan"), terms: "refresh rescan r", run: refresh },
47
+ { label: t("settings"), terms: "settings s", run: settings },
48
+ { label: t("theme"), terms: "theme dark light t", run: theme },
49
+ { label: t("toggleLanguage"), terms: "language en vi l", run: language },
50
+ ].filter(({ label, terms }) => searchable(`${label} ${terms}`).includes(search));
51
+ const groups = [[t("palFilters"), filters], [t("palSessions"), found], [t("palCommands"), commands]] as const;
52
+ const results = groups.flatMap(([, rows]) => rows);
53
+ const exactCommand = commands.findIndex(({ label, terms }) => search === searchable(label) || terms.split(" ").includes(search));
54
+ const preferred = exactCommand >= 0 ? filters.length + found.length + exactCommand : 0;
55
+ const active = Math.min(index ?? preferred, results.length - 1);
56
+ const choose = ({ run }: Result) => { onClose(); run(); };
57
+ useEffect(() => { input.current?.focus(); }, []);
58
+ useEffect(() => {
59
+ if (active >= 0) document.getElementById(`${id}-${active}`)?.scrollIntoView({ block: "nearest" });
60
+ }, [id, active]);
61
+
62
+ let row = 0;
63
+ return (
64
+ <MobileSheet title={t("palette")} closeLabel={t("close")} onClose={onClose}>
65
+ <div className="command-palette">
66
+ <input ref={input} role="combobox" aria-label={t("palettePlaceholder")} placeholder={t("palettePlaceholder")} autoComplete="off"
67
+ aria-expanded={results.length > 0} aria-controls={`${id}-list`} aria-activedescendant={active >= 0 ? `${id}-${active}` : undefined} value={query}
68
+ onChange={(event) => { setQuery(event.target.value); setIndex(null); }} onKeyDown={(event) => {
69
+ if (event.nativeEvent.isComposing || !results.length) return;
70
+ if (event.key === "ArrowDown" || event.key === "ArrowUp") {
71
+ event.preventDefault();
72
+ setIndex((active + (event.key === "ArrowDown" ? 1 : -1) + results.length) % results.length);
73
+ } else if (event.key === "Enter" && active >= 0) {
74
+ event.preventDefault();
75
+ choose(results[active]);
76
+ }
77
+ }} />
78
+ <div id={`${id}-list`} role="listbox" aria-label={t("palette")} className="command-results">
79
+ {groups.map(([title, rows]) => rows.length ? <div role="group" aria-label={title} key={title}>
80
+ <h3 aria-hidden="true">{title}</h3>
81
+ {rows.map((result) => {
82
+ const number = row++;
83
+ return <button type="button" key={number} id={`${id}-${number}`} role="option" tabIndex={-1} aria-selected={number === active}
84
+ title={[result.label, result.meta].filter(Boolean).join(" · ")} onPointerMove={() => setIndex(number)} onClick={() => choose(result)}>
85
+ {result.meta ? <><span>{result.label}</span><small className="command-session-meta">{result.meta}</small></> : result.label}
86
+ </button>;
87
+ })}
88
+ </div> : null)}
89
+ </div>
90
+ </div>
91
+ </MobileSheet>
92
+ );
93
+ }
94
+
95
+ const KEYS = [
96
+ ["? / F1", "kHelp"], ["/", "kSearch"], ["⌘/Ctrl K", "kCommands"], ["1–7", "kViews"],
97
+ ["R", "kRescan"], ["S", "settings"], ["T", "theme"], ["L", "toggleLanguage"],
98
+ ] as const satisfies readonly (readonly [string, Key])[];
99
+
100
+ export function ShortcutHint({ openHelp }: { openHelp: () => void }) {
101
+ const { t } = useDash();
102
+ return <footer className="command-hints">{KEYS.map(([key, label]) => (
103
+ <span key={key}><kbd>{key}</kbd>{" "}{t(label)}</span>
104
+ ))}<button type="button" className="shell-button" onClick={openHelp}>{t("shortcuts")}</button></footer>;
105
+ }
106
+
107
+ export function ShortcutHelp({ onClose }: { onClose: () => void }) {
108
+ const { t } = useDash();
109
+ return <MobileSheet title={t("shortcuts")} closeLabel={t("close")} onClose={onClose}>
110
+ <dl className="command-help">{[...KEYS, ["Tab / ← →", "filters"], ["↵ / ↓", "filters"], ["⌫", "reset"], ["Esc", "close"]].map(([key, label]) => (
111
+ <div key={key}><dt><kbd>{key}</kbd></dt><dd>{t(label as Key)}</dd></div>
112
+ ))}</dl>
113
+ </MobileSheet>;
114
+ }
@@ -0,0 +1,37 @@
1
+ import { useDash } from "../dash.ts";
2
+ import { MobileSheet } from "./MobileSheet.tsx";
3
+ import { STYLES, type Style } from "./preferences.ts";
4
+
5
+ const label = { classic: "styleClassic", console: "styleConsole", donut: "styleDonut" } as const;
6
+ const description = { classic: "styleClassicDesc", console: "styleConsoleDesc", donut: "styleDonutDesc" } as const;
7
+
8
+ export function Settings({ style, providers, hidden, onStyle, onToggle, onClose }: {
9
+ style: Style; providers: { name: string; sessions: number; color: string }[]; hidden: readonly string[];
10
+ onStyle: (style: Style) => void; onToggle: (provider: string) => void; onClose: () => void;
11
+ }) {
12
+ const { t, f } = useDash();
13
+ return (
14
+ <MobileSheet title={t("settings")} closeLabel={t("close")} onClose={onClose}>
15
+ <fieldset className="shell-options">
16
+ <legend>{t("style")}</legend>
17
+ {STYLES.map((value) => (
18
+ <label key={value}>
19
+ <input type="radio" name="dashboard-style" checked={style === value} onChange={() => onStyle(value)} />
20
+ <span><strong>{t(label[value])}</strong><small>{t(description[value])}</small></span>
21
+ </label>
22
+ ))}
23
+ </fieldset>
24
+ <fieldset className="shell-options">
25
+ <legend>{t("providersShown")}</legend>
26
+ {providers.map(({ name, sessions, color }) => (
27
+ <label key={name}>
28
+ <input type="checkbox" checked={!hidden.includes(name)} onChange={() => onToggle(name)} />
29
+ <i className="shell-provider" style={{ background: `var(${color})` }} />
30
+ <span>{name}</span><span className="shell-session-count">{f.int(sessions)} {t("shown")}</span>
31
+ </label>
32
+ ))}
33
+ <p>{t("rescanProviders")}</p>
34
+ </fieldset>
35
+ </MobileSheet>
36
+ );
37
+ }