victauri-plugin 0.2.0

Tauri plugin for Victauri — embedded MCP server with full-stack introspection
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::fmt;

// ── Enums ──────────────────────────────────────────────────────────────────

/// Web storage type for browser storage operations.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum StorageType {
    /// Browser localStorage (persistent across sessions).
    Local,
    /// Browser sessionStorage (cleared when tab closes).
    Session,
}

impl StorageType {
    /// Returns the JavaScript property name for this storage type.
    #[must_use]
    pub fn js_property(self) -> &'static str {
        match self {
            Self::Local => "localStorage",
            Self::Session => "sessionStorage",
        }
    }
}

impl fmt::Display for StorageType {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::Local => f.write_str("local"),
            Self::Session => f.write_str("session"),
        }
    }
}

/// Browser dialog type for dialog response configuration.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum DialogType {
    /// JavaScript `alert()` dialog.
    Alert,
    /// JavaScript `confirm()` dialog.
    Confirm,
    /// JavaScript `prompt()` dialog.
    Prompt,
}

impl DialogType {
    /// Returns the lowercase string for JS bridge consumption.
    #[must_use]
    pub fn as_str(self) -> &'static str {
        match self {
            Self::Alert => "alert",
            Self::Confirm => "confirm",
            Self::Prompt => "prompt",
        }
    }
}

impl fmt::Display for DialogType {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.write_str(self.as_str())
    }
}

/// Action to take on a browser dialog.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum DialogAction {
    /// Accept the dialog (click OK/Yes).
    Accept,
    /// Dismiss the dialog (click Cancel/No).
    Dismiss,
}

impl DialogAction {
    /// Returns the lowercase string for JS bridge consumption.
    #[must_use]
    pub fn as_str(self) -> &'static str {
        match self {
            Self::Accept => "accept",
            Self::Dismiss => "dismiss",
        }
    }
}

impl fmt::Display for DialogAction {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.write_str(self.as_str())
    }
}

// ── interact ────────────────────────────────────────────────────────────────

/// Action for the compound `interact` tool.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum InteractAction {
    /// Click an element.
    Click,
    /// Double-click an element.
    DoubleClick,
    /// Hover over an element.
    Hover,
    /// Focus an element.
    Focus,
    /// Scroll an element into view.
    ScrollIntoView,
    /// Select an option in a `<select>` element.
    SelectOption,
}

impl fmt::Display for InteractAction {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::Click => f.write_str("click"),
            Self::DoubleClick => f.write_str("double_click"),
            Self::Hover => f.write_str("hover"),
            Self::Focus => f.write_str("focus"),
            Self::ScrollIntoView => f.write_str("scroll_into_view"),
            Self::SelectOption => f.write_str("select_option"),
        }
    }
}

/// Parameters for the compound `interact` tool (click, hover, focus, scroll, select).
#[derive(Debug, Deserialize, JsonSchema)]
pub struct InteractParams {
    /// Action to perform: click, `double_click`, hover, focus, `scroll_into_view`, `select_option`.
    pub action: InteractAction,
    /// Ref handle ID from a DOM snapshot (e.g. "e5"). Required for click, `double_click`, hover, focus, `select_option`.
    pub ref_id: Option<String>,
    /// Option values for `select_option` action.
    pub values: Option<Vec<String>>,
    /// Horizontal scroll position (pixels). Used with `scroll_into_view` when `ref_id` is null.
    pub x: Option<f64>,
    /// Vertical scroll position (pixels). Used with `scroll_into_view` when `ref_id` is null.
    pub y: Option<f64>,
    /// Target webview label.
    pub webview_label: Option<String>,
}

// ── input ───────────────────────────────────────────────────────────────────

/// Action for the compound `input` tool.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum InputAction {
    /// Set an input element's value directly.
    Fill,
    /// Type text character-by-character.
    TypeText,
    /// Press a keyboard key.
    PressKey,
}

impl fmt::Display for InputAction {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::Fill => f.write_str("fill"),
            Self::TypeText => f.write_str("type_text"),
            Self::PressKey => f.write_str("press_key"),
        }
    }
}

/// Parameters for the compound `input` tool (fill, `type_text`, `press_key`).
#[derive(Debug, Deserialize, JsonSchema)]
pub struct InputParams {
    /// Action to perform: fill, `type_text`, `press_key`.
    pub action: InputAction,
    /// Ref handle ID of the target element. Required for fill and `type_text`.
    pub ref_id: Option<String>,
    /// Value to set (for fill action).
    pub value: Option<String>,
    /// Text to type character-by-character (for `type_text` action).
    pub text: Option<String>,
    /// Key to press (for `press_key` action, e.g. "Enter", "Escape", "Tab", "`ArrowDown`").
    pub key: Option<String>,
    /// Target webview label.
    pub webview_label: Option<String>,
}

// ── window ──────────────────────────────────────────────────────────────────

/// Action for the compound `window` tool.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum WindowAction {
    /// Get the current state of a window.
    GetState,
    /// List all window labels.
    List,
    /// Manage a window (minimize, maximize, close, etc.).
    Manage,
    /// Resize a window.
    Resize,
    /// Move a window to a new position.
    MoveTo,
    /// Set a window's title.
    SetTitle,
}

impl fmt::Display for WindowAction {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::GetState => f.write_str("get_state"),
            Self::List => f.write_str("list"),
            Self::Manage => f.write_str("manage"),
            Self::Resize => f.write_str("resize"),
            Self::MoveTo => f.write_str("move_to"),
            Self::SetTitle => f.write_str("set_title"),
        }
    }
}

/// Window management sub-action for the `manage` action.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum ManageAction {
    /// Minimize the window.
    Minimize,
    /// Restore from minimized state.
    Unminimize,
    /// Maximize the window.
    Maximize,
    /// Restore from maximized state.
    Unmaximize,
    /// Close the window.
    Close,
    /// Focus the window.
    Focus,
    /// Show the window.
    Show,
    /// Hide the window.
    Hide,
    /// Enter fullscreen mode.
    Fullscreen,
    /// Exit fullscreen mode.
    Unfullscreen,
    /// Set the window to always be on top.
    AlwaysOnTop,
    /// Remove the always-on-top flag.
    NotAlwaysOnTop,
}

impl ManageAction {
    /// Returns the `snake_case` string for bridge consumption.
    #[must_use]
    pub fn as_str(self) -> &'static str {
        match self {
            Self::Minimize => "minimize",
            Self::Unminimize => "unminimize",
            Self::Maximize => "maximize",
            Self::Unmaximize => "unmaximize",
            Self::Close => "close",
            Self::Focus => "focus",
            Self::Show => "show",
            Self::Hide => "hide",
            Self::Fullscreen => "fullscreen",
            Self::Unfullscreen => "unfullscreen",
            Self::AlwaysOnTop => "always_on_top",
            Self::NotAlwaysOnTop => "not_always_on_top",
        }
    }
}

impl fmt::Display for ManageAction {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.write_str(self.as_str())
    }
}

/// Parameters for the compound `window` tool (`get_state`, list, manage, resize, move, title).
#[derive(Debug, Deserialize, JsonSchema)]
pub struct WindowParams {
    /// Action to perform: `get_state`, list, manage, resize, `move_to`, `set_title`.
    pub action: WindowAction,
    /// Target window label.
    pub label: Option<String>,
    /// Window management action (for manage): minimize, unminimize, maximize, unmaximize, close, focus, show, hide, fullscreen, unfullscreen, `always_on_top`, `not_always_on_top`.
    pub manage_action: Option<ManageAction>,
    /// Width in logical pixels (for resize).
    pub width: Option<u32>,
    /// Height in logical pixels (for resize).
    pub height: Option<u32>,
    /// X position in logical pixels (for `move_to`).
    pub x: Option<i32>,
    /// Y position in logical pixels (for `move_to`).
    pub y: Option<i32>,
    /// New window title (for `set_title`).
    pub title: Option<String>,
}

// ── storage ─────────────────────────────────────────────────────────────────

/// Action for the compound `storage` tool.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum StorageAction {
    /// Read a value from storage.
    Get,
    /// Write a value to storage.
    Set,
    /// Delete a value from storage.
    Delete,
    /// Get all cookies.
    GetCookies,
}

impl fmt::Display for StorageAction {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::Get => f.write_str("get"),
            Self::Set => f.write_str("set"),
            Self::Delete => f.write_str("delete"),
            Self::GetCookies => f.write_str("get_cookies"),
        }
    }
}

/// Parameters for the compound `storage` tool (get, set, delete, `get_cookies`).
#[derive(Debug, Deserialize, JsonSchema)]
pub struct StorageParams {
    /// Action to perform: get, set, delete, `get_cookies`.
    pub action: StorageAction,
    /// Storage type for get/set/delete. Defaults to local if omitted.
    pub storage_type: Option<StorageType>,
    /// Key to read, write, or delete.
    pub key: Option<String>,
    /// Value to store (for set action). Will be JSON-serialized if not a string.
    pub value: Option<serde_json::Value>,
    /// Target webview label.
    pub webview_label: Option<String>,
}

// ── navigate ────────────────────────────────────────────────────────────────

/// Action for the compound `navigate` tool.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum NavigateAction {
    /// Navigate to a URL.
    GoTo,
    /// Navigate back in browser history.
    GoBack,
    /// Get the navigation history log.
    GetHistory,
    /// Set an auto-response for browser dialogs.
    SetDialogResponse,
    /// Get the dialog event log.
    GetDialogLog,
}

impl fmt::Display for NavigateAction {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::GoTo => f.write_str("go_to"),
            Self::GoBack => f.write_str("go_back"),
            Self::GetHistory => f.write_str("get_history"),
            Self::SetDialogResponse => f.write_str("set_dialog_response"),
            Self::GetDialogLog => f.write_str("get_dialog_log"),
        }
    }
}

/// Parameters for the compound `navigate` tool (`go_to`, `go_back`, history, dialogs).
#[derive(Debug, Deserialize, JsonSchema)]
pub struct NavigateParams {
    /// Action to perform: `go_to`, `go_back`, `get_history`, `set_dialog_response`, `get_dialog_log`.
    pub action: NavigateAction,
    /// URL to navigate to (for `go_to` action).
    pub url: Option<String>,
    /// Dialog type (for `set_dialog_response`).
    pub dialog_type: Option<DialogType>,
    /// Dialog action (for `set_dialog_response`).
    pub dialog_action: Option<DialogAction>,
    /// Response text for prompt dialogs (for `set_dialog_response`).
    pub text: Option<String>,
    /// Target webview label.
    pub webview_label: Option<String>,
}

// ── recording ───────────────────────────────────────────────────────────────

/// Action for the compound `recording` tool.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum RecordingAction {
    /// Begin recording events.
    Start,
    /// Stop recording and return the session.
    Stop,
    /// Save a state checkpoint.
    Checkpoint,
    /// List all checkpoints in the current session.
    ListCheckpoints,
    /// Get events since an index.
    GetEvents,
    /// Get events between two checkpoints.
    EventsBetween,
    /// Get an IPC replay sequence.
    GetReplay,
    /// Export the current session as JSON.
    Export,
    /// Import a previously exported session.
    Import,
}

impl fmt::Display for RecordingAction {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::Start => f.write_str("start"),
            Self::Stop => f.write_str("stop"),
            Self::Checkpoint => f.write_str("checkpoint"),
            Self::ListCheckpoints => f.write_str("list_checkpoints"),
            Self::GetEvents => f.write_str("get_events"),
            Self::EventsBetween => f.write_str("events_between"),
            Self::GetReplay => f.write_str("get_replay"),
            Self::Export => f.write_str("export"),
            Self::Import => f.write_str("import"),
        }
    }
}

/// Parameters for the compound `recording` tool (start, stop, checkpoint, replay, export, import).
#[derive(Debug, Deserialize, JsonSchema)]
pub struct RecordingParams {
    /// Action to perform: start, stop, checkpoint, `list_checkpoints`, `get_events`, `events_between`, `get_replay`, export, import.
    pub action: RecordingAction,
    /// Session ID (for start — optional, UUID generated if omitted).
    pub session_id: Option<String>,
    /// Checkpoint ID (for checkpoint, required).
    pub checkpoint_id: Option<String>,
    /// Checkpoint label (for checkpoint, optional).
    pub checkpoint_label: Option<String>,
    /// State snapshot as JSON (for checkpoint).
    pub state: Option<serde_json::Value>,
    /// Starting checkpoint ID (for `events_between`).
    pub from: Option<String>,
    /// Ending checkpoint ID (for `events_between`).
    pub to: Option<String>,
    /// Only return events after this index (for `get_events`).
    pub since_index: Option<usize>,
    /// JSON string of a previously exported `RecordedSession` (for import).
    pub session_json: Option<String>,
}

// ── inspect ─────────────────────────────────────────────────────────────────

/// Action for the compound `inspect` tool.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum InspectAction {
    /// Get computed CSS styles for an element.
    GetStyles,
    /// Get bounding boxes for elements.
    GetBoundingBoxes,
    /// Add a debug highlight overlay to an element.
    Highlight,
    /// Remove all debug highlight overlays.
    ClearHighlights,
    /// Run an accessibility audit.
    AuditAccessibility,
    /// Get performance metrics (timing, heap, DOM).
    GetPerformance,
}

impl fmt::Display for InspectAction {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::GetStyles => f.write_str("get_styles"),
            Self::GetBoundingBoxes => f.write_str("get_bounding_boxes"),
            Self::Highlight => f.write_str("highlight"),
            Self::ClearHighlights => f.write_str("clear_highlights"),
            Self::AuditAccessibility => f.write_str("audit_accessibility"),
            Self::GetPerformance => f.write_str("get_performance"),
        }
    }
}

/// Parameters for the compound `inspect` tool (styles, bounding boxes, highlight, a11y, perf).
#[derive(Debug, Deserialize, JsonSchema)]
pub struct InspectParams {
    /// Action to perform: `get_styles`, `get_bounding_boxes`, highlight, `clear_highlights`, `audit_accessibility`, `get_performance`.
    pub action: InspectAction,
    /// Ref handle ID (for `get_styles`, highlight).
    pub ref_id: Option<String>,
    /// List of ref handle IDs (for `get_bounding_boxes`).
    pub ref_ids: Option<Vec<String>>,
    /// CSS property names to return (for `get_styles` — if omitted, returns key properties).
    pub properties: Option<Vec<String>>,
    /// CSS color for the highlight overlay (for highlight, default: "rgba(255, 0, 0, 0.3)").
    pub color: Option<String>,
    /// Text label displayed above the highlight (for highlight).
    #[serde(rename = "highlight_label")]
    pub label: Option<String>,
    /// Target webview label.
    pub webview_label: Option<String>,
}

// ── css ─────────────────────────────────────────────────────────────────────

/// Action for the compound `css` tool.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum CssAction {
    /// Inject custom CSS into the page.
    Inject,
    /// Remove previously injected CSS.
    Remove,
}

impl fmt::Display for CssAction {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::Inject => f.write_str("inject"),
            Self::Remove => f.write_str("remove"),
        }
    }
}

/// Parameters for the compound `css` tool (inject, remove).
#[derive(Debug, Deserialize, JsonSchema)]
pub struct CssParams {
    /// Action to perform: inject, remove.
    pub action: CssAction,
    /// CSS text to inject (for inject action).
    pub css: Option<String>,
    /// Target webview label.
    pub webview_label: Option<String>,
}

// ── logs ────────────────────────────────────────────────────────────────────

/// Action for the compound `logs` tool.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum LogsAction {
    /// Get captured console.log/warn/error entries.
    Console,
    /// Get intercepted fetch/XHR network requests.
    Network,
    /// Get IPC call log.
    Ipc,
    /// Get URL change history.
    Navigation,
    /// Get alert/confirm/prompt dialog events.
    Dialogs,
    /// Get combined event stream.
    Events,
    /// Find slow IPC calls exceeding a threshold.
    SlowIpc,
}

impl fmt::Display for LogsAction {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::Console => f.write_str("console"),
            Self::Network => f.write_str("network"),
            Self::Ipc => f.write_str("ipc"),
            Self::Navigation => f.write_str("navigation"),
            Self::Dialogs => f.write_str("dialogs"),
            Self::Events => f.write_str("events"),
            Self::SlowIpc => f.write_str("slow_ipc"),
        }
    }
}

/// Parameters for the compound `logs` tool (console, network, ipc, navigation, dialogs, events).
#[derive(Debug, Deserialize, JsonSchema)]
pub struct LogsParams {
    /// Action to perform: console, network, ipc, navigation, dialogs, events, `slow_ipc`.
    pub action: LogsAction,
    /// Only return entries after this Unix timestamp in milliseconds (for console, events).
    pub since: Option<f64>,
    /// Filter by URL substring (for network).
    pub filter: Option<String>,
    /// Maximum number of entries to return (for ipc, network, `slow_ipc`).
    pub limit: Option<usize>,
    /// Threshold in milliseconds for slow IPC calls (for `slow_ipc`).
    pub threshold_ms: Option<u64>,
    /// When true (for ipc action), await up to 500ms for the latest IPC entry's
    /// response body to be fully captured. Uses event-driven signaling from the
    /// fetch interceptor rather than polling.
    pub wait_for_capture: Option<bool>,
    /// Target webview label.
    pub webview_label: Option<String>,
}