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(chat): workflow errors reach the model in words; CivitAI without a key says so (C60-S5)
purpleb825964a8fbb
diff --git a/src/api/__tests__/workflow-find.test.ts b/src/api/__tests__/workflow-find.test.tsindex fe2ef62d..e7ac03fe 100644--- a/src/api/__tests__/workflow-find.test.ts+++ b/src/api/__tests__/workflow-find.test.ts@@ -79,6 +79,16 @@ describe('loading a candidate', () => {expect(h.backendCall).toHaveBeenCalledWith('workflow_fetch', { url: 'https://example.org/wf.json', userLink: true, authToken: null })})+ it('CivitAI without a key: the hit says so, and a 401 becomes a sentence', async () => {+ h.backendCall.mockResolvedValueOnce([...new TextEncoder().encode(JSON.stringify({+ items: [{ id: 7, name: 'Simple SD 1.5', modelVersions: [{ files: [{ name: 'wf.zip', sizeKB: 2, downloadUrl: 'https://civitai.com/api/download/models/9' }] }] }],+ }))])+ const [hit] = await searchCivitai('sd')+ expect(hit.needsKey).toBe(true)+ h.backendCall.mockRejectedValueOnce('HTTP 401: https://civitai.com/api/download/models/9')+ await expect(loadCandidate(hit)).rejects.toThrow(/only hands out workflow files with an API key/)+ })+it('a page that is not a workflow says what to do', async () => {h.backendCall.mockResolvedValue([...new TextEncoder().encode('<html>OpenArt</html>')])const { userLinkCandidate } = await import('../workflow-find')diff --git a/src/api/mcp/__tests__/workflow-tools.test.ts b/src/api/mcp/__tests__/workflow-tools.test.tsindex d69ce2ad..6313330e 100644--- a/src/api/mcp/__tests__/workflow-tools.test.ts+++ b/src/api/mcp/__tests__/workflow-tools.test.ts@@ -326,3 +326,10 @@ describe('the shared policy (C60-S3)', () => {await pending})})++describe('errors in words', () => {+ it('a Tauri rejection is a string and still reaches the model', async () => {+ h.check.mockRejectedValue('HTTP 401: https://civitai.com/api/download/models/1')+ expect(await executeWorkflowInspect({ id: candidateId() })).toMatch(/Could not read workflow url\d+: HTTP 401/)+ })+})diff --git a/src/api/mcp/workflow-tools.ts b/src/api/mcp/workflow-tools.tsindex dd5cea23..6b9b525d 100644--- a/src/api/mcp/workflow-tools.ts+++ b/src/api/mcp/workflow-tools.ts@@ -71,6 +71,12 @@ const STRONG_INSTALL = /\b(install|installier|einbau|einbauen|bau(?:e|t)?\b[^.?!const installNames = (text: string, strict: boolean) => (strict ? STRONG_INSTALL.test(text) : userAskedToInstall(text))const assignNames = (text: string, strict: boolean) => (strict ? STRONG_INSTALL.test(text) || /\b(assign|zuweis|zuweisen)/i.test(text) : userAskedToAssign(text))+/** A failure in words. A Tauri command rejects with a plain string, not an Error. */+function errText(e: unknown, max: number): string {+ const t = e instanceof Error ? e.message : typeof e === 'string' ? e : ''+ return (t || 'unknown error').replace(/\s+/g, ' ').slice(0, max)+}+const NOT_HERE = 'Error: workflows can only be installed in a chat where the user sees the confirmation card. Nothing changed.'// ── workflow_find ───────────────────────────────────────────────────────────@@ -79,6 +85,7 @@ function hitLine(c: Candidate): string {const bits: string[] = [c.source]if (c.author) bits.push(`by ${c.author}`)if (c.baseModel) bits.push(cleanName(c.baseModel, 30))+ if (c.needsKey) bits.push('download needs a CivitAI key')if (c.downloads !== undefined) bits.push(`${c.downloads} downloads`)if (c.date) bits.push(c.date)if (c.sizeKB !== undefined) bits.push(`${c.sizeKB} KB`)@@ -107,12 +114,15 @@ export async function executeWorkflowFind(args: ToolArgs, run?: AgentRunContext)const hits = await f()if (hits.length) lines.push(`${name}:`, ...hits.map(hitLine))} catch (e) {- errors.push(`${name}: ${e instanceof Error ? e.message.slice(0, 160) : 'not reachable'}`)+ errors.push(`${name}: ${errText(e, 160)}`)}}if (source === 'all' || source === 'local') await take('Local (LU and ComfyUI)', () => searchLocal(query))- if (source === 'all' || source === 'civitai') await take('CivitAI', () => searchCivitai(query))- if (source === 'all' || source === 'github') await take('GitHub (Comfy Registry)', () => searchGithub(query))+ // Without a CivitAI key its files cannot be fetched, so GitHub comes first.+ const civitaiFirst = !!useWorkflowStore.getState().civitaiApiKey+ const civitai = () => (source === 'all' || source === 'civitai') && take('CivitAI', () => searchCivitai(query))+ const github = () => (source === 'all' || source === 'github') && take('GitHub (Comfy Registry)', () => searchGithub(query))+ if (civitaiFirst) { await civitai(); await github() } else { await github(); await civitai() }if (!lines.length) {return `No workflow found for "${cleanName(query, 80)}".${errors.length ? ` Not reached: ${errors.join('; ')}.` : ''} `@@ -138,7 +148,7 @@ export async function executeWorkflowInspect(args: ToolArgs): Promise<string> {const others = checked.loaded.others ? `\nThe file holds ${checked.loaded.others + 1} workflows; the first one was checked.` : ''return reportForAgent(checked.report, c.id, c.title) + others} catch (e) {- return `Could not read workflow ${c.id}: ${e instanceof Error ? e.message.slice(0, 240) : 'unknown error'}`+ return `Could not read workflow ${c.id}: ${errText(e, 240)}`}}@@ -205,7 +215,7 @@ export async function executeWorkflowInstall(args: ToolArgs, run?: AgentRunContetry {checked = await checkCandidate(c)} catch (e) {- return `Could not read workflow ${c.id}: ${e instanceof Error ? e.message.slice(0, 240) : 'unknown error'}. Nothing changed.`+ return `Could not read workflow ${c.id}: ${errText(e, 240)}. Nothing changed.`}const r = checked.reportif (r.light === 'red') {@@ -255,7 +265,7 @@ export async function applyInstall(checked: Checked, model: string | undefined):if (res && typeof res === 'object' && res.status === 'error') throw new Error(res.error ?? 'failed')done.push(`Installed node pack ${p.name}${p.commit ? ` at ${p.commit.slice(0, 8)}` : ''}.`)} catch (e) {- return `${done.join(' ')} Installing ${p.name} failed: ${e instanceof Error ? e.message.slice(0, 200) : 'unknown'}. The workflow was not installed.`+ return `${done.join(' ')} Installing ${p.name} failed: ${errText(e, 200)}. The workflow was not installed.`}}try {@@ -263,7 +273,7 @@ export async function applyInstall(checked: Checked, model: string | undefined):clearNodeCache()done.push('ComfyUI restarted.')} catch (e) {- notes.push(`ComfyUI did not restart by itself (${e instanceof Error ? e.message.slice(0, 120) : 'unknown'}); restart it before generating.`)+ notes.push(`ComfyUI did not restart by itself (${errText(e, 120)}); restart it before generating.`)}}@@ -277,7 +287,7 @@ export async function applyInstall(checked: Checked, model: string | undefined):if (res?.status === 'error') throw new Error(res.error ?? 'failed')done.push(`Download started: ${file}${m.sizeGB ? ` (${m.sizeGB} GB)` : ''} to ${m.folder}.`)} catch (e) {- notes.push(`Download of ${file} did not start: ${e instanceof Error ? e.message.slice(0, 160) : 'unknown'}.`)+ notes.push(`Download of ${file} did not start: ${errText(e, 160)}.`)}}for (const m of r.models.filter((x) => x.state === 'missing')) notes.push(`${m.name} is missing; the user gets it.`)diff --git a/src/api/workflow-find.ts b/src/api/workflow-find.tsindex 07c3ff94..d7b1b40e 100644--- a/src/api/workflow-find.ts+++ b/src/api/workflow-find.ts@@ -66,6 +66,8 @@ export interface Candidate {page?: string/** A link the user sent, fetched with `userLink`. */userLink?: boolean+ /** CivitAI hands out files only with an API key; none is set. */+ needsKey?: boolean}const candidates = new Map<string, Candidate>()@@ -200,6 +202,7 @@ export async function searchCivitai(query: string): Promise<Candidate[]> {license: civitaiLicense(item),host,page: typeof item.id === 'number' ? `https://${host}/models/${item.id}` : undefined,+ ...(civitaiApiKey ? {} : { needsKey: true }),}, 'civ'))}return out@@ -375,7 +378,17 @@ export async function loadCandidate(c: Candidate): Promise<LoadedWorkflow> {} else {if (!c.fileUrl) throw new Error('This hit has no file to read.')const auth = c.source === 'civitai' ? useWorkflowStore.getState().civitaiApiKey || null : null- raw = await invokeFetch(c.fileUrl, { userLink: c.userLink, auth })+ try {+ raw = await invokeFetch(c.fileUrl, { userLink: c.userLink, auth })+ } catch (e) {+ const t = e instanceof Error ? e.message : String(e)+ if (c.source === 'civitai' && /HTTP 40[13]/.test(t)) {+ throw new Error(auth+ ? 'CivitAI refused the download with the saved API key (it may be expired). Pick a hit from another source.'+ : 'CivitAI only hands out workflow files with an API key, and none is set. The user can add one in Settings (CivitAI key); until then pick a hit from another source.')+ }+ throw e instanceof Error ? e : new Error(t)+ }if (c.sha256) publishedShaOk = (await sha256Hex(raw)) === c.sha256}if (raw.length > 4 * 1024 * 1024) throw new Error('The file is larger than 4 MB.')