MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / extractCommandBlocks

Function extractCommandBlocks

src/core/condense/index.ts:187–212  ·  view source on GitHub ↗
(message: ApiMessage)

Source from the content-addressed store, hash-verified

185 * @returns A string containing all command blocks found, or empty string if none
186 */
187export 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
214export type SummarizeResponse = {
215 messages: ApiMessage[] // The messages after summarization

Callers 3

condense.spec.tsFile · 0.90
index.spec.tsFile · 0.90
summarizeConversationFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected