@harnessio/ai-chat-core 0.0.19 → 0.0.20

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.js CHANGED
@@ -1,7 +1,7 @@
1
1
  var H = Object.defineProperty;
2
- var J = (i, n, t) => n in i ? H(i, n, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[n] = t;
3
- var u = (i, n, t) => J(i, typeof n != "symbol" ? n + "" : n, t);
4
- import U, { createContext as B, useContext as q, useState as m, useEffect as w, useReducer as z, useCallback as C, useMemo as V } from "react";
2
+ var J = (a, n, t) => n in a ? H(a, n, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[n] = t;
3
+ var u = (a, n, t) => J(a, typeof n != "symbol" ? n + "" : n, t);
4
+ import U, { createContext as B, useContext as q, useState as b, useEffect as w, useReducer as z, useCallback as C, useMemo as V } from "react";
5
5
  class G {
6
6
  constructor() {
7
7
  u(this, "plugins", /* @__PURE__ */ new Map());
@@ -16,7 +16,7 @@ class G {
16
16
  unregisterPlugin(n) {
17
17
  const t = this.plugins.get(n);
18
18
  return t ? (t.renderers.forEach((e) => {
19
- const r = (this.renderersByType.get(e.type) || []).filter((a) => !t.renderers.includes(a));
19
+ const r = (this.renderersByType.get(e.type) || []).filter((i) => !t.renderers.includes(i));
20
20
  r.length === 0 ? this.renderersByType.delete(e.type) : this.renderersByType.set(e.type, r);
21
21
  }), this.plugins.delete(n)) : !1;
22
22
  }
@@ -41,29 +41,37 @@ class Y {
41
41
  u(this, "handlers", /* @__PURE__ */ new Map());
42
42
  u(this, "renderers", /* @__PURE__ */ new Map());
43
43
  }
44
- registerHandler(n, t) {
45
- this.handlers.set(n, t);
44
+ registerHandler(n, t, e = 0) {
45
+ const s = this.handlers.get(n) || [], r = { handler: t, priority: e }, i = s.findIndex((o) => o.priority < e);
46
+ i === -1 ? s.push(r) : s.splice(i, 0, r), this.handlers.set(n, s);
46
47
  }
47
- registerRenderer(n, t) {
48
- this.renderers.set(n, t);
48
+ registerRenderer(n, t, e = 0) {
49
+ const s = this.renderers.get(n) || [], r = { renderer: t, priority: e }, i = s.findIndex((o) => o.priority < e);
50
+ i === -1 ? s.push(r) : s.splice(i, 0, r), this.renderers.set(n, s);
49
51
  }
50
52
  unregister(n) {
51
53
  this.handlers.delete(n), this.renderers.delete(n);
52
54
  }
53
55
  getHandler(n) {
54
- return this.handlers.get(n);
56
+ var e;
57
+ const t = this.handlers.get(n);
58
+ return (e = t == null ? void 0 : t[0]) == null ? void 0 : e.handler;
55
59
  }
56
60
  getRenderer(n) {
57
- return this.renderers.get(n);
61
+ var e;
62
+ const t = this.renderers.get(n);
63
+ return (e = t == null ? void 0 : t[0]) == null ? void 0 : e.renderer;
58
64
  }
59
65
  getStrategy() {
60
66
  return "queue";
61
67
  }
62
68
  hasHandler(n) {
63
- return this.handlers.has(n);
69
+ const t = this.handlers.get(n);
70
+ return t !== void 0 && t.length > 0;
64
71
  }
65
72
  hasRenderer(n) {
66
- return this.renderers.has(n);
73
+ const t = this.renderers.get(n);
74
+ return t !== void 0 && t.length > 0;
67
75
  }
68
76
  clear() {
69
77
  this.handlers.clear(), this.renderers.clear();
@@ -120,11 +128,11 @@ class K {
120
128
  });
121
129
  t.status = { type: "complete", result: r }, t.result = r;
122
130
  } catch (r) {
123
- const a = r instanceof Error ? r.message : "Unknown error";
124
- t.status = { type: "error", error: a }, t.error = a;
131
+ const i = r instanceof Error ? r.message : "Unknown error";
132
+ t.status = { type: "error", error: i }, t.error = i;
125
133
  } finally {
126
- const r = this.runningByName.get(t.name) || [], a = r.indexOf(n);
127
- a > -1 && r.splice(a, 1), r.length === 0 ? this.runningByName.delete(t.name) : this.runningByName.set(t.name, r), this.notifySubscribers(n);
134
+ const r = this.runningByName.get(t.name) || [], i = r.indexOf(n);
135
+ i > -1 && r.splice(i, 1), r.length === 0 ? this.runningByName.delete(t.name) : this.runningByName.set(t.name, r), this.notifySubscribers(n);
128
136
  }
129
137
  }
130
138
  this.isProcessing = !1;
@@ -146,7 +154,7 @@ class K {
146
154
  this.executions.clear(), this.executionQueue = [], this.runningByName.clear();
147
155
  }
148
156
  }
149
- class b {
157
+ class m {
150
158
  constructor() {
151
159
  u(this, "_subscriptions", /* @__PURE__ */ new Set());
152
160
  }
@@ -163,7 +171,7 @@ class b {
163
171
  return this._subscriptions.size;
164
172
  }
165
173
  }
166
- class X extends b {
174
+ class X extends m {
167
175
  constructor() {
168
176
  super(...arguments);
169
177
  u(this, "_state", {
@@ -227,46 +235,46 @@ class X extends b {
227
235
  }
228
236
  focusNext(t) {
229
237
  if (!this._state.focusedMessageId || !t.length) return;
230
- const e = t.findIndex((a) => a.id === this._state.focusedMessageId);
238
+ const e = t.findIndex((i) => i.id === this._state.focusedMessageId);
231
239
  if (e === -1) return;
232
240
  const s = t[e], r = this._state.focusedContentIndex ?? 0;
233
241
  if (r + 1 < s.content.length) {
234
- const a = s.content[r + 1];
235
- this.focus(a, s, r + 1, this._state.context || "detail");
242
+ const i = s.content[r + 1];
243
+ this.focus(i, s, r + 1, this._state.context || "detail");
236
244
  return;
237
245
  }
238
246
  if (e + 1 < t.length) {
239
- const a = t[e + 1];
240
- a.content.length > 0 && this.focus(a.content[0], a, 0, this._state.context || "detail");
247
+ const i = t[e + 1];
248
+ i.content.length > 0 && this.focus(i.content[0], i, 0, this._state.context || "detail");
241
249
  }
242
250
  }
243
251
  focusPrevious(t) {
244
252
  if (!this._state.focusedMessageId || !t.length) return;
245
- const e = t.findIndex((a) => a.id === this._state.focusedMessageId);
253
+ const e = t.findIndex((i) => i.id === this._state.focusedMessageId);
246
254
  if (e === -1) return;
247
255
  const s = t[e], r = this._state.focusedContentIndex ?? 0;
248
256
  if (r > 0) {
249
- const a = s.content[r - 1];
250
- this.focus(a, s, r - 1, this._state.context || "detail");
257
+ const i = s.content[r - 1];
258
+ this.focus(i, s, r - 1, this._state.context || "detail");
251
259
  return;
252
260
  }
253
261
  if (e > 0) {
254
- const a = t[e - 1];
255
- if (a.content.length > 0) {
256
- const o = a.content.length - 1;
257
- this.focus(a.content[o], a, o, this._state.context || "detail");
262
+ const i = t[e - 1];
263
+ if (i.content.length > 0) {
264
+ const o = i.content.length - 1;
265
+ this.focus(i.content[o], i, o, this._state.context || "detail");
258
266
  }
259
267
  }
260
268
  }
261
269
  }
262
270
  let Z = 0, tt = 0;
263
- function I() {
271
+ function T() {
264
272
  return `msg-${Date.now()}-${++Z}`;
265
273
  }
266
274
  function N() {
267
275
  return `thread-${Date.now()}-${++tt}`;
268
276
  }
269
- class v extends b {
277
+ class v extends m {
270
278
  constructor(t) {
271
279
  super();
272
280
  u(this, "_state");
@@ -294,7 +302,7 @@ class v extends b {
294
302
  return super.subscribe(t);
295
303
  }
296
304
  }
297
- class et extends b {
305
+ class et extends m {
298
306
  constructor() {
299
307
  super(...arguments);
300
308
  u(this, "_text", "");
@@ -322,7 +330,7 @@ class et extends b {
322
330
  this._isSubmitting = t, this.notifySubscribers();
323
331
  }
324
332
  }
325
- class R extends b {
333
+ class R extends m {
326
334
  constructor(t) {
327
335
  super();
328
336
  u(this, "composer");
@@ -412,7 +420,7 @@ class R extends b {
412
420
  return super.subscribe(t);
413
421
  }
414
422
  }
415
- class E extends b {
423
+ class E extends m {
416
424
  constructor(t) {
417
425
  super();
418
426
  u(this, "_messages", []);
@@ -464,7 +472,7 @@ class E extends b {
464
472
  }
465
473
  append(t) {
466
474
  const e = {
467
- id: t.id || I(),
475
+ id: t.id || T(),
468
476
  parentId: t.parentId,
469
477
  role: t.role,
470
478
  content: t.content,
@@ -478,7 +486,7 @@ class E extends b {
478
486
  if (this._isRunning)
479
487
  throw new Error("A run is already in progress");
480
488
  this._isWaitingForUser = !1, this._pendingCapability = null, this._isRunning = !0, this._abortController = new AbortController(), this._currentPart = null;
481
- const e = I(), s = {
489
+ const e = T(), s = {
482
490
  id: e,
483
491
  role: "assistant",
484
492
  content: [],
@@ -493,20 +501,20 @@ class E extends b {
493
501
  signal: this._abortController.signal,
494
502
  systemEvent: t
495
503
  });
496
- for await (const a of r) {
504
+ for await (const i of r) {
497
505
  if (this._abortController.signal.aborted)
498
506
  break;
499
- this.handleStreamEvent(e, a.event);
507
+ this.handleStreamEvent(e, i.event);
500
508
  }
501
509
  this.updateMessageStatus(e, { type: "complete" });
502
510
  } catch (r) {
503
511
  if (r instanceof Error && r.name === "AbortError")
504
512
  this.completeStreamingContent(e), this.updateMessageStatus(e, { type: "cancelled" });
505
513
  else {
506
- const a = r instanceof Error ? r.message : "Unknown error";
514
+ const i = r instanceof Error ? r.message : "Unknown error";
507
515
  this.completeStreamingContent(e), this.updateMessageStatus(e, {
508
516
  type: "error",
509
- error: a
517
+ error: i
510
518
  });
511
519
  }
512
520
  } finally {
@@ -517,7 +525,7 @@ class E extends b {
517
525
  if (this._isRunning)
518
526
  throw new Error("A run is already in progress");
519
527
  this._isWaitingForUser = !1, this._pendingCapability = null, this.append(t), this._isRunning = !0, this._abortController = new AbortController(), this._currentPart = null;
520
- const e = I(), s = {
528
+ const e = T(), s = {
521
529
  id: e,
522
530
  role: "assistant",
523
531
  content: [],
@@ -531,20 +539,20 @@ class E extends b {
531
539
  conversationId: this._conversationId,
532
540
  signal: this._abortController.signal
533
541
  });
534
- for await (const a of r) {
542
+ for await (const i of r) {
535
543
  if (this._abortController.signal.aborted)
536
544
  break;
537
- this.handleStreamEvent(e, a.event);
545
+ this.handleStreamEvent(e, i.event);
538
546
  }
539
547
  this.updateMessageStatus(e, { type: "complete" });
540
548
  } catch (r) {
541
549
  if (r instanceof Error && r.name === "AbortError")
542
550
  this.completeStreamingContent(e), this.updateMessageStatus(e, { type: "cancelled" });
543
551
  else {
544
- const a = r instanceof Error ? r.message : "Unknown error";
552
+ const i = r instanceof Error ? r.message : "Unknown error";
545
553
  this.completeStreamingContent(e), this.updateMessageStatus(e, {
546
554
  type: "error",
547
- error: a
555
+ error: i
548
556
  });
549
557
  }
550
558
  } finally {
@@ -617,12 +625,12 @@ class E extends b {
617
625
  }
618
626
  ];
619
627
  }
620
- const a = [
628
+ const i = [
621
629
  ...this._messages.slice(0, s),
622
630
  { ...r, timestamp: Date.now() },
623
631
  ...this._messages.slice(s + 1)
624
632
  ];
625
- this.updateMessages(a);
633
+ this.updateMessages(i);
626
634
  }
627
635
  handlePartStart(t, e) {
628
636
  const s = t.content.length;
@@ -687,7 +695,7 @@ class E extends b {
687
695
  this._currentPart = null;
688
696
  }
689
697
  updateMessageStatus(t, e) {
690
- const s = this._messages.findIndex((a) => a.id === t);
698
+ const s = this._messages.findIndex((i) => i.id === t);
691
699
  if (s === -1) return;
692
700
  const r = [
693
701
  ...this._messages.slice(0, s),
@@ -707,12 +715,12 @@ class E extends b {
707
715
  var d;
708
716
  return ((d = c.status) == null ? void 0 : d.type) === "streaming";
709
717
  })) return;
710
- const a = s.content.map((c) => {
718
+ const i = s.content.map((c) => {
711
719
  var d;
712
720
  return ((d = c.status) == null ? void 0 : d.type) === "streaming" ? { ...c, status: { type: "complete" } } : c;
713
721
  }), o = [
714
722
  ...this._messages.slice(0, e),
715
- { ...s, content: a, timestamp: Date.now() },
723
+ { ...s, content: i, timestamp: Date.now() },
716
724
  ...this._messages.slice(e + 1)
717
725
  ];
718
726
  this.updateMessages(o);
@@ -733,7 +741,7 @@ class E extends b {
733
741
  this._title = t, this.notifySubscribers();
734
742
  }
735
743
  }
736
- class st extends b {
744
+ class st extends m {
737
745
  constructor(t) {
738
746
  super();
739
747
  u(this, "_mainThreadId");
@@ -790,12 +798,12 @@ class st extends b {
790
798
  };
791
799
  }
792
800
  async switchToThread(t) {
793
- var a, o;
801
+ var i, o;
794
802
  const e = this._threads.get(t);
795
803
  if (!e)
796
804
  throw new Error(`Thread ${t} not found`);
797
805
  const s = this._threadStates.get(this._mainThreadId);
798
- s && (s.isMain = !1, this._threadStates.set(this._mainThreadId, s), (a = this._threadItems.get(this._mainThreadId)) == null || a.updateState(s)), this._mainThreadId = t;
806
+ s && (s.isMain = !1, this._threadStates.set(this._mainThreadId, s), (i = this._threadItems.get(this._mainThreadId)) == null || i.updateState(s)), this._mainThreadId = t;
799
807
  const r = this._threadStates.get(t);
800
808
  if (r && (r.isMain = !0, this._threadStates.set(t, r), (o = this._threadItems.get(t)) == null || o.updateState(r), e.setConversationId(r.conversationId), e.setTitle(r.title)), this.config.threadListAdapter && (r != null && r.conversationId)) {
801
809
  this._isLoading = !0, this.notifySubscribers();
@@ -825,18 +833,18 @@ class st extends b {
825
833
  updatedAt: Date.now()
826
834
  };
827
835
  this._threadStates.set(t, r);
828
- const a = new v({
836
+ const i = new v({
829
837
  state: r,
830
838
  onSwitchTo: this.switchToThread.bind(this),
831
839
  onRename: this.renameThread.bind(this),
832
840
  onDelete: this.deleteThread.bind(this)
833
841
  });
834
- if (this._threadItems.set(t, a), s.subscribe(() => {
842
+ if (this._threadItems.set(t, i), s.subscribe(() => {
835
843
  this.syncThreadStateFromRuntime(t, s), this.notifySubscribers();
836
844
  }), this.config.threadListAdapter)
837
845
  try {
838
846
  const o = await this.config.threadListAdapter.createThread();
839
- r.conversationId = o.conversationId, this._threadStates.set(t, r), a.updateState(r);
847
+ r.conversationId = o.conversationId, this._threadStates.set(t, r), i.updateState(r);
840
848
  } catch (o) {
841
849
  console.error("Failed to create thread:", o);
842
850
  }
@@ -861,16 +869,16 @@ class st extends b {
861
869
  const r = new E({
862
870
  streamAdapter: this.config.streamAdapter,
863
871
  capabilityExecutionManager: this.config.capabilityExecutionManager
864
- }), a = new R(r);
865
- this._threads.set(s.id, a), this._threadStates.set(s.id, s);
872
+ }), i = new R(r);
873
+ this._threads.set(s.id, i), this._threadStates.set(s.id, s);
866
874
  const o = new v({
867
875
  state: s,
868
876
  onSwitchTo: this.switchToThread.bind(this),
869
877
  onRename: this.renameThread.bind(this),
870
878
  onDelete: this.deleteThread.bind(this)
871
879
  });
872
- this._threadItems.set(s.id, o), a.subscribe(() => {
873
- this.syncThreadStateFromRuntime(s.id, a), this.notifySubscribers();
880
+ this._threadItems.set(s.id, o), i.subscribe(() => {
881
+ this.syncThreadStateFromRuntime(s.id, i), this.notifySubscribers();
874
882
  });
875
883
  }
876
884
  return e;
@@ -895,8 +903,8 @@ class st extends b {
895
903
  if (s.title = e, s.updatedAt = Date.now(), this._threadStates.set(t, s), (r = this._threadItems.get(t)) == null || r.updateState(s), this.config.threadListAdapter)
896
904
  try {
897
905
  await this.config.threadListAdapter.updateThread(t, { title: e });
898
- } catch (a) {
899
- console.error("Failed to rename thread:", a);
906
+ } catch (i) {
907
+ console.error("Failed to rename thread:", i);
900
908
  }
901
909
  this.notifySubscribers();
902
910
  }
@@ -917,7 +925,7 @@ class st extends b {
917
925
  this.notifySubscribers();
918
926
  }
919
927
  }
920
- class mt extends b {
928
+ class bt extends m {
921
929
  constructor(t) {
922
930
  super();
923
931
  u(this, "threads");
@@ -981,10 +989,10 @@ class mt extends b {
981
989
  for (let s = t.length - 1; s >= 0; s--) {
982
990
  const r = t[s];
983
991
  if (r.role === "assistant")
984
- for (let a = r.content.length - 1; a >= 0; a--) {
985
- const o = r.content[a], c = this.pluginRegistry.getRenderersByType(o.type);
992
+ for (let i = r.content.length - 1; i >= 0; i--) {
993
+ const o = r.content[i], c = this.pluginRegistry.getRenderersByType(o.type);
986
994
  if (c.length > 0 && ((e = c[0].capabilities) != null && e.supportsFocus)) {
987
- this._contentFocusRuntime.isActive && this._contentFocusRuntime.focusedMessageId === r.id && this._contentFocusRuntime.focusedContentIndex === a || this._contentFocusRuntime.focus(o, r, a, "detail");
995
+ this._contentFocusRuntime.isActive && this._contentFocusRuntime.focusedMessageId === r.id && this._contentFocusRuntime.focusedContentIndex === i || this._contentFocusRuntime.focus(o, r, i, "detail");
988
996
  return;
989
997
  }
990
998
  }
@@ -1001,7 +1009,7 @@ var A, D;
1001
1009
  function rt() {
1002
1010
  if (D) return A;
1003
1011
  D = 1;
1004
- var i = Object.getOwnPropertySymbols, n = Object.prototype.hasOwnProperty, t = Object.prototype.propertyIsEnumerable;
1012
+ var a = Object.getOwnPropertySymbols, n = Object.prototype.hasOwnProperty, t = Object.prototype.propertyIsEnumerable;
1005
1013
  function e(r) {
1006
1014
  if (r == null)
1007
1015
  throw new TypeError("Object.assign cannot be called with null or undefined");
@@ -1014,10 +1022,10 @@ function rt() {
1014
1022
  var r = new String("abc");
1015
1023
  if (r[5] = "de", Object.getOwnPropertyNames(r)[0] === "5")
1016
1024
  return !1;
1017
- for (var a = {}, o = 0; o < 10; o++)
1018
- a["_" + String.fromCharCode(o)] = o;
1019
- var c = Object.getOwnPropertyNames(a).map(function(l) {
1020
- return a[l];
1025
+ for (var i = {}, o = 0; o < 10; o++)
1026
+ i["_" + String.fromCharCode(o)] = o;
1027
+ var c = Object.getOwnPropertyNames(i).map(function(l) {
1028
+ return i[l];
1021
1029
  });
1022
1030
  if (c.join("") !== "0123456789")
1023
1031
  return !1;
@@ -1029,13 +1037,13 @@ function rt() {
1029
1037
  return !1;
1030
1038
  }
1031
1039
  }
1032
- return A = s() ? Object.assign : function(r, a) {
1040
+ return A = s() ? Object.assign : function(r, i) {
1033
1041
  for (var o, c = e(r), d, l = 1; l < arguments.length; l++) {
1034
1042
  o = Object(arguments[l]);
1035
1043
  for (var h in o)
1036
1044
  n.call(o, h) && (c[h] = o[h]);
1037
- if (i) {
1038
- d = i(o);
1045
+ if (a) {
1046
+ d = a(o);
1039
1047
  for (var g = 0; g < d.length; g++)
1040
1048
  t.call(o, d[g]) && (c[d[g]] = o[d[g]]);
1041
1049
  }
@@ -1055,20 +1063,20 @@ var j;
1055
1063
  function nt() {
1056
1064
  if (j) return x;
1057
1065
  j = 1, rt();
1058
- var i = U, n = 60103;
1066
+ var a = U, n = 60103;
1059
1067
  if (x.Fragment = 60107, typeof Symbol == "function" && Symbol.for) {
1060
1068
  var t = Symbol.for;
1061
1069
  n = t("react.element"), x.Fragment = t("react.fragment");
1062
1070
  }
1063
- var e = i.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, s = Object.prototype.hasOwnProperty, r = { key: !0, ref: !0, __self: !0, __source: !0 };
1064
- function a(o, c, d) {
1071
+ var e = a.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, s = Object.prototype.hasOwnProperty, r = { key: !0, ref: !0, __self: !0, __source: !0 };
1072
+ function i(o, c, d) {
1065
1073
  var l, h = {}, g = null, p = null;
1066
1074
  d !== void 0 && (g = "" + d), c.key !== void 0 && (g = "" + c.key), c.ref !== void 0 && (p = c.ref);
1067
1075
  for (l in c) s.call(c, l) && !r.hasOwnProperty(l) && (h[l] = c[l]);
1068
1076
  if (o && o.defaultProps) for (l in c = o.defaultProps, c) h[l] === void 0 && (h[l] = c[l]);
1069
1077
  return { $$typeof: n, type: o, key: g, ref: p, props: h, _owner: e.current };
1070
1078
  }
1071
- return x.jsx = a, x.jsxs = a, x;
1079
+ return x.jsx = i, x.jsxs = i, x;
1072
1080
  }
1073
1081
  var O;
1074
1082
  function it() {
@@ -1076,42 +1084,42 @@ function it() {
1076
1084
  }
1077
1085
  var S = it();
1078
1086
  const W = B(null);
1079
- function bt({ runtime: i, children: n }) {
1080
- return /* @__PURE__ */ S.jsx(W.Provider, { value: i, children: n });
1087
+ function mt({ runtime: a, children: n }) {
1088
+ return /* @__PURE__ */ S.jsx(W.Provider, { value: a, children: n });
1081
1089
  }
1082
1090
  function at() {
1083
- const i = q(W);
1084
- if (!i)
1091
+ const a = q(W);
1092
+ if (!a)
1085
1093
  throw new Error("useAssistantRuntimeContext must be used within AssistantRuntimeProvider");
1086
- return i;
1094
+ return a;
1087
1095
  }
1088
1096
  function f() {
1089
1097
  return at();
1090
1098
  }
1091
1099
  function _t() {
1092
- const i = f();
1100
+ const a = f();
1093
1101
  return {
1094
- switchToThread: (n) => i.threads.switchToThread(n),
1095
- switchToNewThread: () => i.threads.switchToNewThread(),
1096
- loadThreads: (n) => i.threads.loadThreads(n),
1102
+ switchToThread: (n) => a.threads.switchToThread(n),
1103
+ switchToNewThread: () => a.threads.switchToNewThread(),
1104
+ loadThreads: (n) => a.threads.loadThreads(n),
1097
1105
  renameThread: (n, t) => {
1098
1106
  var e, s;
1099
- return (s = (e = i.threads).renameThread) == null ? void 0 : s.call(e, n, t);
1107
+ return (s = (e = a.threads).renameThread) == null ? void 0 : s.call(e, n, t);
1100
1108
  },
1101
1109
  deleteThread: (n) => {
1102
1110
  var t, e;
1103
- return (e = (t = i.threads).deleteThread) == null ? void 0 : e.call(t, n);
1111
+ return (e = (t = a.threads).deleteThread) == null ? void 0 : e.call(t, n);
1104
1112
  }
1105
1113
  };
1106
1114
  }
1107
1115
  function xt() {
1108
- const i = f(), [n, t] = m(i.threads.getState());
1109
- return w(() => i.threads.subscribe(() => {
1110
- t(i.threads.getState());
1111
- }), [i]), n;
1116
+ const a = f(), [n, t] = b(a.threads.getState());
1117
+ return w(() => a.threads.subscribe(() => {
1118
+ t(a.threads.getState());
1119
+ }), [a]), n;
1112
1120
  }
1113
1121
  function ot() {
1114
- const n = f().threads.getMainThread(), [, t] = m({});
1122
+ const n = f().threads.getMainThread(), [, t] = b({});
1115
1123
  return w(() => n.subscribe(() => {
1116
1124
  t({});
1117
1125
  }), [n]), n;
@@ -1130,26 +1138,26 @@ var L;
1130
1138
  function ct() {
1131
1139
  if (L) return P;
1132
1140
  L = 1;
1133
- var i = U;
1141
+ var a = U;
1134
1142
  function n(h, g) {
1135
1143
  return h === g && (h !== 0 || 1 / h === 1 / g) || h !== h && g !== g;
1136
1144
  }
1137
- var t = typeof Object.is == "function" ? Object.is : n, e = i.useState, s = i.useEffect, r = i.useLayoutEffect, a = i.useDebugValue;
1145
+ var t = typeof Object.is == "function" ? Object.is : n, e = a.useState, s = a.useEffect, r = a.useLayoutEffect, i = a.useDebugValue;
1138
1146
  function o(h, g) {
1139
- var p = g(), _ = e({ inst: { value: p, getSnapshot: g } }), y = _[0].inst, T = _[1];
1147
+ var p = g(), _ = e({ inst: { value: p, getSnapshot: g } }), y = _[0].inst, I = _[1];
1140
1148
  return r(
1141
1149
  function() {
1142
- y.value = p, y.getSnapshot = g, c(y) && T({ inst: y });
1150
+ y.value = p, y.getSnapshot = g, c(y) && I({ inst: y });
1143
1151
  },
1144
1152
  [h, p, g]
1145
1153
  ), s(
1146
1154
  function() {
1147
- return c(y) && T({ inst: y }), h(function() {
1148
- c(y) && T({ inst: y });
1155
+ return c(y) && I({ inst: y }), h(function() {
1156
+ c(y) && I({ inst: y });
1149
1157
  });
1150
1158
  },
1151
1159
  [h]
1152
- ), a(p), p;
1160
+ ), i(p), p;
1153
1161
  }
1154
1162
  function c(h) {
1155
1163
  var g = h.getSnapshot;
@@ -1165,7 +1173,7 @@ function ct() {
1165
1173
  return g();
1166
1174
  }
1167
1175
  var l = typeof window > "u" || typeof window.document > "u" || typeof window.document.createElement > "u" ? d : o;
1168
- return P.useSyncExternalStore = i.useSyncExternalStore !== void 0 ? i.useSyncExternalStore : l, P;
1176
+ return P.useSyncExternalStore = a.useSyncExternalStore !== void 0 ? a.useSyncExternalStore : l, P;
1169
1177
  }
1170
1178
  var k;
1171
1179
  function ut() {
@@ -1173,27 +1181,27 @@ function ut() {
1173
1181
  }
1174
1182
  var ht = ut();
1175
1183
  function St() {
1176
- const i = f();
1184
+ const a = f();
1177
1185
  return ht.useSyncExternalStore(
1178
- (n) => i.subscribe(() => {
1186
+ (n) => a.subscribe(() => {
1179
1187
  n();
1180
1188
  }),
1181
- () => i.thread.messages,
1182
- () => i.thread.messages
1189
+ () => a.thread.messages,
1190
+ () => a.thread.messages
1183
1191
  );
1184
1192
  }
1185
1193
  function wt() {
1186
- const i = ot(), [n, t] = m(""), [e, s] = m(!1);
1194
+ const a = ot(), [n, t] = b(""), [e, s] = b(!1);
1187
1195
  return {
1188
1196
  text: n,
1189
1197
  setText: t,
1190
1198
  isSubmitting: e,
1191
- send: async (a) => {
1192
- if (a == null || a.preventDefault(), !n.trim() || e) return;
1199
+ send: async (i) => {
1200
+ if (i == null || i.preventDefault(), !n.trim() || e) return;
1193
1201
  const o = n;
1194
1202
  t(""), s(!0);
1195
1203
  try {
1196
- await i.send(o);
1204
+ await a.send(o);
1197
1205
  } catch (c) {
1198
1206
  console.error("Failed to send message:", c), t(o);
1199
1207
  } finally {
@@ -1201,12 +1209,12 @@ function wt() {
1201
1209
  }
1202
1210
  },
1203
1211
  clear: () => t(""),
1204
- append: (a) => t((o) => o + a)
1212
+ append: (i) => t((o) => o + i)
1205
1213
  };
1206
1214
  }
1207
- function $(i, n) {
1208
- var r, a, o, c;
1209
- const e = f().pluginRegistry.getBestRendererForType(i);
1215
+ function $(a, n) {
1216
+ var r, i, o, c;
1217
+ const e = f().pluginRegistry.getBestRendererForType(a);
1210
1218
  if (!e)
1211
1219
  return {
1212
1220
  component: null,
@@ -1219,50 +1227,57 @@ function $(i, n) {
1219
1227
  return {
1220
1228
  component: e.component,
1221
1229
  auxiliaryComponent: s,
1222
- supportsFocus: ((a = e.capabilities) == null ? void 0 : a.supportsFocus) ?? !1,
1230
+ supportsFocus: ((i = e.capabilities) == null ? void 0 : i.supportsFocus) ?? !1,
1223
1231
  supportsPreview: ((o = e.capabilities) == null ? void 0 : o.supportsPreview) ?? !1,
1224
1232
  supportsFullscreen: ((c = e.capabilities) == null ? void 0 : c.supportsFullscreen) ?? !1
1225
1233
  };
1226
1234
  }
1227
1235
  function Ct() {
1228
- const i = f(), [n, t] = m(i.contentFocus.state);
1229
- return w(() => i.contentFocus.subscribe(() => {
1230
- t(i.contentFocus.state);
1231
- }), [i]), {
1236
+ const a = f(), [n, t] = b(a.contentFocus.state);
1237
+ return w(() => a.contentFocus.subscribe(() => {
1238
+ t(a.contentFocus.state);
1239
+ }), [a]), {
1232
1240
  ...n,
1233
- focus: (e, s, r, a) => i.contentFocus.focus(e, s, r, a),
1234
- blur: () => i.contentFocus.blur(),
1235
- toggle: (e, s, r, a) => i.contentFocus.toggle(e, s, r, a),
1236
- switchContext: (e) => i.contentFocus.switchContext(e),
1237
- focusNext: () => i.contentFocus.focusNext(i.thread.messages),
1238
- focusPrevious: () => i.contentFocus.focusPrevious(i.thread.messages)
1241
+ focus: (e, s, r, i) => a.contentFocus.focus(e, s, r, i),
1242
+ blur: () => a.contentFocus.blur(),
1243
+ toggle: (e, s, r, i) => a.contentFocus.toggle(e, s, r, i),
1244
+ switchContext: (e) => a.contentFocus.switchContext(e),
1245
+ focusNext: () => a.contentFocus.focusNext(a.thread.messages),
1246
+ focusPrevious: () => a.contentFocus.focusPrevious(a.thread.messages)
1239
1247
  };
1240
1248
  }
1241
- function dt(i) {
1249
+ function dt(a) {
1242
1250
  const n = f();
1243
- w(() => (i.execute && n.capabilityRegistry.registerHandler(i.name, { execute: i.execute }), i.render && n.capabilityRegistry.registerRenderer(i.name, {
1244
- component: i.render
1245
- }), () => {
1246
- n.capabilityRegistry.unregister(i.name);
1247
- }), [i.name, n]);
1251
+ w(() => {
1252
+ const t = a.priority ?? 0;
1253
+ return a.execute && n.capabilityRegistry.registerHandler(a.name, { execute: a.execute }, t), a.render && n.capabilityRegistry.registerRenderer(
1254
+ a.name,
1255
+ {
1256
+ component: a.render
1257
+ },
1258
+ t
1259
+ ), () => {
1260
+ n.capabilityRegistry.unregister(a.name);
1261
+ };
1262
+ }, [a.name, n]);
1248
1263
  }
1249
- function lt(i) {
1250
- const n = f(), [t, e] = m(
1251
- () => n.capabilityExecutionManager.getExecution(i)
1264
+ function lt(a) {
1265
+ const n = f(), [t, e] = b(
1266
+ () => n.capabilityExecutionManager.getExecution(a)
1252
1267
  ), [, s] = z((r) => r + 1, 0);
1253
1268
  return w(() => {
1254
- const r = n.capabilityExecutionManager.getExecution(i);
1269
+ const r = n.capabilityExecutionManager.getExecution(a);
1255
1270
  return e(r), n.capabilityExecutionManager.subscribe((o) => {
1256
- if (o === i) {
1257
- const c = n.capabilityExecutionManager.getExecution(i);
1271
+ if (o === a) {
1272
+ const c = n.capabilityExecutionManager.getExecution(a);
1258
1273
  e(c), s();
1259
1274
  }
1260
1275
  });
1261
- }, [i, n]), t;
1276
+ }, [a, n]), t;
1262
1277
  }
1263
1278
  const Q = B(void 0);
1264
- function Tt({ children: i }) {
1265
- const [n, t] = m({}), e = C((c, d) => {
1279
+ function It({ children: a }) {
1280
+ const [n, t] = b({}), e = C((c, d) => {
1266
1281
  t((l) => {
1267
1282
  if (d === null) {
1268
1283
  const { [c]: h, ...g } = l;
@@ -1290,7 +1305,7 @@ function Tt({ children: i }) {
1290
1305
  return { ...c, ...l };
1291
1306
  },
1292
1307
  {}
1293
- ), [n]), a = C(() => {
1308
+ ), [n]), i = C(() => {
1294
1309
  t({});
1295
1310
  }, []), o = V(
1296
1311
  () => ({
@@ -1298,67 +1313,67 @@ function Tt({ children: i }) {
1298
1313
  setContext: e,
1299
1314
  removeContext: s,
1300
1315
  getContextData: r,
1301
- clearContexts: a
1316
+ clearContexts: i
1302
1317
  }),
1303
- [n, e, s, r, a]
1318
+ [n, e, s, r, i]
1304
1319
  );
1305
- return /* @__PURE__ */ S.jsx(Q.Provider, { value: o, children: i });
1320
+ return /* @__PURE__ */ S.jsx(Q.Provider, { value: o, children: a });
1306
1321
  }
1307
1322
  function gt() {
1308
- const i = q(Q);
1309
- if (!i)
1323
+ const a = q(Q);
1324
+ if (!a)
1310
1325
  throw new Error("useChatContext must be used within a ChatContextProvider");
1311
- return i;
1326
+ return a;
1312
1327
  }
1313
- function It(i) {
1314
- const { setContext: n, removeContext: t } = gt(), { id: e = "currentPage", ...s } = i;
1328
+ function Tt(a) {
1329
+ const { setContext: n, removeContext: t } = gt(), { id: e = "currentPage", ...s } = a;
1315
1330
  w(() => (n(e, s), () => {
1316
1331
  t(e);
1317
1332
  }), [e, s.displayName, JSON.stringify(s.data), s.priority, s.icon]);
1318
1333
  }
1319
- function pt({ message: i, content: n }) {
1334
+ function pt({ message: a, content: n }) {
1320
1335
  const t = f(), e = n, s = lt(e.capabilityId), r = t.capabilityRegistry.getRenderer(e.capabilityName);
1321
1336
  if (!r || !s)
1322
1337
  return null;
1323
- const a = r.component;
1338
+ const i = r.component;
1324
1339
  return /* @__PURE__ */ S.jsx(
1325
- a,
1340
+ i,
1326
1341
  {
1327
1342
  capabilityName: s.name,
1328
1343
  capabilityId: s.id,
1329
1344
  args: s.args,
1330
1345
  result: s.result,
1331
1346
  status: s.status,
1332
- message: i
1347
+ message: a
1333
1348
  }
1334
1349
  );
1335
1350
  }
1336
- function vt({ message: i, content: n }) {
1351
+ function vt({ message: a, content: n }) {
1337
1352
  const { component: t } = $(n.type);
1338
1353
  if (n.type === "capability")
1339
- return /* @__PURE__ */ S.jsx(pt, { message: i, content: n });
1354
+ return /* @__PURE__ */ S.jsx(pt, { message: a, content: n });
1340
1355
  if (!t)
1341
1356
  return null;
1342
1357
  const e = t;
1343
- return /* @__PURE__ */ S.jsx(e, { content: n, message: i });
1358
+ return /* @__PURE__ */ S.jsx(e, { content: n, message: a });
1344
1359
  }
1345
1360
  function Rt({
1346
- message: i,
1361
+ message: a,
1347
1362
  content: n,
1348
1363
  context: t,
1349
1364
  onClose: e,
1350
1365
  onNavigate: s,
1351
1366
  onSwitchContext: r
1352
1367
  }) {
1353
- const { auxiliaryComponent: a } = $(n.type, t);
1354
- if (!a)
1368
+ const { auxiliaryComponent: i } = $(n.type, t);
1369
+ if (!i)
1355
1370
  return null;
1356
- const o = a;
1371
+ const o = i;
1357
1372
  return /* @__PURE__ */ S.jsx(
1358
1373
  o,
1359
1374
  {
1360
1375
  content: n,
1361
- message: i,
1376
+ message: a,
1362
1377
  context: t,
1363
1378
  onClose: e,
1364
1379
  onNavigate: s,
@@ -1366,9 +1381,9 @@ function Rt({
1366
1381
  }
1367
1382
  );
1368
1383
  }
1369
- function Et(i) {
1370
- const n = () => (dt(i), null);
1371
- return n.displayName = `Capability(${i.name})`, n;
1384
+ function Et(a) {
1385
+ const n = () => (dt(a), null);
1386
+ return n.displayName = `Capability(${a.name})`, n;
1372
1387
  }
1373
1388
  class Mt {
1374
1389
  getAllowedEvents() {
@@ -1388,7 +1403,7 @@ class Mt {
1388
1403
  }
1389
1404
  async *parseSSEStream(n, t) {
1390
1405
  const e = n.getReader(), s = new TextDecoder();
1391
- let r = "", a = null;
1406
+ let r = "", i = null;
1392
1407
  try {
1393
1408
  for (; ; ) {
1394
1409
  const { done: o, value: c } = await e.read();
@@ -1400,12 +1415,12 @@ class Mt {
1400
1415
  for (const l of d) {
1401
1416
  const h = l.trim();
1402
1417
  if (!h) {
1403
- a = null;
1418
+ i = null;
1404
1419
  continue;
1405
1420
  }
1406
1421
  if (h !== ": ping") {
1407
1422
  if (h.startsWith("event:")) {
1408
- a = h.substring(6).trim();
1423
+ i = h.substring(6).trim();
1409
1424
  continue;
1410
1425
  }
1411
1426
  if (h.startsWith("data:")) {
@@ -1414,16 +1429,16 @@ class Mt {
1414
1429
  break;
1415
1430
  try {
1416
1431
  const p = JSON.parse(g);
1417
- if (a && this.shouldProcessEvent(a)) {
1432
+ if (i && this.shouldProcessEvent(i)) {
1418
1433
  const _ = this.convertEvent({
1419
- event: a,
1434
+ event: i,
1420
1435
  data: p
1421
1436
  });
1422
1437
  _ && (yield _);
1423
1438
  }
1424
1439
  } catch {
1425
1440
  }
1426
- a = null;
1441
+ i = null;
1427
1442
  }
1428
1443
  }
1429
1444
  }
@@ -1434,14 +1449,14 @@ class Mt {
1434
1449
  }
1435
1450
  }
1436
1451
  export {
1437
- mt as AssistantRuntime,
1438
- bt as AssistantRuntimeProvider,
1452
+ bt as AssistantRuntime,
1453
+ mt as AssistantRuntimeProvider,
1439
1454
  Rt as AuxiliaryRenderer,
1440
1455
  Mt as BaseSSEStreamAdapter,
1441
1456
  K as CapabilityExecutionManager,
1442
1457
  Y as CapabilityRegistry,
1443
1458
  pt as CapabilityRendererComp,
1444
- Tt as ChatContextProvider,
1459
+ It as ChatContextProvider,
1445
1460
  et as ComposerRuntime,
1446
1461
  vt as ContentRenderer,
1447
1462
  G as PluginRegistry,
@@ -1449,7 +1464,7 @@ export {
1449
1464
  st as ThreadListRuntime,
1450
1465
  R as ThreadRuntime,
1451
1466
  E as ThreadRuntimeCore,
1452
- I as generateMessageId,
1467
+ T as generateMessageId,
1453
1468
  Et as makeCapability,
1454
1469
  f as useAssistantRuntime,
1455
1470
  dt as useCapability,
@@ -1460,7 +1475,7 @@ export {
1460
1475
  $ as useContentRenderer,
1461
1476
  ot as useCurrentThread,
1462
1477
  St as useMessages,
1463
- It as usePageContext,
1478
+ Tt as usePageContext,
1464
1479
  _t as useThreadList,
1465
1480
  xt as useThreadListState
1466
1481
  };