@asgard-js/core 0.3.74 → 0.3.75

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,4 +1,4 @@
1
- class I extends Error {
1
+ class E extends Error {
2
2
  status;
3
3
  statusText;
4
4
  /**
@@ -17,7 +17,7 @@ class I extends Error {
17
17
  }
18
18
  }
19
19
  function An(n) {
20
- return n instanceof I;
20
+ return n instanceof E;
21
21
  }
22
22
  class te extends Error {
23
23
  /** Which run is holding the channel. */
@@ -46,7 +46,7 @@ class ne extends Error {
46
46
  function Pn(n) {
47
47
  return n instanceof ne;
48
48
  }
49
- var G = /* @__PURE__ */ ((n) => (n.RESET_CHANNEL = "RESET_CHANNEL", n.NONE = "NONE", n.RESPONSE_TOOL_CALL_CONSENT = "RESPONSE_TOOL_CALL_CONSENT", n.NUDGE = "NUDGE", n))(G || {}), d = /* @__PURE__ */ ((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.MESSAGE_USER = "asgard.message.user", n.MESSAGE_THINKING_START = "asgard.message.thinking.start", n.MESSAGE_THINKING_DELTA = "asgard.message.thinking.delta", n.MESSAGE_THINKING_COMPLETE = "asgard.message.thinking.complete", n.MESSAGE_CANVAS_START = "asgard.message.canvas.start", n.MESSAGE_CANVAS_DELTA = "asgard.message.canvas.delta", n.MESSAGE_CANVAS_COMPLETE = "asgard.message.canvas.complete", n.TOOL_CALL = "asgard.tool_call", n.TOOL_CALL_START = "asgard.tool_call.start", n.TOOL_CALL_COMPLETE = "asgard.tool_call.complete", n.TOOL_CALL_CONSENT = "asgard.tool_call.consent", n.SUBAGENT_START = "asgard.subagent.start", n.SUBAGENT_COMPLETE = "asgard.subagent.complete", n.CHANNEL_TITLE_UPDATE = "asgard.channel.title.update", n.PROMPT_SUGGESTION = "asgard.prompt_suggestion", n.SANDBOX_LAUNCH = "asgard.sandbox.launch", n.SANDBOX_READY = "asgard.sandbox.ready", n.DONE = "asgard.run.done", n.ERROR = "asgard.run.error", n))(d || {}), Ye = /* @__PURE__ */ ((n) => (n.ALLOW_ONCE = "ALLOW_ONCE", n.ALLOW_ALWAYS = "ALLOW_ALWAYS", n.DENY_ONCE = "DENY_ONCE", n))(Ye || {}), Te = /* @__PURE__ */ ((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.TABLE = "TABLE", n.ATTACHMENT = "ATTACHMENT", n.QUESTION = "QUESTION", n.CANVAS = "CANVAS", n))(Te || {});
49
+ var B = /* @__PURE__ */ ((n) => (n.RESET_CHANNEL = "RESET_CHANNEL", n.NONE = "NONE", n.RESPONSE_TOOL_CALL_CONSENT = "RESPONSE_TOOL_CALL_CONSENT", n.NUDGE = "NUDGE", n))(B || {}), d = /* @__PURE__ */ ((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.MESSAGE_USER = "asgard.message.user", n.MESSAGE_THINKING_START = "asgard.message.thinking.start", n.MESSAGE_THINKING_DELTA = "asgard.message.thinking.delta", n.MESSAGE_THINKING_COMPLETE = "asgard.message.thinking.complete", n.MESSAGE_CANVAS_START = "asgard.message.canvas.start", n.MESSAGE_CANVAS_DELTA = "asgard.message.canvas.delta", n.MESSAGE_CANVAS_COMPLETE = "asgard.message.canvas.complete", n.TOOL_CALL = "asgard.tool_call", n.TOOL_CALL_START = "asgard.tool_call.start", n.TOOL_CALL_COMPLETE = "asgard.tool_call.complete", n.TOOL_CALL_CONSENT = "asgard.tool_call.consent", n.SUBAGENT_START = "asgard.subagent.start", n.SUBAGENT_COMPLETE = "asgard.subagent.complete", n.CHANNEL_TITLE_UPDATE = "asgard.channel.title.update", n.PROMPT_SUGGESTION = "asgard.prompt_suggestion", n.SANDBOX_LAUNCH = "asgard.sandbox.launch", n.SANDBOX_READY = "asgard.sandbox.ready", n.DONE = "asgard.run.done", n.ERROR = "asgard.run.error", n))(d || {}), Ye = /* @__PURE__ */ ((n) => (n.ALLOW_ONCE = "ALLOW_ONCE", n.ALLOW_ALWAYS = "ALLOW_ALWAYS", n.DENY_ONCE = "DENY_ONCE", n))(Ye || {}), Te = /* @__PURE__ */ ((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.TABLE = "TABLE", n.ATTACHMENT = "ATTACHMENT", n.QUESTION = "QUESTION", n.CANVAS = "CANVAS", n))(Te || {});
50
50
  async function ze(n, t) {
51
51
  const e = n.getReader();
52
52
  let s;
@@ -138,7 +138,7 @@ function Ce(n, t) {
138
138
  p.abort(), document.hidden || j();
139
139
  }
140
140
  u || document.addEventListener("visibilitychange", f);
141
- let E = tt, w = 0;
141
+ let I = tt, w = 0;
142
142
  function F() {
143
143
  document.removeEventListener("visibilitychange", f), window.clearTimeout(w), p.abort();
144
144
  }
@@ -154,12 +154,12 @@ function Ce(n, t) {
154
154
  await L(D), await ze(D.body, Je(Qe((P) => {
155
155
  P ? h[de] = P : delete h[de];
156
156
  }, (P) => {
157
- E = P;
157
+ I = P;
158
158
  }, i))), o?.(), F(), m();
159
159
  } catch (D) {
160
160
  if (!p.signal.aborted)
161
161
  try {
162
- const P = ($ = a?.(D)) !== null && $ !== void 0 ? $ : E;
162
+ const P = ($ = a?.(D)) !== null && $ !== void 0 ? $ : I;
163
163
  window.clearTimeout(w), w = window.setTimeout(j, P);
164
164
  } catch (P) {
165
165
  F(), v(P);
@@ -277,7 +277,7 @@ function xe(n, t) {
277
277
  return { value: c[0] ? c[1] : void 0, done: !0 };
278
278
  }
279
279
  }
280
- function U(n) {
280
+ function M(n) {
281
281
  var t = typeof Symbol == "function" && Symbol.iterator, e = t && n[t], s = 0;
282
282
  if (e) return e.call(n);
283
283
  if (n && typeof n.length == "number") return {
@@ -287,7 +287,7 @@ function U(n) {
287
287
  };
288
288
  throw new TypeError(t ? "Object is not iterable." : "Symbol.iterator is not defined.");
289
289
  }
290
- function B(n, t) {
290
+ function q(n, t) {
291
291
  var e = typeof Symbol == "function" && n[Symbol.iterator];
292
292
  if (!e) return n;
293
293
  var s = e.call(n), r, i = [], o;
@@ -304,7 +304,7 @@ function B(n, t) {
304
304
  }
305
305
  return i;
306
306
  }
307
- function q(n, t, e) {
307
+ function K(n, t, e) {
308
308
  if (e || arguments.length === 2) for (var s = 0, r = t.length, i; s < r; s++)
309
309
  (i || !(s in t)) && (i || (i = Array.prototype.slice.call(t, 0, s)), i[s] = t[s]);
310
310
  return n.concat(i || Array.prototype.slice.call(t));
@@ -325,8 +325,8 @@ function rt(n, t, e) {
325
325
  }
326
326
  function a(h, p) {
327
327
  s[h] && (r[h] = function(f) {
328
- return new Promise(function(E, w) {
329
- i.push([h, f, E, w]) > 1 || u(h, f);
328
+ return new Promise(function(I, w) {
329
+ i.push([h, f, I, w]) > 1 || u(h, f);
330
330
  });
331
331
  }, p && (r[h] = p(r[h])));
332
332
  }
@@ -353,7 +353,7 @@ function rt(n, t, e) {
353
353
  function it(n) {
354
354
  if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
355
355
  var t = n[Symbol.asyncIterator], e;
356
- return t ? t.call(n) : (n = typeof U == "function" ? U(n) : n[Symbol.iterator](), e = {}, s("next"), s("throw"), s("return"), e[Symbol.asyncIterator] = function() {
356
+ return t ? t.call(n) : (n = typeof M == "function" ? M(n) : n[Symbol.iterator](), e = {}, s("next"), s("throw"), s("return"), e[Symbol.asyncIterator] = function() {
357
357
  return this;
358
358
  }, e);
359
359
  function s(i) {
@@ -387,7 +387,7 @@ var Q = Ae(function(n) {
387
387
  `) : "", this.name = "UnsubscriptionError", this.errors = e;
388
388
  };
389
389
  });
390
- function K(n, t) {
390
+ function V(n, t) {
391
391
  if (n) {
392
392
  var e = n.indexOf(t);
393
393
  0 <= e && n.splice(e, 1);
@@ -405,7 +405,7 @@ var N = (function() {
405
405
  if (o)
406
406
  if (this._parentage = null, Array.isArray(o))
407
407
  try {
408
- for (var a = U(o), u = a.next(); !u.done; u = a.next()) {
408
+ for (var a = M(o), u = a.next(); !u.done; u = a.next()) {
409
409
  var c = u.value;
410
410
  c.remove(this);
411
411
  }
@@ -431,12 +431,12 @@ var N = (function() {
431
431
  if (m) {
432
432
  this._finalizers = null;
433
433
  try {
434
- for (var v = U(m), h = v.next(); !h.done; h = v.next()) {
434
+ for (var v = M(m), h = v.next(); !h.done; h = v.next()) {
435
435
  var p = h.value;
436
436
  try {
437
437
  he(p);
438
438
  } catch (f) {
439
- i = i ?? [], f instanceof Q ? i = q(q([], B(i)), B(f.errors)) : i.push(f);
439
+ i = i ?? [], f instanceof Q ? i = K(K([], q(i)), q(f.errors)) : i.push(f);
440
440
  }
441
441
  }
442
442
  } catch (f) {
@@ -473,10 +473,10 @@ var N = (function() {
473
473
  this._parentage = Array.isArray(e) ? (e.push(t), e) : e ? [e, t] : t;
474
474
  }, n.prototype._removeParent = function(t) {
475
475
  var e = this._parentage;
476
- e === t ? this._parentage = null : Array.isArray(e) && K(e, t);
476
+ e === t ? this._parentage = null : Array.isArray(e) && V(e, t);
477
477
  }, n.prototype.remove = function(t) {
478
478
  var e = this._finalizers;
479
- e && K(e, t), t instanceof n && t._removeParent(this);
479
+ e && V(e, t), t instanceof n && t._removeParent(this);
480
480
  }, n.EMPTY = (function() {
481
481
  var t = new n();
482
482
  return t.closed = !0, t;
@@ -494,7 +494,7 @@ var ot = {
494
494
  setTimeout: function(n, t) {
495
495
  for (var e = [], s = 2; s < arguments.length; s++)
496
496
  e[s - 2] = arguments[s];
497
- return setTimeout.apply(void 0, q([n, t], B(e)));
497
+ return setTimeout.apply(void 0, K([n, t], q(e)));
498
498
  },
499
499
  clearTimeout: function(n) {
500
500
  return clearTimeout(n);
@@ -508,7 +508,7 @@ function _e(n) {
508
508
  }
509
509
  function ie() {
510
510
  }
511
- function W(n) {
511
+ function X(n) {
512
512
  n();
513
513
  }
514
514
  var ae = (function(n) {
@@ -552,7 +552,7 @@ var ae = (function(n) {
552
552
  try {
553
553
  e.next(t);
554
554
  } catch (s) {
555
- V(s);
555
+ W(s);
556
556
  }
557
557
  }, n.prototype.error = function(t) {
558
558
  var e = this.partialObserver;
@@ -560,17 +560,17 @@ var ae = (function(n) {
560
560
  try {
561
561
  e.error(t);
562
562
  } catch (s) {
563
- V(s);
563
+ W(s);
564
564
  }
565
565
  else
566
- V(t);
566
+ W(t);
567
567
  }, n.prototype.complete = function() {
568
568
  var t = this.partialObserver;
569
569
  if (t.complete)
570
570
  try {
571
571
  t.complete();
572
572
  } catch (e) {
573
- V(e);
573
+ W(e);
574
574
  }
575
575
  }, n;
576
576
  })(), oe = (function(n) {
@@ -585,7 +585,7 @@ var ae = (function(n) {
585
585
  }
586
586
  return t;
587
587
  })(ae);
588
- function V(n) {
588
+ function W(n) {
589
589
  _e(n);
590
590
  }
591
591
  function ut(n) {
@@ -618,7 +618,7 @@ var y = (function() {
618
618
  return e.source = this, e.operator = t, e;
619
619
  }, n.prototype.subscribe = function(t, e, s) {
620
620
  var r = this, i = ft(t) ? t : new oe(t, e, s);
621
- return W(function() {
621
+ return X(function() {
622
622
  var o = r, a = o.operator, u = o.source;
623
623
  i.add(a ? a.call(i, u) : u ? r._subscribe(i) : r._trySubscribe(i));
624
624
  }), i;
@@ -751,12 +751,12 @@ var mt = (function(n) {
751
751
  throw new gt();
752
752
  }, t.prototype.next = function(e) {
753
753
  var s = this;
754
- W(function() {
754
+ X(function() {
755
755
  var r, i;
756
756
  if (s._throwIfClosed(), !s.isStopped) {
757
757
  s.currentObservers || (s.currentObservers = Array.from(s.observers));
758
758
  try {
759
- for (var o = U(s.currentObservers), a = o.next(); !a.done; a = o.next()) {
759
+ for (var o = M(s.currentObservers), a = o.next(); !a.done; a = o.next()) {
760
760
  var u = a.value;
761
761
  u.next(e);
762
762
  }
@@ -773,7 +773,7 @@ var mt = (function(n) {
773
773
  });
774
774
  }, t.prototype.error = function(e) {
775
775
  var s = this;
776
- W(function() {
776
+ X(function() {
777
777
  if (s._throwIfClosed(), !s.isStopped) {
778
778
  s.hasError = s.isStopped = !0, s.thrownError = e;
779
779
  for (var r = s.observers; r.length; )
@@ -782,7 +782,7 @@ var mt = (function(n) {
782
782
  });
783
783
  }, t.prototype.complete = function() {
784
784
  var e = this;
785
- W(function() {
785
+ X(function() {
786
786
  if (e._throwIfClosed(), !e.isStopped) {
787
787
  e.isStopped = !0;
788
788
  for (var s = e.observers; s.length; )
@@ -805,7 +805,7 @@ var mt = (function(n) {
805
805
  }, t.prototype._innerSubscribe = function(e) {
806
806
  var s = this, r = this, i = r.hasError, o = r.isStopped, a = r.observers;
807
807
  return i || o ? Oe : (this.currentObservers = null, a.push(e), new N(function() {
808
- s.currentObservers = null, K(a, e);
808
+ s.currentObservers = null, V(a, e);
809
809
  }));
810
810
  }, t.prototype._checkFinalizedStatuses = function(e) {
811
811
  var s = this, r = s.hasError, i = s.thrownError, o = s.isStopped;
@@ -874,7 +874,7 @@ var mt = (function(n) {
874
874
  setInterval: function(n, t) {
875
875
  for (var e = [], s = 2; s < arguments.length; s++)
876
876
  e[s - 2] = arguments[s];
877
- return setInterval.apply(void 0, q([n, t], B(e)));
877
+ return setInterval.apply(void 0, K([n, t], q(e)));
878
878
  },
879
879
  clearInterval: function(n) {
880
880
  return clearInterval(n);
@@ -919,7 +919,7 @@ var mt = (function(n) {
919
919
  }, t.prototype.unsubscribe = function() {
920
920
  if (!this.closed) {
921
921
  var e = this, s = e.id, r = e.scheduler, i = r.actions;
922
- this.work = this.state = this.scheduler = null, this.pending = !1, K(i, this), s != null && (this.id = this.recycleAsyncId(r, s, null)), this.delay = null, n.prototype.unsubscribe.call(this);
922
+ this.work = this.state = this.scheduler = null, this.pending = !1, V(i, this), s != null && (this.id = this.recycleAsyncId(r, s, null)), this.delay = null, n.prototype.unsubscribe.call(this);
923
923
  }
924
924
  }, t;
925
925
  })(vt), ge = (function() {
@@ -964,10 +964,10 @@ function Le(n) {
964
964
  function It(n) {
965
965
  return b(Le(n)) ? n.pop() : void 0;
966
966
  }
967
- function Me(n) {
967
+ function Ue(n) {
968
968
  return Et(Le(n)) ? n.pop() : void 0;
969
969
  }
970
- var Ue = (function(n) {
970
+ var Me = (function(n) {
971
971
  return n && typeof n.length == "number" && typeof n != "function";
972
972
  });
973
973
  function Ne(n) {
@@ -1029,12 +1029,12 @@ function J(n) {
1029
1029
  if (n != null) {
1030
1030
  if (Re(n))
1031
1031
  return Ct(n);
1032
- if (Ue(n))
1032
+ if (Me(n))
1033
1033
  return xt(n);
1034
1034
  if (Ne(n))
1035
1035
  return At(n);
1036
1036
  if (ke(n))
1037
- return Ge(n);
1037
+ return Be(n);
1038
1038
  if (De(n))
1039
1039
  return Ot(n);
1040
1040
  if (Fe(n))
@@ -1070,7 +1070,7 @@ function Ot(n) {
1070
1070
  return new y(function(t) {
1071
1071
  var e, s;
1072
1072
  try {
1073
- for (var r = U(n), i = r.next(); !i.done; i = r.next()) {
1073
+ for (var r = M(n), i = r.next(); !i.done; i = r.next()) {
1074
1074
  var o = i.value;
1075
1075
  if (t.next(o), t.closed)
1076
1076
  return;
@@ -1087,7 +1087,7 @@ function Ot(n) {
1087
1087
  t.complete();
1088
1088
  });
1089
1089
  }
1090
- function Ge(n) {
1090
+ function Be(n) {
1091
1091
  return new y(function(t) {
1092
1092
  _t(n, t).catch(function(e) {
1093
1093
  return t.error(e);
@@ -1095,7 +1095,7 @@ function Ge(n) {
1095
1095
  });
1096
1096
  }
1097
1097
  function Pt(n) {
1098
- return Ge(He(n));
1098
+ return Be(He(n));
1099
1099
  }
1100
1100
  function _t(n, t) {
1101
1101
  var e, s, r, i;
@@ -1143,7 +1143,7 @@ function T(n, t, e, s, r) {
1143
1143
  if (n.add(i), !r)
1144
1144
  return i;
1145
1145
  }
1146
- function Be(n, t) {
1146
+ function Ge(n, t) {
1147
1147
  return t === void 0 && (t = 0), _(function(e, s) {
1148
1148
  e.subscribe(R(s, function(r) {
1149
1149
  return T(s, n, function() {
@@ -1168,12 +1168,12 @@ function qe(n, t) {
1168
1168
  });
1169
1169
  }
1170
1170
  function Lt(n, t) {
1171
- return J(n).pipe(qe(t), Be(t));
1172
- }
1173
- function Mt(n, t) {
1174
- return J(n).pipe(qe(t), Be(t));
1171
+ return J(n).pipe(qe(t), Ge(t));
1175
1172
  }
1176
1173
  function Ut(n, t) {
1174
+ return J(n).pipe(qe(t), Ge(t));
1175
+ }
1176
+ function Mt(n, t) {
1177
1177
  return new y(function(e) {
1178
1178
  var s = 0;
1179
1179
  return t.schedule(function() {
@@ -1221,10 +1221,10 @@ function kt(n, t) {
1221
1221
  if (n != null) {
1222
1222
  if (Re(n))
1223
1223
  return Lt(n, t);
1224
- if (Ue(n))
1225
- return Ut(n, t);
1226
- if (Ne(n))
1224
+ if (Me(n))
1227
1225
  return Mt(n, t);
1226
+ if (Ne(n))
1227
+ return Ut(n, t);
1228
1228
  if (ke(n))
1229
1229
  return Ke(n, t);
1230
1230
  if (De(n))
@@ -1247,21 +1247,21 @@ function Y(n, t) {
1247
1247
  }
1248
1248
  var jt = Array.isArray;
1249
1249
  function $t(n, t) {
1250
- return jt(t) ? n.apply(void 0, q([], B(t))) : n(t);
1250
+ return jt(t) ? n.apply(void 0, K([], q(t))) : n(t);
1251
1251
  }
1252
1252
  function Dt(n) {
1253
1253
  return Y(function(t) {
1254
1254
  return $t(n, t);
1255
1255
  });
1256
1256
  }
1257
- var Ht = Array.isArray, Ft = Object.getPrototypeOf, Gt = Object.prototype, Bt = Object.keys;
1257
+ var Ht = Array.isArray, Ft = Object.getPrototypeOf, Bt = Object.prototype, Gt = Object.keys;
1258
1258
  function qt(n) {
1259
1259
  if (n.length === 1) {
1260
1260
  var t = n[0];
1261
1261
  if (Ht(t))
1262
1262
  return { args: t, keys: null };
1263
1263
  if (Kt(t)) {
1264
- var e = Bt(t);
1264
+ var e = Gt(t);
1265
1265
  return {
1266
1266
  args: e.map(function(s) {
1267
1267
  return t[s];
@@ -1273,7 +1273,7 @@ function qt(n) {
1273
1273
  return { args: n, keys: null };
1274
1274
  }
1275
1275
  function Kt(n) {
1276
- return n && typeof n == "object" && Ft(n) === Gt;
1276
+ return n && typeof n == "object" && Ft(n) === Bt;
1277
1277
  }
1278
1278
  function Vt(n, t) {
1279
1279
  return n.reduce(function(e, s, r) {
@@ -1283,7 +1283,7 @@ function Vt(n, t) {
1283
1283
  function Wt() {
1284
1284
  for (var n = [], t = 0; t < arguments.length; t++)
1285
1285
  n[t] = arguments[t];
1286
- var e = Me(n), s = It(n), r = qt(n), i = r.args, o = r.keys;
1286
+ var e = Ue(n), s = It(n), r = qt(n), i = r.args, o = r.keys;
1287
1287
  if (i.length === 0)
1288
1288
  return Ve([], e);
1289
1289
  var a = new y(Xt(i, e, o ? function(u) {
@@ -1322,17 +1322,17 @@ function Yt(n, t) {
1322
1322
  function zt(n) {
1323
1323
  for (var t, e, s = [], r = 1; r < arguments.length; r++)
1324
1324
  s[r - 1] = arguments[r];
1325
- var i = (t = Me(s)) !== null && t !== void 0 ? t : wt, o = (e = s[0]) !== null && e !== void 0 ? e : null, a = s[1] || 1 / 0;
1325
+ var i = (t = Ue(s)) !== null && t !== void 0 ? t : wt, o = (e = s[0]) !== null && e !== void 0 ? e : null, a = s[1] || 1 / 0;
1326
1326
  return _(function(u, c) {
1327
1327
  var l = [], m = !1, v = function(f) {
1328
- var E = f.buffer, w = f.subs;
1329
- w.unsubscribe(), K(l, f), c.next(E), m && h();
1328
+ var I = f.buffer, w = f.subs;
1329
+ w.unsubscribe(), V(l, f), c.next(I), m && h();
1330
1330
  }, h = function() {
1331
1331
  if (l) {
1332
1332
  var f = new N();
1333
1333
  c.add(f);
1334
- var E = [], w = {
1335
- buffer: E,
1334
+ var I = [], w = {
1335
+ buffer: I,
1336
1336
  subs: f
1337
1337
  };
1338
1338
  l.push(w), T(f, i, function() {
@@ -1342,19 +1342,19 @@ function zt(n) {
1342
1342
  };
1343
1343
  o !== null && o >= 0 ? T(c, i, h, o, !0) : m = !0, h();
1344
1344
  var p = R(c, function(f) {
1345
- var E, w, F = l.slice();
1345
+ var I, w, F = l.slice();
1346
1346
  try {
1347
- for (var k = U(F), L = k.next(); !L.done; L = k.next()) {
1347
+ for (var k = M(F), L = k.next(); !L.done; L = k.next()) {
1348
1348
  var j = L.value, $ = j.buffer;
1349
1349
  $.push(f), a <= $.length && v(j);
1350
1350
  }
1351
1351
  } catch (D) {
1352
- E = { error: D };
1352
+ I = { error: D };
1353
1353
  } finally {
1354
1354
  try {
1355
1355
  L && !L.done && (w = k.return) && w.call(k);
1356
1356
  } finally {
1357
- if (E) throw E.error;
1357
+ if (I) throw I.error;
1358
1358
  }
1359
1359
  }
1360
1360
  }, function() {
@@ -1367,7 +1367,7 @@ function zt(n) {
1367
1367
  u.subscribe(p);
1368
1368
  });
1369
1369
  }
1370
- function M(n, t) {
1370
+ function U(n, t) {
1371
1371
  return t === void 0 && (t = z), n = n ?? Jt, _(function(e, s) {
1372
1372
  var r, i = !0;
1373
1373
  e.subscribe(R(s, function(o) {
@@ -1430,7 +1430,7 @@ function ve(n) {
1430
1430
  f = null;
1431
1431
  }
1432
1432
  }
1433
- a.error(new I(p.status, p.statusText, f)), u.abort();
1433
+ a.error(new E(p.status, p.statusText, f)), u.abort();
1434
1434
  }
1435
1435
  },
1436
1436
  onmessage: (p) => {
@@ -1585,7 +1585,7 @@ class _n {
1585
1585
  if (i.status === 404)
1586
1586
  return null;
1587
1587
  if (!i.ok)
1588
- throw new I(i.status, i.statusText, await i.text().catch(() => {
1588
+ throw new E(i.status, i.statusText, await i.text().catch(() => {
1589
1589
  }));
1590
1590
  const o = await i.json(), a = o.data ?? o;
1591
1591
  return {
@@ -1631,7 +1631,38 @@ class _n {
1631
1631
  r.searchParams.set("custom_channel_id", t), e?.requestId && r.searchParams.set("request_id", e.requestId), e?.force && r.searchParams.set("force", "true");
1632
1632
  const i = await fetch(r.toString(), { method: "POST", headers: this.apiHeaders() });
1633
1633
  if (!(i.ok || i.status === 404))
1634
- throw new I(i.status, i.statusText, await i.text().catch(() => {
1634
+ throw new E(i.status, i.statusText, await i.text().catch(() => {
1635
+ }));
1636
+ }
1637
+ deriveChannelEndpoint() {
1638
+ const t = this.getBaseEndpoint();
1639
+ return t ? `${t}/channel` : null;
1640
+ }
1641
+ /**
1642
+ * End the conversation and release the whole channel (F-032):
1643
+ * `DELETE {base}/channel?custom_channel_id=…`. The backend tears down the in-flight run, the
1644
+ * transcript, uploaded blobs, the tool-call allow-list, the Sandbox and the Channel Home, and only
1645
+ * then answers — so once this resolves the same `customChannelId` is genuinely a blank slate
1646
+ * (`GET /channel/metadata` goes back to `404`).
1647
+ *
1648
+ * Success is **any 2xx**: the endpoint answers `204 No Content`, and does so for a channel that never
1649
+ * existed too (deleting nothing is not a failure). Unlike {@link suspendChannel} there is no `404`
1650
+ * special case, because the backend never answers one here. Everything else throws {@link HttpError},
1651
+ * and a throw must never be read as "deleted" — a `500` means the teardown failed and the old
1652
+ * conversation is still there.
1653
+ *
1654
+ * **No timeout is imposed.** A channel with a live Sandbox blocks until the pod is really gone (up to
1655
+ * about a minute), on purpose: the next turn must not race a dying pod.
1656
+ */
1657
+ async deleteChannel(t) {
1658
+ const e = this.deriveChannelEndpoint();
1659
+ if (!e)
1660
+ throw new Error("Unable to derive channel endpoint. Please provide botProviderEndpoint in config.");
1661
+ const s = new URL(e);
1662
+ s.searchParams.set("custom_channel_id", t);
1663
+ const r = await fetch(s.toString(), { method: "DELETE", headers: this.apiHeaders() });
1664
+ if (!r.ok)
1665
+ throw new E(r.status, r.statusText, await r.text().catch(() => {
1635
1666
  }));
1636
1667
  }
1637
1668
  runSse(t, e) {
@@ -1771,7 +1802,7 @@ class _n {
1771
1802
  this.apiKey && (r["X-API-KEY"] = this.apiKey);
1772
1803
  const i = await fetch(s, { method: "POST", headers: r });
1773
1804
  if (!i.ok)
1774
- throw new I(i.status, i.statusText, await i.text().catch(() => {
1805
+ throw new E(i.status, i.statusText, await i.text().catch(() => {
1775
1806
  }));
1776
1807
  const o = await i.json(), a = o.data?.openURL ?? o.openURL;
1777
1808
  if (!a)
@@ -1801,7 +1832,7 @@ class _n {
1801
1832
  s.searchParams.set("path", e);
1802
1833
  const r = await fetch(s.toString(), { method: "GET", headers: this.apiHeaders() });
1803
1834
  if (!r.ok)
1804
- throw new I(r.status, r.statusText, await r.text().catch(() => {
1835
+ throw new E(r.status, r.statusText, await r.text().catch(() => {
1805
1836
  }));
1806
1837
  const i = await r.json(), o = i.data ?? i;
1807
1838
  return { entries: o.entries ?? [], truncated: o.truncated ?? !1 };
@@ -1815,7 +1846,7 @@ class _n {
1815
1846
  r.searchParams.set("path", e), s?.offsetBytes != null && r.searchParams.set("offset_bytes", String(s.offsetBytes)), s?.limitBytes != null && r.searchParams.set("limit_bytes", String(s.limitBytes));
1816
1847
  const i = await fetch(r.toString(), { method: "GET", headers: this.apiHeaders() });
1817
1848
  if (!i.ok)
1818
- throw new I(i.status, i.statusText, await i.text().catch(() => {
1849
+ throw new E(i.status, i.statusText, await i.text().catch(() => {
1819
1850
  }));
1820
1851
  const o = await i.blob(), a = i.headers.get("X-Total-Bytes");
1821
1852
  return {
@@ -1840,7 +1871,7 @@ class _n {
1840
1871
  signal: r?.signal
1841
1872
  });
1842
1873
  if (!a.ok)
1843
- throw new I(a.status, a.statusText, await a.text().catch(() => {
1874
+ throw new E(a.status, a.statusText, await a.text().catch(() => {
1844
1875
  }));
1845
1876
  const u = await a.json();
1846
1877
  return { bytesWritten: (u.data ?? u).bytesWritten ?? 0 };
@@ -1851,7 +1882,7 @@ class _n {
1851
1882
  Object.entries(r).forEach(([a, u]) => i.searchParams.set(a, u));
1852
1883
  const o = await fetch(i.toString(), { method: s, headers: this.apiHeaders() });
1853
1884
  if (!o.ok)
1854
- throw new I(o.status, o.statusText, await o.text().catch(() => {
1885
+ throw new E(o.status, o.statusText, await o.text().catch(() => {
1855
1886
  }));
1856
1887
  return o.json().catch(() => null);
1857
1888
  }
@@ -1861,7 +1892,7 @@ class _n {
1861
1892
  s.searchParams.set("path", e);
1862
1893
  const r = await fetch(s.toString(), { method: "GET", headers: this.apiHeaders() });
1863
1894
  if (!r.ok)
1864
- throw new I(r.status, r.statusText, await r.text().catch(() => {
1895
+ throw new E(r.status, r.statusText, await r.text().catch(() => {
1865
1896
  }));
1866
1897
  const i = await r.json(), o = i.data ?? i;
1867
1898
  return {
@@ -1914,7 +1945,7 @@ class _n {
1914
1945
  if (!o.ok) {
1915
1946
  const a = await o.text().catch(() => {
1916
1947
  });
1917
- r.error(new I(o.status, o.statusText, a)), i.abort();
1948
+ r.error(new E(o.status, o.statusText, a)), i.abort();
1918
1949
  }
1919
1950
  },
1920
1951
  onmessage: (o) => {
@@ -1982,7 +2013,7 @@ class Ln {
1982
2013
  Object.entries(s).forEach(([u, c]) => o.searchParams.set(u, c));
1983
2014
  const a = await fetch(o.toString(), { method: e, headers: this.headers(), body: r, signal: i });
1984
2015
  if (!a.ok)
1985
- throw new I(a.status, a.statusText, await a.text().catch(() => {
2016
+ throw new E(a.status, a.statusText, await a.text().catch(() => {
1986
2017
  }));
1987
2018
  return a;
1988
2019
  }
@@ -2668,8 +2699,8 @@ function In(n, t) {
2668
2699
  }
2669
2700
  function Tn(n) {
2670
2701
  const t = new A([]), e = new A([]), s = new N();
2671
- return s.add(n.pipe(Y(Sn), M(wn)).subscribe(t)), s.add(
2672
- n.pipe(Y(yn), M(In)).subscribe(e)
2702
+ return s.add(n.pipe(Y(Sn), U(wn)).subscribe(t)), s.add(
2703
+ n.pipe(Y(yn), U(In)).subscribe(e)
2673
2704
  ), {
2674
2705
  tasks$: t.asObservable(),
2675
2706
  subagents$: e.asObservable(),
@@ -2689,7 +2720,7 @@ const ee = { kind: null, stopPhase: "idle" }, Cn = 1e4;
2689
2720
  function xn(n, t) {
2690
2721
  return n.kind === t.kind && n.stopPhase === t.stopPhase && n.requestId === t.requestId;
2691
2722
  }
2692
- class X {
2723
+ class G {
2693
2724
  client;
2694
2725
  customChannelId;
2695
2726
  customMessageId;
@@ -2751,7 +2782,7 @@ class X {
2751
2782
  throw new Error("customChannelId must be required");
2752
2783
  this.client = t.client, this.customChannelId = t.customChannelId, this.customMessageId = t.customMessageId, this.joinRunState = t.runState ?? "IDLE", this.isConnecting$ = new A(!1), this.runStatusSubject = new A(ee), this.conversation$ = new A(t.conversation), this.channelTitleSubject = new A(t.channelTitle ?? null), this.promptSuggestionSubject = new A(null), this.sandboxPhaseSubject = new A("idle"), this.launchedSandboxesSubject = new A(
2753
2784
  Ie(t.launchedSandboxes ?? [])
2754
- ), this.derivedStores = Tn(this.conversation$), this.tasks$ = this.derivedStores.tasks$, this.subagents$ = this.derivedStores.subagents$, this.channelTitle$ = this.channelTitleSubject.pipe(M()), this.promptSuggestion$ = this.promptSuggestionSubject.pipe(M()), this.sandboxPhase$ = this.sandboxPhaseSubject.pipe(M()), this.launchedSandboxes$ = this.launchedSandboxesSubject.pipe(M()), this.runStatus$ = this.runStatusSubject.pipe(M(xn)), this.statesObserver = t.statesObserver;
2785
+ ), this.derivedStores = Tn(this.conversation$), this.tasks$ = this.derivedStores.tasks$, this.subagents$ = this.derivedStores.subagents$, this.channelTitle$ = this.channelTitleSubject.pipe(U()), this.promptSuggestion$ = this.promptSuggestionSubject.pipe(U()), this.sandboxPhase$ = this.sandboxPhaseSubject.pipe(U()), this.launchedSandboxes$ = this.launchedSandboxesSubject.pipe(U()), this.runStatus$ = this.runStatusSubject.pipe(U(xn)), this.statesObserver = t.statesObserver;
2755
2786
  }
2756
2787
  /** Current Task Check List snapshot (F-013) — for framework-agnostic `getSnapshot()` bridging. */
2757
2788
  getTasks() {
@@ -2833,26 +2864,59 @@ class X {
2833
2864
  this.channelTitleSubject.next(t);
2834
2865
  }
2835
2866
  static create(t) {
2836
- const e = new X(t);
2867
+ const e = new G(t);
2837
2868
  return e.subscribe(), e;
2838
2869
  }
2839
- static async reset(t, e, s, r) {
2840
- const i = new X(t);
2870
+ /**
2871
+ * Open a channel with a fresh conversation (F-032): create it and dispatch a single `action=NONE`
2872
+ * opening turn, which the backend answers with the welcome run. Used for the mount-time opening of a
2873
+ * channel that does not exist yet (UC-025) — nothing is deleted, because there is nothing there.
2874
+ *
2875
+ * The run's kind stays `'reset'`: an opening turn is not a turn the user dispatched, so
2876
+ * stop-generation must not fire on it (F-023 AC8).
2877
+ */
2878
+ static async open(t, e, s, r) {
2879
+ const i = new G(t);
2841
2880
  try {
2842
- return i.subscribe(), r?.(i), await i.resetChannel(e, s), i;
2881
+ return i.subscribe(), r?.(i), await i.openChannel(e, s), i;
2843
2882
  } catch (o) {
2844
2883
  throw i.close(), o;
2845
2884
  }
2846
2885
  }
2886
+ /**
2887
+ * Clear an **existing** conversation and start over on the same id (F-032) — what the header's reset
2888
+ * button does. Two steps, in this order and never bundled:
2889
+ *
2890
+ * 1. `client.deleteChannel()` — the backend releases the run, transcript, blobs, consent allow-list,
2891
+ * Sandbox and Channel Home, and answers only once that teardown is done.
2892
+ * 2. {@link Channel.open} — a plain `action=NONE` opening turn on the now-empty id.
2893
+ *
2894
+ * This replaces the single `RESET_CHANNEL` turn, which bundled both into one request and therefore
2895
+ * could never carry attachments: blobs belong to the channel that was live when they were uploaded, so
2896
+ * the delete stripped them and the `blobIds` resolved to nothing without an error. A host that needs
2897
+ * "clear, then send with attachments" sequences it itself: `deleteChannel` → upload → `sendMessage`.
2898
+ *
2899
+ * **Nothing local changes until the delete succeeds** — no channel is constructed, so no state
2900
+ * observer fires. A failed delete therefore leaves the caller's current channel and conversation
2901
+ * exactly as they were, which is the point: the screen must never be cleared while the server still
2902
+ * holds the old conversation.
2903
+ */
2904
+ static async reset(t, e, s, r) {
2905
+ if (!t.client.deleteChannel)
2906
+ throw new Error(
2907
+ "This client cannot reset a channel: IAsgardServiceClient.deleteChannel is not implemented. Implement it (DELETE {base}/channel?custom_channel_id=…) or use AsgardServiceClient."
2908
+ );
2909
+ return await t.client.deleteChannel(t.customChannelId), G.open(t, e, s, r);
2910
+ }
2847
2911
  /**
2848
2912
  * Join an **existing** channel without resetting it (F-015). Seeds the title from `config.channelTitle`
2849
2913
  * (the `GET /channel/metadata` value) at construction, then replays the server transcript via GET
2850
- * `rejoinSse` and holds `isConnecting` until the run reaches a terminal. Never sends `RESET_CHANNEL`,
2851
- * so the channel's history / session / title are preserved — this is the fix for the mount-time
2914
+ * `rejoinSse` and holds `isConnecting` until the run reaches a terminal. Never deletes and never
2915
+ * opens, so the channel's history / session / title are preserved — this is the fix for the mount-time
2852
2916
  * "join an existing channel and wipe its history" data-loss bug.
2853
2917
  */
2854
2918
  static async restore(t, e, s) {
2855
- const r = new X(t);
2919
+ const r = new G(t);
2856
2920
  try {
2857
2921
  return r.subscribe(), s?.(r), await r.rejoinChannel(e), r;
2858
2922
  } catch (i) {
@@ -3001,11 +3065,16 @@ class X {
3001
3065
  }), this.currentRun = this.client.rejoinSse(this.customChannelId, this.buildRunHandlers(t, e, s));
3002
3066
  });
3003
3067
  }
3004
- resetChannel(t, e) {
3068
+ /**
3069
+ * The opening turn (F-032): a plain `action=NONE` with the caller's text / payload (empty text when
3070
+ * they gave none). On a channel that does not exist the backend creates it and runs the welcome; on
3071
+ * one just emptied by `deleteChannel` it starts the new conversation.
3072
+ */
3073
+ openChannel(t, e) {
3005
3074
  return this.fetchSse(
3006
3075
  "reset",
3007
3076
  {
3008
- action: G.RESET_CHANNEL,
3077
+ action: B.NONE,
3009
3078
  customChannelId: this.customChannelId,
3010
3079
  customMessageId: this.customMessageId,
3011
3080
  text: t?.text || "",
@@ -3034,7 +3103,7 @@ class X {
3034
3103
  ), this.fetchSse(
3035
3104
  "user",
3036
3105
  {
3037
- action: G.NONE,
3106
+ action: B.NONE,
3038
3107
  customChannelId: this.customChannelId,
3039
3108
  customMessageId: o,
3040
3109
  payload: this.resolvePayload(t?.payload),
@@ -3049,7 +3118,7 @@ class X {
3049
3118
  return this.conversation$.next(this.conversation$.value.clearPendingConsent()), this.fetchSse(
3050
3119
  "user",
3051
3120
  {
3052
- action: G.RESPONSE_TOOL_CALL_CONSENT,
3121
+ action: B.RESPONSE_TOOL_CALL_CONSENT,
3053
3122
  customChannelId: this.customChannelId,
3054
3123
  customMessageId: this.lastSentMessageId ?? this.customMessageId,
3055
3124
  payload: this.resolvePayload(s),
@@ -3088,7 +3157,7 @@ class X {
3088
3157
  return r ? Promise.reject(new ne(r.processId)) : this.fetchSse(
3089
3158
  "nudge",
3090
3159
  {
3091
- action: G.NUDGE,
3160
+ action: B.NUDGE,
3092
3161
  customChannelId: this.customChannelId,
3093
3162
  customMessageId: this.lastSentMessageId ?? this.customMessageId,
3094
3163
  payload: this.resolvePayload(e),
@@ -3114,7 +3183,7 @@ class X {
3114
3183
  * `force-stoppable`, and calling again with `{ force: true }` tells the backend to give up on the run
3115
3184
  * rather than let it wind down (AC7).
3116
3185
  *
3117
- * No-ops (resolving) when nothing is running, when the run is not the user's own — a `RESET_CHANNEL`
3186
+ * No-ops (resolving) when nothing is running, when the run is not the user's own — an opening
3118
3187
  * welcome, a transcript replay or an invisible nudge must never be stopped (AC8) — or when a stop is
3119
3188
  * already pending and this is not a force.
3120
3189
  *
@@ -3171,7 +3240,7 @@ class X {
3171
3240
  this.currentRun?.unsubscribe(), this.currentRun = void 0, this.clearForceStopTimer(), this.isConnecting$.complete(), this.runStatusSubject.complete(), this.conversation$.complete(), this.channelTitleSubject.complete(), this.sandboxPhaseSubject.complete(), this.launchedSandboxesSubject.complete(), this.derivedStores.teardown(), this.statesSubscription?.unsubscribe();
3172
3241
  }
3173
3242
  }
3174
- function Mn(n) {
3243
+ function Un(n) {
3175
3244
  const t = /^sandbox:\/\/([^/]+)\/([^?#]+)(?:\?([^#]*))?/.exec(n.trim());
3176
3245
  if (!t) return null;
3177
3246
  const e = decodeURIComponent(t[1]), s = t[2], r = new URLSearchParams(t[3] ?? "");
@@ -3185,13 +3254,13 @@ function Mn(n) {
3185
3254
  export {
3186
3255
  _n as AsgardServiceClient,
3187
3256
  Ln as AsgardSourceSetClient,
3188
- X as Channel,
3257
+ G as Channel,
3189
3258
  ne as ChannelAwaitingConsentError,
3190
3259
  te as ChannelBusyError,
3191
3260
  g as Conversation,
3192
3261
  d as EventType,
3193
- G as FetchSseAction,
3194
- I as HttpError,
3262
+ B as FetchSseAction,
3263
+ E as HttpError,
3195
3264
  Te as MessageTemplateType,
3196
3265
  rn as SOURCE_SET_DEFAULT_MAX_ENTRIES,
3197
3266
  We as SOURCE_SET_MAX_PAGE_SIZE,
@@ -3211,7 +3280,7 @@ export {
3211
3280
  Ie as reconcileLaunched,
3212
3281
  gn as reduceSubagents,
3213
3282
  fn as reduceTaskEvents,
3214
- Mn as resolveSandboxUri,
3283
+ Un as resolveSandboxUri,
3215
3284
  In as subagentsEqual,
3216
3285
  wn as tasksEqual
3217
3286
  };