@harnessio/ai-chat-core 0.0.1 → 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 +725 -526
- package/dist/index.js.map +1 -1
- package/dist/react/components/AuxiliaryRenderer.d.ts +2 -0
- package/dist/react/components/CapabilityRenderer.d.ts +6 -0
- package/dist/react/components/ContentRenderer.d.ts +5 -0
- package/dist/react/components/index.d.ts +3 -0
- package/dist/react/hooks/index.d.ts +3 -1
- package/dist/react/hooks/useCapability.d.ts +2 -0
- package/dist/react/hooks/useCapabilityExecution.d.ts +2 -0
- package/dist/react/hooks/useComposer.d.ts +8 -3
- package/dist/react/index.d.ts +2 -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 +3 -0
- package/dist/types/adapters.d.ts +6 -0
- package/dist/types/capability.d.ts +53 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/utils/index.d.ts +0 -3
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -1,62 +1,172 @@
|
|
|
1
1
|
var $ = Object.defineProperty;
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import
|
|
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
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
40
|
constructor() {
|
|
41
|
-
|
|
41
|
+
c(this, "handlers", /* @__PURE__ */ new Map());
|
|
42
|
+
c(this, "renderers", /* @__PURE__ */ new Map());
|
|
42
43
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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 {
|
|
150
|
+
constructor() {
|
|
151
|
+
c(this, "_subscriptions", /* @__PURE__ */ new Set());
|
|
152
|
+
}
|
|
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 z 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,42 +216,42 @@ class z 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 a =
|
|
125
|
-
this.focus(a,
|
|
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 a = t
|
|
238
|
+
if (t + 1 < e.length) {
|
|
239
|
+
const a = e[t + 1];
|
|
130
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 a =
|
|
140
|
-
this.focus(a,
|
|
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 a = t
|
|
253
|
+
if (t > 0) {
|
|
254
|
+
const a = e[t - 1];
|
|
145
255
|
if (a.content.length > 0) {
|
|
146
256
|
const o = a.content.length - 1;
|
|
147
257
|
this.focus(a.content[o], a, o, this._state.context || "detail");
|
|
@@ -149,21 +259,18 @@ class z extends m {
|
|
|
149
259
|
}
|
|
150
260
|
}
|
|
151
261
|
}
|
|
152
|
-
let
|
|
153
|
-
function
|
|
154
|
-
return `msg-${Date.now()}-${++
|
|
262
|
+
let Y = 0, K = 0;
|
|
263
|
+
function P() {
|
|
264
|
+
return `msg-${Date.now()}-${++Y}`;
|
|
155
265
|
}
|
|
156
|
-
function
|
|
157
|
-
return `thread-${Date.now()}-${++
|
|
266
|
+
function F() {
|
|
267
|
+
return `thread-${Date.now()}-${++K}`;
|
|
158
268
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}
|
|
162
|
-
class w extends m {
|
|
163
|
-
constructor(t) {
|
|
269
|
+
class R extends y {
|
|
270
|
+
constructor(e) {
|
|
164
271
|
super();
|
|
165
|
-
|
|
166
|
-
this.config =
|
|
272
|
+
c(this, "_state");
|
|
273
|
+
this.config = e, this._state = e.state;
|
|
167
274
|
}
|
|
168
275
|
get state() {
|
|
169
276
|
return this._state;
|
|
@@ -171,27 +278,27 @@ class w extends m {
|
|
|
171
278
|
getState() {
|
|
172
279
|
return this._state;
|
|
173
280
|
}
|
|
174
|
-
updateState(
|
|
175
|
-
this._state =
|
|
281
|
+
updateState(e) {
|
|
282
|
+
this._state = e, this.notifySubscribers();
|
|
176
283
|
}
|
|
177
284
|
async switchTo() {
|
|
178
285
|
await this.config.onSwitchTo(this._state.id);
|
|
179
286
|
}
|
|
180
|
-
async rename(
|
|
181
|
-
await this.config.onRename(this._state.id,
|
|
287
|
+
async rename(e) {
|
|
288
|
+
await this.config.onRename(this._state.id, e);
|
|
182
289
|
}
|
|
183
290
|
async delete() {
|
|
184
291
|
await this.config.onDelete(this._state.id);
|
|
185
292
|
}
|
|
186
|
-
subscribe(
|
|
187
|
-
return super.subscribe(
|
|
293
|
+
subscribe(e) {
|
|
294
|
+
return super.subscribe(e);
|
|
188
295
|
}
|
|
189
296
|
}
|
|
190
|
-
class
|
|
297
|
+
class X extends y {
|
|
191
298
|
constructor() {
|
|
192
299
|
super(...arguments);
|
|
193
|
-
|
|
194
|
-
|
|
300
|
+
c(this, "_text", "");
|
|
301
|
+
c(this, "_isSubmitting", !1);
|
|
195
302
|
}
|
|
196
303
|
get text() {
|
|
197
304
|
return this._text;
|
|
@@ -205,21 +312,21 @@ class H extends m {
|
|
|
205
312
|
isSubmitting: this._isSubmitting
|
|
206
313
|
};
|
|
207
314
|
}
|
|
208
|
-
setText(
|
|
209
|
-
this._text =
|
|
315
|
+
setText(e) {
|
|
316
|
+
this._text = e, this.notifySubscribers();
|
|
210
317
|
}
|
|
211
318
|
clear() {
|
|
212
319
|
this._text = "", this.notifySubscribers();
|
|
213
320
|
}
|
|
214
|
-
setSubmitting(
|
|
215
|
-
this._isSubmitting =
|
|
321
|
+
setSubmitting(e) {
|
|
322
|
+
this._isSubmitting = e, this.notifySubscribers();
|
|
216
323
|
}
|
|
217
324
|
}
|
|
218
|
-
class
|
|
219
|
-
constructor(
|
|
325
|
+
class C extends y {
|
|
326
|
+
constructor(e) {
|
|
220
327
|
super();
|
|
221
|
-
|
|
222
|
-
this._core =
|
|
328
|
+
c(this, "composer");
|
|
329
|
+
this._core = e, this.composer = new X(), this._core.subscribe(() => {
|
|
223
330
|
this.notifySubscribers();
|
|
224
331
|
});
|
|
225
332
|
}
|
|
@@ -244,16 +351,16 @@ class T extends m {
|
|
|
244
351
|
capabilities: this._core.capabilities
|
|
245
352
|
};
|
|
246
353
|
}
|
|
247
|
-
append(
|
|
248
|
-
this._core.append(
|
|
354
|
+
append(e) {
|
|
355
|
+
this._core.append(e);
|
|
249
356
|
}
|
|
250
|
-
async send(
|
|
251
|
-
if (
|
|
357
|
+
async send(e) {
|
|
358
|
+
if (e.trim()) {
|
|
252
359
|
this.composer.setSubmitting(!0);
|
|
253
360
|
try {
|
|
254
361
|
this.composer.clear(), await this._core.startRun({
|
|
255
362
|
role: "user",
|
|
256
|
-
content: [{ type: "text", data:
|
|
363
|
+
content: [{ type: "text", data: e }]
|
|
257
364
|
});
|
|
258
365
|
} catch {
|
|
259
366
|
} finally {
|
|
@@ -267,23 +374,23 @@ class T extends m {
|
|
|
267
374
|
clear() {
|
|
268
375
|
this._core.clear();
|
|
269
376
|
}
|
|
270
|
-
reset(
|
|
271
|
-
this._core.reset(
|
|
377
|
+
reset(e = []) {
|
|
378
|
+
this._core.reset(e);
|
|
272
379
|
}
|
|
273
|
-
subscribe(
|
|
274
|
-
return super.subscribe(
|
|
380
|
+
subscribe(e) {
|
|
381
|
+
return super.subscribe(e);
|
|
275
382
|
}
|
|
276
383
|
}
|
|
277
|
-
class
|
|
278
|
-
constructor(
|
|
384
|
+
class E extends y {
|
|
385
|
+
constructor(e) {
|
|
279
386
|
super();
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
387
|
+
c(this, "_messages", []);
|
|
388
|
+
c(this, "_isRunning", !1);
|
|
389
|
+
c(this, "_isDisabled", !1);
|
|
390
|
+
c(this, "_abortController", null);
|
|
284
391
|
// Track current part being accumulated
|
|
285
|
-
|
|
286
|
-
this.config =
|
|
392
|
+
c(this, "_currentPart", null);
|
|
393
|
+
this.config = e, e.initialMessages && (this._messages = [...e.initialMessages]);
|
|
287
394
|
}
|
|
288
395
|
get messages() {
|
|
289
396
|
return this._messages;
|
|
@@ -304,133 +411,158 @@ class x extends m {
|
|
|
304
411
|
feedback: !1
|
|
305
412
|
};
|
|
306
413
|
}
|
|
307
|
-
|
|
308
|
-
var
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
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.
|
|
428
|
+
this.updateMessages([...this._messages, t]);
|
|
319
429
|
}
|
|
320
|
-
async startRun(
|
|
321
|
-
var s, a;
|
|
430
|
+
async startRun(e) {
|
|
322
431
|
if (this._isRunning)
|
|
323
432
|
throw new Error("A run is already in progress");
|
|
324
|
-
this.append(
|
|
325
|
-
const
|
|
326
|
-
id:
|
|
433
|
+
this.append(e), this._isRunning = !0, this._abortController = new AbortController(), this._currentPart = null;
|
|
434
|
+
const t = P(), n = {
|
|
435
|
+
id: t,
|
|
327
436
|
role: "assistant",
|
|
328
437
|
content: [],
|
|
329
438
|
status: { type: "running" },
|
|
330
439
|
timestamp: Date.now()
|
|
331
440
|
};
|
|
332
|
-
this.
|
|
441
|
+
this.updateMessages([...this._messages, n]);
|
|
333
442
|
try {
|
|
334
|
-
const
|
|
443
|
+
const r = this.config.streamAdapter.stream({
|
|
335
444
|
messages: this._messages,
|
|
336
445
|
signal: this._abortController.signal
|
|
337
446
|
});
|
|
338
|
-
for await (const
|
|
447
|
+
for await (const a of r) {
|
|
339
448
|
if (this._abortController.signal.aborted)
|
|
340
449
|
break;
|
|
341
|
-
this.handleStreamEvent(
|
|
450
|
+
this.handleStreamEvent(t, a.event);
|
|
342
451
|
}
|
|
343
|
-
this.updateMessageStatus(
|
|
344
|
-
} catch (
|
|
345
|
-
if (
|
|
346
|
-
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" });
|
|
347
456
|
else {
|
|
348
|
-
const
|
|
349
|
-
this.updateMessageStatus(
|
|
457
|
+
const a = r instanceof Error ? r.message : "Unknown error";
|
|
458
|
+
this.updateMessageStatus(t, {
|
|
350
459
|
type: "error",
|
|
351
|
-
error:
|
|
460
|
+
error: a
|
|
352
461
|
});
|
|
353
462
|
}
|
|
354
463
|
} finally {
|
|
355
464
|
this._isRunning = !1, this._abortController = null, this._currentPart = null, this.notifySubscribers();
|
|
356
465
|
}
|
|
357
466
|
}
|
|
358
|
-
handleStreamEvent(
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
else if (e.type === "part-finish")
|
|
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")
|
|
368
476
|
this.handlePartFinish();
|
|
369
|
-
else if (
|
|
370
|
-
const
|
|
371
|
-
|
|
372
|
-
...
|
|
373
|
-
conversationId:
|
|
374
|
-
interactionId:
|
|
477
|
+
else if (t.type === "metadata") {
|
|
478
|
+
const o = t;
|
|
479
|
+
r.metadata = {
|
|
480
|
+
...r.metadata,
|
|
481
|
+
conversationId: o.conversationId,
|
|
482
|
+
interactionId: o.interactionId
|
|
375
483
|
};
|
|
376
|
-
} else if (
|
|
377
|
-
const
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
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,
|
|
505
|
+
{
|
|
506
|
+
type: "error",
|
|
507
|
+
data: o.error
|
|
508
|
+
}
|
|
509
|
+
];
|
|
382
510
|
} else {
|
|
383
|
-
const
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
511
|
+
const o = t;
|
|
512
|
+
r.content = [
|
|
513
|
+
...r.content,
|
|
514
|
+
{
|
|
515
|
+
type: o.type,
|
|
516
|
+
data: o.data,
|
|
517
|
+
parentId: o.parentId
|
|
518
|
+
}
|
|
519
|
+
];
|
|
389
520
|
}
|
|
390
|
-
|
|
391
|
-
...this._messages.slice(0,
|
|
392
|
-
{ ...
|
|
393
|
-
...this._messages.slice(
|
|
394
|
-
]
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
521
|
+
const a = [
|
|
522
|
+
...this._messages.slice(0, n),
|
|
523
|
+
{ ...r, timestamp: Date.now() },
|
|
524
|
+
...this._messages.slice(n + 1)
|
|
525
|
+
];
|
|
526
|
+
this.updateMessages(a);
|
|
527
|
+
}
|
|
528
|
+
handlePartStart(e, t) {
|
|
529
|
+
const n = e.content.length;
|
|
530
|
+
let r;
|
|
531
|
+
switch (t.part.type) {
|
|
400
532
|
case "assistant_thought":
|
|
401
|
-
|
|
402
|
-
type:
|
|
533
|
+
r = {
|
|
534
|
+
type: t.part.type,
|
|
403
535
|
data: [],
|
|
404
|
-
parentId:
|
|
536
|
+
parentId: t.part.parentId
|
|
405
537
|
};
|
|
406
538
|
break;
|
|
407
539
|
case "text":
|
|
408
|
-
|
|
409
|
-
type:
|
|
540
|
+
r = {
|
|
541
|
+
type: t.part.type,
|
|
410
542
|
data: "",
|
|
411
|
-
parentId:
|
|
543
|
+
parentId: t.part.parentId
|
|
412
544
|
};
|
|
413
545
|
break;
|
|
414
546
|
default:
|
|
415
|
-
|
|
416
|
-
type:
|
|
417
|
-
parentId:
|
|
547
|
+
r = {
|
|
548
|
+
type: t.part.type,
|
|
549
|
+
parentId: t.part.parentId
|
|
418
550
|
};
|
|
419
551
|
}
|
|
420
|
-
|
|
421
|
-
messageId:
|
|
422
|
-
contentIndex:
|
|
423
|
-
type:
|
|
424
|
-
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
|
|
425
557
|
};
|
|
426
558
|
}
|
|
427
|
-
handleTextDelta(
|
|
559
|
+
handleTextDelta(e, t) {
|
|
428
560
|
if (!this._currentPart) {
|
|
429
561
|
console.warn("Received text-delta without part-start");
|
|
430
562
|
return;
|
|
431
563
|
}
|
|
432
|
-
const
|
|
433
|
-
|
|
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;
|
|
434
566
|
}
|
|
435
567
|
handlePartFinish() {
|
|
436
568
|
if (!this._currentPart) {
|
|
@@ -439,41 +571,45 @@ class x extends m {
|
|
|
439
571
|
}
|
|
440
572
|
this._currentPart = null;
|
|
441
573
|
}
|
|
442
|
-
updateMessageStatus(
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
...this._messages
|
|
447
|
-
|
|
448
|
-
|
|
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),
|
|
579
|
+
{
|
|
580
|
+
...this._messages[n],
|
|
581
|
+
status: t
|
|
582
|
+
},
|
|
583
|
+
...this._messages.slice(n + 1)
|
|
584
|
+
];
|
|
585
|
+
this.updateMessages(r);
|
|
449
586
|
}
|
|
450
587
|
clear() {
|
|
451
|
-
|
|
452
|
-
this._messages = [], (e = (t = this.config).onMessagesChange) == null || e.call(t, this._messages), this.notifySubscribers();
|
|
588
|
+
this.updateMessages([]);
|
|
453
589
|
}
|
|
454
590
|
cancelRun() {
|
|
455
591
|
!this._isRunning || !this._abortController || this._abortController.abort();
|
|
456
592
|
}
|
|
457
|
-
reset(
|
|
458
|
-
|
|
459
|
-
this._messages = [...t], (r = (e = this.config).onMessagesChange) == null || r.call(e, this._messages), this.notifySubscribers();
|
|
593
|
+
reset(e = []) {
|
|
594
|
+
this.updateMessages([...e]);
|
|
460
595
|
}
|
|
461
596
|
}
|
|
462
|
-
class
|
|
463
|
-
constructor(
|
|
597
|
+
class Z extends y {
|
|
598
|
+
constructor(e) {
|
|
464
599
|
super();
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
this.config =
|
|
472
|
-
const
|
|
473
|
-
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
|
|
474
610
|
});
|
|
475
|
-
this.main = new
|
|
476
|
-
const
|
|
611
|
+
this.main = new C(t), this._threads.set(this._mainThreadId, this.main);
|
|
612
|
+
const n = {
|
|
477
613
|
id: this._mainThreadId,
|
|
478
614
|
title: "New Chat",
|
|
479
615
|
status: { type: "regular" },
|
|
@@ -481,14 +617,14 @@ class K extends m {
|
|
|
481
617
|
createdAt: Date.now(),
|
|
482
618
|
updatedAt: Date.now()
|
|
483
619
|
};
|
|
484
|
-
this._threadStates.set(this._mainThreadId,
|
|
485
|
-
const
|
|
486
|
-
state:
|
|
620
|
+
this._threadStates.set(this._mainThreadId, n);
|
|
621
|
+
const r = new R({
|
|
622
|
+
state: n,
|
|
487
623
|
onSwitchTo: this.switchToThread.bind(this),
|
|
488
624
|
onRename: this.renameThread.bind(this),
|
|
489
625
|
onDelete: this.deleteThread.bind(this)
|
|
490
626
|
});
|
|
491
|
-
this._threadItems.set(this._mainThreadId,
|
|
627
|
+
this._threadItems.set(this._mainThreadId, r);
|
|
492
628
|
}
|
|
493
629
|
get isLoading() {
|
|
494
630
|
return this._isLoading;
|
|
@@ -497,33 +633,33 @@ class K extends m {
|
|
|
497
633
|
* Get the currently active main thread
|
|
498
634
|
*/
|
|
499
635
|
getMainThread() {
|
|
500
|
-
const
|
|
501
|
-
return
|
|
636
|
+
const e = this._threads.get(this._mainThreadId);
|
|
637
|
+
return e || this.main;
|
|
502
638
|
}
|
|
503
639
|
getState() {
|
|
504
|
-
const
|
|
505
|
-
for (const [
|
|
506
|
-
|
|
640
|
+
const e = [], t = {};
|
|
641
|
+
for (const [n, r] of this._threadStates)
|
|
642
|
+
t[n] = r, r.status.type === "regular" && e.push(n);
|
|
507
643
|
return {
|
|
508
644
|
mainThreadId: this._mainThreadId,
|
|
509
|
-
threads:
|
|
645
|
+
threads: e,
|
|
510
646
|
isLoading: this._isLoading,
|
|
511
|
-
threadItems:
|
|
647
|
+
threadItems: t
|
|
512
648
|
};
|
|
513
649
|
}
|
|
514
|
-
async switchToThread(
|
|
650
|
+
async switchToThread(e) {
|
|
515
651
|
var a, o;
|
|
516
|
-
const
|
|
517
|
-
if (!
|
|
518
|
-
throw new Error(`Thread ${
|
|
519
|
-
const
|
|
520
|
-
|
|
521
|
-
const
|
|
522
|
-
if (
|
|
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)) {
|
|
523
659
|
this._isLoading = !0, this.notifySubscribers();
|
|
524
660
|
try {
|
|
525
|
-
const u = await this.config.threadListAdapter.loadThread(
|
|
526
|
-
|
|
661
|
+
const u = await this.config.threadListAdapter.loadThread(e);
|
|
662
|
+
t.reset(u);
|
|
527
663
|
} catch (u) {
|
|
528
664
|
console.error("Failed to load thread:", u);
|
|
529
665
|
} finally {
|
|
@@ -533,35 +669,36 @@ class K extends m {
|
|
|
533
669
|
this.notifySubscribers();
|
|
534
670
|
}
|
|
535
671
|
async switchToNewThread() {
|
|
536
|
-
const
|
|
537
|
-
streamAdapter: this.config.streamAdapter
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
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,
|
|
542
679
|
title: "New Chat",
|
|
543
680
|
status: { type: "regular" },
|
|
544
681
|
isMain: !1,
|
|
545
682
|
createdAt: Date.now(),
|
|
546
683
|
updatedAt: Date.now()
|
|
547
684
|
};
|
|
548
|
-
this._threadStates.set(
|
|
549
|
-
const a = new
|
|
550
|
-
state:
|
|
685
|
+
this._threadStates.set(e, r);
|
|
686
|
+
const a = new R({
|
|
687
|
+
state: r,
|
|
551
688
|
onSwitchTo: this.switchToThread.bind(this),
|
|
552
689
|
onRename: this.renameThread.bind(this),
|
|
553
690
|
onDelete: this.deleteThread.bind(this)
|
|
554
691
|
});
|
|
555
|
-
if (this._threadItems.set(
|
|
692
|
+
if (this._threadItems.set(e, a), n.subscribe(() => {
|
|
556
693
|
this.notifySubscribers();
|
|
557
694
|
}), this.config.threadListAdapter)
|
|
558
695
|
try {
|
|
559
696
|
const o = await this.config.threadListAdapter.createThread();
|
|
560
|
-
|
|
697
|
+
r.conversationId = o.conversationId, this._threadStates.set(e, r), a.updateState(r);
|
|
561
698
|
} catch (o) {
|
|
562
699
|
console.error("Failed to create thread:", o);
|
|
563
700
|
}
|
|
564
|
-
await this.switchToThread(
|
|
701
|
+
await this.switchToThread(e);
|
|
565
702
|
}
|
|
566
703
|
async loadThreads() {
|
|
567
704
|
if (!this.config.threadListAdapter) {
|
|
@@ -570,72 +707,75 @@ class K extends m {
|
|
|
570
707
|
}
|
|
571
708
|
this._isLoading = !0, this.notifySubscribers();
|
|
572
709
|
try {
|
|
573
|
-
const
|
|
574
|
-
for (const
|
|
575
|
-
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))
|
|
576
713
|
continue;
|
|
577
|
-
const
|
|
714
|
+
const n = new E({
|
|
578
715
|
streamAdapter: this.config.streamAdapter
|
|
579
|
-
}),
|
|
580
|
-
this._threads.set(
|
|
581
|
-
const a = new
|
|
582
|
-
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,
|
|
583
720
|
onSwitchTo: this.switchToThread.bind(this),
|
|
584
721
|
onRename: this.renameThread.bind(this),
|
|
585
722
|
onDelete: this.deleteThread.bind(this)
|
|
586
723
|
});
|
|
587
|
-
this._threadItems.set(
|
|
724
|
+
this._threadItems.set(t.id, a), r.subscribe(() => {
|
|
588
725
|
this.notifySubscribers();
|
|
589
726
|
});
|
|
590
727
|
}
|
|
591
|
-
} catch (
|
|
592
|
-
console.error("Failed to load threads:",
|
|
728
|
+
} catch (e) {
|
|
729
|
+
console.error("Failed to load threads:", e);
|
|
593
730
|
} finally {
|
|
594
731
|
this._isLoading = !1, this.notifySubscribers();
|
|
595
732
|
}
|
|
596
733
|
}
|
|
597
|
-
async renameThread(
|
|
598
|
-
var
|
|
599
|
-
const
|
|
600
|
-
if (
|
|
601
|
-
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)
|
|
602
739
|
try {
|
|
603
|
-
await this.config.threadListAdapter.updateThread(
|
|
740
|
+
await this.config.threadListAdapter.updateThread(e, { title: t });
|
|
604
741
|
} catch (a) {
|
|
605
742
|
console.error("Failed to rename thread:", a);
|
|
606
743
|
}
|
|
607
744
|
this.notifySubscribers();
|
|
608
745
|
}
|
|
609
746
|
}
|
|
610
|
-
async deleteThread(
|
|
611
|
-
if (
|
|
747
|
+
async deleteThread(e) {
|
|
748
|
+
if (e === this._mainThreadId && this._threads.size === 1)
|
|
612
749
|
throw new Error("Cannot delete the last thread");
|
|
613
|
-
if (
|
|
614
|
-
const
|
|
615
|
-
|
|
750
|
+
if (e === this._mainThreadId) {
|
|
751
|
+
const t = Array.from(this._threads.keys()).find((n) => n !== e);
|
|
752
|
+
t && await this.switchToThread(t);
|
|
616
753
|
}
|
|
617
|
-
if (this._threads.delete(
|
|
754
|
+
if (this._threads.delete(e), this._threadItems.delete(e), this._threadStates.delete(e), this.config.threadListAdapter)
|
|
618
755
|
try {
|
|
619
|
-
await this.config.threadListAdapter.deleteThread(
|
|
620
|
-
} catch (
|
|
621
|
-
console.error("Failed to delete thread:",
|
|
756
|
+
await this.config.threadListAdapter.deleteThread(e);
|
|
757
|
+
} catch (t) {
|
|
758
|
+
console.error("Failed to delete thread:", t);
|
|
622
759
|
}
|
|
623
760
|
this.notifySubscribers();
|
|
624
761
|
}
|
|
625
762
|
}
|
|
626
|
-
class
|
|
627
|
-
constructor(
|
|
763
|
+
class pe extends y {
|
|
764
|
+
constructor(e) {
|
|
628
765
|
super();
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
this
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
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(() => {
|
|
639
779
|
this.notifySubscribers();
|
|
640
780
|
}), this.threads.subscribe(() => {
|
|
641
781
|
this.subscribeToCurrentThread(), this.notifySubscribers();
|
|
@@ -650,9 +790,9 @@ class ht extends m {
|
|
|
650
790
|
/**
|
|
651
791
|
* Register a plugin
|
|
652
792
|
*/
|
|
653
|
-
registerPlugin(
|
|
654
|
-
var
|
|
655
|
-
this.pluginRegistry.registerPlugin(
|
|
793
|
+
registerPlugin(e) {
|
|
794
|
+
var t;
|
|
795
|
+
this.pluginRegistry.registerPlugin(e), (t = e.init) == null || t.call(e, {
|
|
656
796
|
streamingEnabled: !0,
|
|
657
797
|
feedbackEnabled: !1,
|
|
658
798
|
detailPanelEnabled: !0
|
|
@@ -661,8 +801,8 @@ class ht extends m {
|
|
|
661
801
|
/**
|
|
662
802
|
* Unregister a plugin
|
|
663
803
|
*/
|
|
664
|
-
unregisterPlugin(
|
|
665
|
-
return this.pluginRegistry.unregisterPlugin(
|
|
804
|
+
unregisterPlugin(e) {
|
|
805
|
+
return this.pluginRegistry.unregisterPlugin(e);
|
|
666
806
|
}
|
|
667
807
|
/**
|
|
668
808
|
* Subscribe to the current main thread
|
|
@@ -673,21 +813,21 @@ class ht extends m {
|
|
|
673
813
|
this.handleMessagesChange(this.thread.messages), this.notifySubscribers();
|
|
674
814
|
});
|
|
675
815
|
}
|
|
676
|
-
handleMessagesChange(
|
|
677
|
-
if (
|
|
678
|
-
const
|
|
679
|
-
|
|
680
|
-
}
|
|
681
|
-
autoFocusLastContent(
|
|
682
|
-
var
|
|
683
|
-
if (
|
|
684
|
-
for (let
|
|
685
|
-
const
|
|
686
|
-
if (
|
|
687
|
-
for (let a =
|
|
688
|
-
const o =
|
|
689
|
-
if (u.length > 0 && ((
|
|
690
|
-
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");
|
|
691
831
|
return;
|
|
692
832
|
}
|
|
693
833
|
}
|
|
@@ -700,22 +840,22 @@ object-assign
|
|
|
700
840
|
(c) Sindre Sorhus
|
|
701
841
|
@license MIT
|
|
702
842
|
*/
|
|
703
|
-
var
|
|
704
|
-
function
|
|
705
|
-
if (
|
|
706
|
-
|
|
707
|
-
var
|
|
708
|
-
function
|
|
709
|
-
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)
|
|
710
850
|
throw new TypeError("Object.assign cannot be called with null or undefined");
|
|
711
|
-
return Object(
|
|
851
|
+
return Object(r);
|
|
712
852
|
}
|
|
713
|
-
function
|
|
853
|
+
function n() {
|
|
714
854
|
try {
|
|
715
855
|
if (!Object.assign)
|
|
716
856
|
return !1;
|
|
717
|
-
var
|
|
718
|
-
if (
|
|
857
|
+
var r = new String("abc");
|
|
858
|
+
if (r[5] = "de", Object.getOwnPropertyNames(r)[0] === "5")
|
|
719
859
|
return !1;
|
|
720
860
|
for (var a = {}, o = 0; o < 10; o++)
|
|
721
861
|
a["_" + String.fromCharCode(o)] = o;
|
|
@@ -724,27 +864,27 @@ function Y() {
|
|
|
724
864
|
});
|
|
725
865
|
if (u.join("") !== "0123456789")
|
|
726
866
|
return !1;
|
|
727
|
-
var
|
|
867
|
+
var p = {};
|
|
728
868
|
return "abcdefghijklmnopqrst".split("").forEach(function(l) {
|
|
729
|
-
|
|
730
|
-
}), Object.keys(Object.assign({},
|
|
869
|
+
p[l] = l;
|
|
870
|
+
}), Object.keys(Object.assign({}, p)).join("") === "abcdefghijklmnopqrst";
|
|
731
871
|
} catch {
|
|
732
872
|
return !1;
|
|
733
873
|
}
|
|
734
874
|
}
|
|
735
|
-
return
|
|
736
|
-
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++) {
|
|
737
877
|
o = Object(arguments[l]);
|
|
738
|
-
for (var
|
|
739
|
-
|
|
740
|
-
if (
|
|
741
|
-
|
|
742
|
-
for (var
|
|
743
|
-
|
|
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]]);
|
|
744
884
|
}
|
|
745
885
|
}
|
|
746
886
|
return u;
|
|
747
|
-
},
|
|
887
|
+
}, M;
|
|
748
888
|
}
|
|
749
889
|
/** @license React v17.0.2
|
|
750
890
|
* react-jsx-runtime.production.min.js
|
|
@@ -754,72 +894,72 @@ function Y() {
|
|
|
754
894
|
* This source code is licensed under the MIT license found in the
|
|
755
895
|
* LICENSE file in the root directory of this source tree.
|
|
756
896
|
*/
|
|
757
|
-
var
|
|
758
|
-
function
|
|
759
|
-
if (
|
|
760
|
-
|
|
761
|
-
var
|
|
897
|
+
var j;
|
|
898
|
+
function te() {
|
|
899
|
+
if (j) return _;
|
|
900
|
+
j = 1, ee();
|
|
901
|
+
var i = B, s = 60103;
|
|
762
902
|
if (_.Fragment = 60107, typeof Symbol == "function" && Symbol.for) {
|
|
763
|
-
var
|
|
764
|
-
|
|
903
|
+
var e = Symbol.for;
|
|
904
|
+
s = e("react.element"), _.Fragment = e("react.fragment");
|
|
765
905
|
}
|
|
766
|
-
var
|
|
767
|
-
function a(o, u,
|
|
768
|
-
var l,
|
|
769
|
-
|
|
770
|
-
for (l in u)
|
|
771
|
-
if (o && o.defaultProps) for (l in u = o.defaultProps, u)
|
|
772
|
-
return { $$typeof:
|
|
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 };
|
|
773
913
|
}
|
|
774
914
|
return _.jsx = a, _.jsxs = a, _;
|
|
775
915
|
}
|
|
776
|
-
var
|
|
777
|
-
function
|
|
778
|
-
return
|
|
916
|
+
var O;
|
|
917
|
+
function se() {
|
|
918
|
+
return O || (O = 1, I.exports = te()), I.exports;
|
|
779
919
|
}
|
|
780
|
-
var
|
|
781
|
-
const
|
|
782
|
-
function
|
|
783
|
-
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 });
|
|
784
924
|
}
|
|
785
|
-
function
|
|
786
|
-
const
|
|
787
|
-
if (!
|
|
925
|
+
function re() {
|
|
926
|
+
const i = Q(k);
|
|
927
|
+
if (!i)
|
|
788
928
|
throw new Error("useAssistantRuntimeContext must be used within AssistantRuntimeProvider");
|
|
789
|
-
return
|
|
929
|
+
return i;
|
|
790
930
|
}
|
|
791
|
-
function
|
|
792
|
-
return
|
|
931
|
+
function g() {
|
|
932
|
+
return re();
|
|
793
933
|
}
|
|
794
|
-
function
|
|
795
|
-
const
|
|
934
|
+
function ge() {
|
|
935
|
+
const i = g();
|
|
796
936
|
return {
|
|
797
|
-
switchToThread: (
|
|
798
|
-
switchToNewThread: () =>
|
|
937
|
+
switchToThread: (s) => i.threads.switchToThread(s),
|
|
938
|
+
switchToNewThread: () => i.threads.switchToNewThread(),
|
|
799
939
|
loadThreads: () => {
|
|
800
|
-
var
|
|
801
|
-
return (
|
|
940
|
+
var s, e;
|
|
941
|
+
return (e = (s = i.threads).loadThreads) == null ? void 0 : e.call(s);
|
|
802
942
|
},
|
|
803
|
-
renameThread: (
|
|
804
|
-
var
|
|
805
|
-
return (
|
|
943
|
+
renameThread: (s, e) => {
|
|
944
|
+
var t, n;
|
|
945
|
+
return (n = (t = i.threads).renameThread) == null ? void 0 : n.call(t, s, e);
|
|
806
946
|
},
|
|
807
|
-
deleteThread: (
|
|
808
|
-
var
|
|
809
|
-
return (
|
|
947
|
+
deleteThread: (s) => {
|
|
948
|
+
var e, t;
|
|
949
|
+
return (t = (e = i.threads).deleteThread) == null ? void 0 : t.call(e, s);
|
|
810
950
|
}
|
|
811
951
|
};
|
|
812
952
|
}
|
|
813
|
-
function
|
|
814
|
-
const
|
|
815
|
-
return
|
|
816
|
-
|
|
817
|
-
}), [
|
|
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;
|
|
818
958
|
}
|
|
819
|
-
function
|
|
820
|
-
return
|
|
959
|
+
function ne() {
|
|
960
|
+
return g().threads.getMainThread();
|
|
821
961
|
}
|
|
822
|
-
var
|
|
962
|
+
var v = { exports: {} }, A = {};
|
|
823
963
|
/**
|
|
824
964
|
* @license React
|
|
825
965
|
* use-sync-external-store-shim.production.js
|
|
@@ -829,77 +969,88 @@ var C = { exports: {} }, v = {};
|
|
|
829
969
|
* This source code is licensed under the MIT license found in the
|
|
830
970
|
* LICENSE file in the root directory of this source tree.
|
|
831
971
|
*/
|
|
832
|
-
var
|
|
833
|
-
function
|
|
834
|
-
if (
|
|
835
|
-
|
|
836
|
-
var
|
|
837
|
-
function
|
|
838
|
-
return
|
|
839
|
-
}
|
|
840
|
-
var
|
|
841
|
-
function o(
|
|
842
|
-
var
|
|
843
|
-
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(
|
|
844
984
|
function() {
|
|
845
|
-
|
|
985
|
+
b.value = f, b.getSnapshot = d, u(b) && T({ inst: b });
|
|
846
986
|
},
|
|
847
|
-
[
|
|
848
|
-
),
|
|
987
|
+
[h, f, d]
|
|
988
|
+
), n(
|
|
849
989
|
function() {
|
|
850
|
-
return u(
|
|
851
|
-
u(
|
|
990
|
+
return u(b) && T({ inst: b }), h(function() {
|
|
991
|
+
u(b) && T({ inst: b });
|
|
852
992
|
});
|
|
853
993
|
},
|
|
854
|
-
[
|
|
855
|
-
), a(
|
|
994
|
+
[h]
|
|
995
|
+
), a(f), f;
|
|
856
996
|
}
|
|
857
|
-
function u(
|
|
858
|
-
var
|
|
859
|
-
|
|
997
|
+
function u(h) {
|
|
998
|
+
var d = h.getSnapshot;
|
|
999
|
+
h = h.value;
|
|
860
1000
|
try {
|
|
861
|
-
var
|
|
862
|
-
return !
|
|
1001
|
+
var f = d();
|
|
1002
|
+
return !e(h, f);
|
|
863
1003
|
} catch {
|
|
864
1004
|
return !0;
|
|
865
1005
|
}
|
|
866
1006
|
}
|
|
867
|
-
function
|
|
868
|
-
return
|
|
1007
|
+
function p(h, d) {
|
|
1008
|
+
return d();
|
|
869
1009
|
}
|
|
870
|
-
var l = typeof window > "u" || typeof window.document > "u" || typeof window.document.createElement > "u" ?
|
|
871
|
-
return
|
|
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;
|
|
872
1012
|
}
|
|
873
|
-
var
|
|
874
|
-
function
|
|
875
|
-
return
|
|
1013
|
+
var D;
|
|
1014
|
+
function ae() {
|
|
1015
|
+
return D || (D = 1, v.exports = ie()), v.exports;
|
|
876
1016
|
}
|
|
877
|
-
var
|
|
878
|
-
function
|
|
879
|
-
const
|
|
880
|
-
return
|
|
881
|
-
(
|
|
882
|
-
|
|
1017
|
+
var oe = ae();
|
|
1018
|
+
function ye() {
|
|
1019
|
+
const i = g();
|
|
1020
|
+
return oe.useSyncExternalStore(
|
|
1021
|
+
(s) => i.subscribe(() => {
|
|
1022
|
+
s();
|
|
883
1023
|
}),
|
|
884
|
-
() =>
|
|
885
|
-
() =>
|
|
1024
|
+
() => i.thread.messages,
|
|
1025
|
+
() => i.thread.messages
|
|
886
1026
|
);
|
|
887
1027
|
}
|
|
888
|
-
function
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
(
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
1028
|
+
function me() {
|
|
1029
|
+
const i = ne(), [s, e] = x(""), [t, n] = x(!1);
|
|
1030
|
+
return {
|
|
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);
|
|
1038
|
+
try {
|
|
1039
|
+
await i.send(o);
|
|
1040
|
+
} catch (u) {
|
|
1041
|
+
console.error("Failed to send message:", u), e(o);
|
|
1042
|
+
} finally {
|
|
1043
|
+
n(!1);
|
|
1044
|
+
}
|
|
1045
|
+
},
|
|
1046
|
+
clear: () => e(""),
|
|
1047
|
+
append: (a) => e((o) => o + a)
|
|
1048
|
+
};
|
|
898
1049
|
}
|
|
899
|
-
function
|
|
900
|
-
var
|
|
901
|
-
const
|
|
902
|
-
if (!
|
|
1050
|
+
function q(i, s) {
|
|
1051
|
+
var r, a, o, u;
|
|
1052
|
+
const t = g().pluginRegistry.getBestRendererForType(i);
|
|
1053
|
+
if (!t)
|
|
903
1054
|
return {
|
|
904
1055
|
component: null,
|
|
905
1056
|
auxiliaryComponent: null,
|
|
@@ -907,109 +1058,155 @@ function mt(n, i) {
|
|
|
907
1058
|
supportsPreview: !1,
|
|
908
1059
|
supportsFullscreen: !1
|
|
909
1060
|
};
|
|
910
|
-
const
|
|
1061
|
+
const n = s ? (r = t.auxiliary) == null ? void 0 : r[s] : null;
|
|
911
1062
|
return {
|
|
912
|
-
component:
|
|
913
|
-
auxiliaryComponent:
|
|
914
|
-
supportsFocus: ((a =
|
|
915
|
-
supportsPreview: ((o =
|
|
916
|
-
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
|
|
917
1068
|
};
|
|
918
1069
|
}
|
|
919
|
-
function
|
|
920
|
-
const
|
|
921
|
-
return
|
|
922
|
-
|
|
923
|
-
}), [
|
|
924
|
-
...
|
|
925
|
-
focus: (
|
|
926
|
-
blur: () =>
|
|
927
|
-
toggle: (
|
|
928
|
-
switchContext: (
|
|
929
|
-
focusNext: () =>
|
|
930
|
-
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)
|
|
931
1082
|
};
|
|
932
1083
|
}
|
|
933
|
-
function
|
|
934
|
-
const
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
for (const [e, r] of i) {
|
|
941
|
-
const s = e.startsWith("__ungrouped_") ? void 0 : e, a = r.map((f) => n[f]), o = it(a), u = at(a);
|
|
942
|
-
t.push({ groupKey: s, indices: r, items: a, groupType: o, primaryType: u });
|
|
943
|
-
}
|
|
944
|
-
return t;
|
|
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]);
|
|
945
1091
|
}
|
|
946
|
-
function
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
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)
|
|
1109
|
+
return null;
|
|
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 });
|
|
1131
|
+
}
|
|
1132
|
+
function Se({
|
|
1133
|
+
message: i,
|
|
1134
|
+
content: s,
|
|
1135
|
+
context: e,
|
|
1136
|
+
onClose: t,
|
|
1137
|
+
onNavigate: n,
|
|
1138
|
+
onSwitchContext: r
|
|
1139
|
+
}) {
|
|
1140
|
+
const { auxiliaryComponent: a } = q(s.type, e);
|
|
1141
|
+
if (!a)
|
|
1142
|
+
return null;
|
|
1143
|
+
const o = a;
|
|
1144
|
+
return /* @__PURE__ */ S.jsx(
|
|
1145
|
+
o,
|
|
1146
|
+
{
|
|
1147
|
+
content: s,
|
|
1148
|
+
message: i,
|
|
1149
|
+
context: e,
|
|
1150
|
+
onClose: t,
|
|
1151
|
+
onNavigate: n,
|
|
1152
|
+
onSwitchContext: r
|
|
1153
|
+
}
|
|
1154
|
+
);
|
|
953
1155
|
}
|
|
954
|
-
function
|
|
955
|
-
const
|
|
956
|
-
|
|
957
|
-
i.set(r.type, (i.get(r.type) || 0) + 1);
|
|
958
|
-
let t = 0, e = n[0].type;
|
|
959
|
-
for (const [r, s] of i)
|
|
960
|
-
s > t && (t = s, e = r);
|
|
961
|
-
return e;
|
|
1156
|
+
function we(i) {
|
|
1157
|
+
const s = () => (ue(i), null);
|
|
1158
|
+
return s.displayName = `Capability(${i.name})`, s;
|
|
962
1159
|
}
|
|
963
|
-
class
|
|
1160
|
+
class Te {
|
|
964
1161
|
getAllowedEvents() {
|
|
965
1162
|
return null;
|
|
966
1163
|
}
|
|
967
|
-
shouldProcessEvent(
|
|
968
|
-
const
|
|
969
|
-
return
|
|
1164
|
+
shouldProcessEvent(s) {
|
|
1165
|
+
const e = this.getAllowedEvents();
|
|
1166
|
+
return e ? e.includes(s) : !0;
|
|
970
1167
|
}
|
|
971
|
-
async *stream(
|
|
972
|
-
const { signal:
|
|
973
|
-
if (!
|
|
974
|
-
throw new Error(`HTTP error! status: ${
|
|
975
|
-
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)
|
|
976
1173
|
throw new Error("Response body is null");
|
|
977
|
-
yield* this.parseSSEStream(
|
|
1174
|
+
yield* this.parseSSEStream(r.body, e);
|
|
978
1175
|
}
|
|
979
|
-
async *parseSSEStream(
|
|
980
|
-
const
|
|
981
|
-
let
|
|
1176
|
+
async *parseSSEStream(s, e) {
|
|
1177
|
+
const t = s.getReader(), n = new TextDecoder();
|
|
1178
|
+
let r = "", a = null;
|
|
982
1179
|
try {
|
|
983
1180
|
for (; ; ) {
|
|
984
|
-
const { done: o, value: u } = await
|
|
985
|
-
if (o ||
|
|
986
|
-
|
|
987
|
-
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(`
|
|
988
1185
|
`);
|
|
989
|
-
|
|
990
|
-
for (const l of
|
|
991
|
-
const
|
|
992
|
-
if (!
|
|
1186
|
+
r = p.pop() || "";
|
|
1187
|
+
for (const l of p) {
|
|
1188
|
+
const h = l.trim();
|
|
1189
|
+
if (!h) {
|
|
993
1190
|
a = null;
|
|
994
1191
|
continue;
|
|
995
1192
|
}
|
|
996
|
-
if (
|
|
997
|
-
if (
|
|
998
|
-
a =
|
|
1193
|
+
if (h !== ": ping") {
|
|
1194
|
+
if (h.startsWith("event:")) {
|
|
1195
|
+
a = h.substring(6).trim();
|
|
999
1196
|
continue;
|
|
1000
1197
|
}
|
|
1001
|
-
if (
|
|
1002
|
-
const
|
|
1003
|
-
if (
|
|
1198
|
+
if (h.startsWith("data:")) {
|
|
1199
|
+
const d = h.substring(5).trim();
|
|
1200
|
+
if (d === "eof" || h === "eof")
|
|
1004
1201
|
break;
|
|
1005
1202
|
try {
|
|
1006
|
-
const
|
|
1203
|
+
const f = JSON.parse(d);
|
|
1007
1204
|
if (a && this.shouldProcessEvent(a)) {
|
|
1008
|
-
const
|
|
1205
|
+
const m = this.convertEvent({
|
|
1009
1206
|
event: a,
|
|
1010
|
-
data:
|
|
1207
|
+
data: f
|
|
1011
1208
|
});
|
|
1012
|
-
|
|
1209
|
+
m && (yield m);
|
|
1013
1210
|
}
|
|
1014
1211
|
} catch {
|
|
1015
1212
|
}
|
|
@@ -1019,33 +1216,35 @@ class yt {
|
|
|
1019
1216
|
}
|
|
1020
1217
|
}
|
|
1021
1218
|
} finally {
|
|
1022
|
-
|
|
1219
|
+
t.releaseLock();
|
|
1023
1220
|
}
|
|
1024
1221
|
}
|
|
1025
1222
|
}
|
|
1026
1223
|
export {
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
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,
|
|
1032
1233
|
W as PluginRegistry,
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
lt as useThreadList,
|
|
1049
|
-
ft as useThreadListState
|
|
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,
|
|
1244
|
+
q as useContentRenderer,
|
|
1245
|
+
ne as useCurrentThread,
|
|
1246
|
+
ye as useMessages,
|
|
1247
|
+
ge as useThreadList,
|
|
1248
|
+
be as useThreadListState
|
|
1050
1249
|
};
|
|
1051
1250
|
//# sourceMappingURL=index.js.map
|