Because of a quirk of how implementation tests work in Rust, we had a number of `#[allow(dead_code)]` annotations that were misleading because the functions _were_ being used, just not by all integration tests in a `tests/` folder, so when compiling the test that did not use the function, clippy would complain that it was unused. This fixes things by create a "test_support" crate under the `tests/` folder that is imported as a dev dependency for the respective crate.
96 lines
2.5 KiB
Rust
96 lines
2.5 KiB
Rust
use serde_json::json;
|
|
use std::path::Path;
|
|
|
|
pub fn create_shell_sse_response(
|
|
command: Vec<String>,
|
|
workdir: Option<&Path>,
|
|
timeout_ms: Option<u64>,
|
|
call_id: &str,
|
|
) -> anyhow::Result<String> {
|
|
// The `arguments`` for the `shell` tool is a serialized JSON object.
|
|
let tool_call_arguments = serde_json::to_string(&json!({
|
|
"command": command,
|
|
"workdir": workdir.map(|w| w.to_string_lossy()),
|
|
"timeout": timeout_ms
|
|
}))?;
|
|
let tool_call = json!({
|
|
"choices": [
|
|
{
|
|
"delta": {
|
|
"tool_calls": [
|
|
{
|
|
"id": call_id,
|
|
"function": {
|
|
"name": "shell",
|
|
"arguments": tool_call_arguments
|
|
}
|
|
}
|
|
]
|
|
},
|
|
"finish_reason": "tool_calls"
|
|
}
|
|
]
|
|
});
|
|
|
|
let sse = format!(
|
|
"data: {}\n\ndata: DONE\n\n",
|
|
serde_json::to_string(&tool_call)?
|
|
);
|
|
Ok(sse)
|
|
}
|
|
|
|
pub fn create_final_assistant_message_sse_response(message: &str) -> anyhow::Result<String> {
|
|
let assistant_message = json!({
|
|
"choices": [
|
|
{
|
|
"delta": {
|
|
"content": message
|
|
},
|
|
"finish_reason": "stop"
|
|
}
|
|
]
|
|
});
|
|
|
|
let sse = format!(
|
|
"data: {}\n\ndata: DONE\n\n",
|
|
serde_json::to_string(&assistant_message)?
|
|
);
|
|
Ok(sse)
|
|
}
|
|
|
|
pub fn create_apply_patch_sse_response(
|
|
patch_content: &str,
|
|
call_id: &str,
|
|
) -> anyhow::Result<String> {
|
|
// Use shell command to call apply_patch with heredoc format
|
|
let shell_command = format!("apply_patch <<'EOF'\n{patch_content}\nEOF");
|
|
let tool_call_arguments = serde_json::to_string(&json!({
|
|
"command": ["bash", "-lc", shell_command]
|
|
}))?;
|
|
|
|
let tool_call = json!({
|
|
"choices": [
|
|
{
|
|
"delta": {
|
|
"tool_calls": [
|
|
{
|
|
"id": call_id,
|
|
"function": {
|
|
"name": "shell",
|
|
"arguments": tool_call_arguments
|
|
}
|
|
}
|
|
]
|
|
},
|
|
"finish_reason": "tool_calls"
|
|
}
|
|
]
|
|
});
|
|
|
|
let sse = format!(
|
|
"data: {}\n\ndata: DONE\n\n",
|
|
serde_json::to_string(&tool_call)?
|
|
);
|
|
Ok(sse)
|
|
}
|