fix(cli-tools): enable Apply button for dynamic OpenAI/Anthropic-compatible providers

getAllAvailableModels() only consulted the static PROVIDER_MODELS catalog,
which has no entry for dynamically-registered compatible providers
(id like openai-compatible-chat-uuid). Fall back to the connection's
own defaultModel/customModels/placeholder, mirroring ModelSelectModal.js.
This commit is contained in:
lazysaltyfish
2026-08-05 10:23:39 +07:00
committed by decolua
parent 0e5da70cb1
commit 918b3c87a1

View File

@@ -81,6 +81,33 @@ export default function ToolDetailClient({ toolId, machineId }) {
models.push({ value: modelValue, label: `${alias}/${m.id}`, provider: conn.provider, alias, connectionName: conn.name, modelId: m.id });
}
});
// openai/anthropic-compatible providers are registered with a random UUID (e.g.
// "openai-compatible-chat-<uuid>") that has no entry in the static PROVIDER_MODELS
// catalog, so `getModelsByProviderId` returns []. Routing still works because the
// request path uses the connection's own model config, but `hasActiveProviders`
// below would flip to false and disable the Apply button. Fall back to the
// connection's own models so these providers are usable from CLI tool pages.
if (providerModels.length === 0) {
const prefix = conn.providerSpecificData?.prefix || alias;
const fallbackModels = [];
if (conn.defaultModel) fallbackModels.push({ id: conn.defaultModel, name: conn.defaultModel });
(conn.providerSpecificData?.customModels || []).forEach(m => {
if (m?.id && !fallbackModels.some(f => f.id === m.id)) fallbackModels.push({ id: m.id, name: m.name || m.id });
});
if (fallbackModels.length === 0 && conn.testStatus === "active") {
// Provider is confirmed reachable but exposes no model info anywhere;
// still let the user apply so they aren't stuck on a permanently disabled button.
fallbackModels.push({ id: "model-id", name: `${prefix}/model-id` });
}
fallbackModels.forEach(m => {
const modelValue = `${prefix}/${m.id}`;
if (!seenModels.has(modelValue)) {
seenModels.add(modelValue);
models.push({ value: modelValue, label: `${prefix}/${m.id}`, provider: conn.provider, alias: prefix, connectionName: conn.name, modelId: m.id });
}
});
}
});
return models;
};