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