From e8aa0fafc03a2e1b3dae6cc2770fcd49ac4a3304 Mon Sep 17 00:00:00 2001 From: Loi Phan Date: Mon, 27 Jul 2026 22:46:46 +0700 Subject: [PATCH] fix: add model to provider --- .../dashboard/providers/[id]/page.js | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/app/(dashboard)/dashboard/providers/[id]/page.js b/src/app/(dashboard)/dashboard/providers/[id]/page.js index e03e7619..d22a4117 100644 --- a/src/app/(dashboard)/dashboard/providers/[id]/page.js +++ b/src/app/(dashboard)/dashboard/providers/[id]/page.js @@ -11,6 +11,7 @@ import { getModelsByProviderId, getModelKind } from "@/shared/constants/models"; import { getThinkingLevels } from "open-sse/providers/thinkingLevels.js"; import { useCopyToClipboard } from "@/shared/hooks/useCopyToClipboard"; import { useModelCaps } from "@/shared/hooks/useModelCaps"; +import { useNotificationStore } from "@/store/notificationStore"; import { translate } from "@/i18n/runtime"; import { fetchSuggestedModels } from "@/shared/utils/providerModelsFetcher"; import { getProviderCustomModelRows } from "@/shared/utils/providerCustomModels"; @@ -80,6 +81,7 @@ export default function ProviderDetailPage() { const stopOneByOneRef = useRef(false); const [importingQoderModels, setImportingQoderModels] = useState(false); const { copied, copy } = useCopyToClipboard(); + const notify = useNotificationStore(); const AG_RISK_STORAGE_KEY = "ag_risk_confirmed"; @@ -504,22 +506,35 @@ export default function ProviderDetailPage() { }; const handleAddCustomModel = async (modelId, type = "llm", providerAliasOverride = providerStorageAlias) => { + const fullModel = `${providerAliasOverride}/${modelId}`; try { const res = await fetch("/api/models/custom", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ providerAlias: providerAliasOverride, id: modelId, type }), }); + const data = await res.json().catch(() => ({})); if (res.ok) { - await fetchCustomModels(); + // A built-in model that was permanently deleted is hidden by its + // tombstone. Refresh both sources so restoring it is visible at once. + await Promise.all([fetchCustomModels(), fetchDeletedModels()]); if (typeof window !== "undefined") window.dispatchEvent(new CustomEvent("customModelChanged")); + if (data.restored) { + notify.success(`${fullModel} has been restored.`); + } else if (data.added) { + notify.success(`${fullModel} has been added.`); + } else { + notify.info(`${fullModel} is already available.`); + } + return data; } else { - const data = await res.json(); - alert(data.error || "Failed to add custom model"); + notify.error(data.error || `Failed to add ${fullModel}.`); } } catch (error) { console.log("Error adding custom model:", error); + notify.error(`Failed to add ${fullModel}. Check the connection and try again.`); } + return null; }; const handleDeleteCustomModel = async (modelId, type = "llm", providerAliasOverride = providerStorageAlias) => { @@ -1706,8 +1721,9 @@ export default function ProviderDetailPage() { providerAlias={providerStorageAlias} providerDisplayAlias={providerDisplayAlias} onSave={async (modelId) => { - await handleAddCustomModel(modelId, "llm", providerStorageAlias); - setShowAddCustomModel(false); + const result = await handleAddCustomModel(modelId, "llm", providerStorageAlias); + if (result) setShowAddCustomModel(false); + return result; }} onClose={() => setShowAddCustomModel(false)} />