@asgard-js/core 0.1.25 → 0.1.27

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 CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  This package contains the core functionalities of the AsgardJs SDK, providing essential tools for interacting with the Asgard AI platform through Server-Sent Events (SSE) and conversation management.
4
4
 
5
+ <a id="installation"></a>
6
+ <br/>
7
+
5
8
  ## Installation
6
9
 
7
10
  To install the core package, use the following command:
@@ -10,6 +13,9 @@ To install the core package, use the following command:
10
13
  npm install @asgard-js/core
11
14
  ```
12
15
 
16
+ <a id="usage"></a>
17
+ <br/>
18
+
13
19
  ## Usage
14
20
 
15
21
  Here's a basic example of how to use the core package:
@@ -68,7 +74,10 @@ client.on('ERROR', error => {
68
74
  });
69
75
  ```
70
76
 
71
- ## Migration from `endpoint` to `botProviderEndpoint`
77
+ <a id="migration-from-endpoint-to-botproviderendpoint"></a>
78
+ <br/>
79
+
80
+ ## Migration from endpoint to botProviderEndpoint
72
81
 
73
82
  **Important**: The `endpoint` configuration option is deprecated. Use `botProviderEndpoint` instead for simplified configuration.
74
83
 
@@ -100,10 +109,16 @@ const client = new AsgardServiceClient({
100
109
 
101
110
  **Backward Compatibility:** Existing code using `endpoint` will continue to work but may show deprecation warnings when `debugMode` is enabled.
102
111
 
112
+ <a id="api-reference"></a>
113
+ <br/>
114
+
103
115
  ## API Reference
104
116
 
105
117
  The core package exports three main classes for different levels of abstraction and includes authentication types for dynamic API key management:
106
118
 
119
+ <a id="asgardserviceclient"></a>
120
+ <br/>
121
+
107
122
  ### AsgardServiceClient
108
123
 
109
124
  The main client class for interacting with the Asgard AI platform.
@@ -115,6 +130,7 @@ The main client class for interacting with the Asgard AI platform.
115
130
  - **endpoint?**: `string` (deprecated) - Legacy API endpoint URL. Use `botProviderEndpoint` instead.
116
131
  - **debugMode?**: `boolean` - Enable debug mode for deprecation warnings, defaults to `false`
117
132
  - **transformSsePayload?**: `(payload: FetchSsePayload) => FetchSsePayload` - SSE payload transformer
133
+ - **customHeaders?**: `Record<string, string>` - Custom headers to include in SSE and API requests (e.g., Bearer token via `Authorization` header)
118
134
  - **onRunInit?**: `InitEventHandler` - Handler for run initialization events
119
135
  - **onMessage?**: `MessageEventHandler` - Handler for message events
120
136
  - **onToolCall?**: `ToolCallEventHandler` - Handler for tool call events
@@ -138,6 +154,9 @@ The main client class for interacting with the Asgard AI platform.
138
154
  - **DONE**: Run completion events
139
155
  - **ERROR**: Error events
140
156
 
157
+ <a id="channel"></a>
158
+ <br/>
159
+
141
160
  ### Channel
142
161
 
143
162
  Higher-level abstraction for managing a conversation channel with reactive state management using RxJS.
@@ -190,6 +209,9 @@ const channel = await Channel.reset({
190
209
  await channel.sendMessage({ text: 'Hello, bot!' });
191
210
  ```
192
211
 
212
+ <a id="conversation"></a>
213
+ <br/>
214
+
193
215
  ### Conversation
194
216
 
195
217
  Immutable conversation state manager that handles message updates and SSE event processing.
@@ -233,6 +255,9 @@ const updatedConversation = conversation.pushMessage(userMessage);
233
255
  console.log('Messages:', Array.from(updatedConversation.messages.values()));
234
256
  ```
235
257
 
258
+ <a id="file-upload-api"></a>
259
+ <br/>
260
+
236
261
  ### File Upload API
237
262
 
238
263
  The core package includes file upload capabilities for sending images through the chatbot.
@@ -255,6 +280,9 @@ if (uploadResponse.isSuccess && uploadResponse.data[0]) {
255
280
 
256
281
  **Note**: `uploadFile` is optional - check `client.uploadFile` exists before use. Supports JPEG, PNG, GIF, WebP up to 20MB.
257
282
 
283
+ <a id="authentication-types"></a>
284
+ <br/>
285
+
258
286
  ### Authentication Types
259
287
 
260
288
  The core package includes authentication-related types for dynamic API key management:
@@ -293,6 +321,9 @@ function handleAuthState(state: AuthState) {
293
321
  }
294
322
  ```
295
323
 
324
+ <a id="testing"></a>
325
+ <br/>
326
+
296
327
  ## Testing
297
328
 
298
329
  The core package includes comprehensive tests using Vitest.
@@ -348,6 +379,9 @@ describe('AsgardServiceClient', () => {
348
379
  });
349
380
  ```
350
381
 
382
+ <a id="development"></a>
383
+ <br/>
384
+
351
385
  ## Development
352
386
 
353
387
  To develop the core package locally, follow these steps:
@@ -26,6 +26,7 @@ export declare enum MessageTemplateType {
26
26
  AUDIO = "AUDIO",
27
27
  LOCATION = "LOCATION",
28
28
  CAROUSEL = "CAROUSEL",
29
- CHART = "CHART"
29
+ CHART = "CHART",
30
+ TABLE = "TABLE"
30
31
  }
31
32
  //# sourceMappingURL=enum.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"enum.d.ts","sourceRoot":"","sources":["../../src/constants/enum.ts"],"names":[],"mappings":"AAAA,oBAAY,cAAc;IACxB,aAAa,kBAAkB;IAC/B,IAAI,SAAS;CACd;AAED,oBAAY,SAAS;IACnB,IAAI,oBAAoB;IACxB,OAAO,mBAAmB;IAC1B,aAAa,yBAAyB;IACtC,gBAAgB,4BAA4B;IAC5C,OAAO,mBAAmB;IAC1B,aAAa,yBAAyB;IACtC,aAAa,yBAAyB;IACtC,gBAAgB,4BAA4B;IAC5C,SAAS,qBAAqB;IAC9B,eAAe,2BAA2B;IAC1C,kBAAkB,8BAA8B;IAChD,IAAI,oBAAoB;IACxB,KAAK,qBAAqB;CAC3B;AAED,oBAAY,mBAAmB;IAC7B,IAAI,SAAS;IACb,IAAI,SAAS;IACb,MAAM,WAAW;IACjB,KAAK,UAAU;IACf,KAAK,UAAU;IACf,KAAK,UAAU;IACf,QAAQ,aAAa;IACrB,QAAQ,aAAa;IACrB,KAAK,UAAU;CAChB"}
1
+ {"version":3,"file":"enum.d.ts","sourceRoot":"","sources":["../../src/constants/enum.ts"],"names":[],"mappings":"AAAA,oBAAY,cAAc;IACxB,aAAa,kBAAkB;IAC/B,IAAI,SAAS;CACd;AAED,oBAAY,SAAS;IACnB,IAAI,oBAAoB;IACxB,OAAO,mBAAmB;IAC1B,aAAa,yBAAyB;IACtC,gBAAgB,4BAA4B;IAC5C,OAAO,mBAAmB;IAC1B,aAAa,yBAAyB;IACtC,aAAa,yBAAyB;IACtC,gBAAgB,4BAA4B;IAC5C,SAAS,qBAAqB;IAC9B,eAAe,2BAA2B;IAC1C,kBAAkB,8BAA8B;IAChD,IAAI,oBAAoB;IACxB,KAAK,qBAAqB;CAC3B;AAED,oBAAY,mBAAmB;IAC7B,IAAI,SAAS;IACb,IAAI,SAAS;IACb,MAAM,WAAW;IACjB,KAAK,UAAU;IACf,KAAK,UAAU;IACf,KAAK,UAAU;IACf,QAAQ,aAAa;IACrB,QAAQ,aAAa;IACrB,KAAK,UAAU;IACf,KAAK,UAAU;CAChB"}
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
- "use strict";var Ge=Object.defineProperty;var Fe=(r,t,e)=>t in r?Ge(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e;var b=(r,t,e)=>Fe(r,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var N=(r=>(r.RESET_CHANNEL="RESET_CHANNEL",r.NONE="NONE",r))(N||{}),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||{}),he=(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))(he||{}),W=function(r,t){return W=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])},W(r,t)};function A(r,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");W(r,t);function e(){this.constructor=r}r.prototype=t===null?Object.create(t):(e.prototype=t.prototype,new e)}function Ve(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 a(l){try{u(n.next(l))}catch(d){s(d)}}function c(l){try{u(n.throw(l))}catch(d){s(d)}}function u(l){l.done?o(l.value):i(l.value).then(a,c)}u((n=n.apply(r,t||[])).next())})}function ve(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=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(l){return c([u,l])}}function c(u){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,u[0]&&(e=0)),e;)try{if(n=1,i&&(o=u[0]&2?i.return:u[0]?i.throw||((o=i.return)&&o.call(i),0):i.next)&&!(o=o.call(i,u[1])).done)return o;switch(i=0,o&&(u=[u[0]&2,o.value]),u[0]){case 0:case 1:o=u;break;case 4:return e.label++,{value:u[1],done:!1};case 5:e.label++,i=u[1],u=[0];continue;case 7:u=e.ops.pop(),e.trys.pop();continue;default:if(o=e.trys,!(o=o.length>0&&o[o.length-1])&&(u[0]===6||u[0]===2)){e=0;continue}if(u[0]===3&&(!o||u[1]>o[0]&&u[1]<o[3])){e.label=u[1];break}if(u[0]===6&&e.label<o[1]){e.label=o[1],o=u;break}if(o&&e.label<o[2]){e.label=o[2],e.ops.push(u);break}o[2]&&e.ops.pop(),e.trys.pop();continue}u=t.call(r,e)}catch(l){u=[6,l],i=0}finally{n=o=0}if(u[0]&5)throw u[1];return{value:u[0]?u[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 R(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(a){s={error:a}}finally{try{i&&!i.done&&(e=n.return)&&e.call(n)}finally{if(s)throw s.error}}return o}function U(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 M(r){return this instanceof M?(this.v=r,this):new M(r)}function qe(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),a("next"),a("throw"),a("return",s),i[Symbol.asyncIterator]=function(){return this},i;function s(f){return function(p){return Promise.resolve(p).then(f,d)}}function a(f,p){n[f]&&(i[f]=function(v){return new Promise(function(w,I){o.push([f,v,w,I])>1||c(f,v)})},p&&(i[f]=p(i[f])))}function c(f,p){try{u(n[f](p))}catch(v){y(o[0][3],v)}}function u(f){f.value instanceof M?Promise.resolve(f.value.v).then(l,d):y(o[0][2],f)}function l(f){c("next",f)}function d(f){c("throw",f)}function y(f,p){f(p),o.shift(),o.length&&c(o[0][0],o[0][1])}}function He(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(a,c){s=r[o](s),i(a,c,s.done,s.value)})}}function i(o,s,a,c){Promise.resolve(c).then(function(u){o({value:u,done:a})},s)}}function m(r){return typeof r=="function"}function ye(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=ye(function(r){return function(e){r(this),this.message=e?e.length+` errors occurred during unsubscription:
1
+ "use strict";var Ge=Object.defineProperty;var He=(r,t,e)=>t in r?Ge(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e;var b=(r,t,e)=>He(r,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var N=(r=>(r.RESET_CHANNEL="RESET_CHANNEL",r.NONE="NONE",r))(N||{}),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||{}),he=(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))(he||{}),W=function(r,t){return W=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])},W(r,t)};function A(r,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");W(r,t);function e(){this.constructor=r}r.prototype=t===null?Object.create(t):(e.prototype=t.prototype,new e)}function Fe(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(f){try{u(n.next(f))}catch(h){s(h)}}function a(f){try{u(n.throw(f))}catch(h){s(h)}}function u(f){f.done?o(f.value):i(f.value).then(c,a)}u((n=n.apply(r,t||[])).next())})}function ve(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(u){return function(f){return a([u,f])}}function a(u){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,u[0]&&(e=0)),e;)try{if(n=1,i&&(o=u[0]&2?i.return:u[0]?i.throw||((o=i.return)&&o.call(i),0):i.next)&&!(o=o.call(i,u[1])).done)return o;switch(i=0,o&&(u=[u[0]&2,o.value]),u[0]){case 0:case 1:o=u;break;case 4:return e.label++,{value:u[1],done:!1};case 5:e.label++,i=u[1],u=[0];continue;case 7:u=e.ops.pop(),e.trys.pop();continue;default:if(o=e.trys,!(o=o.length>0&&o[o.length-1])&&(u[0]===6||u[0]===2)){e=0;continue}if(u[0]===3&&(!o||u[1]>o[0]&&u[1]<o[3])){e.label=u[1];break}if(u[0]===6&&e.label<o[1]){e.label=o[1],o=u;break}if(o&&e.label<o[2]){e.label=o[2],e.ops.push(u);break}o[2]&&e.ops.pop(),e.trys.pop();continue}u=t.call(r,e)}catch(f){u=[6,f],i=0}finally{n=o=0}if(u[0]&5)throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}function M(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 R(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 U(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 L(r){return this instanceof L?(this.v=r,this):new L(r)}function Ve(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(l){return function(p){return Promise.resolve(p).then(l,h)}}function c(l,p){n[l]&&(i[l]=function(y){return new Promise(function(w,I){o.push([l,y,w,I])>1||a(l,y)})},p&&(i[l]=p(i[l])))}function a(l,p){try{u(n[l](p))}catch(y){v(o[0][3],y)}}function u(l){l.value instanceof L?Promise.resolve(l.value.v).then(f,h):v(o[0][2],l)}function f(l){a("next",l)}function h(l){a("throw",l)}function v(l,p){l(p),o.shift(),o.length&&a(o[0][0],o[0][1])}}function qe(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 M=="function"?M(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,a){s=r[o](s),i(c,a,s.done,s.value)})}}function i(o,s,c,a){Promise.resolve(a).then(function(u){o({value:u,done:c})},s)}}function m(r){return typeof r=="function"}function ye(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=ye(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 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 a=L(s),c=a.next();!c.done;c=a.next()){var u=c.value;u.remove(this)}}catch(v){t={error:v}}finally{try{c&&!c.done&&(e=a.return)&&e.call(a)}finally{if(t)throw t.error}}else s.remove(this);var l=this.initialTeardown;if(m(l))try{l()}catch(v){o=v instanceof B?v.errors:[v]}var d=this._finalizers;if(d){this._finalizers=null;try{for(var y=L(d),f=y.next();!f.done;f=y.next()){var p=f.value;try{ne(p)}catch(v){o=o??[],v instanceof B?o=U(U([],R(o)),R(v.errors)):o.push(v)}}}catch(v){n={error:v}}finally{try{f&&!f.done&&(i=y.return)&&i.call(y)}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 V(r){return r}function Je(r){return r.length===0?V: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,a=s.operator,c=s.source;o.add(a?a.call(o,c):c?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(a){try{t(a)}catch(c){o(c),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,a){var c=r.call(this,e)||this;return c.onFinalize=s,c.shouldUnsubscribe=a,c._next=n?function(u){try{n(u)}catch(l){e.error(l)}}:r.prototype._next,c._error=o?function(u){try{o(u)}catch(l){e.error(l)}finally{this.unsubscribe()}}:r.prototype._error,c._complete=i?function(){try{i()}catch(u){e.error(u)}finally{this.unsubscribe()}}:r.prototype._complete,c}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=L(n.currentObservers),a=s.next();!a.done;a=s.next()){var c=a.value;c.next(e)}}catch(u){i={error:u}}finally{try{a&&!a.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,a=i.observers;return o||s?pe:(this.currentObservers=null,a.push(e),new k(function(){n.currentObservers=null,G(a,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 qe(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,M(e.read())];case 3:return n=s.sent(),i=n.value,o=n.done,o?[4,M(void 0)]:[3,5];case 4:return[2,s.sent()];case 5:return[4,M(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 Me(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 Le(r);if(xe(r))return ht(r);if(Me(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=L(r),o=i.next();!o.done;o=i.next()){var s=o.value;if(t.next(s),t.closed)return}}catch(a){e={error:a}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}t.complete()})}function Le(r){return new S(function(t){yt(r,t).catch(function(e){return t.error(e)})})}function vt(r){return Le(Pe(r))}function yt(r,t){var e,n,i,o;return Ve(this,void 0,void 0,function(){var s,a;return ve(this,function(c){switch(c.label){case 0:c.trys.push([0,5,6,11]),e=He(r),c.label=1;case 1:return[4,e.next()];case 2:if(n=c.sent(),!!n.done)return[3,4];if(s=n.value,t.next(s),t.closed)return[2];c.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return a=c.sent(),i={error:a},[3,11];case 6:return c.trys.push([6,,9,10]),n&&!n.done&&(o=e.return)?[4,o.call(e)]:[3,8];case 7:c.sent(),c.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(a){e.error(a);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(Me(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 q(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 q(function(t){return At(r,t)})}var Tt=Array.isArray,_t=Object.getPrototypeOf,xt=Object.prototype,Pt=Object.keys;function Mt(r){if(r.length===1){var t=r[0];if(Tt(t))return{args:t,keys:null};if(Lt(t)){var e=Pt(t);return{args:e.map(function(n){return t[n]}),keys:e}}}return{args:r,keys:null}}function Lt(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=Mt(r),o=i.args,s=i.keys;if(o.length===0)return te([],e);var a=new S(kt(o,e,s?function(c){return Rt(s,c)}:V));return n?a.pipe(Ct(n)):a}function kt(r,t,e){return e===void 0&&(e=V),function(n){ue(t,function(){for(var i=r.length,o=new Array(i),s=i,a=i,c=function(l){ue(t,function(){var d=te(r[l],t),y=!1;d.subscribe(O(n,function(f){o[l]=f,y||(y=!0,a--),a||n.next(e(o.slice()))},function(){--s||n.complete()}))},n)},u=0;u<i;u++)c(u)},n)}}function ue(r,t,e){r?T(e,r,t):t()}function $t(r,t,e,n,i,o,s,a){var c=[],u=0,l=0,d=!1,y=function(){d&&!c.length&&!u&&t.complete()},f=function(v){return u<n?p(v):c.push(v)},p=function(v){u++;var w=!1;_(e(v,l++)).subscribe(O(t,function(I){t.next(I)},function(){w=!0},void 0,function(){if(w)try{u--;for(var I=function(){var x=c.shift();s||p(x)};c.length&&u<n;)I();y()}catch(x){t.error(x)}}))};return r.subscribe(O(t,f,function(){d=!0,y()})),function(){}}function F(r,t,e){return e===void 0&&(e=1/0),m(t)?F(function(n,i){return q(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)?F(r,t,1):F(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 q(function(){return r})}function Gt(r,t){return F(function(e,n){return _(r(e,n)).pipe(Dt(1),Nt(e))})}function Ft(r,t){t===void 0&&(t=ge);var e=$e(r,t);return Gt(function(){return e})}function Vt(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?V:P(function(a,c){var u=0,l,d=function(){var y=!1;l=a.subscribe(O(c,function(f){s&&(u=0),c.next(f)},void 0,function(f){if(u++<n){var p=function(){l?(l.unsubscribe(),l=null,d()):y=!0};if(i!=null){var v=typeof i=="number"?$e(i):_(i(f,u)),w=O(c,function(){w.unsubscribe(),p()},function(){c.complete()});v.subscribe(w)}else p()}else c.error(f)})),y&&(l.unsubscribe(),l=null,d())};d()})}function qt(r){return P(function(t,e){_(r).subscribe(O(e,function(){return e.complete()},X)),!e.closed&&t.subscribe(e)})}async function Ht(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 a=t.length;let c=0;for(;e<a;){i&&(t[e]===10&&(c=++e),i=!1);let u=-1;for(;e<a&&u===-1;++e)switch(t[e]){case 58:n===-1&&(n=e-c);break;case 13:i=!0;case 10:u=e;break}if(u===-1)break;r(t.subarray(c,u),n),c=e,n=-1}c===a?t=void 0:c!==0&&(t=t.subarray(c),e-=c)}}function Bt(r,t,e){let n=le();const i=new TextDecoder;return function(s,a){if(s.length===0)e==null||e(n),n=le();else if(a>0){const c=i.decode(s.subarray(0,a)),u=a+(s[a+1]===32?2:1),l=i.decode(s.subarray(u));switch(c){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 d=parseInt(l,10);isNaN(d)||t(n.retry=d);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:a,openWhenHidden:c,fetch:u}=t,l=Wt(t,["signal","headers","onopen","onmessage","onclose","onerror","openWhenHidden","fetch"]);return new Promise((d,y)=>{const f=Object.assign({},n);f.accept||(f.accept=z);let p;function v(){p.abort(),document.hidden||H()}c||document.addEventListener("visibilitychange",v);let w=Xt,I=0;function x(){document.removeEventListener("visibilitychange",v),window.clearTimeout(I),p.abort()}e==null||e.addEventListener("abort",()=>{x(),d()});const De=u??window.fetch,Ne=i??zt;async function H(){var K;p=new AbortController;try{const $=await De(r,Object.assign(Object.assign({},l),{headers:f,signal:p.signal}));await Ne($),await Ht($.body,Kt(Bt(C=>{C?f[fe]=C:delete f[fe]},C=>{w=C},o))),s==null||s(),x(),d()}catch($){if(!p.signal.aborted)try{const C=(K=a==null?void 0:a($))!==null&&K!==void 0?K:w;window.clearTimeout(I),I=window.setTimeout(H,C)}catch(C){x(),y(C)}}}H()})}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}=r;return new S(o=>{const s=new AbortController;let a;const c={"Content-Type":"application/json"};e&&(c["X-API-KEY"]=e);const u=new URLSearchParams;i&&u.set("is_debug","true");const l=new URL(t);return u.toString()&&(l.search=u.toString()),Jt(l.toString(),{method:"POST",headers:c,body:n?JSON.stringify(n):void 0,signal:s.signal,openWhenHidden:!0,onopen:async d=>{d.ok?a=d.headers.get("X-Trace-Id")??void 0:(o.error(d),s.abort())},onmessage:d=>{const y=JSON.parse(d.data);a?y.traceId=a:y.requestId&&(y.traceId=y.requestId,a||(a=y.requestId)),o.next(y)},onclose:()=>{o.complete()},onerror:d=>{throw o.error(d),s.abort(),d}}),()=>{s.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");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),Qt({apiKey:this.apiKey,endpoint:this.endpoint,debugMode:this.debugMode,payload:((i=this.transformSsePayload)==null?void 0:i.call(this,t))??t}).pipe(jt(o=>Et(o).pipe(Ft((e==null?void 0:e.delayTime)??50))),qt(this.destroy$),Vt(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 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 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 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.TOOL_CALL_START:return this.onToolCallStart(t);case h.TOOL_CALL_COMPLETE:return this.onToolCallComplete(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,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:h.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:h.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:h.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:h.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:h.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(q(([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 a=new Map(this.conversation$.value.messages),c=a.get(this.currentUserMessageId);c&&c.type==="user"&&(a.set(this.currentUserMessageId,{...c,traceId:o.traceId}),this.conversation$.next(new E({messages:a}))),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=h;exports.FetchSseAction=N;exports.MessageTemplateType=he;
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;
5
5
  //# sourceMappingURL=index.cjs.map