syntax = "proto3";

package browser;

service BrowserService {
  rpc Navigate(NavigateRequest) returns (BrowserResponse);
  rpc Click(ClickRequest) returns (BrowserResponse);
  rpc Type(TypeRequest) returns (BrowserResponse);
  rpc Hover(HoverRequest) returns (BrowserResponse);
  rpc Scroll(ScrollRequest) returns (BrowserResponse);
  rpc Evaluate(EvalRequest) returns (BrowserResponse);
  rpc GetSnapshot(SnapshotRequest) returns (BrowserResponse);
  rpc CloseSession(CloseRequest) returns (CloseResponse);
  rpc ParallelFetch(ParallelFetchRequest) returns (stream ParallelFetchResponse);
}

message NavigateRequest {
  string url = 1;
  string session_id = 2;
  bool wait_until_idle = 3;
}

message ClickRequest {
  string selector = 1;
  string session_id = 2;
  int32 x = 3;
  int32 y = 4;
}

message TypeRequest {
  string selector = 1;
  string text = 2;
  string session_id = 3;
  bool press_enter = 4;
}

message HoverRequest {
  string selector = 1;
  string session_id = 2;
}

message ScrollRequest {
  string session_id = 1;
  int32 delta_x = 2;
  int32 delta_y = 3;
  string selector = 4;
}

message EvalRequest {
  string script = 1;
  string session_id = 2;
}

message SnapshotRequest {
  string session_id = 1;
  bool include_screenshot = 2;
  bool include_dom = 3;
  bool include_a11y = 4;
}

message CloseRequest {
  string session_id = 1;
}

message CloseResponse {
  bool success = 1;
}

message ParallelFetchRequest {
  repeated string urls = 1;
  string session_id = 2;
  int32 max_concurrent = 3;
  bool extract_markdown = 4;
}

message ParallelFetchResponse {
  message FetchResult {
    string url = 1;
    string title = 2;
    string content_markdown = 3;
    bool success = 4;
    string error = 5;
    // Indicates whether the result was obtained from a fast static fetch or from a JS-rendered browser fetch.
    string fetch_mode = 6;
  }
  repeated FetchResult results = 1;
}

message BrowserResponse {
  string session_id = 1;
  string url = 2;
  string title = 3;
  string status = 4; // "success", "error", "timeout"
  string error_message = 5;
  
  // Large data returned as file path references (Sidecar handoff via /dev/shm)
  string dom_path = 6;
  string screenshot_path = 7;
  string a11y_path = 8;
  
  // Small data returned inline
  string eval_result = 9;
}
