fix(frontend): use uuid v4 instead of crypto.randomUUID

This commit is contained in:
2025-08-25 14:45:12 +08:00
parent 931eb1160c
commit 3c8d2dab7e
2 changed files with 6 additions and 4 deletions

View File

@@ -18,6 +18,7 @@
,"marked": "^6.0.0", ,"marked": "^6.0.0",
"dompurify": "^3.0.0", "dompurify": "^3.0.0",
"highlight.js": "^11.8.0" "highlight.js": "^11.8.0"
,"uuid": "^9.0.0"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^24.3.0", "@types/node": "^24.3.0",

View File

@@ -37,6 +37,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, onMounted, nextTick, computed, watch } from 'vue'; import { ref, onMounted, nextTick, computed, watch } from 'vue';
import { v4 as uuidv4 } from 'uuid';
import { useModelStore } from '@/stores/modelStore'; import { useModelStore } from '@/stores/modelStore';
import { chatWithModel, StreamPayload } from '@/services/chatService'; import { chatWithModel, StreamPayload } from '@/services/chatService';
import { useConversationStore } from '@/stores/conversationStore'; import { useConversationStore } from '@/stores/conversationStore';
@@ -70,9 +71,9 @@ function formatMessage(md: string) {
async function handleSend() { async function handleSend() {
const text = input.value.trim(); const text = input.value.trim();
if (!text || pending.value) return; if (!text || pending.value) return;
const userMsg: ChatMessage = { id: crypto.randomUUID(), role: 'user', content: text, html: renderMarkdown(text) }; const userMsg: ChatMessage = { id: uuidv4(), role: 'user', content: text, html: renderMarkdown(text) };
messages.value.push(userMsg); messages.value.push(userMsg);
const aiId = crypto.randomUUID(); const aiId = uuidv4();
messages.value.push({ id: aiId, role: 'assistant', segments: [], loading: true, html: '' }); messages.value.push({ id: aiId, role: 'assistant', segments: [], loading: true, html: '' });
input.value = ''; input.value = '';
pending.value = true; pending.value = true;
@@ -146,8 +147,8 @@ watch(() => convStore.currentId, (id) => {
if (!id) { messages.value = []; conversationId.value = null; return; } if (!id) { messages.value = []; conversationId.value = null; return; }
// load messages from store and precompute html // load messages from store and precompute html
messages.value = convStore.messages.map(m => m.role === 'user' messages.value = convStore.messages.map(m => m.role === 'user'
? { id: crypto.randomUUID(), role: 'user', content: m.content, html: renderMarkdown(m.content) } ? { id: uuidv4(), role: 'user', content: m.content, html: renderMarkdown(m.content) }
: { id: crypto.randomUUID(), role: 'assistant', segments: [{ kind: 'answer', text: m.content, html: renderMarkdown(m.content) }] } : { id: uuidv4(), role: 'assistant', segments: [{ kind: 'answer', text: m.content, html: renderMarkdown(m.content) }] }
); );
conversationId.value = id; conversationId.value = id;
scrollBottom(); scrollBottom();