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#[serde(deny_unknown_fields)]
8pub struct AgentObserveArgs {
9    #[serde(default)]
10    pub cursor: Option<String>,
11    #[serde(default)]
12    pub role: Option<String>,
13    #[serde(default)]
14    pub name: Option<String>,
15    #[schemars(description = "Maximum labeled controls, 1 through 200. Increase if truncated.")]
16    #[serde(default = "control_limit")]
17    #[schemars(range(min = 1, max = 200))]
18    pub max_controls: usize,
19    #[serde(default = "observe_timeout")]
20    #[schemars(range(min = 50, max = 60000))]
21    pub timeout_ms: u64,
22}
23
24fn control_limit() -> usize {
25    40
26}
27fn observe_timeout() -> u64 {
28    3000
29}
30fn step_timeout() -> u64 {
31    10000
32}
33fn action_timeout() -> u64 {
34    30000
35}
36
37impl Default for AgentObserveArgs {
38    fn default() -> Self {
39        Self {
40            cursor: None,
41            role: None,
42            name: None,
43            max_controls: control_limit(),
44            timeout_ms: observe_timeout(),
45        }
46    }
47}
48
49#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, schemars::JsonSchema)]
50#[serde(rename_all = "snake_case")]
51pub enum AgentMode {
52    Explore,
53    #[default]
54    Verify,
55}
56
57#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
58#[serde(tag = "kind", rename_all = "snake_case", deny_unknown_fields)]
59pub enum AgentAction {
60    Click {
61        target: String,
62    },
63    Fill {
64        target: String,
65        text: String,
66        #[serde(default)]
67        input_mode: InputMode,
68    },
69    Type {
70        target: String,
71        text: String,
72        #[serde(default)]
73        input_mode: InputMode,
74    },
75    Focus {
76        target: String,
77    },
78    Select {
79        target: String,
80        value: String,
81    },
82    Hover {
83        target: String,
84    },
85    ScrollIntoView {
86        target: String,
87    },
88    PressKey {
89        key: String,
90    },
91    Navigate {
92        url: String,
93    },
94    Back,
95    Forward,
96}
97
98#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
99#[serde(deny_unknown_fields)]
100pub struct AgentStepArgs {
101    #[serde(default)]
102    pub destination: Destination,
103    #[schemars(
104        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."
105    )]
106    #[serde(default)]
107    pub operation_id: Option<String>,
108    pub action: AgentAction,
109    #[schemars(
110        description = "Explore permits input without a predicted result and reports unverified outcomes honestly. Verify requires explicit expectations for actions without intrinsic completion evidence."
111    )]
112    #[serde(default)]
113    pub mode: AgentMode,
114    #[serde(default)]
115    pub expect: Option<Expectation>,
116    #[serde(default = "step_timeout")]
117    #[schemars(range(min = 50, max = 60000))]
118    pub timeout_ms: u64,
119    #[schemars(
120        description = "Independent action deadline, 1 through 300000 milliseconds. A shorter response wait never cancels or repeats the action."
121    )]
122    #[serde(default = "action_timeout")]
123    #[schemars(range(min = 1, max = 300000))]
124    pub action_timeout_ms: u64,
125    #[serde(default = "control_limit")]
126    #[schemars(range(min = 1, max = 200))]
127    pub max_controls: usize,
128}
129
130#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
131pub struct AgentControl {
132    pub target: String,
133    pub role: String,
134    pub name: String,
135    pub disabled: bool,
136    pub checked: Option<bool>,
137    pub expanded: Option<bool>,
138    pub focused: bool,
139    pub editable: bool,
140    pub readonly: bool,
141    pub required: bool,
142    pub invalid: bool,
143    pub validation_message: Option<String>,
144}
145
146#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
147pub struct AgentTab {
148    pub id: String,
149    pub url: String,
150    pub title: String,
151    pub selected: bool,
152}
153
154#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
155pub struct AgentObservation {
156    pub observation_id: String,
157    pub tab_id: String,
158    pub page: Option<PageContext>,
159    pub tabs: Vec<AgentTab>,
160    pub controls: Vec<AgentControl>,
161    pub truncated: bool,
162    pub next_cursor: Option<String>,
163    pub total_controls: usize,
164    pub warnings: Vec<String>,
165}
166
167#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
168pub struct AgentStepResult {
169    pub status: OperationStatus,
170    pub operation_id: String,
171    pub operation: Option<OperationRecord>,
172    pub operation_error: Option<ErrorDetail>,
173    pub observation: Option<AgentObservation>,
174    pub observation_error: Option<String>,
175}