// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";

package google.cloud.ces.v1;

import "google/api/field_behavior.proto";
import "google/api/resource.proto";
import "google/cloud/ces/v1/toolset_tool.proto";
import "google/protobuf/struct.proto";
import "google/protobuf/timestamp.proto";

option go_package = "cloud.google.com/go/ces/apiv1/cespb;cespb";
option java_multiple_files = true;
option java_outer_classname = "ExampleProto";
option java_package = "com.google.cloud.ces.v1";

// An example represents a sample conversation between the user and the
// agent(s).
message Example {
  option (google.api.resource) = {
    type: "ces.googleapis.com/Example"
    pattern: "projects/{project}/locations/{location}/apps/{app}/examples/{example}"
    plural: "examples"
    singular: "example"
  };

  // Identifier. The unique identifier of the example.
  // Format:
  // `projects/{project}/locations/{location}/apps/{app}/examples/{example}`
  string name = 1 [(google.api.field_behavior) = IDENTIFIER];

  // Required. Display name of the example.
  string display_name = 2 [(google.api.field_behavior) = REQUIRED];

  // Optional. Human-readable description of the example.
  string description = 3 [(google.api.field_behavior) = OPTIONAL];

  // Optional. The agent that initially handles the conversation. If not
  // specified, the example represents a conversation that is handled by the
  // root agent. Format:
  // `projects/{project}/locations/{location}/apps/{app}/agents/{agent}`
  string entry_agent = 4 [
    (google.api.field_behavior) = OPTIONAL,
    (google.api.resource_reference) = { type: "ces.googleapis.com/Agent" }
  ];

  // Optional. The collection of messages that make up the conversation.
  repeated Message messages = 5 [(google.api.field_behavior) = OPTIONAL];

  // Output only. Timestamp when the example was created.
  google.protobuf.Timestamp create_time = 6
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Timestamp when the example was last updated.
  google.protobuf.Timestamp update_time = 7
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The example may become invalid if referencing resources are
  // deleted. Invalid examples will not be used as few-shot examples.
  bool invalid = 8 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Etag used to ensure the object hasn't changed during a read-modify-write
  // operation. If the etag is empty, the update will overwrite any concurrent
  // changes.
  string etag = 9;
}

// A message within a conversation.
message Message {
  // Optional. The role within the conversation, e.g., user, agent.
  string role = 1 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Content of the message as a series of chunks.
  repeated Chunk chunks = 2 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Timestamp when the message was sent or received. Should not be
  // used if the message is part of an [example][google.cloud.ces.v1.Example].
  google.protobuf.Timestamp event_time = 4
      [(google.api.field_behavior) = OPTIONAL];
}

// A chunk of content within a message.
message Chunk {
  // Chunk data.
  oneof data {
    // Optional. Text data.
    string text = 1 [(google.api.field_behavior) = OPTIONAL];

    // Optional. Transcript associated with the audio.
    string transcript = 9 [(google.api.field_behavior) = OPTIONAL];

    // Optional. Blob data.
    Blob blob = 7 [(google.api.field_behavior) = OPTIONAL];

    // Optional. Custom payload data.
    google.protobuf.Struct payload = 11
        [(google.api.field_behavior) = OPTIONAL];

    // Optional. Image data.
    Image image = 5 [(google.api.field_behavior) = OPTIONAL];

    // Optional. Tool execution request.
    ToolCall tool_call = 2 [(google.api.field_behavior) = OPTIONAL];

    // Optional. Tool execution response.
    ToolResponse tool_response = 3 [(google.api.field_behavior) = OPTIONAL];

    // Optional. Agent transfer event.
    AgentTransfer agent_transfer = 4 [(google.api.field_behavior) = OPTIONAL];

    // A struct represents variables that were updated in the conversation,
    // keyed by variable names.
    google.protobuf.Struct updated_variables = 8;

    // A struct represents default variables at the start of the conversation,
    // keyed by variable names.
    google.protobuf.Struct default_variables = 10;
  }
}

// Represents a blob input or output in the conversation.
message Blob {
  // Required. The IANA standard MIME type of the source data.
  string mime_type = 1 [(google.api.field_behavior) = REQUIRED];

  // Required. Raw bytes of the blob.
  bytes data = 2 [(google.api.field_behavior) = REQUIRED];
}

// Represents an image input or output in the conversation.
message Image {
  // Required. The IANA standard MIME type of the source data.
  // Supported image types includes:
  //  * image/png
  //  * image/jpeg
  //  * image/webp
  string mime_type = 1 [(google.api.field_behavior) = REQUIRED];

  // Required. Raw bytes of the image.
  bytes data = 2 [(google.api.field_behavior) = REQUIRED];
}

// Request for the client or the agent to execute the specified tool.
message ToolCall {
  // The identifier of the tool to execute. It could be either a persisted tool
  // or a tool from a toolset.
  oneof tool_identifier {
    // Optional. The name of the tool to execute.
    // Format: `projects/{project}/locations/{location}/apps/{app}/tools/{tool}`
    string tool = 2 [
      (google.api.field_behavior) = OPTIONAL,
      (google.api.resource_reference) = { type: "ces.googleapis.com/Tool" }
    ];

    // Optional. The toolset tool to execute.
    ToolsetTool toolset_tool = 5 [(google.api.field_behavior) = OPTIONAL];
  }

  // Optional. The unique identifier of the tool call. If populated, the client
  // should return the execution result with the matching ID in
  // [ToolResponse][google.cloud.ces.v1.ToolResponse.id].
  string id = 1 [(google.api.field_behavior) = OPTIONAL];

  // Output only. Display name of the tool.
  string display_name = 4 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Optional. The input parameters and values for the tool in JSON object
  // format.
  google.protobuf.Struct args = 3 [(google.api.field_behavior) = OPTIONAL];
}

// The execution result of a specific tool from the client or the agent.
message ToolResponse {
  // The identifier of the tool that got executed. It could be either a
  // persisted tool or a tool from a toolset.
  oneof tool_identifier {
    // Optional. The name of the tool to execute.
    // Format: `projects/{project}/locations/{location}/apps/{app}/tools/{tool}`
    string tool = 2 [
      (google.api.field_behavior) = OPTIONAL,
      (google.api.resource_reference) = { type: "ces.googleapis.com/Tool" }
    ];

    // Optional. The toolset tool that got executed.
    ToolsetTool toolset_tool = 5 [(google.api.field_behavior) = OPTIONAL];
  }

  // Optional. The matching ID of the [tool call][google.cloud.ces.v1.ToolCall]
  // the response is for.
  string id = 1 [(google.api.field_behavior) = OPTIONAL];

  // Output only. Display name of the tool.
  string display_name = 4 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Required. The tool execution result in JSON object format.
  // Use "output" key to specify tool response and "error" key to specify
  // error details (if any). If "output" and "error" keys are not specified,
  // then whole "response" is treated as tool execution result.
  google.protobuf.Struct response = 3 [(google.api.field_behavior) = REQUIRED];
}

// Represents an event indicating the transfer of a conversation to a different
// agent.
message AgentTransfer {
  // Required. The agent to which the conversation is being transferred. The
  // agent will handle the conversation from this point forward. Format:
  // `projects/{project}/locations/{location}/apps/{app}/agents/{agent}`
  string target_agent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = { type: "ces.googleapis.com/Agent" }
  ];

  // Output only. Display name of the agent.
  string display_name = 2 [(google.api.field_behavior) = OUTPUT_ONLY];
}
