browsr_types/
browser_step.rs1use schemars::JsonSchema;
6use serde::{Deserialize, Serialize};
7
8use crate::Commands;
9
10#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
12pub struct BrowserStepInput {
13 pub commands: Vec<Commands>,
15 #[serde(default)]
17 pub headless: Option<bool>,
18 #[serde(default)]
20 pub thinking: Option<String>,
21 #[serde(default)]
23 pub evaluation_previous_goal: Option<String>,
24 #[serde(default)]
26 pub memory: Option<String>,
27 #[serde(default)]
29 pub next_goal: Option<String>,
30}
31
32impl BrowserStepInput {
33 pub fn new(commands: Vec<Commands>) -> Self {
35 Self {
36 commands,
37 headless: None,
38 thinking: None,
39 evaluation_previous_goal: None,
40 memory: None,
41 next_goal: None,
42 }
43 }
44
45 pub fn with_headless(mut self, headless: bool) -> Self {
47 self.headless = Some(headless);
48 self
49 }
50}
51
52#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
54pub struct BrowserStepRequest {
55 #[serde(default)]
57 pub session_id: String,
58 #[serde(default)]
60 pub thread_id: String,
61 #[serde(default)]
63 pub task_id: Option<String>,
64 #[serde(default)]
66 pub run_id: Option<String>,
67 #[serde(default)]
69 pub tool_call_id: Option<String>,
70 pub commands: Vec<Commands>,
72 #[serde(default)]
74 pub headless: Option<bool>,
75 #[serde(default)]
77 pub thinking: Option<String>,
78 #[serde(default)]
80 pub evaluation_previous_goal: Option<String>,
81 #[serde(default)]
83 pub memory: Option<String>,
84 #[serde(default)]
86 pub next_goal: Option<String>,
87}
88
89impl BrowserStepRequest {
90 pub fn new(input: BrowserStepInput) -> Self {
92 Self {
93 session_id: String::new(),
94 thread_id: String::new(),
95 task_id: None,
96 run_id: None,
97 tool_call_id: None,
98 commands: input.commands,
99 headless: input.headless,
100 thinking: input.thinking,
101 evaluation_previous_goal: input.evaluation_previous_goal,
102 memory: input.memory,
103 next_goal: input.next_goal,
104 }
105 }
106
107 pub fn with_session_id(mut self, session_id: impl Into<String>) -> Self {
109 self.session_id = session_id.into();
110 self
111 }
112
113 pub fn with_thread_id(mut self, thread_id: impl Into<String>) -> Self {
115 self.thread_id = thread_id.into();
116 self
117 }
118
119 pub fn with_task_id(mut self, task_id: impl Into<String>) -> Self {
121 self.task_id = Some(task_id.into());
122 self
123 }
124
125 pub fn with_run_id(mut self, run_id: impl Into<String>) -> Self {
127 self.run_id = Some(run_id.into());
128 self
129 }
130
131 pub fn with_tool_call_id(mut self, tool_call_id: impl Into<String>) -> Self {
133 self.tool_call_id = Some(tool_call_id.into());
134 self
135 }
136}
137
138#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
140pub struct BrowserStepResult {
141 pub success: bool,
143 pub session_id: String,
145 pub summary: Option<String>,
147 pub url: Option<String>,
149 pub error: Option<String>,
151 pub sequence_id: Option<String>,
153 #[serde(skip_serializing_if = "Option::is_none")]
155 pub data: Option<serde_json::Value>,
156}
157
158impl BrowserStepResult {
159 pub fn success(session_id: impl Into<String>) -> Self {
161 Self {
162 success: true,
163 session_id: session_id.into(),
164 summary: None,
165 url: None,
166 error: None,
167 sequence_id: None,
168 data: None,
169 }
170 }
171
172 pub fn error(session_id: impl Into<String>, error: impl Into<String>) -> Self {
174 Self {
175 success: false,
176 session_id: session_id.into(),
177 summary: None,
178 url: None,
179 error: Some(error.into()),
180 sequence_id: None,
181 data: None,
182 }
183 }
184}