@@ -19,6 +19,11 @@ let currentBackgroundModelConfig: ModelConfig | null = null;
1919 */
2020export async function initializeDefaultSemanticEngine ( ) : Promise < void > {
2121 try {
22+ console . log ( 'Background: Initializing default semantic engine...' ) ;
23+
24+ // Update status to initializing
25+ await updateModelStatus ( 'initializing' , 0 ) ;
26+
2227 const result = await chrome . storage . local . get ( [ STORAGE_KEYS . SEMANTIC_MODEL , 'selectedVersion' ] ) ;
2328 const defaultModel =
2429 ( result [ STORAGE_KEYS . SEMANTIC_MODEL ] as ModelPreset ) || 'multilingual-e5-small' ;
@@ -49,11 +54,31 @@ export async function initializeDefaultSemanticEngine(): Promise<void> {
4954 modelDimension : modelInfo . dimension ,
5055 } ;
5156 console . log ( 'Semantic engine initialized successfully:' , currentBackgroundModelConfig ) ;
57+
58+ // Update status to ready
59+ await updateModelStatus ( 'ready' , 100 ) ;
60+
61+ // Also initialize ContentIndexer now that semantic engine is ready
62+ try {
63+ const { getGlobalContentIndexer } = await import ( '@/utils/content-indexer' ) ;
64+ const contentIndexer = getGlobalContentIndexer ( ) ;
65+ contentIndexer . startSemanticEngineInitialization ( ) ;
66+ console . log ( 'ContentIndexer initialization triggered after semantic engine initialization' ) ;
67+ } catch ( indexerError ) {
68+ console . warn (
69+ 'Failed to initialize ContentIndexer after semantic engine initialization:' ,
70+ indexerError ,
71+ ) ;
72+ }
5273 } else {
53- throw new Error ( response ?. error || ERROR_MESSAGES . TOOL_EXECUTION_FAILED ) ;
74+ const errorMessage = response ?. error || ERROR_MESSAGES . TOOL_EXECUTION_FAILED ;
75+ await updateModelStatus ( 'error' , 0 , errorMessage , 'unknown' ) ;
76+ throw new Error ( errorMessage ) ;
5477 }
55- } catch ( error ) {
78+ } catch ( error : any ) {
5679 console . error ( 'Background: Failed to initialize default semantic engine:' , error ) ;
80+ const errorMessage = error ?. message || 'Unknown error during semantic engine initialization' ;
81+ await updateModelStatus ( 'error' , 0 , errorMessage , 'unknown' ) ;
5782 // Don't throw error, let the extension continue running
5883 }
5984}
@@ -314,6 +339,11 @@ export const initSemanticSimilarityListener = () => {
314339 . then ( ( result : { success : boolean ; error ?: string } ) => sendResponse ( result ) )
315340 . catch ( ( error : any ) => sendResponse ( { success : false , error : error . message } ) ) ;
316341 return true ;
342+ } else if ( message . type === BACKGROUND_MESSAGE_TYPES . INITIALIZE_SEMANTIC_ENGINE ) {
343+ initializeDefaultSemanticEngine ( )
344+ . then ( ( ) => sendResponse ( { success : true } ) )
345+ . catch ( ( error : any ) => sendResponse ( { success : false , error : error . message } ) ) ;
346+ return true ;
317347 }
318348 } ) ;
319349} ;
0 commit comments