@harnessio/ai-chat-core 0.0.2 → 0.0.3
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/CapabilityExecutionManager.d.ts +17 -0
- package/dist/core/CapabilityRegistry.d.ts +15 -0
- package/dist/core/index.d.ts +2 -0
- package/dist/index.js +711 -528
- package/dist/index.js.map +1 -1
- package/dist/react/components/CapabilityRenderer.d.ts +6 -0
- package/dist/react/components/index.d.ts +1 -0
- package/dist/react/hooks/index.d.ts +2 -0
- package/dist/react/hooks/useCapability.d.ts +2 -0
- package/dist/react/hooks/useCapabilityExecution.d.ts +2 -0
- package/dist/react/index.d.ts +1 -0
- package/dist/react/utils/index.d.ts +1 -0
- package/dist/react/utils/makeCapability.d.ts +3 -0
- package/dist/runtime/AssistantRuntime/AssistantRuntime.d.ts +3 -0
- package/dist/runtime/ThreadListRuntime/ThreadListRuntime.d.ts +2 -0
- package/dist/runtime/ThreadRuntime/ThreadRuntimeCore.d.ts +2 -0
- package/dist/types/adapters.d.ts +6 -0
- package/dist/types/capability.d.ts +53 -0
- package/dist/types/index.d.ts +1 -0
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -1,62 +1,172 @@
|
|
|
1
1
|
var $ = Object.defineProperty;
|
|
2
|
-
var U = (
|
|
3
|
-
var
|
|
4
|
-
import
|
|
5
|
-
class
|
|
2
|
+
var U = (i, s, e) => s in i ? $(i, s, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[s] = e;
|
|
3
|
+
var c = (i, s, e) => U(i, typeof s != "symbol" ? s + "" : s, e);
|
|
4
|
+
import B, { createContext as H, useContext as Q, useState as x, useEffect as w, useReducer as J } from "react";
|
|
5
|
+
class W {
|
|
6
6
|
constructor() {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
c(this, "plugins", /* @__PURE__ */ new Map());
|
|
8
|
+
c(this, "renderersByType", /* @__PURE__ */ new Map());
|
|
9
9
|
}
|
|
10
|
-
registerPlugin(
|
|
11
|
-
this.plugins.has(
|
|
12
|
-
const
|
|
13
|
-
|
|
10
|
+
registerPlugin(s) {
|
|
11
|
+
this.plugins.has(s.id), this.plugins.set(s.id, s), s.renderers.forEach((e) => {
|
|
12
|
+
const t = this.renderersByType.get(e.type) || [];
|
|
13
|
+
t.push(e), t.sort((n, r) => ((r == null ? void 0 : r.priority) ?? 0) - ((n == null ? void 0 : n.priority) ?? 0)), this.renderersByType.set(e.type, t);
|
|
14
14
|
});
|
|
15
15
|
}
|
|
16
|
-
unregisterPlugin(
|
|
17
|
-
const
|
|
18
|
-
return
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
}), this.plugins.delete(
|
|
16
|
+
unregisterPlugin(s) {
|
|
17
|
+
const e = this.plugins.get(s);
|
|
18
|
+
return e ? (e.renderers.forEach((t) => {
|
|
19
|
+
const r = (this.renderersByType.get(t.type) || []).filter((a) => !e.renderers.includes(a));
|
|
20
|
+
r.length === 0 ? this.renderersByType.delete(t.type) : this.renderersByType.set(t.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 z {
|
|
40
|
+
constructor() {
|
|
41
|
+
c(this, "handlers", /* @__PURE__ */ new Map());
|
|
42
|
+
c(this, "renderers", /* @__PURE__ */ new Map());
|
|
43
|
+
}
|
|
44
|
+
registerHandler(s, e) {
|
|
45
|
+
this.handlers.set(s, e);
|
|
46
|
+
}
|
|
47
|
+
registerRenderer(s, e) {
|
|
48
|
+
this.renderers.set(s, e);
|
|
49
|
+
}
|
|
50
|
+
unregister(s) {
|
|
51
|
+
this.handlers.delete(s), this.renderers.delete(s);
|
|
52
|
+
}
|
|
53
|
+
getHandler(s) {
|
|
54
|
+
return this.handlers.get(s);
|
|
55
|
+
}
|
|
56
|
+
getRenderer(s) {
|
|
57
|
+
return this.renderers.get(s);
|
|
58
|
+
}
|
|
59
|
+
getStrategy() {
|
|
60
|
+
return "queue";
|
|
61
|
+
}
|
|
62
|
+
hasHandler(s) {
|
|
63
|
+
return this.handlers.has(s);
|
|
64
|
+
}
|
|
65
|
+
hasRenderer(s) {
|
|
66
|
+
return this.renderers.has(s);
|
|
67
|
+
}
|
|
68
|
+
clear() {
|
|
69
|
+
this.handlers.clear(), this.renderers.clear();
|
|
70
|
+
}
|
|
71
|
+
getAllCapabilityNames() {
|
|
72
|
+
return Array.from(/* @__PURE__ */ new Set([...this.handlers.keys(), ...this.renderers.keys()]));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
class V {
|
|
76
|
+
constructor(s) {
|
|
77
|
+
c(this, "executions", /* @__PURE__ */ new Map());
|
|
78
|
+
c(this, "executionQueue", []);
|
|
79
|
+
c(this, "isProcessing", !1);
|
|
80
|
+
c(this, "runningByName", /* @__PURE__ */ new Map());
|
|
81
|
+
c(this, "subscribers", /* @__PURE__ */ new Set());
|
|
82
|
+
c(this, "getHandler");
|
|
83
|
+
this.getHandler = s;
|
|
84
|
+
}
|
|
85
|
+
async executeCapability(s, e, t, n, r = "queue") {
|
|
86
|
+
if (!this.getHandler(s)) {
|
|
87
|
+
console.warn(`No handler registered for capability: ${s}`);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const o = {
|
|
91
|
+
id: e,
|
|
92
|
+
name: s,
|
|
93
|
+
args: t,
|
|
94
|
+
status: { type: "queued" },
|
|
95
|
+
timestamp: Date.now(),
|
|
96
|
+
messageId: n
|
|
97
|
+
};
|
|
98
|
+
switch (this.executions.set(e, o), this.notifySubscribers(e), r) {
|
|
99
|
+
case "queue":
|
|
100
|
+
default:
|
|
101
|
+
this.executionQueue.push(e);
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
this.isProcessing || this.processQueue();
|
|
105
|
+
}
|
|
106
|
+
async processQueue() {
|
|
107
|
+
if (!(this.isProcessing || this.executionQueue.length === 0)) {
|
|
108
|
+
for (this.isProcessing = !0; this.executionQueue.length > 0; ) {
|
|
109
|
+
const s = this.executionQueue.shift(), e = this.executions.get(s);
|
|
110
|
+
if (!e) continue;
|
|
111
|
+
const t = this.getHandler(e.name);
|
|
112
|
+
if (!t) continue;
|
|
113
|
+
e.status = { type: "running" }, this.notifySubscribers(s);
|
|
114
|
+
const n = this.runningByName.get(e.name) || [];
|
|
115
|
+
n.push(s), this.runningByName.set(e.name, n);
|
|
116
|
+
try {
|
|
117
|
+
const r = await t.execute(e.args, {
|
|
118
|
+
messageId: e.messageId,
|
|
119
|
+
capabilityId: s
|
|
120
|
+
});
|
|
121
|
+
e.status = { type: "complete", result: r }, e.result = r;
|
|
122
|
+
} catch (r) {
|
|
123
|
+
const a = r instanceof Error ? r.message : "Unknown error";
|
|
124
|
+
e.status = { type: "error", error: a }, e.error = a;
|
|
125
|
+
} finally {
|
|
126
|
+
const r = this.runningByName.get(e.name) || [], a = r.indexOf(s);
|
|
127
|
+
a > -1 && r.splice(a, 1), r.length === 0 ? this.runningByName.delete(e.name) : this.runningByName.set(e.name, r), this.notifySubscribers(s);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
this.isProcessing = !1;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
getExecution(s) {
|
|
134
|
+
return this.executions.get(s);
|
|
135
|
+
}
|
|
136
|
+
getExecutionsByMessage(s) {
|
|
137
|
+
return Array.from(this.executions.values()).filter((e) => e.messageId === s);
|
|
138
|
+
}
|
|
139
|
+
subscribe(s) {
|
|
140
|
+
return this.subscribers.add(s), () => this.subscribers.delete(s);
|
|
141
|
+
}
|
|
142
|
+
notifySubscribers(s) {
|
|
143
|
+
this.subscribers.forEach((e) => e(s));
|
|
144
|
+
}
|
|
145
|
+
clear() {
|
|
146
|
+
this.executions.clear(), this.executionQueue = [], this.runningByName.clear();
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
class y {
|
|
40
150
|
constructor() {
|
|
41
|
-
|
|
151
|
+
c(this, "_subscriptions", /* @__PURE__ */ new Set());
|
|
42
152
|
}
|
|
43
|
-
subscribe(
|
|
44
|
-
return this._subscriptions.add(
|
|
45
|
-
this._subscriptions.delete(
|
|
153
|
+
subscribe(s) {
|
|
154
|
+
return this._subscriptions.add(s), () => {
|
|
155
|
+
this._subscriptions.delete(s);
|
|
46
156
|
};
|
|
47
157
|
}
|
|
48
158
|
notifySubscribers() {
|
|
49
|
-
for (const
|
|
50
|
-
|
|
159
|
+
for (const s of this._subscriptions)
|
|
160
|
+
s();
|
|
51
161
|
}
|
|
52
162
|
getSubscriberCount() {
|
|
53
163
|
return this._subscriptions.size;
|
|
54
164
|
}
|
|
55
165
|
}
|
|
56
|
-
class
|
|
166
|
+
class G extends y {
|
|
57
167
|
constructor() {
|
|
58
168
|
super(...arguments);
|
|
59
|
-
|
|
169
|
+
c(this, "_state", {
|
|
60
170
|
isActive: !1,
|
|
61
171
|
context: null,
|
|
62
172
|
focusedContent: null,
|
|
@@ -86,14 +196,14 @@ class V extends m {
|
|
|
86
196
|
get focusedContentIndex() {
|
|
87
197
|
return this._state.focusedContentIndex;
|
|
88
198
|
}
|
|
89
|
-
focus(t,
|
|
199
|
+
focus(e, t, n, r = "detail") {
|
|
90
200
|
this._state = {
|
|
91
201
|
isActive: !0,
|
|
92
|
-
context:
|
|
93
|
-
focusedContent:
|
|
94
|
-
focusedMessage:
|
|
95
|
-
focusedMessageId:
|
|
96
|
-
focusedContentIndex:
|
|
202
|
+
context: r,
|
|
203
|
+
focusedContent: e,
|
|
204
|
+
focusedMessage: t,
|
|
205
|
+
focusedMessageId: t.id,
|
|
206
|
+
focusedContentIndex: n
|
|
97
207
|
}, this.notifySubscribers();
|
|
98
208
|
}
|
|
99
209
|
blur() {
|
|
@@ -106,61 +216,61 @@ class V extends m {
|
|
|
106
216
|
focusedContentIndex: null
|
|
107
217
|
}, this.notifySubscribers();
|
|
108
218
|
}
|
|
109
|
-
toggle(t,
|
|
110
|
-
this._state.isActive && this._state.focusedMessageId ===
|
|
219
|
+
toggle(e, t, n, r = "detail") {
|
|
220
|
+
this._state.isActive && this._state.focusedMessageId === t.id && this._state.focusedContentIndex === n && this._state.context === r ? this.blur() : this.focus(e, t, n, r);
|
|
111
221
|
}
|
|
112
|
-
switchContext(
|
|
222
|
+
switchContext(e) {
|
|
113
223
|
this._state.isActive && this._state.focusedContent && (this._state = {
|
|
114
224
|
...this._state,
|
|
115
|
-
context:
|
|
225
|
+
context: e
|
|
116
226
|
}, this.notifySubscribers());
|
|
117
227
|
}
|
|
118
|
-
focusNext(
|
|
119
|
-
if (!this._state.focusedMessageId || !
|
|
120
|
-
const
|
|
121
|
-
if (
|
|
122
|
-
const
|
|
123
|
-
if (
|
|
124
|
-
const
|
|
125
|
-
this.focus(
|
|
228
|
+
focusNext(e) {
|
|
229
|
+
if (!this._state.focusedMessageId || !e.length) return;
|
|
230
|
+
const t = e.findIndex((a) => a.id === this._state.focusedMessageId);
|
|
231
|
+
if (t === -1) return;
|
|
232
|
+
const n = e[t], 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");
|
|
126
236
|
return;
|
|
127
237
|
}
|
|
128
|
-
if (
|
|
129
|
-
const
|
|
130
|
-
|
|
238
|
+
if (t + 1 < e.length) {
|
|
239
|
+
const a = e[t + 1];
|
|
240
|
+
a.content.length > 0 && this.focus(a.content[0], a, 0, this._state.context || "detail");
|
|
131
241
|
}
|
|
132
242
|
}
|
|
133
|
-
focusPrevious(
|
|
134
|
-
if (!this._state.focusedMessageId || !
|
|
135
|
-
const
|
|
136
|
-
if (
|
|
137
|
-
const
|
|
138
|
-
if (
|
|
139
|
-
const
|
|
140
|
-
this.focus(
|
|
243
|
+
focusPrevious(e) {
|
|
244
|
+
if (!this._state.focusedMessageId || !e.length) return;
|
|
245
|
+
const t = e.findIndex((a) => a.id === this._state.focusedMessageId);
|
|
246
|
+
if (t === -1) return;
|
|
247
|
+
const n = e[t], 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");
|
|
141
251
|
return;
|
|
142
252
|
}
|
|
143
|
-
if (
|
|
144
|
-
const
|
|
145
|
-
if (
|
|
146
|
-
const o =
|
|
147
|
-
this.focus(
|
|
253
|
+
if (t > 0) {
|
|
254
|
+
const a = e[t - 1];
|
|
255
|
+
if (a.content.length > 0) {
|
|
256
|
+
const o = a.content.length - 1;
|
|
257
|
+
this.focus(a.content[o], a, o, this._state.context || "detail");
|
|
148
258
|
}
|
|
149
259
|
}
|
|
150
260
|
}
|
|
151
261
|
}
|
|
152
|
-
let
|
|
153
|
-
function E() {
|
|
154
|
-
return `msg-${Date.now()}-${++G}`;
|
|
155
|
-
}
|
|
262
|
+
let Y = 0, K = 0;
|
|
156
263
|
function P() {
|
|
157
|
-
return `
|
|
264
|
+
return `msg-${Date.now()}-${++Y}`;
|
|
265
|
+
}
|
|
266
|
+
function F() {
|
|
267
|
+
return `thread-${Date.now()}-${++K}`;
|
|
158
268
|
}
|
|
159
|
-
class
|
|
160
|
-
constructor(
|
|
269
|
+
class R extends y {
|
|
270
|
+
constructor(e) {
|
|
161
271
|
super();
|
|
162
|
-
|
|
163
|
-
this.config =
|
|
272
|
+
c(this, "_state");
|
|
273
|
+
this.config = e, this._state = e.state;
|
|
164
274
|
}
|
|
165
275
|
get state() {
|
|
166
276
|
return this._state;
|
|
@@ -168,27 +278,27 @@ class T extends m {
|
|
|
168
278
|
getState() {
|
|
169
279
|
return this._state;
|
|
170
280
|
}
|
|
171
|
-
updateState(
|
|
172
|
-
this._state =
|
|
281
|
+
updateState(e) {
|
|
282
|
+
this._state = e, this.notifySubscribers();
|
|
173
283
|
}
|
|
174
284
|
async switchTo() {
|
|
175
285
|
await this.config.onSwitchTo(this._state.id);
|
|
176
286
|
}
|
|
177
|
-
async rename(
|
|
178
|
-
await this.config.onRename(this._state.id,
|
|
287
|
+
async rename(e) {
|
|
288
|
+
await this.config.onRename(this._state.id, e);
|
|
179
289
|
}
|
|
180
290
|
async delete() {
|
|
181
291
|
await this.config.onDelete(this._state.id);
|
|
182
292
|
}
|
|
183
|
-
subscribe(
|
|
184
|
-
return super.subscribe(
|
|
293
|
+
subscribe(e) {
|
|
294
|
+
return super.subscribe(e);
|
|
185
295
|
}
|
|
186
296
|
}
|
|
187
|
-
class
|
|
297
|
+
class X extends y {
|
|
188
298
|
constructor() {
|
|
189
299
|
super(...arguments);
|
|
190
|
-
|
|
191
|
-
|
|
300
|
+
c(this, "_text", "");
|
|
301
|
+
c(this, "_isSubmitting", !1);
|
|
192
302
|
}
|
|
193
303
|
get text() {
|
|
194
304
|
return this._text;
|
|
@@ -202,21 +312,21 @@ class Y extends m {
|
|
|
202
312
|
isSubmitting: this._isSubmitting
|
|
203
313
|
};
|
|
204
314
|
}
|
|
205
|
-
setText(
|
|
206
|
-
this._text =
|
|
315
|
+
setText(e) {
|
|
316
|
+
this._text = e, this.notifySubscribers();
|
|
207
317
|
}
|
|
208
318
|
clear() {
|
|
209
319
|
this._text = "", this.notifySubscribers();
|
|
210
320
|
}
|
|
211
|
-
setSubmitting(
|
|
212
|
-
this._isSubmitting =
|
|
321
|
+
setSubmitting(e) {
|
|
322
|
+
this._isSubmitting = e, this.notifySubscribers();
|
|
213
323
|
}
|
|
214
324
|
}
|
|
215
|
-
class
|
|
216
|
-
constructor(
|
|
325
|
+
class C extends y {
|
|
326
|
+
constructor(e) {
|
|
217
327
|
super();
|
|
218
|
-
|
|
219
|
-
this._core =
|
|
328
|
+
c(this, "composer");
|
|
329
|
+
this._core = e, this.composer = new X(), this._core.subscribe(() => {
|
|
220
330
|
this.notifySubscribers();
|
|
221
331
|
});
|
|
222
332
|
}
|
|
@@ -241,16 +351,16 @@ class x extends m {
|
|
|
241
351
|
capabilities: this._core.capabilities
|
|
242
352
|
};
|
|
243
353
|
}
|
|
244
|
-
append(
|
|
245
|
-
this._core.append(
|
|
354
|
+
append(e) {
|
|
355
|
+
this._core.append(e);
|
|
246
356
|
}
|
|
247
|
-
async send(
|
|
248
|
-
if (
|
|
357
|
+
async send(e) {
|
|
358
|
+
if (e.trim()) {
|
|
249
359
|
this.composer.setSubmitting(!0);
|
|
250
360
|
try {
|
|
251
361
|
this.composer.clear(), await this._core.startRun({
|
|
252
362
|
role: "user",
|
|
253
|
-
content: [{ type: "text", data:
|
|
363
|
+
content: [{ type: "text", data: e }]
|
|
254
364
|
});
|
|
255
365
|
} catch {
|
|
256
366
|
} finally {
|
|
@@ -264,23 +374,23 @@ class x extends m {
|
|
|
264
374
|
clear() {
|
|
265
375
|
this._core.clear();
|
|
266
376
|
}
|
|
267
|
-
reset(
|
|
268
|
-
this._core.reset(
|
|
377
|
+
reset(e = []) {
|
|
378
|
+
this._core.reset(e);
|
|
269
379
|
}
|
|
270
|
-
subscribe(
|
|
271
|
-
return super.subscribe(
|
|
380
|
+
subscribe(e) {
|
|
381
|
+
return super.subscribe(e);
|
|
272
382
|
}
|
|
273
383
|
}
|
|
274
|
-
class
|
|
275
|
-
constructor(
|
|
384
|
+
class E extends y {
|
|
385
|
+
constructor(e) {
|
|
276
386
|
super();
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
387
|
+
c(this, "_messages", []);
|
|
388
|
+
c(this, "_isRunning", !1);
|
|
389
|
+
c(this, "_isDisabled", !1);
|
|
390
|
+
c(this, "_abortController", null);
|
|
281
391
|
// Track current part being accumulated
|
|
282
|
-
|
|
283
|
-
this.config =
|
|
392
|
+
c(this, "_currentPart", null);
|
|
393
|
+
this.config = e, e.initialMessages && (this._messages = [...e.initialMessages]);
|
|
284
394
|
}
|
|
285
395
|
get messages() {
|
|
286
396
|
return this._messages;
|
|
@@ -301,89 +411,106 @@ class R extends m {
|
|
|
301
411
|
feedback: !1
|
|
302
412
|
};
|
|
303
413
|
}
|
|
304
|
-
updateMessages(
|
|
305
|
-
var
|
|
306
|
-
this._messages =
|
|
307
|
-
}
|
|
308
|
-
append(
|
|
309
|
-
const
|
|
310
|
-
id:
|
|
311
|
-
parentId:
|
|
312
|
-
role:
|
|
313
|
-
content:
|
|
314
|
-
status:
|
|
315
|
-
timestamp:
|
|
316
|
-
metadata:
|
|
414
|
+
updateMessages(e) {
|
|
415
|
+
var t, n;
|
|
416
|
+
this._messages = e, (n = (t = this.config).onMessagesChange) == null || n.call(t, this._messages), this.notifySubscribers();
|
|
417
|
+
}
|
|
418
|
+
append(e) {
|
|
419
|
+
const t = {
|
|
420
|
+
id: e.id || P(),
|
|
421
|
+
parentId: e.parentId,
|
|
422
|
+
role: e.role,
|
|
423
|
+
content: e.content,
|
|
424
|
+
status: e.status || { type: "complete" },
|
|
425
|
+
timestamp: e.timestamp || Date.now(),
|
|
426
|
+
metadata: e.metadata
|
|
317
427
|
};
|
|
318
|
-
this.updateMessages([...this._messages,
|
|
428
|
+
this.updateMessages([...this._messages, t]);
|
|
319
429
|
}
|
|
320
|
-
async startRun(
|
|
430
|
+
async startRun(e) {
|
|
321
431
|
if (this._isRunning)
|
|
322
432
|
throw new Error("A run is already in progress");
|
|
323
|
-
this.append(
|
|
324
|
-
const
|
|
325
|
-
id:
|
|
433
|
+
this.append(e), this._isRunning = !0, this._abortController = new AbortController(), this._currentPart = null;
|
|
434
|
+
const t = P(), n = {
|
|
435
|
+
id: t,
|
|
326
436
|
role: "assistant",
|
|
327
437
|
content: [],
|
|
328
438
|
status: { type: "running" },
|
|
329
439
|
timestamp: Date.now()
|
|
330
440
|
};
|
|
331
|
-
this.updateMessages([...this._messages,
|
|
441
|
+
this.updateMessages([...this._messages, n]);
|
|
332
442
|
try {
|
|
333
|
-
const
|
|
443
|
+
const r = this.config.streamAdapter.stream({
|
|
334
444
|
messages: this._messages,
|
|
335
445
|
signal: this._abortController.signal
|
|
336
446
|
});
|
|
337
|
-
for await (const
|
|
447
|
+
for await (const a of r) {
|
|
338
448
|
if (this._abortController.signal.aborted)
|
|
339
449
|
break;
|
|
340
|
-
this.handleStreamEvent(
|
|
450
|
+
this.handleStreamEvent(t, a.event);
|
|
341
451
|
}
|
|
342
|
-
this.updateMessageStatus(
|
|
343
|
-
} catch (
|
|
344
|
-
if (
|
|
345
|
-
this.updateMessageStatus(
|
|
452
|
+
this.updateMessageStatus(t, { type: "complete" });
|
|
453
|
+
} catch (r) {
|
|
454
|
+
if (r instanceof Error && r.name === "AbortError")
|
|
455
|
+
this.updateMessageStatus(t, { type: "cancelled" });
|
|
346
456
|
else {
|
|
347
|
-
const
|
|
348
|
-
this.updateMessageStatus(
|
|
457
|
+
const a = r instanceof Error ? r.message : "Unknown error";
|
|
458
|
+
this.updateMessageStatus(t, {
|
|
349
459
|
type: "error",
|
|
350
|
-
error:
|
|
460
|
+
error: a
|
|
351
461
|
});
|
|
352
462
|
}
|
|
353
463
|
} finally {
|
|
354
464
|
this._isRunning = !1, this._abortController = null, this._currentPart = null, this.notifySubscribers();
|
|
355
465
|
}
|
|
356
466
|
}
|
|
357
|
-
handleStreamEvent(
|
|
358
|
-
const
|
|
359
|
-
if (
|
|
360
|
-
const
|
|
361
|
-
if (
|
|
362
|
-
this.handlePartStart(
|
|
363
|
-
else if (
|
|
364
|
-
this.handleTextDelta(
|
|
365
|
-
else if (
|
|
467
|
+
handleStreamEvent(e, t) {
|
|
468
|
+
const n = this._messages.findIndex((o) => o.id === e);
|
|
469
|
+
if (n === -1) return;
|
|
470
|
+
const r = this._messages[n];
|
|
471
|
+
if (t.type === "part-start")
|
|
472
|
+
this.handlePartStart(r, t);
|
|
473
|
+
else if (t.type === "text-delta" || t.type === "assistant_thought")
|
|
474
|
+
this.handleTextDelta(r, t);
|
|
475
|
+
else if (t.type === "part-finish")
|
|
366
476
|
this.handlePartFinish();
|
|
367
|
-
else if (
|
|
368
|
-
const o =
|
|
369
|
-
|
|
370
|
-
...
|
|
477
|
+
else if (t.type === "metadata") {
|
|
478
|
+
const o = t;
|
|
479
|
+
r.metadata = {
|
|
480
|
+
...r.metadata,
|
|
371
481
|
conversationId: o.conversationId,
|
|
372
482
|
interactionId: o.interactionId
|
|
373
483
|
};
|
|
374
|
-
} else if (
|
|
375
|
-
const o =
|
|
376
|
-
|
|
377
|
-
...
|
|
484
|
+
} else if (t.type === "capability_execution") {
|
|
485
|
+
const o = t;
|
|
486
|
+
r.content = [
|
|
487
|
+
...r.content,
|
|
488
|
+
{
|
|
489
|
+
type: "capability",
|
|
490
|
+
capabilityId: o.capabilityId,
|
|
491
|
+
capabilityName: o.capabilityName,
|
|
492
|
+
args: o.args
|
|
493
|
+
}
|
|
494
|
+
], this.config.capabilityExecutionManager && this.config.capabilityExecutionManager.executeCapability(
|
|
495
|
+
o.capabilityName,
|
|
496
|
+
o.capabilityId,
|
|
497
|
+
o.args,
|
|
498
|
+
e,
|
|
499
|
+
o.strategy
|
|
500
|
+
);
|
|
501
|
+
} else if (t.type === "error") {
|
|
502
|
+
const o = t;
|
|
503
|
+
r.content = [
|
|
504
|
+
...r.content,
|
|
378
505
|
{
|
|
379
506
|
type: "error",
|
|
380
507
|
data: o.error
|
|
381
508
|
}
|
|
382
509
|
];
|
|
383
510
|
} else {
|
|
384
|
-
const o =
|
|
385
|
-
|
|
386
|
-
...
|
|
511
|
+
const o = t;
|
|
512
|
+
r.content = [
|
|
513
|
+
...r.content,
|
|
387
514
|
{
|
|
388
515
|
type: o.type,
|
|
389
516
|
data: o.data,
|
|
@@ -391,51 +518,51 @@ class R extends m {
|
|
|
391
518
|
}
|
|
392
519
|
];
|
|
393
520
|
}
|
|
394
|
-
const
|
|
395
|
-
...this._messages.slice(0,
|
|
396
|
-
{ ...
|
|
397
|
-
...this._messages.slice(
|
|
521
|
+
const a = [
|
|
522
|
+
...this._messages.slice(0, n),
|
|
523
|
+
{ ...r, timestamp: Date.now() },
|
|
524
|
+
...this._messages.slice(n + 1)
|
|
398
525
|
];
|
|
399
|
-
this.updateMessages(
|
|
526
|
+
this.updateMessages(a);
|
|
400
527
|
}
|
|
401
|
-
handlePartStart(
|
|
402
|
-
const
|
|
403
|
-
let
|
|
404
|
-
switch (
|
|
528
|
+
handlePartStart(e, t) {
|
|
529
|
+
const n = e.content.length;
|
|
530
|
+
let r;
|
|
531
|
+
switch (t.part.type) {
|
|
405
532
|
case "assistant_thought":
|
|
406
|
-
|
|
407
|
-
type:
|
|
533
|
+
r = {
|
|
534
|
+
type: t.part.type,
|
|
408
535
|
data: [],
|
|
409
|
-
parentId:
|
|
536
|
+
parentId: t.part.parentId
|
|
410
537
|
};
|
|
411
538
|
break;
|
|
412
539
|
case "text":
|
|
413
|
-
|
|
414
|
-
type:
|
|
540
|
+
r = {
|
|
541
|
+
type: t.part.type,
|
|
415
542
|
data: "",
|
|
416
|
-
parentId:
|
|
543
|
+
parentId: t.part.parentId
|
|
417
544
|
};
|
|
418
545
|
break;
|
|
419
546
|
default:
|
|
420
|
-
|
|
421
|
-
type:
|
|
422
|
-
parentId:
|
|
547
|
+
r = {
|
|
548
|
+
type: t.part.type,
|
|
549
|
+
parentId: t.part.parentId
|
|
423
550
|
};
|
|
424
551
|
}
|
|
425
|
-
|
|
426
|
-
messageId:
|
|
427
|
-
contentIndex:
|
|
428
|
-
type:
|
|
429
|
-
parentId:
|
|
552
|
+
e.content = [...e.content, r], this._currentPart = {
|
|
553
|
+
messageId: e.id,
|
|
554
|
+
contentIndex: n,
|
|
555
|
+
type: t.part.type,
|
|
556
|
+
parentId: t.part.parentId
|
|
430
557
|
};
|
|
431
558
|
}
|
|
432
|
-
handleTextDelta(
|
|
559
|
+
handleTextDelta(e, t) {
|
|
433
560
|
if (!this._currentPart) {
|
|
434
561
|
console.warn("Received text-delta without part-start");
|
|
435
562
|
return;
|
|
436
563
|
}
|
|
437
|
-
const
|
|
438
|
-
|
|
564
|
+
const n = e.content[this._currentPart.contentIndex];
|
|
565
|
+
n.type === "assistant_thought" ? (Array.isArray(n.data) || (n.data = []), t.delta.trim() && n.data.push(t.delta.trim())) : n.data = (n.data || "") + t.delta;
|
|
439
566
|
}
|
|
440
567
|
handlePartFinish() {
|
|
441
568
|
if (!this._currentPart) {
|
|
@@ -444,18 +571,18 @@ class R extends m {
|
|
|
444
571
|
}
|
|
445
572
|
this._currentPart = null;
|
|
446
573
|
}
|
|
447
|
-
updateMessageStatus(
|
|
448
|
-
const
|
|
449
|
-
if (
|
|
450
|
-
const
|
|
451
|
-
...this._messages.slice(0,
|
|
574
|
+
updateMessageStatus(e, t) {
|
|
575
|
+
const n = this._messages.findIndex((a) => a.id === e);
|
|
576
|
+
if (n === -1) return;
|
|
577
|
+
const r = [
|
|
578
|
+
...this._messages.slice(0, n),
|
|
452
579
|
{
|
|
453
|
-
...this._messages[
|
|
454
|
-
status:
|
|
580
|
+
...this._messages[n],
|
|
581
|
+
status: t
|
|
455
582
|
},
|
|
456
|
-
...this._messages.slice(
|
|
583
|
+
...this._messages.slice(n + 1)
|
|
457
584
|
];
|
|
458
|
-
this.updateMessages(
|
|
585
|
+
this.updateMessages(r);
|
|
459
586
|
}
|
|
460
587
|
clear() {
|
|
461
588
|
this.updateMessages([]);
|
|
@@ -463,25 +590,26 @@ class R extends m {
|
|
|
463
590
|
cancelRun() {
|
|
464
591
|
!this._isRunning || !this._abortController || this._abortController.abort();
|
|
465
592
|
}
|
|
466
|
-
reset(
|
|
467
|
-
this.updateMessages([...
|
|
593
|
+
reset(e = []) {
|
|
594
|
+
this.updateMessages([...e]);
|
|
468
595
|
}
|
|
469
596
|
}
|
|
470
|
-
class
|
|
471
|
-
constructor(
|
|
597
|
+
class Z extends y {
|
|
598
|
+
constructor(e) {
|
|
472
599
|
super();
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
this.config =
|
|
480
|
-
const
|
|
481
|
-
streamAdapter:
|
|
600
|
+
c(this, "_mainThreadId");
|
|
601
|
+
c(this, "_threads", /* @__PURE__ */ new Map());
|
|
602
|
+
c(this, "_threadItems", /* @__PURE__ */ new Map());
|
|
603
|
+
c(this, "_threadStates", /* @__PURE__ */ new Map());
|
|
604
|
+
c(this, "_isLoading", !1);
|
|
605
|
+
c(this, "main");
|
|
606
|
+
this.config = e, this._mainThreadId = F();
|
|
607
|
+
const t = new E({
|
|
608
|
+
streamAdapter: e.streamAdapter,
|
|
609
|
+
capabilityExecutionManager: e.capabilityExecutionManager
|
|
482
610
|
});
|
|
483
|
-
this.main = new
|
|
484
|
-
const
|
|
611
|
+
this.main = new C(t), this._threads.set(this._mainThreadId, this.main);
|
|
612
|
+
const n = {
|
|
485
613
|
id: this._mainThreadId,
|
|
486
614
|
title: "New Chat",
|
|
487
615
|
status: { type: "regular" },
|
|
@@ -489,14 +617,14 @@ class K extends m {
|
|
|
489
617
|
createdAt: Date.now(),
|
|
490
618
|
updatedAt: Date.now()
|
|
491
619
|
};
|
|
492
|
-
this._threadStates.set(this._mainThreadId,
|
|
493
|
-
const
|
|
494
|
-
state:
|
|
620
|
+
this._threadStates.set(this._mainThreadId, n);
|
|
621
|
+
const r = new R({
|
|
622
|
+
state: n,
|
|
495
623
|
onSwitchTo: this.switchToThread.bind(this),
|
|
496
624
|
onRename: this.renameThread.bind(this),
|
|
497
625
|
onDelete: this.deleteThread.bind(this)
|
|
498
626
|
});
|
|
499
|
-
this._threadItems.set(this._mainThreadId,
|
|
627
|
+
this._threadItems.set(this._mainThreadId, r);
|
|
500
628
|
}
|
|
501
629
|
get isLoading() {
|
|
502
630
|
return this._isLoading;
|
|
@@ -505,33 +633,33 @@ class K extends m {
|
|
|
505
633
|
* Get the currently active main thread
|
|
506
634
|
*/
|
|
507
635
|
getMainThread() {
|
|
508
|
-
const
|
|
509
|
-
return
|
|
636
|
+
const e = this._threads.get(this._mainThreadId);
|
|
637
|
+
return e || this.main;
|
|
510
638
|
}
|
|
511
639
|
getState() {
|
|
512
|
-
const
|
|
513
|
-
for (const [
|
|
514
|
-
|
|
640
|
+
const e = [], t = {};
|
|
641
|
+
for (const [n, r] of this._threadStates)
|
|
642
|
+
t[n] = r, r.status.type === "regular" && e.push(n);
|
|
515
643
|
return {
|
|
516
644
|
mainThreadId: this._mainThreadId,
|
|
517
|
-
threads:
|
|
645
|
+
threads: e,
|
|
518
646
|
isLoading: this._isLoading,
|
|
519
|
-
threadItems:
|
|
647
|
+
threadItems: t
|
|
520
648
|
};
|
|
521
649
|
}
|
|
522
|
-
async switchToThread(
|
|
523
|
-
var
|
|
524
|
-
const
|
|
525
|
-
if (!
|
|
526
|
-
throw new Error(`Thread ${
|
|
527
|
-
const
|
|
528
|
-
|
|
529
|
-
const
|
|
530
|
-
if (
|
|
650
|
+
async switchToThread(e) {
|
|
651
|
+
var a, o;
|
|
652
|
+
const t = this._threads.get(e);
|
|
653
|
+
if (!t)
|
|
654
|
+
throw new Error(`Thread ${e} not found`);
|
|
655
|
+
const n = this._threadStates.get(this._mainThreadId);
|
|
656
|
+
n && (n.isMain = !1, this._threadStates.set(this._mainThreadId, n), (a = this._threadItems.get(this._mainThreadId)) == null || a.updateState(n)), this._mainThreadId = e;
|
|
657
|
+
const r = this._threadStates.get(e);
|
|
658
|
+
if (r && (r.isMain = !0, this._threadStates.set(e, r), (o = this._threadItems.get(e)) == null || o.updateState(r)), this.config.threadListAdapter && (r != null && r.conversationId)) {
|
|
531
659
|
this._isLoading = !0, this.notifySubscribers();
|
|
532
660
|
try {
|
|
533
|
-
const u = await this.config.threadListAdapter.loadThread(
|
|
534
|
-
|
|
661
|
+
const u = await this.config.threadListAdapter.loadThread(e);
|
|
662
|
+
t.reset(u);
|
|
535
663
|
} catch (u) {
|
|
536
664
|
console.error("Failed to load thread:", u);
|
|
537
665
|
} finally {
|
|
@@ -541,35 +669,36 @@ class K extends m {
|
|
|
541
669
|
this.notifySubscribers();
|
|
542
670
|
}
|
|
543
671
|
async switchToNewThread() {
|
|
544
|
-
const
|
|
545
|
-
streamAdapter: this.config.streamAdapter
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
672
|
+
const e = F(), t = new E({
|
|
673
|
+
streamAdapter: this.config.streamAdapter,
|
|
674
|
+
capabilityExecutionManager: this.config.capabilityExecutionManager
|
|
675
|
+
}), n = new C(t);
|
|
676
|
+
this._threads.set(e, n);
|
|
677
|
+
const r = {
|
|
678
|
+
id: e,
|
|
550
679
|
title: "New Chat",
|
|
551
680
|
status: { type: "regular" },
|
|
552
681
|
isMain: !1,
|
|
553
682
|
createdAt: Date.now(),
|
|
554
683
|
updatedAt: Date.now()
|
|
555
684
|
};
|
|
556
|
-
this._threadStates.set(
|
|
557
|
-
const
|
|
558
|
-
state:
|
|
685
|
+
this._threadStates.set(e, r);
|
|
686
|
+
const a = new R({
|
|
687
|
+
state: r,
|
|
559
688
|
onSwitchTo: this.switchToThread.bind(this),
|
|
560
689
|
onRename: this.renameThread.bind(this),
|
|
561
690
|
onDelete: this.deleteThread.bind(this)
|
|
562
691
|
});
|
|
563
|
-
if (this._threadItems.set(
|
|
692
|
+
if (this._threadItems.set(e, a), n.subscribe(() => {
|
|
564
693
|
this.notifySubscribers();
|
|
565
694
|
}), this.config.threadListAdapter)
|
|
566
695
|
try {
|
|
567
696
|
const o = await this.config.threadListAdapter.createThread();
|
|
568
|
-
|
|
697
|
+
r.conversationId = o.conversationId, this._threadStates.set(e, r), a.updateState(r);
|
|
569
698
|
} catch (o) {
|
|
570
699
|
console.error("Failed to create thread:", o);
|
|
571
700
|
}
|
|
572
|
-
await this.switchToThread(
|
|
701
|
+
await this.switchToThread(e);
|
|
573
702
|
}
|
|
574
703
|
async loadThreads() {
|
|
575
704
|
if (!this.config.threadListAdapter) {
|
|
@@ -578,72 +707,75 @@ class K extends m {
|
|
|
578
707
|
}
|
|
579
708
|
this._isLoading = !0, this.notifySubscribers();
|
|
580
709
|
try {
|
|
581
|
-
const
|
|
582
|
-
for (const
|
|
583
|
-
if (this._threadStates.has(
|
|
710
|
+
const e = await this.config.threadListAdapter.loadThreads();
|
|
711
|
+
for (const t of e) {
|
|
712
|
+
if (this._threadStates.has(t.id))
|
|
584
713
|
continue;
|
|
585
|
-
const
|
|
714
|
+
const n = new E({
|
|
586
715
|
streamAdapter: this.config.streamAdapter
|
|
587
|
-
}),
|
|
588
|
-
this._threads.set(
|
|
589
|
-
const
|
|
590
|
-
state:
|
|
716
|
+
}), r = new C(n);
|
|
717
|
+
this._threads.set(t.id, r), this._threadStates.set(t.id, t);
|
|
718
|
+
const a = new R({
|
|
719
|
+
state: t,
|
|
591
720
|
onSwitchTo: this.switchToThread.bind(this),
|
|
592
721
|
onRename: this.renameThread.bind(this),
|
|
593
722
|
onDelete: this.deleteThread.bind(this)
|
|
594
723
|
});
|
|
595
|
-
this._threadItems.set(
|
|
724
|
+
this._threadItems.set(t.id, a), r.subscribe(() => {
|
|
596
725
|
this.notifySubscribers();
|
|
597
726
|
});
|
|
598
727
|
}
|
|
599
|
-
} catch (
|
|
600
|
-
console.error("Failed to load threads:",
|
|
728
|
+
} catch (e) {
|
|
729
|
+
console.error("Failed to load threads:", e);
|
|
601
730
|
} finally {
|
|
602
731
|
this._isLoading = !1, this.notifySubscribers();
|
|
603
732
|
}
|
|
604
733
|
}
|
|
605
|
-
async renameThread(
|
|
606
|
-
var
|
|
607
|
-
const
|
|
608
|
-
if (
|
|
609
|
-
if (
|
|
734
|
+
async renameThread(e, t) {
|
|
735
|
+
var r;
|
|
736
|
+
const n = this._threadStates.get(e);
|
|
737
|
+
if (n) {
|
|
738
|
+
if (n.title = t, n.updatedAt = Date.now(), this._threadStates.set(e, n), (r = this._threadItems.get(e)) == null || r.updateState(n), this.config.threadListAdapter)
|
|
610
739
|
try {
|
|
611
|
-
await this.config.threadListAdapter.updateThread(
|
|
612
|
-
} catch (
|
|
613
|
-
console.error("Failed to rename thread:",
|
|
740
|
+
await this.config.threadListAdapter.updateThread(e, { title: t });
|
|
741
|
+
} catch (a) {
|
|
742
|
+
console.error("Failed to rename thread:", a);
|
|
614
743
|
}
|
|
615
744
|
this.notifySubscribers();
|
|
616
745
|
}
|
|
617
746
|
}
|
|
618
|
-
async deleteThread(
|
|
619
|
-
if (
|
|
747
|
+
async deleteThread(e) {
|
|
748
|
+
if (e === this._mainThreadId && this._threads.size === 1)
|
|
620
749
|
throw new Error("Cannot delete the last thread");
|
|
621
|
-
if (
|
|
622
|
-
const
|
|
623
|
-
|
|
750
|
+
if (e === this._mainThreadId) {
|
|
751
|
+
const t = Array.from(this._threads.keys()).find((n) => n !== e);
|
|
752
|
+
t && await this.switchToThread(t);
|
|
624
753
|
}
|
|
625
|
-
if (this._threads.delete(
|
|
754
|
+
if (this._threads.delete(e), this._threadItems.delete(e), this._threadStates.delete(e), this.config.threadListAdapter)
|
|
626
755
|
try {
|
|
627
|
-
await this.config.threadListAdapter.deleteThread(
|
|
628
|
-
} catch (
|
|
629
|
-
console.error("Failed to delete thread:",
|
|
756
|
+
await this.config.threadListAdapter.deleteThread(e);
|
|
757
|
+
} catch (t) {
|
|
758
|
+
console.error("Failed to delete thread:", t);
|
|
630
759
|
}
|
|
631
760
|
this.notifySubscribers();
|
|
632
761
|
}
|
|
633
762
|
}
|
|
634
|
-
class
|
|
635
|
-
constructor(
|
|
763
|
+
class pe extends y {
|
|
764
|
+
constructor(e) {
|
|
636
765
|
super();
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
this
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
766
|
+
c(this, "threads");
|
|
767
|
+
c(this, "pluginRegistry");
|
|
768
|
+
c(this, "capabilityRegistry");
|
|
769
|
+
c(this, "capabilityExecutionManager");
|
|
770
|
+
c(this, "_contentFocusRuntime");
|
|
771
|
+
c(this, "_currentThreadUnsubscribe");
|
|
772
|
+
this.pluginRegistry = new W(), e.plugins && e.plugins.forEach((t) => {
|
|
773
|
+
this.pluginRegistry.registerPlugin(t);
|
|
774
|
+
}), this.capabilityRegistry = new z(), this.capabilityExecutionManager = new V((t) => this.capabilityRegistry.getHandler(t)), this.threads = new Z({
|
|
775
|
+
streamAdapter: e.streamAdapter,
|
|
776
|
+
threadListAdapter: e.threadListAdapter,
|
|
777
|
+
capabilityExecutionManager: this.capabilityExecutionManager
|
|
778
|
+
}), this._contentFocusRuntime = new G(), this._contentFocusRuntime.subscribe(() => {
|
|
647
779
|
this.notifySubscribers();
|
|
648
780
|
}), this.threads.subscribe(() => {
|
|
649
781
|
this.subscribeToCurrentThread(), this.notifySubscribers();
|
|
@@ -658,9 +790,9 @@ class ot extends m {
|
|
|
658
790
|
/**
|
|
659
791
|
* Register a plugin
|
|
660
792
|
*/
|
|
661
|
-
registerPlugin(
|
|
662
|
-
var
|
|
663
|
-
this.pluginRegistry.registerPlugin(
|
|
793
|
+
registerPlugin(e) {
|
|
794
|
+
var t;
|
|
795
|
+
this.pluginRegistry.registerPlugin(e), (t = e.init) == null || t.call(e, {
|
|
664
796
|
streamingEnabled: !0,
|
|
665
797
|
feedbackEnabled: !1,
|
|
666
798
|
detailPanelEnabled: !0
|
|
@@ -669,8 +801,8 @@ class ot extends m {
|
|
|
669
801
|
/**
|
|
670
802
|
* Unregister a plugin
|
|
671
803
|
*/
|
|
672
|
-
unregisterPlugin(
|
|
673
|
-
return this.pluginRegistry.unregisterPlugin(
|
|
804
|
+
unregisterPlugin(e) {
|
|
805
|
+
return this.pluginRegistry.unregisterPlugin(e);
|
|
674
806
|
}
|
|
675
807
|
/**
|
|
676
808
|
* Subscribe to the current main thread
|
|
@@ -681,21 +813,21 @@ class ot extends m {
|
|
|
681
813
|
this.handleMessagesChange(this.thread.messages), this.notifySubscribers();
|
|
682
814
|
});
|
|
683
815
|
}
|
|
684
|
-
handleMessagesChange(
|
|
685
|
-
if (
|
|
686
|
-
const
|
|
687
|
-
|
|
688
|
-
}
|
|
689
|
-
autoFocusLastContent(
|
|
690
|
-
var
|
|
691
|
-
if (
|
|
692
|
-
for (let
|
|
693
|
-
const
|
|
694
|
-
if (
|
|
695
|
-
for (let
|
|
696
|
-
const o =
|
|
697
|
-
if (u.length > 0 && ((
|
|
698
|
-
this._contentFocusRuntime.focus(o,
|
|
816
|
+
handleMessagesChange(e) {
|
|
817
|
+
if (e.length === 0) return;
|
|
818
|
+
const t = e[e.length - 1];
|
|
819
|
+
t.role === "assistant" && t.status.type === "complete" && this.autoFocusLastContent(e);
|
|
820
|
+
}
|
|
821
|
+
autoFocusLastContent(e) {
|
|
822
|
+
var t;
|
|
823
|
+
if (e.length !== 0 && !this._contentFocusRuntime.isActive)
|
|
824
|
+
for (let n = e.length - 1; n >= 0; n--) {
|
|
825
|
+
const r = e[n];
|
|
826
|
+
if (r.role === "assistant")
|
|
827
|
+
for (let a = r.content.length - 1; a >= 0; a--) {
|
|
828
|
+
const o = r.content[a], u = this.pluginRegistry.getRenderersByType(o.type);
|
|
829
|
+
if (u.length > 0 && ((t = u[0].capabilities) != null && t.supportsFocus)) {
|
|
830
|
+
this._contentFocusRuntime.focus(o, r, a, "detail");
|
|
699
831
|
return;
|
|
700
832
|
}
|
|
701
833
|
}
|
|
@@ -708,51 +840,51 @@ object-assign
|
|
|
708
840
|
(c) Sindre Sorhus
|
|
709
841
|
@license MIT
|
|
710
842
|
*/
|
|
711
|
-
var
|
|
712
|
-
function
|
|
713
|
-
if (
|
|
714
|
-
|
|
715
|
-
var
|
|
716
|
-
function
|
|
717
|
-
if (
|
|
843
|
+
var M, L;
|
|
844
|
+
function ee() {
|
|
845
|
+
if (L) return M;
|
|
846
|
+
L = 1;
|
|
847
|
+
var i = Object.getOwnPropertySymbols, s = Object.prototype.hasOwnProperty, e = Object.prototype.propertyIsEnumerable;
|
|
848
|
+
function t(r) {
|
|
849
|
+
if (r == null)
|
|
718
850
|
throw new TypeError("Object.assign cannot be called with null or undefined");
|
|
719
|
-
return Object(
|
|
851
|
+
return Object(r);
|
|
720
852
|
}
|
|
721
|
-
function
|
|
853
|
+
function n() {
|
|
722
854
|
try {
|
|
723
855
|
if (!Object.assign)
|
|
724
856
|
return !1;
|
|
725
|
-
var
|
|
726
|
-
if (
|
|
857
|
+
var r = new String("abc");
|
|
858
|
+
if (r[5] = "de", Object.getOwnPropertyNames(r)[0] === "5")
|
|
727
859
|
return !1;
|
|
728
|
-
for (var
|
|
729
|
-
|
|
730
|
-
var u = Object.getOwnPropertyNames(
|
|
731
|
-
return
|
|
860
|
+
for (var a = {}, o = 0; o < 10; o++)
|
|
861
|
+
a["_" + String.fromCharCode(o)] = o;
|
|
862
|
+
var u = Object.getOwnPropertyNames(a).map(function(l) {
|
|
863
|
+
return a[l];
|
|
732
864
|
});
|
|
733
865
|
if (u.join("") !== "0123456789")
|
|
734
866
|
return !1;
|
|
735
|
-
var
|
|
867
|
+
var p = {};
|
|
736
868
|
return "abcdefghijklmnopqrst".split("").forEach(function(l) {
|
|
737
|
-
|
|
738
|
-
}), Object.keys(Object.assign({},
|
|
869
|
+
p[l] = l;
|
|
870
|
+
}), Object.keys(Object.assign({}, p)).join("") === "abcdefghijklmnopqrst";
|
|
739
871
|
} catch {
|
|
740
872
|
return !1;
|
|
741
873
|
}
|
|
742
874
|
}
|
|
743
|
-
return
|
|
744
|
-
for (var o, u =
|
|
875
|
+
return M = n() ? Object.assign : function(r, a) {
|
|
876
|
+
for (var o, u = t(r), p, l = 1; l < arguments.length; l++) {
|
|
745
877
|
o = Object(arguments[l]);
|
|
746
|
-
for (var
|
|
747
|
-
|
|
748
|
-
if (
|
|
749
|
-
|
|
750
|
-
for (var
|
|
751
|
-
|
|
878
|
+
for (var h in o)
|
|
879
|
+
s.call(o, h) && (u[h] = o[h]);
|
|
880
|
+
if (i) {
|
|
881
|
+
p = i(o);
|
|
882
|
+
for (var d = 0; d < p.length; d++)
|
|
883
|
+
e.call(o, p[d]) && (u[p[d]] = o[p[d]]);
|
|
752
884
|
}
|
|
753
885
|
}
|
|
754
886
|
return u;
|
|
755
|
-
},
|
|
887
|
+
}, M;
|
|
756
888
|
}
|
|
757
889
|
/** @license React v17.0.2
|
|
758
890
|
* react-jsx-runtime.production.min.js
|
|
@@ -762,72 +894,72 @@ function Q() {
|
|
|
762
894
|
* This source code is licensed under the MIT license found in the
|
|
763
895
|
* LICENSE file in the root directory of this source tree.
|
|
764
896
|
*/
|
|
765
|
-
var
|
|
766
|
-
function
|
|
767
|
-
if (
|
|
768
|
-
|
|
769
|
-
var
|
|
897
|
+
var j;
|
|
898
|
+
function te() {
|
|
899
|
+
if (j) return _;
|
|
900
|
+
j = 1, ee();
|
|
901
|
+
var i = B, s = 60103;
|
|
770
902
|
if (_.Fragment = 60107, typeof Symbol == "function" && Symbol.for) {
|
|
771
|
-
var
|
|
772
|
-
|
|
773
|
-
}
|
|
774
|
-
var
|
|
775
|
-
function
|
|
776
|
-
var l,
|
|
777
|
-
|
|
778
|
-
for (l in u)
|
|
779
|
-
if (o && o.defaultProps) for (l in u = o.defaultProps, u)
|
|
780
|
-
return { $$typeof:
|
|
781
|
-
}
|
|
782
|
-
return _.jsx =
|
|
903
|
+
var e = Symbol.for;
|
|
904
|
+
s = e("react.element"), _.Fragment = e("react.fragment");
|
|
905
|
+
}
|
|
906
|
+
var t = 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 };
|
|
907
|
+
function a(o, u, p) {
|
|
908
|
+
var l, h = {}, d = null, f = null;
|
|
909
|
+
p !== void 0 && (d = "" + p), u.key !== void 0 && (d = "" + u.key), u.ref !== void 0 && (f = u.ref);
|
|
910
|
+
for (l in u) n.call(u, l) && !r.hasOwnProperty(l) && (h[l] = u[l]);
|
|
911
|
+
if (o && o.defaultProps) for (l in u = o.defaultProps, u) h[l] === void 0 && (h[l] = u[l]);
|
|
912
|
+
return { $$typeof: s, type: o, key: d, ref: f, props: h, _owner: t.current };
|
|
913
|
+
}
|
|
914
|
+
return _.jsx = a, _.jsxs = a, _;
|
|
783
915
|
}
|
|
784
|
-
var
|
|
785
|
-
function
|
|
786
|
-
return
|
|
916
|
+
var O;
|
|
917
|
+
function se() {
|
|
918
|
+
return O || (O = 1, I.exports = te()), I.exports;
|
|
787
919
|
}
|
|
788
|
-
var
|
|
789
|
-
const
|
|
790
|
-
function
|
|
791
|
-
return /* @__PURE__ */
|
|
920
|
+
var S = se();
|
|
921
|
+
const k = H(null);
|
|
922
|
+
function fe({ runtime: i, children: s }) {
|
|
923
|
+
return /* @__PURE__ */ S.jsx(k.Provider, { value: i, children: s });
|
|
792
924
|
}
|
|
793
|
-
function
|
|
794
|
-
const
|
|
795
|
-
if (!
|
|
925
|
+
function re() {
|
|
926
|
+
const i = Q(k);
|
|
927
|
+
if (!i)
|
|
796
928
|
throw new Error("useAssistantRuntimeContext must be used within AssistantRuntimeProvider");
|
|
797
|
-
return
|
|
929
|
+
return i;
|
|
798
930
|
}
|
|
799
|
-
function
|
|
800
|
-
return
|
|
931
|
+
function g() {
|
|
932
|
+
return re();
|
|
801
933
|
}
|
|
802
|
-
function
|
|
803
|
-
const
|
|
934
|
+
function ge() {
|
|
935
|
+
const i = g();
|
|
804
936
|
return {
|
|
805
|
-
switchToThread: (
|
|
806
|
-
switchToNewThread: () =>
|
|
937
|
+
switchToThread: (s) => i.threads.switchToThread(s),
|
|
938
|
+
switchToNewThread: () => i.threads.switchToNewThread(),
|
|
807
939
|
loadThreads: () => {
|
|
808
|
-
var
|
|
809
|
-
return (
|
|
940
|
+
var s, e;
|
|
941
|
+
return (e = (s = i.threads).loadThreads) == null ? void 0 : e.call(s);
|
|
810
942
|
},
|
|
811
|
-
renameThread: (
|
|
812
|
-
var
|
|
813
|
-
return (
|
|
943
|
+
renameThread: (s, e) => {
|
|
944
|
+
var t, n;
|
|
945
|
+
return (n = (t = i.threads).renameThread) == null ? void 0 : n.call(t, s, e);
|
|
814
946
|
},
|
|
815
|
-
deleteThread: (
|
|
816
|
-
var
|
|
817
|
-
return (
|
|
947
|
+
deleteThread: (s) => {
|
|
948
|
+
var e, t;
|
|
949
|
+
return (t = (e = i.threads).deleteThread) == null ? void 0 : t.call(e, s);
|
|
818
950
|
}
|
|
819
951
|
};
|
|
820
952
|
}
|
|
821
|
-
function
|
|
822
|
-
const
|
|
823
|
-
return
|
|
824
|
-
|
|
825
|
-
}), [
|
|
953
|
+
function be() {
|
|
954
|
+
const i = g(), [s, e] = x(i.threads.getState());
|
|
955
|
+
return w(() => i.threads.subscribe(() => {
|
|
956
|
+
e(i.threads.getState());
|
|
957
|
+
}), [i]), s;
|
|
826
958
|
}
|
|
827
|
-
function
|
|
828
|
-
return
|
|
959
|
+
function ne() {
|
|
960
|
+
return g().threads.getMainThread();
|
|
829
961
|
}
|
|
830
|
-
var
|
|
962
|
+
var v = { exports: {} }, A = {};
|
|
831
963
|
/**
|
|
832
964
|
* @license React
|
|
833
965
|
* use-sync-external-store-shim.production.js
|
|
@@ -837,88 +969,88 @@ var C = { exports: {} }, A = {};
|
|
|
837
969
|
* This source code is licensed under the MIT license found in the
|
|
838
970
|
* LICENSE file in the root directory of this source tree.
|
|
839
971
|
*/
|
|
840
|
-
var
|
|
841
|
-
function
|
|
842
|
-
if (
|
|
843
|
-
|
|
844
|
-
var
|
|
845
|
-
function
|
|
846
|
-
return
|
|
847
|
-
}
|
|
848
|
-
var
|
|
849
|
-
function o(
|
|
850
|
-
var
|
|
851
|
-
return
|
|
972
|
+
var N;
|
|
973
|
+
function ie() {
|
|
974
|
+
if (N) return A;
|
|
975
|
+
N = 1;
|
|
976
|
+
var i = B;
|
|
977
|
+
function s(h, d) {
|
|
978
|
+
return h === d && (h !== 0 || 1 / h === 1 / d) || h !== h && d !== d;
|
|
979
|
+
}
|
|
980
|
+
var e = typeof Object.is == "function" ? Object.is : s, t = i.useState, n = i.useEffect, r = i.useLayoutEffect, a = i.useDebugValue;
|
|
981
|
+
function o(h, d) {
|
|
982
|
+
var f = d(), m = t({ inst: { value: f, getSnapshot: d } }), b = m[0].inst, T = m[1];
|
|
983
|
+
return r(
|
|
852
984
|
function() {
|
|
853
|
-
|
|
985
|
+
b.value = f, b.getSnapshot = d, u(b) && T({ inst: b });
|
|
854
986
|
},
|
|
855
|
-
[
|
|
856
|
-
),
|
|
987
|
+
[h, f, d]
|
|
988
|
+
), n(
|
|
857
989
|
function() {
|
|
858
|
-
return u(
|
|
859
|
-
u(
|
|
990
|
+
return u(b) && T({ inst: b }), h(function() {
|
|
991
|
+
u(b) && T({ inst: b });
|
|
860
992
|
});
|
|
861
993
|
},
|
|
862
|
-
[
|
|
863
|
-
),
|
|
994
|
+
[h]
|
|
995
|
+
), a(f), f;
|
|
864
996
|
}
|
|
865
|
-
function u(
|
|
866
|
-
var
|
|
867
|
-
|
|
997
|
+
function u(h) {
|
|
998
|
+
var d = h.getSnapshot;
|
|
999
|
+
h = h.value;
|
|
868
1000
|
try {
|
|
869
|
-
var
|
|
870
|
-
return !
|
|
1001
|
+
var f = d();
|
|
1002
|
+
return !e(h, f);
|
|
871
1003
|
} catch {
|
|
872
1004
|
return !0;
|
|
873
1005
|
}
|
|
874
1006
|
}
|
|
875
|
-
function
|
|
876
|
-
return
|
|
1007
|
+
function p(h, d) {
|
|
1008
|
+
return d();
|
|
877
1009
|
}
|
|
878
|
-
var l = typeof window > "u" || typeof window.document > "u" || typeof window.document.createElement > "u" ?
|
|
879
|
-
return A.useSyncExternalStore =
|
|
1010
|
+
var l = typeof window > "u" || typeof window.document > "u" || typeof window.document.createElement > "u" ? p : o;
|
|
1011
|
+
return A.useSyncExternalStore = i.useSyncExternalStore !== void 0 ? i.useSyncExternalStore : l, A;
|
|
880
1012
|
}
|
|
881
1013
|
var D;
|
|
882
|
-
function
|
|
883
|
-
return D || (D = 1,
|
|
1014
|
+
function ae() {
|
|
1015
|
+
return D || (D = 1, v.exports = ie()), v.exports;
|
|
884
1016
|
}
|
|
885
|
-
var
|
|
886
|
-
function
|
|
887
|
-
const
|
|
888
|
-
return
|
|
889
|
-
(
|
|
890
|
-
|
|
1017
|
+
var oe = ae();
|
|
1018
|
+
function ye() {
|
|
1019
|
+
const i = g();
|
|
1020
|
+
return oe.useSyncExternalStore(
|
|
1021
|
+
(s) => i.subscribe(() => {
|
|
1022
|
+
s();
|
|
891
1023
|
}),
|
|
892
|
-
() =>
|
|
893
|
-
() =>
|
|
1024
|
+
() => i.thread.messages,
|
|
1025
|
+
() => i.thread.messages
|
|
894
1026
|
);
|
|
895
1027
|
}
|
|
896
|
-
function
|
|
897
|
-
const
|
|
1028
|
+
function me() {
|
|
1029
|
+
const i = ne(), [s, e] = x(""), [t, n] = x(!1);
|
|
898
1030
|
return {
|
|
899
|
-
text:
|
|
900
|
-
setText:
|
|
901
|
-
isSubmitting:
|
|
902
|
-
send: async (
|
|
903
|
-
if (
|
|
904
|
-
const o =
|
|
905
|
-
|
|
1031
|
+
text: s,
|
|
1032
|
+
setText: e,
|
|
1033
|
+
isSubmitting: t,
|
|
1034
|
+
send: async (a) => {
|
|
1035
|
+
if (a == null || a.preventDefault(), !s.trim() || t) return;
|
|
1036
|
+
const o = s;
|
|
1037
|
+
e(""), n(!0);
|
|
906
1038
|
try {
|
|
907
|
-
await
|
|
1039
|
+
await i.send(o);
|
|
908
1040
|
} catch (u) {
|
|
909
|
-
console.error("Failed to send message:", u),
|
|
1041
|
+
console.error("Failed to send message:", u), e(o);
|
|
910
1042
|
} finally {
|
|
911
|
-
|
|
1043
|
+
n(!1);
|
|
912
1044
|
}
|
|
913
1045
|
},
|
|
914
|
-
clear: () =>
|
|
915
|
-
append: (
|
|
1046
|
+
clear: () => e(""),
|
|
1047
|
+
append: (a) => e((o) => o + a)
|
|
916
1048
|
};
|
|
917
1049
|
}
|
|
918
|
-
function q(
|
|
919
|
-
var
|
|
920
|
-
const
|
|
921
|
-
if (!
|
|
1050
|
+
function q(i, s) {
|
|
1051
|
+
var r, a, o, u;
|
|
1052
|
+
const t = g().pluginRegistry.getBestRendererForType(i);
|
|
1053
|
+
if (!t)
|
|
922
1054
|
return {
|
|
923
1055
|
component: null,
|
|
924
1056
|
auxiliaryComponent: null,
|
|
@@ -926,142 +1058,193 @@ function q(a, n) {
|
|
|
926
1058
|
supportsPreview: !1,
|
|
927
1059
|
supportsFullscreen: !1
|
|
928
1060
|
};
|
|
929
|
-
const
|
|
1061
|
+
const n = s ? (r = t.auxiliary) == null ? void 0 : r[s] : null;
|
|
930
1062
|
return {
|
|
931
|
-
component:
|
|
932
|
-
auxiliaryComponent:
|
|
933
|
-
supportsFocus: ((
|
|
934
|
-
supportsPreview: ((o =
|
|
935
|
-
supportsFullscreen: ((u =
|
|
1063
|
+
component: t.component,
|
|
1064
|
+
auxiliaryComponent: n,
|
|
1065
|
+
supportsFocus: ((a = t.capabilities) == null ? void 0 : a.supportsFocus) ?? !1,
|
|
1066
|
+
supportsPreview: ((o = t.capabilities) == null ? void 0 : o.supportsPreview) ?? !1,
|
|
1067
|
+
supportsFullscreen: ((u = t.capabilities) == null ? void 0 : u.supportsFullscreen) ?? !1
|
|
936
1068
|
};
|
|
937
1069
|
}
|
|
938
|
-
function
|
|
939
|
-
const
|
|
940
|
-
return
|
|
941
|
-
|
|
942
|
-
}), [
|
|
943
|
-
...
|
|
944
|
-
focus: (
|
|
945
|
-
blur: () =>
|
|
946
|
-
toggle: (
|
|
947
|
-
switchContext: (
|
|
948
|
-
focusNext: () =>
|
|
949
|
-
focusPrevious: () =>
|
|
1070
|
+
function _e() {
|
|
1071
|
+
const i = g(), [s, e] = x(i.contentFocus.state);
|
|
1072
|
+
return w(() => i.contentFocus.subscribe(() => {
|
|
1073
|
+
e(i.contentFocus.state);
|
|
1074
|
+
}), [i]), {
|
|
1075
|
+
...s,
|
|
1076
|
+
focus: (t, n, r, a) => i.contentFocus.focus(t, n, r, a),
|
|
1077
|
+
blur: () => i.contentFocus.blur(),
|
|
1078
|
+
toggle: (t, n, r, a) => i.contentFocus.toggle(t, n, r, a),
|
|
1079
|
+
switchContext: (t) => i.contentFocus.switchContext(t),
|
|
1080
|
+
focusNext: () => i.contentFocus.focusNext(i.thread.messages),
|
|
1081
|
+
focusPrevious: () => i.contentFocus.focusPrevious(i.thread.messages)
|
|
950
1082
|
};
|
|
951
1083
|
}
|
|
952
|
-
function
|
|
953
|
-
const
|
|
954
|
-
|
|
1084
|
+
function ue(i) {
|
|
1085
|
+
const s = g();
|
|
1086
|
+
w(() => (i.execute && s.capabilityRegistry.registerHandler(i.name, { execute: i.execute }), i.render && s.capabilityRegistry.registerRenderer(i.name, {
|
|
1087
|
+
component: i.render
|
|
1088
|
+
}), () => {
|
|
1089
|
+
s.capabilityRegistry.unregister(i.name);
|
|
1090
|
+
}), [i.name, s]);
|
|
1091
|
+
}
|
|
1092
|
+
function ce(i) {
|
|
1093
|
+
const s = g(), [e, t] = x(
|
|
1094
|
+
() => s.capabilityExecutionManager.getExecution(i)
|
|
1095
|
+
), [, n] = J((r) => r + 1, 0);
|
|
1096
|
+
return w(() => {
|
|
1097
|
+
const r = s.capabilityExecutionManager.getExecution(i);
|
|
1098
|
+
return t(r), s.capabilityExecutionManager.subscribe((o) => {
|
|
1099
|
+
if (o === i) {
|
|
1100
|
+
const u = s.capabilityExecutionManager.getExecution(i);
|
|
1101
|
+
t(u), n();
|
|
1102
|
+
}
|
|
1103
|
+
});
|
|
1104
|
+
}, [i, s]), e;
|
|
1105
|
+
}
|
|
1106
|
+
function he({ message: i, content: s }) {
|
|
1107
|
+
const e = g(), t = s, n = ce(t.capabilityId), r = e.capabilityRegistry.getRenderer(t.capabilityName);
|
|
1108
|
+
if (!r || !n)
|
|
955
1109
|
return null;
|
|
956
|
-
const
|
|
957
|
-
return /* @__PURE__ */
|
|
1110
|
+
const a = r.component;
|
|
1111
|
+
return /* @__PURE__ */ S.jsx(
|
|
1112
|
+
a,
|
|
1113
|
+
{
|
|
1114
|
+
capabilityName: n.name,
|
|
1115
|
+
capabilityId: n.id,
|
|
1116
|
+
args: n.args,
|
|
1117
|
+
result: n.result,
|
|
1118
|
+
status: n.status,
|
|
1119
|
+
message: i
|
|
1120
|
+
}
|
|
1121
|
+
);
|
|
1122
|
+
}
|
|
1123
|
+
function xe({ message: i, content: s }) {
|
|
1124
|
+
const { component: e } = q(s.type);
|
|
1125
|
+
if (s.type === "capability")
|
|
1126
|
+
return /* @__PURE__ */ S.jsx(he, { message: i, content: s });
|
|
1127
|
+
if (!e)
|
|
1128
|
+
return null;
|
|
1129
|
+
const t = e;
|
|
1130
|
+
return /* @__PURE__ */ S.jsx(t, { content: s, message: i });
|
|
958
1131
|
}
|
|
959
|
-
function
|
|
960
|
-
message:
|
|
961
|
-
content:
|
|
962
|
-
context:
|
|
963
|
-
onClose:
|
|
964
|
-
onNavigate:
|
|
965
|
-
onSwitchContext:
|
|
1132
|
+
function Se({
|
|
1133
|
+
message: i,
|
|
1134
|
+
content: s,
|
|
1135
|
+
context: e,
|
|
1136
|
+
onClose: t,
|
|
1137
|
+
onNavigate: n,
|
|
1138
|
+
onSwitchContext: r
|
|
966
1139
|
}) {
|
|
967
|
-
const { auxiliaryComponent:
|
|
968
|
-
if (!
|
|
1140
|
+
const { auxiliaryComponent: a } = q(s.type, e);
|
|
1141
|
+
if (!a)
|
|
969
1142
|
return null;
|
|
970
|
-
const o =
|
|
971
|
-
return /* @__PURE__ */
|
|
1143
|
+
const o = a;
|
|
1144
|
+
return /* @__PURE__ */ S.jsx(
|
|
972
1145
|
o,
|
|
973
1146
|
{
|
|
974
|
-
content:
|
|
975
|
-
message:
|
|
976
|
-
context:
|
|
977
|
-
onClose:
|
|
978
|
-
onNavigate:
|
|
979
|
-
onSwitchContext:
|
|
1147
|
+
content: s,
|
|
1148
|
+
message: i,
|
|
1149
|
+
context: e,
|
|
1150
|
+
onClose: t,
|
|
1151
|
+
onNavigate: n,
|
|
1152
|
+
onSwitchContext: r
|
|
980
1153
|
}
|
|
981
1154
|
);
|
|
982
1155
|
}
|
|
983
|
-
|
|
1156
|
+
function we(i) {
|
|
1157
|
+
const s = () => (ue(i), null);
|
|
1158
|
+
return s.displayName = `Capability(${i.name})`, s;
|
|
1159
|
+
}
|
|
1160
|
+
class Te {
|
|
984
1161
|
getAllowedEvents() {
|
|
985
1162
|
return null;
|
|
986
1163
|
}
|
|
987
|
-
shouldProcessEvent(
|
|
988
|
-
const
|
|
989
|
-
return
|
|
1164
|
+
shouldProcessEvent(s) {
|
|
1165
|
+
const e = this.getAllowedEvents();
|
|
1166
|
+
return e ? e.includes(s) : !0;
|
|
990
1167
|
}
|
|
991
|
-
async *stream(
|
|
992
|
-
const { signal:
|
|
993
|
-
if (!
|
|
994
|
-
throw new Error(`HTTP error! status: ${
|
|
995
|
-
if (!
|
|
1168
|
+
async *stream(s) {
|
|
1169
|
+
const { signal: e } = s, { url: t, options: n } = this.prepareRequest(s), r = await fetch(t, { ...n, signal: e });
|
|
1170
|
+
if (!r.ok)
|
|
1171
|
+
throw new Error(`HTTP error! status: ${r.status}`);
|
|
1172
|
+
if (!r.body)
|
|
996
1173
|
throw new Error("Response body is null");
|
|
997
|
-
yield* this.parseSSEStream(
|
|
1174
|
+
yield* this.parseSSEStream(r.body, e);
|
|
998
1175
|
}
|
|
999
|
-
async *parseSSEStream(
|
|
1000
|
-
const
|
|
1001
|
-
let
|
|
1176
|
+
async *parseSSEStream(s, e) {
|
|
1177
|
+
const t = s.getReader(), n = new TextDecoder();
|
|
1178
|
+
let r = "", a = null;
|
|
1002
1179
|
try {
|
|
1003
1180
|
for (; ; ) {
|
|
1004
|
-
const { done: o, value: u } = await
|
|
1005
|
-
if (o ||
|
|
1006
|
-
|
|
1007
|
-
const
|
|
1181
|
+
const { done: o, value: u } = await t.read();
|
|
1182
|
+
if (o || e != null && e.aborted) break;
|
|
1183
|
+
r += n.decode(u, { stream: !0 });
|
|
1184
|
+
const p = r.split(`
|
|
1008
1185
|
`);
|
|
1009
|
-
|
|
1010
|
-
for (const l of
|
|
1011
|
-
const
|
|
1012
|
-
if (!
|
|
1013
|
-
|
|
1186
|
+
r = p.pop() || "";
|
|
1187
|
+
for (const l of p) {
|
|
1188
|
+
const h = l.trim();
|
|
1189
|
+
if (!h) {
|
|
1190
|
+
a = null;
|
|
1014
1191
|
continue;
|
|
1015
1192
|
}
|
|
1016
|
-
if (
|
|
1017
|
-
if (
|
|
1018
|
-
|
|
1193
|
+
if (h !== ": ping") {
|
|
1194
|
+
if (h.startsWith("event:")) {
|
|
1195
|
+
a = h.substring(6).trim();
|
|
1019
1196
|
continue;
|
|
1020
1197
|
}
|
|
1021
|
-
if (
|
|
1022
|
-
const
|
|
1023
|
-
if (
|
|
1198
|
+
if (h.startsWith("data:")) {
|
|
1199
|
+
const d = h.substring(5).trim();
|
|
1200
|
+
if (d === "eof" || h === "eof")
|
|
1024
1201
|
break;
|
|
1025
1202
|
try {
|
|
1026
|
-
const
|
|
1027
|
-
if (
|
|
1028
|
-
const
|
|
1029
|
-
event:
|
|
1030
|
-
data:
|
|
1203
|
+
const f = JSON.parse(d);
|
|
1204
|
+
if (a && this.shouldProcessEvent(a)) {
|
|
1205
|
+
const m = this.convertEvent({
|
|
1206
|
+
event: a,
|
|
1207
|
+
data: f
|
|
1031
1208
|
});
|
|
1032
|
-
|
|
1209
|
+
m && (yield m);
|
|
1033
1210
|
}
|
|
1034
1211
|
} catch {
|
|
1035
1212
|
}
|
|
1036
|
-
|
|
1213
|
+
a = null;
|
|
1037
1214
|
}
|
|
1038
1215
|
}
|
|
1039
1216
|
}
|
|
1040
1217
|
}
|
|
1041
1218
|
} finally {
|
|
1042
|
-
|
|
1219
|
+
t.releaseLock();
|
|
1043
1220
|
}
|
|
1044
1221
|
}
|
|
1045
1222
|
}
|
|
1046
1223
|
export {
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
R as
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1224
|
+
pe as AssistantRuntime,
|
|
1225
|
+
fe as AssistantRuntimeProvider,
|
|
1226
|
+
Se as AuxiliaryRenderer,
|
|
1227
|
+
Te as BaseSSEStreamAdapter,
|
|
1228
|
+
V as CapabilityExecutionManager,
|
|
1229
|
+
z as CapabilityRegistry,
|
|
1230
|
+
he as CapabilityRendererComp,
|
|
1231
|
+
X as ComposerRuntime,
|
|
1232
|
+
xe as ContentRenderer,
|
|
1233
|
+
W as PluginRegistry,
|
|
1234
|
+
R as ThreadListItemRuntime,
|
|
1235
|
+
Z as ThreadListRuntime,
|
|
1236
|
+
C as ThreadRuntime,
|
|
1237
|
+
E as ThreadRuntimeCore,
|
|
1238
|
+
we as makeCapability,
|
|
1239
|
+
g as useAssistantRuntime,
|
|
1240
|
+
ue as useCapability,
|
|
1241
|
+
ce as useCapabilityExecution,
|
|
1242
|
+
me as useComposer,
|
|
1243
|
+
_e as useContentFocus,
|
|
1061
1244
|
q as useContentRenderer,
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1245
|
+
ne as useCurrentThread,
|
|
1246
|
+
ye as useMessages,
|
|
1247
|
+
ge as useThreadList,
|
|
1248
|
+
be as useThreadListState
|
|
1066
1249
|
};
|
|
1067
1250
|
//# sourceMappingURL=index.js.map
|