@asgard-js/core 0.3.25 → 0.3.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,25 +1,45 @@
1
1
  class w extends Error {
2
2
  status;
3
3
  statusText;
4
+ /**
5
+ * The decoded error payload, when the response carried one.
6
+ *
7
+ * Consumers branch on this — `asgard-ai-data-insight-web` reads `reason_code` off it to raise its
8
+ * credit-limit dialog on a `429` — so **always pass it when constructing from a real response**,
9
+ * even though the parameter is optional.
10
+ */
4
11
  body;
12
+ // `body` is optional because every construction site derives it from a response whose text or JSON
13
+ // may fail to parse, yielding `undefined` or `null`. An absent body is therefore a normal outcome
14
+ // rather than a caller mistake, and a test raising a status-only error need not pass a filler value.
5
15
  constructor(t, e, r) {
6
16
  super(`HTTP ${t}: ${e}`), this.name = "HttpError", this.status = t, this.statusText = e, this.body = r;
7
17
  }
8
18
  }
9
- function Tn(n) {
19
+ function An(n) {
10
20
  return n instanceof w;
11
21
  }
12
- var $ = /* @__PURE__ */ ((n) => (n.RESET_CHANNEL = "RESET_CHANNEL", n.NONE = "NONE", n.RESPONSE_TOOL_CALL_CONSENT = "RESPONSE_TOOL_CALL_CONSENT", n.NUDGE = "NUDGE", n))($ || {}), 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.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.SANDBOX_LAUNCH = "asgard.sandbox.launch", n.SANDBOX_READY = "asgard.sandbox.ready", n.DONE = "asgard.run.done", n.ERROR = "asgard.run.error", n))(d || {}), Ke = /* @__PURE__ */ ((n) => (n.ALLOW_ONCE = "ALLOW_ONCE", n.ALLOW_ALWAYS = "ALLOW_ALWAYS", n.DENY_ONCE = "DENY_ONCE", n))(Ke || {}), qe = /* @__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))(qe || {});
13
- async function Ye(n, t) {
22
+ class ye extends Error {
23
+ /** Which run is holding the channel. */
24
+ runKind;
25
+ constructor(t) {
26
+ super(`Cannot send a message while a "${t}" run is in flight on this channel.`), this.name = "ChannelBusyError", this.runKind = t;
27
+ }
28
+ }
29
+ function Pn(n) {
30
+ return n instanceof ye;
31
+ }
32
+ var $ = /* @__PURE__ */ ((n) => (n.RESET_CHANNEL = "RESET_CHANNEL", n.NONE = "NONE", n.RESPONSE_TOOL_CALL_CONSENT = "RESPONSE_TOOL_CALL_CONSENT", n.NUDGE = "NUDGE", n))($ || {}), l = /* @__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.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.SANDBOX_LAUNCH = "asgard.sandbox.launch", n.SANDBOX_READY = "asgard.sandbox.ready", n.DONE = "asgard.run.done", n.ERROR = "asgard.run.error", n))(l || {}), Ye = /* @__PURE__ */ ((n) => (n.ALLOW_ONCE = "ALLOW_ONCE", n.ALLOW_ALWAYS = "ALLOW_ALWAYS", n.DENY_ONCE = "DENY_ONCE", n))(Ye || {}), We = /* @__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))(We || {});
33
+ async function Xe(n, t) {
14
34
  const e = n.getReader();
15
35
  let r;
16
36
  for (; !(r = await e.read()).done; )
17
37
  t(r.value);
18
38
  }
19
- function Xe(n) {
39
+ function Ve(n) {
20
40
  let t, e, r, s = !1;
21
41
  return function(i) {
22
- t === void 0 ? (t = i, e = 0, r = -1) : t = We(t, i);
42
+ t === void 0 ? (t = i, e = 0, r = -1) : t = Je(t, i);
23
43
  const a = t.length;
24
44
  let c = 0;
25
45
  for (; e < a; ) {
@@ -43,12 +63,12 @@ function Xe(n) {
43
63
  c === a ? t = void 0 : c !== 0 && (t = t.subarray(c), e -= c);
44
64
  };
45
65
  }
46
- function Ve(n, t, e) {
47
- let r = ie();
66
+ function ze(n, t, e) {
67
+ let r = ae();
48
68
  const s = new TextDecoder();
49
69
  return function(i, a) {
50
70
  if (i.length === 0)
51
- e?.(r), r = ie();
71
+ e?.(r), r = ae();
52
72
  else if (a > 0) {
53
73
  const c = s.decode(i.subarray(0, a)), u = a + (i[a + 1] === 32 ? 2 : 1), h = s.decode(i.subarray(u));
54
74
  switch (c) {
@@ -70,11 +90,11 @@ function Ve(n, t, e) {
70
90
  }
71
91
  };
72
92
  }
73
- function We(n, t) {
93
+ function Je(n, t) {
74
94
  const e = new Uint8Array(n.length + t.length);
75
95
  return e.set(n), e.set(t, n.length), e;
76
96
  }
77
- function ie() {
97
+ function ae() {
78
98
  return {
79
99
  data: "",
80
100
  event: "",
@@ -82,7 +102,7 @@ function ie() {
82
102
  retry: void 0
83
103
  };
84
104
  }
85
- var ze = function(n, t) {
105
+ var Qe = function(n, t) {
86
106
  var e = {};
87
107
  for (var r in n) Object.prototype.hasOwnProperty.call(n, r) && t.indexOf(r) < 0 && (e[r] = n[r]);
88
108
  if (n != null && typeof Object.getOwnPropertySymbols == "function")
@@ -90,70 +110,70 @@ var ze = function(n, t) {
90
110
  t.indexOf(r[s]) < 0 && Object.prototype.propertyIsEnumerable.call(n, r[s]) && (e[r[s]] = n[r[s]]);
91
111
  return e;
92
112
  };
93
- const Q = "text/event-stream", Je = 1e3, ae = "last-event-id";
94
- function ve(n, t) {
95
- var { signal: e, headers: r, onopen: s, onmessage: o, onclose: i, onerror: a, openWhenHidden: c, fetch: u } = t, h = ze(t, ["signal", "headers", "onopen", "onmessage", "onclose", "onerror", "openWhenHidden", "fetch"]);
113
+ const Z = "text/event-stream", Ze = 1e3, ce = "last-event-id";
114
+ function Se(n, t) {
115
+ var { signal: e, headers: r, onopen: s, onmessage: o, onclose: i, onerror: a, openWhenHidden: c, fetch: u } = t, h = Qe(t, ["signal", "headers", "onopen", "onmessage", "onclose", "onerror", "openWhenHidden", "fetch"]);
96
116
  return new Promise((m, b) => {
97
- const l = Object.assign({}, r);
98
- l.accept || (l.accept = Q);
99
- let f;
100
- function p() {
101
- f.abort(), document.hidden || V();
117
+ const d = Object.assign({}, r);
118
+ d.accept || (d.accept = Z);
119
+ let p;
120
+ function f() {
121
+ p.abort(), document.hidden || X();
102
122
  }
103
- c || document.addEventListener("visibilitychange", p);
104
- let L = Je, E = 0;
105
- function _() {
106
- document.removeEventListener("visibilitychange", p), window.clearTimeout(E), f.abort();
123
+ c || document.addEventListener("visibilitychange", f);
124
+ let _ = Ze, E = 0;
125
+ function L() {
126
+ document.removeEventListener("visibilitychange", f), window.clearTimeout(E), p.abort();
107
127
  }
108
128
  e?.addEventListener("abort", () => {
109
- _(), m();
129
+ L(), m();
110
130
  });
111
- const Ge = u ?? window.fetch, Be = s ?? Qe;
112
- async function V() {
113
- var W;
114
- f = new AbortController();
131
+ const Ke = u ?? window.fetch, qe = s ?? et;
132
+ async function X() {
133
+ var V;
134
+ p = new AbortController();
115
135
  try {
116
- const F = await Ge(n, Object.assign(Object.assign({}, h), { headers: l, signal: f.signal }));
117
- await Be(F), await Ye(F.body, Xe(Ve((x) => {
118
- x ? l[ae] = x : delete l[ae];
136
+ const H = await Ke(n, Object.assign(Object.assign({}, h), { headers: d, signal: p.signal }));
137
+ await qe(H), await Xe(H.body, Ve(ze((x) => {
138
+ x ? d[ce] = x : delete d[ce];
119
139
  }, (x) => {
120
- L = x;
121
- }, o))), i?.(), _(), m();
122
- } catch (F) {
123
- if (!f.signal.aborted)
140
+ _ = x;
141
+ }, o))), i?.(), L(), m();
142
+ } catch (H) {
143
+ if (!p.signal.aborted)
124
144
  try {
125
- const x = (W = a?.(F)) !== null && W !== void 0 ? W : L;
126
- window.clearTimeout(E), E = window.setTimeout(V, x);
145
+ const x = (V = a?.(H)) !== null && V !== void 0 ? V : _;
146
+ window.clearTimeout(E), E = window.setTimeout(X, x);
127
147
  } catch (x) {
128
- _(), b(x);
148
+ L(), b(x);
129
149
  }
130
150
  }
131
151
  }
132
- V();
152
+ X();
133
153
  });
134
154
  }
135
- function Qe(n) {
155
+ function et(n) {
136
156
  const t = n.headers.get("content-type");
137
- if (!t?.startsWith(Q))
138
- throw new Error(`Expected content-type to be ${Q}, Actual: ${t}`);
157
+ if (!t?.startsWith(Z))
158
+ throw new Error(`Expected content-type to be ${Z}, Actual: ${t}`);
139
159
  }
140
- var Z = function(n, t) {
141
- return Z = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(e, r) {
160
+ var ee = function(n, t) {
161
+ return ee = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(e, r) {
142
162
  e.__proto__ = r;
143
163
  } || function(e, r) {
144
164
  for (var s in r) Object.prototype.hasOwnProperty.call(r, s) && (e[s] = r[s]);
145
- }, Z(n, t);
165
+ }, ee(n, t);
146
166
  };
147
167
  function T(n, t) {
148
168
  if (typeof t != "function" && t !== null)
149
169
  throw new TypeError("Class extends value " + String(t) + " is not a constructor or null");
150
- Z(n, t);
170
+ ee(n, t);
151
171
  function e() {
152
172
  this.constructor = n;
153
173
  }
154
174
  n.prototype = t === null ? Object.create(t) : (e.prototype = t.prototype, new e());
155
175
  }
156
- function Ze(n, t, e, r) {
176
+ function tt(n, t, e, r) {
157
177
  function s(o) {
158
178
  return o instanceof e ? o : new e(function(i) {
159
179
  i(o);
@@ -180,7 +200,7 @@ function Ze(n, t, e, r) {
180
200
  u((r = r.apply(n, t || [])).next());
181
201
  });
182
202
  }
183
- function ye(n, t) {
203
+ function we(n, t) {
184
204
  var e = { label: 0, sent: function() {
185
205
  if (o[0] & 1) throw o[1];
186
206
  return o[1];
@@ -240,7 +260,7 @@ function ye(n, t) {
240
260
  return { value: u[0] ? u[1] : void 0, done: !0 };
241
261
  }
242
262
  }
243
- function k(n) {
263
+ function R(n) {
244
264
  var t = typeof Symbol == "function" && Symbol.iterator, e = t && n[t], r = 0;
245
265
  if (e) return e.call(n);
246
266
  if (n && typeof n.length == "number") return {
@@ -267,56 +287,56 @@ function D(n, t) {
267
287
  }
268
288
  return o;
269
289
  }
270
- function H(n, t, e) {
290
+ function F(n, t, e) {
271
291
  if (e || arguments.length === 2) for (var r = 0, s = t.length, o; r < s; r++)
272
292
  (o || !(r in t)) && (o || (o = Array.prototype.slice.call(t, 0, r)), o[r] = t[r]);
273
293
  return n.concat(o || Array.prototype.slice.call(t));
274
294
  }
275
- function M(n) {
276
- return this instanceof M ? (this.v = n, this) : new M(n);
295
+ function k(n) {
296
+ return this instanceof k ? (this.v = n, this) : new k(n);
277
297
  }
278
- function et(n, t, e) {
298
+ function nt(n, t, e) {
279
299
  if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
280
300
  var r = e.apply(n, t || []), s, o = [];
281
301
  return s = Object.create((typeof AsyncIterator == "function" ? AsyncIterator : Object).prototype), a("next"), a("throw"), a("return", i), s[Symbol.asyncIterator] = function() {
282
302
  return this;
283
303
  }, s;
284
- function i(l) {
285
- return function(f) {
286
- return Promise.resolve(f).then(l, m);
304
+ function i(d) {
305
+ return function(p) {
306
+ return Promise.resolve(p).then(d, m);
287
307
  };
288
308
  }
289
- function a(l, f) {
290
- r[l] && (s[l] = function(p) {
291
- return new Promise(function(L, E) {
292
- o.push([l, p, L, E]) > 1 || c(l, p);
309
+ function a(d, p) {
310
+ r[d] && (s[d] = function(f) {
311
+ return new Promise(function(_, E) {
312
+ o.push([d, f, _, E]) > 1 || c(d, f);
293
313
  });
294
- }, f && (s[l] = f(s[l])));
314
+ }, p && (s[d] = p(s[d])));
295
315
  }
296
- function c(l, f) {
316
+ function c(d, p) {
297
317
  try {
298
- u(r[l](f));
299
- } catch (p) {
300
- b(o[0][3], p);
318
+ u(r[d](p));
319
+ } catch (f) {
320
+ b(o[0][3], f);
301
321
  }
302
322
  }
303
- function u(l) {
304
- l.value instanceof M ? Promise.resolve(l.value.v).then(h, m) : b(o[0][2], l);
323
+ function u(d) {
324
+ d.value instanceof k ? Promise.resolve(d.value.v).then(h, m) : b(o[0][2], d);
305
325
  }
306
- function h(l) {
307
- c("next", l);
326
+ function h(d) {
327
+ c("next", d);
308
328
  }
309
- function m(l) {
310
- c("throw", l);
329
+ function m(d) {
330
+ c("throw", d);
311
331
  }
312
- function b(l, f) {
313
- l(f), o.shift(), o.length && c(o[0][0], o[0][1]);
332
+ function b(d, p) {
333
+ d(p), o.shift(), o.length && c(o[0][0], o[0][1]);
314
334
  }
315
335
  }
316
- function tt(n) {
336
+ function rt(n) {
317
337
  if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
318
338
  var t = n[Symbol.asyncIterator], e;
319
- return t ? t.call(n) : (n = typeof k == "function" ? k(n) : n[Symbol.iterator](), e = {}, r("next"), r("throw"), r("return"), e[Symbol.asyncIterator] = function() {
339
+ return t ? t.call(n) : (n = typeof R == "function" ? R(n) : n[Symbol.iterator](), e = {}, r("next"), r("throw"), r("return"), e[Symbol.asyncIterator] = function() {
320
340
  return this;
321
341
  }, e);
322
342
  function r(o) {
@@ -335,13 +355,13 @@ function tt(n) {
335
355
  function g(n) {
336
356
  return typeof n == "function";
337
357
  }
338
- function Se(n) {
358
+ function Ee(n) {
339
359
  var t = function(r) {
340
360
  Error.call(r), r.stack = new Error().stack;
341
361
  }, e = n(t);
342
362
  return e.prototype = Object.create(Error.prototype), e.prototype.constructor = e, e;
343
363
  }
344
- var z = Se(function(n) {
364
+ var z = Ee(function(n) {
345
365
  return function(e) {
346
366
  n(this), this.message = e ? e.length + ` errors occurred during unsubscription:
347
367
  ` + e.map(function(r, s) {
@@ -356,7 +376,7 @@ function q(n, t) {
356
376
  0 <= e && n.splice(e, 1);
357
377
  }
358
378
  }
359
- var R = (function() {
379
+ var j = (function() {
360
380
  function n(t) {
361
381
  this.initialTeardown = t, this.closed = !1, this._parentage = null, this._finalizers = null;
362
382
  }
@@ -368,12 +388,12 @@ var R = (function() {
368
388
  if (i)
369
389
  if (this._parentage = null, Array.isArray(i))
370
390
  try {
371
- for (var a = k(i), c = a.next(); !c.done; c = a.next()) {
391
+ for (var a = R(i), c = a.next(); !c.done; c = a.next()) {
372
392
  var u = c.value;
373
393
  u.remove(this);
374
394
  }
375
- } catch (p) {
376
- t = { error: p };
395
+ } catch (f) {
396
+ t = { error: f };
377
397
  } finally {
378
398
  try {
379
399
  c && !c.done && (e = a.return) && e.call(a);
@@ -387,26 +407,26 @@ var R = (function() {
387
407
  if (g(h))
388
408
  try {
389
409
  h();
390
- } catch (p) {
391
- o = p instanceof z ? p.errors : [p];
410
+ } catch (f) {
411
+ o = f instanceof z ? f.errors : [f];
392
412
  }
393
413
  var m = this._finalizers;
394
414
  if (m) {
395
415
  this._finalizers = null;
396
416
  try {
397
- for (var b = k(m), l = b.next(); !l.done; l = b.next()) {
398
- var f = l.value;
417
+ for (var b = R(m), d = b.next(); !d.done; d = b.next()) {
418
+ var p = d.value;
399
419
  try {
400
- ce(f);
401
- } catch (p) {
402
- o = o ?? [], p instanceof z ? o = H(H([], D(o)), D(p.errors)) : o.push(p);
420
+ ue(p);
421
+ } catch (f) {
422
+ o = o ?? [], f instanceof z ? o = F(F([], D(o)), D(f.errors)) : o.push(f);
403
423
  }
404
424
  }
405
- } catch (p) {
406
- r = { error: p };
425
+ } catch (f) {
426
+ r = { error: f };
407
427
  } finally {
408
428
  try {
409
- l && !l.done && (s = b.return) && s.call(b);
429
+ d && !d.done && (s = b.return) && s.call(b);
410
430
  } finally {
411
431
  if (r) throw r.error;
412
432
  }
@@ -419,7 +439,7 @@ var R = (function() {
419
439
  var e;
420
440
  if (t && t !== this)
421
441
  if (this.closed)
422
- ce(t);
442
+ ue(t);
423
443
  else {
424
444
  if (t instanceof n) {
425
445
  if (t.closed || t._hasParent(this))
@@ -444,44 +464,44 @@ var R = (function() {
444
464
  var t = new n();
445
465
  return t.closed = !0, t;
446
466
  })(), n;
447
- })(), we = R.EMPTY;
448
- function Ee(n) {
449
- return n instanceof R || n && "closed" in n && g(n.remove) && g(n.add) && g(n.unsubscribe);
467
+ })(), Ie = j.EMPTY;
468
+ function Te(n) {
469
+ return n instanceof j || n && "closed" in n && g(n.remove) && g(n.add) && g(n.unsubscribe);
450
470
  }
451
- function ce(n) {
471
+ function ue(n) {
452
472
  g(n) ? n() : n.unsubscribe();
453
473
  }
454
- var nt = {
474
+ var st = {
455
475
  Promise: void 0
456
- }, rt = {
476
+ }, ot = {
457
477
  setTimeout: function(n, t) {
458
478
  for (var e = [], r = 2; r < arguments.length; r++)
459
479
  e[r - 2] = arguments[r];
460
- return setTimeout.apply(void 0, H([n, t], D(e)));
480
+ return setTimeout.apply(void 0, F([n, t], D(e)));
461
481
  },
462
482
  clearTimeout: function(n) {
463
483
  return clearTimeout(n);
464
484
  },
465
485
  delegate: void 0
466
486
  };
467
- function Ie(n) {
468
- rt.setTimeout(function() {
487
+ function xe(n) {
488
+ ot.setTimeout(function() {
469
489
  throw n;
470
490
  });
471
491
  }
472
- function ee() {
492
+ function te() {
473
493
  }
474
- function B(n) {
494
+ function G(n) {
475
495
  n();
476
496
  }
477
- var ne = (function(n) {
497
+ var re = (function(n) {
478
498
  T(t, n);
479
499
  function t(e) {
480
500
  var r = n.call(this) || this;
481
- return r.isStopped = !1, e ? (r.destination = e, Ee(e) && e.add(r)) : r.destination = it, r;
501
+ return r.isStopped = !1, e ? (r.destination = e, Te(e) && e.add(r)) : r.destination = ct, r;
482
502
  }
483
503
  return t.create = function(e, r, s) {
484
- return new te(e, r, s);
504
+ return new ne(e, r, s);
485
505
  }, t.prototype.next = function(e) {
486
506
  this.isStopped || this._next(e);
487
507
  }, t.prototype.error = function(e) {
@@ -505,7 +525,7 @@ var ne = (function(n) {
505
525
  this.unsubscribe();
506
526
  }
507
527
  }, t;
508
- })(R), st = (function() {
528
+ })(j), it = (function() {
509
529
  function n(t) {
510
530
  this.partialObserver = t;
511
531
  }
@@ -515,7 +535,7 @@ var ne = (function(n) {
515
535
  try {
516
536
  e.next(t);
517
537
  } catch (r) {
518
- G(r);
538
+ B(r);
519
539
  }
520
540
  }, n.prototype.error = function(t) {
521
541
  var e = this.partialObserver;
@@ -523,20 +543,20 @@ var ne = (function(n) {
523
543
  try {
524
544
  e.error(t);
525
545
  } catch (r) {
526
- G(r);
546
+ B(r);
527
547
  }
528
548
  else
529
- G(t);
549
+ B(t);
530
550
  }, n.prototype.complete = function() {
531
551
  var t = this.partialObserver;
532
552
  if (t.complete)
533
553
  try {
534
554
  t.complete();
535
555
  } catch (e) {
536
- G(e);
556
+ B(e);
537
557
  }
538
558
  }, n;
539
- })(), te = (function(n) {
559
+ })(), ne = (function(n) {
540
560
  T(t, n);
541
561
  function t(e, r, s) {
542
562
  var o = n.call(this) || this, i;
@@ -544,29 +564,29 @@ var ne = (function(n) {
544
564
  next: e ?? void 0,
545
565
  error: r ?? void 0,
546
566
  complete: s ?? void 0
547
- } : i = e, o.destination = new st(i), o;
567
+ } : i = e, o.destination = new it(i), o;
548
568
  }
549
569
  return t;
550
- })(ne);
551
- function G(n) {
552
- Ie(n);
570
+ })(re);
571
+ function B(n) {
572
+ xe(n);
553
573
  }
554
- function ot(n) {
574
+ function at(n) {
555
575
  throw n;
556
576
  }
557
- var it = {
577
+ var ct = {
558
578
  closed: !0,
559
- next: ee,
560
- error: ot,
561
- complete: ee
562
- }, re = (function() {
579
+ next: te,
580
+ error: at,
581
+ complete: te
582
+ }, se = (function() {
563
583
  return typeof Symbol == "function" && Symbol.observable || "@@observable";
564
584
  })();
565
- function X(n) {
585
+ function W(n) {
566
586
  return n;
567
587
  }
568
- function at(n) {
569
- return n.length === 0 ? X : n.length === 1 ? n[0] : function(e) {
588
+ function ut(n) {
589
+ return n.length === 0 ? W : n.length === 1 ? n[0] : function(e) {
570
590
  return n.reduce(function(r, s) {
571
591
  return s(r);
572
592
  }, e);
@@ -580,8 +600,8 @@ var S = (function() {
580
600
  var e = new n();
581
601
  return e.source = this, e.operator = t, e;
582
602
  }, n.prototype.subscribe = function(t, e, r) {
583
- var s = this, o = ut(t) ? t : new te(t, e, r);
584
- return B(function() {
603
+ var s = this, o = dt(t) ? t : new ne(t, e, r);
604
+ return G(function() {
585
605
  var i = s, a = i.operator, c = i.source;
586
606
  o.add(a ? a.call(o, c) : c ? s._subscribe(o) : s._trySubscribe(o));
587
607
  }), o;
@@ -593,8 +613,8 @@ var S = (function() {
593
613
  }
594
614
  }, n.prototype.forEach = function(t, e) {
595
615
  var r = this;
596
- return e = ue(e), new e(function(s, o) {
597
- var i = new te({
616
+ return e = le(e), new e(function(s, o) {
617
+ var i = new ne({
598
618
  next: function(a) {
599
619
  try {
600
620
  t(a);
@@ -610,15 +630,15 @@ var S = (function() {
610
630
  }, n.prototype._subscribe = function(t) {
611
631
  var e;
612
632
  return (e = this.source) === null || e === void 0 ? void 0 : e.subscribe(t);
613
- }, n.prototype[re] = function() {
633
+ }, n.prototype[se] = function() {
614
634
  return this;
615
635
  }, n.prototype.pipe = function() {
616
636
  for (var t = [], e = 0; e < arguments.length; e++)
617
637
  t[e] = arguments[e];
618
- return at(t)(this);
638
+ return ut(t)(this);
619
639
  }, n.prototype.toPromise = function(t) {
620
640
  var e = this;
621
- return t = ue(t), new t(function(r, s) {
641
+ return t = le(t), new t(function(r, s) {
622
642
  var o;
623
643
  e.subscribe(function(i) {
624
644
  return o = i;
@@ -632,22 +652,22 @@ var S = (function() {
632
652
  return new n(t);
633
653
  }, n;
634
654
  })();
635
- function ue(n) {
655
+ function le(n) {
636
656
  var t;
637
- return (t = n ?? nt.Promise) !== null && t !== void 0 ? t : Promise;
657
+ return (t = n ?? st.Promise) !== null && t !== void 0 ? t : Promise;
638
658
  }
639
- function ct(n) {
659
+ function lt(n) {
640
660
  return n && g(n.next) && g(n.error) && g(n.complete);
641
661
  }
642
- function ut(n) {
643
- return n && n instanceof ne || ct(n) && Ee(n);
662
+ function dt(n) {
663
+ return n && n instanceof re || lt(n) && Te(n);
644
664
  }
645
- function lt(n) {
665
+ function ht(n) {
646
666
  return g(n?.lift);
647
667
  }
648
- function A(n) {
668
+ function P(n) {
649
669
  return function(t) {
650
- if (lt(t))
670
+ if (ht(t))
651
671
  return t.lift(function(e) {
652
672
  try {
653
673
  return n(e, this);
@@ -658,10 +678,10 @@ function A(n) {
658
678
  throw new TypeError("Unable to lift unknown Observable type");
659
679
  };
660
680
  }
661
- function O(n, t, e, r, s) {
662
- return new dt(n, t, e, r, s);
681
+ function A(n, t, e, r, s) {
682
+ return new ft(n, t, e, r, s);
663
683
  }
664
- var dt = (function(n) {
684
+ var ft = (function(n) {
665
685
  T(t, n);
666
686
  function t(e, r, s, o, i, a) {
667
687
  var c = n.call(this, e) || this;
@@ -696,30 +716,30 @@ var dt = (function(n) {
696
716
  n.prototype.unsubscribe.call(this), !r && ((e = this.onFinalize) === null || e === void 0 || e.call(this));
697
717
  }
698
718
  }, t;
699
- })(ne), ht = Se(function(n) {
719
+ })(re), pt = Ee(function(n) {
700
720
  return function() {
701
721
  n(this), this.name = "ObjectUnsubscribedError", this.message = "object unsubscribed";
702
722
  };
703
- }), se = (function(n) {
723
+ }), oe = (function(n) {
704
724
  T(t, n);
705
725
  function t() {
706
726
  var e = n.call(this) || this;
707
727
  return e.closed = !1, e.currentObservers = null, e.observers = [], e.isStopped = !1, e.hasError = !1, e.thrownError = null, e;
708
728
  }
709
729
  return t.prototype.lift = function(e) {
710
- var r = new le(this, this);
730
+ var r = new de(this, this);
711
731
  return r.operator = e, r;
712
732
  }, t.prototype._throwIfClosed = function() {
713
733
  if (this.closed)
714
- throw new ht();
734
+ throw new pt();
715
735
  }, t.prototype.next = function(e) {
716
736
  var r = this;
717
- B(function() {
737
+ G(function() {
718
738
  var s, o;
719
739
  if (r._throwIfClosed(), !r.isStopped) {
720
740
  r.currentObservers || (r.currentObservers = Array.from(r.observers));
721
741
  try {
722
- for (var i = k(r.currentObservers), a = i.next(); !a.done; a = i.next()) {
742
+ for (var i = R(r.currentObservers), a = i.next(); !a.done; a = i.next()) {
723
743
  var c = a.value;
724
744
  c.next(e);
725
745
  }
@@ -736,7 +756,7 @@ var dt = (function(n) {
736
756
  });
737
757
  }, t.prototype.error = function(e) {
738
758
  var r = this;
739
- B(function() {
759
+ G(function() {
740
760
  if (r._throwIfClosed(), !r.isStopped) {
741
761
  r.hasError = r.isStopped = !0, r.thrownError = e;
742
762
  for (var s = r.observers; s.length; )
@@ -745,7 +765,7 @@ var dt = (function(n) {
745
765
  });
746
766
  }, t.prototype.complete = function() {
747
767
  var e = this;
748
- B(function() {
768
+ G(function() {
749
769
  if (e._throwIfClosed(), !e.isStopped) {
750
770
  e.isStopped = !0;
751
771
  for (var r = e.observers; r.length; )
@@ -767,7 +787,7 @@ var dt = (function(n) {
767
787
  return this._throwIfClosed(), this._checkFinalizedStatuses(e), this._innerSubscribe(e);
768
788
  }, t.prototype._innerSubscribe = function(e) {
769
789
  var r = this, s = this, o = s.hasError, i = s.isStopped, a = s.observers;
770
- return o || i ? we : (this.currentObservers = null, a.push(e), new R(function() {
790
+ return o || i ? Ie : (this.currentObservers = null, a.push(e), new j(function() {
771
791
  r.currentObservers = null, q(a, e);
772
792
  }));
773
793
  }, t.prototype._checkFinalizedStatuses = function(e) {
@@ -777,9 +797,9 @@ var dt = (function(n) {
777
797
  var e = new S();
778
798
  return e.source = this, e;
779
799
  }, t.create = function(e, r) {
780
- return new le(e, r);
800
+ return new de(e, r);
781
801
  }, t;
782
- })(S), le = (function(n) {
802
+ })(S), de = (function(n) {
783
803
  T(t, n);
784
804
  function t(e, r) {
785
805
  var s = n.call(this) || this;
@@ -796,9 +816,9 @@ var dt = (function(n) {
796
816
  (r = (e = this.destination) === null || e === void 0 ? void 0 : e.complete) === null || r === void 0 || r.call(e);
797
817
  }, t.prototype._subscribe = function(e) {
798
818
  var r, s;
799
- return (s = (r = this.source) === null || r === void 0 ? void 0 : r.subscribe(e)) !== null && s !== void 0 ? s : we;
819
+ return (s = (r = this.source) === null || r === void 0 ? void 0 : r.subscribe(e)) !== null && s !== void 0 ? s : Ie;
800
820
  }, t;
801
- })(se), P = (function(n) {
821
+ })(oe), C = (function(n) {
802
822
  T(t, n);
803
823
  function t(e) {
804
824
  var r = n.call(this) || this;
@@ -821,11 +841,11 @@ var dt = (function(n) {
821
841
  }, t.prototype.next = function(e) {
822
842
  n.prototype.next.call(this, this._value = e);
823
843
  }, t;
824
- })(se), ft = {
844
+ })(oe), mt = {
825
845
  now: function() {
826
846
  return Date.now();
827
847
  }
828
- }, pt = (function(n) {
848
+ }, gt = (function(n) {
829
849
  T(t, n);
830
850
  function t(e, r) {
831
851
  return n.call(this) || this;
@@ -833,17 +853,17 @@ var dt = (function(n) {
833
853
  return t.prototype.schedule = function(e, r) {
834
854
  return this;
835
855
  }, t;
836
- })(R), de = {
856
+ })(j), he = {
837
857
  setInterval: function(n, t) {
838
858
  for (var e = [], r = 2; r < arguments.length; r++)
839
859
  e[r - 2] = arguments[r];
840
- return setInterval.apply(void 0, H([n, t], D(e)));
860
+ return setInterval.apply(void 0, F([n, t], D(e)));
841
861
  },
842
862
  clearInterval: function(n) {
843
863
  return clearInterval(n);
844
864
  },
845
865
  delegate: void 0
846
- }, mt = (function(n) {
866
+ }, bt = (function(n) {
847
867
  T(t, n);
848
868
  function t(e, r) {
849
869
  var s = n.call(this, e, r) || this;
@@ -857,11 +877,11 @@ var dt = (function(n) {
857
877
  var o = this.id, i = this.scheduler;
858
878
  return o != null && (this.id = this.recycleAsyncId(i, o, r)), this.pending = !0, this.delay = r, this.id = (s = this.id) !== null && s !== void 0 ? s : this.requestAsyncId(i, this.id, r), this;
859
879
  }, t.prototype.requestAsyncId = function(e, r, s) {
860
- return s === void 0 && (s = 0), de.setInterval(e.flush.bind(e, this), s);
880
+ return s === void 0 && (s = 0), he.setInterval(e.flush.bind(e, this), s);
861
881
  }, t.prototype.recycleAsyncId = function(e, r, s) {
862
882
  if (s === void 0 && (s = 0), s != null && this.delay === s && this.pending === !1)
863
883
  return r;
864
- r != null && de.clearInterval(r);
884
+ r != null && he.clearInterval(r);
865
885
  }, t.prototype.execute = function(e, r) {
866
886
  if (this.closed)
867
887
  return new Error("executing a cancelled action");
@@ -885,17 +905,17 @@ var dt = (function(n) {
885
905
  this.work = this.state = this.scheduler = null, this.pending = !1, q(o, this), r != null && (this.id = this.recycleAsyncId(s, r, null)), this.delay = null, n.prototype.unsubscribe.call(this);
886
906
  }
887
907
  }, t;
888
- })(pt), he = (function() {
908
+ })(gt), fe = (function() {
889
909
  function n(t, e) {
890
910
  e === void 0 && (e = n.now), this.schedulerActionCtor = t, this.now = e;
891
911
  }
892
912
  return n.prototype.schedule = function(t, e, r) {
893
913
  return e === void 0 && (e = 0), new this.schedulerActionCtor(this, t).schedule(r, e);
894
- }, n.now = ft.now, n;
895
- })(), gt = (function(n) {
914
+ }, n.now = mt.now, n;
915
+ })(), vt = (function(n) {
896
916
  T(t, n);
897
917
  function t(e, r) {
898
- r === void 0 && (r = he.now);
918
+ r === void 0 && (r = fe.now);
899
919
  var s = n.call(this, e, r) || this;
900
920
  return s.actions = [], s._active = !1, s;
901
921
  }
@@ -917,60 +937,60 @@ var dt = (function(n) {
917
937
  throw s;
918
938
  }
919
939
  }, t;
920
- })(he), Te = new gt(mt), bt = Te, vt = new S(function(n) {
940
+ })(fe), Ce = new vt(bt), yt = Ce, St = new S(function(n) {
921
941
  return n.complete();
922
942
  });
923
- function xe(n) {
943
+ function Oe(n) {
924
944
  return n && g(n.schedule);
925
945
  }
926
- function Ce(n) {
946
+ function Ae(n) {
927
947
  return n[n.length - 1];
928
948
  }
929
- function yt(n) {
930
- return g(Ce(n)) ? n.pop() : void 0;
949
+ function wt(n) {
950
+ return g(Ae(n)) ? n.pop() : void 0;
931
951
  }
932
- function Oe(n) {
933
- return xe(Ce(n)) ? n.pop() : void 0;
952
+ function Pe(n) {
953
+ return Oe(Ae(n)) ? n.pop() : void 0;
934
954
  }
935
- var Ae = (function(n) {
955
+ var _e = (function(n) {
936
956
  return n && typeof n.length == "number" && typeof n != "function";
937
957
  });
938
958
  function Le(n) {
939
959
  return g(n?.then);
940
960
  }
941
- function _e(n) {
942
- return g(n[re]);
961
+ function Ue(n) {
962
+ return g(n[se]);
943
963
  }
944
- function Pe(n) {
964
+ function Me(n) {
945
965
  return Symbol.asyncIterator && g(n?.[Symbol.asyncIterator]);
946
966
  }
947
- function Ue(n) {
967
+ function ke(n) {
948
968
  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.");
949
969
  }
950
- function St() {
970
+ function Et() {
951
971
  return typeof Symbol != "function" || !Symbol.iterator ? "@@iterator" : Symbol.iterator;
952
972
  }
953
- var Me = St();
954
- function ke(n) {
955
- return g(n?.[Me]);
956
- }
973
+ var Re = Et();
957
974
  function Ne(n) {
958
- return et(this, arguments, function() {
975
+ return g(n?.[Re]);
976
+ }
977
+ function je(n) {
978
+ return nt(this, arguments, function() {
959
979
  var e, r, s, o;
960
- return ye(this, function(i) {
980
+ return we(this, function(i) {
961
981
  switch (i.label) {
962
982
  case 0:
963
983
  e = n.getReader(), i.label = 1;
964
984
  case 1:
965
985
  i.trys.push([1, , 9, 10]), i.label = 2;
966
986
  case 2:
967
- return [4, M(e.read())];
987
+ return [4, k(e.read())];
968
988
  case 3:
969
- return r = i.sent(), s = r.value, o = r.done, o ? [4, M(void 0)] : [3, 5];
989
+ return r = i.sent(), s = r.value, o = r.done, o ? [4, k(void 0)] : [3, 5];
970
990
  case 4:
971
991
  return [2, i.sent()];
972
992
  case 5:
973
- return [4, M(s)];
993
+ return [4, k(s)];
974
994
  case 6:
975
995
  return [4, i.sent()];
976
996
  case 7:
@@ -985,57 +1005,57 @@ function Ne(n) {
985
1005
  });
986
1006
  });
987
1007
  }
988
- function Re(n) {
1008
+ function $e(n) {
989
1009
  return g(n?.getReader);
990
1010
  }
991
1011
  function U(n) {
992
1012
  if (n instanceof S)
993
1013
  return n;
994
1014
  if (n != null) {
995
- if (_e(n))
996
- return wt(n);
997
- if (Ae(n))
998
- return Et(n);
999
- if (Le(n))
1015
+ if (Ue(n))
1000
1016
  return It(n);
1001
- if (Pe(n))
1002
- return $e(n);
1003
- if (ke(n))
1017
+ if (_e(n))
1004
1018
  return Tt(n);
1005
- if (Re(n))
1019
+ if (Le(n))
1006
1020
  return xt(n);
1021
+ if (Me(n))
1022
+ return De(n);
1023
+ if (Ne(n))
1024
+ return Ct(n);
1025
+ if ($e(n))
1026
+ return Ot(n);
1007
1027
  }
1008
- throw Ue(n);
1028
+ throw ke(n);
1009
1029
  }
1010
- function wt(n) {
1030
+ function It(n) {
1011
1031
  return new S(function(t) {
1012
- var e = n[re]();
1032
+ var e = n[se]();
1013
1033
  if (g(e.subscribe))
1014
1034
  return e.subscribe(t);
1015
1035
  throw new TypeError("Provided object does not correctly implement Symbol.observable");
1016
1036
  });
1017
1037
  }
1018
- function Et(n) {
1038
+ function Tt(n) {
1019
1039
  return new S(function(t) {
1020
1040
  for (var e = 0; e < n.length && !t.closed; e++)
1021
1041
  t.next(n[e]);
1022
1042
  t.complete();
1023
1043
  });
1024
1044
  }
1025
- function It(n) {
1045
+ function xt(n) {
1026
1046
  return new S(function(t) {
1027
1047
  n.then(function(e) {
1028
1048
  t.closed || (t.next(e), t.complete());
1029
1049
  }, function(e) {
1030
1050
  return t.error(e);
1031
- }).then(null, Ie);
1051
+ }).then(null, xe);
1032
1052
  });
1033
1053
  }
1034
- function Tt(n) {
1054
+ function Ct(n) {
1035
1055
  return new S(function(t) {
1036
1056
  var e, r;
1037
1057
  try {
1038
- for (var s = k(n), o = s.next(); !o.done; o = s.next()) {
1058
+ for (var s = R(n), o = s.next(); !o.done; o = s.next()) {
1039
1059
  var i = o.value;
1040
1060
  if (t.next(i), t.closed)
1041
1061
  return;
@@ -1052,24 +1072,24 @@ function Tt(n) {
1052
1072
  t.complete();
1053
1073
  });
1054
1074
  }
1055
- function $e(n) {
1075
+ function De(n) {
1056
1076
  return new S(function(t) {
1057
- Ct(n, t).catch(function(e) {
1077
+ At(n, t).catch(function(e) {
1058
1078
  return t.error(e);
1059
1079
  });
1060
1080
  });
1061
1081
  }
1062
- function xt(n) {
1063
- return $e(Ne(n));
1082
+ function Ot(n) {
1083
+ return De(je(n));
1064
1084
  }
1065
- function Ct(n, t) {
1085
+ function At(n, t) {
1066
1086
  var e, r, s, o;
1067
- return Ze(this, void 0, void 0, function() {
1087
+ return tt(this, void 0, void 0, function() {
1068
1088
  var i, a;
1069
- return ye(this, function(c) {
1089
+ return we(this, function(c) {
1070
1090
  switch (c.label) {
1071
1091
  case 0:
1072
- c.trys.push([0, 5, 6, 11]), e = tt(n), c.label = 1;
1092
+ c.trys.push([0, 5, 6, 11]), e = rt(n), c.label = 1;
1073
1093
  case 1:
1074
1094
  return [4, e.next()];
1075
1095
  case 2:
@@ -1100,7 +1120,7 @@ function Ct(n, t) {
1100
1120
  });
1101
1121
  });
1102
1122
  }
1103
- function C(n, t, e, r, s) {
1123
+ function O(n, t, e, r, s) {
1104
1124
  r === void 0 && (r = 0), s === void 0 && (s = !1);
1105
1125
  var o = t.schedule(function() {
1106
1126
  e(), s ? n.add(this.schedule(null, r)) : this.unsubscribe();
@@ -1108,35 +1128,35 @@ function C(n, t, e, r, s) {
1108
1128
  if (n.add(o), !s)
1109
1129
  return o;
1110
1130
  }
1111
- function je(n, t) {
1112
- return t === void 0 && (t = 0), A(function(e, r) {
1113
- e.subscribe(O(r, function(s) {
1114
- return C(r, n, function() {
1131
+ function Fe(n, t) {
1132
+ return t === void 0 && (t = 0), P(function(e, r) {
1133
+ e.subscribe(A(r, function(s) {
1134
+ return O(r, n, function() {
1115
1135
  return r.next(s);
1116
1136
  }, t);
1117
1137
  }, function() {
1118
- return C(r, n, function() {
1138
+ return O(r, n, function() {
1119
1139
  return r.complete();
1120
1140
  }, t);
1121
1141
  }, function(s) {
1122
- return C(r, n, function() {
1142
+ return O(r, n, function() {
1123
1143
  return r.error(s);
1124
1144
  }, t);
1125
1145
  }));
1126
1146
  });
1127
1147
  }
1128
- function De(n, t) {
1129
- return t === void 0 && (t = 0), A(function(e, r) {
1148
+ function He(n, t) {
1149
+ return t === void 0 && (t = 0), P(function(e, r) {
1130
1150
  r.add(n.schedule(function() {
1131
1151
  return e.subscribe(r);
1132
1152
  }, t));
1133
1153
  });
1134
1154
  }
1135
- function Ot(n, t) {
1136
- return U(n).pipe(De(t), je(t));
1155
+ function Pt(n, t) {
1156
+ return U(n).pipe(He(t), Fe(t));
1137
1157
  }
1138
- function At(n, t) {
1139
- return U(n).pipe(De(t), je(t));
1158
+ function _t(n, t) {
1159
+ return U(n).pipe(He(t), Fe(t));
1140
1160
  }
1141
1161
  function Lt(n, t) {
1142
1162
  return new S(function(e) {
@@ -1146,11 +1166,11 @@ function Lt(n, t) {
1146
1166
  });
1147
1167
  });
1148
1168
  }
1149
- function _t(n, t) {
1169
+ function Ut(n, t) {
1150
1170
  return new S(function(e) {
1151
1171
  var r;
1152
- return C(e, t, function() {
1153
- r = n[Me](), C(e, t, function() {
1172
+ return O(e, t, function() {
1173
+ r = n[Re](), O(e, t, function() {
1154
1174
  var s, o, i;
1155
1175
  try {
1156
1176
  s = r.next(), o = s.value, i = s.done;
@@ -1165,13 +1185,13 @@ function _t(n, t) {
1165
1185
  };
1166
1186
  });
1167
1187
  }
1168
- function He(n, t) {
1188
+ function Be(n, t) {
1169
1189
  if (!n)
1170
1190
  throw new Error("Iterable cannot be null");
1171
1191
  return new S(function(e) {
1172
- C(e, t, function() {
1192
+ O(e, t, function() {
1173
1193
  var r = n[Symbol.asyncIterator]();
1174
- C(e, t, function() {
1194
+ O(e, t, function() {
1175
1195
  r.next().then(function(s) {
1176
1196
  s.done ? e.complete() : e.next(s.value);
1177
1197
  });
@@ -1179,63 +1199,63 @@ function He(n, t) {
1179
1199
  });
1180
1200
  });
1181
1201
  }
1182
- function Pt(n, t) {
1183
- return He(Ne(n), t);
1202
+ function Mt(n, t) {
1203
+ return Be(je(n), t);
1184
1204
  }
1185
- function Ut(n, t) {
1205
+ function kt(n, t) {
1186
1206
  if (n != null) {
1207
+ if (Ue(n))
1208
+ return Pt(n, t);
1187
1209
  if (_e(n))
1188
- return Ot(n, t);
1189
- if (Ae(n))
1190
1210
  return Lt(n, t);
1191
1211
  if (Le(n))
1192
- return At(n, t);
1193
- if (Pe(n))
1194
- return He(n, t);
1195
- if (ke(n))
1196
1212
  return _t(n, t);
1197
- if (Re(n))
1198
- return Pt(n, t);
1213
+ if (Me(n))
1214
+ return Be(n, t);
1215
+ if (Ne(n))
1216
+ return Ut(n, t);
1217
+ if ($e(n))
1218
+ return Mt(n, t);
1199
1219
  }
1200
- throw Ue(n);
1220
+ throw ke(n);
1201
1221
  }
1202
- function oe(n, t) {
1203
- return t ? Ut(n, t) : U(n);
1222
+ function ie(n, t) {
1223
+ return t ? kt(n, t) : U(n);
1204
1224
  }
1205
- function Mt() {
1225
+ function Rt() {
1206
1226
  for (var n = [], t = 0; t < arguments.length; t++)
1207
1227
  n[t] = arguments[t];
1208
- var e = Oe(n);
1209
- return oe(n, e);
1228
+ var e = Pe(n);
1229
+ return ie(n, e);
1210
1230
  }
1211
- function kt(n) {
1231
+ function Nt(n) {
1212
1232
  return n instanceof Date && !isNaN(n);
1213
1233
  }
1214
1234
  function N(n, t) {
1215
- return A(function(e, r) {
1235
+ return P(function(e, r) {
1216
1236
  var s = 0;
1217
- e.subscribe(O(r, function(o) {
1237
+ e.subscribe(A(r, function(o) {
1218
1238
  r.next(n.call(t, o, s++));
1219
1239
  }));
1220
1240
  });
1221
1241
  }
1222
- var Nt = Array.isArray;
1223
- function Rt(n, t) {
1224
- return Nt(t) ? n.apply(void 0, H([], D(t))) : n(t);
1242
+ var jt = Array.isArray;
1243
+ function $t(n, t) {
1244
+ return jt(t) ? n.apply(void 0, F([], D(t))) : n(t);
1225
1245
  }
1226
- function $t(n) {
1246
+ function Dt(n) {
1227
1247
  return N(function(t) {
1228
- return Rt(n, t);
1248
+ return $t(n, t);
1229
1249
  });
1230
1250
  }
1231
- var jt = Array.isArray, Dt = Object.getPrototypeOf, Ht = Object.prototype, Ft = Object.keys;
1232
- function Gt(n) {
1251
+ var Ft = Array.isArray, Ht = Object.getPrototypeOf, Bt = Object.prototype, Gt = Object.keys;
1252
+ function Kt(n) {
1233
1253
  if (n.length === 1) {
1234
1254
  var t = n[0];
1235
- if (jt(t))
1255
+ if (Ft(t))
1236
1256
  return { args: t, keys: null };
1237
- if (Bt(t)) {
1238
- var e = Ft(t);
1257
+ if (qt(t)) {
1258
+ var e = Gt(t);
1239
1259
  return {
1240
1260
  args: e.map(function(r) {
1241
1261
  return t[r];
@@ -1246,33 +1266,33 @@ function Gt(n) {
1246
1266
  }
1247
1267
  return { args: n, keys: null };
1248
1268
  }
1249
- function Bt(n) {
1250
- return n && typeof n == "object" && Dt(n) === Ht;
1269
+ function qt(n) {
1270
+ return n && typeof n == "object" && Ht(n) === Bt;
1251
1271
  }
1252
- function Kt(n, t) {
1272
+ function Yt(n, t) {
1253
1273
  return n.reduce(function(e, r, s) {
1254
1274
  return e[r] = t[s], e;
1255
1275
  }, {});
1256
1276
  }
1257
- function qt() {
1277
+ function Wt() {
1258
1278
  for (var n = [], t = 0; t < arguments.length; t++)
1259
1279
  n[t] = arguments[t];
1260
- var e = Oe(n), r = yt(n), s = Gt(n), o = s.args, i = s.keys;
1280
+ var e = Pe(n), r = wt(n), s = Kt(n), o = s.args, i = s.keys;
1261
1281
  if (o.length === 0)
1262
- return oe([], e);
1263
- var a = new S(Yt(o, e, i ? function(c) {
1264
- return Kt(i, c);
1265
- } : X));
1266
- return r ? a.pipe($t(r)) : a;
1267
- }
1268
- function Yt(n, t, e) {
1269
- return e === void 0 && (e = X), function(r) {
1270
- fe(t, function() {
1282
+ return ie([], e);
1283
+ var a = new S(Xt(o, e, i ? function(c) {
1284
+ return Yt(i, c);
1285
+ } : W));
1286
+ return r ? a.pipe(Dt(r)) : a;
1287
+ }
1288
+ function Xt(n, t, e) {
1289
+ return e === void 0 && (e = W), function(r) {
1290
+ pe(t, function() {
1271
1291
  for (var s = n.length, o = new Array(s), i = s, a = s, c = function(h) {
1272
- fe(t, function() {
1273
- var m = oe(n[h], t), b = !1;
1274
- m.subscribe(O(r, function(l) {
1275
- o[h] = l, b || (b = !0, a--), a || r.next(e(o.slice()));
1292
+ pe(t, function() {
1293
+ var m = ie(n[h], t), b = !1;
1294
+ m.subscribe(A(r, function(d) {
1295
+ o[h] = d, b || (b = !0, a--), a || r.next(e(o.slice()));
1276
1296
  }, function() {
1277
1297
  --i || r.complete();
1278
1298
  }));
@@ -1282,37 +1302,37 @@ function Yt(n, t, e) {
1282
1302
  }, r);
1283
1303
  };
1284
1304
  }
1285
- function fe(n, t, e) {
1286
- n ? C(e, n, t) : t();
1305
+ function pe(n, t, e) {
1306
+ n ? O(e, n, t) : t();
1287
1307
  }
1288
- function Xt(n, t, e, r, s, o, i, a) {
1308
+ function Vt(n, t, e, r, s, o, i, a) {
1289
1309
  var c = [], u = 0, h = 0, m = !1, b = function() {
1290
1310
  m && !c.length && !u && t.complete();
1291
- }, l = function(p) {
1292
- return u < r ? f(p) : c.push(p);
1293
- }, f = function(p) {
1311
+ }, d = function(f) {
1312
+ return u < r ? p(f) : c.push(f);
1313
+ }, p = function(f) {
1294
1314
  u++;
1295
- var L = !1;
1296
- U(e(p, h++)).subscribe(O(t, function(E) {
1315
+ var _ = !1;
1316
+ U(e(f, h++)).subscribe(A(t, function(E) {
1297
1317
  t.next(E);
1298
1318
  }, function() {
1299
- L = !0;
1319
+ _ = !0;
1300
1320
  }, void 0, function() {
1301
- if (L)
1321
+ if (_)
1302
1322
  try {
1303
1323
  u--;
1304
1324
  for (var E = function() {
1305
- var _ = c.shift();
1306
- i || f(_);
1325
+ var L = c.shift();
1326
+ i || p(L);
1307
1327
  }; c.length && u < r; )
1308
1328
  E();
1309
1329
  b();
1310
- } catch (_) {
1311
- t.error(_);
1330
+ } catch (L) {
1331
+ t.error(L);
1312
1332
  }
1313
1333
  }));
1314
1334
  };
1315
- return n.subscribe(O(t, l, function() {
1335
+ return n.subscribe(A(t, d, function() {
1316
1336
  m = !0, b();
1317
1337
  })), function() {
1318
1338
  };
@@ -1322,15 +1342,15 @@ function Y(n, t, e) {
1322
1342
  return N(function(o, i) {
1323
1343
  return t(r, o, s, i);
1324
1344
  })(U(n(r, s)));
1325
- }, e) : (typeof t == "number" && (e = t), A(function(r, s) {
1326
- return Xt(r, s, n, e);
1345
+ }, e) : (typeof t == "number" && (e = t), P(function(r, s) {
1346
+ return Vt(r, s, n, e);
1327
1347
  }));
1328
1348
  }
1329
- function Vt(n, t, e) {
1330
- n === void 0 && (n = 0), e === void 0 && (e = bt);
1349
+ function zt(n, t, e) {
1350
+ n === void 0 && (n = 0), e === void 0 && (e = yt);
1331
1351
  var r = -1;
1332
- return t != null && (xe(t) ? e = t : r = t), new S(function(s) {
1333
- var o = kt(n) ? +n - e.now() : n;
1352
+ return t != null && (Oe(t) ? e = t : r = t), new S(function(s) {
1353
+ var o = Nt(n) ? +n - e.now() : n;
1334
1354
  o < 0 && (o = 0);
1335
1355
  var i = 0;
1336
1356
  return e.schedule(function() {
@@ -1338,50 +1358,50 @@ function Vt(n, t, e) {
1338
1358
  }, o);
1339
1359
  });
1340
1360
  }
1341
- function Wt(n, t) {
1361
+ function Jt(n, t) {
1342
1362
  return g(t) ? Y(n, t, 1) : Y(n, 1);
1343
1363
  }
1344
- function zt(n) {
1364
+ function Qt(n) {
1345
1365
  return n <= 0 ? function() {
1346
- return vt;
1347
- } : A(function(t, e) {
1366
+ return St;
1367
+ } : P(function(t, e) {
1348
1368
  var r = 0;
1349
- t.subscribe(O(e, function(s) {
1369
+ t.subscribe(A(e, function(s) {
1350
1370
  ++r <= n && (e.next(s), n <= r && e.complete());
1351
1371
  }));
1352
1372
  });
1353
1373
  }
1354
- function Jt(n) {
1374
+ function Zt(n) {
1355
1375
  return N(function() {
1356
1376
  return n;
1357
1377
  });
1358
1378
  }
1359
- function Qt(n, t) {
1379
+ function en(n, t) {
1360
1380
  return Y(function(e, r) {
1361
- return U(n(e, r)).pipe(zt(1), Jt(e));
1381
+ return U(n(e, r)).pipe(Qt(1), Zt(e));
1362
1382
  });
1363
1383
  }
1364
- function Zt(n, t) {
1365
- t === void 0 && (t = Te);
1366
- var e = Vt(n, t);
1367
- return Qt(function() {
1384
+ function tn(n, t) {
1385
+ t === void 0 && (t = Ce);
1386
+ var e = zt(n, t);
1387
+ return en(function() {
1368
1388
  return e;
1369
1389
  });
1370
1390
  }
1371
- function j(n, t) {
1372
- return t === void 0 && (t = X), n = n ?? en, A(function(e, r) {
1391
+ function M(n, t) {
1392
+ return t === void 0 && (t = W), n = n ?? nn, P(function(e, r) {
1373
1393
  var s, o = !0;
1374
- e.subscribe(O(r, function(i) {
1394
+ e.subscribe(A(r, function(i) {
1375
1395
  var a = t(i);
1376
1396
  (o || !n(s, a)) && (o = !1, s = a, r.next(i));
1377
1397
  }));
1378
1398
  });
1379
1399
  }
1380
- function en(n, t) {
1400
+ function nn(n, t) {
1381
1401
  return n === t;
1382
1402
  }
1383
- function tn(n) {
1384
- return A(function(t, e) {
1403
+ function rn(n) {
1404
+ return P(function(t, e) {
1385
1405
  try {
1386
1406
  t.subscribe(e);
1387
1407
  } finally {
@@ -1389,27 +1409,27 @@ function tn(n) {
1389
1409
  }
1390
1410
  });
1391
1411
  }
1392
- function nn(n) {
1393
- return A(function(t, e) {
1394
- U(n).subscribe(O(e, function() {
1412
+ function sn(n) {
1413
+ return P(function(t, e) {
1414
+ U(n).subscribe(A(e, function() {
1395
1415
  return e.complete();
1396
- }, ee)), !e.closed && t.subscribe(e);
1416
+ }, te)), !e.closed && t.subscribe(e);
1397
1417
  });
1398
1418
  }
1399
- function pe(n) {
1419
+ function me(n) {
1400
1420
  const { endpoint: t, apiKey: e, payload: r, debugMode: s, customHeaders: o } = n, i = n.method ?? "POST";
1401
1421
  return new S((a) => {
1402
1422
  const c = new AbortController();
1403
- let u, h = !1;
1404
- const m = {
1423
+ let u, h = !1, m = !1;
1424
+ const b = {
1405
1425
  "Content-Type": "application/json",
1406
1426
  ...o
1407
1427
  };
1408
- e && (m["X-API-KEY"] = e);
1409
- const b = new URL(t);
1410
- return s && b.searchParams.set("is_debug", "true"), ve(b.toString(), {
1428
+ e && (b["X-API-KEY"] = e);
1429
+ const d = new URL(t);
1430
+ return s && d.searchParams.set("is_debug", "true"), Se(d.toString(), {
1411
1431
  method: i,
1412
- headers: m,
1432
+ headers: b,
1413
1433
  body: i === "POST" && r ? JSON.stringify(r) : void 0,
1414
1434
  signal: c.signal,
1415
1435
  /**
@@ -1417,41 +1437,42 @@ function pe(n) {
1417
1437
  * https://github.com/Azure/fetch-event-source/issues/17#issuecomment-1525904929
1418
1438
  */
1419
1439
  openWhenHidden: !0,
1420
- onopen: async (l) => {
1421
- if (l.ok)
1422
- u = l.headers.get("X-Trace-Id") ?? void 0;
1440
+ onopen: async (p) => {
1441
+ if (p.ok)
1442
+ u = p.headers.get("X-Trace-Id") ?? void 0;
1423
1443
  else {
1424
1444
  let f;
1425
1445
  try {
1426
- f = await l.json();
1446
+ f = await p.json();
1427
1447
  } catch {
1428
1448
  try {
1429
- f = await l.text();
1449
+ f = await p.text();
1430
1450
  } catch {
1431
1451
  f = null;
1432
1452
  }
1433
1453
  }
1434
- a.error(new w(l.status, l.statusText, f)), c.abort();
1454
+ a.error(new w(p.status, p.statusText, f)), c.abort();
1435
1455
  }
1436
1456
  },
1437
- onmessage: (l) => {
1438
- l.id && (h = !0);
1439
- const f = JSON.parse(l.data);
1457
+ onmessage: (p) => {
1458
+ p.id && (h = !0);
1459
+ const f = JSON.parse(p.data);
1440
1460
  u ? f.traceId = u : f.requestId && (f.traceId = f.requestId, u || (u = f.requestId)), a.next(f);
1441
1461
  },
1442
1462
  onclose: () => {
1443
1463
  a.complete();
1444
1464
  },
1445
- onerror: (l) => {
1465
+ onerror: (p) => {
1466
+ if (m) throw p;
1446
1467
  if (!h)
1447
- throw a.error(l), c.abort(), l;
1468
+ throw a.error(p), c.abort(), p;
1448
1469
  }
1449
1470
  }), () => {
1450
- c.abort();
1471
+ m = !0, c.abort();
1451
1472
  };
1452
1473
  });
1453
1474
  }
1454
- class rn {
1475
+ class on {
1455
1476
  listeners = {};
1456
1477
  on(t, e) {
1457
1478
  this.listeners = Object.assign({}, this.listeners, {
@@ -1470,17 +1491,17 @@ class rn {
1470
1491
  this.listeners[t] && this.listeners[t].forEach((r) => r(...e));
1471
1492
  }
1472
1493
  }
1473
- class xn {
1494
+ class _n {
1474
1495
  apiKey;
1475
1496
  endpoint;
1476
1497
  botProviderEndpoint;
1477
1498
  debugMode;
1478
- destroy$ = new se();
1499
+ destroy$ = new oe();
1479
1500
  closed = !1;
1480
1501
  detached = !1;
1481
1502
  detachTimer;
1482
1503
  inFlight = 0;
1483
- sseEmitter = new rn();
1504
+ sseEmitter = new on();
1484
1505
  transformSsePayload;
1485
1506
  customHeaders;
1486
1507
  constructor(t) {
@@ -1501,39 +1522,39 @@ class xn {
1501
1522
  }
1502
1523
  handleEvent(t) {
1503
1524
  switch (t.eventType) {
1504
- case d.INIT:
1505
- this.sseEmitter.emit(d.INIT, t);
1525
+ case l.INIT:
1526
+ this.sseEmitter.emit(l.INIT, t);
1506
1527
  break;
1507
- case d.PROCESS_START:
1508
- case d.PROCESS_COMPLETE:
1509
- this.sseEmitter.emit(d.PROCESS, t);
1528
+ case l.PROCESS_START:
1529
+ case l.PROCESS_COMPLETE:
1530
+ this.sseEmitter.emit(l.PROCESS, t);
1510
1531
  break;
1511
- case d.MESSAGE_START:
1512
- case d.MESSAGE_DELTA:
1513
- case d.MESSAGE_COMPLETE:
1514
- this.sseEmitter.emit(d.MESSAGE, t);
1532
+ case l.MESSAGE_START:
1533
+ case l.MESSAGE_DELTA:
1534
+ case l.MESSAGE_COMPLETE:
1535
+ this.sseEmitter.emit(l.MESSAGE, t);
1515
1536
  break;
1516
- case d.TOOL_CALL_START:
1517
- case d.TOOL_CALL_COMPLETE:
1518
- this.sseEmitter.emit(d.TOOL_CALL, t);
1537
+ case l.TOOL_CALL_START:
1538
+ case l.TOOL_CALL_COMPLETE:
1539
+ this.sseEmitter.emit(l.TOOL_CALL, t);
1519
1540
  break;
1520
- case d.TOOL_CALL_CONSENT:
1541
+ case l.TOOL_CALL_CONSENT:
1521
1542
  this.sseEmitter.emit(
1522
- d.TOOL_CALL_CONSENT,
1543
+ l.TOOL_CALL_CONSENT,
1523
1544
  t
1524
1545
  );
1525
1546
  break;
1526
- case d.DONE:
1527
- this.sseEmitter.emit(d.DONE, t);
1547
+ case l.DONE:
1548
+ this.sseEmitter.emit(l.DONE, t);
1528
1549
  break;
1529
- case d.ERROR:
1530
- this.sseEmitter.emit(d.ERROR, t);
1550
+ case l.ERROR:
1551
+ this.sseEmitter.emit(l.ERROR, t);
1531
1552
  break;
1532
1553
  }
1533
1554
  }
1534
1555
  fetchSse(t, e) {
1535
1556
  return e?.onSseStart?.(), this.inFlight += 1, this.runSse(
1536
- pe({
1557
+ me({
1537
1558
  apiKey: this.apiKey,
1538
1559
  endpoint: this.endpoint,
1539
1560
  debugMode: this.debugMode,
@@ -1552,7 +1573,7 @@ class xn {
1552
1573
  e?.onSseStart?.(), this.inFlight += 1;
1553
1574
  const r = new URL(this.endpoint);
1554
1575
  return r.searchParams.set("custom_channel_id", t), this.runSse(
1555
- pe({
1576
+ me({
1556
1577
  apiKey: this.apiKey,
1557
1578
  endpoint: r.toString(),
1558
1579
  debugMode: this.debugMode,
@@ -1602,16 +1623,47 @@ class xn {
1602
1623
  }))
1603
1624
  };
1604
1625
  }
1626
+ deriveSuspendEndpoint() {
1627
+ const t = this.getBaseEndpoint();
1628
+ return t ? `${t}/message/suspend` : null;
1629
+ }
1630
+ /**
1631
+ * Ask the backend to suspend this channel's background run (F-023 AC1):
1632
+ * `POST {base}/message/suspend?custom_channel_id=…`. The six downstream relays expose this at the
1633
+ * exact same shape as `GET {base}/message/sse`, so it is derived identically with no per-backend case.
1634
+ *
1635
+ * `custom_channel_id` is always sent — some backends take the channel from the path and ignore it,
1636
+ * others require it, and sending it is correct for both (same rule as the GET rejoin).
1637
+ *
1638
+ * **Resolving means "accepted", not "stopped".** The run winds down on the server and declares itself
1639
+ * finished through the terminal event on the already-open SSE stream (the same event a normal run
1640
+ * ends with), so callers must keep that stream connected and wait for it.
1641
+ *
1642
+ * Success is **any 2xx** — relays variously answer `204 No Content` or `200` with an envelope, so no
1643
+ * single status is hardcoded. `404` means the channel was never created, i.e. there is nothing to
1644
+ * stop, which is a success rather than an error. Every other non-2xx throws {@link HttpError}.
1645
+ */
1646
+ async suspendChannel(t, e) {
1647
+ const r = this.deriveSuspendEndpoint();
1648
+ if (!r)
1649
+ throw new Error("Unable to derive channel suspend endpoint. Please provide botProviderEndpoint in config.");
1650
+ const s = new URL(r);
1651
+ s.searchParams.set("custom_channel_id", t), e?.requestId && s.searchParams.set("request_id", e.requestId), e?.force && s.searchParams.set("force", "true");
1652
+ const o = await fetch(s.toString(), { method: "POST", headers: this.apiHeaders() });
1653
+ if (!(o.ok || o.status === 404))
1654
+ throw new w(o.status, o.statusText, await o.text().catch(() => {
1655
+ }));
1656
+ }
1605
1657
  runSse(t, e) {
1606
1658
  return t.pipe(
1607
1659
  // No RxJS-level retry: re-subscribing would re-POST and the backend would re-dispatch a duplicate
1608
1660
  // run. Mid-stream resume is the library's job (native Last-Event-ID reconnect in
1609
1661
  // create-sse-observable); a no-cursor failure surfaces via `error` below.
1610
- Wt((r) => Mt(r).pipe(Zt(e?.delayTime ?? 50))),
1611
- nn(this.destroy$),
1662
+ Jt((r) => Rt(r).pipe(tn(e?.delayTime ?? 50))),
1663
+ sn(this.destroy$),
1612
1664
  // Settle the run accounting on every termination path — complete, error, AND a user-initiated
1613
1665
  // unsubscribe (stop-generation aborts the connection without a terminal event).
1614
- tn(() => this.onRunSettled())
1666
+ rn(() => this.onRunSettled())
1615
1667
  ).subscribe({
1616
1668
  next: (r) => {
1617
1669
  this.detached || (e?.onSseMessage?.(r), this.handleEvent(r));
@@ -1738,7 +1790,8 @@ class xn {
1738
1790
  throw new Error("Unable to derive sandbox fs endpoint. Please provide botProviderEndpoint in config.");
1739
1791
  return `${e}/sandbox/${encodeURIComponent(t)}/fs`;
1740
1792
  }
1741
- sandboxFsHeaders() {
1793
+ /** The shared auth / custom headers for the client's plain-JSON REST calls (no SSE). */
1794
+ apiHeaders() {
1742
1795
  const t = { ...this.customHeaders };
1743
1796
  return this.apiKey && (t["X-API-KEY"] = this.apiKey), t;
1744
1797
  }
@@ -1749,7 +1802,7 @@ class xn {
1749
1802
  async sandboxFsList(t, e) {
1750
1803
  const r = new URL(`${this.deriveSandboxFsEndpoint(t)}/list`);
1751
1804
  r.searchParams.set("path", e);
1752
- const s = await fetch(r.toString(), { method: "GET", headers: this.sandboxFsHeaders() });
1805
+ const s = await fetch(r.toString(), { method: "GET", headers: this.apiHeaders() });
1753
1806
  if (!s.ok)
1754
1807
  throw new w(s.status, s.statusText, await s.text().catch(() => {
1755
1808
  }));
@@ -1763,7 +1816,7 @@ class xn {
1763
1816
  async sandboxFsRead(t, e, r) {
1764
1817
  const s = new URL(`${this.deriveSandboxFsEndpoint(t)}/file`);
1765
1818
  s.searchParams.set("path", e), r?.offsetBytes != null && s.searchParams.set("offset_bytes", String(r.offsetBytes)), r?.limitBytes != null && s.searchParams.set("limit_bytes", String(r.limitBytes));
1766
- const o = await fetch(s.toString(), { method: "GET", headers: this.sandboxFsHeaders() });
1819
+ const o = await fetch(s.toString(), { method: "GET", headers: this.apiHeaders() });
1767
1820
  if (!o.ok)
1768
1821
  throw new w(o.status, o.statusText, await o.text().catch(() => {
1769
1822
  }));
@@ -1783,7 +1836,7 @@ class xn {
1783
1836
  o.searchParams.set("path", e), s?.mode != null && o.searchParams.set("mode", String(s.mode)), s?.createOnly && o.searchParams.set("create_only", "true");
1784
1837
  const i = new FormData();
1785
1838
  i.append("file", r instanceof Blob ? r : new Blob([r]));
1786
- const a = await fetch(o.toString(), { method: "PUT", headers: this.sandboxFsHeaders(), body: i });
1839
+ const a = await fetch(o.toString(), { method: "PUT", headers: this.apiHeaders(), body: i });
1787
1840
  if (!a.ok)
1788
1841
  throw new w(a.status, a.statusText, await a.text().catch(() => {
1789
1842
  }));
@@ -1794,7 +1847,7 @@ class xn {
1794
1847
  async sandboxFsRequest(t, e, r, s) {
1795
1848
  const o = new URL(`${this.deriveSandboxFsEndpoint(t)}/${e}`);
1796
1849
  Object.entries(s).forEach(([a, c]) => o.searchParams.set(a, c));
1797
- const i = await fetch(o.toString(), { method: r, headers: this.sandboxFsHeaders() });
1850
+ const i = await fetch(o.toString(), { method: r, headers: this.apiHeaders() });
1798
1851
  if (!i.ok)
1799
1852
  throw new w(i.status, i.statusText, await i.text().catch(() => {
1800
1853
  }));
@@ -1804,7 +1857,7 @@ class xn {
1804
1857
  async sandboxFsStat(t, e) {
1805
1858
  const r = new URL(`${this.deriveSandboxFsEndpoint(t)}/stat`);
1806
1859
  r.searchParams.set("path", e);
1807
- const s = await fetch(r.toString(), { method: "GET", headers: this.sandboxFsHeaders() });
1860
+ const s = await fetch(r.toString(), { method: "GET", headers: this.apiHeaders() });
1808
1861
  if (!s.ok)
1809
1862
  throw new w(s.status, s.statusText, await s.text().catch(() => {
1810
1863
  }));
@@ -1851,8 +1904,8 @@ class xn {
1851
1904
  const r = new URL(`${this.deriveSandboxFsEndpoint(t)}/watch`);
1852
1905
  return r.searchParams.set("path", e), new S((s) => {
1853
1906
  const o = new AbortController();
1854
- return ve(r.toString(), {
1855
- headers: this.sandboxFsHeaders(),
1907
+ return Se(r.toString(), {
1908
+ headers: this.apiHeaders(),
1856
1909
  signal: o.signal,
1857
1910
  openWhenHidden: !0,
1858
1911
  onopen: async (i) => {
@@ -1891,29 +1944,29 @@ class xn {
1891
1944
  const y = [];
1892
1945
  for (let n = 0; n < 256; ++n)
1893
1946
  y.push((n + 256).toString(16).slice(1));
1894
- function sn(n, t = 0) {
1947
+ function an(n, t = 0) {
1895
1948
  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();
1896
1949
  }
1897
1950
  let J;
1898
- const on = new Uint8Array(16);
1899
- function an() {
1951
+ const cn = new Uint8Array(16);
1952
+ function un() {
1900
1953
  if (!J) {
1901
1954
  if (typeof crypto > "u" || !crypto.getRandomValues)
1902
1955
  throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
1903
1956
  J = crypto.getRandomValues.bind(crypto);
1904
1957
  }
1905
- return J(on);
1958
+ return J(cn);
1906
1959
  }
1907
- const cn = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), me = { randomUUID: cn };
1908
- function un(n, t, e) {
1960
+ const ln = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), ge = { randomUUID: ln };
1961
+ function dn(n, t, e) {
1909
1962
  n = n || {};
1910
- const r = n.random ?? n.rng?.() ?? an();
1963
+ const r = n.random ?? n.rng?.() ?? un();
1911
1964
  if (r.length < 16)
1912
1965
  throw new Error("Random bytes length must be >= 16");
1913
- return r[6] = r[6] & 15 | 64, r[8] = r[8] & 63 | 128, sn(r);
1966
+ return r[6] = r[6] & 15 | 64, r[8] = r[8] & 63 | 128, an(r);
1914
1967
  }
1915
- function Fe(n, t, e) {
1916
- return me.randomUUID && !n ? me.randomUUID() : un(n);
1968
+ function Ge(n, t, e) {
1969
+ return ge.randomUUID && !n ? ge.randomUUID() : dn(n);
1917
1970
  }
1918
1971
  class v {
1919
1972
  messages = null;
@@ -1929,47 +1982,61 @@ class v {
1929
1982
  return this.pendingConsent ? new v({ messages: this.messages, pendingConsent: null }) : this;
1930
1983
  }
1931
1984
  /**
1932
- * Converge every still-running tool-call to `cancelled` (F-020 AC10). Called when a user-initiated
1933
- * stop-generation aborts the run: an in-flight tool-call (`isComplete === false`) would otherwise
1934
- * linger as `running` forever, since its `tool_call.complete` frame never arrives. Already-settled
1935
- * calls and non-tool-call messages are left untouched; content is preserved (never rolled back).
1936
- * Returns the same instance when nothing is in flight.
1985
+ * Converge everything the aborted run left mid-flight (F-020 AC10, F-023). A stopped run sends no
1986
+ * closing frame for whatever was in progress, so without this those messages advertise activity that
1987
+ * has ceased and they persist in the transcript that way:
1988
+ *
1989
+ * - a tool-call with `isComplete === false` gets no `tool_call.complete`, and would render as
1990
+ * `running` forever, so it converges to `cancelled`;
1991
+ * - a thinking block with `isThinking === true` gets no `message.thinking.complete`, and would keep
1992
+ * its highlighted "Thinking…" state forever, so it converges to the settled state.
1993
+ *
1994
+ * Content is preserved either way — never rolled back. Already-settled messages and every other
1995
+ * message type are untouched, and the same instance is returned when nothing was in flight.
1937
1996
  */
1938
- cancelInFlightToolCalls() {
1997
+ settleInFlightMessages() {
1939
1998
  if (!this.messages) return this;
1940
1999
  let t = !1;
1941
2000
  const e = new Map(this.messages);
1942
2001
  for (const [r, s] of e)
1943
- s.type === "tool-call" && !s.isComplete && (e.set(r, { ...s, isComplete: !0, isCancelled: !0 }), t = !0);
2002
+ s.type === "tool-call" && !s.isComplete && (e.set(r, { ...s, isComplete: !0, isCancelled: !0 }), t = !0), s.type === "thinking" && s.isThinking && (e.set(r, { ...s, isThinking: !1 }), t = !0);
1944
2003
  return t ? new v({ messages: e, pendingConsent: this.pendingConsent }) : this;
1945
2004
  }
2005
+ /**
2006
+ * @deprecated Renamed to {@link settleInFlightMessages} in 0.3.27 — it settles in-flight thinking
2007
+ * blocks as well as tool-calls, which the old name no longer described. Behaviour is unchanged;
2008
+ * this alias will be removed in a future major version.
2009
+ */
2010
+ cancelInFlightToolCalls() {
2011
+ return this.settleInFlightMessages();
2012
+ }
1946
2013
  onMessage(t) {
1947
2014
  switch (t.eventType) {
1948
- case d.MESSAGE_START:
2015
+ case l.MESSAGE_START:
1949
2016
  return this.onMessageStart(t);
1950
- case d.MESSAGE_DELTA:
2017
+ case l.MESSAGE_DELTA:
1951
2018
  return this.onMessageDelta(t);
1952
- case d.MESSAGE_COMPLETE:
2019
+ case l.MESSAGE_COMPLETE:
1953
2020
  return this.onMessageComplete(t);
1954
- case d.MESSAGE_USER:
2021
+ case l.MESSAGE_USER:
1955
2022
  return this.onMessageUser(t);
1956
- case d.MESSAGE_THINKING_START:
2023
+ case l.MESSAGE_THINKING_START:
1957
2024
  return this.onThinkingStart(t);
1958
- case d.MESSAGE_THINKING_DELTA:
2025
+ case l.MESSAGE_THINKING_DELTA:
1959
2026
  return this.onThinkingDelta(t);
1960
- case d.MESSAGE_THINKING_COMPLETE:
2027
+ case l.MESSAGE_THINKING_COMPLETE:
1961
2028
  return this.onThinkingComplete(t);
1962
- case d.TOOL_CALL_START:
2029
+ case l.TOOL_CALL_START:
1963
2030
  return this.onToolCallStart(t);
1964
- case d.TOOL_CALL_COMPLETE:
2031
+ case l.TOOL_CALL_COMPLETE:
1965
2032
  return this.onToolCallComplete(t);
1966
- case d.TOOL_CALL_CONSENT:
2033
+ case l.TOOL_CALL_CONSENT:
1967
2034
  return this.onToolCallConsent(t);
1968
- case d.SUBAGENT_START:
2035
+ case l.SUBAGENT_START:
1969
2036
  return this.onSubagentStart(t);
1970
- case d.SUBAGENT_COMPLETE:
2037
+ case l.SUBAGENT_COMPLETE:
1971
2038
  return this.onSubagentComplete(t);
1972
- case d.ERROR:
2039
+ case l.ERROR:
1973
2040
  return this.onMessageError(t);
1974
2041
  default:
1975
2042
  return this;
@@ -1998,7 +2065,7 @@ class v {
1998
2065
  const r = new Map(this.messages);
1999
2066
  return r.set(e.messageId, {
2000
2067
  type: "bot",
2001
- eventType: d.MESSAGE_START,
2068
+ eventType: l.MESSAGE_START,
2002
2069
  isTyping: !0,
2003
2070
  typingText: "",
2004
2071
  messageId: e.messageId,
@@ -2016,7 +2083,7 @@ class v {
2016
2083
  const s = r?.type === "bot" ? r : void 0, o = new Map(this.messages);
2017
2084
  return o.set(e.messageId, {
2018
2085
  type: "bot",
2019
- eventType: d.MESSAGE_DELTA,
2086
+ eventType: l.MESSAGE_DELTA,
2020
2087
  isTyping: !0,
2021
2088
  typingText: `${s?.typingText ?? ""}${e.text}`,
2022
2089
  messageId: e.messageId,
@@ -2032,7 +2099,7 @@ class v {
2032
2099
  const r = new Map(this.messages), s = r.get(e.messageId);
2033
2100
  return r.set(e.messageId, {
2034
2101
  type: "bot",
2035
- eventType: d.MESSAGE_COMPLETE,
2102
+ eventType: l.MESSAGE_COMPLETE,
2036
2103
  isTyping: !1,
2037
2104
  typingText: null,
2038
2105
  messageId: e.messageId,
@@ -2102,10 +2169,10 @@ class v {
2102
2169
  return s.set(e.messageId, o), new v({ messages: s, pendingConsent: this.pendingConsent });
2103
2170
  }
2104
2171
  onMessageError(t) {
2105
- const e = Fe(), r = t.fact.runError.error, s = new Map(this.messages);
2172
+ const e = Ge(), r = t.fact.runError.error, s = new Map(this.messages);
2106
2173
  return s.set(e, {
2107
2174
  type: "error",
2108
- eventType: d.ERROR,
2175
+ eventType: l.ERROR,
2109
2176
  messageId: e,
2110
2177
  error: r,
2111
2178
  time: /* @__PURE__ */ new Date(),
@@ -2115,7 +2182,7 @@ class v {
2115
2182
  onToolCallStart(t) {
2116
2183
  const e = t.fact.toolCallStart, r = new Map(this.messages), s = `${e.processId}-${e.callSeq}`, o = {
2117
2184
  type: "tool-call",
2118
- eventType: d.TOOL_CALL_START,
2185
+ eventType: l.TOOL_CALL_START,
2119
2186
  messageId: s,
2120
2187
  processId: e.processId,
2121
2188
  callSeq: e.callSeq,
@@ -2136,7 +2203,7 @@ class v {
2136
2203
  if (o?.type === "tool-call") {
2137
2204
  const i = {
2138
2205
  ...o,
2139
- eventType: d.TOOL_CALL_COMPLETE,
2206
+ eventType: l.TOOL_CALL_COMPLETE,
2140
2207
  result: e.toolCallResult,
2141
2208
  isError: e.isError,
2142
2209
  sidecar: e.toolUseResultSidecar,
@@ -2181,22 +2248,22 @@ class v {
2181
2248
  return r.set(s, o), new v({ messages: r, pendingConsent: this.pendingConsent });
2182
2249
  }
2183
2250
  }
2184
- const ln = /* @__PURE__ */ new Set(["TaskCreate", "TaskUpdate"]);
2185
- function dn(n) {
2186
- return n.toolsetName === "" && ln.has(n.toolName);
2251
+ const hn = /* @__PURE__ */ new Set(["TaskCreate", "TaskUpdate"]);
2252
+ function fn(n) {
2253
+ return n.toolsetName === "" && hn.has(n.toolName);
2187
2254
  }
2188
- function ge(n) {
2255
+ function be(n) {
2189
2256
  return typeof n == "object" && n !== null ? n : void 0;
2190
2257
  }
2191
2258
  function I(n) {
2192
2259
  return typeof n == "string" ? n : void 0;
2193
2260
  }
2194
- function hn(n) {
2261
+ function pn(n) {
2195
2262
  const t = [], e = /* @__PURE__ */ new Map();
2196
2263
  for (const r of n) {
2197
2264
  const s = r.parameter ?? {}, o = r.sidecar ?? {};
2198
2265
  if (r.toolName === "TaskCreate") {
2199
- const i = ge(o.task), a = I(i?.id);
2266
+ const i = be(o.task), a = I(i?.id);
2200
2267
  if (!a) continue;
2201
2268
  e.has(a) || t.push(a), e.set(a, {
2202
2269
  id: a,
@@ -2207,7 +2274,7 @@ function hn(n) {
2207
2274
  // initial status = pending (keep existing on repeat)
2208
2275
  });
2209
2276
  } else if (r.toolName === "TaskUpdate") {
2210
- const i = ge(o.statusChange), a = I(s.taskId) || I(o.taskId), c = I(i?.to) || I(s.status);
2277
+ const i = be(o.statusChange), a = I(s.taskId) || I(o.taskId), c = I(i?.to) || I(s.status);
2211
2278
  if (!a || !c) continue;
2212
2279
  const u = e.get(a);
2213
2280
  u && e.set(a, { ...u, status: c });
@@ -2215,13 +2282,13 @@ function hn(n) {
2215
2282
  }
2216
2283
  return t.map((r) => e.get(r));
2217
2284
  }
2218
- function fn(n) {
2285
+ function mn(n) {
2219
2286
  return n.toolsetName === "" && n.toolName === "Agent";
2220
2287
  }
2221
- function pn(n) {
2288
+ function gn(n) {
2222
2289
  return !!n;
2223
2290
  }
2224
- function mn(n) {
2291
+ function bn(n) {
2225
2292
  const t = [], e = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), s = (o) => (e.has(o) || (t.push(o), e.set(o, { status: "running" }), r.set(o, /* @__PURE__ */ new Map())), e.get(o));
2226
2293
  for (const o of n)
2227
2294
  switch (o.kind) {
@@ -2262,21 +2329,21 @@ function mn(n) {
2262
2329
  tools: Array.from(r.get(o).values())
2263
2330
  }));
2264
2331
  }
2265
- function gn(n) {
2332
+ function vn(n) {
2266
2333
  return typeof n == "string" ? n : void 0;
2267
2334
  }
2268
- function bn(n) {
2335
+ function yn(n) {
2269
2336
  const t = [];
2270
2337
  for (const e of n) {
2271
- if (e.type === "tool-call" && fn(e)) {
2338
+ if (e.type === "tool-call" && mn(e)) {
2272
2339
  t.push({
2273
2340
  kind: "agentStart",
2274
2341
  toolUseId: e.toolUseId ?? e.messageId,
2275
- description: gn(e.parameter.description)
2342
+ description: vn(e.parameter.description)
2276
2343
  });
2277
2344
  continue;
2278
2345
  }
2279
- if (e.type === "tool-call" && pn(e.parentToolUseId)) {
2346
+ if (e.type === "tool-call" && gn(e.parentToolUseId)) {
2280
2347
  const r = e.toolUseId ?? e.messageId;
2281
2348
  t.push({
2282
2349
  kind: "toolStart",
@@ -2313,37 +2380,37 @@ function bn(n) {
2313
2380
  }
2314
2381
  return t;
2315
2382
  }
2316
- function vn(n) {
2383
+ function Sn(n) {
2317
2384
  const t = Array.from(n.messages?.values() ?? []).filter(
2318
- (e) => e.type === "tool-call" && e.isComplete && dn(e)
2385
+ (e) => e.type === "tool-call" && e.isComplete && fn(e)
2319
2386
  );
2320
- return hn(t);
2387
+ return pn(t);
2321
2388
  }
2322
- function yn(n) {
2323
- return mn(bn(Array.from(n.messages?.values() ?? [])));
2389
+ function wn(n) {
2390
+ return bn(yn(Array.from(n.messages?.values() ?? [])));
2324
2391
  }
2325
- function Sn(n, t) {
2392
+ function En(n, t) {
2326
2393
  return n === t ? !0 : n.length !== t.length ? !1 : n.every((e, r) => {
2327
2394
  const s = t[r];
2328
2395
  return e.id === s.id && e.status === s.status && e.subject === s.subject && e.activeForm === s.activeForm && e.description === s.description;
2329
2396
  });
2330
2397
  }
2331
- function wn(n, t) {
2398
+ function In(n, t) {
2332
2399
  return n.length !== t.length ? !1 : n.every((e, r) => {
2333
2400
  const s = t[r];
2334
2401
  return e.toolName === s.toolName && e.toolsetName === s.toolsetName && e.status === s.status && e.reason === s.reason;
2335
2402
  });
2336
2403
  }
2337
- function En(n, t) {
2404
+ function Tn(n, t) {
2338
2405
  return n === t ? !0 : n.length !== t.length ? !1 : n.every((e, r) => {
2339
2406
  const s = t[r];
2340
- return e.parentToolUseId === s.parentToolUseId && e.status === s.status && e.subagentType === s.subagentType && e.description === s.description && e.summary === s.summary && wn(e.tools, s.tools);
2407
+ return e.parentToolUseId === s.parentToolUseId && e.status === s.status && e.subagentType === s.subagentType && e.description === s.description && e.summary === s.summary && In(e.tools, s.tools);
2341
2408
  });
2342
2409
  }
2343
- function In(n) {
2344
- const t = new P([]), e = new P([]), r = new R();
2345
- return r.add(n.pipe(N(vn), j(Sn)).subscribe(t)), r.add(
2346
- n.pipe(N(yn), j(En)).subscribe(e)
2410
+ function xn(n) {
2411
+ const t = new C([]), e = new C([]), r = new j();
2412
+ return r.add(n.pipe(N(Sn), M(En)).subscribe(t)), r.add(
2413
+ n.pipe(N(wn), M(Tn)).subscribe(e)
2347
2414
  ), {
2348
2415
  tasks$: t.asObservable(),
2349
2416
  subagents$: e.asObservable(),
@@ -2352,18 +2419,26 @@ function In(n) {
2352
2419
  teardown: () => r.unsubscribe()
2353
2420
  };
2354
2421
  }
2355
- function be(n) {
2422
+ function ve(n) {
2356
2423
  const t = /* @__PURE__ */ new Map();
2357
2424
  for (const e of n) t.set(e.sandboxName, e);
2358
2425
  return [...t.values()].sort(
2359
2426
  (e, r) => (e.sandboxBlueprintName || e.sandboxName).localeCompare(r.sandboxBlueprintName || r.sandboxName)
2360
2427
  );
2361
2428
  }
2429
+ const Q = { kind: null, stopPhase: "idle" }, Cn = 1e4;
2430
+ function On(n, t) {
2431
+ return n.kind === t.kind && n.stopPhase === t.stopPhase && n.requestId === t.requestId;
2432
+ }
2362
2433
  class K {
2363
2434
  client;
2364
2435
  customChannelId;
2365
2436
  customMessageId;
2437
+ // Join-time run state from `GET /channel/metadata` (F-023 AC9): decides whether a rejoin is tailing a
2438
+ // live run (`restore`) or replaying a finished transcript (`replay`).
2439
+ joinRunState;
2366
2440
  isConnecting$;
2441
+ runStatusSubject;
2367
2442
  conversation$;
2368
2443
  channelTitleSubject;
2369
2444
  sandboxPhaseSubject;
@@ -2384,24 +2459,33 @@ class K {
2384
2459
  sandboxPhase$;
2385
2460
  /** Reactive live-sandbox list store (F-019): authoritative from `/channel/metadata`, per-slice; replay-safe. */
2386
2461
  launchedSandboxes$;
2462
+ /** Reactive run identity + stop lifecycle store (F-023): who holds the connection, and is a stop pending. */
2463
+ runStatus$;
2387
2464
  currentUserMessageId;
2388
2465
  // The most-recently-sent user message id. Unlike currentUserMessageId (which
2389
2466
  // is cleared once a traceId is attached), this is kept across the SSE
2390
2467
  // lifecycle so RESPONSE_TOOL_CALL_CONSENT — fired after run.done — can echo
2391
2468
  // back the message id the bot is waiting on.
2392
2469
  lastSentMessageId;
2393
- // The in-flight SSE run's subscription. Held so a user-initiated stop-generation can abort the
2394
- // connection (unsubscribe → create-sse-observable teardown → AbortController.abort()). Cleared on
2395
- // every terminal (complete / error) and on stop.
2470
+ // The in-flight SSE run's subscription. Held so the connection can be aborted locally (unsubscribe →
2471
+ // create-sse-observable teardown → AbortController.abort()) on close, on channel switch, and on the
2472
+ // legacy stop fallback. Cleared on every terminal (complete / error).
2473
+ //
2474
+ // NOTE (F-023): a user-initiated stop no longer unsubscribes this. Runs execute in the background on
2475
+ // the server, so cutting the stream would only stop *watching* — the stop is requested through
2476
+ // `client.suspendChannel()` and declared by this same stream's terminal event.
2396
2477
  currentRun;
2478
+ // Armed when a stop is accepted; fires after FORCE_STOP_TIMEOUT_MS to offer force-stop (F-023 AC7).
2479
+ // Cleared on terminal, on suspend failure, and in close() (§1.5).
2480
+ forceStopTimer;
2397
2481
  constructor(t) {
2398
2482
  if (!t.client)
2399
2483
  throw new Error("client must be required");
2400
2484
  if (!t.customChannelId)
2401
2485
  throw new Error("customChannelId must be required");
2402
- this.client = t.client, this.customChannelId = t.customChannelId, this.customMessageId = t.customMessageId, this.isConnecting$ = new P(!1), this.conversation$ = new P(t.conversation), this.channelTitleSubject = new P(t.channelTitle ?? null), this.sandboxPhaseSubject = new P("idle"), this.launchedSandboxesSubject = new P(
2403
- be(t.launchedSandboxes ?? [])
2404
- ), this.derivedStores = In(this.conversation$), this.tasks$ = this.derivedStores.tasks$, this.subagents$ = this.derivedStores.subagents$, this.channelTitle$ = this.channelTitleSubject.pipe(j()), this.sandboxPhase$ = this.sandboxPhaseSubject.pipe(j()), this.launchedSandboxes$ = this.launchedSandboxesSubject.pipe(j()), this.statesObserver = t.statesObserver;
2486
+ this.client = t.client, this.customChannelId = t.customChannelId, this.customMessageId = t.customMessageId, this.joinRunState = t.runState ?? "IDLE", this.isConnecting$ = new C(!1), this.runStatusSubject = new C(Q), this.conversation$ = new C(t.conversation), this.channelTitleSubject = new C(t.channelTitle ?? null), this.sandboxPhaseSubject = new C("idle"), this.launchedSandboxesSubject = new C(
2487
+ ve(t.launchedSandboxes ?? [])
2488
+ ), this.derivedStores = xn(this.conversation$), this.tasks$ = this.derivedStores.tasks$, this.subagents$ = this.derivedStores.subagents$, this.channelTitle$ = this.channelTitleSubject.pipe(M()), this.sandboxPhase$ = this.sandboxPhaseSubject.pipe(M()), this.launchedSandboxes$ = this.launchedSandboxesSubject.pipe(M()), this.runStatus$ = this.runStatusSubject.pipe(M(On)), this.statesObserver = t.statesObserver;
2405
2489
  }
2406
2490
  /** Current Task Check List snapshot (F-013) — for framework-agnostic `getSnapshot()` bridging. */
2407
2491
  getTasks() {
@@ -2423,6 +2507,10 @@ class K {
2423
2507
  getLaunchedSandboxes() {
2424
2508
  return this.launchedSandboxesSubject.value;
2425
2509
  }
2510
+ /** Current run identity + stop lifecycle snapshot (F-023) — for framework-agnostic `getSnapshot()` bridging. */
2511
+ getRunStatus() {
2512
+ return this.runStatusSubject.value;
2513
+ }
2426
2514
  /** Names hinted by `sandbox.launch` but not yet confirmed live by metadata (F-019) — "starting" placeholders. */
2427
2515
  getPendingLaunches() {
2428
2516
  return this.pendingLaunches;
@@ -2433,7 +2521,7 @@ class K {
2433
2521
  * launch whose name now appears (promoted to live). metadata (heartbeat-backed) is the sole authority.
2434
2522
  */
2435
2523
  applyLaunchedSandboxes(t) {
2436
- const e = be(t);
2524
+ const e = ve(t);
2437
2525
  this.pendingLaunches = this.pendingLaunches.filter((r) => !e.some((s) => s.sandboxName === r)), this.launchedSandboxesSubject.next(e);
2438
2526
  }
2439
2527
  /**
@@ -2494,24 +2582,37 @@ class K {
2494
2582
  }
2495
2583
  }
2496
2584
  subscribe() {
2497
- this.statesSubscription = qt([
2585
+ this.statesSubscription = Wt([
2498
2586
  this.isConnecting$,
2499
2587
  this.conversation$,
2500
2588
  this.derivedStores.tasks$,
2501
2589
  this.derivedStores.subagents$,
2502
2590
  this.channelTitle$,
2503
2591
  this.sandboxPhase$,
2504
- this.launchedSandboxes$
2592
+ this.launchedSandboxes$,
2593
+ this.runStatus$
2505
2594
  ]).pipe(
2506
- N(([t, e, r, s, o, i, a]) => ({
2507
- isConnecting: t,
2508
- conversation: e,
2509
- tasks: r,
2510
- subagents: s,
2511
- channelTitle: o,
2512
- sandboxPhase: i,
2513
- launchedSandboxes: a
2514
- }))
2595
+ N(
2596
+ ([
2597
+ t,
2598
+ e,
2599
+ r,
2600
+ s,
2601
+ o,
2602
+ i,
2603
+ a,
2604
+ c
2605
+ ]) => ({
2606
+ isConnecting: t,
2607
+ conversation: e,
2608
+ tasks: r,
2609
+ subagents: s,
2610
+ channelTitle: o,
2611
+ sandboxPhase: i,
2612
+ launchedSandboxes: a,
2613
+ runStatus: c
2614
+ })
2615
+ )
2515
2616
  ).subscribe(this.statesObserver);
2516
2617
  }
2517
2618
  /**
@@ -2535,14 +2636,14 @@ class K {
2535
2636
  */
2536
2637
  updateSandboxPhase(t) {
2537
2638
  switch (t) {
2538
- case d.SANDBOX_LAUNCH:
2639
+ case l.SANDBOX_LAUNCH:
2539
2640
  this.sandboxPhaseSubject.next("launching");
2540
2641
  break;
2541
- case d.SANDBOX_READY:
2642
+ case l.SANDBOX_READY:
2542
2643
  this.sandboxPhaseSubject.next("ready");
2543
2644
  break;
2544
- case d.INIT:
2545
- case d.ERROR:
2645
+ case l.INIT:
2646
+ case l.ERROR:
2546
2647
  this.sandboxPhaseSubject.next("idle");
2547
2648
  break;
2548
2649
  }
@@ -2556,9 +2657,9 @@ class K {
2556
2657
  return {
2557
2658
  onSseStart: t?.onSseStart,
2558
2659
  onSseMessage: (s) => {
2559
- if (t?.onSseMessage?.(s), s.eventType === d.CHANNEL_TITLE_UPDATE && this.channelTitleSubject.next(
2660
+ if (t?.onSseMessage?.(s), this.captureRequestId(s.requestId), s.eventType === l.CHANNEL_TITLE_UPDATE && this.channelTitleSubject.next(
2560
2661
  s.fact.channelTitleUpdate.title
2561
- ), this.updateSandboxPhase(s.eventType), s.eventType === d.SANDBOX_LAUNCH && this.noteSandboxLaunch(s.fact.sandboxLaunch.sandboxName), this.currentUserMessageId && s.traceId) {
2662
+ ), this.updateSandboxPhase(s.eventType), s.eventType === l.SANDBOX_LAUNCH && this.noteSandboxLaunch(s.fact.sandboxLaunch.sandboxName), this.currentUserMessageId && s.traceId) {
2562
2663
  const o = new Map(this.conversation$.value.messages), i = o.get(this.currentUserMessageId);
2563
2664
  i && i.type === "user" && (o.set(this.currentUserMessageId, {
2564
2665
  ...i,
@@ -2568,16 +2669,33 @@ class K {
2568
2669
  this.conversation$.next(this.conversation$.value.onMessage(s));
2569
2670
  },
2570
2671
  onSseError: (s) => {
2571
- t?.onSseError?.(s), this.isConnecting$.next(!1), this.currentUserMessageId = void 0, this.currentRun = void 0, r(s);
2672
+ t?.onSseError?.(s), this.settleRun(), r(s);
2572
2673
  },
2573
2674
  onSseCompleted: () => {
2574
- t?.onSseCompleted?.(), this.isConnecting$.next(!1), this.currentUserMessageId = void 0, this.currentRun = void 0, e();
2675
+ t?.onSseCompleted?.(), this.settleRun(), e();
2575
2676
  }
2576
2677
  };
2577
2678
  }
2578
- fetchSse(t, e) {
2579
- return new Promise((r, s) => {
2580
- this.isConnecting$.next(!0), this.currentRun = this.client.fetchSse(t, this.buildRunHandlers(e, r, s));
2679
+ /**
2680
+ * The terminal of a run, whichever way it ended. For a stop in flight this is the moment the backend
2681
+ * declares the run actually finished (F-023 AC3) the same event a normal run ends with — so it is
2682
+ * the only place `stopping` is released back to "waiting for input".
2683
+ */
2684
+ settleRun() {
2685
+ const t = this.runStatusSubject.value.stopPhase !== "idle";
2686
+ this.clearForceStopTimer(), this.isConnecting$.next(!1), this.runStatusSubject.next(Q), this.currentUserMessageId = void 0, this.currentRun = void 0, t && this.conversation$.next(this.conversation$.value.settleInFlightMessages());
2687
+ }
2688
+ /** Record the backend run id from the first frame that carries one; later frames must not overwrite it. */
2689
+ captureRequestId(t) {
2690
+ const e = this.runStatusSubject.value;
2691
+ !t || e.requestId || !e.kind || this.runStatusSubject.next({ ...e, requestId: t });
2692
+ }
2693
+ clearForceStopTimer() {
2694
+ this.forceStopTimer && (clearTimeout(this.forceStopTimer), this.forceStopTimer = void 0);
2695
+ }
2696
+ fetchSse(t, e, r) {
2697
+ return new Promise((s, o) => {
2698
+ this.isConnecting$.next(!0), this.runStatusSubject.next({ kind: t, stopPhase: "idle" }), this.currentRun = this.client.fetchSse(e, this.buildRunHandlers(r, s, o));
2581
2699
  });
2582
2700
  }
2583
2701
  /**
@@ -2592,11 +2710,15 @@ class K {
2592
2710
  e();
2593
2711
  return;
2594
2712
  }
2595
- this.isConnecting$.next(!0), this.currentRun = this.client.rejoinSse(this.customChannelId, this.buildRunHandlers(t, e, r));
2713
+ this.isConnecting$.next(!0), this.runStatusSubject.next({
2714
+ kind: this.joinRunState === "RUNNING" ? "restore" : "replay",
2715
+ stopPhase: "idle"
2716
+ }), this.currentRun = this.client.rejoinSse(this.customChannelId, this.buildRunHandlers(t, e, r));
2596
2717
  });
2597
2718
  }
2598
2719
  resetChannel(t, e) {
2599
2720
  return this.fetchSse(
2721
+ "reset",
2600
2722
  {
2601
2723
  action: $.RESET_CHANNEL,
2602
2724
  customChannelId: this.customChannelId,
@@ -2608,24 +2730,27 @@ class K {
2608
2730
  );
2609
2731
  }
2610
2732
  sendMessage(t, e) {
2611
- const r = t.text.trim(), s = t.customMessageId ?? Fe();
2612
- return this.currentUserMessageId = s, this.lastSentMessageId = s, this.conversation$.next(
2733
+ const r = this.runStatusSubject.value.kind;
2734
+ if (r) return Promise.reject(new ye(r));
2735
+ const s = t.text.trim(), o = t.customMessageId ?? Ge();
2736
+ return this.currentUserMessageId = o, this.lastSentMessageId = o, this.conversation$.next(
2613
2737
  this.conversation$.value.pushMessage({
2614
2738
  type: "user",
2615
- messageId: s,
2616
- text: r,
2739
+ messageId: o,
2740
+ text: s,
2617
2741
  blobIds: t.blobIds,
2618
2742
  filePreviewUrls: t.filePreviewUrls,
2619
2743
  documentNames: t.documentNames,
2620
2744
  time: /* @__PURE__ */ new Date()
2621
2745
  })
2622
2746
  ), this.fetchSse(
2747
+ "user",
2623
2748
  {
2624
2749
  action: $.NONE,
2625
2750
  customChannelId: this.customChannelId,
2626
- customMessageId: s,
2751
+ customMessageId: o,
2627
2752
  payload: this.resolvePayload(t?.payload),
2628
- text: r,
2753
+ text: s,
2629
2754
  blobIds: t?.blobIds
2630
2755
  },
2631
2756
  e
@@ -2633,6 +2758,7 @@ class K {
2633
2758
  }
2634
2759
  replyToolCallConsents(t, e, r) {
2635
2760
  return this.conversation$.next(this.conversation$.value.clearPendingConsent()), this.fetchSse(
2761
+ "user",
2636
2762
  {
2637
2763
  action: $.RESPONSE_TOOL_CALL_CONSENT,
2638
2764
  customChannelId: this.customChannelId,
@@ -2652,6 +2778,7 @@ class K {
2652
2778
  */
2653
2779
  nudge(t) {
2654
2780
  return this.fetchSse(
2781
+ "nudge",
2655
2782
  {
2656
2783
  action: $.NUDGE,
2657
2784
  customChannelId: this.customChannelId,
@@ -2662,19 +2789,80 @@ class K {
2662
2789
  );
2663
2790
  }
2664
2791
  /**
2665
- * User-initiated stop-generation: abort the in-flight SSE run (if any) and release the input.
2666
- * Unsubscribing tears down the SSE observable → AbortController.abort() cuts the HTTP stream. The
2667
- * partial assistant message already received stays in the conversation (frozen, not deleted). A no-op
2668
- * when nothing is running.
2792
+ * User-initiated stop-generation (F-023).
2793
+ *
2794
+ * Runs execute in the **background on the server**, so aborting the local SSE connection would only
2795
+ * stop *watching*: the agent would keep running, keep spending tokens and keep writing the
2796
+ * transcript. Instead this asks the backend to suspend the run and **keeps the stream open**, because
2797
+ * the stop is declared by that stream's terminal event — the same event a normal run ends with.
2798
+ *
2799
+ * The call is therefore asynchronous in two stages:
2800
+ * 1. resolving here means the backend **accepted** the request, not that the run has stopped;
2801
+ * 2. `isConnecting` / `runStatus` only return to idle when the terminal event arrives (AC3).
2802
+ *
2803
+ * While waiting, `runStatus.stopPhase` is `stopping` and every send entrance must stay gated (AC5).
2804
+ * If the terminal event has not arrived within {@link FORCE_STOP_TIMEOUT_MS} the phase becomes
2805
+ * `force-stoppable`, and calling again with `{ force: true }` tells the backend to give up on the run
2806
+ * rather than let it wind down (AC7).
2807
+ *
2808
+ * No-ops (resolving) when nothing is running, when the run is not the user's own — a `RESET_CHANNEL`
2809
+ * welcome, a transcript replay or an invisible nudge must never be stopped (AC8) — or when a stop is
2810
+ * already pending and this is not a force.
2811
+ *
2812
+ * **Rejects** when the suspend request fails (network error, or a non-2xx that is not `404`). The
2813
+ * stop phase is rolled back to `idle` first, so the caller can retry and the UI can never be stuck in
2814
+ * `stopping` (AC4).
2815
+ *
2816
+ * A client that predates the suspend endpoint (a custom `IAsgardServiceClient`) falls back to the old
2817
+ * local-abort behavior, so existing integrations keep working.
2818
+ */
2819
+ async stopGeneration(t) {
2820
+ const e = this.runStatusSubject.value;
2821
+ if (!(!this.currentRun || e.kind !== "user") && !(e.stopPhase !== "idle" && !t?.force)) {
2822
+ if (!this.client.suspendChannel) {
2823
+ this.abortConnection();
2824
+ return;
2825
+ }
2826
+ this.clearForceStopTimer(), this.runStatusSubject.next({ ...e, stopPhase: "stopping" });
2827
+ try {
2828
+ await this.client.suspendChannel(this.customChannelId, {
2829
+ requestId: e.requestId,
2830
+ force: t?.force
2831
+ });
2832
+ } catch (r) {
2833
+ throw this.clearForceStopTimer(), this.runStatusSubject.next({ ...this.runStatusSubject.value, stopPhase: "idle" }), r;
2834
+ }
2835
+ this.armForceStopTimer();
2836
+ }
2837
+ }
2838
+ /**
2839
+ * Escalate to `force-stoppable` once an accepted stop has waited too long for the terminal event
2840
+ * (F-023 AC7 / UC-044) — the escape hatch for an agent that never winds down. Re-armed on a force
2841
+ * retry, so a second timeout offers the same way out again.
2842
+ */
2843
+ armForceStopTimer() {
2844
+ this.clearForceStopTimer(), this.forceStopTimer = setTimeout(() => {
2845
+ this.forceStopTimer = void 0;
2846
+ const t = this.runStatusSubject.value;
2847
+ t.stopPhase === "stopping" && this.runStatusSubject.next({ ...t, stopPhase: "force-stoppable" });
2848
+ }, Cn);
2849
+ }
2850
+ /**
2851
+ * Cut the local SSE connection without telling the backend. This is *not* stop-generation (see
2852
+ * {@link stopGeneration}) — the server-side run keeps going. Used when there is nothing to stop
2853
+ * remotely: a client without suspend support, and channel teardown.
2854
+ *
2855
+ * The deliberate abort must never be read as a transport failure — `create-sse-observable` marks the
2856
+ * stream disposed so no reconnect is attempted (F-023 AC10).
2669
2857
  */
2670
- stopGeneration() {
2671
- this.currentRun && (this.currentRun.unsubscribe(), this.currentRun = void 0, this.isConnecting$.next(!1), this.currentUserMessageId = void 0, this.conversation$.next(this.conversation$.value.cancelInFlightToolCalls()));
2858
+ abortConnection() {
2859
+ this.currentRun && (this.currentRun.unsubscribe(), this.clearForceStopTimer(), this.currentRun = void 0, this.isConnecting$.next(!1), this.runStatusSubject.next(Q), this.currentUserMessageId = void 0, this.conversation$.next(this.conversation$.value.settleInFlightMessages()));
2672
2860
  }
2673
2861
  close() {
2674
- this.currentRun?.unsubscribe(), this.currentRun = void 0, this.isConnecting$.complete(), this.conversation$.complete(), this.channelTitleSubject.complete(), this.sandboxPhaseSubject.complete(), this.launchedSandboxesSubject.complete(), this.derivedStores.teardown(), this.statesSubscription?.unsubscribe();
2862
+ 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();
2675
2863
  }
2676
2864
  }
2677
- function Cn(n) {
2865
+ function Ln(n) {
2678
2866
  const t = /^sandbox:\/\/([^/]+)\/([^?#]+)(?:\?([^#]*))?/.exec(n.trim());
2679
2867
  if (!t) return null;
2680
2868
  const e = decodeURIComponent(t[1]), r = t[2], s = new URLSearchParams(t[3] ?? "");
@@ -2686,27 +2874,29 @@ function Cn(n) {
2686
2874
  return null;
2687
2875
  }
2688
2876
  export {
2689
- xn as AsgardServiceClient,
2877
+ _n as AsgardServiceClient,
2690
2878
  K as Channel,
2879
+ ye as ChannelBusyError,
2691
2880
  v as Conversation,
2692
- d as EventType,
2881
+ l as EventType,
2693
2882
  $ as FetchSseAction,
2694
2883
  w as HttpError,
2695
- qe as MessageTemplateType,
2696
- Ke as ToolCallConsentResult,
2697
- bn as conversationToSubagentEvents,
2698
- In as createDerivedStores,
2699
- yn as deriveSubagents,
2700
- vn as deriveTasks,
2701
- fn as isAgentTool,
2702
- Tn as isHttpError,
2703
- pn as isSubagentChildTool,
2704
- dn as isTaskTool,
2705
- be as reconcileLaunched,
2706
- mn as reduceSubagents,
2707
- hn as reduceTaskEvents,
2708
- Cn as resolveSandboxUri,
2709
- En as subagentsEqual,
2710
- Sn as tasksEqual
2884
+ We as MessageTemplateType,
2885
+ Ye as ToolCallConsentResult,
2886
+ yn as conversationToSubagentEvents,
2887
+ xn as createDerivedStores,
2888
+ wn as deriveSubagents,
2889
+ Sn as deriveTasks,
2890
+ mn as isAgentTool,
2891
+ Pn as isChannelBusyError,
2892
+ An as isHttpError,
2893
+ gn as isSubagentChildTool,
2894
+ fn as isTaskTool,
2895
+ ve as reconcileLaunched,
2896
+ bn as reduceSubagents,
2897
+ pn as reduceTaskEvents,
2898
+ Ln as resolveSandboxUri,
2899
+ Tn as subagentsEqual,
2900
+ En as tasksEqual
2711
2901
  };
2712
2902
  //# sourceMappingURL=index.mjs.map