498f407585
Introduce optional Apple account-backed credits with scoped gateway access while preserving local and BYOK paths. Refresh assistant behavior, tests, privacy disclosures, docs, and the website for the 2.0 experience.
55 lines
1.8 KiB
Swift
55 lines
1.8 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()
|
|
}
|
|
if let managedError = error as? ManagedGatewayError {
|
|
switch managedError {
|
|
case .insufficientCredits:
|
|
return SharedL10n.string("flow.warning.managedInsufficientCredits")
|
|
case .missingGrant, .scopeNotGranted, .invalidGrant:
|
|
return SharedL10n.string("flow.warning.managedGrantRejected")
|
|
case .timeout, .server:
|
|
return degradedWarning()
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
public static func degradedWarning() -> String? {
|
|
SharedL10n.string("flow.warning.polishDegraded")
|
|
}
|
|
}
|