@cimulate/copilot-widget 1.33.1 → 1.33.3
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/CHANGELOG.md +8 -0
- package/dist/cimulate-copilot-widget.es.js +1 -1
- package/dist/cimulate-copilot-widget.umd.js +1 -1
- package/dist/copilot.es.js +1 -1
- package/dist/copilot.umd.js +1 -1
- package/dist/messaging.es.js +341 -341
- package/dist/messaging.umd.js +13 -13
- package/package.json +1 -1
package/dist/copilot.umd.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
`);return u===-1?"":s.stack.slice(u+1)})();try{if(!r.stack)r.stack=a;else if(a){const u=a.indexOf(`
|
|
8
8
|
`),c=u===-1?-1:a.indexOf(`
|
|
9
9
|
`,u+1),d=c===-1?"":a.slice(c+1);String(r.stack).endsWith(d)||(r.stack+=`
|
|
10
|
-
`+a)}}catch(u){}}throw r}})}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=ns(this.defaults,n);const{transitional:r,paramsSerializer:s,headers:a}=n;r!==void 0&&cl.assertOptions(r,{silentJSONParsing:pn.transitional(pn.boolean),forcedJSONParsing:pn.transitional(pn.boolean),clarifyTimeoutError:pn.transitional(pn.boolean),legacyInterceptorReqResOrdering:pn.transitional(pn.boolean),advertiseZstdAcceptEncoding:pn.transitional(pn.boolean),validateStatusUndefinedResolves:pn.transitional(pn.boolean)},!1),s!=null&&($.isFunction(s)?n.paramsSerializer={serialize:s}:cl.assertOptions(s,{encode:pn.function,serialize:pn.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),cl.assertOptions(n,{baseUrl:pn.spelling("baseURL"),withXsrfToken:pn.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let u=a&&$.merge(a.common,a[n.method]);a&&$.forEach(["delete","get","head","post","put","patch","query","common"],_=>{delete a[_]}),n.headers=hn.concat(u,a);const c=[];let d=!0;this.interceptors.request.forEach(function(A){if(typeof A.runWhen=="function"&&A.runWhen(n)===!1)return;d=d&&A.synchronous;const v=n.transitional||cf;v&&v.legacyInterceptorReqResOrdering?c.unshift(A.fulfilled,A.rejected):c.push(A.fulfilled,A.rejected)});const f=[];this.interceptors.response.forEach(function(A){f.push(A.fulfilled,A.rejected)});let p,m=0,b;if(!d){const _=[Mg.bind(this),void 0];for(_.unshift(...c),_.push(...f),b=_.length,p=Promise.resolve(n);m<b;)p=p.then(_[m++],_[m++]);return p}b=c.length;let y=n;for(;m<b;){const _=c[m++],A=c[m++];try{y=_(y)}catch(v){A.call(this,v);break}}try{p=Mg.call(this,y)}catch(_){return Promise.reject(_)}for(m=0,b=f.length;m<b;)p=p.then(f[m++],f[m++]);return p}getUri(t){t=ns(this.defaults,t);const n=Cg(t.baseURL,t.url,t.allowAbsoluteUrls,t);return gg(n,t.params,t.paramsSerializer)}};$.forEach(["delete","get","head","options"],function(t){rs.prototype[t]=function(n,r){return this.request(ns(r||{},{method:t,url:n,data:r&&$.hasOwnProp(r,"data")?r.data:void 0}))}}),$.forEach(["post","put","patch","query"],function(t){function n(r){return function(a,u,c){return this.request(ns(c||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:a,data:u}))}}rs.prototype[t]=n(),t!=="query"&&(rs.prototype[t+"Form"]=n(!0))});let rv=class M2{constructor(t){if(typeof t!="function")throw new TypeError("executor must be a function.");let n;this.promise=new Promise(function(a){n=a});const r=this;this.promise.then(s=>{if(!r._listeners)return;let a=r._listeners.length;for(;a-- >0;)r._listeners[a](s);r._listeners=null}),this.promise.then=s=>{let a;const u=new Promise(c=>{r.subscribe(c),a=c}).then(s);return u.cancel=function(){r.unsubscribe(a)},u},t(function(a,u,c){r.reason||(r.reason=new fa(a,u,c),n(r.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(t){if(this.reason){t(this.reason);return}this._listeners?this._listeners.push(t):this._listeners=[t]}unsubscribe(t){if(!this._listeners)return;const n=this._listeners.indexOf(t);n!==-1&&this._listeners.splice(n,1)}toAbortSignal(){const t=new AbortController,n=r=>{t.abort(r)};return this.subscribe(n),t.signal.unsubscribe=()=>this.unsubscribe(n),t.signal}static source(){let t;return{token:new M2(function(s){t=s}),cancel:t}}};function iv(e){return function(n){return e.apply(null,n)}}function sv(e){return $.isObject(e)&&e.isAxiosError===!0}const Ef={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511,WebServerIsDown:521,ConnectionTimedOut:522,OriginIsUnreachable:523,TimeoutOccurred:524,SslHandshakeFailed:525,InvalidSslCertificate:526};Object.entries(Ef).forEach(([e,t])=>{Ef[t]=e});function Bg(e){const t=new rs(e),n=Z0(rs.prototype.request,t);return $.extend(n,rs.prototype,t,{allOwnKeys:!0}),$.extend(n,t,null,{allOwnKeys:!0}),n.create=function(s){return Bg(ns(e,s))},n}const Rt=Bg(da);Rt.Axios=rs,Rt.CanceledError=fa,Rt.CancelToken=rv,Rt.isCancel=_g,Rt.VERSION=pf,Rt.toFormData=sl,Rt.AxiosError=be,Rt.Cancel=Rt.CanceledError,Rt.all=function(t){return Promise.all(t)},Rt.spread=iv,Rt.isAxiosError=sv,Rt.mergeConfig=ns,Rt.AxiosHeaders=hn,Rt.formToJSON=e=>bg($.isHTMLForm(e)?new FormData(e):e),Rt.getAdapter=Dg.getAdapter,Rt.HttpStatusCode=Ef,Rt.default=Rt;const{Axios:U7,AxiosError:H7,CanceledError:z7,isCancel:j7,CancelToken:$7,VERSION:V7,all:q7,Cancel:Y7,isAxiosError:G7,spread:W7,toFormData:X7,AxiosHeaders:K7,HttpStatusCode:Q7,formToJSON:J7,getAdapter:Z7,mergeConfig:eU,create:tU}=Rt;class ov{constructor(t,n,r,s=!1,a,u){Se(this,"CIMULATE_API_HEADER","x-cimulate-api-key");Se(this,"CIMULATE_SEARCH_API_HOST","search.cimulate");Se(this,"CIMULATE_SEARCH_API_PATH","api/v1");Se(this,"baseApiUrl");Se(this,"headers",{});Se(this,"fetchConfig",()=>Ke(this,null,function*(){try{const t=yield Rt.get(`${this.apiUrl}/configs/copilot`,{headers:this.headers}),{customer_config:n}=t.data,r=atob(n);return JSON.parse(r)}catch(t){throw console.error("Error fetching customer config:",t),t}}));Se(this,"_mapCopilotUrlToSearchUrl",(t="",n=!1)=>{if(t.endsWith("io")){const s=new URL(t);return s.hostname=s.hostname.replace(/^copilot\./,"api."),s.origin}return n?`https://staging.${this.CIMULATE_SEARCH_API_HOST}.ai`:`https://prod.${this.CIMULATE_SEARCH_API_HOST}.ai`});if(n&&r||!n&&!r)throw new Error("Provide exactly one authentication method: either 'apiKey' or 'apiToken', but not both.");n?this.headers[this.CIMULATE_API_HEADER]=n:r&&(this.headers.Authorization=`Bearer ${r}`),a&&(this.headers["x-cimulate-customer-id"]=a),u&&(this.headers["Tenant-ID"]=u),this.baseApiUrl=this._mapCopilotUrlToSearchUrl(t,s)}get apiUrl(){return`${this.baseApiUrl}/${this.CIMULATE_SEARCH_API_PATH}`}}class av{constructor(t,n,r,s=!1,a,u){Se(this,"apiService");Se(this,"config",null);Se(this,"getConfig",()=>Ke(this,null,function*(){if(this.config)return this.config;try{const t=yield this.apiService.fetchConfig();return this.config=t,this.config}catch(t){throw console.error("Failed to fetch customer config:",t),t}}));Se(this,"getPid",t=>this.getProductFieldValue(t,"pidCol"));Se(this,"getName",t=>this.getProductFieldValue(t,"nameCol"));Se(this,"getDescription",t=>this.getProductFieldValue(t,"description"));Se(this,"getBrand",t=>this.getProductFieldValue(t,"productBrandCol"));Se(this,"getPrice",t=>this.getProductFieldValue(t,"priceCol"));Se(this,"getRelativePdp",t=>this.getProductFieldValue(t,"relativePdpCol"));Se(this,"getPdp",t=>this.getProductFieldValue(t,"pdpCol"));Se(this,"getImage",t=>this.getProductFieldValue(t,"imageCol"));Se(this,"getProductHiddenFields",()=>{const t=this.getProductField("productHiddenFields");return Array.isArray(t)?t:[]});Se(this,"getProductField",t=>this.config?this.config[t]:"");Se(this,"getProductFieldValue",(t,n)=>{const r=this.getProductField(n);return r&&t[r]||""});this.apiService=new ov(t,n,r,s,a,u)}getPriceDisplay(t){const n=this.getPrice(t);return n?typeof n=="string"?n.includes("$")?n:`$${n}`:typeof n=="number"?new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}).format(n):n:""}}const Ws=(e,t,n,...r)=>{if(!e)return;const s=["background: linear-gradient(90deg,rgba(253, 99, 99, 1) 0%, rgba(245, 139, 35, 1) 65%)","font-weight: bold","color: transparent","background-clip: text","text-fill-color: transparent"].join(";");console[t]("%c[cimulate-widget]",s,n,...r)};class uv{constructor(t=!1){Se(this,"isDevelopment");Se(this,"_log",(t,n,...r)=>{Ws(this.isDevelopment,t,n,...r)});this.isDevelopment=t}log(t,...n){this._log("log",t,...n)}warn(t,...n){this._log("warn",t,...n)}error(t,...n){this._log("error",t,...n)}info(t,...n){this._log("info",t,...n)}debug(t,...n){this._log("debug",t,...n)}}const lv={copilot:"Your Search Assistant",messaging:"Commerce Client"},Ug=B.createContext(null),cv=({mode:e,logoUrl:t,headerText:n,headerConfig:r,globalClassName:s="",entryMessage:a,openLinksInNewTab:u=!1,disclaimerText:c,disclaimerMarkdown:d,clientContext:f,baseCatalogParams:p,searchPlaceholder:m,searchButtonLabel:b,searchConfig:y,suggestionButtonConfig:_,progressStepsLimit:A=3,messageAlignment:v="start",autoScroll:w=!0,showProductDescription:N=!1,componentConfig:C,conversationHistory:H,resetConversationMessage:Y="",apiKey:D,apiToken:q,baseUrl:ne,customerId:de,tenantId:V,theme:se,isDevelopment:pe,__features:ve,routingAttributes:re,enableDownloadTranscript:ae=!0,enableEscalationToAgent:xe=!1,showProductCaptions:oe=!1,staticQuestions:Q,staticQuestionsStrategy:ie="append",children:k})=>{const R=e==="messaging",ee=B.useMemo(()=>{const Ye=re==null?void 0:re.isCartMgmtSupported;return Ye===!0||Ye==="true"},[re]),O=B.useMemo(()=>R?{config:null}:new av(ne,D,q,pe,de,V),[R,ne,D,q,pe,de,V]),_e=B.useMemo(()=>new uv(pe),[pe]);B.useEffect(()=>{R||!O||O.config||O.getConfig()},[O,R]);const Ue=B.useMemo(()=>hA(se),[se]),ye=B.useMemo(()=>{const Ye=(y==null?void 0:y.placeholder)||m,ht=(y==null?void 0:y.buttonLabel)||b;let Vt="icon";return y!=null&&y.buttonType?Vt=y.buttonType:b&&(Vt="text"),fe(F({},y||{}),{placeholder:Ye,buttonLabel:ht,buttonType:Vt})},[y,m,b]),Le=B.useMemo(()=>fe(F({},r||{}),{logoUrl:t||(r==null?void 0:r.logoUrl),headerText:(r==null?void 0:r.headerText)||n||lv[e!=null?e:"copilot"]}),[r,t,n,e]),He=B.useMemo(()=>({configModule:O,mode:e!=null?e:"copilot",headerConfig:Le,entryMessage:a,staticQuestions:Q||[],staticQuestionsStrategy:ie,globalClassName:s,openLinksInNewTab:u,disclaimerText:c,disclaimerMarkdown:d,clientContext:f,baseCatalogParams:p,themeVariables:Ue,logger:_e,searchConfig:ye,suggestionButtonConfig:_,progressStepsLimit:A,messageAlignment:v,autoScroll:w,showProductDescription:!!N,enableMinimize:!!(C!=null&&C.enableMinimize),enableDownloadTranscript:ae,enableEscalationToAgent:xe,showProductCaptions:!!oe,resetConversationMessage:Y,conversationHistory:{sinceHours:typeof(H==null?void 0:H.sinceHours)=="number"?H.sinceHours:1,limit:H==null?void 0:H.limit},features:ve,isCartMgmtSupported:ee}),[O,e,Le,a,Q,ie,s,f,p,c,d,u,ye,_,v,w,N,C,ae,xe,A,oe,Y,_e,Ue,H,ve,ee]);return x.jsx(Ug.Provider,{value:He,children:k})},tt=()=>{const e=B.useContext(Ug);if(!e)throw new Error("useConfig must be used within a ConfigProvider");return e};class dv{constructor(){Se(this,"initialState",{connected:!1,mode:"embedded",entryType:"search",status:{type:"dialog",isOpen:!1,isMinimized:!1},dialog:{position:"bottom-left",isFullHeight:!1,width:""},modal:{isFullscreen:!1}});Se(this,"connectedProxy");Se(this,"modeProxy");Se(this,"entryTypeProxy");Se(this,"statusProxy");Se(this,"dialogProxy");Se(this,"modalProxy",{isFullscreen:!1});Se(this,"_fullGet",(t,n)=>Reflect.get(t,n));Se(this,"_fullSet",(t,n,r)=>{if(!(n in t))throw new Error(`Property ${n} does not exist on UIState`);return gv(n,r),Reflect.set(t,n,r)});this.connectedProxy=new Proxy({connected:this.initialState.connected},{get:this._fullGet,set:this._fullSet}),this.modeProxy=new Proxy({mode:this.initialState.mode},{get:this._fullGet,set:this._fullSet}),this.entryTypeProxy=new Proxy({entryType:this.initialState.entryType},{get:this._fullGet,set:this._fullSet}),this.statusProxy=new Proxy({type:this.initialState.status.type,isOpen:this.initialState.status.isOpen,isMinimized:this.initialState.status.isMinimized},{get:this._fullGet,set:this._fullSet}),this.dialogProxy=new Proxy({position:this.initialState.dialog.position,isFullHeight:this.initialState.dialog.isFullHeight,width:this.initialState.dialog.width},{get:this._fullGet,set:this._fullSet}),this.modalProxy=new Proxy({isFullscreen:this.initialState.modal.isFullscreen},{get:this._fullGet,set:this._fullSet})}get connected(){return this.connectedProxy.connected}get mode(){return this.modeProxy.mode}get isOpen(){return!!this.statusProxy.isOpen}get isMinimized(){return!!this.statusProxy.isMinimized}get type(){return this.statusProxy.type}get entryType(){return this.entryTypeProxy.entryType}get position(){return this.dialogProxy.position}get state(){return{connected:this.connected,mode:this.mode,entryType:this.entryType,status:{type:this.type,isOpen:this.isOpen,isMinimized:this.isMinimized},dialog:{position:this.position,isFullHeight:this.dialogProxy.isFullHeight,width:this.dialogProxy.width},modal:{isFullscreen:this.modalProxy.isFullscreen}}}}const Je=new dv,is=()=>Je.connected,ha=()=>Je.isOpen,yf="cimulate.widget.minimizedOnNav";function fv(){try{const e=sessionStorage.getItem(yf)==="1";return sessionStorage.removeItem(yf),e}catch(e){return!1}}function hv(){try{sessionStorage.removeItem(yf)}catch(e){return}}const pv=e=>{window.addEventListener(Zd,e)},mv=e=>{window.removeEventListener(Zd,e)},gv=(e,t)=>{const n=new CustomEvent(Zd,{detail:{property:e,value:t}});window.dispatchEvent(n)},Ev=e=>{Je.connectedProxy.connected=e},pa=e=>{if(!uA(e)){const t=W0.map(r=>`'${r}'`),n=`${t.slice(0,-1).join(", ")}, or ${t[t.length-1]}`;throw new Error(`Invalid entryType: "${e}". Must be ${n}.`)}Je.entryTypeProxy.entryType=e},ti=e=>{const t=Je.statusProxy.isOpen,n=typeof e=="boolean"?e:!t;Je.statusProxy.isOpen=n,n&&(Je.statusProxy.isMinimized=!1,hv())},ma=e=>{const t=Je.statusProxy.isMinimized,n=typeof e=="boolean"?e:!t;Je.statusProxy.isMinimized=n,n&&(Je.statusProxy.isOpen=!1)},Tf=e=>{Je.modalProxy.isFullscreen=e},dl=e=>{if(!["chat","dialog","modal"].includes(e))throw new Error(`Invalid type: ${e}. Must be 'chat', 'dialog', or 'modal'.`);Je.statusProxy.type=e,e==="dialog"||e==="chat"?Je.modeProxy.mode="embedded":Je.modeProxy.mode="standalone"},bf=e=>{const t=["top","top-left","top-right","bottom","bottom-left","bottom-right","left","right","center"];if(!t.includes(e))throw new Error(`Invalid position: ${e}. Must be one of ${t.join(", ")}.`);Je.dialogProxy.position=e},yv=e=>{const t=Je.dialogProxy.isFullHeight,n=typeof e=="boolean"?e:!t;Je.dialogProxy.isFullHeight=n},Tv=({onCopilotEvent:e,children:t,dispatch:n})=>{const{logger:r}=tt(),s=B.useCallback(C=>{n({type:mt.SET_COPILOT,payload:C})},[n]),a=B.useCallback(C=>{Ev(C),n({type:mt.SET_CONNECTED,payload:C})},[n]),u=B.useCallback(()=>{n({type:mt.RESET_COPILOT,payload:{}})},[n]),c=B.useCallback(()=>{n({type:mt.RESET_STATE,payload:{}})},[n]),d=B.useCallback(C=>{r==null||r.log(`${C.name} event received`,C),n({type:mt.ADD_MESSAGE,payload:C}),C.bypassHandlers||e==null||e(C)},[e,r,n]),f=B.useCallback(C=>{n({type:mt.ADD_LOADING_MESSAGE,payload:C})},[n]),p=B.useCallback(C=>{n({type:mt.REMOVE_LOADING_MESSAGE,payload:C})},[n]),m=B.useCallback(C=>{d(C),f(C.id)},[d,f]),b=B.useCallback(C=>{n({type:mt.SET_ACTIVE_CONVERSATION_ID,payload:C})},[n]),y=B.useCallback(C=>{n({type:mt.ADD_CONVERSATION_ID,payload:C})},[n]),_=B.useCallback(C=>{n({type:mt.SET_CONVERSATION_IDS,payload:C})},[n]),A=B.useCallback(C=>{n({type:mt.SET_IMAGE_FILE,payload:C})},[n]),v=B.useCallback(C=>{n({type:mt.SET_ASK_CIM_PROMPTS,payload:C})},[n]),w=B.useCallback(C=>{n({type:mt.SET_CONVERSATION_HISTORY_LOADED,payload:C})},[n]),N=B.useMemo(()=>({setCopilot:s,setConnected:a,resetCopilot:u,resetCopilotState:c,addCopilotEvent:d,addLoadingMessage:f,removeLoadingMessage:p,handleCopilotRequestAck:m,setActiveConversationId:b,addConversationId:y,setConversationIds:_,setImageFile:A,setAskCimPrompts:v,setConversationHistoryLoaded:w}),[s,a,u,c,d,f,p,m,b,y,_,A,v,w]);return x.jsx(Q0.Provider,{value:N,children:t})};sA();const bv=(e,t)=>{const{type:n,payload:r}=t;if(n===mt.ADD_MESSAGE){const s=r;if(e.messages.push(s),s.eventSourceId){const a=e.groupedMessages.findIndex(u=>u.eventSourceId===s.eventSourceId);if(a!==-1){let u=e.groupedMessages[a].messages;u||(u=[]);const c=u.findIndex(d=>d.id===s.id);if(c!==-1){u[c]=s;return}u.push(s);return}else{e.groupedMessages.push({type:"group",eventSourceId:s.eventSourceId,messages:[s],createdAt:new Date(s.createdAt)});return}}e.groupedMessages.push({type:"individual",message:s,createdAt:new Date(s.createdAt)});return}switch(n){case mt.RESET_STATE:e.messages=Zi.messages,e.groupedMessages=Zi.groupedMessages,e.loadingMessages=Zi.loadingMessages,e.imageFile=Zi.imageFile,e.askCimPrompts=Zi.askCimPrompts,e.conversationHistoryLoaded=Zi.conversationHistoryLoaded;break;case mt.RESET_COPILOT:e.copilot=null;break;case mt.SET_COPILOT:e.copilot=r;break;case mt.SET_CONNECTED:e.connected=r;break;case mt.ADD_LOADING_MESSAGE:e.loadingMessages.add(r);break;case mt.REMOVE_LOADING_MESSAGE:e.loadingMessages.delete(r);break;case mt.SET_ACTIVE_CONVERSATION_ID:e.activeConversationId=r;break;case mt.ADD_CONVERSATION_ID:{const s=r;e.conversationIds.includes(s)||e.conversationIds.push(s)}break;case mt.SET_CONVERSATION_IDS:e.conversationIds=r;break;case mt.SET_IMAGE_FILE:e.imageFile=r;break;case mt.SET_ASK_CIM_PROMPTS:e.askCimPrompts.requestId=(r==null?void 0:r.requestId)||null,e.askCimPrompts.message=(r==null?void 0:r.message)||null;break;case mt.SET_CONVERSATION_HISTORY_LOADED:e.conversationHistoryLoaded=r;break}},_v=({onCopilotEvent:e,children:t})=>{const[n,r]=Y0(bv,Zi);return x.jsx(K0.Provider,{value:n,children:x.jsx(Tv,{onCopilotEvent:e,dispatch:r,children:t})})};function Sv(){var e=B.useRef(!0);return e.current?(e.current=!1,!0):e.current}function xv(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];e&&e.addEventListener&&e.addEventListener.apply(e,t)}function wv(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];e&&e.removeEventListener&&e.removeEventListener.apply(e,t)}var _f=typeof window!="undefined",ga=function(e){B.useEffect(e,[])},Av=function(e){var t=B.useRef(e);t.current=e,ga(function(){return function(){return t.current()}})},Cv=function(e){var t=B.useRef(0),n=B.useState(e),r=n[0],s=n[1],a=B.useCallback(function(u){cancelAnimationFrame(t.current),t.current=requestAnimationFrame(function(){s(u)})},[]);return Av(function(){cancelAnimationFrame(t.current)}),[r,a]},vv=function(e,t){return e===t};function kv(e,t){t===void 0&&(t=vv);var n=B.useRef(),r=B.useRef(e),s=Sv();return!s&&!t(r.current,e)&&(n.current=r.current,r.current=e),n.current}var Nv=function(e){var t={},n=t.initialWidth,r=n===void 0?1/0:n,s=t.initialHeight,a=s===void 0?1/0:s,u=t.onChange,c=Cv({width:_f?window.innerWidth:r,height:_f?window.innerHeight:a}),d=c[0],f=c[1];return B.useEffect(function(){if(_f){var p=function(){var m=window.innerWidth,b=window.innerHeight;f({width:m,height:b}),u&&u(m,b)};return xv(window,"resize",p),function(){wv(window,"resize",p)}}},[]),d};class Pv{constructor(){Se(this,"items",[]);Se(this,"add",t=>{const n=this.first();n&&n.context===t.context&&this.remove(),this.items.push(t)});Se(this,"remove",()=>this.items.shift());Se(this,"first",()=>this.items.length>0?this.items[0]:null);Se(this,"clear",()=>{this.items.length=0});Se(this,"processQueue",t=>{new Array(mn.size).fill(1).forEach(()=>{const r=mn.first();r&&(t(r),mn.remove())})})}get size(){return this.items.length}}const mn=new Pv,Hg=e=>{window.addEventListener(Jd,e)},zg=e=>{window.removeEventListener(Jd,e)},Ov=(e,t,n)=>{const r=new CustomEvent(Jd,{detail:{event:e,property:t,value:n}});window.dispatchEvent(r)},jg=e=>{window.addEventListener(Qd,e)},$g=e=>{window.removeEventListener(Qd,e)},Iv=(e,t,n)=>{const r=new CustomEvent(Qd,{detail:{event:e,property:t,value:n}});window.dispatchEvent(r)},Vg=e=>{window.addEventListener(Kd,e)},qg=e=>{window.removeEventListener(Kd,e)},Yg=(e,t,n)=>{const r=new CustomEvent(Kd,{detail:{property:e,value:t,event:n}});window.dispatchEvent(r)},Rv=e=>{window.addEventListener(tf,e)},Lv=e=>{window.removeEventListener(tf,e)},fl=(e,t,n)=>{const r=new CustomEvent(tf,{detail:{property:e,value:t,event:n}});window.dispatchEvent(r)};class Dv{constructor(){Se(this,"initialParams",{categoryId:"",categoryName:"",page:null,pageSize:null,includeFacets:!0,facetFilters:{},rangeFilters:[],catalogSegment:null,pricebooks:null});Se(this,"categoryIdProxy");Se(this,"facetFiltersProxy");Se(this,"rangeFiltersProxy");Se(this,"catalogSegmentProxy");Se(this,"pricebooksProxy");Se(this,"_fullGet",(t,n)=>Reflect.get(t,n));Se(this,"_fullSet",(t,n,r)=>{const s=dA[n];return Iv(s,n,r),Reflect.set(t,n,r)});Se(this,"updateFacetFiltersProxy",t=>new Proxy({facetFilters:t},{get:this._fullGet,set:this._fullSet}));Se(this,"updateRangeFiltersProxy",t=>new Proxy({rangeFilters:t},{get:this._fullGet,set:this._fullSet}));Se(this,"updatePricebooksProxy",t=>new Proxy({pricebooks:t},{get:this._fullGet,set:this._fullSet}));this.categoryIdProxy=new Proxy({categoryId:this.initialParams.categoryId,categoryName:this.initialParams.categoryName},{get:this._fullGet,set:this._fullSet}),this.facetFiltersProxy=this.updateFacetFiltersProxy(this.initialParams.facetFilters||{}),this.rangeFiltersProxy=this.updateRangeFiltersProxy(this.initialParams.rangeFilters||[]),this.catalogSegmentProxy=new Proxy({catalogSegment:this.initialParams.catalogSegment},{get:this._fullGet,set:this._fullSet}),this.pricebooksProxy=this.updatePricebooksProxy(this.initialParams.pricebooks||null)}get categoryId(){return this.categoryIdProxy.categoryId||""}get facetFilters(){return this.facetFiltersProxy.facetFilters||{}}get rangeFilters(){return this.rangeFiltersProxy.rangeFilters||[]}get catalogSegment(){return this.catalogSegmentProxy.catalogSegment||null}get pricebooks(){return this.pricebooksProxy.pricebooks||null}get state(){return{categoryId:this.categoryId,categoryName:this.categoryIdProxy.categoryName,facetFilters:this.facetFilters,rangeFilters:this.rangeFilters,catalogSegment:this.catalogSegment,pricebooks:this.pricebooks,page:this.initialParams.page,pageSize:this.initialParams.pageSize,includeFacets:this.initialParams.includeFacets}}}const at=new Dv,Gg=(e,t)=>{const n=t.updateFacetFiltersProxy(e);t.facetFiltersProxy.facetFilters=n.facetFilters},Wg=(e,t,n)=>{var u,c;const r=F({},((u=n.facetFiltersProxy)==null?void 0:u.facetFilters)||{});if(!!((c=r[e])!=null&&c.includes(t))){const d=r[e].filter(f=>f!==t);d.length>0?r[e]=d:delete r[e]}else r[e]=r[e]?[...r[e],t]:[t];const a=n.updateFacetFiltersProxy(r);n.facetFiltersProxy.facetFilters=a.facetFilters},Xg=(e,t)=>{const n=t.updateRangeFiltersProxy(e);t.rangeFiltersProxy.rangeFilters=n.rangeFilters},Kg=({field:e,value:t},n)=>{const[r,s]=Array.isArray(t)?t:[];if(typeof r=="undefined"||typeof s=="undefined")throw new Error("Range values must be an array with two numbers for min and max");const a=[...n.rangeFiltersProxy.rangeFilters||[]],u=a.findIndex(d=>d.field===e);if(u!==-1){a[u]={field:e,min:r,max:s},n.rangeFiltersProxy.rangeFilters=a;return}a.push({field:e,min:r,max:s});const c=n.updateRangeFiltersProxy(a);n.rangeFiltersProxy.rangeFilters=c.rangeFilters},Qg=(e,t)=>{t.catalogSegmentProxy.catalogSegment=e},Jg=(e,t)=>{const n=t.updatePricebooksProxy(e);t.pricebooksProxy.pricebooks=n.pricebooks},Mv=e=>{if(!is()||!ha()){is()&&mn.clear(),mn.add({context:"browse",payload:fe(F({},at.state),{categoryId:e})});return}at.categoryIdProxy.categoryId=e},Zg=e=>{Gg(e,at)},Fv=(e,t)=>{Wg(e,t,at)},e1=e=>{Xg(e,at)},Bv=({field:e,value:t})=>{Kg({field:e,value:t},at)},Uv=e=>{Qg(e,at)},t1=e=>{Jg(e,at)},n1=e=>{if(!e||!("categoryId"in e))throw new Error("Browse context must include a categoryId");const t=is(),n=ha();if(!t||!n){t&&mn.clear(),mn.add({context:"browse",payload:F({},e)});return}"facetFilters"in e&&Zg(e.facetFilters||{}),"rangeFilters"in e&&e1(e.rangeFilters||[]),"catalogSegment"in e&&(at.catalogSegmentProxy.catalogSegment=e.catalogSegment||null),"pricebooks"in e&&t1(e.pricebooks||[]),"categoryName"in e&&(at.categoryIdProxy.categoryName=e.categoryName||""),at.categoryIdProxy.categoryId=e.categoryId},Hv=Object.freeze(Object.defineProperty({__proto__:null,setBrowseContext:n1,updateBrowseCategoryId:Mv,updateCatalogSegment:Uv,updateFacetFilter:Fv,updateFacetFilters:Zg,updatePricebooks:t1,updateRangeFilter:Bv,updateRangeFilters:e1},Symbol.toStringTag,{value:"Module"}));class zv{constructor(){Se(this,"initialParams",{productId:"",productName:"",pdpLink:""});Se(this,"proxy");Se(this,"_fullGet",(t,n)=>Reflect.get(t,n));Se(this,"_fullSet",(t,n,r)=>(Yg(n,r),Reflect.set(t,n,r)));Se(this,"updateProxy",t=>{t.productId&&(this.proxy=new Proxy({productId:t.productId,productName:t.productName||"",pdpLink:t.pdpLink||""},{get:this._fullGet,set:this._fullSet}))});this.proxy=new Proxy({productId:this.initialParams.productId,productName:this.initialParams.productName,pdpLink:this.initialParams.pdpLink},{get:this._fullGet,set:this._fullSet})}get productId(){return this.proxy.productId}get pdpLink(){return this.proxy.pdpLink}get state(){return{productId:this.productId,productName:this.proxy.productName,pdpLink:this.pdpLink}}}const mr=new zv,r1=e=>{if(!e||!e.productId)throw new Error("PDP context must include a productId");const t=is(),n=ha();if(!t||!n){t&&mn.clear(),mn.add({context:"pdp",payload:F({},e)});return}mr.updateProxy(e),Yg("pdp-context",e)},jv=e=>{mr.proxy.productId=e,is()||mn.add({context:"pdp",payload:F({},mr.state)})},$v=e=>{mr.proxy.pdpLink=e};class Vv{constructor(){Se(this,"initialState",J0);Se(this,"promptsStateProxy");Se(this,"promptsParamsProxy");Se(this,"_fullGet",(t,n)=>Reflect.get(t,n));Se(this,"_fullSet",(t,n,r)=>{if(!(n in t))throw new Error(`Property ${n} does not exist on PromptsExtensionState`);return Ea(n,r),Reflect.set(t,n,r)});Se(this,"_paramsFullGet",(t,n)=>Reflect.get(t,n));Se(this,"_paramsFullSet",(t,n,r)=>Reflect.set(t,n,r));Se(this,"updatePromptsParamsProxy",t=>new Proxy(F({},t),{get:this._paramsFullGet,set:this._paramsFullSet}));this.promptsStateProxy=new Proxy({isOpen:this.initialState.isOpen,isInline:this.initialState.isInline,elementId:this.initialState.elementId,entryType:this.initialState.entryType},{get:this._fullGet,set:this._fullSet}),this.promptsParamsProxy=this.updatePromptsParamsProxy({})}get isOpen(){return this.promptsStateProxy.isOpen}get isInline(){return this.promptsStateProxy.isInline}get state(){return{isOpen:this.isOpen,isInline:this.isInline}}get params(){return this.promptsParamsProxy}}const Bt=new Vv,qv=e=>{window.addEventListener(ef,e)},Yv=e=>{window.removeEventListener(ef,e)},Ea=(e,t)=>{const n=new CustomEvent(ef,{detail:{property:e,value:t}});window.dispatchEvent(n)},i1=e=>{const t=Bt.isOpen,n=typeof e=="boolean"?e:!t;Bt.promptsStateProxy.isOpen=n},s1=e=>{const t=Bt.isInline,n=typeof e=="boolean"?e:!t;Bt.promptsStateProxy.isInline=n},Gv=e=>{Bt.promptsParamsProxy=Bt.updatePromptsParamsProxy(e),Ea("params",e),Bt.promptsStateProxy.entryType="ask_cim"},Wv=e=>{Bt.promptsParamsProxy=Bt.updatePromptsParamsProxy(e),Ea("params",e),Bt.promptsStateProxy.entryType="search"},Xv=e=>{Bt.promptsParamsProxy=Bt.updatePromptsParamsProxy(e),Ea("params",e),Bt.promptsStateProxy.entryType="browse"},Kv=e=>{Bt.promptsParamsProxy=Bt.updatePromptsParamsProxy(e),Ea("params",e),Bt.promptsStateProxy.entryType="pdp"},Qv=({elementId:e,entryType:t,params:n,isInline:r})=>{Bt.promptsStateProxy.elementId=e,t&&(Bt.promptsStateProxy.entryType=t),typeof r=="boolean"&&s1(r),n&&Bt.updatePromptsParamsProxy(n),Bt.isOpen||i1(!0)},Jv=Object.freeze(Object.defineProperty({__proto__:null,getConversationMessages:({payload:e,callback:t})=>{fl("getConversationMessages",{payload:e,callback:t},bi.GET_CONVERSATION_MESSAGES)},getSessionInformation:e=>{fl("getSessionInformation",{callback:e},bi.GET_SESSION_INFORMATION)},loadConversation:e=>{fl("loadConversation",e,bi.LOAD_CONVERSATION)},resetConversation:()=>{fl("resetConversation",!0,bi.RESET_CONVERSATION)}},Symbol.toStringTag,{value:"Module"}));class Zv{constructor(){Se(this,"initialParams",{query:"",page:null,pageSize:null,includeFacets:!0,facetFilters:{},rangeFilters:[],catalogSegment:null,pricebooks:null});Se(this,"queryProxy");Se(this,"facetFiltersProxy");Se(this,"rangeFiltersProxy");Se(this,"catalogSegmentProxy");Se(this,"pricebooksProxy");Se(this,"_fullGet",(t,n)=>Reflect.get(t,n));Se(this,"_fullSet",(t,n,r)=>{const s=fA[n];return Ov(s,n,r),Reflect.set(t,n,r)});Se(this,"updateFacetFiltersProxy",t=>new Proxy({facetFilters:t},{get:this._fullGet,set:this._fullSet}));Se(this,"updateRangeFiltersProxy",t=>new Proxy({rangeFilters:t},{get:this._fullGet,set:this._fullSet}));Se(this,"updatePricebooksProxy",t=>new Proxy({pricebooks:t},{get:this._fullGet,set:this._fullSet}));this.queryProxy=new Proxy({query:this.initialParams.query},{get:this._fullGet,set:this._fullSet}),this.facetFiltersProxy=this.updateFacetFiltersProxy(this.initialParams.facetFilters||{}),this.rangeFiltersProxy=this.updateRangeFiltersProxy(this.initialParams.rangeFilters||[]),this.catalogSegmentProxy=new Proxy({catalogSegment:this.initialParams.catalogSegment},{get:this._fullGet,set:this._fullSet}),this.pricebooksProxy=this.updatePricebooksProxy(this.initialParams.pricebooks||null)}get query(){return this.queryProxy.query||""}get facetFilters(){return this.facetFiltersProxy.facetFilters||{}}get rangeFilters(){return this.rangeFiltersProxy.rangeFilters||[]}get catalogSegment(){return this.catalogSegmentProxy.catalogSegment||null}get pricebooks(){return this.pricebooksProxy.pricebooks||null}get state(){return{query:this.query,facetFilters:this.facetFilters,rangeFilters:this.rangeFilters,catalogSegment:this.catalogSegment,pricebooks:this.pricebooks,page:this.initialParams.page,pageSize:this.initialParams.pageSize,includeFacets:this.initialParams.includeFacets}}}const bt=new Zv,ek=e=>{const t=ha(),n=is();if(!n||!t){n&&mn.clear(),mn.add({context:"search",payload:fe(F({},bt.state),{query:e})});return}bt.queryProxy.query=e},o1=e=>{Gg(e,bt)},tk=(e,t)=>{Wg(e,t,bt)},a1=e=>{Xg(e,bt)},nk=({field:e,value:t})=>{Kg({field:e,value:t},bt)},rk=e=>{Qg(e,bt)},u1=e=>{Jg(e,bt)},l1=e=>{if(!e||!e.query)throw new Error("Search context must include a query");const t=ha(),n=is();if(!n||!t){n&&mn.clear(),mn.add({context:"search",payload:F({},e)});return}"facetFilters"in e&&o1(e.facetFilters||{}),"rangeFilters"in e&&a1(e.rangeFilters||[]),"catalogSegment"in e&&(bt.catalogSegmentProxy.catalogSegment=e.catalogSegment||null),"pricebooks"in e&&u1(e.pricebooks||[]),bt.queryProxy.query=e.query},ik=Object.freeze(Object.defineProperty({__proto__:null,setSearchContext:l1,updateCatalogSegment:rk,updateFacetFilter:tk,updateFacetFilters:o1,updatePricebooks:u1,updateRangeFilter:nk,updateRangeFilters:a1,updateSearchQuery:ek},Symbol.toStringTag,{value:"Module"})),sk={categoryId:at.categoryId,categoryName:at.categoryIdProxy.categoryName||"",facetFilters:at.facetFilters,rangeFilters:at.rangeFilters,catalogSegment:at.catalogSegment,pricebooks:at.pricebooks},c1=B.createContext(sk),ok=({children:e})=>{const[t,n]=B.useState(at.categoryId),[r,s]=B.useState(at.categoryIdProxy.categoryName||""),[a,u]=B.useState(at.facetFilters||{}),[c,d]=B.useState(at.rangeFilters||[]),[f,p]=B.useState(at.catalogSegment||null),[m,b]=B.useState(at.pricebooks||null);B.useEffect(()=>{const _=({detail:A})=>{(A==null?void 0:A.property)==="categoryId"&&n(A.value),(A==null?void 0:A.property)==="categoryName"&&s(A.value),(A==null?void 0:A.property)==="facetFilters"&&u(A.value),(A==null?void 0:A.property)==="rangeFilters"&&d(A.value),(A==null?void 0:A.property)==="catalogSegment"&&p(A.value),(A==null?void 0:A.property)==="pricebooks"&&b(A.value)};return jg(_),()=>{$g(_)}},[]);const y=B.useMemo(()=>({categoryId:t,categoryName:r,facetFilters:a,rangeFilters:c,catalogSegment:f,pricebooks:m}),[t,r,a,c,f,m]);return x.jsx(c1.Provider,{value:y,children:e})},ak=()=>{const e=B.useContext(c1);if(!e)throw new Error("useBrowse must be used within a BrowseProvider");return e},uk={searchQuery:bt.query,facetFilters:bt.facetFilters,rangeFilters:bt.rangeFilters,catalogSegment:bt.catalogSegment,pricebooks:bt.pricebooks},d1=B.createContext(uk),lk=({children:e})=>{const[t,n]=B.useState(bt.query),[r,s]=B.useState(bt.facetFilters),[a,u]=B.useState(bt.rangeFilters),[c,d]=B.useState(bt.catalogSegment),[f,p]=B.useState(bt.pricebooks);B.useEffect(()=>{const b=({detail:y})=>{(y==null?void 0:y.property)==="query"&&n(y.value),(y==null?void 0:y.property)==="facetFilters"&&s(y.value),(y==null?void 0:y.property)==="rangeFilters"&&u(y.value),(y==null?void 0:y.property)==="catalogSegment"&&d(y.value),(y==null?void 0:y.property)==="pricebooks"&&p(y.value)};return Hg(b),()=>{zg(b)}},[]);const m=B.useMemo(()=>({searchQuery:t,facetFilters:r,rangeFilters:a,catalogSegment:c,pricebooks:f}),[t,r,a,c,f]);return x.jsx(d1.Provider,{value:m,children:e})},ck=()=>{const e=B.useContext(d1);if(!e)throw new Error("useSearch must be used within a SearchProvider");return e},dk={productId:mr.productId,pdpLink:mr.pdpLink},f1=B.createContext(dk),fk=({children:e})=>{const[t,n]=B.useState(mr.productId),[r,s]=B.useState(mr.pdpLink);B.useEffect(()=>{const u=({detail:c})=>{if((c==null?void 0:c.property)==="pdp-context"){const d=c.value;n(d.productId),s(d.pdpLink);return}(c==null?void 0:c.property)==="productId"&&n(c.value),(c==null?void 0:c.property)==="pdpLink"&&s(c.value)};return Vg(u),()=>{qg(u)}},[]);const a=B.useMemo(()=>({productId:t,pdpLink:r}),[t,r]);return x.jsx(f1.Provider,{value:a,children:e})},hk=()=>{const e=B.useContext(f1);if(!e)throw new Error("usePdp must be used within a PdpProvider");return e},h1=B.createContext({mode:Je.modeProxy.mode,entryType:Je.entryType,status:Je.statusProxy,dialogPosition:Je.dialogProxy.position,isDialogFullHeight:Je.dialogProxy.isFullHeight,dialogWidth:Je.dialogProxy.width,isModalFullscreen:Je.modalProxy.isFullscreen,previousComponentType:Je.statusProxy.type}),pk=({entryType:e,componentConfig:t,componentType:n,children:r})=>{const[s,a]=B.useState(e!=null?e:Je.entryTypeProxy.entryType),[u,c]=B.useState(Je.modeProxy.mode),[d,f]=B.useState({type:n||Je.statusProxy.type,isOpen:t&&"isOpen"in t?!!t.isOpen:Je.statusProxy.isOpen,isMinimized:t&&"isMinimized"in t?!!t.isMinimized:Je.statusProxy.isMinimized}),[p,m]=B.useState(Je.dialogProxy.position),[b,y]=B.useState(Je.dialogProxy.isFullHeight),[_,A]=B.useState(Je.dialogProxy.width),[v,w]=B.useState(Je.modalProxy.isFullscreen),N=B.useRef(!1),C=kv(d.type);B.useEffect(()=>{const Y=D=>{const{property:q,value:ne}=D.detail||{};if(!(!q||ne===void 0)){if(q==="mode"){c(ne);return}if(q==="entryType"){a(ne);return}if(q==="isMinimized"){f(de=>fe(F({},de),{isMinimized:ne}));return}if(q==="isOpen"){f(de=>fe(F({},de),{isOpen:ne}));return}if(q==="type"){f(de=>fe(F({},de),{type:ne}));return}if(q==="position"){m(ne);return}if(q==="isFullHeight"){y(ne);return}if(q==="width"){A(ne);return}if(q==="isFullscreen"){w(ne);return}}};return pv(Y),()=>{mv(Y)}},[]),ga(()=>{e&&pa(e)}),ga(()=>{if(N.current)return;N.current=!0;const Y=n||(t==null?void 0:t.type);Y&&dl(Y);const D=fv();t&&"isOpen"in t&&ti(!!t.isOpen),t&&"isMinimized"in t&&ma(!!t.isMinimized),D&&ma(!0)}),ga(()=>{if(!(t!=null&&t.options))return;const{dialogPosition:Y}=t.options;Y&&bf(Y),"dialogFullHeight"in t.options&&yv(!!t.options.dialogFullHeight),"dialogWidth"in t.options&&t.options.dialogWidth&&A(t.options.dialogWidth),"isModalFullscreen"in t.options&&Tf(!!t.options.isModalFullscreen)});const H=B.useMemo(()=>({mode:u,entryType:s,status:d,previousComponentType:C||"dialog",dialogPosition:p,isDialogFullHeight:b,dialogWidth:_,isModalFullscreen:v}),[u,s,d,C,p,b,_,v]);return x.jsx(h1.Provider,{value:H,children:r})},er=()=>{const e=B.useContext(h1);if(!e)throw new Error("useUIState must be used within a UIStateProvider");return e},p1=B.createContext(null),m1=B.createContext(null),Sf=()=>{const e=B.useContext(m1);if(!e)throw new Error("usePromptsExtensionDispatch must be used within a PromptsExtensionProvider");return e||{}},ni=()=>{const e=B.useContext(p1);if(!e)throw new Error("usePromptsExtensionState must be used within a PromptsExtensionProvider");return e||{}},Xs=()=>{const e=B.useContext(Q0);if(!e)throw new Error("useCopilotDispatch must be used within a CopilotProvider");return e},tr=()=>{const e=B.useContext(K0);if(!e)throw new Error("useCopilotState must be used within a CopilotProvider");return e},mk=({copilot:e})=>{const{logger:t,conversationHistory:n}=tt(),{isInline:r}=ni(),{addCopilotEvent:s,setConversationHistoryLoaded:a}=Xs(),{activeConversationId:u}=tr(),c=B.useCallback(f=>{e&&e.requestSessionInformation(p=>{t==null||t.log("Retrieved session information: ",p),f==null||f(p)})},[e,t]),d=B.useCallback((f,p)=>{e&&f.conversationId&&e.getConversationEvents(f,m=>{t==null||t.log("Retrieved conversation messages: ",m),p==null||p(m)})},[e,t]);return B.useEffect(()=>{if(r||!u)return;if(n.sinceHours===0||(n==null?void 0:n.limit)===0){a(!0);return}const f=3600*1e3*n.sinceHours,p=new Date(Date.now()-f).toISOString(),m={conversationId:u,since:p,excludeEvents:["done","error","connection_error","refined_browse","refined_search","conversation_reset"]};typeof n.limit=="number"&&(m.limit=n.limit),d(m,b=>{const y=[];[...b.reverse()||[]].forEach(A=>{var w;const v=b.find(N=>N.id===A.eventSourceId);(w=v==null?void 0:v.name)!=null&&w.endsWith("_suggestions")||(A.bypassHandlers=!0,y.unshift(A))}),y.forEach(A=>{s(A)}),a(!0)})},[t,r,u,d,s,a,n]),{getSessionInformation:c,getConversationMessages:d}},g1=B.createContext({copilot:null,messages:[],groupedMessages:[],isLoading:!1,isResponseLoading:()=>!1,handleAskCim:()=>{},handleSearch:()=>{},handleBrowse:()=>{},handlePdp:()=>{},handleSuggestion:()=>{},handleUserInput:()=>{},handleCancel:()=>{},resetConversation:()=>{},getSessionInformation:()=>{},getConversationMessages:()=>{}}),gk=({apiKey:e,apiToken:t,baseUrl:n,customerId:r,tenantId:s,isDevelopment:a,onConnect:u,onRefinedSearch:c,onRefinedBrowse:d,children:f})=>{const{logger:p,clientContext:m,baseCatalogParams:b}=tt(),an=ck(),{searchQuery:y}=an,_=fn(an,["searchQuery"]),Fn=ak(),{categoryId:A}=Fn,v=fn(Fn,["categoryId"]),{productId:w,pdpLink:N}=hk(),{setCopilot:C,setConnected:H,resetCopilot:Y,resetCopilotState:D,addCopilotEvent:q,removeLoadingMessage:ne,handleCopilotRequestAck:de,setActiveConversationId:V,setConversationIds:se,setAskCimPrompts:pe}=Xs(),{connected:ve,copilot:re,messages:ae,groupedMessages:xe,loadingMessages:oe,askCimPrompts:Q}=tr(),{status:ie,entryType:k}=er(),{isInline:R}=ni(),{getConversationMessages:ee,getSessionInformation:O}=mk({copilot:re}),_e=B.useMemo(()=>oe.size>0,[oe]),Ue=B.useCallback(we=>oe.has(we),[oe]),ye=B.useCallback(({query:we,facetFilters:Pe,rangeFilters:Me,catalogSegment:rt,pricebooks:pt,userPrompt:J,imageFile:ge})=>{if(!re){p==null||p.error("Copilot is not initialized");return}if(!we)return;const Ce={searchParams:{query:we}};J&&(Ce.userPrompt=J),ge&&(Ce.attachments={image:ge}),Pe&&Object.keys(Pe).length>0&&(Ce.searchParams.facetFilters=Pe),Me&&Me.length>0&&(Ce.searchParams.rangeFilters=Me),rt&&(Ce.searchParams.catalogSegment=rt),pt&&(Ce.searchParams.pricebooks=pt),m&&(Ce.clientContext=m),pa("search"),re.search(Ce,qe=>{const Ie=F({},qe);de(Ie)})},[p,de,re,m]),Le=B.useCallback(({categoryId:we,categoryName:Pe,facetFilters:Me,rangeFilters:rt,catalogSegment:pt,pricebooks:J,userPrompt:ge,imageFile:Ce})=>{if(!re){p==null||p.error("Copilot is not initialized");return}const qe=Me&&Object.keys(Me).length>0;if(we===""&&!qe){p==null||p.error("Browse event must include facetFilters when categoryId is empty");return}const Ie={browseParams:{categoryId:we||""}};ge&&(Ie.userPrompt=ge),Ce&&(Ie.attachments={image:Ce}),qe&&(Ie.browseParams.facetFilters=Me),rt&&rt.length>0&&(Ie.browseParams.rangeFilters=rt),pt&&(Ie.browseParams.catalogSegment=pt),Array.isArray(J)&&J.length>0&&(Ie.browseParams.pricebooks=J),(m||Pe)&&(Ie.clientContext={},m&&(Ie.clientContext=F({},m)),Pe&&(Ie.clientContext.cimLabel=Pe)),pa("browse"),re.browse(Ie,ut=>{var Vr;const qt=F({},ut),Ht=((Vr=qt.request)==null?void 0:Vr.clientContext)||{},un=(Ht==null?void 0:Ht.cimLabel)||Pe;un&&qt.request&&(qt.request.label=un),de(qt)})},[p,de,re,m]),He=B.useCallback(({productId:we,productName:Pe,pdpLink:Me,userPrompt:rt,imageFile:pt})=>{if(!re){p==null||p.error("Copilot is not initialized");return}if(!we)return;const J={productId:we};rt&&(J.userPrompt=rt),Me&&(J.pdpLink=Me),pt&&(J.attachments={image:pt}),(m||Pe)&&(J.clientContext={},m&&(J.clientContext=F({},m)),Pe&&(J.clientContext.cimLabel=Pe)),b&&(J.baseCatalogParams=b),pa("pdp"),re.productView(J,ge=>{var ut;const Ce=F({},ge),qe=((ut=Ce.request)==null?void 0:ut.clientContext)||{},Ie=(qe==null?void 0:qe.cimLabel)||Pe;Ie&&Ce.request&&(Ce.request.label=Ie),de(Ce)})},[p,re,de,m,b]),Ye=B.useCallback(({userPrompt:we,imageFile:Pe})=>{if(!re){p==null||p.error("Copilot is not initialized");return}if(!we)return;const Me={userPrompt:we};Pe&&(Me.attachments={image:Pe}),m&&(Me.clientContext=m),b&&(Me.baseCatalogParams=b),re.askCim(Me,rt=>{const pt=F({},rt);de(pt)})},[p,re,de,m,b]),ht=B.useCallback(we=>{q(we),c==null||c(we)},[q,c]),Vt=B.useCallback(we=>{q(we),d==null||d(we)},[q,d]),on=B.useCallback(we=>{u==null||u(we),H(!0)},[u,H]);B.useEffect(()=>{!re||!ve||!ie.isOpen||mn.size>0&&mn.processQueue(we=>{if(we.context==="search"){const Pe=F({},we.payload);l1(Pe)}if(we.context==="browse"){const Pe=F({},we.payload);n1(Pe)}if(we.context==="pdp"){const Pe=F({},we.payload);r1(Pe)}})},[ie.isOpen,re,ve]);const _r=B.useCallback(we=>{const Pe=Me=>{const rt=fe(F({},Me),{id:Me.inquiryLinkId||Me.id});q(rt)};we.on("connect_ack",on),we.on("partial_inquiry",Pe),we.on("display_products",q),we.on("progress",q),we.on("refined_search",ht),we.on("refined_browse",Vt),we.on("done",Me=>{ne(Me.eventSourceId)}),we.on("error",Me=>{q(Me),ne(Me.eventSourceId)}),we.onDisconnect(Me=>{const rt=["io server disconnect","transport error","server shutting down"];if(p==null||p.log("Connection disconnected with reason: ",Me),!rt.includes(Me)){H(!1);return}p==null||p.log("De-registering event listeners");const pt=new Date().toISOString();q({name:"error",message:"Connection was lost. Please try again.",createdAt:pt,id:`error-${pt}`,sessionId:"session"}),we.off()})},[p,H,ne,ht,Vt,q,on]);B.useEffect(()=>{if(!re)return;const we=Pe=>{if(!R){if(!Pe.message&&Pe.eventSourceId&&Pe.eventSourceId===Q.requestId){pe({requestId:Pe.eventSourceId,message:Pe});return}q(Pe)}};return re.on("follow_up",we),()=>{re.off("follow_up",we)}},[re,ae,Q.requestId,R,q,pe]),B.useEffect(()=>{if(!re)return;const we=Pe=>{if(R)return;const Me=fe(F({},Pe),{id:Pe.inquiryLinkId||Pe.id});q(Me)};return re.on("inquiry",we),()=>{re.off("inquiry",we)}},[re,R,q]),ga(()=>{let we;n?we=n:we=a?"https://staging.copilot.search.cimulate.ai":"https://prod.copilot.search.cimulate.ai";const Pe={baseUrl:we};e?Pe.apiKey=e:t&&(Pe.apiToken=t),r&&(Pe.customerId=r),s&&(Pe.tenantId=s);const Me=new Xw(Pe);return C(Me),_r(Me),Me.connect(),Me.requestSessionInformation(rt=>{p==null||p.log("Session Information: ",rt);const{activeConversationId:pt,conversationIds:J}=rt.data||{};pt&&V(pt),J!=null&&J.length&&se(J)}),()=>{Me.disconnect(),Me.off(),Y()}});const sr=B.useCallback(we=>{if(!re)return;const Pe={eventId:we,reason:"User cancelled the request"};re.cancelRequest(Pe,Me=>{q(Me),ne(we)})},[q,ne,re]),Zt=B.useCallback(()=>{re&&re.conversationReset({},we=>{D(),q(we),re.requestSessionInformation(Pe=>{p==null||p.log("Session Information: ",Pe);const{activeConversationId:Me,conversationIds:rt}=Pe.data||{};Me&&V(Me),rt!=null&&rt.length&&se(rt)})})},[re,p,q,D,V,se]),Ve=B.useCallback((we,Pe)=>{if(!we)return;const Me={userPrompt:we};switch(Pe&&(Me.imageFile=Pe),k){case"ask_cim":Ye(Me);return;case"search":y?ye(F(F({query:y},_),Me)):Ye(Me);return;case"browse":Le(F(F({categoryId:A},v),Me));return;case"pdp":w?He(F({productId:w,pdpLink:N||""},Me)):Ye(Me);return}},[k,y,_,ye,Ye,A,v,Le,He,w,N]),kt=B.useCallback((we,Pe)=>{var ge,Ce,qe;const rt=we.params.userPrompt||"";if(!rt)return;const pt=ae.find(Ie=>Ie.id===Pe);if(!pt)return;const J=pt.name.replace("_suggestions","");if(J==="ask_cim"){Ye({userPrompt:rt});return}if(J==="copilot_search"){const Ie=((ge=pt.request)==null?void 0:ge.searchParams)||{},qt=Ie.query===y;ye(fe(F({query:Ie.query||y},qt?_:{}),{userPrompt:rt}));return}if(J==="copilot_browse"){const Ie=pt.request,ut=Ie.browseParams||{},Ht=ut.categoryId===A,un=((Ce=Ie.clientContext)==null?void 0:Ce.cimLabel)||"";Le(fe(F({categoryId:ut.categoryId||A||""},Ht?v:{}),{categoryName:un,userPrompt:rt}));return}if(J==="product_view"){const Ie=pt.request||{},ut=Ie.productId,qt=ut===w,Ht=((qe=Ie.clientContext)==null?void 0:qe.cimLabel)||"";let un="";qt?un=N||"":un=Ie.pdpLink||"",He({productId:ut||w,pdpLink:un,productName:Ht,userPrompt:rt})}},[ae,y,_,ye,Ye,A,v,Le,He,w,N]),vn=B.useMemo(()=>({copilot:re,messages:ae,groupedMessages:xe,isLoading:_e,isResponseLoading:Ue,handleAskCim:Ye,handleSearch:ye,handleBrowse:Le,handlePdp:He,handleUserInput:Ve,handleSuggestion:kt,handleCancel:sr,resetConversation:Zt,getSessionInformation:O,getConversationMessages:ee}),[re,ae,xe,_e,Ue,Ye,ye,Le,He,Ve,kt,sr,Zt,O,ee]);return x.jsx(g1.Provider,{value:vn,children:f})},E1=()=>{const{copilot:e}=tr(),{addCopilotEvent:t}=Xs();return{getCopilotSuggestions:B.useCallback((r,s,a)=>{if(!e||!s||!r)return;const u=c=>{t(c),a(c)};switch(s){case"ask_cim":e.askCimSuggestions(r,u);break;case"search":e.searchSuggestions({searchParams:r},u);break;case"browse":e.browseSuggestions({browseParams:r},u);break;case"pdp":e.productViewSuggestions({productId:r.productId},u);break}},[e,t])}},Ir=()=>{const e=B.useContext(g1);if(!e)throw new Error("useCopilot must be used within a CopilotProvider");return e},Ek=()=>{const{copilot:e,activeConversationId:t,askCimPrompts:n,conversationHistoryLoaded:r}=tr(),{entryType:s}=er(),{resetCopilotState:a,addCopilotEvent:u,setAskCimPrompts:c}=Xs(),{handleSearch:d,handleBrowse:f,handlePdp:p,resetConversation:m,getSessionInformation:b,getConversationMessages:y}=Ir(),{getCopilotSuggestions:_}=E1();B.useEffect(()=>{!e||!s||!t||!r||n.requestId||s==="ask_cim"&&_({},s,N=>{c({requestId:N.id,message:null})})},[e,t,n.requestId,s,r,_,c]);const A=B.useCallback(({query:N})=>{if(!e||!N)return;const{facetFilters:C}=bt.facetFiltersProxy,{rangeFilters:H}=bt.rangeFiltersProxy,{catalogSegment:Y}=bt.catalogSegmentProxy,{pricebooks:D}=bt.pricebooksProxy,q={query:N};q.facetFilters=C||{},q.rangeFilters=H||[],q.catalogSegment=Y||"",q.pricebooks=D||[],d(F({},q))},[e,d]),v=B.useCallback(({categoryId:N})=>{if(!e)return;const C=at.categoryIdProxy.categoryName,{facetFilters:H}=at.facetFiltersProxy,{rangeFilters:Y}=at.rangeFiltersProxy,{catalogSegment:D}=at.catalogSegmentProxy,{pricebooks:q}=at.pricebooksProxy,ne={categoryId:N};ne.categoryName=C||"",ne.facetFilters=H||{},ne.rangeFilters=Y||[],ne.catalogSegment=D||"",ne.pricebooks=q||[],f(F({},ne))},[e,f]),w=B.useCallback(({productId:N})=>{if(!e||!N)return;const C={productId:N,pdpLink:mr.pdpLink,productName:mr.proxy.productName||""};p(C)},[e,p]);return B.useEffect(()=>{const N=({detail:C})=>{(C==null?void 0:C.property)==="query"&&A({query:C.value})};return Hg(N),()=>{zg(N)}},[A]),B.useEffect(()=>{const N=({detail:C})=>{if((C==null?void 0:C.property)==="pdp-context"){const H=C.value;w({productId:H.productId});return}(C==null?void 0:C.property)==="productId"&&w({productId:C.value})};return Vg(N),()=>{qg(N)}},[w]),B.useEffect(()=>{const N=({detail:C})=>{(C==null?void 0:C.property)==="categoryId"&&v({categoryId:C.value})};return jg(N),()=>{$g(N)}},[v]),B.useEffect(()=>{const N=({detail:C})=>{if((C==null?void 0:C.event)==bi.RESET_CONVERSATION&&m(),(C==null?void 0:C.event)==bi.GET_SESSION_INFORMATION){const H=C.value.callback;b(H)}if((C==null?void 0:C.event)==bi.GET_CONVERSATION_MESSAGES){const{payload:H,callback:Y}=C.value;if(!H.conversationId||typeof Y!="function")return;y(H,Y)}if((C==null?void 0:C.event)==bi.LOAD_CONVERSATION){const H=C.value;if(!H.conversationId)return;y(H,D=>{a(),D.forEach(q=>{u(q)})})}};return Rv(N),()=>{Lv(N)}},[m,b,y,a,u]),null},yk=({apiKey:e,apiToken:t,baseUrl:n,customerId:r,tenantId:s,isDevelopment:a,onConnect:u,onRefinedSearch:c,onRefinedBrowse:d,children:f})=>x.jsxs(gk,{apiKey:e,apiToken:t,baseUrl:n,customerId:r,tenantId:s,isDevelopment:a,onConnect:u,onRefinedSearch:c,onRefinedBrowse:d,children:[x.jsx(Ek,{}),f]}),Tk=({children:e,dispatch:t})=>{const n=B.useCallback(_=>{t({type:gt.SET_PROMPTS_EXTENSION_INITIALIZED,payload:_})},[t]),r=B.useCallback(_=>{t({type:gt.SET_PROMPTS_EXTENSION_OPEN,payload:_})},[t]),s=B.useCallback(_=>{t({type:gt.SET_PROMPTS_EXTENSION_INLINE,payload:_})},[t]),a=B.useCallback(_=>{t({type:gt.SET_PROMPTS_EXTENSION_ELEMENT_ID,payload:_})},[t]),u=B.useCallback(_=>{t({type:gt.SET_PROMPTS_EXTENSION_ENTRY_TYPE,payload:_})},[t]),c=B.useCallback(_=>{t({type:gt.SET_PROMPTS_EXTENSION_ACTIVE_PROMPTS_ID,payload:_})},[t]),d=B.useCallback(_=>{t({type:gt.SET_PROMPTS_EXTENSION_USER_PROMPT,payload:_})},[t]),f=B.useCallback(_=>{t({type:gt.SET_PROMPTS_EXTENSION_PARAMS,payload:_})},[t]),p=B.useCallback(_=>{t({type:gt.SET_PROMPTS_EXTENSION_PROMPTS_MESSAGE,payload:_})},[t]),m=B.useCallback(_=>{t({type:gt.SET_PROMPTS_EXTENSION_RESPONSE_MESSAGE,payload:_})},[t]),b=B.useCallback(_=>{t({type:gt.SET_PROMPTS_EXTENSION_RESPONSE_LOADING,payload:_})},[t]),y=B.useMemo(()=>({setIsInitialized:n,setIsOpen:r,setIsInline:s,setElementId:a,setEntryType:u,setActivePromptsId:c,setUserPrompt:d,setParams:f,setPromptsMessage:p,setResponseMessage:m,setIsResponseLoading:b}),[n,r,s,a,u,c,d,f,p,m,b]);return x.jsx(m1.Provider,{value:y,children:e})},bk=(e,t)=>{const{type:n,payload:r}=t;switch(n){case gt.SET_PROMPTS_EXTENSION_INITIALIZED:e.isInitialized=r;break;case gt.SET_PROMPTS_EXTENSION_OPEN:e.isOpen=r;break;case gt.SET_PROMPTS_EXTENSION_INLINE:e.isInline=r;break;case gt.SET_PROMPTS_EXTENSION_ELEMENT_ID:e.elementId=r;break;case gt.SET_PROMPTS_EXTENSION_ENTRY_TYPE:e.entryType=r;break;case gt.SET_PROMPTS_EXTENSION_PARAMS:e.params=r;break;case gt.RESET_PROMPTS_EXTENSION_PARAMS:e.params=null;break;case gt.SET_PROMPTS_EXTENSION_USER_PROMPT:e.userPrompt=r;break;case gt.SET_PROMPTS_EXTENSION_ACTIVE_PROMPTS_ID:e.activePromptsId=r;break;case gt.RESET_PROMPTS_EXTENSION_ACTIVE_PROMPTS_ID:e.activePromptsId=null;break;case gt.SET_PROMPTS_EXTENSION_PROMPTS_MESSAGE:e.promptsMessage=r;break;case gt.RESET_PROMPTS_EXTENSION_PROMPTS_MESSAGE:e.promptsMessage=null;break;case gt.SET_PROMPTS_EXTENSION_RESPONSE_MESSAGE:e.responseMessage=r;break;case gt.RESET_PROMPTS_EXTENSION_RESPONSE_MESSAGE:e.responseMessage=null;break;case gt.SET_PROMPTS_EXTENSION_RESPONSE_LOADING:e.isResponseLoading=r;break}},_k=({promptsConfig:e,children:t})=>{const[n,r]=Y0(bk,fe(F(F({},J0),e||{}),{staticQuestions:L0((e==null?void 0:e.staticQuestions)||[])}));return x.jsx(p1.Provider,{value:n,children:x.jsx(Tk,{dispatch:r,children:t})})},y1=({mode:e,apiKey:t,apiToken:n,baseUrl:r,customerId:s,tenantId:a,logoUrl:u,headerText:c,headerConfig:d,theme:f,openLinksInNewTab:p,globalClassName:m,isDevelopment:b=!1,componentType:y,componentConfig:_,entryType:A,initialEntry:v,entryMessage:w,disclaimerText:N,disclaimerMarkdown:C,clientContext:H,baseCatalogParams:Y,searchPlaceholder:D,searchButtonLabel:q,searchConfig:ne,suggestionButtonConfig:de,messageAlignment:V,autoScroll:se,promptsConfig:pe,resetConversationMessage:ve,conversationHistory:re,onConnect:ae,onCopilotEvent:xe,onRefinedSearch:oe,onRefinedBrowse:Q,__features:ie,children:k})=>{const R=v==null?void 0:v.params;return x.jsx(cv,{mode:e,baseUrl:r,apiKey:t,apiToken:n,customerId:s,tenantId:a,logoUrl:u,headerText:c,headerConfig:d,entryMessage:w,staticQuestions:L0(R==null?void 0:R.staticQuestions),staticQuestionsStrategy:R==null?void 0:R.staticQuestionsStrategy,theme:f,globalClassName:m,openLinksInNewTab:p,searchPlaceholder:D,searchButtonLabel:q,searchConfig:ne,suggestionButtonConfig:de,messageAlignment:V,autoScroll:se,componentConfig:_,clientContext:H,baseCatalogParams:Y,disclaimerMarkdown:C,disclaimerText:N,resetConversationMessage:ve,conversationHistory:re,isDevelopment:b,__features:ie,children:x.jsx(pk,{entryType:A!=null?A:v==null?void 0:v.type,componentConfig:_,componentType:y,children:x.jsx(_v,{onCopilotEvent:xe,children:x.jsx(fk,{children:x.jsx(ok,{children:x.jsx(lk,{children:x.jsx(_k,{promptsConfig:pe,children:x.jsx(yk,{apiKey:t,apiToken:n,baseUrl:r,customerId:s,tenantId:a,isDevelopment:b,entryType:A,onConnect:ae,onRefinedSearch:oe,onRefinedBrowse:Q,onCopilotEvent:xe,children:k})})})})})})})})};var xf={exports:{}},In={},wf={exports:{}},Af={};var T1;function Sk(){return T1||(T1=1,(function(e){function t(Q,ie){var k=Q.length;Q.push(ie);e:for(;0<k;){var R=k-1>>>1,ee=Q[R];if(0<s(ee,ie))Q[R]=ie,Q[k]=ee,k=R;else break e}}function n(Q){return Q.length===0?null:Q[0]}function r(Q){if(Q.length===0)return null;var ie=Q[0],k=Q.pop();if(k!==ie){Q[0]=k;e:for(var R=0,ee=Q.length,O=ee>>>1;R<O;){var _e=2*(R+1)-1,Ue=Q[_e],ye=_e+1,Le=Q[ye];if(0>s(Ue,k))ye<ee&&0>s(Le,Ue)?(Q[R]=Le,Q[ye]=k,R=ye):(Q[R]=Ue,Q[_e]=k,R=_e);else if(ye<ee&&0>s(Le,k))Q[R]=Le,Q[ye]=k,R=ye;else break e}}return ie}function s(Q,ie){var k=Q.sortIndex-ie.sortIndex;return k!==0?k:Q.id-ie.id}if(typeof performance=="object"&&typeof performance.now=="function"){var a=performance;e.unstable_now=function(){return a.now()}}else{var u=Date,c=u.now();e.unstable_now=function(){return u.now()-c}}var d=[],f=[],p=1,m=null,b=3,y=!1,_=!1,A=!1,v=typeof setTimeout=="function"?setTimeout:null,w=typeof clearTimeout=="function"?clearTimeout:null,N=typeof setImmediate!="undefined"?setImmediate:null;typeof navigator!="undefined"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function C(Q){for(var ie=n(f);ie!==null;){if(ie.callback===null)r(f);else if(ie.startTime<=Q)r(f),ie.sortIndex=ie.expirationTime,t(d,ie);else break;ie=n(f)}}function H(Q){if(A=!1,C(Q),!_)if(n(d)!==null)_=!0,xe(Y);else{var ie=n(f);ie!==null&&oe(H,ie.startTime-Q)}}function Y(Q,ie){_=!1,A&&(A=!1,w(ne),ne=-1),y=!0;var k=b;try{for(C(ie),m=n(d);m!==null&&(!(m.expirationTime>ie)||Q&&!se());){var R=m.callback;if(typeof R=="function"){m.callback=null,b=m.priorityLevel;var ee=R(m.expirationTime<=ie);ie=e.unstable_now(),typeof ee=="function"?m.callback=ee:m===n(d)&&r(d),C(ie)}else r(d);m=n(d)}if(m!==null)var O=!0;else{var _e=n(f);_e!==null&&oe(H,_e.startTime-ie),O=!1}return O}finally{m=null,b=k,y=!1}}var D=!1,q=null,ne=-1,de=5,V=-1;function se(){return!(e.unstable_now()-V<de)}function pe(){if(q!==null){var Q=e.unstable_now();V=Q;var ie=!0;try{ie=q(!0,Q)}finally{ie?ve():(D=!1,q=null)}}else D=!1}var ve;if(typeof N=="function")ve=function(){N(pe)};else if(typeof MessageChannel!="undefined"){var re=new MessageChannel,ae=re.port2;re.port1.onmessage=pe,ve=function(){ae.postMessage(null)}}else ve=function(){v(pe,0)};function xe(Q){q=Q,D||(D=!0,ve())}function oe(Q,ie){ne=v(function(){Q(e.unstable_now())},ie)}e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(Q){Q.callback=null},e.unstable_continueExecution=function(){_||y||(_=!0,xe(Y))},e.unstable_forceFrameRate=function(Q){0>Q||125<Q?console.error("forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"):de=0<Q?Math.floor(1e3/Q):5},e.unstable_getCurrentPriorityLevel=function(){return b},e.unstable_getFirstCallbackNode=function(){return n(d)},e.unstable_next=function(Q){switch(b){case 1:case 2:case 3:var ie=3;break;default:ie=b}var k=b;b=ie;try{return Q()}finally{b=k}},e.unstable_pauseExecution=function(){},e.unstable_requestPaint=function(){},e.unstable_runWithPriority=function(Q,ie){switch(Q){case 1:case 2:case 3:case 4:case 5:break;default:Q=3}var k=b;b=Q;try{return ie()}finally{b=k}},e.unstable_scheduleCallback=function(Q,ie,k){var R=e.unstable_now();switch(typeof k=="object"&&k!==null?(k=k.delay,k=typeof k=="number"&&0<k?R+k:R):k=R,Q){case 1:var ee=-1;break;case 2:ee=250;break;case 5:ee=1073741823;break;case 4:ee=1e4;break;default:ee=5e3}return ee=k+ee,Q={id:p++,callback:ie,priorityLevel:Q,startTime:k,expirationTime:ee,sortIndex:-1},k>R?(Q.sortIndex=k,t(f,Q),n(d)===null&&Q===n(f)&&(A?(w(ne),ne=-1):A=!0,oe(H,k-R))):(Q.sortIndex=ee,t(d,Q),_||y||(_=!0,xe(Y))),Q},e.unstable_shouldYield=se,e.unstable_wrapCallback=function(Q){var ie=b;return function(){var k=b;b=ie;try{return Q.apply(this,arguments)}finally{b=k}}}})(Af)),Af}var b1;function xk(){return b1||(b1=1,wf.exports=Sk()),wf.exports}var _1;function wk(){if(_1)return In;_1=1;var e=fr(),t=xk();function n(i){for(var o="https://reactjs.org/docs/error-decoder.html?invariant="+i,l=1;l<arguments.length;l++)o+="&args[]="+encodeURIComponent(arguments[l]);return"Minified React error #"+i+"; visit "+o+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}var r=new Set,s={};function a(i,o){u(i,o),u(i+"Capture",o)}function u(i,o){for(s[i]=o,i=0;i<o.length;i++)r.add(o[i])}var c=!(typeof window=="undefined"||typeof window.document=="undefined"||typeof window.document.createElement=="undefined"),d=Object.prototype.hasOwnProperty,f=/^[:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD][:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\-.0-9\u00B7\u0300-\u036F\u203F-\u2040]*$/,p={},m={};function b(i){return d.call(m,i)?!0:d.call(p,i)?!1:f.test(i)?m[i]=!0:(p[i]=!0,!1)}function y(i,o,l,h){if(l!==null&&l.type===0)return!1;switch(typeof o){case"function":case"symbol":return!0;case"boolean":return h?!1:l!==null?!l.acceptsBooleans:(i=i.toLowerCase().slice(0,5),i!=="data-"&&i!=="aria-");default:return!1}}function _(i,o,l,h){if(o===null||typeof o=="undefined"||y(i,o,l,h))return!0;if(h)return!1;if(l!==null)switch(l.type){case 3:return!o;case 4:return o===!1;case 5:return isNaN(o);case 6:return isNaN(o)||1>o}return!1}function A(i,o,l,h,E,T,S){this.acceptsBooleans=o===2||o===3||o===4,this.attributeName=h,this.attributeNamespace=E,this.mustUseProperty=l,this.propertyName=i,this.type=o,this.sanitizeURL=T,this.removeEmptyString=S}var v={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(i){v[i]=new A(i,0,!1,i,null,!1,!1)}),[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(i){var o=i[0];v[o]=new A(o,1,!1,i[1],null,!1,!1)}),["contentEditable","draggable","spellCheck","value"].forEach(function(i){v[i]=new A(i,2,!1,i.toLowerCase(),null,!1,!1)}),["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(i){v[i]=new A(i,2,!1,i,null,!1,!1)}),"allowFullScreen async autoFocus autoPlay controls default defer disabled disablePictureInPicture disableRemotePlayback formNoValidate hidden loop noModule noValidate open playsInline readOnly required reversed scoped seamless itemScope".split(" ").forEach(function(i){v[i]=new A(i,3,!1,i.toLowerCase(),null,!1,!1)}),["checked","multiple","muted","selected"].forEach(function(i){v[i]=new A(i,3,!0,i,null,!1,!1)}),["capture","download"].forEach(function(i){v[i]=new A(i,4,!1,i,null,!1,!1)}),["cols","rows","size","span"].forEach(function(i){v[i]=new A(i,6,!1,i,null,!1,!1)}),["rowSpan","start"].forEach(function(i){v[i]=new A(i,5,!1,i.toLowerCase(),null,!1,!1)});var w=/[\-:]([a-z])/g;function N(i){return i[1].toUpperCase()}"accent-height alignment-baseline arabic-form baseline-shift cap-height clip-path clip-rule color-interpolation color-interpolation-filters color-profile color-rendering dominant-baseline enable-background fill-opacity fill-rule flood-color flood-opacity font-family font-size font-size-adjust font-stretch font-style font-variant font-weight glyph-name glyph-orientation-horizontal glyph-orientation-vertical horiz-adv-x horiz-origin-x image-rendering letter-spacing lighting-color marker-end marker-mid marker-start overline-position overline-thickness paint-order panose-1 pointer-events rendering-intent shape-rendering stop-color stop-opacity strikethrough-position strikethrough-thickness stroke-dasharray stroke-dashoffset stroke-linecap stroke-linejoin stroke-miterlimit stroke-opacity stroke-width text-anchor text-decoration text-rendering underline-position underline-thickness unicode-bidi unicode-range units-per-em v-alphabetic v-hanging v-ideographic v-mathematical vector-effect vert-adv-y vert-origin-x vert-origin-y word-spacing writing-mode xmlns:xlink x-height".split(" ").forEach(function(i){var o=i.replace(w,N);v[o]=new A(o,1,!1,i,null,!1,!1)}),"xlink:actuate xlink:arcrole xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(i){var o=i.replace(w,N);v[o]=new A(o,1,!1,i,"http://www.w3.org/1999/xlink",!1,!1)}),["xml:base","xml:lang","xml:space"].forEach(function(i){var o=i.replace(w,N);v[o]=new A(o,1,!1,i,"http://www.w3.org/XML/1998/namespace",!1,!1)}),["tabIndex","crossOrigin"].forEach(function(i){v[i]=new A(i,1,!1,i.toLowerCase(),null,!1,!1)}),v.xlinkHref=new A("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1),["src","href","action","formAction"].forEach(function(i){v[i]=new A(i,1,!1,i.toLowerCase(),null,!0,!0)});function C(i,o,l,h){var E=v.hasOwnProperty(o)?v[o]:null;(E!==null?E.type!==0:h||!(2<o.length)||o[0]!=="o"&&o[0]!=="O"||o[1]!=="n"&&o[1]!=="N")&&(_(o,l,E,h)&&(l=null),h||E===null?b(o)&&(l===null?i.removeAttribute(o):i.setAttribute(o,""+l)):E.mustUseProperty?i[E.propertyName]=l===null?E.type===3?!1:"":l:(o=E.attributeName,h=E.attributeNamespace,l===null?i.removeAttribute(o):(E=E.type,l=E===3||E===4&&l===!0?"":""+l,h?i.setAttributeNS(h,o,l):i.setAttribute(o,l))))}var H=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,Y=Symbol.for("react.element"),D=Symbol.for("react.portal"),q=Symbol.for("react.fragment"),ne=Symbol.for("react.strict_mode"),de=Symbol.for("react.profiler"),V=Symbol.for("react.provider"),se=Symbol.for("react.context"),pe=Symbol.for("react.forward_ref"),ve=Symbol.for("react.suspense"),re=Symbol.for("react.suspense_list"),ae=Symbol.for("react.memo"),xe=Symbol.for("react.lazy"),oe=Symbol.for("react.offscreen"),Q=Symbol.iterator;function ie(i){return i===null||typeof i!="object"?null:(i=Q&&i[Q]||i["@@iterator"],typeof i=="function"?i:null)}var k=Object.assign,R;function ee(i){if(R===void 0)try{throw Error()}catch(l){var o=l.stack.trim().match(/\n( *(at )?)/);R=o&&o[1]||""}return`
|
|
10
|
+
`+a)}}catch(u){}}throw r}})}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=ns(this.defaults,n);const{transitional:r,paramsSerializer:s,headers:a}=n;r!==void 0&&cl.assertOptions(r,{silentJSONParsing:pn.transitional(pn.boolean),forcedJSONParsing:pn.transitional(pn.boolean),clarifyTimeoutError:pn.transitional(pn.boolean),legacyInterceptorReqResOrdering:pn.transitional(pn.boolean),advertiseZstdAcceptEncoding:pn.transitional(pn.boolean),validateStatusUndefinedResolves:pn.transitional(pn.boolean)},!1),s!=null&&($.isFunction(s)?n.paramsSerializer={serialize:s}:cl.assertOptions(s,{encode:pn.function,serialize:pn.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),cl.assertOptions(n,{baseUrl:pn.spelling("baseURL"),withXsrfToken:pn.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let u=a&&$.merge(a.common,a[n.method]);a&&$.forEach(["delete","get","head","post","put","patch","query","common"],_=>{delete a[_]}),n.headers=hn.concat(u,a);const c=[];let d=!0;this.interceptors.request.forEach(function(A){if(typeof A.runWhen=="function"&&A.runWhen(n)===!1)return;d=d&&A.synchronous;const v=n.transitional||cf;v&&v.legacyInterceptorReqResOrdering?c.unshift(A.fulfilled,A.rejected):c.push(A.fulfilled,A.rejected)});const f=[];this.interceptors.response.forEach(function(A){f.push(A.fulfilled,A.rejected)});let p,m=0,b;if(!d){const _=[Mg.bind(this),void 0];for(_.unshift(...c),_.push(...f),b=_.length,p=Promise.resolve(n);m<b;)p=p.then(_[m++],_[m++]);return p}b=c.length;let y=n;for(;m<b;){const _=c[m++],A=c[m++];try{y=_(y)}catch(v){A.call(this,v);break}}try{p=Mg.call(this,y)}catch(_){return Promise.reject(_)}for(m=0,b=f.length;m<b;)p=p.then(f[m++],f[m++]);return p}getUri(t){t=ns(this.defaults,t);const n=Cg(t.baseURL,t.url,t.allowAbsoluteUrls,t);return gg(n,t.params,t.paramsSerializer)}};$.forEach(["delete","get","head","options"],function(t){rs.prototype[t]=function(n,r){return this.request(ns(r||{},{method:t,url:n,data:r&&$.hasOwnProp(r,"data")?r.data:void 0}))}}),$.forEach(["post","put","patch","query"],function(t){function n(r){return function(a,u,c){return this.request(ns(c||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:a,data:u}))}}rs.prototype[t]=n(),t!=="query"&&(rs.prototype[t+"Form"]=n(!0))});let rv=class M2{constructor(t){if(typeof t!="function")throw new TypeError("executor must be a function.");let n;this.promise=new Promise(function(a){n=a});const r=this;this.promise.then(s=>{if(!r._listeners)return;let a=r._listeners.length;for(;a-- >0;)r._listeners[a](s);r._listeners=null}),this.promise.then=s=>{let a;const u=new Promise(c=>{r.subscribe(c),a=c}).then(s);return u.cancel=function(){r.unsubscribe(a)},u},t(function(a,u,c){r.reason||(r.reason=new fa(a,u,c),n(r.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(t){if(this.reason){t(this.reason);return}this._listeners?this._listeners.push(t):this._listeners=[t]}unsubscribe(t){if(!this._listeners)return;const n=this._listeners.indexOf(t);n!==-1&&this._listeners.splice(n,1)}toAbortSignal(){const t=new AbortController,n=r=>{t.abort(r)};return this.subscribe(n),t.signal.unsubscribe=()=>this.unsubscribe(n),t.signal}static source(){let t;return{token:new M2(function(s){t=s}),cancel:t}}};function iv(e){return function(n){return e.apply(null,n)}}function sv(e){return $.isObject(e)&&e.isAxiosError===!0}const Ef={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511,WebServerIsDown:521,ConnectionTimedOut:522,OriginIsUnreachable:523,TimeoutOccurred:524,SslHandshakeFailed:525,InvalidSslCertificate:526};Object.entries(Ef).forEach(([e,t])=>{Ef[t]=e});function Bg(e){const t=new rs(e),n=Z0(rs.prototype.request,t);return $.extend(n,rs.prototype,t,{allOwnKeys:!0}),$.extend(n,t,null,{allOwnKeys:!0}),n.create=function(s){return Bg(ns(e,s))},n}const Rt=Bg(da);Rt.Axios=rs,Rt.CanceledError=fa,Rt.CancelToken=rv,Rt.isCancel=_g,Rt.VERSION=pf,Rt.toFormData=sl,Rt.AxiosError=be,Rt.Cancel=Rt.CanceledError,Rt.all=function(t){return Promise.all(t)},Rt.spread=iv,Rt.isAxiosError=sv,Rt.mergeConfig=ns,Rt.AxiosHeaders=hn,Rt.formToJSON=e=>bg($.isHTMLForm(e)?new FormData(e):e),Rt.getAdapter=Dg.getAdapter,Rt.HttpStatusCode=Ef,Rt.default=Rt;const{Axios:U7,AxiosError:H7,CanceledError:z7,isCancel:j7,CancelToken:$7,VERSION:V7,all:q7,Cancel:Y7,isAxiosError:G7,spread:W7,toFormData:X7,AxiosHeaders:K7,HttpStatusCode:Q7,formToJSON:J7,getAdapter:Z7,mergeConfig:eU,create:tU}=Rt;class ov{constructor(t,n,r,s=!1,a,u){Se(this,"CIMULATE_API_HEADER","x-cimulate-api-key");Se(this,"CIMULATE_SEARCH_API_HOST","search.cimulate");Se(this,"CIMULATE_SEARCH_API_PATH","api/v1");Se(this,"baseApiUrl");Se(this,"headers",{});Se(this,"fetchConfig",()=>Ke(this,null,function*(){try{const t=yield Rt.get(`${this.apiUrl}/configs/copilot`,{headers:this.headers}),{customer_config:n}=t.data,r=atob(n);return JSON.parse(r)}catch(t){throw console.error("Error fetching customer config:",t),t}}));Se(this,"_mapCopilotUrlToSearchUrl",(t="",n=!1)=>{if(t.endsWith("io")){const s=new URL(t);return s.hostname=s.hostname.replace(/^copilot\./,"api."),s.origin}return n?`https://staging.${this.CIMULATE_SEARCH_API_HOST}.ai`:`https://prod.${this.CIMULATE_SEARCH_API_HOST}.ai`});if(n&&r||!n&&!r)throw new Error("Provide exactly one authentication method: either 'apiKey' or 'apiToken', but not both.");n?this.headers[this.CIMULATE_API_HEADER]=n:r&&(this.headers.Authorization=`Bearer ${r}`),a&&(this.headers["x-cimulate-customer-id"]=a),u&&(this.headers["Tenant-ID"]=u),this.baseApiUrl=this._mapCopilotUrlToSearchUrl(t,s)}get apiUrl(){return`${this.baseApiUrl}/${this.CIMULATE_SEARCH_API_PATH}`}}class av{constructor(t,n,r,s=!1,a,u){Se(this,"apiService");Se(this,"config",null);Se(this,"getConfig",()=>Ke(this,null,function*(){if(this.config)return this.config;try{const t=yield this.apiService.fetchConfig();return this.config=t,this.config}catch(t){throw console.error("Failed to fetch customer config:",t),t}}));Se(this,"getPid",t=>this.getProductFieldValue(t,"pidCol"));Se(this,"getName",t=>this.getProductFieldValue(t,"nameCol"));Se(this,"getDescription",t=>this.getProductFieldValue(t,"description"));Se(this,"getBrand",t=>this.getProductFieldValue(t,"productBrandCol"));Se(this,"getPrice",t=>this.getProductFieldValue(t,"priceCol"));Se(this,"getRelativePdp",t=>this.getProductFieldValue(t,"relativePdpCol"));Se(this,"getPdp",t=>this.getProductFieldValue(t,"pdpCol"));Se(this,"getImage",t=>this.getProductFieldValue(t,"imageCol"));Se(this,"getProductHiddenFields",()=>{const t=this.getProductField("productHiddenFields");return Array.isArray(t)?t:[]});Se(this,"getProductField",t=>this.config?this.config[t]:"");Se(this,"getProductFieldValue",(t,n)=>{const r=this.getProductField(n);return r&&t[r]||""});this.apiService=new ov(t,n,r,s,a,u)}getPriceDisplay(t){const n=this.getPrice(t);return n?typeof n=="string"?n.includes("$")?n:`$${n}`:typeof n=="number"?new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}).format(n):n:""}}const Ws=(e,t,n,...r)=>{if(!e)return;const s=["background: linear-gradient(90deg,rgba(253, 99, 99, 1) 0%, rgba(245, 139, 35, 1) 65%)","font-weight: bold","color: transparent","background-clip: text","text-fill-color: transparent"].join(";");console[t]("%c[cimulate-widget]",s,n,...r)};class uv{constructor(t=!1){Se(this,"isDevelopment");Se(this,"_log",(t,n,...r)=>{Ws(this.isDevelopment,t,n,...r)});this.isDevelopment=t}log(t,...n){this._log("log",t,...n)}warn(t,...n){this._log("warn",t,...n)}error(t,...n){this._log("error",t,...n)}info(t,...n){this._log("info",t,...n)}debug(t,...n){this._log("debug",t,...n)}}const lv={copilot:"Your Search Assistant",messaging:"Commerce Client"},Ug=B.createContext(null),cv=({mode:e,logoUrl:t,headerText:n,headerConfig:r,globalClassName:s="",entryMessage:a,openLinksInNewTab:u=!1,disclaimerText:c,disclaimerMarkdown:d,clientContext:f,baseCatalogParams:p,searchPlaceholder:m,searchButtonLabel:b,searchConfig:y,suggestionButtonConfig:_,progressStepsLimit:A=3,messageAlignment:v="start",autoScroll:w=!0,showProductDescription:N=!1,componentConfig:C,conversationHistory:H,resetConversationMessage:Y="",apiKey:D,apiToken:q,baseUrl:ne,customerId:de,tenantId:V,theme:se,isDevelopment:pe,__features:ve,routingAttributes:re,enableDownloadTranscript:ae=!0,enableEscalationToAgent:xe=!1,showProductCaptions:oe=!1,staticQuestions:Q,staticQuestionsStrategy:ie="append",children:k})=>{const R=e==="messaging",ee=B.useMemo(()=>{const Ye=re==null?void 0:re.isCartMgmtSupported;return Ye===!0||Ye==="true"},[re]),O=B.useMemo(()=>R?{config:null}:new av(ne,D,q,pe,de,V),[R,ne,D,q,pe,de,V]),_e=B.useMemo(()=>new uv(pe),[pe]);B.useEffect(()=>{R||!O||O.config||O.getConfig()},[O,R]);const Ue=B.useMemo(()=>hA(se),[se]),ye=B.useMemo(()=>{const Ye=(y==null?void 0:y.placeholder)||m,ht=(y==null?void 0:y.buttonLabel)||b;let Vt="icon";return y!=null&&y.buttonType?Vt=y.buttonType:b&&(Vt="text"),fe(F({},y||{}),{placeholder:Ye,buttonLabel:ht,buttonType:Vt})},[y,m,b]),Le=B.useMemo(()=>fe(F({},r||{}),{logoUrl:t||(r==null?void 0:r.logoUrl),headerText:(r==null?void 0:r.headerText)||n||lv[e!=null?e:"copilot"]}),[r,t,n,e]),He=B.useMemo(()=>({configModule:O,mode:e!=null?e:"copilot",headerConfig:Le,entryMessage:a,staticQuestions:Q||[],staticQuestionsStrategy:ie,globalClassName:s,openLinksInNewTab:u,disclaimerText:c,disclaimerMarkdown:d,clientContext:f,baseCatalogParams:p,themeVariables:Ue,logger:_e,searchConfig:ye,suggestionButtonConfig:_,progressStepsLimit:A,messageAlignment:v,autoScroll:w,showProductDescription:!!N,enableMinimize:!!(C!=null&&C.enableMinimize),enableDownloadTranscript:ae,enableEscalationToAgent:xe,showProductCaptions:!!oe,resetConversationMessage:Y,conversationHistory:{sinceHours:typeof(H==null?void 0:H.sinceHours)=="number"?H.sinceHours:R?24:1,limit:H==null?void 0:H.limit},features:ve,isCartMgmtSupported:ee}),[O,e,Le,a,Q,ie,s,f,p,c,d,u,ye,_,v,w,N,C,ae,xe,A,oe,Y,_e,Ue,H,ve,ee]);return x.jsx(Ug.Provider,{value:He,children:k})},tt=()=>{const e=B.useContext(Ug);if(!e)throw new Error("useConfig must be used within a ConfigProvider");return e};class dv{constructor(){Se(this,"initialState",{connected:!1,mode:"embedded",entryType:"search",status:{type:"dialog",isOpen:!1,isMinimized:!1},dialog:{position:"bottom-left",isFullHeight:!1,width:""},modal:{isFullscreen:!1}});Se(this,"connectedProxy");Se(this,"modeProxy");Se(this,"entryTypeProxy");Se(this,"statusProxy");Se(this,"dialogProxy");Se(this,"modalProxy",{isFullscreen:!1});Se(this,"_fullGet",(t,n)=>Reflect.get(t,n));Se(this,"_fullSet",(t,n,r)=>{if(!(n in t))throw new Error(`Property ${n} does not exist on UIState`);return gv(n,r),Reflect.set(t,n,r)});this.connectedProxy=new Proxy({connected:this.initialState.connected},{get:this._fullGet,set:this._fullSet}),this.modeProxy=new Proxy({mode:this.initialState.mode},{get:this._fullGet,set:this._fullSet}),this.entryTypeProxy=new Proxy({entryType:this.initialState.entryType},{get:this._fullGet,set:this._fullSet}),this.statusProxy=new Proxy({type:this.initialState.status.type,isOpen:this.initialState.status.isOpen,isMinimized:this.initialState.status.isMinimized},{get:this._fullGet,set:this._fullSet}),this.dialogProxy=new Proxy({position:this.initialState.dialog.position,isFullHeight:this.initialState.dialog.isFullHeight,width:this.initialState.dialog.width},{get:this._fullGet,set:this._fullSet}),this.modalProxy=new Proxy({isFullscreen:this.initialState.modal.isFullscreen},{get:this._fullGet,set:this._fullSet})}get connected(){return this.connectedProxy.connected}get mode(){return this.modeProxy.mode}get isOpen(){return!!this.statusProxy.isOpen}get isMinimized(){return!!this.statusProxy.isMinimized}get type(){return this.statusProxy.type}get entryType(){return this.entryTypeProxy.entryType}get position(){return this.dialogProxy.position}get state(){return{connected:this.connected,mode:this.mode,entryType:this.entryType,status:{type:this.type,isOpen:this.isOpen,isMinimized:this.isMinimized},dialog:{position:this.position,isFullHeight:this.dialogProxy.isFullHeight,width:this.dialogProxy.width},modal:{isFullscreen:this.modalProxy.isFullscreen}}}}const Je=new dv,is=()=>Je.connected,ha=()=>Je.isOpen,yf="cimulate.widget.minimizedOnNav";function fv(){try{const e=sessionStorage.getItem(yf)==="1";return sessionStorage.removeItem(yf),e}catch(e){return!1}}function hv(){try{sessionStorage.removeItem(yf)}catch(e){return}}const pv=e=>{window.addEventListener(Zd,e)},mv=e=>{window.removeEventListener(Zd,e)},gv=(e,t)=>{const n=new CustomEvent(Zd,{detail:{property:e,value:t}});window.dispatchEvent(n)},Ev=e=>{Je.connectedProxy.connected=e},pa=e=>{if(!uA(e)){const t=W0.map(r=>`'${r}'`),n=`${t.slice(0,-1).join(", ")}, or ${t[t.length-1]}`;throw new Error(`Invalid entryType: "${e}". Must be ${n}.`)}Je.entryTypeProxy.entryType=e},ti=e=>{const t=Je.statusProxy.isOpen,n=typeof e=="boolean"?e:!t;Je.statusProxy.isOpen=n,n&&(Je.statusProxy.isMinimized=!1,hv())},ma=e=>{const t=Je.statusProxy.isMinimized,n=typeof e=="boolean"?e:!t;Je.statusProxy.isMinimized=n,n&&(Je.statusProxy.isOpen=!1)},Tf=e=>{Je.modalProxy.isFullscreen=e},dl=e=>{if(!["chat","dialog","modal"].includes(e))throw new Error(`Invalid type: ${e}. Must be 'chat', 'dialog', or 'modal'.`);Je.statusProxy.type=e,e==="dialog"||e==="chat"?Je.modeProxy.mode="embedded":Je.modeProxy.mode="standalone"},bf=e=>{const t=["top","top-left","top-right","bottom","bottom-left","bottom-right","left","right","center"];if(!t.includes(e))throw new Error(`Invalid position: ${e}. Must be one of ${t.join(", ")}.`);Je.dialogProxy.position=e},yv=e=>{const t=Je.dialogProxy.isFullHeight,n=typeof e=="boolean"?e:!t;Je.dialogProxy.isFullHeight=n},Tv=({onCopilotEvent:e,children:t,dispatch:n})=>{const{logger:r}=tt(),s=B.useCallback(C=>{n({type:mt.SET_COPILOT,payload:C})},[n]),a=B.useCallback(C=>{Ev(C),n({type:mt.SET_CONNECTED,payload:C})},[n]),u=B.useCallback(()=>{n({type:mt.RESET_COPILOT,payload:{}})},[n]),c=B.useCallback(()=>{n({type:mt.RESET_STATE,payload:{}})},[n]),d=B.useCallback(C=>{r==null||r.log(`${C.name} event received`,C),n({type:mt.ADD_MESSAGE,payload:C}),C.bypassHandlers||e==null||e(C)},[e,r,n]),f=B.useCallback(C=>{n({type:mt.ADD_LOADING_MESSAGE,payload:C})},[n]),p=B.useCallback(C=>{n({type:mt.REMOVE_LOADING_MESSAGE,payload:C})},[n]),m=B.useCallback(C=>{d(C),f(C.id)},[d,f]),b=B.useCallback(C=>{n({type:mt.SET_ACTIVE_CONVERSATION_ID,payload:C})},[n]),y=B.useCallback(C=>{n({type:mt.ADD_CONVERSATION_ID,payload:C})},[n]),_=B.useCallback(C=>{n({type:mt.SET_CONVERSATION_IDS,payload:C})},[n]),A=B.useCallback(C=>{n({type:mt.SET_IMAGE_FILE,payload:C})},[n]),v=B.useCallback(C=>{n({type:mt.SET_ASK_CIM_PROMPTS,payload:C})},[n]),w=B.useCallback(C=>{n({type:mt.SET_CONVERSATION_HISTORY_LOADED,payload:C})},[n]),N=B.useMemo(()=>({setCopilot:s,setConnected:a,resetCopilot:u,resetCopilotState:c,addCopilotEvent:d,addLoadingMessage:f,removeLoadingMessage:p,handleCopilotRequestAck:m,setActiveConversationId:b,addConversationId:y,setConversationIds:_,setImageFile:A,setAskCimPrompts:v,setConversationHistoryLoaded:w}),[s,a,u,c,d,f,p,m,b,y,_,A,v,w]);return x.jsx(Q0.Provider,{value:N,children:t})};sA();const bv=(e,t)=>{const{type:n,payload:r}=t;if(n===mt.ADD_MESSAGE){const s=r;if(e.messages.push(s),s.eventSourceId){const a=e.groupedMessages.findIndex(u=>u.eventSourceId===s.eventSourceId);if(a!==-1){let u=e.groupedMessages[a].messages;u||(u=[]);const c=u.findIndex(d=>d.id===s.id);if(c!==-1){u[c]=s;return}u.push(s);return}else{e.groupedMessages.push({type:"group",eventSourceId:s.eventSourceId,messages:[s],createdAt:new Date(s.createdAt)});return}}e.groupedMessages.push({type:"individual",message:s,createdAt:new Date(s.createdAt)});return}switch(n){case mt.RESET_STATE:e.messages=Zi.messages,e.groupedMessages=Zi.groupedMessages,e.loadingMessages=Zi.loadingMessages,e.imageFile=Zi.imageFile,e.askCimPrompts=Zi.askCimPrompts,e.conversationHistoryLoaded=Zi.conversationHistoryLoaded;break;case mt.RESET_COPILOT:e.copilot=null;break;case mt.SET_COPILOT:e.copilot=r;break;case mt.SET_CONNECTED:e.connected=r;break;case mt.ADD_LOADING_MESSAGE:e.loadingMessages.add(r);break;case mt.REMOVE_LOADING_MESSAGE:e.loadingMessages.delete(r);break;case mt.SET_ACTIVE_CONVERSATION_ID:e.activeConversationId=r;break;case mt.ADD_CONVERSATION_ID:{const s=r;e.conversationIds.includes(s)||e.conversationIds.push(s)}break;case mt.SET_CONVERSATION_IDS:e.conversationIds=r;break;case mt.SET_IMAGE_FILE:e.imageFile=r;break;case mt.SET_ASK_CIM_PROMPTS:e.askCimPrompts.requestId=(r==null?void 0:r.requestId)||null,e.askCimPrompts.message=(r==null?void 0:r.message)||null;break;case mt.SET_CONVERSATION_HISTORY_LOADED:e.conversationHistoryLoaded=r;break}},_v=({onCopilotEvent:e,children:t})=>{const[n,r]=Y0(bv,Zi);return x.jsx(K0.Provider,{value:n,children:x.jsx(Tv,{onCopilotEvent:e,dispatch:r,children:t})})};function Sv(){var e=B.useRef(!0);return e.current?(e.current=!1,!0):e.current}function xv(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];e&&e.addEventListener&&e.addEventListener.apply(e,t)}function wv(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];e&&e.removeEventListener&&e.removeEventListener.apply(e,t)}var _f=typeof window!="undefined",ga=function(e){B.useEffect(e,[])},Av=function(e){var t=B.useRef(e);t.current=e,ga(function(){return function(){return t.current()}})},Cv=function(e){var t=B.useRef(0),n=B.useState(e),r=n[0],s=n[1],a=B.useCallback(function(u){cancelAnimationFrame(t.current),t.current=requestAnimationFrame(function(){s(u)})},[]);return Av(function(){cancelAnimationFrame(t.current)}),[r,a]},vv=function(e,t){return e===t};function kv(e,t){t===void 0&&(t=vv);var n=B.useRef(),r=B.useRef(e),s=Sv();return!s&&!t(r.current,e)&&(n.current=r.current,r.current=e),n.current}var Nv=function(e){var t={},n=t.initialWidth,r=n===void 0?1/0:n,s=t.initialHeight,a=s===void 0?1/0:s,u=t.onChange,c=Cv({width:_f?window.innerWidth:r,height:_f?window.innerHeight:a}),d=c[0],f=c[1];return B.useEffect(function(){if(_f){var p=function(){var m=window.innerWidth,b=window.innerHeight;f({width:m,height:b}),u&&u(m,b)};return xv(window,"resize",p),function(){wv(window,"resize",p)}}},[]),d};class Pv{constructor(){Se(this,"items",[]);Se(this,"add",t=>{const n=this.first();n&&n.context===t.context&&this.remove(),this.items.push(t)});Se(this,"remove",()=>this.items.shift());Se(this,"first",()=>this.items.length>0?this.items[0]:null);Se(this,"clear",()=>{this.items.length=0});Se(this,"processQueue",t=>{new Array(mn.size).fill(1).forEach(()=>{const r=mn.first();r&&(t(r),mn.remove())})})}get size(){return this.items.length}}const mn=new Pv,Hg=e=>{window.addEventListener(Jd,e)},zg=e=>{window.removeEventListener(Jd,e)},Ov=(e,t,n)=>{const r=new CustomEvent(Jd,{detail:{event:e,property:t,value:n}});window.dispatchEvent(r)},jg=e=>{window.addEventListener(Qd,e)},$g=e=>{window.removeEventListener(Qd,e)},Iv=(e,t,n)=>{const r=new CustomEvent(Qd,{detail:{event:e,property:t,value:n}});window.dispatchEvent(r)},Vg=e=>{window.addEventListener(Kd,e)},qg=e=>{window.removeEventListener(Kd,e)},Yg=(e,t,n)=>{const r=new CustomEvent(Kd,{detail:{property:e,value:t,event:n}});window.dispatchEvent(r)},Rv=e=>{window.addEventListener(tf,e)},Lv=e=>{window.removeEventListener(tf,e)},fl=(e,t,n)=>{const r=new CustomEvent(tf,{detail:{property:e,value:t,event:n}});window.dispatchEvent(r)};class Dv{constructor(){Se(this,"initialParams",{categoryId:"",categoryName:"",page:null,pageSize:null,includeFacets:!0,facetFilters:{},rangeFilters:[],catalogSegment:null,pricebooks:null});Se(this,"categoryIdProxy");Se(this,"facetFiltersProxy");Se(this,"rangeFiltersProxy");Se(this,"catalogSegmentProxy");Se(this,"pricebooksProxy");Se(this,"_fullGet",(t,n)=>Reflect.get(t,n));Se(this,"_fullSet",(t,n,r)=>{const s=dA[n];return Iv(s,n,r),Reflect.set(t,n,r)});Se(this,"updateFacetFiltersProxy",t=>new Proxy({facetFilters:t},{get:this._fullGet,set:this._fullSet}));Se(this,"updateRangeFiltersProxy",t=>new Proxy({rangeFilters:t},{get:this._fullGet,set:this._fullSet}));Se(this,"updatePricebooksProxy",t=>new Proxy({pricebooks:t},{get:this._fullGet,set:this._fullSet}));this.categoryIdProxy=new Proxy({categoryId:this.initialParams.categoryId,categoryName:this.initialParams.categoryName},{get:this._fullGet,set:this._fullSet}),this.facetFiltersProxy=this.updateFacetFiltersProxy(this.initialParams.facetFilters||{}),this.rangeFiltersProxy=this.updateRangeFiltersProxy(this.initialParams.rangeFilters||[]),this.catalogSegmentProxy=new Proxy({catalogSegment:this.initialParams.catalogSegment},{get:this._fullGet,set:this._fullSet}),this.pricebooksProxy=this.updatePricebooksProxy(this.initialParams.pricebooks||null)}get categoryId(){return this.categoryIdProxy.categoryId||""}get facetFilters(){return this.facetFiltersProxy.facetFilters||{}}get rangeFilters(){return this.rangeFiltersProxy.rangeFilters||[]}get catalogSegment(){return this.catalogSegmentProxy.catalogSegment||null}get pricebooks(){return this.pricebooksProxy.pricebooks||null}get state(){return{categoryId:this.categoryId,categoryName:this.categoryIdProxy.categoryName,facetFilters:this.facetFilters,rangeFilters:this.rangeFilters,catalogSegment:this.catalogSegment,pricebooks:this.pricebooks,page:this.initialParams.page,pageSize:this.initialParams.pageSize,includeFacets:this.initialParams.includeFacets}}}const at=new Dv,Gg=(e,t)=>{const n=t.updateFacetFiltersProxy(e);t.facetFiltersProxy.facetFilters=n.facetFilters},Wg=(e,t,n)=>{var u,c;const r=F({},((u=n.facetFiltersProxy)==null?void 0:u.facetFilters)||{});if(!!((c=r[e])!=null&&c.includes(t))){const d=r[e].filter(f=>f!==t);d.length>0?r[e]=d:delete r[e]}else r[e]=r[e]?[...r[e],t]:[t];const a=n.updateFacetFiltersProxy(r);n.facetFiltersProxy.facetFilters=a.facetFilters},Xg=(e,t)=>{const n=t.updateRangeFiltersProxy(e);t.rangeFiltersProxy.rangeFilters=n.rangeFilters},Kg=({field:e,value:t},n)=>{const[r,s]=Array.isArray(t)?t:[];if(typeof r=="undefined"||typeof s=="undefined")throw new Error("Range values must be an array with two numbers for min and max");const a=[...n.rangeFiltersProxy.rangeFilters||[]],u=a.findIndex(d=>d.field===e);if(u!==-1){a[u]={field:e,min:r,max:s},n.rangeFiltersProxy.rangeFilters=a;return}a.push({field:e,min:r,max:s});const c=n.updateRangeFiltersProxy(a);n.rangeFiltersProxy.rangeFilters=c.rangeFilters},Qg=(e,t)=>{t.catalogSegmentProxy.catalogSegment=e},Jg=(e,t)=>{const n=t.updatePricebooksProxy(e);t.pricebooksProxy.pricebooks=n.pricebooks},Mv=e=>{if(!is()||!ha()){is()&&mn.clear(),mn.add({context:"browse",payload:fe(F({},at.state),{categoryId:e})});return}at.categoryIdProxy.categoryId=e},Zg=e=>{Gg(e,at)},Fv=(e,t)=>{Wg(e,t,at)},e1=e=>{Xg(e,at)},Bv=({field:e,value:t})=>{Kg({field:e,value:t},at)},Uv=e=>{Qg(e,at)},t1=e=>{Jg(e,at)},n1=e=>{if(!e||!("categoryId"in e))throw new Error("Browse context must include a categoryId");const t=is(),n=ha();if(!t||!n){t&&mn.clear(),mn.add({context:"browse",payload:F({},e)});return}"facetFilters"in e&&Zg(e.facetFilters||{}),"rangeFilters"in e&&e1(e.rangeFilters||[]),"catalogSegment"in e&&(at.catalogSegmentProxy.catalogSegment=e.catalogSegment||null),"pricebooks"in e&&t1(e.pricebooks||[]),"categoryName"in e&&(at.categoryIdProxy.categoryName=e.categoryName||""),at.categoryIdProxy.categoryId=e.categoryId},Hv=Object.freeze(Object.defineProperty({__proto__:null,setBrowseContext:n1,updateBrowseCategoryId:Mv,updateCatalogSegment:Uv,updateFacetFilter:Fv,updateFacetFilters:Zg,updatePricebooks:t1,updateRangeFilter:Bv,updateRangeFilters:e1},Symbol.toStringTag,{value:"Module"}));class zv{constructor(){Se(this,"initialParams",{productId:"",productName:"",pdpLink:""});Se(this,"proxy");Se(this,"_fullGet",(t,n)=>Reflect.get(t,n));Se(this,"_fullSet",(t,n,r)=>(Yg(n,r),Reflect.set(t,n,r)));Se(this,"updateProxy",t=>{t.productId&&(this.proxy=new Proxy({productId:t.productId,productName:t.productName||"",pdpLink:t.pdpLink||""},{get:this._fullGet,set:this._fullSet}))});this.proxy=new Proxy({productId:this.initialParams.productId,productName:this.initialParams.productName,pdpLink:this.initialParams.pdpLink},{get:this._fullGet,set:this._fullSet})}get productId(){return this.proxy.productId}get pdpLink(){return this.proxy.pdpLink}get state(){return{productId:this.productId,productName:this.proxy.productName,pdpLink:this.pdpLink}}}const mr=new zv,r1=e=>{if(!e||!e.productId)throw new Error("PDP context must include a productId");const t=is(),n=ha();if(!t||!n){t&&mn.clear(),mn.add({context:"pdp",payload:F({},e)});return}mr.updateProxy(e),Yg("pdp-context",e)},jv=e=>{mr.proxy.productId=e,is()||mn.add({context:"pdp",payload:F({},mr.state)})},$v=e=>{mr.proxy.pdpLink=e};class Vv{constructor(){Se(this,"initialState",J0);Se(this,"promptsStateProxy");Se(this,"promptsParamsProxy");Se(this,"_fullGet",(t,n)=>Reflect.get(t,n));Se(this,"_fullSet",(t,n,r)=>{if(!(n in t))throw new Error(`Property ${n} does not exist on PromptsExtensionState`);return Ea(n,r),Reflect.set(t,n,r)});Se(this,"_paramsFullGet",(t,n)=>Reflect.get(t,n));Se(this,"_paramsFullSet",(t,n,r)=>Reflect.set(t,n,r));Se(this,"updatePromptsParamsProxy",t=>new Proxy(F({},t),{get:this._paramsFullGet,set:this._paramsFullSet}));this.promptsStateProxy=new Proxy({isOpen:this.initialState.isOpen,isInline:this.initialState.isInline,elementId:this.initialState.elementId,entryType:this.initialState.entryType},{get:this._fullGet,set:this._fullSet}),this.promptsParamsProxy=this.updatePromptsParamsProxy({})}get isOpen(){return this.promptsStateProxy.isOpen}get isInline(){return this.promptsStateProxy.isInline}get state(){return{isOpen:this.isOpen,isInline:this.isInline}}get params(){return this.promptsParamsProxy}}const Bt=new Vv,qv=e=>{window.addEventListener(ef,e)},Yv=e=>{window.removeEventListener(ef,e)},Ea=(e,t)=>{const n=new CustomEvent(ef,{detail:{property:e,value:t}});window.dispatchEvent(n)},i1=e=>{const t=Bt.isOpen,n=typeof e=="boolean"?e:!t;Bt.promptsStateProxy.isOpen=n},s1=e=>{const t=Bt.isInline,n=typeof e=="boolean"?e:!t;Bt.promptsStateProxy.isInline=n},Gv=e=>{Bt.promptsParamsProxy=Bt.updatePromptsParamsProxy(e),Ea("params",e),Bt.promptsStateProxy.entryType="ask_cim"},Wv=e=>{Bt.promptsParamsProxy=Bt.updatePromptsParamsProxy(e),Ea("params",e),Bt.promptsStateProxy.entryType="search"},Xv=e=>{Bt.promptsParamsProxy=Bt.updatePromptsParamsProxy(e),Ea("params",e),Bt.promptsStateProxy.entryType="browse"},Kv=e=>{Bt.promptsParamsProxy=Bt.updatePromptsParamsProxy(e),Ea("params",e),Bt.promptsStateProxy.entryType="pdp"},Qv=({elementId:e,entryType:t,params:n,isInline:r})=>{Bt.promptsStateProxy.elementId=e,t&&(Bt.promptsStateProxy.entryType=t),typeof r=="boolean"&&s1(r),n&&Bt.updatePromptsParamsProxy(n),Bt.isOpen||i1(!0)},Jv=Object.freeze(Object.defineProperty({__proto__:null,getConversationMessages:({payload:e,callback:t})=>{fl("getConversationMessages",{payload:e,callback:t},bi.GET_CONVERSATION_MESSAGES)},getSessionInformation:e=>{fl("getSessionInformation",{callback:e},bi.GET_SESSION_INFORMATION)},loadConversation:e=>{fl("loadConversation",e,bi.LOAD_CONVERSATION)},resetConversation:()=>{fl("resetConversation",!0,bi.RESET_CONVERSATION)}},Symbol.toStringTag,{value:"Module"}));class Zv{constructor(){Se(this,"initialParams",{query:"",page:null,pageSize:null,includeFacets:!0,facetFilters:{},rangeFilters:[],catalogSegment:null,pricebooks:null});Se(this,"queryProxy");Se(this,"facetFiltersProxy");Se(this,"rangeFiltersProxy");Se(this,"catalogSegmentProxy");Se(this,"pricebooksProxy");Se(this,"_fullGet",(t,n)=>Reflect.get(t,n));Se(this,"_fullSet",(t,n,r)=>{const s=fA[n];return Ov(s,n,r),Reflect.set(t,n,r)});Se(this,"updateFacetFiltersProxy",t=>new Proxy({facetFilters:t},{get:this._fullGet,set:this._fullSet}));Se(this,"updateRangeFiltersProxy",t=>new Proxy({rangeFilters:t},{get:this._fullGet,set:this._fullSet}));Se(this,"updatePricebooksProxy",t=>new Proxy({pricebooks:t},{get:this._fullGet,set:this._fullSet}));this.queryProxy=new Proxy({query:this.initialParams.query},{get:this._fullGet,set:this._fullSet}),this.facetFiltersProxy=this.updateFacetFiltersProxy(this.initialParams.facetFilters||{}),this.rangeFiltersProxy=this.updateRangeFiltersProxy(this.initialParams.rangeFilters||[]),this.catalogSegmentProxy=new Proxy({catalogSegment:this.initialParams.catalogSegment},{get:this._fullGet,set:this._fullSet}),this.pricebooksProxy=this.updatePricebooksProxy(this.initialParams.pricebooks||null)}get query(){return this.queryProxy.query||""}get facetFilters(){return this.facetFiltersProxy.facetFilters||{}}get rangeFilters(){return this.rangeFiltersProxy.rangeFilters||[]}get catalogSegment(){return this.catalogSegmentProxy.catalogSegment||null}get pricebooks(){return this.pricebooksProxy.pricebooks||null}get state(){return{query:this.query,facetFilters:this.facetFilters,rangeFilters:this.rangeFilters,catalogSegment:this.catalogSegment,pricebooks:this.pricebooks,page:this.initialParams.page,pageSize:this.initialParams.pageSize,includeFacets:this.initialParams.includeFacets}}}const bt=new Zv,ek=e=>{const t=ha(),n=is();if(!n||!t){n&&mn.clear(),mn.add({context:"search",payload:fe(F({},bt.state),{query:e})});return}bt.queryProxy.query=e},o1=e=>{Gg(e,bt)},tk=(e,t)=>{Wg(e,t,bt)},a1=e=>{Xg(e,bt)},nk=({field:e,value:t})=>{Kg({field:e,value:t},bt)},rk=e=>{Qg(e,bt)},u1=e=>{Jg(e,bt)},l1=e=>{if(!e||!e.query)throw new Error("Search context must include a query");const t=ha(),n=is();if(!n||!t){n&&mn.clear(),mn.add({context:"search",payload:F({},e)});return}"facetFilters"in e&&o1(e.facetFilters||{}),"rangeFilters"in e&&a1(e.rangeFilters||[]),"catalogSegment"in e&&(bt.catalogSegmentProxy.catalogSegment=e.catalogSegment||null),"pricebooks"in e&&u1(e.pricebooks||[]),bt.queryProxy.query=e.query},ik=Object.freeze(Object.defineProperty({__proto__:null,setSearchContext:l1,updateCatalogSegment:rk,updateFacetFilter:tk,updateFacetFilters:o1,updatePricebooks:u1,updateRangeFilter:nk,updateRangeFilters:a1,updateSearchQuery:ek},Symbol.toStringTag,{value:"Module"})),sk={categoryId:at.categoryId,categoryName:at.categoryIdProxy.categoryName||"",facetFilters:at.facetFilters,rangeFilters:at.rangeFilters,catalogSegment:at.catalogSegment,pricebooks:at.pricebooks},c1=B.createContext(sk),ok=({children:e})=>{const[t,n]=B.useState(at.categoryId),[r,s]=B.useState(at.categoryIdProxy.categoryName||""),[a,u]=B.useState(at.facetFilters||{}),[c,d]=B.useState(at.rangeFilters||[]),[f,p]=B.useState(at.catalogSegment||null),[m,b]=B.useState(at.pricebooks||null);B.useEffect(()=>{const _=({detail:A})=>{(A==null?void 0:A.property)==="categoryId"&&n(A.value),(A==null?void 0:A.property)==="categoryName"&&s(A.value),(A==null?void 0:A.property)==="facetFilters"&&u(A.value),(A==null?void 0:A.property)==="rangeFilters"&&d(A.value),(A==null?void 0:A.property)==="catalogSegment"&&p(A.value),(A==null?void 0:A.property)==="pricebooks"&&b(A.value)};return jg(_),()=>{$g(_)}},[]);const y=B.useMemo(()=>({categoryId:t,categoryName:r,facetFilters:a,rangeFilters:c,catalogSegment:f,pricebooks:m}),[t,r,a,c,f,m]);return x.jsx(c1.Provider,{value:y,children:e})},ak=()=>{const e=B.useContext(c1);if(!e)throw new Error("useBrowse must be used within a BrowseProvider");return e},uk={searchQuery:bt.query,facetFilters:bt.facetFilters,rangeFilters:bt.rangeFilters,catalogSegment:bt.catalogSegment,pricebooks:bt.pricebooks},d1=B.createContext(uk),lk=({children:e})=>{const[t,n]=B.useState(bt.query),[r,s]=B.useState(bt.facetFilters),[a,u]=B.useState(bt.rangeFilters),[c,d]=B.useState(bt.catalogSegment),[f,p]=B.useState(bt.pricebooks);B.useEffect(()=>{const b=({detail:y})=>{(y==null?void 0:y.property)==="query"&&n(y.value),(y==null?void 0:y.property)==="facetFilters"&&s(y.value),(y==null?void 0:y.property)==="rangeFilters"&&u(y.value),(y==null?void 0:y.property)==="catalogSegment"&&d(y.value),(y==null?void 0:y.property)==="pricebooks"&&p(y.value)};return Hg(b),()=>{zg(b)}},[]);const m=B.useMemo(()=>({searchQuery:t,facetFilters:r,rangeFilters:a,catalogSegment:c,pricebooks:f}),[t,r,a,c,f]);return x.jsx(d1.Provider,{value:m,children:e})},ck=()=>{const e=B.useContext(d1);if(!e)throw new Error("useSearch must be used within a SearchProvider");return e},dk={productId:mr.productId,pdpLink:mr.pdpLink},f1=B.createContext(dk),fk=({children:e})=>{const[t,n]=B.useState(mr.productId),[r,s]=B.useState(mr.pdpLink);B.useEffect(()=>{const u=({detail:c})=>{if((c==null?void 0:c.property)==="pdp-context"){const d=c.value;n(d.productId),s(d.pdpLink);return}(c==null?void 0:c.property)==="productId"&&n(c.value),(c==null?void 0:c.property)==="pdpLink"&&s(c.value)};return Vg(u),()=>{qg(u)}},[]);const a=B.useMemo(()=>({productId:t,pdpLink:r}),[t,r]);return x.jsx(f1.Provider,{value:a,children:e})},hk=()=>{const e=B.useContext(f1);if(!e)throw new Error("usePdp must be used within a PdpProvider");return e},h1=B.createContext({mode:Je.modeProxy.mode,entryType:Je.entryType,status:Je.statusProxy,dialogPosition:Je.dialogProxy.position,isDialogFullHeight:Je.dialogProxy.isFullHeight,dialogWidth:Je.dialogProxy.width,isModalFullscreen:Je.modalProxy.isFullscreen,previousComponentType:Je.statusProxy.type}),pk=({entryType:e,componentConfig:t,componentType:n,children:r})=>{const[s,a]=B.useState(e!=null?e:Je.entryTypeProxy.entryType),[u,c]=B.useState(Je.modeProxy.mode),[d,f]=B.useState({type:n||Je.statusProxy.type,isOpen:t&&"isOpen"in t?!!t.isOpen:Je.statusProxy.isOpen,isMinimized:t&&"isMinimized"in t?!!t.isMinimized:Je.statusProxy.isMinimized}),[p,m]=B.useState(Je.dialogProxy.position),[b,y]=B.useState(Je.dialogProxy.isFullHeight),[_,A]=B.useState(Je.dialogProxy.width),[v,w]=B.useState(Je.modalProxy.isFullscreen),N=B.useRef(!1),C=kv(d.type);B.useEffect(()=>{const Y=D=>{const{property:q,value:ne}=D.detail||{};if(!(!q||ne===void 0)){if(q==="mode"){c(ne);return}if(q==="entryType"){a(ne);return}if(q==="isMinimized"){f(de=>fe(F({},de),{isMinimized:ne}));return}if(q==="isOpen"){f(de=>fe(F({},de),{isOpen:ne}));return}if(q==="type"){f(de=>fe(F({},de),{type:ne}));return}if(q==="position"){m(ne);return}if(q==="isFullHeight"){y(ne);return}if(q==="width"){A(ne);return}if(q==="isFullscreen"){w(ne);return}}};return pv(Y),()=>{mv(Y)}},[]),ga(()=>{e&&pa(e)}),ga(()=>{if(N.current)return;N.current=!0;const Y=n||(t==null?void 0:t.type);Y&&dl(Y);const D=fv();t&&"isOpen"in t&&ti(!!t.isOpen),t&&"isMinimized"in t&&ma(!!t.isMinimized),D&&ma(!0)}),ga(()=>{if(!(t!=null&&t.options))return;const{dialogPosition:Y}=t.options;Y&&bf(Y),"dialogFullHeight"in t.options&&yv(!!t.options.dialogFullHeight),"dialogWidth"in t.options&&t.options.dialogWidth&&A(t.options.dialogWidth),"isModalFullscreen"in t.options&&Tf(!!t.options.isModalFullscreen)});const H=B.useMemo(()=>({mode:u,entryType:s,status:d,previousComponentType:C||"dialog",dialogPosition:p,isDialogFullHeight:b,dialogWidth:_,isModalFullscreen:v}),[u,s,d,C,p,b,_,v]);return x.jsx(h1.Provider,{value:H,children:r})},er=()=>{const e=B.useContext(h1);if(!e)throw new Error("useUIState must be used within a UIStateProvider");return e},p1=B.createContext(null),m1=B.createContext(null),Sf=()=>{const e=B.useContext(m1);if(!e)throw new Error("usePromptsExtensionDispatch must be used within a PromptsExtensionProvider");return e||{}},ni=()=>{const e=B.useContext(p1);if(!e)throw new Error("usePromptsExtensionState must be used within a PromptsExtensionProvider");return e||{}},Xs=()=>{const e=B.useContext(Q0);if(!e)throw new Error("useCopilotDispatch must be used within a CopilotProvider");return e},tr=()=>{const e=B.useContext(K0);if(!e)throw new Error("useCopilotState must be used within a CopilotProvider");return e},mk=({copilot:e})=>{const{logger:t,conversationHistory:n}=tt(),{isInline:r}=ni(),{addCopilotEvent:s,setConversationHistoryLoaded:a}=Xs(),{activeConversationId:u}=tr(),c=B.useCallback(f=>{e&&e.requestSessionInformation(p=>{t==null||t.log("Retrieved session information: ",p),f==null||f(p)})},[e,t]),d=B.useCallback((f,p)=>{e&&f.conversationId&&e.getConversationEvents(f,m=>{t==null||t.log("Retrieved conversation messages: ",m),p==null||p(m)})},[e,t]);return B.useEffect(()=>{if(r||!u)return;if(n.sinceHours===0||(n==null?void 0:n.limit)===0){a(!0);return}const f=3600*1e3*n.sinceHours,p=new Date(Date.now()-f).toISOString(),m={conversationId:u,since:p,excludeEvents:["done","error","connection_error","refined_browse","refined_search","conversation_reset"]};typeof n.limit=="number"&&(m.limit=n.limit),d(m,b=>{const y=[];[...b.reverse()||[]].forEach(A=>{var w;const v=b.find(N=>N.id===A.eventSourceId);(w=v==null?void 0:v.name)!=null&&w.endsWith("_suggestions")||(A.bypassHandlers=!0,y.unshift(A))}),y.forEach(A=>{s(A)}),a(!0)})},[t,r,u,d,s,a,n]),{getSessionInformation:c,getConversationMessages:d}},g1=B.createContext({copilot:null,messages:[],groupedMessages:[],isLoading:!1,isResponseLoading:()=>!1,handleAskCim:()=>{},handleSearch:()=>{},handleBrowse:()=>{},handlePdp:()=>{},handleSuggestion:()=>{},handleUserInput:()=>{},handleCancel:()=>{},resetConversation:()=>{},getSessionInformation:()=>{},getConversationMessages:()=>{}}),gk=({apiKey:e,apiToken:t,baseUrl:n,customerId:r,tenantId:s,isDevelopment:a,onConnect:u,onRefinedSearch:c,onRefinedBrowse:d,children:f})=>{const{logger:p,clientContext:m,baseCatalogParams:b}=tt(),an=ck(),{searchQuery:y}=an,_=fn(an,["searchQuery"]),Fn=ak(),{categoryId:A}=Fn,v=fn(Fn,["categoryId"]),{productId:w,pdpLink:N}=hk(),{setCopilot:C,setConnected:H,resetCopilot:Y,resetCopilotState:D,addCopilotEvent:q,removeLoadingMessage:ne,handleCopilotRequestAck:de,setActiveConversationId:V,setConversationIds:se,setAskCimPrompts:pe}=Xs(),{connected:ve,copilot:re,messages:ae,groupedMessages:xe,loadingMessages:oe,askCimPrompts:Q}=tr(),{status:ie,entryType:k}=er(),{isInline:R}=ni(),{getConversationMessages:ee,getSessionInformation:O}=mk({copilot:re}),_e=B.useMemo(()=>oe.size>0,[oe]),Ue=B.useCallback(we=>oe.has(we),[oe]),ye=B.useCallback(({query:we,facetFilters:Pe,rangeFilters:Me,catalogSegment:rt,pricebooks:pt,userPrompt:J,imageFile:ge})=>{if(!re){p==null||p.error("Copilot is not initialized");return}if(!we)return;const Ce={searchParams:{query:we}};J&&(Ce.userPrompt=J),ge&&(Ce.attachments={image:ge}),Pe&&Object.keys(Pe).length>0&&(Ce.searchParams.facetFilters=Pe),Me&&Me.length>0&&(Ce.searchParams.rangeFilters=Me),rt&&(Ce.searchParams.catalogSegment=rt),pt&&(Ce.searchParams.pricebooks=pt),m&&(Ce.clientContext=m),pa("search"),re.search(Ce,qe=>{const Ie=F({},qe);de(Ie)})},[p,de,re,m]),Le=B.useCallback(({categoryId:we,categoryName:Pe,facetFilters:Me,rangeFilters:rt,catalogSegment:pt,pricebooks:J,userPrompt:ge,imageFile:Ce})=>{if(!re){p==null||p.error("Copilot is not initialized");return}const qe=Me&&Object.keys(Me).length>0;if(we===""&&!qe){p==null||p.error("Browse event must include facetFilters when categoryId is empty");return}const Ie={browseParams:{categoryId:we||""}};ge&&(Ie.userPrompt=ge),Ce&&(Ie.attachments={image:Ce}),qe&&(Ie.browseParams.facetFilters=Me),rt&&rt.length>0&&(Ie.browseParams.rangeFilters=rt),pt&&(Ie.browseParams.catalogSegment=pt),Array.isArray(J)&&J.length>0&&(Ie.browseParams.pricebooks=J),(m||Pe)&&(Ie.clientContext={},m&&(Ie.clientContext=F({},m)),Pe&&(Ie.clientContext.cimLabel=Pe)),pa("browse"),re.browse(Ie,ut=>{var Vr;const qt=F({},ut),Ht=((Vr=qt.request)==null?void 0:Vr.clientContext)||{},un=(Ht==null?void 0:Ht.cimLabel)||Pe;un&&qt.request&&(qt.request.label=un),de(qt)})},[p,de,re,m]),He=B.useCallback(({productId:we,productName:Pe,pdpLink:Me,userPrompt:rt,imageFile:pt})=>{if(!re){p==null||p.error("Copilot is not initialized");return}if(!we)return;const J={productId:we};rt&&(J.userPrompt=rt),Me&&(J.pdpLink=Me),pt&&(J.attachments={image:pt}),(m||Pe)&&(J.clientContext={},m&&(J.clientContext=F({},m)),Pe&&(J.clientContext.cimLabel=Pe)),b&&(J.baseCatalogParams=b),pa("pdp"),re.productView(J,ge=>{var ut;const Ce=F({},ge),qe=((ut=Ce.request)==null?void 0:ut.clientContext)||{},Ie=(qe==null?void 0:qe.cimLabel)||Pe;Ie&&Ce.request&&(Ce.request.label=Ie),de(Ce)})},[p,re,de,m,b]),Ye=B.useCallback(({userPrompt:we,imageFile:Pe})=>{if(!re){p==null||p.error("Copilot is not initialized");return}if(!we)return;const Me={userPrompt:we};Pe&&(Me.attachments={image:Pe}),m&&(Me.clientContext=m),b&&(Me.baseCatalogParams=b),re.askCim(Me,rt=>{const pt=F({},rt);de(pt)})},[p,re,de,m,b]),ht=B.useCallback(we=>{q(we),c==null||c(we)},[q,c]),Vt=B.useCallback(we=>{q(we),d==null||d(we)},[q,d]),on=B.useCallback(we=>{u==null||u(we),H(!0)},[u,H]);B.useEffect(()=>{!re||!ve||!ie.isOpen||mn.size>0&&mn.processQueue(we=>{if(we.context==="search"){const Pe=F({},we.payload);l1(Pe)}if(we.context==="browse"){const Pe=F({},we.payload);n1(Pe)}if(we.context==="pdp"){const Pe=F({},we.payload);r1(Pe)}})},[ie.isOpen,re,ve]);const _r=B.useCallback(we=>{const Pe=Me=>{const rt=fe(F({},Me),{id:Me.inquiryLinkId||Me.id});q(rt)};we.on("connect_ack",on),we.on("partial_inquiry",Pe),we.on("display_products",q),we.on("progress",q),we.on("refined_search",ht),we.on("refined_browse",Vt),we.on("done",Me=>{ne(Me.eventSourceId)}),we.on("error",Me=>{q(Me),ne(Me.eventSourceId)}),we.onDisconnect(Me=>{const rt=["io server disconnect","transport error","server shutting down"];if(p==null||p.log("Connection disconnected with reason: ",Me),!rt.includes(Me)){H(!1);return}p==null||p.log("De-registering event listeners");const pt=new Date().toISOString();q({name:"error",message:"Connection was lost. Please try again.",createdAt:pt,id:`error-${pt}`,sessionId:"session"}),we.off()})},[p,H,ne,ht,Vt,q,on]);B.useEffect(()=>{if(!re)return;const we=Pe=>{if(!R){if(!Pe.message&&Pe.eventSourceId&&Pe.eventSourceId===Q.requestId){pe({requestId:Pe.eventSourceId,message:Pe});return}q(Pe)}};return re.on("follow_up",we),()=>{re.off("follow_up",we)}},[re,ae,Q.requestId,R,q,pe]),B.useEffect(()=>{if(!re)return;const we=Pe=>{if(R)return;const Me=fe(F({},Pe),{id:Pe.inquiryLinkId||Pe.id});q(Me)};return re.on("inquiry",we),()=>{re.off("inquiry",we)}},[re,R,q]),ga(()=>{let we;n?we=n:we=a?"https://staging.copilot.search.cimulate.ai":"https://prod.copilot.search.cimulate.ai";const Pe={baseUrl:we};e?Pe.apiKey=e:t&&(Pe.apiToken=t),r&&(Pe.customerId=r),s&&(Pe.tenantId=s);const Me=new Xw(Pe);return C(Me),_r(Me),Me.connect(),Me.requestSessionInformation(rt=>{p==null||p.log("Session Information: ",rt);const{activeConversationId:pt,conversationIds:J}=rt.data||{};pt&&V(pt),J!=null&&J.length&&se(J)}),()=>{Me.disconnect(),Me.off(),Y()}});const sr=B.useCallback(we=>{if(!re)return;const Pe={eventId:we,reason:"User cancelled the request"};re.cancelRequest(Pe,Me=>{q(Me),ne(we)})},[q,ne,re]),Zt=B.useCallback(()=>{re&&re.conversationReset({},we=>{D(),q(we),re.requestSessionInformation(Pe=>{p==null||p.log("Session Information: ",Pe);const{activeConversationId:Me,conversationIds:rt}=Pe.data||{};Me&&V(Me),rt!=null&&rt.length&&se(rt)})})},[re,p,q,D,V,se]),Ve=B.useCallback((we,Pe)=>{if(!we)return;const Me={userPrompt:we};switch(Pe&&(Me.imageFile=Pe),k){case"ask_cim":Ye(Me);return;case"search":y?ye(F(F({query:y},_),Me)):Ye(Me);return;case"browse":Le(F(F({categoryId:A},v),Me));return;case"pdp":w?He(F({productId:w,pdpLink:N||""},Me)):Ye(Me);return}},[k,y,_,ye,Ye,A,v,Le,He,w,N]),kt=B.useCallback((we,Pe)=>{var ge,Ce,qe;const rt=we.params.userPrompt||"";if(!rt)return;const pt=ae.find(Ie=>Ie.id===Pe);if(!pt)return;const J=pt.name.replace("_suggestions","");if(J==="ask_cim"){Ye({userPrompt:rt});return}if(J==="copilot_search"){const Ie=((ge=pt.request)==null?void 0:ge.searchParams)||{},qt=Ie.query===y;ye(fe(F({query:Ie.query||y},qt?_:{}),{userPrompt:rt}));return}if(J==="copilot_browse"){const Ie=pt.request,ut=Ie.browseParams||{},Ht=ut.categoryId===A,un=((Ce=Ie.clientContext)==null?void 0:Ce.cimLabel)||"";Le(fe(F({categoryId:ut.categoryId||A||""},Ht?v:{}),{categoryName:un,userPrompt:rt}));return}if(J==="product_view"){const Ie=pt.request||{},ut=Ie.productId,qt=ut===w,Ht=((qe=Ie.clientContext)==null?void 0:qe.cimLabel)||"";let un="";qt?un=N||"":un=Ie.pdpLink||"",He({productId:ut||w,pdpLink:un,productName:Ht,userPrompt:rt})}},[ae,y,_,ye,Ye,A,v,Le,He,w,N]),vn=B.useMemo(()=>({copilot:re,messages:ae,groupedMessages:xe,isLoading:_e,isResponseLoading:Ue,handleAskCim:Ye,handleSearch:ye,handleBrowse:Le,handlePdp:He,handleUserInput:Ve,handleSuggestion:kt,handleCancel:sr,resetConversation:Zt,getSessionInformation:O,getConversationMessages:ee}),[re,ae,xe,_e,Ue,Ye,ye,Le,He,Ve,kt,sr,Zt,O,ee]);return x.jsx(g1.Provider,{value:vn,children:f})},E1=()=>{const{copilot:e}=tr(),{addCopilotEvent:t}=Xs();return{getCopilotSuggestions:B.useCallback((r,s,a)=>{if(!e||!s||!r)return;const u=c=>{t(c),a(c)};switch(s){case"ask_cim":e.askCimSuggestions(r,u);break;case"search":e.searchSuggestions({searchParams:r},u);break;case"browse":e.browseSuggestions({browseParams:r},u);break;case"pdp":e.productViewSuggestions({productId:r.productId},u);break}},[e,t])}},Ir=()=>{const e=B.useContext(g1);if(!e)throw new Error("useCopilot must be used within a CopilotProvider");return e},Ek=()=>{const{copilot:e,activeConversationId:t,askCimPrompts:n,conversationHistoryLoaded:r}=tr(),{entryType:s}=er(),{resetCopilotState:a,addCopilotEvent:u,setAskCimPrompts:c}=Xs(),{handleSearch:d,handleBrowse:f,handlePdp:p,resetConversation:m,getSessionInformation:b,getConversationMessages:y}=Ir(),{getCopilotSuggestions:_}=E1();B.useEffect(()=>{!e||!s||!t||!r||n.requestId||s==="ask_cim"&&_({},s,N=>{c({requestId:N.id,message:null})})},[e,t,n.requestId,s,r,_,c]);const A=B.useCallback(({query:N})=>{if(!e||!N)return;const{facetFilters:C}=bt.facetFiltersProxy,{rangeFilters:H}=bt.rangeFiltersProxy,{catalogSegment:Y}=bt.catalogSegmentProxy,{pricebooks:D}=bt.pricebooksProxy,q={query:N};q.facetFilters=C||{},q.rangeFilters=H||[],q.catalogSegment=Y||"",q.pricebooks=D||[],d(F({},q))},[e,d]),v=B.useCallback(({categoryId:N})=>{if(!e)return;const C=at.categoryIdProxy.categoryName,{facetFilters:H}=at.facetFiltersProxy,{rangeFilters:Y}=at.rangeFiltersProxy,{catalogSegment:D}=at.catalogSegmentProxy,{pricebooks:q}=at.pricebooksProxy,ne={categoryId:N};ne.categoryName=C||"",ne.facetFilters=H||{},ne.rangeFilters=Y||[],ne.catalogSegment=D||"",ne.pricebooks=q||[],f(F({},ne))},[e,f]),w=B.useCallback(({productId:N})=>{if(!e||!N)return;const C={productId:N,pdpLink:mr.pdpLink,productName:mr.proxy.productName||""};p(C)},[e,p]);return B.useEffect(()=>{const N=({detail:C})=>{(C==null?void 0:C.property)==="query"&&A({query:C.value})};return Hg(N),()=>{zg(N)}},[A]),B.useEffect(()=>{const N=({detail:C})=>{if((C==null?void 0:C.property)==="pdp-context"){const H=C.value;w({productId:H.productId});return}(C==null?void 0:C.property)==="productId"&&w({productId:C.value})};return Vg(N),()=>{qg(N)}},[w]),B.useEffect(()=>{const N=({detail:C})=>{(C==null?void 0:C.property)==="categoryId"&&v({categoryId:C.value})};return jg(N),()=>{$g(N)}},[v]),B.useEffect(()=>{const N=({detail:C})=>{if((C==null?void 0:C.event)==bi.RESET_CONVERSATION&&m(),(C==null?void 0:C.event)==bi.GET_SESSION_INFORMATION){const H=C.value.callback;b(H)}if((C==null?void 0:C.event)==bi.GET_CONVERSATION_MESSAGES){const{payload:H,callback:Y}=C.value;if(!H.conversationId||typeof Y!="function")return;y(H,Y)}if((C==null?void 0:C.event)==bi.LOAD_CONVERSATION){const H=C.value;if(!H.conversationId)return;y(H,D=>{a(),D.forEach(q=>{u(q)})})}};return Rv(N),()=>{Lv(N)}},[m,b,y,a,u]),null},yk=({apiKey:e,apiToken:t,baseUrl:n,customerId:r,tenantId:s,isDevelopment:a,onConnect:u,onRefinedSearch:c,onRefinedBrowse:d,children:f})=>x.jsxs(gk,{apiKey:e,apiToken:t,baseUrl:n,customerId:r,tenantId:s,isDevelopment:a,onConnect:u,onRefinedSearch:c,onRefinedBrowse:d,children:[x.jsx(Ek,{}),f]}),Tk=({children:e,dispatch:t})=>{const n=B.useCallback(_=>{t({type:gt.SET_PROMPTS_EXTENSION_INITIALIZED,payload:_})},[t]),r=B.useCallback(_=>{t({type:gt.SET_PROMPTS_EXTENSION_OPEN,payload:_})},[t]),s=B.useCallback(_=>{t({type:gt.SET_PROMPTS_EXTENSION_INLINE,payload:_})},[t]),a=B.useCallback(_=>{t({type:gt.SET_PROMPTS_EXTENSION_ELEMENT_ID,payload:_})},[t]),u=B.useCallback(_=>{t({type:gt.SET_PROMPTS_EXTENSION_ENTRY_TYPE,payload:_})},[t]),c=B.useCallback(_=>{t({type:gt.SET_PROMPTS_EXTENSION_ACTIVE_PROMPTS_ID,payload:_})},[t]),d=B.useCallback(_=>{t({type:gt.SET_PROMPTS_EXTENSION_USER_PROMPT,payload:_})},[t]),f=B.useCallback(_=>{t({type:gt.SET_PROMPTS_EXTENSION_PARAMS,payload:_})},[t]),p=B.useCallback(_=>{t({type:gt.SET_PROMPTS_EXTENSION_PROMPTS_MESSAGE,payload:_})},[t]),m=B.useCallback(_=>{t({type:gt.SET_PROMPTS_EXTENSION_RESPONSE_MESSAGE,payload:_})},[t]),b=B.useCallback(_=>{t({type:gt.SET_PROMPTS_EXTENSION_RESPONSE_LOADING,payload:_})},[t]),y=B.useMemo(()=>({setIsInitialized:n,setIsOpen:r,setIsInline:s,setElementId:a,setEntryType:u,setActivePromptsId:c,setUserPrompt:d,setParams:f,setPromptsMessage:p,setResponseMessage:m,setIsResponseLoading:b}),[n,r,s,a,u,c,d,f,p,m,b]);return x.jsx(m1.Provider,{value:y,children:e})},bk=(e,t)=>{const{type:n,payload:r}=t;switch(n){case gt.SET_PROMPTS_EXTENSION_INITIALIZED:e.isInitialized=r;break;case gt.SET_PROMPTS_EXTENSION_OPEN:e.isOpen=r;break;case gt.SET_PROMPTS_EXTENSION_INLINE:e.isInline=r;break;case gt.SET_PROMPTS_EXTENSION_ELEMENT_ID:e.elementId=r;break;case gt.SET_PROMPTS_EXTENSION_ENTRY_TYPE:e.entryType=r;break;case gt.SET_PROMPTS_EXTENSION_PARAMS:e.params=r;break;case gt.RESET_PROMPTS_EXTENSION_PARAMS:e.params=null;break;case gt.SET_PROMPTS_EXTENSION_USER_PROMPT:e.userPrompt=r;break;case gt.SET_PROMPTS_EXTENSION_ACTIVE_PROMPTS_ID:e.activePromptsId=r;break;case gt.RESET_PROMPTS_EXTENSION_ACTIVE_PROMPTS_ID:e.activePromptsId=null;break;case gt.SET_PROMPTS_EXTENSION_PROMPTS_MESSAGE:e.promptsMessage=r;break;case gt.RESET_PROMPTS_EXTENSION_PROMPTS_MESSAGE:e.promptsMessage=null;break;case gt.SET_PROMPTS_EXTENSION_RESPONSE_MESSAGE:e.responseMessage=r;break;case gt.RESET_PROMPTS_EXTENSION_RESPONSE_MESSAGE:e.responseMessage=null;break;case gt.SET_PROMPTS_EXTENSION_RESPONSE_LOADING:e.isResponseLoading=r;break}},_k=({promptsConfig:e,children:t})=>{const[n,r]=Y0(bk,fe(F(F({},J0),e||{}),{staticQuestions:L0((e==null?void 0:e.staticQuestions)||[])}));return x.jsx(p1.Provider,{value:n,children:x.jsx(Tk,{dispatch:r,children:t})})},y1=({mode:e,apiKey:t,apiToken:n,baseUrl:r,customerId:s,tenantId:a,logoUrl:u,headerText:c,headerConfig:d,theme:f,openLinksInNewTab:p,globalClassName:m,isDevelopment:b=!1,componentType:y,componentConfig:_,entryType:A,initialEntry:v,entryMessage:w,disclaimerText:N,disclaimerMarkdown:C,clientContext:H,baseCatalogParams:Y,searchPlaceholder:D,searchButtonLabel:q,searchConfig:ne,suggestionButtonConfig:de,messageAlignment:V,autoScroll:se,promptsConfig:pe,resetConversationMessage:ve,conversationHistory:re,onConnect:ae,onCopilotEvent:xe,onRefinedSearch:oe,onRefinedBrowse:Q,__features:ie,children:k})=>{const R=v==null?void 0:v.params;return x.jsx(cv,{mode:e,baseUrl:r,apiKey:t,apiToken:n,customerId:s,tenantId:a,logoUrl:u,headerText:c,headerConfig:d,entryMessage:w,staticQuestions:L0(R==null?void 0:R.staticQuestions),staticQuestionsStrategy:R==null?void 0:R.staticQuestionsStrategy,theme:f,globalClassName:m,openLinksInNewTab:p,searchPlaceholder:D,searchButtonLabel:q,searchConfig:ne,suggestionButtonConfig:de,messageAlignment:V,autoScroll:se,componentConfig:_,clientContext:H,baseCatalogParams:Y,disclaimerMarkdown:C,disclaimerText:N,resetConversationMessage:ve,conversationHistory:re,isDevelopment:b,__features:ie,children:x.jsx(pk,{entryType:A!=null?A:v==null?void 0:v.type,componentConfig:_,componentType:y,children:x.jsx(_v,{onCopilotEvent:xe,children:x.jsx(fk,{children:x.jsx(ok,{children:x.jsx(lk,{children:x.jsx(_k,{promptsConfig:pe,children:x.jsx(yk,{apiKey:t,apiToken:n,baseUrl:r,customerId:s,tenantId:a,isDevelopment:b,entryType:A,onConnect:ae,onRefinedSearch:oe,onRefinedBrowse:Q,onCopilotEvent:xe,children:k})})})})})})})})};var xf={exports:{}},In={},wf={exports:{}},Af={};var T1;function Sk(){return T1||(T1=1,(function(e){function t(Q,ie){var k=Q.length;Q.push(ie);e:for(;0<k;){var R=k-1>>>1,ee=Q[R];if(0<s(ee,ie))Q[R]=ie,Q[k]=ee,k=R;else break e}}function n(Q){return Q.length===0?null:Q[0]}function r(Q){if(Q.length===0)return null;var ie=Q[0],k=Q.pop();if(k!==ie){Q[0]=k;e:for(var R=0,ee=Q.length,O=ee>>>1;R<O;){var _e=2*(R+1)-1,Ue=Q[_e],ye=_e+1,Le=Q[ye];if(0>s(Ue,k))ye<ee&&0>s(Le,Ue)?(Q[R]=Le,Q[ye]=k,R=ye):(Q[R]=Ue,Q[_e]=k,R=_e);else if(ye<ee&&0>s(Le,k))Q[R]=Le,Q[ye]=k,R=ye;else break e}}return ie}function s(Q,ie){var k=Q.sortIndex-ie.sortIndex;return k!==0?k:Q.id-ie.id}if(typeof performance=="object"&&typeof performance.now=="function"){var a=performance;e.unstable_now=function(){return a.now()}}else{var u=Date,c=u.now();e.unstable_now=function(){return u.now()-c}}var d=[],f=[],p=1,m=null,b=3,y=!1,_=!1,A=!1,v=typeof setTimeout=="function"?setTimeout:null,w=typeof clearTimeout=="function"?clearTimeout:null,N=typeof setImmediate!="undefined"?setImmediate:null;typeof navigator!="undefined"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function C(Q){for(var ie=n(f);ie!==null;){if(ie.callback===null)r(f);else if(ie.startTime<=Q)r(f),ie.sortIndex=ie.expirationTime,t(d,ie);else break;ie=n(f)}}function H(Q){if(A=!1,C(Q),!_)if(n(d)!==null)_=!0,xe(Y);else{var ie=n(f);ie!==null&&oe(H,ie.startTime-Q)}}function Y(Q,ie){_=!1,A&&(A=!1,w(ne),ne=-1),y=!0;var k=b;try{for(C(ie),m=n(d);m!==null&&(!(m.expirationTime>ie)||Q&&!se());){var R=m.callback;if(typeof R=="function"){m.callback=null,b=m.priorityLevel;var ee=R(m.expirationTime<=ie);ie=e.unstable_now(),typeof ee=="function"?m.callback=ee:m===n(d)&&r(d),C(ie)}else r(d);m=n(d)}if(m!==null)var O=!0;else{var _e=n(f);_e!==null&&oe(H,_e.startTime-ie),O=!1}return O}finally{m=null,b=k,y=!1}}var D=!1,q=null,ne=-1,de=5,V=-1;function se(){return!(e.unstable_now()-V<de)}function pe(){if(q!==null){var Q=e.unstable_now();V=Q;var ie=!0;try{ie=q(!0,Q)}finally{ie?ve():(D=!1,q=null)}}else D=!1}var ve;if(typeof N=="function")ve=function(){N(pe)};else if(typeof MessageChannel!="undefined"){var re=new MessageChannel,ae=re.port2;re.port1.onmessage=pe,ve=function(){ae.postMessage(null)}}else ve=function(){v(pe,0)};function xe(Q){q=Q,D||(D=!0,ve())}function oe(Q,ie){ne=v(function(){Q(e.unstable_now())},ie)}e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(Q){Q.callback=null},e.unstable_continueExecution=function(){_||y||(_=!0,xe(Y))},e.unstable_forceFrameRate=function(Q){0>Q||125<Q?console.error("forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"):de=0<Q?Math.floor(1e3/Q):5},e.unstable_getCurrentPriorityLevel=function(){return b},e.unstable_getFirstCallbackNode=function(){return n(d)},e.unstable_next=function(Q){switch(b){case 1:case 2:case 3:var ie=3;break;default:ie=b}var k=b;b=ie;try{return Q()}finally{b=k}},e.unstable_pauseExecution=function(){},e.unstable_requestPaint=function(){},e.unstable_runWithPriority=function(Q,ie){switch(Q){case 1:case 2:case 3:case 4:case 5:break;default:Q=3}var k=b;b=Q;try{return ie()}finally{b=k}},e.unstable_scheduleCallback=function(Q,ie,k){var R=e.unstable_now();switch(typeof k=="object"&&k!==null?(k=k.delay,k=typeof k=="number"&&0<k?R+k:R):k=R,Q){case 1:var ee=-1;break;case 2:ee=250;break;case 5:ee=1073741823;break;case 4:ee=1e4;break;default:ee=5e3}return ee=k+ee,Q={id:p++,callback:ie,priorityLevel:Q,startTime:k,expirationTime:ee,sortIndex:-1},k>R?(Q.sortIndex=k,t(f,Q),n(d)===null&&Q===n(f)&&(A?(w(ne),ne=-1):A=!0,oe(H,k-R))):(Q.sortIndex=ee,t(d,Q),_||y||(_=!0,xe(Y))),Q},e.unstable_shouldYield=se,e.unstable_wrapCallback=function(Q){var ie=b;return function(){var k=b;b=ie;try{return Q.apply(this,arguments)}finally{b=k}}}})(Af)),Af}var b1;function xk(){return b1||(b1=1,wf.exports=Sk()),wf.exports}var _1;function wk(){if(_1)return In;_1=1;var e=fr(),t=xk();function n(i){for(var o="https://reactjs.org/docs/error-decoder.html?invariant="+i,l=1;l<arguments.length;l++)o+="&args[]="+encodeURIComponent(arguments[l]);return"Minified React error #"+i+"; visit "+o+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}var r=new Set,s={};function a(i,o){u(i,o),u(i+"Capture",o)}function u(i,o){for(s[i]=o,i=0;i<o.length;i++)r.add(o[i])}var c=!(typeof window=="undefined"||typeof window.document=="undefined"||typeof window.document.createElement=="undefined"),d=Object.prototype.hasOwnProperty,f=/^[:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD][:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\-.0-9\u00B7\u0300-\u036F\u203F-\u2040]*$/,p={},m={};function b(i){return d.call(m,i)?!0:d.call(p,i)?!1:f.test(i)?m[i]=!0:(p[i]=!0,!1)}function y(i,o,l,h){if(l!==null&&l.type===0)return!1;switch(typeof o){case"function":case"symbol":return!0;case"boolean":return h?!1:l!==null?!l.acceptsBooleans:(i=i.toLowerCase().slice(0,5),i!=="data-"&&i!=="aria-");default:return!1}}function _(i,o,l,h){if(o===null||typeof o=="undefined"||y(i,o,l,h))return!0;if(h)return!1;if(l!==null)switch(l.type){case 3:return!o;case 4:return o===!1;case 5:return isNaN(o);case 6:return isNaN(o)||1>o}return!1}function A(i,o,l,h,E,T,S){this.acceptsBooleans=o===2||o===3||o===4,this.attributeName=h,this.attributeNamespace=E,this.mustUseProperty=l,this.propertyName=i,this.type=o,this.sanitizeURL=T,this.removeEmptyString=S}var v={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(i){v[i]=new A(i,0,!1,i,null,!1,!1)}),[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(i){var o=i[0];v[o]=new A(o,1,!1,i[1],null,!1,!1)}),["contentEditable","draggable","spellCheck","value"].forEach(function(i){v[i]=new A(i,2,!1,i.toLowerCase(),null,!1,!1)}),["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(i){v[i]=new A(i,2,!1,i,null,!1,!1)}),"allowFullScreen async autoFocus autoPlay controls default defer disabled disablePictureInPicture disableRemotePlayback formNoValidate hidden loop noModule noValidate open playsInline readOnly required reversed scoped seamless itemScope".split(" ").forEach(function(i){v[i]=new A(i,3,!1,i.toLowerCase(),null,!1,!1)}),["checked","multiple","muted","selected"].forEach(function(i){v[i]=new A(i,3,!0,i,null,!1,!1)}),["capture","download"].forEach(function(i){v[i]=new A(i,4,!1,i,null,!1,!1)}),["cols","rows","size","span"].forEach(function(i){v[i]=new A(i,6,!1,i,null,!1,!1)}),["rowSpan","start"].forEach(function(i){v[i]=new A(i,5,!1,i.toLowerCase(),null,!1,!1)});var w=/[\-:]([a-z])/g;function N(i){return i[1].toUpperCase()}"accent-height alignment-baseline arabic-form baseline-shift cap-height clip-path clip-rule color-interpolation color-interpolation-filters color-profile color-rendering dominant-baseline enable-background fill-opacity fill-rule flood-color flood-opacity font-family font-size font-size-adjust font-stretch font-style font-variant font-weight glyph-name glyph-orientation-horizontal glyph-orientation-vertical horiz-adv-x horiz-origin-x image-rendering letter-spacing lighting-color marker-end marker-mid marker-start overline-position overline-thickness paint-order panose-1 pointer-events rendering-intent shape-rendering stop-color stop-opacity strikethrough-position strikethrough-thickness stroke-dasharray stroke-dashoffset stroke-linecap stroke-linejoin stroke-miterlimit stroke-opacity stroke-width text-anchor text-decoration text-rendering underline-position underline-thickness unicode-bidi unicode-range units-per-em v-alphabetic v-hanging v-ideographic v-mathematical vector-effect vert-adv-y vert-origin-x vert-origin-y word-spacing writing-mode xmlns:xlink x-height".split(" ").forEach(function(i){var o=i.replace(w,N);v[o]=new A(o,1,!1,i,null,!1,!1)}),"xlink:actuate xlink:arcrole xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(i){var o=i.replace(w,N);v[o]=new A(o,1,!1,i,"http://www.w3.org/1999/xlink",!1,!1)}),["xml:base","xml:lang","xml:space"].forEach(function(i){var o=i.replace(w,N);v[o]=new A(o,1,!1,i,"http://www.w3.org/XML/1998/namespace",!1,!1)}),["tabIndex","crossOrigin"].forEach(function(i){v[i]=new A(i,1,!1,i.toLowerCase(),null,!1,!1)}),v.xlinkHref=new A("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1),["src","href","action","formAction"].forEach(function(i){v[i]=new A(i,1,!1,i.toLowerCase(),null,!0,!0)});function C(i,o,l,h){var E=v.hasOwnProperty(o)?v[o]:null;(E!==null?E.type!==0:h||!(2<o.length)||o[0]!=="o"&&o[0]!=="O"||o[1]!=="n"&&o[1]!=="N")&&(_(o,l,E,h)&&(l=null),h||E===null?b(o)&&(l===null?i.removeAttribute(o):i.setAttribute(o,""+l)):E.mustUseProperty?i[E.propertyName]=l===null?E.type===3?!1:"":l:(o=E.attributeName,h=E.attributeNamespace,l===null?i.removeAttribute(o):(E=E.type,l=E===3||E===4&&l===!0?"":""+l,h?i.setAttributeNS(h,o,l):i.setAttribute(o,l))))}var H=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,Y=Symbol.for("react.element"),D=Symbol.for("react.portal"),q=Symbol.for("react.fragment"),ne=Symbol.for("react.strict_mode"),de=Symbol.for("react.profiler"),V=Symbol.for("react.provider"),se=Symbol.for("react.context"),pe=Symbol.for("react.forward_ref"),ve=Symbol.for("react.suspense"),re=Symbol.for("react.suspense_list"),ae=Symbol.for("react.memo"),xe=Symbol.for("react.lazy"),oe=Symbol.for("react.offscreen"),Q=Symbol.iterator;function ie(i){return i===null||typeof i!="object"?null:(i=Q&&i[Q]||i["@@iterator"],typeof i=="function"?i:null)}var k=Object.assign,R;function ee(i){if(R===void 0)try{throw Error()}catch(l){var o=l.stack.trim().match(/\n( *(at )?)/);R=o&&o[1]||""}return`
|
|
11
11
|
`+R+i}var O=!1;function _e(i,o){if(!i||O)return"";O=!0;var l=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{if(o)if(o=function(){throw Error()},Object.defineProperty(o.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(o,[])}catch(Z){var h=Z}Reflect.construct(i,[],o)}else{try{o.call()}catch(Z){h=Z}i.call(o.prototype)}else{try{throw Error()}catch(Z){h=Z}i()}}catch(Z){if(Z&&h&&typeof Z.stack=="string"){for(var E=Z.stack.split(`
|
|
12
12
|
`),T=h.stack.split(`
|
|
13
13
|
`),S=E.length-1,L=T.length-1;1<=S&&0<=L&&E[S]!==T[L];)L--;for(;1<=S&&0<=L;S--,L--)if(E[S]!==T[L]){if(S!==1||L!==1)do if(S--,L--,0>L||E[S]!==T[L]){var U=`
|