SPB Git

spb/prisme Public MIT

Navigateur iOS intelligent — chaque page comprise localement avant d'être affichée. SwiftUI · WebKit · Foundation Models, 100% on-device.

Swift 96.7% JavaScript 3.3%
1.6 KB · 57 lines swift
Raw Blame History
1//2//  ContentBlock.swift3//  Prisme4//5//  Author: Simon-Pierre Boucher <contact@spboucher.ai>6//78import Foundation910/// A typed block produced by the deterministic DOM extraction (Distiller11/// step 2). `domPath` is the child-index path from `document.body` to the12/// source element — the anchor that lets every generated summary point back13/// to the real page (CLAUDE.md §4, the easiest constraint to forget).14struct ContentBlock: Codable, Hashable, Sendable {15    enum Kind: String, Codable, Sendable {16        case heading17        case paragraph18        case listItem19        case quote20        case code21        case table22        case caption23    }2425    let kind: Kind26    /// Heading depth (1–6) for headings, 0 otherwise.27    let level: Int28    let text: String29    let domPath: String30}3132/// Everything the extractor returns for one page.33struct ExtractedContent: Codable, Sendable {34    let title: String35    let lang: String?36    let blocks: [ContentBlock]3738    /// First sentence of the first paragraph — the deterministic essence39    /// used wherever the model has nothing better to offer.40    var leadSentence: String? {41        guard let paragraph = blocks.first(where: { $0.kind == .paragraph })?.text else {42            return nil43        }44        if let end = paragraph.firstIndex(where: { ".!?".contains($0) }) {45            return String(paragraph[...end])46        }47        return String(paragraph.prefix(200))48    }49}5051/// A text selection captured in the page, with its anchor and context.52struct SelectionExcerpt: Codable, Sendable {53    let text: String54    let domPath: String?55    let section: String?56}57