@@ -40,13 +40,14 @@ export function loadConfigForProvider(provider: Provider): AIConfig {
4040 provider,
4141 endpoint : ( ( ) => {
4242 const value = stored . endpoint ?? defaults . endpoint ?? ''
43+ const fallback = defaults . endpoint ?? ''
4344 if ( provider !== 'ollama' && isLocalEndpoint ( value ) ) {
44- return defaults . endpoint ?? ''
45+ return normalizeEndpoint ( provider , String ( fallback ) )
4546 }
4647 if ( ! value ) {
47- return defaults . endpoint ?? ''
48+ return normalizeEndpoint ( provider , String ( fallback ) )
4849 }
49- return value
50+ return normalizeEndpoint ( provider , String ( value ) )
5051 } ) ( ) ,
5152 model : stored . model ?? defaults . model ?? '' ,
5253 apiKey : stored . apiKey ?? defaults . apiKey ?? '' ,
@@ -74,7 +75,7 @@ export function saveConfig(config: AIConfig): void {
7475 const normalizedProvider = ( provider === 'local' ? 'ollama' : provider ) as Provider
7576 const defaults = getDefaultConfig ( normalizedProvider )
7677 const providerConfig = {
77- endpoint : ( rest . endpoint && String ( rest . endpoint ) . trim ( ) ) || defaults . endpoint || '' ,
78+ endpoint : normalizeEndpoint ( normalizedProvider , ( rest . endpoint && String ( rest . endpoint ) . trim ( ) ) || defaults . endpoint || '' ) ,
7879 model : rest . model ?? defaults . model ?? '' ,
7980 apiKey : rest . apiKey ?? defaults . apiKey ?? '' ,
8081 timeout : ( typeof rest . timeout === 'number' && rest . timeout > 0 ? rest . timeout : defaults . timeout ?? 120 ) ,
@@ -94,7 +95,7 @@ export function saveConfig(config: AIConfig): void {
9495export function getDefaultConfig ( provider : string ) : Partial < AIConfig > {
9596 const defaults : Record < string , Partial < AIConfig > > = {
9697 ollama : { endpoint : 'http://localhost:11434' , apiKey : '' , timeout : 120 } ,
97- openai : { endpoint : 'https://api.openai.com/v1 ' , apiKey : '' , timeout : 120 } ,
98+ openai : { endpoint : 'https://api.openai.com' , apiKey : '' , timeout : 120 } ,
9899 deepseek : { endpoint : 'https://api.deepseek.com' , apiKey : '' , timeout : 180 }
99100 }
100101
@@ -121,10 +122,8 @@ export function getMockModels(provider: string): Model[] {
121122 { id : 'gpt-5' , name : 'GPT-5 ⭐' , size : 'Cloud' } ,
122123 { id : 'gpt-5-mini' , name : 'GPT-5 Mini' , size : 'Cloud' } ,
123124 { id : 'gpt-5-nano' , name : 'GPT-5 Nano' , size : 'Cloud' } ,
124- { id : 'gpt-4.1-2025-04-14' , name : 'GPT-4.1' , size : 'Cloud' } ,
125- { id : 'gpt-4.1-mini-2025-04-14' , name : 'GPT-4.1 Mini' , size : 'Cloud' } ,
126- { id : 'gpt-4o-2024-08-06' , name : 'GPT-4o' , size : 'Cloud' } ,
127- { id : 'gpt-4o-mini-2024-07-18' , name : 'GPT-4o Mini' , size : 'Cloud' }
125+ { id : 'gpt-5-pro' , name : 'GPT-5 Pro' , size : 'Cloud' } ,
126+ { id : 'gpt-4.1' , name : 'GPT-4.1' , size : 'Cloud' }
128127 ] ,
129128 deepseek : [
130129 { id : 'deepseek-chat' , name : 'DeepSeek Chat' , size : 'Cloud' } ,
@@ -140,3 +139,27 @@ export function getMockModels(provider: string): Model[] {
140139export function generateId ( ) : string {
141140 return `${ Date . now ( ) } -${ Math . random ( ) . toString ( 36 ) . slice ( 2 , 9 ) } `
142141}
142+
143+ function normalizeEndpoint ( provider : Provider , endpoint : string ) : string {
144+ const normalizedProvider : Provider = ( provider === 'local' ? 'ollama' : provider ) as Provider
145+ if ( ! endpoint ) {
146+ return endpoint
147+ }
148+
149+ let value = endpoint . trim ( )
150+ while ( value . endsWith ( '/' ) ) {
151+ value = value . slice ( 0 , - 1 )
152+ }
153+
154+ if ( normalizedProvider === 'openai' || normalizedProvider === 'deepseek' ) {
155+ const lower = value . toLowerCase ( )
156+ if ( lower . endsWith ( '/v1' ) ) {
157+ value = value . slice ( 0 , value . length - 3 )
158+ while ( value . endsWith ( '/' ) ) {
159+ value = value . slice ( 0 , - 1 )
160+ }
161+ }
162+ }
163+
164+ return value
165+ }
0 commit comments