diff --git a/drb-frontend/app/trips/[id]/page.tsx b/drb-frontend/app/trips/[id]/page.tsx index 975d1bc..0458436 100644 --- a/drb-frontend/app/trips/[id]/page.tsx +++ b/drb-frontend/app/trips/[id]/page.tsx @@ -10,6 +10,11 @@ import type { TripEvent, TripRecord, PlaceResult } from "@/lib/types"; // Helpers // --------------------------------------------------------------------------- +function uid(): string { + if (typeof crypto !== "undefined" && crypto.randomUUID) return uid(); + return Math.random().toString(36).slice(2) + Date.now().toString(36); +} + function toMin(t: string): number { const [h, m] = t.split(":").map(Number); return h * 60 + (m ?? 0); @@ -513,7 +518,7 @@ function AssistantPanel({ if (!text || loading) return; setInput(""); - const userMsg: ChatMessage = { id: crypto.randomUUID(), role: "user", content: text }; + const userMsg: ChatMessage = { id: uid(), role: "user", content: text }; setMessages((prev) => [...prev, userMsg]); setLoading(true); @@ -522,7 +527,7 @@ function AssistantPanel({ try { const res = await c2api.tripChat(trip.trip_id, text, history); const assistantMsg: ChatMessage = { - id: crypto.randomUUID(), + id: uid(), role: "assistant", content: res.reply, suggestions: (res.suggestions as unknown as SuggestionCard[]) ?? [], @@ -531,7 +536,7 @@ function AssistantPanel({ } catch { setMessages((prev) => [ ...prev, - { id: crypto.randomUUID(), role: "assistant", content: "Something went wrong. Try again." }, + { id: uid(), role: "assistant", content: "Something went wrong. Try again." }, ]); } finally { setLoading(false);