InjectableNativeLlm

Generic delegate-or-degrade injection seam, same shape as Doori's InjectableDocumentAiAnalyzer/ InjectableTextGenerator — kept in commonMain (not iosMain) so this logic is unit-testable; the iosMain holder (FoundationModelsBridge) has nothing left to test once it just forwards here.

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard

Set once at app startup (e.g. from AppDelegate) by the platform bridge — see ai/ios-bridge/README.md.

Functions

Link copied to clipboard
open suspend override fun generate(prompt: String): String?

Null means "declined" — unavailable, or a runtime failure — never throws. Matches OnDeviceLlm.generate's no-throw contract, and keeps a Swift implementation from having to propagate a native error across the interop boundary.

Link copied to clipboard

Streams prompt token-by-token through callback — real per-token output (Apple's LanguageModelSession.streamResponse), not a single-emission replay of generate. Returns a NativeLlmCancelHandle the Kotlin side calls when its collecting coroutine is cancelled, so Stop/screen-leave actually halts native generation instead of only stopping the Kotlin side from listening — the same contract MediaPipeOnDeviceLlm's Android backend already honors for its own callbackFlow.

Link copied to clipboard
open override fun isAvailable(): Boolean