Skip to content

Commit ca1b9b1

Browse files
bennetboosiewicz
authored andcommitted
agent: Restore web search tool card after restart (#30578)
Release Notes: - N/A
1 parent 6ddee29 commit ca1b9b1

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

crates/assistant_tools/src/web_search_tool.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{sync::Arc, time::Duration};
33
use crate::schema::json_schema_for;
44
use crate::ui::ToolCallCardHeader;
55
use anyhow::{Context as _, Result, anyhow};
6-
use assistant_tool::{ActionLog, Tool, ToolCard, ToolResult, ToolUseStatus};
6+
use assistant_tool::{ActionLog, Tool, ToolCard, ToolResult, ToolResultOutput, ToolUseStatus};
77
use futures::{Future, FutureExt, TryFutureExt};
88
use gpui::{
99
AnyWindowHandle, App, AppContext, Context, Entity, IntoElement, Task, WeakEntity, Window,
@@ -73,9 +73,11 @@ impl Tool for WebSearchTool {
7373
let search_task = search_task.clone();
7474
async move {
7575
let response = search_task.await.map_err(|err| anyhow!(err))?;
76-
serde_json::to_string(&response)
77-
.context("Failed to serialize search results")
78-
.map(Into::into)
76+
Ok(ToolResultOutput {
77+
content: serde_json::to_string(&response)
78+
.context("Failed to serialize search results")?,
79+
output: Some(serde_json::to_value(response)?),
80+
})
7981
}
8082
});
8183

@@ -84,6 +86,18 @@ impl Tool for WebSearchTool {
8486
card: Some(cx.new(|cx| WebSearchToolCard::new(search_task, cx)).into()),
8587
}
8688
}
89+
90+
fn deserialize_card(
91+
self: Arc<Self>,
92+
output: serde_json::Value,
93+
_project: Entity<Project>,
94+
_window: &mut Window,
95+
cx: &mut App,
96+
) -> Option<assistant_tool::AnyToolCard> {
97+
let output = serde_json::from_value::<WebSearchResponse>(output).ok()?;
98+
let card = cx.new(|cx| WebSearchToolCard::new(Task::ready(Ok(output)), cx));
99+
Some(card.into())
100+
}
87101
}
88102

89103
#[derive(RegisterComponent)]

0 commit comments

Comments
 (0)