Standardize agent previews (#29790)

This PR makes agent previews render like any other preview in the
component preview list & pages.

Page:

![CleanShot 2025-05-02 at 09 17
12@2x](https://github.com/user-attachments/assets/8b611380-b686-4fd6-9c76-de27e35b0b38)

List:

![CleanShot 2025-05-02 at 09 17
33@2x](https://github.com/user-attachments/assets/ab063649-dc3c-4c95-969b-c3795b2197f2)


Release Notes:

- N/A
This commit is contained in:
Nate Butler 2025-05-02 09:32:59 -04:00 committed by GitHub
parent 225deb6785
commit 3bd7ae6e5b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 114 additions and 105 deletions

View file

@ -1211,7 +1211,7 @@ impl Component for MessageEditor {
}
impl AgentPreview for MessageEditor {
fn create_preview(
fn agent_preview(
workspace: WeakEntity<Workspace>,
active_thread: Entity<ActiveThread>,
thread_store: WeakEntity<ThreadStore>,

View file

@ -3,7 +3,7 @@ use component::ComponentId;
use gpui::{App, Entity, WeakEntity};
use linkme::distributed_slice;
use std::sync::OnceLock;
use ui::{AnyElement, Component, Window};
use ui::{AnyElement, Component, ComponentScope, Window};
use workspace::Workspace;
use crate::{ActiveThread, ThreadStore};
@ -22,27 +22,20 @@ pub type PreviewFn = fn(
pub static __ALL_AGENT_PREVIEWS: [fn() -> (ComponentId, PreviewFn)] = [..];
/// Trait that must be implemented by components that provide agent previews.
pub trait AgentPreview: Component {
/// Get the ID for this component
///
/// Eventually this will move to the component trait.
fn id() -> ComponentId
where
Self: Sized,
{
ComponentId(Self::name())
pub trait AgentPreview: Component + Sized {
#[allow(unused)] // We can't know this is used due to the distributed slice
fn scope(&self) -> ComponentScope {
ComponentScope::Agent
}
/// Static method to create a preview for this component type
fn create_preview(
fn agent_preview(
workspace: WeakEntity<Workspace>,
active_thread: Entity<ActiveThread>,
thread_store: WeakEntity<ThreadStore>,
window: &mut Window,
cx: &mut App,
) -> Option<AnyElement>
where
Self: Sized;
) -> Option<AnyElement>;
}
/// Register an agent preview for the given component type
@ -55,8 +48,8 @@ macro_rules! register_agent_preview {
$crate::ui::agent_preview::PreviewFn,
) = || {
(
<$type as $crate::ui::agent_preview::AgentPreview>::id(),
<$type as $crate::ui::agent_preview::AgentPreview>::create_preview,
<$type as component::Component>::id(),
<$type as $crate::ui::agent_preview::AgentPreview>::agent_preview,
)
};
};