systemprompt_traits/
content.rs1use async_trait::async_trait;
4use chrono::{DateTime, Utc};
5use serde::{Deserialize, Serialize};
6use systemprompt_identifiers::{ContentId, SourceId};
7
8#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct ContentSummary {
10 pub id: ContentId,
11 pub slug: String,
12 pub title: String,
13 pub description: String,
14 pub published_at: DateTime<Utc>,
15 pub kind: String,
16 pub source_id: SourceId,
17}
18
19#[derive(Debug, Clone, Serialize, Deserialize)]
20pub struct ContentItem {
21 pub id: ContentId,
22 pub slug: String,
23 pub title: String,
24 pub description: String,
25 pub body: String,
26 pub author: String,
27 pub published_at: DateTime<Utc>,
28 pub keywords: String,
29 pub kind: String,
30 pub image: Option<String>,
31 pub source_id: SourceId,
32 pub category_id: Option<String>,
33}
34
35#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
36pub struct ContentFilter {
37 pub source_id: Option<SourceId>,
38 pub category_id: Option<String>,
39 pub kind: Option<String>,
40 pub query: Option<String>,
41 pub limit: Option<i64>,
42 pub offset: Option<i64>,
43}
44
45#[async_trait]
46pub trait ContentProvider: Send + Sync {
47 type Error: std::error::Error + Send + Sync + 'static;
48
49 async fn get_content(&self, id: &str) -> Result<Option<ContentItem>, Self::Error>;
50
51 async fn get_content_by_slug(&self, slug: &str) -> Result<Option<ContentItem>, Self::Error>;
52
53 async fn get_content_by_source_and_slug(
54 &self,
55 source_id: &SourceId,
56 slug: &str,
57 ) -> Result<Option<ContentItem>, Self::Error>;
58
59 async fn list_content(&self, filter: ContentFilter)
60 -> Result<Vec<ContentSummary>, Self::Error>;
61
62 async fn search(
63 &self,
64 query: &str,
65 limit: Option<i64>,
66 ) -> Result<Vec<ContentSummary>, Self::Error>;
67}