@asgard-js/core 0.3.81 → 0.3.83

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
@@ -16,7 +16,7 @@ class y extends Error {
16
16
  super(`HTTP ${t}: ${e}`), this.name = "HttpError", this.status = t, this.statusText = e, this.body = s;
17
17
  }
18
18
  }
19
- function On(n) {
19
+ function kn(n) {
20
20
  return n instanceof y;
21
21
  }
22
22
  class te extends Error {
@@ -26,7 +26,7 @@ class te extends Error {
26
26
  super(`Cannot send a message while a "${t}" run is in flight on this channel.`), this.name = "ChannelBusyError", this.runKind = t;
27
27
  }
28
28
  }
29
- function kn(n) {
29
+ function Pn(n) {
30
30
  return n instanceof te;
31
31
  }
32
32
  class ne extends Error {
@@ -43,20 +43,20 @@ class ne extends Error {
43
43
  super("Cannot send this turn while the channel is awaiting a tool-call consent response."), this.name = "ChannelAwaitingConsentError", this.processId = t;
44
44
  }
45
45
  }
46
- function Pn(n) {
46
+ function _n(n) {
47
47
  return n instanceof ne;
48
48
  }
49
- var H = /* @__PURE__ */ ((n) => (n.RESET_CHANNEL = "RESET_CHANNEL", n.NONE = "NONE", n.RESPONSE_TOOL_CALL_CONSENT = "RESPONSE_TOOL_CALL_CONSENT", n.NUDGE = "NUDGE", n))(H || {}), 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.MESSAGE_CANVAS_START = "asgard.message.canvas.start", n.MESSAGE_CANVAS_DELTA = "asgard.message.canvas.delta", n.MESSAGE_CANVAS_COMPLETE = "asgard.message.canvas.complete", n.TOOL_CALL = "asgard.tool_call", n.TOOL_CALL_START = "asgard.tool_call.start", n.TOOL_CALL_COMPLETE = "asgard.tool_call.complete", n.TOOL_CALL_CONSENT = "asgard.tool_call.consent", n.SUBAGENT_START = "asgard.subagent.start", n.SUBAGENT_COMPLETE = "asgard.subagent.complete", n.CHANNEL_TITLE_UPDATE = "asgard.channel.title.update", n.PROMPT_SUGGESTION = "asgard.prompt_suggestion", n.SANDBOX_LAUNCH = "asgard.sandbox.launch", n.SANDBOX_READY = "asgard.sandbox.ready", n.MESSAGE_FEEDBACK = "asgard.message.feedback", 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 || {}), Te = /* @__PURE__ */ ((n) => (n.TEXT = "TEXT", n.HINT = "HINT", n.BUTTON = "BUTTON", n.IMAGE = "IMAGE", n.VIDEO = "VIDEO", n.AUDIO = "AUDIO", n.LOCATION = "LOCATION", n.CAROUSEL = "CAROUSEL", n.CHART = "CHART", n.TABLE = "TABLE", n.ATTACHMENT = "ATTACHMENT", n.QUESTION = "QUESTION", n.CANVAS = "CANVAS", n))(Te || {});
50
- async function ze(n, t) {
49
+ var H = /* @__PURE__ */ ((n) => (n.RESET_CHANNEL = "RESET_CHANNEL", n.NONE = "NONE", n.RESPONSE_TOOL_CALL_CONSENT = "RESPONSE_TOOL_CALL_CONSENT", n.NUDGE = "NUDGE", n))(H || {}), 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.MESSAGE_CANVAS_START = "asgard.message.canvas.start", n.MESSAGE_CANVAS_DELTA = "asgard.message.canvas.delta", n.MESSAGE_CANVAS_COMPLETE = "asgard.message.canvas.complete", n.TOOL_CALL = "asgard.tool_call", n.TOOL_CALL_START = "asgard.tool_call.start", n.TOOL_CALL_COMPLETE = "asgard.tool_call.complete", n.TOOL_CALL_CONSENT = "asgard.tool_call.consent", n.SUBAGENT_START = "asgard.subagent.start", n.SUBAGENT_COMPLETE = "asgard.subagent.complete", n.CHANNEL_TITLE_UPDATE = "asgard.channel.title.update", n.PROMPT_SUGGESTION = "asgard.prompt_suggestion", n.SANDBOX_LAUNCH = "asgard.sandbox.launch", n.SANDBOX_READY = "asgard.sandbox.ready", n.MESSAGE_FEEDBACK = "asgard.message.feedback", n.DONE = "asgard.run.done", n.ERROR = "asgard.run.error", n))(l || {}), ze = /* @__PURE__ */ ((n) => (n.ALLOW_ONCE = "ALLOW_ONCE", n.ALLOW_ALWAYS = "ALLOW_ALWAYS", n.DENY_ONCE = "DENY_ONCE", n))(ze || {}), Ce = /* @__PURE__ */ ((n) => (n.TEXT = "TEXT", n.HINT = "HINT", n.BUTTON = "BUTTON", n.IMAGE = "IMAGE", n.VIDEO = "VIDEO", n.AUDIO = "AUDIO", n.LOCATION = "LOCATION", n.CAROUSEL = "CAROUSEL", n.CHART = "CHART", n.TABLE = "TABLE", n.ATTACHMENT = "ATTACHMENT", n.QUESTION = "QUESTION", n.CANVAS = "CANVAS", n))(Ce || {});
50
+ async function Je(n, t) {
51
51
  const e = n.getReader();
52
52
  let s;
53
53
  for (; !(s = await e.read()).done; )
54
54
  t(s.value);
55
55
  }
56
- function Je(n) {
56
+ function Qe(n) {
57
57
  let t, e, s, r = !1;
58
58
  return function(a) {
59
- t === void 0 ? (t = a, e = 0, s = -1) : t = Ze(t, a);
59
+ t === void 0 ? (t = a, e = 0, s = -1) : t = et(t, a);
60
60
  const o = t.length;
61
61
  let c = 0;
62
62
  for (; e < o; ) {
@@ -80,7 +80,7 @@ function Je(n) {
80
80
  c === o ? t = void 0 : c !== 0 && (t = t.subarray(c), e -= c);
81
81
  };
82
82
  }
83
- function Qe(n, t, e) {
83
+ function Ze(n, t, e) {
84
84
  let s = le();
85
85
  const r = new TextDecoder();
86
86
  return function(a, o) {
@@ -107,7 +107,7 @@ function Qe(n, t, e) {
107
107
  }
108
108
  };
109
109
  }
110
- function Ze(n, t) {
110
+ function et(n, t) {
111
111
  const e = new Uint8Array(n.length + t.length);
112
112
  return e.set(n), e.set(t, n.length), e;
113
113
  }
@@ -119,7 +119,7 @@ function le() {
119
119
  retry: void 0
120
120
  };
121
121
  }
122
- var et = function(n, t) {
122
+ var tt = function(n, t) {
123
123
  var e = {};
124
124
  for (var s in n) Object.prototype.hasOwnProperty.call(n, s) && t.indexOf(s) < 0 && (e[s] = n[s]);
125
125
  if (n != null && typeof Object.getOwnPropertySymbols == "function")
@@ -127,9 +127,9 @@ var et = function(n, t) {
127
127
  t.indexOf(s[r]) < 0 && Object.prototype.propertyIsEnumerable.call(n, s[r]) && (e[s[r]] = n[s[r]]);
128
128
  return e;
129
129
  };
130
- const se = "text/event-stream", tt = 1e3, de = "last-event-id";
131
- function Ce(n, t) {
132
- var { signal: e, headers: s, onopen: r, onmessage: i, onclose: a, onerror: o, openWhenHidden: c, fetch: u } = t, d = et(t, ["signal", "headers", "onopen", "onmessage", "onclose", "onerror", "openWhenHidden", "fetch"]);
130
+ const se = "text/event-stream", nt = 1e3, de = "last-event-id";
131
+ function xe(n, t) {
132
+ var { signal: e, headers: s, onopen: r, onmessage: i, onclose: a, onerror: o, openWhenHidden: c, fetch: u } = t, d = tt(t, ["signal", "headers", "onopen", "onmessage", "onclose", "onerror", "openWhenHidden", "fetch"]);
133
133
  return new Promise((m, v) => {
134
134
  const h = Object.assign({}, s);
135
135
  h.accept || (h.accept = se);
@@ -138,20 +138,20 @@ function Ce(n, t) {
138
138
  p.abort(), document.hidden || F();
139
139
  }
140
140
  c || document.addEventListener("visibilitychange", f);
141
- let I = tt, E = 0;
141
+ let I = nt, E = 0;
142
142
  function B() {
143
143
  document.removeEventListener("visibilitychange", f), window.clearTimeout(E), p.abort();
144
144
  }
145
145
  e?.addEventListener("abort", () => {
146
146
  B(), m();
147
147
  });
148
- const R = u ?? window.fetch, _ = r ?? nt;
148
+ const R = u ?? window.fetch, _ = r ?? st;
149
149
  async function F() {
150
150
  var j;
151
151
  p = new AbortController();
152
152
  try {
153
153
  const $ = await R(n, Object.assign(Object.assign({}, d), { headers: h, signal: p.signal }));
154
- await _($), await ze($.body, Je(Qe((k) => {
154
+ await _($), await Je($.body, Qe(Ze((k) => {
155
155
  k ? h[de] = k : delete h[de];
156
156
  }, (k) => {
157
157
  I = k;
@@ -169,7 +169,7 @@ function Ce(n, t) {
169
169
  F();
170
170
  });
171
171
  }
172
- function nt(n) {
172
+ function st(n) {
173
173
  const t = n.headers.get("content-type");
174
174
  if (!t?.startsWith(se))
175
175
  throw new Error(`Expected content-type to be ${se}, Actual: ${t}`);
@@ -190,7 +190,7 @@ function O(n, t) {
190
190
  }
191
191
  n.prototype = t === null ? Object.create(t) : (e.prototype = t.prototype, new e());
192
192
  }
193
- function st(n, t, e, s) {
193
+ function rt(n, t, e, s) {
194
194
  function r(i) {
195
195
  return i instanceof e ? i : new e(function(a) {
196
196
  a(i);
@@ -217,7 +217,7 @@ function st(n, t, e, s) {
217
217
  u((s = s.apply(n, t || [])).next());
218
218
  });
219
219
  }
220
- function xe(n, t) {
220
+ function Ae(n, t) {
221
221
  var e = { label: 0, sent: function() {
222
222
  if (i[0] & 1) throw i[1];
223
223
  return i[1];
@@ -277,7 +277,7 @@ function xe(n, t) {
277
277
  return { value: u[0] ? u[1] : void 0, done: !0 };
278
278
  }
279
279
  }
280
- function L(n) {
280
+ function U(n) {
281
281
  var t = typeof Symbol == "function" && Symbol.iterator, e = t && n[t], s = 0;
282
282
  if (e) return e.call(n);
283
283
  if (n && typeof n.length == "number") return {
@@ -312,7 +312,7 @@ function K(n, t, e) {
312
312
  function D(n) {
313
313
  return this instanceof D ? (this.v = n, this) : new D(n);
314
314
  }
315
- function rt(n, t, e) {
315
+ function it(n, t, e) {
316
316
  if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
317
317
  var s = e.apply(n, t || []), r, i = [];
318
318
  return r = Object.create((typeof AsyncIterator == "function" ? AsyncIterator : Object).prototype), o("next"), o("throw"), o("return", a), r[Symbol.asyncIterator] = function() {
@@ -350,10 +350,10 @@ function rt(n, t, e) {
350
350
  h(p), i.shift(), i.length && c(i[0][0], i[0][1]);
351
351
  }
352
352
  }
353
- function it(n) {
353
+ function at(n) {
354
354
  if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
355
355
  var t = n[Symbol.asyncIterator], e;
356
- return t ? t.call(n) : (n = typeof L == "function" ? L(n) : n[Symbol.iterator](), e = {}, s("next"), s("throw"), s("return"), e[Symbol.asyncIterator] = function() {
356
+ return t ? t.call(n) : (n = typeof U == "function" ? U(n) : n[Symbol.iterator](), e = {}, s("next"), s("throw"), s("return"), e[Symbol.asyncIterator] = function() {
357
357
  return this;
358
358
  }, e);
359
359
  function s(i) {
@@ -372,13 +372,13 @@ function it(n) {
372
372
  function b(n) {
373
373
  return typeof n == "function";
374
374
  }
375
- function Ae(n) {
375
+ function Oe(n) {
376
376
  var t = function(s) {
377
377
  Error.call(s), s.stack = new Error().stack;
378
378
  }, e = n(t);
379
379
  return e.prototype = Object.create(Error.prototype), e.prototype.constructor = e, e;
380
380
  }
381
- var Q = Ae(function(n) {
381
+ var Q = Oe(function(n) {
382
382
  return function(e) {
383
383
  n(this), this.message = e ? e.length + ` errors occurred during unsubscription:
384
384
  ` + e.map(function(s, r) {
@@ -393,7 +393,7 @@ function V(n, t) {
393
393
  0 <= e && n.splice(e, 1);
394
394
  }
395
395
  }
396
- var U = (function() {
396
+ var L = (function() {
397
397
  function n(t) {
398
398
  this.initialTeardown = t, this.closed = !1, this._parentage = null, this._finalizers = null;
399
399
  }
@@ -405,7 +405,7 @@ var U = (function() {
405
405
  if (a)
406
406
  if (this._parentage = null, Array.isArray(a))
407
407
  try {
408
- for (var o = L(a), c = o.next(); !c.done; c = o.next()) {
408
+ for (var o = U(a), c = o.next(); !c.done; c = o.next()) {
409
409
  var u = c.value;
410
410
  u.remove(this);
411
411
  }
@@ -431,7 +431,7 @@ var U = (function() {
431
431
  if (m) {
432
432
  this._finalizers = null;
433
433
  try {
434
- for (var v = L(m), h = v.next(); !h.done; h = v.next()) {
434
+ for (var v = U(m), h = v.next(); !h.done; h = v.next()) {
435
435
  var p = h.value;
436
436
  try {
437
437
  he(p);
@@ -481,16 +481,16 @@ var U = (function() {
481
481
  var t = new n();
482
482
  return t.closed = !0, t;
483
483
  })(), n;
484
- })(), Oe = U.EMPTY;
485
- function ke(n) {
486
- return n instanceof U || n && "closed" in n && b(n.remove) && b(n.add) && b(n.unsubscribe);
484
+ })(), ke = L.EMPTY;
485
+ function Pe(n) {
486
+ return n instanceof L || n && "closed" in n && b(n.remove) && b(n.add) && b(n.unsubscribe);
487
487
  }
488
488
  function he(n) {
489
489
  b(n) ? n() : n.unsubscribe();
490
490
  }
491
- var at = {
491
+ var ot = {
492
492
  Promise: void 0
493
- }, ot = {
493
+ }, ct = {
494
494
  setTimeout: function(n, t) {
495
495
  for (var e = [], s = 2; s < arguments.length; s++)
496
496
  e[s - 2] = arguments[s];
@@ -501,21 +501,21 @@ var at = {
501
501
  },
502
502
  delegate: void 0
503
503
  };
504
- function Pe(n) {
505
- ot.setTimeout(function() {
504
+ function _e(n) {
505
+ ct.setTimeout(function() {
506
506
  throw n;
507
507
  });
508
508
  }
509
509
  function ie() {
510
510
  }
511
- function W(n) {
511
+ function X(n) {
512
512
  n();
513
513
  }
514
514
  var oe = (function(n) {
515
515
  O(t, n);
516
516
  function t(e) {
517
517
  var s = n.call(this) || this;
518
- return s.isStopped = !1, e ? (s.destination = e, ke(e) && e.add(s)) : s.destination = lt, s;
518
+ return s.isStopped = !1, e ? (s.destination = e, Pe(e) && e.add(s)) : s.destination = dt, s;
519
519
  }
520
520
  return t.create = function(e, s, r) {
521
521
  return new ae(e, s, r);
@@ -542,7 +542,7 @@ var oe = (function(n) {
542
542
  this.unsubscribe();
543
543
  }
544
544
  }, t;
545
- })(U), ct = (function() {
545
+ })(L), ut = (function() {
546
546
  function n(t) {
547
547
  this.partialObserver = t;
548
548
  }
@@ -552,7 +552,7 @@ var oe = (function(n) {
552
552
  try {
553
553
  e.next(t);
554
554
  } catch (s) {
555
- X(s);
555
+ W(s);
556
556
  }
557
557
  }, n.prototype.error = function(t) {
558
558
  var e = this.partialObserver;
@@ -560,17 +560,17 @@ var oe = (function(n) {
560
560
  try {
561
561
  e.error(t);
562
562
  } catch (s) {
563
- X(s);
563
+ W(s);
564
564
  }
565
565
  else
566
- X(t);
566
+ W(t);
567
567
  }, n.prototype.complete = function() {
568
568
  var t = this.partialObserver;
569
569
  if (t.complete)
570
570
  try {
571
571
  t.complete();
572
572
  } catch (e) {
573
- X(e);
573
+ W(e);
574
574
  }
575
575
  }, n;
576
576
  })(), ae = (function(n) {
@@ -581,20 +581,20 @@ var oe = (function(n) {
581
581
  next: e ?? void 0,
582
582
  error: s ?? void 0,
583
583
  complete: r ?? void 0
584
- } : a = e, i.destination = new ct(a), i;
584
+ } : a = e, i.destination = new ut(a), i;
585
585
  }
586
586
  return t;
587
587
  })(oe);
588
- function X(n) {
589
- Pe(n);
588
+ function W(n) {
589
+ _e(n);
590
590
  }
591
- function ut(n) {
591
+ function lt(n) {
592
592
  throw n;
593
593
  }
594
- var lt = {
594
+ var dt = {
595
595
  closed: !0,
596
596
  next: ie,
597
- error: ut,
597
+ error: lt,
598
598
  complete: ie
599
599
  }, ce = (function() {
600
600
  return typeof Symbol == "function" && Symbol.observable || "@@observable";
@@ -602,7 +602,7 @@ var lt = {
602
602
  function z(n) {
603
603
  return n;
604
604
  }
605
- function dt(n) {
605
+ function ht(n) {
606
606
  return n.length === 0 ? z : n.length === 1 ? n[0] : function(e) {
607
607
  return n.reduce(function(s, r) {
608
608
  return r(s);
@@ -617,8 +617,8 @@ var w = (function() {
617
617
  var e = new n();
618
618
  return e.source = this, e.operator = t, e;
619
619
  }, n.prototype.subscribe = function(t, e, s) {
620
- var r = this, i = ft(t) ? t : new ae(t, e, s);
621
- return W(function() {
620
+ var r = this, i = pt(t) ? t : new ae(t, e, s);
621
+ return X(function() {
622
622
  var a = r, o = a.operator, c = a.source;
623
623
  i.add(o ? o.call(i, c) : c ? r._subscribe(i) : r._trySubscribe(i));
624
624
  }), i;
@@ -652,7 +652,7 @@ var w = (function() {
652
652
  }, n.prototype.pipe = function() {
653
653
  for (var t = [], e = 0; e < arguments.length; e++)
654
654
  t[e] = arguments[e];
655
- return dt(t)(this);
655
+ return ht(t)(this);
656
656
  }, n.prototype.toPromise = function(t) {
657
657
  var e = this;
658
658
  return t = fe(t), new t(function(s, r) {
@@ -671,20 +671,20 @@ var w = (function() {
671
671
  })();
672
672
  function fe(n) {
673
673
  var t;
674
- return (t = n ?? at.Promise) !== null && t !== void 0 ? t : Promise;
675
- }
676
- function ht(n) {
677
- return n && b(n.next) && b(n.error) && b(n.complete);
674
+ return (t = n ?? ot.Promise) !== null && t !== void 0 ? t : Promise;
678
675
  }
679
676
  function ft(n) {
680
- return n && n instanceof oe || ht(n) && ke(n);
677
+ return n && b(n.next) && b(n.error) && b(n.complete);
681
678
  }
682
679
  function pt(n) {
680
+ return n && n instanceof oe || ft(n) && Pe(n);
681
+ }
682
+ function gt(n) {
683
683
  return b(n?.lift);
684
684
  }
685
685
  function P(n) {
686
686
  return function(t) {
687
- if (pt(t))
687
+ if (gt(t))
688
688
  return t.lift(function(e) {
689
689
  try {
690
690
  return n(e, this);
@@ -696,9 +696,9 @@ function P(n) {
696
696
  };
697
697
  }
698
698
  function N(n, t, e, s, r) {
699
- return new gt(n, t, e, s, r);
699
+ return new mt(n, t, e, s, r);
700
700
  }
701
- var gt = (function(n) {
701
+ var mt = (function(n) {
702
702
  O(t, n);
703
703
  function t(e, s, r, i, a, o) {
704
704
  var c = n.call(this, e) || this;
@@ -733,7 +733,7 @@ var gt = (function(n) {
733
733
  n.prototype.unsubscribe.call(this), !s && ((e = this.onFinalize) === null || e === void 0 || e.call(this));
734
734
  }
735
735
  }, t;
736
- })(oe), mt = Ae(function(n) {
736
+ })(oe), bt = Oe(function(n) {
737
737
  return function() {
738
738
  n(this), this.name = "ObjectUnsubscribedError", this.message = "object unsubscribed";
739
739
  };
@@ -748,15 +748,15 @@ var gt = (function(n) {
748
748
  return s.operator = e, s;
749
749
  }, t.prototype._throwIfClosed = function() {
750
750
  if (this.closed)
751
- throw new mt();
751
+ throw new bt();
752
752
  }, t.prototype.next = function(e) {
753
753
  var s = this;
754
- W(function() {
754
+ X(function() {
755
755
  var r, i;
756
756
  if (s._throwIfClosed(), !s.isStopped) {
757
757
  s.currentObservers || (s.currentObservers = Array.from(s.observers));
758
758
  try {
759
- for (var a = L(s.currentObservers), o = a.next(); !o.done; o = a.next()) {
759
+ for (var a = U(s.currentObservers), o = a.next(); !o.done; o = a.next()) {
760
760
  var c = o.value;
761
761
  c.next(e);
762
762
  }
@@ -773,7 +773,7 @@ var gt = (function(n) {
773
773
  });
774
774
  }, t.prototype.error = function(e) {
775
775
  var s = this;
776
- W(function() {
776
+ X(function() {
777
777
  if (s._throwIfClosed(), !s.isStopped) {
778
778
  s.hasError = s.isStopped = !0, s.thrownError = e;
779
779
  for (var r = s.observers; r.length; )
@@ -782,7 +782,7 @@ var gt = (function(n) {
782
782
  });
783
783
  }, t.prototype.complete = function() {
784
784
  var e = this;
785
- W(function() {
785
+ X(function() {
786
786
  if (e._throwIfClosed(), !e.isStopped) {
787
787
  e.isStopped = !0;
788
788
  for (var s = e.observers; s.length; )
@@ -804,7 +804,7 @@ var gt = (function(n) {
804
804
  return this._throwIfClosed(), this._checkFinalizedStatuses(e), this._innerSubscribe(e);
805
805
  }, t.prototype._innerSubscribe = function(e) {
806
806
  var s = this, r = this, i = r.hasError, a = r.isStopped, o = r.observers;
807
- return i || a ? Oe : (this.currentObservers = null, o.push(e), new U(function() {
807
+ return i || a ? ke : (this.currentObservers = null, o.push(e), new L(function() {
808
808
  s.currentObservers = null, V(o, e);
809
809
  }));
810
810
  }, t.prototype._checkFinalizedStatuses = function(e) {
@@ -833,7 +833,7 @@ var gt = (function(n) {
833
833
  (s = (e = this.destination) === null || e === void 0 ? void 0 : e.complete) === null || s === void 0 || s.call(e);
834
834
  }, t.prototype._subscribe = function(e) {
835
835
  var s, r;
836
- return (r = (s = this.source) === null || s === void 0 ? void 0 : s.subscribe(e)) !== null && r !== void 0 ? r : Oe;
836
+ return (r = (s = this.source) === null || s === void 0 ? void 0 : s.subscribe(e)) !== null && r !== void 0 ? r : ke;
837
837
  }, t;
838
838
  })(ue), A = (function(n) {
839
839
  O(t, n);
@@ -858,11 +858,11 @@ var gt = (function(n) {
858
858
  }, t.prototype.next = function(e) {
859
859
  n.prototype.next.call(this, this._value = e);
860
860
  }, t;
861
- })(ue), bt = {
861
+ })(ue), vt = {
862
862
  now: function() {
863
863
  return Date.now();
864
864
  }
865
- }, vt = (function(n) {
865
+ }, St = (function(n) {
866
866
  O(t, n);
867
867
  function t(e, s) {
868
868
  return n.call(this) || this;
@@ -870,7 +870,7 @@ var gt = (function(n) {
870
870
  return t.prototype.schedule = function(e, s) {
871
871
  return this;
872
872
  }, t;
873
- })(U), ge = {
873
+ })(L), ge = {
874
874
  setInterval: function(n, t) {
875
875
  for (var e = [], s = 2; s < arguments.length; s++)
876
876
  e[s - 2] = arguments[s];
@@ -880,7 +880,7 @@ var gt = (function(n) {
880
880
  return clearInterval(n);
881
881
  },
882
882
  delegate: void 0
883
- }, St = (function(n) {
883
+ }, yt = (function(n) {
884
884
  O(t, n);
885
885
  function t(e, s) {
886
886
  var r = n.call(this, e, s) || this;
@@ -922,14 +922,14 @@ var gt = (function(n) {
922
922
  this.work = this.state = this.scheduler = null, this.pending = !1, V(i, this), s != null && (this.id = this.recycleAsyncId(r, s, null)), this.delay = null, n.prototype.unsubscribe.call(this);
923
923
  }
924
924
  }, t;
925
- })(vt), me = (function() {
925
+ })(St), me = (function() {
926
926
  function n(t, e) {
927
927
  e === void 0 && (e = n.now), this.schedulerActionCtor = t, this.now = e;
928
928
  }
929
929
  return n.prototype.schedule = function(t, e, s) {
930
930
  return e === void 0 && (e = 0), new this.schedulerActionCtor(this, t).schedule(s, e);
931
- }, n.now = bt.now, n;
932
- })(), yt = (function(n) {
931
+ }, n.now = vt.now, n;
932
+ })(), wt = (function(n) {
933
933
  O(t, n);
934
934
  function t(e, s) {
935
935
  s === void 0 && (s = me.now);
@@ -954,45 +954,45 @@ var gt = (function(n) {
954
954
  throw r;
955
955
  }
956
956
  }, t;
957
- })(me), wt = new yt(St);
958
- function Et(n) {
957
+ })(me), Et = new wt(yt);
958
+ function It(n) {
959
959
  return n && b(n.schedule);
960
960
  }
961
- function _e(n) {
961
+ function Me(n) {
962
962
  return n[n.length - 1];
963
963
  }
964
- function It(n) {
965
- return b(_e(n)) ? n.pop() : void 0;
964
+ function Tt(n) {
965
+ return b(Me(n)) ? n.pop() : void 0;
966
966
  }
967
- function Me(n) {
968
- return Et(_e(n)) ? n.pop() : void 0;
967
+ function Ue(n) {
968
+ return It(Me(n)) ? n.pop() : void 0;
969
969
  }
970
970
  var Le = (function(n) {
971
971
  return n && typeof n.length == "number" && typeof n != "function";
972
972
  });
973
- function Ue(n) {
973
+ function Ne(n) {
974
974
  return b(n?.then);
975
975
  }
976
- function Ne(n) {
976
+ function Re(n) {
977
977
  return b(n[ce]);
978
978
  }
979
- function Re(n) {
979
+ function Fe(n) {
980
980
  return Symbol.asyncIterator && b(n?.[Symbol.asyncIterator]);
981
981
  }
982
- function Fe(n) {
982
+ function je(n) {
983
983
  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.");
984
984
  }
985
- function Tt() {
985
+ function Ct() {
986
986
  return typeof Symbol != "function" || !Symbol.iterator ? "@@iterator" : Symbol.iterator;
987
987
  }
988
- var je = Tt();
989
- function $e(n) {
990
- return b(n?.[je]);
991
- }
988
+ var $e = Ct();
992
989
  function De(n) {
993
- return rt(this, arguments, function() {
990
+ return b(n?.[$e]);
991
+ }
992
+ function Be(n) {
993
+ return it(this, arguments, function() {
994
994
  var e, s, r, i;
995
- return xe(this, function(a) {
995
+ return Ae(this, function(a) {
996
996
  switch (a.label) {
997
997
  case 0:
998
998
  e = n.getReader(), a.label = 1;
@@ -1020,29 +1020,29 @@ function De(n) {
1020
1020
  });
1021
1021
  });
1022
1022
  }
1023
- function Be(n) {
1023
+ function He(n) {
1024
1024
  return b(n?.getReader);
1025
1025
  }
1026
1026
  function J(n) {
1027
1027
  if (n instanceof w)
1028
1028
  return n;
1029
1029
  if (n != null) {
1030
- if (Ne(n))
1031
- return Ct(n);
1032
- if (Le(n))
1030
+ if (Re(n))
1033
1031
  return xt(n);
1034
- if (Ue(n))
1032
+ if (Le(n))
1035
1033
  return At(n);
1036
- if (Re(n))
1037
- return He(n);
1038
- if ($e(n))
1034
+ if (Ne(n))
1039
1035
  return Ot(n);
1040
- if (Be(n))
1036
+ if (Fe(n))
1037
+ return Ge(n);
1038
+ if (De(n))
1041
1039
  return kt(n);
1040
+ if (He(n))
1041
+ return Pt(n);
1042
1042
  }
1043
- throw Fe(n);
1043
+ throw je(n);
1044
1044
  }
1045
- function Ct(n) {
1045
+ function xt(n) {
1046
1046
  return new w(function(t) {
1047
1047
  var e = n[ce]();
1048
1048
  if (b(e.subscribe))
@@ -1050,27 +1050,27 @@ function Ct(n) {
1050
1050
  throw new TypeError("Provided object does not correctly implement Symbol.observable");
1051
1051
  });
1052
1052
  }
1053
- function xt(n) {
1053
+ function At(n) {
1054
1054
  return new w(function(t) {
1055
1055
  for (var e = 0; e < n.length && !t.closed; e++)
1056
1056
  t.next(n[e]);
1057
1057
  t.complete();
1058
1058
  });
1059
1059
  }
1060
- function At(n) {
1060
+ function Ot(n) {
1061
1061
  return new w(function(t) {
1062
1062
  n.then(function(e) {
1063
1063
  t.closed || (t.next(e), t.complete());
1064
1064
  }, function(e) {
1065
1065
  return t.error(e);
1066
- }).then(null, Pe);
1066
+ }).then(null, _e);
1067
1067
  });
1068
1068
  }
1069
- function Ot(n) {
1069
+ function kt(n) {
1070
1070
  return new w(function(t) {
1071
1071
  var e, s;
1072
1072
  try {
1073
- for (var r = L(n), i = r.next(); !i.done; i = r.next()) {
1073
+ for (var r = U(n), i = r.next(); !i.done; i = r.next()) {
1074
1074
  var a = i.value;
1075
1075
  if (t.next(a), t.closed)
1076
1076
  return;
@@ -1087,24 +1087,24 @@ function Ot(n) {
1087
1087
  t.complete();
1088
1088
  });
1089
1089
  }
1090
- function He(n) {
1090
+ function Ge(n) {
1091
1091
  return new w(function(t) {
1092
- Pt(n, t).catch(function(e) {
1092
+ _t(n, t).catch(function(e) {
1093
1093
  return t.error(e);
1094
1094
  });
1095
1095
  });
1096
1096
  }
1097
- function kt(n) {
1098
- return He(De(n));
1097
+ function Pt(n) {
1098
+ return Ge(Be(n));
1099
1099
  }
1100
- function Pt(n, t) {
1100
+ function _t(n, t) {
1101
1101
  var e, s, r, i;
1102
- return st(this, void 0, void 0, function() {
1102
+ return rt(this, void 0, void 0, function() {
1103
1103
  var a, o;
1104
- return xe(this, function(c) {
1104
+ return Ae(this, function(c) {
1105
1105
  switch (c.label) {
1106
1106
  case 0:
1107
- c.trys.push([0, 5, 6, 11]), e = it(n), c.label = 1;
1107
+ c.trys.push([0, 5, 6, 11]), e = at(n), c.label = 1;
1108
1108
  case 1:
1109
1109
  return [4, e.next()];
1110
1110
  case 2:
@@ -1143,7 +1143,7 @@ function T(n, t, e, s, r) {
1143
1143
  if (n.add(i), !r)
1144
1144
  return i;
1145
1145
  }
1146
- function Ge(n, t) {
1146
+ function qe(n, t) {
1147
1147
  return t === void 0 && (t = 0), P(function(e, s) {
1148
1148
  e.subscribe(N(s, function(r) {
1149
1149
  return T(s, n, function() {
@@ -1160,18 +1160,18 @@ function Ge(n, t) {
1160
1160
  }));
1161
1161
  });
1162
1162
  }
1163
- function qe(n, t) {
1163
+ function Ke(n, t) {
1164
1164
  return t === void 0 && (t = 0), P(function(e, s) {
1165
1165
  s.add(n.schedule(function() {
1166
1166
  return e.subscribe(s);
1167
1167
  }, t));
1168
1168
  });
1169
1169
  }
1170
- function _t(n, t) {
1171
- return J(n).pipe(qe(t), Ge(t));
1172
- }
1173
1170
  function Mt(n, t) {
1174
- return J(n).pipe(qe(t), Ge(t));
1171
+ return J(n).pipe(Ke(t), qe(t));
1172
+ }
1173
+ function Ut(n, t) {
1174
+ return J(n).pipe(Ke(t), qe(t));
1175
1175
  }
1176
1176
  function Lt(n, t) {
1177
1177
  return new w(function(e) {
@@ -1181,11 +1181,11 @@ function Lt(n, t) {
1181
1181
  });
1182
1182
  });
1183
1183
  }
1184
- function Ut(n, t) {
1184
+ function Nt(n, t) {
1185
1185
  return new w(function(e) {
1186
1186
  var s;
1187
1187
  return T(e, t, function() {
1188
- s = n[je](), T(e, t, function() {
1188
+ s = n[$e](), T(e, t, function() {
1189
1189
  var r, i, a;
1190
1190
  try {
1191
1191
  r = s.next(), i = r.value, a = r.done;
@@ -1200,7 +1200,7 @@ function Ut(n, t) {
1200
1200
  };
1201
1201
  });
1202
1202
  }
1203
- function Ke(n, t) {
1203
+ function Ve(n, t) {
1204
1204
  if (!n)
1205
1205
  throw new Error("Iterable cannot be null");
1206
1206
  return new w(function(e) {
@@ -1214,28 +1214,28 @@ function Ke(n, t) {
1214
1214
  });
1215
1215
  });
1216
1216
  }
1217
- function Nt(n, t) {
1218
- return Ke(De(n), t);
1219
- }
1220
1217
  function Rt(n, t) {
1218
+ return Ve(Be(n), t);
1219
+ }
1220
+ function Ft(n, t) {
1221
1221
  if (n != null) {
1222
- if (Ne(n))
1223
- return _t(n, t);
1222
+ if (Re(n))
1223
+ return Mt(n, t);
1224
1224
  if (Le(n))
1225
1225
  return Lt(n, t);
1226
- if (Ue(n))
1227
- return Mt(n, t);
1228
- if (Re(n))
1229
- return Ke(n, t);
1230
- if ($e(n))
1226
+ if (Ne(n))
1231
1227
  return Ut(n, t);
1232
- if (Be(n))
1228
+ if (Fe(n))
1229
+ return Ve(n, t);
1230
+ if (De(n))
1233
1231
  return Nt(n, t);
1232
+ if (He(n))
1233
+ return Rt(n, t);
1234
1234
  }
1235
- throw Fe(n);
1235
+ throw je(n);
1236
1236
  }
1237
- function Ve(n, t) {
1238
- return t ? Rt(n, t) : J(n);
1237
+ function We(n, t) {
1238
+ return t ? Ft(n, t) : J(n);
1239
1239
  }
1240
1240
  function Y(n, t) {
1241
1241
  return P(function(e, s) {
@@ -1245,23 +1245,23 @@ function Y(n, t) {
1245
1245
  }));
1246
1246
  });
1247
1247
  }
1248
- var Ft = Array.isArray;
1249
- function jt(n, t) {
1250
- return Ft(t) ? n.apply(void 0, K([], q(t))) : n(t);
1248
+ var jt = Array.isArray;
1249
+ function $t(n, t) {
1250
+ return jt(t) ? n.apply(void 0, K([], q(t))) : n(t);
1251
1251
  }
1252
- function $t(n) {
1252
+ function Dt(n) {
1253
1253
  return Y(function(t) {
1254
- return jt(n, t);
1254
+ return $t(n, t);
1255
1255
  });
1256
1256
  }
1257
- var Dt = Array.isArray, Bt = Object.getPrototypeOf, Ht = Object.prototype, Gt = Object.keys;
1258
- function qt(n) {
1257
+ var Bt = Array.isArray, Ht = Object.getPrototypeOf, Gt = Object.prototype, qt = Object.keys;
1258
+ function Kt(n) {
1259
1259
  if (n.length === 1) {
1260
1260
  var t = n[0];
1261
- if (Dt(t))
1261
+ if (Bt(t))
1262
1262
  return { args: t, keys: null };
1263
- if (Kt(t)) {
1264
- var e = Gt(t);
1263
+ if (Vt(t)) {
1264
+ var e = qt(t);
1265
1265
  return {
1266
1266
  args: e.map(function(s) {
1267
1267
  return t[s];
@@ -1272,10 +1272,10 @@ function qt(n) {
1272
1272
  }
1273
1273
  return { args: n, keys: null };
1274
1274
  }
1275
- function Kt(n) {
1276
- return n && typeof n == "object" && Bt(n) === Ht;
1275
+ function Vt(n) {
1276
+ return n && typeof n == "object" && Ht(n) === Gt;
1277
1277
  }
1278
- function Vt(n, t) {
1278
+ function Wt(n, t) {
1279
1279
  return n.reduce(function(e, s, r) {
1280
1280
  return e[s] = t[r], e;
1281
1281
  }, {});
@@ -1283,20 +1283,20 @@ function Vt(n, t) {
1283
1283
  function Xt() {
1284
1284
  for (var n = [], t = 0; t < arguments.length; t++)
1285
1285
  n[t] = arguments[t];
1286
- var e = Me(n), s = It(n), r = qt(n), i = r.args, a = r.keys;
1286
+ var e = Ue(n), s = Tt(n), r = Kt(n), i = r.args, a = r.keys;
1287
1287
  if (i.length === 0)
1288
- return Ve([], e);
1289
- var o = new w(Wt(i, e, a ? function(c) {
1290
- return Vt(a, c);
1288
+ return We([], e);
1289
+ var o = new w(Yt(i, e, a ? function(c) {
1290
+ return Wt(a, c);
1291
1291
  } : z));
1292
- return s ? o.pipe($t(s)) : o;
1292
+ return s ? o.pipe(Dt(s)) : o;
1293
1293
  }
1294
- function Wt(n, t, e) {
1294
+ function Yt(n, t, e) {
1295
1295
  return e === void 0 && (e = z), function(s) {
1296
1296
  be(t, function() {
1297
1297
  for (var r = n.length, i = new Array(r), a = r, o = r, c = function(d) {
1298
1298
  be(t, function() {
1299
- var m = Ve(n[d], t), v = !1;
1299
+ var m = We(n[d], t), v = !1;
1300
1300
  m.subscribe(N(s, function(h) {
1301
1301
  i[d] = h, v || (v = !0, o--), o || s.next(e(i.slice()));
1302
1302
  }, function() {
@@ -1311,7 +1311,7 @@ function Wt(n, t, e) {
1311
1311
  function be(n, t, e) {
1312
1312
  n ? T(e, n, t) : t();
1313
1313
  }
1314
- function Yt(n, t) {
1314
+ function zt(n, t) {
1315
1315
  return P(function(e, s) {
1316
1316
  var r = 0;
1317
1317
  e.subscribe(N(s, function(i) {
@@ -1319,17 +1319,17 @@ function Yt(n, t) {
1319
1319
  }));
1320
1320
  });
1321
1321
  }
1322
- function zt(n) {
1322
+ function Jt(n) {
1323
1323
  for (var t, e, s = [], r = 1; r < arguments.length; r++)
1324
1324
  s[r - 1] = arguments[r];
1325
- var i = (t = Me(s)) !== null && t !== void 0 ? t : wt, a = (e = s[0]) !== null && e !== void 0 ? e : null, o = s[1] || 1 / 0;
1325
+ var i = (t = Ue(s)) !== null && t !== void 0 ? t : Et, a = (e = s[0]) !== null && e !== void 0 ? e : null, o = s[1] || 1 / 0;
1326
1326
  return P(function(c, u) {
1327
1327
  var d = [], m = !1, v = function(f) {
1328
1328
  var I = f.buffer, E = f.subs;
1329
1329
  E.unsubscribe(), V(d, f), u.next(I), m && h();
1330
1330
  }, h = function() {
1331
1331
  if (d) {
1332
- var f = new U();
1332
+ var f = new L();
1333
1333
  u.add(f);
1334
1334
  var I = [], E = {
1335
1335
  buffer: I,
@@ -1344,7 +1344,7 @@ function zt(n) {
1344
1344
  var p = N(u, function(f) {
1345
1345
  var I, E, B = d.slice();
1346
1346
  try {
1347
- for (var R = L(B), _ = R.next(); !_.done; _ = R.next()) {
1347
+ for (var R = U(B), _ = R.next(); !_.done; _ = R.next()) {
1348
1348
  var F = _.value, j = F.buffer;
1349
1349
  j.push(f), o <= j.length && v(F);
1350
1350
  }
@@ -1368,7 +1368,7 @@ function zt(n) {
1368
1368
  });
1369
1369
  }
1370
1370
  function M(n, t) {
1371
- return t === void 0 && (t = z), n = n ?? Jt, P(function(e, s) {
1371
+ return t === void 0 && (t = z), n = n ?? Qt, P(function(e, s) {
1372
1372
  var r, i = !0;
1373
1373
  e.subscribe(N(s, function(a) {
1374
1374
  var o = t(a);
@@ -1376,10 +1376,10 @@ function M(n, t) {
1376
1376
  }));
1377
1377
  });
1378
1378
  }
1379
- function Jt(n, t) {
1379
+ function Qt(n, t) {
1380
1380
  return n === t;
1381
1381
  }
1382
- function Qt(n) {
1382
+ function Zt(n) {
1383
1383
  return P(function(t, e) {
1384
1384
  try {
1385
1385
  t.subscribe(e);
@@ -1388,7 +1388,7 @@ function Qt(n) {
1388
1388
  }
1389
1389
  });
1390
1390
  }
1391
- function Zt(n) {
1391
+ function en(n) {
1392
1392
  return P(function(t, e) {
1393
1393
  J(n).subscribe(N(e, function() {
1394
1394
  return e.complete();
@@ -1406,7 +1406,7 @@ function ve(n) {
1406
1406
  };
1407
1407
  e && (v["X-API-KEY"] = e);
1408
1408
  const h = new URL(t);
1409
- return r && h.searchParams.set("is_debug", "true"), Ce(h.toString(), {
1409
+ return r && h.searchParams.set("is_debug", "true"), xe(h.toString(), {
1410
1410
  method: a,
1411
1411
  headers: v,
1412
1412
  body: a === "POST" && s ? JSON.stringify(s) : void 0,
@@ -1451,7 +1451,7 @@ function ve(n) {
1451
1451
  };
1452
1452
  });
1453
1453
  }
1454
- class en {
1454
+ class tn {
1455
1455
  listeners = {};
1456
1456
  on(t, e) {
1457
1457
  this.listeners = Object.assign({}, this.listeners, {
@@ -1470,8 +1470,11 @@ class en {
1470
1470
  this.listeners[t] && this.listeners[t].forEach((s) => s(...e));
1471
1471
  }
1472
1472
  }
1473
- const tn = 50;
1474
- class _n {
1473
+ const nn = 50;
1474
+ function Se(n, t) {
1475
+ return t?.customChannelId && n.searchParams.set("custom_channel_id", t.customChannelId), n;
1476
+ }
1477
+ class Mn {
1475
1478
  apiKey;
1476
1479
  endpoint;
1477
1480
  botProviderEndpoint;
@@ -1481,7 +1484,7 @@ class _n {
1481
1484
  detached = !1;
1482
1485
  detachTimer;
1483
1486
  inFlight = 0;
1484
- sseEmitter = new en();
1487
+ sseEmitter = new tn();
1485
1488
  transformSsePayload;
1486
1489
  customHeaders;
1487
1490
  constructor(t) {
@@ -1718,13 +1721,13 @@ class _n {
1718
1721
  // at a consumer, one microtask apart — but the latency it adds is one window total, no matter
1719
1722
  // how many frames land in it. Frames are still delivered individually and in order below, so
1720
1723
  // nothing downstream can tell the difference apart from the timing.
1721
- zt(e?.delayTime ?? tn),
1724
+ Jt(e?.delayTime ?? nn),
1722
1725
  // An idle stream still ticks an empty buffer every window; do not wake the consumer for nothing.
1723
- Yt((s) => s.length > 0),
1724
- Zt(this.destroy$),
1726
+ zt((s) => s.length > 0),
1727
+ en(this.destroy$),
1725
1728
  // Settle the run accounting on every termination path — complete, error, AND a user-initiated
1726
1729
  // unsubscribe (stop-generation aborts the connection without a terminal event).
1727
- Qt(() => this.onRunSettled())
1730
+ Zt(() => this.onRunSettled())
1728
1731
  ).subscribe({
1729
1732
  next: (s) => {
1730
1733
  if (!this.detached)
@@ -1824,18 +1827,22 @@ class _n {
1824
1827
  /**
1825
1828
  * F-020 — 取得 sandbox 瀏覽器一次性接手 URL(`sandbox://<name>/open-browser` 卡的副作用)。
1826
1829
  * 呼叫 `POST {base}/sandbox/{sandboxName}/browser/open-url`(對標 asgard-core edgeserver
1827
- * `GenerateSandboxBrowserOpenUrl`:path 參數 namespace / bot-provider 已在 base、sandbox_name 在路徑,
1828
- * 不需 custom_channel_id)。回應 `{ data: { openURL } }`(envelope 容錯,比照 `channelMetadata`)。
1830
+ * `GenerateSandboxBrowserOpenUrl`:path 參數 namespace / bot-provider 已在 base、sandbox_name 在路徑)。
1831
+ * 回應 `{ data: { openURL } }`(envelope 容錯,比照 `channelMetadata`)。
1832
+ *
1833
+ * `options.customChannelId` 帶上該 sandbox 所屬的 channel(`SandboxChannelScope`)。直接對 edge server
1834
+ * 呼叫時它會被忽略,但前置 relay 用它做 ownership 證明,缺了就是 `400`。
1829
1835
  */
1830
- async generateSandboxBrowserOpenUrl(t) {
1831
- const e = this.getBaseEndpoint();
1832
- if (!e)
1836
+ async generateSandboxBrowserOpenUrl(t, e) {
1837
+ const s = this.getBaseEndpoint();
1838
+ if (!s)
1833
1839
  throw new Error(
1834
1840
  "Unable to derive sandbox browser open-url endpoint. Please provide botProviderEndpoint in config."
1835
1841
  );
1836
- const s = `${e}/sandbox/${encodeURIComponent(t)}/browser/open-url`, r = { ...this.customHeaders };
1837
- this.apiKey && (r["X-API-KEY"] = this.apiKey);
1838
- const i = await fetch(s, { method: "POST", headers: r });
1842
+ const r = Se(
1843
+ new URL(`${s}/sandbox/${encodeURIComponent(t)}/browser/open-url`),
1844
+ e
1845
+ ), i = await fetch(r.toString(), { method: "POST", headers: this.apiHeaders() });
1839
1846
  if (!i.ok)
1840
1847
  throw new y(i.status, i.statusText, await i.text().catch(() => {
1841
1848
  }));
@@ -1853,6 +1860,13 @@ class _n {
1853
1860
  throw new Error("Unable to derive sandbox fs endpoint. Please provide botProviderEndpoint in config.");
1854
1861
  return `${e}/sandbox/${encodeURIComponent(t)}/fs`;
1855
1862
  }
1863
+ /**
1864
+ * F-021 — one sandbox fs URL, with the channel scope already on it. Every `fs/*` call goes through here
1865
+ * so the ownership parameter cannot be forgotten in one of eleven places (see `withChannelScope`).
1866
+ */
1867
+ sandboxFsUrl(t, e, s) {
1868
+ return Se(new URL(`${this.deriveSandboxFsEndpoint(t)}/${e}`), s);
1869
+ }
1856
1870
  /** The shared auth / custom headers for the client's plain-JSON REST calls (no SSE). */
1857
1871
  apiHeaders() {
1858
1872
  const t = { ...this.customHeaders };
@@ -1862,22 +1876,22 @@ class _n {
1862
1876
  * F-021 — 列出 sandbox 目錄內容(`GET fs/list?path=`)。回應 `{ data: { entries, truncated } }`(envelope
1863
1877
  * 容錯,比照 `channelMetadata`)。
1864
1878
  */
1865
- async sandboxFsList(t, e) {
1866
- const s = new URL(`${this.deriveSandboxFsEndpoint(t)}/list`);
1867
- s.searchParams.set("path", e);
1868
- const r = await fetch(s.toString(), { method: "GET", headers: this.apiHeaders() });
1869
- if (!r.ok)
1870
- throw new y(r.status, r.statusText, await r.text().catch(() => {
1879
+ async sandboxFsList(t, e, s) {
1880
+ const r = this.sandboxFsUrl(t, "list", s);
1881
+ r.searchParams.set("path", e);
1882
+ const i = await fetch(r.toString(), { method: "GET", headers: this.apiHeaders() });
1883
+ if (!i.ok)
1884
+ throw new y(i.status, i.statusText, await i.text().catch(() => {
1871
1885
  }));
1872
- const i = await r.json(), a = i.data ?? i;
1873
- return { entries: a.entries ?? [], truncated: a.truncated ?? !1 };
1886
+ const a = await i.json(), o = a.data ?? a;
1887
+ return { entries: o.entries ?? [], truncated: o.truncated ?? !1 };
1874
1888
  }
1875
1889
  /**
1876
1890
  * F-021 — 讀取 sandbox 檔案(`GET fs/file?path=[&offset_bytes&limit_bytes]`)。回應是 raw octet-stream,
1877
1891
  * 檔案總長度 / 是否截斷走 `X-Total-Bytes` / `X-Truncated` header。
1878
1892
  */
1879
1893
  async sandboxFsRead(t, e, s) {
1880
- const r = new URL(`${this.deriveSandboxFsEndpoint(t)}/file`);
1894
+ const r = this.sandboxFsUrl(t, "file", s);
1881
1895
  r.searchParams.set("path", e), s?.offsetBytes != null && r.searchParams.set("offset_bytes", String(s.offsetBytes)), s?.limitBytes != null && r.searchParams.set("limit_bytes", String(s.limitBytes));
1882
1896
  const i = await fetch(r.toString(), { method: "GET", headers: this.apiHeaders() });
1883
1897
  if (!i.ok)
@@ -1895,7 +1909,7 @@ class _n {
1895
1909
  * 回應 `{ data: { bytesWritten } }`。
1896
1910
  */
1897
1911
  async sandboxFsWrite(t, e, s, r) {
1898
- const i = new URL(`${this.deriveSandboxFsEndpoint(t)}/file`);
1912
+ const i = this.sandboxFsUrl(t, "file", r);
1899
1913
  i.searchParams.set("path", e), r?.mode != null && i.searchParams.set("mode", String(r.mode)), r?.createOnly && i.searchParams.set("create_only", "true");
1900
1914
  const a = new FormData();
1901
1915
  a.append("file", s instanceof Blob ? s : new Blob([s]));
@@ -1912,85 +1926,85 @@ class _n {
1912
1926
  return { bytesWritten: (c.data ?? c).bytesWritten ?? 0 };
1913
1927
  }
1914
1928
  /** F-021 Cycle 2 — `sandbox://` fs mutation shared request helper (throws `HttpError` on non-OK). */
1915
- async sandboxFsRequest(t, e, s, r) {
1916
- const i = new URL(`${this.deriveSandboxFsEndpoint(t)}/${e}`);
1917
- Object.entries(r).forEach(([o, c]) => i.searchParams.set(o, c));
1918
- const a = await fetch(i.toString(), { method: s, headers: this.apiHeaders() });
1919
- if (!a.ok)
1920
- throw new y(a.status, a.statusText, await a.text().catch(() => {
1929
+ async sandboxFsRequest(t, e, s, r, i) {
1930
+ const a = this.sandboxFsUrl(t, e, i);
1931
+ Object.entries(r).forEach(([c, u]) => a.searchParams.set(c, u));
1932
+ const o = await fetch(a.toString(), { method: s, headers: this.apiHeaders() });
1933
+ if (!o.ok)
1934
+ throw new y(o.status, o.statusText, await o.text().catch(() => {
1921
1935
  }));
1922
- return a.json().catch(() => null);
1936
+ return o.json().catch(() => null);
1923
1937
  }
1924
1938
  /** F-021 — stat a sandbox path (`GET fs/stat?path=`). */
1925
- async sandboxFsStat(t, e) {
1926
- const s = new URL(`${this.deriveSandboxFsEndpoint(t)}/stat`);
1927
- s.searchParams.set("path", e);
1928
- const r = await fetch(s.toString(), { method: "GET", headers: this.apiHeaders() });
1929
- if (!r.ok)
1930
- throw new y(r.status, r.statusText, await r.text().catch(() => {
1939
+ async sandboxFsStat(t, e, s) {
1940
+ const r = this.sandboxFsUrl(t, "stat", s);
1941
+ r.searchParams.set("path", e);
1942
+ const i = await fetch(r.toString(), { method: "GET", headers: this.apiHeaders() });
1943
+ if (!i.ok)
1944
+ throw new y(i.status, i.statusText, await i.text().catch(() => {
1931
1945
  }));
1932
- const i = await r.json(), a = i.data ?? i;
1946
+ const a = await i.json(), o = a.data ?? a;
1933
1947
  return {
1934
- exists: a.exists ?? !1,
1935
- isDir: a.isDir ?? !1,
1936
- sizeBytes: a.sizeBytes ?? 0,
1937
- mtimeUnix: a.mtimeUnix ?? 0,
1938
- mode: a.mode ?? 0,
1939
- etag: a.etag
1948
+ exists: o.exists ?? !1,
1949
+ isDir: o.isDir ?? !1,
1950
+ sizeBytes: o.sizeBytes ?? 0,
1951
+ mtimeUnix: o.mtimeUnix ?? 0,
1952
+ mode: o.mode ?? 0,
1953
+ etag: o.etag
1940
1954
  };
1941
1955
  }
1942
1956
  /** F-021 — create a directory (`POST fs/mkdir?path=`). */
1943
- async sandboxFsMkdir(t, e) {
1944
- await this.sandboxFsRequest(t, "mkdir", "POST", { path: e });
1957
+ async sandboxFsMkdir(t, e, s) {
1958
+ await this.sandboxFsRequest(t, "mkdir", "POST", { path: e }, s);
1945
1959
  }
1946
1960
  /** F-021 — delete a file (`DELETE fs/item?path=`). */
1947
- async sandboxFsRemove(t, e) {
1948
- await this.sandboxFsRequest(t, "item", "DELETE", { path: e });
1961
+ async sandboxFsRemove(t, e, s) {
1962
+ await this.sandboxFsRequest(t, "item", "DELETE", { path: e }, s);
1949
1963
  }
1950
1964
  /** F-021 — recursively delete a directory (`DELETE fs/all?path=`). */
1951
- async sandboxFsRemoveAll(t, e) {
1952
- await this.sandboxFsRequest(t, "all", "DELETE", { path: e });
1965
+ async sandboxFsRemoveAll(t, e, s) {
1966
+ await this.sandboxFsRequest(t, "all", "DELETE", { path: e }, s);
1953
1967
  }
1954
1968
  /** F-021 — copy a path (`POST fs/copy?src=&dst=[&overwrite]`) → bytes copied. */
1955
1969
  async sandboxFsCopy(t, e, s, r) {
1956
1970
  const i = { src: e, dst: s };
1957
1971
  r?.overwrite && (i.overwrite = "true");
1958
- const a = await this.sandboxFsRequest(t, "copy", "POST", i);
1972
+ const a = await this.sandboxFsRequest(t, "copy", "POST", i, r);
1959
1973
  return { bytesCopied: (a?.data ?? a)?.bytesCopied ?? 0 };
1960
1974
  }
1961
1975
  /** F-021 — move / rename a path (`POST fs/move?src=&dst=[&overwrite]`). */
1962
1976
  async sandboxFsMove(t, e, s, r) {
1963
1977
  const i = { src: e, dst: s };
1964
- r?.overwrite && (i.overwrite = "true"), await this.sandboxFsRequest(t, "move", "POST", i);
1978
+ r?.overwrite && (i.overwrite = "true"), await this.sandboxFsRequest(t, "move", "POST", i, r);
1965
1979
  }
1966
1980
  /**
1967
1981
  * F-021 — watch a sandbox path for changes (`GET fs/watch?path=`, SSE). Each `event: change` frame is one
1968
1982
  * `SandboxFsWatchEvent`. The backend probes the path first, so a missing path errors as HTTP rather than
1969
1983
  * as a dead stream. Unsubscribing aborts the request, which ends the sandbox-side watcher.
1970
1984
  */
1971
- sandboxFsWatch(t, e) {
1972
- const s = new URL(`${this.deriveSandboxFsEndpoint(t)}/watch`);
1973
- return s.searchParams.set("path", e), new w((r) => {
1974
- const i = new AbortController();
1975
- return Ce(s.toString(), {
1985
+ sandboxFsWatch(t, e, s) {
1986
+ const r = this.sandboxFsUrl(t, "watch", s);
1987
+ return r.searchParams.set("path", e), new w((i) => {
1988
+ const a = new AbortController();
1989
+ return xe(r.toString(), {
1976
1990
  headers: this.apiHeaders(),
1977
- signal: i.signal,
1991
+ signal: a.signal,
1978
1992
  openWhenHidden: !0,
1979
- onopen: async (a) => {
1980
- if (!a.ok) {
1981
- const o = await a.text().catch(() => {
1993
+ onopen: async (o) => {
1994
+ if (!o.ok) {
1995
+ const c = await o.text().catch(() => {
1982
1996
  });
1983
- r.error(new y(a.status, a.statusText, o)), i.abort();
1997
+ i.error(new y(o.status, o.statusText, c)), a.abort();
1984
1998
  }
1985
1999
  },
1986
- onmessage: (a) => {
1987
- a.event === "change" && r.next(JSON.parse(a.data));
2000
+ onmessage: (o) => {
2001
+ o.event === "change" && i.next(JSON.parse(o.data));
1988
2002
  },
1989
- onclose: () => r.complete(),
1990
- onerror: (a) => {
1991
- throw r.error(a), i.abort(), a;
2003
+ onclose: () => i.complete(),
2004
+ onerror: (o) => {
2005
+ throw i.error(o), a.abort(), o;
1992
2006
  }
1993
- }), () => i.abort();
2007
+ }), () => a.abort();
1994
2008
  });
1995
2009
  }
1996
2010
  /**
@@ -2009,9 +2023,9 @@ class _n {
2009
2023
  return !t && this.endpoint && (t = this.endpoint.replace("/message/sse", "")), t ? t.replace(/\/+$/, "") : null;
2010
2024
  }
2011
2025
  }
2012
- const nn = "", sn = /* @__PURE__ */ new Set(["", ".", ".."]);
2026
+ const sn = "", rn = /* @__PURE__ */ new Set(["", ".", ".."]);
2013
2027
  function C(n, t) {
2014
- if (n === nn) {
2028
+ if (n === sn) {
2015
2029
  if (t?.allowRoot)
2016
2030
  return n;
2017
2031
  throw new Error(
@@ -2022,15 +2036,15 @@ function C(n, t) {
2022
2036
  throw new Error(`SourceSet volume path must be relative, with no leading slash (the root is ""): "${n}".`);
2023
2037
  if (n.endsWith("/"))
2024
2038
  throw new Error(`SourceSet volume path must not end with a slash: "${n}".`);
2025
- if (n.split("/").some((e) => sn.has(e)))
2039
+ if (n.split("/").some((e) => rn.has(e)))
2026
2040
  throw new Error(`SourceSet volume path must not contain empty, "." or ".." segments: "${n}".`);
2027
2041
  return n;
2028
2042
  }
2029
- const Xe = 1e3, rn = 1e4;
2030
- function Se(n) {
2043
+ const Xe = 1e3, an = 1e4;
2044
+ function ye(n) {
2031
2045
  return Math.min(Math.max(1, Math.floor(n)), Xe);
2032
2046
  }
2033
- class Mn {
2047
+ class Un {
2034
2048
  endpoint;
2035
2049
  apiKey;
2036
2050
  customHeaders;
@@ -2055,7 +2069,7 @@ class Mn {
2055
2069
  /** One page of a directory (`GET volume/list?path=[&page&page_size]`). `path` may be the root `''`. */
2056
2070
  async list(t, e) {
2057
2071
  const s = { path: C(t, { allowRoot: !0 }) };
2058
- e?.page != null && (s.page = String(e.page)), e?.pageSize != null && (s.page_size = String(Se(e.pageSize)));
2072
+ e?.page != null && (s.page = String(e.page)), e?.pageSize != null && (s.page_size = String(ye(e.pageSize)));
2059
2073
  const i = await (await this.request("list", "GET", s)).json(), a = i.data ?? i;
2060
2074
  return {
2061
2075
  entries: a.entries ?? [],
@@ -2072,7 +2086,7 @@ class Mn {
2072
2086
  * directory that looks whole is the failure this exists to prevent.
2073
2087
  */
2074
2088
  async listAll(t, e) {
2075
- const s = Se(e?.pageSize ?? Xe), r = e?.maxEntries ?? rn, i = [];
2089
+ const s = ye(e?.pageSize ?? Xe), r = e?.maxEntries ?? an, i = [];
2076
2090
  let a = 0, o = !0, c = 0;
2077
2091
  for (; ; ) {
2078
2092
  const u = await this.list(t, { page: c, pageSize: s }), d = u.paging;
@@ -2158,29 +2172,29 @@ class Mn {
2158
2172
  const S = [];
2159
2173
  for (let n = 0; n < 256; ++n)
2160
2174
  S.push((n + 256).toString(16).slice(1));
2161
- function an(n, t = 0) {
2175
+ function on(n, t = 0) {
2162
2176
  return (S[n[t + 0]] + S[n[t + 1]] + S[n[t + 2]] + S[n[t + 3]] + "-" + S[n[t + 4]] + S[n[t + 5]] + "-" + S[n[t + 6]] + S[n[t + 7]] + "-" + S[n[t + 8]] + S[n[t + 9]] + "-" + S[n[t + 10]] + S[n[t + 11]] + S[n[t + 12]] + S[n[t + 13]] + S[n[t + 14]] + S[n[t + 15]]).toLowerCase();
2163
2177
  }
2164
2178
  let Z;
2165
- const on = new Uint8Array(16);
2166
- function cn() {
2179
+ const cn = new Uint8Array(16);
2180
+ function un() {
2167
2181
  if (!Z) {
2168
2182
  if (typeof crypto > "u" || !crypto.getRandomValues)
2169
2183
  throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
2170
2184
  Z = crypto.getRandomValues.bind(crypto);
2171
2185
  }
2172
- return Z(on);
2186
+ return Z(cn);
2173
2187
  }
2174
- const un = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), ye = { randomUUID: un };
2175
- function ln(n, t, e) {
2188
+ const ln = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), we = { randomUUID: ln };
2189
+ function dn(n, t, e) {
2176
2190
  n = n || {};
2177
- const s = n.random ?? n.rng?.() ?? cn();
2191
+ const s = n.random ?? n.rng?.() ?? un();
2178
2192
  if (s.length < 16)
2179
2193
  throw new Error("Random bytes length must be >= 16");
2180
- return s[6] = s[6] & 15 | 64, s[8] = s[8] & 63 | 128, an(s);
2194
+ return s[6] = s[6] & 15 | 64, s[8] = s[8] & 63 | 128, on(s);
2181
2195
  }
2182
- function We(n, t, e) {
2183
- return ye.randomUUID && !n ? ye.randomUUID() : ln(n);
2196
+ function Ye(n, t, e) {
2197
+ return we.randomUUID && !n ? we.randomUUID() : dn(n);
2184
2198
  }
2185
2199
  class g {
2186
2200
  messages = null;
@@ -2467,7 +2481,7 @@ class g {
2467
2481
  onCanvasComplete(t) {
2468
2482
  const e = t.fact.messageCanvasComplete.message;
2469
2483
  if (e.parentToolUseId) return this;
2470
- const s = e.template?.type === Te.CANVAS ? e.template : void 0, r = s?.canvas?.html;
2484
+ const s = e.template?.type === Ce.CANVAS ? e.template : void 0, r = s?.canvas?.html;
2471
2485
  if (!r) {
2472
2486
  if (!this.messages?.has(e.messageId)) return this;
2473
2487
  const u = new Map(this.messages);
@@ -2503,7 +2517,7 @@ class g {
2503
2517
  return r.set(e.messageId, i), new g({ messages: r, pendingConsent: this.pendingConsent, pendingFeedback: this.pendingFeedback });
2504
2518
  }
2505
2519
  onMessageError(t) {
2506
- const e = We(), s = t.fact.runError.error, r = new Map(this.messages);
2520
+ const e = Ye(), s = t.fact.runError.error, r = new Map(this.messages);
2507
2521
  return r.set(e, {
2508
2522
  type: "error",
2509
2523
  eventType: l.ERROR,
@@ -2609,22 +2623,22 @@ class g {
2609
2623
  return s.delete(r), s.set(r, i), new g({ messages: s, pendingConsent: this.pendingConsent, pendingFeedback: this.pendingFeedback });
2610
2624
  }
2611
2625
  }
2612
- const dn = /* @__PURE__ */ new Set(["TaskCreate", "TaskUpdate"]);
2613
- function hn(n) {
2614
- return n.toolsetName === "" && dn.has(n.toolName);
2626
+ const hn = /* @__PURE__ */ new Set(["TaskCreate", "TaskUpdate"]);
2627
+ function fn(n) {
2628
+ return n.toolsetName === "" && hn.has(n.toolName);
2615
2629
  }
2616
- function we(n) {
2630
+ function Ee(n) {
2617
2631
  return typeof n == "object" && n !== null ? n : void 0;
2618
2632
  }
2619
2633
  function x(n) {
2620
2634
  return typeof n == "string" ? n : void 0;
2621
2635
  }
2622
- function fn(n) {
2636
+ function pn(n) {
2623
2637
  const t = [], e = /* @__PURE__ */ new Map();
2624
2638
  for (const s of n) {
2625
2639
  const r = s.parameter ?? {}, i = s.sidecar ?? {};
2626
2640
  if (s.toolName === "TaskCreate") {
2627
- const a = we(i.task), o = x(a?.id);
2641
+ const a = Ee(i.task), o = x(a?.id);
2628
2642
  if (!o) continue;
2629
2643
  e.has(o) || t.push(o), e.set(o, {
2630
2644
  id: o,
@@ -2635,7 +2649,7 @@ function fn(n) {
2635
2649
  // initial status = pending (keep existing on repeat)
2636
2650
  });
2637
2651
  } else if (s.toolName === "TaskUpdate") {
2638
- const a = we(i.statusChange), o = x(r.taskId) || x(i.taskId), c = x(a?.to) || x(r.status);
2652
+ const a = Ee(i.statusChange), o = x(r.taskId) || x(i.taskId), c = x(a?.to) || x(r.status);
2639
2653
  if (!o || !c) continue;
2640
2654
  const u = e.get(o);
2641
2655
  u && e.set(o, { ...u, status: c });
@@ -2643,16 +2657,16 @@ function fn(n) {
2643
2657
  }
2644
2658
  return t.map((s) => e.get(s));
2645
2659
  }
2646
- function pn(n) {
2660
+ function gn(n) {
2647
2661
  return n.toolsetName === "" && n.toolName === "Agent";
2648
2662
  }
2649
- function gn(n) {
2663
+ function mn(n) {
2650
2664
  return !!n;
2651
2665
  }
2652
- function Ee(n) {
2666
+ function Ie(n) {
2653
2667
  n.status !== "running" && (n.status = "running", n.summary = void 0);
2654
2668
  }
2655
- function mn(n) {
2669
+ function bn(n) {
2656
2670
  const t = [], e = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map(), r = (i) => (e.has(i) || (t.push(i), e.set(i, { status: "running" }), s.set(i, /* @__PURE__ */ new Map())), e.get(i));
2657
2671
  for (const i of n)
2658
2672
  switch (i.kind) {
@@ -2663,11 +2677,11 @@ function mn(n) {
2663
2677
  }
2664
2678
  case "subagentStart": {
2665
2679
  const a = r(i.parentToolUseId);
2666
- a.agentId = i.agentId ?? a.agentId, a.subagentType = i.subagentType ?? a.subagentType, a.description = i.description ?? a.description, Ee(a);
2680
+ a.agentId = i.agentId ?? a.agentId, a.subagentType = i.subagentType ?? a.subagentType, a.description = i.description ?? a.description, Ie(a);
2667
2681
  break;
2668
2682
  }
2669
2683
  case "toolStart": {
2670
- Ee(r(i.parentToolUseId)), s.get(i.parentToolUseId).set(i.toolUseId, {
2684
+ Ie(r(i.parentToolUseId)), s.get(i.parentToolUseId).set(i.toolUseId, {
2671
2685
  toolsetName: i.toolsetName,
2672
2686
  toolName: i.toolName,
2673
2687
  parameter: i.parameter ?? {},
@@ -2693,21 +2707,21 @@ function mn(n) {
2693
2707
  tools: Array.from(s.get(i).values())
2694
2708
  }));
2695
2709
  }
2696
- function bn(n) {
2710
+ function vn(n) {
2697
2711
  return typeof n == "string" ? n : void 0;
2698
2712
  }
2699
- function vn(n) {
2713
+ function Sn(n) {
2700
2714
  const t = [];
2701
2715
  for (const e of n) {
2702
- if (e.type === "tool-call" && pn(e)) {
2716
+ if (e.type === "tool-call" && gn(e)) {
2703
2717
  t.push({
2704
2718
  kind: "agentStart",
2705
2719
  toolUseId: e.toolUseId ?? e.messageId,
2706
- description: bn(e.parameter.description)
2720
+ description: vn(e.parameter.description)
2707
2721
  });
2708
2722
  continue;
2709
2723
  }
2710
- if (e.type === "tool-call" && gn(e.parentToolUseId)) {
2724
+ if (e.type === "tool-call" && mn(e.parentToolUseId)) {
2711
2725
  const s = e.toolUseId ?? e.messageId;
2712
2726
  t.push({
2713
2727
  kind: "toolStart",
@@ -2744,37 +2758,37 @@ function vn(n) {
2744
2758
  }
2745
2759
  return t;
2746
2760
  }
2747
- function Sn(n) {
2761
+ function yn(n) {
2748
2762
  const t = Array.from(n.messages?.values() ?? []).filter(
2749
- (e) => e.type === "tool-call" && e.isComplete && hn(e)
2763
+ (e) => e.type === "tool-call" && e.isComplete && fn(e)
2750
2764
  );
2751
- return fn(t);
2765
+ return pn(t);
2752
2766
  }
2753
- function yn(n) {
2754
- return mn(vn(Array.from(n.messages?.values() ?? [])));
2767
+ function wn(n) {
2768
+ return bn(Sn(Array.from(n.messages?.values() ?? [])));
2755
2769
  }
2756
- function wn(n, t) {
2770
+ function En(n, t) {
2757
2771
  return n === t ? !0 : n.length !== t.length ? !1 : n.every((e, s) => {
2758
2772
  const r = t[s];
2759
2773
  return e.id === r.id && e.status === r.status && e.subject === r.subject && e.activeForm === r.activeForm && e.description === r.description;
2760
2774
  });
2761
2775
  }
2762
- function En(n, t) {
2776
+ function In(n, t) {
2763
2777
  return n.length !== t.length ? !1 : n.every((e, s) => {
2764
2778
  const r = t[s];
2765
2779
  return e.toolName === r.toolName && e.toolsetName === r.toolsetName && e.status === r.status && e.reason === r.reason;
2766
2780
  });
2767
2781
  }
2768
- function In(n, t) {
2782
+ function Tn(n, t) {
2769
2783
  return n === t ? !0 : n.length !== t.length ? !1 : n.every((e, s) => {
2770
2784
  const r = t[s];
2771
- return e.parentToolUseId === r.parentToolUseId && e.status === r.status && e.subagentType === r.subagentType && e.description === r.description && e.summary === r.summary && En(e.tools, r.tools);
2785
+ return e.parentToolUseId === r.parentToolUseId && e.status === r.status && e.subagentType === r.subagentType && e.description === r.description && e.summary === r.summary && In(e.tools, r.tools);
2772
2786
  });
2773
2787
  }
2774
- function Tn(n) {
2775
- const t = new A([]), e = new A([]), s = new U();
2776
- return s.add(n.pipe(Y(Sn), M(wn)).subscribe(t)), s.add(
2777
- n.pipe(Y(yn), M(In)).subscribe(e)
2788
+ function Cn(n) {
2789
+ const t = new A([]), e = new A([]), s = new L();
2790
+ return s.add(n.pipe(Y(yn), M(En)).subscribe(t)), s.add(
2791
+ n.pipe(Y(wn), M(Tn)).subscribe(e)
2778
2792
  ), {
2779
2793
  tasks$: t.asObservable(),
2780
2794
  subagents$: e.asObservable(),
@@ -2783,15 +2797,15 @@ function Tn(n) {
2783
2797
  teardown: () => s.unsubscribe()
2784
2798
  };
2785
2799
  }
2786
- function Ie(n) {
2800
+ function Te(n) {
2787
2801
  const t = /* @__PURE__ */ new Map();
2788
2802
  for (const e of n) t.set(e.sandboxName, e);
2789
2803
  return [...t.values()].sort(
2790
2804
  (e, s) => (e.sandboxBlueprintName || e.sandboxName).localeCompare(s.sandboxBlueprintName || s.sandboxName)
2791
2805
  );
2792
2806
  }
2793
- const ee = { kind: null, stopPhase: "idle" }, Cn = 1e4;
2794
- function xn(n, t) {
2807
+ const ee = { kind: null, stopPhase: "idle" }, xn = 1e4;
2808
+ function An(n, t) {
2795
2809
  return n.kind === t.kind && n.stopPhase === t.stopPhase && n.requestId === t.requestId;
2796
2810
  }
2797
2811
  class G {
@@ -2855,8 +2869,8 @@ class G {
2855
2869
  if (!t.customChannelId)
2856
2870
  throw new Error("customChannelId must be required");
2857
2871
  this.client = t.client, this.customChannelId = t.customChannelId, this.customMessageId = t.customMessageId, this.joinRunState = t.runState ?? "IDLE", this.isConnecting$ = new A(!1), this.runStatusSubject = new A(ee), this.conversation$ = new A(t.conversation), this.channelTitleSubject = new A(t.channelTitle ?? null), this.promptSuggestionSubject = new A(null), this.sandboxPhaseSubject = new A("idle"), this.launchedSandboxesSubject = new A(
2858
- Ie(t.launchedSandboxes ?? [])
2859
- ), this.derivedStores = Tn(this.conversation$), this.tasks$ = this.derivedStores.tasks$, this.subagents$ = this.derivedStores.subagents$, this.channelTitle$ = this.channelTitleSubject.pipe(M()), this.promptSuggestion$ = this.promptSuggestionSubject.pipe(M()), this.sandboxPhase$ = this.sandboxPhaseSubject.pipe(M()), this.launchedSandboxes$ = this.launchedSandboxesSubject.pipe(M()), this.runStatus$ = this.runStatusSubject.pipe(M(xn)), this.statesObserver = t.statesObserver;
2872
+ Te(t.launchedSandboxes ?? [])
2873
+ ), this.derivedStores = Cn(this.conversation$), this.tasks$ = this.derivedStores.tasks$, this.subagents$ = this.derivedStores.subagents$, this.channelTitle$ = this.channelTitleSubject.pipe(M()), this.promptSuggestion$ = this.promptSuggestionSubject.pipe(M()), this.sandboxPhase$ = this.sandboxPhaseSubject.pipe(M()), this.launchedSandboxes$ = this.launchedSandboxesSubject.pipe(M()), this.runStatus$ = this.runStatusSubject.pipe(M(An)), this.statesObserver = t.statesObserver;
2860
2874
  }
2861
2875
  /** Current Task Check List snapshot (F-013) — for framework-agnostic `getSnapshot()` bridging. */
2862
2876
  getTasks() {
@@ -2904,7 +2918,7 @@ class G {
2904
2918
  * launch whose name now appears (promoted to live). metadata (heartbeat-backed) is the sole authority.
2905
2919
  */
2906
2920
  applyLaunchedSandboxes(t) {
2907
- const e = Ie(t);
2921
+ const e = Te(t);
2908
2922
  this.pendingLaunches = this.pendingLaunches.filter((s) => !e.some((r) => r.sandboxName === s)), this.launchedSandboxesSubject.next(e);
2909
2923
  }
2910
2924
  /**
@@ -3167,7 +3181,7 @@ class G {
3167
3181
  const r = this.conversation$.value.pendingConsent;
3168
3182
  if (r) return Promise.reject(new ne(r.processId));
3169
3183
  this.clearPromptSuggestion();
3170
- const i = t.text.trim(), a = t.customMessageId ?? We();
3184
+ const i = t.text.trim(), a = t.customMessageId ?? Ye();
3171
3185
  return this.currentUserMessageId = a, this.lastSentMessageId = a, this.conversation$.next(
3172
3186
  this.conversation$.value.pushMessage({
3173
3187
  type: "user",
@@ -3330,7 +3344,7 @@ class G {
3330
3344
  this.forceStopTimer = void 0;
3331
3345
  const t = this.runStatusSubject.value;
3332
3346
  t.stopPhase === "stopping" && this.runStatusSubject.next({ ...t, stopPhase: "force-stoppable" });
3333
- }, Cn);
3347
+ }, xn);
3334
3348
  }
3335
3349
  /**
3336
3350
  * Cut the local SSE connection without telling the backend. This is *not* stop-generation (see
@@ -3347,20 +3361,20 @@ class G {
3347
3361
  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();
3348
3362
  }
3349
3363
  }
3350
- const An = {
3364
+ const On = {
3351
3365
  GOOD: "[Response Feedback: Good]",
3352
3366
  BAD: "[Response Feedback: Bad]"
3353
3367
  }, Ln = 8 * 1024;
3354
- function Un(n) {
3368
+ function Nn(n) {
3355
3369
  return new TextEncoder().encode(n).length;
3356
3370
  }
3357
- function Nn(n, t) {
3358
- const e = An[n], s = t?.trim() ?? "";
3371
+ function Rn(n, t) {
3372
+ const e = On[n], s = t?.trim() ?? "";
3359
3373
  return s ? `${e}
3360
3374
 
3361
3375
  ${s}` : e;
3362
3376
  }
3363
- function Rn(n) {
3377
+ function Fn(n) {
3364
3378
  const t = /^sandbox:\/\/([^/]+)\/([^?#]+)(?:\?([^#]*))?/.exec(n.trim());
3365
3379
  if (!t) return null;
3366
3380
  const e = decodeURIComponent(t[1]), s = t[2], r = new URLSearchParams(t[3] ?? "");
@@ -3372,8 +3386,8 @@ function Rn(n) {
3372
3386
  return null;
3373
3387
  }
3374
3388
  export {
3375
- _n as AsgardServiceClient,
3376
- Mn as AsgardSourceSetClient,
3389
+ Mn as AsgardServiceClient,
3390
+ Un as AsgardSourceSetClient,
3377
3391
  G as Channel,
3378
3392
  ne as ChannelAwaitingConsentError,
3379
3393
  te as ChannelBusyError,
@@ -3382,30 +3396,30 @@ export {
3382
3396
  Ln as FEEDBACK_COMMENT_MAX_BYTES,
3383
3397
  H as FetchSseAction,
3384
3398
  y as HttpError,
3385
- Te as MessageTemplateType,
3386
- An as RESPONSE_FEEDBACK_PREFIX,
3387
- rn as SOURCE_SET_DEFAULT_MAX_ENTRIES,
3399
+ Ce as MessageTemplateType,
3400
+ On as RESPONSE_FEEDBACK_PREFIX,
3401
+ an as SOURCE_SET_DEFAULT_MAX_ENTRIES,
3388
3402
  Xe as SOURCE_SET_MAX_PAGE_SIZE,
3389
- nn as SOURCE_SET_VOLUME_ROOT,
3390
- Ye as ToolCallConsentResult,
3403
+ sn as SOURCE_SET_VOLUME_ROOT,
3404
+ ze as ToolCallConsentResult,
3391
3405
  C as assertVolumePath,
3392
- Nn as composeFeedbackMessage,
3393
- vn as conversationToSubagentEvents,
3394
- Tn as createDerivedStores,
3395
- yn as deriveSubagents,
3396
- Sn as deriveTasks,
3397
- Un as feedbackCommentByteLength,
3398
- pn as isAgentTool,
3399
- Pn as isChannelAwaitingConsentError,
3400
- kn as isChannelBusyError,
3401
- On as isHttpError,
3402
- gn as isSubagentChildTool,
3403
- hn as isTaskTool,
3404
- Ie as reconcileLaunched,
3405
- mn as reduceSubagents,
3406
- fn as reduceTaskEvents,
3407
- Rn as resolveSandboxUri,
3408
- In as subagentsEqual,
3409
- wn as tasksEqual
3406
+ Rn as composeFeedbackMessage,
3407
+ Sn as conversationToSubagentEvents,
3408
+ Cn as createDerivedStores,
3409
+ wn as deriveSubagents,
3410
+ yn as deriveTasks,
3411
+ Nn as feedbackCommentByteLength,
3412
+ gn as isAgentTool,
3413
+ _n as isChannelAwaitingConsentError,
3414
+ Pn as isChannelBusyError,
3415
+ kn as isHttpError,
3416
+ mn as isSubagentChildTool,
3417
+ fn as isTaskTool,
3418
+ Te as reconcileLaunched,
3419
+ bn as reduceSubagents,
3420
+ pn as reduceTaskEvents,
3421
+ Fn as resolveSandboxUri,
3422
+ Tn as subagentsEqual,
3423
+ En as tasksEqual
3410
3424
  };
3411
3425
  //# sourceMappingURL=index.mjs.map