* Generic helper to format a tool call as an HTML details section. * This is a reusable helper for all code engines (Claude, Copilot, Codex). * * Tool output/response content is automatically truncated to MAX_TOOL_OUTPUT_LENGTH (256 chars) * to keep step summaries readable and prevent size limit
(options)
| 1077 | * }); |
| 1078 | */ |
| 1079 | function formatToolCallAsDetails(options) { |
| 1080 | const { summary, statusIcon, sections, metadata, maxContentLength = MAX_TOOL_OUTPUT_LENGTH } = options; |
| 1081 | |
| 1082 | // Build the full summary line |
| 1083 | let fullSummary = summary; |
| 1084 | if (statusIcon && !summary.startsWith(statusIcon)) { |
| 1085 | fullSummary = `${statusIcon} ${summary}`; |
| 1086 | } |
| 1087 | if (metadata) { |
| 1088 | fullSummary += ` ${metadata}`; |
| 1089 | } |
| 1090 | |
| 1091 | // If no sections or all sections are empty, just return the summary |
| 1092 | const hasContent = sections && sections.some(s => s.content && s.content.trim()); |
| 1093 | if (!hasContent) { |
| 1094 | return `${fullSummary}\n\n`; |
| 1095 | } |
| 1096 | |
| 1097 | // Build the details content |
| 1098 | let detailsContent = ""; |
| 1099 | for (const section of sections) { |
| 1100 | if (!section.content || !section.content.trim()) { |
| 1101 | continue; |
| 1102 | } |
| 1103 | |
| 1104 | detailsContent += `**${section.label}:**\n\n`; |
| 1105 | |
| 1106 | // Truncate content if it exceeds maxContentLength |
| 1107 | let content = section.content; |
| 1108 | if (content.length > maxContentLength) { |
| 1109 | content = content.substring(0, maxContentLength) + "... (truncated)"; |
| 1110 | } |
| 1111 | |
| 1112 | // Use 6 backticks to avoid conflicts with content that may contain 3 or 5 backticks |
| 1113 | if (section.language) { |
| 1114 | detailsContent += `\`\`\`\`\`\`${section.language}\n`; |
| 1115 | } else { |
| 1116 | detailsContent += "``````\n"; |
| 1117 | } |
| 1118 | detailsContent += content; |
| 1119 | detailsContent += "\n``````\n\n"; |
| 1120 | } |
| 1121 | |
| 1122 | // Remove trailing newlines from details content |
| 1123 | detailsContent = detailsContent.trimEnd(); |
| 1124 | |
| 1125 | return `<details>\n<summary>${fullSummary}</summary>\n\n${detailsContent}\n</details>\n\n`; |
| 1126 | } |
| 1127 | |
| 1128 | /** |
| 1129 | * Formats a tool result content into a preview string showing the first 2 non-empty lines. |
no outgoing calls
no test coverage detected