Threads anchored to an address, each with a chain of messages (user/assistant/system). Notes carry editors[], messages carry a single immutable author. rebuildAddressAnnotations folds note counts into the gutter so the UI can render breadcrumbs.
61 lines
1.5 KiB
Swift
61 lines
1.5 KiB
Swift
import Foundation
|
|
import GRDB
|
|
|
|
public struct AddressNoteMessage: Codable, Identifiable, Sendable, FetchableRecord, PersistableRecord {
|
|
public static let databaseTableName = "address_note_message"
|
|
|
|
public enum Role: String, Codable, Sendable {
|
|
case user
|
|
case assistant
|
|
case system
|
|
}
|
|
|
|
public var id: UUID
|
|
public var noteID: UUID
|
|
public var index: Int
|
|
public var role: Role
|
|
public var author: Author?
|
|
public var bodyMarkdown: String
|
|
public var providerID: String?
|
|
public var modelID: String?
|
|
public var actionID: UUID?
|
|
public var createdAt: Date
|
|
|
|
enum CodingKeys: String, CodingKey {
|
|
case id
|
|
case noteID = "note_id"
|
|
case index
|
|
case role
|
|
case author
|
|
case bodyMarkdown = "body_markdown"
|
|
case providerID = "provider_id"
|
|
case modelID = "model_id"
|
|
case actionID = "action_id"
|
|
case createdAt = "created_at"
|
|
}
|
|
|
|
public init(
|
|
id: UUID = UUID(),
|
|
noteID: UUID,
|
|
index: Int,
|
|
role: Role,
|
|
author: Author? = nil,
|
|
bodyMarkdown: String,
|
|
providerID: String? = nil,
|
|
modelID: String? = nil,
|
|
actionID: UUID? = nil,
|
|
createdAt: Date = .now
|
|
) {
|
|
self.id = id
|
|
self.noteID = noteID
|
|
self.index = index
|
|
self.role = role
|
|
self.author = author
|
|
self.bodyMarkdown = bodyMarkdown
|
|
self.providerID = providerID
|
|
self.modelID = modelID
|
|
self.actionID = actionID
|
|
self.createdAt = createdAt
|
|
}
|
|
}
|