Skip to main content

gpui_ai/
lib.rs

1//! AI-native UI components for GPUI applications.
2//!
3//! Composed, opinionated components for the surfaces an AI application keeps
4//! rebuilding — streaming text, thinking traces, tool calls, approval gates —
5//! built on [`gpui_component`] and inheriting its semantic-token theming.
6//! Every component resolves all of its presentation through the active theme,
7//! so light/dark modes, bundled themes, and custom JSON themes work without
8//! extra wiring.
9//!
10//! # Design rules
11//!
12//! - Stateless components are fluent [`gpui::RenderOnce`] builders; stateful
13//!   composites are entities. Callbacks use `on_*` methods.
14//! - Progressive output flows through one model: [`stream::StreamedContent`].
15//!   Components render snapshots; applications own the state and the clock.
16//! - No component runs a clock over the state it is given, or keeps fixture
17//!   data. A component may time something it alone owns — a "Copied"
18//!   confirmation clearing itself — but nothing a snapshot describes is ever
19//!   advanced from inside.
20//!
21//! Further components land phase by phase; see the repository roadmap.
22
23#![deny(missing_docs)]
24
25pub mod approval;
26pub mod artifact;
27pub mod attachment;
28mod button_label;
29pub mod chat;
30pub mod chip;
31pub mod code_block;
32pub mod code_diff;
33pub mod command_search;
34pub mod comparison_table;
35pub mod context_card;
36pub mod context_meter;
37mod control;
38pub mod cues;
39pub mod decoration;
40pub mod diff_table;
41pub mod filter_table;
42pub mod fine_tune;
43pub mod form;
44mod glide;
45pub mod image_generation;
46pub mod insight;
47pub mod loading;
48pub mod motion;
49pub mod orbs;
50pub mod plan;
51pub mod popup;
52pub mod prompt_bar;
53pub mod question_flow;
54pub mod queue;
55pub mod recommendation;
56pub mod records_table;
57mod resolved_layout;
58pub mod scrolling;
59pub mod search_results;
60pub mod selection_actions;
61pub mod sidebar_nav;
62pub mod sizing;
63pub mod status;
64pub mod stream;
65pub mod streaming_text;
66pub mod suggestions;
67mod surface;
68pub mod task;
69mod theme;
70pub mod thinking;
71pub mod thread_list;
72pub mod todo_list;
73pub mod tool_call;
74pub mod voice;
75
76pub use button_label::ButtonLabelExt;
77
78/// Convenient single-import surface: `use gpui_ai::prelude::*;`.
79pub mod prelude {
80    pub use crate::ButtonLabelExt;
81    pub use crate::approval::{ApprovalCard, ApprovalDecision, ApprovalEvent, ApprovalTone};
82    pub use crate::artifact::{
83        Artifact, ArtifactAction, ArtifactKind, ArtifactPanel, ArtifactPanelEvent, ArtifactVersion,
84        ArtifactView,
85    };
86    pub use crate::attachment::{
87        Attachment, AttachmentEvent, AttachmentKind, AttachmentPreview, AttachmentStrip,
88        format_bytes,
89    };
90    pub use crate::chat::{
91        BranchPosition, Chat, ChatEvent, ChatMessage, ChatMessageAppearance, ChatRole, ChatWelcome,
92        MessageActions, MessageAlignment, MessageBubble,
93    };
94    pub use crate::chip::{ToolChip, ToolChipEvent, ToolStatus};
95    pub use crate::code_block::CodeBlock;
96    pub use crate::code_diff::{
97        CodeDiff, CodeDiffEvent, DiffFile, DiffHunk, DiffLine, DiffLineKind, DiffStats, HunkReview,
98    };
99    pub use crate::command_search::{CommandSearch, CommandSearchEvent, CommandSearchItem};
100    pub use crate::comparison_table::{
101        ComparisonFeature, ComparisonItem, ComparisonItemState, ComparisonSnapshot,
102        ComparisonSnapshotError, ComparisonTable, ComparisonTableEvent, ComparisonValue,
103        MAX_COMPARISON_FEATURES, MAX_COMPARISON_ITEMS,
104    };
105    pub use crate::context_card::{ContextCard, ContextCardEvent};
106    pub use crate::context_meter::{ContextMeter, ContextMeterVariant, ContextUsage, UsageLevel};
107    pub use crate::cues::{Cue, CueSubscription};
108    pub use crate::decoration::{self as decoration, Decoration};
109    pub use crate::diff_table::{
110        DiffCell, DiffChangeKind, DiffColumn, DiffColumnAlignment, DiffProposalAction,
111        DiffProposalState, DiffRow, DiffSortDirection, DiffTable, DiffTableEvent,
112    };
113    pub use crate::filter_table::{
114        FilterCell, FilterColumn, FilterColumnAlignment, FilterDefinition, FilterRow,
115        FilterSortDirection, FilterTable, FilterTableEvent,
116    };
117    pub use crate::fine_tune::{FineTuneCard, FineTuneEvent, FineTuneTypeface, FineTuneValues};
118    pub use crate::form::{
119        ChoiceEvent, ChoiceGroup, ChoiceOption, Toggle, ToggleEvent, ToggleShape,
120    };
121    pub use crate::image_generation::ImageGeneration;
122    pub use crate::insight::{
123        InsightCard, InsightEvent, InsightMetric, InsightPoint, InsightTrend,
124    };
125    pub use crate::loading::LoadingState;
126    pub use crate::motion::{
127        MotionPreference, MotionTokens, Shimmer, breathing, reveal, reveal_staggered,
128    };
129    pub use crate::orbs::{OrbVariant, Orbs};
130    pub use crate::plan::{PlanCard, PlanEvent, PlanState, PlanStep, PlanStepStatus};
131    pub use crate::prompt_bar::{
132        PromptActions, PromptAttachment, PromptBar, PromptBarEvent, PromptCommand, PromptMention,
133        PromptModel, PromptSubmission, PromptSubmit,
134    };
135    pub use crate::question_flow::{Question, QuestionFlow, QuestionFlowEvent};
136    pub use crate::queue::{MessageQueue, QueueEvent, QueuedMessage};
137    pub use crate::recommendation::{RecommendationCard, RecommendationEvent};
138    pub use crate::records_table::{
139        RecordCell, RecordCellKind, RecordColumn, RecordColumnAlignment, RecordRow,
140        RecordSortDirection, RecordStatusTone, RecordsTable, RecordsTableEvent, RowActionPlacement,
141        RowActionVisibility,
142    };
143    // The types, not the tuning. A wheel accelerator's five coefficients are
144    // reachable at `gpui_ai::scrolling::*` for anyone reproducing its feel;
145    // a prelude is for the names an application writes every day, and
146    // `WHEEL_ACCEL_DECAY_SECONDS` is not one of them.
147    pub use crate::scrolling::{
148        AUTOSCROLL_FULL_SPEED_DISTANCE_PX, Autoscroll, MAX_AUTOSCROLL_SPEED_PX_PER_SEC, ScrollRoom,
149        WheelAccelerator,
150    };
151    pub use crate::search_results::{SearchResult, SearchResults, SearchResultsEvent};
152    pub use crate::selection_actions::{SelectionAction, SelectionActions, SelectionActionsEvent};
153    pub use crate::sidebar_nav::{
154        SidebarNav, SidebarNavEvent, SidebarNavItem, SidebarNavPresentation, SidebarSection,
155    };
156    pub use crate::sizing::SizeTokens;
157    pub use crate::status::{StatusBadge, StatusTone};
158    pub use crate::stream::{ProgressState, Progressive, StreamedContent};
159    pub use crate::streaming_text::{
160        CitationRef, FollowUp, SourceRef, StreamingText, StreamingTextEvent,
161    };
162    pub use crate::suggestions::{Suggestion, Suggestions, SuggestionsEvent};
163    pub use crate::task::{TaskRow, TaskSnapshot};
164    pub use crate::thinking::{StepStatus, Thinking, ThinkingEvent, ThinkingStep, ThinkingTrace};
165    pub use crate::thread_list::{ThreadItem, ThreadList, ThreadListEvent, ThreadSection};
166    pub use crate::todo_list::{TodoItem, TodoList, TodoListEvent, TodoStatus};
167    pub use crate::tool_call::{
168        ToolApproval, ToolCall, ToolCallEvent, ToolGroup, ToolGroupEvent, ToolInvocation,
169    };
170    pub use crate::voice::{VoiceControls, VoiceEvent, VoiceState};
171}
172
173pub(crate) mod handlers {
174    use gpui::{App, Window};
175    use std::rc::Rc;
176
177    /// Boxed event handler stored by builder components.
178    pub(crate) type Handler<E> = Box<dyn Fn(&E, &mut Window, &mut App)>;
179    /// Ref-counted event handler for components that clone handlers per child.
180    pub(crate) type SharedHandler<E> = Rc<dyn Fn(&E, &mut Window, &mut App)>;
181}
182
183use gpui::App;
184
185/// Initializes gpui-ai.
186///
187/// Call once at application startup, before creating any windows that use
188/// these components. This also initializes the underlying [`gpui_component`]
189/// state (theme, global settings), so applications do not need to call
190/// `gpui_component::init` separately.
191pub fn init(cx: &mut App) {
192    gpui_component::init(cx);
193    // The motion policy, before any component renders — and only unless the
194    // application already chose one, so either order of init and
195    // customization lands on the application's values.
196    motion::install(cx);
197    sizing::install(cx);
198    scrolling::install(cx);
199    popup::install(cx);
200    records_table::init(cx);
201}