File tree Expand file tree Collapse file tree
src/components/providers/forms/hooks Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -160,9 +160,13 @@ export function useCodexCommonConfig({
160160 config ,
161161 commonConfigSnippet ,
162162 ) ;
163- const hasCommon = initialEnabled ?? inferredHasCommon ;
164163
165- if ( hasCommon && ! inferredHasCommon ) {
164+ // 优先级:显式设置的 initialEnabled > 从配置推断的值
165+ // 如果 initialEnabled 为 undefined,使用推断值
166+ const hasCommon = initialEnabled !== undefined ? initialEnabled : inferredHasCommon ;
167+
168+ // 如果应该启用通用配置但配置中还没有,则自动添加
169+ if ( hasCommon && ! inferredHasCommon && parsedSnippet . hasContent ) {
166170 const { updatedConfig, error } = updateTomlCommonConfigSnippet (
167171 codexConfig ,
168172 commonConfigSnippet ,
Original file line number Diff line number Diff line change @@ -118,17 +118,22 @@ export function useCommonConfigSnippet({
118118 // 初始化时检查通用配置片段(编辑模式)
119119 useEffect ( ( ) => {
120120 if ( ! enabled ) return ;
121- if ( initialData && ! isLoading ) {
121+ if ( initialData && ! isLoading && ! hasInitializedEditMode . current ) {
122+ hasInitializedEditMode . current = true ;
123+
122124 const configString = JSON . stringify ( initialData . settingsConfig , null , 2 ) ;
123125 const inferredHasCommon = hasCommonConfigSnippet (
124126 configString ,
125127 commonConfigSnippet ,
126128 ) ;
127- const hasCommon = initialEnabled ?? inferredHasCommon ;
129+
130+ // 优先级:显式设置的 initialEnabled > 从配置推断的值
131+ // 如果 initialEnabled 为 undefined,使用推断值
132+ const hasCommon = initialEnabled !== undefined ? initialEnabled : inferredHasCommon ;
128133 setUseCommonConfig ( hasCommon ) ;
129134
130- if ( hasCommon && ! inferredHasCommon && ! hasInitializedEditMode . current ) {
131- hasInitializedEditMode . current = true ;
135+ // 如果应该启用通用配置但配置中还没有,则自动添加
136+ if ( hasCommon && ! inferredHasCommon ) {
132137 const { updatedConfig, error } = updateCommonConfigSnippet (
133138 settingsConfig ,
134139 commonConfigSnippet ,
@@ -141,8 +146,6 @@ export function useCommonConfigSnippet({
141146 isUpdatingFromCommonConfig . current = false ;
142147 } , 0 ) ;
143148 }
144- } else {
145- hasInitializedEditMode . current = true ;
146149 }
147150 }
148151 } , [
Original file line number Diff line number Diff line change @@ -244,9 +244,13 @@ export function useGeminiCommonConfig({
244244 env ,
245245 parsed . env as Record < string , string > ,
246246 ) ;
247- const hasCommon = initialEnabled ?? inferredHasCommon ;
248247
249- if ( hasCommon && ! inferredHasCommon ) {
248+ // 优先级:显式设置的 initialEnabled > 从配置推断的值
249+ // 如果 initialEnabled 为 undefined,使用推断值
250+ const hasCommon = initialEnabled !== undefined ? initialEnabled : inferredHasCommon ;
251+
252+ // 如果应该启用通用配置但配置中还没有,则自动添加
253+ if ( hasCommon && ! inferredHasCommon && Object . keys ( parsed . env ) . length > 0 ) {
250254 const currentEnv = envStringToObj ( envValue ) ;
251255 const merged = applySnippetToEnv ( currentEnv , parsed . env ) ;
252256 const nextEnvString = envObjToString ( merged ) ;
You can’t perform that action at this time.
0 commit comments