@harnessio/ai-chat-core 0.0.16 → 0.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +371 -304
- package/dist/index.js.map +1 -1
- package/dist/runtime/ThreadRuntime/ThreadRuntime.d.ts +7 -0
- package/dist/runtime/ThreadRuntime/ThreadRuntimeCore.d.ts +9 -1
- package/dist/types/adapters.d.ts +12 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/thread.d.ts +1 -0
- package/dist/utils/BaseSSEStreamAdapter.d.ts +3 -7
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var u = (i,
|
|
4
|
-
import
|
|
1
|
+
var H = Object.defineProperty;
|
|
2
|
+
var J = (i, n, t) => n in i ? H(i, n, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[n] = t;
|
|
3
|
+
var u = (i, n, t) => J(i, typeof n != "symbol" ? n + "" : n, t);
|
|
4
|
+
import U, { createContext as B, useContext as q, useState as b, useEffect as w, useReducer as z, useCallback as C, useMemo as V } from "react";
|
|
5
5
|
class G {
|
|
6
6
|
constructor() {
|
|
7
7
|
u(this, "plugins", /* @__PURE__ */ new Map());
|
|
8
8
|
u(this, "renderersByType", /* @__PURE__ */ new Map());
|
|
9
9
|
}
|
|
10
|
-
registerPlugin(
|
|
11
|
-
this.plugins.has(
|
|
10
|
+
registerPlugin(n) {
|
|
11
|
+
this.plugins.has(n.id), this.plugins.set(n.id, n), n.renderers.forEach((t) => {
|
|
12
12
|
const e = this.renderersByType.get(t.type) || [];
|
|
13
|
-
e.push(t), e.sort((s,
|
|
13
|
+
e.push(t), e.sort((s, r) => ((r == null ? void 0 : r.priority) ?? 0) - ((s == null ? void 0 : s.priority) ?? 0)), this.renderersByType.set(t.type, e);
|
|
14
14
|
});
|
|
15
15
|
}
|
|
16
|
-
unregisterPlugin(
|
|
17
|
-
const t = this.plugins.get(
|
|
16
|
+
unregisterPlugin(n) {
|
|
17
|
+
const t = this.plugins.get(n);
|
|
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(n)) : !1;
|
|
22
22
|
}
|
|
23
|
-
getPlugin(
|
|
24
|
-
return this.plugins.get(
|
|
23
|
+
getPlugin(n) {
|
|
24
|
+
return this.plugins.get(n);
|
|
25
25
|
}
|
|
26
26
|
getAllPlugins() {
|
|
27
27
|
return Array.from(this.plugins.values());
|
|
28
28
|
}
|
|
29
|
-
getRenderersByType(
|
|
30
|
-
return this.renderersByType.get(
|
|
29
|
+
getRenderersByType(n) {
|
|
30
|
+
return this.renderersByType.get(n) || [];
|
|
31
31
|
}
|
|
32
|
-
getBestRendererForType(
|
|
33
|
-
return this.getRenderersByType(
|
|
32
|
+
getBestRendererForType(n) {
|
|
33
|
+
return this.getRenderersByType(n)[0];
|
|
34
34
|
}
|
|
35
35
|
clear() {
|
|
36
36
|
this.plugins.clear(), this.renderersByType.clear();
|
|
@@ -41,29 +41,29 @@ class Y {
|
|
|
41
41
|
u(this, "handlers", /* @__PURE__ */ new Map());
|
|
42
42
|
u(this, "renderers", /* @__PURE__ */ new Map());
|
|
43
43
|
}
|
|
44
|
-
registerHandler(
|
|
45
|
-
this.handlers.set(
|
|
44
|
+
registerHandler(n, t) {
|
|
45
|
+
this.handlers.set(n, t);
|
|
46
46
|
}
|
|
47
|
-
registerRenderer(
|
|
48
|
-
this.renderers.set(
|
|
47
|
+
registerRenderer(n, t) {
|
|
48
|
+
this.renderers.set(n, t);
|
|
49
49
|
}
|
|
50
|
-
unregister(
|
|
51
|
-
this.handlers.delete(
|
|
50
|
+
unregister(n) {
|
|
51
|
+
this.handlers.delete(n), this.renderers.delete(n);
|
|
52
52
|
}
|
|
53
|
-
getHandler(
|
|
54
|
-
return this.handlers.get(
|
|
53
|
+
getHandler(n) {
|
|
54
|
+
return this.handlers.get(n);
|
|
55
55
|
}
|
|
56
|
-
getRenderer(
|
|
57
|
-
return this.renderers.get(
|
|
56
|
+
getRenderer(n) {
|
|
57
|
+
return this.renderers.get(n);
|
|
58
58
|
}
|
|
59
59
|
getStrategy() {
|
|
60
60
|
return "queue";
|
|
61
61
|
}
|
|
62
|
-
hasHandler(
|
|
63
|
-
return this.handlers.has(
|
|
62
|
+
hasHandler(n) {
|
|
63
|
+
return this.handlers.has(n);
|
|
64
64
|
}
|
|
65
|
-
hasRenderer(
|
|
66
|
-
return this.renderers.has(
|
|
65
|
+
hasRenderer(n) {
|
|
66
|
+
return this.renderers.has(n);
|
|
67
67
|
}
|
|
68
68
|
clear() {
|
|
69
69
|
this.handlers.clear(), this.renderers.clear();
|
|
@@ -73,29 +73,29 @@ class Y {
|
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
class K {
|
|
76
|
-
constructor(
|
|
76
|
+
constructor(n) {
|
|
77
77
|
u(this, "executions", /* @__PURE__ */ new Map());
|
|
78
78
|
u(this, "executionQueue", []);
|
|
79
79
|
u(this, "isProcessing", !1);
|
|
80
80
|
u(this, "runningByName", /* @__PURE__ */ new Map());
|
|
81
81
|
u(this, "subscribers", /* @__PURE__ */ new Set());
|
|
82
82
|
u(this, "getHandler");
|
|
83
|
-
this.getHandler =
|
|
83
|
+
this.getHandler = n;
|
|
84
84
|
}
|
|
85
|
-
async executeCapability(
|
|
86
|
-
if (!this.getHandler(
|
|
87
|
-
console.warn(`No handler registered for capability: ${
|
|
85
|
+
async executeCapability(n, t, e, s, r = "queue") {
|
|
86
|
+
if (!this.getHandler(n)) {
|
|
87
|
+
console.warn(`No handler registered for capability: ${n}`);
|
|
88
88
|
return;
|
|
89
89
|
}
|
|
90
90
|
const o = {
|
|
91
91
|
id: t,
|
|
92
|
-
name:
|
|
92
|
+
name: n,
|
|
93
93
|
args: e,
|
|
94
94
|
status: { type: "queued" },
|
|
95
95
|
timestamp: Date.now(),
|
|
96
96
|
messageId: s
|
|
97
97
|
};
|
|
98
|
-
switch (this.executions.set(t, o), this.notifySubscribers(t),
|
|
98
|
+
switch (this.executions.set(t, o), this.notifySubscribers(t), r) {
|
|
99
99
|
case "queue":
|
|
100
100
|
default:
|
|
101
101
|
this.executionQueue.push(t);
|
|
@@ -106,64 +106,64 @@ class K {
|
|
|
106
106
|
async processQueue() {
|
|
107
107
|
if (!(this.isProcessing || this.executionQueue.length === 0)) {
|
|
108
108
|
for (this.isProcessing = !0; this.executionQueue.length > 0; ) {
|
|
109
|
-
const
|
|
109
|
+
const n = this.executionQueue.shift(), t = this.executions.get(n);
|
|
110
110
|
if (!t) continue;
|
|
111
111
|
const e = this.getHandler(t.name);
|
|
112
112
|
if (!e) continue;
|
|
113
|
-
t.status = { type: "running" }, this.notifySubscribers(
|
|
113
|
+
t.status = { type: "running" }, this.notifySubscribers(n);
|
|
114
114
|
const s = this.runningByName.get(t.name) || [];
|
|
115
|
-
s.push(
|
|
115
|
+
s.push(n), this.runningByName.set(t.name, s);
|
|
116
116
|
try {
|
|
117
|
-
const
|
|
117
|
+
const r = await e.execute(t.args, {
|
|
118
118
|
messageId: t.messageId,
|
|
119
|
-
capabilityId:
|
|
119
|
+
capabilityId: n
|
|
120
120
|
});
|
|
121
|
-
t.status = { type: "complete", result:
|
|
122
|
-
} catch (
|
|
123
|
-
const a =
|
|
121
|
+
t.status = { type: "complete", result: r }, t.result = r;
|
|
122
|
+
} catch (r) {
|
|
123
|
+
const a = r instanceof Error ? r.message : "Unknown error";
|
|
124
124
|
t.status = { type: "error", error: a }, t.error = a;
|
|
125
125
|
} finally {
|
|
126
|
-
const
|
|
127
|
-
a > -1 &&
|
|
126
|
+
const r = this.runningByName.get(t.name) || [], a = r.indexOf(n);
|
|
127
|
+
a > -1 && r.splice(a, 1), r.length === 0 ? this.runningByName.delete(t.name) : this.runningByName.set(t.name, r), this.notifySubscribers(n);
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
130
|
this.isProcessing = !1;
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
|
-
getExecution(
|
|
134
|
-
return this.executions.get(
|
|
133
|
+
getExecution(n) {
|
|
134
|
+
return this.executions.get(n);
|
|
135
135
|
}
|
|
136
|
-
getExecutionsByMessage(
|
|
137
|
-
return Array.from(this.executions.values()).filter((t) => t.messageId ===
|
|
136
|
+
getExecutionsByMessage(n) {
|
|
137
|
+
return Array.from(this.executions.values()).filter((t) => t.messageId === n);
|
|
138
138
|
}
|
|
139
|
-
subscribe(
|
|
140
|
-
return this.subscribers.add(
|
|
139
|
+
subscribe(n) {
|
|
140
|
+
return this.subscribers.add(n), () => this.subscribers.delete(n);
|
|
141
141
|
}
|
|
142
|
-
notifySubscribers(
|
|
143
|
-
this.subscribers.forEach((t) => t(
|
|
142
|
+
notifySubscribers(n) {
|
|
143
|
+
this.subscribers.forEach((t) => t(n));
|
|
144
144
|
}
|
|
145
145
|
clear() {
|
|
146
146
|
this.executions.clear(), this.executionQueue = [], this.runningByName.clear();
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
|
-
class
|
|
149
|
+
class m {
|
|
150
150
|
constructor() {
|
|
151
151
|
u(this, "_subscriptions", /* @__PURE__ */ new Set());
|
|
152
152
|
}
|
|
153
|
-
subscribe(
|
|
154
|
-
return this._subscriptions.add(
|
|
155
|
-
this._subscriptions.delete(
|
|
153
|
+
subscribe(n) {
|
|
154
|
+
return this._subscriptions.add(n), () => {
|
|
155
|
+
this._subscriptions.delete(n);
|
|
156
156
|
};
|
|
157
157
|
}
|
|
158
158
|
notifySubscribers() {
|
|
159
|
-
for (const
|
|
160
|
-
|
|
159
|
+
for (const n of this._subscriptions)
|
|
160
|
+
n();
|
|
161
161
|
}
|
|
162
162
|
getSubscriberCount() {
|
|
163
163
|
return this._subscriptions.size;
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
|
-
class X extends
|
|
166
|
+
class X extends m {
|
|
167
167
|
constructor() {
|
|
168
168
|
super(...arguments);
|
|
169
169
|
u(this, "_state", {
|
|
@@ -196,10 +196,10 @@ class X extends y {
|
|
|
196
196
|
get focusedContentIndex() {
|
|
197
197
|
return this._state.focusedContentIndex;
|
|
198
198
|
}
|
|
199
|
-
focus(t, e, s,
|
|
199
|
+
focus(t, e, s, r = "detail") {
|
|
200
200
|
this._state = {
|
|
201
201
|
isActive: !0,
|
|
202
|
-
context:
|
|
202
|
+
context: r,
|
|
203
203
|
focusedContent: t,
|
|
204
204
|
focusedMessage: e,
|
|
205
205
|
focusedMessageId: e.id,
|
|
@@ -216,8 +216,8 @@ class X extends y {
|
|
|
216
216
|
focusedContentIndex: null
|
|
217
217
|
}, this.notifySubscribers();
|
|
218
218
|
}
|
|
219
|
-
toggle(t, e, s,
|
|
220
|
-
this._state.isActive && this._state.focusedMessageId === e.id && this._state.focusedContentIndex === s && this._state.context ===
|
|
219
|
+
toggle(t, e, s, r = "detail") {
|
|
220
|
+
this._state.isActive && this._state.focusedMessageId === e.id && this._state.focusedContentIndex === s && this._state.context === r ? this.blur() : this.focus(t, e, s, r);
|
|
221
221
|
}
|
|
222
222
|
switchContext(t) {
|
|
223
223
|
this._state.isActive && this._state.focusedContent && (this._state = {
|
|
@@ -229,10 +229,10 @@ class X extends y {
|
|
|
229
229
|
if (!this._state.focusedMessageId || !t.length) return;
|
|
230
230
|
const e = t.findIndex((a) => a.id === this._state.focusedMessageId);
|
|
231
231
|
if (e === -1) return;
|
|
232
|
-
const s = t[e],
|
|
233
|
-
if (
|
|
234
|
-
const a = s.content[
|
|
235
|
-
this.focus(a, s,
|
|
232
|
+
const s = t[e], r = this._state.focusedContentIndex ?? 0;
|
|
233
|
+
if (r + 1 < s.content.length) {
|
|
234
|
+
const a = s.content[r + 1];
|
|
235
|
+
this.focus(a, s, r + 1, this._state.context || "detail");
|
|
236
236
|
return;
|
|
237
237
|
}
|
|
238
238
|
if (e + 1 < t.length) {
|
|
@@ -244,10 +244,10 @@ class X extends y {
|
|
|
244
244
|
if (!this._state.focusedMessageId || !t.length) return;
|
|
245
245
|
const e = t.findIndex((a) => a.id === this._state.focusedMessageId);
|
|
246
246
|
if (e === -1) return;
|
|
247
|
-
const s = t[e],
|
|
248
|
-
if (
|
|
249
|
-
const a = s.content[
|
|
250
|
-
this.focus(a, s,
|
|
247
|
+
const s = t[e], r = this._state.focusedContentIndex ?? 0;
|
|
248
|
+
if (r > 0) {
|
|
249
|
+
const a = s.content[r - 1];
|
|
250
|
+
this.focus(a, s, r - 1, this._state.context || "detail");
|
|
251
251
|
return;
|
|
252
252
|
}
|
|
253
253
|
if (e > 0) {
|
|
@@ -260,13 +260,13 @@ class X extends y {
|
|
|
260
260
|
}
|
|
261
261
|
}
|
|
262
262
|
let Z = 0, tt = 0;
|
|
263
|
-
function
|
|
263
|
+
function I() {
|
|
264
264
|
return `msg-${Date.now()}-${++Z}`;
|
|
265
265
|
}
|
|
266
|
-
function
|
|
266
|
+
function N() {
|
|
267
267
|
return `thread-${Date.now()}-${++tt}`;
|
|
268
268
|
}
|
|
269
|
-
class
|
|
269
|
+
class v extends m {
|
|
270
270
|
constructor(t) {
|
|
271
271
|
super();
|
|
272
272
|
u(this, "_state");
|
|
@@ -294,7 +294,7 @@ class I extends y {
|
|
|
294
294
|
return super.subscribe(t);
|
|
295
295
|
}
|
|
296
296
|
}
|
|
297
|
-
class et extends
|
|
297
|
+
class et extends m {
|
|
298
298
|
constructor() {
|
|
299
299
|
super(...arguments);
|
|
300
300
|
u(this, "_text", "");
|
|
@@ -322,7 +322,7 @@ class et extends y {
|
|
|
322
322
|
this._isSubmitting = t, this.notifySubscribers();
|
|
323
323
|
}
|
|
324
324
|
}
|
|
325
|
-
class
|
|
325
|
+
class R extends m {
|
|
326
326
|
constructor(t) {
|
|
327
327
|
super();
|
|
328
328
|
u(this, "composer");
|
|
@@ -339,6 +339,12 @@ class v extends y {
|
|
|
339
339
|
get isDisabled() {
|
|
340
340
|
return this._core.isDisabled;
|
|
341
341
|
}
|
|
342
|
+
get isWaitingForUser() {
|
|
343
|
+
return this._core.isWaitingForUser;
|
|
344
|
+
}
|
|
345
|
+
get pendingCapability() {
|
|
346
|
+
return this._core.pendingCapability;
|
|
347
|
+
}
|
|
342
348
|
get capabilities() {
|
|
343
349
|
return this._core.capabilities;
|
|
344
350
|
}
|
|
@@ -354,6 +360,7 @@ class v extends y {
|
|
|
354
360
|
// Will be set by ThreadListRuntime
|
|
355
361
|
isDisabled: this._core.isDisabled,
|
|
356
362
|
isRunning: this._core.isRunning,
|
|
363
|
+
isWaitingForUser: this._core.isWaitingForUser,
|
|
357
364
|
capabilities: this._core.capabilities,
|
|
358
365
|
conversationId: this._core.conversationId,
|
|
359
366
|
title: this._core.title
|
|
@@ -366,7 +373,11 @@ class v extends y {
|
|
|
366
373
|
if (t.trim()) {
|
|
367
374
|
this.composer.setSubmitting(!0);
|
|
368
375
|
try {
|
|
369
|
-
this.
|
|
376
|
+
this._core.isWaitingForUser && this._core.pendingCapability && await this._core.startSystemEventRun({
|
|
377
|
+
event_type: "action_cancelled",
|
|
378
|
+
capability_id: this._core.pendingCapability.capabilityName,
|
|
379
|
+
result: { success: !1 }
|
|
380
|
+
}), this.composer.clear(), await this._core.startRun({
|
|
370
381
|
role: "user",
|
|
371
382
|
content: [{ type: "text", data: t }]
|
|
372
383
|
});
|
|
@@ -376,6 +387,12 @@ class v extends y {
|
|
|
376
387
|
}
|
|
377
388
|
}
|
|
378
389
|
}
|
|
390
|
+
async sendSystemEvent(t) {
|
|
391
|
+
try {
|
|
392
|
+
await this._core.startSystemEventRun(t);
|
|
393
|
+
} catch {
|
|
394
|
+
}
|
|
395
|
+
}
|
|
379
396
|
cancelRun() {
|
|
380
397
|
this._core.cancelRun();
|
|
381
398
|
}
|
|
@@ -395,12 +412,14 @@ class v extends y {
|
|
|
395
412
|
return super.subscribe(t);
|
|
396
413
|
}
|
|
397
414
|
}
|
|
398
|
-
class
|
|
415
|
+
class E extends m {
|
|
399
416
|
constructor(t) {
|
|
400
417
|
super();
|
|
401
418
|
u(this, "_messages", []);
|
|
402
419
|
u(this, "_isRunning", !1);
|
|
403
420
|
u(this, "_isDisabled", !1);
|
|
421
|
+
u(this, "_isWaitingForUser", !1);
|
|
422
|
+
u(this, "_pendingCapability", null);
|
|
404
423
|
u(this, "_abortController", null);
|
|
405
424
|
u(this, "_conversationId");
|
|
406
425
|
u(this, "_title");
|
|
@@ -417,6 +436,12 @@ class R extends y {
|
|
|
417
436
|
get isDisabled() {
|
|
418
437
|
return this._isDisabled;
|
|
419
438
|
}
|
|
439
|
+
get isWaitingForUser() {
|
|
440
|
+
return this._isWaitingForUser;
|
|
441
|
+
}
|
|
442
|
+
get pendingCapability() {
|
|
443
|
+
return this._pendingCapability;
|
|
444
|
+
}
|
|
420
445
|
get conversationId() {
|
|
421
446
|
return this._conversationId;
|
|
422
447
|
}
|
|
@@ -439,7 +464,7 @@ class R extends y {
|
|
|
439
464
|
}
|
|
440
465
|
append(t) {
|
|
441
466
|
const e = {
|
|
442
|
-
id: t.id ||
|
|
467
|
+
id: t.id || I(),
|
|
443
468
|
parentId: t.parentId,
|
|
444
469
|
role: t.role,
|
|
445
470
|
content: t.content,
|
|
@@ -449,11 +474,50 @@ class R extends y {
|
|
|
449
474
|
};
|
|
450
475
|
this.updateMessages([...this._messages, e]);
|
|
451
476
|
}
|
|
477
|
+
async startSystemEventRun(t) {
|
|
478
|
+
if (this._isRunning)
|
|
479
|
+
throw new Error("A run is already in progress");
|
|
480
|
+
this._isWaitingForUser = !1, this._pendingCapability = null, this._isRunning = !0, this._abortController = new AbortController(), this._currentPart = null;
|
|
481
|
+
const e = I(), s = {
|
|
482
|
+
id: e,
|
|
483
|
+
role: "assistant",
|
|
484
|
+
content: [],
|
|
485
|
+
status: { type: "running" },
|
|
486
|
+
timestamp: Date.now()
|
|
487
|
+
};
|
|
488
|
+
this.updateMessages([...this._messages, s]);
|
|
489
|
+
try {
|
|
490
|
+
const r = this.config.streamAdapter.stream({
|
|
491
|
+
messages: this._messages,
|
|
492
|
+
conversationId: this._conversationId,
|
|
493
|
+
signal: this._abortController.signal,
|
|
494
|
+
systemEvent: t
|
|
495
|
+
});
|
|
496
|
+
for await (const a of r) {
|
|
497
|
+
if (this._abortController.signal.aborted)
|
|
498
|
+
break;
|
|
499
|
+
this.handleStreamEvent(e, a.event);
|
|
500
|
+
}
|
|
501
|
+
this.updateMessageStatus(e, { type: "complete" });
|
|
502
|
+
} catch (r) {
|
|
503
|
+
if (r instanceof Error && r.name === "AbortError")
|
|
504
|
+
this.completeStreamingContent(e), this.updateMessageStatus(e, { type: "cancelled" });
|
|
505
|
+
else {
|
|
506
|
+
const a = r instanceof Error ? r.message : "Unknown error";
|
|
507
|
+
this.completeStreamingContent(e), this.updateMessageStatus(e, {
|
|
508
|
+
type: "error",
|
|
509
|
+
error: a
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
} finally {
|
|
513
|
+
this._isRunning = !1, this._abortController = null, this._currentPart = null, this.notifySubscribers();
|
|
514
|
+
}
|
|
515
|
+
}
|
|
452
516
|
async startRun(t) {
|
|
453
517
|
if (this._isRunning)
|
|
454
518
|
throw new Error("A run is already in progress");
|
|
455
|
-
this.append(t), this._isRunning = !0, this._abortController = new AbortController(), this._currentPart = null;
|
|
456
|
-
const e =
|
|
519
|
+
this._isWaitingForUser = !1, this._pendingCapability = null, this.append(t), this._isRunning = !0, this._abortController = new AbortController(), this._currentPart = null;
|
|
520
|
+
const e = I(), s = {
|
|
457
521
|
id: e,
|
|
458
522
|
role: "assistant",
|
|
459
523
|
content: [],
|
|
@@ -462,22 +526,22 @@ class R extends y {
|
|
|
462
526
|
};
|
|
463
527
|
this.updateMessages([...this._messages, s]);
|
|
464
528
|
try {
|
|
465
|
-
const
|
|
529
|
+
const r = this.config.streamAdapter.stream({
|
|
466
530
|
messages: this._messages,
|
|
467
531
|
conversationId: this._conversationId,
|
|
468
532
|
signal: this._abortController.signal
|
|
469
533
|
});
|
|
470
|
-
for await (const a of
|
|
534
|
+
for await (const a of r) {
|
|
471
535
|
if (this._abortController.signal.aborted)
|
|
472
536
|
break;
|
|
473
537
|
this.handleStreamEvent(e, a.event);
|
|
474
538
|
}
|
|
475
539
|
this.updateMessageStatus(e, { type: "complete" });
|
|
476
|
-
} catch (
|
|
477
|
-
if (
|
|
540
|
+
} catch (r) {
|
|
541
|
+
if (r instanceof Error && r.name === "AbortError")
|
|
478
542
|
this.completeStreamingContent(e), this.updateMessageStatus(e, { type: "cancelled" });
|
|
479
543
|
else {
|
|
480
|
-
const a =
|
|
544
|
+
const a = r instanceof Error ? r.message : "Unknown error";
|
|
481
545
|
this.completeStreamingContent(e), this.updateMessageStatus(e, {
|
|
482
546
|
type: "error",
|
|
483
547
|
error: a
|
|
@@ -490,17 +554,17 @@ class R extends y {
|
|
|
490
554
|
handleStreamEvent(t, e) {
|
|
491
555
|
const s = this._messages.findIndex((o) => o.id === t);
|
|
492
556
|
if (s === -1) return;
|
|
493
|
-
const
|
|
557
|
+
const r = this._messages[s];
|
|
494
558
|
if (e.type === "part-start")
|
|
495
|
-
this.handlePartStart(
|
|
559
|
+
this.handlePartStart(r, e);
|
|
496
560
|
else if (e.type === "text-delta" || e.type === "assistant_thought")
|
|
497
|
-
this.handleTextDelta(
|
|
561
|
+
this.handleTextDelta(r, e);
|
|
498
562
|
else if (e.type === "part-finish")
|
|
499
563
|
this.handlePartFinish();
|
|
500
564
|
else if (e.type === "metadata") {
|
|
501
565
|
const o = e;
|
|
502
|
-
|
|
503
|
-
...
|
|
566
|
+
r.metadata = {
|
|
567
|
+
...r.metadata,
|
|
504
568
|
conversationId: o.conversationId,
|
|
505
569
|
interactionId: o.interactionId
|
|
506
570
|
}, o.conversationId && !this._conversationId && (this._conversationId = o.conversationId), o.title && !this._title && (this._title = o.title);
|
|
@@ -511,9 +575,9 @@ class R extends y {
|
|
|
511
575
|
capabilityName: o.capabilityName,
|
|
512
576
|
args: o.args
|
|
513
577
|
};
|
|
514
|
-
|
|
578
|
+
r.content.push(c);
|
|
515
579
|
const d = o.artifact;
|
|
516
|
-
d &&
|
|
580
|
+
d && r.content.push({
|
|
517
581
|
type: "artifact",
|
|
518
582
|
data: {
|
|
519
583
|
capabilityName: o.capabilityName,
|
|
@@ -529,11 +593,14 @@ class R extends y {
|
|
|
529
593
|
o.args,
|
|
530
594
|
t,
|
|
531
595
|
o.strategy
|
|
532
|
-
)
|
|
596
|
+
), o.status === "waiting_for_user" && (this._isWaitingForUser = !0, this._pendingCapability = {
|
|
597
|
+
capabilityId: o.capabilityId,
|
|
598
|
+
capabilityName: o.capabilityName
|
|
599
|
+
});
|
|
533
600
|
} else if (e.type === "error") {
|
|
534
601
|
const o = e;
|
|
535
|
-
|
|
536
|
-
...
|
|
602
|
+
r.content = [
|
|
603
|
+
...r.content,
|
|
537
604
|
{
|
|
538
605
|
type: "error",
|
|
539
606
|
data: o.error
|
|
@@ -541,8 +608,8 @@ class R extends y {
|
|
|
541
608
|
];
|
|
542
609
|
} else {
|
|
543
610
|
const o = e;
|
|
544
|
-
|
|
545
|
-
...
|
|
611
|
+
r.content = [
|
|
612
|
+
...r.content,
|
|
546
613
|
{
|
|
547
614
|
type: o.type,
|
|
548
615
|
data: o.data,
|
|
@@ -552,17 +619,17 @@ class R extends y {
|
|
|
552
619
|
}
|
|
553
620
|
const a = [
|
|
554
621
|
...this._messages.slice(0, s),
|
|
555
|
-
{ ...
|
|
622
|
+
{ ...r, timestamp: Date.now() },
|
|
556
623
|
...this._messages.slice(s + 1)
|
|
557
624
|
];
|
|
558
625
|
this.updateMessages(a);
|
|
559
626
|
}
|
|
560
627
|
handlePartStart(t, e) {
|
|
561
628
|
const s = t.content.length;
|
|
562
|
-
let
|
|
629
|
+
let r;
|
|
563
630
|
switch (e.part.type) {
|
|
564
631
|
case "assistant_thought":
|
|
565
|
-
|
|
632
|
+
r = {
|
|
566
633
|
type: e.part.type,
|
|
567
634
|
data: [],
|
|
568
635
|
parentId: e.part.parentId,
|
|
@@ -570,7 +637,7 @@ class R extends y {
|
|
|
570
637
|
};
|
|
571
638
|
break;
|
|
572
639
|
case "text":
|
|
573
|
-
|
|
640
|
+
r = {
|
|
574
641
|
type: e.part.type,
|
|
575
642
|
data: "",
|
|
576
643
|
parentId: e.part.parentId,
|
|
@@ -578,13 +645,13 @@ class R extends y {
|
|
|
578
645
|
};
|
|
579
646
|
break;
|
|
580
647
|
default:
|
|
581
|
-
|
|
648
|
+
r = {
|
|
582
649
|
type: e.part.type,
|
|
583
650
|
parentId: e.part.parentId,
|
|
584
651
|
status: { type: "streaming" }
|
|
585
652
|
};
|
|
586
653
|
}
|
|
587
|
-
t.content = [...t.content,
|
|
654
|
+
t.content = [...t.content, r], this._currentPart = {
|
|
588
655
|
messageId: t.id,
|
|
589
656
|
contentIndex: s,
|
|
590
657
|
type: e.part.type,
|
|
@@ -609,12 +676,12 @@ class R extends y {
|
|
|
609
676
|
const e = this._messages[t], s = e.content[this._currentPart.contentIndex];
|
|
610
677
|
if (s) {
|
|
611
678
|
s.status = { type: "complete" };
|
|
612
|
-
const
|
|
679
|
+
const r = [
|
|
613
680
|
...this._messages.slice(0, t),
|
|
614
681
|
{ ...e, timestamp: Date.now() },
|
|
615
682
|
...this._messages.slice(t + 1)
|
|
616
683
|
];
|
|
617
|
-
this.updateMessages(
|
|
684
|
+
this.updateMessages(r);
|
|
618
685
|
}
|
|
619
686
|
}
|
|
620
687
|
this._currentPart = null;
|
|
@@ -622,7 +689,7 @@ class R extends y {
|
|
|
622
689
|
updateMessageStatus(t, e) {
|
|
623
690
|
const s = this._messages.findIndex((a) => a.id === t);
|
|
624
691
|
if (s === -1) return;
|
|
625
|
-
const
|
|
692
|
+
const r = [
|
|
626
693
|
...this._messages.slice(0, s),
|
|
627
694
|
{
|
|
628
695
|
...this._messages[s],
|
|
@@ -630,7 +697,7 @@ class R extends y {
|
|
|
630
697
|
},
|
|
631
698
|
...this._messages.slice(s + 1)
|
|
632
699
|
];
|
|
633
|
-
this.updateMessages(
|
|
700
|
+
this.updateMessages(r);
|
|
634
701
|
}
|
|
635
702
|
completeStreamingContent(t) {
|
|
636
703
|
const e = this._messages.findIndex((c) => c.id === t);
|
|
@@ -666,7 +733,7 @@ class R extends y {
|
|
|
666
733
|
this._title = t, this.notifySubscribers();
|
|
667
734
|
}
|
|
668
735
|
}
|
|
669
|
-
class st extends
|
|
736
|
+
class st extends m {
|
|
670
737
|
constructor(t) {
|
|
671
738
|
super();
|
|
672
739
|
u(this, "_mainThreadId");
|
|
@@ -677,12 +744,12 @@ class st extends y {
|
|
|
677
744
|
u(this, "_searchQuery");
|
|
678
745
|
u(this, "_abortController", null);
|
|
679
746
|
u(this, "main");
|
|
680
|
-
this.config = t, this._mainThreadId =
|
|
681
|
-
const e = new
|
|
747
|
+
this.config = t, this._mainThreadId = N();
|
|
748
|
+
const e = new E({
|
|
682
749
|
streamAdapter: t.streamAdapter,
|
|
683
750
|
capabilityExecutionManager: t.capabilityExecutionManager
|
|
684
751
|
});
|
|
685
|
-
this.main = new
|
|
752
|
+
this.main = new R(e), this._threads.set(this._mainThreadId, this.main);
|
|
686
753
|
const s = {
|
|
687
754
|
id: this._mainThreadId,
|
|
688
755
|
title: "New Chat",
|
|
@@ -692,13 +759,13 @@ class st extends y {
|
|
|
692
759
|
updatedAt: Date.now()
|
|
693
760
|
};
|
|
694
761
|
this._threadStates.set(this._mainThreadId, s);
|
|
695
|
-
const
|
|
762
|
+
const r = new v({
|
|
696
763
|
state: s,
|
|
697
764
|
onSwitchTo: this.switchToThread.bind(this),
|
|
698
765
|
onRename: this.renameThread.bind(this),
|
|
699
766
|
onDelete: this.deleteThread.bind(this)
|
|
700
767
|
});
|
|
701
|
-
this._threadItems.set(this._mainThreadId,
|
|
768
|
+
this._threadItems.set(this._mainThreadId, r);
|
|
702
769
|
}
|
|
703
770
|
get isLoading() {
|
|
704
771
|
return this._isLoading;
|
|
@@ -712,8 +779,8 @@ class st extends y {
|
|
|
712
779
|
}
|
|
713
780
|
getState() {
|
|
714
781
|
const t = [], e = {};
|
|
715
|
-
for (const [s,
|
|
716
|
-
e[s] =
|
|
782
|
+
for (const [s, r] of this._threadStates)
|
|
783
|
+
e[s] = r, r.status.type === "regular" && t.push(s);
|
|
717
784
|
return {
|
|
718
785
|
mainThreadId: this._mainThreadId,
|
|
719
786
|
threads: t,
|
|
@@ -729,8 +796,8 @@ class st extends y {
|
|
|
729
796
|
throw new Error(`Thread ${t} not found`);
|
|
730
797
|
const s = this._threadStates.get(this._mainThreadId);
|
|
731
798
|
s && (s.isMain = !1, this._threadStates.set(this._mainThreadId, s), (a = this._threadItems.get(this._mainThreadId)) == null || a.updateState(s)), this._mainThreadId = t;
|
|
732
|
-
const
|
|
733
|
-
if (
|
|
799
|
+
const r = this._threadStates.get(t);
|
|
800
|
+
if (r && (r.isMain = !0, this._threadStates.set(t, r), (o = this._threadItems.get(t)) == null || o.updateState(r), e.setConversationId(r.conversationId), e.setTitle(r.title)), this.config.threadListAdapter && (r != null && r.conversationId)) {
|
|
734
801
|
this._isLoading = !0, this.notifySubscribers();
|
|
735
802
|
try {
|
|
736
803
|
const c = await this.config.threadListAdapter.loadThread(t);
|
|
@@ -744,12 +811,12 @@ class st extends y {
|
|
|
744
811
|
this.notifySubscribers();
|
|
745
812
|
}
|
|
746
813
|
async switchToNewThread() {
|
|
747
|
-
const t =
|
|
814
|
+
const t = N(), e = new E({
|
|
748
815
|
streamAdapter: this.config.streamAdapter,
|
|
749
816
|
capabilityExecutionManager: this.config.capabilityExecutionManager
|
|
750
|
-
}), s = new
|
|
817
|
+
}), s = new R(e);
|
|
751
818
|
this._threads.set(t, s);
|
|
752
|
-
const
|
|
819
|
+
const r = {
|
|
753
820
|
id: t,
|
|
754
821
|
title: "New Chat",
|
|
755
822
|
status: { type: "regular" },
|
|
@@ -757,9 +824,9 @@ class st extends y {
|
|
|
757
824
|
createdAt: Date.now(),
|
|
758
825
|
updatedAt: Date.now()
|
|
759
826
|
};
|
|
760
|
-
this._threadStates.set(t,
|
|
761
|
-
const a = new
|
|
762
|
-
state:
|
|
827
|
+
this._threadStates.set(t, r);
|
|
828
|
+
const a = new v({
|
|
829
|
+
state: r,
|
|
763
830
|
onSwitchTo: this.switchToThread.bind(this),
|
|
764
831
|
onRename: this.renameThread.bind(this),
|
|
765
832
|
onDelete: this.deleteThread.bind(this)
|
|
@@ -769,7 +836,7 @@ class st extends y {
|
|
|
769
836
|
}), this.config.threadListAdapter)
|
|
770
837
|
try {
|
|
771
838
|
const o = await this.config.threadListAdapter.createThread();
|
|
772
|
-
|
|
839
|
+
r.conversationId = o.conversationId, this._threadStates.set(t, r), a.updateState(r);
|
|
773
840
|
} catch (o) {
|
|
774
841
|
console.error("Failed to create thread:", o);
|
|
775
842
|
}
|
|
@@ -791,12 +858,12 @@ class st extends y {
|
|
|
791
858
|
for (const s of e) {
|
|
792
859
|
if (this._threadStates.has(s.id))
|
|
793
860
|
continue;
|
|
794
|
-
const
|
|
861
|
+
const r = new E({
|
|
795
862
|
streamAdapter: this.config.streamAdapter,
|
|
796
863
|
capabilityExecutionManager: this.config.capabilityExecutionManager
|
|
797
|
-
}), a = new
|
|
864
|
+
}), a = new R(r);
|
|
798
865
|
this._threads.set(s.id, a), this._threadStates.set(s.id, s);
|
|
799
|
-
const o = new
|
|
866
|
+
const o = new v({
|
|
800
867
|
state: s,
|
|
801
868
|
onSwitchTo: this.switchToThread.bind(this),
|
|
802
869
|
onRename: this.renameThread.bind(this),
|
|
@@ -817,15 +884,15 @@ class st extends y {
|
|
|
817
884
|
* Syncs conversationId and title from thread runtime to thread state
|
|
818
885
|
*/
|
|
819
886
|
syncThreadStateFromRuntime(t, e) {
|
|
820
|
-
var
|
|
887
|
+
var r;
|
|
821
888
|
const s = this._threadStates.get(t);
|
|
822
|
-
s && (s.conversationId !== e.conversationId || s.title !== e.title) && (s.conversationId = e.conversationId, s.title = e.title || s.title, s.updatedAt = Date.now(), this._threadStates.set(t, s), (
|
|
889
|
+
s && (s.conversationId !== e.conversationId || s.title !== e.title) && (s.conversationId = e.conversationId, s.title = e.title || s.title, s.updatedAt = Date.now(), this._threadStates.set(t, s), (r = this._threadItems.get(t)) == null || r.updateState(s));
|
|
823
890
|
}
|
|
824
891
|
async renameThread(t, e) {
|
|
825
|
-
var
|
|
892
|
+
var r;
|
|
826
893
|
const s = this._threadStates.get(t);
|
|
827
894
|
if (s) {
|
|
828
|
-
if (s.title = e, s.updatedAt = Date.now(), this._threadStates.set(t, s), (
|
|
895
|
+
if (s.title = e, s.updatedAt = Date.now(), this._threadStates.set(t, s), (r = this._threadItems.get(t)) == null || r.updateState(s), this.config.threadListAdapter)
|
|
829
896
|
try {
|
|
830
897
|
await this.config.threadListAdapter.updateThread(t, { title: e });
|
|
831
898
|
} catch (a) {
|
|
@@ -850,7 +917,7 @@ class st extends y {
|
|
|
850
917
|
this.notifySubscribers();
|
|
851
918
|
}
|
|
852
919
|
}
|
|
853
|
-
class bt extends
|
|
920
|
+
class bt extends m {
|
|
854
921
|
constructor(t) {
|
|
855
922
|
super();
|
|
856
923
|
u(this, "threads");
|
|
@@ -912,69 +979,69 @@ class bt extends y {
|
|
|
912
979
|
var e;
|
|
913
980
|
if (t.length !== 0 && !this._contentFocusRuntime.isActive)
|
|
914
981
|
for (let s = t.length - 1; s >= 0; s--) {
|
|
915
|
-
const
|
|
916
|
-
if (
|
|
917
|
-
for (let a =
|
|
918
|
-
const o =
|
|
982
|
+
const r = t[s];
|
|
983
|
+
if (r.role === "assistant")
|
|
984
|
+
for (let a = r.content.length - 1; a >= 0; a--) {
|
|
985
|
+
const o = r.content[a], c = this.pluginRegistry.getRenderersByType(o.type);
|
|
919
986
|
if (c.length > 0 && ((e = c[0].capabilities) != null && e.supportsFocus)) {
|
|
920
|
-
this._contentFocusRuntime.focus(o,
|
|
987
|
+
this._contentFocusRuntime.focus(o, r, a, "detail");
|
|
921
988
|
return;
|
|
922
989
|
}
|
|
923
990
|
}
|
|
924
991
|
}
|
|
925
992
|
}
|
|
926
993
|
}
|
|
927
|
-
var
|
|
994
|
+
var M = { exports: {} }, x = {};
|
|
928
995
|
/*
|
|
929
996
|
object-assign
|
|
930
997
|
(c) Sindre Sorhus
|
|
931
998
|
@license MIT
|
|
932
999
|
*/
|
|
933
|
-
var
|
|
1000
|
+
var A, D;
|
|
934
1001
|
function rt() {
|
|
935
|
-
if (
|
|
936
|
-
|
|
937
|
-
var i = Object.getOwnPropertySymbols,
|
|
938
|
-
function e(
|
|
939
|
-
if (
|
|
1002
|
+
if (D) return A;
|
|
1003
|
+
D = 1;
|
|
1004
|
+
var i = Object.getOwnPropertySymbols, n = Object.prototype.hasOwnProperty, t = Object.prototype.propertyIsEnumerable;
|
|
1005
|
+
function e(r) {
|
|
1006
|
+
if (r == null)
|
|
940
1007
|
throw new TypeError("Object.assign cannot be called with null or undefined");
|
|
941
|
-
return Object(
|
|
1008
|
+
return Object(r);
|
|
942
1009
|
}
|
|
943
1010
|
function s() {
|
|
944
1011
|
try {
|
|
945
1012
|
if (!Object.assign)
|
|
946
1013
|
return !1;
|
|
947
|
-
var
|
|
948
|
-
if (
|
|
1014
|
+
var r = new String("abc");
|
|
1015
|
+
if (r[5] = "de", Object.getOwnPropertyNames(r)[0] === "5")
|
|
949
1016
|
return !1;
|
|
950
1017
|
for (var a = {}, o = 0; o < 10; o++)
|
|
951
1018
|
a["_" + String.fromCharCode(o)] = o;
|
|
952
|
-
var c = Object.getOwnPropertyNames(a).map(function(
|
|
953
|
-
return a[
|
|
1019
|
+
var c = Object.getOwnPropertyNames(a).map(function(l) {
|
|
1020
|
+
return a[l];
|
|
954
1021
|
});
|
|
955
1022
|
if (c.join("") !== "0123456789")
|
|
956
1023
|
return !1;
|
|
957
1024
|
var d = {};
|
|
958
|
-
return "abcdefghijklmnopqrst".split("").forEach(function(
|
|
959
|
-
d[
|
|
1025
|
+
return "abcdefghijklmnopqrst".split("").forEach(function(l) {
|
|
1026
|
+
d[l] = l;
|
|
960
1027
|
}), Object.keys(Object.assign({}, d)).join("") === "abcdefghijklmnopqrst";
|
|
961
1028
|
} catch {
|
|
962
1029
|
return !1;
|
|
963
1030
|
}
|
|
964
1031
|
}
|
|
965
|
-
return
|
|
966
|
-
for (var o, c = e(
|
|
967
|
-
o = Object(arguments[
|
|
1032
|
+
return A = s() ? Object.assign : function(r, a) {
|
|
1033
|
+
for (var o, c = e(r), d, l = 1; l < arguments.length; l++) {
|
|
1034
|
+
o = Object(arguments[l]);
|
|
968
1035
|
for (var h in o)
|
|
969
|
-
|
|
1036
|
+
n.call(o, h) && (c[h] = o[h]);
|
|
970
1037
|
if (i) {
|
|
971
1038
|
d = i(o);
|
|
972
|
-
for (var
|
|
973
|
-
t.call(o, d[
|
|
1039
|
+
for (var g = 0; g < d.length; g++)
|
|
1040
|
+
t.call(o, d[g]) && (c[d[g]] = o[d[g]]);
|
|
974
1041
|
}
|
|
975
1042
|
}
|
|
976
1043
|
return c;
|
|
977
|
-
},
|
|
1044
|
+
}, A;
|
|
978
1045
|
}
|
|
979
1046
|
/** @license React v17.0.2
|
|
980
1047
|
* react-jsx-runtime.production.min.js
|
|
@@ -984,72 +1051,72 @@ function rt() {
|
|
|
984
1051
|
* This source code is licensed under the MIT license found in the
|
|
985
1052
|
* LICENSE file in the root directory of this source tree.
|
|
986
1053
|
*/
|
|
987
|
-
var
|
|
1054
|
+
var j;
|
|
988
1055
|
function nt() {
|
|
989
|
-
if (
|
|
990
|
-
|
|
991
|
-
var i =
|
|
1056
|
+
if (j) return x;
|
|
1057
|
+
j = 1, rt();
|
|
1058
|
+
var i = U, n = 60103;
|
|
992
1059
|
if (x.Fragment = 60107, typeof Symbol == "function" && Symbol.for) {
|
|
993
1060
|
var t = Symbol.for;
|
|
994
|
-
|
|
1061
|
+
n = t("react.element"), x.Fragment = t("react.fragment");
|
|
995
1062
|
}
|
|
996
|
-
var e = i.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, s = Object.prototype.hasOwnProperty,
|
|
1063
|
+
var e = i.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, s = Object.prototype.hasOwnProperty, r = { key: !0, ref: !0, __self: !0, __source: !0 };
|
|
997
1064
|
function a(o, c, d) {
|
|
998
|
-
var
|
|
999
|
-
d !== void 0 && (
|
|
1000
|
-
for (
|
|
1001
|
-
if (o && o.defaultProps) for (
|
|
1002
|
-
return { $$typeof:
|
|
1065
|
+
var l, h = {}, g = null, p = null;
|
|
1066
|
+
d !== void 0 && (g = "" + d), c.key !== void 0 && (g = "" + c.key), c.ref !== void 0 && (p = c.ref);
|
|
1067
|
+
for (l in c) s.call(c, l) && !r.hasOwnProperty(l) && (h[l] = c[l]);
|
|
1068
|
+
if (o && o.defaultProps) for (l in c = o.defaultProps, c) h[l] === void 0 && (h[l] = c[l]);
|
|
1069
|
+
return { $$typeof: n, type: o, key: g, ref: p, props: h, _owner: e.current };
|
|
1003
1070
|
}
|
|
1004
1071
|
return x.jsx = a, x.jsxs = a, x;
|
|
1005
1072
|
}
|
|
1006
1073
|
var O;
|
|
1007
1074
|
function it() {
|
|
1008
|
-
return O || (O = 1,
|
|
1075
|
+
return O || (O = 1, M.exports = nt()), M.exports;
|
|
1009
1076
|
}
|
|
1010
1077
|
var S = it();
|
|
1011
|
-
const
|
|
1012
|
-
function
|
|
1013
|
-
return /* @__PURE__ */ S.jsx(
|
|
1078
|
+
const W = B(null);
|
|
1079
|
+
function mt({ runtime: i, children: n }) {
|
|
1080
|
+
return /* @__PURE__ */ S.jsx(W.Provider, { value: i, children: n });
|
|
1014
1081
|
}
|
|
1015
1082
|
function at() {
|
|
1016
|
-
const i =
|
|
1083
|
+
const i = q(W);
|
|
1017
1084
|
if (!i)
|
|
1018
1085
|
throw new Error("useAssistantRuntimeContext must be used within AssistantRuntimeProvider");
|
|
1019
1086
|
return i;
|
|
1020
1087
|
}
|
|
1021
|
-
function
|
|
1088
|
+
function f() {
|
|
1022
1089
|
return at();
|
|
1023
1090
|
}
|
|
1024
1091
|
function _t() {
|
|
1025
|
-
const i =
|
|
1092
|
+
const i = f();
|
|
1026
1093
|
return {
|
|
1027
|
-
switchToThread: (
|
|
1094
|
+
switchToThread: (n) => i.threads.switchToThread(n),
|
|
1028
1095
|
switchToNewThread: () => i.threads.switchToNewThread(),
|
|
1029
|
-
loadThreads: (
|
|
1030
|
-
renameThread: (
|
|
1096
|
+
loadThreads: (n) => i.threads.loadThreads(n),
|
|
1097
|
+
renameThread: (n, t) => {
|
|
1031
1098
|
var e, s;
|
|
1032
|
-
return (s = (e = i.threads).renameThread) == null ? void 0 : s.call(e,
|
|
1099
|
+
return (s = (e = i.threads).renameThread) == null ? void 0 : s.call(e, n, t);
|
|
1033
1100
|
},
|
|
1034
|
-
deleteThread: (
|
|
1101
|
+
deleteThread: (n) => {
|
|
1035
1102
|
var t, e;
|
|
1036
|
-
return (e = (t = i.threads).deleteThread) == null ? void 0 : e.call(t,
|
|
1103
|
+
return (e = (t = i.threads).deleteThread) == null ? void 0 : e.call(t, n);
|
|
1037
1104
|
}
|
|
1038
1105
|
};
|
|
1039
1106
|
}
|
|
1040
1107
|
function xt() {
|
|
1041
|
-
const i =
|
|
1108
|
+
const i = f(), [n, t] = b(i.threads.getState());
|
|
1042
1109
|
return w(() => i.threads.subscribe(() => {
|
|
1043
1110
|
t(i.threads.getState());
|
|
1044
|
-
}), [i]),
|
|
1111
|
+
}), [i]), n;
|
|
1045
1112
|
}
|
|
1046
1113
|
function ot() {
|
|
1047
|
-
const
|
|
1048
|
-
return w(() =>
|
|
1114
|
+
const n = f().threads.getMainThread(), [, t] = b({});
|
|
1115
|
+
return w(() => n.subscribe(() => {
|
|
1049
1116
|
t({});
|
|
1050
|
-
}), [
|
|
1117
|
+
}), [n]), n;
|
|
1051
1118
|
}
|
|
1052
|
-
var
|
|
1119
|
+
var P = { exports: {} }, F = {};
|
|
1053
1120
|
/**
|
|
1054
1121
|
* @license React
|
|
1055
1122
|
* use-sync-external-store-shim.production.js
|
|
@@ -1061,69 +1128,69 @@ var A = { exports: {} }, P = {};
|
|
|
1061
1128
|
*/
|
|
1062
1129
|
var L;
|
|
1063
1130
|
function ct() {
|
|
1064
|
-
if (L) return
|
|
1131
|
+
if (L) return F;
|
|
1065
1132
|
L = 1;
|
|
1066
|
-
var i =
|
|
1067
|
-
function
|
|
1068
|
-
return h ===
|
|
1069
|
-
}
|
|
1070
|
-
var t = typeof Object.is == "function" ? Object.is :
|
|
1071
|
-
function o(h,
|
|
1072
|
-
var p =
|
|
1073
|
-
return
|
|
1133
|
+
var i = U;
|
|
1134
|
+
function n(h, g) {
|
|
1135
|
+
return h === g && (h !== 0 || 1 / h === 1 / g) || h !== h && g !== g;
|
|
1136
|
+
}
|
|
1137
|
+
var t = typeof Object.is == "function" ? Object.is : n, e = i.useState, s = i.useEffect, r = i.useLayoutEffect, a = i.useDebugValue;
|
|
1138
|
+
function o(h, g) {
|
|
1139
|
+
var p = g(), _ = e({ inst: { value: p, getSnapshot: g } }), y = _[0].inst, T = _[1];
|
|
1140
|
+
return r(
|
|
1074
1141
|
function() {
|
|
1075
|
-
|
|
1142
|
+
y.value = p, y.getSnapshot = g, c(y) && T({ inst: y });
|
|
1076
1143
|
},
|
|
1077
|
-
[h, p,
|
|
1144
|
+
[h, p, g]
|
|
1078
1145
|
), s(
|
|
1079
1146
|
function() {
|
|
1080
|
-
return c(
|
|
1081
|
-
c(
|
|
1147
|
+
return c(y) && T({ inst: y }), h(function() {
|
|
1148
|
+
c(y) && T({ inst: y });
|
|
1082
1149
|
});
|
|
1083
1150
|
},
|
|
1084
1151
|
[h]
|
|
1085
1152
|
), a(p), p;
|
|
1086
1153
|
}
|
|
1087
1154
|
function c(h) {
|
|
1088
|
-
var
|
|
1155
|
+
var g = h.getSnapshot;
|
|
1089
1156
|
h = h.value;
|
|
1090
1157
|
try {
|
|
1091
|
-
var p =
|
|
1158
|
+
var p = g();
|
|
1092
1159
|
return !t(h, p);
|
|
1093
1160
|
} catch {
|
|
1094
1161
|
return !0;
|
|
1095
1162
|
}
|
|
1096
1163
|
}
|
|
1097
|
-
function d(h,
|
|
1098
|
-
return
|
|
1164
|
+
function d(h, g) {
|
|
1165
|
+
return g();
|
|
1099
1166
|
}
|
|
1100
|
-
var
|
|
1101
|
-
return
|
|
1167
|
+
var l = typeof window > "u" || typeof window.document > "u" || typeof window.document.createElement > "u" ? d : o;
|
|
1168
|
+
return F.useSyncExternalStore = i.useSyncExternalStore !== void 0 ? i.useSyncExternalStore : l, F;
|
|
1102
1169
|
}
|
|
1103
1170
|
var k;
|
|
1104
1171
|
function ut() {
|
|
1105
|
-
return k || (k = 1,
|
|
1172
|
+
return k || (k = 1, P.exports = ct()), P.exports;
|
|
1106
1173
|
}
|
|
1107
1174
|
var ht = ut();
|
|
1108
1175
|
function St() {
|
|
1109
|
-
const i =
|
|
1176
|
+
const i = f();
|
|
1110
1177
|
return ht.useSyncExternalStore(
|
|
1111
|
-
(
|
|
1112
|
-
|
|
1178
|
+
(n) => i.subscribe(() => {
|
|
1179
|
+
n();
|
|
1113
1180
|
}),
|
|
1114
1181
|
() => i.thread.messages,
|
|
1115
1182
|
() => i.thread.messages
|
|
1116
1183
|
);
|
|
1117
1184
|
}
|
|
1118
1185
|
function wt() {
|
|
1119
|
-
const i = ot(), [
|
|
1186
|
+
const i = ot(), [n, t] = b(""), [e, s] = b(!1);
|
|
1120
1187
|
return {
|
|
1121
|
-
text:
|
|
1188
|
+
text: n,
|
|
1122
1189
|
setText: t,
|
|
1123
1190
|
isSubmitting: e,
|
|
1124
1191
|
send: async (a) => {
|
|
1125
|
-
if (a == null || a.preventDefault(), !
|
|
1126
|
-
const o =
|
|
1192
|
+
if (a == null || a.preventDefault(), !n.trim() || e) return;
|
|
1193
|
+
const o = n;
|
|
1127
1194
|
t(""), s(!0);
|
|
1128
1195
|
try {
|
|
1129
1196
|
await i.send(o);
|
|
@@ -1137,9 +1204,9 @@ function wt() {
|
|
|
1137
1204
|
append: (a) => t((o) => o + a)
|
|
1138
1205
|
};
|
|
1139
1206
|
}
|
|
1140
|
-
function
|
|
1141
|
-
var
|
|
1142
|
-
const e =
|
|
1207
|
+
function $(i, n) {
|
|
1208
|
+
var r, a, o, c;
|
|
1209
|
+
const e = f().pluginRegistry.getBestRendererForType(i);
|
|
1143
1210
|
if (!e)
|
|
1144
1211
|
return {
|
|
1145
1212
|
component: null,
|
|
@@ -1148,7 +1215,7 @@ function Q(i, r) {
|
|
|
1148
1215
|
supportsPreview: !1,
|
|
1149
1216
|
supportsFullscreen: !1
|
|
1150
1217
|
};
|
|
1151
|
-
const s =
|
|
1218
|
+
const s = n ? (r = e.auxiliary) == null ? void 0 : r[n] : null;
|
|
1152
1219
|
return {
|
|
1153
1220
|
component: e.component,
|
|
1154
1221
|
auxiliaryComponent: s,
|
|
@@ -1158,102 +1225,102 @@ function Q(i, r) {
|
|
|
1158
1225
|
};
|
|
1159
1226
|
}
|
|
1160
1227
|
function Ct() {
|
|
1161
|
-
const i =
|
|
1228
|
+
const i = f(), [n, t] = b(i.contentFocus.state);
|
|
1162
1229
|
return w(() => i.contentFocus.subscribe(() => {
|
|
1163
1230
|
t(i.contentFocus.state);
|
|
1164
1231
|
}), [i]), {
|
|
1165
|
-
...
|
|
1166
|
-
focus: (e, s,
|
|
1232
|
+
...n,
|
|
1233
|
+
focus: (e, s, r, a) => i.contentFocus.focus(e, s, r, a),
|
|
1167
1234
|
blur: () => i.contentFocus.blur(),
|
|
1168
|
-
toggle: (e, s,
|
|
1235
|
+
toggle: (e, s, r, a) => i.contentFocus.toggle(e, s, r, a),
|
|
1169
1236
|
switchContext: (e) => i.contentFocus.switchContext(e),
|
|
1170
1237
|
focusNext: () => i.contentFocus.focusNext(i.thread.messages),
|
|
1171
1238
|
focusPrevious: () => i.contentFocus.focusPrevious(i.thread.messages)
|
|
1172
1239
|
};
|
|
1173
1240
|
}
|
|
1174
1241
|
function dt(i) {
|
|
1175
|
-
const
|
|
1176
|
-
w(() => (i.execute &&
|
|
1242
|
+
const n = f();
|
|
1243
|
+
w(() => (i.execute && n.capabilityRegistry.registerHandler(i.name, { execute: i.execute }), i.render && n.capabilityRegistry.registerRenderer(i.name, {
|
|
1177
1244
|
component: i.render
|
|
1178
1245
|
}), () => {
|
|
1179
|
-
|
|
1180
|
-
}), [i.name,
|
|
1246
|
+
n.capabilityRegistry.unregister(i.name);
|
|
1247
|
+
}), [i.name, n]);
|
|
1181
1248
|
}
|
|
1182
1249
|
function lt(i) {
|
|
1183
|
-
const
|
|
1184
|
-
() =>
|
|
1185
|
-
), [, s] = z((
|
|
1250
|
+
const n = f(), [t, e] = b(
|
|
1251
|
+
() => n.capabilityExecutionManager.getExecution(i)
|
|
1252
|
+
), [, s] = z((r) => r + 1, 0);
|
|
1186
1253
|
return w(() => {
|
|
1187
|
-
const
|
|
1188
|
-
return e(
|
|
1254
|
+
const r = n.capabilityExecutionManager.getExecution(i);
|
|
1255
|
+
return e(r), n.capabilityExecutionManager.subscribe((o) => {
|
|
1189
1256
|
if (o === i) {
|
|
1190
|
-
const c =
|
|
1257
|
+
const c = n.capabilityExecutionManager.getExecution(i);
|
|
1191
1258
|
e(c), s();
|
|
1192
1259
|
}
|
|
1193
1260
|
});
|
|
1194
|
-
}, [i,
|
|
1261
|
+
}, [i, n]), t;
|
|
1195
1262
|
}
|
|
1196
|
-
const
|
|
1263
|
+
const Q = B(void 0);
|
|
1197
1264
|
function Tt({ children: i }) {
|
|
1198
|
-
const [
|
|
1199
|
-
t((
|
|
1265
|
+
const [n, t] = b({}), e = C((c, d) => {
|
|
1266
|
+
t((l) => {
|
|
1200
1267
|
if (d === null) {
|
|
1201
|
-
const { [c]: h, ...
|
|
1202
|
-
return
|
|
1268
|
+
const { [c]: h, ...g } = l;
|
|
1269
|
+
return g;
|
|
1203
1270
|
}
|
|
1204
1271
|
return {
|
|
1205
|
-
...
|
|
1272
|
+
...l,
|
|
1206
1273
|
[c]: { id: c, ...d }
|
|
1207
1274
|
};
|
|
1208
1275
|
});
|
|
1209
1276
|
}, []), s = C((c) => {
|
|
1210
1277
|
t((d) => {
|
|
1211
|
-
const { [c]:
|
|
1278
|
+
const { [c]: l, ...h } = d;
|
|
1212
1279
|
return h;
|
|
1213
1280
|
});
|
|
1214
|
-
}, []),
|
|
1281
|
+
}, []), r = C(() => Object.values(n).reduce(
|
|
1215
1282
|
(c, d) => {
|
|
1216
|
-
const
|
|
1217
|
-
(h, [
|
|
1283
|
+
const l = Object.entries(d.data).reduce(
|
|
1284
|
+
(h, [g, p]) => ({
|
|
1218
1285
|
...h,
|
|
1219
|
-
[
|
|
1286
|
+
[g]: typeof p == "string" ? p : JSON.stringify(p)
|
|
1220
1287
|
}),
|
|
1221
1288
|
{}
|
|
1222
1289
|
);
|
|
1223
|
-
return { ...c, ...
|
|
1290
|
+
return { ...c, ...l };
|
|
1224
1291
|
},
|
|
1225
1292
|
{}
|
|
1226
|
-
), [
|
|
1293
|
+
), [n]), a = C(() => {
|
|
1227
1294
|
t({});
|
|
1228
1295
|
}, []), o = V(
|
|
1229
1296
|
() => ({
|
|
1230
|
-
contexts:
|
|
1297
|
+
contexts: n,
|
|
1231
1298
|
setContext: e,
|
|
1232
1299
|
removeContext: s,
|
|
1233
|
-
getContextData:
|
|
1300
|
+
getContextData: r,
|
|
1234
1301
|
clearContexts: a
|
|
1235
1302
|
}),
|
|
1236
|
-
[
|
|
1303
|
+
[n, e, s, r, a]
|
|
1237
1304
|
);
|
|
1238
|
-
return /* @__PURE__ */ S.jsx(
|
|
1305
|
+
return /* @__PURE__ */ S.jsx(Q.Provider, { value: o, children: i });
|
|
1239
1306
|
}
|
|
1240
|
-
function
|
|
1241
|
-
const i =
|
|
1307
|
+
function gt() {
|
|
1308
|
+
const i = q(Q);
|
|
1242
1309
|
if (!i)
|
|
1243
1310
|
throw new Error("useChatContext must be used within a ChatContextProvider");
|
|
1244
1311
|
return i;
|
|
1245
1312
|
}
|
|
1246
1313
|
function It(i) {
|
|
1247
|
-
const { setContext:
|
|
1248
|
-
w(() => (
|
|
1314
|
+
const { setContext: n, removeContext: t } = gt(), { id: e = "currentPage", ...s } = i;
|
|
1315
|
+
w(() => (n(e, s), () => {
|
|
1249
1316
|
t(e);
|
|
1250
1317
|
}), [e, s.displayName, JSON.stringify(s.data), s.priority, s.icon]);
|
|
1251
1318
|
}
|
|
1252
|
-
function pt({ message: i, content:
|
|
1253
|
-
const t =
|
|
1254
|
-
if (!
|
|
1319
|
+
function pt({ message: i, content: n }) {
|
|
1320
|
+
const t = f(), e = n, s = lt(e.capabilityId), r = t.capabilityRegistry.getRenderer(e.capabilityName);
|
|
1321
|
+
if (!r || !s)
|
|
1255
1322
|
return null;
|
|
1256
|
-
const a =
|
|
1323
|
+
const a = r.component;
|
|
1257
1324
|
return /* @__PURE__ */ S.jsx(
|
|
1258
1325
|
a,
|
|
1259
1326
|
{
|
|
@@ -1266,72 +1333,72 @@ function pt({ message: i, content: r }) {
|
|
|
1266
1333
|
}
|
|
1267
1334
|
);
|
|
1268
1335
|
}
|
|
1269
|
-
function vt({ message: i, content:
|
|
1270
|
-
const { component: t } =
|
|
1271
|
-
if (
|
|
1272
|
-
return /* @__PURE__ */ S.jsx(pt, { message: i, content:
|
|
1336
|
+
function vt({ message: i, content: n }) {
|
|
1337
|
+
const { component: t } = $(n.type);
|
|
1338
|
+
if (n.type === "capability")
|
|
1339
|
+
return /* @__PURE__ */ S.jsx(pt, { message: i, content: n });
|
|
1273
1340
|
if (!t)
|
|
1274
1341
|
return null;
|
|
1275
1342
|
const e = t;
|
|
1276
|
-
return /* @__PURE__ */ S.jsx(e, { content:
|
|
1343
|
+
return /* @__PURE__ */ S.jsx(e, { content: n, message: i });
|
|
1277
1344
|
}
|
|
1278
1345
|
function Rt({
|
|
1279
1346
|
message: i,
|
|
1280
|
-
content:
|
|
1347
|
+
content: n,
|
|
1281
1348
|
context: t,
|
|
1282
1349
|
onClose: e,
|
|
1283
1350
|
onNavigate: s,
|
|
1284
|
-
onSwitchContext:
|
|
1351
|
+
onSwitchContext: r
|
|
1285
1352
|
}) {
|
|
1286
|
-
const { auxiliaryComponent: a } =
|
|
1353
|
+
const { auxiliaryComponent: a } = $(n.type, t);
|
|
1287
1354
|
if (!a)
|
|
1288
1355
|
return null;
|
|
1289
1356
|
const o = a;
|
|
1290
1357
|
return /* @__PURE__ */ S.jsx(
|
|
1291
1358
|
o,
|
|
1292
1359
|
{
|
|
1293
|
-
content:
|
|
1360
|
+
content: n,
|
|
1294
1361
|
message: i,
|
|
1295
1362
|
context: t,
|
|
1296
1363
|
onClose: e,
|
|
1297
1364
|
onNavigate: s,
|
|
1298
|
-
onSwitchContext:
|
|
1365
|
+
onSwitchContext: r
|
|
1299
1366
|
}
|
|
1300
1367
|
);
|
|
1301
1368
|
}
|
|
1302
1369
|
function Et(i) {
|
|
1303
|
-
const
|
|
1304
|
-
return
|
|
1370
|
+
const n = () => (dt(i), null);
|
|
1371
|
+
return n.displayName = `Capability(${i.name})`, n;
|
|
1305
1372
|
}
|
|
1306
1373
|
class Mt {
|
|
1307
1374
|
getAllowedEvents() {
|
|
1308
1375
|
return null;
|
|
1309
1376
|
}
|
|
1310
|
-
shouldProcessEvent(
|
|
1377
|
+
shouldProcessEvent(n) {
|
|
1311
1378
|
const t = this.getAllowedEvents();
|
|
1312
|
-
return t ? t.includes(
|
|
1379
|
+
return t ? t.includes(n) : !0;
|
|
1313
1380
|
}
|
|
1314
|
-
async *stream(
|
|
1315
|
-
const { signal: t } =
|
|
1316
|
-
if (!
|
|
1317
|
-
throw new Error(`HTTP error! status: ${
|
|
1318
|
-
if (!
|
|
1381
|
+
async *stream(n) {
|
|
1382
|
+
const { signal: t } = n, { url: e, options: s } = this.prepareRequest(n), r = await fetch(e, { ...s, signal: t });
|
|
1383
|
+
if (!r.ok)
|
|
1384
|
+
throw new Error(`HTTP error! status: ${r.status}`);
|
|
1385
|
+
if (!r.body)
|
|
1319
1386
|
throw new Error("Response body is null");
|
|
1320
|
-
yield* this.parseSSEStream(
|
|
1387
|
+
yield* this.parseSSEStream(r.body, t);
|
|
1321
1388
|
}
|
|
1322
|
-
async *parseSSEStream(
|
|
1323
|
-
const e =
|
|
1324
|
-
let
|
|
1389
|
+
async *parseSSEStream(n, t) {
|
|
1390
|
+
const e = n.getReader(), s = new TextDecoder();
|
|
1391
|
+
let r = "", a = null;
|
|
1325
1392
|
try {
|
|
1326
1393
|
for (; ; ) {
|
|
1327
1394
|
const { done: o, value: c } = await e.read();
|
|
1328
1395
|
if (o || t != null && t.aborted) break;
|
|
1329
|
-
|
|
1330
|
-
const d =
|
|
1396
|
+
r += s.decode(c, { stream: !0 });
|
|
1397
|
+
const d = r.split(`
|
|
1331
1398
|
`);
|
|
1332
|
-
|
|
1333
|
-
for (const
|
|
1334
|
-
const h =
|
|
1399
|
+
r = d.pop() || "";
|
|
1400
|
+
for (const l of d) {
|
|
1401
|
+
const h = l.trim();
|
|
1335
1402
|
if (!h) {
|
|
1336
1403
|
a = null;
|
|
1337
1404
|
continue;
|
|
@@ -1342,11 +1409,11 @@ class Mt {
|
|
|
1342
1409
|
continue;
|
|
1343
1410
|
}
|
|
1344
1411
|
if (h.startsWith("data:")) {
|
|
1345
|
-
const
|
|
1346
|
-
if (
|
|
1412
|
+
const g = h.substring(5).trim();
|
|
1413
|
+
if (g === "eof" || h === "eof")
|
|
1347
1414
|
break;
|
|
1348
1415
|
try {
|
|
1349
|
-
const p = JSON.parse(
|
|
1416
|
+
const p = JSON.parse(g);
|
|
1350
1417
|
if (a && this.shouldProcessEvent(a)) {
|
|
1351
1418
|
const _ = this.convertEvent({
|
|
1352
1419
|
event: a,
|
|
@@ -1368,7 +1435,7 @@ class Mt {
|
|
|
1368
1435
|
}
|
|
1369
1436
|
export {
|
|
1370
1437
|
bt as AssistantRuntime,
|
|
1371
|
-
|
|
1438
|
+
mt as AssistantRuntimeProvider,
|
|
1372
1439
|
Rt as AuxiliaryRenderer,
|
|
1373
1440
|
Mt as BaseSSEStreamAdapter,
|
|
1374
1441
|
K as CapabilityExecutionManager,
|
|
@@ -1378,19 +1445,19 @@ export {
|
|
|
1378
1445
|
et as ComposerRuntime,
|
|
1379
1446
|
vt as ContentRenderer,
|
|
1380
1447
|
G as PluginRegistry,
|
|
1381
|
-
|
|
1448
|
+
v as ThreadListItemRuntime,
|
|
1382
1449
|
st as ThreadListRuntime,
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1450
|
+
R as ThreadRuntime,
|
|
1451
|
+
E as ThreadRuntimeCore,
|
|
1452
|
+
I as generateMessageId,
|
|
1386
1453
|
Et as makeCapability,
|
|
1387
|
-
|
|
1454
|
+
f as useAssistantRuntime,
|
|
1388
1455
|
dt as useCapability,
|
|
1389
1456
|
lt as useCapabilityExecution,
|
|
1390
|
-
|
|
1457
|
+
gt as useChatContext,
|
|
1391
1458
|
wt as useComposer,
|
|
1392
1459
|
Ct as useContentFocus,
|
|
1393
|
-
|
|
1460
|
+
$ as useContentRenderer,
|
|
1394
1461
|
ot as useCurrentThread,
|
|
1395
1462
|
St as useMessages,
|
|
1396
1463
|
It as usePageContext,
|