agent: Restore find path tool card after restart (#30580)
Release Notes: - N/A
This commit is contained in:
parent
6592314984
commit
3173f87dc3
1 changed files with 37 additions and 2 deletions
|
@ -1,6 +1,6 @@
|
||||||
use crate::{schema::json_schema_for, ui::ToolCallCardHeader};
|
use crate::{schema::json_schema_for, ui::ToolCallCardHeader};
|
||||||
use anyhow::{Result, anyhow};
|
use anyhow::{Result, anyhow};
|
||||||
use assistant_tool::{ActionLog, Tool, ToolCard, ToolResult, ToolUseStatus};
|
use assistant_tool::{ActionLog, Tool, ToolCard, ToolResult, ToolResultOutput, ToolUseStatus};
|
||||||
use editor::Editor;
|
use editor::Editor;
|
||||||
use futures::channel::oneshot::{self, Receiver};
|
use futures::channel::oneshot::{self, Receiver};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
|
@ -38,6 +38,12 @@ pub struct FindPathToolInput {
|
||||||
pub offset: usize,
|
pub offset: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
struct FindPathToolOutput {
|
||||||
|
glob: String,
|
||||||
|
paths: Vec<PathBuf>,
|
||||||
|
}
|
||||||
|
|
||||||
const RESULTS_PER_PAGE: usize = 50;
|
const RESULTS_PER_PAGE: usize = 50;
|
||||||
|
|
||||||
pub struct FindPathTool;
|
pub struct FindPathTool;
|
||||||
|
@ -111,10 +117,18 @@ impl Tool for FindPathTool {
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
let output = FindPathToolOutput {
|
||||||
|
glob,
|
||||||
|
paths: matches.clone(),
|
||||||
|
};
|
||||||
|
|
||||||
for mat in matches.into_iter().skip(offset).take(RESULTS_PER_PAGE) {
|
for mat in matches.into_iter().skip(offset).take(RESULTS_PER_PAGE) {
|
||||||
write!(&mut message, "\n{}", mat.display()).unwrap();
|
write!(&mut message, "\n{}", mat.display()).unwrap();
|
||||||
}
|
}
|
||||||
Ok(message.into())
|
Ok(ToolResultOutput {
|
||||||
|
content: message,
|
||||||
|
output: Some(serde_json::to_value(output)?),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -123,6 +137,18 @@ impl Tool for FindPathTool {
|
||||||
card: Some(card.into()),
|
card: Some(card.into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn deserialize_card(
|
||||||
|
self: Arc<Self>,
|
||||||
|
output: serde_json::Value,
|
||||||
|
_project: Entity<Project>,
|
||||||
|
_window: &mut Window,
|
||||||
|
cx: &mut App,
|
||||||
|
) -> Option<assistant_tool::AnyToolCard> {
|
||||||
|
let output = serde_json::from_value::<FindPathToolOutput>(output).ok()?;
|
||||||
|
let card = cx.new(|_| FindPathToolCard::from_output(output));
|
||||||
|
Some(card.into())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn search_paths(glob: &str, project: Entity<Project>, cx: &mut App) -> Task<Result<Vec<PathBuf>>> {
|
fn search_paths(glob: &str, project: Entity<Project>, cx: &mut App) -> Task<Result<Vec<PathBuf>>> {
|
||||||
|
@ -180,6 +206,15 @@ impl FindPathToolCard {
|
||||||
_receiver_task: Some(_receiver_task),
|
_receiver_task: Some(_receiver_task),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn from_output(output: FindPathToolOutput) -> Self {
|
||||||
|
Self {
|
||||||
|
glob: output.glob,
|
||||||
|
paths: output.paths,
|
||||||
|
expanded: false,
|
||||||
|
_receiver_task: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToolCard for FindPathToolCard {
|
impl ToolCard for FindPathToolCard {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue