Skip to content

Commit 8f08718

Browse files
Add ClearChatButton component and related logic
1 parent 2a9d980 commit 8f08718

File tree

4 files changed

+46
-3
lines changed

4 files changed

+46
-3
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<script lang="ts" setup>
2+
import { useI18n } from 'vue-i18n'
3+
4+
const { t } = useI18n()
5+
6+
defineEmits(['clearChat'])
7+
</script>
8+
9+
<template>
10+
<button
11+
@click="$emit('clearChat')"
12+
class="flex items-center p-2 my-2 text-white bg-red-600 w-full h-8 rounded-md hover:bg-red-700"
13+
>
14+
{{ t('clearChat') }}
15+
</button>
16+
</template>
17+
18+
<i18n>
19+
{
20+
"en": {
21+
"clearChat": "Clear chat"
22+
},
23+
"es": {
24+
"clearChat": "Limpiar chat"
25+
}
26+
}
27+
</i18n>

browser-extension/src/components/CopilotChat.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const emit = defineEmits<{
1414
(e: 'close'): void,
1515
(e: 'userMessage', text: string, file: Record<string, string>): void,
1616
(e: 'minimize'): void,
17+
(e: 'clearChat'): void
1718
}>()
1819
1920
const messagesDiv = ref<HTMLDivElement>()
@@ -64,7 +65,7 @@ const lastMessage = computed((): ChatMessage => props.messages[props.messages.le
6465
</template>
6566
<template v-slot:modalsContainer>
6667
<CopilotConfig :show="showConfig" :agent-id="agentId" :agent-name="agentName" :agent-logo="agentLogo"
67-
@close="showConfig = false" />
68+
@close="showConfig = false" @clear-chat="$emit('clearChat')" />
6869
</template>
6970
</PageOverlay>
7071
</template>

browser-extension/src/components/CopilotConfig.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import Modal from './Modal.vue'
77
import ModalForm from './ModalForm.vue'
88
import PromptEditor from './PromptEditor.vue'
99
import NewPromptButton from './NewPromptButton.vue'
10+
import ClearChatButton from './ClearChatButton.vue'
1011
1112
const props = defineProps<{ agentId: string, agentName: string, agentLogo: string, show: boolean }>()
12-
const emit = defineEmits(['close'])
13+
const emit = defineEmits(['close', 'clearChat'])
1314
const { t } = useI18n()
1415
const prompts = ref<Prompt[]>()
1516
const editingPrompt = ref<Prompt>()
@@ -60,6 +61,11 @@ const confirmPromptRemoval = async () => {
6061
prompts.value?.splice(deletingPromptIndex.value, 1)
6162
closePromptDeletionConfirmation()
6263
}
64+
65+
const clearChat = () => {
66+
emit('clearChat')
67+
close()
68+
}
6369
</script>
6470

6571
<template>
@@ -69,6 +75,7 @@ const confirmPromptRemoval = async () => {
6975
<div class="flex-auto self-center cursor-pointer p-1" @click="editingPrompt = prompt">{{ prompt.name }}</div>
7076
<button @click="removePrompt(index)"><trash-x-icon class="action-icon" /></button>
7177
</div>
78+
<ClearChatButton @clear-chat="clearChat" />
7279
</Modal>
7380
<PromptEditor :name="editingPrompt?.name || ''" :text="editingPrompt?.text || ''" @close="closePromptEditor"
7481
@saved="onPromptUpdate" :show="editingPrompt !== undefined" :agent-id="agentId" />

browser-extension/src/pages/Index.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,14 @@ const onAgentError = (error: any) => {
200200
}
201201
}
202202
203+
const onClearChat = () => {
204+
messages.value = []
205+
206+
if (messages.value.length === 0 && agent.value) {
207+
messages.value.push(ChatMessage.agentMessage(agent.value.manifest.welcomeMessage))
208+
}
209+
}
210+
203211
const sidebarClasses = computed(() => [
204212
'fixed flex flex-col bg-white border border-gray-300',
205213
isMinimized.value
@@ -213,7 +221,7 @@ const sidebarClasses = computed(() => [
213221
<div v-if="!isMinimized" class="absolute left-0 z-auto cursor-ew-resize w-2 h-full" @mousedown="onStartResize" />
214222
<CopilotChat v-if="agent" :messages="messages" :agent-id="agent.manifest.id" :agent-name="agent.manifest.name"
215223
:agent-logo="agent.logo" :agent-capabilities="agent.manifest.capabilities || []" @userMessage="onUserMessage"
216-
@close="onCloseSidebar" @minimize="onMinimizeSidebar" :minimized="isMinimized" />
224+
@close="onCloseSidebar" @minimize="onMinimizeSidebar" :minimized="isMinimized" @clear-chat="onClearChat" />
217225
<CopilotList v-if="!agent" @activateAgent="onActivateAgent" @close="onCloseSidebar" />
218226
</div>
219227
</template>

0 commit comments

Comments
 (0)