Fix assistant

This commit is contained in:
Logan
2026-06-21 14:08:33 -04:00
parent 18d96193ab
commit 39c002d090
+8 -3
View File
@@ -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);