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
Run Edit Mode on its own local model
altic-dev51465d76f706
diff --git a/Sources/Fluid/ContentView.swift b/Sources/Fluid/ContentView.swiftindex b32e6554..2e921d38 100644--- a/Sources/Fluid/ContentView.swift+++ b/Sources/Fluid/ContentView.swift@@ -1211,6 +1211,8 @@ struct ContentView: View {self.navigateToApp(.meetingTranscription)case .preferences:self.openSettings(.general)+ case .cleanupStyles:+ self.navigateToApp(.cleanupStyles)}}@@ -3892,41 +3894,30 @@ struct ContentView: View {self.menuBarManager.finishProcessingKeepingOverlayVisible()}- private func showPrivateAIEditModeUnavailableIfNeeded() -> Bool {- let settings = SettingsStore.shared- let providerID = settings.rewriteModeLinkedToGlobal- ? settings.selectedProviderID- : settings.rewriteModeSelectedProviderID- guard PrivateFeatures.privateAIProvider,- providerID.trimmingCharacters(in: .whitespacesAndNewlines) ==- PrivateAIProviderFeature.shared.providerID- else {- return false- }-- guard !self.asr.isRunningOrStarting,- !NotchContentState.shared.isProcessing- else {- return true- }-+ /// Shows why Edit Mode can't run, for a few seconds. A missing model only happens+ /// when Edit Mode is set to run on this Mac, so only then is there a Download button.+ private func showEditModeFailure(_ message: String) {+ let needsModel = message == EditModeRoute.modelMissing.failureMessageself.menuBarManager.setOverlayMode(.edit)self.advanceOverlayLifecycle()let expectedOverlayLifecycleID = self.overlayLifecycleIDself.menuBarManager.showRecordingOverlayImmediately()NotchContentState.shared.showAIProcessingFailure(- message: "Edit Mode cannot be used with Fluid-1",- canRetry: false+ message: message,+ canRetry: false,+ downloadAction: needsModel ? {+ EditModeModelController.shared.download()+ self.menuBarManager.openCleanupStyles()+ } : nil)self.menuBarManager.finishProcessingKeepingOverlayVisible()Task { @MainActor in- try? await Task.sleep(nanoseconds: 6_000_000_000)+ try? await Task.sleep(for: .seconds(needsModel ? 10 : 6))guard self.overlayLifecycleID == expectedOverlayLifecycleID else { return }NotchContentState.shared.clearAIProcessingFailure()await self.menuBarManager.finishProcessingAndHideOverlay()}- return true}private func advanceOverlayLifecycle() {@@ -4621,8 +4612,12 @@ struct ContentView: View {self.rewriteModeService.clearState()self.hideOverlayAfterOutput()} else {- await self.menuBarManager.finishProcessingAndHideOverlay()DebugLogger.shared.error("Rewrite failed - no result", source: "ContentView")+ if let message = self.rewriteModeService.lastErrorMessage {+ self.showEditModeFailure(message)+ } else {+ await self.menuBarManager.finishProcessingAndHideOverlay()+ }}}@@ -5031,6 +5026,22 @@ struct ContentView: View {private func beginRewriteRecording() async {guard self.canBeginDictationRecording() else { return }+ let editProviderID = SettingsStore.shared.effectiveRewriteModeProviderID+ let editRoute = await Task.detached(priority: .userInitiated) {+ EditModeRoute.current(providerID: editProviderID)+ }.value+ // The check above left the main thread, so what it allowed may have changed.+ guard self.canBeginDictationRecording() else { return }+ if let message = editRoute.failureMessage {+ // A dictation in progress keeps going; only a fresh press has an overlay to use.+ if !self.canSwitchActiveDictationCaptureMode { self.showEditModeFailure(message) }+ return+ }+ if case .local = editRoute {+ // Ready by the time the user stops speaking; never delays the recording.+ Task { await PrivateAIIntegrationService.shared.prewarmEdit() }+ }+DictationStopSnapshot.captureStartingContext(reusingCapture: self.canSwitchActiveDictationCaptureMode) {self.captureRecordingContext()}diff --git a/Sources/Fluid/Services/EditModeRoute.swift b/Sources/Fluid/Services/EditModeRoute.swiftnew file mode 100644index 00000000..d812c50a--- /dev/null+++ b/Sources/Fluid/Services/EditModeRoute.swift@@ -0,0 +1,44 @@+import Foundation++/// Where an Edit Mode request runs. The shortcut and the request ask the same+/// question, so they can't disagree about whether the model is there.+enum EditModeRoute: Equatable {+ /// A cloud or custom provider, picked in AI Providers.+ case provider+ case local(PrivateAIRegisteredModel)+ /// Fluid Intelligence is selected, but its Edit Mode model isn't downloaded.+ case modelMissing+ /// Fluid Intelligence is selected, and this build turns its Edit Mode model off.+ case notOffered++ /// Why Edit Mode can't run, or nil when it can.+ var failureMessage: String? {+ switch self {+ case .provider, .local: nil+ case .modelMissing: "Edit Mode needs its model"+ case .notOffered: "Choose an AI provider to use Edit Mode."+ }+ }++ nonisolated static func resolve(+ providerID: String,+ privateProviderID: String?,+ editModel: PrivateAIRegisteredModel?,+ isInstalled: (PrivateAIRegisteredModel) -> Bool+ ) -> EditModeRoute {+ let trimmed = providerID.trimmingCharacters(in: .whitespacesAndNewlines)+ guard let privateProviderID, trimmed == privateProviderID else { return .provider }+ guard let editModel else { return .notOffered }+ return isInstalled(editModel) ? .local(editModel) : .modelMissing+ }++ /// Checks the model folder, so call it off the main thread where it matters.+ nonisolated static func current(providerID: String) -> EditModeRoute {+ self.resolve(+ providerID: providerID,+ privateProviderID: PrivateAIProviderFeature.shared.isAvailable ? PrivateAIProviderFeature.shared.providerID : nil,+ editModel: PrivateAIIntegrationService.editModel,+ isInstalled: { PrivateAIIntegrationService.isModelInstalled($0) }+ )+ }+}diff --git a/Sources/Fluid/Services/MenuBarManager.swift b/Sources/Fluid/Services/MenuBarManager.swiftindex 72cefd77..5fe4fecb 100644--- a/Sources/Fluid/Services/MenuBarManager.swift+++ b/Sources/Fluid/Services/MenuBarManager.swift@@ -8,6 +8,7 @@ enum MenuBarNavigationDestination: String {case settingscase meetingTranscriptioncase preferences+ case cleanupStyles}@MainActor@@ -1518,6 +1519,10 @@ final class MenuBarManager: NSObject, ObservableObject, NSMenuDelegate {self.stopMeetingRecordingHandler?()}+ func openCleanupStyles() {+ self.openNavigationDestination(.cleanupStyles)+ }+private func openNavigationDestination(_ destination: MenuBarNavigationDestination) {self.navigationRequestGeneration &+= 1let requestGeneration = self.navigationRequestGenerationdiff --git a/Sources/Fluid/Services/PrivateAIIntegrationService.swift b/Sources/Fluid/Services/PrivateAIIntegrationService.swiftindex 11078d1d..e34a5241 100644--- a/Sources/Fluid/Services/PrivateAIIntegrationService.swift+++ b/Sources/Fluid/Services/PrivateAIIntegrationService.swift@@ -34,6 +34,8 @@ actor PrivateAIIntegrationService {// Absence means no screen context was read.// swiftlint:disable:next discouraged_optional_collectionvar screenText: [String]? = nil+ /// The text an Edit Mode instruction applies to, when any was selected.+ var selectedText: String? = nil}struct EnhancementResult: Sendable, Equatable {@@ -117,6 +119,11 @@ actor PrivateAIIntegrationService {provider.modelDirectoryURL}+ /// The local model Edit Mode runs on. Dictation's model choice never changes it.+ nonisolated static var editModel: PrivateAIRegisteredModel? {+ PrivateAIModelRegistry.modelIDs(for: .edit).first.flatMap { PrivateAIModelRegistry.model(id: $0) }+ }+nonisolated static func expectedLocalModelURL(for model: PrivateAIRegisteredModel) -> URL {self.provider.expectedLocalModelURL(for: model)}@@ -381,6 +388,11 @@ actor PrivateAIIntegrationService {_ = try? await Self.modelActivity { await Self.provider.prewarmDictation() }}+ func prewarmEdit() async {+ guard !Task.isCancelled, let model = Self.editModel else { return }+ _ = try? await Self.modelActivity(modelID: model.id) { await Self.provider.prewarmEdit() }+ }+func unloadCachedRuntime(reason: String = "manual") async {let token: UUIDdo {@@ -453,7 +465,7 @@ actor PrivateAIIntegrationService {runtime: RuntimeConfiguration,context: AppContext) async throws -> EnhancementResult {- try await Self.modelActivity {+ try await Self.modelActivity(modelID: runtime.model) {try await Self.provider.rewrite(inputText,systemPrompt: systemPrompt,diff --git a/Sources/Fluid/Services/PrivateAIProvider.swift b/Sources/Fluid/Services/PrivateAIProvider.swiftindex ea626372..397d90ee 100644--- a/Sources/Fluid/Services/PrivateAIProvider.swift+++ b/Sources/Fluid/Services/PrivateAIProvider.swift@@ -266,6 +266,8 @@ protocol PrivateAIIntegrationProviding: Sendable {func prewarmDictation() asyncfunc unloadCachedRuntime(reason: String) asyncfunc shutdownForTermination() async+ /// Loads the Edit Mode model ahead of its first request.+ func prewarmEdit() asyncnonisolated func enhanceDictation(_ inputText: String,runtime: PrivateAIIntegrationService.RuntimeConfiguration,@@ -351,6 +353,8 @@ extension PrivateAIIntegrationProviding {await self.unloadCachedRuntime(reason: "termination")}+ func prewarmEdit() async {}+nonisolated func enhanceDictation(_ inputText: String,runtime: PrivateAIIntegrationService.RuntimeConfiguration,diff --git a/Sources/Fluid/Services/RewriteModeService.swift b/Sources/Fluid/Services/RewriteModeService.swiftindex 8f19b4e0..8ff3f798 100644--- a/Sources/Fluid/Services/RewriteModeService.swift+++ b/Sources/Fluid/Services/RewriteModeService.swift@@ -11,6 +11,8 @@ final class RewriteModeService: ObservableObject {@Published var streamingThinkingText: String = "" // Real-time thinking tokens for UI@Published var isProcessing = false@Published var conversationHistory: [Message] = []+ /// Why the last request produced nothing, for the overlay to show.+ @Published private(set) var lastErrorMessage: String?@Published var isWriteMode: Bool = false // true = no text selected (write/improve), false = text selected (rewrite)private var promptAppBundleID: String?@@ -89,6 +91,7 @@ final class RewriteModeService: ObservableObject {defer { MeetingSummaryActivityCoordinator.shared.endProcessing(summaryActivity) }let startTime = Date()+ self.lastErrorMessage = nilAnalyticsService.shared.recordUsage(mode: .edit,aiModel: SettingsStore.shared.analyticsAIModelDescriptor(for: .edit)@@ -135,7 +138,7 @@ final class RewriteModeService: ObservableObject {self.isProcessing = truedo {- let response = try await callLLM(messages: conversationHistory, isWriteMode: isWriteMode)+ let response = try await callLLM(messages: conversationHistory, isWriteMode: isWriteMode, instruction: prompt)self.conversationHistory.append(Message(role: .assistant, content: response))self.rewrittenText = responseself.isProcessing = false@@ -145,6 +148,7 @@ final class RewriteModeService: ObservableObject {} catch {self.conversationHistory.append(Message(role: .assistant, content: "Error: \(error.localizedDescription)"))+ self.lastErrorMessage = error.localizedDescriptionself.isProcessing = falseself.appendDiagnosticLog("processRewriteRequest failure | writeMode=\(self.isWriteMode) | error=\(error.localizedDescription)"@@ -186,6 +190,7 @@ final class RewriteModeService: ObservableObject {self.isWriteMode = falseself.thinkingBuffer = []self.promptAppBundleID = nil+ self.lastErrorMessage = nil}func setPromptAppBundleID(_ bundleID: String?) {@@ -195,7 +200,7 @@ final class RewriteModeService: ObservableObject {// MARK: - LLM Integration- private func callLLM(messages: [Message], isWriteMode: Bool) async throws -> String {+ private func callLLM(messages: [Message], isWriteMode: Bool, instruction: String) async throws -> String {let settings = SettingsStore.sharedlet promptMode: SettingsStore.PromptMode = .editlet appBundleID = self.promptAppBundleID@@ -266,18 +271,18 @@ final class RewriteModeService: ObservableObject {var runtimeModel = modelvar localModelPath = PrivateAIIntegrationService.configuredLocalModelPathif usesPrivateAIProvider {- guard let verifiedModelID = PrivateAIProviderPromptFormat.verifiedModelID(for: model, settings: settings),- let verifiedModel = PrivateAIModelRegistry.model(id: verifiedModelID),- let verifiedModelPath = PrivateAIIntegrationService.localModelPath(for: verifiedModel)+ let route = EditModeRoute.current(providerID: providerID)+ guard case let .local(editModel) = route,+ let editModelPath = PrivateAIIntegrationService.localModelPath(for: editModel)else {throw NSError(domain: "RewriteMode",code: -5,- userInfo: [NSLocalizedDescriptionKey: "Selected Fluid-1 model is not installed and verified"]+ userInfo: [NSLocalizedDescriptionKey: route.failureMessage ?? EditModeRoute.modelMissing.failureMessage ?? ""])}- runtimeModel = verifiedModelID- localModelPath = verifiedModelPath+ runtimeModel = editModel.id+ localModelPath = editModelPath}self.appendDiagnosticLog("LLM config | writeMode=\(isWriteMode) | linkedToGlobal=\(settings.rewriteModeLinkedToGlobal) | " +@@ -296,12 +301,10 @@ final class RewriteModeService: ObservableObject {}if usesPrivateAIProvider || PrivateAIIntegrationService.shouldHandleDictation(model: model) {- let inputText = messages.map {- let role = $0.role == .user ? "user" : "assistant"- return "[\(role)]\n\($0.content)"- }.joined(separator: "\n\n")+ // A follow-up applies to the last result, not to the original selection.+ let textToEdit = self.rewrittenText.isEmpty ? self.selectedContextText : self.rewrittenTextlet response = try await PrivateAIIntegrationService.shared.rewrite(- inputText,+ instruction,systemPrompt: systemPrompt,runtime: PrivateAIIntegrationService.RuntimeConfiguration(selectedProviderID: providerID,@@ -318,7 +321,8 @@ final class RewriteModeService: ObservableObject {appName: "",bundleID: appBundleID ?? "",windowTitle: "",- appVersion: Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String+ appVersion: Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String,+ selectedText: textToEdit.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty ? nil : textToEdit))return response.outputTextdiff --git a/Sources/Fluid/UI/AISettings/EditModeModelSection.swift b/Sources/Fluid/UI/AISettings/EditModeModelSection.swiftnew file mode 100644index 00000000..324088a7--- /dev/null+++ b/Sources/Fluid/UI/AISettings/EditModeModelSection.swift@@ -0,0 +1,148 @@+import Combine+import SwiftUI++/// Edit Mode picks its own model, apart from dictation's. When that is the model on+/// this Mac, this is also where it downloads: nothing downloads when the shortcut is+/// pressed. API users never see the download.+struct EditModeModelSection<ModelControls: View>: View {+ let showsLocalModel: Bool+ @ViewBuilder let modelControls: () -> ModelControls+ @Environment(\.theme) private var theme+ @ObservedObject private var controller = EditModeModelController.shared++ var body: some View {+ FluidManagementGroup(title: "Edit Mode") {+ self.modelControls()+ if self.showsLocalModel, let model = self.controller.model {+ Divider()+ HStack(spacing: self.theme.metrics.spacing.lg) {+ VStack(alignment: .leading, spacing: self.theme.metrics.spacing.xs) {+ Text(ModelDisplayName.forID(model.id))+ .font(self.theme.typography.bodyStrong)+ .foregroundStyle(self.theme.palette.primaryText)+ self.status(for: model)+ }+ Spacer(minLength: self.theme.metrics.spacing.md)+ self.action(for: model)+ }+ }+ }+ .task { await self.controller.refresh() }+ }++ @ViewBuilder private func status(for model: PrivateAIRegisteredModel) -> some View {+ if self.controller.downloading {+ VStack(alignment: .leading, spacing: self.theme.metrics.spacing.xs) {+ ProgressView(value: self.controller.fraction)+ .frame(maxWidth: 220)+ Text("Downloading · \(Int(self.controller.fraction * 100))%")+ .font(self.theme.typography.caption)+ .foregroundStyle(self.theme.palette.secondaryText)+ .monospacedDigit()+ }+ } else if let error = self.controller.error {+ Text(error)+ .font(self.theme.typography.caption)+ .foregroundStyle(self.theme.palette.warning)+ .fixedSize(horizontal: false, vertical: true)+ } else if self.controller.installed {+ Label("Ready · rewrites selected text on this Mac", systemImage: "checkmark.circle.fill")+ .font(self.theme.typography.caption)+ .foregroundStyle(self.theme.palette.success)+ } else {+ Text("Rewrites selected text when you press the Edit Mode shortcut. Stays on this Mac.")+ .font(self.theme.typography.caption)+ .foregroundStyle(self.theme.palette.secondaryText)+ .fixedSize(horizontal: false, vertical: true)+ }+ }++ @ViewBuilder private func action(for model: PrivateAIRegisteredModel) -> some View {+ if self.controller.downloading {+ Button("Cancel") { self.controller.cancelDownload() }+ .fluidGlassAction()+ } else if self.controller.installed {+ Button("Remove") { self.controller.remove() }+ .fluidGlassAction()+ .disabled(self.controller.removing)+ } else {+ Button(self.downloadTitle(for: model)) { self.controller.download() }+ .fluidGlassAction(prominent: true)+ }+ }++ private func downloadTitle(for model: PrivateAIRegisteredModel) -> String {+ guard let bytes = model.artifact.byteCount else { return "Download" }+ return "Download · \(ByteCountFormatter.string(fromByteCount: bytes, countStyle: .file))"+ }+}++@MainActor+final class EditModeModelController: ObservableObject {+ static let shared = EditModeModelController()++ let model = CPUArchitecture.isAppleSilicon && PrivateAIProviderFeature.shared.isAvailable+ ? PrivateAIIntegrationService.editModel+ : nil+ @Published private(set) var installed = false+ @Published private(set) var downloading = false+ @Published private(set) var removing = false+ @Published private(set) var fraction = 0.0+ @Published private(set) var error: String?+ private var operation: Task<Void, Never>?++ func refresh() async {+ guard let model else { return }+ self.installed = await Task.detached(priority: .utility) {+ PrivateAIIntegrationService.isModelInstalled(model, useCache: false)+ }.value+ }++ func download() {+ guard let model, !self.downloading else { return }+ self.downloading = true+ self.fraction = 0+ self.error = nil+ self.operation = Task { [weak self] in+ defer {+ self?.downloading = false+ self?.operation = nil+ }+ do {+ _ = try await PrivateAIIntegrationService.prepareModel(model) { [weak self] progress in+ guard let expected = progress.totalBytesExpected, expected > 0 else { return }+ let fraction = min(1, Double(progress.totalBytesWritten) / Double(expected))+ await self?.receive(fraction: fraction)+ }+ await self?.refresh()+ } catch is CancellationError {+ self?.error = nil+ } catch {+ self?.error = Task.isCancelled ? nil : error.localizedDescription+ }+ }+ }++ func cancelDownload() {+ self.operation?.cancel()+ }++ func remove() {+ guard let model, !self.removing else { return }+ self.removing = true+ self.error = nil+ Task { [weak self] in+ defer { self?.removing = false }+ do {+ try await PrivateAIIntegrationService.shared.unloadAndRemoveInstalledModel(model, reason: "Edit Mode model removed")+ } catch {+ self?.error = error.localizedDescription+ }+ await self?.refresh()+ }+ }++ private func receive(fraction: Double) {+ self.fraction = fraction+ }+}diff --git a/Sources/Fluid/UI/AISettingsView+AIConfiguration.swift b/Sources/Fluid/UI/AISettingsView+AIConfiguration.swiftindex b5f3400f..0616616d 100644--- a/Sources/Fluid/UI/AISettingsView+AIConfiguration.swift+++ b/Sources/Fluid/UI/AISettingsView+AIConfiguration.swift@@ -1852,7 +1852,10 @@ extension AIEnhancementSettingsView {}var promptsStepContent: some View {- self.advancedSettingsCard+ VStack(alignment: .leading, spacing: FluidPageLayout.sectionSpacing) {+ self.editModeSection+ self.advancedSettingsCard+ }}var builtInProvidersList: [(id: String, name: String)] {diff --git a/Sources/Fluid/UI/AISettingsView+AdvancedSettings.swift b/Sources/Fluid/UI/AISettingsView+AdvancedSettings.swiftindex d49390d0..1e9c99ba 100644--- a/Sources/Fluid/UI/AISettingsView+AdvancedSettings.swift+++ b/Sources/Fluid/UI/AISettingsView+AdvancedSettings.swift@@ -1325,6 +1325,12 @@ extension AIEnhancementSettingsView {)}+ var editModeSection: some View {+ EditModeModelSection(showsLocalModel: self.isPrivateAIProviderID(self.activeEditModeProviderID)) {+ self.editModeInlineModelControls+ }+ }+private var editModeInlineModelControls: some View {let verified = self.editModeVerifiedProviders@@ -1347,7 +1353,7 @@ extension AIEnhancementSettingsView {let providerID = self.activeEditModeProviderIDlet models = self.editModeModels(for: providerID)Group {- Toggle("Sync", isOn: self.editModeLinkedToGlobalBinding)+ Toggle("Same as dictation", isOn: self.editModeLinkedToGlobalBinding).toggleStyle(.checkbox).font(.fluidSystem(.caption)).foregroundStyle(.secondary)@@ -1583,7 +1589,14 @@ extension AIEnhancementSettingsView {}private var editModeVerifiedProviders: [AIEnhancementSettingsViewModel.ProviderItemData] {- self.viewModel.cachedVerifiedProviderItems+ var providers = self.viewModel.cachedVerifiedProviderItems+ // The on-device Edit Mode model has its own download, so choosing it never+ // depends on dictation having verified a model.+ let feature = PrivateAIProviderFeature.shared+ if EditModeModelController.shared.model != nil, !providers.contains(where: { $0.id == feature.providerID }) {+ providers.append(.init(id: feature.providerID, name: feature.providerName, isBuiltIn: true))+ }+ return providers.sorted { lhs, rhs inlhs.name.localizedCaseInsensitiveCompare(rhs.name) == .orderedAscending}diff --git a/Sources/Fluid/Views/BottomOverlayView.swift b/Sources/Fluid/Views/BottomOverlayView.swiftindex c06045e0..e4bb18f3 100644--- a/Sources/Fluid/Views/BottomOverlayView.swift+++ b/Sources/Fluid/Views/BottomOverlayView.swift@@ -3319,6 +3319,17 @@ struct BottomOverlayView: View {}}+ if let download = self.contentState.aiProcessingFailureDownloadAction {+ Button("Download") {+ self.contentState.clearAIProcessingFailure()+ NotchOverlayManager.shared.hide()+ download()+ }+ .font(.fluidSystem(size: self.layout.transFontSize, weight: .bold))+ .foregroundStyle(Color.white.opacity(0.9))+ .buttonStyle(.plain)+ }+self.failureIconButton(systemName: "xmark", help: "Dismiss") {self.contentState.clearAIProcessingFailure()NotchOverlayManager.shared.hide()diff --git a/Sources/Fluid/Views/NotchContentViews.swift b/Sources/Fluid/Views/NotchContentViews.swiftindex 95e07fae..60ce4ec2 100644--- a/Sources/Fluid/Views/NotchContentViews.swift+++ b/Sources/Fluid/Views/NotchContentViews.swift@@ -105,6 +105,8 @@ class NotchContentState: ObservableObject {@Published var isAIProcessingFailureVisible: Bool = false@Published private(set) var aiProcessingFailureMessage: String = "AI Enhancement failed"@Published private(set) var canRetryAIProcessingFailure: Bool = true+ /// Set only while a model download would fix the failure on screen.+ @Published private(set) var aiProcessingFailureDownloadAction: (() -> Void)?@Published private(set) var spokenSendIndicatorState: SpokenSendIndicatorState = .hidden@Published private(set) var spokenSendCountdownID: UInt64 = 0@Published var isTextDeliveryFailureVisible: Bool = false@@ -197,15 +199,18 @@ class NotchContentState: ObservableObject {func showAIProcessingFailure(message: String = "AI Enhancement failed",- canRetry: Bool = true+ canRetry: Bool = true,+ downloadAction: (() -> Void)? = nil) {self.aiProcessingFailureMessage = messageself.canRetryAIProcessingFailure = canRetry+ self.aiProcessingFailureDownloadAction = downloadActionself.isAIProcessingFailureVisible = true}func clearAIProcessingFailure() {self.isAIProcessingFailureVisible = false+ self.aiProcessingFailureDownloadAction = nil}func setSpokenSendIndicatorState(_ state: SpokenSendIndicatorState) {@@ -1148,6 +1153,16 @@ struct NotchExpandedView: View {.help("Try again")}+ if let download = self.contentState.aiProcessingFailureDownloadAction {+ Button("Download") {+ self.contentState.clearAIProcessingFailure()+ NotchOverlayManager.shared.hide()+ download()+ }+ .font(.fluidSystem(size: 10, weight: .bold))+ .buttonStyle(.plain)+ }+Button {self.contentState.clearAIProcessingFailure()NotchOverlayManager.shared.hide()diff --git a/Tests/FluidDictationIntegrationTests/EditModeRouteTests.swift b/Tests/FluidDictationIntegrationTests/EditModeRouteTests.swiftnew file mode 100644index 00000000..652b17cd--- /dev/null+++ b/Tests/FluidDictationIntegrationTests/EditModeRouteTests.swift@@ -0,0 +1,98 @@+import Foundation+import XCTest++@testable import FluidVoice_Debug++final class EditModeRouteTests: XCTestCase {+ private let model = PrivateAIRegisteredModel(+ displayName: "Edit",+ detail: "",+ isEnabled: true,+ parameterCount: "",+ recommendedMemoryGB: nil,+ artifact: PrivateAIModelArtifact(identifier: "edit-model", filename: "edit-model")+ )++ func testCloudProviderKeepsItsRouteWhateverIsInstalled() {+ for installed in [true, false] {+ let route = EditModeRoute.resolve(+ providerID: "openai",+ privateProviderID: "fluid-1",+ editModel: self.model,+ isInstalled: { _ in installed }+ )+ XCTAssertEqual(route, .provider)+ }+ }++ func testBuildWithoutThePrivateProviderAlwaysUsesTheProvider() {+ let route = EditModeRoute.resolve(+ providerID: "fluid-1",+ privateProviderID: nil,+ editModel: nil,+ isInstalled: { _ in false }+ )+ XCTAssertEqual(route, .provider)+ }++ func testLocalProviderRunsOnTheInstalledEditModel() {+ let route = EditModeRoute.resolve(+ providerID: " fluid-1 ",+ privateProviderID: "fluid-1",+ editModel: self.model,+ isInstalled: { _ in true }+ )+ XCTAssertEqual(route, .local(self.model))+ }++ func testLocalProviderAsksForTheDownloadInsteadOfFetchingIt() {+ var checked = 0+ let route = EditModeRoute.resolve(+ providerID: "fluid-1",+ privateProviderID: "fluid-1",+ editModel: self.model,+ isInstalled: { _ in+ checked += 1+ return false+ }+ )+ XCTAssertEqual(route, .modelMissing)+ XCTAssertEqual(checked, 1)+ }++ func testLocalProviderWithTheModelTurnedOffPointsElsewhere() {+ let route = EditModeRoute.resolve(+ providerID: "fluid-1",+ privateProviderID: "fluid-1",+ editModel: nil,+ isInstalled: { _ in true }+ )+ XCTAssertEqual(route, .notOffered)+ XCTAssertEqual(route.failureMessage, "Choose an AI provider to use Edit Mode.")+ }++ @MainActor+ func testDownloadButtonOnlyLastsForItsOwnFailure() {+ let state = NotchContentState.shared+ defer {+ state.showAIProcessingFailure()+ state.clearAIProcessingFailure()+ }++ state.showAIProcessingFailure(message: "needs model", canRetry: false, downloadAction: {})+ XCTAssertNotNil(state.aiProcessingFailureDownloadAction)++ state.showAIProcessingFailure(message: "other failure", canRetry: false)+ XCTAssertNil(state.aiProcessingFailureDownloadAction)++ state.showAIProcessingFailure(message: "needs model", canRetry: false, downloadAction: {})+ state.clearAIProcessingFailure()+ XCTAssertNil(state.aiProcessingFailureDownloadAction)+ }++ func testOnlyFailuresHaveAMessage() {+ XCTAssertNil(EditModeRoute.provider.failureMessage)+ XCTAssertNil(EditModeRoute.local(self.model).failureMessage)+ XCTAssertNotNil(EditModeRoute.modelMissing.failureMessage)+ }+}