@asgard-js/core 0.0.5 → 0.0.6

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.
@@ -7,7 +7,8 @@ export declare enum EventType {
7
7
  MESSAGE_START = "asgard.message.start",
8
8
  MESSAGE_DELTA = "asgard.message.delta",
9
9
  MESSAGE_COMPLETE = "asgard.message.complete",
10
- DONE = "asgard.run.done"
10
+ DONE = "asgard.run.done",
11
+ ERROR = "asgard.run.error"
11
12
  }
12
13
  export declare enum MessageTemplateType {
13
14
  TEXT = "TEXT",
@@ -1 +1 @@
1
- {"version":3,"file":"enum.d.ts","sourceRoot":"","sources":["../../src/constants/enum.ts"],"names":[],"mappings":"AAAA,oBAAY,cAAc;IACxB,aAAa,kBAAkB;IAC/B,IAAI,SAAS;CACd;AAED,oBAAY,SAAS;IACnB,IAAI,oBAAoB;IACxB,aAAa,yBAAyB;IACtC,aAAa,yBAAyB;IACtC,gBAAgB,4BAA4B;IAC5C,IAAI,oBAAoB;CACzB;AAED,oBAAY,mBAAmB;IAC7B,IAAI,SAAS;IACb,IAAI,SAAS;IACb,MAAM,WAAW;IACjB,KAAK,UAAU;IACf,KAAK,UAAU;IACf,KAAK,UAAU;IACf,QAAQ,aAAa;IACrB,QAAQ,aAAa;CACtB"}
1
+ {"version":3,"file":"enum.d.ts","sourceRoot":"","sources":["../../src/constants/enum.ts"],"names":[],"mappings":"AAAA,oBAAY,cAAc;IACxB,aAAa,kBAAkB;IAC/B,IAAI,SAAS;CACd;AAED,oBAAY,SAAS;IACnB,IAAI,oBAAoB;IACxB,aAAa,yBAAyB;IACtC,aAAa,yBAAyB;IACtC,gBAAgB,4BAA4B;IAC5C,IAAI,oBAAoB;IACxB,KAAK,qBAAqB;CAC3B;AAED,oBAAY,mBAAmB;IAC7B,IAAI,SAAS;IACb,IAAI,SAAS;IACb,MAAM,WAAW;IACjB,KAAK,UAAU;IACf,KAAK,UAAU;IACf,KAAK,UAAU;IACf,QAAQ,aAAa;IACrB,QAAQ,aAAa;CACtB"}
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
- "use strict";var $e=Object.defineProperty;var Re=(t,r,e)=>r in t?$e(t,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[r]=e;var m=(t,r,e)=>Re(t,typeof r!="symbol"?r+"":r,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var R=(t=>(t.RESET_CHANNEL="RESET_CHANNEL",t.NONE="NONE",t))(R||{}),S=(t=>(t.INIT="asgard.run.init",t.MESSAGE_START="asgard.message.start",t.MESSAGE_DELTA="asgard.message.delta",t.MESSAGE_COMPLETE="asgard.message.complete",t.DONE="asgard.run.done",t))(S||{}),le=(t=>(t.TEXT="TEXT",t.HINT="HINT",t.BUTTON="BUTTON",t.IMAGE="IMAGE",t.VIDEO="VIDEO",t.AUDIO="AUDIO",t.LOCATION="LOCATION",t.CAROUSEL="CAROUSEL",t))(le||{}),q=function(t,r){return q=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,n){e.__proto__=n}||function(e,n){for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])},q(t,r)};function I(t,r){if(typeof r!="function"&&r!==null)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");q(t,r);function e(){this.constructor=t}t.prototype=r===null?Object.create(r):(e.prototype=r.prototype,new e)}function Ue(t,r,e,n){function i(o){return o instanceof e?o:new e(function(s){s(o)})}return new(e||(e=Promise))(function(o,s){function c(f){try{a(n.next(f))}catch(d){s(d)}}function u(f){try{a(n.throw(f))}catch(d){s(d)}}function a(f){f.done?o(f.value):i(f.value).then(c,u)}a((n=n.apply(t,r||[])).next())})}function fe(t,r){var e={label:0,sent:function(){if(o[0]&1)throw o[1];return o[1]},trys:[],ops:[]},n,i,o,s=Object.create((typeof Iterator=="function"?Iterator:Object).prototype);return s.next=c(0),s.throw=c(1),s.return=c(2),typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function c(a){return function(f){return u([a,f])}}function u(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(e=0)),e;)try{if(n=1,i&&(o=a[0]&2?i.return:a[0]?i.throw||((o=i.return)&&o.call(i),0):i.next)&&!(o=o.call(i,a[1])).done)return o;switch(i=0,o&&(a=[a[0]&2,o.value]),a[0]){case 0:case 1:o=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(o=e.trys,!(o=o.length>0&&o[o.length-1])&&(a[0]===6||a[0]===2)){e=0;continue}if(a[0]===3&&(!o||a[1]>o[0]&&a[1]<o[3])){e.label=a[1];break}if(a[0]===6&&e.label<o[1]){e.label=o[1],o=a;break}if(o&&e.label<o[2]){e.label=o[2],e.ops.push(a);break}o[2]&&e.ops.pop(),e.trys.pop();continue}a=r.call(t,e)}catch(f){a=[6,f],i=0}finally{n=o=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}}function P(t){var r=typeof Symbol=="function"&&Symbol.iterator,e=r&&t[r],n=0;if(e)return e.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(r?"Object is not iterable.":"Symbol.iterator is not defined.")}function M(t,r){var e=typeof Symbol=="function"&&t[Symbol.iterator];if(!e)return t;var n=e.call(t),i,o=[],s;try{for(;(r===void 0||r-- >0)&&!(i=n.next()).done;)o.push(i.value)}catch(c){s={error:c}}finally{try{i&&!i.done&&(e=n.return)&&e.call(n)}finally{if(s)throw s.error}}return o}function k(t,r,e){if(e||arguments.length===2)for(var n=0,i=r.length,o;n<i;n++)(o||!(n in r))&&(o||(o=Array.prototype.slice.call(r,0,n)),o[n]=r[n]);return t.concat(o||Array.prototype.slice.call(r))}function T(t){return this instanceof T?(this.v=t,this):new T(t)}function Ne(t,r,e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=e.apply(t,r||[]),i,o=[];return i=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),c("next"),c("throw"),c("return",s),i[Symbol.asyncIterator]=function(){return this},i;function s(l){return function(v){return Promise.resolve(v).then(l,d)}}function c(l,v){n[l]&&(i[l]=function(h){return new Promise(function(g,w){o.push([l,h,g,w])>1||u(l,h)})},v&&(i[l]=v(i[l])))}function u(l,v){try{a(n[l](v))}catch(h){p(o[0][3],h)}}function a(l){l.value instanceof T?Promise.resolve(l.value.v).then(f,d):p(o[0][2],l)}function f(l){u("next",l)}function d(l){u("throw",l)}function p(l,v){l(v),o.shift(),o.length&&u(o[0][0],o[0][1])}}function Ge(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r=t[Symbol.asyncIterator],e;return r?r.call(t):(t=typeof P=="function"?P(t):t[Symbol.iterator](),e={},n("next"),n("throw"),n("return"),e[Symbol.asyncIterator]=function(){return this},e);function n(o){e[o]=t[o]&&function(s){return new Promise(function(c,u){s=t[o](s),i(c,u,s.done,s.value)})}}function i(o,s,c,u){Promise.resolve(u).then(function(a){o({value:a,done:c})},s)}}function y(t){return typeof t=="function"}function he(t){var r=function(n){Error.call(n),n.stack=new Error().stack},e=t(r);return e.prototype=Object.create(Error.prototype),e.prototype.constructor=e,e}var H=he(function(t){return function(e){t(this),this.message=e?e.length+` errors occurred during unsubscription:
1
+ "use strict";var Le=Object.defineProperty;var Ue=(t,r,e)=>r in t?Le(t,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[r]=e;var b=(t,r,e)=>Ue(t,typeof r!="symbol"?r+"":r,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var U=(t=>(t.RESET_CHANNEL="RESET_CHANNEL",t.NONE="NONE",t))(U||{}),g=(t=>(t.INIT="asgard.run.init",t.MESSAGE_START="asgard.message.start",t.MESSAGE_DELTA="asgard.message.delta",t.MESSAGE_COMPLETE="asgard.message.complete",t.DONE="asgard.run.done",t.ERROR="asgard.run.error",t))(g||{}),le=(t=>(t.TEXT="TEXT",t.HINT="HINT",t.BUTTON="BUTTON",t.IMAGE="IMAGE",t.VIDEO="VIDEO",t.AUDIO="AUDIO",t.LOCATION="LOCATION",t.CAROUSEL="CAROUSEL",t))(le||{}),q=function(t,r){return q=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,n){e.__proto__=n}||function(e,n){for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])},q(t,r)};function I(t,r){if(typeof r!="function"&&r!==null)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");q(t,r);function e(){this.constructor=t}t.prototype=r===null?Object.create(r):(e.prototype=r.prototype,new e)}function $e(t,r,e,n){function i(o){return o instanceof e?o:new e(function(s){s(o)})}return new(e||(e=Promise))(function(o,s){function c(f){try{a(n.next(f))}catch(d){s(d)}}function u(f){try{a(n.throw(f))}catch(d){s(d)}}function a(f){f.done?o(f.value):i(f.value).then(c,u)}a((n=n.apply(t,r||[])).next())})}function fe(t,r){var e={label:0,sent:function(){if(o[0]&1)throw o[1];return o[1]},trys:[],ops:[]},n,i,o,s=Object.create((typeof Iterator=="function"?Iterator:Object).prototype);return s.next=c(0),s.throw=c(1),s.return=c(2),typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function c(a){return function(f){return u([a,f])}}function u(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(e=0)),e;)try{if(n=1,i&&(o=a[0]&2?i.return:a[0]?i.throw||((o=i.return)&&o.call(i),0):i.next)&&!(o=o.call(i,a[1])).done)return o;switch(i=0,o&&(a=[a[0]&2,o.value]),a[0]){case 0:case 1:o=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(o=e.trys,!(o=o.length>0&&o[o.length-1])&&(a[0]===6||a[0]===2)){e=0;continue}if(a[0]===3&&(!o||a[1]>o[0]&&a[1]<o[3])){e.label=a[1];break}if(a[0]===6&&e.label<o[1]){e.label=o[1],o=a;break}if(o&&e.label<o[2]){e.label=o[2],e.ops.push(a);break}o[2]&&e.ops.pop(),e.trys.pop();continue}a=r.call(t,e)}catch(f){a=[6,f],i=0}finally{n=o=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}}function P(t){var r=typeof Symbol=="function"&&Symbol.iterator,e=r&&t[r],n=0;if(e)return e.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(r?"Object is not iterable.":"Symbol.iterator is not defined.")}function M(t,r){var e=typeof Symbol=="function"&&t[Symbol.iterator];if(!e)return t;var n=e.call(t),i,o=[],s;try{for(;(r===void 0||r-- >0)&&!(i=n.next()).done;)o.push(i.value)}catch(c){s={error:c}}finally{try{i&&!i.done&&(e=n.return)&&e.call(n)}finally{if(s)throw s.error}}return o}function k(t,r,e){if(e||arguments.length===2)for(var n=0,i=r.length,o;n<i;n++)(o||!(n in r))&&(o||(o=Array.prototype.slice.call(r,0,n)),o[n]=r[n]);return t.concat(o||Array.prototype.slice.call(r))}function C(t){return this instanceof C?(this.v=t,this):new C(t)}function Ne(t,r,e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=e.apply(t,r||[]),i,o=[];return i=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),c("next"),c("throw"),c("return",s),i[Symbol.asyncIterator]=function(){return this},i;function s(l){return function(v){return Promise.resolve(v).then(l,d)}}function c(l,v){n[l]&&(i[l]=function(h){return new Promise(function(w,S){o.push([l,h,w,S])>1||u(l,h)})},v&&(i[l]=v(i[l])))}function u(l,v){try{a(n[l](v))}catch(h){p(o[0][3],h)}}function a(l){l.value instanceof C?Promise.resolve(l.value.v).then(f,d):p(o[0][2],l)}function f(l){u("next",l)}function d(l){u("throw",l)}function p(l,v){l(v),o.shift(),o.length&&u(o[0][0],o[0][1])}}function Ge(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r=t[Symbol.asyncIterator],e;return r?r.call(t):(t=typeof P=="function"?P(t):t[Symbol.iterator](),e={},n("next"),n("throw"),n("return"),e[Symbol.asyncIterator]=function(){return this},e);function n(o){e[o]=t[o]&&function(s){return new Promise(function(c,u){s=t[o](s),i(c,u,s.done,s.value)})}}function i(o,s,c,u){Promise.resolve(u).then(function(a){o({value:a,done:c})},s)}}function y(t){return typeof t=="function"}function he(t){var r=function(n){Error.call(n),n.stack=new Error().stack},e=t(r);return e.prototype=Object.create(Error.prototype),e.prototype.constructor=e,e}var H=he(function(t){return function(e){t(this),this.message=e?e.length+` errors occurred during unsubscription:
2
2
  `+e.map(function(n,i){return i+1+") "+n.toString()}).join(`
3
- `):"",this.name="UnsubscriptionError",this.errors=e}});function U(t,r){if(t){var e=t.indexOf(r);0<=e&&t.splice(e,1)}}var j=function(){function t(r){this.initialTeardown=r,this.closed=!1,this._parentage=null,this._finalizers=null}return t.prototype.unsubscribe=function(){var r,e,n,i,o;if(!this.closed){this.closed=!0;var s=this._parentage;if(s)if(this._parentage=null,Array.isArray(s))try{for(var c=P(s),u=c.next();!u.done;u=c.next()){var a=u.value;a.remove(this)}}catch(h){r={error:h}}finally{try{u&&!u.done&&(e=c.return)&&e.call(c)}finally{if(r)throw r.error}}else s.remove(this);var f=this.initialTeardown;if(y(f))try{f()}catch(h){o=h instanceof H?h.errors:[h]}var d=this._finalizers;if(d){this._finalizers=null;try{for(var p=P(d),l=p.next();!l.done;l=p.next()){var v=l.value;try{te(v)}catch(h){o=o??[],h instanceof H?o=k(k([],M(o)),M(h.errors)):o.push(h)}}}catch(h){n={error:h}}finally{try{l&&!l.done&&(i=p.return)&&i.call(p)}finally{if(n)throw n.error}}}if(o)throw new H(o)}},t.prototype.add=function(r){var e;if(r&&r!==this)if(this.closed)te(r);else{if(r instanceof t){if(r.closed||r._hasParent(this))return;r._addParent(this)}(this._finalizers=(e=this._finalizers)!==null&&e!==void 0?e:[]).push(r)}},t.prototype._hasParent=function(r){var e=this._parentage;return e===r||Array.isArray(e)&&e.includes(r)},t.prototype._addParent=function(r){var e=this._parentage;this._parentage=Array.isArray(e)?(e.push(r),e):e?[e,r]:r},t.prototype._removeParent=function(r){var e=this._parentage;e===r?this._parentage=null:Array.isArray(e)&&U(e,r)},t.prototype.remove=function(r){var e=this._finalizers;e&&U(e,r),r instanceof t&&r._removeParent(this)},t.EMPTY=function(){var r=new t;return r.closed=!0,r}(),t}(),de=j.EMPTY;function ve(t){return t instanceof j||t&&"closed"in t&&y(t.remove)&&y(t.add)&&y(t.unsubscribe)}function te(t){y(t)?t():t.unsubscribe()}var Fe={Promise:void 0},Ve={setTimeout:function(t,r){for(var e=[],n=2;n<arguments.length;n++)e[n-2]=arguments[n];return setTimeout.apply(void 0,k([t,r],M(e)))},clearTimeout:function(t){return clearTimeout(t)},delegate:void 0};function ye(t){Ve.setTimeout(function(){throw t})}function B(){}function $(t){t()}var J=function(t){I(r,t);function r(e){var n=t.call(this)||this;return n.isStopped=!1,e?(n.destination=e,ve(e)&&e.add(n)):n.destination=qe,n}return r.create=function(e,n,i){return new Y(e,n,i)},r.prototype.next=function(e){this.isStopped||this._next(e)},r.prototype.error=function(e){this.isStopped||(this.isStopped=!0,this._error(e))},r.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},r.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,t.prototype.unsubscribe.call(this),this.destination=null)},r.prototype._next=function(e){this.destination.next(e)},r.prototype._error=function(e){try{this.destination.error(e)}finally{this.unsubscribe()}},r.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},r}(j),Ke=function(){function t(r){this.partialObserver=r}return t.prototype.next=function(r){var e=this.partialObserver;if(e.next)try{e.next(r)}catch(n){L(n)}},t.prototype.error=function(r){var e=this.partialObserver;if(e.error)try{e.error(r)}catch(n){L(n)}else L(r)},t.prototype.complete=function(){var r=this.partialObserver;if(r.complete)try{r.complete()}catch(e){L(e)}},t}(),Y=function(t){I(r,t);function r(e,n,i){var o=t.call(this)||this,s;return y(e)||!e?s={next:e??void 0,error:n??void 0,complete:i??void 0}:s=e,o.destination=new Ke(s),o}return r}(J);function L(t){ye(t)}function He(t){throw t}var qe={closed:!0,next:B,error:He,complete:B},X=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();function G(t){return t}function Be(t){return t.length===0?G:t.length===1?t[0]:function(e){return t.reduce(function(n,i){return i(n)},e)}}var b=function(){function t(r){r&&(this._subscribe=r)}return t.prototype.lift=function(r){var e=new t;return e.source=this,e.operator=r,e},t.prototype.subscribe=function(r,e,n){var i=this,o=We(r)?r:new Y(r,e,n);return $(function(){var s=i,c=s.operator,u=s.source;o.add(c?c.call(o,u):u?i._subscribe(o):i._trySubscribe(o))}),o},t.prototype._trySubscribe=function(r){try{return this._subscribe(r)}catch(e){r.error(e)}},t.prototype.forEach=function(r,e){var n=this;return e=re(e),new e(function(i,o){var s=new Y({next:function(c){try{r(c)}catch(u){o(u),s.unsubscribe()}},error:o,complete:i});n.subscribe(s)})},t.prototype._subscribe=function(r){var e;return(e=this.source)===null||e===void 0?void 0:e.subscribe(r)},t.prototype[X]=function(){return this},t.prototype.pipe=function(){for(var r=[],e=0;e<arguments.length;e++)r[e]=arguments[e];return Be(r)(this)},t.prototype.toPromise=function(r){var e=this;return r=re(r),new r(function(n,i){var o;e.subscribe(function(s){return o=s},function(s){return i(s)},function(){return n(o)})})},t.create=function(r){return new t(r)},t}();function re(t){var r;return(r=t??Fe.Promise)!==null&&r!==void 0?r:Promise}function Ye(t){return t&&y(t.next)&&y(t.error)&&y(t.complete)}function We(t){return t&&t instanceof J||Ye(t)&&ve(t)}function Je(t){return y(t==null?void 0:t.lift)}function C(t){return function(r){if(Je(r))return r.lift(function(e){try{return t(e,this)}catch(n){this.error(n)}});throw new TypeError("Unable to lift unknown Observable type")}}function E(t,r,e,n,i){return new Xe(t,r,e,n,i)}var Xe=function(t){I(r,t);function r(e,n,i,o,s,c){var u=t.call(this,e)||this;return u.onFinalize=s,u.shouldUnsubscribe=c,u._next=n?function(a){try{n(a)}catch(f){e.error(f)}}:t.prototype._next,u._error=o?function(a){try{o(a)}catch(f){e.error(f)}finally{this.unsubscribe()}}:t.prototype._error,u._complete=i?function(){try{i()}catch(a){e.error(a)}finally{this.unsubscribe()}}:t.prototype._complete,u}return r.prototype.unsubscribe=function(){var e;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var n=this.closed;t.prototype.unsubscribe.call(this),!n&&((e=this.onFinalize)===null||e===void 0||e.call(this))}},r}(J),ze=he(function(t){return function(){t(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}}),z=function(t){I(r,t);function r(){var e=t.call(this)||this;return e.closed=!1,e.currentObservers=null,e.observers=[],e.isStopped=!1,e.hasError=!1,e.thrownError=null,e}return r.prototype.lift=function(e){var n=new ne(this,this);return n.operator=e,n},r.prototype._throwIfClosed=function(){if(this.closed)throw new ze},r.prototype.next=function(e){var n=this;$(function(){var i,o;if(n._throwIfClosed(),!n.isStopped){n.currentObservers||(n.currentObservers=Array.from(n.observers));try{for(var s=P(n.currentObservers),c=s.next();!c.done;c=s.next()){var u=c.value;u.next(e)}}catch(a){i={error:a}}finally{try{c&&!c.done&&(o=s.return)&&o.call(s)}finally{if(i)throw i.error}}}})},r.prototype.error=function(e){var n=this;$(function(){if(n._throwIfClosed(),!n.isStopped){n.hasError=n.isStopped=!0,n.thrownError=e;for(var i=n.observers;i.length;)i.shift().error(e)}})},r.prototype.complete=function(){var e=this;$(function(){if(e._throwIfClosed(),!e.isStopped){e.isStopped=!0;for(var n=e.observers;n.length;)n.shift().complete()}})},r.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(r.prototype,"observed",{get:function(){var e;return((e=this.observers)===null||e===void 0?void 0:e.length)>0},enumerable:!1,configurable:!0}),r.prototype._trySubscribe=function(e){return this._throwIfClosed(),t.prototype._trySubscribe.call(this,e)},r.prototype._subscribe=function(e){return this._throwIfClosed(),this._checkFinalizedStatuses(e),this._innerSubscribe(e)},r.prototype._innerSubscribe=function(e){var n=this,i=this,o=i.hasError,s=i.isStopped,c=i.observers;return o||s?de:(this.currentObservers=null,c.push(e),new j(function(){n.currentObservers=null,U(c,e)}))},r.prototype._checkFinalizedStatuses=function(e){var n=this,i=n.hasError,o=n.thrownError,s=n.isStopped;i?e.error(o):s&&e.complete()},r.prototype.asObservable=function(){var e=new b;return e.source=this,e},r.create=function(e,n){return new ne(e,n)},r}(b),ne=function(t){I(r,t);function r(e,n){var i=t.call(this)||this;return i.destination=e,i.source=n,i}return r.prototype.next=function(e){var n,i;(i=(n=this.destination)===null||n===void 0?void 0:n.next)===null||i===void 0||i.call(n,e)},r.prototype.error=function(e){var n,i;(i=(n=this.destination)===null||n===void 0?void 0:n.error)===null||i===void 0||i.call(n,e)},r.prototype.complete=function(){var e,n;(n=(e=this.destination)===null||e===void 0?void 0:e.complete)===null||n===void 0||n.call(e)},r.prototype._subscribe=function(e){var n,i;return(i=(n=this.source)===null||n===void 0?void 0:n.subscribe(e))!==null&&i!==void 0?i:de},r}(z),ie=function(t){I(r,t);function r(e){var n=t.call(this)||this;return n._value=e,n}return Object.defineProperty(r.prototype,"value",{get:function(){return this.getValue()},enumerable:!1,configurable:!0}),r.prototype._subscribe=function(e){var n=t.prototype._subscribe.call(this,e);return!n.closed&&e.next(this._value),n},r.prototype.getValue=function(){var e=this,n=e.hasError,i=e.thrownError,o=e._value;if(n)throw i;return this._throwIfClosed(),o},r.prototype.next=function(e){t.prototype.next.call(this,this._value=e)},r}(z),Qe={now:function(){return Date.now()}},Ze=function(t){I(r,t);function r(e,n){return t.call(this)||this}return r.prototype.schedule=function(e,n){return this},r}(j),oe={setInterval:function(t,r){for(var e=[],n=2;n<arguments.length;n++)e[n-2]=arguments[n];return setInterval.apply(void 0,k([t,r],M(e)))},clearInterval:function(t){return clearInterval(t)},delegate:void 0},et=function(t){I(r,t);function r(e,n){var i=t.call(this,e,n)||this;return i.scheduler=e,i.work=n,i.pending=!1,i}return r.prototype.schedule=function(e,n){var i;if(n===void 0&&(n=0),this.closed)return this;this.state=e;var o=this.id,s=this.scheduler;return o!=null&&(this.id=this.recycleAsyncId(s,o,n)),this.pending=!0,this.delay=n,this.id=(i=this.id)!==null&&i!==void 0?i:this.requestAsyncId(s,this.id,n),this},r.prototype.requestAsyncId=function(e,n,i){return i===void 0&&(i=0),oe.setInterval(e.flush.bind(e,this),i)},r.prototype.recycleAsyncId=function(e,n,i){if(i===void 0&&(i=0),i!=null&&this.delay===i&&this.pending===!1)return n;n!=null&&oe.clearInterval(n)},r.prototype.execute=function(e,n){if(this.closed)return new Error("executing a cancelled action");this.pending=!1;var i=this._execute(e,n);if(i)return i;this.pending===!1&&this.id!=null&&(this.id=this.recycleAsyncId(this.scheduler,this.id,null))},r.prototype._execute=function(e,n){var i=!1,o;try{this.work(e)}catch(s){i=!0,o=s||new Error("Scheduled action threw falsy error")}if(i)return this.unsubscribe(),o},r.prototype.unsubscribe=function(){if(!this.closed){var e=this,n=e.id,i=e.scheduler,o=i.actions;this.work=this.state=this.scheduler=null,this.pending=!1,U(o,this),n!=null&&(this.id=this.recycleAsyncId(i,n,null)),this.delay=null,t.prototype.unsubscribe.call(this)}},r}(Ze),se=function(){function t(r,e){e===void 0&&(e=t.now),this.schedulerActionCtor=r,this.now=e}return t.prototype.schedule=function(r,e,n){return e===void 0&&(e=0),new this.schedulerActionCtor(this,r).schedule(n,e)},t.now=Qe.now,t}(),tt=function(t){I(r,t);function r(e,n){n===void 0&&(n=se.now);var i=t.call(this,e,n)||this;return i.actions=[],i._active=!1,i}return r.prototype.flush=function(e){var n=this.actions;if(this._active){n.push(e);return}var i;this._active=!0;do if(i=e.execute(e.state,e.delay))break;while(e=n.shift());if(this._active=!1,i){for(;e=n.shift();)e.unsubscribe();throw i}},r}(se),pe=new tt(et),rt=pe,nt=new b(function(t){return t.complete()});function be(t){return t&&y(t.schedule)}function me(t){return t[t.length-1]}function it(t){return y(me(t))?t.pop():void 0}function ge(t){return be(me(t))?t.pop():void 0}var we=function(t){return t&&typeof t.length=="number"&&typeof t!="function"};function Se(t){return y(t==null?void 0:t.then)}function Ee(t){return y(t[X])}function Ie(t){return Symbol.asyncIterator&&y(t==null?void 0:t[Symbol.asyncIterator])}function Oe(t){return new TypeError("You provided "+(t!==null&&typeof t=="object"?"an invalid object":"'"+t+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}function ot(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}var Ae=ot();function xe(t){return y(t==null?void 0:t[Ae])}function _e(t){return Ne(this,arguments,function(){var e,n,i,o;return fe(this,function(s){switch(s.label){case 0:e=t.getReader(),s.label=1;case 1:s.trys.push([1,,9,10]),s.label=2;case 2:return[4,T(e.read())];case 3:return n=s.sent(),i=n.value,o=n.done,o?[4,T(void 0)]:[3,5];case 4:return[2,s.sent()];case 5:return[4,T(i)];case 6:return[4,s.sent()];case 7:return s.sent(),[3,2];case 8:return[3,10];case 9:return e.releaseLock(),[7];case 10:return[2]}})})}function Ce(t){return y(t==null?void 0:t.getReader)}function x(t){if(t instanceof b)return t;if(t!=null){if(Ee(t))return st(t);if(we(t))return at(t);if(Se(t))return ut(t);if(Ie(t))return Te(t);if(xe(t))return ct(t);if(Ce(t))return lt(t)}throw Oe(t)}function st(t){return new b(function(r){var e=t[X]();if(y(e.subscribe))return e.subscribe(r);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function at(t){return new b(function(r){for(var e=0;e<t.length&&!r.closed;e++)r.next(t[e]);r.complete()})}function ut(t){return new b(function(r){t.then(function(e){r.closed||(r.next(e),r.complete())},function(e){return r.error(e)}).then(null,ye)})}function ct(t){return new b(function(r){var e,n;try{for(var i=P(t),o=i.next();!o.done;o=i.next()){var s=o.value;if(r.next(s),r.closed)return}}catch(c){e={error:c}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}r.complete()})}function Te(t){return new b(function(r){ft(t,r).catch(function(e){return r.error(e)})})}function lt(t){return Te(_e(t))}function ft(t,r){var e,n,i,o;return Ue(this,void 0,void 0,function(){var s,c;return fe(this,function(u){switch(u.label){case 0:u.trys.push([0,5,6,11]),e=Ge(t),u.label=1;case 1:return[4,e.next()];case 2:if(n=u.sent(),!!n.done)return[3,4];if(s=n.value,r.next(s),r.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]),n&&!n.done&&(o=e.return)?[4,o.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 r.complete(),[2]}})})}function A(t,r,e,n,i){n===void 0&&(n=0),i===void 0&&(i=!1);var o=r.schedule(function(){e(),i?t.add(this.schedule(null,n)):this.unsubscribe()},n);if(t.add(o),!i)return o}function Pe(t,r){return r===void 0&&(r=0),C(function(e,n){e.subscribe(E(n,function(i){return A(n,t,function(){return n.next(i)},r)},function(){return A(n,t,function(){return n.complete()},r)},function(i){return A(n,t,function(){return n.error(i)},r)}))})}function Me(t,r){return r===void 0&&(r=0),C(function(e,n){n.add(t.schedule(function(){return e.subscribe(n)},r))})}function ht(t,r){return x(t).pipe(Me(r),Pe(r))}function dt(t,r){return x(t).pipe(Me(r),Pe(r))}function vt(t,r){return new b(function(e){var n=0;return r.schedule(function(){n===t.length?e.complete():(e.next(t[n++]),e.closed||this.schedule())})})}function yt(t,r){return new b(function(e){var n;return A(e,r,function(){n=t[Ae](),A(e,r,function(){var i,o,s;try{i=n.next(),o=i.value,s=i.done}catch(c){e.error(c);return}s?e.complete():e.next(o)},0,!0)}),function(){return y(n==null?void 0:n.return)&&n.return()}})}function ke(t,r){if(!t)throw new Error("Iterable cannot be null");return new b(function(e){A(e,r,function(){var n=t[Symbol.asyncIterator]();A(e,r,function(){n.next().then(function(i){i.done?e.complete():e.next(i.value)})},0,!0)})})}function pt(t,r){return ke(_e(t),r)}function bt(t,r){if(t!=null){if(Ee(t))return ht(t,r);if(we(t))return vt(t,r);if(Se(t))return dt(t,r);if(Ie(t))return ke(t,r);if(xe(t))return yt(t,r);if(Ce(t))return pt(t,r)}throw Oe(t)}function Q(t,r){return r?bt(t,r):x(t)}function mt(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];var e=ge(t);return Q(t,e)}function gt(t){return t instanceof Date&&!isNaN(t)}function F(t,r){return C(function(e,n){var i=0;e.subscribe(E(n,function(o){n.next(t.call(r,o,i++))}))})}var wt=Array.isArray;function St(t,r){return wt(r)?t.apply(void 0,k([],M(r))):t(r)}function Et(t){return F(function(r){return St(t,r)})}var It=Array.isArray,Ot=Object.getPrototypeOf,At=Object.prototype,xt=Object.keys;function _t(t){if(t.length===1){var r=t[0];if(It(r))return{args:r,keys:null};if(Ct(r)){var e=xt(r);return{args:e.map(function(n){return r[n]}),keys:e}}}return{args:t,keys:null}}function Ct(t){return t&&typeof t=="object"&&Ot(t)===At}function Tt(t,r){return t.reduce(function(e,n,i){return e[n]=r[i],e},{})}function Pt(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];var e=ge(t),n=it(t),i=_t(t),o=i.args,s=i.keys;if(o.length===0)return Q([],e);var c=new b(Mt(o,e,s?function(u){return Tt(s,u)}:G));return n?c.pipe(Et(n)):c}function Mt(t,r,e){return e===void 0&&(e=G),function(n){ae(r,function(){for(var i=t.length,o=new Array(i),s=i,c=i,u=function(f){ae(r,function(){var d=Q(t[f],r),p=!1;d.subscribe(E(n,function(l){o[f]=l,p||(p=!0,c--),c||n.next(e(o.slice()))},function(){--s||n.complete()}))},n)},a=0;a<i;a++)u(a)},n)}}function ae(t,r,e){t?A(e,t,r):r()}function kt(t,r,e,n,i,o,s,c){var u=[],a=0,f=0,d=!1,p=function(){d&&!u.length&&!a&&r.complete()},l=function(h){return a<n?v(h):u.push(h)},v=function(h){a++;var g=!1;x(e(h,f++)).subscribe(E(r,function(w){r.next(w)},function(){g=!0},void 0,function(){if(g)try{a--;for(var w=function(){var _=u.shift();s||v(_)};u.length&&a<n;)w();p()}catch(_){r.error(_)}}))};return t.subscribe(E(r,l,function(){d=!0,p()})),function(){}}function N(t,r,e){return e===void 0&&(e=1/0),y(r)?N(function(n,i){return F(function(o,s){return r(n,o,i,s)})(x(t(n,i)))},e):(typeof r=="number"&&(e=r),C(function(n,i){return kt(n,i,t,e)}))}function je(t,r,e){t===void 0&&(t=0),e===void 0&&(e=rt);var n=-1;return r!=null&&(be(r)?e=r:n=r),new b(function(i){var o=gt(t)?+t-e.now():t;o<0&&(o=0);var s=0;return e.schedule(function(){i.closed||(i.next(s++),0<=n?this.schedule(void 0,n):i.complete())},o)})}function jt(t,r){return y(r)?N(t,r,1):N(t,1)}function Dt(t){return t<=0?function(){return nt}:C(function(r,e){var n=0;r.subscribe(E(e,function(i){++n<=t&&(e.next(i),t<=n&&e.complete())}))})}function Lt(t){return F(function(){return t})}function $t(t,r){return N(function(e,n){return x(t(e,n)).pipe(Dt(1),Lt(e))})}function Rt(t,r){r===void 0&&(r=pe);var e=je(t,r);return $t(function(){return e})}function Ut(t){var r;r={count:t};var e=r.count,n=e===void 0?1/0:e,i=r.delay,o=r.resetOnSuccess,s=o===void 0?!1:o;return n<=0?G:C(function(c,u){var a=0,f,d=function(){var p=!1;f=c.subscribe(E(u,function(l){s&&(a=0),u.next(l)},void 0,function(l){if(a++<n){var v=function(){f?(f.unsubscribe(),f=null,d()):p=!0};if(i!=null){var h=typeof i=="number"?je(i):x(i(l,a)),g=E(u,function(){g.unsubscribe(),v()},function(){u.complete()});h.subscribe(g)}else v()}else u.error(l)})),p&&(f.unsubscribe(),f=null,d())};d()})}function Nt(t){return C(function(r,e){x(t).subscribe(E(e,function(){return e.complete()},B)),!e.closed&&r.subscribe(e)})}async function Gt(t,r){const e=t.getReader();let n;for(;!(n=await e.read()).done;)r(n.value)}function Ft(t){let r,e,n,i=!1;return function(s){r===void 0?(r=s,e=0,n=-1):r=Kt(r,s);const c=r.length;let u=0;for(;e<c;){i&&(r[e]===10&&(u=++e),i=!1);let a=-1;for(;e<c&&a===-1;++e)switch(r[e]){case 58:n===-1&&(n=e-u);break;case 13:i=!0;case 10:a=e;break}if(a===-1)break;t(r.subarray(u,a),n),u=e,n=-1}u===c?r=void 0:u!==0&&(r=r.subarray(u),e-=u)}}function Vt(t,r,e){let n=ue();const i=new TextDecoder;return function(s,c){if(s.length===0)e==null||e(n),n=ue();else if(c>0){const u=i.decode(s.subarray(0,c)),a=c+(s[c+1]===32?2:1),f=i.decode(s.subarray(a));switch(u){case"data":n.data=n.data?n.data+`
4
- `+f:f;break;case"event":n.event=f;break;case"id":t(n.id=f);break;case"retry":const d=parseInt(f,10);isNaN(d)||r(n.retry=d);break}}}}function Kt(t,r){const e=new Uint8Array(t.length+r.length);return e.set(t),e.set(r,t.length),e}function ue(){return{data:"",event:"",id:"",retry:void 0}}var Ht=function(t,r){var e={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&r.indexOf(n)<0&&(e[n]=t[n]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(t);i<n.length;i++)r.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(e[n[i]]=t[n[i]]);return e};const W="text/event-stream",qt=1e3,ce="last-event-id";function Bt(t,r){var{signal:e,headers:n,onopen:i,onmessage:o,onclose:s,onerror:c,openWhenHidden:u,fetch:a}=r,f=Ht(r,["signal","headers","onopen","onmessage","onclose","onerror","openWhenHidden","fetch"]);return new Promise((d,p)=>{const l=Object.assign({},n);l.accept||(l.accept=W);let v;function h(){v.abort(),document.hidden||V()}u||document.addEventListener("visibilitychange",h);let g=qt,w=0;function _(){document.removeEventListener("visibilitychange",h),window.clearTimeout(w),v.abort()}e==null||e.addEventListener("abort",()=>{_(),d()});const De=a??window.fetch,Le=i??Yt;async function V(){var K;v=new AbortController;try{const D=await De(t,Object.assign(Object.assign({},f),{headers:l,signal:v.signal}));await Le(D),await Gt(D.body,Ft(Vt(O=>{O?l[ce]=O:delete l[ce]},O=>{g=O},o))),s==null||s(),_(),d()}catch(D){if(!v.signal.aborted)try{const O=(K=c==null?void 0:c(D))!==null&&K!==void 0?K:g;window.clearTimeout(w),w=window.setTimeout(V,O)}catch(O){_(),p(O)}}}V()})}function Yt(t){const r=t.headers.get("content-type");if(!(r!=null&&r.startsWith(W)))throw new Error(`Expected content-type to be ${W}, Actual: ${r}`)}function Wt(t){const{endpoint:r,apiKey:e,payload:n}=t;return new b(i=>{const o=new AbortController;return Bt(r,{method:"POST",headers:{"X-API-KEY":e,"Content-Type":"application/json"},body:n?JSON.stringify(n):void 0,signal:o.signal,onopen:async s=>{s.ok||(i.error(s),o.abort())},onmessage:s=>{i.next(JSON.parse(s.data))},onclose:()=>{i.complete()},onerror:s=>{throw i.error(s),o.abort(),s}}),()=>{o.abort()}})}class Jt{constructor(r){m(this,"apiKey");m(this,"endpoint");m(this,"destroy$",new z);m(this,"transformSsePayload");if(!r.apiKey)throw new Error("apiKey must be required");if(!r.endpoint)throw new Error("endpoint must be required");this.apiKey=r.apiKey,this.endpoint=r.endpoint,this.transformSsePayload=r.transformSsePayload}fetchSse(r,e){var n,i;(n=e==null?void 0:e.onSseStart)==null||n.call(e),Wt({apiKey:this.apiKey,endpoint:this.endpoint,payload:((i=this.transformSsePayload)==null?void 0:i.call(this,r))??r}).pipe(jt(o=>mt(o).pipe(Rt((e==null?void 0:e.delayTime)??50))),Nt(this.destroy$),Ut(3)).subscribe({next:o=>{var s;(s=e==null?void 0:e.onSseMessage)==null||s.call(e,o)},error:o=>{var s;(s=e==null?void 0:e.onSseError)==null||s.call(e,o)},complete:()=>{var o;(o=e==null?void 0:e.onSseCompleted)==null||o.call(e)}})}close(){this.destroy$.next(),this.destroy$.complete()}}class Z{constructor(r){m(this,"client");m(this,"customChannelId");m(this,"customMessageId");m(this,"isConnecting$");m(this,"conversation$");m(this,"statesObserver");m(this,"statesSubscription");if(!r.client)throw new Error("client must be required");if(!r.customChannelId)throw new Error("customChannelId must be required");this.client=r.client,this.customChannelId=r.customChannelId,this.customMessageId=r.customMessageId,this.isConnecting$=new ie(!1),this.conversation$=new ie(r.conversation),this.statesObserver=r.statesObserver}static async reset(r,e){const n=new Z(r);try{return await n.resetChannel(e),n.subscribe(),n}catch(i){throw n.close(),i}}subscribe(){this.statesSubscription=Pt([this.isConnecting$,this.conversation$]).pipe(F(([r,e])=>({isConnecting:r,conversation:e}))).subscribe(this.statesObserver)}fetchSse(r,e){return new Promise((n,i)=>{this.isConnecting$.next(!0),this.client.fetchSse(r,{onSseStart:e==null?void 0:e.onSseStart,onSseMessage:o=>{var s;(s=e==null?void 0:e.onSseMessage)==null||s.call(e,o),this.conversation$.next(this.conversation$.value.onMessage(o))},onSseError:o=>{var s;(s=e==null?void 0:e.onSseError)==null||s.call(e,o),this.isConnecting$.next(!1),i(o)},onSseCompleted:()=>{var o;(o=e==null?void 0:e.onSseCompleted)==null||o.call(e),this.isConnecting$.next(!1),n()}})})}resetChannel(r){return this.fetchSse({action:R.RESET_CHANNEL,customChannelId:this.customChannelId,customMessageId:this.customMessageId,text:""},r)}sendMessage(r,e){const n=r.text.trim(),i=r.customMessageId??crypto.randomUUID();return this.conversation$.next(this.conversation$.value.pushMessage({type:"user",messageId:i,text:n,time:new Date})),this.fetchSse({action:R.NONE,customChannelId:this.customChannelId,customMessageId:i,text:n},e)}close(){var r;this.isConnecting$.complete(),this.conversation$.complete(),(r=this.statesSubscription)==null||r.unsubscribe()}}class ee{constructor({messages:r,showDebugMessage:e}){m(this,"showDebugMessage",!1);m(this,"messages",null);this.messages=r,this.showDebugMessage=e??!1}create(r){return new ee({messages:r,showDebugMessage:this.showDebugMessage})}pushMessage(r){const e=new Map(this.messages);return e.set(r.messageId,r),this.create(e)}onMessage(r){switch(r.eventType){case S.MESSAGE_START:return this.onMessageStart(r);case S.MESSAGE_DELTA:return this.onMessageDelta(r);case S.MESSAGE_COMPLETE:return this.onMessageComplete(r);default:return this}}onMessageStart(r){const e=r.fact.messageStart.message,n=new Map(this.messages);return e.isDebug&&!this.showDebugMessage||n!=null&&n.has(e.messageId)?this.create(n):(n.set(e.messageId,{type:"bot",eventType:S.MESSAGE_START,isTyping:!0,typingText:"",messageId:e.messageId,message:e,time:new Date}),this.create(n))}onMessageDelta(r){const e=r.fact.messageDelta.message,n=new Map(this.messages),i=n.get(e.messageId);if((i==null?void 0:i.type)==="user")return this;if(e.isDebug&&!this.showDebugMessage||(i==null?void 0:i.eventType)===S.MESSAGE_COMPLETE)return this.create(n);const o=`${(i==null?void 0:i.typingText)??""}${e.text}`;return n.set(e.messageId,{type:"bot",eventType:S.MESSAGE_DELTA,isTyping:!0,typingText:o,messageId:e.messageId,message:e,time:new Date}),this.create(n)}onMessageComplete(r){const e=r.fact.messageComplete.message,n=new Map(this.messages);return e.isDebug&&!this.showDebugMessage?this.create(n):(n.set(e.messageId,{type:"bot",eventType:S.MESSAGE_COMPLETE,isTyping:!1,typingText:null,messageId:e.messageId,message:e,time:new Date}),this.create(n))}}exports.AsgardServiceClient=Jt;exports.Channel=Z;exports.Conversation=ee;exports.EventType=S;exports.FetchSseAction=R;exports.MessageTemplateType=le;
3
+ `):"",this.name="UnsubscriptionError",this.errors=e}});function $(t,r){if(t){var e=t.indexOf(r);0<=e&&t.splice(e,1)}}var R=function(){function t(r){this.initialTeardown=r,this.closed=!1,this._parentage=null,this._finalizers=null}return t.prototype.unsubscribe=function(){var r,e,n,i,o;if(!this.closed){this.closed=!0;var s=this._parentage;if(s)if(this._parentage=null,Array.isArray(s))try{for(var c=P(s),u=c.next();!u.done;u=c.next()){var a=u.value;a.remove(this)}}catch(h){r={error:h}}finally{try{u&&!u.done&&(e=c.return)&&e.call(c)}finally{if(r)throw r.error}}else s.remove(this);var f=this.initialTeardown;if(y(f))try{f()}catch(h){o=h instanceof H?h.errors:[h]}var d=this._finalizers;if(d){this._finalizers=null;try{for(var p=P(d),l=p.next();!l.done;l=p.next()){var v=l.value;try{te(v)}catch(h){o=o??[],h instanceof H?o=k(k([],M(o)),M(h.errors)):o.push(h)}}}catch(h){n={error:h}}finally{try{l&&!l.done&&(i=p.return)&&i.call(p)}finally{if(n)throw n.error}}}if(o)throw new H(o)}},t.prototype.add=function(r){var e;if(r&&r!==this)if(this.closed)te(r);else{if(r instanceof t){if(r.closed||r._hasParent(this))return;r._addParent(this)}(this._finalizers=(e=this._finalizers)!==null&&e!==void 0?e:[]).push(r)}},t.prototype._hasParent=function(r){var e=this._parentage;return e===r||Array.isArray(e)&&e.includes(r)},t.prototype._addParent=function(r){var e=this._parentage;this._parentage=Array.isArray(e)?(e.push(r),e):e?[e,r]:r},t.prototype._removeParent=function(r){var e=this._parentage;e===r?this._parentage=null:Array.isArray(e)&&$(e,r)},t.prototype.remove=function(r){var e=this._finalizers;e&&$(e,r),r instanceof t&&r._removeParent(this)},t.EMPTY=function(){var r=new t;return r.closed=!0,r}(),t}(),de=R.EMPTY;function ve(t){return t instanceof R||t&&"closed"in t&&y(t.remove)&&y(t.add)&&y(t.unsubscribe)}function te(t){y(t)?t():t.unsubscribe()}var Fe={Promise:void 0},Ve={setTimeout:function(t,r){for(var e=[],n=2;n<arguments.length;n++)e[n-2]=arguments[n];return setTimeout.apply(void 0,k([t,r],M(e)))},clearTimeout:function(t){return clearTimeout(t)},delegate:void 0};function ye(t){Ve.setTimeout(function(){throw t})}function B(){}function L(t){t()}var J=function(t){I(r,t);function r(e){var n=t.call(this)||this;return n.isStopped=!1,e?(n.destination=e,ve(e)&&e.add(n)):n.destination=qe,n}return r.create=function(e,n,i){return new Y(e,n,i)},r.prototype.next=function(e){this.isStopped||this._next(e)},r.prototype.error=function(e){this.isStopped||(this.isStopped=!0,this._error(e))},r.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},r.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,t.prototype.unsubscribe.call(this),this.destination=null)},r.prototype._next=function(e){this.destination.next(e)},r.prototype._error=function(e){try{this.destination.error(e)}finally{this.unsubscribe()}},r.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},r}(R),Ke=function(){function t(r){this.partialObserver=r}return t.prototype.next=function(r){var e=this.partialObserver;if(e.next)try{e.next(r)}catch(n){j(n)}},t.prototype.error=function(r){var e=this.partialObserver;if(e.error)try{e.error(r)}catch(n){j(n)}else j(r)},t.prototype.complete=function(){var r=this.partialObserver;if(r.complete)try{r.complete()}catch(e){j(e)}},t}(),Y=function(t){I(r,t);function r(e,n,i){var o=t.call(this)||this,s;return y(e)||!e?s={next:e??void 0,error:n??void 0,complete:i??void 0}:s=e,o.destination=new Ke(s),o}return r}(J);function j(t){ye(t)}function He(t){throw t}var qe={closed:!0,next:B,error:He,complete:B},X=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();function G(t){return t}function Be(t){return t.length===0?G:t.length===1?t[0]:function(e){return t.reduce(function(n,i){return i(n)},e)}}var m=function(){function t(r){r&&(this._subscribe=r)}return t.prototype.lift=function(r){var e=new t;return e.source=this,e.operator=r,e},t.prototype.subscribe=function(r,e,n){var i=this,o=We(r)?r:new Y(r,e,n);return L(function(){var s=i,c=s.operator,u=s.source;o.add(c?c.call(o,u):u?i._subscribe(o):i._trySubscribe(o))}),o},t.prototype._trySubscribe=function(r){try{return this._subscribe(r)}catch(e){r.error(e)}},t.prototype.forEach=function(r,e){var n=this;return e=re(e),new e(function(i,o){var s=new Y({next:function(c){try{r(c)}catch(u){o(u),s.unsubscribe()}},error:o,complete:i});n.subscribe(s)})},t.prototype._subscribe=function(r){var e;return(e=this.source)===null||e===void 0?void 0:e.subscribe(r)},t.prototype[X]=function(){return this},t.prototype.pipe=function(){for(var r=[],e=0;e<arguments.length;e++)r[e]=arguments[e];return Be(r)(this)},t.prototype.toPromise=function(r){var e=this;return r=re(r),new r(function(n,i){var o;e.subscribe(function(s){return o=s},function(s){return i(s)},function(){return n(o)})})},t.create=function(r){return new t(r)},t}();function re(t){var r;return(r=t??Fe.Promise)!==null&&r!==void 0?r:Promise}function Ye(t){return t&&y(t.next)&&y(t.error)&&y(t.complete)}function We(t){return t&&t instanceof J||Ye(t)&&ve(t)}function Je(t){return y(t==null?void 0:t.lift)}function T(t){return function(r){if(Je(r))return r.lift(function(e){try{return t(e,this)}catch(n){this.error(n)}});throw new TypeError("Unable to lift unknown Observable type")}}function E(t,r,e,n,i){return new Xe(t,r,e,n,i)}var Xe=function(t){I(r,t);function r(e,n,i,o,s,c){var u=t.call(this,e)||this;return u.onFinalize=s,u.shouldUnsubscribe=c,u._next=n?function(a){try{n(a)}catch(f){e.error(f)}}:t.prototype._next,u._error=o?function(a){try{o(a)}catch(f){e.error(f)}finally{this.unsubscribe()}}:t.prototype._error,u._complete=i?function(){try{i()}catch(a){e.error(a)}finally{this.unsubscribe()}}:t.prototype._complete,u}return r.prototype.unsubscribe=function(){var e;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var n=this.closed;t.prototype.unsubscribe.call(this),!n&&((e=this.onFinalize)===null||e===void 0||e.call(this))}},r}(J),ze=he(function(t){return function(){t(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}}),z=function(t){I(r,t);function r(){var e=t.call(this)||this;return e.closed=!1,e.currentObservers=null,e.observers=[],e.isStopped=!1,e.hasError=!1,e.thrownError=null,e}return r.prototype.lift=function(e){var n=new ne(this,this);return n.operator=e,n},r.prototype._throwIfClosed=function(){if(this.closed)throw new ze},r.prototype.next=function(e){var n=this;L(function(){var i,o;if(n._throwIfClosed(),!n.isStopped){n.currentObservers||(n.currentObservers=Array.from(n.observers));try{for(var s=P(n.currentObservers),c=s.next();!c.done;c=s.next()){var u=c.value;u.next(e)}}catch(a){i={error:a}}finally{try{c&&!c.done&&(o=s.return)&&o.call(s)}finally{if(i)throw i.error}}}})},r.prototype.error=function(e){var n=this;L(function(){if(n._throwIfClosed(),!n.isStopped){n.hasError=n.isStopped=!0,n.thrownError=e;for(var i=n.observers;i.length;)i.shift().error(e)}})},r.prototype.complete=function(){var e=this;L(function(){if(e._throwIfClosed(),!e.isStopped){e.isStopped=!0;for(var n=e.observers;n.length;)n.shift().complete()}})},r.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(r.prototype,"observed",{get:function(){var e;return((e=this.observers)===null||e===void 0?void 0:e.length)>0},enumerable:!1,configurable:!0}),r.prototype._trySubscribe=function(e){return this._throwIfClosed(),t.prototype._trySubscribe.call(this,e)},r.prototype._subscribe=function(e){return this._throwIfClosed(),this._checkFinalizedStatuses(e),this._innerSubscribe(e)},r.prototype._innerSubscribe=function(e){var n=this,i=this,o=i.hasError,s=i.isStopped,c=i.observers;return o||s?de:(this.currentObservers=null,c.push(e),new R(function(){n.currentObservers=null,$(c,e)}))},r.prototype._checkFinalizedStatuses=function(e){var n=this,i=n.hasError,o=n.thrownError,s=n.isStopped;i?e.error(o):s&&e.complete()},r.prototype.asObservable=function(){var e=new m;return e.source=this,e},r.create=function(e,n){return new ne(e,n)},r}(m),ne=function(t){I(r,t);function r(e,n){var i=t.call(this)||this;return i.destination=e,i.source=n,i}return r.prototype.next=function(e){var n,i;(i=(n=this.destination)===null||n===void 0?void 0:n.next)===null||i===void 0||i.call(n,e)},r.prototype.error=function(e){var n,i;(i=(n=this.destination)===null||n===void 0?void 0:n.error)===null||i===void 0||i.call(n,e)},r.prototype.complete=function(){var e,n;(n=(e=this.destination)===null||e===void 0?void 0:e.complete)===null||n===void 0||n.call(e)},r.prototype._subscribe=function(e){var n,i;return(i=(n=this.source)===null||n===void 0?void 0:n.subscribe(e))!==null&&i!==void 0?i:de},r}(z),ie=function(t){I(r,t);function r(e){var n=t.call(this)||this;return n._value=e,n}return Object.defineProperty(r.prototype,"value",{get:function(){return this.getValue()},enumerable:!1,configurable:!0}),r.prototype._subscribe=function(e){var n=t.prototype._subscribe.call(this,e);return!n.closed&&e.next(this._value),n},r.prototype.getValue=function(){var e=this,n=e.hasError,i=e.thrownError,o=e._value;if(n)throw i;return this._throwIfClosed(),o},r.prototype.next=function(e){t.prototype.next.call(this,this._value=e)},r}(z),Qe={now:function(){return Date.now()}},Ze=function(t){I(r,t);function r(e,n){return t.call(this)||this}return r.prototype.schedule=function(e,n){return this},r}(R),oe={setInterval:function(t,r){for(var e=[],n=2;n<arguments.length;n++)e[n-2]=arguments[n];return setInterval.apply(void 0,k([t,r],M(e)))},clearInterval:function(t){return clearInterval(t)},delegate:void 0},et=function(t){I(r,t);function r(e,n){var i=t.call(this,e,n)||this;return i.scheduler=e,i.work=n,i.pending=!1,i}return r.prototype.schedule=function(e,n){var i;if(n===void 0&&(n=0),this.closed)return this;this.state=e;var o=this.id,s=this.scheduler;return o!=null&&(this.id=this.recycleAsyncId(s,o,n)),this.pending=!0,this.delay=n,this.id=(i=this.id)!==null&&i!==void 0?i:this.requestAsyncId(s,this.id,n),this},r.prototype.requestAsyncId=function(e,n,i){return i===void 0&&(i=0),oe.setInterval(e.flush.bind(e,this),i)},r.prototype.recycleAsyncId=function(e,n,i){if(i===void 0&&(i=0),i!=null&&this.delay===i&&this.pending===!1)return n;n!=null&&oe.clearInterval(n)},r.prototype.execute=function(e,n){if(this.closed)return new Error("executing a cancelled action");this.pending=!1;var i=this._execute(e,n);if(i)return i;this.pending===!1&&this.id!=null&&(this.id=this.recycleAsyncId(this.scheduler,this.id,null))},r.prototype._execute=function(e,n){var i=!1,o;try{this.work(e)}catch(s){i=!0,o=s||new Error("Scheduled action threw falsy error")}if(i)return this.unsubscribe(),o},r.prototype.unsubscribe=function(){if(!this.closed){var e=this,n=e.id,i=e.scheduler,o=i.actions;this.work=this.state=this.scheduler=null,this.pending=!1,$(o,this),n!=null&&(this.id=this.recycleAsyncId(i,n,null)),this.delay=null,t.prototype.unsubscribe.call(this)}},r}(Ze),se=function(){function t(r,e){e===void 0&&(e=t.now),this.schedulerActionCtor=r,this.now=e}return t.prototype.schedule=function(r,e,n){return e===void 0&&(e=0),new this.schedulerActionCtor(this,r).schedule(n,e)},t.now=Qe.now,t}(),tt=function(t){I(r,t);function r(e,n){n===void 0&&(n=se.now);var i=t.call(this,e,n)||this;return i.actions=[],i._active=!1,i}return r.prototype.flush=function(e){var n=this.actions;if(this._active){n.push(e);return}var i;this._active=!0;do if(i=e.execute(e.state,e.delay))break;while(e=n.shift());if(this._active=!1,i){for(;e=n.shift();)e.unsubscribe();throw i}},r}(se),pe=new tt(et),rt=pe,nt=new m(function(t){return t.complete()});function be(t){return t&&y(t.schedule)}function me(t){return t[t.length-1]}function it(t){return y(me(t))?t.pop():void 0}function ge(t){return be(me(t))?t.pop():void 0}var we=function(t){return t&&typeof t.length=="number"&&typeof t!="function"};function Se(t){return y(t==null?void 0:t.then)}function Ee(t){return y(t[X])}function Ie(t){return Symbol.asyncIterator&&y(t==null?void 0:t[Symbol.asyncIterator])}function Oe(t){return new TypeError("You provided "+(t!==null&&typeof t=="object"?"an invalid object":"'"+t+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}function ot(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}var Ae=ot();function xe(t){return y(t==null?void 0:t[Ae])}function _e(t){return Ne(this,arguments,function(){var e,n,i,o;return fe(this,function(s){switch(s.label){case 0:e=t.getReader(),s.label=1;case 1:s.trys.push([1,,9,10]),s.label=2;case 2:return[4,C(e.read())];case 3:return n=s.sent(),i=n.value,o=n.done,o?[4,C(void 0)]:[3,5];case 4:return[2,s.sent()];case 5:return[4,C(i)];case 6:return[4,s.sent()];case 7:return s.sent(),[3,2];case 8:return[3,10];case 9:return e.releaseLock(),[7];case 10:return[2]}})})}function Te(t){return y(t==null?void 0:t.getReader)}function x(t){if(t instanceof m)return t;if(t!=null){if(Ee(t))return st(t);if(we(t))return at(t);if(Se(t))return ut(t);if(Ie(t))return Ce(t);if(xe(t))return ct(t);if(Te(t))return lt(t)}throw Oe(t)}function st(t){return new m(function(r){var e=t[X]();if(y(e.subscribe))return e.subscribe(r);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function at(t){return new m(function(r){for(var e=0;e<t.length&&!r.closed;e++)r.next(t[e]);r.complete()})}function ut(t){return new m(function(r){t.then(function(e){r.closed||(r.next(e),r.complete())},function(e){return r.error(e)}).then(null,ye)})}function ct(t){return new m(function(r){var e,n;try{for(var i=P(t),o=i.next();!o.done;o=i.next()){var s=o.value;if(r.next(s),r.closed)return}}catch(c){e={error:c}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}r.complete()})}function Ce(t){return new m(function(r){ft(t,r).catch(function(e){return r.error(e)})})}function lt(t){return Ce(_e(t))}function ft(t,r){var e,n,i,o;return $e(this,void 0,void 0,function(){var s,c;return fe(this,function(u){switch(u.label){case 0:u.trys.push([0,5,6,11]),e=Ge(t),u.label=1;case 1:return[4,e.next()];case 2:if(n=u.sent(),!!n.done)return[3,4];if(s=n.value,r.next(s),r.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]),n&&!n.done&&(o=e.return)?[4,o.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 r.complete(),[2]}})})}function A(t,r,e,n,i){n===void 0&&(n=0),i===void 0&&(i=!1);var o=r.schedule(function(){e(),i?t.add(this.schedule(null,n)):this.unsubscribe()},n);if(t.add(o),!i)return o}function Pe(t,r){return r===void 0&&(r=0),T(function(e,n){e.subscribe(E(n,function(i){return A(n,t,function(){return n.next(i)},r)},function(){return A(n,t,function(){return n.complete()},r)},function(i){return A(n,t,function(){return n.error(i)},r)}))})}function Me(t,r){return r===void 0&&(r=0),T(function(e,n){n.add(t.schedule(function(){return e.subscribe(n)},r))})}function ht(t,r){return x(t).pipe(Me(r),Pe(r))}function dt(t,r){return x(t).pipe(Me(r),Pe(r))}function vt(t,r){return new m(function(e){var n=0;return r.schedule(function(){n===t.length?e.complete():(e.next(t[n++]),e.closed||this.schedule())})})}function yt(t,r){return new m(function(e){var n;return A(e,r,function(){n=t[Ae](),A(e,r,function(){var i,o,s;try{i=n.next(),o=i.value,s=i.done}catch(c){e.error(c);return}s?e.complete():e.next(o)},0,!0)}),function(){return y(n==null?void 0:n.return)&&n.return()}})}function ke(t,r){if(!t)throw new Error("Iterable cannot be null");return new m(function(e){A(e,r,function(){var n=t[Symbol.asyncIterator]();A(e,r,function(){n.next().then(function(i){i.done?e.complete():e.next(i.value)})},0,!0)})})}function pt(t,r){return ke(_e(t),r)}function bt(t,r){if(t!=null){if(Ee(t))return ht(t,r);if(we(t))return vt(t,r);if(Se(t))return dt(t,r);if(Ie(t))return ke(t,r);if(xe(t))return yt(t,r);if(Te(t))return pt(t,r)}throw Oe(t)}function Q(t,r){return r?bt(t,r):x(t)}function mt(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];var e=ge(t);return Q(t,e)}function gt(t){return t instanceof Date&&!isNaN(t)}function F(t,r){return T(function(e,n){var i=0;e.subscribe(E(n,function(o){n.next(t.call(r,o,i++))}))})}var wt=Array.isArray;function St(t,r){return wt(r)?t.apply(void 0,k([],M(r))):t(r)}function Et(t){return F(function(r){return St(t,r)})}var It=Array.isArray,Ot=Object.getPrototypeOf,At=Object.prototype,xt=Object.keys;function _t(t){if(t.length===1){var r=t[0];if(It(r))return{args:r,keys:null};if(Tt(r)){var e=xt(r);return{args:e.map(function(n){return r[n]}),keys:e}}}return{args:t,keys:null}}function Tt(t){return t&&typeof t=="object"&&Ot(t)===At}function Ct(t,r){return t.reduce(function(e,n,i){return e[n]=r[i],e},{})}function Pt(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];var e=ge(t),n=it(t),i=_t(t),o=i.args,s=i.keys;if(o.length===0)return Q([],e);var c=new m(Mt(o,e,s?function(u){return Ct(s,u)}:G));return n?c.pipe(Et(n)):c}function Mt(t,r,e){return e===void 0&&(e=G),function(n){ae(r,function(){for(var i=t.length,o=new Array(i),s=i,c=i,u=function(f){ae(r,function(){var d=Q(t[f],r),p=!1;d.subscribe(E(n,function(l){o[f]=l,p||(p=!0,c--),c||n.next(e(o.slice()))},function(){--s||n.complete()}))},n)},a=0;a<i;a++)u(a)},n)}}function ae(t,r,e){t?A(e,t,r):r()}function kt(t,r,e,n,i,o,s,c){var u=[],a=0,f=0,d=!1,p=function(){d&&!u.length&&!a&&r.complete()},l=function(h){return a<n?v(h):u.push(h)},v=function(h){a++;var w=!1;x(e(h,f++)).subscribe(E(r,function(S){r.next(S)},function(){w=!0},void 0,function(){if(w)try{a--;for(var S=function(){var _=u.shift();s||v(_)};u.length&&a<n;)S();p()}catch(_){r.error(_)}}))};return t.subscribe(E(r,l,function(){d=!0,p()})),function(){}}function N(t,r,e){return e===void 0&&(e=1/0),y(r)?N(function(n,i){return F(function(o,s){return r(n,o,i,s)})(x(t(n,i)))},e):(typeof r=="number"&&(e=r),T(function(n,i){return kt(n,i,t,e)}))}function Re(t,r,e){t===void 0&&(t=0),e===void 0&&(e=rt);var n=-1;return r!=null&&(be(r)?e=r:n=r),new m(function(i){var o=gt(t)?+t-e.now():t;o<0&&(o=0);var s=0;return e.schedule(function(){i.closed||(i.next(s++),0<=n?this.schedule(void 0,n):i.complete())},o)})}function Rt(t,r){return y(r)?N(t,r,1):N(t,1)}function Dt(t){return t<=0?function(){return nt}:T(function(r,e){var n=0;r.subscribe(E(e,function(i){++n<=t&&(e.next(i),t<=n&&e.complete())}))})}function jt(t){return F(function(){return t})}function Lt(t,r){return N(function(e,n){return x(t(e,n)).pipe(Dt(1),jt(e))})}function Ut(t,r){r===void 0&&(r=pe);var e=Re(t,r);return Lt(function(){return e})}function $t(t){var r;r={count:t};var e=r.count,n=e===void 0?1/0:e,i=r.delay,o=r.resetOnSuccess,s=o===void 0?!1:o;return n<=0?G:T(function(c,u){var a=0,f,d=function(){var p=!1;f=c.subscribe(E(u,function(l){s&&(a=0),u.next(l)},void 0,function(l){if(a++<n){var v=function(){f?(f.unsubscribe(),f=null,d()):p=!0};if(i!=null){var h=typeof i=="number"?Re(i):x(i(l,a)),w=E(u,function(){w.unsubscribe(),v()},function(){u.complete()});h.subscribe(w)}else v()}else u.error(l)})),p&&(f.unsubscribe(),f=null,d())};d()})}function Nt(t){return T(function(r,e){x(t).subscribe(E(e,function(){return e.complete()},B)),!e.closed&&r.subscribe(e)})}async function Gt(t,r){const e=t.getReader();let n;for(;!(n=await e.read()).done;)r(n.value)}function Ft(t){let r,e,n,i=!1;return function(s){r===void 0?(r=s,e=0,n=-1):r=Kt(r,s);const c=r.length;let u=0;for(;e<c;){i&&(r[e]===10&&(u=++e),i=!1);let a=-1;for(;e<c&&a===-1;++e)switch(r[e]){case 58:n===-1&&(n=e-u);break;case 13:i=!0;case 10:a=e;break}if(a===-1)break;t(r.subarray(u,a),n),u=e,n=-1}u===c?r=void 0:u!==0&&(r=r.subarray(u),e-=u)}}function Vt(t,r,e){let n=ue();const i=new TextDecoder;return function(s,c){if(s.length===0)e==null||e(n),n=ue();else if(c>0){const u=i.decode(s.subarray(0,c)),a=c+(s[c+1]===32?2:1),f=i.decode(s.subarray(a));switch(u){case"data":n.data=n.data?n.data+`
4
+ `+f:f;break;case"event":n.event=f;break;case"id":t(n.id=f);break;case"retry":const d=parseInt(f,10);isNaN(d)||r(n.retry=d);break}}}}function Kt(t,r){const e=new Uint8Array(t.length+r.length);return e.set(t),e.set(r,t.length),e}function ue(){return{data:"",event:"",id:"",retry:void 0}}var Ht=function(t,r){var e={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&r.indexOf(n)<0&&(e[n]=t[n]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(t);i<n.length;i++)r.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(e[n[i]]=t[n[i]]);return e};const W="text/event-stream",qt=1e3,ce="last-event-id";function Bt(t,r){var{signal:e,headers:n,onopen:i,onmessage:o,onclose:s,onerror:c,openWhenHidden:u,fetch:a}=r,f=Ht(r,["signal","headers","onopen","onmessage","onclose","onerror","openWhenHidden","fetch"]);return new Promise((d,p)=>{const l=Object.assign({},n);l.accept||(l.accept=W);let v;function h(){v.abort(),document.hidden||V()}u||document.addEventListener("visibilitychange",h);let w=qt,S=0;function _(){document.removeEventListener("visibilitychange",h),window.clearTimeout(S),v.abort()}e==null||e.addEventListener("abort",()=>{_(),d()});const De=a??window.fetch,je=i??Yt;async function V(){var K;v=new AbortController;try{const D=await De(t,Object.assign(Object.assign({},f),{headers:l,signal:v.signal}));await je(D),await Gt(D.body,Ft(Vt(O=>{O?l[ce]=O:delete l[ce]},O=>{w=O},o))),s==null||s(),_(),d()}catch(D){if(!v.signal.aborted)try{const O=(K=c==null?void 0:c(D))!==null&&K!==void 0?K:w;window.clearTimeout(S),S=window.setTimeout(V,O)}catch(O){_(),p(O)}}}V()})}function Yt(t){const r=t.headers.get("content-type");if(!(r!=null&&r.startsWith(W)))throw new Error(`Expected content-type to be ${W}, Actual: ${r}`)}function Wt(t){const{endpoint:r,apiKey:e,payload:n}=t;return new m(i=>{const o=new AbortController;return Bt(r,{method:"POST",headers:{"X-API-KEY":e,"Content-Type":"application/json"},body:n?JSON.stringify(n):void 0,signal:o.signal,onopen:async s=>{s.ok||(i.error(s),o.abort())},onmessage:s=>{i.next(JSON.parse(s.data))},onclose:()=>{i.complete()},onerror:s=>{throw i.error(s),o.abort(),s}}),()=>{o.abort()}})}class Jt{constructor(r){b(this,"apiKey");b(this,"endpoint");b(this,"destroy$",new z);b(this,"onExecutionError");b(this,"transformSsePayload");if(!r.apiKey)throw new Error("apiKey must be required");if(!r.endpoint)throw new Error("endpoint must be required");this.apiKey=r.apiKey,this.endpoint=r.endpoint,this.onExecutionError=r.onExecutionError,this.transformSsePayload=r.transformSsePayload}fetchSse(r,e){var n,i;(n=e==null?void 0:e.onSseStart)==null||n.call(e),Wt({apiKey:this.apiKey,endpoint:this.endpoint,payload:((i=this.transformSsePayload)==null?void 0:i.call(this,r))??r}).pipe(Rt(o=>mt(o).pipe(Ut((e==null?void 0:e.delayTime)??50))),Nt(this.destroy$),$t(3)).subscribe({next:o=>{var s,c;switch((s=e==null?void 0:e.onSseMessage)==null||s.call(e,o),o.eventType){case g.ERROR:(c=this.onExecutionError)==null||c.call(this,o.fact.runError);break}},error:o=>{var s;(s=e==null?void 0:e.onSseError)==null||s.call(e,o)},complete:()=>{var o;(o=e==null?void 0:e.onSseCompleted)==null||o.call(e)}})}close(){this.destroy$.next(),this.destroy$.complete()}}class Z{constructor(r){b(this,"client");b(this,"customChannelId");b(this,"customMessageId");b(this,"isConnecting$");b(this,"conversation$");b(this,"statesObserver");b(this,"statesSubscription");if(!r.client)throw new Error("client must be required");if(!r.customChannelId)throw new Error("customChannelId must be required");this.client=r.client,this.customChannelId=r.customChannelId,this.customMessageId=r.customMessageId,this.isConnecting$=new ie(!1),this.conversation$=new ie(r.conversation),this.statesObserver=r.statesObserver}static async reset(r,e){const n=new Z(r);try{return n.subscribe(),await n.resetChannel(e),n}catch(i){throw n.close(),i}}subscribe(){this.statesSubscription=Pt([this.isConnecting$,this.conversation$]).pipe(F(([r,e])=>({isConnecting:r,conversation:e}))).subscribe(this.statesObserver)}fetchSse(r,e){return new Promise((n,i)=>{this.isConnecting$.next(!0),this.client.fetchSse(r,{onSseStart:e==null?void 0:e.onSseStart,onSseMessage:o=>{var s;(s=e==null?void 0:e.onSseMessage)==null||s.call(e,o),this.conversation$.next(this.conversation$.value.onMessage(o))},onSseError:o=>{var s;(s=e==null?void 0:e.onSseError)==null||s.call(e,o),this.isConnecting$.next(!1),i(o)},onSseCompleted:()=>{var o;(o=e==null?void 0:e.onSseCompleted)==null||o.call(e),this.isConnecting$.next(!1),n()}})})}resetChannel(r){return this.fetchSse({action:U.RESET_CHANNEL,customChannelId:this.customChannelId,customMessageId:this.customMessageId,text:""},r)}sendMessage(r,e){const n=r.text.trim(),i=r.customMessageId??crypto.randomUUID();return this.conversation$.next(this.conversation$.value.pushMessage({type:"user",messageId:i,text:n,time:new Date})),this.fetchSse({action:U.NONE,customChannelId:this.customChannelId,customMessageId:i,text:n},e)}close(){var r;this.isConnecting$.complete(),this.conversation$.complete(),(r=this.statesSubscription)==null||r.unsubscribe()}}class ee{constructor({messages:r,showDebugMessage:e}){b(this,"showDebugMessage",!1);b(this,"messages",null);this.messages=r,this.showDebugMessage=e??!1}create(r){return new ee({messages:r,showDebugMessage:this.showDebugMessage})}pushMessage(r){const e=new Map(this.messages);return e.set(r.messageId,r),this.create(e)}onMessage(r){switch(r.eventType){case g.MESSAGE_START:return this.onMessageStart(r);case g.MESSAGE_DELTA:return this.onMessageDelta(r);case g.MESSAGE_COMPLETE:return this.onMessageComplete(r);case g.ERROR:return this.onMessageError(r);default:return this}}onMessageStart(r){const e=r.fact.messageStart.message,n=new Map(this.messages);return e.isDebug&&!this.showDebugMessage||n!=null&&n.has(e.messageId)?this.create(n):(n.set(e.messageId,{type:"bot",eventType:g.MESSAGE_START,isTyping:!0,typingText:"",messageId:e.messageId,message:e,time:new Date}),this.create(n))}onMessageDelta(r){const e=r.fact.messageDelta.message,n=new Map(this.messages),i=n.get(e.messageId);if((i==null?void 0:i.type)!=="bot")return this;if(e.isDebug&&!this.showDebugMessage||(i==null?void 0:i.eventType)===g.MESSAGE_COMPLETE)return this.create(n);const o=`${(i==null?void 0:i.typingText)??""}${e.text}`;return n.set(e.messageId,{type:"bot",eventType:g.MESSAGE_DELTA,isTyping:!0,typingText:o,messageId:e.messageId,message:e,time:new Date}),this.create(n)}onMessageComplete(r){const e=r.fact.messageComplete.message,n=new Map(this.messages);return e.isDebug&&!this.showDebugMessage?this.create(n):(n.set(e.messageId,{type:"bot",eventType:g.MESSAGE_COMPLETE,isTyping:!1,typingText:null,messageId:e.messageId,message:e,time:new Date}),this.create(n))}onMessageError(r){const e=crypto.randomUUID(),n=r.fact.runError.error,i=new Map(this.messages);return i.set(e,{type:"error",eventType:g.ERROR,messageId:e,error:n,time:new Date}),this.create(i)}}exports.AsgardServiceClient=Jt;exports.Channel=Z;exports.Conversation=ee;exports.EventType=g;exports.FetchSseAction=U;exports.MessageTemplateType=le;
5
5
  //# sourceMappingURL=index.cjs.map