diff --git a/desktop/src/features/agent-usage/hooks.ts b/desktop/src/features/agent-usage/hooks.ts index 8a6c09bc9..1861bd8bd 100644 --- a/desktop/src/features/agent-usage/hooks.ts +++ b/desktop/src/features/agent-usage/hooks.ts @@ -8,6 +8,7 @@ import { } from "@/shared/api/tauriArchive"; import { buildLocalDayBoundaries, + deriveUsageIngressTrailing, msUntilNextLocalMidnight, type UsageWindowDays, } from "./lib/agentUsage"; @@ -100,3 +101,25 @@ export function useAgentUsageSeries({ gcTime: 5 * 60_000, }); } + +/** + * Trailing text for the profile Info tab's usage ingress row (plan:328). + * + * Owns its own 7-day window deliberately: the row summarises recent usage + * independently of the focused view's 7d/30d selector, so the two must not + * share a query. Returns `undefined` while the query is disabled or still + * loading, which the row renders as no trailing text at all. + * + * `enabled` gates the query off entirely when the row won't render. + */ +export function useUsageIngress( + agentPubkey: string | null, + enabled: boolean, +): string | undefined { + const query = useAgentUsageSeries({ + agentPubkey: agentPubkey ?? undefined, + days: 7, + enabled, + }); + return query.data ? deriveUsageIngressTrailing(query.data) : undefined; +} diff --git a/desktop/src/features/profile/ui/UserProfilePanel.tsx b/desktop/src/features/profile/ui/UserProfilePanel.tsx index 1c5430c01..bece887e0 100644 --- a/desktop/src/features/profile/ui/UserProfilePanel.tsx +++ b/desktop/src/features/profile/ui/UserProfilePanel.tsx @@ -68,8 +68,7 @@ import { } from "@/features/profile/ui/UserProfilePanelSections"; import { AgentConfigurationFocusedView } from "@/features/profile/ui/UserProfilePanelAgentDetails"; import { AgentUsageFocusedView } from "@/features/agent-usage/ui/AgentUsageFocusedView"; -import { useAgentUsageSeries } from "@/features/agent-usage/hooks"; -import { deriveUsageIngressTrailing } from "@/features/agent-usage/lib/agentUsage"; +import { useUsageIngress } from "@/features/agent-usage/hooks"; import { UserProfileAgentSettingsMenuSlot } from "@/features/profile/ui/UserProfileAgentActions"; import { useProfileAgentDeletion } from "@/features/profile/ui/UserProfilePanelDeletion"; import { useProfileFieldBuckets } from "@/features/profile/ui/UserProfilePanelFields"; @@ -342,17 +341,7 @@ export function UserProfilePanel({ Boolean(effectivePubkey) && canOpenAgentActivity(effectivePubkey); const canViewUsage = viewerIsOwner && isBot && Boolean(effectivePubkey); - // Info-tab ingress row's trailing text (plan:328) needs its own 7-day - // query — independent of the focused view's own 7d/30d selector, and - // gated off entirely when the row won't render. - const usageIngressQuery = useAgentUsageSeries({ - agentPubkey: effectivePubkey ?? undefined, - days: 7, - enabled: canViewUsage, - }); - const usageIngressTrailing = usageIngressQuery.data - ? deriveUsageIngressTrailing(usageIngressQuery.data) - : undefined; + const usageIngressTrailing = useUsageIngress(effectivePubkey, canViewUsage); const canOpenAgentLogs = isOwner === true && managedAgent?.backend.type === "local"; const canInstantiateAgent =