[PR #6686] [MERGED] Feat/nano gpt sub usage indicator #7287

Closed
opened 2026-10-23 04:18:17 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/6686
Author: @ylli-selmani
Created: 9/25/2026
Status: ✅ Merged
Merged: 9/26/2026
Merged by: @SpicyMarinara

Base: staging ← Head: feat/nanoGPTSubUsageIndicator


📝 Commits (10+)

  • cbb4e13 feat(connections): show NanoGPT subscription usage and model quota cost
  • e4c4195 fix(connections): show the NanoGPT usage meter in the chat HUD
  • 8168471 feat(connections): show the NanoGPT meter in the connection picker
  • 6ab6f41 feat(connections): label the usage meter and fit it to the picker
  • 57eb404 fix(connections): de-duplicate the compact meter and re-card the panel
  • 19bf96e fix(connections): theme the quota bar and drop the leftover percentage
  • 09bc52b fix(connections): restore spacing around the usage toggle and theme it
  • 22f45b2 fix(chat-settings): space the usage meter from the connection select
  • 394f97d fix(connections): address review findings on the NanoGPT usage feature
  • 45dc64b Merge branch 'staging' into feat/nanoGPTSubUsageIndicator

📊 Changes

24 files changed (+1483 additions, -36 deletions)

View changed files

📝 CHANGELOG.md (+2 -0)
📝 docs/connections/providers-reference.md (+20 -0)
➕ e2e/nanogpt-usage.e2e.ts (+97 -0)
📝 packages/client/src/components/chat/ChatSettingsDrawer.tsx (+9 -18)
📝 packages/client/src/components/chat/QuickConnectionSwitcher.tsx (+26 -3)
📝 packages/client/src/components/chat/QuickSwitcherMobile.tsx (+22 -2)
📝 packages/client/src/components/connections/ConnectionEditor.tsx (+144 -1)
➕ packages/client/src/components/connections/NanoGptUsageWidget.tsx (+319 -0)
📝 packages/client/src/features/chat-settings/sections/ConnectionSection.tsx (+23 -5)
📝 packages/client/src/hooks/use-connections.ts (+44 -0)
📝 packages/client/src/lib/connection-filters.ts (+13 -0)
➕ packages/client/src/lib/nanogpt-quota.ts (+36 -0)
📝 packages/client/src/localization/locales/en.json (+35 -0)
📝 packages/server/src/db/schema/connections.ts (+7 -0)
📝 packages/server/src/routes/backup.routes.ts (+4 -1)
📝 packages/server/src/routes/connections.routes.ts (+61 -3)
➕ packages/server/src/services/nanogpt/subscription-usage.ts (+234 -0)
📝 packages/server/src/services/storage/connections.storage.ts (+33 -2)
📝 packages/shared/src/schemas/connection.schema.ts (+8 -0)
📝 packages/shared/src/types/connection.ts (+2 -0)

...and 4 more files

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Closes #6684

Why this change

  • NanoGPT users cannot see how much of their subscription they have used without
    leaving Marinara for the NanoGPT dashboard, and the model dropdown gives no hint
    which models are covered, which cost more of the quota, and which bill to the
    paid balance instead. You find out you are near the limit when generation starts
    failing, and the expensive model looks identical to the cheap one.

What changed

  • 1. An optional Management Token field on NanoGPT connections, below the API
    key. A management token can be created with a usage:read-only scope, so the
    credential used for quota reads cannot spend balance. It is preferred when
    present; the API key is used as a fallback when it is not. Can be cleared with a toggle
    that triggers on connection save.

  • 2. A per-connection "Show subscription usage" toggle (off by default) that
    displays weekly and daily input-token quotas in three places: the connection
    editor, the chat settings connection section, and the inline connection picker
    above the composer. The picker variant mirrors the context budget bar directly
    above it.

  • 3. Model list indicators, from the subscription block already returned by
    the existing detailed=true models call, so they cost no extra request:

    • Nx pill (accent) when the subscription covers the model and it consumes more
      than one input token per token sent
    • green 1x pill when covered at the normal rate
    • Paid pill when the model is not in the subscription
    • no pill when there is no subscription data to report

    Design decisions worth reviewing

  • The management token is a quota-widget credential, not an API-key substitute.
    NanoGPT's management endpoint rejects inference keys, and the inference endpoint
    rejects management tokens, so the two are not interchangeable. The widget tries
    the management token first and falls back to the API key.

  • Both endpoint hosts are hardcoded. Neither is derivable from the stored base
    URL (https://nano-gpt.com/api/v1). Management tokens only work against
    nano-gpt.com/... (no api. prefix); inference keys only against
    api.nano-gpt.com/....

  • The multiplier pill only renders for included: true. Excluded models report
    a multiplier of 1, which would otherwise read as full subscription coverage.

  • "Unknown" is rendered as unknown, never as 0% or 100%. A degraded: true
    response with null counters has no honest bar to draw.

  • percentUsed is a fraction and may exceed 1, so the bar clamps rather than
    overflowing.

  • subscription.included is free from the detailed=true call already being
    made, so the Paid pill adds no requests.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

  • Manually verify the meter appears in the connection editor for a NanoGPT
    connection with the toggle enabled, and does not appear with it disabled
  • Manually verify the meter appears in the chat settings Connection section,
    spaced correctly from the select above it
  • Manually verify the meter appears in the inline connection picker, and does
    not appear when the active connection is Random
  • Manually verify the meter follows the app accent color, including the
    gradient accent setting
  • Manually verify saving a management token switches the badge from
    "via API key" to "via management token"
  • Manually verify 1x / 2x / Paid pills against a real NanoGPT model list
  • Manually verify light and dark themes
  • Manually verify the meter on mobile width
  • Manually verified both the usage toggle and management token persisting
    in duplicated connection.
  • Manually verified the management token clearing, and falling back to API key

Docs and release impact

  • No docs changes needed

  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed

  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)

  • Version/release files updated (only if this PR includes a version bump)

    Notes for the reviewer

  • subscription.inputTokenMultiplier is not in NanoGPT's published OpenAPI
    dump, but it is returned by the live API and was verified by direct request. It
    is nested under subscription alongside included. Happy to drop the
    multiplier pill if you would rather not depend on an undocumented field.

  • The new columns use defaults, so no migration and no STORAGE_VERSION bump:
    normalizeRow() backfills missing columns via defaultForColumn().

  • Both new columns are cleared when a connection's provider changes away from
    NanoGPT.

  • Docs: docs/connections/providers-reference.md is updated. Per AGENTS.md
    this needs a docs-i18n mirror or a [docs-i18n] follow-up issue — flagging
    rather than assuming which you prefer.

    Future providers: what this widget already supports

The meter is deliberately provider-shaped rather than NanoGPT-shaped, so a later
PR can extend it. Three seams exist today:

Already reusable without change

  • QuotaBar and the widget shell contain no provider logic. Their only NanoGPT
    references are the import, the hook call, and the type/component names.
  • nanogpt-quota.ts operates on a structural QuotaWindowLike (used /
    remaining / percentUsed), not on NanoGPT's concrete type. Any provider that
    can produce those three numbers reuses this file as-is.
  • The credential badge is driven by the payload (data.credential), not by a
    provider check.
  • providerDisplayName() reads the shared PROVIDERS catalog, so a second
    provider is labelled from its own definition.

Requires work before a second provider can report usage

  1. resolveNanoGptUsageConnection hardcodes provider !== "nanogpt". All three
    render sites gate through it, so it needs to resolve which providers support a
    meter instead of naming one.
  2. GET /connections/:id/subscription-usage rejects non-NanoGPT connections and
    is a single-provider path; the client hook hardcodes that URL.
  3. The credential enum is "management_token" | "api_key", which is
    NanoGPT-specific vocabulary that other providers will not share.
  4. managementTokenEncrypted is provider-shaped storage. showUsageWidget is
    already generic.

Note on providers with no endpoint

Claude (Subscription) and Grok CLI route through local harnesses rather than a
quota API, and NovelAI's Opus tier for diffusion v5 exposes no usage endpoint
today. The current degraded: true path means "the lookup failed, counters are
unknown" — it assumes a lookup was attempted. A provider with no usage
capability at all
is a different state and should simply not render the meter,
rather than render a permanent unknown. Worth deciding before the next provider
lands, but out of scope here.

No refactor is included in this PR: the shape of the next provider's API is not
known yet, and guessing at it would add abstraction without a caller.

UI evidence (if applicable)

Mobile

mobile 2 mobile 3 - ehhh mobile 1 image

PC - On States

quick connections usage meter connection settings usage connections editor usage + management token + toggle no contamination on other providers for model list

Other Providers | or toggled off

mobile 4 no usage on no nanogpt connection no contamination on other providers no contamination on other providers for model list

new ui after coderabbit review

new ui after coderabbit changes

Summary by CodeRabbit

  • New Features
    • NanoGPT connections can optionally display live subscription usage: weekly and daily quotas in connection settings, and a compact weekly quota in chat menus.
    • Configure usage tracking with a usage-only Management Token; if quota data is unavailable, it appears as unknown rather than unused.
    • Model lists identify subscription-included models, show input-token multipliers, and mark excluded models as paid.
  • Documentation
    • Added setup and usage guidance for NanoGPT subscription indicators and quota displays.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/6686 **Author:** [@ylli-selmani](https://github.com/ylli-selmani) **Created:** 9/25/2026 **Status:** ✅ Merged **Merged:** 9/26/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `feat/nanoGPTSubUsageIndicator` --- ### 📝 Commits (10+) - [`cbb4e13`](https://github.com/Pasta-Devs/Marinara-Engine/commit/cbb4e13872ac5b574acf6da1fde00a7adfc5be25) feat(connections): show NanoGPT subscription usage and model quota cost - [`e4c4195`](https://github.com/Pasta-Devs/Marinara-Engine/commit/e4c41956b154826481922de8d8bea91a39e46c16) fix(connections): show the NanoGPT usage meter in the chat HUD - [`8168471`](https://github.com/Pasta-Devs/Marinara-Engine/commit/81684715914fcc3c5041c2f4190f1eb03122b6ae) feat(connections): show the NanoGPT meter in the connection picker - [`6ab6f41`](https://github.com/Pasta-Devs/Marinara-Engine/commit/6ab6f41672836c0cebc0be6b54875f461dca6342) feat(connections): label the usage meter and fit it to the picker - [`57eb404`](https://github.com/Pasta-Devs/Marinara-Engine/commit/57eb4040a0f24ea76ddbf7e50e0b5989cceb8157) fix(connections): de-duplicate the compact meter and re-card the panel - [`19bf96e`](https://github.com/Pasta-Devs/Marinara-Engine/commit/19bf96e7b5a8bf3a4738eca7349d01fc82b67963) fix(connections): theme the quota bar and drop the leftover percentage - [`09bc52b`](https://github.com/Pasta-Devs/Marinara-Engine/commit/09bc52b6ee6844be65ef83de4fe6b638f6dada0c) fix(connections): restore spacing around the usage toggle and theme it - [`22f45b2`](https://github.com/Pasta-Devs/Marinara-Engine/commit/22f45b2552df0276d01ac8fd1473e3bf40f4ea58) fix(chat-settings): space the usage meter from the connection select - [`394f97d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/394f97d197921b5cc2c4f11b915a52756c2162bb) fix(connections): address review findings on the NanoGPT usage feature - [`45dc64b`](https://github.com/Pasta-Devs/Marinara-Engine/commit/45dc64bb7dd594f34b8dfb10575a1f1ef50855e4) Merge branch 'staging' into feat/nanoGPTSubUsageIndicator ### 📊 Changes **24 files changed** (+1483 additions, -36 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+2 -0) 📝 `docs/connections/providers-reference.md` (+20 -0) ➕ `e2e/nanogpt-usage.e2e.ts` (+97 -0) 📝 `packages/client/src/components/chat/ChatSettingsDrawer.tsx` (+9 -18) 📝 `packages/client/src/components/chat/QuickConnectionSwitcher.tsx` (+26 -3) 📝 `packages/client/src/components/chat/QuickSwitcherMobile.tsx` (+22 -2) 📝 `packages/client/src/components/connections/ConnectionEditor.tsx` (+144 -1) ➕ `packages/client/src/components/connections/NanoGptUsageWidget.tsx` (+319 -0) 📝 `packages/client/src/features/chat-settings/sections/ConnectionSection.tsx` (+23 -5) 📝 `packages/client/src/hooks/use-connections.ts` (+44 -0) 📝 `packages/client/src/lib/connection-filters.ts` (+13 -0) ➕ `packages/client/src/lib/nanogpt-quota.ts` (+36 -0) 📝 `packages/client/src/localization/locales/en.json` (+35 -0) 📝 `packages/server/src/db/schema/connections.ts` (+7 -0) 📝 `packages/server/src/routes/backup.routes.ts` (+4 -1) 📝 `packages/server/src/routes/connections.routes.ts` (+61 -3) ➕ `packages/server/src/services/nanogpt/subscription-usage.ts` (+234 -0) 📝 `packages/server/src/services/storage/connections.storage.ts` (+33 -2) 📝 `packages/shared/src/schemas/connection.schema.ts` (+8 -0) 📝 `packages/shared/src/types/connection.ts` (+2 -0) _...and 4 more files_ </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. <!-- See CONTRIBUTING.md § Branches. --> ## Linked issue <!-- Every PR should reference a feature request or issue report. If there isn't one yet, open one first to gather opinions: --> <!-- https://github.com/Pasta-Devs/Marinara-Engine/issues/new/choose --> Closes #6684 ## Why this change <!-- What user problem, bug, or goal does this solve? --> - NanoGPT users cannot see how much of their subscription they have used without leaving Marinara for the NanoGPT dashboard, and the model dropdown gives no hint which models are covered, which cost more of the quota, and which bill to the paid balance instead. You find out you are near the limit when generation starts failing, and the expensive model looks identical to the cheap one. ## What changed <!-- List the key changes in this PR --> - **1. An optional Management Token field** on NanoGPT connections, below the API key. A management token can be created with a `usage:read`-only scope, so the credential used for quota reads cannot spend balance. It is preferred when present; the API key is used as a fallback when it is not. Can be cleared with a toggle that triggers on connection save. - **2. A per-connection "Show subscription usage" toggle** (off by default) that displays weekly and daily input-token quotas in three places: the connection editor, the chat settings connection section, and the inline connection picker above the composer. The picker variant mirrors the context budget bar directly above it. - **3. Model list indicators**, from the `subscription` block already returned by the existing `detailed=true` models call, so they cost no extra request: - `Nx` pill (accent) when the subscription covers the model and it consumes more than one input token per token sent - green `1x` pill when covered at the normal rate - `Paid` pill when the model is not in the subscription - no pill when there is no subscription data to report ## Design decisions worth reviewing - **The management token is a quota-widget credential, not an API-key substitute.** NanoGPT's management endpoint rejects inference keys, and the inference endpoint rejects management tokens, so the two are not interchangeable. The widget tries the management token first and falls back to the API key. - **Both endpoint hosts are hardcoded.** Neither is derivable from the stored base URL (`https://nano-gpt.com/api/v1`). Management tokens only work against `nano-gpt.com/...` (no `api.` prefix); inference keys only against `api.nano-gpt.com/...`. - **The multiplier pill only renders for `included: true`.** Excluded models report a multiplier of 1, which would otherwise read as full subscription coverage. - **"Unknown" is rendered as unknown, never as 0% or 100%.** A `degraded: true` response with null counters has no honest bar to draw. - **`percentUsed` is a fraction and may exceed 1**, so the bar clamps rather than overflowing. - **`subscription.included` is free** from the `detailed=true` call already being made, so the `Paid` pill adds no requests. ## Validation <!-- Required: include commands run and/or manual checks performed --> - [x] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [x] Ran the app, clicked through the changes manually - [x] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [x] Above manual verification completed (describe below) - [x] Read and followed `CONTRIBUTING.md` ### Manual verification notes <!-- Describe exactly what you tested in a real browser/app, step by step. --> <!-- ⚠️ If an AI agent filled out or ticked these boxes for you, treat them --> <!-- as a TO-DO LIST, not as proof the work is done. Verify each item yourself --> <!-- before submitting. If you haven't verified it, untick the box. --> - [x] Manually verify the meter appears in the connection editor for a NanoGPT connection with the toggle enabled, and does not appear with it disabled - [x] Manually verify the meter appears in the chat settings Connection section, spaced correctly from the select above it - [x] Manually verify the meter appears in the inline connection picker, and does not appear when the active connection is Random - [x] Manually verify the meter follows the app accent color, including the gradient accent setting - [x] Manually verify saving a management token switches the badge from "via API key" to "via management token" - [x] Manually verify `1x` / `2x` / `Paid` pills against a real NanoGPT model list - [x] Manually verify light and dark themes - [x] Manually verify the meter on mobile width - [x] Manually verified both the usage toggle and management token persisting in duplicated connection. - [x] Manually verified the management token clearing, and falling back to API key ## Docs and release impact - [ ] No docs changes needed - [x] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [x] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) ## Notes for the reviewer - `subscription.inputTokenMultiplier` is **not** in NanoGPT's published OpenAPI dump, but it is returned by the live API and was verified by direct request. It is nested under `subscription` alongside `included`. Happy to drop the multiplier pill if you would rather not depend on an undocumented field. - The new columns use defaults, so no migration and no `STORAGE_VERSION` bump: `normalizeRow()` backfills missing columns via `defaultForColumn()`. - Both new columns are cleared when a connection's provider changes away from NanoGPT. - Docs: `docs/connections/providers-reference.md` is updated. Per `AGENTS.md` this needs a `docs-i18n` mirror or a `[docs-i18n]` follow-up issue — flagging rather than assuming which you prefer. ## Future providers: what this widget already supports The meter is deliberately provider-shaped rather than NanoGPT-shaped, so a later PR can extend it. Three seams exist today: **Already reusable without change** - `QuotaBar` and the widget shell contain no provider logic. Their only NanoGPT references are the import, the hook call, and the type/component names. - `nanogpt-quota.ts` operates on a structural `QuotaWindowLike` (`used` / `remaining` / `percentUsed`), not on NanoGPT's concrete type. Any provider that can produce those three numbers reuses this file as-is. - The credential badge is driven by the payload (`data.credential`), not by a provider check. - `providerDisplayName()` reads the shared `PROVIDERS` catalog, so a second provider is labelled from its own definition. **Requires work before a second provider can report usage** 1. `resolveNanoGptUsageConnection` hardcodes `provider !== "nanogpt"`. All three render sites gate through it, so it needs to resolve which providers support a meter instead of naming one. 2. `GET /connections/:id/subscription-usage` rejects non-NanoGPT connections and is a single-provider path; the client hook hardcodes that URL. 3. The `credential` enum is `"management_token" | "api_key"`, which is NanoGPT-specific vocabulary that other providers will not share. 4. `managementTokenEncrypted` is provider-shaped storage. `showUsageWidget` is already generic. **Note on providers with no endpoint** Claude (Subscription) and Grok CLI route through local harnesses rather than a quota API, and NovelAI's Opus tier for diffusion v5 exposes no usage endpoint today. The current `degraded: true` path means "the lookup failed, counters are unknown" — it assumes a lookup was attempted. A provider with *no usage capability at all* is a different state and should simply not render the meter, rather than render a permanent unknown. Worth deciding before the next provider lands, but out of scope here. No refactor is included in this PR: the shape of the next provider's API is not known yet, and guessing at it would add abstraction without a caller. ## UI evidence (if applicable) <!-- Add before/after screenshots or recordings for UI changes --> ### Mobile <img width="133" height="274" alt="mobile 2" src="https://github.com/user-attachments/assets/96ab0586-7339-497f-b8a1-c417a7bc4eaf" /> <img width="140" height="273" alt="mobile 3 - ehhh" src="https://github.com/user-attachments/assets/c7e22f7b-0ff7-4745-b993-8be5db68e368" /> <img width="144" height="277" alt="mobile 1" src="https://github.com/user-attachments/assets/afe10fdf-f965-4ae5-b9a6-f64c3fcc9732" /> <img width="144" height="277" alt="image" src="https://github.com/user-attachments/assets/88fbeeb5-3c5d-4984-8964-5968e397ce1f" /> --- ### PC - On States <img width="416" height="154" alt="quick connections usage meter" src="https://github.com/user-attachments/assets/62ef52cd-696f-4476-ba9e-caef27405e35" /> <img width="354" height="334" alt="connection settings usage" src="https://github.com/user-attachments/assets/cda14329-fd0d-42bc-bc7b-4630f17ec050" /> <img width="436" height="327" alt="connections editor usage + management token + toggle" src="https://github.com/user-attachments/assets/0e8d59b7-0576-4a76-8223-7262e9d6960d" /> <img width="348" height="203" alt="no contamination on other providers for model list" src="https://github.com/user-attachments/assets/c2a7e431-c6d3-4ed6-96b9-dd3c0c527beb" /> --- ### Other Providers | or toggled off <img width="166" height="108" alt="mobile 4" src="https://github.com/user-attachments/assets/5b8a8d87-6d81-43cf-b090-a15f1c26d2c0" /> <img width="389" height="339" alt="no usage on no nanogpt connection" src="https://github.com/user-attachments/assets/22afca06-d39f-4bf4-95d5-26992449e57b" /> <img width="441" height="329" alt="no contamination on other providers" src="https://github.com/user-attachments/assets/282d821b-60c5-42d2-ad23-2bef1897b253" /> <img width="348" height="203" alt="no contamination on other providers for model list" src="https://github.com/user-attachments/assets/635f9972-39f1-4c0d-9008-5a696852c7e6" /> ### new ui after coderabbit review <img width="500" height="250" alt="new ui after coderabbit changes" src="https://github.com/user-attachments/assets/64e10138-c054-488c-bd5a-4b7065435180" /> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * NanoGPT connections can optionally display live subscription usage: weekly and daily quotas in connection settings, and a compact weekly quota in chat menus. * Configure usage tracking with a usage-only Management Token; if quota data is unavailable, it appears as unknown rather than unused. * Model lists identify subscription-included models, show input-token multipliers, and mark excluded models as paid. * **Documentation** * Added setup and usage guidance for NanoGPT subscription indicators and quota displays. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:18:17 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#7287
No description provided.