MCPcopy Index your code
hub / github.com/TanStack/ai / reload

Method reload

packages/ai-client/src/chat-client.ts:1125–1149  ·  view source on GitHub ↗

* Reload the last assistant message

()

Source from the content-addressed store, hash-verified

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

Callers 15

reloadFunction · 0.80
reloadFunction · 0.80
use-chat.test.tsFile · 0.80
reloadFunction · 0.80
use-chat.test.tsFile · 0.80
devtools.test.tsFile · 0.80
useChatFunction · 0.80
use-chat.test.tsFile · 0.80
useChatFunction · 0.80
use-chat.test.tsFile · 0.80

Calls 6

cancelInFlightStreamMethod · 0.95
streamResponseMethod · 0.95
reloadedMethod · 0.80
removeMessagesAfterMethod · 0.80
getMessagesMethod · 0.45
emitSnapshotMethod · 0.45

Tested by

no test coverage detected