use crate::graph::ingest::ledger::IngestLedger;
use crate::graph::types::{GraphOrigin, GraphProvenance};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum IngestSourceKind {
StaticArtifact,
SubagentTranscript,
ExternalAgent,
}
impl IngestSourceKind {
#[must_use]
pub fn system_prompt(self) -> &'static str {
match self {
Self::StaticArtifact | Self::SubagentTranscript | Self::ExternalAgent => {
super::prompt::TECH_DOC_SYSTEM_PROMPT
}
}
}
#[must_use]
pub fn graph_origin(self) -> GraphOrigin {
match self {
Self::SubagentTranscript => GraphOrigin::Subagent,
Self::StaticArtifact => GraphOrigin::Ingest,
Self::ExternalAgent => GraphOrigin::ExternalAgent,
}
}
}
#[derive(Debug, Clone)]
pub struct IngestDocument {
content: String,
context: Vec<String>,
provenance: GraphProvenance,
content_hash: String,
}
impl IngestDocument {
pub(super) fn new(
content: String,
prior_messages: Vec<String>,
provenance: GraphProvenance,
) -> Self {
let content_hash = IngestLedger::content_hash(content.as_bytes());
Self {
content,
context: prior_messages,
provenance,
content_hash,
}
}
#[must_use]
pub fn content(&self) -> &str {
&self.content
}
#[must_use]
pub fn context(&self) -> &[String] {
&self.context
}
#[must_use]
pub fn provenance(&self) -> &GraphProvenance {
&self.provenance
}
#[must_use]
pub fn content_hash(&self) -> &str {
&self.content_hash
}
#[must_use]
pub fn source_uri(&self) -> &str {
self.provenance.source_uri.as_deref().unwrap_or_default()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn subagent_transcript_maps_to_subagent_origin() {
assert_eq!(
IngestSourceKind::SubagentTranscript.graph_origin(),
GraphOrigin::Subagent
);
}
#[test]
fn static_artifact_maps_to_ingest_origin() {
assert_eq!(
IngestSourceKind::StaticArtifact.graph_origin(),
GraphOrigin::Ingest
);
}
}