@telia-ace/widget-conversational-agent 1.1.123-rc.7 → 1.1.123-rc.9

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.
Files changed (3) hide show
  1. package/index.js +1 -1
  2. package/index.mjs +1 -4
  3. package/package.json +3 -3
package/index.js CHANGED
@@ -1356,7 +1356,7 @@ Please report this to https://github.com/markedjs/marked.`,n){const s="<p>An err
1356
1356
  width: 100%;
1357
1357
  }
1358
1358
  }
1359
- `];let V=hi;se([N()],V.prototype,"platform");se([N()],V.prototype,"entries");se([N()],V.prototype,"typing");se([N()],V.prototype,"message");se([N()],V.prototype,"disabledInput");se([N()],V.prototype,"disabledSkipToLatest");se([N()],V.prototype,"disabledSubmit");se([N()],V.prototype,"chatOverlayActive");se([N()],V.prototype,"textAreaLength");se([N()],V.prototype,"showAuthBanner");se([N()],V.prototype,"authenticated");const Bh=n=>{var e,t;return!!((e=n==null?void 0:n.outputPayload)!=null&&e.textOutputContent)&&((t=n==null?void 0:n.outputPayload)==null?void 0:t.isFinal)},Fh=n=>{var e;return!!((e=n==null?void 0:n.outputPayload)!=null&&e.textStreamOutputContent)},Hh=n=>{var e;return!!((e=n==null?void 0:n.initializeResponsePayload)!=null&&e.greetingMessage)},jh=n=>!!(n!=null&&n.errorPayload),Ur=n=>{var e,t;return!!((t=(e=n.inputPayload)==null?void 0:e.textInputContent)!=null&&t.text)},qh=n=>(n==null?void 0:n.type)==="handover";class zr{constructor(e,t,s){this.settings=e,this.component=t,this.provider=s,this.started=!1,this.restartRequested=!1,this.currentSequenceNumber=1,this.dialogId=null,this.isConnected$=new H(!1),this.agent$=new H({name:""}),this.messageSubject$=new I,this.systemEvents$=new I,this.store$=new H({messages:[],dialogId:null}),this.retries=0,this.isConnected=()=>this.isConnected$.asObservable(),this.agent=()=>this.agent$.asObservable(),this.messages=()=>this.messageSubject$.asObservable(),this.events=()=>this.systemEvents$.asObservable(),this.restartSubscription$=this.provider.shouldRestart$.subscribe(i=>{this.restartRequested=i})}connect(){this.started||(this.ws=new WebSocket(this.settings.connectionUri),this.ws.onopen=e=>{this.onConnected()},this.ws.onmessage=e=>{const t=JSON.parse(e.data);if(t!=null&&t.text){const s={sequenceNumber:1,outputPayload:{isFinal:!0,textOutputContent:{text:t.text}}};this.onMessage(s)}else this.onMessage(t)},this.ws.onerror=e=>{this.onError(e)},this.ws.onclose=e=>{this.onClose(e)},this.started=!0)}async reconnect(e){}sendMessage(e){const{text:t}=e;if(this.component.disableSubmit(),t.includes("__mockad agent__")){this.systemEvents$.next({event:"handover",text:"",providerKey:"ace-chat",options:{instance:"dt1",engineUrl:"https://widgets.ace.teliacompany.net/engine-simulator/",entrance:"knowsv",errand:"S02"}});return}else if(t.includes("__agent__")){this.systemEvents$.next({event:"handover",text:"",providerKey:"ace-chat",options:{instance:"dt1",engineUrl:"https://chat-dt1.labbn.se/",entrance:"knowsv",errand:"S02"}});return}this._sendMessage({sequenceNumber:this.currentSequenceNumber,inputPayload:{textInputContent:{text:t}}}),this.incrementSequenceNumber()}onConnected(){console.log("Connection established."),this.isConnected$.next(!0),this.retries=0;const e=i=>({sequenceNumber:1,reconnectRequestPayload:{lastReceivedSequenceNumber:2,dialogId:i}}),t=()=>({sequenceNumber:1,initializeRequestPayload:{extension:this.settings.extension}});this.systemEvents$.next({event:"connected",text:"Connection established"});const s=this.dialogId?e(this.dialogId):t();this._sendMessage(s)}_sendMessage(e){var t,s;if(!this.isConnected$.value){console.warn("Message could not be sent, you are not connected.");return}Ur(e)?(this.store$.pipe(Ie(1)).subscribe(i=>{this.store$.next({messages:[...i.messages,e],dialogId:i.dialogId})}),(t=this.ws)==null||t.send(JSON.stringify({text:e.inputPayload.textInputContent.text}))):(s=this.ws)==null||s.send(JSON.stringify(e))}incrementSequenceNumber(){this.currentSequenceNumber=this.currentSequenceNumber+1}onMessage(e){if(this.store$.pipe(Ie(1)).subscribe(t=>{this.store$.next({messages:[...t.messages,e],dialogId:t.dialogId})}),jh(e)){this.provider.setShouldRestart(!0),console.debug("Received error from socket connection:",e);return}if(qh(e)){this.systemEvents$.next({event:e.type,text:"",providerKey:"ace-chat",options:{instance:e.data.instance,engineUrl:e.data.engineUrl,entrance:e.data.entrance,errand:e.data.errand}});return}Hh(e)&&e.initializeResponsePayload.greetingMessage.length>0?(this.agent$.next({name:e.initializeResponsePayload.agentName||""}),this.dialogId=e.initializeResponsePayload.dialogId,this.store$.pipe(Ie(1)).subscribe(t=>{this.store$.next({messages:t.messages,dialogId:this.dialogId})}),e.initializeResponsePayload.greetingMessage.length&&this.messageSubject$.next({text:e.initializeResponsePayload.greetingMessage,isComplete:!0,sequenceNumber:e.sequenceNumber,type:"text"})):Ur(e)?this.messageSubject$.next({isComplete:!0,sequenceNumber:0,text:e.inputPayload.textInputContent.text,type:"text",sender:"user"}):Fh(e)?(e.outputPayload.isFinal&&this.component.enableSubmit(),this.messageSubject$.next({text:e.outputPayload.textStreamOutputContent.textPart||"",isComplete:!!e.outputPayload.isFinal,sequenceNumber:e.sequenceNumber,type:"stream"})):Bh(e)&&(this.component.enableSubmit(),this.messageSubject$.next({text:e.outputPayload.textOutputContent.text,isComplete:!0,sequenceNumber:e.sequenceNumber,type:"text"}))}onError(e){console.error("Connection error:",e),this.systemEvents$.next({event:"error",text:"Something went wrong"})}async onClose(e){var s;this.store$.next({messages:[],dialogId:null});const t=this.dialogId;this.started=!1,this.dialogId=null,this.isConnected$.next(!1),this.restartRequested?(console.log("Connection closed with a request to start a new session",e),this.connect()):(console.log("Connection closed",e),await this.reconnect(t),((s=this.ws)==null?void 0:s.readyState)!==WebSocket.OPEN&&(this.dialogId=null,this.systemEvents$.next({event:"disconnected",text:"Connection closed"})))}endSession(){this.ws&&(this.ws.close(),this.started=!1)}rehydrate(e){e.dialogId&&(this.dialogId=e.dialogId),(e.messages||[]).forEach(t=>{this.onMessage(t)})}dispose(){this.restartSubscription$&&this.restartSubscription$.unsubscribe()}}var Wh=Object.defineProperty,Gh=Object.getOwnPropertyDescriptor,ca=(n,e,t,s)=>{for(var i=s>1?void 0:s?Gh(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(i=(s?o(e,t,i):o(i))||i);return s&&i&&Wh(e,t,i),i};let bn=class extends M{_onRestart(){const n=new CustomEvent("action",{composed:!0,detail:{key:"restart-session",data:{}}});this.dispatchEvent(n)}render(){const n=this.application.texts;return w`<div class="container">
1359
+ `];let V=hi;se([N()],V.prototype,"platform");se([N()],V.prototype,"entries");se([N()],V.prototype,"typing");se([N()],V.prototype,"message");se([N()],V.prototype,"disabledInput");se([N()],V.prototype,"disabledSkipToLatest");se([N()],V.prototype,"disabledSubmit");se([N()],V.prototype,"chatOverlayActive");se([N()],V.prototype,"textAreaLength");se([N()],V.prototype,"showAuthBanner");se([N()],V.prototype,"authenticated");const Bh=n=>{var e,t;return!!((e=n==null?void 0:n.outputPayload)!=null&&e.textOutputContent)&&((t=n==null?void 0:n.outputPayload)==null?void 0:t.isFinal)},Fh=n=>{var e;return!!((e=n==null?void 0:n.outputPayload)!=null&&e.textStreamOutputContent)},Hh=n=>{var e;return!!((e=n==null?void 0:n.initializeResponsePayload)!=null&&e.greetingMessage)},jh=n=>!!(n!=null&&n.errorPayload),Ur=n=>{var e,t;return!!((t=(e=n.inputPayload)==null?void 0:e.textInputContent)!=null&&t.text)},qh=n=>(n==null?void 0:n.type)==="handover";class zr{constructor(e,t,s){this.settings=e,this.component=t,this.provider=s,this.started=!1,this.restartRequested=!1,this.currentSequenceNumber=1,this.dialogId=null,this.isConnected$=new H(!1),this.agent$=new H({name:""}),this.messageSubject$=new I,this.systemEvents$=new I,this.store$=new H({messages:[],dialogId:null}),this.retries=0,this.isConnected=()=>this.isConnected$.asObservable(),this.agent=()=>this.agent$.asObservable(),this.messages=()=>this.messageSubject$.asObservable(),this.events=()=>this.systemEvents$.asObservable(),this.restartSubscription$=this.provider.shouldRestart$.subscribe(i=>{this.restartRequested=i})}connect(){this.started||(this.ws=new WebSocket(this.settings.connectionUri),this.ws.onopen=e=>{this.onConnected()},this.ws.onmessage=e=>{const t=JSON.parse(e.data);if(t!=null&&t.text){const s={sequenceNumber:1,outputPayload:{isFinal:!0,textOutputContent:{text:t.text}}};this.onMessage(s)}else this.onMessage(t)},this.ws.onerror=e=>{this.onError(e)},this.ws.onclose=e=>{this.onClose(e)},this.started=!0)}async reconnect(e){}sendMessage(e){const{text:t}=e;if(this.component.disableSubmit(),t.includes("__mockad agent__")){this.systemEvents$.next({event:"handover",text:"",providerKey:"ace-chat",options:{instance:"dt1",engineUrl:"https://widgets.ace.teliacompany.net/engine-simulator/",entrance:"knowsv",errand:"S02"}});return}else if(t.includes("__agent__")){this.systemEvents$.next({event:"handover",text:"",providerKey:"ace-chat",options:{instance:"dt1",engineUrl:"https://chat-dt1.labbn.se/",entrance:"knowsv",errand:"S02"}});return}this._sendMessage({sequenceNumber:this.currentSequenceNumber,inputPayload:{textInputContent:{text:t}}}),this.incrementSequenceNumber()}onConnected(){console.log("Connection established."),this.isConnected$.next(!0),this.retries=0;const e=i=>({sequenceNumber:1,reconnectRequestPayload:{lastReceivedSequenceNumber:2,dialogId:i}}),t=()=>({text:"Hejsan!"});this.systemEvents$.next({event:"connected",text:"Connection established"});const s=this.dialogId?e(this.dialogId):t();this._sendMessage(s)}_sendMessage(e){var t,s;if(!this.isConnected$.value){console.warn("Message could not be sent, you are not connected.");return}Ur(e)?(this.store$.pipe(Ie(1)).subscribe(i=>{this.store$.next({messages:[...i.messages,e],dialogId:i.dialogId})}),(t=this.ws)==null||t.send(JSON.stringify({text:e.inputPayload.textInputContent.text}))):(s=this.ws)==null||s.send(JSON.stringify(e))}incrementSequenceNumber(){this.currentSequenceNumber=this.currentSequenceNumber+1}onMessage(e){if(this.store$.pipe(Ie(1)).subscribe(t=>{this.store$.next({messages:[...t.messages,e],dialogId:t.dialogId})}),jh(e)){this.provider.setShouldRestart(!0),console.debug("Received error from socket connection:",e);return}if(qh(e)){this.systemEvents$.next({event:e.type,text:"",providerKey:"ace-chat",options:{instance:e.data.instance,engineUrl:e.data.engineUrl,entrance:e.data.entrance,errand:e.data.errand}});return}Hh(e)&&e.initializeResponsePayload.greetingMessage.length>0?(this.agent$.next({name:e.initializeResponsePayload.agentName||""}),this.dialogId=e.initializeResponsePayload.dialogId,this.store$.pipe(Ie(1)).subscribe(t=>{this.store$.next({messages:t.messages,dialogId:this.dialogId})}),e.initializeResponsePayload.greetingMessage.length&&this.messageSubject$.next({text:e.initializeResponsePayload.greetingMessage,isComplete:!0,sequenceNumber:e.sequenceNumber,type:"text"})):Ur(e)?this.messageSubject$.next({isComplete:!0,sequenceNumber:0,text:e.inputPayload.textInputContent.text,type:"text",sender:"user"}):Fh(e)?(e.outputPayload.isFinal&&this.component.enableSubmit(),this.messageSubject$.next({text:e.outputPayload.textStreamOutputContent.textPart||"",isComplete:!!e.outputPayload.isFinal,sequenceNumber:e.sequenceNumber,type:"stream"})):Bh(e)&&(this.component.enableSubmit(),this.messageSubject$.next({text:e.outputPayload.textOutputContent.text,isComplete:!0,sequenceNumber:e.sequenceNumber,type:"text"}))}onError(e){console.error("Connection error:",e),this.systemEvents$.next({event:"error",text:"Something went wrong"})}async onClose(e){var s;this.store$.next({messages:[],dialogId:null});const t=this.dialogId;this.started=!1,this.dialogId=null,this.isConnected$.next(!1),this.restartRequested?(console.log("Connection closed with a request to start a new session",e),this.connect()):(console.log("Connection closed",e),await this.reconnect(t),((s=this.ws)==null?void 0:s.readyState)!==WebSocket.OPEN&&(this.dialogId=null,this.systemEvents$.next({event:"disconnected",text:"Connection closed"})))}endSession(){this.ws&&(this.ws.close(),this.started=!1)}rehydrate(e){e.dialogId&&(this.dialogId=e.dialogId),(e.messages||[]).forEach(t=>{this.onMessage(t)})}dispose(){this.restartSubscription$&&this.restartSubscription$.unsubscribe()}}var Wh=Object.defineProperty,Gh=Object.getOwnPropertyDescriptor,ca=(n,e,t,s)=>{for(var i=s>1?void 0:s?Gh(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(i=(s?o(e,t,i):o(i))||i);return s&&i&&Wh(e,t,i),i};let bn=class extends M{_onRestart(){const n=new CustomEvent("action",{composed:!0,detail:{key:"restart-session",data:{}}});this.dispatchEvent(n)}render(){const n=this.application.texts;return w`<div class="container">
1360
1360
  <h3>
1361
1361
  ${n.getOrFallback("restart-dialog.header","Start a new conversation?")}
1362
1362
  </h3>
package/index.mjs CHANGED
@@ -7745,10 +7745,7 @@ class zr {
7745
7745
  dialogId: i
7746
7746
  }
7747
7747
  }), t = () => ({
7748
- sequenceNumber: 1,
7749
- initializeRequestPayload: {
7750
- extension: this.settings.extension
7751
- }
7748
+ text: "Hejsan!"
7752
7749
  });
7753
7750
  this.systemEvents$.next({
7754
7751
  event: "connected",
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@telia-ace/widget-conversational-agent",
3
- "version": "1.1.123-rc.7",
3
+ "version": "1.1.123-rc.9",
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.7",
9
+ "@telia-ace/widget-conversation-flamingo": "1.1.123-rc.9",
10
10
  "rxjs": "^7.8.2",
11
- "@telia-ace/widget-core-flamingo": "1.1.123-rc.7",
11
+ "@telia-ace/widget-core-flamingo": "1.1.123-rc.9",
12
12
  "lit": "^3.0.2",
13
13
  "@lit/context": "^1.1.4"
14
14
  },