From c3c95babc66f9caa1ae080dcfad491bf972459be Mon Sep 17 00:00:00 2001 From: skylar taylor-barrick Date: Sun, 8 Nov 2026 21:57:32 -0600 Subject: [PATCH] web: a usage menu, window and phone sheet, with the account limits beside them The top bar's usage menu shows today and the account-wide limits; its details open a tileable window with the day chart, a provider and account filter and the model lines, or a bottom sheet on a phone. Reads are shared by day and scope and pause while the tab is hidden. Model and provider marks come from Lobe Icons (MIT), drawn in one colour. nix/packages/web.nix carries the npm dependency hash for the new lockfile. --- THIRD_PARTY_NOTICES.md | 35 ++ nix/packages/web.nix | 2 +- robot-docs/web.md | 12 + web/package-lock.json | 7 + web/package.json | 1 + web/scripts/api-usage.test.mjs | 82 +++ web/scripts/usage-watch.test.mjs | 526 ++++++++++++++++ web/scripts/usage.test.mjs | 449 ++++++++++++++ web/src/App.svelte | 27 +- web/src/app.css | 17 + web/src/lib/About.svelte | 19 +- web/src/lib/LimitRows.svelte | 347 +++++++++++ web/src/lib/Phone.svelte | 6 +- web/src/lib/UsageIcon.svelte | 32 + web/src/lib/UsageMenu.svelte | 237 ++++++++ web/src/lib/UsageSheet.svelte | 73 +++ web/src/lib/api.ts | 38 ++ web/src/lib/board.svelte.ts | 12 +- web/src/lib/nodes/UsageNode.svelte | 14 + web/src/lib/notes.ts | 1 + web/src/lib/tiles/WindowSlot.svelte | 2 + web/src/lib/tiles/title.ts | 2 + web/src/lib/usage.ts | 562 +++++++++++++++++ web/src/lib/usageIcons.ts | 109 ++++ web/src/lib/usageWatch.ts | 299 ++++++++++ web/src/lib/views/UsageView.svelte | 895 ++++++++++++++++++++++++++++ 26 files changed, 3786 insertions(+), 20 deletions(-) create mode 100644 web/scripts/api-usage.test.mjs create mode 100644 web/scripts/usage-watch.test.mjs create mode 100644 web/scripts/usage.test.mjs create mode 100644 web/src/lib/LimitRows.svelte create mode 100644 web/src/lib/UsageIcon.svelte create mode 100644 web/src/lib/UsageMenu.svelte create mode 100644 web/src/lib/UsageSheet.svelte create mode 100644 web/src/lib/nodes/UsageNode.svelte create mode 100644 web/src/lib/usage.ts create mode 100644 web/src/lib/usageIcons.ts create mode 100644 web/src/lib/usageWatch.ts create mode 100644 web/src/lib/views/UsageView.svelte diff --git a/THIRD_PARTY_NOTICES.md b/THIRD_PARTY_NOTICES.md index 6002d6331..c7f2f5b0a 100644 --- a/THIRD_PARTY_NOTICES.md +++ b/THIRD_PARTY_NOTICES.md @@ -107,6 +107,41 @@ Diffs from The Pierre Computer Company (`@pierre/diffs`, https://diffs.com), Apache License 2.0; Shiki, MIT; KaTeX, MIT; Pele (https://pele.run, by Obsidian), MIT; marked, MIT. The client's about pane lists them with links. +## Lobe icons + +The usage screens draw the mark of a model's or an account's provider +(`web/src/lib/usageIcons.ts`, `web/src/lib/UsageIcon.svelte`): @lobehub's static +SVG icons (https://github.com/lobehub/lobe-icons, https://icons.lobehub.com), +`@lobehub/icons-static-svg` 1.102.0, imported at build time so the bundle carries +only the marks that are drawn. They are used unmodified and painted as masks in +the theme's own colour. The client's about pane lists them with links. + +lobe-icons is distributed under the MIT License: + +``` +MIT License + +Copyright (c) 2023 LobeHub + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +``` + ## Lucide The canvas's key hints (`web/src/lib/Gesture.svelte`) draw four of Lucide's diff --git a/nix/packages/web.nix b/nix/packages/web.nix index 15e22f3de..1c7b859fd 100644 --- a/nix/packages/web.nix +++ b/nix/packages/web.nix @@ -19,7 +19,7 @@ buildNpmPackage { ../../web/src ]; }; - npmDepsHash = "sha256-YXVEKCACdr6F2CxnphjRgwp91f50PUORgXkoUjaA5jk="; + npmDepsHash = "sha256-SB78UAR8GPNl4P1nYsAIRoNJiOR6xJtbR1CxBP6OONE="; installPhase = '' runHook preInstall cp -R dist $out diff --git a/robot-docs/web.md b/robot-docs/web.md index 3ade98fd5..48299a0bd 100644 --- a/robot-docs/web.md +++ b/robot-docs/web.md @@ -26,6 +26,18 @@ In development, `npm run dev` in `web/` proxies `/api` the same way from `$ALBED Live compaction progress appears beside the chat’s animated status face as the current stage, its reported count when available, and elapsed time. It is omitted for older daemons; progress remains status metadata, not transcript content. +Usage (`UsageMenu.svelte`, `views/UsageView.svelte`, `LimitRows.svelte`, `usageWatch.ts`): the top bar's usage button opens a pane under it with today's totals and then the account-wide provider limits, on the same pattern as the about pane: a click elsewhere or Escape closes it and the focus goes back to its button. Its details action, or palette `usage: open`, opens a normal tileable usage window. On a phone the usage button opens a bottom sheet. The menu, window and sheet lead with the totals and share one copy set (`usage.ts`'s `USAGE_COPY`), so the same idea is not worded three ways: today's cache share and failed calls are the sub-lines of the stat tiles, and a failure count takes the danger colour only from `TROUBLED_ERRORS` (one call in twenty) up. Choose today, seven days or thirty days, then all providers, one provider or one exact historical account. The chart and totals include every matching row; model lines and scope choices say when their bounded lists are truncated. Accounts are named by the profiles and account labels recorded with each call, never by current login handles or profile pins. The pane and the phone's sheet are chrome outside a window, so their type, and the limits drawn inside them (the same `LimitRows.svelte` a window shows), reads through `--ui-scale`: each sets `--canvas-scale: var(--ui-scale)` on what it holds. The window's usage view reads through `--canvas-scale` like every other view, so the canvas text size and the window's own zoom both reach it. + +A provider is recorded as `:`, which is not a name: the selector and the totals line read it through one table in `usage.ts` (`PROVIDERS`) that names the endpoints people know (ChatGPT, OpenAI, Anthropic, Ollama, Google, Vertex AI, Bedrock, OpenCode, OpenRouter, DeepSeek, Alibaba, GitHub Copilot) and shows any other endpoint as its own host, port and all. Two endpoints that share a host are told apart by their paths. The terminal's usage view keeps the same table; change both together. Options lead with the provider name, one `` per provider, separated by ` · ` (as every other line separates its parts) from the account or the profiles that used it; an account recorded with no account at all is named by the profiles that made those calls, or "no account" when another account of the provider would otherwise read alike, since a blank after the separator names nothing and two choices that read alike cannot be told apart. Calls recorded with no account and calls recorded under an account named after the profile stay two choices, because they select different rows. A provider with one account offers one choice rather than the same rows twice, and a scope a period no longer reports stays selected under its last good label with "(no use in this period)" rather than falling back to its key. A native `