use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
#[derive(
Debug,
Clone,
Copy,
PartialEq,
Eq,
Serialize,
Deserialize,
JsonSchema,
arbitrary::Arbitrary,
)]
#[serde(rename_all = "snake_case")]
#[schemars(rename = "agent.openrouter.SystemPromptRole")]
pub enum SystemPromptRole {
System,
Developer,
}
#[derive(
Debug,
Clone,
PartialEq,
Eq,
Serialize,
Deserialize,
JsonSchema,
arbitrary::Arbitrary,
)]
#[schemars(rename = "agent.openrouter.SystemPrompt")]
pub struct SystemPrompt {
pub role: SystemPromptRole,
pub content: String,
}
impl SystemPrompt {
pub fn validate(&self) -> Result<(), String> {
if self.content.is_empty() {
return Err("system_prompt.content must not be empty".to_string());
}
Ok(())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn serializes_to_role_tagged_wire_shape() {
assert_eq!(
serde_json::to_value(SystemPrompt {
role: SystemPromptRole::System,
content: "hi".to_string(),
})
.unwrap(),
serde_json::json!({"role": "system", "content": "hi"})
);
assert_eq!(
serde_json::to_value(SystemPrompt {
role: SystemPromptRole::Developer,
content: "yo".to_string(),
})
.unwrap(),
serde_json::json!({"role": "developer", "content": "yo"})
);
}
#[test]
fn validate_rejects_empty_content() {
assert!(
SystemPrompt {
role: SystemPromptRole::System,
content: String::new(),
}
.validate()
.is_err()
);
assert!(
SystemPrompt {
role: SystemPromptRole::System,
content: "non-empty".to_string(),
}
.validate()
.is_ok()
);
}
}