refactor(agent-usage): move usage-ingress wiring into the feature hook

main's file-size ratchet (#3352) replaced the static per-file override map
with a git-diff base comparison, dropping the 1025-line ceiling that
UserProfilePanel.tsx had been living under. The 7-day ingress query was
agent-usage logic sitting in a profile file; moving it home puts the panel
back under the 1000-line limit with no behavior change.

Co-authored-by: Will Pfleger <pfleger.will@gmail.com>
Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
This commit is contained in:
npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7
2026-07-29 18:57:48 -04:00
co-authored by Will Pfleger
parent 0bd3b7d0a3
commit 25f7dfe138
2 changed files with 25 additions and 13 deletions
+23
View File
@@ -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;
}
@@ -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 =