use crate::embed::lifecycle::public_api::EmbedSourceRefusal;
pub use crate::knowledge::curation_contract::{
CurateKnowledgeInput, KnowledgePolicyActionInput, KnowledgePolicyAuthorityDomainInput,
KnowledgePolicyEntryInput, KnowledgePolicyEvidenceInput, KnowledgePolicyLifecycleInput,
KnowledgePolicyMutationInput, KnowledgePolicyTargetInput,
};
pub use crate::knowledge::review_contract::{
KnowledgeSourceScope, ReviewKnowledgeInput, ReviewKnowledgeMode,
};
use serde::{Deserialize, Serialize};
pub mod search;
#[derive(Debug)]
pub enum KnowledgeReviewError {
Source(EmbedSourceRefusal),
InvalidSelection,
InvalidInput,
Readiness,
BoundExceeded,
}
impl From<EmbedSourceRefusal> for KnowledgeReviewError {
fn from(value: EmbedSourceRefusal) -> Self {
Self::Source(value)
}
}
#[derive(Clone, Debug, Serialize)]
pub struct KnowledgeReviewResult {
pub rendered: String,
pub source_key: String,
pub review_hash: String,
pub result_hash: String,
pub publication_identity: String,
pub serving_publication_identity: String,
pub source_version: u64,
pub publication_generation: u64,
pub summarized: bool,
}
#[derive(Clone)]
pub struct BoundCurateKnowledgeInput {
pub input: CurateKnowledgeInput,
pub if_serving_publication_identity: String,
}
impl BoundCurateKnowledgeInput {
pub fn from_review(review: &KnowledgeReviewResult, input: CurateKnowledgeInput) -> Self {
Self {
input,
if_serving_publication_identity: review.serving_publication_identity.clone(),
}
}
}
impl std::fmt::Debug for BoundCurateKnowledgeInput {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("BoundCurateKnowledgeInput")
.field("input", &self.input)
.field(
"has_serving_publication_identity",
&!self.if_serving_publication_identity.is_empty(),
)
.finish()
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum KnowledgeCurationStatus {
Preview,
Applied,
}
#[derive(Clone, Debug, Serialize)]
pub struct KnowledgeCurationResult {
pub status: KnowledgeCurationStatus,
pub rendered: String,
pub refresh_ticket_identity: Option<String>,
}
#[derive(Debug)]
pub enum KnowledgeCurationError {
Source(EmbedSourceRefusal),
InvalidInput,
StalePublication,
ReplayConflict,
WriteAuthorityRefused,
DurableStateUnavailable,
EngineRejected,
Uncertain,
}
impl From<EmbedSourceRefusal> for KnowledgeCurationError {
fn from(value: EmbedSourceRefusal) -> Self {
Self::Source(value)
}
}
#[derive(Clone, Deserialize, Serialize)]
#[serde(tag = "kind", rename_all = "snake_case", deny_unknown_fields)]
pub enum WireKnowledgeRequest {
Review {
input: ReviewKnowledgeInput,
},
CuratePreview {
input: CurateKnowledgeInput,
if_serving_publication_identity: String,
},
CurateApply {
input: CurateKnowledgeInput,
if_serving_publication_identity: String,
},
}
impl WireKnowledgeRequest {
pub fn is_apply(&self) -> bool {
match self {
Self::CurateApply { .. } => true,
Self::Review { .. } | Self::CuratePreview { .. } => false,
}
}
}
#[derive(Serialize)]
#[serde(tag = "kind", content = "result", rename_all = "snake_case")]
pub enum WireKnowledgeReply {
Review(KnowledgeReviewResult),
Curation(KnowledgeCurationResult),
}
#[derive(Debug)]
pub enum WireKnowledgeError {
Review(KnowledgeReviewError),
Curation(KnowledgeCurationError),
InvalidKind,
}