* Extract plain-text content from a message for indexing.
(content: Conversation["messages"][number]["content"])
| 41 | * Extract plain-text content from a message for indexing. |
| 42 | */ |
| 43 | function messageText(content: Conversation["messages"][number]["content"]): string { |
| 44 | if (typeof content === "string") return content; |
| 45 | if (!Array.isArray(content)) return ""; |
| 46 | |
| 47 | return content |
| 48 | .map((block) => { |
| 49 | if (block.type === "text") return block.text; |
| 50 | if (block.type === "tool_use") return `${block.name} ${JSON.stringify(block.input)}`; |
| 51 | if (block.type === "tool_result") { |
| 52 | return typeof block.content === "string" |
| 53 | ? block.content |
| 54 | : extractTextContent(block.content); |
| 55 | } |
| 56 | return ""; |
| 57 | }) |
| 58 | .join(" "); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Run a client-side full-text search over an array of conversations. |
no test coverage detected