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 // 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 { function toMin(t: string): number {
const [h, m] = t.split(":").map(Number); const [h, m] = t.split(":").map(Number);
return h * 60 + (m ?? 0); return h * 60 + (m ?? 0);
@@ -513,7 +518,7 @@ function AssistantPanel({
if (!text || loading) return; if (!text || loading) return;
setInput(""); setInput("");
const userMsg: ChatMessage = { id: crypto.randomUUID(), role: "user", content: text }; const userMsg: ChatMessage = { id: uid(), role: "user", content: text };
setMessages((prev) => [...prev, userMsg]); setMessages((prev) => [...prev, userMsg]);
setLoading(true); setLoading(true);
@@ -522,7 +527,7 @@ function AssistantPanel({
try { try {
const res = await c2api.tripChat(trip.trip_id, text, history); const res = await c2api.tripChat(trip.trip_id, text, history);
const assistantMsg: ChatMessage = { const assistantMsg: ChatMessage = {
id: crypto.randomUUID(), id: uid(),
role: "assistant", role: "assistant",
content: res.reply, content: res.reply,
suggestions: (res.suggestions as unknown as SuggestionCard[]) ?? [], suggestions: (res.suggestions as unknown as SuggestionCard[]) ?? [],
@@ -531,7 +536,7 @@ function AssistantPanel({
} catch { } catch {
setMessages((prev) => [ setMessages((prev) => [
...prev, ...prev,
{ id: crypto.randomUUID(), role: "assistant", content: "Something went wrong. Try again." }, { id: uid(), role: "assistant", content: "Something went wrong. Try again." },
]); ]);
} finally { } finally {
setLoading(false); setLoading(false);