#[derive(serde::Serialize, serde::Deserialize, Clone, Debug)]
pub struct Resource {
pub uri: String,
pub name: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub mime_type: Option<String>,
}
impl Resource {
pub fn new(
uri: String,
name: String,
description: Option<String>,
mime_type: Option<String>,
) -> Self {
Resource {
uri,
name,
description,
mime_type,
}
}
pub fn ai_context() -> Self {
Resource::new(
String::from("hexser://context"),
String::from("Architecture Context"),
Some(String::from(
"Machine-readable architecture with components, relationships, and constraints",
)),
Some(String::from("application/json")),
)
}
pub fn agent_pack() -> Self {
Resource::new(
String::from("hexser://pack"),
String::from("Agent Pack"),
Some(String::from(
"Comprehensive package with architecture, guidelines, and documentation",
)),
Some(String::from("application/json")),
)
}
}
#[derive(serde::Serialize, serde::Deserialize, Clone, Debug)]
pub struct ResourceList {
pub resources: Vec<Resource>,
}
impl ResourceList {
pub fn new(resources: Vec<Resource>) -> Self {
ResourceList { resources }
}
pub fn hexser_default() -> Self {
ResourceList::new(vec![Resource::ai_context(), Resource::agent_pack()])
}
}
#[derive(serde::Serialize, serde::Deserialize, Clone, Debug)]
pub struct ResourceContent {
pub uri: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub text: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub blob: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub mime_type: Option<String>,
}
impl ResourceContent {
pub fn text(uri: String, text: String, mime_type: Option<String>) -> Self {
ResourceContent {
uri,
text: Some(text),
blob: None,
mime_type,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_resource_serialization() {
let resource = Resource::ai_context();
let json = serde_json::to_string(&resource).unwrap();
std::assert!(json.contains("\"uri\":\"hexser://context\""));
std::assert!(json.contains("\"name\":\"Architecture Context\""));
}
#[test]
fn test_resource_list_default() {
let list = ResourceList::hexser_default();
std::assert_eq!(list.resources.len(), 2);
std::assert_eq!(list.resources[0].uri, "hexser://context");
std::assert_eq!(list.resources[1].uri, "hexser://pack");
}
#[test]
fn test_resource_content_text() {
let content = ResourceContent::text(
String::from("hexser://context"),
String::from("{\"test\": true}"),
Some(String::from("application/json")),
);
std::assert_eq!(content.uri, "hexser://context");
std::assert!(content.text.is_some());
std::assert!(content.blob.is_none());
}
}