@asgard-js/core 0.0.1 → 0.0.3-8.canary-1

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.
Files changed (50) hide show
  1. package/README.md +329 -6
  2. package/dist/constants/enum.d.ts +12 -3
  3. package/dist/constants/enum.d.ts.map +1 -1
  4. package/dist/index.cjs +3 -3
  5. package/dist/index.cjs.map +1 -1
  6. package/dist/index.d.ts +2 -0
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +3 -3
  9. package/dist/index.js.map +1 -1
  10. package/dist/index.mjs +1119 -1010
  11. package/dist/index.mjs.map +1 -1
  12. package/dist/lib/channel.d.ts +19 -0
  13. package/dist/lib/channel.d.ts.map +1 -0
  14. package/dist/lib/client.d.ts +11 -13
  15. package/dist/lib/client.d.ts.map +1 -1
  16. package/dist/lib/conversation.d.ts +18 -0
  17. package/dist/lib/conversation.d.ts.map +1 -0
  18. package/dist/lib/create-sse-observable.d.ts +7 -6
  19. package/dist/lib/create-sse-observable.d.ts.map +1 -1
  20. package/dist/lib/event-emitter.d.ts +8 -0
  21. package/dist/lib/event-emitter.d.ts.map +1 -0
  22. package/dist/types/channel.d.ts +42 -0
  23. package/dist/types/channel.d.ts.map +1 -0
  24. package/dist/types/client.d.ts +62 -16
  25. package/dist/types/client.d.ts.map +1 -1
  26. package/dist/types/event-emitter.d.ts +5 -0
  27. package/dist/types/event-emitter.d.ts.map +1 -0
  28. package/dist/types/index.d.ts +2 -0
  29. package/dist/types/index.d.ts.map +1 -1
  30. package/dist/types/sse-response.d.ts +60 -11
  31. package/dist/types/sse-response.d.ts.map +1 -1
  32. package/eslint.config.cjs +22 -0
  33. package/package.json +13 -1
  34. package/src/constants/enum.ts +32 -0
  35. package/src/index.ts +11 -0
  36. package/src/lib/channel.ts +153 -0
  37. package/src/lib/client.spec.ts +150 -0
  38. package/src/lib/client.ts +141 -0
  39. package/src/lib/conversation.ts +120 -0
  40. package/src/lib/create-sse-observable.ts +77 -0
  41. package/src/lib/event-emitter.ts +30 -0
  42. package/src/types/channel.ts +50 -0
  43. package/src/types/client.ts +89 -0
  44. package/src/types/event-emitter.ts +8 -0
  45. package/src/types/index.ts +4 -0
  46. package/src/types/sse-response.ts +176 -0
  47. package/tsconfig.json +13 -0
  48. package/tsconfig.lib.json +28 -0
  49. package/tsconfig.spec.json +33 -0
  50. package/vite.config.ts +80 -0
package/README.md CHANGED
@@ -1,11 +1,334 @@
1
- # core
1
+ # AsgardJs Core
2
2
 
3
- This library was generated with [Nx](https://nx.dev).
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
- ## Building
5
+ ## Installation
6
6
 
7
- Run `nx build core` to build the library.
7
+ To install the core package, use the following command:
8
8
 
9
- ## Running unit tests
9
+ ```sh
10
+ yarn add @asgard-js/core
11
+ ```
10
12
 
11
- Run `nx test core` to execute the unit tests via [Vitest](https://vitest.dev/).
13
+ ## Usage
14
+
15
+ Here's a basic example of how to use the core package:
16
+
17
+ ```javascript
18
+ import { AsgardServiceClient } from '@asgard-js/core';
19
+
20
+ const client = new AsgardServiceClient({
21
+ apiKey: 'your-api-key',
22
+ botProviderEndpoint:
23
+ 'https://api.asgard-ai.com/ns/{namespace}/bot-provider/{botProviderId}',
24
+ debugMode: true, // Enable to see deprecation warnings
25
+ });
26
+
27
+ // Use the client to send messages via SSE
28
+ client.fetchSse({
29
+ customChannelId: 'your-channel-id',
30
+ text: 'Hello, Asgard!',
31
+ action: 'message',
32
+ });
33
+
34
+ // Listen to events
35
+ client.on('MESSAGE', (response) => {
36
+ console.log('Received message:', response);
37
+ });
38
+
39
+ client.on('DONE', (response) => {
40
+ console.log('Conversation completed:', response);
41
+ });
42
+
43
+ client.on('ERROR', (error) => {
44
+ console.error('Error occurred:', error);
45
+ });
46
+ ```
47
+
48
+ ## Migration from `endpoint` to `botProviderEndpoint`
49
+
50
+ **Important**: The `endpoint` configuration option is deprecated. Use `botProviderEndpoint` instead for simplified configuration.
51
+
52
+ ### Before (Deprecated)
53
+
54
+ ```javascript
55
+ const client = new AsgardServiceClient({
56
+ apiKey: 'your-api-key',
57
+ endpoint:
58
+ 'https://api.asgard-ai.com/ns/{namespace}/bot-provider/{botProviderId}/message/sse',
59
+ botProviderEndpoint:
60
+ 'https://api.asgard-ai.com/ns/{namespace}/bot-provider/{botProviderId}',
61
+ });
62
+ ```
63
+
64
+ ### After (Recommended)
65
+
66
+ ```javascript
67
+ const client = new AsgardServiceClient({
68
+ apiKey: 'your-api-key',
69
+ botProviderEndpoint:
70
+ 'https://api.asgard-ai.com/ns/{namespace}/bot-provider/{botProviderId}',
71
+ // SSE endpoint is automatically derived as: botProviderEndpoint + '/message/sse'
72
+ });
73
+ ```
74
+
75
+ **Benefits:**
76
+
77
+ - Simplified configuration with single endpoint
78
+ - Reduced chance of configuration errors
79
+ - Automatic endpoint derivation
80
+
81
+ **Backward Compatibility:** Existing code using `endpoint` will continue to work but may show deprecation warnings when `debugMode` is enabled.
82
+
83
+ ## API Reference
84
+
85
+ The core package exports three main classes for different levels of abstraction:
86
+
87
+ ### AsgardServiceClient
88
+
89
+ The main client class for interacting with the Asgard AI platform.
90
+
91
+ #### Constructor Options (ClientConfig)
92
+
93
+ - **apiKey**: `string` (required) - API key for authentication
94
+ - **botProviderEndpoint**: `string` (required) - Bot provider endpoint URL (SSE endpoint will be auto-derived)
95
+ - **endpoint?**: `string` (deprecated) - Legacy API endpoint URL. Use `botProviderEndpoint` instead.
96
+ - **debugMode?**: `boolean` - Enable debug mode for deprecation warnings, defaults to `false`
97
+ - **transformSsePayload?**: `(payload: FetchSsePayload) => FetchSsePayload` - SSE payload transformer
98
+ - **onRunInit?**: `InitEventHandler` - Handler for run initialization events
99
+ - **onMessage?**: `MessageEventHandler` - Handler for message events
100
+ - **onToolCall?**: `ToolCallEventHandler` - Handler for tool call events
101
+ - **onProcess?**: `ProcessEventHandler` - Handler for process events
102
+ - **onRunDone?**: `DoneEventHandler` - Handler for run completion events
103
+ - **onRunError?**: `ErrorEventHandler` - Error handler for execution errors
104
+
105
+ #### Methods
106
+
107
+ - **fetchSse(payload, options?)**: Send a message via Server-Sent Events
108
+ - **on(event, handler)**: Listen to specific SSE events
109
+ - **close()**: Close the SSE connection and cleanup resources
110
+
111
+ #### Event Types
112
+
113
+ - **INIT**: Run initialization events
114
+ - **MESSAGE**: Message events (start, delta, complete)
115
+ - **TOOL_CALL**: Tool call events (start, complete)
116
+ - **PROCESS**: Process events (start, complete)
117
+ - **DONE**: Run completion events
118
+ - **ERROR**: Error events
119
+
120
+ ### Channel
121
+
122
+ Higher-level abstraction for managing a conversation channel with reactive state management using RxJS.
123
+
124
+ #### Static Methods
125
+
126
+ - **Channel.reset(config, payload?, options?)**: `Promise<Channel>` - Create and initialize a new channel
127
+
128
+ #### Instance Methods
129
+
130
+ - **sendMessage(payload, options?)**: `Promise<void>` - Send a message through the channel
131
+ - **close()**: `void` - Close the channel and cleanup subscriptions
132
+
133
+ #### Configuration (ChannelConfig)
134
+
135
+ - **client**: `IAsgardServiceClient` - Instance of AsgardServiceClient
136
+ - **customChannelId**: `string` - Unique channel identifier
137
+ - **customMessageId?**: `string` - Optional message ID
138
+ - **conversation**: `Conversation` - Initial conversation state
139
+ - **statesObserver?**: `ObserverOrNext<ChannelStates>` - Observer for channel state changes
140
+
141
+ #### Properties
142
+
143
+ - **customChannelId**: `string` - The channel identifier
144
+ - **customMessageId?**: `string` - Optional message identifier
145
+
146
+ #### Example Usage
147
+
148
+ ```javascript
149
+ import { AsgardServiceClient, Channel, Conversation } from '@asgard-js/core';
150
+
151
+ const client = new AsgardServiceClient({
152
+ botProviderEndpoint: 'https://api.example.com/bot-provider/123',
153
+ apiKey: 'your-api-key',
154
+ });
155
+
156
+ const conversation = new Conversation({ messages: new Map() });
157
+
158
+ const channel = await Channel.reset({
159
+ client,
160
+ customChannelId: 'channel-123',
161
+ conversation,
162
+ statesObserver: (states) => {
163
+ console.log('Connection status:', states.isConnecting);
164
+ console.log('Messages:', Array.from(states.conversation.messages.values()));
165
+ },
166
+ });
167
+
168
+ // Send a message
169
+ await channel.sendMessage({ text: 'Hello, bot!' });
170
+ ```
171
+
172
+ ### Conversation
173
+
174
+ Immutable conversation state manager that handles message updates and SSE event processing.
175
+
176
+ #### Constructor
177
+
178
+ - **constructor(options)**: Initialize conversation with `{messages: Map<string, ConversationMessage> | null}`
179
+
180
+ #### Methods
181
+
182
+ - **pushMessage(message)**: `Conversation` - Add a new message (returns new instance)
183
+ - **onMessage(response)**: `Conversation` - Process SSE response and update conversation
184
+
185
+ #### Properties
186
+
187
+ - **messages**: `Map<string, ConversationMessage> | null` - Map of all messages in the conversation
188
+
189
+ #### Message Types
190
+
191
+ - **ConversationUserMessage**: User-sent messages with `text` and `time`
192
+ - **ConversationBotMessage**: Bot responses with `message`, `isTyping`, `typingText`, `eventType`
193
+ - **ConversationErrorMessage**: Error messages with `error` details
194
+
195
+ #### Example Usage
196
+
197
+ ```javascript
198
+ import { Conversation } from '@asgard-js/core';
199
+
200
+ // Create new conversation
201
+ const conversation = new Conversation({ messages: new Map() });
202
+
203
+ // Add a user message
204
+ const userMessage = {
205
+ id: 'msg-1',
206
+ type: 'user',
207
+ text: 'Hello',
208
+ time: Date.now(),
209
+ };
210
+
211
+ const updatedConversation = conversation.pushMessage(userMessage);
212
+ console.log('Messages:', Array.from(updatedConversation.messages.values()));
213
+ ```
214
+
215
+ ## Testing
216
+
217
+ The core package includes comprehensive tests using Vitest.
218
+
219
+ ### Running Tests
220
+
221
+ ```sh
222
+ # Run tests once
223
+ yarn test:core
224
+
225
+ # Run tests in watch mode
226
+ yarn test:core:watch
227
+
228
+ # Run tests with UI
229
+ yarn test:core:ui
230
+
231
+ # Run tests with coverage
232
+ yarn test:core:coverage
233
+ ```
234
+
235
+ ### Test Structure
236
+
237
+ Tests are located alongside source files with `.spec.ts` extensions:
238
+
239
+ - `src/lib/client.spec.ts` - Tests for AsgardServiceClient including deprecation scenarios
240
+ - Test environment: jsdom with Vitest
241
+ - Coverage reports available in `test-output/vitest/coverage/`
242
+
243
+ ### Writing Tests
244
+
245
+ The package uses Vitest for testing with the following setup:
246
+
247
+ - TypeScript support
248
+ - jsdom environment for DOM APIs
249
+ - ESLint integration
250
+ - Coverage reporting with v8 provider
251
+
252
+ Example test structure:
253
+
254
+ ```javascript
255
+ import { describe, it, expect } from 'vitest';
256
+ import { AsgardServiceClient } from './client';
257
+
258
+ describe('AsgardServiceClient', () => {
259
+ it('should create client with botProviderEndpoint', () => {
260
+ const client = new AsgardServiceClient({
261
+ botProviderEndpoint: 'https://api.example.com/bot-provider/bp-123',
262
+ apiKey: 'test-key',
263
+ });
264
+
265
+ expect(client).toBeDefined();
266
+ });
267
+ });
268
+ ```
269
+
270
+ ## Development
271
+
272
+ To develop the core package locally, follow these steps:
273
+
274
+ 1. Clone the repository and navigate to the project root directory.
275
+
276
+ 2. Install dependencies:
277
+
278
+ ```sh
279
+ yarn install
280
+ ```
281
+
282
+ 3. Start development:
283
+
284
+ You can use the following commands to work with the core package:
285
+
286
+ ```sh
287
+ # Lint the core package
288
+ yarn lint:core
289
+
290
+ # Run tests
291
+ yarn test:core
292
+
293
+ # Build the package
294
+ yarn build:core
295
+
296
+ # Watch mode for development
297
+ yarn watch:core
298
+ ```
299
+
300
+ Setup your npm registry token for yarn publishing:
301
+
302
+ ```sh
303
+ cd ~/
304
+ touch .npmrc
305
+ echo "//registry.npmjs.org/:_authToken={{YOUR_TOKEN}}" >> .npmrc
306
+ ```
307
+
308
+ For working with both core and React packages:
309
+
310
+ ```sh
311
+ # Lint both packages
312
+ yarn lint:packages
313
+
314
+ # Test both packages
315
+ yarn test
316
+
317
+ # Build core package (required for React package)
318
+ yarn build:core
319
+ yarn build:react
320
+
321
+ # Release packages
322
+ yarn release:core # Release core package
323
+ yarn release:react # Release React package
324
+ ```
325
+
326
+ All builds will be available in the `dist` directory.
327
+
328
+ ## Contributing
329
+
330
+ We welcome contributions! Please read our [contributing guide](../../CONTRIBUTING.md) to get started.
331
+
332
+ ## License
333
+
334
+ This project is licensed under the MIT License - see the [LICENSE](../../LICENSE) file for details.
@@ -1,13 +1,21 @@
1
- export declare enum FetchSSEAction {
1
+ export declare enum FetchSseAction {
2
2
  RESET_CHANNEL = "RESET_CHANNEL",
3
3
  NONE = "NONE"
4
4
  }
5
5
  export declare enum EventType {
6
6
  INIT = "asgard.run.init",
7
+ PROCESS = "asgard.process",
8
+ PROCESS_START = "asgard.process.start",
9
+ PROCESS_COMPLETE = "asgard.process.complete",
10
+ MESSAGE = "asgard.message",
7
11
  MESSAGE_START = "asgard.message.start",
8
12
  MESSAGE_DELTA = "asgard.message.delta",
9
13
  MESSAGE_COMPLETE = "asgard.message.complete",
10
- DONE = "asgard.run.done"
14
+ TOOL_CALL = "asgard.tool_call",
15
+ TOOL_CALL_START = "asgard.tool_call.start",
16
+ TOOL_CALL_COMPLETE = "asgard.tool_call.complete",
17
+ DONE = "asgard.run.done",
18
+ ERROR = "asgard.run.error"
11
19
  }
12
20
  export declare enum MessageTemplateType {
13
21
  TEXT = "TEXT",
@@ -17,6 +25,7 @@ export declare enum MessageTemplateType {
17
25
  VIDEO = "VIDEO",
18
26
  AUDIO = "AUDIO",
19
27
  LOCATION = "LOCATION",
20
- CAROUSEL = "CAROUSEL"
28
+ CAROUSEL = "CAROUSEL",
29
+ CHART = "CHART"
21
30
  }
22
31
  //# 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,aAAa,yBAAyB;IACtC,aAAa,yBAAyB;IACtC,gBAAgB,4BAA4B;IAC5C,IAAI,oBAAoB;CACzB;AAED,oBAAY,mBAAmB;IAC7B,IAAI,SAAS;IACb,IAAI,SAAS;IACb,MAAM,WAAW;IACjB,KAAK,UAAU;IACf,KAAK,UAAU;IACf,KAAK,UAAU;IACf,QAAQ,aAAa;IACrB,QAAQ,aAAa;CACtB"}
1
+ {"version":3,"file":"enum.d.ts","sourceRoot":"","sources":["../../src/constants/enum.ts"],"names":[],"mappings":"AAAA,oBAAY,cAAc;IACxB,aAAa,kBAAkB;IAC/B,IAAI,SAAS;CACd;AAED,oBAAY,SAAS;IACnB,IAAI,oBAAoB;IACxB,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"}
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
- "use strict";var Ye=Object.defineProperty;var Be=(t,n,e)=>n in t?Ye(t,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[n]=e;var E=(t,n,e)=>Be(t,typeof n!="symbol"?n+"":n,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var I=(t=>(t.RESET_CHANNEL="RESET_CHANNEL",t.NONE="NONE",t))(I||{}),le=(t=>(t.INIT="asgard.run.init",t.MESSAGE_START="asgard.message.start",t.MESSAGE_DELTA="asgard.message.delta",t.MESSAGE_COMPLETE="asgard.message.complete",t.DONE="asgard.run.done",t))(le||{}),de=(t=>(t.TEXT="TEXT",t.HINT="HINT",t.BUTTON="BUTTON",t.IMAGE="IMAGE",t.VIDEO="VIDEO",t.AUDIO="AUDIO",t.LOCATION="LOCATION",t.CAROUSEL="CAROUSEL",t))(de||{});function Ke(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var J={exports:{}},T=typeof Reflect=="object"?Reflect:null,Z=T&&typeof T.apply=="function"?T.apply:function(n,e,r){return Function.prototype.apply.call(n,e,r)},U;T&&typeof T.ownKeys=="function"?U=T.ownKeys:Object.getOwnPropertySymbols?U=function(n){return Object.getOwnPropertyNames(n).concat(Object.getOwnPropertySymbols(n))}:U=function(n){return Object.getOwnPropertyNames(n)};function ze(t){console&&console.warn&&console.warn(t)}var he=Number.isNaN||function(n){return n!==n};function d(){d.init.call(this)}J.exports=d;J.exports.once=Ze;d.EventEmitter=d;d.prototype._events=void 0;d.prototype._eventsCount=0;d.prototype._maxListeners=void 0;var ee=10;function G(t){if(typeof t!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t)}Object.defineProperty(d,"defaultMaxListeners",{enumerable:!0,get:function(){return ee},set:function(t){if(typeof t!="number"||t<0||he(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");ee=t}});d.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0};d.prototype.setMaxListeners=function(n){if(typeof n!="number"||n<0||he(n))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+n+".");return this._maxListeners=n,this};function ve(t){return t._maxListeners===void 0?d.defaultMaxListeners:t._maxListeners}d.prototype.getMaxListeners=function(){return ve(this)};d.prototype.emit=function(n){for(var e=[],r=1;r<arguments.length;r++)e.push(arguments[r]);var i=n==="error",o=this._events;if(o!==void 0)i=i&&o.error===void 0;else if(!i)return!1;if(i){var u;if(e.length>0&&(u=e[0]),u instanceof Error)throw u;var s=new Error("Unhandled error."+(u?" ("+u.message+")":""));throw s.context=u,s}var f=o[n];if(f===void 0)return!1;if(typeof f=="function")Z(f,this,e);else for(var a=f.length,l=we(f,a),r=0;r<a;++r)Z(l[r],this,e);return!0};function pe(t,n,e,r){var i,o,u;if(G(e),o=t._events,o===void 0?(o=t._events=Object.create(null),t._eventsCount=0):(o.newListener!==void 0&&(t.emit("newListener",n,e.listener?e.listener:e),o=t._events),u=o[n]),u===void 0)u=o[n]=e,++t._eventsCount;else if(typeof u=="function"?u=o[n]=r?[e,u]:[u,e]:r?u.unshift(e):u.push(e),i=ve(t),i>0&&u.length>i&&!u.warned){u.warned=!0;var s=new Error("Possible EventEmitter memory leak detected. "+u.length+" "+String(n)+" listeners added. Use emitter.setMaxListeners() to increase limit");s.name="MaxListenersExceededWarning",s.emitter=t,s.type=n,s.count=u.length,ze(s)}return t}d.prototype.addListener=function(n,e){return pe(this,n,e,!1)};d.prototype.on=d.prototype.addListener;d.prototype.prependListener=function(n,e){return pe(this,n,e,!0)};function Je(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function ye(t,n,e){var r={fired:!1,wrapFn:void 0,target:t,type:n,listener:e},i=Je.bind(r);return i.listener=e,r.wrapFn=i,i}d.prototype.once=function(n,e){return G(e),this.on(n,ye(this,n,e)),this};d.prototype.prependOnceListener=function(n,e){return G(e),this.prependListener(n,ye(this,n,e)),this};d.prototype.removeListener=function(n,e){var r,i,o,u,s;if(G(e),i=this._events,i===void 0)return this;if(r=i[n],r===void 0)return this;if(r===e||r.listener===e)--this._eventsCount===0?this._events=Object.create(null):(delete i[n],i.removeListener&&this.emit("removeListener",n,r.listener||e));else if(typeof r!="function"){for(o=-1,u=r.length-1;u>=0;u--)if(r[u]===e||r[u].listener===e){s=r[u].listener,o=u;break}if(o<0)return this;o===0?r.shift():Xe(r,o),r.length===1&&(i[n]=r[0]),i.removeListener!==void 0&&this.emit("removeListener",n,s||e)}return this};d.prototype.off=d.prototype.removeListener;d.prototype.removeAllListeners=function(n){var e,r,i;if(r=this._events,r===void 0)return this;if(r.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):r[n]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete r[n]),this;if(arguments.length===0){var o=Object.keys(r),u;for(i=0;i<o.length;++i)u=o[i],u!=="removeListener"&&this.removeAllListeners(u);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(e=r[n],typeof e=="function")this.removeListener(n,e);else if(e!==void 0)for(i=e.length-1;i>=0;i--)this.removeListener(n,e[i]);return this};function be(t,n,e){var r=t._events;if(r===void 0)return[];var i=r[n];return i===void 0?[]:typeof i=="function"?e?[i.listener||i]:[i]:e?Qe(i):we(i,i.length)}d.prototype.listeners=function(n){return be(this,n,!0)};d.prototype.rawListeners=function(n){return be(this,n,!1)};d.listenerCount=function(t,n){return typeof t.listenerCount=="function"?t.listenerCount(n):me.call(t,n)};d.prototype.listenerCount=me;function me(t){var n=this._events;if(n!==void 0){var e=n[t];if(typeof e=="function")return 1;if(e!==void 0)return e.length}return 0}d.prototype.eventNames=function(){return this._eventsCount>0?U(this._events):[]};function we(t,n){for(var e=new Array(n),r=0;r<n;++r)e[r]=t[r];return e}function Xe(t,n){for(;n+1<t.length;n++)t[n]=t[n+1];t.pop()}function Qe(t){for(var n=new Array(t.length),e=0;e<n.length;++e)n[e]=t[e].listener||t[e];return n}function Ze(t,n){return new Promise(function(e,r){function i(u){t.removeListener(n,o),r(u)}function o(){typeof t.removeListener=="function"&&t.removeListener("error",i),e([].slice.call(arguments))}ge(t,n,o,{once:!0}),n!=="error"&&et(t,i,{once:!0})})}function et(t,n,e){typeof t.on=="function"&&ge(t,"error",n,e)}function ge(t,n,e,r){if(typeof t.on=="function")r.once?t.once(n,e):t.on(n,e);else if(typeof t.addEventListener=="function")t.addEventListener(n,function i(o){r.once&&t.removeEventListener(n,i),e(o)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof t)}var tt=J.exports;const nt=Ke(tt);var Y=function(t,n){return Y=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,r){e.__proto__=r}||function(e,r){for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(e[i]=r[i])},Y(t,n)};function S(t,n){if(typeof n!="function"&&n!==null)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");Y(t,n);function e(){this.constructor=t}t.prototype=n===null?Object.create(n):(e.prototype=n.prototype,new e)}function rt(t,n,e,r){function i(o){return o instanceof e?o:new e(function(u){u(o)})}return new(e||(e=Promise))(function(o,u){function s(l){try{a(r.next(l))}catch(y){u(y)}}function f(l){try{a(r.throw(l))}catch(y){u(y)}}function a(l){l.done?o(l.value):i(l.value).then(s,f)}a((r=r.apply(t,n||[])).next())})}function Ee(t,n){var e={label:0,sent:function(){if(o[0]&1)throw o[1];return o[1]},trys:[],ops:[]},r,i,o,u=Object.create((typeof Iterator=="function"?Iterator:Object).prototype);return u.next=s(0),u.throw=s(1),u.return=s(2),typeof Symbol=="function"&&(u[Symbol.iterator]=function(){return this}),u;function s(a){return function(l){return f([a,l])}}function f(a){if(r)throw new TypeError("Generator is already executing.");for(;u&&(u=0,a[0]&&(e=0)),e;)try{if(r=1,i&&(o=a[0]&2?i.return:a[0]?i.throw||((o=i.return)&&o.call(i),0):i.next)&&!(o=o.call(i,a[1])).done)return o;switch(i=0,o&&(a=[a[0]&2,o.value]),a[0]){case 0:case 1:o=a;break;case 4:return e.label++,{value:a[1],done:!1};case 5:e.label++,i=a[1],a=[0];continue;case 7:a=e.ops.pop(),e.trys.pop();continue;default:if(o=e.trys,!(o=o.length>0&&o[o.length-1])&&(a[0]===6||a[0]===2)){e=0;continue}if(a[0]===3&&(!o||a[1]>o[0]&&a[1]<o[3])){e.label=a[1];break}if(a[0]===6&&e.label<o[1]){e.label=o[1],o=a;break}if(o&&e.label<o[2]){e.label=o[2],e.ops.push(a);break}o[2]&&e.ops.pop(),e.trys.pop();continue}a=n.call(t,e)}catch(l){a=[6,l],i=0}finally{r=o=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}}function P(t){var n=typeof Symbol=="function"&&Symbol.iterator,e=n&&t[n],r=0;if(e)return e.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")}function $(t,n){var e=typeof Symbol=="function"&&t[Symbol.iterator];if(!e)return t;var r=e.call(t),i,o=[],u;try{for(;(n===void 0||n-- >0)&&!(i=r.next()).done;)o.push(i.value)}catch(s){u={error:s}}finally{try{i&&!i.done&&(e=r.return)&&e.call(r)}finally{if(u)throw u.error}}return o}function D(t,n,e){if(e||arguments.length===2)for(var r=0,i=n.length,o;r<i;r++)(o||!(r in n))&&(o||(o=Array.prototype.slice.call(n,0,r)),o[r]=n[r]);return t.concat(o||Array.prototype.slice.call(n))}function k(t){return this instanceof k?(this.v=t,this):new k(t)}function it(t,n,e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r=e.apply(t,n||[]),i,o=[];return i=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),s("next"),s("throw"),s("return",u),i[Symbol.asyncIterator]=function(){return this},i;function u(c){return function(p){return Promise.resolve(p).then(c,y)}}function s(c,p){r[c]&&(i[c]=function(h){return new Promise(function(O,w){o.push([c,h,O,w])>1||f(c,h)})},p&&(i[c]=p(i[c])))}function f(c,p){try{a(r[c](p))}catch(h){m(o[0][3],h)}}function a(c){c.value instanceof k?Promise.resolve(c.value.v).then(l,y):m(o[0][2],c)}function l(c){f("next",c)}function y(c){f("throw",c)}function m(c,p){c(p),o.shift(),o.length&&f(o[0][0],o[0][1])}}function ot(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=t[Symbol.asyncIterator],e;return n?n.call(t):(t=typeof P=="function"?P(t):t[Symbol.iterator](),e={},r("next"),r("throw"),r("return"),e[Symbol.asyncIterator]=function(){return this},e);function r(o){e[o]=t[o]&&function(u){return new Promise(function(s,f){u=t[o](u),i(s,f,u.done,u.value)})}}function i(o,u,s,f){Promise.resolve(f).then(function(a){o({value:a,done:s})},u)}}function v(t){return typeof t=="function"}function Se(t){var n=function(r){Error.call(r),r.stack=new Error().stack},e=t(n);return e.prototype=Object.create(Error.prototype),e.prototype.constructor=e,e}var V=Se(function(t){return function(e){t(this),this.message=e?e.length+` errors occurred during unsubscription:
1
+ "use strict";var Ue=Object.defineProperty;var Ne=(n,t,e)=>t in n?Ue(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var m=(n,t,e)=>Ne(n,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var N=(n=>(n.RESET_CHANNEL="RESET_CHANNEL",n.NONE="NONE",n))(N||{}),h=(n=>(n.INIT="asgard.run.init",n.PROCESS="asgard.process",n.PROCESS_START="asgard.process.start",n.PROCESS_COMPLETE="asgard.process.complete",n.MESSAGE="asgard.message",n.MESSAGE_START="asgard.message.start",n.MESSAGE_DELTA="asgard.message.delta",n.MESSAGE_COMPLETE="asgard.message.complete",n.TOOL_CALL="asgard.tool_call",n.TOOL_CALL_START="asgard.tool_call.start",n.TOOL_CALL_COMPLETE="asgard.tool_call.complete",n.DONE="asgard.run.done",n.ERROR="asgard.run.error",n))(h||{}),fe=(n=>(n.TEXT="TEXT",n.HINT="HINT",n.BUTTON="BUTTON",n.IMAGE="IMAGE",n.VIDEO="VIDEO",n.AUDIO="AUDIO",n.LOCATION="LOCATION",n.CAROUSEL="CAROUSEL",n.CHART="CHART",n))(fe||{}),Y=function(n,t){return Y=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,r){e.__proto__=r}||function(e,r){for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(e[i]=r[i])},Y(n,t)};function O(n,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");Y(n,t);function e(){this.constructor=n}n.prototype=t===null?Object.create(t):(e.prototype=t.prototype,new e)}function $e(n,t,e,r){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(r.next(f))}catch(y){s(y)}}function a(f){try{u(r.throw(f))}catch(y){s(y)}}function u(f){f.done?o(f.value):i(f.value).then(c,a)}u((r=r.apply(n,t||[])).next())})}function le(n,t){var e={label:0,sent:function(){if(o[0]&1)throw o[1];return o[1]},trys:[],ops:[]},r,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(r)throw new TypeError("Generator is already executing.");for(;s&&(s=0,u[0]&&(e=0)),e;)try{if(r=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(n,e)}catch(f){u=[6,f],i=0}finally{r=o=0}if(u[0]&5)throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}function M(n){var t=typeof Symbol=="function"&&Symbol.iterator,e=t&&n[t],r=0;if(e)return e.call(n);if(n&&typeof n.length=="number")return{next:function(){return n&&r>=n.length&&(n=void 0),{value:n&&n[r++],done:!n}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function L(n,t){var e=typeof Symbol=="function"&&n[Symbol.iterator];if(!e)return n;var r=e.call(n),i,o=[],s;try{for(;(t===void 0||t-- >0)&&!(i=r.next()).done;)o.push(i.value)}catch(c){s={error:c}}finally{try{i&&!i.done&&(e=r.return)&&e.call(r)}finally{if(s)throw s.error}}return o}function R(n,t,e){if(e||arguments.length===2)for(var r=0,i=t.length,o;r<i;r++)(o||!(r in t))&&(o||(o=Array.prototype.slice.call(t,0,r)),o[r]=t[r]);return n.concat(o||Array.prototype.slice.call(t))}function P(n){return this instanceof P?(this.v=n,this):new P(n)}function Ge(n,t,e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r=e.apply(n,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(v){return Promise.resolve(v).then(l,y)}}function c(l,v){r[l]&&(i[l]=function(d){return new Promise(function(g,w){o.push([l,d,g,w])>1||a(l,d)})},v&&(i[l]=v(i[l])))}function a(l,v){try{u(r[l](v))}catch(d){b(o[0][3],d)}}function u(l){l.value instanceof P?Promise.resolve(l.value.v).then(f,y):b(o[0][2],l)}function f(l){a("next",l)}function y(l){a("throw",l)}function b(l,v){l(v),o.shift(),o.length&&a(o[0][0],o[0][1])}}function Fe(n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=n[Symbol.asyncIterator],e;return t?t.call(n):(n=typeof M=="function"?M(n):n[Symbol.iterator](),e={},r("next"),r("throw"),r("return"),e[Symbol.asyncIterator]=function(){return this},e);function r(o){e[o]=n[o]&&function(s){return new Promise(function(c,a){s=n[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 p(n){return typeof n=="function"}function de(n){var t=function(r){Error.call(r),r.stack=new Error().stack},e=n(t);return e.prototype=Object.create(Error.prototype),e.prototype.constructor=e,e}var K=de(function(n){return function(e){n(this),this.message=e?e.length+` errors occurred during unsubscription:
2
2
  `+e.map(function(r,i){return i+1+") "+r.toString()}).join(`
3
- `):"",this.name="UnsubscriptionError",this.errors=e}});function F(t,n){if(t){var e=t.indexOf(n);0<=e&&t.splice(e,1)}}var N=function(){function t(n){this.initialTeardown=n,this.closed=!1,this._parentage=null,this._finalizers=null}return t.prototype.unsubscribe=function(){var n,e,r,i,o;if(!this.closed){this.closed=!0;var u=this._parentage;if(u)if(this._parentage=null,Array.isArray(u))try{for(var s=P(u),f=s.next();!f.done;f=s.next()){var a=f.value;a.remove(this)}}catch(h){n={error:h}}finally{try{f&&!f.done&&(e=s.return)&&e.call(s)}finally{if(n)throw n.error}}else u.remove(this);var l=this.initialTeardown;if(v(l))try{l()}catch(h){o=h instanceof V?h.errors:[h]}var y=this._finalizers;if(y){this._finalizers=null;try{for(var m=P(y),c=m.next();!c.done;c=m.next()){var p=c.value;try{te(p)}catch(h){o=o??[],h instanceof V?o=D(D([],$(o)),$(h.errors)):o.push(h)}}}catch(h){r={error:h}}finally{try{c&&!c.done&&(i=m.return)&&i.call(m)}finally{if(r)throw r.error}}}if(o)throw new V(o)}},t.prototype.add=function(n){var e;if(n&&n!==this)if(this.closed)te(n);else{if(n instanceof t){if(n.closed||n._hasParent(this))return;n._addParent(this)}(this._finalizers=(e=this._finalizers)!==null&&e!==void 0?e:[]).push(n)}},t.prototype._hasParent=function(n){var e=this._parentage;return e===n||Array.isArray(e)&&e.includes(n)},t.prototype._addParent=function(n){var e=this._parentage;this._parentage=Array.isArray(e)?(e.push(n),e):e?[e,n]:n},t.prototype._removeParent=function(n){var e=this._parentage;e===n?this._parentage=null:Array.isArray(e)&&F(e,n)},t.prototype.remove=function(n){var e=this._finalizers;e&&F(e,n),n instanceof t&&n._removeParent(this)},t.EMPTY=function(){var n=new t;return n.closed=!0,n}(),t}(),Oe=N.EMPTY;function _e(t){return t instanceof N||t&&"closed"in t&&v(t.remove)&&v(t.add)&&v(t.unsubscribe)}function te(t){v(t)?t():t.unsubscribe()}var ut={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},xe={setTimeout:function(t,n){for(var e=[],r=2;r<arguments.length;r++)e[r-2]=arguments[r];return setTimeout.apply(void 0,D([t,n],$(e)))},clearTimeout:function(t){var n=xe.delegate;return((n==null?void 0:n.clearTimeout)||clearTimeout)(t)},delegate:void 0};function Le(t){xe.setTimeout(function(){throw t})}function B(){}function M(t){t()}var X=function(t){S(n,t);function n(e){var r=t.call(this)||this;return r.isStopped=!1,e?(r.destination=e,_e(e)&&e.add(r)):r.destination=ft,r}return n.create=function(e,r,i){return new K(e,r,i)},n.prototype.next=function(e){this.isStopped||this._next(e)},n.prototype.error=function(e){this.isStopped||(this.isStopped=!0,this._error(e))},n.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},n.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,t.prototype.unsubscribe.call(this),this.destination=null)},n.prototype._next=function(e){this.destination.next(e)},n.prototype._error=function(e){try{this.destination.error(e)}finally{this.unsubscribe()}},n.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},n}(N),st=function(){function t(n){this.partialObserver=n}return t.prototype.next=function(n){var e=this.partialObserver;if(e.next)try{e.next(n)}catch(r){R(r)}},t.prototype.error=function(n){var e=this.partialObserver;if(e.error)try{e.error(n)}catch(r){R(r)}else R(n)},t.prototype.complete=function(){var n=this.partialObserver;if(n.complete)try{n.complete()}catch(e){R(e)}},t}(),K=function(t){S(n,t);function n(e,r,i){var o=t.call(this)||this,u;return v(e)||!e?u={next:e??void 0,error:r??void 0,complete:i??void 0}:u=e,o.destination=new st(u),o}return n}(X);function R(t){Le(t)}function at(t){throw t}var ft={closed:!0,next:B,error:at,complete:B},Q=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();function ct(t){return t}function lt(t){return t.length===0?ct:t.length===1?t[0]:function(e){return t.reduce(function(r,i){return i(r)},e)}}var b=function(){function t(n){n&&(this._subscribe=n)}return t.prototype.lift=function(n){var e=new t;return e.source=this,e.operator=n,e},t.prototype.subscribe=function(n,e,r){var i=this,o=ht(n)?n:new K(n,e,r);return M(function(){var u=i,s=u.operator,f=u.source;o.add(s?s.call(o,f):f?i._subscribe(o):i._trySubscribe(o))}),o},t.prototype._trySubscribe=function(n){try{return this._subscribe(n)}catch(e){n.error(e)}},t.prototype.forEach=function(n,e){var r=this;return e=ne(e),new e(function(i,o){var u=new K({next:function(s){try{n(s)}catch(f){o(f),u.unsubscribe()}},error:o,complete:i});r.subscribe(u)})},t.prototype._subscribe=function(n){var e;return(e=this.source)===null||e===void 0?void 0:e.subscribe(n)},t.prototype[Q]=function(){return this},t.prototype.pipe=function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];return lt(n)(this)},t.prototype.toPromise=function(n){var e=this;return n=ne(n),new n(function(r,i){var o;e.subscribe(function(u){return o=u},function(u){return i(u)},function(){return r(o)})})},t.create=function(n){return new t(n)},t}();function ne(t){var n;return(n=t??ut.Promise)!==null&&n!==void 0?n:Promise}function dt(t){return t&&v(t.next)&&v(t.error)&&v(t.complete)}function ht(t){return t&&t instanceof X||dt(t)&&_e(t)}function vt(t){return v(t==null?void 0:t.lift)}function L(t){return function(n){if(vt(n))return n.lift(function(e){try{return t(e,this)}catch(r){this.error(r)}});throw new TypeError("Unable to lift unknown Observable type")}}function C(t,n,e,r,i){return new pt(t,n,e,r,i)}var pt=function(t){S(n,t);function n(e,r,i,o,u,s){var f=t.call(this,e)||this;return f.onFinalize=u,f.shouldUnsubscribe=s,f._next=r?function(a){try{r(a)}catch(l){e.error(l)}}:t.prototype._next,f._error=o?function(a){try{o(a)}catch(l){e.error(l)}finally{this.unsubscribe()}}:t.prototype._error,f._complete=i?function(){try{i()}catch(a){e.error(a)}finally{this.unsubscribe()}}:t.prototype._complete,f}return n.prototype.unsubscribe=function(){var e;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var r=this.closed;t.prototype.unsubscribe.call(this),!r&&((e=this.onFinalize)===null||e===void 0||e.call(this))}},n}(X),yt=Se(function(t){return function(){t(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}}),Ae=function(t){S(n,t);function n(){var e=t.call(this)||this;return e.closed=!1,e.currentObservers=null,e.observers=[],e.isStopped=!1,e.hasError=!1,e.thrownError=null,e}return n.prototype.lift=function(e){var r=new re(this,this);return r.operator=e,r},n.prototype._throwIfClosed=function(){if(this.closed)throw new yt},n.prototype.next=function(e){var r=this;M(function(){var i,o;if(r._throwIfClosed(),!r.isStopped){r.currentObservers||(r.currentObservers=Array.from(r.observers));try{for(var u=P(r.currentObservers),s=u.next();!s.done;s=u.next()){var f=s.value;f.next(e)}}catch(a){i={error:a}}finally{try{s&&!s.done&&(o=u.return)&&o.call(u)}finally{if(i)throw i.error}}}})},n.prototype.error=function(e){var r=this;M(function(){if(r._throwIfClosed(),!r.isStopped){r.hasError=r.isStopped=!0,r.thrownError=e;for(var i=r.observers;i.length;)i.shift().error(e)}})},n.prototype.complete=function(){var e=this;M(function(){if(e._throwIfClosed(),!e.isStopped){e.isStopped=!0;for(var r=e.observers;r.length;)r.shift().complete()}})},n.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(n.prototype,"observed",{get:function(){var e;return((e=this.observers)===null||e===void 0?void 0:e.length)>0},enumerable:!1,configurable:!0}),n.prototype._trySubscribe=function(e){return this._throwIfClosed(),t.prototype._trySubscribe.call(this,e)},n.prototype._subscribe=function(e){return this._throwIfClosed(),this._checkFinalizedStatuses(e),this._innerSubscribe(e)},n.prototype._innerSubscribe=function(e){var r=this,i=this,o=i.hasError,u=i.isStopped,s=i.observers;return o||u?Oe:(this.currentObservers=null,s.push(e),new N(function(){r.currentObservers=null,F(s,e)}))},n.prototype._checkFinalizedStatuses=function(e){var r=this,i=r.hasError,o=r.thrownError,u=r.isStopped;i?e.error(o):u&&e.complete()},n.prototype.asObservable=function(){var e=new b;return e.source=this,e},n.create=function(e,r){return new re(e,r)},n}(b),re=function(t){S(n,t);function n(e,r){var i=t.call(this)||this;return i.destination=e,i.source=r,i}return n.prototype.next=function(e){var r,i;(i=(r=this.destination)===null||r===void 0?void 0:r.next)===null||i===void 0||i.call(r,e)},n.prototype.error=function(e){var r,i;(i=(r=this.destination)===null||r===void 0?void 0:r.error)===null||i===void 0||i.call(r,e)},n.prototype.complete=function(){var e,r;(r=(e=this.destination)===null||e===void 0?void 0:e.complete)===null||r===void 0||r.call(e)},n.prototype._subscribe=function(e){var r,i;return(i=(r=this.source)===null||r===void 0?void 0:r.subscribe(e))!==null&&i!==void 0?i:Oe},n}(Ae),bt={now:function(){return Date.now()},delegate:void 0},mt=function(t){S(n,t);function n(e,r){return t.call(this)||this}return n.prototype.schedule=function(e,r){return this},n}(N),ie={setInterval:function(t,n){for(var e=[],r=2;r<arguments.length;r++)e[r-2]=arguments[r];return setInterval.apply(void 0,D([t,n],$(e)))},clearInterval:function(t){return clearInterval(t)},delegate:void 0},wt=function(t){S(n,t);function n(e,r){var i=t.call(this,e,r)||this;return i.scheduler=e,i.work=r,i.pending=!1,i}return n.prototype.schedule=function(e,r){var i;if(r===void 0&&(r=0),this.closed)return this;this.state=e;var o=this.id,u=this.scheduler;return o!=null&&(this.id=this.recycleAsyncId(u,o,r)),this.pending=!0,this.delay=r,this.id=(i=this.id)!==null&&i!==void 0?i:this.requestAsyncId(u,this.id,r),this},n.prototype.requestAsyncId=function(e,r,i){return i===void 0&&(i=0),ie.setInterval(e.flush.bind(e,this),i)},n.prototype.recycleAsyncId=function(e,r,i){if(i===void 0&&(i=0),i!=null&&this.delay===i&&this.pending===!1)return r;r!=null&&ie.clearInterval(r)},n.prototype.execute=function(e,r){if(this.closed)return new Error("executing a cancelled action");this.pending=!1;var i=this._execute(e,r);if(i)return i;this.pending===!1&&this.id!=null&&(this.id=this.recycleAsyncId(this.scheduler,this.id,null))},n.prototype._execute=function(e,r){var i=!1,o;try{this.work(e)}catch(u){i=!0,o=u||new Error("Scheduled action threw falsy error")}if(i)return this.unsubscribe(),o},n.prototype.unsubscribe=function(){if(!this.closed){var e=this,r=e.id,i=e.scheduler,o=i.actions;this.work=this.state=this.scheduler=null,this.pending=!1,F(o,this),r!=null&&(this.id=this.recycleAsyncId(i,r,null)),this.delay=null,t.prototype.unsubscribe.call(this)}},n}(mt),oe=function(){function t(n,e){e===void 0&&(e=t.now),this.schedulerActionCtor=n,this.now=e}return t.prototype.schedule=function(n,e,r){return e===void 0&&(e=0),new this.schedulerActionCtor(this,n).schedule(r,e)},t.now=bt.now,t}(),gt=function(t){S(n,t);function n(e,r){r===void 0&&(r=oe.now);var i=t.call(this,e,r)||this;return i.actions=[],i._active=!1,i}return n.prototype.flush=function(e){var r=this.actions;if(this._active){r.push(e);return}var i;this._active=!0;do if(i=e.execute(e.state,e.delay))break;while(e=r.shift());if(this._active=!1,i){for(;e=r.shift();)e.unsubscribe();throw i}},n}(oe),Ie=new gt(wt),Et=Ie,St=new b(function(t){return t.complete()});function Te(t){return t&&v(t.schedule)}function Ot(t){return t[t.length-1]}function _t(t){return Te(Ot(t))?t.pop():void 0}var ke=function(t){return t&&typeof t.length=="number"&&typeof t!="function"};function Pe(t){return v(t==null?void 0:t.then)}function Ce(t){return v(t[Q])}function Ne(t){return Symbol.asyncIterator&&v(t==null?void 0:t[Symbol.asyncIterator])}function je(t){return new TypeError("You provided "+(t!==null&&typeof t=="object"?"an invalid object":"'"+t+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}function xt(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}var Re=xt();function Ue(t){return v(t==null?void 0:t[Re])}function Me(t){return it(this,arguments,function(){var e,r,i,o;return Ee(this,function(u){switch(u.label){case 0:e=t.getReader(),u.label=1;case 1:u.trys.push([1,,9,10]),u.label=2;case 2:return[4,k(e.read())];case 3:return r=u.sent(),i=r.value,o=r.done,o?[4,k(void 0)]:[3,5];case 4:return[2,u.sent()];case 5:return[4,k(i)];case 6:return[4,u.sent()];case 7:return u.sent(),[3,2];case 8:return[3,10];case 9:return e.releaseLock(),[7];case 10:return[2]}})})}function $e(t){return v(t==null?void 0:t.getReader)}function A(t){if(t instanceof b)return t;if(t!=null){if(Ce(t))return Lt(t);if(ke(t))return At(t);if(Pe(t))return It(t);if(Ne(t))return De(t);if(Ue(t))return Tt(t);if($e(t))return kt(t)}throw je(t)}function Lt(t){return new b(function(n){var e=t[Q]();if(v(e.subscribe))return e.subscribe(n);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function At(t){return new b(function(n){for(var e=0;e<t.length&&!n.closed;e++)n.next(t[e]);n.complete()})}function It(t){return new b(function(n){t.then(function(e){n.closed||(n.next(e),n.complete())},function(e){return n.error(e)}).then(null,Le)})}function Tt(t){return new b(function(n){var e,r;try{for(var i=P(t),o=i.next();!o.done;o=i.next()){var u=o.value;if(n.next(u),n.closed)return}}catch(s){e={error:s}}finally{try{o&&!o.done&&(r=i.return)&&r.call(i)}finally{if(e)throw e.error}}n.complete()})}function De(t){return new b(function(n){Pt(t,n).catch(function(e){return n.error(e)})})}function kt(t){return De(Me(t))}function Pt(t,n){var e,r,i,o;return rt(this,void 0,void 0,function(){var u,s;return Ee(this,function(f){switch(f.label){case 0:f.trys.push([0,5,6,11]),e=ot(t),f.label=1;case 1:return[4,e.next()];case 2:if(r=f.sent(),!!r.done)return[3,4];if(u=r.value,n.next(u),n.closed)return[2];f.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return s=f.sent(),i={error:s},[3,11];case 6:return f.trys.push([6,,9,10]),r&&!r.done&&(o=e.return)?[4,o.call(e)]:[3,8];case 7:f.sent(),f.label=8;case 8:return[3,10];case 9:if(i)throw i.error;return[7];case 10:return[7];case 11:return n.complete(),[2]}})})}function x(t,n,e,r,i){r===void 0&&(r=0),i===void 0&&(i=!1);var o=n.schedule(function(){e(),i?t.add(this.schedule(null,r)):this.unsubscribe()},r);if(t.add(o),!i)return o}function Fe(t,n){return n===void 0&&(n=0),L(function(e,r){e.subscribe(C(r,function(i){return x(r,t,function(){return r.next(i)},n)},function(){return x(r,t,function(){return r.complete()},n)},function(i){return x(r,t,function(){return r.error(i)},n)}))})}function He(t,n){return n===void 0&&(n=0),L(function(e,r){r.add(t.schedule(function(){return e.subscribe(r)},n))})}function Ct(t,n){return A(t).pipe(He(n),Fe(n))}function Nt(t,n){return A(t).pipe(He(n),Fe(n))}function jt(t,n){return new b(function(e){var r=0;return n.schedule(function(){r===t.length?e.complete():(e.next(t[r++]),e.closed||this.schedule())})})}function Rt(t,n){return new b(function(e){var r;return x(e,n,function(){r=t[Re](),x(e,n,function(){var i,o,u;try{i=r.next(),o=i.value,u=i.done}catch(s){e.error(s);return}u?e.complete():e.next(o)},0,!0)}),function(){return v(r==null?void 0:r.return)&&r.return()}})}function Ge(t,n){if(!t)throw new Error("Iterable cannot be null");return new b(function(e){x(e,n,function(){var r=t[Symbol.asyncIterator]();x(e,n,function(){r.next().then(function(i){i.done?e.complete():e.next(i.value)})},0,!0)})})}function Ut(t,n){return Ge(Me(t),n)}function Mt(t,n){if(t!=null){if(Ce(t))return Ct(t,n);if(ke(t))return jt(t,n);if(Pe(t))return Nt(t,n);if(Ne(t))return Ge(t,n);if(Ue(t))return Rt(t,n);if($e(t))return Ut(t,n)}throw je(t)}function $t(t,n){return n?Mt(t,n):A(t)}function Dt(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];var e=_t(t);return $t(t,e)}function Ft(t){return t instanceof Date&&!isNaN(t)}function We(t,n){return L(function(e,r){var i=0;e.subscribe(C(r,function(o){r.next(t.call(n,o,i++))}))})}function Ht(t,n,e,r,i,o,u,s){var f=[],a=0,l=0,y=!1,m=function(){y&&!f.length&&!a&&n.complete()},c=function(h){return a<r?p(h):f.push(h)},p=function(h){a++;var O=!1;A(e(h,l++)).subscribe(C(n,function(w){n.next(w)},function(){O=!0},void 0,function(){if(O)try{a--;for(var w=function(){var _=f.shift();u||p(_)};f.length&&a<r;)w();m()}catch(_){n.error(_)}}))};return t.subscribe(C(n,c,function(){y=!0,m()})),function(){}}function H(t,n,e){return e===void 0&&(e=1/0),v(n)?H(function(r,i){return We(function(o,u){return n(r,o,i,u)})(A(t(r,i)))},e):(typeof n=="number"&&(e=n),L(function(r,i){return Ht(r,i,t,e)}))}function Gt(t,n,e){t===void 0&&(t=0),e===void 0&&(e=Et);var r=-1;return n!=null&&(Te(n)?e=n:r=n),new b(function(i){var o=Ft(t)?+t-e.now():t;o<0&&(o=0);var u=0;return e.schedule(function(){i.closed||(i.next(u++),0<=r?this.schedule(void 0,r):i.complete())},o)})}function Wt(t,n){return v(n)?H(t,n,1):H(t,1)}function qt(t){return t<=0?function(){return St}:L(function(n,e){var r=0;n.subscribe(C(e,function(i){++r<=t&&(e.next(i),t<=r&&e.complete())}))})}function Vt(t){return We(function(){return t})}function Yt(t,n){return H(function(e,r){return A(t(e,r)).pipe(qt(1),Vt(e))})}function Bt(t,n){n===void 0&&(n=Ie);var e=Gt(t,n);return Yt(function(){return e})}function ue(t){return L(function(n,e){try{n.subscribe(e)}finally{e.add(t)}})}function se(t){return L(function(n,e){A(t).subscribe(C(e,function(){return e.complete()},B)),!e.closed&&n.subscribe(e)})}async function Kt(t,n){const e=t.getReader();let r;for(;!(r=await e.read()).done;)n(r.value)}function zt(t){let n,e,r,i=!1;return function(u){n===void 0?(n=u,e=0,r=-1):n=Xt(n,u);const s=n.length;let f=0;for(;e<s;){i&&(n[e]===10&&(f=++e),i=!1);let a=-1;for(;e<s&&a===-1;++e)switch(n[e]){case 58:r===-1&&(r=e-f);break;case 13:i=!0;case 10:a=e;break}if(a===-1)break;t(n.subarray(f,a),r),f=e,r=-1}f===s?n=void 0:f!==0&&(n=n.subarray(f),e-=f)}}function Jt(t,n,e){let r=ae();const i=new TextDecoder;return function(u,s){if(u.length===0)e==null||e(r),r=ae();else if(s>0){const f=i.decode(u.subarray(0,s)),a=s+(u[s+1]===32?2:1),l=i.decode(u.subarray(a));switch(f){case"data":r.data=r.data?r.data+`
4
- `+l:l;break;case"event":r.event=l;break;case"id":t(r.id=l);break;case"retry":const y=parseInt(l,10);isNaN(y)||n(r.retry=y);break}}}}function Xt(t,n){const e=new Uint8Array(t.length+n.length);return e.set(t),e.set(n,t.length),e}function ae(){return{data:"",event:"",id:"",retry:void 0}}var Qt=function(t,n){var e={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&n.indexOf(r)<0&&(e[r]=t[r]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,r=Object.getOwnPropertySymbols(t);i<r.length;i++)n.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(t,r[i])&&(e[r[i]]=t[r[i]]);return e};const z="text/event-stream",Zt=1e3,fe="last-event-id";function en(t,n){var{signal:e,headers:r,onopen:i,onmessage:o,onclose:u,onerror:s,openWhenHidden:f,fetch:a}=n,l=Qt(n,["signal","headers","onopen","onmessage","onclose","onerror","openWhenHidden","fetch"]);return new Promise((y,m)=>{const c=Object.assign({},r);c.accept||(c.accept=z);let p;function h(){p.abort(),document.hidden||W()}f||document.addEventListener("visibilitychange",h);let O=Zt,w=0;function _(){document.removeEventListener("visibilitychange",h),window.clearTimeout(w),p.abort()}e==null||e.addEventListener("abort",()=>{_(),y()});const qe=a??window.fetch,Ve=i??tn;async function W(){var q;p=new AbortController;try{const j=await qe(t,Object.assign(Object.assign({},l),{headers:c,signal:p.signal}));await Ve(j),await Kt(j.body,zt(Jt(g=>{g?c[fe]=g:delete c[fe]},g=>{O=g},o))),u==null||u(),_(),y()}catch(j){if(!p.signal.aborted)try{const g=(q=s==null?void 0:s(j))!==null&&q!==void 0?q:O;window.clearTimeout(w),w=window.setTimeout(W,g)}catch(g){_(),m(g)}}}W()})}function tn(t){const n=t.headers.get("content-type");if(!(n!=null&&n.startsWith(z)))throw new Error(`Expected content-type to be ${z}, Actual: ${n}`)}function ce(t){const{endpoint:n,webhookToken:e,payload:r}=t;return new b(i=>{const o=new AbortController;return en(n,{method:"POST",headers:{"X-Asgard-Webhook-Token":e,"Content-Type":"application/json"},body:r?JSON.stringify(r):void 0,signal:o.signal,onopen:async u=>{u.ok||(i.error(u),o.abort())},onmessage:u=>{i.next(u)},onclose:()=>{i.complete()},onerror:u=>{i.error(u),o.abort()}}),()=>{o.abort()}})}class nn{constructor(n){E(this,"baseUrl");E(this,"namespace");E(this,"botProviderName");E(this,"endpoint");E(this,"webhookToken");E(this,"eventEmitter");E(this,"destroy$",new Ae);if(!n.baseUrl)throw new Error("baseUrl must be required");if(!n.namespace)throw new Error("namespace must be required");if(!n.botProviderName)throw new Error("botProviderName must be required");if(!n.webhookToken)throw new Error("webhookToken must be required");this.baseUrl=n.baseUrl,this.namespace=n.namespace,this.botProviderName=n.botProviderName,this.webhookToken=n.webhookToken,this.endpoint=`${this.baseUrl}/generic/ns/${this.namespace}/bot-provider/${this.botProviderName}/message/sse`,this.eventEmitter=new nt}on(n,e,r){const i=`${n}:${e}`;this.eventEmitter.listeners(i).length>0&&this.eventEmitter.removeAllListeners(i),this.eventEmitter.on(i,r)}setChannel(n,e){var r;return(r=e==null?void 0:e.onStart)==null||r.call(e),ce({endpoint:this.endpoint,webhookToken:this.webhookToken,payload:Object.assign({action:I.RESET_CHANNEL},n)}).pipe(se(this.destroy$),ue(()=>{var i;return(i=e==null?void 0:e.onCompleted)==null?void 0:i.call(e)})).subscribe({next:i=>{this.eventEmitter.emit(`${I.RESET_CHANNEL}:${i.event}`,JSON.parse(i.data))}})}sendMessage(n,e){var r;return(r=e==null?void 0:e.onStart)==null||r.call(e),ce({endpoint:this.endpoint,webhookToken:this.webhookToken,payload:Object.assign({action:I.NONE},n)}).pipe(Wt(i=>Dt(i).pipe(Bt((e==null?void 0:e.delayTime)??50))),se(this.destroy$),ue(()=>{var i;return(i=e==null?void 0:e.onCompleted)==null?void 0:i.call(e)})).subscribe({next:i=>{this.eventEmitter.emit(`${I.NONE}:${i.event}`,JSON.parse(i.data))}})}close(){this.destroy$.next(),this.destroy$.complete()}}exports.AsgardServiceClient=nn;exports.EventType=le;exports.FetchSSEAction=I;exports.MessageTemplateType=de;
3
+ `):"",this.name="UnsubscriptionError",this.errors=e}});function $(n,t){if(n){var e=n.indexOf(t);0<=e&&n.splice(e,1)}}var k=function(){function n(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}return n.prototype.unsubscribe=function(){var t,e,r,i,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(d){t={error:d}}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(p(f))try{f()}catch(d){o=d instanceof K?d.errors:[d]}var y=this._finalizers;if(y){this._finalizers=null;try{for(var b=M(y),l=b.next();!l.done;l=b.next()){var v=l.value;try{te(v)}catch(d){o=o??[],d instanceof K?o=R(R([],L(o)),L(d.errors)):o.push(d)}}}catch(d){r={error:d}}finally{try{l&&!l.done&&(i=b.return)&&i.call(b)}finally{if(r)throw r.error}}}if(o)throw new K(o)}},n.prototype.add=function(t){var e;if(t&&t!==this)if(this.closed)te(t);else{if(t instanceof n){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=(e=this._finalizers)!==null&&e!==void 0?e:[]).push(t)}},n.prototype._hasParent=function(t){var e=this._parentage;return e===t||Array.isArray(e)&&e.includes(t)},n.prototype._addParent=function(t){var e=this._parentage;this._parentage=Array.isArray(e)?(e.push(t),e):e?[e,t]:t},n.prototype._removeParent=function(t){var e=this._parentage;e===t?this._parentage=null:Array.isArray(e)&&$(e,t)},n.prototype.remove=function(t){var e=this._finalizers;e&&$(e,t),t instanceof n&&t._removeParent(this)},n.EMPTY=function(){var t=new n;return t.closed=!0,t}(),n}(),he=k.EMPTY;function ye(n){return n instanceof k||n&&"closed"in n&&p(n.remove)&&p(n.add)&&p(n.unsubscribe)}function te(n){p(n)?n():n.unsubscribe()}var He={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},ve={setTimeout:function(n,t){for(var e=[],r=2;r<arguments.length;r++)e[r-2]=arguments[r];return setTimeout.apply(void 0,R([n,t],L(e)))},clearTimeout:function(n){var t=ve.delegate;return((t==null?void 0:t.clearTimeout)||clearTimeout)(n)},delegate:void 0};function pe(n){ve.setTimeout(function(){throw n})}function q(){}function U(n){n()}var X=function(n){O(t,n);function t(e){var r=n.call(this)||this;return r.isStopped=!1,e?(r.destination=e,ye(e)&&e.add(r)):r.destination=Ke,r}return t.create=function(e,r,i){return new W(e,r,i)},t.prototype.next=function(e){this.isStopped||this._next(e)},t.prototype.error=function(e){this.isStopped||(this.isStopped=!0,this._error(e))},t.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},t.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,n.prototype.unsubscribe.call(this),this.destination=null)},t.prototype._next=function(e){this.destination.next(e)},t.prototype._error=function(e){try{this.destination.error(e)}finally{this.unsubscribe()}},t.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},t}(k),Ve=function(){function n(t){this.partialObserver=t}return n.prototype.next=function(t){var e=this.partialObserver;if(e.next)try{e.next(t)}catch(r){D(r)}},n.prototype.error=function(t){var e=this.partialObserver;if(e.error)try{e.error(t)}catch(r){D(r)}else D(t)},n.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(e){D(e)}},n}(),W=function(n){O(t,n);function t(e,r,i){var o=n.call(this)||this,s;return p(e)||!e?s={next:e??void 0,error:r??void 0,complete:i??void 0}:s=e,o.destination=new Ve(s),o}return t}(X);function D(n){pe(n)}function Be(n){throw n}var Ke={closed:!0,next:q,error:Be,complete:q},z=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();function F(n){return n}function Ye(n){return n.length===0?F:n.length===1?n[0]:function(e){return n.reduce(function(r,i){return i(r)},e)}}var S=function(){function n(t){t&&(this._subscribe=t)}return n.prototype.lift=function(t){var e=new n;return e.source=this,e.operator=t,e},n.prototype.subscribe=function(t,e,r){var i=this,o=We(t)?t:new W(t,e,r);return U(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},n.prototype._trySubscribe=function(t){try{return this._subscribe(t)}catch(e){t.error(e)}},n.prototype.forEach=function(t,e){var r=this;return e=ne(e),new e(function(i,o){var s=new W({next:function(c){try{t(c)}catch(a){o(a),s.unsubscribe()}},error:o,complete:i});r.subscribe(s)})},n.prototype._subscribe=function(t){var e;return(e=this.source)===null||e===void 0?void 0:e.subscribe(t)},n.prototype[z]=function(){return this},n.prototype.pipe=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return Ye(t)(this)},n.prototype.toPromise=function(t){var e=this;return t=ne(t),new t(function(r,i){var o;e.subscribe(function(s){return o=s},function(s){return i(s)},function(){return r(o)})})},n.create=function(t){return new n(t)},n}();function ne(n){var t;return(t=n??He.Promise)!==null&&t!==void 0?t:Promise}function qe(n){return n&&p(n.next)&&p(n.error)&&p(n.complete)}function We(n){return n&&n instanceof X||qe(n)&&ye(n)}function Je(n){return p(n==null?void 0:n.lift)}function C(n){return function(t){if(Je(t))return t.lift(function(e){try{return n(e,this)}catch(r){this.error(r)}});throw new TypeError("Unable to lift unknown Observable type")}}function E(n,t,e,r,i){return new Xe(n,t,e,r,i)}var Xe=function(n){O(t,n);function t(e,r,i,o,s,c){var a=n.call(this,e)||this;return a.onFinalize=s,a.shouldUnsubscribe=c,a._next=r?function(u){try{r(u)}catch(f){e.error(f)}}:n.prototype._next,a._error=o?function(u){try{o(u)}catch(f){e.error(f)}finally{this.unsubscribe()}}:n.prototype._error,a._complete=i?function(){try{i()}catch(u){e.error(u)}finally{this.unsubscribe()}}:n.prototype._complete,a}return t.prototype.unsubscribe=function(){var e;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var r=this.closed;n.prototype.unsubscribe.call(this),!r&&((e=this.onFinalize)===null||e===void 0||e.call(this))}},t}(X),ze=de(function(n){return function(){n(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}}),Q=function(n){O(t,n);function t(){var e=n.call(this)||this;return e.closed=!1,e.currentObservers=null,e.observers=[],e.isStopped=!1,e.hasError=!1,e.thrownError=null,e}return t.prototype.lift=function(e){var r=new re(this,this);return r.operator=e,r},t.prototype._throwIfClosed=function(){if(this.closed)throw new ze},t.prototype.next=function(e){var r=this;U(function(){var i,o;if(r._throwIfClosed(),!r.isStopped){r.currentObservers||(r.currentObservers=Array.from(r.observers));try{for(var s=M(r.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 r=this;U(function(){if(r._throwIfClosed(),!r.isStopped){r.hasError=r.isStopped=!0,r.thrownError=e;for(var i=r.observers;i.length;)i.shift().error(e)}})},t.prototype.complete=function(){var e=this;U(function(){if(e._throwIfClosed(),!e.isStopped){e.isStopped=!0;for(var r=e.observers;r.length;)r.shift().complete()}})},t.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(t.prototype,"observed",{get:function(){var e;return((e=this.observers)===null||e===void 0?void 0:e.length)>0},enumerable:!1,configurable:!0}),t.prototype._trySubscribe=function(e){return this._throwIfClosed(),n.prototype._trySubscribe.call(this,e)},t.prototype._subscribe=function(e){return this._throwIfClosed(),this._checkFinalizedStatuses(e),this._innerSubscribe(e)},t.prototype._innerSubscribe=function(e){var r=this,i=this,o=i.hasError,s=i.isStopped,c=i.observers;return o||s?he:(this.currentObservers=null,c.push(e),new k(function(){r.currentObservers=null,$(c,e)}))},t.prototype._checkFinalizedStatuses=function(e){var r=this,i=r.hasError,o=r.thrownError,s=r.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,r){return new re(e,r)},t}(S),re=function(n){O(t,n);function t(e,r){var i=n.call(this)||this;return i.destination=e,i.source=r,i}return t.prototype.next=function(e){var r,i;(i=(r=this.destination)===null||r===void 0?void 0:r.next)===null||i===void 0||i.call(r,e)},t.prototype.error=function(e){var r,i;(i=(r=this.destination)===null||r===void 0?void 0:r.error)===null||i===void 0||i.call(r,e)},t.prototype.complete=function(){var e,r;(r=(e=this.destination)===null||e===void 0?void 0:e.complete)===null||r===void 0||r.call(e)},t.prototype._subscribe=function(e){var r,i;return(i=(r=this.source)===null||r===void 0?void 0:r.subscribe(e))!==null&&i!==void 0?i:he},t}(Q),ie=function(n){O(t,n);function t(e){var r=n.call(this)||this;return r._value=e,r}return Object.defineProperty(t.prototype,"value",{get:function(){return this.getValue()},enumerable:!1,configurable:!0}),t.prototype._subscribe=function(e){var r=n.prototype._subscribe.call(this,e);return!r.closed&&e.next(this._value),r},t.prototype.getValue=function(){var e=this,r=e.hasError,i=e.thrownError,o=e._value;if(r)throw i;return this._throwIfClosed(),o},t.prototype.next=function(e){n.prototype.next.call(this,this._value=e)},t}(Q),Qe={now:function(){return Date.now()},delegate:void 0},Ze=function(n){O(t,n);function t(e,r){return n.call(this)||this}return t.prototype.schedule=function(e,r){return this},t}(k),oe={setInterval:function(n,t){for(var e=[],r=2;r<arguments.length;r++)e[r-2]=arguments[r];return setInterval.apply(void 0,R([n,t],L(e)))},clearInterval:function(n){return clearInterval(n)},delegate:void 0},et=function(n){O(t,n);function t(e,r){var i=n.call(this,e,r)||this;return i.scheduler=e,i.work=r,i.pending=!1,i}return t.prototype.schedule=function(e,r){var i;if(r===void 0&&(r=0),this.closed)return this;this.state=e;var o=this.id,s=this.scheduler;return o!=null&&(this.id=this.recycleAsyncId(s,o,r)),this.pending=!0,this.delay=r,this.id=(i=this.id)!==null&&i!==void 0?i:this.requestAsyncId(s,this.id,r),this},t.prototype.requestAsyncId=function(e,r,i){return i===void 0&&(i=0),oe.setInterval(e.flush.bind(e,this),i)},t.prototype.recycleAsyncId=function(e,r,i){if(i===void 0&&(i=0),i!=null&&this.delay===i&&this.pending===!1)return r;r!=null&&oe.clearInterval(r)},t.prototype.execute=function(e,r){if(this.closed)return new Error("executing a cancelled action");this.pending=!1;var i=this._execute(e,r);if(i)return i;this.pending===!1&&this.id!=null&&(this.id=this.recycleAsyncId(this.scheduler,this.id,null))},t.prototype._execute=function(e,r){var i=!1,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,r=e.id,i=e.scheduler,o=i.actions;this.work=this.state=this.scheduler=null,this.pending=!1,$(o,this),r!=null&&(this.id=this.recycleAsyncId(i,r,null)),this.delay=null,n.prototype.unsubscribe.call(this)}},t}(Ze),se=function(){function n(t,e){e===void 0&&(e=n.now),this.schedulerActionCtor=t,this.now=e}return n.prototype.schedule=function(t,e,r){return e===void 0&&(e=0),new this.schedulerActionCtor(this,t).schedule(r,e)},n.now=Qe.now,n}(),tt=function(n){O(t,n);function t(e,r){r===void 0&&(r=se.now);var i=n.call(this,e,r)||this;return i.actions=[],i._active=!1,i}return t.prototype.flush=function(e){var r=this.actions;if(this._active){r.push(e);return}var i;this._active=!0;do if(i=e.execute(e.state,e.delay))break;while(e=r.shift());if(this._active=!1,i){for(;e=r.shift();)e.unsubscribe();throw i}},t}(se),be=new tt(et),nt=be,rt=new S(function(n){return n.complete()});function me(n){return n&&p(n.schedule)}function Se(n){return n[n.length-1]}function it(n){return p(Se(n))?n.pop():void 0}function ge(n){return me(Se(n))?n.pop():void 0}var we=function(n){return n&&typeof n.length=="number"&&typeof n!="function"};function Ee(n){return p(n==null?void 0:n.then)}function Oe(n){return p(n[z])}function Ie(n){return Symbol.asyncIterator&&p(n==null?void 0:n[Symbol.asyncIterator])}function Ae(n){return new TypeError("You provided "+(n!==null&&typeof n=="object"?"an invalid object":"'"+n+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}function ot(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}var _e=ot();function xe(n){return p(n==null?void 0:n[_e])}function Te(n){return Ge(this,arguments,function(){var e,r,i,o;return le(this,function(s){switch(s.label){case 0:e=n.getReader(),s.label=1;case 1:s.trys.push([1,,9,10]),s.label=2;case 2:return[4,P(e.read())];case 3:return r=s.sent(),i=r.value,o=r.done,o?[4,P(void 0)]:[3,5];case 4:return[2,s.sent()];case 5:return[4,P(i)];case 6:return[4,s.sent()];case 7:return s.sent(),[3,2];case 8:return[3,10];case 9:return e.releaseLock(),[7];case 10:return[2]}})})}function Ce(n){return p(n==null?void 0:n.getReader)}function _(n){if(n instanceof S)return n;if(n!=null){if(Oe(n))return st(n);if(we(n))return ut(n);if(Ee(n))return at(n);if(Ie(n))return Pe(n);if(xe(n))return ct(n);if(Ce(n))return ft(n)}throw Ae(n)}function st(n){return new S(function(t){var e=n[z]();if(p(e.subscribe))return e.subscribe(t);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function ut(n){return new S(function(t){for(var e=0;e<n.length&&!t.closed;e++)t.next(n[e]);t.complete()})}function at(n){return new S(function(t){n.then(function(e){t.closed||(t.next(e),t.complete())},function(e){return t.error(e)}).then(null,pe)})}function ct(n){return new S(function(t){var e,r;try{for(var i=M(n),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&&(r=i.return)&&r.call(i)}finally{if(e)throw e.error}}t.complete()})}function Pe(n){return new S(function(t){lt(n,t).catch(function(e){return t.error(e)})})}function ft(n){return Pe(Te(n))}function lt(n,t){var e,r,i,o;return $e(this,void 0,void 0,function(){var s,c;return le(this,function(a){switch(a.label){case 0:a.trys.push([0,5,6,11]),e=Fe(n),a.label=1;case 1:return[4,e.next()];case 2:if(r=a.sent(),!!r.done)return[3,4];if(s=r.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]),r&&!r.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 A(n,t,e,r,i){r===void 0&&(r=0),i===void 0&&(i=!1);var o=t.schedule(function(){e(),i?n.add(this.schedule(null,r)):this.unsubscribe()},r);if(n.add(o),!i)return o}function Me(n,t){return t===void 0&&(t=0),C(function(e,r){e.subscribe(E(r,function(i){return A(r,n,function(){return r.next(i)},t)},function(){return A(r,n,function(){return r.complete()},t)},function(i){return A(r,n,function(){return r.error(i)},t)}))})}function Le(n,t){return t===void 0&&(t=0),C(function(e,r){r.add(n.schedule(function(){return e.subscribe(r)},t))})}function dt(n,t){return _(n).pipe(Le(t),Me(t))}function ht(n,t){return _(n).pipe(Le(t),Me(t))}function yt(n,t){return new S(function(e){var r=0;return t.schedule(function(){r===n.length?e.complete():(e.next(n[r++]),e.closed||this.schedule())})})}function vt(n,t){return new S(function(e){var r;return A(e,t,function(){r=n[_e](),A(e,t,function(){var i,o,s;try{i=r.next(),o=i.value,s=i.done}catch(c){e.error(c);return}s?e.complete():e.next(o)},0,!0)}),function(){return p(r==null?void 0:r.return)&&r.return()}})}function Re(n,t){if(!n)throw new Error("Iterable cannot be null");return new S(function(e){A(e,t,function(){var r=n[Symbol.asyncIterator]();A(e,t,function(){r.next().then(function(i){i.done?e.complete():e.next(i.value)})},0,!0)})})}function pt(n,t){return Re(Te(n),t)}function bt(n,t){if(n!=null){if(Oe(n))return dt(n,t);if(we(n))return yt(n,t);if(Ee(n))return ht(n,t);if(Ie(n))return Re(n,t);if(xe(n))return vt(n,t);if(Ce(n))return pt(n,t)}throw Ae(n)}function Z(n,t){return t?bt(n,t):_(n)}function mt(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];var e=ge(n);return Z(n,e)}function St(n){return n instanceof Date&&!isNaN(n)}function H(n,t){return C(function(e,r){var i=0;e.subscribe(E(r,function(o){r.next(n.call(t,o,i++))}))})}var gt=Array.isArray;function wt(n,t){return gt(t)?n.apply(void 0,R([],L(t))):n(t)}function Et(n){return H(function(t){return wt(n,t)})}var Ot=Array.isArray,It=Object.getPrototypeOf,At=Object.prototype,_t=Object.keys;function xt(n){if(n.length===1){var t=n[0];if(Ot(t))return{args:t,keys:null};if(Tt(t)){var e=_t(t);return{args:e.map(function(r){return t[r]}),keys:e}}}return{args:n,keys:null}}function Tt(n){return n&&typeof n=="object"&&It(n)===At}function Ct(n,t){return n.reduce(function(e,r,i){return e[r]=t[i],e},{})}function Pt(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];var e=ge(n),r=it(n),i=xt(n),o=i.args,s=i.keys;if(o.length===0)return Z([],e);var c=new S(Mt(o,e,s?function(a){return Ct(s,a)}:F));return r?c.pipe(Et(r)):c}function Mt(n,t,e){return e===void 0&&(e=F),function(r){ue(t,function(){for(var i=n.length,o=new Array(i),s=i,c=i,a=function(f){ue(t,function(){var y=Z(n[f],t),b=!1;y.subscribe(E(r,function(l){o[f]=l,b||(b=!0,c--),c||r.next(e(o.slice()))},function(){--s||r.complete()}))},r)},u=0;u<i;u++)a(u)},r)}}function ue(n,t,e){n?A(e,n,t):t()}function Lt(n,t,e,r,i,o,s,c){var a=[],u=0,f=0,y=!1,b=function(){y&&!a.length&&!u&&t.complete()},l=function(d){return u<r?v(d):a.push(d)},v=function(d){u++;var g=!1;_(e(d,f++)).subscribe(E(t,function(w){t.next(w)},function(){g=!0},void 0,function(){if(g)try{u--;for(var w=function(){var x=a.shift();s||v(x)};a.length&&u<r;)w();b()}catch(x){t.error(x)}}))};return n.subscribe(E(t,l,function(){y=!0,b()})),function(){}}function G(n,t,e){return e===void 0&&(e=1/0),p(t)?G(function(r,i){return H(function(o,s){return t(r,o,i,s)})(_(n(r,i)))},e):(typeof t=="number"&&(e=t),C(function(r,i){return Lt(r,i,n,e)}))}function ke(n,t,e){n===void 0&&(n=0),e===void 0&&(e=nt);var r=-1;return t!=null&&(me(t)?e=t:r=t),new S(function(i){var o=St(n)?+n-e.now():n;o<0&&(o=0);var s=0;return e.schedule(function(){i.closed||(i.next(s++),0<=r?this.schedule(void 0,r):i.complete())},o)})}function Rt(n,t){return p(t)?G(n,t,1):G(n,1)}function kt(n){return n<=0?function(){return rt}:C(function(t,e){var r=0;t.subscribe(E(e,function(i){++r<=n&&(e.next(i),n<=r&&e.complete())}))})}function jt(n){return H(function(){return n})}function Dt(n,t){return G(function(e,r){return _(n(e,r)).pipe(kt(1),jt(e))})}function Ut(n,t){t===void 0&&(t=be);var e=ke(n,t);return Dt(function(){return e})}function Nt(n){var t;t={count:n};var e=t.count,r=e===void 0?1/0:e,i=t.delay,o=t.resetOnSuccess,s=o===void 0?!1:o;return r<=0?F:C(function(c,a){var u=0,f,y=function(){var b=!1;f=c.subscribe(E(a,function(l){s&&(u=0),a.next(l)},void 0,function(l){if(u++<r){var v=function(){f?(f.unsubscribe(),f=null,y()):b=!0};if(i!=null){var d=typeof i=="number"?ke(i):_(i(l,u)),g=E(a,function(){g.unsubscribe(),v()},function(){a.complete()});d.subscribe(g)}else v()}else a.error(l)})),b&&(f.unsubscribe(),f=null,y())};y()})}function $t(n){return C(function(t,e){_(n).subscribe(E(e,function(){return e.complete()},q)),!e.closed&&t.subscribe(e)})}async function Gt(n,t){const e=n.getReader();let r;for(;!(r=await e.read()).done;)t(r.value)}function Ft(n){let t,e,r,i=!1;return function(s){t===void 0?(t=s,e=0,r=-1):t=Vt(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:r===-1&&(r=e-a);break;case 13:i=!0;case 10:u=e;break}if(u===-1)break;n(t.subarray(a,u),r),a=e,r=-1}a===c?t=void 0:a!==0&&(t=t.subarray(a),e-=a)}}function Ht(n,t,e){let r=ae();const i=new TextDecoder;return function(s,c){if(s.length===0)e==null||e(r),r=ae();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":r.data=r.data?r.data+`
4
+ `+f:f;break;case"event":r.event=f;break;case"id":n(r.id=f);break;case"retry":const y=parseInt(f,10);isNaN(y)||t(r.retry=y);break}}}}function Vt(n,t){const e=new Uint8Array(n.length+t.length);return e.set(n),e.set(t,n.length),e}function ae(){return{data:"",event:"",id:"",retry:void 0}}var Bt=function(n,t){var e={};for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&t.indexOf(r)<0&&(e[r]=n[r]);if(n!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,r=Object.getOwnPropertySymbols(n);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(n,r[i])&&(e[r[i]]=n[r[i]]);return e};const J="text/event-stream",Kt=1e3,ce="last-event-id";function Yt(n,t){var{signal:e,headers:r,onopen:i,onmessage:o,onclose:s,onerror:c,openWhenHidden:a,fetch:u}=t,f=Bt(t,["signal","headers","onopen","onmessage","onclose","onerror","openWhenHidden","fetch"]);return new Promise((y,b)=>{const l=Object.assign({},r);l.accept||(l.accept=J);let v;function d(){v.abort(),document.hidden||V()}a||document.addEventListener("visibilitychange",d);let g=Kt,w=0;function x(){document.removeEventListener("visibilitychange",d),window.clearTimeout(w),v.abort()}e==null||e.addEventListener("abort",()=>{x(),y()});const je=u??window.fetch,De=i??qt;async function V(){var B;v=new AbortController;try{const j=await je(n,Object.assign(Object.assign({},f),{headers:l,signal:v.signal}));await De(j),await Gt(j.body,Ft(Ht(I=>{I?l[ce]=I:delete l[ce]},I=>{g=I},o))),s==null||s(),x(),y()}catch(j){if(!v.signal.aborted)try{const I=(B=c==null?void 0:c(j))!==null&&B!==void 0?B:g;window.clearTimeout(w),w=window.setTimeout(V,I)}catch(I){x(),b(I)}}}V()})}function qt(n){const t=n.headers.get("content-type");if(!(t!=null&&t.startsWith(J)))throw new Error(`Expected content-type to be ${J}, Actual: ${t}`)}function Wt(n){const{endpoint:t,apiKey:e,payload:r,debugMode:i}=n;return new S(o=>{const s=new AbortController,c={"Content-Type":"application/json"};e&&(c["X-API-KEY"]=e);const a=new URLSearchParams;i&&a.set("is_debug","true");const u=new URL(t);return a.toString()&&(u.search=a.toString()),Yt(u.toString(),{method:"POST",headers:c,body:r?JSON.stringify(r):void 0,signal:s.signal,openWhenHidden:!0,onopen:async f=>{f.ok||(o.error(f),s.abort())},onmessage:f=>{o.next(JSON.parse(f.data))},onclose:()=>{o.complete()},onerror:f=>{throw o.error(f),s.abort(),f}}),()=>{s.abort()}})}class Jt{constructor(){m(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(r=>r!==e)}))}remove(t){delete this.listeners[t]}emit(t,...e){this.listeners[t]&&this.listeners[t].forEach(r=>r(...e))}}class Xt{constructor(t){m(this,"apiKey");m(this,"endpoint");m(this,"debugMode");m(this,"destroy$",new Q);m(this,"sseEmitter",new Jt);m(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,!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 r,i;(r=e==null?void 0:e.onSseStart)==null||r.call(e),Wt({apiKey:this.apiKey,endpoint:this.endpoint,debugMode:this.debugMode,payload:((i=this.transformSsePayload)==null?void 0:i.call(this,t))??t}).pipe(Rt(o=>mt(o).pipe(Ut((e==null?void 0:e.delayTime)??50))),$t(this.destroy$),Nt(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()}}class ee{constructor(t){m(this,"client");m(this,"customChannelId");m(this,"customMessageId");m(this,"isConnecting$");m(this,"conversation$");m(this,"statesObserver");m(this,"statesSubscription");if(!t.client)throw new Error("client must be required");if(!t.customChannelId)throw new Error("customChannelId must be required");this.client=t.client,this.customChannelId=t.customChannelId,this.customMessageId=t.customMessageId,this.isConnecting$=new ie(!1),this.conversation$=new ie(t.conversation),this.statesObserver=t.statesObserver}static async reset(t,e,r){const i=new ee(t);try{return i.subscribe(),await i.resetChannel(e,r),i}catch(o){throw i.close(),o}}subscribe(){this.statesSubscription=Pt([this.isConnecting$,this.conversation$]).pipe(H(([t,e])=>({isConnecting:t,conversation:e}))).subscribe(this.statesObserver)}fetchSse(t,e){return new Promise((r,i)=>{this.isConnecting$.next(!0),this.client.fetchSse(t,{onSseStart:e==null?void 0:e.onSseStart,onSseMessage:o=>{var s;(s=e==null?void 0:e.onSseMessage)==null||s.call(e,o),this.conversation$.next(this.conversation$.value.onMessage(o))},onSseError:o=>{var s;(s=e==null?void 0:e.onSseError)==null||s.call(e,o),this.isConnecting$.next(!1),i(o)},onSseCompleted:()=>{var o;(o=e==null?void 0:e.onSseCompleted)==null||o.call(e),this.isConnecting$.next(!1),r()}})})}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 r=t.text.trim(),i=t.customMessageId??crypto.randomUUID();return this.conversation$.next(this.conversation$.value.pushMessage({type:"user",messageId:i,text:r,time:new Date})),this.fetchSse({action:N.NONE,customChannelId:this.customChannelId,customMessageId:i,payload:t==null?void 0:t.payload,text:r},e)}close(){var t;this.isConnecting$.complete(),this.conversation$.complete(),(t=this.statesSubscription)==null||t.unsubscribe()}}class T{constructor({messages:t}){m(this,"messages",null);this.messages=t}pushMessage(t){const e=new Map(this.messages);return e.set(t.messageId,t),new T({messages:e})}onMessage(t){switch(t.eventType){case h.MESSAGE_START:return this.onMessageStart(t);case h.MESSAGE_DELTA:return this.onMessageDelta(t);case h.MESSAGE_COMPLETE:return this.onMessageComplete(t);case h.ERROR:return this.onMessageError(t);default:return this}}onMessageStart(t){const e=t.fact.messageStart.message,r=new Map(this.messages);return r.set(e.messageId,{type:"bot",eventType:h.MESSAGE_START,isTyping:!0,typingText:"",messageId:e.messageId,message:e,time:new Date}),new T({messages:r})}onMessageDelta(t){const e=t.fact.messageDelta.message,r=new Map(this.messages),i=r.get(e.messageId);if((i==null?void 0:i.type)!=="bot")return this;const o=`${(i==null?void 0:i.typingText)??""}${e.text}`;return r.set(e.messageId,{type:"bot",eventType:h.MESSAGE_DELTA,isTyping:!0,typingText:o,messageId:e.messageId,message:e,time:new Date}),new T({messages:r})}onMessageComplete(t){const e=t.fact.messageComplete.message,r=new Map(this.messages);return r.set(e.messageId,{type:"bot",eventType:h.MESSAGE_COMPLETE,isTyping:!1,typingText:null,messageId:e.messageId,message:e,time:new Date}),new T({messages:r})}onMessageError(t){const e=crypto.randomUUID(),r=t.fact.runError.error,i=new Map(this.messages);return i.set(e,{type:"error",eventType:h.ERROR,messageId:e,error:r,time:new Date}),new T({messages:i})}}exports.AsgardServiceClient=Xt;exports.Channel=ee;exports.Conversation=T;exports.EventType=h;exports.FetchSseAction=N;exports.MessageTemplateType=fe;
5
5
  //# sourceMappingURL=index.cjs.map