@kabmo-labs/kabmo 0.16.0 → 0.18.0
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 +2 -2
- package/dist/client/index.html +1 -1
- package/dist/client/index.js +552 -471
- package/dist/client/static/js/index-hp75vsv9.css +1 -0
- package/dist/client/static/js/{index-cpydmygd.js → index-tc09dtca.js} +897 -886
- package/package.json +1 -1
- package/src/client/components/common/MarkdownRenderer.tsx +136 -89
- package/src/client/components/common/anchored-menu/index.test.tsx +141 -0
- package/src/client/components/common/anchored-menu/index.tsx +143 -0
- package/src/client/components/common/code-surface/bracket-guide.test.ts +2 -2
- package/src/client/components/common/code-surface/bracket-guide.ts +2 -2
- package/src/client/components/common/code-surface/conflict-markers.ts +5 -5
- package/src/client/components/common/code-surface/extensions.ts +7 -4
- package/src/client/components/common/code-surface/theme.ts +34 -9
- package/src/client/components/common/code-surface/whitespace.test.ts +223 -0
- package/src/client/components/common/code-surface/whitespace.ts +140 -0
- package/src/client/components/common/markdown-review/ReviewPopover.tsx +144 -0
- package/src/client/components/common/markdown-review/ReviewSummary.tsx +108 -0
- package/src/client/components/common/markdown-review/index.tsx +129 -0
- package/src/client/components/common/{server-switcher/index.tsx → server-control/Panel.tsx} +92 -44
- package/src/client/components/common/server-control/index.test.tsx +217 -0
- package/src/client/components/common/server-control/index.tsx +120 -0
- package/src/client/components/layout/desktop-layout/TopNavbar.tsx +8 -50
- package/src/client/components/layout/session-sidebar/CategoryHeader.tsx +42 -21
- package/src/client/components/layout/session-sidebar/CategoryHeader.worktree.test.tsx +36 -17
- package/src/client/components/layout/session-sidebar/CategoryItem.tsx +8 -7
- package/src/client/components/layout/session-sidebar/about-modal/NotesDialog.tsx +94 -0
- package/src/client/components/layout/session-sidebar/about-modal/VersionLine.test.tsx +68 -0
- package/src/client/components/layout/session-sidebar/about-modal/VersionLine.tsx +36 -0
- package/src/client/components/layout/session-sidebar/about-modal/index.tsx +57 -34
- package/src/client/components/layout/session-sidebar/modern/WorkspaceHeader.tsx +28 -10
- package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +7 -6
- package/src/client/components/layout/session-sidebar/modern/workspace-header.test.tsx +1 -1
- package/src/client/components/layout/update-popup/ReleaseNotes.tsx +8 -3
- package/src/client/components/layout/update-popup/index.tsx +5 -1
- package/src/client/components/mobile/mobile-main-view/Header.tsx +6 -12
- package/src/client/components/mobile/mobile-right-sidebar/FullEditor.tsx +13 -15
- package/src/client/components/mobile/mobile-right-sidebar/Header.tsx +23 -1
- package/src/client/components/mobile/mobile-right-sidebar/MissingFileBanner.tsx +30 -0
- package/src/client/components/mobile/mobile-right-sidebar/PreviewScroller.tsx +18 -2
- package/src/client/components/mobile/mobile-session-sidebar/Header.tsx +41 -13
- package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +22 -67
- package/src/client/components/mobile/mobile-session-sidebar/ItemMenu.tsx +110 -0
- package/src/client/components/settings/Modal.tsx +9 -3
- package/src/client/components/settings/ProjectSelectorDropdown.tsx +19 -9
- package/src/client/components/settings/SettingsSidebarList.tsx +20 -0
- package/src/client/components/settings/categories/AgentSettings.tsx +38 -44
- package/src/client/components/settings/categories/CommandSettings.tsx +2 -2
- package/src/client/components/settings/categories/McpSettings.tsx +4 -21
- package/src/client/components/settings/categories/OmpSettings.tsx +147 -194
- package/src/client/components/settings/categories/ProjectSettings.tsx +122 -156
- package/src/client/components/settings/categories/SkillCatalogSettings.tsx +220 -260
- package/src/client/components/settings/categories/SkillSettings.tsx +8 -5
- package/src/client/components/settings/categories/TokenUsageSettings.tsx +211 -229
- package/src/client/components/settings/categories/agent-settings/DetailPane.tsx +229 -237
- package/src/client/components/settings/categories/agent-settings/ModelPicker.tsx +71 -0
- package/src/client/components/settings/categories/agent-settings/SidebarList.tsx +14 -2
- package/src/client/components/settings/categories/agent-settings/levels.ts +38 -0
- package/src/client/components/settings/categories/behavior-settings/Editor.tsx +27 -7
- package/src/client/components/settings/categories/chat-settings/ToolRenderSection.tsx +23 -5
- package/src/client/components/settings/categories/command-settings/DetailPane.tsx +75 -33
- package/src/client/components/settings/categories/command-settings/SidebarList.tsx +7 -0
- package/src/client/components/settings/categories/mcp-settings/DetailPane.tsx +91 -76
- package/src/client/components/settings/categories/mcp-settings/EnvVarsSection.tsx +83 -0
- package/src/client/components/settings/categories/mcp-settings/ImportModal.tsx +26 -13
- package/src/client/components/settings/categories/mcp-settings/SidebarList.tsx +20 -0
- package/src/client/components/settings/categories/omp-settings/ConfigTabs.tsx +97 -36
- package/src/client/components/settings/categories/omp-settings/EngineHeader.tsx +151 -0
- package/src/client/components/settings/categories/omp-settings/ExtensionsPanel.tsx +68 -32
- package/src/client/components/settings/categories/omp-settings/OrderedChips.tsx +119 -0
- package/src/client/components/settings/categories/omp-settings/PresetBar.tsx +14 -7
- package/src/client/components/settings/categories/omp-settings/RoleEditor.tsx +15 -6
- package/src/client/components/settings/categories/omp-settings/RowEditor.tsx +165 -226
- package/src/client/components/settings/categories/omp-settings/types.ts +28 -0
- package/src/client/components/settings/categories/project-settings/AccentPalette.test.tsx +189 -0
- package/src/client/components/settings/categories/project-settings/AccentPalette.tsx +156 -24
- package/src/client/components/settings/categories/project-settings/AddProjectModal.tsx +175 -0
- package/src/client/components/settings/categories/project-settings/DeleteProjectModal.tsx +107 -0
- package/src/client/components/settings/categories/project-settings/DetailsForm.tsx +40 -24
- package/src/client/components/settings/categories/project-settings/DetailsHeader.tsx +17 -7
- package/src/client/components/settings/categories/project-settings/IconGrid.tsx +164 -69
- package/src/client/components/settings/categories/project-settings/ModelDropdown.test.tsx +122 -0
- package/src/client/components/settings/categories/project-settings/ModelDropdown.tsx +124 -53
- package/src/client/components/settings/categories/project-settings/NameInput.tsx +57 -11
- package/src/client/components/settings/categories/project-settings/PathField.tsx +122 -0
- package/src/client/components/settings/categories/project-settings/SidebarList.tsx +100 -59
- package/src/client/components/settings/categories/skill-catalog/GitImportPanel.tsx +253 -0
- package/src/client/components/settings/categories/skill-catalog/SkillCard.tsx +89 -0
- package/src/client/components/settings/categories/skill-catalog/SourceRail.tsx +122 -0
- package/src/client/components/settings/categories/skill-catalog/catalog-ui.test.tsx +179 -0
- package/src/client/components/settings/categories/skill-settings/DetailHeader.tsx +236 -0
- package/src/client/components/settings/categories/skill-settings/DetailPane.tsx +164 -239
- package/src/client/components/settings/categories/skill-settings/InstructionsEditor.tsx +84 -0
- package/src/client/components/settings/categories/skill-settings/SidebarList.tsx +144 -87
- package/src/client/components/settings/categories/skill-settings/pane.test.tsx +188 -0
- package/src/client/components/settings/categories/skill-settings/row-meta.ts +58 -0
- package/src/client/components/settings/categories/token-usage-settings/Breakdown.tsx +242 -102
- package/src/client/components/settings/categories/token-usage-settings/Chart.tsx +130 -56
- package/src/client/components/settings/categories/token-usage-settings/Controls.tsx +135 -0
- package/src/client/components/settings/categories/token-usage-settings/MetricsGrid.tsx +55 -33
- package/src/client/components/settings/categories/token-usage-settings/Provenance.tsx +59 -0
- package/src/client/components/settings/categories/token-usage-settings/panel.test.tsx +239 -0
- package/src/client/components/workspace/browser-panel/Screencast.test.ts +1 -0
- package/src/client/components/workspace/browser-panel/Screencast.tsx +17 -22
- package/src/client/components/workspace/browser-panel/TabStrip.test.tsx +158 -0
- package/src/client/components/workspace/browser-panel/TabStrip.tsx +90 -0
- package/src/client/components/workspace/browser-panel/index.tsx +50 -4
- package/src/client/components/workspace/browser-toolbar/index.tsx +41 -1
- package/src/client/components/workspace/chat-timeline/ThinkingSection.tsx +3 -1
- package/src/client/components/workspace/chat-timeline/ToolCallingSection.tsx +2 -0
- package/src/client/components/workspace/chat-timeline/block-chrome.test.tsx +13 -2
- package/src/client/components/workspace/chat-timeline/index.tsx +6 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Bash.test.ts +88 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Bash.tsx +24 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Proc.test.ts +46 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Proc.tsx +15 -6
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Read.test.ts +34 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Read.tsx +5 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.test.ts +29 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.tsx +11 -3
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/ArtifactChip.tsx +7 -6
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/card-header.test.ts +24 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/card-header.ts +6 -2
- package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Tui.test.tsx +237 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Tui.tsx +191 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/styles/styles.test.tsx +1 -1
- package/src/client/components/workspace/diff-panel/MergeDiffView.tsx +21 -7
- package/src/client/components/workspace/diff-panel/changes.test.ts +51 -0
- package/src/client/components/workspace/diff-panel/changes.ts +28 -12
- package/src/client/components/workspace/diff-panel/merge.test.ts +28 -0
- package/src/client/components/workspace/diff-panel/merge.ts +21 -1
- package/src/client/components/workspace/editor/Body.tsx +7 -0
- package/src/client/components/workspace/editor/FileDocument.tsx +15 -21
- package/src/client/components/workspace/editor/FilePane.tsx +12 -0
- package/src/client/components/workspace/editor/PreviewPane.tsx +70 -0
- package/src/client/components/workspace/editor/Toolbar.tsx +17 -1
- package/src/client/components/workspace/editor/index.tsx +25 -22
- package/src/client/components/workspace/editor/toolbar-clusters.test.ts +14 -0
- package/src/client/components/workspace/editor/toolbar-clusters.tsx +12 -86
- package/src/client/components/workspace/editor/toolbar-toggle.tsx +53 -0
- package/src/client/components/workspace/editor/toolbar-write-clusters.tsx +112 -0
- package/src/client/components/workspace/editor/viewers/SvgPreview.tsx +18 -2
- package/src/client/components/workspace/editor/viewers/viewers.test.ts +39 -0
- package/src/client/components/workspace/file-explorer/ContextMenu.tsx +18 -5
- package/src/client/components/workspace/file-explorer/Modals.tsx +15 -1
- package/src/client/components/workspace/file-explorer/RowLabel.tsx +68 -0
- package/src/client/components/workspace/file-explorer/TreeItem.tsx +47 -57
- package/src/client/components/workspace/file-explorer/collapsed-chain.test.ts +167 -0
- package/src/client/components/workspace/file-explorer/drag-props.ts +42 -0
- package/src/client/components/workspace/file-explorer/drag.test.ts +43 -0
- package/src/client/components/workspace/file-explorer/index.tsx +21 -20
- package/src/client/components/workspace/git-panel/commit-modal.test.ts +5 -3
- package/src/client/components/workspace/user-browser-panel/AddressBar.tsx +5 -0
- package/src/client/components/workspace/user-browser-panel/AnnotateBar.test.tsx +201 -0
- package/src/client/components/workspace/user-browser-panel/AnnotateBar.tsx +112 -0
- package/src/client/components/workspace/user-browser-panel/AnnotateLayer.test.tsx +225 -0
- package/src/client/components/workspace/user-browser-panel/AnnotateLayer.tsx +217 -0
- package/src/client/components/workspace/user-browser-panel/AnnotateTarget.tsx +99 -0
- package/src/client/components/workspace/user-browser-panel/Frame.tsx +30 -1
- package/src/client/components/workspace/user-browser-panel/index.tsx +81 -2
- package/src/client/data/agent-data/builtin.ts +0 -10
- package/src/client/data/agent-data/orchestrator.ts +0 -45
- package/src/client/data/agent-data/specialist.ts +0 -100
- package/src/client/data/mock/token-usage.ts +170 -120
- package/src/client/data/settings/omp-schema.json +123 -4
- package/src/client/data/settings/project.ts +9 -28
- package/src/client/data/settings/skill.ts +6 -32
- package/src/client/hooks/browser/use-annotate.test.ts +143 -0
- package/src/client/hooks/browser/use-annotate.ts +98 -0
- package/src/client/hooks/browser/use-close-tab.test.ts +148 -0
- package/src/client/hooks/browser/use-close-tab.ts +67 -0
- package/src/client/hooks/browser/use-screencast.ts +13 -1
- package/src/client/hooks/chat/composer/browser-context.test.ts +117 -0
- package/src/client/hooks/chat/composer/browser-context.ts +40 -16
- package/src/client/hooks/chat/composer/items.test.ts +1 -1
- package/src/client/hooks/chat/composer/review-context.ts +38 -0
- package/src/client/hooks/chat/composer/use-draft.test.ts +132 -0
- package/src/client/hooks/chat/composer/use-draft.ts +31 -2
- package/src/client/hooks/chat/timeline/pending-model.ts +28 -0
- package/src/client/hooks/chat/timeline/row-window.test.ts +15 -2
- package/src/client/hooks/editor/use-document-annotations.ts +124 -0
- package/src/client/hooks/editor/use-editor-panel-ui.ts +52 -0
- package/src/client/hooks/editor/use-file-review-mode.ts +35 -0
- package/src/client/hooks/editor/use-preview-review.ts +148 -0
- package/src/client/hooks/settings/agents.ts +149 -0
- package/src/client/hooks/settings/crud-list.test.ts +28 -6
- package/src/client/hooks/settings/crud-list.ts +96 -57
- package/src/client/hooks/settings/omp-config.ts +164 -0
- package/src/client/hooks/settings/projects/index.ts +294 -0
- package/src/client/hooks/settings/projects.test.ts +237 -0
- package/src/client/hooks/settings/skill-catalog.ts +101 -9
- package/src/client/hooks/settings/skill-git-import.ts +153 -0
- package/src/client/hooks/settings/useTokenUsage.ts +125 -0
- package/src/client/hooks/settings/write-feedback.test.ts +104 -0
- package/src/client/hooks/settings/write-feedback.ts +63 -0
- package/src/client/hooks/shell/servers.test.ts +166 -0
- package/src/client/hooks/{desktop → shell}/servers.ts +17 -14
- package/src/client/hooks/ui/markdown-hydration.ts +125 -0
- package/src/client/hooks/ui/updates/index.test.ts +100 -1
- package/src/client/hooks/ui/updates/index.ts +50 -0
- package/src/client/hooks/ui/updates/notes.test.ts +138 -0
- package/src/client/hooks/ui/updates/notes.ts +57 -0
- package/src/client/hooks/ui/updates/shell-download.ts +1 -1
- package/src/client/hooks/ui/updates/shell-update.ts +2 -6
- package/src/client/hooks/workspace/file-row-drag.ts +41 -0
- package/src/client/hooks/workspace/file-tree-actions.ts +25 -1
- package/src/client/hooks/workspace/file-tree-edits.ts +23 -6
- package/src/client/hooks/workspace/root-drop-target.ts +77 -0
- package/src/client/hooks/workspace/unfolded-chains.ts +165 -0
- package/src/client/lib/browser/element-at.test.ts +229 -0
- package/src/client/lib/browser/element-at.ts +139 -0
- package/src/client/lib/desktop/dropped-paths.ts +1 -1
- package/src/client/lib/desktop/titlebar.test.ts +12 -3
- package/src/client/lib/desktop/titlebar.ts +1 -1
- package/src/client/lib/review/client.ts +73 -0
- package/src/client/lib/router/search-params.ts +42 -20
- package/src/client/lib/shell/desktop.ts +117 -0
- package/src/client/lib/shell/servers.ts +75 -0
- package/src/client/lib/shell/transport.ts +216 -0
- package/src/client/main.tsx +9 -0
- package/src/client/tailwind.css +65 -0
- package/src/server/lib/btw/lifecycle.server.ts +2 -2
- package/src/server/lib/db/schema.ts +7 -0
- package/src/server/lib/db/seed-terminal.test.ts +4 -0
- package/src/server/lib/fs/git-merge-conflict.test.ts +14 -1
- package/src/server/lib/omp/config/agent-definitions.test.ts +273 -0
- package/src/server/lib/omp/config/agents.ts +231 -61
- package/src/server/lib/omp/config/definitions.test.ts +9 -105
- package/src/server/lib/omp/config/extensions.ts +16 -7
- package/src/server/lib/omp/config/omp-config-files.test.ts +27 -0
- package/src/server/lib/omp/config/skill-sources.ts +49 -0
- package/src/server/lib/omp/config/skills-git-install.ts +155 -0
- package/src/server/lib/omp/config/skills-git-repo.ts +288 -0
- package/src/server/lib/omp/config/skills-git.test.ts +220 -0
- package/src/server/lib/omp/rpc/constants.test.ts +11 -0
- package/src/server/lib/omp/rpc/constants.ts +15 -0
- package/src/server/lib/omp/rpc/process.ts +11 -14
- package/src/server/lib/omp/rpc/session-commands.ts +6 -3
- package/src/server/lib/omp/rpc/utility-agent-dir.test.ts +134 -0
- package/src/server/lib/omp/rpc/utility-agent-dir.ts +138 -0
- package/src/server/lib/omp/rpc/utility.ts +12 -0
- package/src/server/lib/review/schema.server.ts +45 -0
- package/src/server/lib/review/store.server.ts +138 -0
- package/src/server/lib/terminal/attach-replay.test.ts +132 -0
- package/src/server/lib/terminal/output.test.ts +166 -0
- package/src/server/lib/terminal/output.ts +104 -0
- package/src/server/lib/terminal/runtime.server.ts +5 -0
- package/src/server/lib/terminal/send-result.test.ts +33 -0
- package/src/server/lib/terminal/send-result.ts +32 -0
- package/src/server/lib/terminal/session.server.ts +45 -11
- package/src/server/lib/terminal/store-liveness.test.ts +4 -0
- package/src/server/lib/updates/active-notes.test.ts +149 -0
- package/src/server/lib/updates/active-notes.ts +75 -0
- package/src/server/lib/updates/changelog-file.ts +42 -11
- package/src/server/lib/updates/changelog.test.ts +15 -1
- package/src/server/lib/updates/omp.ts +42 -15
- package/src/server/lib/updates/release-url.ts +27 -1
- package/src/server/lib/usage/index-parse.test.ts +200 -0
- package/src/server/lib/usage/index-parse.ts +178 -0
- package/src/server/lib/usage/index-query.server.ts +248 -0
- package/src/server/lib/usage/index-scan.server.ts +343 -0
- package/src/server/lib/usage/index-schema.server.ts +82 -0
- package/src/server/lib/usage/index.test.ts +234 -0
- package/src/server/lib/usage/providers.server.ts +4 -53
- package/src/server/lib/workspace/project-model.server.test.ts +102 -0
- package/src/server/lib/workspace/project-model.server.ts +47 -0
- package/src/server/lib/workspace/project-patch.server.ts +156 -0
- package/src/server/routes/agent/new.ts +8 -1
- package/src/server/routes/browser/index.ts +3 -0
- package/src/server/routes/browser/stream.ts +31 -2
- package/src/server/routes/browser/tabs.test.ts +94 -0
- package/src/server/routes/browser/tabs.ts +85 -0
- package/src/server/routes/index.ts +2 -0
- package/src/server/routes/review/bindings.ts +11 -0
- package/src/server/routes/review/index.ts +127 -0
- package/src/server/routes/review/routes.test.ts +191 -0
- package/src/server/routes/settings/agents.test.ts +180 -0
- package/src/server/routes/settings/agents.ts +99 -94
- package/src/server/routes/settings/mcp.test.ts +135 -0
- package/src/server/routes/settings/mcp.ts +14 -6
- package/src/server/routes/settings/projects.ts +53 -19
- package/src/server/routes/settings/settings-projects-routes.test.ts +214 -0
- package/src/server/routes/settings/settings-store-routes.test.ts +11 -115
- package/src/server/routes/settings/skills-catalog-actions.ts +195 -0
- package/src/server/routes/settings/skills.test.ts +225 -0
- package/src/server/routes/settings/skills.ts +18 -15
- package/src/server/routes/telemetry/tokens.test.ts +145 -0
- package/src/server/routes/telemetry/tokens.ts +70 -149
- package/src/server/routes/terminal/ws.ts +6 -5
- package/src/server/routes/updates/index.ts +2 -0
- package/src/server/routes/updates/notes.ts +34 -0
- package/src/server/routes/updates/routes.test.ts +49 -0
- package/src/shared/lib/browser/annotate.test.ts +283 -0
- package/src/shared/lib/browser/annotate.ts +231 -0
- package/src/shared/lib/browser/browser-viewer.test.ts +26 -4
- package/src/shared/lib/browser/frame-gate.test.ts +91 -0
- package/src/shared/lib/browser/frame-gate.ts +69 -0
- package/src/shared/lib/browser/frame-params.test.ts +43 -0
- package/src/shared/lib/browser/frame-params.ts +60 -0
- package/src/shared/lib/browser/frame-pipeline.test.ts +132 -0
- package/src/shared/lib/browser/frame-pipeline.ts +80 -0
- package/src/shared/lib/browser/page-context.ts +60 -4
- package/src/shared/lib/browser/snapshot.test.ts +115 -0
- package/src/shared/lib/browser/snapshot.ts +112 -0
- package/src/shared/lib/browser/tab-close.test.ts +74 -0
- package/src/shared/lib/browser/tab-close.ts +77 -0
- package/src/shared/lib/browser/viewer.ts +45 -26
- package/src/shared/lib/chat/timeline/block-chrome.ts +19 -0
- package/src/shared/lib/chat/timeline/tool-render-mode.ts +17 -4
- package/src/shared/lib/chat/tool/artifact.ts +55 -20
- package/src/shared/lib/chat/tool/bash-facts.ts +96 -0
- package/src/shared/lib/chat/tool/minimized.test.ts +98 -0
- package/src/shared/lib/chat/tool/minimized.ts +64 -0
- package/src/shared/lib/chat/tool/summary.test.ts +28 -8
- package/src/shared/lib/chat/tool/summary.ts +3 -32
- package/src/shared/lib/fs/folder-chain.test.ts +81 -1
- package/src/shared/lib/fs/folder-chain.ts +84 -0
- package/src/shared/lib/markdown/blocks/anchor.ts +63 -0
- package/src/shared/lib/markdown/blocks/blocks.test.ts +141 -0
- package/src/shared/lib/markdown/blocks/renderer.ts +120 -0
- package/src/shared/lib/markdown/blocks/scan.ts +100 -0
- package/src/shared/lib/markdown/blocks/types.ts +62 -0
- package/src/shared/lib/markdown/marked.ts +58 -147
- package/src/shared/lib/markdown/math-extensions.ts +168 -0
- package/src/shared/lib/markdown/review/prompt.ts +77 -0
- package/src/shared/lib/markdown/review/reconcile.ts +55 -0
- package/src/shared/lib/markdown/review/review.test.ts +96 -0
- package/src/shared/lib/markdown/xml-sections.test.ts +140 -0
- package/src/shared/lib/markdown/xml-sections.ts +139 -0
- package/src/shared/lib/models/provider/label.ts +57 -0
- package/src/shared/lib/omp/config/agent-file.test.ts +54 -0
- package/src/shared/lib/omp/config/agent-file.ts +43 -0
- package/src/shared/lib/omp/config/row-value.test.ts +95 -0
- package/src/shared/lib/omp/config/row-value.ts +97 -0
- package/src/shared/lib/omp/config/schema.test.ts +66 -0
- package/src/shared/lib/omp/config/schema.ts +6 -0
- package/src/shared/lib/omp/rpc/frame.test.ts +48 -47
- package/src/shared/lib/omp/rpc/frame.ts +49 -40
- package/src/shared/lib/omp/session/job-progress.test.ts +37 -1
- package/src/shared/lib/omp/session/job-progress.ts +31 -0
- package/src/shared/lib/omp/session/proc.ts +5 -0
- package/src/shared/lib/omp/session/wait.ts +5 -0
- package/src/shared/lib/ui/menu-anchor.test.ts +69 -0
- package/src/shared/lib/ui/menu-anchor.ts +89 -0
- package/src/shared/lib/ui/mobile-overlay.ts +61 -0
- package/src/shared/lib/ui/svg-scope.test.ts +97 -0
- package/src/shared/lib/ui/svg-scope.ts +134 -0
- package/src/shared/lib/usage/breakdown.test.ts +197 -0
- package/src/shared/lib/usage/breakdown.ts +241 -0
- package/src/shared/lib/usage/range.test.ts +204 -0
- package/src/shared/lib/usage/range.ts +240 -0
- package/src/shared/lib/usage/view.test.ts +85 -0
- package/src/shared/lib/usage/view.ts +74 -0
- package/src/shared/lib/workspace/project-accent.test.ts +69 -0
- package/src/shared/lib/workspace/project-accent.ts +63 -0
- package/src/shared/lib/workspace/project-icon.ts +40 -0
- package/src/shared/lib/workspace/project-model.test.ts +79 -0
- package/src/shared/lib/workspace/project-model.ts +64 -0
- package/src/shared/types/browser.ts +78 -0
- package/src/shared/types/index.ts +1 -0
- package/src/shared/types/settings/agent.ts +28 -6
- package/src/shared/types/settings/skill.ts +53 -3
- package/src/shared/types/settings/state.ts +4 -3
- package/src/shared/types/settings/write.ts +6 -0
- package/src/shared/types/tokenUsage.ts +128 -21
- package/src/shared/types/updates.ts +20 -0
- package/src/test-support/file-explorer-disk.test-util.ts +25 -1
- package/src/test-support/file-explorer-drag.test-util.ts +88 -0
- package/src/test-support/file-explorer.test-util.ts +47 -47
- package/dist/client/static/js/index-fjnq2z2d.css +0 -1
- package/src/client/components/common/code-surface/indent-guide.ts +0 -104
- package/src/client/components/common/server-switcher/index.test.tsx +0 -150
- package/src/client/components/settings/categories/skill-catalog/AddSourceModal.tsx +0 -133
- package/src/client/hooks/desktop/servers.test.ts +0 -73
- package/src/client/lib/desktop/bridge.ts +0 -203
- package/src/server/lib/omp/session/usage/aggregate-shaping.test.ts +0 -149
- package/src/server/lib/omp/session/usage/aggregate.test.ts +0 -243
- package/src/server/lib/omp/session/usage/aggregate.ts +0 -330
- package/src/server/lib/omp/session/usage/shaping.ts +0 -130
- package/src/shared/lib/code/editor/indent-guide-rule.test.ts +0 -65
- package/src/shared/lib/code/editor/indent-guide-rule.ts +0 -47
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Where a phone's header overlays hang, in ONE place.
|
|
8
|
+
*
|
|
9
|
+
* Both the session picker (`MobileHeader`) and the server panel hang below the
|
|
10
|
+
* 3.5rem title bar, and both used to state the same six numbers inline. They
|
|
11
|
+
* drifted once already: the server panel was drawn `absolute` at 340px, which
|
|
12
|
+
* on a 390px phone runs off the right edge and past the bottom in landscape.
|
|
13
|
+
*
|
|
14
|
+
* Pinned to the VIEWPORT with both insets rather than anchored to the trigger:
|
|
15
|
+
* a trigger is not always near the edge it would have to grow from, and the
|
|
16
|
+
* safe area is a property of the device, not of the button.
|
|
17
|
+
*
|
|
18
|
+
* `100dvh`, not `100vh`: a landscape phone's visible height is the dynamic one,
|
|
19
|
+
* and a `vh` cap left the last rows under the browser's own chrome.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/** The title bar both phone headers draw. */
|
|
23
|
+
export const MOBILE_HEADER_REM = 3.5;
|
|
24
|
+
|
|
25
|
+
/** The gap between that bar and the overlay. */
|
|
26
|
+
const GAP_REM = 0.375;
|
|
27
|
+
|
|
28
|
+
/** The inset kept from the screen's left and right edges. */
|
|
29
|
+
const INSET_REM = 0.75;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* A type alias rather than an interface: preact's `CSSProperties` carries an
|
|
33
|
+
* index signature, and an interface has no implicit one, so the object below is
|
|
34
|
+
* not assignable to a `style` prop otherwise.
|
|
35
|
+
*/
|
|
36
|
+
export type MobileOverlayStyle = {
|
|
37
|
+
top: string;
|
|
38
|
+
left: string;
|
|
39
|
+
right: string;
|
|
40
|
+
maxWidth: string;
|
|
41
|
+
maxHeight: string;
|
|
42
|
+
overflowY: 'auto';
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The style for an overlay hanging below the phone's title bar.
|
|
47
|
+
*
|
|
48
|
+
* `maxWidth` keeps a wide phone from stretching a menu across the screen; the
|
|
49
|
+
* `maxHeight` subtracts the bar, the gap and the safe area, so a landscape
|
|
50
|
+
* phone scrolls the overlay instead of running it past the bottom edge.
|
|
51
|
+
*/
|
|
52
|
+
export function mobileOverlayStyle(maxWidthRem = 18): MobileOverlayStyle {
|
|
53
|
+
return {
|
|
54
|
+
top: `calc(${MOBILE_HEADER_REM}rem + env(safe-area-inset-top, 0px) + ${GAP_REM}rem)`,
|
|
55
|
+
left: `max(${INSET_REM}rem, env(safe-area-inset-left, 0px))`,
|
|
56
|
+
right: `max(${INSET_REM}rem, env(safe-area-inset-right, 0px))`,
|
|
57
|
+
maxWidth: `${maxWidthRem}rem`,
|
|
58
|
+
maxHeight: `calc(100dvh - ${MOBILE_HEADER_REM}rem - env(safe-area-inset-top, 0px) - ${GAP_REM + INSET_REM}rem)`,
|
|
59
|
+
overflowY: 'auto',
|
|
60
|
+
};
|
|
61
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Scoping an SVG's ids, and the two failures it exists to prevent.
|
|
8
|
+
*
|
|
9
|
+
* Both are silent: the picture still draws, just with the wrong paint. These
|
|
10
|
+
* cases therefore assert the REFERENCES, not the declarations — a rename that
|
|
11
|
+
* updated `id="body"` but left `fill="url(#body)"` pointing at the old name
|
|
12
|
+
* would look correct in any test that only counted ids.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { describe, expect, test } from 'bun:test';
|
|
16
|
+
import { nextSvgScopePrefix, scopeSvgIds } from '@/shared/lib/ui/svg-scope';
|
|
17
|
+
|
|
18
|
+
describe('scopeSvgIds', () => {
|
|
19
|
+
test('renames the declaration and every reference shape with it', () => {
|
|
20
|
+
const svg = [
|
|
21
|
+
'<svg xmlns="http://www.w3.org/2000/svg">',
|
|
22
|
+
'<defs>',
|
|
23
|
+
'<linearGradient id="body"><stop offset="0" stop-color="#fff"/></linearGradient>',
|
|
24
|
+
'<clipPath id="cut"><circle cx="1" cy="1" r="1"/></clipPath>',
|
|
25
|
+
'<style>#body { stroke: url(#cut); }</style>',
|
|
26
|
+
'</defs>',
|
|
27
|
+
'<ellipse fill="url(#body)" clip-path="url(#cut)" style="stroke:url(#body)"/>',
|
|
28
|
+
'<use xlink:href="#body"/>',
|
|
29
|
+
'</svg>',
|
|
30
|
+
].join('');
|
|
31
|
+
|
|
32
|
+
const scoped = scopeSvgIds(svg, 'svg7-');
|
|
33
|
+
|
|
34
|
+
expect(scoped).toContain('id="svg7-body"');
|
|
35
|
+
expect(scoped).toContain('id="svg7-cut"');
|
|
36
|
+
expect(scoped).toContain('fill="url(#svg7-body)"');
|
|
37
|
+
expect(scoped).toContain('clip-path="url(#svg7-cut)"');
|
|
38
|
+
expect(scoped).toContain('style="stroke:url(#svg7-body)"');
|
|
39
|
+
expect(scoped).toContain('xlink:href="#svg7-body"');
|
|
40
|
+
// The stylesheet's SELECTOR half is rewritten...
|
|
41
|
+
expect(scoped).toContain('#svg7-body { stroke: url(#svg7-cut); }');
|
|
42
|
+
// ...and no reference still names an unprefixed id (colours like `#fff`
|
|
43
|
+
// are not references, so they are matched by the URI forms only).
|
|
44
|
+
expect(scoped).not.toMatch(/url\(#(?!svg7-)/);
|
|
45
|
+
expect(scoped).not.toMatch(/href="#(?!svg7-)/);
|
|
46
|
+
expect(scoped).toContain('stop-color="#fff"');
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('a stylesheet declaration keeps a hex colour that looks like an id', () => {
|
|
50
|
+
// `#abc` in a DECLARATION is a colour, and an id named `abc` is not a
|
|
51
|
+
// reason to rewrite it: doing so would repaint the shape with nothing.
|
|
52
|
+
const scoped = scopeSvgIds(
|
|
53
|
+
'<svg xmlns="http://www.w3.org/2000/svg"><style>#abc, #def { fill: #abc }</style><rect id="abc"/><rect id="def"/></svg>',
|
|
54
|
+
'svg2-',
|
|
55
|
+
);
|
|
56
|
+
expect(scoped).toContain('#svg2-abc, #svg2-def { fill: #abc }');
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test('a cross-document href is left alone, a same-document fragment is not', () => {
|
|
60
|
+
const scoped = scopeSvgIds(
|
|
61
|
+
'<svg xmlns="http://www.w3.org/2000/svg"><g id="g1"/><use href="other.svg#g1"/><use href="#g1"/></svg>',
|
|
62
|
+
'svg9-',
|
|
63
|
+
);
|
|
64
|
+
expect(scoped).toContain('href="other.svg#g1"');
|
|
65
|
+
expect(scoped).toContain('href="#svg9-g1"');
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test('an ARIA idref LIST is rewritten entry by entry', () => {
|
|
69
|
+
const scoped = scopeSvgIds(
|
|
70
|
+
'<svg xmlns="http://www.w3.org/2000/svg"><title id="t1">t</title><desc id="d1">d</desc><g id="g1" aria-labelledby="t1 d1 g1 outside"/></svg>',
|
|
71
|
+
'svg4-',
|
|
72
|
+
);
|
|
73
|
+
// `outside` is not declared here, so it is not ours to rename.
|
|
74
|
+
expect(scoped).toContain('aria-labelledby="svg4-t1 svg4-d1 svg4-g1 outside"');
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('markup with no id is returned as the SAME string', () => {
|
|
78
|
+
const markup = '<svg xmlns="http://www.w3.org/2000/svg"><rect width="4" height="4"/></svg>';
|
|
79
|
+
expect(scopeSvgIds(markup, 'svg1-')).toBe(markup);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test('an already-scoped document is not prefixed twice', () => {
|
|
83
|
+
const scoped = scopeSvgIds('<svg><rect id="a"/><use href="#a"/></svg>', 'svg5-');
|
|
84
|
+
expect(scopeSvgIds(scoped, 'svg5-')).toBe(scoped);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
describe('nextSvgScopePrefix', () => {
|
|
89
|
+
test('every call is a fresh, XML-name-safe prefix', () => {
|
|
90
|
+
const a = nextSvgScopePrefix();
|
|
91
|
+
const b = nextSvgScopePrefix();
|
|
92
|
+
expect(a).not.toBe(b);
|
|
93
|
+
expect(a).toMatch(/^svg\d+-$/);
|
|
94
|
+
// An id may not begin with a digit, so the prefix cannot either.
|
|
95
|
+
expect(a).toMatch(/^[A-Za-z_]/);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Give an SVG document its own id namespace.
|
|
8
|
+
*
|
|
9
|
+
* Two defects are one defect: an id namespace authored in isolation being
|
|
10
|
+
* shared with the page it is drawn into.
|
|
11
|
+
*
|
|
12
|
+
* 1. **DOMPurify DELETES an id the page already owns.** Its clobbering guard
|
|
13
|
+
* drops an `id`/`name` whose value is `in document` (`SANITIZE_DOM`, on by
|
|
14
|
+
* default), and `document.body`, `document.title` and friends are always in
|
|
15
|
+
* it. Measured in Chromium on a real app icon: the `<linearGradient
|
|
16
|
+
* id="body">` lost its id while `fill="url(#body)"` stayed, so the two
|
|
17
|
+
* shapes that gradient paints — the chicken's body and head — came out
|
|
18
|
+
* filled with the background's dark green instead of cream, and nothing was
|
|
19
|
+
* logged. Prefixing the id is what satisfies the guard. `SANITIZE_NAMED_PROPS`
|
|
20
|
+
* is NOT a substitute: it prefixes the declaration (`user-content-body`) and
|
|
21
|
+
* leaves `url(#body)` pointing at the old name, which is a worse break —
|
|
22
|
+
* measured, `urlRefRewritten: false`.
|
|
23
|
+
* 2. **Two previews share every definition.** `defs` ids are document-scoped,
|
|
24
|
+
* so the same icon opened twice — or a file reusing a name the app's own
|
|
25
|
+
* inline SVG already defines — silently resolves to the FIRST match, and the
|
|
26
|
+
* second picture paints with the first one's gradient.
|
|
27
|
+
*
|
|
28
|
+
* The rewrite is TEXT, deliberately: it runs on markup that has not been
|
|
29
|
+
* sanitized yet, and parsing untrusted SVG into the live document is the thing
|
|
30
|
+
* the sanitizer exists to prevent (a detached `<img src onerror>` still fires).
|
|
31
|
+
* Renaming a string cannot execute anything.
|
|
32
|
+
*
|
|
33
|
+
* Every reference form that can carry an id is rewritten with its declaration,
|
|
34
|
+
* because a rename that missed one would silently point at nothing: `url(#id)`
|
|
35
|
+
* (fill, stroke, filters, clip-path, mask, marker-*, and the same values inside
|
|
36
|
+
* a `<style>` block), `href`/`xlink:href`, `#id` selectors in a `<style>`
|
|
37
|
+
* block, and the ARIA idref lists. Bare-name references are NOT rewritten:
|
|
38
|
+
* SMIL's `begin="id.click"` would be one, and DOMPurify strips `<animate>`/`<set>`
|
|
39
|
+
* outright, so a rewrite there would invent a rule with no example.
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
/** An `id="…"` declaration, any quote style, any spacing around `=`. */
|
|
43
|
+
const ID_DECLARATION = /(\sid\s*=\s*)(["'])([^"']*)\2/g;
|
|
44
|
+
|
|
45
|
+
/** `url(#id)`, quoted or not — how a paint server, filter or clip is referenced. */
|
|
46
|
+
const URL_REFERENCE = /url\(\s*(["']?)#([A-Za-z_][\w-]*)\1\s*\)/g;
|
|
47
|
+
|
|
48
|
+
/** `href="#id"` / `xlink:href="#id"`: a same-document fragment ONLY. */
|
|
49
|
+
const HREF_FRAGMENT = /(\s(?:xlink:href|href)\s*=\s*)(["'])(#[^"']*)\2/g;
|
|
50
|
+
|
|
51
|
+
/** The ARIA attributes whose value is a whitespace-separated list of ids. */
|
|
52
|
+
const ARIA_IDREF =
|
|
53
|
+
/(\saria-(?:labelledby|describedby|controls|owns|flowto|activedescendant|details|errormessage)\s*=\s*)(["'])([^"']*)\2/g;
|
|
54
|
+
|
|
55
|
+
/** A `<style>` element, whose body is stylesheet text rather than markup. */
|
|
56
|
+
const STYLE_ELEMENT = /(<style\b[^>]*>)([\s\S]*?)(<\/style\s*>)/g;
|
|
57
|
+
|
|
58
|
+
/** One stylesheet rule, split so only the SELECTOR half is read for ids. */
|
|
59
|
+
const STYLE_RULE = /([^{}]*)\{([^{}]*)\}/g;
|
|
60
|
+
|
|
61
|
+
/** A `#name` token inside a selector. */
|
|
62
|
+
const SELECTOR_REFERENCE = /#([A-Za-z_][\w-]*)/g;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Prefix every id in `markup` with `prefix`, and rewrite the references that
|
|
66
|
+
* point at them.
|
|
67
|
+
*
|
|
68
|
+
* `prefix` must be unique in the page and XML-name safe (`svg3-`, not `3-`).
|
|
69
|
+
* Markup with no id is returned as the SAME string, so a caller can tell
|
|
70
|
+
* nothing was scoped.
|
|
71
|
+
*/
|
|
72
|
+
export function scopeSvgIds(markup: string, prefix: string): string {
|
|
73
|
+
if (!markup || !markup.includes('id')) return markup;
|
|
74
|
+
|
|
75
|
+
const renamed = new Map<string, string>();
|
|
76
|
+
for (const match of markup.matchAll(ID_DECLARATION)) {
|
|
77
|
+
const id = match[3];
|
|
78
|
+
if (id && !id.startsWith(prefix)) renamed.set(id, `${prefix}${id}`);
|
|
79
|
+
}
|
|
80
|
+
if (renamed.size === 0) return markup;
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
markup
|
|
84
|
+
.replace(ID_DECLARATION, (all, head: string, quote: string, id: string) => {
|
|
85
|
+
const next = renamed.get(id);
|
|
86
|
+
return next ? `${head}${quote}${next}${quote}` : all;
|
|
87
|
+
})
|
|
88
|
+
.replace(URL_REFERENCE, (all, quote: string, name: string) => {
|
|
89
|
+
const next = renamed.get(name);
|
|
90
|
+
return next ? `url(${quote}#${next}${quote})` : all;
|
|
91
|
+
})
|
|
92
|
+
// Only a fragment is ours. `href="other.svg#id"` names an id in ANOTHER
|
|
93
|
+
// document, which this prefix has no authority over.
|
|
94
|
+
.replace(HREF_FRAGMENT, (all, head: string, quote: string, value: string) => {
|
|
95
|
+
const next = renamed.get(value.slice(1));
|
|
96
|
+
return next ? `${head}${quote}#${next}${quote}` : all;
|
|
97
|
+
})
|
|
98
|
+
.replace(ARIA_IDREF, (all, head: string, quote: string, value: string) => {
|
|
99
|
+
const next = value
|
|
100
|
+
.split(/\s+/)
|
|
101
|
+
.map((name) => renamed.get(name) ?? name)
|
|
102
|
+
.join(' ');
|
|
103
|
+
return next === value ? all : `${head}${quote}${next}${quote}`;
|
|
104
|
+
})
|
|
105
|
+
// A stylesheet's DECLARATIONS may hold `url(#id)`, already rewritten
|
|
106
|
+
// above; only its selector half can hold a bare `#id`. Reading the
|
|
107
|
+
// declaration half would rewrite a hex colour that happens to be shaped
|
|
108
|
+
// like a name (`fill:#abc` where an id `abc` exists).
|
|
109
|
+
.replace(STYLE_ELEMENT, (all, open: string, body: string, close: string) => {
|
|
110
|
+
const next = body.replace(STYLE_RULE, (rule, selector: string, declarations: string) => {
|
|
111
|
+
const rewritten = selector.replace(SELECTOR_REFERENCE, (token, name: string) => {
|
|
112
|
+
const mapped = renamed.get(name);
|
|
113
|
+
return mapped ? `#${mapped}` : token;
|
|
114
|
+
});
|
|
115
|
+
return rewritten === selector ? rule : `${rewritten}{${declarations}}`;
|
|
116
|
+
});
|
|
117
|
+
return next === body ? all : `${open}${next}${close}`;
|
|
118
|
+
})
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* A prefix no other preview shares.
|
|
124
|
+
*
|
|
125
|
+
* A module counter, not `useId`: measured, two Preact roots mounted on one page
|
|
126
|
+
* both allocate `P0-0`, so two previews in two roots would collide on exactly
|
|
127
|
+
* the ids this exists to keep apart. A process counter cannot.
|
|
128
|
+
*/
|
|
129
|
+
let sequence = 0;
|
|
130
|
+
|
|
131
|
+
export function nextSvgScopePrefix(): string {
|
|
132
|
+
sequence += 1;
|
|
133
|
+
return `svg${sequence}-`;
|
|
134
|
+
}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Breakdown and chart view models (`breakdown.ts`).
|
|
8
|
+
*
|
|
9
|
+
* These are the rows a user reads, so each case pins a value that would be a
|
|
10
|
+
* bug if it drifted: a model shown under the wrong provider, a share computed
|
|
11
|
+
* against the wrong denominator, a cadence that relabels without re-bucketing,
|
|
12
|
+
* or a per-bucket average divided by the wrong count.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { describe, expect, test } from 'bun:test';
|
|
16
|
+
|
|
17
|
+
import {
|
|
18
|
+
breakdownRows,
|
|
19
|
+
bucketDays,
|
|
20
|
+
chartSeries,
|
|
21
|
+
dayRows,
|
|
22
|
+
providerModelRows,
|
|
23
|
+
} from '@/shared/lib/usage/breakdown';
|
|
24
|
+
import type { UsageDayRow, UsageProviderRow, UsageTotals } from '@/shared/types';
|
|
25
|
+
|
|
26
|
+
const counters = (cost: number, tokens: number, records = 1, cacheRead = 0, input = 0) => ({
|
|
27
|
+
cost, tokens, input, output: tokens - input - cacheRead, cacheRead, cacheWrite: 0,
|
|
28
|
+
reasoning: 0, cacheReadCost: cost * 0.1, records, unpriced: 0,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const provider = (id: string, name: string, models: Array<[string, number, number]>): UsageProviderRow => {
|
|
32
|
+
const rows = models.map(([model, cost, tokens]) => ({ model, ...counters(cost, tokens) }));
|
|
33
|
+
return {
|
|
34
|
+
id,
|
|
35
|
+
name,
|
|
36
|
+
models: rows,
|
|
37
|
+
...rows.reduce(
|
|
38
|
+
(acc, row) => ({
|
|
39
|
+
...acc,
|
|
40
|
+
cost: acc.cost + row.cost,
|
|
41
|
+
tokens: acc.tokens + row.tokens,
|
|
42
|
+
records: acc.records + row.records,
|
|
43
|
+
}),
|
|
44
|
+
{ cost: 0, tokens: 0, records: 0 },
|
|
45
|
+
),
|
|
46
|
+
input: 0, output: 0, cacheRead: 0, cacheWrite: 0, reasoning: 0, cacheReadCost: 0, unpriced: 0,
|
|
47
|
+
} as UsageProviderRow;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const totals: UsageTotals = {
|
|
51
|
+
...counters(20, 1_000_000, 40, 900_000, 50_000),
|
|
52
|
+
unpriced: 4,
|
|
53
|
+
activeDays: 6,
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const day = (key: string, cost: number, tokens: number, providers: Record<string, { cost: number; tokens: number }>): UsageDayRow => ({
|
|
57
|
+
day: key,
|
|
58
|
+
providers,
|
|
59
|
+
...counters(cost, tokens),
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
describe('bucketDays', () => {
|
|
63
|
+
const days = [
|
|
64
|
+
day('2026-10-31', 1, 10, { kenari: { cost: 1, tokens: 10 } }),
|
|
65
|
+
day('2026-11-02', 3, 30, { 'kenari-jatis': { cost: 2, tokens: 20 }, kenari: { cost: 1, tokens: 10 } }),
|
|
66
|
+
day('2026-11-03', 4, 40, { 'kenari-jatis': { cost: 4, tokens: 40 } }),
|
|
67
|
+
];
|
|
68
|
+
|
|
69
|
+
test('a week merges its days and sums each provider separately', () => {
|
|
70
|
+
const buckets = bucketDays(days, 'week');
|
|
71
|
+
// Oct 31 is a Saturday in the week of Oct 26; Nov 2–3 fall in the week of Nov 2.
|
|
72
|
+
expect(buckets.map((bucket) => bucket.label)).toEqual(['Oct 26', 'Nov 2']);
|
|
73
|
+
expect(buckets[1].cost).toBe(7);
|
|
74
|
+
expect(buckets[1].byProvider['kenari-jatis']).toEqual({ cost: 6, tokens: 60 });
|
|
75
|
+
expect(buckets[1].byProvider.kenari).toEqual({ cost: 1, tokens: 10 });
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test('a month keeps one bucket per month, ordered', () => {
|
|
79
|
+
const buckets = bucketDays(days, 'month');
|
|
80
|
+
expect(buckets.map((bucket) => bucket.label)).toEqual(['Oct', 'Nov']);
|
|
81
|
+
expect(buckets[1].cost).toBe(7);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test('the flat series matches the buckets it summarises', () => {
|
|
85
|
+
expect(chartSeries(days, 'day')).toEqual([
|
|
86
|
+
{ label: 'Oct 31', cost: 1, tokens: 10 },
|
|
87
|
+
{ label: 'Nov 2', cost: 3, tokens: 30 },
|
|
88
|
+
{ label: 'Nov 3', cost: 4, tokens: 40 },
|
|
89
|
+
]);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
describe('providerModelRows', () => {
|
|
94
|
+
const providers = [
|
|
95
|
+
provider('kenari-jatis', 'Kenari Jatis', [['deepseek-v4-1-flash', 18, 900]]),
|
|
96
|
+
provider('kenari', 'Kenari.id', [['deepseek-v4-1-flash', 1.5, 80], ['minimax-m3', 0.5, 20]]),
|
|
97
|
+
];
|
|
98
|
+
|
|
99
|
+
test('one model id under two providers is two subtrees, not one row', () => {
|
|
100
|
+
const rows = providerModelRows(providers, 20);
|
|
101
|
+
expect(rows.map((row) => `${row.kind}:${row.label}`)).toEqual([
|
|
102
|
+
'group:Kenari Jatis',
|
|
103
|
+
'row:deepseek-v4-1-flash',
|
|
104
|
+
'group:Kenari.id',
|
|
105
|
+
'row:deepseek-v4-1-flash',
|
|
106
|
+
'row:minimax-m3',
|
|
107
|
+
]);
|
|
108
|
+
// Keys stay unique even where the label repeats.
|
|
109
|
+
expect(new Set(rows.map((row) => row.key)).size).toBe(rows.length);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test('model share is of the period, and of its provider', () => {
|
|
113
|
+
const rows = providerModelRows(providers, 20);
|
|
114
|
+
const jatisModel = rows[1];
|
|
115
|
+
expect(jatisModel.sharePercent).toBe(90);
|
|
116
|
+
expect(jatisModel.shareOfParentPercent).toBe(100);
|
|
117
|
+
const kenariSmall = rows[4];
|
|
118
|
+
expect(kenariSmall.sharePercent).toBe(2.5);
|
|
119
|
+
expect(kenariSmall.shareOfParentPercent).toBe(25);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test('a row is the period total, with no derived per-day figure', () => {
|
|
123
|
+
const rows = providerModelRows(providers, 20);
|
|
124
|
+
expect(rows[0].cost).toBe(18);
|
|
125
|
+
expect(rows[1].cost).toBe(18);
|
|
126
|
+
expect(rows[1].tokens).toBe(900);
|
|
127
|
+
expect('display' in rows[1]).toBe(false);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
test('a zero total does not divide by zero', () => {
|
|
131
|
+
const rows = providerModelRows([provider('x', 'X', [['m', 0, 0]])], 0);
|
|
132
|
+
expect(rows.every((row) => row.sharePercent === 0)).toBe(true);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
describe('dayRows', () => {
|
|
137
|
+
const days = [
|
|
138
|
+
day('2026-11-02', 1, 10, { kenari: { cost: 1, tokens: 10 } }),
|
|
139
|
+
day('2026-11-03', 3, 30, { kenari: { cost: 3, tokens: 30 } }),
|
|
140
|
+
];
|
|
141
|
+
|
|
142
|
+
test('lists the period oldest first, and a quiet day is still listed', () => {
|
|
143
|
+
// Nov 1 has no records at all; the table must still show it, or the list
|
|
144
|
+
// silently stops matching the period it claims to describe.
|
|
145
|
+
const rows = dayRows(days, 'day', 4, { from: '2026-11-01', to: '2026-11-03' });
|
|
146
|
+
expect(rows.map((row) => row.label)).toEqual(['Nov 1', 'Nov 2', 'Nov 3']);
|
|
147
|
+
expect(rows[0].cost).toBe(0);
|
|
148
|
+
expect(rows[0].sharePercent).toBe(0);
|
|
149
|
+
expect(rows[2].sharePercent).toBe(75);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
test('a weekly bucket sums the week into one row per week of the period', () => {
|
|
153
|
+
const rows = dayRows(days, 'week', 4, { from: '2026-11-02', to: '2026-11-03' });
|
|
154
|
+
expect(rows).toHaveLength(1);
|
|
155
|
+
expect(rows[0].label).toBe('Nov 2');
|
|
156
|
+
expect(rows[0].cost).toBe(4);
|
|
157
|
+
expect(rows[0].records).toBe(2);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
test('all time lists every month between its first and last recorded day', () => {
|
|
161
|
+
// A quiet month in the middle of the history must not vanish: the rows
|
|
162
|
+
// have to add up to the totals shown beside them.
|
|
163
|
+
const rows = dayRows(
|
|
164
|
+
[day('2026-06-24', 1, 10, { kenari: { cost: 1, tokens: 10 } }), day('2026-08-02', 2, 20, { kenari: { cost: 2, tokens: 20 } })],
|
|
165
|
+
'month',
|
|
166
|
+
3,
|
|
167
|
+
{ from: '2026-06-24', to: '2026-08-02' },
|
|
168
|
+
);
|
|
169
|
+
expect(rows.map((row) => row.label)).toEqual(['Jun', 'Jul', 'Aug']);
|
|
170
|
+
expect(rows[1].cost).toBe(0);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
test('without a window only the days that saw usage are listed', () => {
|
|
174
|
+
// All-time has no bounded window, so the rollup's own days are the list.
|
|
175
|
+
const rows = dayRows(days, 'day', 4, null);
|
|
176
|
+
expect(rows.map((row) => row.label)).toEqual(['Nov 2', 'Nov 3']);
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
describe('breakdownRows', () => {
|
|
181
|
+
const providers = [provider('kenari', 'Kenari.id', [['m', 4, 40]])];
|
|
182
|
+
const payload = {
|
|
183
|
+
totals: { ...totals, cost: 4, tokens: 40, activeDays: 1 },
|
|
184
|
+
providers,
|
|
185
|
+
days: [day('2026-11-03', 4, 40, { kenari: { cost: 4, tokens: 40 } })],
|
|
186
|
+
projects: [],
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
test('provider and model tabs draw the same tree', () => {
|
|
190
|
+
expect(breakdownRows('provider', payload, 'day', null)).toEqual(breakdownRows('model', payload, 'day', null));
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
test('each tab selects its own source', () => {
|
|
194
|
+
expect(breakdownRows('day', payload, 'day', null)[0].label).toBe('Nov 3');
|
|
195
|
+
expect(breakdownRows('project', payload, 'day', null)).toEqual([]);
|
|
196
|
+
});
|
|
197
|
+
});
|