@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,
|
|
3
|
-
var c = (i,
|
|
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(
|
|
11
|
-
this.plugins.has(
|
|
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,
|
|
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(
|
|
17
|
-
const t = this.plugins.get(
|
|
16
|
+
unregisterPlugin(r) {
|
|
17
|
+
const t = this.plugins.get(r);
|
|
18
18
|
return t ? (t.renderers.forEach((e) => {
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
}), this.plugins.delete(
|
|
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(
|
|
24
|
-
return this.plugins.get(
|
|
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(
|
|
30
|
-
return this.renderersByType.get(
|
|
29
|
+
getRenderersByType(r) {
|
|
30
|
+
return this.renderersByType.get(r) || [];
|
|
31
31
|
}
|
|
32
|
-
getBestRendererForType(
|
|
33
|
-
return this.getRenderersByType(
|
|
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(
|
|
45
|
-
this.handlers.set(
|
|
44
|
+
registerHandler(r, t) {
|
|
45
|
+
this.handlers.set(r, t);
|
|
46
46
|
}
|
|
47
|
-
registerRenderer(
|
|
48
|
-
this.renderers.set(
|
|
47
|
+
registerRenderer(r, t) {
|
|
48
|
+
this.renderers.set(r, t);
|
|
49
49
|
}
|
|
50
|
-
unregister(
|
|
51
|
-
this.handlers.delete(
|
|
50
|
+
unregister(r) {
|
|
51
|
+
this.handlers.delete(r), this.renderers.delete(r);
|
|
52
52
|
}
|
|
53
|
-
getHandler(
|
|
54
|
-
return this.handlers.get(
|
|
53
|
+
getHandler(r) {
|
|
54
|
+
return this.handlers.get(r);
|
|
55
55
|
}
|
|
56
|
-
getRenderer(
|
|
57
|
-
return this.renderers.get(
|
|
56
|
+
getRenderer(r) {
|
|
57
|
+
return this.renderers.get(r);
|
|
58
58
|
}
|
|
59
59
|
getStrategy() {
|
|
60
60
|
return "queue";
|
|
61
61
|
}
|
|
62
|
-
hasHandler(
|
|
63
|
-
return this.handlers.has(
|
|
62
|
+
hasHandler(r) {
|
|
63
|
+
return this.handlers.has(r);
|
|
64
64
|
}
|
|
65
|
-
hasRenderer(
|
|
66
|
-
return this.renderers.has(
|
|
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(
|
|
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 =
|
|
83
|
+
this.getHandler = r;
|
|
84
84
|
}
|
|
85
|
-
async executeCapability(
|
|
86
|
-
if (!this.getHandler(
|
|
87
|
-
console.warn(`No handler registered for capability: ${
|
|
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:
|
|
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),
|
|
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
|
|
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(
|
|
113
|
+
t.status = { type: "running" }, this.notifySubscribers(r);
|
|
114
114
|
const n = this.runningByName.get(t.name) || [];
|
|
115
|
-
n.push(
|
|
115
|
+
n.push(r), this.runningByName.set(t.name, n);
|
|
116
116
|
try {
|
|
117
|
-
const
|
|
117
|
+
const s = await e.execute(t.args, {
|
|
118
118
|
messageId: t.messageId,
|
|
119
|
-
capabilityId:
|
|
119
|
+
capabilityId: r
|
|
120
120
|
});
|
|
121
|
-
t.status = { type: "complete", result:
|
|
122
|
-
} catch (
|
|
123
|
-
const a =
|
|
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
|
|
127
|
-
a > -1 &&
|
|
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(
|
|
134
|
-
return this.executions.get(
|
|
133
|
+
getExecution(r) {
|
|
134
|
+
return this.executions.get(r);
|
|
135
135
|
}
|
|
136
|
-
getExecutionsByMessage(
|
|
137
|
-
return Array.from(this.executions.values()).filter((t) => t.messageId ===
|
|
136
|
+
getExecutionsByMessage(r) {
|
|
137
|
+
return Array.from(this.executions.values()).filter((t) => t.messageId === r);
|
|
138
138
|
}
|
|
139
|
-
subscribe(
|
|
140
|
-
return this.subscribers.add(
|
|
139
|
+
subscribe(r) {
|
|
140
|
+
return this.subscribers.add(r), () => this.subscribers.delete(r);
|
|
141
141
|
}
|
|
142
|
-
notifySubscribers(
|
|
143
|
-
this.subscribers.forEach((t) => t(
|
|
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(
|
|
154
|
-
return this._subscriptions.add(
|
|
155
|
-
this._subscriptions.delete(
|
|
153
|
+
subscribe(r) {
|
|
154
|
+
return this._subscriptions.add(r), () => {
|
|
155
|
+
this._subscriptions.delete(r);
|
|
156
156
|
};
|
|
157
157
|
}
|
|
158
158
|
notifySubscribers() {
|
|
159
|
-
for (const
|
|
160
|
-
|
|
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,
|
|
199
|
+
focus(t, e, n, s = "detail") {
|
|
200
200
|
this._state = {
|
|
201
201
|
isActive: !0,
|
|
202
|
-
context:
|
|
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,
|
|
220
|
-
this._state.isActive && this._state.focusedMessageId === e.id && this._state.focusedContentIndex === n && this._state.context ===
|
|
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],
|
|
233
|
-
if (
|
|
234
|
-
const a = n.content[
|
|
235
|
-
this.focus(a, n,
|
|
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],
|
|
248
|
-
if (
|
|
249
|
-
const a = n.content[
|
|
250
|
-
this.focus(a, n,
|
|
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
|
|
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
|
|
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 (
|
|
471
|
-
if (
|
|
476
|
+
} catch (s) {
|
|
477
|
+
if (s instanceof Error && s.name === "AbortError")
|
|
472
478
|
this.updateMessageStatus(e, { type: "cancelled" });
|
|
473
479
|
else {
|
|
474
|
-
const a =
|
|
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
|
|
493
|
+
const s = this._messages[n];
|
|
488
494
|
if (e.type === "part-start")
|
|
489
|
-
this.handlePartStart(
|
|
495
|
+
this.handlePartStart(s, e);
|
|
490
496
|
else if (e.type === "text-delta" || e.type === "assistant_thought")
|
|
491
|
-
this.handleTextDelta(
|
|
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
|
-
|
|
497
|
-
...
|
|
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
|
-
|
|
504
|
-
...
|
|
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
|
-
|
|
521
|
-
...
|
|
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
|
-
|
|
530
|
-
...
|
|
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
|
-
{ ...
|
|
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
|
|
553
|
+
let s;
|
|
548
554
|
switch (e.part.type) {
|
|
549
555
|
case "assistant_thought":
|
|
550
|
-
|
|
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
|
-
|
|
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
|
-
|
|
570
|
+
s = {
|
|
565
571
|
type: e.part.type,
|
|
566
572
|
parentId: e.part.parentId
|
|
567
573
|
};
|
|
568
574
|
}
|
|
569
|
-
t.content = [...t.content,
|
|
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
|
|
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(
|
|
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
|
|
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,
|
|
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,
|
|
659
|
-
e[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
|
|
675
|
-
if (
|
|
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
|
|
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,
|
|
714
|
+
this._threadStates.set(t, s);
|
|
703
715
|
const a = new I({
|
|
704
|
-
state:
|
|
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
|
-
|
|
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
|
-
}),
|
|
734
|
-
this._threads.set(e.id,
|
|
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),
|
|
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
|
|
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), (
|
|
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
|
|
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
|
|
843
|
-
if (
|
|
844
|
-
for (let a =
|
|
845
|
-
const o =
|
|
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,
|
|
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,
|
|
865
|
-
function e(
|
|
866
|
-
if (
|
|
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(
|
|
888
|
+
return Object(s);
|
|
869
889
|
}
|
|
870
890
|
function n() {
|
|
871
891
|
try {
|
|
872
892
|
if (!Object.assign)
|
|
873
893
|
return !1;
|
|
874
|
-
var
|
|
875
|
-
if (
|
|
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
|
|
904
|
+
var f = {};
|
|
885
905
|
return "abcdefghijklmnopqrst".split("").forEach(function(l) {
|
|
886
|
-
|
|
887
|
-
}), Object.keys(Object.assign({},
|
|
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(
|
|
893
|
-
for (var o, u = e(
|
|
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
|
-
|
|
916
|
+
r.call(o, h) && (u[h] = o[h]);
|
|
897
917
|
if (i) {
|
|
898
|
-
|
|
899
|
-
for (var d = 0; d <
|
|
900
|
-
t.call(o,
|
|
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,
|
|
938
|
+
var i = B, r = 60103;
|
|
919
939
|
if (_.Fragment = 60107, typeof Symbol == "function" && Symbol.for) {
|
|
920
940
|
var t = Symbol.for;
|
|
921
|
-
|
|
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,
|
|
924
|
-
function a(o, u,
|
|
925
|
-
var l, h = {}, d = null,
|
|
926
|
-
|
|
927
|
-
for (l in u) n.call(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:
|
|
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
|
|
940
|
-
return /* @__PURE__ */ S.jsx(k.Provider, { value: i, children:
|
|
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: (
|
|
974
|
+
switchToThread: (r) => i.threads.switchToThread(r),
|
|
955
975
|
switchToNewThread: () => i.threads.switchToNewThread(),
|
|
956
976
|
loadThreads: () => {
|
|
957
|
-
var
|
|
958
|
-
return (t = (
|
|
977
|
+
var r, t;
|
|
978
|
+
return (t = (r = i.threads).loadThreads) == null ? void 0 : t.call(r);
|
|
959
979
|
},
|
|
960
|
-
renameThread: (
|
|
980
|
+
renameThread: (r, t) => {
|
|
961
981
|
var e, n;
|
|
962
|
-
return (n = (e = i.threads).renameThread) == null ? void 0 : n.call(e,
|
|
982
|
+
return (n = (e = i.threads).renameThread) == null ? void 0 : n.call(e, r, t);
|
|
963
983
|
},
|
|
964
|
-
deleteThread: (
|
|
984
|
+
deleteThread: (r) => {
|
|
965
985
|
var t, e;
|
|
966
|
-
return (e = (t = i.threads).deleteThread) == null ? void 0 : e.call(t,
|
|
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(), [
|
|
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]),
|
|
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
|
|
1009
|
+
var D;
|
|
990
1010
|
function it() {
|
|
991
|
-
if (
|
|
992
|
-
|
|
1011
|
+
if (D) return A;
|
|
1012
|
+
D = 1;
|
|
993
1013
|
var i = B;
|
|
994
|
-
function
|
|
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 :
|
|
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
|
|
1000
|
-
return
|
|
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 =
|
|
1022
|
+
b.value = p, b.getSnapshot = d, u(b) && T({ inst: b });
|
|
1003
1023
|
},
|
|
1004
|
-
[h,
|
|
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(
|
|
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
|
|
1019
|
-
return !t(h,
|
|
1038
|
+
var p = d();
|
|
1039
|
+
return !t(h, p);
|
|
1020
1040
|
} catch {
|
|
1021
1041
|
return !0;
|
|
1022
1042
|
}
|
|
1023
1043
|
}
|
|
1024
|
-
function
|
|
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" ?
|
|
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
|
|
1050
|
+
var N;
|
|
1031
1051
|
function at() {
|
|
1032
|
-
return
|
|
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
|
-
(
|
|
1039
|
-
|
|
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(), [
|
|
1066
|
+
const i = nt(), [r, t] = x(""), [e, n] = x(!1);
|
|
1047
1067
|
return {
|
|
1048
|
-
text:
|
|
1068
|
+
text: r,
|
|
1049
1069
|
setText: t,
|
|
1050
1070
|
isSubmitting: e,
|
|
1051
1071
|
send: async (a) => {
|
|
1052
|
-
if (a == null || a.preventDefault(), !
|
|
1053
|
-
const o =
|
|
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,
|
|
1068
|
-
var
|
|
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 =
|
|
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(), [
|
|
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
|
-
...
|
|
1093
|
-
focus: (e, n,
|
|
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,
|
|
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
|
|
1103
|
-
w(() => (i.execute &&
|
|
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
|
-
|
|
1107
|
-
}), [i.name,
|
|
1126
|
+
r.capabilityRegistry.unregister(i.name);
|
|
1127
|
+
}), [i.name, r]);
|
|
1108
1128
|
}
|
|
1109
1129
|
function ct(i) {
|
|
1110
|
-
const
|
|
1111
|
-
() =>
|
|
1112
|
-
), [, n] = J((
|
|
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
|
|
1115
|
-
return e(
|
|
1134
|
+
const s = r.capabilityExecutionManager.getExecution(i);
|
|
1135
|
+
return e(s), r.capabilityExecutionManager.subscribe((o) => {
|
|
1116
1136
|
if (o === i) {
|
|
1117
|
-
const u =
|
|
1137
|
+
const u = r.capabilityExecutionManager.getExecution(i);
|
|
1118
1138
|
e(u), n();
|
|
1119
1139
|
}
|
|
1120
1140
|
});
|
|
1121
|
-
}, [i,
|
|
1141
|
+
}, [i, r]), t;
|
|
1122
1142
|
}
|
|
1123
|
-
function ht({ message: i, content:
|
|
1124
|
-
const t = g(), e =
|
|
1125
|
-
if (!
|
|
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 =
|
|
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:
|
|
1141
|
-
const { component: t } = q(
|
|
1142
|
-
if (
|
|
1143
|
-
return /* @__PURE__ */ S.jsx(ht, { message: i, content:
|
|
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:
|
|
1167
|
+
return /* @__PURE__ */ S.jsx(e, { content: r, message: i });
|
|
1148
1168
|
}
|
|
1149
1169
|
function St({
|
|
1150
1170
|
message: i,
|
|
1151
|
-
content:
|
|
1171
|
+
content: r,
|
|
1152
1172
|
context: t,
|
|
1153
1173
|
onClose: e,
|
|
1154
1174
|
onNavigate: n,
|
|
1155
|
-
onSwitchContext:
|
|
1175
|
+
onSwitchContext: s
|
|
1156
1176
|
}) {
|
|
1157
|
-
const { auxiliaryComponent: a } = q(
|
|
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:
|
|
1184
|
+
content: r,
|
|
1165
1185
|
message: i,
|
|
1166
1186
|
context: t,
|
|
1167
1187
|
onClose: e,
|
|
1168
1188
|
onNavigate: n,
|
|
1169
|
-
onSwitchContext:
|
|
1189
|
+
onSwitchContext: s
|
|
1170
1190
|
}
|
|
1171
1191
|
);
|
|
1172
1192
|
}
|
|
1173
1193
|
function wt(i) {
|
|
1174
|
-
const
|
|
1175
|
-
return
|
|
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(
|
|
1201
|
+
shouldProcessEvent(r) {
|
|
1182
1202
|
const t = this.getAllowedEvents();
|
|
1183
|
-
return t ? t.includes(
|
|
1203
|
+
return t ? t.includes(r) : !0;
|
|
1184
1204
|
}
|
|
1185
|
-
async *stream(
|
|
1186
|
-
const { signal: t } =
|
|
1187
|
-
if (!
|
|
1188
|
-
throw new Error(`HTTP error! status: ${
|
|
1189
|
-
if (!
|
|
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(
|
|
1211
|
+
yield* this.parseSSEStream(s.body, t);
|
|
1192
1212
|
}
|
|
1193
|
-
async *parseSSEStream(
|
|
1194
|
-
const e =
|
|
1195
|
-
let
|
|
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
|
-
|
|
1201
|
-
const
|
|
1220
|
+
s += n.decode(u, { stream: !0 });
|
|
1221
|
+
const f = s.split(`
|
|
1202
1222
|
`);
|
|
1203
|
-
|
|
1204
|
-
for (const l of
|
|
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
|
|
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:
|
|
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
|
-
|
|
1242
|
-
|
|
1261
|
+
ft as AssistantRuntime,
|
|
1262
|
+
pt as AssistantRuntimeProvider,
|
|
1243
1263
|
St as AuxiliaryRenderer,
|
|
1244
1264
|
Tt as BaseSSEStreamAdapter,
|
|
1245
1265
|
V as CapabilityExecutionManager,
|