Skip to main content

origin_types/
pages.rs

1// SPDX-License-Identifier: Apache-2.0
2//! Wire types for compiled knowledge pages.
3
4use serde::{Deserialize, Serialize};
5
6/// A compiled knowledge page — structured, cross-referenced, backed by source memories.
7#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct Page {
9    pub id: String,
10    pub title: String,
11    pub summary: Option<String>,
12    pub content: String,
13    pub entity_id: Option<String>,
14    #[serde(default, alias = "domain")]
15    pub space: Option<String>,
16    /// Kept for dual-write transition; prefer concept_sources join table for new reads.
17    pub source_memory_ids: Vec<String>,
18    pub version: i64,
19    pub status: String,
20    pub created_at: String,
21    pub last_compiled: String,
22    pub last_modified: String,
23    /// How many source memories were updated since last distillation.
24    pub sources_updated_count: i64,
25    /// Why this page is stale: "source_updated" | "source_conflict" | None.
26    pub stale_reason: Option<String>,
27    /// True if a human has edited this page's content directly.
28    pub user_edited: bool,
29    /// Relevance score from search (0.0-1.0). Only populated by `search_pages`;
30    /// zero for persisted/non-search contexts.
31    #[serde(default, skip_serializing_if = "is_zero_f32")]
32    pub relevance_score: f32,
33    #[serde(skip_serializing_if = "Option::is_none")]
34    pub last_edited_by: Option<String>,
35    #[serde(skip_serializing_if = "Option::is_none")]
36    pub last_edited_at: Option<i64>,
37    #[serde(skip_serializing_if = "Option::is_none")]
38    pub last_delta_summary: Option<String>,
39    #[serde(skip_serializing_if = "Option::is_none")]
40    pub changelog: Option<String>,
41    /// Routing metadata: which mechanism created this page.
42    /// One of: "distilled" | "authored" | "research" | "imported".
43    /// NOT a trust signal (see `review_status` for that).
44    #[serde(default = "default_creation_kind")]
45    pub creation_kind: String,
46    /// Trust boundary: whether this page has been confirmed as accurate.
47    /// One of: "unconfirmed" | "confirmed".
48    /// Distilled pages start confirmed; authored/research pages start unconfirmed.
49    #[serde(default = "default_review_status")]
50    pub review_status: String,
51}
52
53fn default_creation_kind() -> String {
54    "distilled".to_string()
55}
56
57fn default_review_status() -> String {
58    "confirmed".to_string()
59}
60
61fn is_zero_f32(v: &f32) -> bool {
62    *v == 0.0
63}
64
65/// Typed provenance link for a page (P2 successor to `PageSource`).
66/// Backed by the `page_evidence` SQL table (migration 60).
67/// Additive — `PageSource` / `page_sources` are NOT removed.
68#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
69pub struct PageEvidence {
70    pub page_id: String,
71    pub source_kind: String, // memory | external_url | external_file | authored
72    pub locator: Option<String>,
73    pub title: Option<String>,
74    pub linked_at: i64,
75    pub link_reason: Option<String>,
76}