web: fallback when crypto.randomUUID() is unavailable

Some browsers and insecure contexts (plain HTTP) throw on
crypto.randomUUID(), which silently breaks the chat UI.
Fall back to a plain UUID v4 generator when the native call
fails - same behaviour on modern browsers, works everywhere
else.
This commit is contained in:
rene
2026-07-15 14:20:50 +02:00
parent 3fd47b7bbd
commit 869e80ee2d
+5 -1
View File
@@ -34,7 +34,11 @@ import { Brain } from "./Brain"
import { persistPublicSettings, stored } from "@/lib/storage"
import { cn } from "@/lib/utils"
const message = (role: ChatMessage["role"], content: string): ChatMessage => ({ id: crypto.randomUUID(), role, content })
const message = (role: ChatMessage["role"], content: string): ChatMessage => {
let id: string
try { id = crypto.randomUUID() } catch { id = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => { const r = Math.random() * 16 | 0; return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16) }) }
return { id, role, content }
}
export default function App() {
// When the page is served by the engine itself (coli web), same-origin is the