mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-29 01:25:33 +08:00
146b42fb68
Implements dual-editor pattern for Gemini providers, following the Codex architecture:
- Environment variables (.env format) editor
- Extended configuration (config.json) editor with common config support
New Components:
- GeminiConfigSections: Separate sections for env and config editing
- GeminiCommonConfigModal: Modal for editing common config snippets
New Hooks:
- useGeminiConfigState: Manages env/config separation and conversion
- Converts between .env string format and JSON object
- Validates JSON config structure
- Extracts API Key and Base URL from env
- useGeminiCommonConfig: Handles common config snippets
- Deep merge algorithm for combining configs
- Remove common config logic for toggling off
- localStorage persistence for snippets
Features:
- Format buttons for both env and config editors
- Common config toggle with deep merge/remove
- Error validation and display
- Auto-open modal on common config errors
Configuration Structure:
{
"env": {
"GOOGLE_GEMINI_BASE_URL": "https://...",
"GEMINI_API_KEY": "sk-...",
"GEMINI_MODEL": "gemini-2.5-pro"
},
"config": {
"timeout": 30000,
"maxRetries": 3
}
}
This brings Gemini providers to feature parity with Claude and Codex.
77 lines
2.1 KiB
TypeScript
77 lines
2.1 KiB
TypeScript
import React, { useState, useEffect } from "react";
|
|
import { GeminiEnvSection, GeminiConfigSection } from "./GeminiConfigSections";
|
|
import { GeminiCommonConfigModal } from "./GeminiCommonConfigModal";
|
|
|
|
interface GeminiConfigEditorProps {
|
|
envValue: string;
|
|
configValue: string;
|
|
onEnvChange: (value: string) => void;
|
|
onConfigChange: (value: string) => void;
|
|
onEnvBlur?: () => void;
|
|
useCommonConfig: boolean;
|
|
onCommonConfigToggle: (checked: boolean) => void;
|
|
commonConfigSnippet: string;
|
|
onCommonConfigSnippetChange: (value: string) => void;
|
|
commonConfigError: string;
|
|
envError: string;
|
|
configError: string;
|
|
}
|
|
|
|
const GeminiConfigEditor: React.FC<GeminiConfigEditorProps> = ({
|
|
envValue,
|
|
configValue,
|
|
onEnvChange,
|
|
onConfigChange,
|
|
onEnvBlur,
|
|
useCommonConfig,
|
|
onCommonConfigToggle,
|
|
commonConfigSnippet,
|
|
onCommonConfigSnippetChange,
|
|
commonConfigError,
|
|
envError,
|
|
configError,
|
|
}) => {
|
|
const [isCommonConfigModalOpen, setIsCommonConfigModalOpen] = useState(false);
|
|
|
|
// Auto-open common config modal if there's an error
|
|
useEffect(() => {
|
|
if (commonConfigError && !isCommonConfigModalOpen) {
|
|
setIsCommonConfigModalOpen(true);
|
|
}
|
|
}, [commonConfigError, isCommonConfigModalOpen]);
|
|
|
|
return (
|
|
<div className="space-y-6">
|
|
{/* Env Section */}
|
|
<GeminiEnvSection
|
|
value={envValue}
|
|
onChange={onEnvChange}
|
|
onBlur={onEnvBlur}
|
|
error={envError}
|
|
/>
|
|
|
|
{/* Config JSON Section */}
|
|
<GeminiConfigSection
|
|
value={configValue}
|
|
onChange={onConfigChange}
|
|
useCommonConfig={useCommonConfig}
|
|
onCommonConfigToggle={onCommonConfigToggle}
|
|
onEditCommonConfig={() => setIsCommonConfigModalOpen(true)}
|
|
commonConfigError={commonConfigError}
|
|
configError={configError}
|
|
/>
|
|
|
|
{/* Common Config Modal */}
|
|
<GeminiCommonConfigModal
|
|
isOpen={isCommonConfigModalOpen}
|
|
onClose={() => setIsCommonConfigModalOpen(false)}
|
|
value={commonConfigSnippet}
|
|
onChange={onCommonConfigSnippetChange}
|
|
error={commonConfigError}
|
|
/>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default GeminiConfigEditor;
|