Skip to main content

eoka_protocol/
args.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
4pub struct OpenArgs {
5    pub url: String,
6    pub headers: Option<serde_json::Value>,
7    pub user_agent: Option<String>,
8    #[serde(default)]
9    pub bypass_csp: bool,
10    pub inject_js: Option<String>,
11    pub load_state: Option<String>,
12}
13
14#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
15pub struct SnapshotArgs {
16    #[serde(default)]
17    pub interactive: bool,
18    #[serde(default)]
19    pub all: bool,
20}
21
22#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
23pub struct ObserveArgs {
24    #[schemars(
25        description = "Filter: 'inputs' for form elements, 'buttons' for buttons and links, or 'all' for all observed elements."
26    )]
27    pub filter: Option<String>,
28    #[schemars(description = "Maximum elements to return.")]
29    pub max: Option<usize>,
30    #[serde(default)]
31    pub structured: bool,
32}
33
34#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
35pub struct ScreenshotArgs {
36    pub output: Option<String>,
37    #[serde(default)]
38    pub annotate: bool,
39}
40
41#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
42pub struct EmulateArgs {
43    #[serde(default = "default_viewport_width")]
44    pub width: u32,
45    #[serde(default = "default_viewport_height")]
46    pub height: u32,
47    #[serde(default = "default_device_pixel_ratio")]
48    pub dpr: f64,
49    #[serde(default)]
50    pub desktop: bool,
51    #[serde(default)]
52    pub reset: bool,
53}
54
55impl Default for EmulateArgs {
56    fn default() -> Self {
57        Self {
58            width: default_viewport_width(),
59            height: default_viewport_height(),
60            dpr: default_device_pixel_ratio(),
61            desktop: false,
62            reset: false,
63        }
64    }
65}
66
67#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
68pub struct TextArgs {
69    #[schemars(description = "Text substring to search for, matched case-insensitively.")]
70    pub text: String,
71}
72
73#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
74pub struct TargetArgs {
75    #[schemars(
76        description = "Target element. Supports index, snapshot refs like @e1, text:Submit, placeholder:Email, role:button, css:form button, id:my-btn, or plain text search."
77    )]
78    pub target: String,
79}
80
81#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
82pub struct FillArgs {
83    #[schemars(
84        description = "Target input. Supports index, text:Email, placeholder:Enter code, css:input.search, id:email-field, or plain text search."
85    )]
86    pub target: String,
87    #[schemars(description = "Text to type into the element.")]
88    pub text: String,
89}
90
91#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
92pub struct SelectArgs {
93    #[schemars(description = "Target select element by index, text, CSS selector, id, or role.")]
94    pub target: String,
95    #[schemars(description = "Option value or visible text to select.")]
96    pub value: String,
97}
98
99#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
100pub struct KeyArgs {
101    #[schemars(
102        description = "Key to press, for example Enter, Tab, Escape, ArrowDown, or Backspace."
103    )]
104    pub key: String,
105}
106
107#[derive(Debug, Clone, Copy, Serialize, Deserialize, schemars::JsonSchema)]
108#[serde(rename_all = "lowercase")]
109pub enum MouseButton {
110    Left,
111    Middle,
112    Right,
113    Back,
114    Forward,
115}
116
117#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
118pub struct MouseButtonArgs {
119    #[schemars(description = "Viewport horizontal coordinate in CSS pixels.")]
120    pub x: f64,
121    #[schemars(description = "Viewport vertical coordinate in CSS pixels.")]
122    pub y: f64,
123    #[schemars(description = "Mouse button to hold or release.")]
124    pub button: MouseButton,
125}
126
127#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
128pub struct MouseMoveArgs {
129    #[schemars(description = "Viewport horizontal coordinate in CSS pixels.")]
130    pub x: f64,
131    #[schemars(description = "Viewport vertical coordinate in CSS pixels.")]
132    pub y: f64,
133}
134
135#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
136pub struct ScriptArgs {
137    pub code: Option<String>,
138    pub file: Option<String>,
139    pub max_size: Option<usize>,
140    #[serde(default)]
141    pub no_await: bool,
142}
143
144#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
145pub struct FrameEvalArgs {
146    #[schemars(
147        description = "CSS selector matching exactly one iframe/frame in the top document, or id:<frame-id> from frames for explicit/nested selection. Bare URLs and indices are not supported. Evaluation uses an isolated world, not page-owned JavaScript globals."
148    )]
149    pub frame: String,
150    pub code: Option<String>,
151    pub file: Option<String>,
152}
153
154#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
155pub struct FetchArgs {
156    pub url: String,
157    pub method: Option<String>,
158    pub headers: Option<serde_json::Value>,
159    pub body: Option<String>,
160    pub redirect: Option<String>,
161    #[serde(default)]
162    pub body_only: bool,
163    pub max_body: Option<usize>,
164}
165
166#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
167pub struct SetCookieArgs {
168    pub name: String,
169    pub value: String,
170    pub domain: Option<String>,
171    pub path: Option<String>,
172}
173
174#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
175pub struct DeleteCookieArgs {
176    pub name: String,
177    pub domain: Option<String>,
178}
179
180#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
181pub struct StorageArgs {
182    pub key: Option<String>,
183    #[serde(default)]
184    pub session_storage: bool,
185}
186
187#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
188pub struct SetStorageArgs {
189    pub key: String,
190    pub value: String,
191    #[serde(default)]
192    pub session_storage: bool,
193}
194
195#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
196pub struct PathArgs {
197    #[schemars(description = "File path.")]
198    pub path: String,
199}
200
201#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
202pub struct LoadStateArgs {
203    pub path: String,
204    #[serde(default)]
205    pub no_navigate: bool,
206}
207
208#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
209pub struct HeadersArgs {
210    pub headers_json: String,
211}
212
213#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
214pub struct ConsoleArgs {
215    #[serde(default)]
216    pub clear: bool,
217    pub level: Option<String>,
218}
219
220#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
221pub struct ClearFlagArgs {
222    #[serde(default)]
223    pub clear: bool,
224}
225
226#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
227pub struct TabNewArgs {
228    #[schemars(description = "Optional URL to navigate to. If omitted, opens a blank tab.")]
229    pub url: Option<String>,
230}
231
232#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
233pub struct TabIdArgs {
234    #[schemars(description = "Tab ID from list_tabs.")]
235    pub tab_id: String,
236}
237
238#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
239pub struct CloneFromArgs {
240    pub source: String,
241    pub to: Option<String>,
242}
243
244#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
245pub struct WaitArgs {
246    pub ms: Option<u64>,
247    pub text: Option<String>,
248    pub url: Option<String>,
249    pub load: Option<String>,
250    pub timeout: Option<u64>,
251}
252
253#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
254pub struct PathStringArgs {
255    #[schemars(description = "Target path, for example /docs or /about.")]
256    pub path: String,
257}
258
259#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
260pub struct FakeCameraArgs {
261    pub file: String,
262    #[serde(default)]
263    pub loop_video: bool,
264}
265
266#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
267pub struct WasmReadArgs {
268    pub addr: String,
269    pub len: usize,
270    pub memory: Option<String>,
271}
272
273#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
274pub struct WasmWriteArgs {
275    pub addr: String,
276    pub hex: String,
277    pub memory: Option<String>,
278}
279
280#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
281pub struct WasmFindArgs {
282    pub pattern: String,
283    pub start: Option<String>,
284    pub end: Option<String>,
285    #[serde(default = "default_wasm_find_max")]
286    pub max: usize,
287    pub memory: Option<String>,
288}
289
290impl Default for WasmFindArgs {
291    fn default() -> Self {
292        Self {
293            pattern: String::new(),
294            start: None,
295            end: None,
296            max: default_wasm_find_max(),
297            memory: None,
298        }
299    }
300}
301
302#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
303pub struct InterceptAddArgs {
304    pub url_pattern: String,
305    pub capture: Option<String>,
306    pub respond: Option<String>,
307    #[serde(default = "default_intercept_status")]
308    pub status: u16,
309}
310
311impl Default for InterceptAddArgs {
312    fn default() -> Self {
313        Self {
314            url_pattern: String::new(),
315            capture: None,
316            respond: None,
317            status: default_intercept_status(),
318        }
319    }
320}
321
322#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
323pub struct IdArgs {
324    pub id: String,
325}
326
327#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
328pub struct ModeArgs {
329    pub mode: String,
330}
331
332#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
333pub struct DomainArgs {
334    pub domain: String,
335}
336
337#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
338pub struct CaptchaInjectArgs {
339    pub token: String,
340    #[serde(default = "default_captcha_type")]
341    pub captcha_type: String,
342    pub callback: Option<String>,
343    pub click_after: Option<String>,
344}
345
346#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
347pub struct NetworkRecordStartArgs {
348    #[serde(default)]
349    pub patterns: Vec<String>,
350    #[serde(default)]
351    pub no_bodies: bool,
352    #[serde(default = "default_max_body_bytes")]
353    pub max_body_bytes: usize,
354    #[serde(default)]
355    pub clear: bool,
356}
357
358#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
359pub struct NetworkLogArgs {
360    pub limit: Option<usize>,
361    pub pattern: Option<String>,
362    pub method: Option<String>,
363    pub status: Option<u16>,
364    pub since: Option<u64>,
365    #[serde(default)]
366    pub compact: bool,
367}
368
369#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
370pub struct NetworkShowArgs {
371    pub id: u64,
372    #[serde(default)]
373    pub body: bool,
374    pub max_body: Option<usize>,
375}
376
377#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
378pub struct NetworkWaitArgs {
379    pub pattern: Option<String>,
380    pub method: Option<String>,
381    pub status: Option<u16>,
382    pub timeout: Option<u64>,
383    pub since: Option<u64>,
384    #[serde(default)]
385    pub include_existing: bool,
386}
387
388#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
389pub struct NetworkExportArgs {
390    pub path: String,
391    #[serde(default = "default_network_export_format")]
392    pub format: String,
393    pub settle_ms: Option<u64>,
394}
395
396impl Default for NetworkExportArgs {
397    fn default() -> Self {
398        Self {
399            path: String::new(),
400            format: default_network_export_format(),
401            settle_ms: None,
402        }
403    }
404}
405
406fn default_max_body_bytes() -> usize {
407    10 * 1024 * 1024
408}
409
410fn default_network_export_format() -> String {
411    "har".to_string()
412}
413
414fn default_viewport_width() -> u32 {
415    390
416}
417
418fn default_viewport_height() -> u32 {
419    844
420}
421
422fn default_device_pixel_ratio() -> f64 {
423    2.0
424}
425
426fn default_wasm_find_max() -> usize {
427    20
428}
429
430fn default_intercept_status() -> u16 {
431    200
432}
433
434fn default_captcha_type() -> String {
435    "auto".to_string()
436}