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}
31
32#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
33pub struct ScreenshotArgs {
34    pub output: Option<String>,
35    #[serde(default)]
36    pub annotate: bool,
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
40pub struct EmulateArgs {
41    #[serde(default = "default_viewport_width")]
42    pub width: u32,
43    #[serde(default = "default_viewport_height")]
44    pub height: u32,
45    #[serde(default = "default_device_pixel_ratio")]
46    pub dpr: f64,
47    #[serde(default)]
48    pub desktop: bool,
49    #[serde(default)]
50    pub reset: bool,
51}
52
53impl Default for EmulateArgs {
54    fn default() -> Self {
55        Self {
56            width: default_viewport_width(),
57            height: default_viewport_height(),
58            dpr: default_device_pixel_ratio(),
59            desktop: false,
60            reset: false,
61        }
62    }
63}
64
65#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
66pub struct TextArgs {
67    #[schemars(description = "Text substring to search for, matched case-insensitively.")]
68    pub text: String,
69}
70
71#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
72pub struct TargetArgs {
73    #[schemars(
74        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."
75    )]
76    pub target: String,
77}
78
79#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
80pub struct FillArgs {
81    #[schemars(
82        description = "Target input. Supports index, text:Email, placeholder:Enter code, css:input.search, id:email-field, or plain text search."
83    )]
84    pub target: String,
85    #[schemars(description = "Text to type into the element.")]
86    pub text: String,
87}
88
89#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
90pub struct SelectArgs {
91    #[schemars(description = "Target select element by index, text, CSS selector, id, or role.")]
92    pub target: String,
93    #[schemars(description = "Option value or visible text to select.")]
94    pub value: String,
95}
96
97#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
98pub struct KeyArgs {
99    #[schemars(
100        description = "Key to press, for example Enter, Tab, Escape, ArrowDown, or Backspace."
101    )]
102    pub key: String,
103}
104
105#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
106pub struct ScriptArgs {
107    pub code: Option<String>,
108    pub file: Option<String>,
109    pub max_size: Option<usize>,
110    #[serde(default)]
111    pub no_await: bool,
112}
113
114#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
115pub struct FetchArgs {
116    pub url: String,
117    pub method: Option<String>,
118    pub headers: Option<serde_json::Value>,
119    pub body: Option<String>,
120    pub redirect: Option<String>,
121    #[serde(default)]
122    pub body_only: bool,
123    pub max_body: Option<usize>,
124}
125
126#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
127pub struct SetCookieArgs {
128    pub name: String,
129    pub value: String,
130    pub domain: Option<String>,
131    pub path: Option<String>,
132}
133
134#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
135pub struct DeleteCookieArgs {
136    pub name: String,
137    pub domain: Option<String>,
138}
139
140#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
141pub struct StorageArgs {
142    pub key: Option<String>,
143    #[serde(default)]
144    pub session_storage: bool,
145}
146
147#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
148pub struct SetStorageArgs {
149    pub key: String,
150    pub value: String,
151    #[serde(default)]
152    pub session_storage: bool,
153}
154
155#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
156pub struct PathArgs {
157    #[schemars(description = "File path.")]
158    pub path: String,
159}
160
161#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
162pub struct LoadStateArgs {
163    pub path: String,
164    #[serde(default)]
165    pub no_navigate: bool,
166}
167
168#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
169pub struct HeadersArgs {
170    pub headers_json: String,
171}
172
173#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
174pub struct ConsoleArgs {
175    #[serde(default)]
176    pub clear: bool,
177    pub level: Option<String>,
178}
179
180#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
181pub struct ClearFlagArgs {
182    #[serde(default)]
183    pub clear: bool,
184}
185
186#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
187pub struct TabNewArgs {
188    #[schemars(description = "Optional URL to navigate to. If omitted, opens a blank tab.")]
189    pub url: Option<String>,
190}
191
192#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
193pub struct TabIdArgs {
194    #[schemars(description = "Tab ID from list_tabs.")]
195    pub tab_id: String,
196}
197
198#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
199pub struct CloneFromArgs {
200    pub source: String,
201    pub to: Option<String>,
202}
203
204#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
205pub struct WaitArgs {
206    pub ms: Option<u64>,
207    pub text: Option<String>,
208    pub url: Option<String>,
209    pub load: Option<String>,
210    pub timeout: Option<u64>,
211}
212
213#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
214pub struct PathStringArgs {
215    #[schemars(description = "Target path, for example /docs or /about.")]
216    pub path: String,
217}
218
219#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
220pub struct FakeCameraArgs {
221    pub file: String,
222    #[serde(default)]
223    pub loop_video: bool,
224}
225
226#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
227pub struct WasmReadArgs {
228    pub addr: String,
229    pub len: usize,
230    pub memory: Option<String>,
231}
232
233#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
234pub struct WasmWriteArgs {
235    pub addr: String,
236    pub hex: String,
237    pub memory: Option<String>,
238}
239
240#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
241pub struct WasmFindArgs {
242    pub pattern: String,
243    pub start: Option<String>,
244    pub end: Option<String>,
245    #[serde(default = "default_wasm_find_max")]
246    pub max: usize,
247    pub memory: Option<String>,
248}
249
250impl Default for WasmFindArgs {
251    fn default() -> Self {
252        Self {
253            pattern: String::new(),
254            start: None,
255            end: None,
256            max: default_wasm_find_max(),
257            memory: None,
258        }
259    }
260}
261
262#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
263pub struct InterceptAddArgs {
264    pub url_pattern: String,
265    pub capture: Option<String>,
266    pub respond: Option<String>,
267    #[serde(default = "default_intercept_status")]
268    pub status: u16,
269}
270
271impl Default for InterceptAddArgs {
272    fn default() -> Self {
273        Self {
274            url_pattern: String::new(),
275            capture: None,
276            respond: None,
277            status: default_intercept_status(),
278        }
279    }
280}
281
282#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
283pub struct IdArgs {
284    pub id: String,
285}
286
287#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
288pub struct ModeArgs {
289    pub mode: String,
290}
291
292#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
293pub struct DomainArgs {
294    pub domain: String,
295}
296
297#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
298pub struct CaptchaInjectArgs {
299    pub token: String,
300    #[serde(default = "default_captcha_type")]
301    pub captcha_type: String,
302    pub callback: Option<String>,
303    pub click_after: Option<String>,
304}
305
306#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
307pub struct NetworkRecordStartArgs {
308    #[serde(default)]
309    pub patterns: Vec<String>,
310    #[serde(default)]
311    pub no_bodies: bool,
312    #[serde(default = "default_max_body_bytes")]
313    pub max_body_bytes: usize,
314    #[serde(default)]
315    pub clear: bool,
316}
317
318#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
319pub struct NetworkLogArgs {
320    pub limit: Option<usize>,
321    pub pattern: Option<String>,
322    pub method: Option<String>,
323    pub status: Option<u16>,
324    pub since: Option<u64>,
325    #[serde(default)]
326    pub compact: bool,
327}
328
329#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
330pub struct NetworkShowArgs {
331    pub id: u64,
332    #[serde(default)]
333    pub body: bool,
334    pub max_body: Option<usize>,
335}
336
337#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
338pub struct NetworkWaitArgs {
339    pub pattern: Option<String>,
340    pub method: Option<String>,
341    pub status: Option<u16>,
342    pub timeout: Option<u64>,
343    pub since: Option<u64>,
344    #[serde(default)]
345    pub include_existing: bool,
346}
347
348#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
349pub struct NetworkExportArgs {
350    pub path: String,
351    #[serde(default = "default_network_export_format")]
352    pub format: String,
353    pub settle_ms: Option<u64>,
354}
355
356impl Default for NetworkExportArgs {
357    fn default() -> Self {
358        Self {
359            path: String::new(),
360            format: default_network_export_format(),
361            settle_ms: None,
362        }
363    }
364}
365
366fn default_max_body_bytes() -> usize {
367    10 * 1024 * 1024
368}
369
370fn default_network_export_format() -> String {
371    "har".to_string()
372}
373
374fn default_viewport_width() -> u32 {
375    390
376}
377
378fn default_viewport_height() -> u32 {
379    844
380}
381
382fn default_device_pixel_ratio() -> f64 {
383    2.0
384}
385
386fn default_wasm_find_max() -> usize {
387    20
388}
389
390fn default_intercept_status() -> u16 {
391    200
392}
393
394fn default_captcha_type() -> String {
395    "auto".to_string()
396}