@@ -320,9 +320,82 @@ export const useModelProvider = create<ModelProviderState>()(
320320 } )
321321 }
322322
323+ if ( version <= 3 && state ?. providers ) {
324+ state . providers . forEach ( ( provider ) => {
325+ // Migrate Anthropic provider base URL and add custom headers
326+ if ( provider . provider === 'anthropic' ) {
327+ if ( provider . base_url === 'https://api.anthropic.com' ) {
328+ provider . base_url = 'https://api.anthropic.com/v1'
329+ }
330+
331+ // Update base-url in settings
332+ if ( provider . settings ) {
333+ const baseUrlSetting = provider . settings . find (
334+ ( s ) => s . key === 'base-url'
335+ )
336+ if (
337+ baseUrlSetting ?. controller_props ?. value ===
338+ 'https://api.anthropic.com'
339+ ) {
340+ baseUrlSetting . controller_props . value =
341+ 'https://api.anthropic.com/v1'
342+ }
343+ if (
344+ baseUrlSetting ?. controller_props ?. placeholder ===
345+ 'https://api.anthropic.com'
346+ ) {
347+ baseUrlSetting . controller_props . placeholder =
348+ 'https://api.anthropic.com/v1'
349+ }
350+ }
351+
352+ if ( ! provider . custom_header ) {
353+ provider . custom_header = [
354+ {
355+ header : 'anthropic-version' ,
356+ value : '2023-06-01' ,
357+ } ,
358+ {
359+ header : 'anthropic-dangerous-direct-browser-access' ,
360+ value : 'true' ,
361+ } ,
362+ ]
363+ }
364+ }
365+
366+ if ( provider . provider === 'cohere' ) {
367+ if ( provider . base_url === 'https://api.cohere.ai/compatibility/v1' ) {
368+ provider . base_url = 'https://api.cohere.ai/v1'
369+ }
370+
371+ // Update base-url in settings
372+ if ( provider . settings ) {
373+ const baseUrlSetting = provider . settings . find (
374+ ( s ) => s . key === 'base-url'
375+ )
376+ if (
377+ baseUrlSetting ?. controller_props ?. value ===
378+ 'https://api.cohere.ai/compatibility/v1'
379+ ) {
380+ baseUrlSetting . controller_props . value =
381+ 'https://api.cohere.ai/v1'
382+ }
383+ if (
384+ baseUrlSetting ?. controller_props ?. placeholder ===
385+ 'https://api.cohere.ai/compatibility/v1'
386+ ) {
387+ baseUrlSetting . controller_props . placeholder =
388+ 'https://api.cohere.ai/v1'
389+ }
390+ }
391+ }
392+
393+ } )
394+ }
395+
323396 return state
324397 } ,
325- version : 3 ,
398+ version : 4 ,
326399 }
327400 )
328401)
0 commit comments