Skip to content

Fastest and only macOS Dictation app with on-device STT and custom trained AI enhancement model. Windows, iOS testflight! Android, Linux waitlist open! A local Wispr Flow alternative. Follow https://x.com/fluidvoiceapp for more

fix(private-ai): keep model card state in sync with runtime

altic-dev1fbd1ec9b3b4
diff --git a/Sources/Fluid/Services/PrivateAIIdleUnloader.swift b/Sources/Fluid/Services/PrivateAIIdleUnloader.swift
index 184a0dfe..06f5a254 100644
--- a/Sources/Fluid/Services/PrivateAIIdleUnloader.swift
+++ b/Sources/Fluid/Services/PrivateAIIdleUnloader.swift
@@ -9,14 +9,17 @@ actor PrivateAIIdleUnloader {
private let delay: @Sendable () async -> Duration?
private let isBusy: @Sendable () async -> Bool
private let unload: @Sendable () async -> Void
+ private let activityEnded: @Sendable () async -> Void
private var inFlight = 0
private var pending: Task<Void, Never>?
init(
delay: @escaping @Sendable () async -> Duration?,
isBusy: @escaping @Sendable () async -> Bool,
- unload: @escaping @Sendable () async -> Void
+ unload: @escaping @Sendable () async -> Void,
+ activityEnded: @escaping @Sendable () async -> Void = {}
) {
+ self.activityEnded = activityEnded
self.delay = delay
self.isBusy = isBusy
self.unload = unload
@@ -32,6 +35,7 @@ actor PrivateAIIdleUnloader {
self.inFlight = max(0, self.inFlight - 1)
guard self.inFlight == 0 else { return }
self.schedule()
+ Task { [activityEnded] in await activityEnded() }
}
/// Runs `work` as model activity: the countdown restarts when it finishes.
diff --git a/Sources/Fluid/Services/PrivateAIIntegrationService.swift b/Sources/Fluid/Services/PrivateAIIntegrationService.swift
index 7631a513..b60f4cb8 100644
--- a/Sources/Fluid/Services/PrivateAIIntegrationService.swift
+++ b/Sources/Fluid/Services/PrivateAIIntegrationService.swift
@@ -242,9 +242,20 @@ actor PrivateAIIntegrationService {
nonisolated static let idleUnloader = PrivateAIIdleUnloader(
delay: { await MainActor.run { SettingsStore.shared.privateAIIdleUnloadDelay } },
isBusy: { await MainActor.run { AppServices.shared.asr.isRunningOrStarting } },
- unload: { await PrivateAIIntegrationService.shared.unloadCachedRuntime(reason: "idle") }
+ unload: { await PrivateAIIntegrationService.shared.unloadCachedRuntime(reason: "idle") },
+ activityEnded: { await PrivateAIIntegrationService.postRuntimeDidChange() }
)
+ /// Posted whenever the model may have entered or left memory, so Settings can show
+ /// "Active" for exactly as long as the model is loaded.
+ nonisolated static let runtimeDidChangeNotification = Notification.Name("PrivateAIRuntimeDidChange")
+
+ nonisolated static func postRuntimeDidChange() async {
+ await MainActor.run {
+ NotificationCenter.default.post(name: Self.runtimeDidChangeNotification, object: nil)
+ }
+ }
+
func loadModel(_ model: PrivateAIRegisteredModel) async throws -> PrivateAIStatus {
let status = try await Self.idleUnloader.tracking { try await Self.provider.loadModel(model) }
guard status.state == .ready else { return status }
@@ -285,6 +296,7 @@ actor PrivateAIIntegrationService {
func unloadCachedRuntime(reason: String = "manual") async {
await Self.provider.unloadCachedRuntime(reason: reason)
+ await Self.postRuntimeDidChange()
}
func shutdownForTermination() async {
diff --git a/Sources/Fluid/UI/AISettings/FluidIntelligenceLiveSection.swift b/Sources/Fluid/UI/AISettings/FluidIntelligenceLiveSection.swift
index 2fd00108..04bb3b3b 100644
--- a/Sources/Fluid/UI/AISettings/FluidIntelligenceLiveSection.swift
+++ b/Sources/Fluid/UI/AISettings/FluidIntelligenceLiveSection.swift
@@ -116,7 +116,10 @@ struct FluidIntelligenceLiveSection<Management: View>: View {
private func cardControls(_ model: PrivateAIRegisteredModel) -> some View {
let files = self.snapshots[model.id]
let selected = model.id == self.controller.privateAISelectedModelID
- let active = selected && self.isVerified && self.controller.privateAILoadState.isLoaded(model.id)
+ // Active = dictation will use this model. Whether it is in memory right now is shown
+ // separately, because the idle unloader frees it and the next dictation reloads it.
+ let active = selected && self.isVerified && self.controller.routesDictationThroughPrivateAI
+ let inMemory = self.controller.privateAILoadState.isLoaded(model.id)
let realUpdate = files?.installed == true && self.controller.privateAIModelUpdateStatusByID[model.id]?.state == .updateAvailable
return VStack(alignment: .leading, spacing: 8) {
Divider().overlay(self.theme.palette.cardBorder)
@@ -127,6 +130,10 @@ struct FluidIntelligenceLiveSection<Management: View>: View {
Text("Preparing model…").font(self.theme.typography.caption)
} else if let failure = self.controller.privateAILoadState.failureMessage(for: model.id) {
Text(failure).font(self.theme.typography.caption).foregroundStyle(.red).lineLimit(2).help(failure)
+ } else if active {
+ Text(inMemory ? "In memory" : "Not in memory · loads when you dictate")
+ .font(self.theme.typography.caption)
+ .foregroundStyle(self.theme.palette.secondaryText)
}
HStack(spacing: 8) {
if active {
@@ -176,7 +183,7 @@ struct FluidIntelligenceLiveSection<Management: View>: View {
Button("Deactivate model") {
self.controller.deactivateSelectedModel()
}
- .disabled(!selected || !self.controller.routesDictationThroughPrivateAI || self.controller.isBusy)
+ .disabled(!active || self.controller.isBusy)
if !selected {
Text("Activate this model to manage it")
}
diff --git a/Sources/Fluid/UI/AISettings/PrivateAISettingsController.swift b/Sources/Fluid/UI/AISettings/PrivateAISettingsController.swift
index 9825767d..963a9cba 100644
--- a/Sources/Fluid/UI/AISettings/PrivateAISettingsController.swift
+++ b/Sources/Fluid/UI/AISettings/PrivateAISettingsController.swift
@@ -59,11 +59,21 @@ final class PrivateAISettingsController: ObservableObject {
var previewModelID: String { self.session.previewModelID }
var isBusy: Bool { self.session.isBusy || self.viewModel.isTestingConnection }
@Published var privateAILoadState: PrivateAIModelLoadState = .idle
+ private var runtimeObserver: NSObjectProtocol?
@Published var privateAIModelUpdateStatusByID: [String: PrivateAIModelUpdateStatus] = [:]
init(viewModel: AIEnhancementSettingsViewModel) {
self.viewModel = viewModel
self.session = PrivateAISettingsSession(selectedModelID: PrivateAIIntegrationService.configuredModelID)
+ self.runtimeObserver = NotificationCenter.default.addObserver(
+ forName: PrivateAIIntegrationService.runtimeDidChangeNotification, object: nil, queue: .main
+ ) { [weak self] _ in
+ MainActor.assumeIsolated { self?.refreshPrivateAILoadState() }
+ }
+ }
+
+ deinit {
+ if let runtimeObserver { NotificationCenter.default.removeObserver(runtimeObserver) }
}
/// Carousel arrows/dots call this; no defaults, provider, or runtime writes.