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 FetchArgs {
146    pub url: String,
147    pub method: Option<String>,
148    pub headers: Option<serde_json::Value>,
149    pub body: Option<String>,
150    pub redirect: Option<String>,
151    #[serde(default)]
152    pub body_only: bool,
153    pub max_body: Option<usize>,
154}
155
156#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
157pub struct SetCookieArgs {
158    pub name: String,
159    pub value: String,
160    pub domain: Option<String>,
161    pub path: Option<String>,
162}
163
164#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
165pub struct DeleteCookieArgs {
166    pub name: String,
167    pub domain: Option<String>,
168}
169
170#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
171pub struct StorageArgs {
172    pub key: Option<String>,
173    #[serde(default)]
174    pub session_storage: bool,
175}
176
177#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
178pub struct SetStorageArgs {
179    pub key: String,
180    pub value: String,
181    #[serde(default)]
182    pub session_storage: bool,
183}
184
185#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
186pub struct PathArgs {
187    #[schemars(description = "File path.")]
188    pub path: String,
189}
190
191#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
192pub struct LoadStateArgs {
193    pub path: String,
194    #[serde(default)]
195    pub no_navigate: bool,
196}
197
198#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
199pub struct HeadersArgs {
200    pub headers_json: String,
201}
202
203#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
204pub struct ConsoleArgs {
205    #[serde(default)]
206    pub clear: bool,
207    pub level: Option<String>,
208}
209
210#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
211pub struct ClearFlagArgs {
212    #[serde(default)]
213    pub clear: bool,
214}
215
216#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
217pub struct TabNewArgs {
218    #[schemars(description = "Optional URL to navigate to. If omitted, opens a blank tab.")]
219    pub url: Option<String>,
220}
221
222#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
223pub struct TabIdArgs {
224    #[schemars(description = "Tab ID from list_tabs.")]
225    pub tab_id: String,
226}
227
228#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
229pub struct CloneFromArgs {
230    pub source: String,
231    pub to: Option<String>,
232}
233
234#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
235pub struct WaitArgs {
236    pub ms: Option<u64>,
237    pub text: Option<String>,
238    pub url: Option<String>,
239    pub load: Option<String>,
240    pub timeout: Option<u64>,
241}
242
243#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
244pub struct PathStringArgs {
245    #[schemars(description = "Target path, for example /docs or /about.")]
246    pub path: String,
247}
248
249#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
250pub struct FakeCameraArgs {
251    pub file: String,
252    #[serde(default)]
253    pub loop_video: bool,
254}
255
256#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
257pub struct WasmReadArgs {
258    pub addr: String,
259    pub len: usize,
260    pub memory: Option<String>,
261}
262
263#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
264pub struct WasmWriteArgs {
265    pub addr: String,
266    pub hex: String,
267    pub memory: Option<String>,
268}
269
270#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
271pub struct WasmFindArgs {
272    pub pattern: String,
273    pub start: Option<String>,
274    pub end: Option<String>,
275    #[serde(default = "default_wasm_find_max")]
276    pub max: usize,
277    pub memory: Option<String>,
278}
279
280impl Default for WasmFindArgs {
281    fn default() -> Self {
282        Self {
283            pattern: String::new(),
284            start: None,
285            end: None,
286            max: default_wasm_find_max(),
287            memory: None,
288        }
289    }
290}
291
292#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
293pub struct InterceptAddArgs {
294    pub url_pattern: String,
295    pub capture: Option<String>,
296    pub respond: Option<String>,
297    #[serde(default = "default_intercept_status")]
298    pub status: u16,
299}
300
301impl Default for InterceptAddArgs {
302    fn default() -> Self {
303        Self {
304            url_pattern: String::new(),
305            capture: None,
306            respond: None,
307            status: default_intercept_status(),
308        }
309    }
310}
311
312#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
313pub struct IdArgs {
314    pub id: String,
315}
316
317#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
318pub struct ModeArgs {
319    pub mode: String,
320}
321
322#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
323pub struct DomainArgs {
324    pub domain: String,
325}
326
327#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
328pub struct CaptchaInjectArgs {
329    pub token: String,
330    #[serde(default = "default_captcha_type")]
331    pub captcha_type: String,
332    pub callback: Option<String>,
333    pub click_after: Option<String>,
334}
335
336#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
337pub struct NetworkRecordStartArgs {
338    #[serde(default)]
339    pub patterns: Vec<String>,
340    #[serde(default)]
341    pub no_bodies: bool,
342    #[serde(default = "default_max_body_bytes")]
343    pub max_body_bytes: usize,
344    #[serde(default)]
345    pub clear: bool,
346}
347
348#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
349pub struct NetworkLogArgs {
350    pub limit: Option<usize>,
351    pub pattern: Option<String>,
352    pub method: Option<String>,
353    pub status: Option<u16>,
354    pub since: Option<u64>,
355    #[serde(default)]
356    pub compact: bool,
357}
358
359#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
360pub struct NetworkShowArgs {
361    pub id: u64,
362    #[serde(default)]
363    pub body: bool,
364    pub max_body: Option<usize>,
365}
366
367#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
368pub struct NetworkWaitArgs {
369    pub pattern: Option<String>,
370    pub method: Option<String>,
371    pub status: Option<u16>,
372    pub timeout: Option<u64>,
373    pub since: Option<u64>,
374    #[serde(default)]
375    pub include_existing: bool,
376}
377
378#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
379pub struct NetworkExportArgs {
380    pub path: String,
381    #[serde(default = "default_network_export_format")]
382    pub format: String,
383    pub settle_ms: Option<u64>,
384}
385
386impl Default for NetworkExportArgs {
387    fn default() -> Self {
388        Self {
389            path: String::new(),
390            format: default_network_export_format(),
391            settle_ms: None,
392        }
393    }
394}
395
396fn default_max_body_bytes() -> usize {
397    10 * 1024 * 1024
398}
399
400fn default_network_export_format() -> String {
401    "har".to_string()
402}
403
404fn default_viewport_width() -> u32 {
405    390
406}
407
408fn default_viewport_height() -> u32 {
409    844
410}
411
412fn default_device_pixel_ratio() -> f64 {
413    2.0
414}
415
416fn default_wasm_find_max() -> usize {
417    20
418}
419
420fn default_intercept_status() -> u16 {
421    200
422}
423
424fn default_captcha_type() -> String {
425    "auto".to_string()
426}