* Extracts a truncated transcript from session messages.
(messages: SerializedMessage[])
| 84 | * Extracts a truncated transcript from session messages. |
| 85 | */ |
| 86 | function extractTranscript(messages: SerializedMessage[]): string { |
| 87 | if (messages.length === 0) return '' |
| 88 | |
| 89 | // Take messages from start and end to get context |
| 90 | const messagesToScan = |
| 91 | messages.length <= MAX_MESSAGES_TO_SCAN |
| 92 | ? messages |
| 93 | : [ |
| 94 | ...messages.slice(0, MAX_MESSAGES_TO_SCAN / 2), |
| 95 | ...messages.slice(-MAX_MESSAGES_TO_SCAN / 2), |
| 96 | ] |
| 97 | |
| 98 | const text = messagesToScan |
| 99 | .map(extractMessageText) |
| 100 | .filter(Boolean) |
| 101 | .join(' ') |
| 102 | .replace(/\s+/g, ' ') |
| 103 | .trim() |
| 104 | |
| 105 | return text.length > MAX_TRANSCRIPT_CHARS |
| 106 | ? text.slice(0, MAX_TRANSCRIPT_CHARS) + '…' |
| 107 | : text |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Checks if a log contains the query term in any searchable field. |
no outgoing calls
no test coverage detected