| 69 | } |
| 70 | |
| 71 | pub(crate) fn truncate_tool_output_with_artifact( |
| 72 | tool_name: &str, |
| 73 | output: &str, |
| 74 | ) -> TruncatedToolOutput { |
| 75 | if output.len() <= MAX_OUTPUT_SIZE { |
| 76 | return TruncatedToolOutput { |
| 77 | content: output.to_string(), |
| 78 | artifact: None, |
| 79 | }; |
| 80 | } |
| 81 | |
| 82 | let shown = truncate_utf8(output, MAX_OUTPUT_SIZE); |
| 83 | let artifact = tool_output_artifact(tool_name, output, shown.len()); |
| 84 | let artifact_uri = artifact.artifact_uri.clone(); |
| 85 | let content = format!( |
| 86 | "{}\n\n[tool output truncated: showing the first {} of {} bytes. Full output artifact: {}. Use narrower arguments such as offset/limit or filtering when possible.]", |
| 87 | shown, |
| 88 | shown.len(), |
| 89 | output.len(), |
| 90 | artifact_uri, |
| 91 | ); |
| 92 | |
| 93 | TruncatedToolOutput { |
| 94 | content, |
| 95 | artifact: Some(artifact), |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | pub(crate) fn tool_output_artifact( |
| 100 | tool_name: &str, |