@harnessio/ai-chat-core 0.0.1 → 0.0.2

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
1
  var $ = Object.defineProperty;
2
- var q = (n, i, t) => i in n ? $(n, i, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[i] = t;
3
- var d = (n, i, t) => q(n, typeof i != "symbol" ? i + "" : i, t);
4
- import j, { createContext as U, useContext as J, useState as D, useEffect as k } from "react";
5
- class W {
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 {
6
6
  constructor() {
7
7
  d(this, "plugins", /* @__PURE__ */ new Map());
8
8
  d(this, "renderersByType", /* @__PURE__ */ new Map());
9
9
  }
10
- registerPlugin(i) {
11
- this.plugins.has(i.id), this.plugins.set(i.id, i), i.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
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);
14
14
  });
15
15
  }
16
- unregisterPlugin(i) {
17
- const t = this.plugins.get(i);
16
+ unregisterPlugin(n) {
17
+ const t = this.plugins.get(n);
18
18
  return t ? (t.renderers.forEach((e) => {
19
- const s = (this.renderersByType.get(e.type) || []).filter((a) => !t.renderers.includes(a));
19
+ const s = (this.renderersByType.get(e.type) || []).filter((i) => !t.renderers.includes(i));
20
20
  s.length === 0 ? this.renderersByType.delete(e.type) : this.renderersByType.set(e.type, s);
21
- }), this.plugins.delete(i)) : !1;
21
+ }), this.plugins.delete(n)) : !1;
22
22
  }
23
- getPlugin(i) {
24
- return this.plugins.get(i);
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(i) {
30
- return this.renderersByType.get(i) || [];
29
+ getRenderersByType(n) {
30
+ return this.renderersByType.get(n) || [];
31
31
  }
32
- getBestRendererForType(i) {
33
- return this.getRenderersByType(i)[0];
32
+ getBestRendererForType(n) {
33
+ return this.getRenderersByType(n)[0];
34
34
  }
35
35
  clear() {
36
36
  this.plugins.clear(), this.renderersByType.clear();
@@ -40,20 +40,20 @@ class m {
40
40
  constructor() {
41
41
  d(this, "_subscriptions", /* @__PURE__ */ new Set());
42
42
  }
43
- subscribe(i) {
44
- return this._subscriptions.add(i), () => {
45
- this._subscriptions.delete(i);
43
+ subscribe(n) {
44
+ return this._subscriptions.add(n), () => {
45
+ this._subscriptions.delete(n);
46
46
  };
47
47
  }
48
48
  notifySubscribers() {
49
- for (const i of this._subscriptions)
50
- i();
49
+ for (const n of this._subscriptions)
50
+ n();
51
51
  }
52
52
  getSubscriberCount() {
53
53
  return this._subscriptions.size;
54
54
  }
55
55
  }
56
- class z extends m {
56
+ class V extends m {
57
57
  constructor() {
58
58
  super(...arguments);
59
59
  d(this, "_state", {
@@ -117,49 +117,46 @@ class z extends m {
117
117
  }
118
118
  focusNext(t) {
119
119
  if (!this._state.focusedMessageId || !t.length) return;
120
- const e = t.findIndex((a) => a.id === this._state.focusedMessageId);
120
+ const e = t.findIndex((i) => i.id === this._state.focusedMessageId);
121
121
  if (e === -1) return;
122
122
  const r = t[e], s = this._state.focusedContentIndex ?? 0;
123
123
  if (s + 1 < r.content.length) {
124
- const a = r.content[s + 1];
125
- this.focus(a, r, s + 1, this._state.context || "detail");
124
+ const i = r.content[s + 1];
125
+ this.focus(i, r, s + 1, this._state.context || "detail");
126
126
  return;
127
127
  }
128
128
  if (e + 1 < t.length) {
129
- const a = t[e + 1];
130
- a.content.length > 0 && this.focus(a.content[0], a, 0, this._state.context || "detail");
129
+ const i = t[e + 1];
130
+ i.content.length > 0 && this.focus(i.content[0], i, 0, this._state.context || "detail");
131
131
  }
132
132
  }
133
133
  focusPrevious(t) {
134
134
  if (!this._state.focusedMessageId || !t.length) return;
135
- const e = t.findIndex((a) => a.id === this._state.focusedMessageId);
135
+ const e = t.findIndex((i) => i.id === this._state.focusedMessageId);
136
136
  if (e === -1) return;
137
137
  const r = t[e], s = this._state.focusedContentIndex ?? 0;
138
138
  if (s > 0) {
139
- const a = r.content[s - 1];
140
- this.focus(a, r, s - 1, this._state.context || "detail");
139
+ const i = r.content[s - 1];
140
+ this.focus(i, r, s - 1, this._state.context || "detail");
141
141
  return;
142
142
  }
143
143
  if (e > 0) {
144
- const a = t[e - 1];
145
- if (a.content.length > 0) {
146
- const o = a.content.length - 1;
147
- this.focus(a.content[o], a, o, this._state.context || "detail");
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");
148
148
  }
149
149
  }
150
150
  }
151
151
  }
152
- let G = 0, V = 0;
152
+ let G = 0, H = 0;
153
153
  function E() {
154
154
  return `msg-${Date.now()}-${++G}`;
155
155
  }
156
- function M() {
157
- return `thread-${Date.now()}-${++V}`;
156
+ function P() {
157
+ return `thread-${Date.now()}-${++H}`;
158
158
  }
159
- function ct(n = "id") {
160
- return `${n}-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
161
- }
162
- class w extends m {
159
+ class T extends m {
163
160
  constructor(t) {
164
161
  super();
165
162
  d(this, "_state");
@@ -187,7 +184,7 @@ class w extends m {
187
184
  return super.subscribe(t);
188
185
  }
189
186
  }
190
- class H extends m {
187
+ class Y extends m {
191
188
  constructor() {
192
189
  super(...arguments);
193
190
  d(this, "_text", "");
@@ -215,11 +212,11 @@ class H extends m {
215
212
  this._isSubmitting = t, this.notifySubscribers();
216
213
  }
217
214
  }
218
- class T extends m {
215
+ class x extends m {
219
216
  constructor(t) {
220
217
  super();
221
218
  d(this, "composer");
222
- this._core = t, this.composer = new H(), this._core.subscribe(() => {
219
+ this._core = t, this.composer = new Y(), this._core.subscribe(() => {
223
220
  this.notifySubscribers();
224
221
  });
225
222
  }
@@ -274,7 +271,7 @@ class T extends m {
274
271
  return super.subscribe(t);
275
272
  }
276
273
  }
277
- class x extends m {
274
+ class R extends m {
278
275
  constructor(t) {
279
276
  super();
280
277
  d(this, "_messages", []);
@@ -304,8 +301,11 @@ class x extends m {
304
301
  feedback: !1
305
302
  };
306
303
  }
304
+ updateMessages(t) {
305
+ var e, r;
306
+ this._messages = t, (r = (e = this.config).onMessagesChange) == null || r.call(e, this._messages), this.notifySubscribers();
307
+ }
307
308
  append(t) {
308
- var r, s;
309
309
  const e = {
310
310
  id: t.id || E(),
311
311
  parentId: t.parentId,
@@ -315,13 +315,12 @@ class x extends m {
315
315
  timestamp: t.timestamp || Date.now(),
316
316
  metadata: t.metadata
317
317
  };
318
- this._messages.push(e), (s = (r = this.config).onMessagesChange) == null || s.call(r, this._messages), this.notifySubscribers();
318
+ this.updateMessages([...this._messages, e]);
319
319
  }
320
320
  async startRun(t) {
321
- var s, a;
322
321
  if (this._isRunning)
323
322
  throw new Error("A run is already in progress");
324
- this.append(t), this._isRunning = !0, this._abortController = new AbortController(), this._currentPart = null, this.notifySubscribers();
323
+ this.append(t), this._isRunning = !0, this._abortController = new AbortController(), this._currentPart = null;
325
324
  const e = E(), r = {
326
325
  id: e,
327
326
  role: "assistant",
@@ -329,26 +328,26 @@ class x extends m {
329
328
  status: { type: "running" },
330
329
  timestamp: Date.now()
331
330
  };
332
- this._messages.push(r), (a = (s = this.config).onMessagesChange) == null || a.call(s, this._messages), this.notifySubscribers();
331
+ this.updateMessages([...this._messages, r]);
333
332
  try {
334
- const o = this.config.streamAdapter.stream({
333
+ const s = this.config.streamAdapter.stream({
335
334
  messages: this._messages,
336
335
  signal: this._abortController.signal
337
336
  });
338
- for await (const u of o) {
337
+ for await (const i of s) {
339
338
  if (this._abortController.signal.aborted)
340
339
  break;
341
- this.handleStreamEvent(e, u.event);
340
+ this.handleStreamEvent(e, i.event);
342
341
  }
343
342
  this.updateMessageStatus(e, { type: "complete" });
344
- } catch (o) {
345
- if (o instanceof Error && o.name === "AbortError")
343
+ } catch (s) {
344
+ if (s instanceof Error && s.name === "AbortError")
346
345
  this.updateMessageStatus(e, { type: "cancelled" });
347
346
  else {
348
- const u = o instanceof Error ? o.message : "Unknown error";
347
+ const i = s instanceof Error ? s.message : "Unknown error";
349
348
  this.updateMessageStatus(e, {
350
349
  type: "error",
351
- error: u
350
+ error: i
352
351
  });
353
352
  }
354
353
  } finally {
@@ -356,8 +355,7 @@ class x extends m {
356
355
  }
357
356
  }
358
357
  handleStreamEvent(t, e) {
359
- var a, o;
360
- const r = this._messages.findIndex((u) => u.id === t);
358
+ const r = this._messages.findIndex((o) => o.id === t);
361
359
  if (r === -1) return;
362
360
  const s = this._messages[r];
363
361
  if (e.type === "part-start")
@@ -367,31 +365,38 @@ class x extends m {
367
365
  else if (e.type === "part-finish")
368
366
  this.handlePartFinish();
369
367
  else if (e.type === "metadata") {
370
- const u = e;
368
+ const o = e;
371
369
  s.metadata = {
372
370
  ...s.metadata,
373
- conversationId: u.conversationId,
374
- interactionId: u.interactionId
371
+ conversationId: o.conversationId,
372
+ interactionId: o.interactionId
375
373
  };
376
374
  } else if (e.type === "error") {
377
- const u = e;
378
- s.content.push({
379
- type: "error",
380
- data: u.error
381
- });
375
+ const o = e;
376
+ s.content = [
377
+ ...s.content,
378
+ {
379
+ type: "error",
380
+ data: o.error
381
+ }
382
+ ];
382
383
  } else {
383
- const u = e;
384
- s.content.push({
385
- type: u.type,
386
- data: u.data,
387
- parentId: u.parentId
388
- });
384
+ const o = e;
385
+ s.content = [
386
+ ...s.content,
387
+ {
388
+ type: o.type,
389
+ data: o.data,
390
+ parentId: o.parentId
391
+ }
392
+ ];
389
393
  }
390
- this._messages = [
394
+ const i = [
391
395
  ...this._messages.slice(0, r),
392
396
  { ...s, timestamp: Date.now() },
393
397
  ...this._messages.slice(r + 1)
394
- ], (o = (a = this.config).onMessagesChange) == null || o.call(a, this._messages), this.notifySubscribers();
398
+ ];
399
+ this.updateMessages(i);
395
400
  }
396
401
  handlePartStart(t, e) {
397
402
  const r = t.content.length;
@@ -417,7 +422,7 @@ class x extends m {
417
422
  parentId: e.part.parentId
418
423
  };
419
424
  }
420
- t.content.push(s), this._currentPart = {
425
+ t.content = [...t.content, s], this._currentPart = {
421
426
  messageId: t.id,
422
427
  contentIndex: r,
423
428
  type: e.part.type,
@@ -440,23 +445,26 @@ class x extends m {
440
445
  this._currentPart = null;
441
446
  }
442
447
  updateMessageStatus(t, e) {
443
- var s, a;
444
- const r = this._messages.findIndex((o) => o.id === t);
445
- r !== -1 && (this._messages[r] = {
446
- ...this._messages[r],
447
- status: e
448
- }, (a = (s = this.config).onMessagesChange) == null || a.call(s, this._messages), this.notifySubscribers());
448
+ const r = this._messages.findIndex((i) => i.id === t);
449
+ if (r === -1) return;
450
+ const s = [
451
+ ...this._messages.slice(0, r),
452
+ {
453
+ ...this._messages[r],
454
+ status: e
455
+ },
456
+ ...this._messages.slice(r + 1)
457
+ ];
458
+ this.updateMessages(s);
449
459
  }
450
460
  clear() {
451
- var t, e;
452
- this._messages = [], (e = (t = this.config).onMessagesChange) == null || e.call(t, this._messages), this.notifySubscribers();
461
+ this.updateMessages([]);
453
462
  }
454
463
  cancelRun() {
455
464
  !this._isRunning || !this._abortController || this._abortController.abort();
456
465
  }
457
466
  reset(t = []) {
458
- var e, r;
459
- this._messages = [...t], (r = (e = this.config).onMessagesChange) == null || r.call(e, this._messages), this.notifySubscribers();
467
+ this.updateMessages([...t]);
460
468
  }
461
469
  }
462
470
  class K extends m {
@@ -468,11 +476,11 @@ class K extends m {
468
476
  d(this, "_threadStates", /* @__PURE__ */ new Map());
469
477
  d(this, "_isLoading", !1);
470
478
  d(this, "main");
471
- this.config = t, this._mainThreadId = M();
472
- const e = new x({
479
+ this.config = t, this._mainThreadId = P();
480
+ const e = new R({
473
481
  streamAdapter: t.streamAdapter
474
482
  });
475
- this.main = new T(e), this._threads.set(this._mainThreadId, this.main);
483
+ this.main = new x(e), this._threads.set(this._mainThreadId, this.main);
476
484
  const r = {
477
485
  id: this._mainThreadId,
478
486
  title: "New Chat",
@@ -482,7 +490,7 @@ class K extends m {
482
490
  updatedAt: Date.now()
483
491
  };
484
492
  this._threadStates.set(this._mainThreadId, r);
485
- const s = new w({
493
+ const s = new T({
486
494
  state: r,
487
495
  onSwitchTo: this.switchToThread.bind(this),
488
496
  onRename: this.renameThread.bind(this),
@@ -512,12 +520,12 @@ class K extends m {
512
520
  };
513
521
  }
514
522
  async switchToThread(t) {
515
- var a, o;
523
+ var i, o;
516
524
  const e = this._threads.get(t);
517
525
  if (!e)
518
526
  throw new Error(`Thread ${t} not found`);
519
527
  const r = this._threadStates.get(this._mainThreadId);
520
- r && (r.isMain = !1, this._threadStates.set(this._mainThreadId, r), (a = this._threadItems.get(this._mainThreadId)) == null || a.updateState(r)), this._mainThreadId = t;
528
+ r && (r.isMain = !1, this._threadStates.set(this._mainThreadId, r), (i = this._threadItems.get(this._mainThreadId)) == null || i.updateState(r)), this._mainThreadId = t;
521
529
  const s = this._threadStates.get(t);
522
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)) {
523
531
  this._isLoading = !0, this.notifySubscribers();
@@ -533,9 +541,9 @@ class K extends m {
533
541
  this.notifySubscribers();
534
542
  }
535
543
  async switchToNewThread() {
536
- const t = M(), e = new x({
544
+ const t = P(), e = new R({
537
545
  streamAdapter: this.config.streamAdapter
538
- }), r = new T(e);
546
+ }), r = new x(e);
539
547
  this._threads.set(t, r);
540
548
  const s = {
541
549
  id: t,
@@ -546,18 +554,18 @@ class K extends m {
546
554
  updatedAt: Date.now()
547
555
  };
548
556
  this._threadStates.set(t, s);
549
- const a = new w({
557
+ const i = new T({
550
558
  state: s,
551
559
  onSwitchTo: this.switchToThread.bind(this),
552
560
  onRename: this.renameThread.bind(this),
553
561
  onDelete: this.deleteThread.bind(this)
554
562
  });
555
- if (this._threadItems.set(t, a), r.subscribe(() => {
563
+ if (this._threadItems.set(t, i), r.subscribe(() => {
556
564
  this.notifySubscribers();
557
565
  }), this.config.threadListAdapter)
558
566
  try {
559
567
  const o = await this.config.threadListAdapter.createThread();
560
- s.conversationId = o.conversationId, this._threadStates.set(t, s), a.updateState(s);
568
+ s.conversationId = o.conversationId, this._threadStates.set(t, s), i.updateState(s);
561
569
  } catch (o) {
562
570
  console.error("Failed to create thread:", o);
563
571
  }
@@ -574,17 +582,17 @@ class K extends m {
574
582
  for (const e of t) {
575
583
  if (this._threadStates.has(e.id))
576
584
  continue;
577
- const r = new x({
585
+ const r = new R({
578
586
  streamAdapter: this.config.streamAdapter
579
- }), s = new T(r);
587
+ }), s = new x(r);
580
588
  this._threads.set(e.id, s), this._threadStates.set(e.id, e);
581
- const a = new w({
589
+ const i = new T({
582
590
  state: e,
583
591
  onSwitchTo: this.switchToThread.bind(this),
584
592
  onRename: this.renameThread.bind(this),
585
593
  onDelete: this.deleteThread.bind(this)
586
594
  });
587
- this._threadItems.set(e.id, a), s.subscribe(() => {
595
+ this._threadItems.set(e.id, i), s.subscribe(() => {
588
596
  this.notifySubscribers();
589
597
  });
590
598
  }
@@ -601,8 +609,8 @@ class K extends m {
601
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)
602
610
  try {
603
611
  await this.config.threadListAdapter.updateThread(t, { title: e });
604
- } catch (a) {
605
- console.error("Failed to rename thread:", a);
612
+ } catch (i) {
613
+ console.error("Failed to rename thread:", i);
606
614
  }
607
615
  this.notifySubscribers();
608
616
  }
@@ -623,19 +631,19 @@ class K extends m {
623
631
  this.notifySubscribers();
624
632
  }
625
633
  }
626
- class ht extends m {
634
+ class ot extends m {
627
635
  constructor(t) {
628
636
  super();
629
637
  d(this, "threads");
630
638
  d(this, "pluginRegistry");
631
639
  d(this, "_contentFocusRuntime");
632
640
  d(this, "_currentThreadUnsubscribe");
633
- this.pluginRegistry = new W(), t.plugins && t.plugins.forEach((e) => {
641
+ this.pluginRegistry = new z(), t.plugins && t.plugins.forEach((e) => {
634
642
  this.pluginRegistry.registerPlugin(e);
635
643
  }), this.threads = new K({
636
644
  streamAdapter: t.streamAdapter,
637
645
  threadListAdapter: t.threadListAdapter
638
- }), this._contentFocusRuntime = new z(), this._contentFocusRuntime.subscribe(() => {
646
+ }), this._contentFocusRuntime = new V(), this._contentFocusRuntime.subscribe(() => {
639
647
  this.notifySubscribers();
640
648
  }), this.threads.subscribe(() => {
641
649
  this.subscribeToCurrentThread(), this.notifySubscribers();
@@ -684,10 +692,10 @@ class ht extends m {
684
692
  for (let r = t.length - 1; r >= 0; r--) {
685
693
  const s = t[r];
686
694
  if (s.role === "assistant")
687
- for (let a = s.content.length - 1; a >= 0; a--) {
688
- const o = s.content[a], u = this.pluginRegistry.getRenderersByType(o.type);
695
+ for (let i = s.content.length - 1; i >= 0; i--) {
696
+ const o = s.content[i], u = this.pluginRegistry.getRenderersByType(o.type);
689
697
  if (u.length > 0 && ((e = u[0].capabilities) != null && e.supportsFocus)) {
690
- this._contentFocusRuntime.focus(o, s, a, "detail");
698
+ this._contentFocusRuntime.focus(o, s, i, "detail");
691
699
  return;
692
700
  }
693
701
  }
@@ -700,11 +708,11 @@ object-assign
700
708
  (c) Sindre Sorhus
701
709
  @license MIT
702
710
  */
703
- var R, A;
704
- function Y() {
705
- if (A) return R;
706
- A = 1;
707
- var n = Object.getOwnPropertySymbols, i = Object.prototype.hasOwnProperty, t = Object.prototype.propertyIsEnumerable;
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;
708
716
  function e(s) {
709
717
  if (s == null)
710
718
  throw new TypeError("Object.assign cannot be called with null or undefined");
@@ -717,10 +725,10 @@ function Y() {
717
725
  var s = new String("abc");
718
726
  if (s[5] = "de", Object.getOwnPropertyNames(s)[0] === "5")
719
727
  return !1;
720
- for (var a = {}, o = 0; o < 10; o++)
721
- a["_" + String.fromCharCode(o)] = o;
722
- var u = Object.getOwnPropertyNames(a).map(function(l) {
723
- return a[l];
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];
724
732
  });
725
733
  if (u.join("") !== "0123456789")
726
734
  return !1;
@@ -732,19 +740,19 @@ function Y() {
732
740
  return !1;
733
741
  }
734
742
  }
735
- return R = r() ? Object.assign : function(s, a) {
743
+ return v = r() ? Object.assign : function(s, i) {
736
744
  for (var o, u = e(s), f, l = 1; l < arguments.length; l++) {
737
745
  o = Object(arguments[l]);
738
746
  for (var c in o)
739
- i.call(o, c) && (u[c] = o[c]);
740
- if (n) {
741
- f = n(o);
747
+ n.call(o, c) && (u[c] = o[c]);
748
+ if (a) {
749
+ f = a(o);
742
750
  for (var h = 0; h < f.length; h++)
743
751
  t.call(o, f[h]) && (u[f[h]] = o[f[h]]);
744
752
  }
745
753
  }
746
754
  return u;
747
- }, R;
755
+ }, v;
748
756
  }
749
757
  /** @license React v17.0.2
750
758
  * react-jsx-runtime.production.min.js
@@ -754,72 +762,72 @@ function Y() {
754
762
  * This source code is licensed under the MIT license found in the
755
763
  * LICENSE file in the root directory of this source tree.
756
764
  */
757
- var P;
758
- function Q() {
759
- if (P) return _;
760
- P = 1, Y();
761
- var n = j, i = 60103;
765
+ var L;
766
+ function X() {
767
+ if (L) return _;
768
+ L = 1, Q();
769
+ var a = k, n = 60103;
762
770
  if (_.Fragment = 60107, typeof Symbol == "function" && Symbol.for) {
763
771
  var t = Symbol.for;
764
- i = t("react.element"), _.Fragment = t("react.fragment");
772
+ n = t("react.element"), _.Fragment = t("react.fragment");
765
773
  }
766
- var e = n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, r = Object.prototype.hasOwnProperty, s = { key: !0, ref: !0, __self: !0, __source: !0 };
767
- function a(o, u, f) {
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) {
768
776
  var l, c = {}, h = null, p = null;
769
777
  f !== void 0 && (h = "" + f), u.key !== void 0 && (h = "" + u.key), u.ref !== void 0 && (p = u.ref);
770
778
  for (l in u) r.call(u, l) && !s.hasOwnProperty(l) && (c[l] = u[l]);
771
779
  if (o && o.defaultProps) for (l in u = o.defaultProps, u) c[l] === void 0 && (c[l] = u[l]);
772
- return { $$typeof: i, type: o, key: h, ref: p, props: c, _owner: e.current };
780
+ return { $$typeof: n, type: o, key: h, ref: p, props: c, _owner: e.current };
773
781
  }
774
- return _.jsx = a, _.jsxs = a, _;
782
+ return _.jsx = i, _.jsxs = i, _;
775
783
  }
776
- var F;
777
- function X() {
778
- return F || (F = 1, I.exports = Q()), I.exports;
784
+ var j;
785
+ function Z() {
786
+ return j || (j = 1, I.exports = X()), I.exports;
779
787
  }
780
- var Z = X();
781
- const B = U(null);
782
- function dt({ runtime: n, children: i }) {
783
- return /* @__PURE__ */ Z.jsx(B.Provider, { value: n, children: i });
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 });
784
792
  }
785
793
  function tt() {
786
- const n = J(B);
787
- if (!n)
794
+ const a = W(N);
795
+ if (!a)
788
796
  throw new Error("useAssistantRuntimeContext must be used within AssistantRuntimeProvider");
789
- return n;
797
+ return a;
790
798
  }
791
799
  function y() {
792
800
  return tt();
793
801
  }
794
- function lt() {
795
- const n = y();
802
+ function ct() {
803
+ const a = y();
796
804
  return {
797
- switchToThread: (i) => n.threads.switchToThread(i),
798
- switchToNewThread: () => n.threads.switchToNewThread(),
805
+ switchToThread: (n) => a.threads.switchToThread(n),
806
+ switchToNewThread: () => a.threads.switchToNewThread(),
799
807
  loadThreads: () => {
800
- var i, t;
801
- return (t = (i = n.threads).loadThreads) == null ? void 0 : t.call(i);
808
+ var n, t;
809
+ return (t = (n = a.threads).loadThreads) == null ? void 0 : t.call(n);
802
810
  },
803
- renameThread: (i, t) => {
811
+ renameThread: (n, t) => {
804
812
  var e, r;
805
- return (r = (e = n.threads).renameThread) == null ? void 0 : r.call(e, i, t);
813
+ return (r = (e = a.threads).renameThread) == null ? void 0 : r.call(e, n, t);
806
814
  },
807
- deleteThread: (i) => {
815
+ deleteThread: (n) => {
808
816
  var t, e;
809
- return (e = (t = n.threads).deleteThread) == null ? void 0 : e.call(t, i);
817
+ return (e = (t = a.threads).deleteThread) == null ? void 0 : e.call(t, n);
810
818
  }
811
819
  };
812
820
  }
813
- function ft() {
814
- const n = y(), [i, t] = D(n.threads.getState());
815
- return k(() => n.threads.subscribe(() => {
816
- t(n.threads.getState());
817
- }), [n]), i;
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;
818
826
  }
819
827
  function et() {
820
828
  return y().threads.getMainThread();
821
829
  }
822
- var C = { exports: {} }, v = {};
830
+ var C = { exports: {} }, A = {};
823
831
  /**
824
832
  * @license React
825
833
  * use-sync-external-store-shim.production.js
@@ -829,30 +837,30 @@ var C = { exports: {} }, v = {};
829
837
  * This source code is licensed under the MIT license found in the
830
838
  * LICENSE file in the root directory of this source tree.
831
839
  */
832
- var L;
840
+ var O;
833
841
  function st() {
834
- if (L) return v;
835
- L = 1;
836
- var n = j;
837
- function i(c, h) {
842
+ if (O) return A;
843
+ O = 1;
844
+ var a = k;
845
+ function n(c, h) {
838
846
  return c === h && (c !== 0 || 1 / c === 1 / h) || c !== c && h !== h;
839
847
  }
840
- var t = typeof Object.is == "function" ? Object.is : i, e = n.useState, r = n.useEffect, s = n.useLayoutEffect, a = n.useDebugValue;
848
+ var t = typeof Object.is == "function" ? Object.is : n, e = a.useState, r = a.useEffect, s = a.useLayoutEffect, i = a.useDebugValue;
841
849
  function o(c, h) {
842
- var p = h(), b = e({ inst: { value: p, getSnapshot: h } }), g = b[0].inst, S = b[1];
850
+ var p = h(), b = e({ inst: { value: p, getSnapshot: h } }), g = b[0].inst, w = b[1];
843
851
  return s(
844
852
  function() {
845
- g.value = p, g.getSnapshot = h, u(g) && S({ inst: g });
853
+ g.value = p, g.getSnapshot = h, u(g) && w({ inst: g });
846
854
  },
847
855
  [c, p, h]
848
856
  ), r(
849
857
  function() {
850
- return u(g) && S({ inst: g }), c(function() {
851
- u(g) && S({ inst: g });
858
+ return u(g) && w({ inst: g }), c(function() {
859
+ u(g) && w({ inst: g });
852
860
  });
853
861
  },
854
862
  [c]
855
- ), a(p), p;
863
+ ), i(p), p;
856
864
  }
857
865
  function u(c) {
858
866
  var h = c.getSnapshot;
@@ -868,37 +876,48 @@ function st() {
868
876
  return h();
869
877
  }
870
878
  var l = typeof window > "u" || typeof window.document > "u" || typeof window.document.createElement > "u" ? f : o;
871
- return v.useSyncExternalStore = n.useSyncExternalStore !== void 0 ? n.useSyncExternalStore : l, v;
879
+ return A.useSyncExternalStore = a.useSyncExternalStore !== void 0 ? a.useSyncExternalStore : l, A;
872
880
  }
873
- var O;
881
+ var D;
874
882
  function rt() {
875
- return O || (O = 1, C.exports = st()), C.exports;
883
+ return D || (D = 1, C.exports = st()), C.exports;
876
884
  }
877
- var N = rt();
878
- function pt() {
879
- const n = y();
880
- return N.useSyncExternalStore(
881
- (i) => n.subscribe(() => {
882
- i();
885
+ var nt = rt();
886
+ function dt() {
887
+ const a = y();
888
+ return nt.useSyncExternalStore(
889
+ (n) => a.subscribe(() => {
890
+ n();
883
891
  }),
884
- () => n.thread.messages,
885
- () => n.thread.messages
892
+ () => a.thread.messages,
893
+ () => a.thread.messages
886
894
  );
887
895
  }
888
- function nt() {
889
- return et().composer;
890
- }
891
- function gt() {
892
- const n = nt();
893
- return N.useSyncExternalStore(
894
- (i) => n.subscribe(i),
895
- () => n.getState(),
896
- () => n.getState()
897
- );
896
+ function lt() {
897
+ const a = et(), [n, t] = S(""), [e, r] = S(!1);
898
+ return {
899
+ text: n,
900
+ setText: t,
901
+ isSubmitting: e,
902
+ send: async (i) => {
903
+ if (i == null || i.preventDefault(), !n.trim() || e) return;
904
+ const o = n;
905
+ t(""), r(!0);
906
+ try {
907
+ await a.send(o);
908
+ } catch (u) {
909
+ console.error("Failed to send message:", u), t(o);
910
+ } finally {
911
+ r(!1);
912
+ }
913
+ },
914
+ clear: () => t(""),
915
+ append: (i) => t((o) => o + i)
916
+ };
898
917
  }
899
- function mt(n, i) {
900
- var s, a, o, u;
901
- const e = y().pluginRegistry.getBestRendererForType(n);
918
+ function q(a, n) {
919
+ var s, i, o, u;
920
+ const e = y().pluginRegistry.getBestRendererForType(a);
902
921
  if (!e)
903
922
  return {
904
923
  component: null,
@@ -907,78 +926,79 @@ function mt(n, i) {
907
926
  supportsPreview: !1,
908
927
  supportsFullscreen: !1
909
928
  };
910
- const r = i ? (s = e.auxiliary) == null ? void 0 : s[i] : null;
929
+ const r = n ? (s = e.auxiliary) == null ? void 0 : s[n] : null;
911
930
  return {
912
931
  component: e.component,
913
932
  auxiliaryComponent: r,
914
- supportsFocus: ((a = e.capabilities) == null ? void 0 : a.supportsFocus) ?? !1,
933
+ supportsFocus: ((i = e.capabilities) == null ? void 0 : i.supportsFocus) ?? !1,
915
934
  supportsPreview: ((o = e.capabilities) == null ? void 0 : o.supportsPreview) ?? !1,
916
935
  supportsFullscreen: ((u = e.capabilities) == null ? void 0 : u.supportsFullscreen) ?? !1
917
936
  };
918
937
  }
919
- function bt() {
920
- const n = y(), [i, t] = D(n.contentFocus.state);
921
- return k(() => n.contentFocus.subscribe(() => {
922
- t(n.contentFocus.state);
923
- }), [n]), {
924
- ...i,
925
- focus: (e, r, s, a) => n.contentFocus.focus(e, r, s, a),
926
- blur: () => n.contentFocus.blur(),
927
- toggle: (e, r, s, a) => n.contentFocus.toggle(e, r, s, a),
928
- switchContext: (e) => n.contentFocus.switchContext(e),
929
- focusNext: () => n.contentFocus.focusNext(n.thread.messages),
930
- focusPrevious: () => n.contentFocus.focusPrevious(n.thread.messages)
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)
931
950
  };
932
951
  }
933
- function _t(n) {
934
- const i = /* @__PURE__ */ new Map();
935
- for (let e = 0; e < n.length; e++) {
936
- const a = n[e].parentId ?? `__ungrouped_${e}`, o = i.get(a) ?? [];
937
- o.push(e), i.set(a, o);
938
- }
939
- const t = [];
940
- for (const [e, r] of i) {
941
- const s = e.startsWith("__ungrouped_") ? void 0 : e, a = r.map((f) => n[f]), o = it(a), u = at(a);
942
- t.push({ groupKey: s, indices: r, items: a, groupType: o, primaryType: u });
943
- }
944
- return t;
945
- }
946
- function it(n) {
947
- if (n.length === 1) return "single-type";
948
- if (new Set(n.map((t) => t.type)).size === 1) {
949
- const t = n[0].type;
950
- return t === "tool_call" ? "tool-calls" : t === "assistant_thought" ? "reasoning" : "single-type";
951
- }
952
- return "mixed";
952
+ function pt({ message: a, content: n }) {
953
+ const { component: t } = q(n.type);
954
+ if (!t)
955
+ return null;
956
+ const e = t;
957
+ return /* @__PURE__ */ M.jsx(e, { content: n, message: a });
953
958
  }
954
- function at(n) {
955
- const i = /* @__PURE__ */ new Map();
956
- for (const r of n)
957
- i.set(r.type, (i.get(r.type) || 0) + 1);
958
- let t = 0, e = n[0].type;
959
- for (const [r, s] of i)
960
- s > t && (t = s, e = r);
961
- return e;
959
+ function gt({
960
+ message: a,
961
+ content: n,
962
+ context: t,
963
+ onClose: e,
964
+ onNavigate: r,
965
+ onSwitchContext: s
966
+ }) {
967
+ const { auxiliaryComponent: i } = q(n.type, t);
968
+ if (!i)
969
+ return null;
970
+ const o = i;
971
+ return /* @__PURE__ */ M.jsx(
972
+ o,
973
+ {
974
+ content: n,
975
+ message: a,
976
+ context: t,
977
+ onClose: e,
978
+ onNavigate: r,
979
+ onSwitchContext: s
980
+ }
981
+ );
962
982
  }
963
- class yt {
983
+ class mt {
964
984
  getAllowedEvents() {
965
985
  return null;
966
986
  }
967
- shouldProcessEvent(i) {
987
+ shouldProcessEvent(n) {
968
988
  const t = this.getAllowedEvents();
969
- return t ? t.includes(i) : !0;
989
+ return t ? t.includes(n) : !0;
970
990
  }
971
- async *stream(i) {
972
- const { signal: t } = i, { url: e, options: r } = this.prepareRequest(i), s = await fetch(e, { ...r, signal: t });
991
+ async *stream(n) {
992
+ const { signal: t } = n, { url: e, options: r } = this.prepareRequest(n), s = await fetch(e, { ...r, signal: t });
973
993
  if (!s.ok)
974
994
  throw new Error(`HTTP error! status: ${s.status}`);
975
995
  if (!s.body)
976
996
  throw new Error("Response body is null");
977
997
  yield* this.parseSSEStream(s.body, t);
978
998
  }
979
- async *parseSSEStream(i, t) {
980
- const e = i.getReader(), r = new TextDecoder();
981
- let s = "", a = null;
999
+ async *parseSSEStream(n, t) {
1000
+ const e = n.getReader(), r = new TextDecoder();
1001
+ let s = "", i = null;
982
1002
  try {
983
1003
  for (; ; ) {
984
1004
  const { done: o, value: u } = await e.read();
@@ -990,12 +1010,12 @@ class yt {
990
1010
  for (const l of f) {
991
1011
  const c = l.trim();
992
1012
  if (!c) {
993
- a = null;
1013
+ i = null;
994
1014
  continue;
995
1015
  }
996
1016
  if (c !== ": ping") {
997
1017
  if (c.startsWith("event:")) {
998
- a = c.substring(6).trim();
1018
+ i = c.substring(6).trim();
999
1019
  continue;
1000
1020
  }
1001
1021
  if (c.startsWith("data:")) {
@@ -1004,16 +1024,16 @@ class yt {
1004
1024
  break;
1005
1025
  try {
1006
1026
  const p = JSON.parse(h);
1007
- if (a && this.shouldProcessEvent(a)) {
1027
+ if (i && this.shouldProcessEvent(i)) {
1008
1028
  const b = this.convertEvent({
1009
- event: a,
1029
+ event: i,
1010
1030
  data: p
1011
1031
  });
1012
1032
  b && (yield b);
1013
1033
  }
1014
1034
  } catch {
1015
1035
  }
1016
- a = null;
1036
+ i = null;
1017
1037
  }
1018
1038
  }
1019
1039
  }
@@ -1024,28 +1044,24 @@ class yt {
1024
1044
  }
1025
1045
  }
1026
1046
  export {
1027
- ht as AssistantRuntime,
1028
- dt as AssistantRuntimeProvider,
1029
- yt as BaseSSEStreamAdapter,
1030
- m as BaseSubscribable,
1031
- H as ComposerRuntime,
1032
- W as PluginRegistry,
1033
- w as ThreadListItemRuntime,
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,
1034
1055
  K as ThreadListRuntime,
1035
- T as ThreadRuntime,
1036
- x as ThreadRuntimeCore,
1037
- ct as generateId,
1038
- E as generateMessageId,
1039
- M as generateThreadId,
1040
- _t as groupContentByParentId,
1056
+ x as ThreadRuntime,
1057
+ R as ThreadRuntimeCore,
1041
1058
  y as useAssistantRuntime,
1042
- nt as useComposer,
1043
- gt as useComposerState,
1044
- bt as useContentFocus,
1045
- mt as useContentRenderer,
1059
+ lt as useComposer,
1060
+ ft as useContentFocus,
1061
+ q as useContentRenderer,
1046
1062
  et as useCurrentThread,
1047
- pt as useMessages,
1048
- lt as useThreadList,
1049
- ft as useThreadListState
1063
+ dt as useMessages,
1064
+ ct as useThreadList,
1065
+ ht as useThreadListState
1050
1066
  };
1051
1067
  //# sourceMappingURL=index.js.map