Skip to content

Commit 8624f3b

Browse files
authored
Merge pull request #72 from 7df-lab/dev/tool0518
Dev/tool0518
2 parents 1650700 + 2417fb9 commit 8624f3b

17 files changed

Lines changed: 1339 additions & 56 deletions

File tree

crates/core/src/query.rs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::collections::HashSet;
12
use std::sync::Arc;
23
use std::time::Duration;
34

@@ -610,6 +611,7 @@ pub async fn query(
610611
let mut assistant_text = String::new();
611612
let mut reasoning_text = String::new();
612613
let mut tool_uses: Vec<(String, String, serde_json::Value, String, bool)> = Vec::new();
614+
let mut emitted_tool_use_starts: HashSet<String> = HashSet::new();
613615
let mut final_response = None;
614616
let mut stop_reason = None;
615617

@@ -631,6 +633,13 @@ pub async fn query(
631633
Ok(StreamEvent::ToolCallStart {
632634
id, name, input, ..
633635
}) => {
636+
if emitted_tool_use_starts.insert(id.clone()) {
637+
emit(QueryEvent::ToolUseStart {
638+
id: id.clone(),
639+
name: name.clone(),
640+
input: input.clone(),
641+
});
642+
}
634643
tool_uses.push((id, name, input, String::new(), false));
635644
}
636645
Ok(StreamEvent::ToolCallInputDelta { partial_json, .. }) => {
@@ -784,11 +793,13 @@ pub async fn query(
784793
} else {
785794
initial_input
786795
};
787-
emit(QueryEvent::ToolUseStart {
788-
id: id.clone(),
789-
name: name.clone(),
790-
input: input.clone(),
791-
});
796+
if emitted_tool_use_starts.insert(id.clone()) {
797+
emit(QueryEvent::ToolUseStart {
798+
id: id.clone(),
799+
name: name.clone(),
800+
input: input.clone(),
801+
});
802+
}
792803
assistant_content.push(ContentBlock::ToolUse {
793804
id: id.clone(),
794805
name: name.clone(),
@@ -977,6 +988,7 @@ mod tests {
977988
use devo_protocol::Usage;
978989
use devo_provider::ModelProviderSDK;
979990
use devo_safety::PermissionMode;
991+
use devo_tools::ToolPreparationFeedback;
980992
use devo_tools::ToolRegistry;
981993
use devo_tools::ToolRuntime;
982994
use devo_tools::errors::ToolExecutionError;
@@ -1462,6 +1474,7 @@ mod tests {
14621474
execution_mode: ToolExecutionMode::Mutating,
14631475
capability_tags: vec![],
14641476
supports_parallel: false,
1477+
preparation_feedback: ToolPreparationFeedback::None,
14651478
});
14661479
let registry = Arc::new(builder.build());
14671480
let deny_checker = PermissionChecker::new(|request| {
@@ -1957,6 +1970,7 @@ mod tests {
19571970
execution_mode: ToolExecutionMode::Mutating,
19581971
capability_tags: vec![],
19591972
supports_parallel: false,
1973+
preparation_feedback: ToolPreparationFeedback::None,
19601974
});
19611975
let registry = Arc::new(builder.build());
19621976
let runtime = ToolRuntime::new_without_permissions(Arc::clone(&registry));
@@ -2010,6 +2024,7 @@ mod tests {
20102024
execution_mode: ToolExecutionMode::ReadOnly,
20112025
capability_tags: vec![],
20122026
supports_parallel: false,
2027+
preparation_feedback: ToolPreparationFeedback::None,
20132028
});
20142029
let registry = Arc::new(builder.build());
20152030
let runtime = ToolRuntime::new_without_permissions(Arc::clone(&registry));
@@ -2067,6 +2082,7 @@ mod tests {
20672082
execution_mode: ToolExecutionMode::Mutating,
20682083
capability_tags: vec![],
20692084
supports_parallel: false,
2085+
preparation_feedback: ToolPreparationFeedback::None,
20702086
});
20712087
let registry = Arc::new(builder.build());
20722088
let runtime = ToolRuntime::new_without_permissions(Arc::clone(&registry));
@@ -2144,6 +2160,7 @@ mod tests {
21442160
execution_mode: ToolExecutionMode::ReadOnly,
21452161
capability_tags: vec![],
21462162
supports_parallel: true,
2163+
preparation_feedback: ToolPreparationFeedback::None,
21472164
});
21482165
let registry = Arc::new(builder.build());
21492166
let runtime = ToolRuntime::new_without_permissions(Arc::clone(&registry));

crates/protocol/src/event.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ pub struct CommandExecutionPayload {
6161
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6262
pub struct FileChangePayload {
6363
pub tool_call_id: String,
64+
#[serde(default, skip_serializing_if = "Option::is_none")]
65+
pub tool_name: Option<String>,
6466
pub changes: Vec<(std::path::PathBuf, FileChange)>,
6567
pub is_error: bool,
6668
}

crates/server/src/projection.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,18 @@ fn parse_edited_history_metadata(output: &serde_json::Value) -> Option<SessionHi
324324
.unwrap_or(0);
325325
let change = match kind {
326326
"add" => devo_protocol::protocol::FileChange::Add {
327-
content: "\n".repeat(additions as usize),
327+
content: file
328+
.get("content")
329+
.and_then(serde_json::Value::as_str)
330+
.map(ToOwned::to_owned)
331+
.unwrap_or_else(|| "\n".repeat(additions as usize)),
328332
},
329333
"delete" => devo_protocol::protocol::FileChange::Delete {
330-
content: "\n".repeat(deletions as usize),
334+
content: file
335+
.get("content")
336+
.and_then(serde_json::Value::as_str)
337+
.map(ToOwned::to_owned)
338+
.unwrap_or_else(|| "\n".repeat(deletions as usize)),
331339
},
332340
"update" | "move" => devo_protocol::protocol::FileChange::Update {
333341
unified_diff: file

0 commit comments

Comments
 (0)