@gengage/assistant-fe 0.1.9 → 0.2.1
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/dist/assistant-fe.css +1 -1
- package/dist/chat/components/CategoriesContainer.d.ts.map +1 -1
- package/dist/chat/components/ChatDrawer.d.ts.map +1 -1
- package/dist/chat/components/renderUISpec.d.ts.map +1 -1
- package/dist/chat/index.d.ts.map +1 -1
- package/dist/chat/panel-manager.d.ts +16 -0
- package/dist/chat/panel-manager.d.ts.map +1 -1
- package/dist/chat.cjs +1 -1
- package/dist/chat.iife.js +28 -28
- package/dist/chat.iife.js.map +1 -1
- package/dist/chat.js +2 -2
- package/dist/common/action-router.d.ts.map +1 -1
- package/dist/common/debug.d.ts.map +1 -1
- package/dist/common/events.d.ts.map +1 -1
- package/dist/common/native-webview.d.ts.map +1 -1
- package/dist/common/product-utils.d.ts +10 -0
- package/dist/common/product-utils.d.ts.map +1 -1
- package/dist/common/protocol-adapter.d.ts.map +1 -1
- package/dist/common.cjs +1 -1
- package/dist/common.js +5 -5
- package/dist/index-BUtw0Jlm.cjs +2 -0
- package/dist/index-BUtw0Jlm.cjs.map +1 -0
- package/dist/index-D-tVifN8.cjs +13 -0
- package/dist/index-D-tVifN8.cjs.map +1 -0
- package/dist/{index-DR2uepzb.js → index-DjPldwe7.js} +181 -187
- package/dist/index-DjPldwe7.js.map +1 -0
- package/dist/{index-CEt87kCd.js → index-TY0qKDI-.js} +1291 -1292
- package/dist/index-TY0qKDI-.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +3 -3
- package/dist/native.cjs +1 -1
- package/dist/native.iife.js +30 -30
- package/dist/native.iife.js.map +1 -1
- package/dist/native.js +1 -1
- package/dist/qna.cjs +1 -1
- package/dist/qna.iife.js +2 -2
- package/dist/qna.iife.js.map +1 -1
- package/dist/qna.js +1 -1
- package/dist/quantity-stepper-BKtPQUR1.js +78 -0
- package/dist/quantity-stepper-BKtPQUR1.js.map +1 -0
- package/dist/quantity-stepper-DU6va4sS.cjs +2 -0
- package/dist/quantity-stepper-DU6va4sS.cjs.map +1 -0
- package/dist/{schemas-DIhL3DkL.js → schemas-BAEbjFPE.js} +17 -12
- package/dist/schemas-BAEbjFPE.js.map +1 -0
- package/dist/{schemas-Dsr0bbO_.cjs → schemas-DIyHm5pa.cjs} +4 -4
- package/dist/{schemas-DIhL3DkL.js.map → schemas-DIyHm5pa.cjs.map} +1 -1
- package/dist/simrel/api.d.ts.map +1 -1
- package/dist/simrel/components/ProductCard.d.ts.map +1 -1
- package/dist/simrel/locales/en.d.ts.map +1 -1
- package/dist/simrel/locales/tr.d.ts.map +1 -1
- package/dist/simrel/types.d.ts +1 -0
- package/dist/simrel/types.d.ts.map +1 -1
- package/dist/simrel.cjs +1 -1
- package/dist/simrel.cjs.map +1 -1
- package/dist/simrel.css +1 -1
- package/dist/simrel.iife.js +6 -6
- package/dist/simrel.iife.js.map +1 -1
- package/dist/simrel.js +236 -234
- package/dist/simrel.js.map +1 -1
- package/package.json +1 -1
- package/dist/index-BWPx4pM7.cjs +0 -13
- package/dist/index-BWPx4pM7.cjs.map +0 -1
- package/dist/index-CEt87kCd.js.map +0 -1
- package/dist/index-DL4CAkyL.cjs +0 -2
- package/dist/index-DL4CAkyL.cjs.map +0 -1
- package/dist/index-DR2uepzb.js.map +0 -1
- package/dist/quantity-stepper-C-nV4lwi.js +0 -77
- package/dist/quantity-stepper-C-nV4lwi.js.map +0 -1
- package/dist/quantity-stepper-CURMkwRF.cjs +0 -2
- package/dist/quantity-stepper-CURMkwRF.cjs.map +0 -1
- package/dist/schemas-Dsr0bbO_.cjs.map +0 -1
package/dist/native.js
CHANGED
package/dist/qna.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./schemas-Dsr0bbO_.cjs");async function q(n,e,t){const i=s.buildChatEndpointUrl("launcher_action",e),o={uiSpecs:[],actions:[]},r={method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)};t!==void 0&&(r.signal=t);const a=await fetch(i,r);if(!a.ok)throw new Error(`HTTP ${a.status}: ${a.statusText}`);const c={onEvent:l=>{const u=s.adaptBackendEvent(l);if(u&&(u.type==="ui_spec"&&o.uiSpecs.push(u.spec),u.type==="ui_spec"&&u.spec.elements)){for(const p of Object.values(u.spec.elements))if(p.type==="ActionButton"&&p.props?.action){const h=p.props.action;o.actions.push(h)}}}};return t!==void 0&&(c.signal=t),await s.consumeStream(a,c),o}function y(n){const e=document.createElement("div");e.className="gengage-qna-buttons",e.setAttribute("role","group"),e.setAttribute("aria-label",n.quickQuestionsAriaLabel??"Quick questions"),n.orientation==="vertical"&&(e.style.flexDirection="column");for(const t of n.actions){const i=document.createElement("button");i.className="gengage-qna-button",i.textContent=t.title,i.type="button",i.addEventListener("click",()=>{const o={title:t.title,type:t.type};t.payload!==void 0&&(o.payload=t.payload),n.onAction(o)}),e.appendChild(i)}if(n.ctaText||n.onOpenChat){const t=document.createElement("button");t.className="gengage-qna-cta",t.textContent=n.ctaText??n.defaultCtaText??"Ask something else",t.type="button",t.addEventListener("click",()=>{n.onOpenChat?.()}),e.appendChild(t)}return e}function w(n){const e=document.createElement("div");e.className="gengage-qna-input-wrapper";const t=document.createElement("input");t.type="text",t.className="gengage-qna-input",t.setAttribute("aria-label",n.askQuestionAriaLabel??"Ask a question");const i=Array.isArray(n.placeholders)?n.placeholders:n.placeholders?[n.placeholders]:[n.defaultInputPlaceholder??"Ask a question..."];let o=0;t.placeholder=i[0]??"";let r=null,a=null;i.length>1&&(r=setInterval(()=>{t.classList.add("gengage-qna-input--fade"),a=setTimeout(()=>{o=(o+1)%i.length,t.placeholder=i[o]??"",t.classList.remove("gengage-qna-input--fade")},180)},3e3));const c=document.createElement("button");c.className="gengage-qna-send",c.type="button",c.textContent=n.ctaLabel??n.sendButtonText??"Ask",c.setAttribute("aria-label",n.sendQuestionAriaLabel??"Send question");const l=()=>{const u=t.value.trim();u&&(n.onSubmit({title:u,type:"user_message",payload:u}),t.value="")};return c.addEventListener("click",l),t.addEventListener("keydown",u=>{u.key==="Enter"&&(u.preventDefault(),l())}),e.appendChild(t),e.appendChild(c),e._cleanup=()=>{r&&clearInterval(r),a&&clearTimeout(a)},e}function g(n,e){if(!n||typeof n!="object")return null;const t=n,i=t.type;if(typeof i!="string"||i.length===0)return null;const o=t.title,r=t.payload,a=typeof o=="string"&&o.length>0?o:e;if(!a)return null;const c={title:a,type:i};return r!==void 0&&(c.payload=r),c}function m(n){const e={title:n.title,type:n.type};return n.payload!==void 0&&(e.payload=n.payload),e}function A(n,e){const t=[],i=n.props?.actions;if(Array.isArray(i))for(const a of i){const c=g(a);c&&t.push(c)}const o=n.props?.buttons;if(Array.isArray(o))for(const a of o){if(!a||typeof a!="object")continue;const c=a,l=typeof c.label=="string"?c.label:void 0,u=g(c.action,l);u&&t.push(u)}if(n.children)for(const a of n.children){const c=e.elements[a];if(!c||c.type!=="ActionButton")continue;const l=typeof c.props?.label=="string"?c.props.label:void 0,u=g(c.props?.action,l);u&&t.push(u)}const r=new Set;return t.filter(a=>r.has(a.title)?!1:(r.add(a.title),!0))}const T={ButtonRow:({element:n,spec:e,context:t})=>{const i=A(n,e).map(m),o=n.props?.orientation,r={actions:i,onAction:t.onAction,defaultCtaText:t.i18n.defaultCtaText,quickQuestionsAriaLabel:t.i18n.quickQuestionsAriaLabel};return t.onOpenChat!==void 0&&(r.onOpenChat=t.onOpenChat),t.ctaText!==void 0&&(r.ctaText=t.ctaText),(o==="horizontal"||o==="vertical")&&(r.orientation=o),y(r)},ActionButtons:({element:n,spec:e,context:t})=>{const o={actions:A(n,e).map(m),onAction:t.onAction,defaultCtaText:t.i18n.defaultCtaText,quickQuestionsAriaLabel:t.i18n.quickQuestionsAriaLabel};return t.onOpenChat!==void 0&&(o.onOpenChat=t.onOpenChat),t.ctaText!==void 0&&(o.ctaText=t.ctaText),y(o)},ActionButton:({element:n,context:e})=>{const t=document.createElement("button");t.className="gengage-qna-button",t.type="button";const i=n.props?.label;typeof i=="string"?t.textContent=i:t.textContent=e.i18n.defaultCtaText;const o=g(n.props?.action,typeof i=="string"?i:void 0);return o&&t.addEventListener("click",()=>e.onAction(o)),t},TextInput:({element:n,context:e})=>{const t=n.props?.placeholder,i=typeof t=="string"||Array.isArray(t)?t:e.inputPlaceholder,o=typeof n.props?.ctaLabel=="string"?n.props.ctaLabel:void 0,r={onSubmit:e.onAction,askQuestionAriaLabel:e.i18n.askQuestionAriaLabel,defaultInputPlaceholder:e.i18n.defaultInputPlaceholder,sendButtonText:e.i18n.sendButton,sendQuestionAriaLabel:e.i18n.sendQuestionAriaLabel};return i!==void 0&&(r.placeholders=i),o!==void 0&&(r.ctaLabel=o),w(r)},QuestionHeading:({element:n})=>{const e=document.createElement("h3");e.className="gengage-qna-heading";const t=n.props?.text;return e.textContent=typeof t=="string"?t:"",e},ProductCard:()=>null},b=({element:n,renderElement:e})=>{if(!n.children||n.children.length===0)return null;const t=document.createElement("div");for(const i of n.children){const o=e(i);o&&t.appendChild(o)}return t};function C(){return{...T}}function E(n,e,t=T,i=b){return s.renderUISpecWithRegistry({spec:n,context:e,registry:t,containerClassName:"gengage-qna-uispec",unknownRenderer:i})}const I={quickQuestionsAriaLabel:"Hızlı sorular",askQuestionAriaLabel:"Soru sorun",defaultInputPlaceholder:"Bir soru sorun...",sendButton:"Sor",sendQuestionAriaLabel:"Soruyu gönder",defaultCtaText:"Başka bir şey sor"},Q={quickQuestionsAriaLabel:"Quick questions",askQuestionAriaLabel:"Ask a question",defaultInputPlaceholder:"Ask a question...",sendButton:"Ask",sendQuestionAriaLabel:"Send question",defaultCtaText:"Ask something else"};function x(n){return n?n.toLowerCase().split("-")[0]??"tr":"tr"}function L(n){return x(n)==="en"?Q:I}const R=s.object({title:s.string(),type:s.string(),payload:s.unknown().optional()}),N=s.object({label:s.string(),action:R,variant:s._enum(["primary","outline","ghost"]).optional()}),P=s.object({orientation:s._enum(["horizontal","vertical"]).optional(),wrap:s.boolean().optional()}),B=s.object({placeholder:s.union([s.string(),s.array(s.string())]).optional(),ctaLabel:s.string().optional()}),U=s.object({text:s.string()}),O={components:{ActionButton:{schema:N,description:"A single clickable QNA action button."},ButtonRow:{schema:P,description:"Container for a group of QNA action buttons."},TextInput:{schema:B,description:"Free-text input with rotating placeholder and CTA button."},QuestionHeading:{schema:U,description:"A heading displayed above the QNA button group."}}};class S extends s.BaseWidget{constructor(){super(...arguments),this._abortController=null,this._debounceTimer=null,this._contentEl=null,this._i18n=I,this._actionHandler=this._handleAction.bind(this),this._openChatHandler=this._handleOpenChat.bind(this)}async onInit(e){this._i18n=this._resolveI18n(e),this._contentEl=document.createElement("div"),this._contentEl.className="gengage-qna-container",this.root.appendChild(this._contentEl);const t=e.pageContext?.sku;t&&(this._lastSku=t,await this._fetchAndRender(t)),this.isVisible=!0,s.trackInit("qna")}onUpdate(e){const t=e.sku;!t||t===this._lastSku||(this._debounceTimer&&clearTimeout(this._debounceTimer),this._debounceTimer=setTimeout(()=>{this._debounceTimer=null,this._lastSku=t,this._fetchAndRender(t)},50))}onShow(){this._contentEl&&(this._contentEl.style.opacity="0",this._contentEl.style.transition="opacity 0.2s ease-in",requestAnimationFrame(()=>{this._contentEl&&(this._contentEl.style.opacity="1")}))}onHide(){}onDestroy(){this._abort(),this._debounceTimer&&(clearTimeout(this._debounceTimer),this._debounceTimer=null),this._contentEl&&(this._cleanupTextInputTimers(),this._contentEl.remove(),this._contentEl=null)}_abort(){this._abortController?.abort(),this._abortController=null}_cleanupTextInputTimers(){if(!this._contentEl)return;const e=this._contentEl.querySelectorAll(".gengage-qna-input-wrapper");for(const t of e)t._cleanup?.()}async _fetchAndRender(e){if(this._abort(),this._abortController=new AbortController,!this._contentEl)return;this._cleanupTextInputTimers(),this._contentEl.innerHTML="";const t=this._createLoadingIndicator();this._contentEl.appendChild(t);const i={middlewareUrl:this.config.middlewareUrl},o=crypto.randomUUID(),r=Date.now();this.track(s.streamStartEvent(this.analyticsContext(),{endpoint:"launcher_action",request_id:o,widget:"qna"}));try{const a={account_id:this.config.accountId,session_id:this.config.session?.sessionId??"",correlation_id:this.config.session?.sessionId??"",sku:e,locale:this.config.locale??"tr"},c=this.config.pageContext?.pageType;c!==void 0&&(a.page_type=c);const l=await q(a,i,this._abortController.signal);if(this.track(s.streamDoneEvent(this.analyticsContext(),{request_id:o,latency_ms:Date.now()-r,chunk_count:l.actions.length,widget:"qna"})),this.track(s.widgetHistorySnapshotEvent(this.analyticsContext(),{message_count:l.actions.length,history_ref:o,redaction_level:"none",widget:"qna"})),!this._contentEl)return;if(this._contentEl.innerHTML="",!this._specIncludesType(l.uiSpecs,"QuestionHeading")&&this.config.showStaticQuestion&&this.config.staticQuestionText){const d=document.createElement("h3");d.className="gengage-qna-heading",d.textContent=this.config.staticQuestionText,this._contentEl.appendChild(d)}const p=this.config.inputPlaceholder,h=l.actions.length>0&&p===!0?l.actions.map(d=>d.title):p===!0?this._i18n.defaultInputPlaceholder:p??this._i18n.defaultInputPlaceholder,f={onAction:this._actionHandler,i18n:this._i18n,onOpenChat:this._openChatHandler};this.config.ctaText!==void 0&&(f.ctaText=this.config.ctaText),h!==void 0&&(f.inputPlaceholder=h);const v=this._buildFallbackActionsSpec(l.actions),_=(l.uiSpecs.length>0?l.uiSpecs:[v]).filter(d=>Object.keys(d.elements).length>0);for(const d of _){const k=this._renderUISpec(d,f);this._contentEl.appendChild(k)}_.length>0&&s.trackShow("qna"),!this._specIncludesType(_,"TextInput")&&this._appendStandaloneInput(f,h)}catch(a){if(a instanceof DOMException&&a.name==="AbortError")return;if(s.dispatch("gengage:global:error",{source:"qna",code:"FETCH_ERROR",message:s.getGlobalErrorMessage(this.config.locale)}),this.track(s.streamErrorEvent(this.analyticsContext(),{request_id:o,error_code:"FETCH_ERROR",error_message:a instanceof Error?a.message:String(a),widget:"qna"})),this._contentEl){this._cleanupTextInputTimers(),this._contentEl.innerHTML="";const c=this.config.inputPlaceholder===!0?this._i18n.defaultInputPlaceholder:this.config.inputPlaceholder??this._i18n.defaultInputPlaceholder,l={onAction:this._actionHandler,i18n:this._i18n,onOpenChat:this._openChatHandler};this.config.ctaText!==void 0&&(l.ctaText=this.config.ctaText),this._appendStandaloneInput(l,c)}}}_createLoadingIndicator(){const e=document.createElement("div");e.className="gengage-qna-loading";for(let t=0;t<3;t++){const i=document.createElement("div");i.className="gengage-qna-loading-dot",e.appendChild(i)}return e}_resolveI18n(e){return{...L(e.locale),...e.i18n}}_resolveUISpecRegistry(){const e=C();return s.mergeUISpecRegistry(e,this.config.renderer?.registry)}_renderUISpec(e,t){const i=this._resolveUISpecRegistry(),o=this.config.renderer?.unknownRenderer??b,r=(l,u)=>E(l,u,i,o),a=this.config.renderer?.renderUISpec;return a?a(e,t,{registry:i,unknownRenderer:o,defaultRender:r}):r(e,t)}_specIncludesType(e,t){for(const i of e)for(const o of Object.values(i.elements))if(o.type===t)return!0;return!1}_buildFallbackActionsSpec(e){if(e.length===0)return{root:"root",elements:{}};const t={},i=[];for(let o=0;o<e.length;o++){const r=e[o],a=`action-${o}`;i.push(a),t[a]={type:"ActionButton",props:{label:r.title,action:{title:r.title,type:r.type,payload:r.payload}}}}return t.root={type:"ButtonRow",children:i},{root:"root",elements:t}}_appendStandaloneInput(e,t){if(!this._contentEl)return;const i={root:"root",elements:{root:{type:"TextInput",props:{placeholder:t}}}},o=this._renderUISpec(i,e);this._contentEl.appendChild(o)}_handleAction(e){s.trackSuggestedQuestion(e.title,e.type),this.config.onActionSelected?.(e),s.dispatch("gengage:qna:action",e)}_handleOpenChat(){const e=this._contentEl?.querySelector(".gengage-qna-input");e&&e.focus(),this.config.onOpenChat?.(),s.dispatch("gengage:qna:open-chat",{})}}function H(){return new S}exports.GengageQNA=S;exports.createDefaultQnaUISpecRegistry=C;exports.createQNAWidget=H;exports.defaultQnaUnknownUISpecRenderer=b;exports.qnaCatalog=O;exports.renderQnaUISpec=E;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./schemas-DIyHm5pa.cjs");async function q(n,e,t){const i=s.buildChatEndpointUrl("launcher_action",e),o={uiSpecs:[],actions:[]},r={method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)};t!==void 0&&(r.signal=t);const a=await fetch(i,r);if(!a.ok)throw new Error(`HTTP ${a.status}: ${a.statusText}`);const c={onEvent:l=>{const u=s.adaptBackendEvent(l);if(u&&(u.type==="ui_spec"&&o.uiSpecs.push(u.spec),u.type==="ui_spec"&&u.spec.elements)){for(const p of Object.values(u.spec.elements))if(p.type==="ActionButton"&&p.props?.action){const h=p.props.action;o.actions.push(h)}}}};return t!==void 0&&(c.signal=t),await s.consumeStream(a,c),o}function y(n){const e=document.createElement("div");e.className="gengage-qna-buttons",e.setAttribute("role","group"),e.setAttribute("aria-label",n.quickQuestionsAriaLabel??"Quick questions"),n.orientation==="vertical"&&(e.style.flexDirection="column");for(const t of n.actions){const i=document.createElement("button");i.className="gengage-qna-button",i.textContent=t.title,i.type="button",i.addEventListener("click",()=>{const o={title:t.title,type:t.type};t.payload!==void 0&&(o.payload=t.payload),n.onAction(o)}),e.appendChild(i)}if(n.ctaText||n.onOpenChat){const t=document.createElement("button");t.className="gengage-qna-cta",t.textContent=n.ctaText??n.defaultCtaText??"Ask something else",t.type="button",t.addEventListener("click",()=>{n.onOpenChat?.()}),e.appendChild(t)}return e}function w(n){const e=document.createElement("div");e.className="gengage-qna-input-wrapper";const t=document.createElement("input");t.type="text",t.className="gengage-qna-input",t.setAttribute("aria-label",n.askQuestionAriaLabel??"Ask a question");const i=Array.isArray(n.placeholders)?n.placeholders:n.placeholders?[n.placeholders]:[n.defaultInputPlaceholder??"Ask a question..."];let o=0;t.placeholder=i[0]??"";let r=null,a=null;i.length>1&&(r=setInterval(()=>{t.classList.add("gengage-qna-input--fade"),a=setTimeout(()=>{o=(o+1)%i.length,t.placeholder=i[o]??"",t.classList.remove("gengage-qna-input--fade")},180)},3e3));const c=document.createElement("button");c.className="gengage-qna-send",c.type="button",c.textContent=n.ctaLabel??n.sendButtonText??"Ask",c.setAttribute("aria-label",n.sendQuestionAriaLabel??"Send question");const l=()=>{const u=t.value.trim();u&&(n.onSubmit({title:u,type:"user_message",payload:u}),t.value="")};return c.addEventListener("click",l),t.addEventListener("keydown",u=>{u.key==="Enter"&&(u.preventDefault(),l())}),e.appendChild(t),e.appendChild(c),e._cleanup=()=>{r&&clearInterval(r),a&&clearTimeout(a)},e}function g(n,e){if(!n||typeof n!="object")return null;const t=n,i=t.type;if(typeof i!="string"||i.length===0)return null;const o=t.title,r=t.payload,a=typeof o=="string"&&o.length>0?o:e;if(!a)return null;const c={title:a,type:i};return r!==void 0&&(c.payload=r),c}function m(n){const e={title:n.title,type:n.type};return n.payload!==void 0&&(e.payload=n.payload),e}function A(n,e){const t=[],i=n.props?.actions;if(Array.isArray(i))for(const a of i){const c=g(a);c&&t.push(c)}const o=n.props?.buttons;if(Array.isArray(o))for(const a of o){if(!a||typeof a!="object")continue;const c=a,l=typeof c.label=="string"?c.label:void 0,u=g(c.action,l);u&&t.push(u)}if(n.children)for(const a of n.children){const c=e.elements[a];if(!c||c.type!=="ActionButton")continue;const l=typeof c.props?.label=="string"?c.props.label:void 0,u=g(c.props?.action,l);u&&t.push(u)}const r=new Set;return t.filter(a=>r.has(a.title)?!1:(r.add(a.title),!0))}const T={ButtonRow:({element:n,spec:e,context:t})=>{const i=A(n,e).map(m),o=n.props?.orientation,r={actions:i,onAction:t.onAction,defaultCtaText:t.i18n.defaultCtaText,quickQuestionsAriaLabel:t.i18n.quickQuestionsAriaLabel};return t.onOpenChat!==void 0&&(r.onOpenChat=t.onOpenChat),t.ctaText!==void 0&&(r.ctaText=t.ctaText),(o==="horizontal"||o==="vertical")&&(r.orientation=o),y(r)},ActionButtons:({element:n,spec:e,context:t})=>{const o={actions:A(n,e).map(m),onAction:t.onAction,defaultCtaText:t.i18n.defaultCtaText,quickQuestionsAriaLabel:t.i18n.quickQuestionsAriaLabel};return t.onOpenChat!==void 0&&(o.onOpenChat=t.onOpenChat),t.ctaText!==void 0&&(o.ctaText=t.ctaText),y(o)},ActionButton:({element:n,context:e})=>{const t=document.createElement("button");t.className="gengage-qna-button",t.type="button";const i=n.props?.label;typeof i=="string"?t.textContent=i:t.textContent=e.i18n.defaultCtaText;const o=g(n.props?.action,typeof i=="string"?i:void 0);return o&&t.addEventListener("click",()=>e.onAction(o)),t},TextInput:({element:n,context:e})=>{const t=n.props?.placeholder,i=typeof t=="string"||Array.isArray(t)?t:e.inputPlaceholder,o=typeof n.props?.ctaLabel=="string"?n.props.ctaLabel:void 0,r={onSubmit:e.onAction,askQuestionAriaLabel:e.i18n.askQuestionAriaLabel,defaultInputPlaceholder:e.i18n.defaultInputPlaceholder,sendButtonText:e.i18n.sendButton,sendQuestionAriaLabel:e.i18n.sendQuestionAriaLabel};return i!==void 0&&(r.placeholders=i),o!==void 0&&(r.ctaLabel=o),w(r)},QuestionHeading:({element:n})=>{const e=document.createElement("h3");e.className="gengage-qna-heading";const t=n.props?.text;return e.textContent=typeof t=="string"?t:"",e},ProductCard:()=>null},b=({element:n,renderElement:e})=>{if(!n.children||n.children.length===0)return null;const t=document.createElement("div");for(const i of n.children){const o=e(i);o&&t.appendChild(o)}return t};function C(){return{...T}}function E(n,e,t=T,i=b){return s.renderUISpecWithRegistry({spec:n,context:e,registry:t,containerClassName:"gengage-qna-uispec",unknownRenderer:i})}const I={quickQuestionsAriaLabel:"Hızlı sorular",askQuestionAriaLabel:"Soru sorun",defaultInputPlaceholder:"Bir soru sorun...",sendButton:"Sor",sendQuestionAriaLabel:"Soruyu gönder",defaultCtaText:"Başka bir şey sor"},Q={quickQuestionsAriaLabel:"Quick questions",askQuestionAriaLabel:"Ask a question",defaultInputPlaceholder:"Ask a question...",sendButton:"Ask",sendQuestionAriaLabel:"Send question",defaultCtaText:"Ask something else"};function x(n){return n?n.toLowerCase().split("-")[0]??"tr":"tr"}function L(n){return x(n)==="en"?Q:I}const R=s.object({title:s.string(),type:s.string(),payload:s.unknown().optional()}),N=s.object({label:s.string(),action:R,variant:s._enum(["primary","outline","ghost"]).optional()}),P=s.object({orientation:s._enum(["horizontal","vertical"]).optional(),wrap:s.boolean().optional()}),B=s.object({placeholder:s.union([s.string(),s.array(s.string())]).optional(),ctaLabel:s.string().optional()}),U=s.object({text:s.string()}),O={components:{ActionButton:{schema:N,description:"A single clickable QNA action button."},ButtonRow:{schema:P,description:"Container for a group of QNA action buttons."},TextInput:{schema:B,description:"Free-text input with rotating placeholder and CTA button."},QuestionHeading:{schema:U,description:"A heading displayed above the QNA button group."}}};class S extends s.BaseWidget{constructor(){super(...arguments),this._abortController=null,this._debounceTimer=null,this._contentEl=null,this._i18n=I,this._actionHandler=this._handleAction.bind(this),this._openChatHandler=this._handleOpenChat.bind(this)}async onInit(e){this._i18n=this._resolveI18n(e),this._contentEl=document.createElement("div"),this._contentEl.className="gengage-qna-container",this.root.appendChild(this._contentEl);const t=e.pageContext?.sku;t&&(this._lastSku=t,await this._fetchAndRender(t)),this.isVisible=!0,s.trackInit("qna")}onUpdate(e){const t=e.sku;!t||t===this._lastSku||(this._debounceTimer&&clearTimeout(this._debounceTimer),this._debounceTimer=setTimeout(()=>{this._debounceTimer=null,this._lastSku=t,this._fetchAndRender(t)},50))}onShow(){this._contentEl&&(this._contentEl.style.opacity="0",this._contentEl.style.transition="opacity 0.2s ease-in",requestAnimationFrame(()=>{this._contentEl&&(this._contentEl.style.opacity="1")}))}onHide(){}onDestroy(){this._abort(),this._debounceTimer&&(clearTimeout(this._debounceTimer),this._debounceTimer=null),this._contentEl&&(this._cleanupTextInputTimers(),this._contentEl.remove(),this._contentEl=null)}_abort(){this._abortController?.abort(),this._abortController=null}_cleanupTextInputTimers(){if(!this._contentEl)return;const e=this._contentEl.querySelectorAll(".gengage-qna-input-wrapper");for(const t of e)t._cleanup?.()}async _fetchAndRender(e){if(this._abort(),this._abortController=new AbortController,!this._contentEl)return;this._cleanupTextInputTimers(),this._contentEl.innerHTML="";const t=this._createLoadingIndicator();this._contentEl.appendChild(t);const i={middlewareUrl:this.config.middlewareUrl},o=crypto.randomUUID(),r=Date.now();this.track(s.streamStartEvent(this.analyticsContext(),{endpoint:"launcher_action",request_id:o,widget:"qna"}));try{const a={account_id:this.config.accountId,session_id:this.config.session?.sessionId??"",correlation_id:this.config.session?.sessionId??"",sku:e,locale:this.config.locale??"tr"},c=this.config.pageContext?.pageType;c!==void 0&&(a.page_type=c);const l=await q(a,i,this._abortController.signal);if(this.track(s.streamDoneEvent(this.analyticsContext(),{request_id:o,latency_ms:Date.now()-r,chunk_count:l.actions.length,widget:"qna"})),this.track(s.widgetHistorySnapshotEvent(this.analyticsContext(),{message_count:l.actions.length,history_ref:o,redaction_level:"none",widget:"qna"})),!this._contentEl)return;if(this._contentEl.innerHTML="",!this._specIncludesType(l.uiSpecs,"QuestionHeading")&&this.config.showStaticQuestion&&this.config.staticQuestionText){const d=document.createElement("h3");d.className="gengage-qna-heading",d.textContent=this.config.staticQuestionText,this._contentEl.appendChild(d)}const p=this.config.inputPlaceholder,h=l.actions.length>0&&p===!0?l.actions.map(d=>d.title):p===!0?this._i18n.defaultInputPlaceholder:p??this._i18n.defaultInputPlaceholder,f={onAction:this._actionHandler,i18n:this._i18n,onOpenChat:this._openChatHandler};this.config.ctaText!==void 0&&(f.ctaText=this.config.ctaText),h!==void 0&&(f.inputPlaceholder=h);const v=this._buildFallbackActionsSpec(l.actions),_=(l.uiSpecs.length>0?l.uiSpecs:[v]).filter(d=>Object.keys(d.elements).length>0);for(const d of _){const k=this._renderUISpec(d,f);this._contentEl.appendChild(k)}_.length>0&&s.trackShow("qna"),!this._specIncludesType(_,"TextInput")&&this._appendStandaloneInput(f,h)}catch(a){if(a instanceof DOMException&&a.name==="AbortError")return;if(s.dispatch("gengage:global:error",{source:"qna",code:"FETCH_ERROR",message:s.getGlobalErrorMessage(this.config.locale)}),this.track(s.streamErrorEvent(this.analyticsContext(),{request_id:o,error_code:"FETCH_ERROR",error_message:a instanceof Error?a.message:String(a),widget:"qna"})),this._contentEl){this._cleanupTextInputTimers(),this._contentEl.innerHTML="";const c=this.config.inputPlaceholder===!0?this._i18n.defaultInputPlaceholder:this.config.inputPlaceholder??this._i18n.defaultInputPlaceholder,l={onAction:this._actionHandler,i18n:this._i18n,onOpenChat:this._openChatHandler};this.config.ctaText!==void 0&&(l.ctaText=this.config.ctaText),this._appendStandaloneInput(l,c)}}}_createLoadingIndicator(){const e=document.createElement("div");e.className="gengage-qna-loading";for(let t=0;t<3;t++){const i=document.createElement("div");i.className="gengage-qna-loading-dot",e.appendChild(i)}return e}_resolveI18n(e){return{...L(e.locale),...e.i18n}}_resolveUISpecRegistry(){const e=C();return s.mergeUISpecRegistry(e,this.config.renderer?.registry)}_renderUISpec(e,t){const i=this._resolveUISpecRegistry(),o=this.config.renderer?.unknownRenderer??b,r=(l,u)=>E(l,u,i,o),a=this.config.renderer?.renderUISpec;return a?a(e,t,{registry:i,unknownRenderer:o,defaultRender:r}):r(e,t)}_specIncludesType(e,t){for(const i of e)for(const o of Object.values(i.elements))if(o.type===t)return!0;return!1}_buildFallbackActionsSpec(e){if(e.length===0)return{root:"root",elements:{}};const t={},i=[];for(let o=0;o<e.length;o++){const r=e[o],a=`action-${o}`;i.push(a),t[a]={type:"ActionButton",props:{label:r.title,action:{title:r.title,type:r.type,payload:r.payload}}}}return t.root={type:"ButtonRow",children:i},{root:"root",elements:t}}_appendStandaloneInput(e,t){if(!this._contentEl)return;const i={root:"root",elements:{root:{type:"TextInput",props:{placeholder:t}}}},o=this._renderUISpec(i,e);this._contentEl.appendChild(o)}_handleAction(e){s.trackSuggestedQuestion(e.title,e.type),this.config.onActionSelected?.(e),s.dispatch("gengage:qna:action",e)}_handleOpenChat(){const e=this._contentEl?.querySelector(".gengage-qna-input");e&&e.focus(),this.config.onOpenChat?.(),s.dispatch("gengage:qna:open-chat",{})}}function H(){return new S}exports.GengageQNA=S;exports.createDefaultQnaUISpecRegistry=C;exports.createQNAWidget=H;exports.defaultQnaUnknownUISpecRenderer=b;exports.qnaCatalog=O;exports.renderQnaUISpec=E;
|
|
2
2
|
//# sourceMappingURL=qna.cjs.map
|
package/dist/qna.iife.js
CHANGED
|
@@ -43,8 +43,8 @@
|
|
|
43
43
|
transform: translateY(0);
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
-
`,document.head.appendChild(e)}let W=null;function ln(){if(W!==null)return W;try{W=localStorage.getItem("gengage:debug")==="1"}catch{W=!1}return W}function ge(e,t,n){ln()
|
|
47
|
-
`);r=f.pop()??"";for(const _ of f)if(je(_,t))return}if(r.trim()&&je(r,t))return}catch(c){if(c instanceof DOMException&&c.name==="AbortError")return;t.onError?.(c instanceof Error?c:new Error(String(c)))}finally{a||n.releaseLock()}t.onDone?.()}const mn={process_action:"/process_action",launcher_action:"/launcher_action",similar_products:"/similar_products",product_groupings:"/product_groupings"};function _n(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 yn(e,t){return`${_n(t?.middlewareUrl)}/chat${mn[e]}`}function vn(e){if(typeof e.type!="string")return null;if(wn(e))return e;const n=e;switch(n.type){case"outputText":return bn(n);case"suggestedActions":return kn(n);case"productList":return zn(n);case"productDetails":return Sn(n);case"productDetailsSimilars":return $n(n);case"comparisonTable":return Tn(n);case"context":return Zn(n);case"chatStreamEnd":return On();case"loading":return Cn(n);case"panelLoading":return Pn(n);case"similarLoading":return Rn(n);case"redirect":return Nn(n);case"error":return jn(n);case"dummy":return Dn();case"launcherAction":return Ln(n);case"text":return me(n);case"productItem":return xn(n);case"text_image":return De(n);case"quick_qna":return Le(n);case"reviewHighlights":return Un(n);case"aiProductSuggestions":return Mn(n);case"aiProductGroupings":return Jn(n);case"aiSuggestedSearches":return Bn(n);case"prosAndCons":return qn(n);case"getGroundingReview":return Qn(n);case"voice":return Vn(n);case"visitorDataResponse":return Fn(n);case"productListPreview":return Hn();case"groupList":return Wn(n);case"formGetInfo":case"formTestDrive":case"formServiceRequest":case"launchFormPage":return Gn(n);case"launcherContent":return Yn(n);case"handoff":return Kn(n);default:return null}}function wn(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 o=N(e.spec);return o?typeof o.root=="string"&&N(o.elements)!==null:!1}case"action":{const n=N(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 bn(e){const t=w(e.payload.text,e.payload.plain_text)??"",n=w(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 o={type:"text_chunk",content:t,final:!0},r=e.payload.product_mentions;Array.isArray(r)&&r.length>0&&(o.productMentions=r.filter(a=>typeof a=="object"&&a!==null&&typeof a.sku=="string"&&typeof a.short_name=="string"));const s=e.payload.sku_to_product_item;s&&typeof s=="object"&&!Array.isArray(s)&&(o.skuToProductItem=s);const i=e.payload.conversation_mode;return typeof i=="string"&&i&&(o.conversationMode=i),o}function kn(e){const t=(e.payload.actions??[]).map(n=>{const o=w(n.title)??"",r=C(n.requestDetails,o),s=r?{label:o,action:r}:null;return s?(typeof n.icon=="string"&&(s.icon=n.icon),typeof n.image=="string"&&(s.image=n.image),s):null});return xe(t.filter(qe),"chat")}function zn(e){const t=Ue(e.payload.product_list??[],"chat");t.panelHint="panel";const n=t.spec.elements[t.spec.root];return n&&(typeof e.payload.offset=="number"&&(n.props={...n.props,offset:e.payload.offset}),typeof e.payload.end_of_list=="boolean"&&(n.props={...n.props,endOfList:e.payload.end_of_list}),typeof e.payload.title=="string"&&(n.props={...n.props,panelTitle:e.payload.title})),t}function Sn(e){const t=e.payload.productDetails;return t?{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"ProductDetailsPanel",props:{product:B(t)}}}},panelHint:"panel"}:eo("chat")}function $n(e){const t=Ue(e.payload.similarProducts??[],"chat"),n=t.spec.elements[t.spec.root];return n&&(n.props={...n.props,similarsAppend:!0}),{...t,panelHint:"panel"}}function Tn(e){const t=e.payload.multiple_product_details??[],n=e.payload,o={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??{}},r=e.payload.table,s=e.payload.features_list,i=[];for(const v of t){const b=B(v);i.push(b)}const a=En(r,i,o,s);let c;o?.recommended_choice_sku?c=o.recommended_choice_sku:o?.winner_product&&o.winner_product.length>0&&(c=o.winner_product[0]?.product_detail?.sku??o.winner_product[0]?.sku);const u=c?i.find(v=>v.sku===c)??i[0]:i[0],l=[];if(Array.isArray(o?.key_differences))for(const v of o.key_differences)typeof v=="string"&&l.push(v);const h=ro(o?.special_considerations),p=o?.recommended_choice,f=o?.winner_hits,_={};for(const v of i){const b=v.sku;b&&(_[b]={title:v.name??b,type:"launchSingleProduct",payload:{sku:b}})}const m={products:i,attributes:a,highlights:l,productActions:_};return u&&(m.recommended=u),h.length>0&&(m.specialCases=h),p&&(m.recommendedText=p),f&&(m.winnerHits=f),typeof o?.key_differences=="string"&&(m.keyDifferencesHtml=o.key_differences),o?.special_considerations&&(m.specialConsiderations=o.special_considerations),{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"ComparisonTable",props:m}}},panelHint:"panel"}}function En(e,t,n,o){if(!e)return[];const r=Object.entries(e);if(r.length===0)return[];const s=r[0]?.[1];if(Array.isArray(s)){const p=n.criteria_view??n.criteria_view_short??{},f=n.compared_field_names??Object.keys(e),_=[];for(const m of f){const v=e[m];if(!v||!Array.isArray(v))continue;const b=p[m]??m;_.push({label:b,values:v.map(Z=>typeof Z=="string"?Z:String(Z??""))})}return _}const i=e,a=t.map(p=>String(p.sku??"")).filter(p=>p.length>0),c=n.criteria_view??n.criteria_view_short??{},l=(o&&o.length>0?o:n.compared_field_names&&n.compared_field_names.length>0?n.compared_field_names:An(i)).filter(p=>p!=="name"&&p!=="name_short"&&!p.endsWith("_short")),h=[];for(const p of l){const f=a.map(m=>{const v=i[m];if(!v||typeof v!="object")return"";const b=v[`${p}_short`],Z=v[p];return In(b??Z)});if(f.every(m=>m.length===0))continue;const _=c[p]??p;h.push({label:_,values:f})}return h}function An(e){const t=[],n=new Set;for(const o of Object.values(e))if(!(!o||typeof o!="object"))for(const r of Object.keys(o))n.has(r)||(n.add(r),t.push(r));return t}function In(e){return typeof e=="string"?e:typeof e=="number"||typeof e=="boolean"?String(e):""}function Zn(e){return{type:"metadata",sessionId:"",model:"",meta:{panel:e.payload.panel,messages:e.payload.messages,message_id:e.payload.message_id}}}function On(){return{type:"done"}}function Cn(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 Pn(e){return{type:"metadata",sessionId:"",model:"",meta:{loading:!0,panelLoading:!0,panelPendingType:e.payload?.pending_type,loadingText:e.payload?.text}}}function Rn(e){return{type:"metadata",sessionId:"",model:"",meta:{loading:!0,similarPanelLoading:!0,panelPendingType:e.payload?.pending_type,loadingText:e.payload?.text}}}function Nn(e){const t=w(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:w(e.payload.to)}}}function jn(e){return{type:"error",code:"BACKEND_ERROR",message:w(e.payload?.text,e.payload?.message,e.payload?.error)??"Backend returned an error"}}function Dn(e){return{type:"metadata",sessionId:"",model:"",meta:{noop:!0}}}function Ln(e){const t=e.payload??{};if(Array.isArray(t.action_list)){const s={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&&(s.type=i),a!==void 0&&(s.theme=a),Le({payload:s})}const o=N(t.action);if(o){const s={action:o},i=typeof t.text=="string"?t.text:void 0,a=typeof t.image_url=="string"?t.image_url:void 0,c=typeof t.theme=="string"?t.theme:void 0;return i!==void 0&&(s.text=i),a!==void 0&&(s.image_url=a),c!==void 0&&(s.theme=c),De({payload:s})}const r=typeof t.text=="string"?t.text:"";if(r){const s={text:r},i=typeof t.type=="string"?t.type:void 0,a=typeof t.theme=="string"?t.theme:void 0,c=N(t.payload)??void 0;return i!==void 0&&(s.type=i),c!==void 0&&(s.payload=c),a!==void 0&&(s.theme=a),me({payload:s})}return{type:"metadata",sessionId:"",model:"",meta:{launcherAction:t}}}function me(e){const t={text:w(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 xn(e){return Xn(e.payload,"qna")}function De(e){const t=w(e.payload.text)??"",n=C(e.payload.action,t);if(n){const r={label:t||n.title,action:n};return typeof e.payload.image_url=="string"&&(r.image=e.payload.image_url),typeof e.payload.theme=="string"&&(r.theme=e.payload.theme),{type:"ui_spec",widget:"qna",spec:{root:"root",elements:{root:{type:"ActionButton",props:r}}}}}const o={text:t};return typeof e.payload.theme=="string"&&(o.theme=e.payload.theme),me({payload:o})}function Le(e){const t=(e.payload.action_list??[]).map(n=>{const o=w(n.title)??"",r=C(n.requestDetails,o),s=r?{label:o,action:r}:null;return s?(typeof n.icon=="string"&&(s.icon=n.icon),typeof n.image=="string"&&(s.image=n.image),s):null});return xe(t.filter(qe),"qna")}function Un(e){const n={reviews:(e.payload.reviews??[]).map(o=>{const r={};return typeof o.review_class=="string"&&(r.review_class=o.review_class),typeof o.review_text=="string"&&(r.review_text=o.review_text),(typeof o.review_rating=="string"||typeof o.review_rating=="number")&&(r.review_rating=o.review_rating),typeof o.review_tag=="string"&&(r.review_tag=o.review_tag),r})};return typeof e.payload.sku=="string"&&(n.sku=e.payload.sku),{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"ReviewHighlights",props:n}}}}}function qn(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 Fn(e){return{type:"metadata",sessionId:"",model:"",meta:{visitorDataResponse:e.payload}}}function Mn(e){const t=e.payload.product_suggestions??[],n=[];for(let o=0;o<t.length;o++){const r=t[o];if(!r)continue;const s=to(r);if(!s)continue;const i={product:s},a=C(r.requestDetails,s.name);a&&(i.action=a),typeof r.role=="string"&&(i.role=r.role),typeof r.reason=="string"&&(i.reason=r.reason),typeof r.review_highlight=="string"&&(i.reviewHighlight=r.review_highlight),Array.isArray(r.labels)&&(i.labels=r.labels),typeof r.expert_quality_score=="number"&&(i.expertQualityScore=r.expert_quality_score),n.push(i)}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 Jn(e){const t=e.payload.product_groupings??[],n=[];for(let o=0;o<t.length;o++){const r=t[o];if(!r)continue;const s=w(r.name)??"",i=r.sku&&r.sku.length>0?{type:"findSimilar",payload:{sku:r.sku}}:void 0,a=C(r.requestDetails??i,s);if(!a)continue;const c={name:s,action:a};if(Array.isArray(r.labels)){const u=r.labels.filter(l=>typeof l=="string");u.length>0&&(c.labels=u)}typeof r.image=="string"&&(c.image=r.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 Bn(e){const t=e.payload.suggested_searches??[],n=[];for(let o=0;o<t.length;o++){const r=t[o];if(!r)continue;const s=w(r.short_name,r.chosen_attribute,r.detailed_user_message)??`Search ${o+1}`,i={},a=w(r.detailed_user_message);a&&(i.text=a);const c=N(r.requestDetails),u=N(c?.payload),l=u?.group_skus;r.group_skus&&Array.isArray(r.group_skus)?i.group_skus=r.group_skus:Array.isArray(l)&&(i.group_skus=l.filter(Z=>typeof Z=="string"));const h=w(r.sku,r.representative_product_sku,u?.sku);h&&(i.sku=h),i.is_suggested_text=1;const p={type:"inputText",payload:i},f=C(r.requestDetails,s),_=f?.type==="findSimilar"&&typeof i.text=="string"?C(p,s):f??C(p,s);if(!_)continue;const m={shortName:s,action:_},v=w(r.detailed_user_message);v&&v!==s&&(m.detailedMessage=v);const b=w(r.why_different);b&&(m.whyDifferent=b),typeof r.image=="string"&&(m.image=r.image),n.push(m)}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 Qn(e){const t=C(e.payload.requestDetails,w(e.payload.review_count,e.payload.text,e.payload.title)??"Urun yorumlarini goster");if(!t)return{type:"metadata",sessionId:"",model:"",meta:{groundingReview:e.payload}};const n={action:t};return e.payload.title&&(n.title=e.payload.title),e.payload.text&&(n.text=e.payload.text),e.payload.review_count&&(n.reviewCount=e.payload.review_count),{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"GroundingReviewCard",props:n}}}}}function Hn(){return{type:"metadata",sessionId:"",model:"",meta:{analyzeAnimation:!0}}}function Vn(e){return{type:"metadata",sessionId:"",model:"",meta:{voice:e.payload}}}function Wn(e){const t=e.payload.group_list??[],n=[];for(const r of t){const s=r.group_name??"",i=(r.product_list??[]).map(B);n.push({groupName:s,products:i})}const o=[];for(const r of e.payload.filter_tags??[]){const s=r.title??"";if(!s)continue;const i=C(r.requestDetails,s),a={title:s};i&&(a.action=i),o.push(a)}return{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"CategoriesContainer",props:{groups:n,filterTags:o}}}},panelHint:"panel"}}function Gn(e){return{type:"metadata",sessionId:"",model:"",meta:{formType:e.type,formPayload:e.payload??{}}}}function Kn(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 Yn(e){return{type:"metadata",sessionId:"",model:"",meta:{launcherContent:e.payload??{}}}}function xe(e,t){const n={},o=[];for(let r=0;r<e.length;r++){const s=e[r];if(!s)continue;const i=`action-${r}`;o.push(i);const a={label:s.label,action:s.action};s.icon!==void 0&&(a.icon=s.icon),s.image!==void 0&&(a.image=s.image),s.description!==void 0&&(a.description=s.description),n[i]={type:"ActionButton",props:a}}return n.root={type:"ActionButtons",props:{buttons:e.map(r=>{const s={label:r.label,action:r.action};return r.image!==void 0&&(s.image=r.image),r.description!==void 0&&(s.description=r.description),r.icon!==void 0&&(s.icon=r.icon),s})},children:o},{type:"ui_spec",widget:t,spec:{root:"root",elements:n}}}function Ue(e,t){const n={},o=[];for(let r=0;r<e.length;r++){const s=e[r];if(!s)continue;const i=`product-${r}`;o.push(i),n[i]={type:"ProductCard",props:{product:B(s),index:r}}}return n.root={type:"ProductGrid",props:{layout:"grid"},children:o},{type:"ui_spec",widget:t,spec:{root:"root",elements:n}}}function Xn(e,t){return{type:"ui_spec",widget:t,spec:{root:"root",elements:{root:{type:"ProductCard",props:{product:B(e),index:0}}}}}}function eo(e){return{type:"ui_spec",widget:e,spec:{root:"root",elements:{root:{type:"ActionButtons",props:{buttons:[]},children:[]}}}}}function to(e){const t=w(e.sku),n=w(e.short_name),o=N(e.product_item)??e;return no(o,t,n)}function no(e,t,n){const o=w(e.sku,t),r=w(e.name,n);if(!o||!r)return null;const s={sku:o,name:r},i=w(e.brand);i&&(s.brand=i);const a=w(e.url);a&&(s.url=a);const c=oo(e.images);if(c.length>0)s.images=c;else{const _=w(e.image,e.image_url,e.imageUrl);_&&(s.images=[_])}const u=G(e.price_discounted);u!==void 0&&(s.price_discounted=u);const l=G(e.price);l!==void 0&&(s.price=l);const h=G(e.rating);h!==void 0&&(s.rating=h);const p=G(e.review_count)??G(e.reviewCount);p!==void 0&&(s.review_count=p);const f=w(e.cart_code,e.cartCode);return f&&(s.cart_code=f),typeof e.in_stock=="boolean"&&(s.in_stock=e.in_stock),typeof e.inStock=="boolean"&&(s.in_stock=e.inStock),B(s)}function C(e,t){const n=N(e);if(!n)return null;const o=n.type;if(typeof o!="string"||o.length===0)return null;const r={title:t||o,type:o};return n.payload!==void 0&&(r.payload=n.payload),r}function N(e){return!e||typeof e!="object"||Array.isArray(e)?null:e}function w(...e){for(const t of e)if(typeof t=="string"){const n=t.trim();if(n.length>0)return n}}function oo(e){return Array.isArray(e)?e.filter(t=>typeof t=="string"&&t.length>0):[]}function ro(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 G(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 qe(e){return e!=null}function B(e){const t=e.price_discounted!=null&&e.price_discounted>0?e.price_discounted:e.price,n=e.price_discounted!=null&&e.price_discounted>0&&e.price!=null?e.price:void 0;let o;n!=null&&t!=null&&n>0&&(o=Math.round((n-t)/n*100));const r=w(e.brand),s=w(e.name)??e.sku,i=r&&!s.toLowerCase().startsWith(r.toLowerCase())?`${r} ${s}`:s,a={sku:e.sku,name:i,url:w(e.url)??""},c=e.images?.[0];return c&&(a.imageUrl=c),e.images&&e.images.length>1&&(a.images=e.images),t!=null&&(a.price=String(t)),n!=null&&(a.originalPrice=String(n)),o!==void 0&&(a.discountPercent=o),r!==void 0&&(a.brand=r),e.rating!==void 0&&(a.rating=e.rating),e.review_count!==void 0&&(a.reviewCount=e.review_count),e.cart_code!==void 0&&(a.cartCode=e.cart_code),e.in_stock!==void 0&&(a.inStock=e.in_stock),e.variants&&e.variants.length>0&&(a.variants=e.variants),e.discount_reason!==void 0&&(a.discountReason=e.discount_reason),e.promotions&&e.promotions.length>0&&(a.promotions=e.promotions),a}async function io(e,t,n){const o=yn("launcher_action",t),r={uiSpecs:[],actions:[]},s={method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)};n!==void 0&&(s.signal=n);const i=await fetch(o,s);if(!i.ok)throw new Error(`HTTP ${i.status}: ${i.statusText}`);const a={onEvent:c=>{const u=vn(c);if(u&&(u.type==="ui_spec"&&r.uiSpecs.push(u.spec),u.type==="ui_spec"&&u.spec.elements)){for(const l of Object.values(u.spec.elements))if(l.type==="ActionButton"&&l.props?.action){const h=l.props.action;r.actions.push(h)}}}};return n!==void 0&&(a.signal=n),await gn(i,a),r}function so(){return typeof window<"u"&&Array.isArray(window.dataLayer)}function _e(e,t){const n={event:e,...t};so()&&window.dataLayer.push(n)}function ao(e){_e("gengage-on-init",{gengage_widget:e})}function co(e){_e("gengage-show",{gengage_widget:e})}function uo(e,t){_e("gengage-suggested-question",{gengage_question_title:e,gengage_action_type:t})}function Fe(e){const t=document.createElement("div");t.className="gengage-qna-buttons",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 o=document.createElement("button");o.className="gengage-qna-button",o.textContent=n.title,o.type="button",o.addEventListener("click",()=>{const r={title:n.title,type:n.type};n.payload!==void 0&&(r.payload=n.payload),e.onAction(r)}),t.appendChild(o)}if(e.ctaText||e.onOpenChat){const n=document.createElement("button");n.className="gengage-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 lo(e){const t=document.createElement("div");t.className="gengage-qna-input-wrapper";const n=document.createElement("input");n.type="text",n.className="gengage-qna-input",n.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 r=0;n.placeholder=o[0]??"";let s=null,i=null;o.length>1&&(s=setInterval(()=>{n.classList.add("gengage-qna-input--fade"),i=setTimeout(()=>{r=(r+1)%o.length,n.placeholder=o[r]??"",n.classList.remove("gengage-qna-input--fade")},180)},3e3));const a=document.createElement("button");a.className="gengage-qna-send",a.type="button",a.textContent=e.ctaLabel??e.sendButtonText??"Ask",a.setAttribute("aria-label",e.sendQuestionAriaLabel??"Send question");const c=()=>{const u=n.value.trim();u&&(e.onSubmit({title:u,type:"user_message",payload:u}),n.value="")};return a.addEventListener("click",c),n.addEventListener("keydown",u=>{u.key==="Enter"&&(u.preventDefault(),c())}),t.appendChild(n),t.appendChild(a),t._cleanup=()=>{s&&clearInterval(s),i&&clearTimeout(i)},t}function te(e,t){if(!e||typeof e!="object")return null;const n=e,o=n.type;if(typeof o!="string"||o.length===0)return null;const r=n.title,s=n.payload,i=typeof r=="string"&&r.length>0?r:t;if(!i)return null;const a={title:i,type:o};return s!==void 0&&(a.payload=s),a}function Me(e){const t={title:e.title,type:e.type};return e.payload!==void 0&&(t.payload=e.payload),t}function Je(e,t){const n=[],o=e.props?.actions;if(Array.isArray(o))for(const i of o){const a=te(i);a&&n.push(a)}const r=e.props?.buttons;if(Array.isArray(r))for(const i of r){if(!i||typeof i!="object")continue;const a=i,c=typeof a.label=="string"?a.label:void 0,u=te(a.action,c);u&&n.push(u)}if(e.children)for(const i of e.children){const a=t.elements[i];if(!a||a.type!=="ActionButton")continue;const c=typeof a.props?.label=="string"?a.props.label:void 0,u=te(a.props?.action,c);u&&n.push(u)}const s=new Set;return n.filter(i=>s.has(i.title)?!1:(s.add(i.title),!0))}const Be={ButtonRow:({element:e,spec:t,context:n})=>{const o=Je(e,t).map(Me),r=e.props?.orientation,s={actions:o,onAction:n.onAction,defaultCtaText:n.i18n.defaultCtaText,quickQuestionsAriaLabel:n.i18n.quickQuestionsAriaLabel};return n.onOpenChat!==void 0&&(s.onOpenChat=n.onOpenChat),n.ctaText!==void 0&&(s.ctaText=n.ctaText),(r==="horizontal"||r==="vertical")&&(s.orientation=r),Fe(s)},ActionButtons:({element:e,spec:t,context:n})=>{const r={actions:Je(e,t).map(Me),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),Fe(r)},ActionButton:({element:e,context:t})=>{const n=document.createElement("button");n.className="gengage-qna-button",n.type="button";const o=e.props?.label;typeof o=="string"?n.textContent=o:n.textContent=t.i18n.defaultCtaText;const r=te(e.props?.action,typeof o=="string"?o:void 0);return r&&n.addEventListener("click",()=>t.onAction(r)),n},TextInput:({element:e,context:t})=>{const n=e.props?.placeholder,o=typeof n=="string"||Array.isArray(n)?n:t.inputPlaceholder,r=typeof e.props?.ctaLabel=="string"?e.props.ctaLabel:void 0,s={onSubmit:t.onAction,askQuestionAriaLabel:t.i18n.askQuestionAriaLabel,defaultInputPlaceholder:t.i18n.defaultInputPlaceholder,sendButtonText:t.i18n.sendButton,sendQuestionAriaLabel:t.i18n.sendQuestionAriaLabel};return o!==void 0&&(s.placeholders=o),r!==void 0&&(s.ctaLabel=r),lo(s)},QuestionHeading:({element:e})=>{const t=document.createElement("h3");t.className="gengage-qna-heading";const n=e.props?.text;return t.textContent=typeof n=="string"?n:"",t},ProductCard:()=>null},ye=({element:e,renderElement:t})=>{if(!e.children||e.children.length===0)return null;const n=document.createElement("div");for(const o of e.children){const r=t(o);r&&n.appendChild(r)}return n};function Qe(){return{...Be}}function He(e,t,n=Be,o=ye){return qt({spec:e,context:t,registry:n,containerClassName:"gengage-qna-uispec",unknownRenderer:o})}const Ve={quickQuestionsAriaLabel:"Hızlı sorular",askQuestionAriaLabel:"Soru sorun",defaultInputPlaceholder:"Bir soru sorun...",sendButton:"Sor",sendQuestionAriaLabel:"Soruyu gönder",defaultCtaText:"Başka bir şey sor"},po={quickQuestionsAriaLabel:"Quick questions",askQuestionAriaLabel:"Ask a question",defaultInputPlaceholder:"Ask a question...",sendButton:"Ask",sendQuestionAriaLabel:"Send question",defaultCtaText:"Ask something else"};function fo(e){return e?e.toLowerCase().split("-")[0]??"tr":"tr"}function ho(e){return fo(e)==="en"?po:Ve}function d(e,t,n){function o(a,c){if(a._zod||Object.defineProperty(a,"_zod",{value:{def:c,constr:i,traits:new Set},enumerable:!1}),a._zod.traits.has(e))return;a._zod.traits.add(e),t(a,c);const u=i.prototype,l=Object.keys(u);for(let h=0;h<l.length;h++){const p=l[h];p in a||(a[p]=u[p].bind(a))}}const r=n?.Parent??Object;class s extends r{}Object.defineProperty(s,"name",{value:e});function i(a){var c;const u=n?.Parent?new s:this;o(u,a),(c=u._zod).deferred??(c.deferred=[]);for(const l of u._zod.deferred)l();return u}return Object.defineProperty(i,"init",{value:o}),Object.defineProperty(i,Symbol.hasInstance,{value:a=>n?.Parent&&a instanceof n.Parent?!0:a?._zod?.traits?.has(e)}),Object.defineProperty(i,"name",{value:e}),i}class Q extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class We extends Error{constructor(t){super(`Encountered unidirectional transform during encode: ${t}`),this.name="ZodEncodeError"}}const Ge={};function q(e){return Ge}function Ke(e){const t=Object.values(e).filter(o=>typeof o=="number");return Object.entries(e).filter(([o,r])=>t.indexOf(+o)===-1).map(([o,r])=>r)}function ve(e,t){return typeof t=="bigint"?t.toString():t}function we(e){return{get value(){{const t=e();return Object.defineProperty(this,"value",{value:t}),t}}}}function be(e){return e==null}function ke(e){const t=e.startsWith("^")?1:0,n=e.endsWith("$")?e.length-1:e.length;return e.slice(t,n)}const Ye=Symbol("evaluating");function y(e,t,n){let o;Object.defineProperty(e,t,{get(){if(o!==Ye)return o===void 0&&(o=Ye,o=n()),o},set(r){Object.defineProperty(e,t,{value:r})},configurable:!0})}function F(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function D(...e){const t={};for(const n of e){const o=Object.getOwnPropertyDescriptors(n);Object.assign(t,o)}return Object.defineProperties({},t)}function Xe(e){return JSON.stringify(e)}function go(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}const et="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function ne(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}const mo=we(()=>{if(typeof navigator<"u"&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{const e=Function;return new e(""),!0}catch{return!1}});function K(e){if(ne(e)===!1)return!1;const t=e.constructor;if(t===void 0||typeof t!="function")return!0;const n=t.prototype;return!(ne(n)===!1||Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")===!1)}function tt(e){return K(e)?{...e}:Array.isArray(e)?[...e]:e}const _o=new Set(["string","number","symbol"]);function oe(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function L(e,t,n){const o=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(o._zod.parent=e),o}function g(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")}function vo(e,t){const n=e._zod.def,o=n.checks;if(o&&o.length>0)throw new Error(".pick() cannot be used on object schemas containing refinements");const s=D(e._zod.def,{get shape(){const i={};for(const a in t){if(!(a in n.shape))throw new Error(`Unrecognized key: "${a}"`);t[a]&&(i[a]=n.shape[a])}return F(this,"shape",i),i},checks:[]});return L(e,s)}function wo(e,t){const n=e._zod.def,o=n.checks;if(o&&o.length>0)throw new Error(".omit() cannot be used on object schemas containing refinements");const s=D(e._zod.def,{get shape(){const i={...e._zod.def.shape};for(const a in t){if(!(a in n.shape))throw new Error(`Unrecognized key: "${a}"`);t[a]&&delete i[a]}return F(this,"shape",i),i},checks:[]});return L(e,s)}function bo(e,t){if(!K(t))throw new Error("Invalid input to extend: expected a plain object");const n=e._zod.def.checks;if(n&&n.length>0){const s=e._zod.def.shape;for(const i in t)if(Object.getOwnPropertyDescriptor(s,i)!==void 0)throw new Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}const r=D(e._zod.def,{get shape(){const s={...e._zod.def.shape,...t};return F(this,"shape",s),s}});return L(e,r)}function ko(e,t){if(!K(t))throw new Error("Invalid input to safeExtend: expected a plain object");const n=D(e._zod.def,{get shape(){const o={...e._zod.def.shape,...t};return F(this,"shape",o),o}});return L(e,n)}function zo(e,t){const n=D(e._zod.def,{get shape(){const o={...e._zod.def.shape,...t._zod.def.shape};return F(this,"shape",o),o},get catchall(){return t._zod.def.catchall},checks:[]});return L(e,n)}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");const i=D(t._zod.def,{get shape(){const a=t._zod.def.shape,c={...a};if(n)for(const u in n){if(!(u in a))throw new Error(`Unrecognized key: "${u}"`);n[u]&&(c[u]=e?new e({type:"optional",innerType:a[u]}):a[u])}else for(const u in a)c[u]=e?new e({type:"optional",innerType:a[u]}):a[u];return F(this,"shape",c),c},checks:[]});return L(t,i)}function $o(e,t,n){const o=D(t._zod.def,{get shape(){const r=t._zod.def.shape,s={...r};if(n)for(const i in n){if(!(i in s))throw new Error(`Unrecognized key: "${i}"`);n[i]&&(s[i]=new e({type:"nonoptional",innerType:r[i]}))}else for(const i in r)s[i]=new e({type:"nonoptional",innerType:r[i]});return F(this,"shape",s),s}});return L(t,o)}function H(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 nt(e,t){return t.map(n=>{var o;return(o=n).path??(o.path=[]),n.path.unshift(e),n})}function re(e){return typeof e=="string"?e:e?.message}function M(e,t,n){const o={...e,path:e.path??[]};if(!e.message){const r=re(e.inst?._zod.def?.error?.(e))??re(t?.error?.(e))??re(n.customError?.(e))??re(n.localeError?.(e))??"Invalid input";o.message=r}return delete o.inst,delete o.continue,t?.reportInput||delete o.input,o}function ze(e){return Array.isArray(e)?"array":typeof e=="string"?"string":"unknown"}function Y(...e){const[t,n,o]=e;return typeof t=="string"?{message:t,code:"custom",input:n,inst:o}:{...t}}const ot=(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,ve,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},rt=d("$ZodError",ot),it=d("$ZodError",ot,{Parent:Error});function To(e,t=n=>n.message){const n={},o=[];for(const r of e.issues)r.path.length>0?(n[r.path[0]]=n[r.path[0]]||[],n[r.path[0]].push(t(r))):o.push(t(r));return{formErrors:o,fieldErrors:n}}function Eo(e,t=n=>n.message){const n={_errors:[]},o=r=>{for(const s of r.issues)if(s.code==="invalid_union"&&s.errors.length)s.errors.map(i=>o({issues:i}));else if(s.code==="invalid_key")o({issues:s.issues});else if(s.code==="invalid_element")o({issues:s.issues});else if(s.path.length===0)n._errors.push(t(s));else{let i=n,a=0;for(;a<s.path.length;){const c=s.path[a];a===s.path.length-1?(i[c]=i[c]||{_errors:[]},i[c]._errors.push(t(s))):i[c]=i[c]||{_errors:[]},i=i[c],a++}}};return o(e),n}const Se=e=>(t,n,o,r)=>{const s=o?Object.assign(o,{async:!1}):{async:!1},i=t._zod.run({value:n,issues:[]},s);if(i instanceof Promise)throw new Q;if(i.issues.length){const a=new(r?.Err??e)(i.issues.map(c=>M(c,s,q())));throw et(a,r?.callee),a}return i.value},$e=e=>async(t,n,o,r)=>{const s=o?Object.assign(o,{async:!0}):{async:!0};let i=t._zod.run({value:n,issues:[]},s);if(i instanceof Promise&&(i=await i),i.issues.length){const a=new(r?.Err??e)(i.issues.map(c=>M(c,s,q())));throw et(a,r?.callee),a}return i.value},ie=e=>(t,n,o)=>{const r=o?{...o,async:!1}:{async:!1},s=t._zod.run({value:n,issues:[]},r);if(s instanceof Promise)throw new Q;return s.issues.length?{success:!1,error:new(e??rt)(s.issues.map(i=>M(i,r,q())))}:{success:!0,data:s.value}},Ao=ie(it),se=e=>async(t,n,o)=>{const r=o?Object.assign(o,{async:!0}):{async:!0};let s=t._zod.run({value:n,issues:[]},r);return s instanceof Promise&&(s=await s),s.issues.length?{success:!1,error:new e(s.issues.map(i=>M(i,r,q())))}:{success:!0,data:s.value}},Io=se(it),Zo=e=>(t,n,o)=>{const r=o?Object.assign(o,{direction:"backward"}):{direction:"backward"};return Se(e)(t,n,r)},Oo=e=>(t,n,o)=>Se(e)(t,n,o),Co=e=>async(t,n,o)=>{const r=o?Object.assign(o,{direction:"backward"}):{direction:"backward"};return $e(e)(t,n,r)},Po=e=>async(t,n,o)=>$e(e)(t,n,o),Ro=e=>(t,n,o)=>{const r=o?Object.assign(o,{direction:"backward"}):{direction:"backward"};return ie(e)(t,n,r)},No=e=>(t,n,o)=>ie(e)(t,n,o),jo=e=>async(t,n,o)=>{const r=o?Object.assign(o,{direction:"backward"}):{direction:"backward"};return se(e)(t,n,r)},Do=e=>async(t,n,o)=>se(e)(t,n,o),Lo=/^[cC][^\s-]{8,}$/,xo=/^[0-9a-z]+$/,Uo=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,qo=/^[0-9a-vA-V]{20}$/,Fo=/^[A-Za-z0-9]{27}$/,Mo=/^[a-zA-Z0-9_-]{21}$/,Jo=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,Bo=/^([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})$/,st=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,}$/,Ho="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";function Vo(){return new RegExp(Ho,"u")}const Wo=/^(?:(?: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])$/,Go=/^(([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}|:))$/,Ko=/^((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])$/,Yo=/^(([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])$/,Xo=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,at=/^[A-Za-z0-9_-]*$/,er=/^\+[1-9]\d{6,14}$/,ct="(?:(?:\\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])))",tr=new RegExp(`^${ct}$`);function ut(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 nr(e){return new RegExp(`^${ut(e)}$`)}function or(e){const t=ut({precision:e.precision}),n=["Z"];e.local&&n.push(""),e.offset&&n.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");const o=`${t}(?:${n.join("|")})`;return new RegExp(`^${ct}T(?:${o})$`)}const rr=e=>{const t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??""}}`:"[\\s\\S]*";return new RegExp(`^${t}$`)},ir=/^(?:true|false)$/i,sr=/^[^A-Z]*$/,ar=/^[^a-z]*$/,P=d("$ZodCheck",(e,t)=>{var n;e._zod??(e._zod={}),e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),cr=d("$ZodCheckMaxLength",(e,t)=>{var n;P.init(e,t),(n=e._zod.def).when??(n.when=o=>{const r=o.value;return!be(r)&&r.length!==void 0}),e._zod.onattach.push(o=>{const r=o._zod.bag.maximum??Number.POSITIVE_INFINITY;t.maximum<r&&(o._zod.bag.maximum=t.maximum)}),e._zod.check=o=>{const r=o.value;if(r.length<=t.maximum)return;const i=ze(r);o.issues.push({origin:i,code:"too_big",maximum:t.maximum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),ur=d("$ZodCheckMinLength",(e,t)=>{var n;P.init(e,t),(n=e._zod.def).when??(n.when=o=>{const r=o.value;return!be(r)&&r.length!==void 0}),e._zod.onattach.push(o=>{const r=o._zod.bag.minimum??Number.NEGATIVE_INFINITY;t.minimum>r&&(o._zod.bag.minimum=t.minimum)}),e._zod.check=o=>{const r=o.value;if(r.length>=t.minimum)return;const i=ze(r);o.issues.push({origin:i,code:"too_small",minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),dr=d("$ZodCheckLengthEquals",(e,t)=>{var n;P.init(e,t),(n=e._zod.def).when??(n.when=o=>{const r=o.value;return!be(r)&&r.length!==void 0}),e._zod.onattach.push(o=>{const r=o._zod.bag;r.minimum=t.length,r.maximum=t.length,r.length=t.length}),e._zod.check=o=>{const r=o.value,s=r.length;if(s===t.length)return;const i=ze(r),a=s>t.length;o.issues.push({origin:i,...a?{code:"too_big",maximum:t.length}:{code:"too_small",minimum:t.length},inclusive:!0,exact:!0,input:o.value,inst:e,continue:!t.abort})}}),ae=d("$ZodCheckStringFormat",(e,t)=>{var n,o;P.init(e,t),e._zod.onattach.push(r=>{const s=r._zod.bag;s.format=t.format,t.pattern&&(s.patterns??(s.patterns=new Set),s.patterns.add(t.pattern))}),t.pattern?(n=e._zod).check??(n.check=r=>{t.pattern.lastIndex=0,!t.pattern.test(r.value)&&r.issues.push({origin:"string",code:"invalid_format",format:t.format,input:r.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(o=e._zod).check??(o.check=()=>{})}),lr=d("$ZodCheckRegex",(e,t)=>{ae.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})}}),pr=d("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=sr),ae.init(e,t)}),fr=d("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=ar),ae.init(e,t)}),hr=d("$ZodCheckIncludes",(e,t)=>{P.init(e,t);const n=oe(t.includes),o=new RegExp(typeof t.position=="number"?`^.{${t.position}}${n}`:n);t.pattern=o,e._zod.onattach.push(r=>{const s=r._zod.bag;s.patterns??(s.patterns=new Set),s.patterns.add(o)}),e._zod.check=r=>{r.value.includes(t.includes,t.position)||r.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:t.includes,input:r.value,inst:e,continue:!t.abort})}}),gr=d("$ZodCheckStartsWith",(e,t)=>{P.init(e,t);const n=new RegExp(`^${oe(t.prefix)}.*`);t.pattern??(t.pattern=n),e._zod.onattach.push(o=>{const r=o._zod.bag;r.patterns??(r.patterns=new Set),r.patterns.add(n)}),e._zod.check=o=>{o.value.startsWith(t.prefix)||o.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:t.prefix,input:o.value,inst:e,continue:!t.abort})}}),mr=d("$ZodCheckEndsWith",(e,t)=>{P.init(e,t);const n=new RegExp(`.*${oe(t.suffix)}$`);t.pattern??(t.pattern=n),e._zod.onattach.push(o=>{const r=o._zod.bag;r.patterns??(r.patterns=new Set),r.patterns.add(n)}),e._zod.check=o=>{o.value.endsWith(t.suffix)||o.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:t.suffix,input:o.value,inst:e,continue:!t.abort})}}),_r=d("$ZodCheckOverwrite",(e,t)=>{P.init(e,t),e._zod.check=n=>{n.value=t.tx(n.value)}});class yr{constructor(t=[]){this.content=[],this.indent=0,this&&(this.args=t)}indented(t){this.indent+=1,t(this),this.indent-=1}write(t){if(typeof t=="function"){t(this,{execution:"sync"}),t(this,{execution:"async"});return}const o=t.split(`
|
|
46
|
+
`,document.head.appendChild(e)}let W=null;function ln(){if(W!==null)return W;try{W=localStorage.getItem("gengage:debug")==="1"}catch{W=!1}return W}function ge(e,t,n){if(!ln())return;const o=[`[gengage:${e}]`,t];n!==void 0&&o.push(n),console.debug(...o)}class pn{constructor(){this.isVisible=!1,this.isInitialised=!1,this._handlers=new Map,this._cleanups=[],this._ownsRoot=!1,this._destroying=!1}async init(t){if(this.isInitialised){console.warn("[gengage] Widget already initialised. Call update() instead.");return}const n=Yt(t.theme);this.config={...t,theme:n,session:Kt(t.session)},this.root=this._resolveMount(t.mountTarget),this._applyTheme(n),on();const o=Oe("gengage:context:update",r=>this.update(r));this._cleanups.push(o),ge("lifecycle",`${this.constructor.name}.init`,{accountId:t.accountId,sku:t.pageContext?.sku});try{await this.onInit(this.config)}catch(r){throw this.destroy(),r}this.isInitialised=!0,ge("lifecycle",`${this.constructor.name} ready`),this.emit("ready")}update(t){this.isInitialised&&(this.config.pageContext?this.config={...this.config,pageContext:{...this.config.pageContext,...t}}:t.pageType!==void 0&&(this.config={...this.config,pageContext:t}),this.onUpdate(t),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(t=>t()),this._cleanups.length=0,this._handlers.clear(),this.onDestroy(),this.config.analyticsClient?.destroy(),this._ownsRoot?this.root.remove():this.root.innerHTML="",this.isInitialised=!1)}on(t,n){return this._handlers.has(t)||this._handlers.set(t,new Set),this._handlers.get(t).add(n),()=>this._handlers.get(t)?.delete(n)}trackCheckout(t,n){const o=t==="start"?Vt:Wt;this.track(o(this.analyticsContext(),n))}flushMeteringSummary(t){this.track(Qt(this.analyticsContext(),t))}emit(t,...n){this._handlers.get(t)?.forEach(o=>o(...n))}addCleanup(t){this._cleanups.push(t)}track(t){this.config.analyticsClient?.track(t)}analyticsContext(){const t={account_id:this.config.accountId,session_id:this.config.session?.sessionId??"",correlation_id:this.config.session?.sessionId??""};return this.config.session?.viewId!==void 0&&(t.view_id=this.config.session.viewId),this.config.session?.userId!==void 0&&(t.user_id=this.config.session.userId),this.config.pageContext?.pageType!==void 0&&(t.page_type=this.config.pageContext.pageType),this.config.pageContext?.sku!==void 0&&(t.sku=this.config.pageContext.sku),this.config.session?.abTestVariant!==void 0&&(t.ab_test_variant=this.config.session.abTestVariant),this.config.session?.abTestExperimentId!==void 0&&(t.ab_test_experiment_id=this.config.session.abTestExperimentId),t}_resolveMount(t){if(t instanceof HTMLElement)return t;if(typeof t=="string"){const o=document.querySelector(t);if(!o)throw new Error(`[gengage] Mount target not found: "${t}"`);return o}const n=document.createElement("div");return n.dataset.gengageWidget=this.constructor.name.toLowerCase(),document.body.appendChild(n),this._ownsRoot=!0,n}_applyTheme(t){if(t){for(const[n,o]of Object.entries(t))if(o!==void 0){const r=n.startsWith("--")?n:`--gengage-${fn(n)}`;this.root.style.setProperty(r,o)}}}}function fn(e){return e.replace(/([A-Z])/g,"-$1").toLowerCase()}function Ne(e){return typeof e=="object"&&e!==null&&typeof e.type=="string"}function hn(e){const t=[];let n=0,o=!1,r=!1,s=0;for(let i=0;i<e.length;i++){const a=e[i];if(r){r=!1;continue}if(a==="\\"&&o){r=!0;continue}if(a==='"'){o=!o;continue}o||(a==="{"&&n++,a==="}"&&(n--,n===0&&(t.push(e.slice(s,i+1)),s=i+1)))}return t.length>0?t:[e]}function je(e,t){const n=e.trim();if(!n||n.startsWith(":"))return!1;const o=n.startsWith("data: ")?n.slice(6):n;if(o==="[DONE]")return t.onDone?.(),!0;try{const r=JSON.parse(o);return Ne(r)?(ge("stream",`event: ${r.type}`,r),t.onEvent(r),r.type==="done"?(t.onDone?.(),!0):!1):!1}catch{const r=hn(o);if(r.length>1){for(const s of r)try{const i=JSON.parse(s);if(!Ne(i))continue;if(t.onEvent(i),i.type==="done")return t.onDone?.(),!0}catch{}return!1}return!1}}async function gn(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(),o=new TextDecoder("utf-8");let r="";const s=t.idleTimeoutMs??6e4,i=Symbol("idle-timeout");let a=!1;try{for(;;){const c=n.read();let u;const l=await(s>0?Promise.race([c.then(_=>(clearTimeout(u),_)),new Promise(_=>{u=setTimeout(()=>_(i),s)})]):c);if(l===i){a=!0,await n.cancel();break}const{done:h,value:p}=l;if(h)break;r+=o.decode(p,{stream:!0});const f=r.split(`
|
|
47
|
+
`);r=f.pop()??"";for(const _ of f)if(je(_,t))return}if(r.trim()&&je(r,t))return}catch(c){if(c instanceof DOMException&&c.name==="AbortError")return;t.onError?.(c instanceof Error?c:new Error(String(c)))}finally{a||n.releaseLock()}t.onDone?.()}const mn={process_action:"/process_action",launcher_action:"/launcher_action",similar_products:"/similar_products",product_groupings:"/product_groupings"};function _n(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 yn(e,t){return`${_n(t?.middlewareUrl)}/chat${mn[e]}`}function vn(e){if(typeof e.type!="string")return null;if(wn(e))return e;const n=e;switch(n.type){case"outputText":return bn(n);case"suggestedActions":return kn(n);case"productList":return zn(n);case"productDetails":return Sn(n);case"productDetailsSimilars":return $n(n);case"comparisonTable":return Tn(n);case"context":return Zn(n);case"chatStreamEnd":return On();case"loading":return Cn(n);case"panelLoading":return Pn(n);case"similarLoading":return Rn(n);case"redirect":return Nn(n);case"error":return jn(n);case"dummy":return Dn();case"launcherAction":return Ln(n);case"text":return me(n);case"productItem":return xn(n);case"text_image":return De(n);case"quick_qna":return Le(n);case"reviewHighlights":return Un(n);case"aiProductSuggestions":return Mn(n);case"aiProductGroupings":return Jn(n);case"aiSuggestedSearches":return Bn(n);case"prosAndCons":return qn(n);case"getGroundingReview":return Qn(n);case"voice":return Vn(n);case"visitorDataResponse":return Fn(n);case"productListPreview":return Hn();case"groupList":return Wn(n);case"formGetInfo":case"formTestDrive":case"formServiceRequest":case"launchFormPage":return Gn(n);case"launcherContent":return Yn(n);case"handoff":return Kn(n);default:return null}}function wn(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 o=N(e.spec);return o?typeof o.root=="string"&&N(o.elements)!==null:!1}case"action":{const n=N(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 bn(e){const t=w(e.payload.text,e.payload.plain_text)??"",n=w(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 o={type:"text_chunk",content:t,final:!0},r=e.payload.product_mentions;Array.isArray(r)&&r.length>0&&(o.productMentions=r.filter(a=>typeof a=="object"&&a!==null&&typeof a.sku=="string"&&typeof a.short_name=="string"));const s=e.payload.sku_to_product_item;s&&typeof s=="object"&&!Array.isArray(s)&&(o.skuToProductItem=s);const i=e.payload.conversation_mode;return typeof i=="string"&&i&&(o.conversationMode=i),o}function kn(e){const t=(e.payload.actions??[]).map(n=>{const o=w(n.title)??"",r=C(n.requestDetails,o),s=r?{label:o,action:r}:null;return s?(typeof n.icon=="string"&&(s.icon=n.icon),typeof n.image=="string"&&(s.image=n.image),s):null});return xe(t.filter(qe),"chat")}function zn(e){const t=Ue(e.payload.product_list??[],"chat");t.panelHint="panel";const n=t.spec.elements[t.spec.root];return n&&(typeof e.payload.offset=="number"&&(n.props={...n.props,offset:e.payload.offset}),typeof e.payload.end_of_list=="boolean"&&(n.props={...n.props,endOfList:e.payload.end_of_list}),typeof e.payload.title=="string"&&(n.props={...n.props,panelTitle:e.payload.title})),t}function Sn(e){const t=e.payload.productDetails;return t?{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"ProductDetailsPanel",props:{product:B(t)}}}},panelHint:"panel"}:eo("chat")}function $n(e){const t=Ue(e.payload.similarProducts??[],"chat"),n=t.spec.elements[t.spec.root];return n&&(n.props={...n.props,similarsAppend:!0}),{...t,panelHint:"panel"}}function Tn(e){const t=e.payload.multiple_product_details??[],n=e.payload,o={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??{}},r=e.payload.table,s=e.payload.features_list,i=[];for(const v of t){const b=B(v);i.push(b)}const a=En(r,i,o,s);let c;o?.recommended_choice_sku?c=o.recommended_choice_sku:o?.winner_product&&o.winner_product.length>0&&(c=o.winner_product[0]?.product_detail?.sku??o.winner_product[0]?.sku);const u=c?i.find(v=>v.sku===c)??i[0]:i[0],l=[];if(Array.isArray(o?.key_differences))for(const v of o.key_differences)typeof v=="string"&&l.push(v);const h=ro(o?.special_considerations),p=o?.recommended_choice,f=o?.winner_hits,_={};for(const v of i){const b=v.sku;b&&(_[b]={title:v.name??b,type:"launchSingleProduct",payload:{sku:b}})}const m={products:i,attributes:a,highlights:l,productActions:_};return u&&(m.recommended=u),h.length>0&&(m.specialCases=h),p&&(m.recommendedText=p),f&&(m.winnerHits=f),typeof o?.key_differences=="string"&&(m.keyDifferencesHtml=o.key_differences),o?.special_considerations&&(m.specialConsiderations=o.special_considerations),{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"ComparisonTable",props:m}}},panelHint:"panel"}}function En(e,t,n,o){if(!e)return[];const r=Object.entries(e);if(r.length===0)return[];const s=r[0]?.[1];if(Array.isArray(s)){const p=n.criteria_view??n.criteria_view_short??{},f=n.compared_field_names??Object.keys(e),_=[];for(const m of f){const v=e[m];if(!v||!Array.isArray(v))continue;const b=p[m]??m;_.push({label:b,values:v.map(Z=>typeof Z=="string"?Z:String(Z??""))})}return _}const i=e,a=t.map(p=>String(p.sku??"")).filter(p=>p.length>0),c=n.criteria_view??n.criteria_view_short??{},l=(o&&o.length>0?o:n.compared_field_names&&n.compared_field_names.length>0?n.compared_field_names:An(i)).filter(p=>p!=="name"&&p!=="name_short"&&!p.endsWith("_short")),h=[];for(const p of l){const f=a.map(m=>{const v=i[m];if(!v||typeof v!="object")return"";const b=v[`${p}_short`],Z=v[p];return In(b??Z)});if(f.every(m=>m.length===0))continue;const _=c[p]??p;h.push({label:_,values:f})}return h}function An(e){const t=[],n=new Set;for(const o of Object.values(e))if(!(!o||typeof o!="object"))for(const r of Object.keys(o))n.has(r)||(n.add(r),t.push(r));return t}function In(e){return typeof e=="string"?e:typeof e=="number"||typeof e=="boolean"?String(e):""}function Zn(e){return{type:"metadata",sessionId:"",model:"",meta:{panel:e.payload.panel,messages:e.payload.messages,message_id:e.payload.message_id}}}function On(){return{type:"done"}}function Cn(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 Pn(e){return{type:"metadata",sessionId:"",model:"",meta:{loading:!0,panelLoading:!0,panelPendingType:e.payload?.pending_type,loadingText:e.payload?.text}}}function Rn(e){return{type:"metadata",sessionId:"",model:"",meta:{loading:!0,similarPanelLoading:!0,panelPendingType:e.payload?.pending_type,loadingText:e.payload?.text}}}function Nn(e){const t=w(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:w(e.payload.to)}}}function jn(e){return{type:"error",code:"BACKEND_ERROR",message:w(e.payload?.text,e.payload?.message,e.payload?.error)??"Backend returned an error"}}function Dn(e){return{type:"metadata",sessionId:"",model:"",meta:{noop:!0}}}function Ln(e){const t=e.payload??{};if(Array.isArray(t.action_list)){const s={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&&(s.type=i),a!==void 0&&(s.theme=a),Le({payload:s})}const o=N(t.action);if(o){const s={action:o},i=typeof t.text=="string"?t.text:void 0,a=typeof t.image_url=="string"?t.image_url:void 0,c=typeof t.theme=="string"?t.theme:void 0;return i!==void 0&&(s.text=i),a!==void 0&&(s.image_url=a),c!==void 0&&(s.theme=c),De({payload:s})}const r=typeof t.text=="string"?t.text:"";if(r){const s={text:r},i=typeof t.type=="string"?t.type:void 0,a=typeof t.theme=="string"?t.theme:void 0,c=N(t.payload)??void 0;return i!==void 0&&(s.type=i),c!==void 0&&(s.payload=c),a!==void 0&&(s.theme=a),me({payload:s})}return{type:"metadata",sessionId:"",model:"",meta:{launcherAction:t}}}function me(e){const t={text:w(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 xn(e){return Xn(e.payload,"qna")}function De(e){const t=w(e.payload.text)??"",n=C(e.payload.action,t);if(n){const r={label:t||n.title,action:n};return typeof e.payload.image_url=="string"&&(r.image=e.payload.image_url),typeof e.payload.theme=="string"&&(r.theme=e.payload.theme),{type:"ui_spec",widget:"qna",spec:{root:"root",elements:{root:{type:"ActionButton",props:r}}}}}const o={text:t};return typeof e.payload.theme=="string"&&(o.theme=e.payload.theme),me({payload:o})}function Le(e){const t=(e.payload.action_list??[]).map(n=>{const o=w(n.title)??"",r=C(n.requestDetails,o),s=r?{label:o,action:r}:null;return s?(typeof n.icon=="string"&&(s.icon=n.icon),typeof n.image=="string"&&(s.image=n.image),s):null});return xe(t.filter(qe),"qna")}function Un(e){const n={reviews:(e.payload.reviews??[]).map(o=>{const r={};return typeof o.review_class=="string"&&(r.review_class=o.review_class),typeof o.review_text=="string"&&(r.review_text=o.review_text),(typeof o.review_rating=="string"||typeof o.review_rating=="number")&&(r.review_rating=o.review_rating),typeof o.review_tag=="string"&&(r.review_tag=o.review_tag),r})};return typeof e.payload.sku=="string"&&(n.sku=e.payload.sku),{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"ReviewHighlights",props:n}}}}}function qn(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 Fn(e){return{type:"metadata",sessionId:"",model:"",meta:{visitorDataResponse:e.payload}}}function Mn(e){const t=e.payload.product_suggestions??[],n=[];for(let o=0;o<t.length;o++){const r=t[o];if(!r)continue;const s=to(r);if(!s)continue;const i={product:s},a=C(r.requestDetails,s.name);a&&(i.action=a),typeof r.role=="string"&&(i.role=r.role),typeof r.reason=="string"&&(i.reason=r.reason),typeof r.review_highlight=="string"&&(i.reviewHighlight=r.review_highlight),Array.isArray(r.labels)&&(i.labels=r.labels),typeof r.expert_quality_score=="number"&&(i.expertQualityScore=r.expert_quality_score),n.push(i)}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 Jn(e){const t=e.payload.product_groupings??[],n=[];for(let o=0;o<t.length;o++){const r=t[o];if(!r)continue;const s=w(r.name)??"",i=r.sku&&r.sku.length>0?{type:"findSimilar",payload:{sku:r.sku}}:void 0,a=C(r.requestDetails??i,s);if(!a)continue;const c={name:s,action:a};if(Array.isArray(r.labels)){const u=r.labels.filter(l=>typeof l=="string");u.length>0&&(c.labels=u)}typeof r.image=="string"&&(c.image=r.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 Bn(e){const t=e.payload.suggested_searches??[],n=[];for(let o=0;o<t.length;o++){const r=t[o];if(!r)continue;const s=w(r.short_name,r.chosen_attribute,r.detailed_user_message)??`Search ${o+1}`,i={},a=w(r.detailed_user_message);a&&(i.text=a);const c=N(r.requestDetails),u=N(c?.payload),l=u?.group_skus;r.group_skus&&Array.isArray(r.group_skus)?i.group_skus=r.group_skus:Array.isArray(l)&&(i.group_skus=l.filter(Z=>typeof Z=="string"));const h=w(r.sku,r.representative_product_sku,u?.sku);h&&(i.sku=h),i.is_suggested_text=1;const p={type:"inputText",payload:i},f=C(r.requestDetails,s),_=f?.type==="findSimilar"&&typeof i.text=="string"?C(p,s):f??C(p,s);if(!_)continue;const m={shortName:s,action:_},v=w(r.detailed_user_message);v&&v!==s&&(m.detailedMessage=v);const b=w(r.why_different);b&&(m.whyDifferent=b),typeof r.image=="string"&&(m.image=r.image),n.push(m)}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 Qn(e){const t=C(e.payload.requestDetails,w(e.payload.review_count,e.payload.text,e.payload.title)??"Urun yorumlarini goster");if(!t)return{type:"metadata",sessionId:"",model:"",meta:{groundingReview:e.payload}};const n={action:t};return e.payload.title&&(n.title=e.payload.title),e.payload.text&&(n.text=e.payload.text),e.payload.review_count&&(n.reviewCount=e.payload.review_count),{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"GroundingReviewCard",props:n}}}}}function Hn(){return{type:"metadata",sessionId:"",model:"",meta:{analyzeAnimation:!0}}}function Vn(e){return{type:"metadata",sessionId:"",model:"",meta:{voice:e.payload}}}function Wn(e){const t=e.payload.group_list??[],n=[];for(const r of t){const s=r.group_name??"",i=(r.product_list??[]).map(B);n.push({groupName:s,products:i})}const o=[];for(const r of e.payload.filter_tags??[]){const s=r.title??"";if(!s)continue;const i=C(r.requestDetails,s),a={title:s};i&&(a.action=i),o.push(a)}return{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"CategoriesContainer",props:{groups:n,filterTags:o}}}},panelHint:"panel"}}function Gn(e){return{type:"metadata",sessionId:"",model:"",meta:{formType:e.type,formPayload:e.payload??{}}}}function Kn(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 Yn(e){return{type:"metadata",sessionId:"",model:"",meta:{launcherContent:e.payload??{}}}}function xe(e,t){const n={},o=[];for(let r=0;r<e.length;r++){const s=e[r];if(!s)continue;const i=`action-${r}`;o.push(i);const a={label:s.label,action:s.action};s.icon!==void 0&&(a.icon=s.icon),s.image!==void 0&&(a.image=s.image),s.description!==void 0&&(a.description=s.description),n[i]={type:"ActionButton",props:a}}return n.root={type:"ActionButtons",props:{buttons:e.map(r=>{const s={label:r.label,action:r.action};return r.image!==void 0&&(s.image=r.image),r.description!==void 0&&(s.description=r.description),r.icon!==void 0&&(s.icon=r.icon),s})},children:o},{type:"ui_spec",widget:t,spec:{root:"root",elements:n}}}function Ue(e,t){const n={},o=[];for(let r=0;r<e.length;r++){const s=e[r];if(!s)continue;const i=`product-${r}`;o.push(i),n[i]={type:"ProductCard",props:{product:B(s),index:r}}}return n.root={type:"ProductGrid",props:{layout:"grid"},children:o},{type:"ui_spec",widget:t,spec:{root:"root",elements:n}}}function Xn(e,t){return{type:"ui_spec",widget:t,spec:{root:"root",elements:{root:{type:"ProductCard",props:{product:B(e),index:0}}}}}}function eo(e){return{type:"ui_spec",widget:e,spec:{root:"root",elements:{root:{type:"ActionButtons",props:{buttons:[]},children:[]}}}}}function to(e){const t=w(e.sku),n=w(e.short_name),o=N(e.product_item)??e;return no(o,t,n)}function no(e,t,n){const o=w(e.sku,t),r=w(e.name,n);if(!o||!r)return null;const s={sku:o,name:r},i=w(e.brand);i&&(s.brand=i);const a=w(e.url);a&&(s.url=a);const c=oo(e.images);if(c.length>0)s.images=c;else{const _=w(e.image,e.image_url,e.imageUrl);_&&(s.images=[_])}const u=G(e.price_discounted);u!==void 0&&(s.price_discounted=u);const l=G(e.price);l!==void 0&&(s.price=l);const h=G(e.rating);h!==void 0&&(s.rating=h);const p=G(e.review_count)??G(e.reviewCount);p!==void 0&&(s.review_count=p);const f=w(e.cart_code,e.cartCode);return f&&(s.cart_code=f),typeof e.in_stock=="boolean"&&(s.in_stock=e.in_stock),typeof e.inStock=="boolean"&&(s.in_stock=e.inStock),B(s)}function C(e,t){const n=N(e);if(!n)return null;const o=n.type;if(typeof o!="string"||o.length===0)return null;const r={title:t||o,type:o};return n.payload!==void 0&&(r.payload=n.payload),r}function N(e){return!e||typeof e!="object"||Array.isArray(e)?null:e}function w(...e){for(const t of e)if(typeof t=="string"){const n=t.trim();if(n.length>0)return n}}function oo(e){return Array.isArray(e)?e.filter(t=>typeof t=="string"&&t.length>0):[]}function ro(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 G(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 qe(e){return e!=null}function B(e){const t=e.price_discounted!=null&&e.price_discounted>0,n=t?e.price_discounted:e.price,o=t&&e.price!=null?e.price:void 0;let r;o!=null&&n!=null&&o>0&&(r=Math.round((o-n)/o*100));const s=w(e.brand),i=w(e.name)??e.sku,a=s&&!i.toLowerCase().startsWith(s.toLowerCase())?`${s} ${i}`:i,c={sku:e.sku,name:a,url:w(e.url)??""},u=e.images?.[0];return u&&(c.imageUrl=u),e.images&&e.images.length>1&&(c.images=e.images),n!=null&&(c.price=String(n)),o!=null&&(c.originalPrice=String(o)),r!==void 0&&(c.discountPercent=r),s!==void 0&&(c.brand=s),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),c}async function io(e,t,n){const o=yn("launcher_action",t),r={uiSpecs:[],actions:[]},s={method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)};n!==void 0&&(s.signal=n);const i=await fetch(o,s);if(!i.ok)throw new Error(`HTTP ${i.status}: ${i.statusText}`);const a={onEvent:c=>{const u=vn(c);if(u&&(u.type==="ui_spec"&&r.uiSpecs.push(u.spec),u.type==="ui_spec"&&u.spec.elements)){for(const l of Object.values(u.spec.elements))if(l.type==="ActionButton"&&l.props?.action){const h=l.props.action;r.actions.push(h)}}}};return n!==void 0&&(a.signal=n),await gn(i,a),r}function so(){return typeof window<"u"&&Array.isArray(window.dataLayer)}function _e(e,t){const n={event:e,...t};so()&&window.dataLayer.push(n)}function ao(e){_e("gengage-on-init",{gengage_widget:e})}function co(e){_e("gengage-show",{gengage_widget:e})}function uo(e,t){_e("gengage-suggested-question",{gengage_question_title:e,gengage_action_type:t})}function Fe(e){const t=document.createElement("div");t.className="gengage-qna-buttons",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 o=document.createElement("button");o.className="gengage-qna-button",o.textContent=n.title,o.type="button",o.addEventListener("click",()=>{const r={title:n.title,type:n.type};n.payload!==void 0&&(r.payload=n.payload),e.onAction(r)}),t.appendChild(o)}if(e.ctaText||e.onOpenChat){const n=document.createElement("button");n.className="gengage-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 lo(e){const t=document.createElement("div");t.className="gengage-qna-input-wrapper";const n=document.createElement("input");n.type="text",n.className="gengage-qna-input",n.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 r=0;n.placeholder=o[0]??"";let s=null,i=null;o.length>1&&(s=setInterval(()=>{n.classList.add("gengage-qna-input--fade"),i=setTimeout(()=>{r=(r+1)%o.length,n.placeholder=o[r]??"",n.classList.remove("gengage-qna-input--fade")},180)},3e3));const a=document.createElement("button");a.className="gengage-qna-send",a.type="button",a.textContent=e.ctaLabel??e.sendButtonText??"Ask",a.setAttribute("aria-label",e.sendQuestionAriaLabel??"Send question");const c=()=>{const u=n.value.trim();u&&(e.onSubmit({title:u,type:"user_message",payload:u}),n.value="")};return a.addEventListener("click",c),n.addEventListener("keydown",u=>{u.key==="Enter"&&(u.preventDefault(),c())}),t.appendChild(n),t.appendChild(a),t._cleanup=()=>{s&&clearInterval(s),i&&clearTimeout(i)},t}function te(e,t){if(!e||typeof e!="object")return null;const n=e,o=n.type;if(typeof o!="string"||o.length===0)return null;const r=n.title,s=n.payload,i=typeof r=="string"&&r.length>0?r:t;if(!i)return null;const a={title:i,type:o};return s!==void 0&&(a.payload=s),a}function Me(e){const t={title:e.title,type:e.type};return e.payload!==void 0&&(t.payload=e.payload),t}function Je(e,t){const n=[],o=e.props?.actions;if(Array.isArray(o))for(const i of o){const a=te(i);a&&n.push(a)}const r=e.props?.buttons;if(Array.isArray(r))for(const i of r){if(!i||typeof i!="object")continue;const a=i,c=typeof a.label=="string"?a.label:void 0,u=te(a.action,c);u&&n.push(u)}if(e.children)for(const i of e.children){const a=t.elements[i];if(!a||a.type!=="ActionButton")continue;const c=typeof a.props?.label=="string"?a.props.label:void 0,u=te(a.props?.action,c);u&&n.push(u)}const s=new Set;return n.filter(i=>s.has(i.title)?!1:(s.add(i.title),!0))}const Be={ButtonRow:({element:e,spec:t,context:n})=>{const o=Je(e,t).map(Me),r=e.props?.orientation,s={actions:o,onAction:n.onAction,defaultCtaText:n.i18n.defaultCtaText,quickQuestionsAriaLabel:n.i18n.quickQuestionsAriaLabel};return n.onOpenChat!==void 0&&(s.onOpenChat=n.onOpenChat),n.ctaText!==void 0&&(s.ctaText=n.ctaText),(r==="horizontal"||r==="vertical")&&(s.orientation=r),Fe(s)},ActionButtons:({element:e,spec:t,context:n})=>{const r={actions:Je(e,t).map(Me),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),Fe(r)},ActionButton:({element:e,context:t})=>{const n=document.createElement("button");n.className="gengage-qna-button",n.type="button";const o=e.props?.label;typeof o=="string"?n.textContent=o:n.textContent=t.i18n.defaultCtaText;const r=te(e.props?.action,typeof o=="string"?o:void 0);return r&&n.addEventListener("click",()=>t.onAction(r)),n},TextInput:({element:e,context:t})=>{const n=e.props?.placeholder,o=typeof n=="string"||Array.isArray(n)?n:t.inputPlaceholder,r=typeof e.props?.ctaLabel=="string"?e.props.ctaLabel:void 0,s={onSubmit:t.onAction,askQuestionAriaLabel:t.i18n.askQuestionAriaLabel,defaultInputPlaceholder:t.i18n.defaultInputPlaceholder,sendButtonText:t.i18n.sendButton,sendQuestionAriaLabel:t.i18n.sendQuestionAriaLabel};return o!==void 0&&(s.placeholders=o),r!==void 0&&(s.ctaLabel=r),lo(s)},QuestionHeading:({element:e})=>{const t=document.createElement("h3");t.className="gengage-qna-heading";const n=e.props?.text;return t.textContent=typeof n=="string"?n:"",t},ProductCard:()=>null},ye=({element:e,renderElement:t})=>{if(!e.children||e.children.length===0)return null;const n=document.createElement("div");for(const o of e.children){const r=t(o);r&&n.appendChild(r)}return n};function Qe(){return{...Be}}function He(e,t,n=Be,o=ye){return qt({spec:e,context:t,registry:n,containerClassName:"gengage-qna-uispec",unknownRenderer:o})}const Ve={quickQuestionsAriaLabel:"Hızlı sorular",askQuestionAriaLabel:"Soru sorun",defaultInputPlaceholder:"Bir soru sorun...",sendButton:"Sor",sendQuestionAriaLabel:"Soruyu gönder",defaultCtaText:"Başka bir şey sor"},po={quickQuestionsAriaLabel:"Quick questions",askQuestionAriaLabel:"Ask a question",defaultInputPlaceholder:"Ask a question...",sendButton:"Ask",sendQuestionAriaLabel:"Send question",defaultCtaText:"Ask something else"};function fo(e){return e?e.toLowerCase().split("-")[0]??"tr":"tr"}function ho(e){return fo(e)==="en"?po:Ve}function d(e,t,n){function o(a,c){if(a._zod||Object.defineProperty(a,"_zod",{value:{def:c,constr:i,traits:new Set},enumerable:!1}),a._zod.traits.has(e))return;a._zod.traits.add(e),t(a,c);const u=i.prototype,l=Object.keys(u);for(let h=0;h<l.length;h++){const p=l[h];p in a||(a[p]=u[p].bind(a))}}const r=n?.Parent??Object;class s extends r{}Object.defineProperty(s,"name",{value:e});function i(a){var c;const u=n?.Parent?new s:this;o(u,a),(c=u._zod).deferred??(c.deferred=[]);for(const l of u._zod.deferred)l();return u}return Object.defineProperty(i,"init",{value:o}),Object.defineProperty(i,Symbol.hasInstance,{value:a=>n?.Parent&&a instanceof n.Parent?!0:a?._zod?.traits?.has(e)}),Object.defineProperty(i,"name",{value:e}),i}class Q extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class We extends Error{constructor(t){super(`Encountered unidirectional transform during encode: ${t}`),this.name="ZodEncodeError"}}const Ge={};function q(e){return Ge}function Ke(e){const t=Object.values(e).filter(o=>typeof o=="number");return Object.entries(e).filter(([o,r])=>t.indexOf(+o)===-1).map(([o,r])=>r)}function ve(e,t){return typeof t=="bigint"?t.toString():t}function we(e){return{get value(){{const t=e();return Object.defineProperty(this,"value",{value:t}),t}}}}function be(e){return e==null}function ke(e){const t=e.startsWith("^")?1:0,n=e.endsWith("$")?e.length-1:e.length;return e.slice(t,n)}const Ye=Symbol("evaluating");function y(e,t,n){let o;Object.defineProperty(e,t,{get(){if(o!==Ye)return o===void 0&&(o=Ye,o=n()),o},set(r){Object.defineProperty(e,t,{value:r})},configurable:!0})}function F(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function D(...e){const t={};for(const n of e){const o=Object.getOwnPropertyDescriptors(n);Object.assign(t,o)}return Object.defineProperties({},t)}function Xe(e){return JSON.stringify(e)}function go(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}const et="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function ne(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}const mo=we(()=>{if(typeof navigator<"u"&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{const e=Function;return new e(""),!0}catch{return!1}});function K(e){if(ne(e)===!1)return!1;const t=e.constructor;if(t===void 0||typeof t!="function")return!0;const n=t.prototype;return!(ne(n)===!1||Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")===!1)}function tt(e){return K(e)?{...e}:Array.isArray(e)?[...e]:e}const _o=new Set(["string","number","symbol"]);function oe(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function L(e,t,n){const o=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(o._zod.parent=e),o}function g(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")}function vo(e,t){const n=e._zod.def,o=n.checks;if(o&&o.length>0)throw new Error(".pick() cannot be used on object schemas containing refinements");const s=D(e._zod.def,{get shape(){const i={};for(const a in t){if(!(a in n.shape))throw new Error(`Unrecognized key: "${a}"`);t[a]&&(i[a]=n.shape[a])}return F(this,"shape",i),i},checks:[]});return L(e,s)}function wo(e,t){const n=e._zod.def,o=n.checks;if(o&&o.length>0)throw new Error(".omit() cannot be used on object schemas containing refinements");const s=D(e._zod.def,{get shape(){const i={...e._zod.def.shape};for(const a in t){if(!(a in n.shape))throw new Error(`Unrecognized key: "${a}"`);t[a]&&delete i[a]}return F(this,"shape",i),i},checks:[]});return L(e,s)}function bo(e,t){if(!K(t))throw new Error("Invalid input to extend: expected a plain object");const n=e._zod.def.checks;if(n&&n.length>0){const s=e._zod.def.shape;for(const i in t)if(Object.getOwnPropertyDescriptor(s,i)!==void 0)throw new Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}const r=D(e._zod.def,{get shape(){const s={...e._zod.def.shape,...t};return F(this,"shape",s),s}});return L(e,r)}function ko(e,t){if(!K(t))throw new Error("Invalid input to safeExtend: expected a plain object");const n=D(e._zod.def,{get shape(){const o={...e._zod.def.shape,...t};return F(this,"shape",o),o}});return L(e,n)}function zo(e,t){const n=D(e._zod.def,{get shape(){const o={...e._zod.def.shape,...t._zod.def.shape};return F(this,"shape",o),o},get catchall(){return t._zod.def.catchall},checks:[]});return L(e,n)}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");const i=D(t._zod.def,{get shape(){const a=t._zod.def.shape,c={...a};if(n)for(const u in n){if(!(u in a))throw new Error(`Unrecognized key: "${u}"`);n[u]&&(c[u]=e?new e({type:"optional",innerType:a[u]}):a[u])}else for(const u in a)c[u]=e?new e({type:"optional",innerType:a[u]}):a[u];return F(this,"shape",c),c},checks:[]});return L(t,i)}function $o(e,t,n){const o=D(t._zod.def,{get shape(){const r=t._zod.def.shape,s={...r};if(n)for(const i in n){if(!(i in s))throw new Error(`Unrecognized key: "${i}"`);n[i]&&(s[i]=new e({type:"nonoptional",innerType:r[i]}))}else for(const i in r)s[i]=new e({type:"nonoptional",innerType:r[i]});return F(this,"shape",s),s}});return L(t,o)}function H(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 nt(e,t){return t.map(n=>{var o;return(o=n).path??(o.path=[]),n.path.unshift(e),n})}function re(e){return typeof e=="string"?e:e?.message}function M(e,t,n){const o={...e,path:e.path??[]};if(!e.message){const r=re(e.inst?._zod.def?.error?.(e))??re(t?.error?.(e))??re(n.customError?.(e))??re(n.localeError?.(e))??"Invalid input";o.message=r}return delete o.inst,delete o.continue,t?.reportInput||delete o.input,o}function ze(e){return Array.isArray(e)?"array":typeof e=="string"?"string":"unknown"}function Y(...e){const[t,n,o]=e;return typeof t=="string"?{message:t,code:"custom",input:n,inst:o}:{...t}}const ot=(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,ve,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},rt=d("$ZodError",ot),it=d("$ZodError",ot,{Parent:Error});function To(e,t=n=>n.message){const n={},o=[];for(const r of e.issues)r.path.length>0?(n[r.path[0]]=n[r.path[0]]||[],n[r.path[0]].push(t(r))):o.push(t(r));return{formErrors:o,fieldErrors:n}}function Eo(e,t=n=>n.message){const n={_errors:[]},o=r=>{for(const s of r.issues)if(s.code==="invalid_union"&&s.errors.length)s.errors.map(i=>o({issues:i}));else if(s.code==="invalid_key")o({issues:s.issues});else if(s.code==="invalid_element")o({issues:s.issues});else if(s.path.length===0)n._errors.push(t(s));else{let i=n,a=0;for(;a<s.path.length;){const c=s.path[a];a===s.path.length-1?(i[c]=i[c]||{_errors:[]},i[c]._errors.push(t(s))):i[c]=i[c]||{_errors:[]},i=i[c],a++}}};return o(e),n}const Se=e=>(t,n,o,r)=>{const s=o?Object.assign(o,{async:!1}):{async:!1},i=t._zod.run({value:n,issues:[]},s);if(i instanceof Promise)throw new Q;if(i.issues.length){const a=new(r?.Err??e)(i.issues.map(c=>M(c,s,q())));throw et(a,r?.callee),a}return i.value},$e=e=>async(t,n,o,r)=>{const s=o?Object.assign(o,{async:!0}):{async:!0};let i=t._zod.run({value:n,issues:[]},s);if(i instanceof Promise&&(i=await i),i.issues.length){const a=new(r?.Err??e)(i.issues.map(c=>M(c,s,q())));throw et(a,r?.callee),a}return i.value},ie=e=>(t,n,o)=>{const r=o?{...o,async:!1}:{async:!1},s=t._zod.run({value:n,issues:[]},r);if(s instanceof Promise)throw new Q;return s.issues.length?{success:!1,error:new(e??rt)(s.issues.map(i=>M(i,r,q())))}:{success:!0,data:s.value}},Ao=ie(it),se=e=>async(t,n,o)=>{const r=o?Object.assign(o,{async:!0}):{async:!0};let s=t._zod.run({value:n,issues:[]},r);return s instanceof Promise&&(s=await s),s.issues.length?{success:!1,error:new e(s.issues.map(i=>M(i,r,q())))}:{success:!0,data:s.value}},Io=se(it),Zo=e=>(t,n,o)=>{const r=o?Object.assign(o,{direction:"backward"}):{direction:"backward"};return Se(e)(t,n,r)},Oo=e=>(t,n,o)=>Se(e)(t,n,o),Co=e=>async(t,n,o)=>{const r=o?Object.assign(o,{direction:"backward"}):{direction:"backward"};return $e(e)(t,n,r)},Po=e=>async(t,n,o)=>$e(e)(t,n,o),Ro=e=>(t,n,o)=>{const r=o?Object.assign(o,{direction:"backward"}):{direction:"backward"};return ie(e)(t,n,r)},No=e=>(t,n,o)=>ie(e)(t,n,o),jo=e=>async(t,n,o)=>{const r=o?Object.assign(o,{direction:"backward"}):{direction:"backward"};return se(e)(t,n,r)},Do=e=>async(t,n,o)=>se(e)(t,n,o),Lo=/^[cC][^\s-]{8,}$/,xo=/^[0-9a-z]+$/,Uo=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,qo=/^[0-9a-vA-V]{20}$/,Fo=/^[A-Za-z0-9]{27}$/,Mo=/^[a-zA-Z0-9_-]{21}$/,Jo=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,Bo=/^([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})$/,st=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,}$/,Ho="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";function Vo(){return new RegExp(Ho,"u")}const Wo=/^(?:(?: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])$/,Go=/^(([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}|:))$/,Ko=/^((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])$/,Yo=/^(([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])$/,Xo=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,at=/^[A-Za-z0-9_-]*$/,er=/^\+[1-9]\d{6,14}$/,ct="(?:(?:\\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])))",tr=new RegExp(`^${ct}$`);function ut(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 nr(e){return new RegExp(`^${ut(e)}$`)}function or(e){const t=ut({precision:e.precision}),n=["Z"];e.local&&n.push(""),e.offset&&n.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");const o=`${t}(?:${n.join("|")})`;return new RegExp(`^${ct}T(?:${o})$`)}const rr=e=>{const t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??""}}`:"[\\s\\S]*";return new RegExp(`^${t}$`)},ir=/^(?:true|false)$/i,sr=/^[^A-Z]*$/,ar=/^[^a-z]*$/,P=d("$ZodCheck",(e,t)=>{var n;e._zod??(e._zod={}),e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),cr=d("$ZodCheckMaxLength",(e,t)=>{var n;P.init(e,t),(n=e._zod.def).when??(n.when=o=>{const r=o.value;return!be(r)&&r.length!==void 0}),e._zod.onattach.push(o=>{const r=o._zod.bag.maximum??Number.POSITIVE_INFINITY;t.maximum<r&&(o._zod.bag.maximum=t.maximum)}),e._zod.check=o=>{const r=o.value;if(r.length<=t.maximum)return;const i=ze(r);o.issues.push({origin:i,code:"too_big",maximum:t.maximum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),ur=d("$ZodCheckMinLength",(e,t)=>{var n;P.init(e,t),(n=e._zod.def).when??(n.when=o=>{const r=o.value;return!be(r)&&r.length!==void 0}),e._zod.onattach.push(o=>{const r=o._zod.bag.minimum??Number.NEGATIVE_INFINITY;t.minimum>r&&(o._zod.bag.minimum=t.minimum)}),e._zod.check=o=>{const r=o.value;if(r.length>=t.minimum)return;const i=ze(r);o.issues.push({origin:i,code:"too_small",minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),dr=d("$ZodCheckLengthEquals",(e,t)=>{var n;P.init(e,t),(n=e._zod.def).when??(n.when=o=>{const r=o.value;return!be(r)&&r.length!==void 0}),e._zod.onattach.push(o=>{const r=o._zod.bag;r.minimum=t.length,r.maximum=t.length,r.length=t.length}),e._zod.check=o=>{const r=o.value,s=r.length;if(s===t.length)return;const i=ze(r),a=s>t.length;o.issues.push({origin:i,...a?{code:"too_big",maximum:t.length}:{code:"too_small",minimum:t.length},inclusive:!0,exact:!0,input:o.value,inst:e,continue:!t.abort})}}),ae=d("$ZodCheckStringFormat",(e,t)=>{var n,o;P.init(e,t),e._zod.onattach.push(r=>{const s=r._zod.bag;s.format=t.format,t.pattern&&(s.patterns??(s.patterns=new Set),s.patterns.add(t.pattern))}),t.pattern?(n=e._zod).check??(n.check=r=>{t.pattern.lastIndex=0,!t.pattern.test(r.value)&&r.issues.push({origin:"string",code:"invalid_format",format:t.format,input:r.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(o=e._zod).check??(o.check=()=>{})}),lr=d("$ZodCheckRegex",(e,t)=>{ae.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})}}),pr=d("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=sr),ae.init(e,t)}),fr=d("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=ar),ae.init(e,t)}),hr=d("$ZodCheckIncludes",(e,t)=>{P.init(e,t);const n=oe(t.includes),o=new RegExp(typeof t.position=="number"?`^.{${t.position}}${n}`:n);t.pattern=o,e._zod.onattach.push(r=>{const s=r._zod.bag;s.patterns??(s.patterns=new Set),s.patterns.add(o)}),e._zod.check=r=>{r.value.includes(t.includes,t.position)||r.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:t.includes,input:r.value,inst:e,continue:!t.abort})}}),gr=d("$ZodCheckStartsWith",(e,t)=>{P.init(e,t);const n=new RegExp(`^${oe(t.prefix)}.*`);t.pattern??(t.pattern=n),e._zod.onattach.push(o=>{const r=o._zod.bag;r.patterns??(r.patterns=new Set),r.patterns.add(n)}),e._zod.check=o=>{o.value.startsWith(t.prefix)||o.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:t.prefix,input:o.value,inst:e,continue:!t.abort})}}),mr=d("$ZodCheckEndsWith",(e,t)=>{P.init(e,t);const n=new RegExp(`.*${oe(t.suffix)}$`);t.pattern??(t.pattern=n),e._zod.onattach.push(o=>{const r=o._zod.bag;r.patterns??(r.patterns=new Set),r.patterns.add(n)}),e._zod.check=o=>{o.value.endsWith(t.suffix)||o.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:t.suffix,input:o.value,inst:e,continue:!t.abort})}}),_r=d("$ZodCheckOverwrite",(e,t)=>{P.init(e,t),e._zod.check=n=>{n.value=t.tx(n.value)}});class yr{constructor(t=[]){this.content=[],this.indent=0,this&&(this.args=t)}indented(t){this.indent+=1,t(this),this.indent-=1}write(t){if(typeof t=="function"){t(this,{execution:"sync"}),t(this,{execution:"async"});return}const o=t.split(`
|
|
48
48
|
`).filter(i=>i),r=Math.min(...o.map(i=>i.length-i.trimStart().length)),s=o.map(i=>i.slice(r)).map(i=>" ".repeat(this.indent*2)+i);for(const i of s)this.content.push(i)}compile(){const t=Function,n=this?.args,r=[...(this?.content??[""]).map(s=>` ${s}`)];return new t(...n,r.join(`
|
|
49
49
|
`))}}const vr={major:4,minor:3,patch:6},S=d("$ZodType",(e,t)=>{var n;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=vr;const o=[...e._zod.def.checks??[]];e._zod.traits.has("$ZodCheck")&&o.unshift(e);for(const r of o)for(const s of r._zod.onattach)s(e);if(o.length===0)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{const r=(i,a,c)=>{let u=H(i),l;for(const h of a){if(h._zod.def.when){if(!h._zod.def.when(i))continue}else if(u)continue;const p=i.issues.length,f=h._zod.check(i);if(f instanceof Promise&&c?.async===!1)throw new Q;if(l||f instanceof Promise)l=(l??Promise.resolve()).then(async()=>{await f,i.issues.length!==p&&(u||(u=H(i,p)))});else{if(i.issues.length===p)continue;u||(u=H(i,p))}}return l?l.then(()=>i):i},s=(i,a,c)=>{if(H(i))return i.aborted=!0,i;const u=r(a,o,c);if(u instanceof Promise){if(c.async===!1)throw new Q;return u.then(l=>e._zod.parse(l,c))}return e._zod.parse(u,c)};e._zod.run=(i,a)=>{if(a.skipChecks)return e._zod.parse(i,a);if(a.direction==="backward"){const u=e._zod.parse({value:i.value,issues:[]},{...a,skipChecks:!0});return u instanceof Promise?u.then(l=>s(l,i,a)):s(u,i,a)}const c=e._zod.parse(i,a);if(c instanceof Promise){if(a.async===!1)throw new Q;return c.then(u=>r(u,o,a))}return r(c,o,a)}}y(e,"~standard",()=>({validate:r=>{try{const s=Ao(e,r);return s.success?{value:s.data}:{issues:s.error?.issues}}catch{return Io(e,r).then(i=>i.success?{value:i.data}:{issues:i.error?.issues})}},vendor:"zod",version:1}))}),Te=d("$ZodString",(e,t)=>{S.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??rr(e._zod.bag),e._zod.parse=(n,o)=>{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}}),k=d("$ZodStringFormat",(e,t)=>{ae.init(e,t),Te.init(e,t)}),wr=d("$ZodGUID",(e,t)=>{t.pattern??(t.pattern=Bo),k.init(e,t)}),br=d("$ZodUUID",(e,t)=>{if(t.version){const o={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(o===void 0)throw new Error(`Invalid UUID version: "${t.version}"`);t.pattern??(t.pattern=st(o))}else t.pattern??(t.pattern=st());k.init(e,t)}),kr=d("$ZodEmail",(e,t)=>{t.pattern??(t.pattern=Qo),k.init(e,t)}),zr=d("$ZodURL",(e,t)=>{k.init(e,t),e._zod.check=n=>{try{const o=n.value.trim(),r=new URL(o);t.hostname&&(t.hostname.lastIndex=0,t.hostname.test(r.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(r.protocol.endsWith(":")?r.protocol.slice(0,-1):r.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=r.href:n.value=o;return}catch{n.issues.push({code:"invalid_format",format:"url",input:n.value,inst:e,continue:!t.abort})}}}),Sr=d("$ZodEmoji",(e,t)=>{t.pattern??(t.pattern=Vo()),k.init(e,t)}),$r=d("$ZodNanoID",(e,t)=>{t.pattern??(t.pattern=Mo),k.init(e,t)}),Tr=d("$ZodCUID",(e,t)=>{t.pattern??(t.pattern=Lo),k.init(e,t)}),Er=d("$ZodCUID2",(e,t)=>{t.pattern??(t.pattern=xo),k.init(e,t)}),Ar=d("$ZodULID",(e,t)=>{t.pattern??(t.pattern=Uo),k.init(e,t)}),Ir=d("$ZodXID",(e,t)=>{t.pattern??(t.pattern=qo),k.init(e,t)}),Zr=d("$ZodKSUID",(e,t)=>{t.pattern??(t.pattern=Fo),k.init(e,t)}),Or=d("$ZodISODateTime",(e,t)=>{t.pattern??(t.pattern=or(t)),k.init(e,t)}),Cr=d("$ZodISODate",(e,t)=>{t.pattern??(t.pattern=tr),k.init(e,t)}),Pr=d("$ZodISOTime",(e,t)=>{t.pattern??(t.pattern=nr(t)),k.init(e,t)}),Rr=d("$ZodISODuration",(e,t)=>{t.pattern??(t.pattern=Jo),k.init(e,t)}),Nr=d("$ZodIPv4",(e,t)=>{t.pattern??(t.pattern=Wo),k.init(e,t),e._zod.bag.format="ipv4"}),jr=d("$ZodIPv6",(e,t)=>{t.pattern??(t.pattern=Go),k.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})}}}),Dr=d("$ZodCIDRv4",(e,t)=>{t.pattern??(t.pattern=Ko),k.init(e,t)}),Lr=d("$ZodCIDRv6",(e,t)=>{t.pattern??(t.pattern=Yo),k.init(e,t),e._zod.check=n=>{const o=n.value.split("/");try{if(o.length!==2)throw new Error;const[r,s]=o;if(!s)throw new Error;const i=Number(s);if(`${i}`!==s)throw new Error;if(i<0||i>128)throw new Error;new URL(`http://[${r}]`)}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}}const xr=d("$ZodBase64",(e,t)=>{t.pattern??(t.pattern=Xo),k.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 Ur(e){if(!at.test(e))return!1;const t=e.replace(/[-_]/g,o=>o==="-"?"+":"/"),n=t.padEnd(Math.ceil(t.length/4)*4,"=");return dt(n)}const qr=d("$ZodBase64URL",(e,t)=>{t.pattern??(t.pattern=at),k.init(e,t),e._zod.bag.contentEncoding="base64url",e._zod.check=n=>{Ur(n.value)||n.issues.push({code:"invalid_format",format:"base64url",input:n.value,inst:e,continue:!t.abort})}}),Fr=d("$ZodE164",(e,t)=>{t.pattern??(t.pattern=er),k.init(e,t)});function Mr(e,t=null){try{const n=e.split(".");if(n.length!==3)return!1;const[o]=n;if(!o)return!1;const r=JSON.parse(atob(o));return!("typ"in r&&r?.typ!=="JWT"||!r.alg||t&&(!("alg"in r)||r.alg!==t))}catch{return!1}}const Jr=d("$ZodJWT",(e,t)=>{k.init(e,t),e._zod.check=n=>{Mr(n.value,t.alg)||n.issues.push({code:"invalid_format",format:"jwt",input:n.value,inst:e,continue:!t.abort})}}),Br=d("$ZodBoolean",(e,t)=>{S.init(e,t),e._zod.pattern=ir,e._zod.parse=(n,o)=>{if(t.coerce)try{n.value=!!n.value}catch{}const r=n.value;return typeof r=="boolean"||n.issues.push({expected:"boolean",code:"invalid_type",input:r,inst:e}),n}}),Qr=d("$ZodUnknown",(e,t)=>{S.init(e,t),e._zod.parse=n=>n}),Hr=d("$ZodNever",(e,t)=>{S.init(e,t),e._zod.parse=(n,o)=>(n.issues.push({expected:"never",code:"invalid_type",input:n.value,inst:e}),n)});function lt(e,t,n){e.issues.length&&t.issues.push(...nt(n,e.issues)),t.value[n]=e.value}const Vr=d("$ZodArray",(e,t)=>{S.init(e,t),e._zod.parse=(n,o)=>{const r=n.value;if(!Array.isArray(r))return n.issues.push({expected:"array",code:"invalid_type",input:r,inst:e}),n;n.value=Array(r.length);const s=[];for(let i=0;i<r.length;i++){const a=r[i],c=t.element._zod.run({value:a,issues:[]},o);c instanceof Promise?s.push(c.then(u=>lt(u,n,i))):lt(c,n,i)}return s.length?Promise.all(s).then(()=>n):n}});function ce(e,t,n,o,r){if(e.issues.length){if(r&&!(n in o))return;t.issues.push(...nt(n,e.issues))}e.value===void 0?n in o&&(t.value[n]=void 0):t.value[n]=e.value}function pt(e){const t=Object.keys(e.shape);for(const o of t)if(!e.shape?.[o]?._zod?.traits?.has("$ZodType"))throw new Error(`Invalid element at key "${o}": 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 ft(e,t,n,o,r,s){const i=[],a=r.keySet,c=r.catchall._zod,u=c.def.type,l=c.optout==="optional";for(const h in t){if(a.has(h))continue;if(u==="never"){i.push(h);continue}const p=c.run({value:t[h],issues:[]},o);p instanceof Promise?e.push(p.then(f=>ce(f,n,h,t,l))):ce(p,n,h,t,l)}return i.length&&n.issues.push({code:"unrecognized_keys",keys:i,input:t,inst:s}),e.length?Promise.all(e).then(()=>n):n}const Wr=d("$ZodObject",(e,t)=>{if(S.init(e,t),!Object.getOwnPropertyDescriptor(t,"shape")?.get){const a=t.shape;Object.defineProperty(t,"shape",{get:()=>{const c={...a};return Object.defineProperty(t,"shape",{value:c}),c}})}const o=we(()=>pt(t));y(e._zod,"propValues",()=>{const a=t.shape,c={};for(const u in a){const l=a[u]._zod;if(l.values){c[u]??(c[u]=new Set);for(const h of l.values)c[u].add(h)}}return c});const r=ne,s=t.catchall;let i;e._zod.parse=(a,c)=>{i??(i=o.value);const u=a.value;if(!r(u))return a.issues.push({expected:"object",code:"invalid_type",input:u,inst:e}),a;a.value={};const l=[],h=i.shape;for(const p of i.keys){const f=h[p],_=f._zod.optout==="optional",m=f._zod.run({value:u[p],issues:[]},c);m instanceof Promise?l.push(m.then(v=>ce(v,a,p,u,_))):ce(m,a,p,u,_)}return s?ft(l,u,a,c,o.value,e):l.length?Promise.all(l).then(()=>a):a}}),Gr=d("$ZodObjectJIT",(e,t)=>{Wr.init(e,t);const n=e._zod.parse,o=we(()=>pt(t)),r=p=>{const f=new yr(["shape","payload","ctx"]),_=o.value,m=R=>{const A=Xe(R);return`shape[${A}]._zod.run({ value: input[${A}], issues: [] }, ctx)`};f.write("const input = payload.value;");const v=Object.create(null);let b=0;for(const R of _.keys)v[R]=`key_${b++}`;f.write("const newResult = {};");for(const R of _.keys){const A=v[R],O=Xe(R),qa=p[R]?._zod?.optout==="optional";f.write(`const ${A} = ${m(R)};`),qa?f.write(`
|
|
50
50
|
if (${A}.issues.length) {
|