@talgent/workbench-ui 0.0.0-stage → 0.1.2
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 +15 -2
- package/assets/brand-icons/LICENSE.md +30 -0
- package/assets/brand-icons/README.md +5 -0
- package/assets/brand-icons/figma.svg +1 -0
- package/assets/brand-icons/github.svg +1 -0
- package/assets/brand-icons/linear.svg +1 -0
- package/assets/brand-icons/notion.svg +1 -0
- package/assets/brand-icons/sentry.svg +1 -0
- package/assets/brand-icons/slack.svg +1 -0
- package/assets/fonts/Inter-OFL.txt +93 -0
- package/assets/fonts/inter-latin.woff2 +0 -0
- package/components/agent/agent-icon.css +14 -0
- package/components/agent/agent-icon.tsx +14 -0
- package/components/analytics/chart-geometry.ts +95 -0
- package/components/analytics/dashboard-charts.tsx +136 -0
- package/components/analytics/model-usage-chart.tsx +84 -0
- package/components/analytics/token-breakdown.css +13 -0
- package/components/analytics/token-breakdown.tsx +23 -0
- package/components/analytics/token-report.tsx +57 -0
- package/components/analytics/work-usage/turn-timeline.tsx +98 -0
- package/components/analytics/work-usage/turns.ts +170 -0
- package/components/analytics/work-usage/work-status.ts +36 -0
- package/components/analytics/work-usage/work-usage-reader.tsx +122 -0
- package/components/analytics/work-usage/work-usage.css +48 -0
- package/components/auth/auth-gate.tsx +44 -0
- package/components/chat/message-input.tsx +105 -0
- package/components/composer/permission-mode-list.tsx +15 -0
- package/components/composer/prompt-bar-controls.tsx +77 -0
- package/components/composer/prompt-bar.tsx +45 -0
- package/components/composer/skill-completion.css +27 -0
- package/components/composer/skill-completion.tsx +49 -0
- package/components/composer/use-slash-completion.tsx +69 -0
- package/components/composer/work-start.css +133 -0
- package/components/feedback/toast-region.css +2 -0
- package/components/feedback/toast-region.tsx +15 -0
- package/components/files/file-facts.tsx +16 -0
- package/components/files/file-section.tsx +181 -0
- package/components/markdown.tsx +144 -0
- package/components/marketplace/connector-pages.tsx +166 -0
- package/components/marketplace/marketplace-icons.tsx +66 -0
- package/components/marketplace/marketplace-shared.tsx +43 -0
- package/components/marketplace/marketplace-shell.tsx +32 -0
- package/components/marketplace/marketplace.css +97 -0
- package/components/marketplace/parameter-fields.tsx +46 -0
- package/components/marketplace/plugin-list.tsx +84 -0
- package/components/marketplace/plugin-page.tsx +133 -0
- package/components/marketplace/provider-pages.tsx +120 -0
- package/components/preview/file-format.ts +75 -0
- package/components/preview/file-preview.tsx +153 -0
- package/components/preview/preview-verdict.ts +44 -0
- package/components/preview/preview.css +19 -0
- package/components/preview/text-preview.tsx +174 -0
- package/components/profile/provider-callback.tsx +43 -0
- package/components/profile/work-agent-appearance.tsx +109 -0
- package/components/profile/work-agent-soul.tsx +76 -0
- package/components/rail/rail-section.tsx +20 -0
- package/components/rail/rail.css +19 -0
- package/components/rail/use-expand-on-change.ts +18 -0
- package/components/session/startup-progress.css +77 -0
- package/components/session/startup-progress.tsx +103 -0
- package/components/session/work-permission-control.tsx +45 -0
- package/components/session/work-thinking-control.tsx +52 -0
- package/components/shell/account-menu.tsx +134 -0
- package/components/shell/app-shell.tsx +148 -0
- package/components/shell/core-reading-views.tsx +26 -0
- package/components/shell/core-reading.tsx +17 -0
- package/components/shell/document-title.tsx +11 -0
- package/components/shell/entry-shell.ts +39 -0
- package/components/shell/file-reading.tsx +22 -0
- package/components/shell/page-layout.tsx +7 -0
- package/components/shell/reading-context.ts +41 -0
- package/components/shell/reading-panel.css +67 -0
- package/components/shell/reading-panel.tsx +74 -0
- package/components/shell/sidebar-parts.tsx +38 -0
- package/components/work/context-rail.css +61 -0
- package/components/work/conversation-unavailable.css +6 -0
- package/components/work/conversation-unavailable.tsx +11 -0
- package/components/work/subagent-item.tsx +42 -0
- package/components/work/subagents-section.css +31 -0
- package/components/work/subagents-section.tsx +40 -0
- package/components/work/token-usage.tsx +28 -0
- package/components/work/tool-message-detail.tsx +39 -0
- package/components/work/tool-output-preview.tsx +52 -0
- package/components/work/tool-preview-reading.tsx +27 -0
- package/components/work/tool-reading-content.tsx +31 -0
- package/components/work/work-context-rail.tsx +23 -0
- package/components/work/work-conversation.tsx +207 -0
- package/components/work/work-history.tsx +115 -0
- package/components/work/work-interaction.css +38 -0
- package/components/work/work-interaction.tsx +105 -0
- package/components/work/work-message-flow.css +86 -0
- package/components/work/work-message-flow.tsx +352 -0
- package/components/work/work-progress-section.tsx +20 -0
- package/components/work/work-prompt-bar.tsx +82 -0
- package/components/work/work-question-record.tsx +72 -0
- package/components/work/work-snapshot-state.tsx +24 -0
- package/components/work/work-status-control.tsx +54 -0
- package/components/work-start/start-work-launch-state.ts +33 -0
- package/components/work-start/work-start-catalog.tsx +116 -0
- package/components/work-start/work-start-form.tsx +173 -0
- package/components/work-start/work-start-tray.css +40 -0
- package/components/work-start/work-start-tray.tsx +128 -0
- package/hooks/use-debounced.ts +11 -0
- package/hooks/use-work-conversation.ts +125 -0
- package/hooks/use-work-lifecycle-controls.ts +40 -0
- package/hooks/use-work-stream.ts +91 -0
- package/lib/account-service.ts +77 -0
- package/lib/agent-appearance-service.ts +59 -0
- package/lib/agent-icon.ts +26 -0
- package/lib/agent-soul-service.ts +48 -0
- package/lib/agent-work-service.ts +23 -0
- package/lib/client.ts +20 -0
- package/lib/computer-release.ts +30 -0
- package/lib/computer-service.ts +241 -0
- package/lib/dashboard-report.ts +38 -0
- package/lib/dashboard.ts +21 -0
- package/lib/marketplace-catalog.ts +138 -0
- package/lib/marketplace-connections.ts +98 -0
- package/lib/marketplace-plugins.ts +53 -0
- package/lib/marketplace-routes.ts +12 -0
- package/lib/model-vendors.ts +13 -0
- package/lib/name-taken-error.ts +7 -0
- package/lib/notifications.ts +37 -0
- package/lib/permission-modes.ts +25 -0
- package/lib/personal-usage-service.ts +19 -0
- package/lib/personal-work-service.ts +159 -0
- package/lib/plugin-parameters.ts +64 -0
- package/lib/preview-verdict.ts +26 -0
- package/lib/relative-time.ts +11 -0
- package/lib/session.ts +108 -0
- package/lib/share-link.ts +4 -0
- package/lib/stale-build-reload.ts +41 -0
- package/lib/start-work-request.ts +34 -0
- package/lib/startup-progress.ts +9 -0
- package/lib/subagents.ts +12 -0
- package/lib/thinking-levels.ts +2 -0
- package/lib/token-analytics.ts +168 -0
- package/lib/token-usage.ts +64 -0
- package/lib/trace-view-model.ts +292 -0
- package/lib/transport.ts +29 -0
- package/lib/use-now.ts +11 -0
- package/lib/use-work-trace.ts +175 -0
- package/lib/user-display.ts +49 -0
- package/lib/work-conversation.ts +118 -0
- package/lib/work-file-service.ts +118 -0
- package/lib/work-model.ts +38 -0
- package/lib/work-notices.ts +23 -0
- package/lib/work-progress.ts +41 -0
- package/lib/work-projection.ts +122 -0
- package/lib/work-questions.ts +18 -0
- package/lib/work-start-draft.ts +61 -0
- package/lib/work-start-loadout.ts +100 -0
- package/lib/work-start-source.ts +16 -0
- package/lib/work-state-presentation.ts +80 -0
- package/lib/work-stream-source.ts +32 -0
- package/package.json +87 -3
- package/pages/computers/computers-page.tsx +56 -0
- package/pages/computers/connect-computer-page.tsx +92 -0
- package/pages/computers/install-commands.tsx +42 -0
- package/pages/computers/remove-computer-dialog.tsx +33 -0
- package/pages/computers/rename-computer-dialog.tsx +37 -0
- package/pages/computers/room-rules-dialog.tsx +55 -0
- package/pages/login-page.css +33 -0
- package/pages/login-page.tsx +88 -0
- package/pages/login-threads.tsx +51 -0
- package/pages/marketplace-page.tsx +59 -0
- package/pages/profile-page.tsx +68 -0
- package/pages/workbench/library-page.tsx +88 -0
- package/pages/workbench/new-work-page.tsx +24 -0
- package/pages/workbench/person.tsx +13 -0
- package/pages/workbench/personal-work-context.tsx +93 -0
- package/pages/workbench/personal-work-page.tsx +100 -0
- package/pages/workbench/personal-works-page.tsx +36 -0
- package/pages/workbench/share-dialog.tsx +57 -0
- package/pages/workbench/title-dialog.tsx +35 -0
- package/pages/workbench/usage-page.tsx +52 -0
- package/public/assets/brand/talgent-lettering.png +0 -0
- package/public/assets/brand/talgent-logo-page-bg.png +0 -0
- package/public/assets/brand/talgent-logo-white-bg.png +0 -0
- package/public/assets/brand/talgent-mark-page-bg.png +0 -0
- package/public/assets/brand/talgent-mark-white-bg.png +0 -0
- package/public/assets/brand/talgent-mark.png +0 -0
- package/public/assets/product-icons/LICENSE +21 -0
- package/public/assets/product-icons/README.md +13 -0
- package/public/assets/product-icons/anthropic.svg +1 -0
- package/public/assets/product-icons/deepseek.svg +1 -0
- package/public/assets/product-icons/glm.svg +1 -0
- package/public/assets/product-icons/kimi.svg +1 -0
- package/public/assets/product-icons/linear.svg +1 -0
- package/public/assets/product-icons/minimax.svg +1 -0
- package/public/assets/product-icons/notion.svg +1 -0
- package/public/assets/product-icons/openai.svg +1 -0
- package/public/assets/product-icons/qwen.svg +1 -0
- package/styles/base.css +95 -0
- package/styles/fonts.css +14 -0
- package/styles/markdown.css +79 -0
- package/styles/uber-theme.css +96 -0
- package/styles/work-composer.css +222 -0
- package/styles/work-stream.css +343 -0
- package/styles/workbench.css +144 -0
- package/styles/workspace.css +260 -0
- package/test-support/backend.ts +67 -0
- package/test-support/plugin-summary.ts +8 -0
- package/test-support/setup.ts +59 -0
- package/vite-preset.ts +85 -0
package/README.md
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
-
#
|
|
1
|
+
# workbench-ui
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The Agent Workbench's pages, components, hooks, clients and styles. Every web app built on the
|
|
4
|
+
Workbench uses it; each app mounts the pages in its own shell through `EntryShellContext`
|
|
5
|
+
(`components/shell/entry-shell.ts`).
|
|
6
|
+
|
|
7
|
+
An app imports modules by path, such as `@talgent/workbench-ui/lib/client`, its stylesheet
|
|
8
|
+
right after Tailwind (`@import "@talgent/workbench-ui/styles/workbench.css"`), and its Vite
|
|
9
|
+
settings from `vite-preset.ts`: the public icons, bundle splitting, test environment and the
|
|
10
|
+
dev proxy to the core. Test support for apps is in `test-support/`.
|
|
11
|
+
|
|
12
|
+
The package is published as TypeScript source; the app's Vite and Tailwind compile it. Node does
|
|
13
|
+
not strip types from files under `node_modules`, so an app that installs the package from the
|
|
14
|
+
registry loads its Vite config with `--configLoader runner` (on `vite` and `vitest` alike).
|
|
15
|
+
|
|
16
|
+
The package depends only on the core.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# CC0 1.0 Universal
|
|
2
|
+
|
|
3
|
+
## Statement of Purpose
|
|
4
|
+
|
|
5
|
+
The laws of most jurisdictions throughout the world automatically confer exclusive Copyright and Related Rights (defined below) upon the creator and subsequent owner(s) (each and all, an “owner”) of an original work of authorship and/or a database (each, a “Work”).
|
|
6
|
+
|
|
7
|
+
Certain owners wish to permanently relinquish those rights to a Work for the purpose of contributing to a commons of creative, cultural and scientific works (“Commons”) that the public can reliably and without fear of later claims of infringement build upon, modify, incorporate in other works, reuse and redistribute as freely as possible in any form whatsoever and for any purposes, including without limitation commercial purposes. These owners may contribute to the Commons to promote the ideal of a free culture and the further production of creative, cultural and scientific works, or to gain reputation or greater distribution for their Work in part through the use and efforts of others.
|
|
8
|
+
|
|
9
|
+
For these and/or other purposes and motivations, and without any expectation of additional consideration or compensation, the person associating CC0 with a Work (the “Affirmer”), to the extent that he or she is an owner of Copyright and Related Rights in the Work, voluntarily elects to apply CC0 to the Work and publicly distribute the Work under its terms, with knowledge of his or her Copyright and Related Rights in the Work and the meaning and intended legal effect of CC0 on those rights.
|
|
10
|
+
|
|
11
|
+
1. Copyright and Related Rights. A Work made available under CC0 may be protected by copyright and related or neighboring rights (“Copyright and Related Rights”). Copyright and Related Rights include, but are not limited to, the following:
|
|
12
|
+
1. the right to reproduce, adapt, distribute, perform, display, communicate, and translate a Work;
|
|
13
|
+
2. moral rights retained by the original author(s) and/or performer(s);
|
|
14
|
+
3. publicity and privacy rights pertaining to a person’s image or likeness depicted in a Work;
|
|
15
|
+
4. rights protecting against unfair competition in regards to a Work, subject to the limitations in paragraph 4(i), below;
|
|
16
|
+
5. rights protecting the extraction, dissemination, use and reuse of data in a Work;
|
|
17
|
+
6. database rights (such as those arising under Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, and under any national implementation thereof, including any amended or successor version of such directive); and
|
|
18
|
+
7. other similar, equivalent or corresponding rights throughout the world based on applicable law or treaty, and any national implementations thereof.
|
|
19
|
+
|
|
20
|
+
2. Waiver. To the greatest extent permitted by, but not in contravention of, applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and unconditionally waives, abandons, and surrenders all of Affirmer’s Copyright and Related Rights and associated claims and causes of action, whether now known or unknown (including existing as well as future claims and causes of action), in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the “Waiver”). Affirmer makes the Waiver for the benefit of each member of the public at large and to the detriment of Affirmer’s heirs and successors, fully intending that such Waiver shall not be subject to revocation, rescission, cancellation, termination, or any other legal or equitable action to disrupt the quiet enjoyment of the Work by the public as contemplated by Affirmer’s express Statement of Purpose.
|
|
21
|
+
|
|
22
|
+
3. Public License Fallback. Should any part of the Waiver for any reason be judged legally invalid or ineffective under applicable law, then the Waiver shall be preserved to the maximum extent permitted taking into account Affirmer’s express Statement of Purpose. In addition, to the extent the Waiver is so judged Affirmer hereby grants to each affected person a royalty-free, non transferable, non sublicensable, non exclusive, irrevocable and unconditional license to exercise Affirmer’s Copyright and Related Rights in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the “License”). The License shall be deemed effective as of the date CC0 was applied by Affirmer to the Work. Should any part of the License for any reason be judged legally invalid or ineffective under applicable law, such partial invalidity or ineffectiveness shall not invalidate the remainder of the License, and in such case Affirmer hereby affirms that he or she will not (i) exercise any of his or her remaining Copyright and Related Rights in the Work or (ii) assert any associated claims and causes of action with respect to the Work, in either case contrary to Affirmer’s express Statement of Purpose.
|
|
23
|
+
|
|
24
|
+
4. Limitations and Disclaimers.
|
|
25
|
+
1. No trademark or patent rights held by Affirmer are waived, abandoned, surrendered, licensed or otherwise affected by this document.
|
|
26
|
+
2. Affirmer offers the Work as-is and makes no representations or warranties of any kind concerning the Work, express, implied, statutory or otherwise, including without limitation warranties of title, merchantability, fitness for a particular purpose, non infringement, or the absence of latent or other defects, accuracy, or the present or absence of errors, whether or not discoverable, all to the greatest extent permissible under applicable law.
|
|
27
|
+
3. Affirmer disclaims responsibility for clearing rights of other persons that may apply to the Work or any use thereof, including without limitation any person’s Copyright and Related Rights in the Work. Further, Affirmer disclaims responsibility for obtaining any necessary consents, permissions or other rights required for any use of the Work.
|
|
28
|
+
4. Affirmer understands and acknowledges that Creative Commons is not a party to this document and has no duty or obligation with respect to this CC0 or use of the Work.
|
|
29
|
+
|
|
30
|
+
For more information, please see <https://creativecommons.org/publicdomain/zero/1.0/>.
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Brand icons
|
|
2
|
+
|
|
3
|
+
Brand marks from [Simple Icons](https://simpleicons.org/) 14.0.0, released under CC0 1.0 (see `LICENSE.md`).
|
|
4
|
+
They identify known services in Marketplace; the brand-to-item mapping lives in
|
|
5
|
+
`components/marketplace/marketplace-icons.tsx`. Brand names and marks remain their owners' trademarks.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Figma</title><path d="M15.852 8.981h-4.588V0h4.588c2.476 0 4.49 2.014 4.49 4.49s-2.014 4.491-4.49 4.491zM12.735 7.51h3.117c1.665 0 3.019-1.355 3.019-3.019s-1.355-3.019-3.019-3.019h-3.117V7.51zm0 1.471H8.148c-2.476 0-4.49-2.014-4.49-4.49S5.672 0 8.148 0h4.588v8.981zm-4.587-7.51c-1.665 0-3.019 1.355-3.019 3.019s1.354 3.02 3.019 3.02h3.117V1.471H8.148zm4.587 15.019H8.148c-2.476 0-4.49-2.014-4.49-4.49s2.014-4.49 4.49-4.49h4.588v8.98zM8.148 8.981c-1.665 0-3.019 1.355-3.019 3.019s1.355 3.019 3.019 3.019h3.117V8.981H8.148zM8.172 24c-2.489 0-4.515-2.014-4.515-4.49s2.014-4.49 4.49-4.49h4.588v4.441c0 2.503-2.047 4.539-4.563 4.539zm-.024-7.51a3.023 3.023 0 0 0-3.019 3.019c0 1.665 1.365 3.019 3.044 3.019 1.705 0 3.093-1.376 3.093-3.068v-2.97H8.148zm7.704 0h-.098c-2.476 0-4.49-2.014-4.49-4.49s2.014-4.49 4.49-4.49h.098c2.476 0 4.49 2.014 4.49 4.49s-2.014 4.49-4.49 4.49zm-.097-7.509c-1.665 0-3.019 1.355-3.019 3.019s1.355 3.019 3.019 3.019h.098c1.665 0 3.019-1.355 3.019-3.019s-1.355-3.019-3.019-3.019h-.098z"/></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>GitHub</title><path d="M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12"/></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Linear</title><path d="M2.886 4.18A11.982 11.982 0 0 1 11.99 0C18.624 0 24 5.376 24 12.009c0 3.64-1.62 6.903-4.18 9.105L2.887 4.18ZM1.817 5.626l16.556 16.556c-.524.33-1.075.62-1.65.866L.951 7.277c.247-.575.537-1.126.866-1.65ZM.322 9.163l14.515 14.515c-.71.172-1.443.282-2.195.322L0 11.358a12 12 0 0 1 .322-2.195Zm-.17 4.862 9.823 9.824a12.02 12.02 0 0 1-9.824-9.824Z"/></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Notion</title><path d="M4.459 4.208c.746.606 1.026.56 2.428.466l13.215-.793c.28 0 .047-.28-.046-.326L17.86 1.968c-.42-.326-.981-.7-2.055-.607L3.01 2.295c-.466.046-.56.28-.374.466zm.793 3.08v13.904c0 .747.373 1.027 1.214.98l14.523-.84c.841-.046.935-.56.935-1.167V6.354c0-.606-.233-.933-.748-.887l-15.177.887c-.56.047-.747.327-.747.933zm14.337.745c.093.42 0 .84-.42.888l-.7.14v10.264c-.608.327-1.168.514-1.635.514-.748 0-.935-.234-1.495-.933l-4.577-7.186v6.952L12.21 19s0 .84-1.168.84l-3.222.186c-.093-.186 0-.653.327-.746l.84-.233V9.854L7.822 9.76c-.094-.42.14-1.026.793-1.073l3.456-.233 4.764 7.279v-6.44l-1.215-.139c-.093-.514.28-.887.747-.933zM1.936 1.035l13.31-.98c1.634-.14 2.055-.047 3.082.7l4.249 2.986c.7.513.934.653.934 1.213v16.378c0 1.026-.373 1.634-1.68 1.726l-15.458.934c-.98.047-1.448-.093-1.962-.747l-3.129-4.06c-.56-.747-.793-1.306-.793-1.96V2.667c0-.839.374-1.54 1.447-1.632z"/></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Sentry</title><path d="M13.91 2.505c-.873-1.448-2.972-1.448-3.844 0L6.904 7.92a15.478 15.478 0 0 1 8.53 12.811h-2.221A13.301 13.301 0 0 0 5.784 9.814l-2.926 5.06a7.65 7.65 0 0 1 4.435 5.848H2.194a.365.365 0 0 1-.298-.534l1.413-2.402a5.16 5.16 0 0 0-1.614-.913L.296 19.275a2.182 2.182 0 0 0 .812 2.999 2.24 2.24 0 0 0 1.086.288h6.983a9.322 9.322 0 0 0-3.845-8.318l1.11-1.922a11.47 11.47 0 0 1 4.95 10.24h5.915a17.242 17.242 0 0 0-7.885-15.28l2.244-3.845a.37.37 0 0 1 .504-.13c.255.14 9.75 16.708 9.928 16.9a.365.365 0 0 1-.327.543h-2.287c.029.612.029 1.223 0 1.831h2.297a2.206 2.206 0 0 0 1.922-3.31z"/></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Slack</title><path d="M5.042 15.165a2.528 2.528 0 0 1-2.52 2.523A2.528 2.528 0 0 1 0 15.165a2.527 2.527 0 0 1 2.522-2.52h2.52v2.52zM6.313 15.165a2.527 2.527 0 0 1 2.521-2.52 2.527 2.527 0 0 1 2.521 2.52v6.313A2.528 2.528 0 0 1 8.834 24a2.528 2.528 0 0 1-2.521-2.522v-6.313zM8.834 5.042a2.528 2.528 0 0 1-2.521-2.52A2.528 2.528 0 0 1 8.834 0a2.528 2.528 0 0 1 2.521 2.522v2.52H8.834zM8.834 6.313a2.528 2.528 0 0 1 2.521 2.521 2.528 2.528 0 0 1-2.521 2.521H2.522A2.528 2.528 0 0 1 0 8.834a2.528 2.528 0 0 1 2.522-2.521h6.312zM18.956 8.834a2.528 2.528 0 0 1 2.522-2.521A2.528 2.528 0 0 1 24 8.834a2.528 2.528 0 0 1-2.522 2.521h-2.522V8.834zM17.688 8.834a2.528 2.528 0 0 1-2.523 2.521 2.527 2.527 0 0 1-2.52-2.521V2.522A2.527 2.527 0 0 1 15.165 0a2.528 2.528 0 0 1 2.523 2.522v6.312zM15.165 18.956a2.528 2.528 0 0 1 2.523 2.522A2.528 2.528 0 0 1 15.165 24a2.527 2.527 0 0 1-2.52-2.522v-2.522h2.52zM15.165 17.688a2.527 2.527 0 0 1-2.52-2.523 2.526 2.526 0 0 1 2.52-2.52h6.313A2.527 2.527 0 0 1 24 15.165a2.528 2.528 0 0 1-2.522 2.523h-6.313z"/></svg>
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
Copyright 2020 The Inter Project Authors (https://github.com/rsms/inter)
|
|
2
|
+
|
|
3
|
+
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
|
4
|
+
This license is copied below, and is also available with a FAQ at:
|
|
5
|
+
https://scripts.sil.org/OFL
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
-----------------------------------------------------------
|
|
9
|
+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
|
10
|
+
-----------------------------------------------------------
|
|
11
|
+
|
|
12
|
+
PREAMBLE
|
|
13
|
+
The goals of the Open Font License (OFL) are to stimulate worldwide
|
|
14
|
+
development of collaborative font projects, to support the font creation
|
|
15
|
+
efforts of academic and linguistic communities, and to provide a free and
|
|
16
|
+
open framework in which fonts may be shared and improved in partnership
|
|
17
|
+
with others.
|
|
18
|
+
|
|
19
|
+
The OFL allows the licensed fonts to be used, studied, modified and
|
|
20
|
+
redistributed freely as long as they are not sold by themselves. The
|
|
21
|
+
fonts, including any derivative works, can be bundled, embedded,
|
|
22
|
+
redistributed and/or sold with any software provided that any reserved
|
|
23
|
+
names are not used by derivative works. The fonts and derivatives,
|
|
24
|
+
however, cannot be released under any other type of license. The
|
|
25
|
+
requirement for fonts to remain under this license does not apply
|
|
26
|
+
to any document created using the fonts or their derivatives.
|
|
27
|
+
|
|
28
|
+
DEFINITIONS
|
|
29
|
+
"Font Software" refers to the set of files released by the Copyright
|
|
30
|
+
Holder(s) under this license and clearly marked as such. This may
|
|
31
|
+
include source files, build scripts and documentation.
|
|
32
|
+
|
|
33
|
+
"Reserved Font Name" refers to any names specified as such after the
|
|
34
|
+
copyright statement(s).
|
|
35
|
+
|
|
36
|
+
"Original Version" refers to the collection of Font Software components as
|
|
37
|
+
distributed by the Copyright Holder(s).
|
|
38
|
+
|
|
39
|
+
"Modified Version" refers to any derivative made by adding to, deleting,
|
|
40
|
+
or substituting -- in part or in whole -- any of the components of the
|
|
41
|
+
Original Version, by changing formats or by porting the Font Software to a
|
|
42
|
+
new environment.
|
|
43
|
+
|
|
44
|
+
"Author" refers to any designer, engineer, programmer, technical
|
|
45
|
+
writer or other person who contributed to the Font Software.
|
|
46
|
+
|
|
47
|
+
PERMISSION & CONDITIONS
|
|
48
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
49
|
+
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
|
50
|
+
redistribute, and sell modified and unmodified copies of the Font
|
|
51
|
+
Software, subject to the following conditions:
|
|
52
|
+
|
|
53
|
+
1) Neither the Font Software nor any of its individual components,
|
|
54
|
+
in Original or Modified Versions, may be sold by itself.
|
|
55
|
+
|
|
56
|
+
2) Original or Modified Versions of the Font Software may be bundled,
|
|
57
|
+
redistributed and/or sold with any software, provided that each copy
|
|
58
|
+
contains the above copyright notice and this license. These can be
|
|
59
|
+
included either as stand-alone text files, human-readable headers or
|
|
60
|
+
in the appropriate machine-readable metadata fields within text or
|
|
61
|
+
binary files as long as those fields can be easily viewed by the user.
|
|
62
|
+
|
|
63
|
+
3) No Modified Version of the Font Software may use the Reserved Font
|
|
64
|
+
Name(s) unless explicit written permission is granted by the corresponding
|
|
65
|
+
Copyright Holder. This restriction only applies to the primary font name as
|
|
66
|
+
presented to the users.
|
|
67
|
+
|
|
68
|
+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
|
69
|
+
Software shall not be used to promote, endorse or advertise any
|
|
70
|
+
Modified Version, except to acknowledge the contribution(s) of the
|
|
71
|
+
Copyright Holder(s) and the Author(s) or with their explicit written
|
|
72
|
+
permission.
|
|
73
|
+
|
|
74
|
+
5) The Font Software, modified or unmodified, in part or in whole,
|
|
75
|
+
must be distributed entirely under this license, and must not be
|
|
76
|
+
distributed under any other license. The requirement for fonts to
|
|
77
|
+
remain under this license does not apply to any document created
|
|
78
|
+
using the Font Software.
|
|
79
|
+
|
|
80
|
+
TERMINATION
|
|
81
|
+
This license becomes null and void if any of the above conditions are
|
|
82
|
+
not met.
|
|
83
|
+
|
|
84
|
+
DISCLAIMER
|
|
85
|
+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
86
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
|
87
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
|
88
|
+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
|
89
|
+
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
90
|
+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
|
91
|
+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
92
|
+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
|
93
|
+
OTHER DEALINGS IN THE FONT SOFTWARE.
|
|
Binary file
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/* The Agent color tints the tile and inks the glyph, legible in both themes. */
|
|
2
|
+
.agent-icon {
|
|
3
|
+
--agent-icon-radius: calc(var(--agent-icon-size) * 0.27);
|
|
4
|
+
display: inline-grid;
|
|
5
|
+
flex: none;
|
|
6
|
+
place-items: center;
|
|
7
|
+
width: var(--agent-icon-size);
|
|
8
|
+
height: var(--agent-icon-size);
|
|
9
|
+
border-radius: var(--agent-icon-radius);
|
|
10
|
+
background: color-mix(in oklab, var(--agent-ink) 14%, var(--surface));
|
|
11
|
+
color: color-mix(in oklab, var(--agent-ink) 85%, var(--foreground));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.agent-color-swatch { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 999px; color: #fff; }
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { CSSProperties } from "react";
|
|
2
|
+
import { Bot } from "lucide-react";
|
|
3
|
+
import { agentColors, agentGlyphs, agentIconOf, type AgentIconValue } from "../../lib/agent-icon";
|
|
4
|
+
import "./agent-icon.css";
|
|
5
|
+
|
|
6
|
+
// Decorative: the surrounding control or text names the Agent.
|
|
7
|
+
export function AgentIcon({ icon, size = 24, className }: { icon: Partial<AgentIconValue> | undefined; size?: number; className?: string }) {
|
|
8
|
+
const { glyph, color } = agentIconOf(icon);
|
|
9
|
+
const Glyph = agentGlyphs.find(item => item.id === glyph)?.Icon ?? Bot;
|
|
10
|
+
const style = { "--agent-ink": agentColors[color], "--agent-icon-size": `${size}px` } as CSSProperties;
|
|
11
|
+
return <span aria-hidden="true" className={className ? `agent-icon ${className}` : "agent-icon"} data-glyph={glyph} data-color={color} style={style}>
|
|
12
|
+
<Glyph size={Math.round(size * 0.6)} />
|
|
13
|
+
</span>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
export type TrendSeries<TPoint> = { key: keyof TPoint; label: string; color: string; defaultHidden?: boolean };
|
|
2
|
+
|
|
3
|
+
export function trendPath<TPoint extends { label: string }>(points: TPoint[], key: keyof TPoint, maxValue: number) {
|
|
4
|
+
if (points.length === 1) {
|
|
5
|
+
const y = pointY(numericValue(points[0], key), maxValue).toFixed(2);
|
|
6
|
+
return `M 0.00 ${y} L 100.00 ${y}`;
|
|
7
|
+
}
|
|
8
|
+
return points
|
|
9
|
+
.map((point) => {
|
|
10
|
+
const coords = pointCoords(points, point, key, maxValue);
|
|
11
|
+
return `${points.indexOf(point) === 0 ? "M" : "L"} ${coords.x.toFixed(2)} ${coords.y.toFixed(2)}`;
|
|
12
|
+
})
|
|
13
|
+
.join(" ");
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function pointCoords<TPoint extends { label: string }>(points: TPoint[], point: TPoint, key: keyof TPoint, maxValue: number) {
|
|
17
|
+
const index = points.indexOf(point);
|
|
18
|
+
const x = pointX(points.length, index);
|
|
19
|
+
const y = pointY(numericValue(point, key), maxValue);
|
|
20
|
+
return { x, y };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function numericValue<TPoint>(point: TPoint, key: keyof TPoint): number {
|
|
24
|
+
const value = point[key];
|
|
25
|
+
return typeof value === "number" && Number.isFinite(value) ? value : 0;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function pointX(pointCount: number, index: number) {
|
|
29
|
+
return pointCount <= 1 ? 50 : (index / (pointCount - 1)) * 100;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function pointY(value: number, maxValue: number) {
|
|
33
|
+
return 88 - (value / maxValue) * 72;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function niceAxisMax(value: number) {
|
|
37
|
+
const safeValue = Number.isFinite(value) && value > 0 ? value : 1;
|
|
38
|
+
const step = niceTickStep(safeValue / 4);
|
|
39
|
+
return Math.max(step, Math.ceil(safeValue / step) * step);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function yTickValues(maxValue: number) {
|
|
43
|
+
const step = niceTickStep(maxValue / 4);
|
|
44
|
+
const ticks: number[] = [];
|
|
45
|
+
for (let value = maxValue; value >= 0; value -= step) {
|
|
46
|
+
ticks.push(Number(value.toFixed(6)));
|
|
47
|
+
}
|
|
48
|
+
if (ticks[ticks.length - 1] !== 0) ticks.push(0);
|
|
49
|
+
return ticks;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function niceTickStep(rawStep: number) {
|
|
53
|
+
const safeStep = Number.isFinite(rawStep) && rawStep > 0 ? rawStep : 1;
|
|
54
|
+
const magnitude = 10 ** Math.floor(Math.log10(safeStep));
|
|
55
|
+
const normalized = safeStep / magnitude;
|
|
56
|
+
const niceNormalized = normalized <= 1 ? 1 : normalized <= 2 ? 2 : normalized <= 5 ? 5 : 10;
|
|
57
|
+
return Math.max(1, niceNormalized * magnitude);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function stackedAreaPath<TPoint extends { label: string }>(
|
|
61
|
+
points: TPoint[],
|
|
62
|
+
series: readonly TrendSeries<TPoint>[],
|
|
63
|
+
seriesIndex: number,
|
|
64
|
+
maxValue: number,
|
|
65
|
+
) {
|
|
66
|
+
if (points.length === 1) {
|
|
67
|
+
const point = points[0];
|
|
68
|
+
const top = pointY(cumulativeValue(point, series, seriesIndex), maxValue).toFixed(2);
|
|
69
|
+
const bottom = pointY(cumulativeValue(point, series, seriesIndex - 1), maxValue).toFixed(2);
|
|
70
|
+
return `M 0.00 ${top} L 100.00 ${top} L 100.00 ${bottom} L 0.00 ${bottom} Z`;
|
|
71
|
+
}
|
|
72
|
+
const top = points.map((point, pointIndex) => {
|
|
73
|
+
const value = cumulativeValue(point, series, seriesIndex);
|
|
74
|
+
return `${pointIndex === 0 ? "M" : "L"} ${pointX(points.length, pointIndex).toFixed(2)} ${pointY(value, maxValue).toFixed(2)}`;
|
|
75
|
+
});
|
|
76
|
+
const bottom = [...points].reverse().map((point, reverseIndex) => {
|
|
77
|
+
const originalIndex = points.length - 1 - reverseIndex;
|
|
78
|
+
const value = cumulativeValue(point, series, seriesIndex - 1);
|
|
79
|
+
return `L ${pointX(points.length, originalIndex).toFixed(2)} ${pointY(value, maxValue).toFixed(2)}`;
|
|
80
|
+
});
|
|
81
|
+
return [...top, ...bottom, "Z"].join(" ");
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function cumulativeValue<TPoint>(point: TPoint, series: readonly TrendSeries<TPoint>[], throughIndex: number) {
|
|
85
|
+
if (throughIndex < 0) return 0;
|
|
86
|
+
return series.slice(0, throughIndex + 1).reduce((sum, item) => sum + numericValue(point, item.key), 0);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Labelled buckets for the time axis: at most `max`, a whole number of buckets
|
|
90
|
+
// apart, so the labels are evenly spaced (the last may fall short of the end).
|
|
91
|
+
export function xTickIndices(pointCount: number, max = 5) {
|
|
92
|
+
if (pointCount <= 0) return [];
|
|
93
|
+
const step = Math.max(1, Math.ceil((pointCount - 1) / (max - 1)));
|
|
94
|
+
return Array.from({ length: Math.floor((pointCount - 1) / step) + 1 }, (_, index) => index * step);
|
|
95
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
// HeroUI owns card/control appearance. SVG marks reuse the existing chart geometry.
|
|
2
|
+
import { useState, type ReactNode } from "react";
|
|
3
|
+
import { typographyVariants, Avatar, Button, Card, Chip, Disclosure, Table, Tooltip, Typography } from "@heroui/react";
|
|
4
|
+
import { niceAxisMax, numericValue, pointY, stackedAreaPath, trendPath, xTickIndices, yTickValues } from "./chart-geometry";
|
|
5
|
+
import type { TrendSeries } from "./chart-geometry";
|
|
6
|
+
import { compareMetric, previousReportPeriod, type DashboardReportPeriod } from "../../lib/dashboard-report";
|
|
7
|
+
import { Activity, Archive, ArrowDownToLine, ArrowUpFromLine, Database, DatabaseZap, FilePlus2, MessageCircleQuestion, Sigma, ArrowDownRight, ArrowUpRight, Minus, type LucideIcon } from "lucide-react";
|
|
8
|
+
import { formatDashboardNumber } from "../../lib/dashboard";
|
|
9
|
+
|
|
10
|
+
export function MetricTrend({current, previous, period, snapshot = false, bounds}: {current: number | null; previous: number | null; period: string; snapshot?: boolean; bounds?: DashboardReportPeriod}) {
|
|
11
|
+
const {direction, percent} = compareMetric(current, previous);
|
|
12
|
+
const Icon = direction === "up" || direction === "new" ? ArrowUpRight : direction === "down" ? ArrowDownRight : Minus;
|
|
13
|
+
const text = direction === "unknown" ? "—" : direction === "new" ? "New" : `${percent && Math.abs(percent) < .1 ? "<0.1" : Math.abs(percent ?? 0).toFixed(1)}%`;
|
|
14
|
+
const description = direction === "unknown" ? "Comparison unavailable" : direction === "new" ? "Previous value was zero; percentage change is undefined" : `${direction === "up" ? "Up" : direction === "down" ? "Down" : "Unchanged"} ${text}`;
|
|
15
|
+
const color = direction === "up" || direction === "new" ? "success" : direction === "down" ? "danger" : "default";
|
|
16
|
+
const interval = (range: DashboardReportPeriod) => `${range.start.toISOString().slice(0, 16).replace("T", " ")} – ${range.end.toISOString().slice(0, 16).replace("T", " ")} UTC`;
|
|
17
|
+
return <Tooltip><Tooltip.Trigger className="p-metric-trend" aria-label={`${description} versus previous ${period}`}><Chip size="sm" variant="soft" color={color}><Icon size={13} /><Chip.Label>{text}</Chip.Label></Chip></Tooltip.Trigger><Tooltip.Content><Typography type="body-sm">{description} · vs previous {period}</Typography><Typography type="body-xs">{current === null ? "—" : current.toLocaleString()} vs {previous === null ? "—" : previous.toLocaleString()}{snapshot ? " · period-end snapshots" : " · equal-length windows"}</Typography>{bounds && <><Typography type="body-xs">Current: {interval(bounds)}</Typography><Typography type="body-xs">Previous: {interval(previousReportPeriod(bounds))}</Typography></>}</Tooltip.Content></Tooltip>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function MetricCard({ label, value, hint, icon, comparison }: {label: string; value: string; hint?: string; icon: ReactNode; comparison: Parameters<typeof MetricTrend>[0]}) {
|
|
21
|
+
const icons: Partial<Record<string, LucideIcon>> = { Created: FilePlus2, Active: Activity, Waiting: MessageCircleQuestion, Closed: Archive, Total: Sigma, Input: ArrowDownToLine, "Cache read": Database, "Cache write": DatabaseZap, Output: ArrowUpFromLine };
|
|
22
|
+
const Icon = icons[label];
|
|
23
|
+
return <Card role="group" aria-label={`${label} metric`}><Card.Content><div className="flex items-start gap-3">
|
|
24
|
+
{(Icon || icon) && <Avatar size="sm" variant="soft" color="warning" aria-hidden="true"><Avatar.Fallback>{Icon ? <Icon size={18} strokeWidth={1.75} /> : icon}</Avatar.Fallback></Avatar>}
|
|
25
|
+
<div className="min-w-0 flex-1"><Card.Title role="heading" aria-level={2}>{hint ? <Tooltip><Tooltip.Trigger aria-label={`${label} definition`}>{label}</Tooltip.Trigger><Tooltip.Content>{hint}</Tooltip.Content></Tooltip> : label}</Card.Title>
|
|
26
|
+
<div className="p-metric-value mt-1"><p className={typographyVariants({ type: "h2" }).base()}>{value}</p><MetricTrend {...comparison} /></div>
|
|
27
|
+
</div>
|
|
28
|
+
</div></Card.Content></Card>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// "1 call", not "1 calls": a plural unit reads singular for exactly one.
|
|
32
|
+
const unitOf = (unit: string, value: number) => value === 1 && unit.endsWith("s") ? unit.slice(0, -1) : unit;
|
|
33
|
+
|
|
34
|
+
export function TimeChart<PlotPoint extends {label: string; interval: string}>({ title, points, series, kind = "line", unit, hint, summary, missingValueLabel, formatValue, hover, onHover }: {title: string; points: PlotPoint[]; series: TrendSeries<PlotPoint>[]; kind?: "line" | "area" | "bar"; unit: string; hint?: string; summary?: string; missingValueLabel?: string; /** The hover card's value, in place of the full number and unit. */ formatValue?: (value: number) => string; hover: {index: number; chart: string} | null; onHover: (value: {index: number; chart: string} | null) => void}) {
|
|
35
|
+
const [plotWidth, setPlotWidth] = useState(0);
|
|
36
|
+
const [hidden, setHidden] = useState<string[]>([]);
|
|
37
|
+
const active = series.filter(s => !hidden.includes(String(s.key)));
|
|
38
|
+
const value = (p: PlotPoint, key: keyof PlotPoint) => Number(p[key]) || 0;
|
|
39
|
+
const known = (p: PlotPoint, key: keyof PlotPoint) => typeof p[key] === "number" && Number.isFinite(p[key]);
|
|
40
|
+
const display = (p: PlotPoint, key: keyof PlotPoint) => known(p, key) ? value(p, key).toLocaleString() : (missingValueLabel ?? "—");
|
|
41
|
+
const incomplete = points.some(p => series.some(s => !known(p, s.key)));
|
|
42
|
+
const maximum = niceAxisMax(Math.max(1, ...points.map(p => kind === "area" ? active.reduce((sum, s) => sum + value(p, s.key), 0) : Math.max(...series.map(s => value(p, s.key))))));
|
|
43
|
+
const ticks = yTickValues(maximum);
|
|
44
|
+
const x = (index: number) => (index + .5) * 100 / points.length;
|
|
45
|
+
const total = points.reduce((sum, p) => sum + series.reduce((n, s) => n + value(p, s.key), 0), 0);
|
|
46
|
+
const point = hover ? points[hover.index] : undefined;
|
|
47
|
+
const isSource = hover?.chart === title;
|
|
48
|
+
const selectBucket = (index: number, element: HTMLElement) => {
|
|
49
|
+
setPlotWidth(element.getBoundingClientRect().width);
|
|
50
|
+
if (hover?.index !== index || !isSource) onHover({index, chart: title});
|
|
51
|
+
};
|
|
52
|
+
const selectAt = (event: {clientX: number; currentTarget: HTMLElement}) => {
|
|
53
|
+
const box = event.currentTarget.getBoundingClientRect();
|
|
54
|
+
const fraction = Math.max(0, Math.min(1, (event.clientX - box.left) / box.width));
|
|
55
|
+
selectBucket(Math.min(points.length - 1, Math.floor(fraction * points.length)), event.currentTarget);
|
|
56
|
+
};
|
|
57
|
+
const bandStart = hover ? hover.index * 100 / points.length : 0;
|
|
58
|
+
const bandEnd = hover ? (hover.index + 1) * 100 / points.length : 0;
|
|
59
|
+
return <Card role="group" className="p-plot-card" aria-label={title}>
|
|
60
|
+
<Card.Header><div className="p-section-title"><Card.Title role="heading" aria-level={2}>{hint ? <Tooltip><Tooltip.Trigger aria-label={`${title} definition`}>{title}</Tooltip.Trigger><Tooltip.Content>{hint}</Tooltip.Content></Tooltip> : title}</Card.Title>{summary !== "" && <Chip size="sm">{summary ?? (incomplete ? "Incomplete data" : `${formatDashboardNumber(total)} ${unitOf(unit, total)}`)}</Chip>}</div></Card.Header>
|
|
61
|
+
<Card.Content>
|
|
62
|
+
{incomplete && !missingValueLabel && <Typography type="body-sm" color="muted">Some values are unavailable. Missing values appear as — in the data table.</Typography>}
|
|
63
|
+
{series.length > 1 && <div className="p-chart-legend" role="group" aria-label={`${title} series`}>{series.map(s => {
|
|
64
|
+
const selected = !hidden.includes(String(s.key));
|
|
65
|
+
const lastVisible = active.length === 1 && active[0].key === s.key;
|
|
66
|
+
return <Chip<"button"> key={String(s.key)} size="sm" variant={selected ? "secondary" : "tertiary"} className="p-series-chip" render={props => <button {...props} type="button" />}
|
|
67
|
+
aria-pressed={selected} aria-disabled={lastVisible || undefined} onClick={() => {if (!lastVisible) setHidden(keys => selected ? [...keys, String(s.key)] : keys.filter(k => k !== s.key));}}>
|
|
68
|
+
<span className="p-series-label"><span className="p-series-dot"><svg width="8" height="8" aria-hidden="true"><circle cx="4" cy="4" r="3" fill={selected ? s.color : "none"} stroke={s.color} /></svg></span><span className={typographyVariants({ type: "body-xs", color: selected ? "default" : "muted" }).base()} >{s.label}</span></span>
|
|
69
|
+
</Chip>;
|
|
70
|
+
})}</div>}
|
|
71
|
+
|
|
72
|
+
{points.length ? <Tooltip delay={0} closeDelay={100} isOpen={!!point && isSource} onOpenChange={open => {if (!open && isSource) onHover(null);}}><Tooltip.Trigger className="p-time-plot" role="slider" aria-valuemin={1} aria-valuemax={points.length} aria-valuenow={(hover?.index ?? 0) + 1} aria-valuetext={`${(point ?? points[0]).interval}. ${active.map(s => `${s.label}: ${display(point ?? points[0], s.key)} ${unitOf(unit, numericValue(point ?? points[0], s.key))}`).join(". ")}`} aria-label={`Explore ${title} timeline. Use arrow keys to select a time interval.`}
|
|
73
|
+
onPointerMove={selectAt} onPointerDown={selectAt}
|
|
74
|
+
onFocus={event => selectBucket(hover?.index ?? 0, event.currentTarget)}
|
|
75
|
+
onKeyDown={event => {
|
|
76
|
+
if (["ArrowLeft", "ArrowRight", "Home", "End"].includes(event.key)) {
|
|
77
|
+
event.preventDefault();
|
|
78
|
+
const index = event.key === "Home" ? 0 : event.key === "End" ? points.length - 1 : Math.max(0, Math.min(points.length - 1, (hover?.index ?? 0) + (event.key === "ArrowRight" ? 1 : -1)));
|
|
79
|
+
selectBucket(index, event.currentTarget);
|
|
80
|
+
}
|
|
81
|
+
if (event.key === "Escape") onHover(null);
|
|
82
|
+
}}><div className="p-y-axis">{ticks.map(t => <span className={typographyVariants({ type: "body-xs" }).base()} key={t} style={{top: `${pointY(t, maximum)}%`}}>{formatDashboardNumber(t)}</span>)}</div><svg viewBox="0 0 100 100" preserveAspectRatio="none" role="img" aria-label={`${title}: ${points.length} time buckets. Exact values in View data.`}>
|
|
83
|
+
{point && hover && <rect className="p-chart-time-band" data-interval={point.interval} x={bandStart} y="0" width={bandEnd - bandStart} height="88" fill="var(--accent)" fillOpacity="0.07" />}
|
|
84
|
+
{ticks.map(t => <path key={t} d={`M 0 ${pointY(t, maximum)} H 100`} stroke="var(--separator)" strokeWidth="1" strokeDasharray="3 4" vectorEffect="non-scaling-stroke" />)}
|
|
85
|
+
{kind === "bar" ? points.flatMap((p, i) => active.map((s, j) => {if (!known(p, s.key)) return null; const width = 65 / points.length / active.length; return <rect className="p-bar-mark" data-series={String(s.key)} key={`${i}-${String(s.key)}`} x={(i + .175) * 100 / points.length + j * width} y={pointY(value(p, s.key), maximum)} width={width * .8} height={88 - pointY(value(p, s.key), maximum)} fill={s.color} />;})) : !incomplete && active.map((s, i) => <g key={String(s.key)} transform={points.length > 1 ? `translate(${50 / points.length} 0) scale(${(points.length - 1) / points.length} 1)` : undefined}>{kind === "area" ? <path d={stackedAreaPath(points, active, i, maximum)} fill={s.color} fillOpacity="0.7" /> : <><path d={`${trendPath(points, s.key, maximum)} L 100 88 L 0 88 Z`} fill={s.color} fillOpacity="0.08" /><path d={trendPath(points, s.key, maximum)} stroke={s.color} strokeWidth="2.5" fill="none" strokeLinejoin="round" vectorEffect="non-scaling-stroke" /></>}</g>)}
|
|
86
|
+
{point && hover && <path className="p-chart-time-cursor" d={`M ${x(hover.index)} 0 V 88`} stroke="var(--muted)" strokeWidth="1" strokeDasharray="3 3" vectorEffect="non-scaling-stroke" />}
|
|
87
|
+
</svg></Tooltip.Trigger><Tooltip.Content className="p-chart-hover-tip" placement="top" crossOffset={hover ? (x(hover.index) / 100 - .5) * plotWidth : 0}>
|
|
88
|
+
{point && <><Typography type="body-xs" color="muted" className="p-chart-hover-interval">{point.interval}</Typography><dl className="p-chart-hover-values">{active.map(s => <div key={String(s.key)}><dt className="p-series-label"><span className="p-series-dot"><svg width="8" height="8" aria-hidden="true"><circle cx="4" cy="4" r="3" fill={s.color} /></svg></span>{s.label}</dt><dd>{formatValue && known(point, s.key) ? formatValue(value(point, s.key)) : `${display(point, s.key)} ${unitOf(unit, numericValue(point, s.key))}`}</dd></div>)}</dl></>}
|
|
89
|
+
</Tooltip.Content></Tooltip> : <Typography type="body-sm" className="p-chart-empty">No observations in this window.</Typography>}
|
|
90
|
+
|
|
91
|
+
<div className="p-x-axis">{xTickIndices(points.length).map(i => <Typography type="body-xs" key={i} style={{left: `${x(i)}%`}}>{points[i].label.split(" · ").map(part => <span key={part}>{part}</span>)}</Typography>)}</div>
|
|
92
|
+
<Disclosure><Disclosure.Heading><Button slot="trigger" variant="ghost" size="sm" aria-label={`View ${title} data`}><span className={typographyVariants({ type: "body-xs", color: "muted" }).base()} >View data</span><Disclosure.Indicator /></Button></Disclosure.Heading><Disclosure.Content><Table><Table.ScrollContainer><Table.Content aria-label={`${title} data`}><Table.Header><Table.Column isRowHeader>Time</Table.Column>{series.map(s => <Table.Column key={String(s.key)}>{s.label}</Table.Column>)}</Table.Header><Table.Body>{points.map(p => <Table.Row key={p.label}><Table.Cell>{p.interval}</Table.Cell>{series.map(s => <Table.Cell key={String(s.key)}>{display(p, s.key)}</Table.Cell>)}</Table.Row>)}</Table.Body></Table.Content></Table.ScrollContainer></Table></Disclosure.Content></Disclosure>
|
|
93
|
+
</Card.Content>
|
|
94
|
+
</Card>;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function DistributionChart({ title, data, unit }: {title: string; data: {key?: string; label: string; value: number; color: string}[]; unit: string}) {
|
|
98
|
+
const total = data.reduce((n, d) => n + d.value, 0);
|
|
99
|
+
const [active, setActive] = useState<number | null>(null);
|
|
100
|
+
const [open, setOpen] = useState(false);
|
|
101
|
+
const selected = active === null ? null : data[active];
|
|
102
|
+
const percentage = (value: number) => total ? `${(value / total * 100).toFixed(1)}%` : "0.0%";
|
|
103
|
+
const select = (index: number) => { setActive(index); setOpen(true); };
|
|
104
|
+
return <Card role="group" aria-label={`${title} distribution`}>
|
|
105
|
+
<Card.Header><Card.Title role="heading" aria-level={2}>{title}</Card.Title></Card.Header>
|
|
106
|
+
<Card.Content><div className="p-distribution">
|
|
107
|
+
<Tooltip delay={0} closeDelay={0} isOpen={open} onOpenChange={value => {setOpen(value); if (!value) setActive(null);}}>
|
|
108
|
+
<Tooltip.Trigger className="p-donut" role="slider" aria-valuemin={1} aria-valuemax={Math.max(1, data.length)} aria-valuenow={(active ?? 0) + 1} aria-valuetext={selected ? `${selected.label}: ${selected.value} ${unit}, ${percentage(selected.value)}` : total ? `${total} ${unit}` : "No observations"} aria-label={`${title}: ${data.map(d => `${d.label} ${d.value} (${percentage(d.value)})`).join(", ")}. Use arrow keys to explore.`}
|
|
109
|
+
onFocus={() => {if (data.length) select(0);}}
|
|
110
|
+
onBlur={() => {setOpen(false); setActive(null);}}
|
|
111
|
+
onKeyDown={event => {
|
|
112
|
+
if (["ArrowRight", "ArrowDown", "ArrowLeft", "ArrowUp"].includes(event.key) && data.length) {
|
|
113
|
+
event.preventDefault();
|
|
114
|
+
select(((active ?? 0) + (event.key === "ArrowRight" || event.key === "ArrowDown" ? 1 : -1) + data.length) % data.length);
|
|
115
|
+
}
|
|
116
|
+
if (event.key === "Home" && data.length) {event.preventDefault(); select(0);}
|
|
117
|
+
if (event.key === "End" && data.length) {event.preventDefault(); select(data.length - 1);}
|
|
118
|
+
if (event.key === "Escape") {setOpen(false); setActive(null);}
|
|
119
|
+
}}>
|
|
120
|
+
<svg viewBox="0 0 120 120" aria-hidden="true">
|
|
121
|
+
<circle cx="60" cy="60" r="42" stroke="var(--default)" strokeWidth="24" fill="none" />
|
|
122
|
+
{total > 0 && data.map((d, i) => <circle key={d.key ?? d.label} className="p-donut-slice" data-label={d.label} cx="60" cy="60" r="42" pathLength="100" stroke={d.color}
|
|
123
|
+
strokeWidth={active === i ? 28 : 24} opacity={active === null || active === i ? 1 : .45}
|
|
124
|
+
strokeDasharray={`${Math.max(0, d.value / total * 100 - .8)} 100`}
|
|
125
|
+
strokeDashoffset={-data.slice(0, i).reduce((n, row) => n + row.value / total * 100, 0)} transform="rotate(-90 60 60)" fill="none"
|
|
126
|
+
onPointerEnter={() => select(i)} onClick={() => select(i)} />)}
|
|
127
|
+
</svg>
|
|
128
|
+
<div className="p-donut-total" aria-hidden="true">
|
|
129
|
+
<Typography type="body" weight="semibold">{formatDashboardNumber(selected?.value ?? total)}</Typography>
|
|
130
|
+
</div>
|
|
131
|
+
</Tooltip.Trigger>
|
|
132
|
+
<Tooltip.Content placement="top"><Typography type="body-sm">{selected?.label ?? title}</Typography><Typography type="body-xs">{(selected?.value ?? total).toLocaleString()} {unit} · {percentage(selected?.value ?? total)}</Typography></Tooltip.Content>
|
|
133
|
+
</Tooltip>
|
|
134
|
+
</div><div className="p-donut-legend">{data.map(d => <span className="p-series-label" key={d.key ?? d.label}><span className="p-series-dot"><svg width="8" height="8" aria-hidden="true"><circle cx="4" cy="4" r="3" fill={d.color} /></svg></span><span className={typographyVariants({ type: "body-xs", color: "muted" }).base()} >{d.label}</span></span>)}</div></Card.Content>
|
|
135
|
+
</Card>;
|
|
136
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// Grouped bars: one per model in each window, height its Total Tokens. Hover,
|
|
2
|
+
// focus or tap a bar for that model's four categories and Cache hit rate.
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { typographyVariants, Button, Card, Chip, Disclosure, Table, Tooltip, Typography } from "@heroui/react";
|
|
5
|
+
import { niceAxisMax, pointY, xTickIndices, yTickValues } from "./chart-geometry";
|
|
6
|
+
import { formatDashboardNumber } from "../../lib/dashboard";
|
|
7
|
+
import { tokenTotal, type TokenUsage } from "../../lib/token-usage";
|
|
8
|
+
import { formatCompactTokenCount } from "../../lib/trace-view-model";
|
|
9
|
+
import { TokenBreakdown } from "./token-breakdown";
|
|
10
|
+
|
|
11
|
+
export type ModelUsagePoint = { label: string; interval: string; usage: Record<string, TokenUsage> };
|
|
12
|
+
|
|
13
|
+
export function ModelUsageChart({ points, models, colors }: { points: ModelUsagePoint[]; models: string[]; colors: Record<string, string> }) {
|
|
14
|
+
const [selected, setSelected] = useState<{ bucket: number; model: number } | null>(null);
|
|
15
|
+
const [plotWidth, setPlotWidth] = useState(0);
|
|
16
|
+
const total = (bucket: number, model: number) => { const usage = points[bucket]?.usage[models[model]]; return usage ? tokenTotal(usage) : 0; };
|
|
17
|
+
// Keyboard moves through the bars that exist, in reading order.
|
|
18
|
+
const bars = points.flatMap((_, bucket) => models.flatMap((__, model) => total(bucket, model) > 0 ? [{ bucket, model }] : []));
|
|
19
|
+
const maximum = niceAxisMax(Math.max(1, ...bars.map(bar => total(bar.bucket, bar.model))));
|
|
20
|
+
const ticks = yTickValues(maximum);
|
|
21
|
+
const groupWidth = 100 / Math.max(points.length, 1);
|
|
22
|
+
const barWidth = groupWidth * .8 / Math.max(models.length, 1);
|
|
23
|
+
const barX = (bucket: number, model: number) => bucket * groupWidth + groupWidth * .1 + model * barWidth;
|
|
24
|
+
const grandTotal = bars.reduce((sum, bar) => sum + total(bar.bucket, bar.model), 0);
|
|
25
|
+
const usage = selected ? points[selected.bucket].usage[models[selected.model]] : undefined;
|
|
26
|
+
const select = (bar: { bucket: number; model: number } | undefined, element: Element) => {
|
|
27
|
+
if (!bar) return;
|
|
28
|
+
setPlotWidth(element.getBoundingClientRect().width);
|
|
29
|
+
setSelected(bar);
|
|
30
|
+
};
|
|
31
|
+
const step = (offset: number, element: Element) => {
|
|
32
|
+
const index = selected ? bars.findIndex(bar => bar.bucket === selected.bucket && bar.model === selected.model) : -1;
|
|
33
|
+
select(bars[Math.max(0, Math.min(bars.length - 1, index + offset))], element);
|
|
34
|
+
};
|
|
35
|
+
const describe = (bar: { bucket: number; model: number }) => `${points[bar.bucket].interval}, ${models[bar.model]}: ${total(bar.bucket, bar.model).toLocaleString()} tokens`;
|
|
36
|
+
|
|
37
|
+
return <Card role="group" className="p-plot-card" aria-label="Model usage">
|
|
38
|
+
<Card.Header><div className="p-section-title"><Card.Title role="heading" aria-level={2}>Model usage</Card.Title><Chip size="sm">{formatDashboardNumber(grandTotal)} tokens</Chip></div></Card.Header>
|
|
39
|
+
<Card.Content>
|
|
40
|
+
{models.length > 0 && <div className="p-chart-legend" role="list" aria-label="Models">{models.map(model => <span role="listitem" className="p-series-label" key={model}><span className="p-series-dot"><svg width="8" height="8" aria-hidden="true"><circle cx="4" cy="4" r="3" fill={colors[model]} /></svg></span><span className={typographyVariants({ type: "body-xs" }).base()}>{model}</span></span>)}</div>}
|
|
41
|
+
{bars.length ? <Tooltip delay={0} closeDelay={100} isOpen={Boolean(usage)} onOpenChange={open => { if (!open) setSelected(null); }}>
|
|
42
|
+
<Tooltip.Trigger className="p-time-plot" role="slider" aria-label="Explore Model usage. Use arrow keys to move between bars."
|
|
43
|
+
aria-valuemin={1} aria-valuemax={bars.length} aria-valuenow={selected ? bars.findIndex(bar => bar.bucket === selected.bucket && bar.model === selected.model) + 1 : 1}
|
|
44
|
+
aria-valuetext={describe(selected ?? bars[0])}
|
|
45
|
+
onFocus={event => { if (!selected) select(bars[0], event.currentTarget); }}
|
|
46
|
+
onKeyDown={event => {
|
|
47
|
+
if (["ArrowLeft", "ArrowRight", "Home", "End"].includes(event.key)) {
|
|
48
|
+
event.preventDefault();
|
|
49
|
+
if (event.key === "Home") select(bars[0], event.currentTarget);
|
|
50
|
+
else if (event.key === "End") select(bars.at(-1), event.currentTarget);
|
|
51
|
+
else step(event.key === "ArrowRight" ? 1 : -1, event.currentTarget);
|
|
52
|
+
}
|
|
53
|
+
if (event.key === "Escape") setSelected(null);
|
|
54
|
+
}}>
|
|
55
|
+
<div className="p-y-axis">{ticks.map(tick => <span className={typographyVariants({ type: "body-xs" }).base()} key={tick} style={{ top: `${pointY(tick, maximum)}%` }}>{formatDashboardNumber(tick)}</span>)}</div>
|
|
56
|
+
<svg viewBox="0 0 100 100" preserveAspectRatio="none" role="img" aria-label={`Model usage: ${points.length} time buckets. Exact values in View data.`}>
|
|
57
|
+
{ticks.map(tick => <path key={tick} d={`M 0 ${pointY(tick, maximum)} H 100`} stroke="var(--separator)" strokeWidth="1" strokeDasharray="3 4" vectorEffect="non-scaling-stroke" />)}
|
|
58
|
+
{bars.map(bar => {
|
|
59
|
+
const value = total(bar.bucket, bar.model);
|
|
60
|
+
const active = selected?.bucket === bar.bucket && selected.model === bar.model;
|
|
61
|
+
return <rect key={`${bar.bucket}-${bar.model}`} className="p-bar-mark" data-model={models[bar.model]} x={barX(bar.bucket, bar.model)} y={pointY(value, maximum)} width={barWidth * .85} height={88 - pointY(value, maximum)}
|
|
62
|
+
fill={colors[models[bar.model]]} opacity={!selected || active ? 1 : .45}
|
|
63
|
+
onPointerEnter={event => select(bar, event.currentTarget.closest(".p-time-plot") ?? event.currentTarget)}
|
|
64
|
+
onPointerDown={event => select(bar, event.currentTarget.closest(".p-time-plot") ?? event.currentTarget)} />;
|
|
65
|
+
})}
|
|
66
|
+
</svg>
|
|
67
|
+
</Tooltip.Trigger>
|
|
68
|
+
<Tooltip.Content className="p-chart-hover-tip" placement="top" crossOffset={selected ? ((barX(selected.bucket, selected.model) + barWidth / 2) / 100 - .5) * plotWidth : 0}>
|
|
69
|
+
{selected && usage && <>
|
|
70
|
+
<Typography type="body-xs" color="muted" className="p-chart-hover-interval">{points[selected.bucket].interval}</Typography>
|
|
71
|
+
<p className="p-chart-hover-head"><span className="p-series-label"><span className="p-series-dot"><svg width="8" height="8" aria-hidden="true"><circle cx="4" cy="4" r="3" fill={colors[models[selected.model]]} /></svg></span>{models[selected.model]}</span><strong>{formatCompactTokenCount(tokenTotal(usage))}</strong></p>
|
|
72
|
+
<TokenBreakdown usage={usage} />
|
|
73
|
+
</>}
|
|
74
|
+
</Tooltip.Content>
|
|
75
|
+
</Tooltip> : <Typography type="body-sm" className="p-chart-empty">No observations in this window.</Typography>}
|
|
76
|
+
<div className="p-x-axis">{xTickIndices(points.length).map(index => <Typography type="body-xs" key={index} style={{ left: `${(index + .5) * groupWidth}%` }}>{points[index].label.split(" · ").map(part => <span key={part}>{part}</span>)}</Typography>)}</div>
|
|
77
|
+
<Disclosure><Disclosure.Heading><Button slot="trigger" variant="ghost" size="sm" aria-label="View Model usage data"><span className={typographyVariants({ type: "body-xs", color: "muted" }).base()}>View data</span><Disclosure.Indicator /></Button></Disclosure.Heading><Disclosure.Content>
|
|
78
|
+
<Table><Table.ScrollContainer><Table.Content aria-label="Model usage data"><Table.Header><Table.Column isRowHeader>Time</Table.Column>{models.map(model => <Table.Column key={model}>{model}</Table.Column>)}</Table.Header>
|
|
79
|
+
<Table.Body>{points.map((point, bucket) => <Table.Row key={point.label}><Table.Cell>{point.interval}</Table.Cell>{models.map((model, index) => <Table.Cell key={model}>{total(bucket, index).toLocaleString()}</Table.Cell>)}</Table.Row>)}</Table.Body>
|
|
80
|
+
</Table.Content></Table.ScrollContainer></Table>
|
|
81
|
+
</Disclosure.Content></Disclosure>
|
|
82
|
+
</Card.Content>
|
|
83
|
+
</Card>;
|
|
84
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
.token-breakdown { display: grid; gap: 8px; font-size: 12px; font-variant-numeric: tabular-nums; }
|
|
2
|
+
.token-breakdown>div { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
|
|
3
|
+
.token-breakdown dt { display: flex; align-items: center; gap: 7px; color: var(--muted); }
|
|
4
|
+
.token-breakdown i { display: block; width: 6px; height: 6px; border-radius: 2px; }
|
|
5
|
+
/* The hit-rate ring sits in the swatch column; 8px so its fill stays legible. */
|
|
6
|
+
.token-hit-mark { flex-shrink: 0; margin-inline: -1px; fill: none; stroke-width: 2; stroke: var(--default); }
|
|
7
|
+
.token-hit-mark [data-filled] { stroke: var(--foreground); }
|
|
8
|
+
.token-breakdown dd { font-weight: 500; }
|
|
9
|
+
/* Category tones, shared with any bar of the same categories. */
|
|
10
|
+
[data-token-tone="input"] { background: var(--foreground); }
|
|
11
|
+
[data-token-tone="cacheRead"] { background: color-mix(in oklch,var(--foreground) 52%,var(--surface)); }
|
|
12
|
+
[data-token-tone="cacheWrite"] { background: color-mix(in oklch,var(--foreground) 32%,var(--surface)); }
|
|
13
|
+
[data-token-tone="output"] { background: color-mix(in oklch,var(--foreground) 17%,var(--surface)); }
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { formatCompactTokenCount } from "../../lib/trace-view-model";
|
|
2
|
+
import { cacheHitRate, formatHitRate, tokenCategories, type TokenUsage } from "../../lib/token-usage";
|
|
3
|
+
import "./token-breakdown.css";
|
|
4
|
+
|
|
5
|
+
/** One usage's Cache hit rate and its four categories, as one list. Shared by
|
|
6
|
+
* the Work context card and the usage charts' hover cards. */
|
|
7
|
+
export function TokenBreakdown({ usage, className }: { usage: TokenUsage; className?: string }) {
|
|
8
|
+
const rate = cacheHitRate(usage);
|
|
9
|
+
return <dl className={["token-breakdown", className].filter(Boolean).join(" ")}>
|
|
10
|
+
{rate !== null && <div><dt><HitRateMark rate={rate} />Cache hit rate</dt><dd>{formatHitRate(rate)}</dd></div>}
|
|
11
|
+
{tokenCategories.map(({ key, label }) => <div key={key}><dt><i data-token-tone={key} />{label}</dt><dd>{formatCompactTokenCount(usage[key])}</dd></div>)}
|
|
12
|
+
</dl>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Cache hit rate's legend mark: a small ring filled to the rate. It leads the
|
|
16
|
+
* list in the darkest tone, above the categories' lightening swatches. */
|
|
17
|
+
function HitRateMark({ rate }: { rate: number }) {
|
|
18
|
+
const circumference = 2 * Math.PI * 3;
|
|
19
|
+
return <svg className="token-hit-mark" width="8" height="8" viewBox="0 0 8 8" aria-hidden="true">
|
|
20
|
+
<circle cx="4" cy="4" r="3" />
|
|
21
|
+
<circle cx="4" cy="4" r="3" data-filled="" strokeDasharray={`${circumference * Math.min(Math.max(rate, 0), 1)} ${circumference}`} transform="rotate(-90 4 4)" />
|
|
22
|
+
</svg>;
|
|
23
|
+
}
|