Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 54 additions & 0 deletions src/llama-webview-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export class LlamaWebviewProvider implements vscode.WebviewViewProvider {
webviewView.webview.onDidReceiveMessage(
async (message) => {
console.log('Webview received message:', message);
console.log('Message command:', message.command);
switch (message.command) {
case 'sendText':
this.app.llamaAgent.run(message.text);
Expand All @@ -57,6 +58,9 @@ export class LlamaWebviewProvider implements vscode.WebviewViewProvider {
case 'showChatsHistory':
this.app.chatService.selectChatFromList();
break;
case 'deleteCurrentChat':
await this.deleteCurrentChat(webviewView);
break;
case 'configureTools':
await this.app.tools.selectTools()
break;
Expand Down Expand Up @@ -335,6 +339,20 @@ export class LlamaWebviewProvider implements vscode.WebviewViewProvider {
const settingValue = this.app.configuration[message.key as keyof Configuration];
this.updateSettingInEnvView(message.key, settingValue);
break;
case 'deleteCurrentChat':
console.log('Delete current chat triggered');
try {
await this.app.chatService.deleteCurrentChat();
console.log('Chat deleted successfully');
await this.clearChatText(webviewView);
console.log('Chat view cleared');
} catch (error) {
console.error('Error deleting chat:', error);
vscode.window.showErrorMessage('Error deleting chat: ' + (error instanceof Error ? error.message : String(error)));
}
break;
default:
console.log('Unknown command:', message.command);
}
}
);
Expand Down Expand Up @@ -371,6 +389,42 @@ export class LlamaWebviewProvider implements vscode.WebviewViewProvider {
});
}

private async deleteCurrentChat(webviewView: vscode.WebviewView) {
const currentChat = this.app.getChat();
if (!currentChat || !currentChat.id) {
vscode.window.showInformationMessage("No chat to delete. Start a new conversation first.");
return;
}

let chatsList = this.app.persistence.getChats();
if (!chatsList || chatsList.length === 0) {
vscode.window.showInformationMessage("No saved chats to delete.");
return;
}

// Show confirmation dialog with action buttons
const confirmed = await vscode.window.showWarningMessage(
`Delete chat "${currentChat.name || 'Untitled'}"?`,
{ modal: true },
"Delete"
);

if (confirmed === "Delete") {
// Find and remove the current chat from the list
const chatIndex = chatsList.findIndex((chat: any) => chat.id === currentChat.id);
if (chatIndex !== -1) {
chatsList.splice(chatIndex, 1);
await this.app.persistence.setChats(chatsList);

// Clear the UI after deletion
await this.clearChatText(webviewView);
vscode.window.showInformationMessage(`Chat "${currentChat.name || 'Untitled'}" has been deleted.`);
} else {
vscode.window.showWarningMessage("Could not find the chat to delete.");
}
}
}

public addEditAgent(agent: Agent) {
this.app.agentService.resetEditedAgentTools();
agent.tools?.map(tool => this.app.agentService.addEditedAgentTools(tool, ""));
Expand Down
63 changes: 63 additions & 0 deletions src/services/chat-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,69 @@ export class ChatService {
}
}

deleteCurrentChat = async () => {
console.log('deleteCurrentChat called');
try {
const currentChat = this.app.getChat();
console.log('Got current chat, has ID:', !!currentChat?.id, 'name:', currentChat?.name);

if (!currentChat || !currentChat.id) {
console.log('No current chat to delete - showing info message');
vscode.window.showInformationMessage("No chat to delete.");
return;
}

console.log('Asking user for confirmation');
const shouldDelete = await Utils.confirmAction(
"Are you sure you want to delete the current chat?",
"name: " + currentChat.name + "\ndescription: " + currentChat.description
);
console.log('User confirmed deletion:', shouldDelete);

if (shouldDelete) {
console.log('Getting chats list from persistence');
let chatsList = this.app.persistence.getChats();
console.log('Chats list length before:', chatsList?.length);

if (!chatsList || chatsList.length === 0) {
console.log('Chat list is empty');
return;
}

const index = chatsList.findIndex((ch: Chat) => ch.id === currentChat.id);
console.log('Chat index to delete:', index);

if (index !== -1) {
console.log('Splicing chat at index:', index);
chatsList.splice(index, 1);
console.log('Chats list length after splice:', chatsList.length);

console.log('Saving chats to persistence');
await this.app.persistence.setChats(chatsList);
console.log('Persistence updated');

console.log('Updating current chat selection');
await this.selectUpdateChat({ name: "", id: "" });
console.log('Chat selection updated');

console.log('Showing success message');
vscode.window.showInformationMessage("The chat '" + currentChat.name + "' is deleted.");
console.log('Delete completed successfully');
} else {
console.log('Chat not found in list at index:', index);
}
} else {
console.log('User cancelled deletion');
}
} catch (error) {
console.error('Error in deleteCurrentChat:', error instanceof Error ? error.message : String(error));
if (error instanceof Error) {
console.error('Error stack:', error.stack);
}
vscode.window.showErrorMessage('Error: ' + (error instanceof Error ? error.message : String(error)));
}
}

public getChatActions(): vscode.QuickPickItem[] {
return [
{
Expand Down
24 changes: 24 additions & 0 deletions ui/src/components/AgentView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,12 @@ const AgentView: React.FC<AgentViewProps> = ({
});
};

const handleDeleteCurrentChat = () => {
vscode.postMessage({
command: 'deleteCurrentChat'
});
};

const handleFileSelect = (fileLongName: string) => {
// Send the selected file to the extension
setShowFileSelector(false);
Expand Down Expand Up @@ -355,13 +361,31 @@ const AgentView: React.FC<AgentViewProps> = ({
>
New Chat
</button>
<button
onClick={() => {
vscode.postMessage({
command: 'deleteCurrentChat'
});
}}
className="header-btn secondary"
title="Delete Current Chat"
>
🗑️
</button>
<button
onClick={handleChatsHistory}
className="header-btn secondary"
title="View Chats History And Load Old Chats"
>
Chats History
</button>
<button
onClick={handleDeleteCurrentChat}
className="header-btn secondary"
title="Delete This Chat"
>
🗑️
</button>

<button
onClick={handleConfigureTools}
Expand Down