e3057f90ea
* feat(provider): add NewAPI provider * feat(providers): Enhance New API model discovery and configuration This commit refactors the model fetching mechanism for the "New API" provider to improve user experience and support more detailed model information. The `NewAPIClient` now fetches models directly from the `/models` endpoint, which provides richer metadata, including a new `supported_endpoint_types` field. Key changes: - The "Edit Models" popup now automatically adds a model if its `supported_endpoint_types` are provided by the API, using the first available type. - The manual "Add Model" popup is now a fallback for models that do not declare their endpoint types. - A new `NewApiModel` type is introduced to handle the structured API response. - Added support for the `jina-rerank` endpoint type. * chore(store): update version to 119 and adjust migration function for state management * fix: adjust label column flex for New API provider in ModelEditContent and NewApiAddModelPopup * feat: Implement batch adding for New API provider * feat: Add useDynamicLabelWidth hook for adaptive label widths in forms and fix localization typos * fix: update dependencies in various components to include translation function --------- Co-authored-by: 自由的世界人 <3196812536@qq.com>
102 lines
2.9 KiB
TypeScript
102 lines
2.9 KiB
TypeScript
import { combineReducers, configureStore } from '@reduxjs/toolkit'
|
|
import { useDispatch, useSelector, useStore } from 'react-redux'
|
|
import { FLUSH, PAUSE, PERSIST, persistReducer, persistStore, PURGE, REGISTER, REHYDRATE } from 'redux-persist'
|
|
import storage from 'redux-persist/lib/storage'
|
|
|
|
import storeSyncService from '../services/StoreSyncService'
|
|
import agents from './agents'
|
|
import assistants from './assistants'
|
|
import backup from './backup'
|
|
import copilot from './copilot'
|
|
import inputToolsReducer from './inputTools'
|
|
import knowledge from './knowledge'
|
|
import llm from './llm'
|
|
import mcp from './mcp'
|
|
import messageBlocksReducer from './messageBlock'
|
|
import migrate from './migrate'
|
|
import minapps from './minapps'
|
|
import newMessagesReducer from './newMessage'
|
|
import nutstore from './nutstore'
|
|
import ocr from './ocr'
|
|
import paintings from './paintings'
|
|
import preprocess from './preprocess'
|
|
import runtime from './runtime'
|
|
import selectionStore from './selectionStore'
|
|
import settings from './settings'
|
|
import shortcuts from './shortcuts'
|
|
import websearch from './websearch'
|
|
|
|
const rootReducer = combineReducers({
|
|
assistants,
|
|
agents,
|
|
backup,
|
|
nutstore,
|
|
paintings,
|
|
llm,
|
|
settings,
|
|
runtime,
|
|
ocr,
|
|
shortcuts,
|
|
knowledge,
|
|
minapps,
|
|
websearch,
|
|
mcp,
|
|
copilot,
|
|
selectionStore,
|
|
// messages: messagesReducer,
|
|
preprocess,
|
|
messages: newMessagesReducer,
|
|
messageBlocks: messageBlocksReducer,
|
|
inputTools: inputToolsReducer
|
|
})
|
|
|
|
const persistedReducer = persistReducer(
|
|
{
|
|
key: 'cherry-studio',
|
|
storage,
|
|
version: 119,
|
|
blacklist: ['runtime', 'messages', 'messageBlocks'],
|
|
migrate
|
|
},
|
|
rootReducer
|
|
)
|
|
|
|
/**
|
|
* Configures the store sync service to synchronize specific state slices across all windows.
|
|
* For detailed implementation, see @renderer/services/StoreSyncService.ts
|
|
*
|
|
* Usage:
|
|
* - 'xxxx/' - Synchronizes the entire state slice
|
|
* - 'xxxx/sliceName' - Synchronizes a specific slice within the state
|
|
*
|
|
* To listen for store changes in a window:
|
|
* Call storeSyncService.subscribe() in the window's entryPoint.tsx
|
|
*/
|
|
storeSyncService.setOptions({
|
|
syncList: ['assistants/', 'settings/', 'llm/', 'selectionStore/']
|
|
})
|
|
|
|
const store = configureStore({
|
|
// @ts-ignore store type is unknown
|
|
reducer: persistedReducer as typeof rootReducer,
|
|
middleware: (getDefaultMiddleware) => {
|
|
return getDefaultMiddleware({
|
|
serializableCheck: {
|
|
ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER]
|
|
}
|
|
}).concat(storeSyncService.createMiddleware())
|
|
},
|
|
devTools: true
|
|
})
|
|
|
|
export type RootState = ReturnType<typeof rootReducer>
|
|
export type AppDispatch = typeof store.dispatch
|
|
|
|
export const persistor = persistStore(store)
|
|
export const useAppDispatch = useDispatch.withTypes<AppDispatch>()
|
|
export const useAppSelector = useSelector.withTypes<RootState>()
|
|
export const useAppStore = useStore.withTypes<typeof store>()
|
|
window.store = store
|
|
|
|
export default store
|