Comet Gemini is an AI chat application featuring real-time streaming capabilities and integration with an E2B desktop sandbox. Its primary purpose is to provide a highly interactive and responsive AI assistant experience, specifically designed for tasks requiring precise interaction with a desktop environment. The project aims to overcome common AI interaction challenges, such as incorrect coordinate generation and unresponsive UI, to deliver a seamless user experience.
- Communication Style: I prefer simple language and clear, direct instructions.
- Workflow: I want iterative development, where I see the effect of each action before the next is taken.
- Interaction: Ask before making major changes. I need immediate feedback on actions.
- Coding Style: I prefer a clean codebase with unused files and redundant code removed.
- Agent Behavior:
- AI should be able to click anywhere on the screen without limitations.
- AI should perform actions sequentially, one at a time.
- AI should not buffer events but process them immediately.
- AI should not group message parts; each part should be a separate element.
- Conditional Rendering: The application uses conditional rendering for desktop and mobile views to avoid dual DOM issues and ensure a single, optimized UI is present at any given time.
- Real-time Rendering:
flushSync()is used extensively to ensure immediate rendering of all updates, crucial for a real-time streaming experience. - GPU Optimizations: Messages are wrapped in
RealtimeMessagecomponents that include GPU optimizations for smoother performance.
- AI Coordinate Validation: A three-level validation system for AI-generated coordinates includes:
- Coordinate Sanity Checklist: Critical rules are placed at the beginning of the prompt, reduced to four mandatory steps with clear examples. AI must define a
target_region(e.g., "top-left") before providing coordinates. target_regionTool Parameter: Thecomputer_usetool requires atarget_regionparameter, an enum of 9 screen regions (e.g., top-left, middle-center).- Server-side Validation: Automatically calculates the actual region from
[X, Y]coordinates and compares it with the declaredtarget_region. Mismatches trigger a detailed error analysis, including correct ranges and examples.
- Coordinate Sanity Checklist: Critical rules are placed at the beginning of the prompt, reduced to four mandatory steps with clear examples. AI must define a
- Screenshot Metadata: Each screenshot includes detailed technical data (timestamp, resolution, aspect ratio, coordinate system, corner/edge coordinates) and a 3x3 ASCII grid visualization with coordinate ranges and examples for each region.
- Clicking Behavior: Instructions explicitly state that there are no restrictions on where the AI can click, allowing clicks anywhere from
(0,0)to(max_width-1, max_height-1). Coordinate validation has been removed from the server-side forleft_clickandright_clickto ensure direct input to E2B. - Action Execution: AI actions are executed sequentially. Only the first tool call generated by the AI is processed, and its result is returned to the AI before it decides on the next action. This ensures controlled, step-by-step execution.
- Typing Action: The
typeaction now usesdesktop.write(textToType)for correct text input, replacing the error-pronedesktop.press()loop. - Continuous Action Loop: The
while (true)loop for AI actions has been corrected to prevent premature stream closure, allowing the AI to perform an unlimited number of sequential actions until the task is complete.
- Real-time Streaming: Uses a custom JSON Lines format over fetch API for communication between the client and
/api/chat/route.ts. Events (text-delta,tool-call-start, etc.) are streamed asJSON.stringify(event) + '\n'. - No Buffering/Grouping:
ENABLE_BUFFERINGandENABLE_MESSAGE_GROUPINGare explicitly set tofalse, andIMMEDIATE_PROCESSINGtotrueinlib/streaming-config.tsto ensure immediate and granular event handling. - State Management: The
lib/use-raw-streaming.tshook (previouslyuse-optimized-chat.ts) usesuseState(instead ofuseReducer) andmessagesReffor synchronous state tracking and immediate updates. - Cache Busting: Timestamps are included in every request to prevent caching issues.
- Project Structure: Key components include
app/page.tsx(main UI),app/api/chat/route.ts(OpenAI streaming endpoint),lib/use-raw-streaming.ts(streaming hook), andlib/streaming-config.ts.
- Next.js: Framework (version 15.2.1)
- React: UI library (version 18+)
- E2B Sandbox: Desktop environment integration for AI interactions (e.g.,
desktop.leftClick(x, y),desktop.write(textToType)). - OpenAI: Used for AI chat capabilities and generating tool calls.