forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProactiveModels.swift
More file actions
157 lines (131 loc) · 3.92 KB
/
Copy pathProactiveModels.swift
File metadata and controls
157 lines (131 loc) · 3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import Foundation
@preconcurrency import GRDB
// MARK: - Extraction Type
/// Types of proactive extractions
enum ExtractionType: String, Codable, CaseIterable {
case memory
case task
case insight
}
// MARK: - Proactive Extraction Record
/// Database record for memories, tasks, and advice extracted from screenshots
struct ProactiveExtractionRecord: Codable, FetchableRecord, PersistableRecord, Identifiable {
var id: Int64?
var screenshotId: Int64?
var type: ExtractionType
var content: String
var category: String?
var confidence: Double?
var reasoning: String?
var sourceApp: String
var contextSummary: String?
var priority: String?
var isRead: Bool
var isDismissed: Bool
var backendId: String?
var backendSynced: Bool
var createdAt: Date
var updatedAt: Date
static let databaseTableName = "proactive_extractions"
// MARK: - Initialization
init(
id: Int64? = nil,
screenshotId: Int64? = nil,
type: ExtractionType,
content: String,
category: String? = nil,
confidence: Double? = nil,
reasoning: String? = nil,
sourceApp: String,
contextSummary: String? = nil,
priority: String? = nil,
isRead: Bool = false,
isDismissed: Bool = false,
backendId: String? = nil,
backendSynced: Bool = false,
createdAt: Date = Date(),
updatedAt: Date = Date()
) {
self.id = id
self.screenshotId = screenshotId
self.type = type
self.content = content
self.category = category
self.confidence = confidence
self.reasoning = reasoning
self.sourceApp = sourceApp
self.contextSummary = contextSummary
self.priority = priority
self.isRead = isRead
self.isDismissed = isDismissed
self.backendId = backendId
self.backendSynced = backendSynced
self.createdAt = createdAt
self.updatedAt = updatedAt
}
// MARK: - Persistence Callbacks
mutating func didInsert(_ inserted: InsertionSuccess) {
id = inserted.rowID
}
// MARK: - Relationships
static let screenshot = belongsTo(Screenshot.self)
var screenshot: QueryInterfaceRequest<Screenshot> {
request(for: ProactiveExtractionRecord.screenshot)
}
}
// MARK: - Task Dedup Log Record
/// Database record for AI-driven task deduplication deletions
struct TaskDedupLogRecord: Codable, FetchableRecord, PersistableRecord, Identifiable {
var id: Int64?
var deletedTaskId: String
var deletedDescription: String
var keptTaskId: String
var keptDescription: String
var reason: String
var deletedAt: Date
static let databaseTableName = "task_dedup_log"
init(
id: Int64? = nil,
deletedTaskId: String,
deletedDescription: String,
keptTaskId: String,
keptDescription: String,
reason: String,
deletedAt: Date = Date()
) {
self.id = id
self.deletedTaskId = deletedTaskId
self.deletedDescription = deletedDescription
self.keptTaskId = keptTaskId
self.keptDescription = keptDescription
self.reason = reason
self.deletedAt = deletedAt
}
mutating func didInsert(_ inserted: InsertionSuccess) {
id = inserted.rowID
}
}
// MARK: - Screenshot Extensions for Relationships
extension Screenshot {
static let extractions = hasMany(ProactiveExtractionRecord.self)
var extractions: QueryInterfaceRequest<ProactiveExtractionRecord> {
request(for: Screenshot.extractions)
}
}
// MARK: - Extraction with Screenshot
/// Combined extraction and screenshot data for UI display
struct ExtractionWithScreenshot {
let extraction: ProactiveExtractionRecord
let screenshot: Screenshot?
var imagePath: String? {
screenshot?.imagePath
}
var screenshotTimestamp: Date? {
screenshot?.timestamp
}
}
// MARK: - TableDocumented
extension ProactiveExtractionRecord: TableDocumented {
static var tableDescription: String { ChatPrompts.tableAnnotations["proactive_extractions"]! }
static var columnDescriptions: [String: String] { ChatPrompts.columnAnnotations["proactive_extractions"] ?? [:] }
}