(
messages: WithParts[],
startIndex?: number,
)
| 3 | import { isMessageWithInfo } from "./shape" |
| 4 | |
| 5 | export const getLastUserMessage = ( |
| 6 | messages: WithParts[], |
| 7 | startIndex?: number, |
| 8 | ): WithParts | null => { |
| 9 | const start = startIndex ?? messages.length - 1 |
| 10 | for (let i = start; i >= 0; i--) { |
| 11 | const msg = messages[i] |
| 12 | if (!isMessageWithInfo(msg)) { |
| 13 | continue |
| 14 | } |
| 15 | if (msg.info.role === "user" && !isIgnoredUserMessage(msg)) { |
| 16 | return msg |
| 17 | } |
| 18 | } |
| 19 | return null |
| 20 | } |
| 21 | |
| 22 | export const messageHasCompress = (message: WithParts): boolean => { |
| 23 | if (!isMessageWithInfo(message)) { |
no test coverage detected