feat(dashboard): add AI usage page (#978)#1083
feat(dashboard): add AI usage page (#978)#1083ayushmk7 wants to merge 3 commits intoInsForge:mainInsForge/InsForge:mainfrom ayushmk7:feat/ai-usage-dashboard-978ayushmk7/Ayush-s-InsForge:feat/ai-usage-dashboard-978Copy head branch name to clipboard
Conversation
…le (InsForge#978) Surfaces existing AI usage data in the admin UI at /dashboard/ai/usage. - New AIUsagePage at /dashboard/ai/usage: date range filter (this week / this month / all time), summary cards (requests, input tokens, output tokens, images), and a paginated records table (time, model, provider, token counts, images) — all driven by the existing useAIUsageSummary and useAIUsageRecords hooks with no new backend changes. - Wires a nested route path="usage" under the /dashboard/ai AILayout. - Adds a "View usage" button on AIPage linking to the new route.
WalkthroughAdds a new AI Usage dashboard page component with date-range filtering and paginated records, a "View usage" link on the existing AI page, and a new route at Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/dashboard/src/features/ai/pages/AIUsagePage.tsx`:
- Around line 13-15: The page is missing the per-model breakdown and a
request-type column in the detailed table; update the UI and data usage so the
per-model counts/costs are shown and each record displays its request type.
Specifically: ensure useAIUsageSummary or AIUsageSummarySchema returns a
perModel map (model name -> {count,cost,usage}) or compute it from
useAIUsageRecords results, render that breakdown in AIUsagePage (e.g., a summary
card/list using the existing formatTime helper for timestamps), and add a new
column in the detailed table that reads the request type from
AIUsageRecordSchema (e.g., record.requestType or record.type) and shows one of
"chat"/"image"/"embedding"; also update useAIUsageRecords/AIUsageRecordSchema to
include and type this requestType field if missing.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: d44d0dfa-3c35-4c95-a7a2-79714fdc914f
📒 Files selected for processing (3)
packages/dashboard/src/features/ai/pages/AIPage.tsxpackages/dashboard/src/features/ai/pages/AIUsagePage.tsxpackages/dashboard/src/router/AppRoutes.tsx
… page - Per-model breakdown table derived by grouping a high-limit records fetch (200 records) by model name, showing requests, input tokens, and output tokens per model. - Type column in the records table derived from outputModality (image → Image, audio → Audio, text → Text); no requestType field exists on AIUsageRecordSchema yet (tracked in InsForge#979).
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/dashboard/src/features/ai/pages/AIUsagePage.tsx`:
- Around line 169-174: The aggregate useAIUsageRecords call is missing error
handling: destructure error as aggregateError from the hook call where
aggregateData and aggregateLoading are defined, then include aggregateError in
the combined error check (e.g., replace summaryError ?? recordsError with
summaryError ?? recordsError ?? aggregateError) so failures from the aggregate
fetch are surfaced to the UI; update any UI/error rendering logic that uses
those combined errors (references: useAIUsageRecords, aggregateData,
aggregateLoading, aggregateError, summaryError, recordsError).
- Around line 129-154: RecordRow passes createdAt to formatTime using
String(record.createdAt), which can produce locale-dependent strings that
parseISO can't handle; update the conversion so createdAt is sent as an ISO 8601
string (e.g., use record.createdAt.toISOString() when record.createdAt is a
Date, falling back to String(record.createdAt) otherwise) before calling
formatTime to ensure parseISO in formatTime receives a valid ISO string.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: cbec24d0-9117-46e7-8237-3564359f4ec9
📒 Files selected for processing (1)
packages/dashboard/src/features/ai/pages/AIUsagePage.tsx
…ch errors - Use toISOString() when createdAt is a Date (z.date() schema) so formatTime's parseISO receives a valid ISO 8601 string instead of locale-dependent output - Destructure and propagate aggregateError from the per-model breakdown fetch so failures are surfaced to users rather than silently ignored Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Summary
Closes #978. Surfaces existing AI usage data in the admin UI — no new backend endpoints or schema changes.
/dashboard/ai/usagewith:startDate/endDateparams the existing API already acceptsuseAIUsageSummaryuseAIUsageRecordswithlimit/offsetpath="usage"added as a nested child under the existing/dashboard/ai+AILayoutinAppRoutes.tsxAIPageheader linking to the new routeWhat was not changed
useAIUsageSummary,useAIUsageRecords) and theaiServicemethods are usedVerification
Note
Add AI usage page with period filtering, aggregate metrics, and paginated records
/dashboard/ai/usageshowing total requests, input/output tokens, and images generated for a selected time period (this week, this month, or all time).Macroscope summarized 9b80eb8.
Summary by CodeRabbit