mirror of
https://github.com/Tencent/BrowserSkill.git
synced 2026-09-10 13:01:23 +08:00
feat: support Agent Window sizing (session start --width/--height, window resize) (#52)
- `bsk session start --width <px> --height <px>` opens the Agent Window with the given outer size (chrome.windows.create) - new `bsk window resize --session <id> --width <px> --height <px>` resizes the Agent Window at runtime (chrome.windows.update) - both validated on CLI, daemon and extension sides (100..=7680 CSS px) - protocol: new tool.window_resize method (BrowserMutation) and optional width/height on tool.session_start params; schemas regenerated
This commit is contained in:
@@ -45,6 +45,9 @@ fn main() {
|
||||
dump!(SessionStopParams, "tool_session_stop_params");
|
||||
dump!(SessionStopResult, "tool_session_stop_result");
|
||||
|
||||
dump!(WindowResizeParams, "tool_window_resize_params");
|
||||
dump!(WindowResizeResult, "tool_window_resize_result");
|
||||
|
||||
dump!(TabListParams, "tool_tab_list_params");
|
||||
dump!(TabListResult, "tool_tab_list_result");
|
||||
dump!(TabCreateParams, "tool_tab_create_params");
|
||||
|
||||
@@ -44,6 +44,8 @@ pub enum Method {
|
||||
ToolSessionStart,
|
||||
#[serde(rename = "tool.session_stop")]
|
||||
ToolSessionStop,
|
||||
#[serde(rename = "tool.window_resize")]
|
||||
ToolWindowResize,
|
||||
#[serde(rename = "tool.tab_list")]
|
||||
ToolTabList,
|
||||
#[serde(rename = "tool.tab_create")]
|
||||
@@ -140,6 +142,7 @@ impl Method {
|
||||
| Method::ToolTabBorrow
|
||||
| Method::ToolTabReturn
|
||||
| Method::ToolTabSelect
|
||||
| Method::ToolWindowResize
|
||||
| Method::ToolNavigate
|
||||
| Method::ToolNavigateBack
|
||||
| Method::ToolNavigateForward
|
||||
@@ -272,6 +275,7 @@ mod tests {
|
||||
assert!(Method::ToolSelect.is_mutating());
|
||||
assert!(Method::ToolEvaluate.is_mutating());
|
||||
assert!(Method::ToolRecordStart.is_mutating());
|
||||
assert!(Method::ToolWindowResize.is_mutating());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -12,6 +12,7 @@ pub mod script;
|
||||
pub mod session;
|
||||
pub mod tabs;
|
||||
pub mod waits;
|
||||
pub mod window;
|
||||
|
||||
pub use console::*;
|
||||
pub use dialog::*;
|
||||
@@ -25,3 +26,4 @@ pub use script::*;
|
||||
pub use session::*;
|
||||
pub use tabs::*;
|
||||
pub use waits::*;
|
||||
pub use window::*;
|
||||
|
||||
@@ -10,6 +10,12 @@ pub struct SessionStartParams {
|
||||
pub session_id: String,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub browser_instance_id: Option<String>,
|
||||
/// Optional Agent Window outer width in CSS pixels (100..=7680).
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub width: Option<u32>,
|
||||
/// Optional Agent Window outer height in CSS pixels (100..=7680).
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub height: Option<u32>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
|
||||
|
||||
Executable
+62
@@ -0,0 +1,62 @@
|
||||
//! Agent Window management tools (`tool.window_*`).
|
||||
|
||||
use schemars::JsonSchema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
// ----- window_resize -----
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct WindowResizeParams {
|
||||
pub session_id: String,
|
||||
/// New Agent Window outer width in CSS pixels (100..=7680).
|
||||
pub width: u32,
|
||||
/// New Agent Window outer height in CSS pixels (100..=7680).
|
||||
pub height: u32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct WindowResizeResult {
|
||||
pub window_id: i64,
|
||||
pub width: u32,
|
||||
pub height: u32,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use serde_json::json;
|
||||
|
||||
#[test]
|
||||
fn window_resize_params_round_trip() {
|
||||
let params: WindowResizeParams = serde_json::from_value(json!({
|
||||
"session_id": "ab12",
|
||||
"width": 1280,
|
||||
"height": 800,
|
||||
}))
|
||||
.unwrap();
|
||||
assert_eq!(params.session_id, "ab12");
|
||||
assert_eq!(params.width, 1280);
|
||||
assert_eq!(params.height, 800);
|
||||
let encoded = serde_json::to_value(params).unwrap();
|
||||
assert_eq!(
|
||||
encoded,
|
||||
json!({ "session_id": "ab12", "width": 1280, "height": 800 })
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn window_resize_result_round_trip() {
|
||||
let result: WindowResizeResult = serde_json::from_value(json!({
|
||||
"window_id": 42,
|
||||
"width": 1280,
|
||||
"height": 800,
|
||||
}))
|
||||
.unwrap();
|
||||
assert_eq!(result.window_id, 42);
|
||||
let encoded = serde_json::to_value(result).unwrap();
|
||||
assert_eq!(
|
||||
encoded,
|
||||
json!({ "window_id": 42, "width": 1280, "height": 800 })
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user