pub use crate::protocol_generated::types::*;
impl InputEvent {
pub fn user(text: impl Into<String>) -> Self {
Self {
user_input: Some(text.into()),
..Default::default()
}
}
pub fn halt() -> Self {
Self {
halt_request: Some(true),
..Default::default()
}
}
pub fn session_end() -> Self {
Self {
session_end_request: Some(true),
..Default::default()
}
}
pub fn tool_response(response: ToolResponse) -> Self {
Self {
tool_response: Some(response),
..Default::default()
}
}
pub fn hook_response(response: CallHookResponse) -> Self {
Self {
call_hook_response: Some(response),
..Default::default()
}
}
pub fn policy_response(response: PolicyDecisionResponse) -> Self {
Self {
policy_decision_response: Some(response),
..Default::default()
}
}
}
impl ToolResponse {
pub fn ok(id: impl Into<String>, response_json: impl Into<String>) -> Self {
Self {
id: Some(id.into()),
response_json: Some(response_json.into()),
..Default::default()
}
}
pub fn error(id: impl Into<String>, message: impl Into<String>) -> Self {
Self {
id: Some(id.into()),
error_message: Some(message.into()),
..Default::default()
}
}
}
impl HarnessSideTools {
pub fn none() -> Self {
Self::default()
}
pub fn read_only() -> Self {
Self {
list_dir: Some(ListDirToolConfig {
enabled: Some(true),
}),
grep_search: Some(GrepSearchToolConfig {
enabled: Some(true),
}),
find: Some(FindToolConfig {
enabled: Some(true),
}),
view_file: Some(ViewFileToolConfig {
enabled: Some(true),
}),
read_url_content: Some(ReadUrlContentToolConfig {
enabled: Some(true),
}),
..Default::default()
}
}
pub fn all() -> Self {
Self {
file_edit: Some(FileEditToolConfig {
enabled: Some(true),
}),
write_to_file: Some(WriteToFileToolConfig {
enabled: Some(true),
}),
run_command: Some(RunCommandToolConfig {
enabled: Some(true),
}),
subagents: Some(SubagentsConfig {
enabled: Some(true),
}),
user_questions: Some(UserQuestionsConfig {
enabled: Some(true),
}),
generate_image: Some(GenerateImageToolConfig {
enabled: Some(true),
}),
search_web: Some(SearchWebToolConfig {
enabled: Some(true),
}),
..Self::read_only()
}
}
}
impl StepUpdate {
pub fn is_terminal(&self) -> bool {
matches!(
self.state,
Some(StepUpdateState::Done) | Some(StepUpdateState::Error)
)
}
pub fn text_or_delta(&self) -> Option<&str> {
self.text
.as_deref()
.filter(|t| !t.is_empty())
.or(self.text_delta.as_deref().filter(|t| !t.is_empty()))
}
}
impl OutputEvent {
pub fn sequence(&self) -> Option<i64> {
self.seq_num
}
}