Fix crypto.randomUUID not available in all environments
Replace with a simple counter-based temp ID generator for optimistic UI messages. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -133,6 +133,11 @@ import { chatApi } from '@/services/chat'
|
|||||||
import ChatToolResult from './ChatToolResult.vue'
|
import ChatToolResult from './ChatToolResult.vue'
|
||||||
import type { ChatConversation, ChatMessage } from '@/types'
|
import type { ChatConversation, ChatMessage } from '@/types'
|
||||||
|
|
||||||
|
let _idCounter = 0
|
||||||
|
function tempId(): string {
|
||||||
|
return `temp-${Date.now()}-${++_idCounter}`
|
||||||
|
}
|
||||||
|
|
||||||
const conversations = ref<ChatConversation[]>([])
|
const conversations = ref<ChatConversation[]>([])
|
||||||
const messages = ref<ChatMessage[]>([])
|
const messages = ref<ChatMessage[]>([])
|
||||||
const activeConversationId = ref<string | null>(null)
|
const activeConversationId = ref<string | null>(null)
|
||||||
@@ -189,7 +194,7 @@ async function sendMessage() {
|
|||||||
|
|
||||||
// Add user message optimistically
|
// Add user message optimistically
|
||||||
const userMsg: ChatMessage = {
|
const userMsg: ChatMessage = {
|
||||||
id: crypto.randomUUID(),
|
id: tempId(),
|
||||||
role: 'user',
|
role: 'user',
|
||||||
content: text,
|
content: text,
|
||||||
toolResultType: null,
|
toolResultType: null,
|
||||||
@@ -218,7 +223,7 @@ async function sendMessage() {
|
|||||||
messages.value.push(data.assistantMessage)
|
messages.value.push(data.assistantMessage)
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
messages.value.push({
|
messages.value.push({
|
||||||
id: crypto.randomUUID(),
|
id: tempId(),
|
||||||
role: 'assistant',
|
role: 'assistant',
|
||||||
content: err.response?.data?.message || 'Sorry, something went wrong. Please check that Ollama is running and try again.',
|
content: err.response?.data?.message || 'Sorry, something went wrong. Please check that Ollama is running and try again.',
|
||||||
toolResultType: null,
|
toolResultType: null,
|
||||||
|
|||||||
Reference in New Issue
Block a user