corporateai 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.dockerignore +10 -0
- package/.env.example +3 -0
- package/.github/workflows/publish-cli.yml +49 -0
- package/.mailmap +1 -0
- package/AGENTS.md +148 -0
- package/CONTRIBUTING.md +75 -0
- package/Dockerfile +59 -0
- package/Dockerfile.onboard-smoke +42 -0
- package/LICENSE +21 -0
- package/README.md +93 -0
- package/cli/esbuild.config.mjs +11 -0
- package/cli/package.json +24 -0
- package/cli/scripts/build-cli.mjs +5 -0
- package/cli/src/index.ts +27 -0
- package/docker-compose.quickstart.yml +18 -0
- package/docker-compose.untrusted-review.yml +33 -0
- package/docker-compose.yml +38 -0
- package/package.json +56 -0
- package/patches/embedded-postgres@18.1.0-beta.16.patch +0 -0
- package/pnpm-workspace.yaml +4 -0
- package/releases/.gitkeep +0 -0
- package/releases/v0.0.1.md +36 -0
- package/releases/v0.2.7.md +15 -0
- package/releases/v0.3.0.md +54 -0
- package/releases/v0.3.1.md +55 -0
- package/releases/v2026.318.0.md +66 -0
- package/releases/v2026.325.0.md +78 -0
- package/report/2026-03-13-08-46-token-optimization-implementation.md +48 -0
- package/scripts/backup-db.sh +17 -0
- package/scripts/build-npm.sh +80 -0
- package/scripts/check-forbidden-tokens.mjs +115 -0
- package/scripts/clean-onboard-git.sh +14 -0
- package/scripts/clean-onboard-npm.sh +13 -0
- package/scripts/clean-onboard-ref.sh +86 -0
- package/scripts/create-github-release.sh +99 -0
- package/scripts/dev-runner-paths.mjs +38 -0
- package/scripts/dev-runner.mjs +606 -0
- package/scripts/docker-onboard-smoke.sh +306 -0
- package/scripts/ensure-plugin-build-deps.mjs +47 -0
- package/scripts/generate-company-assets.ts +365 -0
- package/scripts/generate-npm-package-json.mjs +113 -0
- package/scripts/generate-org-chart-images.ts +694 -0
- package/scripts/generate-org-chart-satori-comparison.ts +225 -0
- package/scripts/generate-ui-package-json.mjs +31 -0
- package/scripts/kill-dev.sh +71 -0
- package/scripts/migrate-inline-env-secrets.ts +126 -0
- package/scripts/prepare-server-ui-dist.sh +22 -0
- package/scripts/provision-worktree.sh +333 -0
- package/scripts/release-lib.sh +306 -0
- package/scripts/release-package-map.mjs +169 -0
- package/scripts/release.sh +312 -0
- package/scripts/rollback-latest.sh +111 -0
- package/scripts/smoke/openclaw-docker-ui.sh +329 -0
- package/scripts/smoke/openclaw-gateway-e2e.sh +954 -0
- package/scripts/smoke/openclaw-join.sh +295 -0
- package/scripts/smoke/openclaw-sse-standalone.sh +146 -0
- package/scripts/workspace-compat.mjs +60 -0
- package/server/CHANGELOG.md +130 -0
- package/server/package.json +96 -0
- package/server/scripts/copy-onboarding-assets.mjs +10 -0
- package/server/scripts/dev-watch.ts +33 -0
- package/server/src/__tests__/activity-routes.test.ts +70 -0
- package/server/src/__tests__/adapter-models.test.ts +105 -0
- package/server/src/__tests__/adapter-session-codecs.test.ts +194 -0
- package/server/src/__tests__/agent-auth-jwt.test.ts +79 -0
- package/server/src/__tests__/agent-instructions-routes.test.ts +318 -0
- package/server/src/__tests__/agent-instructions-service.test.ts +361 -0
- package/server/src/__tests__/agent-permissions-routes.test.ts +275 -0
- package/server/src/__tests__/agent-shortname-collision.test.ts +69 -0
- package/server/src/__tests__/agent-skill-contract.test.ts +50 -0
- package/server/src/__tests__/agent-skills-routes.test.ts +462 -0
- package/server/src/__tests__/app-hmr-port.test.ts +19 -0
- package/server/src/__tests__/approval-routes-idempotency.test.ts +110 -0
- package/server/src/__tests__/approvals-service.test.ts +107 -0
- package/server/src/__tests__/assets.test.ts +250 -0
- package/server/src/__tests__/attachment-types.test.ts +97 -0
- package/server/src/__tests__/board-mutation-guard.test.ts +105 -0
- package/server/src/__tests__/budgets-service.test.ts +311 -0
- package/server/src/__tests__/claude-local-adapter-environment.test.ts +92 -0
- package/server/src/__tests__/claude-local-adapter.test.ts +31 -0
- package/server/src/__tests__/claude-local-skill-sync.test.ts +111 -0
- package/server/src/__tests__/cli-auth-routes.test.ts +230 -0
- package/server/src/__tests__/codex-local-adapter-environment.test.ts +143 -0
- package/server/src/__tests__/codex-local-adapter.test.ts +253 -0
- package/server/src/__tests__/codex-local-execute.test.ts +391 -0
- package/server/src/__tests__/codex-local-skill-injection.test.ts +175 -0
- package/server/src/__tests__/codex-local-skill-sync.test.ts +123 -0
- package/server/src/__tests__/companies-route-path-guard.test.ts +56 -0
- package/server/src/__tests__/company-branding-route.test.ts +196 -0
- package/server/src/__tests__/company-portability-routes.test.ts +175 -0
- package/server/src/__tests__/company-portability.test.ts +2186 -0
- package/server/src/__tests__/company-skills-routes.test.ts +113 -0
- package/server/src/__tests__/company-skills.test.ts +229 -0
- package/server/src/__tests__/costs-service.test.ts +226 -0
- package/server/src/__tests__/cursor-local-adapter-environment.test.ts +196 -0
- package/server/src/__tests__/cursor-local-adapter.test.ts +406 -0
- package/server/src/__tests__/cursor-local-execute.test.ts +263 -0
- package/server/src/__tests__/cursor-local-skill-injection.test.ts +104 -0
- package/server/src/__tests__/cursor-local-skill-sync.test.ts +145 -0
- package/server/src/__tests__/dev-runner-paths.test.ts +25 -0
- package/server/src/__tests__/dev-server-status.test.ts +66 -0
- package/server/src/__tests__/dev-watch-ignore.test.ts +42 -0
- package/server/src/__tests__/documents.test.ts +29 -0
- package/server/src/__tests__/error-handler.test.ts +53 -0
- package/server/src/__tests__/execution-workspace-policy.test.ts +170 -0
- package/server/src/__tests__/forbidden-tokens.test.ts +77 -0
- package/server/src/__tests__/gemini-local-adapter-environment.test.ts +135 -0
- package/server/src/__tests__/gemini-local-adapter.test.ts +190 -0
- package/server/src/__tests__/gemini-local-execute.test.ts +172 -0
- package/server/src/__tests__/gemini-local-skill-sync.test.ts +90 -0
- package/server/src/__tests__/health.test.ts +16 -0
- package/server/src/__tests__/heartbeat-process-recovery.test.ts +256 -0
- package/server/src/__tests__/heartbeat-run-summary.test.ts +33 -0
- package/server/src/__tests__/heartbeat-workspace-session.test.ts +334 -0
- package/server/src/__tests__/helpers/embedded-postgres.ts +7 -0
- package/server/src/__tests__/hire-hook.test.ts +181 -0
- package/server/src/__tests__/instance-settings-routes.test.ts +156 -0
- package/server/src/__tests__/invite-accept-gateway-defaults.test.ts +119 -0
- package/server/src/__tests__/invite-accept-replay.test.ts +92 -0
- package/server/src/__tests__/invite-expiry.test.ts +10 -0
- package/server/src/__tests__/invite-join-grants.test.ts +57 -0
- package/server/src/__tests__/invite-join-manager.test.ts +33 -0
- package/server/src/__tests__/invite-onboarding-text.test.ts +116 -0
- package/server/src/__tests__/issue-comment-reopen-routes.test.ts +146 -0
- package/server/src/__tests__/issue-goal-fallback.test.ts +99 -0
- package/server/src/__tests__/issues-checkout-wakeup.test.ts +48 -0
- package/server/src/__tests__/issues-goal-context-routes.test.ts +187 -0
- package/server/src/__tests__/issues-service.test.ts +317 -0
- package/server/src/__tests__/issues-user-context.test.ts +113 -0
- package/server/src/__tests__/log-redaction.test.ts +74 -0
- package/server/src/__tests__/monthly-spend-service.test.ts +90 -0
- package/server/src/__tests__/normalize-agent-mention-token.test.ts +41 -0
- package/server/src/__tests__/openclaw-gateway-adapter.test.ts +626 -0
- package/server/src/__tests__/openclaw-invite-prompt-route.test.ts +192 -0
- package/server/src/__tests__/opencode-local-adapter-environment.test.ts +97 -0
- package/server/src/__tests__/opencode-local-adapter.test.ts +226 -0
- package/server/src/__tests__/opencode-local-skill-sync.test.ts +91 -0
- package/server/src/__tests__/paperclip-env.test.ts +58 -0
- package/server/src/__tests__/paperclip-skill-utils.test.ts +63 -0
- package/server/src/__tests__/pi-local-adapter-environment.test.ts +102 -0
- package/server/src/__tests__/pi-local-skill-sync.test.ts +95 -0
- package/server/src/__tests__/plugin-dev-watcher.test.ts +68 -0
- package/server/src/__tests__/plugin-worker-manager.test.ts +43 -0
- package/server/src/__tests__/private-hostname-guard.test.ts +56 -0
- package/server/src/__tests__/project-shortname-resolution.test.ts +45 -0
- package/server/src/__tests__/quota-windows-service.test.ts +56 -0
- package/server/src/__tests__/quota-windows.test.ts +1109 -0
- package/server/src/__tests__/redaction.test.ts +66 -0
- package/server/src/__tests__/routines-e2e.test.ts +276 -0
- package/server/src/__tests__/routines-routes.test.ts +271 -0
- package/server/src/__tests__/routines-service.test.ts +424 -0
- package/server/src/__tests__/storage-local-provider.test.ts +78 -0
- package/server/src/__tests__/ui-branding.test.ts +82 -0
- package/server/src/__tests__/work-products.test.ts +95 -0
- package/server/src/__tests__/workspace-runtime.test.ts +1131 -0
- package/server/src/__tests__/worktree-config.test.ts +426 -0
- package/server/src/adapters/codex-models.ts +105 -0
- package/server/src/adapters/cursor-models.ts +171 -0
- package/server/src/adapters/http/execute.ts +42 -0
- package/server/src/adapters/http/index.ts +21 -0
- package/server/src/adapters/http/test.ts +116 -0
- package/server/src/adapters/index.ts +18 -0
- package/server/src/adapters/process/execute.ts +77 -0
- package/server/src/adapters/process/index.ts +24 -0
- package/server/src/adapters/process/test.ts +89 -0
- package/server/src/adapters/registry.ts +225 -0
- package/server/src/adapters/server-utils-compat.ts +57 -0
- package/server/src/adapters/types.ts +30 -0
- package/server/src/adapters/utils.ts +48 -0
- package/server/src/agent-auth-jwt.ts +141 -0
- package/server/src/app.ts +321 -0
- package/server/src/attachment-types.ts +74 -0
- package/server/src/auth/better-auth.ts +148 -0
- package/server/src/board-claim.ts +150 -0
- package/server/src/config-file.ts +17 -0
- package/server/src/config.ts +260 -0
- package/server/src/dev-server-status.ts +103 -0
- package/server/src/dev-watch-ignore.ts +36 -0
- package/server/src/errors.ts +34 -0
- package/server/src/home-paths.ts +95 -0
- package/server/src/index.ts +799 -0
- package/server/src/log-redaction.ts +146 -0
- package/server/src/middleware/auth.ts +178 -0
- package/server/src/middleware/board-mutation-guard.ts +66 -0
- package/server/src/middleware/error-handler.ts +71 -0
- package/server/src/middleware/index.ts +3 -0
- package/server/src/middleware/logger.ts +90 -0
- package/server/src/middleware/private-hostname-guard.ts +92 -0
- package/server/src/middleware/validate.ts +9 -0
- package/server/src/onboarding-assets/ceo/AGENTS.md +54 -0
- package/server/src/onboarding-assets/ceo/HEARTBEAT.md +72 -0
- package/server/src/onboarding-assets/ceo/SOUL.md +33 -0
- package/server/src/onboarding-assets/ceo/TOOLS.md +3 -0
- package/server/src/onboarding-assets/default/AGENTS.md +3 -0
- package/server/src/paths.ts +34 -0
- package/server/src/realtime/live-events-ws.ts +274 -0
- package/server/src/redaction.ts +59 -0
- package/server/src/routes/access.ts +2888 -0
- package/server/src/routes/activity.ts +89 -0
- package/server/src/routes/agents.ts +2313 -0
- package/server/src/routes/approvals.ts +346 -0
- package/server/src/routes/assets.ts +341 -0
- package/server/src/routes/authz.ts +52 -0
- package/server/src/routes/companies.ts +343 -0
- package/server/src/routes/company-skills.ts +300 -0
- package/server/src/routes/costs.ts +335 -0
- package/server/src/routes/dashboard.ts +19 -0
- package/server/src/routes/execution-workspaces.ts +182 -0
- package/server/src/routes/goals.ts +107 -0
- package/server/src/routes/health.ts +94 -0
- package/server/src/routes/index.ts +17 -0
- package/server/src/routes/instance-settings.ts +95 -0
- package/server/src/routes/issues-checkout-wakeup.ts +14 -0
- package/server/src/routes/issues.ts +1680 -0
- package/server/src/routes/llms.ts +86 -0
- package/server/src/routes/org-chart-svg.ts +777 -0
- package/server/src/routes/plugin-ui-static.ts +497 -0
- package/server/src/routes/plugins.ts +2220 -0
- package/server/src/routes/projects.ts +295 -0
- package/server/src/routes/routines.ts +300 -0
- package/server/src/routes/secrets.ts +166 -0
- package/server/src/routes/sidebar-badges.ts +52 -0
- package/server/src/secrets/external-stub-providers.ts +32 -0
- package/server/src/secrets/local-encrypted-provider.ts +135 -0
- package/server/src/secrets/provider-registry.ts +31 -0
- package/server/src/secrets/types.ts +23 -0
- package/server/src/services/access.ts +381 -0
- package/server/src/services/activity-log.ts +95 -0
- package/server/src/services/activity.ts +164 -0
- package/server/src/services/agent-instructions.ts +735 -0
- package/server/src/services/agent-permissions.ts +27 -0
- package/server/src/services/agents.ts +694 -0
- package/server/src/services/approvals.ts +273 -0
- package/server/src/services/assets.ts +23 -0
- package/server/src/services/board-auth.ts +355 -0
- package/server/src/services/budgets.ts +959 -0
- package/server/src/services/companies.ts +313 -0
- package/server/src/services/company-export-readme.ts +173 -0
- package/server/src/services/company-portability.ts +4263 -0
- package/server/src/services/company-skills.ts +2356 -0
- package/server/src/services/costs.ts +365 -0
- package/server/src/services/cron.ts +373 -0
- package/server/src/services/dashboard.ts +110 -0
- package/server/src/services/default-agent-instructions.ts +27 -0
- package/server/src/services/documents.ts +434 -0
- package/server/src/services/execution-workspace-policy.ts +210 -0
- package/server/src/services/execution-workspaces.ts +100 -0
- package/server/src/services/finance.ts +135 -0
- package/server/src/services/goals.ts +81 -0
- package/server/src/services/heartbeat-run-summary.ts +35 -0
- package/server/src/services/heartbeat.ts +3863 -0
- package/server/src/services/hire-hook.ts +114 -0
- package/server/src/services/index.ts +32 -0
- package/server/src/services/instance-settings.ts +138 -0
- package/server/src/services/issue-approvals.ts +175 -0
- package/server/src/services/issue-assignment-wakeup.ts +48 -0
- package/server/src/services/issue-goal-fallback.ts +56 -0
- package/server/src/services/issues.ts +1828 -0
- package/server/src/services/live-events.ts +55 -0
- package/server/src/services/plugin-capability-validator.ts +450 -0
- package/server/src/services/plugin-config-validator.ts +55 -0
- package/server/src/services/plugin-dev-watcher.ts +339 -0
- package/server/src/services/plugin-event-bus.ts +413 -0
- package/server/src/services/plugin-host-service-cleanup.ts +59 -0
- package/server/src/services/plugin-host-services.ts +1132 -0
- package/server/src/services/plugin-job-coordinator.ts +261 -0
- package/server/src/services/plugin-job-scheduler.ts +753 -0
- package/server/src/services/plugin-job-store.ts +466 -0
- package/server/src/services/plugin-lifecycle.ts +822 -0
- package/server/src/services/plugin-loader.ts +1955 -0
- package/server/src/services/plugin-log-retention.ts +87 -0
- package/server/src/services/plugin-manifest-validator.ts +164 -0
- package/server/src/services/plugin-registry.ts +683 -0
- package/server/src/services/plugin-runtime-sandbox.ts +222 -0
- package/server/src/services/plugin-secrets-handler.ts +355 -0
- package/server/src/services/plugin-state-store.ts +238 -0
- package/server/src/services/plugin-stream-bus.ts +81 -0
- package/server/src/services/plugin-tool-dispatcher.ts +449 -0
- package/server/src/services/plugin-tool-registry.ts +450 -0
- package/server/src/services/plugin-worker-manager.ts +1343 -0
- package/server/src/services/projects.ts +860 -0
- package/server/src/services/quota-windows.ts +65 -0
- package/server/src/services/routines.ts +1269 -0
- package/server/src/services/run-log-store.ts +156 -0
- package/server/src/services/secrets.ts +370 -0
- package/server/src/services/sidebar-badges.ts +56 -0
- package/server/src/services/work-products.ts +124 -0
- package/server/src/services/workspace-operation-log-store.ts +156 -0
- package/server/src/services/workspace-operations.ts +262 -0
- package/server/src/services/workspace-runtime.ts +1565 -0
- package/server/src/startup-banner.ts +176 -0
- package/server/src/storage/index.ts +35 -0
- package/server/src/storage/local-disk-provider.ts +89 -0
- package/server/src/storage/provider-registry.ts +18 -0
- package/server/src/storage/s3-provider.ts +153 -0
- package/server/src/storage/service.ts +131 -0
- package/server/src/storage/types.ts +63 -0
- package/server/src/ui-branding.ts +217 -0
- package/server/src/version.ts +10 -0
- package/server/src/worktree-config.ts +468 -0
- package/server/tsconfig.json +9 -0
- package/server/vitest.config.ts +7 -0
- package/skills/paperclip/SKILL.md +365 -0
- package/skills/paperclip/references/api-reference.md +647 -0
- package/skills/paperclip/references/company-skills.md +193 -0
- package/skills/paperclip-create-agent/SKILL.md +142 -0
- package/skills/paperclip-create-agent/references/api-reference.md +105 -0
- package/skills/paperclip-create-plugin/SKILL.md +102 -0
- package/skills/para-memory-files/SKILL.md +104 -0
- package/skills/para-memory-files/references/schemas.md +35 -0
- package/tests/e2e/onboarding.spec.ts +142 -0
- package/tests/e2e/playwright.config.ts +35 -0
- package/tests/release-smoke/docker-auth-onboarding.spec.ts +141 -0
- package/tests/release-smoke/playwright.config.ts +28 -0
- package/tsconfig.base.json +18 -0
- package/tsconfig.json +18 -0
- package/ui/README.md +12 -0
- package/ui/components.json +21 -0
- package/ui/index.html +47 -0
- package/ui/package.json +73 -0
- package/ui/public/android-chrome-192x192.png +0 -0
- package/ui/public/android-chrome-512x512.png +0 -0
- package/ui/public/apple-touch-icon.png +0 -0
- package/ui/public/brands/opencode-logo-dark-square.svg +18 -0
- package/ui/public/brands/opencode-logo-light-square.svg +18 -0
- package/ui/public/favicon-16x16.png +0 -0
- package/ui/public/favicon-32x32.png +0 -0
- package/ui/public/favicon.ico +0 -0
- package/ui/public/favicon.svg +9 -0
- package/ui/public/site.webmanifest +30 -0
- package/ui/public/sprites/1-D-1.png +0 -0
- package/ui/public/sprites/1-D-2.png +0 -0
- package/ui/public/sprites/1-D-3.png +0 -0
- package/ui/public/sprites/1-L-1.png +0 -0
- package/ui/public/sprites/1-R-1.png +0 -0
- package/ui/public/sprites/10-D-1.png +0 -0
- package/ui/public/sprites/10-D-2.png +0 -0
- package/ui/public/sprites/10-D-3.png +0 -0
- package/ui/public/sprites/10-L-1.png +0 -0
- package/ui/public/sprites/10-R-1.png +0 -0
- package/ui/public/sprites/11-D-1.png +0 -0
- package/ui/public/sprites/11-D-2.png +0 -0
- package/ui/public/sprites/11-D-3.png +0 -0
- package/ui/public/sprites/11-L-1.png +0 -0
- package/ui/public/sprites/11-R-1.png +0 -0
- package/ui/public/sprites/12-D-1.png +0 -0
- package/ui/public/sprites/12-D-2.png +0 -0
- package/ui/public/sprites/12-D-3.png +0 -0
- package/ui/public/sprites/12-L-1.png +0 -0
- package/ui/public/sprites/12-R-1.png +0 -0
- package/ui/public/sprites/13-D-1.png +0 -0
- package/ui/public/sprites/13-D-2.png +0 -0
- package/ui/public/sprites/13-D-3.png +0 -0
- package/ui/public/sprites/13-L-1.png +0 -0
- package/ui/public/sprites/13-R-1.png +0 -0
- package/ui/public/sprites/14-D-1.png +0 -0
- package/ui/public/sprites/14-D-2.png +0 -0
- package/ui/public/sprites/14-D-3.png +0 -0
- package/ui/public/sprites/14-L-1.png +0 -0
- package/ui/public/sprites/14-R-1.png +0 -0
- package/ui/public/sprites/2-D-1.png +0 -0
- package/ui/public/sprites/2-D-2.png +0 -0
- package/ui/public/sprites/2-D-3.png +0 -0
- package/ui/public/sprites/2-L-1.png +0 -0
- package/ui/public/sprites/2-R-1.png +0 -0
- package/ui/public/sprites/3-D-1.png +0 -0
- package/ui/public/sprites/3-D-2.png +0 -0
- package/ui/public/sprites/3-D-3.png +0 -0
- package/ui/public/sprites/3-L-1.png +0 -0
- package/ui/public/sprites/3-R-1.png +0 -0
- package/ui/public/sprites/4-D-1.png +0 -0
- package/ui/public/sprites/4-D-2.png +0 -0
- package/ui/public/sprites/4-D-3.png +0 -0
- package/ui/public/sprites/4-L-1.png +0 -0
- package/ui/public/sprites/4-R-1.png +0 -0
- package/ui/public/sprites/5-D-1.png +0 -0
- package/ui/public/sprites/5-D-2.png +0 -0
- package/ui/public/sprites/5-D-3.png +0 -0
- package/ui/public/sprites/5-L-1.png +0 -0
- package/ui/public/sprites/5-R-1.png +0 -0
- package/ui/public/sprites/6-D-1.png +0 -0
- package/ui/public/sprites/6-D-2.png +0 -0
- package/ui/public/sprites/6-D-3.png +0 -0
- package/ui/public/sprites/6-L-1.png +0 -0
- package/ui/public/sprites/6-R-1.png +0 -0
- package/ui/public/sprites/7-D-1.png +0 -0
- package/ui/public/sprites/7-D-2.png +0 -0
- package/ui/public/sprites/7-D-3.png +0 -0
- package/ui/public/sprites/7-L-1.png +0 -0
- package/ui/public/sprites/7-R-1.png +0 -0
- package/ui/public/sprites/8-D-1.png +0 -0
- package/ui/public/sprites/8-D-2.png +0 -0
- package/ui/public/sprites/8-D-3.png +0 -0
- package/ui/public/sprites/8-L-1.png +0 -0
- package/ui/public/sprites/8-R-1.png +0 -0
- package/ui/public/sprites/9-D-1.png +0 -0
- package/ui/public/sprites/9-D-2.png +0 -0
- package/ui/public/sprites/9-D-3.png +0 -0
- package/ui/public/sprites/9-L-1.png +0 -0
- package/ui/public/sprites/9-R-1.png +0 -0
- package/ui/public/sprites/ceo-lobster.png +0 -0
- package/ui/public/sw.js +42 -0
- package/ui/public/worktree-favicon-16x16.png +0 -0
- package/ui/public/worktree-favicon-32x32.png +0 -0
- package/ui/public/worktree-favicon.ico +0 -0
- package/ui/public/worktree-favicon.svg +9 -0
- package/ui/src/App.tsx +354 -0
- package/ui/src/adapters/claude-local/config-fields.tsx +138 -0
- package/ui/src/adapters/claude-local/index.ts +13 -0
- package/ui/src/adapters/codex-local/config-fields.tsx +104 -0
- package/ui/src/adapters/codex-local/index.ts +13 -0
- package/ui/src/adapters/cursor/config-fields.tsx +49 -0
- package/ui/src/adapters/cursor/index.ts +13 -0
- package/ui/src/adapters/gemini-local/config-fields.tsx +51 -0
- package/ui/src/adapters/gemini-local/index.ts +13 -0
- package/ui/src/adapters/http/build-config.ts +9 -0
- package/ui/src/adapters/http/config-fields.tsx +38 -0
- package/ui/src/adapters/http/index.ts +12 -0
- package/ui/src/adapters/http/parse-stdout.ts +5 -0
- package/ui/src/adapters/index.ts +9 -0
- package/ui/src/adapters/local-workspace-runtime-fields.tsx +5 -0
- package/ui/src/adapters/openclaw-gateway/config-fields.tsx +237 -0
- package/ui/src/adapters/openclaw-gateway/index.ts +13 -0
- package/ui/src/adapters/opencode-local/config-fields.tsx +72 -0
- package/ui/src/adapters/opencode-local/index.ts +13 -0
- package/ui/src/adapters/pi-local/config-fields.tsx +49 -0
- package/ui/src/adapters/pi-local/index.ts +13 -0
- package/ui/src/adapters/process/build-config.ts +18 -0
- package/ui/src/adapters/process/config-fields.tsx +77 -0
- package/ui/src/adapters/process/index.ts +12 -0
- package/ui/src/adapters/process/parse-stdout.ts +5 -0
- package/ui/src/adapters/registry.ts +34 -0
- package/ui/src/adapters/runtime-json-fields.tsx +122 -0
- package/ui/src/adapters/transcript.test.ts +30 -0
- package/ui/src/adapters/transcript.ts +62 -0
- package/ui/src/adapters/types.ts +34 -0
- package/ui/src/api/access.ts +160 -0
- package/ui/src/api/activity.ts +37 -0
- package/ui/src/api/agents.ts +194 -0
- package/ui/src/api/approvals.ts +25 -0
- package/ui/src/api/assets.ts +30 -0
- package/ui/src/api/auth.ts +74 -0
- package/ui/src/api/budgets.ts +21 -0
- package/ui/src/api/client.ts +50 -0
- package/ui/src/api/companies.ts +59 -0
- package/ui/src/api/companySkills.ts +55 -0
- package/ui/src/api/costs.ts +60 -0
- package/ui/src/api/dashboard.ts +7 -0
- package/ui/src/api/execution-workspaces.ts +27 -0
- package/ui/src/api/goals.ts +12 -0
- package/ui/src/api/health.ts +41 -0
- package/ui/src/api/heartbeats.ts +62 -0
- package/ui/src/api/index.ts +18 -0
- package/ui/src/api/instanceSettings.ts +19 -0
- package/ui/src/api/issues.ts +115 -0
- package/ui/src/api/plugins.ts +424 -0
- package/ui/src/api/projects.ts +34 -0
- package/ui/src/api/routines.ts +59 -0
- package/ui/src/api/secrets.ts +26 -0
- package/ui/src/api/sidebarBadges.ts +7 -0
- package/ui/src/components/AccountingModelCard.tsx +69 -0
- package/ui/src/components/ActiveAgentsPanel.tsx +157 -0
- package/ui/src/components/ActivityCharts.tsx +264 -0
- package/ui/src/components/ActivityRow.tsx +147 -0
- package/ui/src/components/AgentActionButtons.tsx +51 -0
- package/ui/src/components/AgentConfigForm.tsx +1468 -0
- package/ui/src/components/AgentIconPicker.tsx +81 -0
- package/ui/src/components/AgentProperties.tsx +107 -0
- package/ui/src/components/ApprovalCard.tsx +107 -0
- package/ui/src/components/ApprovalPayload.tsx +134 -0
- package/ui/src/components/AsciiArtAnimation.tsx +355 -0
- package/ui/src/components/BillerSpendCard.tsx +146 -0
- package/ui/src/components/BreadcrumbBar.tsx +113 -0
- package/ui/src/components/BudgetIncidentCard.tsx +101 -0
- package/ui/src/components/BudgetPolicyCard.tsx +220 -0
- package/ui/src/components/BudgetSidebarMarker.tsx +13 -0
- package/ui/src/components/ClaudeSubscriptionPanel.tsx +141 -0
- package/ui/src/components/CodexSubscriptionPanel.tsx +158 -0
- package/ui/src/components/CommandPalette.tsx +239 -0
- package/ui/src/components/CommentThread.tsx +503 -0
- package/ui/src/components/CompanyPatternIcon.tsx +212 -0
- package/ui/src/components/CompanyRail.tsx +329 -0
- package/ui/src/components/CompanySwitcher.tsx +81 -0
- package/ui/src/components/CopyText.tsx +56 -0
- package/ui/src/components/DevRestartBanner.tsx +89 -0
- package/ui/src/components/EmptyState.tsx +27 -0
- package/ui/src/components/EntityRow.tsx +69 -0
- package/ui/src/components/FilterBar.tsx +39 -0
- package/ui/src/components/FinanceBillerCard.tsx +45 -0
- package/ui/src/components/FinanceKindCard.tsx +44 -0
- package/ui/src/components/FinanceTimelineCard.tsx +72 -0
- package/ui/src/components/GoalProperties.tsx +165 -0
- package/ui/src/components/GoalTree.tsx +118 -0
- package/ui/src/components/Identity.tsx +39 -0
- package/ui/src/components/InlineEditor.tsx +248 -0
- package/ui/src/components/InlineEntitySelector.tsx +206 -0
- package/ui/src/components/InstanceSidebar.tsx +53 -0
- package/ui/src/components/IssueDocumentsSection.tsx +892 -0
- package/ui/src/components/IssueProperties.tsx +621 -0
- package/ui/src/components/IssueRow.tsx +149 -0
- package/ui/src/components/IssueWorkspaceCard.tsx +404 -0
- package/ui/src/components/IssuesList.tsx +889 -0
- package/ui/src/components/JsonSchemaForm.tsx +1048 -0
- package/ui/src/components/KanbanBoard.tsx +275 -0
- package/ui/src/components/Layout.tsx +441 -0
- package/ui/src/components/LiveRunWidget.tsx +160 -0
- package/ui/src/components/MarkdownBody.test.tsx +50 -0
- package/ui/src/components/MarkdownBody.tsx +152 -0
- package/ui/src/components/MarkdownEditor.tsx +622 -0
- package/ui/src/components/MetricCard.tsx +53 -0
- package/ui/src/components/MobileBottomNav.tsx +123 -0
- package/ui/src/components/NewAgentDialog.tsx +223 -0
- package/ui/src/components/NewGoalDialog.tsx +283 -0
- package/ui/src/components/NewIssueDialog.tsx +1473 -0
- package/ui/src/components/NewProjectDialog.tsx +451 -0
- package/ui/src/components/OnboardingWizard.tsx +1392 -0
- package/ui/src/components/OpenCodeLogoIcon.tsx +22 -0
- package/ui/src/components/PackageFileTree.tsx +318 -0
- package/ui/src/components/PageSkeleton.tsx +180 -0
- package/ui/src/components/PageTabBar.tsx +45 -0
- package/ui/src/components/PathInstructionsModal.tsx +143 -0
- package/ui/src/components/PriorityIcon.tsx +77 -0
- package/ui/src/components/ProjectProperties.tsx +1127 -0
- package/ui/src/components/PropertiesPanel.tsx +29 -0
- package/ui/src/components/ProviderQuotaCard.tsx +417 -0
- package/ui/src/components/QuotaBar.tsx +65 -0
- package/ui/src/components/ReportsToPicker.tsx +127 -0
- package/ui/src/components/ScheduleEditor.tsx +344 -0
- package/ui/src/components/ScrollToBottom.tsx +79 -0
- package/ui/src/components/Sidebar.tsx +130 -0
- package/ui/src/components/SidebarAgents.tsx +146 -0
- package/ui/src/components/SidebarNavItem.tsx +92 -0
- package/ui/src/components/SidebarProjects.tsx +234 -0
- package/ui/src/components/SidebarSection.tsx +17 -0
- package/ui/src/components/StatusBadge.tsx +15 -0
- package/ui/src/components/StatusIcon.tsx +71 -0
- package/ui/src/components/SwipeToArchive.tsx +152 -0
- package/ui/src/components/ToastViewport.tsx +99 -0
- package/ui/src/components/WorktreeBanner.tsx +25 -0
- package/ui/src/components/agent-config-defaults.ts +31 -0
- package/ui/src/components/agent-config-primitives.tsx +476 -0
- package/ui/src/components/transcript/RunTranscriptView.test.tsx +84 -0
- package/ui/src/components/transcript/RunTranscriptView.tsx +1015 -0
- package/ui/src/components/transcript/useLiveRunTranscripts.ts +297 -0
- package/ui/src/components/ui/avatar.tsx +107 -0
- package/ui/src/components/ui/badge.tsx +48 -0
- package/ui/src/components/ui/breadcrumb.tsx +109 -0
- package/ui/src/components/ui/button.tsx +64 -0
- package/ui/src/components/ui/card.tsx +92 -0
- package/ui/src/components/ui/checkbox.tsx +32 -0
- package/ui/src/components/ui/collapsible.tsx +33 -0
- package/ui/src/components/ui/command.tsx +194 -0
- package/ui/src/components/ui/dialog.tsx +156 -0
- package/ui/src/components/ui/dropdown-menu.tsx +257 -0
- package/ui/src/components/ui/input.tsx +21 -0
- package/ui/src/components/ui/label.tsx +22 -0
- package/ui/src/components/ui/popover.tsx +88 -0
- package/ui/src/components/ui/scroll-area.tsx +56 -0
- package/ui/src/components/ui/select.tsx +188 -0
- package/ui/src/components/ui/separator.tsx +28 -0
- package/ui/src/components/ui/sheet.tsx +143 -0
- package/ui/src/components/ui/skeleton.tsx +13 -0
- package/ui/src/components/ui/tabs.tsx +89 -0
- package/ui/src/components/ui/textarea.tsx +18 -0
- package/ui/src/components/ui/tooltip.tsx +57 -0
- package/ui/src/components/visual-office/AgentAvatar.tsx +99 -0
- package/ui/src/components/visual-office/OfficeViewExact.tsx +417 -0
- package/ui/src/components/visual-office/i18n.ts +52 -0
- package/ui/src/components/visual-office/office-view/CliUsagePanel.tsx +240 -0
- package/ui/src/components/visual-office/office-view/VirtualPadOverlay.tsx +104 -0
- package/ui/src/components/visual-office/office-view/buildScene-break-room.ts +248 -0
- package/ui/src/components/visual-office/office-view/buildScene-ceo-hallway.ts +345 -0
- package/ui/src/components/visual-office/office-view/buildScene-department-agent.ts +242 -0
- package/ui/src/components/visual-office/office-view/buildScene-departments.ts +360 -0
- package/ui/src/components/visual-office/office-view/buildScene-final-layers.ts +113 -0
- package/ui/src/components/visual-office/office-view/buildScene-types.ts +91 -0
- package/ui/src/components/visual-office/office-view/buildScene.ts +232 -0
- package/ui/src/components/visual-office/office-view/drawing-core.ts +374 -0
- package/ui/src/components/visual-office/office-view/drawing-furniture-a.ts +338 -0
- package/ui/src/components/visual-office/office-view/drawing-furniture-b.ts +241 -0
- package/ui/src/components/visual-office/office-view/model.ts +301 -0
- package/ui/src/components/visual-office/office-view/officeTicker.ts +455 -0
- package/ui/src/components/visual-office/office-view/officeTickerRoomAndDelivery.ts +133 -0
- package/ui/src/components/visual-office/office-view/themes-locale.ts +460 -0
- package/ui/src/components/visual-office/office-view/useCliUsage.ts +37 -0
- package/ui/src/components/visual-office/office-view/useOfficeDeliveryEffects.ts +465 -0
- package/ui/src/components/visual-office/office-view/useOfficePixiRuntime.ts +282 -0
- package/ui/src/components/visual-office/types.ts +123 -0
- package/ui/src/context/BreadcrumbContext.tsx +44 -0
- package/ui/src/context/CompanyContext.tsx +151 -0
- package/ui/src/context/DialogContext.tsx +135 -0
- package/ui/src/context/LiveUpdatesProvider.test.ts +119 -0
- package/ui/src/context/LiveUpdatesProvider.tsx +760 -0
- package/ui/src/context/PanelContext.tsx +73 -0
- package/ui/src/context/SidebarContext.tsx +43 -0
- package/ui/src/context/ThemeContext.tsx +83 -0
- package/ui/src/context/ToastContext.tsx +172 -0
- package/ui/src/fixtures/runTranscriptFixtures.ts +226 -0
- package/ui/src/hooks/useAgentOrder.ts +105 -0
- package/ui/src/hooks/useAutosaveIndicator.ts +72 -0
- package/ui/src/hooks/useCompanyPageMemory.test.ts +90 -0
- package/ui/src/hooks/useCompanyPageMemory.ts +79 -0
- package/ui/src/hooks/useDateRange.ts +120 -0
- package/ui/src/hooks/useInboxBadge.ts +132 -0
- package/ui/src/hooks/useKeyboardShortcuts.ts +40 -0
- package/ui/src/hooks/useProjectOrder.ts +106 -0
- package/ui/src/index.css +770 -0
- package/ui/src/lib/agent-icons.ts +99 -0
- package/ui/src/lib/agent-order.ts +107 -0
- package/ui/src/lib/agent-skills-state.test.ts +90 -0
- package/ui/src/lib/agent-skills-state.ts +41 -0
- package/ui/src/lib/assignees.test.ts +92 -0
- package/ui/src/lib/assignees.ts +82 -0
- package/ui/src/lib/color-contrast.ts +107 -0
- package/ui/src/lib/company-export-selection.test.ts +41 -0
- package/ui/src/lib/company-export-selection.ts +57 -0
- package/ui/src/lib/company-page-memory.ts +65 -0
- package/ui/src/lib/company-portability-sidebar.test.ts +101 -0
- package/ui/src/lib/company-portability-sidebar.ts +62 -0
- package/ui/src/lib/company-routes.ts +88 -0
- package/ui/src/lib/company-selection.test.ts +34 -0
- package/ui/src/lib/company-selection.ts +18 -0
- package/ui/src/lib/groupBy.ts +11 -0
- package/ui/src/lib/inbox.test.ts +404 -0
- package/ui/src/lib/inbox.ts +292 -0
- package/ui/src/lib/instance-settings.test.ts +26 -0
- package/ui/src/lib/instance-settings.ts +25 -0
- package/ui/src/lib/issueDetailBreadcrumb.ts +24 -0
- package/ui/src/lib/legacy-agent-config.test.ts +40 -0
- package/ui/src/lib/legacy-agent-config.ts +17 -0
- package/ui/src/lib/mention-aware-link-node.test.ts +50 -0
- package/ui/src/lib/mention-aware-link-node.ts +67 -0
- package/ui/src/lib/mention-chips.ts +168 -0
- package/ui/src/lib/mention-deletion.test.ts +87 -0
- package/ui/src/lib/mention-deletion.ts +143 -0
- package/ui/src/lib/model-utils.ts +16 -0
- package/ui/src/lib/onboarding-goal.test.ts +22 -0
- package/ui/src/lib/onboarding-goal.ts +18 -0
- package/ui/src/lib/onboarding-launch.test.ts +131 -0
- package/ui/src/lib/onboarding-launch.ts +54 -0
- package/ui/src/lib/onboarding-route.test.ts +80 -0
- package/ui/src/lib/onboarding-route.ts +51 -0
- package/ui/src/lib/portable-files.ts +42 -0
- package/ui/src/lib/project-order.ts +71 -0
- package/ui/src/lib/queryKeys.ts +140 -0
- package/ui/src/lib/recent-assignees.ts +36 -0
- package/ui/src/lib/router.tsx +76 -0
- package/ui/src/lib/routine-trigger-patch.test.ts +72 -0
- package/ui/src/lib/routine-trigger-patch.ts +31 -0
- package/ui/src/lib/status-colors.ts +108 -0
- package/ui/src/lib/timeAgo.ts +31 -0
- package/ui/src/lib/utils.ts +168 -0
- package/ui/src/lib/worktree-branding.ts +65 -0
- package/ui/src/lib/zip.test.ts +289 -0
- package/ui/src/lib/zip.ts +284 -0
- package/ui/src/main.tsx +67 -0
- package/ui/src/pages/Activity.tsx +141 -0
- package/ui/src/pages/AgentDetail.tsx +4053 -0
- package/ui/src/pages/Agents.tsx +415 -0
- package/ui/src/pages/ApprovalDetail.tsx +369 -0
- package/ui/src/pages/Approvals.tsx +132 -0
- package/ui/src/pages/Auth.tsx +180 -0
- package/ui/src/pages/BoardClaim.tsx +125 -0
- package/ui/src/pages/CliAuth.tsx +184 -0
- package/ui/src/pages/Companies.tsx +297 -0
- package/ui/src/pages/CompanyExport.tsx +1019 -0
- package/ui/src/pages/CompanyImport.tsx +1355 -0
- package/ui/src/pages/CompanySettings.tsx +661 -0
- package/ui/src/pages/CompanySkills.tsx +1171 -0
- package/ui/src/pages/Costs.tsx +1103 -0
- package/ui/src/pages/Dashboard.tsx +388 -0
- package/ui/src/pages/DesignGuide.tsx +1330 -0
- package/ui/src/pages/ExecutionWorkspaceDetail.tsx +82 -0
- package/ui/src/pages/GoalDetail.tsx +197 -0
- package/ui/src/pages/Goals.tsx +63 -0
- package/ui/src/pages/Inbox.tsx +1291 -0
- package/ui/src/pages/InstanceExperimentalSettings.tsx +139 -0
- package/ui/src/pages/InstanceGeneralSettings.tsx +104 -0
- package/ui/src/pages/InstanceSettings.tsx +284 -0
- package/ui/src/pages/InviteLanding.tsx +320 -0
- package/ui/src/pages/IssueDetail.tsx +1201 -0
- package/ui/src/pages/Issues.tsx +116 -0
- package/ui/src/pages/MyIssues.tsx +72 -0
- package/ui/src/pages/NewAgent.tsx +353 -0
- package/ui/src/pages/NotFound.tsx +66 -0
- package/ui/src/pages/Org.tsx +132 -0
- package/ui/src/pages/OrgChart.tsx +447 -0
- package/ui/src/pages/PluginManager.tsx +510 -0
- package/ui/src/pages/PluginPage.tsx +156 -0
- package/ui/src/pages/PluginSettings.tsx +836 -0
- package/ui/src/pages/ProjectDetail.tsx +633 -0
- package/ui/src/pages/Projects.tsx +87 -0
- package/ui/src/pages/RoutineDetail.tsx +1022 -0
- package/ui/src/pages/Routines.tsx +661 -0
- package/ui/src/pages/RunTranscriptUxLab.tsx +334 -0
- package/ui/src/pages/VisualOffice.tsx +243 -0
- package/ui/src/plugins/bridge-init.ts +69 -0
- package/ui/src/plugins/bridge.ts +476 -0
- package/ui/src/plugins/launchers.tsx +834 -0
- package/ui/src/plugins/slots.tsx +855 -0
- package/ui/tsconfig.json +21 -0
- package/ui/vite.config.ts +23 -0
- package/ui/vitest.config.ts +14 -0
- package/vitest.config.ts +11 -0
|
@@ -0,0 +1,1103 @@
|
|
|
1
|
+
import { useEffect, useMemo, useRef, useState, type ComponentType } from "react";
|
|
2
|
+
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
3
|
+
import type {
|
|
4
|
+
BudgetPolicySummary,
|
|
5
|
+
CostByAgentModel,
|
|
6
|
+
CostByBiller,
|
|
7
|
+
CostByProviderModel,
|
|
8
|
+
CostWindowSpendRow,
|
|
9
|
+
FinanceEvent,
|
|
10
|
+
QuotaWindow,
|
|
11
|
+
} from "@corporateai/shared";
|
|
12
|
+
import { ArrowDownLeft, ArrowUpRight, ChevronDown, ChevronRight, Coins, DollarSign, ReceiptText } from "lucide-react";
|
|
13
|
+
import { budgetsApi } from "../api/budgets";
|
|
14
|
+
import { costsApi } from "../api/costs";
|
|
15
|
+
import { BillerSpendCard } from "../components/BillerSpendCard";
|
|
16
|
+
import { BudgetIncidentCard } from "../components/BudgetIncidentCard";
|
|
17
|
+
import { BudgetPolicyCard } from "../components/BudgetPolicyCard";
|
|
18
|
+
import { EmptyState } from "../components/EmptyState";
|
|
19
|
+
import { FinanceBillerCard } from "../components/FinanceBillerCard";
|
|
20
|
+
import { FinanceKindCard } from "../components/FinanceKindCard";
|
|
21
|
+
import { FinanceTimelineCard } from "../components/FinanceTimelineCard";
|
|
22
|
+
import { Identity } from "../components/Identity";
|
|
23
|
+
import { PageSkeleton } from "../components/PageSkeleton";
|
|
24
|
+
import { PageTabBar } from "../components/PageTabBar";
|
|
25
|
+
import { ProviderQuotaCard } from "../components/ProviderQuotaCard";
|
|
26
|
+
import { StatusBadge } from "../components/StatusBadge";
|
|
27
|
+
import { useBreadcrumbs } from "../context/BreadcrumbContext";
|
|
28
|
+
import { useCompany } from "../context/CompanyContext";
|
|
29
|
+
import { useDateRange, PRESET_KEYS, PRESET_LABELS } from "../hooks/useDateRange";
|
|
30
|
+
import { queryKeys } from "../lib/queryKeys";
|
|
31
|
+
import { billingTypeDisplayName, cn, formatCents, formatTokens, providerDisplayName } from "../lib/utils";
|
|
32
|
+
import { Button } from "@/components/ui/button";
|
|
33
|
+
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
|
34
|
+
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
|
35
|
+
|
|
36
|
+
const NO_COMPANY = "__none__";
|
|
37
|
+
|
|
38
|
+
function currentWeekRange(): { from: string; to: string } {
|
|
39
|
+
const now = new Date();
|
|
40
|
+
const day = now.getDay();
|
|
41
|
+
const diffToMon = day === 0 ? -6 : 1 - day;
|
|
42
|
+
const mon = new Date(now.getFullYear(), now.getMonth(), now.getDate() + diffToMon, 0, 0, 0, 0);
|
|
43
|
+
const sun = new Date(mon.getFullYear(), mon.getMonth(), mon.getDate() + 6, 23, 59, 59, 999);
|
|
44
|
+
return { from: mon.toISOString(), to: sun.toISOString() };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function ProviderTabLabel({ provider, rows }: { provider: string; rows: CostByProviderModel[] }) {
|
|
48
|
+
const totalTokens = rows.reduce((sum, row) => sum + row.inputTokens + row.cachedInputTokens + row.outputTokens, 0);
|
|
49
|
+
const totalCost = rows.reduce((sum, row) => sum + row.costCents, 0);
|
|
50
|
+
return (
|
|
51
|
+
<span className="flex items-center gap-1.5">
|
|
52
|
+
<span>{providerDisplayName(provider)}</span>
|
|
53
|
+
<span className="font-mono text-xs text-muted-foreground">{formatTokens(totalTokens)}</span>
|
|
54
|
+
<span className="text-xs text-muted-foreground">{formatCents(totalCost)}</span>
|
|
55
|
+
</span>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function BillerTabLabel({ biller, rows }: { biller: string; rows: CostByBiller[] }) {
|
|
60
|
+
const totalTokens = rows.reduce((sum, row) => sum + row.inputTokens + row.cachedInputTokens + row.outputTokens, 0);
|
|
61
|
+
const totalCost = rows.reduce((sum, row) => sum + row.costCents, 0);
|
|
62
|
+
return (
|
|
63
|
+
<span className="flex items-center gap-1.5">
|
|
64
|
+
<span>{providerDisplayName(biller)}</span>
|
|
65
|
+
<span className="font-mono text-xs text-muted-foreground">{formatTokens(totalTokens)}</span>
|
|
66
|
+
<span className="text-xs text-muted-foreground">{formatCents(totalCost)}</span>
|
|
67
|
+
</span>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function MetricTile({
|
|
72
|
+
label,
|
|
73
|
+
value,
|
|
74
|
+
subtitle,
|
|
75
|
+
icon: Icon,
|
|
76
|
+
}: {
|
|
77
|
+
label: string;
|
|
78
|
+
value: string;
|
|
79
|
+
subtitle: string;
|
|
80
|
+
icon: ComponentType<{ className?: string }>;
|
|
81
|
+
}) {
|
|
82
|
+
return (
|
|
83
|
+
<div className="border border-border p-4">
|
|
84
|
+
<div className="flex items-center justify-between gap-3">
|
|
85
|
+
<div className="min-w-0">
|
|
86
|
+
<div className="text-[11px] uppercase tracking-[0.16em] text-muted-foreground">{label}</div>
|
|
87
|
+
<div className="mt-2 text-2xl font-semibold tabular-nums">{value}</div>
|
|
88
|
+
<div className="mt-1 text-xs leading-5 text-muted-foreground">{subtitle}</div>
|
|
89
|
+
</div>
|
|
90
|
+
<div className="flex h-9 w-9 shrink-0 items-center justify-center border border-border">
|
|
91
|
+
<Icon className="h-4 w-4 text-muted-foreground" />
|
|
92
|
+
</div>
|
|
93
|
+
</div>
|
|
94
|
+
</div>
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function FinanceSummaryCard({
|
|
99
|
+
debitCents,
|
|
100
|
+
creditCents,
|
|
101
|
+
netCents,
|
|
102
|
+
estimatedDebitCents,
|
|
103
|
+
eventCount,
|
|
104
|
+
}: {
|
|
105
|
+
debitCents: number;
|
|
106
|
+
creditCents: number;
|
|
107
|
+
netCents: number;
|
|
108
|
+
estimatedDebitCents: number;
|
|
109
|
+
eventCount: number;
|
|
110
|
+
}) {
|
|
111
|
+
return (
|
|
112
|
+
<Card>
|
|
113
|
+
<CardHeader className="px-5 pt-5 pb-2">
|
|
114
|
+
<CardTitle className="text-base">Finance ledger</CardTitle>
|
|
115
|
+
<CardDescription>
|
|
116
|
+
Account-level charges that do not map to a single inference request.
|
|
117
|
+
</CardDescription>
|
|
118
|
+
</CardHeader>
|
|
119
|
+
<CardContent className="grid gap-3 px-5 pb-5 pt-2 sm:grid-cols-2 xl:grid-cols-4">
|
|
120
|
+
<MetricTile
|
|
121
|
+
label="Debits"
|
|
122
|
+
value={formatCents(debitCents)}
|
|
123
|
+
subtitle={`${eventCount} total event${eventCount === 1 ? "" : "s"} in range`}
|
|
124
|
+
icon={ArrowUpRight}
|
|
125
|
+
/>
|
|
126
|
+
<MetricTile
|
|
127
|
+
label="Credits"
|
|
128
|
+
value={formatCents(creditCents)}
|
|
129
|
+
subtitle="Refunds, offsets, and credit returns"
|
|
130
|
+
icon={ArrowDownLeft}
|
|
131
|
+
/>
|
|
132
|
+
<MetricTile
|
|
133
|
+
label="Net"
|
|
134
|
+
value={formatCents(netCents)}
|
|
135
|
+
subtitle="Debit minus credit for the selected period"
|
|
136
|
+
icon={ReceiptText}
|
|
137
|
+
/>
|
|
138
|
+
<MetricTile
|
|
139
|
+
label="Estimated"
|
|
140
|
+
value={formatCents(estimatedDebitCents)}
|
|
141
|
+
subtitle="Estimated debits that are not yet invoice-authoritative"
|
|
142
|
+
icon={Coins}
|
|
143
|
+
/>
|
|
144
|
+
</CardContent>
|
|
145
|
+
</Card>
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export function Costs() {
|
|
150
|
+
const { selectedCompanyId } = useCompany();
|
|
151
|
+
const { setBreadcrumbs } = useBreadcrumbs();
|
|
152
|
+
const queryClient = useQueryClient();
|
|
153
|
+
|
|
154
|
+
const [mainTab, setMainTab] = useState<"overview" | "budgets" | "providers" | "billers" | "finance">("overview");
|
|
155
|
+
const [activeProvider, setActiveProvider] = useState("all");
|
|
156
|
+
const [activeBiller, setActiveBiller] = useState("all");
|
|
157
|
+
|
|
158
|
+
const {
|
|
159
|
+
preset,
|
|
160
|
+
setPreset,
|
|
161
|
+
customFrom,
|
|
162
|
+
setCustomFrom,
|
|
163
|
+
customTo,
|
|
164
|
+
setCustomTo,
|
|
165
|
+
from,
|
|
166
|
+
to,
|
|
167
|
+
customReady,
|
|
168
|
+
} = useDateRange();
|
|
169
|
+
|
|
170
|
+
useEffect(() => {
|
|
171
|
+
setBreadcrumbs([{ label: "Costs" }]);
|
|
172
|
+
}, [setBreadcrumbs]);
|
|
173
|
+
|
|
174
|
+
const [today, setToday] = useState(() => new Date().toDateString());
|
|
175
|
+
const todayTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
176
|
+
useEffect(() => {
|
|
177
|
+
const schedule = () => {
|
|
178
|
+
const now = new Date();
|
|
179
|
+
const ms = new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1).getTime() - now.getTime();
|
|
180
|
+
todayTimerRef.current = setTimeout(() => {
|
|
181
|
+
setToday(new Date().toDateString());
|
|
182
|
+
schedule();
|
|
183
|
+
}, ms);
|
|
184
|
+
};
|
|
185
|
+
schedule();
|
|
186
|
+
return () => {
|
|
187
|
+
if (todayTimerRef.current != null) clearTimeout(todayTimerRef.current);
|
|
188
|
+
};
|
|
189
|
+
}, []);
|
|
190
|
+
|
|
191
|
+
const weekRange = useMemo(() => currentWeekRange(), [today]);
|
|
192
|
+
const companyId = selectedCompanyId ?? NO_COMPANY;
|
|
193
|
+
|
|
194
|
+
const { data: budgetData, isLoading: budgetLoading, error: budgetError } = useQuery({
|
|
195
|
+
queryKey: queryKeys.budgets.overview(companyId),
|
|
196
|
+
queryFn: () => budgetsApi.overview(companyId),
|
|
197
|
+
enabled: !!selectedCompanyId && customReady,
|
|
198
|
+
refetchInterval: 30_000,
|
|
199
|
+
staleTime: 5_000,
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
const invalidateBudgetViews = () => {
|
|
203
|
+
if (!selectedCompanyId) return;
|
|
204
|
+
queryClient.invalidateQueries({ queryKey: queryKeys.budgets.overview(selectedCompanyId) });
|
|
205
|
+
queryClient.invalidateQueries({ queryKey: queryKeys.dashboard(selectedCompanyId) });
|
|
206
|
+
queryClient.invalidateQueries({ queryKey: queryKeys.agents.list(selectedCompanyId) });
|
|
207
|
+
queryClient.invalidateQueries({ queryKey: queryKeys.projects.list(selectedCompanyId) });
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
const policyMutation = useMutation({
|
|
211
|
+
mutationFn: (input: {
|
|
212
|
+
scopeType: BudgetPolicySummary["scopeType"];
|
|
213
|
+
scopeId: string;
|
|
214
|
+
amount: number;
|
|
215
|
+
windowKind: BudgetPolicySummary["windowKind"];
|
|
216
|
+
}) =>
|
|
217
|
+
budgetsApi.upsertPolicy(companyId, {
|
|
218
|
+
scopeType: input.scopeType,
|
|
219
|
+
scopeId: input.scopeId,
|
|
220
|
+
amount: input.amount,
|
|
221
|
+
windowKind: input.windowKind,
|
|
222
|
+
}),
|
|
223
|
+
onSuccess: invalidateBudgetViews,
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
const incidentMutation = useMutation({
|
|
227
|
+
mutationFn: (input: { incidentId: string; action: "keep_paused" | "raise_budget_and_resume"; amount?: number }) =>
|
|
228
|
+
budgetsApi.resolveIncident(companyId, input.incidentId, input),
|
|
229
|
+
onSuccess: invalidateBudgetViews,
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
const { data: spendData, isLoading: spendLoading, error: spendError } = useQuery({
|
|
233
|
+
queryKey: queryKeys.costs(companyId, from || undefined, to || undefined),
|
|
234
|
+
queryFn: async () => {
|
|
235
|
+
const [summary, byAgent, byProject, byAgentModel] = await Promise.all([
|
|
236
|
+
costsApi.summary(companyId, from || undefined, to || undefined),
|
|
237
|
+
costsApi.byAgent(companyId, from || undefined, to || undefined),
|
|
238
|
+
costsApi.byProject(companyId, from || undefined, to || undefined),
|
|
239
|
+
costsApi.byAgentModel(companyId, from || undefined, to || undefined),
|
|
240
|
+
]);
|
|
241
|
+
return { summary, byAgent, byProject, byAgentModel };
|
|
242
|
+
},
|
|
243
|
+
enabled: !!selectedCompanyId && customReady,
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
const { data: financeData, isLoading: financeLoading, error: financeError } = useQuery({
|
|
247
|
+
queryKey: [
|
|
248
|
+
queryKeys.financeSummary(companyId, from || undefined, to || undefined),
|
|
249
|
+
queryKeys.financeByBiller(companyId, from || undefined, to || undefined),
|
|
250
|
+
queryKeys.financeByKind(companyId, from || undefined, to || undefined),
|
|
251
|
+
queryKeys.financeEvents(companyId, from || undefined, to || undefined, 18),
|
|
252
|
+
],
|
|
253
|
+
queryFn: async () => {
|
|
254
|
+
const [summary, byBiller, byKind, events] = await Promise.all([
|
|
255
|
+
costsApi.financeSummary(companyId, from || undefined, to || undefined),
|
|
256
|
+
costsApi.financeByBiller(companyId, from || undefined, to || undefined),
|
|
257
|
+
costsApi.financeByKind(companyId, from || undefined, to || undefined),
|
|
258
|
+
costsApi.financeEvents(companyId, from || undefined, to || undefined, 18),
|
|
259
|
+
]);
|
|
260
|
+
return { summary, byBiller, byKind, events };
|
|
261
|
+
},
|
|
262
|
+
enabled: !!selectedCompanyId && customReady,
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
const [expandedAgents, setExpandedAgents] = useState<Set<string>>(new Set());
|
|
266
|
+
useEffect(() => {
|
|
267
|
+
setExpandedAgents(new Set());
|
|
268
|
+
}, [companyId, from, to]);
|
|
269
|
+
|
|
270
|
+
function toggleAgent(agentId: string) {
|
|
271
|
+
setExpandedAgents((prev) => {
|
|
272
|
+
const next = new Set(prev);
|
|
273
|
+
if (next.has(agentId)) next.delete(agentId);
|
|
274
|
+
else next.add(agentId);
|
|
275
|
+
return next;
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
const agentModelRows = useMemo(() => {
|
|
280
|
+
const map = new Map<string, CostByAgentModel[]>();
|
|
281
|
+
for (const row of spendData?.byAgentModel ?? []) {
|
|
282
|
+
const rows = map.get(row.agentId) ?? [];
|
|
283
|
+
rows.push(row);
|
|
284
|
+
map.set(row.agentId, rows);
|
|
285
|
+
}
|
|
286
|
+
for (const [agentId, rows] of map) {
|
|
287
|
+
map.set(agentId, rows.slice().sort((a, b) => b.costCents - a.costCents));
|
|
288
|
+
}
|
|
289
|
+
return map;
|
|
290
|
+
}, [spendData?.byAgentModel]);
|
|
291
|
+
|
|
292
|
+
const { data: providerData } = useQuery({
|
|
293
|
+
queryKey: queryKeys.usageByProvider(companyId, from || undefined, to || undefined),
|
|
294
|
+
queryFn: () => costsApi.byProvider(companyId, from || undefined, to || undefined),
|
|
295
|
+
enabled: !!selectedCompanyId && customReady && (mainTab === "providers" || mainTab === "billers"),
|
|
296
|
+
refetchInterval: 30_000,
|
|
297
|
+
staleTime: 10_000,
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
const { data: billerData } = useQuery({
|
|
301
|
+
queryKey: queryKeys.usageByBiller(companyId, from || undefined, to || undefined),
|
|
302
|
+
queryFn: () => costsApi.byBiller(companyId, from || undefined, to || undefined),
|
|
303
|
+
enabled: !!selectedCompanyId && customReady && mainTab === "billers",
|
|
304
|
+
refetchInterval: 30_000,
|
|
305
|
+
staleTime: 10_000,
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
const { data: weekData } = useQuery({
|
|
309
|
+
queryKey: queryKeys.usageByProvider(companyId, weekRange.from, weekRange.to),
|
|
310
|
+
queryFn: () => costsApi.byProvider(companyId, weekRange.from, weekRange.to),
|
|
311
|
+
enabled: !!selectedCompanyId && (mainTab === "providers" || mainTab === "billers"),
|
|
312
|
+
refetchInterval: 30_000,
|
|
313
|
+
staleTime: 10_000,
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
const { data: weekBillerData } = useQuery({
|
|
317
|
+
queryKey: queryKeys.usageByBiller(companyId, weekRange.from, weekRange.to),
|
|
318
|
+
queryFn: () => costsApi.byBiller(companyId, weekRange.from, weekRange.to),
|
|
319
|
+
enabled: !!selectedCompanyId && mainTab === "billers",
|
|
320
|
+
refetchInterval: 30_000,
|
|
321
|
+
staleTime: 10_000,
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
const { data: windowData } = useQuery({
|
|
325
|
+
queryKey: queryKeys.usageWindowSpend(companyId),
|
|
326
|
+
queryFn: () => costsApi.windowSpend(companyId),
|
|
327
|
+
enabled: !!selectedCompanyId && mainTab === "providers",
|
|
328
|
+
refetchInterval: 30_000,
|
|
329
|
+
staleTime: 10_000,
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
const { data: quotaData, isLoading: quotaLoading } = useQuery({
|
|
333
|
+
queryKey: queryKeys.usageQuotaWindows(companyId),
|
|
334
|
+
queryFn: () => costsApi.quotaWindows(companyId),
|
|
335
|
+
enabled: !!selectedCompanyId && mainTab === "providers",
|
|
336
|
+
refetchInterval: 300_000,
|
|
337
|
+
staleTime: 60_000,
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
const byProvider = useMemo(() => {
|
|
341
|
+
const map = new Map<string, CostByProviderModel[]>();
|
|
342
|
+
for (const row of providerData ?? []) {
|
|
343
|
+
const rows = map.get(row.provider) ?? [];
|
|
344
|
+
rows.push(row);
|
|
345
|
+
map.set(row.provider, rows);
|
|
346
|
+
}
|
|
347
|
+
return map;
|
|
348
|
+
}, [providerData]);
|
|
349
|
+
|
|
350
|
+
const byBiller = useMemo(() => {
|
|
351
|
+
const map = new Map<string, CostByBiller[]>();
|
|
352
|
+
for (const row of billerData ?? []) {
|
|
353
|
+
const rows = map.get(row.biller) ?? [];
|
|
354
|
+
rows.push(row);
|
|
355
|
+
map.set(row.biller, rows);
|
|
356
|
+
}
|
|
357
|
+
return map;
|
|
358
|
+
}, [billerData]);
|
|
359
|
+
|
|
360
|
+
const weekSpendByProvider = useMemo(() => {
|
|
361
|
+
const map = new Map<string, number>();
|
|
362
|
+
for (const row of weekData ?? []) {
|
|
363
|
+
map.set(row.provider, (map.get(row.provider) ?? 0) + row.costCents);
|
|
364
|
+
}
|
|
365
|
+
return map;
|
|
366
|
+
}, [weekData]);
|
|
367
|
+
|
|
368
|
+
const weekSpendByBiller = useMemo(() => {
|
|
369
|
+
const map = new Map<string, number>();
|
|
370
|
+
for (const row of weekBillerData ?? []) {
|
|
371
|
+
map.set(row.biller, (map.get(row.biller) ?? 0) + row.costCents);
|
|
372
|
+
}
|
|
373
|
+
return map;
|
|
374
|
+
}, [weekBillerData]);
|
|
375
|
+
|
|
376
|
+
const windowSpendByProvider = useMemo(() => {
|
|
377
|
+
const map = new Map<string, CostWindowSpendRow[]>();
|
|
378
|
+
for (const row of windowData ?? []) {
|
|
379
|
+
const rows = map.get(row.provider) ?? [];
|
|
380
|
+
rows.push(row);
|
|
381
|
+
map.set(row.provider, rows);
|
|
382
|
+
}
|
|
383
|
+
return map;
|
|
384
|
+
}, [windowData]);
|
|
385
|
+
|
|
386
|
+
const quotaWindowsByProvider = useMemo(() => {
|
|
387
|
+
const map = new Map<string, QuotaWindow[]>();
|
|
388
|
+
for (const result of quotaData ?? []) {
|
|
389
|
+
if (result.ok && result.windows.length > 0) {
|
|
390
|
+
map.set(result.provider, result.windows);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
return map;
|
|
394
|
+
}, [quotaData]);
|
|
395
|
+
|
|
396
|
+
const quotaErrorsByProvider = useMemo(() => {
|
|
397
|
+
const map = new Map<string, string>();
|
|
398
|
+
for (const result of quotaData ?? []) {
|
|
399
|
+
if (!result.ok && result.error) map.set(result.provider, result.error);
|
|
400
|
+
}
|
|
401
|
+
return map;
|
|
402
|
+
}, [quotaData]);
|
|
403
|
+
|
|
404
|
+
const quotaSourcesByProvider = useMemo(() => {
|
|
405
|
+
const map = new Map<string, string>();
|
|
406
|
+
for (const result of quotaData ?? []) {
|
|
407
|
+
if (typeof result.source === "string" && result.source.length > 0) {
|
|
408
|
+
map.set(result.provider, result.source);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
return map;
|
|
412
|
+
}, [quotaData]);
|
|
413
|
+
|
|
414
|
+
const deficitNotchByProvider = useMemo(() => {
|
|
415
|
+
const map = new Map<string, boolean>();
|
|
416
|
+
if (preset !== "mtd") return map;
|
|
417
|
+
const budget = spendData?.summary.budgetCents ?? 0;
|
|
418
|
+
if (budget <= 0) return map;
|
|
419
|
+
const totalSpend = spendData?.summary.spendCents ?? 0;
|
|
420
|
+
const now = new Date();
|
|
421
|
+
const daysElapsed = now.getDate();
|
|
422
|
+
const daysInMonth = new Date(now.getFullYear(), now.getMonth() + 1, 0).getDate();
|
|
423
|
+
for (const [providerKey, rows] of byProvider) {
|
|
424
|
+
const providerCostCents = rows.reduce((sum, row) => sum + row.costCents, 0);
|
|
425
|
+
const providerShare = totalSpend > 0 ? providerCostCents / totalSpend : 0;
|
|
426
|
+
const providerBudget = budget * providerShare;
|
|
427
|
+
if (providerBudget <= 0) {
|
|
428
|
+
map.set(providerKey, false);
|
|
429
|
+
continue;
|
|
430
|
+
}
|
|
431
|
+
const burnRate = providerCostCents / Math.max(daysElapsed, 1);
|
|
432
|
+
map.set(providerKey, providerCostCents + burnRate * (daysInMonth - daysElapsed) > providerBudget);
|
|
433
|
+
}
|
|
434
|
+
return map;
|
|
435
|
+
}, [preset, spendData, byProvider]);
|
|
436
|
+
|
|
437
|
+
const providers = useMemo(() => Array.from(byProvider.keys()), [byProvider]);
|
|
438
|
+
const billers = useMemo(() => Array.from(byBiller.keys()), [byBiller]);
|
|
439
|
+
|
|
440
|
+
const effectiveProvider =
|
|
441
|
+
activeProvider === "all" || providers.includes(activeProvider) ? activeProvider : "all";
|
|
442
|
+
useEffect(() => {
|
|
443
|
+
if (effectiveProvider !== activeProvider) setActiveProvider("all");
|
|
444
|
+
}, [effectiveProvider, activeProvider]);
|
|
445
|
+
|
|
446
|
+
const effectiveBiller =
|
|
447
|
+
activeBiller === "all" || billers.includes(activeBiller) ? activeBiller : "all";
|
|
448
|
+
useEffect(() => {
|
|
449
|
+
if (effectiveBiller !== activeBiller) setActiveBiller("all");
|
|
450
|
+
}, [effectiveBiller, activeBiller]);
|
|
451
|
+
|
|
452
|
+
const providerTabItems = useMemo(() => {
|
|
453
|
+
const providerKeys = Array.from(byProvider.keys());
|
|
454
|
+
const allTokens = providerKeys.reduce(
|
|
455
|
+
(sum, provider) => sum + (byProvider.get(provider)?.reduce((acc, row) => acc + row.inputTokens + row.cachedInputTokens + row.outputTokens, 0) ?? 0),
|
|
456
|
+
0,
|
|
457
|
+
);
|
|
458
|
+
const allCents = providerKeys.reduce(
|
|
459
|
+
(sum, provider) => sum + (byProvider.get(provider)?.reduce((acc, row) => acc + row.costCents, 0) ?? 0),
|
|
460
|
+
0,
|
|
461
|
+
);
|
|
462
|
+
return [
|
|
463
|
+
{
|
|
464
|
+
value: "all",
|
|
465
|
+
label: (
|
|
466
|
+
<span className="flex items-center gap-1.5">
|
|
467
|
+
<span>All providers</span>
|
|
468
|
+
{providerKeys.length > 0 ? (
|
|
469
|
+
<>
|
|
470
|
+
<span className="font-mono text-xs text-muted-foreground">{formatTokens(allTokens)}</span>
|
|
471
|
+
<span className="text-xs text-muted-foreground">{formatCents(allCents)}</span>
|
|
472
|
+
</>
|
|
473
|
+
) : null}
|
|
474
|
+
</span>
|
|
475
|
+
),
|
|
476
|
+
},
|
|
477
|
+
...providerKeys.map((provider) => ({
|
|
478
|
+
value: provider,
|
|
479
|
+
label: <ProviderTabLabel provider={provider} rows={byProvider.get(provider) ?? []} />,
|
|
480
|
+
})),
|
|
481
|
+
];
|
|
482
|
+
}, [byProvider]);
|
|
483
|
+
|
|
484
|
+
const billerTabItems = useMemo(() => {
|
|
485
|
+
const billerKeys = Array.from(byBiller.keys());
|
|
486
|
+
const allTokens = billerKeys.reduce(
|
|
487
|
+
(sum, biller) => sum + (byBiller.get(biller)?.reduce((acc, row) => acc + row.inputTokens + row.cachedInputTokens + row.outputTokens, 0) ?? 0),
|
|
488
|
+
0,
|
|
489
|
+
);
|
|
490
|
+
const allCents = billerKeys.reduce(
|
|
491
|
+
(sum, biller) => sum + (byBiller.get(biller)?.reduce((acc, row) => acc + row.costCents, 0) ?? 0),
|
|
492
|
+
0,
|
|
493
|
+
);
|
|
494
|
+
return [
|
|
495
|
+
{
|
|
496
|
+
value: "all",
|
|
497
|
+
label: (
|
|
498
|
+
<span className="flex items-center gap-1.5">
|
|
499
|
+
<span>All billers</span>
|
|
500
|
+
{billerKeys.length > 0 ? (
|
|
501
|
+
<>
|
|
502
|
+
<span className="font-mono text-xs text-muted-foreground">{formatTokens(allTokens)}</span>
|
|
503
|
+
<span className="text-xs text-muted-foreground">{formatCents(allCents)}</span>
|
|
504
|
+
</>
|
|
505
|
+
) : null}
|
|
506
|
+
</span>
|
|
507
|
+
),
|
|
508
|
+
},
|
|
509
|
+
...billerKeys.map((biller) => ({
|
|
510
|
+
value: biller,
|
|
511
|
+
label: <BillerTabLabel biller={biller} rows={byBiller.get(biller) ?? []} />,
|
|
512
|
+
})),
|
|
513
|
+
];
|
|
514
|
+
}, [byBiller]);
|
|
515
|
+
|
|
516
|
+
const inferenceTokenTotal =
|
|
517
|
+
(spendData?.byAgent ?? []).reduce(
|
|
518
|
+
(sum, row) => sum + row.inputTokens + row.cachedInputTokens + row.outputTokens,
|
|
519
|
+
0,
|
|
520
|
+
);
|
|
521
|
+
|
|
522
|
+
const topFinanceEvents = (financeData?.events ?? []) as FinanceEvent[];
|
|
523
|
+
const budgetPolicies = budgetData?.policies ?? [];
|
|
524
|
+
const activeBudgetIncidents = budgetData?.activeIncidents ?? [];
|
|
525
|
+
const budgetPoliciesByScope = useMemo(() => ({
|
|
526
|
+
company: budgetPolicies.filter((policy) => policy.scopeType === "company"),
|
|
527
|
+
agent: budgetPolicies.filter((policy) => policy.scopeType === "agent"),
|
|
528
|
+
project: budgetPolicies.filter((policy) => policy.scopeType === "project"),
|
|
529
|
+
}), [budgetPolicies]);
|
|
530
|
+
|
|
531
|
+
if (!selectedCompanyId) {
|
|
532
|
+
return <EmptyState icon={DollarSign} message="Select a company to view costs." />;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
const showCustomPrompt = preset === "custom" && !customReady;
|
|
536
|
+
const showOverviewLoading = (spendLoading || financeLoading) && customReady;
|
|
537
|
+
const overviewError = spendError ?? financeError;
|
|
538
|
+
|
|
539
|
+
return (
|
|
540
|
+
<div className="space-y-6">
|
|
541
|
+
<div className="space-y-5">
|
|
542
|
+
<div className="flex flex-col gap-4 lg:flex-row lg:items-start lg:justify-between">
|
|
543
|
+
<div>
|
|
544
|
+
<h1 className="text-3xl font-semibold tracking-tight">Costs</h1>
|
|
545
|
+
<p className="mt-2 max-w-2xl text-sm leading-6 text-muted-foreground">
|
|
546
|
+
Inference spend, platform fees, credits, and live quota windows.
|
|
547
|
+
</p>
|
|
548
|
+
</div>
|
|
549
|
+
|
|
550
|
+
<div className="flex flex-wrap items-center gap-2">
|
|
551
|
+
{PRESET_KEYS.map((key) => (
|
|
552
|
+
<Button
|
|
553
|
+
key={key}
|
|
554
|
+
variant={preset === key ? "secondary" : "ghost"}
|
|
555
|
+
size="sm"
|
|
556
|
+
onClick={() => setPreset(key)}
|
|
557
|
+
>
|
|
558
|
+
{PRESET_LABELS[key]}
|
|
559
|
+
</Button>
|
|
560
|
+
))}
|
|
561
|
+
</div>
|
|
562
|
+
</div>
|
|
563
|
+
|
|
564
|
+
{preset === "custom" ? (
|
|
565
|
+
<div className="flex flex-wrap items-center gap-2 border border-border p-3">
|
|
566
|
+
<input
|
|
567
|
+
type="date"
|
|
568
|
+
value={customFrom}
|
|
569
|
+
onChange={(event) => setCustomFrom(event.target.value)}
|
|
570
|
+
className="h-9 rounded-md border border-input bg-background px-3 text-sm text-foreground"
|
|
571
|
+
/>
|
|
572
|
+
<span className="text-sm text-muted-foreground">to</span>
|
|
573
|
+
<input
|
|
574
|
+
type="date"
|
|
575
|
+
value={customTo}
|
|
576
|
+
onChange={(event) => setCustomTo(event.target.value)}
|
|
577
|
+
className="h-9 rounded-md border border-input bg-background px-3 text-sm text-foreground"
|
|
578
|
+
/>
|
|
579
|
+
</div>
|
|
580
|
+
) : null}
|
|
581
|
+
|
|
582
|
+
<div className="grid gap-3 lg:grid-cols-4">
|
|
583
|
+
<MetricTile
|
|
584
|
+
label="Inference spend"
|
|
585
|
+
value={formatCents(spendData?.summary.spendCents ?? 0)}
|
|
586
|
+
subtitle={`${formatTokens(inferenceTokenTotal)} tokens across request-scoped events`}
|
|
587
|
+
icon={DollarSign}
|
|
588
|
+
/>
|
|
589
|
+
<MetricTile
|
|
590
|
+
label="Budget"
|
|
591
|
+
value={activeBudgetIncidents.length > 0 ? String(activeBudgetIncidents.length) : (
|
|
592
|
+
spendData?.summary.budgetCents && spendData.summary.budgetCents > 0
|
|
593
|
+
? `${spendData.summary.utilizationPercent}%`
|
|
594
|
+
: "Open"
|
|
595
|
+
)}
|
|
596
|
+
subtitle={
|
|
597
|
+
activeBudgetIncidents.length > 0
|
|
598
|
+
? `${budgetData?.pausedAgentCount ?? 0} agents paused · ${budgetData?.pausedProjectCount ?? 0} projects paused`
|
|
599
|
+
: spendData?.summary.budgetCents && spendData.summary.budgetCents > 0
|
|
600
|
+
? `${formatCents(spendData.summary.spendCents)} of ${formatCents(spendData.summary.budgetCents)}`
|
|
601
|
+
: "No monthly cap configured"
|
|
602
|
+
}
|
|
603
|
+
icon={Coins}
|
|
604
|
+
/>
|
|
605
|
+
<MetricTile
|
|
606
|
+
label="Finance net"
|
|
607
|
+
value={formatCents(financeData?.summary.netCents ?? 0)}
|
|
608
|
+
subtitle={`${formatCents(financeData?.summary.debitCents ?? 0)} debits · ${formatCents(financeData?.summary.creditCents ?? 0)} credits`}
|
|
609
|
+
icon={ReceiptText}
|
|
610
|
+
/>
|
|
611
|
+
<MetricTile
|
|
612
|
+
label="Finance events"
|
|
613
|
+
value={String(financeData?.summary.eventCount ?? 0)}
|
|
614
|
+
subtitle={`${formatCents(financeData?.summary.estimatedDebitCents ?? 0)} estimated in range`}
|
|
615
|
+
icon={ArrowUpRight}
|
|
616
|
+
/>
|
|
617
|
+
</div>
|
|
618
|
+
</div>
|
|
619
|
+
|
|
620
|
+
<Tabs value={mainTab} onValueChange={(value) => setMainTab(value as typeof mainTab)}>
|
|
621
|
+
<TabsList variant="line" className="justify-start">
|
|
622
|
+
<TabsTrigger value="overview">Overview</TabsTrigger>
|
|
623
|
+
<TabsTrigger value="budgets">Budgets</TabsTrigger>
|
|
624
|
+
<TabsTrigger value="providers">Providers</TabsTrigger>
|
|
625
|
+
<TabsTrigger value="billers">Billers</TabsTrigger>
|
|
626
|
+
<TabsTrigger value="finance">Finance</TabsTrigger>
|
|
627
|
+
</TabsList>
|
|
628
|
+
|
|
629
|
+
<TabsContent value="overview" className="mt-4 space-y-4">
|
|
630
|
+
{showCustomPrompt ? (
|
|
631
|
+
<p className="text-sm text-muted-foreground">Select a start and end date to load data.</p>
|
|
632
|
+
) : showOverviewLoading ? (
|
|
633
|
+
<PageSkeleton variant="costs" />
|
|
634
|
+
) : overviewError ? (
|
|
635
|
+
<p className="text-sm text-destructive">{(overviewError as Error).message}</p>
|
|
636
|
+
) : (
|
|
637
|
+
<>
|
|
638
|
+
{activeBudgetIncidents.length > 0 ? (
|
|
639
|
+
<div className="grid gap-4 xl:grid-cols-2">
|
|
640
|
+
{activeBudgetIncidents.slice(0, 2).map((incident) => (
|
|
641
|
+
<BudgetIncidentCard
|
|
642
|
+
key={incident.id}
|
|
643
|
+
incident={incident}
|
|
644
|
+
isMutating={incidentMutation.isPending}
|
|
645
|
+
onKeepPaused={() => incidentMutation.mutate({ incidentId: incident.id, action: "keep_paused" })}
|
|
646
|
+
onRaiseAndResume={(amount) =>
|
|
647
|
+
incidentMutation.mutate({
|
|
648
|
+
incidentId: incident.id,
|
|
649
|
+
action: "raise_budget_and_resume",
|
|
650
|
+
amount,
|
|
651
|
+
})}
|
|
652
|
+
/>
|
|
653
|
+
))}
|
|
654
|
+
</div>
|
|
655
|
+
) : null}
|
|
656
|
+
|
|
657
|
+
<div className="grid gap-4 xl:grid-cols-[1.3fr,1fr]">
|
|
658
|
+
<Card>
|
|
659
|
+
<CardHeader className="px-5 pt-5 pb-2">
|
|
660
|
+
<CardTitle className="text-base">Inference ledger</CardTitle>
|
|
661
|
+
<CardDescription>
|
|
662
|
+
Request-scoped inference spend for the selected period.
|
|
663
|
+
</CardDescription>
|
|
664
|
+
</CardHeader>
|
|
665
|
+
<CardContent className="space-y-4 px-5 pb-5 pt-2">
|
|
666
|
+
<div className="flex flex-wrap items-end justify-between gap-3">
|
|
667
|
+
<div>
|
|
668
|
+
<div className="text-3xl font-semibold tabular-nums">
|
|
669
|
+
{formatCents(spendData?.summary.spendCents ?? 0)}
|
|
670
|
+
</div>
|
|
671
|
+
<div className="mt-1 text-sm text-muted-foreground">
|
|
672
|
+
{spendData?.summary.budgetCents && spendData.summary.budgetCents > 0
|
|
673
|
+
? `Budget ${formatCents(spendData.summary.budgetCents)}`
|
|
674
|
+
: "Unlimited budget"}
|
|
675
|
+
</div>
|
|
676
|
+
</div>
|
|
677
|
+
<div className="border border-border px-4 py-3 text-right">
|
|
678
|
+
<div className="text-[11px] uppercase tracking-[0.14em] text-muted-foreground">usage</div>
|
|
679
|
+
<div className="mt-1 text-lg font-medium tabular-nums">
|
|
680
|
+
{formatTokens(inferenceTokenTotal)}
|
|
681
|
+
</div>
|
|
682
|
+
</div>
|
|
683
|
+
</div>
|
|
684
|
+
{spendData?.summary.budgetCents && spendData.summary.budgetCents > 0 ? (
|
|
685
|
+
<div className="space-y-2">
|
|
686
|
+
<div className="h-2 overflow-hidden bg-muted">
|
|
687
|
+
<div
|
|
688
|
+
className={cn(
|
|
689
|
+
"h-full transition-[width,background-color] duration-150",
|
|
690
|
+
spendData.summary.utilizationPercent > 90
|
|
691
|
+
? "bg-red-400"
|
|
692
|
+
: spendData.summary.utilizationPercent > 70
|
|
693
|
+
? "bg-yellow-400"
|
|
694
|
+
: "bg-emerald-400",
|
|
695
|
+
)}
|
|
696
|
+
style={{ width: `${Math.min(100, spendData.summary.utilizationPercent)}%` }}
|
|
697
|
+
/>
|
|
698
|
+
</div>
|
|
699
|
+
<div className="text-xs text-muted-foreground">
|
|
700
|
+
{spendData.summary.utilizationPercent}% of monthly budget consumed in this range.
|
|
701
|
+
</div>
|
|
702
|
+
</div>
|
|
703
|
+
) : null}
|
|
704
|
+
</CardContent>
|
|
705
|
+
</Card>
|
|
706
|
+
|
|
707
|
+
<FinanceSummaryCard
|
|
708
|
+
debitCents={financeData?.summary.debitCents ?? 0}
|
|
709
|
+
creditCents={financeData?.summary.creditCents ?? 0}
|
|
710
|
+
netCents={financeData?.summary.netCents ?? 0}
|
|
711
|
+
estimatedDebitCents={financeData?.summary.estimatedDebitCents ?? 0}
|
|
712
|
+
eventCount={financeData?.summary.eventCount ?? 0}
|
|
713
|
+
/>
|
|
714
|
+
</div>
|
|
715
|
+
|
|
716
|
+
<div className="grid gap-4 xl:grid-cols-[1.25fr,0.95fr]">
|
|
717
|
+
<Card>
|
|
718
|
+
<CardHeader className="px-5 pt-5 pb-2">
|
|
719
|
+
<CardTitle className="text-base">By agent</CardTitle>
|
|
720
|
+
<CardDescription>What each agent consumed in the selected period.</CardDescription>
|
|
721
|
+
</CardHeader>
|
|
722
|
+
<CardContent className="space-y-2 px-5 pb-5 pt-2">
|
|
723
|
+
{(spendData?.byAgent.length ?? 0) === 0 ? (
|
|
724
|
+
<p className="text-sm text-muted-foreground">No cost events yet.</p>
|
|
725
|
+
) : (
|
|
726
|
+
spendData?.byAgent.map((row) => {
|
|
727
|
+
const modelRows = agentModelRows.get(row.agentId) ?? [];
|
|
728
|
+
const isExpanded = expandedAgents.has(row.agentId);
|
|
729
|
+
const hasBreakdown = modelRows.length > 0;
|
|
730
|
+
return (
|
|
731
|
+
<div key={row.agentId} className="border border-border px-4 py-3">
|
|
732
|
+
<div
|
|
733
|
+
className={cn("flex items-start justify-between gap-3", hasBreakdown ? "cursor-pointer select-none" : "")}
|
|
734
|
+
onClick={() => hasBreakdown && toggleAgent(row.agentId)}
|
|
735
|
+
>
|
|
736
|
+
<div className="flex min-w-0 items-center gap-2">
|
|
737
|
+
{hasBreakdown ? (
|
|
738
|
+
isExpanded
|
|
739
|
+
? <ChevronDown className="h-3 w-3 shrink-0 text-muted-foreground" />
|
|
740
|
+
: <ChevronRight className="h-3 w-3 shrink-0 text-muted-foreground" />
|
|
741
|
+
) : (
|
|
742
|
+
<span className="h-3 w-3 shrink-0" />
|
|
743
|
+
)}
|
|
744
|
+
<Identity name={row.agentName ?? row.agentId} size="sm" />
|
|
745
|
+
{row.agentStatus === "terminated" ? <StatusBadge status="terminated" /> : null}
|
|
746
|
+
</div>
|
|
747
|
+
<div className="text-right text-sm tabular-nums">
|
|
748
|
+
<div className="font-medium">{formatCents(row.costCents)}</div>
|
|
749
|
+
<div className="text-xs text-muted-foreground">
|
|
750
|
+
in {formatTokens(row.inputTokens + row.cachedInputTokens)} · out {formatTokens(row.outputTokens)}
|
|
751
|
+
</div>
|
|
752
|
+
{(row.apiRunCount > 0 || row.subscriptionRunCount > 0) ? (
|
|
753
|
+
<div className="text-xs text-muted-foreground">
|
|
754
|
+
{row.apiRunCount > 0 ? `${row.apiRunCount} api` : "0 api"}
|
|
755
|
+
{" · "}
|
|
756
|
+
{row.subscriptionRunCount > 0
|
|
757
|
+
? `${row.subscriptionRunCount} subscription`
|
|
758
|
+
: "0 subscription"}
|
|
759
|
+
</div>
|
|
760
|
+
) : null}
|
|
761
|
+
</div>
|
|
762
|
+
</div>
|
|
763
|
+
|
|
764
|
+
{isExpanded && modelRows.length > 0 ? (
|
|
765
|
+
<div className="mt-3 space-y-2 border-l border-border pl-4">
|
|
766
|
+
{modelRows.map((modelRow) => {
|
|
767
|
+
const sharePct = row.costCents > 0 ? Math.round((modelRow.costCents / row.costCents) * 100) : 0;
|
|
768
|
+
return (
|
|
769
|
+
<div
|
|
770
|
+
key={`${modelRow.provider}:${modelRow.model}:${modelRow.billingType}`}
|
|
771
|
+
className="flex items-start justify-between gap-3 text-xs"
|
|
772
|
+
>
|
|
773
|
+
<div className="min-w-0">
|
|
774
|
+
<div className="truncate font-medium text-foreground">
|
|
775
|
+
{providerDisplayName(modelRow.provider)}
|
|
776
|
+
<span className="mx-1 text-border">/</span>
|
|
777
|
+
<span className="font-mono">{modelRow.model}</span>
|
|
778
|
+
</div>
|
|
779
|
+
<div className="truncate text-muted-foreground">
|
|
780
|
+
{providerDisplayName(modelRow.biller)} · {billingTypeDisplayName(modelRow.billingType)}
|
|
781
|
+
</div>
|
|
782
|
+
</div>
|
|
783
|
+
<div className="text-right tabular-nums">
|
|
784
|
+
<div className="font-medium">
|
|
785
|
+
{formatCents(modelRow.costCents)}
|
|
786
|
+
<span className="ml-1 font-normal text-muted-foreground">({sharePct}%)</span>
|
|
787
|
+
</div>
|
|
788
|
+
<div className="text-muted-foreground">
|
|
789
|
+
{formatTokens(modelRow.inputTokens + modelRow.cachedInputTokens + modelRow.outputTokens)} tok
|
|
790
|
+
</div>
|
|
791
|
+
</div>
|
|
792
|
+
</div>
|
|
793
|
+
);
|
|
794
|
+
})}
|
|
795
|
+
</div>
|
|
796
|
+
) : null}
|
|
797
|
+
</div>
|
|
798
|
+
);
|
|
799
|
+
})
|
|
800
|
+
)}
|
|
801
|
+
</CardContent>
|
|
802
|
+
</Card>
|
|
803
|
+
|
|
804
|
+
<div className="space-y-4">
|
|
805
|
+
<Card>
|
|
806
|
+
<CardHeader className="px-5 pt-5 pb-2">
|
|
807
|
+
<CardTitle className="text-base">By project</CardTitle>
|
|
808
|
+
<CardDescription>Run costs attributed through project-linked issues.</CardDescription>
|
|
809
|
+
</CardHeader>
|
|
810
|
+
<CardContent className="space-y-2 px-5 pb-5 pt-2">
|
|
811
|
+
{(spendData?.byProject.length ?? 0) === 0 ? (
|
|
812
|
+
<p className="text-sm text-muted-foreground">No project-attributed run costs yet.</p>
|
|
813
|
+
) : (
|
|
814
|
+
spendData?.byProject.map((row, index) => (
|
|
815
|
+
<div
|
|
816
|
+
key={row.projectId ?? `unattributed-${index}`}
|
|
817
|
+
className="flex items-center justify-between gap-3 border border-border px-3 py-2 text-sm"
|
|
818
|
+
>
|
|
819
|
+
<span className="truncate">{row.projectName ?? row.projectId ?? "Unattributed"}</span>
|
|
820
|
+
<span className="font-medium tabular-nums">{formatCents(row.costCents)}</span>
|
|
821
|
+
</div>
|
|
822
|
+
))
|
|
823
|
+
)}
|
|
824
|
+
</CardContent>
|
|
825
|
+
</Card>
|
|
826
|
+
|
|
827
|
+
<FinanceTimelineCard rows={topFinanceEvents.slice(0, 6)} emptyMessage="No finance events yet. Add account-level charges once biller invoices or credits land." />
|
|
828
|
+
</div>
|
|
829
|
+
</div>
|
|
830
|
+
</>
|
|
831
|
+
)}
|
|
832
|
+
</TabsContent>
|
|
833
|
+
|
|
834
|
+
<TabsContent value="budgets" className="mt-4 space-y-4">
|
|
835
|
+
{budgetLoading ? (
|
|
836
|
+
<PageSkeleton variant="costs" />
|
|
837
|
+
) : budgetError ? (
|
|
838
|
+
<p className="text-sm text-destructive">{(budgetError as Error).message}</p>
|
|
839
|
+
) : (
|
|
840
|
+
<>
|
|
841
|
+
<Card className="border-border/70 bg-[linear-gradient(180deg,rgba(255,255,255,0.05),rgba(255,255,255,0.02))]">
|
|
842
|
+
<CardHeader className="px-5 pt-5 pb-3">
|
|
843
|
+
<CardTitle className="text-base">Budget control plane</CardTitle>
|
|
844
|
+
<CardDescription>
|
|
845
|
+
Hard-stop spend limits for agents and projects. Provider subscription quota stays separate and appears under Providers.
|
|
846
|
+
</CardDescription>
|
|
847
|
+
</CardHeader>
|
|
848
|
+
<CardContent className="grid gap-3 px-5 pb-5 pt-0 md:grid-cols-4">
|
|
849
|
+
<MetricTile
|
|
850
|
+
label="Active incidents"
|
|
851
|
+
value={String(activeBudgetIncidents.length)}
|
|
852
|
+
subtitle="Open soft or hard threshold crossings"
|
|
853
|
+
icon={ReceiptText}
|
|
854
|
+
/>
|
|
855
|
+
<MetricTile
|
|
856
|
+
label="Pending approvals"
|
|
857
|
+
value={String(budgetData?.pendingApprovalCount ?? 0)}
|
|
858
|
+
subtitle="Budget override approvals awaiting board action"
|
|
859
|
+
icon={ArrowUpRight}
|
|
860
|
+
/>
|
|
861
|
+
<MetricTile
|
|
862
|
+
label="Paused agents"
|
|
863
|
+
value={String(budgetData?.pausedAgentCount ?? 0)}
|
|
864
|
+
subtitle="Agent heartbeats blocked by budget"
|
|
865
|
+
icon={Coins}
|
|
866
|
+
/>
|
|
867
|
+
<MetricTile
|
|
868
|
+
label="Paused projects"
|
|
869
|
+
value={String(budgetData?.pausedProjectCount ?? 0)}
|
|
870
|
+
subtitle="Project execution blocked by budget"
|
|
871
|
+
icon={DollarSign}
|
|
872
|
+
/>
|
|
873
|
+
</CardContent>
|
|
874
|
+
</Card>
|
|
875
|
+
|
|
876
|
+
{activeBudgetIncidents.length > 0 ? (
|
|
877
|
+
<div className="space-y-3">
|
|
878
|
+
<div>
|
|
879
|
+
<h2 className="text-lg font-semibold">Active incidents</h2>
|
|
880
|
+
<p className="text-sm text-muted-foreground">
|
|
881
|
+
Resolve hard stops here by raising the budget or explicitly keeping the scope paused.
|
|
882
|
+
</p>
|
|
883
|
+
</div>
|
|
884
|
+
<div className="grid gap-4 xl:grid-cols-2">
|
|
885
|
+
{activeBudgetIncidents.map((incident) => (
|
|
886
|
+
<BudgetIncidentCard
|
|
887
|
+
key={incident.id}
|
|
888
|
+
incident={incident}
|
|
889
|
+
isMutating={incidentMutation.isPending}
|
|
890
|
+
onKeepPaused={() => incidentMutation.mutate({ incidentId: incident.id, action: "keep_paused" })}
|
|
891
|
+
onRaiseAndResume={(amount) =>
|
|
892
|
+
incidentMutation.mutate({
|
|
893
|
+
incidentId: incident.id,
|
|
894
|
+
action: "raise_budget_and_resume",
|
|
895
|
+
amount,
|
|
896
|
+
})}
|
|
897
|
+
/>
|
|
898
|
+
))}
|
|
899
|
+
</div>
|
|
900
|
+
</div>
|
|
901
|
+
) : null}
|
|
902
|
+
|
|
903
|
+
<div className="space-y-5">
|
|
904
|
+
{(["company", "agent", "project"] as const).map((scopeType) => {
|
|
905
|
+
const rows = budgetPoliciesByScope[scopeType];
|
|
906
|
+
if (rows.length === 0) return null;
|
|
907
|
+
return (
|
|
908
|
+
<section key={scopeType} className="space-y-3">
|
|
909
|
+
<div>
|
|
910
|
+
<h2 className="text-lg font-semibold capitalize">{scopeType} budgets</h2>
|
|
911
|
+
<p className="text-sm text-muted-foreground">
|
|
912
|
+
{scopeType === "company"
|
|
913
|
+
? "Company-wide monthly policy."
|
|
914
|
+
: scopeType === "agent"
|
|
915
|
+
? "Recurring monthly spend policies for individual agents."
|
|
916
|
+
: "Lifetime spend policies for execution-bound projects."}
|
|
917
|
+
</p>
|
|
918
|
+
</div>
|
|
919
|
+
<div className="grid gap-4 xl:grid-cols-2">
|
|
920
|
+
{rows.map((summary) => (
|
|
921
|
+
<BudgetPolicyCard
|
|
922
|
+
key={summary.policyId}
|
|
923
|
+
summary={summary}
|
|
924
|
+
isSaving={policyMutation.isPending}
|
|
925
|
+
onSave={(amount) =>
|
|
926
|
+
policyMutation.mutate({
|
|
927
|
+
scopeType: summary.scopeType,
|
|
928
|
+
scopeId: summary.scopeId,
|
|
929
|
+
amount,
|
|
930
|
+
windowKind: summary.windowKind,
|
|
931
|
+
})}
|
|
932
|
+
/>
|
|
933
|
+
))}
|
|
934
|
+
</div>
|
|
935
|
+
</section>
|
|
936
|
+
);
|
|
937
|
+
})}
|
|
938
|
+
|
|
939
|
+
{budgetPolicies.length === 0 ? (
|
|
940
|
+
<Card>
|
|
941
|
+
<CardContent className="px-5 py-8 text-sm text-muted-foreground">
|
|
942
|
+
No budget policies yet. Set agent and project budgets from their detail pages, or use the existing company monthly budget control.
|
|
943
|
+
</CardContent>
|
|
944
|
+
</Card>
|
|
945
|
+
) : null}
|
|
946
|
+
</div>
|
|
947
|
+
</>
|
|
948
|
+
)}
|
|
949
|
+
</TabsContent>
|
|
950
|
+
|
|
951
|
+
<TabsContent value="providers" className="mt-4 space-y-4">
|
|
952
|
+
{showCustomPrompt ? (
|
|
953
|
+
<p className="text-sm text-muted-foreground">Select a start and end date to load data.</p>
|
|
954
|
+
) : (
|
|
955
|
+
<>
|
|
956
|
+
<Tabs value={effectiveProvider} onValueChange={setActiveProvider}>
|
|
957
|
+
<PageTabBar items={providerTabItems} value={effectiveProvider} />
|
|
958
|
+
|
|
959
|
+
<TabsContent value="all" className="mt-4">
|
|
960
|
+
{providers.length === 0 ? (
|
|
961
|
+
<p className="text-sm text-muted-foreground">No cost events in this period.</p>
|
|
962
|
+
) : (
|
|
963
|
+
<div className="grid gap-4 md:grid-cols-2">
|
|
964
|
+
{providers.map((provider) => (
|
|
965
|
+
<ProviderQuotaCard
|
|
966
|
+
key={provider}
|
|
967
|
+
provider={provider}
|
|
968
|
+
rows={byProvider.get(provider) ?? []}
|
|
969
|
+
budgetMonthlyCents={spendData?.summary.budgetCents ?? 0}
|
|
970
|
+
totalCompanySpendCents={spendData?.summary.spendCents ?? 0}
|
|
971
|
+
weekSpendCents={weekSpendByProvider.get(provider) ?? 0}
|
|
972
|
+
windowRows={windowSpendByProvider.get(provider) ?? []}
|
|
973
|
+
showDeficitNotch={deficitNotchByProvider.get(provider) ?? false}
|
|
974
|
+
quotaWindows={quotaWindowsByProvider.get(provider) ?? []}
|
|
975
|
+
quotaError={quotaErrorsByProvider.get(provider) ?? null}
|
|
976
|
+
quotaSource={quotaSourcesByProvider.get(provider) ?? null}
|
|
977
|
+
quotaLoading={quotaLoading}
|
|
978
|
+
/>
|
|
979
|
+
))}
|
|
980
|
+
</div>
|
|
981
|
+
)}
|
|
982
|
+
</TabsContent>
|
|
983
|
+
|
|
984
|
+
{providers.map((provider) => (
|
|
985
|
+
<TabsContent key={provider} value={provider} className="mt-4">
|
|
986
|
+
<ProviderQuotaCard
|
|
987
|
+
provider={provider}
|
|
988
|
+
rows={byProvider.get(provider) ?? []}
|
|
989
|
+
budgetMonthlyCents={spendData?.summary.budgetCents ?? 0}
|
|
990
|
+
totalCompanySpendCents={spendData?.summary.spendCents ?? 0}
|
|
991
|
+
weekSpendCents={weekSpendByProvider.get(provider) ?? 0}
|
|
992
|
+
windowRows={windowSpendByProvider.get(provider) ?? []}
|
|
993
|
+
showDeficitNotch={deficitNotchByProvider.get(provider) ?? false}
|
|
994
|
+
quotaWindows={quotaWindowsByProvider.get(provider) ?? []}
|
|
995
|
+
quotaError={quotaErrorsByProvider.get(provider) ?? null}
|
|
996
|
+
quotaSource={quotaSourcesByProvider.get(provider) ?? null}
|
|
997
|
+
quotaLoading={quotaLoading}
|
|
998
|
+
/>
|
|
999
|
+
</TabsContent>
|
|
1000
|
+
))}
|
|
1001
|
+
</Tabs>
|
|
1002
|
+
</>
|
|
1003
|
+
)}
|
|
1004
|
+
</TabsContent>
|
|
1005
|
+
|
|
1006
|
+
<TabsContent value="billers" className="mt-4 space-y-4">
|
|
1007
|
+
{showCustomPrompt ? (
|
|
1008
|
+
<p className="text-sm text-muted-foreground">Select a start and end date to load data.</p>
|
|
1009
|
+
) : (
|
|
1010
|
+
<>
|
|
1011
|
+
<Tabs value={effectiveBiller} onValueChange={setActiveBiller}>
|
|
1012
|
+
<PageTabBar items={billerTabItems} value={effectiveBiller} />
|
|
1013
|
+
|
|
1014
|
+
<TabsContent value="all" className="mt-4">
|
|
1015
|
+
{billers.length === 0 ? (
|
|
1016
|
+
<p className="text-sm text-muted-foreground">No billable events in this period.</p>
|
|
1017
|
+
) : (
|
|
1018
|
+
<div className="grid gap-4 md:grid-cols-2">
|
|
1019
|
+
{billers.map((biller) => {
|
|
1020
|
+
const row = (byBiller.get(biller) ?? [])[0];
|
|
1021
|
+
if (!row) return null;
|
|
1022
|
+
const providerRows = (providerData ?? []).filter((entry) => entry.biller === biller);
|
|
1023
|
+
return (
|
|
1024
|
+
<BillerSpendCard
|
|
1025
|
+
key={biller}
|
|
1026
|
+
row={row}
|
|
1027
|
+
weekSpendCents={weekSpendByBiller.get(biller) ?? 0}
|
|
1028
|
+
budgetMonthlyCents={spendData?.summary.budgetCents ?? 0}
|
|
1029
|
+
totalCompanySpendCents={spendData?.summary.spendCents ?? 0}
|
|
1030
|
+
providerRows={providerRows}
|
|
1031
|
+
/>
|
|
1032
|
+
);
|
|
1033
|
+
})}
|
|
1034
|
+
</div>
|
|
1035
|
+
)}
|
|
1036
|
+
</TabsContent>
|
|
1037
|
+
|
|
1038
|
+
{billers.map((biller) => {
|
|
1039
|
+
const row = (byBiller.get(biller) ?? [])[0];
|
|
1040
|
+
if (!row) return null;
|
|
1041
|
+
const providerRows = (providerData ?? []).filter((entry) => entry.biller === biller);
|
|
1042
|
+
return (
|
|
1043
|
+
<TabsContent key={biller} value={biller} className="mt-4">
|
|
1044
|
+
<BillerSpendCard
|
|
1045
|
+
row={row}
|
|
1046
|
+
weekSpendCents={weekSpendByBiller.get(biller) ?? 0}
|
|
1047
|
+
budgetMonthlyCents={spendData?.summary.budgetCents ?? 0}
|
|
1048
|
+
totalCompanySpendCents={spendData?.summary.spendCents ?? 0}
|
|
1049
|
+
providerRows={providerRows}
|
|
1050
|
+
/>
|
|
1051
|
+
</TabsContent>
|
|
1052
|
+
);
|
|
1053
|
+
})}
|
|
1054
|
+
</Tabs>
|
|
1055
|
+
</>
|
|
1056
|
+
)}
|
|
1057
|
+
</TabsContent>
|
|
1058
|
+
|
|
1059
|
+
<TabsContent value="finance" className="mt-4 space-y-4">
|
|
1060
|
+
{showCustomPrompt ? (
|
|
1061
|
+
<p className="text-sm text-muted-foreground">Select a start and end date to load data.</p>
|
|
1062
|
+
) : financeLoading ? (
|
|
1063
|
+
<PageSkeleton variant="costs" />
|
|
1064
|
+
) : financeError ? (
|
|
1065
|
+
<p className="text-sm text-destructive">{(financeError as Error).message}</p>
|
|
1066
|
+
) : (
|
|
1067
|
+
<>
|
|
1068
|
+
<FinanceSummaryCard
|
|
1069
|
+
debitCents={financeData?.summary.debitCents ?? 0}
|
|
1070
|
+
creditCents={financeData?.summary.creditCents ?? 0}
|
|
1071
|
+
netCents={financeData?.summary.netCents ?? 0}
|
|
1072
|
+
estimatedDebitCents={financeData?.summary.estimatedDebitCents ?? 0}
|
|
1073
|
+
eventCount={financeData?.summary.eventCount ?? 0}
|
|
1074
|
+
/>
|
|
1075
|
+
|
|
1076
|
+
<div className="grid gap-4 xl:grid-cols-[1.2fr,0.95fr]">
|
|
1077
|
+
<div className="space-y-4">
|
|
1078
|
+
<Card>
|
|
1079
|
+
<CardHeader className="px-5 pt-5 pb-2">
|
|
1080
|
+
<CardTitle className="text-base">By biller</CardTitle>
|
|
1081
|
+
<CardDescription>Account-level financial events grouped by who charged or credited them.</CardDescription>
|
|
1082
|
+
</CardHeader>
|
|
1083
|
+
<CardContent className="grid gap-4 px-5 pb-5 pt-2 md:grid-cols-2">
|
|
1084
|
+
{(financeData?.byBiller.length ?? 0) === 0 ? (
|
|
1085
|
+
<p className="text-sm text-muted-foreground">No finance events yet.</p>
|
|
1086
|
+
) : (
|
|
1087
|
+
financeData?.byBiller.map((row) => <FinanceBillerCard key={row.biller} row={row} />)
|
|
1088
|
+
)}
|
|
1089
|
+
</CardContent>
|
|
1090
|
+
</Card>
|
|
1091
|
+
<FinanceTimelineCard rows={topFinanceEvents} />
|
|
1092
|
+
</div>
|
|
1093
|
+
|
|
1094
|
+
<FinanceKindCard rows={financeData?.byKind ?? []} />
|
|
1095
|
+
</div>
|
|
1096
|
+
</>
|
|
1097
|
+
)}
|
|
1098
|
+
</TabsContent>
|
|
1099
|
+
</Tabs>
|
|
1100
|
+
</div>
|
|
1101
|
+
);
|
|
1102
|
+
}
|
|
1103
|
+
|