The capture gate and the chunk size were the same number, so a selection above one chunk was rejected before the pipeline could split it; the Settings sliders moved both thresholds together. Add maximumPartsPerSelection (1-8, default 1, so existing behaviour is unchanged). The capture limit is now part size x parts and travels on TranslationSessionRequest, so the watcher, CapturePolicy and TranslationSession agree for that capture. TranslationStreaming gained an optional per-part callback; the session emits chunkStarted and the panel shows 'Part 2 of 4' while streaming and '2 parts' when finished. textTooLong now points at Settings and offers an Open Settings button. Lower the dense-script part-size maximum to 4000 because 5000 dense characters plus a 4096-token output can overflow the 8192-token context. Tests cover capture limits, watcher limits, pipeline part callbacks, session events and limits, panel progress, settings clamping and migration. Docs updated: ADR-011, TRANSLATION_OUTPUT, SELECTION_AND_CLIPBOARD, ARCHITECTURE, LANGUAGES and README. Verified: make verify green; live 4355-character German text showed Part 1 of 2, Part 2 of 2 and '2 parts'; with one part the panel showed the too-long message and Open Settings.
140 lines
4.8 KiB
Swift
140 lines
4.8 KiB
Swift
import Foundation
|
|
import SprachmittlerOllama
|
|
|
|
/// A user-facing recovery action. The UI never shows a raw `localizedDescription`.
|
|
public enum RecoveryAction: Sendable, Equatable {
|
|
/// Start Ollama.
|
|
case startOllama
|
|
/// Copy and run `ollama pull <model>`.
|
|
case pullModel(String)
|
|
/// Open the relevant System Settings page.
|
|
case openSettings
|
|
/// Copy the translation instead.
|
|
case copyInstead
|
|
/// Shorten the selection.
|
|
case shortenText
|
|
/// Retry the translation.
|
|
case retry
|
|
/// Nothing to do.
|
|
case none
|
|
}
|
|
|
|
public extension SprachmittlerError {
|
|
/// A short, non-technical message for the panel and onboarding.
|
|
var userMessage: String {
|
|
switch self {
|
|
case .noSelection:
|
|
"No text was selected."
|
|
case .emptyText:
|
|
"No text was copied."
|
|
case let .textTooLong(_, limit):
|
|
"This selection is too long (limit \(limit) characters). You can raise the limit in Settings."
|
|
case .pasteboardUnavailable:
|
|
"The clipboard is unavailable."
|
|
case .ollamaUnreachable:
|
|
"Ollama is not running."
|
|
case let .ollamaTooOld(_, required):
|
|
"Ollama is too old. Version \(required) or newer is required."
|
|
case let .endpointRejected(reason):
|
|
"The endpoint is not allowed: \(reason.userMessage)"
|
|
case .modelNotInstalled:
|
|
"The Hy-MT3 model is not installed."
|
|
case .noAdapter:
|
|
"This model is not supported."
|
|
case .badRequest:
|
|
"Ollama rejected the request."
|
|
case .server:
|
|
"Ollama returned an error."
|
|
case .timeout:
|
|
"Ollama took too long to answer."
|
|
case .emptyOutput:
|
|
"The model returned an empty translation."
|
|
case .truncated:
|
|
"The translation was cut off."
|
|
case .repetitionLoop:
|
|
"The translation started repeating."
|
|
case .preambleDetected:
|
|
"The model added an explanation."
|
|
case .protectedTokenLost:
|
|
"A URL, placeholder or code token was lost."
|
|
case .accessibilityNotTrusted:
|
|
"Replace needs the Accessibility permission."
|
|
case .accessibilityUnsupported:
|
|
"This app did not accept the replacement."
|
|
case .insertionTargetChanged:
|
|
"The selection changed before Replace."
|
|
case .pasteboardRestoreFailed:
|
|
"The previous clipboard could not be restored."
|
|
case .cancelled:
|
|
"Translation cancelled."
|
|
}
|
|
}
|
|
|
|
/// A stable non-text code for diagnostics.
|
|
var diagnosticCode: String {
|
|
switch self {
|
|
case .noSelection: "noSelection"
|
|
case .emptyText: "emptyText"
|
|
case .textTooLong: "textTooLong"
|
|
case .pasteboardUnavailable: "pasteboardUnavailable"
|
|
case .ollamaUnreachable: "ollamaUnreachable"
|
|
case .ollamaTooOld: "ollamaTooOld"
|
|
case .endpointRejected: "endpointRejected"
|
|
case .modelNotInstalled: "modelNotInstalled"
|
|
case .noAdapter: "noAdapter"
|
|
case .badRequest: "badRequest"
|
|
case .server: "server"
|
|
case .timeout: "timeout"
|
|
case .emptyOutput: "emptyOutput"
|
|
case .truncated: "truncated"
|
|
case .repetitionLoop: "repetitionLoop"
|
|
case .preambleDetected: "preambleDetected"
|
|
case .protectedTokenLost: "protectedTokenLost"
|
|
case .accessibilityNotTrusted: "accessibilityNotTrusted"
|
|
case .accessibilityUnsupported: "accessibilityUnsupported"
|
|
case .insertionTargetChanged: "insertionTargetChanged"
|
|
case .pasteboardRestoreFailed: "pasteboardRestoreFailed"
|
|
case .cancelled: "cancelled"
|
|
}
|
|
}
|
|
|
|
/// The primary recovery action, if any.
|
|
var recoveryAction: RecoveryAction {
|
|
switch self {
|
|
case .ollamaUnreachable:
|
|
.startOllama
|
|
case let .modelNotInstalled(model):
|
|
.pullModel(model)
|
|
case .ollamaTooOld, .endpointRejected:
|
|
.openSettings
|
|
case .textTooLong:
|
|
.openSettings
|
|
case .accessibilityNotTrusted:
|
|
.openSettings
|
|
case .accessibilityUnsupported, .insertionTargetChanged, .pasteboardRestoreFailed:
|
|
.copyInstead
|
|
case .timeout, .server, .emptyOutput, .truncated, .repetitionLoop, .preambleDetected:
|
|
.retry
|
|
default:
|
|
.none
|
|
}
|
|
}
|
|
}
|
|
|
|
private extension EndpointRejection {
|
|
var userMessage: String {
|
|
switch self {
|
|
case .scheme:
|
|
"only http and https are supported"
|
|
case .form:
|
|
"it must not contain credentials, a query or a fragment"
|
|
case .remoteNotAllowed:
|
|
"remote endpoints are disabled"
|
|
case .remoteRequiresHTTPS:
|
|
"remote endpoints require HTTPS"
|
|
case .redirect:
|
|
"redirects are refused"
|
|
}
|
|
}
|
|
}
|