@ -16,49 +16,53 @@ export async function validateEmbeddingProviders(validationWarning: HTMLElement)
return ;
}
// Get pr ovider pr ecedence
// Get pr ecedence list from options
const precedenceStr = options . get ( 'aiProviderPrecedence' ) || 'openai,anthropic,ollama' ;
let precedenceList : string [ ] = [ ] ;
if ( precedenceStr ) {
if ( precedenceStr . startsWith ( '[' ) && precedenceStr . endsWith ( ']' ) ) {
precedenceList = JSON . parse ( precedenceStr ) ;
try {
precedenceList = JSON . parse ( precedenceStr ) ;
} catch ( e ) {
console . error ( 'Error parsing precedence list:' , e ) ;
precedenceList = [ 'openai' ] ; // Default if parsing fails
}
} else if ( precedenceStr . includes ( ',' ) ) {
precedenceList = precedenceStr . split ( ',' ) . map ( p = > p . trim ( ) ) ;
} else {
precedenceList = [ precedenceStr ] ;
}
}
// Get enabled providers - this is a simplification since we don't have direct DB access
// We'll determine enabled status based on the presence of keys or settings
const enabledProviders : string [ ] = [ ] ;
// OpenAI is enabled if API key is set
const openaiKey = options . get ( 'openaiApiKey' ) ;
if ( openaiKey ) {
enabledProviders . push ( 'openai' ) ;
}
// Anthropic is enabled if API key is set
const anthropicKey = options . get ( 'anthropicApiKey' ) ;
if ( anthropicKey ) {
enabledProviders . push ( 'anthropic' ) ;
}
// Ollama is enabled if base URL is set
const ollamaBaseUrl = options . get ( 'ollamaBaseUrl' ) ;
if ( ollamaBaseUrl ) {
enabledProviders . push ( 'ollama' ) ;
// Check for configuration issues with providers in the precedence list
const configIssues : string [ ] = [ ] ;
// Check each provider in the precedence list for proper configuration
for ( const provider of precedenceList ) {
if ( provider === 'openai' ) {
// Check OpenAI configuration
const apiKey = options . get ( 'openaiApiKey' ) ;
if ( ! apiKey ) {
configIssues . push ( ` OpenAI API key is missing ` ) ;
}
} else if ( provider === 'anthropic' ) {
// Check Anthropic configuration
const apiKey = options . get ( 'anthropicApiKey' ) ;
if ( ! apiKey ) {
configIssues . push ( ` Anthropic API key is missing ` ) ;
}
} else if ( provider === 'ollama' ) {
// Check Ollama configuration
const baseUrl = options . get ( 'ollamaBaseUrl' ) ;
if ( ! baseUrl ) {
configIssues . push ( ` Ollama Base URL is missing ` ) ;
}
}
// Add checks for other providers as needed
}
// Local is always available
enabledProviders . push ( 'local' ) ;
// Perform validation checks
const allPrecedenceEnabled = precedenceList . every ( ( p : string ) = > enabledProviders . includes ( p ) ) ;
// Get embedding queue status
// Fetch embedding stats to check if there are any notes being processed
const embeddingStats = await getEmbeddingStats ( ) as {
success : boolean ,
stats : {
@ -73,17 +77,18 @@ export async function validateEmbeddingProviders(validationWarning: HTMLElement)
const queuedNotes = embeddingStats ? . stats ? . queuedNotesCount || 0 ;
const hasEmbeddingsInQueue = queuedNotes > 0 ;
// Show warning if there are issues
if ( ! allPrecedenceEnabled || hasEmbeddingsInQueue ) {
// Show warning if there are configuration issues or embeddings in queue
if ( configIssues . length > 0 || hasEmbeddingsInQueue ) {
let message = '<i class="bx bx-error-circle me-2"></i><strong>AI Provider Configuration Issues</strong>' ;
message += '<ul class="mb-1 ps-4">' ;
if ( ! allPrecedenceEnabled ) {
const disabledProviders = precedenceList . filter ( ( p : string ) = > ! enabledProviders . includes ( p ) ) ;
message += ` <li> The following providers in your precedence list are not enabled: ${ disabledProviders . join ( ', ' ) } . </li>` ;
// Show configuration issues
for ( const issue of configIssues ) {
message += ` <li> ${ issue } </li>` ;
}
// Show warning about embeddings queue if applicable
if ( hasEmbeddingsInQueue ) {
message += ` <li>Currently processing embeddings for ${ queuedNotes } notes. Some AI features may produce incomplete results until processing completes.</li> ` ;
}