@gengage/assistant-fe 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/dist/assistant-fe.css +1 -1
  2. package/dist/chat/components/AIGroupingCards.d.ts.map +1 -1
  3. package/dist/chat/components/AITopPicks.d.ts.map +1 -1
  4. package/dist/chat/components/ChatDrawer.d.ts +4 -0
  5. package/dist/chat/components/ChatDrawer.d.ts.map +1 -1
  6. package/dist/chat/components/ComparisonTable.d.ts +2 -7
  7. package/dist/chat/components/ComparisonTable.d.ts.map +1 -1
  8. package/dist/chat/components/productMentionLinker.d.ts.map +1 -1
  9. package/dist/chat/index.d.ts +9 -1
  10. package/dist/chat/index.d.ts.map +1 -1
  11. package/dist/chat/locales/en.d.ts.map +1 -1
  12. package/dist/chat/locales/tr.d.ts.map +1 -1
  13. package/dist/chat/panel-manager.d.ts +6 -2
  14. package/dist/chat/panel-manager.d.ts.map +1 -1
  15. package/dist/chat/session-persistence.d.ts +1 -0
  16. package/dist/chat/session-persistence.d.ts.map +1 -1
  17. package/dist/chat/types.d.ts +3 -1
  18. package/dist/chat/types.d.ts.map +1 -1
  19. package/dist/chat.cjs +1 -1
  20. package/dist/chat.iife.js +29 -29
  21. package/dist/chat.iife.js.map +1 -1
  22. package/dist/chat.js +2 -2
  23. package/dist/common/indexed-db.d.ts +2 -0
  24. package/dist/common/indexed-db.d.ts.map +1 -1
  25. package/dist/common/v1-protocol-adapter.d.ts.map +1 -1
  26. package/dist/common.cjs +1 -1
  27. package/dist/common.js +4 -4
  28. package/dist/index-B8EeSm-F.cjs +13 -0
  29. package/dist/index-B8EeSm-F.cjs.map +1 -0
  30. package/dist/index-BSpLCzAK.js +4523 -0
  31. package/dist/index-BSpLCzAK.js.map +1 -0
  32. package/dist/index.cjs +1 -1
  33. package/dist/index.js +2 -2
  34. package/dist/qna.cjs +1 -1
  35. package/dist/qna.iife.js +26 -26
  36. package/dist/qna.iife.js.map +1 -1
  37. package/dist/qna.js +1 -1
  38. package/dist/{schemas-B9GN-J3e.js → schemas-BlkBmaA5.js} +983 -934
  39. package/dist/schemas-BlkBmaA5.js.map +1 -0
  40. package/dist/schemas-DhaO7I0-.cjs +86 -0
  41. package/dist/schemas-DhaO7I0-.cjs.map +1 -0
  42. package/dist/simrel.cjs +1 -1
  43. package/dist/simrel.cjs.map +1 -1
  44. package/dist/simrel.css +1 -1
  45. package/dist/simrel.iife.js +21 -21
  46. package/dist/simrel.iife.js.map +1 -1
  47. package/dist/simrel.js +2 -2
  48. package/dist/simrel.js.map +1 -1
  49. package/package.json +1 -1
  50. package/dist/index-eefqsSOT.cjs +0 -13
  51. package/dist/index-eefqsSOT.cjs.map +0 -1
  52. package/dist/index-kp84NL1R.js +0 -4399
  53. package/dist/index-kp84NL1R.js.map +0 -1
  54. package/dist/schemas-B9GN-J3e.js.map +0 -1
  55. package/dist/schemas-tCxs1sED.cjs +0 -86
  56. package/dist/schemas-tCxs1sED.cjs.map +0 -1
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./index-eefqsSOT.cjs"),a=require("./qna.cjs"),i=require("./simrel.cjs"),t=require("./schemas-tCxs1sED.cjs"),e=require("./common.cjs");exports.GengageChat=n.GengageChat;exports.VoiceInput=n.VoiceInput;exports.createChatWidget=n.createChatWidget;exports.createDefaultChatUISpecRegistry=n.createDefaultChatUISpecRegistry;exports.defaultChatUnknownUISpecRenderer=n.defaultChatUnknownUISpecRenderer;exports.isVoiceInputSupported=n.isVoiceInputSupported;exports.renderChatUISpec=n.renderUISpec;exports.routeStreamAction=n.routeStreamAction;exports.GengageQNA=a.GengageQNA;exports.createDefaultQnaUISpecRegistry=a.createDefaultQnaUISpecRegistry;exports.createQNAWidget=a.createQNAWidget;exports.defaultQnaUnknownUISpecRenderer=a.defaultQnaUnknownUISpecRenderer;exports.renderQnaUISpec=a.renderQnaUISpec;exports.GengageSimRel=i.GengageSimRel;exports.createDefaultSimRelUISpecRegistry=i.createDefaultSimRelUISpecRegistry;exports.createSimRelWidget=i.createSimRelWidget;exports.defaultSimRelUnknownUISpecRenderer=i.defaultSimRelUnknownUISpecRenderer;exports.renderSimRelUISpec=i.renderSimRelUISpec;exports.DEFAULT_WIDGET_THEME_TOKENS=t.DEFAULT_WIDGET_THEME_TOKENS;exports.bootstrapSession=t.bootstrapSession;exports.buildChatEndpointUrl=t.buildChatEndpointUrl;exports.consumeStream=t.consumeStream;exports.defaultUnknownUISpecRenderer=t.defaultUnknownUISpecRenderer;exports.dispatch=t.dispatch;exports.listen=t.listen;exports.normalizeMiddlewareUrl=t.normalizeMiddlewareUrl;exports.renderUISpecWithRegistry=t.renderUISpecWithRegistry;exports.streamPost=t.streamPost;exports.updatePageContext=t.updatePageContext;exports.wireGADataLayer=t.wireGADataLayer;exports.wireQNAToChat=t.wireQNAToChat;exports.wireSimilarToChat=t.wireSimilarToChat;exports.withDefaultWidgetTheme=t.withDefaultWidgetTheme;exports.AccountRuntimeConfigSchema=e.AccountRuntimeConfigSchema;exports.AnalyticsAuthModeSchema=e.AnalyticsAuthModeSchema;exports.BASE_WIDGET_THEME=e.BASE_WIDGET_THEME;exports.DEFAULT_CUSTOMIZATION_LOCALE=e.DEFAULT_CUSTOMIZATION_LOCALE;exports.UnknownActionPolicySchema=e.UnknownActionPolicySchema;exports.autoDetectPageContext=e.autoDetectPageContext;exports.buildOverlayIdempotencyKey=e.buildOverlayIdempotencyKey;exports.createAccountIdentity=e.createAccountIdentity;exports.createAnalyticsClient=e.createAnalyticsClient;exports.createDefaultAccountRuntimeConfig=e.createDefaultAccountRuntimeConfig;exports.createDefaultAnalyticsConfig=e.createDefaultAnalyticsConfig;exports.createFloatingChatConfig=e.createFloatingChatConfig;exports.createPdpQnaConfig=e.createPdpQnaConfig;exports.createPdpSimRelConfig=e.createPdpSimRelConfig;exports.destroyOverlayWidgets=e.destroyOverlayWidgets;exports.detectPageType=e.detectPageType;exports.extractSkuFromUrl=e.extractSkuFromUrl;exports.getOverlayWidgets=e.getOverlayWidgets;exports.initGengageClient=e.initGengageClient;exports.initOverlayWidgets=e.initOverlayWidgets;exports.parseAccountRuntimeConfig=e.parseAccountRuntimeConfig;exports.preflightDiagnostics=e.preflightDiagnostics;exports.safeParseAccountRuntimeConfig=e.safeParseAccountRuntimeConfig;exports.withBaseTheme=e.withBaseTheme;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./index-B8EeSm-F.cjs"),a=require("./qna.cjs"),i=require("./simrel.cjs"),t=require("./schemas-DhaO7I0-.cjs"),e=require("./common.cjs");exports.GengageChat=n.GengageChat;exports.VoiceInput=n.VoiceInput;exports.createChatWidget=n.createChatWidget;exports.createDefaultChatUISpecRegistry=n.createDefaultChatUISpecRegistry;exports.defaultChatUnknownUISpecRenderer=n.defaultChatUnknownUISpecRenderer;exports.isVoiceInputSupported=n.isVoiceInputSupported;exports.renderChatUISpec=n.renderUISpec;exports.routeStreamAction=n.routeStreamAction;exports.GengageQNA=a.GengageQNA;exports.createDefaultQnaUISpecRegistry=a.createDefaultQnaUISpecRegistry;exports.createQNAWidget=a.createQNAWidget;exports.defaultQnaUnknownUISpecRenderer=a.defaultQnaUnknownUISpecRenderer;exports.renderQnaUISpec=a.renderQnaUISpec;exports.GengageSimRel=i.GengageSimRel;exports.createDefaultSimRelUISpecRegistry=i.createDefaultSimRelUISpecRegistry;exports.createSimRelWidget=i.createSimRelWidget;exports.defaultSimRelUnknownUISpecRenderer=i.defaultSimRelUnknownUISpecRenderer;exports.renderSimRelUISpec=i.renderSimRelUISpec;exports.DEFAULT_WIDGET_THEME_TOKENS=t.DEFAULT_WIDGET_THEME_TOKENS;exports.bootstrapSession=t.bootstrapSession;exports.buildChatEndpointUrl=t.buildChatEndpointUrl;exports.consumeStream=t.consumeStream;exports.defaultUnknownUISpecRenderer=t.defaultUnknownUISpecRenderer;exports.dispatch=t.dispatch;exports.listen=t.listen;exports.normalizeMiddlewareUrl=t.normalizeMiddlewareUrl;exports.renderUISpecWithRegistry=t.renderUISpecWithRegistry;exports.streamPost=t.streamPost;exports.updatePageContext=t.updatePageContext;exports.wireGADataLayer=t.wireGADataLayer;exports.wireQNAToChat=t.wireQNAToChat;exports.wireSimilarToChat=t.wireSimilarToChat;exports.withDefaultWidgetTheme=t.withDefaultWidgetTheme;exports.AccountRuntimeConfigSchema=e.AccountRuntimeConfigSchema;exports.AnalyticsAuthModeSchema=e.AnalyticsAuthModeSchema;exports.BASE_WIDGET_THEME=e.BASE_WIDGET_THEME;exports.DEFAULT_CUSTOMIZATION_LOCALE=e.DEFAULT_CUSTOMIZATION_LOCALE;exports.UnknownActionPolicySchema=e.UnknownActionPolicySchema;exports.autoDetectPageContext=e.autoDetectPageContext;exports.buildOverlayIdempotencyKey=e.buildOverlayIdempotencyKey;exports.createAccountIdentity=e.createAccountIdentity;exports.createAnalyticsClient=e.createAnalyticsClient;exports.createDefaultAccountRuntimeConfig=e.createDefaultAccountRuntimeConfig;exports.createDefaultAnalyticsConfig=e.createDefaultAnalyticsConfig;exports.createFloatingChatConfig=e.createFloatingChatConfig;exports.createPdpQnaConfig=e.createPdpQnaConfig;exports.createPdpSimRelConfig=e.createPdpSimRelConfig;exports.destroyOverlayWidgets=e.destroyOverlayWidgets;exports.detectPageType=e.detectPageType;exports.extractSkuFromUrl=e.extractSkuFromUrl;exports.getOverlayWidgets=e.getOverlayWidgets;exports.initGengageClient=e.initGengageClient;exports.initOverlayWidgets=e.initOverlayWidgets;exports.parseAccountRuntimeConfig=e.parseAccountRuntimeConfig;exports.preflightDiagnostics=e.preflightDiagnostics;exports.safeParseAccountRuntimeConfig=e.safeParseAccountRuntimeConfig;exports.withBaseTheme=e.withBaseTheme;
2
2
  //# sourceMappingURL=index.cjs.map
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import { G as t, V as n, c as r, a as i, d as c, i as o, b as s, r as l } from "./index-kp84NL1R.js";
1
+ import { G as t, V as n, c as r, a as i, d as c, i as o, b as s, r as l } from "./index-BSpLCzAK.js";
2
2
  import { GengageQNA as g, createDefaultQnaUISpecRegistry as p, createQNAWidget as u, defaultQnaUnknownUISpecRenderer as S, renderQnaUISpec as m } from "./qna.js";
3
3
  import { GengageSimRel as C, createDefaultSimRelUISpecRegistry as U, createSimRelWidget as A, defaultSimRelUnknownUISpecRenderer as h, renderSimRelUISpec as I } from "./simrel.js";
4
- import { X as R, Y as T, b as D, c as E, a0 as w, j as W, a3 as x, A as G, r as O, a8 as P, a9 as Q, aa as _, W as b, ab as k, ac as L } from "./schemas-B9GN-J3e.js";
4
+ import { X as R, Y as T, b as D, c as E, a0 as w, j as W, a3 as x, A as G, r as O, a8 as P, a9 as Q, aa as _, W as b, ab as k, ac as L } from "./schemas-BlkBmaA5.js";
5
5
  import { AccountRuntimeConfigSchema as N, AnalyticsAuthModeSchema as v, BASE_WIDGET_THEME as F, DEFAULT_CUSTOMIZATION_LOCALE as V, UnknownActionPolicySchema as B, autoDetectPageContext as H, buildOverlayIdempotencyKey as K, createAccountIdentity as j, createAnalyticsClient as z, createDefaultAccountRuntimeConfig as X, createDefaultAnalyticsConfig as Y, createFloatingChatConfig as Z, createPdpQnaConfig as q, createPdpSimRelConfig as J, destroyOverlayWidgets as $, detectPageType as ee, extractSkuFromUrl as ae, getOverlayWidgets as te, initGengageClient as ne, initOverlayWidgets as re, parseAccountRuntimeConfig as ie, preflightDiagnostics as ce, safeParseAccountRuntimeConfig as oe, withBaseTheme as se } from "./common.js";
6
6
  export {
7
7
  N as AccountRuntimeConfigSchema,
package/dist/qna.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./schemas-tCxs1sED.cjs");async function q(n,e,t){const i=s.buildChatEndpointUrl("launcher_action",e),o={uiSpecs:[],actions:[]},r={method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)};t!==void 0&&(r.signal=t);const a=await fetch(i,r);if(!a.ok)throw new Error(`HTTP ${a.status}: ${a.statusText}`);const c={onEvent:u=>{const l=s.adaptV1Event(u);if(l&&(l.type==="ui_spec"&&o.uiSpecs.push(l.spec),l.type==="ui_spec"&&l.spec.elements)){for(const p of Object.values(l.spec.elements))if(p.type==="ActionButton"&&p.props?.action){const h=p.props.action;o.actions.push(h)}}}};return t!==void 0&&(c.signal=t),await s.consumeStream(a,c),o}function _(n){const e=document.createElement("div");e.className="gengage-qna-buttons",e.setAttribute("role","group"),e.setAttribute("aria-label",n.quickQuestionsAriaLabel??"Quick questions"),n.orientation==="vertical"&&(e.style.flexDirection="column");for(const t of n.actions){const i=document.createElement("button");i.className="gengage-qna-button",i.textContent=t.title,i.type="button",i.addEventListener("click",()=>{const o={title:t.title,type:t.type};t.payload!==void 0&&(o.payload=t.payload),n.onAction(o)}),e.appendChild(i)}if(n.ctaText||n.onOpenChat){const t=document.createElement("button");t.className="gengage-qna-cta",t.textContent=n.ctaText??n.defaultCtaText??"Başka bir şey sor",t.type="button",t.addEventListener("click",()=>{n.onOpenChat?.()}),e.appendChild(t)}return e}function w(n){const e=document.createElement("div");e.className="gengage-qna-input-wrapper";const t=document.createElement("input");t.type="text",t.className="gengage-qna-input",t.setAttribute("aria-label",n.askQuestionAriaLabel??"Ask a question");const i=Array.isArray(n.placeholders)?n.placeholders:n.placeholders?[n.placeholders]:[n.defaultInputPlaceholder??"Bir soru sorun..."];let o=0;t.placeholder=i[0]??"";let r=null,a=null;i.length>1&&(r=setInterval(()=>{t.classList.add("gengage-qna-input--fade"),a=setTimeout(()=>{o=(o+1)%i.length,t.placeholder=i[o]??"",t.classList.remove("gengage-qna-input--fade")},180)},3e3));const c=document.createElement("button");c.className="gengage-qna-send",c.type="button",c.textContent=n.ctaLabel??n.sendButtonText??"Sor",c.setAttribute("aria-label",n.sendQuestionAriaLabel??"Send question");const u=()=>{const l=t.value.trim();l&&(n.onSubmit({title:l,type:"user_message",payload:{text:l}}),t.value="")};return c.addEventListener("click",u),t.addEventListener("keydown",l=>{l.key==="Enter"&&(l.preventDefault(),u())}),e.appendChild(t),e.appendChild(c),e._cleanup=()=>{r&&clearInterval(r),a&&clearTimeout(a)},e}function f(n,e){if(!n||typeof n!="object")return null;const t=n,i=t.type;if(typeof i!="string"||i.length===0)return null;const o=t.title,r=t.payload,a=typeof o=="string"&&o.length>0?o:e;if(!a)return null;const c={title:a,type:i};return r!==void 0&&(c.payload=r),c}function A(n){const e={title:n.title,type:n.type};return n.payload!==void 0&&(e.payload=n.payload),e}function T(n,e){const t=[],i=n.props?.actions;if(Array.isArray(i))for(const a of i){const c=f(a);c&&t.push(c)}const o=n.props?.buttons;if(Array.isArray(o))for(const a of o){if(!a||typeof a!="object")continue;const c=a,u=typeof c.label=="string"?c.label:void 0,l=f(c.action,u);l&&t.push(l)}if(n.children)for(const a of n.children){const c=e.elements[a];if(!c||c.type!=="ActionButton")continue;const u=typeof c.props?.label=="string"?c.props.label:void 0,l=f(c.props?.action,u);l&&t.push(l)}const r=new Set;return t.filter(a=>r.has(a.title)?!1:(r.add(a.title),!0))}const C={ButtonRow:({element:n,spec:e,context:t})=>{const i=T(n,e).map(A),o=n.props?.orientation,r={actions:i,onAction:t.onAction,defaultCtaText:t.i18n.defaultCtaText,quickQuestionsAriaLabel:t.i18n.quickQuestionsAriaLabel};return t.onOpenChat!==void 0&&(r.onOpenChat=t.onOpenChat),t.ctaText!==void 0&&(r.ctaText=t.ctaText),(o==="horizontal"||o==="vertical")&&(r.orientation=o),_(r)},ActionButtons:({element:n,spec:e,context:t})=>{const o={actions:T(n,e).map(A),onAction:t.onAction,defaultCtaText:t.i18n.defaultCtaText,quickQuestionsAriaLabel:t.i18n.quickQuestionsAriaLabel};return t.onOpenChat!==void 0&&(o.onOpenChat=t.onOpenChat),t.ctaText!==void 0&&(o.ctaText=t.ctaText),_(o)},ActionButton:({element:n,context:e})=>{const t=document.createElement("button");t.className="gengage-qna-button",t.type="button";const i=n.props?.label;typeof i=="string"?t.textContent=i:t.textContent=e.i18n.defaultCtaText;const o=f(n.props?.action,typeof i=="string"?i:void 0);return o&&t.addEventListener("click",()=>e.onAction(o)),t},TextInput:({element:n,context:e})=>{const t=n.props?.placeholder,i=typeof t=="string"||Array.isArray(t)?t:e.inputPlaceholder,o=typeof n.props?.ctaLabel=="string"?n.props.ctaLabel:e.ctaText,r={onSubmit:e.onAction,askQuestionAriaLabel:e.i18n.askQuestionAriaLabel,defaultInputPlaceholder:e.i18n.defaultInputPlaceholder,sendButtonText:e.i18n.sendButton,sendQuestionAriaLabel:e.i18n.sendQuestionAriaLabel};return i!==void 0&&(r.placeholders=i),o!==void 0&&(r.ctaLabel=o),w(r)},QuestionHeading:({element:n})=>{const e=document.createElement("h3");e.className="gengage-qna-heading";const t=n.props?.text;return e.textContent=typeof t=="string"?t:"",e},ProductCard:()=>null},m=({element:n,renderElement:e})=>{if(!n.children||n.children.length===0)return null;const t=document.createElement("div");for(const i of n.children){const o=e(i);o&&t.appendChild(o)}return t};function E(){return{...C}}function S(n,e,t=C,i=m){return s.renderUISpecWithRegistry({spec:n,context:e,registry:t,containerClassName:"gengage-qna-uispec",unknownRenderer:i})}const v={quickQuestionsAriaLabel:"Hızlı sorular",askQuestionAriaLabel:"Soru sorun",defaultInputPlaceholder:"Bir soru sorun...",sendButton:"Sor",sendQuestionAriaLabel:"Soruyu gönder",defaultCtaText:"Başka bir şey sor"},Q={quickQuestionsAriaLabel:"Quick questions",askQuestionAriaLabel:"Ask a question",defaultInputPlaceholder:"Ask a question...",sendButton:"Ask",sendQuestionAriaLabel:"Send question",defaultCtaText:"Ask something else"};function L(n){return n?n.toLowerCase().split("-")[0]??"tr":"tr"}function x(n){return L(n)==="en"?Q:v}const R=s.object({title:s.string(),type:s.string(),payload:s.unknown().optional()}),N=s.object({label:s.string(),action:R,variant:s._enum(["primary","outline","ghost"]).optional()}),B=s.object({orientation:s._enum(["horizontal","vertical"]).optional(),wrap:s.boolean().optional()}),U=s.object({placeholder:s.union([s.string(),s.array(s.string())]).optional(),ctaLabel:s.string().optional()}),O=s.object({text:s.string()}),P={components:{ActionButton:{schema:N,description:"A single clickable QNA action button."},ButtonRow:{schema:B,description:"Container for a group of QNA action buttons."},TextInput:{schema:U,description:"Free-text input with rotating placeholder and CTA button."},QuestionHeading:{schema:O,description:"A heading displayed above the QNA button group."}}};class I extends s.BaseWidget{constructor(){super(...arguments),this._abortController=null,this._debounceTimer=null,this._contentEl=null,this._i18n=v,this._actionHandler=this._handleAction.bind(this),this._openChatHandler=this._handleOpenChat.bind(this)}async onInit(e){this._i18n=this._resolveI18n(e),this._contentEl=document.createElement("div"),this._contentEl.className="gengage-qna-container",this.root.appendChild(this._contentEl);const t=e.pageContext?.sku;t&&(this._lastSku=t,await this._fetchAndRender(t)),this.isVisible=!0,s.trackInit("qna")}onUpdate(e){const t=e.sku;!t||t===this._lastSku||(this._debounceTimer&&clearTimeout(this._debounceTimer),this._debounceTimer=setTimeout(()=>{this._debounceTimer=null,this._lastSku=t,this._fetchAndRender(t)},50))}onShow(){this._contentEl&&(this._contentEl.style.opacity="0",this._contentEl.style.transition="opacity 0.2s ease-in",requestAnimationFrame(()=>{this._contentEl&&(this._contentEl.style.opacity="1")}))}onHide(){}onDestroy(){this._abort(),this._debounceTimer&&(clearTimeout(this._debounceTimer),this._debounceTimer=null),this._contentEl&&(this._cleanupTextInputTimers(),this._contentEl.remove(),this._contentEl=null)}_abort(){this._abortController?.abort(),this._abortController=null}_cleanupTextInputTimers(){if(!this._contentEl)return;const e=this._contentEl.querySelectorAll(".gengage-qna-input-wrapper");for(const t of e)t._cleanup?.()}async _fetchAndRender(e){if(this._abort(),this._abortController=new AbortController,!this._contentEl)return;this._cleanupTextInputTimers(),this._contentEl.innerHTML="";const t=this._createLoadingIndicator();this._contentEl.appendChild(t);const i={middlewareUrl:this.config.middlewareUrl},o=crypto.randomUUID(),r=Date.now();this.track(s.streamStartEvent(this.analyticsContext(),{endpoint:"launcher_action",request_id:o,widget:"qna"}));try{const a={account_id:this.config.accountId,session_id:this.config.session?.sessionId??"",correlation_id:this.config.session?.sessionId??"",sku:e,locale:this.config.locale??"tr"},c=this.config.pageContext?.pageType;c!==void 0&&(a.page_type=c);const u=await q(a,i,this._abortController.signal);if(this.track(s.streamDoneEvent(this.analyticsContext(),{request_id:o,latency_ms:Date.now()-r,chunk_count:u.actions.length,widget:"qna"})),this.track(s.widgetHistorySnapshotEvent(this.analyticsContext(),{message_count:u.actions.length,history_ref:o,redaction_level:"none",widget:"qna"})),!this._contentEl)return;if(this._contentEl.innerHTML="",!this._specIncludesType(u.uiSpecs,"QuestionHeading")&&this.config.showStaticQuestion&&this.config.staticQuestionText){const d=document.createElement("h3");d.className="gengage-qna-heading",d.textContent=this.config.staticQuestionText,this._contentEl.appendChild(d)}const p=this.config.inputPlaceholder,h=u.actions.length>0&&p===!0?u.actions.map(d=>d.title):p===!0?this._i18n.defaultInputPlaceholder:p,g={onAction:this._actionHandler,i18n:this._i18n};p===void 0&&(g.onOpenChat=this._openChatHandler,this.config.ctaText!==void 0&&(g.ctaText=this.config.ctaText)),h!==void 0&&(g.inputPlaceholder=h);const k=this._buildFallbackActionsSpec(u.actions),b=(u.uiSpecs.length>0?u.uiSpecs:[k]).filter(d=>Object.keys(d.elements).length>0);for(const d of b){const y=this._renderUISpec(d,g);this._contentEl.appendChild(y)}if(b.length>0&&s.trackShow("qna"),p!==void 0&&!this._specIncludesType(b,"TextInput")){const d={root:"root",elements:{root:{type:"TextInput",props:{placeholder:h,ctaLabel:this.config.ctaText}}}},y=this._renderUISpec(d,g);this._contentEl.appendChild(y)}}catch(a){if(a instanceof DOMException&&a.name==="AbortError")return;s.dispatch("gengage:global:error",{source:"qna",code:"FETCH_ERROR",message:s.getGlobalErrorMessage(this.config.locale)}),this.track(s.streamErrorEvent(this.analyticsContext(),{request_id:o,error_code:"FETCH_ERROR",error_message:a instanceof Error?a.message:String(a),widget:"qna"}))}}_createLoadingIndicator(){const e=document.createElement("div");e.className="gengage-qna-loading";for(let t=0;t<3;t++){const i=document.createElement("div");i.className="gengage-qna-loading-dot",e.appendChild(i)}return e}_resolveI18n(e){return{...x(e.locale),...e.i18n}}_resolveUISpecRegistry(){const e=E();return s.mergeUISpecRegistry(e,this.config.renderer?.registry)}_renderUISpec(e,t){const i=this._resolveUISpecRegistry(),o=this.config.renderer?.unknownRenderer??m,r=(u,l)=>S(u,l,i,o),a=this.config.renderer?.renderUISpec;return a?a(e,t,{registry:i,unknownRenderer:o,defaultRender:r}):r(e,t)}_specIncludesType(e,t){for(const i of e)for(const o of Object.values(i.elements))if(o.type===t)return!0;return!1}_buildFallbackActionsSpec(e){if(e.length===0)return{root:"root",elements:{}};const t={},i=[];for(let o=0;o<e.length;o++){const r=e[o],a=`action-${o}`;i.push(a),t[a]={type:"ActionButton",props:{label:r.title,action:{title:r.title,type:r.type,payload:r.payload}}}}return t.root={type:"ButtonRow",children:i},{root:"root",elements:t}}_handleAction(e){s.trackSuggestedQuestion(e.title,e.type),this.config.onActionSelected?.(e),s.dispatch("gengage:qna:action",e)}_handleOpenChat(){this.config.onOpenChat?.(),s.dispatch("gengage:qna:open-chat",{})}}function H(){return new I}exports.GengageQNA=I;exports.createDefaultQnaUISpecRegistry=E;exports.createQNAWidget=H;exports.defaultQnaUnknownUISpecRenderer=m;exports.qnaCatalog=P;exports.renderQnaUISpec=S;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./schemas-DhaO7I0-.cjs");async function q(n,e,t){const i=s.buildChatEndpointUrl("launcher_action",e),o={uiSpecs:[],actions:[]},r={method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)};t!==void 0&&(r.signal=t);const a=await fetch(i,r);if(!a.ok)throw new Error(`HTTP ${a.status}: ${a.statusText}`);const c={onEvent:u=>{const l=s.adaptV1Event(u);if(l&&(l.type==="ui_spec"&&o.uiSpecs.push(l.spec),l.type==="ui_spec"&&l.spec.elements)){for(const p of Object.values(l.spec.elements))if(p.type==="ActionButton"&&p.props?.action){const h=p.props.action;o.actions.push(h)}}}};return t!==void 0&&(c.signal=t),await s.consumeStream(a,c),o}function _(n){const e=document.createElement("div");e.className="gengage-qna-buttons",e.setAttribute("role","group"),e.setAttribute("aria-label",n.quickQuestionsAriaLabel??"Quick questions"),n.orientation==="vertical"&&(e.style.flexDirection="column");for(const t of n.actions){const i=document.createElement("button");i.className="gengage-qna-button",i.textContent=t.title,i.type="button",i.addEventListener("click",()=>{const o={title:t.title,type:t.type};t.payload!==void 0&&(o.payload=t.payload),n.onAction(o)}),e.appendChild(i)}if(n.ctaText||n.onOpenChat){const t=document.createElement("button");t.className="gengage-qna-cta",t.textContent=n.ctaText??n.defaultCtaText??"Başka bir şey sor",t.type="button",t.addEventListener("click",()=>{n.onOpenChat?.()}),e.appendChild(t)}return e}function w(n){const e=document.createElement("div");e.className="gengage-qna-input-wrapper";const t=document.createElement("input");t.type="text",t.className="gengage-qna-input",t.setAttribute("aria-label",n.askQuestionAriaLabel??"Ask a question");const i=Array.isArray(n.placeholders)?n.placeholders:n.placeholders?[n.placeholders]:[n.defaultInputPlaceholder??"Bir soru sorun..."];let o=0;t.placeholder=i[0]??"";let r=null,a=null;i.length>1&&(r=setInterval(()=>{t.classList.add("gengage-qna-input--fade"),a=setTimeout(()=>{o=(o+1)%i.length,t.placeholder=i[o]??"",t.classList.remove("gengage-qna-input--fade")},180)},3e3));const c=document.createElement("button");c.className="gengage-qna-send",c.type="button",c.textContent=n.ctaLabel??n.sendButtonText??"Sor",c.setAttribute("aria-label",n.sendQuestionAriaLabel??"Send question");const u=()=>{const l=t.value.trim();l&&(n.onSubmit({title:l,type:"user_message",payload:{text:l}}),t.value="")};return c.addEventListener("click",u),t.addEventListener("keydown",l=>{l.key==="Enter"&&(l.preventDefault(),u())}),e.appendChild(t),e.appendChild(c),e._cleanup=()=>{r&&clearInterval(r),a&&clearTimeout(a)},e}function f(n,e){if(!n||typeof n!="object")return null;const t=n,i=t.type;if(typeof i!="string"||i.length===0)return null;const o=t.title,r=t.payload,a=typeof o=="string"&&o.length>0?o:e;if(!a)return null;const c={title:a,type:i};return r!==void 0&&(c.payload=r),c}function A(n){const e={title:n.title,type:n.type};return n.payload!==void 0&&(e.payload=n.payload),e}function T(n,e){const t=[],i=n.props?.actions;if(Array.isArray(i))for(const a of i){const c=f(a);c&&t.push(c)}const o=n.props?.buttons;if(Array.isArray(o))for(const a of o){if(!a||typeof a!="object")continue;const c=a,u=typeof c.label=="string"?c.label:void 0,l=f(c.action,u);l&&t.push(l)}if(n.children)for(const a of n.children){const c=e.elements[a];if(!c||c.type!=="ActionButton")continue;const u=typeof c.props?.label=="string"?c.props.label:void 0,l=f(c.props?.action,u);l&&t.push(l)}const r=new Set;return t.filter(a=>r.has(a.title)?!1:(r.add(a.title),!0))}const C={ButtonRow:({element:n,spec:e,context:t})=>{const i=T(n,e).map(A),o=n.props?.orientation,r={actions:i,onAction:t.onAction,defaultCtaText:t.i18n.defaultCtaText,quickQuestionsAriaLabel:t.i18n.quickQuestionsAriaLabel};return t.onOpenChat!==void 0&&(r.onOpenChat=t.onOpenChat),t.ctaText!==void 0&&(r.ctaText=t.ctaText),(o==="horizontal"||o==="vertical")&&(r.orientation=o),_(r)},ActionButtons:({element:n,spec:e,context:t})=>{const o={actions:T(n,e).map(A),onAction:t.onAction,defaultCtaText:t.i18n.defaultCtaText,quickQuestionsAriaLabel:t.i18n.quickQuestionsAriaLabel};return t.onOpenChat!==void 0&&(o.onOpenChat=t.onOpenChat),t.ctaText!==void 0&&(o.ctaText=t.ctaText),_(o)},ActionButton:({element:n,context:e})=>{const t=document.createElement("button");t.className="gengage-qna-button",t.type="button";const i=n.props?.label;typeof i=="string"?t.textContent=i:t.textContent=e.i18n.defaultCtaText;const o=f(n.props?.action,typeof i=="string"?i:void 0);return o&&t.addEventListener("click",()=>e.onAction(o)),t},TextInput:({element:n,context:e})=>{const t=n.props?.placeholder,i=typeof t=="string"||Array.isArray(t)?t:e.inputPlaceholder,o=typeof n.props?.ctaLabel=="string"?n.props.ctaLabel:e.ctaText,r={onSubmit:e.onAction,askQuestionAriaLabel:e.i18n.askQuestionAriaLabel,defaultInputPlaceholder:e.i18n.defaultInputPlaceholder,sendButtonText:e.i18n.sendButton,sendQuestionAriaLabel:e.i18n.sendQuestionAriaLabel};return i!==void 0&&(r.placeholders=i),o!==void 0&&(r.ctaLabel=o),w(r)},QuestionHeading:({element:n})=>{const e=document.createElement("h3");e.className="gengage-qna-heading";const t=n.props?.text;return e.textContent=typeof t=="string"?t:"",e},ProductCard:()=>null},m=({element:n,renderElement:e})=>{if(!n.children||n.children.length===0)return null;const t=document.createElement("div");for(const i of n.children){const o=e(i);o&&t.appendChild(o)}return t};function E(){return{...C}}function S(n,e,t=C,i=m){return s.renderUISpecWithRegistry({spec:n,context:e,registry:t,containerClassName:"gengage-qna-uispec",unknownRenderer:i})}const v={quickQuestionsAriaLabel:"Hızlı sorular",askQuestionAriaLabel:"Soru sorun",defaultInputPlaceholder:"Bir soru sorun...",sendButton:"Sor",sendQuestionAriaLabel:"Soruyu gönder",defaultCtaText:"Başka bir şey sor"},Q={quickQuestionsAriaLabel:"Quick questions",askQuestionAriaLabel:"Ask a question",defaultInputPlaceholder:"Ask a question...",sendButton:"Ask",sendQuestionAriaLabel:"Send question",defaultCtaText:"Ask something else"};function L(n){return n?n.toLowerCase().split("-")[0]??"tr":"tr"}function x(n){return L(n)==="en"?Q:v}const R=s.object({title:s.string(),type:s.string(),payload:s.unknown().optional()}),N=s.object({label:s.string(),action:R,variant:s._enum(["primary","outline","ghost"]).optional()}),B=s.object({orientation:s._enum(["horizontal","vertical"]).optional(),wrap:s.boolean().optional()}),U=s.object({placeholder:s.union([s.string(),s.array(s.string())]).optional(),ctaLabel:s.string().optional()}),O=s.object({text:s.string()}),P={components:{ActionButton:{schema:N,description:"A single clickable QNA action button."},ButtonRow:{schema:B,description:"Container for a group of QNA action buttons."},TextInput:{schema:U,description:"Free-text input with rotating placeholder and CTA button."},QuestionHeading:{schema:O,description:"A heading displayed above the QNA button group."}}};class I extends s.BaseWidget{constructor(){super(...arguments),this._abortController=null,this._debounceTimer=null,this._contentEl=null,this._i18n=v,this._actionHandler=this._handleAction.bind(this),this._openChatHandler=this._handleOpenChat.bind(this)}async onInit(e){this._i18n=this._resolveI18n(e),this._contentEl=document.createElement("div"),this._contentEl.className="gengage-qna-container",this.root.appendChild(this._contentEl);const t=e.pageContext?.sku;t&&(this._lastSku=t,await this._fetchAndRender(t)),this.isVisible=!0,s.trackInit("qna")}onUpdate(e){const t=e.sku;!t||t===this._lastSku||(this._debounceTimer&&clearTimeout(this._debounceTimer),this._debounceTimer=setTimeout(()=>{this._debounceTimer=null,this._lastSku=t,this._fetchAndRender(t)},50))}onShow(){this._contentEl&&(this._contentEl.style.opacity="0",this._contentEl.style.transition="opacity 0.2s ease-in",requestAnimationFrame(()=>{this._contentEl&&(this._contentEl.style.opacity="1")}))}onHide(){}onDestroy(){this._abort(),this._debounceTimer&&(clearTimeout(this._debounceTimer),this._debounceTimer=null),this._contentEl&&(this._cleanupTextInputTimers(),this._contentEl.remove(),this._contentEl=null)}_abort(){this._abortController?.abort(),this._abortController=null}_cleanupTextInputTimers(){if(!this._contentEl)return;const e=this._contentEl.querySelectorAll(".gengage-qna-input-wrapper");for(const t of e)t._cleanup?.()}async _fetchAndRender(e){if(this._abort(),this._abortController=new AbortController,!this._contentEl)return;this._cleanupTextInputTimers(),this._contentEl.innerHTML="";const t=this._createLoadingIndicator();this._contentEl.appendChild(t);const i={middlewareUrl:this.config.middlewareUrl},o=crypto.randomUUID(),r=Date.now();this.track(s.streamStartEvent(this.analyticsContext(),{endpoint:"launcher_action",request_id:o,widget:"qna"}));try{const a={account_id:this.config.accountId,session_id:this.config.session?.sessionId??"",correlation_id:this.config.session?.sessionId??"",sku:e,locale:this.config.locale??"tr"},c=this.config.pageContext?.pageType;c!==void 0&&(a.page_type=c);const u=await q(a,i,this._abortController.signal);if(this.track(s.streamDoneEvent(this.analyticsContext(),{request_id:o,latency_ms:Date.now()-r,chunk_count:u.actions.length,widget:"qna"})),this.track(s.widgetHistorySnapshotEvent(this.analyticsContext(),{message_count:u.actions.length,history_ref:o,redaction_level:"none",widget:"qna"})),!this._contentEl)return;if(this._contentEl.innerHTML="",!this._specIncludesType(u.uiSpecs,"QuestionHeading")&&this.config.showStaticQuestion&&this.config.staticQuestionText){const d=document.createElement("h3");d.className="gengage-qna-heading",d.textContent=this.config.staticQuestionText,this._contentEl.appendChild(d)}const p=this.config.inputPlaceholder,h=u.actions.length>0&&p===!0?u.actions.map(d=>d.title):p===!0?this._i18n.defaultInputPlaceholder:p,g={onAction:this._actionHandler,i18n:this._i18n};p===void 0&&(g.onOpenChat=this._openChatHandler,this.config.ctaText!==void 0&&(g.ctaText=this.config.ctaText)),h!==void 0&&(g.inputPlaceholder=h);const k=this._buildFallbackActionsSpec(u.actions),b=(u.uiSpecs.length>0?u.uiSpecs:[k]).filter(d=>Object.keys(d.elements).length>0);for(const d of b){const y=this._renderUISpec(d,g);this._contentEl.appendChild(y)}if(b.length>0&&s.trackShow("qna"),p!==void 0&&!this._specIncludesType(b,"TextInput")){const d={root:"root",elements:{root:{type:"TextInput",props:{placeholder:h,ctaLabel:this.config.ctaText}}}},y=this._renderUISpec(d,g);this._contentEl.appendChild(y)}}catch(a){if(a instanceof DOMException&&a.name==="AbortError")return;s.dispatch("gengage:global:error",{source:"qna",code:"FETCH_ERROR",message:s.getGlobalErrorMessage(this.config.locale)}),this.track(s.streamErrorEvent(this.analyticsContext(),{request_id:o,error_code:"FETCH_ERROR",error_message:a instanceof Error?a.message:String(a),widget:"qna"}))}}_createLoadingIndicator(){const e=document.createElement("div");e.className="gengage-qna-loading";for(let t=0;t<3;t++){const i=document.createElement("div");i.className="gengage-qna-loading-dot",e.appendChild(i)}return e}_resolveI18n(e){return{...x(e.locale),...e.i18n}}_resolveUISpecRegistry(){const e=E();return s.mergeUISpecRegistry(e,this.config.renderer?.registry)}_renderUISpec(e,t){const i=this._resolveUISpecRegistry(),o=this.config.renderer?.unknownRenderer??m,r=(u,l)=>S(u,l,i,o),a=this.config.renderer?.renderUISpec;return a?a(e,t,{registry:i,unknownRenderer:o,defaultRender:r}):r(e,t)}_specIncludesType(e,t){for(const i of e)for(const o of Object.values(i.elements))if(o.type===t)return!0;return!1}_buildFallbackActionsSpec(e){if(e.length===0)return{root:"root",elements:{}};const t={},i=[];for(let o=0;o<e.length;o++){const r=e[o],a=`action-${o}`;i.push(a),t[a]={type:"ActionButton",props:{label:r.title,action:{title:r.title,type:r.type,payload:r.payload}}}}return t.root={type:"ButtonRow",children:i},{root:"root",elements:t}}_handleAction(e){s.trackSuggestedQuestion(e.title,e.type),this.config.onActionSelected?.(e),s.dispatch("gengage:qna:action",e)}_handleOpenChat(){this.config.onOpenChat?.(),s.dispatch("gengage:qna:open-chat",{})}}function H(){return new I}exports.GengageQNA=I;exports.createDefaultQnaUISpecRegistry=E;exports.createQNAWidget=H;exports.defaultQnaUnknownUISpecRenderer=m;exports.qnaCatalog=P;exports.renderQnaUISpec=S;
2
2
  //# sourceMappingURL=qna.cjs.map