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

Add testing in the prompt addition modal

grohith3278437a3eb1dc4
diff --git a/Sources/Fluid/ContentView.swift b/Sources/Fluid/ContentView.swift
index 7cfcc383..83300778 100644
--- a/Sources/Fluid/ContentView.swift
+++ b/Sources/Fluid/ContentView.swift
@@ -1239,7 +1239,7 @@ struct ContentView: View {
// MARK: - Modular AI Processing
- private func processTextWithAI(_ inputText: String) async -> String {
+ private func processTextWithAI(_ inputText: String, overrideSystemPrompt: String? = nil) async -> String {
// CRITICAL FIX: Read current settings from SettingsStore, not stale @State copies
// This ensures AI provider/model changes in AISettingsView take effect immediately
let currentSelectedProviderID = SettingsStore.shared.selectedProviderID
@@ -1299,7 +1299,11 @@ struct ContentView: View {
// Get app context captured at start of recording if available
let appInfo = self.recordingAppInfo ?? self.getCurrentAppInfo()
- let systemPrompt = self.buildSystemPrompt(appInfo: appInfo)
+ let systemPrompt: String = {
+ let override = overrideSystemPrompt?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
+ if !override.isEmpty { return override }
+ return self.buildSystemPrompt(appInfo: appInfo)
+ }()
DebugLogger.shared.debug("Using app context for AI: app=\(appInfo.name), bundleId=\(appInfo.bundleId), title=\(appInfo.windowTitle)", source: "ContentView")
// Check if this is a reasoning model that doesn't support temperature parameter
@@ -1400,6 +1404,31 @@ struct ContentView: View {
return
}
+ // Prompt Test Mode: reroute dictation hotkey output into the prompt editor (no typing/clipboard/history).
+ let promptTest = DictationPromptTestCoordinator.shared
+ if promptTest.isActive {
+ promptTest.lastTranscriptionText = transcribedText
+ promptTest.lastOutputText = ""
+ promptTest.lastError = ""
+
+ guard DictationAIPostProcessingGate.isConfigured() else {
+ promptTest.lastError = "AI post-processing is not configured. Enable AI Enhancement and configure a provider/model (and API key for non-local endpoints)."
+ return
+ }
+
+ promptTest.isProcessing = true
+ self.menuBarManager.setProcessing(true)
+ defer {
+ self.menuBarManager.setProcessing(false)
+ promptTest.isProcessing = false
+ }
+
+ let result = await self.processTextWithAI(transcribedText, overrideSystemPrompt: promptTest.draftPromptText)
+ let finalText = ASRService.applyGAAVFormatting(result)
+ promptTest.lastOutputText = finalText
+ return
+ }
+
// If this was a rewrite recording, process the rewrite instead of typing
if wasRewriteMode {
DebugLogger.shared.info("Processing rewrite with instruction: \(transcribedText)", source: "ContentView")
@@ -1433,20 +1462,7 @@ struct ContentView: View {
var finalText: String
// Check if we should use AI processing
- // IMPORTANT: Derive provider context from SettingsStore so AISettingsView changes take effect immediately.
- let currentProviderID = SettingsStore.shared.selectedProviderID
- let baseURL: String
- if let saved = SettingsStore.shared.savedProviders.first(where: { $0.id == currentProviderID }) {
- baseURL = saved.baseURL
- } else if currentProviderID == "groq" {
- baseURL = "https://api.groq.com/openai/v1"
- } else {
- baseURL = "https://api.openai.com/v1"
- }
- let trimmedBaseURL = baseURL.trimmingCharacters(in: .whitespacesAndNewlines)
- let isLocal = self.isLocalEndpoint(trimmedBaseURL)
- let apiKey = (SettingsStore.shared.getAPIKey(for: currentProviderID) ?? "").trimmingCharacters(in: .whitespacesAndNewlines)
- let shouldUseAI = SettingsStore.shared.enableAIProcessing && (isLocal || !apiKey.isEmpty)
+ let shouldUseAI = DictationAIPostProcessingGate.isConfigured()
if shouldUseAI {
DebugLogger.shared.debug("Routing transcription through AI post-processing", source: "ContentView")
diff --git a/Sources/Fluid/Services/DictationAIPostProcessingGate.swift b/Sources/Fluid/Services/DictationAIPostProcessingGate.swift
new file mode 100644
index 00000000..af2be996
--- /dev/null
+++ b/Sources/Fluid/Services/DictationAIPostProcessingGate.swift
@@ -0,0 +1,54 @@
+import Foundation
+
+/// Shared gating logic for whether dictation AI post-processing is usable/configured.
+enum DictationAIPostProcessingGate {
+ /// Returns true if dictation AI post-processing should be allowed, given current settings.
+ /// - Requires `SettingsStore.shared.enableAIProcessing == true`
+ /// - For Apple Intelligence: requires `AppleIntelligenceService.isAvailable`
+ /// - For other providers: requires a local endpoint OR a non-empty API key
+ static func isConfigured() -> Bool {
+ let settings = SettingsStore.shared
+ guard settings.enableAIProcessing else { return false }
+
+ let providerID = settings.selectedProviderID
+ if providerID == "apple-intelligence" {
+ return AppleIntelligenceService.isAvailable
+ }
+
+ let baseURL = self.baseURL(for: providerID, settings: settings)
+ if self.isLocalEndpoint(baseURL) {
+ return true
+ }
+
+ let apiKey = (settings.getAPIKey(for: providerID) ?? "").trimmingCharacters(in: .whitespacesAndNewlines)
+ return !apiKey.isEmpty
+ }
+
+ static func baseURL(for providerID: String, settings: SettingsStore) -> String {
+ if let saved = settings.savedProviders.first(where: { $0.id == providerID }) {
+ return saved.baseURL.trimmingCharacters(in: .whitespacesAndNewlines)
+ }
+ if providerID == "groq" {
+ return "https://api.groq.com/openai/v1"
+ }
+ return "https://api.openai.com/v1"
+ }
+
+ static func isLocalEndpoint(_ urlString: String) -> Bool {
+ guard let url = URL(string: urlString), let host = url.host else { return false }
+ let hostLower = host.lowercased()
+
+ if hostLower == "localhost" || hostLower == "127.0.0.1" { return true }
+ if hostLower.hasPrefix("127.") || hostLower.hasPrefix("10.") || hostLower.hasPrefix("192.168.") { return true }
+
+ if hostLower.hasPrefix("172.") {
+ let components = hostLower.split(separator: ".")
+ if components.count >= 2, let secondOctet = Int(components[1]), secondOctet >= 16 && secondOctet <= 31 {
+ return true
+ }
+ }
+
+ return false
+ }
+}
+
diff --git a/Sources/Fluid/Services/DictationPromptTestCoordinator.swift b/Sources/Fluid/Services/DictationPromptTestCoordinator.swift
new file mode 100644
index 00000000..e4898342
--- /dev/null
+++ b/Sources/Fluid/Services/DictationPromptTestCoordinator.swift
@@ -0,0 +1,41 @@
+import Combine
+import Foundation
+
+/// Coordinates "Prompt Test Mode" for the dictation prompt editor.
+/// When active, the global dictation hotkey flow is rerouted to populate test output in the modal
+/// instead of typing into other apps.
+@MainActor
+final class DictationPromptTestCoordinator: ObservableObject {
+ static let shared = DictationPromptTestCoordinator()
+
+ @Published private(set) var isActive: Bool = false
+ @Published private(set) var draftPromptText: String = ""
+ @Published var isProcessing: Bool = false
+
+ @Published var lastTranscriptionText: String = ""
+ @Published var lastOutputText: String = ""
+ @Published var lastError: String = ""
+
+ private init() {}
+
+ func activate(draftPromptText: String) {
+ self.isActive = true
+ self.draftPromptText = draftPromptText
+ self.isProcessing = false
+ self.lastTranscriptionText = ""
+ self.lastOutputText = ""
+ self.lastError = ""
+ }
+
+ func deactivate() {
+ self.isActive = false
+ self.draftPromptText = ""
+ self.isProcessing = false
+ }
+
+ func updateDraftPromptText(_ text: String) {
+ guard self.isActive else { return }
+ self.draftPromptText = text
+ }
+}
+
diff --git a/Sources/Fluid/UI/AISettingsView.swift b/Sources/Fluid/UI/AISettingsView.swift
index 3f3fd35e..e4edb126 100644
--- a/Sources/Fluid/UI/AISettingsView.swift
+++ b/Sources/Fluid/UI/AISettingsView.swift
@@ -20,6 +20,7 @@ struct AISettingsView: View {
@EnvironmentObject private var appServices: AppServices
@EnvironmentObject private var menuBarManager: MenuBarManager
@Environment(\.theme) private var theme
+ @ObservedObject private var promptTest = DictationPromptTestCoordinator.shared
private var asr: ASRService { self.appServices.asr }
@@ -1660,7 +1661,120 @@ struct AISettingsView: View {
)
)
.disabled(self.editorIsDefaultPrompt)
+ .onChange(of: self.draftPromptText) { _, newValue in
+ self.promptTest.updateDraftPromptText(newValue)
+ }
+ }
+
+ // MARK: - Test Mode
+ VStack(alignment: .leading, spacing: 8) {
+ HStack(spacing: 8) {
+ Image(systemName: "waveform")
+ .foregroundStyle(self.theme.palette.accent)
+ Text("Test")
+ .font(.subheadline)
+ .fontWeight(.semibold)
+ Spacer()
+ }
+
+ let hotkeyDisplay = SettingsStore.shared.hotkeyShortcut.displayString
+ let canTest = self.isAIPostProcessingConfiguredForDictation()
+
+ Toggle(isOn: Binding(
+ get: { self.promptTest.isActive },
+ set: { enabled in
+ if enabled {
+ self.promptTest.activate(draftPromptText: self.draftPromptText)
+ } else {
+ self.promptTest.deactivate()
+ }
+ }
+ )) {
+ Text("Enable Test Mode (Hotkey: \(hotkeyDisplay))")
+ .font(.caption)
+ }
+ .toggleStyle(.switch)
+ .disabled(!canTest)
+
+ if !canTest {
+ Text("Testing is disabled because AI post-processing is not configured.")
+ .font(.caption2)
+ .foregroundStyle(.secondary)
+ } else if self.promptTest.isActive {
+ Text("Press the hotkey to start/stop recording. The transcription will be post-processed using your draft prompt and shown below (nothing will be typed into other apps).")
+ .font(.caption2)
+ .foregroundStyle(.secondary)
+ }
+
+ if self.promptTest.isActive {
+ if self.promptTest.isProcessing {
+ HStack(spacing: 8) {
+ ProgressView().controlSize(.small)
+ Text("Processing…")
+ .font(.caption)
+ .foregroundStyle(.secondary)
+ }
+ }
+
+ if !self.promptTest.lastError.isEmpty {
+ Text(self.promptTest.lastError)
+ .font(.caption2)
+ .foregroundStyle(.red)
+ .textSelection(.enabled)
+ }
+
+ VStack(alignment: .leading, spacing: 6) {
+ Text("Raw transcription")
+ .font(.caption2)
+ .foregroundStyle(.secondary)
+ TextEditor(text: Binding(
+ get: { self.promptTest.lastTranscriptionText },
+ set: { _ in }
+ ))
+ .font(.system(.caption, design: .monospaced))
+ .frame(minHeight: 70)
+ .scrollContentBackground(.hidden)
+ .background(
+ RoundedRectangle(cornerRadius: 8, style: .continuous)
+ .fill(.ultraThinMaterial.opacity(0.25))
+ .overlay(
+ RoundedRectangle(cornerRadius: 8, style: .continuous)
+ .stroke(.white.opacity(0.12), lineWidth: 1)
+ )
+ )
+ }
+
+ VStack(alignment: .leading, spacing: 6) {
+ Text("Post-processed output")
+ .font(.caption2)
+ .foregroundStyle(.secondary)
+ TextEditor(text: Binding(
+ get: { self.promptTest.lastOutputText },
+ set: { _ in }
+ ))
+ .font(.system(.caption, design: .monospaced))
+ .frame(minHeight: 110)
+ .scrollContentBackground(.hidden)
+ .background(
+ RoundedRectangle(cornerRadius: 8, style: .continuous)
+ .fill(.ultraThinMaterial.opacity(0.25))
+ .overlay(
+ RoundedRectangle(cornerRadius: 8, style: .continuous)
+ .stroke(.white.opacity(0.12), lineWidth: 1)
+ )
+ )
+ }
+ }
}
+ .padding(12)
+ .background(
+ RoundedRectangle(cornerRadius: 12, style: .continuous)
+ .fill(self.theme.palette.accent.opacity(0.06))
+ .overlay(
+ RoundedRectangle(cornerRadius: 12, style: .continuous)
+ .stroke(.white.opacity(0.10), lineWidth: 1)
+ )
+ )
HStack(spacing: 10) {
Button(self.editorIsDefaultPrompt ? "Close" : "Cancel") {
@@ -1679,6 +1793,9 @@ struct AISettingsView: View {
}
.padding()
.frame(minWidth: 520, minHeight: 420)
+ .onDisappear {
+ self.promptTest.deactivate()
+ }
}
private func openDefaultPromptViewer() {
@@ -1711,6 +1828,13 @@ struct AISettingsView: View {
self.editingPromptID = nil
self.draftPromptName = ""
self.draftPromptText = ""
+ self.promptTest.deactivate()
+ }
+
+ // MARK: - Prompt Test Gating
+
+ private func isAIPostProcessingConfiguredForDictation() -> Bool {
+ DictationAIPostProcessingGate.isConfigured()
}
private func savePromptEditor() {