Files
schihei 26b493e7e5 feat(m1): Ollama client, catalog, streaming chat and CLI (T1.1-T1.6)
Add endpoint policy and redirect-safe ephemeral HTTP client, error mapping, catalog cache and version checks, streaming chat with phase timeouts/cancellation, provisional Hy-MT3 prompt/language/request factory, warm-up policy, and sprachmittler-cli models/show/translate. Recapture the 7B fixtures; defer the 1.8B VERIFY items; document ADR-016. Also fix the signature checker's pipefail SIGPIPE issue.
2026-11-26 13:04:22 +01:00

49 lines
1.8 KiB
Swift

import Foundation
/// A comparable Ollama version such as `0.40.18`.
public struct OllamaVersion: Comparable, Sendable, CustomStringConvertible {
/// The numeric components, e.g. `[0, 40, 18]`.
public let components: [Int]
/// The minimum supported server version (ARCHITECTURE §2).
public static let minimumSupported = OllamaVersion(components: [0, 40, 0])
/// Parses a dotted numeric version. Returns nil for non-numeric or empty input.
public init?(_ string: String) {
let withoutBuild = string.split(separator: "+", maxSplits: 1).first.map(String.init) ?? string
let core = withoutBuild.split(separator: "-", maxSplits: 1).first.map(String.init) ?? withoutBuild
let parts = core.split(separator: ".").map { Int($0) }
guard !parts.isEmpty, parts.allSatisfy({ $0 != nil }) else {
return nil
}
components = parts.compactMap(\.self)
}
private init(components: [Int]) {
self.components = components
}
/// The dotted representation.
public var description: String {
components.map(String.init).joined(separator: ".")
}
/// Component-wise comparison, padding the shorter version with zeros.
public static func < (lhs: OllamaVersion, rhs: OllamaVersion) -> Bool {
let count = max(lhs.components.count, rhs.components.count)
for index in 0 ..< count {
let left = index < lhs.components.count ? lhs.components[index] : 0
let right = index < rhs.components.count ? rhs.components[index] : 0
if left != right {
return left < right
}
}
return false
}
/// Equality treats `0.40` and `0.40.0` as the same version.
public static func == (lhs: OllamaVersion, rhs: OllamaVersion) -> Bool {
!(lhs < rhs) && !(rhs < lhs)
}
}