(message: ChatMessage)
| 2436 | |
| 2437 | // Message filtering function - hide internal tool results and system messages |
| 2438 | const shouldDisplayMessage = (message: ChatMessage) => { |
| 2439 | const metadata = message.metadata as Record<string, unknown> | null | undefined; |
| 2440 | const contentText = normalizeChatContent(message.content); |
| 2441 | |
| 2442 | if (metadata && (metadata as { hidden_from_ui?: boolean }).hidden_from_ui) { |
| 2443 | return false; |
| 2444 | } |
| 2445 | |
| 2446 | if (metadata && (metadata as { isTransientToolMessage?: boolean }).isTransientToolMessage) { |
| 2447 | if ( |
| 2448 | message.messageType === 'tool_use' || |
| 2449 | message.messageType === 'tool_result' || |
| 2450 | message.role === 'tool' |
| 2451 | ) { |
| 2452 | // Keep transient tool updates visible so users can follow in-flight work |
| 2453 | } else { |
| 2454 | return false; |
| 2455 | } |
| 2456 | } |
| 2457 | |
| 2458 | // **Important**: Always display messages that include attachments |
| 2459 | if (metadata && metadata.attachments && Array.isArray(metadata.attachments) && metadata.attachments.length > 0) { |
| 2460 | console.log('🖼️ Message has attachments, displaying:', { messageId: message.id, attachments: metadata.attachments }); |
| 2461 | return true; |
| 2462 | } |
| 2463 | |
| 2464 | if (message.messageType === 'tool_result') { |
| 2465 | const messageId = message.id ?? ensureStableMessageId(message); |
| 2466 | const visibleSet = visibleToolMessageIdsRef.current; |
| 2467 | |
| 2468 | const hasContent = contentText.trim().length > 0; |
| 2469 | let shouldShow = hasContent; |
| 2470 | |
| 2471 | if (!shouldShow && metadata) { |
| 2472 | const meta = metadata as Record<string, unknown>; |
| 2473 | const summary = |
| 2474 | pickFirstString(meta.summary) ?? |
| 2475 | pickFirstString(meta.result) ?? |
| 2476 | pickFirstString(meta.resultSummary) ?? |
| 2477 | pickFirstString(meta.result_summary) ?? |
| 2478 | pickFirstString(meta.command) ?? |
| 2479 | pickFirstString(meta.content) ?? |
| 2480 | pickFirstString(meta.output); |
| 2481 | const diff = |
| 2482 | pickFirstString(meta.diff) ?? |
| 2483 | pickFirstString(meta.diff_info) ?? |
| 2484 | pickFirstString(meta.toolOutput) ?? |
| 2485 | pickFirstString(meta.tool_output); |
| 2486 | const toolName = |
| 2487 | pickFirstString(meta.tool_name) ?? |
| 2488 | pickFirstString(meta.toolName) ?? |
| 2489 | pickFirstString(meta.action); |
| 2490 | shouldShow = Boolean(summary ?? diff ?? toolName); |
| 2491 | } |
| 2492 | |
| 2493 | if (shouldShow) { |
| 2494 | if (messageId) { |
| 2495 | visibleSet.add(messageId); |
nothing calls this directly
no test coverage detected