mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-29 01:25:33 +08:00
feat(codex): add remote compaction toggle for third-party providers
Write model_providers name as "OpenAI" to let Codex attempt remote compaction through compatible endpoints. Hidden for official providers.
This commit is contained in:
@@ -7,6 +7,10 @@ interface CodexConfigEditorProps {
|
||||
|
||||
configValue: string;
|
||||
|
||||
providerName?: string;
|
||||
|
||||
showRemoteCompaction?: boolean;
|
||||
|
||||
onAuthChange: (value: string) => void;
|
||||
|
||||
onConfigChange: (value: string) => void;
|
||||
@@ -37,6 +41,8 @@ interface CodexConfigEditorProps {
|
||||
const CodexConfigEditor: React.FC<CodexConfigEditorProps> = ({
|
||||
authValue,
|
||||
configValue,
|
||||
providerName,
|
||||
showRemoteCompaction,
|
||||
onAuthChange,
|
||||
onConfigChange,
|
||||
onAuthBlur,
|
||||
@@ -72,6 +78,8 @@ const CodexConfigEditor: React.FC<CodexConfigEditorProps> = ({
|
||||
<CodexConfigSection
|
||||
value={configValue}
|
||||
onChange={onConfigChange}
|
||||
providerName={providerName}
|
||||
showRemoteCompaction={showRemoteCompaction}
|
||||
useCommonConfig={useCommonConfig}
|
||||
onCommonConfigToggle={onCommonConfigToggle}
|
||||
onEditCommonConfig={() => setIsCommonConfigModalOpen(true)}
|
||||
|
||||
@@ -12,7 +12,9 @@ import { useTranslation } from "react-i18next";
|
||||
import JsonEditor from "@/components/JsonEditor";
|
||||
import {
|
||||
isCodexGoalModeEnabled,
|
||||
isCodexRemoteCompactionEnabled,
|
||||
setCodexGoalMode,
|
||||
setCodexRemoteCompaction,
|
||||
} from "@/utils/providerConfigUtils";
|
||||
/*
|
||||
import {
|
||||
@@ -98,6 +100,8 @@ export const CodexAuthSection: React.FC<CodexAuthSectionProps> = ({
|
||||
interface CodexConfigSectionProps {
|
||||
value: string;
|
||||
onChange: (value: string) => void;
|
||||
providerName?: string;
|
||||
showRemoteCompaction?: boolean;
|
||||
useCommonConfig: boolean;
|
||||
onCommonConfigToggle: (checked: boolean) => void;
|
||||
onEditCommonConfig: () => void;
|
||||
@@ -111,6 +115,8 @@ interface CodexConfigSectionProps {
|
||||
export const CodexConfigSection: React.FC<CodexConfigSectionProps> = ({
|
||||
value,
|
||||
onChange,
|
||||
providerName,
|
||||
showRemoteCompaction = true,
|
||||
useCommonConfig,
|
||||
onCommonConfigToggle,
|
||||
onEditCommonConfig,
|
||||
@@ -157,6 +163,10 @@ export const CodexConfigSection: React.FC<CodexConfigSectionProps> = ({
|
||||
() => isCodexGoalModeEnabled(localValue),
|
||||
[localValue],
|
||||
);
|
||||
const remoteCompactionEnabled = useMemo(
|
||||
() => isCodexRemoteCompactionEnabled(localValue),
|
||||
[localValue],
|
||||
);
|
||||
|
||||
const handleGoalModeToggle = useCallback(
|
||||
(checked: boolean) => {
|
||||
@@ -165,6 +175,19 @@ export const CodexConfigSection: React.FC<CodexConfigSectionProps> = ({
|
||||
[handleLocalChange],
|
||||
);
|
||||
|
||||
const handleRemoteCompactionToggle = useCallback(
|
||||
(checked: boolean) => {
|
||||
handleLocalChange(
|
||||
setCodexRemoteCompaction(
|
||||
localValueRef.current || "",
|
||||
checked,
|
||||
providerName,
|
||||
),
|
||||
);
|
||||
},
|
||||
[handleLocalChange, providerName],
|
||||
);
|
||||
|
||||
// Codex 1M 上下文相关状态/回调暂时禁用——见同文件下方 JSX 注释处的恢复说明。
|
||||
/*
|
||||
// Parse toggle states from TOML text
|
||||
@@ -257,6 +280,21 @@ export const CodexConfigSection: React.FC<CodexConfigSectionProps> = ({
|
||||
{t("codexConfig.enableGoalMode")}
|
||||
</label>
|
||||
|
||||
{showRemoteCompaction && (
|
||||
<label
|
||||
className="inline-flex cursor-pointer items-center gap-2 text-sm text-muted-foreground"
|
||||
title={t("codexConfig.remoteCompactionHint")}
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={remoteCompactionEnabled}
|
||||
onChange={(e) => handleRemoteCompactionToggle(e.target.checked)}
|
||||
className="w-4 h-4 text-blue-500 bg-white dark:bg-gray-800 border-border-default rounded focus:ring-blue-500 dark:focus:ring-blue-400 focus:ring-2"
|
||||
/>
|
||||
{t("codexConfig.enableRemoteCompaction")}
|
||||
</label>
|
||||
)}
|
||||
|
||||
<label className="inline-flex cursor-pointer items-center gap-2 text-sm text-muted-foreground">
|
||||
<input
|
||||
type="checkbox"
|
||||
|
||||
@@ -2163,6 +2163,8 @@ function ProviderFormFull({
|
||||
<CodexConfigEditor
|
||||
authValue={codexAuth}
|
||||
configValue={codexConfig}
|
||||
providerName={form.watch("name")}
|
||||
showRemoteCompaction={category !== "official"}
|
||||
onAuthChange={setCodexAuth}
|
||||
onConfigChange={handleCodexConfigChange}
|
||||
useCommonConfig={useCodexCommonConfigFlag}
|
||||
|
||||
Reference in New Issue
Block a user