@harnessio/ai-chat-core 0.0.2 → 0.0.3

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