@@ -4,12 +4,21 @@ import { Outlet, useLocation, useNavigate, useParams } from 'react-router-dom';
44import { useTranslation } from 'react-i18next' ;
55import { useUnsavedChangesGuard } from '@/hooks/useUnsavedChangesGuard' ;
66import { providersApi } from '@/services/api' ;
7- import { useAuthStore , useClaudeEditDraftStore , useConfigStore , useNotificationStore } from '@/stores' ;
7+ import {
8+ useAuthStore ,
9+ useClaudeEditDraftStore ,
10+ useConfigStore ,
11+ useNotificationStore ,
12+ } from '@/stores' ;
813import type { ProviderKeyConfig } from '@/types' ;
914import type { ModelInfo } from '@/utils/models' ;
1015import type { ModelEntry , ProviderFormState } from '@/components/providers/types' ;
1116import { buildHeaderObject , headersToEntries , normalizeHeaderEntries } from '@/utils/headers' ;
12- import { areKeyValueEntriesEqual , areModelEntriesEqual , areStringArraysEqual } from '@/utils/compare' ;
17+ import {
18+ areKeyValueEntriesEqual ,
19+ areModelEntriesEqual ,
20+ areStringArraysEqual ,
21+ } from '@/utils/compare' ;
1322import { excludedModelsToText , parseExcludedModels } from '@/components/providers/utils' ;
1423import { modelsToEntries } from '@/components/ui/modelInputListUtils' ;
1524import type { ClaudeEditBaseline } from '@/stores/useClaudeEditDraftStore' ;
@@ -80,7 +89,10 @@ const normalizeClaudeModelEntries = (entries: Array<{ name: string; alias: strin
8089
8190const normalizeCloakConfig = ( cloak : ProviderFormState [ 'cloak' ] ) => {
8291 if ( ! cloak ) return null ;
83- const mode = String ( cloak . mode ?? '' ) . trim ( ) . toLowerCase ( ) || 'auto' ;
92+ const mode =
93+ String ( cloak . mode ?? '' )
94+ . trim ( )
95+ . toLowerCase ( ) || 'auto' ;
8496 const strictMode = Boolean ( cloak . strictMode ) ;
8597 const sensitiveWords = Array . isArray ( cloak . sensitiveWords )
8698 ? cloak . sensitiveWords . map ( ( word ) => String ( word ?? '' ) . trim ( ) ) . filter ( Boolean )
@@ -95,7 +107,9 @@ const normalizeCloakConfig = (cloak: ProviderFormState['cloak']) => {
95107const buildClaudeBaseline = ( form : ProviderFormState ) : ClaudeEditBaseline => ( {
96108 apiKey : String ( form . apiKey ?? '' ) . trim ( ) ,
97109 priority :
98- form . priority !== undefined && Number . isFinite ( form . priority ) ? Math . trunc ( form . priority ) : null ,
110+ form . priority !== undefined && Number . isFinite ( form . priority )
111+ ? Math . trunc ( form . priority )
112+ : null ,
99113 prefix : String ( form . prefix ?? '' ) . trim ( ) ,
100114 baseUrl : String ( form . baseUrl ?? '' ) . trim ( ) ,
101115 proxyUrl : String ( form . proxyUrl ?? '' ) . trim ( ) ,
@@ -105,7 +119,10 @@ const buildClaudeBaseline = (form: ProviderFormState): ClaudeEditBaseline => ({
105119 cloak : normalizeCloakConfig ( form . cloak ) ,
106120} ) ;
107121
108- const areCloakConfigsEqual = ( left : ClaudeEditBaseline [ 'cloak' ] , right : ClaudeEditBaseline [ 'cloak' ] ) => {
122+ const areCloakConfigsEqual = (
123+ left : ClaudeEditBaseline [ 'cloak' ] ,
124+ right : ClaudeEditBaseline [ 'cloak' ]
125+ ) => {
109126 if ( left === right ) return true ;
110127 if ( ! left || ! right ) return false ;
111128 if ( left . mode !== right . mode || left . strictMode !== right . strictMode ) return false ;
@@ -248,6 +265,7 @@ export function AiProvidersClaudeEditLayout() {
248265 if ( initialData ) {
249266 const seededForm : ProviderFormState = {
250267 ...initialData ,
268+ apiKey : '' ,
251269 headers : headersToEntries ( initialData . headers ) ,
252270 modelEntries : modelsToEntries ( initialData . models ) ,
253271 excludedText : excludedModelsToText ( initialData . excludedModels ) ,
@@ -332,8 +350,7 @@ export function AiProvidersClaudeEditLayout() {
332350 enabled : canGuard ,
333351 shouldBlock : ( { nextLocation } ) => {
334352 const nextPath = nextLocation . pathname ;
335- const isWithinRoot =
336- nextPath === editorRootPath || nextPath . startsWith ( `${ editorRootPath } /` ) ;
353+ const isWithinRoot = nextPath === editorRootPath || nextPath . startsWith ( `${ editorRootPath } /` ) ;
337354 return isDirty && ! isWithinRoot ;
338355 } ,
339356 dialog : {
@@ -392,7 +409,10 @@ export function AiProvidersClaudeEditLayout() {
392409 } ) ;
393410
394411 if ( addedCount > 0 ) {
395- showNotification ( t ( 'ai_providers.claude_models_fetch_added' , { count : addedCount } ) , 'success' ) ;
412+ showNotification (
413+ t ( 'ai_providers.claude_models_fetch_added' , { count : addedCount } ) ,
414+ 'success'
415+ ) ;
396416 }
397417 } ,
398418 [ setForm , showNotification , t ]
@@ -406,7 +426,7 @@ export function AiProvidersClaudeEditLayout() {
406426 setSaving ( true ) ;
407427 try {
408428 const payload : ProviderKeyConfig = {
409- apiKey : form . apiKey . trim ( ) ,
429+ apiKey : form . apiKey . trim ( ) || initialData ?. apiKey ?. trim ( ) || '' ,
410430 priority : form . priority !== undefined ? Math . trunc ( form . priority ) : undefined ,
411431 prefix : form . prefix ?. trim ( ) || undefined ,
412432 baseUrl : ( form . baseUrl ?? '' ) . trim ( ) || undefined ,
@@ -434,7 +454,9 @@ export function AiProvidersClaudeEditLayout() {
434454 updateConfigValue ( 'claude-api-key' , nextList ) ;
435455 clearCache ( 'claude-api-key' ) ;
436456 showNotification (
437- editIndex !== null ? t ( 'notification.claude_config_updated' ) : t ( 'notification.claude_config_added' ) ,
457+ editIndex !== null
458+ ? t ( 'notification.claude_config_updated' )
459+ : t ( 'notification.claude_config_added' ) ,
438460 'success'
439461 ) ;
440462 allowNextNavigation ( ) ;
@@ -454,6 +476,7 @@ export function AiProvidersClaudeEditLayout() {
454476 editIndex ,
455477 form ,
456478 handleBack ,
479+ initialData ,
457480 invalidIndex ,
458481 invalidIndexParam ,
459482 resolvedLoading ,
@@ -466,27 +489,29 @@ export function AiProvidersClaudeEditLayout() {
466489
467490 return (
468491 < Outlet
469- context = { {
470- hasIndexParam,
471- editIndex,
472- invalidIndexParam,
473- invalidIndex,
474- disableControls,
475- loading : resolvedLoading ,
476- saving,
477- form,
478- setForm,
479- testModel,
480- setTestModel,
481- testStatus,
482- setTestStatus,
483- testMessage,
484- setTestMessage,
485- availableModels,
486- handleBack,
487- handleSave,
488- mergeDiscoveredModels,
489- } satisfies ClaudeEditOutletContext }
492+ context = {
493+ {
494+ hasIndexParam,
495+ editIndex,
496+ invalidIndexParam,
497+ invalidIndex,
498+ disableControls,
499+ loading : resolvedLoading ,
500+ saving,
501+ form,
502+ setForm,
503+ testModel,
504+ setTestModel,
505+ testStatus,
506+ setTestStatus,
507+ testMessage,
508+ setTestMessage,
509+ availableModels,
510+ handleBack,
511+ handleSave,
512+ mergeDiscoveredModels,
513+ } satisfies ClaudeEditOutletContext
514+ }
490515 />
491516 ) ;
492517}
0 commit comments