Skip to main content

systemprompt_sync/diff/
mod.rs

1mod agents;
2mod content;
3mod skills;
4
5pub use agents::AgentsDiffCalculator;
6pub use content::ContentDiffCalculator;
7pub use skills::SkillsDiffCalculator;
8
9use crate::models::{DiskAgent, DiskSkill};
10use sha2::{Digest, Sha256};
11use systemprompt_agent::models::{Agent, Skill};
12
13pub fn compute_content_hash(body: &str, title: &str) -> String {
14    let mut hasher = Sha256::new();
15    hasher.update(title.as_bytes());
16    hasher.update(body.as_bytes());
17    format!("{:x}", hasher.finalize())
18}
19
20pub(crate) fn compute_skill_hash(skill: &DiskSkill) -> String {
21    let mut hasher = Sha256::new();
22    hasher.update(skill.name.as_bytes());
23    hasher.update(skill.description.as_bytes());
24    hasher.update(skill.instructions.as_bytes());
25    format!("{:x}", hasher.finalize())
26}
27
28pub(crate) fn compute_db_skill_hash(skill: &Skill) -> String {
29    let mut hasher = Sha256::new();
30    hasher.update(skill.name.as_bytes());
31    hasher.update(skill.description.as_bytes());
32    hasher.update(skill.instructions.as_bytes());
33    format!("{:x}", hasher.finalize())
34}
35
36pub(crate) fn compute_agent_hash(agent: &DiskAgent) -> String {
37    let mut hasher = Sha256::new();
38    hasher.update(agent.name.as_bytes());
39    hasher.update(agent.display_name.as_bytes());
40    hasher.update(agent.description.as_bytes());
41    if let Some(sp) = &agent.system_prompt {
42        hasher.update(sp.as_bytes());
43    }
44    format!("{:x}", hasher.finalize())
45}
46
47pub(crate) fn compute_db_agent_hash(agent: &Agent) -> String {
48    let mut hasher = Sha256::new();
49    hasher.update(agent.name.as_bytes());
50    hasher.update(agent.display_name.as_bytes());
51    hasher.update(agent.description.as_bytes());
52    if let Some(sp) = &agent.system_prompt {
53        hasher.update(sp.as_bytes());
54    }
55    format!("{:x}", hasher.finalize())
56}