cdf833935a
Fix cold-start overlay recursion that overflowed the main-thread stack when recording began while the ready overlay was still up; also remove temporary on-screen Flow DEBUG panels after the orange-mic investigation, and land the macOS overlay/catalog/layout polish plus related Flow recovery hardening.
48 lines
1.5 KiB
Swift
48 lines
1.5 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:
|
|
if engineMode == "local" {
|
|
return SharedL10n.string("flow.warning.localPolishUnavailable")
|
|
}
|
|
return SharedL10n.string("flow.warning.cloudPolishMissingKey")
|
|
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")
|
|
}
|
|
}
|