(content: string)
| 37 | } |
| 38 | |
| 39 | function extractLastUserMessageContent(content: string): string { |
| 40 | const regex = /<user_message>([\s\S]*?)<\/user_message>/gi |
| 41 | const matches = [...content.matchAll(regex)] |
| 42 | if (matches.length > 0) { |
| 43 | const lastMatch = matches[matches.length - 1] |
| 44 | return lastMatch[1].trim() |
| 45 | } |
| 46 | return content.trim() |
| 47 | } |
| 48 | |
| 49 | function queryFromMessages(messages: AdMessage[]): string | null { |
| 50 | const lastUser = [...messages] |