Core Architecture and Data Flow
The Desktop UI follows a unidirectional data flow pattern where the frontend consumes a comprehensiveDesktopCompanionSnapshot apps/desktop/ui/src/lib/desktopApi.ts#227-243 provided by the backend.
The Synchronization Loop
TheuseDesktopCompanion hook manages the lifecycle of data fetching. It implements an adaptive polling mechanism that adjusts based on the connection state:
- Active Refresh: 5,000ms when connected apps/desktop/ui/src/hooks/useDesktopCompanion.ts#18.
- Idle Refresh: 12,000ms when offline or degraded apps/desktop/ui/src/hooks/useDesktopCompanion.ts#19.
getDesktopCompanionSnapshot apps/desktop/ui/src/lib/desktopApi.ts#50 to invoke the Tauri command and updates the React state via startTransition to maintain UI responsiveness apps/desktop/ui/src/hooks/useDesktopCompanion.ts#52-56.
Desktop API Bridge
ThedesktopApi.ts file acts as the translation layer between the TypeScript frontend and the Rust backend. It uses Tauri’s invoke apps/desktop/ui/src/lib/desktopApi.ts#1 to call commands defined in the src-tauri crate.
| Function | Purpose | Backend Entity |
|---|---|---|
getDesktopCompanionSnapshot | Fetches the full UI state. | get_desktop_companion_snapshot |
sendDesktopCompanionChatMessage | Dispatches user input to the agent. | send_desktop_companion_chat_message |
decideDesktopCompanionApproval | Submits a Human-in-the-loop decision. | decide_desktop_companion_approval |
updateDesktopCompanionPreferences | Persists UI state (active tab, etc). | update_desktop_companion_preferences |
Component Hierarchy and Navigation
TheApp.tsx file serves as the root layout and state coordinator. It manages several UI-specific states that are not persisted in the daemon, such as active session selections and draft message content.
System Navigation
The UI is divided into five primary sections defined byDesktopCompanionSection apps/desktop/ui/src/lib/desktopApi.ts#17:
- Home: System health, process monitors, and quick facts.
- Chat: Real-time interaction with the agent and session management.
- Approvals: Queue for pending tool execution requests.
- Access: Inventory of paired devices and their trust states.
- Onboarding: Guided setup for external connectors (e.g., Discord).
State Synchronization Diagram
This diagram bridges the ReactApp state with the underlying Rust DesktopCompanionSnapshot.
Title: Desktop UI State Mapping
Sources: apps/desktop/ui/src/App.tsx#52-135, apps/desktop/src-tauri/src/companion.rs#51-67
Companion Shell and Styling
The UI is designed to feel like a native desktop utility rather than a standard web page. This is achieved through specific CSS variables and layout constraints defined instyles.css.
Visual Constraints
- Width: Limited to
1100pxvia--desktop-shell-widthapps/desktop/ui/src/styles.css#8. - Theme: Forced dark mode via the
darkclass on the HTML element apps/desktop/ui/index.html#2 and Tailwind/HeroUI configurations apps/desktop/ui/src/styles.css#1-5. - Layout: Uses a CSS Grid system for “cards” (e.g.,
.desktop-card) to ensure consistent spacing and borders apps/desktop/ui/src/styles.css#74-78.
Native Integration Features
The UI interacts with native OS features through the Tauri bridge:- Notifications: The
Appcomponent monitors theunreadNotificationsarray in the snapshot and triggers the Web Notification API when new items appear apps/desktop/ui/src/App.tsx#170-185. - Window Visibility: Upon initialization, the UI calls
showMainWindow()to ensure the Tauri window is visible to the user only after the initial state is loaded apps/desktop/ui/src/App.tsx#153-168.
Onboarding and Connector Flows
The Onboarding section apps/desktop/ui/src/lib/desktopApi.ts#197-208 is a specialized state machine that guides the user through complex setup tasks, such as Discord bot integration.Data Flow for Discord Onboarding
This diagram illustrates how the UI coordinates between the user, the Tauri backend, and the Palyra daemon during onboarding. Title: Discord Connector Onboarding FlowOnboarding Progress Tracking
The UI calculates progress usingprogress_completed and progress_total from the snapshot apps/desktop/ui/src/App.tsx#96. If a failure occurs during setup, the recovery object apps/desktop/ui/src/lib/desktopApi.ts#205-207 provides a user-facing error message to help resolve configuration issues.
Sources: apps/desktop/ui/src/lib/desktopApi.ts#197-208, apps/desktop/ui/src/App.tsx#96, apps/desktop/src-tauri/src/companion.rs#54