Skip to main content

systemprompt_models/artifacts/
research.rs

1//! Research artifact shape with source citations.
2//!
3//! Copyright (c) systemprompt.io — Business Source License 1.1.
4//! See <https://systemprompt.io> for licensing details.
5
6use crate::artifacts::card::PresentationCardResponse;
7use schemars::JsonSchema;
8use serde::{Deserialize, Serialize};
9
10#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
11pub struct ResearchArtifact {
12    #[serde(flatten)]
13    pub card: PresentationCardResponse,
14    pub topic: String,
15    pub sources: Vec<SourceCitation>,
16    pub query_count: u32,
17    pub source_count: u32,
18}
19
20impl ResearchArtifact {
21    pub fn new(
22        topic: impl Into<String>,
23        card: PresentationCardResponse,
24        sources: Vec<SourceCitation>,
25    ) -> Self {
26        let source_count = u32::try_from(sources.len()).unwrap_or(u32::MAX);
27        Self {
28            card,
29            topic: topic.into(),
30            sources,
31            query_count: 0,
32            source_count,
33        }
34    }
35
36    pub const fn with_query_count(mut self, count: u32) -> Self {
37        self.query_count = count;
38        self
39    }
40}
41
42#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
43pub struct SourceCitation {
44    pub title: String,
45    pub uri: String,
46    pub relevance: f32,
47}
48
49impl SourceCitation {
50    pub fn new(title: impl Into<String>, uri: impl Into<String>, relevance: f32) -> Self {
51        Self {
52            title: title.into(),
53            uri: uri.into(),
54            relevance,
55        }
56    }
57}