Files
OSGKeyboard/OSGKeyboardShared/Services/TranscriptionPolishFallback.swift
T
Rocky 3de665d254 feat(keyboard): ship AI mode surface with streaming search answers
Add the AI keyboard tab, Agent settings, and user-owned LLM key path for 1.7.0, including streaming answers and web-search transports without the built-in DeepSeek fallback.
2026-08-11 01:06:27 +08:00

45 lines
1.4 KiB
Swift

// TranscriptionPolishFallback.swift
// OSGKeyboard · Shared
//
// Shared polish-failure handling: conservative raw ASR cleanup plus
// bilingual user-visible warnings (iOS Flow + macOS dictation).
import Foundation
public enum TranscriptionPolishFallback: Sendable {
public static func makeDelivery(
rawText: String,
error: Error,
engineMode: String,
chunkWarning: String?
) -> TranscriptionDelivery {
let fallbackText = TranscriptPostProcessor.cleanRawASRFallback(rawText)
let warning = warning(for: error, engineMode: engineMode)
?? degradedWarning()
?? chunkWarning
return TranscriptionDelivery(text: fallbackText, polishWarning: warning)
}
public static func warning(for error: Error, engineMode: String) -> String? {
if let polishError = error as? PolishingService.PolishError {
switch polishError {
case .missingAPIKey:
return SharedL10n.string("flow.warning.polishMissingAPIKey")
case .timeout, .keychainLocked:
return degradedWarning()
case .noTranscript:
return nil
}
}
if error is LLMError {
return degradedWarning()
}
return nil
}
public static func degradedWarning() -> String? {
SharedL10n.string("flow.warning.polishDegraded")
}
}