// 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.aiplatform.v1;

import "google/api/field_behavior.proto";
import "google/api/resource.proto";
import "google/cloud/aiplatform/v1/content.proto";
import "google/protobuf/duration.proto";
import "google/protobuf/struct.proto";
import "google/protobuf/timestamp.proto";

option csharp_namespace = "Google.Cloud.AIPlatform.V1";
option go_package = "cloud.google.com/go/aiplatform/apiv1/aiplatformpb;aiplatformpb";
option java_multiple_files = true;
option java_outer_classname = "SessionProto";
option java_package = "com.google.cloud.aiplatform.v1";
option php_namespace = "Google\\Cloud\\AIPlatform\\V1";
option ruby_package = "Google::Cloud::AIPlatform::V1";

// A session contains a set of actions between users and Vertex agents.
message Session {
  option (google.api.resource) = {
    type: "aiplatform.googleapis.com/Session"
    pattern: "projects/{project}/locations/{location}/reasoningEngines/{reasoning_engine}/sessions/{session}"
    plural: "sessions"
    singular: "session"
  };

  // The expiration of the session.
  oneof expiration {
    // Optional. Timestamp of when this session is considered expired.
    // This is *always* provided on output, regardless of what was sent
    // on input.
    // The minimum value is 24 hours from the time of creation.
    google.protobuf.Timestamp expire_time = 13
        [(google.api.field_behavior) = OPTIONAL];

    // Optional. Input only. The TTL for this session.
    // The minimum value is 24 hours.
    google.protobuf.Duration ttl = 14 [
      (google.api.field_behavior) = OPTIONAL,
      (google.api.field_behavior) = INPUT_ONLY
    ];
  }

  // Identifier. The resource name of the session.
  // Format:
  // 'projects/{project}/locations/{location}/reasoningEngines/{reasoning_engine}/sessions/{session}'.
  string name = 1 [(google.api.field_behavior) = IDENTIFIER];

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

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

  // Optional. The display name of the session.
  string display_name = 5 [(google.api.field_behavior) = OPTIONAL];

  // The labels with user-defined metadata to organize your Sessions.
  //
  // Label keys and values can be no longer than 64 characters
  // (Unicode codepoints), can only contain lowercase letters, numeric
  // characters, underscores and dashes. International characters are allowed.
  //
  // See https://goo.gl/xmQnxf for more information and examples of labels.
  map<string, string> labels = 8;

  // Optional. Session specific memory which stores key conversation points.
  google.protobuf.Struct session_state = 10
      [(google.api.field_behavior) = OPTIONAL];

  // Required. Immutable. String id provided by the user
  string user_id = 12 [
    (google.api.field_behavior) = IMMUTABLE,
    (google.api.field_behavior) = REQUIRED
  ];
}

// An event represents a message from either the user or agent.
message SessionEvent {
  option (google.api.resource) = {
    type: "aiplatform.googleapis.com/SessionEvent"
    pattern: "projects/{project}/locations/{location}/reasoningEngines/{reasoning_engine}/sessions/{session}/events/{event}"
    plural: "sessionEvents"
    singular: "sessionEvent"
  };

  // Identifier. The resource name of the event.
  // Format:`projects/{project}/locations/{location}/reasoningEngines/{reasoning_engine}/sessions/{session}/events/{event}`.
  string name = 1 [(google.api.field_behavior) = IDENTIFIER];

  // Required. The name of the agent that sent the event, or user.
  string author = 3 [(google.api.field_behavior) = REQUIRED];

  // Optional. Content of the event provided by the author.
  Content content = 4 [(google.api.field_behavior) = OPTIONAL];

  // Required. The invocation id of the event, multiple events can have the same
  // invocation id.
  string invocation_id = 5 [(google.api.field_behavior) = REQUIRED];

  // Optional. Actions executed by the agent.
  EventActions actions = 6 [(google.api.field_behavior) = OPTIONAL];

  // Required. Timestamp when the event was created on client side.
  google.protobuf.Timestamp timestamp = 8
      [(google.api.field_behavior) = REQUIRED];

  // Optional. Error code if the response is an error. Code varies by model.
  string error_code = 9 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Error message if the response is an error.
  string error_message = 10 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Metadata relating to this event.
  EventMetadata event_metadata = 11 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Weakly typed raw event data in proto struct format.
  google.protobuf.Struct raw_event = 12
      [(google.api.field_behavior) = OPTIONAL];
}

// Metadata relating to a LLM response event.
message EventMetadata {
  // Optional. Metadata returned to client when grounding is enabled.
  GroundingMetadata grounding_metadata = 1
      [(google.api.field_behavior) = OPTIONAL];

  // Optional. Indicates whether the text content is part of a unfinished text
  // stream. Only used for streaming mode and when the content is plain text.
  bool partial = 2 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Indicates whether the response from the model is complete.
  // Only used for streaming mode.
  bool turn_complete = 3 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Flag indicating that LLM was interrupted when generating the
  // content. Usually it's due to user interruption during a bidi streaming.
  bool interrupted = 4 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Set of ids of the long running function calls.
  // Agent client will know from this field about which function call is long
  // running. Only valid for function call event.
  repeated string long_running_tool_ids = 5
      [(google.api.field_behavior) = OPTIONAL];

  // Optional. The branch of the event.
  // The format is like agent_1.agent_2.agent_3, where agent_1 is the parent of
  // agent_2, and agent_2 is the parent of agent_3.
  // Branch is used when multiple child agents shouldn't see their siblings'
  // conversation history.
  string branch = 6 [(google.api.field_behavior) = OPTIONAL];

  // The custom metadata of the LlmResponse.
  google.protobuf.Struct custom_metadata = 7;

  // Optional. Audio transcription of user input.
  Transcription input_transcription = 10
      [(google.api.field_behavior) = OPTIONAL];

  // Optional. Audio transcription of model output.
  Transcription output_transcription = 11
      [(google.api.field_behavior) = OPTIONAL];
}

// Actions are parts of events that are executed by the agent.
message EventActions {
  // Optional. If true, it won't call model to summarize function response.
  // Only used for function_response event.
  bool skip_summarization = 1 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Indicates that the event is updating the state with the given
  // delta.
  google.protobuf.Struct state_delta = 2
      [(google.api.field_behavior) = OPTIONAL];

  // Optional. Indicates that the event is updating an artifact. key is the
  // filename, value is the version.
  map<string, int32> artifact_delta = 3
      [(google.api.field_behavior) = OPTIONAL];

  // Optional. The agent is escalating to a higher level agent.
  bool escalate = 6 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Will only be set by a tool response indicating tool request euc.
  // Struct key is the function call id since one function call response (from
  // model) could correspond to multiple function calls. Struct value is the
  // required auth config, which can be another struct.
  google.protobuf.Struct requested_auth_configs = 7
      [(google.api.field_behavior) = OPTIONAL];

  // Optional. If set, the event transfers to the specified agent.
  string transfer_agent = 8 [(google.api.field_behavior) = OPTIONAL];
}

// Audio transcription in Server Content.
message Transcription {
  // Optional. Transcription text.
  string text = 1 [(google.api.field_behavior) = OPTIONAL];

  // Optional. The bool indicates the end of the transcription.
  bool finished = 2 [(google.api.field_behavior) = OPTIONAL];
}
