SPB Git

Repository Public

InboxModels.swift 7.6 KB 201 lines swift

1// SP Notes Core2// File: Sources/SPNotesAPI/InboxModels.swift3// Description: Additions to the inbox and capture models: capture kinds as open strings, what a triage created, the4//              inbox badge, and the Smart Inbox of the AI workstream (suggestions, apply).5//6// Author: Simon-Pierre Boucher7// Contact: contact@spboucher.ai8import Foundation910// MARK: - Capture1112/// The capture kinds as strings (`CaptureDraft.kind`). The first six are accepted by every server; the 3.0 kinds13/// are refused with `400` by a server that does not know them (observed on the foundation build).14public enum CaptureKindName {15    public static let note = "note"16    public static let tasks = "tasks"17    public static let link = "link"18    public static let photo = "photo"19    public static let file = "file"20    public static let audio = "audio"21    /// 3.0 (SPEC): not accepted by the foundation server.22    public static let screenshot = "screenshot"23    /// 3.0 (SPEC): not accepted by the foundation server.24    public static let selection = "selection"25    /// 3.0 (SPEC): not accepted by the foundation server.26    public static let document = "document"27    /// The kinds every server accepts.28    public static let baseline = [note, tasks, link, photo, file, audio]29}3031/// Body of `POST /api/capture` with an open `kind` (see `CaptureKindName`). Same route as `CaptureRequest`.32/// - `link` needs an http(s) `url` (or one as the first line of `text`); `tasks` makes one task item per line;33///   the others need `text` or at least one attachment (uploaded first with `uploadAttachment`).34public struct CaptureDraft: Encodable, Sendable, Equatable {35    public var kind: String36    /// ≤ 100 000 characters. Its first line becomes the title.37    public var text: String?38    public var url: String?39    /// ≤ 20 attachment ids.40    public var attachmentIds: [String]?4142    public init(kind: String, text: String? = nil, url: String? = nil, attachmentIds: [String]? = nil) {43        self.kind = kind44        self.text = text45        self.url = url46        self.attachmentIds = attachmentIds47    }48}4950/// `GET /api/inbox?count=1`.51public struct InboxCount: Codable, Sendable, Equatable {52    public var count: Int53}5455// MARK: - Triage5657/// What a triage (or a Smart Inbox apply) created — the typed form of `TriageResult.created`.58public struct TriageCreated: Codable, Sendable, Equatable {59    /// `task`: one task per open task item of the capture (or one with its title).60    public var taskIds: [String]?61    /// `database`: the new row…62    public var rowId: String?63    /// …and its database.64    public var databaseId: String?65    /// `reference`: the reference created.66    public var referenceId: String?67    /// `reference`: the DOI was already in the library; nothing was created (and undo will not delete it).68    public var existingReferenceId: String?69    /// Smart Inbox apply: block id of the inserted AI summary.70    public var summaryBlockId: String?71    /// Smart Inbox apply.72    public var tagsAdded: [String]?73    /// Smart Inbox apply: the accepted relations.74    public var edgeIds: [String]?7576    public init() {}77}7879extension TriageResult {80    /// `created`, decoded (every field nil for `keep`, `archive` and `trash`).81    public var createdObjects: TriageCreated { created.flatMap { try? $0.decode(TriageCreated.self) } ?? TriageCreated() }82}8384// MARK: - Smart Inbox (AI workstream, API-NEXT-AI §5)8586/// The title proposed for a capture.87public struct InboxTitleSuggestion: Codable, Sendable, Equatable {88    public var value: String89    public var current: String?90}9192public struct InboxTagSuggestion: Codable, Sendable, Equatable {93    public var name: String94    /// `false`: the tag would be created.95    public var existing: Bool?96}9798/// Where to file a capture: a section, optionally under an existing page.99public struct InboxDestinationSuggestion: Codable, Sendable, Equatable {100    public var section: String?101    public var parentId: String?102    public var parentTitle: String?103}104105public struct InboxRelationSuggestion: Codable, Sendable, Equatable {106    public var pageId: String107    public var title: String?108    public var icon: String?109    public var reason: String?110}111112/// `suggestions` of `GET /api/inbox/<id>/suggestions`: each part may be absent.113public struct InboxSuggestionSet: Codable, Sendable, Equatable {114    /// `nil` when the model keeps the current title.115    public var title: InboxTitleSuggestion?116    public var tags: [InboxTagSuggestion]?117    public var destination: InboxDestinationSuggestion?118    public var relations: [InboxRelationSuggestion]?119    public var summary: String?120}121122/// `GET /api/inbox/<id>/suggestions` — AI suggestions for one capture. The route changes nothing.123public struct InboxSuggestions: Codable, Sendable, Equatable {124    public var pageId: String125    public var contentHash: String?126    /// `ready`, or `empty` for a capture with no title and no text.127    public var status: String?128    public var ai: Bool?129    public var model: String?130    public var provider: String?131    public var generatedAt: Date?132    /// The answer came from the cache (no provider call).133    public var cached: Bool?134    public var costUsd: Double?135    public var suggestions: InboxSuggestionSet?136}137138/// Body of `POST /api/inbox/<id>/apply`: the subset the user chose, with the values possibly edited. Only what is139/// set is applied; without `destination` the capture stays in the inbox.140public struct InboxSuggestionSelection: Encodable, Sendable, Equatable {141    public struct Destination: Encodable, Sendable, Equatable {142        /// `notes`, `documents`, `projects`, `research`.143        public var section: String?144        public var parentId: PatchValue<String>?145146        public init(section: String? = nil, parentId: PatchValue<String>? = nil) {147            self.section = section148            self.parentId = parentId149        }150151        enum CodingKeys: String, CodingKey { case section, parentId }152153        public func encode(to encoder: Encoder) throws {154            var c = encoder.container(keyedBy: CodingKeys.self)155            try c.encodeIfPresent(section, forKey: .section)156            try c.encodePatch(parentId, forKey: .parentId)157        }158    }159160    public struct Relation: Encodable, Sendable, Equatable {161        public var pageId: String162        public var reason: String?163164        public init(pageId: String, reason: String? = nil) {165            self.pageId = pageId166            self.reason = reason167        }168    }169170    /// ≤ 300 characters.171    public var title: String?172    /// ≤ 10, added to the existing tags.173    public var tags: [String]?174    public var destination: Destination?175    /// ≤ 10.176    public var relations: [Relation]?177    /// ≤ 1000 characters, inserted as an AI block at the top of the page.178    public var summary: String?179180    public init(title: String? = nil, tags: [String]? = nil, destination: Destination? = nil, relations: [Relation]? = nil, summary: String? = nil) {181        self.title = title182        self.tags = tags183        self.destination = destination184        self.relations = relations185        self.summary = summary186    }187188    public var isEmpty: Bool { title == nil && tags == nil && destination == nil && relations == nil && summary == nil }189}190191/// Answer of `POST /api/inbox/<id>/apply`. `actionId` is undone with `undoInboxAction` like a triage.192public struct InboxApplyResult: Codable, Sendable, Equatable {193    public var actionId: String194    public var summary: String?195    /// The parts applied: `title`, `summary`, `tags`, `relations`, `destination`.196    public var applied: [String]?197    /// The capture left the inbox.198    public var filed: Bool?199    public var created: TriageCreated?200}201
Files main
Menu

Theme