@asgard-js/core 0.3.7 → 0.3.9

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
@@ -35,15 +35,15 @@ function Be(n, t, e, r) {
35
35
  function a(h) {
36
36
  try {
37
37
  c(r.next(h));
38
- } catch (m) {
39
- o(m);
38
+ } catch (g) {
39
+ o(g);
40
40
  }
41
41
  }
42
42
  function u(h) {
43
43
  try {
44
44
  c(r.throw(h));
45
- } catch (m) {
46
- o(m);
45
+ } catch (g) {
46
+ o(g);
47
47
  }
48
48
  }
49
49
  function c(h) {
@@ -155,7 +155,7 @@ function qe(n, t, e) {
155
155
  }, s;
156
156
  function o(l) {
157
157
  return function(f) {
158
- return Promise.resolve(f).then(l, m);
158
+ return Promise.resolve(f).then(l, g);
159
159
  };
160
160
  }
161
161
  function a(l, f) {
@@ -173,12 +173,12 @@ function qe(n, t, e) {
173
173
  }
174
174
  }
175
175
  function c(l) {
176
- l.value instanceof L ? Promise.resolve(l.value.v).then(h, m) : v(i[0][2], l);
176
+ l.value instanceof L ? Promise.resolve(l.value.v).then(h, g) : v(i[0][2], l);
177
177
  }
178
178
  function h(l) {
179
179
  u("next", l);
180
180
  }
181
- function m(l) {
181
+ function g(l) {
182
182
  u("throw", l);
183
183
  }
184
184
  function v(l, f) {
@@ -204,7 +204,7 @@ function Ve(n) {
204
204
  }, o);
205
205
  }
206
206
  }
207
- function g(n) {
207
+ function m(n) {
208
208
  return typeof n == "function";
209
209
  }
210
210
  function ye(n) {
@@ -256,17 +256,17 @@ var U = (function() {
256
256
  else
257
257
  o.remove(this);
258
258
  var h = this.initialTeardown;
259
- if (g(h))
259
+ if (m(h))
260
260
  try {
261
261
  h();
262
262
  } catch (p) {
263
263
  i = p instanceof W ? p.errors : [p];
264
264
  }
265
- var m = this._finalizers;
266
- if (m) {
265
+ var g = this._finalizers;
266
+ if (g) {
267
267
  this._finalizers = null;
268
268
  try {
269
- for (var v = k(m), l = v.next(); !l.done; l = v.next()) {
269
+ for (var v = k(g), l = v.next(); !l.done; l = v.next()) {
270
270
  var f = l.value;
271
271
  try {
272
272
  oe(f);
@@ -318,10 +318,10 @@ var U = (function() {
318
318
  })(), n;
319
319
  })(), be = U.EMPTY;
320
320
  function Se(n) {
321
- return n instanceof U || n && "closed" in n && g(n.remove) && g(n.add) && g(n.unsubscribe);
321
+ return n instanceof U || n && "closed" in n && m(n.remove) && m(n.add) && m(n.unsubscribe);
322
322
  }
323
323
  function oe(n) {
324
- g(n) ? n() : n.unsubscribe();
324
+ m(n) ? n() : n.unsubscribe();
325
325
  }
326
326
  var Ye = {
327
327
  Promise: void 0
@@ -412,7 +412,7 @@ var ne = (function(n) {
412
412
  w(t, n);
413
413
  function t(e, r, s) {
414
414
  var i = n.call(this) || this, o;
415
- return g(e) || !e ? o = {
415
+ return m(e) || !e ? o = {
416
416
  next: e ?? void 0,
417
417
  error: r ?? void 0,
418
418
  complete: s ?? void 0
@@ -509,13 +509,13 @@ function ae(n) {
509
509
  return (t = n ?? Ye.Promise) !== null && t !== void 0 ? t : Promise;
510
510
  }
511
511
  function Ze(n) {
512
- return n && g(n.next) && g(n.error) && g(n.complete);
512
+ return n && m(n.next) && m(n.error) && m(n.complete);
513
513
  }
514
514
  function et(n) {
515
515
  return n && n instanceof ne || Ze(n) && Se(n);
516
516
  }
517
517
  function tt(n) {
518
- return g(n?.lift);
518
+ return m(n?.lift);
519
519
  }
520
520
  function A(n) {
521
521
  return function(t) {
@@ -793,13 +793,13 @@ var nt = (function(n) {
793
793
  return n.complete();
794
794
  });
795
795
  function we(n) {
796
- return n && g(n.schedule);
796
+ return n && m(n.schedule);
797
797
  }
798
798
  function Te(n) {
799
799
  return n[n.length - 1];
800
800
  }
801
801
  function lt(n) {
802
- return g(Te(n)) ? n.pop() : void 0;
802
+ return m(Te(n)) ? n.pop() : void 0;
803
803
  }
804
804
  function Ce(n) {
805
805
  return we(Te(n)) ? n.pop() : void 0;
@@ -808,13 +808,13 @@ var Oe = (function(n) {
808
808
  return n && typeof n.length == "number" && typeof n != "function";
809
809
  });
810
810
  function Ae(n) {
811
- return g(n?.then);
811
+ return m(n?.then);
812
812
  }
813
813
  function _e(n) {
814
- return g(n[re]);
814
+ return m(n[re]);
815
815
  }
816
816
  function Me(n) {
817
- return Symbol.asyncIterator && g(n?.[Symbol.asyncIterator]);
817
+ return Symbol.asyncIterator && m(n?.[Symbol.asyncIterator]);
818
818
  }
819
819
  function xe(n) {
820
820
  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.");
@@ -824,7 +824,7 @@ function dt() {
824
824
  }
825
825
  var Le = dt();
826
826
  function ke(n) {
827
- return g(n?.[Le]);
827
+ return m(n?.[Le]);
828
828
  }
829
829
  function Pe(n) {
830
830
  return qe(this, arguments, function() {
@@ -858,7 +858,7 @@ function Pe(n) {
858
858
  });
859
859
  }
860
860
  function Ue(n) {
861
- return g(n?.getReader);
861
+ return m(n?.getReader);
862
862
  }
863
863
  function x(n) {
864
864
  if (n instanceof S)
@@ -873,16 +873,16 @@ function x(n) {
873
873
  if (Me(n))
874
874
  return Ne(n);
875
875
  if (ke(n))
876
- return mt(n);
877
- if (Ue(n))
878
876
  return gt(n);
877
+ if (Ue(n))
878
+ return mt(n);
879
879
  }
880
880
  throw xe(n);
881
881
  }
882
882
  function ht(n) {
883
883
  return new S(function(t) {
884
884
  var e = n[re]();
885
- if (g(e.subscribe))
885
+ if (m(e.subscribe))
886
886
  return e.subscribe(t);
887
887
  throw new TypeError("Provided object does not correctly implement Symbol.observable");
888
888
  });
@@ -903,7 +903,7 @@ function pt(n) {
903
903
  }).then(null, Ie);
904
904
  });
905
905
  }
906
- function mt(n) {
906
+ function gt(n) {
907
907
  return new S(function(t) {
908
908
  var e, r;
909
909
  try {
@@ -931,7 +931,7 @@ function Ne(n) {
931
931
  });
932
932
  });
933
933
  }
934
- function gt(n) {
934
+ function mt(n) {
935
935
  return Ne(Pe(n));
936
936
  }
937
937
  function vt(n, t) {
@@ -1033,7 +1033,7 @@ function It(n, t) {
1033
1033
  o ? e.complete() : e.next(i);
1034
1034
  }, 0, !0);
1035
1035
  }), function() {
1036
- return g(r?.return) && r.return();
1036
+ return m(r?.return) && r.return();
1037
1037
  };
1038
1038
  });
1039
1039
  }
@@ -1142,8 +1142,8 @@ function $t(n, t, e) {
1142
1142
  de(t, function() {
1143
1143
  for (var s = n.length, i = new Array(s), o = s, a = s, u = function(h) {
1144
1144
  de(t, function() {
1145
- var m = ie(n[h], t), v = !1;
1146
- m.subscribe(O(r, function(l) {
1145
+ var g = ie(n[h], t), v = !1;
1146
+ g.subscribe(O(r, function(l) {
1147
1147
  i[h] = l, v || (v = !0, a--), a || r.next(e(i.slice()));
1148
1148
  }, function() {
1149
1149
  --o || r.complete();
@@ -1158,8 +1158,8 @@ function de(n, t, e) {
1158
1158
  n ? C(e, n, t) : t();
1159
1159
  }
1160
1160
  function jt(n, t, e, r, s, i, o, a) {
1161
- var u = [], c = 0, h = 0, m = !1, v = function() {
1162
- m && !u.length && !c && t.complete();
1161
+ var u = [], c = 0, h = 0, g = !1, v = function() {
1162
+ g && !u.length && !c && t.complete();
1163
1163
  }, l = function(p) {
1164
1164
  return c < r ? f(p) : u.push(p);
1165
1165
  }, f = function(p) {
@@ -1185,12 +1185,12 @@ function jt(n, t, e, r, s, i, o, a) {
1185
1185
  }));
1186
1186
  };
1187
1187
  return n.subscribe(O(t, l, function() {
1188
- m = !0, v();
1188
+ g = !0, v();
1189
1189
  })), function() {
1190
1190
  };
1191
1191
  }
1192
1192
  function B(n, t, e) {
1193
- return e === void 0 && (e = 1 / 0), g(t) ? B(function(r, s) {
1193
+ return e === void 0 && (e = 1 / 0), m(t) ? B(function(r, s) {
1194
1194
  return P(function(i, o) {
1195
1195
  return t(r, i, s, o);
1196
1196
  })(x(n(r, s)));
@@ -1211,7 +1211,7 @@ function Dt(n, t, e) {
1211
1211
  });
1212
1212
  }
1213
1213
  function Ht(n, t) {
1214
- return g(t) ? B(n, t, 1) : B(n, 1);
1214
+ return m(t) ? B(n, t, 1) : B(n, 1);
1215
1215
  }
1216
1216
  function Gt(n) {
1217
1217
  return n <= 0 ? function() {
@@ -1321,8 +1321,8 @@ function zt(n, t, e) {
1321
1321
  n(r.id = h);
1322
1322
  break;
1323
1323
  case "retry":
1324
- const m = parseInt(h, 10);
1325
- isNaN(m) || t(r.retry = m);
1324
+ const g = parseInt(h, 10);
1325
+ isNaN(g) || t(r.retry = g);
1326
1326
  break;
1327
1327
  }
1328
1328
  }
@@ -1351,7 +1351,7 @@ var Qt = function(n, t) {
1351
1351
  const ee = "text/event-stream", Zt = 1e3, fe = "last-event-id";
1352
1352
  function en(n, t) {
1353
1353
  var { signal: e, headers: r, onopen: s, onmessage: i, onclose: o, onerror: a, openWhenHidden: u, fetch: c } = t, h = Qt(t, ["signal", "headers", "onopen", "onmessage", "onclose", "onerror", "openWhenHidden", "fetch"]);
1354
- return new Promise((m, v) => {
1354
+ return new Promise((g, v) => {
1355
1355
  const l = Object.assign({}, r);
1356
1356
  l.accept || (l.accept = ee);
1357
1357
  let f;
@@ -1364,7 +1364,7 @@ function en(n, t) {
1364
1364
  document.removeEventListener("visibilitychange", p), window.clearTimeout(I), f.abort();
1365
1365
  }
1366
1366
  e?.addEventListener("abort", () => {
1367
- M(), m();
1367
+ M(), g();
1368
1368
  });
1369
1369
  const He = c ?? window.fetch, Ge = s ?? tn;
1370
1370
  async function V() {
@@ -1376,7 +1376,7 @@ function en(n, t) {
1376
1376
  T ? l[fe] = T : delete l[fe];
1377
1377
  }, (T) => {
1378
1378
  _ = T;
1379
- }, i))), o?.(), M(), m();
1379
+ }, i))), o?.(), M(), g();
1380
1380
  } catch (j) {
1381
1381
  if (!f.signal.aborted)
1382
1382
  try {
@@ -1400,15 +1400,15 @@ function pe(n) {
1400
1400
  return new S((a) => {
1401
1401
  const u = new AbortController();
1402
1402
  let c, h = !1;
1403
- const m = {
1403
+ const g = {
1404
1404
  "Content-Type": "application/json",
1405
1405
  ...i
1406
1406
  };
1407
- e && (m["X-API-KEY"] = e);
1407
+ e && (g["X-API-KEY"] = e);
1408
1408
  const v = new URL(t);
1409
1409
  return s && v.searchParams.set("is_debug", "true"), en(v.toString(), {
1410
1410
  method: o,
1411
- headers: m,
1411
+ headers: g,
1412
1412
  body: o === "POST" && r ? JSON.stringify(r) : void 0,
1413
1413
  signal: u.signal,
1414
1414
  /**
@@ -1712,11 +1712,11 @@ class Tn {
1712
1712
  return !t && this.endpoint && (t = this.endpoint.replace("/message/sse", "")), t ? t.replace(/\/+$/, "") : null;
1713
1713
  }
1714
1714
  }
1715
- const y = [];
1715
+ const b = [];
1716
1716
  for (let n = 0; n < 256; ++n)
1717
- y.push((n + 256).toString(16).slice(1));
1717
+ b.push((n + 256).toString(16).slice(1));
1718
1718
  function rn(n, t = 0) {
1719
- return (y[n[t + 0]] + y[n[t + 1]] + y[n[t + 2]] + y[n[t + 3]] + "-" + y[n[t + 4]] + y[n[t + 5]] + "-" + y[n[t + 6]] + y[n[t + 7]] + "-" + y[n[t + 8]] + y[n[t + 9]] + "-" + y[n[t + 10]] + y[n[t + 11]] + y[n[t + 12]] + y[n[t + 13]] + y[n[t + 14]] + y[n[t + 15]]).toLowerCase();
1719
+ return (b[n[t + 0]] + b[n[t + 1]] + b[n[t + 2]] + b[n[t + 3]] + "-" + b[n[t + 4]] + b[n[t + 5]] + "-" + b[n[t + 6]] + b[n[t + 7]] + "-" + b[n[t + 8]] + b[n[t + 9]] + "-" + b[n[t + 10]] + b[n[t + 11]] + b[n[t + 12]] + b[n[t + 13]] + b[n[t + 14]] + b[n[t + 15]]).toLowerCase();
1720
1720
  }
1721
1721
  let X;
1722
1722
  const sn = new Uint8Array(16);
@@ -1728,7 +1728,7 @@ function on() {
1728
1728
  }
1729
1729
  return X(sn);
1730
1730
  }
1731
- const an = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), me = { randomUUID: an };
1731
+ const an = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), ge = { randomUUID: an };
1732
1732
  function cn(n, t, e) {
1733
1733
  n = n || {};
1734
1734
  const r = n.random ?? n.rng?.() ?? on();
@@ -1737,9 +1737,9 @@ function cn(n, t, e) {
1737
1737
  return r[6] = r[6] & 15 | 64, r[8] = r[8] & 63 | 128, rn(r);
1738
1738
  }
1739
1739
  function De(n, t, e) {
1740
- return me.randomUUID && !n ? me.randomUUID() : cn(n);
1740
+ return ge.randomUUID && !n ? ge.randomUUID() : cn(n);
1741
1741
  }
1742
- class b {
1742
+ class y {
1743
1743
  messages = null;
1744
1744
  pendingConsent = null;
1745
1745
  constructor({ messages: t, pendingConsent: e = null }) {
@@ -1747,10 +1747,25 @@ class b {
1747
1747
  }
1748
1748
  pushMessage(t) {
1749
1749
  const e = new Map(this.messages);
1750
- return e.set(t.messageId, t), new b({ messages: e, pendingConsent: this.pendingConsent });
1750
+ return e.set(t.messageId, t), new y({ messages: e, pendingConsent: this.pendingConsent });
1751
1751
  }
1752
1752
  clearPendingConsent() {
1753
- return this.pendingConsent ? new b({ messages: this.messages, pendingConsent: null }) : this;
1753
+ return this.pendingConsent ? new y({ messages: this.messages, pendingConsent: null }) : this;
1754
+ }
1755
+ /**
1756
+ * Converge every still-running tool-call to `cancelled` (F-020 AC10). Called when a user-initiated
1757
+ * stop-generation aborts the run: an in-flight tool-call (`isComplete === false`) would otherwise
1758
+ * linger as `running` forever, since its `tool_call.complete` frame never arrives. Already-settled
1759
+ * calls and non-tool-call messages are left untouched; content is preserved (never rolled back).
1760
+ * Returns the same instance when nothing is in flight.
1761
+ */
1762
+ cancelInFlightToolCalls() {
1763
+ if (!this.messages) return this;
1764
+ let t = !1;
1765
+ const e = new Map(this.messages);
1766
+ for (const [r, s] of e)
1767
+ s.type === "tool-call" && !s.isComplete && (e.set(r, { ...s, isComplete: !0, isCancelled: !0 }), t = !0);
1768
+ return t ? new y({ messages: e, pendingConsent: this.pendingConsent }) : this;
1754
1769
  }
1755
1770
  onMessage(t) {
1756
1771
  switch (t.eventType) {
@@ -1814,7 +1829,7 @@ class b {
1814
1829
  time: /* @__PURE__ */ new Date(),
1815
1830
  traceId: t.traceId,
1816
1831
  raw: ""
1817
- }), new b({ messages: r, pendingConsent: this.pendingConsent });
1832
+ }), new y({ messages: r, pendingConsent: this.pendingConsent });
1818
1833
  }
1819
1834
  onMessageDelta(t) {
1820
1835
  const e = t.fact.messageDelta.message, r = this.messages?.get(e.messageId);
@@ -1830,7 +1845,7 @@ class b {
1830
1845
  time: /* @__PURE__ */ new Date(),
1831
1846
  traceId: t.traceId ?? s?.traceId,
1832
1847
  raw: s?.raw ?? ""
1833
- }), new b({ messages: i, pendingConsent: this.pendingConsent });
1848
+ }), new y({ messages: i, pendingConsent: this.pendingConsent });
1834
1849
  }
1835
1850
  onMessageComplete(t) {
1836
1851
  const e = t.fact.messageComplete.message, r = new Map(this.messages), s = r.get(e.messageId);
@@ -1844,7 +1859,7 @@ class b {
1844
1859
  time: /* @__PURE__ */ new Date(),
1845
1860
  traceId: t.traceId ?? (s?.type === "bot" ? s.traceId : void 0),
1846
1861
  raw: JSON.stringify(t)
1847
- }), new b({ messages: r, pendingConsent: this.pendingConsent });
1862
+ }), new y({ messages: r, pendingConsent: this.pendingConsent });
1848
1863
  }
1849
1864
  onThinkingStart(t) {
1850
1865
  const e = t.fact.messageThinkingStart.message;
@@ -1857,7 +1872,7 @@ class b {
1857
1872
  time: /* @__PURE__ */ new Date(),
1858
1873
  traceId: t.traceId
1859
1874
  };
1860
- return r.set(e.messageId, s), new b({ messages: r, pendingConsent: this.pendingConsent });
1875
+ return r.set(e.messageId, s), new y({ messages: r, pendingConsent: this.pendingConsent });
1861
1876
  }
1862
1877
  onThinkingDelta(t) {
1863
1878
  const e = t.fact.messageThinkingDelta.message, r = this.messages?.get(e.messageId);
@@ -1870,7 +1885,7 @@ class b {
1870
1885
  time: s?.time ?? /* @__PURE__ */ new Date(),
1871
1886
  traceId: t.traceId ?? s?.traceId
1872
1887
  };
1873
- return i.set(e.messageId, o), new b({ messages: i, pendingConsent: this.pendingConsent });
1888
+ return i.set(e.messageId, o), new y({ messages: i, pendingConsent: this.pendingConsent });
1874
1889
  }
1875
1890
  onThinkingComplete(t) {
1876
1891
  const e = t.fact.messageThinkingComplete.message, r = this.messages?.get(e.messageId), s = r?.type === "thinking" ? r : void 0, i = new Map(this.messages), o = {
@@ -1883,7 +1898,7 @@ class b {
1883
1898
  time: s?.time ?? /* @__PURE__ */ new Date(),
1884
1899
  traceId: t.traceId ?? s?.traceId
1885
1900
  };
1886
- return i.set(e.messageId, o), new b({ messages: i, pendingConsent: this.pendingConsent });
1901
+ return i.set(e.messageId, o), new y({ messages: i, pendingConsent: this.pendingConsent });
1887
1902
  }
1888
1903
  onMessageUser(t) {
1889
1904
  const e = t.fact.messageUser;
@@ -1898,7 +1913,7 @@ class b {
1898
1913
  time: /* @__PURE__ */ new Date(),
1899
1914
  traceId: t.traceId
1900
1915
  };
1901
- return s.set(e.messageId, i), new b({ messages: s, pendingConsent: this.pendingConsent });
1916
+ return s.set(e.messageId, i), new y({ messages: s, pendingConsent: this.pendingConsent });
1902
1917
  }
1903
1918
  onMessageError(t) {
1904
1919
  const e = De(), r = t.fact.runError.error, s = new Map(this.messages);
@@ -1909,7 +1924,7 @@ class b {
1909
1924
  error: r,
1910
1925
  time: /* @__PURE__ */ new Date(),
1911
1926
  traceId: t.traceId
1912
- }), new b({ messages: s, pendingConsent: this.pendingConsent });
1927
+ }), new y({ messages: s, pendingConsent: this.pendingConsent });
1913
1928
  }
1914
1929
  onToolCallStart(t) {
1915
1930
  const e = t.fact.toolCallStart, r = new Map(this.messages), s = `${e.processId}-${e.callSeq}`, i = {
@@ -1928,7 +1943,7 @@ class b {
1928
1943
  time: /* @__PURE__ */ new Date(),
1929
1944
  traceId: t.traceId
1930
1945
  };
1931
- return r.set(s, i), new b({ messages: r, pendingConsent: this.pendingConsent });
1946
+ return r.set(s, i), new y({ messages: r, pendingConsent: this.pendingConsent });
1932
1947
  }
1933
1948
  onToolCallComplete(t) {
1934
1949
  const e = t.fact.toolCallComplete, r = new Map(this.messages), s = `${e.processId}-${e.callSeq}`, i = r.get(s);
@@ -1944,11 +1959,11 @@ class b {
1944
1959
  };
1945
1960
  r.set(s, o);
1946
1961
  }
1947
- return new b({ messages: r, pendingConsent: this.pendingConsent });
1962
+ return new y({ messages: r, pendingConsent: this.pendingConsent });
1948
1963
  }
1949
1964
  onToolCallConsent(t) {
1950
1965
  const e = t.fact.toolCallConsent;
1951
- return new b({ messages: this.messages, pendingConsent: e });
1966
+ return new y({ messages: this.messages, pendingConsent: e });
1952
1967
  }
1953
1968
  onSubagentStart(t) {
1954
1969
  const e = t.fact.subagentStart, r = new Map(this.messages), s = `subagent:${e.parentToolUseId}:start`, i = {
@@ -1962,7 +1977,7 @@ class b {
1962
1977
  time: /* @__PURE__ */ new Date(),
1963
1978
  traceId: t.traceId
1964
1979
  };
1965
- return r.set(s, i), new b({ messages: r, pendingConsent: this.pendingConsent });
1980
+ return r.set(s, i), new y({ messages: r, pendingConsent: this.pendingConsent });
1966
1981
  }
1967
1982
  onSubagentComplete(t) {
1968
1983
  const e = t.fact.subagentComplete, r = new Map(this.messages), s = `subagent:${e.parentToolUseId}:complete`, i = {
@@ -1977,14 +1992,14 @@ class b {
1977
1992
  time: /* @__PURE__ */ new Date(),
1978
1993
  traceId: t.traceId
1979
1994
  };
1980
- return r.set(s, i), new b({ messages: r, pendingConsent: this.pendingConsent });
1995
+ return r.set(s, i), new y({ messages: r, pendingConsent: this.pendingConsent });
1981
1996
  }
1982
1997
  }
1983
1998
  const un = /* @__PURE__ */ new Set(["TaskCreate", "TaskUpdate"]);
1984
1999
  function ln(n) {
1985
2000
  return n.toolsetName === "" && un.has(n.toolName);
1986
2001
  }
1987
- function ge(n) {
2002
+ function me(n) {
1988
2003
  return typeof n == "object" && n !== null ? n : void 0;
1989
2004
  }
1990
2005
  function E(n) {
@@ -1995,7 +2010,7 @@ function dn(n) {
1995
2010
  for (const r of n) {
1996
2011
  const s = r.parameter ?? {}, i = r.sidecar ?? {};
1997
2012
  if (r.toolName === "TaskCreate") {
1998
- const o = ge(i.task), a = E(o?.id);
2013
+ const o = me(i.task), a = E(o?.id);
1999
2014
  if (!a) continue;
2000
2015
  e.has(a) || t.push(a), e.set(a, {
2001
2016
  id: a,
@@ -2006,7 +2021,7 @@ function dn(n) {
2006
2021
  // initial status = pending (keep existing on repeat)
2007
2022
  });
2008
2023
  } else if (r.toolName === "TaskUpdate") {
2009
- const o = ge(i.statusChange), a = E(s.taskId) || E(i.taskId), u = E(o?.to) || E(s.status);
2024
+ const o = me(i.statusChange), a = E(s.taskId) || E(i.taskId), u = E(o?.to) || E(s.status);
2010
2025
  if (!a || !u) continue;
2011
2026
  const c = e.get(a);
2012
2027
  c && e.set(a, { ...c, status: u });
@@ -2061,17 +2076,17 @@ function pn(n) {
2061
2076
  tools: Array.from(r.get(i).values())
2062
2077
  }));
2063
2078
  }
2064
- function mn(n) {
2079
+ function gn(n) {
2065
2080
  return typeof n == "string" ? n : void 0;
2066
2081
  }
2067
- function gn(n) {
2082
+ function mn(n) {
2068
2083
  const t = [];
2069
2084
  for (const e of n) {
2070
2085
  if (e.type === "tool-call" && hn(e)) {
2071
2086
  t.push({
2072
2087
  kind: "agentStart",
2073
2088
  toolUseId: e.toolUseId ?? e.messageId,
2074
- description: mn(e.parameter.description)
2089
+ description: gn(e.parameter.description)
2075
2090
  });
2076
2091
  continue;
2077
2092
  }
@@ -2119,7 +2134,7 @@ function vn(n) {
2119
2134
  return dn(t);
2120
2135
  }
2121
2136
  function yn(n) {
2122
- return pn(gn(Array.from(n.messages?.values() ?? [])));
2137
+ return pn(mn(Array.from(n.messages?.values() ?? [])));
2123
2138
  }
2124
2139
  function bn(n, t) {
2125
2140
  return n === t ? !0 : n.length !== t.length ? !1 : n.every((e, r) => {
@@ -2274,7 +2289,7 @@ class K {
2274
2289
  o && o.type === "user" && (i.set(this.currentUserMessageId, {
2275
2290
  ...o,
2276
2291
  traceId: s.traceId
2277
- }), this.conversation$.next(new b({ messages: i }))), this.currentUserMessageId = void 0;
2292
+ }), this.conversation$.next(new y({ messages: i }))), this.currentUserMessageId = void 0;
2278
2293
  }
2279
2294
  this.conversation$.next(this.conversation$.value.onMessage(s));
2280
2295
  },
@@ -2362,7 +2377,7 @@ class K {
2362
2377
  * when nothing is running.
2363
2378
  */
2364
2379
  stopGeneration() {
2365
- this.currentRun && (this.currentRun.unsubscribe(), this.currentRun = void 0, this.isConnecting$.next(!1), this.currentUserMessageId = void 0);
2380
+ this.currentRun && (this.currentRun.unsubscribe(), this.currentRun = void 0, this.isConnecting$.next(!1), this.currentUserMessageId = void 0, this.conversation$.next(this.conversation$.value.cancelInFlightToolCalls()));
2366
2381
  }
2367
2382
  close() {
2368
2383
  this.currentRun?.unsubscribe(), this.currentRun = void 0, this.isConnecting$.complete(), this.conversation$.complete(), this.channelTitleSubject.complete(), this.derivedStores.teardown(), this.statesSubscription?.unsubscribe();
@@ -2371,13 +2386,13 @@ class K {
2371
2386
  export {
2372
2387
  Tn as AsgardServiceClient,
2373
2388
  K as Channel,
2374
- b as Conversation,
2389
+ y as Conversation,
2375
2390
  d as EventType,
2376
2391
  H as FetchSseAction,
2377
2392
  te as HttpError,
2378
2393
  Fe as MessageTemplateType,
2379
2394
  Ke as ToolCallConsentResult,
2380
- gn as conversationToSubagentEvents,
2395
+ mn as conversationToSubagentEvents,
2381
2396
  En as createDerivedStores,
2382
2397
  yn as deriveSubagents,
2383
2398
  vn as deriveTasks,