@harnessio/ai-chat-core 0.0.7 → 0.0.8
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,69 +1,69 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var c = (i,
|
|
4
|
-
import B, { createContext as
|
|
5
|
-
class
|
|
1
|
+
var Q = Object.defineProperty;
|
|
2
|
+
var $ = (i, s, t) => s in i ? Q(i, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[s] = t;
|
|
3
|
+
var c = (i, s, t) => $(i, typeof s != "symbol" ? s + "" : s, t);
|
|
4
|
+
import B, { createContext as U, useContext as H, useState as x, useEffect as w, useReducer as J } from "react";
|
|
5
|
+
class z {
|
|
6
6
|
constructor() {
|
|
7
7
|
c(this, "plugins", /* @__PURE__ */ new Map());
|
|
8
8
|
c(this, "renderersByType", /* @__PURE__ */ new Map());
|
|
9
9
|
}
|
|
10
|
-
registerPlugin(
|
|
11
|
-
this.plugins.has(
|
|
10
|
+
registerPlugin(s) {
|
|
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,
|
|
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);
|
|
14
14
|
});
|
|
15
15
|
}
|
|
16
|
-
unregisterPlugin(
|
|
17
|
-
const t = this.plugins.get(
|
|
16
|
+
unregisterPlugin(s) {
|
|
17
|
+
const t = this.plugins.get(s);
|
|
18
18
|
return t ? (t.renderers.forEach((e) => {
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
}), this.plugins.delete(
|
|
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;
|
|
22
22
|
}
|
|
23
|
-
getPlugin(
|
|
24
|
-
return this.plugins.get(
|
|
23
|
+
getPlugin(s) {
|
|
24
|
+
return this.plugins.get(s);
|
|
25
25
|
}
|
|
26
26
|
getAllPlugins() {
|
|
27
27
|
return Array.from(this.plugins.values());
|
|
28
28
|
}
|
|
29
|
-
getRenderersByType(
|
|
30
|
-
return this.renderersByType.get(
|
|
29
|
+
getRenderersByType(s) {
|
|
30
|
+
return this.renderersByType.get(s) || [];
|
|
31
31
|
}
|
|
32
|
-
getBestRendererForType(
|
|
33
|
-
return this.getRenderersByType(
|
|
32
|
+
getBestRendererForType(s) {
|
|
33
|
+
return this.getRenderersByType(s)[0];
|
|
34
34
|
}
|
|
35
35
|
clear() {
|
|
36
36
|
this.plugins.clear(), this.renderersByType.clear();
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
-
class
|
|
39
|
+
class W {
|
|
40
40
|
constructor() {
|
|
41
41
|
c(this, "handlers", /* @__PURE__ */ new Map());
|
|
42
42
|
c(this, "renderers", /* @__PURE__ */ new Map());
|
|
43
43
|
}
|
|
44
|
-
registerHandler(
|
|
45
|
-
this.handlers.set(
|
|
44
|
+
registerHandler(s, t) {
|
|
45
|
+
this.handlers.set(s, t);
|
|
46
46
|
}
|
|
47
|
-
registerRenderer(
|
|
48
|
-
this.renderers.set(
|
|
47
|
+
registerRenderer(s, t) {
|
|
48
|
+
this.renderers.set(s, t);
|
|
49
49
|
}
|
|
50
|
-
unregister(
|
|
51
|
-
this.handlers.delete(
|
|
50
|
+
unregister(s) {
|
|
51
|
+
this.handlers.delete(s), this.renderers.delete(s);
|
|
52
52
|
}
|
|
53
|
-
getHandler(
|
|
54
|
-
return this.handlers.get(
|
|
53
|
+
getHandler(s) {
|
|
54
|
+
return this.handlers.get(s);
|
|
55
55
|
}
|
|
56
|
-
getRenderer(
|
|
57
|
-
return this.renderers.get(
|
|
56
|
+
getRenderer(s) {
|
|
57
|
+
return this.renderers.get(s);
|
|
58
58
|
}
|
|
59
59
|
getStrategy() {
|
|
60
60
|
return "queue";
|
|
61
61
|
}
|
|
62
|
-
hasHandler(
|
|
63
|
-
return this.handlers.has(
|
|
62
|
+
hasHandler(s) {
|
|
63
|
+
return this.handlers.has(s);
|
|
64
64
|
}
|
|
65
|
-
hasRenderer(
|
|
66
|
-
return this.renderers.has(
|
|
65
|
+
hasRenderer(s) {
|
|
66
|
+
return this.renderers.has(s);
|
|
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(
|
|
76
|
+
constructor(s) {
|
|
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 =
|
|
83
|
+
this.getHandler = s;
|
|
84
84
|
}
|
|
85
|
-
async executeCapability(
|
|
86
|
-
if (!this.getHandler(
|
|
87
|
-
console.warn(`No handler registered for capability: ${
|
|
85
|
+
async executeCapability(s, t, e, n, r = "queue") {
|
|
86
|
+
if (!this.getHandler(s)) {
|
|
87
|
+
console.warn(`No handler registered for capability: ${s}`);
|
|
88
88
|
return;
|
|
89
89
|
}
|
|
90
90
|
const o = {
|
|
91
91
|
id: t,
|
|
92
|
-
name:
|
|
92
|
+
name: s,
|
|
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),
|
|
98
|
+
switch (this.executions.set(t, o), this.notifySubscribers(t), r) {
|
|
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
|
|
109
|
+
const s = this.executionQueue.shift(), t = this.executions.get(s);
|
|
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(
|
|
113
|
+
t.status = { type: "running" }, this.notifySubscribers(s);
|
|
114
114
|
const n = this.runningByName.get(t.name) || [];
|
|
115
|
-
n.push(
|
|
115
|
+
n.push(s), this.runningByName.set(t.name, n);
|
|
116
116
|
try {
|
|
117
|
-
const
|
|
117
|
+
const r = await e.execute(t.args, {
|
|
118
118
|
messageId: t.messageId,
|
|
119
|
-
capabilityId:
|
|
119
|
+
capabilityId: s
|
|
120
120
|
});
|
|
121
|
-
t.status = { type: "complete", result:
|
|
122
|
-
} catch (
|
|
123
|
-
const a =
|
|
121
|
+
t.status = { type: "complete", result: r }, t.result = r;
|
|
122
|
+
} catch (r) {
|
|
123
|
+
const a = r instanceof Error ? r.message : "Unknown error";
|
|
124
124
|
t.status = { type: "error", error: a }, t.error = a;
|
|
125
125
|
} finally {
|
|
126
|
-
const
|
|
127
|
-
a > -1 &&
|
|
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);
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
130
|
this.isProcessing = !1;
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
|
-
getExecution(
|
|
134
|
-
return this.executions.get(
|
|
133
|
+
getExecution(s) {
|
|
134
|
+
return this.executions.get(s);
|
|
135
135
|
}
|
|
136
|
-
getExecutionsByMessage(
|
|
137
|
-
return Array.from(this.executions.values()).filter((t) => t.messageId ===
|
|
136
|
+
getExecutionsByMessage(s) {
|
|
137
|
+
return Array.from(this.executions.values()).filter((t) => t.messageId === s);
|
|
138
138
|
}
|
|
139
|
-
subscribe(
|
|
140
|
-
return this.subscribers.add(
|
|
139
|
+
subscribe(s) {
|
|
140
|
+
return this.subscribers.add(s), () => this.subscribers.delete(s);
|
|
141
141
|
}
|
|
142
|
-
notifySubscribers(
|
|
143
|
-
this.subscribers.forEach((t) => t(
|
|
142
|
+
notifySubscribers(s) {
|
|
143
|
+
this.subscribers.forEach((t) => t(s));
|
|
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(
|
|
154
|
-
return this._subscriptions.add(
|
|
155
|
-
this._subscriptions.delete(
|
|
153
|
+
subscribe(s) {
|
|
154
|
+
return this._subscriptions.add(s), () => {
|
|
155
|
+
this._subscriptions.delete(s);
|
|
156
156
|
};
|
|
157
157
|
}
|
|
158
158
|
notifySubscribers() {
|
|
159
|
-
for (const
|
|
160
|
-
|
|
159
|
+
for (const s of this._subscriptions)
|
|
160
|
+
s();
|
|
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,
|
|
199
|
+
focus(t, e, n, r = "detail") {
|
|
200
200
|
this._state = {
|
|
201
201
|
isActive: !0,
|
|
202
|
-
context:
|
|
202
|
+
context: r,
|
|
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,
|
|
220
|
-
this._state.isActive && this._state.focusedMessageId === e.id && this._state.focusedContentIndex === n && this._state.context ===
|
|
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);
|
|
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],
|
|
233
|
-
if (
|
|
234
|
-
const a = n.content[
|
|
235
|
-
this.focus(a, n,
|
|
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");
|
|
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],
|
|
248
|
-
if (
|
|
249
|
-
const a = n.content[
|
|
250
|
-
this.focus(a, n,
|
|
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");
|
|
251
251
|
return;
|
|
252
252
|
}
|
|
253
253
|
if (e > 0) {
|
|
@@ -263,7 +263,7 @@ let Y = 0, K = 0;
|
|
|
263
263
|
function P() {
|
|
264
264
|
return `msg-${Date.now()}-${++Y}`;
|
|
265
265
|
}
|
|
266
|
-
function
|
|
266
|
+
function L() {
|
|
267
267
|
return `thread-${Date.now()}-${++K}`;
|
|
268
268
|
}
|
|
269
269
|
class I extends y {
|
|
@@ -322,7 +322,7 @@ class X extends y {
|
|
|
322
322
|
this._isSubmitting = t, this.notifySubscribers();
|
|
323
323
|
}
|
|
324
324
|
}
|
|
325
|
-
class
|
|
325
|
+
class C extends y {
|
|
326
326
|
constructor(t) {
|
|
327
327
|
super();
|
|
328
328
|
c(this, "composer");
|
|
@@ -395,7 +395,7 @@ class R extends y {
|
|
|
395
395
|
return super.subscribe(t);
|
|
396
396
|
}
|
|
397
397
|
}
|
|
398
|
-
class
|
|
398
|
+
class M extends y {
|
|
399
399
|
constructor(t) {
|
|
400
400
|
super();
|
|
401
401
|
c(this, "_messages", []);
|
|
@@ -462,22 +462,22 @@ class v extends y {
|
|
|
462
462
|
};
|
|
463
463
|
this.updateMessages([...this._messages, n]);
|
|
464
464
|
try {
|
|
465
|
-
const
|
|
465
|
+
const r = 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
|
|
470
|
+
for await (const a of r) {
|
|
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 (
|
|
477
|
-
if (
|
|
476
|
+
} catch (r) {
|
|
477
|
+
if (r instanceof Error && r.name === "AbortError")
|
|
478
478
|
this.updateMessageStatus(e, { type: "cancelled" });
|
|
479
479
|
else {
|
|
480
|
-
const a =
|
|
480
|
+
const a = r instanceof Error ? r.message : "Unknown error";
|
|
481
481
|
this.updateMessageStatus(e, {
|
|
482
482
|
type: "error",
|
|
483
483
|
error: a
|
|
@@ -490,24 +490,24 @@ class v extends y {
|
|
|
490
490
|
handleStreamEvent(t, e) {
|
|
491
491
|
const n = this._messages.findIndex((o) => o.id === t);
|
|
492
492
|
if (n === -1) return;
|
|
493
|
-
const
|
|
493
|
+
const r = this._messages[n];
|
|
494
494
|
if (e.type === "part-start")
|
|
495
|
-
this.handlePartStart(
|
|
495
|
+
this.handlePartStart(r, e);
|
|
496
496
|
else if (e.type === "text-delta" || e.type === "assistant_thought")
|
|
497
|
-
this.handleTextDelta(
|
|
497
|
+
this.handleTextDelta(r, 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
|
-
|
|
503
|
-
...
|
|
502
|
+
r.metadata = {
|
|
503
|
+
...r.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
|
-
|
|
510
|
-
...
|
|
509
|
+
r.content = [
|
|
510
|
+
...r.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
|
-
|
|
527
|
-
...
|
|
526
|
+
r.content = [
|
|
527
|
+
...r.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
|
-
|
|
536
|
-
...
|
|
535
|
+
r.content = [
|
|
536
|
+
...r.content,
|
|
537
537
|
{
|
|
538
538
|
type: o.type,
|
|
539
539
|
data: o.data,
|
|
@@ -543,36 +543,36 @@ class v extends y {
|
|
|
543
543
|
}
|
|
544
544
|
const a = [
|
|
545
545
|
...this._messages.slice(0, n),
|
|
546
|
-
{ ...
|
|
546
|
+
{ ...r, timestamp: Date.now() },
|
|
547
547
|
...this._messages.slice(n + 1)
|
|
548
548
|
];
|
|
549
549
|
this.updateMessages(a);
|
|
550
550
|
}
|
|
551
551
|
handlePartStart(t, e) {
|
|
552
552
|
const n = t.content.length;
|
|
553
|
-
let
|
|
553
|
+
let r;
|
|
554
554
|
switch (e.part.type) {
|
|
555
555
|
case "assistant_thought":
|
|
556
|
-
|
|
556
|
+
r = {
|
|
557
557
|
type: e.part.type,
|
|
558
558
|
data: [],
|
|
559
559
|
parentId: e.part.parentId
|
|
560
560
|
};
|
|
561
561
|
break;
|
|
562
562
|
case "text":
|
|
563
|
-
|
|
563
|
+
r = {
|
|
564
564
|
type: e.part.type,
|
|
565
565
|
data: "",
|
|
566
566
|
parentId: e.part.parentId
|
|
567
567
|
};
|
|
568
568
|
break;
|
|
569
569
|
default:
|
|
570
|
-
|
|
570
|
+
r = {
|
|
571
571
|
type: e.part.type,
|
|
572
572
|
parentId: e.part.parentId
|
|
573
573
|
};
|
|
574
574
|
}
|
|
575
|
-
t.content = [...t.content,
|
|
575
|
+
t.content = [...t.content, r], this._currentPart = {
|
|
576
576
|
messageId: t.id,
|
|
577
577
|
contentIndex: n,
|
|
578
578
|
type: e.part.type,
|
|
@@ -597,7 +597,7 @@ class v extends y {
|
|
|
597
597
|
updateMessageStatus(t, e) {
|
|
598
598
|
const n = this._messages.findIndex((a) => a.id === t);
|
|
599
599
|
if (n === -1) return;
|
|
600
|
-
const
|
|
600
|
+
const r = [
|
|
601
601
|
...this._messages.slice(0, n),
|
|
602
602
|
{
|
|
603
603
|
...this._messages[n],
|
|
@@ -605,7 +605,7 @@ class v extends y {
|
|
|
605
605
|
},
|
|
606
606
|
...this._messages.slice(n + 1)
|
|
607
607
|
];
|
|
608
|
-
this.updateMessages(
|
|
608
|
+
this.updateMessages(r);
|
|
609
609
|
}
|
|
610
610
|
clear() {
|
|
611
611
|
this.updateMessages([]);
|
|
@@ -631,13 +631,20 @@ class Z extends y {
|
|
|
631
631
|
c(this, "_threadItems", /* @__PURE__ */ new Map());
|
|
632
632
|
c(this, "_threadStates", /* @__PURE__ */ new Map());
|
|
633
633
|
c(this, "_isLoading", !1);
|
|
634
|
+
c(this, "_isLoadingMore", !1);
|
|
635
|
+
c(this, "_currentPage", 0);
|
|
636
|
+
c(this, "_totalPages", 0);
|
|
637
|
+
c(this, "_totalCount", 0);
|
|
638
|
+
c(this, "_hasMore", !0);
|
|
639
|
+
c(this, "_searchQuery");
|
|
640
|
+
c(this, "_abortController", null);
|
|
634
641
|
c(this, "main");
|
|
635
|
-
this.config = t, this._mainThreadId =
|
|
636
|
-
const e = new
|
|
642
|
+
this.config = t, this._mainThreadId = L();
|
|
643
|
+
const e = new M({
|
|
637
644
|
streamAdapter: t.streamAdapter,
|
|
638
645
|
capabilityExecutionManager: t.capabilityExecutionManager
|
|
639
646
|
});
|
|
640
|
-
this.main = new
|
|
647
|
+
this.main = new C(e), this._threads.set(this._mainThreadId, this.main);
|
|
641
648
|
const n = {
|
|
642
649
|
id: this._mainThreadId,
|
|
643
650
|
title: "New Chat",
|
|
@@ -647,17 +654,20 @@ class Z extends y {
|
|
|
647
654
|
updatedAt: Date.now()
|
|
648
655
|
};
|
|
649
656
|
this._threadStates.set(this._mainThreadId, n);
|
|
650
|
-
const
|
|
657
|
+
const r = new I({
|
|
651
658
|
state: n,
|
|
652
659
|
onSwitchTo: this.switchToThread.bind(this),
|
|
653
660
|
onRename: this.renameThread.bind(this),
|
|
654
661
|
onDelete: this.deleteThread.bind(this)
|
|
655
662
|
});
|
|
656
|
-
this._threadItems.set(this._mainThreadId,
|
|
663
|
+
this._threadItems.set(this._mainThreadId, r);
|
|
657
664
|
}
|
|
658
665
|
get isLoading() {
|
|
659
666
|
return this._isLoading;
|
|
660
667
|
}
|
|
668
|
+
get isLoadingMore() {
|
|
669
|
+
return this._isLoadingMore;
|
|
670
|
+
}
|
|
661
671
|
/**
|
|
662
672
|
* Get the currently active main thread
|
|
663
673
|
*/
|
|
@@ -667,13 +677,21 @@ class Z extends y {
|
|
|
667
677
|
}
|
|
668
678
|
getState() {
|
|
669
679
|
const t = [], e = {};
|
|
670
|
-
for (const [n,
|
|
671
|
-
e[n] =
|
|
680
|
+
for (const [n, r] of this._threadStates)
|
|
681
|
+
e[n] = r, r.status.type === "regular" && t.push(n);
|
|
672
682
|
return {
|
|
673
683
|
mainThreadId: this._mainThreadId,
|
|
674
684
|
threads: t,
|
|
675
685
|
isLoading: this._isLoading,
|
|
676
|
-
|
|
686
|
+
isLoadingMore: this._isLoadingMore,
|
|
687
|
+
threadItems: e,
|
|
688
|
+
pagination: {
|
|
689
|
+
currentPage: this._currentPage,
|
|
690
|
+
totalPages: this._totalPages,
|
|
691
|
+
totalCount: this._totalCount,
|
|
692
|
+
hasMore: this._hasMore
|
|
693
|
+
},
|
|
694
|
+
searchQuery: this._searchQuery
|
|
677
695
|
};
|
|
678
696
|
}
|
|
679
697
|
async switchToThread(t) {
|
|
@@ -683,8 +701,8 @@ class Z extends y {
|
|
|
683
701
|
throw new Error(`Thread ${t} not found`);
|
|
684
702
|
const n = this._threadStates.get(this._mainThreadId);
|
|
685
703
|
n && (n.isMain = !1, this._threadStates.set(this._mainThreadId, n), (a = this._threadItems.get(this._mainThreadId)) == null || a.updateState(n)), this._mainThreadId = t;
|
|
686
|
-
const
|
|
687
|
-
if (
|
|
704
|
+
const r = this._threadStates.get(t);
|
|
705
|
+
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)) {
|
|
688
706
|
this._isLoading = !0, this.notifySubscribers();
|
|
689
707
|
try {
|
|
690
708
|
const u = await this.config.threadListAdapter.loadThread(t);
|
|
@@ -698,12 +716,12 @@ class Z extends y {
|
|
|
698
716
|
this.notifySubscribers();
|
|
699
717
|
}
|
|
700
718
|
async switchToNewThread() {
|
|
701
|
-
const t =
|
|
719
|
+
const t = L(), e = new M({
|
|
702
720
|
streamAdapter: this.config.streamAdapter,
|
|
703
721
|
capabilityExecutionManager: this.config.capabilityExecutionManager
|
|
704
|
-
}), n = new
|
|
722
|
+
}), n = new C(e);
|
|
705
723
|
this._threads.set(t, n);
|
|
706
|
-
const
|
|
724
|
+
const r = {
|
|
707
725
|
id: t,
|
|
708
726
|
title: "New Chat",
|
|
709
727
|
status: { type: "regular" },
|
|
@@ -711,9 +729,9 @@ class Z extends y {
|
|
|
711
729
|
createdAt: Date.now(),
|
|
712
730
|
updatedAt: Date.now()
|
|
713
731
|
};
|
|
714
|
-
this._threadStates.set(t,
|
|
732
|
+
this._threadStates.set(t, r);
|
|
715
733
|
const a = new I({
|
|
716
|
-
state:
|
|
734
|
+
state: r,
|
|
717
735
|
onSwitchTo: this.switchToThread.bind(this),
|
|
718
736
|
onRename: this.renameThread.bind(this),
|
|
719
737
|
onDelete: this.deleteThread.bind(this)
|
|
@@ -723,56 +741,73 @@ class Z extends y {
|
|
|
723
741
|
}), this.config.threadListAdapter)
|
|
724
742
|
try {
|
|
725
743
|
const o = await this.config.threadListAdapter.createThread();
|
|
726
|
-
|
|
744
|
+
r.conversationId = o.conversationId, this._threadStates.set(t, r), a.updateState(r);
|
|
727
745
|
} catch (o) {
|
|
728
746
|
console.error("Failed to create thread:", o);
|
|
729
747
|
}
|
|
730
748
|
await this.switchToThread(t);
|
|
731
749
|
}
|
|
732
|
-
async loadThreads() {
|
|
750
|
+
async loadThreads(t, e = !1) {
|
|
733
751
|
if (!this.config.threadListAdapter) {
|
|
734
752
|
console.warn("No threadListAdapter configured");
|
|
735
753
|
return;
|
|
736
754
|
}
|
|
737
|
-
this.
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
this._threads.set(e.id, s), this._threadStates.set(e.id, e);
|
|
747
|
-
const a = new I({
|
|
748
|
-
state: e,
|
|
749
|
-
onSwitchTo: this.switchToThread.bind(this),
|
|
750
|
-
onRename: this.renameThread.bind(this),
|
|
751
|
-
onDelete: this.deleteThread.bind(this)
|
|
752
|
-
});
|
|
753
|
-
this._threadItems.set(e.id, a), s.subscribe(() => {
|
|
754
|
-
this.syncThreadStateFromRuntime(e.id, s), this.notifySubscribers();
|
|
755
|
+
this._abortController && this._abortController.abort(), this._abortController = new AbortController();
|
|
756
|
+
const n = t !== this._searchQuery, r = e || n;
|
|
757
|
+
if (r && (this._currentPage = 0, this._searchQuery = t, this._hasMore = !0, this._threadStates.clear(), this._threads.clear(), this._threadItems.clear()), !(!r && !this._hasMore)) {
|
|
758
|
+
r ? this._isLoading = !0 : this._isLoadingMore = !0, this.notifySubscribers();
|
|
759
|
+
try {
|
|
760
|
+
const a = await this.config.threadListAdapter.loadThreads({
|
|
761
|
+
query: this._searchQuery,
|
|
762
|
+
page: this._currentPage,
|
|
763
|
+
size: 50
|
|
755
764
|
});
|
|
765
|
+
let o, u;
|
|
766
|
+
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;
|
|
767
|
+
for (const f of o) {
|
|
768
|
+
if (this._threadStates.has(f.id))
|
|
769
|
+
continue;
|
|
770
|
+
const l = new M({
|
|
771
|
+
streamAdapter: this.config.streamAdapter,
|
|
772
|
+
capabilityExecutionManager: this.config.capabilityExecutionManager
|
|
773
|
+
}), h = new C(l);
|
|
774
|
+
this._threads.set(f.id, h), this._threadStates.set(f.id, f);
|
|
775
|
+
const d = new I({
|
|
776
|
+
state: f,
|
|
777
|
+
onSwitchTo: this.switchToThread.bind(this),
|
|
778
|
+
onRename: this.renameThread.bind(this),
|
|
779
|
+
onDelete: this.deleteThread.bind(this)
|
|
780
|
+
});
|
|
781
|
+
this._threadItems.set(f.id, d), h.subscribe(() => {
|
|
782
|
+
this.syncThreadStateFromRuntime(f.id, h), this.notifySubscribers();
|
|
783
|
+
});
|
|
784
|
+
}
|
|
785
|
+
} catch (a) {
|
|
786
|
+
a instanceof Error && a.name !== "AbortError" && console.error("Failed to load threads:", a);
|
|
787
|
+
} finally {
|
|
788
|
+
this._isLoading = !1, this._isLoadingMore = !1, this._abortController = null, this.notifySubscribers();
|
|
756
789
|
}
|
|
757
|
-
} catch (t) {
|
|
758
|
-
console.error("Failed to load threads:", t);
|
|
759
|
-
} finally {
|
|
760
|
-
this._isLoading = !1, this.notifySubscribers();
|
|
761
790
|
}
|
|
762
791
|
}
|
|
792
|
+
async loadMoreThreads() {
|
|
793
|
+
this._isLoading || this._isLoadingMore || !this._hasMore || (this._currentPage += 1, await this.loadThreads(this._searchQuery, !1));
|
|
794
|
+
}
|
|
795
|
+
async searchThreads(t) {
|
|
796
|
+
await this.loadThreads(t, !0);
|
|
797
|
+
}
|
|
763
798
|
/**
|
|
764
799
|
* Syncs conversationId and title from thread runtime to thread state
|
|
765
800
|
*/
|
|
766
801
|
syncThreadStateFromRuntime(t, e) {
|
|
767
|
-
var
|
|
802
|
+
var r;
|
|
768
803
|
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), (
|
|
804
|
+
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));
|
|
770
805
|
}
|
|
771
806
|
async renameThread(t, e) {
|
|
772
|
-
var
|
|
807
|
+
var r;
|
|
773
808
|
const n = this._threadStates.get(t);
|
|
774
809
|
if (n) {
|
|
775
|
-
if (n.title = e, n.updatedAt = Date.now(), this._threadStates.set(t, n), (
|
|
810
|
+
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)
|
|
776
811
|
try {
|
|
777
812
|
await this.config.threadListAdapter.updateThread(t, { title: e });
|
|
778
813
|
} catch (a) {
|
|
@@ -806,9 +841,9 @@ class ft extends y {
|
|
|
806
841
|
c(this, "capabilityExecutionManager");
|
|
807
842
|
c(this, "_contentFocusRuntime");
|
|
808
843
|
c(this, "_currentThreadUnsubscribe");
|
|
809
|
-
this.pluginRegistry = new
|
|
844
|
+
this.pluginRegistry = new z(), t.plugins && t.plugins.forEach((e) => {
|
|
810
845
|
this.pluginRegistry.registerPlugin(e);
|
|
811
|
-
}), this.capabilityRegistry = new
|
|
846
|
+
}), this.capabilityRegistry = new W(), this.capabilityExecutionManager = new V((e) => this.capabilityRegistry.getHandler(e)), this.threads = new Z({
|
|
812
847
|
streamAdapter: t.streamAdapter,
|
|
813
848
|
threadListAdapter: t.threadListAdapter,
|
|
814
849
|
capabilityExecutionManager: this.capabilityExecutionManager
|
|
@@ -859,40 +894,40 @@ class ft extends y {
|
|
|
859
894
|
var e;
|
|
860
895
|
if (t.length !== 0 && !this._contentFocusRuntime.isActive)
|
|
861
896
|
for (let n = t.length - 1; n >= 0; n--) {
|
|
862
|
-
const
|
|
863
|
-
if (
|
|
864
|
-
for (let a =
|
|
865
|
-
const o =
|
|
897
|
+
const r = t[n];
|
|
898
|
+
if (r.role === "assistant")
|
|
899
|
+
for (let a = r.content.length - 1; a >= 0; a--) {
|
|
900
|
+
const o = r.content[a], u = this.pluginRegistry.getRenderersByType(o.type);
|
|
866
901
|
if (u.length > 0 && ((e = u[0].capabilities) != null && e.supportsFocus)) {
|
|
867
|
-
this._contentFocusRuntime.focus(o,
|
|
902
|
+
this._contentFocusRuntime.focus(o, r, a, "detail");
|
|
868
903
|
return;
|
|
869
904
|
}
|
|
870
905
|
}
|
|
871
906
|
}
|
|
872
907
|
}
|
|
873
908
|
}
|
|
874
|
-
var
|
|
909
|
+
var R = { exports: {} }, _ = {};
|
|
875
910
|
/*
|
|
876
911
|
object-assign
|
|
877
912
|
(c) Sindre Sorhus
|
|
878
913
|
@license MIT
|
|
879
914
|
*/
|
|
880
|
-
var
|
|
915
|
+
var v, F;
|
|
881
916
|
function tt() {
|
|
882
|
-
if (
|
|
883
|
-
|
|
884
|
-
var i = Object.getOwnPropertySymbols,
|
|
885
|
-
function e(
|
|
886
|
-
if (
|
|
917
|
+
if (F) return v;
|
|
918
|
+
F = 1;
|
|
919
|
+
var i = Object.getOwnPropertySymbols, s = Object.prototype.hasOwnProperty, t = Object.prototype.propertyIsEnumerable;
|
|
920
|
+
function e(r) {
|
|
921
|
+
if (r == null)
|
|
887
922
|
throw new TypeError("Object.assign cannot be called with null or undefined");
|
|
888
|
-
return Object(
|
|
923
|
+
return Object(r);
|
|
889
924
|
}
|
|
890
925
|
function n() {
|
|
891
926
|
try {
|
|
892
927
|
if (!Object.assign)
|
|
893
928
|
return !1;
|
|
894
|
-
var
|
|
895
|
-
if (
|
|
929
|
+
var r = new String("abc");
|
|
930
|
+
if (r[5] = "de", Object.getOwnPropertyNames(r)[0] === "5")
|
|
896
931
|
return !1;
|
|
897
932
|
for (var a = {}, o = 0; o < 10; o++)
|
|
898
933
|
a["_" + String.fromCharCode(o)] = o;
|
|
@@ -909,11 +944,11 @@ function tt() {
|
|
|
909
944
|
return !1;
|
|
910
945
|
}
|
|
911
946
|
}
|
|
912
|
-
return
|
|
913
|
-
for (var o, u = e(
|
|
947
|
+
return v = n() ? Object.assign : function(r, a) {
|
|
948
|
+
for (var o, u = e(r), f, l = 1; l < arguments.length; l++) {
|
|
914
949
|
o = Object(arguments[l]);
|
|
915
950
|
for (var h in o)
|
|
916
|
-
|
|
951
|
+
s.call(o, h) && (u[h] = o[h]);
|
|
917
952
|
if (i) {
|
|
918
953
|
f = i(o);
|
|
919
954
|
for (var d = 0; d < f.length; d++)
|
|
@@ -921,7 +956,7 @@ function tt() {
|
|
|
921
956
|
}
|
|
922
957
|
}
|
|
923
958
|
return u;
|
|
924
|
-
},
|
|
959
|
+
}, v;
|
|
925
960
|
}
|
|
926
961
|
/** @license React v17.0.2
|
|
927
962
|
* react-jsx-runtime.production.min.js
|
|
@@ -931,72 +966,71 @@ function tt() {
|
|
|
931
966
|
* This source code is licensed under the MIT license found in the
|
|
932
967
|
* LICENSE file in the root directory of this source tree.
|
|
933
968
|
*/
|
|
934
|
-
var
|
|
969
|
+
var N;
|
|
935
970
|
function et() {
|
|
936
|
-
if (
|
|
937
|
-
|
|
938
|
-
var i = B,
|
|
971
|
+
if (N) return _;
|
|
972
|
+
N = 1, tt();
|
|
973
|
+
var i = B, s = 60103;
|
|
939
974
|
if (_.Fragment = 60107, typeof Symbol == "function" && Symbol.for) {
|
|
940
975
|
var t = Symbol.for;
|
|
941
|
-
|
|
976
|
+
s = t("react.element"), _.Fragment = t("react.fragment");
|
|
942
977
|
}
|
|
943
|
-
var e = i.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, n = Object.prototype.hasOwnProperty,
|
|
978
|
+
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 };
|
|
944
979
|
function a(o, u, f) {
|
|
945
|
-
var l, h = {}, d = null,
|
|
946
|
-
f !== void 0 && (d = "" + f), u.key !== void 0 && (d = "" + u.key), u.ref !== void 0 && (
|
|
947
|
-
for (l in u) n.call(u, l) && !
|
|
980
|
+
var l, h = {}, d = null, g = null;
|
|
981
|
+
f !== void 0 && (d = "" + f), u.key !== void 0 && (d = "" + u.key), u.ref !== void 0 && (g = u.ref);
|
|
982
|
+
for (l in u) n.call(u, l) && !r.hasOwnProperty(l) && (h[l] = u[l]);
|
|
948
983
|
if (o && o.defaultProps) for (l in u = o.defaultProps, u) h[l] === void 0 && (h[l] = u[l]);
|
|
949
|
-
return { $$typeof:
|
|
984
|
+
return { $$typeof: s, type: o, key: d, ref: g, props: h, _owner: e.current };
|
|
950
985
|
}
|
|
951
986
|
return _.jsx = a, _.jsxs = a, _;
|
|
952
987
|
}
|
|
953
|
-
var
|
|
988
|
+
var j;
|
|
954
989
|
function st() {
|
|
955
|
-
return
|
|
990
|
+
return j || (j = 1, R.exports = et()), R.exports;
|
|
956
991
|
}
|
|
957
992
|
var S = st();
|
|
958
|
-
const k =
|
|
959
|
-
function
|
|
960
|
-
return /* @__PURE__ */ S.jsx(k.Provider, { value: i, children:
|
|
993
|
+
const k = U(null);
|
|
994
|
+
function gt({ runtime: i, children: s }) {
|
|
995
|
+
return /* @__PURE__ */ S.jsx(k.Provider, { value: i, children: s });
|
|
961
996
|
}
|
|
962
997
|
function rt() {
|
|
963
|
-
const i =
|
|
998
|
+
const i = H(k);
|
|
964
999
|
if (!i)
|
|
965
1000
|
throw new Error("useAssistantRuntimeContext must be used within AssistantRuntimeProvider");
|
|
966
1001
|
return i;
|
|
967
1002
|
}
|
|
968
|
-
function
|
|
1003
|
+
function p() {
|
|
969
1004
|
return rt();
|
|
970
1005
|
}
|
|
971
|
-
function
|
|
972
|
-
const i =
|
|
1006
|
+
function pt() {
|
|
1007
|
+
const i = p();
|
|
973
1008
|
return {
|
|
974
|
-
switchToThread: (
|
|
1009
|
+
switchToThread: (s) => i.threads.switchToThread(s),
|
|
975
1010
|
switchToNewThread: () => i.threads.switchToNewThread(),
|
|
976
|
-
loadThreads: () =>
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
renameThread: (r, t) => {
|
|
1011
|
+
loadThreads: (s, t) => i.threads.loadThreads(s, t),
|
|
1012
|
+
loadMoreThreads: () => i.threads.loadMoreThreads(),
|
|
1013
|
+
searchThreads: (s) => i.threads.searchThreads(s),
|
|
1014
|
+
renameThread: (s, t) => {
|
|
981
1015
|
var e, n;
|
|
982
|
-
return (n = (e = i.threads).renameThread) == null ? void 0 : n.call(e,
|
|
1016
|
+
return (n = (e = i.threads).renameThread) == null ? void 0 : n.call(e, s, t);
|
|
983
1017
|
},
|
|
984
|
-
deleteThread: (
|
|
1018
|
+
deleteThread: (s) => {
|
|
985
1019
|
var t, e;
|
|
986
|
-
return (e = (t = i.threads).deleteThread) == null ? void 0 : e.call(t,
|
|
1020
|
+
return (e = (t = i.threads).deleteThread) == null ? void 0 : e.call(t, s);
|
|
987
1021
|
}
|
|
988
1022
|
};
|
|
989
1023
|
}
|
|
990
1024
|
function bt() {
|
|
991
|
-
const i =
|
|
1025
|
+
const i = p(), [s, t] = x(i.threads.getState());
|
|
992
1026
|
return w(() => i.threads.subscribe(() => {
|
|
993
1027
|
t(i.threads.getState());
|
|
994
|
-
}), [i]),
|
|
1028
|
+
}), [i]), s;
|
|
995
1029
|
}
|
|
996
1030
|
function nt() {
|
|
997
|
-
return
|
|
1031
|
+
return p().threads.getMainThread();
|
|
998
1032
|
}
|
|
999
|
-
var
|
|
1033
|
+
var E = { exports: {} }, A = {};
|
|
1000
1034
|
/**
|
|
1001
1035
|
* @license React
|
|
1002
1036
|
* use-sync-external-store-shim.production.js
|
|
@@ -1006,22 +1040,22 @@ var M = { exports: {} }, A = {};
|
|
|
1006
1040
|
* This source code is licensed under the MIT license found in the
|
|
1007
1041
|
* LICENSE file in the root directory of this source tree.
|
|
1008
1042
|
*/
|
|
1009
|
-
var
|
|
1043
|
+
var O;
|
|
1010
1044
|
function it() {
|
|
1011
|
-
if (
|
|
1012
|
-
|
|
1045
|
+
if (O) return A;
|
|
1046
|
+
O = 1;
|
|
1013
1047
|
var i = B;
|
|
1014
|
-
function
|
|
1048
|
+
function s(h, d) {
|
|
1015
1049
|
return h === d && (h !== 0 || 1 / h === 1 / d) || h !== h && d !== d;
|
|
1016
1050
|
}
|
|
1017
|
-
var t = typeof Object.is == "function" ? Object.is :
|
|
1051
|
+
var t = typeof Object.is == "function" ? Object.is : s, e = i.useState, n = i.useEffect, r = i.useLayoutEffect, a = i.useDebugValue;
|
|
1018
1052
|
function o(h, d) {
|
|
1019
|
-
var
|
|
1020
|
-
return
|
|
1053
|
+
var g = d(), m = e({ inst: { value: g, getSnapshot: d } }), b = m[0].inst, T = m[1];
|
|
1054
|
+
return r(
|
|
1021
1055
|
function() {
|
|
1022
|
-
b.value =
|
|
1056
|
+
b.value = g, b.getSnapshot = d, u(b) && T({ inst: b });
|
|
1023
1057
|
},
|
|
1024
|
-
[h,
|
|
1058
|
+
[h, g, d]
|
|
1025
1059
|
), n(
|
|
1026
1060
|
function() {
|
|
1027
1061
|
return u(b) && T({ inst: b }), h(function() {
|
|
@@ -1029,14 +1063,14 @@ function it() {
|
|
|
1029
1063
|
});
|
|
1030
1064
|
},
|
|
1031
1065
|
[h]
|
|
1032
|
-
), a(
|
|
1066
|
+
), a(g), g;
|
|
1033
1067
|
}
|
|
1034
1068
|
function u(h) {
|
|
1035
1069
|
var d = h.getSnapshot;
|
|
1036
1070
|
h = h.value;
|
|
1037
1071
|
try {
|
|
1038
|
-
var
|
|
1039
|
-
return !t(h,
|
|
1072
|
+
var g = d();
|
|
1073
|
+
return !t(h, g);
|
|
1040
1074
|
} catch {
|
|
1041
1075
|
return !0;
|
|
1042
1076
|
}
|
|
@@ -1047,30 +1081,30 @@ function it() {
|
|
|
1047
1081
|
var l = typeof window > "u" || typeof window.document > "u" || typeof window.document.createElement > "u" ? f : o;
|
|
1048
1082
|
return A.useSyncExternalStore = i.useSyncExternalStore !== void 0 ? i.useSyncExternalStore : l, A;
|
|
1049
1083
|
}
|
|
1050
|
-
var
|
|
1084
|
+
var D;
|
|
1051
1085
|
function at() {
|
|
1052
|
-
return
|
|
1086
|
+
return D || (D = 1, E.exports = it()), E.exports;
|
|
1053
1087
|
}
|
|
1054
1088
|
var ot = at();
|
|
1055
1089
|
function yt() {
|
|
1056
|
-
const i =
|
|
1090
|
+
const i = p();
|
|
1057
1091
|
return ot.useSyncExternalStore(
|
|
1058
|
-
(
|
|
1059
|
-
|
|
1092
|
+
(s) => i.subscribe(() => {
|
|
1093
|
+
s();
|
|
1060
1094
|
}),
|
|
1061
1095
|
() => i.thread.messages,
|
|
1062
1096
|
() => i.thread.messages
|
|
1063
1097
|
);
|
|
1064
1098
|
}
|
|
1065
1099
|
function mt() {
|
|
1066
|
-
const i = nt(), [
|
|
1100
|
+
const i = nt(), [s, t] = x(""), [e, n] = x(!1);
|
|
1067
1101
|
return {
|
|
1068
|
-
text:
|
|
1102
|
+
text: s,
|
|
1069
1103
|
setText: t,
|
|
1070
1104
|
isSubmitting: e,
|
|
1071
1105
|
send: async (a) => {
|
|
1072
|
-
if (a == null || a.preventDefault(), !
|
|
1073
|
-
const o =
|
|
1106
|
+
if (a == null || a.preventDefault(), !s.trim() || e) return;
|
|
1107
|
+
const o = s;
|
|
1074
1108
|
t(""), n(!0);
|
|
1075
1109
|
try {
|
|
1076
1110
|
await i.send(o);
|
|
@@ -1084,9 +1118,9 @@ function mt() {
|
|
|
1084
1118
|
append: (a) => t((o) => o + a)
|
|
1085
1119
|
};
|
|
1086
1120
|
}
|
|
1087
|
-
function q(i,
|
|
1088
|
-
var
|
|
1089
|
-
const e =
|
|
1121
|
+
function q(i, s) {
|
|
1122
|
+
var r, a, o, u;
|
|
1123
|
+
const e = p().pluginRegistry.getBestRendererForType(i);
|
|
1090
1124
|
if (!e)
|
|
1091
1125
|
return {
|
|
1092
1126
|
component: null,
|
|
@@ -1095,7 +1129,7 @@ function q(i, r) {
|
|
|
1095
1129
|
supportsPreview: !1,
|
|
1096
1130
|
supportsFullscreen: !1
|
|
1097
1131
|
};
|
|
1098
|
-
const n =
|
|
1132
|
+
const n = s ? (r = e.auxiliary) == null ? void 0 : r[s] : null;
|
|
1099
1133
|
return {
|
|
1100
1134
|
component: e.component,
|
|
1101
1135
|
auxiliaryComponent: n,
|
|
@@ -1105,46 +1139,46 @@ function q(i, r) {
|
|
|
1105
1139
|
};
|
|
1106
1140
|
}
|
|
1107
1141
|
function _t() {
|
|
1108
|
-
const i =
|
|
1142
|
+
const i = p(), [s, t] = x(i.contentFocus.state);
|
|
1109
1143
|
return w(() => i.contentFocus.subscribe(() => {
|
|
1110
1144
|
t(i.contentFocus.state);
|
|
1111
1145
|
}), [i]), {
|
|
1112
|
-
...
|
|
1113
|
-
focus: (e, n,
|
|
1146
|
+
...s,
|
|
1147
|
+
focus: (e, n, r, a) => i.contentFocus.focus(e, n, r, a),
|
|
1114
1148
|
blur: () => i.contentFocus.blur(),
|
|
1115
|
-
toggle: (e, n,
|
|
1149
|
+
toggle: (e, n, r, a) => i.contentFocus.toggle(e, n, r, a),
|
|
1116
1150
|
switchContext: (e) => i.contentFocus.switchContext(e),
|
|
1117
1151
|
focusNext: () => i.contentFocus.focusNext(i.thread.messages),
|
|
1118
1152
|
focusPrevious: () => i.contentFocus.focusPrevious(i.thread.messages)
|
|
1119
1153
|
};
|
|
1120
1154
|
}
|
|
1121
1155
|
function ut(i) {
|
|
1122
|
-
const
|
|
1123
|
-
w(() => (i.execute &&
|
|
1156
|
+
const s = p();
|
|
1157
|
+
w(() => (i.execute && s.capabilityRegistry.registerHandler(i.name, { execute: i.execute }), i.render && s.capabilityRegistry.registerRenderer(i.name, {
|
|
1124
1158
|
component: i.render
|
|
1125
1159
|
}), () => {
|
|
1126
|
-
|
|
1127
|
-
}), [i.name,
|
|
1160
|
+
s.capabilityRegistry.unregister(i.name);
|
|
1161
|
+
}), [i.name, s]);
|
|
1128
1162
|
}
|
|
1129
1163
|
function ct(i) {
|
|
1130
|
-
const
|
|
1131
|
-
() =>
|
|
1132
|
-
), [, n] = J((
|
|
1164
|
+
const s = p(), [t, e] = x(
|
|
1165
|
+
() => s.capabilityExecutionManager.getExecution(i)
|
|
1166
|
+
), [, n] = J((r) => r + 1, 0);
|
|
1133
1167
|
return w(() => {
|
|
1134
|
-
const
|
|
1135
|
-
return e(
|
|
1168
|
+
const r = s.capabilityExecutionManager.getExecution(i);
|
|
1169
|
+
return e(r), s.capabilityExecutionManager.subscribe((o) => {
|
|
1136
1170
|
if (o === i) {
|
|
1137
|
-
const u =
|
|
1171
|
+
const u = s.capabilityExecutionManager.getExecution(i);
|
|
1138
1172
|
e(u), n();
|
|
1139
1173
|
}
|
|
1140
1174
|
});
|
|
1141
|
-
}, [i,
|
|
1175
|
+
}, [i, s]), t;
|
|
1142
1176
|
}
|
|
1143
|
-
function ht({ message: i, content:
|
|
1144
|
-
const t =
|
|
1145
|
-
if (!
|
|
1177
|
+
function ht({ message: i, content: s }) {
|
|
1178
|
+
const t = p(), e = s, n = ct(e.capabilityId), r = t.capabilityRegistry.getRenderer(e.capabilityName);
|
|
1179
|
+
if (!r || !n)
|
|
1146
1180
|
return null;
|
|
1147
|
-
const a =
|
|
1181
|
+
const a = r.component;
|
|
1148
1182
|
return /* @__PURE__ */ S.jsx(
|
|
1149
1183
|
a,
|
|
1150
1184
|
{
|
|
@@ -1157,70 +1191,70 @@ function ht({ message: i, content: r }) {
|
|
|
1157
1191
|
}
|
|
1158
1192
|
);
|
|
1159
1193
|
}
|
|
1160
|
-
function xt({ message: i, content:
|
|
1161
|
-
const { component: t } = q(
|
|
1162
|
-
if (
|
|
1163
|
-
return /* @__PURE__ */ S.jsx(ht, { message: i, content:
|
|
1194
|
+
function xt({ message: i, content: s }) {
|
|
1195
|
+
const { component: t } = q(s.type);
|
|
1196
|
+
if (s.type === "capability")
|
|
1197
|
+
return /* @__PURE__ */ S.jsx(ht, { message: i, content: s });
|
|
1164
1198
|
if (!t)
|
|
1165
1199
|
return null;
|
|
1166
1200
|
const e = t;
|
|
1167
|
-
return /* @__PURE__ */ S.jsx(e, { content:
|
|
1201
|
+
return /* @__PURE__ */ S.jsx(e, { content: s, message: i });
|
|
1168
1202
|
}
|
|
1169
1203
|
function St({
|
|
1170
1204
|
message: i,
|
|
1171
|
-
content:
|
|
1205
|
+
content: s,
|
|
1172
1206
|
context: t,
|
|
1173
1207
|
onClose: e,
|
|
1174
1208
|
onNavigate: n,
|
|
1175
|
-
onSwitchContext:
|
|
1209
|
+
onSwitchContext: r
|
|
1176
1210
|
}) {
|
|
1177
|
-
const { auxiliaryComponent: a } = q(
|
|
1211
|
+
const { auxiliaryComponent: a } = q(s.type, t);
|
|
1178
1212
|
if (!a)
|
|
1179
1213
|
return null;
|
|
1180
1214
|
const o = a;
|
|
1181
1215
|
return /* @__PURE__ */ S.jsx(
|
|
1182
1216
|
o,
|
|
1183
1217
|
{
|
|
1184
|
-
content:
|
|
1218
|
+
content: s,
|
|
1185
1219
|
message: i,
|
|
1186
1220
|
context: t,
|
|
1187
1221
|
onClose: e,
|
|
1188
1222
|
onNavigate: n,
|
|
1189
|
-
onSwitchContext:
|
|
1223
|
+
onSwitchContext: r
|
|
1190
1224
|
}
|
|
1191
1225
|
);
|
|
1192
1226
|
}
|
|
1193
1227
|
function wt(i) {
|
|
1194
|
-
const
|
|
1195
|
-
return
|
|
1228
|
+
const s = () => (ut(i), null);
|
|
1229
|
+
return s.displayName = `Capability(${i.name})`, s;
|
|
1196
1230
|
}
|
|
1197
1231
|
class Tt {
|
|
1198
1232
|
getAllowedEvents() {
|
|
1199
1233
|
return null;
|
|
1200
1234
|
}
|
|
1201
|
-
shouldProcessEvent(
|
|
1235
|
+
shouldProcessEvent(s) {
|
|
1202
1236
|
const t = this.getAllowedEvents();
|
|
1203
|
-
return t ? t.includes(
|
|
1237
|
+
return t ? t.includes(s) : !0;
|
|
1204
1238
|
}
|
|
1205
|
-
async *stream(
|
|
1206
|
-
const { signal: t } =
|
|
1207
|
-
if (!
|
|
1208
|
-
throw new Error(`HTTP error! status: ${
|
|
1209
|
-
if (!
|
|
1239
|
+
async *stream(s) {
|
|
1240
|
+
const { signal: t } = s, { url: e, options: n } = this.prepareRequest(s), r = await fetch(e, { ...n, signal: t });
|
|
1241
|
+
if (!r.ok)
|
|
1242
|
+
throw new Error(`HTTP error! status: ${r.status}`);
|
|
1243
|
+
if (!r.body)
|
|
1210
1244
|
throw new Error("Response body is null");
|
|
1211
|
-
yield* this.parseSSEStream(
|
|
1245
|
+
yield* this.parseSSEStream(r.body, t);
|
|
1212
1246
|
}
|
|
1213
|
-
async *parseSSEStream(
|
|
1214
|
-
const e =
|
|
1215
|
-
let
|
|
1247
|
+
async *parseSSEStream(s, t) {
|
|
1248
|
+
const e = s.getReader(), n = new TextDecoder();
|
|
1249
|
+
let r = "", a = null;
|
|
1216
1250
|
try {
|
|
1217
1251
|
for (; ; ) {
|
|
1218
1252
|
const { done: o, value: u } = await e.read();
|
|
1219
1253
|
if (o || t != null && t.aborted) break;
|
|
1220
|
-
|
|
1221
|
-
const f =
|
|
1254
|
+
r += n.decode(u, { stream: !0 });
|
|
1255
|
+
const f = r.split(`
|
|
1222
1256
|
`);
|
|
1223
|
-
|
|
1257
|
+
r = f.pop() || "";
|
|
1224
1258
|
for (const l of f) {
|
|
1225
1259
|
const h = l.trim();
|
|
1226
1260
|
if (!h) {
|
|
@@ -1237,11 +1271,11 @@ class Tt {
|
|
|
1237
1271
|
if (d === "eof" || h === "eof")
|
|
1238
1272
|
break;
|
|
1239
1273
|
try {
|
|
1240
|
-
const
|
|
1274
|
+
const g = JSON.parse(d);
|
|
1241
1275
|
if (a && this.shouldProcessEvent(a)) {
|
|
1242
1276
|
const m = this.convertEvent({
|
|
1243
1277
|
event: a,
|
|
1244
|
-
data:
|
|
1278
|
+
data: g
|
|
1245
1279
|
});
|
|
1246
1280
|
m && (yield m);
|
|
1247
1281
|
}
|
|
@@ -1259,21 +1293,21 @@ class Tt {
|
|
|
1259
1293
|
}
|
|
1260
1294
|
export {
|
|
1261
1295
|
ft as AssistantRuntime,
|
|
1262
|
-
|
|
1296
|
+
gt as AssistantRuntimeProvider,
|
|
1263
1297
|
St as AuxiliaryRenderer,
|
|
1264
1298
|
Tt as BaseSSEStreamAdapter,
|
|
1265
1299
|
V as CapabilityExecutionManager,
|
|
1266
|
-
|
|
1300
|
+
W as CapabilityRegistry,
|
|
1267
1301
|
ht as CapabilityRendererComp,
|
|
1268
1302
|
X as ComposerRuntime,
|
|
1269
1303
|
xt as ContentRenderer,
|
|
1270
|
-
|
|
1304
|
+
z as PluginRegistry,
|
|
1271
1305
|
I as ThreadListItemRuntime,
|
|
1272
1306
|
Z as ThreadListRuntime,
|
|
1273
|
-
|
|
1274
|
-
|
|
1307
|
+
C as ThreadRuntime,
|
|
1308
|
+
M as ThreadRuntimeCore,
|
|
1275
1309
|
wt as makeCapability,
|
|
1276
|
-
|
|
1310
|
+
p as useAssistantRuntime,
|
|
1277
1311
|
ut as useCapability,
|
|
1278
1312
|
ct as useCapabilityExecution,
|
|
1279
1313
|
mt as useComposer,
|
|
@@ -1281,7 +1315,7 @@ export {
|
|
|
1281
1315
|
q as useContentRenderer,
|
|
1282
1316
|
nt as useCurrentThread,
|
|
1283
1317
|
yt as useMessages,
|
|
1284
|
-
|
|
1318
|
+
pt as useThreadList,
|
|
1285
1319
|
bt as useThreadListState
|
|
1286
1320
|
};
|
|
1287
1321
|
//# sourceMappingURL=index.js.map
|