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