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