AiProvider

interface AiProvider(source)

A cloud (or on-device) chat-completion backend — one turn in, one text reply out.

Inheritors

Properties

Link copied to clipboard
abstract val displayName: String
Link copied to clipboard
abstract val id: String

Functions

Link copied to clipboard
open suspend fun capabilities(): AiCapabilities

Honest self-report for a capability-aware caller: whether this backend genuinely streams tokens and accepts images, which AiConfig fields it actually reads, and — when it can't run — the real AiFailure reason instead of a bare false. Default answer is conservative (no streaming, no honored config) and blames a missing key, matching every real provider's own isAvailable gate; a provider whose unavailability means something else overrides this.

Link copied to clipboard
abstract suspend fun complete(messages: List<AiMessage>, config: AiConfig = AiConfig()): AiResult<String>

Runs one turn. Success carries the model's text; failure names why via AiFailure — a wrong/missing key, a rate limit, a timeout, any other transport problem, or a reply that came back empty. Never throws for an ordinary provider-side failure.

Link copied to clipboard
suspend fun AiProvider.completeOrBlank(messages: List<AiMessage>, config: AiConfig = AiConfig()): String

Bridge for callers not yet migrated off the pre-AiResult complete(): collapses every AiFailure back to "", matching the old runCatching { }.getOrElse { "" } behavior.

Link copied to clipboard
open fun completeStream(messages: List<AiMessage>, config: AiConfig = AiConfig()): Flow<AiChunk>

Token-by-token variant of complete — so a UI can render the reply as it arrives and a Stop action actually cancels the in-flight request (cancelling the collecting coroutine tears down the underlying HTTP call) instead of leaving it running to completion in the background.

Link copied to clipboard
abstract suspend fun isAvailable(): Boolean