@@ -15,7 +15,7 @@ import { reduxSyncMiddleware } from "readium-desktop/main/redux/middleware/sync"
1515import { rootReducer } from "readium-desktop/main/redux/reducers" ;
1616import { rootSaga } from "readium-desktop/main/redux/sagas" ;
1717import { PersistRootState , RootState } from "readium-desktop/main/redux/states" ;
18- import { IS_DEV } from "readium-desktop/preprocessor-directives" ;
18+ import { IS_AI_FEATURE , IS_DEV } from "readium-desktop/preprocessor-directives" ;
1919import { tryCatch , tryCatchSync } from "readium-desktop/utils/tryCatch" ;
2020import { applyMiddleware , legacy_createStore as createStore , type Store } from "redux" ;
2121import createSagaMiddleware , { SagaMiddleware } from "redux-saga" ;
@@ -30,8 +30,11 @@ import { clone } from "ramda";
3030import { TBookmarkState } from "readium-desktop/common/redux/states/bookmark" ;
3131import { TAnnotationState } from "readium-desktop/common/redux/states/renderer/annotation" ;
3232
33- // TODO: DEBUG ONLY AISDK
34- import "dotenv/config" ;
33+
34+ if ( IS_AI_FEATURE ) {
35+ // .env AI API KEY":
36+ require ( "dotenv/config" ) ;
37+ }
3538
3639// import { composeWithDevTools } from "remote-redux-devtools";
3740const REDUX_REMOTE_DEVTOOLS_PORT = 7770 ;
@@ -438,29 +441,33 @@ export async function initStore()
438441 preloadedState . reader . defaultConfig = { ...readerConfigInitialState , ...preloadedState . reader . defaultConfig } ;
439442 }
440443
441- if ( preloadedState ?. aiApiKeys ) {
442- for ( const aiKey of preloadedState . aiApiKeys ) {
443- if ( aiKey . provider === "openAI" && aiKey . aiKey ) {
444- process . env [ "OPENAI_API_KEY" ] = aiKey . aiKey ;
445- } else if ( aiKey . provider === "mistralAI" && aiKey . aiKey ) {
446- process . env [ "MISTRAL_API_KEY" ] = aiKey . aiKey ;
447- } else if ( aiKey . provider === "geminiAI" && aiKey . aiKey ) {
448- process . env [ "GOOGLE_GENERATIVE_AI_API_KEY" ] = aiKey . aiKey ;
444+ if ( IS_AI_FEATURE ) {
445+
446+ if ( preloadedState ?. aiApiKeys ) {
447+ for ( const aiKey of preloadedState . aiApiKeys ) {
448+ if ( aiKey . provider === "openAI" && aiKey . aiKey ) {
449+ process . env [ "OPENAI_API_KEY" ] = aiKey . aiKey ;
450+ } else if ( aiKey . provider === "mistralAI" && aiKey . aiKey ) {
451+ process . env [ "MISTRAL_API_KEY" ] = aiKey . aiKey ;
452+ } else if ( aiKey . provider === "geminiAI" && aiKey . aiKey ) {
453+ process . env [ "GOOGLE_GENERATIVE_AI_API_KEY" ] = aiKey . aiKey ;
454+ }
449455 }
450456 }
451- }
452- {
453- preloadedState . aiApiKeys = [ ] ;
454- if ( process . env [ "OPENAI_API_KEY" ] ) {
455- preloadedState . aiApiKeys . push ( { provider : "openAI" , aiKey : process . env [ "OPENAI_API_KEY" ] } ) ;
456- }
457- if ( process . env [ "MISTRAL_API_KEY" ] ) {
458- preloadedState . aiApiKeys . push ( { provider : "mistralAI" , aiKey : process . env [ "MISTRAL_API_KEY" ] } ) ;
459- }
460- if ( process . env [ "GOOGLE_GENERATIVE_AI_API_KEY" ] ) {
461- preloadedState . aiApiKeys . push ( { provider : "geminiAI" , aiKey : process . env [ "GOOGLE_GENERATIVE_AI_API_KEY" ] } ) ;
457+ {
458+ preloadedState . aiApiKeys = [ ] ;
459+ if ( process . env [ "OPENAI_API_KEY" ] ) {
460+ preloadedState . aiApiKeys . push ( { provider : "openAI" , aiKey : process . env [ "OPENAI_API_KEY" ] } ) ;
461+ }
462+ if ( process . env [ "MISTRAL_API_KEY" ] ) {
463+ preloadedState . aiApiKeys . push ( { provider : "mistralAI" , aiKey : process . env [ "MISTRAL_API_KEY" ] } ) ;
464+ }
465+ if ( process . env [ "GOOGLE_GENERATIVE_AI_API_KEY" ] ) {
466+ preloadedState . aiApiKeys . push ( { provider : "geminiAI" , aiKey : process . env [ "GOOGLE_GENERATIVE_AI_API_KEY" ] } ) ;
467+ }
462468 }
463469 }
470+
464471 if ( preloadedState ?. creator && ! preloadedState . creator . urn ) {
465472 preloadedState . creator . urn = `urn:uuid:${ preloadedState . creator . id } ` ;
466473 }
0 commit comments