Total length of user-authored text across the conversation.
(messages: UIMessage[])
| 104 | |
| 105 | /** Total length of user-authored text across the conversation. */ |
| 106 | function userInputChars(messages: UIMessage[]): number { |
| 107 | let total = 0 |
| 108 | for (const message of messages) { |
| 109 | if (message.role !== 'user') continue |
| 110 | for (const part of message.parts) { |
| 111 | if (part.type === 'text' && typeof part.text === 'string') total += part.text.length |
| 112 | } |
| 113 | } |
| 114 | return total |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Strip everything the model shouldn't trust from client-supplied history: |