Files
OSGKeyboard/OSGKeyboardShared/Models/SpeechHistoryEntry.swift
T
Rocky 3de665d254 feat(keyboard): ship AI mode surface with streaming search answers
Add the AI keyboard tab, Agent settings, and user-owned LLM key path for 1.7.0, including streaming answers and web-search transports without the built-in DeepSeek fallback.
2026-08-11 01:06:27 +08:00

61 lines
2.2 KiB
Swift

// SpeechHistoryEntry.swift
// OSGKeyboard · Shared
//
// A single voice transcription in the cross-device history log.
import Foundation
public struct SpeechHistoryEntry: Codable, Identifiable, Equatable, Sendable {
public enum Source: String, Codable, Equatable, Sendable {
case dictation
case ai
}
public let id: UUID
public let text: String
public let createdAt: Date
/// Last content mutation. Legacy rows default to `createdAt`.
public let modifiedAt: Date
/// Monotonic per-entry revision used to merge edits across devices.
public let revision: Int64
/// iOS Flow engine mode; nil on macOS captures.
public let engineMode: String?
/// Origin of the inserted text. Legacy rows decode as normal dictation.
public let source: Source
public init(
id: UUID = UUID(),
text: String,
createdAt: Date = Date(),
modifiedAt: Date? = nil,
revision: Int64 = 0,
engineMode: String? = nil,
source: Source = .dictation
) {
self.id = id
self.text = text
self.createdAt = createdAt
self.modifiedAt = modifiedAt ?? createdAt
self.revision = revision
self.engineMode = engineMode
self.source = source
}
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
id = try container.decode(UUID.self, forKey: .id)
text = try container.decode(String.self, forKey: .text)
createdAt = try container.decode(Date.self, forKey: .createdAt)
modifiedAt = try container.decodeIfPresent(Date.self, forKey: .modifiedAt) ?? createdAt
revision = try container.decodeIfPresent(Int64.self, forKey: .revision) ?? 0
engineMode = try container.decodeIfPresent(String.self, forKey: .engineMode)
source = try container.decodeIfPresent(Source.self, forKey: .source) ?? .dictation
}
/// First-line preview for compact list rows (macOS history sidebar).
public var previewTitle: String {
let firstLine = text.split(separator: "\n").first.map(String.init) ?? text
return firstLine.count > 36 ? String(firstLine.prefix(36)) + "…" : firstLine
}
}