scv_protocol/
attachment.rs1use serde::{Deserialize, Serialize};
4use serde_json::Value;
5
6use crate::CHAT_ATTACH_TOOL;
7
8#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
11pub struct Attachment {
12 pub kind: String,
14 pub path: String,
16 #[serde(default, skip_serializing_if = "String::is_empty")]
18 pub name: String,
19 #[serde(default, skip_serializing_if = "String::is_empty")]
21 pub mime: String,
22 pub size: u64,
24 #[serde(default, skip_serializing_if = "Option::is_none")]
26 pub transcript: Option<String>,
27}
28
29#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
32pub struct ReplyAttachment {
33 pub path: String,
35 pub name: String,
37 #[serde(default, skip_serializing_if = "String::is_empty")]
39 pub mime: String,
40 pub size: u64,
42 #[serde(default, skip_serializing_if = "String::is_empty")]
44 pub caption: String,
45}
46
47pub fn reply_attachment(tool: &str, success: bool, output: &str) -> Option<ReplyAttachment> {
50 if tool != CHAT_ATTACH_TOOL || !success {
51 return None;
52 }
53 let value: Value = serde_json::from_str(output).ok()?;
54 serde_json::from_value(value.get("attached")?.clone()).ok()
55}