chore: rework unified exec events (#7775)

This commit is contained in:
jif-oai authored and GitHub committed 2025-12-10 10:30:38 +00:00
1 parent d1c5db5796
commit 0ad54982ae
20 files changed
+876 -174

No files matched your search

+1 -2
View File
@@ -134,7 +134,6 @@ impl ToolEmitter {
command: &[String],
cwd: PathBuf,
source: ExecCommandSource,
interaction_input: Option<String>,
process_id: Option<String>,
) -> Self {
let parsed_cmd = parse_command(command);
@@ -142,7 +141,7 @@ impl ToolEmitter {
command: command.to_vec(),
cwd,
source,
interaction_input,
interaction_input: None, // TODO(jif) drop this field in the protocol.
parsed_cmd,
process_id,
}
@@ -1,9 +1,8 @@
use crate::function_tool::FunctionCallError;
use crate::is_safe_command::is_known_safe_command;
use crate::protocol::EventMsg;
use crate::protocol::ExecCommandOutputDeltaEvent;
use crate::protocol::ExecCommandSource;
use crate::protocol::ExecOutputStream;
use crate::protocol::TerminalInteractionEvent;
use crate::shell::Shell;
use crate::shell::get_shell_by_model_provided_path;
use crate::tools::context::ToolInvocation;
@@ -189,7 +188,6 @@ impl ToolHandler for UnifiedExecHandler {
&command,
cwd.clone(),
ExecCommandSource::UnifiedExecStartup,
None,
Some(process_id.clone()),
);
emitter.emit(event_ctx, ToolEventStage::Begin).await;
@@ -218,7 +216,7 @@ impl ToolHandler for UnifiedExecHandler {
"failed to parse write_stdin arguments: {err:?}"
))
})?;
manager
let response = manager
.write_stdin(WriteStdinRequest {
process_id: &args.session_id.to_string(),
input: &args.chars,
@@ -228,7 +226,18 @@ impl ToolHandler for UnifiedExecHandler {
.await
.map_err(|err| {
FunctionCallError::RespondToModel(format!("write_stdin failed: {err:?}"))
})?
})?;
let interaction = TerminalInteractionEvent {
call_id: response.event_call_id.clone(),
process_id: args.session_id.to_string(),
stdin: args.chars.clone(),
};
session
.send_event(turn.as_ref(), EventMsg::TerminalInteraction(interaction))
.await;
response
}
other => {
return Err(FunctionCallError::RespondToModel(format!(
@@ -237,18 +246,6 @@ impl ToolHandler for UnifiedExecHandler {
}
};
// Emit a delta event with the chunk of output we just produced, if any.
if !response.output.is_empty() {
let delta = ExecCommandOutputDeltaEvent {
call_id: response.event_call_id.clone(),
stream: ExecOutputStream::Stdout,
chunk: response.output.as_bytes().to_vec(),
};
session
.send_event(turn.as_ref(), EventMsg::ExecCommandOutputDelta(delta))
.await;
}
let content = format_response(&response);
Ok(ToolOutput::Function {