From 8853a2df4c8b255d8c6638858f525ed5a0387f5f Mon Sep 17 00:00:00 2001 From: Adam Malczewski Date: Wed, 14 Oct 2026 17:29:03 +0900 Subject: feat(account-usage): Hyper daily credits card with allowance + reset-time editor --- src/app/store.svelte.ts | 47 +++++++++++++++++++++++++++++++++-- src/app/views/AccountUsagePane.svelte | 12 ++++++--- 2 files changed, 54 insertions(+), 5 deletions(-) (limited to 'src/app') diff --git a/src/app/store.svelte.ts b/src/app/store.svelte.ts index 7433f81..0a9cbd1 100644 --- a/src/app/store.svelte.ts +++ b/src/app/store.svelte.ts @@ -56,8 +56,13 @@ import { subscribe as protocolSubscribe, unsubscribe as protocolUnsubscribe, } from "../core/protocol"; -import type { AccountUsageResult } from "../features/account-usage"; -import { normalizeAccountUsage } from "../features/account-usage"; +import type { + AccountUsageProviderId, + AccountUsageResult, + AccountUsageSettingsResult, + UpdateAccountUsageSettingsRequest, +} from "../features/account-usage"; +import { normalizeAccountUsage, normalizeAccountUsageReport } from "../features/account-usage"; import type { ChatStore, HistorySync, MetricsSync } from "../features/chat"; import { createChatStore, migrateLegacyModelName } from "../features/chat"; import type { SetThinkingRequest, ThinkingResponse } from "../features/chat/reasoning-effort"; @@ -543,6 +548,15 @@ export interface AppStore { * `account-usage` extension isn't loaded) returns `unavailable: true`. */ accountUsage(opts?: { readonly refresh?: boolean }): Promise; + /** + * Update a provider's usage settings (`PUT /usage/:provider/settings`; today + * only `hyper`: `dailyAllowance` + `resetAnchor` epoch-ms or null). Returns + * the provider's refreshed report. + */ + setAccountUsageSettings( + provider: AccountUsageProviderId, + settings: UpdateAccountUsageSettingsRequest, + ): Promise; /** * Load the GLOBAL search-backend selection * (`GET /search/config`): which engine backs the `web_search` tool's search @@ -2613,6 +2627,35 @@ export function createAppStore(opts?: CreateAppStoreOptions): AppStore { } }, + async setAccountUsageSettings( + provider: AccountUsageProviderId, + settings: UpdateAccountUsageSettingsRequest, + ): Promise { + try { + const res = await fetchImpl(`${httpBase}/usage/${encodeURIComponent(provider)}/settings`, { + method: "PUT", + headers: { "content-type": "application/json" }, + body: JSON.stringify(settings), + }); + if (!res.ok) { + const errBody = (await res.json().catch(() => null)) as { error?: string } | null; + return { + ok: false, + error: errBody?.error ?? `Save usage settings failed (HTTP ${res.status})`, + }; + } + const report = normalizeAccountUsageReport(await res.json()); + return report + ? { ok: true, report } + : { ok: false, error: "Malformed usage settings response" }; + } catch (err) { + return { + ok: false, + error: err instanceof Error ? err.message : "Save usage settings request failed", + }; + } + }, + async concurrencyStatus(): Promise { try { const res = await fetchImpl(`${httpBase}/concurrency/status`); diff --git a/src/app/views/AccountUsagePane.svelte b/src/app/views/AccountUsagePane.svelte index 4315d4c..09afb5f 100644 --- a/src/app/views/AccountUsagePane.svelte +++ b/src/app/views/AccountUsagePane.svelte @@ -1,16 +1,22 @@ - + -- cgit v1.2.3