@gengage/assistant-fe 0.3.20 → 0.3.22
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.
- package/README.md +18 -6
- package/dist/{chat-CuPO9t-Z.cjs → chat-BF5pt6iX.cjs} +5 -5
- package/dist/{chat-yAf9OADM.js → chat-CHAi6Xej.js} +476 -480
- package/dist/chat.cjs +1 -1
- package/dist/chat.iife.js +17 -17
- package/dist/chat.js +1 -1
- package/dist/common/client.d.ts +4 -0
- package/dist/common/config-schema.d.ts +4 -0
- package/dist/common/overlay.d.ts +4 -0
- package/dist/common/widget-base.d.ts +6 -0
- package/dist/{common-C8NRcP7O.js → common-Ct6r0F2s.js} +35 -26
- package/dist/common-DXdLT4e0.cjs +1 -0
- package/dist/common.cjs +1 -1
- package/dist/common.js +6 -6
- package/dist/{connection-warning-CVZzlGJt.js → connection-warning-CHHi3BAf.js} +1 -1
- package/dist/{connection-warning-CL1CReZo.cjs → connection-warning-YQiIRXrz.cjs} +1 -1
- package/dist/{ga-datalayer-DkfsAHf9.cjs → ga-datalayer-BVppFxqk.cjs} +1 -1
- package/dist/{ga-datalayer-CgI6Kb_i.js → ga-datalayer-BwxWX-cr.js} +35 -32
- package/dist/index.cjs +1 -1
- package/dist/index.js +9 -9
- package/dist/native-webview-BaW1H_nZ.cjs +1 -0
- package/dist/{native-webview-B8vOoxns.js → native-webview-Cf5WtlIH.js} +72 -69
- package/dist/native.cjs +1 -1
- package/dist/native.iife.js +11 -11
- package/dist/native.js +1 -1
- package/dist/{qna-YSaIDxjs.js → qna-DXCQtwLq.js} +3 -3
- package/dist/{qna-KizG_W1J.cjs → qna-DwG8AJJf.cjs} +1 -1
- package/dist/qna.cjs +1 -1
- package/dist/qna.iife.js +1 -1
- package/dist/qna.js +1 -1
- package/dist/{schemas-B6RjqKrg.cjs → schemas-B7jnyzQI.cjs} +1 -1
- package/dist/{schemas-PkedCk_-.js → schemas-CTbgsvNJ.js} +1 -1
- package/dist/simbut/index.d.ts +3 -0
- package/dist/{simbut-BI054QK0.js → simbut-BBXTlzOg.js} +28 -20
- package/dist/simbut-D_ycY_MQ.cjs +1 -0
- package/dist/simbut.cjs +1 -1
- package/dist/simbut.iife.js +8 -8
- package/dist/simbut.js +1 -1
- package/dist/{simrel-C-DKpfVB.js → simrel-DP2EMyua.js} +3 -3
- package/dist/{simrel-vL0woDkE.cjs → simrel-DdP4lur9.cjs} +1 -1
- package/dist/simrel.cjs +1 -1
- package/dist/simrel.iife.js +1 -1
- package/dist/simrel.js +1 -1
- package/package.json +1 -1
- package/dist/common-BzegEdJs.cjs +0 -1
- package/dist/native-webview-D2lDXTh3.cjs +0 -1
- package/dist/simbut-B2jXtckF.cjs +0 -1
package/dist/native.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { S as N, b as H, c as _, d as O, l as U, n as j, o as A, p as M, r as D, t as L, u as F, w as W } from "./schemas-
|
|
2
|
-
import { P as E, Q as z, S as $, X as G, Z, c as J, et as V, g as X, h as Y, y as K } from "./ga-datalayer-
|
|
3
|
-
import { n as tt } from "./connection-warning-
|
|
1
|
+
import { S as N, b as H, c as _, d as O, l as U, n as j, o as A, p as M, r as D, t as L, u as F, w as W } from "./schemas-CTbgsvNJ.js";
|
|
2
|
+
import { P as E, Q as z, S as $, X as G, Z, c as J, et as V, g as X, h as Y, y as K } from "./ga-datalayer-BwxWX-cr.js";
|
|
3
|
+
import { n as tt } from "./connection-warning-CHHi3BAf.js";
|
|
4
4
|
async function et(t, n, e) {
|
|
5
5
|
const o = O("launcher_action", n), i = {
|
|
6
6
|
uiSpecs: [],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const u=require("./schemas-B6RjqKrg.cjs"),y=require("./ga-datalayer-DkfsAHf9.cjs"),O=require("./connection-warning-CL1CReZo.cjs");async function H(t,n,e){const o=u.buildChatEndpointUrl("launcher_action",n),i={uiSpecs:[],actions:[]},a={method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)};e!==void 0&&(a.signal=e);const r=await fetch(o,a);if(!r.ok)throw new Error(`HTTP ${r.status}: ${r.statusText}`);const s={onEvent:c=>{const l=u.adaptBackendEvent(c);if(l&&(l.type==="ui_spec"&&i.uiSpecs.push(l.spec),l.type==="ui_spec"&&l.spec.elements)){for(const d of Object.values(l.spec.elements))if(d.type==="ActionButton"&&d.props?.action){const _=d.props.action;i.actions.push(_)}}}};return e!==void 0&&(s.signal=e),await u.consumeStream(r,s),i}function C(t){const n=document.createElement("div");n.className="gengage-qna-buttons gds-toolbar",n.dataset.gengagePart="qna-button-row",n.setAttribute("role","group"),n.setAttribute("aria-label",t.quickQuestionsAriaLabel??"Quick questions"),t.orientation==="vertical"&&(n.style.flexDirection="column");for(const e of t.actions){const o=document.createElement("button");o.className="gengage-qna-button gds-chip",o.dataset.gengagePart="qna-quick-question",o.textContent=e.title,o.type="button",o.addEventListener("click",()=>{const i={title:e.title,type:e.type};e.payload!==void 0&&(i.payload=e.payload),t.onAction(i)}),n.appendChild(o)}if(t.ctaText||t.onOpenChat){const e=document.createElement("button");e.className="gengage-qna-cta gds-btn gds-btn-secondary",e.dataset.gengagePart="qna-cta",e.textContent=t.ctaText??t.defaultCtaText??"Ask something else",e.type="button",e.addEventListener("click",()=>{t.onOpenChat?.()}),n.appendChild(e)}return n}function U(t){const n=document.createElement("div");n.className="gengage-qna-input-wrapper",n.dataset.gengagePart="qna-input-wrapper";const e=document.createElement("div");e.className="gengage-qna-input-combo",e.dataset.gengagePart="qna-input-combo";const o=document.createElement("input");o.type="text",o.className="gengage-qna-input",o.dataset.gengagePart="qna-input",o.setAttribute("aria-label",t.askQuestionAriaLabel??"Ask a question");const i=Array.isArray(t.placeholders)?t.placeholders:t.placeholders?[t.placeholders]:[t.defaultInputPlaceholder??"Ask a question..."];let a=0,r=i[0]??"";o.placeholder=r;let s=null,c=null,l=!1;const d=()=>{s&&clearInterval(s),s=null,c&&clearTimeout(c),c=null,o.classList.remove("gengage-qna-input--fade")},_=()=>i.length>1&&!l&&o.value.trim().length===0,b=()=>{d(),_()&&(s=setInterval(()=>{_()&&(o.classList.add("gengage-qna-input--fade"),c=setTimeout(()=>{a=(a+1)%i.length,r=i[a]??"",o.placeholder=r,o.classList.remove("gengage-qna-input--fade")},180))},3e3))},f=document.createElement("div");f.className="gengage-qna-input-actions",f.dataset.gengagePart="qna-input-actions";const g=document.createElement("button");g.className="gengage-qna-icon-btn gengage-qna-clear gengage-qna-icon-btn--hidden",g.type="button",g.dataset.gengagePart="qna-clear",g.setAttribute("aria-label","Clear question"),g.innerHTML='<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M18 6L6 18" /><path d="M6 6L18 18" /></svg>';const h=document.createElement("button");h.className="gengage-qna-icon-btn gengage-qna-send gengage-qna-icon-btn--hidden",h.type="button",h.dataset.gengagePart="qna-send",h.setAttribute("aria-label",t.sendQuestionAriaLabel??"Send question"),h.disabled=!0,h.innerHTML=`<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M22 2L11 13" /><path d="M22 2L15 22L11 13L2 9L22 2Z" /></svg><span class="gengage-qna-sr-only">${t.ctaLabel??t.sendButtonText??"Ask"}</span>`;const v=()=>{const p=o.value.trim().length>0;g.classList.toggle("gengage-qna-icon-btn--hidden",!p),h.classList.toggle("gengage-qna-icon-btn--hidden",!p),h.classList.toggle("gengage-qna-send--active",p),h.disabled=!p},q=()=>{const p=o.value.trim();p&&(t.onSubmit({title:p,type:"user_message",payload:p}),o.value="",v(),b())};return g.addEventListener("click",()=>{o.value="",v(),o.focus({preventScroll:!0})}),h.addEventListener("click",q),o.addEventListener("focus",()=>{l=!0,d(),o.placeholder=""}),o.addEventListener("blur",()=>{l=!1,o.value.trim().length===0&&(o.placeholder=r),b()}),o.addEventListener("input",()=>{if(v(),o.value.trim().length>0){d();return}o.placeholder=l?"":r,b()}),o.addEventListener("keydown",p=>{p.key==="Enter"&&(p.preventDefault(),q()),p.key==="Escape"&&o.value.length>0&&(o.value="",v(),b())}),f.appendChild(g),f.appendChild(h),e.appendChild(o),e.appendChild(f),n.appendChild(e),v(),b(),n._cleanup=()=>{d()},n}function T(t,n){if(!t||typeof t!="object")return null;const e=t,o=e.type;if(typeof o!="string"||o.length===0)return null;const i=e.title,a=e.payload,r=typeof i=="string"&&i.length>0?i:n;if(!r)return null;const s={title:r,type:o};return a!==void 0&&(s.payload=a),s}function S(t){const n={title:t.title,type:t.type};return t.payload!==void 0&&(n.payload=t.payload),n}function k(t,n){const e=[],o=t.props?.actions;if(Array.isArray(o))for(const r of o){const s=T(r);s&&e.push(s)}const i=t.props?.buttons;if(Array.isArray(i))for(const r of i){if(!r||typeof r!="object")continue;const s=r,c=typeof s.label=="string"?s.label:void 0,l=T(s.action,c);l&&e.push(l)}if(t.children)for(const r of t.children){const s=n.elements[r];if(!s||s.type!=="ActionButton")continue;const c=typeof s.props?.label=="string"?s.props.label:void 0,l=T(s.props?.action,c);l&&e.push(l)}const a=new Set;return e.filter(r=>a.has(r.title)?!1:(a.add(r.title),!0))}var L={ButtonRow:({element:t,spec:n,context:e})=>{const o=k(t,n).map(S),i=t.props?.orientation,a={actions:o,onAction:e.onAction,defaultCtaText:e.i18n.defaultCtaText,quickQuestionsAriaLabel:e.i18n.quickQuestionsAriaLabel};return e.onOpenChat!==void 0&&(a.onOpenChat=e.onOpenChat),e.ctaText!==void 0&&(a.ctaText=e.ctaText),(i==="horizontal"||i==="vertical")&&(a.orientation=i),C(a)},ActionButtons:({element:t,spec:n,context:e})=>{const o={actions:k(t,n).map(S),onAction:e.onAction,defaultCtaText:e.i18n.defaultCtaText,quickQuestionsAriaLabel:e.i18n.quickQuestionsAriaLabel};return e.onOpenChat!==void 0&&(o.onOpenChat=e.onOpenChat),e.ctaText!==void 0&&(o.ctaText=e.ctaText),C(o)},ActionButton:({element:t,context:n})=>{const e=document.createElement("button");e.className="gengage-qna-button gds-chip",e.type="button",e.dataset.gengagePart="qna-action-button";const o=t.props?.label;typeof o=="string"?e.textContent=o:e.textContent=n.i18n.defaultCtaText;const i=T(t.props?.action,typeof o=="string"?o:void 0);return i&&e.addEventListener("click",()=>n.onAction(i)),e},TextInput:({element:t,context:n})=>{const e=t.props?.placeholder,o=typeof e=="string"||Array.isArray(e)?e:n.inputPlaceholder,i=typeof t.props?.ctaLabel=="string"?t.props.ctaLabel:void 0,a={onSubmit:n.onAction,askQuestionAriaLabel:n.i18n.askQuestionAriaLabel,defaultInputPlaceholder:n.i18n.defaultInputPlaceholder,sendButtonText:n.i18n.sendButton,sendQuestionAriaLabel:n.i18n.sendQuestionAriaLabel};return o!==void 0&&(a.placeholders=o),i!==void 0&&(a.ctaLabel=i),U(a)},QuestionHeading:({element:t,context:n})=>{const e=document.createElement("h3");e.className="gengage-qna-heading",e.dataset.gengagePart="qna-heading";const o=t.props?.text,i=n.headingTitleOverride;return e.textContent=typeof i=="string"&&i.trim().length>0?i:typeof o=="string"?o:"",e},ProductCard:()=>null},E=({element:t,renderElement:n})=>{if(!t.children||t.children.length===0)return null;const e=document.createElement("div");for(const o of t.children){const i=n(o);i&&e.appendChild(i)}return e};function P(){return{...L}}function Q(t,n,e=L,o=E){return u.renderUISpecWithRegistry({spec:t,context:n,registry:e,containerClassName:"gengage-qna-uispec",unknownRenderer:o})}function j(t){if(!t)return;const n=t.extra;if(n&&typeof n=="object"&&!Array.isArray(n)){const o=n.visible_skus??n.visibleSkus;if(Array.isArray(o)){const i=o.filter(a=>typeof a=="string"&&a.trim().length>0).map(a=>a.trim()).slice(0,200);if(i.length>0)return i}}const e=typeof t.sku=="string"&&t.sku.trim()?t.sku.trim():void 0;return e?[e]:void 0}function B(t,n){if(!t)return null;const e=t.action;if(!e||typeof e!="object")return null;const o=e,i=o.type;if(typeof i!="string"||i.length===0)return null;const a=o.title,r=typeof a=="string"&&a.length>0?a:typeof n=="string"&&n.length>0?n:"";if(!r)return null;const s=o.payload,c={title:r,type:i};return s!==void 0&&(c.payload=s),c}function M(t,n){const e=t.elements[t.root];if(!e)return!1;const o=i=>{if(i.type!=="ActionButton")return!1;const a=i.props;if(!a||typeof a!="object")return!1;const r=typeof a.label=="string"?a.label:void 0;return r===n?!0:B(a,r)?.title===n};if(e.type==="ActionButton")return o(e);if(e.children)for(const i of e.children){const a=t.elements[i];if(a&&o(a))return!0}if(e.type==="ActionButtons"&&Array.isArray(e.props?.buttons)){for(const i of e.props.buttons)if(i?.label===n||i?.action?.title===n)return!0}return!1}var I=0;function x(){return I+=1,`gengage-merge-${I}`}function D(t,n){const e=t.elements[t.root];if(!e||e.type!=="ButtonRow")return;const o=x();t.elements[o]={type:"ActionButton",props:{label:n.title,action:{title:n.title,type:n.type,...n.payload!==void 0?{payload:n.payload}:{}}}},e.children=e.children?[o,...e.children]:[o]}function F(t,n){const e=t.elements[t.root];if(!e||e.type!=="ActionButtons")return;const o=x();t.elements[o]={type:"ActionButton",props:{label:n.title,action:{title:n.title,type:n.type,...n.payload!==void 0?{payload:n.payload}:{}}}},e.children=e.children?[o,...e.children]:[o];const i=e.props?.buttons??[],a={label:n.title,action:{title:n.title,type:n.type,...n.payload!==void 0?{payload:n.payload}:{}}};e.props={...e.props,buttons:[a,...i]}}function W(t){const n={},e=[];for(let o=0;o<t.length;o++){const i=t[o],a=`action-${o}`;e.push(a),n[a]={type:"ActionButton",props:{label:i.title,action:{title:i.title,type:i.type,...i.payload!==void 0?{payload:i.payload}:{}}}}}return n.root={type:"ButtonRow",children:e},{root:"root",elements:n}}function z(t){return t.find(n=>{const e=n.elements[n.root];return e?.type==="ActionButtons"||e?.type==="ButtonRow"})}function w(t,n){const e=t.productContextQuickPillLabel,o={text:e};return n&&n.length>0&&(o.sku_list=n),{title:e,type:"user_message",payload:o}}function $(t,n,e){const o=e?.skuList,i=[],a=[];for(const c of t){const l=c.elements[c.root];if(l?.type==="ActionButton"){const d=l.props;if(B(d,typeof d?.label=="string"?d.label:void 0)?.type==="findSimilar"){i.push(w(n,o));continue}}a.push(c)}if(i.length===0)return t;const r=w(n,o),s=z(a);if(!s)return[...a,W([r])];if(!M(s,r.title)){const c=s.elements[s.root];c?.type==="ActionButtons"?F(s,r):c?.type==="ButtonRow"&&D(s,r)}return a}var R={quickQuestionsAriaLabel:"Hızlı sorular",askQuestionAriaLabel:"Soru sorun",defaultInputPlaceholder:"Bir soru sorun...",sendButton:"Sor",sendQuestionAriaLabel:"Soruyu gönder",defaultCtaText:"Başka bir şey sor",redirectingToChat:"Sohbete yönlendiriliyor...",productContextQuickPillLabel:"Bu ürün hakkında ne bilmeliyim?"},G={quickQuestionsAriaLabel:"Quick questions",askQuestionAriaLabel:"Ask a question",defaultInputPlaceholder:"Ask a question...",sendButton:"Ask",sendQuestionAriaLabel:"Send question",defaultCtaText:"Ask something else",redirectingToChat:"Redirecting to chat...",productContextQuickPillLabel:"What should I know about this product?"};function J(t){return t?t.toLowerCase().split("-")[0]??"tr":"tr"}function V(t){return J(t)==="en"?G:R}var Y=u.object({title:u.string(),type:u.string(),payload:u.unknown().optional()}),Z=u.object({label:u.string(),action:Y,variant:u._enum(["primary","outline","ghost"]).optional()}),K=u.object({orientation:u._enum(["horizontal","vertical"]).optional(),wrap:u.boolean().optional()}),X=u.object({placeholder:u.union([u.string(),u.array(u.string())]).optional(),ctaLabel:u.string().optional()}),tt=u.object({text:u.string()}),et={components:{ActionButton:{schema:Z,description:"A single clickable QNA action button."},ButtonRow:{schema:K,description:"Container for a group of QNA action buttons."},TextInput:{schema:X,description:"Free-text input with rotating placeholder and CTA button."},QuestionHeading:{schema:tt,description:"A heading displayed above the QNA button group."}}},N=class extends y.BaseWidget{constructor(...t){super(...t),this._abortController=null,this._debounceTimer=null,this._contentEl=null,this._i18n=R,this._actionHandler=this._handleAction.bind(this),this._openChatHandler=this._handleOpenChat.bind(this)}async onInit(t){this._i18n=this._resolveI18n(t),this._contentEl=document.createElement("div"),this._contentEl.className="gengage-qna-container",this._contentEl.dataset.gengagePart="qna-container",this.root.appendChild(this._contentEl);const n=t.pageContext?.sku;n&&(this._lastSku=n,await this._fetchAndRender(n)),y.trackInit("qna")}onUpdate(t){const n=t.sku;!n||n===this._lastSku||(this._debounceTimer&&clearTimeout(this._debounceTimer),this._debounceTimer=setTimeout(()=>{this._debounceTimer=null,this._lastSku=n,this._fetchAndRender(n)},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}_resolvedQnaHeaderTitle(){const t=this.config.headerTitle??this.config.headingTitle;if(typeof t!="string")return;const n=t.trim();return n.length>0?n:void 0}_cleanupTextInputTimers(){if(!this._contentEl)return;const t=this._contentEl.querySelectorAll(".gengage-qna-input-wrapper");for(const n of t)n._cleanup?.()}async _fetchAndRender(t){if(this._abort(),this._abortController=new AbortController,!this._contentEl)return;this._cleanupTextInputTimers(),this._contentEl.innerHTML="";const n=this._createLoadingIndicator();this._contentEl.appendChild(n);const e={middlewareUrl:this.config.middlewareUrl},o=crypto.randomUUID(),i=Date.now(),a=O.trackConnectionWarningRequest({source:"qna",locale:this.config.locale});this.track(y.streamStartEvent(this.analyticsContext(),{endpoint:"launcher_action",request_id:o,widget:"qna"}));try{const r={account_id:this.config.accountId,session_id:this.config.session?.sessionId??"",correlation_id:this.config.session?.sessionId??"",sku:t,locale:this.config.locale??"tr"},s=this.config.pageContext?.pageType;s!==void 0&&(r.page_type=s);const c=await H(r,e,this._abortController.signal);if(this.track(y.streamDoneEvent(this.analyticsContext(),{request_id:o,latency_ms:Date.now()-i,chunk_count:c.actions.length,widget:"qna"})),this.track(y.widgetHistorySnapshotEvent(this.analyticsContext(),{message_count:c.actions.length,history_ref:o,redaction_level:"none",widget:"qna"})),!this._contentEl)return;this._contentEl.innerHTML="";const l=document.createElement("div");l.className="gengage-qna-panel gds-panel",l.dataset.gengagePart="qna-panel",this._contentEl.appendChild(l);const d=this._specIncludesType(c.uiSpecs,"QuestionHeading"),_=this._resolvedQnaHeaderTitle()??(this.config.showStaticQuestion&&this.config.staticQuestionText?this.config.staticQuestionText:void 0);if(!d&&_){const m=document.createElement("h3");m.className="gengage-qna-heading",m.textContent=_,l.appendChild(m)}const b=this.config.inputPlaceholder;let f;if(b!==!0)f=b??this._i18n.defaultInputPlaceholder;else if(c.actions.length>0){const m=c.actions.filter(A=>A.type==="user_message"||A.title.includes("?")).map(A=>A.title);f=m.length>0?m:this._i18n.defaultInputPlaceholder}else f=this._i18n.defaultInputPlaceholder;const g={onAction:this._actionHandler,i18n:this._i18n},h=this._resolvedQnaHeaderTitle();h!==void 0&&(g.headingTitleOverride=h),this.config.hideButtonRowCta||(g.onOpenChat=this._openChatHandler,this.config.ctaText!==void 0&&(g.ctaText=this.config.ctaText)),f!==void 0&&(g.inputPlaceholder=f);const v=this._buildFallbackActionsSpec(c.actions),q=j(this.config.pageContext),p=(c.uiSpecs.length>0?$(c.uiSpecs,this._i18n,{skuList:q}):[v]).filter(m=>Object.keys(m.elements).length>0);for(const m of p){const A=this._renderUISpec(m,g);l.appendChild(A)}p.length>0&&y.trackShow("qna"),this._specIncludesType(p,"TextInput")||this._insertStandaloneInputBeforePills(l,g,f)}catch(r){if(r instanceof DOMException&&r.name==="AbortError")return;if(y.dispatch("gengage:global:error",{source:"qna",code:"FETCH_ERROR",message:y.getGlobalErrorMessage(this.config.locale,r)}),this.track(y.streamErrorEvent(this.analyticsContext(),{request_id:o,error_code:"FETCH_ERROR",error_message:r instanceof Error?r.message:String(r),widget:"qna"})),this._contentEl){this._cleanupTextInputTimers(),this._contentEl.innerHTML="";const s=document.createElement("div");s.className="gengage-qna-panel",this._contentEl.appendChild(s);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},d=this._resolvedQnaHeaderTitle();d!==void 0&&(l.headingTitleOverride=d),this.config.ctaText!==void 0&&(l.ctaText=this.config.ctaText),this._appendStandaloneInput(l,c,s)}}finally{a()}}_createLoadingIndicator(){const t=document.createElement("div");t.className="gengage-qna-loading";for(let n=0;n<3;n++){const e=document.createElement("div");e.className="gengage-qna-loading-dot",t.appendChild(e)}return t}_resolveI18n(t){return{...V(t.locale),...t.i18n}}_resolveUISpecRegistry(){return u.mergeUISpecRegistry(P(),this.config.renderer?.registry)}_renderUISpec(t,n){const e=this._resolveUISpecRegistry(),o=this.config.renderer?.unknownRenderer??E,i=(r,s)=>Q(r,s,e,o),a=this.config.renderer?.renderUISpec;return a?a(t,n,{registry:e,unknownRenderer:o,defaultRender:i}):i(t,n)}_specIncludesType(t,n){for(const e of t)for(const o of Object.values(e.elements))if(o.type===n)return!0;return!1}_buildFallbackActionsSpec(t){if(t.length===0)return{root:"root",elements:{}};const n={},e=[];for(let o=0;o<t.length;o++){const i=t[o],a=`action-${o}`;e.push(a),n[a]={type:"ActionButton",props:{label:i.title,action:{title:i.title,type:i.type,payload:i.payload}}}}return n.root={type:"ButtonRow",children:e},{root:"root",elements:n}}_insertStandaloneInputBeforePills(t,n,e){const o={root:"root",elements:{root:{type:"TextInput",props:{placeholder:e}}}},i=this._renderUISpec(o,n),a=i.querySelector(".gengage-qna-input-wrapper");if(!a)return;const r=t.querySelector(".gengage-qna-uispec"),s=r?.querySelector(":scope > .gengage-qna-buttons");if(r&&s)r.insertBefore(a,s);else if(r){const c=r.querySelector(":scope > .gengage-qna-heading");c?c.insertAdjacentElement("afterend",a):r.prepend(a)}else{t.appendChild(i);return}i.remove()}_appendStandaloneInput(t,n,e){if(!this._contentEl)return;const o={root:"root",elements:{root:{type:"TextInput",props:{placeholder:n}}}},i=this._renderUISpec(o,t);(e??this._contentEl).appendChild(i)}_handleAction(t){this._showTransitionIndicator(),y.trackSuggestedQuestion(t.title,t.type),this.config.onActionSelected?.(t),setTimeout(()=>y.dispatch("gengage:qna:action",t),350)}_handleOpenChat(){this._showTransitionIndicator(),this.config.onOpenChat?.(),setTimeout(()=>y.dispatch("gengage:qna:open-chat",{}),350)}_showTransitionIndicator(){if(!this._contentEl)return;this._contentEl.querySelector(".gengage-qna-transition-indicator")?.remove(),this._contentEl.classList.add("gengage-qna--transitioning");const t=this._i18n.redirectingToChat??"Redirecting to chat...",n=document.createElement("div");n.className="gengage-qna-transition-indicator",n.textContent=t,(this._contentEl.querySelector(".gengage-qna-panel")??this._contentEl).appendChild(n),setTimeout(()=>{this._contentEl?.classList.remove("gengage-qna--transitioning"),n.remove()},600)}};function nt(){return new N}Object.defineProperty(exports,"GengageQNA",{enumerable:!0,get:function(){return N}});Object.defineProperty(exports,"createDefaultQnaUISpecRegistry",{enumerable:!0,get:function(){return P}});Object.defineProperty(exports,"createQNAWidget",{enumerable:!0,get:function(){return nt}});Object.defineProperty(exports,"defaultQnaUnknownUISpecRenderer",{enumerable:!0,get:function(){return E}});Object.defineProperty(exports,"qnaCatalog",{enumerable:!0,get:function(){return et}});Object.defineProperty(exports,"renderQnaUISpec",{enumerable:!0,get:function(){return Q}});
|
|
1
|
+
const u=require("./schemas-B7jnyzQI.cjs"),y=require("./ga-datalayer-BVppFxqk.cjs"),O=require("./connection-warning-YQiIRXrz.cjs");async function H(t,n,e){const o=u.buildChatEndpointUrl("launcher_action",n),i={uiSpecs:[],actions:[]},a={method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)};e!==void 0&&(a.signal=e);const r=await fetch(o,a);if(!r.ok)throw new Error(`HTTP ${r.status}: ${r.statusText}`);const s={onEvent:c=>{const l=u.adaptBackendEvent(c);if(l&&(l.type==="ui_spec"&&i.uiSpecs.push(l.spec),l.type==="ui_spec"&&l.spec.elements)){for(const d of Object.values(l.spec.elements))if(d.type==="ActionButton"&&d.props?.action){const _=d.props.action;i.actions.push(_)}}}};return e!==void 0&&(s.signal=e),await u.consumeStream(r,s),i}function C(t){const n=document.createElement("div");n.className="gengage-qna-buttons gds-toolbar",n.dataset.gengagePart="qna-button-row",n.setAttribute("role","group"),n.setAttribute("aria-label",t.quickQuestionsAriaLabel??"Quick questions"),t.orientation==="vertical"&&(n.style.flexDirection="column");for(const e of t.actions){const o=document.createElement("button");o.className="gengage-qna-button gds-chip",o.dataset.gengagePart="qna-quick-question",o.textContent=e.title,o.type="button",o.addEventListener("click",()=>{const i={title:e.title,type:e.type};e.payload!==void 0&&(i.payload=e.payload),t.onAction(i)}),n.appendChild(o)}if(t.ctaText||t.onOpenChat){const e=document.createElement("button");e.className="gengage-qna-cta gds-btn gds-btn-secondary",e.dataset.gengagePart="qna-cta",e.textContent=t.ctaText??t.defaultCtaText??"Ask something else",e.type="button",e.addEventListener("click",()=>{t.onOpenChat?.()}),n.appendChild(e)}return n}function U(t){const n=document.createElement("div");n.className="gengage-qna-input-wrapper",n.dataset.gengagePart="qna-input-wrapper";const e=document.createElement("div");e.className="gengage-qna-input-combo",e.dataset.gengagePart="qna-input-combo";const o=document.createElement("input");o.type="text",o.className="gengage-qna-input",o.dataset.gengagePart="qna-input",o.setAttribute("aria-label",t.askQuestionAriaLabel??"Ask a question");const i=Array.isArray(t.placeholders)?t.placeholders:t.placeholders?[t.placeholders]:[t.defaultInputPlaceholder??"Ask a question..."];let a=0,r=i[0]??"";o.placeholder=r;let s=null,c=null,l=!1;const d=()=>{s&&clearInterval(s),s=null,c&&clearTimeout(c),c=null,o.classList.remove("gengage-qna-input--fade")},_=()=>i.length>1&&!l&&o.value.trim().length===0,b=()=>{d(),_()&&(s=setInterval(()=>{_()&&(o.classList.add("gengage-qna-input--fade"),c=setTimeout(()=>{a=(a+1)%i.length,r=i[a]??"",o.placeholder=r,o.classList.remove("gengage-qna-input--fade")},180))},3e3))},f=document.createElement("div");f.className="gengage-qna-input-actions",f.dataset.gengagePart="qna-input-actions";const g=document.createElement("button");g.className="gengage-qna-icon-btn gengage-qna-clear gengage-qna-icon-btn--hidden",g.type="button",g.dataset.gengagePart="qna-clear",g.setAttribute("aria-label","Clear question"),g.innerHTML='<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M18 6L6 18" /><path d="M6 6L18 18" /></svg>';const h=document.createElement("button");h.className="gengage-qna-icon-btn gengage-qna-send gengage-qna-icon-btn--hidden",h.type="button",h.dataset.gengagePart="qna-send",h.setAttribute("aria-label",t.sendQuestionAriaLabel??"Send question"),h.disabled=!0,h.innerHTML=`<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M22 2L11 13" /><path d="M22 2L15 22L11 13L2 9L22 2Z" /></svg><span class="gengage-qna-sr-only">${t.ctaLabel??t.sendButtonText??"Ask"}</span>`;const v=()=>{const p=o.value.trim().length>0;g.classList.toggle("gengage-qna-icon-btn--hidden",!p),h.classList.toggle("gengage-qna-icon-btn--hidden",!p),h.classList.toggle("gengage-qna-send--active",p),h.disabled=!p},q=()=>{const p=o.value.trim();p&&(t.onSubmit({title:p,type:"user_message",payload:p}),o.value="",v(),b())};return g.addEventListener("click",()=>{o.value="",v(),o.focus({preventScroll:!0})}),h.addEventListener("click",q),o.addEventListener("focus",()=>{l=!0,d(),o.placeholder=""}),o.addEventListener("blur",()=>{l=!1,o.value.trim().length===0&&(o.placeholder=r),b()}),o.addEventListener("input",()=>{if(v(),o.value.trim().length>0){d();return}o.placeholder=l?"":r,b()}),o.addEventListener("keydown",p=>{p.key==="Enter"&&(p.preventDefault(),q()),p.key==="Escape"&&o.value.length>0&&(o.value="",v(),b())}),f.appendChild(g),f.appendChild(h),e.appendChild(o),e.appendChild(f),n.appendChild(e),v(),b(),n._cleanup=()=>{d()},n}function T(t,n){if(!t||typeof t!="object")return null;const e=t,o=e.type;if(typeof o!="string"||o.length===0)return null;const i=e.title,a=e.payload,r=typeof i=="string"&&i.length>0?i:n;if(!r)return null;const s={title:r,type:o};return a!==void 0&&(s.payload=a),s}function S(t){const n={title:t.title,type:t.type};return t.payload!==void 0&&(n.payload=t.payload),n}function k(t,n){const e=[],o=t.props?.actions;if(Array.isArray(o))for(const r of o){const s=T(r);s&&e.push(s)}const i=t.props?.buttons;if(Array.isArray(i))for(const r of i){if(!r||typeof r!="object")continue;const s=r,c=typeof s.label=="string"?s.label:void 0,l=T(s.action,c);l&&e.push(l)}if(t.children)for(const r of t.children){const s=n.elements[r];if(!s||s.type!=="ActionButton")continue;const c=typeof s.props?.label=="string"?s.props.label:void 0,l=T(s.props?.action,c);l&&e.push(l)}const a=new Set;return e.filter(r=>a.has(r.title)?!1:(a.add(r.title),!0))}var L={ButtonRow:({element:t,spec:n,context:e})=>{const o=k(t,n).map(S),i=t.props?.orientation,a={actions:o,onAction:e.onAction,defaultCtaText:e.i18n.defaultCtaText,quickQuestionsAriaLabel:e.i18n.quickQuestionsAriaLabel};return e.onOpenChat!==void 0&&(a.onOpenChat=e.onOpenChat),e.ctaText!==void 0&&(a.ctaText=e.ctaText),(i==="horizontal"||i==="vertical")&&(a.orientation=i),C(a)},ActionButtons:({element:t,spec:n,context:e})=>{const o={actions:k(t,n).map(S),onAction:e.onAction,defaultCtaText:e.i18n.defaultCtaText,quickQuestionsAriaLabel:e.i18n.quickQuestionsAriaLabel};return e.onOpenChat!==void 0&&(o.onOpenChat=e.onOpenChat),e.ctaText!==void 0&&(o.ctaText=e.ctaText),C(o)},ActionButton:({element:t,context:n})=>{const e=document.createElement("button");e.className="gengage-qna-button gds-chip",e.type="button",e.dataset.gengagePart="qna-action-button";const o=t.props?.label;typeof o=="string"?e.textContent=o:e.textContent=n.i18n.defaultCtaText;const i=T(t.props?.action,typeof o=="string"?o:void 0);return i&&e.addEventListener("click",()=>n.onAction(i)),e},TextInput:({element:t,context:n})=>{const e=t.props?.placeholder,o=typeof e=="string"||Array.isArray(e)?e:n.inputPlaceholder,i=typeof t.props?.ctaLabel=="string"?t.props.ctaLabel:void 0,a={onSubmit:n.onAction,askQuestionAriaLabel:n.i18n.askQuestionAriaLabel,defaultInputPlaceholder:n.i18n.defaultInputPlaceholder,sendButtonText:n.i18n.sendButton,sendQuestionAriaLabel:n.i18n.sendQuestionAriaLabel};return o!==void 0&&(a.placeholders=o),i!==void 0&&(a.ctaLabel=i),U(a)},QuestionHeading:({element:t,context:n})=>{const e=document.createElement("h3");e.className="gengage-qna-heading",e.dataset.gengagePart="qna-heading";const o=t.props?.text,i=n.headingTitleOverride;return e.textContent=typeof i=="string"&&i.trim().length>0?i:typeof o=="string"?o:"",e},ProductCard:()=>null},E=({element:t,renderElement:n})=>{if(!t.children||t.children.length===0)return null;const e=document.createElement("div");for(const o of t.children){const i=n(o);i&&e.appendChild(i)}return e};function P(){return{...L}}function Q(t,n,e=L,o=E){return u.renderUISpecWithRegistry({spec:t,context:n,registry:e,containerClassName:"gengage-qna-uispec",unknownRenderer:o})}function j(t){if(!t)return;const n=t.extra;if(n&&typeof n=="object"&&!Array.isArray(n)){const o=n.visible_skus??n.visibleSkus;if(Array.isArray(o)){const i=o.filter(a=>typeof a=="string"&&a.trim().length>0).map(a=>a.trim()).slice(0,200);if(i.length>0)return i}}const e=typeof t.sku=="string"&&t.sku.trim()?t.sku.trim():void 0;return e?[e]:void 0}function B(t,n){if(!t)return null;const e=t.action;if(!e||typeof e!="object")return null;const o=e,i=o.type;if(typeof i!="string"||i.length===0)return null;const a=o.title,r=typeof a=="string"&&a.length>0?a:typeof n=="string"&&n.length>0?n:"";if(!r)return null;const s=o.payload,c={title:r,type:i};return s!==void 0&&(c.payload=s),c}function M(t,n){const e=t.elements[t.root];if(!e)return!1;const o=i=>{if(i.type!=="ActionButton")return!1;const a=i.props;if(!a||typeof a!="object")return!1;const r=typeof a.label=="string"?a.label:void 0;return r===n?!0:B(a,r)?.title===n};if(e.type==="ActionButton")return o(e);if(e.children)for(const i of e.children){const a=t.elements[i];if(a&&o(a))return!0}if(e.type==="ActionButtons"&&Array.isArray(e.props?.buttons)){for(const i of e.props.buttons)if(i?.label===n||i?.action?.title===n)return!0}return!1}var I=0;function x(){return I+=1,`gengage-merge-${I}`}function D(t,n){const e=t.elements[t.root];if(!e||e.type!=="ButtonRow")return;const o=x();t.elements[o]={type:"ActionButton",props:{label:n.title,action:{title:n.title,type:n.type,...n.payload!==void 0?{payload:n.payload}:{}}}},e.children=e.children?[o,...e.children]:[o]}function F(t,n){const e=t.elements[t.root];if(!e||e.type!=="ActionButtons")return;const o=x();t.elements[o]={type:"ActionButton",props:{label:n.title,action:{title:n.title,type:n.type,...n.payload!==void 0?{payload:n.payload}:{}}}},e.children=e.children?[o,...e.children]:[o];const i=e.props?.buttons??[],a={label:n.title,action:{title:n.title,type:n.type,...n.payload!==void 0?{payload:n.payload}:{}}};e.props={...e.props,buttons:[a,...i]}}function W(t){const n={},e=[];for(let o=0;o<t.length;o++){const i=t[o],a=`action-${o}`;e.push(a),n[a]={type:"ActionButton",props:{label:i.title,action:{title:i.title,type:i.type,...i.payload!==void 0?{payload:i.payload}:{}}}}}return n.root={type:"ButtonRow",children:e},{root:"root",elements:n}}function z(t){return t.find(n=>{const e=n.elements[n.root];return e?.type==="ActionButtons"||e?.type==="ButtonRow"})}function w(t,n){const e=t.productContextQuickPillLabel,o={text:e};return n&&n.length>0&&(o.sku_list=n),{title:e,type:"user_message",payload:o}}function $(t,n,e){const o=e?.skuList,i=[],a=[];for(const c of t){const l=c.elements[c.root];if(l?.type==="ActionButton"){const d=l.props;if(B(d,typeof d?.label=="string"?d.label:void 0)?.type==="findSimilar"){i.push(w(n,o));continue}}a.push(c)}if(i.length===0)return t;const r=w(n,o),s=z(a);if(!s)return[...a,W([r])];if(!M(s,r.title)){const c=s.elements[s.root];c?.type==="ActionButtons"?F(s,r):c?.type==="ButtonRow"&&D(s,r)}return a}var R={quickQuestionsAriaLabel:"Hızlı sorular",askQuestionAriaLabel:"Soru sorun",defaultInputPlaceholder:"Bir soru sorun...",sendButton:"Sor",sendQuestionAriaLabel:"Soruyu gönder",defaultCtaText:"Başka bir şey sor",redirectingToChat:"Sohbete yönlendiriliyor...",productContextQuickPillLabel:"Bu ürün hakkında ne bilmeliyim?"},G={quickQuestionsAriaLabel:"Quick questions",askQuestionAriaLabel:"Ask a question",defaultInputPlaceholder:"Ask a question...",sendButton:"Ask",sendQuestionAriaLabel:"Send question",defaultCtaText:"Ask something else",redirectingToChat:"Redirecting to chat...",productContextQuickPillLabel:"What should I know about this product?"};function J(t){return t?t.toLowerCase().split("-")[0]??"tr":"tr"}function V(t){return J(t)==="en"?G:R}var Y=u.object({title:u.string(),type:u.string(),payload:u.unknown().optional()}),Z=u.object({label:u.string(),action:Y,variant:u._enum(["primary","outline","ghost"]).optional()}),K=u.object({orientation:u._enum(["horizontal","vertical"]).optional(),wrap:u.boolean().optional()}),X=u.object({placeholder:u.union([u.string(),u.array(u.string())]).optional(),ctaLabel:u.string().optional()}),tt=u.object({text:u.string()}),et={components:{ActionButton:{schema:Z,description:"A single clickable QNA action button."},ButtonRow:{schema:K,description:"Container for a group of QNA action buttons."},TextInput:{schema:X,description:"Free-text input with rotating placeholder and CTA button."},QuestionHeading:{schema:tt,description:"A heading displayed above the QNA button group."}}},N=class extends y.BaseWidget{constructor(...t){super(...t),this._abortController=null,this._debounceTimer=null,this._contentEl=null,this._i18n=R,this._actionHandler=this._handleAction.bind(this),this._openChatHandler=this._handleOpenChat.bind(this)}async onInit(t){this._i18n=this._resolveI18n(t),this._contentEl=document.createElement("div"),this._contentEl.className="gengage-qna-container",this._contentEl.dataset.gengagePart="qna-container",this.root.appendChild(this._contentEl);const n=t.pageContext?.sku;n&&(this._lastSku=n,await this._fetchAndRender(n)),y.trackInit("qna")}onUpdate(t){const n=t.sku;!n||n===this._lastSku||(this._debounceTimer&&clearTimeout(this._debounceTimer),this._debounceTimer=setTimeout(()=>{this._debounceTimer=null,this._lastSku=n,this._fetchAndRender(n)},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}_resolvedQnaHeaderTitle(){const t=this.config.headerTitle??this.config.headingTitle;if(typeof t!="string")return;const n=t.trim();return n.length>0?n:void 0}_cleanupTextInputTimers(){if(!this._contentEl)return;const t=this._contentEl.querySelectorAll(".gengage-qna-input-wrapper");for(const n of t)n._cleanup?.()}async _fetchAndRender(t){if(this._abort(),this._abortController=new AbortController,!this._contentEl)return;this._cleanupTextInputTimers(),this._contentEl.innerHTML="";const n=this._createLoadingIndicator();this._contentEl.appendChild(n);const e={middlewareUrl:this.config.middlewareUrl},o=crypto.randomUUID(),i=Date.now(),a=O.trackConnectionWarningRequest({source:"qna",locale:this.config.locale});this.track(y.streamStartEvent(this.analyticsContext(),{endpoint:"launcher_action",request_id:o,widget:"qna"}));try{const r={account_id:this.config.accountId,session_id:this.config.session?.sessionId??"",correlation_id:this.config.session?.sessionId??"",sku:t,locale:this.config.locale??"tr"},s=this.config.pageContext?.pageType;s!==void 0&&(r.page_type=s);const c=await H(r,e,this._abortController.signal);if(this.track(y.streamDoneEvent(this.analyticsContext(),{request_id:o,latency_ms:Date.now()-i,chunk_count:c.actions.length,widget:"qna"})),this.track(y.widgetHistorySnapshotEvent(this.analyticsContext(),{message_count:c.actions.length,history_ref:o,redaction_level:"none",widget:"qna"})),!this._contentEl)return;this._contentEl.innerHTML="";const l=document.createElement("div");l.className="gengage-qna-panel gds-panel",l.dataset.gengagePart="qna-panel",this._contentEl.appendChild(l);const d=this._specIncludesType(c.uiSpecs,"QuestionHeading"),_=this._resolvedQnaHeaderTitle()??(this.config.showStaticQuestion&&this.config.staticQuestionText?this.config.staticQuestionText:void 0);if(!d&&_){const m=document.createElement("h3");m.className="gengage-qna-heading",m.textContent=_,l.appendChild(m)}const b=this.config.inputPlaceholder;let f;if(b!==!0)f=b??this._i18n.defaultInputPlaceholder;else if(c.actions.length>0){const m=c.actions.filter(A=>A.type==="user_message"||A.title.includes("?")).map(A=>A.title);f=m.length>0?m:this._i18n.defaultInputPlaceholder}else f=this._i18n.defaultInputPlaceholder;const g={onAction:this._actionHandler,i18n:this._i18n},h=this._resolvedQnaHeaderTitle();h!==void 0&&(g.headingTitleOverride=h),this.config.hideButtonRowCta||(g.onOpenChat=this._openChatHandler,this.config.ctaText!==void 0&&(g.ctaText=this.config.ctaText)),f!==void 0&&(g.inputPlaceholder=f);const v=this._buildFallbackActionsSpec(c.actions),q=j(this.config.pageContext),p=(c.uiSpecs.length>0?$(c.uiSpecs,this._i18n,{skuList:q}):[v]).filter(m=>Object.keys(m.elements).length>0);for(const m of p){const A=this._renderUISpec(m,g);l.appendChild(A)}p.length>0&&y.trackShow("qna"),this._specIncludesType(p,"TextInput")||this._insertStandaloneInputBeforePills(l,g,f)}catch(r){if(r instanceof DOMException&&r.name==="AbortError")return;if(y.dispatch("gengage:global:error",{source:"qna",code:"FETCH_ERROR",message:y.getGlobalErrorMessage(this.config.locale,r)}),this.track(y.streamErrorEvent(this.analyticsContext(),{request_id:o,error_code:"FETCH_ERROR",error_message:r instanceof Error?r.message:String(r),widget:"qna"})),this._contentEl){this._cleanupTextInputTimers(),this._contentEl.innerHTML="";const s=document.createElement("div");s.className="gengage-qna-panel",this._contentEl.appendChild(s);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},d=this._resolvedQnaHeaderTitle();d!==void 0&&(l.headingTitleOverride=d),this.config.ctaText!==void 0&&(l.ctaText=this.config.ctaText),this._appendStandaloneInput(l,c,s)}}finally{a()}}_createLoadingIndicator(){const t=document.createElement("div");t.className="gengage-qna-loading";for(let n=0;n<3;n++){const e=document.createElement("div");e.className="gengage-qna-loading-dot",t.appendChild(e)}return t}_resolveI18n(t){return{...V(t.locale),...t.i18n}}_resolveUISpecRegistry(){return u.mergeUISpecRegistry(P(),this.config.renderer?.registry)}_renderUISpec(t,n){const e=this._resolveUISpecRegistry(),o=this.config.renderer?.unknownRenderer??E,i=(r,s)=>Q(r,s,e,o),a=this.config.renderer?.renderUISpec;return a?a(t,n,{registry:e,unknownRenderer:o,defaultRender:i}):i(t,n)}_specIncludesType(t,n){for(const e of t)for(const o of Object.values(e.elements))if(o.type===n)return!0;return!1}_buildFallbackActionsSpec(t){if(t.length===0)return{root:"root",elements:{}};const n={},e=[];for(let o=0;o<t.length;o++){const i=t[o],a=`action-${o}`;e.push(a),n[a]={type:"ActionButton",props:{label:i.title,action:{title:i.title,type:i.type,payload:i.payload}}}}return n.root={type:"ButtonRow",children:e},{root:"root",elements:n}}_insertStandaloneInputBeforePills(t,n,e){const o={root:"root",elements:{root:{type:"TextInput",props:{placeholder:e}}}},i=this._renderUISpec(o,n),a=i.querySelector(".gengage-qna-input-wrapper");if(!a)return;const r=t.querySelector(".gengage-qna-uispec"),s=r?.querySelector(":scope > .gengage-qna-buttons");if(r&&s)r.insertBefore(a,s);else if(r){const c=r.querySelector(":scope > .gengage-qna-heading");c?c.insertAdjacentElement("afterend",a):r.prepend(a)}else{t.appendChild(i);return}i.remove()}_appendStandaloneInput(t,n,e){if(!this._contentEl)return;const o={root:"root",elements:{root:{type:"TextInput",props:{placeholder:n}}}},i=this._renderUISpec(o,t);(e??this._contentEl).appendChild(i)}_handleAction(t){this._showTransitionIndicator(),y.trackSuggestedQuestion(t.title,t.type),this.config.onActionSelected?.(t),setTimeout(()=>y.dispatch("gengage:qna:action",t),350)}_handleOpenChat(){this._showTransitionIndicator(),this.config.onOpenChat?.(),setTimeout(()=>y.dispatch("gengage:qna:open-chat",{}),350)}_showTransitionIndicator(){if(!this._contentEl)return;this._contentEl.querySelector(".gengage-qna-transition-indicator")?.remove(),this._contentEl.classList.add("gengage-qna--transitioning");const t=this._i18n.redirectingToChat??"Redirecting to chat...",n=document.createElement("div");n.className="gengage-qna-transition-indicator",n.textContent=t,(this._contentEl.querySelector(".gengage-qna-panel")??this._contentEl).appendChild(n),setTimeout(()=>{this._contentEl?.classList.remove("gengage-qna--transitioning"),n.remove()},600)}};function nt(){return new N}Object.defineProperty(exports,"GengageQNA",{enumerable:!0,get:function(){return N}});Object.defineProperty(exports,"createDefaultQnaUISpecRegistry",{enumerable:!0,get:function(){return P}});Object.defineProperty(exports,"createQNAWidget",{enumerable:!0,get:function(){return nt}});Object.defineProperty(exports,"defaultQnaUnknownUISpecRenderer",{enumerable:!0,get:function(){return E}});Object.defineProperty(exports,"qnaCatalog",{enumerable:!0,get:function(){return et}});Object.defineProperty(exports,"renderQnaUISpec",{enumerable:!0,get:function(){return Q}});
|
package/dist/qna.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./qna-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./qna-DwG8AJJf.cjs");exports.GengageQNA=e.GengageQNA;exports.createDefaultQnaUISpecRegistry=e.createDefaultQnaUISpecRegistry;exports.createQNAWidget=e.createQNAWidget;exports.defaultQnaUnknownUISpecRenderer=e.defaultQnaUnknownUISpecRenderer;exports.qnaCatalog=e.qnaCatalog;exports.renderQnaUISpec=e.renderQnaUISpec;
|
package/dist/qna.iife.js
CHANGED
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
transform: translateY(0);
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
-
`,document.head.appendChild(e)}var te=null;function Fn(){if(te!==null)return te;try{te=localStorage.getItem("gengage:debug")==="1"}catch{te=!1}return te}function Te(e,t,n){if(!Fn())return;const r=[`[gengage:${e}]`,t];n!==void 0&&r.push(n),console.debug(...r)}var Hn=class{constructor(){this.isVisible=!1,this.isInitialised=!1,this._handlers=new Map,this._cleanups=[],this._ownsRoot=!1,this._destroying=!1}async init(e){if(this.isInitialised){console.warn("[gengage] Widget already initialised. Call update() instead.");return}const t=Pn(e.theme);this.config={...e,theme:t,session:In(e.session)},this.root=this._resolveMount(e.mountTarget),this._applyTheme(t),qn();const n=Fe("gengage:context:update",r=>this.update(r));this._cleanups.push(n),Te("lifecycle",`${this.constructor.name}.init`,{accountId:e.accountId,sku:e.pageContext?.sku});try{await this.onInit(this.config)}catch(r){throw this.destroy(),r}this._destroying||(this.isInitialised=!0,Te("lifecycle",`${this.constructor.name} ready`),this.emit("ready"))}update(e){this.isInitialised&&(this.config.pageContext?this.config={...this.config,pageContext:{...this.config.pageContext,...e}}:e.pageType!==void 0&&(this.config={...this.config,pageContext:e}),this.onUpdate(e),this.emit("context-update",this.config.pageContext))}show(){this.isVisible||(this.isVisible=!0,this.root.style.display="",this.onShow(),this.emit("show"))}hide(){this.isVisible&&(this.isVisible=!1,this.root.style.display="none",this.onHide(),this.emit("hide"))}destroy(){this._destroying||(this._destroying=!0,this.emit("destroy"),this._cleanups.forEach(e=>e()),this._cleanups.length=0,this._handlers.clear(),this.onDestroy(),this.config.analyticsClient?.destroy(),this._ownsRoot?this.root.remove():this.root.innerHTML=""
|
|
47
|
+
`,document.head.appendChild(e)}var te=null;function Fn(){if(te!==null)return te;try{te=localStorage.getItem("gengage:debug")==="1"}catch{te=!1}return te}function Te(e,t,n){if(!Fn())return;const r=[`[gengage:${e}]`,t];n!==void 0&&r.push(n),console.debug(...r)}var Hn=class{constructor(){this.isVisible=!1,this.isInitialised=!1,this._handlers=new Map,this._cleanups=[],this._ownsRoot=!1,this._destroying=!1}async init(e){if(this.isInitialised){console.warn("[gengage] Widget already initialised. Call update() instead.");return}const t=Pn(e.theme);this.config={...e,theme:t,session:In(e.session)},this.root=this._resolveMount(e.mountTarget),this._applyTheme(t),qn();const n=Fe("gengage:context:update",r=>this.update(r));this._cleanups.push(n),Te("lifecycle",`${this.constructor.name}.init`,{accountId:e.accountId,sku:e.pageContext?.sku});try{await this.onInit(this.config)}catch(r){throw this.destroy(),r}this._destroying||(this.isInitialised=!0,Te("lifecycle",`${this.constructor.name} ready`),this.emit("ready"))}update(e){this.isInitialised&&(this.config.pageContext?this.config={...this.config,pageContext:{...this.config.pageContext,...e}}:e.pageType!==void 0&&(this.config={...this.config,pageContext:e}),this.onUpdate(e),this.emit("context-update",this.config.pageContext))}show(){this.isVisible||(this.isVisible=!0,this.root.style.display="",this.onShow(),this.emit("show"))}hide(){this.isVisible&&(this.isVisible=!1,this.root.style.display="none",this.onHide(),this.emit("hide"))}destroy(){this._destroying||(this._destroying=!0,this.emit("destroy"),this._cleanups.forEach(e=>e()),this._cleanups.length=0,this._handlers.clear(),this.onDestroy(),this.config.analyticsClient?.destroy(),this._cleanupRoot(),this.isInitialised=!1)}_cleanupRoot(){this._ownsRoot?this.root.remove():this.root.innerHTML=""}on(e,t){return this._handlers.has(e)||this._handlers.set(e,new Set),this._handlers.get(e).add(t),()=>this._handlers.get(e)?.delete(t)}trackCheckout(e,t){const n=e==="start"?Tn:An;this.track(n(this.analyticsContext(),t))}flushMeteringSummary(e){this.track(Sn(this.analyticsContext(),e))}emit(e,...t){this._handlers.get(e)?.forEach(n=>n(...t))}addCleanup(e){this._cleanups.push(e)}track(e){this.config.analyticsClient?.track(e)}analyticsContext(){const e={account_id:this.config.accountId,session_id:this.config.session?.sessionId??"",correlation_id:this.config.session?.sessionId??""};return this.config.session?.viewId!==void 0&&(e.view_id=this.config.session.viewId),this.config.session?.userId!==void 0&&(e.user_id=this.config.session.userId),this.config.pageContext?.pageType!==void 0&&(e.page_type=this.config.pageContext.pageType),this.config.pageContext?.sku!==void 0&&(e.sku=this.config.pageContext.sku),this.config.session?.abTestVariant!==void 0&&(e.ab_test_variant=this.config.session.abTestVariant),this.config.session?.abTestExperimentId!==void 0&&(e.ab_test_experiment_id=this.config.session.abTestExperimentId),e}_resolveMount(e){if(e instanceof HTMLElement)return e;if(typeof e=="string"){const n=document.querySelector(e);if(!n)throw new Error(`[gengage] Mount target not found: "${e}"`);return n}const t=document.createElement("div");return t.dataset.gengageWidget=this.constructor.name.toLowerCase(),document.body.insertBefore(t,document.body.firstChild),this._ownsRoot=!0,t}_applyTheme(e){if(e){for(const[t,n]of Object.entries(e))if(n!==void 0){const r=t.startsWith("--")?t:`--gengage-${Jn(t)}`;this.root.style.setProperty(r,n)}}}};function Jn(e){return e.replace(/([A-Z])/g,"-$1").toLowerCase()}var Qn=8e3,Vn=5e3,Wn="https://www.google.com/favicon.ico",q=new Map,Ge=!1,G=null,ne=null,H=!1;function Gn(e){return typeof e=="string"&&e.toLowerCase().startsWith("tr")}function Ke(e){return Gn(e)?"İnternet bağlantısında sorun var gibi görünüyor. İstek sürerken yeniden deneyeceğiz.":"Your internet connection looks unstable. We'll keep retrying while this request is active."}function Ye(){let e;for(const t of q.values())e=t;return e}function Ae(){G&&(clearTimeout(G),G=null)}function Kn(){ne&&(clearInterval(ne),ne=null)}async function Xe(){try{if(typeof navigator<"u"&&navigator.onLine===!1)return!1;if(typeof window<"u"){const n=window.location.hostname;if(n==="localhost"||n==="127.0.0.1")return navigator.onLine}const e=new AbortController,t=setTimeout(()=>e.abort(),3e3);try{return await fetch(Wn,{method:"HEAD",mode:"no-cors",cache:"no-cache",signal:e.signal}),!0}catch{return navigator.onLine}finally{clearTimeout(t)}}catch{return typeof navigator>"u"?!0:navigator.onLine}}function se(){H=!1,Kn(),We()}function ce(){G||H||q.size===0||(G=setTimeout(async()=>{G=null,!(H||q.size===0)&&!await Xe()&&q.size>0&&(H=!0,Ee({source:"sdk",message:Ke(Ye()),sticky:!0}),ne||(ne=setInterval(async()=>{if(q.size===0){se();return}await Xe()&&(se(),ce())},Vn)))},Qn))}function Yn(){Ge||typeof window>"u"||(Ge=!0,window.addEventListener("online",()=>{se(),ce()}),window.addEventListener("offline",()=>{q.size===0||H||(H=!0,Ae(),Ee({source:"sdk",message:Ke(Ye()),sticky:!0}))}))}function Xn(e){Yn();const t=Symbol(e.source);q.set(t,e.locale),ce();let n=!1;return()=>{if(!n){if(n=!0,q.delete(t),q.size===0){Ae(),se();return}H||(Ae(),ce())}}}function et(e){return typeof e=="object"&&e!==null&&typeof e.type=="string"}function er(e){const t=[];let n=0,r=!1,o=!1,i=0;for(let a=0;a<e.length;a++){const s=e[a];if(o){o=!1;continue}if(s==="\\"&&r){o=!0;continue}if(s==='"'){r=!r;continue}r||(s==="{"&&n++,s==="}"&&(n--,n===0&&(t.push(e.slice(i,a+1)),i=a+1)))}return t.length>0?t:[e]}function tt(e,t){const n=e.trim();if(!n||n.startsWith(":"))return!1;const r=n.startsWith("data: ")?n.slice(6):n;if(r==="[DONE]")return t.onDone?.(),!0;try{const o=JSON.parse(r);return et(o)?(Te("stream",`event: ${o.type}`,o),t.onEvent(o),o.type==="done"?(t.onDone?.(),!0):!1):!1}catch{const o=er(r);if(o.length>1){for(const i of o)try{const a=JSON.parse(i);if(!et(a))continue;if(t.onEvent(a),a.type==="done")return t.onDone?.(),!0}catch{}return!1}return!1}}async function tr(e,t){if(!e.ok){t.onError?.(new Error(`HTTP ${e.status}: ${e.statusText}`));return}if(!e.body){t.onError?.(new Error("Response body is null — streaming not supported"));return}const n=e.body.getReader(),r=new TextDecoder("utf-8");let o="";const i=t.idleTimeoutMs??6e4,a=Symbol("idle-timeout");let s=!1;try{for(;;){const c=n.read();let u;const d=await(i>0?Promise.race([c.then(h=>(clearTimeout(u),h)),new Promise(h=>{u=setTimeout(()=>h(a),i)})]):c);if(d===a){s=!0,await n.cancel();break}const{done:g,value:p}=d;if(g)break;o+=r.decode(p,{stream:!0});const f=o.split(`
|
|
48
48
|
`);o=f.pop()??"";for(const h of f)if(tt(h,t))return}if(o.trim()&&tt(o,t))return}catch(c){if(c instanceof DOMException&&c.name==="AbortError")return;t.onError?.(c instanceof Error?c:new Error(String(c)))}finally{s||n.releaseLock()}t.onDone?.()}var nr={process_action:"/process_action",launcher_action:"/launcher_action",similar_products:"/similar_products",product_groupings:"/product_groupings"};function rr(e){if(e===void 0)throw new Error("[gengage] middlewareUrl is required. Pass your Gengage backend URL in widget config.");const t=e.trim();return t===""?"":t.replace(/\/+$/,"")}function or(e,t){return`${rr(t?.middlewareUrl)}/chat${nr[e]}`}var nt=3,ir=(e,t)=>{const n=e.replace(/\s+/g," ").trim().replace(/^[,.;:!?•-]+|[,.;:!?•-]+$/g,"");if(!n)return"";const r=t?.stripLeadingStopWords?n.replace(/^(?:daha|için)\s+/i,"").trim():n;return r?r.split(/\s+/).slice(0,3).join(" ").trim():""},$e=(e,t)=>e?e.split(/[•,;:/()]|(?:\sve\s)|(?:\sand\s)|(?:\sile\s)|(?:\sfor\s)|(?:\swith\s)/i).map(n=>ir(n,t)).filter(Boolean):[];function ar(e){const t=(e.display_keywords??[]).flatMap(o=>$e(o,{stripLeadingStopWords:!0})),n=t.filter((o,i)=>t.indexOf(o)===i);if(n.length>0)return n.slice(0,nt);const r=[...$e(e.chosen_attribute,{stripLeadingStopWords:!0}),...$e(e.short_name)];return r.filter((o,i)=>r.indexOf(o)===i).slice(0,nt)}function sr(e){return ar(e).join(" • ")}var cr=["beauty_consulting","watch_expert"];function ur(e){return typeof e=="string"&&cr.includes(e)}function lr(e){if(typeof e.type!="string")return null;if(dr(e))return e;const t=e;switch(t.type){case"outputText":return pr(t);case"suggestedActions":return fr(t);case"productList":return gr(t);case"productDetails":return hr(t);case"productDetailsSimilars":return mr(t);case"comparisonTable":return _r(t);case"context":return wr(t);case"chatStreamEnd":return kr();case"loading":return zr(t);case"panelLoading":return Sr(t);case"similarLoading":return Er(t);case"redirect":return Tr(t);case"error":return Ar(t);case"dummy":return $r(t);case"launcherAction":return Ir(t);case"text":return Ie(t);case"productItem":return Pr(t);case"text_image":return rt(t);case"quick_qna":return ot(t);case"reviewHighlights":return Cr(t);case"aiProductSuggestions":return Rr(t);case"aiProductGroupings":return Nr(t);case"aiSuggestedSearches":return xr(t);case"prosAndCons":return Or(t);case"getGroundingReview":return Lr(t);case"voice":return jr(t);case"visitorDataResponse":return Zr(t);case"productListPreview":return qr();case"groupList":return Dr(t);case"formGetInfo":case"formTestDrive":case"formServiceRequest":case"launchFormPage":return Ur(t);case"launcherContent":return Mr(t);case"handoff":return Br(t);case"uiSpec":return Kr(t);default:return null}}function dr(e){const t=e.type;if(typeof t!="string")return!1;switch(t){case"metadata":return typeof e.sessionId=="string"&&typeof e.model=="string";case"text_chunk":return typeof e.content=="string";case"ui_spec":{const n=e.widget;if(n!=="chat"&&n!=="qna"&&n!=="simrel")return!1;const r=C(e.spec);return r?typeof r.root=="string"&&C(r.elements)!==null:!1}case"action":{const n=C(e.action);return n!==null&&typeof n.kind=="string"}case"error":return typeof e.code=="string"&&typeof e.message=="string";case"done":return!0;default:return!1}}function pr(e){const t=y(e.payload.text,e.payload.plain_text)??"",n=y(e.payload.plain_text,e.payload.text)??t;if(e.payload.is_error)return{type:"error",code:"BACKEND_ERROR",message:n||"Backend returned an error"};const r={type:"text_chunk",content:t,final:!0},o=e.payload.product_mentions;Array.isArray(o)&&o.length>0&&(r.productMentions=o.filter(c=>typeof c=="object"&&c!==null&&typeof c.sku=="string"&&typeof c.short_name=="string"));const i=e.payload.sku_to_product_item;i&&typeof i=="object"&&!Array.isArray(i)&&(r.skuToProductItem=i);const a=e.payload.conversation_mode;typeof a=="string"&&a&&(r.conversationMode=a);const s=e.payload.render_hint;return typeof s=="string"&&s&&(r.renderHint=s),e.payload.kvkk===!0&&(r.kvkk=!0),r}function fr(e){return it((e.payload.actions??[]).map(t=>{const n=y(t.title)??"",r=L(t.requestDetails,n),o=r?{label:n,action:r}:null;return o?(typeof t.icon=="string"&&(o.icon=t.icon),typeof t.image=="string"&&(o.image=t.image),o):null}).filter(Pe),"chat")}function gr(e){const t=(Array.isArray(e.payload.style_variations)?e.payload.style_variations:[]).map(a=>{const s=y(a.style_label),c=y(a.style_mood),u=y(a.image_url??void 0),d=(Array.isArray(a.product_list)?a.product_list:[]).map(p=>{const f=C(p);return f?st(C(f.product_detail)??C(f.product)??f):null}).filter(Pe),g=Array.isArray(a.recommendation_groups)?a.recommendation_groups.map(p=>({label:y(p.label)??"",reason:y(p.reason)??"",skus:Array.isArray(p.skus)?p.skus.filter(f=>typeof f=="string"&&f.trim().length>0):[]})):[];return{style_label:s??"",style_mood:c??"",...u?{image_url:u}:{},product_list:d,recommendation_groups:g}}).filter(a=>a.product_list.length>0),n=e.payload.product_list??[],r=ur(e.payload.source)&&t.length>0?t[0].product_list:null,o=r?Fr(r,"chat"):at(n,"chat");o.panelHint="panel";const i=o.spec.elements[o.spec.root];if(i){const a={};typeof e.payload.offset=="number"&&(a.offset=e.payload.offset),typeof e.payload.end_of_list=="boolean"&&(a.endOfList=e.payload.end_of_list),typeof e.payload.title=="string"&&(a.panelTitle=e.payload.title),typeof e.payload.source=="string"&&(a.source=e.payload.source),t.length>0&&(a.styleVariations=t),Object.keys(a).length>0&&(i.props={...i.props,...a})}return o}function hr(e){const t=e.payload.productDetails;if(!t)return Jr("chat");const n=K(t);return{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"ProductDetailsPanel",props:{product:{...t,...n}}}}},panelHint:"panel"}}function mr(e){const t=at(e.payload.similarProducts??[],"chat"),n=t.spec.elements[t.spec.root];return n&&(n.props={...n.props,similarsAppend:!0}),{...t,panelHint:"panel"}}function _r(e){const t=e.payload.multiple_product_details??[],n=e.payload,r={key_differences:n.key_differences,recommended_choice:n.recommended_choice,recommended_choice_sku:n.recommended_choice_sku,special_considerations:n.special_considerations,criteria_view:n.criteria_view,criteria_view_short:n.criteria_view_short,compared_field_names:n.compared_field_names,winner_product:n.winner_product,winner_hits:n.winner_hits,...e.payload.product_comparison_framework??{}},o=e.payload.table,i=e.payload.features_list,a=[];for(const b of t){const z=K(b);a.push(z)}const s=yr(o,a,r,i);let c;r?.recommended_choice_sku?c=r.recommended_choice_sku:r?.winner_product&&r.winner_product.length>0&&(c=r.winner_product[0]?.product_detail?.sku??r.winner_product[0]?.sku);const u=c?a.find(b=>b.sku===c)??a[0]:a[0],d=[];if(Array.isArray(r?.key_differences))for(const b of r.key_differences)typeof b=="string"&&d.push(b);const g=Wr(r?.special_considerations),p=r?.recommended_choice,f=r?.winner_hits,h={};for(const b of a){const z=b.sku;z&&(h[z]={title:b.name??z,type:"launchSingleProduct",payload:{sku:z}})}const _={products:a,attributes:s,highlights:d,productActions:h};return u&&(_.recommended=u),g.length>0&&(_.specialCases=g),p&&(_.recommendedText=p),f&&(_.winnerHits=f),typeof r?.key_differences=="string"&&(_.keyDifferencesHtml=r.key_differences),r?.special_considerations&&(_.specialConsiderations=r.special_considerations),{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"ComparisonTable",props:_}}},panelHint:"panel"}}function yr(e,t,n,r){if(!e)return[];const o=Object.entries(e);if(o.length===0)return[];const i=o[0]?.[1];if(Array.isArray(i)){const g=n.criteria_view??n.criteria_view_short??{},p=n.compared_field_names??Object.keys(e),f=[];for(const h of p){const _=e[h];if(!_||!Array.isArray(_))continue;const b=g[h]??h;f.push({label:b,values:_.map(z=>typeof z=="string"?z:String(z??""))})}return f}const a=e,s=t.map(g=>String(g.sku??"")).filter(g=>g.length>0),c=n.criteria_view??n.criteria_view_short??{},u=(r&&r.length>0?r:n.compared_field_names&&n.compared_field_names.length>0?n.compared_field_names:vr(a)).filter(g=>g!=="name"&&g!=="name_short"&&!g.endsWith("_short")),d=[];for(const g of u){const p=s.map(h=>{const _=a[h];if(!_||typeof _!="object")return"";const b=_[`${g}_short`],z=_[g];return br(b??z)});if(p.every(h=>h.length===0))continue;const f=c[g]??g;d.push({label:f,values:p})}return d}function vr(e){const t=[],n=new Set;for(const r of Object.values(e))if(!(!r||typeof r!="object"))for(const o of Object.keys(r))n.has(o)||(n.add(o),t.push(o));return t}function br(e){return typeof e=="string"?e:typeof e=="number"||typeof e=="boolean"?String(e):""}function wr(e){return{type:"metadata",sessionId:"",model:"",meta:{panel:e.payload.panel,messages:e.payload.messages,message_id:e.payload.message_id}}}function kr(){return{type:"done"}}function zr(e){return{type:"metadata",sessionId:"",model:"",meta:{loading:!0,loadingText:e.payload.text,thinkingMessages:e.payload.thinking_messages,dynamicLoading:e.payload.is_dynamic===!0}}}function Sr(e){return{type:"metadata",sessionId:"",model:"",meta:{loading:!0,panelLoading:!0,panelPendingType:e.payload?.pending_type,loadingText:e.payload?.text}}}function Er(e){return{type:"metadata",sessionId:"",model:"",meta:{loading:!0,similarPanelLoading:!0,panelPendingType:e.payload?.pending_type,loadingText:e.payload?.text}}}function Tr(e){const t=y(e.payload.url);return t?{type:"action",action:{kind:"navigate",url:t,newTab:e.payload.new_tab===!0}}:{type:"metadata",sessionId:"",model:"",meta:{redirect:e.payload,redirectTarget:y(e.payload.to)}}}function Ar(e){return{type:"error",code:"BACKEND_ERROR",message:y(e.payload?.text,e.payload?.message,e.payload?.error)??"Backend returned an error"}}function $r(e){return{type:"metadata",sessionId:"",model:"",meta:{noop:!0}}}function Ir(e){const t=e.payload??{};if(Array.isArray(t.action_list)){const o={action_list:t.action_list},i=typeof t.type=="string"?t.type:void 0,a=typeof t.theme=="string"?t.theme:void 0;return i!==void 0&&(o.type=i),a!==void 0&&(o.theme=a),ot({type:"quick_qna",payload:o})}const n=C(t.action);if(n){const o={action:n},i=typeof t.text=="string"?t.text:void 0,a=typeof t.image_url=="string"?t.image_url:void 0,s=typeof t.theme=="string"?t.theme:void 0;return i!==void 0&&(o.text=i),a!==void 0&&(o.image_url=a),s!==void 0&&(o.theme=s),rt({type:"text_image",payload:o})}const r=typeof t.text=="string"?t.text:"";if(r){const o={text:r},i=typeof t.type=="string"?t.type:void 0,a=typeof t.theme=="string"?t.theme:void 0,s=C(t.payload)??void 0;return i!==void 0&&(o.type=i),s!==void 0&&(o.payload=s),a!==void 0&&(o.theme=a),Ie({type:"text",payload:o})}return{type:"metadata",sessionId:"",model:"",meta:{launcherAction:t}}}function Ie(e){const t={text:y(e.payload.text)??""};return typeof e.payload.theme=="string"&&(t.theme=e.payload.theme),e.payload.payload!==void 0&&(t.payload=e.payload.payload),{type:"ui_spec",widget:"qna",spec:{root:"root",elements:{root:{type:"QuestionHeading",props:t}}}}}function Pr(e){return Hr(e.payload,"qna")}function rt(e){const t=y(e.payload.text)??"",n=L(e.payload.action,t);if(n){const o={label:t||n.title,action:n};return typeof e.payload.image_url=="string"&&(o.image=e.payload.image_url),typeof e.payload.theme=="string"&&(o.theme=e.payload.theme),{type:"ui_spec",widget:"qna",spec:{root:"root",elements:{root:{type:"ActionButton",props:o}}}}}const r={text:t};return typeof e.payload.theme=="string"&&(r.theme=e.payload.theme),Ie({type:"text",payload:r})}function ot(e){return it((e.payload.action_list??[]).map(t=>{const n=y(t.title)??"",r=L(t.requestDetails,n),o=r?{label:n,action:r}:null;return o?(typeof t.icon=="string"&&(o.icon=t.icon),typeof t.image=="string"&&(o.image=t.image),o):null}).filter(Pe),"qna")}function Cr(e){const t={reviews:(e.payload.reviews??[]).map(n=>{const r={};return typeof n.review_class=="string"&&(r.review_class=n.review_class),typeof n.review_text=="string"&&(r.review_text=n.review_text),(typeof n.review_rating=="string"||typeof n.review_rating=="number")&&(r.review_rating=n.review_rating),typeof n.review_tag=="string"&&(r.review_tag=n.review_tag),r})};return typeof e.payload.sku=="string"&&(t.sku=e.payload.sku),{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"ReviewHighlights",props:t}}}}}function Or(e){const t={};return Array.isArray(e.payload.pros)&&(t.pros=e.payload.pros),Array.isArray(e.payload.cons)&&(t.cons=e.payload.cons),typeof e.payload.product_name=="string"&&(t.productName=e.payload.product_name),{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"ProsAndCons",props:t}}}}}function Zr(e){return{type:"metadata",sessionId:"",model:"",meta:{visitorDataResponse:e.payload}}}function Rr(e){const t=e.payload.product_suggestions??[],n=[];for(let r=0;r<t.length;r++){const o=t[r];if(!o)continue;const i=Qr(o);if(!i)continue;const a={product:i},s=L(o.requestDetails,i.name);s&&(a.action=s),typeof o.role=="string"&&(a.role=o.role),typeof o.reason=="string"&&(a.reason=o.reason),typeof o.review_highlight=="string"&&(a.reviewHighlight=o.review_highlight),Array.isArray(o.labels)&&(a.labels=o.labels),typeof o.expert_quality_score=="number"&&(a.expertQualityScore=o.expert_quality_score),n.push(a)}return n.length===0?{type:"metadata",sessionId:"",model:"",meta:{aiProductSuggestions:e.payload.product_suggestions??[]}}:{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"AITopPicks",props:{suggestions:n}}}}}}function Nr(e){const t=e.payload.product_groupings??[],n=[];for(let r=0;r<t.length;r++){const o=t[r];if(!o)continue;const i=y(o.name)??"",a=o.sku&&o.sku.length>0?{type:"findSimilar",payload:{sku:o.sku}}:void 0,s=L(o.requestDetails??a,i);if(!s)continue;const c={name:i,action:s};if(Array.isArray(o.labels)){const u=o.labels.filter(d=>typeof d=="string");u.length>0&&(c.labels=u)}typeof o.image=="string"&&(c.image=o.image),n.push(c)}return n.length===0?{type:"metadata",sessionId:"",model:"",meta:{aiProductGroupings:e.payload.product_groupings??[]}}:{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"AIGroupingCards",props:{entries:n}}}}}}function xr(e){const t=e.payload.suggested_searches??[],n=[];for(let r=0;r<t.length;r++){const o=t[r];if(!o)continue;const i=y(o.short_name,o.chosen_attribute,o.detailed_user_message)??`Search ${r+1}`,a={},s=y(o.detailed_user_message);s&&(a.text=s);const c=C(C(o.requestDetails)?.payload),u=c?.group_skus;o.group_skus&&Array.isArray(o.group_skus)?a.group_skus=o.group_skus:Array.isArray(u)&&(a.group_skus=u.filter(z=>typeof z=="string"));const d=y(o.sku,o.representative_product_sku,c?.sku);d&&(a.sku=d),a.is_suggested_text=1;const g={type:"inputText",payload:a},p=L(o.requestDetails,i),f=p?.type==="findSimilar"&&typeof a.text=="string"?L(g,i):p??L(g,i);if(!f)continue;const h={shortName:i,action:f},_=y(o.detailed_user_message);_&&_!==i&&(h.detailedMessage=_);const b=sr(o);b&&b!==i&&b!==(_??"")&&(h.whyDifferent=b),typeof o.image=="string"&&(h.image=o.image),n.push(h)}return n.length===0?{type:"metadata",sessionId:"",model:"",meta:{aiSuggestedSearches:e.payload.suggested_searches??[]}}:{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"AISuggestedSearchCards",props:{entries:n}}}}}}function Lr(e){const t=e.payload,n=L(t.requestDetails??t.request_details,y(t.review_count,t.reviewCount,t.text,t.title)??"Show product reviews");if(!n)return{type:"metadata",sessionId:"",model:"",meta:{groundingReview:t}};const r={action:n};return t.title&&(r.title=t.title),t.text&&(r.text=t.text),t.review_count?r.reviewCount=t.review_count:typeof t.reviewCount=="string"&&t.reviewCount.trim()&&(r.reviewCount=t.reviewCount),{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"GroundingReviewCard",props:r}}}}}function qr(){return{type:"metadata",sessionId:"",model:"",meta:{analyzeAnimation:!0}}}function jr(e){return{type:"metadata",sessionId:"",model:"",meta:{voice:e.payload}}}function Dr(e){const t=e.payload.group_list??[],n=[];for(const o of t){const i=o.group_name??"",a=(o.product_list??[]).map(K);n.push({groupName:i,products:a})}const r=[];for(const o of e.payload.filter_tags??[]){const i=o.title??"";if(!i)continue;const a=L(o.requestDetails,i),s={title:i};a&&(s.action=a),r.push(s)}return{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"CategoriesContainer",props:{groups:n,filterTags:r}}}},panelHint:"panel"}}function Ur(e){return{type:"metadata",sessionId:"",model:"",meta:{formType:e.type,formPayload:e.payload??{}}}}function Br(e){const t={};return typeof e.payload?.summary=="string"&&(t.summary=e.payload.summary),Array.isArray(e.payload?.products_discussed)&&(t.products_discussed=e.payload.products_discussed),typeof e.payload?.user_sentiment=="string"&&(t.user_sentiment=e.payload.user_sentiment),{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"HandoffNotice",props:t}}}}}function Mr(e){return{type:"metadata",sessionId:"",model:"",meta:{launcherContent:e.payload??{}}}}function it(e,t){const n={},r=[];for(let o=0;o<e.length;o++){const i=e[o];if(!i)continue;const a=`action-${o}`;r.push(a);const s={label:i.label,action:i.action};i.icon!==void 0&&(s.icon=i.icon),i.image!==void 0&&(s.image=i.image),i.description!==void 0&&(s.description=i.description),n[a]={type:"ActionButton",props:s}}return n.root={type:"ActionButtons",props:{buttons:e.map(o=>{const i={label:o.label,action:o.action};return o.image!==void 0&&(i.image=o.image),o.description!==void 0&&(i.description=o.description),o.icon!==void 0&&(i.icon=o.icon),i})},children:r},{type:"ui_spec",widget:t,spec:{root:"root",elements:n}}}function at(e,t){const n={},r=[];for(let o=0;o<e.length;o++){const i=e[o];if(!i)continue;const a=K(i),s=`product-${o}`;r.push(s);const c={product:a,index:o};a.sku&&(c.action={title:a.name,type:"launchSingleProduct",payload:{sku:a.sku}}),n[s]={type:"ProductCard",props:c}}return n.root={type:"ProductGrid",props:{layout:"grid"},children:r},{type:"ui_spec",widget:t,spec:{root:"root",elements:n}}}function Fr(e,t){const n={},r=[];for(let o=0;o<e.length;o++){const i=e[o];if(!i)continue;const a=`product-${o}`;r.push(a);const s={product:i,index:o},c=i.sku;c&&(s.action={title:i.name??"",type:"launchSingleProduct",payload:{sku:c}}),n[a]={type:"ProductCard",props:s}}return n.root={type:"ProductGrid",props:{layout:"grid"},children:r},{type:"ui_spec",widget:t,spec:{root:"root",elements:n}}}function Hr(e,t){return{type:"ui_spec",widget:t,spec:{root:"root",elements:{root:{type:"ProductCard",props:{product:K(e),index:0}}}}}}function Jr(e){return{type:"ui_spec",widget:e,spec:{root:"root",elements:{root:{type:"ActionButtons",props:{buttons:[]},children:[]}}}}}function Qr(e){const t=y(e.sku),n=y(e.short_name),r={...C(e.product_item)??e},o=y(e.discount_reason,e.discountReason);return o&&!y(r.discount_reason,r.discountReason)&&(r.discount_reason=o),st(r,t,n)}function st(e,t,n){const r=y(e.sku,t),o=y(e.name,n);if(!r||!o)return null;const i={sku:r,name:o},a=y(e.brand);a&&(i.brand=a);const s=y(e.url);s&&(i.url=s);const c=Vr(e.images);if(c.length>0)i.images=c;else{const _=y(e.image,e.image_url,e.imageUrl);_&&(i.images=[_])}const u=re(e.price_discounted);u!==void 0&&(i.price_discounted=u);const d=re(e.price);d!==void 0&&(i.price=d);const g=re(e.rating);g!==void 0&&(i.rating=g);const p=re(e.review_count)??re(e.reviewCount);p!==void 0&&(i.review_count=p);const f=y(e.cart_code,e.cartCode);f&&(i.cart_code=f),typeof e.in_stock=="boolean"&&(i.in_stock=e.in_stock),typeof e.inStock=="boolean"&&(i.in_stock=e.inStock);const h=y(e.discount_reason,e.discountReason);return h&&(i.discount_reason=h),K(i)}function L(e,t){const n=C(e);if(!n)return null;const r=n.type;if(typeof r!="string"||r.length===0)return null;const o={title:t||r,type:r};return n.payload!==void 0&&(o.payload=n.payload),o}function C(e){return!e||typeof e!="object"||Array.isArray(e)?null:e}function y(...e){for(const t of e)if(typeof t=="string"){const n=t.trim();if(n.length>0)return n}}function Vr(e){return Array.isArray(e)?e.filter(t=>typeof t=="string"&&t.length>0):[]}function Wr(e){if(typeof e=="string"){const t=e.trim();return t?[t]:[]}return Array.isArray(e)?e.filter(t=>typeof t=="string").map(t=>t.trim()).filter(t=>t.length>0):[]}function re(e){if(typeof e=="number"&&Number.isFinite(e))return e;if(typeof e=="string"){let t;e.includes(".")&&e.includes(",")?t=e.replace(/\./g,"").replace(",","."):t=e.replace(",",".");const n=Number(t);if(Number.isFinite(n))return n}}function Pe(e){return e!=null}var Gr=new Set(["sku","name","brand","images","price","price_discounted","price_discount_rate","price_currency","discount_reason","url","rating","review_count","cart_code","in_stock","description","description_html","features","specifications","facet_tags","short_name","category_ids","category_names","variants","facet_hits","promotions"]);function K(e){const t=e.price_discounted!=null&&e.price_discounted>0,n=t?e.price_discounted:e.price,r=t&&e.price!=null?e.price:void 0;let o;r!=null&&n!=null&&r>0?o=Math.round((r-n)/r*100):e.price_discount_rate!=null&&e.price_discount_rate>0&&(o=e.price_discount_rate);const i=y(e.brand),a=y(e.name)??e.sku,s=i&&!a.toLowerCase().startsWith(i.toLowerCase())?`${i} ${a}`:a,c={sku:e.sku,name:s,url:y(e.url)??""},u=e.images?.[0];u&&(c.imageUrl=u),e.images&&e.images.length>1&&(c.images=e.images),n!=null&&(c.price=String(n)),r!=null&&(c.originalPrice=String(r)),o!==void 0&&(c.discountPercent=o),i!==void 0&&(c.brand=i),e.rating!==void 0&&(c.rating=e.rating),e.review_count!==void 0&&(c.reviewCount=e.review_count),e.cart_code!==void 0&&(c.cartCode=e.cart_code),e.in_stock!==void 0&&(c.inStock=e.in_stock),e.variants&&e.variants.length>0&&(c.variants=e.variants),e.discount_reason!==void 0&&(c.discountReason=e.discount_reason),e.promotions&&e.promotions.length>0&&(c.promotions=e.promotions),e.description!==void 0&&(c.description=e.description),e.description_html!==void 0&&(c.descriptionHtml=e.description_html),e.features&&e.features.length>0&&(c.features=e.features),e.specifications!==void 0&&(c.specifications=e.specifications),e.facet_hits&&(c.facetHits=e.facet_hits),e.short_name!==void 0&&(c.shortName=e.short_name);const d=e,g={};let p=!1;for(const f of Object.keys(d))Gr.has(f)||(g[f]=d[f],p=!0);return p&&(c.extras=g),c}function Kr(e){const t=e.payload.type,{type:n,...r}=e.payload;return{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:t,props:r}}}}}async function Yr(e,t,n){const r=or("launcher_action",t),o={uiSpecs:[],actions:[]},i={method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)};n!==void 0&&(i.signal=n);const a=await fetch(r,i);if(!a.ok)throw new Error(`HTTP ${a.status}: ${a.statusText}`);const s={onEvent:c=>{const u=lr(c);if(u&&(u.type==="ui_spec"&&o.uiSpecs.push(u.spec),u.type==="ui_spec"&&u.spec.elements)){for(const d of Object.values(u.spec.elements))if(d.type==="ActionButton"&&d.props?.action){const g=d.props.action;o.actions.push(g)}}}};return n!==void 0&&(s.signal=n),await tr(a,s),o}function Xr(){return typeof window<"u"&&Array.isArray(window.dataLayer)}function Ce(e,t){const n={event:e,...t};Xr()&&window.dataLayer.push(n)}function eo(e){Ce("gengage-on-init",{gengage_widget:e})}function to(e){Ce("gengage-show",{gengage_widget:e})}function no(e,t){Ce("gengage-suggested-question",{gengage_question_title:e,gengage_action_type:t})}function ct(e){const t=document.createElement("div");t.className="gengage-qna-buttons gds-toolbar",t.dataset.gengagePart="qna-button-row",t.setAttribute("role","group"),t.setAttribute("aria-label",e.quickQuestionsAriaLabel??"Quick questions"),e.orientation==="vertical"&&(t.style.flexDirection="column");for(const n of e.actions){const r=document.createElement("button");r.className="gengage-qna-button gds-chip",r.dataset.gengagePart="qna-quick-question",r.textContent=n.title,r.type="button",r.addEventListener("click",()=>{const o={title:n.title,type:n.type};n.payload!==void 0&&(o.payload=n.payload),e.onAction(o)}),t.appendChild(r)}if(e.ctaText||e.onOpenChat){const n=document.createElement("button");n.className="gengage-qna-cta gds-btn gds-btn-secondary",n.dataset.gengagePart="qna-cta",n.textContent=e.ctaText??e.defaultCtaText??"Ask something else",n.type="button",n.addEventListener("click",()=>{e.onOpenChat?.()}),t.appendChild(n)}return t}function ro(e){const t=document.createElement("div");t.className="gengage-qna-input-wrapper",t.dataset.gengagePart="qna-input-wrapper";const n=document.createElement("div");n.className="gengage-qna-input-combo",n.dataset.gengagePart="qna-input-combo";const r=document.createElement("input");r.type="text",r.className="gengage-qna-input",r.dataset.gengagePart="qna-input",r.setAttribute("aria-label",e.askQuestionAriaLabel??"Ask a question");const o=Array.isArray(e.placeholders)?e.placeholders:e.placeholders?[e.placeholders]:[e.defaultInputPlaceholder??"Ask a question..."];let i=0,a=o[0]??"";r.placeholder=a;let s=null,c=null,u=!1;const d=()=>{s&&clearInterval(s),s=null,c&&clearTimeout(c),c=null,r.classList.remove("gengage-qna-input--fade")},g=()=>o.length>1&&!u&&r.value.trim().length===0,p=()=>{d(),g()&&(s=setInterval(()=>{g()&&(r.classList.add("gengage-qna-input--fade"),c=setTimeout(()=>{i=(i+1)%o.length,a=o[i]??"",r.placeholder=a,r.classList.remove("gengage-qna-input--fade")},180))},3e3))},f=document.createElement("div");f.className="gengage-qna-input-actions",f.dataset.gengagePart="qna-input-actions";const h=document.createElement("button");h.className="gengage-qna-icon-btn gengage-qna-clear gengage-qna-icon-btn--hidden",h.type="button",h.dataset.gengagePart="qna-clear",h.setAttribute("aria-label","Clear question"),h.innerHTML='<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M18 6L6 18" /><path d="M6 6L18 18" /></svg>';const _=document.createElement("button");_.className="gengage-qna-icon-btn gengage-qna-send gengage-qna-icon-btn--hidden",_.type="button",_.dataset.gengagePart="qna-send",_.setAttribute("aria-label",e.sendQuestionAriaLabel??"Send question"),_.disabled=!0,_.innerHTML=`<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M22 2L11 13" /><path d="M22 2L15 22L11 13L2 9L22 2Z" /></svg><span class="gengage-qna-sr-only">${e.ctaLabel??e.sendButtonText??"Ask"}</span>`;const b=()=>{const $=r.value.trim().length>0;h.classList.toggle("gengage-qna-icon-btn--hidden",!$),_.classList.toggle("gengage-qna-icon-btn--hidden",!$),_.classList.toggle("gengage-qna-send--active",$),_.disabled=!$},z=()=>{const $=r.value.trim();$&&(e.onSubmit({title:$,type:"user_message",payload:$}),r.value="",b(),p())};return h.addEventListener("click",()=>{r.value="",b(),r.focus({preventScroll:!0})}),_.addEventListener("click",z),r.addEventListener("focus",()=>{u=!0,d(),r.placeholder=""}),r.addEventListener("blur",()=>{u=!1,r.value.trim().length===0&&(r.placeholder=a),p()}),r.addEventListener("input",()=>{if(b(),r.value.trim().length>0){d();return}r.placeholder=u?"":a,p()}),r.addEventListener("keydown",$=>{$.key==="Enter"&&($.preventDefault(),z()),$.key==="Escape"&&r.value.length>0&&(r.value="",b(),p())}),f.appendChild(h),f.appendChild(_),n.appendChild(r),n.appendChild(f),t.appendChild(n),b(),p(),t._cleanup=()=>{d()},t}function ue(e,t){if(!e||typeof e!="object")return null;const n=e,r=n.type;if(typeof r!="string"||r.length===0)return null;const o=n.title,i=n.payload,a=typeof o=="string"&&o.length>0?o:t;if(!a)return null;const s={title:a,type:r};return i!==void 0&&(s.payload=i),s}function ut(e){const t={title:e.title,type:e.type};return e.payload!==void 0&&(t.payload=e.payload),t}function lt(e,t){const n=[],r=e.props?.actions;if(Array.isArray(r))for(const a of r){const s=ue(a);s&&n.push(s)}const o=e.props?.buttons;if(Array.isArray(o))for(const a of o){if(!a||typeof a!="object")continue;const s=a,c=typeof s.label=="string"?s.label:void 0,u=ue(s.action,c);u&&n.push(u)}if(e.children)for(const a of e.children){const s=t.elements[a];if(!s||s.type!=="ActionButton")continue;const c=typeof s.props?.label=="string"?s.props.label:void 0,u=ue(s.props?.action,c);u&&n.push(u)}const i=new Set;return n.filter(a=>i.has(a.title)?!1:(i.add(a.title),!0))}var dt={ButtonRow:({element:e,spec:t,context:n})=>{const r=lt(e,t).map(ut),o=e.props?.orientation,i={actions:r,onAction:n.onAction,defaultCtaText:n.i18n.defaultCtaText,quickQuestionsAriaLabel:n.i18n.quickQuestionsAriaLabel};return n.onOpenChat!==void 0&&(i.onOpenChat=n.onOpenChat),n.ctaText!==void 0&&(i.ctaText=n.ctaText),(o==="horizontal"||o==="vertical")&&(i.orientation=o),ct(i)},ActionButtons:({element:e,spec:t,context:n})=>{const r={actions:lt(e,t).map(ut),onAction:n.onAction,defaultCtaText:n.i18n.defaultCtaText,quickQuestionsAriaLabel:n.i18n.quickQuestionsAriaLabel};return n.onOpenChat!==void 0&&(r.onOpenChat=n.onOpenChat),n.ctaText!==void 0&&(r.ctaText=n.ctaText),ct(r)},ActionButton:({element:e,context:t})=>{const n=document.createElement("button");n.className="gengage-qna-button gds-chip",n.type="button",n.dataset.gengagePart="qna-action-button";const r=e.props?.label;typeof r=="string"?n.textContent=r:n.textContent=t.i18n.defaultCtaText;const o=ue(e.props?.action,typeof r=="string"?r:void 0);return o&&n.addEventListener("click",()=>t.onAction(o)),n},TextInput:({element:e,context:t})=>{const n=e.props?.placeholder,r=typeof n=="string"||Array.isArray(n)?n:t.inputPlaceholder,o=typeof e.props?.ctaLabel=="string"?e.props.ctaLabel:void 0,i={onSubmit:t.onAction,askQuestionAriaLabel:t.i18n.askQuestionAriaLabel,defaultInputPlaceholder:t.i18n.defaultInputPlaceholder,sendButtonText:t.i18n.sendButton,sendQuestionAriaLabel:t.i18n.sendQuestionAriaLabel};return r!==void 0&&(i.placeholders=r),o!==void 0&&(i.ctaLabel=o),ro(i)},QuestionHeading:({element:e,context:t})=>{const n=document.createElement("h3");n.className="gengage-qna-heading",n.dataset.gengagePart="qna-heading";const r=e.props?.text,o=t.headingTitleOverride;return n.textContent=typeof o=="string"&&o.trim().length>0?o:typeof r=="string"?r:"",n},ProductCard:()=>null},Oe=({element:e,renderElement:t})=>{if(!e.children||e.children.length===0)return null;const n=document.createElement("div");for(const r of e.children){const o=t(r);o&&n.appendChild(o)}return n};function pt(){return{...dt}}function ft(e,t,n=dt,r=Oe){return vn({spec:e,context:t,registry:n,containerClassName:"gengage-qna-uispec",unknownRenderer:r})}function oo(e){if(!e)return;const t=e.extra;if(t&&typeof t=="object"&&!Array.isArray(t)){const r=t.visible_skus??t.visibleSkus;if(Array.isArray(r)){const o=r.filter(i=>typeof i=="string"&&i.trim().length>0).map(i=>i.trim()).slice(0,200);if(o.length>0)return o}}const n=typeof e.sku=="string"&&e.sku.trim()?e.sku.trim():void 0;return n?[n]:void 0}function gt(e,t){if(!e)return null;const n=e.action;if(!n||typeof n!="object")return null;const r=n,o=r.type;if(typeof o!="string"||o.length===0)return null;const i=r.title,a=typeof i=="string"&&i.length>0?i:typeof t=="string"&&t.length>0?t:"";if(!a)return null;const s=r.payload,c={title:a,type:o};return s!==void 0&&(c.payload=s),c}function io(e,t){const n=e.elements[e.root];if(!n)return!1;const r=o=>{if(o.type!=="ActionButton")return!1;const i=o.props;if(!i||typeof i!="object")return!1;const a=typeof i.label=="string"?i.label:void 0;return a===t?!0:gt(i,a)?.title===t};if(n.type==="ActionButton")return r(n);if(n.children)for(const o of n.children){const i=e.elements[o];if(i&&r(i))return!0}if(n.type==="ActionButtons"&&Array.isArray(n.props?.buttons)){for(const o of n.props.buttons)if(o?.label===t||o?.action?.title===t)return!0}return!1}var ht=0;function mt(){return ht+=1,`gengage-merge-${ht}`}function ao(e,t){const n=e.elements[e.root];if(!n||n.type!=="ButtonRow")return;const r=mt();e.elements[r]={type:"ActionButton",props:{label:t.title,action:{title:t.title,type:t.type,...t.payload!==void 0?{payload:t.payload}:{}}}},n.children=n.children?[r,...n.children]:[r]}function so(e,t){const n=e.elements[e.root];if(!n||n.type!=="ActionButtons")return;const r=mt();e.elements[r]={type:"ActionButton",props:{label:t.title,action:{title:t.title,type:t.type,...t.payload!==void 0?{payload:t.payload}:{}}}},n.children=n.children?[r,...n.children]:[r];const o=n.props?.buttons??[],i={label:t.title,action:{title:t.title,type:t.type,...t.payload!==void 0?{payload:t.payload}:{}}};n.props={...n.props,buttons:[i,...o]}}function co(e){const t={},n=[];for(let r=0;r<e.length;r++){const o=e[r],i=`action-${r}`;n.push(i),t[i]={type:"ActionButton",props:{label:o.title,action:{title:o.title,type:o.type,...o.payload!==void 0?{payload:o.payload}:{}}}}}return t.root={type:"ButtonRow",children:n},{root:"root",elements:t}}function uo(e){return e.find(t=>{const n=t.elements[t.root];return n?.type==="ActionButtons"||n?.type==="ButtonRow"})}function _t(e,t){const n=e.productContextQuickPillLabel,r={text:n};return t&&t.length>0&&(r.sku_list=t),{title:n,type:"user_message",payload:r}}function lo(e,t,n){const r=n?.skuList,o=[],i=[];for(const c of e){const u=c.elements[c.root];if(u?.type==="ActionButton"){const d=u.props;if(gt(d,typeof d?.label=="string"?d.label:void 0)?.type==="findSimilar"){o.push(_t(t,r));continue}}i.push(c)}if(o.length===0)return e;const a=_t(t,r),s=uo(i);if(!s)return[...i,co([a])];if(!io(s,a.title)){const c=s.elements[s.root];c?.type==="ActionButtons"?so(s,a):c?.type==="ButtonRow"&&ao(s,a)}return i}var yt={quickQuestionsAriaLabel:"Hızlı sorular",askQuestionAriaLabel:"Soru sorun",defaultInputPlaceholder:"Bir soru sorun...",sendButton:"Sor",sendQuestionAriaLabel:"Soruyu gönder",defaultCtaText:"Başka bir şey sor",redirectingToChat:"Sohbete yönlendiriliyor...",productContextQuickPillLabel:"Bu ürün hakkında ne bilmeliyim?"},po={quickQuestionsAriaLabel:"Quick questions",askQuestionAriaLabel:"Ask a question",defaultInputPlaceholder:"Ask a question...",sendButton:"Ask",sendQuestionAriaLabel:"Send question",defaultCtaText:"Ask something else",redirectingToChat:"Redirecting to chat...",productContextQuickPillLabel:"What should I know about this product?"};function fo(e){return e?e.toLowerCase().split("-")[0]??"tr":"tr"}function go(e){return fo(e)==="en"?po:yt}var xc=Object.freeze({status:"aborted"});function l(e,t,n){function r(s,c){if(s._zod||Object.defineProperty(s,"_zod",{value:{def:c,constr:a,traits:new Set},enumerable:!1}),s._zod.traits.has(e))return;s._zod.traits.add(e),t(s,c);const u=a.prototype,d=Object.keys(u);for(let g=0;g<d.length;g++){const p=d[g];p in s||(s[p]=u[p].bind(s))}}const o=n?.Parent??Object;class i extends o{}Object.defineProperty(i,"name",{value:e});function a(s){var c;const u=n?.Parent?new i:this;r(u,s),(c=u._zod).deferred??(c.deferred=[]);for(const d of u._zod.deferred)d();return u}return Object.defineProperty(a,"init",{value:r}),Object.defineProperty(a,Symbol.hasInstance,{value:s=>n?.Parent&&s instanceof n.Parent?!0:s?._zod?.traits?.has(e)}),Object.defineProperty(a,"name",{value:e}),a}var Y=class extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}},vt=class extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name="ZodEncodeError"}},Ze={};function J(e){return e&&Object.assign(Ze,e),Ze}function bt(e){const t=Object.values(e).filter(n=>typeof n=="number");return Object.entries(e).filter(([n,r])=>t.indexOf(+n)===-1).map(([n,r])=>r)}function Re(e,t){return typeof t=="bigint"?t.toString():t}function Ne(e){return{get value(){{const t=e();return Object.defineProperty(this,"value",{value:t}),t}throw new Error("cached value already set")}}}function xe(e){return e==null}function Le(e){const t=e.startsWith("^")?1:0,n=e.endsWith("$")?e.length-1:e.length;return e.slice(t,n)}var wt=Symbol("evaluating");function v(e,t,n){let r;Object.defineProperty(e,t,{get(){if(r!==wt)return r===void 0&&(r=wt,r=n()),r},set(o){Object.defineProperty(e,t,{value:o})},configurable:!0})}function Q(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function U(...e){const t={};for(const n of e)Object.assign(t,Object.getOwnPropertyDescriptors(n));return Object.defineProperties({},t)}function kt(e){return JSON.stringify(e)}function ho(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}var zt="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function le(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}var mo=Ne(()=>{if(typeof navigator<"u"&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{return new Function(""),!0}catch{return!1}});function oe(e){if(le(e)===!1)return!1;const t=e.constructor;if(t===void 0||typeof t!="function")return!0;const n=t.prototype;return!(le(n)===!1||Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")===!1)}function St(e){return oe(e)?{...e}:Array.isArray(e)?[...e]:e}var _o=new Set(["string","number","symbol"]);function de(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function B(e,t,n){const r=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(r._zod.parent=e),r}function m(e){const t=e;if(!t)return{};if(typeof t=="string")return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw new Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,typeof t.error=="string"?{...t,error:()=>t.error}:t}function yo(e){return Object.keys(e).filter(t=>e[t]._zod.optin==="optional"&&e[t]._zod.optout==="optional")}var Lc={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function vo(e,t){const n=e._zod.def,r=n.checks;if(r&&r.length>0)throw new Error(".pick() cannot be used on object schemas containing refinements");return B(e,U(e._zod.def,{get shape(){const o={};for(const i in t){if(!(i in n.shape))throw new Error(`Unrecognized key: "${i}"`);t[i]&&(o[i]=n.shape[i])}return Q(this,"shape",o),o},checks:[]}))}function bo(e,t){const n=e._zod.def,r=n.checks;if(r&&r.length>0)throw new Error(".omit() cannot be used on object schemas containing refinements");return B(e,U(e._zod.def,{get shape(){const o={...e._zod.def.shape};for(const i in t){if(!(i in n.shape))throw new Error(`Unrecognized key: "${i}"`);t[i]&&delete o[i]}return Q(this,"shape",o),o},checks:[]}))}function wo(e,t){if(!oe(t))throw new Error("Invalid input to extend: expected a plain object");const n=e._zod.def.checks;if(n&&n.length>0){const r=e._zod.def.shape;for(const o in t)if(Object.getOwnPropertyDescriptor(r,o)!==void 0)throw new Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}return B(e,U(e._zod.def,{get shape(){const r={...e._zod.def.shape,...t};return Q(this,"shape",r),r}}))}function ko(e,t){if(!oe(t))throw new Error("Invalid input to safeExtend: expected a plain object");return B(e,U(e._zod.def,{get shape(){const n={...e._zod.def.shape,...t};return Q(this,"shape",n),n}}))}function zo(e,t){return B(e,U(e._zod.def,{get shape(){const n={...e._zod.def.shape,...t._zod.def.shape};return Q(this,"shape",n),n},get catchall(){return t._zod.def.catchall},checks:[]}))}function So(e,t,n){const r=t._zod.def.checks;if(r&&r.length>0)throw new Error(".partial() cannot be used on object schemas containing refinements");return B(t,U(t._zod.def,{get shape(){const o=t._zod.def.shape,i={...o};if(n)for(const a in n){if(!(a in o))throw new Error(`Unrecognized key: "${a}"`);n[a]&&(i[a]=e?new e({type:"optional",innerType:o[a]}):o[a])}else for(const a in o)i[a]=e?new e({type:"optional",innerType:o[a]}):o[a];return Q(this,"shape",i),i},checks:[]}))}function Eo(e,t,n){return B(t,U(t._zod.def,{get shape(){const r=t._zod.def.shape,o={...r};if(n)for(const i in n){if(!(i in o))throw new Error(`Unrecognized key: "${i}"`);n[i]&&(o[i]=new e({type:"nonoptional",innerType:r[i]}))}else for(const i in r)o[i]=new e({type:"nonoptional",innerType:r[i]});return Q(this,"shape",o),o}}))}function X(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue!==!0)return!0;return!1}function Et(e,t){return t.map(n=>{var r;return(r=n).path??(r.path=[]),n.path.unshift(e),n})}function pe(e){return typeof e=="string"?e:e?.message}function V(e,t,n){const r={...e,path:e.path??[]};return e.message||(r.message=pe(e.inst?._zod.def?.error?.(e))??pe(t?.error?.(e))??pe(n.customError?.(e))??pe(n.localeError?.(e))??"Invalid input"),delete r.inst,delete r.continue,t?.reportInput||delete r.input,r}function qe(e){return Array.isArray(e)?"array":typeof e=="string"?"string":"unknown"}function ie(...e){const[t,n,r]=e;return typeof t=="string"?{message:t,code:"custom",input:n,inst:r}:{...t}}var Tt=(e,t)=>{e.name="$ZodError",Object.defineProperty(e,"_zod",{value:e._zod,enumerable:!1}),Object.defineProperty(e,"issues",{value:t,enumerable:!1}),e.message=JSON.stringify(t,Re,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},At=l("$ZodError",Tt),O=l("$ZodError",Tt,{Parent:Error});function To(e,t=n=>n.message){const n={},r=[];for(const o of e.issues)o.path.length>0?(n[o.path[0]]=n[o.path[0]]||[],n[o.path[0]].push(t(o))):r.push(t(o));return{formErrors:r,fieldErrors:n}}function Ao(e,t=n=>n.message){const n={_errors:[]},r=o=>{for(const i of o.issues)if(i.code==="invalid_union"&&i.errors.length)i.errors.map(a=>r({issues:a}));else if(i.code==="invalid_key")r({issues:i.issues});else if(i.code==="invalid_element")r({issues:i.issues});else if(i.path.length===0)n._errors.push(t(i));else{let a=n,s=0;for(;s<i.path.length;){const c=i.path[s];s!==i.path.length-1?a[c]=a[c]||{_errors:[]}:(a[c]=a[c]||{_errors:[]},a[c]._errors.push(t(i))),a=a[c],s++}}};return r(e),n}var fe=e=>(t,n,r,o)=>{const i=r?Object.assign(r,{async:!1}):{async:!1},a=t._zod.run({value:n,issues:[]},i);if(a instanceof Promise)throw new Y;if(a.issues.length){const s=new(o?.Err??e)(a.issues.map(c=>V(c,i,J())));throw zt(s,o?.callee),s}return a.value},qc=fe(O),ge=e=>async(t,n,r,o)=>{const i=r?Object.assign(r,{async:!0}):{async:!0};let a=t._zod.run({value:n,issues:[]},i);if(a instanceof Promise&&(a=await a),a.issues.length){const s=new(o?.Err??e)(a.issues.map(c=>V(c,i,J())));throw zt(s,o?.callee),s}return a.value},jc=ge(O),he=e=>(t,n,r)=>{const o=r?{...r,async:!1}:{async:!1},i=t._zod.run({value:n,issues:[]},o);if(i instanceof Promise)throw new Y;return i.issues.length?{success:!1,error:new(e??At)(i.issues.map(a=>V(a,o,J())))}:{success:!0,data:i.value}},$o=he(O),me=e=>async(t,n,r)=>{const o=r?Object.assign(r,{async:!0}):{async:!0};let i=t._zod.run({value:n,issues:[]},o);return i instanceof Promise&&(i=await i),i.issues.length?{success:!1,error:new e(i.issues.map(a=>V(a,o,J())))}:{success:!0,data:i.value}},Io=me(O),$t=e=>(t,n,r)=>{const o=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return fe(e)(t,n,o)},Dc=$t(O),It=e=>(t,n,r)=>fe(e)(t,n,r),Uc=It(O),Pt=e=>async(t,n,r)=>{const o=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return ge(e)(t,n,o)},Bc=Pt(O),Ct=e=>async(t,n,r)=>ge(e)(t,n,r),Mc=Ct(O),Ot=e=>(t,n,r)=>{const o=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return he(e)(t,n,o)},Fc=Ot(O),Zt=e=>(t,n,r)=>he(e)(t,n,r),Hc=Zt(O),Rt=e=>async(t,n,r)=>{const o=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return me(e)(t,n,o)},Jc=Rt(O),Nt=e=>async(t,n,r)=>me(e)(t,n,r),Qc=Nt(O),Po=/^[cC][^\s-]{8,}$/,Co=/^[0-9a-z]+$/,Oo=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,Zo=/^[0-9a-vA-V]{20}$/,Ro=/^[A-Za-z0-9]{27}$/,No=/^[a-zA-Z0-9_-]{21}$/,xo=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,Lo=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,xt=e=>e?new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,qo=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,jo="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";function Do(){return new RegExp(jo,"u")}var Uo=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,Bo=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,Mo=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,Fo=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Ho=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,Lt=/^[A-Za-z0-9_-]*$/,Jo=/^\+[1-9]\d{6,14}$/,qt="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))",Qo=new RegExp(`^${qt}$`);function jt(e){const t="(?:[01]\\d|2[0-3]):[0-5]\\d";return typeof e.precision=="number"?e.precision===-1?`${t}`:e.precision===0?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`}function Vo(e){return new RegExp(`^${jt(e)}$`)}function Wo(e){const t=jt({precision:e.precision}),n=["Z"];e.local&&n.push(""),e.offset&&n.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");const r=`${t}(?:${n.join("|")})`;return new RegExp(`^${qt}T(?:${r})$`)}var Go=e=>{const t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??""}}`:"[\\s\\S]*";return new RegExp(`^${t}$`)},Ko=/^(?:true|false)$/i,Yo=/^[^A-Z]*$/,Xo=/^[^a-z]*$/,Z=l("$ZodCheck",(e,t)=>{var n;e._zod??(e._zod={}),e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),ei=l("$ZodCheckMaxLength",(e,t)=>{var n;Z.init(e,t),(n=e._zod.def).when??(n.when=r=>{const o=r.value;return!xe(o)&&o.length!==void 0}),e._zod.onattach.push(r=>{const o=r._zod.bag.maximum??Number.POSITIVE_INFINITY;t.maximum<o&&(r._zod.bag.maximum=t.maximum)}),e._zod.check=r=>{const o=r.value;if(o.length<=t.maximum)return;const i=qe(o);r.issues.push({origin:i,code:"too_big",maximum:t.maximum,inclusive:!0,input:o,inst:e,continue:!t.abort})}}),ti=l("$ZodCheckMinLength",(e,t)=>{var n;Z.init(e,t),(n=e._zod.def).when??(n.when=r=>{const o=r.value;return!xe(o)&&o.length!==void 0}),e._zod.onattach.push(r=>{const o=r._zod.bag.minimum??Number.NEGATIVE_INFINITY;t.minimum>o&&(r._zod.bag.minimum=t.minimum)}),e._zod.check=r=>{const o=r.value;if(o.length>=t.minimum)return;const i=qe(o);r.issues.push({origin:i,code:"too_small",minimum:t.minimum,inclusive:!0,input:o,inst:e,continue:!t.abort})}}),ni=l("$ZodCheckLengthEquals",(e,t)=>{var n;Z.init(e,t),(n=e._zod.def).when??(n.when=r=>{const o=r.value;return!xe(o)&&o.length!==void 0}),e._zod.onattach.push(r=>{const o=r._zod.bag;o.minimum=t.length,o.maximum=t.length,o.length=t.length}),e._zod.check=r=>{const o=r.value,i=o.length;if(i===t.length)return;const a=qe(o),s=i>t.length;r.issues.push({origin:a,...s?{code:"too_big",maximum:t.length}:{code:"too_small",minimum:t.length},inclusive:!0,exact:!0,input:r.value,inst:e,continue:!t.abort})}}),_e=l("$ZodCheckStringFormat",(e,t)=>{var n,r;Z.init(e,t),e._zod.onattach.push(o=>{const i=o._zod.bag;i.format=t.format,t.pattern&&(i.patterns??(i.patterns=new Set),i.patterns.add(t.pattern))}),t.pattern?(n=e._zod).check??(n.check=o=>{t.pattern.lastIndex=0,!t.pattern.test(o.value)&&o.issues.push({origin:"string",code:"invalid_format",format:t.format,input:o.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(r=e._zod).check??(r.check=()=>{})}),ri=l("$ZodCheckRegex",(e,t)=>{_e.init(e,t),e._zod.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:"string",code:"invalid_format",format:"regex",input:n.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),oi=l("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=Yo),_e.init(e,t)}),ii=l("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=Xo),_e.init(e,t)}),ai=l("$ZodCheckIncludes",(e,t)=>{Z.init(e,t);const n=de(t.includes),r=new RegExp(typeof t.position=="number"?`^.{${t.position}}${n}`:n);t.pattern=r,e._zod.onattach.push(o=>{const i=o._zod.bag;i.patterns??(i.patterns=new Set),i.patterns.add(r)}),e._zod.check=o=>{o.value.includes(t.includes,t.position)||o.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:t.includes,input:o.value,inst:e,continue:!t.abort})}}),si=l("$ZodCheckStartsWith",(e,t)=>{Z.init(e,t);const n=new RegExp(`^${de(t.prefix)}.*`);t.pattern??(t.pattern=n),e._zod.onattach.push(r=>{const o=r._zod.bag;o.patterns??(o.patterns=new Set),o.patterns.add(n)}),e._zod.check=r=>{r.value.startsWith(t.prefix)||r.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:t.prefix,input:r.value,inst:e,continue:!t.abort})}}),ci=l("$ZodCheckEndsWith",(e,t)=>{Z.init(e,t);const n=new RegExp(`.*${de(t.suffix)}$`);t.pattern??(t.pattern=n),e._zod.onattach.push(r=>{const o=r._zod.bag;o.patterns??(o.patterns=new Set),o.patterns.add(n)}),e._zod.check=r=>{r.value.endsWith(t.suffix)||r.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:t.suffix,input:r.value,inst:e,continue:!t.abort})}}),ui=l("$ZodCheckOverwrite",(e,t)=>{Z.init(e,t),e._zod.check=n=>{n.value=t.tx(n.value)}}),li=class{constructor(e=[]){this.content=[],this.indent=0,this&&(this.args=e)}indented(e){this.indent+=1,e(this),this.indent-=1}write(e){if(typeof e=="function"){e(this,{execution:"sync"}),e(this,{execution:"async"});return}const t=e.split(`
|
|
49
49
|
`).filter(o=>o),n=Math.min(...t.map(o=>o.length-o.trimStart().length)),r=t.map(o=>o.slice(n)).map(o=>" ".repeat(this.indent*2)+o);for(const o of r)this.content.push(o)}compile(){const e=Function,t=this?.args,n=[...(this?.content??[""]).map(r=>` ${r}`)];return new e(...t,n.join(`
|
|
50
50
|
`))}},di={major:4,minor:3,patch:6},T=l("$ZodType",(e,t)=>{var n;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=di;const r=[...e._zod.def.checks??[]];e._zod.traits.has("$ZodCheck")&&r.unshift(e);for(const o of r)for(const i of o._zod.onattach)i(e);if(r.length===0)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{const o=(a,s,c)=>{let u=X(a),d;for(const g of s){if(g._zod.def.when){if(!g._zod.def.when(a))continue}else if(u)continue;const p=a.issues.length,f=g._zod.check(a);if(f instanceof Promise&&c?.async===!1)throw new Y;if(d||f instanceof Promise)d=(d??Promise.resolve()).then(async()=>{await f,a.issues.length!==p&&(u||(u=X(a,p)))});else{if(a.issues.length===p)continue;u||(u=X(a,p))}}return d?d.then(()=>a):a},i=(a,s,c)=>{if(X(a))return a.aborted=!0,a;const u=o(s,r,c);if(u instanceof Promise){if(c.async===!1)throw new Y;return u.then(d=>e._zod.parse(d,c))}return e._zod.parse(u,c)};e._zod.run=(a,s)=>{if(s.skipChecks)return e._zod.parse(a,s);if(s.direction==="backward"){const u=e._zod.parse({value:a.value,issues:[]},{...s,skipChecks:!0});return u instanceof Promise?u.then(d=>i(d,a,s)):i(u,a,s)}const c=e._zod.parse(a,s);if(c instanceof Promise){if(s.async===!1)throw new Y;return c.then(u=>o(u,r,s))}return o(c,r,s)}}v(e,"~standard",()=>({validate:o=>{try{const i=$o(e,o);return i.success?{value:i.data}:{issues:i.error?.issues}}catch{return Io(e,o).then(a=>a.success?{value:a.data}:{issues:a.error?.issues})}},vendor:"zod",version:1}))}),je=l("$ZodString",(e,t)=>{T.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??Go(e._zod.bag),e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=String(n.value)}catch{}return typeof n.value=="string"||n.issues.push({expected:"string",code:"invalid_type",input:n.value,inst:e}),n}}),w=l("$ZodStringFormat",(e,t)=>{_e.init(e,t),je.init(e,t)}),pi=l("$ZodGUID",(e,t)=>{t.pattern??(t.pattern=Lo),w.init(e,t)}),fi=l("$ZodUUID",(e,t)=>{if(t.version){const n={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(n===void 0)throw new Error(`Invalid UUID version: "${t.version}"`);t.pattern??(t.pattern=xt(n))}else t.pattern??(t.pattern=xt());w.init(e,t)}),gi=l("$ZodEmail",(e,t)=>{t.pattern??(t.pattern=qo),w.init(e,t)}),hi=l("$ZodURL",(e,t)=>{w.init(e,t),e._zod.check=n=>{try{const r=n.value.trim(),o=new URL(r);t.hostname&&(t.hostname.lastIndex=0,t.hostname.test(o.hostname)||n.issues.push({code:"invalid_format",format:"url",note:"Invalid hostname",pattern:t.hostname.source,input:n.value,inst:e,continue:!t.abort})),t.protocol&&(t.protocol.lastIndex=0,t.protocol.test(o.protocol.endsWith(":")?o.protocol.slice(0,-1):o.protocol)||n.issues.push({code:"invalid_format",format:"url",note:"Invalid protocol",pattern:t.protocol.source,input:n.value,inst:e,continue:!t.abort})),t.normalize?n.value=o.href:n.value=r;return}catch{n.issues.push({code:"invalid_format",format:"url",input:n.value,inst:e,continue:!t.abort})}}}),mi=l("$ZodEmoji",(e,t)=>{t.pattern??(t.pattern=Do()),w.init(e,t)}),_i=l("$ZodNanoID",(e,t)=>{t.pattern??(t.pattern=No),w.init(e,t)}),yi=l("$ZodCUID",(e,t)=>{t.pattern??(t.pattern=Po),w.init(e,t)}),vi=l("$ZodCUID2",(e,t)=>{t.pattern??(t.pattern=Co),w.init(e,t)}),bi=l("$ZodULID",(e,t)=>{t.pattern??(t.pattern=Oo),w.init(e,t)}),wi=l("$ZodXID",(e,t)=>{t.pattern??(t.pattern=Zo),w.init(e,t)}),ki=l("$ZodKSUID",(e,t)=>{t.pattern??(t.pattern=Ro),w.init(e,t)}),zi=l("$ZodISODateTime",(e,t)=>{t.pattern??(t.pattern=Wo(t)),w.init(e,t)}),Si=l("$ZodISODate",(e,t)=>{t.pattern??(t.pattern=Qo),w.init(e,t)}),Ei=l("$ZodISOTime",(e,t)=>{t.pattern??(t.pattern=Vo(t)),w.init(e,t)}),Ti=l("$ZodISODuration",(e,t)=>{t.pattern??(t.pattern=xo),w.init(e,t)}),Ai=l("$ZodIPv4",(e,t)=>{t.pattern??(t.pattern=Uo),w.init(e,t),e._zod.bag.format="ipv4"}),$i=l("$ZodIPv6",(e,t)=>{t.pattern??(t.pattern=Bo),w.init(e,t),e._zod.bag.format="ipv6",e._zod.check=n=>{try{new URL(`http://[${n.value}]`)}catch{n.issues.push({code:"invalid_format",format:"ipv6",input:n.value,inst:e,continue:!t.abort})}}}),Ii=l("$ZodCIDRv4",(e,t)=>{t.pattern??(t.pattern=Mo),w.init(e,t)}),Pi=l("$ZodCIDRv6",(e,t)=>{t.pattern??(t.pattern=Fo),w.init(e,t),e._zod.check=n=>{const r=n.value.split("/");try{if(r.length!==2)throw new Error;const[o,i]=r;if(!i)throw new Error;const a=Number(i);if(`${a}`!==i)throw new Error;if(a<0||a>128)throw new Error;new URL(`http://[${o}]`)}catch{n.issues.push({code:"invalid_format",format:"cidrv6",input:n.value,inst:e,continue:!t.abort})}}});function Dt(e){if(e==="")return!0;if(e.length%4!==0)return!1;try{return atob(e),!0}catch{return!1}}var Ci=l("$ZodBase64",(e,t)=>{t.pattern??(t.pattern=Ho),w.init(e,t),e._zod.bag.contentEncoding="base64",e._zod.check=n=>{Dt(n.value)||n.issues.push({code:"invalid_format",format:"base64",input:n.value,inst:e,continue:!t.abort})}});function Oi(e){if(!Lt.test(e))return!1;const t=e.replace(/[-_]/g,n=>n==="-"?"+":"/");return Dt(t.padEnd(Math.ceil(t.length/4)*4,"="))}var Zi=l("$ZodBase64URL",(e,t)=>{t.pattern??(t.pattern=Lt),w.init(e,t),e._zod.bag.contentEncoding="base64url",e._zod.check=n=>{Oi(n.value)||n.issues.push({code:"invalid_format",format:"base64url",input:n.value,inst:e,continue:!t.abort})}}),Ri=l("$ZodE164",(e,t)=>{t.pattern??(t.pattern=Jo),w.init(e,t)});function Ni(e,t=null){try{const n=e.split(".");if(n.length!==3)return!1;const[r]=n;if(!r)return!1;const o=JSON.parse(atob(r));return!("typ"in o&&o?.typ!=="JWT"||!o.alg||t&&(!("alg"in o)||o.alg!==t))}catch{return!1}}var xi=l("$ZodJWT",(e,t)=>{w.init(e,t),e._zod.check=n=>{Ni(n.value,t.alg)||n.issues.push({code:"invalid_format",format:"jwt",input:n.value,inst:e,continue:!t.abort})}}),Li=l("$ZodBoolean",(e,t)=>{T.init(e,t),e._zod.pattern=Ko,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=!!n.value}catch{}const o=n.value;return typeof o=="boolean"||n.issues.push({expected:"boolean",code:"invalid_type",input:o,inst:e}),n}}),qi=l("$ZodUnknown",(e,t)=>{T.init(e,t),e._zod.parse=n=>n}),ji=l("$ZodNever",(e,t)=>{T.init(e,t),e._zod.parse=(n,r)=>(n.issues.push({expected:"never",code:"invalid_type",input:n.value,inst:e}),n)});function Ut(e,t,n){e.issues.length&&t.issues.push(...Et(n,e.issues)),t.value[n]=e.value}var Di=l("$ZodArray",(e,t)=>{T.init(e,t),e._zod.parse=(n,r)=>{const o=n.value;if(!Array.isArray(o))return n.issues.push({expected:"array",code:"invalid_type",input:o,inst:e}),n;n.value=Array(o.length);const i=[];for(let a=0;a<o.length;a++){const s=o[a],c=t.element._zod.run({value:s,issues:[]},r);c instanceof Promise?i.push(c.then(u=>Ut(u,n,a))):Ut(c,n,a)}return i.length?Promise.all(i).then(()=>n):n}});function ye(e,t,n,r,o){if(e.issues.length){if(o&&!(n in r))return;t.issues.push(...Et(n,e.issues))}e.value===void 0?n in r&&(t.value[n]=void 0):t.value[n]=e.value}function Bt(e){const t=Object.keys(e.shape);for(const r of t)if(!e.shape?.[r]?._zod?.traits?.has("$ZodType"))throw new Error(`Invalid element at key "${r}": expected a Zod schema`);const n=yo(e.shape);return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(n)}}function Mt(e,t,n,r,o,i){const a=[],s=o.keySet,c=o.catchall._zod,u=c.def.type,d=c.optout==="optional";for(const g in t){if(s.has(g))continue;if(u==="never"){a.push(g);continue}const p=c.run({value:t[g],issues:[]},r);p instanceof Promise?e.push(p.then(f=>ye(f,n,g,t,d))):ye(p,n,g,t,d)}return a.length&&n.issues.push({code:"unrecognized_keys",keys:a,input:t,inst:i}),e.length?Promise.all(e).then(()=>n):n}var Ui=l("$ZodObject",(e,t)=>{if(T.init(e,t),!Object.getOwnPropertyDescriptor(t,"shape")?.get){const a=t.shape;Object.defineProperty(t,"shape",{get:()=>{const s={...a};return Object.defineProperty(t,"shape",{value:s}),s}})}const n=Ne(()=>Bt(t));v(e._zod,"propValues",()=>{const a=t.shape,s={};for(const c in a){const u=a[c]._zod;if(u.values){s[c]??(s[c]=new Set);for(const d of u.values)s[c].add(d)}}return s});const r=le,o=t.catchall;let i;e._zod.parse=(a,s)=>{i??(i=n.value);const c=a.value;if(!r(c))return a.issues.push({expected:"object",code:"invalid_type",input:c,inst:e}),a;a.value={};const u=[],d=i.shape;for(const g of i.keys){const p=d[g],f=p._zod.optout==="optional",h=p._zod.run({value:c[g],issues:[]},s);h instanceof Promise?u.push(h.then(_=>ye(_,a,g,c,f))):ye(h,a,g,c,f)}return o?Mt(u,c,a,s,n.value,e):u.length?Promise.all(u).then(()=>a):a}}),Bi=l("$ZodObjectJIT",(e,t)=>{Ui.init(e,t);const n=e._zod.parse,r=Ne(()=>Bt(t)),o=p=>{const f=new li(["shape","payload","ctx"]),h=r.value,_=S=>{const E=kt(S);return`shape[${E}]._zod.run({ value: input[${E}], issues: [] }, ctx)`};f.write("const input = payload.value;");const b=Object.create(null);let z=0;for(const S of h.keys)b[S]=`key_${z++}`;f.write("const newResult = {};");for(const S of h.keys){const E=b[S],N=kt(S),Nc=p[S]?._zod?.optout==="optional";f.write(`const ${E} = ${_(S)};`),Nc?f.write(`
|
package/dist/qna.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const Ut=require("./ga-datalayer-
|
|
1
|
+
const Ut=require("./ga-datalayer-BVppFxqk.cjs");var We=({element:e,renderElement:t})=>{if(!e.children||e.children.length===0)return null;const r=document.createElement("div");for(const n of e.children){const o=t(n);o&&r.appendChild(o)}return r};function Lt(e){const t=document.createElement("div");if(t.className=e.containerClassName,!e.spec.elements[e.spec.root])return t;const r=e.unknownRenderer??We,n=i=>{const a=e.spec.elements[i];if(!a)return null;const s=e.registry[a.type];return s?s({elementId:i,element:a,spec:e.spec,context:e.context,renderElement:n}):r({elementId:i,element:a,spec:e.spec,context:e.context,renderElement:n})},o=n(e.spec.root);return o&&t.appendChild(o),t}function Ft(e,t){if(!t)return e;const r={...e};for(const[n,o]of Object.entries(t))o&&(r[n]=o);return r}function ze(e){return typeof e=="object"&&e!==null&&typeof e.type=="string"}function Mt(e){const t=[];let r=0,n=!1,o=!1,i=0;for(let a=0;a<e.length;a++){const s=e[a];if(o){o=!1;continue}if(s==="\\"&&n){o=!0;continue}if(s==='"'){n=!n;continue}n||(s==="{"&&r++,s==="}"&&(r--,r===0&&(t.push(e.slice(i,a+1)),i=a+1)))}return t.length>0?t:[e]}function $e(e,t){const r=e.trim();if(!r||r.startsWith(":"))return!1;const n=r.startsWith("data: ")?r.slice(6):r;if(n==="[DONE]")return t.onDone?.(),!0;try{const o=JSON.parse(n);return ze(o)?(Ut.debugLog("stream",`event: ${o.type}`,o),t.onEvent(o),o.type==="done"?(t.onDone?.(),!0):!1):!1}catch{const o=Mt(n);if(o.length>1){for(const i of o)try{const a=JSON.parse(i);if(!ze(a))continue;if(t.onEvent(a),a.type==="done")return t.onDone?.(),!0}catch{}return!1}return!1}}async function Be(e,t){if(!e.ok){t.onError?.(new Error(`HTTP ${e.status}: ${e.statusText}`));return}if(!e.body){t.onError?.(new Error("Response body is null — streaming not supported"));return}const r=e.body.getReader(),n=new TextDecoder("utf-8");let o="";const i=t.idleTimeoutMs??6e4,a=Symbol("idle-timeout");let s=!1;try{for(;;){const c=r.read();let u;const d=await(i>0?Promise.race([c.then(g=>(clearTimeout(u),g)),new Promise(g=>{u=setTimeout(()=>g(a),i)})]):c);if(d===a){s=!0,await r.cancel();break}const{done:p,value:f}=d;if(p)break;o+=n.decode(f,{stream:!0});const m=o.split(`
|
|
2
2
|
`);o=m.pop()??"";for(const g of m)if($e(g,t))return}if(o.trim()&&$e(o,t))return}catch(c){if(c instanceof DOMException&&c.name==="AbortError")return;t.onError?.(c instanceof Error?c:new Error(String(c)))}finally{s||r.releaseLock()}t.onDone?.()}function Jt(e,t,r){const n=new AbortController,o=r.signal?Vt([r.signal,n.signal]):n.signal;return fetch(e,{method:"POST",headers:{"Content-Type":"application/json",...r.headers},body:JSON.stringify(t),signal:o}).then(i=>Be(i,{...r,signal:o})).catch(i=>{i instanceof DOMException&&i.name==="AbortError"||r.onError?.(i instanceof Error?i:new Error(String(i)))}),n}function Vt(e){const t=new AbortController,r=[];for(const n of e){if(n.aborted)return t.abort(n.reason),t.signal;const o=()=>t.abort(n.reason);n.addEventListener("abort",o,{once:!0}),r.push(()=>n.removeEventListener("abort",o))}return t.signal.addEventListener("abort",()=>{for(const n of r)n()},{once:!0}),t.signal}var Se=3,qt=(e,t)=>{const r=e.replace(/\s+/g," ").trim().replace(/^[,.;:!?•-]+|[,.;:!?•-]+$/g,"");if(!r)return"";const n=t?.stripLeadingStopWords?r.replace(/^(?:daha|için)\s+/i,"").trim():r;return n?n.split(/\s+/).slice(0,3).join(" ").trim():""},ae=(e,t)=>e?e.split(/[•,;:/()]|(?:\sve\s)|(?:\sand\s)|(?:\sile\s)|(?:\sfor\s)|(?:\swith\s)/i).map(r=>qt(r,t)).filter(Boolean):[];function Ke(e){const t=(e.display_keywords??[]).flatMap(o=>ae(o,{stripLeadingStopWords:!0})),r=t.filter((o,i)=>t.indexOf(o)===i);if(r.length>0)return r.slice(0,Se);const n=[...ae(e.chosen_attribute,{stripLeadingStopWords:!0}),...ae(e.short_name)];return n.filter((o,i)=>n.indexOf(o)===i).slice(0,Se)}function He(e){return Ke(e).join(" • ")}var Gt=["beauty_consulting","watch_expert"];function Ye(e){return typeof e=="string"&&Gt.includes(e)}function Wt(e){if(typeof e.type!="string")return null;if(Bt(e))return e;const t=e;switch(t.type){case"outputText":return Kt(t);case"suggestedActions":return Ht(t);case"productList":return Yt(t);case"productDetails":return Xt(t);case"productDetailsSimilars":return Qt(t);case"comparisonTable":return er(t);case"context":return or(t);case"chatStreamEnd":return ir();case"loading":return ar(t);case"panelLoading":return sr(t);case"similarLoading":return cr(t);case"redirect":return ur(t);case"error":return lr(t);case"dummy":return dr(t);case"launcherAction":return pr(t);case"text":return me(t);case"productItem":return fr(t);case"text_image":return Xe(t);case"quick_qna":return Qe(t);case"reviewHighlights":return mr(t);case"aiProductSuggestions":return _r(t);case"aiProductGroupings":return vr(t);case"aiSuggestedSearches":return yr(t);case"prosAndCons":return hr(t);case"getGroundingReview":return br(t);case"voice":return kr(t);case"visitorDataResponse":return gr(t);case"productListPreview":return wr();case"groupList":return zr(t);case"formGetInfo":case"formTestDrive":case"formServiceRequest":case"launchFormPage":return $r(t);case"launcherContent":return Zr(t);case"handoff":return Sr(t);case"uiSpec":return Cr(t);default:return null}}function Bt(e){const t=e.type;if(typeof t!="string")return!1;switch(t){case"metadata":return typeof e.sessionId=="string"&&typeof e.model=="string";case"text_chunk":return typeof e.content=="string";case"ui_spec":{const r=e.widget;if(r!=="chat"&&r!=="qna"&&r!=="simrel")return!1;const n=I(e.spec);return n?typeof n.root=="string"&&I(n.elements)!==null:!1}case"action":{const r=I(e.action);return r!==null&&typeof r.kind=="string"}case"error":return typeof e.code=="string"&&typeof e.message=="string";case"done":return!0;default:return!1}}function Kt(e){const t=_(e.payload.text,e.payload.plain_text)??"",r=_(e.payload.plain_text,e.payload.text)??t;if(e.payload.is_error)return{type:"error",code:"BACKEND_ERROR",message:r||"Backend returned an error"};const n={type:"text_chunk",content:t,final:!0},o=e.payload.product_mentions;Array.isArray(o)&&o.length>0&&(n.productMentions=o.filter(c=>typeof c=="object"&&c!==null&&typeof c.sku=="string"&&typeof c.short_name=="string"));const i=e.payload.sku_to_product_item;i&&typeof i=="object"&&!Array.isArray(i)&&(n.skuToProductItem=i);const a=e.payload.conversation_mode;typeof a=="string"&&a&&(n.conversationMode=a);const s=e.payload.render_hint;return typeof s=="string"&&s&&(n.renderHint=s),e.payload.kvkk===!0&&(n.kvkk=!0),n}function Ht(e){return et((e.payload.actions??[]).map(t=>{const r=_(t.title)??"",n=j(t.requestDetails,r),o=n?{label:r,action:n}:null;return o?(typeof t.icon=="string"&&(o.icon=t.icon),typeof t.image=="string"&&(o.image=t.image),o):null}).filter(he),"chat")}function Yt(e){const t=(Array.isArray(e.payload.style_variations)?e.payload.style_variations:[]).map(a=>{const s=_(a.style_label),c=_(a.style_mood),u=_(a.image_url??void 0),d=(Array.isArray(a.product_list)?a.product_list:[]).map(f=>{const m=I(f);return m?rt(I(m.product_detail)??I(m.product)??m):null}).filter(he),p=Array.isArray(a.recommendation_groups)?a.recommendation_groups.map(f=>({label:_(f.label)??"",reason:_(f.reason)??"",skus:Array.isArray(f.skus)?f.skus.filter(m=>typeof m=="string"&&m.trim().length>0):[]})):[];return{style_label:s??"",style_mood:c??"",...u?{image_url:u}:{},product_list:d,recommendation_groups:p}}).filter(a=>a.product_list.length>0),r=e.payload.product_list??[],n=Ye(e.payload.source)&&t.length>0?t[0].product_list:null,o=n?Or(n,"chat"):tt(r,"chat");o.panelHint="panel";const i=o.spec.elements[o.spec.root];if(i){const a={};typeof e.payload.offset=="number"&&(a.offset=e.payload.offset),typeof e.payload.end_of_list=="boolean"&&(a.endOfList=e.payload.end_of_list),typeof e.payload.title=="string"&&(a.panelTitle=e.payload.title),typeof e.payload.source=="string"&&(a.source=e.payload.source),t.length>0&&(a.styleVariations=t),Object.keys(a).length>0&&(i.props={...i.props,...a})}return o}function Xt(e){const t=e.payload.productDetails;if(!t)return Er("chat");const r=R(t);return{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"ProductDetailsPanel",props:{product:{...t,...r}}}}},panelHint:"panel"}}function Qt(e){const t=tt(e.payload.similarProducts??[],"chat"),r=t.spec.elements[t.spec.root];return r&&(r.props={...r.props,similarsAppend:!0}),{...t,panelHint:"panel"}}function er(e){const t=e.payload.multiple_product_details??[],r=e.payload,n={key_differences:r.key_differences,recommended_choice:r.recommended_choice,recommended_choice_sku:r.recommended_choice_sku,special_considerations:r.special_considerations,criteria_view:r.criteria_view,criteria_view_short:r.criteria_view_short,compared_field_names:r.compared_field_names,winner_product:r.winner_product,winner_hits:r.winner_hits,...e.payload.product_comparison_framework??{}},o=e.payload.table,i=e.payload.features_list,a=[];for(const $ of t){const Z=R($);a.push(Z)}const s=tr(o,a,n,i);let c;n?.recommended_choice_sku?c=n.recommended_choice_sku:n?.winner_product&&n.winner_product.length>0&&(c=n.winner_product[0]?.product_detail?.sku??n.winner_product[0]?.sku);const u=c?a.find($=>$.sku===c)??a[0]:a[0],d=[];if(Array.isArray(n?.key_differences))for(const $ of n.key_differences)typeof $=="string"&&d.push($);const p=Ar(n?.special_considerations),f=n?.recommended_choice,m=n?.winner_hits,g={};for(const $ of a){const Z=$.sku;Z&&(g[Z]={title:$.name??Z,type:"launchSingleProduct",payload:{sku:Z}})}const y={products:a,attributes:s,highlights:d,productActions:g};return u&&(y.recommended=u),p.length>0&&(y.specialCases=p),f&&(y.recommendedText=f),m&&(y.winnerHits=m),typeof n?.key_differences=="string"&&(y.keyDifferencesHtml=n.key_differences),n?.special_considerations&&(y.specialConsiderations=n.special_considerations),{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"ComparisonTable",props:y}}},panelHint:"panel"}}function tr(e,t,r,n){if(!e)return[];const o=Object.entries(e);if(o.length===0)return[];const i=o[0]?.[1];if(Array.isArray(i)){const p=r.criteria_view??r.criteria_view_short??{},f=r.compared_field_names??Object.keys(e),m=[];for(const g of f){const y=e[g];if(!y||!Array.isArray(y))continue;const $=p[g]??g;m.push({label:$,values:y.map(Z=>typeof Z=="string"?Z:String(Z??""))})}return m}const a=e,s=t.map(p=>String(p.sku??"")).filter(p=>p.length>0),c=r.criteria_view??r.criteria_view_short??{},u=(n&&n.length>0?n:r.compared_field_names&&r.compared_field_names.length>0?r.compared_field_names:rr(a)).filter(p=>p!=="name"&&p!=="name_short"&&!p.endsWith("_short")),d=[];for(const p of u){const f=s.map(g=>{const y=a[g];if(!y||typeof y!="object")return"";const $=y[`${p}_short`],Z=y[p];return nr($??Z)});if(f.every(g=>g.length===0))continue;const m=c[p]??p;d.push({label:m,values:f})}return d}function rr(e){const t=[],r=new Set;for(const n of Object.values(e))if(!(!n||typeof n!="object"))for(const o of Object.keys(n))r.has(o)||(r.add(o),t.push(o));return t}function nr(e){return typeof e=="string"?e:typeof e=="number"||typeof e=="boolean"?String(e):""}function or(e){return{type:"metadata",sessionId:"",model:"",meta:{panel:e.payload.panel,messages:e.payload.messages,message_id:e.payload.message_id}}}function ir(){return{type:"done"}}function ar(e){return{type:"metadata",sessionId:"",model:"",meta:{loading:!0,loadingText:e.payload.text,thinkingMessages:e.payload.thinking_messages,dynamicLoading:e.payload.is_dynamic===!0}}}function sr(e){return{type:"metadata",sessionId:"",model:"",meta:{loading:!0,panelLoading:!0,panelPendingType:e.payload?.pending_type,loadingText:e.payload?.text}}}function cr(e){return{type:"metadata",sessionId:"",model:"",meta:{loading:!0,similarPanelLoading:!0,panelPendingType:e.payload?.pending_type,loadingText:e.payload?.text}}}function ur(e){const t=_(e.payload.url);return t?{type:"action",action:{kind:"navigate",url:t,newTab:e.payload.new_tab===!0}}:{type:"metadata",sessionId:"",model:"",meta:{redirect:e.payload,redirectTarget:_(e.payload.to)}}}function lr(e){return{type:"error",code:"BACKEND_ERROR",message:_(e.payload?.text,e.payload?.message,e.payload?.error)??"Backend returned an error"}}function dr(e){return{type:"metadata",sessionId:"",model:"",meta:{noop:!0}}}function pr(e){const t=e.payload??{};if(Array.isArray(t.action_list)){const o={action_list:t.action_list},i=typeof t.type=="string"?t.type:void 0,a=typeof t.theme=="string"?t.theme:void 0;return i!==void 0&&(o.type=i),a!==void 0&&(o.theme=a),Qe({type:"quick_qna",payload:o})}const r=I(t.action);if(r){const o={action:r},i=typeof t.text=="string"?t.text:void 0,a=typeof t.image_url=="string"?t.image_url:void 0,s=typeof t.theme=="string"?t.theme:void 0;return i!==void 0&&(o.text=i),a!==void 0&&(o.image_url=a),s!==void 0&&(o.theme=s),Xe({type:"text_image",payload:o})}const n=typeof t.text=="string"?t.text:"";if(n){const o={text:n},i=typeof t.type=="string"?t.type:void 0,a=typeof t.theme=="string"?t.theme:void 0,s=I(t.payload)??void 0;return i!==void 0&&(o.type=i),s!==void 0&&(o.payload=s),a!==void 0&&(o.theme=a),me({type:"text",payload:o})}return{type:"metadata",sessionId:"",model:"",meta:{launcherAction:t}}}function me(e){const t={text:_(e.payload.text)??""};return typeof e.payload.theme=="string"&&(t.theme=e.payload.theme),e.payload.payload!==void 0&&(t.payload=e.payload.payload),{type:"ui_spec",widget:"qna",spec:{root:"root",elements:{root:{type:"QuestionHeading",props:t}}}}}function fr(e){return Pr(e.payload,"qna")}function Xe(e){const t=_(e.payload.text)??"",r=j(e.payload.action,t);if(r){const o={label:t||r.title,action:r};return typeof e.payload.image_url=="string"&&(o.image=e.payload.image_url),typeof e.payload.theme=="string"&&(o.theme=e.payload.theme),{type:"ui_spec",widget:"qna",spec:{root:"root",elements:{root:{type:"ActionButton",props:o}}}}}const n={text:t};return typeof e.payload.theme=="string"&&(n.theme=e.payload.theme),me({type:"text",payload:n})}function Qe(e){return et((e.payload.action_list??[]).map(t=>{const r=_(t.title)??"",n=j(t.requestDetails,r),o=n?{label:r,action:n}:null;return o?(typeof t.icon=="string"&&(o.icon=t.icon),typeof t.image=="string"&&(o.image=t.image),o):null}).filter(he),"qna")}function mr(e){const t={reviews:(e.payload.reviews??[]).map(r=>{const n={};return typeof r.review_class=="string"&&(n.review_class=r.review_class),typeof r.review_text=="string"&&(n.review_text=r.review_text),(typeof r.review_rating=="string"||typeof r.review_rating=="number")&&(n.review_rating=r.review_rating),typeof r.review_tag=="string"&&(n.review_tag=r.review_tag),n})};return typeof e.payload.sku=="string"&&(t.sku=e.payload.sku),{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"ReviewHighlights",props:t}}}}}function hr(e){const t={};return Array.isArray(e.payload.pros)&&(t.pros=e.payload.pros),Array.isArray(e.payload.cons)&&(t.cons=e.payload.cons),typeof e.payload.product_name=="string"&&(t.productName=e.payload.product_name),{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"ProsAndCons",props:t}}}}}function gr(e){return{type:"metadata",sessionId:"",model:"",meta:{visitorDataResponse:e.payload}}}function _r(e){const t=e.payload.product_suggestions??[],r=[];for(let n=0;n<t.length;n++){const o=t[n];if(!o)continue;const i=Ir(o);if(!i)continue;const a={product:i},s=j(o.requestDetails,i.name);s&&(a.action=s),typeof o.role=="string"&&(a.role=o.role),typeof o.reason=="string"&&(a.reason=o.reason),typeof o.review_highlight=="string"&&(a.reviewHighlight=o.review_highlight),Array.isArray(o.labels)&&(a.labels=o.labels),typeof o.expert_quality_score=="number"&&(a.expertQualityScore=o.expert_quality_score),r.push(a)}return r.length===0?{type:"metadata",sessionId:"",model:"",meta:{aiProductSuggestions:e.payload.product_suggestions??[]}}:{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"AITopPicks",props:{suggestions:r}}}}}}function vr(e){const t=e.payload.product_groupings??[],r=[];for(let n=0;n<t.length;n++){const o=t[n];if(!o)continue;const i=_(o.name)??"",a=o.sku&&o.sku.length>0?{type:"findSimilar",payload:{sku:o.sku}}:void 0,s=j(o.requestDetails??a,i);if(!s)continue;const c={name:i,action:s};if(Array.isArray(o.labels)){const u=o.labels.filter(d=>typeof d=="string");u.length>0&&(c.labels=u)}typeof o.image=="string"&&(c.image=o.image),r.push(c)}return r.length===0?{type:"metadata",sessionId:"",model:"",meta:{aiProductGroupings:e.payload.product_groupings??[]}}:{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"AIGroupingCards",props:{entries:r}}}}}}function yr(e){const t=e.payload.suggested_searches??[],r=[];for(let n=0;n<t.length;n++){const o=t[n];if(!o)continue;const i=_(o.short_name,o.chosen_attribute,o.detailed_user_message)??`Search ${n+1}`,a={},s=_(o.detailed_user_message);s&&(a.text=s);const c=I(I(o.requestDetails)?.payload),u=c?.group_skus;o.group_skus&&Array.isArray(o.group_skus)?a.group_skus=o.group_skus:Array.isArray(u)&&(a.group_skus=u.filter(Z=>typeof Z=="string"));const d=_(o.sku,o.representative_product_sku,c?.sku);d&&(a.sku=d),a.is_suggested_text=1;const p={type:"inputText",payload:a},f=j(o.requestDetails,i),m=f?.type==="findSimilar"&&typeof a.text=="string"?j(p,i):f??j(p,i);if(!m)continue;const g={shortName:i,action:m},y=_(o.detailed_user_message);y&&y!==i&&(g.detailedMessage=y);const $=He(o);$&&$!==i&&$!==(y??"")&&(g.whyDifferent=$),typeof o.image=="string"&&(g.image=o.image),r.push(g)}return r.length===0?{type:"metadata",sessionId:"",model:"",meta:{aiSuggestedSearches:e.payload.suggested_searches??[]}}:{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"AISuggestedSearchCards",props:{entries:r}}}}}}function br(e){const t=e.payload,r=j(t.requestDetails??t.request_details,_(t.review_count,t.reviewCount,t.text,t.title)??"Show product reviews");if(!r)return{type:"metadata",sessionId:"",model:"",meta:{groundingReview:t}};const n={action:r};return t.title&&(n.title=t.title),t.text&&(n.text=t.text),t.review_count?n.reviewCount=t.review_count:typeof t.reviewCount=="string"&&t.reviewCount.trim()&&(n.reviewCount=t.reviewCount),{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"GroundingReviewCard",props:n}}}}}function wr(){return{type:"metadata",sessionId:"",model:"",meta:{analyzeAnimation:!0}}}function kr(e){return{type:"metadata",sessionId:"",model:"",meta:{voice:e.payload}}}function zr(e){const t=e.payload.group_list??[],r=[];for(const o of t){const i=o.group_name??"",a=(o.product_list??[]).map(R);r.push({groupName:i,products:a})}const n=[];for(const o of e.payload.filter_tags??[]){const i=o.title??"";if(!i)continue;const a=j(o.requestDetails,i),s={title:i};a&&(s.action=a),n.push(s)}return{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"CategoriesContainer",props:{groups:r,filterTags:n}}}},panelHint:"panel"}}function $r(e){return{type:"metadata",sessionId:"",model:"",meta:{formType:e.type,formPayload:e.payload??{}}}}function Sr(e){const t={};return typeof e.payload?.summary=="string"&&(t.summary=e.payload.summary),Array.isArray(e.payload?.products_discussed)&&(t.products_discussed=e.payload.products_discussed),typeof e.payload?.user_sentiment=="string"&&(t.user_sentiment=e.payload.user_sentiment),{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"HandoffNotice",props:t}}}}}function Zr(e){return{type:"metadata",sessionId:"",model:"",meta:{launcherContent:e.payload??{}}}}function et(e,t){const r={},n=[];for(let o=0;o<e.length;o++){const i=e[o];if(!i)continue;const a=`action-${o}`;n.push(a);const s={label:i.label,action:i.action};i.icon!==void 0&&(s.icon=i.icon),i.image!==void 0&&(s.image=i.image),i.description!==void 0&&(s.description=i.description),r[a]={type:"ActionButton",props:s}}return r.root={type:"ActionButtons",props:{buttons:e.map(o=>{const i={label:o.label,action:o.action};return o.image!==void 0&&(i.image=o.image),o.description!==void 0&&(i.description=o.description),o.icon!==void 0&&(i.icon=o.icon),i})},children:n},{type:"ui_spec",widget:t,spec:{root:"root",elements:r}}}function tt(e,t){const r={},n=[];for(let o=0;o<e.length;o++){const i=e[o];if(!i)continue;const a=R(i),s=`product-${o}`;n.push(s);const c={product:a,index:o};a.sku&&(c.action={title:a.name,type:"launchSingleProduct",payload:{sku:a.sku}}),r[s]={type:"ProductCard",props:c}}return r.root={type:"ProductGrid",props:{layout:"grid"},children:n},{type:"ui_spec",widget:t,spec:{root:"root",elements:r}}}function Or(e,t){const r={},n=[];for(let o=0;o<e.length;o++){const i=e[o];if(!i)continue;const a=`product-${o}`;n.push(a);const s={product:i,index:o},c=i.sku;c&&(s.action={title:i.name??"",type:"launchSingleProduct",payload:{sku:c}}),r[a]={type:"ProductCard",props:s}}return r.root={type:"ProductGrid",props:{layout:"grid"},children:n},{type:"ui_spec",widget:t,spec:{root:"root",elements:r}}}function Pr(e,t){return{type:"ui_spec",widget:t,spec:{root:"root",elements:{root:{type:"ProductCard",props:{product:R(e),index:0}}}}}}function Er(e){return{type:"ui_spec",widget:e,spec:{root:"root",elements:{root:{type:"ActionButtons",props:{buttons:[]},children:[]}}}}}function Ir(e){const t=_(e.sku),r=_(e.short_name),n={...I(e.product_item)??e},o=_(e.discount_reason,e.discountReason);return o&&!_(n.discount_reason,n.discountReason)&&(n.discount_reason=o),rt(n,t,r)}function rt(e,t,r){const n=_(e.sku,t),o=_(e.name,r);if(!n||!o)return null;const i={sku:n,name:o},a=_(e.brand);a&&(i.brand=a);const s=_(e.url);s&&(i.url=s);const c=Tr(e.images);if(c.length>0)i.images=c;else{const y=_(e.image,e.image_url,e.imageUrl);y&&(i.images=[y])}const u=W(e.price_discounted);u!==void 0&&(i.price_discounted=u);const d=W(e.price);d!==void 0&&(i.price=d);const p=W(e.rating);p!==void 0&&(i.rating=p);const f=W(e.review_count)??W(e.reviewCount);f!==void 0&&(i.review_count=f);const m=_(e.cart_code,e.cartCode);m&&(i.cart_code=m),typeof e.in_stock=="boolean"&&(i.in_stock=e.in_stock),typeof e.inStock=="boolean"&&(i.in_stock=e.inStock);const g=_(e.discount_reason,e.discountReason);return g&&(i.discount_reason=g),R(i)}function j(e,t){const r=I(e);if(!r)return null;const n=r.type;if(typeof n!="string"||n.length===0)return null;const o={title:t||n,type:n};return r.payload!==void 0&&(o.payload=r.payload),o}function I(e){return!e||typeof e!="object"||Array.isArray(e)?null:e}function _(...e){for(const t of e)if(typeof t=="string"){const r=t.trim();if(r.length>0)return r}}function Tr(e){return Array.isArray(e)?e.filter(t=>typeof t=="string"&&t.length>0):[]}function Ar(e){if(typeof e=="string"){const t=e.trim();return t?[t]:[]}return Array.isArray(e)?e.filter(t=>typeof t=="string").map(t=>t.trim()).filter(t=>t.length>0):[]}function W(e){if(typeof e=="number"&&Number.isFinite(e))return e;if(typeof e=="string"){let t;e.includes(".")&&e.includes(",")?t=e.replace(/\./g,"").replace(",","."):t=e.replace(",",".");const r=Number(t);if(Number.isFinite(r))return r}}function he(e){return e!=null}var Nr=new Set(["sku","name","brand","images","price","price_discounted","price_discount_rate","price_currency","discount_reason","url","rating","review_count","cart_code","in_stock","description","description_html","features","specifications","facet_tags","short_name","category_ids","category_names","variants","facet_hits","promotions"]);function R(e){const t=e.price_discounted!=null&&e.price_discounted>0,r=t?e.price_discounted:e.price,n=t&&e.price!=null?e.price:void 0;let o;n!=null&&r!=null&&n>0?o=Math.round((n-r)/n*100):e.price_discount_rate!=null&&e.price_discount_rate>0&&(o=e.price_discount_rate);const i=_(e.brand),a=_(e.name)??e.sku,s=i&&!a.toLowerCase().startsWith(i.toLowerCase())?`${i} ${a}`:a,c={sku:e.sku,name:s,url:_(e.url)??""},u=e.images?.[0];u&&(c.imageUrl=u),e.images&&e.images.length>1&&(c.images=e.images),r!=null&&(c.price=String(r)),n!=null&&(c.originalPrice=String(n)),o!==void 0&&(c.discountPercent=o),i!==void 0&&(c.brand=i),e.rating!==void 0&&(c.rating=e.rating),e.review_count!==void 0&&(c.reviewCount=e.review_count),e.cart_code!==void 0&&(c.cartCode=e.cart_code),e.in_stock!==void 0&&(c.inStock=e.in_stock),e.variants&&e.variants.length>0&&(c.variants=e.variants),e.discount_reason!==void 0&&(c.discountReason=e.discount_reason),e.promotions&&e.promotions.length>0&&(c.promotions=e.promotions),e.description!==void 0&&(c.description=e.description),e.description_html!==void 0&&(c.descriptionHtml=e.description_html),e.features&&e.features.length>0&&(c.features=e.features),e.specifications!==void 0&&(c.specifications=e.specifications),e.facet_hits&&(c.facetHits=e.facet_hits),e.short_name!==void 0&&(c.shortName=e.short_name);const d=e,p={};let f=!1;for(const m of Object.keys(d))Nr.has(m)||(p[m]=d[m],f=!0);return f&&(c.extras=p),c}function jr(e){return e.results.map(R)}function Rr(e){return e.product_groupings.map(t=>{const r={name:t.name,products:(t.group_products??[]).map(R)};return t.highlight!==void 0&&(r.highlight=t.highlight),r})}function Cr(e){const t=e.payload.type,{type:r,...n}=e.payload;return{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:t,props:n}}}}}var xr={process_action:"/process_action",launcher_action:"/launcher_action",similar_products:"/similar_products",product_groupings:"/product_groupings"};function nt(e){if(e===void 0)throw new Error("[gengage] middlewareUrl is required. Pass your Gengage backend URL in widget config.");const t=e.trim();return t===""?"":t.replace(/\/+$/,"")}function Dr(e,t){return`${nt(t?.middlewareUrl)}/chat${xr[e]}`}var Os=Object.freeze({status:"aborted"});function l(e,t,r){function n(s,c){if(s._zod||Object.defineProperty(s,"_zod",{value:{def:c,constr:a,traits:new Set},enumerable:!1}),s._zod.traits.has(e))return;s._zod.traits.add(e),t(s,c);const u=a.prototype,d=Object.keys(u);for(let p=0;p<d.length;p++){const f=d[p];f in s||(s[f]=u[f].bind(s))}}const o=r?.Parent??Object;class i extends o{}Object.defineProperty(i,"name",{value:e});function a(s){var c;const u=r?.Parent?new i:this;n(u,s),(c=u._zod).deferred??(c.deferred=[]);for(const d of u._zod.deferred)d();return u}return Object.defineProperty(a,"init",{value:n}),Object.defineProperty(a,Symbol.hasInstance,{value:s=>r?.Parent&&s instanceof r.Parent?!0:s?._zod?.traits?.has(e)}),Object.defineProperty(a,"name",{value:e}),a}var J=class extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}},ot=class extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name="ZodEncodeError"}},ue={};function C(e){return e&&Object.assign(ue,e),ue}function it(e){const t=Object.values(e).filter(r=>typeof r=="number");return Object.entries(e).filter(([r,n])=>t.indexOf(+r)===-1).map(([r,n])=>n)}function le(e,t){return typeof t=="bigint"?t.toString():t}function ge(e){return{get value(){{const t=e();return Object.defineProperty(this,"value",{value:t}),t}throw new Error("cached value already set")}}}function _e(e){return e==null}function ve(e){const t=e.startsWith("^")?1:0,r=e.endsWith("$")?e.length-1:e.length;return e.slice(t,r)}function Ur(e,t){const r=(e.toString().split(".")[1]||"").length,n=t.toString();let o=(n.split(".")[1]||"").length;if(o===0&&/\d?e-\d?/.test(n)){const a=n.match(/\d?e-(\d?)/);a?.[1]&&(o=Number.parseInt(a[1]))}const i=r>o?r:o;return Number.parseInt(e.toFixed(i).replace(".",""))%Number.parseInt(t.toFixed(i).replace(".",""))/10**i}var Ze=Symbol("evaluating");function v(e,t,r){let n;Object.defineProperty(e,t,{get(){if(n!==Ze)return n===void 0&&(n=Ze,n=r()),n},set(o){Object.defineProperty(e,t,{value:o})},configurable:!0})}function L(e,t,r){Object.defineProperty(e,t,{value:r,writable:!0,enumerable:!0,configurable:!0})}function D(...e){const t={};for(const r of e)Object.assign(t,Object.getOwnPropertyDescriptors(r));return Object.defineProperties({},t)}function Oe(e){return JSON.stringify(e)}function Lr(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}var at="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function Q(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}var Fr=ge(()=>{if(typeof navigator<"u"&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{return new Function(""),!0}catch{return!1}});function V(e){if(Q(e)===!1)return!1;const t=e.constructor;if(t===void 0||typeof t!="function")return!0;const r=t.prototype;return!(Q(r)===!1||Object.prototype.hasOwnProperty.call(r,"isPrototypeOf")===!1)}function st(e){return V(e)?{...e}:Array.isArray(e)?[...e]:e}var Mr=new Set(["string","number","symbol"]);function q(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function U(e,t,r){const n=new e._zod.constr(t??e._zod.def);return(!t||r?.parent)&&(n._zod.parent=e),n}function h(e){const t=e;if(!t)return{};if(typeof t=="string")return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw new Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,typeof t.error=="string"?{...t,error:()=>t.error}:t}function Jr(e){return Object.keys(e).filter(t=>e[t]._zod.optin==="optional"&&e[t]._zod.optout==="optional")}var Vr={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function qr(e,t){const r=e._zod.def,n=r.checks;if(n&&n.length>0)throw new Error(".pick() cannot be used on object schemas containing refinements");return U(e,D(e._zod.def,{get shape(){const o={};for(const i in t){if(!(i in r.shape))throw new Error(`Unrecognized key: "${i}"`);t[i]&&(o[i]=r.shape[i])}return L(this,"shape",o),o},checks:[]}))}function Gr(e,t){const r=e._zod.def,n=r.checks;if(n&&n.length>0)throw new Error(".omit() cannot be used on object schemas containing refinements");return U(e,D(e._zod.def,{get shape(){const o={...e._zod.def.shape};for(const i in t){if(!(i in r.shape))throw new Error(`Unrecognized key: "${i}"`);t[i]&&delete o[i]}return L(this,"shape",o),o},checks:[]}))}function Wr(e,t){if(!V(t))throw new Error("Invalid input to extend: expected a plain object");const r=e._zod.def.checks;if(r&&r.length>0){const n=e._zod.def.shape;for(const o in t)if(Object.getOwnPropertyDescriptor(n,o)!==void 0)throw new Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}return U(e,D(e._zod.def,{get shape(){const n={...e._zod.def.shape,...t};return L(this,"shape",n),n}}))}function Br(e,t){if(!V(t))throw new Error("Invalid input to safeExtend: expected a plain object");return U(e,D(e._zod.def,{get shape(){const r={...e._zod.def.shape,...t};return L(this,"shape",r),r}}))}function Kr(e,t){return U(e,D(e._zod.def,{get shape(){const r={...e._zod.def.shape,...t._zod.def.shape};return L(this,"shape",r),r},get catchall(){return t._zod.def.catchall},checks:[]}))}function Hr(e,t,r){const n=t._zod.def.checks;if(n&&n.length>0)throw new Error(".partial() cannot be used on object schemas containing refinements");return U(t,D(t._zod.def,{get shape(){const o=t._zod.def.shape,i={...o};if(r)for(const a in r){if(!(a in o))throw new Error(`Unrecognized key: "${a}"`);r[a]&&(i[a]=e?new e({type:"optional",innerType:o[a]}):o[a])}else for(const a in o)i[a]=e?new e({type:"optional",innerType:o[a]}):o[a];return L(this,"shape",i),i},checks:[]}))}function Yr(e,t,r){return U(t,D(t._zod.def,{get shape(){const n=t._zod.def.shape,o={...n};if(r)for(const i in r){if(!(i in o))throw new Error(`Unrecognized key: "${i}"`);r[i]&&(o[i]=new e({type:"nonoptional",innerType:n[i]}))}else for(const i in n)o[i]=new e({type:"nonoptional",innerType:n[i]});return L(this,"shape",o),o}}))}function F(e,t=0){if(e.aborted===!0)return!0;for(let r=t;r<e.issues.length;r++)if(e.issues[r]?.continue!==!0)return!0;return!1}function M(e,t){return t.map(r=>{var n;return(n=r).path??(n.path=[]),r.path.unshift(e),r})}function H(e){return typeof e=="string"?e:e?.message}function x(e,t,r){const n={...e,path:e.path??[]};return e.message||(n.message=H(e.inst?._zod.def?.error?.(e))??H(t?.error?.(e))??H(r.customError?.(e))??H(r.localeError?.(e))??"Invalid input"),delete n.inst,delete n.continue,t?.reportInput||delete n.input,n}function ye(e){return Array.isArray(e)?"array":typeof e=="string"?"string":"unknown"}function K(...e){const[t,r,n]=e;return typeof t=="string"?{message:t,code:"custom",input:r,inst:n}:{...t}}var ct=(e,t)=>{e.name="$ZodError",Object.defineProperty(e,"_zod",{value:e._zod,enumerable:!1}),Object.defineProperty(e,"issues",{value:t,enumerable:!1}),e.message=JSON.stringify(t,le,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},ut=l("$ZodError",ct),lt=l("$ZodError",ct,{Parent:Error});function Xr(e,t=r=>r.message){const r={},n=[];for(const o of e.issues)o.path.length>0?(r[o.path[0]]=r[o.path[0]]||[],r[o.path[0]].push(t(o))):n.push(t(o));return{formErrors:n,fieldErrors:r}}function Qr(e,t=r=>r.message){const r={_errors:[]},n=o=>{for(const i of o.issues)if(i.code==="invalid_union"&&i.errors.length)i.errors.map(a=>n({issues:a}));else if(i.code==="invalid_key")n({issues:i.issues});else if(i.code==="invalid_element")n({issues:i.issues});else if(i.path.length===0)r._errors.push(t(i));else{let a=r,s=0;for(;s<i.path.length;){const c=i.path[s];s!==i.path.length-1?a[c]=a[c]||{_errors:[]}:(a[c]=a[c]||{_errors:[]},a[c]._errors.push(t(i))),a=a[c],s++}}};return n(e),r}var be=e=>(t,r,n,o)=>{const i=n?Object.assign(n,{async:!1}):{async:!1},a=t._zod.run({value:r,issues:[]},i);if(a instanceof Promise)throw new J;if(a.issues.length){const s=new(o?.Err??e)(a.issues.map(c=>x(c,i,C())));throw at(s,o?.callee),s}return a.value};var we=e=>async(t,r,n,o)=>{const i=n?Object.assign(n,{async:!0}):{async:!0};let a=t._zod.run({value:r,issues:[]},i);if(a instanceof Promise&&(a=await a),a.issues.length){const s=new(o?.Err??e)(a.issues.map(c=>x(c,i,C())));throw at(s,o?.callee),s}return a.value};var ne=e=>(t,r,n)=>{const o=n?{...n,async:!1}:{async:!1},i=t._zod.run({value:r,issues:[]},o);if(i instanceof Promise)throw new J;return i.issues.length?{success:!1,error:new(e??ut)(i.issues.map(a=>x(a,o,C())))}:{success:!0,data:i.value}},en=ne(lt),oe=e=>async(t,r,n)=>{const o=n?Object.assign(n,{async:!0}):{async:!0};let i=t._zod.run({value:r,issues:[]},o);return i instanceof Promise&&(i=await i),i.issues.length?{success:!1,error:new e(i.issues.map(a=>x(a,o,C())))}:{success:!0,data:i.value}},tn=oe(lt),rn=e=>(t,r,n)=>{const o=n?Object.assign(n,{direction:"backward"}):{direction:"backward"};return be(e)(t,r,o)};var nn=e=>(t,r,n)=>be(e)(t,r,n);var on=e=>async(t,r,n)=>{const o=n?Object.assign(n,{direction:"backward"}):{direction:"backward"};return we(e)(t,r,o)};var an=e=>async(t,r,n)=>we(e)(t,r,n);var sn=e=>(t,r,n)=>{const o=n?Object.assign(n,{direction:"backward"}):{direction:"backward"};return ne(e)(t,r,o)};var cn=e=>(t,r,n)=>ne(e)(t,r,n);var un=e=>async(t,r,n)=>{const o=n?Object.assign(n,{direction:"backward"}):{direction:"backward"};return oe(e)(t,r,o)};var ln=e=>async(t,r,n)=>oe(e)(t,r,n);var dn=/^[cC][^\s-]{8,}$/,pn=/^[0-9a-z]+$/,fn=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,mn=/^[0-9a-vA-V]{20}$/,hn=/^[A-Za-z0-9]{27}$/,gn=/^[a-zA-Z0-9_-]{21}$/,_n=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,vn=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,Pe=e=>e?new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,yn=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,bn="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";function wn(){return new RegExp(bn,"u")}var kn=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,zn=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,$n=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,Sn=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Zn=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,dt=/^[A-Za-z0-9_-]*$/,On=/^\+[1-9]\d{6,14}$/,pt="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))",Pn=new RegExp(`^${pt}$`);function ft(e){const t="(?:[01]\\d|2[0-3]):[0-5]\\d";return typeof e.precision=="number"?e.precision===-1?`${t}`:e.precision===0?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`}function En(e){return new RegExp(`^${ft(e)}$`)}function In(e){const t=ft({precision:e.precision}),r=["Z"];e.local&&r.push(""),e.offset&&r.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");const n=`${t}(?:${r.join("|")})`;return new RegExp(`^${pt}T(?:${n})$`)}var Tn=e=>{const t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??""}}`:"[\\s\\S]*";return new RegExp(`^${t}$`)},An=/^-?\d+$/,mt=/^-?\d+(?:\.\d+)?$/,Nn=/^(?:true|false)$/i,jn=/^[^A-Z]*$/,Rn=/^[^a-z]*$/,E=l("$ZodCheck",(e,t)=>{var r;e._zod??(e._zod={}),e._zod.def=t,(r=e._zod).onattach??(r.onattach=[])}),ht={number:"number",bigint:"bigint",object:"date"},gt=l("$ZodCheckLessThan",(e,t)=>{E.init(e,t);const r=ht[typeof t.value];e._zod.onattach.push(n=>{const o=n._zod.bag,i=(t.inclusive?o.maximum:o.exclusiveMaximum)??Number.POSITIVE_INFINITY;t.value<i&&(t.inclusive?o.maximum=t.value:o.exclusiveMaximum=t.value)}),e._zod.check=n=>{(t.inclusive?n.value<=t.value:n.value<t.value)||n.issues.push({origin:r,code:"too_big",maximum:typeof t.value=="object"?t.value.getTime():t.value,input:n.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),_t=l("$ZodCheckGreaterThan",(e,t)=>{E.init(e,t);const r=ht[typeof t.value];e._zod.onattach.push(n=>{const o=n._zod.bag,i=(t.inclusive?o.minimum:o.exclusiveMinimum)??Number.NEGATIVE_INFINITY;t.value>i&&(t.inclusive?o.minimum=t.value:o.exclusiveMinimum=t.value)}),e._zod.check=n=>{(t.inclusive?n.value>=t.value:n.value>t.value)||n.issues.push({origin:r,code:"too_small",minimum:typeof t.value=="object"?t.value.getTime():t.value,input:n.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),Cn=l("$ZodCheckMultipleOf",(e,t)=>{E.init(e,t),e._zod.onattach.push(r=>{var n;(n=r._zod.bag).multipleOf??(n.multipleOf=t.value)}),e._zod.check=r=>{if(typeof r.value!=typeof t.value)throw new Error("Cannot mix number and bigint in multiple_of check.");(typeof r.value=="bigint"?r.value%t.value===BigInt(0):Ur(r.value,t.value)===0)||r.issues.push({origin:typeof r.value,code:"not_multiple_of",divisor:t.value,input:r.value,inst:e,continue:!t.abort})}}),xn=l("$ZodCheckNumberFormat",(e,t)=>{E.init(e,t),t.format=t.format||"float64";const r=t.format?.includes("int"),n=r?"int":"number",[o,i]=Vr[t.format];e._zod.onattach.push(a=>{const s=a._zod.bag;s.format=t.format,s.minimum=o,s.maximum=i,r&&(s.pattern=An)}),e._zod.check=a=>{const s=a.value;if(r){if(!Number.isInteger(s)){a.issues.push({expected:n,format:t.format,code:"invalid_type",continue:!1,input:s,inst:e});return}if(!Number.isSafeInteger(s)){s>0?a.issues.push({input:s,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:n,inclusive:!0,continue:!t.abort}):a.issues.push({input:s,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:n,inclusive:!0,continue:!t.abort});return}}s<o&&a.issues.push({origin:"number",input:s,code:"too_small",minimum:o,inclusive:!0,inst:e,continue:!t.abort}),s>i&&a.issues.push({origin:"number",input:s,code:"too_big",maximum:i,inclusive:!0,inst:e,continue:!t.abort})}}),Dn=l("$ZodCheckMaxLength",(e,t)=>{var r;E.init(e,t),(r=e._zod.def).when??(r.when=n=>{const o=n.value;return!_e(o)&&o.length!==void 0}),e._zod.onattach.push(n=>{const o=n._zod.bag.maximum??Number.POSITIVE_INFINITY;t.maximum<o&&(n._zod.bag.maximum=t.maximum)}),e._zod.check=n=>{const o=n.value;if(o.length<=t.maximum)return;const i=ye(o);n.issues.push({origin:i,code:"too_big",maximum:t.maximum,inclusive:!0,input:o,inst:e,continue:!t.abort})}}),Un=l("$ZodCheckMinLength",(e,t)=>{var r;E.init(e,t),(r=e._zod.def).when??(r.when=n=>{const o=n.value;return!_e(o)&&o.length!==void 0}),e._zod.onattach.push(n=>{const o=n._zod.bag.minimum??Number.NEGATIVE_INFINITY;t.minimum>o&&(n._zod.bag.minimum=t.minimum)}),e._zod.check=n=>{const o=n.value;if(o.length>=t.minimum)return;const i=ye(o);n.issues.push({origin:i,code:"too_small",minimum:t.minimum,inclusive:!0,input:o,inst:e,continue:!t.abort})}}),Ln=l("$ZodCheckLengthEquals",(e,t)=>{var r;E.init(e,t),(r=e._zod.def).when??(r.when=n=>{const o=n.value;return!_e(o)&&o.length!==void 0}),e._zod.onattach.push(n=>{const o=n._zod.bag;o.minimum=t.length,o.maximum=t.length,o.length=t.length}),e._zod.check=n=>{const o=n.value,i=o.length;if(i===t.length)return;const a=ye(o),s=i>t.length;n.issues.push({origin:a,...s?{code:"too_big",maximum:t.length}:{code:"too_small",minimum:t.length},inclusive:!0,exact:!0,input:n.value,inst:e,continue:!t.abort})}}),ie=l("$ZodCheckStringFormat",(e,t)=>{var r,n;E.init(e,t),e._zod.onattach.push(o=>{const i=o._zod.bag;i.format=t.format,t.pattern&&(i.patterns??(i.patterns=new Set),i.patterns.add(t.pattern))}),t.pattern?(r=e._zod).check??(r.check=o=>{t.pattern.lastIndex=0,!t.pattern.test(o.value)&&o.issues.push({origin:"string",code:"invalid_format",format:t.format,input:o.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(n=e._zod).check??(n.check=()=>{})}),Fn=l("$ZodCheckRegex",(e,t)=>{ie.init(e,t),e._zod.check=r=>{t.pattern.lastIndex=0,!t.pattern.test(r.value)&&r.issues.push({origin:"string",code:"invalid_format",format:"regex",input:r.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),Mn=l("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=jn),ie.init(e,t)}),Jn=l("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=Rn),ie.init(e,t)}),Vn=l("$ZodCheckIncludes",(e,t)=>{E.init(e,t);const r=q(t.includes),n=new RegExp(typeof t.position=="number"?`^.{${t.position}}${r}`:r);t.pattern=n,e._zod.onattach.push(o=>{const i=o._zod.bag;i.patterns??(i.patterns=new Set),i.patterns.add(n)}),e._zod.check=o=>{o.value.includes(t.includes,t.position)||o.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:t.includes,input:o.value,inst:e,continue:!t.abort})}}),qn=l("$ZodCheckStartsWith",(e,t)=>{E.init(e,t);const r=new RegExp(`^${q(t.prefix)}.*`);t.pattern??(t.pattern=r),e._zod.onattach.push(n=>{const o=n._zod.bag;o.patterns??(o.patterns=new Set),o.patterns.add(r)}),e._zod.check=n=>{n.value.startsWith(t.prefix)||n.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:t.prefix,input:n.value,inst:e,continue:!t.abort})}}),Gn=l("$ZodCheckEndsWith",(e,t)=>{E.init(e,t);const r=new RegExp(`.*${q(t.suffix)}$`);t.pattern??(t.pattern=r),e._zod.onattach.push(n=>{const o=n._zod.bag;o.patterns??(o.patterns=new Set),o.patterns.add(r)}),e._zod.check=n=>{n.value.endsWith(t.suffix)||n.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:t.suffix,input:n.value,inst:e,continue:!t.abort})}}),Wn=l("$ZodCheckOverwrite",(e,t)=>{E.init(e,t),e._zod.check=r=>{r.value=t.tx(r.value)}}),Bn=class{constructor(e=[]){this.content=[],this.indent=0,this&&(this.args=e)}indented(e){this.indent+=1,e(this),this.indent-=1}write(e){if(typeof e=="function"){e(this,{execution:"sync"}),e(this,{execution:"async"});return}const t=e.split(`
|
|
3
3
|
`).filter(o=>o),r=Math.min(...t.map(o=>o.length-o.trimStart().length)),n=t.map(o=>o.slice(r)).map(o=>" ".repeat(this.indent*2)+o);for(const o of n)this.content.push(o)}compile(){const e=Function,t=this?.args,r=[...(this?.content??[""]).map(n=>` ${n}`)];return new e(...t,r.join(`
|
|
4
4
|
`))}},Kn={major:4,minor:3,patch:6},w=l("$ZodType",(e,t)=>{var r;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=Kn;const n=[...e._zod.def.checks??[]];e._zod.traits.has("$ZodCheck")&&n.unshift(e);for(const o of n)for(const i of o._zod.onattach)i(e);if(n.length===0)(r=e._zod).deferred??(r.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{const o=(a,s,c)=>{let u=F(a),d;for(const p of s){if(p._zod.def.when){if(!p._zod.def.when(a))continue}else if(u)continue;const f=a.issues.length,m=p._zod.check(a);if(m instanceof Promise&&c?.async===!1)throw new J;if(d||m instanceof Promise)d=(d??Promise.resolve()).then(async()=>{await m,a.issues.length!==f&&(u||(u=F(a,f)))});else{if(a.issues.length===f)continue;u||(u=F(a,f))}}return d?d.then(()=>a):a},i=(a,s,c)=>{if(F(a))return a.aborted=!0,a;const u=o(s,n,c);if(u instanceof Promise){if(c.async===!1)throw new J;return u.then(d=>e._zod.parse(d,c))}return e._zod.parse(u,c)};e._zod.run=(a,s)=>{if(s.skipChecks)return e._zod.parse(a,s);if(s.direction==="backward"){const u=e._zod.parse({value:a.value,issues:[]},{...s,skipChecks:!0});return u instanceof Promise?u.then(d=>i(d,a,s)):i(u,a,s)}const c=e._zod.parse(a,s);if(c instanceof Promise){if(s.async===!1)throw new J;return c.then(u=>o(u,n,s))}return o(c,n,s)}}v(e,"~standard",()=>({validate:o=>{try{const i=en(e,o);return i.success?{value:i.data}:{issues:i.error?.issues}}catch{return tn(e,o).then(a=>a.success?{value:a.data}:{issues:a.error?.issues})}},vendor:"zod",version:1}))}),ke=l("$ZodString",(e,t)=>{w.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??Tn(e._zod.bag),e._zod.parse=(r,n)=>{if(t.coerce)try{r.value=String(r.value)}catch{}return typeof r.value=="string"||r.issues.push({expected:"string",code:"invalid_type",input:r.value,inst:e}),r}}),b=l("$ZodStringFormat",(e,t)=>{ie.init(e,t),ke.init(e,t)}),Hn=l("$ZodGUID",(e,t)=>{t.pattern??(t.pattern=vn),b.init(e,t)}),Yn=l("$ZodUUID",(e,t)=>{if(t.version){const r={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(r===void 0)throw new Error(`Invalid UUID version: "${t.version}"`);t.pattern??(t.pattern=Pe(r))}else t.pattern??(t.pattern=Pe());b.init(e,t)}),Xn=l("$ZodEmail",(e,t)=>{t.pattern??(t.pattern=yn),b.init(e,t)}),Qn=l("$ZodURL",(e,t)=>{b.init(e,t),e._zod.check=r=>{try{const n=r.value.trim(),o=new URL(n);t.hostname&&(t.hostname.lastIndex=0,t.hostname.test(o.hostname)||r.issues.push({code:"invalid_format",format:"url",note:"Invalid hostname",pattern:t.hostname.source,input:r.value,inst:e,continue:!t.abort})),t.protocol&&(t.protocol.lastIndex=0,t.protocol.test(o.protocol.endsWith(":")?o.protocol.slice(0,-1):o.protocol)||r.issues.push({code:"invalid_format",format:"url",note:"Invalid protocol",pattern:t.protocol.source,input:r.value,inst:e,continue:!t.abort})),t.normalize?r.value=o.href:r.value=n;return}catch{r.issues.push({code:"invalid_format",format:"url",input:r.value,inst:e,continue:!t.abort})}}}),eo=l("$ZodEmoji",(e,t)=>{t.pattern??(t.pattern=wn()),b.init(e,t)}),to=l("$ZodNanoID",(e,t)=>{t.pattern??(t.pattern=gn),b.init(e,t)}),ro=l("$ZodCUID",(e,t)=>{t.pattern??(t.pattern=dn),b.init(e,t)}),no=l("$ZodCUID2",(e,t)=>{t.pattern??(t.pattern=pn),b.init(e,t)}),oo=l("$ZodULID",(e,t)=>{t.pattern??(t.pattern=fn),b.init(e,t)}),io=l("$ZodXID",(e,t)=>{t.pattern??(t.pattern=mn),b.init(e,t)}),ao=l("$ZodKSUID",(e,t)=>{t.pattern??(t.pattern=hn),b.init(e,t)}),so=l("$ZodISODateTime",(e,t)=>{t.pattern??(t.pattern=In(t)),b.init(e,t)}),co=l("$ZodISODate",(e,t)=>{t.pattern??(t.pattern=Pn),b.init(e,t)}),uo=l("$ZodISOTime",(e,t)=>{t.pattern??(t.pattern=En(t)),b.init(e,t)}),lo=l("$ZodISODuration",(e,t)=>{t.pattern??(t.pattern=_n),b.init(e,t)}),po=l("$ZodIPv4",(e,t)=>{t.pattern??(t.pattern=kn),b.init(e,t),e._zod.bag.format="ipv4"}),fo=l("$ZodIPv6",(e,t)=>{t.pattern??(t.pattern=zn),b.init(e,t),e._zod.bag.format="ipv6",e._zod.check=r=>{try{new URL(`http://[${r.value}]`)}catch{r.issues.push({code:"invalid_format",format:"ipv6",input:r.value,inst:e,continue:!t.abort})}}}),mo=l("$ZodCIDRv4",(e,t)=>{t.pattern??(t.pattern=$n),b.init(e,t)}),ho=l("$ZodCIDRv6",(e,t)=>{t.pattern??(t.pattern=Sn),b.init(e,t),e._zod.check=r=>{const n=r.value.split("/");try{if(n.length!==2)throw new Error;const[o,i]=n;if(!i)throw new Error;const a=Number(i);if(`${a}`!==i)throw new Error;if(a<0||a>128)throw new Error;new URL(`http://[${o}]`)}catch{r.issues.push({code:"invalid_format",format:"cidrv6",input:r.value,inst:e,continue:!t.abort})}}});function vt(e){if(e==="")return!0;if(e.length%4!==0)return!1;try{return atob(e),!0}catch{return!1}}var go=l("$ZodBase64",(e,t)=>{t.pattern??(t.pattern=Zn),b.init(e,t),e._zod.bag.contentEncoding="base64",e._zod.check=r=>{vt(r.value)||r.issues.push({code:"invalid_format",format:"base64",input:r.value,inst:e,continue:!t.abort})}});function _o(e){if(!dt.test(e))return!1;const t=e.replace(/[-_]/g,r=>r==="-"?"+":"/");return vt(t.padEnd(Math.ceil(t.length/4)*4,"="))}var vo=l("$ZodBase64URL",(e,t)=>{t.pattern??(t.pattern=dt),b.init(e,t),e._zod.bag.contentEncoding="base64url",e._zod.check=r=>{_o(r.value)||r.issues.push({code:"invalid_format",format:"base64url",input:r.value,inst:e,continue:!t.abort})}}),yo=l("$ZodE164",(e,t)=>{t.pattern??(t.pattern=On),b.init(e,t)});function bo(e,t=null){try{const r=e.split(".");if(r.length!==3)return!1;const[n]=r;if(!n)return!1;const o=JSON.parse(atob(n));return!("typ"in o&&o?.typ!=="JWT"||!o.alg||t&&(!("alg"in o)||o.alg!==t))}catch{return!1}}var wo=l("$ZodJWT",(e,t)=>{b.init(e,t),e._zod.check=r=>{bo(r.value,t.alg)||r.issues.push({code:"invalid_format",format:"jwt",input:r.value,inst:e,continue:!t.abort})}}),yt=l("$ZodNumber",(e,t)=>{w.init(e,t),e._zod.pattern=e._zod.bag.pattern??mt,e._zod.parse=(r,n)=>{if(t.coerce)try{r.value=Number(r.value)}catch{}const o=r.value;if(typeof o=="number"&&!Number.isNaN(o)&&Number.isFinite(o))return r;const i=typeof o=="number"?Number.isNaN(o)?"NaN":Number.isFinite(o)?void 0:"Infinity":void 0;return r.issues.push({expected:"number",code:"invalid_type",input:o,inst:e,...i?{received:i}:{}}),r}}),ko=l("$ZodNumberFormat",(e,t)=>{xn.init(e,t),yt.init(e,t)}),zo=l("$ZodBoolean",(e,t)=>{w.init(e,t),e._zod.pattern=Nn,e._zod.parse=(r,n)=>{if(t.coerce)try{r.value=!!r.value}catch{}const o=r.value;return typeof o=="boolean"||r.issues.push({expected:"boolean",code:"invalid_type",input:o,inst:e}),r}}),$o=l("$ZodUnknown",(e,t)=>{w.init(e,t),e._zod.parse=r=>r}),So=l("$ZodNever",(e,t)=>{w.init(e,t),e._zod.parse=(r,n)=>(r.issues.push({expected:"never",code:"invalid_type",input:r.value,inst:e}),r)});function Ee(e,t,r){e.issues.length&&t.issues.push(...M(r,e.issues)),t.value[r]=e.value}var Zo=l("$ZodArray",(e,t)=>{w.init(e,t),e._zod.parse=(r,n)=>{const o=r.value;if(!Array.isArray(o))return r.issues.push({expected:"array",code:"invalid_type",input:o,inst:e}),r;r.value=Array(o.length);const i=[];for(let a=0;a<o.length;a++){const s=o[a],c=t.element._zod.run({value:s,issues:[]},n);c instanceof Promise?i.push(c.then(u=>Ee(u,r,a))):Ee(c,r,a)}return i.length?Promise.all(i).then(()=>r):r}});function ee(e,t,r,n,o){if(e.issues.length){if(o&&!(r in n))return;t.issues.push(...M(r,e.issues))}e.value===void 0?r in n&&(t.value[r]=void 0):t.value[r]=e.value}function bt(e){const t=Object.keys(e.shape);for(const n of t)if(!e.shape?.[n]?._zod?.traits?.has("$ZodType"))throw new Error(`Invalid element at key "${n}": expected a Zod schema`);const r=Jr(e.shape);return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(r)}}function wt(e,t,r,n,o,i){const a=[],s=o.keySet,c=o.catchall._zod,u=c.def.type,d=c.optout==="optional";for(const p in t){if(s.has(p))continue;if(u==="never"){a.push(p);continue}const f=c.run({value:t[p],issues:[]},n);f instanceof Promise?e.push(f.then(m=>ee(m,r,p,t,d))):ee(f,r,p,t,d)}return a.length&&r.issues.push({code:"unrecognized_keys",keys:a,input:t,inst:i}),e.length?Promise.all(e).then(()=>r):r}var Oo=l("$ZodObject",(e,t)=>{if(w.init(e,t),!Object.getOwnPropertyDescriptor(t,"shape")?.get){const a=t.shape;Object.defineProperty(t,"shape",{get:()=>{const s={...a};return Object.defineProperty(t,"shape",{value:s}),s}})}const r=ge(()=>bt(t));v(e._zod,"propValues",()=>{const a=t.shape,s={};for(const c in a){const u=a[c]._zod;if(u.values){s[c]??(s[c]=new Set);for(const d of u.values)s[c].add(d)}}return s});const n=Q,o=t.catchall;let i;e._zod.parse=(a,s)=>{i??(i=r.value);const c=a.value;if(!n(c))return a.issues.push({expected:"object",code:"invalid_type",input:c,inst:e}),a;a.value={};const u=[],d=i.shape;for(const p of i.keys){const f=d[p],m=f._zod.optout==="optional",g=f._zod.run({value:c[p],issues:[]},s);g instanceof Promise?u.push(g.then(y=>ee(y,a,p,c,m))):ee(g,a,p,c,m)}return o?wt(u,c,a,s,r.value,e):u.length?Promise.all(u).then(()=>a):a}}),Po=l("$ZodObjectJIT",(e,t)=>{Oo.init(e,t);const r=e._zod.parse,n=ge(()=>bt(t)),o=f=>{const m=new Bn(["shape","payload","ctx"]),g=n.value,y=N=>{const P=Oe(N);return`shape[${P}]._zod.run({ value: input[${P}], issues: [] }, ctx)`};m.write("const input = payload.value;");const $=Object.create(null);let Z=0;for(const N of g.keys)$[N]=`key_${Z++}`;m.write("const newResult = {};");for(const N of g.keys){const P=$[N],A=Oe(N),Dt=f[N]?._zod?.optout==="optional";m.write(`const ${P} = ${y(N)};`),Dt?m.write(`
|
package/dist/simbut/index.d.ts
CHANGED
|
@@ -7,6 +7,9 @@ export declare class GengageSimBut extends BaseWidget<SimButWidgetConfig> {
|
|
|
7
7
|
private _label;
|
|
8
8
|
protected onInit(config: SimButWidgetConfig): Promise<void>;
|
|
9
9
|
protected onUpdate(_context: Partial<PageContext>): void;
|
|
10
|
+
hide(): void;
|
|
11
|
+
show(): void;
|
|
12
|
+
protected _cleanupRoot(): void;
|
|
10
13
|
protected onShow(): void;
|
|
11
14
|
protected onHide(): void;
|
|
12
15
|
protected onDestroy(): void;
|