@asgard-js/core 0.2.4 → 0.2.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.
- package/README.md +0 -64
- package/dist/index.cjs +4 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1032 -1046
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -12
package/README.md
CHANGED
|
@@ -321,64 +321,6 @@ function handleAuthState(state: AuthState) {
|
|
|
321
321
|
}
|
|
322
322
|
```
|
|
323
323
|
|
|
324
|
-
<a id="testing"></a>
|
|
325
|
-
<br/>
|
|
326
|
-
|
|
327
|
-
## Testing
|
|
328
|
-
|
|
329
|
-
The core package includes comprehensive tests using Vitest.
|
|
330
|
-
|
|
331
|
-
### Running Tests
|
|
332
|
-
|
|
333
|
-
```sh
|
|
334
|
-
# Run tests once
|
|
335
|
-
npm run test:core
|
|
336
|
-
|
|
337
|
-
# Run tests in watch mode
|
|
338
|
-
npm run test:core:watch
|
|
339
|
-
|
|
340
|
-
# Run tests with UI
|
|
341
|
-
npm run test:core:ui
|
|
342
|
-
|
|
343
|
-
# Run tests with coverage
|
|
344
|
-
npm run test:core:coverage
|
|
345
|
-
```
|
|
346
|
-
|
|
347
|
-
### Test Structure
|
|
348
|
-
|
|
349
|
-
Tests are located alongside source files with `.spec.ts` extensions:
|
|
350
|
-
|
|
351
|
-
- `src/lib/client.spec.ts` - Tests for AsgardServiceClient including deprecation scenarios
|
|
352
|
-
- Test environment: jsdom with Vitest
|
|
353
|
-
- Coverage reports available in `test-output/vitest/coverage/`
|
|
354
|
-
|
|
355
|
-
### Writing Tests
|
|
356
|
-
|
|
357
|
-
The package uses Vitest for testing with the following setup:
|
|
358
|
-
|
|
359
|
-
- TypeScript support
|
|
360
|
-
- jsdom environment for DOM APIs
|
|
361
|
-
- ESLint integration
|
|
362
|
-
- Coverage reporting with v8 provider
|
|
363
|
-
|
|
364
|
-
Example test structure:
|
|
365
|
-
|
|
366
|
-
```javascript
|
|
367
|
-
import { describe, it, expect } from 'vitest';
|
|
368
|
-
import { AsgardServiceClient } from './client';
|
|
369
|
-
|
|
370
|
-
describe('AsgardServiceClient', () => {
|
|
371
|
-
it('should create client with botProviderEndpoint', () => {
|
|
372
|
-
const client = new AsgardServiceClient({
|
|
373
|
-
botProviderEndpoint: 'https://api.example.com/bot-provider/bp-123',
|
|
374
|
-
apiKey: 'test-key',
|
|
375
|
-
});
|
|
376
|
-
|
|
377
|
-
expect(client).toBeDefined();
|
|
378
|
-
});
|
|
379
|
-
});
|
|
380
|
-
```
|
|
381
|
-
|
|
382
324
|
<a id="development"></a>
|
|
383
325
|
<br/>
|
|
384
326
|
|
|
@@ -402,9 +344,6 @@ You can use the following commands to work with the core package:
|
|
|
402
344
|
# Lint the core package
|
|
403
345
|
npm run lint:core
|
|
404
346
|
|
|
405
|
-
# Run tests
|
|
406
|
-
npm run test:core
|
|
407
|
-
|
|
408
347
|
# Build the package
|
|
409
348
|
npm run build:core
|
|
410
349
|
|
|
@@ -426,9 +365,6 @@ For working with both core and React packages:
|
|
|
426
365
|
# Lint both packages
|
|
427
366
|
npm run lint:packages
|
|
428
367
|
|
|
429
|
-
# Test both packages
|
|
430
|
-
npm test
|
|
431
|
-
|
|
432
368
|
# Build core package (required for React package)
|
|
433
369
|
npm run build:core
|
|
434
370
|
npm run build:react
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
`+
|
|
3
|
-
`):"",this.name="UnsubscriptionError",this.errors=e}});function G(r,t){if(r){var e=r.indexOf(t);0<=e&&r.splice(e,1)}}var k=(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=M(s),a=c.next();!a.done;a=c.next()){var u=a.value;u.remove(this)}}catch(y){t={error:y}}finally{try{a&&!a.done&&(e=c.return)&&e.call(c)}finally{if(t)throw t.error}}else s.remove(this);var f=this.initialTeardown;if(m(f))try{f()}catch(y){o=y instanceof B?y.errors:[y]}var h=this._finalizers;if(h){this._finalizers=null;try{for(var v=M(h),l=v.next();!l.done;l=v.next()){var p=l.value;try{ne(p)}catch(y){o=o??[],y instanceof B?o=U(U([],R(o)),R(y.errors)):o.push(y)}}}catch(y){n={error:y}}finally{try{l&&!l.done&&(i=v.return)&&i.call(v)}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)ne(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)&&G(e,t)},r.prototype.remove=function(t){var e=this._finalizers;e&&G(e,t),t instanceof r&&t._removeParent(this)},r.EMPTY=(function(){var t=new r;return t.closed=!0,t})(),r})(),pe=k.EMPTY;function me(r){return r instanceof k||r&&"closed"in r&&m(r.remove)&&m(r.add)&&m(r.unsubscribe)}function ne(r){m(r)?r():r.unsubscribe()}var Ke={Promise:void 0},Be={setTimeout:function(r,t){for(var e=[],n=2;n<arguments.length;n++)e[n-2]=arguments[n];return setTimeout.apply(void 0,U([r,t],R(e)))},clearTimeout:function(r){return clearTimeout(r)},delegate:void 0};function be(r){Be.setTimeout(function(){throw r})}function X(){}function D(r){r()}var Q=(function(r){A(t,r);function t(e){var n=r.call(this)||this;return n.isStopped=!1,e?(n.destination=e,me(e)&&e.add(n)):n.destination=Xe,n}return t.create=function(e,n,i){return new J(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})(k),Ye=(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){j(n)}},r.prototype.error=function(t){var e=this.partialObserver;if(e.error)try{e.error(t)}catch(n){j(n)}else j(t)},r.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(e){j(e)}},r})(),J=(function(r){A(t,r);function t(e,n,i){var o=r.call(this)||this,s;return m(e)||!e?s={next:e??void 0,error:n??void 0,complete:i??void 0}:s=e,o.destination=new Ye(s),o}return t})(Q);function j(r){be(r)}function We(r){throw r}var Xe={closed:!0,next:X,error:We,complete:X},Z=(function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"})();function F(r){return r}function Je(r){return r.length===0?F:r.length===1?r[0]:function(e){return r.reduce(function(n,i){return i(n)},e)}}var S=(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=Qe(t)?t:new J(t,e,n);return D(function(){var s=i,c=s.operator,a=s.source;o.add(c?c.call(o,a):a?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=ie(e),new e(function(i,o){var s=new J({next:function(c){try{t(c)}catch(a){o(a),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[Z]=function(){return this},r.prototype.pipe=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return Je(t)(this)},r.prototype.toPromise=function(t){var e=this;return t=ie(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 ie(r){var t;return(t=r??Ke.Promise)!==null&&t!==void 0?t:Promise}function ze(r){return r&&m(r.next)&&m(r.error)&&m(r.complete)}function Qe(r){return r&&r instanceof Q||ze(r)&&me(r)}function Ze(r){return m(r==null?void 0:r.lift)}function P(r){return function(t){if(Ze(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 O(r,t,e,n,i){return new et(r,t,e,n,i)}var et=(function(r){A(t,r);function t(e,n,i,o,s,c){var a=r.call(this,e)||this;return a.onFinalize=s,a.shouldUnsubscribe=c,a._next=n?function(u){try{n(u)}catch(f){e.error(f)}}:r.prototype._next,a._error=o?function(u){try{o(u)}catch(f){e.error(f)}finally{this.unsubscribe()}}:r.prototype._error,a._complete=i?function(){try{i()}catch(u){e.error(u)}finally{this.unsubscribe()}}:r.prototype._complete,a}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),tt=ye(function(r){return function(){r(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}}),ee=(function(r){A(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 oe(this,this);return n.operator=e,n},t.prototype._throwIfClosed=function(){if(this.closed)throw new tt},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=M(n.currentObservers),c=s.next();!c.done;c=s.next()){var a=c.value;a.next(e)}}catch(u){i={error:u}}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?pe:(this.currentObservers=null,c.push(e),new k(function(){n.currentObservers=null,G(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 S;return e.source=this,e},t.create=function(e,n){return new oe(e,n)},t})(S),oe=(function(r){A(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:pe},t})(ee),se=(function(r){A(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})(ee),rt={now:function(){return Date.now()}},nt=(function(r){A(t,r);function t(e,n){return r.call(this)||this}return t.prototype.schedule=function(e,n){return this},t})(k),ae={setInterval:function(r,t){for(var e=[],n=2;n<arguments.length;n++)e[n-2]=arguments[n];return setInterval.apply(void 0,U([r,t],R(e)))},clearInterval:function(r){return clearInterval(r)},delegate:void 0},it=(function(r){A(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),ae.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&&ae.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,G(o,this),n!=null&&(this.id=this.recycleAsyncId(i,n,null)),this.delay=null,r.prototype.unsubscribe.call(this)}},t})(nt),ce=(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=rt.now,r})(),ot=(function(r){A(t,r);function t(e,n){n===void 0&&(n=ce.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})(ce),ge=new ot(it),st=ge,at=new S(function(r){return r.complete()});function Se(r){return r&&m(r.schedule)}function we(r){return r[r.length-1]}function ct(r){return m(we(r))?r.pop():void 0}function Ee(r){return Se(we(r))?r.pop():void 0}var Ie=(function(r){return r&&typeof r.length=="number"&&typeof r!="function"});function Oe(r){return m(r==null?void 0:r.then)}function Ae(r){return m(r[Z])}function Ce(r){return Symbol.asyncIterator&&m(r==null?void 0:r[Symbol.asyncIterator])}function Te(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 ut(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}var _e=ut();function xe(r){return m(r==null?void 0:r[_e])}function Pe(r){return Ve(this,arguments,function(){var e,n,i,o;return ve(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,L(e.read())];case 3:return n=s.sent(),i=n.value,o=n.done,o?[4,L(void 0)]:[3,5];case 4:return[2,s.sent()];case 5:return[4,L(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 Le(r){return m(r==null?void 0:r.getReader)}function _(r){if(r instanceof S)return r;if(r!=null){if(Ae(r))return lt(r);if(Ie(r))return ft(r);if(Oe(r))return dt(r);if(Ce(r))return Me(r);if(xe(r))return ht(r);if(Le(r))return vt(r)}throw Te(r)}function lt(r){return new S(function(t){var e=r[Z]();if(m(e.subscribe))return e.subscribe(t);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function ft(r){return new S(function(t){for(var e=0;e<r.length&&!t.closed;e++)t.next(r[e]);t.complete()})}function dt(r){return new S(function(t){r.then(function(e){t.closed||(t.next(e),t.complete())},function(e){return t.error(e)}).then(null,be)})}function ht(r){return new S(function(t){var e,n;try{for(var i=M(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 Me(r){return new S(function(t){yt(r,t).catch(function(e){return t.error(e)})})}function vt(r){return Me(Pe(r))}function yt(r,t){var e,n,i,o;return Fe(this,void 0,void 0,function(){var s,c;return ve(this,function(a){switch(a.label){case 0:a.trys.push([0,5,6,11]),e=qe(r),a.label=1;case 1:return[4,e.next()];case 2:if(n=a.sent(),!!n.done)return[3,4];if(s=n.value,t.next(s),t.closed)return[2];a.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return c=a.sent(),i={error:c},[3,11];case 6:return a.trys.push([6,,9,10]),n&&!n.done&&(o=e.return)?[4,o.call(e)]:[3,8];case 7:a.sent(),a.label=8;case 8:return[3,10];case 9:if(i)throw i.error;return[7];case 10:return[7];case 11:return t.complete(),[2]}})})}function T(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 Re(r,t){return t===void 0&&(t=0),P(function(e,n){e.subscribe(O(n,function(i){return T(n,r,function(){return n.next(i)},t)},function(){return T(n,r,function(){return n.complete()},t)},function(i){return T(n,r,function(){return n.error(i)},t)}))})}function Ue(r,t){return t===void 0&&(t=0),P(function(e,n){n.add(r.schedule(function(){return e.subscribe(n)},t))})}function pt(r,t){return _(r).pipe(Ue(t),Re(t))}function mt(r,t){return _(r).pipe(Ue(t),Re(t))}function bt(r,t){return new S(function(e){var n=0;return t.schedule(function(){n===r.length?e.complete():(e.next(r[n++]),e.closed||this.schedule())})})}function gt(r,t){return new S(function(e){var n;return T(e,t,function(){n=r[_e](),T(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 m(n==null?void 0:n.return)&&n.return()}})}function ke(r,t){if(!r)throw new Error("Iterable cannot be null");return new S(function(e){T(e,t,function(){var n=r[Symbol.asyncIterator]();T(e,t,function(){n.next().then(function(i){i.done?e.complete():e.next(i.value)})},0,!0)})})}function St(r,t){return ke(Pe(r),t)}function wt(r,t){if(r!=null){if(Ae(r))return pt(r,t);if(Ie(r))return bt(r,t);if(Oe(r))return mt(r,t);if(Ce(r))return ke(r,t);if(xe(r))return gt(r,t);if(Le(r))return St(r,t)}throw Te(r)}function te(r,t){return t?wt(r,t):_(r)}function Et(){for(var r=[],t=0;t<arguments.length;t++)r[t]=arguments[t];var e=Ee(r);return te(r,e)}function It(r){return r instanceof Date&&!isNaN(r)}function V(r,t){return P(function(e,n){var i=0;e.subscribe(O(n,function(o){n.next(r.call(t,o,i++))}))})}var Ot=Array.isArray;function At(r,t){return Ot(t)?r.apply(void 0,U([],R(t))):r(t)}function Ct(r){return V(function(t){return At(r,t)})}var Tt=Array.isArray,_t=Object.getPrototypeOf,xt=Object.prototype,Pt=Object.keys;function Lt(r){if(r.length===1){var t=r[0];if(Tt(t))return{args:t,keys:null};if(Mt(t)){var e=Pt(t);return{args:e.map(function(n){return t[n]}),keys:e}}}return{args:r,keys:null}}function Mt(r){return r&&typeof r=="object"&&_t(r)===xt}function Rt(r,t){return r.reduce(function(e,n,i){return e[n]=t[i],e},{})}function Ut(){for(var r=[],t=0;t<arguments.length;t++)r[t]=arguments[t];var e=Ee(r),n=ct(r),i=Lt(r),o=i.args,s=i.keys;if(o.length===0)return te([],e);var c=new S(kt(o,e,s?function(a){return Rt(s,a)}:F));return n?c.pipe(Ct(n)):c}function kt(r,t,e){return e===void 0&&(e=F),function(n){ue(t,function(){for(var i=r.length,o=new Array(i),s=i,c=i,a=function(f){ue(t,function(){var h=te(r[f],t),v=!1;h.subscribe(O(n,function(l){o[f]=l,v||(v=!0,c--),c||n.next(e(o.slice()))},function(){--s||n.complete()}))},n)},u=0;u<i;u++)a(u)},n)}}function ue(r,t,e){r?T(e,r,t):t()}function $t(r,t,e,n,i,o,s,c){var a=[],u=0,f=0,h=!1,v=function(){h&&!a.length&&!u&&t.complete()},l=function(y){return u<n?p(y):a.push(y)},p=function(y){u++;var w=!1;_(e(y,f++)).subscribe(O(t,function(I){t.next(I)},function(){w=!0},void 0,function(){if(w)try{u--;for(var I=function(){var x=a.shift();s||p(x)};a.length&&u<n;)I();v()}catch(x){t.error(x)}}))};return r.subscribe(O(t,l,function(){h=!0,v()})),function(){}}function H(r,t,e){return e===void 0&&(e=1/0),m(t)?H(function(n,i){return V(function(o,s){return t(n,o,i,s)})(_(r(n,i)))},e):(typeof t=="number"&&(e=t),P(function(n,i){return $t(n,i,r,e)}))}function $e(r,t,e){r===void 0&&(r=0),e===void 0&&(e=st);var n=-1;return t!=null&&(Se(t)?e=t:n=t),new S(function(i){var o=It(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 jt(r,t){return m(t)?H(r,t,1):H(r,1)}function Dt(r){return r<=0?function(){return at}:P(function(t,e){var n=0;t.subscribe(O(e,function(i){++n<=r&&(e.next(i),r<=n&&e.complete())}))})}function Nt(r){return V(function(){return r})}function Gt(r,t){return H(function(e,n){return _(r(e,n)).pipe(Dt(1),Nt(e))})}function Ht(r,t){t===void 0&&(t=ge);var e=$e(r,t);return Gt(function(){return e})}function Ft(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?F:P(function(c,a){var u=0,f,h=function(){var v=!1;f=c.subscribe(O(a,function(l){s&&(u=0),a.next(l)},void 0,function(l){if(u++<n){var p=function(){f?(f.unsubscribe(),f=null,h()):v=!0};if(i!=null){var y=typeof i=="number"?$e(i):_(i(l,u)),w=O(a,function(){w.unsubscribe(),p()},function(){a.complete()});y.subscribe(w)}else p()}else a.error(l)})),v&&(f.unsubscribe(),f=null,h())};h()})}function Vt(r){return P(function(t,e){_(r).subscribe(O(e,function(){return e.complete()},X)),!e.closed&&t.subscribe(e)})}async function qt(r,t){const e=r.getReader();let n;for(;!(n=await e.read()).done;)t(n.value)}function Kt(r){let t,e,n,i=!1;return function(s){t===void 0?(t=s,e=0,n=-1):t=Yt(t,s);const c=t.length;let a=0;for(;e<c;){i&&(t[e]===10&&(a=++e),i=!1);let u=-1;for(;e<c&&u===-1;++e)switch(t[e]){case 58:n===-1&&(n=e-a);break;case 13:i=!0;case 10:u=e;break}if(u===-1)break;r(t.subarray(a,u),n),a=e,n=-1}a===c?t=void 0:a!==0&&(t=t.subarray(a),e-=a)}}function Bt(r,t,e){let n=le();const i=new TextDecoder;return function(s,c){if(s.length===0)e==null||e(n),n=le();else if(c>0){const a=i.decode(s.subarray(0,c)),u=c+(s[c+1]===32?2:1),f=i.decode(s.subarray(u));switch(a){case"data":n.data=n.data?n.data+`
|
|
4
|
-
`+f:f;break;case"event":n.event=f;break;case"id":r(n.id=f);break;case"retry":const h=parseInt(f,10);isNaN(h)||t(n.retry=h);break}}}}function Yt(r,t){const e=new Uint8Array(r.length+t.length);return e.set(r),e.set(t,r.length),e}function le(){return{data:"",event:"",id:"",retry:void 0}}var Wt=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 z="text/event-stream",Xt=1e3,fe="last-event-id";function Jt(r,t){var{signal:e,headers:n,onopen:i,onmessage:o,onclose:s,onerror:c,openWhenHidden:a,fetch:u}=t,f=Wt(t,["signal","headers","onopen","onmessage","onclose","onerror","openWhenHidden","fetch"]);return new Promise((h,v)=>{const l=Object.assign({},n);l.accept||(l.accept=z);let p;function y(){p.abort(),document.hidden||q()}a||document.addEventListener("visibilitychange",y);let w=Xt,I=0;function x(){document.removeEventListener("visibilitychange",y),window.clearTimeout(I),p.abort()}e==null||e.addEventListener("abort",()=>{x(),h()});const De=u??window.fetch,Ne=i??zt;async function q(){var K;p=new AbortController;try{const $=await De(r,Object.assign(Object.assign({},f),{headers:l,signal:p.signal}));await Ne($),await qt($.body,Kt(Bt(C=>{C?l[fe]=C:delete l[fe]},C=>{w=C},o))),s==null||s(),x(),h()}catch($){if(!p.signal.aborted)try{const C=(K=c==null?void 0:c($))!==null&&K!==void 0?K:w;window.clearTimeout(I),I=window.setTimeout(q,C)}catch(C){x(),v(C)}}}q()})}function zt(r){const t=r.headers.get("content-type");if(!(t!=null&&t.startsWith(z)))throw new Error(`Expected content-type to be ${z}, Actual: ${t}`)}function Qt(r){const{endpoint:t,apiKey:e,payload:n,debugMode:i,customHeaders:o}=r;return new S(s=>{const c=new AbortController;let a;const u={"Content-Type":"application/json",...o};e&&(u["X-API-KEY"]=e);const f=new URLSearchParams;i&&f.set("is_debug","true");const h=new URL(t);return f.toString()&&(h.search=f.toString()),Jt(h.toString(),{method:"POST",headers:u,body:n?JSON.stringify(n):void 0,signal:c.signal,openWhenHidden:!0,onopen:async v=>{v.ok?a=v.headers.get("X-Trace-Id")??void 0:(s.error(v),c.abort())},onmessage:v=>{const l=JSON.parse(v.data);a?l.traceId=a:l.requestId&&(l.traceId=l.requestId,a||(a=l.requestId)),s.next(l)},onclose:()=>{s.complete()},onerror:v=>{throw s.error(v),c.abort(),v}}),()=>{c.abort()}})}class Zt{constructor(){b(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 er{constructor(t){b(this,"apiKey");b(this,"endpoint");b(this,"botProviderEndpoint");b(this,"debugMode");b(this,"destroy$",new ee);b(this,"sseEmitter",new Zt);b(this,"transformSsePayload");b(this,"customHeaders");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,this.customHeaders=t.customHeaders,!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 d.INIT:this.sseEmitter.emit(d.INIT,t);break;case d.PROCESS_START:case d.PROCESS_COMPLETE:this.sseEmitter.emit(d.PROCESS,t);break;case d.MESSAGE_START:case d.MESSAGE_DELTA:case d.MESSAGE_COMPLETE:this.sseEmitter.emit(d.MESSAGE,t);break;case d.TOOL_CALL_START:case d.TOOL_CALL_COMPLETE:this.sseEmitter.emit(d.TOOL_CALL,t);break;case d.DONE:this.sseEmitter.emit(d.DONE,t);break;case d.ERROR:this.sseEmitter.emit(d.ERROR,t);break}}fetchSse(t,e){var n,i;(n=e==null?void 0:e.onSseStart)==null||n.call(e),Qt({apiKey:this.apiKey,endpoint:this.endpoint,debugMode:this.debugMode,payload:((i=this.transformSsePayload)==null?void 0:i.call(this,t))??t,customHeaders:this.customHeaders}).pipe(jt(o=>Et(o).pipe(Ht((e==null?void 0:e.delayTime)??50))),Vt(this.destroy$),Ft(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.customHeaders};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`}}const g=[];for(let r=0;r<256;++r)g.push((r+256).toString(16).slice(1));function tr(r,t=0){return(g[r[t+0]]+g[r[t+1]]+g[r[t+2]]+g[r[t+3]]+"-"+g[r[t+4]]+g[r[t+5]]+"-"+g[r[t+6]]+g[r[t+7]]+"-"+g[r[t+8]]+g[r[t+9]]+"-"+g[r[t+10]]+g[r[t+11]]+g[r[t+12]]+g[r[t+13]]+g[r[t+14]]+g[r[t+15]]).toLowerCase()}let Y;const rr=new Uint8Array(16);function nr(){if(!Y){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Y=crypto.getRandomValues.bind(crypto)}return Y(rr)}const ir=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),de={randomUUID:ir};function or(r,t,e){var i;r=r||{};const n=r.random??((i=r.rng)==null?void 0:i.call(r))??nr();if(n.length<16)throw new Error("Random bytes length must be >= 16");return n[6]=n[6]&15|64,n[8]=n[8]&63|128,tr(n)}function je(r,t,e){return de.randomUUID&&!r?de.randomUUID():or(r)}class E{constructor({messages:t}){b(this,"messages",null);this.messages=t}pushMessage(t){const e=new Map(this.messages);return e.set(t.messageId,t),new E({messages:e})}onMessage(t){switch(t.eventType){case d.MESSAGE_START:return this.onMessageStart(t);case d.MESSAGE_DELTA:return this.onMessageDelta(t);case d.MESSAGE_COMPLETE:return this.onMessageComplete(t);case d.TOOL_CALL_START:return this.onToolCallStart(t);case d.TOOL_CALL_COMPLETE:return this.onToolCallComplete(t);case d.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:d.MESSAGE_START,isTyping:!0,typingText:"",messageId:e.messageId,message:e,time:new Date,traceId:t.traceId,raw:""}),new E({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:d.MESSAGE_DELTA,isTyping:!0,typingText:o,messageId:e.messageId,message:e,time:new Date,traceId:t.traceId??i.traceId,raw:i.raw}),new E({messages:n})}onMessageComplete(t){const e=t.fact.messageComplete.message,n=new Map(this.messages),i=n.get(e.messageId);return n.set(e.messageId,{type:"bot",eventType:d.MESSAGE_COMPLETE,isTyping:!1,typingText:null,messageId:e.messageId,message:e,time:new Date,traceId:t.traceId??((i==null?void 0:i.type)==="bot"?i.traceId:void 0),raw:JSON.stringify(t)}),new E({messages:n})}onMessageError(t){const e=je(),n=t.fact.runError.error,i=new Map(this.messages);return i.set(e,{type:"error",eventType:d.ERROR,messageId:e,error:n,time:new Date,traceId:t.traceId}),new E({messages:i})}onToolCallStart(t){const e=t.fact.toolCallStart,n=new Map(this.messages),i=`${e.processId}-${e.callSeq}`,o={type:"tool-call",eventType:d.TOOL_CALL_START,messageId:i,processId:e.processId,callSeq:e.callSeq,toolName:e.toolCall.toolName,toolsetName:e.toolCall.toolsetName,parameter:e.toolCall.parameter,isComplete:!1,time:new Date,traceId:t.traceId};return n.set(i,o),new E({messages:n})}onToolCallComplete(t){const e=t.fact.toolCallComplete,n=new Map(this.messages),i=`${e.processId}-${e.callSeq}`,o=n.get(i);if((o==null?void 0:o.type)==="tool-call"){const s={...o,eventType:d.TOOL_CALL_COMPLETE,result:e.toolCallResult,isComplete:!0,traceId:t.traceId??o.traceId};n.set(i,s)}return new E({messages:n})}}class re{constructor(t){b(this,"client");b(this,"customChannelId");b(this,"customMessageId");b(this,"isConnecting$");b(this,"conversation$");b(this,"statesObserver");b(this,"statesSubscription");b(this,"currentUserMessageId");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 se(!1),this.conversation$=new se(t.conversation),this.statesObserver=t.statesObserver}static async reset(t,e,n){const i=new re(t);try{return i.subscribe(),await i.resetChannel(e,n),i}catch(o){throw i.close(),o}}subscribe(){this.statesSubscription=Ut([this.isConnecting$,this.conversation$]).pipe(V(([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;if((s=e==null?void 0:e.onSseMessage)==null||s.call(e,o),this.currentUserMessageId&&o.traceId){const c=new Map(this.conversation$.value.messages),a=c.get(this.currentUserMessageId);a&&a.type==="user"&&(c.set(this.currentUserMessageId,{...a,traceId:o.traceId}),this.conversation$.next(new E({messages:c}))),this.currentUserMessageId=void 0}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),this.currentUserMessageId=void 0,i(o)},onSseCompleted:()=>{var o;(o=e==null?void 0:e.onSseCompleted)==null||o.call(e),this.isConnecting$.next(!1),this.currentUserMessageId=void 0,n()}})})}resetChannel(t,e){return this.fetchSse({action:N.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??je();return this.currentUserMessageId=i,this.conversation$.next(this.conversation$.value.pushMessage({type:"user",messageId:i,text:n,blobIds:t.blobIds,filePreviewUrls:t.filePreviewUrls,documentNames:t.documentNames,time:new Date})),this.fetchSse({action:N.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()}}exports.AsgardServiceClient=er;exports.Channel=re;exports.Conversation=E;exports.EventType=d;exports.FetchSseAction=N;exports.MessageTemplateType=he;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var D=(r=>(r.RESET_CHANNEL="RESET_CHANNEL",r.NONE="NONE",r))(D||{}),d=(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))(d||{}),de=(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.TABLE="TABLE",r))(de||{}),Y=function(r,e){return Y=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o])},Y(r,e)};function O(r,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");Y(r,e);function t(){this.constructor=r}r.prototype=e===null?Object.create(e):(t.prototype=e.prototype,new t)}function Ne(r,e,t,n){function o(i){return i instanceof t?i:new t(function(s){s(i)})}return new(t||(t=Promise))(function(i,s){function a(f){try{u(n.next(f))}catch(h){s(h)}}function c(f){try{u(n.throw(f))}catch(h){s(h)}}function u(f){f.done?i(f.value):o(f.value).then(a,c)}u((n=n.apply(r,e||[])).next())})}function he(r,e){var t={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,o,i,s=Object.create((typeof Iterator=="function"?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function a(u){return function(f){return c([u,f])}}function c(u){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,u[0]&&(t=0)),t;)try{if(n=1,o&&(i=u[0]&2?o.return:u[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,u[1])).done)return i;switch(o=0,i&&(u=[u[0]&2,i.value]),u[0]){case 0:case 1:i=u;break;case 4:return t.label++,{value:u[1],done:!1};case 5:t.label++,o=u[1],u=[0];continue;case 7:u=t.ops.pop(),t.trys.pop();continue;default:if(i=t.trys,!(i=i.length>0&&i[i.length-1])&&(u[0]===6||u[0]===2)){t=0;continue}if(u[0]===3&&(!i||u[1]>i[0]&&u[1]<i[3])){t.label=u[1];break}if(u[0]===6&&t.label<i[1]){t.label=i[1],i=u;break}if(i&&t.label<i[2]){t.label=i[2],t.ops.push(u);break}i[2]&&t.ops.pop(),t.trys.pop();continue}u=e.call(r,t)}catch(f){u=[6,f],o=0}finally{n=i=0}if(u[0]&5)throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}function M(r){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&r[e],n=0;if(t)return t.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(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function L(r,e){var t=typeof Symbol=="function"&&r[Symbol.iterator];if(!t)return r;var n=t.call(r),o,i=[],s;try{for(;(e===void 0||e-- >0)&&!(o=n.next()).done;)i.push(o.value)}catch(a){s={error:a}}finally{try{o&&!o.done&&(t=n.return)&&t.call(n)}finally{if(s)throw s.error}}return i}function R(r,e,t){if(t||arguments.length===2)for(var n=0,o=e.length,i;n<o;n++)(i||!(n in e))&&(i||(i=Array.prototype.slice.call(e,0,n)),i[n]=e[n]);return r.concat(i||Array.prototype.slice.call(e))}function P(r){return this instanceof P?(this.v=r,this):new P(r)}function Ge(r,e,t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=t.apply(r,e||[]),o,i=[];return o=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),a("next"),a("throw"),a("return",s),o[Symbol.asyncIterator]=function(){return this},o;function s(l){return function(y){return Promise.resolve(y).then(l,h)}}function a(l,y){n[l]&&(o[l]=function(p){return new Promise(function(S,E){i.push([l,p,S,E])>1||c(l,p)})},y&&(o[l]=y(o[l])))}function c(l,y){try{u(n[l](y))}catch(p){v(i[0][3],p)}}function u(l){l.value instanceof P?Promise.resolve(l.value.v).then(f,h):v(i[0][2],l)}function f(l){c("next",l)}function h(l){c("throw",l)}function v(l,y){l(y),i.shift(),i.length&&c(i[0][0],i[0][1])}}function He(r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e=r[Symbol.asyncIterator],t;return e?e.call(r):(r=typeof M=="function"?M(r):r[Symbol.iterator](),t={},n("next"),n("throw"),n("return"),t[Symbol.asyncIterator]=function(){return this},t);function n(i){t[i]=r[i]&&function(s){return new Promise(function(a,c){s=r[i](s),o(a,c,s.done,s.value)})}}function o(i,s,a,c){Promise.resolve(c).then(function(u){i({value:u,done:a})},s)}}function m(r){return typeof r=="function"}function ve(r){var e=function(n){Error.call(n),n.stack=new Error().stack},t=r(e);return t.prototype=Object.create(Error.prototype),t.prototype.constructor=t,t}var K=ve(function(r){return function(t){r(this),this.message=t?t.length+` errors occurred during unsubscription:
|
|
2
|
+
`+t.map(function(n,o){return o+1+") "+n.toString()}).join(`
|
|
3
|
+
`):"",this.name="UnsubscriptionError",this.errors=t}});function N(r,e){if(r){var t=r.indexOf(e);0<=t&&r.splice(t,1)}}var U=(function(){function r(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._finalizers=null}return r.prototype.unsubscribe=function(){var e,t,n,o,i;if(!this.closed){this.closed=!0;var s=this._parentage;if(s)if(this._parentage=null,Array.isArray(s))try{for(var a=M(s),c=a.next();!c.done;c=a.next()){var u=c.value;u.remove(this)}}catch(p){e={error:p}}finally{try{c&&!c.done&&(t=a.return)&&t.call(a)}finally{if(e)throw e.error}}else s.remove(this);var f=this.initialTeardown;if(m(f))try{f()}catch(p){i=p instanceof K?p.errors:[p]}var h=this._finalizers;if(h){this._finalizers=null;try{for(var v=M(h),l=v.next();!l.done;l=v.next()){var y=l.value;try{re(y)}catch(p){i=i??[],p instanceof K?i=R(R([],L(i)),L(p.errors)):i.push(p)}}}catch(p){n={error:p}}finally{try{l&&!l.done&&(o=v.return)&&o.call(v)}finally{if(n)throw n.error}}}if(i)throw new K(i)}},r.prototype.add=function(e){var t;if(e&&e!==this)if(this.closed)re(e);else{if(e instanceof r){if(e.closed||e._hasParent(this))return;e._addParent(this)}(this._finalizers=(t=this._finalizers)!==null&&t!==void 0?t:[]).push(e)}},r.prototype._hasParent=function(e){var t=this._parentage;return t===e||Array.isArray(t)&&t.includes(e)},r.prototype._addParent=function(e){var t=this._parentage;this._parentage=Array.isArray(t)?(t.push(e),t):t?[t,e]:e},r.prototype._removeParent=function(e){var t=this._parentage;t===e?this._parentage=null:Array.isArray(t)&&N(t,e)},r.prototype.remove=function(e){var t=this._finalizers;t&&N(t,e),e instanceof r&&e._removeParent(this)},r.EMPTY=(function(){var e=new r;return e.closed=!0,e})(),r})(),pe=U.EMPTY;function ye(r){return r instanceof U||r&&"closed"in r&&m(r.remove)&&m(r.add)&&m(r.unsubscribe)}function re(r){m(r)?r():r.unsubscribe()}var Fe={Promise:void 0},Ve={setTimeout:function(r,e){for(var t=[],n=2;n<arguments.length;n++)t[n-2]=arguments[n];return setTimeout.apply(void 0,R([r,e],L(t)))},clearTimeout:function(r){return clearTimeout(r)},delegate:void 0};function me(r){Ve.setTimeout(function(){throw r})}function W(){}function j(r){r()}var z=(function(r){O(e,r);function e(t){var n=r.call(this)||this;return n.isStopped=!1,t?(n.destination=t,ye(t)&&t.add(n)):n.destination=Be,n}return e.create=function(t,n,o){return new X(t,n,o)},e.prototype.next=function(t){this.isStopped||this._next(t)},e.prototype.error=function(t){this.isStopped||(this.isStopped=!0,this._error(t))},e.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},e.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,r.prototype.unsubscribe.call(this),this.destination=null)},e.prototype._next=function(t){this.destination.next(t)},e.prototype._error=function(t){try{this.destination.error(t)}finally{this.unsubscribe()}},e.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},e})(U),qe=(function(){function r(e){this.partialObserver=e}return r.prototype.next=function(e){var t=this.partialObserver;if(t.next)try{t.next(e)}catch(n){$(n)}},r.prototype.error=function(e){var t=this.partialObserver;if(t.error)try{t.error(e)}catch(n){$(n)}else $(e)},r.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(t){$(t)}},r})(),X=(function(r){O(e,r);function e(t,n,o){var i=r.call(this)||this,s;return m(t)||!t?s={next:t??void 0,error:n??void 0,complete:o??void 0}:s=t,i.destination=new qe(s),i}return e})(z);function $(r){me(r)}function Ke(r){throw r}var Be={closed:!0,next:W,error:Ke,complete:W},Q=(function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"})();function H(r){return r}function Ye(r){return r.length===0?H:r.length===1?r[0]:function(t){return r.reduce(function(n,o){return o(n)},t)}}var g=(function(){function r(e){e&&(this._subscribe=e)}return r.prototype.lift=function(e){var t=new r;return t.source=this,t.operator=e,t},r.prototype.subscribe=function(e,t,n){var o=this,i=Xe(e)?e:new X(e,t,n);return j(function(){var s=o,a=s.operator,c=s.source;i.add(a?a.call(i,c):c?o._subscribe(i):o._trySubscribe(i))}),i},r.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(t){e.error(t)}},r.prototype.forEach=function(e,t){var n=this;return t=ne(t),new t(function(o,i){var s=new X({next:function(a){try{e(a)}catch(c){i(c),s.unsubscribe()}},error:i,complete:o});n.subscribe(s)})},r.prototype._subscribe=function(e){var t;return(t=this.source)===null||t===void 0?void 0:t.subscribe(e)},r.prototype[Q]=function(){return this},r.prototype.pipe=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return Ye(e)(this)},r.prototype.toPromise=function(e){var t=this;return e=ne(e),new e(function(n,o){var i;t.subscribe(function(s){return i=s},function(s){return o(s)},function(){return n(i)})})},r.create=function(e){return new r(e)},r})();function ne(r){var e;return(e=r??Fe.Promise)!==null&&e!==void 0?e:Promise}function We(r){return r&&m(r.next)&&m(r.error)&&m(r.complete)}function Xe(r){return r&&r instanceof z||We(r)&&ye(r)}function Je(r){return m(r?.lift)}function x(r){return function(e){if(Je(e))return e.lift(function(t){try{return r(t,this)}catch(n){this.error(n)}});throw new TypeError("Unable to lift unknown Observable type")}}function I(r,e,t,n,o){return new ze(r,e,t,n,o)}var ze=(function(r){O(e,r);function e(t,n,o,i,s,a){var c=r.call(this,t)||this;return c.onFinalize=s,c.shouldUnsubscribe=a,c._next=n?function(u){try{n(u)}catch(f){t.error(f)}}:r.prototype._next,c._error=i?function(u){try{i(u)}catch(f){t.error(f)}finally{this.unsubscribe()}}:r.prototype._error,c._complete=o?function(){try{o()}catch(u){t.error(u)}finally{this.unsubscribe()}}:r.prototype._complete,c}return e.prototype.unsubscribe=function(){var t;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var n=this.closed;r.prototype.unsubscribe.call(this),!n&&((t=this.onFinalize)===null||t===void 0||t.call(this))}},e})(z),Qe=ve(function(r){return function(){r(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}}),Z=(function(r){O(e,r);function e(){var t=r.call(this)||this;return t.closed=!1,t.currentObservers=null,t.observers=[],t.isStopped=!1,t.hasError=!1,t.thrownError=null,t}return e.prototype.lift=function(t){var n=new oe(this,this);return n.operator=t,n},e.prototype._throwIfClosed=function(){if(this.closed)throw new Qe},e.prototype.next=function(t){var n=this;j(function(){var o,i;if(n._throwIfClosed(),!n.isStopped){n.currentObservers||(n.currentObservers=Array.from(n.observers));try{for(var s=M(n.currentObservers),a=s.next();!a.done;a=s.next()){var c=a.value;c.next(t)}}catch(u){o={error:u}}finally{try{a&&!a.done&&(i=s.return)&&i.call(s)}finally{if(o)throw o.error}}}})},e.prototype.error=function(t){var n=this;j(function(){if(n._throwIfClosed(),!n.isStopped){n.hasError=n.isStopped=!0,n.thrownError=t;for(var o=n.observers;o.length;)o.shift().error(t)}})},e.prototype.complete=function(){var t=this;j(function(){if(t._throwIfClosed(),!t.isStopped){t.isStopped=!0;for(var n=t.observers;n.length;)n.shift().complete()}})},e.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(e.prototype,"observed",{get:function(){var t;return((t=this.observers)===null||t===void 0?void 0:t.length)>0},enumerable:!1,configurable:!0}),e.prototype._trySubscribe=function(t){return this._throwIfClosed(),r.prototype._trySubscribe.call(this,t)},e.prototype._subscribe=function(t){return this._throwIfClosed(),this._checkFinalizedStatuses(t),this._innerSubscribe(t)},e.prototype._innerSubscribe=function(t){var n=this,o=this,i=o.hasError,s=o.isStopped,a=o.observers;return i||s?pe:(this.currentObservers=null,a.push(t),new U(function(){n.currentObservers=null,N(a,t)}))},e.prototype._checkFinalizedStatuses=function(t){var n=this,o=n.hasError,i=n.thrownError,s=n.isStopped;o?t.error(i):s&&t.complete()},e.prototype.asObservable=function(){var t=new g;return t.source=this,t},e.create=function(t,n){return new oe(t,n)},e})(g),oe=(function(r){O(e,r);function e(t,n){var o=r.call(this)||this;return o.destination=t,o.source=n,o}return e.prototype.next=function(t){var n,o;(o=(n=this.destination)===null||n===void 0?void 0:n.next)===null||o===void 0||o.call(n,t)},e.prototype.error=function(t){var n,o;(o=(n=this.destination)===null||n===void 0?void 0:n.error)===null||o===void 0||o.call(n,t)},e.prototype.complete=function(){var t,n;(n=(t=this.destination)===null||t===void 0?void 0:t.complete)===null||n===void 0||n.call(t)},e.prototype._subscribe=function(t){var n,o;return(o=(n=this.source)===null||n===void 0?void 0:n.subscribe(t))!==null&&o!==void 0?o:pe},e})(Z),ie=(function(r){O(e,r);function e(t){var n=r.call(this)||this;return n._value=t,n}return Object.defineProperty(e.prototype,"value",{get:function(){return this.getValue()},enumerable:!1,configurable:!0}),e.prototype._subscribe=function(t){var n=r.prototype._subscribe.call(this,t);return!n.closed&&t.next(this._value),n},e.prototype.getValue=function(){var t=this,n=t.hasError,o=t.thrownError,i=t._value;if(n)throw o;return this._throwIfClosed(),i},e.prototype.next=function(t){r.prototype.next.call(this,this._value=t)},e})(Z),Ze={now:function(){return Date.now()}},et=(function(r){O(e,r);function e(t,n){return r.call(this)||this}return e.prototype.schedule=function(t,n){return this},e})(U),se={setInterval:function(r,e){for(var t=[],n=2;n<arguments.length;n++)t[n-2]=arguments[n];return setInterval.apply(void 0,R([r,e],L(t)))},clearInterval:function(r){return clearInterval(r)},delegate:void 0},tt=(function(r){O(e,r);function e(t,n){var o=r.call(this,t,n)||this;return o.scheduler=t,o.work=n,o.pending=!1,o}return e.prototype.schedule=function(t,n){var o;if(n===void 0&&(n=0),this.closed)return this;this.state=t;var i=this.id,s=this.scheduler;return i!=null&&(this.id=this.recycleAsyncId(s,i,n)),this.pending=!0,this.delay=n,this.id=(o=this.id)!==null&&o!==void 0?o:this.requestAsyncId(s,this.id,n),this},e.prototype.requestAsyncId=function(t,n,o){return o===void 0&&(o=0),se.setInterval(t.flush.bind(t,this),o)},e.prototype.recycleAsyncId=function(t,n,o){if(o===void 0&&(o=0),o!=null&&this.delay===o&&this.pending===!1)return n;n!=null&&se.clearInterval(n)},e.prototype.execute=function(t,n){if(this.closed)return new Error("executing a cancelled action");this.pending=!1;var o=this._execute(t,n);if(o)return o;this.pending===!1&&this.id!=null&&(this.id=this.recycleAsyncId(this.scheduler,this.id,null))},e.prototype._execute=function(t,n){var o=!1,i;try{this.work(t)}catch(s){o=!0,i=s||new Error("Scheduled action threw falsy error")}if(o)return this.unsubscribe(),i},e.prototype.unsubscribe=function(){if(!this.closed){var t=this,n=t.id,o=t.scheduler,i=o.actions;this.work=this.state=this.scheduler=null,this.pending=!1,N(i,this),n!=null&&(this.id=this.recycleAsyncId(o,n,null)),this.delay=null,r.prototype.unsubscribe.call(this)}},e})(et),ae=(function(){function r(e,t){t===void 0&&(t=r.now),this.schedulerActionCtor=e,this.now=t}return r.prototype.schedule=function(e,t,n){return t===void 0&&(t=0),new this.schedulerActionCtor(this,e).schedule(n,t)},r.now=Ze.now,r})(),rt=(function(r){O(e,r);function e(t,n){n===void 0&&(n=ae.now);var o=r.call(this,t,n)||this;return o.actions=[],o._active=!1,o}return e.prototype.flush=function(t){var n=this.actions;if(this._active){n.push(t);return}var o;this._active=!0;do if(o=t.execute(t.state,t.delay))break;while(t=n.shift());if(this._active=!1,o){for(;t=n.shift();)t.unsubscribe();throw o}},e})(ae),be=new rt(tt),nt=be,ot=new g(function(r){return r.complete()});function ge(r){return r&&m(r.schedule)}function Se(r){return r[r.length-1]}function it(r){return m(Se(r))?r.pop():void 0}function we(r){return ge(Se(r))?r.pop():void 0}var Ee=(function(r){return r&&typeof r.length=="number"&&typeof r!="function"});function Ie(r){return m(r?.then)}function Oe(r){return m(r[Q])}function Ae(r){return Symbol.asyncIterator&&m(r?.[Symbol.asyncIterator])}function Ce(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 st(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}var Te=st();function _e(r){return m(r?.[Te])}function xe(r){return Ge(this,arguments,function(){var t,n,o,i;return he(this,function(s){switch(s.label){case 0:t=r.getReader(),s.label=1;case 1:s.trys.push([1,,9,10]),s.label=2;case 2:return[4,P(t.read())];case 3:return n=s.sent(),o=n.value,i=n.done,i?[4,P(void 0)]:[3,5];case 4:return[2,s.sent()];case 5:return[4,P(o)];case 6:return[4,s.sent()];case 7:return s.sent(),[3,2];case 8:return[3,10];case 9:return t.releaseLock(),[7];case 10:return[2]}})})}function Pe(r){return m(r?.getReader)}function T(r){if(r instanceof g)return r;if(r!=null){if(Oe(r))return at(r);if(Ee(r))return ct(r);if(Ie(r))return ut(r);if(Ae(r))return Me(r);if(_e(r))return lt(r);if(Pe(r))return ft(r)}throw Ce(r)}function at(r){return new g(function(e){var t=r[Q]();if(m(t.subscribe))return t.subscribe(e);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function ct(r){return new g(function(e){for(var t=0;t<r.length&&!e.closed;t++)e.next(r[t]);e.complete()})}function ut(r){return new g(function(e){r.then(function(t){e.closed||(e.next(t),e.complete())},function(t){return e.error(t)}).then(null,me)})}function lt(r){return new g(function(e){var t,n;try{for(var o=M(r),i=o.next();!i.done;i=o.next()){var s=i.value;if(e.next(s),e.closed)return}}catch(a){t={error:a}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(t)throw t.error}}e.complete()})}function Me(r){return new g(function(e){dt(r,e).catch(function(t){return e.error(t)})})}function ft(r){return Me(xe(r))}function dt(r,e){var t,n,o,i;return Ne(this,void 0,void 0,function(){var s,a;return he(this,function(c){switch(c.label){case 0:c.trys.push([0,5,6,11]),t=He(r),c.label=1;case 1:return[4,t.next()];case 2:if(n=c.sent(),!!n.done)return[3,4];if(s=n.value,e.next(s),e.closed)return[2];c.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return a=c.sent(),o={error:a},[3,11];case 6:return c.trys.push([6,,9,10]),n&&!n.done&&(i=t.return)?[4,i.call(t)]:[3,8];case 7:c.sent(),c.label=8;case 8:return[3,10];case 9:if(o)throw o.error;return[7];case 10:return[7];case 11:return e.complete(),[2]}})})}function C(r,e,t,n,o){n===void 0&&(n=0),o===void 0&&(o=!1);var i=e.schedule(function(){t(),o?r.add(this.schedule(null,n)):this.unsubscribe()},n);if(r.add(i),!o)return i}function Le(r,e){return e===void 0&&(e=0),x(function(t,n){t.subscribe(I(n,function(o){return C(n,r,function(){return n.next(o)},e)},function(){return C(n,r,function(){return n.complete()},e)},function(o){return C(n,r,function(){return n.error(o)},e)}))})}function Re(r,e){return e===void 0&&(e=0),x(function(t,n){n.add(r.schedule(function(){return t.subscribe(n)},e))})}function ht(r,e){return T(r).pipe(Re(e),Le(e))}function vt(r,e){return T(r).pipe(Re(e),Le(e))}function pt(r,e){return new g(function(t){var n=0;return e.schedule(function(){n===r.length?t.complete():(t.next(r[n++]),t.closed||this.schedule())})})}function yt(r,e){return new g(function(t){var n;return C(t,e,function(){n=r[Te](),C(t,e,function(){var o,i,s;try{o=n.next(),i=o.value,s=o.done}catch(a){t.error(a);return}s?t.complete():t.next(i)},0,!0)}),function(){return m(n?.return)&&n.return()}})}function Ue(r,e){if(!r)throw new Error("Iterable cannot be null");return new g(function(t){C(t,e,function(){var n=r[Symbol.asyncIterator]();C(t,e,function(){n.next().then(function(o){o.done?t.complete():t.next(o.value)})},0,!0)})})}function mt(r,e){return Ue(xe(r),e)}function bt(r,e){if(r!=null){if(Oe(r))return ht(r,e);if(Ee(r))return pt(r,e);if(Ie(r))return vt(r,e);if(Ae(r))return Ue(r,e);if(_e(r))return yt(r,e);if(Pe(r))return mt(r,e)}throw Ce(r)}function ee(r,e){return e?bt(r,e):T(r)}function gt(){for(var r=[],e=0;e<arguments.length;e++)r[e]=arguments[e];var t=we(r);return ee(r,t)}function St(r){return r instanceof Date&&!isNaN(r)}function F(r,e){return x(function(t,n){var o=0;t.subscribe(I(n,function(i){n.next(r.call(e,i,o++))}))})}var wt=Array.isArray;function Et(r,e){return wt(e)?r.apply(void 0,R([],L(e))):r(e)}function It(r){return F(function(e){return Et(r,e)})}var Ot=Array.isArray,At=Object.getPrototypeOf,Ct=Object.prototype,Tt=Object.keys;function _t(r){if(r.length===1){var e=r[0];if(Ot(e))return{args:e,keys:null};if(xt(e)){var t=Tt(e);return{args:t.map(function(n){return e[n]}),keys:t}}}return{args:r,keys:null}}function xt(r){return r&&typeof r=="object"&&At(r)===Ct}function Pt(r,e){return r.reduce(function(t,n,o){return t[n]=e[o],t},{})}function Mt(){for(var r=[],e=0;e<arguments.length;e++)r[e]=arguments[e];var t=we(r),n=it(r),o=_t(r),i=o.args,s=o.keys;if(i.length===0)return ee([],t);var a=new g(Lt(i,t,s?function(c){return Pt(s,c)}:H));return n?a.pipe(It(n)):a}function Lt(r,e,t){return t===void 0&&(t=H),function(n){ce(e,function(){for(var o=r.length,i=new Array(o),s=o,a=o,c=function(f){ce(e,function(){var h=ee(r[f],e),v=!1;h.subscribe(I(n,function(l){i[f]=l,v||(v=!0,a--),a||n.next(t(i.slice()))},function(){--s||n.complete()}))},n)},u=0;u<o;u++)c(u)},n)}}function ce(r,e,t){r?C(t,r,e):e()}function Rt(r,e,t,n,o,i,s,a){var c=[],u=0,f=0,h=!1,v=function(){h&&!c.length&&!u&&e.complete()},l=function(p){return u<n?y(p):c.push(p)},y=function(p){u++;var S=!1;T(t(p,f++)).subscribe(I(e,function(E){e.next(E)},function(){S=!0},void 0,function(){if(S)try{u--;for(var E=function(){var _=c.shift();s||y(_)};c.length&&u<n;)E();v()}catch(_){e.error(_)}}))};return r.subscribe(I(e,l,function(){h=!0,v()})),function(){}}function G(r,e,t){return t===void 0&&(t=1/0),m(e)?G(function(n,o){return F(function(i,s){return e(n,i,o,s)})(T(r(n,o)))},t):(typeof e=="number"&&(t=e),x(function(n,o){return Rt(n,o,r,t)}))}function ke(r,e,t){r===void 0&&(r=0),t===void 0&&(t=nt);var n=-1;return e!=null&&(ge(e)?t=e:n=e),new g(function(o){var i=St(r)?+r-t.now():r;i<0&&(i=0);var s=0;return t.schedule(function(){o.closed||(o.next(s++),0<=n?this.schedule(void 0,n):o.complete())},i)})}function Ut(r,e){return m(e)?G(r,e,1):G(r,1)}function kt(r){return r<=0?function(){return ot}:x(function(e,t){var n=0;e.subscribe(I(t,function(o){++n<=r&&(t.next(o),r<=n&&t.complete())}))})}function $t(r){return F(function(){return r})}function jt(r,e){return G(function(t,n){return T(r(t,n)).pipe(kt(1),$t(t))})}function Dt(r,e){e===void 0&&(e=be);var t=ke(r,e);return jt(function(){return t})}function Nt(r){var e;e={count:r};var t=e.count,n=t===void 0?1/0:t,o=e.delay,i=e.resetOnSuccess,s=i===void 0?!1:i;return n<=0?H:x(function(a,c){var u=0,f,h=function(){var v=!1;f=a.subscribe(I(c,function(l){s&&(u=0),c.next(l)},void 0,function(l){if(u++<n){var y=function(){f?(f.unsubscribe(),f=null,h()):v=!0};if(o!=null){var p=typeof o=="number"?ke(o):T(o(l,u)),S=I(c,function(){S.unsubscribe(),y()},function(){c.complete()});p.subscribe(S)}else y()}else c.error(l)})),v&&(f.unsubscribe(),f=null,h())};h()})}function Gt(r){return x(function(e,t){T(r).subscribe(I(t,function(){return t.complete()},W)),!t.closed&&e.subscribe(t)})}async function Ht(r,e){const t=r.getReader();let n;for(;!(n=await t.read()).done;)e(n.value)}function Ft(r){let e,t,n,o=!1;return function(s){e===void 0?(e=s,t=0,n=-1):e=qt(e,s);const a=e.length;let c=0;for(;t<a;){o&&(e[t]===10&&(c=++t),o=!1);let u=-1;for(;t<a&&u===-1;++t)switch(e[t]){case 58:n===-1&&(n=t-c);break;case 13:o=!0;case 10:u=t;break}if(u===-1)break;r(e.subarray(c,u),n),c=t,n=-1}c===a?e=void 0:c!==0&&(e=e.subarray(c),t-=c)}}function Vt(r,e,t){let n=ue();const o=new TextDecoder;return function(s,a){if(s.length===0)t?.(n),n=ue();else if(a>0){const c=o.decode(s.subarray(0,a)),u=a+(s[a+1]===32?2:1),f=o.decode(s.subarray(u));switch(c){case"data":n.data=n.data?n.data+`
|
|
4
|
+
`+f:f;break;case"event":n.event=f;break;case"id":r(n.id=f);break;case"retry":const h=parseInt(f,10);isNaN(h)||e(n.retry=h);break}}}}function qt(r,e){const t=new Uint8Array(r.length+e.length);return t.set(r),t.set(e,r.length),t}function ue(){return{data:"",event:"",id:"",retry:void 0}}var Kt=function(r,e){var t={};for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&e.indexOf(n)<0&&(t[n]=r[n]);if(r!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,n=Object.getOwnPropertySymbols(r);o<n.length;o++)e.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(r,n[o])&&(t[n[o]]=r[n[o]]);return t};const J="text/event-stream",Bt=1e3,le="last-event-id";function Yt(r,e){var{signal:t,headers:n,onopen:o,onmessage:i,onclose:s,onerror:a,openWhenHidden:c,fetch:u}=e,f=Kt(e,["signal","headers","onopen","onmessage","onclose","onerror","openWhenHidden","fetch"]);return new Promise((h,v)=>{const l=Object.assign({},n);l.accept||(l.accept=J);let y;function p(){y.abort(),document.hidden||V()}c||document.addEventListener("visibilitychange",p);let S=Bt,E=0;function _(){document.removeEventListener("visibilitychange",p),window.clearTimeout(E),y.abort()}t?.addEventListener("abort",()=>{_(),h()});const je=u??window.fetch,De=o??Wt;async function V(){var q;y=new AbortController;try{const k=await je(r,Object.assign(Object.assign({},f),{headers:l,signal:y.signal}));await De(k),await Ht(k.body,Ft(Vt(A=>{A?l[le]=A:delete l[le]},A=>{S=A},i))),s?.(),_(),h()}catch(k){if(!y.signal.aborted)try{const A=(q=a?.(k))!==null&&q!==void 0?q:S;window.clearTimeout(E),E=window.setTimeout(V,A)}catch(A){_(),v(A)}}}V()})}function Wt(r){const e=r.headers.get("content-type");if(!e?.startsWith(J))throw new Error(`Expected content-type to be ${J}, Actual: ${e}`)}function Xt(r){const{endpoint:e,apiKey:t,payload:n,debugMode:o,customHeaders:i}=r;return new g(s=>{const a=new AbortController;let c;const u={"Content-Type":"application/json",...i};t&&(u["X-API-KEY"]=t);const f=new URLSearchParams;o&&f.set("is_debug","true");const h=new URL(e);return f.toString()&&(h.search=f.toString()),Yt(h.toString(),{method:"POST",headers:u,body:n?JSON.stringify(n):void 0,signal:a.signal,openWhenHidden:!0,onopen:async v=>{v.ok?c=v.headers.get("X-Trace-Id")??void 0:(s.error(v),a.abort())},onmessage:v=>{const l=JSON.parse(v.data);c?l.traceId=c:l.requestId&&(l.traceId=l.requestId,c||(c=l.requestId)),s.next(l)},onclose:()=>{s.complete()},onerror:v=>{throw s.error(v),a.abort(),v}}),()=>{a.abort()}})}class Jt{listeners={};on(e,t){this.listeners=Object.assign({},this.listeners,{[e]:(this.listeners[e]??[]).concat(t)})}off(e,t){this.listeners[e]&&(this.listeners=Object.assign({},this.listeners,{[e]:(this.listeners[e]??[]).filter(n=>n!==t)}))}remove(e){delete this.listeners[e]}emit(e,...t){this.listeners[e]&&this.listeners[e].forEach(n=>n(...t))}}class zt{apiKey;endpoint;botProviderEndpoint;debugMode;destroy$=new Z;sseEmitter=new Jt;transformSsePayload;customHeaders;constructor(e){if(!e.endpoint&&!e.botProviderEndpoint)throw new Error("Either endpoint or botProviderEndpoint must be provided");if(this.apiKey=e.apiKey,this.debugMode=e.debugMode,this.transformSsePayload=e.transformSsePayload,this.botProviderEndpoint=e.botProviderEndpoint,this.customHeaders=e.customHeaders,!e.endpoint&&e.botProviderEndpoint){const t=e.botProviderEndpoint.replace(/\/+$/,"");this.endpoint=`${t}/message/sse`}else e.endpoint&&(this.endpoint=e.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(e,t){this.sseEmitter.remove(e),this.sseEmitter.on(e,t)}handleEvent(e){switch(e.eventType){case d.INIT:this.sseEmitter.emit(d.INIT,e);break;case d.PROCESS_START:case d.PROCESS_COMPLETE:this.sseEmitter.emit(d.PROCESS,e);break;case d.MESSAGE_START:case d.MESSAGE_DELTA:case d.MESSAGE_COMPLETE:this.sseEmitter.emit(d.MESSAGE,e);break;case d.TOOL_CALL_START:case d.TOOL_CALL_COMPLETE:this.sseEmitter.emit(d.TOOL_CALL,e);break;case d.DONE:this.sseEmitter.emit(d.DONE,e);break;case d.ERROR:this.sseEmitter.emit(d.ERROR,e);break}}fetchSse(e,t){t?.onSseStart?.(),Xt({apiKey:this.apiKey,endpoint:this.endpoint,debugMode:this.debugMode,payload:this.transformSsePayload?.(e)??e,customHeaders:this.customHeaders}).pipe(Ut(n=>gt(n).pipe(Dt(t?.delayTime??50))),Gt(this.destroy$),Nt(3)).subscribe({next:n=>{t?.onSseMessage?.(n),this.handleEvent(n)},error:n=>{t?.onSseError?.(n)},complete:()=>{t?.onSseCompleted?.()}})}close(){this.destroy$.next(),this.destroy$.complete()}async uploadFile(e,t){const n=this.deriveBlobEndpoint();if(!n)throw new Error("Unable to derive blob endpoint. Please provide botProviderEndpoint in config.");const o=new FormData;o.append("file",e),o.append("customChannelId",t);const i={...this.customHeaders};this.apiKey&&(i["X-API-KEY"]=this.apiKey);try{const s=await fetch(n,{method:"POST",headers:i,body:o});if(!s.ok)throw new Error(`Upload failed: ${s.status} ${s.statusText}`);const a=await s.json();return this.debugMode&&console.log("[AsgardServiceClient] File upload response:",a),a}catch(s){throw console.error("[AsgardServiceClient] File upload error:",s),s}}deriveBlobEndpoint(){if(!this.botProviderEndpoint&&!this.endpoint)return null;let e=this.botProviderEndpoint;if(!e&&this.endpoint&&(e=this.endpoint.replace("/message/sse","")),!e)return null;if(e=e.replace(/\/+$/,""),!e.includes("/generic/")){const t=e.match(/^(https?:\/\/[^/]+)(\/.*)/);if(t){const[,n,o]=t;e=`${n}/generic${o}`}}return`${e}/blob`}}const b=[];for(let r=0;r<256;++r)b.push((r+256).toString(16).slice(1));function Qt(r,e=0){return(b[r[e+0]]+b[r[e+1]]+b[r[e+2]]+b[r[e+3]]+"-"+b[r[e+4]]+b[r[e+5]]+"-"+b[r[e+6]]+b[r[e+7]]+"-"+b[r[e+8]]+b[r[e+9]]+"-"+b[r[e+10]]+b[r[e+11]]+b[r[e+12]]+b[r[e+13]]+b[r[e+14]]+b[r[e+15]]).toLowerCase()}let B;const Zt=new Uint8Array(16);function er(){if(!B){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");B=crypto.getRandomValues.bind(crypto)}return B(Zt)}const tr=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),fe={randomUUID:tr};function rr(r,e,t){r=r||{};const n=r.random??r.rng?.()??er();if(n.length<16)throw new Error("Random bytes length must be >= 16");return n[6]=n[6]&15|64,n[8]=n[8]&63|128,Qt(n)}function $e(r,e,t){return fe.randomUUID&&!r?fe.randomUUID():rr(r)}class w{messages=null;constructor({messages:e}){this.messages=e}pushMessage(e){const t=new Map(this.messages);return t.set(e.messageId,e),new w({messages:t})}onMessage(e){switch(e.eventType){case d.MESSAGE_START:return this.onMessageStart(e);case d.MESSAGE_DELTA:return this.onMessageDelta(e);case d.MESSAGE_COMPLETE:return this.onMessageComplete(e);case d.TOOL_CALL_START:return this.onToolCallStart(e);case d.TOOL_CALL_COMPLETE:return this.onToolCallComplete(e);case d.ERROR:return this.onMessageError(e);default:return this}}onMessageStart(e){const t=e.fact.messageStart.message,n=new Map(this.messages);return n.set(t.messageId,{type:"bot",eventType:d.MESSAGE_START,isTyping:!0,typingText:"",messageId:t.messageId,message:t,time:new Date,traceId:e.traceId,raw:""}),new w({messages:n})}onMessageDelta(e){const t=e.fact.messageDelta.message,n=new Map(this.messages),o=n.get(t.messageId);if(o?.type!=="bot")return this;const i=`${o?.typingText??""}${t.text}`;return n.set(t.messageId,{type:"bot",eventType:d.MESSAGE_DELTA,isTyping:!0,typingText:i,messageId:t.messageId,message:t,time:new Date,traceId:e.traceId??o.traceId,raw:o.raw}),new w({messages:n})}onMessageComplete(e){const t=e.fact.messageComplete.message,n=new Map(this.messages),o=n.get(t.messageId);return n.set(t.messageId,{type:"bot",eventType:d.MESSAGE_COMPLETE,isTyping:!1,typingText:null,messageId:t.messageId,message:t,time:new Date,traceId:e.traceId??(o?.type==="bot"?o.traceId:void 0),raw:JSON.stringify(e)}),new w({messages:n})}onMessageError(e){const t=$e(),n=e.fact.runError.error,o=new Map(this.messages);return o.set(t,{type:"error",eventType:d.ERROR,messageId:t,error:n,time:new Date,traceId:e.traceId}),new w({messages:o})}onToolCallStart(e){const t=e.fact.toolCallStart,n=new Map(this.messages),o=`${t.processId}-${t.callSeq}`,i={type:"tool-call",eventType:d.TOOL_CALL_START,messageId:o,processId:t.processId,callSeq:t.callSeq,toolName:t.toolCall.toolName,toolsetName:t.toolCall.toolsetName,parameter:t.toolCall.parameter,isComplete:!1,time:new Date,traceId:e.traceId};return n.set(o,i),new w({messages:n})}onToolCallComplete(e){const t=e.fact.toolCallComplete,n=new Map(this.messages),o=`${t.processId}-${t.callSeq}`,i=n.get(o);if(i?.type==="tool-call"){const s={...i,eventType:d.TOOL_CALL_COMPLETE,result:t.toolCallResult,isComplete:!0,traceId:e.traceId??i.traceId};n.set(o,s)}return new w({messages:n})}}class te{client;customChannelId;customMessageId;isConnecting$;conversation$;statesObserver;statesSubscription;currentUserMessageId;constructor(e){if(!e.client)throw new Error("client must be required");if(!e.customChannelId)throw new Error("customChannelId must be required");this.client=e.client,this.customChannelId=e.customChannelId,this.customMessageId=e.customMessageId,this.isConnecting$=new ie(!1),this.conversation$=new ie(e.conversation),this.statesObserver=e.statesObserver}static async reset(e,t,n){const o=new te(e);try{return o.subscribe(),await o.resetChannel(t,n),o}catch(i){throw o.close(),i}}subscribe(){this.statesSubscription=Mt([this.isConnecting$,this.conversation$]).pipe(F(([e,t])=>({isConnecting:e,conversation:t}))).subscribe(this.statesObserver)}fetchSse(e,t){return new Promise((n,o)=>{this.isConnecting$.next(!0),this.client.fetchSse(e,{onSseStart:t?.onSseStart,onSseMessage:i=>{if(t?.onSseMessage?.(i),this.currentUserMessageId&&i.traceId){const s=new Map(this.conversation$.value.messages),a=s.get(this.currentUserMessageId);a&&a.type==="user"&&(s.set(this.currentUserMessageId,{...a,traceId:i.traceId}),this.conversation$.next(new w({messages:s}))),this.currentUserMessageId=void 0}this.conversation$.next(this.conversation$.value.onMessage(i))},onSseError:i=>{t?.onSseError?.(i),this.isConnecting$.next(!1),this.currentUserMessageId=void 0,o(i)},onSseCompleted:()=>{t?.onSseCompleted?.(),this.isConnecting$.next(!1),this.currentUserMessageId=void 0,n()}})})}resetChannel(e,t){return this.fetchSse({action:D.RESET_CHANNEL,customChannelId:this.customChannelId,customMessageId:this.customMessageId,text:e?.text||"",payload:e?.payload},t)}sendMessage(e,t){const n=e.text.trim(),o=e.customMessageId??$e();return this.currentUserMessageId=o,this.conversation$.next(this.conversation$.value.pushMessage({type:"user",messageId:o,text:n,blobIds:e.blobIds,filePreviewUrls:e.filePreviewUrls,documentNames:e.documentNames,time:new Date})),this.fetchSse({action:D.NONE,customChannelId:this.customChannelId,customMessageId:o,payload:e?.payload,text:n,blobIds:e?.blobIds},t)}close(){this.isConnecting$.complete(),this.conversation$.complete(),this.statesSubscription?.unsubscribe()}}exports.AsgardServiceClient=zt;exports.Channel=te;exports.Conversation=w;exports.EventType=d;exports.FetchSseAction=D;exports.MessageTemplateType=de;
|
|
5
5
|
//# sourceMappingURL=index.cjs.map
|