| 241 | } |
| 242 | |
| 243 | function extractMessageText(message: Partial<AgentMessage>): string { |
| 244 | const content = (message as { content?: unknown }).content; |
| 245 | if (typeof content === "string") return content; |
| 246 | if (!Array.isArray(content)) return ""; |
| 247 | return content |
| 248 | .map((block) => |
| 249 | block && typeof block === "object" |
| 250 | && (block as { type?: string }).type === "text" |
| 251 | && typeof (block as { text?: unknown }).text === "string" |
| 252 | ? (block as { text: string }).text |
| 253 | : "") |
| 254 | .filter(Boolean) |
| 255 | .join("\n"); |
| 256 | } |
| 257 | |
| 258 | function imageSignature(block: unknown): string { |
| 259 | if (!block || typeof block !== "object" || (block as { type?: unknown }).type !== "image") return ""; |