mirror of
https://github.com/pacnpal/Roo-Code.git
synced 2025-12-22 05:11:06 -05:00
Add a button to delete user messages
This commit is contained in:
@@ -70,7 +70,7 @@ export class Cline {
|
||||
diffStrategy?: DiffStrategy
|
||||
diffEnabled: boolean = false
|
||||
|
||||
apiConversationHistory: Anthropic.MessageParam[] = []
|
||||
apiConversationHistory: (Anthropic.MessageParam & { ts?: number })[] = []
|
||||
clineMessages: ClineMessage[] = []
|
||||
private askResponse?: ClineAskResponse
|
||||
private askResponseText?: string
|
||||
@@ -165,11 +165,12 @@ export class Cline {
|
||||
}
|
||||
|
||||
private async addToApiConversationHistory(message: Anthropic.MessageParam) {
|
||||
this.apiConversationHistory.push(message)
|
||||
const messageWithTs = { ...message, ts: Date.now() }
|
||||
this.apiConversationHistory.push(messageWithTs)
|
||||
await this.saveApiConversationHistory()
|
||||
}
|
||||
|
||||
private async overwriteApiConversationHistory(newHistory: Anthropic.MessageParam[]) {
|
||||
async overwriteApiConversationHistory(newHistory: Anthropic.MessageParam[]) {
|
||||
this.apiConversationHistory = newHistory
|
||||
await this.saveApiConversationHistory()
|
||||
}
|
||||
@@ -205,7 +206,7 @@ export class Cline {
|
||||
await this.saveClineMessages()
|
||||
}
|
||||
|
||||
private async overwriteClineMessages(newMessages: ClineMessage[]) {
|
||||
public async overwriteClineMessages(newMessages: ClineMessage[]) {
|
||||
this.clineMessages = newMessages
|
||||
await this.saveClineMessages()
|
||||
}
|
||||
@@ -460,6 +461,11 @@ export class Cline {
|
||||
await this.overwriteClineMessages(modifiedClineMessages)
|
||||
this.clineMessages = await this.getSavedClineMessages()
|
||||
|
||||
// need to make sure that the api conversation history can be resumed by the api, even if it goes out of sync with cline messages
|
||||
|
||||
let existingApiConversationHistory: Anthropic.Messages.MessageParam[] =
|
||||
await this.getSavedApiConversationHistory()
|
||||
|
||||
// Now present the cline messages to the user and ask if they want to resume
|
||||
|
||||
const lastClineMessage = this.clineMessages
|
||||
@@ -493,11 +499,6 @@ export class Cline {
|
||||
responseImages = images
|
||||
}
|
||||
|
||||
// need to make sure that the api conversation history can be resumed by the api, even if it goes out of sync with cline messages
|
||||
|
||||
let existingApiConversationHistory: Anthropic.Messages.MessageParam[] =
|
||||
await this.getSavedApiConversationHistory()
|
||||
|
||||
// v2.0 xml tags refactor caveat: since we don't use tools anymore, we need to replace all tool use blocks with a text block since the API disallows conversations with tool uses and no tool schema
|
||||
const conversationWithoutToolBlocks = existingApiConversationHistory.map((message) => {
|
||||
if (Array.isArray(message.content)) {
|
||||
|
||||
@@ -642,6 +642,28 @@ export class ClineProvider implements vscode.WebviewViewProvider {
|
||||
await this.updateGlobalState("writeDelayMs", message.value)
|
||||
await this.postStateToWebview()
|
||||
break
|
||||
case "deleteMessage": {
|
||||
const answer = await vscode.window.showInformationMessage(
|
||||
"Are you sure you want to delete this message and all subsequent messages?",
|
||||
{ modal: true },
|
||||
"Yes",
|
||||
"No"
|
||||
)
|
||||
if (answer === "Yes" && this.cline && typeof message.value === 'number' && message.value) {
|
||||
const timeCutoff = message.value - 1000; // 1 second buffer before the message to delete
|
||||
const messageIndex = this.cline.clineMessages.findIndex(msg => msg.ts && msg.ts >= timeCutoff)
|
||||
const apiConversationHistoryIndex = this.cline.apiConversationHistory.findIndex(msg => msg.ts && msg.ts >= timeCutoff)
|
||||
if (messageIndex !== -1) {
|
||||
const { historyItem } = await this.getTaskWithId(this.cline.taskId)
|
||||
await this.cline.overwriteClineMessages(this.cline.clineMessages.slice(0, messageIndex))
|
||||
if (apiConversationHistoryIndex !== -1) {
|
||||
await this.cline.overwriteApiConversationHistory(this.cline.apiConversationHistory.slice(0, apiConversationHistoryIndex))
|
||||
}
|
||||
await this.initClineWithHistoryItem(historyItem)
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
case "screenshotQuality":
|
||||
await this.updateGlobalState("screenshotQuality", message.value)
|
||||
await this.postStateToWebview()
|
||||
|
||||
Reference in New Issue
Block a user