Fix ModelSelectModal

This commit is contained in:
decolua 2026-04-05 21:25:00 +07:00
parent 67e0db77da
commit 57cfaccceb
4 changed files with 13 additions and 12 deletions

View file

@ -4,11 +4,12 @@ import { useState, useMemo, useEffect } from "react";
import PropTypes from "prop-types";
import Modal from "./Modal";
import { getModelsByProviderId, PROVIDER_ID_TO_ALIAS } from "@/shared/constants/models";
import { OAUTH_PROVIDERS, APIKEY_PROVIDERS, isOpenAICompatibleProvider, isAnthropicCompatibleProvider } from "@/shared/constants/providers";
import { OAUTH_PROVIDERS, APIKEY_PROVIDERS, FREE_TIER_PROVIDERS, isOpenAICompatibleProvider, isAnthropicCompatibleProvider } from "@/shared/constants/providers";
// Provider order: OAuth first, then API Key (matches dashboard/providers)
// Provider order: OAuth first, then Free Tier, then API Key (matches dashboard/providers)
const PROVIDER_ORDER = [
...Object.keys(OAUTH_PROVIDERS),
...Object.keys(FREE_TIER_PROVIDERS),
...Object.keys(APIKEY_PROVIDERS),
];
@ -57,7 +58,7 @@ export default function ModelSelectModal({
if (isOpen) fetchProviderNodes();
}, [isOpen]);
const allProviders = useMemo(() => ({ ...OAUTH_PROVIDERS, ...APIKEY_PROVIDERS }), []);
const allProviders = useMemo(() => ({ ...OAUTH_PROVIDERS, ...FREE_TIER_PROVIDERS, ...APIKEY_PROVIDERS }), []);
// Group models by provider with priority order
const groupedModels = useMemo(() => {
@ -142,16 +143,18 @@ export default function ModelSelectModal({
const hardcodedModels = getModelsByProviderId(providerId);
const hardcodedIds = new Set(hardcodedModels.map((m) => m.id));
// Custom models user added via "Add Model" button (alias === modelId pattern)
// Custom models: if no hardcoded models (e.g. openrouter), show all aliases for this provider
// Otherwise only show aliases where aliasName === modelId ("Add Model" button pattern)
const hasHardcoded = hardcodedModels.length > 0;
const customModels = Object.entries(modelAliases)
.filter(([aliasName, fullModel]) =>
fullModel.startsWith(`${alias}/`) &&
aliasName === fullModel.replace(`${alias}/`, "") &&
(hasHardcoded ? aliasName === fullModel.replace(`${alias}/`, "") : true) &&
!hardcodedIds.has(fullModel.replace(`${alias}/`, ""))
)
.map(([, fullModel]) => {
.map(([aliasName, fullModel]) => {
const modelId = fullModel.replace(`${alias}/`, "");
return { id: modelId, name: modelId, value: fullModel, isCustom: true };
return { id: modelId, name: aliasName, value: fullModel, isCustom: true };
});
const allModels = [