fix(opencode): fix add/remove provider flow and toast messages

- Create separate removeFromLiveConfig API for additive mode apps
  (remove only removes from live config, not database)
- Fix useSwitchProviderMutation to invalidate opencodeLiveProviderIds
  cache so button state updates correctly after add operation
- Show appropriate toast messages:
  - Add: "已添加到配置" / "Added to config"
  - Remove: "已从配置移除" / "Removed from config"
- Add i18n texts for addToConfigSuccess and removeFromConfigSuccess
This commit is contained in:
Jason
2026-01-17 17:51:32 +08:00
parent 2844f7c557
commit ad6f5b388b
9 changed files with 77 additions and 12 deletions
+8
View File
@@ -38,6 +38,14 @@ export const providersApi = {
return await invoke("delete_provider", { id, app: appId });
},
/**
* Remove provider from live config only (for additive mode apps like OpenCode)
* Does NOT delete from database - provider remains in the list
*/
async removeFromLiveConfig(id: string, appId: AppId): Promise<boolean> {
return await invoke("remove_provider_from_live_config", { id, app: appId });
},
async switch(id: string, appId: AppId): Promise<boolean> {
return await invoke("switch_provider", { id, app: appId });
},
+18 -9
View File
@@ -155,6 +155,13 @@ export const useSwitchProviderMutation = (appId: AppId) => {
onSuccess: async () => {
await queryClient.invalidateQueries({ queryKey: ["providers", appId] });
// OpenCode: also invalidate live provider IDs cache to update button state
if (appId === "opencode") {
await queryClient.invalidateQueries({
queryKey: ["opencodeLiveProviderIds"],
});
}
// 更新托盘菜单(失败不影响主操作)
try {
await providersApi.updateTrayMenu();
@@ -165,15 +172,17 @@ export const useSwitchProviderMutation = (appId: AppId) => {
);
}
toast.success(
t("notifications.switchSuccess", {
defaultValue: "切换供应商成功",
appName: t(`apps.${appId}`, { defaultValue: appId }),
}),
{
closeButton: true,
},
);
// OpenCode: show "added to config" message instead of "switched"
const messageKey =
appId === "opencode"
? "notifications.addToConfigSuccess"
: "notifications.switchSuccess";
const defaultMessage =
appId === "opencode" ? "已添加到配置" : "切换供应商成功";
toast.success(t(messageKey, { defaultValue: defaultMessage }), {
closeButton: true,
});
},
onError: (error: Error) => {
const detail = extractErrorMessage(error) || t("common.unknown");