@harnessio/ai-chat-core 0.0.13 → 0.0.14

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,23 +1,23 @@
1
1
  var J = Object.defineProperty;
2
- var z = (i, s, t) => s in i ? J(i, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[s] = t;
3
- var c = (i, s, t) => z(i, typeof s != "symbol" ? s + "" : s, t);
4
- import k, { createContext as q, useContext as Q, useState as b, useEffect as w, useReducer as W, useCallback as C, useMemo as V } from "react";
2
+ var W = (i, s, t) => s in i ? J(i, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[s] = t;
3
+ var u = (i, s, t) => W(i, typeof s != "symbol" ? s + "" : s, t);
4
+ import k, { createContext as q, useContext as U, 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
- c(this, "plugins", /* @__PURE__ */ new Map());
8
- c(this, "renderersByType", /* @__PURE__ */ new Map());
7
+ u(this, "plugins", /* @__PURE__ */ new Map());
8
+ u(this, "renderersByType", /* @__PURE__ */ new Map());
9
9
  }
10
10
  registerPlugin(s) {
11
11
  this.plugins.has(s.id), this.plugins.set(s.id, s), s.renderers.forEach((t) => {
12
12
  const e = this.renderersByType.get(t.type) || [];
13
- e.push(t), e.sort((n, r) => ((r == null ? void 0 : r.priority) ?? 0) - ((n == null ? void 0 : n.priority) ?? 0)), this.renderersByType.set(t.type, e);
13
+ e.push(t), e.sort((r, n) => ((n == null ? void 0 : n.priority) ?? 0) - ((r == null ? void 0 : r.priority) ?? 0)), this.renderersByType.set(t.type, e);
14
14
  });
15
15
  }
16
16
  unregisterPlugin(s) {
17
17
  const t = this.plugins.get(s);
18
18
  return t ? (t.renderers.forEach((e) => {
19
- const r = (this.renderersByType.get(e.type) || []).filter((a) => !t.renderers.includes(a));
20
- r.length === 0 ? this.renderersByType.delete(e.type) : this.renderersByType.set(e.type, r);
19
+ const n = (this.renderersByType.get(e.type) || []).filter((a) => !t.renderers.includes(a));
20
+ n.length === 0 ? this.renderersByType.delete(e.type) : this.renderersByType.set(e.type, n);
21
21
  }), this.plugins.delete(s)) : !1;
22
22
  }
23
23
  getPlugin(s) {
@@ -38,8 +38,8 @@ class G {
38
38
  }
39
39
  class Y {
40
40
  constructor() {
41
- c(this, "handlers", /* @__PURE__ */ new Map());
42
- c(this, "renderers", /* @__PURE__ */ new Map());
41
+ u(this, "handlers", /* @__PURE__ */ new Map());
42
+ u(this, "renderers", /* @__PURE__ */ new Map());
43
43
  }
44
44
  registerHandler(s, t) {
45
45
  this.handlers.set(s, t);
@@ -74,15 +74,15 @@ class Y {
74
74
  }
75
75
  class K {
76
76
  constructor(s) {
77
- c(this, "executions", /* @__PURE__ */ new Map());
78
- c(this, "executionQueue", []);
79
- c(this, "isProcessing", !1);
80
- c(this, "runningByName", /* @__PURE__ */ new Map());
81
- c(this, "subscribers", /* @__PURE__ */ new Set());
82
- c(this, "getHandler");
77
+ u(this, "executions", /* @__PURE__ */ new Map());
78
+ u(this, "executionQueue", []);
79
+ u(this, "isProcessing", !1);
80
+ u(this, "runningByName", /* @__PURE__ */ new Map());
81
+ u(this, "subscribers", /* @__PURE__ */ new Set());
82
+ u(this, "getHandler");
83
83
  this.getHandler = s;
84
84
  }
85
- async executeCapability(s, t, e, n, r = "queue") {
85
+ async executeCapability(s, t, e, r, n = "queue") {
86
86
  if (!this.getHandler(s)) {
87
87
  console.warn(`No handler registered for capability: ${s}`);
88
88
  return;
@@ -93,9 +93,9 @@ class K {
93
93
  args: e,
94
94
  status: { type: "queued" },
95
95
  timestamp: Date.now(),
96
- messageId: n
96
+ messageId: r
97
97
  };
98
- switch (this.executions.set(t, o), this.notifySubscribers(t), r) {
98
+ switch (this.executions.set(t, o), this.notifySubscribers(t), n) {
99
99
  case "queue":
100
100
  default:
101
101
  this.executionQueue.push(t);
@@ -111,20 +111,20 @@ class K {
111
111
  const e = this.getHandler(t.name);
112
112
  if (!e) continue;
113
113
  t.status = { type: "running" }, this.notifySubscribers(s);
114
- const n = this.runningByName.get(t.name) || [];
115
- n.push(s), this.runningByName.set(t.name, n);
114
+ const r = this.runningByName.get(t.name) || [];
115
+ r.push(s), this.runningByName.set(t.name, r);
116
116
  try {
117
- const r = await e.execute(t.args, {
117
+ const n = await e.execute(t.args, {
118
118
  messageId: t.messageId,
119
119
  capabilityId: s
120
120
  });
121
- t.status = { type: "complete", result: r }, t.result = r;
122
- } catch (r) {
123
- const a = r instanceof Error ? r.message : "Unknown error";
121
+ t.status = { type: "complete", result: n }, t.result = n;
122
+ } catch (n) {
123
+ const a = n instanceof Error ? n.message : "Unknown error";
124
124
  t.status = { type: "error", error: a }, t.error = a;
125
125
  } finally {
126
- const r = this.runningByName.get(t.name) || [], a = r.indexOf(s);
127
- a > -1 && r.splice(a, 1), r.length === 0 ? this.runningByName.delete(t.name) : this.runningByName.set(t.name, r), this.notifySubscribers(s);
126
+ const n = this.runningByName.get(t.name) || [], a = n.indexOf(s);
127
+ a > -1 && n.splice(a, 1), n.length === 0 ? this.runningByName.delete(t.name) : this.runningByName.set(t.name, n), this.notifySubscribers(s);
128
128
  }
129
129
  }
130
130
  this.isProcessing = !1;
@@ -148,7 +148,7 @@ class K {
148
148
  }
149
149
  class y {
150
150
  constructor() {
151
- c(this, "_subscriptions", /* @__PURE__ */ new Set());
151
+ u(this, "_subscriptions", /* @__PURE__ */ new Set());
152
152
  }
153
153
  subscribe(s) {
154
154
  return this._subscriptions.add(s), () => {
@@ -166,7 +166,7 @@ class y {
166
166
  class X extends y {
167
167
  constructor() {
168
168
  super(...arguments);
169
- c(this, "_state", {
169
+ u(this, "_state", {
170
170
  isActive: !1,
171
171
  context: null,
172
172
  focusedContent: null,
@@ -196,14 +196,14 @@ class X extends y {
196
196
  get focusedContentIndex() {
197
197
  return this._state.focusedContentIndex;
198
198
  }
199
- focus(t, e, n, r = "detail") {
199
+ focus(t, e, r, n = "detail") {
200
200
  this._state = {
201
201
  isActive: !0,
202
- context: r,
202
+ context: n,
203
203
  focusedContent: t,
204
204
  focusedMessage: e,
205
205
  focusedMessageId: e.id,
206
- focusedContentIndex: n
206
+ focusedContentIndex: r
207
207
  }, this.notifySubscribers();
208
208
  }
209
209
  blur() {
@@ -216,8 +216,8 @@ class X extends y {
216
216
  focusedContentIndex: null
217
217
  }, this.notifySubscribers();
218
218
  }
219
- toggle(t, e, n, r = "detail") {
220
- this._state.isActive && this._state.focusedMessageId === e.id && this._state.focusedContentIndex === n && this._state.context === r ? this.blur() : this.focus(t, e, n, r);
219
+ toggle(t, e, r, n = "detail") {
220
+ this._state.isActive && this._state.focusedMessageId === e.id && this._state.focusedContentIndex === r && this._state.context === n ? this.blur() : this.focus(t, e, r, n);
221
221
  }
222
222
  switchContext(t) {
223
223
  this._state.isActive && this._state.focusedContent && (this._state = {
@@ -229,10 +229,10 @@ class X extends y {
229
229
  if (!this._state.focusedMessageId || !t.length) return;
230
230
  const e = t.findIndex((a) => a.id === this._state.focusedMessageId);
231
231
  if (e === -1) return;
232
- const n = t[e], r = this._state.focusedContentIndex ?? 0;
233
- if (r + 1 < n.content.length) {
234
- const a = n.content[r + 1];
235
- this.focus(a, n, r + 1, this._state.context || "detail");
232
+ const r = t[e], n = this._state.focusedContentIndex ?? 0;
233
+ if (n + 1 < r.content.length) {
234
+ const a = r.content[n + 1];
235
+ this.focus(a, r, n + 1, this._state.context || "detail");
236
236
  return;
237
237
  }
238
238
  if (e + 1 < t.length) {
@@ -244,10 +244,10 @@ class X extends y {
244
244
  if (!this._state.focusedMessageId || !t.length) return;
245
245
  const e = t.findIndex((a) => a.id === this._state.focusedMessageId);
246
246
  if (e === -1) return;
247
- const n = t[e], r = this._state.focusedContentIndex ?? 0;
248
- if (r > 0) {
249
- const a = n.content[r - 1];
250
- this.focus(a, n, r - 1, this._state.context || "detail");
247
+ const r = t[e], n = this._state.focusedContentIndex ?? 0;
248
+ if (n > 0) {
249
+ const a = r.content[n - 1];
250
+ this.focus(a, r, n - 1, this._state.context || "detail");
251
251
  return;
252
252
  }
253
253
  if (e > 0) {
@@ -260,16 +260,16 @@ class X extends y {
260
260
  }
261
261
  }
262
262
  let Z = 0, tt = 0;
263
- function L() {
263
+ function F() {
264
264
  return `msg-${Date.now()}-${++Z}`;
265
265
  }
266
- function F() {
266
+ function j() {
267
267
  return `thread-${Date.now()}-${++tt}`;
268
268
  }
269
269
  class I extends y {
270
270
  constructor(t) {
271
271
  super();
272
- c(this, "_state");
272
+ u(this, "_state");
273
273
  this.config = t, this._state = t.state;
274
274
  }
275
275
  get state() {
@@ -297,8 +297,8 @@ class I extends y {
297
297
  class et extends y {
298
298
  constructor() {
299
299
  super(...arguments);
300
- c(this, "_text", "");
301
- c(this, "_isSubmitting", !1);
300
+ u(this, "_text", "");
301
+ u(this, "_isSubmitting", !1);
302
302
  }
303
303
  get text() {
304
304
  return this._text;
@@ -322,10 +322,10 @@ class et extends y {
322
322
  this._isSubmitting = t, this.notifySubscribers();
323
323
  }
324
324
  }
325
- class M extends y {
325
+ class v extends y {
326
326
  constructor(t) {
327
327
  super();
328
- c(this, "composer");
328
+ u(this, "composer");
329
329
  this._core = t, this.composer = new et(), this._core.subscribe(() => {
330
330
  this.notifySubscribers();
331
331
  });
@@ -395,17 +395,17 @@ class M extends y {
395
395
  return super.subscribe(t);
396
396
  }
397
397
  }
398
- class v extends y {
398
+ class R extends y {
399
399
  constructor(t) {
400
400
  super();
401
- c(this, "_messages", []);
402
- c(this, "_isRunning", !1);
403
- c(this, "_isDisabled", !1);
404
- c(this, "_abortController", null);
405
- c(this, "_conversationId");
406
- c(this, "_title");
401
+ u(this, "_messages", []);
402
+ u(this, "_isRunning", !1);
403
+ u(this, "_isDisabled", !1);
404
+ u(this, "_abortController", null);
405
+ u(this, "_conversationId");
406
+ u(this, "_title");
407
407
  // Track current part being accumulated
408
- c(this, "_currentPart", null);
408
+ u(this, "_currentPart", null);
409
409
  this.config = t, t.initialMessages && (this._messages = [...t.initialMessages]);
410
410
  }
411
411
  get messages() {
@@ -434,12 +434,12 @@ class v extends y {
434
434
  };
435
435
  }
436
436
  updateMessages(t) {
437
- var e, n;
438
- this._messages = t, (n = (e = this.config).onMessagesChange) == null || n.call(e, this._messages), this.notifySubscribers();
437
+ var e, r;
438
+ this._messages = t, (r = (e = this.config).onMessagesChange) == null || r.call(e, this._messages), this.notifySubscribers();
439
439
  }
440
440
  append(t) {
441
441
  const e = {
442
- id: t.id || L(),
442
+ id: t.id || F(),
443
443
  parentId: t.parentId,
444
444
  role: t.role,
445
445
  content: t.content,
@@ -453,31 +453,31 @@ class v extends y {
453
453
  if (this._isRunning)
454
454
  throw new Error("A run is already in progress");
455
455
  this.append(t), this._isRunning = !0, this._abortController = new AbortController(), this._currentPart = null;
456
- const e = L(), n = {
456
+ const e = F(), r = {
457
457
  id: e,
458
458
  role: "assistant",
459
459
  content: [],
460
460
  status: { type: "running" },
461
461
  timestamp: Date.now()
462
462
  };
463
- this.updateMessages([...this._messages, n]);
463
+ this.updateMessages([...this._messages, r]);
464
464
  try {
465
- const r = this.config.streamAdapter.stream({
465
+ const n = this.config.streamAdapter.stream({
466
466
  messages: this._messages,
467
467
  conversationId: this._conversationId,
468
468
  signal: this._abortController.signal
469
469
  });
470
- for await (const a of r) {
470
+ for await (const a of n) {
471
471
  if (this._abortController.signal.aborted)
472
472
  break;
473
473
  this.handleStreamEvent(e, a.event);
474
474
  }
475
475
  this.updateMessageStatus(e, { type: "complete" });
476
- } catch (r) {
477
- if (r instanceof Error && r.name === "AbortError")
476
+ } catch (n) {
477
+ if (n instanceof Error && n.name === "AbortError")
478
478
  this.completeStreamingContent(e), this.updateMessageStatus(e, { type: "cancelled" });
479
479
  else {
480
- const a = r instanceof Error ? r.message : "Unknown error";
480
+ const a = n instanceof Error ? n.message : "Unknown error";
481
481
  this.completeStreamingContent(e), this.updateMessageStatus(e, {
482
482
  type: "error",
483
483
  error: a
@@ -488,26 +488,26 @@ class v extends y {
488
488
  }
489
489
  }
490
490
  handleStreamEvent(t, e) {
491
- const n = this._messages.findIndex((o) => o.id === t);
492
- if (n === -1) return;
493
- const r = this._messages[n];
491
+ const r = this._messages.findIndex((o) => o.id === t);
492
+ if (r === -1) return;
493
+ const n = this._messages[r];
494
494
  if (e.type === "part-start")
495
- this.handlePartStart(r, e);
495
+ this.handlePartStart(n, e);
496
496
  else if (e.type === "text-delta" || e.type === "assistant_thought")
497
- this.handleTextDelta(r, e);
497
+ this.handleTextDelta(n, e);
498
498
  else if (e.type === "part-finish")
499
499
  this.handlePartFinish();
500
500
  else if (e.type === "metadata") {
501
501
  const o = e;
502
- r.metadata = {
503
- ...r.metadata,
502
+ n.metadata = {
503
+ ...n.metadata,
504
504
  conversationId: o.conversationId,
505
505
  interactionId: o.interactionId
506
506
  }, o.conversationId && !this._conversationId && (this._conversationId = o.conversationId), o.title && !this._title && (this._title = o.title);
507
507
  } else if (e.type === "capability_execution") {
508
508
  const o = e;
509
- r.content = [
510
- ...r.content,
509
+ n.content = [
510
+ ...n.content,
511
511
  {
512
512
  type: "capability",
513
513
  capabilityId: o.capabilityId,
@@ -523,8 +523,8 @@ class v extends y {
523
523
  );
524
524
  } else if (e.type === "error") {
525
525
  const o = e;
526
- r.content = [
527
- ...r.content,
526
+ n.content = [
527
+ ...n.content,
528
528
  {
529
529
  type: "error",
530
530
  data: o.error
@@ -532,8 +532,8 @@ class v extends y {
532
532
  ];
533
533
  } else {
534
534
  const o = e;
535
- r.content = [
536
- ...r.content,
535
+ n.content = [
536
+ ...n.content,
537
537
  {
538
538
  type: o.type,
539
539
  data: o.data,
@@ -542,18 +542,18 @@ class v extends y {
542
542
  ];
543
543
  }
544
544
  const a = [
545
- ...this._messages.slice(0, n),
546
- { ...r, timestamp: Date.now() },
547
- ...this._messages.slice(n + 1)
545
+ ...this._messages.slice(0, r),
546
+ { ...n, timestamp: Date.now() },
547
+ ...this._messages.slice(r + 1)
548
548
  ];
549
549
  this.updateMessages(a);
550
550
  }
551
551
  handlePartStart(t, e) {
552
- const n = t.content.length;
553
- let r;
552
+ const r = t.content.length;
553
+ let n;
554
554
  switch (e.part.type) {
555
555
  case "assistant_thought":
556
- r = {
556
+ n = {
557
557
  type: e.part.type,
558
558
  data: [],
559
559
  parentId: e.part.parentId,
@@ -561,7 +561,7 @@ class v extends y {
561
561
  };
562
562
  break;
563
563
  case "text":
564
- r = {
564
+ n = {
565
565
  type: e.part.type,
566
566
  data: "",
567
567
  parentId: e.part.parentId,
@@ -569,15 +569,15 @@ class v extends y {
569
569
  };
570
570
  break;
571
571
  default:
572
- r = {
572
+ n = {
573
573
  type: e.part.type,
574
574
  parentId: e.part.parentId,
575
575
  status: { type: "streaming" }
576
576
  };
577
577
  }
578
- t.content = [...t.content, r], this._currentPart = {
578
+ t.content = [...t.content, n], this._currentPart = {
579
579
  messageId: t.id,
580
- contentIndex: n,
580
+ contentIndex: r,
581
581
  type: e.part.type,
582
582
  parentId: e.part.parentId
583
583
  };
@@ -587,8 +587,8 @@ class v extends y {
587
587
  console.warn("Received text-delta without part-start");
588
588
  return;
589
589
  }
590
- const n = t.content[this._currentPart.contentIndex];
591
- n.type === "assistant_thought" ? (Array.isArray(n.data) || (n.data = []), e.delta.trim() && n.data.push(e.delta.trim())) : n.data = (n.data || "") + e.delta;
590
+ const r = t.content[this._currentPart.contentIndex];
591
+ r.type === "assistant_thought" ? (Array.isArray(r.data) || (r.data = []), e.delta.trim() && r.data.push(e.delta.trim())) : r.data = (r.data || "") + e.delta;
592
592
  }
593
593
  handlePartFinish() {
594
594
  if (!this._currentPart) {
@@ -597,46 +597,46 @@ class v extends y {
597
597
  }
598
598
  const t = this._messages.findIndex((e) => e.id === this._currentPart.messageId);
599
599
  if (t !== -1) {
600
- const e = this._messages[t], n = e.content[this._currentPart.contentIndex];
601
- if (n) {
602
- n.status = { type: "complete" };
603
- const r = [
600
+ const e = this._messages[t], r = e.content[this._currentPart.contentIndex];
601
+ if (r) {
602
+ r.status = { type: "complete" };
603
+ const n = [
604
604
  ...this._messages.slice(0, t),
605
605
  { ...e, timestamp: Date.now() },
606
606
  ...this._messages.slice(t + 1)
607
607
  ];
608
- this.updateMessages(r);
608
+ this.updateMessages(n);
609
609
  }
610
610
  }
611
611
  this._currentPart = null;
612
612
  }
613
613
  updateMessageStatus(t, e) {
614
- const n = this._messages.findIndex((a) => a.id === t);
615
- if (n === -1) return;
616
- const r = [
617
- ...this._messages.slice(0, n),
614
+ const r = this._messages.findIndex((a) => a.id === t);
615
+ if (r === -1) return;
616
+ const n = [
617
+ ...this._messages.slice(0, r),
618
618
  {
619
- ...this._messages[n],
619
+ ...this._messages[r],
620
620
  status: e
621
621
  },
622
- ...this._messages.slice(n + 1)
622
+ ...this._messages.slice(r + 1)
623
623
  ];
624
- this.updateMessages(r);
624
+ this.updateMessages(n);
625
625
  }
626
626
  completeStreamingContent(t) {
627
- const e = this._messages.findIndex((u) => u.id === t);
627
+ const e = this._messages.findIndex((c) => c.id === t);
628
628
  if (e === -1) return;
629
- const n = this._messages[e];
630
- if (!n.content.some((u) => {
631
- var d;
632
- return ((d = u.status) == null ? void 0 : d.type) === "streaming";
629
+ const r = this._messages[e];
630
+ if (!r.content.some((c) => {
631
+ var l;
632
+ return ((l = c.status) == null ? void 0 : l.type) === "streaming";
633
633
  })) return;
634
- const a = n.content.map((u) => {
635
- var d;
636
- return ((d = u.status) == null ? void 0 : d.type) === "streaming" ? { ...u, status: { type: "complete" } } : u;
634
+ const a = r.content.map((c) => {
635
+ var l;
636
+ return ((l = c.status) == null ? void 0 : l.type) === "streaming" ? { ...c, status: { type: "complete" } } : c;
637
637
  }), o = [
638
638
  ...this._messages.slice(0, e),
639
- { ...n, content: a, timestamp: Date.now() },
639
+ { ...r, content: a, timestamp: Date.now() },
640
640
  ...this._messages.slice(e + 1)
641
641
  ];
642
642
  this.updateMessages(o);
@@ -660,26 +660,21 @@ class v extends y {
660
660
  class st extends y {
661
661
  constructor(t) {
662
662
  super();
663
- c(this, "_mainThreadId");
664
- c(this, "_threads", /* @__PURE__ */ new Map());
665
- c(this, "_threadItems", /* @__PURE__ */ new Map());
666
- c(this, "_threadStates", /* @__PURE__ */ new Map());
667
- c(this, "_isLoading", !1);
668
- c(this, "_isLoadingMore", !1);
669
- c(this, "_currentPage", 0);
670
- c(this, "_totalPages", 0);
671
- c(this, "_totalCount", 0);
672
- c(this, "_hasMore", !0);
673
- c(this, "_searchQuery");
674
- c(this, "_abortController", null);
675
- c(this, "main");
676
- this.config = t, this._mainThreadId = F();
677
- const e = new v({
663
+ u(this, "_mainThreadId");
664
+ u(this, "_threads", /* @__PURE__ */ new Map());
665
+ u(this, "_threadItems", /* @__PURE__ */ new Map());
666
+ u(this, "_threadStates", /* @__PURE__ */ new Map());
667
+ u(this, "_isLoading", !1);
668
+ u(this, "_searchQuery");
669
+ u(this, "_abortController", null);
670
+ u(this, "main");
671
+ this.config = t, this._mainThreadId = j();
672
+ const e = new R({
678
673
  streamAdapter: t.streamAdapter,
679
674
  capabilityExecutionManager: t.capabilityExecutionManager
680
675
  });
681
- this.main = new M(e), this._threads.set(this._mainThreadId, this.main);
682
- const n = {
676
+ this.main = new v(e), this._threads.set(this._mainThreadId, this.main);
677
+ const r = {
683
678
  id: this._mainThreadId,
684
679
  title: "New Chat",
685
680
  status: { type: "regular" },
@@ -687,21 +682,18 @@ class st extends y {
687
682
  createdAt: Date.now(),
688
683
  updatedAt: Date.now()
689
684
  };
690
- this._threadStates.set(this._mainThreadId, n);
691
- const r = new I({
692
- state: n,
685
+ this._threadStates.set(this._mainThreadId, r);
686
+ const n = new I({
687
+ state: r,
693
688
  onSwitchTo: this.switchToThread.bind(this),
694
689
  onRename: this.renameThread.bind(this),
695
690
  onDelete: this.deleteThread.bind(this)
696
691
  });
697
- this._threadItems.set(this._mainThreadId, r);
692
+ this._threadItems.set(this._mainThreadId, n);
698
693
  }
699
694
  get isLoading() {
700
695
  return this._isLoading;
701
696
  }
702
- get isLoadingMore() {
703
- return this._isLoadingMore;
704
- }
705
697
  /**
706
698
  * Get the currently active main thread
707
699
  */
@@ -711,20 +703,13 @@ class st extends y {
711
703
  }
712
704
  getState() {
713
705
  const t = [], e = {};
714
- for (const [n, r] of this._threadStates)
715
- e[n] = r, r.status.type === "regular" && t.push(n);
706
+ for (const [r, n] of this._threadStates)
707
+ e[r] = n, n.status.type === "regular" && t.push(r);
716
708
  return {
717
709
  mainThreadId: this._mainThreadId,
718
710
  threads: t,
719
711
  isLoading: this._isLoading,
720
- isLoadingMore: this._isLoadingMore,
721
712
  threadItems: e,
722
- pagination: {
723
- currentPage: this._currentPage,
724
- totalPages: this._totalPages,
725
- totalCount: this._totalCount,
726
- hasMore: this._hasMore
727
- },
728
713
  searchQuery: this._searchQuery
729
714
  };
730
715
  }
@@ -733,16 +718,16 @@ class st extends y {
733
718
  const e = this._threads.get(t);
734
719
  if (!e)
735
720
  throw new Error(`Thread ${t} not found`);
736
- const n = this._threadStates.get(this._mainThreadId);
737
- n && (n.isMain = !1, this._threadStates.set(this._mainThreadId, n), (a = this._threadItems.get(this._mainThreadId)) == null || a.updateState(n)), this._mainThreadId = t;
738
- const r = this._threadStates.get(t);
739
- 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)) {
721
+ const r = this._threadStates.get(this._mainThreadId);
722
+ r && (r.isMain = !1, this._threadStates.set(this._mainThreadId, r), (a = this._threadItems.get(this._mainThreadId)) == null || a.updateState(r)), this._mainThreadId = t;
723
+ const n = this._threadStates.get(t);
724
+ if (n && (n.isMain = !0, this._threadStates.set(t, n), (o = this._threadItems.get(t)) == null || o.updateState(n), e.setConversationId(n.conversationId), e.setTitle(n.title)), this.config.threadListAdapter && (n != null && n.conversationId)) {
740
725
  this._isLoading = !0, this.notifySubscribers();
741
726
  try {
742
- const u = await this.config.threadListAdapter.loadThread(t);
743
- e.reset(u);
744
- } catch (u) {
745
- console.error("Failed to load thread:", u);
727
+ const c = await this.config.threadListAdapter.loadThread(t);
728
+ e.reset(c);
729
+ } catch (c) {
730
+ console.error("Failed to load thread:", c);
746
731
  } finally {
747
732
  this._isLoading = !1;
748
733
  }
@@ -750,12 +735,12 @@ class st extends y {
750
735
  this.notifySubscribers();
751
736
  }
752
737
  async switchToNewThread() {
753
- const t = F(), e = new v({
738
+ const t = j(), e = new R({
754
739
  streamAdapter: this.config.streamAdapter,
755
740
  capabilityExecutionManager: this.config.capabilityExecutionManager
756
- }), n = new M(e);
757
- this._threads.set(t, n);
758
- const r = {
741
+ }), r = new v(e);
742
+ this._threads.set(t, r);
743
+ const n = {
759
744
  id: t,
760
745
  title: "New Chat",
761
746
  status: { type: "regular" },
@@ -763,85 +748,70 @@ class st extends y {
763
748
  createdAt: Date.now(),
764
749
  updatedAt: Date.now()
765
750
  };
766
- this._threadStates.set(t, r);
751
+ this._threadStates.set(t, n);
767
752
  const a = new I({
768
- state: r,
753
+ state: n,
769
754
  onSwitchTo: this.switchToThread.bind(this),
770
755
  onRename: this.renameThread.bind(this),
771
756
  onDelete: this.deleteThread.bind(this)
772
757
  });
773
- if (this._threadItems.set(t, a), n.subscribe(() => {
774
- this.syncThreadStateFromRuntime(t, n), this.notifySubscribers();
758
+ if (this._threadItems.set(t, a), r.subscribe(() => {
759
+ this.syncThreadStateFromRuntime(t, r), this.notifySubscribers();
775
760
  }), this.config.threadListAdapter)
776
761
  try {
777
762
  const o = await this.config.threadListAdapter.createThread();
778
- r.conversationId = o.conversationId, this._threadStates.set(t, r), a.updateState(r);
763
+ n.conversationId = o.conversationId, this._threadStates.set(t, n), a.updateState(n);
779
764
  } catch (o) {
780
765
  console.error("Failed to create thread:", o);
781
766
  }
782
767
  await this.switchToThread(t);
783
768
  }
784
- async loadThreads(t, e = !1) {
785
- if (!this.config.threadListAdapter) {
786
- console.warn("No threadListAdapter configured");
787
- return;
788
- }
789
- this._abortController && this._abortController.abort(), this._abortController = new AbortController();
790
- const n = t !== this._searchQuery, r = e || n;
791
- if (r && (this._currentPage = 0, this._searchQuery = t, this._hasMore = !0, this._threadStates.clear(), this._threads.clear(), this._threadItems.clear()), !(!r && !this._hasMore)) {
792
- r ? this._isLoading = !0 : this._isLoadingMore = !0, this.notifySubscribers();
793
- try {
794
- const a = await this.config.threadListAdapter.loadThreads({
795
- query: this._searchQuery,
796
- page: this._currentPage,
797
- size: 50
769
+ async loadThreads(t) {
770
+ if (!this.config.threadListAdapter)
771
+ return console.warn("No threadListAdapter configured"), [];
772
+ if (this._isLoading)
773
+ return [];
774
+ this._abortController && this._abortController.abort(), this._abortController = new AbortController(), (t == null ? void 0 : t.query) !== void 0 && (this._searchQuery = t.query), this._isLoading = !0, this.notifySubscribers();
775
+ try {
776
+ const e = await this.config.threadListAdapter.loadThreads(t);
777
+ for (const r of e) {
778
+ if (this._threadStates.has(r.id))
779
+ continue;
780
+ const n = new R({
781
+ streamAdapter: this.config.streamAdapter,
782
+ capabilityExecutionManager: this.config.capabilityExecutionManager
783
+ }), a = new v(n);
784
+ this._threads.set(r.id, a), this._threadStates.set(r.id, r);
785
+ const o = new I({
786
+ state: r,
787
+ onSwitchTo: this.switchToThread.bind(this),
788
+ onRename: this.renameThread.bind(this),
789
+ onDelete: this.deleteThread.bind(this)
790
+ });
791
+ this._threadItems.set(r.id, o), a.subscribe(() => {
792
+ this.syncThreadStateFromRuntime(r.id, a), this.notifySubscribers();
798
793
  });
799
- let o, u;
800
- Array.isArray(a) ? (o = a, u = void 0) : (o = a.threads, u = a.pagination), u ? (this._totalPages = u.pageCount ?? 0, this._totalCount = u.total ?? 0, this._currentPage = u.pageNumber ?? this._currentPage, this._hasMore = u.pageNumber !== void 0 && u.pageCount !== void 0 && u.pageNumber < u.pageCount - 1) : this._hasMore = !1;
801
- for (const d of o) {
802
- if (this._threadStates.has(d.id))
803
- continue;
804
- const g = new v({
805
- streamAdapter: this.config.streamAdapter,
806
- capabilityExecutionManager: this.config.capabilityExecutionManager
807
- }), h = new M(g);
808
- this._threads.set(d.id, h), this._threadStates.set(d.id, d);
809
- const l = new I({
810
- state: d,
811
- onSwitchTo: this.switchToThread.bind(this),
812
- onRename: this.renameThread.bind(this),
813
- onDelete: this.deleteThread.bind(this)
814
- });
815
- this._threadItems.set(d.id, l), h.subscribe(() => {
816
- this.syncThreadStateFromRuntime(d.id, h), this.notifySubscribers();
817
- });
818
- }
819
- } catch (a) {
820
- a instanceof Error && a.name !== "AbortError" && console.error("Failed to load threads:", a);
821
- } finally {
822
- this._isLoading = !1, this._isLoadingMore = !1, this._abortController = null, this.notifySubscribers();
823
794
  }
795
+ return e;
796
+ } catch (e) {
797
+ return e instanceof Error && e.name !== "AbortError" && console.error("Failed to load threads:", e), [];
798
+ } finally {
799
+ this._isLoading = !1, this._abortController = null, this.notifySubscribers();
824
800
  }
825
801
  }
826
- async loadMoreThreads() {
827
- this._isLoading || this._isLoadingMore || !this._hasMore || (this._currentPage += 1, await this.loadThreads(this._searchQuery, !1));
828
- }
829
- async searchThreads(t) {
830
- await this.loadThreads(t, !0);
831
- }
832
802
  /**
833
803
  * Syncs conversationId and title from thread runtime to thread state
834
804
  */
835
805
  syncThreadStateFromRuntime(t, e) {
836
- var r;
837
- const n = this._threadStates.get(t);
838
- n && (n.conversationId !== e.conversationId || n.title !== e.title) && (n.conversationId = e.conversationId, n.title = e.title || n.title, n.updatedAt = Date.now(), this._threadStates.set(t, n), (r = this._threadItems.get(t)) == null || r.updateState(n));
806
+ var n;
807
+ const r = this._threadStates.get(t);
808
+ r && (r.conversationId !== e.conversationId || r.title !== e.title) && (r.conversationId = e.conversationId, r.title = e.title || r.title, r.updatedAt = Date.now(), this._threadStates.set(t, r), (n = this._threadItems.get(t)) == null || n.updateState(r));
839
809
  }
840
810
  async renameThread(t, e) {
841
- var r;
842
- const n = this._threadStates.get(t);
843
- if (n) {
844
- if (n.title = e, n.updatedAt = Date.now(), this._threadStates.set(t, n), (r = this._threadItems.get(t)) == null || r.updateState(n), this.config.threadListAdapter)
811
+ var n;
812
+ const r = this._threadStates.get(t);
813
+ if (r) {
814
+ if (r.title = e, r.updatedAt = Date.now(), this._threadStates.set(t, r), (n = this._threadItems.get(t)) == null || n.updateState(r), this.config.threadListAdapter)
845
815
  try {
846
816
  await this.config.threadListAdapter.updateThread(t, { title: e });
847
817
  } catch (a) {
@@ -854,7 +824,7 @@ class st extends y {
854
824
  if (t === this._mainThreadId && this._threads.size === 1)
855
825
  throw new Error("Cannot delete the last thread");
856
826
  if (t === this._mainThreadId) {
857
- const e = Array.from(this._threads.keys()).find((n) => n !== t);
827
+ const e = Array.from(this._threads.keys()).find((r) => r !== t);
858
828
  e && await this.switchToThread(e);
859
829
  }
860
830
  if (this._threads.delete(t), this._threadItems.delete(t), this._threadStates.delete(t), this.config.threadListAdapter)
@@ -869,12 +839,12 @@ class st extends y {
869
839
  class bt extends y {
870
840
  constructor(t) {
871
841
  super();
872
- c(this, "threads");
873
- c(this, "pluginRegistry");
874
- c(this, "capabilityRegistry");
875
- c(this, "capabilityExecutionManager");
876
- c(this, "_contentFocusRuntime");
877
- c(this, "_currentThreadUnsubscribe");
842
+ u(this, "threads");
843
+ u(this, "pluginRegistry");
844
+ u(this, "capabilityRegistry");
845
+ u(this, "capabilityExecutionManager");
846
+ u(this, "_contentFocusRuntime");
847
+ u(this, "_currentThreadUnsubscribe");
878
848
  this.pluginRegistry = new G(), t.plugins && t.plugins.forEach((e) => {
879
849
  this.pluginRegistry.registerPlugin(e);
880
850
  }), this.capabilityRegistry = new Y(), this.capabilityExecutionManager = new K((e) => this.capabilityRegistry.getHandler(e)), this.threads = new st({
@@ -927,70 +897,70 @@ class bt extends y {
927
897
  autoFocusLastContent(t) {
928
898
  var e;
929
899
  if (t.length !== 0 && !this._contentFocusRuntime.isActive)
930
- for (let n = t.length - 1; n >= 0; n--) {
931
- const r = t[n];
932
- if (r.role === "assistant")
933
- for (let a = r.content.length - 1; a >= 0; a--) {
934
- const o = r.content[a], u = this.pluginRegistry.getRenderersByType(o.type);
935
- if (u.length > 0 && ((e = u[0].capabilities) != null && e.supportsFocus)) {
936
- this._contentFocusRuntime.focus(o, r, a, "detail");
900
+ for (let r = t.length - 1; r >= 0; r--) {
901
+ const n = t[r];
902
+ if (n.role === "assistant")
903
+ for (let a = n.content.length - 1; a >= 0; a--) {
904
+ const o = n.content[a], c = this.pluginRegistry.getRenderersByType(o.type);
905
+ if (c.length > 0 && ((e = c[0].capabilities) != null && e.supportsFocus)) {
906
+ this._contentFocusRuntime.focus(o, n, a, "detail");
937
907
  return;
938
908
  }
939
909
  }
940
910
  }
941
911
  }
942
912
  }
943
- var R = { exports: {} }, x = {};
913
+ var E = { exports: {} }, x = {};
944
914
  /*
945
915
  object-assign
946
916
  (c) Sindre Sorhus
947
917
  @license MIT
948
918
  */
949
- var E, N;
919
+ var M, O;
950
920
  function rt() {
951
- if (N) return E;
952
- N = 1;
921
+ if (O) return M;
922
+ O = 1;
953
923
  var i = Object.getOwnPropertySymbols, s = Object.prototype.hasOwnProperty, t = Object.prototype.propertyIsEnumerable;
954
- function e(r) {
955
- if (r == null)
924
+ function e(n) {
925
+ if (n == null)
956
926
  throw new TypeError("Object.assign cannot be called with null or undefined");
957
- return Object(r);
927
+ return Object(n);
958
928
  }
959
- function n() {
929
+ function r() {
960
930
  try {
961
931
  if (!Object.assign)
962
932
  return !1;
963
- var r = new String("abc");
964
- if (r[5] = "de", Object.getOwnPropertyNames(r)[0] === "5")
933
+ var n = new String("abc");
934
+ if (n[5] = "de", Object.getOwnPropertyNames(n)[0] === "5")
965
935
  return !1;
966
936
  for (var a = {}, o = 0; o < 10; o++)
967
937
  a["_" + String.fromCharCode(o)] = o;
968
- var u = Object.getOwnPropertyNames(a).map(function(g) {
969
- return a[g];
938
+ var c = Object.getOwnPropertyNames(a).map(function(f) {
939
+ return a[f];
970
940
  });
971
- if (u.join("") !== "0123456789")
941
+ if (c.join("") !== "0123456789")
972
942
  return !1;
973
- var d = {};
974
- return "abcdefghijklmnopqrst".split("").forEach(function(g) {
975
- d[g] = g;
976
- }), Object.keys(Object.assign({}, d)).join("") === "abcdefghijklmnopqrst";
943
+ var l = {};
944
+ return "abcdefghijklmnopqrst".split("").forEach(function(f) {
945
+ l[f] = f;
946
+ }), Object.keys(Object.assign({}, l)).join("") === "abcdefghijklmnopqrst";
977
947
  } catch {
978
948
  return !1;
979
949
  }
980
950
  }
981
- return E = n() ? Object.assign : function(r, a) {
982
- for (var o, u = e(r), d, g = 1; g < arguments.length; g++) {
983
- o = Object(arguments[g]);
951
+ return M = r() ? Object.assign : function(n, a) {
952
+ for (var o, c = e(n), l, f = 1; f < arguments.length; f++) {
953
+ o = Object(arguments[f]);
984
954
  for (var h in o)
985
- s.call(o, h) && (u[h] = o[h]);
955
+ s.call(o, h) && (c[h] = o[h]);
986
956
  if (i) {
987
- d = i(o);
988
- for (var l = 0; l < d.length; l++)
989
- t.call(o, d[l]) && (u[d[l]] = o[d[l]]);
957
+ l = i(o);
958
+ for (var d = 0; d < l.length; d++)
959
+ t.call(o, l[d]) && (c[l[d]] = o[l[d]]);
990
960
  }
991
961
  }
992
- return u;
993
- }, E;
962
+ return c;
963
+ }, M;
994
964
  }
995
965
  /** @license React v17.0.2
996
966
  * react-jsx-runtime.production.min.js
@@ -1000,54 +970,52 @@ function rt() {
1000
970
  * This source code is licensed under the MIT license found in the
1001
971
  * LICENSE file in the root directory of this source tree.
1002
972
  */
1003
- var j;
973
+ var D;
1004
974
  function nt() {
1005
- if (j) return x;
1006
- j = 1, rt();
975
+ if (D) return x;
976
+ D = 1, rt();
1007
977
  var i = k, s = 60103;
1008
978
  if (x.Fragment = 60107, typeof Symbol == "function" && Symbol.for) {
1009
979
  var t = Symbol.for;
1010
980
  s = t("react.element"), x.Fragment = t("react.fragment");
1011
981
  }
1012
- var e = i.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, n = Object.prototype.hasOwnProperty, r = { key: !0, ref: !0, __self: !0, __source: !0 };
1013
- function a(o, u, d) {
1014
- var g, h = {}, l = null, p = null;
1015
- d !== void 0 && (l = "" + d), u.key !== void 0 && (l = "" + u.key), u.ref !== void 0 && (p = u.ref);
1016
- for (g in u) n.call(u, g) && !r.hasOwnProperty(g) && (h[g] = u[g]);
1017
- if (o && o.defaultProps) for (g in u = o.defaultProps, u) h[g] === void 0 && (h[g] = u[g]);
1018
- return { $$typeof: s, type: o, key: l, ref: p, props: h, _owner: e.current };
982
+ var e = i.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, r = Object.prototype.hasOwnProperty, n = { key: !0, ref: !0, __self: !0, __source: !0 };
983
+ function a(o, c, l) {
984
+ var f, h = {}, d = null, g = null;
985
+ l !== void 0 && (d = "" + l), c.key !== void 0 && (d = "" + c.key), c.ref !== void 0 && (g = c.ref);
986
+ for (f in c) r.call(c, f) && !n.hasOwnProperty(f) && (h[f] = c[f]);
987
+ if (o && o.defaultProps) for (f in c = o.defaultProps, c) h[f] === void 0 && (h[f] = c[f]);
988
+ return { $$typeof: s, type: o, key: d, ref: g, props: h, _owner: e.current };
1019
989
  }
1020
990
  return x.jsx = a, x.jsxs = a, x;
1021
991
  }
1022
- var O;
992
+ var L;
1023
993
  function it() {
1024
- return O || (O = 1, R.exports = nt()), R.exports;
994
+ return L || (L = 1, E.exports = nt()), E.exports;
1025
995
  }
1026
996
  var S = it();
1027
- const U = q(null);
997
+ const $ = q(null);
1028
998
  function yt({ runtime: i, children: s }) {
1029
- return /* @__PURE__ */ S.jsx(U.Provider, { value: i, children: s });
999
+ return /* @__PURE__ */ S.jsx($.Provider, { value: i, children: s });
1030
1000
  }
1031
1001
  function at() {
1032
- const i = Q(U);
1002
+ const i = U($);
1033
1003
  if (!i)
1034
1004
  throw new Error("useAssistantRuntimeContext must be used within AssistantRuntimeProvider");
1035
1005
  return i;
1036
1006
  }
1037
- function f() {
1007
+ function p() {
1038
1008
  return at();
1039
1009
  }
1040
1010
  function _t() {
1041
- const i = f();
1011
+ const i = p();
1042
1012
  return {
1043
1013
  switchToThread: (s) => i.threads.switchToThread(s),
1044
1014
  switchToNewThread: () => i.threads.switchToNewThread(),
1045
- loadThreads: (s, t) => i.threads.loadThreads(s, t),
1046
- loadMoreThreads: () => i.threads.loadMoreThreads(),
1047
- searchThreads: (s) => i.threads.searchThreads(s),
1015
+ loadThreads: (s) => i.threads.loadThreads(s),
1048
1016
  renameThread: (s, t) => {
1049
- var e, n;
1050
- return (n = (e = i.threads).renameThread) == null ? void 0 : n.call(e, s, t);
1017
+ var e, r;
1018
+ return (r = (e = i.threads).renameThread) == null ? void 0 : r.call(e, s, t);
1051
1019
  },
1052
1020
  deleteThread: (s) => {
1053
1021
  var t, e;
@@ -1056,18 +1024,18 @@ function _t() {
1056
1024
  };
1057
1025
  }
1058
1026
  function xt() {
1059
- const i = f(), [s, t] = b(i.threads.getState());
1027
+ const i = p(), [s, t] = b(i.threads.getState());
1060
1028
  return w(() => i.threads.subscribe(() => {
1061
1029
  t(i.threads.getState());
1062
1030
  }), [i]), s;
1063
1031
  }
1064
1032
  function ot() {
1065
- const s = f().threads.getMainThread(), [, t] = b({});
1033
+ const s = p().threads.getMainThread(), [, t] = b({});
1066
1034
  return w(() => s.subscribe(() => {
1067
1035
  t({});
1068
1036
  }), [s]), s;
1069
1037
  }
1070
- var P = { exports: {} }, A = {};
1038
+ var A = { exports: {} }, P = {};
1071
1039
  /**
1072
1040
  * @license React
1073
1041
  * use-sync-external-store-shim.production.js
@@ -1077,54 +1045,54 @@ var P = { exports: {} }, A = {};
1077
1045
  * This source code is licensed under the MIT license found in the
1078
1046
  * LICENSE file in the root directory of this source tree.
1079
1047
  */
1080
- var D;
1081
- function ut() {
1082
- if (D) return A;
1083
- D = 1;
1048
+ var N;
1049
+ function ct() {
1050
+ if (N) return P;
1051
+ N = 1;
1084
1052
  var i = k;
1085
- function s(h, l) {
1086
- return h === l && (h !== 0 || 1 / h === 1 / l) || h !== h && l !== l;
1053
+ function s(h, d) {
1054
+ return h === d && (h !== 0 || 1 / h === 1 / d) || h !== h && d !== d;
1087
1055
  }
1088
- var t = typeof Object.is == "function" ? Object.is : s, e = i.useState, n = i.useEffect, r = i.useLayoutEffect, a = i.useDebugValue;
1089
- function o(h, l) {
1090
- var p = l(), _ = e({ inst: { value: p, getSnapshot: l } }), m = _[0].inst, T = _[1];
1091
- return r(
1056
+ var t = typeof Object.is == "function" ? Object.is : s, e = i.useState, r = i.useEffect, n = i.useLayoutEffect, a = i.useDebugValue;
1057
+ function o(h, d) {
1058
+ var g = d(), _ = e({ inst: { value: g, getSnapshot: d } }), m = _[0].inst, T = _[1];
1059
+ return n(
1092
1060
  function() {
1093
- m.value = p, m.getSnapshot = l, u(m) && T({ inst: m });
1061
+ m.value = g, m.getSnapshot = d, c(m) && T({ inst: m });
1094
1062
  },
1095
- [h, p, l]
1096
- ), n(
1063
+ [h, g, d]
1064
+ ), r(
1097
1065
  function() {
1098
- return u(m) && T({ inst: m }), h(function() {
1099
- u(m) && T({ inst: m });
1066
+ return c(m) && T({ inst: m }), h(function() {
1067
+ c(m) && T({ inst: m });
1100
1068
  });
1101
1069
  },
1102
1070
  [h]
1103
- ), a(p), p;
1071
+ ), a(g), g;
1104
1072
  }
1105
- function u(h) {
1106
- var l = h.getSnapshot;
1073
+ function c(h) {
1074
+ var d = h.getSnapshot;
1107
1075
  h = h.value;
1108
1076
  try {
1109
- var p = l();
1110
- return !t(h, p);
1077
+ var g = d();
1078
+ return !t(h, g);
1111
1079
  } catch {
1112
1080
  return !0;
1113
1081
  }
1114
1082
  }
1115
- function d(h, l) {
1116
- return l();
1083
+ function l(h, d) {
1084
+ return d();
1117
1085
  }
1118
- var g = typeof window > "u" || typeof window.document > "u" || typeof window.document.createElement > "u" ? d : o;
1119
- return A.useSyncExternalStore = i.useSyncExternalStore !== void 0 ? i.useSyncExternalStore : g, A;
1086
+ var f = typeof window > "u" || typeof window.document > "u" || typeof window.document.createElement > "u" ? l : o;
1087
+ return P.useSyncExternalStore = i.useSyncExternalStore !== void 0 ? i.useSyncExternalStore : f, P;
1120
1088
  }
1121
1089
  var B;
1122
- function ct() {
1123
- return B || (B = 1, P.exports = ut()), P.exports;
1090
+ function ut() {
1091
+ return B || (B = 1, A.exports = ct()), A.exports;
1124
1092
  }
1125
- var ht = ct();
1093
+ var ht = ut();
1126
1094
  function St() {
1127
- const i = f();
1095
+ const i = p();
1128
1096
  return ht.useSyncExternalStore(
1129
1097
  (s) => i.subscribe(() => {
1130
1098
  s();
@@ -1134,7 +1102,7 @@ function St() {
1134
1102
  );
1135
1103
  }
1136
1104
  function wt() {
1137
- const i = ot(), [s, t] = b(""), [e, n] = b(!1);
1105
+ const i = ot(), [s, t] = b(""), [e, r] = b(!1);
1138
1106
  return {
1139
1107
  text: s,
1140
1108
  setText: t,
@@ -1142,22 +1110,22 @@ function wt() {
1142
1110
  send: async (a) => {
1143
1111
  if (a == null || a.preventDefault(), !s.trim() || e) return;
1144
1112
  const o = s;
1145
- t(""), n(!0);
1113
+ t(""), r(!0);
1146
1114
  try {
1147
1115
  await i.send(o);
1148
- } catch (u) {
1149
- console.error("Failed to send message:", u), t(o);
1116
+ } catch (c) {
1117
+ console.error("Failed to send message:", c), t(o);
1150
1118
  } finally {
1151
- n(!1);
1119
+ r(!1);
1152
1120
  }
1153
1121
  },
1154
1122
  clear: () => t(""),
1155
1123
  append: (a) => t((o) => o + a)
1156
1124
  };
1157
1125
  }
1158
- function $(i, s) {
1159
- var r, a, o, u;
1160
- const e = f().pluginRegistry.getBestRendererForType(i);
1126
+ function Q(i, s) {
1127
+ var n, a, o, c;
1128
+ const e = p().pluginRegistry.getBestRendererForType(i);
1161
1129
  if (!e)
1162
1130
  return {
1163
1131
  component: null,
@@ -1166,31 +1134,31 @@ function $(i, s) {
1166
1134
  supportsPreview: !1,
1167
1135
  supportsFullscreen: !1
1168
1136
  };
1169
- const n = s ? (r = e.auxiliary) == null ? void 0 : r[s] : null;
1137
+ const r = s ? (n = e.auxiliary) == null ? void 0 : n[s] : null;
1170
1138
  return {
1171
1139
  component: e.component,
1172
- auxiliaryComponent: n,
1140
+ auxiliaryComponent: r,
1173
1141
  supportsFocus: ((a = e.capabilities) == null ? void 0 : a.supportsFocus) ?? !1,
1174
1142
  supportsPreview: ((o = e.capabilities) == null ? void 0 : o.supportsPreview) ?? !1,
1175
- supportsFullscreen: ((u = e.capabilities) == null ? void 0 : u.supportsFullscreen) ?? !1
1143
+ supportsFullscreen: ((c = e.capabilities) == null ? void 0 : c.supportsFullscreen) ?? !1
1176
1144
  };
1177
1145
  }
1178
1146
  function Ct() {
1179
- const i = f(), [s, t] = b(i.contentFocus.state);
1147
+ const i = p(), [s, t] = b(i.contentFocus.state);
1180
1148
  return w(() => i.contentFocus.subscribe(() => {
1181
1149
  t(i.contentFocus.state);
1182
1150
  }), [i]), {
1183
1151
  ...s,
1184
- focus: (e, n, r, a) => i.contentFocus.focus(e, n, r, a),
1152
+ focus: (e, r, n, a) => i.contentFocus.focus(e, r, n, a),
1185
1153
  blur: () => i.contentFocus.blur(),
1186
- toggle: (e, n, r, a) => i.contentFocus.toggle(e, n, r, a),
1154
+ toggle: (e, r, n, a) => i.contentFocus.toggle(e, r, n, a),
1187
1155
  switchContext: (e) => i.contentFocus.switchContext(e),
1188
1156
  focusNext: () => i.contentFocus.focusNext(i.thread.messages),
1189
1157
  focusPrevious: () => i.contentFocus.focusPrevious(i.thread.messages)
1190
1158
  };
1191
1159
  }
1192
1160
  function dt(i) {
1193
- const s = f();
1161
+ const s = p();
1194
1162
  w(() => (i.execute && s.capabilityRegistry.registerHandler(i.name, { execute: i.execute }), i.render && s.capabilityRegistry.registerRenderer(i.name, {
1195
1163
  component: i.render
1196
1164
  }), () => {
@@ -1198,47 +1166,47 @@ function dt(i) {
1198
1166
  }), [i.name, s]);
1199
1167
  }
1200
1168
  function lt(i) {
1201
- const s = f(), [t, e] = b(
1169
+ const s = p(), [t, e] = b(
1202
1170
  () => s.capabilityExecutionManager.getExecution(i)
1203
- ), [, n] = W((r) => r + 1, 0);
1171
+ ), [, r] = z((n) => n + 1, 0);
1204
1172
  return w(() => {
1205
- const r = s.capabilityExecutionManager.getExecution(i);
1206
- return e(r), s.capabilityExecutionManager.subscribe((o) => {
1173
+ const n = s.capabilityExecutionManager.getExecution(i);
1174
+ return e(n), s.capabilityExecutionManager.subscribe((o) => {
1207
1175
  if (o === i) {
1208
- const u = s.capabilityExecutionManager.getExecution(i);
1209
- e(u), n();
1176
+ const c = s.capabilityExecutionManager.getExecution(i);
1177
+ e(c), r();
1210
1178
  }
1211
1179
  });
1212
1180
  }, [i, s]), t;
1213
1181
  }
1214
1182
  const H = q(void 0);
1215
1183
  function Tt({ children: i }) {
1216
- const [s, t] = b({}), e = C((u, d) => {
1217
- t((g) => {
1218
- if (d === null) {
1219
- const { [u]: h, ...l } = g;
1220
- return l;
1184
+ const [s, t] = b({}), e = C((c, l) => {
1185
+ t((f) => {
1186
+ if (l === null) {
1187
+ const { [c]: h, ...d } = f;
1188
+ return d;
1221
1189
  }
1222
1190
  return {
1223
- ...g,
1224
- [u]: { id: u, ...d }
1191
+ ...f,
1192
+ [c]: { id: c, ...l }
1225
1193
  };
1226
1194
  });
1227
- }, []), n = C((u) => {
1228
- t((d) => {
1229
- const { [u]: g, ...h } = d;
1195
+ }, []), r = C((c) => {
1196
+ t((l) => {
1197
+ const { [c]: f, ...h } = l;
1230
1198
  return h;
1231
1199
  });
1232
- }, []), r = C(() => Object.values(s).reduce(
1233
- (u, d) => {
1234
- const g = Object.entries(d.data).reduce(
1235
- (h, [l, p]) => ({
1200
+ }, []), n = C(() => Object.values(s).reduce(
1201
+ (c, l) => {
1202
+ const f = Object.entries(l.data).reduce(
1203
+ (h, [d, g]) => ({
1236
1204
  ...h,
1237
- [l]: typeof p == "string" ? p : JSON.stringify(p)
1205
+ [d]: typeof g == "string" ? g : JSON.stringify(g)
1238
1206
  }),
1239
1207
  {}
1240
1208
  );
1241
- return { ...u, ...g };
1209
+ return { ...c, ...f };
1242
1210
  },
1243
1211
  {}
1244
1212
  ), [s]), a = C(() => {
@@ -1247,61 +1215,61 @@ function Tt({ children: i }) {
1247
1215
  () => ({
1248
1216
  contexts: s,
1249
1217
  setContext: e,
1250
- removeContext: n,
1251
- getContextData: r,
1218
+ removeContext: r,
1219
+ getContextData: n,
1252
1220
  clearContexts: a
1253
1221
  }),
1254
- [s, e, n, r, a]
1222
+ [s, e, r, n, a]
1255
1223
  );
1256
1224
  return /* @__PURE__ */ S.jsx(H.Provider, { value: o, children: i });
1257
1225
  }
1258
- function gt() {
1259
- const i = Q(H);
1226
+ function ft() {
1227
+ const i = U(H);
1260
1228
  if (!i)
1261
1229
  throw new Error("useChatContext must be used within a ChatContextProvider");
1262
1230
  return i;
1263
1231
  }
1264
1232
  function It(i) {
1265
- const { setContext: s, removeContext: t } = gt(), { id: e = "currentPage", ...n } = i;
1266
- w(() => (s(e, n), () => {
1233
+ const { setContext: s, removeContext: t } = ft(), { id: e = "currentPage", ...r } = i;
1234
+ w(() => (s(e, r), () => {
1267
1235
  t(e);
1268
- }), [e, n.displayName, JSON.stringify(n.data), n.priority, n.icon]);
1236
+ }), [e, r.displayName, JSON.stringify(r.data), r.priority, r.icon]);
1269
1237
  }
1270
- function pt({ message: i, content: s }) {
1271
- const t = f(), e = s, n = lt(e.capabilityId), r = t.capabilityRegistry.getRenderer(e.capabilityName);
1272
- if (!r || !n)
1238
+ function gt({ message: i, content: s }) {
1239
+ const t = p(), e = s, r = lt(e.capabilityId), n = t.capabilityRegistry.getRenderer(e.capabilityName);
1240
+ if (!n || !r)
1273
1241
  return null;
1274
- const a = r.component;
1242
+ const a = n.component;
1275
1243
  return /* @__PURE__ */ S.jsx(
1276
1244
  a,
1277
1245
  {
1278
- capabilityName: n.name,
1279
- capabilityId: n.id,
1280
- args: n.args,
1281
- result: n.result,
1282
- status: n.status,
1246
+ capabilityName: r.name,
1247
+ capabilityId: r.id,
1248
+ args: r.args,
1249
+ result: r.result,
1250
+ status: r.status,
1283
1251
  message: i
1284
1252
  }
1285
1253
  );
1286
1254
  }
1287
- function Mt({ message: i, content: s }) {
1288
- const { component: t } = $(s.type);
1255
+ function vt({ message: i, content: s }) {
1256
+ const { component: t } = Q(s.type);
1289
1257
  if (s.type === "capability")
1290
- return /* @__PURE__ */ S.jsx(pt, { message: i, content: s });
1258
+ return /* @__PURE__ */ S.jsx(gt, { message: i, content: s });
1291
1259
  if (!t)
1292
1260
  return null;
1293
1261
  const e = t;
1294
1262
  return /* @__PURE__ */ S.jsx(e, { content: s, message: i });
1295
1263
  }
1296
- function vt({
1264
+ function Rt({
1297
1265
  message: i,
1298
1266
  content: s,
1299
1267
  context: t,
1300
1268
  onClose: e,
1301
- onNavigate: n,
1302
- onSwitchContext: r
1269
+ onNavigate: r,
1270
+ onSwitchContext: n
1303
1271
  }) {
1304
- const { auxiliaryComponent: a } = $(s.type, t);
1272
+ const { auxiliaryComponent: a } = Q(s.type, t);
1305
1273
  if (!a)
1306
1274
  return null;
1307
1275
  const o = a;
@@ -1312,16 +1280,16 @@ function vt({
1312
1280
  message: i,
1313
1281
  context: t,
1314
1282
  onClose: e,
1315
- onNavigate: n,
1316
- onSwitchContext: r
1283
+ onNavigate: r,
1284
+ onSwitchContext: n
1317
1285
  }
1318
1286
  );
1319
1287
  }
1320
- function Rt(i) {
1288
+ function Et(i) {
1321
1289
  const s = () => (dt(i), null);
1322
1290
  return s.displayName = `Capability(${i.name})`, s;
1323
1291
  }
1324
- class Et {
1292
+ class Mt {
1325
1293
  getAllowedEvents() {
1326
1294
  return null;
1327
1295
  }
@@ -1330,26 +1298,26 @@ class Et {
1330
1298
  return t ? t.includes(s) : !0;
1331
1299
  }
1332
1300
  async *stream(s) {
1333
- const { signal: t } = s, { url: e, options: n } = this.prepareRequest(s), r = await fetch(e, { ...n, signal: t });
1334
- if (!r.ok)
1335
- throw new Error(`HTTP error! status: ${r.status}`);
1336
- if (!r.body)
1301
+ const { signal: t } = s, { url: e, options: r } = this.prepareRequest(s), n = await fetch(e, { ...r, signal: t });
1302
+ if (!n.ok)
1303
+ throw new Error(`HTTP error! status: ${n.status}`);
1304
+ if (!n.body)
1337
1305
  throw new Error("Response body is null");
1338
- yield* this.parseSSEStream(r.body, t);
1306
+ yield* this.parseSSEStream(n.body, t);
1339
1307
  }
1340
1308
  async *parseSSEStream(s, t) {
1341
- const e = s.getReader(), n = new TextDecoder();
1342
- let r = "", a = null;
1309
+ const e = s.getReader(), r = new TextDecoder();
1310
+ let n = "", a = null;
1343
1311
  try {
1344
1312
  for (; ; ) {
1345
- const { done: o, value: u } = await e.read();
1313
+ const { done: o, value: c } = await e.read();
1346
1314
  if (o || t != null && t.aborted) break;
1347
- r += n.decode(u, { stream: !0 });
1348
- const d = r.split(`
1315
+ n += r.decode(c, { stream: !0 });
1316
+ const l = n.split(`
1349
1317
  `);
1350
- r = d.pop() || "";
1351
- for (const g of d) {
1352
- const h = g.trim();
1318
+ n = l.pop() || "";
1319
+ for (const f of l) {
1320
+ const h = f.trim();
1353
1321
  if (!h) {
1354
1322
  a = null;
1355
1323
  continue;
@@ -1360,15 +1328,15 @@ class Et {
1360
1328
  continue;
1361
1329
  }
1362
1330
  if (h.startsWith("data:")) {
1363
- const l = h.substring(5).trim();
1364
- if (l === "eof" || h === "eof")
1331
+ const d = h.substring(5).trim();
1332
+ if (d === "eof" || h === "eof")
1365
1333
  break;
1366
1334
  try {
1367
- const p = JSON.parse(l);
1335
+ const g = JSON.parse(d);
1368
1336
  if (a && this.shouldProcessEvent(a)) {
1369
1337
  const _ = this.convertEvent({
1370
1338
  event: a,
1371
- data: p
1339
+ data: g
1372
1340
  });
1373
1341
  _ && (yield _);
1374
1342
  }
@@ -1387,27 +1355,27 @@ class Et {
1387
1355
  export {
1388
1356
  bt as AssistantRuntime,
1389
1357
  yt as AssistantRuntimeProvider,
1390
- vt as AuxiliaryRenderer,
1391
- Et as BaseSSEStreamAdapter,
1358
+ Rt as AuxiliaryRenderer,
1359
+ Mt as BaseSSEStreamAdapter,
1392
1360
  K as CapabilityExecutionManager,
1393
1361
  Y as CapabilityRegistry,
1394
- pt as CapabilityRendererComp,
1362
+ gt as CapabilityRendererComp,
1395
1363
  Tt as ChatContextProvider,
1396
1364
  et as ComposerRuntime,
1397
- Mt as ContentRenderer,
1365
+ vt as ContentRenderer,
1398
1366
  G as PluginRegistry,
1399
1367
  I as ThreadListItemRuntime,
1400
1368
  st as ThreadListRuntime,
1401
- M as ThreadRuntime,
1402
- v as ThreadRuntimeCore,
1403
- Rt as makeCapability,
1404
- f as useAssistantRuntime,
1369
+ v as ThreadRuntime,
1370
+ R as ThreadRuntimeCore,
1371
+ Et as makeCapability,
1372
+ p as useAssistantRuntime,
1405
1373
  dt as useCapability,
1406
1374
  lt as useCapabilityExecution,
1407
- gt as useChatContext,
1375
+ ft as useChatContext,
1408
1376
  wt as useComposer,
1409
1377
  Ct as useContentFocus,
1410
- $ as useContentRenderer,
1378
+ Q as useContentRenderer,
1411
1379
  ot as useCurrentThread,
1412
1380
  St as useMessages,
1413
1381
  It as usePageContext,