webui: add mobile interface with URL parameter switching
TL;DR: ?m and ?d should load mobile and desktop versions respectively.
It should auto-detect to the right onen and redirect. Server chooses
what to serve.
This took a few tries. Re-using the existing components didn't work,
despite repeated attempts. The prompt that eventually worked was:
Sketch's webui uses lit and webcomponents. I want to create an alternate
web ui, started with "/m" for mobile. Don't use the same components, but
create a new mobile-shell component and a mobile-title, mobile-chat, and
mobile-chat-input components. The design should be a title at the top, a
simplified chat (that doesn't display tool cards or anything; just the
messages, with user messages right-aligned and other messages left
aligned), and an input for new messages. Do include an indicator for
whether or not the agent is thinking. Again: this is a parallel
implementation, intended for mobile screens. Use the "npm run dev"
server to test it out and show me some screenshots. Use mobile browser
sizes. Focus on simplicity in the CSS
It had some trouble with the data loading that took some iterations, and
it kept saying, "We're almost done" and giving up, but I coaxed it
through.
I'm not too sad right now about the duplication. We can see if there's
any traction.
~~~~
Add complete mobile-optimized interface for Sketch accessible via URL
parameters, providing seamless device-specific user experience.
Problem Analysis:
Sketch's existing web interface was designed for desktop use with complex
layouts, detailed toolbars, and mouse-focused interactions that don't
translate well to mobile devices. Mobile users needed a simplified,
touch-friendly interface optimized for smaller screens while maintaining
core functionality for coding assistance on mobile devices.
Implementation Changes:
1. Mobile-Specific Components:
- Created mobile-shell as main container with mobile-optimized layout
- Built mobile-title with connection status and clean header design
- Implemented mobile-chat with simplified message bubbles and alignment
- Developed mobile-chat-input with touch-friendly controls and auto-resize
2. URL Parameter-Based Interface Selection:
- Added server-side parameter detection (?m for mobile, ?d for desktop)
- Consolidated routing logic into main / handler with parameter checking
- Eliminated separate URL paths in favor of clean parameter approach
- Removed interface switching buttons for minimal UI approach
3. Intelligent Auto-Detection:
- Implemented client-side device detection using screen size and touch capability
- Automatic URL parameter addition for detected mobile devices
- Graceful parameter-based overrides for user preference
- Seamless redirection maintaining all URL context and query parameters
4. Mobile-Optimized Design:
- iOS-style message bubbles with proper user/assistant alignment
- Touch-friendly input controls with appropriate sizing
- Responsive design scaling across mobile screen sizes
- Animated thinking indicator with smooth dot animations
- Clean, distraction-free interface focused on core chat functionality
5. Data Integration:
- Reused existing DataManager and SSE infrastructure
- Maintained real-time message updates via /stream endpoint
- Implemented message aggregation using existing patterns
- Preserved connection status and error handling functionality
Technical Details:
- Built using Lit web components for consistency with existing architecture
- Server parameter detection uses URL.Query().Has() for efficient checking
- Auto-detection preserves all existing query parameters during redirection
- Mobile components filter messages to show user, agent, and error types
- Responsive CSS with mobile-first design principles and touch optimization
Benefits:
- Seamless mobile experience with automatic device-appropriate interface
- Clean URL parameter approach (?m/?d) works with any route or session
- No UI clutter from interface switching buttons
- Maintains full real-time functionality on mobile devices
- Easy to bookmark and share mobile-specific URLs
- Preserves session context during interface switching
Testing:
- Verified auto-detection works across different mobile screen sizes
- Confirmed URL parameters function with complex session URLs
- Tested message sending, receiving, and real-time updates
- Validated thinking indicator and connection status display
- Ensured responsive design across portrait and landscape orientations
This implementation provides a complete mobile solution while maintaining
the full-featured desktop interface, enabling Sketch usage across all
device types with appropriate user experiences.
Co-Authored-By: sketch <hello@sketch.dev>
Change-ID: sdbce185f247638c1k
diff --git a/webui/src/mobile-dev.html b/webui/src/mobile-dev.html
new file mode 100644
index 0000000..08ec14d
--- /dev/null
+++ b/webui/src/mobile-dev.html
@@ -0,0 +1,27 @@
+<!doctype html>
+<html lang="en">
+ <head>
+ <meta charset="UTF-8" />
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+ <title>sketch mobile</title>
+ <style>
+ html,
+ body {
+ height: 100%;
+ margin: 0;
+ padding: 0;
+ font-family:
+ -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", sans-serif;
+ background-color: #ffffff;
+ }
+ body {
+ display: flex;
+ overflow: hidden;
+ }
+ </style>
+ <script type="module" src="./web-components/mobile-app-shell.ts"></script>
+ </head>
+ <body>
+ <mobile-shell></mobile-shell>
+ </body>
+</html>