( history: readonly ContextMessage[], )
| 212 | } |
| 213 | |
| 214 | function undoAvailabilityFromContext( |
| 215 | history: readonly ContextMessage[], |
| 216 | ): UndoAvailability { |
| 217 | let maxCount = 0; |
| 218 | let stoppedAtCompaction = false; |
| 219 | |
| 220 | for (let i = history.length - 1; i >= 0; i--) { |
| 221 | const message = history[i]; |
| 222 | if (message === undefined) continue; |
| 223 | if (message.origin?.kind === 'injection') continue; |
| 224 | if (message.origin?.kind === 'compaction_summary') { |
| 225 | stoppedAtCompaction = true; |
| 226 | break; |
| 227 | } |
| 228 | if (isContextUndoAnchor(message)) maxCount++; |
| 229 | } |
| 230 | |
| 231 | return { maxCount, stoppedAtCompaction }; |
| 232 | } |
| 233 | |
| 234 | function isContextUndoAnchor(message: ContextMessage): boolean { |
| 235 | if (message.role !== 'user') return false; |
no test coverage detected