@harnessio/ai-chat-core 0.0.5 → 0.0.7

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,36 +1,36 @@
1
1
  var $ = Object.defineProperty;
2
- var U = (i, s, t) => s in i ? $(i, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[s] = t;
3
- var c = (i, s, t) => U(i, typeof s != "symbol" ? s + "" : s, t);
2
+ var U = (i, r, t) => r in i ? $(i, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[r] = t;
3
+ var c = (i, r, t) => U(i, typeof r != "symbol" ? r + "" : r, t);
4
4
  import B, { createContext as H, useContext as Q, useState as x, useEffect as w, useReducer as J } from "react";
5
5
  class W {
6
6
  constructor() {
7
7
  c(this, "plugins", /* @__PURE__ */ new Map());
8
8
  c(this, "renderersByType", /* @__PURE__ */ new Map());
9
9
  }
10
- registerPlugin(s) {
11
- this.plugins.has(s.id), this.plugins.set(s.id, s), s.renderers.forEach((t) => {
10
+ registerPlugin(r) {
11
+ this.plugins.has(r.id), this.plugins.set(r.id, r), r.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((n, s) => ((s == null ? void 0 : s.priority) ?? 0) - ((n == null ? void 0 : n.priority) ?? 0)), this.renderersByType.set(t.type, e);
14
14
  });
15
15
  }
16
- unregisterPlugin(s) {
17
- const t = this.plugins.get(s);
16
+ unregisterPlugin(r) {
17
+ const t = this.plugins.get(r);
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);
21
- }), this.plugins.delete(s)) : !1;
19
+ const s = (this.renderersByType.get(e.type) || []).filter((a) => !t.renderers.includes(a));
20
+ s.length === 0 ? this.renderersByType.delete(e.type) : this.renderersByType.set(e.type, s);
21
+ }), this.plugins.delete(r)) : !1;
22
22
  }
23
- getPlugin(s) {
24
- return this.plugins.get(s);
23
+ getPlugin(r) {
24
+ return this.plugins.get(r);
25
25
  }
26
26
  getAllPlugins() {
27
27
  return Array.from(this.plugins.values());
28
28
  }
29
- getRenderersByType(s) {
30
- return this.renderersByType.get(s) || [];
29
+ getRenderersByType(r) {
30
+ return this.renderersByType.get(r) || [];
31
31
  }
32
- getBestRendererForType(s) {
33
- return this.getRenderersByType(s)[0];
32
+ getBestRendererForType(r) {
33
+ return this.getRenderersByType(r)[0];
34
34
  }
35
35
  clear() {
36
36
  this.plugins.clear(), this.renderersByType.clear();
@@ -41,29 +41,29 @@ class z {
41
41
  c(this, "handlers", /* @__PURE__ */ new Map());
42
42
  c(this, "renderers", /* @__PURE__ */ new Map());
43
43
  }
44
- registerHandler(s, t) {
45
- this.handlers.set(s, t);
44
+ registerHandler(r, t) {
45
+ this.handlers.set(r, t);
46
46
  }
47
- registerRenderer(s, t) {
48
- this.renderers.set(s, t);
47
+ registerRenderer(r, t) {
48
+ this.renderers.set(r, t);
49
49
  }
50
- unregister(s) {
51
- this.handlers.delete(s), this.renderers.delete(s);
50
+ unregister(r) {
51
+ this.handlers.delete(r), this.renderers.delete(r);
52
52
  }
53
- getHandler(s) {
54
- return this.handlers.get(s);
53
+ getHandler(r) {
54
+ return this.handlers.get(r);
55
55
  }
56
- getRenderer(s) {
57
- return this.renderers.get(s);
56
+ getRenderer(r) {
57
+ return this.renderers.get(r);
58
58
  }
59
59
  getStrategy() {
60
60
  return "queue";
61
61
  }
62
- hasHandler(s) {
63
- return this.handlers.has(s);
62
+ hasHandler(r) {
63
+ return this.handlers.has(r);
64
64
  }
65
- hasRenderer(s) {
66
- return this.renderers.has(s);
65
+ hasRenderer(r) {
66
+ return this.renderers.has(r);
67
67
  }
68
68
  clear() {
69
69
  this.handlers.clear(), this.renderers.clear();
@@ -73,29 +73,29 @@ class z {
73
73
  }
74
74
  }
75
75
  class V {
76
- constructor(s) {
76
+ constructor(r) {
77
77
  c(this, "executions", /* @__PURE__ */ new Map());
78
78
  c(this, "executionQueue", []);
79
79
  c(this, "isProcessing", !1);
80
80
  c(this, "runningByName", /* @__PURE__ */ new Map());
81
81
  c(this, "subscribers", /* @__PURE__ */ new Set());
82
82
  c(this, "getHandler");
83
- this.getHandler = s;
83
+ this.getHandler = r;
84
84
  }
85
- async executeCapability(s, t, e, n, r = "queue") {
86
- if (!this.getHandler(s)) {
87
- console.warn(`No handler registered for capability: ${s}`);
85
+ async executeCapability(r, t, e, n, s = "queue") {
86
+ if (!this.getHandler(r)) {
87
+ console.warn(`No handler registered for capability: ${r}`);
88
88
  return;
89
89
  }
90
90
  const o = {
91
91
  id: t,
92
- name: s,
92
+ name: r,
93
93
  args: e,
94
94
  status: { type: "queued" },
95
95
  timestamp: Date.now(),
96
96
  messageId: n
97
97
  };
98
- switch (this.executions.set(t, o), this.notifySubscribers(t), r) {
98
+ switch (this.executions.set(t, o), this.notifySubscribers(t), s) {
99
99
  case "queue":
100
100
  default:
101
101
  this.executionQueue.push(t);
@@ -106,41 +106,41 @@ class V {
106
106
  async processQueue() {
107
107
  if (!(this.isProcessing || this.executionQueue.length === 0)) {
108
108
  for (this.isProcessing = !0; this.executionQueue.length > 0; ) {
109
- const s = this.executionQueue.shift(), t = this.executions.get(s);
109
+ const r = this.executionQueue.shift(), t = this.executions.get(r);
110
110
  if (!t) continue;
111
111
  const e = this.getHandler(t.name);
112
112
  if (!e) continue;
113
- t.status = { type: "running" }, this.notifySubscribers(s);
113
+ t.status = { type: "running" }, this.notifySubscribers(r);
114
114
  const n = this.runningByName.get(t.name) || [];
115
- n.push(s), this.runningByName.set(t.name, n);
115
+ n.push(r), this.runningByName.set(t.name, n);
116
116
  try {
117
- const r = await e.execute(t.args, {
117
+ const s = await e.execute(t.args, {
118
118
  messageId: t.messageId,
119
- capabilityId: s
119
+ capabilityId: r
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: s }, t.result = s;
122
+ } catch (s) {
123
+ const a = s instanceof Error ? s.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 s = this.runningByName.get(t.name) || [], a = s.indexOf(r);
127
+ a > -1 && s.splice(a, 1), s.length === 0 ? this.runningByName.delete(t.name) : this.runningByName.set(t.name, s), this.notifySubscribers(r);
128
128
  }
129
129
  }
130
130
  this.isProcessing = !1;
131
131
  }
132
132
  }
133
- getExecution(s) {
134
- return this.executions.get(s);
133
+ getExecution(r) {
134
+ return this.executions.get(r);
135
135
  }
136
- getExecutionsByMessage(s) {
137
- return Array.from(this.executions.values()).filter((t) => t.messageId === s);
136
+ getExecutionsByMessage(r) {
137
+ return Array.from(this.executions.values()).filter((t) => t.messageId === r);
138
138
  }
139
- subscribe(s) {
140
- return this.subscribers.add(s), () => this.subscribers.delete(s);
139
+ subscribe(r) {
140
+ return this.subscribers.add(r), () => this.subscribers.delete(r);
141
141
  }
142
- notifySubscribers(s) {
143
- this.subscribers.forEach((t) => t(s));
142
+ notifySubscribers(r) {
143
+ this.subscribers.forEach((t) => t(r));
144
144
  }
145
145
  clear() {
146
146
  this.executions.clear(), this.executionQueue = [], this.runningByName.clear();
@@ -150,14 +150,14 @@ class y {
150
150
  constructor() {
151
151
  c(this, "_subscriptions", /* @__PURE__ */ new Set());
152
152
  }
153
- subscribe(s) {
154
- return this._subscriptions.add(s), () => {
155
- this._subscriptions.delete(s);
153
+ subscribe(r) {
154
+ return this._subscriptions.add(r), () => {
155
+ this._subscriptions.delete(r);
156
156
  };
157
157
  }
158
158
  notifySubscribers() {
159
- for (const s of this._subscriptions)
160
- s();
159
+ for (const r of this._subscriptions)
160
+ r();
161
161
  }
162
162
  getSubscriberCount() {
163
163
  return this._subscriptions.size;
@@ -196,10 +196,10 @@ class G 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, n, s = "detail") {
200
200
  this._state = {
201
201
  isActive: !0,
202
- context: r,
202
+ context: s,
203
203
  focusedContent: t,
204
204
  focusedMessage: e,
205
205
  focusedMessageId: e.id,
@@ -216,8 +216,8 @@ class G 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, n, s = "detail") {
220
+ this._state.isActive && this._state.focusedMessageId === e.id && this._state.focusedContentIndex === n && this._state.context === s ? this.blur() : this.focus(t, e, n, s);
221
221
  }
222
222
  switchContext(t) {
223
223
  this._state.isActive && this._state.focusedContent && (this._state = {
@@ -229,10 +229,10 @@ class G 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 n = t[e], s = this._state.focusedContentIndex ?? 0;
233
+ if (s + 1 < n.content.length) {
234
+ const a = n.content[s + 1];
235
+ this.focus(a, n, s + 1, this._state.context || "detail");
236
236
  return;
237
237
  }
238
238
  if (e + 1 < t.length) {
@@ -244,10 +244,10 @@ class G 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 n = t[e], s = this._state.focusedContentIndex ?? 0;
248
+ if (s > 0) {
249
+ const a = n.content[s - 1];
250
+ this.focus(a, n, s - 1, this._state.context || "detail");
251
251
  return;
252
252
  }
253
253
  if (e > 0) {
@@ -385,6 +385,12 @@ class R extends y {
385
385
  reset(t = []) {
386
386
  this._core.reset(t);
387
387
  }
388
+ setConversationId(t) {
389
+ this._core.setConversationId(t);
390
+ }
391
+ setTitle(t) {
392
+ this._core.setTitle(t);
393
+ }
388
394
  subscribe(t) {
389
395
  return super.subscribe(t);
390
396
  }
@@ -456,22 +462,22 @@ class v extends y {
456
462
  };
457
463
  this.updateMessages([...this._messages, n]);
458
464
  try {
459
- const r = this.config.streamAdapter.stream({
465
+ const s = this.config.streamAdapter.stream({
460
466
  messages: this._messages,
461
467
  conversationId: this._conversationId,
462
468
  signal: this._abortController.signal
463
469
  });
464
- for await (const a of r) {
470
+ for await (const a of s) {
465
471
  if (this._abortController.signal.aborted)
466
472
  break;
467
473
  this.handleStreamEvent(e, a.event);
468
474
  }
469
475
  this.updateMessageStatus(e, { type: "complete" });
470
- } catch (r) {
471
- if (r instanceof Error && r.name === "AbortError")
476
+ } catch (s) {
477
+ if (s instanceof Error && s.name === "AbortError")
472
478
  this.updateMessageStatus(e, { type: "cancelled" });
473
479
  else {
474
- const a = r instanceof Error ? r.message : "Unknown error";
480
+ const a = s instanceof Error ? s.message : "Unknown error";
475
481
  this.updateMessageStatus(e, {
476
482
  type: "error",
477
483
  error: a
@@ -484,24 +490,24 @@ class v extends y {
484
490
  handleStreamEvent(t, e) {
485
491
  const n = this._messages.findIndex((o) => o.id === t);
486
492
  if (n === -1) return;
487
- const r = this._messages[n];
493
+ const s = this._messages[n];
488
494
  if (e.type === "part-start")
489
- this.handlePartStart(r, e);
495
+ this.handlePartStart(s, e);
490
496
  else if (e.type === "text-delta" || e.type === "assistant_thought")
491
- this.handleTextDelta(r, e);
497
+ this.handleTextDelta(s, e);
492
498
  else if (e.type === "part-finish")
493
499
  this.handlePartFinish();
494
500
  else if (e.type === "metadata") {
495
501
  const o = e;
496
- r.metadata = {
497
- ...r.metadata,
502
+ s.metadata = {
503
+ ...s.metadata,
498
504
  conversationId: o.conversationId,
499
505
  interactionId: o.interactionId
500
506
  }, o.conversationId && !this._conversationId && (this._conversationId = o.conversationId), o.title && !this._title && (this._title = o.title);
501
507
  } else if (e.type === "capability_execution") {
502
508
  const o = e;
503
- r.content = [
504
- ...r.content,
509
+ s.content = [
510
+ ...s.content,
505
511
  {
506
512
  type: "capability",
507
513
  capabilityId: o.capabilityId,
@@ -517,8 +523,8 @@ class v extends y {
517
523
  );
518
524
  } else if (e.type === "error") {
519
525
  const o = e;
520
- r.content = [
521
- ...r.content,
526
+ s.content = [
527
+ ...s.content,
522
528
  {
523
529
  type: "error",
524
530
  data: o.error
@@ -526,8 +532,8 @@ class v extends y {
526
532
  ];
527
533
  } else {
528
534
  const o = e;
529
- r.content = [
530
- ...r.content,
535
+ s.content = [
536
+ ...s.content,
531
537
  {
532
538
  type: o.type,
533
539
  data: o.data,
@@ -537,36 +543,36 @@ class v extends y {
537
543
  }
538
544
  const a = [
539
545
  ...this._messages.slice(0, n),
540
- { ...r, timestamp: Date.now() },
546
+ { ...s, timestamp: Date.now() },
541
547
  ...this._messages.slice(n + 1)
542
548
  ];
543
549
  this.updateMessages(a);
544
550
  }
545
551
  handlePartStart(t, e) {
546
552
  const n = t.content.length;
547
- let r;
553
+ let s;
548
554
  switch (e.part.type) {
549
555
  case "assistant_thought":
550
- r = {
556
+ s = {
551
557
  type: e.part.type,
552
558
  data: [],
553
559
  parentId: e.part.parentId
554
560
  };
555
561
  break;
556
562
  case "text":
557
- r = {
563
+ s = {
558
564
  type: e.part.type,
559
565
  data: "",
560
566
  parentId: e.part.parentId
561
567
  };
562
568
  break;
563
569
  default:
564
- r = {
570
+ s = {
565
571
  type: e.part.type,
566
572
  parentId: e.part.parentId
567
573
  };
568
574
  }
569
- t.content = [...t.content, r], this._currentPart = {
575
+ t.content = [...t.content, s], this._currentPart = {
570
576
  messageId: t.id,
571
577
  contentIndex: n,
572
578
  type: e.part.type,
@@ -591,7 +597,7 @@ class v extends y {
591
597
  updateMessageStatus(t, e) {
592
598
  const n = this._messages.findIndex((a) => a.id === t);
593
599
  if (n === -1) return;
594
- const r = [
600
+ const s = [
595
601
  ...this._messages.slice(0, n),
596
602
  {
597
603
  ...this._messages[n],
@@ -599,7 +605,7 @@ class v extends y {
599
605
  },
600
606
  ...this._messages.slice(n + 1)
601
607
  ];
602
- this.updateMessages(r);
608
+ this.updateMessages(s);
603
609
  }
604
610
  clear() {
605
611
  this.updateMessages([]);
@@ -610,6 +616,12 @@ class v extends y {
610
616
  reset(t = []) {
611
617
  this.updateMessages([...t]);
612
618
  }
619
+ setConversationId(t) {
620
+ this._conversationId = t, this.notifySubscribers();
621
+ }
622
+ setTitle(t) {
623
+ this._title = t, this.notifySubscribers();
624
+ }
613
625
  }
614
626
  class Z extends y {
615
627
  constructor(t) {
@@ -635,13 +647,13 @@ class Z extends y {
635
647
  updatedAt: Date.now()
636
648
  };
637
649
  this._threadStates.set(this._mainThreadId, n);
638
- const r = new I({
650
+ const s = new I({
639
651
  state: n,
640
652
  onSwitchTo: this.switchToThread.bind(this),
641
653
  onRename: this.renameThread.bind(this),
642
654
  onDelete: this.deleteThread.bind(this)
643
655
  });
644
- this._threadItems.set(this._mainThreadId, r);
656
+ this._threadItems.set(this._mainThreadId, s);
645
657
  }
646
658
  get isLoading() {
647
659
  return this._isLoading;
@@ -655,8 +667,8 @@ class Z extends y {
655
667
  }
656
668
  getState() {
657
669
  const t = [], e = {};
658
- for (const [n, r] of this._threadStates)
659
- e[n] = r, r.status.type === "regular" && t.push(n);
670
+ for (const [n, s] of this._threadStates)
671
+ e[n] = s, s.status.type === "regular" && t.push(n);
660
672
  return {
661
673
  mainThreadId: this._mainThreadId,
662
674
  threads: t,
@@ -671,8 +683,8 @@ class Z extends y {
671
683
  throw new Error(`Thread ${t} not found`);
672
684
  const n = this._threadStates.get(this._mainThreadId);
673
685
  n && (n.isMain = !1, this._threadStates.set(this._mainThreadId, n), (a = this._threadItems.get(this._mainThreadId)) == null || a.updateState(n)), this._mainThreadId = t;
674
- const r = this._threadStates.get(t);
675
- if (r && (r.isMain = !0, this._threadStates.set(t, r), (o = this._threadItems.get(t)) == null || o.updateState(r)), this.config.threadListAdapter && (r != null && r.conversationId)) {
686
+ const s = this._threadStates.get(t);
687
+ if (s && (s.isMain = !0, this._threadStates.set(t, s), (o = this._threadItems.get(t)) == null || o.updateState(s), e.setConversationId(s.conversationId), e.setTitle(s.title)), this.config.threadListAdapter && (s != null && s.conversationId)) {
676
688
  this._isLoading = !0, this.notifySubscribers();
677
689
  try {
678
690
  const u = await this.config.threadListAdapter.loadThread(t);
@@ -691,7 +703,7 @@ class Z extends y {
691
703
  capabilityExecutionManager: this.config.capabilityExecutionManager
692
704
  }), n = new R(e);
693
705
  this._threads.set(t, n);
694
- const r = {
706
+ const s = {
695
707
  id: t,
696
708
  title: "New Chat",
697
709
  status: { type: "regular" },
@@ -699,19 +711,19 @@ class Z extends y {
699
711
  createdAt: Date.now(),
700
712
  updatedAt: Date.now()
701
713
  };
702
- this._threadStates.set(t, r);
714
+ this._threadStates.set(t, s);
703
715
  const a = new I({
704
- state: r,
716
+ state: s,
705
717
  onSwitchTo: this.switchToThread.bind(this),
706
718
  onRename: this.renameThread.bind(this),
707
719
  onDelete: this.deleteThread.bind(this)
708
720
  });
709
721
  if (this._threadItems.set(t, a), n.subscribe(() => {
710
- this.notifySubscribers();
722
+ this.syncThreadStateFromRuntime(t, n), this.notifySubscribers();
711
723
  }), this.config.threadListAdapter)
712
724
  try {
713
725
  const o = await this.config.threadListAdapter.createThread();
714
- r.conversationId = o.conversationId, this._threadStates.set(t, r), a.updateState(r);
726
+ s.conversationId = o.conversationId, this._threadStates.set(t, s), a.updateState(s);
715
727
  } catch (o) {
716
728
  console.error("Failed to create thread:", o);
717
729
  }
@@ -730,16 +742,16 @@ class Z extends y {
730
742
  continue;
731
743
  const n = new v({
732
744
  streamAdapter: this.config.streamAdapter
733
- }), r = new R(n);
734
- this._threads.set(e.id, r), this._threadStates.set(e.id, e);
745
+ }), s = new R(n);
746
+ this._threads.set(e.id, s), this._threadStates.set(e.id, e);
735
747
  const a = new I({
736
748
  state: e,
737
749
  onSwitchTo: this.switchToThread.bind(this),
738
750
  onRename: this.renameThread.bind(this),
739
751
  onDelete: this.deleteThread.bind(this)
740
752
  });
741
- this._threadItems.set(e.id, a), r.subscribe(() => {
742
- this.notifySubscribers();
753
+ this._threadItems.set(e.id, a), s.subscribe(() => {
754
+ this.syncThreadStateFromRuntime(e.id, s), this.notifySubscribers();
743
755
  });
744
756
  }
745
757
  } catch (t) {
@@ -748,11 +760,19 @@ class Z extends y {
748
760
  this._isLoading = !1, this.notifySubscribers();
749
761
  }
750
762
  }
763
+ /**
764
+ * Syncs conversationId and title from thread runtime to thread state
765
+ */
766
+ syncThreadStateFromRuntime(t, e) {
767
+ var s;
768
+ const n = this._threadStates.get(t);
769
+ 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), (s = this._threadItems.get(t)) == null || s.updateState(n));
770
+ }
751
771
  async renameThread(t, e) {
752
- var r;
772
+ var s;
753
773
  const n = this._threadStates.get(t);
754
774
  if (n) {
755
- 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)
775
+ if (n.title = e, n.updatedAt = Date.now(), this._threadStates.set(t, n), (s = this._threadItems.get(t)) == null || s.updateState(n), this.config.threadListAdapter)
756
776
  try {
757
777
  await this.config.threadListAdapter.updateThread(t, { title: e });
758
778
  } catch (a) {
@@ -777,7 +797,7 @@ class Z extends y {
777
797
  this.notifySubscribers();
778
798
  }
779
799
  }
780
- class pt extends y {
800
+ class ft extends y {
781
801
  constructor(t) {
782
802
  super();
783
803
  c(this, "threads");
@@ -839,12 +859,12 @@ class pt extends y {
839
859
  var e;
840
860
  if (t.length !== 0 && !this._contentFocusRuntime.isActive)
841
861
  for (let n = t.length - 1; n >= 0; n--) {
842
- const r = t[n];
843
- if (r.role === "assistant")
844
- for (let a = r.content.length - 1; a >= 0; a--) {
845
- const o = r.content[a], u = this.pluginRegistry.getRenderersByType(o.type);
862
+ const s = t[n];
863
+ if (s.role === "assistant")
864
+ for (let a = s.content.length - 1; a >= 0; a--) {
865
+ const o = s.content[a], u = this.pluginRegistry.getRenderersByType(o.type);
846
866
  if (u.length > 0 && ((e = u[0].capabilities) != null && e.supportsFocus)) {
847
- this._contentFocusRuntime.focus(o, r, a, "detail");
867
+ this._contentFocusRuntime.focus(o, s, a, "detail");
848
868
  return;
849
869
  }
850
870
  }
@@ -861,18 +881,18 @@ var E, L;
861
881
  function tt() {
862
882
  if (L) return E;
863
883
  L = 1;
864
- var i = Object.getOwnPropertySymbols, s = Object.prototype.hasOwnProperty, t = Object.prototype.propertyIsEnumerable;
865
- function e(r) {
866
- if (r == null)
884
+ var i = Object.getOwnPropertySymbols, r = Object.prototype.hasOwnProperty, t = Object.prototype.propertyIsEnumerable;
885
+ function e(s) {
886
+ if (s == null)
867
887
  throw new TypeError("Object.assign cannot be called with null or undefined");
868
- return Object(r);
888
+ return Object(s);
869
889
  }
870
890
  function n() {
871
891
  try {
872
892
  if (!Object.assign)
873
893
  return !1;
874
- var r = new String("abc");
875
- if (r[5] = "de", Object.getOwnPropertyNames(r)[0] === "5")
894
+ var s = new String("abc");
895
+ if (s[5] = "de", Object.getOwnPropertyNames(s)[0] === "5")
876
896
  return !1;
877
897
  for (var a = {}, o = 0; o < 10; o++)
878
898
  a["_" + String.fromCharCode(o)] = o;
@@ -881,23 +901,23 @@ function tt() {
881
901
  });
882
902
  if (u.join("") !== "0123456789")
883
903
  return !1;
884
- var p = {};
904
+ var f = {};
885
905
  return "abcdefghijklmnopqrst".split("").forEach(function(l) {
886
- p[l] = l;
887
- }), Object.keys(Object.assign({}, p)).join("") === "abcdefghijklmnopqrst";
906
+ f[l] = l;
907
+ }), Object.keys(Object.assign({}, f)).join("") === "abcdefghijklmnopqrst";
888
908
  } catch {
889
909
  return !1;
890
910
  }
891
911
  }
892
- return E = n() ? Object.assign : function(r, a) {
893
- for (var o, u = e(r), p, l = 1; l < arguments.length; l++) {
912
+ return E = n() ? Object.assign : function(s, a) {
913
+ for (var o, u = e(s), f, l = 1; l < arguments.length; l++) {
894
914
  o = Object(arguments[l]);
895
915
  for (var h in o)
896
- s.call(o, h) && (u[h] = o[h]);
916
+ r.call(o, h) && (u[h] = o[h]);
897
917
  if (i) {
898
- p = i(o);
899
- for (var d = 0; d < p.length; d++)
900
- t.call(o, p[d]) && (u[p[d]] = o[p[d]]);
918
+ f = i(o);
919
+ for (var d = 0; d < f.length; d++)
920
+ t.call(o, f[d]) && (u[f[d]] = o[f[d]]);
901
921
  }
902
922
  }
903
923
  return u;
@@ -915,18 +935,18 @@ var j;
915
935
  function et() {
916
936
  if (j) return _;
917
937
  j = 1, tt();
918
- var i = B, s = 60103;
938
+ var i = B, r = 60103;
919
939
  if (_.Fragment = 60107, typeof Symbol == "function" && Symbol.for) {
920
940
  var t = Symbol.for;
921
- s = t("react.element"), _.Fragment = t("react.fragment");
941
+ r = t("react.element"), _.Fragment = t("react.fragment");
922
942
  }
923
- 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 };
924
- function a(o, u, p) {
925
- var l, h = {}, d = null, f = null;
926
- p !== void 0 && (d = "" + p), u.key !== void 0 && (d = "" + u.key), u.ref !== void 0 && (f = u.ref);
927
- for (l in u) n.call(u, l) && !r.hasOwnProperty(l) && (h[l] = u[l]);
943
+ var e = i.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, n = Object.prototype.hasOwnProperty, s = { key: !0, ref: !0, __self: !0, __source: !0 };
944
+ function a(o, u, f) {
945
+ var l, h = {}, d = null, p = null;
946
+ f !== void 0 && (d = "" + f), u.key !== void 0 && (d = "" + u.key), u.ref !== void 0 && (p = u.ref);
947
+ for (l in u) n.call(u, l) && !s.hasOwnProperty(l) && (h[l] = u[l]);
928
948
  if (o && o.defaultProps) for (l in u = o.defaultProps, u) h[l] === void 0 && (h[l] = u[l]);
929
- return { $$typeof: s, type: o, key: d, ref: f, props: h, _owner: e.current };
949
+ return { $$typeof: r, type: o, key: d, ref: p, props: h, _owner: e.current };
930
950
  }
931
951
  return _.jsx = a, _.jsxs = a, _;
932
952
  }
@@ -936,8 +956,8 @@ function st() {
936
956
  }
937
957
  var S = st();
938
958
  const k = H(null);
939
- function ft({ runtime: i, children: s }) {
940
- return /* @__PURE__ */ S.jsx(k.Provider, { value: i, children: s });
959
+ function pt({ runtime: i, children: r }) {
960
+ return /* @__PURE__ */ S.jsx(k.Provider, { value: i, children: r });
941
961
  }
942
962
  function rt() {
943
963
  const i = Q(k);
@@ -951,27 +971,27 @@ function g() {
951
971
  function gt() {
952
972
  const i = g();
953
973
  return {
954
- switchToThread: (s) => i.threads.switchToThread(s),
974
+ switchToThread: (r) => i.threads.switchToThread(r),
955
975
  switchToNewThread: () => i.threads.switchToNewThread(),
956
976
  loadThreads: () => {
957
- var s, t;
958
- return (t = (s = i.threads).loadThreads) == null ? void 0 : t.call(s);
977
+ var r, t;
978
+ return (t = (r = i.threads).loadThreads) == null ? void 0 : t.call(r);
959
979
  },
960
- renameThread: (s, t) => {
980
+ renameThread: (r, t) => {
961
981
  var e, n;
962
- return (n = (e = i.threads).renameThread) == null ? void 0 : n.call(e, s, t);
982
+ return (n = (e = i.threads).renameThread) == null ? void 0 : n.call(e, r, t);
963
983
  },
964
- deleteThread: (s) => {
984
+ deleteThread: (r) => {
965
985
  var t, e;
966
- return (e = (t = i.threads).deleteThread) == null ? void 0 : e.call(t, s);
986
+ return (e = (t = i.threads).deleteThread) == null ? void 0 : e.call(t, r);
967
987
  }
968
988
  };
969
989
  }
970
990
  function bt() {
971
- const i = g(), [s, t] = x(i.threads.getState());
991
+ const i = g(), [r, t] = x(i.threads.getState());
972
992
  return w(() => i.threads.subscribe(() => {
973
993
  t(i.threads.getState());
974
- }), [i]), s;
994
+ }), [i]), r;
975
995
  }
976
996
  function nt() {
977
997
  return g().threads.getMainThread();
@@ -986,22 +1006,22 @@ var M = { exports: {} }, A = {};
986
1006
  * This source code is licensed under the MIT license found in the
987
1007
  * LICENSE file in the root directory of this source tree.
988
1008
  */
989
- var N;
1009
+ var D;
990
1010
  function it() {
991
- if (N) return A;
992
- N = 1;
1011
+ if (D) return A;
1012
+ D = 1;
993
1013
  var i = B;
994
- function s(h, d) {
1014
+ function r(h, d) {
995
1015
  return h === d && (h !== 0 || 1 / h === 1 / d) || h !== h && d !== d;
996
1016
  }
997
- var t = typeof Object.is == "function" ? Object.is : s, e = i.useState, n = i.useEffect, r = i.useLayoutEffect, a = i.useDebugValue;
1017
+ var t = typeof Object.is == "function" ? Object.is : r, e = i.useState, n = i.useEffect, s = i.useLayoutEffect, a = i.useDebugValue;
998
1018
  function o(h, d) {
999
- var f = d(), m = e({ inst: { value: f, getSnapshot: d } }), b = m[0].inst, T = m[1];
1000
- return r(
1019
+ var p = d(), m = e({ inst: { value: p, getSnapshot: d } }), b = m[0].inst, T = m[1];
1020
+ return s(
1001
1021
  function() {
1002
- b.value = f, b.getSnapshot = d, u(b) && T({ inst: b });
1022
+ b.value = p, b.getSnapshot = d, u(b) && T({ inst: b });
1003
1023
  },
1004
- [h, f, d]
1024
+ [h, p, d]
1005
1025
  ), n(
1006
1026
  function() {
1007
1027
  return u(b) && T({ inst: b }), h(function() {
@@ -1009,48 +1029,48 @@ function it() {
1009
1029
  });
1010
1030
  },
1011
1031
  [h]
1012
- ), a(f), f;
1032
+ ), a(p), p;
1013
1033
  }
1014
1034
  function u(h) {
1015
1035
  var d = h.getSnapshot;
1016
1036
  h = h.value;
1017
1037
  try {
1018
- var f = d();
1019
- return !t(h, f);
1038
+ var p = d();
1039
+ return !t(h, p);
1020
1040
  } catch {
1021
1041
  return !0;
1022
1042
  }
1023
1043
  }
1024
- function p(h, d) {
1044
+ function f(h, d) {
1025
1045
  return d();
1026
1046
  }
1027
- var l = typeof window > "u" || typeof window.document > "u" || typeof window.document.createElement > "u" ? p : o;
1047
+ var l = typeof window > "u" || typeof window.document > "u" || typeof window.document.createElement > "u" ? f : o;
1028
1048
  return A.useSyncExternalStore = i.useSyncExternalStore !== void 0 ? i.useSyncExternalStore : l, A;
1029
1049
  }
1030
- var D;
1050
+ var N;
1031
1051
  function at() {
1032
- return D || (D = 1, M.exports = it()), M.exports;
1052
+ return N || (N = 1, M.exports = it()), M.exports;
1033
1053
  }
1034
1054
  var ot = at();
1035
1055
  function yt() {
1036
1056
  const i = g();
1037
1057
  return ot.useSyncExternalStore(
1038
- (s) => i.subscribe(() => {
1039
- s();
1058
+ (r) => i.subscribe(() => {
1059
+ r();
1040
1060
  }),
1041
1061
  () => i.thread.messages,
1042
1062
  () => i.thread.messages
1043
1063
  );
1044
1064
  }
1045
1065
  function mt() {
1046
- const i = nt(), [s, t] = x(""), [e, n] = x(!1);
1066
+ const i = nt(), [r, t] = x(""), [e, n] = x(!1);
1047
1067
  return {
1048
- text: s,
1068
+ text: r,
1049
1069
  setText: t,
1050
1070
  isSubmitting: e,
1051
1071
  send: async (a) => {
1052
- if (a == null || a.preventDefault(), !s.trim() || e) return;
1053
- const o = s;
1072
+ if (a == null || a.preventDefault(), !r.trim() || e) return;
1073
+ const o = r;
1054
1074
  t(""), n(!0);
1055
1075
  try {
1056
1076
  await i.send(o);
@@ -1064,8 +1084,8 @@ function mt() {
1064
1084
  append: (a) => t((o) => o + a)
1065
1085
  };
1066
1086
  }
1067
- function q(i, s) {
1068
- var r, a, o, u;
1087
+ function q(i, r) {
1088
+ var s, a, o, u;
1069
1089
  const e = g().pluginRegistry.getBestRendererForType(i);
1070
1090
  if (!e)
1071
1091
  return {
@@ -1075,7 +1095,7 @@ function q(i, s) {
1075
1095
  supportsPreview: !1,
1076
1096
  supportsFullscreen: !1
1077
1097
  };
1078
- const n = s ? (r = e.auxiliary) == null ? void 0 : r[s] : null;
1098
+ const n = r ? (s = e.auxiliary) == null ? void 0 : s[r] : null;
1079
1099
  return {
1080
1100
  component: e.component,
1081
1101
  auxiliaryComponent: n,
@@ -1085,46 +1105,46 @@ function q(i, s) {
1085
1105
  };
1086
1106
  }
1087
1107
  function _t() {
1088
- const i = g(), [s, t] = x(i.contentFocus.state);
1108
+ const i = g(), [r, t] = x(i.contentFocus.state);
1089
1109
  return w(() => i.contentFocus.subscribe(() => {
1090
1110
  t(i.contentFocus.state);
1091
1111
  }), [i]), {
1092
- ...s,
1093
- focus: (e, n, r, a) => i.contentFocus.focus(e, n, r, a),
1112
+ ...r,
1113
+ focus: (e, n, s, a) => i.contentFocus.focus(e, n, s, a),
1094
1114
  blur: () => i.contentFocus.blur(),
1095
- toggle: (e, n, r, a) => i.contentFocus.toggle(e, n, r, a),
1115
+ toggle: (e, n, s, a) => i.contentFocus.toggle(e, n, s, a),
1096
1116
  switchContext: (e) => i.contentFocus.switchContext(e),
1097
1117
  focusNext: () => i.contentFocus.focusNext(i.thread.messages),
1098
1118
  focusPrevious: () => i.contentFocus.focusPrevious(i.thread.messages)
1099
1119
  };
1100
1120
  }
1101
1121
  function ut(i) {
1102
- const s = g();
1103
- w(() => (i.execute && s.capabilityRegistry.registerHandler(i.name, { execute: i.execute }), i.render && s.capabilityRegistry.registerRenderer(i.name, {
1122
+ const r = g();
1123
+ w(() => (i.execute && r.capabilityRegistry.registerHandler(i.name, { execute: i.execute }), i.render && r.capabilityRegistry.registerRenderer(i.name, {
1104
1124
  component: i.render
1105
1125
  }), () => {
1106
- s.capabilityRegistry.unregister(i.name);
1107
- }), [i.name, s]);
1126
+ r.capabilityRegistry.unregister(i.name);
1127
+ }), [i.name, r]);
1108
1128
  }
1109
1129
  function ct(i) {
1110
- const s = g(), [t, e] = x(
1111
- () => s.capabilityExecutionManager.getExecution(i)
1112
- ), [, n] = J((r) => r + 1, 0);
1130
+ const r = g(), [t, e] = x(
1131
+ () => r.capabilityExecutionManager.getExecution(i)
1132
+ ), [, n] = J((s) => s + 1, 0);
1113
1133
  return w(() => {
1114
- const r = s.capabilityExecutionManager.getExecution(i);
1115
- return e(r), s.capabilityExecutionManager.subscribe((o) => {
1134
+ const s = r.capabilityExecutionManager.getExecution(i);
1135
+ return e(s), r.capabilityExecutionManager.subscribe((o) => {
1116
1136
  if (o === i) {
1117
- const u = s.capabilityExecutionManager.getExecution(i);
1137
+ const u = r.capabilityExecutionManager.getExecution(i);
1118
1138
  e(u), n();
1119
1139
  }
1120
1140
  });
1121
- }, [i, s]), t;
1141
+ }, [i, r]), t;
1122
1142
  }
1123
- function ht({ message: i, content: s }) {
1124
- const t = g(), e = s, n = ct(e.capabilityId), r = t.capabilityRegistry.getRenderer(e.capabilityName);
1125
- if (!r || !n)
1143
+ function ht({ message: i, content: r }) {
1144
+ const t = g(), e = r, n = ct(e.capabilityId), s = t.capabilityRegistry.getRenderer(e.capabilityName);
1145
+ if (!s || !n)
1126
1146
  return null;
1127
- const a = r.component;
1147
+ const a = s.component;
1128
1148
  return /* @__PURE__ */ S.jsx(
1129
1149
  a,
1130
1150
  {
@@ -1137,71 +1157,71 @@ function ht({ message: i, content: s }) {
1137
1157
  }
1138
1158
  );
1139
1159
  }
1140
- function xt({ message: i, content: s }) {
1141
- const { component: t } = q(s.type);
1142
- if (s.type === "capability")
1143
- return /* @__PURE__ */ S.jsx(ht, { message: i, content: s });
1160
+ function xt({ message: i, content: r }) {
1161
+ const { component: t } = q(r.type);
1162
+ if (r.type === "capability")
1163
+ return /* @__PURE__ */ S.jsx(ht, { message: i, content: r });
1144
1164
  if (!t)
1145
1165
  return null;
1146
1166
  const e = t;
1147
- return /* @__PURE__ */ S.jsx(e, { content: s, message: i });
1167
+ return /* @__PURE__ */ S.jsx(e, { content: r, message: i });
1148
1168
  }
1149
1169
  function St({
1150
1170
  message: i,
1151
- content: s,
1171
+ content: r,
1152
1172
  context: t,
1153
1173
  onClose: e,
1154
1174
  onNavigate: n,
1155
- onSwitchContext: r
1175
+ onSwitchContext: s
1156
1176
  }) {
1157
- const { auxiliaryComponent: a } = q(s.type, t);
1177
+ const { auxiliaryComponent: a } = q(r.type, t);
1158
1178
  if (!a)
1159
1179
  return null;
1160
1180
  const o = a;
1161
1181
  return /* @__PURE__ */ S.jsx(
1162
1182
  o,
1163
1183
  {
1164
- content: s,
1184
+ content: r,
1165
1185
  message: i,
1166
1186
  context: t,
1167
1187
  onClose: e,
1168
1188
  onNavigate: n,
1169
- onSwitchContext: r
1189
+ onSwitchContext: s
1170
1190
  }
1171
1191
  );
1172
1192
  }
1173
1193
  function wt(i) {
1174
- const s = () => (ut(i), null);
1175
- return s.displayName = `Capability(${i.name})`, s;
1194
+ const r = () => (ut(i), null);
1195
+ return r.displayName = `Capability(${i.name})`, r;
1176
1196
  }
1177
1197
  class Tt {
1178
1198
  getAllowedEvents() {
1179
1199
  return null;
1180
1200
  }
1181
- shouldProcessEvent(s) {
1201
+ shouldProcessEvent(r) {
1182
1202
  const t = this.getAllowedEvents();
1183
- return t ? t.includes(s) : !0;
1203
+ return t ? t.includes(r) : !0;
1184
1204
  }
1185
- async *stream(s) {
1186
- const { signal: t } = s, { url: e, options: n } = this.prepareRequest(s), r = await fetch(e, { ...n, signal: t });
1187
- if (!r.ok)
1188
- throw new Error(`HTTP error! status: ${r.status}`);
1189
- if (!r.body)
1205
+ async *stream(r) {
1206
+ const { signal: t } = r, { url: e, options: n } = this.prepareRequest(r), s = await fetch(e, { ...n, signal: t });
1207
+ if (!s.ok)
1208
+ throw new Error(`HTTP error! status: ${s.status}`);
1209
+ if (!s.body)
1190
1210
  throw new Error("Response body is null");
1191
- yield* this.parseSSEStream(r.body, t);
1211
+ yield* this.parseSSEStream(s.body, t);
1192
1212
  }
1193
- async *parseSSEStream(s, t) {
1194
- const e = s.getReader(), n = new TextDecoder();
1195
- let r = "", a = null;
1213
+ async *parseSSEStream(r, t) {
1214
+ const e = r.getReader(), n = new TextDecoder();
1215
+ let s = "", a = null;
1196
1216
  try {
1197
1217
  for (; ; ) {
1198
1218
  const { done: o, value: u } = await e.read();
1199
1219
  if (o || t != null && t.aborted) break;
1200
- r += n.decode(u, { stream: !0 });
1201
- const p = r.split(`
1220
+ s += n.decode(u, { stream: !0 });
1221
+ const f = s.split(`
1202
1222
  `);
1203
- r = p.pop() || "";
1204
- for (const l of p) {
1223
+ s = f.pop() || "";
1224
+ for (const l of f) {
1205
1225
  const h = l.trim();
1206
1226
  if (!h) {
1207
1227
  a = null;
@@ -1217,11 +1237,11 @@ class Tt {
1217
1237
  if (d === "eof" || h === "eof")
1218
1238
  break;
1219
1239
  try {
1220
- const f = JSON.parse(d);
1240
+ const p = JSON.parse(d);
1221
1241
  if (a && this.shouldProcessEvent(a)) {
1222
1242
  const m = this.convertEvent({
1223
1243
  event: a,
1224
- data: f
1244
+ data: p
1225
1245
  });
1226
1246
  m && (yield m);
1227
1247
  }
@@ -1238,8 +1258,8 @@ class Tt {
1238
1258
  }
1239
1259
  }
1240
1260
  export {
1241
- pt as AssistantRuntime,
1242
- ft as AssistantRuntimeProvider,
1261
+ ft as AssistantRuntime,
1262
+ pt as AssistantRuntimeProvider,
1243
1263
  St as AuxiliaryRenderer,
1244
1264
  Tt as BaseSSEStreamAdapter,
1245
1265
  V as CapabilityExecutionManager,