@asgard-js/core 0.1.26 → 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/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  var Ne = Object.defineProperty;
2
2
  var Ge = (r, t, e) => t in r ? Ne(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
3
3
  var b = (r, t, e) => Ge(r, typeof t != "symbol" ? t + "" : t, e);
4
- var Y = /* @__PURE__ */ ((r) => (r.RESET_CHANNEL = "RESET_CHANNEL", r.NONE = "NONE", r))(Y || {}), h = /* @__PURE__ */ ((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 || {}), Fe = /* @__PURE__ */ ((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))(Fe || {}), W = function(r, t) {
4
+ var Y = /* @__PURE__ */ ((r) => (r.RESET_CHANNEL = "RESET_CHANNEL", r.NONE = "NONE", r))(Y || {}), d = /* @__PURE__ */ ((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 = /* @__PURE__ */ ((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) {
5
5
  return W = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(e, n) {
6
6
  e.__proto__ = n;
7
7
  } || function(e, n) {
@@ -17,29 +17,29 @@ function A(r, t) {
17
17
  }
18
18
  r.prototype = t === null ? Object.create(t) : (e.prototype = t.prototype, new e());
19
19
  }
20
- function Ve(r, t, e, n) {
20
+ function Fe(r, t, e, n) {
21
21
  function i(o) {
22
22
  return o instanceof e ? o : new e(function(s) {
23
23
  s(o);
24
24
  });
25
25
  }
26
26
  return new (e || (e = Promise))(function(o, s) {
27
- function a(l) {
27
+ function c(f) {
28
28
  try {
29
- u(n.next(l));
30
- } catch (d) {
31
- s(d);
29
+ u(n.next(f));
30
+ } catch (h) {
31
+ s(h);
32
32
  }
33
33
  }
34
- function c(l) {
34
+ function a(f) {
35
35
  try {
36
- u(n.throw(l));
37
- } catch (d) {
38
- s(d);
36
+ u(n.throw(f));
37
+ } catch (h) {
38
+ s(h);
39
39
  }
40
40
  }
41
- function u(l) {
42
- l.done ? o(l.value) : i(l.value).then(a, c);
41
+ function u(f) {
42
+ f.done ? o(f.value) : i(f.value).then(c, a);
43
43
  }
44
44
  u((n = n.apply(r, t || [])).next());
45
45
  });
@@ -49,15 +49,15 @@ function de(r, t) {
49
49
  if (o[0] & 1) throw o[1];
50
50
  return o[1];
51
51
  }, trys: [], ops: [] }, n, i, o, s = Object.create((typeof Iterator == "function" ? Iterator : Object).prototype);
52
- return s.next = a(0), s.throw = a(1), s.return = a(2), typeof Symbol == "function" && (s[Symbol.iterator] = function() {
52
+ return s.next = c(0), s.throw = c(1), s.return = c(2), typeof Symbol == "function" && (s[Symbol.iterator] = function() {
53
53
  return this;
54
54
  }), s;
55
- function a(u) {
56
- return function(l) {
57
- return c([u, l]);
55
+ function c(u) {
56
+ return function(f) {
57
+ return a([u, f]);
58
58
  };
59
59
  }
60
- function c(u) {
60
+ function a(u) {
61
61
  if (n) throw new TypeError("Generator is already executing.");
62
62
  for (; s && (s = 0, u[0] && (e = 0)), e; ) try {
63
63
  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;
@@ -95,8 +95,8 @@ function de(r, t) {
95
95
  continue;
96
96
  }
97
97
  u = t.call(r, e);
98
- } catch (l) {
99
- u = [6, l], i = 0;
98
+ } catch (f) {
99
+ u = [6, f], i = 0;
100
100
  } finally {
101
101
  n = o = 0;
102
102
  }
@@ -120,8 +120,8 @@ function R(r, t) {
120
120
  var n = e.call(r), i, o = [], s;
121
121
  try {
122
122
  for (; (t === void 0 || t-- > 0) && !(i = n.next()).done; ) o.push(i.value);
123
- } catch (a) {
124
- s = { error: a };
123
+ } catch (c) {
124
+ s = { error: c };
125
125
  } finally {
126
126
  try {
127
127
  i && !i.done && (e = n.return) && e.call(n);
@@ -139,45 +139,45 @@ function U(r, t, e) {
139
139
  function L(r) {
140
140
  return this instanceof L ? (this.v = r, this) : new L(r);
141
141
  }
142
- function qe(r, t, e) {
142
+ function Ve(r, t, e) {
143
143
  if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
144
144
  var n = e.apply(r, t || []), i, o = [];
145
- return i = Object.create((typeof AsyncIterator == "function" ? AsyncIterator : Object).prototype), a("next"), a("throw"), a("return", s), i[Symbol.asyncIterator] = function() {
145
+ return i = Object.create((typeof AsyncIterator == "function" ? AsyncIterator : Object).prototype), c("next"), c("throw"), c("return", s), i[Symbol.asyncIterator] = function() {
146
146
  return this;
147
147
  }, i;
148
- function s(f) {
148
+ function s(l) {
149
149
  return function(p) {
150
- return Promise.resolve(p).then(f, d);
150
+ return Promise.resolve(p).then(l, h);
151
151
  };
152
152
  }
153
- function a(f, p) {
154
- n[f] && (i[f] = function(v) {
153
+ function c(l, p) {
154
+ n[l] && (i[l] = function(y) {
155
155
  return new Promise(function(w, E) {
156
- o.push([f, v, w, E]) > 1 || c(f, v);
156
+ o.push([l, y, w, E]) > 1 || a(l, y);
157
157
  });
158
- }, p && (i[f] = p(i[f])));
158
+ }, p && (i[l] = p(i[l])));
159
159
  }
160
- function c(f, p) {
160
+ function a(l, p) {
161
161
  try {
162
- u(n[f](p));
163
- } catch (v) {
164
- y(o[0][3], v);
162
+ u(n[l](p));
163
+ } catch (y) {
164
+ v(o[0][3], y);
165
165
  }
166
166
  }
167
- function u(f) {
168
- f.value instanceof L ? Promise.resolve(f.value.v).then(l, d) : y(o[0][2], f);
167
+ function u(l) {
168
+ l.value instanceof L ? Promise.resolve(l.value.v).then(f, h) : v(o[0][2], l);
169
169
  }
170
- function l(f) {
171
- c("next", f);
170
+ function f(l) {
171
+ a("next", l);
172
172
  }
173
- function d(f) {
174
- c("throw", f);
173
+ function h(l) {
174
+ a("throw", l);
175
175
  }
176
- function y(f, p) {
177
- f(p), o.shift(), o.length && c(o[0][0], o[0][1]);
176
+ function v(l, p) {
177
+ l(p), o.shift(), o.length && a(o[0][0], o[0][1]);
178
178
  }
179
179
  }
180
- function He(r) {
180
+ function qe(r) {
181
181
  if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
182
182
  var t = r[Symbol.asyncIterator], e;
183
183
  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() {
@@ -185,14 +185,14 @@ function He(r) {
185
185
  }, e);
186
186
  function n(o) {
187
187
  e[o] = r[o] && function(s) {
188
- return new Promise(function(a, c) {
189
- s = r[o](s), i(a, c, s.done, s.value);
188
+ return new Promise(function(c, a) {
189
+ s = r[o](s), i(c, a, s.done, s.value);
190
190
  });
191
191
  };
192
192
  }
193
- function i(o, s, a, c) {
194
- Promise.resolve(c).then(function(u) {
195
- o({ value: u, done: a });
193
+ function i(o, s, c, a) {
194
+ Promise.resolve(a).then(function(u) {
195
+ o({ value: u, done: c });
196
196
  }, s);
197
197
  }
198
198
  }
@@ -232,45 +232,45 @@ var k = (function() {
232
232
  if (s)
233
233
  if (this._parentage = null, Array.isArray(s))
234
234
  try {
235
- for (var a = M(s), c = a.next(); !c.done; c = a.next()) {
236
- var u = c.value;
235
+ for (var c = M(s), a = c.next(); !a.done; a = c.next()) {
236
+ var u = a.value;
237
237
  u.remove(this);
238
238
  }
239
- } catch (v) {
240
- t = { error: v };
239
+ } catch (y) {
240
+ t = { error: y };
241
241
  } finally {
242
242
  try {
243
- c && !c.done && (e = a.return) && e.call(a);
243
+ a && !a.done && (e = c.return) && e.call(c);
244
244
  } finally {
245
245
  if (t) throw t.error;
246
246
  }
247
247
  }
248
248
  else
249
249
  s.remove(this);
250
- var l = this.initialTeardown;
251
- if (m(l))
250
+ var f = this.initialTeardown;
251
+ if (m(f))
252
252
  try {
253
- l();
254
- } catch (v) {
255
- o = v instanceof K ? v.errors : [v];
253
+ f();
254
+ } catch (y) {
255
+ o = y instanceof K ? y.errors : [y];
256
256
  }
257
- var d = this._finalizers;
258
- if (d) {
257
+ var h = this._finalizers;
258
+ if (h) {
259
259
  this._finalizers = null;
260
260
  try {
261
- for (var y = M(d), f = y.next(); !f.done; f = y.next()) {
262
- var p = f.value;
261
+ for (var v = M(h), l = v.next(); !l.done; l = v.next()) {
262
+ var p = l.value;
263
263
  try {
264
264
  re(p);
265
- } catch (v) {
266
- o = o ?? [], v instanceof K ? o = U(U([], R(o)), R(v.errors)) : o.push(v);
265
+ } catch (y) {
266
+ o = o ?? [], y instanceof K ? o = U(U([], R(o)), R(y.errors)) : o.push(y);
267
267
  }
268
268
  }
269
- } catch (v) {
270
- n = { error: v };
269
+ } catch (y) {
270
+ n = { error: y };
271
271
  } finally {
272
272
  try {
273
- f && !f.done && (i = y.return) && i.call(y);
273
+ l && !l.done && (i = v.return) && i.call(v);
274
274
  } finally {
275
275
  if (n) throw n.error;
276
276
  }
@@ -426,11 +426,11 @@ var Xe = {
426
426
  }, Z = (function() {
427
427
  return typeof Symbol == "function" && Symbol.observable || "@@observable";
428
428
  })();
429
- function F(r) {
429
+ function H(r) {
430
430
  return r;
431
431
  }
432
432
  function Je(r) {
433
- return r.length === 0 ? F : r.length === 1 ? r[0] : function(e) {
433
+ return r.length === 0 ? H : r.length === 1 ? r[0] : function(e) {
434
434
  return r.reduce(function(n, i) {
435
435
  return i(n);
436
436
  }, e);
@@ -446,8 +446,8 @@ var S = (function() {
446
446
  }, r.prototype.subscribe = function(t, e, n) {
447
447
  var i = this, o = Qe(t) ? t : new J(t, e, n);
448
448
  return D(function() {
449
- var s = i, a = s.operator, c = s.source;
450
- o.add(a ? a.call(o, c) : c ? i._subscribe(o) : i._trySubscribe(o));
449
+ var s = i, c = s.operator, a = s.source;
450
+ o.add(c ? c.call(o, a) : a ? i._subscribe(o) : i._trySubscribe(o));
451
451
  }), o;
452
452
  }, r.prototype._trySubscribe = function(t) {
453
453
  try {
@@ -459,11 +459,11 @@ var S = (function() {
459
459
  var n = this;
460
460
  return e = ne(e), new e(function(i, o) {
461
461
  var s = new J({
462
- next: function(a) {
462
+ next: function(c) {
463
463
  try {
464
- t(a);
465
- } catch (c) {
466
- o(c), s.unsubscribe();
464
+ t(c);
465
+ } catch (a) {
466
+ o(a), s.unsubscribe();
467
467
  }
468
468
  },
469
469
  error: o,
@@ -527,23 +527,23 @@ function O(r, t, e, n, i) {
527
527
  }
528
528
  var et = (function(r) {
529
529
  A(t, r);
530
- function t(e, n, i, o, s, a) {
531
- var c = r.call(this, e) || this;
532
- return c.onFinalize = s, c.shouldUnsubscribe = a, c._next = n ? function(u) {
530
+ function t(e, n, i, o, s, c) {
531
+ var a = r.call(this, e) || this;
532
+ return a.onFinalize = s, a.shouldUnsubscribe = c, a._next = n ? function(u) {
533
533
  try {
534
534
  n(u);
535
- } catch (l) {
536
- e.error(l);
535
+ } catch (f) {
536
+ e.error(f);
537
537
  }
538
- } : r.prototype._next, c._error = o ? function(u) {
538
+ } : r.prototype._next, a._error = o ? function(u) {
539
539
  try {
540
540
  o(u);
541
- } catch (l) {
542
- e.error(l);
541
+ } catch (f) {
542
+ e.error(f);
543
543
  } finally {
544
544
  this.unsubscribe();
545
545
  }
546
- } : r.prototype._error, c._complete = i ? function() {
546
+ } : r.prototype._error, a._complete = i ? function() {
547
547
  try {
548
548
  i();
549
549
  } catch (u) {
@@ -551,7 +551,7 @@ var et = (function(r) {
551
551
  } finally {
552
552
  this.unsubscribe();
553
553
  }
554
- } : r.prototype._complete, c;
554
+ } : r.prototype._complete, a;
555
555
  }
556
556
  return t.prototype.unsubscribe = function() {
557
557
  var e;
@@ -583,15 +583,15 @@ var et = (function(r) {
583
583
  if (n._throwIfClosed(), !n.isStopped) {
584
584
  n.currentObservers || (n.currentObservers = Array.from(n.observers));
585
585
  try {
586
- for (var s = M(n.currentObservers), a = s.next(); !a.done; a = s.next()) {
587
- var c = a.value;
588
- c.next(e);
586
+ for (var s = M(n.currentObservers), c = s.next(); !c.done; c = s.next()) {
587
+ var a = c.value;
588
+ a.next(e);
589
589
  }
590
590
  } catch (u) {
591
591
  i = { error: u };
592
592
  } finally {
593
593
  try {
594
- a && !a.done && (o = s.return) && o.call(s);
594
+ c && !c.done && (o = s.return) && o.call(s);
595
595
  } finally {
596
596
  if (i) throw i.error;
597
597
  }
@@ -630,9 +630,9 @@ var et = (function(r) {
630
630
  }, t.prototype._subscribe = function(e) {
631
631
  return this._throwIfClosed(), this._checkFinalizedStatuses(e), this._innerSubscribe(e);
632
632
  }, t.prototype._innerSubscribe = function(e) {
633
- var n = this, i = this, o = i.hasError, s = i.isStopped, a = i.observers;
634
- return o || s ? ve : (this.currentObservers = null, a.push(e), new k(function() {
635
- n.currentObservers = null, N(a, e);
633
+ var n = this, i = this, o = i.hasError, s = i.isStopped, c = i.observers;
634
+ return o || s ? ve : (this.currentObservers = null, c.push(e), new k(function() {
635
+ n.currentObservers = null, N(c, e);
636
636
  }));
637
637
  }, t.prototype._checkFinalizedStatuses = function(e) {
638
638
  var n = this, i = n.hasError, o = n.thrownError, s = n.isStopped;
@@ -819,7 +819,7 @@ function _e(r) {
819
819
  return m(r == null ? void 0 : r[Ce]);
820
820
  }
821
821
  function Te(r) {
822
- return qe(this, arguments, function() {
822
+ return Ve(this, arguments, function() {
823
823
  var e, n, i, o;
824
824
  return de(this, function(s) {
825
825
  switch (s.label) {
@@ -904,8 +904,8 @@ function ht(r) {
904
904
  if (t.next(s), t.closed)
905
905
  return;
906
906
  }
907
- } catch (a) {
908
- e = { error: a };
907
+ } catch (c) {
908
+ e = { error: c };
909
909
  } finally {
910
910
  try {
911
911
  o && !o.done && (n = i.return) && n.call(i);
@@ -928,29 +928,29 @@ function vt(r) {
928
928
  }
929
929
  function yt(r, t) {
930
930
  var e, n, i, o;
931
- return Ve(this, void 0, void 0, function() {
932
- var s, a;
933
- return de(this, function(c) {
934
- switch (c.label) {
931
+ return Fe(this, void 0, void 0, function() {
932
+ var s, c;
933
+ return de(this, function(a) {
934
+ switch (a.label) {
935
935
  case 0:
936
- c.trys.push([0, 5, 6, 11]), e = He(r), c.label = 1;
936
+ a.trys.push([0, 5, 6, 11]), e = qe(r), a.label = 1;
937
937
  case 1:
938
938
  return [4, e.next()];
939
939
  case 2:
940
- if (n = c.sent(), !!n.done) return [3, 4];
940
+ if (n = a.sent(), !!n.done) return [3, 4];
941
941
  if (s = n.value, t.next(s), t.closed)
942
942
  return [2];
943
- c.label = 3;
943
+ a.label = 3;
944
944
  case 3:
945
945
  return [3, 1];
946
946
  case 4:
947
947
  return [3, 11];
948
948
  case 5:
949
- return a = c.sent(), i = { error: a }, [3, 11];
949
+ return c = a.sent(), i = { error: c }, [3, 11];
950
950
  case 6:
951
- return c.trys.push([6, , 9, 10]), n && !n.done && (o = e.return) ? [4, o.call(e)] : [3, 8];
951
+ return a.trys.push([6, , 9, 10]), n && !n.done && (o = e.return) ? [4, o.call(e)] : [3, 8];
952
952
  case 7:
953
- c.sent(), c.label = 8;
953
+ a.sent(), a.label = 8;
954
954
  case 8:
955
955
  return [3, 10];
956
956
  case 9:
@@ -1018,8 +1018,8 @@ function gt(r, t) {
1018
1018
  var i, o, s;
1019
1019
  try {
1020
1020
  i = n.next(), o = i.value, s = i.done;
1021
- } catch (a) {
1022
- e.error(a);
1021
+ } catch (c) {
1022
+ e.error(c);
1023
1023
  return;
1024
1024
  }
1025
1025
  s ? e.complete() : e.next(o);
@@ -1075,7 +1075,7 @@ function Et() {
1075
1075
  function It(r) {
1076
1076
  return r instanceof Date && !isNaN(r);
1077
1077
  }
1078
- function V(r, t) {
1078
+ function F(r, t) {
1079
1079
  return P(function(e, n) {
1080
1080
  var i = 0;
1081
1081
  e.subscribe(O(n, function(o) {
@@ -1088,7 +1088,7 @@ function At(r, t) {
1088
1088
  return Ot(t) ? r.apply(void 0, U([], R(t))) : r(t);
1089
1089
  }
1090
1090
  function Ct(r) {
1091
- return V(function(t) {
1091
+ return F(function(t) {
1092
1092
  return At(r, t);
1093
1093
  });
1094
1094
  }
@@ -1124,40 +1124,40 @@ function Ut() {
1124
1124
  var e = Se(r), n = ct(r), i = Lt(r), o = i.args, s = i.keys;
1125
1125
  if (o.length === 0)
1126
1126
  return te([], e);
1127
- var a = new S(kt(o, e, s ? function(c) {
1128
- return Rt(s, c);
1129
- } : F));
1130
- return n ? a.pipe(Ct(n)) : a;
1127
+ var c = new S(kt(o, e, s ? function(a) {
1128
+ return Rt(s, a);
1129
+ } : H));
1130
+ return n ? c.pipe(Ct(n)) : c;
1131
1131
  }
1132
1132
  function kt(r, t, e) {
1133
- return e === void 0 && (e = F), function(n) {
1133
+ return e === void 0 && (e = H), function(n) {
1134
1134
  ce(t, function() {
1135
- for (var i = r.length, o = new Array(i), s = i, a = i, c = function(l) {
1135
+ for (var i = r.length, o = new Array(i), s = i, c = i, a = function(f) {
1136
1136
  ce(t, function() {
1137
- var d = te(r[l], t), y = !1;
1138
- d.subscribe(O(n, function(f) {
1139
- o[l] = f, y || (y = !0, a--), a || n.next(e(o.slice()));
1137
+ var h = te(r[f], t), v = !1;
1138
+ h.subscribe(O(n, function(l) {
1139
+ o[f] = l, v || (v = !0, c--), c || n.next(e(o.slice()));
1140
1140
  }, function() {
1141
1141
  --s || n.complete();
1142
1142
  }));
1143
1143
  }, n);
1144
1144
  }, u = 0; u < i; u++)
1145
- c(u);
1145
+ a(u);
1146
1146
  }, n);
1147
1147
  };
1148
1148
  }
1149
1149
  function ce(r, t, e) {
1150
1150
  r ? _(e, r, t) : t();
1151
1151
  }
1152
- function $t(r, t, e, n, i, o, s, a) {
1153
- var c = [], u = 0, l = 0, d = !1, y = function() {
1154
- d && !c.length && !u && t.complete();
1155
- }, f = function(v) {
1156
- return u < n ? p(v) : c.push(v);
1157
- }, p = function(v) {
1152
+ function $t(r, t, e, n, i, o, s, c) {
1153
+ var a = [], u = 0, f = 0, h = !1, v = function() {
1154
+ h && !a.length && !u && t.complete();
1155
+ }, l = function(y) {
1156
+ return u < n ? p(y) : a.push(y);
1157
+ }, p = function(y) {
1158
1158
  u++;
1159
1159
  var w = !1;
1160
- T(e(v, l++)).subscribe(O(t, function(E) {
1160
+ T(e(y, f++)).subscribe(O(t, function(E) {
1161
1161
  t.next(E);
1162
1162
  }, function() {
1163
1163
  w = !0;
@@ -1166,24 +1166,24 @@ function $t(r, t, e, n, i, o, s, a) {
1166
1166
  try {
1167
1167
  u--;
1168
1168
  for (var E = function() {
1169
- var x = c.shift();
1169
+ var x = a.shift();
1170
1170
  s || p(x);
1171
- }; c.length && u < n; )
1171
+ }; a.length && u < n; )
1172
1172
  E();
1173
- y();
1173
+ v();
1174
1174
  } catch (x) {
1175
1175
  t.error(x);
1176
1176
  }
1177
1177
  }));
1178
1178
  };
1179
- return r.subscribe(O(t, f, function() {
1180
- d = !0, y();
1179
+ return r.subscribe(O(t, l, function() {
1180
+ h = !0, v();
1181
1181
  })), function() {
1182
1182
  };
1183
1183
  }
1184
1184
  function G(r, t, e) {
1185
1185
  return e === void 0 && (e = 1 / 0), m(t) ? G(function(n, i) {
1186
- return V(function(o, s) {
1186
+ return F(function(o, s) {
1187
1187
  return t(n, o, i, s);
1188
1188
  })(T(r(n, i)));
1189
1189
  }, e) : (typeof t == "number" && (e = t), P(function(n, i) {
@@ -1216,7 +1216,7 @@ function Dt(r) {
1216
1216
  });
1217
1217
  }
1218
1218
  function Nt(r) {
1219
- return V(function() {
1219
+ return F(function() {
1220
1220
  return r;
1221
1221
  });
1222
1222
  }
@@ -1225,53 +1225,53 @@ function Gt(r, t) {
1225
1225
  return T(r(e, n)).pipe(Dt(1), Nt(e));
1226
1226
  });
1227
1227
  }
1228
- function Ft(r, t) {
1228
+ function Ht(r, t) {
1229
1229
  t === void 0 && (t = me);
1230
1230
  var e = Ue(r, t);
1231
1231
  return Gt(function() {
1232
1232
  return e;
1233
1233
  });
1234
1234
  }
1235
- function Vt(r) {
1235
+ function Ft(r) {
1236
1236
  var t;
1237
1237
  t = {
1238
1238
  count: r
1239
1239
  };
1240
1240
  var e = t.count, n = e === void 0 ? 1 / 0 : e, i = t.delay, o = t.resetOnSuccess, s = o === void 0 ? !1 : o;
1241
- return n <= 0 ? F : P(function(a, c) {
1242
- var u = 0, l, d = function() {
1243
- var y = !1;
1244
- l = a.subscribe(O(c, function(f) {
1245
- s && (u = 0), c.next(f);
1246
- }, void 0, function(f) {
1241
+ return n <= 0 ? H : P(function(c, a) {
1242
+ var u = 0, f, h = function() {
1243
+ var v = !1;
1244
+ f = c.subscribe(O(a, function(l) {
1245
+ s && (u = 0), a.next(l);
1246
+ }, void 0, function(l) {
1247
1247
  if (u++ < n) {
1248
1248
  var p = function() {
1249
- l ? (l.unsubscribe(), l = null, d()) : y = !0;
1249
+ f ? (f.unsubscribe(), f = null, h()) : v = !0;
1250
1250
  };
1251
1251
  if (i != null) {
1252
- var v = typeof i == "number" ? Ue(i) : T(i(f, u)), w = O(c, function() {
1252
+ var y = typeof i == "number" ? Ue(i) : T(i(l, u)), w = O(a, function() {
1253
1253
  w.unsubscribe(), p();
1254
1254
  }, function() {
1255
- c.complete();
1255
+ a.complete();
1256
1256
  });
1257
- v.subscribe(w);
1257
+ y.subscribe(w);
1258
1258
  } else
1259
1259
  p();
1260
1260
  } else
1261
- c.error(f);
1262
- })), y && (l.unsubscribe(), l = null, d());
1261
+ a.error(l);
1262
+ })), v && (f.unsubscribe(), f = null, h());
1263
1263
  };
1264
- d();
1264
+ h();
1265
1265
  });
1266
1266
  }
1267
- function qt(r) {
1267
+ function Vt(r) {
1268
1268
  return P(function(t, e) {
1269
1269
  T(r).subscribe(O(e, function() {
1270
1270
  return e.complete();
1271
1271
  }, X)), !e.closed && t.subscribe(e);
1272
1272
  });
1273
1273
  }
1274
- async function Ht(r, t) {
1274
+ async function qt(r, t) {
1275
1275
  const e = r.getReader();
1276
1276
  let n;
1277
1277
  for (; !(n = await e.read()).done; )
@@ -1281,15 +1281,15 @@ function Kt(r) {
1281
1281
  let t, e, n, i = !1;
1282
1282
  return function(s) {
1283
1283
  t === void 0 ? (t = s, e = 0, n = -1) : t = Yt(t, s);
1284
- const a = t.length;
1285
- let c = 0;
1286
- for (; e < a; ) {
1287
- i && (t[e] === 10 && (c = ++e), i = !1);
1284
+ const c = t.length;
1285
+ let a = 0;
1286
+ for (; e < c; ) {
1287
+ i && (t[e] === 10 && (a = ++e), i = !1);
1288
1288
  let u = -1;
1289
- for (; e < a && u === -1; ++e)
1289
+ for (; e < c && u === -1; ++e)
1290
1290
  switch (t[e]) {
1291
1291
  case 58:
1292
- n === -1 && (n = e - c);
1292
+ n === -1 && (n = e - a);
1293
1293
  break;
1294
1294
  case 13:
1295
1295
  i = !0;
@@ -1299,33 +1299,33 @@ function Kt(r) {
1299
1299
  }
1300
1300
  if (u === -1)
1301
1301
  break;
1302
- r(t.subarray(c, u), n), c = e, n = -1;
1302
+ r(t.subarray(a, u), n), a = e, n = -1;
1303
1303
  }
1304
- c === a ? t = void 0 : c !== 0 && (t = t.subarray(c), e -= c);
1304
+ a === c ? t = void 0 : a !== 0 && (t = t.subarray(a), e -= a);
1305
1305
  };
1306
1306
  }
1307
1307
  function Bt(r, t, e) {
1308
1308
  let n = ue();
1309
1309
  const i = new TextDecoder();
1310
- return function(s, a) {
1310
+ return function(s, c) {
1311
1311
  if (s.length === 0)
1312
1312
  e == null || e(n), n = ue();
1313
- else if (a > 0) {
1314
- const c = i.decode(s.subarray(0, a)), u = a + (s[a + 1] === 32 ? 2 : 1), l = i.decode(s.subarray(u));
1315
- switch (c) {
1313
+ else if (c > 0) {
1314
+ const a = i.decode(s.subarray(0, c)), u = c + (s[c + 1] === 32 ? 2 : 1), f = i.decode(s.subarray(u));
1315
+ switch (a) {
1316
1316
  case "data":
1317
1317
  n.data = n.data ? n.data + `
1318
- ` + l : l;
1318
+ ` + f : f;
1319
1319
  break;
1320
1320
  case "event":
1321
- n.event = l;
1321
+ n.event = f;
1322
1322
  break;
1323
1323
  case "id":
1324
- r(n.id = l);
1324
+ r(n.id = f);
1325
1325
  break;
1326
1326
  case "retry":
1327
- const d = parseInt(l, 10);
1328
- isNaN(d) || t(n.retry = d);
1327
+ const h = parseInt(f, 10);
1328
+ isNaN(h) || t(n.retry = h);
1329
1329
  break;
1330
1330
  }
1331
1331
  }
@@ -1353,44 +1353,44 @@ var Wt = function(r, t) {
1353
1353
  };
1354
1354
  const z = "text/event-stream", Xt = 1e3, le = "last-event-id";
1355
1355
  function Jt(r, t) {
1356
- 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"]);
1357
- return new Promise((d, y) => {
1358
- const f = Object.assign({}, n);
1359
- f.accept || (f.accept = z);
1356
+ 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"]);
1357
+ return new Promise((h, v) => {
1358
+ const l = Object.assign({}, n);
1359
+ l.accept || (l.accept = z);
1360
1360
  let p;
1361
- function v() {
1362
- p.abort(), document.hidden || q();
1361
+ function y() {
1362
+ p.abort(), document.hidden || V();
1363
1363
  }
1364
- c || document.addEventListener("visibilitychange", v);
1364
+ a || document.addEventListener("visibilitychange", y);
1365
1365
  let w = Xt, E = 0;
1366
1366
  function x() {
1367
- document.removeEventListener("visibilitychange", v), window.clearTimeout(E), p.abort();
1367
+ document.removeEventListener("visibilitychange", y), window.clearTimeout(E), p.abort();
1368
1368
  }
1369
1369
  e == null || e.addEventListener("abort", () => {
1370
- x(), d();
1370
+ x(), h();
1371
1371
  });
1372
1372
  const je = u ?? window.fetch, De = i ?? zt;
1373
- async function q() {
1374
- var H;
1373
+ async function V() {
1374
+ var q;
1375
1375
  p = new AbortController();
1376
1376
  try {
1377
- const $ = await je(r, Object.assign(Object.assign({}, l), { headers: f, signal: p.signal }));
1378
- await De($), await Ht($.body, Kt(Bt((C) => {
1379
- C ? f[le] = C : delete f[le];
1377
+ const $ = await je(r, Object.assign(Object.assign({}, f), { headers: l, signal: p.signal }));
1378
+ await De($), await qt($.body, Kt(Bt((C) => {
1379
+ C ? l[le] = C : delete l[le];
1380
1380
  }, (C) => {
1381
1381
  w = C;
1382
- }, o))), s == null || s(), x(), d();
1382
+ }, o))), s == null || s(), x(), h();
1383
1383
  } catch ($) {
1384
1384
  if (!p.signal.aborted)
1385
1385
  try {
1386
- const C = (H = a == null ? void 0 : a($)) !== null && H !== void 0 ? H : w;
1387
- window.clearTimeout(E), E = window.setTimeout(q, C);
1386
+ const C = (q = c == null ? void 0 : c($)) !== null && q !== void 0 ? q : w;
1387
+ window.clearTimeout(E), E = window.setTimeout(V, C);
1388
1388
  } catch (C) {
1389
- x(), y(C);
1389
+ x(), v(C);
1390
1390
  }
1391
1391
  }
1392
1392
  }
1393
- q();
1393
+ V();
1394
1394
  });
1395
1395
  }
1396
1396
  function zt(r) {
@@ -1399,42 +1399,43 @@ function zt(r) {
1399
1399
  throw new Error(`Expected content-type to be ${z}, Actual: ${t}`);
1400
1400
  }
1401
1401
  function Qt(r) {
1402
- const { endpoint: t, apiKey: e, payload: n, debugMode: i } = r;
1403
- return new S((o) => {
1404
- const s = new AbortController();
1402
+ const { endpoint: t, apiKey: e, payload: n, debugMode: i, customHeaders: o } = r;
1403
+ return new S((s) => {
1404
+ const c = new AbortController();
1405
1405
  let a;
1406
- const c = {
1407
- "Content-Type": "application/json"
1406
+ const u = {
1407
+ "Content-Type": "application/json",
1408
+ ...o
1408
1409
  };
1409
- e && (c["X-API-KEY"] = e);
1410
- const u = new URLSearchParams();
1411
- i && u.set("is_debug", "true");
1412
- const l = new URL(t);
1413
- return u.toString() && (l.search = u.toString()), Jt(l.toString(), {
1410
+ e && (u["X-API-KEY"] = e);
1411
+ const f = new URLSearchParams();
1412
+ i && f.set("is_debug", "true");
1413
+ const h = new URL(t);
1414
+ return f.toString() && (h.search = f.toString()), Jt(h.toString(), {
1414
1415
  method: "POST",
1415
- headers: c,
1416
+ headers: u,
1416
1417
  body: n ? JSON.stringify(n) : void 0,
1417
- signal: s.signal,
1418
+ signal: c.signal,
1418
1419
  /**
1419
1420
  * Allow SSE to work when the page is hidden.
1420
1421
  * https://github.com/Azure/fetch-event-source/issues/17#issuecomment-1525904929
1421
1422
  */
1422
1423
  openWhenHidden: !0,
1423
- onopen: async (d) => {
1424
- d.ok ? a = d.headers.get("X-Trace-Id") ?? void 0 : (o.error(d), s.abort());
1424
+ onopen: async (v) => {
1425
+ v.ok ? a = v.headers.get("X-Trace-Id") ?? void 0 : (s.error(v), c.abort());
1425
1426
  },
1426
- onmessage: (d) => {
1427
- const y = JSON.parse(d.data);
1428
- a ? y.traceId = a : y.requestId && (y.traceId = y.requestId, a || (a = y.requestId)), o.next(y);
1427
+ onmessage: (v) => {
1428
+ const l = JSON.parse(v.data);
1429
+ a ? l.traceId = a : l.requestId && (l.traceId = l.requestId, a || (a = l.requestId)), s.next(l);
1429
1430
  },
1430
1431
  onclose: () => {
1431
- o.complete();
1432
+ s.complete();
1432
1433
  },
1433
- onerror: (d) => {
1434
- throw o.error(d), s.abort(), d;
1434
+ onerror: (v) => {
1435
+ throw s.error(v), c.abort(), v;
1435
1436
  }
1436
1437
  }), () => {
1437
- s.abort();
1438
+ c.abort();
1438
1439
  };
1439
1440
  });
1440
1441
  }
@@ -1468,9 +1469,10 @@ class sr {
1468
1469
  b(this, "destroy$", new ee());
1469
1470
  b(this, "sseEmitter", new Zt());
1470
1471
  b(this, "transformSsePayload");
1472
+ b(this, "customHeaders");
1471
1473
  if (!t.endpoint && !t.botProviderEndpoint)
1472
1474
  throw new Error("Either endpoint or botProviderEndpoint must be provided");
1473
- if (this.apiKey = t.apiKey, this.debugMode = t.debugMode, this.transformSsePayload = t.transformSsePayload, this.botProviderEndpoint = t.botProviderEndpoint, !t.endpoint && t.botProviderEndpoint) {
1475
+ 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) {
1474
1476
  const e = t.botProviderEndpoint.replace(/\/+$/, "");
1475
1477
  this.endpoint = `${e}/message/sse`;
1476
1478
  } else t.endpoint && (this.endpoint = t.endpoint, this.debugMode && console.warn(
@@ -1482,27 +1484,27 @@ class sr {
1482
1484
  }
1483
1485
  handleEvent(t) {
1484
1486
  switch (t.eventType) {
1485
- case h.INIT:
1486
- this.sseEmitter.emit(h.INIT, t);
1487
+ case d.INIT:
1488
+ this.sseEmitter.emit(d.INIT, t);
1487
1489
  break;
1488
- case h.PROCESS_START:
1489
- case h.PROCESS_COMPLETE:
1490
- this.sseEmitter.emit(h.PROCESS, t);
1490
+ case d.PROCESS_START:
1491
+ case d.PROCESS_COMPLETE:
1492
+ this.sseEmitter.emit(d.PROCESS, t);
1491
1493
  break;
1492
- case h.MESSAGE_START:
1493
- case h.MESSAGE_DELTA:
1494
- case h.MESSAGE_COMPLETE:
1495
- this.sseEmitter.emit(h.MESSAGE, t);
1494
+ case d.MESSAGE_START:
1495
+ case d.MESSAGE_DELTA:
1496
+ case d.MESSAGE_COMPLETE:
1497
+ this.sseEmitter.emit(d.MESSAGE, t);
1496
1498
  break;
1497
- case h.TOOL_CALL_START:
1498
- case h.TOOL_CALL_COMPLETE:
1499
- this.sseEmitter.emit(h.TOOL_CALL, t);
1499
+ case d.TOOL_CALL_START:
1500
+ case d.TOOL_CALL_COMPLETE:
1501
+ this.sseEmitter.emit(d.TOOL_CALL, t);
1500
1502
  break;
1501
- case h.DONE:
1502
- this.sseEmitter.emit(h.DONE, t);
1503
+ case d.DONE:
1504
+ this.sseEmitter.emit(d.DONE, t);
1503
1505
  break;
1504
- case h.ERROR:
1505
- this.sseEmitter.emit(h.ERROR, t);
1506
+ case d.ERROR:
1507
+ this.sseEmitter.emit(d.ERROR, t);
1506
1508
  break;
1507
1509
  }
1508
1510
  }
@@ -1512,11 +1514,12 @@ class sr {
1512
1514
  apiKey: this.apiKey,
1513
1515
  endpoint: this.endpoint,
1514
1516
  debugMode: this.debugMode,
1515
- payload: ((i = this.transformSsePayload) == null ? void 0 : i.call(this, t)) ?? t
1517
+ payload: ((i = this.transformSsePayload) == null ? void 0 : i.call(this, t)) ?? t,
1518
+ customHeaders: this.customHeaders
1516
1519
  }).pipe(
1517
- jt((o) => Et(o).pipe(Ft((e == null ? void 0 : e.delayTime) ?? 50))),
1518
- qt(this.destroy$),
1519
- Vt(3)
1520
+ jt((o) => Et(o).pipe(Ht((e == null ? void 0 : e.delayTime) ?? 50))),
1521
+ Vt(this.destroy$),
1522
+ Ft(3)
1520
1523
  ).subscribe({
1521
1524
  next: (o) => {
1522
1525
  var s;
@@ -1545,7 +1548,9 @@ class sr {
1545
1548
  throw new Error("Unable to derive blob endpoint. Please provide botProviderEndpoint in config.");
1546
1549
  const i = new FormData();
1547
1550
  i.append("file", t), i.append("customChannelId", e);
1548
- const o = {};
1551
+ const o = {
1552
+ ...this.customHeaders
1553
+ };
1549
1554
  this.apiKey && (o["X-API-KEY"] = this.apiKey);
1550
1555
  try {
1551
1556
  const s = await fetch(n, {
@@ -1555,8 +1560,8 @@ class sr {
1555
1560
  });
1556
1561
  if (!s.ok)
1557
1562
  throw new Error(`Upload failed: ${s.status} ${s.statusText}`);
1558
- const a = await s.json();
1559
- return this.debugMode && console.log("[AsgardServiceClient] File upload response:", a), a;
1563
+ const c = await s.json();
1564
+ return this.debugMode && console.log("[AsgardServiceClient] File upload response:", c), c;
1560
1565
  } catch (s) {
1561
1566
  throw console.error("[AsgardServiceClient] File upload error:", s), s;
1562
1567
  }
@@ -1619,17 +1624,17 @@ class I {
1619
1624
  }
1620
1625
  onMessage(t) {
1621
1626
  switch (t.eventType) {
1622
- case h.MESSAGE_START:
1627
+ case d.MESSAGE_START:
1623
1628
  return this.onMessageStart(t);
1624
- case h.MESSAGE_DELTA:
1629
+ case d.MESSAGE_DELTA:
1625
1630
  return this.onMessageDelta(t);
1626
- case h.MESSAGE_COMPLETE:
1631
+ case d.MESSAGE_COMPLETE:
1627
1632
  return this.onMessageComplete(t);
1628
- case h.TOOL_CALL_START:
1633
+ case d.TOOL_CALL_START:
1629
1634
  return this.onToolCallStart(t);
1630
- case h.TOOL_CALL_COMPLETE:
1635
+ case d.TOOL_CALL_COMPLETE:
1631
1636
  return this.onToolCallComplete(t);
1632
- case h.ERROR:
1637
+ case d.ERROR:
1633
1638
  return this.onMessageError(t);
1634
1639
  default:
1635
1640
  return this;
@@ -1639,7 +1644,7 @@ class I {
1639
1644
  const e = t.fact.messageStart.message, n = new Map(this.messages);
1640
1645
  return n.set(e.messageId, {
1641
1646
  type: "bot",
1642
- eventType: h.MESSAGE_START,
1647
+ eventType: d.MESSAGE_START,
1643
1648
  isTyping: !0,
1644
1649
  typingText: "",
1645
1650
  messageId: e.messageId,
@@ -1655,7 +1660,7 @@ class I {
1655
1660
  const o = `${(i == null ? void 0 : i.typingText) ?? ""}${e.text}`;
1656
1661
  return n.set(e.messageId, {
1657
1662
  type: "bot",
1658
- eventType: h.MESSAGE_DELTA,
1663
+ eventType: d.MESSAGE_DELTA,
1659
1664
  isTyping: !0,
1660
1665
  typingText: o,
1661
1666
  messageId: e.messageId,
@@ -1669,7 +1674,7 @@ class I {
1669
1674
  const e = t.fact.messageComplete.message, n = new Map(this.messages), i = n.get(e.messageId);
1670
1675
  return n.set(e.messageId, {
1671
1676
  type: "bot",
1672
- eventType: h.MESSAGE_COMPLETE,
1677
+ eventType: d.MESSAGE_COMPLETE,
1673
1678
  isTyping: !1,
1674
1679
  typingText: null,
1675
1680
  messageId: e.messageId,
@@ -1683,7 +1688,7 @@ class I {
1683
1688
  const e = ke(), n = t.fact.runError.error, i = new Map(this.messages);
1684
1689
  return i.set(e, {
1685
1690
  type: "error",
1686
- eventType: h.ERROR,
1691
+ eventType: d.ERROR,
1687
1692
  messageId: e,
1688
1693
  error: n,
1689
1694
  time: /* @__PURE__ */ new Date(),
@@ -1693,7 +1698,7 @@ class I {
1693
1698
  onToolCallStart(t) {
1694
1699
  const e = t.fact.toolCallStart, n = new Map(this.messages), i = `${e.processId}-${e.callSeq}`, o = {
1695
1700
  type: "tool-call",
1696
- eventType: h.TOOL_CALL_START,
1701
+ eventType: d.TOOL_CALL_START,
1697
1702
  messageId: i,
1698
1703
  processId: e.processId,
1699
1704
  callSeq: e.callSeq,
@@ -1711,7 +1716,7 @@ class I {
1711
1716
  if ((o == null ? void 0 : o.type) === "tool-call") {
1712
1717
  const s = {
1713
1718
  ...o,
1714
- eventType: h.TOOL_CALL_COMPLETE,
1719
+ eventType: d.TOOL_CALL_COMPLETE,
1715
1720
  result: e.toolCallResult,
1716
1721
  isComplete: !0,
1717
1722
  traceId: t.traceId ?? o.traceId
@@ -1747,7 +1752,7 @@ class $e {
1747
1752
  }
1748
1753
  subscribe() {
1749
1754
  this.statesSubscription = Ut([this.isConnecting$, this.conversation$]).pipe(
1750
- V(([t, e]) => ({
1755
+ F(([t, e]) => ({
1751
1756
  isConnecting: t,
1752
1757
  conversation: e
1753
1758
  }))
@@ -1760,11 +1765,11 @@ class $e {
1760
1765
  onSseMessage: (o) => {
1761
1766
  var s;
1762
1767
  if ((s = e == null ? void 0 : e.onSseMessage) == null || s.call(e, o), this.currentUserMessageId && o.traceId) {
1763
- const a = new Map(this.conversation$.value.messages), c = a.get(this.currentUserMessageId);
1764
- c && c.type === "user" && (a.set(this.currentUserMessageId, {
1765
- ...c,
1768
+ const c = new Map(this.conversation$.value.messages), a = c.get(this.currentUserMessageId);
1769
+ a && a.type === "user" && (c.set(this.currentUserMessageId, {
1770
+ ...a,
1766
1771
  traceId: o.traceId
1767
- }), this.conversation$.next(new I({ messages: a }))), this.currentUserMessageId = void 0;
1772
+ }), this.conversation$.next(new I({ messages: c }))), this.currentUserMessageId = void 0;
1768
1773
  }
1769
1774
  this.conversation$.next(this.conversation$.value.onMessage(o));
1770
1775
  },
@@ -1824,8 +1829,8 @@ export {
1824
1829
  sr as AsgardServiceClient,
1825
1830
  $e as Channel,
1826
1831
  I as Conversation,
1827
- h as EventType,
1832
+ d as EventType,
1828
1833
  Y as FetchSseAction,
1829
- Fe as MessageTemplateType
1834
+ He as MessageTemplateType
1830
1835
  };
1831
1836
  //# sourceMappingURL=index.mjs.map