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