// Copyright 2026 Codex Launcher Contributors
// SPDX-License-Identifier: MIT
//
// CloudCode internal gRPC service definitions.
// Reverse-engineered from the agy-core binary for Antigravity proxy fallback.
// Service: google.internal.cloud.code.v1internal.PredictionService
//
// NOTE: google/api/annotations.proto is NOT imported here because it conflicts
// with the google namespace package at runtime. The HTTP annotations are only
// needed for Google's Envoy/gRPC-gateway and are unnecessary for our client.

syntax = "proto3";

package google.internal.cloud.code.v1internal;

import "google/protobuf/struct.proto";

option go_package = "google.golang.org/internal/cloud/code/v1internal";

// ─── Reused message types ───────────────────────────────────────────

message Content {
  string role = 1;
  repeated Part parts = 2;
}

message Part {
  oneof data {
    string text = 1;
    InlineData inline_data = 2;
    FunctionCall function_call = 3;
    FunctionResponse function_response = 4;
  }
  // Thought signature for Gemini continuity
  string thought_signature = 10;
  // Thought part (reasoning)
  bool thought = 11;
}

message InlineData {
  string mime_type = 1;
  bytes data = 2;
}

message FunctionCall {
  string name = 1;
  google.protobuf.Struct args = 2;
  string id = 3;
}

message FunctionResponse {
  string name = 1;
  google.protobuf.Struct response = 2;
  string id = 3;
}

message SafetySetting {
  string category = 1;
  string threshold = 2;
}

message GenerationConfig {
  int32 max_output_tokens = 1;
  float temperature = 2;
  float top_p = 3;
  int32 thinking_budget = 4;
  bool include_thoughts = 5;
  repeated string stop_sequences = 6;
  message ThinkingConfig {
    bool include_thoughts = 1;
    int32 thinking_budget = 2;
  }
  ThinkingConfig thinking_config = 7;
}

message Tool {
  repeated FunctionDeclaration function_declarations = 1;
}

message FunctionDeclaration {
  string name = 1;
  string description = 2;
  google.protobuf.Struct parameters = 3;
}

message ToolConfig {
  message FunctionCallingConfig {
    string mode = 1;  // "AUTO", "ANY", "NONE", "VALIDATED"
    repeated string allowed_function_names = 2;
  }
  FunctionCallingConfig function_calling_config = 1;
}

message Candidate {
  Content content = 1;
  string finish_reason = 2;
  int32 index = 3;
}

// ─── GenerateContent ─────────────────────────────────────────────────

message GenerateContentRequest {
  string project = 1;
  string model = 2;
  string request_type = 3;
  string user_agent = 4;
  string request_id = 5;

  message InnerRequest {
    repeated Content contents = 1;
    Content system_instruction = 2;
    GenerationConfig generation_config = 3;
    repeated Tool tools = 4;
    repeated SafetySetting safety_settings = 5;
    ToolConfig tool_config = 6;
    string session_id = 7;
  }

  InnerRequest request = 10;
}

message GenerateContentResponse {
  message Response {
    repeated Candidate candidates = 1;
  }
  Response response = 1;
}

// ─── StreamGenerateContent ────────────────────────────────────────────

message StreamGenerateContentChunk {
  GenerateContentResponse.Response response = 1;
}

// ─── FetchAvailableModels ────────────────────────────────────────────

message FetchAvailableModelsRequest {
  string project = 1;
}

message FetchAvailableModelsResponse {
  message ModelInfo {
    string name = 1;
    string display_name = 2;
    string description = 3;
    int64 context_window = 4;
  }
  repeated ModelInfo models = 1;
}

// ─── CountTokens ──────────────────────────────────────────────────────

message CountTokensRequest {
  string project = 1;
  string model = 2;
  repeated Content contents = 3;
}

message CountTokensResponse {
  int32 total_tokens = 1;
}

// ─── RetrieveUserQuota ───────────────────────────────────────────────

message RetrieveUserQuotaRequest {
  string project = 1;
}

message RetrieveUserQuotaResponse {
  int64 daily_limit = 1;
  int64 daily_usage = 2;
  int64 daily_remaining = 3;
}

// ─── Service ──────────────────────────────────────────────────────────

service PredictionService {
  rpc GenerateContent(GenerateContentRequest) returns (GenerateContentResponse);
  rpc StreamGenerateContent(GenerateContentRequest) returns (stream StreamGenerateContentChunk);
  rpc FetchAvailableModels(FetchAvailableModelsRequest) returns (FetchAvailableModelsResponse);
  rpc CountTokens(CountTokensRequest) returns (CountTokensResponse);
  rpc RetrieveUserQuota(RetrieveUserQuotaRequest) returns (RetrieveUserQuotaResponse);
}
