Open source CapCut alternative.
TypeScript
feat(site): empty-credits inference errors read 'No credits left, reload here'
David Le38970fceb35b
diff --git a/site/src/cut/components/AiPanel.tsx b/site/src/cut/components/AiPanel.tsxindex b289c07e..c0733a83 100644--- a/site/src/cut/components/AiPanel.tsx+++ b/site/src/cut/components/AiPanel.tsx@@ -63,6 +63,7 @@ import { cn } from "@/lib/utils";import { cardIconButton } from "@/cut/components/iconButton";import { MentionTextarea, RefChips, RefThumb, RefTokenChip } from "./AssetRefs";import { ToolOutputAssets } from "./ChatAssets";+import { HostedErrorText } from "./hostedError";// Chat attachments are asset refs — anything in the project, the library, or// the stock catalog. They arrive by drag (media cards, library clips, stock@@ -552,7 +553,9 @@ function ChatSession({{error && (<div className="ai-error mt-2 flex items-start gap-2 rounded-lg bg-red-50 px-2.5 py-2 text-[11.5px] leading-relaxed text-red-700"><TriangleAlert className="mt-0.5 size-3.5 shrink-0" />- {error.message}+ <span>+ <HostedErrorText error={error.message} />+ </span></div>)}</div>diff --git a/site/src/cut/components/ChatAssets.tsx b/site/src/cut/components/ChatAssets.tsxindex b17c904d..7e0f2813 100644--- a/site/src/cut/components/ChatAssets.tsx+++ b/site/src/cut/components/ChatAssets.tsx@@ -24,6 +24,7 @@ import { AudioRow } from "./AudioPanel";import { DocText, useDocText } from "./DocText";import { GeneratedAssetMenu } from "./GeneratedAssetMenu";import { scrimIconButton } from "./iconButton";+import { HostedErrorText } from "./hostedError";// Assets rendered inside chat messages. Anything the assistant makes previews// here as a media-first card and stays in the chat until the user moves it:@@ -99,7 +100,7 @@ export function ChatVideoJobCard({ jobId }: { jobId: string }) {job.status === "error" ? "text-red-600" : "text-muted-foreground")}>- {job.status === "running" ? "Rendering…" : (job.error ?? "Failed.")}+ {job.status === "running" ? "Rendering…" : <HostedErrorText error={job.error} />}</div></div></div>diff --git a/site/src/cut/components/GeneratePanel.tsx b/site/src/cut/components/GeneratePanel.tsxindex 4abc8fb5..23339238 100644--- a/site/src/cut/components/GeneratePanel.tsx+++ b/site/src/cut/components/GeneratePanel.tsx@@ -28,6 +28,7 @@ import {import { cn } from "@/lib/utils";import { MentionTextarea, RefChips, RefHandlePill } from "./AssetRefs";import { GeneratedAssetMenu } from "./GeneratedAssetMenu";+import { HostedErrorText } from "./hostedError";import { cardIconButton } from "./iconButton";import { PillSelect } from "./PillSelect";@@ -297,7 +298,7 @@ function JobRow({ job, handle }: { job: GenerateJob; handle?: string }) {job.status === "error" ? "text-red-600" : "text-muted-foreground")}>- {job.status === "running" ? "Rendering…" : (job.error ?? "Failed.")}+ {job.status === "running" ? "Rendering…" : <HostedErrorText error={job.error} />}</div></div>{job.status !== "running" && (diff --git a/site/src/cut/components/hostedError.tsx b/site/src/cut/components/hostedError.tsxnew file mode 100644index 00000000..917267e3--- /dev/null+++ b/site/src/cut/components/hostedError.tsx@@ -0,0 +1,23 @@+import { creditsUrl, NO_CREDITS_MESSAGE } from "@/cut/lib/generate";++/** A hosted-inference error message (chat reply or generation tile). An+ * empty-balance failure reads "No credits left, reload here" with the credits+ * link inline; any other error (or a missing message) renders as plain text. */+export function HostedErrorText({ error }: { error?: string }) {+ if (error === NO_CREDITS_MESSAGE) {+ return (+ <>+ No credits left,{" "}+ <a+ className="font-medium underline hover:no-underline"+ href={creditsUrl()}+ target="_blank"+ rel="noreferrer"+ >+ reload here+ </a>+ </>+ );+ }+ return <>{error ?? "Failed."}</>;+}diff --git a/site/src/cut/lib/generate.ts b/site/src/cut/lib/generate.tsindex 2c58213f..00a3bd98 100644--- a/site/src/cut/lib/generate.ts+++ b/site/src/cut/lib/generate.ts@@ -121,6 +121,11 @@ export function signInUrl(): string {return `${apex}/sign-in?callbackURL=${encodeURIComponent(href)}`;}+/** Shown for any 402 (empty balance) across chat and generation tiles. The+ * chat error box and the job tiles match this text to swap in a "reload here"+ * credits link, so keep it and those call sites in sync. */+export const NO_CREDITS_MESSAGE = "No credits left";+/** The Donkey settings page where credits are bought (cut.* → apex). Linked* from any generation error caused by an empty balance. */export function creditsUrl(): string {@@ -160,7 +165,7 @@ async function readError(res: Response, fallback: string): Promise<string> {const message = [body?.message, body?.error].find((v): v is string => typeof v === "string" && v.length > 0);- if (res.status === 402) return message ?? "Not enough Donkey credits — top up to generate.";+ if (res.status === 402) return NO_CREDITS_MESSAGE;// The provider tucks the real reason (a safety block, a rejected prompt) under// details.message; the top-level message is only a generic headline. Append it so a// failure explains itself instead of stopping at "…generation failed."