From 9fac004f05f063fa4a190a1a6a4ddf750640dcf4 Mon Sep 17 00:00:00 2001 From: redshift <213178690+1ftredsh@users.noreply.github.com> Date: Sun, 3 May 2026 16:21:38 +0800 Subject: [PATCH] refactor(usage): remove CLI-side suffix filtering now that auth proxy handles it The auth proxy intercepts GET /usage and returns only entries belonging to the authenticated npub's clients, with owner suffixes stripped. The TUI no longer needs to filter entries client-side. - Remove getNpubSuffix and loadConfig from tui/usage/data.ts imports - Remove old suffix-based filtering logic from fetchUsage() - Remove unused getNpubSuffix from cli.ts imports --- bun.lock | 4 +++- src/cli.ts | 1 - src/tui/usage/data.ts | 19 ++++--------------- 3 files changed, 7 insertions(+), 17 deletions(-) mode change 100755 => 100644 bun.lock diff --git a/bun.lock b/bun.lock old mode 100755 new mode 100644 index 57b54b5..1a69048 --- a/bun.lock +++ b/bun.lock @@ -1,5 +1,6 @@ { - "lockfileVersion": 0, + "lockfileVersion": 1, + "configVersion": 0, "workspaces": { "": { "dependencies": { @@ -8,6 +9,7 @@ "applesauce-core": "^5.1.0", "applesauce-relay": "^5.1.0", "commander": "^14.0.2", + "nostr-tools": "^2.12.0", "qrcode": "^1.5.4", "rxjs": "^7.8.1", "zustand": "^5.0.5", diff --git a/src/cli.ts b/src/cli.ts index be65236..13297b6 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -7,7 +7,6 @@ import { isDaemonRunning, loadConfig, getDaemonBaseUrl, - getNpubSuffix, getUserNpub, } from "./utils/daemon-client"; import { diff --git a/src/tui/usage/data.ts b/src/tui/usage/data.ts index 8aade1f..cdcfa53 100644 --- a/src/tui/usage/data.ts +++ b/src/tui/usage/data.ts @@ -1,5 +1,5 @@ import type { UsageTrackingEntry } from "../../daemon/types.ts"; -import { callDaemon, getNpubSuffix, isDaemonRunning, loadConfig } from "../../utils/daemon-client.ts"; +import { callDaemon, isDaemonRunning } from "../../utils/daemon-client.ts"; import type { ClientStats, DayStats, ModelStats, ProviderStats, UsageStats } from "./types.ts"; export interface BalanceKey { @@ -82,21 +82,10 @@ export async function fetchUsage(limit = 10000): Promise { const result = await callDaemon(`/usage?limit=${limit}`); if (result.error) return null; - // The daemon returns { output: [...] } where output is the entries array directly. - // In remote daemon mode, client IDs are suffixed with the last 7 chars of our npub. - // Fetch the full daemon result, but only display/aggregate entries for our clients. + // The auth proxy filters usage to the authenticated npub's clients and + // returns client IDs without the owner suffix. const entries = result.output as UsageTrackingEntry[] | undefined; - const entriesArray = Array.isArray(entries) ? entries : []; - const suffix = getNpubSuffix(await loadConfig()); - const suffixStr = suffix ? `-${suffix}` : null; - const visibleEntries = suffixStr - ? entriesArray - .filter((entry) => entry.client?.endsWith(suffixStr)) - .map((entry) => ({ - ...entry, - client: entry.client?.slice(0, -suffixStr.length), - })) - : entriesArray; + const visibleEntries = Array.isArray(entries) ? entries : []; // Calculate totals from visible entries const totals = visibleEntries.reduce(