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
feat(cloud): 'Load up your credits' dialog on credits_exhausted (2.5.10)
purplec8fe1f55d17e
diff --git a/src/api/providers/openai-provider.ts b/src/api/providers/openai-provider.tsindex ee519066..ceda7a28 100644--- a/src/api/providers/openai-provider.ts+++ b/src/api/providers/openai-provider.ts@@ -16,6 +16,7 @@ import type {import { ProviderError } from './types'import { parseSSEStream } from '../sse'import { repairJson } from '../../lib/tool-call-repair'+import { signalCreditsExhausted } from '../../lib/credits-exhausted'import { localFetch, localFetchStream, isPrivateOrLanHost, hostnameOf, ensureProxyAllowsHost } from '../backend'// Local/LAN vs cloud routing now lives in the `useLocalProxy` getter (below)@@ -730,6 +731,13 @@ export class OpenAIProvider implements ProviderClient {// honest, user-facing `error` line (already captured as `message`).if (serverCode === 'model_no_tools') code = 'tools_unsupported'else if (serverCode === 'model_no_vision') code = 'vision_unsupported'+ else if (serverCode === 'credits_exhausted') {+ // Out of credits, top-up wallet empty (HTTP 429). Raise the global+ // signal so the "Load up your credits" dialog opens on top of the+ // honest error line already carried in `message`.+ code = 'credits_exhausted'+ signalCreditsExhausted()+ }// LM Studio: model load fails when there's no inference runtime for the// model's format installed. The raw API error reads "No LM Runtime founddiff --git a/src/components/layout/AppShell.tsx b/src/components/layout/AppShell.tsxindex 7b9f5557..3203d5d6 100644--- a/src/components/layout/AppShell.tsx+++ b/src/components/layout/AppShell.tsx@@ -32,6 +32,7 @@ import { CloudGateModal } from '../cloud/CloudGateModal'import { CloudTeaserModal } from '../cloud/CloudTeaserModal'import { CloudExampleModal } from '../cloud/CloudExampleModal'import { ShortcutsModal } from './ShortcutsModal'+import { CreditsExhaustedModal } from './CreditsExhaustedModal'import { Titlebar } from './Titlebar'// The backup triad must never write %APPDATA%/store_backup.json before the@@ -818,6 +819,9 @@ export function AppShell() {surfaces only) before the gate. */}<CloudExampleModal /><ShortcutsModal />+ {/* Out-of-credits purchase prompt: opens when LU Cloud answers+ code:'credits_exhausted' (monthly budget + top-up wallet empty). */}+ <CreditsExhaustedModal /></div>)}diff --git a/src/components/layout/CreditsExhaustedModal.tsx b/src/components/layout/CreditsExhaustedModal.tsxnew file mode 100644index 00000000..7b6b9471--- /dev/null+++ b/src/components/layout/CreditsExhaustedModal.tsx@@ -0,0 +1,53 @@+import { useEffect, useState } from 'react'+import { Zap } from 'lucide-react'+import { Modal } from '../ui/Modal'+import { CREDITS_EXHAUSTED_EVENT, TOPUP_URL } from '../../lib/credits-exhausted'+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'`+ * (lib/credits-exhausted.ts); this turns it into a purchase prompt with a+ * button to the website's top-up store instead of a dead-end error line.+ */+export function CreditsExhaustedModal() {+ const [open, setOpen] = useState(false)++ useEffect(() => {+ const show = () => setOpen(true)+ window.addEventListener(CREDITS_EXHAUSTED_EVENT, show)+ return () => window.removeEventListener(CREDITS_EXHAUSTED_EVENT, show)+ }, [])++ return (+ <Modal open={open} onClose={() => setOpen(false)} title="You're out of credits">+ <div className="space-y-4">+ <p className="text-sm text-gray-600 dark:text-gray-300">+ Your plan credits for this month are used up. Top-up credits are+ one-time, never expire, and are only used after your monthly plan+ credits.+ </p>+ <div className="flex flex-col gap-2">+ <button+ type="button"+ onClick={() => {+ void openExternal(TOPUP_URL)+ setOpen(false)+ }}+ className="inline-flex items-center justify-center gap-2 rounded-xl bg-purple-600 hover:bg-purple-500 text-white font-semibold px-4 py-2.5 transition-colors"+ >+ <Zap size={16} />+ Load up your credits+ </button>+ <button+ type="button"+ onClick={() => setOpen(false)}+ className="rounded-xl px-4 py-2 text-sm text-gray-500 hover:text-gray-900 dark:text-gray-400 dark:hover:text-white transition-colors"+ >+ Not now+ </button>+ </div>+ </div>+ </Modal>+ )+}diff --git a/src/lib/credits-exhausted.ts b/src/lib/credits-exhausted.tsnew file mode 100644index 00000000..0cd9c4f2--- /dev/null+++ b/src/lib/credits-exhausted.ts@@ -0,0 +1,17 @@+// Client-side signal for LU Cloud's `code: 'credits_exhausted'` (out of+// credits, top-up wallet empty). Any request layer that spots the code fires+// ONE window event; the globally mounted CreditsExhaustedModal turns it into+// the "Load up your credits" dialog instead of a dead-end chat error. An+// event (not a store) so the non-React provider layer can raise it without+// new dependencies.++export const CREDITS_EXHAUSTED_EVENT = 'lu:credits-exhausted'++/** Where the dialog's button leads. Purchases happen on the website. */+export const TOPUP_URL = 'https://lu-labs.ai/credits'++export function signalCreditsExhausted(): void {+ if (typeof window !== 'undefined') {+ window.dispatchEvent(new Event(CREDITS_EXHAUSTED_EVENT))+ }+}