(message: ApiMessage)
| 185 | * @returns A string containing all command blocks found, or empty string if none |
| 186 | */ |
| 187 | export function extractCommandBlocks(message: ApiMessage): string { |
| 188 | const content = message.content |
| 189 | let text: string |
| 190 | |
| 191 | if (typeof content === "string") { |
| 192 | text = content |
| 193 | } else if (Array.isArray(content)) { |
| 194 | // Concatenate all text blocks |
| 195 | text = content |
| 196 | .filter((block): block is Anthropic.Messages.TextBlockParam => block.type === "text") |
| 197 | .map((block) => block.text) |
| 198 | .join("\n") |
| 199 | } else { |
| 200 | return "" |
| 201 | } |
| 202 | |
| 203 | // Match all <command> blocks including their content |
| 204 | const commandRegex = /<command[^>]*>[\s\S]*?<\/command>/g |
| 205 | const matches = text.match(commandRegex) |
| 206 | |
| 207 | if (!matches || matches.length === 0) { |
| 208 | return "" |
| 209 | } |
| 210 | |
| 211 | return matches.join("\n") |
| 212 | } |
| 213 | |
| 214 | export type SummarizeResponse = { |
| 215 | messages: ApiMessage[] // The messages after summarization |
no outgoing calls
no test coverage detected