diff --git a/src/features/DebugUI/data.ts b/src/features/DebugUI/data.ts index 4711a12e..3ef5996a 100644 --- a/src/features/DebugUI/data.ts +++ b/src/features/DebugUI/data.ts @@ -557,7 +557,9 @@ const settings = { backgroundEffect: 'glow', languageModel: { openAI: { - model: 'gpt-4o', + fetchOnClient: true, + apiKey: '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', + endpoint: 'https://openrouter.ai/api/v1', }, }, }, diff --git a/src/layout/StoreHydration.tsx b/src/layout/StoreHydration.tsx index 8b1e37c7..3d8dbbdf 100644 --- a/src/layout/StoreHydration.tsx +++ b/src/layout/StoreHydration.tsx @@ -7,7 +7,7 @@ import { memo, useEffect } from 'react'; import { AGENT_STORAGE_KEY, useAgentStore } from '@/store/agent'; import { DANCE_STORAGE_KEY } from '@/store/dance'; import { SESSION_STORAGE_KEY } from '@/store/session'; -import { SETTING_STORAGE_KEY } from '@/store/setting'; +import { SETTING_STORAGE_KEY, useSettingStore } from '@/store/setting'; import { vidolStorage } from '@/utils/storage'; const MIGRATION_KEY = 'MIGRATE_TO_INDEXED_DB'; @@ -33,11 +33,15 @@ const migrate = async () => { const StoreHydration = () => { const router = useRouter(); + const refreshDefaultModelProviderList = useSettingStore((s) => s.refreshDefaultModelProviderList); + useEffect(() => { // refs: https://github.com/pmndrs/zustand/blob/main/docs/integrations/persisting-store-data.md#hashydrated migrate().then(() => { useAgentStore.persist.rehydrate(); }); + + refreshDefaultModelProviderList(); }, []); useEffect(() => { diff --git a/src/store/setting/index.ts b/src/store/setting/index.ts index 29912aee..140df4e8 100644 --- a/src/store/setting/index.ts +++ b/src/store/setting/index.ts @@ -13,6 +13,7 @@ import { shallow } from 'zustand/shallow'; import { createWithEqualityFn } from 'zustand/traditional'; import { StateCreator } from 'zustand/vanilla'; +import { ModelProvider } from '@/libs/agent-runtime/types/type'; import { ModelListAction, createModelListSlice } from '@/store/setting/slices/modelList'; import createTouchStore, { TouchStore } from '@/store/setting/slices/touch'; import { BackgroundEffect, Config } from '@/types/config'; @@ -118,7 +119,35 @@ const createStore: StateCreator = { name: SETTING_STORAGE_KEY, // name of the item in the storage (must be unique) storage: createJSONStorage(() => vidolStorage), - version: 0, + version: 1, + migrate: (persistedState: unknown, version: number): SettingStore => { + if (version === 0) { + const state = persistedState as SettingStore; + if (state.config.languageModel) { + state.config.languageModel = { + ...state.config.languageModel, + [ModelProvider.OpenAI]: { + //@ts-ignore + ...state.config.languageModel['openAI'], + }, + }; + state.config.languageModel[ModelProvider.OpenAI]!.fetchOnClient = + //@ts-ignore + state.config.languageModel['openAI']!.fetchOnClient; + state.config.keyVaults = { + ...state.config.keyVaults, + [ModelProvider.OpenAI]: { + //@ts-ignore + apiKey: state.config.languageModel['openAI']!.apiKey, + //@ts-ignore + baseURL: state.config.languageModel['openAI']!.endpoint, + }, + }; + } + return state; + } + return persistedState as SettingStore; + }, }; export const useSettingStore = createWithEqualityFn()(