Skip to main content

eoka_protocol/
agent.rs

1use crate::{
2    Destination, ErrorDetail, Expectation, InputMode, OperationRecord, OperationStatus, PageContext,
3};
4use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
7#[cfg_attr(feature = "clap", derive(clap::Args))]
8#[serde(deny_unknown_fields)]
9pub struct AgentObserveArgs {
10    #[cfg_attr(
11        feature = "clap",
12        arg(long, help = "Continue from a cursor returned by a previous view")
13    )]
14    #[serde(default)]
15    pub cursor: Option<String>,
16    #[cfg_attr(feature = "clap", arg(long, help = "Only controls with this role"))]
17    #[serde(default)]
18    pub role: Option<String>,
19    #[cfg_attr(
20        feature = "clap",
21        arg(long, help = "Only controls whose accessible name contains this text")
22    )]
23    #[serde(default)]
24    pub name: Option<String>,
25    #[cfg_attr(
26        feature = "clap",
27        arg(
28            long,
29            default_value_t = 40,
30            help = "Maximum controls to return, 1 through 200"
31        )
32    )]
33    #[schemars(description = "Maximum labeled controls, 1 through 200. Increase if truncated.")]
34    #[serde(default = "control_limit")]
35    #[schemars(range(min = 1, max = 200))]
36    pub max_controls: usize,
37    #[cfg_attr(
38        feature = "clap",
39        arg(
40            long,
41            default_value_t = 3000,
42            help = "Observation deadline, 50 through 60000 ms"
43        )
44    )]
45    #[serde(default = "observe_timeout")]
46    #[schemars(range(min = 50, max = 60000))]
47    pub timeout_ms: u64,
48}
49
50fn control_limit() -> usize {
51    40
52}
53fn observe_timeout() -> u64 {
54    3000
55}
56fn step_timeout() -> u64 {
57    10000
58}
59fn action_timeout() -> u64 {
60    30000
61}
62
63impl Default for AgentObserveArgs {
64    fn default() -> Self {
65        Self {
66            cursor: None,
67            role: None,
68            name: None,
69            max_controls: control_limit(),
70            timeout_ms: observe_timeout(),
71        }
72    }
73}
74
75#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, schemars::JsonSchema)]
76#[serde(rename_all = "snake_case")]
77pub enum AgentMode {
78    Explore,
79    #[default]
80    Verify,
81}
82
83#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
84#[serde(tag = "kind", rename_all = "snake_case", deny_unknown_fields)]
85pub enum AgentAction {
86    Click {
87        target: String,
88    },
89    Fill {
90        target: String,
91        text: String,
92        #[serde(default)]
93        input_mode: InputMode,
94    },
95    Type {
96        target: String,
97        text: String,
98        #[serde(default)]
99        input_mode: InputMode,
100    },
101    Focus {
102        target: String,
103    },
104    Select {
105        target: String,
106        value: String,
107    },
108    Hover {
109        target: String,
110    },
111    ScrollIntoView {
112        target: String,
113    },
114    PressKey {
115        key: String,
116    },
117    Navigate {
118        url: String,
119    },
120    Back,
121    Forward,
122}
123
124#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
125#[serde(deny_unknown_fields)]
126pub struct AgentStepArgs {
127    #[serde(default)]
128    pub destination: Destination,
129    #[schemars(
130        description = "Optional canonical UUID. SDK/CLI allocate before sending; direct MCP callers should supply one when recovery from a lost response is required. Reuse only with identical action arguments."
131    )]
132    #[serde(default)]
133    pub operation_id: Option<String>,
134    pub action: AgentAction,
135    #[schemars(
136        description = "Explore permits input without a predicted result and reports unverified outcomes honestly. Verify requires explicit expectations for actions without intrinsic completion evidence."
137    )]
138    #[serde(default)]
139    pub mode: AgentMode,
140    #[serde(default)]
141    pub expect: Option<Expectation>,
142    #[serde(default = "step_timeout")]
143    #[schemars(range(min = 50, max = 60000))]
144    pub timeout_ms: u64,
145    #[schemars(
146        description = "Independent action deadline, 1 through 300000 milliseconds. A shorter response wait never cancels or repeats the action."
147    )]
148    #[serde(default = "action_timeout")]
149    #[schemars(range(min = 1, max = 300000))]
150    pub action_timeout_ms: u64,
151    #[serde(default = "control_limit")]
152    #[schemars(range(min = 1, max = 200))]
153    pub max_controls: usize,
154}
155
156#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
157pub struct AgentControl {
158    pub target: String,
159    pub role: String,
160    pub name: String,
161    pub disabled: bool,
162    pub checked: Option<bool>,
163    pub expanded: Option<bool>,
164    pub focused: bool,
165    pub editable: bool,
166    pub readonly: bool,
167    pub required: bool,
168    pub invalid: bool,
169    pub validation_message: Option<String>,
170}
171
172#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
173pub struct AgentTab {
174    pub id: String,
175    pub url: String,
176    pub title: String,
177    pub selected: bool,
178}
179
180#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
181pub struct AgentObservation {
182    pub observation_id: String,
183    pub tab_id: String,
184    pub page: Option<PageContext>,
185    pub tabs: Vec<AgentTab>,
186    pub controls: Vec<AgentControl>,
187    pub truncated: bool,
188    pub next_cursor: Option<String>,
189    pub total_controls: usize,
190    pub warnings: Vec<String>,
191}
192
193#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
194pub struct AgentStepResult {
195    pub status: OperationStatus,
196    pub operation_id: String,
197    pub operation: Option<OperationRecord>,
198    pub operation_error: Option<ErrorDetail>,
199    pub observation: Option<AgentObservation>,
200    pub observation_error: Option<String>,
201}