#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum MessageRole {
System,
User,
Assistant,
Tool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum ContentBlock {
Text(TextBlock),
Image(ImageBlock),
ToolUse(ToolUseBlock),
ToolResult(ToolResultBlock),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TextBlock {
pub text: String,
}
impl TextBlock {
pub fn new(text: impl Into<String>) -> Self {
Self { text: text.into() }
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ToolUseBlock {
id: String,
name: String,
input: serde_json::Value,
}
impl ToolUseBlock {
pub fn new(id: impl Into<String>, name: impl Into<String>, input: serde_json::Value) -> Self {
Self {
id: id.into(),
name: name.into(),
input,
}
}
pub fn id(&self) -> &str {
&self.id
}
pub fn name(&self) -> &str {
&self.name
}
pub fn input(&self) -> &serde_json::Value {
&self.input
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ToolResultBlock {
tool_use_id: String,
content: serde_json::Value,
}
impl ToolResultBlock {
pub fn new(tool_use_id: impl Into<String>, content: serde_json::Value) -> Self {
Self {
tool_use_id: tool_use_id.into(),
content,
}
}
pub fn tool_use_id(&self) -> &str {
&self.tool_use_id
}
pub fn content(&self) -> &serde_json::Value {
&self.content
}
}