browsr_types/
browser_step.rs1use serde::{Deserialize, Serialize};
6
7use crate::Commands;
8
9#[derive(Debug, Clone, Serialize, Deserialize)]
11pub struct BrowserStepInput {
12 pub commands: Vec<Commands>,
14 #[serde(default)]
16 pub headless: Option<bool>,
17 #[serde(default)]
19 pub thinking: Option<String>,
20 #[serde(default)]
22 pub evaluation_previous_goal: Option<String>,
23 #[serde(default)]
25 pub memory: Option<String>,
26 #[serde(default)]
28 pub next_goal: Option<String>,
29}
30
31impl BrowserStepInput {
32 pub fn new(commands: Vec<Commands>) -> Self {
34 Self {
35 commands,
36 headless: None,
37 thinking: None,
38 evaluation_previous_goal: None,
39 memory: None,
40 next_goal: None,
41 }
42 }
43
44 pub fn with_headless(mut self, headless: bool) -> Self {
46 self.headless = Some(headless);
47 self
48 }
49}
50
51#[derive(Debug, Clone, Serialize, Deserialize)]
53pub struct BrowserStepRequest {
54 #[serde(default)]
56 pub session_id: String,
57 #[serde(default)]
59 pub thread_id: String,
60 #[serde(default)]
62 pub task_id: Option<String>,
63 #[serde(default)]
65 pub run_id: Option<String>,
66 #[serde(default)]
68 pub tool_call_id: Option<String>,
69 pub commands: Vec<Commands>,
71 #[serde(default)]
73 pub headless: Option<bool>,
74 #[serde(default)]
76 pub thinking: Option<String>,
77 #[serde(default)]
79 pub evaluation_previous_goal: Option<String>,
80 #[serde(default)]
82 pub memory: Option<String>,
83 #[serde(default)]
85 pub next_goal: Option<String>,
86}
87
88impl BrowserStepRequest {
89 pub fn new(input: BrowserStepInput) -> Self {
91 Self {
92 session_id: String::new(),
93 thread_id: String::new(),
94 task_id: None,
95 run_id: None,
96 tool_call_id: None,
97 commands: input.commands,
98 headless: input.headless,
99 thinking: input.thinking,
100 evaluation_previous_goal: input.evaluation_previous_goal,
101 memory: input.memory,
102 next_goal: input.next_goal,
103 }
104 }
105
106 pub fn with_session_id(mut self, session_id: impl Into<String>) -> Self {
108 self.session_id = session_id.into();
109 self
110 }
111
112 pub fn with_thread_id(mut self, thread_id: impl Into<String>) -> Self {
114 self.thread_id = thread_id.into();
115 self
116 }
117
118 pub fn with_task_id(mut self, task_id: impl Into<String>) -> Self {
120 self.task_id = Some(task_id.into());
121 self
122 }
123
124 pub fn with_run_id(mut self, run_id: impl Into<String>) -> Self {
126 self.run_id = Some(run_id.into());
127 self
128 }
129
130 pub fn with_tool_call_id(mut self, tool_call_id: impl Into<String>) -> Self {
132 self.tool_call_id = Some(tool_call_id.into());
133 self
134 }
135}
136
137#[derive(Debug, Clone, Serialize, Deserialize)]
139pub struct BrowserStepResult {
140 pub success: bool,
142 pub session_id: String,
144 pub summary: Option<String>,
146 pub url: Option<String>,
148 pub error: Option<String>,
150 pub sequence_id: Option<String>,
152 #[serde(skip_serializing_if = "Option::is_none")]
154 pub data: Option<serde_json::Value>,
155}
156
157impl BrowserStepResult {
158 pub fn success(session_id: impl Into<String>) -> Self {
160 Self {
161 success: true,
162 session_id: session_id.into(),
163 summary: None,
164 url: None,
165 error: None,
166 sequence_id: None,
167 data: None,
168 }
169 }
170
171 pub fn error(session_id: impl Into<String>, error: impl Into<String>) -> Self {
173 Self {
174 success: false,
175 session_id: session_id.into(),
176 summary: None,
177 url: None,
178 error: Some(error.into()),
179 sequence_id: None,
180 data: None,
181 }
182 }
183}