(
base_url: String,
input: String,
command: Option<String>,
continue_last: bool,
session: Option<String>,
fork: bool,
share: bool,
model: Option<String>,
variant: O
| 1282 | } |
| 1283 | |
| 1284 | async fn run_non_interactive_attach( |
| 1285 | base_url: String, |
| 1286 | input: String, |
| 1287 | command: Option<String>, |
| 1288 | continue_last: bool, |
| 1289 | session: Option<String>, |
| 1290 | fork: bool, |
| 1291 | share: bool, |
| 1292 | model: Option<String>, |
| 1293 | variant: Option<String>, |
| 1294 | format: RunOutputFormat, |
| 1295 | title: Option<String>, |
| 1296 | ) -> anyhow::Result<()> { |
| 1297 | let client = reqwest::Client::new(); |
| 1298 | let session_id = |
| 1299 | resolve_remote_session(&client, &base_url, continue_last, session, fork, title).await?; |
| 1300 | maybe_share_remote_session(&client, &base_url, &session_id, share).await?; |
| 1301 | |
| 1302 | let content = if let Some(command_name) = command { |
| 1303 | if input.trim().is_empty() { |
| 1304 | format!("/{}", command_name) |
| 1305 | } else { |
| 1306 | format!("/{} {}", command_name, input) |
| 1307 | } |
| 1308 | } else { |
| 1309 | input |
| 1310 | }; |
| 1311 | |
| 1312 | let endpoint = server_url(&base_url, &format!("/session/{}/stream", session_id)); |
| 1313 | let response = client |
| 1314 | .post(endpoint) |
| 1315 | .json(&serde_json::json!({ |
| 1316 | "content": content, |
| 1317 | "model": model, |
| 1318 | "variant": variant, |
| 1319 | "stream": true |
| 1320 | })) |
| 1321 | .send() |
| 1322 | .await?; |
| 1323 | |
| 1324 | if !response.status().is_success() { |
| 1325 | let status = response.status(); |
| 1326 | let body = response.text().await.unwrap_or_default(); |
| 1327 | anyhow::bail!("Remote run failed ({}): {}", status, body); |
| 1328 | } |
| 1329 | |
| 1330 | consume_remote_sse(response, &session_id, format).await |
| 1331 | } |
| 1332 | |
| 1333 | async fn run_non_interactive( |
| 1334 | message: Vec<String>, |
no test coverage detected