feat: add message editing
This commit adds message editing as a feature. To accomplish this, the settings dialog was refactored into a singleton and now the message edit and settings use the singleton where appropriate.
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
<script setup lang="ts">
|
||||
import type { Message } from '~/composables/useChat';
|
||||
import { assert } from '~~/utils/assert';
|
||||
|
||||
const triplit = useTriplitClient();
|
||||
const { openDialog } = useDialog();
|
||||
|
||||
const { message } = defineProps<{
|
||||
message: Message
|
||||
@@ -88,6 +90,26 @@ const regenerateMessage = async () => {
|
||||
emit('regenerate');
|
||||
}
|
||||
|
||||
const handleEdit = async () => {
|
||||
openDialog<string>(DialogType.Textbox, async (res) => {
|
||||
if (res.ok) {
|
||||
if (!res.data) return;
|
||||
|
||||
await triplit.update('messages', message.id, {
|
||||
content: res.data
|
||||
});
|
||||
|
||||
assert('flush' in triplit);
|
||||
await triplit.flush();
|
||||
|
||||
await regenerateMessage();
|
||||
}
|
||||
}, {
|
||||
title: 'Edit Message',
|
||||
initialValue: message.content
|
||||
});
|
||||
};
|
||||
|
||||
const deleteMessage = () => {
|
||||
if (focusedIndex.value !== 0 && focusedIndex.value === message.children.length) {
|
||||
focusedIndex.value = Math.max(0, focusedIndex.value - 1);
|
||||
@@ -135,6 +157,10 @@ const messageCount = computed(() => {
|
||||
class="flex justify-center items-center w-7 h-6 hover:bg-[var(--color-hover)]">
|
||||
<Icon name="mynaui:refresh" class="text-4.5" />
|
||||
</button>
|
||||
<button v-if="message.role === 'user'" @click="handleEdit"
|
||||
class="flex justify-center items-center w-7 h-6 hover:bg-[var(--color-hover)]">
|
||||
<Icon name="mynaui:pencil" class="text-4.5" />
|
||||
</button>
|
||||
<button @click="copyMessage" :class="{ 'text-emerald-500': copied }"
|
||||
class="flex justify-center items-center w-7 h-6 hover:bg-[var(--color-hover)]">
|
||||
<Icon :name="copied ? 'mynaui:check' : 'mynaui:copy'" class="text-4.5" />
|
||||
|
||||
Reference in New Issue
Block a user