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
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
import { useDash } from "
|
|
2
|
-
import { mainLevel,
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { useDash } from "../../dash.ts";
|
|
2
|
+
import { mainLevel, type Fact, type SessionRow } from "../../model.ts";
|
|
3
|
+
import { buildSessionsVM } from "../../vm/sessions.ts";
|
|
4
|
+
import type { SortKey } from "../../state.ts";
|
|
5
|
+
import { Search } from "../../controls/Search.tsx";
|
|
6
|
+
import { CostCell, SessionMix, RunsStrip } from "../../ui.tsx";
|
|
7
|
+
import { ActiveSessionScope } from "../../sessionScope.tsx";
|
|
8
|
+
import { SessionLink } from "../SessionDetail.tsx";
|
|
6
9
|
|
|
7
10
|
export function Sessions({ F }: { F: Fact[] }) {
|
|
8
11
|
const { M, S, t, L, f, filter, set, limit, more } = useDash();
|
|
9
|
-
const
|
|
10
|
-
start: (r) => r.x.day + String(r.x.hour).padStart(2, "0") + String(r.x.min).padStart(2, "0"),
|
|
11
|
-
dur: (r) => r.x.dur, turns: (r) => r.x.owner, out: (r) => r.o, cost: (r) => r.c, ctx: (r) => r.ctx,
|
|
12
|
-
};
|
|
13
|
-
const q = S.q.trim().toLowerCase();
|
|
14
|
-
const rows = sessionRows(M, F).filter((r) => !q || (r.x.title + " " + M.projects[r.x.p] + " " + (M.providers[r.x.pr ?? 0] ?? "")).toLowerCase().includes(q));
|
|
15
|
-
const key = SORT[S.sort];
|
|
16
|
-
rows.sort((a, b) => (key(a) < key(b) ? -1 : key(a) > key(b) ? 1 : 0) * S.dir);
|
|
12
|
+
const { rows, total } = buildSessionsVM(M, F, S, limit, filter);
|
|
17
13
|
const sort = (k: SortKey) => set(S.sort === k ? { dir: S.dir === 1 ? -1 : 1 } : { sort: k, dir: -1 });
|
|
18
14
|
const th = (k: SortKey, label: string, cls = "") => (
|
|
19
15
|
<th className={cls} aria-sort={S.sort === k ? (S.dir > 0 ? "ascending" : "descending") : undefined}>
|
|
@@ -25,13 +21,14 @@ export function Sessions({ F }: { F: Fact[] }) {
|
|
|
25
21
|
return (
|
|
26
22
|
<section className="card">
|
|
27
23
|
<header><h2>{t("sessions")}</h2><Search value={S.q} placeholder={t("search")} clearLabel={t("clear")} onChange={(q) => set({ q }, { replace: true })} /></header>
|
|
28
|
-
<
|
|
24
|
+
<ActiveSessionScope />
|
|
25
|
+
<p className="hint" style={{ margin: "0 0 12px" }}>{f.int(rows.length)} / {f.int(total)} {t("shown")}</p>
|
|
29
26
|
<div className="scroll"><table className="wraphead sesstable">
|
|
30
27
|
<thead><tr>{th("start", t("session"))}{th("dur", t("dur"), "num o1")}{th("turns", t("turns"), "num o2")}<th className="o1">{t("modelEffort")}</th>{th("ctx", t("ctxPerReq"), "num o2")}{th("out", t("out"), "num")}{th("cost", t("cost"), "num")}</tr></thead>
|
|
31
|
-
<tbody>{
|
|
28
|
+
<tbody>{total ? rows.map((r) => (
|
|
32
29
|
<tr key={r.s}>
|
|
33
30
|
<td>
|
|
34
|
-
<
|
|
31
|
+
<SessionLink session={r.x} />
|
|
35
32
|
<span className="sub">{[M.providers.length > 1 ? M.providers[r.x.pr ?? 0] : "", M.projects[r.x.p], when(r), r.x.subs.length ? L.nSubs(r.x.subs.length) : "", r.lapses ? L.nLapses(r.lapses) : ""].filter(Boolean).map((p, k) => <span key={k}>{k ? " · " : ""}<span className="nw">{p}</span></span>)}</span>
|
|
36
33
|
</td>
|
|
37
34
|
<td className="num o1">{f.dur(r.x.dur)}</td>
|
|
@@ -48,7 +45,7 @@ export function Sessions({ F }: { F: Fact[] }) {
|
|
|
48
45
|
</tr>
|
|
49
46
|
)) : <tr><td colSpan={7} className="empty">{t("nodata")}</td></tr>}</tbody>
|
|
50
47
|
</table></div>
|
|
51
|
-
{
|
|
48
|
+
{total > limit ? <p style={{ margin: "14px 0 0" }}><button className="link" onClick={more}>{t("more")}</button></p> : null}
|
|
52
49
|
</section>
|
|
53
50
|
);
|
|
54
51
|
}
|
|
@@ -1,45 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { RelatedSessions } from "../../sessionScope.tsx";
|
|
2
|
+
import { useDash } from "../../dash.ts";
|
|
3
|
+
import { buildSubagentsVM } from "../../vm/subagents.ts";
|
|
4
|
+
import type { Fact } from "../../model.ts";
|
|
5
|
+
import { Empty, Legend, Mix, Stats, tip, type TipRow } from "../../ui.tsx";
|
|
4
6
|
|
|
5
7
|
// The subagent story: how much of each model's output subagents wrote, which models each parent model's subagents
|
|
6
8
|
// ran on, the subagent types, and the effort they ran at, which is often not the parent's.
|
|
7
9
|
export function Subagents({ F }: { F: Fact[] }) {
|
|
8
10
|
const { M, filter, t, L, f } = useDash();
|
|
9
|
-
const all =
|
|
10
|
-
const per = M.models.map((n, m) => {
|
|
11
|
-
const x = F.filter((y) => y.m === m), sub = x.reduce((a, y) => a + (y.sub ? y.o : 0), 0);
|
|
12
|
-
return { n, m, tt: totals(M, x), sub };
|
|
13
|
-
}).filter((r) => r.tt.q);
|
|
11
|
+
const { all, per, subs, routes, types, subOut, models, subLv, moved, subCost, lo, hi, ranked, subEff } = buildSubagentsVM(M, F, filter.model);
|
|
14
12
|
if (!per.length) return <section className="card"><Empty /></section>;
|
|
15
|
-
const
|
|
16
|
-
const routes = M.models.map((n, p) => ({ n, p, row: M.models.map((_, m) => subs.filter((a) => a.parent === p && a.m === m).length) })).filter((r) => r.row.some(Boolean));
|
|
17
|
-
const types = M.types.map((n, k) => {
|
|
18
|
-
const list = subs.filter((a) => a.type === k), mix = M.models.map(() => 0);
|
|
19
|
-
list.forEach((a) => mix[a.m]++);
|
|
20
|
-
return { n, count: list.length, mix, o: list.reduce((x, a) => x + a.o, 0) };
|
|
21
|
-
}).filter((r) => r.count).sort((a, b) => b.count - a.count);
|
|
22
|
-
const subOut = per.reduce((n, r) => n + r.sub, 0);
|
|
23
|
-
const subModelIdx = new Set(subs.flatMap((a) => [a.m, a.parent]).filter((m) => m >= 0));
|
|
24
|
-
const models = M.models.map((n, i) => ({ n, c: M.mColor(i) })).filter((_, i) => subModelIdx.has(i));
|
|
25
|
-
// Requests by effort level, per model the subagents ran on.
|
|
26
|
-
const SF = F.filter((x) => x.sub), subLv = M.levels.filter((e) => SF.some((x) => x.e === e));
|
|
27
|
-
// How often a subagent ran on another model than the one that spawned it, and what subagents cost.
|
|
28
|
-
const moved = subs.filter((a) => a.m !== a.parent).length, subCost = SF.reduce((n, x) => n + x.c, 0);
|
|
29
|
-
// Subagent requests against the level the session's main thread ran most; levels past max have no order.
|
|
30
|
-
let lo = 0, hi = 0, same = 0;
|
|
31
|
-
for (const x of SF) {
|
|
32
|
-
const r = M.sessions[x.s].runs, p = r.length ? mainLevel(r) : -1;
|
|
33
|
-
if (p < 0 || p > 4 || x.e > 4) continue;
|
|
34
|
-
if (x.e < p) lo += x.q; else if (x.e > p) hi += x.q; else same += x.q;
|
|
35
|
-
}
|
|
36
|
-
const ranked = lo + hi + same;
|
|
37
|
-
const subEff = M.models.map((n, m) => ({ n, m, c: subLv.map((e) => SF.reduce((a, x) => a + (x.m === m && x.e === e ? x.q : 0), 0)) })).filter((r) => r.c.some(Boolean));
|
|
13
|
+
const legend = models.map((m) => ({ n: M.models[m], c: M.mColor(m) }));
|
|
38
14
|
return (
|
|
39
15
|
<div className="stack">
|
|
40
16
|
<div className="grid half">
|
|
41
17
|
<section className="card">
|
|
42
|
-
<header><h2>{t("mainVsSub")}</h2><span className="hint">{t("out")}</span></header>
|
|
18
|
+
<header><h2>{t("mainVsSub")}</h2><RelatedSessions F={F} scope="subagent" /><span className="hint">{t("out")}</span></header>
|
|
43
19
|
<ul className="legend"><li><i className="c0" />{t("mainThread")}<b>{f.pct(1 - subOut / (all.o || 1))}</b></li><li><i className="csub" />{t("subs")}<b>{f.pct(subOut / (all.o || 1))}</b></li></ul>
|
|
44
20
|
<div className="rows total">{per.map((r) => {
|
|
45
21
|
const main = r.tt.o - r.sub, w = (v: number) => `${(v / (r.tt.o || 1)) * 100}%`;
|
|
@@ -59,7 +35,7 @@ export function Subagents({ F }: { F: Fact[] }) {
|
|
|
59
35
|
{ label: t("otherModel"), value: f.pct(moved / subs.length), meter: [moved / subs.length, "csub"], sub: t("ofSubagents") },
|
|
60
36
|
{ label: t("subCost"), value: f.pct(subCost / (all.c || 1)), meter: [subCost / (all.c || 1), "csub"], sub: L.ofAllCost(f.usd(subCost)) },
|
|
61
37
|
]} /> : null}
|
|
62
|
-
<Legend groups={
|
|
38
|
+
<Legend groups={legend} metric="sess" />
|
|
63
39
|
{routes.length ? <div className="rows">{routes.map((r) => {
|
|
64
40
|
const sum = r.row.reduce((a, b) => a + b, 0);
|
|
65
41
|
return [
|
|
@@ -71,7 +47,7 @@ export function Subagents({ F }: { F: Fact[] }) {
|
|
|
71
47
|
</div>
|
|
72
48
|
<div className="grid half">
|
|
73
49
|
<section className="card">
|
|
74
|
-
<header><h2>{t("subTypes")}</h2><Legend groups={
|
|
50
|
+
<header><h2>{t("subTypes")}</h2><Legend groups={legend} metric="sess" style={{ margin: 0 }} /></header>
|
|
75
51
|
{types.length ? <div className="scroll"><table>
|
|
76
52
|
<thead><tr><th>{t("subs")}</th><th className="num">{t("count")}</th><th>{t("ranOn")}</th><th className="num">{t("out")}</th></tr></thead>
|
|
77
53
|
<tbody>{types.map((r) => (
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import { RelatedSessions } from "../../sessionScope.tsx";
|
|
2
|
+
import "./activity-context.css";
|
|
3
|
+
import { useState, type ReactNode } from "react";
|
|
4
|
+
import { useDash } from "../../dash.ts";
|
|
5
|
+
import { type Fact } from "../../model.ts";
|
|
6
|
+
import { ACTIVITY_PREVIEW_SIZE as SHOWN, buildActivityVM, type ActivityVM } from "../../vm/activity.ts";
|
|
7
|
+
import { ChartSeg, Columns, Delta, Empty, HeatSeg, Info, Kpi, Stats, tip } from "../../ui.tsx";
|
|
8
|
+
|
|
9
|
+
// What the agent did: time on the model and on tools, owner turns, lines, compactions and agent time per owner turn
|
|
10
|
+
// against the window before; working time per day beside the hours of the week it fell in; lines per day; where the cache was rebuilt;
|
|
11
|
+
// tool calls with their failed part beside the skills used.
|
|
12
|
+
export function Activity({ F, list }: { F: Fact[]; list: string[] }) {
|
|
13
|
+
const { M, S, filter, t, f, set } = useDash();
|
|
14
|
+
const data = buildActivityVM(M, F, list, filter, S.heat);
|
|
15
|
+
const { w, p, slots, timeRows, lineRows, idle, series, perTurnNow, perTurnPrior } = data;
|
|
16
|
+
if (!w.ss.length) return <section className="card console-panel"><Empty /></section>;
|
|
17
|
+
|
|
18
|
+
const agent = w.api + w.tool;
|
|
19
|
+
const previousAgent = p ? p.api + p.tool : undefined;
|
|
20
|
+
const workTime = agent + w.idle;
|
|
21
|
+
const workParts = [
|
|
22
|
+
{ key: "api", value: w.api, color: "ac-work" },
|
|
23
|
+
{ key: "tool", value: w.tool, color: "ac-cost" },
|
|
24
|
+
{ key: "idle", value: w.idle, color: "ac-req" },
|
|
25
|
+
] as const;
|
|
26
|
+
const selectDay = typeof slots[0] === "string" ? (day: string | number) => {
|
|
27
|
+
if (typeof day === "string") set({ range: "", from: day, to: day });
|
|
28
|
+
} : undefined;
|
|
29
|
+
const hours = (h: number) => (h >= 1 ? `${f.dec(h)}h` : `${Math.round(h * 60)}m`);
|
|
30
|
+
const kpi = (label: string, value: ReactNode, a: number, b: number | undefined, series: number[]) => (
|
|
31
|
+
<Kpi label={label} value={value} d={<Delta a={a} b={p ? b : undefined} side="none" />} series={series} />
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<div className="console-view ac-view">
|
|
36
|
+
<div className="console-kpis ac-kpis">
|
|
37
|
+
{kpi(t("time"), f.dur(agent / 60), agent, previousAgent, series.api.map((value, index) => value + series.tool[index]))}
|
|
38
|
+
{kpi(`${t("lines")} · ${t("added")}`, `+${f.cmp(w.la)}`, w.la, p?.la, [])}
|
|
39
|
+
{kpi(`${t("lines")} · ${t("removed")}`, `−${f.cmp(w.lr)}`, w.lr, p?.lr, [])}
|
|
40
|
+
<Kpi label={t("failed")} value={f.pct(data.tools.errs / (data.tools.calls || 1))} d={f.int(data.tools.errs)} series={[]} />
|
|
41
|
+
<Kpi label={t("rebuilt")} value={f.int(data.rebuild.count)}
|
|
42
|
+
d={<>{f.usd(data.rebuild.r.idle.extra + data.rebuild.r.compaction.extra + data.rebuild.r.other.extra)} · {t("rbExtra")}</>} series={[]} />
|
|
43
|
+
</div>
|
|
44
|
+
<div className="console-grid ac-grid">
|
|
45
|
+
<section className="card console-panel">
|
|
46
|
+
<header><h2>{t("time")}</h2><div className="segs"><b className="num">{f.dur(workTime / 60)}</b><ChartSeg /></div></header>
|
|
47
|
+
{workTime > 0 ? <div className="ac-inline-bar" aria-hidden="true">
|
|
48
|
+
{workParts.map(({ key, value, color }) => <i key={key} className={color} style={{ flexGrow: value }} />)}
|
|
49
|
+
</div> : null}
|
|
50
|
+
<ul className="legend">{workParts.map(({ key, value, color }) => <li key={key}>
|
|
51
|
+
<i className={color} />{t(key)}<b>{f.dur(value / 60)} · {f.pct(value / (workTime || 1))}</b>
|
|
52
|
+
</li>)}</ul>
|
|
53
|
+
<Columns list={slots} rows={timeRows} groups={[{ n: t("api"), c: "ac-work" }, { n: t("tool"), c: "ac-cost" }]} metric="out" fmt={hours} onSlot={selectDay}
|
|
54
|
+
extra={(i) => (idle[i] ? [["ac-req", t("idle"), hours(idle[i])]] : [])} />
|
|
55
|
+
<Stats items={[
|
|
56
|
+
{ label: t("ownerTurns"), value: f.int(w.owner), sub: <Delta a={w.owner} b={p?.owner} side="none" /> },
|
|
57
|
+
{ label: t("compactions"), value: f.int(w.compact), sub: <Delta a={w.compact} b={p?.compact} side="none" /> },
|
|
58
|
+
{ label: t("perTurn"), value: f.dur(perTurnNow / 60), sub: <Delta a={perTurnNow} b={perTurnPrior} side="none" /> },
|
|
59
|
+
]} />
|
|
60
|
+
</section>
|
|
61
|
+
<section className="card console-panel"><header><h2>{t("hours")}</h2><HeatSeg /></header><Heatmap data={data.heat} F={F} /></section>
|
|
62
|
+
</div>
|
|
63
|
+
<div className="console-grid ac-grid">
|
|
64
|
+
<Tools data={data.tools} />
|
|
65
|
+
<Skills data={data.skills} />
|
|
66
|
+
</div>
|
|
67
|
+
<Rebuilds data={data.rebuild} sessionsLink={<RelatedSessions F={F} scope="rebuild" />} />
|
|
68
|
+
<section className="card console-panel">
|
|
69
|
+
<header><h2>{t("lines")}</h2><ChartSeg /></header>
|
|
70
|
+
<ul className="legend"><li><i className="ac-work" />{t("added")}<b>{f.cmp(w.la)}</b></li><li><i className="ac-req" />{t("removed")}<b>{f.cmp(w.lr)}</b></li></ul>
|
|
71
|
+
<Columns list={slots} rows={lineRows} groups={[{ n: t("added"), c: "ac-work" }, { n: t("removed"), c: "ac-req" }]} metric="out" fmt={(v) => f.cmp(v)} onSlot={selectDay} />
|
|
72
|
+
</section>
|
|
73
|
+
</div>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Tool calls, most used first, each with its failed part; the lead says how many failed and which tool most of them came
|
|
78
|
+
// from. Past SHOWN rows the rest opens below.
|
|
79
|
+
function Tools({ data }: { data: ActivityVM["tools"] }) {
|
|
80
|
+
const { t, L, f } = useDash();
|
|
81
|
+
const [all, setAll] = useState(false);
|
|
82
|
+
const { rows, calls, errs, tmax, worst } = data;
|
|
83
|
+
const shown = all ? rows : rows.slice(0, SHOWN);
|
|
84
|
+
return (
|
|
85
|
+
<section className="card console-panel">
|
|
86
|
+
<header><h2>{t("tools")}</h2><span className="hint">{f.int(calls)} {t("calls")} · {f.int(rows.length)} {t("toolCount")}</span></header>
|
|
87
|
+
{errs ? <Stats items={[
|
|
88
|
+
{ label: t("failed"), value: f.int(errs), tone: "err", sub: L.ofCalls(f.pct(errs / calls)) },
|
|
89
|
+
{ label: L.fromTool(worst[0]), value: f.pct(worst[1][1] / errs), meter: [worst[1][1] / errs, "ac-bad"], sub: t("ofFailures") },
|
|
90
|
+
]} /> : null}
|
|
91
|
+
{rows.length ? <div className="rank tools">{shown.map(([n, [c, e]]) => [
|
|
92
|
+
<span key={`n${n}`} className="n" title={n}>{n}</span>,
|
|
93
|
+
<span key={`t${n}`} className="t"><span className="b" style={{ width: `${(c / tmax) * 100}%` }} data-tip={tip(n, [["ac-work", t("calls"), f.int(c)], ["ac-bad", t("errors"), f.int(e)]])}>{e ? <i style={{ width: `max(2px, ${(e / c) * 100}%)` }} /> : null}</span></span>,
|
|
94
|
+
<span key={`v${n}`} className="val">{f.int(c)}<small className={e ? "err" : ""}>{f.pct(e / c)} {t("errors")}</small></span>,
|
|
95
|
+
])}</div> : <Empty />}
|
|
96
|
+
{rows.length ? <ul className="legend ac-status-legend">
|
|
97
|
+
<li><i className="ac-work" />{t("succeeded")}</li>
|
|
98
|
+
<li><i className="ac-bad" />{t("errors")}</li>
|
|
99
|
+
</ul> : null}
|
|
100
|
+
{rows.length > SHOWN ? <button type="button" className="disc more" aria-expanded={all} onClick={() => setAll(!all)}>
|
|
101
|
+
<svg viewBox="0 0 16 16" aria-hidden="true"><path d="M6 4l4 4-4 4" /></svg>{all ? t("showFewer") : `${t("seeAll")} (${rows.length})`}
|
|
102
|
+
</button> : null}
|
|
103
|
+
</section>
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
const SOURCE = { project: "srcProject", personal: "srcPersonal", plugin: "srcPlugin", builtin: "srcBuiltin", other: "srcOther" } as const;
|
|
107
|
+
|
|
108
|
+
// Skills retain source, command and agent counts, errors, sessions and most recent use.
|
|
109
|
+
function Skills({ data }: { data: ActivityVM["skills"] }) {
|
|
110
|
+
const { t, f } = useDash();
|
|
111
|
+
const [all, setAll] = useState(false);
|
|
112
|
+
const { rows, uses, preview } = data;
|
|
113
|
+
const shown = all ? rows : preview;
|
|
114
|
+
return (
|
|
115
|
+
<section className="card console-panel">
|
|
116
|
+
<header><h2>{t("skills")}</h2><span className="hint">{f.int(uses)} {t("uses")} · {f.int(rows.length)} {t("skillCount")}</span></header>
|
|
117
|
+
{rows.length ? <>
|
|
118
|
+
<div className="ac-table-wrap"><table className="console-table ac-table compact-metrics">
|
|
119
|
+
<thead><tr><th scope="col">{t("skills")}</th><th scope="col">{t("source")}</th>
|
|
120
|
+
<th scope="col" className="num">{t("skillTyped")}</th><th scope="col" className="num">{t("skillAgent")}</th>
|
|
121
|
+
<th scope="col" className="num">{t("errors")}</th><th scope="col" className="num">{t("sess")}</th><th scope="col">{t("lastUsed")}</th></tr></thead>
|
|
122
|
+
<tbody>{shown.map((r) => <tr key={r.name} data-tip={tip(r.name, [
|
|
123
|
+
["ac-work", t("skillTyped"), f.int(r.command)], ["ac-cost", t("skillAgent"), f.int(r.agent)],
|
|
124
|
+
["ac-bad", t("errors"), f.int(r.errors)], ["", t("sess"), f.int(r.sessions)],
|
|
125
|
+
])}>
|
|
126
|
+
<th scope="row" title={r.name}>{r.name}</th>
|
|
127
|
+
<td data-label={t("source")}>{t(SOURCE[r.source])}</td>
|
|
128
|
+
<td className="num" data-label={t("skillTyped")}>{f.int(r.command)}</td>
|
|
129
|
+
<td className="num" data-label={t("skillAgent")}>{f.int(r.agent)}</td>
|
|
130
|
+
<td className="num" data-label={t("errors")}>{f.int(r.errors)}</td>
|
|
131
|
+
<td className="num" data-label={t("sess")}>{f.int(r.sessions)}</td>
|
|
132
|
+
<td data-label={t("lastUsed")}>{r.last ? f.dshort(r.last) : "—"}</td>
|
|
133
|
+
</tr>)}</tbody>
|
|
134
|
+
</table></div>
|
|
135
|
+
{rows.length > SHOWN ? <button type="button" className="disc more" aria-expanded={all} onClick={() => setAll(!all)}>
|
|
136
|
+
<svg viewBox="0 0 16 16" aria-hidden="true"><path d="M6 4l4 4-4 4" /></svg>{all ? t("showFewer") : `${t("seeAll")} (${rows.length})`}
|
|
137
|
+
</button> : null}
|
|
138
|
+
</> : <Empty />}
|
|
139
|
+
</section>
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Where the prompt cache had to be written again: the four causes with their count, rewritten tokens and extra cost
|
|
144
|
+
// over reading it; beside it, the idle ones by the time since the previous request.
|
|
145
|
+
function Rebuilds({ data, sessionsLink }: { data: ActivityVM["rebuild"]; sessionsLink: ReactNode }) {
|
|
146
|
+
const { t, L, f } = useDash();
|
|
147
|
+
const { r, count, gmax } = data;
|
|
148
|
+
const rows = [["idle", t("rbIdle"), t("rbIdleTip")], ["compaction", t("rbCompaction"), t("rbCompactionTip")], ["other", t("rbOther"), t("rbOtherTip")], ["start", t("rbStart"), t("rbStartTip")]] as const;
|
|
149
|
+
const gaps = [t("gapShort"), t("gapMid"), t("gapLong")];
|
|
150
|
+
return (
|
|
151
|
+
<div className="console-grid ac-grid">
|
|
152
|
+
<section className="card console-panel">
|
|
153
|
+
<header>
|
|
154
|
+
<div className="ttl"><h2>{t("rebuilt")}</h2>{sessionsLink}<Info label={t("howToRead")}>
|
|
155
|
+
<p>{t("rbInfo")}</p>
|
|
156
|
+
<ul>{rows.map(([c, label, def]) => <li key={c}><b>{label}</b>: {def}</li>)}</ul>
|
|
157
|
+
</Info></div>
|
|
158
|
+
<span className="hint">{f.int(count)}</span>
|
|
159
|
+
</header>
|
|
160
|
+
{count ? <div className="ac-table-wrap"><table className="console-table ac-table">
|
|
161
|
+
<thead><tr><th /><th className="num">{t("count")}</th><th className="num">{t("rbTokens")}</th><th className="num">{t("rbExtra")}</th></tr></thead>
|
|
162
|
+
<tbody>{rows.map(([c, label]) => (
|
|
163
|
+
<tr key={c}>
|
|
164
|
+
<th scope="row" className="name">{label}</th>
|
|
165
|
+
<td className="num" data-label={t("count")}>{f.int(r[c].n)}</td>
|
|
166
|
+
<td className="num" data-label={t("rbTokens")}>{r[c].n ? f.cmp(r[c].tokens) : "—"}</td>
|
|
167
|
+
<td className="num" data-label={t("rbExtra")}>{c === "start" || !r[c].n ? "—" : f.usd(r[c].extra)}</td>
|
|
168
|
+
</tr>
|
|
169
|
+
))}</tbody>
|
|
170
|
+
</table></div> : <Empty />}
|
|
171
|
+
</section>
|
|
172
|
+
<section className="card console-panel">
|
|
173
|
+
<header><h2>{t("idleGap")}</h2><span className="hint">{t("rbIdle")}: {f.int(r.idle.n)}</span></header>
|
|
174
|
+
{r.idle.n ? <Stats items={[
|
|
175
|
+
{ label: t("perBreak"), value: f.usd(r.idle.extra / r.idle.n), sub: t("onAverage") },
|
|
176
|
+
{ label: t("overHour"), value: f.pct(r.gaps[2] / r.idle.n), meter: [r.gaps[2] / r.idle.n, "ac-work"], sub: t("ofRebuilds") },
|
|
177
|
+
]} /> : null}
|
|
178
|
+
{r.idle.n ? <div className="rank">{gaps.map((label, k) => [
|
|
179
|
+
<span key={`n${k}`} className="n">{label}</span>,
|
|
180
|
+
<span key={`t${k}`} className="t">{r.gaps[k] ? <span className="b ac-bad" style={{ width: `${(r.gaps[k] / gmax) * 100}%` }} /> : null}</span>,
|
|
181
|
+
<span key={`v${k}`} className="val">{f.int(r.gaps[k])}</span>,
|
|
182
|
+
])}</div> : <Empty />}
|
|
183
|
+
</section>
|
|
184
|
+
</div>
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function Heatmap({ data, F }: { data: ActivityVM["heat"]; F: Fact[] }) {
|
|
189
|
+
const { S, L, f, t } = useDash();
|
|
190
|
+
const { g, max, peak, all, weekend, night, mid, most } = data;
|
|
191
|
+
if (!max) return <Empty />;
|
|
192
|
+
const requestMode = S.heat === "req";
|
|
193
|
+
const metric = requestMode ? t("requests") : t("out");
|
|
194
|
+
const show = requestMode ? f.int : f.cmp;
|
|
195
|
+
const details = g.map((row) => row.map(() => ({ requests: 0, cost: 0, sessions: new Set<number>() })));
|
|
196
|
+
for (const fact of F) {
|
|
197
|
+
const weekday = (new Date(fact.d + "T00:00:00Z").getUTCDay() + 6) % 7;
|
|
198
|
+
const entry = details[weekday][fact.h];
|
|
199
|
+
entry.requests += fact.q;
|
|
200
|
+
entry.cost += fact.c;
|
|
201
|
+
entry.sessions.add(fact.s);
|
|
202
|
+
}
|
|
203
|
+
const step = Math.ceil(max / 4);
|
|
204
|
+
const hour = (h: number) => `${String(h % 24).padStart(2, "0")}:00`;
|
|
205
|
+
return <>
|
|
206
|
+
<div className="heat ac-heat">
|
|
207
|
+
{g.map((row, weekday) => [
|
|
208
|
+
<span key={`r${weekday}`} className="rl">{L.wd[weekday]}</span>,
|
|
209
|
+
...row.map((value, h) => {
|
|
210
|
+
const cell = details[weekday][h];
|
|
211
|
+
const label = `${L.wd[weekday]} · ${hour(h)}–${hour(h + 1)}`;
|
|
212
|
+
const rows: [string, string, string][] = [
|
|
213
|
+
["ac-req", t("requests"), f.int(cell.requests)],
|
|
214
|
+
["", t("sess"), f.int(cell.sessions.size)],
|
|
215
|
+
["ac-cost", t("cost"), f.usd(cell.cost)],
|
|
216
|
+
];
|
|
217
|
+
if (!requestMode) rows.unshift(["ac-work", metric, show(value)]);
|
|
218
|
+
return <span key={`${weekday}-${h}`} className={`ac-heat-cell ac-heat-${Math.ceil(value / step)}`}
|
|
219
|
+
tabIndex={cell.sessions.size ? 0 : undefined} data-tip={tip(label, rows)}
|
|
220
|
+
aria-label={`${label} · ${rows.map(([, key, val]) => `${key} ${val}`).join(" · ")}`} />;
|
|
221
|
+
}),
|
|
222
|
+
])}
|
|
223
|
+
<span />
|
|
224
|
+
{g[0].map((_, h) => <span key={h} className="cl">{h % 3 === 0 ? h : ""}</span>)}
|
|
225
|
+
</div>
|
|
226
|
+
<ul className="legend ac-heat-legend">
|
|
227
|
+
<li>{requestMode ? t("reqPerHour") : metric}</li>
|
|
228
|
+
<li><i className="ac-heat-0" />0</li>
|
|
229
|
+
{Array.from({ length: Math.ceil(max / step) }, (_, i) => {
|
|
230
|
+
const from = i * step + 1, to = Math.min(max, (i + 1) * step);
|
|
231
|
+
return <li key={i}><i className={`ac-heat-${i + 1}`} />{from === to ? show(from) : `${show(from)}–${show(to)}`}</li>;
|
|
232
|
+
})}
|
|
233
|
+
</ul>
|
|
234
|
+
<Stats items={[
|
|
235
|
+
{ label: t("peak"), value: `${L.wd[peak[0]]} · ${hour(peak[1])}`, sub: `${show(max)} ${metric.toLowerCase()}` },
|
|
236
|
+
{ label: t("weekend"), value: f.pct(weekend / all), meter: [weekend / all, "ac-work"], sub: metric.toLowerCase() },
|
|
237
|
+
{ label: "22:00–6:00", value: f.pct(night / all), meter: [night / all, "ac-work"], sub: metric.toLowerCase() },
|
|
238
|
+
{ label: t("sameHour"), value: f.int(mid), dots: [mid, most], sub: L.atMost(f.int(most)) },
|
|
239
|
+
]} />
|
|
240
|
+
</>;
|
|
241
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { Fmt } from "../../format.ts";
|
|
3
|
+
import type { Key } from "../../i18n.tsx";
|
|
4
|
+
import type { BootVM } from "../../vm/specialStates.ts";
|
|
5
|
+
import "./console-boot.css";
|
|
6
|
+
|
|
7
|
+
const commands = { first: "scan --first", rebuild: "scan --rebuild", update: "scan" };
|
|
8
|
+
const stepMarks = { done: "[✓]", active: "[▸]", pending: "[ ]" };
|
|
9
|
+
|
|
10
|
+
export function ConsoleBoot({ brand, vm, retry, t, f, title }: {
|
|
11
|
+
brand: ReactNode;
|
|
12
|
+
vm: BootVM;
|
|
13
|
+
retry: () => void;
|
|
14
|
+
t: (key: Key) => string;
|
|
15
|
+
f: Fmt;
|
|
16
|
+
title: string;
|
|
17
|
+
}) {
|
|
18
|
+
const { phase, reason, share, done, total, mb, mbTotal, status } = vm;
|
|
19
|
+
const failed = phase === "error";
|
|
20
|
+
const finding = phase === "loading" || phase === "find";
|
|
21
|
+
const activeStep = phase === "finish" ? 2 : phase === "read" ? 1 : 0;
|
|
22
|
+
const steps = [
|
|
23
|
+
{ label: t(finding ? "bootFind" : "bootStepFind"), value: total == null ? "" : `${f.int(total)} ${t("bootFiles")}` },
|
|
24
|
+
{ label: t("bootStepRead"), value: activeStep > 0 && done != null && total != null ? `${f.int(done)} / ${f.int(total)}` : "" },
|
|
25
|
+
{ label: t(phase === "finish" ? "bootFinish" : "bootStepTotal") },
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<main className="console-boot">
|
|
30
|
+
<div className="console-boot-inner">
|
|
31
|
+
{brand}
|
|
32
|
+
<div className="console-boot-panel" role={failed ? "alert" : "status"} aria-live={failed ? undefined : "off"}>
|
|
33
|
+
<p className="console-boot-command">
|
|
34
|
+
<strong aria-hidden="true">❯</strong> {commands[reason]}{!failed && <span className="console-boot-cursor" aria-hidden="true" />}
|
|
35
|
+
</p>
|
|
36
|
+
<h1 aria-live={failed ? undefined : "polite"}>{title}</h1>
|
|
37
|
+
{failed ? <>
|
|
38
|
+
<div className="console-boot-row console-boot-error-row">
|
|
39
|
+
<strong aria-hidden="true">[✗]</strong><span>{t("bootLoadData")}</span>
|
|
40
|
+
{status && <span>HTTP {status}</span>}
|
|
41
|
+
</div>
|
|
42
|
+
<p className="console-boot-help">{t("loadFailHelp")}</p>
|
|
43
|
+
<div className="console-boot-actions">
|
|
44
|
+
<button type="button" className="console-boot-retry" onClick={retry} aria-keyshortcuts="R">{t("retry")}</button>
|
|
45
|
+
<span aria-hidden="true"><kbd>R</kbd> {t("retry")}</span>
|
|
46
|
+
</div>
|
|
47
|
+
</> : <>
|
|
48
|
+
<ol className="console-boot-steps">
|
|
49
|
+
{steps.map(({ label, value }, index) => {
|
|
50
|
+
const state = index < activeStep ? "done" : index === activeStep ? "active" : "pending";
|
|
51
|
+
return <li key={index} className="console-boot-row" data-state={state} aria-current={state === "active" ? "step" : undefined}>
|
|
52
|
+
<strong aria-hidden="true">{stepMarks[state]}</strong><span>{label}</span><span>{value}</span>
|
|
53
|
+
</li>;
|
|
54
|
+
})}
|
|
55
|
+
</ol>
|
|
56
|
+
<div className="console-boot-meter">
|
|
57
|
+
<span aria-hidden="true">[</span>
|
|
58
|
+
<div className="console-boot-track" role="progressbar" aria-label={title}
|
|
59
|
+
aria-valuenow={share === null ? undefined : Math.round(share * 100)}>
|
|
60
|
+
<span className="console-boot-fill" style={share === null ? undefined : { width: `${share * 100}%` }} />
|
|
61
|
+
</div>
|
|
62
|
+
<span aria-hidden="true">]</span>
|
|
63
|
+
<strong aria-hidden="true">{share === null ? "…" : f.pct(share)}</strong>
|
|
64
|
+
</div>
|
|
65
|
+
{phase === "read" && mb != null && mbTotal != null && (
|
|
66
|
+
<p className="console-boot-bytes">{f.int(mb)} MB / {f.int(mbTotal)} MB</p>
|
|
67
|
+
)}
|
|
68
|
+
</>}
|
|
69
|
+
</div>
|
|
70
|
+
</div>
|
|
71
|
+
</main>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import "./activity-context.css";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { RelatedSessions } from "../../sessionScope.tsx";
|
|
4
|
+
import { ReplayNotes } from "../Breakdown.tsx";
|
|
5
|
+
import { useDash } from "../../dash.ts";
|
|
6
|
+
import { type Fact } from "../../model.ts";
|
|
7
|
+
import { buildContextVM, round5, TAIL, type ContextVM, type ReplayScope } from "../../vm/context.ts";
|
|
8
|
+
import { Delta, Empty, Kpi, Stats, tip, type TipRow } from "../../ui.tsx";
|
|
9
|
+
|
|
10
|
+
// Whether the auto-compact window suits the sessions: how compactions went, what reading the context cost by its size, and
|
|
11
|
+
// the same requests replayed with compaction at other points.
|
|
12
|
+
|
|
13
|
+
export function Context({ F, list }: { F: Fact[]; list: string[] }) {
|
|
14
|
+
return F.length ? <ContextContent F={F} list={list} /> : <section className="card console-panel"><Empty /></section>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function ContextContent({ F, list }: { F: Fact[]; list: string[] }) {
|
|
18
|
+
const { M, filter, t, L, f } = useDash();
|
|
19
|
+
const [scope, setScope] = useState<ReplayScope>("all");
|
|
20
|
+
const data = buildContextVM(M, F, list, filter, scope);
|
|
21
|
+
const { total, current, prior, series } = data;
|
|
22
|
+
return (
|
|
23
|
+
<div className="console-view ac-view ctx">
|
|
24
|
+
<div className="console-kpis ac-kpis">
|
|
25
|
+
<Kpi label={t("compactions")} value={f.int(current.count)} d={<Delta a={current.count} b={prior.count} side="none" />} series={series.count} />
|
|
26
|
+
<Kpi label={t("compacting")} value={<>{f.usd(current.compacting)} <small>{L.ofCost(f.pct(total ? current.compacting / total : 0))}</small></>}
|
|
27
|
+
d={<Delta a={current.compacting} b={prior.compacting} side="none" />} series={series.compacting} />
|
|
28
|
+
<Kpi label={t("readingCtx")} value={<>{f.usd(current.reading)} <small>{L.ofCost(f.pct(total ? current.reading / total : 0))}</small></>}
|
|
29
|
+
d={<Delta a={current.reading} b={prior.reading} side="none" />} series={series.reading} />
|
|
30
|
+
<Kpi label={t("ctxPerReq")} value={data.reading.reqs ? f.cmp(data.reading.ctx) : "—"} d={t("onAverage")} series={[]} />
|
|
31
|
+
<Kpi label={t("eachCosts")} value={data.compactions.count ? f.usd(data.compactions.sum + data.compactions.rb) : "—"}
|
|
32
|
+
d={data.compactions.count ? L.eachSplit(f.usd(data.compactions.sum), f.usd(data.compactions.rb)).join(" · ") : null} series={[]} />
|
|
33
|
+
</div>
|
|
34
|
+
<RelatedSessions F={F} scope="compaction" />
|
|
35
|
+
<div className="console-grid ac-grid">
|
|
36
|
+
<Compactions data={data.compactions} />
|
|
37
|
+
<Intervals data={data.compactions} />
|
|
38
|
+
</div>
|
|
39
|
+
<Reading data={data.reading} />
|
|
40
|
+
<Replay data={data.replay} scope={scope} setScope={setScope} />
|
|
41
|
+
</div>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// How compactions went: what each kept and left to work with, the wait, what one cost, the sessions that ended right after
|
|
46
|
+
// one, and the stretch from each to the next by its order in the session.
|
|
47
|
+
function Compactions({ data }: { data: ContextVM["compactions"] }) {
|
|
48
|
+
const { t, L, f } = useDash();
|
|
49
|
+
const { parts: counts, fire, kept, wait, totalWait, sum, rb, soon } = data;
|
|
50
|
+
const parts = [[counts[0], L.nAuto], [counts[1], L.nManual], [counts[2], L.nInSubs]] as const;
|
|
51
|
+
const head = <header><h2>{t("compactions")}</h2><span className="hint">{parts.filter(([n]) => n).map(([n, l]) => l(f.int(n))).join(" · ")}</span></header>;
|
|
52
|
+
if (!data.count) return <section className="card console-panel">{head}<Empty /></section>;
|
|
53
|
+
return (
|
|
54
|
+
<section className="card console-panel">
|
|
55
|
+
{head}
|
|
56
|
+
{fire && kept && kept < fire ? <>
|
|
57
|
+
<ul className="legend"><li><i className="ac-req" />{t("keptAfter")}<b>{f.cmp(kept)}</b></li><li><i className="ac-work" />{t("roomToWork")}<b>{f.cmp(fire - kept)}</b></li></ul>
|
|
58
|
+
<div className="gauge">
|
|
59
|
+
<div className="track"><i className="ac-req" style={{ width: `${(kept / fire) * 100}%` }} /><i className="ac-work" style={{ flex: 1 }} /></div>
|
|
60
|
+
<div className="ticks"><span style={{ left: 0 }}>0</span><span style={{ left: `${(kept / fire) * 100}%` }}>{f.cmp(kept)}</span><span style={{ left: "100%" }}>{L.compactsAt(f.cmp(fire))}</span></div>
|
|
61
|
+
</div>
|
|
62
|
+
</> : null}
|
|
63
|
+
<Stats items={[
|
|
64
|
+
{ label: t("wait"), value: wait !== null ? `${Math.round(wait / 1000)} s` : "—", sub: wait !== null ? L.inAll(f.dur(totalWait / 60000)) : undefined },
|
|
65
|
+
{ label: t("eachCosts"), value: f.usd(sum + rb), sub: L.eachSplit(f.usd(sum), f.usd(rb)).map((s) => <span key={s} className="line">{s}</span>) },
|
|
66
|
+
{ label: t("endedSoon"), value: f.int(soon), sub: L.endedWithin(TAIL) },
|
|
67
|
+
]} />
|
|
68
|
+
</section>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function Intervals({ data }: { data: ContextVM["compactions"] }) {
|
|
73
|
+
const { t, L, f } = useDash();
|
|
74
|
+
return <section className="card console-panel">
|
|
75
|
+
<header><h2>{t("inSession")}</h2></header>
|
|
76
|
+
{data.mainCount ? <div className="ac-table-wrap"><table className="console-table ac-table">
|
|
77
|
+
<thead><tr><th scope="col">{t("inSession")}</th><th scope="col" className="num">{t("compactions")}</th>
|
|
78
|
+
<th scope="col" className="num">{t("keptCol")}</th><th scope="col" className="num">{t("reqsToNext")}</th>
|
|
79
|
+
<th scope="col" className="num">{t("turnsToNext")}</th></tr></thead>
|
|
80
|
+
<tbody>{data.intervals.map((g, k) => g.count ? <tr key={k}>
|
|
81
|
+
<th className="name" scope="row">{L.nth[k]}</th>
|
|
82
|
+
<td className="num" data-label={t("compactions")}>{f.int(g.count)}</td>
|
|
83
|
+
<td className="num" data-label={t("keptCol")}>{cell(g.kept, f.cmp)}</td>
|
|
84
|
+
<td className="num" data-label={t("reqsToNext")}>{cell(g.next, f.int)}</td>
|
|
85
|
+
<td className="num" data-label={t("turnsToNext")}>{cell(g.turns, f.int)}</td>
|
|
86
|
+
</tr> : null)}</tbody>
|
|
87
|
+
</table></div> : <Empty />}
|
|
88
|
+
</section>;
|
|
89
|
+
}
|
|
90
|
+
const cell = (v: number | null, fmt: (n: number) => string) => (v === null ? "—" : fmt(v));
|
|
91
|
+
|
|
92
|
+
// The cost of reading the context by the context each request carried: rows add up to the overview's cost of reading the
|
|
93
|
+
// context, a part the host charged with no request included.
|
|
94
|
+
function Reading({ data }: { data: ContextVM["reading"] }) {
|
|
95
|
+
const { t, L, f } = useDash();
|
|
96
|
+
const { E, n, b, q, cost, reqs, above, aboveQ, per, top, base, ctx } = data;
|
|
97
|
+
const head = <header><h2>{t("readingCtx")}</h2><span className="hint">{t("byCtx")}</span></header>;
|
|
98
|
+
if (!reqs) return <section className="card console-panel">{head}<Empty /></section>;
|
|
99
|
+
const k = (v: number) => f.cmp(v).replace(/K$/, "");
|
|
100
|
+
const label = (j: number) => (j === 0 ? L.under(f.cmp(E[0])) : j === n - 1 ? L.andOver(f.cmp(E[n - 2])) : `${f.cmp(E[j - 1]).endsWith("K") && f.cmp(E[j]).endsWith("K") ? k(E[j - 1]) : f.cmp(E[j - 1])}–${f.cmp(E[j])}`);
|
|
101
|
+
return (
|
|
102
|
+
<section className="card console-panel">
|
|
103
|
+
{head}
|
|
104
|
+
<Stats items={[
|
|
105
|
+
{ label: t("ctxPerReq"), value: f.cmp(ctx), sub: t("onAverage") },
|
|
106
|
+
{ label: L.above(f.cmp(300e3)), value: f.pct(cost ? above / cost : 0), sub: L.ofCostReqs(f.pct(aboveQ / reqs)) },
|
|
107
|
+
...(top >= 0 && base >= 0 && top !== base && per[base] ? [{ label: L.perReqAt(label(top)), value: f.times(per[top] / per[base]), sub: L.whatAt(label(base)) }] : []),
|
|
108
|
+
]} />
|
|
109
|
+
<div className="ac-reading">
|
|
110
|
+
{q.map((requests, j) => requests ? <div key={j} className="ac-reading-row">
|
|
111
|
+
<b>{label(j)}</b>
|
|
112
|
+
<div className="ac-reading-meter"><div className="ac-inline-bar"><i className="ac-req" style={{ width: percent(requests, reqs) }} /></div>
|
|
113
|
+
<span className="num">{f.int(requests)} · {f.pct(requests / reqs)}</span></div>
|
|
114
|
+
<div className="ac-reading-meter"><div className="ac-inline-bar"><i className="ac-cost" style={{ width: percent(b[j], cost) }} /></div>
|
|
115
|
+
<span className="num">{f.usd(b[j])} · {f.pct(b[j] / (cost || 1))}</span></div>
|
|
116
|
+
<span className="num" title={t("perReqCol")}>{f.usd3(per[j])}</span>
|
|
117
|
+
</div> : null)}
|
|
118
|
+
{b[n] >= cost * 0.005 ? <div className="ac-reading-total"><span>{t("noRequest")}</span><strong className="num">{f.usd(b[n])}</strong></div> : null}
|
|
119
|
+
<div className="ac-reading-total"><b>{t("all")}</b><span className="num">{f.int(reqs)} · {f.usd(cost)} · {f.usd3(cost / reqs)} {t("perReqCol")}</span></div>
|
|
120
|
+
</div>
|
|
121
|
+
<ul className="legend"><li><i className="ac-req" />{t("requests")}</li><li><i className="ac-cost" />{t("cost")}</li></ul>
|
|
122
|
+
</section>
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// The main threads replayed with compaction at each point, against the point it fires at now. A point within NEAR of now
|
|
127
|
+
// gives way to it; when the models in the filter fire at different points now, now has a row of its own.
|
|
128
|
+
const percent = (value: number, total: number) => `${value / (total || 1) * 100}%`;
|
|
129
|
+
|
|
130
|
+
function Replay({ data, scope, setScope }: { data: ContextVM["replay"]; scope: ReplayScope; setScope: (scope: ReplayScope) => void }) {
|
|
131
|
+
const { t, f } = useDash();
|
|
132
|
+
const { hasRows, recorded, recordedCost, P, shown, one, levels, base, max } = data;
|
|
133
|
+
const kinds: [string, string][] = [["ac-cost", t("readingCtx")], ["ac-work", t("compacting")], ["ac-bad", t("rebuildIdle")]];
|
|
134
|
+
const name = (x: (typeof shown)[number]) => (x.now ? (one ? f.cmp(round5(one)) : levels.map((v) => f.cmp(round5(v))).join(" · ")) : f.cmp(x.at));
|
|
135
|
+
return (
|
|
136
|
+
<section className="card console-panel">
|
|
137
|
+
<header>
|
|
138
|
+
<h2>{t("otherPoints")}</h2>
|
|
139
|
+
<div className="segs"><div className="seg" role="group">{(["all", "long"] as const).map((k) => <button key={k} aria-pressed={scope === k} onClick={() => setScope(k)}>{t(k === "all" ? "allSessions" : "long4")}</button>)}</div></div>
|
|
140
|
+
</header>
|
|
141
|
+
{hasRows ? <>
|
|
142
|
+
<ReplayNotes count={recorded} cost={recordedCost} />
|
|
143
|
+
<ul className="legend">{kinds.map(([c, n]) => <li key={c}><i className={c} />{n}</li>)}</ul>
|
|
144
|
+
<div className="ac-table-wrap"><table className="console-table ac-table">
|
|
145
|
+
<thead><tr><th>{t("compactsAtCol")}</th><th className="num">{t("compactions")}</th><th className="num">{t("sessCompacted")}</th>{kinds.slice(0, 2).map(([c, n]) => <th key={c} className="num">{n}</th>)}<th /><th className="num">{t("estimatedCost")}</th>{base ? <th className="num">{t("againstNow")}</th> : null}</tr></thead>
|
|
146
|
+
<tbody>{shown.map((x) => {
|
|
147
|
+
const d = base ? x.total - base.total : 0;
|
|
148
|
+
const rowsTip: TipRow[] = kinds.map(([c, n], k) => [c, n, f.usd(x.parts[k])]);
|
|
149
|
+
return <tr key={`${x.j}`} className={x.now ? "now" : ""} data-tip={tip(`${t("compactsAtCol")} ${name(x)}`, rowsTip)}>
|
|
150
|
+
<th scope="row" className="lbl">{name(x)}{x.now ? <span className="chip">{t("now")}</span> : null}{!x.now && x.at === P.at(-1) ? <span className="sub">{t("byDefault")}</span> : null}</th>
|
|
151
|
+
<td className="num" data-label={t("compactions")}>{f.int(x.n)}</td><td className="num" data-label={t("sessCompacted")}>{f.int(x.sess)}</td>
|
|
152
|
+
{kinds.slice(0, 2).map(([c, n], k) => <td key={c} className="num" data-label={n}>{f.usd(x.parts[k])}</td>)}
|
|
153
|
+
<td className="ac-bar-cell" data-label={t("cost")}><div className="ac-inline-bar" style={{ width: `${(x.total / max) * 100}%` }}>{x.parts.map((v, k) => <i key={k} className={kinds[k][0]} style={{ flex: v }} />)}</div></td>
|
|
154
|
+
<td className="num" data-label={t("estimatedCost")}>{f.usd(x.total)}</td>
|
|
155
|
+
{base ? <td className="num" data-label={t("againstNow")}>{x.now ? "—" : <span className={d < 0 ? "better" : d > 0 ? "worse" : ""}>{d < 0 ? "−" : "+"}{f.usd(Math.abs(d))}</span>}</td> : null}
|
|
156
|
+
</tr>;
|
|
157
|
+
})}</tbody>
|
|
158
|
+
</table></div>
|
|
159
|
+
</> : <Empty />}
|
|
160
|
+
</section>
|
|
161
|
+
);
|
|
162
|
+
}
|