mirror of
https://github.com/Tencent/BrowserSkill.git
synced 2026-09-10 13:01:23 +08:00
`bsk session start --no-focus` opens the Agent Window in the background without stealing focus. The flag threads focused=false through CLI -> daemon IPC -> tool.session_start -> chrome.windows.create; an omitted `focused` keeps the extension default (true) so older clients are unaffected. Reworked onto current main so it composes with #52 window sizing: AgentWindowApi.create / SessionManager.start (extension), start_session (CLI) and the daemon's session start now take options objects/structs ({ size, focused }) instead of colliding positional params. Co-authored-by: alectimison-maker <alec.timison@gmail.com>
91 lines
3.1 KiB
Rust
91 lines
3.1 KiB
Rust
//! Session-scoped tools (`tool.session_*`).
|
|
|
|
use schemars::JsonSchema;
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use crate::ErrorCode;
|
|
|
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
|
|
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>,
|
|
/// Whether the new Agent Window should take focus. Omitted means the
|
|
/// extension's default (`true`) for compatibility with older clients.
|
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
|
pub focused: Option<bool>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
|
|
pub struct SessionStartResult {
|
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
|
pub agent_window_id: Option<i64>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
|
|
pub struct SessionStopParams {
|
|
pub session_id: String,
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
|
|
pub struct ReturnFailure {
|
|
pub tab_id: i64,
|
|
pub code: ErrorCode,
|
|
pub message: String,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize, JsonSchema)]
|
|
pub struct SessionStopResult {
|
|
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
|
pub returned_tab_ids: Vec<i64>,
|
|
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
|
pub return_failures: Vec<ReturnFailure>,
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
use serde_json::json;
|
|
|
|
#[test]
|
|
fn session_start_focus_is_optional_and_round_trips_false() {
|
|
let defaulted: SessionStartParams = serde_json::from_value(json!({
|
|
"session_id": "aa11"
|
|
}))
|
|
.unwrap();
|
|
assert_eq!(defaulted.focused, None);
|
|
|
|
let background: SessionStartParams = serde_json::from_value(json!({
|
|
"session_id": "aa11",
|
|
"focused": false
|
|
}))
|
|
.unwrap();
|
|
assert_eq!(background.focused, Some(false));
|
|
assert_eq!(serde_json::to_value(background).unwrap()["focused"], false);
|
|
}
|
|
|
|
#[test]
|
|
fn session_stop_result_round_trips_auto_return_payload() {
|
|
let result: SessionStopResult = serde_json::from_value(json!({
|
|
"returned_tab_ids": [7, 8],
|
|
"return_failures": [
|
|
{ "tab_id": 9, "code": "cdp_failed", "message": "move failed" }
|
|
]
|
|
}))
|
|
.unwrap();
|
|
|
|
assert_eq!(result.returned_tab_ids, vec![7, 8]);
|
|
assert_eq!(result.return_failures[0].tab_id, 9);
|
|
assert_eq!(result.return_failures[0].code, ErrorCode::CdpFailed);
|
|
let encoded = serde_json::to_value(result).unwrap();
|
|
assert_eq!(encoded["returned_tab_ids"], json!([7, 8]));
|
|
assert_eq!(encoded["return_failures"][0]["code"], "cdp_failed");
|
|
}
|
|
}
|