Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

fix(account): show the tray's "credits left" under the meter, one shared sum (T2, FEHLER-T2 #1)

purple173327305e7a
diff --git a/src/components/auth/AccountPanel.tsx b/src/components/auth/AccountPanel.tsx
index cd53fc2a..ed107ac5 100644
--- a/src/components/auth/AccountPanel.tsx
+++ b/src/components/auth/AccountPanel.tsx
@@ -13,6 +13,7 @@ import { CLOUD_BASE } from '../../api/cloud/config'
import { MONOGRAM } from '../layout/brand'
import { openExternal } from '../../api/backend'
import { formatCount } from '../../lib/formatters'
+import { creditsLeft, creditsLeftLine } from '../../lib/credits-left'
import { countUnsyncedAccountMemories } from '../../lib/memory-unsynced'
import { PAST_DUE_ACTION, PAST_DUE_BADGE, PAST_DUE_WALLET_LINE, pastDueLine } from '../../lib/past-due'
import { Modal } from '../ui/Modal'
@@ -338,6 +339,10 @@ export function AccountPanel() {
used={Number(quota.used.credits_used)}
limit={quota.limits.credits}
/>
+ {/* The tray's "credits left" (Plan & Credits… lands here), same sum. */}
+ <p data-testid="credits-left" className="text-[0.65rem] text-gray-500 dark:text-gray-500 tabular-nums">
+ {creditsLeftLine(creditsLeft(quota))}
+ </p>
</div>
) : (
!pastDue && (
diff --git a/src/components/auth/__tests__/a-failed-payment-is-shown-as-one.test.tsx b/src/components/auth/__tests__/a-failed-payment-is-shown-as-one.test.tsx
index dd20634f..814bd67f 100644
--- a/src/components/auth/__tests__/a-failed-payment-is-shown-as-one.test.tsx
+++ b/src/components/auth/__tests__/a-failed-payment-is-shown-as-one.test.tsx
@@ -102,3 +102,23 @@ describe('no failed payment', () => {
expect(screen.queryByTestId('past-due-notice')).toBeNull()
})
})
+
+describe('credits left (FEHLER-T2 #1)', () => {
+ it('shows the same "credits left" as the tray under the meter, top-up named', () => {
+ signIn({
+ licenseActive: true,
+ tier: 'hosted-pro',
+ quota: { ...walletQuota, limits: { credits: 2000 }, used: { credits_used: 1060 }, remaining: { credits: 940 }, topup: { credits: 300 } },
+ paidPlan: true,
+ })
+ render(<AccountPanel />)
+ expect(screen.getByText('1,060 / 2,000')).toBeTruthy()
+ expect(screen.getByTestId('credits-left').textContent).toBe('1,240 credits left (incl. 300 top-up)')
+ })
+
+ it('without a top-up it is the monthly rest alone', () => {
+ signIn({ licenseActive: true, tier: 'hosted', quota: { ...walletQuota, tier: 'hosted' }, paidPlan: true })
+ render(<AccountPanel />)
+ expect(screen.getByTestId('credits-left').textContent).toBe('3,800 credits left')
+ })
+})
diff --git a/src/hooks/useTraySync.ts b/src/hooks/useTraySync.ts
index ee4f3b02..215b316a 100644
--- a/src/hooks/useTraySync.ts
+++ b/src/hooks/useTraySync.ts
@@ -15,6 +15,7 @@ import type { EngineStatus } from '../api/engine'
import { readLoadedModels } from '../api/ollama'
import { displayModelName, getProviderIdFromModel } from '../api/providers/model-name'
import { isMobile } from '../lib/device-kind'
+import { creditsLeft } from '../lib/credits-left'
import { builtinModelMatches, builtinModelNameFromPath } from '../lib/builtin-model-identity'
import { isBuiltinEngineEntry } from '../lib/lmstudio-match'
import { LU_ENGINE_NAME } from '../lib/engine-name'
@@ -68,7 +69,7 @@ export function currentTrayStatus(): TrayStatus {
tier: a.tier ?? q?.tier ?? null,
licenseActive: a.licenseActive,
pastDue: a.pastDue,
- credits: q ? q.remaining.credits + (q.topup?.credits ?? 0) : null,
+ credits: q ? creditsLeft(q).total : null,
})
}
const { models, activeModel } = useModelStore.getState()
diff --git a/src/lib/__tests__/credits-left.test.ts b/src/lib/__tests__/credits-left.test.ts
new file mode 100644
index 00000000..5b67069b
--- /dev/null
+++ b/src/lib/__tests__/credits-left.test.ts
@@ -0,0 +1,42 @@
+/**
+ * One sum of the credits left, for the tray line and for Settings → LU Cloud
+ * Account (FEHLER-T2 #1, 3.0.9): the tray said "1,240 credits left" while the
+ * panel the click lands on showed only "1,060 / 2,000" used.
+ *
+ * Run: npx vitest run src/lib/__tests__/credits-left.test.ts
+ */
+import { describe, expect, it } from 'vitest'
+import type { CloudQuota } from '../render/cloud-jobs'
+import { creditsLeft, creditsLeftLine } from '../credits-left'
+
+const quota = (over: Partial<CloudQuota> = {}): CloudQuota => ({
+ tier: 'hosted-pro',
+ period: '2026-10',
+ limits: { credits: 2000 },
+ costs: { image: 10, video: 100 },
+ used: { credits_used: 1060 },
+ remaining: { credits: 940 },
+ topup: { credits: 300 },
+ ...over,
+})
+
+describe('credits left', () => {
+ it('is the monthly rest plus the bought credits', () => {
+ expect(creditsLeft(quota())).toEqual({ total: 1240, topup: 300 })
+ expect(creditsLeftLine(creditsLeft(quota()))).toBe('1,240 credits left (incl. 300 top-up)')
+ })
+
+ it('names no top-up when there is none', () => {
+ const c = creditsLeft(quota({ topup: undefined }))
+ expect(c).toEqual({ total: 940, topup: 0 })
+ expect(creditsLeftLine(c)).toBe('940 credits left')
+ })
+
+ it('never goes below zero or shows fractions', () => {
+ expect(creditsLeft(quota({ remaining: { credits: -20 }, topup: { credits: 12.7 } }))).toEqual({ total: 12, topup: 12 })
+ })
+
+ it('the tray line is the same number without the brackets', () => {
+ expect(creditsLeftLine(creditsLeft(quota()), { short: true })).toBe('1,240 credits left')
+ })
+})
diff --git a/src/lib/credits-left.ts b/src/lib/credits-left.ts
new file mode 100644
index 00000000..ef45e309
--- /dev/null
+++ b/src/lib/credits-left.ts
@@ -0,0 +1,25 @@
+// The credits an account has left: the monthly allowance still open plus the
+// bought ones (top-up). One sum for the tray line and for Settings → LU Cloud
+// Account, so the click on "Plan & Credits…" lands on the same number it
+// came from (FEHLER-T2 #1, 3.0.9).
+
+import { formatCount } from './formatters'
+import type { CloudQuota } from './render/cloud-jobs'
+
+export interface CreditsLeft {
+ total: number
+ topup: number
+}
+
+const whole = (n: unknown): number => Math.max(0, Math.floor(Number(n) || 0))
+
+export function creditsLeft(quota: Pick<CloudQuota, 'remaining' | 'topup'>): CreditsLeft {
+ const topup = whole(quota.topup?.credits)
+ return { total: whole(quota.remaining?.credits) + topup, topup }
+}
+
+/** "1,240 credits left (incl. 300 top-up)"; `short` drops the brackets (tray). */
+export function creditsLeftLine(c: CreditsLeft, opts: { short?: boolean } = {}): string {
+ const line = `${formatCount(c.total)} credits left`
+ return !opts.short && c.topup > 0 ? `${line} (incl. ${formatCount(c.topup)} top-up)` : line
+}
diff --git a/src/lib/tray-menu.ts b/src/lib/tray-menu.ts
index 9bc9c5fa..35a4f866 100644
--- a/src/lib/tray-menu.ts
+++ b/src/lib/tray-menu.ts
@@ -16,6 +16,7 @@
// So a state with nothing to say on a line says so instead of leaving it out.
import { PLAN_NAMES } from './past-due'
+import { creditsLeftLine } from './credits-left'
export type TrayDot = 'green' | 'amber' | 'grey'
export interface TrayLine {
@@ -61,7 +62,7 @@ export function cloudTrayStatus(c: TrayCloudInput): TrayStatus {
lines.push({ text: 'No active plan', dot: 'grey' })
}
lines.push({
- text: c.credits === null ? 'Credits …' : `${Math.max(0, Math.floor(c.credits)).toLocaleString('en-US')} credits left`,
+ text: c.credits === null ? 'Credits …' : creditsLeftLine({ total: Math.max(0, Math.floor(c.credits)), topup: 0 }, { short: true }),
})
return { lines, action: 'plan' }
}