Skip to main content

victauri_plugin/mcp/
other_params.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3use std::fmt;
4
5// ── Enums ──────────────────────────────────────────────────────────────────
6
7/// Condition to poll for in the `wait_for` tool.
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
9#[serde(rename_all = "snake_case")]
10pub enum WaitCondition {
11    /// Wait for text to appear in the page.
12    Text,
13    /// Wait for text to disappear from the page.
14    TextGone,
15    /// Wait for a CSS selector to match an element.
16    Selector,
17    /// Wait for a CSS selector to stop matching.
18    SelectorGone,
19    /// Wait for the URL to contain a substring.
20    Url,
21    /// Wait for all IPC calls to complete.
22    IpcIdle,
23    /// Wait for all network requests to complete.
24    NetworkIdle,
25}
26
27impl WaitCondition {
28    /// Returns the `snake_case` string for JS bridge consumption.
29    #[must_use]
30    pub fn as_str(self) -> &'static str {
31        match self {
32            Self::Text => "text",
33            Self::TextGone => "text_gone",
34            Self::Selector => "selector",
35            Self::SelectorGone => "selector_gone",
36            Self::Url => "url",
37            Self::IpcIdle => "ipc_idle",
38            Self::NetworkIdle => "network_idle",
39        }
40    }
41}
42
43impl fmt::Display for WaitCondition {
44    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
45        f.write_str(self.as_str())
46    }
47}
48
49// ── Intent ─────────────────────────────────────────────────────────────────
50
51/// Parameters for the `resolve_command` tool.
52#[derive(Debug, Deserialize, JsonSchema)]
53pub struct ResolveCommandParams {
54    /// Natural language query describing what you want to do (e.g. "save the user's settings").
55    pub query: String,
56    /// Maximum number of results to return. Default: 5.
57    pub limit: Option<usize>,
58}
59
60/// Parameters for the `semantic_assert` tool.
61#[derive(Debug, Deserialize, JsonSchema)]
62pub struct SemanticAssertParams {
63    /// JavaScript expression to evaluate in the webview. The result is checked against the assertion.
64    pub expression: String,
65    /// Human-readable label for this assertion (e.g. "user is logged in").
66    /// Optional — defaults to empty so a minimal `{expression, condition}` call
67    /// succeeds instead of failing deserialization with an opaque 400.
68    #[serde(default)]
69    pub label: String,
70    /// Condition to evaluate against the actual value.
71    pub condition: victauri_core::AssertionCondition,
72    /// Expected value for the assertion. Optional for truthy/falsy/exists conditions.
73    #[serde(default)]
74    pub expected: serde_json::Value,
75    /// Target webview label.
76    pub webview_label: Option<String>,
77}
78
79// ── Wait ───────────────────────────────────────────────────────────────────
80
81/// Parameters for the `wait_for` tool.
82#[derive(Debug, Deserialize, JsonSchema)]
83pub struct WaitForParams {
84    /// Condition to wait for.
85    pub condition: WaitCondition,
86    /// Value for the condition (text to find, CSS selector, URL substring).
87    pub value: Option<String>,
88    /// Maximum time to wait in milliseconds. Default: 10000.
89    pub timeout_ms: Option<u64>,
90    /// Polling interval in milliseconds. Default: 200.
91    pub poll_ms: Option<u64>,
92    /// Target webview label.
93    pub webview_label: Option<String>,
94}
95
96// ── Find Elements ──────────────────────────────────────────────────────────
97
98/// Parameters for the `find_elements` tool.
99#[derive(Debug, Deserialize, JsonSchema)]
100pub struct FindElementsParams {
101    /// Text content to search for (case-insensitive substring match).
102    pub text: Option<String>,
103    /// ARIA role to match (exact match).
104    pub role: Option<String>,
105    /// data-testid attribute value to match (exact match).
106    pub test_id: Option<String>,
107    /// CSS selector to match (also accepts `selector` as an alias).
108    pub css: Option<String>,
109    /// Alias for `css` — CSS selector to match.
110    pub selector: Option<String>,
111    /// Accessible name to search for (aria-label, title, placeholder -- case-insensitive substring).
112    pub name: Option<String>,
113    /// Maximum number of results to return. Default: 10.
114    pub max_results: Option<u32>,
115    /// HTML tag name to match (e.g. "button", "input").
116    pub tag: Option<String>,
117    /// Placeholder text to match (case-insensitive substring).
118    pub placeholder: Option<String>,
119    /// Alt text to match (case-insensitive substring).
120    pub alt: Option<String>,
121    /// Title attribute to match (case-insensitive substring).
122    pub title_attr: Option<String>,
123    /// Associated label text to match (finds inputs by their label).
124    pub label: Option<String>,
125    /// If true, text matching is exact instead of substring.
126    pub exact: Option<bool>,
127    /// Filter by enabled state.
128    pub enabled: Option<bool>,
129    /// Target webview label.
130    pub webview_label: Option<String>,
131}
132
133/// Parameters for the `get_diagnostics` tool.
134#[derive(Debug, Deserialize, JsonSchema)]
135pub struct DiagnosticsParams {
136    /// Target a specific webview window by label.
137    pub webview_label: Option<String>,
138}