@telia-ace/widget-conversational-agent 1.1.123-rc.42 → 1.1.123-rc.44
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/index.js +3 -3
- package/index.mjs +9 -10
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -298,7 +298,7 @@
|
|
|
298
298
|
* @license
|
|
299
299
|
* Copyright 2022 Google LLC
|
|
300
300
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
301
|
-
*/function Bo({context:n,subscribe:e}){return(t,s)=>{typeof s=="object"?s.addInitializer((function(){new $r(this,{context:n,callback:i=>{t.set.call(this,i)},subscribe:e})})):t.constructor.addInitializer((i=>{new $r(i,{context:n,callback:r=>{i[s]=r},subscribe:e})}))}}var $u=Object.defineProperty,Ho=(n,e,t,s)=>{for(var i=void 0,r=n.length-1,o;r>=0;r--)(o=n[r])&&(i=o(e,t,i)||i);return i&&$u(e,t,i),i};const Hs="application",ni=class ni extends M{constructor(){super(...arguments),this.nodes=[],this.wrapperRef=oe(),this.fullscreen=!1,this.isReady=new F(!1)}addChild(e){e.parent=this,this.nodes.push(e)}applyBranding(){if(!this.wrapperRef.value)return;const e=this.application.settings;e!=null&&e.branding&&No(e.branding,this.wrapperRef.value)}applyStyles(){if(!this.wrapperRef.value)return;const e=this.application.styles(),t=this.wrapperRef.value;Object.entries(e).forEach(([s,i])=>{t.style.setProperty(`--${s}`,i)})}firstUpdated(e){this.applyBranding(),this.applyStyles()}render(){var s,i;
|
|
301
|
+
*/function Bo({context:n,subscribe:e}){return(t,s)=>{typeof s=="object"?s.addInitializer((function(){new $r(this,{context:n,callback:i=>{t.set.call(this,i)},subscribe:e})})):t.constructor.addInitializer((i=>{new $r(i,{context:n,callback:r=>{i[s]=r},subscribe:e})}))}}var $u=Object.defineProperty,Ho=(n,e,t,s)=>{for(var i=void 0,r=n.length-1,o;r>=0;r--)(o=n[r])&&(i=o(e,t,i)||i);return i&&$u(e,t,i),i};const Hs="application",ni=class ni extends M{constructor(){super(...arguments),this.nodes=[],this.wrapperRef=oe(),this.fullscreen=!1,this.isReady=new F(!1)}addChild(e){e.parent=this,this.nodes.push(e)}applyBranding(){if(!this.wrapperRef.value)return;const e=this.application.settings;e!=null&&e.branding&&No(e.branding,this.wrapperRef.value)}applyStyles(){if(!this.wrapperRef.value)return;const e=this.application.styles(),t=this.wrapperRef.value;Object.entries(e).forEach(([s,i])=>{t.style.setProperty(`--${s}`,i)})}firstUpdated(e){this.applyBranding(),this.applyStyles()}render(){var t,s,i;return((i=(s=(t=this.application.settings)==null?void 0:t.agentConfig)==null?void 0:s.live)==null?void 0:i.isThirdPartyWidget)??!1?this.renderRoot.host.classList.add("third-party"):this.application.renderStrategy===Bs.Trigger&&(this.renderRoot.host.classList.add("floating"),this.application.anchor==="BottomLeft"?this.renderRoot.host.classList.add("bottom-left"):this.application.anchor==="BottomRight"&&this.renderRoot.host.classList.add("bottom-right")),this.application.fullscreen&&this.renderRoot.host.classList.add("fullscreen"),window.self!==window.top&&this.renderRoot.host.classList.add("embedded"),w`<div class="widget-container" ${ae(this.wrapperRef)}>
|
|
302
302
|
${mu(this.nodes,r=>r)}
|
|
303
303
|
</div>`}};ni.styles=Z`
|
|
304
304
|
:host {
|
|
@@ -940,7 +940,7 @@ Please report this to https://github.com/markedjs/marked.`,n){const s="<p>An err
|
|
|
940
940
|
width: 80%;
|
|
941
941
|
max-width: 700px;
|
|
942
942
|
}
|
|
943
|
-
`];let vn=ui;Uh([C({attribute:!0})],vn.prototype,"imageUrl");var zh=Object.defineProperty,se=(n,e,t,s)=>{for(var i=void 0,r=n.length-1,o;r>=0;r--)(o=n[r])&&(i=o(e,t,i)||i);return i&&zh(e,t,i),i};customElements.get("conversation-entry")||customElements.define("conversation-entry",Ct);customElements.get("ace-conversation-feed")||customElements.define("ace-conversation-feed",Tt);customElements.get("conversation-group")||customElements.define("conversation-group",pn);customElements.get("ace-typing-state")||customElements.define("ace-typing-state",vs);customElements.get("message-type-html")||customElements.define("message-type-html",fn);customElements.get("message-type-markdown")||customElements.define("message-type-markdown",Lt);customElements.get("ace-lightbox")||customElements.define("ace-lightbox",vn);const Dr=Do(M),hi=class hi extends Dr{constructor(){super(...arguments),this.platform=null,this.entries=[],this.typing=!1,this.message="",this.disabledInput=!1,this.disabledSkipToLatest=!1,this.disabledSubmit=!1,this.chatOverlayActive=!1,this.textAreaLength=0,this.showAuthBanner=!1,this.authenticated=!1,this.isMuted=!1,this.isKeyboardNavigation=!1,this.conversationContentRef=oe(),this.conversationFeedRef=oe(),this.formRef=oe(),this.inputRef=oe(),this.scrollRef=oe(),this.counterRef=oe(),this.chatCurrentScrollPosition=0,this.toast=new wu(this),this.messageMaxLength=1e3,this.messageMaxLengthLabel="Maximum character limit reached",this.skipToLatestMessageLabel="Skip to latest message",this.conversationState$=new F("waiting"),this.stateMachine=new Su(this.conversationState$,this),this.provider$=this.stateMachine.session().pipe(Je(e=>e?e==null?void 0:e.provider$:os(null))),this.userTyping$=new I}async connectedCallback(){super.connectedCallback(),this.messageMaxLength=this.properties.messageMaxLength??this.messageMaxLength,this.messageMaxLengthLabel=this.properties.messageMaxLengthLabel??this.messageMaxLengthLabel,this.skipToLatestMessageLabel=this.properties.skipToLatestMessageLabel??this.skipToLatestMessageLabel;const e=await this.application.container.get("conversation");this.platform=e||null;const t=this.application.trigger;t&&t.widgetActive$.pipe(as(t.componentIsDestroyed$)).subscribe(s=>{const i=this.conversationContentRef.value;i&&(s?i.scrollTop=this.chatCurrentScrollPosition:this.chatCurrentScrollPosition=i.scrollTop)}),this.stateSubscription=hl([this.stateMachine.entries(),this.stateMachine.isTyping()]).subscribe(([s,i])=>{this.entries=s,this.typing=i}),this.userSubmitSubscription=sn(this,"user-submit").pipe(ls(this.provider$)).subscribe(([s,i])=>{i&&i.onUserSubmit(s.detail)}),this.addHeaderOptions(),this.provider$.pipe(ls(this.provider$)).subscribe(([s,i])=>{i&&i.showChatOverlay$.pipe().subscribe(r=>{this.chatOverlayActive=r})})}firstUpdated(){this.isMuted=this.application.storage.get("muteAudioNotifications")??!1}disconnectedCallback(){var e,t;super.disconnectedCallback(),(e=this.userSubmitSubscription)==null||e.unsubscribe(),(t=this.stateSubscription)==null||t.unsubscribe()}actionHandler(e){}isTypingState(){var t,s;const e=(s=(t=this.conversationFeedRef.value)==null?void 0:t.shadowRoot)==null?void 0:s.querySelector(".conversation-feed");if(e){const i=e.lastElementChild;if(i&&i.tagName.toLowerCase()==="ace-typing-state")return!0}return!1}isAtBottom(){const e=this.conversationContentRef.value;return e?e.scrollHeight-e.scrollTop-e.clientHeight<1:!1}scrollToBottom(){var e;(!this.isTypingState()||this.isAtBottom())&&(setTimeout(()=>{var t;return(t=this.scrollRef.value)==null?void 0:t.scrollIntoView({behavior:"smooth"})},300),this.chatCurrentScrollPosition=(e=this.scrollRef.value)==null?void 0:e.scrollTop)}onSessionUpdated(){this.scrollToBottom()}async onSendMessage(e){var s,i;if(e.preventDefault(),this.message.length<=0||this.message.length>this.messageMaxLength){(s=this.formRef.value)==null||s.classList.add("shake"),setTimeout(()=>{var r;(r=this.formRef.value)==null||r.classList.remove("shake")},500);return}this.message=this.message.slice(0,this.messageMaxLength);const t=new CustomEvent("user-submit",{detail:{text:this.message}});this.dispatchEvent(t),this.message="",this.textAreaLength=0,(i=this.counterRef.value)==null||i.classList.remove("max-char-count-reached"),this.inputRef.value.style.height=this.style.getPropertyValue("--textarea-default-height")}addHeaderOptions(){const e=this.application.getComponent("widget-header");if(!e)return;const t=this.application.texts,s=t.getOrFallback("conversation.mute","Mute"),i=t.getOrFallback("conversation.unmute","Unmute"),r=e.addOption({label:this.isMuted?i:s,icon:this.isMuted?Ji.svg:er.svg,closeOnClick:!1,datatestid:"options-mute-button",onClick:()=>{this.isMuted?(this.isMuted=!1,this.application.unmute(),r.updateLabel(s),r.updateIcon(er.svg)):(this.isMuted=!0,this.application.mute(),r.updateLabel(i),r.updateIcon(Ji.svg))}})}inputHandler(e){var t,s;this.message=e.target.value,e.target.style.height=this.style.getPropertyValue("--textarea-default-height"),e.target.style.height=e.target.scrollHeight+"px",this.textAreaLength=e.target.value.length,e.target.value.length>this.messageMaxLength?(t=this.counterRef.value)==null||t.classList.add("max-char-count-reached"):(s=this.counterRef.value)==null||s.classList.remove("max-char-count-reached")}keyDownHandler(e){this.userTyping$.next(e.key),e.key==="Tab"&&(this.isKeyboardNavigation=!0),e.key==="Enter"&&!e.shiftKey&&!this.disabledSubmit&&(this.onSendMessage(e),e.preventDefault())}mouseDownHandler(e){e.target===this.inputRef.value&&(this.isKeyboardNavigation=!1)}focusHandler(){this.isKeyboardNavigation&&this.inputRef.value&&this.inputRef.value.classList.add("keyboard-focused")}blurHandler(){this.inputRef.value&&this.inputRef.value.classList.remove("keyboard-focused")}getAuthBannerMessage(){const e=this.application.texts;return this.authenticated?e.getOrFallback("conversation.auth-banner.authenticated","Authenticated"):e.getOrFallback("conversation.auth-banner.unauthenticated","Not authenticated")}disableInput(){this.disabledInput=!0,this.message=""}enableInput(){this.disabledInput=!1}enableSkipToLatestMessage(){this.disabledSkipToLatest=!1}disableSkipToLatestMessage(){this.disabledSkipToLatest=!0}disableSubmit(){this.disabledSubmit=!0}enableSubmit(){this.disabledSubmit=!1}clearMessages(){var i,r;const e=(i=this.shadowRoot)==null?void 0:i.querySelector("ace-conversation-feed"),t=(r=e==null?void 0:e.shadowRoot)==null?void 0:r.querySelector(".conversation-feed"),s=t==null?void 0:t.querySelectorAll(".conversation-entry");s==null||s.forEach(o=>o.remove())}setToastMessage(e){this.toast.message=e}skipToLatestMessage(){var s,i;const e=(s=this.conversationFeedRef)==null?void 0:s.value,t=(i=e==null?void 0:e.shadowRoot)==null?void 0:i.querySelectorAll(".conversation-entry");t.length&&Array.from(t).pop().focus()}setAuthenticationBannerStatus(e){this.showAuthBanner=e!==null,this.authenticated=e===Uo.Authenticated}handover(e,t){this.enableInput(),this.setToastMessage(null);const s=new CustomEvent("handover",{detail:{providerKey:e,providerOptions:t}});return this.dispatchEvent(s),s.detail.complete||Pt}render(){var i,r,o;const e=this.application.texts;this.conversationState$.value==="waiting"&&((
|
|
943
|
+
`];let vn=ui;Uh([C({attribute:!0})],vn.prototype,"imageUrl");var zh=Object.defineProperty,se=(n,e,t,s)=>{for(var i=void 0,r=n.length-1,o;r>=0;r--)(o=n[r])&&(i=o(e,t,i)||i);return i&&zh(e,t,i),i};customElements.get("conversation-entry")||customElements.define("conversation-entry",Ct);customElements.get("ace-conversation-feed")||customElements.define("ace-conversation-feed",Tt);customElements.get("conversation-group")||customElements.define("conversation-group",pn);customElements.get("ace-typing-state")||customElements.define("ace-typing-state",vs);customElements.get("message-type-html")||customElements.define("message-type-html",fn);customElements.get("message-type-markdown")||customElements.define("message-type-markdown",Lt);customElements.get("ace-lightbox")||customElements.define("ace-lightbox",vn);const Dr=Do(M),hi=class hi extends Dr{constructor(){super(...arguments),this.platform=null,this.entries=[],this.typing=!1,this.message="",this.disabledInput=!1,this.disabledSkipToLatest=!1,this.disabledSubmit=!1,this.chatOverlayActive=!1,this.textAreaLength=0,this.showAuthBanner=!1,this.authenticated=!1,this.isMuted=!1,this.isKeyboardNavigation=!1,this.conversationContentRef=oe(),this.conversationFeedRef=oe(),this.formRef=oe(),this.inputRef=oe(),this.scrollRef=oe(),this.counterRef=oe(),this.chatCurrentScrollPosition=0,this.toast=new wu(this),this.messageMaxLength=1e3,this.messageMaxLengthLabel="Maximum character limit reached",this.skipToLatestMessageLabel="Skip to latest message",this.conversationState$=new F("waiting"),this.stateMachine=new Su(this.conversationState$,this),this.provider$=this.stateMachine.session().pipe(Je(e=>e?e==null?void 0:e.provider$:os(null))),this.userTyping$=new I}async connectedCallback(){super.connectedCallback(),this.messageMaxLength=this.properties.messageMaxLength??this.messageMaxLength,this.messageMaxLengthLabel=this.properties.messageMaxLengthLabel??this.messageMaxLengthLabel,this.skipToLatestMessageLabel=this.properties.skipToLatestMessageLabel??this.skipToLatestMessageLabel;const e=await this.application.container.get("conversation");this.platform=e||null;const t=this.application.trigger;t&&t.widgetActive$.pipe(as(t.componentIsDestroyed$)).subscribe(s=>{const i=this.conversationContentRef.value;i&&(s?i.scrollTop=this.chatCurrentScrollPosition:this.chatCurrentScrollPosition=i.scrollTop)}),this.stateSubscription=hl([this.stateMachine.entries(),this.stateMachine.isTyping()]).subscribe(([s,i])=>{this.entries=s,this.typing=i}),this.userSubmitSubscription=sn(this,"user-submit").pipe(ls(this.provider$)).subscribe(([s,i])=>{i&&i.onUserSubmit(s.detail)}),this.addHeaderOptions(),this.provider$.pipe(ls(this.provider$)).subscribe(([s,i])=>{i&&i.showChatOverlay$.pipe().subscribe(r=>{this.chatOverlayActive=r})})}firstUpdated(){this.isMuted=this.application.storage.get("muteAudioNotifications")??!1}disconnectedCallback(){var e,t;super.disconnectedCallback(),(e=this.userSubmitSubscription)==null||e.unsubscribe(),(t=this.stateSubscription)==null||t.unsubscribe()}actionHandler(e){}isTypingState(){var t,s;const e=(s=(t=this.conversationFeedRef.value)==null?void 0:t.shadowRoot)==null?void 0:s.querySelector(".conversation-feed");if(e){const i=e.lastElementChild;if(i&&i.tagName.toLowerCase()==="ace-typing-state")return!0}return!1}isAtBottom(){const e=this.conversationContentRef.value;return e?e.scrollHeight-e.scrollTop-e.clientHeight<1:!1}scrollToBottom(){var e;(!this.isTypingState()||this.isAtBottom())&&(setTimeout(()=>{var t;return(t=this.scrollRef.value)==null?void 0:t.scrollIntoView({behavior:"smooth"})},300),this.chatCurrentScrollPosition=(e=this.scrollRef.value)==null?void 0:e.scrollTop)}onSessionUpdated(){this.scrollToBottom()}async onSendMessage(e){var s,i;if(e.preventDefault(),this.message.length<=0||this.message.length>this.messageMaxLength){(s=this.formRef.value)==null||s.classList.add("shake"),setTimeout(()=>{var r;(r=this.formRef.value)==null||r.classList.remove("shake")},500);return}this.message=this.message.slice(0,this.messageMaxLength);const t=new CustomEvent("user-submit",{detail:{text:this.message}});this.dispatchEvent(t),this.message="",this.textAreaLength=0,(i=this.counterRef.value)==null||i.classList.remove("max-char-count-reached"),this.inputRef.value.style.height=this.style.getPropertyValue("--textarea-default-height")}addHeaderOptions(){const e=this.application.getComponent("widget-header");if(!e)return;const t=this.application.texts,s=t.getOrFallback("conversation.mute","Mute"),i=t.getOrFallback("conversation.unmute","Unmute"),r=e.addOption({label:this.isMuted?i:s,icon:this.isMuted?Ji.svg:er.svg,closeOnClick:!1,datatestid:"options-mute-button",onClick:()=>{this.isMuted?(this.isMuted=!1,this.application.unmute(),r.updateLabel(s),r.updateIcon(er.svg)):(this.isMuted=!0,this.application.mute(),r.updateLabel(i),r.updateIcon(Ji.svg))}})}inputHandler(e){var t,s;this.message=e.target.value,e.target.style.height=this.style.getPropertyValue("--textarea-default-height"),e.target.style.height=e.target.scrollHeight+"px",this.textAreaLength=e.target.value.length,e.target.value.length>this.messageMaxLength?(t=this.counterRef.value)==null||t.classList.add("max-char-count-reached"):(s=this.counterRef.value)==null||s.classList.remove("max-char-count-reached")}keyDownHandler(e){this.userTyping$.next(e.key),e.key==="Tab"&&(this.isKeyboardNavigation=!0),e.key==="Enter"&&!e.shiftKey&&!this.disabledSubmit&&(this.onSendMessage(e),e.preventDefault())}mouseDownHandler(e){e.target===this.inputRef.value&&(this.isKeyboardNavigation=!1)}focusHandler(){this.isKeyboardNavigation&&this.inputRef.value&&this.inputRef.value.classList.add("keyboard-focused")}blurHandler(){this.inputRef.value&&this.inputRef.value.classList.remove("keyboard-focused")}getAuthBannerMessage(){const e=this.application.texts;return this.authenticated?e.getOrFallback("conversation.auth-banner.authenticated","Authenticated"):e.getOrFallback("conversation.auth-banner.unauthenticated","Not authenticated")}disableInput(){this.disabledInput=!0,this.message=""}enableInput(){this.disabledInput=!1}enableSkipToLatestMessage(){this.disabledSkipToLatest=!1}disableSkipToLatestMessage(){this.disabledSkipToLatest=!0}disableSubmit(){this.disabledSubmit=!0}enableSubmit(){this.disabledSubmit=!1}clearMessages(){var i,r;const e=(i=this.shadowRoot)==null?void 0:i.querySelector("ace-conversation-feed"),t=(r=e==null?void 0:e.shadowRoot)==null?void 0:r.querySelector(".conversation-feed"),s=t==null?void 0:t.querySelectorAll(".conversation-entry");s==null||s.forEach(o=>o.remove())}setToastMessage(e){this.toast.message=e}skipToLatestMessage(){var s,i;const e=(s=this.conversationFeedRef)==null?void 0:s.value,t=(i=e==null?void 0:e.shadowRoot)==null?void 0:i.querySelectorAll(".conversation-entry");t.length&&Array.from(t).pop().focus()}setAuthenticationBannerStatus(e){this.showAuthBanner=e!==null,this.authenticated=e===Uo.Authenticated}handover(e,t){this.enableInput(),this.setToastMessage(null);const s=new CustomEvent("handover",{detail:{providerKey:e,providerOptions:t}});return this.dispatchEvent(s),s.detail.complete||Pt}render(){var s,i,r,o;const e=this.application.texts;return this.conversationState$.value==="waiting"&&((s=this.application)!=null&&s.storage)&&this.platform&&(this.stateMachine.setStorage(this.application.storage),this.conversationState$.next("init")),(((o=(r=(i=this.application.settings)==null?void 0:i.agentConfig)==null?void 0:r.live)==null?void 0:o.isThirdPartyWidget)??!1)&&(this.renderRoot.host.style.width="100%"),w` <div class="conversation-container">
|
|
944
944
|
${this.showAuthBanner?w`<div
|
|
945
945
|
class="auth-banner ${this.authenticated?"auth-banner--authenticated":"auth-banner--unauthenticated"}"
|
|
946
946
|
role="status"
|
|
@@ -1428,4 +1428,4 @@ Please report this to https://github.com/markedjs/marked.`,n){const s="<p>An err
|
|
|
1428
1428
|
button:hover {
|
|
1429
1429
|
filter: brightness(150%);
|
|
1430
1430
|
}
|
|
1431
|
-
`];ca([Bo({context:Hs}),C({attribute:!1})],bn.prototype,"application",2);bn=ca([Qc("ace-restart-dialog")],bn);class Qs extends Cl{constructor(e,t){super(e,t),this.isConnected=!1,this.rehydrating=!1,this.lastReceivedMessageWasComplete=!0,this.isReady=!1,this.lastWrittenEntry=null,this.agent=this.createAgent(""),this.user=this.createUser(""),this.shouldRestartSubject$=new F(!1),this.connection=this.createConnection(t.properties),this.connection.store$.subscribe(s=>{s={...s,messages:s.messages.filter(i=>!i.reconnectResponsePayload)},this.save(s)}),this.connection.isConnected().subscribe(s=>{this.isConnected=s,s?(this.component.enableInput(),this.setShouldRestart(!1)):this.component.disableInput()}),this.connection.agent().subscribe(s=>{this.agent.name=s.name}),this.connection.messages().subscribe(s=>{if(s.type==="stream"){let i=null;if(this.lastReceivedMessageWasComplete||!this.lastWrittenEntry)i=this.printAgent(s.text),i&&(this.lastWrittenEntry={entry:i,messages:[s]});else if(this.lastWrittenEntry){const r=this.mergeMessageParts(this.lastWrittenEntry.messages);s.isComplete?(this.updateEntry(this.lastWrittenEntry.entry,`${r}${s.text}`),this.lastWrittenEntry.messages.push(s)):(this.updateEntry(this.lastWrittenEntry.entry,`${r}${s.text}`),this.lastWrittenEntry.messages.push(s))}this.lastReceivedMessageWasComplete=s.isComplete}else s.sender==="user"?this.printUser(s.text):this.printAgent(s.text)}),this.connection.events().subscribe(s=>{switch(s.event){case"disconnected":this.printAgent("You were disconnected from the chat session."),this.showRestartDialog();break;case"handover":this.showRestartDialog();break}})}static getInstance(e,t){return t.providerInstance||(t.providerInstance=new Qs(e,t)),t.providerInstance}setShouldRestart(e){this.shouldRestartSubject$.next(e)}get shouldRestart$(){return this.shouldRestartSubject$.asObservable()}printAgent(e){return this.setTypingState(!1),this.agent.print(e,"markdown")}printUser(e){const t=cs(Fi(e));return this.user.print(t)}printSystem(e){const t=cs(Fi(e));return this.system.print(t)}showRestartDialog(){this.restartDialogEntry&&this.restartDialogEntry.remove(),this.component.disableInput(),this.restartDialogEntry=new It(be.System,{name:""},[{items:[["ace-restart-dialog",{content:""}]]}]),this.printEntry(this.restartDialogEntry),this.restartDialogEntry.actions$.pipe(wl(e=>e.key==="restart-session"),Ie(1)).subscribe(async()=>{this.restartDialogEntry&&this.restartDialogEntry.remove(),this.restartConversation(),this.component.clearMessages()})}onUserSubmit(e){if(!this.isConnected){this.printAgent("The connection have been closed. Please reload the page to start a new session.");return}this.printUser(e.text),this.connection.sendMessage({text:e.text}),!(e.text.includes("__agent__")||e.text.includes("__mockad agent__"))&&this.setTypingState(!0)}mergeMessageParts(e){return e.length?e.map(t=>t.text).join(""):""}updateEntry(e,t){e.update([["markdown",{content:t}]])}createConnection(e){var r;this.connection&&this.connection.dispose();const t=(r=this.component.application.settings.
|
|
1431
|
+
`];ca([Bo({context:Hs}),C({attribute:!1})],bn.prototype,"application",2);bn=ca([Qc("ace-restart-dialog")],bn);class Qs extends Cl{constructor(e,t){super(e,t),this.isConnected=!1,this.rehydrating=!1,this.lastReceivedMessageWasComplete=!0,this.isReady=!1,this.lastWrittenEntry=null,this.agent=this.createAgent(""),this.user=this.createUser(""),this.shouldRestartSubject$=new F(!1),this.connection=this.createConnection(t.properties),this.connection.store$.subscribe(s=>{s={...s,messages:s.messages.filter(i=>!i.reconnectResponsePayload)},this.save(s)}),this.connection.isConnected().subscribe(s=>{this.isConnected=s,s?(this.component.enableInput(),this.setShouldRestart(!1)):this.component.disableInput()}),this.connection.agent().subscribe(s=>{this.agent.name=s.name}),this.connection.messages().subscribe(s=>{if(s.type==="stream"){let i=null;if(this.lastReceivedMessageWasComplete||!this.lastWrittenEntry)i=this.printAgent(s.text),i&&(this.lastWrittenEntry={entry:i,messages:[s]});else if(this.lastWrittenEntry){const r=this.mergeMessageParts(this.lastWrittenEntry.messages);s.isComplete?(this.updateEntry(this.lastWrittenEntry.entry,`${r}${s.text}`),this.lastWrittenEntry.messages.push(s)):(this.updateEntry(this.lastWrittenEntry.entry,`${r}${s.text}`),this.lastWrittenEntry.messages.push(s))}this.lastReceivedMessageWasComplete=s.isComplete}else s.sender==="user"?this.printUser(s.text):this.printAgent(s.text)}),this.connection.events().subscribe(s=>{switch(s.event){case"disconnected":this.printAgent("You were disconnected from the chat session."),this.showRestartDialog();break;case"handover":this.showRestartDialog();break}})}static getInstance(e,t){return t.providerInstance||(t.providerInstance=new Qs(e,t)),t.providerInstance}setShouldRestart(e){this.shouldRestartSubject$.next(e)}get shouldRestart$(){return this.shouldRestartSubject$.asObservable()}printAgent(e){return this.setTypingState(!1),this.agent.print(e,"markdown")}printUser(e){const t=cs(Fi(e));return this.user.print(t)}printSystem(e){const t=cs(Fi(e));return this.system.print(t)}showRestartDialog(){this.restartDialogEntry&&this.restartDialogEntry.remove(),this.component.disableInput(),this.restartDialogEntry=new It(be.System,{name:""},[{items:[["ace-restart-dialog",{content:""}]]}]),this.printEntry(this.restartDialogEntry),this.restartDialogEntry.actions$.pipe(wl(e=>e.key==="restart-session"),Ie(1)).subscribe(async()=>{this.restartDialogEntry&&this.restartDialogEntry.remove(),this.restartConversation(),this.component.clearMessages()})}onUserSubmit(e){if(!this.isConnected){this.printAgent("The connection have been closed. Please reload the page to start a new session.");return}this.printUser(e.text),this.connection.sendMessage({text:e.text}),!(e.text.includes("__agent__")||e.text.includes("__mockad agent__"))&&this.setTypingState(!0)}mergeMessageParts(e){return e.length?e.map(t=>t.text).join(""):""}updateEntry(e,t){e.update([["markdown",{content:t}]])}createConnection(e){var r,o;this.connection&&this.connection.dispose();const t=(o=(r=this.component.application.settings.agentConfig)==null?void 0:r.virtual)==null?void 0:o.extension;if(!t)throw new Error("Extension is required, config misconfigured. See agents.extension");const s=`wss://knowledge-dev.ace.teliacompany.net/v1/dialogflow/ws?agent_id=${t}&project=know-sandbox-dev`,i=e.webconnectorUrl||s;return e.extension?new zr({connectionUri:i,extension:e.extension.toString()},this.component,this):(console.warn("ConversationalAgentProvider has not defined an extension. Using default extension 1792."),new zr({connectionUri:i,extension:"1936"},this.component,this))}restartConversation(){if(this.isConnected){this.setShouldRestart(!0),this.connection.endSession();return}this.connection.connect()}save(e){this.rehydrating||this.saveToCurrentSession$.next(e)}async rehydrate(e){this.rehydrating=!0,this.connection&&this.connection.rehydrate(e)}connect(e){super.connect(),this.rehydrating=!1,this.component.application.root&&this.component.application.root.isReady.subscribe(t=>{t&&!this.isReady&&(this.connection.connect(),this.isReady=!0)})}}const Br="ace-conversational-agent-provider",Zh=async n=>{(await Ss.getInstance(n.container)).registerProvider(Br,t=>Qs.getInstance(Br,t))};exports.ConversationalAgentProviderPlugin=Zh;
|
package/index.mjs
CHANGED
|
@@ -3686,9 +3686,8 @@ const Hs = "application", ni = class ni extends M {
|
|
|
3686
3686
|
this.applyBranding(), this.applyStyles();
|
|
3687
3687
|
}
|
|
3688
3688
|
render() {
|
|
3689
|
-
var s, i;
|
|
3690
|
-
|
|
3691
|
-
return ((i = (s = e == null ? void 0 : e.properties) == null ? void 0 : s.chat) == null ? void 0 : i.isThirdPartyWidget) ? this.renderRoot.host.classList.add("third-party") : this.application.renderStrategy === Bs.Trigger && (this.renderRoot.host.classList.add("floating"), this.application.anchor === "BottomLeft" ? this.renderRoot.host.classList.add("bottom-left") : this.application.anchor === "BottomRight" && this.renderRoot.host.classList.add("bottom-right")), this.application.fullscreen && this.renderRoot.host.classList.add("fullscreen"), window.self !== window.top && this.renderRoot.host.classList.add("embedded"), w`<div class="widget-container" ${ae(this.wrapperRef)}>
|
|
3689
|
+
var t, s, i;
|
|
3690
|
+
return ((i = (s = (t = this.application.settings) == null ? void 0 : t.agentConfig) == null ? void 0 : s.live) == null ? void 0 : i.isThirdPartyWidget) ?? !1 ? this.renderRoot.host.classList.add("third-party") : this.application.renderStrategy === Bs.Trigger && (this.renderRoot.host.classList.add("floating"), this.application.anchor === "BottomLeft" ? this.renderRoot.host.classList.add("bottom-left") : this.application.anchor === "BottomRight" && this.renderRoot.host.classList.add("bottom-right")), this.application.fullscreen && this.renderRoot.host.classList.add("fullscreen"), window.self !== window.top && this.renderRoot.host.classList.add("embedded"), w`<div class="widget-container" ${ae(this.wrapperRef)}>
|
|
3692
3691
|
${mu(this.nodes, (r) => r)}
|
|
3693
3692
|
</div>`;
|
|
3694
3693
|
}
|
|
@@ -7181,11 +7180,9 @@ const Dr = Do(M), hi = class hi extends Dr {
|
|
|
7181
7180
|
return this.dispatchEvent(s), s.detail.complete || Pt;
|
|
7182
7181
|
}
|
|
7183
7182
|
render() {
|
|
7184
|
-
var i, r, o;
|
|
7183
|
+
var s, i, r, o;
|
|
7185
7184
|
const e = this.application.texts;
|
|
7186
|
-
this.conversationState$.value === "waiting" && ((
|
|
7187
|
-
const t = this.application.settings.components.conversation;
|
|
7188
|
-
return ((o = (r = t == null ? void 0 : t.properties) == null ? void 0 : r.chat) == null ? void 0 : o.isThirdPartyWidget) && (this.renderRoot.host.style.width = "100%"), w` <div class="conversation-container">
|
|
7185
|
+
return this.conversationState$.value === "waiting" && ((s = this.application) != null && s.storage) && this.platform && (this.stateMachine.setStorage(this.application.storage), this.conversationState$.next("init")), (((o = (r = (i = this.application.settings) == null ? void 0 : i.agentConfig) == null ? void 0 : r.live) == null ? void 0 : o.isThirdPartyWidget) ?? !1) && (this.renderRoot.host.style.width = "100%"), w` <div class="conversation-container">
|
|
7189
7186
|
${this.showAuthBanner ? w`<div
|
|
7190
7187
|
class="auth-banner ${this.authenticated ? "auth-banner--authenticated" : "auth-banner--unauthenticated"}"
|
|
7191
7188
|
role="status"
|
|
@@ -8071,11 +8068,13 @@ class Qs extends Cl {
|
|
|
8071
8068
|
e.update([["markdown", { content: t }]]);
|
|
8072
8069
|
}
|
|
8073
8070
|
createConnection(e) {
|
|
8074
|
-
var r;
|
|
8071
|
+
var r, o;
|
|
8075
8072
|
this.connection && this.connection.dispose();
|
|
8076
|
-
const t = (r = this.component.application.settings.
|
|
8073
|
+
const t = (o = (r = this.component.application.settings.agentConfig) == null ? void 0 : r.virtual) == null ? void 0 : o.extension;
|
|
8077
8074
|
if (!t)
|
|
8078
|
-
throw new Error(
|
|
8075
|
+
throw new Error(
|
|
8076
|
+
"Extension is required, config misconfigured. See agents.extension"
|
|
8077
|
+
);
|
|
8079
8078
|
const s = `wss://knowledge-dev.ace.teliacompany.net/v1/dialogflow/ws?agent_id=${t}&project=know-sandbox-dev`, i = e.webconnectorUrl || s;
|
|
8080
8079
|
return e.extension ? new zr(
|
|
8081
8080
|
{
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@telia-ace/widget-conversational-agent",
|
|
3
|
-
"version": "1.1.123-rc.
|
|
3
|
+
"version": "1.1.123-rc.44",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@telia-ace/widget-conversation-flamingo": "1.1.123-rc.
|
|
9
|
+
"@telia-ace/widget-conversation-flamingo": "1.1.123-rc.44",
|
|
10
10
|
"rxjs": "^7.8.2",
|
|
11
|
-
"@telia-ace/widget-core-flamingo": "1.1.123-rc.
|
|
11
|
+
"@telia-ace/widget-core-flamingo": "1.1.123-rc.44",
|
|
12
12
|
"lit": "^3.0.2",
|
|
13
13
|
"@lit/context": "^1.1.4"
|
|
14
14
|
},
|