response_validator/
types.rs1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
10#[serde(tag = "type")]
11pub enum ContentBlock {
12 #[serde(rename = "text")]
14 Text { text: String },
15
16 #[serde(rename = "tool_use")]
18 ToolUse {
19 id: String,
20 name: String,
21 input: serde_json::Value,
22 },
23
24 #[serde(rename = "tool_result")]
26 ToolResult {
27 tool_use_id: String,
28 content: String,
29 },
30}
31
32#[derive(Debug, Clone)]
34pub struct ValidationResult {
35 pub text: String,
37 pub was_truncated: bool,
39 pub detected_marker: Option<String>,
41 pub truncation_offset: Option<usize>,
43}
44
45#[derive(Debug, Clone, PartialEq, Eq)]
47pub enum ActionCategory {
48 FileOperation,
50 CommandExecution,
52 GeneralCompletion,
54}
55
56impl ActionCategory {
57 pub fn matches_tool(&self, tool_name: &str) -> bool {
59 let lower = tool_name.to_lowercase();
60 match self {
61 Self::FileOperation => {
62 lower.contains("write")
63 || lower.contains("edit")
64 || lower.contains("notebook")
65 || lower.contains("file")
66 }
67 Self::CommandExecution => {
68 lower.contains("bash")
69 || lower.contains("shell")
70 || lower.contains("exec")
71 || lower.contains("command")
72 }
73 Self::GeneralCompletion => true,
74 }
75 }
76}
77
78impl std::fmt::Display for ActionCategory {
79 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
80 match self {
81 Self::FileOperation => write!(f, "file_operation"),
82 Self::CommandExecution => write!(f, "command_execution"),
83 Self::GeneralCompletion => write!(f, "general_completion"),
84 }
85 }
86}
87
88#[derive(Debug, Clone)]
90pub struct ActionClaim {
91 pub matched_text: String,
93 pub description: &'static str,
95 pub category: ActionCategory,
97 pub confidence: f32,
99 pub offset: usize,
101}
102
103#[derive(Debug, Clone, Default)]
105pub struct ActionClaimValidation {
106 pub claims: Vec<ActionClaim>,
108 pub unmatched_claims: Vec<ActionClaim>,
110}
111
112impl ActionClaimValidation {
113 pub fn has_warnings(&self) -> bool {
115 !self.unmatched_claims.is_empty()
116 }
117}