* Reload the last assistant message
()
| 1123 | * Reload the last assistant message |
| 1124 | */ |
| 1125 | async reload(): Promise<void> { |
| 1126 | const messages = this.processor.getMessages() |
| 1127 | if (messages.length === 0) return |
| 1128 | |
| 1129 | // Find the last user message |
| 1130 | const lastUserMessageIndex = messages.findLastIndex( |
| 1131 | (m) => m.role === 'user', |
| 1132 | ) |
| 1133 | |
| 1134 | if (lastUserMessageIndex === -1) return |
| 1135 | |
| 1136 | // Cancel any active stream before reloading |
| 1137 | if (this.isLoading) { |
| 1138 | this.cancelInFlightStream() |
| 1139 | } |
| 1140 | |
| 1141 | this.events.reloaded(lastUserMessageIndex) |
| 1142 | |
| 1143 | // Remove all messages after the last user message |
| 1144 | this.processor.removeMessagesAfter(lastUserMessageIndex) |
| 1145 | this.devtoolsBridge.emitSnapshot() |
| 1146 | |
| 1147 | // Resend |
| 1148 | await this.streamResponse() |
| 1149 | } |
| 1150 | |
| 1151 | /** |
| 1152 | * Stop the current stream |
no test coverage detected