AiSettingsState

class AiSettingsState(modelManager: ModelManager, manifest: List<ModelManifestEntry>, onDeviceLlm: OnDeviceLlm, getKey: (ProviderId) -> String?, setKey: (ProviderId, String?) -> Unit, scope: CoroutineScope, consentStore: AiConsentStore = InMemoryAiConsentStore, providerFactory: (ProviderId, String) -> AiProvider? = ::defaultCloudProvider)(source)

State holder behind AiSettingsSection — the ModelManager settings screen the toolkit never shipped one for. Same shape as com.siddharth.kmp.designsystem.ThemeController: a plain class, StateFlow-exposed, testable with fakes in commonTest, bound as a Koin screen-scoped instance by the consuming app.

Provider keys are read/written through getKey/setKey rather than a com.siddharth.kmp.llmchat.SecureKeyStore directly — that type has a different constructor per platform (Android needs a Context), so it can't be built generically in commonMain; the same reason com.siddharth.kmp.llmchat.loadAiProviderConfig takes a plain function instead. Pass keyStore::getKey / keyStore::setKey at the call site.

manifest is caller-supplied because ModelManager itself doesn't expose one (by design — see ModelManifestEntry's KDoc): pass the same list the app gave its ModelManager.

Constructors

Link copied to clipboard
constructor(modelManager: ModelManager, manifest: List<ModelManifestEntry>, onDeviceLlm: OnDeviceLlm, getKey: (ProviderId) -> String?, setKey: (ProviderId, String?) -> Unit, scope: CoroutineScope, consentStore: AiConsentStore = InMemoryAiConsentStore, providerFactory: (ProviderId, String) -> AiProvider? = ::defaultCloudProvider)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Functions

Link copied to clipboard
fun clearProviderKey(providerId: ProviderId)
Link copied to clipboard
fun deleteModel(modelId: String)
Link copied to clipboard
fun pauseDownload(modelId: String)

Cancels an in-flight download. ModelManager.download resumes from the .tmp a cancelled transfer leaves behind (surfaced as com.siddharth.kmp.ai.ModelDownloadState.PARTIALLY_DOWNLOADED), so this is a real pause, not a restart-from-zero — no new cancellation plumbing needed, the manager already tears down its resumable state on any interruption.

Link copied to clipboard
fun selectProvider(providerId: ProviderId)
Link copied to clipboard
fun setAiConsent(consent: Boolean)
Link copied to clipboard
fun setProviderKey(providerId: ProviderId, apiKey: String?)

Saves (or, when apiKey is null/blank, clears) the key for providerId.

Link copied to clipboard
fun startDownload(modelId: String, licenseAcknowledged: Boolean = false)

Starts (or resumes) downloading modelId in this state's own scope. licenseAcknowledged must be true for a model whose OnDeviceModelRow.requiresLicenseAck is true — see ModelManager.download.

Link copied to clipboard
fun testKey(providerId: ProviderId)

Runs one real completion against providerId's saved key and records the typed AiFailure if it fails — so a wrong key reads "unauthorized" here instead of an empty reply three screens later.