agentmux_common/
place_args.rs1use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone, Default, Serialize, Deserialize)]
9pub struct PlaceArgs {
10 #[serde(default, skip_serializing_if = "Option::is_none")]
12 pub width: Option<serde_json::Value>,
13 #[serde(default, skip_serializing_if = "Option::is_none")]
14 pub height: Option<serde_json::Value>,
15 #[serde(default, skip_serializing_if = "Option::is_none")]
17 pub spot: Option<String>,
18 #[serde(default, skip_serializing_if = "Option::is_none")]
19 pub x: Option<f64>,
20 #[serde(default, skip_serializing_if = "Option::is_none")]
21 pub y: Option<f64>,
22}
23
24impl PlaceArgs {
25 pub fn of(arguments: &serde_json::Value) -> Result<Self, String> {
27 let size = |k: &str| match arguments.get(k) {
28 None | Some(serde_json::Value::Null) => Ok(None),
29 Some(v @ (serde_json::Value::Number(_) | serde_json::Value::String(_))) => Ok(Some(v.clone())),
30 Some(other) => Err(format!("{k} is a number of CSS pixels or a share of the work area such as 60%, not {other}")),
31 };
32 let coord = |k: &str| match arguments.get(k) {
33 None | Some(serde_json::Value::Null) => Ok(None),
34 Some(v) => v.as_f64().map(Some).ok_or_else(|| format!("{k} is a number of CSS pixels, not {v}")),
35 };
36 Ok(Self {
37 width: size("width")?,
38 height: size("height")?,
39 spot: arguments.get("spot").and_then(|v| v.as_str()).map(str::to_string),
40 x: coord("x")?,
41 y: coord("y")?,
42 })
43 }
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
49pub struct PanePlaceRequest {
50 pub op: String,
54 pub target_id: String,
56 #[serde(flatten)]
57 pub place: PlaceArgs,
58 #[serde(default, skip_serializing_if = "Option::is_none")]
60 pub split: Option<String>,
61 #[serde(default, skip_serializing_if = "Option::is_none")]
63 pub block_id: Option<String>,
64}