// Copyright 2026 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

syntax = "proto2";

option java_multiple_files = true;
option java_package = "org.chromium.components.sharing_message.proto";

package components_sharing_message;

option optimize_for = LITE_RUNTIME;

// Payload for initiating and managing an experimental triggering approach.
message GlicExperimentalTriggering {
  // Contains identifiers and synchronization metadata for the actuation task.
  message TaskMetadata {
    // Unique identifier for the conversation the task is a part of.
    // Expected to only be populated by the client.
    optional string conversation_id = 1;

    // Unique identifier for the specific actuation task.
    // Expected to only be populated by the client.
    optional string task_id = 2;

    // Monotonically increasing sequence number to ensure we can sort messages.
    // Since messages can arrive out of order, the sequence number enables an
    // ordered reconstruction of the stream.
    // Expected to be populated by client & server.
    optional int64 sender_sequence_number = 3;

    // For this message, this was the last previously seen sequence number.
    // Expected to be populated by client & server.
    optional int64 last_seen_sequence_number = 4;

    // Information about the parent conversation that started this task.
    // Expected to only be populated by the server.
    message ParentConversationMetadata {
      optional string conversation_id = 1;
      optional string conversation_title = 2;
    }
    optional ParentConversationMetadata parent_conversation_metadata = 5;
  }
  // If the task is already running, this contains the metadata about it.
  optional TaskMetadata task_metadata = 1;

  message ExperimentalTriggeringRequest {
    message TriggerActuationRequest {
      // The actual prompt that should be triggered.
      optional string initial_prompt = 1;
    }

    message ContinueActuationRequest {
      // The prompt to be sent to server to continue the actuation.
      optional string continuation_prompt = 1;
    }

    message StopActuationRequest {
      // The reason for stopping. This may be surfaced to the user, so it should
      // be human readable.
      optional string stop_reason = 1;
    }

    message DeviceOptInRequest {
      // The source of the triggering request.
      optional string triggering_source = 1;
    }

    message GetScreenshotRequest {
      // Ephemeral public key.
      optional bytes public_key = 1;

      // Ephemeral auth secret.
      optional bytes auth_secret = 2;

      // Opaque identifier to correlate this request with its response.
      optional bytes request_token = 3;
    }

    oneof payload {
      TriggerActuationRequest trigger_actuation_request = 1;
      StopActuationRequest stop_actuation_request = 2;
      DeviceOptInRequest device_opt_in_request = 3;
      GetScreenshotRequest get_screenshot_request = 4;
      ContinueActuationRequest continue_actuation_request = 5;
    }
  }

  message ExperimentalTriggeringResponse {
    // Represents a lifecycle and/or data update.
    message TaskUpdate {
      // Represents the overall lifecycle state of the actuation task.
      enum State {
        UNKNOWN_STATE = 0;
        STARTING = 1;  // Sent immediately upon TriggerActuationRequest.
        RUNNING = 2;   // Actively generating or thinking.
        PAUSED = 3;    // User took over task.
        YIELD = 4;     // Waiting on user input.
        STOPPED = 5;   // Task Ended: Halted by user or system.
        COMPLETE = 6;  // Task Ended: Finished successfully.
        FAILED = 7;    // Task Ended: Terminated due to model error or failure.
        RESUMED = 8;   // Task resumed after pause or yield.
      }

      // Defines the type of string payload being sent in the `data` field.
      enum DataType {
        UNKNOWN_DATA_TYPE = 0;
        WORKLOG = 1;           // Internal steps.
        PARTIAL_RESPONSE = 2;  // Streaming chunk of text.
        FINAL_RESPONSE = 3;    // The completed response text.
        ERROR_MESSAGE = 4;     // Error string.
      }

      // The macro state of the task.
      optional State state = 1;

      // The micro type of the payload.
      optional DataType data_type = 3;

      // The actual text content. Context depends on `data_type`.
      optional string data = 4;

      // Optional metadata, based on `state` and `data_type`.
      map<string, string> metadata = 5;
    }

    // The result of the device opt-in request.
    enum DeviceOptInResult {
      UNKNOWN = 0;
      DECLINED = 1;
      ACCEPTED = 2;
      FAILED = 3;
    }

    message ScreenshotResult {
      enum Status {
        // Default value.
        UNSPECIFIED = 0;
        // Capture successful.
        SUCCESS = 1;
        // Capture failure.
        ERROR_CAPTURE = 2;
        // Transient failure.
        ERROR_SERVER = 3;
        // Feature is disabled.
        ERROR_DISABLED = 4;
        // Malformed or invalid request parameters.
        ERROR_INVALID_REQUEST = 5;
      }

      // The status of the screenshot capture operation.
      optional Status status = 1;
      // A screenshot file identifier.
      optional string file_token = 2;
      // Detailed error message.
      optional string error_message = 3;
      // Opaque identifier to correlate this response with its request.
      optional bytes request_token = 4;
    }

    oneof payload {
      TaskUpdate task_update = 3;
      DeviceOptInResult device_opt_in_result = 4;
      ScreenshotResult screenshot_result = 5;
    }
  }

  // Empty message that signifies that the TaskMetadata field has been updated
  // (e.g. new parent conversation information).
  message TaskMetadataUpdated {}

  oneof payload {
    ExperimentalTriggeringRequest request = 2;
    ExperimentalTriggeringResponse response = 3;
    TaskMetadataUpdated task_metadata_updated = 5;
  }

  // An identifier to support actuation requests for the same glic instance.
  optional string context_id = 4;

  // Monotonically increasing version number of the triggering protocol.
  optional int32 glic_experimental_triggering_version = 6;
}
