agent: Restore web search tool card after restart (#30578)
Release Notes: - N/A
This commit is contained in:
parent
1a0eedb787
commit
e79d1b27b1
1 changed files with 18 additions and 4 deletions
|
@ -3,7 +3,7 @@ use std::{sync::Arc, time::Duration};
|
|||
use crate::schema::json_schema_for;
|
||||
use crate::ui::ToolCallCardHeader;
|
||||
use anyhow::{Context as _, Result, anyhow};
|
||||
use assistant_tool::{ActionLog, Tool, ToolCard, ToolResult, ToolUseStatus};
|
||||
use assistant_tool::{ActionLog, Tool, ToolCard, ToolResult, ToolResultOutput, ToolUseStatus};
|
||||
use futures::{Future, FutureExt, TryFutureExt};
|
||||
use gpui::{
|
||||
AnyWindowHandle, App, AppContext, Context, Entity, IntoElement, Task, WeakEntity, Window,
|
||||
|
@ -73,9 +73,11 @@ impl Tool for WebSearchTool {
|
|||
let search_task = search_task.clone();
|
||||
async move {
|
||||
let response = search_task.await.map_err(|err| anyhow!(err))?;
|
||||
serde_json::to_string(&response)
|
||||
.context("Failed to serialize search results")
|
||||
.map(Into::into)
|
||||
Ok(ToolResultOutput {
|
||||
content: serde_json::to_string(&response)
|
||||
.context("Failed to serialize search results")?,
|
||||
output: Some(serde_json::to_value(response)?),
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -84,6 +86,18 @@ impl Tool for WebSearchTool {
|
|||
card: Some(cx.new(|cx| WebSearchToolCard::new(search_task, cx)).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::<WebSearchResponse>(output).ok()?;
|
||||
let card = cx.new(|cx| WebSearchToolCard::new(Task::ready(Ok(output)), cx));
|
||||
Some(card.into())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(RegisterComponent)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue