athena-xai-chat 1.0.76 → 1.0.78
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.
|
@@ -2553,8 +2553,8 @@ class J7 {
|
|
|
2553
2553
|
bubbles: !0
|
|
2554
2554
|
})
|
|
2555
2555
|
));
|
|
2556
|
-
const v = this._extractTopTags(this._answers)
|
|
2557
|
-
|
|
2556
|
+
const v = this._extractTopTags(this._answers);
|
|
2557
|
+
this._answers.findIndex((l) => l.love_language) === -1 && this._answers.push(v), this._answers = this._answers.map(({ tag: l, ...x }) => x);
|
|
2558
2558
|
const z = C9(
|
|
2559
2559
|
this._userId,
|
|
2560
2560
|
JSON.stringify(this._answers),
|
|
@@ -2817,10 +2817,9 @@ let Qe = class extends k {
|
|
|
2817
2817
|
};
|
|
2818
2818
|
Qe.styles = dA`
|
|
2819
2819
|
.athena-xai-select-chat__initial-outer-container {
|
|
2820
|
-
height:
|
|
2820
|
+
height: 85dvh;
|
|
2821
2821
|
background: #FFFFFF;
|
|
2822
2822
|
display: flex;
|
|
2823
|
-
padding-top: 68px;
|
|
2824
2823
|
overflow: hidden;
|
|
2825
2824
|
}
|
|
2826
2825
|
|
|
@@ -737,7 +737,7 @@ Ces cadeaux viennent du cœur:`}}}},$t=A=>`${I.api.baseUrl}${I.api.endpoints[A]}
|
|
|
737
737
|
</div>
|
|
738
738
|
</div>
|
|
739
739
|
`}};ae.styles=Cf,Pt([Y()],ae.prototype,"message",2),Pt([Y()],ae.prototype,"messageRole",2),ae=Pt([eA("athena-xai-chat-message")],ae);class Vr{constructor(e){this._messages=[],this._isLoading=!1,this._image="",this._previewImage="",this._isGuardrailsOn=I.features.guardrails.defaultState,this.lastAssistantIndex=null,this.userId=et(),this.host=e,e.addController(this)}get messages(){return this._messages}set messages(e){this._messages=e,this.host.requestUpdate()}get isLoading(){return this._isLoading}set isLoading(e){this._isLoading=e,this.host.requestUpdate()}get image(){return this._image}set image(e){this._image=e,this.host.requestUpdate()}get previewImage(){return this._previewImage}set previewImage(e){this._previewImage=e,this.host.requestUpdate()}get isGuardrailsOn(){return this._isGuardrailsOn}set isGuardrailsOn(e){this._isGuardrailsOn=e,this.host.requestUpdate()}hostConnected(){}hostDisconnected(){}hostUpdate(){}addMessage(e,t,n=""){this.messages=[...this._messages,{role:e,content:t,productName:n}],e==="assistant"&&(this.lastAssistantIndex===null||this.lastAssistantIndex<this._messages.length-1)&&(this.lastAssistantIndex=this._messages.length-1)}updateLastMessage(e,t,n){if(!this._messages.length)return;const f=this._messages.length-1,r={...this._messages[f]};t&&(r.role=t),r.content=typeof e=="string"&&n?r.content+e:e,this.messages=[...this._messages.slice(0,f),r]}async handleImageUpload(e){try{const{base64:t,previewUrl:n}=await Ar(e);this.image=t,this.previewImage=n}catch(t){console.error(`Image upload failed: ${t}`)}}clearImage(){this.image="",this.previewImage=""}async sendMessage(e,t){if(window.dispatchEvent(new Event("clear-picture")),!this.isLoading&&!(!e.trim()&&!t)){this.isLoading=!0;try{e&&this.addMessage("user",e),t&&this.addMessage("user_image",this.previewImage),this.addMessage("assistant","loader");const n=en(this.userId,e,t||this.image,this.isGuardrailsOn,"cB4SWF0BK8Ers0lxoGnx"),f=$t("stream"),r=await fetch(f,{method:"POST",mode:"cors",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!r.ok){let i=`HTTP error! status: ${r.status}`;try{const o=await r.json();i=o.detail||o.message||i}catch{}throw new Error(i)}if(!r.body)throw new Error("No response body received");const v=r.body.getReader(),a=new TextDecoder("utf-8");let s="";for(;;){const{value:i,done:o}=await v.read();if(o)break;const g=a.decode(i,{stream:!0}).split(`
|
|
740
|
-
`).filter(z=>z.startsWith("data:"));for(let z of g){const c=z.replace(/^data:\s*/,""),X=An(c);if(!X)continue;if(X.type==="content")s+=X.payload;else if(X.type==="images"){const P=Object.entries(X.payload).map(([b,x])=>({productUrl:x,productName:b})),l=this._messages.length-1;this._messages[l]={...this._messages[l],role:"image_row",content:P},this.messages=[...this._messages]}else if(X.type==="error")throw new Error(X.payload);const w=this._messages.length-1;this._messages[w]?.role==="assistant"?(this._messages[w]={...this._messages[w],content:s},this.messages=[...this._messages]):this.addMessage("assistant",s)}}this.clearImage()}catch(n){console.error(`Error sending message: ${n}`);const f=n.message||"Failed to send message. Please try again.",r=this._messages.filter(v=>v.content!=="loader");this.messages=[...r,{role:"assistant",content:`❌ Error: ${f}`,productName:""}]}finally{this.isLoading=!1}}}async resetChat(){if(this.isLoading)return;this.isLoading=!0,this.messages=[],this.clearImage(),$f(),this.userId=et(),this.addMessage("system","You are an advanced AI assistant helps customers on a Retail e-commerce website. You help answer questions for customers about products. Start the conversation by asking a couple of questions to clarify what the user is looking for. Use emojis but do not use too many. Structure your output using Markdown but do not use nested indentations.",""),await F(250),this.addMessage("assistant",""),await F(250);const e="Hi, I'm your Gift Concierge - I'm here to help you find the perfect gift for your friends and family. 🙂";for(const t of e.split(" "))await F(40),this.updateLastMessage(t+" ",void 0,!0);this.isLoading=!1}}const Gr=(A,e,t)=>{const n=A[e];return n?typeof n=="function"?n():Promise.resolve(n):new Promise((f,r)=>{(typeof queueMicrotask=="function"?queueMicrotask:setTimeout)(r.bind(null,new Error("Unknown variable dynamic import: "+e+(e.split("/").length!==t?". Note that variables only represent file names one level deep.":""))))})};class Lr{constructor(e,t){this._messages=[],this._isLoading=!1,this._isError=!1,this._resetLoading=!1,this._stateData={},this._answers=[],this._userId=et(),this._questions=[],this.websiteToken="",this._getRandomTextVariant=n=>n[Math.floor(Math.random()*n.length)],this.host=e,e.addController(this),this.websiteToken=t,this.loadQuestions().then(()=>{this._flow=this._questions.find(n=>n?.id==="general"),this._currentNode=this._flow?.nodes.find(n=>n?.id===this._flow?.start_node)})}get messages(){return this._messages}get isLoading(){return this._isLoading}set isLoading(e){this._isLoading=e,this.host.requestUpdate()}get isError(){return this._isError}set isError(e){this._isError=e,this.host.requestUpdate()}get isResetLoading(){return this._resetLoading}set isResetLoading(e){this._resetLoading=e,this.host.requestUpdate()}async loadQuestions(){const e=document.documentElement.lang||"en";try{const t=await Gr(Object.assign({"../config/questions.de.backup.json":()=>Promise.resolve().then(()=>Zv),"../config/questions.de.json":()=>Promise.resolve().then(()=>qv),"../config/questions.en.backup.json":()=>Promise.resolve().then(()=>Nv),"../config/questions.en.json":()=>Promise.resolve().then(()=>Cn),"../config/questions.fr.backup.json":()=>Promise.resolve().then(()=>Wv),"../config/questions.fr.json":()=>Promise.resolve().then(()=>yv),"../config/questions.it.backup.json":()=>Promise.resolve().then(()=>Qv),"../config/questions.it.json":()=>Promise.resolve().then(()=>Vv)}),`../config/questions.${e}.json`,3);this._questions=t.default}catch{console.warn(`Falling back to English questions because "${e}" not found.`);const n=await Promise.resolve().then(()=>Cn);this._questions=n.default}}_initializeFlow(){this._flow=this._questions.find(e=>e?.id==="general"),this._currentNode=this._flow?.nodes.find(e=>e?.id===this._flow?.start_node)}requestUpdate(){this.host.requestUpdate()}async addMessage(e,t="bot",n,f,r=!0){if(this._messages=[...r?this._messages:[],{text:"",from:t,options:[],results:f}],this.requestUpdate(),e==="end")return;const v=e.split(" ");for(const a of v)this._messages[this._messages.length-1].text+=a+" ",await F(75),this.requestUpdate();n&&n.length>0&&(await F(75),this._messages[this._messages.length-1].options=n,this.requestUpdate())}checkVisible(e){return e?.any?e.any.some(t=>t.eq?this._stateData[t.eq[0]]===t.eq[1]:t.in?t.in[1].includes(this._stateData[t.in[0]]):!1):!0}_extractTopTags(e){const t={};e.forEach(a=>{a.tag?.forEach(s=>{t[s]=(t[s]??0)+1})});const n=Object.entries(t).reduce((a,[s,i])=>(a[i]=a[i]?[...a[i],s]:[s],a),{}),f=Object.keys(n).map(Number).sort((a,s)=>s-a),r=n[f[0]]??[];return{love_language:r.length>0?r[Math.floor(Math.random()*r.length)]:null}}async fetchRecommendedProducts(e=[],t=!1){const n=new AbortController,f=n.signal;try{if(this.isLoading)return;t||(this.isLoading=!0,await F(400),window.dispatchEvent(new CustomEvent("loading-text-variant-trigger",{detail:{loadingTextVariant:this._getRandomTextVariant(this._currentNode.text_variants)},composed:!0,bubbles:!0})));const r=this._extractTopTags(this._answers)
|
|
740
|
+
`).filter(z=>z.startsWith("data:"));for(let z of g){const c=z.replace(/^data:\s*/,""),X=An(c);if(!X)continue;if(X.type==="content")s+=X.payload;else if(X.type==="images"){const P=Object.entries(X.payload).map(([b,x])=>({productUrl:x,productName:b})),l=this._messages.length-1;this._messages[l]={...this._messages[l],role:"image_row",content:P},this.messages=[...this._messages]}else if(X.type==="error")throw new Error(X.payload);const w=this._messages.length-1;this._messages[w]?.role==="assistant"?(this._messages[w]={...this._messages[w],content:s},this.messages=[...this._messages]):this.addMessage("assistant",s)}}this.clearImage()}catch(n){console.error(`Error sending message: ${n}`);const f=n.message||"Failed to send message. Please try again.",r=this._messages.filter(v=>v.content!=="loader");this.messages=[...r,{role:"assistant",content:`❌ Error: ${f}`,productName:""}]}finally{this.isLoading=!1}}}async resetChat(){if(this.isLoading)return;this.isLoading=!0,this.messages=[],this.clearImage(),$f(),this.userId=et(),this.addMessage("system","You are an advanced AI assistant helps customers on a Retail e-commerce website. You help answer questions for customers about products. Start the conversation by asking a couple of questions to clarify what the user is looking for. Use emojis but do not use too many. Structure your output using Markdown but do not use nested indentations.",""),await F(250),this.addMessage("assistant",""),await F(250);const e="Hi, I'm your Gift Concierge - I'm here to help you find the perfect gift for your friends and family. 🙂";for(const t of e.split(" "))await F(40),this.updateLastMessage(t+" ",void 0,!0);this.isLoading=!1}}const Gr=(A,e,t)=>{const n=A[e];return n?typeof n=="function"?n():Promise.resolve(n):new Promise((f,r)=>{(typeof queueMicrotask=="function"?queueMicrotask:setTimeout)(r.bind(null,new Error("Unknown variable dynamic import: "+e+(e.split("/").length!==t?". Note that variables only represent file names one level deep.":""))))})};class Lr{constructor(e,t){this._messages=[],this._isLoading=!1,this._isError=!1,this._resetLoading=!1,this._stateData={},this._answers=[],this._userId=et(),this._questions=[],this.websiteToken="",this._getRandomTextVariant=n=>n[Math.floor(Math.random()*n.length)],this.host=e,e.addController(this),this.websiteToken=t,this.loadQuestions().then(()=>{this._flow=this._questions.find(n=>n?.id==="general"),this._currentNode=this._flow?.nodes.find(n=>n?.id===this._flow?.start_node)})}get messages(){return this._messages}get isLoading(){return this._isLoading}set isLoading(e){this._isLoading=e,this.host.requestUpdate()}get isError(){return this._isError}set isError(e){this._isError=e,this.host.requestUpdate()}get isResetLoading(){return this._resetLoading}set isResetLoading(e){this._resetLoading=e,this.host.requestUpdate()}async loadQuestions(){const e=document.documentElement.lang||"en";try{const t=await Gr(Object.assign({"../config/questions.de.backup.json":()=>Promise.resolve().then(()=>Zv),"../config/questions.de.json":()=>Promise.resolve().then(()=>qv),"../config/questions.en.backup.json":()=>Promise.resolve().then(()=>Nv),"../config/questions.en.json":()=>Promise.resolve().then(()=>Cn),"../config/questions.fr.backup.json":()=>Promise.resolve().then(()=>Wv),"../config/questions.fr.json":()=>Promise.resolve().then(()=>yv),"../config/questions.it.backup.json":()=>Promise.resolve().then(()=>Qv),"../config/questions.it.json":()=>Promise.resolve().then(()=>Vv)}),`../config/questions.${e}.json`,3);this._questions=t.default}catch{console.warn(`Falling back to English questions because "${e}" not found.`);const n=await Promise.resolve().then(()=>Cn);this._questions=n.default}}_initializeFlow(){this._flow=this._questions.find(e=>e?.id==="general"),this._currentNode=this._flow?.nodes.find(e=>e?.id===this._flow?.start_node)}requestUpdate(){this.host.requestUpdate()}async addMessage(e,t="bot",n,f,r=!0){if(this._messages=[...r?this._messages:[],{text:"",from:t,options:[],results:f}],this.requestUpdate(),e==="end")return;const v=e.split(" ");for(const a of v)this._messages[this._messages.length-1].text+=a+" ",await F(75),this.requestUpdate();n&&n.length>0&&(await F(75),this._messages[this._messages.length-1].options=n,this.requestUpdate())}checkVisible(e){return e?.any?e.any.some(t=>t.eq?this._stateData[t.eq[0]]===t.eq[1]:t.in?t.in[1].includes(this._stateData[t.in[0]]):!1):!0}_extractTopTags(e){const t={};e.forEach(a=>{a.tag?.forEach(s=>{t[s]=(t[s]??0)+1})});const n=Object.entries(t).reduce((a,[s,i])=>(a[i]=a[i]?[...a[i],s]:[s],a),{}),f=Object.keys(n).map(Number).sort((a,s)=>s-a),r=n[f[0]]??[];return{love_language:r.length>0?r[Math.floor(Math.random()*r.length)]:null}}async fetchRecommendedProducts(e=[],t=!1){const n=new AbortController,f=n.signal;try{if(this.isLoading)return;t||(this.isLoading=!0,await F(400),window.dispatchEvent(new CustomEvent("loading-text-variant-trigger",{detail:{loadingTextVariant:this._getRandomTextVariant(this._currentNode.text_variants)},composed:!0,bubbles:!0})));const r=this._extractTopTags(this._answers);this._answers.findIndex(c=>c.love_language)===-1&&this._answers.push(r),this._answers=this._answers.map(({tag:c,...X})=>X);const a=en(this._userId,JSON.stringify(this._answers),"",!1,this.websiteToken,e),s=$t("stream"),i=fetch(s,{method:"POST",mode:"cors",headers:{"Content-Type":"application/json"},body:JSON.stringify(a),signal:f});t&&(await F(2100),this.isLoading=!0,await F(400),window.dispatchEvent(new CustomEvent("loading-text-variant-trigger",{detail:{loadingTextVariant:this._getRandomTextVariant(this._currentNode.text_variants)},composed:!0,bubbles:!0})));const o=await i;if(!o.ok){let c=`HTTP error! status: ${o.status}`;try{const X=await o.json();c=X.detail||X.message||c}catch{}throw this.isError=!0,new Error(c)}if(!o.body)throw new Error("No response body received");const u=o.body.getReader(),g=new TextDecoder("utf-8");let z="";for(;;){const{value:c,done:X}=await u.read();if(X)break;z+=g.decode(c,{stream:!0});let w=z.lastIndexOf(`
|
|
741
741
|
`);if(w===-1)continue;const P=z.slice(0,w);z=z.slice(w+1);const l=P.split(`
|
|
742
742
|
`).filter(b=>b.startsWith("data:"));for(const b of l){const x=b.replace(/^data:\s*/,"").trim();if(!x)continue;const H=An(x);H&&H.type!=="content"&&H.type==="images"&&(await this.addMessage("end","bot",[],H.results??[],!1),n.abort(),setTimeout(()=>{window.dispatchEvent(new CustomEvent("relaxed-call",{detail:{isRelaxed:H.relaxed},composed:!0,bubbles:!0})),window.dispatchEvent(new CustomEvent("love-language",{detail:{loveLanguage:r?.love_language},composed:!0,bubbles:!0}))},200))}}}catch(r){r.name!=="AbortError"&&(console.error(`Error sending message: ${r}`),this.isError=!0)}finally{this.isLoading=!1}}async handleAnswer(e,t){const n=this._messages[e],f=n.options?.[t];if(!f)return;n.options=n.options?.map((g,z)=>({...g,selected:z===t})),this.requestUpdate();const r=this._currentNode,v={question:r._shownText,answer:f.label};f?.tag&&(v.tag=[f?.tag]),this._answers.push(v),Object.entries(f.set||{}).forEach(([g,z])=>this._stateData[g]=z);const a=f.next||r.default_next;this._currentNode=this._flow?.nodes.find(g=>g?.id===a);const s=f.follow_ups?this._getRandomTextVariant(f.follow_ups):"";if(await F(400),!this._currentNode)return;if(this._currentNode.type==="end"){const g=this._currentNode.text_variants?this._getRandomTextVariant(this._currentNode.text_variants):"";g&&await this.addMessage(g,"bot"),await this.addMessage("end","bot"),await this.fetchRecommendedProducts([],!0);return}const i=this._getRandomTextVariant(this._currentNode.text_variants);this._messages=[...this._messages,{text:"",from:"bot",options:[]}],this.requestUpdate();const o=this._messages.length-1;if(s){const g=s.split(" ");for(const z of g)this._messages[o].text+=z+" ",await F(75),this.requestUpdate();await F(800),this._messages[o].text+="<br /><br />",this.requestUpdate()}const u=i.split(" ");for(const g of u)this._messages[o].text+=g+" ",await F(75),this.requestUpdate();this._messages[o].options=(this._currentNode.options||[]).filter(g=>!g.visible_when||this.checkVisible(g.visible_when)),this._currentNode._shownText=i}async reset(){this._messages=[],this._stateData={},this._answers=[],this.isError=!1,sessionStorage.removeItem("athena_seen_results"),this._initializeFlow(),this.requestUpdate(),await this.startConversation()}async showQuestion(e){const t=(e.options||[]).filter(f=>!f.visible_when||this.checkVisible(f.visible_when)),n=this._getRandomTextVariant(e.text_variants);await this.addMessage(n,"bot",t),e._shownText=n}async startConversation(){this.isResetLoading=!0,this.isError=!1,await F(600),await this.showQuestion(this._currentNode),this.isResetLoading=!1}hostConnected(){}}var Yr=Object.defineProperty,Er=Object.getOwnPropertyDescriptor,lt=(A,e,t,n)=>{for(var f=n>1?void 0:n?Er(e,t):e,r=A.length-1,v;r>=0;r--)(v=A[r])&&(f=(n?v(e,t,f):v(f))||f);return n&&f&&Yr(e,t,f),f};let ie=class extends h{constructor(){super(...arguments),this._chatController=new Vr(this),this._inputValue="",this._imageValue=""}_submitEventHandler(){this.addEventListener("input-value-submit",async A=>{this._updateScrollPosition();const e=A.detail?.imageValue;if(this._inputValue=bn.sanitize(A.detail?.value)??"",e){const{imageData:t,imageFile:n}=A.detail?.imageValue;this._imageValue=t??"",await this._chatController.handleImageUpload(n??"")}if(this._imageValue){await this._chatController.sendMessage(this._inputValue,this._imageValue);return}await this._chatController.sendMessage(this._inputValue)})}_resetChatEventHandler(){this.addEventListener("reset-chat",async()=>{await this._chatController.resetChat()})}_updateScrollPosition(){const A=this.renderRoot.querySelector(".athena-xai-chat__message-container");A&&(A.scrollTo({top:A.scrollHeight,behavior:"smooth"}),this.requestUpdate())}async connectedCallback(){super.connectedCallback(),await er(),await this._chatController.resetChat(),this._submitEventHandler(),this._resetChatEventHandler()}willUpdate(){this._updateScrollPosition()}render(){return Z`
|
|
743
743
|
<div class="athena-xai-chat__container">
|
|
@@ -784,10 +784,9 @@ Ces cadeaux viennent du cœur:`}}}},$t=A=>`${I.api.baseUrl}${I.api.endpoints[A]}
|
|
|
784
784
|
</section>
|
|
785
785
|
`}};we.styles=iA`
|
|
786
786
|
.athena-xai-select-chat__initial-outer-container {
|
|
787
|
-
height:
|
|
787
|
+
height: 85dvh;
|
|
788
788
|
background: #FFFFFF;
|
|
789
789
|
display: flex;
|
|
790
|
-
padding-top: 68px;
|
|
791
790
|
overflow: hidden;
|
|
792
791
|
}
|
|
793
792
|
|