[hmu] add Elucidate to mahi provider

Add `Elucidate` function to mahi provider, and corresponding metrics to
histogram xmls.

Bug: b:372741602
Test: CQs
Change-Id: Iea900cf5a245667fe197cc341b2ff92efdd1f03c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5925298
Reviewed-by: Thanh Nguyen <thanhdng@chromium.org>
Reviewed-by: Tony Yeoman <tby@chromium.org>
Commit-Queue: Xinglong Luan <alanlxl@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1368089}
diff --git a/components/manta/mahi_provider.cc b/components/manta/mahi_provider.cc
index 4ce11f29..38c1dfa 100644
--- a/components/manta/mahi_provider.cc
+++ b/components/manta/mahi_provider.cc
@@ -84,7 +84,8 @@
 enum class MahiFeature {
   kSummary = 0,
   kQA = 1,
-  kMaxValue = kQA,
+  kElucidation = 2,
+  kMaxValue = kElucidation,
 };
 
 void OnServerResponseOrErrorReceived(
@@ -171,6 +172,45 @@
   base::UmaHistogramEnumeration(kUsedHistogram, MahiFeature::kSummary);
 }
 
+void MahiProvider::Elucidate(const std::string& input,
+                             const std::string& context,
+                             const std::string& title,
+                             const std::optional<std::string>& url,
+                             MantaGenericCallback done_callback) {
+  proto::Request request;
+  request.set_feature_name(proto::FeatureName::CHROMEOS_READER_ELUCIDATION);
+
+  auto* input_data = request.add_input_data();
+  input_data->set_tag("model_input");
+  input_data->set_text(input);
+
+  input_data = request.add_input_data();
+  input_data->set_tag("context");
+  input_data->set_text(context);
+
+  if (!title.empty()) {
+    input_data = request.add_input_data();
+    input_data->set_tag("title");
+    input_data->set_text(title);
+  }
+
+  if (url.has_value() && !url->empty()) {
+    input_data = request.add_input_data();
+    input_data->set_tag("url");
+    input_data->set_text(url.value());
+  }
+
+  RequestInternal(
+      GURL{GetProviderEndpoint(features::IsMahiUseProdServerEnabled())},
+      kOauthConsumerName, kMahiTrafficAnnotationTag, request,
+      MantaMetricType::kMahiElucidation,
+      base::BindOnce(&OnServerResponseOrErrorReceived,
+                     std::move(done_callback)),
+      kTimeout);
+
+  base::UmaHistogramEnumeration(kUsedHistogram, MahiFeature::kElucidation);
+}
+
 void MahiProvider::Outline(const std::string& input,
                            const std::string& title,
                            const std::optional<std::string>& url,
diff --git a/components/manta/mahi_provider.h b/components/manta/mahi_provider.h
index 3b164098..7f1c78c5 100644
--- a/components/manta/mahi_provider.h
+++ b/components/manta/mahi_provider.h
@@ -53,6 +53,17 @@
                          const std::optional<std::string>& url,
                          MantaGenericCallback done_callback);
 
+  // Similar to `Summarize` but elucidates / simplifies the `input`, making it
+  // easy to unserstand. The `input` is usually a piece of user selected text
+  // while the `context` is the full document where `input` is selected from, to
+  // help the service better understand the context and give more accurate
+  // output.
+  virtual void Elucidate(const std::string& input,
+                         const std::string& context,
+                         const std::string& title,
+                         const std::optional<std::string>& url,
+                         MantaGenericCallback done_callback);
+
   // Similar to `Summarize` but outlines the `input`.
   void Outline(const std::string& input,
                const std::string& title,
diff --git a/components/manta/manta_service_callbacks.cc b/components/manta/manta_service_callbacks.cc
index 619fcc4..17c4d8ec 100644
--- a/components/manta/manta_service_callbacks.cc
+++ b/components/manta/manta_service_callbacks.cc
@@ -80,6 +80,10 @@
       base::UmaHistogramTimes("Ash.MantaService.MahiProvider.Summary.TimeCost",
                               time_cost);
       break;
+    case MantaMetricType::kMahiElucidation:
+      base::UmaHistogramTimes(
+          "Ash.MantaService.MahiProvider.Elucidation.TimeCost", time_cost);
+      break;
     case MantaMetricType::kMahiQA:
       base::UmaHistogramTimes("Ash.MantaService.MahiProvider.QA.TimeCost",
                               time_cost);
@@ -118,6 +122,10 @@
       base::UmaHistogramEnumeration(
           "Ash.MantaService.MahiProvider.Summary.StatusCode", status_code);
       break;
+    case MantaMetricType::kMahiElucidation:
+      base::UmaHistogramEnumeration(
+          "Ash.MantaService.MahiProvider.Elucidation.StatusCode", status_code);
+      break;
     case MantaMetricType::kMahiQA:
       base::UmaHistogramEnumeration(
           "Ash.MantaService.MahiProvider.QA.StatusCode", status_code);
diff --git a/components/manta/manta_service_callbacks.h b/components/manta/manta_service_callbacks.h
index 3a2f6d9..9cbdc94 100644
--- a/components/manta/manta_service_callbacks.h
+++ b/components/manta/manta_service_callbacks.h
@@ -27,6 +27,7 @@
   kScanner,
   kSnapper,
   kMahiSummary,
+  kMahiElucidation,
   kMahiQA,
   kSparky,
   kWalrus,
diff --git a/components/manta/proto/manta.proto b/components/manta/proto/manta.proto
index ad59963..a697dde 100644
--- a/components/manta/proto/manta.proto
+++ b/components/manta/proto/manta.proto
@@ -22,6 +22,7 @@
   CHROMEOS_SPARKY = 314;
   CHROMEOS_LOBSTER = 315;
   CHROMEOS_SCANNER = 316;
+  CHROMEOS_READER_ELUCIDATION = 317;
   CHROMEOS_WALRUS = 318;
   reserved 304 to 311;
 
diff --git a/tools/metrics/histograms/metadata/ash/histograms.xml b/tools/metrics/histograms/metadata/ash/histograms.xml
index 6f50c176..972780f 100644
--- a/tools/metrics/histograms/metadata/ash/histograms.xml
+++ b/tools/metrics/histograms/metadata/ash/histograms.xml
@@ -266,6 +266,8 @@
 
 <variants name="MantaMetricType">
   <variant name="AnchovyProvider" summary="Request from Anchovy provider"/>
+  <variant name="MahiProvider.Elucidation"
+      summary="Request from Mahi provider for elucidation"/>
   <variant name="MahiProvider.Outline"
       summary="Request from Mahi provider for outline"/>
   <variant name="MahiProvider.QA" summary="Request from Mahi provider for QA"/>
diff --git a/tools/metrics/histograms/metadata/chromeos/enums.xml b/tools/metrics/histograms/metadata/chromeos/enums.xml
index 23169fae..fa29ab41 100644
--- a/tools/metrics/histograms/metadata/chromeos/enums.xml
+++ b/tools/metrics/histograms/metadata/chromeos/enums.xml
@@ -1418,6 +1418,7 @@
 <enum name="MahiFeature">
   <int value="0" label="Summary"/>
   <int value="1" label="QA"/>
+  <int value="2" label="Elucidation"/>
 </enum>
 
 <enum name="MahiMenuButton">