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

edition = "2023";

package optimization_guide.proto;

option optimize_for = LITE_RUNTIME;
option java_package = "org.chromium.components.optimization_guide.features.proto";

option java_outer_classname = "ContextualTasksContextProto";

// DO NOT EDIT THIS FILE DIRECTLY!
//
// This file is generated in g3 and then synced to Chrome. Instead, please refer to
// http://go/chrome-mqls-onboarding (Google-internal link), and then changes will
// be synced with Chrome automatically.

message ContextualTasksContextLoggingData {
  ContextualTasksContextQuality quality = 1 [features = { field_presence: EXPLICIT }];
}

message ContextualTasksContextQuality {
  // The eligible tabs for tab selection.
  //
  // Note that any tabs that are deemed ineligible (i.e. server upload
  // eligibility or sensitivity) will not be included in this list.
  repeated ContextualTasksTabContext eligible_tabs = 1;

  // The surface the query was made on.
  ContextualTasksSurface surface = 2 [features = { field_presence: EXPLICIT }];

  // The version of the model generating the query embedding.
  int64 embedding_model_version = 3 [features = { field_presence: EXPLICIT }];

  // Number of words in the query.
  int32 number_of_query_words = 4 [features = { field_presence: EXPLICIT }];

  // The mode of tab selection. `aggregate_tab_score` is set based on the mode.
  TabSelectionMode tab_selection_mode = 5 [features = { field_presence: EXPLICIT }];

  // Cosine similarity between the query embedding and the active tab title
  // embedding.
  float query_active_tab_title_similarity = 6 [features = { field_presence: EXPLICIT }];

  // Cosine similarity scores between the query embedding and embeddings of
  // up to N (currently 10) passages from the active tab.
  repeated float query_active_tab_passage_similarities = 7;

  // The version of the model tab relevance tflite model.
  int64 tab_selection_model_version = 8 [features = { field_presence: EXPLICIT }];
}

// Next ID: 10
message ContextualTasksTabContext {
  // The highest query-passage embedding score for the tab.
  // Note that, the fields 7, 8 have been added later to store all the
  // embeddings match scores.
  float best_embedding_score = 1 [
    deprecated = true,
    features = { field_presence: EXPLICIT }
  ];

  // The number of seconds since the tab was last active.
  int64 seconds_since_last_active = 2 [features = { field_presence: EXPLICIT }];

  // The number of non-stop words that are common between query and tab title.
  int64 number_of_common_words = 3 [features = { field_presence: EXPLICIT }];

  // Aggregate score for the tab. Here for convenience even though it can be
  // calculated from the tab.
  float aggregate_tab_score = 4 [features = { field_presence: EXPLICIT }];

  // The number of seconds spent on the tab while it was last being active (i.e
  // while it was in the foreground).
  int64 seconds_of_last_visit = 6 [features = { field_presence: EXPLICIT }];

  // Cosine similarity between the query embedding and the candidate tab title
  // embedding.
  float query_title_similarity = 7 [features = { field_presence: EXPLICIT }];

  // Cosine similarity scores between the query embedding and embeddings of
  // up to N (currently 10) passages from the candidate tab.
  repeated float query_passage_similarities = 8;

  // Cosine similarity between the active tab's title and this candidate tab's
  // title.
  float active_tab_title_similarity = 9 [features = { field_presence: EXPLICIT }];

  // ////////////////////////////////////////////////////////////////////////////
  // Fields below are some sort of label groundtruth.
  // ////////////////////////////////////////////////////////////////////////////

  // Whether the tab was explicitly added to the query by the user.
  bool was_explicitly_chosen = 5 [features = { field_presence: EXPLICIT }];
}

enum ContextualTasksSurface {
  CONTEXTUAL_TASK_SURFACE_UNKNOWN = 0;

  CONTEXTUAL_TASK_SURFACE_NEW_TAB_PAGE = 1;

  CONTEXTUAL_TASK_SURFACE_OMNIBOX = 2;

  CONTEXTUAL_TASK_SURFACE_CONTEXTUAL_TASKS_UI = 3;
}

// The mode of tab selection. `aggregate_tab_score` is set based on the mode.
enum TabSelectionMode {
  TAB_SELECTION_MODE_UNKNOWN = 0;

  TAB_SELECTION_MODE_STATIC_SIGNALS = 1;

  TAB_SELECTION_MODE_STATIC_AND_ENGAGEMENT_SIGNALS = 2;

  TAB_SELECTION_MODE_STATIC_ML_MODEL = 3;

  TAB_SELECTION_MODE_STATIC_ML_MODEL_AND_ENGAGEMENT_SIGNALS = 4;
}
