MCPcopy
hub / github.com/TanStack/ai / clear

Method clear

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

* Clear all messages

()

Source from the content-addressed store, hash-verified

1164 * Clear all messages
1165 */
1166 clear(): void {
1167 if (this.persistor) {
1168 this.persistor.snapshotClear({
1169 messages: this.processor.getMessages(),
1170 activeRunIds: this.activeRunIds,
1171 currentRunId: this.currentRunId,
1172 })
1173 if (this.isLoading) {
1174 this.cancelInFlightStream({ setReadyStatus: true })
1175 this.resetSessionGenerating()
1176 } else if (this.activeRunIds.size > 0) {
1177 this.resetSessionGenerating()
1178 }
1179 // Suppress persisting the empty snapshot that clearMessages emits, then
1180 // remove the stored conversation outright.
1181 this.persistor.beginClear()
1182 }
1183 this.processor.clearMessages()
1184 this.persistor?.remove()
1185 this.setError(undefined)
1186 this.events.messagesCleared()
1187 }
1188
1189 /**
1190 * Add the result of a client-side tool execution

Callers

nothing calls this directly

Calls 9

cancelInFlightStreamMethod · 0.95
setErrorMethod · 0.95
snapshotClearMethod · 0.80
beginClearMethod · 0.80
clearMessagesMethod · 0.80
messagesClearedMethod · 0.80
removeMethod · 0.65
getMessagesMethod · 0.45

Tested by

no test coverage detected