Skip to content

armgit / fuobe

Public Imported from GitHub
0

The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.

Fixes 5: AI-Toolkit's "wants its auth token" says what Settings can do

Claude0cf1f1bd1452
diff --git a/src/server/training.ts b/src/server/training.ts
index df5b5967..542c554c 100644
--- a/src/server/training.ts
+++ b/src/server/training.ts
@@ -324,11 +324,22 @@ export async function testAiToolkit(opts?: { focus?: string }): Promise<{ ok: bo
const why = (e as Error).name === "TimeoutError" ? "no answer in 10 s" : (e as Error).message;
return { ok: false, detail: `Can't reach AI-Toolkit at ${base} (${why}). Is its UI running? (in ai-toolkit/ui: npm run build_and_start)` };
}
+ // Settings tests one field at a time: a new address is tested without a token, and a token with the saved address.
+ // So the way to a trainer that wants one is its address saved anyway, then the token tested under Auth token.
if (res.status === 401) {
if (aitkTokenWithheld() && getSetting("aiToolkitToken")) {
- return { ok: false, detail: `AI-Toolkit wants its auth token: type it with the new address (the saved one stays with ${savedSetting("aiToolkitUrl").replace(/\/+$/, "")})` };
+ return {
+ ok: false,
+ detail: `AI-Toolkit wants its auth token, and the saved one isn't sent to a new address (it stays with ${savedSetting("aiToolkitUrl").replace(/\/+$/, "")}): Save anyway, then test the token under Auth token (type this trainer's there if it differs)`,
+ };
}
- return { ok: false, detail: getSetting("aiToolkitToken") ? "AI-Toolkit rejected the auth token (401)" : "AI-Toolkit wants its auth token (AI_TOOLKIT_AUTH on the trainer): add it under Auth token" };
+ if (getSetting("aiToolkitToken")) return { ok: false, detail: "AI-Toolkit rejected the auth token (401)" };
+ return {
+ ok: false,
+ detail: isCandidate("aiToolkitUrl")
+ ? "AI-Toolkit wants its auth token (AI_TOOLKIT_AUTH on the trainer): Save anyway, then add the token under Auth token and test it there"
+ : "AI-Toolkit wants its auth token (AI_TOOLKIT_AUTH on the trainer): add it under Auth token",
+ };
}
if (!res.ok) return { ok: false, detail: `AI-Toolkit answered HTTP ${res.status}` };
const jobs = ((await res.json().catch(() => null)) as { jobs?: unknown } | null)?.jobs;
diff --git a/tests/connections.test.ts b/tests/connections.test.ts
index cd60e12b..4aa2efb6 100644
--- a/tests/connections.test.ts
+++ b/tests/connections.test.ts
@@ -258,7 +258,8 @@ describe("POST /api/providers/test with unsaved values", () => {
expect(all.result.body).toEqual({ ok: true, detail: "AI-Toolkit · 1 training running" });
// AI_TOOLKIT_AUTH set on the trainer: it wants the token.
const locked = await withFetch({ "http://10.0.0.7:8675/api/jobs": [401, { error: "Unauthorized" }] }, () => post({ provider: "ai-toolkit", value: "http://10.0.0.7:8675" }));
- expect(locked.result.body).toEqual({ ok: false, detail: "AI-Toolkit wants its auth token (AI_TOOLKIT_AUTH on the trainer): add it under Auth token" });
+ // Settings tests one field at a time, so the way there is the address saved anyway, then the token tested on it.
+ expect(locked.result.body).toEqual({ ok: false, detail: "AI-Toolkit wants its auth token (AI_TOOLKIT_AUTH on the trainer): Save anyway, then add the token under Auth token and test it there" });
const typed = await withFetch({ "http://10.0.0.7:8675/api/jobs": [401, { error: "Unauthorized" }] }, () =>
post({ provider: "ai-toolkit", values: { aiToolkitUrl: "http://10.0.0.7:8675", aiToolkitToken: "wrong" } }),
);
@@ -282,7 +283,17 @@ describe("POST /api/providers/test with unsaved values", () => {
// A new address gets no token unless one is typed with it, and says so when the trainer wants one.
const other = await withFetch(answers, () => post({ provider: "ai-toolkit", value: "http://10.0.0.9:8675" }));
expect(other.seen.map((r) => r.auth)).toEqual([undefined]);
- expect(other.result.body.detail).toBe("AI-Toolkit wants its auth token: type it with the new address (the saved one stays with http://10.0.0.7:8675)");
+ // Settings can't send a token with a new address (each field tests on its own): saved anyway, the token is tested there.
+ expect(other.result.body.detail).toBe(
+ "AI-Toolkit wants its auth token, and the saved one isn't sent to a new address (it stays with http://10.0.0.7:8675): Save anyway, then test the token under Auth token (type this trainer's there if it differs)",
+ );
+ setSetting("aiToolkitUrl", "http://10.0.0.9:8675");
+ const after = await withFetch({ "http://10.0.0.9:8675/api/jobs": [200, { jobs: [] }] }, () => post({ provider: "ai-toolkit", field: "aiToolkitToken" }));
+ expect(after.result.body).toEqual({ ok: true, detail: "AI-Toolkit · ready, no training running" });
+ expect(after.seen.map((r) => r.auth)).toEqual(["Bearer saved-aitk-token"]);
+ const retyped = await withFetch({ "http://10.0.0.9:8675/api/jobs": [200, { jobs: [] }] }, () => post({ provider: "ai-toolkit", values: { aiToolkitToken: "new-token" }, field: "aiToolkitToken" }));
+ expect(retyped.seen.map((r) => r.auth)).toEqual(["Bearer new-token"]);
+ setSetting("aiToolkitUrl", "http://10.0.0.7:8675");
const same = await withFetch(answers, () => post({ provider: "ai-toolkit", value: "http://10.0.0.7:8675/" }));
expect(same.seen.map((r) => r.auth)).toEqual(["Bearer saved-aitk-token"]);
setSetting("aiToolkitUrl", "");