@harnessio/ai-chat-core 0.0.15 → 0.0.17

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