@gengage/assistant-fe 0.2.5 → 0.2.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 (64) hide show
  1. package/dist/chat/chat-presentation-state.d.ts +54 -0
  2. package/dist/chat/chat-presentation-state.d.ts.map +1 -0
  3. package/dist/chat/components/AIGroupingCards.d.ts.map +1 -1
  4. package/dist/chat/components/AISuggestedSearchCards.d.ts.map +1 -1
  5. package/dist/chat/components/AITopPicks.d.ts.map +1 -1
  6. package/dist/chat/components/ChatDrawer.d.ts +46 -0
  7. package/dist/chat/components/ChatDrawer.d.ts.map +1 -1
  8. package/dist/chat/components/ThumbnailsColumn.d.ts +2 -0
  9. package/dist/chat/components/ThumbnailsColumn.d.ts.map +1 -1
  10. package/dist/chat/index.d.ts +10 -0
  11. package/dist/chat/index.d.ts.map +1 -1
  12. package/dist/chat/locales/en.d.ts.map +1 -1
  13. package/dist/chat/locales/tr.d.ts.map +1 -1
  14. package/dist/chat/types.d.ts +7 -1
  15. package/dist/chat/types.d.ts.map +1 -1
  16. package/dist/chat/utils/chat-presentation-debug.d.ts +20 -0
  17. package/dist/chat/utils/chat-presentation-debug.d.ts.map +1 -0
  18. package/dist/chat/utils/get-chat-scroll-element.d.ts +11 -0
  19. package/dist/chat/utils/get-chat-scroll-element.d.ts.map +1 -0
  20. package/dist/chat.cjs +1 -1
  21. package/dist/chat.iife.js +22 -22
  22. package/dist/chat.iife.js.map +1 -1
  23. package/dist/chat.js +10 -6
  24. package/dist/common/index.d.ts +2 -0
  25. package/dist/common/index.d.ts.map +1 -1
  26. package/dist/common/protocol-adapter.d.ts.map +1 -1
  27. package/dist/common/suggested-search-keywords.d.ts +19 -0
  28. package/dist/common/suggested-search-keywords.d.ts.map +1 -0
  29. package/dist/common.cjs +1 -1
  30. package/dist/common.js +50 -48
  31. package/dist/index-BLq9Phmq.js +5101 -0
  32. package/dist/index-BLq9Phmq.js.map +1 -0
  33. package/dist/{index-B6xRdkMq.cjs → index-BeP3ETm1.cjs} +2 -2
  34. package/dist/{index-B6xRdkMq.cjs.map → index-BeP3ETm1.cjs.map} +1 -1
  35. package/dist/index-BwBJkYGY.cjs +13 -0
  36. package/dist/index-BwBJkYGY.cjs.map +1 -0
  37. package/dist/{index-BsvmfVa1.js → index-ZO_kMfUR.js} +3 -3
  38. package/dist/{index-BsvmfVa1.js.map → index-ZO_kMfUR.js.map} +1 -1
  39. package/dist/index.cjs +1 -1
  40. package/dist/index.js +5 -5
  41. package/dist/native.cjs +1 -1
  42. package/dist/native.iife.js +28 -28
  43. package/dist/native.iife.js.map +1 -1
  44. package/dist/native.js +1 -1
  45. package/dist/qna.cjs +1 -1
  46. package/dist/qna.iife.js +6 -6
  47. package/dist/qna.iife.js.map +1 -1
  48. package/dist/qna.js +1 -1
  49. package/dist/schemas-CaaT5BuE.cjs +86 -0
  50. package/dist/schemas-CaaT5BuE.cjs.map +1 -0
  51. package/dist/{schemas-Fiaobs4L.js → schemas-DR_GaPQj.js} +900 -876
  52. package/dist/schemas-DR_GaPQj.js.map +1 -0
  53. package/dist/simrel.cjs +1 -1
  54. package/dist/simrel.iife.js +7 -7
  55. package/dist/simrel.iife.js.map +1 -1
  56. package/dist/simrel.js +1 -1
  57. package/package.json +2 -1
  58. package/dist/index-BzCc2DCm.cjs +0 -13
  59. package/dist/index-BzCc2DCm.cjs.map +0 -1
  60. package/dist/index-D5UPIXIA.js +0 -4831
  61. package/dist/index-D5UPIXIA.js.map +0 -1
  62. package/dist/schemas-CNzyBhf7.cjs +0 -86
  63. package/dist/schemas-CNzyBhf7.cjs.map +0 -1
  64. package/dist/schemas-Fiaobs4L.js.map +0 -1
package/dist/native.js CHANGED
@@ -1,4 +1,4 @@
1
- import { D as i, b as t, e as s, g as r, j as v } from "./index-BsvmfVa1.js";
1
+ import { D as i, b as t, e as s, g as r, j as v } from "./index-ZO_kMfUR.js";
2
2
  export {
3
3
  i as DEFAULT_NATIVE_TRACKED_EVENTS,
4
4
  t as applyNativeSession,
package/dist/qna.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./schemas-CNzyBhf7.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:l=>{const u=s.adaptBackendEvent(l);if(u&&(u.type==="ui_spec"&&o.uiSpecs.push(u.spec),u.type==="ui_spec"&&u.spec.elements)){for(const h of Object.values(u.spec.elements))if(h.type==="ActionButton"&&h.props?.action){const p=h.props.action;o.actions.push(p)}}}};return t!==void 0&&(c.signal=t),await s.consumeStream(a,c),o}function m(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??"Ask something else",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??"Ask a question..."];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??"Ask",c.setAttribute("aria-label",n.sendQuestionAriaLabel??"Send question");const l=()=>{const u=t.value.trim();u&&(n.onSubmit({title:u,type:"user_message",payload:u}),t.value="")};return c.addEventListener("click",l),t.addEventListener("keydown",u=>{u.key==="Enter"&&(u.preventDefault(),l())}),e.appendChild(t),e.appendChild(c),e._cleanup=()=>{r&&clearInterval(r),a&&clearTimeout(a)},e}function _(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=_(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,l=typeof c.label=="string"?c.label:void 0,u=_(c.action,l);u&&t.push(u)}if(n.children)for(const a of n.children){const c=e.elements[a];if(!c||c.type!=="ActionButton")continue;const l=typeof c.props?.label=="string"?c.props.label:void 0,u=_(c.props?.action,l);u&&t.push(u)}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),m(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),m(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=_(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:void 0,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},y=({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 I(n,e,t=C,i=y){return s.renderUISpecWithRegistry({spec:n,context:e,registry:t,containerClassName:"gengage-qna-uispec",unknownRenderer:i})}const S={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 x(n){return n?n.toLowerCase().split("-")[0]??"tr":"tr"}function L(n){return x(n)==="en"?Q:S}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()}),P=s.object({orientation:s._enum(["horizontal","vertical"]).optional(),wrap:s.boolean().optional()}),B=s.object({placeholder:s.union([s.string(),s.array(s.string())]).optional(),ctaLabel:s.string().optional()}),U=s.object({text:s.string()}),O={components:{ActionButton:{schema:N,description:"A single clickable QNA action button."},ButtonRow:{schema:P,description:"Container for a group of QNA action buttons."},TextInput:{schema:B,description:"Free-text input with rotating placeholder and CTA button."},QuestionHeading:{schema:U,description:"A heading displayed above the QNA button group."}}};class v extends s.BaseWidget{constructor(){super(...arguments),this._abortController=null,this._debounceTimer=null,this._contentEl=null,this._i18n=S,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)),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 l=await q(a,i,this._abortController.signal);if(this.track(s.streamDoneEvent(this.analyticsContext(),{request_id:o,latency_ms:Date.now()-r,chunk_count:l.actions.length,widget:"qna"})),this.track(s.widgetHistorySnapshotEvent(this.analyticsContext(),{message_count:l.actions.length,history_ref:o,redaction_level:"none",widget:"qna"})),!this._contentEl)return;if(this._contentEl.innerHTML="",!this._specIncludesType(l.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 h=this.config.inputPlaceholder;let p;if(h!==!0)p=h??this._i18n.defaultInputPlaceholder;else if(l.actions.length>0){const d=l.actions.filter(f=>f.type==="user_message"||f.title.includes("?")).map(f=>f.title);p=d.length>0?d:this._i18n.defaultInputPlaceholder}else p=this._i18n.defaultInputPlaceholder;const g={onAction:this._actionHandler,i18n:this._i18n};this.config.hideButtonRowCta||(g.onOpenChat=this._openChatHandler,this.config.ctaText!==void 0&&(g.ctaText=this.config.ctaText)),p!==void 0&&(g.inputPlaceholder=p);const k=this._buildFallbackActionsSpec(l.actions),b=(l.uiSpecs.length>0?l.uiSpecs:[k]).filter(d=>Object.keys(d.elements).length>0);for(const d of b){const f=this._renderUISpec(d,g);this._contentEl.appendChild(f)}b.length>0&&s.trackShow("qna"),!this._specIncludesType(b,"TextInput")&&this._appendStandaloneInput(g,p)}catch(a){if(a instanceof DOMException&&a.name==="AbortError")return;if(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"})),this._contentEl){this._cleanupTextInputTimers(),this._contentEl.innerHTML="";const c=this.config.inputPlaceholder===!0?this._i18n.defaultInputPlaceholder:this.config.inputPlaceholder??this._i18n.defaultInputPlaceholder,l={onAction:this._actionHandler,i18n:this._i18n,onOpenChat:this._openChatHandler};this.config.ctaText!==void 0&&(l.ctaText=this.config.ctaText),this._appendStandaloneInput(l,c)}}}_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{...L(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??y,r=(l,u)=>I(l,u,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}}_appendStandaloneInput(e,t){if(!this._contentEl)return;const i={root:"root",elements:{root:{type:"TextInput",props:{placeholder:t}}}},o=this._renderUISpec(i,e);this._contentEl.appendChild(o)}_handleAction(e){s.trackSuggestedQuestion(e.title,e.type),this.config.onActionSelected?.(e),s.dispatch("gengage:qna:action",e)}_handleOpenChat(){const e=this._contentEl?.querySelector(".gengage-qna-input");e&&e.focus(),this.config.onOpenChat?.(),s.dispatch("gengage:qna:open-chat",{})}}function H(){return new v}exports.GengageQNA=v;exports.createDefaultQnaUISpecRegistry=E;exports.createQNAWidget=H;exports.defaultQnaUnknownUISpecRenderer=y;exports.qnaCatalog=O;exports.renderQnaUISpec=I;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./schemas-CaaT5BuE.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:l=>{const u=s.adaptBackendEvent(l);if(u&&(u.type==="ui_spec"&&o.uiSpecs.push(u.spec),u.type==="ui_spec"&&u.spec.elements)){for(const h of Object.values(u.spec.elements))if(h.type==="ActionButton"&&h.props?.action){const p=h.props.action;o.actions.push(p)}}}};return t!==void 0&&(c.signal=t),await s.consumeStream(a,c),o}function m(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??"Ask something else",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??"Ask a question..."];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??"Ask",c.setAttribute("aria-label",n.sendQuestionAriaLabel??"Send question");const l=()=>{const u=t.value.trim();u&&(n.onSubmit({title:u,type:"user_message",payload:u}),t.value="")};return c.addEventListener("click",l),t.addEventListener("keydown",u=>{u.key==="Enter"&&(u.preventDefault(),l())}),e.appendChild(t),e.appendChild(c),e._cleanup=()=>{r&&clearInterval(r),a&&clearTimeout(a)},e}function _(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=_(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,l=typeof c.label=="string"?c.label:void 0,u=_(c.action,l);u&&t.push(u)}if(n.children)for(const a of n.children){const c=e.elements[a];if(!c||c.type!=="ActionButton")continue;const l=typeof c.props?.label=="string"?c.props.label:void 0,u=_(c.props?.action,l);u&&t.push(u)}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),m(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),m(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=_(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:void 0,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},y=({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 I(n,e,t=C,i=y){return s.renderUISpecWithRegistry({spec:n,context:e,registry:t,containerClassName:"gengage-qna-uispec",unknownRenderer:i})}const S={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 x(n){return n?n.toLowerCase().split("-")[0]??"tr":"tr"}function L(n){return x(n)==="en"?Q:S}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()}),P=s.object({orientation:s._enum(["horizontal","vertical"]).optional(),wrap:s.boolean().optional()}),B=s.object({placeholder:s.union([s.string(),s.array(s.string())]).optional(),ctaLabel:s.string().optional()}),U=s.object({text:s.string()}),O={components:{ActionButton:{schema:N,description:"A single clickable QNA action button."},ButtonRow:{schema:P,description:"Container for a group of QNA action buttons."},TextInput:{schema:B,description:"Free-text input with rotating placeholder and CTA button."},QuestionHeading:{schema:U,description:"A heading displayed above the QNA button group."}}};class v extends s.BaseWidget{constructor(){super(...arguments),this._abortController=null,this._debounceTimer=null,this._contentEl=null,this._i18n=S,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)),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 l=await q(a,i,this._abortController.signal);if(this.track(s.streamDoneEvent(this.analyticsContext(),{request_id:o,latency_ms:Date.now()-r,chunk_count:l.actions.length,widget:"qna"})),this.track(s.widgetHistorySnapshotEvent(this.analyticsContext(),{message_count:l.actions.length,history_ref:o,redaction_level:"none",widget:"qna"})),!this._contentEl)return;if(this._contentEl.innerHTML="",!this._specIncludesType(l.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 h=this.config.inputPlaceholder;let p;if(h!==!0)p=h??this._i18n.defaultInputPlaceholder;else if(l.actions.length>0){const d=l.actions.filter(f=>f.type==="user_message"||f.title.includes("?")).map(f=>f.title);p=d.length>0?d:this._i18n.defaultInputPlaceholder}else p=this._i18n.defaultInputPlaceholder;const g={onAction:this._actionHandler,i18n:this._i18n};this.config.hideButtonRowCta||(g.onOpenChat=this._openChatHandler,this.config.ctaText!==void 0&&(g.ctaText=this.config.ctaText)),p!==void 0&&(g.inputPlaceholder=p);const k=this._buildFallbackActionsSpec(l.actions),b=(l.uiSpecs.length>0?l.uiSpecs:[k]).filter(d=>Object.keys(d.elements).length>0);for(const d of b){const f=this._renderUISpec(d,g);this._contentEl.appendChild(f)}b.length>0&&s.trackShow("qna"),!this._specIncludesType(b,"TextInput")&&this._appendStandaloneInput(g,p)}catch(a){if(a instanceof DOMException&&a.name==="AbortError")return;if(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"})),this._contentEl){this._cleanupTextInputTimers(),this._contentEl.innerHTML="";const c=this.config.inputPlaceholder===!0?this._i18n.defaultInputPlaceholder:this.config.inputPlaceholder??this._i18n.defaultInputPlaceholder,l={onAction:this._actionHandler,i18n:this._i18n,onOpenChat:this._openChatHandler};this.config.ctaText!==void 0&&(l.ctaText=this.config.ctaText),this._appendStandaloneInput(l,c)}}}_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{...L(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??y,r=(l,u)=>I(l,u,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}}_appendStandaloneInput(e,t){if(!this._contentEl)return;const i={root:"root",elements:{root:{type:"TextInput",props:{placeholder:t}}}},o=this._renderUISpec(i,e);this._contentEl.appendChild(o)}_handleAction(e){s.trackSuggestedQuestion(e.title,e.type),this.config.onActionSelected?.(e),s.dispatch("gengage:qna:action",e)}_handleOpenChat(){const e=this._contentEl?.querySelector(".gengage-qna-input");e&&e.focus(),this.config.onOpenChat?.(),s.dispatch("gengage:qna:open-chat",{})}}function H(){return new v}exports.GengageQNA=v;exports.createDefaultQnaUISpecRegistry=E;exports.createQNAWidget=H;exports.defaultQnaUnknownUISpecRenderer=y;exports.qnaCatalog=O;exports.renderQnaUISpec=I;
2
2
  //# sourceMappingURL=qna.cjs.map