Merge pull request #196 from NgoQuocViet2001/ai/wan2gp-endpoint-fallback

fix(wan2gp): keep default endpoints available without metadata
This commit is contained in:
Anil Chandra Naidu Matcha
2026-05-22 23:15:22 +05:30
committed by GitHub
4 changed files with 97 additions and 14 deletions
+33
View File
@@ -0,0 +1,33 @@
function withWan2gpAvailability(model, probeResult, cachedResolution) {
if (!probeResult?.ok) {
return {
...model,
ready: false,
unavailableReason: probeResult?.error || 'Wan2GP probe failed',
};
}
const apiNames = Array.isArray(cachedResolution?.apiNames) ? cachedResolution.apiNames : [];
const realFn = cachedResolution?.resolved?.get?.(model.id) || null;
if (realFn) {
return { ...model, ready: true, fn: realFn };
}
if (apiNames.length === 0) {
return {
...model,
ready: true,
fn: model.fn,
availabilityNote: 'Wan2GP did not expose endpoint metadata; using the default api_name.',
};
}
return {
...model,
ready: false,
unavailableReason: `Wan2GP server has no api_name matching "${model.fn}". Check Wan2GP version or load this model in its UI.`,
};
}
module.exports = { withWan2gpAvailability };
+2 -12
View File
@@ -9,6 +9,7 @@ const path = require('path');
const fs = require('fs');
const http = require('http');
const https = require('https');
const { withWan2gpAvailability } = require('./wan2gpModelAvailability');
const DATA_DIR = path.join(app.getPath('userData'), 'local-ai');
const CONFIG_FILE = path.join(DATA_DIR, 'wan2gp.json');
@@ -274,18 +275,7 @@ async function listModels() {
const base = normalizeUrl(url);
const probeRes = await probe(url); // populates fnResolutionCache
const cached = fnResolutionCache.get(base);
return WAN2GP_CATALOG.map(m => {
if (!probeRes.ok) return { ...m, ready: false, unavailableReason: probeRes.error };
const realFn = cached?.resolved.get(m.id) || null;
if (!realFn) {
return {
...m,
ready: false,
unavailableReason: `Wan2GP server has no api_name matching "${m.fn}". Check Wan2GP version or load this model in its UI.`,
};
}
return { ...m, ready: true, fn: realFn };
});
return WAN2GP_CATALOG.map(m => withWan2gpAvailability(m, probeRes, cached));
}
// ─── Generate ─────────────────────────────────────────────────────────────────
+2 -2
View File
@@ -189,7 +189,7 @@ const translations = {
'localModels.requiredComponents': 'Required components',
'localModels.ready': 'Ready',
'localModels.available': 'Available',
'localModels.offline': 'Server offline',
'localModels.offline': 'Unavailable',
'localModels.starting': 'Starting...',
'localModels.complete': 'Complete!',
'localModels.preparing': 'Preparing...',
@@ -379,7 +379,7 @@ const translations = {
'localModels.requiredComponents': '所需组件',
'localModels.ready': '已就绪',
'localModels.available': '可用',
'localModels.offline': '服务器离线',
'localModels.offline': '不可用',
'localModels.starting': '启动中...',
'localModels.complete': '完成!',
'localModels.preparing': '准备中...',
+60
View File
@@ -0,0 +1,60 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const { withWan2gpAvailability } = require('../electron/lib/wan2gpModelAvailability');
const fluxModel = {
id: 'wan2gp:flux-dev',
name: 'Flux.1 Dev (Wan2GP)',
fn: 'flux',
};
test('withWan2gpAvailability marks models unavailable when the server probe fails', () => {
const model = withWan2gpAvailability(fluxModel, { ok: false, error: 'Request timed out' });
assert.equal(model.ready, false);
assert.equal(model.unavailableReason, 'Request timed out');
});
test('withWan2gpAvailability uses resolved api_name when endpoint metadata matches', () => {
const model = withWan2gpAvailability(
fluxModel,
{ ok: true },
{
apiNames: ['flux_image'],
resolved: new Map([['wan2gp:flux-dev', 'flux_image']]),
}
);
assert.equal(model.ready, true);
assert.equal(model.fn, 'flux_image');
});
test('withWan2gpAvailability keeps default api_name available when Gradio omits endpoint metadata', () => {
const model = withWan2gpAvailability(
fluxModel,
{ ok: true },
{
apiNames: [],
resolved: new Map([['wan2gp:flux-dev', null]]),
}
);
assert.equal(model.ready, true);
assert.equal(model.fn, 'flux');
assert.match(model.availabilityNote, /default api_name/);
});
test('withWan2gpAvailability rejects unmatched models when endpoint metadata is present', () => {
const model = withWan2gpAvailability(
fluxModel,
{ ok: true },
{
apiNames: ['qwen_image'],
resolved: new Map([['wan2gp:flux-dev', null]]),
}
);
assert.equal(model.ready, false);
assert.match(model.unavailableReason, /no api_name matching "flux"/);
});