mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-27 08:14:33 +08:00
refactor(common-config): extract snippet from editor content instead of active provider
- Change extraction source from current active provider to editor's live content - Add i18n support for JSON parse error messages via invalid_json_format_error() - Simplify API by removing unused providerId parameter - Update button labels and error messages in zh/en/ja locales
This commit is contained in:
@@ -67,7 +67,7 @@ export const CodexCommonConfigModal: React.FC<CodexCommonConfigModalProps> = ({
|
||||
<Download className="w-4 h-4" />
|
||||
)}
|
||||
{t("codexConfig.extractFromCurrent", {
|
||||
defaultValue: "从当前供应商提取",
|
||||
defaultValue: "从编辑内容提取",
|
||||
})}
|
||||
</Button>
|
||||
)}
|
||||
|
||||
@@ -129,7 +129,7 @@ export function CommonConfigEditor({
|
||||
<Download className="w-4 h-4" />
|
||||
)}
|
||||
{t("claudeConfig.extractFromCurrent", {
|
||||
defaultValue: "从当前供应商提取",
|
||||
defaultValue: "从编辑内容提取",
|
||||
})}
|
||||
</Button>
|
||||
)}
|
||||
|
||||
@@ -63,7 +63,7 @@ export const GeminiCommonConfigModal: React.FC<
|
||||
<Download className="w-4 h-4" />
|
||||
)}
|
||||
{t("geminiConfig.extractFromCurrent", {
|
||||
defaultValue: "从当前供应商提取",
|
||||
defaultValue: "从编辑内容提取",
|
||||
})}
|
||||
</Button>
|
||||
)}
|
||||
|
||||
@@ -246,13 +246,17 @@ export function useCodexCommonConfig({
|
||||
setUseCommonConfig(hasCommon);
|
||||
}, [codexConfig, commonConfigSnippet, isLoading]);
|
||||
|
||||
// 从当前供应商提取通用配置片段
|
||||
// 从编辑器当前内容提取通用配置片段
|
||||
const handleExtract = useCallback(async () => {
|
||||
setIsExtracting(true);
|
||||
setCommonConfigError("");
|
||||
|
||||
try {
|
||||
const extracted = await configApi.extractCommonConfigSnippet("codex");
|
||||
const extracted = await configApi.extractCommonConfigSnippet("codex", {
|
||||
settingsConfig: JSON.stringify({
|
||||
config: codexConfig ?? "",
|
||||
}),
|
||||
});
|
||||
|
||||
if (!extracted || !extracted.trim()) {
|
||||
setCommonConfigError(t("codexConfig.extractNoCommonConfig"));
|
||||
@@ -270,7 +274,7 @@ export function useCodexCommonConfig({
|
||||
} finally {
|
||||
setIsExtracting(false);
|
||||
}
|
||||
}, []);
|
||||
}, [codexConfig, t]);
|
||||
|
||||
return {
|
||||
useCommonConfig,
|
||||
|
||||
@@ -252,13 +252,15 @@ export function useCommonConfigSnippet({
|
||||
setUseCommonConfig(hasCommon);
|
||||
}, [settingsConfig, commonConfigSnippet, isLoading]);
|
||||
|
||||
// 从当前供应商提取通用配置片段
|
||||
// 从编辑器当前内容提取通用配置片段
|
||||
const handleExtract = useCallback(async () => {
|
||||
setIsExtracting(true);
|
||||
setCommonConfigError("");
|
||||
|
||||
try {
|
||||
const extracted = await configApi.extractCommonConfigSnippet("claude");
|
||||
const extracted = await configApi.extractCommonConfigSnippet("claude", {
|
||||
settingsConfig,
|
||||
});
|
||||
|
||||
if (!extracted || extracted === "{}") {
|
||||
setCommonConfigError(t("claudeConfig.extractNoCommonConfig"));
|
||||
@@ -283,7 +285,7 @@ export function useCommonConfigSnippet({
|
||||
} finally {
|
||||
setIsExtracting(false);
|
||||
}
|
||||
}, []);
|
||||
}, [settingsConfig, t]);
|
||||
|
||||
return {
|
||||
useCommonConfig,
|
||||
|
||||
@@ -402,13 +402,20 @@ export function useGeminiCommonConfig({
|
||||
parseSnippetEnv,
|
||||
]);
|
||||
|
||||
// 从当前供应商提取通用配置片段
|
||||
// 从编辑器当前内容提取通用配置片段
|
||||
const handleExtract = useCallback(async () => {
|
||||
setIsExtracting(true);
|
||||
setCommonConfigError("");
|
||||
|
||||
try {
|
||||
const extracted = await configApi.extractCommonConfigSnippet("gemini");
|
||||
const extracted = await configApi.extractCommonConfigSnippet(
|
||||
"gemini",
|
||||
{
|
||||
settingsConfig: JSON.stringify({
|
||||
env: envStringToObj(envValue),
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
if (!extracted || extracted === "{}") {
|
||||
setCommonConfigError(t("geminiConfig.extractNoCommonConfig"));
|
||||
@@ -433,7 +440,7 @@ export function useGeminiCommonConfig({
|
||||
} finally {
|
||||
setIsExtracting(false);
|
||||
}
|
||||
}, [parseSnippetEnv, t]);
|
||||
}, [envStringToObj, envValue, parseSnippetEnv, t]);
|
||||
|
||||
return {
|
||||
useCommonConfig,
|
||||
|
||||
Reference in New Issue
Block a user