gestura_core_tools/
gui.rs

1//! GUI Control Tool
2//!
3//! Provides a stub tool that the agent can invoke to control the frontend UI.
4//! When invoked, the backend validates the action and the frontend intercepts
5//! the start of the tool to update its UI state seamlessly.
6//!
7//! # Tools
8//! - `gui_control`: dispatches a synthetic event that the frontend uses for UI
9//!   layout.
10
11use crate::error::Result;
12use serde::{Deserialize, Serialize};
13
14/// Supported GUI actions
15#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
16#[serde(rename_all = "snake_case")]
17pub enum GuiAction {
18    ToggleViewMode,
19    OpenExplorer,
20    CloseExplorer,
21    OpenChat,
22    CloseChat,
23    NavigateConfig,
24}
25
26/// Request payload for GUI control
27#[derive(Debug, Clone, Serialize, Deserialize)]
28pub struct GuiControlRequest {
29    pub action: GuiAction,
30    pub target: Option<String>,
31}
32
33/// Response payload for GUI control
34#[derive(Debug, Clone, Serialize, Deserialize)]
35pub struct GuiControlResponse {
36    pub success: bool,
37    pub action: GuiAction,
38    pub message: String,
39}
40
41/// Process a GUI control request.
42/// Since the actual UI mutation happens on the frontend when it intercepts
43/// the tool call, the backend's job is simply to validate and return a success message.
44pub async fn execute_gui_control(req: GuiControlRequest) -> Result<GuiControlResponse> {
45    // In the future, we could add validation here.
46    // For now, we just acknowledge receipt.
47    let message = format!("Dispatched UI action '{:?}' successfully.", req.action);
48
49    Ok(GuiControlResponse {
50        success: true,
51        action: req.action,
52        message,
53    })
54}