llmtop 0.1.5 → 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.
- package/README.md +70 -67
- package/dashboard/dist/assets/be-vietnam-pro-latin-400-normal-PpnXBOrz.woff2 +0 -0
- package/dashboard/dist/assets/be-vietnam-pro-latin-500-normal-B6LVzGNe.woff2 +0 -0
- package/dashboard/dist/assets/be-vietnam-pro-latin-600-normal-BZDkUTrt.woff2 +0 -0
- package/dashboard/dist/assets/be-vietnam-pro-latin-700-normal-DlW1Zbsh.woff2 +0 -0
- package/dashboard/dist/assets/be-vietnam-pro-latin-800-normal-BpHZASpI.woff2 +0 -0
- package/dashboard/dist/assets/be-vietnam-pro-latin-ext-400-normal-CiZNW1ec.woff2 +0 -0
- package/dashboard/dist/assets/be-vietnam-pro-latin-ext-500-normal-h0Fp6aX0.woff2 +0 -0
- package/dashboard/dist/assets/be-vietnam-pro-latin-ext-600-normal-BNd8euf0.woff2 +0 -0
- package/dashboard/dist/assets/be-vietnam-pro-latin-ext-700-normal-C8_gqRu2.woff2 +0 -0
- package/dashboard/dist/assets/be-vietnam-pro-latin-ext-800-normal-GEpNgheG.woff2 +0 -0
- package/dashboard/dist/assets/be-vietnam-pro-vietnamese-400-normal-CRcqvyg1.woff2 +0 -0
- package/dashboard/dist/assets/be-vietnam-pro-vietnamese-500-normal-DREgrEoJ.woff2 +0 -0
- package/dashboard/dist/assets/be-vietnam-pro-vietnamese-600-normal-nyU-ZL2p.woff2 +0 -0
- package/dashboard/dist/assets/be-vietnam-pro-vietnamese-700-normal-Csr0PCuG.woff2 +0 -0
- package/dashboard/dist/assets/be-vietnam-pro-vietnamese-800-normal-D4LFh2W4.woff2 +0 -0
- package/dashboard/dist/assets/index-C6JlgSDz.js +9 -0
- package/dashboard/dist/assets/index-CeDllzpB.css +1 -0
- package/dashboard/dist/assets/jetbrains-mono-latin-ext-wght-normal-DBQx-q_a.woff2 +0 -0
- package/dashboard/dist/assets/jetbrains-mono-latin-wght-normal-B9CIFXIH.woff2 +0 -0
- package/dashboard/dist/assets/jetbrains-mono-vietnamese-wght-normal-Bt-aOZkq.woff2 +0 -0
- package/dashboard/dist/index.html +2 -2
- package/dashboard/src/App.tsx +224 -88
- package/dashboard/src/controls/DateRange.tsx +3 -3
- package/dashboard/src/controls/Search.tsx +2 -2
- package/dashboard/src/controls/popover.tsx +24 -4
- package/dashboard/src/format.ts +1 -1
- package/dashboard/src/i18n.tsx +32 -4
- package/dashboard/src/main.tsx +11 -2
- package/dashboard/src/model.ts +1 -1
- package/dashboard/src/overview-flow.css +24 -0
- package/dashboard/src/overviewFlow.tsx +76 -0
- package/dashboard/src/sessionDetail.test.ts +19 -0
- package/dashboard/src/sessionScope.tsx +28 -0
- package/dashboard/src/shell/ConsoleFilters.tsx +203 -0
- package/dashboard/src/shell/Header.tsx +29 -0
- package/dashboard/src/shell/MobileSheet.tsx +29 -0
- package/dashboard/src/shell/Palette.tsx +114 -0
- package/dashboard/src/shell/Settings.tsx +37 -0
- package/dashboard/src/shell/SpecialStates.tsx +145 -0
- package/dashboard/src/shell/preferences.ts +71 -0
- package/dashboard/src/shell/styleColors.ts +5 -0
- package/dashboard/src/shell/useShortcuts.ts +67 -0
- package/dashboard/src/state.test.ts +9 -0
- package/dashboard/src/state.ts +13 -2
- package/dashboard/src/styles/commands.css +61 -0
- package/dashboard/src/styles/console.css +149 -0
- package/dashboard/src/styles/donut.css +83 -0
- package/dashboard/src/styles/fonts/be-vietnam-pro-LICENSE +93 -0
- package/dashboard/src/styles/fonts/be-vietnam-pro-latin-400-normal.woff2 +0 -0
- package/dashboard/src/styles/fonts/be-vietnam-pro-latin-500-normal.woff2 +0 -0
- package/dashboard/src/styles/fonts/be-vietnam-pro-latin-600-normal.woff2 +0 -0
- package/dashboard/src/styles/fonts/be-vietnam-pro-latin-700-normal.woff2 +0 -0
- package/dashboard/src/styles/fonts/be-vietnam-pro-latin-800-normal.woff2 +0 -0
- package/dashboard/src/styles/fonts/be-vietnam-pro-latin-ext-400-normal.woff2 +0 -0
- package/dashboard/src/styles/fonts/be-vietnam-pro-latin-ext-500-normal.woff2 +0 -0
- package/dashboard/src/styles/fonts/be-vietnam-pro-latin-ext-600-normal.woff2 +0 -0
- package/dashboard/src/styles/fonts/be-vietnam-pro-latin-ext-700-normal.woff2 +0 -0
- package/dashboard/src/styles/fonts/be-vietnam-pro-latin-ext-800-normal.woff2 +0 -0
- package/dashboard/src/styles/fonts/be-vietnam-pro-vietnamese-400-normal.woff2 +0 -0
- package/dashboard/src/styles/fonts/be-vietnam-pro-vietnamese-500-normal.woff2 +0 -0
- package/dashboard/src/styles/fonts/be-vietnam-pro-vietnamese-600-normal.woff2 +0 -0
- package/dashboard/src/styles/fonts/be-vietnam-pro-vietnamese-700-normal.woff2 +0 -0
- package/dashboard/src/styles/fonts/be-vietnam-pro-vietnamese-800-normal.woff2 +0 -0
- package/dashboard/src/styles/fonts/jetbrains-mono-LICENSE +93 -0
- package/dashboard/src/styles/fonts/jetbrains-mono-latin-ext-wght-normal.woff2 +0 -0
- package/dashboard/src/styles/fonts/jetbrains-mono-latin-wght-normal.woff2 +0 -0
- package/dashboard/src/styles/fonts/jetbrains-mono-vietnamese-wght-normal.woff2 +0 -0
- package/dashboard/src/styles/fonts.css +240 -0
- package/dashboard/src/styles/shell.css +151 -0
- package/dashboard/src/styles/states.css +32 -0
- package/dashboard/src/styles/tokens.css +159 -0
- package/dashboard/src/styles.css +13 -44
- package/dashboard/src/tip.ts +3 -1
- package/dashboard/src/treemap.ts +3 -0
- package/dashboard/src/ui.tsx +21 -32
- package/dashboard/src/views/Breakdown.tsx +46 -0
- package/dashboard/src/views/SessionDetail.tsx +67 -0
- package/dashboard/src/views/breakdown.css +33 -0
- package/dashboard/src/views/{Activity.tsx → classic/Activity.tsx} +31 -50
- package/dashboard/src/views/classic/Context.tsx +140 -0
- package/dashboard/src/views/{Models.tsx → classic/Models.tsx} +18 -35
- package/dashboard/src/views/classic/Overview.tsx +80 -0
- package/dashboard/src/views/classic/Projects.tsx +98 -0
- package/dashboard/src/views/{Sessions.tsx → classic/Sessions.tsx} +14 -17
- package/dashboard/src/views/{Subagents.tsx → classic/Subagents.tsx} +10 -34
- package/dashboard/src/views/console/Activity.tsx +241 -0
- package/dashboard/src/views/console/ConsoleBoot.tsx +73 -0
- package/dashboard/src/views/console/Context.tsx +162 -0
- package/dashboard/src/views/console/Models.tsx +187 -0
- package/dashboard/src/views/console/Overview.tsx +91 -0
- package/dashboard/src/views/console/Projects.tsx +6 -0
- package/dashboard/src/views/console/ProviderMeters.tsx +35 -0
- package/dashboard/src/views/console/Sessions.tsx +6 -0
- package/dashboard/src/views/console/Subagents.tsx +137 -0
- package/dashboard/src/views/console/activity-context.css +92 -0
- package/dashboard/src/views/console/console-boot.css +137 -0
- package/dashboard/src/views/console/modelVisuals.tsx +29 -0
- package/dashboard/src/views/console/models-subagents.css +203 -0
- package/dashboard/src/views/donut/Activity.tsx +247 -0
- package/dashboard/src/views/donut/Context.tsx +169 -0
- package/dashboard/src/views/donut/DonutBoot.tsx +68 -0
- package/dashboard/src/views/donut/Models.tsx +58 -0
- package/dashboard/src/views/donut/Overview.tsx +49 -0
- package/dashboard/src/views/donut/Projects.tsx +6 -0
- package/dashboard/src/views/donut/Ring.tsx +30 -0
- package/dashboard/src/views/donut/Sessions.tsx +6 -0
- package/dashboard/src/views/donut/Subagents.tsx +131 -0
- package/dashboard/src/views/donut/activity-context.css +154 -0
- package/dashboard/src/views/donut/donut-boot.css +165 -0
- package/dashboard/src/views/donut/models-subagents.css +157 -0
- package/dashboard/src/views/records/Projects.tsx +140 -0
- package/dashboard/src/views/records/Sessions.tsx +125 -0
- package/dashboard/src/views/records/records.css +119 -0
- package/dashboard/src/views/session-detail.css +44 -0
- package/dashboard/src/vm/activity.ts +72 -0
- package/dashboard/src/vm/colors.ts +57 -0
- package/dashboard/src/vm/context.ts +81 -0
- package/dashboard/src/vm/filterChoices.ts +27 -0
- package/dashboard/src/vm/models.ts +50 -0
- package/dashboard/src/vm/overview.ts +46 -0
- package/dashboard/src/vm/palette.ts +63 -0
- package/dashboard/src/vm/projects.ts +63 -0
- package/dashboard/src/vm/providerBreakdown.ts +19 -0
- package/dashboard/src/vm/sessionDetail.ts +16 -0
- package/dashboard/src/vm/sessions.ts +36 -0
- package/dashboard/src/vm/specialStates.ts +64 -0
- package/dashboard/src/vm/subagents.ts +36 -0
- package/dashboard/src/vm.test.ts +183 -0
- package/package.json +1 -1
- package/src/dashboard.mjs +4 -1
- package/dashboard/dist/assets/index-Ba0kF2tG.js +0 -9
- package/dashboard/dist/assets/index-NQzaBVIY.css +0 -1
- package/dashboard/dist/assets/montserrat-cyrillic-ext-wght-normal-CO5hGrJv.woff2 +0 -0
- package/dashboard/dist/assets/montserrat-cyrillic-wght-normal-EAA9jha_.woff2 +0 -0
- package/dashboard/dist/assets/roboto-mono-cyrillic-ext-wght-normal-BUDPrIko.woff2 +0 -0
- package/dashboard/dist/assets/roboto-mono-cyrillic-wght-normal-HUlVHixE.woff2 +0 -0
- package/dashboard/dist/assets/roboto-mono-greek-wght-normal-BJJTbwTT.woff2 +0 -0
- package/dashboard/src/views/Context.tsx +0 -183
- package/dashboard/src/views/Overview.tsx +0 -83
- package/dashboard/src/views/Projects.tsx +0 -116
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { effortColor } from "../../vm/colors.ts";
|
|
2
|
+
import type { CSSProperties } from "react";
|
|
3
|
+
import { Search } from "../../controls/Search.tsx";
|
|
4
|
+
import { NoMatch } from "../../shell/SpecialStates.tsx";
|
|
5
|
+
import { useDash } from "../../dash.ts";
|
|
6
|
+
import { mainLevel, type Fact, type SessionRow } from "../../model.ts";
|
|
7
|
+
import { useStyleColors } from "../../shell/styleColors.ts";
|
|
8
|
+
import type { SortKey } from "../../state.ts";
|
|
9
|
+
import { CostCell, Empty, tip, type TipRow } from "../../ui.tsx";
|
|
10
|
+
import { buildSessionsVM } from "../../vm/sessions.ts";
|
|
11
|
+
import { ActiveSessionScope } from "../../sessionScope.tsx";
|
|
12
|
+
import { SessionLink } from "../SessionDetail.tsx";
|
|
13
|
+
import "./records.css";
|
|
14
|
+
|
|
15
|
+
export function Sessions({ F, variant }: { F: Fact[]; variant: "console" | "donut" }) {
|
|
16
|
+
const { M, S, t, L, f, filter, set, limit, more } = useDash();
|
|
17
|
+
const colors = useStyleColors();
|
|
18
|
+
const { rows, total } = buildSessionsVM(M, F, S, limit, filter);
|
|
19
|
+
const sort = (key: SortKey) => set(S.sort === key ? { dir: S.dir === 1 ? -1 : 1 } : { sort: key, dir: -1 });
|
|
20
|
+
const sorts = { start: t("start"), dur: t("dur"), turns: t("turns"), ctx: t("ctxPerReq"), out: t("out"), cost: t("cost") };
|
|
21
|
+
const sortHead = (key: SortKey) => (
|
|
22
|
+
<th scope="col" className="num" aria-sort={S.sort === key ? (S.dir === 1 ? "ascending" : "descending") : undefined}>
|
|
23
|
+
<button type="button" onClick={() => sort(key)}>{sorts[key]}{S.sort === key && (S.dir === 1 ? " ↑" : " ↓")}</button>
|
|
24
|
+
</th>
|
|
25
|
+
);
|
|
26
|
+
const when = (r: SessionRow) => filter.from === filter.to
|
|
27
|
+
? `${String(r.x.hour).padStart(2, "0")}:${String(r.x.min).padStart(2, "0")}`
|
|
28
|
+
: f.startText(r.x);
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<div className={`${variant}-view`}>
|
|
32
|
+
<section className={`card ${variant}-panel record-sessions`}>
|
|
33
|
+
<header>
|
|
34
|
+
<h2>{t("sessions")}</h2>
|
|
35
|
+
{total || !S.q.trim() ? <span className="num">{f.int(rows.length)} / {f.int(total)} {t("shown")}</span> : null}
|
|
36
|
+
<Search value={S.q} placeholder={t("search")} clearLabel={t("clear")} onChange={(q) => set({ q }, { replace: true })} />
|
|
37
|
+
{variant === "donut" && (
|
|
38
|
+
<div className="record-quick-sort" role="group">
|
|
39
|
+
{(["cost", "out", "start"] as const).map((key) => (
|
|
40
|
+
<button key={key} className="field" type="button" aria-pressed={S.sort === key} onClick={() => sort(key)}>
|
|
41
|
+
{key === "start" ? t("newest") : sorts[key]}{S.sort === key && (S.dir === 1 ? " ↑" : " ↓")}
|
|
42
|
+
</button>
|
|
43
|
+
))}
|
|
44
|
+
</div>
|
|
45
|
+
)}
|
|
46
|
+
<div className="record-row-sort">
|
|
47
|
+
<select className="field" aria-label={t("sessions")} value={S.sort} onChange={(event) => sort(event.currentTarget.value as SortKey)}>
|
|
48
|
+
{Object.entries(sorts).map(([key, label]) => <option key={key} value={key}>{label}</option>)}
|
|
49
|
+
</select>
|
|
50
|
+
<button type="button" className="field" aria-label={sorts[S.sort]} onClick={() => sort(S.sort)}>{S.dir === 1 ? "↑" : "↓"}</button>
|
|
51
|
+
</div>
|
|
52
|
+
</header>
|
|
53
|
+
<ActiveSessionScope />
|
|
54
|
+
{total ? <table className={`${variant}-table record-table record-session-table`}>
|
|
55
|
+
<thead><tr><th scope="col">{t("title")}</th><th scope="col">{t("project")}</th><th scope="col">{t("modelEffort")}</th>
|
|
56
|
+
{sortHead("start")}{sortHead("dur")}{sortHead("turns")}{sortHead("ctx")}{sortHead("out")}{sortHead("cost")}</tr></thead>
|
|
57
|
+
<tbody>{rows.map((r) => {
|
|
58
|
+
const name = M.projects[r.x.p];
|
|
59
|
+
const metadata = [
|
|
60
|
+
M.providers.length > 1 ? M.providers[r.x.pr ?? 0] : "",
|
|
61
|
+
r.x.subs.length ? L.nSubs(r.x.subs.length) : "",
|
|
62
|
+
r.lapses ? L.nLapses(r.lapses) : "",
|
|
63
|
+
].filter(Boolean).join(" · ");
|
|
64
|
+
return (
|
|
65
|
+
<tr key={r.s}>
|
|
66
|
+
<th scope="row" className="record-title">
|
|
67
|
+
<SessionLink session={r.x} />
|
|
68
|
+
{metadata && <small title={metadata}>{metadata}</small>}
|
|
69
|
+
</th>
|
|
70
|
+
<td data-label={t("project")}>
|
|
71
|
+
<span className="record-project-name">
|
|
72
|
+
<i aria-hidden="true" className="record-project-dot" style={{ background: `var(${colors.projects[r.x.p] ?? "--proj-other"})` }} />
|
|
73
|
+
<button type="button" className="rowlink" onClick={() => set({ project: name })} title={name}>{name}</button>
|
|
74
|
+
</span>
|
|
75
|
+
</td>
|
|
76
|
+
<td data-label={t("modelEffort")}><ModelEffort row={r} /></td>
|
|
77
|
+
<td className="num" data-label={t("start")}>{when(r)}</td>
|
|
78
|
+
<td className="num" data-label={t("dur")}>{f.dur(r.x.dur)}</td>
|
|
79
|
+
<td className="num" data-label={t("turns")}>{f.int(r.x.owner)}</td>
|
|
80
|
+
<td className="num" data-label={t("ctxPerReq")}>{r.q ? f.cmp(r.ctx) : "—"}</td>
|
|
81
|
+
<td className="num" data-label={t("out")}>{f.cmp(r.o)}</td>
|
|
82
|
+
<td className="num" data-label={t("cost")}><CostCell r={r} /></td>
|
|
83
|
+
</tr>
|
|
84
|
+
);
|
|
85
|
+
})}</tbody>
|
|
86
|
+
</table> : S.q.trim() && !S.sessionsBy ? <NoMatch facts={F} /> : <Empty />}
|
|
87
|
+
{total > limit && <button type="button" className="field record-session-more" onClick={more}>{t("more")}</button>}
|
|
88
|
+
</section>
|
|
89
|
+
</div>
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function ModelEffort({ row }: { row: SessionRow }) {
|
|
94
|
+
const { M, t, f } = useDash();
|
|
95
|
+
const colors = useStyleColors();
|
|
96
|
+
const model = M.models[row.x.parent] ?? "";
|
|
97
|
+
const { runs } = row.x;
|
|
98
|
+
const level = runs.length ? M.efforts[mainLevel(runs)] : "";
|
|
99
|
+
const caption = [model, level].filter(Boolean).join(" · ");
|
|
100
|
+
const modelParts = row.mix.flatMap((value, index) => value > 0 ? [{ index, value }] : []);
|
|
101
|
+
const output = modelParts.reduce((sum, part) => sum + part.value, 0);
|
|
102
|
+
const requests = runs.reduce((sum, [, q]) => sum + q, 0);
|
|
103
|
+
const mixTips = modelParts.flatMap(({ index, value }) => [
|
|
104
|
+
{ name: `${M.models[index]} · ${t("mainThread")}`, value: value - row.subMix[index] },
|
|
105
|
+
{ name: `${M.models[index]} · ${t("subs")}`, value: row.subMix[index] },
|
|
106
|
+
]).filter(({ value }) => value > 0).sort((a, b) => b.value - a.value);
|
|
107
|
+
const meter = (token: string, width: number) => ({ "--c": `var(${token})`, width: `${width}%` }) as CSSProperties;
|
|
108
|
+
return (
|
|
109
|
+
<span className="record-model-effort">
|
|
110
|
+
<span className="record-table-value" title={caption}>{caption}{runs.length > 1 && ` +${runs.length - 1}`}</span>
|
|
111
|
+
{modelParts.length > 1 && (
|
|
112
|
+
<span className="record-session-strip" tabIndex={0} data-tip={tip(t("out"), mixTips.map(({ name, value }): TipRow =>
|
|
113
|
+
["", name, `${f.cmp(value)} · ${f.pct(value / output)}`]))}>
|
|
114
|
+
{modelParts.map(({ index, value }) => <i className="bar-fill" key={index} style={meter(colors.models[index] ?? "--prov-unknown", value / output * 100)} />)}
|
|
115
|
+
</span>
|
|
116
|
+
)}
|
|
117
|
+
{runs.length > 1 && requests > 0 && (
|
|
118
|
+
<span className="record-session-strip" tabIndex={0} data-tip={tip(t("effort"), runs.map(([effort, q]): TipRow =>
|
|
119
|
+
["", M.efforts[effort], `${f.int(q)} ${t("requests").toLowerCase()}`]))}>
|
|
120
|
+
{runs.map(([effort, q], index) => <i className="bar-fill" key={index} style={meter(effortColor(effort), q / requests * 100)} />)}
|
|
121
|
+
</span>
|
|
122
|
+
)}
|
|
123
|
+
</span>
|
|
124
|
+
);
|
|
125
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
.record-project-map { position: relative; }
|
|
2
|
+
.record-project-tile {
|
|
3
|
+
position: absolute;
|
|
4
|
+
display: grid;
|
|
5
|
+
align-content: end;
|
|
6
|
+
gap: var(--space-1);
|
|
7
|
+
min-width: 0;
|
|
8
|
+
overflow: hidden;
|
|
9
|
+
padding: 0;
|
|
10
|
+
border: var(--space-1) solid var(--panel);
|
|
11
|
+
border-radius: var(--radius-md);
|
|
12
|
+
text-align: start;
|
|
13
|
+
font: inherit;
|
|
14
|
+
}
|
|
15
|
+
.record-project-tile:not(:empty) { padding: var(--space-2); }
|
|
16
|
+
button.record-project-tile { cursor: pointer; }
|
|
17
|
+
.record-project-tile > *, .record-table .rowlink, .record-table-value,
|
|
18
|
+
.record-title small { display: block; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
19
|
+
.record-project-tile:focus-visible, .record-table button:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--focus); }
|
|
20
|
+
.record-table { table-layout: fixed; width: 100%; }
|
|
21
|
+
.record-table td { overflow: hidden; text-overflow: ellipsis; }
|
|
22
|
+
.record-table th button { color: inherit; font: inherit; }
|
|
23
|
+
.record-table th button:not(.rowlink) { white-space: normal; overflow-wrap: anywhere; }
|
|
24
|
+
.record-table .record-title, .record-project-name { min-width: 0; text-align: start; }
|
|
25
|
+
.record-table .record-title .rowlink, .record-project-name .rowlink { display: inline-block; vertical-align: middle; max-width: calc(100% - var(--space-4)); }
|
|
26
|
+
.record-project-dot { display: inline-block; vertical-align: middle; inline-size: var(--space-2); block-size: var(--space-2); margin-inline-end: var(--space-1); border-radius: var(--radius-sm); }
|
|
27
|
+
.record-project-share, .record-title small { color: var(--muted); font-size: var(--fs-xs); }
|
|
28
|
+
.record-project-share { display: block; }
|
|
29
|
+
.record-project-trend .spark { display: block; width: 100%; max-width: calc(2 * var(--space-8)); margin-inline-start: auto; color: var(--work); }
|
|
30
|
+
.record-session-table th:first-child { width: 24%; }
|
|
31
|
+
.record-session-table th:nth-child(3) { width: 14%; }
|
|
32
|
+
.record-session-more { margin-top: var(--space-3); cursor: pointer; }
|
|
33
|
+
.record-model-effort { display: block; min-width: 0; }
|
|
34
|
+
.record-session-strip {
|
|
35
|
+
display: flex;
|
|
36
|
+
overflow: hidden;
|
|
37
|
+
min-width: 0;
|
|
38
|
+
margin-block-start: var(--space-1);
|
|
39
|
+
height: var(--space-1);
|
|
40
|
+
background: var(--track);
|
|
41
|
+
}
|
|
42
|
+
.record-row-sort { display: none; }
|
|
43
|
+
|
|
44
|
+
@media (max-width: 639px) {
|
|
45
|
+
.record-row-sort { display: flex; min-width: 0; max-width: 100%; gap: var(--space-1); }
|
|
46
|
+
.record-row-sort .field { min-height: var(--tap-min); min-width: var(--tap-min); }
|
|
47
|
+
.record-row-sort select.field { flex: 1; min-width: 0; }
|
|
48
|
+
.record-table thead { display: none; }
|
|
49
|
+
.record-table {
|
|
50
|
+
display: block;
|
|
51
|
+
border-collapse: separate;
|
|
52
|
+
}
|
|
53
|
+
.record-table tbody, .record-table tfoot { display: grid; gap: var(--space-2); }
|
|
54
|
+
.record-table tfoot { margin-top: var(--space-2); }
|
|
55
|
+
.record-table tr {
|
|
56
|
+
display: grid;
|
|
57
|
+
min-width: 0;
|
|
58
|
+
padding: var(--space-2) var(--space-3);
|
|
59
|
+
border: 1px solid var(--line);
|
|
60
|
+
border-radius: var(--radius-md);
|
|
61
|
+
background: var(--sunken);
|
|
62
|
+
}
|
|
63
|
+
.record-table .record-title { width: auto; padding: 0 0 var(--space-1); white-space: nowrap; }
|
|
64
|
+
.record-table td {
|
|
65
|
+
display: grid;
|
|
66
|
+
grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
|
|
67
|
+
align-items: center;
|
|
68
|
+
column-gap: var(--space-2);
|
|
69
|
+
padding: var(--space-1) 0;
|
|
70
|
+
border: 0;
|
|
71
|
+
text-align: end;
|
|
72
|
+
}
|
|
73
|
+
.record-table td::before {
|
|
74
|
+
content: attr(data-label);
|
|
75
|
+
font-family: var(--font-sans);
|
|
76
|
+
color: var(--muted);
|
|
77
|
+
text-align: start;
|
|
78
|
+
white-space: normal;
|
|
79
|
+
}
|
|
80
|
+
.record-project-name { text-align: end; }
|
|
81
|
+
.record-sessions .search { min-height: var(--tap-min); max-width: 100%; }
|
|
82
|
+
.record-sessions .search input { width: 100%; }
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.record-project-trend .spark polyline { stroke: var(--work); }
|
|
86
|
+
.record-project-trend .spark circle { fill: var(--work); stroke: var(--panel); }
|
|
87
|
+
.record-project-trend .spark .g0, .record-project-trend .spark .g1 { stop-color: var(--work); }
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
.record-quick-sort { display: flex; flex-wrap: wrap; gap: var(--space-2); }
|
|
91
|
+
.record-quick-sort .field, .donut-view .record-session-more {
|
|
92
|
+
background: var(--sunken);
|
|
93
|
+
border: 1px solid var(--line);
|
|
94
|
+
border-radius: var(--radius-pill);
|
|
95
|
+
color: var(--ink);
|
|
96
|
+
cursor: pointer;
|
|
97
|
+
font-weight: var(--fw-medium);
|
|
98
|
+
}
|
|
99
|
+
.record-quick-sort .field[aria-pressed="true"] {
|
|
100
|
+
background: var(--selected-bg);
|
|
101
|
+
border-color: var(--selected-line);
|
|
102
|
+
font-weight: var(--fw-semibold);
|
|
103
|
+
}
|
|
104
|
+
.record-quick-sort .field:focus-visible, .donut-view .record-session-more:focus-visible {
|
|
105
|
+
outline: none;
|
|
106
|
+
box-shadow: var(--focus-ring);
|
|
107
|
+
}
|
|
108
|
+
.donut-view .record-table tbody tr:hover { background: var(--row-active); }
|
|
109
|
+
.donut-view .record-table th button:not(.rowlink) { cursor: pointer; padding: 0; border: 0; background: none; }
|
|
110
|
+
.donut-view .record-table th, .donut-view .record-table td { padding: var(--space-2); }
|
|
111
|
+
|
|
112
|
+
@media (max-width: 639px) {
|
|
113
|
+
.donut-view .record-table td { padding: var(--space-1) 0; }
|
|
114
|
+
.donut-view .record-table .record-title { padding: 0 0 var(--space-2); }
|
|
115
|
+
.donut-view .record-project-map { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
|
116
|
+
.donut-view .record-project-tile { position: static; align-content: space-between; }
|
|
117
|
+
.donut-view .record-project-tile .num { font-size: var(--fs-kpi); font-weight: var(--fw-heavy); }
|
|
118
|
+
.donut-view .record-project-tile strong { white-space: normal; overflow-wrap: anywhere; }
|
|
119
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
.session-link {
|
|
2
|
+
display: inline-block;
|
|
3
|
+
max-width: 100%;
|
|
4
|
+
color: inherit;
|
|
5
|
+
overflow-wrap: anywhere;
|
|
6
|
+
text-decoration: underline;
|
|
7
|
+
text-decoration-color: color-mix(in srgb, currentColor 55%, transparent);
|
|
8
|
+
text-underline-offset: .16em;
|
|
9
|
+
}
|
|
10
|
+
.session-link:hover, .session-link:focus-visible { text-decoration-color: currentColor; }
|
|
11
|
+
.session-link:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
|
|
12
|
+
.session-detail { margin-top: var(--space-4); }
|
|
13
|
+
.session-detail h3 { margin: 0; font-size: var(--fs-xl); overflow-wrap: anywhere; }
|
|
14
|
+
.session-detail-meta, .session-detail-note {
|
|
15
|
+
margin: var(--space-2) 0;
|
|
16
|
+
color: var(--ink-2);
|
|
17
|
+
font-size: var(--fs-sm);
|
|
18
|
+
overflow-wrap: anywhere;
|
|
19
|
+
}
|
|
20
|
+
.session-detail-metrics {
|
|
21
|
+
display: grid;
|
|
22
|
+
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
23
|
+
margin: var(--space-3) 0 0;
|
|
24
|
+
border-top: 1px solid var(--line);
|
|
25
|
+
}
|
|
26
|
+
.session-detail-metrics > div { padding: var(--space-3) var(--space-2); border-bottom: 1px solid var(--line); }
|
|
27
|
+
.session-detail-metrics dt { color: var(--ink-2); }
|
|
28
|
+
.session-detail-metrics dd { margin: var(--space-1) 0 0; overflow-wrap: anywhere; }
|
|
29
|
+
.session-detail-metrics dd:first-of-type { font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; }
|
|
30
|
+
|
|
31
|
+
.command-results button:has(.command-session-meta) > * {
|
|
32
|
+
display: block;
|
|
33
|
+
overflow: hidden;
|
|
34
|
+
text-overflow: ellipsis;
|
|
35
|
+
white-space: nowrap;
|
|
36
|
+
}
|
|
37
|
+
.command-results button .command-session-meta { color: var(--ink-2); font-size: var(--fs-xs); white-space: normal; overflow-wrap: anywhere; }
|
|
38
|
+
.session-detail-days { width: 100%; margin-top: var(--space-4); }
|
|
39
|
+
.session-detail-days caption { margin-bottom: var(--space-2); text-align: start; font-weight: var(--fw-semibold); }
|
|
40
|
+
|
|
41
|
+
@media (max-width: 639px) {
|
|
42
|
+
.session-link { min-height: var(--tap-min); align-content: center; }
|
|
43
|
+
.record-title .session-link { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
44
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { dayAdd, rebuilds, skillUses, slice, slotsOf, toolCalls, type Fact, type Filter, type Model, type Session } from "../model.ts";
|
|
2
|
+
import type { UrlState } from "../state.ts";
|
|
3
|
+
|
|
4
|
+
const work = (M: Model, F: Fact[]) => {
|
|
5
|
+
const ids = [...new Set(F.map((x) => x.s))], ss = ids.map((s) => M.sessions[s]), add = (k: (s: Session) => number) => ss.reduce((n, s) => n + k(s), 0);
|
|
6
|
+
return { ids, ss, api: add((s) => s.api), tool: add((s) => s.tool), idle: add((s) => Math.max(0, s.dur * 60 - s.api - s.tool)), owner: add((s) => s.owner), compact: add((s) => s.compact), la: add((s) => s.la), lr: add((s) => s.lr) };
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
// How long the agent worked, waiting for the model or running tools, for each owner turn.
|
|
10
|
+
const perTurn = (w: { api: number; tool: number; owner: number }) => (w.owner ? (w.api + w.tool) / w.owner : 0);
|
|
11
|
+
|
|
12
|
+
export const ACTIVITY_PREVIEW_SIZE = 12;
|
|
13
|
+
|
|
14
|
+
export function buildActivityVM(M: Model, F: Fact[], list: string[], filter: Filter, by: UrlState["heat"]) {
|
|
15
|
+
const w = work(M, F), pf = dayAdd(filter.from, -list.length);
|
|
16
|
+
const p = pf >= M.first ? work(M, slice(M, filter, pf, dayAdd(filter.from, -1))) : null;
|
|
17
|
+
|
|
18
|
+
// Per day by session start, or per hour in a one-day window.
|
|
19
|
+
const slots = slotsOf(list), hourly = slots !== list;
|
|
20
|
+
const at = (s: Session) => slots.indexOf(hourly ? s.hour : s.day);
|
|
21
|
+
const per = (k: (s: Session) => number) => { const out = slots.map(() => 0); w.ss.forEach((s) => { const i = at(s); if (i >= 0) out[i] += k(s); }); return out; };
|
|
22
|
+
const api = per((s) => s.api / 3600), tool = per((s) => s.tool / 3600), idle = per((s) => Math.max(0, s.dur * 60 - s.api - s.tool) / 3600);
|
|
23
|
+
const la = per((s) => s.la), lr = per((s) => s.lr);
|
|
24
|
+
const daily = (k: (s: Session) => number) => list.map((d) => w.ss.reduce((n, s) => n + (s.day === d ? k(s) : 0), 0));
|
|
25
|
+
const series = {
|
|
26
|
+
api: daily((s) => s.api),
|
|
27
|
+
tool: daily((s) => s.tool),
|
|
28
|
+
owner: daily((s) => s.owner),
|
|
29
|
+
lines: daily((s) => s.la + s.lr),
|
|
30
|
+
compact: daily((s) => s.compact),
|
|
31
|
+
perTurn: list.map((d) => { const ss = w.ss.filter((s) => s.day === d), o = ss.reduce((n, s) => n + s.owner, 0); return o ? ss.reduce((n, s) => n + s.api + s.tool, 0) / o : 0; }),
|
|
32
|
+
};
|
|
33
|
+
const r = rebuilds(F);
|
|
34
|
+
const count = r.start.n + r.compaction.n + r.idle.n + r.other.n;
|
|
35
|
+
return { w, p, slots, timeRows: slots.map((_, i) => [api[i], tool[i]]), lineRows: slots.map((_, i) => [la[i], lr[i]]), idle, series, perTurnNow: perTurn(w), perTurnPrior: p ? perTurn(p) : undefined, heat: buildHeat(F, by), tools: buildTools(M, w.ids), skills: buildSkills(M, w.ids), rebuild: { r, count, gmax: Math.max(1, ...r.gaps) } };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function buildHeat(F: Fact[], by: UrlState["heat"]) {
|
|
39
|
+
const g = Array.from({ length: 7 }, () => new Array<number>(24).fill(0));
|
|
40
|
+
let max = 0, peak = [0, 0];
|
|
41
|
+
// Beside the grid: the weekend's and the night's share, and how many sessions had requests in the same hour.
|
|
42
|
+
let all = 0, weekend = 0, night = 0;
|
|
43
|
+
const slots = new Map<string, Set<number>>();
|
|
44
|
+
for (const x of F) {
|
|
45
|
+
const wd = (new Date(x.d + "T00:00:00Z").getUTCDay() + 6) % 7, v = by === "req" ? x.q : x.o;
|
|
46
|
+
g[wd][x.h] += v; all += v;
|
|
47
|
+
if (wd >= 5) weekend += v;
|
|
48
|
+
if (x.h >= 22 || x.h < 6) night += v;
|
|
49
|
+
if (g[wd][x.h] > max) { max = g[wd][x.h]; peak = [wd, x.h]; }
|
|
50
|
+
const k = x.d + " " + x.h;
|
|
51
|
+
if (!slots.has(k)) slots.set(k, new Set());
|
|
52
|
+
slots.get(k)!.add(x.s);
|
|
53
|
+
}
|
|
54
|
+
const same = [...slots.values()].map((s) => s.size).sort((a, b) => a - b), mid = same[Math.floor(same.length / 2)], most = same[same.length - 1];
|
|
55
|
+
return { g, max, peak, all, weekend, night, mid, most };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function buildTools(M: Model, ids: number[]) {
|
|
59
|
+
const rows = toolCalls(M, ids);
|
|
60
|
+
const calls = rows.reduce((n, [, [c]]) => n + c, 0), errs = rows.reduce((n, [, [, e]]) => n + e, 0), tmax = Math.max(1, ...rows.map(([, [c]]) => c));
|
|
61
|
+
const worst = [...rows].sort((a, b) => b[1][1] - a[1][1])[0];
|
|
62
|
+
return { rows, calls, errs, tmax, worst };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function buildSkills(M: Model, ids: number[]) {
|
|
66
|
+
const rows = skillUses(M, ids), uses = rows.reduce((n, r) => n + r.command + r.agent, 0);
|
|
67
|
+
const top = new Set([...rows].sort((a, b) => b.command + b.agent - (a.command + a.agent)).slice(0, ACTIVITY_PREVIEW_SIZE).map((r) => r.name));
|
|
68
|
+
const max = Math.max(1, ...rows.map((r) => r.command + r.agent));
|
|
69
|
+
return { rows, uses, preview: rows.filter((r) => top.has(r.name)), max };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export type ActivityVM = ReturnType<typeof buildActivityVM>;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { Model } from "../model.ts";
|
|
2
|
+
|
|
3
|
+
type ProviderFamily = "claude" | "codex" | "antigravity" | "4" | "5" | "unknown";
|
|
4
|
+
type ProjectSlot = 1 | 2 | 3 | 4 | 5 | 6 | "other";
|
|
5
|
+
type ProviderToken = `--prov-${ProviderFamily}`;
|
|
6
|
+
type ModelToken = ProviderToken | `--model-${Exclude<ProviderFamily, "unknown">}-${number}`;
|
|
7
|
+
|
|
8
|
+
function providerFamily(name: string, index: number): ProviderFamily {
|
|
9
|
+
const key = name.toLowerCase();
|
|
10
|
+
if (key === "agy" || key === "antigravity") return "antigravity";
|
|
11
|
+
if (key === "claude" || key === "codex") return key;
|
|
12
|
+
if (!key || key === "unknown") return "unknown";
|
|
13
|
+
if (index === 3) return "4";
|
|
14
|
+
if (index === 4) return "5";
|
|
15
|
+
return "unknown";
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Rank from all facts so a date range or filter cannot change a model's family or shade.
|
|
19
|
+
export function buildColorVM(M: Model) {
|
|
20
|
+
const families = M.providers.map(providerFamily);
|
|
21
|
+
const output = M.models.map(() => new Map<number, number>());
|
|
22
|
+
for (const fact of M.facts) {
|
|
23
|
+
const provider = M.sessions[fact.s].pr ?? 0;
|
|
24
|
+
const byProvider = output[fact.m];
|
|
25
|
+
byProvider.set(provider, (byProvider.get(provider) ?? 0) + fact.o);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const modelProviders = output.map((byProvider) => {
|
|
29
|
+
const ranked = [...byProvider].sort(([a, x], [b, y]) => y - x || a - b);
|
|
30
|
+
return ranked[0]?.[0] ?? -1;
|
|
31
|
+
});
|
|
32
|
+
const models: ModelToken[] = M.models.map(() => "--prov-unknown");
|
|
33
|
+
for (const [provider, family] of families.entries()) {
|
|
34
|
+
if (family === "unknown") continue;
|
|
35
|
+
const ranked = M.models.map((_, i) => i)
|
|
36
|
+
.filter((i) => modelProviders[i] === provider && M.models[i] !== "unknown")
|
|
37
|
+
.sort((a, b) => output[b].get(provider)! - output[a].get(provider)!);
|
|
38
|
+
const shades = family === "4" || family === "5" ? 3 : 5;
|
|
39
|
+
ranked.slice(0, shades).forEach((model, rank) => {
|
|
40
|
+
models[model] = `--model-${family}-${rank + 1}`;
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
const projectSlots = M.projects.map((): ProjectSlot => "other");
|
|
44
|
+
const slots = [1, 2, 3, 4, 5, 6] as const;
|
|
45
|
+
M.projectRank.slice(0, slots.length).forEach((project, i) => { projectSlots[project] = slots[i]; });
|
|
46
|
+
return {
|
|
47
|
+
providers: families.map((family): ProviderToken => `--prov-${family}`),
|
|
48
|
+
modelProviders,
|
|
49
|
+
models,
|
|
50
|
+
projects: projectSlots.map((slot): `--proj-${ProjectSlot}` => `--proj-${slot}`),
|
|
51
|
+
projectInk: projectSlots.map((slot): `--proj-ink-${ProjectSlot}` => `--proj-ink-${slot}`),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function effortColor(effort: number) {
|
|
56
|
+
return effort >= 0 && effort < 5 ? `--effort-${effort + 1}` : "--req-weak";
|
|
57
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { dayAdd, keep, slice, type Compaction, type Ctx, type Fact, type Filter, type Model } from "../model.ts";
|
|
2
|
+
|
|
3
|
+
const median = (xs: (number | null)[]) => {
|
|
4
|
+
const v = xs.filter((x): x is number => x !== null).sort((a, b) => a - b), m = v.length >> 1;
|
|
5
|
+
return v.length ? (v.length % 2 ? v[m] : (v[m - 1] + v[m]) / 2) : null;
|
|
6
|
+
};
|
|
7
|
+
export const TAIL = 15; // requests after a session's last compaction under which it ended soon after
|
|
8
|
+
const LONG = 4; // compactions that make a session long
|
|
9
|
+
const NEAR = 0.03; // a point this close to where compaction fires now gives way to it
|
|
10
|
+
const PARTS = 4;
|
|
11
|
+
export const round5 = (v: number) => Math.round(v / 5000) * 5000; // a firing point as read: measured points scatter by a few thousand tokens
|
|
12
|
+
const compacting = (C: Compaction[]) => C.reduce((n, x) => n + (x.sum ?? 0) + x.rb, 0);
|
|
13
|
+
const reading = (F: Fact[]) => F.reduce((n, x) => n + (x.k?.[0] ?? 0), 0);
|
|
14
|
+
const costOf = (F: Fact[]) => F.reduce((n, x) => n + x.c, 0);
|
|
15
|
+
|
|
16
|
+
export type ReplayScope = "all" | "long";
|
|
17
|
+
|
|
18
|
+
export function buildContextVM(M: Model, F: Fact[], list: string[], filter: Filter, scope: ReplayScope) {
|
|
19
|
+
const C = M.compactions.filter(keep(M, filter)), X = M.context.filter(keep(M, filter));
|
|
20
|
+
const pf = dayAdd(filter.from, -list.length), pt = dayAdd(filter.from, -1), prev = pf >= M.first;
|
|
21
|
+
const PC = prev ? M.compactions.filter(keep(M, filter, pf, pt)) : null, PF = prev ? slice(M, filter, pf, pt) : null;
|
|
22
|
+
const total = costOf(F);
|
|
23
|
+
const daily = <T extends { d: string }>(rows: T[], v: (x: T) => number) => list.map((d) => rows.reduce((n, x) => n + (x.d === d ? v(x) : 0), 0));
|
|
24
|
+
const current = { count: C.length, compacting: compacting(C), reading: reading(F) };
|
|
25
|
+
const prior = { count: PC?.length, compacting: PC ? compacting(PC) : undefined, reading: PF ? reading(PF) : undefined };
|
|
26
|
+
const series = { count: daily(C, () => 1), compacting: daily(C, (x) => (x.sum ?? 0) + x.rb), reading: daily(F, (x) => x.k?.[0] ?? 0) };
|
|
27
|
+
return { total, current, prior, series, compactions: buildCompactions(C), reading: buildReading(M, F, X), replay: buildReplay(M, C, X, scope) };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function buildCompactions(C: Compaction[]) {
|
|
31
|
+
const main = C.filter((x) => !x.sub), auto = C.filter((x) => x.auto === 1);
|
|
32
|
+
const parts = [auto.filter((x) => !x.sub).length, main.filter((x) => x.auto === 0).length, C.length - main.length];
|
|
33
|
+
const measured = median(auto.filter((x) => !x.sub).map((x) => x.pre)) ?? median(auto.map((x) => x.pre)), fire = measured && round5(measured), kept = median(main.map((x) => x.kept));
|
|
34
|
+
const waits = C.map((x) => x.wait).filter((x): x is number => x !== null);
|
|
35
|
+
const priced = C.filter((x) => x.sum !== null), sum = priced.reduce((n, x) => n + x.sum!, 0) / (priced.length || 1), rb = C.reduce((n, x) => n + x.rb, 0) / C.length;
|
|
36
|
+
const soon = new Set(main.filter((x) => x.tail !== null && x.tail < TAIL).map((x) => x.s)).size;
|
|
37
|
+
const groups = [1, 2, 3, 4].map((k) => main.filter((x) => (k < 4 ? x.nth === k : x.nth >= 4)));
|
|
38
|
+
const intervals = groups.map((g) => ({ count: g.length, kept: median(g.map((x) => x.kept)), next: median(g.map((x) => x.next)), turns: median(g.map((x) => x.turns)) }));
|
|
39
|
+
return { count: C.length, mainCount: main.length, parts, fire, kept, wait: median(waits), totalWait: waits.reduce((a, b) => a + b, 0), sum, rb, soon, intervals };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function buildReading(M: Model, F: Fact[], X: Ctx[]) {
|
|
43
|
+
const E = M.edges, n = E.length + 1;
|
|
44
|
+
const b = new Array<number>(n + 1).fill(0), q = new Array<number>(n).fill(0);
|
|
45
|
+
for (const x of X) { x.b.forEach((v, j) => { b[j] += v; }); x.n.forEach((v, j) => { q[j] += v; }); }
|
|
46
|
+
const cost = b.reduce((a, v) => a + v, 0), reqs = q.reduce((a, v) => a + v, 0);
|
|
47
|
+
const at300 = E.indexOf(300e3) + 1, above = b.slice(at300, n).reduce((a, v) => a + v, 0), aboveQ = q.slice(at300).reduce((a, v) => a + v, 0);
|
|
48
|
+
const per = (j: number) => (q[j] ? b[j] / q[j] : 0), seen = q.map((v, j) => (v >= reqs * 0.01 ? j : -1)).filter((j) => j >= 0);
|
|
49
|
+
const top = seen.at(-1) ?? -1, base = seen.includes(2) ? 2 : seen[0] ?? -1;
|
|
50
|
+
const ctx = F.reduce((a, x) => a + x.i + x.cr + x.cw, 0) / (F.reduce((a, x) => a + x.q, 0) || 1);
|
|
51
|
+
const max = Math.max(...b.slice(0, n));
|
|
52
|
+
return { E, n, b, q, cost, reqs, above, aboveQ, per: q.map((_, j) => per(j)), top, base, ctx, max };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function buildReplay(M: Model, C: Compaction[], X: Ctx[], scope: ReplayScope) {
|
|
56
|
+
const counts = new Map<number, number>();
|
|
57
|
+
for (const x of M.compactions) if (!x.sub) counts.set(x.s, (counts.get(x.s) ?? 0) + 1);
|
|
58
|
+
const long = (s: number) => (counts.get(s) ?? 0) >= LONG;
|
|
59
|
+
const rows = X.filter((x) => x.r && (scope === "all" || long(x.s))), real = C.filter((x) => !x.sub && (scope === "all" || long(x.s)));
|
|
60
|
+
const P = M.points, NOW = P.length;
|
|
61
|
+
// Models whose points sit within NEAR of each other fire at one point: the point of the model with the most requests.
|
|
62
|
+
const reqs = new Map<number, number>();
|
|
63
|
+
for (const x of rows) if (M.fires[x.m]) reqs.set(M.fires[x.m]!, (reqs.get(M.fires[x.m]!) ?? 0) + x.n.reduce((a, v) => a + v, 0));
|
|
64
|
+
const levels = [...reqs.keys()].sort((a, b) => a - b);
|
|
65
|
+
const one = levels.length && levels.at(-1)! <= levels[0] * (1 + NEAR) ? [...reqs].sort((a, b) => b[1] - a[1])[0][0] : null;
|
|
66
|
+
const point = (j: number) => {
|
|
67
|
+
const v = [0, 0, 0, 0], sess = new Set<number>();
|
|
68
|
+
for (const x of rows) { for (let k = 0; k < PARTS; k++) v[k] += x.r![j * PARTS + k]; if (x.r![j * PARTS] > 0) sess.add(x.s); }
|
|
69
|
+
return { n: v[0], sess: sess.size, parts: [v[1], v[2], v[3]], total: v[1] + v[2] + v[3] };
|
|
70
|
+
};
|
|
71
|
+
const shown = [
|
|
72
|
+
...P.map((p, j) => ({ j, at: p, now: false })).filter((x) => !(one && Math.abs(x.at - one) <= one * NEAR)),
|
|
73
|
+
...(levels.length ? [{ j: NOW, at: one ?? levels[0], now: true }] : []),
|
|
74
|
+
].sort((a, b) => a.at - b.at || Number(a.now) - Number(b.now)).map((x) => ({ ...x, ...point(x.j) }))
|
|
75
|
+
// Past the first point at which nothing compacts, the rows repeat it, save the default.
|
|
76
|
+
.filter((x, i, all) => x.now || x.j === NOW - 1 || x.n > 0 || !all.slice(0, i).some((y) => y.n === 0));
|
|
77
|
+
const base = shown.find((x) => x.now) ?? null, max = Math.max(1, ...shown.map((x) => x.total));
|
|
78
|
+
return { hasRows: rows.length > 0, recorded: real.length, recordedCost: compacting(real), P, shown, one, levels, base, max };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export type ContextVM = ReturnType<typeof buildContextVM>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { dayAdd, slice, type Filter, type Model } from "../model.ts";
|
|
2
|
+
import type { UrlState } from "../state.ts";
|
|
3
|
+
|
|
4
|
+
export const FILTER_KEYS = ["provider", "project", "model", "effort"] as const;
|
|
5
|
+
export type FilterKey = (typeof FILTER_KEYS)[number];
|
|
6
|
+
|
|
7
|
+
export function choices(M: Model, filter: Filter, key: FilterKey) {
|
|
8
|
+
const output = new Map<number, number>();
|
|
9
|
+
const facts = slice(M, { ...filter, [key]: -1 });
|
|
10
|
+
for (const fact of facts) {
|
|
11
|
+
const session = M.sessions[fact.s];
|
|
12
|
+
const id = key === "provider" ? session.pr ?? -1 : key === "project" ? session.p : key === "model" ? fact.m : fact.e;
|
|
13
|
+
if (id >= 0) output.set(id, (output.get(id) ?? 0) + fact.o);
|
|
14
|
+
}
|
|
15
|
+
return output;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function providerForModel(M: Model, model: number): string | undefined {
|
|
19
|
+
const providers = new Set(M.facts.filter(({ m }) => m === model).map(({ s }) => M.sessions[s].pr));
|
|
20
|
+
return providers.size === 1 ? M.providers[[...providers][0] ?? -1] : undefined;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function windowFor(M: Model, state: Pick<UrlState, "from" | "to" | "range">) {
|
|
24
|
+
return !state.range ? { from: state.from, to: state.to } : {
|
|
25
|
+
from: state.range === "all" ? M.first : dayAdd(M.today, 1 - Number(state.range)), to: M.today,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { behavior, costParts, mainLevel, totals, vsHigh, type Fact, type Model } from "../model.ts";
|
|
2
|
+
|
|
3
|
+
export function buildModelsVM(M: Model, F: Fact[]) {
|
|
4
|
+
const all = totals(M, F);
|
|
5
|
+
const per = M.models.map((n, m) => ({ n, m, tt: totals(M, F.filter((y) => y.m === m)) })).filter((r) => r.tt.q);
|
|
6
|
+
const rows = per.map((r) => ({ ...r, parts: costParts(r.tt.c, r.tt.k) }));
|
|
7
|
+
return { all, providerCosts: modelCostsByProvider(M, F), per: rows, behaviors: behavior(M, F), efforts: buildEfforts(M, F) };
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// A model can run on several providers. Keep each fact's cost with its actual provider.
|
|
11
|
+
function modelCostsByProvider(M: Model, F: Fact[]) {
|
|
12
|
+
const byProvider = new Map<number, Map<number, number>>();
|
|
13
|
+
for (const fact of F) {
|
|
14
|
+
const provider = M.sessions[fact.s].pr ?? 0;
|
|
15
|
+
let costs = byProvider.get(provider);
|
|
16
|
+
if (!costs) {
|
|
17
|
+
costs = new Map();
|
|
18
|
+
byProvider.set(provider, costs);
|
|
19
|
+
}
|
|
20
|
+
costs.set(fact.m, (costs.get(fact.m) ?? 0) + fact.c);
|
|
21
|
+
}
|
|
22
|
+
return [...byProvider].sort(([a], [b]) => a - b).map(([provider, costs]) => {
|
|
23
|
+
const models = Array.from(costs, ([model, cost]) => ({ model, cost })).sort((a, b) => b.cost - a.cost);
|
|
24
|
+
return { provider, models, cost: models.reduce((sum, row) => sum + row.cost, 0) };
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function buildEfforts(M: Model, F: Fact[]) {
|
|
29
|
+
const lv = M.levels.filter((e) => F.some((x) => x.e === e));
|
|
30
|
+
const total = (pick: (x: Fact) => number) => lv.map((e) => F.reduce((n, x) => n + (x.e === e ? pick(x) : 0), 0));
|
|
31
|
+
const share = (arr: number[]) => { const sum = arr.reduce((a, b) => a + b, 0) || 1; return arr.map((v) => v / sum); };
|
|
32
|
+
const q = total((x) => x.q), o = total((x) => x.o), th = total((x) => x.th), c = total((x) => x.c), sq = share(q), so = share(o), sth = share(th), sc = share(c);
|
|
33
|
+
let k = 0;
|
|
34
|
+
lv.forEach((_, i) => { if (Math.abs(sc[i] - sq[i]) > Math.abs(sc[k] - sq[k])) k = i; });
|
|
35
|
+
// Sessions whose main thread changed level; the Sessions table draws their levels.
|
|
36
|
+
const ss = [...new Set(F.filter((x) => !x.sub).map((x) => x.s))].map((s) => M.sessions[s]), sw = ss.filter((x) => x.runs.length > 1);
|
|
37
|
+
// Each session once, under the level its main thread ran most.
|
|
38
|
+
const n = lv.map((e) => ss.filter((x) => x.runs.length && mainLevel(x.runs) === e).length), sn = share(n);
|
|
39
|
+
// What effort controls: how much a request writes (thinking included) at each level, model by model, and against
|
|
40
|
+
// the same model's high within the sessions that ran both, since most sessions keep one level and the levels would
|
|
41
|
+
// otherwise compare different work. Cost per request follows the context more than the effort, so it stays in the tooltip.
|
|
42
|
+
const price = M.models.map((n, m) => {
|
|
43
|
+
const cells = lv.map((e) => { const x = F.filter((y) => y.m === m && y.e === e); return { e, q: x.reduce((a, y) => a + y.q, 0), o: x.reduce((a, y) => a + y.o, 0), th: x.reduce((a, y) => a + y.th, 0), c: x.reduce((a, y) => a + y.c, 0) }; });
|
|
44
|
+
return { n, m, cells: cells.map((r) => ({ ...r, vs: r.e !== 2 && r.q ? vsHigh(F, m, r.e, 2) : null })) };
|
|
45
|
+
}).filter((r) => r.cells.some((x) => x.q));
|
|
46
|
+
const allC = c.reduce((a, b) => a + b, 0) || 1;
|
|
47
|
+
return { lv, q, o, th, c, sq, so, sth, sc, k, ss, sw, n, sn, price, allC };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export type ModelsVM = ReturnType<typeof buildModelsVM>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { byDay, byDayKinds, dayAdd, group, mainLevel, sessionRows, slice, slotsOf, totals, type Fact, type Filter, type Model } from "../model.ts";
|
|
2
|
+
import type { UrlState } from "../state.ts";
|
|
3
|
+
|
|
4
|
+
export function buildOverviewVM(M: Model, F: Fact[], list: string[], filter: Filter, S: Pick<UrlState, "metric" | "split">, shown = M.projectRank.slice(0, 5)) {
|
|
5
|
+
const { metric } = S;
|
|
6
|
+
const now = totals(M, F), len = list.length, pf = dayAdd(filter.from, -len);
|
|
7
|
+
const prev = pf >= M.first ? totals(M, slice(M, filter, pf, dayAdd(filter.from, -1))) : null;
|
|
8
|
+
// What the cache saved follows how much work was done, so its line shows the share of cost spent reading the context instead.
|
|
9
|
+
const reread = (x: ReturnType<typeof totals>) => x.k[0] / (x.c || 1);
|
|
10
|
+
const daily = (pick: (x: Fact[]) => number) => list.map((d) => pick(F.filter((x) => x.d === d)));
|
|
11
|
+
// The chart splits by model, project (the five largest and the rest) or effort level, and cost also by what it paid for;
|
|
12
|
+
// web search and the part that cannot be split show only when present. Sessions count once, under their main model
|
|
13
|
+
// and main level, so the stack adds up to the sessions.
|
|
14
|
+
const split = (S.split === "kind" && metric !== "cost") || (S.split === "provider" && M.providers.length <= 1) ? "model" : S.split;
|
|
15
|
+
const slots = slotsOf(list), hourly = slots !== list, sess = metric === "sess";
|
|
16
|
+
const kindRows = split === "kind" ? byDayKinds(F, slots) : [];
|
|
17
|
+
const keep = [0, 1, 2, 3, 4].filter((j) => j < 3 || kindRows.some((r) => r[j]));
|
|
18
|
+
const lv = M.levels.filter((e) => F.some((x) => x.e === e));
|
|
19
|
+
const by = {
|
|
20
|
+
model: { groups: M.models.map((_, i) => i), key: (x: Fact) => (sess && M.sessions[x.s].parent >= 0 ? M.sessions[x.s].parent : x.m) },
|
|
21
|
+
provider: { groups: M.providers.map((_, i) => i), key: (x: Fact) => M.sessions[x.s].pr ?? 0 },
|
|
22
|
+
project: { groups: [...shown, -1], key: (x: Fact) => { const k = shown.indexOf(M.sessions[x.s].p); return k < 0 ? shown.length : k; } },
|
|
23
|
+
effort: { groups: lv, key: (x: Fact) => { const r = M.sessions[x.s].runs; return lv.indexOf(sess && r.length ? mainLevel(r) : x.e); } },
|
|
24
|
+
};
|
|
25
|
+
const groups = split === "kind" ? keep : by[split].groups;
|
|
26
|
+
const rows = split === "kind" ? kindRows.map((r) => keep.map((j) => r[j])) : byDay(F, slots, by[split].key, groups, metric);
|
|
27
|
+
const sums = groups.map((_, k) => rows.reduce((n, r) => n + r[k], 0));
|
|
28
|
+
const rowTotals = rows.map((row) => row.reduce((sum, value) => sum + value, 0));
|
|
29
|
+
const peak = Math.max(0, ...rowTotals);
|
|
30
|
+
const average = rowTotals.reduce((sum, value) => sum + value, 0) / (rowTotals.length || 1);
|
|
31
|
+
const activeCols = groups.flatMap((_, k) => sums[k] > 0 ? [k] : []);
|
|
32
|
+
const gp = group(F, (x) => M.sessions[x.s].p, metric);
|
|
33
|
+
const projects = [...gp].map(([p, v]) => ({ p, v })).sort((a, b) => b.v - a.v).slice(0, 6);
|
|
34
|
+
const top = sessionRows(M, F).sort((a, b) => (metric === "cost" ? b.c - a.c : b.o - a.o)).slice(0, 6);
|
|
35
|
+
const series = {
|
|
36
|
+
out: daily((x) => x.reduce((n, y) => n + y.o, 0)),
|
|
37
|
+
cost: daily((x) => x.reduce((n, y) => n + y.c, 0)),
|
|
38
|
+
sessions: daily((x) => new Set(x.map((y) => y.s)).size),
|
|
39
|
+
hit: daily((x) => totals(M, x).hit),
|
|
40
|
+
saved: daily((x) => x.reduce((n, y) => n + y.sv, 0)),
|
|
41
|
+
speed: daily((x) => totals(M, x).tps),
|
|
42
|
+
};
|
|
43
|
+
return { now, prev, rereadNow: reread(now), rereadPrev: prev ? reread(prev) || undefined : undefined, series, slots, hourly, split, groupIds: groups, rows, sums, rowTotals, peak, average, activeCols, projects, top };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export type OverviewVM = ReturnType<typeof buildOverviewVM>;
|