feat(usage): add Grok reports to desktop and mobile #5830
Closedjakeleventhal(GitHub profile, opens in a new tab)wants to merge 11 commits into
main fromrefs/pull/5830/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/web/src/components/usage/usageProviders.ts line 10OutdatedResolvedby jakeleventhal(GitHub profile, opens in a new tab)@@ -1,10 +1,10 @@11 import type { UsageProviderKind } from "@t3tools/contracts";223-import { ClaudeAI, type Icon, OpenAI } from "../Icons";3+import { ClaudeAI, GrokIcon, type Icon, OpenAI } from "../Icons";4455 /**6- * Series and table order. The chart layers both providers from a shared zero6+ * Series and table order. The chart layers all providers from a shared zero77 * baseline, so this only fixes the reading order of legends, tables and hover88 * rows; it does not decide which series sits above the other.99 */10-export const PROVIDER_ORDER: readonly UsageProviderKind[] = ["codex", "claude"];10+export const PROVIDER_ORDER: readonly UsageProviderKind[] = ["codex", "claude", "grok"];
- apps/server/src/usage/usageTranscripts.ts line 415OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -299,0 +395,21 @@395+ const cacheCreationTokens = int(usage["cacheCreationTokens"]);396+ const outputTokens = int(usage["outputTokens"]);397+ const totals: UsageTokenTotals = {398+ uncachedInputTokens: Math.max(0, inputTokens - cachedInputTokens - cacheCreationTokens),399+ cachedInputTokens,400+ cacheCreationTokens,401+ outputTokens,402+ reasoningTokens: Math.min(outputTokens, int(usage["reasoningTokens"])),403+ };404+ if (totalTokens(totals) === 0) continue;405+406+ const usageSignature = JSON.stringify(usage);407+ records.push({408+ provider: "grok",409+ timestampMs,410+ model,411+ sessionId,412+ totals,413+ recordCount: Math.max(1, int(usage["modelCalls"])),414+ reportedCostUsd: grokCostUsd(usage, aggregateUsage, rows.length === 1),415+ dedupeKey: `${sessionId}:${eventId ?? timestampMs}:${model}:${usageSignature}`,
- apps/server/src/usage/UsageService.ts lines 221 to 222OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -217,3 +218,5 @@217218 const claudeHome = yield* resolveClaudeHomePath(settings.providers.claudeAgent);218219 const claudeDir = yield* resolveClaudeTranscriptDir(claudeHome);219220 const codexLayout = yield* resolveCodexHomeLayout(settings.providers.codex);221+ const grokHome = path.resolve(222+ expandHomePath(process.env["GROK_HOME"] ?? path.join(NodeOS.homedir(), ".grok")),
- apps/server/src/usage/UsageService.ts line 231Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -217,3 +220,6 @@217220 const claudeHome = yield* resolveClaudeHomePath(settings.providers.claudeAgent);218221 const claudeDir = yield* resolveClaudeTranscriptDir(claudeHome);219222 const codexLayout = yield* resolveCodexHomeLayout(settings.providers.codex);223+ const grokHome = path.resolve(224+ expandHomePath(hostEnvironment["GROK_HOME"] ?? path.join(NodeOS.homedir(), ".grok")),225+ );
- apps/server/src/usage/usageTranscripts.ts line 421Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -299,0 +394,21 @@394+ const cachedInputTokens = int(usage["cachedReadTokens"] ?? usage["cacheReadInputTokens"]);395+ const cacheCreationTokens = int(usage["cacheCreationTokens"]);396+ const outputTokens = int(usage["outputTokens"]);397+ const totals: UsageTokenTotals = {398+ uncachedInputTokens: Math.max(0, inputTokens - cachedInputTokens - cacheCreationTokens),399+ cachedInputTokens,400+ cacheCreationTokens,401+ outputTokens,402+ reasoningTokens: Math.min(outputTokens, int(usage["reasoningTokens"])),403+ };404+ if (totalTokens(totals) === 0) continue;405+406+ const usageSignature = JSON.stringify(usage);407+ records.push({408+ provider: "grok",409+ timestampMs,410+ model,411+ sessionId,412+ totals,413+ recordCount: Math.max(1, int(usage["modelCalls"])),414+ reportedCostUsd: grokCostUsd(usage, aggregateUsage, rows.length === 1),
t3dotgg(GitHub profile, opens in a new tab) added labelsvouch:trusted
t3dotgg(GitHub profile, opens in a new tab) removed labelsvouch:unvouched
- apps/web/src/components/usage/usageProviders.ts lines 29 to 29OutdatedResolvedby jakeleventhal(GitHub profile, opens in a new tab)@@ -24,3 +24,6 @@2424 color: "#d97757",2525 mark: ClaudeAI,2626 },27+ grok: {28+ label: "Grok",29+ color: "#8b8b8b",
- apps/server/src/usage/usageTranscriptReader.ts line 75Resolvedby jakeleventhal(GitHub profile, opens in a new tab)@@ -58,3 +60,4 @@5860 continue;5961 }6062 if (!entry.name.endsWith(".jsonl")) continue;63+ if (provider === "grok" && entry.name !== "updates.jsonl") continue;apps/server/src/usage/usageTranscripts.ts line 425OutdatedResolvedby jakeleventhal(GitHub profile, opens in a new tab)@@ -299,0 +405,21 @@405+ reasoningTokens: Math.min(outputTokens, int(usage["reasoningTokens"])),406+ };407+ if (totalTokens(totals) === 0) continue;408+ rows.push({ model, usage, totals });409+ }410+411+ const records: UsageRecord[] = [];412+ for (const { model, usage, totals } of rows) {413+ const usageSignature = JSON.stringify(usage);414+ records.push({415+ provider: "grok",416+ timestampMs,417+ model,418+ sessionId,419+ totals,420+ recordCount: Math.max(1, int(usage["modelCalls"])),421+ reportedCostUsd: grokCostUsd(usage, aggregateUsage, rows.length === 1),422+ dedupeKey:423+ sessionId.length > 0 || eventId !== null424+ ? `${sessionId}:${eventId ?? timestampMs}:${model}:${usageSignature}`425+ : null,
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.



Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
5393327a-77ab-4bd0-b928-0327e5152745You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
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.
❤️ Share