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.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
fix(credits): signalCreditsExhausted bekommt den Grund, der Dialog drei Titel (R5-51)
purple77a33e83dee6
diff --git a/src/components/layout/CreditsExhaustedModal.tsx b/src/components/layout/CreditsExhaustedModal.tsxindex 27d425b9..a6401184 100644--- a/src/components/layout/CreditsExhaustedModal.tsx+++ b/src/components/layout/CreditsExhaustedModal.tsx@@ -1,38 +1,62 @@import { useEffect, useState } from 'react'import { Zap } from 'lucide-react'import { Modal } from '../ui/Modal'-import { CREDITS_EXHAUSTED_EVENT, PRICING_URL } from '../../lib/credits-exhausted'+import { CREDITS_EXHAUSTED_EVENT, PRICING_URL, type ExhaustedReason } from '../../lib/credits-exhausted'import { CLOUD_SUBSCRIBER_LINE } from '../../lib/cloud-pitch'import { openExternal } from '../../api/backend'/**- * Globally mounted "out of credits" dialog. The OpenAI provider fires- * CREDITS_EXHAUSTED_EVENT when LU Cloud answers `code: 'credits_exhausted'`+ * Globally mounted "out of credits" dialog. The OpenAI provider and the cloud+ * Create hooks fire CREDITS_EXHAUSTED_EVENT for one of three server codes* (lib/credits-exhausted.ts); this turns it into a readable next step instead- * of a dead-end error line.+ * of a dead-end error line. The title and body follow the reason carried on+ * the event, matching apps/web/components/layout/CreditsExhaustedModal.tsx+ * (R5-51): the same refusal must not read differently on the two apps.** R5-51, Entscheid David vom 12.09.2026: der Knopf oeffnet die PREISSEITE im- * Browser, nicht die Aufladeseite. Wer leer ist, waehlt zwischen einem Plan- * und einem Paket; ein Knopf, der direkt in einen Kauf springt, nimmt ihm- * diese Wahl ab. Gekauft wird auf der Website.+ * Browser, nicht die Aufladeseite, fuer alle drei Gruende. Wer leer ist,+ * waehlt zwischen einem Plan und einem Paket; ein Knopf, der direkt in einen+ * Kauf springt, nimmt ihm diese Wahl ab. Gekauft wird auf der Website; ein+ * In-Dialog-Kauf wie im Web ist eine eigene Entscheidung fuer eine spaetere+ * Runde, nicht Teil dieses Fixes.*/export function CreditsExhaustedModal() {const [open, setOpen] = useState(false)+ const [reason, setReason] = useState<ExhaustedReason>('credits')useEffect(() => {- const show = () => setOpen(true)+ const show = (e: Event) => {+ const r = (e as CustomEvent<{ reason?: ExhaustedReason }>).detail?.reason+ setReason(r ?? 'credits')+ setOpen(true)+ }window.addEventListener(CREDITS_EXHAUSTED_EVENT, show)return () => window.removeEventListener(CREDITS_EXHAUSTED_EVENT, show)}, [])+ const title =+ reason === 'video_budget'+ ? "This month's video budget is used up"+ : reason === 'trainings'+ ? 'Top up to keep training'+ : "You're out of credits"+return (- <Modal open={open} onClose={() => setOpen(false)} title="You're out of credits">+ <Modal open={open} onClose={() => setOpen(false)} title={title}><div className="space-y-4">- <p className="text-sm text-gray-600 dark:text-gray-300">- Your plan credits for this billing period are used up. They refill on- your next renewal date. Top-up credits are one-time, never expire, and- are only used after your plan credits.- </p>+ {reason === 'trainings' ? (+ <p className="text-sm text-gray-600 dark:text-gray-300">+ Your included trainings refill on the next renewal date. Top-up+ credits can fund another training now, never expire, and work+ without a subscription.+ </p>+ ) : (+ <p className="text-sm text-gray-600 dark:text-gray-300">+ {reason === 'video_budget'+ ? 'Your plan credits are fine, but the monthly video budget is spent. Top-up credits are not part of that budget: they fund video directly, never expire, and are used only after your plan credits.'+ : 'Your plan credits for this billing period are used up. They refill on your next renewal date. Top-up credits are one-time, never expire, and are only used after your plan credits.'}+ </p>+ )}{/* Hier werden gleich Pakete angeboten, also steht daneben, was ein Aboje Euro mehr bringt. Zeichengleich mit dem Verkaufs-Panel, demVersionsblatt und dem CHANGELOG, aus einer Konstante, deren Faktordiff --git a/src/components/layout/__tests__/drei-gruende-drei-titel.test.tsx b/src/components/layout/__tests__/drei-gruende-drei-titel.test.tsxnew file mode 100644index 00000000..b7dd2015--- /dev/null+++ b/src/components/layout/__tests__/drei-gruende-drei-titel.test.tsx@@ -0,0 +1,52 @@+// @vitest-environment jsdom+/**+ * R5-51 — signalCreditsExhausted() and the dialog it opens used to know only+ * one reason ('credits'). The cloud Create hooks already distinguished three+ * server codes (credits_exhausted, video_budget_exhausted, trainings_exhausted,+ * see throttleMessage in useCloudCreate.ts) but only the first one opened the+ * dialog; the other two only printed a line the customer had no button under.+ * Matches apps/web/lib/credits-exhausted.ts and+ * apps/web/components/layout/CreditsExhaustedModal.tsx.+ *+ * Run: npx vitest run src/components/layout/__tests__/drei-gruende-drei-titel.test.tsx+ */+import { afterEach, describe, expect, it } from 'vitest'+import { act, cleanup, render, screen } from '@testing-library/react'+import { CreditsExhaustedModal } from '../CreditsExhaustedModal'+import { CREDITS_EXHAUSTED_EVENT, signalCreditsExhausted } from '../../../lib/credits-exhausted'++afterEach(() => cleanup())++describe('R5-51: three reasons, three titles', () => {+ it('credits (the default) shows the original title', () => {+ render(<CreditsExhaustedModal />)+ act(() => signalCreditsExhausted('credits'))+ expect(screen.getByText("You're out of credits")).toBeTruthy()+ })++ it('video_budget shows its own title and body, no plan-credits sentence', () => {+ render(<CreditsExhaustedModal />)+ act(() => signalCreditsExhausted('video_budget'))+ expect(screen.getByText("This month's video budget is used up")).toBeTruthy()+ expect(screen.getByText(/monthly video budget is spent/)).toBeTruthy()+ })++ it('trainings shows its own title and body', () => {+ render(<CreditsExhaustedModal />)+ act(() => signalCreditsExhausted('trainings'))+ expect(screen.getByText('Top up to keep training')).toBeTruthy()+ expect(screen.getByText(/included trainings refill/)).toBeTruthy()+ })++ it('a raw event with no detail (e.g. a plain Event) still falls back to credits', () => {+ render(<CreditsExhaustedModal />)+ act(() => { window.dispatchEvent(new Event(CREDITS_EXHAUSTED_EVENT)) })+ expect(screen.getByText("You're out of credits")).toBeTruthy()+ })++ it('NEGATIVE CONTROL: the video_budget and trainings titles are not the default title', () => {+ render(<CreditsExhaustedModal />)+ act(() => signalCreditsExhausted('video_budget'))+ expect(screen.queryByText("You're out of credits")).toBeNull()+ })+})diff --git a/src/hooks/useCloudCreate.ts b/src/hooks/useCloudCreate.tsindex 167d9bd8..e618cee8 100644--- a/src/hooks/useCloudCreate.ts+++ b/src/hooks/useCloudCreate.ts@@ -91,11 +91,17 @@ export function throttleMessage(err: CloudJobError): string {// R5-52: the buy dialog had exactly one caller and it sat in the chat// path, so a render that ran the wallet dry left the customer with a red// line and no way to pay.- signalCreditsExhausted()+ signalCreditsExhausted('credits')return "You're out of credits. Load up your credits or upgrade your plan."case 'video_budget_exhausted':+ // R5-51: this cap and 'trainings_exhausted' below used to only print a+ // line and never opened the dialog, so a Create render that hit either+ // one left the customer with prose and no way to act on it, same gap+ // R5-52 had already found and closed for 'credits_exhausted'.+ signalCreditsExhausted('video_budget')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."}const secs = err.retryAfterMs && err.retryAfterMs > 0 ? Math.ceil(err.retryAfterMs / 1000) : nulldiff --git a/src/lib/credits-exhausted.ts b/src/lib/credits-exhausted.tsindex 48a84401..0919d154 100644--- a/src/lib/credits-exhausted.ts+++ b/src/lib/credits-exhausted.ts@@ -9,6 +9,14 @@ import { CLOUD_BASE } from '../api/cloud/config'export const CREDITS_EXHAUSTED_EVENT = 'lu:credits-exhausted'+/** Which cap said no — drives the dialog title and copy. 'credits' = the+ * shared pool, 'video_budget' = the monthly video sub-budget (top-ups+ * bypass it), 'trainings' = no included run remains and the top-up wallet+ * cannot cover the selected training. Matches apps/web/lib/credits-+ * exhausted.ts, so the same server code reads the same on both apps+ * (R5-51). */+export type ExhaustedReason = 'credits' | 'video_budget' | 'trainings'+/*** Wohin der Knopf fuehrt: auf die Preisseite, nicht in einen Kauf.*@@ -24,9 +32,9 @@ export const CREDITS_EXHAUSTED_EVENT = 'lu:credits-exhausted'*/export const PRICING_URL = `${CLOUD_BASE}/pricing`-export function signalCreditsExhausted(): void {+export function signalCreditsExhausted(reason: ExhaustedReason = 'credits'): void {if (typeof window !== 'undefined') {- window.dispatchEvent(new Event(CREDITS_EXHAUSTED_EVENT))+ window.dispatchEvent(new CustomEvent(CREDITS_EXHAUSTED_EVENT, { detail: { reason } }))}}