Start
Getting started
What you need, how to add the dependency, and a complete window with a component in it.
What you need
A Rust toolchain, and a machine that can run a GPUI application: GPUI draws through the platform’s GPU API, so a working graphics stack is a requirement rather than an optimisation. On Linux that means the usual X11 or Wayland development packages, which is what the x11 and wayland features below pull in.
Adding the dependency
Four crates, because an application uses all four directly: gpui and gpui-component are what you write interface against, gpui_platform opens the window, and gpui-ai is this library.
[dependencies]
gpui-ai = "0.8.0"
gpui = { package = "gpui-pre", version = "0.3.3" }
gpui-component = "0.6.0"
gpui_platform = { package = "gpui-pre-platform", version = "0.3.3", features = ["font-kit", "x11", "wayland", "runtime_shaders"] }
GPUI is on crates.io under another name: GPUI Kit publishes a snapshot of Zed’s crate as gpui-pre, so the dependency carries a package rename and every use gpui:: path in your application keeps working. This release was built against gpui-pre 0.3.3 and gpui-component 0.6.0. They are one compatible set: a different gpui-pre underneath gpui-component gives you two copies of GPUI’s types, and nothing shared between them will compile.
A window with a component in it
One call during setup — gpui_ai::init, which initializes gpui-component too — and a Root around the top-level view. Root owns the theme, the rem size, and the layer that dialogs and popovers are drawn into; a component rendered outside one has no theme to read.
use gpui::{App, Application, WindowOptions, prelude::*};
use gpui_ai::prelude::*;
use gpui_component::Root;
struct Agent;
impl Render for Agent {
fn render(&mut self, _: &mut Window, _: &mut Context<Self>) -> impl IntoElement {
ToolChip::new("edit", "Edit main.rs").status(ToolStatus::Running)
}
}
fn main() {
Application::new().run(|cx: &mut App| {
gpui_ai::init(cx);
cx.open_window(WindowOptions::default(), |window, cx| {
let agent = cx.new(|_| Agent);
// Root owns the theme, the rem size, and the layers dialogs and
// popovers are drawn into. Every gpui-component app has one.
cx.new(|cx| Root::new(agent.into(), window, cx))
})
.unwrap();
});
}
Stateless components are fluent builders you construct where you render them, as above. Stateful ones are GPUI entities: keep the entity and its subscriptions in your own state, because their lifetime is your application’s, not the frame’s.
Where to go next
All 37 components, each with its demo, its events, and the exact code its story is cut from. Then Ownership and events, which is the one idea the whole library is arranged around.