SPB Git

Repository Public

NotesAPI+Inbox.swift 2.6 KB 40 lines swift

1// SP Notes Core2// File: Sources/SPNotesAPI/NotesAPI+Inbox.swift3// Description: Inbox and capture routes beside the 2.x ones of NotesAPI.swift: the badge count, captures with an open4//              kind, and the Smart Inbox of the AI workstream (suggestions, apply).5//6// Author: Simon-Pierre Boucher7// Contact: contact@spboucher.ai8import Foundation910extension NotesAPI {11    /// `GET /api/inbox?count=1` — the number of captures waiting (navigation badge).12    public func inboxCount() async throws -> Int {13        try await client.decode(InboxCount.self, .get("/api/inbox", query: [URLQueryItem(name: "count", value: "1")])).count14    }1516    /// `POST /api/capture` with an open kind (`CaptureKindName`) → 201. A kind the server does not know answers `400`17    /// (`"Validation: kind Invalid option…"`, no code). Always give an idempotency key when the capture may be replayed.18    public func capture(_ draft: CaptureDraft, idempotencyKey: String? = nil) async throws -> CaptureResult {19        try await client.decode(CaptureResult.self, .json(.post, "/api/capture", body: draft, idempotencyKey: idempotencyKey))20    }2122    // MARK: - Smart Inbox (API-NEXT-AI §5)2324    /// `GET /api/inbox/<id>/suggestions` — title, tags, destination, related pages and summary proposed for a capture.25    /// **Calls a paid model** unless the answer is cached; `cachedOnly` never does (`404 not_generated` when there is26    /// nothing cached). A server without the AI workstream has no such route: `APIError.isRouteMissing`.27    /// Errors: `409 not_in_inbox`, `503 no_model`, `502 provider_error | refused | bad_output`.28    public func inboxSuggestions(id: String, refresh: Bool = false, cachedOnly: Bool = false, model: String? = nil) async throws -> InboxSuggestions {29        let query = Self.flag("refresh", refresh) + Self.flag("cachedOnly", cachedOnly) + Self.item("model", model)30        return try await client.decode(InboxSuggestions.self, .get("/api/inbox/\(Self.segment(id))/suggestions", query: query))31    }3233    /// `POST /api/inbox/<id>/apply` — applies the chosen suggestions (no model involved). Undo with34    /// `undoInboxAction(actionID:)`. Errors: `400 nothing_to_apply | bad_section | bad_destination | bad_relation`,35    /// `409 not_in_inbox`, `409 conflict`.36    public func applyInboxSuggestions(id: String, _ selection: InboxSuggestionSelection, idempotencyKey: String? = nil) async throws -> InboxApplyResult {37        try await client.decode(InboxApplyResult.self, .json(.post, "/api/inbox/\(Self.segment(id))/apply", body: selection, idempotencyKey: idempotencyKey))38    }39}40
Files main
Menu

Theme