Skip to main content

systemprompt_provider_contracts/
template.rs

1use std::path::PathBuf;
2
3#[derive(Debug, Clone)]
4pub enum TemplateSource {
5    Embedded(&'static str),
6    File(PathBuf),
7    Directory(PathBuf),
8}
9
10#[derive(Debug, Clone)]
11pub struct TemplateDefinition {
12    pub name: String,
13    pub source: TemplateSource,
14    pub priority: u32,
15    pub content_types: Vec<String>,
16}
17
18impl TemplateDefinition {
19    #[must_use]
20    pub fn embedded(name: impl Into<String>, content: &'static str) -> Self {
21        Self {
22            name: name.into(),
23            source: TemplateSource::Embedded(content),
24            priority: 100,
25            content_types: vec![],
26        }
27    }
28
29    #[must_use]
30    pub fn file(name: impl Into<String>, path: impl Into<PathBuf>) -> Self {
31        Self {
32            name: name.into(),
33            source: TemplateSource::File(path.into()),
34            priority: 100,
35            content_types: vec![],
36        }
37    }
38
39    #[must_use]
40    pub fn directory(name: impl Into<String>, path: impl Into<PathBuf>) -> Self {
41        Self {
42            name: name.into(),
43            source: TemplateSource::Directory(path.into()),
44            priority: 100,
45            content_types: vec![],
46        }
47    }
48
49    #[must_use]
50    pub const fn with_priority(mut self, priority: u32) -> Self {
51        self.priority = priority;
52        self
53    }
54
55    #[must_use]
56    pub fn for_content_types(mut self, types: Vec<String>) -> Self {
57        self.content_types = types;
58        self
59    }
60
61    #[must_use]
62    pub fn for_content_type(mut self, content_type: impl Into<String>) -> Self {
63        self.content_types.push(content_type.into());
64        self
65    }
66}
67
68pub trait TemplateProvider: Send + Sync {
69    fn templates(&self) -> Vec<TemplateDefinition>;
70
71    fn provider_id(&self) -> &'static str;
72
73    fn priority(&self) -> u32 {
74        100
75    }
76}