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(billing): A1 Nachbesserung B1/B2/B3/B6, Wortlaut und Tests an Web ziehen

purplea85b67514a20
diff --git a/src/components/create/experimental/CreditsMeter.tsx b/src/components/create/experimental/CreditsMeter.tsx
index e16366cf..920d123b 100644
--- a/src/components/create/experimental/CreditsMeter.tsx
+++ b/src/components/create/experimental/CreditsMeter.tsx
@@ -61,8 +61,10 @@ export function CreditsMeter() {
const remaining = quota.remaining.credits
const limit = quota.limits.credits
const state = meterState(quota, cost, kind, op)
- // A wallet-fixable shortfall (credits, video budget) lands on the credits
- // tab; the training count is a plan property, so that one goes to the plans.
+ // Every shortfall this chip can show is wallet-fixable now, trainings
+ // included since a topup wallet can fund a run past the included count
+ // (server migration 0047), so all three send the customer to the credits
+ // tab, not to a plan change.
//
// Der Knopf traegt die Flaeche des Zaehlers daneben und den Fehlerton als
// SCHRIFT. Vorher war er gelb gefuellt, also dieselbe Farbe, mit der ein
@@ -98,9 +100,16 @@ export function CreditsMeter() {
state.showVideoBudget && quota.video
? ` (monthly video budget: ${quota.video.remaining} of ${quota.video.limit} credits left)`
: ''
+ // B3 (review-a1.md): the chip beside this tooltip can already show more
+ // runs than the included count once a topup wallet covers the run
+ // (trainingPackRun in credits-meter.ts). Without this half-sentence the
+ // tooltip named only the included count and read as a contradiction next
+ // to the chip's own number.
+ const topup = quota.topup?.credits ?? 0
+ const trainingPackRun = op === 'lora-train' && cost > 0 && topup >= cost
const trainingTail =
op === 'lora-train' && quota.trainings
- ? ` (${quota.trainings.remaining} of ${quota.trainings.limit} included trainings left)`
+ ? ` (${quota.trainings.remaining} of ${quota.trainings.limit} included trainings left${trainingPackRun ? '; paid credits unlock more' : ''})`
: ''
return (
diff --git a/src/hooks/__tests__/a-429-is-not-always-money.test.ts b/src/hooks/__tests__/a-429-is-not-always-money.test.ts
index 4735f7b0..1ded0072 100644
--- a/src/hooks/__tests__/a-429-is-not-always-money.test.ts
+++ b/src/hooks/__tests__/a-429-is-not-always-money.test.ts
@@ -37,9 +37,10 @@ describe('jeder Geldgrund traegt seinen eigenen Satz, wortgleich mit dem Web', (
.toBe("This month's video budget is used up. Top-up credits keep video going, or upgrade your plan.")
})
- it('monthly character trainings, and it does not point at a clock', () => {
+ it('monthly character trainings, names the top-up path, wortgleich mit dem Web (B1, review-a1.md)', () => {
const err = new CloudJobError('no trainings left', 429, { code: 'trainings_exhausted' })
- expect(throttleMessage(err)).toBe("Your plan's character trainings for this month are used up.")
+ expect(throttleMessage(err))
+ .toBe('Your included character trainings are used up. Top-up credits keep training going, or upgrade your plan.')
expect(throttleMessage(err)).not.toMatch(/try again|wait/i)
})
diff --git a/src/hooks/useCloudCreate.ts b/src/hooks/useCloudCreate.ts
index 427f0caa..580d878d 100644
--- a/src/hooks/useCloudCreate.ts
+++ b/src/hooks/useCloudCreate.ts
@@ -119,7 +119,12 @@ export function throttleMessage(err: CloudJobError): string {
return "This month's video budget is used up. Top-up credits keep video going, or upgrade your plan."
case 'trainings_exhausted':
signalCreditsExhausted('trainings')
- return "Your plan's character trainings for this month are used up."
+ // B1 (review-a1.md): a pack buyer with topup credits can still start a
+ // training the moment this fires, the server race between quota read
+ // and submit is what triggers it. The old sentence only offered a plan
+ // change and hid that path, so it now matches the web word for word
+ // (89055415, apps/web/hooks/useCloudCreate.ts).
+ return 'Your included character trainings are used up. Top-up credits keep training going, or upgrade your plan.'
}
const secs = err.retryAfterMs && err.retryAfterMs > 0 ? Math.ceil(err.retryAfterMs / 1000) : null
return secs
diff --git a/src/lib/render/__tests__/credits-meter.test.ts b/src/lib/render/__tests__/credits-meter.test.ts
index d783db48..8ffc7cf8 100644
--- a/src/lib/render/__tests__/credits-meter.test.ts
+++ b/src/lib/render/__tests__/credits-meter.test.ts
@@ -135,6 +135,94 @@ describe('character trainings use included runs or paid credits', () => {
})
})
+// B6 (review-a1.md): the two new trainingPackRun cases proved the branch
+// exists, but left three gaps the review named by name. These three close
+// them without touching meterState itself, which is why the two existing
+// cases above still pass unchanged.
+describe('B6: der gemischte Fall aus Monatsraum und Pack-Wallet', () => {
+ it('9 Trainings, wenn beide Quellen zusammen neun Laeufe decken', () => {
+ // Hosted-Pool 900k plus ein 450k-Pack, beide Trainings des Plans schon
+ // verbraucht, ein Training kostet 150k: (900k + 450k) / 150k = 9. Das ist
+ // genau die Zahl aus B4, die vor diesem Test nirgends festgenagelt war.
+ const q = hosted({
+ remaining: { credits: 1_350_000 },
+ topup: { credits: 450_000 },
+ trainings: { limit: 2, used: 2, remaining: 0 },
+ })
+ expect(meterState(q, 150_000, 'image', 'lora-train')).toMatchObject({
+ kind: 'ok', runsLeft: 9, unit: 'trainings',
+ })
+ })
+})
+
+describe('B6: die starter-Form der Quota (kein Plan, nur Wallet)', () => {
+ it('ein reiner Pack-Kaeufer ohne Plan-Trainings kann trotzdem trainieren', () => {
+ // starter traegt trainings.limit 0 und video.limit 0 (TIER_TRAININGS,
+ // TIER_VIDEO_CREDITS in apps/web/lib/billing/credits.ts): kein Monatsraum
+ // fuer eins von beiden, nur die Wallet. Der bestehende Test oben pruefte
+ // das nur an der hosted-Form, wo ein Monatsraum existiert.
+ const starter: CloudQuota = {
+ tier: 'starter',
+ period: '2026-09-01',
+ limits: { credits: 450_000 },
+ costs: { image: 300, video: 15_000 },
+ used: { credits_used: 0 },
+ remaining: { credits: 450_000 },
+ topup: { credits: 450_000 },
+ video: { limit: 0, used: 0, remaining: 0 },
+ trainings: { limit: 0, used: 0, remaining: 0 },
+ }
+ expect(meterState(starter, 100_000, 'image', 'lora-train')).toMatchObject({
+ kind: 'ok', runsLeft: 4, unit: 'trainings',
+ })
+ })
+
+ it('GEGENPROBE: eine leere Wallet lehnt trotz gekauftem Nullplan ab', () => {
+ const starter: CloudQuota = {
+ tier: 'starter',
+ period: '2026-09-01',
+ limits: { credits: 0 },
+ costs: { image: 300, video: 15_000 },
+ used: { credits_used: 0 },
+ remaining: { credits: 0 },
+ topup: { credits: 0 },
+ video: { limit: 0, used: 0, remaining: 0 },
+ trainings: { limit: 0, used: 0, remaining: 0 },
+ }
+ expect(meterState(starter, 100_000, 'image', 'lora-train')).toEqual({
+ kind: 'insufficient', remaining: 0, cost: 100_000,
+ })
+ })
+})
+
+describe('B6: Gegenprobe, der Video-Unterdeckel bleibt von trainingPackRun unberuehrt', () => {
+ it('ein Pack, gross genug fuer ein Training, oeffnet nicht den Video-Unterdeckel', () => {
+ // trainingPackRun greift nur bei isTraining (op === 'lora-train'). Die
+ // Wallet reicht fuer das 20k-Training, aber nicht fuer den 40k-Videoclip:
+ // ein Video-Render mit derselben Wallet muss weiterhin am eigenen
+ // Unterdeckel scheitern, sonst haette das Zusammenlegen beider Zweige in
+ // einer Funktion den Video-Deckel mit durchlaessig gemacht.
+ const q = hosted({
+ remaining: { credits: 50_000 },
+ topup: { credits: 30_000 },
+ video: { limit: 900_000, used: 900_000, remaining: 0 },
+ })
+ expect(meterState(q, 40_000, 'video', 'generate')).toEqual({ kind: 'no-video-budget' })
+ })
+
+ it('dieselbe Wallet, als guenstigeres Training statt Video, laesst den Lauf durch', () => {
+ // Gegenstueck zum Test daneben: derselbe Kontostand, nur der Zweig und die
+ // Kosten wechseln. Das zeigt, dass die beiden Deckel wirklich getrennt
+ // bleiben, nicht dass einer von beiden immer sperrt oder immer durchlaesst.
+ const q = hosted({
+ remaining: { credits: 50_000 },
+ topup: { credits: 30_000 },
+ trainings: { limit: 2, used: 2, remaining: 0 },
+ })
+ expect(meterState(q, 20_000, 'image', 'lora-train')).toMatchObject({ kind: 'ok' })
+ })
+})
+
describe('an older server never gates', () => {
it('treats absent video and training fields as uncapped', () => {
// A pre-0029 server sends neither. Reading a missing field as zero would
diff --git a/src/lib/render/cloud-jobs.ts b/src/lib/render/cloud-jobs.ts
index 7f72040a..180ba040 100644
--- a/src/lib/render/cloud-jobs.ts
+++ b/src/lib/render/cloud-jobs.ts
@@ -32,8 +32,8 @@ export interface CloudQuota {
topup?: { credits: number }
/** Monthly video sub-budget. `remaining` is the MONTHLY share only. */
video?: { limit: number; used: number; remaining: number }
- /** Character trainings this cycle. A count, not a budget: the wallet cannot
- * buy past it. */
+ /** Monthly included character-training count. A wallet with at least the
+ * cost of the selected trainer unlocks an additional metered run. */
trainings?: { limit: number; used: number; remaining: number }
}
diff --git a/src/lib/render/credits-meter.ts b/src/lib/render/credits-meter.ts
index 12acb33e..8b6a3205 100644
--- a/src/lib/render/credits-meter.ts
+++ b/src/lib/render/credits-meter.ts
@@ -25,8 +25,10 @@ export type MeterState =
showVideoBudget: boolean
}
-/** Video renders draw the 0029 sub-budget. A character training never does; it
- * draws the separate monthly COUNT instead. */
+/** Video renders draw the 0029 sub-budget. A character training draws the
+ * separate monthly COUNT first; once that count is spent, a wallet holding
+ * at least the full cost of the run unlocks one more (`trainingPackRun`
+ * below, server migration 0047). */
export function drawsVideoBudget(kind: RenderKind, op: RenderOp): boolean {
return kind === 'video' && op !== 'lora-train'
}