syntax = "proto3";

package brunix;

service AssistanceEngine {
  // Respuesta completa — compatible con clientes existentes
  rpc AskAgent       (AgentRequest) returns (stream AgentResponse);

  // Streaming real token a token desde Ollama
  rpc AskAgentStream (AgentRequest) returns (stream AgentResponse);

  // Evaluación RAGAS con Claude como juez
  rpc EvaluateRAG    (EvalRequest)  returns (EvalResponse);
}

// ---------------------------------------------------------------------------
// AskAgent / AskAgentStream — mismos mensajes, dos comportamientos
// ---------------------------------------------------------------------------

message AgentRequest {
  // ── Core fields (v1) ──────────────────────────────────────────────────────
  string query      = 1;
  string session_id = 2;

  // ── Editor context fields (v2 — PRD-0002) ────────────────────────────────
  // All three fields are optional. Clients that do not send them default to
  // empty string. Existing clients remain fully compatible without changes.

  // Full content of the active file open in the editor at query time.
  // Gives the assistant awareness of the complete code the user is working on.
  string editor_content = 3;

  // Text currently selected in the editor, if any.
  // Most precise signal of user intent — if non-empty, the question almost
  // certainly refers to this specific code block.
  string selected_text  = 4;

  // Free-form additional context (e.g. file path, language identifier,
  // open diagnostic errors). Extensible without requiring future proto changes.
  string extra_context  = 5;

  string user_info = 6;

  // ── Caller-declared type (v3 — ADR-0008 Phase 3) ─────────────────────────
  // Optional. When set by the caller, all three classifier layers are bypassed
  // and the engine routes directly using this value.
  // Valid values: RETRIEVAL | CODE_GENERATION | CONVERSATIONAL | PLATFORM
  // Empty string (default) means: run the normal L1 → L2 → L3 pipeline.
  string query_type = 7;
}

message AgentResponse {
  string text              = 1;
  string avap_code         = 2;
  bool   is_final          = 3;
  string validation_status = 4;  // "" | "INVALID_UNRESOLVED" | "PARSER_UNAVAILABLE"
}

// ---------------------------------------------------------------------------
// EvaluateRAG
// ---------------------------------------------------------------------------

message EvalRequest {
  string category = 1;
  int32  limit    = 2;
  string index    = 3;
}

message EvalResponse {
  string status               = 1;
  int32  questions_evaluated  = 2;
  float  elapsed_seconds      = 3;
  string judge_model          = 4;
  string index                = 5;
  float  faithfulness         = 6;
  float  answer_relevancy     = 7;
  float  context_recall       = 8;
  float  context_precision    = 9;
  float  global_score         = 10;
  string verdict              = 11;
  repeated QuestionDetail details = 12;
}

message QuestionDetail {
  string id             = 1;
  string category       = 2;
  string question       = 3;
  string answer_preview = 4;
  int32  n_chunks       = 5;
}
