@harnessio/ai-chat-core 0.0.2 → 0.0.4

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