feat: enhance AI settings management with local model support and error handling#2142
Closed
VoidX3D wants to merge 126 commits into
Closed
feat: enhance AI settings management with local model support and error handling#2142VoidX3D wants to merge 126 commits into
VoidX3D wants to merge 126 commits into
Conversation
…ptional support and configuration management
Feat(ai) powerful changes
AI updae
- Add Log, CastAudioMimeUtils, IsoBmffAudioCodecDetector imports to CastPlayer - Fix ArrowBack import in AiPreferencesScreen - Add AI_PREFERENCES branch to SettingsCategoryScreen when expression - Remove retryLastMetadataGeneration from PlayerViewModel (feature was removed) - Fix ColorSchemePair import path in SettingsViewModel Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- Add new engagement tracking fields for AI behavior analysis - Enhance engagement data model with play duration, skip counts Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- Add new AI configuration options for local models - Enhance provider preferences handling Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- Add new AI-related dependency injections - Update provider configurations Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- Update AI state management for playlist generation - Enhance error handling and status tracking Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- Add listening statistics tracking for AI behavior - Update player UI state for enhanced features Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- Update daily mix section for AI integration - Enhance song selection logic Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…oved UX AiPreferencesScreen: - Split into distinct sections: provider, online settings, local models, context settings, data collection, cache, behavior, usage stats - Grey out local model section when online provider is selected - Grey out online API/model settings when local provider is selected - Add system prompt editor with reset-to-default - Add context size text input (5-500 range, user-changeable) - Add data collection & privacy section with 8 granular toggles - Add cache settings (enable, max entries, TTL) - Add notification & behavior preferences - Add usage statistics display with clear button - Use AiProvider.models dynamically for model dropdowns SettingsViewModel: - Add telemetry StateFlows, collectors, and 8 handler functions - Add get*Once() helpers to AiPreferencesRepository for backup
- Add AI_CONTEXT section to BackupSection enum (sinceVersion 5) - Create AiContextBackupHandler: exports/restores AI provider prefs, context settings, cache config, local ML settings (excludes model files) - Register new handler in BackupModule DI
- Fix expand_more/expand_less icon references to PascalCase - Remove duplicate onAiApiKeyChange function overload - Fix currentAiModel -> currentModel field name in state update - Fix Int/Float type mismatch for aiTemperature conversion - Add missing onIncludeUserHabitsChange function - Remove unused expandVertically/shrinkVertically imports - Remove dead companion functions from AiProvider enum
- Add import kotlinx.coroutines.flow.first in AiPreferencesRepository - Add import androidx.compose.ui.res.stringResource in AiPreferencesScreen - Add AI_CONTEXT branch to ModuleSchemaValidator when expression
…leCard AiPreferencesRepository: - Remove 33 per-provider Flow properties (dead code) - Remove 10 duplicate DEFAULT_*_SYSTEM_PROMPT aliases SettingsViewModel: - Remove 33 per-provider StateFlows (dead code) - Remove 33 per-provider change handlers (use generic functions) - Consolidate 30+ individual AI collector coroutines into 2 combine() groups - Remove fragile delay(100) workaround in onAiProviderChange AiPreferencesScreen: - Extract reusable CollapsibleCard composable (~80 lines eliminated) - Add remember() caching in ModelSelectionCard (valueOf + models list) - Fix contextTextInput desync with remember(maxSongsForContext) Other: - Add missing import kotlinx.coroutines.flow.first - Add missing import androidx.compose.ui.res.stringResource - Add AI_CONTEXT branch in ModuleSchemaValidator when expression
…iewModel references
… setters, compress error handlers
… on AdvancedGenerationCard
… bottom UI cutoff
…ds, slim progress bar, robust api key validation
…A/cancel/retry, fix progress bar import - Add 10+ new free models: SmolLM2 1.7B, Qwen 2.5 Coder (0.5B/1.5B/7B/14B), Llama 3.2 3B, Phi-3.5 Mini, Granite 3.0 2B/8B, Mistral Nemo 12B - Enrich ModelStatus with bytesDownloaded, totalBytes, speedBytesPerSec, etaSeconds - Add Pending state for retry/queue scenarios - Rewrite download engine: average speed tracking, cancel via HTTP disconnect + Job, exponential backoff retry (3 attempts), persistent scope surviving navigation - Improve error classification with user-facing messages - Add GGUF magic byte validation, ValidationResult sealed class - Add cancel button to download progress UI with speed/ETA display - Wire statusMap observer for notifications on Ready/Error - Auto-detect and validate installed models on startup - Fix background() unresolved reference in progress bar (add missing import)
…ModelManager, SettingsViewModel - Replace downloadModel().first() with downloadAndWait() in AiSettingsManager (downloadModel no longer returns a Flow) - Add downloadAndWait() suspend function to LocalModelManager (polling-based) - Fix ensureActive() receiver mismatch by replacing with yield() - Add missing LocalModelManager import in SettingsViewModel - Remove unused ensureActive import from LocalModelManager
…ocus controls - AiBehaviorDataCollector: derive skip rates, completion stats, recency from playback stats - UserProfileDigestGenerator: add skip count, genre completion %, recently played section - AiPlaylistGenerator: inject play count (pc) and last-played hour (lh) into candidate JSON - AiPromptTemplateEngine: inject user context (skip rate, energy) and 'avoid skipped songs' instruction - PlaylistCreationDialogs: add Tempo slider (1-5) and Focus on recent toggle - Add 4 string resources for new lab UI controls
… types AiPlaylistGenerator: album, year are non-nullable; genre safe-call reordered AiPromptTemplateEngine: remove year ?: fallback in 3 templates UserProfileDigestGenerator: album is non-nullable String
- baseline-prof.txt: fix AiPlaylistGenerator constructor (add PlaybackStatsRepository) - baseline-prof.txt: remove stale AiMetadataGenerator references (deleted class) - baseline-prof.txt: fix AiStateHolder constructor (remove deleted AiMetadataGenerator param) - Delete dead AiPromptTemplateEngine.kt (unused, never imported) - PlaylistCreationDialogs.kt: remove 6 unused imports
…lls, Elvis operators) - LibraryMediaTabs.kt, LibrarySongsTab.kt: remove redundant smart-casts - AccountsViewModel.kt: remove unnecessary type casts on combined states - GenreDetailViewModel.kt: remove Elvis ?: on non-nullable artist/album fields - PlaybackStateHolder.kt: remove unnecessary safe call on non-null Song - CastTransferStateHolder.kt: remove unnecessary safe call on non-null HttpURLConnection - ConnectivityStateHolder.kt: remove unnecessary safe call on non-null String - RoundedParallaxCarousell.kt: remove redundant .toFloat() on Float width/height
…DisplaySections
The previous edit accidentally removed the grouped.map { (artist, artistSongs) ->
lambda that wraps the albums construction for the ARTIST sort option.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PixelPlayer AI System
Overview
Complete AI infrastructure for PixelPlayer — multi-provider cloud inference, on-device local models with download management, usage analytics, and a dedicated settings UI.
~4,500 lines of new code, ~1,900 lines removed through refactoring.
Cloud Provider System
11 providers supported through a unified client interface:
GenericOpenAiClient/v1/chat/completionsGeminiAiClientAnthropicAiClientArchitecture Components
AiClientFactoryAiProviderEndpointsAiProviderSupportisRateLimit,isBillingIssue,isApiKeyIssue), provider fallback chain, request wrappingAiHandlerAiSettingsManagersuspend fun set(block:)— replaced 20 individual setters/v1/modelsRefactoring Highlights
GenericOpenAiClientLocal Model System
40+ downloadable models — all ≤16B params, free, no authentication required.
Model Tiers
Sources:
TheBloke/andQwen/HuggingFace repos only — no login or license acceptance required.Download Engine (
LocalModelManager)CoroutineScope— downloads survive screen navigationRangeheaderValidationResultsealed class (Ok/Missing/SizeMismatch/Corrupted)UI —
AiPreferencesScreenFull-featured settings screen with:
Provider Configuration
AiProvider.models)Generation Parameters
Model Management
Integration
SettingsCategoryScreenupdated with AI categoryNotifications (
AiNotificationManager)Notification Channels
Features
BigTextStylefor full message visibilityDatabase
Migration: v41 → v42
New entity:
ApiCallRecordAnalytics Queries
AiUsageDaostreamlined with provider-based queriesError Handling (
AiErrorHandler)Automatic Classification
Fallback Strategy
AiLoggerAiProviderExceptionsealed hierarchy for type-safe handlingSupporting Infrastructure
AiDeviceCapabilitiesAiPromptTemplateEnginejsonArrayOutputhelperAiSystemPromptEngineAiCacheManagerAiBehaviorDataCollectorRefactoring Summary
Key Changes
GenericOpenAiClientAiSettingsManagersettersset()methodAiLoggermethodslog(vararg)GeminiModelService, deprecatedAiMetadataSheetAiOrchestratorAiHandlerLocalMlManagerLocalModelManagerStateFlowsinSettingsViewModelLine Count
Breaking Changes
https://ollama.ai/api/v1LocalMlManagerrenamedLocalModelManagerAiOrchestratorrenamedAiHandlerModelFormatenum requires explicit extension parameterFiles Changed
Added (Key Files)
data/ai/AiHandlerAiSettingsManagerAiDeviceCapabilitiesAiErrorHandlerAiCacheManagerAiLoggerAiPromptTemplateEngineAiSystemPromptEngineAiNotificationManagerAiBehaviorDataCollectorHuggingFaceClientOllamaClientAiUsageAnalyticsdata/ai/provider/AiProviderAiProviderEndpointsAiClientFactoryGenericOpenAiClientGeminiAiClientAnthropicAiClientAiProviderSupportdata/ai/local/LocalModelConfigLocalModelManagerdata/database/ApiCallRecordpresentation/AiPreferencesScreenModified
SettingsViewModel.ktSettingsCategoryScreen.ktAiPreferencesRepository.ktAiUsageDao.ktDatabase.ktArchitecture Diagram