mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-26 06:24:32 +08:00
62fa5213bf
* feat(proxy): align thinking rectifiers and resolve clippy warnings - add thinking budget rectifier flow with single retry on anthropic budget errors - align thinking signature rectification behavior with adaptive-safe handling - expose requestThinkingBudget in settings/ui/i18n and default rectifier config to disabled - fix clippy warnings in model_mapper format args and RectifierConfig default derive * fix(proxy): thinking rectifiers
92 lines
3.0 KiB
TypeScript
92 lines
3.0 KiB
TypeScript
import { useEffect, useState } from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
import { toast } from "sonner";
|
|
import { Switch } from "@/components/ui/switch";
|
|
import { Label } from "@/components/ui/label";
|
|
import { settingsApi, type RectifierConfig } from "@/lib/api/settings";
|
|
|
|
export function RectifierConfigPanel() {
|
|
const { t } = useTranslation();
|
|
const [config, setConfig] = useState<RectifierConfig>({
|
|
enabled: true,
|
|
requestThinkingSignature: true,
|
|
requestThinkingBudget: true,
|
|
});
|
|
const [isLoading, setIsLoading] = useState(true);
|
|
|
|
useEffect(() => {
|
|
settingsApi
|
|
.getRectifierConfig()
|
|
.then(setConfig)
|
|
.catch((e) => console.error("Failed to load rectifier config:", e))
|
|
.finally(() => setIsLoading(false));
|
|
}, []);
|
|
|
|
const handleChange = async (updates: Partial<RectifierConfig>) => {
|
|
const newConfig = { ...config, ...updates };
|
|
setConfig(newConfig);
|
|
try {
|
|
await settingsApi.setRectifierConfig(newConfig);
|
|
} catch (e) {
|
|
console.error("Failed to save rectifier config:", e);
|
|
toast.error(String(e));
|
|
setConfig(config);
|
|
}
|
|
};
|
|
|
|
if (isLoading) return null;
|
|
|
|
return (
|
|
<div className="space-y-6">
|
|
<div className="flex items-center justify-between">
|
|
<div className="space-y-0.5">
|
|
<Label>{t("settings.advanced.rectifier.enabled")}</Label>
|
|
<p className="text-xs text-muted-foreground">
|
|
{t("settings.advanced.rectifier.enabledDescription")}
|
|
</p>
|
|
</div>
|
|
<Switch
|
|
checked={config.enabled}
|
|
onCheckedChange={(checked) => handleChange({ enabled: checked })}
|
|
/>
|
|
</div>
|
|
|
|
<div className="space-y-4">
|
|
<h4 className="text-sm font-medium text-muted-foreground">
|
|
{t("settings.advanced.rectifier.requestGroup")}
|
|
</h4>
|
|
<div className="flex items-center justify-between pl-4">
|
|
<div className="space-y-0.5">
|
|
<Label>{t("settings.advanced.rectifier.thinkingSignature")}</Label>
|
|
<p className="text-xs text-muted-foreground">
|
|
{t("settings.advanced.rectifier.thinkingSignatureDescription")}
|
|
</p>
|
|
</div>
|
|
<Switch
|
|
checked={config.requestThinkingSignature}
|
|
disabled={!config.enabled}
|
|
onCheckedChange={(checked) =>
|
|
handleChange({ requestThinkingSignature: checked })
|
|
}
|
|
/>
|
|
</div>
|
|
<div className="flex items-center justify-between pl-4">
|
|
<div className="space-y-0.5">
|
|
<Label>{t("settings.advanced.rectifier.thinkingBudget")}</Label>
|
|
<p className="text-xs text-muted-foreground">
|
|
{t("settings.advanced.rectifier.thinkingBudgetDescription")}
|
|
</p>
|
|
</div>
|
|
<Switch
|
|
checked={config.requestThinkingBudget}
|
|
disabled={!config.enabled}
|
|
onCheckedChange={(checked) =>
|
|
handleChange({ requestThinkingBudget: checked })
|
|
}
|
|
/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|