@asgard-js/core 0.0.2 → 0.0.3

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/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
- "use strict";var Le=Object.defineProperty;var je=(n,t,e)=>t in n?Le(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var _=(n,t,e)=>je(n,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var N=(n=>(n.RESET_CHANNEL="RESET_CHANNEL",n.NONE="NONE",n))(N||{}),m=(n=>(n.INIT="asgard.run.init",n.MESSAGE_START="asgard.message.start",n.MESSAGE_DELTA="asgard.message.delta",n.MESSAGE_COMPLETE="asgard.message.complete",n.DONE="asgard.run.done",n))(m||{}),oe=(n=>(n.TEXT="TEXT",n.HINT="HINT",n.BUTTON="BUTTON",n.IMAGE="IMAGE",n.VIDEO="VIDEO",n.AUDIO="AUDIO",n.LOCATION="LOCATION",n.CAROUSEL="CAROUSEL",n))(oe||{}),V=function(n,t){return V=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,r){e.__proto__=r}||function(e,r){for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(e[i]=r[i])},V(n,t)};function O(n,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");V(n,t);function e(){this.constructor=n}n.prototype=t===null?Object.create(t):(e.prototype=t.prototype,new e)}function Ne(n,t,e,r){function i(s){return s instanceof e?s:new e(function(o){o(s)})}return new(e||(e=Promise))(function(s,o){function c(l){try{a(r.next(l))}catch(h){o(h)}}function u(l){try{a(r.throw(l))}catch(h){o(h)}}function a(l){l.done?s(l.value):i(l.value).then(c,u)}a((r=r.apply(n,t||[])).next())})}function ue(n,t){var e={label:0,sent:function(){if(s[0]&1)throw s[1];return s[1]},trys:[],ops:[]},r,i,s,o=Object.create((typeof Iterator=="function"?Iterator:Object).prototype);return o.next=c(0),o.throw=c(1),o.return=c(2),typeof Symbol=="function"&&(o[Symbol.iterator]=function(){return this}),o;function c(a){return function(l){return u([a,l])}}function u(a){if(r)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(e=0)),e;)try{if(r=1,i&&(s=a[0]&2?i.return:a[0]?i.throw||((s=i.return)&&s.call(i),0):i.next)&&!(s=s.call(i,a[1])).done)return s;switch(i=0,s&&(a=[a[0]&2,s.value]),a[0]){case 0:case 1:s=a;break;case 4:return e.label++,{value:a[1],done:!1};case 5:e.label++,i=a[1],a=[0];continue;case 7:a=e.ops.pop(),e.trys.pop();continue;default:if(s=e.trys,!(s=s.length>0&&s[s.length-1])&&(a[0]===6||a[0]===2)){e=0;continue}if(a[0]===3&&(!s||a[1]>s[0]&&a[1]<s[3])){e.label=a[1];break}if(a[0]===6&&e.label<s[1]){e.label=s[1],s=a;break}if(s&&e.label<s[2]){e.label=s[2],e.ops.push(a);break}s[2]&&e.ops.pop(),e.trys.pop();continue}a=t.call(n,e)}catch(l){a=[6,l],i=0}finally{r=s=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}}function P(n){var t=typeof Symbol=="function"&&Symbol.iterator,e=t&&n[t],r=0;if(e)return e.call(n);if(n&&typeof n.length=="number")return{next:function(){return n&&r>=n.length&&(n=void 0),{value:n&&n[r++],done:!n}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function R(n,t){var e=typeof Symbol=="function"&&n[Symbol.iterator];if(!e)return n;var r=e.call(n),i,s=[],o;try{for(;(t===void 0||t-- >0)&&!(i=r.next()).done;)s.push(i.value)}catch(c){o={error:c}}finally{try{i&&!i.done&&(e=r.return)&&e.call(r)}finally{if(o)throw o.error}}return s}function U(n,t,e){if(e||arguments.length===2)for(var r=0,i=t.length,s;r<i;r++)(s||!(r in t))&&(s||(s=Array.prototype.slice.call(t,0,r)),s[r]=t[r]);return n.concat(s||Array.prototype.slice.call(t))}function C(n){return this instanceof C?(this.v=n,this):new C(n)}function Re(n,t,e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r=e.apply(n,t||[]),i,s=[];return i=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),c("next"),c("throw"),c("return",o),i[Symbol.asyncIterator]=function(){return this},i;function o(f){return function(y){return Promise.resolve(y).then(f,h)}}function c(f,y){r[f]&&(i[f]=function(d){return new Promise(function(w,S){s.push([f,d,w,S])>1||u(f,d)})},y&&(i[f]=y(i[f])))}function u(f,y){try{a(r[f](y))}catch(d){p(s[0][3],d)}}function a(f){f.value instanceof C?Promise.resolve(f.value.v).then(l,h):p(s[0][2],f)}function l(f){u("next",f)}function h(f){u("throw",f)}function p(f,y){f(y),s.shift(),s.length&&u(s[0][0],s[0][1])}}function Ue(n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=n[Symbol.asyncIterator],e;return t?t.call(n):(n=typeof P=="function"?P(n):n[Symbol.iterator](),e={},r("next"),r("throw"),r("return"),e[Symbol.asyncIterator]=function(){return this},e);function r(s){e[s]=n[s]&&function(o){return new Promise(function(c,u){o=n[s](o),i(c,u,o.done,o.value)})}}function i(s,o,c,u){Promise.resolve(u).then(function(a){s({value:a,done:c})},o)}}function v(n){return typeof n=="function"}function ae(n){var t=function(r){Error.call(r),r.stack=new Error().stack},e=n(t);return e.prototype=Object.create(Error.prototype),e.prototype.constructor=e,e}var $=ae(function(n){return function(e){n(this),this.message=e?e.length+` errors occurred during unsubscription:
1
+ "use strict";var Le=Object.defineProperty;var je=(n,t,e)=>t in n?Le(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var M=(n,t,e)=>je(n,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var N=(n=>(n.RESET_CHANNEL="RESET_CHANNEL",n.NONE="NONE",n))(N||{}),m=(n=>(n.INIT="asgard.run.init",n.MESSAGE_START="asgard.message.start",n.MESSAGE_DELTA="asgard.message.delta",n.MESSAGE_COMPLETE="asgard.message.complete",n.DONE="asgard.run.done",n))(m||{}),oe=(n=>(n.TEXT="TEXT",n.HINT="HINT",n.BUTTON="BUTTON",n.IMAGE="IMAGE",n.VIDEO="VIDEO",n.AUDIO="AUDIO",n.LOCATION="LOCATION",n.CAROUSEL="CAROUSEL",n))(oe||{}),V=function(n,t){return V=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,r){e.__proto__=r}||function(e,r){for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(e[i]=r[i])},V(n,t)};function O(n,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");V(n,t);function e(){this.constructor=n}n.prototype=t===null?Object.create(t):(e.prototype=t.prototype,new e)}function Ne(n,t,e,r){function i(u){return u instanceof e?u:new e(function(o){o(u)})}return new(e||(e=Promise))(function(u,o){function c(l){try{a(r.next(l))}catch(h){o(h)}}function s(l){try{a(r.throw(l))}catch(h){o(h)}}function a(l){l.done?u(l.value):i(l.value).then(c,s)}a((r=r.apply(n,t||[])).next())})}function se(n,t){var e={label:0,sent:function(){if(u[0]&1)throw u[1];return u[1]},trys:[],ops:[]},r,i,u,o=Object.create((typeof Iterator=="function"?Iterator:Object).prototype);return o.next=c(0),o.throw=c(1),o.return=c(2),typeof Symbol=="function"&&(o[Symbol.iterator]=function(){return this}),o;function c(a){return function(l){return s([a,l])}}function s(a){if(r)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(e=0)),e;)try{if(r=1,i&&(u=a[0]&2?i.return:a[0]?i.throw||((u=i.return)&&u.call(i),0):i.next)&&!(u=u.call(i,a[1])).done)return u;switch(i=0,u&&(a=[a[0]&2,u.value]),a[0]){case 0:case 1:u=a;break;case 4:return e.label++,{value:a[1],done:!1};case 5:e.label++,i=a[1],a=[0];continue;case 7:a=e.ops.pop(),e.trys.pop();continue;default:if(u=e.trys,!(u=u.length>0&&u[u.length-1])&&(a[0]===6||a[0]===2)){e=0;continue}if(a[0]===3&&(!u||a[1]>u[0]&&a[1]<u[3])){e.label=a[1];break}if(a[0]===6&&e.label<u[1]){e.label=u[1],u=a;break}if(u&&e.label<u[2]){e.label=u[2],e.ops.push(a);break}u[2]&&e.ops.pop(),e.trys.pop();continue}a=t.call(n,e)}catch(l){a=[6,l],i=0}finally{r=u=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}}function C(n){var t=typeof Symbol=="function"&&Symbol.iterator,e=t&&n[t],r=0;if(e)return e.call(n);if(n&&typeof n.length=="number")return{next:function(){return n&&r>=n.length&&(n=void 0),{value:n&&n[r++],done:!n}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function R(n,t){var e=typeof Symbol=="function"&&n[Symbol.iterator];if(!e)return n;var r=e.call(n),i,u=[],o;try{for(;(t===void 0||t-- >0)&&!(i=r.next()).done;)u.push(i.value)}catch(c){o={error:c}}finally{try{i&&!i.done&&(e=r.return)&&e.call(r)}finally{if(o)throw o.error}}return u}function U(n,t,e){if(e||arguments.length===2)for(var r=0,i=t.length,u;r<i;r++)(u||!(r in t))&&(u||(u=Array.prototype.slice.call(t,0,r)),u[r]=t[r]);return n.concat(u||Array.prototype.slice.call(t))}function P(n){return this instanceof P?(this.v=n,this):new P(n)}function Re(n,t,e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r=e.apply(n,t||[]),i,u=[];return i=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),c("next"),c("throw"),c("return",o),i[Symbol.asyncIterator]=function(){return this},i;function o(f){return function(y){return Promise.resolve(y).then(f,h)}}function c(f,y){r[f]&&(i[f]=function(d){return new Promise(function(w,S){u.push([f,d,w,S])>1||s(f,d)})},y&&(i[f]=y(i[f])))}function s(f,y){try{a(r[f](y))}catch(d){p(u[0][3],d)}}function a(f){f.value instanceof P?Promise.resolve(f.value.v).then(l,h):p(u[0][2],f)}function l(f){s("next",f)}function h(f){s("throw",f)}function p(f,y){f(y),u.shift(),u.length&&s(u[0][0],u[0][1])}}function Ue(n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=n[Symbol.asyncIterator],e;return t?t.call(n):(n=typeof C=="function"?C(n):n[Symbol.iterator](),e={},r("next"),r("throw"),r("return"),e[Symbol.asyncIterator]=function(){return this},e);function r(u){e[u]=n[u]&&function(o){return new Promise(function(c,s){o=n[u](o),i(c,s,o.done,o.value)})}}function i(u,o,c,s){Promise.resolve(s).then(function(a){u({value:a,done:c})},o)}}function v(n){return typeof n=="function"}function ae(n){var t=function(r){Error.call(r),r.stack=new Error().stack},e=n(t);return e.prototype=Object.create(Error.prototype),e.prototype.constructor=e,e}var $=ae(function(n){return function(e){n(this),this.message=e?e.length+` errors occurred during unsubscription:
2
2
  `+e.map(function(r,i){return i+1+") "+r.toString()}).join(`
3
- `):"",this.name="UnsubscriptionError",this.errors=e}});function G(n,t){if(n){var e=n.indexOf(t);0<=e&&n.splice(e,1)}}var D=function(){function n(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}return n.prototype.unsubscribe=function(){var t,e,r,i,s;if(!this.closed){this.closed=!0;var o=this._parentage;if(o)if(this._parentage=null,Array.isArray(o))try{for(var c=P(o),u=c.next();!u.done;u=c.next()){var a=u.value;a.remove(this)}}catch(d){t={error:d}}finally{try{u&&!u.done&&(e=c.return)&&e.call(c)}finally{if(t)throw t.error}}else o.remove(this);var l=this.initialTeardown;if(v(l))try{l()}catch(d){s=d instanceof $?d.errors:[d]}var h=this._finalizers;if(h){this._finalizers=null;try{for(var p=P(h),f=p.next();!f.done;f=p.next()){var y=f.value;try{z(y)}catch(d){s=s??[],d instanceof $?s=U(U([],R(s)),R(d.errors)):s.push(d)}}}catch(d){r={error:d}}finally{try{f&&!f.done&&(i=p.return)&&i.call(p)}finally{if(r)throw r.error}}}if(s)throw new $(s)}},n.prototype.add=function(t){var e;if(t&&t!==this)if(this.closed)z(t);else{if(t instanceof n){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=(e=this._finalizers)!==null&&e!==void 0?e:[]).push(t)}},n.prototype._hasParent=function(t){var e=this._parentage;return e===t||Array.isArray(e)&&e.includes(t)},n.prototype._addParent=function(t){var e=this._parentage;this._parentage=Array.isArray(e)?(e.push(t),e):e?[e,t]:t},n.prototype._removeParent=function(t){var e=this._parentage;e===t?this._parentage=null:Array.isArray(e)&&G(e,t)},n.prototype.remove=function(t){var e=this._finalizers;e&&G(e,t),t instanceof n&&t._removeParent(this)},n.EMPTY=function(){var t=new n;return t.closed=!0,t}(),n}(),ce=D.EMPTY;function fe(n){return n instanceof D||n&&"closed"in n&&v(n.remove)&&v(n.add)&&v(n.unsubscribe)}function z(n){v(n)?n():n.unsubscribe()}var Ge={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},le={setTimeout:function(n,t){for(var e=[],r=2;r<arguments.length;r++)e[r-2]=arguments[r];return setTimeout.apply(void 0,U([n,t],R(e)))},clearTimeout:function(n){var t=le.delegate;return((t==null?void 0:t.clearTimeout)||clearTimeout)(n)},delegate:void 0};function de(n){le.setTimeout(function(){throw n})}function Y(){}function j(n){n()}var W=function(n){O(t,n);function t(e){var r=n.call(this)||this;return r.isStopped=!1,e?(r.destination=e,fe(e)&&e.add(r)):r.destination=He,r}return t.create=function(e,r,i){return new q(e,r,i)},t.prototype.next=function(e){this.isStopped||this._next(e)},t.prototype.error=function(e){this.isStopped||(this.isStopped=!0,this._error(e))},t.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},t.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,n.prototype.unsubscribe.call(this),this.destination=null)},t.prototype._next=function(e){this.destination.next(e)},t.prototype._error=function(e){try{this.destination.error(e)}finally{this.unsubscribe()}},t.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},t}(D),Fe=function(){function n(t){this.partialObserver=t}return n.prototype.next=function(t){var e=this.partialObserver;if(e.next)try{e.next(t)}catch(r){L(r)}},n.prototype.error=function(t){var e=this.partialObserver;if(e.error)try{e.error(t)}catch(r){L(r)}else L(t)},n.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(e){L(e)}},n}(),q=function(n){O(t,n);function t(e,r,i){var s=n.call(this)||this,o;return v(e)||!e?o={next:e??void 0,error:r??void 0,complete:i??void 0}:o=e,s.destination=new Fe(o),s}return t}(W);function L(n){de(n)}function Ke(n){throw n}var He={closed:!0,next:Y,error:Ke,complete:Y},X=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();function he(n){return n}function $e(n){return n.length===0?he:n.length===1?n[0]:function(e){return n.reduce(function(r,i){return i(r)},e)}}var b=function(){function n(t){t&&(this._subscribe=t)}return n.prototype.lift=function(t){var e=new n;return e.source=this,e.operator=t,e},n.prototype.subscribe=function(t,e,r){var i=this,s=Ye(t)?t:new q(t,e,r);return j(function(){var o=i,c=o.operator,u=o.source;s.add(c?c.call(s,u):u?i._subscribe(s):i._trySubscribe(s))}),s},n.prototype._trySubscribe=function(t){try{return this._subscribe(t)}catch(e){t.error(e)}},n.prototype.forEach=function(t,e){var r=this;return e=J(e),new e(function(i,s){var o=new q({next:function(c){try{t(c)}catch(u){s(u),o.unsubscribe()}},error:s,complete:i});r.subscribe(o)})},n.prototype._subscribe=function(t){var e;return(e=this.source)===null||e===void 0?void 0:e.subscribe(t)},n.prototype[X]=function(){return this},n.prototype.pipe=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return $e(t)(this)},n.prototype.toPromise=function(t){var e=this;return t=J(t),new t(function(r,i){var s;e.subscribe(function(o){return s=o},function(o){return i(o)},function(){return r(s)})})},n.create=function(t){return new n(t)},n}();function J(n){var t;return(t=n??Ge.Promise)!==null&&t!==void 0?t:Promise}function Ve(n){return n&&v(n.next)&&v(n.error)&&v(n.complete)}function Ye(n){return n&&n instanceof W||Ve(n)&&fe(n)}function qe(n){return v(n==null?void 0:n.lift)}function M(n){return function(t){if(qe(t))return t.lift(function(e){try{return n(e,this)}catch(r){this.error(r)}});throw new TypeError("Unable to lift unknown Observable type")}}function I(n,t,e,r,i){return new Be(n,t,e,r,i)}var Be=function(n){O(t,n);function t(e,r,i,s,o,c){var u=n.call(this,e)||this;return u.onFinalize=o,u.shouldUnsubscribe=c,u._next=r?function(a){try{r(a)}catch(l){e.error(l)}}:n.prototype._next,u._error=s?function(a){try{s(a)}catch(l){e.error(l)}finally{this.unsubscribe()}}:n.prototype._error,u._complete=i?function(){try{i()}catch(a){e.error(a)}finally{this.unsubscribe()}}:n.prototype._complete,u}return t.prototype.unsubscribe=function(){var e;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var r=this.closed;n.prototype.unsubscribe.call(this),!r&&((e=this.onFinalize)===null||e===void 0||e.call(this))}},t}(W),We=ae(function(n){return function(){n(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}}),ye=function(n){O(t,n);function t(){var e=n.call(this)||this;return e.closed=!1,e.currentObservers=null,e.observers=[],e.isStopped=!1,e.hasError=!1,e.thrownError=null,e}return t.prototype.lift=function(e){var r=new Q(this,this);return r.operator=e,r},t.prototype._throwIfClosed=function(){if(this.closed)throw new We},t.prototype.next=function(e){var r=this;j(function(){var i,s;if(r._throwIfClosed(),!r.isStopped){r.currentObservers||(r.currentObservers=Array.from(r.observers));try{for(var o=P(r.currentObservers),c=o.next();!c.done;c=o.next()){var u=c.value;u.next(e)}}catch(a){i={error:a}}finally{try{c&&!c.done&&(s=o.return)&&s.call(o)}finally{if(i)throw i.error}}}})},t.prototype.error=function(e){var r=this;j(function(){if(r._throwIfClosed(),!r.isStopped){r.hasError=r.isStopped=!0,r.thrownError=e;for(var i=r.observers;i.length;)i.shift().error(e)}})},t.prototype.complete=function(){var e=this;j(function(){if(e._throwIfClosed(),!e.isStopped){e.isStopped=!0;for(var r=e.observers;r.length;)r.shift().complete()}})},t.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(t.prototype,"observed",{get:function(){var e;return((e=this.observers)===null||e===void 0?void 0:e.length)>0},enumerable:!1,configurable:!0}),t.prototype._trySubscribe=function(e){return this._throwIfClosed(),n.prototype._trySubscribe.call(this,e)},t.prototype._subscribe=function(e){return this._throwIfClosed(),this._checkFinalizedStatuses(e),this._innerSubscribe(e)},t.prototype._innerSubscribe=function(e){var r=this,i=this,s=i.hasError,o=i.isStopped,c=i.observers;return s||o?ce:(this.currentObservers=null,c.push(e),new D(function(){r.currentObservers=null,G(c,e)}))},t.prototype._checkFinalizedStatuses=function(e){var r=this,i=r.hasError,s=r.thrownError,o=r.isStopped;i?e.error(s):o&&e.complete()},t.prototype.asObservable=function(){var e=new b;return e.source=this,e},t.create=function(e,r){return new Q(e,r)},t}(b),Q=function(n){O(t,n);function t(e,r){var i=n.call(this)||this;return i.destination=e,i.source=r,i}return t.prototype.next=function(e){var r,i;(i=(r=this.destination)===null||r===void 0?void 0:r.next)===null||i===void 0||i.call(r,e)},t.prototype.error=function(e){var r,i;(i=(r=this.destination)===null||r===void 0?void 0:r.error)===null||i===void 0||i.call(r,e)},t.prototype.complete=function(){var e,r;(r=(e=this.destination)===null||e===void 0?void 0:e.complete)===null||r===void 0||r.call(e)},t.prototype._subscribe=function(e){var r,i;return(i=(r=this.source)===null||r===void 0?void 0:r.subscribe(e))!==null&&i!==void 0?i:ce},t}(ye),Xe={now:function(){return Date.now()},delegate:void 0},ze=function(n){O(t,n);function t(e,r){return n.call(this)||this}return t.prototype.schedule=function(e,r){return this},t}(D),Z={setInterval:function(n,t){for(var e=[],r=2;r<arguments.length;r++)e[r-2]=arguments[r];return setInterval.apply(void 0,U([n,t],R(e)))},clearInterval:function(n){return clearInterval(n)},delegate:void 0},Je=function(n){O(t,n);function t(e,r){var i=n.call(this,e,r)||this;return i.scheduler=e,i.work=r,i.pending=!1,i}return t.prototype.schedule=function(e,r){var i;if(r===void 0&&(r=0),this.closed)return this;this.state=e;var s=this.id,o=this.scheduler;return s!=null&&(this.id=this.recycleAsyncId(o,s,r)),this.pending=!0,this.delay=r,this.id=(i=this.id)!==null&&i!==void 0?i:this.requestAsyncId(o,this.id,r),this},t.prototype.requestAsyncId=function(e,r,i){return i===void 0&&(i=0),Z.setInterval(e.flush.bind(e,this),i)},t.prototype.recycleAsyncId=function(e,r,i){if(i===void 0&&(i=0),i!=null&&this.delay===i&&this.pending===!1)return r;r!=null&&Z.clearInterval(r)},t.prototype.execute=function(e,r){if(this.closed)return new Error("executing a cancelled action");this.pending=!1;var i=this._execute(e,r);if(i)return i;this.pending===!1&&this.id!=null&&(this.id=this.recycleAsyncId(this.scheduler,this.id,null))},t.prototype._execute=function(e,r){var i=!1,s;try{this.work(e)}catch(o){i=!0,s=o||new Error("Scheduled action threw falsy error")}if(i)return this.unsubscribe(),s},t.prototype.unsubscribe=function(){if(!this.closed){var e=this,r=e.id,i=e.scheduler,s=i.actions;this.work=this.state=this.scheduler=null,this.pending=!1,G(s,this),r!=null&&(this.id=this.recycleAsyncId(i,r,null)),this.delay=null,n.prototype.unsubscribe.call(this)}},t}(ze),ee=function(){function n(t,e){e===void 0&&(e=n.now),this.schedulerActionCtor=t,this.now=e}return n.prototype.schedule=function(t,e,r){return e===void 0&&(e=0),new this.schedulerActionCtor(this,t).schedule(r,e)},n.now=Xe.now,n}(),Qe=function(n){O(t,n);function t(e,r){r===void 0&&(r=ee.now);var i=n.call(this,e,r)||this;return i.actions=[],i._active=!1,i}return t.prototype.flush=function(e){var r=this.actions;if(this._active){r.push(e);return}var i;this._active=!0;do if(i=e.execute(e.state,e.delay))break;while(e=r.shift());if(this._active=!1,i){for(;e=r.shift();)e.unsubscribe();throw i}},t}(ee),ve=new Qe(Je),Ze=ve,en=new b(function(n){return n.complete()});function pe(n){return n&&v(n.schedule)}function nn(n){return n[n.length-1]}function tn(n){return pe(nn(n))?n.pop():void 0}var be=function(n){return n&&typeof n.length=="number"&&typeof n!="function"};function me(n){return v(n==null?void 0:n.then)}function ge(n){return v(n[X])}function we(n){return Symbol.asyncIterator&&v(n==null?void 0:n[Symbol.asyncIterator])}function Se(n){return new TypeError("You provided "+(n!==null&&typeof n=="object"?"an invalid object":"'"+n+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}function rn(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}var Ee=rn();function Ie(n){return v(n==null?void 0:n[Ee])}function Oe(n){return Re(this,arguments,function(){var e,r,i,s;return ue(this,function(o){switch(o.label){case 0:e=n.getReader(),o.label=1;case 1:o.trys.push([1,,9,10]),o.label=2;case 2:return[4,C(e.read())];case 3:return r=o.sent(),i=r.value,s=r.done,s?[4,C(void 0)]:[3,5];case 4:return[2,o.sent()];case 5:return[4,C(i)];case 6:return[4,o.sent()];case 7:return o.sent(),[3,2];case 8:return[3,10];case 9:return e.releaseLock(),[7];case 10:return[2]}})})}function Ae(n){return v(n==null?void 0:n.getReader)}function A(n){if(n instanceof b)return n;if(n!=null){if(ge(n))return sn(n);if(be(n))return on(n);if(me(n))return un(n);if(we(n))return xe(n);if(Ie(n))return an(n);if(Ae(n))return cn(n)}throw Se(n)}function sn(n){return new b(function(t){var e=n[X]();if(v(e.subscribe))return e.subscribe(t);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function on(n){return new b(function(t){for(var e=0;e<n.length&&!t.closed;e++)t.next(n[e]);t.complete()})}function un(n){return new b(function(t){n.then(function(e){t.closed||(t.next(e),t.complete())},function(e){return t.error(e)}).then(null,de)})}function an(n){return new b(function(t){var e,r;try{for(var i=P(n),s=i.next();!s.done;s=i.next()){var o=s.value;if(t.next(o),t.closed)return}}catch(c){e={error:c}}finally{try{s&&!s.done&&(r=i.return)&&r.call(i)}finally{if(e)throw e.error}}t.complete()})}function xe(n){return new b(function(t){fn(n,t).catch(function(e){return t.error(e)})})}function cn(n){return xe(Oe(n))}function fn(n,t){var e,r,i,s;return Ne(this,void 0,void 0,function(){var o,c;return ue(this,function(u){switch(u.label){case 0:u.trys.push([0,5,6,11]),e=Ue(n),u.label=1;case 1:return[4,e.next()];case 2:if(r=u.sent(),!!r.done)return[3,4];if(o=r.value,t.next(o),t.closed)return[2];u.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return c=u.sent(),i={error:c},[3,11];case 6:return u.trys.push([6,,9,10]),r&&!r.done&&(s=e.return)?[4,s.call(e)]:[3,8];case 7:u.sent(),u.label=8;case 8:return[3,10];case 9:if(i)throw i.error;return[7];case 10:return[7];case 11:return t.complete(),[2]}})})}function T(n,t,e,r,i){r===void 0&&(r=0),i===void 0&&(i=!1);var s=t.schedule(function(){e(),i?n.add(this.schedule(null,r)):this.unsubscribe()},r);if(n.add(s),!i)return s}function _e(n,t){return t===void 0&&(t=0),M(function(e,r){e.subscribe(I(r,function(i){return T(r,n,function(){return r.next(i)},t)},function(){return T(r,n,function(){return r.complete()},t)},function(i){return T(r,n,function(){return r.error(i)},t)}))})}function Te(n,t){return t===void 0&&(t=0),M(function(e,r){r.add(n.schedule(function(){return e.subscribe(r)},t))})}function ln(n,t){return A(n).pipe(Te(t),_e(t))}function dn(n,t){return A(n).pipe(Te(t),_e(t))}function hn(n,t){return new b(function(e){var r=0;return t.schedule(function(){r===n.length?e.complete():(e.next(n[r++]),e.closed||this.schedule())})})}function yn(n,t){return new b(function(e){var r;return T(e,t,function(){r=n[Ee](),T(e,t,function(){var i,s,o;try{i=r.next(),s=i.value,o=i.done}catch(c){e.error(c);return}o?e.complete():e.next(s)},0,!0)}),function(){return v(r==null?void 0:r.return)&&r.return()}})}function Me(n,t){if(!n)throw new Error("Iterable cannot be null");return new b(function(e){T(e,t,function(){var r=n[Symbol.asyncIterator]();T(e,t,function(){r.next().then(function(i){i.done?e.complete():e.next(i.value)})},0,!0)})})}function vn(n,t){return Me(Oe(n),t)}function pn(n,t){if(n!=null){if(ge(n))return ln(n,t);if(be(n))return hn(n,t);if(me(n))return dn(n,t);if(we(n))return Me(n,t);if(Ie(n))return yn(n,t);if(Ae(n))return vn(n,t)}throw Se(n)}function bn(n,t){return t?pn(n,t):A(n)}function mn(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];var e=tn(n);return bn(n,e)}function gn(n){return n instanceof Date&&!isNaN(n)}function Ce(n,t){return M(function(e,r){var i=0;e.subscribe(I(r,function(s){r.next(n.call(t,s,i++))}))})}function wn(n,t,e,r,i,s,o,c){var u=[],a=0,l=0,h=!1,p=function(){h&&!u.length&&!a&&t.complete()},f=function(d){return a<r?y(d):u.push(d)},y=function(d){a++;var w=!1;A(e(d,l++)).subscribe(I(t,function(S){t.next(S)},function(){w=!0},void 0,function(){if(w)try{a--;for(var S=function(){var x=u.shift();o||y(x)};u.length&&a<r;)S();p()}catch(x){t.error(x)}}))};return n.subscribe(I(t,f,function(){h=!0,p()})),function(){}}function F(n,t,e){return e===void 0&&(e=1/0),v(t)?F(function(r,i){return Ce(function(s,o){return t(r,s,i,o)})(A(n(r,i)))},e):(typeof t=="number"&&(e=t),M(function(r,i){return wn(r,i,n,e)}))}function Pe(n,t,e){n===void 0&&(n=0),e===void 0&&(e=Ze);var r=-1;return t!=null&&(pe(t)?e=t:r=t),new b(function(i){var s=gn(n)?+n-e.now():n;s<0&&(s=0);var o=0;return e.schedule(function(){i.closed||(i.next(o++),0<=r?this.schedule(void 0,r):i.complete())},s)})}function Sn(n,t){return v(t)?F(n,t,1):F(n,1)}function En(n){return n<=0?function(){return en}:M(function(t,e){var r=0;t.subscribe(I(e,function(i){++r<=n&&(e.next(i),n<=r&&e.complete())}))})}function In(n){return Ce(function(){return n})}function On(n,t){return F(function(e,r){return A(n(e,r)).pipe(En(1),In(e))})}function An(n,t){t===void 0&&(t=ve);var e=Pe(n,t);return On(function(){return e})}function ne(n){var t;t={count:n};var e=t.count,r=e===void 0?1/0:e,i=t.delay,s=t.resetOnSuccess,o=s===void 0?!1:s;return r<=0?he:M(function(c,u){var a=0,l,h=function(){var p=!1;l=c.subscribe(I(u,function(f){o&&(a=0),u.next(f)},void 0,function(f){if(a++<r){var y=function(){l?(l.unsubscribe(),l=null,h()):p=!0};if(i!=null){var d=typeof i=="number"?Pe(i):A(i(f,a)),w=I(u,function(){w.unsubscribe(),y()},function(){u.complete()});d.subscribe(w)}else y()}else u.error(f)})),p&&(l.unsubscribe(),l=null,h())};h()})}function te(n){return M(function(t,e){A(n).subscribe(I(e,function(){return e.complete()},Y)),!e.closed&&t.subscribe(e)})}async function xn(n,t){const e=n.getReader();let r;for(;!(r=await e.read()).done;)t(r.value)}function _n(n){let t,e,r,i=!1;return function(o){t===void 0?(t=o,e=0,r=-1):t=Mn(t,o);const c=t.length;let u=0;for(;e<c;){i&&(t[e]===10&&(u=++e),i=!1);let a=-1;for(;e<c&&a===-1;++e)switch(t[e]){case 58:r===-1&&(r=e-u);break;case 13:i=!0;case 10:a=e;break}if(a===-1)break;n(t.subarray(u,a),r),u=e,r=-1}u===c?t=void 0:u!==0&&(t=t.subarray(u),e-=u)}}function Tn(n,t,e){let r=re();const i=new TextDecoder;return function(o,c){if(o.length===0)e==null||e(r),r=re();else if(c>0){const u=i.decode(o.subarray(0,c)),a=c+(o[c+1]===32?2:1),l=i.decode(o.subarray(a));switch(u){case"data":r.data=r.data?r.data+`
4
- `+l:l;break;case"event":r.event=l;break;case"id":n(r.id=l);break;case"retry":const h=parseInt(l,10);isNaN(h)||t(r.retry=h);break}}}}function Mn(n,t){const e=new Uint8Array(n.length+t.length);return e.set(n),e.set(t,n.length),e}function re(){return{data:"",event:"",id:"",retry:void 0}}var Cn=function(n,t){var e={};for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&t.indexOf(r)<0&&(e[r]=n[r]);if(n!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,r=Object.getOwnPropertySymbols(n);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(n,r[i])&&(e[r[i]]=n[r[i]]);return e};const B="text/event-stream",Pn=1e3,ie="last-event-id";function Dn(n,t){var{signal:e,headers:r,onopen:i,onmessage:s,onclose:o,onerror:c,openWhenHidden:u,fetch:a}=t,l=Cn(t,["signal","headers","onopen","onmessage","onclose","onerror","openWhenHidden","fetch"]);return new Promise((h,p)=>{const f=Object.assign({},r);f.accept||(f.accept=B);let y;function d(){y.abort(),document.hidden||K()}u||document.addEventListener("visibilitychange",d);let w=Pn,S=0;function x(){document.removeEventListener("visibilitychange",d),window.clearTimeout(S),y.abort()}e==null||e.addEventListener("abort",()=>{x(),h()});const De=a??window.fetch,ke=i??kn;async function K(){var H;y=new AbortController;try{const k=await De(n,Object.assign(Object.assign({},l),{headers:f,signal:y.signal}));await ke(k),await xn(k.body,_n(Tn(E=>{E?f[ie]=E:delete f[ie]},E=>{w=E},s))),o==null||o(),x(),h()}catch(k){if(!y.signal.aborted)try{const E=(H=c==null?void 0:c(k))!==null&&H!==void 0?H:w;window.clearTimeout(S),S=window.setTimeout(K,E)}catch(E){x(),p(E)}}}K()})}function kn(n){const t=n.headers.get("content-type");if(!(t!=null&&t.startsWith(B)))throw new Error(`Expected content-type to be ${B}, Actual: ${t}`)}function se(n){const{endpoint:t,apiKey:e,payload:r}=n;return new b(i=>{const s=new AbortController;return Dn(t,{method:"POST",headers:{"X-API-KEY":e,"Content-Type":"application/json"},body:r?JSON.stringify(r):void 0,signal:s.signal,onopen:async o=>{o.ok||(i.error(o),s.abort())},onmessage:o=>{i.next(JSON.parse(o.data))},onclose:()=>{i.complete()},onerror:o=>{throw i.error(o),s.abort(),o}}),()=>{s.abort()}})}class Ln{constructor(t){_(this,"isConnecting",!1);_(this,"apiKey");_(this,"endpoint");_(this,"destroy$",new ye);if(!t.apiKey)throw new Error("apiKey must be required");if(!t.endpoint)throw new Error("botProviderName must be required");this.apiKey=t.apiKey,this.endpoint=t.endpoint}setChannel(t,e){var r;(r=e==null?void 0:e.onSseStart)==null||r.call(e),this.isConnecting=!0,se({apiKey:this.apiKey,endpoint:this.endpoint,payload:{action:N.RESET_CHANNEL,customChannelId:t.customChannelId,customMessageId:t==null?void 0:t.customMessageId,text:""}}).pipe(te(this.destroy$),ne(3)).subscribe({next:i=>{var s;(s=e==null?void 0:e.onSseMessage)==null||s.call(e,i)},error:i=>{var s;(s=e==null?void 0:e.onSseError)==null||s.call(e,i),this.isConnecting=!1},complete:()=>{var i;(i=e==null?void 0:e.onSseCompleted)==null||i.call(e),this.isConnecting=!1}})}sendMessage(t,e){var r;this.isConnecting=!0,(r=e==null?void 0:e.onSseStart)==null||r.call(e),se({apiKey:this.apiKey,endpoint:this.endpoint,payload:{action:N.NONE,customChannelId:t.customChannelId,customMessageId:t==null?void 0:t.customMessageId,text:t.text}}).pipe(Sn(i=>mn(i).pipe(An((e==null?void 0:e.delayTime)??50))),te(this.destroy$),ne(3)).subscribe({next:i=>{var s;(s=e==null?void 0:e.onSseMessage)==null||s.call(e,i)},error:i=>{var s;(s=e==null?void 0:e.onSseError)==null||s.call(e,i),this.isConnecting=!1},complete:()=>{var i;(i=e==null?void 0:e.onSseCompleted)==null||i.call(e),this.isConnecting=!1}})}close(){this.isConnecting=!1,this.destroy$.next(),this.destroy$.complete()}}class g{constructor({messages:t,typingMessages:e}){_(this,"messages");_(this,"typingMessages",null);this.messages=t,this.typingMessages=e}resetConversation(){return new g({messages:null,typingMessages:null})}pushMessage(t,e){const r=new Map(t.messages);return r.set(e.messageId,e),new g({messages:r,typingMessages:t.typingMessages})}onMessage(t,e,r){const i=(r==null?void 0:r.showDebugMessage)??!1;switch(e.eventType){case m.MESSAGE_START:return t.onMessageStart(t,e,{showDebugMessage:i});case m.MESSAGE_DELTA:return t.onMessageDelta(t,e,{showDebugMessage:i});case m.MESSAGE_COMPLETE:return t.onMessageComplete(t,e,{showDebugMessage:i});case m.DONE:return t.onMessageDone(t);default:return t}}onMessageStart(t,e,r){const i=e.fact.messageStart.message,s=new Map(t.typingMessages);return i.isDebug&&!r.showDebugMessage||s!=null&&s.has(i.messageId)?new g({messages:t.messages,typingMessages:s}):(s.set(i.messageId,{type:"bot",eventType:m.MESSAGE_START,isTyping:!0,typingText:"",messageId:i.messageId,message:i,time:new Date}),new g({messages:t.messages,typingMessages:s}))}onMessageDelta(t,e,r){const i=e.fact.messageDelta.message,s=new Map(t.messages),o=new Map(t.typingMessages),c=o.get(i.messageId);if(i.isDebug&&!r.showDebugMessage||s.has(i.messageId)||(c==null?void 0:c.eventType)===m.MESSAGE_COMPLETE)return new g({messages:t.messages,typingMessages:o});const u=`${(c==null?void 0:c.typingText)??""}${i.text}`;return o.set(i.messageId,{type:"bot",eventType:m.MESSAGE_DELTA,isTyping:!0,typingText:u,messageId:i.messageId,message:i,time:new Date}),new g({messages:t.messages,typingMessages:o})}onMessageComplete(t,e,r){const i=e.fact.messageComplete.message,s=new Map(t.messages),o=new Map(t.typingMessages);return i.isDebug&&!r.showDebugMessage?new g({messages:s,typingMessages:o}):(s.set(i.messageId,{type:"bot",eventType:m.MESSAGE_COMPLETE,isTyping:!1,typingText:null,messageId:i.messageId,message:i,time:new Date}),o.delete(i.messageId),new g({messages:s,typingMessages:o}))}onMessageDone(t){const e=new Map(t.messages),r=new Map(t.typingMessages);return r.forEach((i,s)=>{i.eventType===m.MESSAGE_COMPLETE&&(e.set(i.messageId,i),r.delete(s))}),new g({messages:t.messages,typingMessages:r})}}exports.AsgardServiceClient=Ln;exports.Conversation=g;exports.EventType=m;exports.FetchSseAction=N;exports.MessageTemplateType=oe;
3
+ `):"",this.name="UnsubscriptionError",this.errors=e}});function G(n,t){if(n){var e=n.indexOf(t);0<=e&&n.splice(e,1)}}var D=function(){function n(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}return n.prototype.unsubscribe=function(){var t,e,r,i,u;if(!this.closed){this.closed=!0;var o=this._parentage;if(o)if(this._parentage=null,Array.isArray(o))try{for(var c=C(o),s=c.next();!s.done;s=c.next()){var a=s.value;a.remove(this)}}catch(d){t={error:d}}finally{try{s&&!s.done&&(e=c.return)&&e.call(c)}finally{if(t)throw t.error}}else o.remove(this);var l=this.initialTeardown;if(v(l))try{l()}catch(d){u=d instanceof $?d.errors:[d]}var h=this._finalizers;if(h){this._finalizers=null;try{for(var p=C(h),f=p.next();!f.done;f=p.next()){var y=f.value;try{z(y)}catch(d){u=u??[],d instanceof $?u=U(U([],R(u)),R(d.errors)):u.push(d)}}}catch(d){r={error:d}}finally{try{f&&!f.done&&(i=p.return)&&i.call(p)}finally{if(r)throw r.error}}}if(u)throw new $(u)}},n.prototype.add=function(t){var e;if(t&&t!==this)if(this.closed)z(t);else{if(t instanceof n){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=(e=this._finalizers)!==null&&e!==void 0?e:[]).push(t)}},n.prototype._hasParent=function(t){var e=this._parentage;return e===t||Array.isArray(e)&&e.includes(t)},n.prototype._addParent=function(t){var e=this._parentage;this._parentage=Array.isArray(e)?(e.push(t),e):e?[e,t]:t},n.prototype._removeParent=function(t){var e=this._parentage;e===t?this._parentage=null:Array.isArray(e)&&G(e,t)},n.prototype.remove=function(t){var e=this._finalizers;e&&G(e,t),t instanceof n&&t._removeParent(this)},n.EMPTY=function(){var t=new n;return t.closed=!0,t}(),n}(),ce=D.EMPTY;function fe(n){return n instanceof D||n&&"closed"in n&&v(n.remove)&&v(n.add)&&v(n.unsubscribe)}function z(n){v(n)?n():n.unsubscribe()}var Ge={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},le={setTimeout:function(n,t){for(var e=[],r=2;r<arguments.length;r++)e[r-2]=arguments[r];return setTimeout.apply(void 0,U([n,t],R(e)))},clearTimeout:function(n){var t=le.delegate;return((t==null?void 0:t.clearTimeout)||clearTimeout)(n)},delegate:void 0};function de(n){le.setTimeout(function(){throw n})}function Y(){}function j(n){n()}var W=function(n){O(t,n);function t(e){var r=n.call(this)||this;return r.isStopped=!1,e?(r.destination=e,fe(e)&&e.add(r)):r.destination=He,r}return t.create=function(e,r,i){return new q(e,r,i)},t.prototype.next=function(e){this.isStopped||this._next(e)},t.prototype.error=function(e){this.isStopped||(this.isStopped=!0,this._error(e))},t.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},t.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,n.prototype.unsubscribe.call(this),this.destination=null)},t.prototype._next=function(e){this.destination.next(e)},t.prototype._error=function(e){try{this.destination.error(e)}finally{this.unsubscribe()}},t.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},t}(D),Fe=function(){function n(t){this.partialObserver=t}return n.prototype.next=function(t){var e=this.partialObserver;if(e.next)try{e.next(t)}catch(r){L(r)}},n.prototype.error=function(t){var e=this.partialObserver;if(e.error)try{e.error(t)}catch(r){L(r)}else L(t)},n.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(e){L(e)}},n}(),q=function(n){O(t,n);function t(e,r,i){var u=n.call(this)||this,o;return v(e)||!e?o={next:e??void 0,error:r??void 0,complete:i??void 0}:o=e,u.destination=new Fe(o),u}return t}(W);function L(n){de(n)}function Ke(n){throw n}var He={closed:!0,next:Y,error:Ke,complete:Y},X=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();function he(n){return n}function $e(n){return n.length===0?he:n.length===1?n[0]:function(e){return n.reduce(function(r,i){return i(r)},e)}}var b=function(){function n(t){t&&(this._subscribe=t)}return n.prototype.lift=function(t){var e=new n;return e.source=this,e.operator=t,e},n.prototype.subscribe=function(t,e,r){var i=this,u=Ye(t)?t:new q(t,e,r);return j(function(){var o=i,c=o.operator,s=o.source;u.add(c?c.call(u,s):s?i._subscribe(u):i._trySubscribe(u))}),u},n.prototype._trySubscribe=function(t){try{return this._subscribe(t)}catch(e){t.error(e)}},n.prototype.forEach=function(t,e){var r=this;return e=J(e),new e(function(i,u){var o=new q({next:function(c){try{t(c)}catch(s){u(s),o.unsubscribe()}},error:u,complete:i});r.subscribe(o)})},n.prototype._subscribe=function(t){var e;return(e=this.source)===null||e===void 0?void 0:e.subscribe(t)},n.prototype[X]=function(){return this},n.prototype.pipe=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return $e(t)(this)},n.prototype.toPromise=function(t){var e=this;return t=J(t),new t(function(r,i){var u;e.subscribe(function(o){return u=o},function(o){return i(o)},function(){return r(u)})})},n.create=function(t){return new n(t)},n}();function J(n){var t;return(t=n??Ge.Promise)!==null&&t!==void 0?t:Promise}function Ve(n){return n&&v(n.next)&&v(n.error)&&v(n.complete)}function Ye(n){return n&&n instanceof W||Ve(n)&&fe(n)}function qe(n){return v(n==null?void 0:n.lift)}function T(n){return function(t){if(qe(t))return t.lift(function(e){try{return n(e,this)}catch(r){this.error(r)}});throw new TypeError("Unable to lift unknown Observable type")}}function I(n,t,e,r,i){return new Be(n,t,e,r,i)}var Be=function(n){O(t,n);function t(e,r,i,u,o,c){var s=n.call(this,e)||this;return s.onFinalize=o,s.shouldUnsubscribe=c,s._next=r?function(a){try{r(a)}catch(l){e.error(l)}}:n.prototype._next,s._error=u?function(a){try{u(a)}catch(l){e.error(l)}finally{this.unsubscribe()}}:n.prototype._error,s._complete=i?function(){try{i()}catch(a){e.error(a)}finally{this.unsubscribe()}}:n.prototype._complete,s}return t.prototype.unsubscribe=function(){var e;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var r=this.closed;n.prototype.unsubscribe.call(this),!r&&((e=this.onFinalize)===null||e===void 0||e.call(this))}},t}(W),We=ae(function(n){return function(){n(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}}),ye=function(n){O(t,n);function t(){var e=n.call(this)||this;return e.closed=!1,e.currentObservers=null,e.observers=[],e.isStopped=!1,e.hasError=!1,e.thrownError=null,e}return t.prototype.lift=function(e){var r=new Q(this,this);return r.operator=e,r},t.prototype._throwIfClosed=function(){if(this.closed)throw new We},t.prototype.next=function(e){var r=this;j(function(){var i,u;if(r._throwIfClosed(),!r.isStopped){r.currentObservers||(r.currentObservers=Array.from(r.observers));try{for(var o=C(r.currentObservers),c=o.next();!c.done;c=o.next()){var s=c.value;s.next(e)}}catch(a){i={error:a}}finally{try{c&&!c.done&&(u=o.return)&&u.call(o)}finally{if(i)throw i.error}}}})},t.prototype.error=function(e){var r=this;j(function(){if(r._throwIfClosed(),!r.isStopped){r.hasError=r.isStopped=!0,r.thrownError=e;for(var i=r.observers;i.length;)i.shift().error(e)}})},t.prototype.complete=function(){var e=this;j(function(){if(e._throwIfClosed(),!e.isStopped){e.isStopped=!0;for(var r=e.observers;r.length;)r.shift().complete()}})},t.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(t.prototype,"observed",{get:function(){var e;return((e=this.observers)===null||e===void 0?void 0:e.length)>0},enumerable:!1,configurable:!0}),t.prototype._trySubscribe=function(e){return this._throwIfClosed(),n.prototype._trySubscribe.call(this,e)},t.prototype._subscribe=function(e){return this._throwIfClosed(),this._checkFinalizedStatuses(e),this._innerSubscribe(e)},t.prototype._innerSubscribe=function(e){var r=this,i=this,u=i.hasError,o=i.isStopped,c=i.observers;return u||o?ce:(this.currentObservers=null,c.push(e),new D(function(){r.currentObservers=null,G(c,e)}))},t.prototype._checkFinalizedStatuses=function(e){var r=this,i=r.hasError,u=r.thrownError,o=r.isStopped;i?e.error(u):o&&e.complete()},t.prototype.asObservable=function(){var e=new b;return e.source=this,e},t.create=function(e,r){return new Q(e,r)},t}(b),Q=function(n){O(t,n);function t(e,r){var i=n.call(this)||this;return i.destination=e,i.source=r,i}return t.prototype.next=function(e){var r,i;(i=(r=this.destination)===null||r===void 0?void 0:r.next)===null||i===void 0||i.call(r,e)},t.prototype.error=function(e){var r,i;(i=(r=this.destination)===null||r===void 0?void 0:r.error)===null||i===void 0||i.call(r,e)},t.prototype.complete=function(){var e,r;(r=(e=this.destination)===null||e===void 0?void 0:e.complete)===null||r===void 0||r.call(e)},t.prototype._subscribe=function(e){var r,i;return(i=(r=this.source)===null||r===void 0?void 0:r.subscribe(e))!==null&&i!==void 0?i:ce},t}(ye),Xe={now:function(){return Date.now()},delegate:void 0},ze=function(n){O(t,n);function t(e,r){return n.call(this)||this}return t.prototype.schedule=function(e,r){return this},t}(D),Z={setInterval:function(n,t){for(var e=[],r=2;r<arguments.length;r++)e[r-2]=arguments[r];return setInterval.apply(void 0,U([n,t],R(e)))},clearInterval:function(n){return clearInterval(n)},delegate:void 0},Je=function(n){O(t,n);function t(e,r){var i=n.call(this,e,r)||this;return i.scheduler=e,i.work=r,i.pending=!1,i}return t.prototype.schedule=function(e,r){var i;if(r===void 0&&(r=0),this.closed)return this;this.state=e;var u=this.id,o=this.scheduler;return u!=null&&(this.id=this.recycleAsyncId(o,u,r)),this.pending=!0,this.delay=r,this.id=(i=this.id)!==null&&i!==void 0?i:this.requestAsyncId(o,this.id,r),this},t.prototype.requestAsyncId=function(e,r,i){return i===void 0&&(i=0),Z.setInterval(e.flush.bind(e,this),i)},t.prototype.recycleAsyncId=function(e,r,i){if(i===void 0&&(i=0),i!=null&&this.delay===i&&this.pending===!1)return r;r!=null&&Z.clearInterval(r)},t.prototype.execute=function(e,r){if(this.closed)return new Error("executing a cancelled action");this.pending=!1;var i=this._execute(e,r);if(i)return i;this.pending===!1&&this.id!=null&&(this.id=this.recycleAsyncId(this.scheduler,this.id,null))},t.prototype._execute=function(e,r){var i=!1,u;try{this.work(e)}catch(o){i=!0,u=o||new Error("Scheduled action threw falsy error")}if(i)return this.unsubscribe(),u},t.prototype.unsubscribe=function(){if(!this.closed){var e=this,r=e.id,i=e.scheduler,u=i.actions;this.work=this.state=this.scheduler=null,this.pending=!1,G(u,this),r!=null&&(this.id=this.recycleAsyncId(i,r,null)),this.delay=null,n.prototype.unsubscribe.call(this)}},t}(ze),ee=function(){function n(t,e){e===void 0&&(e=n.now),this.schedulerActionCtor=t,this.now=e}return n.prototype.schedule=function(t,e,r){return e===void 0&&(e=0),new this.schedulerActionCtor(this,t).schedule(r,e)},n.now=Xe.now,n}(),Qe=function(n){O(t,n);function t(e,r){r===void 0&&(r=ee.now);var i=n.call(this,e,r)||this;return i.actions=[],i._active=!1,i}return t.prototype.flush=function(e){var r=this.actions;if(this._active){r.push(e);return}var i;this._active=!0;do if(i=e.execute(e.state,e.delay))break;while(e=r.shift());if(this._active=!1,i){for(;e=r.shift();)e.unsubscribe();throw i}},t}(ee),ve=new Qe(Je),Ze=ve,en=new b(function(n){return n.complete()});function pe(n){return n&&v(n.schedule)}function nn(n){return n[n.length-1]}function tn(n){return pe(nn(n))?n.pop():void 0}var be=function(n){return n&&typeof n.length=="number"&&typeof n!="function"};function me(n){return v(n==null?void 0:n.then)}function ge(n){return v(n[X])}function we(n){return Symbol.asyncIterator&&v(n==null?void 0:n[Symbol.asyncIterator])}function Se(n){return new TypeError("You provided "+(n!==null&&typeof n=="object"?"an invalid object":"'"+n+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}function rn(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}var Ee=rn();function Ie(n){return v(n==null?void 0:n[Ee])}function Oe(n){return Re(this,arguments,function(){var e,r,i,u;return se(this,function(o){switch(o.label){case 0:e=n.getReader(),o.label=1;case 1:o.trys.push([1,,9,10]),o.label=2;case 2:return[4,P(e.read())];case 3:return r=o.sent(),i=r.value,u=r.done,u?[4,P(void 0)]:[3,5];case 4:return[2,o.sent()];case 5:return[4,P(i)];case 6:return[4,o.sent()];case 7:return o.sent(),[3,2];case 8:return[3,10];case 9:return e.releaseLock(),[7];case 10:return[2]}})})}function Ae(n){return v(n==null?void 0:n.getReader)}function A(n){if(n instanceof b)return n;if(n!=null){if(ge(n))return un(n);if(be(n))return on(n);if(me(n))return sn(n);if(we(n))return xe(n);if(Ie(n))return an(n);if(Ae(n))return cn(n)}throw Se(n)}function un(n){return new b(function(t){var e=n[X]();if(v(e.subscribe))return e.subscribe(t);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function on(n){return new b(function(t){for(var e=0;e<n.length&&!t.closed;e++)t.next(n[e]);t.complete()})}function sn(n){return new b(function(t){n.then(function(e){t.closed||(t.next(e),t.complete())},function(e){return t.error(e)}).then(null,de)})}function an(n){return new b(function(t){var e,r;try{for(var i=C(n),u=i.next();!u.done;u=i.next()){var o=u.value;if(t.next(o),t.closed)return}}catch(c){e={error:c}}finally{try{u&&!u.done&&(r=i.return)&&r.call(i)}finally{if(e)throw e.error}}t.complete()})}function xe(n){return new b(function(t){fn(n,t).catch(function(e){return t.error(e)})})}function cn(n){return xe(Oe(n))}function fn(n,t){var e,r,i,u;return Ne(this,void 0,void 0,function(){var o,c;return se(this,function(s){switch(s.label){case 0:s.trys.push([0,5,6,11]),e=Ue(n),s.label=1;case 1:return[4,e.next()];case 2:if(r=s.sent(),!!r.done)return[3,4];if(o=r.value,t.next(o),t.closed)return[2];s.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return c=s.sent(),i={error:c},[3,11];case 6:return s.trys.push([6,,9,10]),r&&!r.done&&(u=e.return)?[4,u.call(e)]:[3,8];case 7:s.sent(),s.label=8;case 8:return[3,10];case 9:if(i)throw i.error;return[7];case 10:return[7];case 11:return t.complete(),[2]}})})}function _(n,t,e,r,i){r===void 0&&(r=0),i===void 0&&(i=!1);var u=t.schedule(function(){e(),i?n.add(this.schedule(null,r)):this.unsubscribe()},r);if(n.add(u),!i)return u}function _e(n,t){return t===void 0&&(t=0),T(function(e,r){e.subscribe(I(r,function(i){return _(r,n,function(){return r.next(i)},t)},function(){return _(r,n,function(){return r.complete()},t)},function(i){return _(r,n,function(){return r.error(i)},t)}))})}function Te(n,t){return t===void 0&&(t=0),T(function(e,r){r.add(n.schedule(function(){return e.subscribe(r)},t))})}function ln(n,t){return A(n).pipe(Te(t),_e(t))}function dn(n,t){return A(n).pipe(Te(t),_e(t))}function hn(n,t){return new b(function(e){var r=0;return t.schedule(function(){r===n.length?e.complete():(e.next(n[r++]),e.closed||this.schedule())})})}function yn(n,t){return new b(function(e){var r;return _(e,t,function(){r=n[Ee](),_(e,t,function(){var i,u,o;try{i=r.next(),u=i.value,o=i.done}catch(c){e.error(c);return}o?e.complete():e.next(u)},0,!0)}),function(){return v(r==null?void 0:r.return)&&r.return()}})}function Me(n,t){if(!n)throw new Error("Iterable cannot be null");return new b(function(e){_(e,t,function(){var r=n[Symbol.asyncIterator]();_(e,t,function(){r.next().then(function(i){i.done?e.complete():e.next(i.value)})},0,!0)})})}function vn(n,t){return Me(Oe(n),t)}function pn(n,t){if(n!=null){if(ge(n))return ln(n,t);if(be(n))return hn(n,t);if(me(n))return dn(n,t);if(we(n))return Me(n,t);if(Ie(n))return yn(n,t);if(Ae(n))return vn(n,t)}throw Se(n)}function bn(n,t){return t?pn(n,t):A(n)}function mn(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];var e=tn(n);return bn(n,e)}function gn(n){return n instanceof Date&&!isNaN(n)}function Pe(n,t){return T(function(e,r){var i=0;e.subscribe(I(r,function(u){r.next(n.call(t,u,i++))}))})}function wn(n,t,e,r,i,u,o,c){var s=[],a=0,l=0,h=!1,p=function(){h&&!s.length&&!a&&t.complete()},f=function(d){return a<r?y(d):s.push(d)},y=function(d){a++;var w=!1;A(e(d,l++)).subscribe(I(t,function(S){t.next(S)},function(){w=!0},void 0,function(){if(w)try{a--;for(var S=function(){var x=s.shift();o||y(x)};s.length&&a<r;)S();p()}catch(x){t.error(x)}}))};return n.subscribe(I(t,f,function(){h=!0,p()})),function(){}}function F(n,t,e){return e===void 0&&(e=1/0),v(t)?F(function(r,i){return Pe(function(u,o){return t(r,u,i,o)})(A(n(r,i)))},e):(typeof t=="number"&&(e=t),T(function(r,i){return wn(r,i,n,e)}))}function Ce(n,t,e){n===void 0&&(n=0),e===void 0&&(e=Ze);var r=-1;return t!=null&&(pe(t)?e=t:r=t),new b(function(i){var u=gn(n)?+n-e.now():n;u<0&&(u=0);var o=0;return e.schedule(function(){i.closed||(i.next(o++),0<=r?this.schedule(void 0,r):i.complete())},u)})}function Sn(n,t){return v(t)?F(n,t,1):F(n,1)}function En(n){return n<=0?function(){return en}:T(function(t,e){var r=0;t.subscribe(I(e,function(i){++r<=n&&(e.next(i),n<=r&&e.complete())}))})}function In(n){return Pe(function(){return n})}function On(n,t){return F(function(e,r){return A(n(e,r)).pipe(En(1),In(e))})}function An(n,t){t===void 0&&(t=ve);var e=Ce(n,t);return On(function(){return e})}function ne(n){var t;t={count:n};var e=t.count,r=e===void 0?1/0:e,i=t.delay,u=t.resetOnSuccess,o=u===void 0?!1:u;return r<=0?he:T(function(c,s){var a=0,l,h=function(){var p=!1;l=c.subscribe(I(s,function(f){o&&(a=0),s.next(f)},void 0,function(f){if(a++<r){var y=function(){l?(l.unsubscribe(),l=null,h()):p=!0};if(i!=null){var d=typeof i=="number"?Ce(i):A(i(f,a)),w=I(s,function(){w.unsubscribe(),y()},function(){s.complete()});d.subscribe(w)}else y()}else s.error(f)})),p&&(l.unsubscribe(),l=null,h())};h()})}function te(n){return T(function(t,e){A(n).subscribe(I(e,function(){return e.complete()},Y)),!e.closed&&t.subscribe(e)})}async function xn(n,t){const e=n.getReader();let r;for(;!(r=await e.read()).done;)t(r.value)}function _n(n){let t,e,r,i=!1;return function(o){t===void 0?(t=o,e=0,r=-1):t=Mn(t,o);const c=t.length;let s=0;for(;e<c;){i&&(t[e]===10&&(s=++e),i=!1);let a=-1;for(;e<c&&a===-1;++e)switch(t[e]){case 58:r===-1&&(r=e-s);break;case 13:i=!0;case 10:a=e;break}if(a===-1)break;n(t.subarray(s,a),r),s=e,r=-1}s===c?t=void 0:s!==0&&(t=t.subarray(s),e-=s)}}function Tn(n,t,e){let r=re();const i=new TextDecoder;return function(o,c){if(o.length===0)e==null||e(r),r=re();else if(c>0){const s=i.decode(o.subarray(0,c)),a=c+(o[c+1]===32?2:1),l=i.decode(o.subarray(a));switch(s){case"data":r.data=r.data?r.data+`
4
+ `+l:l;break;case"event":r.event=l;break;case"id":n(r.id=l);break;case"retry":const h=parseInt(l,10);isNaN(h)||t(r.retry=h);break}}}}function Mn(n,t){const e=new Uint8Array(n.length+t.length);return e.set(n),e.set(t,n.length),e}function re(){return{data:"",event:"",id:"",retry:void 0}}var Pn=function(n,t){var e={};for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&t.indexOf(r)<0&&(e[r]=n[r]);if(n!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,r=Object.getOwnPropertySymbols(n);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(n,r[i])&&(e[r[i]]=n[r[i]]);return e};const B="text/event-stream",Cn=1e3,ie="last-event-id";function Dn(n,t){var{signal:e,headers:r,onopen:i,onmessage:u,onclose:o,onerror:c,openWhenHidden:s,fetch:a}=t,l=Pn(t,["signal","headers","onopen","onmessage","onclose","onerror","openWhenHidden","fetch"]);return new Promise((h,p)=>{const f=Object.assign({},r);f.accept||(f.accept=B);let y;function d(){y.abort(),document.hidden||K()}s||document.addEventListener("visibilitychange",d);let w=Cn,S=0;function x(){document.removeEventListener("visibilitychange",d),window.clearTimeout(S),y.abort()}e==null||e.addEventListener("abort",()=>{x(),h()});const De=a??window.fetch,ke=i??kn;async function K(){var H;y=new AbortController;try{const k=await De(n,Object.assign(Object.assign({},l),{headers:f,signal:y.signal}));await ke(k),await xn(k.body,_n(Tn(E=>{E?f[ie]=E:delete f[ie]},E=>{w=E},u))),o==null||o(),x(),h()}catch(k){if(!y.signal.aborted)try{const E=(H=c==null?void 0:c(k))!==null&&H!==void 0?H:w;window.clearTimeout(S),S=window.setTimeout(K,E)}catch(E){x(),p(E)}}}K()})}function kn(n){const t=n.headers.get("content-type");if(!(t!=null&&t.startsWith(B)))throw new Error(`Expected content-type to be ${B}, Actual: ${t}`)}function ue(n){const{endpoint:t,apiKey:e,payload:r}=n;return new b(i=>{const u=new AbortController;return Dn(t,{method:"POST",headers:{"X-API-KEY":e,"Content-Type":"application/json"},body:r?JSON.stringify(r):void 0,signal:u.signal,onopen:async o=>{o.ok||(i.error(o),u.abort())},onmessage:o=>{i.next(JSON.parse(o.data))},onclose:()=>{i.complete()},onerror:o=>{throw i.error(o),u.abort(),o}}),()=>{u.abort()}})}class Ln{constructor(t){M(this,"apiKey");M(this,"endpoint");M(this,"destroy$",new ye);if(!t.apiKey)throw new Error("apiKey must be required");if(!t.endpoint)throw new Error("botProviderName must be required");this.apiKey=t.apiKey,this.endpoint=t.endpoint}setChannel(t,e){var r;(r=e==null?void 0:e.onSseStart)==null||r.call(e),ue({apiKey:this.apiKey,endpoint:this.endpoint,payload:{action:N.RESET_CHANNEL,customChannelId:t.customChannelId,customMessageId:t==null?void 0:t.customMessageId,text:""}}).pipe(te(this.destroy$),ne(3)).subscribe({next:i=>{var u;(u=e==null?void 0:e.onSseMessage)==null||u.call(e,i)},error:i=>{var u;(u=e==null?void 0:e.onSseError)==null||u.call(e,i)},complete:()=>{var i;(i=e==null?void 0:e.onSseCompleted)==null||i.call(e)}})}sendMessage(t,e){var r;(r=e==null?void 0:e.onSseStart)==null||r.call(e),ue({apiKey:this.apiKey,endpoint:this.endpoint,payload:{action:N.NONE,customChannelId:t.customChannelId,customMessageId:t==null?void 0:t.customMessageId,text:t.text}}).pipe(Sn(i=>mn(i).pipe(An((e==null?void 0:e.delayTime)??50))),te(this.destroy$),ne(3)).subscribe({next:i=>{var u;(u=e==null?void 0:e.onSseMessage)==null||u.call(e,i)},error:i=>{var u;(u=e==null?void 0:e.onSseError)==null||u.call(e,i)},complete:()=>{var i;(i=e==null?void 0:e.onSseCompleted)==null||i.call(e)}})}close(){this.destroy$.next(),this.destroy$.complete()}}class g{constructor({messages:t,typingMessages:e}){M(this,"messages");M(this,"typingMessages",null);this.messages=t,this.typingMessages=e}resetConversation(){return new g({messages:null,typingMessages:null})}pushMessage(t,e){const r=new Map(t.messages);return r.set(e.messageId,e),new g({messages:r,typingMessages:t.typingMessages})}onMessage(t,e,r){const i=(r==null?void 0:r.showDebugMessage)??!1;switch(e.eventType){case m.MESSAGE_START:return t.onMessageStart(t,e,{showDebugMessage:i});case m.MESSAGE_DELTA:return t.onMessageDelta(t,e,{showDebugMessage:i});case m.MESSAGE_COMPLETE:return t.onMessageComplete(t,e,{showDebugMessage:i});case m.DONE:return t.onMessageDone(t);default:return t}}onMessageStart(t,e,r){const i=e.fact.messageStart.message,u=new Map(t.typingMessages);return i.isDebug&&!r.showDebugMessage||u!=null&&u.has(i.messageId)?new g({messages:t.messages,typingMessages:u}):(u.set(i.messageId,{type:"bot",eventType:m.MESSAGE_START,isTyping:!0,typingText:"",messageId:i.messageId,message:i,time:new Date}),new g({messages:t.messages,typingMessages:u}))}onMessageDelta(t,e,r){const i=e.fact.messageDelta.message,u=new Map(t.messages),o=new Map(t.typingMessages),c=o.get(i.messageId);if(i.isDebug&&!r.showDebugMessage||u.has(i.messageId)||(c==null?void 0:c.eventType)===m.MESSAGE_COMPLETE)return new g({messages:t.messages,typingMessages:o});const s=`${(c==null?void 0:c.typingText)??""}${i.text}`;return o.set(i.messageId,{type:"bot",eventType:m.MESSAGE_DELTA,isTyping:!0,typingText:s,messageId:i.messageId,message:i,time:new Date}),new g({messages:t.messages,typingMessages:o})}onMessageComplete(t,e,r){const i=e.fact.messageComplete.message,u=new Map(t.messages),o=new Map(t.typingMessages);return i.isDebug&&!r.showDebugMessage?new g({messages:u,typingMessages:o}):(u.set(i.messageId,{type:"bot",eventType:m.MESSAGE_COMPLETE,isTyping:!1,typingText:null,messageId:i.messageId,message:i,time:new Date}),o.delete(i.messageId),new g({messages:u,typingMessages:o}))}onMessageDone(t){const e=new Map(t.messages),r=new Map(t.typingMessages);return r.forEach((i,u)=>{i.eventType===m.MESSAGE_COMPLETE&&(e.set(i.messageId,i),r.delete(u))}),new g({messages:t.messages,typingMessages:r})}}exports.AsgardServiceClient=Ln;exports.Conversation=g;exports.EventType=m;exports.FetchSseAction=N;exports.MessageTemplateType=oe;
5
5
  //# sourceMappingURL=index.cjs.map