@harnessio/ai-chat-core 0.0.21 → 0.0.22
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/QuickActionRegistry.d.ts +48 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/index.js +635 -443
- package/dist/index.js.map +1 -1
- package/dist/react/hooks/index.d.ts +3 -0
- package/dist/react/hooks/useQuickAction.d.ts +26 -0
- package/dist/react/hooks/useQuickActionScope.d.ts +21 -0
- package/dist/react/hooks/useQuickActions.d.ts +25 -0
- package/dist/runtime/AssistantRuntime/AssistantRuntime.d.ts +2 -0
- package/dist/runtime/ThreadRuntime/ThreadRuntime.d.ts +2 -1
- package/dist/runtime/ThreadRuntime/ThreadRuntimeCore.d.ts +2 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/quick-action.d.ts +21 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
1
|
var H = Object.defineProperty;
|
|
2
|
-
var J = (
|
|
3
|
-
var u = (
|
|
4
|
-
import
|
|
2
|
+
var J = (n, s, t) => s in n ? H(n, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[s] = t;
|
|
3
|
+
var u = (n, s, t) => J(n, typeof s != "symbol" ? s + "" : s, t);
|
|
4
|
+
import q, { createContext as U, useContext as B, useState as y, useEffect as m, useReducer as V, useCallback as C, useMemo as z } 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(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((i, r) => ((r == null ? void 0 : r.priority) ?? 0) - ((i == null ? void 0 : i.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 r = (this.renderersByType.get(e.type) || []).filter((
|
|
19
|
+
const r = (this.renderersByType.get(e.type) || []).filter((a) => !t.renderers.includes(a));
|
|
20
20
|
r.length === 0 ? this.renderersByType.delete(e.type) : this.renderersByType.set(e.type, r);
|
|
21
|
-
}), this.plugins.delete(
|
|
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();
|
|
@@ -41,36 +41,36 @@ class Y {
|
|
|
41
41
|
u(this, "handlers", /* @__PURE__ */ new Map());
|
|
42
42
|
u(this, "renderers", /* @__PURE__ */ new Map());
|
|
43
43
|
}
|
|
44
|
-
registerHandler(
|
|
45
|
-
const
|
|
46
|
-
|
|
44
|
+
registerHandler(s, t, e = 0) {
|
|
45
|
+
const i = this.handlers.get(s) || [], r = { handler: t, priority: e }, a = i.findIndex((o) => o.priority < e);
|
|
46
|
+
a === -1 ? i.push(r) : i.splice(a, 0, r), this.handlers.set(s, i);
|
|
47
47
|
}
|
|
48
|
-
registerRenderer(
|
|
49
|
-
const
|
|
50
|
-
|
|
48
|
+
registerRenderer(s, t, e = 0) {
|
|
49
|
+
const i = this.renderers.get(s) || [], r = { renderer: t, priority: e }, a = i.findIndex((o) => o.priority < e);
|
|
50
|
+
a === -1 ? i.push(r) : i.splice(a, 0, r), this.renderers.set(s, i);
|
|
51
51
|
}
|
|
52
|
-
unregister(
|
|
53
|
-
this.handlers.delete(
|
|
52
|
+
unregister(s) {
|
|
53
|
+
this.handlers.delete(s), this.renderers.delete(s);
|
|
54
54
|
}
|
|
55
|
-
getHandler(
|
|
55
|
+
getHandler(s) {
|
|
56
56
|
var e;
|
|
57
|
-
const t = this.handlers.get(
|
|
57
|
+
const t = this.handlers.get(s);
|
|
58
58
|
return (e = t == null ? void 0 : t[0]) == null ? void 0 : e.handler;
|
|
59
59
|
}
|
|
60
|
-
getRenderer(
|
|
60
|
+
getRenderer(s) {
|
|
61
61
|
var e;
|
|
62
|
-
const t = this.renderers.get(
|
|
62
|
+
const t = this.renderers.get(s);
|
|
63
63
|
return (e = t == null ? void 0 : t[0]) == null ? void 0 : e.renderer;
|
|
64
64
|
}
|
|
65
65
|
getStrategy() {
|
|
66
66
|
return "queue";
|
|
67
67
|
}
|
|
68
|
-
hasHandler(
|
|
69
|
-
const t = this.handlers.get(
|
|
68
|
+
hasHandler(s) {
|
|
69
|
+
const t = this.handlers.get(s);
|
|
70
70
|
return t !== void 0 && t.length > 0;
|
|
71
71
|
}
|
|
72
|
-
hasRenderer(
|
|
73
|
-
const t = this.renderers.get(
|
|
72
|
+
hasRenderer(s) {
|
|
73
|
+
const t = this.renderers.get(s);
|
|
74
74
|
return t !== void 0 && t.length > 0;
|
|
75
75
|
}
|
|
76
76
|
clear() {
|
|
@@ -81,27 +81,27 @@ class Y {
|
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
class K {
|
|
84
|
-
constructor(
|
|
84
|
+
constructor(s) {
|
|
85
85
|
u(this, "executions", /* @__PURE__ */ new Map());
|
|
86
86
|
u(this, "executionQueue", []);
|
|
87
87
|
u(this, "isProcessing", !1);
|
|
88
88
|
u(this, "runningByName", /* @__PURE__ */ new Map());
|
|
89
89
|
u(this, "subscribers", /* @__PURE__ */ new Set());
|
|
90
90
|
u(this, "getHandler");
|
|
91
|
-
this.getHandler =
|
|
91
|
+
this.getHandler = s;
|
|
92
92
|
}
|
|
93
|
-
async executeCapability(
|
|
94
|
-
if (!this.getHandler(
|
|
95
|
-
console.warn(`No handler registered for capability: ${
|
|
93
|
+
async executeCapability(s, t, e, i, r = "queue") {
|
|
94
|
+
if (!this.getHandler(s)) {
|
|
95
|
+
console.warn(`No handler registered for capability: ${s}`);
|
|
96
96
|
return;
|
|
97
97
|
}
|
|
98
98
|
const o = {
|
|
99
99
|
id: t,
|
|
100
|
-
name:
|
|
100
|
+
name: s,
|
|
101
101
|
args: e,
|
|
102
102
|
status: { type: "queued" },
|
|
103
103
|
timestamp: Date.now(),
|
|
104
|
-
messageId:
|
|
104
|
+
messageId: i
|
|
105
105
|
};
|
|
106
106
|
switch (this.executions.set(t, o), this.notifySubscribers(t), r) {
|
|
107
107
|
case "queue":
|
|
@@ -114,64 +114,207 @@ class K {
|
|
|
114
114
|
async processQueue() {
|
|
115
115
|
if (!(this.isProcessing || this.executionQueue.length === 0)) {
|
|
116
116
|
for (this.isProcessing = !0; this.executionQueue.length > 0; ) {
|
|
117
|
-
const
|
|
117
|
+
const s = this.executionQueue.shift(), t = this.executions.get(s);
|
|
118
118
|
if (!t) continue;
|
|
119
119
|
const e = this.getHandler(t.name);
|
|
120
120
|
if (!e) continue;
|
|
121
|
-
t.status = { type: "running" }, this.notifySubscribers(
|
|
122
|
-
const
|
|
123
|
-
|
|
121
|
+
t.status = { type: "running" }, this.notifySubscribers(s);
|
|
122
|
+
const i = this.runningByName.get(t.name) || [];
|
|
123
|
+
i.push(s), this.runningByName.set(t.name, i);
|
|
124
124
|
try {
|
|
125
125
|
const r = await e.execute(t.args, {
|
|
126
126
|
messageId: t.messageId,
|
|
127
|
-
capabilityId:
|
|
127
|
+
capabilityId: s
|
|
128
128
|
});
|
|
129
129
|
t.status = { type: "complete", result: r }, t.result = r;
|
|
130
130
|
} catch (r) {
|
|
131
|
-
const
|
|
132
|
-
t.status = { type: "error", error:
|
|
131
|
+
const a = r instanceof Error ? r.message : "Unknown error";
|
|
132
|
+
t.status = { type: "error", error: a }, t.error = a;
|
|
133
133
|
} finally {
|
|
134
|
-
const r = this.runningByName.get(t.name) || [],
|
|
135
|
-
|
|
134
|
+
const r = this.runningByName.get(t.name) || [], a = r.indexOf(s);
|
|
135
|
+
a > -1 && r.splice(a, 1), r.length === 0 ? this.runningByName.delete(t.name) : this.runningByName.set(t.name, r), this.notifySubscribers(s);
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
138
|
this.isProcessing = !1;
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
|
-
getExecution(
|
|
142
|
-
return this.executions.get(
|
|
141
|
+
getExecution(s) {
|
|
142
|
+
return this.executions.get(s);
|
|
143
143
|
}
|
|
144
|
-
getExecutionsByMessage(
|
|
145
|
-
return Array.from(this.executions.values()).filter((t) => t.messageId ===
|
|
144
|
+
getExecutionsByMessage(s) {
|
|
145
|
+
return Array.from(this.executions.values()).filter((t) => t.messageId === s);
|
|
146
146
|
}
|
|
147
|
-
subscribe(
|
|
148
|
-
return this.subscribers.add(
|
|
147
|
+
subscribe(s) {
|
|
148
|
+
return this.subscribers.add(s), () => this.subscribers.delete(s);
|
|
149
149
|
}
|
|
150
|
-
notifySubscribers(
|
|
151
|
-
this.subscribers.forEach((t) => t(
|
|
150
|
+
notifySubscribers(s) {
|
|
151
|
+
this.subscribers.forEach((t) => t(s));
|
|
152
152
|
}
|
|
153
153
|
clear() {
|
|
154
154
|
this.executions.clear(), this.executionQueue = [], this.runningByName.clear();
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
|
-
class
|
|
157
|
+
class X {
|
|
158
|
+
constructor() {
|
|
159
|
+
u(this, "scopes", /* @__PURE__ */ new Map());
|
|
160
|
+
u(this, "scopeStack", []);
|
|
161
|
+
this.scopes.set("global", {
|
|
162
|
+
mode: "merge",
|
|
163
|
+
actions: /* @__PURE__ */ new Map()
|
|
164
|
+
}), this.scopeStack.push("global");
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Activate a scope with the specified mode.
|
|
168
|
+
* This pushes the scope onto the stack, making it active.
|
|
169
|
+
*/
|
|
170
|
+
activateScope(s, t = "merge") {
|
|
171
|
+
if (!this.scopes.has(s))
|
|
172
|
+
this.scopes.set(s, {
|
|
173
|
+
mode: t,
|
|
174
|
+
actions: /* @__PURE__ */ new Map()
|
|
175
|
+
});
|
|
176
|
+
else {
|
|
177
|
+
const e = this.scopes.get(s);
|
|
178
|
+
e.mode = t;
|
|
179
|
+
}
|
|
180
|
+
this.scopeStack.includes(s) || this.scopeStack.push(s);
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Deactivate a scope, removing it from the stack.
|
|
184
|
+
* This restores the previous scope as active.
|
|
185
|
+
*/
|
|
186
|
+
deactivateScope(s) {
|
|
187
|
+
const t = this.scopeStack.indexOf(s);
|
|
188
|
+
t !== -1 && s !== "global" && this.scopeStack.splice(t, 1);
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Get the currently active scope (top of stack).
|
|
192
|
+
*/
|
|
193
|
+
getActiveScope() {
|
|
194
|
+
return this.scopeStack[this.scopeStack.length - 1] || "global";
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Get the full scope stack.
|
|
198
|
+
*/
|
|
199
|
+
getScopeStack() {
|
|
200
|
+
return [...this.scopeStack];
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Register a quick action in the specified scope.
|
|
204
|
+
*/
|
|
205
|
+
register(s, t = "global") {
|
|
206
|
+
const e = s.priority ?? 0;
|
|
207
|
+
this.scopes.has(t) || this.scopes.set(t, {
|
|
208
|
+
mode: "merge",
|
|
209
|
+
actions: /* @__PURE__ */ new Map()
|
|
210
|
+
});
|
|
211
|
+
const i = this.scopes.get(t);
|
|
212
|
+
i.actions.has(s.id) && console.warn(`QuickAction with id "${s.id}" is already registered in scope "${t}". Overwriting.`), i.actions.set(s.id, {
|
|
213
|
+
config: s,
|
|
214
|
+
priority: e
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Unregister a quick action from the specified scope.
|
|
219
|
+
*/
|
|
220
|
+
unregister(s, t = "global") {
|
|
221
|
+
const e = this.scopes.get(t);
|
|
222
|
+
return e ? e.actions.delete(s) : !1;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Clear all actions in the specified scope.
|
|
226
|
+
*/
|
|
227
|
+
clearScope(s) {
|
|
228
|
+
const t = this.scopes.get(s);
|
|
229
|
+
t && t.actions.clear();
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Get all visible quick actions based on the active scope and its mode.
|
|
233
|
+
*/
|
|
234
|
+
async getVisible(s) {
|
|
235
|
+
const t = this.getActiveScope(), e = this.scopes.get(t);
|
|
236
|
+
if (!e)
|
|
237
|
+
return [];
|
|
238
|
+
const i = e.mode;
|
|
239
|
+
let r = [];
|
|
240
|
+
if (i === "replace")
|
|
241
|
+
r = Array.from(e.actions.values());
|
|
242
|
+
else if (i === "append")
|
|
243
|
+
for (const c of this.scopeStack) {
|
|
244
|
+
const h = this.scopes.get(c);
|
|
245
|
+
h && r.push(...Array.from(h.actions.values()));
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
const c = this.scopes.get("global");
|
|
249
|
+
c && r.push(...Array.from(c.actions.values())), t !== "global" && r.push(...Array.from(e.actions.values()));
|
|
250
|
+
}
|
|
251
|
+
let o = (await Promise.all(
|
|
252
|
+
r.map(async (c) => {
|
|
253
|
+
if (!c.config.condition)
|
|
254
|
+
return { entry: c, visible: !0 };
|
|
255
|
+
try {
|
|
256
|
+
const h = await c.config.condition();
|
|
257
|
+
return { entry: c, visible: h };
|
|
258
|
+
} catch (h) {
|
|
259
|
+
return console.error(`Error evaluating condition for quick action "${c.config.id}":`, h), { entry: c, visible: !1 };
|
|
260
|
+
}
|
|
261
|
+
})
|
|
262
|
+
)).filter((c) => c.visible).map((c) => c.entry);
|
|
263
|
+
return o.sort((c, h) => h.priority - c.priority), s != null && s.scope && (o = o.filter((c) => c.config.scope === s.scope)), o.map((c) => ({
|
|
264
|
+
id: c.config.id,
|
|
265
|
+
label: c.config.label,
|
|
266
|
+
prompt: c.config.prompt,
|
|
267
|
+
icon: c.config.icon,
|
|
268
|
+
description: c.config.description,
|
|
269
|
+
priority: c.config.priority,
|
|
270
|
+
scope: c.config.scope
|
|
271
|
+
}));
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Get a single quick action by ID from the specified scope.
|
|
275
|
+
*/
|
|
276
|
+
get(s, t = "global") {
|
|
277
|
+
const e = this.scopes.get(t);
|
|
278
|
+
if (!e)
|
|
279
|
+
return;
|
|
280
|
+
const i = e.actions.get(s);
|
|
281
|
+
if (i)
|
|
282
|
+
return {
|
|
283
|
+
id: i.config.id,
|
|
284
|
+
label: i.config.label,
|
|
285
|
+
prompt: i.config.prompt,
|
|
286
|
+
icon: i.config.icon,
|
|
287
|
+
description: i.config.description,
|
|
288
|
+
priority: i.config.priority,
|
|
289
|
+
scope: i.config.scope
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Check if a quick action exists in the specified scope.
|
|
294
|
+
*/
|
|
295
|
+
has(s, t = "global") {
|
|
296
|
+
const e = this.scopes.get(t);
|
|
297
|
+
return e ? e.actions.has(s) : !1;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
class _ {
|
|
158
301
|
constructor() {
|
|
159
302
|
u(this, "_subscriptions", /* @__PURE__ */ new Set());
|
|
160
303
|
}
|
|
161
|
-
subscribe(
|
|
162
|
-
return this._subscriptions.add(
|
|
163
|
-
this._subscriptions.delete(
|
|
304
|
+
subscribe(s) {
|
|
305
|
+
return this._subscriptions.add(s), () => {
|
|
306
|
+
this._subscriptions.delete(s);
|
|
164
307
|
};
|
|
165
308
|
}
|
|
166
309
|
notifySubscribers() {
|
|
167
|
-
for (const
|
|
168
|
-
|
|
310
|
+
for (const s of this._subscriptions)
|
|
311
|
+
s();
|
|
169
312
|
}
|
|
170
313
|
getSubscriberCount() {
|
|
171
314
|
return this._subscriptions.size;
|
|
172
315
|
}
|
|
173
316
|
}
|
|
174
|
-
class
|
|
317
|
+
class Z extends _ {
|
|
175
318
|
constructor() {
|
|
176
319
|
super(...arguments);
|
|
177
320
|
u(this, "_state", {
|
|
@@ -204,14 +347,14 @@ class X extends b {
|
|
|
204
347
|
get focusedContentIndex() {
|
|
205
348
|
return this._state.focusedContentIndex;
|
|
206
349
|
}
|
|
207
|
-
focus(t, e,
|
|
350
|
+
focus(t, e, i, r = "detail") {
|
|
208
351
|
this._state = {
|
|
209
352
|
isActive: !0,
|
|
210
353
|
context: r,
|
|
211
354
|
focusedContent: t,
|
|
212
355
|
focusedMessage: e,
|
|
213
356
|
focusedMessageId: e.id,
|
|
214
|
-
focusedContentIndex:
|
|
357
|
+
focusedContentIndex: i
|
|
215
358
|
}, this.notifySubscribers();
|
|
216
359
|
}
|
|
217
360
|
blur() {
|
|
@@ -224,8 +367,8 @@ class X extends b {
|
|
|
224
367
|
focusedContentIndex: null
|
|
225
368
|
}, this.notifySubscribers();
|
|
226
369
|
}
|
|
227
|
-
toggle(t, e,
|
|
228
|
-
this._state.isActive && this._state.focusedMessageId === e.id && this._state.focusedContentIndex ===
|
|
370
|
+
toggle(t, e, i, r = "detail") {
|
|
371
|
+
this._state.isActive && this._state.focusedMessageId === e.id && this._state.focusedContentIndex === i && this._state.context === r ? this.blur() : this.focus(t, e, i, r);
|
|
229
372
|
}
|
|
230
373
|
switchContext(t) {
|
|
231
374
|
this._state.isActive && this._state.focusedContent && (this._state = {
|
|
@@ -235,46 +378,46 @@ class X extends b {
|
|
|
235
378
|
}
|
|
236
379
|
focusNext(t) {
|
|
237
380
|
if (!this._state.focusedMessageId || !t.length) return;
|
|
238
|
-
const e = t.findIndex((
|
|
381
|
+
const e = t.findIndex((a) => a.id === this._state.focusedMessageId);
|
|
239
382
|
if (e === -1) return;
|
|
240
|
-
const
|
|
241
|
-
if (r + 1 <
|
|
242
|
-
const
|
|
243
|
-
this.focus(
|
|
383
|
+
const i = t[e], r = this._state.focusedContentIndex ?? 0;
|
|
384
|
+
if (r + 1 < i.content.length) {
|
|
385
|
+
const a = i.content[r + 1];
|
|
386
|
+
this.focus(a, i, r + 1, this._state.context || "detail");
|
|
244
387
|
return;
|
|
245
388
|
}
|
|
246
389
|
if (e + 1 < t.length) {
|
|
247
|
-
const
|
|
248
|
-
|
|
390
|
+
const a = t[e + 1];
|
|
391
|
+
a.content.length > 0 && this.focus(a.content[0], a, 0, this._state.context || "detail");
|
|
249
392
|
}
|
|
250
393
|
}
|
|
251
394
|
focusPrevious(t) {
|
|
252
395
|
if (!this._state.focusedMessageId || !t.length) return;
|
|
253
|
-
const e = t.findIndex((
|
|
396
|
+
const e = t.findIndex((a) => a.id === this._state.focusedMessageId);
|
|
254
397
|
if (e === -1) return;
|
|
255
|
-
const
|
|
398
|
+
const i = t[e], r = this._state.focusedContentIndex ?? 0;
|
|
256
399
|
if (r > 0) {
|
|
257
|
-
const
|
|
258
|
-
this.focus(
|
|
400
|
+
const a = i.content[r - 1];
|
|
401
|
+
this.focus(a, i, r - 1, this._state.context || "detail");
|
|
259
402
|
return;
|
|
260
403
|
}
|
|
261
404
|
if (e > 0) {
|
|
262
|
-
const
|
|
263
|
-
if (
|
|
264
|
-
const o =
|
|
265
|
-
this.focus(
|
|
405
|
+
const a = t[e - 1];
|
|
406
|
+
if (a.content.length > 0) {
|
|
407
|
+
const o = a.content.length - 1;
|
|
408
|
+
this.focus(a.content[o], a, o, this._state.context || "detail");
|
|
266
409
|
}
|
|
267
410
|
}
|
|
268
411
|
}
|
|
269
412
|
}
|
|
270
|
-
let
|
|
271
|
-
function
|
|
272
|
-
return `msg-${Date.now()}-${++
|
|
413
|
+
let tt = 0, et = 0;
|
|
414
|
+
function v() {
|
|
415
|
+
return `msg-${Date.now()}-${++tt}`;
|
|
273
416
|
}
|
|
274
|
-
function
|
|
275
|
-
return `thread-${Date.now()}-${++
|
|
417
|
+
function k() {
|
|
418
|
+
return `thread-${Date.now()}-${++et}`;
|
|
276
419
|
}
|
|
277
|
-
class
|
|
420
|
+
class T extends _ {
|
|
278
421
|
constructor(t) {
|
|
279
422
|
super();
|
|
280
423
|
u(this, "_state");
|
|
@@ -302,7 +445,7 @@ class v extends b {
|
|
|
302
445
|
return super.subscribe(t);
|
|
303
446
|
}
|
|
304
447
|
}
|
|
305
|
-
class
|
|
448
|
+
class st extends _ {
|
|
306
449
|
constructor() {
|
|
307
450
|
super(...arguments);
|
|
308
451
|
u(this, "_text", "");
|
|
@@ -330,11 +473,11 @@ class et extends b {
|
|
|
330
473
|
this._isSubmitting = t, this.notifySubscribers();
|
|
331
474
|
}
|
|
332
475
|
}
|
|
333
|
-
class R extends
|
|
476
|
+
class R extends _ {
|
|
334
477
|
constructor(t) {
|
|
335
478
|
super();
|
|
336
479
|
u(this, "composer");
|
|
337
|
-
this._core = t, this.composer = new
|
|
480
|
+
this._core = t, this.composer = new st(), this._core.subscribe(() => {
|
|
338
481
|
this.notifySubscribers();
|
|
339
482
|
});
|
|
340
483
|
}
|
|
@@ -425,11 +568,14 @@ class R extends b {
|
|
|
425
568
|
setTitle(t) {
|
|
426
569
|
this._core.setTitle(t);
|
|
427
570
|
}
|
|
571
|
+
updateMessageContent(t, e) {
|
|
572
|
+
this._core.updateMessageContent(t, e);
|
|
573
|
+
}
|
|
428
574
|
subscribe(t) {
|
|
429
575
|
return super.subscribe(t);
|
|
430
576
|
}
|
|
431
577
|
}
|
|
432
|
-
class
|
|
578
|
+
class M extends _ {
|
|
433
579
|
constructor(t) {
|
|
434
580
|
super();
|
|
435
581
|
u(this, "_messages", []);
|
|
@@ -481,12 +627,12 @@ class E extends b {
|
|
|
481
627
|
};
|
|
482
628
|
}
|
|
483
629
|
updateMessages(t) {
|
|
484
|
-
var e,
|
|
485
|
-
this._messages = t, (
|
|
630
|
+
var e, i;
|
|
631
|
+
this._messages = t, (i = (e = this.config).onMessagesChange) == null || i.call(e, this._messages), this.notifySubscribers();
|
|
486
632
|
}
|
|
487
633
|
append(t) {
|
|
488
634
|
const e = {
|
|
489
|
-
id: t.id ||
|
|
635
|
+
id: t.id || v(),
|
|
490
636
|
parentId: t.parentId,
|
|
491
637
|
role: t.role,
|
|
492
638
|
content: t.content,
|
|
@@ -523,14 +669,14 @@ class E extends b {
|
|
|
523
669
|
if (this._isRunning)
|
|
524
670
|
throw new Error("A run is already in progress");
|
|
525
671
|
this._isWaitingForUser = !1, this._pendingCapability = null, this._isRunning = !0, this._abortController = new AbortController(), this._currentPart = null;
|
|
526
|
-
const e =
|
|
672
|
+
const e = v(), i = {
|
|
527
673
|
id: e,
|
|
528
674
|
role: "assistant",
|
|
529
675
|
content: [],
|
|
530
676
|
status: { type: "running" },
|
|
531
677
|
timestamp: Date.now()
|
|
532
678
|
};
|
|
533
|
-
this.updateMessages([...this._messages,
|
|
679
|
+
this.updateMessages([...this._messages, i]);
|
|
534
680
|
try {
|
|
535
681
|
const r = this.config.streamAdapter.stream({
|
|
536
682
|
messages: this._messages,
|
|
@@ -538,20 +684,20 @@ class E extends b {
|
|
|
538
684
|
signal: this._abortController.signal,
|
|
539
685
|
systemEvent: t
|
|
540
686
|
});
|
|
541
|
-
for await (const
|
|
687
|
+
for await (const a of r) {
|
|
542
688
|
if (this._abortController.signal.aborted)
|
|
543
689
|
break;
|
|
544
|
-
this.handleStreamEvent(e,
|
|
690
|
+
this.handleStreamEvent(e, a.event);
|
|
545
691
|
}
|
|
546
692
|
this.updateMessageStatus(e, { type: "complete" });
|
|
547
693
|
} catch (r) {
|
|
548
694
|
if (r instanceof Error && r.name === "AbortError")
|
|
549
695
|
this.completeStreamingContent(e), this.updateMessageStatus(e, { type: "cancelled" });
|
|
550
696
|
else {
|
|
551
|
-
const
|
|
697
|
+
const a = r instanceof Error ? r.message : "Unknown error";
|
|
552
698
|
this.completeStreamingContent(e), this.updateMessageStatus(e, {
|
|
553
699
|
type: "error",
|
|
554
|
-
error:
|
|
700
|
+
error: a
|
|
555
701
|
});
|
|
556
702
|
}
|
|
557
703
|
} finally {
|
|
@@ -562,34 +708,34 @@ class E extends b {
|
|
|
562
708
|
if (this._isRunning)
|
|
563
709
|
throw new Error("A run is already in progress");
|
|
564
710
|
this._isWaitingForUser = !1, this._pendingCapability = null, this.append(t), this._isRunning = !0, this._abortController = new AbortController(), this._currentPart = null;
|
|
565
|
-
const e =
|
|
711
|
+
const e = v(), i = {
|
|
566
712
|
id: e,
|
|
567
713
|
role: "assistant",
|
|
568
714
|
content: [],
|
|
569
715
|
status: { type: "running" },
|
|
570
716
|
timestamp: Date.now()
|
|
571
717
|
};
|
|
572
|
-
this.updateMessages([...this._messages,
|
|
718
|
+
this.updateMessages([...this._messages, i]);
|
|
573
719
|
try {
|
|
574
720
|
const r = this.config.streamAdapter.stream({
|
|
575
721
|
messages: this._messages,
|
|
576
722
|
conversationId: this._conversationId,
|
|
577
723
|
signal: this._abortController.signal
|
|
578
724
|
});
|
|
579
|
-
for await (const
|
|
725
|
+
for await (const a of r) {
|
|
580
726
|
if (this._abortController.signal.aborted)
|
|
581
727
|
break;
|
|
582
|
-
this.handleStreamEvent(e,
|
|
728
|
+
this.handleStreamEvent(e, a.event);
|
|
583
729
|
}
|
|
584
730
|
this.updateMessageStatus(e, { type: "complete" });
|
|
585
731
|
} catch (r) {
|
|
586
732
|
if (r instanceof Error && r.name === "AbortError")
|
|
587
733
|
this.completeStreamingContent(e), this.updateMessageStatus(e, { type: "cancelled" });
|
|
588
734
|
else {
|
|
589
|
-
const
|
|
735
|
+
const a = r instanceof Error ? r.message : "Unknown error";
|
|
590
736
|
this.completeStreamingContent(e), this.updateMessageStatus(e, {
|
|
591
737
|
type: "error",
|
|
592
|
-
error:
|
|
738
|
+
error: a
|
|
593
739
|
});
|
|
594
740
|
}
|
|
595
741
|
} finally {
|
|
@@ -597,9 +743,9 @@ class E extends b {
|
|
|
597
743
|
}
|
|
598
744
|
}
|
|
599
745
|
handleStreamEvent(t, e) {
|
|
600
|
-
const
|
|
601
|
-
if (
|
|
602
|
-
const r = this._messages[
|
|
746
|
+
const i = this._messages.findIndex((o) => o.id === t);
|
|
747
|
+
if (i === -1) return;
|
|
748
|
+
const r = this._messages[i];
|
|
603
749
|
if (e.type === "part-start")
|
|
604
750
|
this.handlePartStart(r, e);
|
|
605
751
|
else if (e.type === "text-delta" || e.type === "assistant_thought")
|
|
@@ -621,15 +767,15 @@ class E extends b {
|
|
|
621
767
|
args: o.args
|
|
622
768
|
};
|
|
623
769
|
r.content.push(c);
|
|
624
|
-
const
|
|
625
|
-
|
|
770
|
+
const h = o.artifact;
|
|
771
|
+
h && r.content.push({
|
|
626
772
|
type: "artifact",
|
|
627
773
|
data: {
|
|
628
774
|
capabilityName: o.capabilityName,
|
|
629
775
|
originalArgs: o.args,
|
|
630
776
|
displayData: {
|
|
631
|
-
name:
|
|
632
|
-
type:
|
|
777
|
+
name: h.displayName,
|
|
778
|
+
type: h.displayType
|
|
633
779
|
}
|
|
634
780
|
}
|
|
635
781
|
}), this.config.capabilityExecutionManager && this.config.capabilityExecutionManager.executeCapability(
|
|
@@ -662,15 +808,15 @@ class E extends b {
|
|
|
662
808
|
}
|
|
663
809
|
];
|
|
664
810
|
}
|
|
665
|
-
const
|
|
666
|
-
...this._messages.slice(0,
|
|
811
|
+
const a = [
|
|
812
|
+
...this._messages.slice(0, i),
|
|
667
813
|
{ ...r, timestamp: Date.now() },
|
|
668
|
-
...this._messages.slice(
|
|
814
|
+
...this._messages.slice(i + 1)
|
|
669
815
|
];
|
|
670
|
-
this.updateMessages(
|
|
816
|
+
this.updateMessages(a);
|
|
671
817
|
}
|
|
672
818
|
handlePartStart(t, e) {
|
|
673
|
-
const
|
|
819
|
+
const i = t.content.length;
|
|
674
820
|
let r;
|
|
675
821
|
switch (e.part.type) {
|
|
676
822
|
case "assistant_thought":
|
|
@@ -698,7 +844,7 @@ class E extends b {
|
|
|
698
844
|
}
|
|
699
845
|
t.content = [...t.content, r], this._currentPart = {
|
|
700
846
|
messageId: t.id,
|
|
701
|
-
contentIndex:
|
|
847
|
+
contentIndex: i,
|
|
702
848
|
type: e.part.type,
|
|
703
849
|
parentId: e.part.parentId
|
|
704
850
|
};
|
|
@@ -708,8 +854,8 @@ class E extends b {
|
|
|
708
854
|
console.warn("Received text-delta without part-start");
|
|
709
855
|
return;
|
|
710
856
|
}
|
|
711
|
-
const
|
|
712
|
-
|
|
857
|
+
const i = t.content[this._currentPart.contentIndex];
|
|
858
|
+
i.type === "assistant_thought" ? (Array.isArray(i.data) || (i.data = []), e.delta.trim() && i.data.push(e.delta.trim())) : i.data = (i.data || "") + e.delta;
|
|
713
859
|
}
|
|
714
860
|
handlePartFinish() {
|
|
715
861
|
if (!this._currentPart) {
|
|
@@ -718,9 +864,9 @@ class E extends b {
|
|
|
718
864
|
}
|
|
719
865
|
const t = this._messages.findIndex((e) => e.id === this._currentPart.messageId);
|
|
720
866
|
if (t !== -1) {
|
|
721
|
-
const e = this._messages[t],
|
|
722
|
-
if (
|
|
723
|
-
|
|
867
|
+
const e = this._messages[t], i = e.content[this._currentPart.contentIndex];
|
|
868
|
+
if (i) {
|
|
869
|
+
i.status = { type: "complete" };
|
|
724
870
|
const r = [
|
|
725
871
|
...this._messages.slice(0, t),
|
|
726
872
|
{ ...e, timestamp: Date.now() },
|
|
@@ -732,32 +878,32 @@ class E extends b {
|
|
|
732
878
|
this._currentPart = null;
|
|
733
879
|
}
|
|
734
880
|
updateMessageStatus(t, e) {
|
|
735
|
-
const
|
|
736
|
-
if (
|
|
881
|
+
const i = this._messages.findIndex((a) => a.id === t);
|
|
882
|
+
if (i === -1) return;
|
|
737
883
|
const r = [
|
|
738
|
-
...this._messages.slice(0,
|
|
884
|
+
...this._messages.slice(0, i),
|
|
739
885
|
{
|
|
740
|
-
...this._messages[
|
|
886
|
+
...this._messages[i],
|
|
741
887
|
status: e
|
|
742
888
|
},
|
|
743
|
-
...this._messages.slice(
|
|
889
|
+
...this._messages.slice(i + 1)
|
|
744
890
|
];
|
|
745
891
|
this.updateMessages(r);
|
|
746
892
|
}
|
|
747
893
|
completeStreamingContent(t) {
|
|
748
894
|
const e = this._messages.findIndex((c) => c.id === t);
|
|
749
895
|
if (e === -1) return;
|
|
750
|
-
const
|
|
751
|
-
if (!
|
|
752
|
-
var
|
|
753
|
-
return ((
|
|
896
|
+
const i = this._messages[e];
|
|
897
|
+
if (!i.content.some((c) => {
|
|
898
|
+
var h;
|
|
899
|
+
return ((h = c.status) == null ? void 0 : h.type) === "streaming";
|
|
754
900
|
})) return;
|
|
755
|
-
const
|
|
756
|
-
var
|
|
757
|
-
return ((
|
|
901
|
+
const a = i.content.map((c) => {
|
|
902
|
+
var h;
|
|
903
|
+
return ((h = c.status) == null ? void 0 : h.type) === "streaming" ? { ...c, status: { type: "complete" } } : c;
|
|
758
904
|
}), o = [
|
|
759
905
|
...this._messages.slice(0, e),
|
|
760
|
-
{ ...
|
|
906
|
+
{ ...i, content: a, timestamp: Date.now() },
|
|
761
907
|
...this._messages.slice(e + 1)
|
|
762
908
|
];
|
|
763
909
|
this.updateMessages(o);
|
|
@@ -777,8 +923,18 @@ class E extends b {
|
|
|
777
923
|
setTitle(t) {
|
|
778
924
|
this._title = t, this.notifySubscribers();
|
|
779
925
|
}
|
|
926
|
+
updateMessageContent(t, e) {
|
|
927
|
+
const i = this._messages.findIndex((c) => c.id === t);
|
|
928
|
+
if (i === -1) return;
|
|
929
|
+
const r = this._messages[i], a = e(r.content), o = [
|
|
930
|
+
...this._messages.slice(0, i),
|
|
931
|
+
{ ...r, content: a, timestamp: Date.now() },
|
|
932
|
+
...this._messages.slice(i + 1)
|
|
933
|
+
];
|
|
934
|
+
this.updateMessages(o);
|
|
935
|
+
}
|
|
780
936
|
}
|
|
781
|
-
class
|
|
937
|
+
class it extends _ {
|
|
782
938
|
constructor(t) {
|
|
783
939
|
super();
|
|
784
940
|
u(this, "_mainThreadId");
|
|
@@ -789,13 +945,13 @@ class st extends b {
|
|
|
789
945
|
u(this, "_searchQuery");
|
|
790
946
|
u(this, "_abortController", null);
|
|
791
947
|
u(this, "main");
|
|
792
|
-
this.config = t, this._mainThreadId =
|
|
793
|
-
const e = new
|
|
948
|
+
this.config = t, this._mainThreadId = k();
|
|
949
|
+
const e = new M({
|
|
794
950
|
streamAdapter: t.streamAdapter,
|
|
795
951
|
capabilityExecutionManager: t.capabilityExecutionManager
|
|
796
952
|
});
|
|
797
953
|
this.main = new R(e), this._threads.set(this._mainThreadId, this.main);
|
|
798
|
-
const
|
|
954
|
+
const i = {
|
|
799
955
|
id: this._mainThreadId,
|
|
800
956
|
title: "New Chat",
|
|
801
957
|
status: { type: "regular" },
|
|
@@ -803,9 +959,9 @@ class st extends b {
|
|
|
803
959
|
createdAt: Date.now(),
|
|
804
960
|
updatedAt: Date.now()
|
|
805
961
|
};
|
|
806
|
-
this._threadStates.set(this._mainThreadId,
|
|
807
|
-
const r = new
|
|
808
|
-
state:
|
|
962
|
+
this._threadStates.set(this._mainThreadId, i);
|
|
963
|
+
const r = new T({
|
|
964
|
+
state: i,
|
|
809
965
|
onSwitchTo: this.switchToThread.bind(this),
|
|
810
966
|
onRename: this.renameThread.bind(this),
|
|
811
967
|
onDelete: this.deleteThread.bind(this)
|
|
@@ -824,8 +980,8 @@ class st extends b {
|
|
|
824
980
|
}
|
|
825
981
|
getState() {
|
|
826
982
|
const t = [], e = {};
|
|
827
|
-
for (const [
|
|
828
|
-
e[
|
|
983
|
+
for (const [i, r] of this._threadStates)
|
|
984
|
+
e[i] = r, r.status.type === "regular" && t.push(i);
|
|
829
985
|
return {
|
|
830
986
|
mainThreadId: this._mainThreadId,
|
|
831
987
|
threads: t,
|
|
@@ -835,12 +991,12 @@ class st extends b {
|
|
|
835
991
|
};
|
|
836
992
|
}
|
|
837
993
|
async switchToThread(t) {
|
|
838
|
-
var
|
|
994
|
+
var a, o;
|
|
839
995
|
const e = this._threads.get(t);
|
|
840
996
|
if (!e)
|
|
841
997
|
throw new Error(`Thread ${t} not found`);
|
|
842
|
-
const
|
|
843
|
-
|
|
998
|
+
const i = this._threadStates.get(this._mainThreadId);
|
|
999
|
+
i && (i.isMain = !1, this._threadStates.set(this._mainThreadId, i), (a = this._threadItems.get(this._mainThreadId)) == null || a.updateState(i)), this._mainThreadId = t;
|
|
844
1000
|
const r = this._threadStates.get(t);
|
|
845
1001
|
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)) {
|
|
846
1002
|
this._isLoading = !0, this.notifySubscribers();
|
|
@@ -856,11 +1012,11 @@ class st extends b {
|
|
|
856
1012
|
this.notifySubscribers();
|
|
857
1013
|
}
|
|
858
1014
|
async switchToNewThread() {
|
|
859
|
-
const t =
|
|
1015
|
+
const t = k(), e = new M({
|
|
860
1016
|
streamAdapter: this.config.streamAdapter,
|
|
861
1017
|
capabilityExecutionManager: this.config.capabilityExecutionManager
|
|
862
|
-
}),
|
|
863
|
-
this._threads.set(t,
|
|
1018
|
+
}), i = new R(e);
|
|
1019
|
+
this._threads.set(t, i);
|
|
864
1020
|
const r = {
|
|
865
1021
|
id: t,
|
|
866
1022
|
title: "New Chat",
|
|
@@ -870,18 +1026,18 @@ class st extends b {
|
|
|
870
1026
|
updatedAt: Date.now()
|
|
871
1027
|
};
|
|
872
1028
|
this._threadStates.set(t, r);
|
|
873
|
-
const
|
|
1029
|
+
const a = new T({
|
|
874
1030
|
state: r,
|
|
875
1031
|
onSwitchTo: this.switchToThread.bind(this),
|
|
876
1032
|
onRename: this.renameThread.bind(this),
|
|
877
1033
|
onDelete: this.deleteThread.bind(this)
|
|
878
1034
|
});
|
|
879
|
-
if (this._threadItems.set(t,
|
|
880
|
-
this.syncThreadStateFromRuntime(t,
|
|
1035
|
+
if (this._threadItems.set(t, a), i.subscribe(() => {
|
|
1036
|
+
this.syncThreadStateFromRuntime(t, i), this.notifySubscribers();
|
|
881
1037
|
}), this.config.threadListAdapter)
|
|
882
1038
|
try {
|
|
883
1039
|
const o = await this.config.threadListAdapter.createThread();
|
|
884
|
-
r.conversationId = o.conversationId, this._threadStates.set(t, r),
|
|
1040
|
+
r.conversationId = o.conversationId, this._threadStates.set(t, r), a.updateState(r);
|
|
885
1041
|
} catch (o) {
|
|
886
1042
|
console.error("Failed to create thread:", o);
|
|
887
1043
|
}
|
|
@@ -893,29 +1049,29 @@ class st extends b {
|
|
|
893
1049
|
if (this._isLoading)
|
|
894
1050
|
return [];
|
|
895
1051
|
if (this._abortController && this._abortController.abort(), this._abortController = new AbortController(), (t == null ? void 0 : t.query) !== void 0 && (this._searchQuery = t.query), t != null && t.replace) {
|
|
896
|
-
const e = Array.from(this._threads.keys()).filter((
|
|
897
|
-
for (const
|
|
898
|
-
this._threads.delete(
|
|
1052
|
+
const e = Array.from(this._threads.keys()).filter((i) => i !== this._mainThreadId);
|
|
1053
|
+
for (const i of e)
|
|
1054
|
+
this._threads.delete(i), this._threadItems.delete(i), this._threadStates.delete(i);
|
|
899
1055
|
}
|
|
900
1056
|
this._isLoading = !0, this.notifySubscribers();
|
|
901
1057
|
try {
|
|
902
1058
|
const e = await this.config.threadListAdapter.loadThreads(t);
|
|
903
|
-
for (const
|
|
904
|
-
if (this._threadStates.has(
|
|
1059
|
+
for (const i of e) {
|
|
1060
|
+
if (this._threadStates.has(i.id))
|
|
905
1061
|
continue;
|
|
906
|
-
const r = new
|
|
1062
|
+
const r = new M({
|
|
907
1063
|
streamAdapter: this.config.streamAdapter,
|
|
908
1064
|
capabilityExecutionManager: this.config.capabilityExecutionManager
|
|
909
|
-
}),
|
|
910
|
-
this._threads.set(
|
|
911
|
-
const o = new
|
|
912
|
-
state:
|
|
1065
|
+
}), a = new R(r);
|
|
1066
|
+
this._threads.set(i.id, a), this._threadStates.set(i.id, i);
|
|
1067
|
+
const o = new T({
|
|
1068
|
+
state: i,
|
|
913
1069
|
onSwitchTo: this.switchToThread.bind(this),
|
|
914
1070
|
onRename: this.renameThread.bind(this),
|
|
915
1071
|
onDelete: this.deleteThread.bind(this)
|
|
916
1072
|
});
|
|
917
|
-
this._threadItems.set(
|
|
918
|
-
this.syncThreadStateFromRuntime(
|
|
1073
|
+
this._threadItems.set(i.id, o), a.subscribe(() => {
|
|
1074
|
+
this.syncThreadStateFromRuntime(i.id, a), this.notifySubscribers();
|
|
919
1075
|
});
|
|
920
1076
|
}
|
|
921
1077
|
return e;
|
|
@@ -930,18 +1086,18 @@ class st extends b {
|
|
|
930
1086
|
*/
|
|
931
1087
|
syncThreadStateFromRuntime(t, e) {
|
|
932
1088
|
var r;
|
|
933
|
-
const
|
|
934
|
-
|
|
1089
|
+
const i = this._threadStates.get(t);
|
|
1090
|
+
i && (i.conversationId !== e.conversationId || i.title !== e.title) && (i.conversationId = e.conversationId, i.title = e.title || i.title, i.updatedAt = Date.now(), this._threadStates.set(t, i), (r = this._threadItems.get(t)) == null || r.updateState(i));
|
|
935
1091
|
}
|
|
936
1092
|
async renameThread(t, e) {
|
|
937
1093
|
var r;
|
|
938
|
-
const
|
|
939
|
-
if (
|
|
940
|
-
if (
|
|
1094
|
+
const i = this._threadStates.get(t);
|
|
1095
|
+
if (i) {
|
|
1096
|
+
if (i.title = e, i.updatedAt = Date.now(), this._threadStates.set(t, i), (r = this._threadItems.get(t)) == null || r.updateState(i), this.config.threadListAdapter)
|
|
941
1097
|
try {
|
|
942
1098
|
await this.config.threadListAdapter.updateThread(t, { title: e });
|
|
943
|
-
} catch (
|
|
944
|
-
console.error("Failed to rename thread:",
|
|
1099
|
+
} catch (a) {
|
|
1100
|
+
console.error("Failed to rename thread:", a);
|
|
945
1101
|
}
|
|
946
1102
|
this.notifySubscribers();
|
|
947
1103
|
}
|
|
@@ -950,7 +1106,7 @@ class st extends b {
|
|
|
950
1106
|
if (t === this._mainThreadId && this._threads.size === 1)
|
|
951
1107
|
throw new Error("Cannot delete the last thread");
|
|
952
1108
|
if (t === this._mainThreadId) {
|
|
953
|
-
const e = Array.from(this._threads.keys()).find((
|
|
1109
|
+
const e = Array.from(this._threads.keys()).find((i) => i !== t);
|
|
954
1110
|
e && await this.switchToThread(e);
|
|
955
1111
|
}
|
|
956
1112
|
if (this._threads.delete(t), this._threadItems.delete(t), this._threadStates.delete(t), this.config.threadListAdapter)
|
|
@@ -962,22 +1118,23 @@ class st extends b {
|
|
|
962
1118
|
this.notifySubscribers();
|
|
963
1119
|
}
|
|
964
1120
|
}
|
|
965
|
-
class
|
|
1121
|
+
class yt extends _ {
|
|
966
1122
|
constructor(t) {
|
|
967
1123
|
super();
|
|
968
1124
|
u(this, "threads");
|
|
969
1125
|
u(this, "pluginRegistry");
|
|
970
1126
|
u(this, "capabilityRegistry");
|
|
971
1127
|
u(this, "capabilityExecutionManager");
|
|
1128
|
+
u(this, "quickActionRegistry");
|
|
972
1129
|
u(this, "_contentFocusRuntime");
|
|
973
1130
|
u(this, "_currentThreadUnsubscribe");
|
|
974
1131
|
this.pluginRegistry = new G(), t.plugins && t.plugins.forEach((e) => {
|
|
975
1132
|
this.pluginRegistry.registerPlugin(e);
|
|
976
|
-
}), this.capabilityRegistry = new Y(), this.capabilityExecutionManager = new K((e) => this.capabilityRegistry.getHandler(e)), this.threads = new
|
|
1133
|
+
}), this.capabilityRegistry = new Y(), this.capabilityExecutionManager = new K((e) => this.capabilityRegistry.getHandler(e)), this.quickActionRegistry = new X(), this.threads = new it({
|
|
977
1134
|
streamAdapter: t.streamAdapter,
|
|
978
1135
|
threadListAdapter: t.threadListAdapter,
|
|
979
1136
|
capabilityExecutionManager: this.capabilityExecutionManager
|
|
980
|
-
}), this._contentFocusRuntime = new
|
|
1137
|
+
}), this._contentFocusRuntime = new Z(), this._contentFocusRuntime.subscribe(() => {
|
|
981
1138
|
this.notifySubscribers();
|
|
982
1139
|
}), this.threads.subscribe(() => {
|
|
983
1140
|
this.subscribeToCurrentThread(), this.notifySubscribers();
|
|
@@ -1023,20 +1180,20 @@ class mt extends b {
|
|
|
1023
1180
|
autoFocusLastContent(t) {
|
|
1024
1181
|
var e;
|
|
1025
1182
|
if (t.length !== 0)
|
|
1026
|
-
for (let
|
|
1027
|
-
const r = t[
|
|
1183
|
+
for (let i = t.length - 1; i >= 0; i--) {
|
|
1184
|
+
const r = t[i];
|
|
1028
1185
|
if (r.role === "assistant")
|
|
1029
|
-
for (let
|
|
1030
|
-
const o = r.content[
|
|
1186
|
+
for (let a = r.content.length - 1; a >= 0; a--) {
|
|
1187
|
+
const o = r.content[a], c = this.pluginRegistry.getRenderersByType(o.type);
|
|
1031
1188
|
if (c.length > 0 && ((e = c[0].capabilities) != null && e.supportsFocus)) {
|
|
1032
|
-
this._contentFocusRuntime.isActive && this._contentFocusRuntime.focusedMessageId === r.id && this._contentFocusRuntime.focusedContentIndex ===
|
|
1189
|
+
this._contentFocusRuntime.isActive && this._contentFocusRuntime.focusedMessageId === r.id && this._contentFocusRuntime.focusedContentIndex === a || this._contentFocusRuntime.focus(o, r, a, "detail");
|
|
1033
1190
|
return;
|
|
1034
1191
|
}
|
|
1035
1192
|
}
|
|
1036
1193
|
}
|
|
1037
1194
|
}
|
|
1038
1195
|
}
|
|
1039
|
-
var
|
|
1196
|
+
var E = { exports: {} }, x = {};
|
|
1040
1197
|
/*
|
|
1041
1198
|
object-assign
|
|
1042
1199
|
(c) Sindre Sorhus
|
|
@@ -1046,43 +1203,43 @@ var A, D;
|
|
|
1046
1203
|
function rt() {
|
|
1047
1204
|
if (D) return A;
|
|
1048
1205
|
D = 1;
|
|
1049
|
-
var
|
|
1206
|
+
var n = Object.getOwnPropertySymbols, s = Object.prototype.hasOwnProperty, t = Object.prototype.propertyIsEnumerable;
|
|
1050
1207
|
function e(r) {
|
|
1051
1208
|
if (r == null)
|
|
1052
1209
|
throw new TypeError("Object.assign cannot be called with null or undefined");
|
|
1053
1210
|
return Object(r);
|
|
1054
1211
|
}
|
|
1055
|
-
function
|
|
1212
|
+
function i() {
|
|
1056
1213
|
try {
|
|
1057
1214
|
if (!Object.assign)
|
|
1058
1215
|
return !1;
|
|
1059
1216
|
var r = new String("abc");
|
|
1060
1217
|
if (r[5] = "de", Object.getOwnPropertyNames(r)[0] === "5")
|
|
1061
1218
|
return !1;
|
|
1062
|
-
for (var
|
|
1063
|
-
|
|
1064
|
-
var c = Object.getOwnPropertyNames(
|
|
1065
|
-
return
|
|
1219
|
+
for (var a = {}, o = 0; o < 10; o++)
|
|
1220
|
+
a["_" + String.fromCharCode(o)] = o;
|
|
1221
|
+
var c = Object.getOwnPropertyNames(a).map(function(l) {
|
|
1222
|
+
return a[l];
|
|
1066
1223
|
});
|
|
1067
1224
|
if (c.join("") !== "0123456789")
|
|
1068
1225
|
return !1;
|
|
1069
|
-
var
|
|
1226
|
+
var h = {};
|
|
1070
1227
|
return "abcdefghijklmnopqrst".split("").forEach(function(l) {
|
|
1071
|
-
|
|
1072
|
-
}), Object.keys(Object.assign({},
|
|
1228
|
+
h[l] = l;
|
|
1229
|
+
}), Object.keys(Object.assign({}, h)).join("") === "abcdefghijklmnopqrst";
|
|
1073
1230
|
} catch {
|
|
1074
1231
|
return !1;
|
|
1075
1232
|
}
|
|
1076
1233
|
}
|
|
1077
|
-
return A =
|
|
1078
|
-
for (var o, c = e(r),
|
|
1234
|
+
return A = i() ? Object.assign : function(r, a) {
|
|
1235
|
+
for (var o, c = e(r), h, l = 1; l < arguments.length; l++) {
|
|
1079
1236
|
o = Object(arguments[l]);
|
|
1080
|
-
for (var
|
|
1081
|
-
|
|
1082
|
-
if (
|
|
1083
|
-
|
|
1084
|
-
for (var
|
|
1085
|
-
t.call(o,
|
|
1237
|
+
for (var d in o)
|
|
1238
|
+
s.call(o, d) && (c[d] = o[d]);
|
|
1239
|
+
if (n) {
|
|
1240
|
+
h = n(o);
|
|
1241
|
+
for (var p = 0; p < h.length; p++)
|
|
1242
|
+
t.call(o, h[p]) && (c[h[p]] = o[h[p]]);
|
|
1086
1243
|
}
|
|
1087
1244
|
}
|
|
1088
1245
|
return c;
|
|
@@ -1096,72 +1253,72 @@ function rt() {
|
|
|
1096
1253
|
* This source code is licensed under the MIT license found in the
|
|
1097
1254
|
* LICENSE file in the root directory of this source tree.
|
|
1098
1255
|
*/
|
|
1099
|
-
var
|
|
1256
|
+
var N;
|
|
1100
1257
|
function nt() {
|
|
1101
|
-
if (
|
|
1102
|
-
|
|
1103
|
-
var
|
|
1258
|
+
if (N) return x;
|
|
1259
|
+
N = 1, rt();
|
|
1260
|
+
var n = q, s = 60103;
|
|
1104
1261
|
if (x.Fragment = 60107, typeof Symbol == "function" && Symbol.for) {
|
|
1105
1262
|
var t = Symbol.for;
|
|
1106
|
-
|
|
1263
|
+
s = t("react.element"), x.Fragment = t("react.fragment");
|
|
1107
1264
|
}
|
|
1108
|
-
var e =
|
|
1109
|
-
function
|
|
1110
|
-
var l,
|
|
1111
|
-
|
|
1112
|
-
for (l in c)
|
|
1113
|
-
if (o && o.defaultProps) for (l in c = o.defaultProps, c)
|
|
1114
|
-
return { $$typeof:
|
|
1265
|
+
var e = n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, i = Object.prototype.hasOwnProperty, r = { key: !0, ref: !0, __self: !0, __source: !0 };
|
|
1266
|
+
function a(o, c, h) {
|
|
1267
|
+
var l, d = {}, p = null, g = null;
|
|
1268
|
+
h !== void 0 && (p = "" + h), c.key !== void 0 && (p = "" + c.key), c.ref !== void 0 && (g = c.ref);
|
|
1269
|
+
for (l in c) i.call(c, l) && !r.hasOwnProperty(l) && (d[l] = c[l]);
|
|
1270
|
+
if (o && o.defaultProps) for (l in c = o.defaultProps, c) d[l] === void 0 && (d[l] = c[l]);
|
|
1271
|
+
return { $$typeof: s, type: o, key: p, ref: g, props: d, _owner: e.current };
|
|
1115
1272
|
}
|
|
1116
|
-
return x.jsx =
|
|
1273
|
+
return x.jsx = a, x.jsxs = a, x;
|
|
1117
1274
|
}
|
|
1118
1275
|
var O;
|
|
1119
|
-
function
|
|
1120
|
-
return O || (O = 1,
|
|
1276
|
+
function at() {
|
|
1277
|
+
return O || (O = 1, E.exports = nt()), E.exports;
|
|
1121
1278
|
}
|
|
1122
|
-
var
|
|
1123
|
-
const
|
|
1124
|
-
function
|
|
1125
|
-
return /* @__PURE__ */
|
|
1279
|
+
var w = at();
|
|
1280
|
+
const W = U(null);
|
|
1281
|
+
function _t({ runtime: n, children: s }) {
|
|
1282
|
+
return /* @__PURE__ */ w.jsx(W.Provider, { value: n, children: s });
|
|
1126
1283
|
}
|
|
1127
|
-
function
|
|
1128
|
-
const
|
|
1129
|
-
if (!
|
|
1284
|
+
function ot() {
|
|
1285
|
+
const n = B(W);
|
|
1286
|
+
if (!n)
|
|
1130
1287
|
throw new Error("useAssistantRuntimeContext must be used within AssistantRuntimeProvider");
|
|
1131
|
-
return
|
|
1288
|
+
return n;
|
|
1132
1289
|
}
|
|
1133
1290
|
function f() {
|
|
1134
|
-
return
|
|
1291
|
+
return ot();
|
|
1135
1292
|
}
|
|
1136
|
-
function
|
|
1137
|
-
const
|
|
1293
|
+
function St() {
|
|
1294
|
+
const n = f();
|
|
1138
1295
|
return {
|
|
1139
|
-
switchToThread: (
|
|
1140
|
-
switchToNewThread: () =>
|
|
1141
|
-
loadThreads: (
|
|
1142
|
-
renameThread: (
|
|
1143
|
-
var e,
|
|
1144
|
-
return (
|
|
1296
|
+
switchToThread: (s) => n.threads.switchToThread(s),
|
|
1297
|
+
switchToNewThread: () => n.threads.switchToNewThread(),
|
|
1298
|
+
loadThreads: (s) => n.threads.loadThreads(s),
|
|
1299
|
+
renameThread: (s, t) => {
|
|
1300
|
+
var e, i;
|
|
1301
|
+
return (i = (e = n.threads).renameThread) == null ? void 0 : i.call(e, s, t);
|
|
1145
1302
|
},
|
|
1146
|
-
deleteThread: (
|
|
1303
|
+
deleteThread: (s) => {
|
|
1147
1304
|
var t, e;
|
|
1148
|
-
return (e = (t =
|
|
1305
|
+
return (e = (t = n.threads).deleteThread) == null ? void 0 : e.call(t, s);
|
|
1149
1306
|
}
|
|
1150
1307
|
};
|
|
1151
1308
|
}
|
|
1152
1309
|
function xt() {
|
|
1153
|
-
const
|
|
1154
|
-
return
|
|
1155
|
-
t(
|
|
1156
|
-
}), [
|
|
1310
|
+
const n = f(), [s, t] = y(n.threads.getState());
|
|
1311
|
+
return m(() => n.threads.subscribe(() => {
|
|
1312
|
+
t(n.threads.getState());
|
|
1313
|
+
}), [n]), s;
|
|
1157
1314
|
}
|
|
1158
|
-
function
|
|
1159
|
-
const
|
|
1160
|
-
return
|
|
1315
|
+
function ct() {
|
|
1316
|
+
const s = f().threads.getMainThread(), [, t] = y({});
|
|
1317
|
+
return m(() => s.subscribe(() => {
|
|
1161
1318
|
t({});
|
|
1162
|
-
}), [
|
|
1319
|
+
}), [s]), s;
|
|
1163
1320
|
}
|
|
1164
|
-
var
|
|
1321
|
+
var P = { exports: {} }, F = {};
|
|
1165
1322
|
/**
|
|
1166
1323
|
* @license React
|
|
1167
1324
|
* use-sync-external-store-shim.production.js
|
|
@@ -1171,87 +1328,87 @@ var F = { exports: {} }, P = {};
|
|
|
1171
1328
|
* This source code is licensed under the MIT license found in the
|
|
1172
1329
|
* LICENSE file in the root directory of this source tree.
|
|
1173
1330
|
*/
|
|
1174
|
-
var
|
|
1175
|
-
function
|
|
1176
|
-
if (
|
|
1177
|
-
|
|
1178
|
-
var
|
|
1179
|
-
function
|
|
1180
|
-
return
|
|
1181
|
-
}
|
|
1182
|
-
var t = typeof Object.is == "function" ? Object.is :
|
|
1183
|
-
function o(
|
|
1184
|
-
var
|
|
1331
|
+
var j;
|
|
1332
|
+
function ut() {
|
|
1333
|
+
if (j) return F;
|
|
1334
|
+
j = 1;
|
|
1335
|
+
var n = q;
|
|
1336
|
+
function s(d, p) {
|
|
1337
|
+
return d === p && (d !== 0 || 1 / d === 1 / p) || d !== d && p !== p;
|
|
1338
|
+
}
|
|
1339
|
+
var t = typeof Object.is == "function" ? Object.is : s, e = n.useState, i = n.useEffect, r = n.useLayoutEffect, a = n.useDebugValue;
|
|
1340
|
+
function o(d, p) {
|
|
1341
|
+
var g = p(), S = e({ inst: { value: g, getSnapshot: p } }), b = S[0].inst, I = S[1];
|
|
1185
1342
|
return r(
|
|
1186
1343
|
function() {
|
|
1187
|
-
|
|
1344
|
+
b.value = g, b.getSnapshot = p, c(b) && I({ inst: b });
|
|
1188
1345
|
},
|
|
1189
|
-
[
|
|
1190
|
-
),
|
|
1346
|
+
[d, g, p]
|
|
1347
|
+
), i(
|
|
1191
1348
|
function() {
|
|
1192
|
-
return c(
|
|
1193
|
-
c(
|
|
1349
|
+
return c(b) && I({ inst: b }), d(function() {
|
|
1350
|
+
c(b) && I({ inst: b });
|
|
1194
1351
|
});
|
|
1195
1352
|
},
|
|
1196
|
-
[
|
|
1197
|
-
),
|
|
1353
|
+
[d]
|
|
1354
|
+
), a(g), g;
|
|
1198
1355
|
}
|
|
1199
|
-
function c(
|
|
1200
|
-
var
|
|
1201
|
-
|
|
1356
|
+
function c(d) {
|
|
1357
|
+
var p = d.getSnapshot;
|
|
1358
|
+
d = d.value;
|
|
1202
1359
|
try {
|
|
1203
|
-
var
|
|
1204
|
-
return !t(
|
|
1360
|
+
var g = p();
|
|
1361
|
+
return !t(d, g);
|
|
1205
1362
|
} catch {
|
|
1206
1363
|
return !0;
|
|
1207
1364
|
}
|
|
1208
1365
|
}
|
|
1209
|
-
function d
|
|
1210
|
-
return
|
|
1366
|
+
function h(d, p) {
|
|
1367
|
+
return p();
|
|
1211
1368
|
}
|
|
1212
|
-
var l = typeof window > "u" || typeof window.document > "u" || typeof window.document.createElement > "u" ?
|
|
1213
|
-
return
|
|
1369
|
+
var l = typeof window > "u" || typeof window.document > "u" || typeof window.document.createElement > "u" ? h : o;
|
|
1370
|
+
return F.useSyncExternalStore = n.useSyncExternalStore !== void 0 ? n.useSyncExternalStore : l, F;
|
|
1214
1371
|
}
|
|
1215
|
-
var
|
|
1216
|
-
function
|
|
1217
|
-
return
|
|
1372
|
+
var L;
|
|
1373
|
+
function ht() {
|
|
1374
|
+
return L || (L = 1, P.exports = ut()), P.exports;
|
|
1218
1375
|
}
|
|
1219
|
-
var
|
|
1220
|
-
function
|
|
1221
|
-
const
|
|
1222
|
-
return
|
|
1223
|
-
(
|
|
1224
|
-
|
|
1376
|
+
var dt = ht();
|
|
1377
|
+
function wt() {
|
|
1378
|
+
const n = f();
|
|
1379
|
+
return dt.useSyncExternalStore(
|
|
1380
|
+
(s) => n.subscribe(() => {
|
|
1381
|
+
s();
|
|
1225
1382
|
}),
|
|
1226
|
-
() =>
|
|
1227
|
-
() =>
|
|
1383
|
+
() => n.thread.messages,
|
|
1384
|
+
() => n.thread.messages
|
|
1228
1385
|
);
|
|
1229
1386
|
}
|
|
1230
|
-
function
|
|
1231
|
-
const
|
|
1387
|
+
function Ct() {
|
|
1388
|
+
const n = ct(), [s, t] = y(""), [e, i] = y(!1);
|
|
1232
1389
|
return {
|
|
1233
|
-
text:
|
|
1390
|
+
text: s,
|
|
1234
1391
|
setText: t,
|
|
1235
1392
|
isSubmitting: e,
|
|
1236
|
-
send: async (
|
|
1237
|
-
if (
|
|
1238
|
-
const o =
|
|
1239
|
-
t(""),
|
|
1393
|
+
send: async (a) => {
|
|
1394
|
+
if (a == null || a.preventDefault(), !s.trim() || e) return;
|
|
1395
|
+
const o = s;
|
|
1396
|
+
t(""), i(!0);
|
|
1240
1397
|
try {
|
|
1241
|
-
await
|
|
1398
|
+
await n.send(o);
|
|
1242
1399
|
} catch (c) {
|
|
1243
1400
|
console.error("Failed to send message:", c), t(o);
|
|
1244
1401
|
} finally {
|
|
1245
|
-
|
|
1402
|
+
i(!1);
|
|
1246
1403
|
}
|
|
1247
1404
|
},
|
|
1248
1405
|
clear: () => t(""),
|
|
1249
|
-
append: (
|
|
1406
|
+
append: (a) => t((o) => o + a)
|
|
1250
1407
|
};
|
|
1251
1408
|
}
|
|
1252
|
-
function
|
|
1253
|
-
var r,
|
|
1254
|
-
const e = f().pluginRegistry.getBestRendererForType(
|
|
1409
|
+
function Q(n, s) {
|
|
1410
|
+
var r, a, o, c;
|
|
1411
|
+
const e = f().pluginRegistry.getBestRendererForType(n);
|
|
1255
1412
|
if (!e)
|
|
1256
1413
|
return {
|
|
1257
1414
|
component: null,
|
|
@@ -1260,222 +1417,253 @@ function $(a, n) {
|
|
|
1260
1417
|
supportsPreview: !1,
|
|
1261
1418
|
supportsFullscreen: !1
|
|
1262
1419
|
};
|
|
1263
|
-
const
|
|
1420
|
+
const i = s ? (r = e.auxiliary) == null ? void 0 : r[s] : null;
|
|
1264
1421
|
return {
|
|
1265
1422
|
component: e.component,
|
|
1266
|
-
auxiliaryComponent:
|
|
1267
|
-
supportsFocus: ((
|
|
1423
|
+
auxiliaryComponent: i,
|
|
1424
|
+
supportsFocus: ((a = e.capabilities) == null ? void 0 : a.supportsFocus) ?? !1,
|
|
1268
1425
|
supportsPreview: ((o = e.capabilities) == null ? void 0 : o.supportsPreview) ?? !1,
|
|
1269
1426
|
supportsFullscreen: ((c = e.capabilities) == null ? void 0 : c.supportsFullscreen) ?? !1
|
|
1270
1427
|
};
|
|
1271
1428
|
}
|
|
1272
|
-
function
|
|
1273
|
-
const
|
|
1274
|
-
return
|
|
1275
|
-
t(
|
|
1276
|
-
}), [
|
|
1277
|
-
...
|
|
1278
|
-
focus: (e,
|
|
1279
|
-
blur: () =>
|
|
1280
|
-
toggle: (e,
|
|
1281
|
-
switchContext: (e) =>
|
|
1282
|
-
focusNext: () =>
|
|
1283
|
-
focusPrevious: () =>
|
|
1429
|
+
function It() {
|
|
1430
|
+
const n = f(), [s, t] = y(n.contentFocus.state);
|
|
1431
|
+
return m(() => n.contentFocus.subscribe(() => {
|
|
1432
|
+
t(n.contentFocus.state);
|
|
1433
|
+
}), [n]), {
|
|
1434
|
+
...s,
|
|
1435
|
+
focus: (e, i, r, a) => n.contentFocus.focus(e, i, r, a),
|
|
1436
|
+
blur: () => n.contentFocus.blur(),
|
|
1437
|
+
toggle: (e, i, r, a) => n.contentFocus.toggle(e, i, r, a),
|
|
1438
|
+
switchContext: (e) => n.contentFocus.switchContext(e),
|
|
1439
|
+
focusNext: () => n.contentFocus.focusNext(n.thread.messages),
|
|
1440
|
+
focusPrevious: () => n.contentFocus.focusPrevious(n.thread.messages)
|
|
1284
1441
|
};
|
|
1285
1442
|
}
|
|
1286
|
-
function
|
|
1287
|
-
const
|
|
1288
|
-
|
|
1289
|
-
const t =
|
|
1290
|
-
return
|
|
1291
|
-
|
|
1443
|
+
function lt(n) {
|
|
1444
|
+
const s = f();
|
|
1445
|
+
m(() => {
|
|
1446
|
+
const t = n.priority ?? 0;
|
|
1447
|
+
return n.execute && s.capabilityRegistry.registerHandler(n.name, { execute: n.execute }, t), n.render && s.capabilityRegistry.registerRenderer(
|
|
1448
|
+
n.name,
|
|
1292
1449
|
{
|
|
1293
|
-
component:
|
|
1450
|
+
component: n.render
|
|
1294
1451
|
},
|
|
1295
1452
|
t
|
|
1296
1453
|
), () => {
|
|
1297
|
-
|
|
1454
|
+
s.capabilityRegistry.unregister(n.name);
|
|
1298
1455
|
};
|
|
1299
|
-
}, [
|
|
1456
|
+
}, [n.name, s]);
|
|
1300
1457
|
}
|
|
1301
|
-
function
|
|
1302
|
-
const
|
|
1303
|
-
() =>
|
|
1304
|
-
), [,
|
|
1305
|
-
return
|
|
1306
|
-
const r =
|
|
1307
|
-
return e(r),
|
|
1308
|
-
if (o ===
|
|
1309
|
-
const c =
|
|
1310
|
-
e(c),
|
|
1458
|
+
function pt(n) {
|
|
1459
|
+
const s = f(), [t, e] = y(
|
|
1460
|
+
() => s.capabilityExecutionManager.getExecution(n)
|
|
1461
|
+
), [, i] = V((r) => r + 1, 0);
|
|
1462
|
+
return m(() => {
|
|
1463
|
+
const r = s.capabilityExecutionManager.getExecution(n);
|
|
1464
|
+
return e(r), s.capabilityExecutionManager.subscribe((o) => {
|
|
1465
|
+
if (o === n) {
|
|
1466
|
+
const c = s.capabilityExecutionManager.getExecution(n);
|
|
1467
|
+
e(c), i();
|
|
1311
1468
|
}
|
|
1312
1469
|
});
|
|
1313
|
-
}, [
|
|
1470
|
+
}, [n, s]), t;
|
|
1314
1471
|
}
|
|
1315
|
-
const
|
|
1316
|
-
function
|
|
1317
|
-
const [
|
|
1472
|
+
const $ = U(void 0);
|
|
1473
|
+
function vt({ children: n }) {
|
|
1474
|
+
const [s, t] = y({}), e = C((c, h) => {
|
|
1318
1475
|
t((l) => {
|
|
1319
|
-
if (
|
|
1320
|
-
const { [c]:
|
|
1321
|
-
return
|
|
1476
|
+
if (h === null) {
|
|
1477
|
+
const { [c]: d, ...p } = l;
|
|
1478
|
+
return p;
|
|
1322
1479
|
}
|
|
1323
1480
|
return {
|
|
1324
1481
|
...l,
|
|
1325
|
-
[c]: { id: c, ...
|
|
1482
|
+
[c]: { id: c, ...h }
|
|
1326
1483
|
};
|
|
1327
1484
|
});
|
|
1328
|
-
}, []),
|
|
1329
|
-
t((
|
|
1330
|
-
const { [c]: l, ...
|
|
1331
|
-
return
|
|
1485
|
+
}, []), i = C((c) => {
|
|
1486
|
+
t((h) => {
|
|
1487
|
+
const { [c]: l, ...d } = h;
|
|
1488
|
+
return d;
|
|
1332
1489
|
});
|
|
1333
|
-
}, []), r = C(() => Object.values(
|
|
1334
|
-
(c,
|
|
1335
|
-
const l = Object.entries(
|
|
1336
|
-
(
|
|
1337
|
-
...
|
|
1338
|
-
[
|
|
1490
|
+
}, []), r = C(() => Object.values(s).reduce(
|
|
1491
|
+
(c, h) => {
|
|
1492
|
+
const l = Object.entries(h.data).reduce(
|
|
1493
|
+
(d, [p, g]) => ({
|
|
1494
|
+
...d,
|
|
1495
|
+
[p]: typeof g == "string" ? g : JSON.stringify(g)
|
|
1339
1496
|
}),
|
|
1340
1497
|
{}
|
|
1341
1498
|
);
|
|
1342
1499
|
return { ...c, ...l };
|
|
1343
1500
|
},
|
|
1344
1501
|
{}
|
|
1345
|
-
), [
|
|
1502
|
+
), [s]), a = C(() => {
|
|
1346
1503
|
t({});
|
|
1347
|
-
}, []), o =
|
|
1504
|
+
}, []), o = z(
|
|
1348
1505
|
() => ({
|
|
1349
|
-
contexts:
|
|
1506
|
+
contexts: s,
|
|
1350
1507
|
setContext: e,
|
|
1351
|
-
removeContext:
|
|
1508
|
+
removeContext: i,
|
|
1352
1509
|
getContextData: r,
|
|
1353
|
-
clearContexts:
|
|
1510
|
+
clearContexts: a
|
|
1354
1511
|
}),
|
|
1355
|
-
[
|
|
1512
|
+
[s, e, i, r, a]
|
|
1356
1513
|
);
|
|
1357
|
-
return /* @__PURE__ */
|
|
1514
|
+
return /* @__PURE__ */ w.jsx($.Provider, { value: o, children: n });
|
|
1358
1515
|
}
|
|
1359
1516
|
function gt() {
|
|
1360
|
-
const
|
|
1361
|
-
if (!
|
|
1517
|
+
const n = B($);
|
|
1518
|
+
if (!n)
|
|
1362
1519
|
throw new Error("useChatContext must be used within a ChatContextProvider");
|
|
1363
|
-
return
|
|
1520
|
+
return n;
|
|
1364
1521
|
}
|
|
1365
|
-
function Tt(
|
|
1366
|
-
const { setContext:
|
|
1367
|
-
|
|
1522
|
+
function Tt(n) {
|
|
1523
|
+
const { setContext: s, removeContext: t } = gt(), { id: e = "currentPage", ...i } = n;
|
|
1524
|
+
m(() => (s(e, i), () => {
|
|
1368
1525
|
t(e);
|
|
1369
|
-
}), [e,
|
|
1526
|
+
}), [e, i.displayName, JSON.stringify(i.data), i.priority, i.icon]);
|
|
1527
|
+
}
|
|
1528
|
+
function Rt(n, s = "merge") {
|
|
1529
|
+
const t = f();
|
|
1530
|
+
m(() => (t.quickActionRegistry.activateScope(n, s), () => {
|
|
1531
|
+
t.quickActionRegistry.deactivateScope(n);
|
|
1532
|
+
}), [n, s, t]);
|
|
1370
1533
|
}
|
|
1371
|
-
function
|
|
1372
|
-
const t = f()
|
|
1373
|
-
|
|
1534
|
+
function Mt(n, s) {
|
|
1535
|
+
const t = f();
|
|
1536
|
+
m(() => {
|
|
1537
|
+
const e = s || t.quickActionRegistry.getActiveScope();
|
|
1538
|
+
return t.quickActionRegistry.register(n, e), () => {
|
|
1539
|
+
t.quickActionRegistry.unregister(n.id, e);
|
|
1540
|
+
};
|
|
1541
|
+
}, [
|
|
1542
|
+
n.id,
|
|
1543
|
+
n.label,
|
|
1544
|
+
n.prompt,
|
|
1545
|
+
n.icon,
|
|
1546
|
+
n.description,
|
|
1547
|
+
n.priority,
|
|
1548
|
+
n.scope,
|
|
1549
|
+
s,
|
|
1550
|
+
t
|
|
1551
|
+
]);
|
|
1552
|
+
}
|
|
1553
|
+
function Et(n) {
|
|
1554
|
+
const s = f(), [t, e] = y([]);
|
|
1555
|
+
return m(() => (s.quickActionRegistry.getVisible(n).then(e), s.subscribe(() => {
|
|
1556
|
+
s.quickActionRegistry.getVisible(n).then(e);
|
|
1557
|
+
})), [s, n == null ? void 0 : n.scope]), t;
|
|
1558
|
+
}
|
|
1559
|
+
function ft({ message: n, content: s }) {
|
|
1560
|
+
const t = f(), e = s, i = pt(e.capabilityId), r = t.capabilityRegistry.getRenderer(e.capabilityName);
|
|
1561
|
+
if (!r || !i)
|
|
1374
1562
|
return null;
|
|
1375
|
-
const
|
|
1376
|
-
return /* @__PURE__ */
|
|
1377
|
-
|
|
1563
|
+
const a = r.component;
|
|
1564
|
+
return /* @__PURE__ */ w.jsx(
|
|
1565
|
+
a,
|
|
1378
1566
|
{
|
|
1379
|
-
capabilityName:
|
|
1380
|
-
capabilityId:
|
|
1381
|
-
args:
|
|
1382
|
-
result:
|
|
1383
|
-
status:
|
|
1384
|
-
message:
|
|
1567
|
+
capabilityName: i.name,
|
|
1568
|
+
capabilityId: i.id,
|
|
1569
|
+
args: i.args,
|
|
1570
|
+
result: i.result,
|
|
1571
|
+
status: i.status,
|
|
1572
|
+
message: n
|
|
1385
1573
|
}
|
|
1386
1574
|
);
|
|
1387
1575
|
}
|
|
1388
|
-
function
|
|
1389
|
-
const { component: t } =
|
|
1390
|
-
if (
|
|
1391
|
-
return /* @__PURE__ */
|
|
1576
|
+
function At({ message: n, content: s }) {
|
|
1577
|
+
const { component: t } = Q(s.type);
|
|
1578
|
+
if (s.type === "capability")
|
|
1579
|
+
return /* @__PURE__ */ w.jsx(ft, { message: n, content: s });
|
|
1392
1580
|
if (!t)
|
|
1393
1581
|
return null;
|
|
1394
1582
|
const e = t;
|
|
1395
|
-
return /* @__PURE__ */
|
|
1583
|
+
return /* @__PURE__ */ w.jsx(e, { content: s, message: n });
|
|
1396
1584
|
}
|
|
1397
|
-
function
|
|
1398
|
-
message:
|
|
1399
|
-
content:
|
|
1585
|
+
function Pt({
|
|
1586
|
+
message: n,
|
|
1587
|
+
content: s,
|
|
1400
1588
|
context: t,
|
|
1401
1589
|
onClose: e,
|
|
1402
|
-
onNavigate:
|
|
1590
|
+
onNavigate: i,
|
|
1403
1591
|
onSwitchContext: r
|
|
1404
1592
|
}) {
|
|
1405
|
-
const { auxiliaryComponent:
|
|
1406
|
-
if (!
|
|
1593
|
+
const { auxiliaryComponent: a } = Q(s.type, t);
|
|
1594
|
+
if (!a)
|
|
1407
1595
|
return null;
|
|
1408
|
-
const o =
|
|
1409
|
-
return /* @__PURE__ */
|
|
1596
|
+
const o = a;
|
|
1597
|
+
return /* @__PURE__ */ w.jsx(
|
|
1410
1598
|
o,
|
|
1411
1599
|
{
|
|
1412
|
-
content:
|
|
1413
|
-
message:
|
|
1600
|
+
content: s,
|
|
1601
|
+
message: n,
|
|
1414
1602
|
context: t,
|
|
1415
1603
|
onClose: e,
|
|
1416
|
-
onNavigate:
|
|
1604
|
+
onNavigate: i,
|
|
1417
1605
|
onSwitchContext: r
|
|
1418
1606
|
}
|
|
1419
1607
|
);
|
|
1420
1608
|
}
|
|
1421
|
-
function
|
|
1422
|
-
const
|
|
1423
|
-
return
|
|
1609
|
+
function Ft(n) {
|
|
1610
|
+
const s = () => (lt(n), null);
|
|
1611
|
+
return s.displayName = `Capability(${n.name})`, s;
|
|
1424
1612
|
}
|
|
1425
|
-
class
|
|
1613
|
+
class kt {
|
|
1426
1614
|
getAllowedEvents() {
|
|
1427
1615
|
return null;
|
|
1428
1616
|
}
|
|
1429
|
-
shouldProcessEvent(
|
|
1617
|
+
shouldProcessEvent(s) {
|
|
1430
1618
|
const t = this.getAllowedEvents();
|
|
1431
|
-
return t ? t.includes(
|
|
1619
|
+
return t ? t.includes(s) : !0;
|
|
1432
1620
|
}
|
|
1433
|
-
async *stream(
|
|
1434
|
-
const { signal: t } =
|
|
1621
|
+
async *stream(s) {
|
|
1622
|
+
const { signal: t } = s, { url: e, options: i } = this.prepareRequest(s), r = await fetch(e, { ...i, signal: t });
|
|
1435
1623
|
if (!r.ok)
|
|
1436
1624
|
throw new Error(`HTTP error! status: ${r.status}`);
|
|
1437
1625
|
if (!r.body)
|
|
1438
1626
|
throw new Error("Response body is null");
|
|
1439
1627
|
yield* this.parseSSEStream(r.body, t);
|
|
1440
1628
|
}
|
|
1441
|
-
async *parseSSEStream(
|
|
1442
|
-
const e =
|
|
1443
|
-
let r = "",
|
|
1629
|
+
async *parseSSEStream(s, t) {
|
|
1630
|
+
const e = s.getReader(), i = new TextDecoder();
|
|
1631
|
+
let r = "", a = null;
|
|
1444
1632
|
try {
|
|
1445
1633
|
for (; ; ) {
|
|
1446
1634
|
const { done: o, value: c } = await e.read();
|
|
1447
1635
|
if (o || t != null && t.aborted) break;
|
|
1448
|
-
r +=
|
|
1449
|
-
const
|
|
1636
|
+
r += i.decode(c, { stream: !0 });
|
|
1637
|
+
const h = r.split(`
|
|
1450
1638
|
`);
|
|
1451
|
-
r =
|
|
1452
|
-
for (const l of
|
|
1453
|
-
const
|
|
1454
|
-
if (!
|
|
1455
|
-
|
|
1639
|
+
r = h.pop() || "";
|
|
1640
|
+
for (const l of h) {
|
|
1641
|
+
const d = l.trim();
|
|
1642
|
+
if (!d) {
|
|
1643
|
+
a = null;
|
|
1456
1644
|
continue;
|
|
1457
1645
|
}
|
|
1458
|
-
if (
|
|
1459
|
-
if (
|
|
1460
|
-
|
|
1646
|
+
if (d !== ": ping") {
|
|
1647
|
+
if (d.startsWith("event:")) {
|
|
1648
|
+
a = d.substring(6).trim();
|
|
1461
1649
|
continue;
|
|
1462
1650
|
}
|
|
1463
|
-
if (
|
|
1464
|
-
const
|
|
1465
|
-
if (
|
|
1651
|
+
if (d.startsWith("data:")) {
|
|
1652
|
+
const p = d.substring(5).trim();
|
|
1653
|
+
if (p === "eof" || d === "eof")
|
|
1466
1654
|
break;
|
|
1467
1655
|
try {
|
|
1468
|
-
const
|
|
1469
|
-
if (
|
|
1470
|
-
const
|
|
1471
|
-
event:
|
|
1472
|
-
data:
|
|
1656
|
+
const g = JSON.parse(p);
|
|
1657
|
+
if (a && this.shouldProcessEvent(a)) {
|
|
1658
|
+
const S = this.convertEvent({
|
|
1659
|
+
event: a,
|
|
1660
|
+
data: g
|
|
1473
1661
|
});
|
|
1474
|
-
|
|
1662
|
+
S && (yield S);
|
|
1475
1663
|
}
|
|
1476
1664
|
} catch {
|
|
1477
1665
|
}
|
|
1478
|
-
|
|
1666
|
+
a = null;
|
|
1479
1667
|
}
|
|
1480
1668
|
}
|
|
1481
1669
|
}
|
|
@@ -1486,34 +1674,38 @@ class Mt {
|
|
|
1486
1674
|
}
|
|
1487
1675
|
}
|
|
1488
1676
|
export {
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1677
|
+
yt as AssistantRuntime,
|
|
1678
|
+
_t as AssistantRuntimeProvider,
|
|
1679
|
+
Pt as AuxiliaryRenderer,
|
|
1680
|
+
kt as BaseSSEStreamAdapter,
|
|
1493
1681
|
K as CapabilityExecutionManager,
|
|
1494
1682
|
Y as CapabilityRegistry,
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1683
|
+
ft as CapabilityRendererComp,
|
|
1684
|
+
vt as ChatContextProvider,
|
|
1685
|
+
st as ComposerRuntime,
|
|
1686
|
+
At as ContentRenderer,
|
|
1499
1687
|
G as PluginRegistry,
|
|
1500
|
-
|
|
1501
|
-
|
|
1688
|
+
X as QuickActionRegistry,
|
|
1689
|
+
T as ThreadListItemRuntime,
|
|
1690
|
+
it as ThreadListRuntime,
|
|
1502
1691
|
R as ThreadRuntime,
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1692
|
+
M as ThreadRuntimeCore,
|
|
1693
|
+
v as generateMessageId,
|
|
1694
|
+
Ft as makeCapability,
|
|
1506
1695
|
f as useAssistantRuntime,
|
|
1507
|
-
|
|
1508
|
-
|
|
1696
|
+
lt as useCapability,
|
|
1697
|
+
pt as useCapabilityExecution,
|
|
1509
1698
|
gt as useChatContext,
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1699
|
+
Ct as useComposer,
|
|
1700
|
+
It as useContentFocus,
|
|
1701
|
+
Q as useContentRenderer,
|
|
1702
|
+
ct as useCurrentThread,
|
|
1703
|
+
wt as useMessages,
|
|
1515
1704
|
Tt as usePageContext,
|
|
1516
|
-
|
|
1705
|
+
Mt as useQuickAction,
|
|
1706
|
+
Rt as useQuickActionScope,
|
|
1707
|
+
Et as useQuickActions,
|
|
1708
|
+
St as useThreadList,
|
|
1517
1709
|
xt as useThreadListState
|
|
1518
1710
|
};
|
|
1519
1711
|
//# sourceMappingURL=index.js.map
|