(
tool_name: &str,
output: &str,
shown_bytes: usize,
)
| 97 | } |
| 98 | |
| 99 | pub(crate) fn tool_output_artifact( |
| 100 | tool_name: &str, |
| 101 | output: &str, |
| 102 | shown_bytes: usize, |
| 103 | ) -> ToolOutputArtifact { |
| 104 | use std::hash::{Hash, Hasher}; |
| 105 | |
| 106 | let mut hasher = std::collections::hash_map::DefaultHasher::new(); |
| 107 | tool_name.hash(&mut hasher); |
| 108 | output.len().hash(&mut hasher); |
| 109 | output.hash(&mut hasher); |
| 110 | let digest = hasher.finish(); |
| 111 | let sanitized_tool = tool_name |
| 112 | .chars() |
| 113 | .map(|ch| { |
| 114 | if ch.is_ascii_alphanumeric() || ch == '_' || ch == '-' { |
| 115 | ch |
| 116 | } else { |
| 117 | '_' |
| 118 | } |
| 119 | }) |
| 120 | .collect::<String>(); |
| 121 | let artifact_id = format!("tool-output:{sanitized_tool}:{digest:016x}"); |
| 122 | let artifact_uri = format!("a3s://tool-output/{sanitized_tool}/{digest:016x}"); |
| 123 | |
| 124 | ToolOutputArtifact { |
| 125 | artifact_id, |
| 126 | artifact_uri, |
| 127 | original_bytes: output.len(), |
| 128 | shown_bytes, |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | pub(crate) fn merge_tool_output_artifact_metadata( |
| 133 | metadata: Option<serde_json::Value>, |
no test coverage detected