@asgard-js/core 0.0.44-canary.3 → 0.0.44
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/README.md +65 -17
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +167 -119
- package/dist/index.mjs.map +1 -1
- package/dist/lib/channel.d.ts +3 -1
- package/dist/lib/channel.d.ts.map +1 -1
- package/dist/lib/client.d.ts +11 -1
- package/dist/lib/client.d.ts.map +1 -1
- package/dist/types/blob.d.ts +22 -0
- package/dist/types/blob.d.ts.map +1 -0
- package/dist/types/channel.d.ts +2 -0
- package/dist/types/channel.d.ts.map +1 -1
- package/dist/types/client.d.ts +3 -0
- package/dist/types/client.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
(function(m,S){typeof exports=="object"&&typeof module<"u"?S(exports):typeof define=="function"&&define.amd?define(["exports"],S):(m=typeof globalThis<"u"?globalThis:m||self,S(m["@asgard-js/core"]={}))})(this,(function(m){"use strict";var
|
|
1
|
+
(function(m,S){typeof exports=="object"&&typeof module<"u"?S(exports):typeof define=="function"&&define.amd?define(["exports"],S):(m=typeof globalThis<"u"?globalThis:m||self,S(m["@asgard-js/core"]={}))})(this,(function(m){"use strict";var Jt=Object.defineProperty;var zt=(m,S,h)=>S in m?Jt(m,S,{enumerable:!0,configurable:!0,writable:!0,value:h}):m[S]=h;var g=(m,S,h)=>zt(m,typeof S!="symbol"?S+"":S,h);var S=(r=>(r.RESET_CHANNEL="RESET_CHANNEL",r.NONE="NONE",r))(S||{}),h=(r=>(r.INIT="asgard.run.init",r.PROCESS="asgard.process",r.PROCESS_START="asgard.process.start",r.PROCESS_COMPLETE="asgard.process.complete",r.MESSAGE="asgard.message",r.MESSAGE_START="asgard.message.start",r.MESSAGE_DELTA="asgard.message.delta",r.MESSAGE_COMPLETE="asgard.message.complete",r.TOOL_CALL="asgard.tool_call",r.TOOL_CALL_START="asgard.tool_call.start",r.TOOL_CALL_COMPLETE="asgard.tool_call.complete",r.DONE="asgard.run.done",r.ERROR="asgard.run.error",r))(h||{}),re=(r=>(r.TEXT="TEXT",r.HINT="HINT",r.BUTTON="BUTTON",r.IMAGE="IMAGE",r.VIDEO="VIDEO",r.AUDIO="AUDIO",r.LOCATION="LOCATION",r.CAROUSEL="CAROUSEL",r.CHART="CHART",r))(re||{}),K=function(r,t){return K=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])},K(r,t)};function O(r,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");K(r,t);function e(){this.constructor=r}r.prototype=t===null?Object.create(t):(e.prototype=t.prototype,new e)}function je(r,t,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(l){try{a(n.next(l))}catch(v){s(v)}}function u(l){try{a(n.throw(l))}catch(v){s(v)}}function a(l){l.done?o(l.value):i(l.value).then(c,u)}a((n=n.apply(r,t||[])).next())})}function ne(r,t){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(l){return u([a,l])}}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=t.call(r,e)}catch(l){a=[6,l],i=0}finally{n=o=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}}function L(r){var t=typeof Symbol=="function"&&Symbol.iterator,e=t&&r[t],n=0;if(e)return e.call(r);if(r&&typeof r.length=="number")return{next:function(){return r&&n>=r.length&&(r=void 0),{value:r&&r[n++],done:!r}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function k(r,t){var e=typeof Symbol=="function"&&r[Symbol.iterator];if(!e)return r;var n=e.call(r),i,o=[],s;try{for(;(t===void 0||t-- >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 j(r,t,e){if(e||arguments.length===2)for(var n=0,i=t.length,o;n<i;n++)(o||!(n in t))&&(o||(o=Array.prototype.slice.call(t,0,n)),o[n]=t[n]);return r.concat(o||Array.prototype.slice.call(t))}function R(r){return this instanceof R?(this.v=r,this):new R(r)}function $e(r,t,e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=e.apply(r,t||[]),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(f){return function(y){return Promise.resolve(y).then(f,v)}}function c(f,y){n[f]&&(i[f]=function(d){return new Promise(function(E,A){o.push([f,d,E,A])>1||u(f,d)})},y&&(i[f]=y(i[f])))}function u(f,y){try{a(n[f](y))}catch(d){b(o[0][3],d)}}function a(f){f.value instanceof R?Promise.resolve(f.value.v).then(l,v):b(o[0][2],f)}function l(f){u("next",f)}function v(f){u("throw",f)}function b(f,y){f(y),o.shift(),o.length&&u(o[0][0],o[0][1])}}function Ue(r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=r[Symbol.asyncIterator],e;return t?t.call(r):(r=typeof L=="function"?L(r):r[Symbol.iterator](),e={},n("next"),n("throw"),n("return"),e[Symbol.asyncIterator]=function(){return this},e);function n(o){e[o]=r[o]&&function(s){return new Promise(function(c,u){s=r[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)}}typeof SuppressedError=="function"&&SuppressedError;function p(r){return typeof r=="function"}function ie(r){var t=function(n){Error.call(n),n.stack=new Error().stack},e=r(t);return e.prototype=Object.create(Error.prototype),e.prototype.constructor=e,e}var B=ie(function(r){return function(e){r(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(r,t){if(r){var e=r.indexOf(t);0<=e&&r.splice(e,1)}}var D=(function(){function r(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}return r.prototype.unsubscribe=function(){var t,e,n,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=L(s),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 s.remove(this);var l=this.initialTeardown;if(p(l))try{l()}catch(d){o=d instanceof K?d.errors:[d]}var v=this._finalizers;if(v){this._finalizers=null;try{for(var b=L(v),f=b.next();!f.done;f=b.next()){var y=f.value;try{ae(y)}catch(d){o=o??[],d instanceof K?o=j(j([],k(o)),k(d.errors)):o.push(d)}}}catch(d){n={error:d}}finally{try{f&&!f.done&&(i=b.return)&&i.call(b)}finally{if(n)throw n.error}}}if(o)throw new K(o)}},r.prototype.add=function(t){var e;if(t&&t!==this)if(this.closed)ae(t);else{if(t instanceof r){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=(e=this._finalizers)!==null&&e!==void 0?e:[]).push(t)}},r.prototype._hasParent=function(t){var e=this._parentage;return e===t||Array.isArray(e)&&e.includes(t)},r.prototype._addParent=function(t){var e=this._parentage;this._parentage=Array.isArray(e)?(e.push(t),e):e?[e,t]:t},r.prototype._removeParent=function(t){var e=this._parentage;e===t?this._parentage=null:Array.isArray(e)&&U(e,t)},r.prototype.remove=function(t){var e=this._finalizers;e&&U(e,t),t instanceof r&&t._removeParent(this)},r.EMPTY=(function(){var t=new r;return t.closed=!0,t})(),r})(),oe=D.EMPTY;function se(r){return r instanceof D||r&&"closed"in r&&p(r.remove)&&p(r.add)&&p(r.unsubscribe)}function ae(r){p(r)?r():r.unsubscribe()}var $e={Promise:void 0},Ne={setTimeout:function(r,t){for(var e=[],n=2;n<arguments.length;n++)e[n-2]=arguments[n];return setTimeout.apply(void 0,j([r,t],k(e)))},clearTimeout:function(r){return clearTimeout(r)},delegate:void 0};function ue(r){Ne.setTimeout(function(){throw r})}function Y(){}function $(r){r()}var q=(function(r){O(t,r);function t(e){var n=r.call(this)||this;return n.isStopped=!1,e?(n.destination=e,se(e)&&e.add(n)):n.destination=He,n}return t.create=function(e,n,i){return new W(e,n,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,r.prototype.unsubscribe.call(this),this.destination=null)},t.prototype._next=function(e){this.destination.next(e)},t.prototype._error=function(e){try{this.destination.error(e)}finally{this.unsubscribe()}},t.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},t})(D),Ge=(function(){function r(t){this.partialObserver=t}return r.prototype.next=function(t){var e=this.partialObserver;if(e.next)try{e.next(t)}catch(n){N(n)}},r.prototype.error=function(t){var e=this.partialObserver;if(e.error)try{e.error(t)}catch(n){N(n)}else N(t)},r.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(e){N(e)}},r})(),W=(function(r){O(t,r);function t(e,n,i){var o=r.call(this)||this,s;return p(e)||!e?s={next:e??void 0,error:n??void 0,complete:i??void 0}:s=e,o.destination=new Ge(s),o}return t})(q);function N(r){ue(r)}function Fe(r){throw r}var He={closed:!0,next:Y,error:Fe,complete:Y},J=(function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"})();function G(r){return r}function Ve(r){return r.length===0?G:r.length===1?r[0]:function(e){return r.reduce(function(n,i){return i(n)},e)}}var w=(function(){function r(t){t&&(this._subscribe=t)}return r.prototype.lift=function(t){var e=new r;return e.source=this,e.operator=t,e},r.prototype.subscribe=function(t,e,n){var i=this,o=Ke(t)?t:new W(t,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},r.prototype._trySubscribe=function(t){try{return this._subscribe(t)}catch(e){t.error(e)}},r.prototype.forEach=function(t,e){var n=this;return e=ce(e),new e(function(i,o){var s=new W({next:function(c){try{t(c)}catch(u){o(u),s.unsubscribe()}},error:o,complete:i});n.subscribe(s)})},r.prototype._subscribe=function(t){var e;return(e=this.source)===null||e===void 0?void 0:e.subscribe(t)},r.prototype[J]=function(){return this},r.prototype.pipe=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return Ve(t)(this)},r.prototype.toPromise=function(t){var e=this;return t=ce(t),new t(function(n,i){var o;e.subscribe(function(s){return o=s},function(s){return i(s)},function(){return n(o)})})},r.create=function(t){return new r(t)},r})();function ce(r){var t;return(t=r??$e.Promise)!==null&&t!==void 0?t:Promise}function Be(r){return r&&p(r.next)&&p(r.error)&&p(r.complete)}function Ke(r){return r&&r instanceof q||Be(r)&&se(r)}function Ye(r){return p(r==null?void 0:r.lift)}function C(r){return function(t){if(Ye(t))return t.lift(function(e){try{return r(e,this)}catch(n){this.error(n)}});throw new TypeError("Unable to lift unknown Observable type")}}function I(r,t,e,n,i){return new qe(r,t,e,n,i)}var qe=(function(r){O(t,r);function t(e,n,i,o,s,c){var u=r.call(this,e)||this;return u.onFinalize=s,u.shouldUnsubscribe=c,u._next=n?function(a){try{n(a)}catch(l){e.error(l)}}:r.prototype._next,u._error=o?function(a){try{o(a)}catch(l){e.error(l)}finally{this.unsubscribe()}}:r.prototype._error,u._complete=i?function(){try{i()}catch(a){e.error(a)}finally{this.unsubscribe()}}:r.prototype._complete,u}return t.prototype.unsubscribe=function(){var e;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var n=this.closed;r.prototype.unsubscribe.call(this),!n&&((e=this.onFinalize)===null||e===void 0||e.call(this))}},t})(q),We=ie(function(r){return function(){r(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}}),X=(function(r){O(t,r);function t(){var e=r.call(this)||this;return e.closed=!1,e.currentObservers=null,e.observers=[],e.isStopped=!1,e.hasError=!1,e.thrownError=null,e}return t.prototype.lift=function(e){var n=new le(this,this);return n.operator=e,n},t.prototype._throwIfClosed=function(){if(this.closed)throw new We},t.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=L(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}}}})},t.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)}})},t.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()}})},t.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(t.prototype,"observed",{get:function(){var e;return((e=this.observers)===null||e===void 0?void 0:e.length)>0},enumerable:!1,configurable:!0}),t.prototype._trySubscribe=function(e){return this._throwIfClosed(),r.prototype._trySubscribe.call(this,e)},t.prototype._subscribe=function(e){return this._throwIfClosed(),this._checkFinalizedStatuses(e),this._innerSubscribe(e)},t.prototype._innerSubscribe=function(e){var n=this,i=this,o=i.hasError,s=i.isStopped,c=i.observers;return o||s?oe:(this.currentObservers=null,c.push(e),new D(function(){n.currentObservers=null,U(c,e)}))},t.prototype._checkFinalizedStatuses=function(e){var n=this,i=n.hasError,o=n.thrownError,s=n.isStopped;i?e.error(o):s&&e.complete()},t.prototype.asObservable=function(){var e=new w;return e.source=this,e},t.create=function(e,n){return new le(e,n)},t})(w),le=(function(r){O(t,r);function t(e,n){var i=r.call(this)||this;return i.destination=e,i.source=n,i}return t.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)},t.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)},t.prototype.complete=function(){var e,n;(n=(e=this.destination)===null||e===void 0?void 0:e.complete)===null||n===void 0||n.call(e)},t.prototype._subscribe=function(e){var n,i;return(i=(n=this.source)===null||n===void 0?void 0:n.subscribe(e))!==null&&i!==void 0?i:oe},t})(X),fe=(function(r){O(t,r);function t(e){var n=r.call(this)||this;return n._value=e,n}return Object.defineProperty(t.prototype,"value",{get:function(){return this.getValue()},enumerable:!1,configurable:!0}),t.prototype._subscribe=function(e){var n=r.prototype._subscribe.call(this,e);return!n.closed&&e.next(this._value),n},t.prototype.getValue=function(){var e=this,n=e.hasError,i=e.thrownError,o=e._value;if(n)throw i;return this._throwIfClosed(),o},t.prototype.next=function(e){r.prototype.next.call(this,this._value=e)},t})(X),Je={now:function(){return Date.now()}},Xe=(function(r){O(t,r);function t(e,n){return r.call(this)||this}return t.prototype.schedule=function(e,n){return this},t})(D),he={setInterval:function(r,t){for(var e=[],n=2;n<arguments.length;n++)e[n-2]=arguments[n];return setInterval.apply(void 0,j([r,t],k(e)))},clearInterval:function(r){return clearInterval(r)},delegate:void 0},ze=(function(r){O(t,r);function t(e,n){var i=r.call(this,e,n)||this;return i.scheduler=e,i.work=n,i.pending=!1,i}return t.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},t.prototype.requestAsyncId=function(e,n,i){return i===void 0&&(i=0),he.setInterval(e.flush.bind(e,this),i)},t.prototype.recycleAsyncId=function(e,n,i){if(i===void 0&&(i=0),i!=null&&this.delay===i&&this.pending===!1)return n;n!=null&&he.clearInterval(n)},t.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))},t.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},t.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,r.prototype.unsubscribe.call(this)}},t})(Xe),de=(function(){function r(t,e){e===void 0&&(e=r.now),this.schedulerActionCtor=t,this.now=e}return r.prototype.schedule=function(t,e,n){return e===void 0&&(e=0),new this.schedulerActionCtor(this,t).schedule(n,e)},r.now=Je.now,r})(),Qe=(function(r){O(t,r);function t(e,n){n===void 0&&(n=de.now);var i=r.call(this,e,n)||this;return i.actions=[],i._active=!1,i}return t.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}},t})(de),ve=new Qe(ze),Ze=ve,et=new w(function(r){return r.complete()});function ye(r){return r&&p(r.schedule)}function pe(r){return r[r.length-1]}function tt(r){return p(pe(r))?r.pop():void 0}function be(r){return ye(pe(r))?r.pop():void 0}var me=(function(r){return r&&typeof r.length=="number"&&typeof r!="function"});function Se(r){return p(r==null?void 0:r.then)}function ge(r){return p(r[J])}function we(r){return Symbol.asyncIterator&&p(r==null?void 0:r[Symbol.asyncIterator])}function Ee(r){return new TypeError("You provided "+(r!==null&&typeof r=="object"?"an invalid object":"'"+r+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}function rt(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}var Oe=rt();function Ie(r){return p(r==null?void 0:r[Oe])}function Ae(r){return De(this,arguments,function(){var e,n,i,o;return ne(this,function(s){switch(s.label){case 0:e=r.getReader(),s.label=1;case 1:s.trys.push([1,,9,10]),s.label=2;case 2:return[4,R(e.read())];case 3:return n=s.sent(),i=n.value,o=n.done,o?[4,R(void 0)]:[3,5];case 4:return[2,s.sent()];case 5:return[4,R(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 _e(r){return p(r==null?void 0:r.getReader)}function _(r){if(r instanceof w)return r;if(r!=null){if(ge(r))return nt(r);if(me(r))return it(r);if(Se(r))return ot(r);if(we(r))return xe(r);if(Ie(r))return st(r);if(_e(r))return at(r)}throw Ee(r)}function nt(r){return new w(function(t){var e=r[J]();if(p(e.subscribe))return e.subscribe(t);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function it(r){return new w(function(t){for(var e=0;e<r.length&&!t.closed;e++)t.next(r[e]);t.complete()})}function ot(r){return new w(function(t){r.then(function(e){t.closed||(t.next(e),t.complete())},function(e){return t.error(e)}).then(null,ue)})}function st(r){return new w(function(t){var e,n;try{for(var i=L(r),o=i.next();!o.done;o=i.next()){var s=o.value;if(t.next(s),t.closed)return}}catch(c){e={error:c}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}t.complete()})}function xe(r){return new w(function(t){ut(r,t).catch(function(e){return t.error(e)})})}function at(r){return xe(Ae(r))}function ut(r,t){var e,n,i,o;return je(this,void 0,void 0,function(){var s,c;return ne(this,function(u){switch(u.label){case 0:u.trys.push([0,5,6,11]),e=Ue(r),u.label=1;case 1:return[4,e.next()];case 2:if(n=u.sent(),!!n.done)return[3,4];if(s=n.value,t.next(s),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]),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 t.complete(),[2]}})})}function x(r,t,e,n,i){n===void 0&&(n=0),i===void 0&&(i=!1);var o=t.schedule(function(){e(),i?r.add(this.schedule(null,n)):this.unsubscribe()},n);if(r.add(o),!i)return o}function Te(r,t){return t===void 0&&(t=0),C(function(e,n){e.subscribe(I(n,function(i){return x(n,r,function(){return n.next(i)},t)},function(){return x(n,r,function(){return n.complete()},t)},function(i){return x(n,r,function(){return n.error(i)},t)}))})}function Ce(r,t){return t===void 0&&(t=0),C(function(e,n){n.add(r.schedule(function(){return e.subscribe(n)},t))})}function ct(r,t){return _(r).pipe(Ce(t),Te(t))}function lt(r,t){return _(r).pipe(Ce(t),Te(t))}function ft(r,t){return new w(function(e){var n=0;return t.schedule(function(){n===r.length?e.complete():(e.next(r[n++]),e.closed||this.schedule())})})}function ht(r,t){return new w(function(e){var n;return x(e,t,function(){n=r[Oe](),x(e,t,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 p(n==null?void 0:n.return)&&n.return()}})}function Pe(r,t){if(!r)throw new Error("Iterable cannot be null");return new w(function(e){x(e,t,function(){var n=r[Symbol.asyncIterator]();x(e,t,function(){n.next().then(function(i){i.done?e.complete():e.next(i.value)})},0,!0)})})}function dt(r,t){return Pe(Ae(r),t)}function vt(r,t){if(r!=null){if(ge(r))return ct(r,t);if(me(r))return ft(r,t);if(Se(r))return lt(r,t);if(we(r))return Pe(r,t);if(Ie(r))return ht(r,t);if(_e(r))return dt(r,t)}throw Ee(r)}function z(r,t){return t?vt(r,t):_(r)}function yt(){for(var r=[],t=0;t<arguments.length;t++)r[t]=arguments[t];var e=be(r);return z(r,e)}function pt(r){return r instanceof Date&&!isNaN(r)}function F(r,t){return C(function(e,n){var i=0;e.subscribe(I(n,function(o){n.next(r.call(t,o,i++))}))})}var bt=Array.isArray;function mt(r,t){return bt(t)?r.apply(void 0,j([],k(t))):r(t)}function St(r){return F(function(t){return mt(r,t)})}var gt=Array.isArray,wt=Object.getPrototypeOf,Et=Object.prototype,Ot=Object.keys;function It(r){if(r.length===1){var t=r[0];if(gt(t))return{args:t,keys:null};if(At(t)){var e=Ot(t);return{args:e.map(function(n){return t[n]}),keys:e}}}return{args:r,keys:null}}function At(r){return r&&typeof r=="object"&&wt(r)===Et}function _t(r,t){return r.reduce(function(e,n,i){return e[n]=t[i],e},{})}function xt(){for(var r=[],t=0;t<arguments.length;t++)r[t]=arguments[t];var e=be(r),n=tt(r),i=It(r),o=i.args,s=i.keys;if(o.length===0)return z([],e);var c=new w(Tt(o,e,s?function(u){return _t(s,u)}:G));return n?c.pipe(St(n)):c}function Tt(r,t,e){return e===void 0&&(e=G),function(n){Me(t,function(){for(var i=r.length,o=new Array(i),s=i,c=i,u=function(l){Me(t,function(){var v=z(r[l],t),b=!1;v.subscribe(I(n,function(f){o[l]=f,b||(b=!0,c--),c||n.next(e(o.slice()))},function(){--s||n.complete()}))},n)},a=0;a<i;a++)u(a)},n)}}function Me(r,t,e){r?x(e,r,t):t()}function Ct(r,t,e,n,i,o,s,c){var u=[],a=0,l=0,v=!1,b=function(){v&&!u.length&&!a&&t.complete()},f=function(d){return a<n?y(d):u.push(d)},y=function(d){a++;var E=!1;_(e(d,l++)).subscribe(I(t,function(A){t.next(A)},function(){E=!0},void 0,function(){if(E)try{a--;for(var A=function(){var M=u.shift();s||y(M)};u.length&&a<n;)A();b()}catch(M){t.error(M)}}))};return r.subscribe(I(t,f,function(){v=!0,b()})),function(){}}function H(r,t,e){return e===void 0&&(e=1/0),p(t)?H(function(n,i){return F(function(o,s){return t(n,o,i,s)})(_(r(n,i)))},e):(typeof t=="number"&&(e=t),C(function(n,i){return Ct(n,i,r,e)}))}function Le(r,t,e){r===void 0&&(r=0),e===void 0&&(e=Ze);var n=-1;return t!=null&&(ye(t)?e=t:n=t),new w(function(i){var o=pt(r)?+r-e.now():r;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 Pt(r,t){return p(t)?H(r,t,1):H(r,1)}function Mt(r){return r<=0?function(){return et}:C(function(t,e){var n=0;t.subscribe(I(e,function(i){++n<=r&&(e.next(i),r<=n&&e.complete())}))})}function Lt(r){return F(function(){return r})}function Rt(r,t){return H(function(e,n){return _(r(e,n)).pipe(Mt(1),Lt(e))})}function kt(r,t){t===void 0&&(t=ve);var e=Le(r,t);return Rt(function(){return e})}function jt(r){var t;t={count:r};var e=t.count,n=e===void 0?1/0:e,i=t.delay,o=t.resetOnSuccess,s=o===void 0?!1:o;return n<=0?G:C(function(c,u){var a=0,l,v=function(){var b=!1;l=c.subscribe(I(u,function(f){s&&(a=0),u.next(f)},void 0,function(f){if(a++<n){var y=function(){l?(l.unsubscribe(),l=null,v()):b=!0};if(i!=null){var d=typeof i=="number"?Le(i):_(i(f,a)),E=I(u,function(){E.unsubscribe(),y()},function(){u.complete()});d.subscribe(E)}else y()}else u.error(f)})),b&&(l.unsubscribe(),l=null,v())};v()})}function Dt(r){return C(function(t,e){_(r).subscribe(I(e,function(){return e.complete()},Y)),!e.closed&&t.subscribe(e)})}async function Ut(r,t){const e=r.getReader();let n;for(;!(n=await e.read()).done;)t(n.value)}function $t(r){let t,e,n,i=!1;return function(s){t===void 0?(t=s,e=0,n=-1):t=Gt(t,s);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:n===-1&&(n=e-u);break;case 13:i=!0;case 10:a=e;break}if(a===-1)break;r(t.subarray(u,a),n),u=e,n=-1}u===c?t=void 0:u!==0&&(t=t.subarray(u),e-=u)}}function Nt(r,t,e){let n=Re();const i=new TextDecoder;return function(s,c){if(s.length===0)e==null||e(n),n=Re();else if(c>0){const u=i.decode(s.subarray(0,c)),a=c+(s[c+1]===32?2:1),l=i.decode(s.subarray(a));switch(u){case"data":n.data=n.data?n.data+`
|
|
4
|
-
`+l:l;break;case"event":n.event=l;break;case"id":r(n.id=l);break;case"retry":const v=parseInt(l,10);isNaN(v)||t(n.retry=v);break}}}}function Gt(r,t){const e=new Uint8Array(r.length+t.length);return e.set(r),e.set(t,r.length),e}function Re(){return{data:"",event:"",id:"",retry:void 0}}var Ft=function(r,t){var e={};for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&t.indexOf(n)<0&&(e[n]=r[n]);if(r!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(r);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(r,n[i])&&(e[n[i]]=r[n[i]]);return e};const Q="text/event-stream",Ht=1e3,ke="last-event-id";function Vt(r,t){var{signal:e,headers:n,onopen:i,onmessage:o,onclose:s,onerror:c,openWhenHidden:u,fetch:a}=t,l=Ft(t,["signal","headers","onopen","onmessage","onclose","onerror","openWhenHidden","fetch"]);return new Promise((v,b)=>{const f=Object.assign({},n);f.accept||(f.accept=Q);let y;function d(){y.abort(),document.hidden||ee()}u||document.addEventListener("visibilitychange",d);let E=Ht,A=0;function M(){document.removeEventListener("visibilitychange",d),window.clearTimeout(A),y.abort()}e==null||e.addEventListener("abort",()=>{M(),v()});const Wt=a??window.fetch,
|
|
3
|
+
`):"",this.name="UnsubscriptionError",this.errors=e}});function U(r,t){if(r){var e=r.indexOf(t);0<=e&&r.splice(e,1)}}var $=(function(){function r(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}return r.prototype.unsubscribe=function(){var t,e,n,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=L(s),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 s.remove(this);var l=this.initialTeardown;if(p(l))try{l()}catch(d){o=d instanceof B?d.errors:[d]}var v=this._finalizers;if(v){this._finalizers=null;try{for(var b=L(v),f=b.next();!f.done;f=b.next()){var y=f.value;try{ae(y)}catch(d){o=o??[],d instanceof B?o=j(j([],k(o)),k(d.errors)):o.push(d)}}}catch(d){n={error:d}}finally{try{f&&!f.done&&(i=b.return)&&i.call(b)}finally{if(n)throw n.error}}}if(o)throw new B(o)}},r.prototype.add=function(t){var e;if(t&&t!==this)if(this.closed)ae(t);else{if(t instanceof r){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=(e=this._finalizers)!==null&&e!==void 0?e:[]).push(t)}},r.prototype._hasParent=function(t){var e=this._parentage;return e===t||Array.isArray(e)&&e.includes(t)},r.prototype._addParent=function(t){var e=this._parentage;this._parentage=Array.isArray(e)?(e.push(t),e):e?[e,t]:t},r.prototype._removeParent=function(t){var e=this._parentage;e===t?this._parentage=null:Array.isArray(e)&&U(e,t)},r.prototype.remove=function(t){var e=this._finalizers;e&&U(e,t),t instanceof r&&t._removeParent(this)},r.EMPTY=(function(){var t=new r;return t.closed=!0,t})(),r})(),oe=$.EMPTY;function se(r){return r instanceof $||r&&"closed"in r&&p(r.remove)&&p(r.add)&&p(r.unsubscribe)}function ae(r){p(r)?r():r.unsubscribe()}var De={Promise:void 0},Ne={setTimeout:function(r,t){for(var e=[],n=2;n<arguments.length;n++)e[n-2]=arguments[n];return setTimeout.apply(void 0,j([r,t],k(e)))},clearTimeout:function(r){return clearTimeout(r)},delegate:void 0};function ue(r){Ne.setTimeout(function(){throw r})}function Y(){}function D(r){r()}var q=(function(r){O(t,r);function t(e){var n=r.call(this)||this;return n.isStopped=!1,e?(n.destination=e,se(e)&&e.add(n)):n.destination=He,n}return t.create=function(e,n,i){return new W(e,n,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,r.prototype.unsubscribe.call(this),this.destination=null)},t.prototype._next=function(e){this.destination.next(e)},t.prototype._error=function(e){try{this.destination.error(e)}finally{this.unsubscribe()}},t.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},t})($),Ge=(function(){function r(t){this.partialObserver=t}return r.prototype.next=function(t){var e=this.partialObserver;if(e.next)try{e.next(t)}catch(n){N(n)}},r.prototype.error=function(t){var e=this.partialObserver;if(e.error)try{e.error(t)}catch(n){N(n)}else N(t)},r.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(e){N(e)}},r})(),W=(function(r){O(t,r);function t(e,n,i){var o=r.call(this)||this,s;return p(e)||!e?s={next:e??void 0,error:n??void 0,complete:i??void 0}:s=e,o.destination=new Ge(s),o}return t})(q);function N(r){ue(r)}function Fe(r){throw r}var He={closed:!0,next:Y,error:Fe,complete:Y},X=(function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"})();function G(r){return r}function Ve(r){return r.length===0?G:r.length===1?r[0]:function(e){return r.reduce(function(n,i){return i(n)},e)}}var w=(function(){function r(t){t&&(this._subscribe=t)}return r.prototype.lift=function(t){var e=new r;return e.source=this,e.operator=t,e},r.prototype.subscribe=function(t,e,n){var i=this,o=Be(t)?t:new W(t,e,n);return D(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},r.prototype._trySubscribe=function(t){try{return this._subscribe(t)}catch(e){t.error(e)}},r.prototype.forEach=function(t,e){var n=this;return e=ce(e),new e(function(i,o){var s=new W({next:function(c){try{t(c)}catch(u){o(u),s.unsubscribe()}},error:o,complete:i});n.subscribe(s)})},r.prototype._subscribe=function(t){var e;return(e=this.source)===null||e===void 0?void 0:e.subscribe(t)},r.prototype[X]=function(){return this},r.prototype.pipe=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return Ve(t)(this)},r.prototype.toPromise=function(t){var e=this;return t=ce(t),new t(function(n,i){var o;e.subscribe(function(s){return o=s},function(s){return i(s)},function(){return n(o)})})},r.create=function(t){return new r(t)},r})();function ce(r){var t;return(t=r??De.Promise)!==null&&t!==void 0?t:Promise}function Ke(r){return r&&p(r.next)&&p(r.error)&&p(r.complete)}function Be(r){return r&&r instanceof q||Ke(r)&&se(r)}function Ye(r){return p(r==null?void 0:r.lift)}function T(r){return function(t){if(Ye(t))return t.lift(function(e){try{return r(e,this)}catch(n){this.error(n)}});throw new TypeError("Unable to lift unknown Observable type")}}function I(r,t,e,n,i){return new qe(r,t,e,n,i)}var qe=(function(r){O(t,r);function t(e,n,i,o,s,c){var u=r.call(this,e)||this;return u.onFinalize=s,u.shouldUnsubscribe=c,u._next=n?function(a){try{n(a)}catch(l){e.error(l)}}:r.prototype._next,u._error=o?function(a){try{o(a)}catch(l){e.error(l)}finally{this.unsubscribe()}}:r.prototype._error,u._complete=i?function(){try{i()}catch(a){e.error(a)}finally{this.unsubscribe()}}:r.prototype._complete,u}return t.prototype.unsubscribe=function(){var e;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var n=this.closed;r.prototype.unsubscribe.call(this),!n&&((e=this.onFinalize)===null||e===void 0||e.call(this))}},t})(q),We=ie(function(r){return function(){r(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}}),J=(function(r){O(t,r);function t(){var e=r.call(this)||this;return e.closed=!1,e.currentObservers=null,e.observers=[],e.isStopped=!1,e.hasError=!1,e.thrownError=null,e}return t.prototype.lift=function(e){var n=new le(this,this);return n.operator=e,n},t.prototype._throwIfClosed=function(){if(this.closed)throw new We},t.prototype.next=function(e){var n=this;D(function(){var i,o;if(n._throwIfClosed(),!n.isStopped){n.currentObservers||(n.currentObservers=Array.from(n.observers));try{for(var s=L(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}}}})},t.prototype.error=function(e){var n=this;D(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)}})},t.prototype.complete=function(){var e=this;D(function(){if(e._throwIfClosed(),!e.isStopped){e.isStopped=!0;for(var n=e.observers;n.length;)n.shift().complete()}})},t.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(t.prototype,"observed",{get:function(){var e;return((e=this.observers)===null||e===void 0?void 0:e.length)>0},enumerable:!1,configurable:!0}),t.prototype._trySubscribe=function(e){return this._throwIfClosed(),r.prototype._trySubscribe.call(this,e)},t.prototype._subscribe=function(e){return this._throwIfClosed(),this._checkFinalizedStatuses(e),this._innerSubscribe(e)},t.prototype._innerSubscribe=function(e){var n=this,i=this,o=i.hasError,s=i.isStopped,c=i.observers;return o||s?oe:(this.currentObservers=null,c.push(e),new $(function(){n.currentObservers=null,U(c,e)}))},t.prototype._checkFinalizedStatuses=function(e){var n=this,i=n.hasError,o=n.thrownError,s=n.isStopped;i?e.error(o):s&&e.complete()},t.prototype.asObservable=function(){var e=new w;return e.source=this,e},t.create=function(e,n){return new le(e,n)},t})(w),le=(function(r){O(t,r);function t(e,n){var i=r.call(this)||this;return i.destination=e,i.source=n,i}return t.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)},t.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)},t.prototype.complete=function(){var e,n;(n=(e=this.destination)===null||e===void 0?void 0:e.complete)===null||n===void 0||n.call(e)},t.prototype._subscribe=function(e){var n,i;return(i=(n=this.source)===null||n===void 0?void 0:n.subscribe(e))!==null&&i!==void 0?i:oe},t})(J),fe=(function(r){O(t,r);function t(e){var n=r.call(this)||this;return n._value=e,n}return Object.defineProperty(t.prototype,"value",{get:function(){return this.getValue()},enumerable:!1,configurable:!0}),t.prototype._subscribe=function(e){var n=r.prototype._subscribe.call(this,e);return!n.closed&&e.next(this._value),n},t.prototype.getValue=function(){var e=this,n=e.hasError,i=e.thrownError,o=e._value;if(n)throw i;return this._throwIfClosed(),o},t.prototype.next=function(e){r.prototype.next.call(this,this._value=e)},t})(J),Xe={now:function(){return Date.now()}},Je=(function(r){O(t,r);function t(e,n){return r.call(this)||this}return t.prototype.schedule=function(e,n){return this},t})($),he={setInterval:function(r,t){for(var e=[],n=2;n<arguments.length;n++)e[n-2]=arguments[n];return setInterval.apply(void 0,j([r,t],k(e)))},clearInterval:function(r){return clearInterval(r)},delegate:void 0},ze=(function(r){O(t,r);function t(e,n){var i=r.call(this,e,n)||this;return i.scheduler=e,i.work=n,i.pending=!1,i}return t.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},t.prototype.requestAsyncId=function(e,n,i){return i===void 0&&(i=0),he.setInterval(e.flush.bind(e,this),i)},t.prototype.recycleAsyncId=function(e,n,i){if(i===void 0&&(i=0),i!=null&&this.delay===i&&this.pending===!1)return n;n!=null&&he.clearInterval(n)},t.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))},t.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},t.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,r.prototype.unsubscribe.call(this)}},t})(Je),de=(function(){function r(t,e){e===void 0&&(e=r.now),this.schedulerActionCtor=t,this.now=e}return r.prototype.schedule=function(t,e,n){return e===void 0&&(e=0),new this.schedulerActionCtor(this,t).schedule(n,e)},r.now=Xe.now,r})(),Qe=(function(r){O(t,r);function t(e,n){n===void 0&&(n=de.now);var i=r.call(this,e,n)||this;return i.actions=[],i._active=!1,i}return t.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}},t})(de),ve=new Qe(ze),Ze=ve,et=new w(function(r){return r.complete()});function ye(r){return r&&p(r.schedule)}function pe(r){return r[r.length-1]}function tt(r){return p(pe(r))?r.pop():void 0}function be(r){return ye(pe(r))?r.pop():void 0}var me=(function(r){return r&&typeof r.length=="number"&&typeof r!="function"});function ge(r){return p(r==null?void 0:r.then)}function Se(r){return p(r[X])}function we(r){return Symbol.asyncIterator&&p(r==null?void 0:r[Symbol.asyncIterator])}function Ee(r){return new TypeError("You provided "+(r!==null&&typeof r=="object"?"an invalid object":"'"+r+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}function rt(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}var Oe=rt();function Ie(r){return p(r==null?void 0:r[Oe])}function Ae(r){return $e(this,arguments,function(){var e,n,i,o;return ne(this,function(s){switch(s.label){case 0:e=r.getReader(),s.label=1;case 1:s.trys.push([1,,9,10]),s.label=2;case 2:return[4,R(e.read())];case 3:return n=s.sent(),i=n.value,o=n.done,o?[4,R(void 0)]:[3,5];case 4:return[2,s.sent()];case 5:return[4,R(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 _e(r){return p(r==null?void 0:r.getReader)}function _(r){if(r instanceof w)return r;if(r!=null){if(Se(r))return nt(r);if(me(r))return it(r);if(ge(r))return ot(r);if(we(r))return xe(r);if(Ie(r))return st(r);if(_e(r))return at(r)}throw Ee(r)}function nt(r){return new w(function(t){var e=r[X]();if(p(e.subscribe))return e.subscribe(t);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function it(r){return new w(function(t){for(var e=0;e<r.length&&!t.closed;e++)t.next(r[e]);t.complete()})}function ot(r){return new w(function(t){r.then(function(e){t.closed||(t.next(e),t.complete())},function(e){return t.error(e)}).then(null,ue)})}function st(r){return new w(function(t){var e,n;try{for(var i=L(r),o=i.next();!o.done;o=i.next()){var s=o.value;if(t.next(s),t.closed)return}}catch(c){e={error:c}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}t.complete()})}function xe(r){return new w(function(t){ut(r,t).catch(function(e){return t.error(e)})})}function at(r){return xe(Ae(r))}function ut(r,t){var e,n,i,o;return je(this,void 0,void 0,function(){var s,c;return ne(this,function(u){switch(u.label){case 0:u.trys.push([0,5,6,11]),e=Ue(r),u.label=1;case 1:return[4,e.next()];case 2:if(n=u.sent(),!!n.done)return[3,4];if(s=n.value,t.next(s),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]),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 t.complete(),[2]}})})}function x(r,t,e,n,i){n===void 0&&(n=0),i===void 0&&(i=!1);var o=t.schedule(function(){e(),i?r.add(this.schedule(null,n)):this.unsubscribe()},n);if(r.add(o),!i)return o}function Pe(r,t){return t===void 0&&(t=0),T(function(e,n){e.subscribe(I(n,function(i){return x(n,r,function(){return n.next(i)},t)},function(){return x(n,r,function(){return n.complete()},t)},function(i){return x(n,r,function(){return n.error(i)},t)}))})}function Te(r,t){return t===void 0&&(t=0),T(function(e,n){n.add(r.schedule(function(){return e.subscribe(n)},t))})}function ct(r,t){return _(r).pipe(Te(t),Pe(t))}function lt(r,t){return _(r).pipe(Te(t),Pe(t))}function ft(r,t){return new w(function(e){var n=0;return t.schedule(function(){n===r.length?e.complete():(e.next(r[n++]),e.closed||this.schedule())})})}function ht(r,t){return new w(function(e){var n;return x(e,t,function(){n=r[Oe](),x(e,t,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 p(n==null?void 0:n.return)&&n.return()}})}function Ce(r,t){if(!r)throw new Error("Iterable cannot be null");return new w(function(e){x(e,t,function(){var n=r[Symbol.asyncIterator]();x(e,t,function(){n.next().then(function(i){i.done?e.complete():e.next(i.value)})},0,!0)})})}function dt(r,t){return Ce(Ae(r),t)}function vt(r,t){if(r!=null){if(Se(r))return ct(r,t);if(me(r))return ft(r,t);if(ge(r))return lt(r,t);if(we(r))return Ce(r,t);if(Ie(r))return ht(r,t);if(_e(r))return dt(r,t)}throw Ee(r)}function z(r,t){return t?vt(r,t):_(r)}function yt(){for(var r=[],t=0;t<arguments.length;t++)r[t]=arguments[t];var e=be(r);return z(r,e)}function pt(r){return r instanceof Date&&!isNaN(r)}function F(r,t){return T(function(e,n){var i=0;e.subscribe(I(n,function(o){n.next(r.call(t,o,i++))}))})}var bt=Array.isArray;function mt(r,t){return bt(t)?r.apply(void 0,j([],k(t))):r(t)}function gt(r){return F(function(t){return mt(r,t)})}var St=Array.isArray,wt=Object.getPrototypeOf,Et=Object.prototype,Ot=Object.keys;function It(r){if(r.length===1){var t=r[0];if(St(t))return{args:t,keys:null};if(At(t)){var e=Ot(t);return{args:e.map(function(n){return t[n]}),keys:e}}}return{args:r,keys:null}}function At(r){return r&&typeof r=="object"&&wt(r)===Et}function _t(r,t){return r.reduce(function(e,n,i){return e[n]=t[i],e},{})}function xt(){for(var r=[],t=0;t<arguments.length;t++)r[t]=arguments[t];var e=be(r),n=tt(r),i=It(r),o=i.args,s=i.keys;if(o.length===0)return z([],e);var c=new w(Pt(o,e,s?function(u){return _t(s,u)}:G));return n?c.pipe(gt(n)):c}function Pt(r,t,e){return e===void 0&&(e=G),function(n){Me(t,function(){for(var i=r.length,o=new Array(i),s=i,c=i,u=function(l){Me(t,function(){var v=z(r[l],t),b=!1;v.subscribe(I(n,function(f){o[l]=f,b||(b=!0,c--),c||n.next(e(o.slice()))},function(){--s||n.complete()}))},n)},a=0;a<i;a++)u(a)},n)}}function Me(r,t,e){r?x(e,r,t):t()}function Tt(r,t,e,n,i,o,s,c){var u=[],a=0,l=0,v=!1,b=function(){v&&!u.length&&!a&&t.complete()},f=function(d){return a<n?y(d):u.push(d)},y=function(d){a++;var E=!1;_(e(d,l++)).subscribe(I(t,function(A){t.next(A)},function(){E=!0},void 0,function(){if(E)try{a--;for(var A=function(){var M=u.shift();s||y(M)};u.length&&a<n;)A();b()}catch(M){t.error(M)}}))};return r.subscribe(I(t,f,function(){v=!0,b()})),function(){}}function H(r,t,e){return e===void 0&&(e=1/0),p(t)?H(function(n,i){return F(function(o,s){return t(n,o,i,s)})(_(r(n,i)))},e):(typeof t=="number"&&(e=t),T(function(n,i){return Tt(n,i,r,e)}))}function Le(r,t,e){r===void 0&&(r=0),e===void 0&&(e=Ze);var n=-1;return t!=null&&(ye(t)?e=t:n=t),new w(function(i){var o=pt(r)?+r-e.now():r;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 Ct(r,t){return p(t)?H(r,t,1):H(r,1)}function Mt(r){return r<=0?function(){return et}:T(function(t,e){var n=0;t.subscribe(I(e,function(i){++n<=r&&(e.next(i),r<=n&&e.complete())}))})}function Lt(r){return F(function(){return r})}function Rt(r,t){return H(function(e,n){return _(r(e,n)).pipe(Mt(1),Lt(e))})}function kt(r,t){t===void 0&&(t=ve);var e=Le(r,t);return Rt(function(){return e})}function jt(r){var t;t={count:r};var e=t.count,n=e===void 0?1/0:e,i=t.delay,o=t.resetOnSuccess,s=o===void 0?!1:o;return n<=0?G:T(function(c,u){var a=0,l,v=function(){var b=!1;l=c.subscribe(I(u,function(f){s&&(a=0),u.next(f)},void 0,function(f){if(a++<n){var y=function(){l?(l.unsubscribe(),l=null,v()):b=!0};if(i!=null){var d=typeof i=="number"?Le(i):_(i(f,a)),E=I(u,function(){E.unsubscribe(),y()},function(){u.complete()});d.subscribe(E)}else y()}else u.error(f)})),b&&(l.unsubscribe(),l=null,v())};v()})}function $t(r){return T(function(t,e){_(r).subscribe(I(e,function(){return e.complete()},Y)),!e.closed&&t.subscribe(e)})}async function Ut(r,t){const e=r.getReader();let n;for(;!(n=await e.read()).done;)t(n.value)}function Dt(r){let t,e,n,i=!1;return function(s){t===void 0?(t=s,e=0,n=-1):t=Gt(t,s);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:n===-1&&(n=e-u);break;case 13:i=!0;case 10:a=e;break}if(a===-1)break;r(t.subarray(u,a),n),u=e,n=-1}u===c?t=void 0:u!==0&&(t=t.subarray(u),e-=u)}}function Nt(r,t,e){let n=Re();const i=new TextDecoder;return function(s,c){if(s.length===0)e==null||e(n),n=Re();else if(c>0){const u=i.decode(s.subarray(0,c)),a=c+(s[c+1]===32?2:1),l=i.decode(s.subarray(a));switch(u){case"data":n.data=n.data?n.data+`
|
|
4
|
+
`+l:l;break;case"event":n.event=l;break;case"id":r(n.id=l);break;case"retry":const v=parseInt(l,10);isNaN(v)||t(n.retry=v);break}}}}function Gt(r,t){const e=new Uint8Array(r.length+t.length);return e.set(r),e.set(t,r.length),e}function Re(){return{data:"",event:"",id:"",retry:void 0}}var Ft=function(r,t){var e={};for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&t.indexOf(n)<0&&(e[n]=r[n]);if(r!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(r);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(r,n[i])&&(e[n[i]]=r[n[i]]);return e};const Q="text/event-stream",Ht=1e3,ke="last-event-id";function Vt(r,t){var{signal:e,headers:n,onopen:i,onmessage:o,onclose:s,onerror:c,openWhenHidden:u,fetch:a}=t,l=Ft(t,["signal","headers","onopen","onmessage","onclose","onerror","openWhenHidden","fetch"]);return new Promise((v,b)=>{const f=Object.assign({},n);f.accept||(f.accept=Q);let y;function d(){y.abort(),document.hidden||ee()}u||document.addEventListener("visibilitychange",d);let E=Ht,A=0;function M(){document.removeEventListener("visibilitychange",d),window.clearTimeout(A),y.abort()}e==null||e.addEventListener("abort",()=>{M(),v()});const Wt=a??window.fetch,Xt=i??Kt;async function ee(){var te;y=new AbortController;try{const V=await Wt(r,Object.assign(Object.assign({},l),{headers:f,signal:y.signal}));await Xt(V),await Ut(V.body,Dt(Nt(P=>{P?f[ke]=P:delete f[ke]},P=>{E=P},o))),s==null||s(),M(),v()}catch(V){if(!y.signal.aborted)try{const P=(te=c==null?void 0:c(V))!==null&&te!==void 0?te:E;window.clearTimeout(A),A=window.setTimeout(ee,P)}catch(P){M(),b(P)}}}ee()})}function Kt(r){const t=r.headers.get("content-type");if(!(t!=null&&t.startsWith(Q)))throw new Error(`Expected content-type to be ${Q}, Actual: ${t}`)}function Bt(r){const{endpoint:t,apiKey:e,payload:n,debugMode:i}=r;return new w(o=>{const s=new AbortController,c={"Content-Type":"application/json"};e&&(c["X-API-KEY"]=e);const u=new URLSearchParams;i&&u.set("is_debug","true");const a=new URL(t);return u.toString()&&(a.search=u.toString()),Vt(a.toString(),{method:"POST",headers:c,body:n?JSON.stringify(n):void 0,signal:s.signal,openWhenHidden:!0,onopen:async l=>{l.ok||(o.error(l),s.abort())},onmessage:l=>{o.next(JSON.parse(l.data))},onclose:()=>{o.complete()},onerror:l=>{throw o.error(l),s.abort(),l}}),()=>{s.abort()}})}class Yt{constructor(){g(this,"listeners",{})}on(t,e){this.listeners=Object.assign({},this.listeners,{[t]:(this.listeners[t]??[]).concat(e)})}off(t,e){this.listeners[t]&&(this.listeners=Object.assign({},this.listeners,{[t]:(this.listeners[t]??[]).filter(n=>n!==e)}))}remove(t){delete this.listeners[t]}emit(t,...e){this.listeners[t]&&this.listeners[t].forEach(n=>n(...e))}}class qt{constructor(t){g(this,"apiKey");g(this,"endpoint");g(this,"botProviderEndpoint");g(this,"debugMode");g(this,"destroy$",new J);g(this,"sseEmitter",new Yt);g(this,"transformSsePayload");if(!t.endpoint&&!t.botProviderEndpoint)throw new Error("Either endpoint or botProviderEndpoint must be provided");if(this.apiKey=t.apiKey,this.debugMode=t.debugMode,this.transformSsePayload=t.transformSsePayload,this.botProviderEndpoint=t.botProviderEndpoint,!t.endpoint&&t.botProviderEndpoint){const e=t.botProviderEndpoint.replace(/\/+$/,"");this.endpoint=`${e}/message/sse`}else t.endpoint&&(this.endpoint=t.endpoint,this.debugMode&&console.warn('[AsgardServiceClient] The "endpoint" option is deprecated and will be removed in the next major version. Please use "botProviderEndpoint" instead. The SSE endpoint will be automatically derived as "${botProviderEndpoint}/message/sse".'))}on(t,e){this.sseEmitter.remove(t),this.sseEmitter.on(t,e)}handleEvent(t){switch(t.eventType){case h.INIT:this.sseEmitter.emit(h.INIT,t);break;case h.PROCESS_START:case h.PROCESS_COMPLETE:this.sseEmitter.emit(h.PROCESS,t);break;case h.MESSAGE_START:case h.MESSAGE_DELTA:case h.MESSAGE_COMPLETE:this.sseEmitter.emit(h.MESSAGE,t);break;case h.TOOL_CALL_START:case h.TOOL_CALL_COMPLETE:this.sseEmitter.emit(h.TOOL_CALL,t);break;case h.DONE:this.sseEmitter.emit(h.DONE,t);break;case h.ERROR:this.sseEmitter.emit(h.ERROR,t);break}}fetchSse(t,e){var n,i;(n=e==null?void 0:e.onSseStart)==null||n.call(e),Bt({apiKey:this.apiKey,endpoint:this.endpoint,debugMode:this.debugMode,payload:((i=this.transformSsePayload)==null?void 0:i.call(this,t))??t}).pipe(Ct(o=>yt(o).pipe(kt((e==null?void 0:e.delayTime)??50))),$t(this.destroy$),jt(3)).subscribe({next:o=>{var s;(s=e==null?void 0:e.onSseMessage)==null||s.call(e,o),this.handleEvent(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()}async uploadFile(t,e){const n=this.deriveBlobEndpoint();if(!n)throw new Error("Unable to derive blob endpoint. Please provide botProviderEndpoint in config.");const i=new FormData;i.append("file",t),i.append("customChannelId",e);const o={};this.apiKey&&(o["X-API-KEY"]=this.apiKey);try{const s=await fetch(n,{method:"POST",headers:o,body:i});if(!s.ok)throw new Error(`Upload failed: ${s.status} ${s.statusText}`);const c=await s.json();return this.debugMode&&console.log("[AsgardServiceClient] File upload response:",c),c}catch(s){throw console.error("[AsgardServiceClient] File upload error:",s),s}}deriveBlobEndpoint(){if(!this.botProviderEndpoint&&!this.endpoint)return null;let t=this.botProviderEndpoint;if(!t&&this.endpoint&&(t=this.endpoint.replace("/message/sse","")),!t)return null;if(t=t.replace(/\/+$/,""),!t.includes("/generic/")){const e=t.match(/^(https?:\/\/[^/]+)(\/.*)/);if(e){const[,n,i]=e;t=`${n}/generic${i}`}}return`${t}/blob`}}class Z{constructor(t){g(this,"client");g(this,"customChannelId");g(this,"customMessageId");g(this,"isConnecting$");g(this,"conversation$");g(this,"statesObserver");g(this,"statesSubscription");if(!t.client)throw new Error("client must be required");if(!t.customChannelId)throw new Error("customChannelId must be required");this.client=t.client,this.customChannelId=t.customChannelId,this.customMessageId=t.customMessageId,this.isConnecting$=new fe(!1),this.conversation$=new fe(t.conversation),this.statesObserver=t.statesObserver}static async reset(t,e,n){const i=new Z(t);try{return i.subscribe(),await i.resetChannel(e,n),i}catch(o){throw i.close(),o}}subscribe(){this.statesSubscription=xt([this.isConnecting$,this.conversation$]).pipe(F(([t,e])=>({isConnecting:t,conversation:e}))).subscribe(this.statesObserver)}fetchSse(t,e){return new Promise((n,i)=>{this.isConnecting$.next(!0),this.client.fetchSse(t,{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(t,e){return this.fetchSse({action:S.RESET_CHANNEL,customChannelId:this.customChannelId,customMessageId:this.customMessageId,text:(t==null?void 0:t.text)||"",payload:t==null?void 0:t.payload},e)}sendMessage(t,e){const n=t.text.trim(),i=t.customMessageId??crypto.randomUUID();return this.conversation$.next(this.conversation$.value.pushMessage({type:"user",messageId:i,text:n,blobIds:t.blobIds,filePreviewUrls:t.filePreviewUrls,time:new Date})),this.fetchSse({action:S.NONE,customChannelId:this.customChannelId,customMessageId:i,payload:t==null?void 0:t.payload,text:n,blobIds:t==null?void 0:t.blobIds},e)}close(){var t;this.isConnecting$.complete(),this.conversation$.complete(),(t=this.statesSubscription)==null||t.unsubscribe()}}class C{constructor({messages:t}){g(this,"messages",null);this.messages=t}pushMessage(t){const e=new Map(this.messages);return e.set(t.messageId,t),new C({messages:e})}onMessage(t){switch(t.eventType){case h.MESSAGE_START:return this.onMessageStart(t);case h.MESSAGE_DELTA:return this.onMessageDelta(t);case h.MESSAGE_COMPLETE:return this.onMessageComplete(t);case h.ERROR:return this.onMessageError(t);default:return this}}onMessageStart(t){const e=t.fact.messageStart.message,n=new Map(this.messages);return n.set(e.messageId,{type:"bot",eventType:h.MESSAGE_START,isTyping:!0,typingText:"",messageId:e.messageId,message:e,time:new Date}),new C({messages:n})}onMessageDelta(t){const e=t.fact.messageDelta.message,n=new Map(this.messages),i=n.get(e.messageId);if((i==null?void 0:i.type)!=="bot")return this;const o=`${(i==null?void 0:i.typingText)??""}${e.text}`;return n.set(e.messageId,{type:"bot",eventType:h.MESSAGE_DELTA,isTyping:!0,typingText:o,messageId:e.messageId,message:e,time:new Date}),new C({messages:n})}onMessageComplete(t){const e=t.fact.messageComplete.message,n=new Map(this.messages);return n.set(e.messageId,{type:"bot",eventType:h.MESSAGE_COMPLETE,isTyping:!1,typingText:null,messageId:e.messageId,message:e,time:new Date}),new C({messages:n})}onMessageError(t){const e=crypto.randomUUID(),n=t.fact.runError.error,i=new Map(this.messages);return i.set(e,{type:"error",eventType:h.ERROR,messageId:e,error:n,time:new Date}),new C({messages:i})}}m.AsgardServiceClient=qt,m.Channel=Z,m.Conversation=C,m.EventType=h,m.FetchSseAction=S,m.MessageTemplateType=re,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})}));
|
|
5
5
|
//# sourceMappingURL=index.js.map
|