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