/** * WorkspaceBriefing — "home screen" shown in ChatApp when no messages exist. * Displays workspace context: greeting, memories, decisions, tasks, suggested prompts. * Fetches from GET /api/workspaces/:id/context. */ import { useState, useEffect, useMemo } from 'react'; import { Brain, Clock, CheckCircle2, AlertTriangle, MessageSquare, Lightbulb, ChevronRight, Layers, ChevronDown, ChevronUp, Wrench, } from 'lucide-react'; import { adapter } from '@/lib/adapter'; import { DATE_LOCALE } from '@/lib/date-locale'; import { HintTooltip } from '@/components/ui/hint-tooltip'; import type { WorkspaceContext } from '@/lib/types'; import { readWorkspaceBriefingCollapsed, writeWorkspaceBriefingCollapsed, } from '@/lib/workspace-briefing-state'; import { recommendSkills } from '@/lib/skill-recommendations'; import { formatPersonaName } from '@/lib/persona-display'; interface WorkspaceBriefingProps { workspaceId: string; /** * Active workspace's persona id. When set, a "Skills for [Persona]" chip * row is rendered alongside the existing context-aware suggestedPrompts. * Optional — when omitted, the chip row is silently skipped. */ personaId?: string; onSendMessage?: (msg: string) => void; /** * Pre-fill the input WITHOUT auto-sending. Used by skill chips, where * the starter is a partial sentence ("Brainstorm ideas for: ") that the * user must finish before sending. Different from onSendMessage which * (per ChatApp wiring at line 994) pre-fills and auto-sends after a 1s * confirm delay. */ onPrefill?: (msg: string) => void; onSelectSession?: (id: string) => void; } const WorkspaceBriefing = ({ workspaceId, personaId, onSendMessage, onPrefill, onSelectSession }: WorkspaceBriefingProps) => { const [ctx, setCtx] = useState(null); const [loading, setLoading] = useState(true); // M-23 / ENG-2: collapse state persists per-workspace so it survives // reload and stays scoped to the current workspace. const [collapsed, setCollapsedState] = useState(() => readWorkspaceBriefingCollapsed(workspaceId)); // Persona-aware skill chips (Phase 4c). Falls back to universal defaults // when personaId is missing or unknown — the chip row never strands empty. const skillChips = useMemo(() => recommendSkills(personaId), [personaId]); const personaLabel = useMemo(() => formatPersonaName(personaId), [personaId]); useEffect(() => { setLoading(true); setCollapsedState(readWorkspaceBriefingCollapsed(workspaceId)); adapter.getWorkspaceContext(workspaceId) .then(setCtx) .catch(() => setCtx(null)) .finally(() => setLoading(false)); }, [workspaceId]); const toggleCollapsed = () => { const next = !collapsed; setCollapsedState(next); writeWorkspaceBriefingCollapsed(workspaceId, next); }; if (loading) { // Wave T Lane E fix 3: the chat's entry loading is a thread-shaped skeleton // (message rhythm: bee-avatar + assistant lines, a right-aligned user bubble) // instead of a bare centered spinner + "Loading workspace…" — so entering a // chat reads as "your conversation is loading", not a lie about an empty box. // sr-only text keeps the screen-reader announcement; reduced-motion stills it. return (
Loading conversation…