Trim index output (#11445)
Trims down the project index output view in assistant2 to just list the filenames and hideaway the query. <img width="374" alt="image" src="https://github.com/zed-industries/zed/assets/836375/8603e3cf-9fdc-4661-bc45-1d87621a006f"> Introduces a way for tools to render running. Release Notes: - N/A --------- Co-authored-by: Max <max@zed.dev>
This commit is contained in:
parent
f658af5903
commit
32b59bfa0e
4 changed files with 106 additions and 75 deletions
|
@ -1,5 +1,5 @@
|
|||
use anyhow::{anyhow, Result};
|
||||
use gpui::{Task, WindowContext};
|
||||
use gpui::{div, AnyElement, IntoElement as _, ParentElement, Styled, Task, WindowContext};
|
||||
use std::{
|
||||
any::TypeId,
|
||||
collections::HashMap,
|
||||
|
@ -15,6 +15,7 @@ pub struct Tool {
|
|||
enabled: AtomicBool,
|
||||
type_id: TypeId,
|
||||
call: Box<dyn Fn(&ToolFunctionCall, &mut WindowContext) -> Task<Result<ToolFunctionCall>>>,
|
||||
render_running: Box<dyn Fn(&mut WindowContext) -> gpui::AnyElement>,
|
||||
definition: ToolFunctionDefinition,
|
||||
}
|
||||
|
||||
|
@ -22,12 +23,14 @@ impl Tool {
|
|||
fn new(
|
||||
type_id: TypeId,
|
||||
call: Box<dyn Fn(&ToolFunctionCall, &mut WindowContext) -> Task<Result<ToolFunctionCall>>>,
|
||||
render_running: Box<dyn Fn(&mut WindowContext) -> gpui::AnyElement>,
|
||||
definition: ToolFunctionDefinition,
|
||||
) -> Self {
|
||||
Self {
|
||||
enabled: AtomicBool::new(true),
|
||||
type_id,
|
||||
call,
|
||||
render_running,
|
||||
definition,
|
||||
}
|
||||
}
|
||||
|
@ -70,6 +73,24 @@ impl ToolRegistry {
|
|||
.collect()
|
||||
}
|
||||
|
||||
pub fn render_tool_call(
|
||||
&self,
|
||||
tool_call: &ToolFunctionCall,
|
||||
cx: &mut WindowContext,
|
||||
) -> AnyElement {
|
||||
match &tool_call.result {
|
||||
Some(result) => div()
|
||||
.p_2()
|
||||
.child(result.into_any_element(&tool_call.name))
|
||||
.into_any_element(),
|
||||
None => self
|
||||
.tools
|
||||
.get(&tool_call.name)
|
||||
.map(|tool| (tool.render_running)(cx))
|
||||
.unwrap_or_else(|| div().into_any_element()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn register<T: 'static + LanguageModelTool>(
|
||||
&mut self,
|
||||
tool: T,
|
||||
|
@ -115,6 +136,7 @@ impl ToolRegistry {
|
|||
})
|
||||
},
|
||||
),
|
||||
Box::new(|cx| T::render_running(cx).into_any_element()),
|
||||
definition,
|
||||
);
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use anyhow::Result;
|
||||
use gpui::{AnyElement, AnyView, IntoElement as _, Render, Task, View, WindowContext};
|
||||
use gpui::{div, AnyElement, AnyView, IntoElement, Render, Task, View, WindowContext};
|
||||
use schemars::{schema::RootSchema, schema_for, JsonSchema};
|
||||
use serde::Deserialize;
|
||||
use std::fmt::Display;
|
||||
|
@ -104,4 +104,8 @@ pub trait LanguageModelTool {
|
|||
output: Result<Self::Output>,
|
||||
cx: &mut WindowContext,
|
||||
) -> View<Self::View>;
|
||||
|
||||
fn render_running(_cx: &mut WindowContext) -> impl IntoElement {
|
||||
div()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue