imbajin commented on code in PR #505:
URL: https://github.com/apache/hugegraph-doc/pull/505#discussion_r4163908899


##########
i18n/en.yaml:
##########
@@ -20,7 +20,8 @@ download_component_computer: Computer
 download_component_commons: Common
 download_asf_note: Source archives are the official Apache Software Foundation 
releases; binary packages are convenience builds made from them. All files are 
served from ASF mirrors, with signatures and checksums hosted on 
downloads.apache.org. Source archives generated automatically by GitHub are not 
ASF releases.
 
-ui_ai_consent_description: "Continuing loads Kapa, a third-party service. Your 
question will be sent to Kapa to generate an answer."
-ui_ai_consent_continue: "Continue to Ask AI"
-ui_ai_consent_cancel: "Cancel"
+ui_ai_consent_description: "Agree to load Kapa and use AI to answer your 
questions based on the documentation."

Review Comment:
   Fixed in 784a42151. Both locale disclosures now explicitly say questions are 
sent to the third-party Kapa service before agreement, while keeping the notice 
concise.



##########
assets/js/kapa-adapter.js:
##########
@@ -319,18 +366,20 @@
         }
       });
       consent.querySelector('[data-hg-ai-continue]').addEventListener('click', 
function () {
-        if (!pending) return;
-        var request = pending;
+        if (consented || state === 'loading') return;
+        var request = pending || { query: '', submit: false };
+        if (!pending) lastTrigger = launcher;
         pending = null;
         consented = true;
-        consent.close();
+        try {
+          windowObject.localStorage.setItem(consentKey, 'granted');

Review Comment:
   Fixed in 784a42151. An accessible footer control appears only after 
agreement. Withdrawal clears the website grant and reloads all open tabs to 
unload Kapa; page-only consent also works when storage is blocked. Failed 
removal of a persisted grant explicitly reports that consent remains active. 
Unit and browser regressions cover these cases.



##########
assets/js/kapa-adapter.js:
##########
@@ -104,14 +116,46 @@
       'data-exit-feedback-enabled': 'false',
       'data-user-satisfaction-feedback-enabled': 'false',
       'data-bot-protection-mechanism': 'hcaptcha',
+      'data-example-questions': (config.exampleQuestions || []).join(','),
+      'data-example-questions-col-span': '12',
+      'data-answer-cta-button-enabled': 'true',
+      'data-answer-cta-button-text': config.labels.community,
+      'data-answer-cta-button-link': config.communityURL,
+      'data-answer-cta-button-background-color': 'transparent',
+      'data-answer-cta-button-border': 'none',
+      'data-answer-cta-button-font-weight': '400',
+      'data-answer-cta-button-font-size': '.8rem',
     };
   }
 
   function createController(windowObject, documentObject, config) {
     var state = 'idle';
+    var widgetConfig = Object.assign({}, config, {
+      exampleQuestions: pickExampleQuestions(config.exampleQuestions),
+    });
+    var consentKey = 'hg-ai-consent:v2:' + config.websiteId;
     var consented = false;
+    try {
+      consented = windowObject.localStorage.getItem(consentKey) === 'granted';
+    } catch (_) {
+      // Storage may be disabled; consent still works for this page only.
+    }
     var pending = null;
     var consent = documentObject.querySelector('[data-hg-ai-consent]');
+    var launcher = documentObject.querySelector('.hg-ask-ai-launcher');
+    if (consent) consent.hidden = consented;

Review Comment:
   Fixed in 784a42151. Not now and Escape persist a dismissed choice rather 
than a grant. Navigation, reload and new tabs keep the notice hidden and 
launcher visible, with no AI request. Explicit launcher or search activation 
displays the disclosure again. Cross-tab choice synchronization and EN/CN 
browser regressions are included.



##########
layouts/_partials/hooks/body-end.html:
##########
@@ -25,31 +25,38 @@
       "description" (T "ui_ask_ai_description")
       "latest" (T "ui_ask_ai_latest")
       "error" (T "ui_ai_error")
+      "community" (T "ui_ai_community")
   -}}
+  {{- $questions := slice -}}
+  {{- range hugo.Data.ai.questions -}}
+    {{- $questions = $questions | append (index . $lang) -}}
+  {{- end -}}
   {{- $clientConfig := dict
     "websiteId" $ai.websiteID
     "sourceGroupId" $sourceGroup
     "locale" (cond (eq $lang "cn") "zh" "en")
     "themeColor" $themeColor
     "historical" $historical
     "labels" $labels
+    "exampleQuestions" $questions
+    "communityURL" "https://github.com/apache/hugegraph/discussions";
   -}}
 <script type="application/json" id="hg-ai-config">{{ $clientConfig | jsonify | 
safeJS }}</script>
 <button type="button" class="hg-ask-ai-launcher d-print-none" data-hg-ask-ai
-  data-hg-ai-submit="false" aria-haspopup="dialog"{{ if $historical }} 
aria-label="{{ index $labels "ask" }} — {{ index $labels "latest" }}"{{ end }}>
+  data-hg-ai-submit="false" hidden aria-haspopup="dialog"{{ if $historical }} 
aria-label="{{ index $labels "ask" }} — {{ index $labels "latest" }}"{{ end }}>
   <i class="fa-solid fa-wand-magic-sparkles" aria-hidden="true"></i>
   <span>{{ index $labels "ask" }}</span>
 </button>
-<dialog class="hg-ai-consent" data-hg-ai-consent 
aria-labelledby="hg-ai-consent-title" aria-describedby="hg-ai-disclosure">
-  <h2 id="hg-ai-consent-title">{{ index $labels "ask" }}</h2>
+<section class="hg-ai-consent d-print-none" data-hg-ai-consent 
aria-labelledby="hg-ai-consent-title" aria-describedby="hg-ai-disclosure">

Review Comment:
   Fixed in 784a42151. The notice and launcher are both hidden in 
server-rendered markup; the local adapter reveals only the appropriate 
controls. A blocked-adapter browser regression confirms hidden controls, 
working native search and zero third-party AI requests.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to