This commit is contained in:
snowspeeder committed 2026-08-31 19:50:46 -04:00
1 parent c9c25f86eb
commit 40aaf4fea7
56 files changed
+5683 -179

No files matched your search

+15 -8
View File
@@ -7,12 +7,17 @@ struct HistoryEntry: Codable, Equatable {
}
/// Last 50 final transcript entries persisted as JSON in UserDefaults.
///
/// Persistence-only store. The visible transcript is the single canonical
/// collection owned by `TranscriptHandler.events`; this class provides the
/// durable snapshot it initializes from and syncs to. It performs no dedupe —
/// all suppression is source-aware and time-bounded in the handler.
@MainActor
final class TranscriptHistory: ObservableObject {
@Published private(set) var entries: [HistoryEntry] = []
private static let key = "voice_history"
private static let maxEntries = 50
static let key = "voice_history"
static let maxEntries = 50
init() {
if let raw = UserDefaults.standard.string(forKey: Self.key),
@@ -22,12 +27,14 @@ final class TranscriptHistory: ObservableObject {
}
}
func add(role: String, text: String) {
guard !text.isEmpty else { return }
entries.append(HistoryEntry(role: role, text: text, timestamp: Date()))
if entries.count > Self.maxEntries {
entries.removeFirst(entries.count - Self.maxEntries)
}
/// Replaces the persisted snapshot with exactly the finals currently in the
/// canonical visible collection. Called by `TranscriptHandler` after every
/// change so persistence and the UI never diverge. No dedupe is applied here:
/// same-source repeats are legitimate entries.
func sync(finals: [(role: String, text: String, timestamp: Date)]) {
entries = Array(finals.suffix(Self.maxEntries).map {
HistoryEntry(role: $0.role, text: $0.text, timestamp: $0.timestamp)
})
persist()
}