diff --git a/src/App.tsx b/src/App.tsx index 4ba0359..21f5e5c 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -102,6 +102,28 @@ export default function App() { } return n; }; + // Cold-start: if localStorage heads map is empty/stale (fresh browser, + // private window, cleared site data), fetch the last message per thread + // ONCE on first mount so the badge isn't lying. Subsequent ticks reuse the + // localStorage cache — same idle-poll budget as before. + const seedHeadsIfMissing = async (threads: { _key: string }[]) => { + try { + const existing = JSON.parse(localStorage.getItem(`fm.canvas.chat.heads.${userEmail}`) || "{}"); + if (Object.keys(existing).length >= threads.length) return; + } catch { /* fall through */ } + const { chatApi } = await import("./lib/chatApi"); + const heads: Record = {}; + await Promise.all( + threads.map(async (t) => { + try { + const rows = await chatApi.listMessages(t._key); + const last = rows[rows.length - 1]; + if (last) heads[t._key] = { at: last.created_at, by: last.author_email }; + } catch { /* ignore */ } + }) + ); + try { localStorage.setItem(`fm.canvas.chat.heads.${userEmail}`, JSON.stringify(heads)); } catch { /* ignore */ } + }; const refresh = async () => { try { const { chatApi } = await import("./lib/chatApi"); @@ -111,6 +133,8 @@ export default function App() { apiMod.workItems().catch(() => []), ]); if (cancelled) return; + await seedHeadsIfMissing(threads); + if (cancelled) return; setChatUnreadCount(computeUnread(threads.map((t) => t._key))); setQueueCount(items.filter((it) => (it as any).tenant_id === tenantId).length); } catch { /* ignore */ } diff --git a/src/scenes/Wizard.tsx b/src/scenes/Wizard.tsx index 2283deb..daa524a 100644 --- a/src/scenes/Wizard.tsx +++ b/src/scenes/Wizard.tsx @@ -281,7 +281,7 @@ export default function Wizard() {
  • {i + 1} {n.display_name || "Untitled step"} - {({ human: "Person", agent: "Assistant", system: "System" } as Record)[n.dispatch_kind || "human"] || "Person"} + {({ human: "Manual review", agent: "Assistant", system: "System" } as Record)[n.dispatch_kind || "human"] || "Manual review"}
  • ))} @@ -412,7 +412,7 @@ export default function Wizard() { updateDraft({ nodes: newNodes }); }} > - +