MCPcopy Create free account
hub / github.com/freecodexyz/free-code / extractMessageText

Function extractMessageText

src/utils/agenticSessionSearch.ts:57–81  ·  view source on GitHub ↗

* Extracts searchable text content from a message.

(message: SerializedMessage)

Source from the content-addressed store, hash-verified

55 * Extracts searchable text content from a message.
56 */
57function extractMessageText(message: SerializedMessage): string {
58 if (message.type !== 'user' && message.type !== 'assistant') {
59 return ''
60 }
61
62 const content = 'message' in message ? message.message?.content : undefined
63 if (!content) return ''
64
65 if (typeof content === 'string') {
66 return content
67 }
68
69 if (Array.isArray(content)) {
70 return content
71 .map(block => {
72 if (typeof block === 'string') return block
73 if ('text' in block && typeof block.text === 'string') return block.text
74 return ''
75 })
76 .filter(Boolean)
77 .join(' ')
78 }
79
80 return ''
81}
82
83/**
84 * Extracts a truncated transcript from session messages.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected