Prompt Input Component
Relevant source files
The following files were used as context for generating this wiki page:
Introduction
The Prompt Input Component is the primary interface for user interaction within the Agent Cowork application. It provides a fixed, multi-line text input area where users can describe tasks or respond to the AI agent. This component acts as the entry point for both initializing new sessions and continuing existing conversations by dispatching specific client events to the backend runner.
Sources: src/ui/components/PromptInput.tsx:1-120, src/ui/App.tsx:280-285
Component Architecture and Logic
The prompt input system is divided into a presentation component (PromptInput) and a functional hook (usePromptActions) that manages state and event dispatching.
Logic Flow and Event Dispatching
The usePromptActions hook encapsulates the logic for determining whether to start a new session or continue an existing one based on the activeSessionId. If no session is active, it triggers a title generation process via Electron before starting a new session.
The logic differentiates between session.start and session.continue payloads. session.start includes the prompt, working directory (CWD), and default allowed tools (Read,Edit,Bash).
Sources: src/ui/components/PromptInput.tsx:20-63, src/ui/types.ts:40-47
UI State and Interactions
The PromptInput component uses a textarea that auto-expands until a maximum height of 12 rows (approx. 252px) is reached, at which point it enables internal scrolling.
| Feature | Description | File Reference |
|---|---|---|
| Auto-expand | Textarea adjusts height based on content up to MAX_ROWS. | PromptInput.tsx:82-93 |
| Stop Mechanism | If a session is running, the send button transforms into a stop button. | PromptInput.tsx:106-118 |
| Keyboard Control | Supports Enter for submission and Shift+Enter for new lines. | PromptInput.tsx:71-77 |
| Dynamic Placeholder | Displays "Create/select a task..." when disabled/no session. | PromptInput.tsx:100-101 |
Sources: src/ui/components/PromptInput.tsx:5-10, src/ui/components/PromptInput.tsx:100-118
Data Flow and Dependencies
The component is heavily integrated with the global application store (useAppStore) and Electron's IPC bridge.
Store Integration
The component relies on several pieces of global state:
prompt: The current text content of the input.cwd: The current working directory for new sessions.activeSessionId: Determines if the message is a new start or a continuation.sessions: Used to check therunningstatus of the active session.
Sources: src/ui/components/PromptInput.tsx:21-27, src/ui/store/useAppStore.ts
Title Generation Sequence
When a new session is started from the prompt input, the application performs an asynchronous call to the Electron main process to generate a descriptive title based on the user's initial intent.
Key Configurations and Constants
The component's behavior is governed by several internal constants defined in PromptInput.tsx:
| Constant | Value | Purpose |
|---|---|---|
DEFAULT_ALLOWED_TOOLS | "Read,Edit,Bash" | Default permissions granted to the agent on session start. |
MAX_ROWS | 12 | Maximum visual height of the textarea before scrolling. |
LINE_HEIGHT | 21 | Pixel height used for calculation of auto-expand logic. |
Sources: src/ui/components/PromptInput.tsx:6-9
Usage in App Shell
The PromptInput is positioned as a fixed element at the bottom of the main content area. It is automatically disabled when no messages are present in the current view unless a session is being initialized via the StartSessionModal.
// src/ui/App.tsx:280
<PromptInput
sendEvent={sendEvent}
onSendMessage={handleSendMessage}
disabled={visibleMessages.length === 0}
/>
Sources: src/ui/App.tsx:280-285, src/ui/components/PromptInput.tsx:112
Summary
The Prompt Input Component serves as the command center for the Agent Cowork UI. It manages complex state transitions between starting new tasks and stopping running ones, handles automated title generation via IPC, and ensures a responsive user experience through dynamic UI adjustments like auto-expanding text fields and status-aware action buttons.