M4: TranslationSession actor with epochs/one-in-flight streaming, PanelViewModel, non-activating NSPanel, streaming panel UI, searchable/recent target languages, warnings/errors and Copy/Retry/Replace actions. M5: InsertionCoordinator with target capture, AX direct replacement, secure-field/own-PID refusal, frontmost and selected-text verification, snapshot/⌘V/restore fallback, cancellation-safe restore and blocking-warning gate. M6: versioned AppSettings/SettingsStore, onboarding for Ollama/model/target/Accessibility, General/Model/Translation/Privacy/Diagnostics settings, launch-at-login via SMAppService, status menu (target, copy/replace last, setup, diagnostics, about), text-free diagnostics and first-run setup. Docs: PROGRESS M4–M6, ARCHITECTURE §10–§12, ADR-019/020, SELECTION_AND_CLIPBOARD and TESTING. Manual 10-app matrices, real AX/paste delivery, VoiceOver and focus checks remain open. Verified: make verify green (format, strict lint, scripts, privacy, Debug+Release signatures, 217 package tests); app launches and a two-copy clipboard smoke test opens the panel.
77 lines
2.8 KiB
Swift
77 lines
2.8 KiB
Swift
import Foundation
|
|
import Observation
|
|
import SprachmittlerEngines
|
|
import SprachmittlerOllama
|
|
|
|
/// The diagnostics window model. It formats versions, digests, timings and error kinds only.
|
|
@MainActor
|
|
@Observable
|
|
public final class DiagnosticsViewModel {
|
|
/// The last events, oldest first.
|
|
public private(set) var events: [DiagnosticEvent] = []
|
|
/// The Ollama version.
|
|
public private(set) var serverVersion: String?
|
|
/// The installed Hy-MT3 models.
|
|
public private(set) var models: [InstalledModel] = []
|
|
/// A short error when the refresh failed.
|
|
public private(set) var error: String?
|
|
/// True while refreshing.
|
|
public private(set) var isRefreshing = false
|
|
|
|
private let store: DiagnosticsStore
|
|
private let catalogProvider: @Sendable (AppSettings) throws -> any OllamaCatalog
|
|
private let settingsProvider: @Sendable () -> AppSettings
|
|
|
|
/// Creates the diagnostics model.
|
|
public init(
|
|
store: DiagnosticsStore,
|
|
catalogProvider: @escaping @Sendable (AppSettings) throws -> any OllamaCatalog,
|
|
settingsProvider: @escaping @Sendable () -> AppSettings
|
|
) {
|
|
self.store = store
|
|
self.catalogProvider = catalogProvider
|
|
self.settingsProvider = settingsProvider
|
|
}
|
|
|
|
/// Reloads events and, when possible, server/model details.
|
|
public func refresh() async {
|
|
isRefreshing = true
|
|
defer { isRefreshing = false }
|
|
events = await store.snapshot()
|
|
|
|
do {
|
|
let catalog = try catalogProvider(settingsProvider())
|
|
serverVersion = try await catalog.serverVersion()
|
|
models = try await catalog.installedModels()
|
|
.filter { HyMT3ModelPreset.isHyMT3($0.name) }
|
|
error = nil
|
|
} catch let rejection as EndpointRejection {
|
|
self.error = SprachmittlerError.endpointRejected(reason: rejection).userMessage
|
|
} catch {
|
|
self.error = "Ollama details are unavailable."
|
|
}
|
|
}
|
|
|
|
/// Clears the in-memory event list.
|
|
public func clear() async {
|
|
await store.clear()
|
|
events = []
|
|
}
|
|
|
|
/// A text-only report for the clipboard; no source text or translation is included.
|
|
public func report() -> String {
|
|
var lines = [
|
|
"Sprachmittler diagnostics",
|
|
"Ollama: \(serverVersion ?? "unknown")",
|
|
"Endpoint: \(settingsProvider().endpoint.absoluteString)",
|
|
"Models: \(models.map { "\($0.name) [\($0.digest.prefix(12))]" }.joined(separator: ", "))",
|
|
]
|
|
for event in events {
|
|
let duration = event.durationMs.map { " \($0) ms" } ?? ""
|
|
let detail = event.detail.map { " [\($0)]" } ?? ""
|
|
lines.append("\(event.kind)\(duration)\(detail)")
|
|
}
|
|
return lines.joined(separator: "\n")
|
|
}
|
|
}
|