fix: add model to provider

This commit is contained in:
2026-07-27 22:46:46 +07:00
parent fbbc435bfd
commit e8aa0fafc0
@@ -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)}
/>