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

Function extractUserMessageText

src/bridge/sessionRunner.ts:269–296  ·  view source on GitHub ↗

* Extract plain text from a replayed SDKUserMessage NDJSON line. Returns the * trimmed text if this looks like a real human-authored message, otherwise * undefined so the caller keeps waiting for the first real message.

(
  msg: Record<string, unknown>,
)

Source from the content-addressed store, hash-verified

267 * undefined so the caller keeps waiting for the first real message.
268 */
269function extractUserMessageText(
270 msg: Record<string, unknown>,
271): string | undefined {
272 // Skip tool-result user messages (wrapped subagent results) and synthetic
273 // caveat messages — neither is human-authored.
274 if (msg.parent_tool_use_id != null || msg.isSynthetic || msg.isReplay)
275 return undefined
276
277 const message = msg.message as Record<string, unknown> | undefined
278 const content = message?.content
279 let text: string | undefined
280 if (typeof content === 'string') {
281 text = content
282 } else if (Array.isArray(content)) {
283 for (const block of content) {
284 if (
285 block &&
286 typeof block === 'object' &&
287 (block as Record<string, unknown>).type === 'text'
288 ) {
289 text = (block as Record<string, unknown>).text as string | undefined
290 break
291 }
292 }
293 }
294 text = text?.trim()
295 return text ? text : undefined
296}
297
298/** Build a short preview of tool input for debug logging. */
299function inputPreview(input: Record<string, unknown>): string {

Callers 1

spawnFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected