@telia-ace/widget-conversational-hub 1.1.12 → 1.1.13
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/connection.d.ts +3 -1
- package/index.d.ts +1 -2
- package/index.js +3 -158
- package/index.mjs +408 -4138
- package/package.json +4 -6
- package/plugin.d.ts +2 -3
- package/provider.d.ts +10 -23
- package/types.d.ts +3 -16
- package/index-5087564d.mjs +0 -335
- package/index-6dd00f59.js +0 -1
- package/utils.d.ts +0 -6
package/connection.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Observable } from 'rxjs';
|
|
2
2
|
import { IConnection } from './connection-interface';
|
|
3
|
-
import { ReceiveMessage, SystemEvent } from './types';
|
|
3
|
+
import { AgentInfo, ReceiveMessage, SystemEvent } from './types';
|
|
4
4
|
type ConnectionSettings = {
|
|
5
5
|
connectionUri: string;
|
|
6
6
|
extension: string;
|
|
@@ -10,10 +10,12 @@ export declare class Connection implements IConnection {
|
|
|
10
10
|
private ws;
|
|
11
11
|
private currentSequenceNumber;
|
|
12
12
|
private isConnected$;
|
|
13
|
+
private agent$;
|
|
13
14
|
private messageSubject$;
|
|
14
15
|
private systemEvents$;
|
|
15
16
|
constructor(settings: ConnectionSettings);
|
|
16
17
|
isConnected: () => Observable<boolean>;
|
|
18
|
+
agent: () => Observable<AgentInfo>;
|
|
17
19
|
messages: () => Observable<ReceiveMessage>;
|
|
18
20
|
events: () => Observable<SystemEvent>;
|
|
19
21
|
sendMessage(payload: {
|
package/index.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { ConversationalHubProviderPlugin };
|
|
1
|
+
export { ConversationalHubProviderPlugin } from './plugin';
|
package/index.js
CHANGED
|
@@ -1,158 +1,3 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Dt=(n,t,e,...s)=>{const i=`[${n.get("$environment").name||"webprovisions"}] ${e}`;switch(t){case"info":console.info(i,...s);break;case"warning":console.warn(i,...s);break;case"error":console.error(i,...s);break}},Ws=n=>{const t=n.container||n;return{info:(e,...s)=>Dt(t,"info",e,...s),warn:(e,...s)=>Dt(t,"warning",e,...s),error:(e,...s)=>Dt(t,"error",e,...s)}};var tt=(n=>(n.Implementation="implementation",n.Widget="widget",n))(tt||{}),N=(n=>(n.Pre="pre",n.Post="post",n))(N||{});const Ls=(n,t,e,s)=>{try{const i=new t(e,s);return{name:n,invoke:(r,o)=>{let a;return i[r]&&(a=i[r].call(i,o)),Promise.resolve(a)},getInstance:()=>i}}catch(i){if(i.message&&i.message.indexOf("is not a constructor")>=0)return{name:n,invoke:r=>{let o;return r==="initialize"&&(o=t(e,s)),Promise.resolve(o)},getInstance:()=>t};throw i}};function Oe(n,t){return typeof n>"u"?t:n}let zs=class{constructor(t={}){this.part=t}createCommand(t,e,s){let i;typeof e=="function"?i={scope:tt.Widget,stage:N.Post,defaultArgs:void 0,handlerResolver:e}:i={scope:Oe(e.scope,tt.Widget),stage:Oe(e.stage,N.Post),defaultArgs:e.defaultArgs,handlerResolver:s};let r=this.part;const o=t.split(".");return o.forEach((a,c)=>{c===o.length-1?r[a]||(r[a]=()=>i):r=this.part[a]=this.part[a]||{}}),this}get(){return this.part}};const us=n=>{const t=new zs({});return n(t),t.get()};us(n=>{n.createCommand("types.register",{scope:tt.Implementation,stage:N.Pre},t=>(e,s)=>{t.container.get("$types")[e]=s}).createCommand("type",{stage:N.Pre},t=>e=>{t.container.register("$type",e)}).createCommand("settings",{stage:N.Pre,defaultArgs:[null]},t=>e=>{t.events.dispatch("settings:change",e,{bubbles:!0}),t.container.register("$settings",e)}).createCommand("plugin",{stage:N.Pre},t=>(e,s,i)=>{const{container:r}=t;let o=null,a=e,c=s;typeof e=="string"&&(o=e,a=s,c=i);const h=l=>{const{transformPluginSettings:u}=t.container.get("$environmentOptions"),p=u?u(c||{},o,t.container,a):s;try{const d=Ls(o,a,r,p);r.get("$plugins").push(d),l&&d.invoke("initialize",null)}catch(d){Ws(t).warn("Error when initializing plugin",d)}};t.container.get("$instance")?h(!0):t.events.subscribeOnce("widget:instance-created",()=>h(!1))}).createCommand("container.register",t=>(e,s)=>{t.container.register(e,s)}).createCommand("container.registerAsync",t=>(e,s)=>{t.container.registerAsync(e,s)}).createCommand("container.registerFactory",t=>(e,s)=>{t.container.registerFactory(e,s)}).createCommand("container.touch",t=>(e,s)=>{t.container.touch(e,s)}).createCommand("csp",{},t=>e=>{t.container.register("csp",e)})});const Bs=us(n=>{n.createCommand("ready",{scope:tt.Implementation,stage:N.Pre},t=>e=>{const{container:s}=t,i=s.owner;s.get("bootstrapping").ready?e(i):i.events.subscribeOnce("bootstrap:ready",()=>{e(i)})})}),Ht=new WeakMap;function F(){return n=>(Ht.has(n)||Ht.set(n,{}),Ht.get(n))}const Rt=(n,t,e,...s)=>{const i=`[${n.get("$environment").name||"webprovisions"}] ${e}`;switch(t){case"info":console.info(i,...s);break;case"warning":console.warn(i,...s);break;case"error":console.error(i,...s);break}},$=n=>{const t=n.container||n;return{info:(e,...s)=>Rt(t,"info",e,...s),warn:(e,...s)=>Rt(t,"warning",e,...s),error:(e,...s)=>Rt(t,"error",e,...s)}},g=F(),he=(()=>{let n=0;return()=>++n})(),le=(n,t,e)=>{const s=g(n).touchQueue.get(t);s&&s.forEach(i=>{i(e,n)})};let Vs=class{constructor(t,e,s,i){this.key=t,this.factory=e,this.parent=s,this.container=i,this.id=he(),this.resolved=!1,this.constructed=!1,this.async=!0}resolve(){if(!this.constructed){const t=this.factory(this.parent,this.container);return this.constructed=!0,this.value=Promise.resolve(t).then(e=>(this.resolved=!0,le(this.container,this.key,e),e))}return this.value}},qs=class{constructor(t,e,s,i){this.key=t,this.value=e,this.parent=s,this.container=i,this.id=he(),this.async=!1,this.resolved=!1,this.constructed=!0,this.resolve=()=>(this.resolved=!0,le(this.container,this.key,this.value),this.value)}},Fs=class{constructor(t,e,s,i){this.key=t,this.value=e,this.parent=s,this.container=i,this.id=he(),this.async=!1,this.resolved=!1,this.constructed=!1,this.resolve=()=>{this.resolved=!0,this.constructed=!0;const r=this.value(this.parent,this.container);return le(this.container,this.key,this.value),r}}},Js=class ds{constructor(t,e,s){this.owner=t,this.name=e,this.parent=s,g(this).resolvers=new Map,g(this).touchQueue=new Map,g(this).children=[]}delete(t){const e=g(this).resolvers,s=Array.from(e.values()).find(i=>i.id===t);return s?(g(this).touchQueue.delete(s.key),Promise.resolve(e.delete(s.key))):this.parent?this.parent.delete(t):Promise.resolve(!1)}clear(){const t=g(this).resolvers,e=Array.from(t.values());return Promise.all(e.map(s=>{if(s.constructed)return Promise.resolve(s.resolve()).then(i=>{if(i!==null&&typeof i=="object"&&typeof i.dispose=="function")return i.dispose.call(i,this,s)})})).then(()=>{e.forEach(s=>this.delete(s.id)),g(this).children.forEach(s=>s.clear())})}detach(){if(this.parent){const t=g(this.parent).children,e=t.indexOf(this);e>-1&&(t.splice(e,1),delete this.parent)}}touch(t,e){const s=g(this).resolvers.get(t);if(s&&s.constructed)Promise.resolve(s.resolve()).then(i=>{e(i,this)});else{const i=g(this).touchQueue;let r=i.get(t);r||(r=[],i.set(t,r)),r.push(e)}return this.parent&&!s?this.parent.touch(t,e):Promise.resolve()}registerAsync(t,e){const s=g(this).resolvers.get(t);s&&!s.async&&process.env.NODE_ENV!=="production"&&$(this).warn(`Mismatching resolver type. You are registering an async resolver with a key ('${t}') previously used by a non-async resolver.`);const i=new Vs(t,e,s,this);return g(this).resolvers.set(t,i),i.id}registerFactory(t,e){const s=g(this).resolvers.get(t);s&&s.async&&process.env.NODE_ENV!=="production"&&$(this).warn(`Mismatching resolver type. You are registering a non-async resolver with a key ('${t}') previously used by an async resolver.`);const i=new Fs(t,e,s,this);return g(this).resolvers.set(t,i),i.id}register(t,e){const s=g(this).resolvers.get(t);s&&s.async&&process.env.NODE_ENV!=="production"&&$(this).warn(`Mismatching resolver type. You are registering a non-async resolver with a key ('${t}') previously used by an async resolver.`);const i=new qs(t,e,s,this);return g(this).resolvers.set(t,i),i.id}get(t){const e=g(this).resolvers.get(t);if(e)return e.async&&process.env.NODE_ENV!=="production"&&$(this).warn(`You are retrieving an async value (with key '${t}') by the non-async function 'container.get(key)'. This will not be supported in future versions. Use 'container.getAsync(key) instead.'`),e.resolve();if(this.parent)return this.parent.get(t)}getAsync(t){const e=g(this).resolvers.get(t);if(e){if(!e.async)throw process.env.NODE_ENV!=="production"&&$(this).warn(`You are retrieving a non-async value (with key '${t}') by the async function 'container.getAsync(key)'.Use 'container.get(key) instead.'`),"Mismatching resolver type";return e.resolve()}return this.parent?this.parent.getAsync(t):Promise.resolve(void 0)}getMany(...t){const e={};return t.forEach(s=>e[s]=this.get(s)),e}getManyAsync(...t){const e={};return Promise.all(t.map(s=>this.getAsync(s).then(i=>e[s]=i))).then(()=>e)}createChild(t,e){const s=new ds(t,e,this);return g(this).children.push(s),s}},ke=class{constructor(t,e,s=!1,i=!1){this.type=t,this.target=e,this.cancelable=!!s,this.bubbles=!!i,this.defaultPrevented=!1}preventDefault(){this.cancelable&&(this.defaultPrevented=!0)}};const A=F(),Te=(n,t)=>[].concat(A(n).listenerLookup.get(t.toLowerCase())||[],A(n).listenerLookup.get("*")||[]),Ne=(n,t,e,s)=>{let i,r;return t instanceof ke?(i=t,r=t.type):(i=new ke(t,n.target,!!e.cancelable,!!e.bubbles),r=t),{event:i,type:r,async:s}};let Ks=class ps{constructor(t,e){this.target=t,this.parent=e,A(this).listenerLookup=new Map,A(this).children=[]}clear(){A(this).listenerLookup.clear(),A(this).children.forEach(t=>t.clear())}detach(){if(this.parent){const t=A(this.parent).children,e=t.indexOf(this);e>-1&&t.splice(e,1)}}subscribe(t,e,s){const i=A(this).listenerLookup,r=t.toLowerCase();return i.has(r)||i.set(r,[]),i.get(r).push(e),()=>this.unsubscribe(t,e)}subscribeOnce(t,e){const s=this.subscribe(t,(i,r)=>(s(),e(i,r)))}unsubscribe(t,e){const s=A(this).listenerLookup.get(t.toLowerCase());if(s){const i=s.indexOf(e);i>-1&&s.splice(i,1)}}dispatchAsync(t,e,s={}){const{event:i,type:r}=Ne(this,t,s,!0),o=Te(this,r);let a=0;const c=o.length;let h=Promise.resolve();for(a=0;a<c;a++)(l=>{h=h.then(u=>u?Promise.resolve(!0):Promise.resolve(l(i,e)).then(()=>i.defaultPrevented))})(o[a]);return h.then(l=>!l&&i.bubbles&&this.parent?this.parent.dispatchAsync(i,e):l)}dispatch(t,e,s={}){const{event:i,type:r}=Ne(this,t,s,!1),o=Te(this,r);let a=0;const c=o.length;let h=!1;for(a=0;a<c;a++)if(o[a](i,e),i.defaultPrevented){h=!0;break}return!h&&i.bubbles&&this.parent&&(h=this.parent.dispatch(i,e)),h}createChild(t){const e=new ps(t,this);return A(this).children.push(e),e}};const ct=(n,t,e)=>{const s=n.get("$plugins").map(i=>{try{return i.invoke(t,e)}catch(r){$(n).error("An error occured when invoking a plugin.",i,r)}});return Promise.all(s)};let Qs=class{constructor(t){this.widget=t.get("$widget"),this.events=this.widget.events,this.container=this.widget.container,this.initialized=null,this.activated=null,this.initialize=this.initialize.bind(this),this.activate=this.activate.bind(this),this.deactivate=this.deactivate.bind(this),this.invoke=this.invoke.bind(this),this.createInstance()}createInstance(){if(!this.widget.container.get("$instance")){const t=this.widget.container.get("$types"),e=this.widget.container.get("$type");!e&&$(this).error("Unable to create widget. No type is specified.");const s=t[e];!s&&$(this).error(`Unable to create widget. Type '${e}' is not registered.`),this.widget.events.dispatch("widget:create-instance",{},{bubbles:!0});try{this.widget.container.register("$instance",new s(this.container))}catch(i){$(this).error("Unable to create widget type.",i)}this.widget.events.dispatch("widget:instance-created",{},{bubbles:!0})}}initialize(t){return this.initialized=this.initialized||(()=>{const e=this.container.get("$instance"),s=e.initialize||(()=>{});return this.initialized=Promise.resolve(s.call(e,t)).then(()=>ct(this.container,"initialize",t)).then(()=>{})})()}activate(t){return(this.initialized||this.initialize()).then(()=>{this.activated=this.activated||(()=>ct(this.container,"activate").then(()=>{const e=this.container.get("$instance");return this.activated=e.activate(t)}))()})}deactivate(){const t=this.container.get("$instance"),e=t.deactivate||(()=>{});return ct(this.container,"deactivate").then(()=>Promise.resolve(e.call(t))).then(()=>{this.initialized=null,this.activated=null}).then(()=>{})}invoke(t,...e){return ct(this.container,"invoke",{command:t,args:e}).then(()=>{const s=this.container.get("$instance");if(s[t])return s[t].apply(s,e);const i=s.invoke;if(i)return i.call(s,t,...e)})}};const z=(n,t)=>{if(!t)return!0;if(typeof t=="string"){const e=t.split(",");for(let s=0,i=e.length;s<i;s++){const r=e[s].trim();if(r===n||r==="*")return!0}}return t instanceof Array?t.indexOf(n)>-1:!1},Ys=(n,t)=>{if(typeof t=="function")return t(n);const e=typeof t=="string"?Xs(t):t;return!(!z(n.implementation.tenant||"",e.tenant||"")||!z(n.implementation.name,e.implementation||"")||!z(n.name,e.widget||"")||!z(n.container.get("$type"),e.type||""))},Zs=(n,t)=>{if(typeof t=="function")return t(n);const e=typeof t=="string"?tn(t):t;return!(!z(n.tenant||"",e.tenant||"")||!z(n.name,e.implementation||""))},gs=n=>t=>Ys(t,n),Gs=n=>t=>Zs(t,n),P=n=>n instanceof Array&&n.length===1?n[0]:n,Xs=n=>{const t={},e=n.split(":");return e.length===1?t.widget=P(e[0].split(",")):e.length===2?(t.implementation=P(e[0].split(",")),t.widget=P(e[1].split(","))):(t.tenant=P(e[0].split(",")),t.implementation=P(e[1].split(",")),t.widget=P(e[2].split(","))),t},tn=n=>{const t={},e=n.split(":");return e.length===1?t.implementation=P(e[0].split(",")):(t.tenant=P(e[0].split(",")),t.implementation=P(e[1].split(","))),t},yt=F(),Me=(n,t,e)=>n.filter(s=>s.stage===t&&gs(s.selector)(e));function en(n){const t=n.container.get("$environment");let e=yt(t).configurationCache;e&&(e=e.filter(s=>s[0]!==n),yt(t).configurationCache=e)}var bt=(n=>(n.Implementation="implementation",n.Widget="widget",n))(bt||{}),C=(n=>(n.Pre="pre",n.Post="post",n))(C||{});const fs=(n,t,e)=>(Object.keys(t).forEach(s=>{const i=t[s];if(typeof i=="function"){const r=i();typeof r.defaultArgs<"u"&&e(r,...r.defaultArgs),n[s]=(...o)=>{const a=Object.assign({},r,{handlerResolver:r.handlerResolver.bind({})});return e(a,...o),n}}else n[s]=fs({},i,e)}),n),sn=(n,t)=>{switch(t){case"implementation":return n.implementation;case"widget":return n}},Ie=(n,t,e,s)=>(s.forEach(i=>{fs(n,i,(r,...o)=>{const a={selector:t,stage:r.stage,handler:c=>{const h=sn(c,r.scope),l={container:h.container,events:h.events},u=r.handlerResolver,p=u(l);let d=yt(e.environment).configurationCache;return d||(d=yt(e.environment).configurationCache=[]),d.find(v=>v.indexOf(h)>-1&&v.indexOf(u)>-1)?Promise.resolve():(d.push([h,u]),Promise.resolve(p(...o)))}};e.instructions.push(a)})}),n);function nn(n,t){function e(s){return Ie({},s,n,t)}return Ie(e,"*",n,t)}const rn=(n,t,e,s)=>{try{const i=new t(e,s);return{name:n,invoke:(r,o)=>{let a;return i[r]&&(a=i[r].call(i,o)),Promise.resolve(a)},getInstance:()=>i}}catch(i){if(i.message&&i.message.indexOf("is not a constructor")>=0)return{name:n,invoke:r=>{let o;return r==="initialize"&&(o=t(e,s)),Promise.resolve(o)},getInstance:()=>t};throw i}};function je(n,t){return typeof n>"u"?t:n}let on=class{constructor(t={}){this.part=t}createCommand(t,e,s){let i;typeof e=="function"?i={scope:bt.Widget,stage:C.Post,defaultArgs:void 0,handlerResolver:e}:i={scope:je(e.scope,bt.Widget),stage:je(e.stage,C.Post),defaultArgs:e.defaultArgs,handlerResolver:s};let r=this.part;const o=t.split(".");return o.forEach((a,c)=>{c===o.length-1?r[a]||(r[a]=()=>i):r=this.part[a]=this.part[a]||{}}),this}get(){return this.part}};const ms=n=>{const t=new on({});return n(t),t.get()},an=ms(n=>{n.createCommand("types.register",{scope:bt.Implementation,stage:C.Pre},t=>(e,s)=>{t.container.get("$types")[e]=s}).createCommand("type",{stage:C.Pre},t=>e=>{t.container.register("$type",e)}).createCommand("settings",{stage:C.Pre,defaultArgs:[null]},t=>e=>{t.events.dispatch("settings:change",e,{bubbles:!0}),t.container.register("$settings",e)}).createCommand("plugin",{stage:C.Pre},t=>(e,s,i)=>{const{container:r}=t;let o=null,a=e,c=s;typeof e=="string"&&(o=e,a=s,c=i);const h=l=>{const{transformPluginSettings:u}=t.container.get("$environmentOptions"),p=u?u(c||{},o,t.container,a):s;try{const d=rn(o,a,r,p);r.get("$plugins").push(d),l&&d.invoke("initialize",null)}catch(d){$(t).warn("Error when initializing plugin",d)}};t.container.get("$instance")?h(!0):t.events.subscribeOnce("widget:instance-created",()=>h(!1))}).createCommand("container.register",t=>(e,s)=>{t.container.register(e,s)}).createCommand("container.registerAsync",t=>(e,s)=>{t.container.registerAsync(e,s)}).createCommand("container.registerFactory",t=>(e,s)=>{t.container.registerFactory(e,s)}).createCommand("container.touch",t=>(e,s)=>{t.container.touch(e,s)}).createCommand("csp",{},t=>e=>{t.container.register("csp",e)})}),cn=an;function hn(n,t,e=[]){const s=[cn].concat(e),i=nn(t,s);n(i,t)}let ln=class{constructor(){this.tasks=[],this.current=Promise.resolve(),this.next=this.next.bind(this)}add(t,e,s,i){this.tasks.push({task:t,resolve:e,reject:s,done:i}),this.next()}next(){this.current=this.current.then(()=>{const t=this.tasks.shift();if(t){const e=Promise.resolve(t.task());return Promise.resolve(e).then(this.next).then(()=>e.then(s=>{t.done(),t.resolve(s)})).catch(s=>(t.done(),t.reject(s),this.next()))}return Promise.resolve()})}};const ht=new WeakMap;function un(n){return ht.has(n)||ht.set(n,new ln),t=>new Promise((e,s)=>{const i=ht.get(n);i.add(t,e,s,()=>{i.tasks.length||ht.delete(n)})})}const Ue=n=>typeof n<"u",K=(n,t)=>{n.events.dispatch("widget:state-change",{state:t},{bubbles:!0}),n.state=t,n.events.dispatch("widget:state-changed",{},{bubbles:!0})},E=F(),dn=n=>{const{container:t,events:e}=n;t.get("$controller")||(t.register("$controller",new Qs(t)),e.dispatch("widget:controller-created",{},{bubbles:!0}))};class pn{constructor(t,e,s){this.state="deactivated",this.name=t,this.implementation=e,this.container=e.container.createChild(this,t),this.events=e.events.createChild(this),E(this).subscriptions=[],s&&e.configure(i=>{const r=i(t);Ue(s.type)&&r.type(s.type),Ue(s.settings)&&r.settings(s.settings),s.plugins&&Object.keys(s.plugins).forEach(o=>{var a;const c=(a=s.plugins)==null?void 0:a[o];r.plugin(o,c)})}),this.load=this.load.bind(this),this.activate=this.activate.bind(this),this.invoke=this.invoke.bind(this),this.deactivate=this.deactivate.bind(this)}load(){return un(this)(()=>{E(this).deactivatedPromise=null;const t=this.state==="deactivated";t&&(K(this,"activating"),this.container.register("$widget",this),this.container.register("$controller",null),this.container.register("$plugins",[]),this.container.register("$type",null),this.container.register("$instance",null)),K(this,"loading");const e=this.implementation.instructions,s=Me(e,C.Pre,this);return Promise.all(s.map(i=>i.handler(this))).then(()=>{dn(this);const i=Me(e,C.Post,this);return Promise.all(i.map(r=>r.handler(this))).then(()=>{t&&this.container.get("$controller").initialize()})}).then(()=>(K(this,"activated"),this))})}activate(t){E(this).subscriptions.push(this.implementation.events.subscribe("implementation:configured",()=>{["activated","activating","loading"].indexOf(this.state)>-1&&this.load()}));const e=E(this).activatedPromise;return e?(process.env.NODE_ENV!=="production"&&$(this).warn(`Widget '${this.name}' has already been activated. The passed arguments for this activation will be discarded.`,t),e):E(this).activatedPromise=this.load().then(()=>this.container.get("$controller").activate(t))}invoke(t,...e){const s=E(this).activatedPromise,i=(r,...o)=>s.then(this.load).then(()=>this.container.get("$controller").invoke(r,...o));return s?i(t,...e):(process.env.NODE_ENV!=="production"&&$(this).warn("You are invoking a command on a deactivated widget. The invocation will be queued until the widget is activated.",this),new Promise(r=>{const o=this.events.subscribe("widget:state-changed",()=>{this.state==="activated"&&(o(),r(i(t,...e)))})}))}deactivate(){return E(this).deactivatedPromise||(this.state==="deactivated"?Promise.resolve():(K(this,"deactivating"),E(this).deactivatedPromise=this.container.get("$controller").deactivate().then(()=>(E(this).activatedPromise=null,E(this).subscriptions.forEach(e=>e()),E(this).subscriptions=[],this.container.clear().then(()=>{this.events.clear(),en(this),K(this,"deactivated")})))))}}const De=F();class gn{constructor(t,e,s=[]){this.instructions=[],this.widgets=new Map,this.name=t.name,this.tenant=t.tenant,this.environment=e,this.container=e.container.createChild(this,this.name),this.events=e.events.createChild(this),this.container.register("$types",{}),De(this).configurationApiExtensions=s}load(){const t=Array.from(this.widgets.values());return Promise.all(t.map(e=>e.load())).then(()=>t)}configure(t){return hn(t,this,De(this).configurationApiExtensions),this.events.dispatch("implementation:configured",{implementation:this},{bubbles:!0}),this}createWidget(t,e){const s=new pn(t,this,e);return this.widgets.set(s.name,s),s}}function fn(n,t,e){const s=new gn(n,t,e);return n.widgets&&Object.keys(n.widgets).forEach(i=>{var r;const o=(r=n.widgets)==null?void 0:r[i];s.createWidget(i,o)}),s}let He=class vs{constructor(t,e){this.selectorFactory=e,typeof t=="function"?this.resolver=t:this.resolver=()=>t}append(t){const e=typeof t=="function"?t:()=>t;return new vs(()=>this.all().concat(e()),this.selectorFactory)}all(){return this.resolver().concat([])}query(t){return this.all().filter(this.selectorFactory(t))}find(t){const e=this.query(t);if(e.length)return e[0]}};const ue="#____version____#",Wt=F(),mn=n=>n.tenant?`${n.name}:${n.tenant}`:n.name,ys=class{constructor(t,e=[],s={}){this.widgets=new He(()=>{let i=[];return this.implementations.all().forEach(r=>{i=i.concat(Array.from(r.widgets.values()))}),i},gs),this.implementations=new He([],Gs),this.name=t,this.container=new Js(this,t),this.events=new Ks(this),this.container.register("$version",ue),this.container.register("$environment",this),this.container.register("$environmentOptions",s),Wt(this).configurationApiExtensions=e}createImplementation(t){const e=mn(t);let s=this.implementations.find(e);if(s)return process.env.NODE_ENV!=="production"&&$(s).warn(`Implementation "${e}" already exist on current environment.`),s;const i=Wt(this).configurationApiExtensions;return s=fn(t,this,i),this.implementations=this.implementations.append([s]),this.events.dispatch("implementation:created",{implementation:s}),s}patch(t={}){const{name:e,configurationApiExtensions:s}=t;typeof e<"u"&&e!==null&&(this.name=e),s&&s.forEach(i=>{Wt(this).configurationApiExtensions.push(i)})}static create(t={}){return new ys(t.name||"",t.configurationApiExtensions,t.options)}};let bs=ys;bs.version=ue;const Pt=(n,t,...e)=>typeof t=="string"?n(`[humany] ${t}`,...e):n(t,...e),Y=class{constructor(){this.keys=[],this.log=(t,...e)=>this.lookup(t,()=>Y.log(...e)),this.warn=(t,...e)=>this.lookup(t,()=>Y.warn(...e)),this.error=(t,...e)=>this.lookup(t,()=>Y.error(...e)),this.info=(t,...e)=>this.lookup(t,()=>Y.info(...e))}lookup(t,e){this.keys.indexOf(t)===-1&&(this.keys.push(t),e())}};let w=Y;w.log=(...n)=>Pt(console.log,...n);w.warn=(...n)=>Pt(console.warn,...n);w.error=(...n)=>Pt(console.error,...n);w.info=(...n)=>Pt(console.info,...n);const $s=n=>{let t={},e,s;if(typeof n!="object"||n===null)return n;t=Array.isArray(n)?[]:{};for(s in n)e=n[s],t[s]=typeof e=="object"&&e!==null?$s(e):e;return t},vn=$s;function Re(n){let t=0;if(n.length===0)return t.toString();for(let e=0;e<n.length;e++){const s=n.charCodeAt(e);t=(t<<5)-t+s,t=t&t}return t.toString()}let yn=class{constructor(t,e){this.lockWarningTime=t,this.lockErrorTime=e,this.tasks=[],this.current=Promise.resolve(),this.next=this.next.bind(this)}add(t,e,s,i){this.tasks.push({task:t,resolve:e,reject:s,done:i}),this.next()}next(){this.current=this.current.then(()=>{const t=this.tasks.shift();if(t){let e;const s=setTimeout(()=>{process.env.NODE_ENV!=="production"&&w.warn(`A lock has exceeded ${this.lockWarningTime} ms. Waiting additional ${this.lockErrorTime} ms before rejecting the task.`,t),e=setTimeout(()=>{t.reject("lock timeout exceeded")},this.lockErrorTime)},this.lockWarningTime),i=Promise.resolve(t.task()).then(r=>(clearTimeout(s),clearTimeout(e),r));return Promise.resolve(i).then(this.next).then(()=>i.then(r=>{t.done(),t.resolve(r)})).catch(r=>(t.done(),t.reject(r),this.next()))}return Promise.resolve()})}};const lt=new WeakMap;function it(n,t=5e3,e=1e3){return lt.has(n)||lt.set(n,new yn(t,e)),s=>new Promise((i,r)=>{const o=lt.get(n);o.add(s,i,r,()=>{o.tasks.length||lt.delete(n)})})}const k=()=>Math.floor((1+Math.random())*65536).toString(16).substring(1);function I(){return k()+k()+"-"+k()+"-"+k()+"-"+k()+"-"+k()+k()+k()}var bn=Object.defineProperty,$n=Object.defineProperties,wn=Object.getOwnPropertyDescriptors,We=Object.getOwnPropertySymbols,_n=Object.prototype.hasOwnProperty,En=Object.prototype.propertyIsEnumerable,Le=(n,t,e)=>t in n?bn(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,Xt=(n,t)=>{for(var e in t||(t={}))_n.call(t,e)&&Le(n,e,t[e]);if(We)for(var e of We(t))En.call(t,e)&&Le(n,e,t[e]);return n},An=(n,t)=>$n(n,wn(t));const xn=n=>{const t=[];return[(e,s)=>{t.push(n.subscribe(e,s))},()=>{t.forEach(e=>{e()})}]};let ws=class{constructor(t,e=[]){this.platform=t,this.rules=e}match(t){return this.rules.every(e=>!(e.id&&e.id!==t.id||e.type&&e.type!==t.type))}ofType(t){return this.rules.push({type:t}),this}withId(t){return this.rules.push({id:t}),this}select(){return new Pn(this.platform,this)}},Sn=class{constructor(t,e,s){this.platform=t,this.node=e,this.actions=new de(t,new ws(t).withId(e.id),s);const[i,r]=xn(this.platform.events);this.subscribe=i,this.unsubscribe=r}properties(t){return t&&this.node.touchProperties(e=>t(e)),this.node.attributes.properties}context(t){return t&&this.subscribe("components:context-changed",(e,{node:s})=>{s===this.node&&t(this.node.attributes.context)}),this.node.attributes.context}layout(t){return t&&this.subscribe("components:layout-changed",(e,{node:s})=>{s===this.node&&t(this.node.attributes.layout)}),this.node.attributes.layout}writeProperties(t,e){this.node.writeProperties(t,e)}writeContext(t,e){this.node.writeProperties(t,e)}writeLayout(t,e){this.node.writeLayout(t,e)}dispose(){this.unsubscribe(),this.actions.dispose()}};class Pn{constructor(t,e,s=!0){this.platform=t,this.target=e,this.clearOnDispose=s,this.removes=[],this.actions=new de(this.platform,this.target)}writeProperties(t,e){this.removes.push(this.platform.write({options:e,attributes:{properties:t},target:this.target,removable:this.clearOnDispose}))}writeContext(t,e){this.removes.push(this.platform.write({options:e,attributes:{context:t},target:this.target,removable:this.clearOnDispose}))}writeLayout(t,e){this.removes.push(this.platform.write({options:e,attributes:{layout:t},target:this.target,removable:this.clearOnDispose}))}dispose(){this.removes.forEach(t=>{t()}),this.actions.dispose()}}const Cn=(n,t,e)=>{const s=n.concat(),i=(r,o,a)=>{let c=!0;if(s.length){const h=s.shift(),l=(u,p)=>(c=!1,i(u,Object.assign({},o,p),a));return Promise.resolve(h(r,l,a)).then(u=>An(Xt({},u),{cancelled:c}))}return Promise.resolve({data:r,cancelled:!1,options:o})};return i(t,{},e)};let de=class{constructor(t,e,s){this.platform=t,this.target=e,this.ns=s,this.subscriptions=[],this.create=this.create.bind(this)}create(t,e=()=>{}){const s={key:t,fn:e,target:this.target,ns:this.ns};this.platform.actionsState.handlers.push(s);const i=()=>{const r=this.platform.actionsState.handlers.indexOf(s);r>-1&&this.platform.actionsState.handlers.splice(r,1)};return this.subscriptions.push(i),i}dispatch(t,e){const s=this.platform.nodes.all.concat(this.platform.nodes.detached),i={},r=this.platform.actionsState.handlers.filter(o=>o.key===t&&(!o.ns||!this.ns||o.ns===this.ns));return Promise.all(r.map(o=>{const a=s.filter(h=>o.target.match(h)&&this.target.match(h)),c=this.platform.actionsState.watchers.filter(h=>h.key===t&&(!h.ns||!this.ns||h.ns===this.ns)&&a.some(l=>h.target.match(l))).map(h=>h.fn);return Promise.all(a.map(h=>{const l=new Sn(this.platform,h,this.ns);return Cn(c,e,l).then(u=>{const{data:p={},options:d,cancelled:v}=u;return Promise.resolve(v?{}:o.fn(p,d,l)).then(m=>{i[h.id]=m})})}))})).then(()=>i)}watch(t,e){let s=t,i=this.ns;const r=t.split(".");r.length>1&&(i=r[0],s=r.splice(1).join("."));const o={fn:e,target:this.target,key:s,ns:i};this.platform.actionsState.watchers.push(o);const a=()=>{const c=this.platform.actionsState.watchers.indexOf(o);c>-1&&this.platform.actionsState.watchers.splice(c,1)};return this.subscriptions.push(a),a}dispose(){this.subscriptions.forEach(t=>t())}};ms(n=>{n.createCommand("components",t=>e=>{t.events.subscribeOnce("components:platform-created",(s,{platform:i})=>{e.handlers&&e.handlers.forEach(([r,o])=>{i.addComponentHandler(r,o)})})})});let ze=class{constructor(t,e){this.events=t,this.tags=[],this.children={},this.changesets=[],this.mountCount=0,this.id=I(),this.type=e,this.attributes={context:{},properties:{},layout:{},tags:[]},this.writeLayout({size:"full",indent:0})}mount(t,e){let s=t.get("mounted-nodes");return s||(s=new Map,t.register("mounted-nodes",s)),s.has(this)?(process.env.NODE_ENV!=="production"&&w.error("Trying to mount an already mounted component node.",this),()=>{}):(this.events.dispatch("components:node-mounted",{node:this}),this.mountCount===0&&(this.mountCount=this.mountCount+1,this.events.dispatch("components:node-enter",{node:this})),()=>{s.delete(this),this.events.dispatch("components:node-unmounted",{node:this}),this.mountCount=this.mountCount-1,this.mountCount===0&&this.events.dispatch("components:node-exit",{node:this})})}appendChild(t,e="default"){if(t.parent){if(t.parent===this)return;t.parent.removeChild(t)}t.parent=this,this.children[e]||(this.children[e]=[]),this.children[e].push(t),this.events.dispatch("components:node-appended",{node:t})}prependChild(t,e="default"){if(t.parent){if(t.parent===this)return;t.parent.removeChild(t)}t.parent=this,this.children[e]||(this.children[e]=[]),this.children[e].unshift(t),this.events.dispatch("components:node-appended",{node:t})}touchProperties(t,e={},s){const i=[{properties:t},e];return this.changesets.push(i),this.events.dispatch("components:set-properties",{node:this}),()=>{if(s){const r=this.changesets.indexOf(i);r>-1&&(this.changesets.splice(r,1),this.events.dispatch("components:set-properties",{node:this}))}}}writeProperties(t,e={},s){const i=[{properties:t},e];return this.changesets.push(i),this.events.dispatch("components:set-properties",{node:this}),()=>{if(s){const r=this.changesets.indexOf(i);r>-1&&(this.changesets.splice(r,1),this.events.dispatch("components:set-properties",{node:this}))}}}writeLayout(t,e={},s){const i=[{layout:t},e];return this.changesets.push(i),this.events.dispatch("components:set-layout",{node:this}),()=>{if(!s)return;const r=this.changesets.indexOf(i);r>-1&&(this.changesets.splice(r,1),this.events.dispatch("components:set-layout",{node:this}))}}writeContext(t,e={},s){const i=[{context:t},e];return this.changesets.push(i),this.events.dispatch("components:set-context",{node:this}),()=>{if(!s)return;const r=this.changesets.indexOf(i);r>-1&&(this.changesets.splice(r,1),this.events.dispatch("components:set-context",{node:this}))}}getChildren(t="default"){const e=this.children[t]||[];return e.reduce((s,i,r)=>{const{order:o=r}=i.attributes.layout;return s[o]?s.splice(o,0,i):s[o]=i,s},Array(e.length))}remove(){this.parent&&this.parent.removeChild(this)}removeChild(t){Object.keys(this.children).forEach(e=>{const s=this.children[e],i=s.indexOf(t);i>-1&&(s.splice(i,1),this.events.dispatch("components:node-removed",{node:t,parentNode:this}))}),delete t.parent}};const _s=(n,t,e)=>{for(let s=0,i=n.length;s<i&&e(n[s])!==!0;s++){const r=t[n[s].id]||"default",o=n[s].getChildren(r);_s(o,t,e)}},pe=(n,t,e)=>{if(e(n)!==!0){const s=t[n.id]||"default",i=n.children[s];_s(i,t,e)}},Lt=(n,t)=>{const e=[];return pe(n,t,s=>{e.push(s)}),e},On=(n,t,e)=>{let s;return pe(n,t,i=>{if(e(i))return s=i,!0}),s};class kn{constructor(t,e,s){this.root=t,this.switches=e,this.all=[],this.visible=[],this.detached=[],s.subscribe("components:node-appended",(i,r)=>{this.all.push(r.node),this.visible=Lt(t,e)}),s.subscribe("components:node-removed",(i,r)=>{let o=this.all.indexOf(r.node);o>-1&&this.all.splice(o,1),o=this.visible.indexOf(r.node),o>-1&&this.visible.splice(o,1),this.visible=Lt(t,e)}),s.subscribe("components:node-switched",(i,r)=>{this.visible=Lt(t,e)})}query(t={}){const e=[];return pe(this.root,this.switches,s=>{Object.keys(t).every(i=>t[i]===s[i])&&e.push(s)}),e}get(t){return On(this.root,this.switches,e=>e.id===t)||this.detached.find(e=>e.id===t)}}class Tn{constructor(){this.handlers=new Map}add(t,e){this.handlers.set(t,e)}get(t){return this.handlers.get(t)}}const Nn=n=>{let t=n,e=0;for(;t.parent;)e=e+1,t=t.parent;return e},Mn=n=>n.map(([t,e])=>[Nn(t),t,e]).sort(([t],[e])=>t-e).map(([,t,e])=>[t,e]),zt=n=>n instanceof Date?!1:n&&typeof n=="object"&&!Array.isArray(n),S=(n,...t)=>{if(!t.length)return n;const e=t.shift();if(zt(n)&&zt(e))for(const s in e)zt(e[s])?(n[s]||Object.assign(n,{[s]:{}}),S(n[s],e[s])):Object.assign(n,{[s]:e[s]});return S(n,...t)},In=(n,t)=>!n||n==="all"?!0:n.some(e=>t.indexOf(e)>-1),jn=(n,t)=>{let e=[],s=[],i;const r=()=>{process.env.NODE_ENV!=="production"&&console.time("state-processor.flush");const a=new Map,c=Mn(e.map((l,u)=>[l,s[u]])),h=(l,u)=>{var p;const d=a.get(l)||{},v=u.context&&!d.context,m=u.properties&&!d.properties,jt=u.layout&&!d.layout;a.set(l,{context:d.context||v,properties:d.properties||m,layout:d.layout||jt}),m&&(l.attributes.properties={}),jt&&(l.attributes.layout={}),v&&(l.attributes.context=S({},(p=l.parent)==null?void 0:p.attributes.context));const Se=[],Pe=[],Ce=[];if(l.changesets.forEach(x=>{const[_,Ut]=x;In(Ut.breakpoints,n.breakpoints)&&(m&&(typeof _.properties=="function"?Se.push(_.properties):S(l.attributes.properties,_.properties)),jt&&(typeof _.layout=="function"?Pe.push(_.layout):S(l.attributes.layout,_.layout)),v&&(typeof _.context=="function"?Ce.push(_.context):S(l.attributes.context,_.context)))}),Se.forEach(x=>{S(l.attributes.properties,x(l.attributes.properties))}),Pe.forEach(x=>{S(l.attributes.layout,x(l.attributes.layout))}),Ce.forEach(x=>{S(l.attributes.context,x(l.attributes.context))}),v||u.recursive){const x=n.getBranch(l),_=u.recursive?u:{context:!!v};l.getChildren(x).forEach(Ut=>{h(Ut,_)})}};process.env.NODE_ENV!=="production"&&console.timeEnd("state-processor.flush"),c.forEach(([l,u])=>{h(l,u)}),e=[],s=[],t(a)},o=()=>{clearTimeout(i),i=setTimeout(r,0)};return(a,c)=>{const h=e.indexOf(a);if(h>-1){const l=s[h];return c.context&&(l.context=!0),c.properties&&(l.properties=!0),c.layout&&(l.layout=!0),c.recursive&&(l.recursive=!0),o()}return e.push(a),s.push(c),o()}};class Un{constructor(t,e={}){this.providers=e,this.breakpoints=[],this.actionsState={handlers:[],watchers:[]},this.switches={},this.changesets=[],this.subscriptions=[],this.customComponentHandler=new Tn,this.events=t.events.createChild(this);const s=new ze(this.events,"root");s.name=`root-${t.name}`,this.nodes=new kn(s,this.switches,this.events);const i=this.processNode=jn(this,r=>{const o=Array.from(r.keys());process.env.NODE_ENV!=="production"&&console.info(`STATE PROCESSOR: ${o.length} node(s) processed:
|
|
2
|
-
|
|
3
|
-
`)}`),o.forEach(a=>{const c=r.get(a);a.parent&&a.parent.type==="root"&&this.events.dispatch("components:root-children-changed",{node:a}),c!=null&&c.context&&this.events.dispatch("components:context-changed",{node:a}),c!=null&&c.properties&&this.events.dispatch("components:properties-changed",{node:a}),c!=null&&c.layout&&this.events.dispatch("components:layout-changed",{node:a})}),this.events.dispatch("components:component-model-initialized",{},{bubbles:!0})});Promise.all(Object.keys(e).map(r=>e[r].load(this))),this.subscriptions.push(this.events.subscribe("components:node-appended",(r,o)=>{const{node:a}=o;this.changesets.forEach(c=>{const{changeset:h,target:l,removes:u}=c,[p,d]=h;l.match(o.node)&&(p.properties&&u.push(a.writeProperties(p.properties,d)),p.context&&u.push(a.writeContext(p.context,d)),p.layout&&u.push(a.writeLayout(p.layout,d)))})})),this.subscriptions.push(this.events.subscribe("components:node-appended",(r,o)=>{i(o.node,{properties:!0,context:!0})})),this.subscriptions.push(this.events.subscribe("components:set-properties",(r,o)=>{i(o.node,{properties:!0})})),this.subscriptions.push(this.events.subscribe("components:set-context",(r,o)=>{i(o.node,{properties:!0,context:!0})})),this.subscriptions.push(this.events.subscribe("components:set-indent",(r,o)=>{i(o.node,{layout:!0})})),this.subscriptions.push(this.events.subscribe("components:set-layout",(r,o)=>{i(o.node,{layout:!0})})),this.subscriptions.push(this.events.subscribe("components:node-switched",(r,{node:o,branch:a})=>{i(o,{layout:!0,recursive:!0,properties:!0,context:!0})})),this.subscriptions.push(this.events.subscribe("components:node-removed",(r,{parentNode:o})=>{i(o,{properties:!0})})),this.events.parent&&this.events.parent.dispatch("components:platform-created",{platform:this})}static getInstance(t){return t.getAsync("components")}addBreakpoint(t){this.breakpoints.indexOf(t)===-1&&(this.breakpoints.push(t),this.processNode(this.nodes.root,{context:!0,properties:!0,layout:!0,recursive:!0}))}removeBreakpoint(t){const e=this.breakpoints.indexOf(t);e>-1&&(this.breakpoints.splice(e,1),this.processNode(this.nodes.root,{context:!0,properties:!0,layout:!0,recursive:!0}))}setSwitch(t,e){this.switches[t.id]=e,this.events.dispatch("components:node-switched",{node:t,branch:e})}getBranch(t){return this.switches[t.id]}createNode(t,e={}){const s=new ze(this.events,t);return e.detached&&this.nodes.detached.push(s),s}components(){return new ws(this)}actions(t,e){return new de(this,t,e)}write(t){const{provider:e,target:s,attributes:i,options:r={},removable:o}=t,a=t.key||I(),c={changeset:[i,r],target:s,removes:[]};if(e){const h=this.providers[e];h.write(a,s,i,r),c.removes.push(()=>{h.remove(a)})}return this.changesets.push(c),this.nodes.all.forEach(h=>{if(s.match(h)){let l=()=>{};i.properties&&(l=h.writeProperties(i.properties,r,o)),i.context&&(l=h.writeContext(i.context,r,o)),i.layout&&(l=h.writeContext(i.layout,r,o)),c.removes.push(l)}}),()=>{if(o){c.removes.forEach(l=>l());const h=this.changesets.indexOf(c);h>-1&&this.changesets.splice(h,1)}}}addComponentHandler(t,e){this.customComponentHandler.add(t,e)}getComponentHandler(t){return this.customComponentHandler.get(t)}dispose(){this.subscriptions.forEach(t=>t())}}const Dn="#____version____#",Es=class extends bs{constructor(t,e=[]){super(t,e,{transformPluginSettings:(s,i,r)=>{const o=r.get("$settings"),a=o.plugins&&i?o.plugins[i]||{}:{};return Xt(Xt({},a),s)}})}createImplementation(t){const e=super.createImplementation(t);return e.bindings=t.bindings,e}navigate(t,e,s){this.widgets.query(t).forEach(i=>i.invoke("navigate",{route:e,params:s}))}static create(t={}){const e=[Bs].concat(t.configurationApiExtensions||[]);return new Es("humany",e)}static createFromGlobal(t,e={}){if(this.isRuntime(t))return t.patch(e),t;const s=[],i=t&&t._c;i&&i.forEach(o=>s.push(o));const r=this.create(e);return r.container.register("$runtimecfg",s),r}static isRuntime(t){return!!(t&&typeof t=="object"&&t.container&&typeof t.container.get=="function"&&t.container.get("$environment")===t&&t.container.owner===t)}};let Hn=Es;Hn.version=`${Dn} (${ue})`;var Rn=Object.defineProperty,Be=Object.getOwnPropertySymbols,Wn=Object.prototype.hasOwnProperty,Ln=Object.prototype.propertyIsEnumerable,Ve=(n,t,e)=>t in n?Rn(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,W=(n,t)=>{for(var e in t||(t={}))Wn.call(t,e)&&Ve(n,e,t[e]);if(Be)for(var e of Be(t))Ln.call(t,e)&&Ve(n,e,t[e]);return n},b=(n=>(n.Cookie="cookie",n.Local="local",n.Session="session",n))(b||{}),Ct=(n=>(n.Tenant="tenant",n.Implementation="implementation",n.Widget="widget",n))(Ct||{}),y=(n=>(n.Necessary="necessary",n.Functional="functional",n.Analytical="analytical",n.Marketing="marketing",n))(y||{});const Ot=(n,t,e,s={})=>qe(n,e).then(i=>(process.env.NODE_ENV!=="production"&&i&&w.warn(`createStorageWriter: Attempted to create storage writer using unallowed category.
|
|
4
|
-
Key: ${t}
|
|
5
|
-
Category: ${JSON.stringify(e)}
|
|
6
|
-
Options: ${JSON.stringify(s)}`),r=>(fe(n),qe(n,e).then(o=>{if(o){process.env.NODE_ENV!=="production"&&w.warn(`storageWriter: Attempted to write to storage using unallowed category.
|
|
7
|
-
Key: ${t}
|
|
8
|
-
Category: ${JSON.stringify(e)}
|
|
9
|
-
Value: ${JSON.stringify(r)}
|
|
10
|
-
Options: ${JSON.stringify(s)}`);return}const{scope:a=Ct.Widget,medium:c=b.Session,duration:h}=s,l=Bn();return l[a][t]=Ss(r,e,h),c===b.Cookie?Kn(n,l):Yn(n,c,l)})))),B=(n,t,e=b.Session)=>(fe(n),typeof t>"u"?(process.env.NODE_ENV!=="production"&&w.warn("readStorage: Undefined key passed when reading storage. ",t,e),Promise.resolve(void 0)):e===b.Cookie?Jn(n).then(s=>ee(s,t)):Qn(n,e).then(s=>ee(s,t))),V=n=>!!Object.entries(n).filter(([t,e])=>typeof e<"u").length,Bt=n=>Object.entries(n).filter(([t,e])=>typeof e<"u").forEach(([t,{value:e}])=>{typeof e>"u"&&delete n[t]}),As=(n,t)=>{const e={tenant:W(W({},n.tenant),t.tenant),implementation:W(W({},n.implementation),t.implementation),widget:W(W({},n.widget),t.widget)};return Bt(e.tenant),Bt(e.implementation),Bt(e.widget),e},zn=n=>Object.entries(n).reduce((t,e)=>{const[s,i]=e;return Object.entries(i).forEach(r=>{const[o,{expiration:a}]=r;a&&t.push(a)}),t},[]).slice().sort((t,e)=>new Date(e).valueOf()-new Date(t).valueOf()).shift()||me(),kt=n=>{const{name:t,implementation:{name:e,tenant:s}}=n.get("$widget");return[`humany_${s}`,`humany_${Re(s+e)}`,`humany_${Re(s+e+t)}`]},Vt=n=>{const t=new RegExp(`(?:^|;)\\s?${n}=(.*?)(?:;|$)`,"i"),e=document.cookie.match(t);return e&&e[1]&&JSON.parse(e[1])||void 0},qt=(n,t,e)=>{const s=`${n}=${JSON.stringify(t).trim()}`,i=`expires=${new Date(e).toUTCString()}`,r="path=/",o="SameSite=None;Secure";return document.cookie=`${s}; ${i}; ${r}; ${o}`},ge=n=>{const[t,e,s]=kt(n),i=Vt(t)||{},r=Vt(e)||{},o=Vt(s)||{};return{tenant:i,implementation:r,widget:o}},xs=(n,t)=>{const e=ge(n),s=As(e,t),[i,r,o]=kt(n),{tenant:a,implementation:c,widget:h}=s,l=zn(t),u=me({days:-1});qt(i,a,V(a)?l:u),qt(r,c,V(c)?l:u),qt(o,h,V(h)?l:u)},$t=(n,t)=>{const[e,s,i]=kt(n),r=t.getItem(e)||"{}",o=t.getItem(s)||"{}",a=t.getItem(i)||"{}";return{tenant:JSON.parse(r),implementation:JSON.parse(o),widget:JSON.parse(a)}},te=(n,t,e)=>{const s=$t(n,t),i=As(s,e),[r,o,a]=kt(n),{tenant:c,implementation:h,widget:l}=i;V(c)?t.setItem(r,JSON.stringify(c)):t.removeItem(r),V(h)?t.setItem(o,JSON.stringify(h)):t.removeItem(o),V(l)?t.setItem(a,JSON.stringify(l)):t.removeItem(a)},Bn=()=>({tenant:{},implementation:{},widget:{}}),Vn=n=>n?!!n&&new Date>new Date(n):!1,ee=(n,t)=>{const e=n.widget[t]||n.implementation[t]||n.tenant[t];return e==null?void 0:e.value},Ss=(n,t,e)=>e?{value:n,category:t,expiration:typeof e=="object"?me(e):e}:{value:n,category:t},qn=(n,t)=>{const e=vn(n);return Object.entries(e).forEach(([s,i])=>{Object.entries(i).forEach(([r,o])=>{const{expiration:a,category:c}=o;(Vn(a)||Fn(t,c))&&(i[r]=Ss(void 0,c,a))})}),e},qe=(n,t)=>B(n,"storagePolicy",b.Cookie).then((e=[y.Necessary])=>!!t&&e.indexOf(t)===-1),Fn=(n=[y.Necessary],t)=>!!t&&n.indexOf(t)===-1,fe=n=>{const t=ge(n),e=$t(n,window.localStorage),s=$t(n,sessionStorage),i=ee(t,"storagePolicy"),[r,o,a]=[t,e,s].map(c=>qn(c,i));xs(n,r),te(n,window.localStorage,o),te(n,window.sessionStorage,a)},me=(n={days:30})=>{const{days:t=0,hours:e=0,minutes:s=0,seconds:i=0}=n,r=new Date;return r.setTime(r.getTime()+e*60*60*1e3),r.setTime(r.getTime()+t*24*60*60*1e3),r.setTime(r.getTime()+s*60*1e3),r.setTime(r.getTime()+i*1e3),r.toISOString()},Jn=n=>it(document)(()=>ge(n)),Kn=(n,t)=>it(document)(()=>xs(n,t)),Qn=(n,t)=>{const e=t===b.Local?window.localStorage:window.sessionStorage;return it(e)(()=>$t(n,e))},Yn=(n,t,e)=>{const s=t===b.Local?window.localStorage:window.sessionStorage;return it(s)(()=>te(n,s,e))},Ft=(n,t,e,...s)=>{const i=`[${n.get("$environment").name||"webprovisions"}] ${e}`;switch(t){case"info":console.info(i,...s);break;case"warning":console.warn(i,...s);break;case"error":console.error(i,...s);break}},Zn=n=>{const t=n.container||n;return{info:(e,...s)=>Ft(t,"info",e,...s),warn:(e,...s)=>Ft(t,"warning",e,...s),error:(e,...s)=>Ft(t,"error",e,...s)}};var wt=(n=>(n.Implementation="implementation",n.Widget="widget",n))(wt||{}),U=(n=>(n.Pre="pre",n.Post="post",n))(U||{});const Gn=(n,t,e,s)=>{try{const i=new t(e,s);return{name:n,invoke:(r,o)=>{let a;return i[r]&&(a=i[r].call(i,o)),Promise.resolve(a)},getInstance:()=>i}}catch(i){if(i.message&&i.message.indexOf("is not a constructor")>=0)return{name:n,invoke:r=>{let o;return r==="initialize"&&(o=t(e,s)),Promise.resolve(o)},getInstance:()=>t};throw i}};function Fe(n,t){return typeof n>"u"?t:n}class Xn{constructor(t={}){this.part=t}createCommand(t,e,s){let i;typeof e=="function"?i={scope:wt.Widget,stage:U.Post,defaultArgs:void 0,handlerResolver:e}:i={scope:Fe(e.scope,wt.Widget),stage:Fe(e.stage,U.Post),defaultArgs:e.defaultArgs,handlerResolver:s};let r=this.part;const o=t.split(".");return o.forEach((a,c)=>{c===o.length-1?r[a]||(r[a]=()=>i):r=this.part[a]=this.part[a]||{}}),this}get(){return this.part}}const Ps=n=>{const t=new Xn({});return n(t),t.get()};Ps(n=>{n.createCommand("types.register",{scope:wt.Implementation,stage:U.Pre},t=>(e,s)=>{t.container.get("$types")[e]=s}).createCommand("type",{stage:U.Pre},t=>e=>{t.container.register("$type",e)}).createCommand("settings",{stage:U.Pre,defaultArgs:[null]},t=>e=>{t.events.dispatch("settings:change",e,{bubbles:!0}),t.container.register("$settings",e)}).createCommand("plugin",{stage:U.Pre},t=>(e,s,i)=>{const{container:r}=t;let o=null,a=e,c=s;typeof e=="string"&&(o=e,a=s,c=i);const h=l=>{const{transformPluginSettings:u}=t.container.get("$environmentOptions"),p=u?u(c||{},o,t.container,a):s;try{const d=Gn(o,a,r,p);r.get("$plugins").push(d),l&&d.invoke("initialize",null)}catch(d){Zn(t).warn("Error when initializing plugin",d)}};t.container.get("$instance")?h(!0):t.events.subscribeOnce("widget:instance-created",()=>h(!1))}).createCommand("container.register",t=>(e,s)=>{t.container.register(e,s)}).createCommand("container.registerAsync",t=>(e,s)=>{t.container.registerAsync(e,s)}).createCommand("container.registerFactory",t=>(e,s)=>{t.container.registerFactory(e,s)}).createCommand("container.touch",t=>(e,s)=>{t.container.touch(e,s)}).createCommand("csp",{},t=>e=>{t.container.register("csp",e)})});Ps(n=>{n.createCommand("storage",t=>(e={})=>{const{consent:s}=e;if(typeof s<"u"){if(typeof s!="number"&&typeof s!="string"&&!Array.isArray(s)){process.env.NODE_ENV!=="production"&&w.warn(`storagePolicyConfigurationApi: passed consent is not valid. Consent either has to be a number, a string, an array of strings or an array of numbers.
|
|
11
|
-
Passed consent: ${JSON.stringify(s)}`);return}if(Array.isArray(s)&&!s.every(r=>typeof r=="number"||typeof r=="string")){process.env.NODE_ENV!=="production"&&w.warn(`storagePolicyConfigurationApi: passed consent is not valid. Consent either has to be a number, a string, an array of strings or an array of numbers.
|
|
12
|
-
Passed consent: ${JSON.stringify(s)}`);return}const i=[y.Necessary,y.Functional,y.Analytical,y.Marketing].filter((r,o,a)=>typeof s=="number"?s>o:typeof s=="string"?a.indexOf(s)+1>o:Array.isArray(s)?s.findIndex(c=>c===o+1||c===r)>-1:!0);return i.indexOf(y.Necessary)===-1&&(process.env.NODE_ENV!=="production"&&w.warn(`storagePolicyConfigurationApi: passed consent does not include category: '${y.Necessary}'. Consent has to atleast include the '${y.Necessary}' category.
|
|
13
|
-
Passed consent: ${JSON.stringify(s)}`),i.unshift(y.Necessary)),Ot(t.container,"storagePolicy",y.Necessary,{medium:b.Cookie,scope:Ct.Tenant,duration:{days:365}}).then(r=>r(i)).then(()=>{fe(t.container),t.events.dispatch("storage:policy-changed",i)})}})});class ti{constructor(t){this.controller=t,this.cache=new Map,this.subscriptions=[];const{events:e}=t.container.get("$widget"),s=e.subscribe("data-client:fetched",(i,r)=>{r.type==="contact-method"&&this.cache.set(r.response.id,r.response)});this.subscriptions.push(s)}getConversationLogs(){return this.controller.messages.reduce((e,s)=>{const i=Nt(s),{content:r,type:o,sender:a,timestamp:c}=i.content,h=this.parseEntry(r,o,a,c);return h&&e.push(h),e},[])}parseEntry(t,e,s,i){const r=h=>{let l=[],u=[],p;if(Array.isArray(h)){const[v,m]=h;p=m}else p=h;return this.createMessageContent(p).length&&(u=[...u,this.createMessageContent(p)]),l=[...l,...this.createMessageOptions(p)],{messagesAsList:u,options:l}};let o=[],a=[];if(Array.isArray(t.items)){const{items:h}=t;h.forEach(l=>{const u=r(l);o=[...o,...u.options],a=[...a,...u.messagesAsList]})}else{const h=r(t);o=[...o,...h.options],a=[...a,...h.messagesAsList]}return{options:o,message:a.length?a.join(`
|
|
14
|
-
`):void 0,source:this.createMessageSource(e),alias:this.createAlias(e,s),timestamp:i}}createMessageSource(t){return t}createAlias(t,e){return t===Tt.System?"system":(e==null?void 0:e.name)||"Me"}handleContactMethod(t){if(!this.cache.has(t))return;const e=this.cache.get(t);let s="";return s=this.appendText(s,`${e.clientName}:`),s=this.appendText(s,e.title),e.description&&(s=this.appendText(s,e.title)),s}getDetails(t,e=!0){if(!t)return"";const{header:s,title:i,label:r,description:o,text:a,html:c,body:h,contactMethodId:l}=t;let u="";if(l){const p=this.handleContactMethod(l.toString());p&&(u=this.appendText(u,p,e))}return s&&(u=this.appendText(u,s,e)),i&&(u=this.appendText(u,i,e)),o&&(u=this.appendText(u,o,e)),a&&(u=this.appendText(u,a,e)),r&&(u=this.appendText(u,r,e)),c&&(u=this.appendText(u,c,e)),h&&typeof h=="string"&&(u=this.appendText(u,h,e)),u}createMessageContent(t){let e="";return e=this.getDetails(t),e}createMessageOptions(t){let e=[],s=[];return Array.isArray(t==null?void 0:t.actions)?s=t.actions:typeof(t==null?void 0:t.actions)=="object"&&(s=Object.entries(t.actions).map(([i,r])=>({actionKey:i,label:r}))),s.length&&(e=s.map(i=>this.getDetails(i,!1))),e}appendText(t,e,s=!0){return s&&t.length?`${t}
|
|
15
|
-
${e}`:t.length?`${t} ${e}`:e}dispose(){this.subscriptions.forEach(t=>{t()})}}class se{constructor(t,e){this.provider=t,this.print=(s,i)=>{const r={name:this.name,avatar:this.avatar,id:this.id},o=Nt(s,i);return this.provider.createEntry(o.key,o.content,Tt.Agent,r,o.timestamp)},this.typing=()=>this.provider.setTypingState({name:this.name,avatar:this.avatar}),this.id=e.id||I(),this.name=e.name,this.avatar=e.avatar}update(t){var i;const{name:e,avatar:s}=t;s===null?this.avatar=void 0:s&&(this.avatar=s),e===null?this.name=void 0:e&&(this.name=e),(i=this.provider.controller)==null||i.events.dispatch("conversation:agent-updated",{agent:this})}}class ve{constructor(t,e,s){this.name=t,this.controller=s,this.subscriptions=[],this.user=s==null?void 0:s.user,this.options={silent:!1}}static create(t,e,s){return new ve(t,e,s)}createAgent(t={}){var e;if(this.controller){const s=this.controller.getAgentById(t.id),i=s?new se(this,{...s,...t}):new se(this,t);return s||(e=this.controller)==null||e.events.dispatch("conversation:agent-created",{agent:i}),i}}print(t){var e;return(e=this.controller)==null?void 0:e.print(t)}setTypingState(t,e){var s;return(s=this.controller)==null?void 0:s.setTypingState(t,e)}loading(){return this.controller?this.controller.loader():()=>()=>{}}createEntry(t,e,s,i,r){var o;return(o=this.controller)==null?void 0:o.createEntry(t,e,s,i,r)}dispose(){var t;process.env.NODE_ENV!=="production"&&console.log(`conversation-provider: dispose (${this.name})`),(t=this.controller)==null||t.disposeProvider(this),this.controller=null,this.subscriptions.forEach(e=>e())}isRehydrated(){var t;return((t=this.controller)==null?void 0:t.isRehydrated())||Promise.resolve(!1)}getHistory(){var t;return((t=this.controller)==null?void 0:t.getHistory())||[]}complete(){var t;(t=this.controller)==null||t.onCompleteProvider()}setOptions(t={silent:!1}){this.options=t}onUnreadMessage(t){var e;if(this.controller){const s=(e=this.controller)==null?void 0:e.onUnreadMessage(t);return this.subscriptions.push(s),()=>{s()}}}onMounted(t){var e;if(this.controller){const s=(e=this.controller)==null?void 0:e.events.subscribe("conversation:component-mount-changed",t);return this.subscriptions.push(s),t({},this.controller.getComponentMountedState()),()=>{s()}}}}const Cs=n=>`conversation-${n}`;class ei{constructor(){this._locking=Promise.resolve(),this._locks=0}isLocked(){return this._locks>0}lock(){this._locks+=1;let t;const e=new Promise(i=>t=()=>{this._locks-=1,i()}),s=this._locking.then(()=>t);return this._locking=this._locking.then(()=>e),s}}class si{constructor(t,e,s){this.container=t,this.enabled=s,this.locker=new ei,this.initialStoredAgents=[],this.sessionStorageKey=Cs(e.id),e.onStarted(async()=>{if(e.messages.length>0)return;const{agents:i}=await this.read(),r=[];i&&i.forEach(a=>{const c=e.providerIndex(a.providerName),h=c>-1?e.registeredProviders[c]:e.createProvider(a.providerName),l=new se(h,{name:a.name,avatar:a.avatar,id:a.id});r.push(l)});const{messages:o}=await this.read();o.forEach(a=>{switch(a.type){case"agent":{const c=r.find(h=>{var l;return h.id===((l=a.sender)==null?void 0:l.id)});c&&c.print(a.content.items||a.content,{key:a.key});return}case"user":{e.user.print(a.content.items||a.content,{key:a.key});return}case"system":default:e.print(a.content.items||a.content)}})}),e.onMessageCreated(async(i,r)=>{this.write(r.message,"messages")}),e.events.subscribe("conversation:agent-created",async(i,r)=>{const o={id:r.agent.id,name:r.agent.name,avatar:r.agent.avatar,providerName:r.agent.provider.name};await this.write(o,"agents")}),e.events.subscribe("conversation:agent-updated",async(i,r)=>{const{agents:o}=await this.read();await this.write([...o.map(a=>a.id===r.agent.id?{...a,name:r.agent.name,avatar:r.agent.avatar}:a)],"agents","update")})}setInitialData(t){this.initialStoredAgents=t.agents}async isRehydrated(){const{messages:t}=await this.read();return t.length>0}getStoredAgent(t){if(this.enabled)return this.initialStoredAgents.find(e=>e.id===t)}async write(t,e,s="add"){if(!this.enabled)return;const i=await this.locker.lock();return Ot(this.container,this.sessionStorageKey,y.Necessary).then(async r=>{if(s==="add"){const o=await this.read();if(e==="messages"&&o.messages.findIndex(c=>c.key===t.key)>-1){i();return}const a={...o};return e==="messages"?a.messages=[...a.messages,t]:e==="agents"&&(a.agents=[...a.agents,t]),r({...o,...a}).then(()=>{i()})}if(s==="update"&&e==="agents"){const o=await this.read();return r({...o,agents:t}).then(()=>{i()})}return r(t).then(()=>{i()})})}async read(){return B(this.container,this.sessionStorageKey).then(t=>t||{messages:[],agents:[]})}}class ni{constructor(t){this.controller=t,this.print=(e,s)=>{const i=Nt(e,s);return this.controller.createEntry(i.key,i.content,Tt.User,void 0,i.timestamp)}}}const ne=async(n,t,e)=>{const s=await n.getAsync("conversation"),i=await n.getAsync("components"),r=s.controllers.find(o=>o.conversation.id===t);if(r){const o=[...r.conversation.providers];o.forEach(c=>{r.conversation.setProviderOptions(c,{silent:!0})}),r.conversation.queueProviders(o),r.conversation.setProviders([e]);const a=i.components().ofType("conversation");i.write({key:"setConversationProvider",attributes:{properties:{providers:[e]}},target:a,provider:"localStorage"})}};class ii{constructor(t){this.writer=t,this.entryId=I()}update(t){const e=this.getNormalizedSettings(t);this.writer(e)}remove(){this.writer(null)}getNormalizedSettings(t){return typeof t=="string"?{body:t}:t.length>-1&&typeof t=="object"?{items:t}:t}}var Tt=(n=>(n.User="user",n.Agent="agent",n.System="system",n))(Tt||{});const Nt=(n,t)=>{let e,s=(t==null?void 0:t.key)||I(),i=Date.now();return Array.isArray(n)&&n.length>-1?typeof n[0]=="string"?e={items:[n]}:e={items:n}:typeof n=="string"?e={body:n}:(n=n||{},n.type?e={...n}:(e={body:n.body,actions:n.actions,title:n.title},n.key&&(s=n.key),n.timestamp&&(i=n.timestamp),n.form,n.timestamp===null&&(i=null))),{content:e,key:s,timestamp:i}},Je=(n,t)=>{if(!t)return;const e=JSON.stringify(t),s=n.findIndex(i=>e===JSON.stringify(i));if(s>-1)return n.splice(s,1)};class ri{constructor(t,e,s){this.container=t,this.id=e,this.formHandlers={},this.user=new ni(this),this.providers=[],this.active=!1,this.queuedProviders=[],this.registeredProviders=[],this.loaders=0,this.componentMounted=!1,this.messages=[],this.typingActors=[],this.print=r=>{const o=Nt(r);return this.createEntry(o.key,o.content,"system",void 0,o.timestamp)};const i=t.get("$widget");this.events=i.events.createChild(this),this.store=new si(t,this,s.rehydrate),this.conversationHistory=new ti(this)}setInitialStorage(t){this.store.setInitialData(t)}setProviders(t){const e=[],s=[];this.providers.reduce((i,r)=>(t.indexOf(r)===-1&&i.push(r),i),[]).forEach(i=>{const r=this.providers.indexOf(i);r>-1&&(e.push(i),this.providers.splice(r,1))}),t.forEach(i=>{this.providers.indexOf(i)===-1&&(s.push(i),this.providers.push(i))}),(s.length||e.length)&&this.events.dispatch("conversation:providers-changed",{added:s,removed:e})}createProvider(t){const e=this.providerIndex(t);if(e>-1)return this.registeredProviders[e];const s=ve.create(t,this.container,this);return this.registeredProviders.push(s),s}providerIndex(t){return this.registeredProviders.findIndex(e=>e.name===t)}getAgentById(t){if(t)return this.store.getStoredAgent(t)}dispose(){this.conversationHistory.dispose(),this.registeredProviders.forEach(t=>t.dispose()),this.messages=[],this.events.dispatch("conversation:controller-disposed",this),this.active=!1}onDispose(t){return this.events.subscribe("conversation:controller-disposed",t)}onStarted(t){return this.events.subscribe("conversation:started",t)}onMessageCreated(t){return this.events.subscribe("conversation:message-created",t)}isRehydrated(){return this.store.isRehydrated()}disposeProvider(t){const e=this.providerIndex(t.name);e>-1&&this.registeredProviders.splice(e,1),this.events.dispatch("conversation:providers-changed",{removed:[t.name]}),this.registeredProviders.length||this.dispose()}onProvidersChange(t){return this.events.subscribe("conversation:providers-changed",t)}setComponentMountedState(t){this.componentMounted!==t&&(this.componentMounted=t,t&&(this.events.dispatch("conversation:unread-message",!1),this.events.dispatch("conversation:started",!0),this.active=!0),this.events.dispatch("conversation:component-mount-changed",t))}setProviderOptions(t,e){const s=this.providerIndex(t);s>-1&&this.registeredProviders[s].setOptions(e)}changeProvider(t){this.registeredProviders.find(s=>s.name===t)&&ne(this.container,this.id,t)}queueProviders(t){this.queuedProviders=t}onCompleteProvider(){const t=this.queuedProviders.pop();t&&ne(this.container,this.id,t)}getComponentMountedState(){return this.componentMounted}onUnreadMessage(t){return this.events.subscribe("conversation:unread-message",t)}createEntry(t,e,s,i,r){const o={key:t,content:e,type:s,sender:i||null,timestamp:r||r===null?r:Date.now()};this.messages.push(o),o.type==="agent"&&Je(this.typingActors,i);const a=new ii(c=>{if(c!==null){const{timestamp:h=void 0,...l}=c;o.content=l,h&&(o.timestamp=h)}else{const h=this.messages.indexOf(o);o.content=null,h>-1&&this.messages.splice(h,1)}this.events.dispatch("conversation:message-updated",{message:o}),this.update()});return this.events.dispatch("conversation:message-created",{message:o}),this.update(),this.componentMounted||this.events.dispatch("conversation:unread-message",!0),a}update(){this.events.dispatch("conversation:updated",{messages:this.messages,loading:this.loaders>0,typingActors:this.typingActors})}getMessageStream(){return{messages:this.messages,loading:this.loaders>0,typingActors:this.typingActors}}setTypingState(t,e){return this.typingActors.indexOf(t)===-1&&(this.typingActors.push(t),this.update()),()=>{Je(this.typingActors,t),this.update()}}loader(){this.loaders=this.loaders+1;let t=!1;return this.loaders===1&&this.update(),()=>{t||(t=!0,this.loaders=this.loaders-1,this.loaders===0&&this.update())}}submitForm(t,e){this.formHandlers[t]={...this.formHandlers[t],submit:e}}validateForm(t,e){this.formHandlers[t]={...this.formHandlers[t],validate:e}}getHistory(){return this.conversationHistory.getConversationLogs()}}const oi=(n,t)=>{const e=n.split("_contact");return t.widgets.get(e[0])},ye=n=>{const t=n.get("$widget"),{name:e,implementation:s}=n.get("$widget"),i=e.indexOf("_contact")>-1?oi(e,s):t,{data:r}=n.get("$settings"),{trigger:o}=i.container.get("$settings"),a=`${e.replace("_contact-method","").replace("_contact","")}_contact-method`,c=s.widgets.get(a);return c&&!o?{chatWidget:c,mainWidget:i,data:r}:{mainWidget:i,data:r}},ai=n=>{const{chatWidget:t}=ye(n);return!!t},Ke=(n,t,e)=>{const{mainWidget:s,data:i,chatWidget:r}=ye(n);return r?r.state==="activated"?r.invoke("open").then(()=>{r.container.getAsync("conversation").then(o=>{o.navigateToConversationIfActive(t.id)})}):r.activate().then(()=>{const{trigger:o}=r.container.get("$settings");return o.action="hide",r.invoke("setSettings",()=>({data:i,trigger:o,activate:!0})).then(()=>r.container.getAsync("components").then(a=>{const c=a.components().ofType("contact-method");a.write({key:"setContactMethodId",attributes:{properties:{id:t.id,guideId:t.guideId}},target:c,provider:"localStorage"});const h=a.components().ofType("conversation");a.write({key:"setConversationProvider",attributes:{properties:{providers:[t.clientName]}},target:h,provider:"localStorage"})}))}).then(()=>r.invoke("attach",{key:"contact-method",triggerDOMElement:e,withRenderState:"open"})).then(()=>(Ot(r.container,"activeStickyWidget",y.Necessary,{medium:b.Local,scope:Ct.Implementation}).then(o=>o(r.name)),r.container.getAsync("conversation").then(o=>{o.setConversationEndedBehavior(be.Deactivate)}).then(()=>!1))):!r},ci=(n,t,e="conversation")=>{const{mainWidget:s,chatWidget:i}=ye(n);return s.container.getAsync("conversation").then(r=>{var o;(o=r.setConversationEndedBehavior(be.Navigate))==null||o.then(()=>{s.container.getAsync("components").then(a=>{const c=a.components().ofType("conversation");a.write({key:"setConversationProvider",attributes:{properties:{providers:[t.clientName]}},target:c,provider:"localStorage"})})})})},ut="conversations";var be=(n=>(n.Deactivate="deactivate",n.Navigate="navigate",n.None="none",n))(be||{});class $e{constructor(t,e){this.container=t,this.components=e,this.controllers=[],this.providers=[],this.disposeProviders={},this.subscriptions=[],this.storageWriter=null,this.buttonQuery=null,this.sessionInfo=null;const s=t.get("$widget");this.events=s.events.createChild(this)}initialize(){Ot(this.container,ut,y.Necessary,{medium:b.Local}).then(t=>this.storageWriter=t),B(this.container,ut,b.Local).then(t=>{this.buttonQuery=this.components.components().ofType("conversation-return-button"),t&&(this.sessionInfo=t,t.id&&t.route&&this.writeToComponents({active:!0,alert:{show:!1}}))}),this.events.subscribe("conversation:ended",(t,e)=>{var s;switch((s=this.sessionInfo)==null?void 0:s.conversationEndedBehavior){case"deactivate":this.container.get("$widget").deactivate();break}this.writeToComponents({active:!1}),this.sessionInfo=null,this.storageWriter&&this.storageWriter()})}addSubscription(t){this.subscriptions.push(t)}static getInstance(t,e="conversation"){return it(t)(()=>t.getAsync(e).then(s=>{let i=s;return i||Un.getInstance(t).then(r=>(i=new $e(t,r),i.initialize(),t.registerAsync(e,()=>i),i))}))}setConversationEndedBehavior(t){return B(this.container,ut,b.Local).then(e=>{let s=e;return s?s.conversationEndedBehavior=t:s={conversationEndedBehavior:t},this.sessionInfo=s,this.storageWriter&&this.storageWriter(this.sessionInfo)||Promise.resolve()})}async createController(t,e){const s=Cs(t),{agents:i}=await B(this.container,s)||{agents:[]},r=this.controllers.findIndex(a=>a.conversation.id===t);let o;return r>-1?o=this.controllers[r].conversation:o=new ri(this.container,t,e),o.setInitialStorage({agents:i||[]}),o}registerProvider(t,e){const s={name:t,handler:e};this.providers.push(s),this.controllers.filter(i=>i.conversation.providers.indexOf(t)>-1).forEach(i=>{this.invokeHandler(s,i)})}registerController(t,e){const s=this.controllers.findIndex(r=>r.conversation.id===t.id);let i;if(s<0){i={conversation:t,component:e},this.controllers.push(i);const r=o=>{o&&this.providers.filter(a=>o.indexOf(a.name)>-1).forEach(a=>{this.invokeHandler(a,i)})};return this.subscriptions.push(t.onDispose((o,a)=>{const c=this.controllers.findIndex(h=>h.conversation===a);c>-1&&this.controllers.splice(c,1),this.components.components().ofType("conversation-return-button").select().writeProperties({active:!1}),this.events.dispatch("conversation:ended",{},{bubbles:!0})})),this.subscriptions.push(t.onProvidersChange((o,a)=>{const{added:c,removed:h=[]}=a;h.forEach(l=>{(this.disposeProviders[l]||[]).forEach(u=>{u()})}),r(c)})),this.subscriptions.push(t.onStarted((o,a)=>{var h;const c={id:t.id,conversationEndedBehavior:(h=this.sessionInfo)==null?void 0:h.conversationEndedBehavior};this.sessionInfo=c,this.storageWriter&&this.storageWriter(c),this.writeToComponents({active:a})})),this.subscriptions.push(t.onUnreadMessage((o,a)=>{this.events.dispatch("conversation:unread-message",a),this.writeToComponents({alert:{show:a}})})),r(t.providers),!0}return i=this.controllers[s],!1}writeToComponents(t,e="conversationReturnButtonState"){this.buttonQuery&&this.components.write({key:"conversationReturnButtonState",attributes:{properties:t},target:this.buttonQuery,provider:"localStorage"})}invokeHandler(t,e){const s=t.handler(e.conversation.createProvider(t.name),e.component);s&&(this.disposeProviders[t.name]||(this.disposeProviders[t.name]=[]),this.disposeProviders[t.name].push(s))}getComponentRoute(){return B(this.container,ut,b.Local).then(t=>t==null?void 0:t.route)}dispose(){Object.keys(this.disposeProviders).forEach(t=>{this.disposeProviders[t].forEach(e=>{e()})}),this.subscriptions.forEach(t=>{t()}),this.controllers=[],this.providers=[]}static async handleContactMethodClick(t,e,s,i){if(ai(e)){t.preventDefault();let r=document.getElementById("humany-dynamic-anchor");r||(r=document.createElement("a"),r.setAttribute("href","#"),r.id="humany-dynamic-anchor",document.body.appendChild(r)),Ke(e,s,r)}Ke(e,s)}static async handleContactMethodSubmit(t,e){var s,i;return(i=(s=e==null?void 0:e.body.form.meta)==null?void 0:s.conversation)!=null&&i.id?ne(t,e.body.form.meta.conversation.id,e.clientName):ci(t,e)}}/**
|
|
16
|
-
* @license
|
|
17
|
-
* Copyright 2019 Google LLC
|
|
18
|
-
* SPDX-License-Identifier: BSD-3-Clause
|
|
19
|
-
*/const ft=globalThis,we=ft.ShadowRoot&&(ft.ShadyCSS===void 0||ft.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,_e=Symbol(),Qe=new WeakMap;let Os=class{constructor(t,e,s){if(this._$cssResult$=!0,s!==_e)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t,this.t=e}get styleSheet(){let t=this.o;const e=this.t;if(we&&t===void 0){const s=e!==void 0&&e.length===1;s&&(t=Qe.get(e)),t===void 0&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),s&&Qe.set(e,t))}return t}toString(){return this.cssText}};const hi=n=>new Os(typeof n=="string"?n:n+"",void 0,_e),li=(n,...t)=>{const e=n.length===1?n[0]:t.reduce((s,i,r)=>s+(o=>{if(o._$cssResult$===!0)return o.cssText;if(typeof o=="number")return o;throw Error("Value passed to 'css' function must be a 'css' function result: "+o+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(i)+n[r+1],n[0]);return new Os(e,n,_e)},ui=(n,t)=>{if(we)n.adoptedStyleSheets=t.map(e=>e instanceof CSSStyleSheet?e:e.styleSheet);else for(const e of t){const s=document.createElement("style"),i=ft.litNonce;i!==void 0&&s.setAttribute("nonce",i),s.textContent=e.cssText,n.appendChild(s)}},Ye=we?n=>n:n=>n instanceof CSSStyleSheet?(t=>{let e="";for(const s of t.cssRules)e+=s.cssText;return hi(e)})(n):n;/**
|
|
20
|
-
* @license
|
|
21
|
-
* Copyright 2017 Google LLC
|
|
22
|
-
* SPDX-License-Identifier: BSD-3-Clause
|
|
23
|
-
*/const{is:di,defineProperty:pi,getOwnPropertyDescriptor:gi,getOwnPropertyNames:fi,getOwnPropertySymbols:mi,getPrototypeOf:vi}=Object,M=globalThis,Ze=M.trustedTypes,yi=Ze?Ze.emptyScript:"",Jt=M.reactiveElementPolyfillSupport,Z=(n,t)=>n,_t={toAttribute(n,t){switch(t){case Boolean:n=n?yi:null;break;case Object:case Array:n=n==null?n:JSON.stringify(n)}return n},fromAttribute(n,t){let e=n;switch(t){case Boolean:e=n!==null;break;case Number:e=n===null?null:Number(n);break;case Object:case Array:try{e=JSON.parse(n)}catch{e=null}}return e}},Ee=(n,t)=>!di(n,t),Ge={attribute:!0,type:String,converter:_t,reflect:!1,hasChanged:Ee};Symbol.metadata??(Symbol.metadata=Symbol("metadata")),M.litPropertyMetadata??(M.litPropertyMetadata=new WeakMap);class L extends HTMLElement{static addInitializer(t){this._$Ei(),(this.l??(this.l=[])).push(t)}static get observedAttributes(){return this.finalize(),this._$Eh&&[...this._$Eh.keys()]}static createProperty(t,e=Ge){if(e.state&&(e.attribute=!1),this._$Ei(),this.elementProperties.set(t,e),!e.noAccessor){const s=Symbol(),i=this.getPropertyDescriptor(t,s,e);i!==void 0&&pi(this.prototype,t,i)}}static getPropertyDescriptor(t,e,s){const{get:i,set:r}=gi(this.prototype,t)??{get(){return this[e]},set(o){this[e]=o}};return{get(){return i==null?void 0:i.call(this)},set(o){const a=i==null?void 0:i.call(this);r.call(this,o),this.requestUpdate(t,a,s)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)??Ge}static _$Ei(){if(this.hasOwnProperty(Z("elementProperties")))return;const t=vi(this);t.finalize(),t.l!==void 0&&(this.l=[...t.l]),this.elementProperties=new Map(t.elementProperties)}static finalize(){if(this.hasOwnProperty(Z("finalized")))return;if(this.finalized=!0,this._$Ei(),this.hasOwnProperty(Z("properties"))){const e=this.properties,s=[...fi(e),...mi(e)];for(const i of s)this.createProperty(i,e[i])}const t=this[Symbol.metadata];if(t!==null){const e=litPropertyMetadata.get(t);if(e!==void 0)for(const[s,i]of e)this.elementProperties.set(s,i)}this._$Eh=new Map;for(const[e,s]of this.elementProperties){const i=this._$Eu(e,s);i!==void 0&&this._$Eh.set(i,e)}this.elementStyles=this.finalizeStyles(this.styles)}static finalizeStyles(t){const e=[];if(Array.isArray(t)){const s=new Set(t.flat(1/0).reverse());for(const i of s)e.unshift(Ye(i))}else t!==void 0&&e.push(Ye(t));return e}static _$Eu(t,e){const s=e.attribute;return s===!1?void 0:typeof s=="string"?s:typeof t=="string"?t.toLowerCase():void 0}constructor(){super(),this._$Ep=void 0,this.isUpdatePending=!1,this.hasUpdated=!1,this._$Em=null,this._$Ev()}_$Ev(){var t;this._$Eg=new Promise(e=>this.enableUpdating=e),this._$AL=new Map,this._$E_(),this.requestUpdate(),(t=this.constructor.l)==null||t.forEach(e=>e(this))}addController(t){var e;(this._$ES??(this._$ES=[])).push(t),this.renderRoot!==void 0&&this.isConnected&&((e=t.hostConnected)==null||e.call(t))}removeController(t){var e;(e=this._$ES)==null||e.splice(this._$ES.indexOf(t)>>>0,1)}_$E_(){const t=new Map,e=this.constructor.elementProperties;for(const s of e.keys())this.hasOwnProperty(s)&&(t.set(s,this[s]),delete this[s]);t.size>0&&(this._$Ep=t)}createRenderRoot(){const t=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return ui(t,this.constructor.elementStyles),t}connectedCallback(){var t;this.renderRoot??(this.renderRoot=this.createRenderRoot()),this.enableUpdating(!0),(t=this._$ES)==null||t.forEach(e=>{var s;return(s=e.hostConnected)==null?void 0:s.call(e)})}enableUpdating(t){}disconnectedCallback(){var t;(t=this._$ES)==null||t.forEach(e=>{var s;return(s=e.hostDisconnected)==null?void 0:s.call(e)})}attributeChangedCallback(t,e,s){this._$AK(t,s)}_$EO(t,e){var r;const s=this.constructor.elementProperties.get(t),i=this.constructor._$Eu(t,s);if(i!==void 0&&s.reflect===!0){const o=(((r=s.converter)==null?void 0:r.toAttribute)!==void 0?s.converter:_t).toAttribute(e,s.type);this._$Em=t,o==null?this.removeAttribute(i):this.setAttribute(i,o),this._$Em=null}}_$AK(t,e){var r;const s=this.constructor,i=s._$Eh.get(t);if(i!==void 0&&this._$Em!==i){const o=s.getPropertyOptions(i),a=typeof o.converter=="function"?{fromAttribute:o.converter}:((r=o.converter)==null?void 0:r.fromAttribute)!==void 0?o.converter:_t;this._$Em=i,this[i]=a.fromAttribute(e,o.type),this._$Em=null}}requestUpdate(t,e,s,i=!1,r){if(t!==void 0){if(s??(s=this.constructor.getPropertyOptions(t)),!(s.hasChanged??Ee)(i?r:this[t],e))return;this.C(t,e,s)}this.isUpdatePending===!1&&(this._$Eg=this._$EP())}C(t,e,s){this._$AL.has(t)||this._$AL.set(t,e),s.reflect===!0&&this._$Em!==t&&(this._$Ej??(this._$Ej=new Set)).add(t)}async _$EP(){this.isUpdatePending=!0;try{await this._$Eg}catch(e){Promise.reject(e)}const t=this.scheduleUpdate();return t!=null&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){var s;if(!this.isUpdatePending)return;if(!this.hasUpdated){if(this._$Ep){for(const[r,o]of this._$Ep)this[r]=o;this._$Ep=void 0}const i=this.constructor.elementProperties;if(i.size>0)for(const[r,o]of i)o.wrapped!==!0||this._$AL.has(r)||this[r]===void 0||this.C(r,this[r],o)}let t=!1;const e=this._$AL;try{t=this.shouldUpdate(e),t?(this.willUpdate(e),(s=this._$ES)==null||s.forEach(i=>{var r;return(r=i.hostUpdate)==null?void 0:r.call(i)}),this.update(e)):this._$ET()}catch(i){throw t=!1,this._$ET(),i}t&&this._$AE(e)}willUpdate(t){}_$AE(t){var e;(e=this._$ES)==null||e.forEach(s=>{var i;return(i=s.hostUpdated)==null?void 0:i.call(s)}),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(t)),this.updated(t)}_$ET(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$Eg}shouldUpdate(t){return!0}update(t){this._$Ej&&(this._$Ej=this._$Ej.forEach(e=>this._$EO(e,this[e]))),this._$ET()}updated(t){}firstUpdated(t){}}L.elementStyles=[],L.shadowRootOptions={mode:"open"},L[Z("elementProperties")]=new Map,L[Z("finalized")]=new Map,Jt==null||Jt({ReactiveElement:L}),(M.reactiveElementVersions??(M.reactiveElementVersions=[])).push("2.0.1");/**
|
|
24
|
-
* @license
|
|
25
|
-
* Copyright 2017 Google LLC
|
|
26
|
-
* SPDX-License-Identifier: BSD-3-Clause
|
|
27
|
-
*/const G=globalThis,Et=G.trustedTypes,Xe=Et?Et.createPolicy("lit-html",{createHTML:n=>n}):void 0,ks="$lit$",T=`lit$${(Math.random()+"").slice(9)}$`,Ts="?"+T,bi=`<${Ts}>`,H=document,et=()=>H.createComment(""),st=n=>n===null||typeof n!="object"&&typeof n!="function",Ns=Array.isArray,$i=n=>Ns(n)||typeof(n==null?void 0:n[Symbol.iterator])=="function",Kt=`[
|
|
28
|
-
\f\r]`,Q=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,ts=/-->/g,es=/>/g,j=RegExp(`>|${Kt}(?:([^\\s"'>=/]+)(${Kt}*=${Kt}*(?:[^
|
|
29
|
-
\f\r"'\`<>=]|("|')|))|$)`,"g"),ss=/'/g,ns=/"/g,Ms=/^(?:script|style|textarea|title)$/i,wi=n=>(t,...e)=>({_$litType$:n,strings:t,values:e}),dt=wi(1),R=Symbol.for("lit-noChange"),f=Symbol.for("lit-nothing"),is=new WeakMap,D=H.createTreeWalker(H,129);function Is(n,t){if(!Array.isArray(n)||!n.hasOwnProperty("raw"))throw Error("invalid template strings array");return Xe!==void 0?Xe.createHTML(t):t}const _i=(n,t)=>{const e=n.length-1,s=[];let i,r=t===2?"<svg>":"",o=Q;for(let a=0;a<e;a++){const c=n[a];let h,l,u=-1,p=0;for(;p<c.length&&(o.lastIndex=p,l=o.exec(c),l!==null);)p=o.lastIndex,o===Q?l[1]==="!--"?o=ts:l[1]!==void 0?o=es:l[2]!==void 0?(Ms.test(l[2])&&(i=RegExp("</"+l[2],"g")),o=j):l[3]!==void 0&&(o=j):o===j?l[0]===">"?(o=i??Q,u=-1):l[1]===void 0?u=-2:(u=o.lastIndex-l[2].length,h=l[1],o=l[3]===void 0?j:l[3]==='"'?ns:ss):o===ns||o===ss?o=j:o===ts||o===es?o=Q:(o=j,i=void 0);const d=o===j&&n[a+1].startsWith("/>")?" ":"";r+=o===Q?c+bi:u>=0?(s.push(h),c.slice(0,u)+ks+c.slice(u)+T+d):c+T+(u===-2?a:d)}return[Is(n,r+(n[e]||"<?>")+(t===2?"</svg>":"")),s]};class nt{constructor({strings:t,_$litType$:e},s){let i;this.parts=[];let r=0,o=0;const a=t.length-1,c=this.parts,[h,l]=_i(t,e);if(this.el=nt.createElement(h,s),D.currentNode=this.el.content,e===2){const u=this.el.content.firstChild;u.replaceWith(...u.childNodes)}for(;(i=D.nextNode())!==null&&c.length<a;){if(i.nodeType===1){if(i.hasAttributes())for(const u of i.getAttributeNames())if(u.endsWith(ks)){const p=l[o++],d=i.getAttribute(u).split(T),v=/([.?@])?(.*)/.exec(p);c.push({type:1,index:r,name:v[2],strings:d,ctor:v[1]==="."?Ai:v[1]==="?"?xi:v[1]==="@"?Si:Mt}),i.removeAttribute(u)}else u.startsWith(T)&&(c.push({type:6,index:r}),i.removeAttribute(u));if(Ms.test(i.tagName)){const u=i.textContent.split(T),p=u.length-1;if(p>0){i.textContent=Et?Et.emptyScript:"";for(let d=0;d<p;d++)i.append(u[d],et()),D.nextNode(),c.push({type:2,index:++r});i.append(u[p],et())}}}else if(i.nodeType===8)if(i.data===Ts)c.push({type:2,index:r});else{let u=-1;for(;(u=i.data.indexOf(T,u+1))!==-1;)c.push({type:7,index:r}),u+=T.length-1}r++}}static createElement(t,e){const s=H.createElement("template");return s.innerHTML=t,s}}function q(n,t,e=n,s){var o,a;if(t===R)return t;let i=s!==void 0?(o=e._$Co)==null?void 0:o[s]:e._$Cl;const r=st(t)?void 0:t._$litDirective$;return(i==null?void 0:i.constructor)!==r&&((a=i==null?void 0:i._$AO)==null||a.call(i,!1),r===void 0?i=void 0:(i=new r(n),i._$AT(n,e,s)),s!==void 0?(e._$Co??(e._$Co=[]))[s]=i:e._$Cl=i),i!==void 0&&(t=q(n,i._$AS(n,t.values),i,s)),t}class Ei{constructor(t,e){this._$AV=[],this._$AN=void 0,this._$AD=t,this._$AM=e}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}u(t){const{el:{content:e},parts:s}=this._$AD,i=((t==null?void 0:t.creationScope)??H).importNode(e,!0);D.currentNode=i;let r=D.nextNode(),o=0,a=0,c=s[0];for(;c!==void 0;){if(o===c.index){let h;c.type===2?h=new rt(r,r.nextSibling,this,t):c.type===1?h=new c.ctor(r,c.name,c.strings,this,t):c.type===6&&(h=new Pi(r,this,t)),this._$AV.push(h),c=s[++a]}o!==(c==null?void 0:c.index)&&(r=D.nextNode(),o++)}return D.currentNode=H,i}p(t){let e=0;for(const s of this._$AV)s!==void 0&&(s.strings!==void 0?(s._$AI(t,s,e),e+=s.strings.length-2):s._$AI(t[e])),e++}}class rt{get _$AU(){var t;return((t=this._$AM)==null?void 0:t._$AU)??this._$Cv}constructor(t,e,s,i){this.type=2,this._$AH=f,this._$AN=void 0,this._$AA=t,this._$AB=e,this._$AM=s,this.options=i,this._$Cv=(i==null?void 0:i.isConnected)??!0}get parentNode(){let t=this._$AA.parentNode;const e=this._$AM;return e!==void 0&&(t==null?void 0:t.nodeType)===11&&(t=e.parentNode),t}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(t,e=this){t=q(this,t,e),st(t)?t===f||t==null||t===""?(this._$AH!==f&&this._$AR(),this._$AH=f):t!==this._$AH&&t!==R&&this._(t):t._$litType$!==void 0?this.g(t):t.nodeType!==void 0?this.$(t):$i(t)?this.T(t):this._(t)}k(t){return this._$AA.parentNode.insertBefore(t,this._$AB)}$(t){this._$AH!==t&&(this._$AR(),this._$AH=this.k(t))}_(t){this._$AH!==f&&st(this._$AH)?this._$AA.nextSibling.data=t:this.$(H.createTextNode(t)),this._$AH=t}g(t){var r;const{values:e,_$litType$:s}=t,i=typeof s=="number"?this._$AC(t):(s.el===void 0&&(s.el=nt.createElement(Is(s.h,s.h[0]),this.options)),s);if(((r=this._$AH)==null?void 0:r._$AD)===i)this._$AH.p(e);else{const o=new Ei(i,this),a=o.u(this.options);o.p(e),this.$(a),this._$AH=o}}_$AC(t){let e=is.get(t.strings);return e===void 0&&is.set(t.strings,e=new nt(t)),e}T(t){Ns(this._$AH)||(this._$AH=[],this._$AR());const e=this._$AH;let s,i=0;for(const r of t)i===e.length?e.push(s=new rt(this.k(et()),this.k(et()),this,this.options)):s=e[i],s._$AI(r),i++;i<e.length&&(this._$AR(s&&s._$AB.nextSibling,i),e.length=i)}_$AR(t=this._$AA.nextSibling,e){var s;for((s=this._$AP)==null?void 0:s.call(this,!1,!0,e);t&&t!==this._$AB;){const i=t.nextSibling;t.remove(),t=i}}setConnected(t){var e;this._$AM===void 0&&(this._$Cv=t,(e=this._$AP)==null||e.call(this,t))}}class Mt{get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}constructor(t,e,s,i,r){this.type=1,this._$AH=f,this._$AN=void 0,this.element=t,this.name=e,this._$AM=i,this.options=r,s.length>2||s[0]!==""||s[1]!==""?(this._$AH=Array(s.length-1).fill(new String),this.strings=s):this._$AH=f}_$AI(t,e=this,s,i){const r=this.strings;let o=!1;if(r===void 0)t=q(this,t,e,0),o=!st(t)||t!==this._$AH&&t!==R,o&&(this._$AH=t);else{const a=t;let c,h;for(t=r[0],c=0;c<r.length-1;c++)h=q(this,a[s+c],e,c),h===R&&(h=this._$AH[c]),o||(o=!st(h)||h!==this._$AH[c]),h===f?t=f:t!==f&&(t+=(h??"")+r[c+1]),this._$AH[c]=h}o&&!i&&this.O(t)}O(t){t===f?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,t??"")}}class Ai extends Mt{constructor(){super(...arguments),this.type=3}O(t){this.element[this.name]=t===f?void 0:t}}class xi extends Mt{constructor(){super(...arguments),this.type=4}O(t){this.element.toggleAttribute(this.name,!!t&&t!==f)}}class Si extends Mt{constructor(t,e,s,i,r){super(t,e,s,i,r),this.type=5}_$AI(t,e=this){if((t=q(this,t,e,0)??f)===R)return;const s=this._$AH,i=t===f&&s!==f||t.capture!==s.capture||t.once!==s.once||t.passive!==s.passive,r=t!==f&&(s===f||i);i&&this.element.removeEventListener(this.name,this,s),r&&this.element.addEventListener(this.name,this,t),this._$AH=t}handleEvent(t){var e;typeof this._$AH=="function"?this._$AH.call(((e=this.options)==null?void 0:e.host)??this.element,t):this._$AH.handleEvent(t)}}class Pi{constructor(t,e,s){this.element=t,this.type=6,this._$AN=void 0,this._$AM=e,this.options=s}get _$AU(){return this._$AM._$AU}_$AI(t){q(this,t)}}const Qt=G.litHtmlPolyfillSupport;Qt==null||Qt(nt,rt),(G.litHtmlVersions??(G.litHtmlVersions=[])).push("3.0.2");const Ci=(n,t,e)=>{const s=(e==null?void 0:e.renderBefore)??t;let i=s._$litPart$;if(i===void 0){const r=(e==null?void 0:e.renderBefore)??null;s._$litPart$=i=new rt(t.insertBefore(et(),r),r,void 0,e??{})}return i._$AI(n),i};/**
|
|
30
|
-
* @license
|
|
31
|
-
* Copyright 2017 Google LLC
|
|
32
|
-
* SPDX-License-Identifier: BSD-3-Clause
|
|
33
|
-
*/class X extends L{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0}createRenderRoot(){var e;const t=super.createRenderRoot();return(e=this.renderOptions).renderBefore??(e.renderBefore=t.firstChild),t}update(t){const e=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(t),this._$Do=Ci(e,this.renderRoot,this.renderOptions)}connectedCallback(){var t;super.connectedCallback(),(t=this._$Do)==null||t.setConnected(!0)}disconnectedCallback(){var t;super.disconnectedCallback(),(t=this._$Do)==null||t.setConnected(!1)}render(){return R}}var ls;X._$litElement$=!0,X.finalized=!0,(ls=globalThis.litElementHydrateSupport)==null||ls.call(globalThis,{LitElement:X});const Yt=globalThis.litElementPolyfillSupport;Yt==null||Yt({LitElement:X});(globalThis.litElementVersions??(globalThis.litElementVersions=[])).push("4.0.1");/**
|
|
34
|
-
* @license
|
|
35
|
-
* Copyright 2017 Google LLC
|
|
36
|
-
* SPDX-License-Identifier: BSD-3-Clause
|
|
37
|
-
*/const Oi={attribute:!0,type:String,converter:_t,reflect:!1,hasChanged:Ee},ki=(n=Oi,t,e)=>{const{kind:s,metadata:i}=e;let r=globalThis.litPropertyMetadata.get(i);if(r===void 0&&globalThis.litPropertyMetadata.set(i,r=new Map),r.set(e.name,n),s==="accessor"){const{name:o}=e;return{set(a){const c=t.get.call(this);t.set.call(this,a),this.requestUpdate(o,c,n)},init(a){return a!==void 0&&this.C(o,void 0,n),a}}}if(s==="setter"){const{name:o}=e;return function(a){const c=this[o];t.call(this,a),this.requestUpdate(o,c,n)}}throw Error("Unsupported decorator location: "+s)};function Ae(n){return(t,e)=>typeof e=="object"?ki(n,t,e):((s,i,r)=>{const o=i.hasOwnProperty(r);return i.constructor.createProperty(r,o?{...s,wrapped:!0}:s),o?Object.getOwnPropertyDescriptor(i,r):void 0})(n,t,e)}/**
|
|
38
|
-
* @license
|
|
39
|
-
* Copyright 2017 Google LLC
|
|
40
|
-
* SPDX-License-Identifier: BSD-3-Clause
|
|
41
|
-
*/function xe(n){return Ae({...n,state:!0,attribute:!1})}/**
|
|
42
|
-
* @license
|
|
43
|
-
* Copyright 2017 Google LLC
|
|
44
|
-
* SPDX-License-Identifier: BSD-3-Clause
|
|
45
|
-
*/const Ti={ATTRIBUTE:1,CHILD:2,PROPERTY:3,BOOLEAN_ATTRIBUTE:4,EVENT:5,ELEMENT:6},Ni=n=>(...t)=>({_$litDirective$:n,values:t});class Mi{constructor(t){}get _$AU(){return this._$AM._$AU}_$AT(t,e,s){this._$Ct=t,this._$AM=e,this._$Ci=s}_$AS(t,e){return this.update(t,e)}update(t,e){return this.render(...e)}}/**
|
|
46
|
-
* @license
|
|
47
|
-
* Copyright 2018 Google LLC
|
|
48
|
-
* SPDX-License-Identifier: BSD-3-Clause
|
|
49
|
-
*/const Ii=Ni(class extends Mi{constructor(n){var t;if(super(n),n.type!==Ti.ATTRIBUTE||n.name!=="class"||((t=n.strings)==null?void 0:t.length)>2)throw Error("`classMap()` can only be used in the `class` attribute and must be the only part in the attribute.")}render(n){return" "+Object.keys(n).filter(t=>n[t]).join(" ")+" "}update(n,[t]){var s,i;if(this.it===void 0){this.it=new Set,n.strings!==void 0&&(this.st=new Set(n.strings.join(" ").split(/\s/).filter(r=>r!=="")));for(const r in t)t[r]&&!((s=this.st)!=null&&s.has(r))&&this.it.add(r);return this.render(t)}const e=n.element.classList;for(const r of this.it)r in t||(e.remove(r),this.it.delete(r));for(const r in t){const o=!!t[r];o===this.it.has(r)||(i=this.st)!=null&&i.has(r)||(o?(e.add(r),this.it.add(r)):(e.remove(r),this.it.delete(r)))}return R}}),pt=(n,t,e)=>{n&&e.style.setProperty(t,n)},ji=(n,t)=>{var e,s,i,r;pt((e=n.colors)==null?void 0:e.primaryBackground,"--primary-background",t),pt((s=n.colors)==null?void 0:s.textOnPrimaryBackground,"--text-on-primary-background",t),pt((i=n.colors)==null?void 0:i.secondaryBackground,"--secondary-background",t),pt((r=n.colors)==null?void 0:r.textOnSecondaryBackground,"--text-on-secondary-background",t)};var Ui=Object.defineProperty,Di=Object.getOwnPropertyDescriptor,ot=(n,t,e,s)=>{for(var i=s>1?void 0:s?Di(t,e):t,r=n.length-1,o;r>=0;r--)(o=n[r])&&(i=(s?o(t,e,i):o(i))||i);return s&&i&&Ui(t,e,i),i};class J extends X{constructor(){super(...arguments),this.active=!1,this.loaded=!1}async connectedCallback(){super.connectedCallback(),this.icon=await this._renderSymbol(this.symbol),this.loaded=!0,this._applyBranding()}_toggleActive(){this.active=!this.active}_applyBranding(){var e;const t=((e=this.container)==null?void 0:e.get("$settings"))??{};t!=null&&t.branding&&ji(t.branding,this)}async _renderSymbol(t){const e=async s=>await Promise.resolve().then(()=>require("./index-6dd00f59.js")).then(r=>r[s]);if(t){const{type:s,content:i}=t;switch(s){case"Telia":{const r=await e(i);return r?dt`<telia-icon
|
|
50
|
-
class="trigger-icon"
|
|
51
|
-
svg=${r.svg}
|
|
52
|
-
size="lg"
|
|
53
|
-
></telia-icon>`:f}case"FontAwesome":return dt`<i class="trigger-fa-icon fa fa-${i}"></i>`;case"Uri":return dt`<i
|
|
54
|
-
class="trigger-custom-icon"
|
|
55
|
-
style="background: url(${i}) no-repeat center center;background-size: contain;"
|
|
56
|
-
></i>`;default:return f}}}render(){return dt`<button
|
|
57
|
-
class=${Ii({trigger:!0,active:this.active,rendered:this.loaded})}
|
|
58
|
-
@click=${this._toggleActive}
|
|
59
|
-
>
|
|
60
|
-
${this.icon}
|
|
61
|
-
<span class="trigger-close">
|
|
62
|
-
<svg
|
|
63
|
-
width="18"
|
|
64
|
-
height="9"
|
|
65
|
-
viewBox="0 0 18 9"
|
|
66
|
-
fill="none"
|
|
67
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
68
|
-
>
|
|
69
|
-
<path
|
|
70
|
-
d="M9 9C8.81794 9.00045 8.63759 8.96634 8.46939 8.89965C8.3012 8.83295 8.14851 8.735 8.02015 8.61145L0.194523 1.12367C0.068294 0.99862 -0.00155266 0.831133 2.61958e-05 0.657285C0.00160506 0.483436 0.0744832 0.317136 0.202964 0.194202C0.331445 0.0712675 0.505249 0.00153576 0.686941 2.50649e-05C0.868634 -0.00148563 1.04368 0.0653456 1.17437 0.186125L9 7.6739L16.8256 0.186125C16.9563 0.0653456 17.1314 -0.00148563 17.3131 2.50649e-05C17.4948 0.00153576 17.6686 0.0712675 17.797 0.194202C17.9255 0.317136 17.9984 0.483436 18 0.657285C18.0016 0.831133 17.9317 0.99862 17.8055 1.12367L9.97985 8.61145C9.85149 8.735 9.6988 8.83295 9.53061 8.89965C9.36241 8.96634 9.18206 9.00045 9 9Z"
|
|
71
|
-
fill="white"
|
|
72
|
-
/>
|
|
73
|
-
</svg>
|
|
74
|
-
</span>
|
|
75
|
-
<span class="trigger-loader">
|
|
76
|
-
<svg viewBox="25 25 50 50">
|
|
77
|
-
<circle
|
|
78
|
-
cx="50"
|
|
79
|
-
cy="50"
|
|
80
|
-
r="20"
|
|
81
|
-
fill="none"
|
|
82
|
-
stroke="#000"
|
|
83
|
-
stroke-width="2"
|
|
84
|
-
stroke-miterlimit="10"
|
|
85
|
-
/>
|
|
86
|
-
</svg>
|
|
87
|
-
</span>
|
|
88
|
-
</button>`}}J.styles=[li`
|
|
89
|
-
:host {
|
|
90
|
-
--voca-rem-multiplier: 0.625;
|
|
91
|
-
display: block;
|
|
92
|
-
box-sizing: border-box;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
.trigger {
|
|
96
|
-
position: fixed;
|
|
97
|
-
transform: scale(0);
|
|
98
|
-
box-shadow: rgba(0, 0, 0, 0.16) 0px 5px 40px;
|
|
99
|
-
bottom: 20px;
|
|
100
|
-
right: 20px;
|
|
101
|
-
z-index: 5;
|
|
102
|
-
display: flex;
|
|
103
|
-
align-items: center;
|
|
104
|
-
justify-content: center;
|
|
105
|
-
border: none;
|
|
106
|
-
line-height: 55px;
|
|
107
|
-
height: 55px;
|
|
108
|
-
width: 55px;
|
|
109
|
-
border-radius: 55px;
|
|
110
|
-
cursor: pointer;
|
|
111
|
-
background-color: var(--trigger-bg, var(--primary-background));
|
|
112
|
-
font-family: Lato;
|
|
113
|
-
text-decoration: none;
|
|
114
|
-
border: 3px dashed transparent;
|
|
115
|
-
box-sizing: border-box;
|
|
116
|
-
transition: transform 200ms ease-out;
|
|
117
|
-
}
|
|
118
|
-
.trigger:hover {
|
|
119
|
-
transform: scale(1.1) !important;
|
|
120
|
-
}
|
|
121
|
-
.trigger.rendered {
|
|
122
|
-
transform: scale(1);
|
|
123
|
-
}
|
|
124
|
-
.trigger.active .trigger-icon {
|
|
125
|
-
opacity: 0;
|
|
126
|
-
transform: rotate(-180deg) scale(0);
|
|
127
|
-
}
|
|
128
|
-
.trigger.active .trigger-close {
|
|
129
|
-
opacity: 1;
|
|
130
|
-
transform: rotate(0deg) scale(1);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
.trigger-icon {
|
|
134
|
-
display: inline-block;
|
|
135
|
-
line-height: inherit;
|
|
136
|
-
text-align: center;
|
|
137
|
-
opacity: 1;
|
|
138
|
-
transform: rotate(0deg) scale(1);
|
|
139
|
-
transition: opacity 200ms ease-out, transform 200ms ease-out;
|
|
140
|
-
color: var(--trigger-text-color, var(--text-on-primary-background));
|
|
141
|
-
}
|
|
142
|
-
.trigger-close {
|
|
143
|
-
opacity: 0;
|
|
144
|
-
transition: transform 200ms ease-out;
|
|
145
|
-
transform: rotate(180deg) scale(0);
|
|
146
|
-
position: absolute;
|
|
147
|
-
top: 0;
|
|
148
|
-
bottom: 0;
|
|
149
|
-
left: 0;
|
|
150
|
-
right: 0;
|
|
151
|
-
display: flex;
|
|
152
|
-
justify-content: center;
|
|
153
|
-
align-items: center;
|
|
154
|
-
fill: var(--trigger-text-color, var(--text-on-primary-background));
|
|
155
|
-
}
|
|
156
|
-
`];ot([Ae({attribute:!1})],J.prototype,"symbol",2);ot([Ae({attribute:!1})],J.prototype,"container",2);ot([xe()],J.prototype,"active",2);ot([xe()],J.prototype,"loaded",2);ot([xe()],J.prototype,"icon",2);var mt=(n=>(n.LinkList="link-list",n.Separator="separator",n.ButtonList="button-list",n.ItemList="item-list",n.Text="text",n.HTML="html",n.VideoRequest="video-request",n))(mt||{});const Hi=({isUser:n,items:t=[],meta:e={}})=>{const s=I();return{id:s,isUser:n,items:t.map(r=>({id:r.id||I(),isUser:n,groupId:s,message:r.message||[]})),meta:e}};var ie=function(n,t){return ie=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,s){e.__proto__=s}||function(e,s){for(var i in s)Object.prototype.hasOwnProperty.call(s,i)&&(e[i]=s[i])},ie(n,t)};function at(n,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");ie(n,t);function e(){this.constructor=n}n.prototype=t===null?Object.create(t):(e.prototype=t.prototype,new e)}function re(n){var t=typeof Symbol=="function"&&Symbol.iterator,e=t&&n[t],s=0;if(e)return e.call(n);if(n&&typeof n.length=="number")return{next:function(){return n&&s>=n.length&&(n=void 0),{value:n&&n[s++],done:!n}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function At(n,t){var e=typeof Symbol=="function"&&n[Symbol.iterator];if(!e)return n;var s=e.call(n),i,r=[],o;try{for(;(t===void 0||t-- >0)&&!(i=s.next()).done;)r.push(i.value)}catch(a){o={error:a}}finally{try{i&&!i.done&&(e=s.return)&&e.call(s)}finally{if(o)throw o.error}}return r}function xt(n,t,e){if(e||arguments.length===2)for(var s=0,i=t.length,r;s<i;s++)(r||!(s in t))&&(r||(r=Array.prototype.slice.call(t,0,s)),r[s]=t[s]);return n.concat(r||Array.prototype.slice.call(t))}function O(n){return typeof n=="function"}function js(n){var t=function(s){Error.call(s),s.stack=new Error().stack},e=n(t);return e.prototype=Object.create(Error.prototype),e.prototype.constructor=e,e}var Zt=js(function(n){return function(e){n(this),this.message=e?e.length+` errors occurred during unsubscription:
|
|
157
|
-
`+e.map(function(s,i){return i+1+") "+s.toString()}).join(`
|
|
158
|
-
`):"",this.name="UnsubscriptionError",this.errors=e}});function oe(n,t){if(n){var e=n.indexOf(t);0<=e&&n.splice(e,1)}}var It=function(){function n(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}return n.prototype.unsubscribe=function(){var t,e,s,i,r;if(!this.closed){this.closed=!0;var o=this._parentage;if(o)if(this._parentage=null,Array.isArray(o))try{for(var a=re(o),c=a.next();!c.done;c=a.next()){var h=c.value;h.remove(this)}}catch(m){t={error:m}}finally{try{c&&!c.done&&(e=a.return)&&e.call(a)}finally{if(t)throw t.error}}else o.remove(this);var l=this.initialTeardown;if(O(l))try{l()}catch(m){r=m instanceof Zt?m.errors:[m]}var u=this._finalizers;if(u){this._finalizers=null;try{for(var p=re(u),d=p.next();!d.done;d=p.next()){var v=d.value;try{rs(v)}catch(m){r=r??[],m instanceof Zt?r=xt(xt([],At(r)),At(m.errors)):r.push(m)}}}catch(m){s={error:m}}finally{try{d&&!d.done&&(i=p.return)&&i.call(p)}finally{if(s)throw s.error}}}if(r)throw new Zt(r)}},n.prototype.add=function(t){var e;if(t&&t!==this)if(this.closed)rs(t);else{if(t instanceof n){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=(e=this._finalizers)!==null&&e!==void 0?e:[]).push(t)}},n.prototype._hasParent=function(t){var e=this._parentage;return e===t||Array.isArray(e)&&e.includes(t)},n.prototype._addParent=function(t){var e=this._parentage;this._parentage=Array.isArray(e)?(e.push(t),e):e?[e,t]:t},n.prototype._removeParent=function(t){var e=this._parentage;e===t?this._parentage=null:Array.isArray(e)&&oe(e,t)},n.prototype.remove=function(t){var e=this._finalizers;e&&oe(e,t),t instanceof n&&t._removeParent(this)},n.EMPTY=function(){var t=new n;return t.closed=!0,t}(),n}(),Us=It.EMPTY;function Ds(n){return n instanceof It||n&&"closed"in n&&O(n.remove)&&O(n.add)&&O(n.unsubscribe)}function rs(n){O(n)?n():n.unsubscribe()}var Hs={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},ae={setTimeout:function(n,t){for(var e=[],s=2;s<arguments.length;s++)e[s-2]=arguments[s];var i=ae.delegate;return i!=null&&i.setTimeout?i.setTimeout.apply(i,xt([n,t],At(e))):setTimeout.apply(void 0,xt([n,t],At(e)))},clearTimeout:function(n){var t=ae.delegate;return((t==null?void 0:t.clearTimeout)||clearTimeout)(n)},delegate:void 0};function Ri(n){ae.setTimeout(function(){throw n})}function os(){}function vt(n){n()}var Rs=function(n){at(t,n);function t(e){var s=n.call(this)||this;return s.isStopped=!1,e?(s.destination=e,Ds(e)&&e.add(s)):s.destination=Bi,s}return t.create=function(e,s,i){return new ce(e,s,i)},t.prototype.next=function(e){this.isStopped||this._next(e)},t.prototype.error=function(e){this.isStopped||(this.isStopped=!0,this._error(e))},t.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},t.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,n.prototype.unsubscribe.call(this),this.destination=null)},t.prototype._next=function(e){this.destination.next(e)},t.prototype._error=function(e){try{this.destination.error(e)}finally{this.unsubscribe()}},t.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},t}(It),Wi=Function.prototype.bind;function Gt(n,t){return Wi.call(n,t)}var Li=function(){function n(t){this.partialObserver=t}return n.prototype.next=function(t){var e=this.partialObserver;if(e.next)try{e.next(t)}catch(s){gt(s)}},n.prototype.error=function(t){var e=this.partialObserver;if(e.error)try{e.error(t)}catch(s){gt(s)}else gt(t)},n.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(e){gt(e)}},n}(),ce=function(n){at(t,n);function t(e,s,i){var r=n.call(this)||this,o;if(O(e)||!e)o={next:e??void 0,error:s??void 0,complete:i??void 0};else{var a;r&&Hs.useDeprecatedNextContext?(a=Object.create(e),a.unsubscribe=function(){return r.unsubscribe()},o={next:e.next&&Gt(e.next,a),error:e.error&&Gt(e.error,a),complete:e.complete&&Gt(e.complete,a)}):o=e}return r.destination=new Li(o),r}return t}(Rs);function gt(n){Ri(n)}function zi(n){throw n}var Bi={closed:!0,next:os,error:zi,complete:os},Vi=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();function qi(n){return n}function Fi(n){return n.length===0?qi:n.length===1?n[0]:function(e){return n.reduce(function(s,i){return i(s)},e)}}var as=function(){function n(t){t&&(this._subscribe=t)}return n.prototype.lift=function(t){var e=new n;return e.source=this,e.operator=t,e},n.prototype.subscribe=function(t,e,s){var i=this,r=Ki(t)?t:new ce(t,e,s);return vt(function(){var o=i,a=o.operator,c=o.source;r.add(a?a.call(r,c):c?i._subscribe(r):i._trySubscribe(r))}),r},n.prototype._trySubscribe=function(t){try{return this._subscribe(t)}catch(e){t.error(e)}},n.prototype.forEach=function(t,e){var s=this;return e=cs(e),new e(function(i,r){var o=new ce({next:function(a){try{t(a)}catch(c){r(c),o.unsubscribe()}},error:r,complete:i});s.subscribe(o)})},n.prototype._subscribe=function(t){var e;return(e=this.source)===null||e===void 0?void 0:e.subscribe(t)},n.prototype[Vi]=function(){return this},n.prototype.pipe=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return Fi(t)(this)},n.prototype.toPromise=function(t){var e=this;return t=cs(t),new t(function(s,i){var r;e.subscribe(function(o){return r=o},function(o){return i(o)},function(){return s(r)})})},n.create=function(t){return new n(t)},n}();function cs(n){var t;return(t=n??Hs.Promise)!==null&&t!==void 0?t:Promise}function Ji(n){return n&&O(n.next)&&O(n.error)&&O(n.complete)}function Ki(n){return n&&n instanceof Rs||Ji(n)&&Ds(n)}var Qi=js(function(n){return function(){n(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}}),St=function(n){at(t,n);function t(){var e=n.call(this)||this;return e.closed=!1,e.currentObservers=null,e.observers=[],e.isStopped=!1,e.hasError=!1,e.thrownError=null,e}return t.prototype.lift=function(e){var s=new hs(this,this);return s.operator=e,s},t.prototype._throwIfClosed=function(){if(this.closed)throw new Qi},t.prototype.next=function(e){var s=this;vt(function(){var i,r;if(s._throwIfClosed(),!s.isStopped){s.currentObservers||(s.currentObservers=Array.from(s.observers));try{for(var o=re(s.currentObservers),a=o.next();!a.done;a=o.next()){var c=a.value;c.next(e)}}catch(h){i={error:h}}finally{try{a&&!a.done&&(r=o.return)&&r.call(o)}finally{if(i)throw i.error}}}})},t.prototype.error=function(e){var s=this;vt(function(){if(s._throwIfClosed(),!s.isStopped){s.hasError=s.isStopped=!0,s.thrownError=e;for(var i=s.observers;i.length;)i.shift().error(e)}})},t.prototype.complete=function(){var e=this;vt(function(){if(e._throwIfClosed(),!e.isStopped){e.isStopped=!0;for(var s=e.observers;s.length;)s.shift().complete()}})},t.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(t.prototype,"observed",{get:function(){var e;return((e=this.observers)===null||e===void 0?void 0:e.length)>0},enumerable:!1,configurable:!0}),t.prototype._trySubscribe=function(e){return this._throwIfClosed(),n.prototype._trySubscribe.call(this,e)},t.prototype._subscribe=function(e){return this._throwIfClosed(),this._checkFinalizedStatuses(e),this._innerSubscribe(e)},t.prototype._innerSubscribe=function(e){var s=this,i=this,r=i.hasError,o=i.isStopped,a=i.observers;return r||o?Us:(this.currentObservers=null,a.push(e),new It(function(){s.currentObservers=null,oe(a,e)}))},t.prototype._checkFinalizedStatuses=function(e){var s=this,i=s.hasError,r=s.thrownError,o=s.isStopped;i?e.error(r):o&&e.complete()},t.prototype.asObservable=function(){var e=new as;return e.source=this,e},t.create=function(e,s){return new hs(e,s)},t}(as),hs=function(n){at(t,n);function t(e,s){var i=n.call(this)||this;return i.destination=e,i.source=s,i}return t.prototype.next=function(e){var s,i;(i=(s=this.destination)===null||s===void 0?void 0:s.next)===null||i===void 0||i.call(s,e)},t.prototype.error=function(e){var s,i;(i=(s=this.destination)===null||s===void 0?void 0:s.error)===null||i===void 0||i.call(s,e)},t.prototype.complete=function(){var e,s;(s=(e=this.destination)===null||e===void 0?void 0:e.complete)===null||s===void 0||s.call(e)},t.prototype._subscribe=function(e){var s,i;return(i=(s=this.source)===null||s===void 0?void 0:s.subscribe(e))!==null&&i!==void 0?i:Us},t}(St),Yi=function(n){at(t,n);function t(e){var s=n.call(this)||this;return s._value=e,s}return Object.defineProperty(t.prototype,"value",{get:function(){return this.getValue()},enumerable:!1,configurable:!0}),t.prototype._subscribe=function(e){var s=n.prototype._subscribe.call(this,e);return!s.closed&&e.next(this._value),s},t.prototype.getValue=function(){var e=this,s=e.hasError,i=e.thrownError,r=e._value;if(s)throw i;return this._throwIfClosed(),r},t.prototype.next=function(e){n.prototype.next.call(this,this._value=e)},t}(St);const Zi=n=>{var t,e;return!!((t=n==null?void 0:n.outputPayload)!=null&&t.textOutputContent)&&((e=n==null?void 0:n.outputPayload)==null?void 0:e.isFinal)},Gi=n=>{var t;return!!((t=n==null?void 0:n.outputPayload)!=null&&t.textStreamOutputContent)};class Xi{constructor(t){this.settings=t,this.currentSequenceNumber=1,this.isConnected$=new Yi(!1),this.messageSubject$=new St,this.systemEvents$=new St,this.isConnected=()=>this.isConnected$.asObservable(),this.messages=()=>this.messageSubject$.asObservable(),this.events=()=>this.systemEvents$.asObservable(),this.ws=new WebSocket(t.connectionUri),this.ws.onopen=e=>{this.onConnected()},this.ws.onmessage=e=>{this.onMessage(e)},this.ws.onerror=e=>{this.onError(e)},this.ws.onclose=e=>{this.onClose(e)}}sendMessage(t){this._sendMessage({sequenceNumber:this.currentSequenceNumber,inputPayload:{textInputContent:{text:t.text}}}),this.incrementSequenceNumber()}onConnected(){console.log("Connection established."),this.isConnected$.next(!0);const t={sequenceNumber:1,initializeRequestPayload:{extension:this.settings.extension}};this.systemEvents$.next({event:"connected",text:"Connection established"}),this._sendMessage(t)}_sendMessage(t){if(!this.isConnected$.value){console.warn("Message could not be sent, you are not connected.");return}this.ws.send(JSON.stringify(t))}incrementSequenceNumber(){this.currentSequenceNumber=this.currentSequenceNumber+1}onMessage(t){const e=JSON.parse(t.data);Gi(e)?this.messageSubject$.next({text:e.outputPayload.textStreamOutputContent.textPart||"",isComplete:!!e.outputPayload.isFinal,sequenceNumber:e.sequenceNumber,type:"stream"}):Zi(e)&&this.messageSubject$.next({text:e.outputPayload.textOutputContent.text,isComplete:!0,sequenceNumber:e.sequenceNumber,type:"text"})}onError(t){console.error("Connection error:",t),this.systemEvents$.next({event:"error",text:"Something went wrong"})}onClose(t){console.log("Connection closed",t),this.systemEvents$.next({event:"disconnected",text:"Connection closed"}),this.isConnected$.next(!1)}}class tr{constructor(t,e,s){this.container=t,this.conversation=e,this.groups=[],this.lastReceivedMessageWasComplete=!0,this.lastWrittenEntry=null,this.isConnected=!1,this.connection=new Xi({connectionUri:"wss://cso-ccs.labbn.se/convhub/webconnector/v2/dialog",extension:"104"}),this.agent=e.createAgent({id:"conversational-hub-bot-agent",name:"",avatar:void 0}),this.user=e.user,this.connection.isConnected().subscribe(i=>{this.isConnected=i}),this.connection.messages().subscribe(i=>{if(i.type==="stream"){let r=null;if(this.lastReceivedMessageWasComplete||!this.lastWrittenEntry)r=this.printAgentMessage(i.text),r&&(this.lastWrittenEntry={entry:r,messages:[i]});else if(this.lastWrittenEntry){const o=this.mergeMessageParts(this.lastWrittenEntry.messages);this.updateEntry(this.lastWrittenEntry.entry,`${o}${i.text}`),this.lastWrittenEntry.messages.push(i)}this.lastReceivedMessageWasComplete=i.isComplete}else this.printAgentMessage(i.text)}),this.connection.events().subscribe(i=>{switch(i.event){case"connected":break;case"disconnected":this.printAgentMessage("You were disconnected from the chat session. Please reload the page to reconnect.");break}})}async onInput(t){switch(typeof t=="string"?t:t.actionKey){default:typeof t!="string"&&t.label&&this.printUserMessage(t.label);break}}printUserMessage(t){const e=Hi({isUser:!0,items:[{id:I(),isUser:!0,message:[mt.HTML,{body:t}]}]});return this.onMessagesReceived([e]),e}printAgentMessage(t){return this.agent.print([[mt.HTML,{body:t}]])||null}mergeMessageParts(t){return t.length?t.map(e=>e.text).join(""):""}async onMessagesReceived(t){this.groups=this.groups.concat(t),t.forEach(e=>{const s=e.items.map(i=>i.message);e.isUser?e.writer=this.user.print(s):e.writer=this.agent.print(s)})}async onMessageSend(t){this.isConnected?(this.connection.sendMessage({text:t}),this.printUserMessage(t)):this.printAgentMessage("The connection have been closed. Please reload the page to start a new session.")}updateEntry(t,e){t.update([[mt.HTML,{body:e}]])}}const er=async n=>{(await $e.getInstance(n)).registerProvider("ace-conversational-hub-provider",(e,s)=>{const i=new tr(n,e,s),r=[];return r.push(s.actions.watch("conversation.user-submit",(o,a)=>{i.onMessageSend(o.text)})),()=>{r.forEach(o=>{o()})}})};exports.ConversationalHubProviderPlugin=er;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var _=function(r,t){return _=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,n){e.__proto__=n}||function(e,n){for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(e[s]=n[s])},_(r,t)};function f(r,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");_(r,t);function e(){this.constructor=r}r.prototype=t===null?Object.create(t):(e.prototype=t.prototype,new e)}function C(r){var t=typeof Symbol=="function"&&Symbol.iterator,e=t&&r[t],n=0;if(e)return e.call(r);if(r&&typeof r.length=="number")return{next:function(){return r&&n>=r.length&&(r=void 0),{value:r&&r[n++],done:!r}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function y(r,t){var e=typeof Symbol=="function"&&r[Symbol.iterator];if(!e)return r;var n=e.call(r),s,i=[],o;try{for(;(t===void 0||t-- >0)&&!(s=n.next()).done;)i.push(s.value)}catch(u){o={error:u}}finally{try{s&&!s.done&&(e=n.return)&&e.call(n)}finally{if(o)throw o.error}}return i}function m(r,t,e){if(e||arguments.length===2)for(var n=0,s=t.length,i;n<s;n++)(i||!(n in t))&&(i||(i=Array.prototype.slice.call(t,0,n)),i[n]=t[n]);return r.concat(i||Array.prototype.slice.call(t))}function l(r){return typeof r=="function"}function B(r){var t=function(n){Error.call(n),n.stack=new Error().stack},e=r(t);return e.prototype=Object.create(Error.prototype),e.prototype.constructor=e,e}var x=B(function(r){return function(e){r(this),this.message=e?e.length+` errors occurred during unsubscription:
|
|
2
|
+
`+e.map(function(n,s){return s+1+") "+n.toString()}).join(`
|
|
3
|
+
`):"",this.name="UnsubscriptionError",this.errors=e}});function P(r,t){if(r){var e=r.indexOf(t);0<=e&&r.splice(e,1)}}var g=function(){function r(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}return r.prototype.unsubscribe=function(){var t,e,n,s,i;if(!this.closed){this.closed=!0;var o=this._parentage;if(o)if(this._parentage=null,Array.isArray(o))try{for(var u=C(o),c=u.next();!c.done;c=u.next()){var w=c.value;w.remove(this)}}catch(a){t={error:a}}finally{try{c&&!c.done&&(e=u.return)&&e.call(u)}finally{if(t)throw t.error}}else o.remove(this);var M=this.initialTeardown;if(l(M))try{M()}catch(a){i=a instanceof x?a.errors:[a]}var U=this._finalizers;if(U){this._finalizers=null;try{for(var b=C(U),p=b.next();!p.done;p=b.next()){var H=p.value;try{A(H)}catch(a){i=i??[],a instanceof x?i=m(m([],y(i)),y(a.errors)):i.push(a)}}}catch(a){n={error:a}}finally{try{p&&!p.done&&(s=b.return)&&s.call(b)}finally{if(n)throw n.error}}}if(i)throw new x(i)}},r.prototype.add=function(t){var e;if(t&&t!==this)if(this.closed)A(t);else{if(t instanceof r){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=(e=this._finalizers)!==null&&e!==void 0?e:[]).push(t)}},r.prototype._hasParent=function(t){var e=this._parentage;return e===t||Array.isArray(e)&&e.includes(t)},r.prototype._addParent=function(t){var e=this._parentage;this._parentage=Array.isArray(e)?(e.push(t),e):e?[e,t]:t},r.prototype._removeParent=function(t){var e=this._parentage;e===t?this._parentage=null:Array.isArray(e)&&P(e,t)},r.prototype.remove=function(t){var e=this._finalizers;e&&P(e,t),t instanceof r&&t._removeParent(this)},r.EMPTY=function(){var t=new r;return t.closed=!0,t}(),r}(),F=g.EMPTY;function N(r){return r instanceof g||r&&"closed"in r&&l(r.remove)&&l(r.add)&&l(r.unsubscribe)}function A(r){l(r)?r():r.unsubscribe()}var k={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},O={setTimeout:function(r,t){for(var e=[],n=2;n<arguments.length;n++)e[n-2]=arguments[n];var s=O.delegate;return s!=null&&s.setTimeout?s.setTimeout.apply(s,m([r,t],y(e))):setTimeout.apply(void 0,m([r,t],y(e)))},clearTimeout:function(r){var t=O.delegate;return((t==null?void 0:t.clearTimeout)||clearTimeout)(r)},delegate:void 0};function Y(r){O.setTimeout(function(){throw r})}function T(){}function v(r){r()}var z=function(r){f(t,r);function t(e){var n=r.call(this)||this;return n.isStopped=!1,e?(n.destination=e,N(e)&&e.add(n)):n.destination=G,n}return t.create=function(e,n,s){return new $(e,n,s)},t.prototype.next=function(e){this.isStopped||this._next(e)},t.prototype.error=function(e){this.isStopped||(this.isStopped=!0,this._error(e))},t.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},t.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,r.prototype.unsubscribe.call(this),this.destination=null)},t.prototype._next=function(e){this.destination.next(e)},t.prototype._error=function(e){try{this.destination.error(e)}finally{this.unsubscribe()}},t.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},t}(g),D=Function.prototype.bind;function E(r,t){return D.call(r,t)}var V=function(){function r(t){this.partialObserver=t}return r.prototype.next=function(t){var e=this.partialObserver;if(e.next)try{e.next(t)}catch(n){d(n)}},r.prototype.error=function(t){var e=this.partialObserver;if(e.error)try{e.error(t)}catch(n){d(n)}else d(t)},r.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(e){d(e)}},r}(),$=function(r){f(t,r);function t(e,n,s){var i=r.call(this)||this,o;if(l(e)||!e)o={next:e??void 0,error:n??void 0,complete:s??void 0};else{var u;i&&k.useDeprecatedNextContext?(u=Object.create(e),u.unsubscribe=function(){return i.unsubscribe()},o={next:e.next&&E(e.next,u),error:e.error&&E(e.error,u),complete:e.complete&&E(e.complete,u)}):o=e}return i.destination=new V(o),i}return t}(z);function d(r){Y(r)}function J(r){throw r}var G={closed:!0,next:T,error:J,complete:T},K=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();function L(r){return r}function Q(r){return r.length===0?L:r.length===1?r[0]:function(e){return r.reduce(function(n,s){return s(n)},e)}}var q=function(){function r(t){t&&(this._subscribe=t)}return r.prototype.lift=function(t){var e=new r;return e.source=this,e.operator=t,e},r.prototype.subscribe=function(t,e,n){var s=this,i=Z(t)?t:new $(t,e,n);return v(function(){var o=s,u=o.operator,c=o.source;i.add(u?u.call(i,c):c?s._subscribe(i):s._trySubscribe(i))}),i},r.prototype._trySubscribe=function(t){try{return this._subscribe(t)}catch(e){t.error(e)}},r.prototype.forEach=function(t,e){var n=this;return e=R(e),new e(function(s,i){var o=new $({next:function(u){try{t(u)}catch(c){i(c),o.unsubscribe()}},error:i,complete:s});n.subscribe(o)})},r.prototype._subscribe=function(t){var e;return(e=this.source)===null||e===void 0?void 0:e.subscribe(t)},r.prototype[K]=function(){return this},r.prototype.pipe=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return Q(t)(this)},r.prototype.toPromise=function(t){var e=this;return t=R(t),new t(function(n,s){var i;e.subscribe(function(o){return i=o},function(o){return s(o)},function(){return n(i)})})},r.create=function(t){return new r(t)},r}();function R(r){var t;return(t=r??k.Promise)!==null&&t!==void 0?t:Promise}function X(r){return r&&l(r.next)&&l(r.error)&&l(r.complete)}function Z(r){return r&&r instanceof z||X(r)&&N(r)}var ee=B(function(r){return function(){r(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}}),h=function(r){f(t,r);function t(){var e=r.call(this)||this;return e.closed=!1,e.currentObservers=null,e.observers=[],e.isStopped=!1,e.hasError=!1,e.thrownError=null,e}return t.prototype.lift=function(e){var n=new I(this,this);return n.operator=e,n},t.prototype._throwIfClosed=function(){if(this.closed)throw new ee},t.prototype.next=function(e){var n=this;v(function(){var s,i;if(n._throwIfClosed(),!n.isStopped){n.currentObservers||(n.currentObservers=Array.from(n.observers));try{for(var o=C(n.currentObservers),u=o.next();!u.done;u=o.next()){var c=u.value;c.next(e)}}catch(w){s={error:w}}finally{try{u&&!u.done&&(i=o.return)&&i.call(o)}finally{if(s)throw s.error}}}})},t.prototype.error=function(e){var n=this;v(function(){if(n._throwIfClosed(),!n.isStopped){n.hasError=n.isStopped=!0,n.thrownError=e;for(var s=n.observers;s.length;)s.shift().error(e)}})},t.prototype.complete=function(){var e=this;v(function(){if(e._throwIfClosed(),!e.isStopped){e.isStopped=!0;for(var n=e.observers;n.length;)n.shift().complete()}})},t.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(t.prototype,"observed",{get:function(){var e;return((e=this.observers)===null||e===void 0?void 0:e.length)>0},enumerable:!1,configurable:!0}),t.prototype._trySubscribe=function(e){return this._throwIfClosed(),r.prototype._trySubscribe.call(this,e)},t.prototype._subscribe=function(e){return this._throwIfClosed(),this._checkFinalizedStatuses(e),this._innerSubscribe(e)},t.prototype._innerSubscribe=function(e){var n=this,s=this,i=s.hasError,o=s.isStopped,u=s.observers;return i||o?F:(this.currentObservers=null,u.push(e),new g(function(){n.currentObservers=null,P(u,e)}))},t.prototype._checkFinalizedStatuses=function(e){var n=this,s=n.hasError,i=n.thrownError,o=n.isStopped;s?e.error(i):o&&e.complete()},t.prototype.asObservable=function(){var e=new q;return e.source=this,e},t.create=function(e,n){return new I(e,n)},t}(q),I=function(r){f(t,r);function t(e,n){var s=r.call(this)||this;return s.destination=e,s.source=n,s}return t.prototype.next=function(e){var n,s;(s=(n=this.destination)===null||n===void 0?void 0:n.next)===null||s===void 0||s.call(n,e)},t.prototype.error=function(e){var n,s;(s=(n=this.destination)===null||n===void 0?void 0:n.error)===null||s===void 0||s.call(n,e)},t.prototype.complete=function(){var e,n;(n=(e=this.destination)===null||e===void 0?void 0:e.complete)===null||n===void 0||n.call(e)},t.prototype._subscribe=function(e){var n,s;return(s=(n=this.source)===null||n===void 0?void 0:n.subscribe(e))!==null&&s!==void 0?s:F},t}(h),W=function(r){f(t,r);function t(e){var n=r.call(this)||this;return n._value=e,n}return Object.defineProperty(t.prototype,"value",{get:function(){return this.getValue()},enumerable:!1,configurable:!0}),t.prototype._subscribe=function(e){var n=r.prototype._subscribe.call(this,e);return!n.closed&&e.next(this._value),n},t.prototype.getValue=function(){var e=this,n=e.hasError,s=e.thrownError,i=e._value;if(n)throw s;return this._throwIfClosed(),i},t.prototype.next=function(e){r.prototype.next.call(this,this._value=e)},t}(h),S=(r=>(r.User="user",r.Agent="agent",r.System="system",r))(S||{});class j{constructor(t,e,n){this.type=t,this.sender=e,this.messages=n,this.didUpdate=new h,this.timestamp=Date.now()}update(t){this.messages=[{items:t}],this.didUpdate.next(this)}}class te{constructor(t){this.name=t,this.print$=new h}print(t){const e=new j(S.Agent,{name:this.name},[{items:[["html",{content:t}]]}]);return this.print$.next(e),e}subscribe(){return this.print$.asObservable()}}class re{constructor(t){this.name=t,this.print$=new h}print(t){const e=new j(S.User,{name:this.name},[{items:[["html",{content:t}]]}]);return this.print$.next(e),e}subscribe(){return this.print$.asObservable()}}class ne{constructor(t){this.name=t,this.print$=new h}onUserSubmit(t){this.print(S.User,t.text)}print(t,e){const n=new j(t,{name:"Botsson"},[{items:[["html",{content:e}]]}]);return this.printEntry(n)}printEntry(t){return this.print$.next(t),t}createAgent(t){const e=new te(t);return e.subscribe().subscribe(n=>{this.printEntry(n)}),e}createUser(t){const e=new re(t);return e.subscribe().subscribe(n=>{this.printEntry(n)}),e}actions(){return this.print$.asObservable()}}const se=r=>{var t,e;return!!((t=r==null?void 0:r.outputPayload)!=null&&t.textOutputContent)&&((e=r==null?void 0:r.outputPayload)==null?void 0:e.isFinal)},ie=r=>{var t;return!!((t=r==null?void 0:r.outputPayload)!=null&&t.textStreamOutputContent)},oe=r=>{var t;return!!((t=r==null?void 0:r.initializeResponsePayload)!=null&&t.greetingMessage)};class ue{constructor(t){this.settings=t,this.currentSequenceNumber=1,this.isConnected$=new W(!1),this.agent$=new W({name:""}),this.messageSubject$=new h,this.systemEvents$=new h,this.isConnected=()=>this.isConnected$.asObservable(),this.agent=()=>this.agent$.asObservable(),this.messages=()=>this.messageSubject$.asObservable(),this.events=()=>this.systemEvents$.asObservable(),this.ws=new WebSocket(t.connectionUri),this.ws.onopen=e=>{this.onConnected()},this.ws.onmessage=e=>{this.onMessage(e)},this.ws.onerror=e=>{this.onError(e)},this.ws.onclose=e=>{this.onClose(e)}}sendMessage(t){this._sendMessage({sequenceNumber:this.currentSequenceNumber,inputPayload:{textInputContent:{text:t.text}}}),this.incrementSequenceNumber()}onConnected(){console.log("Connection established."),this.isConnected$.next(!0);const t={sequenceNumber:1,initializeRequestPayload:{extension:this.settings.extension}};this.systemEvents$.next({event:"connected",text:"Connection established"}),this._sendMessage(t)}_sendMessage(t){if(!this.isConnected$.value){console.warn("Message could not be sent, you are not connected.");return}this.ws.send(JSON.stringify(t))}incrementSequenceNumber(){this.currentSequenceNumber=this.currentSequenceNumber+1}onMessage(t){const e=JSON.parse(t.data);oe(e)&&e.initializeResponsePayload.greetingMessage.length>0?(this.agent$.next({name:e.initializeResponsePayload.agentName||""}),e.initializeResponsePayload.greetingMessage.length&&this.messageSubject$.next({text:e.initializeResponsePayload.greetingMessage,isComplete:!0,sequenceNumber:e.sequenceNumber,type:"text"})):ie(e)?this.messageSubject$.next({text:e.outputPayload.textStreamOutputContent.textPart||"",isComplete:!!e.outputPayload.isFinal,sequenceNumber:e.sequenceNumber,type:"stream"}):se(e)&&this.messageSubject$.next({text:e.outputPayload.textOutputContent.text,isComplete:!0,sequenceNumber:e.sequenceNumber,type:"text"})}onError(t){console.error("Connection error:",t),this.systemEvents$.next({event:"error",text:"Something went wrong"})}onClose(t){console.log("Connection closed",t),this.systemEvents$.next({event:"disconnected",text:"Connection closed"}),this.isConnected$.next(!1)}}class ce extends ne{constructor(t){super(t),this.isConnected=!1,this.connection=new ue({connectionUri:"wss://cso-ccs.labbn.se/convhub/webconnector/v2/dialog",extension:"104"}),this.lastReceivedMessageWasComplete=!0,this.lastWrittenEntry=null,this.agent=this.createAgent(""),this.user=this.createUser(""),this.connection.isConnected().subscribe(e=>{this.isConnected=e}),this.connection.agent().subscribe(e=>{this.agent.name=e.name}),this.connection.messages().subscribe(e=>{if(e.type==="stream"){let n=null;if(this.lastReceivedMessageWasComplete||!this.lastWrittenEntry)n=this.agent.print(e.text),n&&(this.lastWrittenEntry={entry:n,messages:[e]});else if(this.lastWrittenEntry){const s=this.mergeMessageParts(this.lastWrittenEntry.messages);this.updateEntry(this.lastWrittenEntry.entry,`${s}${e.text}`),this.lastWrittenEntry.messages.push(e)}this.lastReceivedMessageWasComplete=e.isComplete}else this.agent.print(e.text)}),this.connection.events().subscribe(e=>{switch(e.event){case"connected":break;case"disconnected":this.agent.print("You were disconnected from the chat session. Please reload the page to reconnect.");break}})}onUserSubmit(t){if(!this.isConnected){this.agent.print("The connection have been closed. Please reload the page to start a new session.");return}this.connection.sendMessage({text:t.text}),this.user.print(t.text)}mergeMessageParts(t){return t.length?t.map(e=>e.text).join(""):""}updateEntry(t,e){t.update([["html",{content:e}]])}}const ae=async r=>{const t=await r.container.get("conversation");t==null||t.registerProvider("ace-conversational-hub-provider",()=>new ce("ace-conversational-hub-provider"))};exports.ConversationalHubProviderPlugin=ae;
|