MCPcopy Create free account
hub / github.com/Noumena-Network/code / hasOnlyWhitespaceTextContent

Function hasOnlyWhitespaceTextContent

src/utils/messages.ts:4935–4955  ·  view source on GitHub ↗

* Check if an assistant message has only whitespace-only text content blocks. * Returns true if all content blocks are text blocks with only whitespace. * Returns false if there are any non-text blocks (like tool_use) or text with actual content.

(
  content: Array<{ type: string; text?: string }>,
)

Source from the content-addressed store, hash-verified

4933 * Returns false if there are any non-text blocks (like tool_use) or text with actual content.
4934 */
4935function hasOnlyWhitespaceTextContent(
4936 content: Array<{ type: string; text?: string }>,
4937): boolean {
4938 if (content.length === 0) {
4939 return false
4940 }
4941
4942 for (const block of content) {
4943 // If there's any non-text block (tool_use, thinking, etc.), the message is valid
4944 if (block.type !== 'text') {
4945 return false
4946 }
4947 // If there's a text block with non-whitespace content, the message is valid
4948 if (block.text !== undefined && block.text.trim() !== '') {
4949 return false
4950 }
4951 }
4952
4953 // All blocks are text blocks with only whitespace
4954 return true
4955}
4956
4957/**
4958 * Filter out assistant messages with only whitespace-only text content.

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected