llmtop 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +114 -2
- package/bin/llmtop.mjs +101 -0
- package/dashboard/dist/apple-touch-icon.png +0 -0
- package/dashboard/dist/assets/index-BVbAwMVB.js +9 -0
- package/dashboard/dist/assets/index-Cp7Swcz5.css +1 -0
- package/dashboard/dist/assets/llmtop-lockup-DtFPJmhv.svg +1 -0
- package/dashboard/dist/assets/llmtop-lockup-reversed-D9OmQIVU.svg +1 -0
- package/dashboard/dist/favicon.ico +0 -0
- package/dashboard/dist/favicon.svg +1 -0
- package/dashboard/dist/index.html +19 -0
- package/dashboard/dist/llmtop-mark-192.png +0 -0
- package/dashboard/dist/llmtop-mark-512.png +0 -0
- package/dashboard/dist/site.webmanifest +11 -0
- package/dashboard/src/App.tsx +213 -0
- package/dashboard/src/controls/DateRange.tsx +108 -0
- package/dashboard/src/controls/Disclosure.tsx +15 -0
- package/dashboard/src/controls/Search.tsx +18 -0
- package/dashboard/src/controls/Select.tsx +48 -0
- package/dashboard/src/controls/popover.tsx +31 -0
- package/dashboard/src/dash.ts +23 -0
- package/dashboard/src/extra.test.ts +9 -0
- package/dashboard/src/extra.ts +16 -0
- package/dashboard/src/format.ts +29 -0
- package/dashboard/src/i18n.tsx +52 -0
- package/dashboard/src/index.ts +7 -0
- package/dashboard/src/main.tsx +7 -0
- package/dashboard/src/model.test.ts +110 -0
- package/dashboard/src/model.ts +255 -0
- package/dashboard/src/state.test.ts +48 -0
- package/dashboard/src/state.ts +61 -0
- package/dashboard/src/styles.css +401 -0
- package/dashboard/src/tip.ts +51 -0
- package/dashboard/src/treemap.test.ts +23 -0
- package/dashboard/src/treemap.ts +30 -0
- package/dashboard/src/ui.tsx +327 -0
- package/dashboard/src/views/Activity.tsx +177 -0
- package/dashboard/src/views/Context.tsx +183 -0
- package/dashboard/src/views/Models.tsx +155 -0
- package/dashboard/src/views/Overview.tsx +83 -0
- package/dashboard/src/views/Projects.tsx +116 -0
- package/dashboard/src/views/Sessions.tsx +54 -0
- package/dashboard/src/views/Subagents.tsx +102 -0
- package/docs/brand/README.md +91 -0
- package/docs/brand/brand.json +67 -0
- package/docs/brand/favicon.ico +0 -0
- package/docs/brand/png/apple-touch-icon.png +0 -0
- package/docs/brand/png/favicon-16.png +0 -0
- package/docs/brand/png/favicon-32.png +0 -0
- package/docs/brand/png/favicon-48.png +0 -0
- package/docs/brand/png/llmtop-lockup-reversed@2x.png +0 -0
- package/docs/brand/png/llmtop-lockup@2x.png +0 -0
- package/docs/brand/png/llmtop-mark-1024.png +0 -0
- package/docs/brand/png/llmtop-mark-192.png +0 -0
- package/docs/brand/png/llmtop-mark-512.png +0 -0
- package/docs/brand/png/llmtop-wordmark@2x.png +0 -0
- package/docs/brand/source/build_brand.py +173 -0
- package/docs/brand/svg/favicon.svg +1 -0
- package/docs/brand/svg/llmtop-glyph.svg +1 -0
- package/docs/brand/svg/llmtop-lockup-reversed.svg +1 -0
- package/docs/brand/svg/llmtop-lockup.svg +1 -0
- package/docs/brand/svg/llmtop-mark-light.svg +1 -0
- package/docs/brand/svg/llmtop-mark.svg +1 -0
- package/docs/brand/svg/llmtop-wordmark-reversed.svg +1 -0
- package/docs/brand/svg/llmtop-wordmark.svg +1 -0
- package/llmtop.config.example.json +10 -0
- package/package.json +73 -4
- package/prices.md +27 -0
- package/src/api.mjs +53 -0
- package/src/archive.mjs +142 -0
- package/src/config.mjs +55 -0
- package/src/context.mjs +151 -0
- package/src/dashboard.mjs +61 -0
- package/src/db.mjs +102 -0
- package/src/derive.mjs +346 -0
- package/src/effort.mjs +18 -0
- package/src/format.mjs +19 -0
- package/src/paths.mjs +82 -0
- package/src/prices-command.mjs +25 -0
- package/src/prices.mjs +146 -0
- package/src/providers/agy.mjs +438 -0
- package/src/providers/claude.mjs +274 -0
- package/src/providers/codex.mjs +589 -0
- package/src/providers/index.mjs +25 -0
- package/src/rebuilds.mjs +85 -0
- package/src/scan.mjs +214 -0
- package/src/serve.mjs +44 -0
- package/src/show.mjs +20 -0
- package/src/usage-command.mjs +110 -0
- package/src/usage.mjs +388 -0
- package/src/zone.mjs +15 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// What every view reads: the data, the address-bar state resolved against it, and the language's helpers.
|
|
2
|
+
import { createContext, useContext } from "react";
|
|
3
|
+
import type { Fmt } from "./format.ts";
|
|
4
|
+
import type { Key, Lang, T } from "./i18n.tsx";
|
|
5
|
+
import type { Filter, Model } from "./model.ts";
|
|
6
|
+
import type { UrlState } from "./state.ts";
|
|
7
|
+
|
|
8
|
+
export type Dash = {
|
|
9
|
+
M: Model;
|
|
10
|
+
S: UrlState;
|
|
11
|
+
filter: Filter; // the window and the filters as indices into M
|
|
12
|
+
lang: Lang;
|
|
13
|
+
L: (typeof T)[Lang]; // every string, for the ones that are functions or lists
|
|
14
|
+
t: (k: Key) => string;
|
|
15
|
+
f: Fmt;
|
|
16
|
+
limit: number; // rows shown in the long session tables
|
|
17
|
+
more: () => void;
|
|
18
|
+
// Changes the address-bar state; replace keeps one history entry while typing.
|
|
19
|
+
set: (patch: Partial<UrlState>, opts?: { replace?: boolean }) => void;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const DashContext = createContext<Dash | null>(null);
|
|
23
|
+
export const useDash = () => useContext(DashContext)!;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { test } from "node:test";
|
|
3
|
+
import { labelOf } from "./extra.ts";
|
|
4
|
+
|
|
5
|
+
test("a label is a string or a function of the page language", () => {
|
|
6
|
+
assert.equal(labelOf("Notes", "vi"), "Notes");
|
|
7
|
+
const label = (lang: "vi" | "en") => (lang === "vi" ? "Ghi chú" : "Notes");
|
|
8
|
+
assert.deepEqual([labelOf(label, "vi"), labelOf(label, "en")], ["Ghi chú", "Notes"]);
|
|
9
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// What a host package adds to the dashboard: a second navigation section with views of its own.
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
import type { Lang } from "./i18n.tsx";
|
|
4
|
+
|
|
5
|
+
// A label is one string, or a function of the page language when the host translates it.
|
|
6
|
+
export type Label = string | ((lang: Lang) => string);
|
|
7
|
+
export const labelOf = (label: Label, lang: Lang) => (typeof label === "function" ? label(lang) : label);
|
|
8
|
+
|
|
9
|
+
export type ExtraView = {
|
|
10
|
+
id: string; // the view's path: /<id>
|
|
11
|
+
label: Label;
|
|
12
|
+
icon: string; // SVG markup for a 24x24 viewBox, like the built-in icons
|
|
13
|
+
render: () => ReactNode; // rendered inside the shared context (useDash)
|
|
14
|
+
filters?: false; // hides the date and filter row for this view
|
|
15
|
+
};
|
|
16
|
+
export type Extra = { label: Label; views: ExtraView[] };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Number, money, date and duration formats for the page's language.
|
|
2
|
+
import type { Metric, Session } from "./model.ts";
|
|
3
|
+
|
|
4
|
+
export type Fmt = ReturnType<typeof makeFmt>;
|
|
5
|
+
|
|
6
|
+
export function makeFmt(lang: "vi" | "en") {
|
|
7
|
+
const loc = lang === "vi" ? "vi-VN" : "en-GB";
|
|
8
|
+
const cmp = (n: number) => {
|
|
9
|
+
const [d, u] = n >= 1e9 ? [1e9, "B"] : n >= 1e6 ? [1e6, "M"] : n >= 1e3 ? [1e3, "K"] : [1, ""], v = n / (d as number);
|
|
10
|
+
return new Intl.NumberFormat(loc, { maximumFractionDigits: !u || v >= 100 ? 0 : v >= 10 ? 1 : 2 }).format(v) + u;
|
|
11
|
+
};
|
|
12
|
+
const int = (n: number) => new Intl.NumberFormat(loc).format(Math.round(n));
|
|
13
|
+
const usd = (n: number) => { const d = n >= 100 || Number.isInteger(n) ? 0 : 2; return "$" + new Intl.NumberFormat(loc, { maximumFractionDigits: d, minimumFractionDigits: d }).format(n); };
|
|
14
|
+
const pct = (n: number) => new Intl.NumberFormat(loc, { style: "percent", maximumFractionDigits: n > 0 && n < 0.1 ? 1 : 0 }).format(n);
|
|
15
|
+
const dshort = (d: string) => new Intl.DateTimeFormat(loc, { day: "numeric", month: "short", timeZone: "UTC" }).format(new Date(d + "T00:00:00Z"));
|
|
16
|
+
return {
|
|
17
|
+
locale: loc, cmp, int, usd, pct, dshort,
|
|
18
|
+
month: (d: string) => new Intl.DateTimeFormat(loc, { month: "short", timeZone: "UTC" }).format(new Date(d + "T00:00:00Z")),
|
|
19
|
+
// Minutes rounded first, so 59.6 reads 1h 00m, not 0h 60m or 60m.
|
|
20
|
+
dur: (m: number) => { const r = Math.round(m); return r >= 60 ? Math.floor(r / 60) + "h " + String(r % 60).padStart(2, "0") + "m" : r + "m"; },
|
|
21
|
+
fmt: (metric: Metric, v: number) => (metric === "cost" ? usd(v) : metric === "sess" ? int(v) : cmp(v)),
|
|
22
|
+
usd3: (n: number) => "$" + new Intl.NumberFormat(loc, { minimumFractionDigits: n < 1 ? 3 : 2, maximumFractionDigits: n < 1 ? 3 : 2 }).format(n),
|
|
23
|
+
dec: (n: number) => new Intl.NumberFormat(loc, { maximumFractionDigits: 1 }).format(n),
|
|
24
|
+
times: (n: number) => new Intl.NumberFormat(loc, { minimumFractionDigits: 1, maximumFractionDigits: 1 }).format(n) + "×",
|
|
25
|
+
startText: (x: Session) => `${dshort(x.day)} ${String(x.hour).padStart(2, "0")}:${String(x.min).padStart(2, "0")}`,
|
|
26
|
+
// The time alone for a scan today, with the date otherwise.
|
|
27
|
+
scanTime: (iso: string) => { const d = new Date(iso); return new Intl.DateTimeFormat(loc, d.toDateString() === new Date().toDateString() ? { hour: "2-digit", minute: "2-digit" } : { hour: "2-digit", minute: "2-digit", day: "numeric", month: "short" }).format(d); },
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// Every string the page shows, in Vietnamese and English.
|
|
2
|
+
export const T = {
|
|
3
|
+
vi: { usage: "Sử dụng", overview: "Tổng quan", projects: "Dự án", sessions: "Phiên làm việc", models: "Model & effort", subagents: "Subagent", activity: "Hoạt động",
|
|
4
|
+
scanned: "Quét lúc", untitled: "(chưa có tiêu đề)", costUnknown: "Không có bản ghi chi phí của host", costEstimated: "Không có bản ghi chi phí của host; ước tính theo bảng giá", costPartial: "Host đánh dấu chi phí chưa đủ", today: "Hôm nay", perHour: "Theo giờ", hour: "Giờ", d7: "7 ngày", d14: "14 ngày", d30: "30 ngày", all: "Tất cả", dates: "Khoảng ngày", prevMonth: "Tháng trước", nextMonth: "Tháng sau", clear: "Xoá", allProviders: "Tất cả provider", allProjects: "Tất cả dự án", allModels: "Tất cả model", provider: "Provider", project: "Dự án", model: "Model", reset: "Bỏ lọc",
|
|
5
|
+
out: "Output token", cost: "Chi phí", costList: "Chi phí niêm yết", sess: "Phiên", cache: "Đọc từ cache", saved: "Cache tiết kiệm", bars: "Dạng cột", areas: "Dạng vùng", shares: "Mỗi cột 100%", savedTip: "So với gửi lại cả context làm input ở mỗi request, đã trừ phần ghi cache trả thêm", reread: (p: string) => `Đọc context: ${p} chi phí`, perM: "$ / 1M token", behave: "Mỗi model làm việc thế nào", bOut: "Output mỗi request", bThink: "Thinking trong output", bSteps: "Request mỗi lượt owner", bTools: "Tool call mỗi request", bFail: "Tool call lỗi", bSpeed: "Tốc độ output", oneModel: "Phiên chỉ dùng model này", speed: "Tốc độ", tps: "token/giây", vsPrev: "so với kỳ trước", noPrev: "chưa có kỳ trước",
|
|
6
|
+
perDay: "Theo ngày", topProjects: "Dự án dùng nhiều nhất", seeAll: "Xem tất cả", hours: "Khung giờ làm việc", peak: "Cao điểm", perBreak: "Tốn thêm mỗi lần", onAverage: "trung bình", overHour: "Sau hơn 1 giờ", ofRebuilds: "số lần dựng lại", failed: "Lượt lỗi", ofCalls: (p: string) => `${p} số lượt gọi`, fromTool: (n: string) => `Từ ${n}`, ofFailures: "số lượt lỗi", otherModel: "Khác model đã gọi", ofSubagents: "số subagent", subCost: "Chi phí subagent", ofAllCost: (usd: string) => `${usd} trong tổng chi phí`, belowMain: "Thấp hơn mức phiên", aboveMain: "Cao hơn mức phiên", ofSubReq: "request của subagent", toolCount: "công cụ", weekend: "Cuối tuần", sameHour: "Phiên cùng giờ", atMost: (n: string) => `thường vậy, nhiều nhất ${n}`, perTurn: "Agent làm mỗi lượt owner", topSessions: "Phiên lớn nhất", dailyTable: "Bảng số liệu theo ngày", hourlyTable: "Bảng số liệu theo giờ",
|
|
7
|
+
day: "Ngày", total: "Tổng", start: "Bắt đầu", title: "Tiêu đề", dur: "Thời lượng", turns: "Lượt owner", subs: "Subagent", activeDays: "Ngày hoạt động", mainModel: "Model chính", trend: "Xu hướng", other: "Khác", search: "Tìm tiêu đề, dự án…", shown: "phiên", more: "Hiện thêm",
|
|
8
|
+
requests: "Request", input: "Input", thinking: "Thinking", cacheRead: "Cache đọc", cacheWrite: "Cache ghi", share: "Tỷ trọng", allEfforts: "Mọi effort", effShare: "Mỗi mức effort chiếm bao nhiêu", leadMore: (n: string, q: string, c: string) => <><b>{n}</b> chiếm {q} số request nhưng tới <b>{c}</b> chi phí.</>, leadLess: (n: string, q: string, c: string) => <><b>{n}</b> chiếm {q} số request và chỉ {c} chi phí.</>, price: "Output mỗi request theo mức effort", priceInfo: "Số lớn là output trung bình mỗi request ở mức đó, thinking tính cả. Phần lớn phiên giữ một mức suốt phiên, nên so thẳng hai mức là so hai nhóm việc khác nhau. Vì vậy dòng \"× high\" chỉ so trong những phiên chạy cả mức đó lẫn high, mỗi mức ít nhất 5 request, rồi lấy trung vị. Dưới 3 phiên như vậy thì không ghi.", vsLevel: "So với", nBoth: (n: number) => `trong ${n} phiên chạy cả hai mức`, fewBoth: (n: number) => (n ? `chỉ ${n} phiên chạy cả hai mức, chưa đủ để so` : "chưa phiên nào chạy cả hai mức"), perReq: "/ request", costShare: "Tỷ trọng chi phí", subEffort: "Effort của subagent", switches: "phiên đã đổi effort", effort: "Effort", subTypes: "Subagent theo loại", count: "Số lần", ranOn: "Chạy trên",
|
|
9
|
+
rebuilt: "Cache bị dựng lại", rbIdle: "Sau khi nghỉ", rbCompaction: "Khi nén context", rbOther: "Khác", rbStart: "Đầu phiên", rbIdleTip: "quay lại sau khi cache hết hạn (5 phút, hoặc 1 giờ nếu dùng cache 1h). Đây là phần tránh được.", rbCompactionTip: "context vừa được nén nên phải ghi lại.", rbOtherTip: "phần đầu prompt đổi mà transcript không cho biết lý do.", rbStartTip: "request đầu của phiên hoặc subagent, không tránh được.",
|
|
10
|
+
rbInfo: "Mỗi request đọc lại cuộc trò chuyện từ prompt cache với giá rẻ. Khi cache mất, request đó phải ghi lại gần hết context vào cache, đắt gấp 25–40 lần đọc. Bảng đếm các lần ghi lại theo nguyên nhân; chi phí thêm là phần trả hơn so với chỉ đọc.", howToRead: "Cách đọc",
|
|
11
|
+
rbTokens: "Token ghi lại", rbExtra: "Chi phí thêm", gapShort: "5–15 phút", gapMid: "15–60 phút", gapLong: "Trên 1 giờ", idleGap: "Đã nghỉ bao lâu trước lần dựng lại", lapses: "Cache hết hạn", session: "Phiên", modelEffort: "Model · effort", nSubs: (n: number) => `${n} subagent`, nLapses: (n: number) => `${n} lần cache hết hạn`, onlySub: "chỉ chạy làm subagent, không trả lời owner", fewReq: (n: string) => `chỉ ${n} request, chưa đủ 20`, fewTurns: (n: string) => `chỉ ${n} lượt owner, chưa đủ 20`, fewCalls: (n: string) => `chỉ ${n} tool call, chưa đủ 20`, fewAlone: (n: number) => (n ? `chỉ ${n} phiên dùng riêng model này, chưa đủ 3` : "không phiên nào dùng riêng model này"),
|
|
12
|
+
tools: "Công cụ được gọi", calls: "lượt", skills: "Skill được dùng", uses: "lượt", skillCount: "skill", skillTyped: "Gõ lệnh /", skillAgent: "Agent tự gọi", lastUsed: "Dùng gần nhất", showFewer: "Thu gọn", srcProject: "Project", srcPersonal: "Cá nhân", srcPlugin: "Plugin", srcBuiltin: "Có sẵn", srcOther: "Khác", errors: "lỗi", time: "Thời gian agent làm việc", linesAR: "Dòng code thêm / xoá", api: "Chờ model", tool: "Chạy công cụ", idle: "Chờ owner, nghỉ", lines: "Dòng code thêm và xoá", added: "Thêm", removed: "Xoá", compactions: "Lần nén context", ownerTurns: "Lượt owner",
|
|
13
|
+
lastActive: "Lần cuối", whereMoney: "Tiền đi vào model nào", ctxPerReq: "Context / request", costKinds: "Chi phí gồm", kRead: "Đọc context", kWrite: "Ghi cache", kOut: "Output", kWeb: "Web search", kRest: "Không tách được", splitModel: "Model", splitProvider: "Provider", splitProject: "Dự án", splitEffort: "Effort", splitKind: "Loại chi phí", figures: "Bảng số liệu", mainVsSub: "Luồng chính và subagent", mainThread: "Luồng chính", routedTitle: "Subagent chạy trên model nào", spawnedOn: (p: string, m: string) => `${p} → ${m}`, costNotes: "Chi phí chưa chắc chắn", stUnknown: "không có bản ghi", stPartial: "chưa đủ", stEst: "ước tính", moreSess: (n: number) => `và ${n} phiên khác`, priceOff: (n: string, d: string) => `lệch bảng giá ở ${n} phiên, từ ${d}`, noPrice: "chưa có giá", costPerSess: "Chi phí mỗi phiên", avgDur: "Thời lượng mỗi phiên", turnsPerSess: "Lượt owner mỗi phiên", compactPerSess: "Nén context mỗi phiên", costPerKLines: "Chi phí mỗi 1.000 dòng code", allProj: "Mọi dự án", shareBy: "Phần của mỗi dự án",
|
|
14
|
+
nodata: "Không có dữ liệu trong khoảng lọc này.", wd: ["T2", "T3", "T4", "T5", "T6", "T7", "CN"], wdShort: ["T2", "T3", "T4", "T5", "T6", "T7", "CN"], theme: "Đổi sáng/tối",
|
|
15
|
+
|
|
16
|
+
context: "Context", compacting: "Nén context", readingCtx: "Đọc lại context", ofCost: (p: string) => `${p} chi phí`, nAuto: (n: string) => `${n} tự động`, nManual: (n: string) => `${n} thủ công`, nInSubs: (n: string) => `${n} trong subagent`,
|
|
17
|
+
keptAfter: "Giữ lại sau khi nén", roomToWork: "Còn trống để làm việc", compactsAt: (v: string) => `Nén ở ${v}`, wait: "Chờ nén", inAll: (d: string) => `tổng ${d}`, eachCosts: "Mỗi lần tốn", eachSplit: (a: string, b: string) => [`tóm tắt ${a}`, `ghi cache ${b}`],
|
|
18
|
+
endedSoon: "Kết thúc ngay sau", endedWithin: (n: number) => `phiên, trong ${n} request`, inSession: "Lần trong phiên", nth: ["Lần 1", "Lần 2", "Lần 3", "Lần 4 trở đi"],
|
|
19
|
+
keptCol: "Giữ lại", reqsToNext: "Request tới lần sau", turnsToNext: "Lượt owner tới lần sau", byCtx: "theo context mỗi request", ctxCol: "Context", perReqCol: "Mỗi request", above: (v: string) => `Trên ${v}`, ofCostReqs: (p: string) => `chi phí, ${p} số request`,
|
|
20
|
+
perReqAt: (b: string) => `Mỗi request ở ${b}`, whatAt: (b: string) => `so với ở ${b}`, noRequest: "Không có request trong transcript", under: (v: string) => `Dưới ${v}`, andOver: (v: string) => `Từ ${v}`,
|
|
21
|
+
otherPoints: "Nén ở mốc khác", estimate: "Ước tính", estNotes: ["Mỗi phiên được chạy lại với mốc nén đó", "Chưa tính phần đọc lại file sau mỗi lần nén, nên mốc thấp hơn hiện tại thực tế tốn hơn số hiện", "Giá niêm yết"],
|
|
22
|
+
allSessions: "Mọi phiên", long4: "Nén từ 4 lần", rebuildIdle: "Dựng lại sau khi nghỉ", compactsAtCol: "Nén ở", sessCompacted: "Phiên có nén", againstNow: "So với hiện tại", now: "hiện tại", byDefault: "mặc định", recorded: "Thực tế",
|
|
23
|
+
recordedVal: (n: string, usd: string) => `${n} lần nén, ${usd} tiền nén`,
|
|
24
|
+
refresh: "Làm mới", scanning: "Đang quét…", bootFind: "Đang tìm transcript…", bootFirst: "Đang đọc transcript lần đầu", bootRebuild: "Đang dựng lại dữ liệu sau khi cập nhật", bootUpdate: "Đang quét transcript mới", bootFinish: "Đang tổng hợp số liệu…", transcripts: "transcript", retry: "Thử lại", scanNew: (n: number) => `${n} phiên mới`, scanFail: "Quét lỗi", loadFail: "Không đọc được dữ liệu", loading: "Đang tải…" },
|
|
25
|
+
en: { usage: "Usage", overview: "Overview", projects: "Projects", sessions: "Sessions", models: "Models & effort", subagents: "Subagents", activity: "Activity",
|
|
26
|
+
scanned: "Scanned", untitled: "(untitled)", costUnknown: "No cost record from the host", costEstimated: "No cost record from the host; estimated from the price table", costPartial: "The host marked this cost incomplete", today: "Today", perHour: "Per hour", hour: "Hour", d7: "7 days", d14: "14 days", d30: "30 days", all: "All", dates: "Date range", prevMonth: "Previous month", nextMonth: "Next month", clear: "Clear", allProviders: "All providers", allProjects: "All projects", allModels: "All models", provider: "Provider", project: "Project", model: "Model", reset: "Clear filters",
|
|
27
|
+
out: "Output tokens", cost: "Cost", costList: "List-price cost", sess: "Sessions", cache: "Read from cache", saved: "Saved by cache", bars: "Columns", areas: "Areas", shares: "Each column as 100%", savedTip: "Against sending the whole context as input on every request, less what cache writes cost extra", reread: (p: string) => `Reading context: ${p} of cost`, perM: "$ / 1M tokens", behave: "How each model works", bOut: "Output per request", bThink: "Thinking share of output", bSteps: "Requests per owner turn", bTools: "Tool calls per request", bFail: "Failed tool calls", bSpeed: "Output speed", oneModel: "Sessions on this model only", speed: "Speed", tps: "tokens/s", vsPrev: "vs prev. period", noPrev: "no previous period",
|
|
28
|
+
perDay: "Per day", topProjects: "Top projects", seeAll: "See all", hours: "Working hours", peak: "Peak", perBreak: "Extra per rebuild", onAverage: "on average", overHour: "After over an hour", ofRebuilds: "of rebuilds", failed: "Failed calls", ofCalls: (p: string) => `${p} of calls`, fromTool: (n: string) => `From ${n}`, ofFailures: "of failures", otherModel: "On another model", ofSubagents: "of subagents", subCost: "Subagent cost", ofAllCost: (usd: string) => `${usd} of all cost`, belowMain: "Below session level", aboveMain: "Above session level", ofSubReq: "of subagent requests", toolCount: "tools", weekend: "Weekends", sameHour: "Same-hour sessions", atMost: (n: string) => `typical, at most ${n}`, perTurn: "Agent work per owner turn", topSessions: "Largest sessions", dailyTable: "Daily figures", hourlyTable: "Hourly figures",
|
|
29
|
+
day: "Day", total: "Total", start: "Start", title: "Title", dur: "Duration", turns: "Owner turns", subs: "Subagents", activeDays: "Active days", mainModel: "Main model", trend: "Trend", other: "Other", search: "Search title, project…", shown: "sessions", more: "Show more",
|
|
30
|
+
requests: "Requests", input: "Input", thinking: "Thinking", cacheRead: "Cache read", cacheWrite: "Cache write", share: "Share", allEfforts: "All efforts", effShare: "How much each effort level takes", leadMore: (n: string, q: string, c: string) => <><b>{n}</b> is {q} of requests but <b>{c}</b> of cost.</>, leadLess: (n: string, q: string, c: string) => <><b>{n}</b> is {q} of requests and only {c} of cost.</>, price: "Output per request by effort level", priceInfo: "The large figure is the average output of one request at that level, thinking included. Most sessions keep one level throughout, so comparing two levels directly compares different work. The \"× high\" line therefore compares only sessions that ran both that level and high, with at least 5 requests at each, and takes the median. With fewer than 3 such sessions it is left out.", vsLevel: "Against", nBoth: (n: number) => `in ${n} session${n === 1 ? "" : "s"} that ran both levels`, fewBoth: (n: number) => (n ? `only ${n} session${n === 1 ? "" : "s"} ran both levels, too few to compare` : "no session ran both levels"), perReq: "/ request", costShare: "Share of cost", subEffort: "Subagent effort", switches: "sessions changed effort", effort: "Effort", subTypes: "Subagents by type", count: "Count", ranOn: "Ran on",
|
|
31
|
+
rebuilt: "Cache rebuilt", rbIdle: "After idle", rbCompaction: "At compaction", rbOther: "Other", rbStart: "At session start", rbIdleTip: "returned after the cache expired (5 minutes, or 1 hour with 1h cache). The avoidable part.", rbCompactionTip: "the context was just compacted.", rbOtherTip: "the start of the prompt changed for a reason the transcript does not show.", rbStartTip: "the first request of a session or subagent, unavoidable.",
|
|
32
|
+
rbInfo: "Each request rereads the conversation from the prompt cache at a low price. When the cache is gone, the request writes most of the context into it again, at 25–40 times the read price. The table counts these rewrites by cause; extra cost is what they cost beyond a read.", howToRead: "How to read",
|
|
33
|
+
rbTokens: "Rewritten tokens", rbExtra: "Extra cost", gapShort: "5–15 min", gapMid: "15–60 min", gapLong: "Over 1 h", idleGap: "Idle time before the rebuild", lapses: "Cache lapses", session: "Session", modelEffort: "Model · effort", nSubs: (n: number) => `${n} subagent${n === 1 ? "" : "s"}`, nLapses: (n: number) => `${n} cache lapse${n === 1 ? "" : "s"}`, onlySub: "runs only as a subagent, never answering the owner", fewReq: (n: string) => `only ${n} requests, fewer than 20`, fewTurns: (n: string) => `only ${n} owner turns, fewer than 20`, fewCalls: (n: string) => `only ${n} tool calls, fewer than 20`, fewAlone: (n: number) => (n ? `only ${n} session${n === 1 ? "" : "s"} on this model alone, fewer than 3` : "no session ran this model alone"),
|
|
34
|
+
tools: "Tool calls", calls: "calls", skills: "Skills used", uses: "uses", skillCount: "skills", skillTyped: "Typed as /command", skillAgent: "Called by the agent", lastUsed: "Last used", showFewer: "Show fewer", srcProject: "Project", srcPersonal: "Personal", srcPlugin: "Plugin", srcBuiltin: "Built-in", srcOther: "Other", errors: "errors", time: "Agent working time", linesAR: "Lines added / removed", api: "Waiting for the model", tool: "Running tools", idle: "Idle, waiting for the owner", lines: "Lines added and removed", added: "Added", removed: "Removed", compactions: "Compactions", ownerTurns: "Owner turns",
|
|
35
|
+
lastActive: "Last active", whereMoney: "Which model the money goes to", ctxPerReq: "Context per request", costKinds: "Cost made of", kRead: "Reading context", kWrite: "Cache writes", kOut: "Output", kWeb: "Web search", kRest: "Not split", splitModel: "Model", splitProvider: "Provider", splitProject: "Project", splitEffort: "Effort", splitKind: "Cost kind", figures: "Figures", mainVsSub: "Main thread and subagents", mainThread: "Main thread", routedTitle: "Which model subagents ran on", spawnedOn: (p: string, m: string) => `${p} → ${m}`, costNotes: "Cost not certain", stUnknown: "no record", stPartial: "incomplete", stEst: "estimated", moreSess: (n: number) => `and ${n} more sessions`, priceOff: (n: string, d: string) => `off the price table in ${n} sessions since ${d}`, noPrice: "no price", costPerSess: "Cost per session", avgDur: "Length per session", turnsPerSess: "Owner turns per session", compactPerSess: "Compactions per session", costPerKLines: "Cost per 1,000 lines", allProj: "All projects", shareBy: "Each project's share",
|
|
36
|
+
nodata: "No data in this filter range.", wd: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"], wdShort: ["Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"], theme: "Toggle light/dark",
|
|
37
|
+
|
|
38
|
+
context: "Context", compacting: "Compacting", readingCtx: "Reading the context", ofCost: (p: string) => `${p} of cost`, nAuto: (n: string) => `${n} auto`, nManual: (n: string) => `${n} manual`, nInSubs: (n: string) => `${n} in subagents`,
|
|
39
|
+
keptAfter: "Kept after compacting", roomToWork: "Room to work", compactsAt: (v: string) => `Compacts at ${v}`, wait: "Wait", inAll: (d: string) => `${d} in all`, eachCosts: "Each costs", eachSplit: (a: string, b: string) => [`summary ${a}`, `cache write ${b}`],
|
|
40
|
+
endedSoon: "Ended soon after", endedWithin: (n: number) => `sessions, within ${n} requests`, inSession: "In the session", nth: ["1st", "2nd", "3rd", "4th or later"],
|
|
41
|
+
keptCol: "Kept after", reqsToNext: "Requests to next", turnsToNext: "Owner turns to next", byCtx: "by context per request", ctxCol: "Context", perReqCol: "Per request", above: (v: string) => `Above ${v}`, ofCostReqs: (p: string) => `of the cost, ${p} of requests`,
|
|
42
|
+
perReqAt: (b: string) => `Per request at ${b}`, whatAt: (b: string) => `what it is at ${b}`, noRequest: "No request in the transcript", under: (v: string) => `Under ${v}`, andOver: (v: string) => `${v} and over`,
|
|
43
|
+
otherPoints: "Compacting at other points", estimate: "Estimate", estNotes: ["Each session replayed with compaction at that point", "Files read again after a compaction are not counted, so points below now cost more than shown", "List prices"],
|
|
44
|
+
allSessions: "All sessions", long4: "Compacted 4+ times", rebuildIdle: "Rebuild after idle", compactsAtCol: "Compacts at", sessCompacted: "Sessions compacted", againstNow: "Against now", now: "now", byDefault: "default", recorded: "Recorded",
|
|
45
|
+
recordedVal: (n: string, usd: string) => `${n} compactions, ${usd} compacting`,
|
|
46
|
+
refresh: "Refresh", scanning: "Scanning…", bootFind: "Finding transcripts…", bootFirst: "Reading your transcripts for the first time", bootRebuild: "Rebuilding the data after an update", bootUpdate: "Scanning new transcripts", bootFinish: "Putting the figures together…", transcripts: "transcripts", retry: "Try again", scanNew: (n: number) => `${n} new sessions`, scanFail: "Scan failed", loadFail: "Cannot read the data", loading: "Loading…" },
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export type Lang = keyof typeof T;
|
|
50
|
+
type Strings = (typeof T)["vi"];
|
|
51
|
+
// Keys whose value is plain text, for the t() lookup.
|
|
52
|
+
export type Key = { [K in keyof Strings]: Strings[K] extends string ? K : never }[keyof Strings];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// What another package imports to extend the dashboard: the App, the shared context and the UI parts of the built-in views.
|
|
2
|
+
export { App } from "./App.tsx";
|
|
3
|
+
export { DashContext, useDash, type Dash } from "./dash.ts";
|
|
4
|
+
export type { Extra, ExtraView, Label } from "./extra.ts";
|
|
5
|
+
export type { Fmt } from "./format.ts";
|
|
6
|
+
export type { Key, Lang } from "./i18n.tsx";
|
|
7
|
+
export * from "./ui.tsx";
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { test } from "node:test";
|
|
3
|
+
import { behavior, buildModel, byDayKinds, context, costParts, providerOptions, rebuilds, skillUses, vsHigh, type Fact, type Model, type Payload } from "./model.ts";
|
|
4
|
+
import { parseUrl } from "./state.ts";
|
|
5
|
+
|
|
6
|
+
const fact = (rb: number[] | null): Fact => ({ s: 0, d: "2026-11-01", h: 0, m: 0, sub: 0, e: 0, q: 1, i: 0, o: 0, cr: 0, cw: 0, th: 0, c: 0, rb, k: null, sv: 0, tc: 0, te: 0, ot: 0 });
|
|
7
|
+
|
|
8
|
+
test("rebuilds sums the facts' vectors per cause and splits the idle ones by gap", () => {
|
|
9
|
+
// start, compaction, idle, other as [count, tokens, extra], then the three idle gap counts.
|
|
10
|
+
const a = [1, 100, 0.5, 0, 0, 0, 2, 300, 1.5, 0, 0, 0, 1, 0, 1];
|
|
11
|
+
const b = [0, 0, 0, 1, 50, 0.25, 0, 0, 0, 3, 90, 0.75, 0, 0, 0];
|
|
12
|
+
assert.deepEqual(rebuilds([fact(a), fact(null), fact(b)]), {
|
|
13
|
+
start: { n: 1, tokens: 100, extra: 0.5 }, compaction: { n: 1, tokens: 50, extra: 0.25 }, idle: { n: 2, tokens: 300, extra: 1.5 }, other: { n: 3, tokens: 90, extra: 0.75 }, gaps: [1, 0, 1],
|
|
14
|
+
});
|
|
15
|
+
assert.equal(rebuilds([]).idle.n, 0);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test("a sort the sessions table has no column for falls back to the start", () => {
|
|
19
|
+
for (const k of ["project", "tps", "subs", "lapses"]) assert.equal(parseUrl("/sessions", `sort=${k}`).sort, "start");
|
|
20
|
+
assert.equal(parseUrl("/sessions", "sort=ctx").sort, "ctx");
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test("skillUses sums sessions per skill, listed by source and then most used", () => {
|
|
24
|
+
const M = {
|
|
25
|
+
skills: [{ review: [1, 2, 0, "2026-11-01"], pdf: [0, 1, 1, "2026-11-01"] }, { review: [0, 3, 0, "2026-11-03"], notes: [2, 0, 0, "2026-11-02"] }, { review: [9, 9, 0, "2026-11-04"] }],
|
|
26
|
+
skillSources: { review: "project", pdf: "plugin", notes: "personal" },
|
|
27
|
+
} as unknown as Model;
|
|
28
|
+
assert.deepEqual(skillUses(M, [0, 1]), [
|
|
29
|
+
{ name: "review", source: "project", command: 1, agent: 5, errors: 0, sessions: 2, last: "2026-11-03" },
|
|
30
|
+
{ name: "notes", source: "personal", command: 2, agent: 0, errors: 0, sessions: 1, last: "2026-11-02" },
|
|
31
|
+
{ name: "pdf", source: "plugin", command: 0, agent: 1, errors: 1, sessions: 1, last: "2026-11-01" },
|
|
32
|
+
]);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test("context per request counts input, cache reads and cache writes", () => {
|
|
36
|
+
assert.equal(context({ i: 10, cr: 900, cw: 90, q: 2 }), 500);
|
|
37
|
+
assert.equal(context({ i: 0, cr: 0, cw: 0, q: 0 }), 0);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test("cost parts keep what the table cannot split only when it is at least 1% of the cost", () => {
|
|
41
|
+
assert.deepEqual(costParts(10, [5, 2, 1, 0]), [5, 2, 1, 0, 2]);
|
|
42
|
+
assert.deepEqual(costParts(10, [4, 3, 1.95, 1]), [4, 3, 1.95, 1, 0]);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test("cost per day splits each fact's priced parts and puts the rest of its cost apart", () => {
|
|
46
|
+
const f = (d: string, c: number, k: number[] | null): Fact => ({ ...fact(null), d, c, k });
|
|
47
|
+
const rows = byDayKinds([f("2026-11-01", 4, [1, 1, 1, 1]), f("2026-11-01", 3, null), f("2026-11-02", 2, [1, 0.5, 0.5, 0])], ["2026-11-01", "2026-11-02"]);
|
|
48
|
+
assert.deepEqual(rows, [[1, 1, 1, 1, 3], [1, 0.5, 0.5, 0, 0]]);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test("effort against high compares the same sessions, as the median of their ratios", () => {
|
|
52
|
+
const f = (s: number, sub: number, e: number, q: number, o: number): Fact => ({ ...fact(null), s, sub, e, q, o });
|
|
53
|
+
// Sessions 0-2 ran medium (1) at half, 0.8 and 0.6 of their high (2); session 3 ran only medium, at a far higher
|
|
54
|
+
// output, and session 4 has too few medium requests: neither counts. Session 0's subagents are compared apart.
|
|
55
|
+
const F = [f(0, 0, 1, 10, 500), f(0, 0, 2, 10, 1000), f(1, 0, 1, 5, 400), f(1, 0, 2, 5, 500), f(2, 0, 1, 20, 1200), f(2, 0, 2, 20, 2000),
|
|
56
|
+
f(3, 0, 1, 50, 50000), f(4, 0, 1, 4, 100), f(4, 0, 2, 9, 900), f(0, 1, 1, 5, 5000), f(0, 1, 2, 4, 100)];
|
|
57
|
+
assert.deepEqual(vsHigh(F, 0, 1, 2), { r: 0.6, n: 3 });
|
|
58
|
+
assert.deepEqual(vsHigh(F.filter((x) => x.s !== 2), 0, 1, 2), { r: null, n: 2 });
|
|
59
|
+
assert.deepEqual(vsHigh(F, 1, 1, 2), { r: null, n: 0 });
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("how each model works needs a base for each figure, and speed only sessions that ran one model", () => {
|
|
63
|
+
const f = (s: number, m: number, sub: number, q: number, o: number, x: Partial<Fact> = {}): Fact => ({ ...fact(null), s, m, sub, q, o, ...x });
|
|
64
|
+
const session = (api: number, out: number) => ({ api, out });
|
|
65
|
+
// Model 0 runs sessions 0-2 alone; session 3 mixes it with model 1, so only model 0's sessions 0-2 give a speed.
|
|
66
|
+
const F = [f(0, 0, 0, 10, 1000, { th: 500, ot: 10, tc: 20, te: 2 }), f(0, 0, 1, 10, 500, { tc: 10 }), f(1, 0, 0, 5, 500, { ot: 5 }), f(2, 0, 0, 5, 500, { ot: 5 }),
|
|
67
|
+
f(3, 0, 0, 5, 100), f(3, 1, 1, 30, 300, { tc: 3 })];
|
|
68
|
+
const M = { models: ["a", "b"], facts: F, sessions: [session(10, 1500), session(5, 500), session(5, 500), session(20, 400)] } as unknown as Model;
|
|
69
|
+
const [a, b] = behavior(M, F);
|
|
70
|
+
assert.deepEqual(a, { m: 0, q: 35, main: 25, turns: 20, calls: 30, timed: 3, out: 2600 / 35, think: 500 / 2600, steps: 25 / 20, tools: 30 / 35, fail: 2 / 30, tps: 2500 / 20 });
|
|
71
|
+
assert.deepEqual(b, { m: 1, q: 30, main: 0, turns: 0, calls: 3, timed: 0, out: 10, think: 0, steps: null, tools: 0.1, fail: null, tps: null });
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test("providerOptions scopes models, projects and effort levels to the chosen provider", () => {
|
|
75
|
+
const f = (s: number, m: number, e: number): Fact => ({ ...fact(null), s, m, e });
|
|
76
|
+
const M = {
|
|
77
|
+
models: ["Opus", "Sonnet", "GPT Sol", "Gemini Neon"],
|
|
78
|
+
providers: ["Claude", "Codex", "Antigravity"],
|
|
79
|
+
projectRank: [0, 1, 2],
|
|
80
|
+
levels: [0, 1, 2, 3],
|
|
81
|
+
sessions: [{ pr: 0, p: 0 }, { pr: 1, p: 1 }, { pr: 2, p: 2 }],
|
|
82
|
+
facts: [f(0, 0, 2), f(0, 1, 1), f(1, 2, 0), f(2, 3, 3)],
|
|
83
|
+
} as unknown as Model;
|
|
84
|
+
assert.deepEqual(providerOptions(M, -1), { models: [0, 1, 2, 3], projects: [0, 1, 2], levels: [0, 1, 2, 3] });
|
|
85
|
+
assert.deepEqual(providerOptions(M, 0), { models: [0, 1], projects: [0], levels: [1, 2] });
|
|
86
|
+
assert.deepEqual(providerOptions(M, 1), { models: [2], projects: [1], levels: [0] });
|
|
87
|
+
assert.deepEqual(providerOptions(M, 2), { models: [3], projects: [2], levels: [3] });
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test("mColor assigns 16 distinct colors skipping unknown as c0", () => {
|
|
91
|
+
const models = [...Array.from({ length: 10 }, (_, i) => `M${i}`), "unknown", ...Array.from({ length: 7 }, (_, i) => `M${i + 10}`)];
|
|
92
|
+
const m = buildModel({
|
|
93
|
+
today: "2026-11-01",
|
|
94
|
+
scanned: "2026-11-01T00:00:00Z",
|
|
95
|
+
models,
|
|
96
|
+
projects: [],
|
|
97
|
+
types: [],
|
|
98
|
+
efforts: [],
|
|
99
|
+
sessions: [],
|
|
100
|
+
subagents: [],
|
|
101
|
+
tools: [],
|
|
102
|
+
skills: [],
|
|
103
|
+
skillSources: {},
|
|
104
|
+
facts: [],
|
|
105
|
+
} as unknown as Payload);
|
|
106
|
+
assert.equal(m.mColor(10), "c0");
|
|
107
|
+
const nonUnknown = models.map((_, i) => i).filter((i) => i !== 10).map((i) => m.mColor(i));
|
|
108
|
+
assert.deepEqual(nonUnknown.slice(0, 16), Array.from({ length: 16 }, (_, i) => `c${i + 1}`));
|
|
109
|
+
assert.equal(nonUnknown[16], "c1");
|
|
110
|
+
});
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
// The rows from GET /api/data (built by src/dashboard.mjs) and the queries the views run.
|
|
2
|
+
// sessions one row per session (project, title, start, durations and cost from the host's cost record,
|
|
3
|
+
// owner messages, compactions, lines changed) and its main-thread effort runs [effort, requests]
|
|
4
|
+
// facts tokens and cost per session, day, hour, model, effort and main/subagent (from per-request usage)
|
|
5
|
+
// subagents one row per subagent (type, model, parent model, output tokens)
|
|
6
|
+
// tools tool calls and errors per session
|
|
7
|
+
// skills per session, each skill's [typed as a command, called by the agent, failed calls, last day used];
|
|
8
|
+
// skillSources says where each skill was loaded from
|
|
9
|
+
// compactions one row per compaction (see Compaction)
|
|
10
|
+
// context per session, day, model and effort: the cost of reading the context by size and the replay (see Ctx)
|
|
11
|
+
|
|
12
|
+
export type Run = [effort: number, requests: number];
|
|
13
|
+
export type Session = {
|
|
14
|
+
id: string; pr?: number; p: number; title: string; day: string; hour: number; min: number; dur: number; api: number; tool: number;
|
|
15
|
+
owner: number; compact: number; la: number; lr: number; parent: number; subs: unknown[]; cost: number;
|
|
16
|
+
costState: "ok" | "unknown" | "incomplete" | "estimated"; out: number; runs: Run[];
|
|
17
|
+
// Models without a price row, and models whose host cost misses the price table, in this session.
|
|
18
|
+
unpriced: string[]; priceOff: string[];
|
|
19
|
+
};
|
|
20
|
+
// rb is null unless a request of the fact rebuilt the cache; else [count, rewritten tokens, extra cost] per cause in
|
|
21
|
+
// CAUSES order, then the idle gaps from 5 to 15 minutes, from 15 to 60 minutes and over an hour (summed over the fact's requests).
|
|
22
|
+
// k is null unless part of the fact's cost was priced; else that cost as [reading the context, writing the cache, output, web search].
|
|
23
|
+
// sv is what the cache saved against sending the same tokens as input; tc and te count tool calls and failed ones;
|
|
24
|
+
// ot counts the owner turns whose first request is in the fact.
|
|
25
|
+
export type Fact = { s: number; d: string; h: number; m: number; sub: number; e: number; q: number; i: number; o: number; cr: number; cw: number; th: number; c: number; rb: number[] | null; k: number[] | null; sv: number; tc: number; te: number; ot: number };
|
|
26
|
+
export type Subagent = { s: number; type: number; m: number; parent: number; o: number };
|
|
27
|
+
type RawFact = [number, string, number, number, number, number, number, number, number, number, number, number, number, number[] | null, number[] | null, number, number, number, number];
|
|
28
|
+
// A compaction: auto is 1, manual 0, unknown null; pre, post and kept are tokens of context before it, of its summary and of
|
|
29
|
+
// the next request; next and turns count requests and owner turns up to the next one (null for the last), tail the requests
|
|
30
|
+
// after the last one; sum is what its summary request cost (null when it cannot be priced), rb the rewrite after it.
|
|
31
|
+
export type Compaction = { s: number; d: string; m: number; e: number; sub: number; auto: number | null; pre: number | null; post: number | null; wait: number | null;
|
|
32
|
+
kept: number | null; nth: number; next: number | null; turns: number | null; tail: number | null; sum: number | null; rb: number };
|
|
33
|
+
type RawCompaction = [number, string, number, number, number, number | null, number | null, number | null, number | null, number | null, number, number | null, number | null, number | null, number | null, number];
|
|
34
|
+
// b: the cost of reading the context per size bucket (edges in Payload), then a part the host charged with no request;
|
|
35
|
+
// n: requests per bucket; r: per replay point (the points, then now) compactions, reading, compacting, rebuilds after idle.
|
|
36
|
+
export type Ctx = { s: number; d: string; m: number; e: number; b: number[]; n: number[]; r: number[] | null };
|
|
37
|
+
type RawCtx = [number, string, number, number, number[], number[], number[] | null];
|
|
38
|
+
export type Payload = {
|
|
39
|
+
today: string; scanned: string; models: string[]; providers?: string[]; projects: string[]; types: string[]; efforts: string[]; transcripts: number;
|
|
40
|
+
sessions: Session[]; facts: RawFact[]; subagents: Subagent[]; tools: Record<string, [number, number]>[];
|
|
41
|
+
skills: Record<string, SkillUse>[]; skillSources: Record<string, SkillSource>;
|
|
42
|
+
compactions: RawCompaction[]; context: RawCtx[]; edges: number[]; points: number[]; fires: Record<number, number | null>;
|
|
43
|
+
};
|
|
44
|
+
export type SkillUse = [command: number, agent: number, errors: number, last: string];
|
|
45
|
+
export const SKILL_SOURCES = ["project", "personal", "plugin", "builtin", "other"] as const;
|
|
46
|
+
export type SkillSource = (typeof SKILL_SOURCES)[number];
|
|
47
|
+
|
|
48
|
+
export type Model = ReturnType<typeof buildModel>;
|
|
49
|
+
|
|
50
|
+
export const dayAdd = (day: string, n: number) => new Date(Date.parse(day + "T00:00:00Z") + n * 864e5).toISOString().slice(0, 10);
|
|
51
|
+
export const days = (from: string, to: string) => { const out: string[] = []; for (let d = from; d <= to; d = dayAdd(d, 1)) out.push(d); return out; };
|
|
52
|
+
|
|
53
|
+
export function buildModel(data: Payload) {
|
|
54
|
+
const facts: Fact[] = data.facts.map(([s, d, h, m, sub, e, q, i, o, cr, cw, th, c, rb, k, sv, tc, te, ot]) => ({ s, d, h, m, sub, e, q, i, o, cr, cw, th, c, rb, k, sv, tc, te, ot }));
|
|
55
|
+
const sumOut = (p: number) => facts.reduce((n, f) => n + (data.sessions[f.s].p === p ? f.o : 0), 0);
|
|
56
|
+
const projectRank = data.projects.map((_, i) => i).sort((a, b) => sumOut(b) - sumOut(a));
|
|
57
|
+
const modelColors: string[] = [];
|
|
58
|
+
let colorSlot = 0;
|
|
59
|
+
for (const name of data.models) {
|
|
60
|
+
if (name === "unknown") modelColors.push("c0");
|
|
61
|
+
else modelColors.push("c" + ((colorSlot++ % 16) + 1));
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
today: data.today, scanned: data.scanned,
|
|
65
|
+
models: data.models, providers: data.providers ?? [], projects: data.projects, types: data.types,
|
|
66
|
+
// Levels low → max, then any other value seen as written; facts and runs hold an index into it.
|
|
67
|
+
efforts: data.efforts,
|
|
68
|
+
levels: data.efforts.map((_, e) => e).filter((e) => facts.some((f) => f.e === e)), // levels seen, low → max
|
|
69
|
+
first: facts.reduce((a, f) => (f.d < a ? f.d : a), data.today),
|
|
70
|
+
sessions: data.sessions, subagents: data.subagents, tools: data.tools, skills: data.skills, skillSources: data.skillSources, facts, projectRank,
|
|
71
|
+
compactions: (data.compactions ?? []).map(([s, d, m, e, sub, auto, pre, post, wait, kept, nth, next, turns, tail, sum, rb]): Compaction => ({ s, d, m, e, sub, auto, pre, post, wait, kept, nth, next, turns, tail, sum, rb })),
|
|
72
|
+
context: (data.context ?? []).map(([s, d, m, e, b, n, r]): Ctx => ({ s, d, m, e, b, n, r })),
|
|
73
|
+
edges: data.edges ?? [], points: data.points ?? [], fires: data.fires ?? {}, // per model, the context at which compaction fires now
|
|
74
|
+
pColor: (p: number) => { const r = projectRank.indexOf(p); return r < 5 ? "c" + (r + 1) : "c0"; },
|
|
75
|
+
mColor: (m: number) => modelColors[m] ?? "c0",
|
|
76
|
+
prColor: (pr: number) => (pr >= 0 && pr < 8 ? "c" + (pr + 1) : "c0"),
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export type Filter = { from: string; to: string; provider: number; project: number; model: number; effort: number };
|
|
81
|
+
export type Metric = "out" | "cost" | "sess";
|
|
82
|
+
export type Split = "model" | "provider" | "kind";
|
|
83
|
+
|
|
84
|
+
export function providerOptions(M: Model, provider: number): { models: number[]; projects: number[]; levels: number[] } {
|
|
85
|
+
if (provider < 0) return { models: M.models.map((_, i) => i), projects: M.projectRank, levels: M.levels };
|
|
86
|
+
const seenM = new Set<number>(), seenP = new Set<number>(), seenE = new Set<number>();
|
|
87
|
+
for (const f of M.facts) {
|
|
88
|
+
const s = M.sessions[f.s];
|
|
89
|
+
if ((s.pr ?? -1) !== provider) continue;
|
|
90
|
+
seenM.add(f.m);
|
|
91
|
+
seenP.add(s.p);
|
|
92
|
+
seenE.add(f.e);
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
models: M.models.map((_, i) => i).filter((m) => seenM.has(m)),
|
|
96
|
+
projects: M.projectRank.filter((p) => seenP.has(p)),
|
|
97
|
+
levels: M.levels.filter((e) => seenE.has(e)),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function slice(M: Model, f: Filter, from = f.from, to = f.to) {
|
|
102
|
+
return M.facts.filter((x) => x.d >= from && x.d <= to && (f.provider < 0 || (M.sessions[x.s].pr ?? -1) === f.provider) && (f.project < 0 || M.sessions[x.s].p === f.project) && (f.model < 0 || x.m === f.model) && (f.effort < 0 || x.e === f.effort));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Compactions and context rows under the same filter as the facts.
|
|
106
|
+
export const keep = (M: Model, f: Filter, from = f.from, to = f.to) => <T extends { s: number; d: string; m: number; e: number }>(x: T) =>
|
|
107
|
+
x.d >= from && x.d <= to && (f.provider < 0 || (M.sessions[x.s].pr ?? -1) === f.provider) && (f.project < 0 || M.sessions[x.s].p === f.project) && (f.model < 0 || x.m === f.model) && (f.effort < 0 || x.e === f.effort);
|
|
108
|
+
|
|
109
|
+
export const CAUSES = ["start", "compaction", "idle", "other"] as const;
|
|
110
|
+
const RB_IDLE = CAUSES.indexOf("idle") * 3, RB_GAPS = CAUSES.length * 3;
|
|
111
|
+
export type Rebuilds = Record<(typeof CAUSES)[number], { n: number; tokens: number; extra: number }> & { gaps: number[] };
|
|
112
|
+
// What the facts hold per rebuild cause, and the idle ones split by the time since the previous request.
|
|
113
|
+
export function rebuilds(F: Fact[]): Rebuilds {
|
|
114
|
+
const v = new Array(RB_GAPS + 3).fill(0);
|
|
115
|
+
for (const f of F) if (f.rb) f.rb.forEach((x, i) => { v[i] += x; });
|
|
116
|
+
const at = (c: (typeof CAUSES)[number]) => { const i = CAUSES.indexOf(c) * 3; return { n: v[i], tokens: v[i + 1], extra: v[i + 2] }; };
|
|
117
|
+
return { start: at("start"), compaction: at("compaction"), idle: at("idle"), other: at("other"), gaps: v.slice(RB_GAPS) };
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// A cost as [reading the context, writing the cache, output, what the price table cannot split]: the last part is a
|
|
121
|
+
// model without a price row, or a cost the host charged without a request in the transcript; under 1% it is dropped.
|
|
122
|
+
// A cost as reading the context, writing the cache, output, web search and the rest the price table cannot split.
|
|
123
|
+
export function costParts(c: number, k: number[]) {
|
|
124
|
+
const rest = c - k.reduce((a, b) => a + b, 0);
|
|
125
|
+
return [...k, rest > c * 0.01 ? rest : 0];
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Cost per day, or per hour when list holds hours, split as costParts splits it.
|
|
129
|
+
export function byDayKinds(F: Fact[], list: (string | number)[]) {
|
|
130
|
+
const slot = typeof list[0] === "number" ? (f: Fact) => f.h : (f: Fact) => f.d;
|
|
131
|
+
const idx = new Map<string | number, number>(list.map((d, i) => [d, i]));
|
|
132
|
+
const rows = list.map(() => [0, 0, 0, 0, 0]);
|
|
133
|
+
for (const f of F) {
|
|
134
|
+
const i = idx.get(slot(f));
|
|
135
|
+
if (i === undefined) continue;
|
|
136
|
+
const k = f.k ?? [0, 0, 0, 0];
|
|
137
|
+
for (let j = 0; j < 4; j++) rows[i][j] += k[j];
|
|
138
|
+
rows[i][4] += f.c - k[0] - k[1] - k[2] - k[3];
|
|
139
|
+
}
|
|
140
|
+
// A rounding remainder is not a part of its own.
|
|
141
|
+
for (const r of rows) if (r[4] < r.reduce((a, b) => a + b, 0) * 0.01) r[4] = 0;
|
|
142
|
+
return rows;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export type Totals = ReturnType<typeof totals>;
|
|
146
|
+
export function totals(M: Model, F: Fact[]) {
|
|
147
|
+
const a = { o: 0, c: 0, i: 0, cr: 0, cw: 0, q: 0, th: 0, sv: 0, n: 0, hit: 0, ctx: 0, tps: 0, k: [0, 0, 0, 0], sess: new Set<number>() };
|
|
148
|
+
for (const f of F) { a.o += f.o; a.c += f.c; a.i += f.i; a.cr += f.cr; a.cw += f.cw; a.q += f.q; a.th += f.th; a.sv += f.sv; a.sess.add(f.s); f.k?.forEach((x, j) => { a.k[j] += x; }); }
|
|
149
|
+
const ss = [...a.sess].map((s) => M.sessions[s]);
|
|
150
|
+
a.n = a.sess.size; a.hit = a.cr / (a.cr + a.cw + a.i || 1); a.ctx = context(a);
|
|
151
|
+
// Speed counts only sessions whose host record gives API time; a running session has none yet.
|
|
152
|
+
const timed = ss.filter((s) => s.api > 0);
|
|
153
|
+
a.tps = timed.reduce((n, s) => n + s.out, 0) / (timed.reduce((n, s) => n + s.api, 0) || 1);
|
|
154
|
+
return a;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const val = (metric: Metric, f: Fact) => (metric === "cost" ? f.c : f.o);
|
|
158
|
+
export const HOURLY = Array.from({ length: 24 }, (_, h) => h);
|
|
159
|
+
// A one-day window draws per-day charts by hour.
|
|
160
|
+
export const slotsOf = (list: string[]): (string | number)[] => (list.length === 1 ? HOURLY : list);
|
|
161
|
+
|
|
162
|
+
export function byDay(F: Fact[], list: (string | number)[], key: (f: Fact) => number, groups: unknown[], metric: Metric) {
|
|
163
|
+
const slot = typeof list[0] === "number" ? (f: Fact) => f.h : (f: Fact) => f.d;
|
|
164
|
+
const idx = new Map<string | number, number>(list.map((d, i) => [d, i]));
|
|
165
|
+
const rows = list.map(() => groups.map(() => 0)), seen = list.map(() => groups.map(() => new Set<number>()));
|
|
166
|
+
for (const f of F) { const i = idx.get(slot(f)), g = key(f); if (i === undefined || g < 0) continue; if (metric === "sess") seen[i][g].add(f.s); else rows[i][g] += val(metric, f); }
|
|
167
|
+
return metric === "sess" ? seen.map((r) => r.map((s) => s.size)) : rows;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export function group(F: Fact[], key: (f: Fact) => number, metric: Metric) {
|
|
171
|
+
const m = new Map<number, number | Set<number>>();
|
|
172
|
+
for (const f of F) {
|
|
173
|
+
const k = key(f);
|
|
174
|
+
if (metric === "sess") { if (!m.has(k)) m.set(k, new Set()); (m.get(k) as Set<number>).add(f.s); } else m.set(k, ((m.get(k) as number) || 0) + val(metric, f));
|
|
175
|
+
}
|
|
176
|
+
return new Map([...m].map(([k, v]) => [k, v instanceof Set ? v.size : v]));
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// The context one request carries: what it read as input, from the cache or wrote to it.
|
|
180
|
+
export const context = (a: { i: number; cr: number; cw: number; q: number }) => (a.q ? (a.i + a.cr + a.cw) / a.q : 0);
|
|
181
|
+
|
|
182
|
+
export type SessionRow = { s: number; o: number; c: number; cr: number; cw: number; i: number; q: number; mix: number[]; subMix: number[]; lapses: number; x: Session; hit: number; ctx: number };
|
|
183
|
+
export function sessionRows(M: Model, F: Fact[]): SessionRow[] {
|
|
184
|
+
const m = new Map<number, Omit<SessionRow, "x" | "hit" | "ctx">>();
|
|
185
|
+
for (const f of F) {
|
|
186
|
+
let r = m.get(f.s);
|
|
187
|
+
if (!r) m.set(f.s, (r = { s: f.s, o: 0, c: 0, cr: 0, cw: 0, i: 0, q: 0, mix: M.models.map(() => 0), subMix: M.models.map(() => 0), lapses: 0 }));
|
|
188
|
+
r.o += f.o; r.c += f.c; r.cr += f.cr; r.cw += f.cw; r.i += f.i; r.q += f.q; r.mix[f.m] += f.o; if (f.sub) r.subMix[f.m] += f.o;
|
|
189
|
+
if (f.rb) r.lapses += f.rb[RB_IDLE];
|
|
190
|
+
}
|
|
191
|
+
return [...m.values()].map((r) => ({ ...r, x: M.sessions[r.s], hit: r.cr / (r.cr + r.cw + r.i || 1), ctx: context(r) }));
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Tool calls and errors summed over sessions, most called first.
|
|
195
|
+
export function toolCalls(M: Model, sessions: number[]) {
|
|
196
|
+
const by = new Map<string, [number, number]>();
|
|
197
|
+
sessions.forEach((s) => Object.entries(M.tools[s]).forEach(([n, [c, e]]) => { const r = by.get(n) ?? [0, 0]; r[0] += c; r[1] += e; by.set(n, r); }));
|
|
198
|
+
return [...by].sort((a, b) => b[1][0] - a[1][0]);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export type SkillRow = { name: string; source: SkillSource; command: number; agent: number; errors: number; sessions: number; last: string };
|
|
202
|
+
// Skills summed over sessions, by source and then most used first; the same rows as `usage --by skill`.
|
|
203
|
+
export function skillUses(M: Model, sessions: number[]): SkillRow[] {
|
|
204
|
+
const by = new Map<string, SkillRow>();
|
|
205
|
+
sessions.forEach((s) => Object.entries(M.skills[s]).forEach(([name, [c, a, e, last]]) => {
|
|
206
|
+
const r = by.get(name) ?? { name, source: M.skillSources[name], command: 0, agent: 0, errors: 0, sessions: 0, last: "" };
|
|
207
|
+
r.command += c; r.agent += a; r.errors += e; r.sessions++; if (last > r.last) r.last = last;
|
|
208
|
+
by.set(name, r);
|
|
209
|
+
}));
|
|
210
|
+
const uses = (r: SkillRow) => r.command + r.agent;
|
|
211
|
+
return [...by.values()].sort((a, b) => SKILL_SOURCES.indexOf(a.source) - SKILL_SOURCES.indexOf(b.source) || uses(b) - uses(a) || a.name.localeCompare(b.name));
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// Output per request at level e against level `high` on model m, within the same work: each session's main thread
|
|
215
|
+
// and its subagents apart, where both levels ran at least 5 requests; the median of those ratios, so no long session
|
|
216
|
+
// outweighs the rest, and only when 3 sessions or more have both. n counts those sessions.
|
|
217
|
+
export function vsHigh(F: Fact[], m: number, e: number, high: number): { r: number | null; n: number } {
|
|
218
|
+
const by = new Map<string, { s: number; q: number[]; o: number[] }>();
|
|
219
|
+
for (const f of F) {
|
|
220
|
+
if (f.m !== m || (f.e !== e && f.e !== high)) continue;
|
|
221
|
+
const key = `${f.s}|${f.sub}`, u = by.get(key) ?? by.set(key, { s: f.s, q: [0, 0], o: [0, 0] }).get(key)!, j = f.e === e ? 0 : 1;
|
|
222
|
+
u.q[j] += f.q; u.o[j] += f.o;
|
|
223
|
+
}
|
|
224
|
+
const pairs = [...by.values()].filter((u) => u.q[0] >= 5 && u.q[1] >= 5 && u.o[1] > 0);
|
|
225
|
+
const n = new Set(pairs.map((u) => u.s)).size;
|
|
226
|
+
if (n < 3) return { r: null, n };
|
|
227
|
+
const ratios = pairs.map((u) => u.o[0] / u.q[0] / (u.o[1] / u.q[1])).sort((a, b) => a - b), mid = ratios.length >> 1;
|
|
228
|
+
return { r: ratios.length % 2 ? ratios[mid] : (ratios[mid - 1] + ratios[mid]) / 2, n };
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// How each model works, from the facts in the window: output per request, the thinking share of output, main-thread
|
|
232
|
+
// requests per owner turn, tool calls per request and the failed share of them, and output speed. A figure needs a base
|
|
233
|
+
// of at least BASE requests, turns or calls, else it is null. Speed counts sessions that ran only this model, subagents
|
|
234
|
+
// included, since the host gives API time per session; it needs at least 3 such sessions.
|
|
235
|
+
export const BASE = 20;
|
|
236
|
+
export type Behavior = { m: number; q: number; main: number; turns: number; calls: number; timed: number; out: number | null; think: number | null; steps: number | null; tools: number | null; fail: number | null; tps: number | null };
|
|
237
|
+
export function behavior(M: Model, F: Fact[]): Behavior[] {
|
|
238
|
+
const only = new Map<number, number>(); // session → its one model, or -1 when it ran several
|
|
239
|
+
for (const f of M.facts) { const m = only.get(f.s); only.set(f.s, m === undefined || m === f.m ? f.m : -1); }
|
|
240
|
+
const sessions = new Set(F.map((f) => f.s));
|
|
241
|
+
return M.models.map((_, m) => {
|
|
242
|
+
const x = F.filter((f) => f.m === m), sum = (k: (f: Fact) => number) => x.reduce((n, f) => n + k(f), 0);
|
|
243
|
+
const q = sum((f) => f.q), main = sum((f) => (f.sub ? 0 : f.q)), o = sum((f) => f.o), turns = sum((f) => f.ot), calls = sum((f) => f.tc);
|
|
244
|
+
const timed = [...sessions].filter((s) => only.get(s) === m).map((s) => M.sessions[s]).filter((s) => s.api > 0);
|
|
245
|
+
const api = timed.reduce((n, s) => n + s.api, 0);
|
|
246
|
+
return {
|
|
247
|
+
m, q, main, turns, calls, timed: timed.length,
|
|
248
|
+
out: q >= BASE ? o / q : null, think: q >= BASE && o ? sum((f) => f.th) / o : null,
|
|
249
|
+
steps: turns >= BASE ? main / turns : null, tools: q >= BASE ? calls / q : null,
|
|
250
|
+
fail: calls >= BASE ? sum((f) => f.te) / calls : null, tps: timed.length >= 3 && api ? timed.reduce((n, s) => n + s.out, 0) / api : null,
|
|
251
|
+
};
|
|
252
|
+
}).filter((b) => b.q);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export const mainLevel = (runs: Run[]) => { const by = new Map<number, number>(); runs.forEach(([e, q]) => by.set(e, (by.get(e) || 0) + q)); return [...by].sort((a, b) => b[1] - a[1])[0][0]; };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { test } from "node:test";
|
|
3
|
+
import { DEFAULTS, parseUrl, toUrl, type UrlState } from "./state.ts";
|
|
4
|
+
|
|
5
|
+
const round = (s: UrlState) => { const u = new URL(toUrl(s), "http://x"); return parseUrl(u.pathname, u.search); };
|
|
6
|
+
|
|
7
|
+
test("the address bar holds the view and every filter, and reads back the same", () => {
|
|
8
|
+
const cases: [Partial<UrlState>, string][] = [
|
|
9
|
+
[{}, "/"],
|
|
10
|
+
[{ view: "sessions", range: "7" }, "/sessions?range=7"],
|
|
11
|
+
[{ view: "subagents", range: "", from: "2026-11-01", to: "2026-11-03", project: "alpha", model: "Opus", effort: "xhigh", metric: "cost" }, "/subagents?from=2026-11-01&to=2026-11-03&project=alpha&model=Opus&effort=xhigh&metric=cost"],
|
|
12
|
+
[{ view: "sessions", sort: "turns", dir: 1, q: "cda fix" }, "/sessions?q=cda+fix&sort=turns&dir=asc"],
|
|
13
|
+
[{ view: "activity", range: "all" }, "/activity?range=all"],
|
|
14
|
+
[{ metric: "cost", split: "kind", heat: "out" }, "/?metric=cost&split=kind&heat=out"],
|
|
15
|
+
[{ split: "project", chart: "share" }, "/?split=project&chart=share"],
|
|
16
|
+
[{ provider: "Codex", split: "provider" }, "/?provider=Codex&split=provider"],
|
|
17
|
+
];
|
|
18
|
+
for (const [patch, url] of cases) {
|
|
19
|
+
const s = { ...DEFAULTS, ...patch };
|
|
20
|
+
assert.equal(toUrl(s), url);
|
|
21
|
+
assert.deepEqual(round(s), s, url);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test("an unknown or broken address falls back to the defaults it cannot read", () => {
|
|
26
|
+
assert.deepEqual(parseUrl("/nope", "?range=9&metric=x&sort=y&dir=up"), DEFAULTS);
|
|
27
|
+
// A custom window needs two valid days in order; otherwise the default range applies.
|
|
28
|
+
assert.deepEqual(parseUrl("/", "?from=2026-11-05&to=2026-11-01"), DEFAULTS);
|
|
29
|
+
assert.deepEqual(parseUrl("/", "?from=2026-11-05"), DEFAULTS);
|
|
30
|
+
assert.equal(parseUrl("/sessions/", "").view, "sessions");
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test("a view a host package adds is routed like a built-in one, and only when it is declared", () => {
|
|
34
|
+
assert.equal(parseUrl("/notes", "", ["notes"]).view, "notes");
|
|
35
|
+
assert.equal(parseUrl("/notes", "").view, "overview");
|
|
36
|
+
assert.equal(toUrl({ ...DEFAULTS, view: "notes", range: "7" }), "/notes?range=7");
|
|
37
|
+
const u = new URL(toUrl({ ...DEFAULTS, view: "notes", project: "alpha" }), "http://x");
|
|
38
|
+
assert.deepEqual([parseUrl(u.pathname, u.search, ["notes"]).view, parseUrl(u.pathname, u.search, ["notes"]).project], ["notes", "alpha"]);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test("the chart form is kept in the address, columns by default", () => {
|
|
42
|
+
assert.equal(parseUrl("/", "").chart, "bar");
|
|
43
|
+
assert.equal(parseUrl("/", "chart=area").chart, "area");
|
|
44
|
+
assert.equal(parseUrl("/", "chart=share").chart, "share");
|
|
45
|
+
assert.equal(parseUrl("/", "chart=pie").chart, "bar");
|
|
46
|
+
assert.equal(toUrl({ ...DEFAULTS, chart: "area" }), "/?chart=area");
|
|
47
|
+
assert.equal(toUrl(DEFAULTS), "/");
|
|
48
|
+
});
|