@telia-ace/conversational-hub-bot-provider 0.0.7 → 1.1.2-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +3 -3
- package/index.mjs +75 -61
- package/package.json +6 -6
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var zs=Object.defineProperty;var Bs=(t,e,n)=>e in t?zs(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var O=(t,e,n)=>(Bs(t,typeof e!="symbol"?e+"":e,n),n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("react/jsx-runtime"),m=require("react"),ot=require("react-dom");function Ws(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const n in t)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,r.get?r:{enumerable:!0,get:()=>t[n]})}}return e.default=t,Object.freeze(e)}const oe=Ws(m),rn=new WeakMap;function Us(){return t=>(rn.has(t)||rn.set(t,{}),rn.get(t))}const sn=(t,e,n,...r)=>{const i=`[${t.get("$environment").name||"webprovisions"}] ${n}`;switch(e){case"info":console.info(i,...r);break;case"warning":console.warn(i,...r);break;case"error":console.error(i,...r);break}},ze=t=>{const e=t.container||t;return{info:(n,...r)=>sn(e,"info",n,...r),warn:(n,...r)=>sn(e,"warning",n,...r),error:(n,...r)=>sn(e,"error",n,...r)}},ae=Us(),Wn=(()=>{let t=0;return()=>++t})(),Un=(t,e,n)=>{const r=ae(t).touchQueue.get(e);r&&r.forEach(i=>{i(n,t)})};class Fs{constructor(e,n,r,i){this.key=e,this.factory=n,this.parent=r,this.container=i,this.id=Wn(),this.resolved=!1,this.constructed=!1,this.async=!0}resolve(){if(!this.constructed){const e=this.factory(this.parent,this.container);return this.constructed=!0,this.value=Promise.resolve(e).then(n=>(this.resolved=!0,Un(this.container,this.key,n),n))}return this.value}}class qs{constructor(e,n,r,i){this.key=e,this.value=n,this.parent=r,this.container=i,this.id=Wn(),this.async=!1,this.resolved=!1,this.constructed=!0,this.resolve=()=>(this.resolved=!0,Un(this.container,this.key,this.value),this.value)}}class Ys{constructor(e,n,r,i){this.key=e,this.value=n,this.parent=r,this.container=i,this.id=Wn(),this.async=!1,this.resolved=!1,this.constructed=!1,this.resolve=()=>{this.resolved=!0,this.constructed=!0;const s=this.value(this.parent,this.container);return Un(this.container,this.key,this.value),s}}}class Fn{constructor(e,n,r){this.owner=e,this.name=n,this.parent=r,ae(this).resolvers=new Map,ae(this).touchQueue=new Map,ae(this).children=[]}delete(e){const n=ae(this).resolvers,r=Array.from(n.values()).find(i=>i.id===e);return r?(ae(this).touchQueue.delete(r.key),Promise.resolve(n.delete(r.key))):this.parent?this.parent.delete(e):Promise.resolve(!1)}clear(){const e=ae(this).resolvers,n=Array.from(e.values());return Promise.all(n.map(r=>{if(r.constructed)return Promise.resolve(r.resolve()).then(i=>{if(i!==null&&typeof i=="object"&&typeof i.dispose=="function")return i.dispose.call(i,this,r)})})).then(()=>{n.forEach(r=>this.delete(r.id)),ae(this).children.forEach(r=>r.clear())})}detach(){if(this.parent){const e=ae(this.parent).children,n=e.indexOf(this);n>-1&&(e.splice(n,1),delete this.parent)}}touch(e,n){const r=ae(this).resolvers.get(e);if(r&&r.constructed)Promise.resolve(r.resolve()).then(i=>{n(i,this)});else{const i=ae(this).touchQueue;let s=i.get(e);s||(s=[],i.set(e,s)),s.push(n)}return this.parent&&!r?this.parent.touch(e,n):Promise.resolve()}registerAsync(e,n){const r=ae(this).resolvers.get(e);r&&!r.async&&process.env.NODE_ENV!=="production"&&ze(this).warn(`Mismatching resolver type. You are registering an async resolver with a key ('${e}') previously used by a non-async resolver.`);const i=new Fs(e,n,r,this);return ae(this).resolvers.set(e,i),i.id}registerFactory(e,n){const r=ae(this).resolvers.get(e);r&&r.async&&process.env.NODE_ENV!=="production"&&ze(this).warn(`Mismatching resolver type. You are registering a non-async resolver with a key ('${e}') previously used by an async resolver.`);const i=new Ys(e,n,r,this);return ae(this).resolvers.set(e,i),i.id}register(e,n){const r=ae(this).resolvers.get(e);r&&r.async&&process.env.NODE_ENV!=="production"&&ze(this).warn(`Mismatching resolver type. You are registering a non-async resolver with a key ('${e}') previously used by an async resolver.`);const i=new qs(e,n,r,this);return ae(this).resolvers.set(e,i),i.id}get(e){const n=ae(this).resolvers.get(e);if(n)return n.async&&process.env.NODE_ENV!=="production"&&ze(this).warn(`You are retrieving an async value (with key '${e}') by the non-async function 'container.get(key)'. This will not be supported in future versions. Use 'container.getAsync(key) instead.'`),n.resolve();if(this.parent)return this.parent.get(e)}getAsync(e){const n=ae(this).resolvers.get(e);if(n){if(!n.async)throw process.env.NODE_ENV!=="production"&&ze(this).warn(`You are retrieving a non-async value (with key '${e}') by the async function 'container.getAsync(key)'.Use 'container.get(key) instead.'`),"Mismatching resolver type";return n.resolve()}return this.parent?this.parent.getAsync(e):Promise.resolve(void 0)}getMany(...e){const n={};return e.forEach(r=>n[r]=this.get(r)),n}getManyAsync(...e){const n={};return Promise.all(e.map(r=>this.getAsync(r).then(i=>n[r]=i))).then(()=>n)}createChild(e,n){const r=new Fn(e,n,this);return ae(this).children.push(r),r}}var Lt=(t=>(t.Implementation="implementation",t.Widget="widget",t))(Lt||{}),De=(t=>(t.Pre="pre",t.Post="post",t))(De||{});const Zs=(t,e,n,r)=>{try{const i=new e(n,r);return{name:t,invoke:(s,o)=>{let a;return i[s]&&(a=i[s].call(i,o)),Promise.resolve(a)},getInstance:()=>i}}catch(i){if(i.message&&i.message.indexOf("is not a constructor")>=0)return{name:t,invoke:s=>{let o;return s==="initialize"&&(o=e(n,r)),Promise.resolve(o)},getInstance:()=>e};throw i}};function Pr(t,e){return typeof t>"u"?e:t}class Ks{constructor(e={}){this.part=e}createCommand(e,n,r){let i;typeof n=="function"?i={scope:Lt.Widget,stage:De.Post,defaultArgs:void 0,handlerResolver:n}:i={scope:Pr(n.scope,Lt.Widget),stage:Pr(n.stage,De.Post),defaultArgs:n.defaultArgs,handlerResolver:r};let s=this.part;const o=e.split(".");return o.forEach((a,l)=>{l===o.length-1?s[a]||(s[a]=()=>i):s=this.part[a]=this.part[a]||{}}),this}get(){return this.part}}const Wt=t=>{const e=new Ks({});return t(e),e.get()};Wt(t=>{t.createCommand("types.register",{scope:Lt.Implementation,stage:De.Pre},e=>(n,r)=>{e.container.get("$types")[n]=r}).createCommand("type",{stage:De.Pre},e=>n=>{e.container.register("$type",n)}).createCommand("settings",{stage:De.Pre,defaultArgs:[null]},e=>n=>{e.events.dispatch("settings:change",n,{bubbles:!0}),e.container.register("$settings",n)}).createCommand("plugin",{stage:De.Pre},e=>(n,r,i)=>{const{container:s}=e;let o=null,a=n,l=r;typeof n=="string"&&(o=n,a=r,l=i);const u=c=>{const{transformPluginSettings:d}=e.container.get("$environmentOptions"),f=d?d(l||{},o,e.container,a):r;try{const p=Zs(o,a,s,f);s.get("$plugins").push(p),c&&p.invoke("initialize",null)}catch(p){ze(e).warn("Error when initializing plugin",p)}};e.container.get("$instance")?u(!0):e.events.subscribeOnce("widget:instance-created",()=>u(!1))}).createCommand("container.register",e=>(n,r)=>{e.container.register(n,r)}).createCommand("container.registerAsync",e=>(n,r)=>{e.container.registerAsync(n,r)}).createCommand("container.registerFactory",e=>(n,r)=>{e.container.registerFactory(n,r)}).createCommand("container.touch",e=>(n,r)=>{e.container.touch(n,r)}).createCommand("csp",{},e=>n=>{e.container.register("csp",n)})});var Di=(t=>(t.Activating="activating",t.Loading="loading",t.Activated="activated",t.Deactivating="deactivating",t.Deactivated="deactivated",t))(Di||{});const Gs=t=>{const e=[];return[(r,i)=>{e.push(t.subscribe(r,i))},()=>{e.forEach(r=>{r()})}]};class Mi{constructor(e,n=[]){this.platform=e,this.rules=n}match(e){return this.rules.every(n=>!(n.id&&n.id!==e.id||n.type&&n.type!==e.type))}ofType(e){return this.rules.push({type:e}),this}withId(e){return this.rules.push({id:e}),this}select(){return new Xs(this.platform,this)}}class Js{constructor(e,n,r){O(this,"actions");O(this,"subscribe");O(this,"unsubscribe");this.platform=e,this.node=n,this.actions=new qn(e,new Mi(e).withId(n.id),r);const[i,s]=Gs(this.platform.events);this.subscribe=i,this.unsubscribe=s}properties(e){return e&&this.node.touchProperties(n=>e(n)),this.node.attributes.properties}context(e){return e&&this.subscribe("components:context-changed",(n,{node:r})=>{r===this.node&&e(this.node.attributes.context)}),this.node.attributes.context}layout(e){return e&&this.subscribe("components:layout-changed",(n,{node:r})=>{r===this.node&&e(this.node.attributes.layout)}),this.node.attributes.layout}writeProperties(e,n){this.node.writeProperties(e,n)}writeContext(e,n){this.node.writeProperties(e,n)}writeLayout(e,n){this.node.writeLayout(e,n)}dispose(){this.unsubscribe(),this.actions.dispose()}}class Xs{constructor(e,n,r=!0){O(this,"actions");O(this,"removes",[]);this.platform=e,this.target=n,this.clearOnDispose=r,this.actions=new qn(this.platform,this.target)}writeProperties(e,n){this.removes.push(this.platform.write({options:n,attributes:{properties:e},target:this.target,removable:this.clearOnDispose}))}writeContext(e,n){this.removes.push(this.platform.write({options:n,attributes:{context:e},target:this.target,removable:this.clearOnDispose}))}writeLayout(e,n){this.removes.push(this.platform.write({options:n,attributes:{layout:e},target:this.target,removable:this.clearOnDispose}))}dispose(){this.removes.forEach(e=>{e()}),this.actions.dispose()}}const Qs=(t,e,n)=>{const r=t.concat(),i=(s,o,a)=>{let l=!0;if(r.length){const u=r.shift(),c=(d,f)=>(l=!1,i(d,Object.assign({},o,f),a));return Promise.resolve(u(s,c,a)).then(d=>({...d,cancelled:l}))}return Promise.resolve({data:s,cancelled:!1,options:o})};return i(e,{},n)};class qn{constructor(e,n,r){O(this,"subscriptions",[]);this.platform=e,this.target=n,this.ns=r,this.create=this.create.bind(this)}create(e,n=()=>{}){const r={key:e,fn:n,target:this.target,ns:this.ns};this.platform.actionsState.handlers.push(r);const i=()=>{const s=this.platform.actionsState.handlers.indexOf(r);s>-1&&this.platform.actionsState.handlers.splice(s,1)};return this.subscriptions.push(i),i}dispatch(e,n){const r=this.platform.nodes.all.concat(this.platform.nodes.detached),i={},s=this.platform.actionsState.handlers.filter(o=>o.key===e&&(!o.ns||!this.ns||o.ns===this.ns));return Promise.all(s.map(o=>{const a=r.filter(u=>o.target.match(u)&&this.target.match(u)),l=this.platform.actionsState.watchers.filter(u=>u.key===e&&(!u.ns||!this.ns||u.ns===this.ns)&&a.some(c=>u.target.match(c))).map(u=>u.fn);return Promise.all(a.map(u=>{const c=new Js(this.platform,u,this.ns);return Qs(l,n,c).then(d=>{const{data:f={},options:p,cancelled:g}=d;return Promise.resolve(g?{}:o.fn(f,p,c)).then(v=>{i[u.id]=v})})}))})).then(()=>i)}watch(e,n){let r=e,i=this.ns;const s=e.split(".");s.length>1&&(i=s[0],r=s.splice(1).join("."));const o={fn:n,target:this.target,key:r,ns:i};this.platform.actionsState.watchers.push(o);const a=()=>{const l=this.platform.actionsState.watchers.indexOf(o);l>-1&&this.platform.actionsState.watchers.splice(l,1)};return this.subscriptions.push(a),a}dispose(){this.subscriptions.forEach(e=>e())}}Wt(t=>{t.createCommand("components",e=>n=>{e.events.subscribeOnce("components:platform-created",(r,{platform:i})=>{n.handlers&&n.handlers.forEach(([s,o])=>{i.addComponentHandler(s,o)})})})});function Dt(t){const e={};if(typeof t=="number"||typeof t=="string")return t;for(const n in t)if(t.hasOwnProperty(n)){const r=t[n],i=n.substring(0,1).toLowerCase()+n.substring(1);if(Object.prototype.toString.call(r)==="[object Array]"){e[i]=[];for(let s=0,o=r.length;s<o;s++)e[i].push(Dt(r[s]))}else r!==null&&typeof r=="object"?e[i]=Dt(r):e[i]=r}return e}const bt=(t,e,...n)=>typeof e=="string"?t(`[humany] ${e}`,...n):t(e,...n),We=class{constructor(){O(this,"keys",[]);O(this,"log",(e,...n)=>this.lookup(e,()=>We.log(...n)));O(this,"warn",(e,...n)=>this.lookup(e,()=>We.warn(...n)));O(this,"error",(e,...n)=>this.lookup(e,()=>We.error(...n)));O(this,"info",(e,...n)=>this.lookup(e,()=>We.info(...n)))}lookup(e,n){this.keys.indexOf(e)===-1&&(this.keys.push(e),n())}};let se=We;O(se,"log",(...e)=>bt(console.log,...e)),O(se,"warn",(...e)=>bt(console.warn,...e)),O(se,"error",(...e)=>bt(console.error,...e)),O(se,"info",(...e)=>bt(console.info,...e));const Ii=t=>{let e={},n,r;if(typeof t!="object"||t===null)return t;e=Array.isArray(t)?[]:{};for(r in t)n=t[r],e[r]=typeof n=="object"&&n!==null?Ii(n):n;return e};function jr(t){let e=0;if(t.length===0)return e.toString();for(let n=0;n<t.length;n++){const r=t.charCodeAt(n);e=(e<<5)-e+r,e=e&e}return e.toString()}function eo(t){return t.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/\s+/g,"-").toLowerCase()}class to{constructor(e,n){O(this,"tasks",[]);O(this,"current",Promise.resolve());this.lockWarningTime=e,this.lockErrorTime=n,this.next=this.next.bind(this)}add(e,n,r,i){this.tasks.push({task:e,resolve:n,reject:r,done:i}),this.next()}next(){this.current=this.current.then(()=>{const e=this.tasks.shift();if(e){let n;const r=setTimeout(()=>{process.env.NODE_ENV!=="production"&&se.warn(`A lock has exceeded ${this.lockWarningTime} ms. Waiting additional ${this.lockErrorTime} ms before rejecting the task.`,e),n=setTimeout(()=>{e.reject("lock timeout exceeded")},this.lockErrorTime)},this.lockWarningTime),i=Promise.resolve(e.task()).then(s=>(clearTimeout(r),clearTimeout(n),s));return Promise.resolve(i).then(this.next).then(()=>i.then(s=>{e.done(),e.resolve(s)})).catch(s=>(e.done(),e.reject(s),this.next()))}return Promise.resolve()})}}const xt=new WeakMap;function ht(t,e=5e3,n=1e3){return xt.has(t)||xt.set(t,new to(e,n)),r=>new Promise((i,s)=>{const o=xt.get(t);o.add(r,i,s,()=>{o.tasks.length||xt.delete(t)})})}const Pe=()=>Math.floor((1+Math.random())*65536).toString(16).substring(1);function Xe(){return Pe()+Pe()+"-"+Pe()+"-"+Pe()+"-"+Pe()+"-"+Pe()+Pe()+Pe()}function no(t){const e=[];return t.forEach(n=>{e.indexOf(n)===-1&&e.push(n)}),e}function On(t="",e=""){const n=t.split(" ").concat(e.split(" "));return no(n).join(" ").trim()}function ro(t,e){if(t){if(typeof e=="string")return e;if(Array.isArray(e)){let n="";return e.forEach(r=>n=On(n,r)),n}}}function ie(...t){let e="";return t.length&&t.forEach(n=>{typeof n=="string"?e=On(e,n):Array.isArray(n)?e=On(e,ro(...n)):typeof n<"u"&&n!==null&&process.env.NODE_ENV!=="production"&&se.warn("appendClassNames: arguments either haveto be a string or [boolean, ...string[]]. Passed args:",...t)}),e}class Ar{constructor(e,n){O(this,"id");O(this,"type");O(this,"name");O(this,"parent");O(this,"tags",[]);O(this,"children",{});O(this,"changesets",[]);O(this,"attributes");O(this,"mountCount",0);this.events=e,this.id=Xe(),this.type=n,this.attributes={context:{},properties:{},layout:{},tags:[]},this.writeLayout({size:"full",indent:0})}mount(e,n){let r=e.get("mounted-nodes");return r||(r=new Map,e.register("mounted-nodes",r)),r.has(this)?(process.env.NODE_ENV!=="production"&&se.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})),()=>{r.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(e,n="default"){if(e.parent){if(e.parent===this)return;e.parent.removeChild(e)}e.parent=this,this.children[n]||(this.children[n]=[]),this.children[n].push(e),this.events.dispatch("components:node-appended",{node:e})}prependChild(e,n="default"){if(e.parent){if(e.parent===this)return;e.parent.removeChild(e)}e.parent=this,this.children[n]||(this.children[n]=[]),this.children[n].unshift(e),this.events.dispatch("components:node-appended",{node:e})}touchProperties(e,n={},r){const s=[{properties:e},n];return this.changesets.push(s),this.events.dispatch("components:set-properties",{node:this}),()=>{if(r){const o=this.changesets.indexOf(s);o>-1&&(this.changesets.splice(o,1),this.events.dispatch("components:set-properties",{node:this}))}}}writeProperties(e,n={},r){const s=[{properties:e},n];return this.changesets.push(s),this.events.dispatch("components:set-properties",{node:this}),()=>{if(r){const o=this.changesets.indexOf(s);o>-1&&(this.changesets.splice(o,1),this.events.dispatch("components:set-properties",{node:this}))}}}writeLayout(e,n={},r){const s=[{layout:e},n];return this.changesets.push(s),this.events.dispatch("components:set-layout",{node:this}),()=>{if(!r)return;const o=this.changesets.indexOf(s);o>-1&&(this.changesets.splice(o,1),this.events.dispatch("components:set-layout",{node:this}))}}writeContext(e,n={},r){const s=[{context:e},n];return this.changesets.push(s),this.events.dispatch("components:set-context",{node:this}),()=>{if(!r)return;const o=this.changesets.indexOf(s);o>-1&&(this.changesets.splice(o,1),this.events.dispatch("components:set-context",{node:this}))}}getChildren(e="default"){const n=this.children[e]||[];return n.reduce((r,i,s)=>{const{order:o=s}=i.attributes.layout;return r[o]?r.splice(o,0,i):r[o]=i,r},Array(n.length))}remove(){this.parent&&this.parent.removeChild(this)}removeChild(e){Object.keys(this.children).forEach(n=>{const r=this.children[n],i=r.indexOf(e);i>-1&&(r.splice(i,1),this.events.dispatch("components:node-removed",{node:e,parentNode:this}))}),delete e.parent}}const Vi=(t,e,n)=>{for(let r=0,i=t.length;r<i&&n(t[r])!==!0;r++){const s=e[t[r].id]||"default",o=t[r].getChildren(s);Vi(o,e,n)}},Yn=(t,e,n)=>{if(n(t)!==!0){const r=e[t.id]||"default",i=t.children[r];Vi(i,e,n)}},on=(t,e)=>{const n=[];return Yn(t,e,r=>{n.push(r)}),n},io=(t,e,n)=>{let r;return Yn(t,e,i=>{if(n(i))return r=i,!0}),r};class so{constructor(e,n,r){O(this,"all",[]);O(this,"visible",[]);O(this,"detached",[]);this.root=e,this.switches=n,r.subscribe("components:node-appended",(i,s)=>{this.all.push(s.node),this.visible=on(e,n)}),r.subscribe("components:node-removed",(i,s)=>{let o=this.all.indexOf(s.node);o>-1&&this.all.splice(o,1),o=this.visible.indexOf(s.node),o>-1&&this.visible.splice(o,1),this.visible=on(e,n)}),r.subscribe("components:node-switched",(i,s)=>{this.visible=on(e,n)})}query(e={}){const n=[];return Yn(this.root,this.switches,r=>{Object.keys(e).every(s=>e[s]===r[s])&&n.push(r)}),n}get(e){return io(this.root,this.switches,n=>n.id===e)||this.detached.find(n=>n.id===e)}}class oo{constructor(){O(this,"handlers",new Map)}add(e,n){this.handlers.set(e,n)}get(e){return this.handlers.get(e)}}const ao=t=>{let e=t,n=0;for(;e.parent;)n=n+1,e=e.parent;return n},co=t=>t.map(([n,r])=>[ao(n),n,r]).sort(([n],[r])=>n-r).map(([,n,r])=>[n,r]),an=t=>t instanceof Date?!1:t&&typeof t=="object"&&!Array.isArray(t),Te=(t,...e)=>{if(!e.length)return t;const n=e.shift();if(an(t)&&an(n))for(const r in n)an(n[r])?(t[r]||Object.assign(t,{[r]:{}}),Te(t[r],n[r])):Object.assign(t,{[r]:n[r]});return Te(t,...e)},lo=(t,e)=>!t||t==="all"?!0:t.some(n=>e.indexOf(n)>-1),uo=(t,e)=>{let n=[],r=[],i;const s=()=>{process.env.NODE_ENV!=="production"&&console.time("state-processor.flush");const a=new Map,l=co(n.map((c,d)=>[c,r[d]])),u=(c,d)=>{var k;const f=a.get(c)||{},p=d.context&&!f.context,g=d.properties&&!f.properties,v=d.layout&&!f.layout;a.set(c,{context:f.context||p,properties:f.properties||g,layout:f.layout||v}),g&&(c.attributes.properties={}),v&&(c.attributes.layout={}),p&&(c.attributes.context=Te({},(k=c.parent)==null?void 0:k.attributes.context));const b=[],$=[],P=[];if(c.changesets.forEach(S=>{const[y,L]=S;lo(L.breakpoints,t.breakpoints)&&(g&&(typeof y.properties=="function"?b.push(y.properties):Te(c.attributes.properties,y.properties)),v&&(typeof y.layout=="function"?$.push(y.layout):Te(c.attributes.layout,y.layout)),p&&(typeof y.context=="function"?P.push(y.context):Te(c.attributes.context,y.context)))}),b.forEach(S=>{Te(c.attributes.properties,S(c.attributes.properties))}),$.forEach(S=>{Te(c.attributes.layout,S(c.attributes.layout))}),P.forEach(S=>{Te(c.attributes.context,S(c.attributes.context))}),p||d.recursive){const S=t.getBranch(c),y=d.recursive?d:{context:!!p};c.getChildren(S).forEach(L=>{u(L,y)})}};process.env.NODE_ENV!=="production"&&console.timeEnd("state-processor.flush"),l.forEach(([c,d])=>{u(c,d)}),n=[],r=[],e(a)},o=()=>{clearTimeout(i),i=setTimeout(s,0)};return(a,l)=>{const u=n.indexOf(a);if(u>-1){const c=r[u];return l.context&&(c.context=!0),l.properties&&(c.properties=!0),l.layout&&(c.layout=!0),l.recursive&&(c.recursive=!0),o()}return n.push(a),r.push(l),o()}};class Hi{constructor(e,n={}){O(this,"events");O(this,"breakpoints",[]);O(this,"nodes");O(this,"actionsState",{handlers:[],watchers:[]});O(this,"switches",{});O(this,"changesets",[]);O(this,"subscriptions",[]);O(this,"processNode");O(this,"customComponentHandler",new oo);this.providers=n,this.events=e.events.createChild(this);const r=new Ar(this.events,"root");r.name=`root-${e.name}`,this.nodes=new so(r,this.switches,this.events);const i=this.processNode=uo(this,s=>{const o=Array.from(s.keys());process.env.NODE_ENV!=="production"&&console.info(`STATE PROCESSOR: ${o.length} node(s) processed:
|
|
1
|
+
"use strict";var zs=Object.defineProperty;var Bs=(t,e,n)=>e in t?zs(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var O=(t,e,n)=>(Bs(t,typeof e!="symbol"?e+"":e,n),n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("react/jsx-runtime"),m=require("react"),ot=require("react-dom");function Ws(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const n in t)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,r.get?r:{enumerable:!0,get:()=>t[n]})}}return e.default=t,Object.freeze(e)}const oe=Ws(m),rn=new WeakMap;function Us(){return t=>(rn.has(t)||rn.set(t,{}),rn.get(t))}const sn=(t,e,n,...r)=>{const i=`[${t.get("$environment").name||"webprovisions"}] ${n}`;switch(e){case"info":console.info(i,...r);break;case"warning":console.warn(i,...r);break;case"error":console.error(i,...r);break}},ze=t=>{const e=t.container||t;return{info:(n,...r)=>sn(e,"info",n,...r),warn:(n,...r)=>sn(e,"warning",n,...r),error:(n,...r)=>sn(e,"error",n,...r)}},ae=Us(),Wn=(()=>{let t=0;return()=>++t})(),Un=(t,e,n)=>{const r=ae(t).touchQueue.get(e);r&&r.forEach(i=>{i(n,t)})};class Fs{constructor(e,n,r,i){this.key=e,this.factory=n,this.parent=r,this.container=i,this.id=Wn(),this.resolved=!1,this.constructed=!1,this.async=!0}resolve(){if(!this.constructed){const e=this.factory(this.parent,this.container);return this.constructed=!0,this.value=Promise.resolve(e).then(n=>(this.resolved=!0,Un(this.container,this.key,n),n))}return this.value}}class qs{constructor(e,n,r,i){this.key=e,this.value=n,this.parent=r,this.container=i,this.id=Wn(),this.async=!1,this.resolved=!1,this.constructed=!0,this.resolve=()=>(this.resolved=!0,Un(this.container,this.key,this.value),this.value)}}class Ys{constructor(e,n,r,i){this.key=e,this.value=n,this.parent=r,this.container=i,this.id=Wn(),this.async=!1,this.resolved=!1,this.constructed=!1,this.resolve=()=>{this.resolved=!0,this.constructed=!0;const s=this.value(this.parent,this.container);return Un(this.container,this.key,this.value),s}}}class Fn{constructor(e,n,r){this.owner=e,this.name=n,this.parent=r,ae(this).resolvers=new Map,ae(this).touchQueue=new Map,ae(this).children=[]}delete(e){const n=ae(this).resolvers,r=Array.from(n.values()).find(i=>i.id===e);return r?(ae(this).touchQueue.delete(r.key),Promise.resolve(n.delete(r.key))):this.parent?this.parent.delete(e):Promise.resolve(!1)}clear(){const e=ae(this).resolvers,n=Array.from(e.values());return Promise.all(n.map(r=>{if(r.constructed)return Promise.resolve(r.resolve()).then(i=>{if(i!==null&&typeof i=="object"&&typeof i.dispose=="function")return i.dispose.call(i,this,r)})})).then(()=>{n.forEach(r=>this.delete(r.id)),ae(this).children.forEach(r=>r.clear())})}detach(){if(this.parent){const e=ae(this.parent).children,n=e.indexOf(this);n>-1&&(e.splice(n,1),delete this.parent)}}touch(e,n){const r=ae(this).resolvers.get(e);if(r&&r.constructed)Promise.resolve(r.resolve()).then(i=>{n(i,this)});else{const i=ae(this).touchQueue;let s=i.get(e);s||(s=[],i.set(e,s)),s.push(n)}return this.parent&&!r?this.parent.touch(e,n):Promise.resolve()}registerAsync(e,n){const r=ae(this).resolvers.get(e);r&&!r.async&&process.env.NODE_ENV!=="production"&&ze(this).warn(`Mismatching resolver type. You are registering an async resolver with a key ('${e}') previously used by a non-async resolver.`);const i=new Fs(e,n,r,this);return ae(this).resolvers.set(e,i),i.id}registerFactory(e,n){const r=ae(this).resolvers.get(e);r&&r.async&&process.env.NODE_ENV!=="production"&&ze(this).warn(`Mismatching resolver type. You are registering a non-async resolver with a key ('${e}') previously used by an async resolver.`);const i=new Ys(e,n,r,this);return ae(this).resolvers.set(e,i),i.id}register(e,n){const r=ae(this).resolvers.get(e);r&&r.async&&process.env.NODE_ENV!=="production"&&ze(this).warn(`Mismatching resolver type. You are registering a non-async resolver with a key ('${e}') previously used by an async resolver.`);const i=new qs(e,n,r,this);return ae(this).resolvers.set(e,i),i.id}get(e){const n=ae(this).resolvers.get(e);if(n)return n.async&&process.env.NODE_ENV!=="production"&&ze(this).warn(`You are retrieving an async value (with key '${e}') by the non-async function 'container.get(key)'. This will not be supported in future versions. Use 'container.getAsync(key) instead.'`),n.resolve();if(this.parent)return this.parent.get(e)}getAsync(e){const n=ae(this).resolvers.get(e);if(n){if(!n.async)throw process.env.NODE_ENV!=="production"&&ze(this).warn(`You are retrieving a non-async value (with key '${e}') by the async function 'container.getAsync(key)'.Use 'container.get(key) instead.'`),"Mismatching resolver type";return n.resolve()}return this.parent?this.parent.getAsync(e):Promise.resolve(void 0)}getMany(...e){const n={};return e.forEach(r=>n[r]=this.get(r)),n}getManyAsync(...e){const n={};return Promise.all(e.map(r=>this.getAsync(r).then(i=>n[r]=i))).then(()=>n)}createChild(e,n){const r=new Fn(e,n,this);return ae(this).children.push(r),r}}var Lt=(t=>(t.Implementation="implementation",t.Widget="widget",t))(Lt||{}),De=(t=>(t.Pre="pre",t.Post="post",t))(De||{});const Zs=(t,e,n,r)=>{try{const i=new e(n,r);return{name:t,invoke:(s,o)=>{let a;return i[s]&&(a=i[s].call(i,o)),Promise.resolve(a)},getInstance:()=>i}}catch(i){if(i.message&&i.message.indexOf("is not a constructor")>=0)return{name:t,invoke:s=>{let o;return s==="initialize"&&(o=e(n,r)),Promise.resolve(o)},getInstance:()=>e};throw i}};function Pr(t,e){return typeof t>"u"?e:t}class Ks{constructor(e={}){this.part=e}createCommand(e,n,r){let i;typeof n=="function"?i={scope:Lt.Widget,stage:De.Post,defaultArgs:void 0,handlerResolver:n}:i={scope:Pr(n.scope,Lt.Widget),stage:Pr(n.stage,De.Post),defaultArgs:n.defaultArgs,handlerResolver:r};let s=this.part;const o=e.split(".");return o.forEach((a,l)=>{l===o.length-1?s[a]||(s[a]=()=>i):s=this.part[a]=this.part[a]||{}}),this}get(){return this.part}}const Wt=t=>{const e=new Ks({});return t(e),e.get()};Wt(t=>{t.createCommand("types.register",{scope:Lt.Implementation,stage:De.Pre},e=>(n,r)=>{e.container.get("$types")[n]=r}).createCommand("type",{stage:De.Pre},e=>n=>{e.container.register("$type",n)}).createCommand("settings",{stage:De.Pre,defaultArgs:[null]},e=>n=>{e.events.dispatch("settings:change",n,{bubbles:!0}),e.container.register("$settings",n)}).createCommand("plugin",{stage:De.Pre},e=>(n,r,i)=>{const{container:s}=e;let o=null,a=n,l=r;typeof n=="string"&&(o=n,a=r,l=i);const u=c=>{const{transformPluginSettings:d}=e.container.get("$environmentOptions"),f=d?d(l||{},o,e.container,a):r;try{const p=Zs(o,a,s,f);s.get("$plugins").push(p),c&&p.invoke("initialize",null)}catch(p){ze(e).warn("Error when initializing plugin",p)}};e.container.get("$instance")?u(!0):e.events.subscribeOnce("widget:instance-created",()=>u(!1))}).createCommand("container.register",e=>(n,r)=>{e.container.register(n,r)}).createCommand("container.registerAsync",e=>(n,r)=>{e.container.registerAsync(n,r)}).createCommand("container.registerFactory",e=>(n,r)=>{e.container.registerFactory(n,r)}).createCommand("container.touch",e=>(n,r)=>{e.container.touch(n,r)}).createCommand("csp",{},e=>n=>{e.container.register("csp",n)})});var Di=(t=>(t.Activating="activating",t.Loading="loading",t.Activated="activated",t.Deactivating="deactivating",t.Deactivated="deactivated",t))(Di||{});const Gs=t=>{const e=[];return[(r,i)=>{e.push(t.subscribe(r,i))},()=>{e.forEach(r=>{r()})}]};class Mi{constructor(e,n=[]){this.platform=e,this.rules=n}match(e){return this.rules.every(n=>!(n.id&&n.id!==e.id||n.type&&n.type!==e.type))}ofType(e){return this.rules.push({type:e}),this}withId(e){return this.rules.push({id:e}),this}select(){return new Xs(this.platform,this)}}class Js{constructor(e,n,r){O(this,"actions");O(this,"subscribe");O(this,"unsubscribe");this.platform=e,this.node=n,this.actions=new qn(e,new Mi(e).withId(n.id),r);const[i,s]=Gs(this.platform.events);this.subscribe=i,this.unsubscribe=s}properties(e){return e&&this.node.touchProperties(n=>e(n)),this.node.attributes.properties}context(e){return e&&this.subscribe("components:context-changed",(n,{node:r})=>{r===this.node&&e(this.node.attributes.context)}),this.node.attributes.context}layout(e){return e&&this.subscribe("components:layout-changed",(n,{node:r})=>{r===this.node&&e(this.node.attributes.layout)}),this.node.attributes.layout}writeProperties(e,n){this.node.writeProperties(e,n)}writeContext(e,n){this.node.writeProperties(e,n)}writeLayout(e,n){this.node.writeLayout(e,n)}dispose(){this.unsubscribe(),this.actions.dispose()}}class Xs{constructor(e,n,r=!0){O(this,"actions");O(this,"removes",[]);this.platform=e,this.target=n,this.clearOnDispose=r,this.actions=new qn(this.platform,this.target)}writeProperties(e,n){this.removes.push(this.platform.write({options:n,attributes:{properties:e},target:this.target,removable:this.clearOnDispose}))}writeContext(e,n){this.removes.push(this.platform.write({options:n,attributes:{context:e},target:this.target,removable:this.clearOnDispose}))}writeLayout(e,n){this.removes.push(this.platform.write({options:n,attributes:{layout:e},target:this.target,removable:this.clearOnDispose}))}dispose(){this.removes.forEach(e=>{e()}),this.actions.dispose()}}const Qs=(t,e,n)=>{const r=t.concat(),i=(s,o,a)=>{let l=!0;if(r.length){const u=r.shift(),c=(d,f)=>(l=!1,i(d,Object.assign({},o,f),a));return Promise.resolve(u(s,c,a)).then(d=>({...d,cancelled:l}))}return Promise.resolve({data:s,cancelled:!1,options:o})};return i(e,{},n)};class qn{constructor(e,n,r){O(this,"subscriptions",[]);this.platform=e,this.target=n,this.ns=r,this.create=this.create.bind(this)}create(e,n=()=>{}){const r={key:e,fn:n,target:this.target,ns:this.ns};this.platform.actionsState.handlers.push(r);const i=()=>{const s=this.platform.actionsState.handlers.indexOf(r);s>-1&&this.platform.actionsState.handlers.splice(s,1)};return this.subscriptions.push(i),i}dispatch(e,n){const r=this.platform.nodes.all.concat(this.platform.nodes.detached),i={},s=this.platform.actionsState.handlers.filter(o=>o.key===e&&(!o.ns||!this.ns||o.ns===this.ns));return Promise.all(s.map(o=>{const a=r.filter(u=>o.target.match(u)&&this.target.match(u)),l=this.platform.actionsState.watchers.filter(u=>u.key===e&&(!u.ns||!this.ns||u.ns===this.ns)&&a.some(c=>u.target.match(c))).map(u=>u.fn);return Promise.all(a.map(u=>{const c=new Js(this.platform,u,this.ns);return Qs(l,n,c).then(d=>{const{data:f={},options:p,cancelled:g}=d;return Promise.resolve(g?{}:o.fn(f,p,c)).then(v=>{i[u.id]=v})})}))})).then(()=>i)}watch(e,n){let r=e,i=this.ns;const s=e.split(".");s.length>1&&(i=s[0],r=s.splice(1).join("."));const o={fn:n,target:this.target,key:r,ns:i};this.platform.actionsState.watchers.push(o);const a=()=>{const l=this.platform.actionsState.watchers.indexOf(o);l>-1&&this.platform.actionsState.watchers.splice(l,1)};return this.subscriptions.push(a),a}dispose(){this.subscriptions.forEach(e=>e())}}Wt(t=>{t.createCommand("components",e=>n=>{e.events.subscribeOnce("components:platform-created",(r,{platform:i})=>{n.handlers&&n.handlers.forEach(([s,o])=>{i.addComponentHandler(s,o)})})})});function eo(t){const e=[];return t.forEach(n=>{e.indexOf(n)===-1&&e.push(n)}),e}function On(t="",e=""){const n=t.split(" ").concat(e.split(" "));return eo(n).join(" ").trim()}function to(t,e){if(t){if(typeof e=="string")return e;if(Array.isArray(e)){let n="";return e.forEach(r=>n=On(n,r)),n}}}function ie(...t){let e="";return t.length&&t.forEach(n=>{typeof n=="string"?e=On(e,n):Array.isArray(n)?e=On(e,to(...n)):typeof n<"u"&&n!==null&&process.env.NODE_ENV!=="production"&&se.warn("appendClassNames: arguments either haveto be a string or [boolean, ...string[]]. Passed args:",...t)}),e}function Dt(t){const e={};if(typeof t=="number"||typeof t=="string")return t;for(const n in t)if(t.hasOwnProperty(n)){const r=t[n],i=n.substring(0,1).toLowerCase()+n.substring(1);if(Object.prototype.toString.call(r)==="[object Array]"){e[i]=[];for(let s=0,o=r.length;s<o;s++)e[i].push(Dt(r[s]))}else r!==null&&typeof r=="object"?e[i]=Dt(r):e[i]=r}return e}const bt=(t,e,...n)=>typeof e=="string"?t(`[humany] ${e}`,...n):t(e,...n),We=class{constructor(){O(this,"keys",[]);O(this,"log",(e,...n)=>this.lookup(e,()=>We.log(...n)));O(this,"warn",(e,...n)=>this.lookup(e,()=>We.warn(...n)));O(this,"error",(e,...n)=>this.lookup(e,()=>We.error(...n)));O(this,"info",(e,...n)=>this.lookup(e,()=>We.info(...n)))}lookup(e,n){this.keys.indexOf(e)===-1&&(this.keys.push(e),n())}};let se=We;O(se,"log",(...e)=>bt(console.log,...e)),O(se,"warn",(...e)=>bt(console.warn,...e)),O(se,"error",(...e)=>bt(console.error,...e)),O(se,"info",(...e)=>bt(console.info,...e));const Ii=t=>{let e={},n,r;if(typeof t!="object"||t===null)return t;e=Array.isArray(t)?[]:{};for(r in t)n=t[r],e[r]=typeof n=="object"&&n!==null?Ii(n):n;return e};function jr(t){let e=0;if(t.length===0)return e.toString();for(let n=0;n<t.length;n++){const r=t.charCodeAt(n);e=(e<<5)-e+r,e=e&e}return e.toString()}function no(t){return t.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/\s+/g,"-").toLowerCase()}class ro{constructor(e,n){O(this,"tasks",[]);O(this,"current",Promise.resolve());this.lockWarningTime=e,this.lockErrorTime=n,this.next=this.next.bind(this)}add(e,n,r,i){this.tasks.push({task:e,resolve:n,reject:r,done:i}),this.next()}next(){this.current=this.current.then(()=>{const e=this.tasks.shift();if(e){let n;const r=setTimeout(()=>{process.env.NODE_ENV!=="production"&&se.warn(`A lock has exceeded ${this.lockWarningTime} ms. Waiting additional ${this.lockErrorTime} ms before rejecting the task.`,e),n=setTimeout(()=>{e.reject("lock timeout exceeded")},this.lockErrorTime)},this.lockWarningTime),i=Promise.resolve(e.task()).then(s=>(clearTimeout(r),clearTimeout(n),s));return Promise.resolve(i).then(this.next).then(()=>i.then(s=>{e.done(),e.resolve(s)})).catch(s=>(e.done(),e.reject(s),this.next()))}return Promise.resolve()})}}const xt=new WeakMap;function ht(t,e=5e3,n=1e3){return xt.has(t)||xt.set(t,new ro(e,n)),r=>new Promise((i,s)=>{const o=xt.get(t);o.add(r,i,s,()=>{o.tasks.length||xt.delete(t)})})}const Pe=()=>Math.floor((1+Math.random())*65536).toString(16).substring(1);function Xe(){return Pe()+Pe()+"-"+Pe()+"-"+Pe()+"-"+Pe()+"-"+Pe()+Pe()+Pe()}class Ar{constructor(e,n){O(this,"id");O(this,"type");O(this,"name");O(this,"parent");O(this,"tags",[]);O(this,"children",{});O(this,"changesets",[]);O(this,"attributes");O(this,"mountCount",0);this.events=e,this.id=Xe(),this.type=n,this.attributes={context:{},properties:{},layout:{},tags:[]},this.writeLayout({size:"full",indent:0})}mount(e,n){let r=e.get("mounted-nodes");return r||(r=new Map,e.register("mounted-nodes",r)),r.has(this)?(process.env.NODE_ENV!=="production"&&se.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})),()=>{r.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(e,n="default"){if(e.parent){if(e.parent===this)return;e.parent.removeChild(e)}e.parent=this,this.children[n]||(this.children[n]=[]),this.children[n].push(e),this.events.dispatch("components:node-appended",{node:e})}prependChild(e,n="default"){if(e.parent){if(e.parent===this)return;e.parent.removeChild(e)}e.parent=this,this.children[n]||(this.children[n]=[]),this.children[n].unshift(e),this.events.dispatch("components:node-appended",{node:e})}touchProperties(e,n={},r){const s=[{properties:e},n];return this.changesets.push(s),this.events.dispatch("components:set-properties",{node:this}),()=>{if(r){const o=this.changesets.indexOf(s);o>-1&&(this.changesets.splice(o,1),this.events.dispatch("components:set-properties",{node:this}))}}}writeProperties(e,n={},r){const s=[{properties:e},n];return this.changesets.push(s),this.events.dispatch("components:set-properties",{node:this}),()=>{if(r){const o=this.changesets.indexOf(s);o>-1&&(this.changesets.splice(o,1),this.events.dispatch("components:set-properties",{node:this}))}}}writeLayout(e,n={},r){const s=[{layout:e},n];return this.changesets.push(s),this.events.dispatch("components:set-layout",{node:this}),()=>{if(!r)return;const o=this.changesets.indexOf(s);o>-1&&(this.changesets.splice(o,1),this.events.dispatch("components:set-layout",{node:this}))}}writeContext(e,n={},r){const s=[{context:e},n];return this.changesets.push(s),this.events.dispatch("components:set-context",{node:this}),()=>{if(!r)return;const o=this.changesets.indexOf(s);o>-1&&(this.changesets.splice(o,1),this.events.dispatch("components:set-context",{node:this}))}}getChildren(e="default"){const n=this.children[e]||[];return n.reduce((r,i,s)=>{const{order:o=s}=i.attributes.layout;return r[o]?r.splice(o,0,i):r[o]=i,r},Array(n.length))}remove(){this.parent&&this.parent.removeChild(this)}removeChild(e){Object.keys(this.children).forEach(n=>{const r=this.children[n],i=r.indexOf(e);i>-1&&(r.splice(i,1),this.events.dispatch("components:node-removed",{node:e,parentNode:this}))}),delete e.parent}}const Vi=(t,e,n)=>{for(let r=0,i=t.length;r<i&&n(t[r])!==!0;r++){const s=e[t[r].id]||"default",o=t[r].getChildren(s);Vi(o,e,n)}},Yn=(t,e,n)=>{if(n(t)!==!0){const r=e[t.id]||"default",i=t.children[r];Vi(i,e,n)}},on=(t,e)=>{const n=[];return Yn(t,e,r=>{n.push(r)}),n},io=(t,e,n)=>{let r;return Yn(t,e,i=>{if(n(i))return r=i,!0}),r};class so{constructor(e,n,r){O(this,"all",[]);O(this,"visible",[]);O(this,"detached",[]);this.root=e,this.switches=n,r.subscribe("components:node-appended",(i,s)=>{this.all.push(s.node),this.visible=on(e,n)}),r.subscribe("components:node-removed",(i,s)=>{let o=this.all.indexOf(s.node);o>-1&&this.all.splice(o,1),o=this.visible.indexOf(s.node),o>-1&&this.visible.splice(o,1),this.visible=on(e,n)}),r.subscribe("components:node-switched",(i,s)=>{this.visible=on(e,n)})}query(e={}){const n=[];return Yn(this.root,this.switches,r=>{Object.keys(e).every(s=>e[s]===r[s])&&n.push(r)}),n}get(e){return io(this.root,this.switches,n=>n.id===e)||this.detached.find(n=>n.id===e)}}class oo{constructor(){O(this,"handlers",new Map)}add(e,n){this.handlers.set(e,n)}get(e){return this.handlers.get(e)}}const ao=t=>{let e=t,n=0;for(;e.parent;)n=n+1,e=e.parent;return n},co=t=>t.map(([n,r])=>[ao(n),n,r]).sort(([n],[r])=>n-r).map(([,n,r])=>[n,r]),an=t=>t instanceof Date?!1:t&&typeof t=="object"&&!Array.isArray(t),Te=(t,...e)=>{if(!e.length)return t;const n=e.shift();if(an(t)&&an(n))for(const r in n)an(n[r])?(t[r]||Object.assign(t,{[r]:{}}),Te(t[r],n[r])):Object.assign(t,{[r]:n[r]});return Te(t,...e)},lo=(t,e)=>!t||t==="all"?!0:t.some(n=>e.indexOf(n)>-1),uo=(t,e)=>{let n=[],r=[],i;const s=()=>{process.env.NODE_ENV!=="production"&&console.time("state-processor.flush");const a=new Map,l=co(n.map((c,d)=>[c,r[d]])),u=(c,d)=>{var k;const f=a.get(c)||{},p=d.context&&!f.context,g=d.properties&&!f.properties,v=d.layout&&!f.layout;a.set(c,{context:f.context||p,properties:f.properties||g,layout:f.layout||v}),g&&(c.attributes.properties={}),v&&(c.attributes.layout={}),p&&(c.attributes.context=Te({},(k=c.parent)==null?void 0:k.attributes.context));const b=[],$=[],P=[];if(c.changesets.forEach(S=>{const[y,L]=S;lo(L.breakpoints,t.breakpoints)&&(g&&(typeof y.properties=="function"?b.push(y.properties):Te(c.attributes.properties,y.properties)),v&&(typeof y.layout=="function"?$.push(y.layout):Te(c.attributes.layout,y.layout)),p&&(typeof y.context=="function"?P.push(y.context):Te(c.attributes.context,y.context)))}),b.forEach(S=>{Te(c.attributes.properties,S(c.attributes.properties))}),$.forEach(S=>{Te(c.attributes.layout,S(c.attributes.layout))}),P.forEach(S=>{Te(c.attributes.context,S(c.attributes.context))}),p||d.recursive){const S=t.getBranch(c),y=d.recursive?d:{context:!!p};c.getChildren(S).forEach(L=>{u(L,y)})}};process.env.NODE_ENV!=="production"&&console.timeEnd("state-processor.flush"),l.forEach(([c,d])=>{u(c,d)}),n=[],r=[],e(a)},o=()=>{clearTimeout(i),i=setTimeout(s,0)};return(a,l)=>{const u=n.indexOf(a);if(u>-1){const c=r[u];return l.context&&(c.context=!0),l.properties&&(c.properties=!0),l.layout&&(c.layout=!0),l.recursive&&(c.recursive=!0),o()}return n.push(a),r.push(l),o()}};class Hi{constructor(e,n={}){O(this,"events");O(this,"breakpoints",[]);O(this,"nodes");O(this,"actionsState",{handlers:[],watchers:[]});O(this,"switches",{});O(this,"changesets",[]);O(this,"subscriptions",[]);O(this,"processNode");O(this,"customComponentHandler",new oo);this.providers=n,this.events=e.events.createChild(this);const r=new Ar(this.events,"root");r.name=`root-${e.name}`,this.nodes=new so(r,this.switches,this.events);const i=this.processNode=uo(this,s=>{const o=Array.from(s.keys());process.env.NODE_ENV!=="production"&&console.info(`STATE PROCESSOR: ${o.length} node(s) processed:
|
|
2
2
|
${o.map(a=>`${a.name||"<no name>"} (${a.id})
|
|
3
3
|
`)}`),o.forEach(a=>{const l=s.get(a);a.parent&&a.parent.type==="root"&&this.events.dispatch("components:root-children-changed",{node:a}),l!=null&&l.context&&this.events.dispatch("components:context-changed",{node:a}),l!=null&&l.properties&&this.events.dispatch("components:properties-changed",{node:a}),l!=null&&l.layout&&this.events.dispatch("components:layout-changed",{node:a})}),this.events.dispatch("components:component-model-initialized",{},{bubbles:!0})});Promise.all(Object.keys(n).map(s=>n[s].load(this))),this.subscriptions.push(this.events.subscribe("components:node-appended",(s,o)=>{const{node:a}=o;this.changesets.forEach(l=>{const{changeset:u,target:c,removes:d}=l,[f,p]=u;c.match(o.node)&&(f.properties&&d.push(a.writeProperties(f.properties,p)),f.context&&d.push(a.writeContext(f.context,p)),f.layout&&d.push(a.writeLayout(f.layout,p)))})})),this.subscriptions.push(this.events.subscribe("components:node-appended",(s,o)=>{i(o.node,{properties:!0,context:!0})})),this.subscriptions.push(this.events.subscribe("components:set-properties",(s,o)=>{i(o.node,{properties:!0})})),this.subscriptions.push(this.events.subscribe("components:set-context",(s,o)=>{i(o.node,{properties:!0,context:!0})})),this.subscriptions.push(this.events.subscribe("components:set-indent",(s,o)=>{i(o.node,{layout:!0})})),this.subscriptions.push(this.events.subscribe("components:set-layout",(s,o)=>{i(o.node,{layout:!0})})),this.subscriptions.push(this.events.subscribe("components:node-switched",(s,{node:o,branch:a})=>{i(o,{layout:!0,recursive:!0,properties:!0,context:!0})})),this.subscriptions.push(this.events.subscribe("components:node-removed",(s,{parentNode:o})=>{i(o,{properties:!0})})),this.events.parent&&this.events.parent.dispatch("components:platform-created",{platform:this})}static getInstance(e){return e.getAsync("components")}addBreakpoint(e){this.breakpoints.indexOf(e)===-1&&(this.breakpoints.push(e),this.processNode(this.nodes.root,{context:!0,properties:!0,layout:!0,recursive:!0}))}removeBreakpoint(e){const n=this.breakpoints.indexOf(e);n>-1&&(this.breakpoints.splice(n,1),this.processNode(this.nodes.root,{context:!0,properties:!0,layout:!0,recursive:!0}))}setSwitch(e,n){this.switches[e.id]=n,this.events.dispatch("components:node-switched",{node:e,branch:n})}getBranch(e){return this.switches[e.id]}createNode(e,n={}){const r=new Ar(this.events,e);return n.detached&&this.nodes.detached.push(r),r}components(){return new Mi(this)}actions(e,n){return new qn(this,e,n)}write(e){const{provider:n,target:r,attributes:i,options:s={},removable:o}=e,a=e.key||Xe(),u={changeset:[i,s],target:r,removes:[]};if(n){const c=this.providers[n];c.write(a,r,i,s),u.removes.push(()=>{c.remove(a)})}return this.changesets.push(u),this.nodes.all.forEach(c=>{if(r.match(c)){let d=()=>{};i.properties&&(d=c.writeProperties(i.properties,s,o)),i.context&&(d=c.writeContext(i.context,s,o)),i.layout&&(d=c.writeContext(i.layout,s,o)),u.removes.push(d)}}),()=>{if(o){u.removes.forEach(d=>d());const c=this.changesets.indexOf(u);c>-1&&this.changesets.splice(c,1)}}}addComponentHandler(e,n){this.customComponentHandler.add(e,n)}getComponentHandler(e){return this.customComponentHandler.get(e)}dispose(){this.subscriptions.forEach(e=>e())}}var zi=(t=>(t.open="open",t.closed="closed",t.hidden="hidden",t))(zi||{}),pe=(t=>(t.Cookie="cookie",t.Local="local",t.Session="session",t))(pe||{}),Ut=(t=>(t.Tenant="tenant",t.Implementation="implementation",t.Widget="widget",t))(Ut||{}),he=(t=>(t.Necessary="necessary",t.Functional="functional",t.Analytical="analytical",t.Marketing="marketing",t))(he||{});const pt=(t,e,n,r={})=>_r(t,n).then(i=>(process.env.NODE_ENV!=="production"&&i&&se.warn(`createStorageWriter: Attempted to create storage writer using unallowed category.
|
|
4
4
|
Key: ${e}
|
|
@@ -38,7 +38,7 @@ You should wrap it with \`css\` like this:
|
|
|
38
38
|
Because you write your CSS inside a JavaScript string you actually have to do double escaping, so for example "content: '\\00d7';" should become "content: '\\\\00d7';".
|
|
39
39
|
You can read more about this here:
|
|
40
40
|
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#ES2018_revision_of_illegal_escape_sequences`,Ka=function(e){var n=e.cache,r=e.serialized,i=e.isStringTag;return Gt(n,r,i),sr(function(){return Jt(n,r,i)}),null},Ga=function t(e,n){if(process.env.NODE_ENV!=="production"&&e===void 0)throw new Error(`You are trying to create a styled element with an undefined component.
|
|
41
|
-
You may have forgotten to import it.`);var r=e.__emotion_real===e,i=r&&e.__emotion_base||e,s,o;n!==void 0&&(s=n.label,o=n.target);var a=ei(e,n,r),l=a||Qr(i),u=!l("as");return function(){var c=arguments,d=r&&e.__emotion_styles!==void 0?e.__emotion_styles.slice(0):[];if(s!==void 0&&d.push("label:"+s+";"),c[0]==null||c[0].raw===void 0)d.push.apply(d,c);else{process.env.NODE_ENV!=="production"&&c[0][0]===void 0&&console.error(ti),d.push(c[0][0]);for(var f=c.length,p=1;p<f;p++)process.env.NODE_ENV!=="production"&&c[0][p]===void 0&&console.error(ti),d.push(c[p],c[0][p])}var g=Xt(function(v,b,$){var P=u&&v.as||i,k="",S=[],y=v;if(v.theme==null){y={};for(var L in v)y[L]=v[L];y.theme=oe.useContext(vt)}typeof v.className=="string"?k=rr(b.registered,S,v.className):v.className!=null&&(k=v.className+" ");var T=Ze(d.concat(S),b.registered,y);k+=b.key+"-"+T.name,o!==void 0&&(k+=" "+o);var A=u&&a===void 0?Qr(P):l,H={};for(var B in v)u&&B==="as"||A(B)&&(H[B]=v[B]);return H.className=k,H.ref=$,oe.createElement(oe.Fragment,null,oe.createElement(Ka,{cache:b,serialized:T,isStringTag:typeof P=="string"}),oe.createElement(P,H))});return g.displayName=s!==void 0?s:"Styled("+(typeof i=="string"?i:i.displayName||i.name||"Component")+")",g.defaultProps=e.defaultProps,g.__emotion_real=g,g.__emotion_base=i,g.__emotion_styles=d,g.__emotion_forwardProp=a,Object.defineProperty(g,"toString",{value:function(){return o===void 0&&process.env.NODE_ENV!=="production"?"NO_COMPONENT_SELECTOR":"."+o}}),g.withComponent=function(v,b){return t(v,ue({},n,b,{shouldForwardProp:ei(g,b,!0)})).apply(void 0,d)},g}},Ja=["a","abbr","address","area","article","aside","audio","b","base","bdi","bdo","big","blockquote","body","br","button","canvas","caption","cite","code","col","colgroup","data","datalist","dd","del","details","dfn","dialog","div","dl","dt","em","embed","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","iframe","img","input","ins","kbd","keygen","label","legend","li","link","main","map","mark","marquee","menu","menuitem","meta","meter","nav","noscript","object","ol","optgroup","option","output","p","param","picture","pre","progress","q","rp","rt","ruby","s","samp","script","section","select","small","source","span","strong","style","sub","summary","sup","table","tbody","td","textarea","tfoot","th","thead","time","title","tr","track","u","ul","var","video","wbr","circle","clipPath","defs","ellipse","foreignObject","g","image","line","linearGradient","mask","path","pattern","polygon","polyline","radialGradient","rect","stop","svg","text","tspan"],R=Ga.bind();Ja.forEach(function(t){R[t]=R(t)});var jn=(t=>(t.Opera="opera",t.Chrome="chrome",t.Firefox="firefox",t.Safari="safari",t.Edge="edge",t.EdgeChromium="edge-chromium",t.Blink="blink",t.IE="internet-explorer",t))(jn||{});const ni=()=>{const{opr:t,opera:e,InstallTrigger:n,HTMLElement:r,safari:i,documentMode:s,StyleMedia:o,chrome:a,CSS:l}=window,u=!!t&&!!t.addons||!!e||navigator.userAgent.indexOf(" OPR/")>=0;if(u)return"opera";if(n)return"firefox";const c=(p=>p.toString()==="[object SafariRemoteNotification]")(!i||typeof i<"u"&&i.pushNotification);if(/constructor/i.test(r)||c)return"safari";const d=!!s;if(d)return"internet-explorer";if(!d&&o)return"edge";const f=!!a&&(!!a.webstore||!!a.runtime);if(f)return"chrome";if(f&&navigator.userAgent.indexOf("Edg")!==-1)return"edge-chromium";if((f||u)&&l)return"blink"},Xa=["string","number"],Se=t=>Object.keys(t).reduce((e,n)=>{const r=typeof t[n]>"u"?"":t[n],i=typeof r;if(Xa.indexOf(i)>-1){const s=n.substring(0,5);s==="data-"||s==="aria-"?e[
|
|
41
|
+
You may have forgotten to import it.`);var r=e.__emotion_real===e,i=r&&e.__emotion_base||e,s,o;n!==void 0&&(s=n.label,o=n.target);var a=ei(e,n,r),l=a||Qr(i),u=!l("as");return function(){var c=arguments,d=r&&e.__emotion_styles!==void 0?e.__emotion_styles.slice(0):[];if(s!==void 0&&d.push("label:"+s+";"),c[0]==null||c[0].raw===void 0)d.push.apply(d,c);else{process.env.NODE_ENV!=="production"&&c[0][0]===void 0&&console.error(ti),d.push(c[0][0]);for(var f=c.length,p=1;p<f;p++)process.env.NODE_ENV!=="production"&&c[0][p]===void 0&&console.error(ti),d.push(c[p],c[0][p])}var g=Xt(function(v,b,$){var P=u&&v.as||i,k="",S=[],y=v;if(v.theme==null){y={};for(var L in v)y[L]=v[L];y.theme=oe.useContext(vt)}typeof v.className=="string"?k=rr(b.registered,S,v.className):v.className!=null&&(k=v.className+" ");var T=Ze(d.concat(S),b.registered,y);k+=b.key+"-"+T.name,o!==void 0&&(k+=" "+o);var A=u&&a===void 0?Qr(P):l,H={};for(var B in v)u&&B==="as"||A(B)&&(H[B]=v[B]);return H.className=k,H.ref=$,oe.createElement(oe.Fragment,null,oe.createElement(Ka,{cache:b,serialized:T,isStringTag:typeof P=="string"}),oe.createElement(P,H))});return g.displayName=s!==void 0?s:"Styled("+(typeof i=="string"?i:i.displayName||i.name||"Component")+")",g.defaultProps=e.defaultProps,g.__emotion_real=g,g.__emotion_base=i,g.__emotion_styles=d,g.__emotion_forwardProp=a,Object.defineProperty(g,"toString",{value:function(){return o===void 0&&process.env.NODE_ENV!=="production"?"NO_COMPONENT_SELECTOR":"."+o}}),g.withComponent=function(v,b){return t(v,ue({},n,b,{shouldForwardProp:ei(g,b,!0)})).apply(void 0,d)},g}},Ja=["a","abbr","address","area","article","aside","audio","b","base","bdi","bdo","big","blockquote","body","br","button","canvas","caption","cite","code","col","colgroup","data","datalist","dd","del","details","dfn","dialog","div","dl","dt","em","embed","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","iframe","img","input","ins","kbd","keygen","label","legend","li","link","main","map","mark","marquee","menu","menuitem","meta","meter","nav","noscript","object","ol","optgroup","option","output","p","param","picture","pre","progress","q","rp","rt","ruby","s","samp","script","section","select","small","source","span","strong","style","sub","summary","sup","table","tbody","td","textarea","tfoot","th","thead","time","title","tr","track","u","ul","var","video","wbr","circle","clipPath","defs","ellipse","foreignObject","g","image","line","linearGradient","mask","path","pattern","polygon","polyline","radialGradient","rect","stop","svg","text","tspan"],R=Ga.bind();Ja.forEach(function(t){R[t]=R(t)});var jn=(t=>(t.Opera="opera",t.Chrome="chrome",t.Firefox="firefox",t.Safari="safari",t.Edge="edge",t.EdgeChromium="edge-chromium",t.Blink="blink",t.IE="internet-explorer",t))(jn||{});const ni=()=>{const{opr:t,opera:e,InstallTrigger:n,HTMLElement:r,safari:i,documentMode:s,StyleMedia:o,chrome:a,CSS:l}=window,u=!!t&&!!t.addons||!!e||navigator.userAgent.indexOf(" OPR/")>=0;if(u)return"opera";if(n)return"firefox";const c=(p=>p.toString()==="[object SafariRemoteNotification]")(!i||typeof i<"u"&&i.pushNotification);if(/constructor/i.test(r)||c)return"safari";const d=!!s;if(d)return"internet-explorer";if(!d&&o)return"edge";const f=!!a&&(!!a.webstore||!!a.runtime);if(f)return"chrome";if(f&&navigator.userAgent.indexOf("Edg")!==-1)return"edge-chromium";if((f||u)&&l)return"blink"},Xa=["string","number"],Se=t=>Object.keys(t).reduce((e,n)=>{const r=typeof t[n]>"u"?"":t[n],i=typeof r;if(Xa.indexOf(i)>-1){const s=n.substring(0,5);s==="data-"||s==="aria-"?e[no(n)]=r.toString():n.substring(0,4)!=="css-"&&(e[n]=r.toString())}else e[n]=r;return e},{}),Qa=t=>new RegExp("^#","i").test(t),ec=t=>({children:e,...n})=>{const{implementation:r,name:i}=t.get("$widget"),{href:s=""}=n;if(Qa(s))return h.jsx(ac,{smooth:!0,to:s,children:e});const o=r.bindings.map(u=>u.replace(/\./g,"\\.")).join("|"),l=new RegExp(`^((http[s]?:)?//)?(${o})/([^\\s]+)`).exec(s);if(l&&l.length>=4){const u=l[4];if(r.widgets.get(u)&&!u.startsWith("blob?")&&!u.startsWith(i))return h.jsx(wu,{widgetName:u,children:e})}return h.jsx("a",{...n,children:e})},ls=t=>{const e={};return Object.keys(t).forEach(n=>{n.indexOf("css-")>-1&&(e[n]=t[n])}),e},tc=t=>{let e="";return Object.keys(ls(t)).forEach(n=>{n.indexOf("css-")>-1&&(e+=`${n.replace("css-","")}:${t[n]};`)}),re`
|
|
42
42
|
${e}
|
|
43
43
|
`},nc=(t,e)=>{let n="";const r=()=>{n=""},i=c=>{const d=document.getElementById(n);return d!==null?(c(d),r(),!0):!1},s=c=>(c.preventDefault(),r(),t.onClick&&t.onClick(c),typeof t.to=="string"&&(n=t.to.split("#").slice(1).join("#")),n!==""&&i(t.scroll||(d=>t.smooth?d.scrollIntoView({behavior:"smooth"}):d.scrollIntoView())),!1),{scroll:o,smooth:a,to:l,...u}=t;return e==="a"&&(u.href="javascript:;"),h.jsx(e,{...u,onClick:s,children:t.children})},ar=t=>(e,n)=>{let r=e,i="";if(["h1","h2","h3","h4","h5","h6"].includes(e))r=e;else{const a=e.match(/h1|h2|h3|h4|h5|h6/);if(a!=null&&a[0]){r=a[0];const[l]=e.split(r);i=l}}const o=((a,l,u)=>u[a]?`${l}${u[a]}`:`${l}${a}`)(r,i,t.theme.typographyVariantMapping||{});return re`
|
|
44
44
|
${o} {
|
|
@@ -1092,4 +1092,4 @@ Valid keys: `+JSON.stringify(Object.keys(x),null," "));var _=me(M,U,j,I,D+"."+U
|
|
|
1092
1092
|
min-width: 100px;
|
|
1093
1093
|
`;class Du{constructor(e){O(this,"cache",new Map);O(this,"subscriptions",[]);this.controller=e;const{events:n}=e.container.get("$widget"),r=n.subscribe("data-client:fetched",(i,s)=>{s.type==="contact-method"&&this.cache.set(s.response.id,s.response)});this.subscriptions.push(r)}getConversationLogs(){return this.controller.messages.reduce((n,r)=>{const i=nn(r),{key:s,content:o,type:a,sender:l,timestamp:u}=i.content,c=this.parseEntry(o,a,l,u);return c&&n.push(c),n},[])}parseEntry(e,n,r,i){const s=u=>{let c=[],d=[],f;if(Array.isArray(u)){const[g,v]=u;f=v}else f=u;return this.createMessageContent(f).length&&(d=[...d,this.createMessageContent(f)]),c=[...c,...this.createMessageOptions(f)],{messagesAsList:d,options:c}};let o=[],a=[];if(Array.isArray(e.items)){const{items:u}=e;u.forEach(c=>{const d=s(c);o=[...o,...d.options],a=[...a,...d.messagesAsList]})}else{const u=s(e);o=[...o,...u.options],a=[...a,...u.messagesAsList]}return{options:o,message:a.length?a.join(`
|
|
1094
1094
|
`):void 0,source:this.createMessageSource(n),alias:this.createAlias(n,r),timestamp:i}}createMessageSource(e){return e}createAlias(e,n){return e===tn.System?"system":(n==null?void 0:n.name)||"Me"}handleContactMethod(e){if(!this.cache.has(e))return;const n=this.cache.get(e);let r="";return r=this.appendText(r,`${n.clientName}:`),r=this.appendText(r,n.title),n.description&&(r=this.appendText(r,n.title)),r}getDetails(e,n=!0){if(!e)return"";const{header:r,title:i,label:s,description:o,text:a,html:l,body:u,contactMethodId:c}=e;let d="";if(c){const f=this.handleContactMethod(c.toString());f&&(d=this.appendText(d,f,n))}return r&&(d=this.appendText(d,r,n)),i&&(d=this.appendText(d,i,n)),o&&(d=this.appendText(d,o,n)),a&&(d=this.appendText(d,a,n)),s&&(d=this.appendText(d,s,n)),l&&(d=this.appendText(d,l,n)),u&&typeof u=="string"&&(d=this.appendText(d,u,n)),d}createMessageContent(e){let n="";return n=this.getDetails(e),n}createMessageOptions(e){let n=[],r=[];return Array.isArray(e==null?void 0:e.actions)?r=e.actions:typeof(e==null?void 0:e.actions)=="object"&&(r=Object.entries(e.actions).map(([i,s])=>({actionKey:i,label:s}))),r.length&&(n=r.map(i=>this.getDetails(i,!1))),n}appendText(e,n,r=!0){return r&&e.length?`${e}
|
|
1095
|
-
${n}`:e.length?`${e} ${n}`:n}dispose(){this.subscriptions.forEach(e=>{e()})}}class zn{constructor(e,n){O(this,"id");O(this,"name");O(this,"avatar");O(this,"print",(e,n)=>{const r={name:this.name,avatar:this.avatar,id:this.id},i=nn(e,n);return this.provider.createEntry(i.key,i.content,tn.Agent,r,i.timestamp)});O(this,"typing",()=>this.provider.setTypingState({name:this.name,avatar:this.avatar}));this.provider=e,this.id=n.id||Xe(),this.name=n.name,this.avatar=n.avatar}update(e){var i;const{name:n,avatar:r}=e;r===null?this.avatar=void 0:r&&(this.avatar=r),n===null?this.name=void 0:n&&(this.name=n),(i=this.provider.controller)==null||i.events.dispatch("conversation:agent-updated",{agent:this})}}class Nr{constructor(e,n,r){O(this,"subscriptions",[]);O(this,"options");O(this,"user");this.name=e,this.container=n,this.controller=r,this.user=r==null?void 0:r.user,this.options={silent:!1}}static create(e,n,r){return new Nr(e,n,r)}createAgent(e={}){var n;if(this.controller){const r=this.controller.getAgentById(e.id),i=r?new zn(this,{...r,...e}):new zn(this,e);return r||(n=this.controller)==null||n.events.dispatch("conversation:agent-created",{agent:i}),i}}print(e){var n;return(n=this.controller)==null?void 0:n.print(e)}setTypingState(e,n){var r;return(r=this.controller)==null?void 0:r.setTypingState(e,n)}loading(){return this.controller?this.controller.loader():()=>()=>{}}createEntry(e,n,r,i,s){var o;return(o=this.controller)==null?void 0:o.createEntry(e,n,r,i,s)}dispose(){var e;process.env.NODE_ENV!=="production"&&console.log(`conversation-provider: dispose (${this.name})`),(e=this.controller)==null||e.disposeProvider(this),this.controller=null,this.subscriptions.forEach(n=>n())}isRehydrated(){var e;return((e=this.controller)==null?void 0:e.isRehydrated())||Promise.resolve(!1)}getHistory(){var e;return((e=this.controller)==null?void 0:e.getHistory())||[]}complete(){var e;(e=this.controller)==null||e.onCompleteProvider()}setOptions(e={silent:!1}){this.options=e}onUnreadMessage(e){var n;if(this.controller){const r=(n=this.controller)==null?void 0:n.onUnreadMessage(e);return this.subscriptions.push(r),()=>{r()}}}onMounted(e){var n;if(this.controller){const r=(n=this.controller)==null?void 0:n.events.subscribe("conversation:component-mount-changed",e);return this.subscriptions.push(r),e({},this.controller.getComponentMountedState()),()=>{r()}}}}const Hs=t=>`conversation-${t}`;class Mu{constructor(){O(this,"_locking",Promise.resolve());O(this,"_locks",0)}isLocked(){return this._locks>0}lock(){this._locks+=1;let e;const n=new Promise(i=>e=()=>{this._locks-=1,i()}),r=this._locking.then(()=>e);return this._locking=this._locking.then(()=>n),r}}class Iu{constructor(e,n,r){O(this,"sessionStorageKey");O(this,"locker",new Mu);O(this,"initialStoredAgents",[]);this.container=e,this.conversation=n,this.enabled=r,this.sessionStorageKey=Hs(n.id),n.onStarted(async()=>{if(n.messages.length>0)return;const{agents:i}=await this.read(),s=[];i&&i.forEach(a=>{const l=n.providerIndex(a.providerName),u=l>-1?n.registeredProviders[l]:n.createProvider(a.providerName),c=new zn(u,{name:a.name,avatar:a.avatar,id:a.id});s.push(c)});const{messages:o}=await this.read();o.forEach(a=>{switch(a.type){case"agent":{const l=s.find(u=>{var c;return u.id===((c=a.sender)==null?void 0:c.id)});l&&l.print(a.content.items||a.content,{key:a.key});return}case"user":{n.user.print(a.content.items||a.content,{key:a.key});return}case"system":default:n.print(a.content.items||a.content)}})}),n.onMessageCreated(async(i,s)=>{this.write(s.message,"messages")}),n.events.subscribe("conversation:agent-created",async(i,s)=>{const o={id:s.agent.id,name:s.agent.name,avatar:s.agent.avatar,providerName:s.agent.provider.name};await this.write(o,"agents")}),n.events.subscribe("conversation:agent-updated",async(i,s)=>{const{agents:o}=await this.read();await this.write([...o.map(a=>a.id===s.agent.id?{...a,name:s.agent.name,avatar:s.agent.avatar}:a)],"agents","update")})}setInitialData(e){this.initialStoredAgents=e.agents}async isRehydrated(){const{messages:e}=await this.read();return e.length>0}getStoredAgent(e){if(this.enabled)return this.initialStoredAgents.find(n=>n.id===e)}async write(e,n,r="add"){if(!this.enabled)return;const i=await this.locker.lock();return pt(this.container,this.sessionStorageKey,he.Necessary).then(async s=>{if(r==="add"){const o=await this.read();if(n==="messages"&&o.messages.findIndex(l=>l.key===e.key)>-1){i();return}const a={...o};return n==="messages"?a.messages=[...a.messages,e]:n==="agents"&&(a.agents=[...a.agents,e]),s({...o,...a}).then(()=>{i()})}if(r==="update"&&n==="agents"){const o=await this.read();return s({...o,agents:e}).then(()=>{i()})}return s(e).then(()=>{i()})})}async read(){return je(this.container,this.sessionStorageKey).then(e=>e||{messages:[],agents:[]})}}class Vu{constructor(e){O(this,"print",(e,n)=>{const r=nn(e,n);return this.controller.createEntry(r.key,r.content,tn.User,void 0,r.timestamp)});this.controller=e}}const Bn=async(t,e,n)=>{const r=await t.getAsync("conversation"),i=await t.getAsync("components"),s=r.controllers.find(o=>o.conversation.id===e);if(s){const o=[...s.conversation.providers];o.forEach(l=>{s.conversation.setProviderOptions(l,{silent:!0})}),s.conversation.queueProviders(o),s.conversation.setProviders([n]);const a=i.components().ofType("conversation");i.write({key:"setConversationProvider",attributes:{properties:{providers:[n]}},target:a,provider:"localStorage"})}};class Hu{constructor(e){this.writer=e}update(e){const n=this.getNormalizedSettings(e);this.writer(n)}remove(){this.writer(null)}getNormalizedSettings(e){return typeof e=="string"?{body:e}:e.length>-1&&typeof e=="object"?{items:e}:e}}var tn=(t=>(t.User="user",t.Agent="agent",t.System="system",t))(tn||{});const nn=(t,e)=>{let n,r=(e==null?void 0:e.key)||Xe(),i=Date.now();if(Array.isArray(t)&&t.length>-1)typeof t[0]=="string"?n={items:[t]}:n={items:t};else if(typeof t=="string")n={body:t};else if(t=t||{},t.type)n={...t};else{if(n={body:t.body,actions:t.actions,title:t.title},t.key&&(r=t.key),t.timestamp&&(i=t.timestamp),typeof t.form=="function"){const s=Me.create(r);t.form(s);const o=s.get();n.form=o}t.timestamp===null&&(i=null)}return{content:n,key:r,timestamp:i}},Ai=(t,e)=>{if(!e)return;const n=JSON.stringify(e),r=t.findIndex(i=>n===JSON.stringify(i));if(r>-1)return t.splice(r,1)};class zu{constructor(e,n,r){O(this,"formHandlers",{});O(this,"user",new Vu(this));O(this,"events");O(this,"providers",[]);O(this,"active",!1);O(this,"queuedProviders",[]);O(this,"registeredProviders",[]);O(this,"loaders",0);O(this,"componentMounted",!1);O(this,"store");O(this,"messages",[]);O(this,"typingActors",[]);O(this,"conversationHistory");O(this,"print",e=>{const n=nn(e);return this.createEntry(n.key,n.content,"system",void 0,n.timestamp)});this.container=e,this.id=n;const i=e.get("$widget");this.events=i.events.createChild(this),this.store=new Iu(e,this,r.rehydrate),this.conversationHistory=new Du(this)}setInitialStorage(e){this.store.setInitialData(e)}setProviders(e){const n=[],r=[];this.providers.reduce((i,s)=>(e.indexOf(s)===-1&&i.push(s),i),[]).forEach(i=>{const s=this.providers.indexOf(i);s>-1&&(n.push(i),this.providers.splice(s,1))}),e.forEach(i=>{this.providers.indexOf(i)===-1&&(r.push(i),this.providers.push(i))}),(r.length||n.length)&&this.events.dispatch("conversation:providers-changed",{added:r,removed:n})}createProvider(e){const n=this.providerIndex(e);if(n>-1)return this.registeredProviders[n];const r=Nr.create(e,this.container,this);return this.registeredProviders.push(r),r}providerIndex(e){return this.registeredProviders.findIndex(n=>n.name===e)}getAgentById(e){if(e)return this.store.getStoredAgent(e)}dispose(){this.conversationHistory.dispose(),this.registeredProviders.forEach(e=>e.dispose()),this.messages=[],this.events.dispatch("conversation:controller-disposed",this),this.active=!1}onDispose(e){return this.events.subscribe("conversation:controller-disposed",e)}onStarted(e){return this.events.subscribe("conversation:started",e)}onMessageCreated(e){return this.events.subscribe("conversation:message-created",e)}isRehydrated(){return this.store.isRehydrated()}disposeProvider(e){const n=this.providerIndex(e.name);n>-1&&this.registeredProviders.splice(n,1),this.events.dispatch("conversation:providers-changed",{removed:[e.name]}),this.registeredProviders.length||this.dispose()}onProvidersChange(e){return this.events.subscribe("conversation:providers-changed",e)}setComponentMountedState(e){this.componentMounted!==e&&(this.componentMounted=e,e&&(this.events.dispatch("conversation:unread-message",!1),this.events.dispatch("conversation:started",!0),this.active=!0),this.events.dispatch("conversation:component-mount-changed",e))}setProviderOptions(e,n){const r=this.providerIndex(e);r>-1&&this.registeredProviders[r].setOptions(n)}changeProvider(e){this.registeredProviders.find(r=>r.name===e)&&Bn(this.container,this.id,e)}queueProviders(e){this.queuedProviders=e}onCompleteProvider(){const e=this.queuedProviders.pop();e&&Bn(this.container,this.id,e)}getComponentMountedState(){return this.componentMounted}onUnreadMessage(e){return this.events.subscribe("conversation:unread-message",e)}createEntry(e,n,r,i,s){const o={key:e,content:n,type:r,sender:i||null,timestamp:s||s===null?s:Date.now()};this.messages.push(o),o.type==="agent"&&Ai(this.typingActors,i);const a=new Hu(l=>{if(l!==null){const{timestamp:u=void 0,...c}=l;o.content=c,u&&(o.timestamp=u)}else{const u=this.messages.indexOf(o);o.content=null,u>-1&&this.messages.splice(u,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(e,n){return this.typingActors.indexOf(e)===-1&&(this.typingActors.push(e),this.update()),()=>{Ai(this.typingActors,e),this.update()}}loader(){this.loaders=this.loaders+1;let e=!1;return this.loaders===1&&this.update(),()=>{e||(e=!0,this.loaders=this.loaders-1,this.loaders===0&&this.update())}}submitForm(e,n){this.formHandlers[e]={...this.formHandlers[e],submit:n}}validateForm(e,n){this.formHandlers[e]={...this.formHandlers[e],validate:n}}getHistory(){return this.conversationHistory.getConversationLogs()}}const _i=t=>{const{implementation:e}=t.get("$widget"),r=(e.container.get("modals")||[]).map(i=>i.close());return Promise.all(r)},Bu=(t,e)=>{const n=t.split("_contact");return e.widgets.get(n[0])},$r=t=>{const e=t.get("$widget"),{name:n,implementation:r}=t.get("$widget"),i=n.indexOf("_contact")>-1?Bu(n,r):e,{data:s}=t.get("$settings"),{trigger:o}=i.container.get("$settings"),a=`${n.replace("_contact-method","").replace("_contact","")}_contact-method`,l=r.widgets.get(a);return l&&!o?{chatWidget:l,mainWidget:i,data:s}:{mainWidget:i,data:s}},Wu=t=>{const{chatWidget:e}=$r(t);return!!e},Li=(t,e,n)=>{const{mainWidget:r,data:i,chatWidget:s}=$r(t);return s?s.state==="activated"?s.invoke("open").then(()=>{s.container.getAsync("conversation").then(o=>{o.navigateToConversationIfActive(e.id).then(()=>_i(t))})}):s.activate().then(()=>{const{trigger:o}=s.container.get("$settings");return o.action="hide",s.invoke("setSettings",()=>({data:i,trigger:o,activate:!0})).then(()=>s.container.getAsync("components").then(a=>{const l=a.components().ofType("contact-method");a.write({key:"setContactMethodId",attributes:{properties:{id:e.id,guideId:e.guideId}},target:l,provider:"localStorage"});const u=a.components().ofType("conversation");a.write({key:"setConversationProvider",attributes:{properties:{providers:[e.clientName]}},target:u,provider:"localStorage"})}))}).then(()=>s.invoke("attach",{key:"contact-method",triggerDOMElement:n,withRenderState:"open"})).then(()=>(pt(s.container,"activeStickyWidget",he.Necessary,{medium:pe.Local,scope:Ut.Implementation}).then(o=>o(s.name)),s.container.getAsync("conversation").then(o=>{o.setConversationEndedBehavior(Bt.Deactivate)}).then(()=>_i(t)).then(()=>!1))):(r.container.getAsync("conversation").then(o=>o.navigateToConversationIfActive(e.id).then(()=>o.setConversationEndedBehavior(Bt.Navigate))),!s)},Uu=(t,e,n="conversation")=>{const{mainWidget:r,chatWidget:i}=$r(t);return i?i.container.getAsync("router").then(s=>{s.navigate(n,{id:e.id})}):r.container.getAsync("conversation").then(s=>{var o;(o=s.setConversationEndedBehavior(Bt.Navigate))==null||o.then(()=>{r.container.getAsync("router").then(a=>{r.container.getAsync("components").then(l=>{const u=l.components().ofType("conversation");l.write({key:"setConversationProvider",attributes:{properties:{providers:[e.clientName]}},target:u,provider:"localStorage"})}).then(()=>{a.navigate(n,{id:e.id})})})})})},st="conversations";var Bt=(t=>(t.Deactivate="deactivate",t.Navigate="navigate",t.None="none",t))(Bt||{});class Tr{constructor(e,n){O(this,"events");O(this,"controllers",[]);O(this,"providers",[]);O(this,"disposeProviders",{});O(this,"subscriptions",[]);O(this,"storageWriter",null);O(this,"router",null);O(this,"buttonQuery",null);O(this,"sessionInfo",null);this.container=e,this.components=n;const r=e.get("$widget");this.events=r.events.createChild(this)}initialize(){pt(this.container,st,he.Necessary,{medium:pe.Local}).then(e=>this.storageWriter=e),je(this.container,st,pe.Local).then(e=>{this.buttonQuery=this.components.components().ofType("conversation-return-button"),e&&(this.sessionInfo=e,e.id&&e.route&&this.writeToComponents({active:!0,alert:{show:!1}}))}),this.container.getAsync("router").then(e=>this.router=e),this.events.subscribe("conversation:ended",(e,n)=>{var r,i,s;switch((r=this.sessionInfo)==null?void 0:r.conversationEndedBehavior){case"deactivate":this.container.get("$widget").deactivate();break;case"navigate":const a=(i=this.router)==null?void 0:i.getInitialRoute();a&&((s=this.router)==null||s.navigate(a.name));break}this.writeToComponents({active:!1}),this.sessionInfo=null,this.storageWriter&&this.storageWriter()})}addSubscription(e){this.subscriptions.push(e)}static getInstance(e,n="conversation"){return ht(e)(()=>e.getAsync(n).then(r=>{let i=r;return i||Hi.getInstance(e).then(s=>(i=new Tr(e,s),i.initialize(),e.registerAsync(n,()=>i),i))}))}navigateToConversationIfActive(e){return je(this.container,st,pe.Local).then(n=>{var r;if(n&&n.id===e&&n.route){const{name:i,params:s}=n.route;(r=this.router)==null||r.navigate(i,s)}})}setConversationEndedBehavior(e){return je(this.container,st,pe.Local).then(n=>{let r=n;return r?r.conversationEndedBehavior=e:r={conversationEndedBehavior:e},this.sessionInfo=r,this.storageWriter&&this.storageWriter(this.sessionInfo)||Promise.resolve()})}async createController(e,n){const r=Hs(e),{agents:i}=await je(this.container,r)||{agents:[]},s=this.controllers.findIndex(a=>a.conversation.id===e);let o;return s>-1?o=this.controllers[s].conversation:o=new zu(this.container,e,n),o.setInitialStorage({agents:i||[]}),o}registerProvider(e,n){const r={name:e,handler:n};this.providers.push(r),this.controllers.filter(i=>i.conversation.providers.indexOf(e)>-1).forEach(i=>{this.invokeHandler(r,i)})}registerController(e,n){const r=this.controllers.findIndex(s=>s.conversation.id===e.id);let i;if(r<0){i={conversation:e,component:n},this.controllers.push(i);const s=o=>{o&&this.providers.filter(a=>o.indexOf(a.name)>-1).forEach(a=>{this.invokeHandler(a,i)})};return this.subscriptions.push(e.onDispose((o,a)=>{const l=this.controllers.findIndex(u=>u.conversation===a);l>-1&&this.controllers.splice(l,1),this.components.components().ofType("conversation-return-button").select().writeProperties({active:!1}),this.events.dispatch("conversation:ended",{},{bubbles:!0})})),this.subscriptions.push(e.onProvidersChange((o,a)=>{const{added:l,removed:u=[]}=a;u.forEach(c=>{(this.disposeProviders[c]||[]).forEach(d=>{d()})}),s(l)})),this.subscriptions.push(e.onStarted((o,a)=>{var u,c;const l={id:e.id,route:(u=this.router)==null?void 0:u.getRouteData(),conversationEndedBehavior:(c=this.sessionInfo)==null?void 0:c.conversationEndedBehavior};this.sessionInfo=l,this.storageWriter&&this.storageWriter(l),this.writeToComponents({active:a})})),this.subscriptions.push(e.onUnreadMessage((o,a)=>{this.events.dispatch("conversation:unread-message",a),this.writeToComponents({alert:{show:a}})})),s(e.providers),!0}return i=this.controllers[r],!1}writeToComponents(e,n="conversationReturnButtonState"){this.buttonQuery&&this.components.write({key:"conversationReturnButtonState",attributes:{properties:e},target:this.buttonQuery,provider:"localStorage"})}invokeHandler(e,n){const r=e.handler(n.conversation.createProvider(e.name),n.component);r&&(this.disposeProviders[e.name]||(this.disposeProviders[e.name]=[]),this.disposeProviders[e.name].push(r))}getComponentRoute(){return je(this.container,st,pe.Local).then(e=>e==null?void 0:e.route)}dispose(){Object.keys(this.disposeProviders).forEach(e=>{this.disposeProviders[e].forEach(n=>{n()})}),this.subscriptions.forEach(e=>{e()}),this.controllers=[],this.providers=[]}static async handleContactMethodClick(e,n,r,i){if(Wu(n)){e.preventDefault();let s=document.getElementById("humany-dynamic-anchor");s||(s=document.createElement("a"),s.setAttribute("href","#"),s.id="humany-dynamic-anchor",document.body.appendChild(s)),Li(n,r,s)}Li(n,r)}static async handleContactMethodSubmit(e,n){var r,i;return(i=(r=n==null?void 0:n.body.form.meta)==null?void 0:r.conversation)!=null&&i.id?Bn(e,n.body.form.meta.conversation.id,n.clientName):Uu(e,n)}}const Fu="@telia-ace/conversational-hub-bot-provider",qu="0.0.7",Yu="./index.js",Zu="./index.d.ts",Ku={".":{import:"./index.mjs",require:"./index.js"}},Gu={"@telia-ace/widget-conversation":"*","@webprovisions/platform":"^1.1.4","@emotion/react":"11.11.1","@telia-ace/knowledge-widget-core":"*","@telia-ace/widget-utilities":"*","@telia-ace/widget-services":"*"},He={name:Fu,version:qu,main:Yu,types:Zu,exports:Ku,dependencies:Gu},Ju=async t=>{var g,v,b,$,P;const e=t.get("$widget");se.info((He==null?void 0:He.name)+" version: "+(He==null?void 0:He.version));const n=await pt(t,"conversational-hub-session",he.Necessary),r=(P=($=(b=(v=(g=e==null?void 0:e.container)==null?void 0:g.get("$settings"))==null?void 0:v.components)==null?void 0:b.conversation)==null?void 0:$.properties)==null?void 0:P.conversationalHubPluginSettings,i=await Tr.getInstance(t);let s,o,a=(r==null?void 0:r.connectionAttempts)??5,l;i.registerProvider("chub-plugin",(k,S)=>{s=k,o=s.createAgent({name:r==null?void 0:r.botName,avatar:r==null?void 0:r.avatar}),u(),S.actions.watch("conversation.action",(y,L)=>(c(y),L(y))),S.actions.watch("conversation.user-submit",(y,L)=>(d(y.text),L(y)))});async function u(k=!0){const S=await je(t,"conversational-hub-session");S!=null&&S.sessionId?l=S==null?void 0:S.sessionId:await f(r.baseUrl+"/initialize",`{"extension": "${r.extension}"}`,k)}async function c(k){await f(`${r.baseUrl}/input/${l}`,`{"type":"button_click","language":"${r.language}","content":{"button_text":"${k.label}","value":"${k.actionKey}"}}`)}async function d(k){await f(`${r.baseUrl}/input/${l}`,`{"type":"text","language":"${r.language}","content":{"text":"${k}"}}`)}async function f(k,S,y=!0){var H,B,Y,q;const L=s.loading();let T,A;try{T=await fetch(k,{method:"POST",body:S}),A=await(T==null?void 0:T.json())}catch(Q){Q instanceof SyntaxError?se.error("Incorrect JSON format.",Q):se.error("Network error: check connection or baseUrl.",Q),L(),o.print(r.errorMessage);return}if(!(T!=null&&T.ok)){if(se.error(`HTTP ${T==null?void 0:T.status}.`,JSON.stringify(A)),L(),!!((H=A==null?void 0:A.errors)!=null&&H.filter(W=>W.code==="1003").length)&&a>0){a--,await new Promise(te=>setTimeout(te,500)),await u(!1);const W=JSON.parse(S);(B=W==null?void 0:W.content)!=null&&B.text?await d(W.content.text):(Y=W==null?void 0:W.content)!=null&&Y.action&&await c((q=W==null?void 0:W.content)==null?void 0:q.action)}else o.print(r.errorMessage);return}L(),a=(r==null?void 0:r.connectionAttempts)??5,l=A==null?void 0:A.session_id,n({sessionId:l}),y&&p(A)}function p(k){var S;k==null||k.agent_response.forEach(y=>{o.print(y.payload.text)}),(S=k==null?void 0:k.prompt)!=null&&S.items&&o.print(["button-list",{actions:k.prompt.items.map(y=>{let L;return y.type==="button"&&(L={actionKey:y.value,label:y.text}),y.type==="link"&&(L={actionKey:y.value,label:y.text,data:{href:y.url,target:(r==null?void 0:r.linkTarget)??"_blank"}}),L})}])}};exports.ConversationalHubPlugin=Ju;
|
|
1095
|
+
${n}`:e.length?`${e} ${n}`:n}dispose(){this.subscriptions.forEach(e=>{e()})}}class zn{constructor(e,n){O(this,"id");O(this,"name");O(this,"avatar");O(this,"print",(e,n,r=null)=>{const i={name:this.name,avatar:this.avatar,id:this.id},s=nn(e,n);return r=r??s.timestamp,this.provider.createEntry(s.key,s.content,tn.Agent,i,r)});O(this,"typing",()=>this.provider.setTypingState({name:this.name,avatar:this.avatar}));this.provider=e,this.id=n.id||Xe(),this.name=n.name,this.avatar=n.avatar}update(e){var i;const{name:n,avatar:r}=e;r===null?this.avatar=void 0:r&&(this.avatar=r),n===null?this.name=void 0:n&&(this.name=n),(i=this.provider.controller)==null||i.events.dispatch("conversation:agent-updated",{agent:this})}}class Nr{constructor(e,n,r){O(this,"subscriptions",[]);O(this,"options");O(this,"user");this.name=e,this.container=n,this.controller=r,this.user=r==null?void 0:r.user,this.options={silent:!1}}static create(e,n,r){return new Nr(e,n,r)}createAgent(e={}){var n;if(this.controller){const r=this.controller.getAgentById(e.id),i=r?new zn(this,{...r,...e}):new zn(this,e);return r||(n=this.controller)==null||n.events.dispatch("conversation:agent-created",{agent:i}),i}}print(e){var n;return(n=this.controller)==null?void 0:n.print(e)}setTypingState(e,n){var r;return(r=this.controller)==null?void 0:r.setTypingState(e,n)}loading(){return this.controller?this.controller.loader():()=>()=>{}}createEntry(e,n,r,i,s){var o;return(o=this.controller)==null?void 0:o.createEntry(e,n,r,i,s)}dispose(){var e;process.env.NODE_ENV!=="production"&&console.log(`conversation-provider: dispose (${this.name})`),(e=this.controller)==null||e.disposeProvider(this),this.controller=null,this.subscriptions.forEach(n=>n())}isRehydrated(){var e;return((e=this.controller)==null?void 0:e.isRehydrated())||Promise.resolve(!1)}getHistory(){var e;return((e=this.controller)==null?void 0:e.getHistory())||[]}complete(){var e;(e=this.controller)==null||e.onCompleteProvider()}setOptions(e={silent:!1}){this.options=e}onUnreadMessage(e){var n;if(this.controller){const r=(n=this.controller)==null?void 0:n.onUnreadMessage(e);return this.subscriptions.push(r),()=>{r()}}}onMounted(e){var n;if(this.controller){const r=(n=this.controller)==null?void 0:n.events.subscribe("conversation:component-mount-changed",e);return this.subscriptions.push(r),e({},this.controller.getComponentMountedState()),()=>{r()}}}}const Hs=t=>`conversation-${t}`;class Mu{constructor(){O(this,"_locking",Promise.resolve());O(this,"_locks",0)}isLocked(){return this._locks>0}lock(){this._locks+=1;let e;const n=new Promise(i=>e=()=>{this._locks-=1,i()}),r=this._locking.then(()=>e);return this._locking=this._locking.then(()=>n),r}}class Iu{constructor(e,n,r){O(this,"sessionStorageKey");O(this,"locker",new Mu);O(this,"initialStoredAgents",[]);this.container=e,this.conversation=n,this.enabled=r,this.sessionStorageKey=Hs(n.id),n.onStarted(async()=>{if(n.messages.length>0)return;const{agents:i}=await this.read(),s=[];i&&i.forEach(a=>{const l=n.providerIndex(a.providerName),u=l>-1?n.registeredProviders[l]:n.createProvider(a.providerName),c=new zn(u,{name:a.name,avatar:a.avatar,id:a.id});s.push(c)});const{messages:o}=await this.read();o.forEach(a=>{switch(a.type){case"agent":{const l=s.find(u=>{var c;return u.id===((c=a.sender)==null?void 0:c.id)});l&&l.print(a.content.items||a.content,{key:a.key},a.timestamp);return}case"user":{n.user.print(a.content.items||a.content,{key:a.key},a.timestamp);return}case"system":default:n.print(a.content.items||a.content,a.timestamp)}})}),n.onMessageCreated(async(i,s)=>{this.write(s.message,"messages")}),n.events.subscribe("conversation:agent-created",async(i,s)=>{const o={id:s.agent.id,name:s.agent.name,avatar:s.agent.avatar,providerName:s.agent.provider.name};await this.write(o,"agents")}),n.events.subscribe("conversation:agent-updated",async(i,s)=>{const{agents:o}=await this.read();await this.write([...o.map(a=>a.id===s.agent.id?{...a,name:s.agent.name,avatar:s.agent.avatar}:a)],"agents","update")})}setInitialData(e){this.initialStoredAgents=e.agents}async isRehydrated(){const{messages:e}=await this.read();return e.length>0}getStoredAgent(e){if(this.enabled)return this.initialStoredAgents.find(n=>n.id===e)}async write(e,n,r="add"){if(!this.enabled)return;const i=await this.locker.lock();return pt(this.container,this.sessionStorageKey,he.Necessary).then(async s=>{if(r==="add"){const o=await this.read();if(n==="messages"&&o.messages.findIndex(l=>l.key===e.key)>-1){i();return}const a={...o};return n==="messages"?a.messages=[...a.messages,e]:n==="agents"&&(a.agents=[...a.agents,e]),s({...o,...a}).then(()=>{i()})}if(r==="update"&&n==="agents"){const o=await this.read();return s({...o,agents:e}).then(()=>{i()})}return s(e).then(()=>{i()})})}async read(){return je(this.container,this.sessionStorageKey).then(e=>e||{messages:[],agents:[]})}}class Vu{constructor(e){O(this,"print",(e,n,r=null)=>{const i=nn(e,n);return r=r??i.timestamp,this.controller.createEntry(i.key,i.content,tn.User,void 0,r)});this.controller=e}}const Bn=async(t,e,n)=>{const r=await t.getAsync("conversation"),i=await t.getAsync("components"),s=r.controllers.find(o=>o.conversation.id===e);if(s){const o=[...s.conversation.providers];o.forEach(l=>{s.conversation.setProviderOptions(l,{silent:!0})}),s.conversation.queueProviders(o),s.conversation.setProviders([n]);const a=i.components().ofType("conversation");i.write({key:"setConversationProvider",attributes:{properties:{providers:[n]}},target:a,provider:"localStorage"})}};class Hu{constructor(e){this.writer=e}update(e){const n=this.getNormalizedSettings(e);this.writer(n)}remove(){this.writer(null)}getNormalizedSettings(e){return typeof e=="string"?{body:e}:e.length>-1&&typeof e=="object"?{items:e}:e}}var tn=(t=>(t.User="user",t.Agent="agent",t.System="system",t))(tn||{});const nn=(t,e)=>{let n,r=(e==null?void 0:e.key)||Xe(),i=Date.now();if(Array.isArray(t)&&t.length>-1)typeof t[0]=="string"?n={items:[t]}:n={items:t};else if(typeof t=="string")n={body:t};else if(t=t||{},t.type)n={...t};else{if(n={body:t.body,actions:t.actions,title:t.title},t.key&&(r=t.key),t.timestamp&&(i=t.timestamp),typeof t.form=="function"){const s=Me.create(r);t.form(s);const o=s.get();n.form=o}t.timestamp===null&&(i=null)}return{content:n,key:r,timestamp:i}},Ai=(t,e)=>{if(!e)return;const n=JSON.stringify(e),r=t.findIndex(i=>n===JSON.stringify(i));if(r>-1)return t.splice(r,1)};class zu{constructor(e,n,r){O(this,"formHandlers",{});O(this,"user",new Vu(this));O(this,"events");O(this,"providers",[]);O(this,"active",!1);O(this,"queuedProviders",[]);O(this,"registeredProviders",[]);O(this,"loaders",0);O(this,"componentMounted",!1);O(this,"store");O(this,"messages",[]);O(this,"typingActors",[]);O(this,"conversationHistory");O(this,"print",(e,n=null)=>{const r=nn(e);return n=n??r.timestamp,this.createEntry(r.key,r.content,"system",void 0,n)});this.container=e,this.id=n;const i=e.get("$widget");this.events=i.events.createChild(this),this.store=new Iu(e,this,r.rehydrate),this.conversationHistory=new Du(this)}setInitialStorage(e){this.store.setInitialData(e)}setProviders(e){const n=[],r=[];this.providers.reduce((i,s)=>(e.indexOf(s)===-1&&i.push(s),i),[]).forEach(i=>{const s=this.providers.indexOf(i);s>-1&&(n.push(i),this.providers.splice(s,1))}),e.forEach(i=>{this.providers.indexOf(i)===-1&&(r.push(i),this.providers.push(i))}),(r.length||n.length)&&this.events.dispatch("conversation:providers-changed",{added:r,removed:n})}createProvider(e){const n=this.providerIndex(e);if(n>-1)return this.registeredProviders[n];const r=Nr.create(e,this.container,this);return this.registeredProviders.push(r),r}providerIndex(e){return this.registeredProviders.findIndex(n=>n.name===e)}getAgentById(e){if(e)return this.store.getStoredAgent(e)}dispose(){this.conversationHistory.dispose(),this.registeredProviders.forEach(e=>e.dispose()),this.messages=[],this.events.dispatch("conversation:controller-disposed",this),this.active=!1}onDispose(e){return this.events.subscribe("conversation:controller-disposed",e)}onStarted(e){return this.events.subscribe("conversation:started",e)}onMessageCreated(e){return this.events.subscribe("conversation:message-created",e)}isRehydrated(){return this.store.isRehydrated()}disposeProvider(e){const n=this.providerIndex(e.name);n>-1&&this.registeredProviders.splice(n,1),this.events.dispatch("conversation:providers-changed",{removed:[e.name]}),this.registeredProviders.length||this.dispose()}onProvidersChange(e){return this.events.subscribe("conversation:providers-changed",e)}setComponentMountedState(e){this.componentMounted!==e&&(this.componentMounted=e,e&&(this.events.dispatch("conversation:unread-message",!1),this.events.dispatch("conversation:started",!0),this.active=!0),this.events.dispatch("conversation:component-mount-changed",e))}setProviderOptions(e,n){const r=this.providerIndex(e);r>-1&&this.registeredProviders[r].setOptions(n)}changeProvider(e){this.registeredProviders.find(r=>r.name===e)&&Bn(this.container,this.id,e)}queueProviders(e){this.queuedProviders=e}onCompleteProvider(){const e=this.queuedProviders.pop();e&&Bn(this.container,this.id,e)}getComponentMountedState(){return this.componentMounted}onUnreadMessage(e){return this.events.subscribe("conversation:unread-message",e)}createEntry(e,n,r,i,s){const o={key:e,content:n,type:r,sender:i||null,timestamp:s||s===null?s:Date.now()};this.messages.push(o),o.type==="agent"&&Ai(this.typingActors,i);const a=new Hu(l=>{if(l!==null){const{timestamp:u=void 0,...c}=l;o.content=c,u&&(o.timestamp=u)}else{const u=this.messages.indexOf(o);o.content=null,u>-1&&this.messages.splice(u,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(e,n){return this.typingActors.indexOf(e)===-1&&(this.typingActors.push(e),this.update()),()=>{Ai(this.typingActors,e),this.update()}}loader(){this.loaders=this.loaders+1;let e=!1;return this.loaders===1&&this.update(),()=>{e||(e=!0,this.loaders=this.loaders-1,this.loaders===0&&this.update())}}submitForm(e,n){this.formHandlers[e]={...this.formHandlers[e],submit:n}}validateForm(e,n){this.formHandlers[e]={...this.formHandlers[e],validate:n}}getHistory(){return this.conversationHistory.getConversationLogs()}}const _i=t=>{const{implementation:e}=t.get("$widget"),r=(e.container.get("modals")||[]).map(i=>i.close());return Promise.all(r)},Bu=(t,e)=>{const n=t.split("_contact");return e.widgets.get(n[0])},$r=t=>{const e=t.get("$widget"),{name:n,implementation:r}=t.get("$widget"),i=n.indexOf("_contact")>-1?Bu(n,r):e,{data:s}=t.get("$settings"),{trigger:o}=i.container.get("$settings"),a=`${n.replace("_contact-method","").replace("_contact","")}_contact-method`,l=r.widgets.get(a);return l&&!o?{chatWidget:l,mainWidget:i,data:s}:{mainWidget:i,data:s}},Wu=t=>{const{chatWidget:e}=$r(t);return!!e},Li=(t,e,n)=>{const{mainWidget:r,data:i,chatWidget:s}=$r(t);return s?s.state==="activated"?s.invoke("open").then(()=>{s.container.getAsync("conversation").then(o=>{o.navigateToConversationIfActive(e.id).then(()=>_i(t))})}):s.activate().then(()=>{const{trigger:o}=s.container.get("$settings");return o.action="hide",s.invoke("setSettings",()=>({data:i,trigger:o,activate:!0})).then(()=>s.container.getAsync("components").then(a=>{const l=a.components().ofType("contact-method");a.write({key:"setContactMethodId",attributes:{properties:{id:e.id,guideId:e.guideId}},target:l,provider:"localStorage"});const u=a.components().ofType("conversation");a.write({key:"setConversationProvider",attributes:{properties:{providers:[e.clientName]}},target:u,provider:"localStorage"})}))}).then(()=>s.invoke("attach",{key:"contact-method",triggerDOMElement:n,withRenderState:"open"})).then(()=>(pt(s.container,"activeStickyWidget",he.Necessary,{medium:pe.Local,scope:Ut.Implementation}).then(o=>o(s.name)),s.container.getAsync("conversation").then(o=>{o.setConversationEndedBehavior(Bt.Deactivate)}).then(()=>_i(t)).then(()=>!1))):(r.container.getAsync("conversation").then(o=>o.navigateToConversationIfActive(e.id).then(()=>o.setConversationEndedBehavior(Bt.Navigate))),!s)},Uu=(t,e,n="conversation")=>{const{mainWidget:r,chatWidget:i}=$r(t);return i?i.container.getAsync("router").then(s=>{s.navigate(n,{id:e.id})}):r.container.getAsync("conversation").then(s=>{var o;(o=s.setConversationEndedBehavior(Bt.Navigate))==null||o.then(()=>{r.container.getAsync("router").then(a=>{r.container.getAsync("components").then(l=>{const u=l.components().ofType("conversation");l.write({key:"setConversationProvider",attributes:{properties:{providers:[e.clientName]}},target:u,provider:"localStorage"})}).then(()=>{a.navigate(n,{id:e.id})})})})})},st="conversations";var Bt=(t=>(t.Deactivate="deactivate",t.Navigate="navigate",t.None="none",t))(Bt||{});class Tr{constructor(e,n){O(this,"events");O(this,"controllers",[]);O(this,"providers",[]);O(this,"disposeProviders",{});O(this,"subscriptions",[]);O(this,"storageWriter",null);O(this,"router",null);O(this,"buttonQuery",null);O(this,"sessionInfo",null);this.container=e,this.components=n;const r=e.get("$widget");this.events=r.events.createChild(this)}initialize(){pt(this.container,st,he.Necessary,{medium:pe.Local}).then(e=>this.storageWriter=e),je(this.container,st,pe.Local).then(e=>{this.buttonQuery=this.components.components().ofType("conversation-return-button"),e&&(this.sessionInfo=e,e.id&&e.route&&this.writeToComponents({active:!0,alert:{show:!1}}))}),this.container.getAsync("router").then(e=>this.router=e),this.events.subscribe("conversation:ended",(e,n)=>{var r,i,s;switch((r=this.sessionInfo)==null?void 0:r.conversationEndedBehavior){case"deactivate":this.container.get("$widget").deactivate();break;case"navigate":const a=(i=this.router)==null?void 0:i.getInitialRoute();a&&((s=this.router)==null||s.navigate(a.name));break}this.writeToComponents({active:!1}),this.sessionInfo=null,this.storageWriter&&this.storageWriter()})}addSubscription(e){this.subscriptions.push(e)}static getInstance(e,n="conversation"){return ht(e)(()=>e.getAsync(n).then(r=>{let i=r;return i||Hi.getInstance(e).then(s=>(i=new Tr(e,s),i.initialize(),e.registerAsync(n,()=>i),i))}))}navigateToConversationIfActive(e){return je(this.container,st,pe.Local).then(n=>{var r;if(n&&n.id===e&&n.route){const{name:i,params:s}=n.route;(r=this.router)==null||r.navigate(i,s)}})}setConversationEndedBehavior(e){return je(this.container,st,pe.Local).then(n=>{let r=n;return r?r.conversationEndedBehavior=e:r={conversationEndedBehavior:e},this.sessionInfo=r,this.storageWriter&&this.storageWriter(this.sessionInfo)||Promise.resolve()})}async createController(e,n){const r=Hs(e),{agents:i}=await je(this.container,r)||{agents:[]},s=this.controllers.findIndex(a=>a.conversation.id===e);let o;return s>-1?o=this.controllers[s].conversation:o=new zu(this.container,e,n),o.setInitialStorage({agents:i||[]}),o}registerProvider(e,n){const r={name:e,handler:n};this.providers.push(r),this.controllers.filter(i=>i.conversation.providers.indexOf(e)>-1).forEach(i=>{this.invokeHandler(r,i)})}registerController(e,n){const r=this.controllers.findIndex(s=>s.conversation.id===e.id);let i;if(r<0){i={conversation:e,component:n},this.controllers.push(i);const s=o=>{o&&this.providers.filter(a=>o.indexOf(a.name)>-1).forEach(a=>{this.invokeHandler(a,i)})};return this.subscriptions.push(e.onDispose((o,a)=>{const l=this.controllers.findIndex(u=>u.conversation===a);l>-1&&this.controllers.splice(l,1),this.components.components().ofType("conversation-return-button").select().writeProperties({active:!1}),this.events.dispatch("conversation:ended",{},{bubbles:!0})})),this.subscriptions.push(e.onProvidersChange((o,a)=>{const{added:l,removed:u=[]}=a;u.forEach(c=>{(this.disposeProviders[c]||[]).forEach(d=>{d()})}),s(l)})),this.subscriptions.push(e.onStarted((o,a)=>{var u,c;const l={id:e.id,route:(u=this.router)==null?void 0:u.getRouteData(),conversationEndedBehavior:(c=this.sessionInfo)==null?void 0:c.conversationEndedBehavior};this.sessionInfo=l,this.storageWriter&&this.storageWriter(l),this.writeToComponents({active:a})})),this.subscriptions.push(e.onUnreadMessage((o,a)=>{this.events.dispatch("conversation:unread-message",a),this.writeToComponents({alert:{show:a}})})),s(e.providers),!0}return i=this.controllers[r],!1}writeToComponents(e,n="conversationReturnButtonState"){this.buttonQuery&&this.components.write({key:"conversationReturnButtonState",attributes:{properties:e},target:this.buttonQuery,provider:"localStorage"})}invokeHandler(e,n){const r=e.handler(n.conversation.createProvider(e.name),n.component);r&&(this.disposeProviders[e.name]||(this.disposeProviders[e.name]=[]),this.disposeProviders[e.name].push(r))}getComponentRoute(){return je(this.container,st,pe.Local).then(e=>e==null?void 0:e.route)}dispose(){Object.keys(this.disposeProviders).forEach(e=>{this.disposeProviders[e].forEach(n=>{n()})}),this.subscriptions.forEach(e=>{e()}),this.controllers=[],this.providers=[]}static async handleContactMethodClick(e,n,r,i){if(Wu(n)){e.preventDefault();let s=document.getElementById("humany-dynamic-anchor");s||(s=document.createElement("a"),s.setAttribute("href","#"),s.id="humany-dynamic-anchor",document.body.appendChild(s)),Li(n,r,s)}Li(n,r)}static async handleContactMethodSubmit(e,n){var r,i;return(i=(r=n==null?void 0:n.body.form.meta)==null?void 0:r.conversation)!=null&&i.id?Bn(e,n.body.form.meta.conversation.id,n.clientName):Uu(e,n)}}const Fu="@telia-ace/conversational-hub-bot-provider",qu="0.0.7",Yu="./index.js",Zu="./index.d.ts",Ku={".":{import:"./index.mjs",require:"./index.js"}},Gu={"@telia-ace/widget-conversation":"*","@webprovisions/platform":"^1.1.4","@emotion/react":"11.11.1","@telia-ace/knowledge-widget-core":"*","@telia-ace/widget-utilities":"*","@telia-ace/widget-services":"*"},He={name:Fu,version:qu,main:Yu,types:Zu,exports:Ku,dependencies:Gu},Ju=async t=>{var g,v,b,$,P;const e=t.get("$widget");se.info((He==null?void 0:He.name)+" version: "+(He==null?void 0:He.version));const n=await pt(t,"conversational-hub-session",he.Necessary),r=(P=($=(b=(v=(g=e==null?void 0:e.container)==null?void 0:g.get("$settings"))==null?void 0:v.components)==null?void 0:b.conversation)==null?void 0:$.properties)==null?void 0:P.conversationalHubPluginSettings,i=await Tr.getInstance(t);let s,o,a=(r==null?void 0:r.connectionAttempts)??5,l;i.registerProvider("chub-plugin",(k,S)=>{s=k,o=s.createAgent({name:r==null?void 0:r.botName,avatar:r==null?void 0:r.avatar}),u(),S.actions.watch("conversation.action",(y,L)=>(c(y),L(y))),S.actions.watch("conversation.user-submit",(y,L)=>(d(y.text),L(y)))});async function u(k=!0){const S=await je(t,"conversational-hub-session");S!=null&&S.sessionId?l=S==null?void 0:S.sessionId:await f(r.baseUrl+"/initialize",`{"extension": "${r.extension}"}`,k)}async function c(k){await f(`${r.baseUrl}/input/${l}`,`{"type":"button_click","language":"${r.language}","content":{"button_text":"${k.label}","value":"${k.actionKey}"}}`)}async function d(k){await f(`${r.baseUrl}/input/${l}`,`{"type":"text","language":"${r.language}","content":{"text":"${k}"}}`)}async function f(k,S,y=!0){var H,B,Y,q;const L=s.loading();let T,A;try{T=await fetch(k,{method:"POST",body:S}),A=await(T==null?void 0:T.json())}catch(Q){Q instanceof SyntaxError?se.error("Incorrect JSON format.",Q):se.error("Network error: check connection or baseUrl.",Q),L(),o.print(r.errorMessage);return}if(!(T!=null&&T.ok)){if(se.error(`HTTP ${T==null?void 0:T.status}.`,JSON.stringify(A)),L(),!!((H=A==null?void 0:A.errors)!=null&&H.filter(W=>W.code==="1003").length)&&a>0){a--,await new Promise(te=>setTimeout(te,500)),await u(!1);const W=JSON.parse(S);(B=W==null?void 0:W.content)!=null&&B.text?await d(W.content.text):(Y=W==null?void 0:W.content)!=null&&Y.action&&await c((q=W==null?void 0:W.content)==null?void 0:q.action)}else o.print(r.errorMessage);return}L(),a=(r==null?void 0:r.connectionAttempts)??5,l=A==null?void 0:A.session_id,n({sessionId:l}),y&&p(A)}function p(k){var S;k==null||k.agent_response.forEach(y=>{o.print(y.payload.text)}),(S=k==null?void 0:k.prompt)!=null&&S.items&&o.print(["button-list",{actions:k.prompt.items.map(y=>{let L;return y.type==="button"&&(L={actionKey:y.value,label:y.text}),y.type==="link"&&(L={actionKey:y.value,label:y.text,data:{href:y.url,target:(r==null?void 0:r.linkTarget)??"_blank"}}),L})}])}};exports.ConversationalHubPlugin=Ju;
|
package/index.mjs
CHANGED
|
@@ -539,6 +539,35 @@ Qt((t) => {
|
|
|
539
539
|
});
|
|
540
540
|
});
|
|
541
541
|
});
|
|
542
|
+
function fs(t) {
|
|
543
|
+
const e = [];
|
|
544
|
+
return t.forEach((n) => {
|
|
545
|
+
e.indexOf(n) === -1 && e.push(n);
|
|
546
|
+
}), e;
|
|
547
|
+
}
|
|
548
|
+
function Mn(t = "", e = "") {
|
|
549
|
+
const n = t.split(" ").concat(e.split(" "));
|
|
550
|
+
return fs(n).join(" ").trim();
|
|
551
|
+
}
|
|
552
|
+
function hs(t, e) {
|
|
553
|
+
if (t) {
|
|
554
|
+
if (typeof e == "string")
|
|
555
|
+
return e;
|
|
556
|
+
if (Array.isArray(e)) {
|
|
557
|
+
let n = "";
|
|
558
|
+
return e.forEach((r) => n = Mn(n, r)), n;
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
function se(...t) {
|
|
563
|
+
let e = "";
|
|
564
|
+
return t.length && t.forEach((n) => {
|
|
565
|
+
typeof n == "string" ? e = Mn(e, n) : Array.isArray(n) ? e = Mn(e, hs(...n)) : typeof n < "u" && n !== null && process.env.NODE_ENV !== "production" && ae.warn(
|
|
566
|
+
"appendClassNames: arguments either haveto be a string or [boolean, ...string[]]. Passed args:",
|
|
567
|
+
...t
|
|
568
|
+
);
|
|
569
|
+
}), e;
|
|
570
|
+
}
|
|
542
571
|
function Ut(t) {
|
|
543
572
|
const e = {};
|
|
544
573
|
if (typeof t == "number" || typeof t == "string")
|
|
@@ -620,10 +649,10 @@ function Wr(t) {
|
|
|
620
649
|
}
|
|
621
650
|
return e.toString();
|
|
622
651
|
}
|
|
623
|
-
function
|
|
652
|
+
function ps(t) {
|
|
624
653
|
return t.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/\s+/g, "-").toLowerCase();
|
|
625
654
|
}
|
|
626
|
-
class
|
|
655
|
+
class ms {
|
|
627
656
|
constructor(e, n) {
|
|
628
657
|
k(this, "tasks", []);
|
|
629
658
|
k(this, "current", Promise.resolve());
|
|
@@ -657,7 +686,7 @@ class hs {
|
|
|
657
686
|
}
|
|
658
687
|
const Ot = /* @__PURE__ */ new WeakMap();
|
|
659
688
|
function bt(t, e = 5e3, n = 1e3) {
|
|
660
|
-
return Ot.has(t) || Ot.set(t, new
|
|
689
|
+
return Ot.has(t) || Ot.set(t, new ms(e, n)), (r) => new Promise((i, o) => {
|
|
661
690
|
const s = Ot.get(t);
|
|
662
691
|
s.add(r, i, o, () => {
|
|
663
692
|
s.tasks.length || Ot.delete(t);
|
|
@@ -668,35 +697,6 @@ const Ie = () => Math.floor((1 + Math.random()) * 65536).toString(16).substring(
|
|
|
668
697
|
function ot() {
|
|
669
698
|
return Ie() + Ie() + "-" + Ie() + "-" + Ie() + "-" + Ie() + "-" + Ie() + Ie() + Ie();
|
|
670
699
|
}
|
|
671
|
-
function ps(t) {
|
|
672
|
-
const e = [];
|
|
673
|
-
return t.forEach((n) => {
|
|
674
|
-
e.indexOf(n) === -1 && e.push(n);
|
|
675
|
-
}), e;
|
|
676
|
-
}
|
|
677
|
-
function Mn(t = "", e = "") {
|
|
678
|
-
const n = t.split(" ").concat(e.split(" "));
|
|
679
|
-
return ps(n).join(" ").trim();
|
|
680
|
-
}
|
|
681
|
-
function ms(t, e) {
|
|
682
|
-
if (t) {
|
|
683
|
-
if (typeof e == "string")
|
|
684
|
-
return e;
|
|
685
|
-
if (Array.isArray(e)) {
|
|
686
|
-
let n = "";
|
|
687
|
-
return e.forEach((r) => n = Mn(n, r)), n;
|
|
688
|
-
}
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
function se(...t) {
|
|
692
|
-
let e = "";
|
|
693
|
-
return t.length && t.forEach((n) => {
|
|
694
|
-
typeof n == "string" ? e = Mn(e, n) : Array.isArray(n) ? e = Mn(e, ms(...n)) : typeof n < "u" && n !== null && process.env.NODE_ENV !== "production" && ae.warn(
|
|
695
|
-
"appendClassNames: arguments either haveto be a string or [boolean, ...string[]]. Passed args:",
|
|
696
|
-
...t
|
|
697
|
-
);
|
|
698
|
-
}), e;
|
|
699
|
-
}
|
|
700
700
|
class Ur {
|
|
701
701
|
constructor(e, n) {
|
|
702
702
|
k(this, "id");
|
|
@@ -3210,7 +3210,7 @@ const hi = () => {
|
|
|
3210
3210
|
const r = typeof t[n] > "u" ? "" : t[n], i = typeof r;
|
|
3211
3211
|
if (lc.indexOf(i) > -1) {
|
|
3212
3212
|
const o = n.substring(0, 5);
|
|
3213
|
-
o === "data-" || o === "aria-" ? e[
|
|
3213
|
+
o === "data-" || o === "aria-" ? e[ps(n)] = r.toString() : n.substring(0, 4) !== "css-" && (e[n] = r.toString());
|
|
3214
3214
|
} else
|
|
3215
3215
|
e[n] = r;
|
|
3216
3216
|
return e;
|
|
@@ -9043,21 +9043,24 @@ class Jn {
|
|
|
9043
9043
|
k(this, "id");
|
|
9044
9044
|
k(this, "name");
|
|
9045
9045
|
k(this, "avatar");
|
|
9046
|
-
k(this, "print", (e, n) => {
|
|
9047
|
-
const
|
|
9046
|
+
k(this, "print", (e, n, r = null) => {
|
|
9047
|
+
const i = {
|
|
9048
9048
|
name: this.name,
|
|
9049
9049
|
avatar: this.avatar,
|
|
9050
9050
|
id: this.id
|
|
9051
|
-
},
|
|
9052
|
-
return this.provider.createEntry(
|
|
9053
|
-
|
|
9054
|
-
|
|
9051
|
+
}, o = hn(e, n);
|
|
9052
|
+
return r = r ?? o.timestamp, this.provider.createEntry(
|
|
9053
|
+
o.key,
|
|
9054
|
+
o.content,
|
|
9055
9055
|
fn.Agent,
|
|
9056
|
-
|
|
9057
|
-
|
|
9056
|
+
i,
|
|
9057
|
+
r
|
|
9058
9058
|
);
|
|
9059
9059
|
});
|
|
9060
|
-
k(this, "typing", () => this.provider.setTypingState({
|
|
9060
|
+
k(this, "typing", () => this.provider.setTypingState({
|
|
9061
|
+
name: this.name,
|
|
9062
|
+
avatar: this.avatar
|
|
9063
|
+
}));
|
|
9061
9064
|
this.provider = e, this.id = n.id || ot(), this.name = n.name, this.avatar = n.avatar;
|
|
9062
9065
|
}
|
|
9063
9066
|
update(e) {
|
|
@@ -9191,20 +9194,31 @@ class Ku {
|
|
|
9191
9194
|
var c;
|
|
9192
9195
|
return u.id === ((c = a.sender) == null ? void 0 : c.id);
|
|
9193
9196
|
});
|
|
9194
|
-
l && l.print(
|
|
9195
|
-
|
|
9196
|
-
|
|
9197
|
+
l && l.print(
|
|
9198
|
+
a.content.items || a.content,
|
|
9199
|
+
{
|
|
9200
|
+
key: a.key
|
|
9201
|
+
},
|
|
9202
|
+
a.timestamp
|
|
9203
|
+
);
|
|
9197
9204
|
return;
|
|
9198
9205
|
}
|
|
9199
9206
|
case "user": {
|
|
9200
|
-
n.user.print(
|
|
9201
|
-
|
|
9202
|
-
|
|
9207
|
+
n.user.print(
|
|
9208
|
+
a.content.items || a.content,
|
|
9209
|
+
{
|
|
9210
|
+
key: a.key
|
|
9211
|
+
},
|
|
9212
|
+
a.timestamp
|
|
9213
|
+
);
|
|
9203
9214
|
return;
|
|
9204
9215
|
}
|
|
9205
9216
|
case "system":
|
|
9206
9217
|
default:
|
|
9207
|
-
n.print(
|
|
9218
|
+
n.print(
|
|
9219
|
+
a.content.items || a.content,
|
|
9220
|
+
a.timestamp
|
|
9221
|
+
);
|
|
9208
9222
|
}
|
|
9209
9223
|
});
|
|
9210
9224
|
}), n.onMessageCreated(async (i, o) => {
|
|
@@ -9297,14 +9311,14 @@ class Ku {
|
|
|
9297
9311
|
}
|
|
9298
9312
|
class Gu {
|
|
9299
9313
|
constructor(e) {
|
|
9300
|
-
k(this, "print", (e, n) => {
|
|
9301
|
-
const
|
|
9302
|
-
return this.controller.createEntry(
|
|
9303
|
-
|
|
9304
|
-
|
|
9314
|
+
k(this, "print", (e, n, r = null) => {
|
|
9315
|
+
const i = hn(e, n);
|
|
9316
|
+
return r = r ?? i.timestamp, this.controller.createEntry(
|
|
9317
|
+
i.key,
|
|
9318
|
+
i.content,
|
|
9305
9319
|
fn.User,
|
|
9306
9320
|
void 0,
|
|
9307
|
-
r
|
|
9321
|
+
r
|
|
9308
9322
|
);
|
|
9309
9323
|
});
|
|
9310
9324
|
this.controller = e;
|
|
@@ -9393,14 +9407,14 @@ class Xu {
|
|
|
9393
9407
|
k(this, "messages", []);
|
|
9394
9408
|
k(this, "typingActors", []);
|
|
9395
9409
|
k(this, "conversationHistory");
|
|
9396
|
-
k(this, "print", (e) => {
|
|
9397
|
-
const
|
|
9398
|
-
return this.createEntry(
|
|
9399
|
-
|
|
9400
|
-
|
|
9410
|
+
k(this, "print", (e, n = null) => {
|
|
9411
|
+
const r = hn(e);
|
|
9412
|
+
return n = n ?? r.timestamp, this.createEntry(
|
|
9413
|
+
r.key,
|
|
9414
|
+
r.content,
|
|
9401
9415
|
"system",
|
|
9402
9416
|
void 0,
|
|
9403
|
-
n
|
|
9417
|
+
n
|
|
9404
9418
|
);
|
|
9405
9419
|
});
|
|
9406
9420
|
this.container = e, this.id = n;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@telia-ace/conversational-hub-bot-provider",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.1.2-rc.1",
|
|
4
4
|
"main": "./index.js",
|
|
5
5
|
"types": "./index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -10,11 +10,11 @@
|
|
|
10
10
|
}
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@telia-ace/widget-conversation": "
|
|
13
|
+
"@telia-ace/widget-conversation": "^1.1.2-rc.1",
|
|
14
14
|
"@webprovisions/platform": "^1.1.4",
|
|
15
15
|
"@emotion/react": "11.11.1",
|
|
16
|
-
"@telia-ace/knowledge-widget-core": "
|
|
17
|
-
"@telia-ace/widget-utilities": "
|
|
18
|
-
"@telia-ace/widget-services": "
|
|
16
|
+
"@telia-ace/knowledge-widget-core": "^1.1.2-rc.1",
|
|
17
|
+
"@telia-ace/widget-utilities": "^1.1.2-rc.1",
|
|
18
|
+
"@telia-ace/widget-services": "^1.1.2-rc.1"
|
|
19
19
|
}
|
|
20
|
-
}
|
|
20
|
+
}
|