Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions crates/core/src/query.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::collections::HashSet;
use std::sync::Arc;
use std::time::Duration;

Expand Down Expand Up @@ -610,6 +611,7 @@ pub async fn query(
let mut assistant_text = String::new();
let mut reasoning_text = String::new();
let mut tool_uses: Vec<(String, String, serde_json::Value, String, bool)> = Vec::new();
let mut emitted_tool_use_starts: HashSet<String> = HashSet::new();
let mut final_response = None;
let mut stop_reason = None;

Expand All @@ -631,6 +633,13 @@ pub async fn query(
Ok(StreamEvent::ToolCallStart {
id, name, input, ..
}) => {
if emitted_tool_use_starts.insert(id.clone()) {
emit(QueryEvent::ToolUseStart {
id: id.clone(),
name: name.clone(),
input: input.clone(),
});
}
tool_uses.push((id, name, input, String::new(), false));
}
Ok(StreamEvent::ToolCallInputDelta { partial_json, .. }) => {
Expand Down Expand Up @@ -784,11 +793,13 @@ pub async fn query(
} else {
initial_input
};
emit(QueryEvent::ToolUseStart {
id: id.clone(),
name: name.clone(),
input: input.clone(),
});
if emitted_tool_use_starts.insert(id.clone()) {
emit(QueryEvent::ToolUseStart {
id: id.clone(),
name: name.clone(),
input: input.clone(),
});
}
assistant_content.push(ContentBlock::ToolUse {
id: id.clone(),
name: name.clone(),
Expand Down Expand Up @@ -977,6 +988,7 @@ mod tests {
use devo_protocol::Usage;
use devo_provider::ModelProviderSDK;
use devo_safety::PermissionMode;
use devo_tools::ToolPreparationFeedback;
use devo_tools::ToolRegistry;
use devo_tools::ToolRuntime;
use devo_tools::errors::ToolExecutionError;
Expand Down Expand Up @@ -1462,6 +1474,7 @@ mod tests {
execution_mode: ToolExecutionMode::Mutating,
capability_tags: vec![],
supports_parallel: false,
preparation_feedback: ToolPreparationFeedback::None,
});
let registry = Arc::new(builder.build());
let deny_checker = PermissionChecker::new(|request| {
Expand Down Expand Up @@ -1957,6 +1970,7 @@ mod tests {
execution_mode: ToolExecutionMode::Mutating,
capability_tags: vec![],
supports_parallel: false,
preparation_feedback: ToolPreparationFeedback::None,
});
let registry = Arc::new(builder.build());
let runtime = ToolRuntime::new_without_permissions(Arc::clone(&registry));
Expand Down Expand Up @@ -2010,6 +2024,7 @@ mod tests {
execution_mode: ToolExecutionMode::ReadOnly,
capability_tags: vec![],
supports_parallel: false,
preparation_feedback: ToolPreparationFeedback::None,
});
let registry = Arc::new(builder.build());
let runtime = ToolRuntime::new_without_permissions(Arc::clone(&registry));
Expand Down Expand Up @@ -2067,6 +2082,7 @@ mod tests {
execution_mode: ToolExecutionMode::Mutating,
capability_tags: vec![],
supports_parallel: false,
preparation_feedback: ToolPreparationFeedback::None,
});
let registry = Arc::new(builder.build());
let runtime = ToolRuntime::new_without_permissions(Arc::clone(&registry));
Expand Down Expand Up @@ -2144,6 +2160,7 @@ mod tests {
execution_mode: ToolExecutionMode::ReadOnly,
capability_tags: vec![],
supports_parallel: true,
preparation_feedback: ToolPreparationFeedback::None,
});
let registry = Arc::new(builder.build());
let runtime = ToolRuntime::new_without_permissions(Arc::clone(&registry));
Expand Down
2 changes: 2 additions & 0 deletions crates/protocol/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ pub struct CommandExecutionPayload {
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct FileChangePayload {
pub tool_call_id: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub tool_name: Option<String>,
pub changes: Vec<(std::path::PathBuf, FileChange)>,
pub is_error: bool,
}
Expand Down
12 changes: 10 additions & 2 deletions crates/server/src/projection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,18 @@ fn parse_edited_history_metadata(output: &serde_json::Value) -> Option<SessionHi
.unwrap_or(0);
let change = match kind {
"add" => devo_protocol::protocol::FileChange::Add {
content: "\n".repeat(additions as usize),
content: file
.get("content")
.and_then(serde_json::Value::as_str)
.map(ToOwned::to_owned)
.unwrap_or_else(|| "\n".repeat(additions as usize)),
},
"delete" => devo_protocol::protocol::FileChange::Delete {
content: "\n".repeat(deletions as usize),
content: file
.get("content")
.and_then(serde_json::Value::as_str)
.map(ToOwned::to_owned)
.unwrap_or_else(|| "\n".repeat(deletions as usize)),
},
"update" | "move" => devo_protocol::protocol::FileChange::Update {
unified_diff: file
Expand Down
Loading
Loading