This document outlines the chat interface architecture for SAM, designed to match SAM 1.0's quality and user experience while leveraging the completed streaming implementation.
Purpose: Main chat window with navigation and conversation management
Location: Sources/UserInterface/Chat/MainChatView.swift
Pattern: NavigationSplitView with sidebar + content layout
struct MainChatView: View {
// Sidebar: Conversation list with search and filters
// Content: Active conversation display
// Toolbar: New conversation, settings, inspector toggle
}Key Features:
- NavigationSplitView layout matching SAM 1.0
- Conversation list sidebar with search/filtering
- Active conversation display area
- Toolbar with new chat, settings, inspector actions
- Integration with existing EndpointManager for model access
Purpose: Display and manage conversation history
Location: Sources/UserInterface/Chat/ConversationListView.swift
Pattern: List with custom conversation rows
struct ConversationListView: View {
// List of conversations with titles and metadata
// Search and filter functionality
// New conversation creation
// Conversation selection management
}Key Features:
- Conversation list with titles and timestamps
- Search and filtering capabilities
- Active conversation highlighting
- Context menu actions (delete, export, rename)
- Drag and drop organization
Purpose: Display active conversation with messages and input
Location: Sources/UserInterface/Chat/EnhancedConversationView.swift
Pattern: VStack with header, messages, input areas
struct EnhancedConversationView: View {
// Conversation header with title and status
// Scrollable message list with auto-scroll
// Enhanced message input area
// Streaming status indicators
}Key Features:
- Enhanced header matching SAM 1.0 design
- Message list with proper auto-scrolling
- Integration with existing ChatWidget streaming
- Status indicators for processing/streaming
- Model selection and configuration UI
Purpose: Individual message display with rich formatting
Location: Sources/UserInterface/Chat/MessageBubbleView.swift
Pattern: HStack with role-based alignment and styling
struct MessageBubbleView: View {
// Role-based message alignment (user right, assistant left)
// Rich markdown rendering
// Hover actions (edit, copy, regenerate, delete)
// Timestamp and metadata display
}Key Features:
- User messages: right-aligned, blue styling
- Assistant messages: left-aligned, gray styling
- Full markdown support with syntax highlighting
- Hover actions: edit, regenerate, copy, delete
- Message metadata: tokens, timestamp, formatting indicators
- Copy and text selection support
Purpose: Enhanced message input with streaming integration
Location: Sources/UserInterface/Chat/StreamingMessageInput.swift
Pattern: Enhanced TextEditor with send controls
struct StreamingMessageInput: View {
// Multi-line text input with auto-resize
// Send button with streaming state management
// Model/provider selection integration
// Attachment support preparation
}Key Features:
- Multi-line text input with proper sizing
- Send button with streaming state management
- Integration with EndpointManager for model selection
- Keyboard shortcuts and accessibility
- Placeholder for future attachment support
Purpose: Provide visibility into agent's knowledge and context state
Location: Sources/UserInterface/Chat/ChatWidget.swift (sessionIntelligencePanel)
Pattern: VStack with three distinct sections
struct SessionIntelligencePanel: View {
// Memory Status section
// Context Management section
// Enhanced Search section with multi-source capabilities
}Key Features:
Memory Status Section:
- Total stored memories (count)
- Memory access statistics (total accesses, average importance)
- Memory span indicator (days between oldest and newest memories)
- Clear memories action button
Intelligence Activity Section (replaces Context Management):
- Telemetry Tracking: Real-time counters for agent intelligence operations
- Archive Recalls: How many times agent fetched from archived context (via recall_history tool)
- Memory Searches: How many times agent searched RAG database (via retrieveRelevantMemories)
- YaRN Compressions: How many times context was compressed to fit API limits
- Context Statistics:
- Active Tokens: Current conversation token count (calculated from messages)
- Archived Chunks: Number of archived context chunks
- Archived Tokens: Total tokens in archived chunks
- Archive Topics: Top 5 topics from archived chunks (when available)
- Compact 2x3 Grid Layout: Space-efficient display of all statistics
Enhanced Search Section:
- Stored Search: Vector RAG semantic search across stored memories in database
- Active/Archive Search: Disabled pending backend support for ConversationMemory creation from UI
- Single-source search with real-time results
- Result display with enhanced memory item view showing content preview
Integration Points:
ConversationManager.getActiveConversationMemoryStats()- Memory statisticsConversationManager.getActiveConversationArchiveStats()- Archive dataConversationManager.getContextStats(for:)- Per-conversation token countsConversationManager.incrementArchiveRecall()- Telemetry trackingConversationManager.incrementMemoryRetrieval()- Telemetry trackingConversationManager.incrementCompressionEvent()- Telemetry trackingMemoryManager.retrieveRelevantMemories()- Stored searchconversation.settings.telemetry- Persisted telemetry counters
User Experience:
- Collapsible panel accessed via brain icon in toolbar
- Real-time updates when switching conversations or shared topics
- Clear visual separation between sections with dividers
- Tooltips and help text for all interactive elements
- Graceful degradation when data unavailable (shows "No data" messages)
EndpointManager Integration:
reloadProviderConfigurations()for UI consistencyprocessStreamingChatCompletion()for streaming responses- Provider configuration loading patterns established
ChatWidget Streaming Patterns:
- Delta content append strategy for efficient streaming updates
- Performance tracking and error handling
- Model loading consistency (36 models accessible)
User Input → StreamingMessageInput → EndpointManager → Provider API
↓
Streaming Response → MessageBubbleView → ConversationView
↓
Conversation Persistence → ConversationListView Update
Message Bubble Styling:
- User: Blue accent, right-aligned, rounded corners
- Assistant: System background, left-aligned, SAM branding
- System: Purple accent, center-aligned, minimal styling
Layout Patterns:
- Consistent spacing: 12pt padding, 8pt item spacing
- Typography: System font with proper line spacing
- Colors: System semantic colors with theme support
- Animation: Smooth transitions, auto-scroll behavior
Interaction Patterns:
- Hover states for message actions
- Context menus for conversation management
- Keyboard shortcuts for power users
- VoiceOver accessibility support
- MainChatView: Basic NavigationSplitView layout
- MessageBubbleView: User and assistant message display
- StreamingMessageInput: Basic input with send functionality
- Integration: Connect with existing EndpointManager streaming
- ConversationListView: Conversation management sidebar
- EnhancedConversationView: Full conversation display with headers
- Message Actions: Edit, regenerate, copy, delete functionality
- Search and Filtering: Conversation and message search
- Markdown Rendering: Rich text display with syntax highlighting
- Conversation Persistence: Full conversation history management
- Export/Import: Conversation data management
- Advanced Configuration: Model settings, temperature, context
The chat interface succeeds when:
- Visual Match: Interface is visually indistinguishable from SAM 1.0
- Streaming Integration: Real-time responses using existing streaming implementation
- User Experience: Navigation and interaction feels identical to SAM 1.0
- Performance: Responsive UI with smooth animations and transitions
- Accessibility: Full VoiceOver support and keyboard navigation
- Reliability: No crashes, memory leaks, or UI freezing
Architecture Patterns Learned from SAM 1.0:
- NavigationSplitView for main layout structure
- Timer-based message refreshing during processing
- Debouncing and state guards to prevent UI conflicts
- ChatManager pattern for conversation state management
- StreamingChatViewModel for UI state management
Critical Implementation Details:
- Always call
reloadProviderConfigurations()for UI/API consistency - Use delta.content append strategy for streaming
- Implement proper message ordering with timestamp + ID sorting
- Add comprehensive code comments explaining architectural decisions
- Maintain existing streaming quality while adding UI enhancements
This architecture ensures pixel-perfect recreation of SAM 1.0's interface quality while building on the solid streaming foundation already completed.