@asgard-js/core 0.2.54 → 0.2.56-canary.1

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
@@ -9,17 +9,17 @@ class de extends Error {
9
9
  function on(n) {
10
10
  return n instanceof de;
11
11
  }
12
- var $ = /* @__PURE__ */ ((n) => (n.RESET_CHANNEL = "RESET_CHANNEL", n.NONE = "NONE", n.RESPONSE_TOOL_CALL_CONSENT = "RESPONSE_TOOL_CALL_CONSENT", 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.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.DONE = "asgard.run.done", n.ERROR = "asgard.run.error", n))(d || {}), De = /* @__PURE__ */ ((n) => (n.ALLOW_ONCE = "ALLOW_ONCE", n.ALLOW_ALWAYS = "ALLOW_ALWAYS", n.DENY_ONCE = "DENY_ONCE", n))(De || {}), He = /* @__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))(He || {}), B = function(n, e) {
13
- return B = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(t, r) {
12
+ var k = /* @__PURE__ */ ((n) => (n.RESET_CHANNEL = "RESET_CHANNEL", n.NONE = "NONE", n.RESPONSE_TOOL_CALL_CONSENT = "RESPONSE_TOOL_CALL_CONSENT", n))(k || {}), 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.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.DONE = "asgard.run.done", n.ERROR = "asgard.run.error", n))(d || {}), je = /* @__PURE__ */ ((n) => (n.ALLOW_ONCE = "ALLOW_ONCE", n.ALLOW_ALWAYS = "ALLOW_ALWAYS", n.DENY_ONCE = "DENY_ONCE", n))(je || {}), He = /* @__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))(He || {}), q = function(n, e) {
13
+ return q = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(t, r) {
14
14
  t.__proto__ = r;
15
15
  } || function(t, r) {
16
16
  for (var o in r) Object.prototype.hasOwnProperty.call(r, o) && (t[o] = r[o]);
17
- }, B(n, e);
17
+ }, q(n, e);
18
18
  };
19
19
  function I(n, e) {
20
20
  if (typeof e != "function" && e !== null)
21
21
  throw new TypeError("Class extends value " + String(e) + " is not a constructor or null");
22
- B(n, e);
22
+ q(n, e);
23
23
  function t() {
24
24
  this.constructor = n;
25
25
  }
@@ -160,8 +160,8 @@ function Ge(n, e, t) {
160
160
  }
161
161
  function a(l, y) {
162
162
  r[l] && (o[l] = function(v) {
163
- return new Promise(function(E, w) {
164
- i.push([l, v, E, w]) > 1 || c(l, v);
163
+ return new Promise(function(w, E) {
164
+ i.push([l, v, w, E]) > 1 || c(l, v);
165
165
  });
166
166
  }, y && (o[l] = y(o[l])));
167
167
  }
@@ -185,7 +185,7 @@ function Ge(n, e, t) {
185
185
  l(y), i.shift(), i.length && c(i[0][0], i[0][1]);
186
186
  }
187
187
  }
188
- function Ve(n) {
188
+ function Ke(n) {
189
189
  if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
190
190
  var e = n[Symbol.asyncIterator], t;
191
191
  return e ? e.call(n) : (n = typeof P == "function" ? P(n) : n[Symbol.iterator](), t = {}, r("next"), r("throw"), r("return"), t[Symbol.asyncIterator] = function() {
@@ -213,7 +213,7 @@ function pe(n) {
213
213
  }, t = n(e);
214
214
  return t.prototype = Object.create(Error.prototype), t.prototype.constructor = t, t;
215
215
  }
216
- var q = pe(function(n) {
216
+ var B = pe(function(n) {
217
217
  return function(t) {
218
218
  n(this), this.message = t ? t.length + ` errors occurred during unsubscription:
219
219
  ` + t.map(function(r, o) {
@@ -222,7 +222,7 @@ var q = pe(function(n) {
222
222
  `) : "", this.name = "UnsubscriptionError", this.errors = t;
223
223
  };
224
224
  });
225
- function D(n, e) {
225
+ function j(n, e) {
226
226
  if (n) {
227
227
  var t = n.indexOf(e);
228
228
  0 <= t && n.splice(t, 1);
@@ -260,7 +260,7 @@ var N = (function() {
260
260
  try {
261
261
  f();
262
262
  } catch (v) {
263
- i = v instanceof q ? v.errors : [v];
263
+ i = v instanceof B ? v.errors : [v];
264
264
  }
265
265
  var p = this._finalizers;
266
266
  if (p) {
@@ -271,7 +271,7 @@ var N = (function() {
271
271
  try {
272
272
  ne(y);
273
273
  } catch (v) {
274
- i = i ?? [], v instanceof q ? i = R(R([], M(i)), M(v.errors)) : i.push(v);
274
+ i = i ?? [], v instanceof B ? i = R(R([], M(i)), M(v.errors)) : i.push(v);
275
275
  }
276
276
  }
277
277
  } catch (v) {
@@ -285,7 +285,7 @@ var N = (function() {
285
285
  }
286
286
  }
287
287
  if (i)
288
- throw new q(i);
288
+ throw new B(i);
289
289
  }
290
290
  }, n.prototype.add = function(e) {
291
291
  var t;
@@ -308,10 +308,10 @@ var N = (function() {
308
308
  this._parentage = Array.isArray(t) ? (t.push(e), t) : t ? [t, e] : e;
309
309
  }, n.prototype._removeParent = function(e) {
310
310
  var t = this._parentage;
311
- t === e ? this._parentage = null : Array.isArray(t) && D(t, e);
311
+ t === e ? this._parentage = null : Array.isArray(t) && j(t, e);
312
312
  }, n.prototype.remove = function(e) {
313
313
  var t = this._finalizers;
314
- t && D(t, e), e instanceof n && e._removeParent(this);
314
+ t && j(t, e), e instanceof n && e._removeParent(this);
315
315
  }, n.EMPTY = (function() {
316
316
  var e = new n();
317
317
  return e.closed = !0, e;
@@ -323,9 +323,9 @@ function ye(n) {
323
323
  function ne(n) {
324
324
  m(n) ? n() : n.unsubscribe();
325
325
  }
326
- var Ye = {
326
+ var Ve = {
327
327
  Promise: void 0
328
- }, qe = {
328
+ }, Be = {
329
329
  setTimeout: function(n, e) {
330
330
  for (var t = [], r = 2; r < arguments.length; r++)
331
331
  t[r - 2] = arguments[r];
@@ -337,13 +337,13 @@ var Ye = {
337
337
  delegate: void 0
338
338
  };
339
339
  function me(n) {
340
- qe.setTimeout(function() {
340
+ Be.setTimeout(function() {
341
341
  throw n;
342
342
  });
343
343
  }
344
344
  function W() {
345
345
  }
346
- function j(n) {
346
+ function D(n) {
347
347
  n();
348
348
  }
349
349
  var Q = (function(n) {
@@ -377,7 +377,7 @@ var Q = (function(n) {
377
377
  this.unsubscribe();
378
378
  }
379
379
  }, e;
380
- })(N), Ke = (function() {
380
+ })(N), Ye = (function() {
381
381
  function n(e) {
382
382
  this.partialObserver = e;
383
383
  }
@@ -387,7 +387,7 @@ var Q = (function(n) {
387
387
  try {
388
388
  t.next(e);
389
389
  } catch (r) {
390
- k(r);
390
+ $(r);
391
391
  }
392
392
  }, n.prototype.error = function(e) {
393
393
  var t = this.partialObserver;
@@ -395,17 +395,17 @@ var Q = (function(n) {
395
395
  try {
396
396
  t.error(e);
397
397
  } catch (r) {
398
- k(r);
398
+ $(r);
399
399
  }
400
400
  else
401
- k(e);
401
+ $(e);
402
402
  }, n.prototype.complete = function() {
403
403
  var e = this.partialObserver;
404
404
  if (e.complete)
405
405
  try {
406
406
  e.complete();
407
407
  } catch (t) {
408
- k(t);
408
+ $(t);
409
409
  }
410
410
  }, n;
411
411
  })(), X = (function(n) {
@@ -416,20 +416,20 @@ var Q = (function(n) {
416
416
  next: t ?? void 0,
417
417
  error: r ?? void 0,
418
418
  complete: o ?? void 0
419
- } : s = t, i.destination = new Ke(s), i;
419
+ } : s = t, i.destination = new Ye(s), i;
420
420
  }
421
421
  return e;
422
422
  })(Q);
423
- function k(n) {
423
+ function $(n) {
424
424
  me(n);
425
425
  }
426
- function Be(n) {
426
+ function qe(n) {
427
427
  throw n;
428
428
  }
429
429
  var We = {
430
430
  closed: !0,
431
431
  next: W,
432
- error: Be,
432
+ error: qe,
433
433
  complete: W
434
434
  }, Z = (function() {
435
435
  return typeof Symbol == "function" && Symbol.observable || "@@observable";
@@ -452,8 +452,8 @@ var g = (function() {
452
452
  var t = new n();
453
453
  return t.source = this, t.operator = e, t;
454
454
  }, n.prototype.subscribe = function(e, t, r) {
455
- var o = this, i = ze(e) ? e : new X(e, t, r);
456
- return j(function() {
455
+ var o = this, i = Je(e) ? e : new X(e, t, r);
456
+ return D(function() {
457
457
  var s = o, a = s.operator, c = s.source;
458
458
  i.add(a ? a.call(i, c) : c ? o._subscribe(i) : o._trySubscribe(i));
459
459
  }), i;
@@ -506,13 +506,13 @@ var g = (function() {
506
506
  })();
507
507
  function re(n) {
508
508
  var e;
509
- return (e = n ?? Ye.Promise) !== null && e !== void 0 ? e : Promise;
509
+ return (e = n ?? Ve.Promise) !== null && e !== void 0 ? e : Promise;
510
510
  }
511
- function Je(n) {
511
+ function ze(n) {
512
512
  return n && m(n.next) && m(n.error) && m(n.complete);
513
513
  }
514
- function ze(n) {
515
- return n && n instanceof Q || Je(n) && ye(n);
514
+ function Je(n) {
515
+ return n && n instanceof Q || ze(n) && ye(n);
516
516
  }
517
517
  function Qe(n) {
518
518
  return m(n?.lift);
@@ -586,7 +586,7 @@ var Ze = (function(n) {
586
586
  throw new et();
587
587
  }, e.prototype.next = function(t) {
588
588
  var r = this;
589
- j(function() {
589
+ D(function() {
590
590
  var o, i;
591
591
  if (r._throwIfClosed(), !r.isStopped) {
592
592
  r.currentObservers || (r.currentObservers = Array.from(r.observers));
@@ -608,7 +608,7 @@ var Ze = (function(n) {
608
608
  });
609
609
  }, e.prototype.error = function(t) {
610
610
  var r = this;
611
- j(function() {
611
+ D(function() {
612
612
  if (r._throwIfClosed(), !r.isStopped) {
613
613
  r.hasError = r.isStopped = !0, r.thrownError = t;
614
614
  for (var o = r.observers; o.length; )
@@ -617,7 +617,7 @@ var Ze = (function(n) {
617
617
  });
618
618
  }, e.prototype.complete = function() {
619
619
  var t = this;
620
- j(function() {
620
+ D(function() {
621
621
  if (t._throwIfClosed(), !t.isStopped) {
622
622
  t.isStopped = !0;
623
623
  for (var r = t.observers; r.length; )
@@ -640,7 +640,7 @@ var Ze = (function(n) {
640
640
  }, e.prototype._innerSubscribe = function(t) {
641
641
  var r = this, o = this, i = o.hasError, s = o.isStopped, a = o.observers;
642
642
  return i || s ? ve : (this.currentObservers = null, a.push(t), new N(function() {
643
- r.currentObservers = null, D(a, t);
643
+ r.currentObservers = null, j(a, t);
644
644
  }));
645
645
  }, e.prototype._checkFinalizedStatuses = function(t) {
646
646
  var r = this, o = r.hasError, i = r.thrownError, s = r.isStopped;
@@ -754,7 +754,7 @@ var Ze = (function(n) {
754
754
  }, e.prototype.unsubscribe = function() {
755
755
  if (!this.closed) {
756
756
  var t = this, r = t.id, o = t.scheduler, i = o.actions;
757
- this.work = this.state = this.scheduler = null, this.pending = !1, D(i, this), r != null && (this.id = this.recycleAsyncId(o, r, null)), this.delay = null, n.prototype.unsubscribe.call(this);
757
+ this.work = this.state = this.scheduler = null, this.pending = !1, j(i, this), r != null && (this.id = this.recycleAsyncId(o, r, null)), this.delay = null, n.prototype.unsubscribe.call(this);
758
758
  }
759
759
  }, e;
760
760
  })(nt), ae = (function() {
@@ -801,10 +801,10 @@ function Se(n) {
801
801
  function at(n) {
802
802
  return m(Se(n)) ? n.pop() : void 0;
803
803
  }
804
- function Ee(n) {
804
+ function we(n) {
805
805
  return ge(Se(n)) ? n.pop() : void 0;
806
806
  }
807
- var we = (function(n) {
807
+ var Ee = (function(n) {
808
808
  return n && typeof n.length == "number" && typeof n != "function";
809
809
  });
810
810
  function Oe(n) {
@@ -866,7 +866,7 @@ function T(n) {
866
866
  if (n != null) {
867
867
  if (Ie(n))
868
868
  return ut(n);
869
- if (we(n))
869
+ if (Ee(n))
870
870
  return lt(n);
871
871
  if (Oe(n))
872
872
  return ft(n);
@@ -941,7 +941,7 @@ function pt(n, e) {
941
941
  return he(this, function(c) {
942
942
  switch (c.label) {
943
943
  case 0:
944
- c.trys.push([0, 5, 6, 11]), t = Ve(n), c.label = 1;
944
+ c.trys.push([0, 5, 6, 11]), t = Ke(n), c.label = 1;
945
945
  case 1:
946
946
  return [4, t.next()];
947
947
  case 2:
@@ -1058,7 +1058,7 @@ function St(n, e) {
1058
1058
  if (n != null) {
1059
1059
  if (Ie(n))
1060
1060
  return vt(n, e);
1061
- if (we(n))
1061
+ if (Ee(n))
1062
1062
  return mt(n, e);
1063
1063
  if (Oe(n))
1064
1064
  return yt(n, e);
@@ -1074,13 +1074,13 @@ function St(n, e) {
1074
1074
  function te(n, e) {
1075
1075
  return e ? St(n, e) : T(n);
1076
1076
  }
1077
- function Et() {
1077
+ function wt() {
1078
1078
  for (var n = [], e = 0; e < arguments.length; e++)
1079
1079
  n[e] = arguments[e];
1080
- var t = Ee(n);
1080
+ var t = we(n);
1081
1081
  return te(n, t);
1082
1082
  }
1083
- function wt(n) {
1083
+ function Et(n) {
1084
1084
  return n instanceof Date && !isNaN(n);
1085
1085
  }
1086
1086
  function G(n, e) {
@@ -1129,7 +1129,7 @@ function Mt(n, e) {
1129
1129
  function Rt() {
1130
1130
  for (var n = [], e = 0; e < arguments.length; e++)
1131
1131
  n[e] = arguments[e];
1132
- var t = Ee(n), r = at(n), o = xt(n), i = o.args, s = o.keys;
1132
+ var t = we(n), r = at(n), o = xt(n), i = o.args, s = o.keys;
1133
1133
  if (i.length === 0)
1134
1134
  return te([], t);
1135
1135
  var a = new g(Nt(i, t, s ? function(c) {
@@ -1164,20 +1164,20 @@ function Ut(n, e, t, r, o, i, s, a) {
1164
1164
  return u < r ? y(v) : c.push(v);
1165
1165
  }, y = function(v) {
1166
1166
  u++;
1167
- var E = !1;
1168
- T(t(v, f++)).subscribe(O(e, function(w) {
1169
- e.next(w);
1167
+ var w = !1;
1168
+ T(t(v, f++)).subscribe(O(e, function(E) {
1169
+ e.next(E);
1170
1170
  }, function() {
1171
- E = !0;
1171
+ w = !0;
1172
1172
  }, void 0, function() {
1173
- if (E)
1173
+ if (w)
1174
1174
  try {
1175
1175
  u--;
1176
- for (var w = function() {
1176
+ for (var E = function() {
1177
1177
  var _ = c.shift();
1178
1178
  s || y(_);
1179
1179
  }; c.length && u < r; )
1180
- w();
1180
+ E();
1181
1181
  h();
1182
1182
  } catch (_) {
1183
1183
  e.error(_);
@@ -1202,7 +1202,7 @@ function Ue(n, e, t) {
1202
1202
  n === void 0 && (n = 0), t === void 0 && (t = it);
1203
1203
  var r = -1;
1204
1204
  return e != null && (ge(e) ? t = e : r = e), new g(function(o) {
1205
- var i = wt(n) ? +n - t.now() : n;
1205
+ var i = Et(n) ? +n - t.now() : n;
1206
1206
  i < 0 && (i = 0);
1207
1207
  var s = 0;
1208
1208
  return t.schedule(function() {
@@ -1210,10 +1210,10 @@ function Ue(n, e, t) {
1210
1210
  }, i);
1211
1211
  });
1212
1212
  }
1213
- function kt(n, e) {
1213
+ function $t(n, e) {
1214
1214
  return m(e) ? H(n, e, 1) : H(n, 1);
1215
1215
  }
1216
- function $t(n) {
1216
+ function kt(n) {
1217
1217
  return n <= 0 ? function() {
1218
1218
  return st;
1219
1219
  } : L(function(e, t) {
@@ -1223,20 +1223,20 @@ function $t(n) {
1223
1223
  }));
1224
1224
  });
1225
1225
  }
1226
- function jt(n) {
1226
+ function Dt(n) {
1227
1227
  return G(function() {
1228
1228
  return n;
1229
1229
  });
1230
1230
  }
1231
- function Dt(n, e) {
1231
+ function jt(n, e) {
1232
1232
  return H(function(t, r) {
1233
- return T(n(t, r)).pipe($t(1), jt(t));
1233
+ return T(n(t, r)).pipe(kt(1), Dt(t));
1234
1234
  });
1235
1235
  }
1236
1236
  function Ht(n, e) {
1237
1237
  e === void 0 && (e = be);
1238
1238
  var t = Ue(n, e);
1239
- return Dt(function() {
1239
+ return jt(function() {
1240
1240
  return t;
1241
1241
  });
1242
1242
  }
@@ -1257,12 +1257,12 @@ function Ft(n) {
1257
1257
  f ? (f.unsubscribe(), f = null, p()) : h = !0;
1258
1258
  };
1259
1259
  if (o != null) {
1260
- var v = typeof o == "number" ? Ue(o) : T(o(l, u)), E = O(c, function() {
1261
- E.unsubscribe(), y();
1260
+ var v = typeof o == "number" ? Ue(o) : T(o(l, u)), w = O(c, function() {
1261
+ w.unsubscribe(), y();
1262
1262
  }, function() {
1263
1263
  c.complete();
1264
1264
  });
1265
- v.subscribe(E);
1265
+ v.subscribe(w);
1266
1266
  } else
1267
1267
  y();
1268
1268
  } else
@@ -1279,16 +1279,16 @@ function Gt(n) {
1279
1279
  }, W)), !t.closed && e.subscribe(t);
1280
1280
  });
1281
1281
  }
1282
- async function Vt(n, e) {
1282
+ async function Kt(n, e) {
1283
1283
  const t = n.getReader();
1284
1284
  let r;
1285
1285
  for (; !(r = await t.read()).done; )
1286
1286
  e(r.value);
1287
1287
  }
1288
- function Yt(n) {
1288
+ function Vt(n) {
1289
1289
  let e, t, r, o = !1;
1290
1290
  return function(s) {
1291
- e === void 0 ? (e = s, t = 0, r = -1) : e = Kt(e, s);
1291
+ e === void 0 ? (e = s, t = 0, r = -1) : e = Yt(e, s);
1292
1292
  const a = e.length;
1293
1293
  let c = 0;
1294
1294
  for (; t < a; ) {
@@ -1312,7 +1312,7 @@ function Yt(n) {
1312
1312
  c === a ? e = void 0 : c !== 0 && (e = e.subarray(c), t -= c);
1313
1313
  };
1314
1314
  }
1315
- function qt(n, e, t) {
1315
+ function Bt(n, e, t) {
1316
1316
  let r = ue();
1317
1317
  const o = new TextDecoder();
1318
1318
  return function(s, a) {
@@ -1339,7 +1339,7 @@ function qt(n, e, t) {
1339
1339
  }
1340
1340
  };
1341
1341
  }
1342
- function Kt(n, e) {
1342
+ function Yt(n, e) {
1343
1343
  const t = new Uint8Array(n.length + e.length);
1344
1344
  return t.set(n), t.set(e, n.length), t;
1345
1345
  }
@@ -1351,7 +1351,7 @@ function ue() {
1351
1351
  retry: void 0
1352
1352
  };
1353
1353
  }
1354
- var Bt = function(n, e) {
1354
+ var qt = function(n, e) {
1355
1355
  var t = {};
1356
1356
  for (var r in n) Object.prototype.hasOwnProperty.call(n, r) && e.indexOf(r) < 0 && (t[r] = n[r]);
1357
1357
  if (n != null && typeof Object.getOwnPropertySymbols == "function")
@@ -1359,54 +1359,54 @@ var Bt = function(n, e) {
1359
1359
  e.indexOf(r[o]) < 0 && Object.prototype.propertyIsEnumerable.call(n, r[o]) && (t[r[o]] = n[r[o]]);
1360
1360
  return t;
1361
1361
  };
1362
- const J = "text/event-stream", Wt = 1e3, le = "last-event-id";
1362
+ const z = "text/event-stream", Wt = 1e3, le = "last-event-id";
1363
1363
  function Xt(n, e) {
1364
- var { signal: t, headers: r, onopen: o, onmessage: i, onclose: s, onerror: a, openWhenHidden: c, fetch: u } = e, f = Bt(e, ["signal", "headers", "onopen", "onmessage", "onclose", "onerror", "openWhenHidden", "fetch"]);
1364
+ var { signal: t, headers: r, onopen: o, onmessage: i, onclose: s, onerror: a, openWhenHidden: c, fetch: u } = e, f = qt(e, ["signal", "headers", "onopen", "onmessage", "onclose", "onerror", "openWhenHidden", "fetch"]);
1365
1365
  return new Promise((p, h) => {
1366
1366
  const l = Object.assign({}, r);
1367
- l.accept || (l.accept = J);
1367
+ l.accept || (l.accept = z);
1368
1368
  let y;
1369
1369
  function v() {
1370
- y.abort(), document.hidden || V();
1370
+ y.abort(), document.hidden || K();
1371
1371
  }
1372
1372
  c || document.addEventListener("visibilitychange", v);
1373
- let E = Wt, w = 0;
1373
+ let w = Wt, E = 0;
1374
1374
  function _() {
1375
- document.removeEventListener("visibilitychange", v), window.clearTimeout(w), y.abort();
1375
+ document.removeEventListener("visibilitychange", v), window.clearTimeout(E), y.abort();
1376
1376
  }
1377
1377
  t?.addEventListener("abort", () => {
1378
1378
  _(), p();
1379
1379
  });
1380
- const $e = u ?? window.fetch, je = o ?? Jt;
1381
- async function V() {
1382
- var Y;
1380
+ const ke = u ?? window.fetch, De = o ?? zt;
1381
+ async function K() {
1382
+ var V;
1383
1383
  y = new AbortController();
1384
1384
  try {
1385
- const U = await $e(n, Object.assign(Object.assign({}, f), { headers: l, signal: y.signal }));
1386
- await je(U), await Vt(U.body, Yt(qt((C) => {
1385
+ const U = await ke(n, Object.assign(Object.assign({}, f), { headers: l, signal: y.signal }));
1386
+ await De(U), await Kt(U.body, Vt(Bt((C) => {
1387
1387
  C ? l[le] = C : delete l[le];
1388
1388
  }, (C) => {
1389
- E = C;
1389
+ w = C;
1390
1390
  }, i))), s?.(), _(), p();
1391
1391
  } catch (U) {
1392
1392
  if (!y.signal.aborted)
1393
1393
  try {
1394
- const C = (Y = a?.(U)) !== null && Y !== void 0 ? Y : E;
1395
- window.clearTimeout(w), w = window.setTimeout(V, C);
1394
+ const C = (V = a?.(U)) !== null && V !== void 0 ? V : w;
1395
+ window.clearTimeout(E), E = window.setTimeout(K, C);
1396
1396
  } catch (C) {
1397
1397
  _(), h(C);
1398
1398
  }
1399
1399
  }
1400
1400
  }
1401
- V();
1401
+ K();
1402
1402
  });
1403
1403
  }
1404
- function Jt(n) {
1404
+ function zt(n) {
1405
1405
  const e = n.headers.get("content-type");
1406
- if (!e?.startsWith(J))
1407
- throw new Error(`Expected content-type to be ${J}, Actual: ${e}`);
1406
+ if (!e?.startsWith(z))
1407
+ throw new Error(`Expected content-type to be ${z}, Actual: ${e}`);
1408
1408
  }
1409
- function zt(n) {
1409
+ function Jt(n) {
1410
1410
  const { endpoint: e, apiKey: t, payload: r, debugMode: o, customHeaders: i } = n;
1411
1411
  return new g((s) => {
1412
1412
  const a = new AbortController();
@@ -1542,14 +1542,14 @@ class sn {
1542
1542
  }
1543
1543
  }
1544
1544
  fetchSse(e, t) {
1545
- t?.onSseStart?.(), this.inFlight += 1, zt({
1545
+ t?.onSseStart?.(), this.inFlight += 1, Jt({
1546
1546
  apiKey: this.apiKey,
1547
1547
  endpoint: this.endpoint,
1548
1548
  debugMode: this.debugMode,
1549
1549
  payload: this.transformSsePayload?.(e) ?? e,
1550
1550
  customHeaders: this.customHeaders
1551
1551
  }).pipe(
1552
- kt((r) => Et(r).pipe(Ht(t?.delayTime ?? 50))),
1552
+ $t((r) => wt(r).pipe(Ht(t?.delayTime ?? 50))),
1553
1553
  Gt(this.destroy$),
1554
1554
  Ft(3)
1555
1555
  ).subscribe({
@@ -1621,14 +1621,45 @@ class sn {
1621
1621
  throw console.error("[AsgardServiceClient] File upload error:", s), s;
1622
1622
  }
1623
1623
  }
1624
+ /**
1625
+ * 下載 channel sandbox 工作目錄裡的檔案(cwd:// URI action)。
1626
+ * 呼叫 Edge Server GET <base>/cwd/download?custom_channel_id=xxx&relative_path=xxx 取回 binary。
1627
+ */
1628
+ async downloadCwdFile(e, t) {
1629
+ const r = this.getBaseEndpoint();
1630
+ if (!r)
1631
+ throw new Error("Unable to derive cwd download endpoint. Please provide botProviderEndpoint in config.");
1632
+ const o = `custom_channel_id=${encodeURIComponent(t)}&relative_path=${encodeURIComponent(e)}`, i = `${r}/cwd/download?${o}`, s = {
1633
+ ...this.customHeaders
1634
+ };
1635
+ this.apiKey && (s["X-API-KEY"] = this.apiKey);
1636
+ try {
1637
+ const a = await fetch(i, {
1638
+ method: "GET",
1639
+ headers: s
1640
+ });
1641
+ if (!a.ok)
1642
+ throw new Error(`CWD download failed: ${a.status} ${a.statusText}`);
1643
+ const c = await a.blob(), u = e.split("/").pop() || "download";
1644
+ return this.debugMode && console.log("[AsgardServiceClient] CWD download response:", { filename: u, size: c.size }), { blob: c, filename: u };
1645
+ } catch (a) {
1646
+ throw console.error("[AsgardServiceClient] CWD download error:", a), a;
1647
+ }
1648
+ }
1624
1649
  /**
1625
1650
  * 從 botProviderEndpoint 衍生 Blob API endpoint
1626
1651
  */
1627
1652
  deriveBlobEndpoint() {
1628
- if (!this.botProviderEndpoint && !this.endpoint)
1629
- return null;
1653
+ const e = this.getBaseEndpoint();
1654
+ return e ? `${e}/blob` : null;
1655
+ }
1656
+ /**
1657
+ * 衍生 bot provider 的 base endpoint(不含子路徑)。
1658
+ * 優先用 botProviderEndpoint;若只有 deprecated 的 endpoint 則反推(移除 /message/sse)。已去除尾部斜線。
1659
+ */
1660
+ getBaseEndpoint() {
1630
1661
  let e = this.botProviderEndpoint;
1631
- return !e && this.endpoint && (e = this.endpoint.replace("/message/sse", "")), e ? (e = e.replace(/\/+$/, ""), `${e}/blob`) : null;
1662
+ return !e && this.endpoint && (e = this.endpoint.replace("/message/sse", "")), e ? e.replace(/\/+$/, "") : null;
1632
1663
  }
1633
1664
  }
1634
1665
  const b = [];
@@ -1637,15 +1668,15 @@ for (let n = 0; n < 256; ++n)
1637
1668
  function Zt(n, e = 0) {
1638
1669
  return (b[n[e + 0]] + b[n[e + 1]] + b[n[e + 2]] + b[n[e + 3]] + "-" + b[n[e + 4]] + b[n[e + 5]] + "-" + b[n[e + 6]] + b[n[e + 7]] + "-" + b[n[e + 8]] + b[n[e + 9]] + "-" + b[n[e + 10]] + b[n[e + 11]] + b[n[e + 12]] + b[n[e + 13]] + b[n[e + 14]] + b[n[e + 15]]).toLowerCase();
1639
1670
  }
1640
- let K;
1671
+ let Y;
1641
1672
  const en = new Uint8Array(16);
1642
1673
  function tn() {
1643
- if (!K) {
1674
+ if (!Y) {
1644
1675
  if (typeof crypto > "u" || !crypto.getRandomValues)
1645
1676
  throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
1646
- K = crypto.getRandomValues.bind(crypto);
1677
+ Y = crypto.getRandomValues.bind(crypto);
1647
1678
  }
1648
- return K(en);
1679
+ return Y(en);
1649
1680
  }
1650
1681
  const nn = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), fe = { randomUUID: nn };
1651
1682
  function rn(n, e, t) {
@@ -1655,7 +1686,7 @@ function rn(n, e, t) {
1655
1686
  throw new Error("Random bytes length must be >= 16");
1656
1687
  return r[6] = r[6] & 15 | 64, r[8] = r[8] & 63 | 128, Zt(r);
1657
1688
  }
1658
- function ke(n, e, t) {
1689
+ function $e(n, e, t) {
1659
1690
  return fe.randomUUID && !n ? fe.randomUUID() : rn(n);
1660
1691
  }
1661
1692
  class S {
@@ -1736,7 +1767,7 @@ class S {
1736
1767
  }), new S({ messages: r, pendingConsent: this.pendingConsent });
1737
1768
  }
1738
1769
  onMessageError(e) {
1739
- const t = ke(), r = e.fact.runError.error, o = new Map(this.messages);
1770
+ const t = $e(), r = e.fact.runError.error, o = new Map(this.messages);
1740
1771
  return o.set(t, {
1741
1772
  type: "error",
1742
1773
  eventType: d.ERROR,
@@ -1782,7 +1813,7 @@ class S {
1782
1813
  return new S({ messages: this.messages, pendingConsent: t });
1783
1814
  }
1784
1815
  }
1785
- class z {
1816
+ class J {
1786
1817
  client;
1787
1818
  customChannelId;
1788
1819
  customMessageId;
@@ -1804,11 +1835,11 @@ class z {
1804
1835
  this.client = e.client, this.customChannelId = e.customChannelId, this.customMessageId = e.customMessageId, this.isConnecting$ = new ie(!1), this.conversation$ = new ie(e.conversation), this.statesObserver = e.statesObserver;
1805
1836
  }
1806
1837
  static create(e) {
1807
- const t = new z(e);
1838
+ const t = new J(e);
1808
1839
  return t.subscribe(), t;
1809
1840
  }
1810
1841
  static async reset(e, t, r) {
1811
- const o = new z(e);
1842
+ const o = new J(e);
1812
1843
  try {
1813
1844
  return o.subscribe(), await o.resetChannel(t, r), o;
1814
1845
  } catch (i) {
@@ -1863,7 +1894,7 @@ class z {
1863
1894
  resetChannel(e, t) {
1864
1895
  return this.fetchSse(
1865
1896
  {
1866
- action: $.RESET_CHANNEL,
1897
+ action: k.RESET_CHANNEL,
1867
1898
  customChannelId: this.customChannelId,
1868
1899
  customMessageId: this.customMessageId,
1869
1900
  text: e?.text || "",
@@ -1873,7 +1904,7 @@ class z {
1873
1904
  );
1874
1905
  }
1875
1906
  sendMessage(e, t) {
1876
- const r = e.text.trim(), o = e.customMessageId ?? ke();
1907
+ const r = e.text.trim(), o = e.customMessageId ?? $e();
1877
1908
  return this.currentUserMessageId = o, this.lastSentMessageId = o, this.conversation$.next(
1878
1909
  this.conversation$.value.pushMessage({
1879
1910
  type: "user",
@@ -1886,7 +1917,7 @@ class z {
1886
1917
  })
1887
1918
  ), this.fetchSse(
1888
1919
  {
1889
- action: $.NONE,
1920
+ action: k.NONE,
1890
1921
  customChannelId: this.customChannelId,
1891
1922
  customMessageId: o,
1892
1923
  payload: this.resolvePayload(e?.payload),
@@ -1899,7 +1930,7 @@ class z {
1899
1930
  replyToolCallConsents(e, t, r) {
1900
1931
  return this.conversation$.next(this.conversation$.value.clearPendingConsent()), this.fetchSse(
1901
1932
  {
1902
- action: $.RESPONSE_TOOL_CALL_CONSENT,
1933
+ action: k.RESPONSE_TOOL_CALL_CONSENT,
1903
1934
  customChannelId: this.customChannelId,
1904
1935
  customMessageId: this.lastSentMessageId ?? this.customMessageId,
1905
1936
  payload: this.resolvePayload(r),
@@ -1915,13 +1946,13 @@ class z {
1915
1946
  }
1916
1947
  export {
1917
1948
  sn as AsgardServiceClient,
1918
- z as Channel,
1949
+ J as Channel,
1919
1950
  S as Conversation,
1920
1951
  d as EventType,
1921
- $ as FetchSseAction,
1952
+ k as FetchSseAction,
1922
1953
  de as HttpError,
1923
1954
  He as MessageTemplateType,
1924
- De as ToolCallConsentResult,
1955
+ je as ToolCallConsentResult,
1925
1956
  on as isHttpError
1926
1957
  };
1927
1958
  //# sourceMappingURL=index.mjs.map