@assistant-ui/react 0.5.77 → 0.5.79

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4; var _class5; var _class6; var _class7; var _class8; var _class9; var _class10; var _class11; var _class12; var _class13; var _class14; var _class15; var _class16; var _class17; var _class18;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4; var _class5; var _class6; var _class7; var _class8; var _class9; var _class10; var _class11; var _class12; var _class13; var _class14; var _class15; var _class16; var _class17;
2
2
 
3
3
 
4
4
 
@@ -411,15 +411,11 @@ function useComposerRuntime(options) {
411
411
 
412
412
  var useAppendMessage = () => {
413
413
  const threadRuntime = useThreadRuntime();
414
- const threadViewportStore = useThreadViewportStore();
415
- const threadComposerStore = useThreadComposerStore();
416
414
  const append = _react.useCallback.call(void 0,
417
415
  (message) => {
418
416
  threadRuntime.append(message);
419
- threadViewportStore.getState().scrollToBottom();
420
- threadComposerStore.getState().focus();
421
417
  },
422
- [threadRuntime, threadViewportStore, threadComposerStore]
418
+ [threadRuntime]
423
419
  );
424
420
  return append;
425
421
  };
@@ -428,11 +424,9 @@ var useAppendMessage = () => {
428
424
 
429
425
  var useSwitchToNewThread = () => {
430
426
  const assistantRuntime = useAssistantRuntime();
431
- const threadComposerStore = useThreadComposerStore();
432
427
  const switchToNewThread = _react.useCallback.call(void 0, () => {
433
428
  assistantRuntime.switchToNewThread();
434
- threadComposerStore.getState().focus();
435
- }, [assistantRuntime, threadComposerStore]);
429
+ }, [assistantRuntime]);
436
430
  return switchToNewThread;
437
431
  };
438
432
 
@@ -545,25 +539,25 @@ var getThreadMessageText = (message) => {
545
539
  var useActionBarCopy = ({
546
540
  copiedDuration = 3e3
547
541
  } = {}) => {
548
- const messageStore = useMessageStore();
542
+ const messageRuntime = useMessageRuntime();
543
+ const composerRuntime = useComposerRuntime();
549
544
  const messageUtilsStore = useMessageUtilsStore();
550
- const editComposerStore = useEditComposerStore();
551
545
  const hasCopyableContent = useCombinedStore(
552
- [messageStore, editComposerStore],
546
+ [messageRuntime, composerRuntime],
553
547
  (message, c) => {
554
548
  return !c.isEditing && (message.role !== "assistant" || message.status.type !== "running") && message.content.some((c2) => c2.type === "text" && c2.text.length > 0);
555
549
  }
556
550
  );
557
551
  const callback = _react.useCallback.call(void 0, () => {
558
- const message = messageStore.getState();
552
+ const message = messageRuntime.getState();
559
553
  const { setIsCopied } = messageUtilsStore.getState();
560
- const { isEditing, text: composerValue } = editComposerStore.getState();
554
+ const { isEditing, text: composerValue } = composerRuntime.getState();
561
555
  const valueToCopy = isEditing ? composerValue : getThreadMessageText(message);
562
556
  navigator.clipboard.writeText(valueToCopy).then(() => {
563
557
  setIsCopied(true);
564
558
  setTimeout(() => setIsCopied(false), copiedDuration);
565
559
  });
566
- }, [messageStore, messageUtilsStore, editComposerStore, copiedDuration]);
560
+ }, [messageRuntime, messageUtilsStore, composerRuntime, copiedDuration]);
567
561
  if (!hasCopyableContent) return null;
568
562
  return callback;
569
563
  };
@@ -583,20 +577,15 @@ var useActionBarEdit = () => {
583
577
  // src/primitive-hooks/actionBar/useActionBarReload.tsx
584
578
 
585
579
  var useActionBarReload = () => {
586
- const messageStore = useMessageStore();
587
- const threadStore = useThreadStore();
588
580
  const messageRuntime = useMessageRuntime();
589
- const threadComposerStore = useThreadComposerStore();
590
- const threadViewportStore = useThreadViewportStore();
581
+ const threadRuntime = useThreadRuntime();
591
582
  const disabled = useCombinedStore(
592
- [threadStore, messageStore],
583
+ [threadRuntime, messageRuntime],
593
584
  (t, m) => t.isRunning || t.isDisabled || m.role !== "assistant"
594
585
  );
595
586
  const callback = _react.useCallback.call(void 0, () => {
596
587
  messageRuntime.reload();
597
- threadViewportStore.getState().scrollToBottom();
598
- threadComposerStore.getState().focus();
599
- }, [messageRuntime, threadComposerStore, threadViewportStore]);
588
+ }, [messageRuntime]);
600
589
  if (disabled) return null;
601
590
  return callback;
602
591
  };
@@ -686,12 +675,11 @@ var useBranchPickerPrevious = () => {
686
675
  // src/primitive-hooks/composer/useComposerCancel.tsx
687
676
 
688
677
  var useComposerCancel = () => {
689
- const composerStore = useComposerStore();
678
+ const composerRuntime = useComposerRuntime();
690
679
  const disabled = useComposer((c) => !c.canCancel);
691
680
  const callback = _react.useCallback.call(void 0, () => {
692
- const { cancel } = composerStore.getState();
693
- cancel();
694
- }, [composerStore]);
681
+ composerRuntime.cancel();
682
+ }, [composerRuntime]);
695
683
  if (disabled) return null;
696
684
  return callback;
697
685
  };
@@ -708,21 +696,16 @@ var useComposerIf = (props) => {
708
696
  // src/primitive-hooks/composer/useComposerSend.tsx
709
697
 
710
698
  var useComposerSend = () => {
711
- const threadStore = useThreadStore();
712
- const threadViewportStore = useThreadViewportStore();
713
- const composerStore = useComposerStore();
714
- const threadComposerStore = useThreadComposerStore();
699
+ const composerRuntime = useComposerRuntime();
700
+ const threadRuntime = useThreadRuntime();
715
701
  const disabled = useCombinedStore(
716
- [threadStore, composerStore],
702
+ [threadRuntime, composerRuntime],
717
703
  (t, c) => t.isRunning || !c.isEditing || c.isEmpty
718
704
  );
719
705
  const callback = _react.useCallback.call(void 0, () => {
720
- const composerState = composerStore.getState();
721
- if (!composerState.isEditing) return;
722
- composerState.send();
723
- threadViewportStore.getState().scrollToBottom();
724
- threadComposerStore.getState().focus();
725
- }, [threadComposerStore, composerStore, threadViewportStore]);
706
+ if (!composerRuntime.getState().isEditing) return;
707
+ composerRuntime.send();
708
+ }, [threadRuntime]);
726
709
  if (disabled) return null;
727
710
  return callback;
728
711
  };
@@ -788,10 +771,10 @@ var useContentPartText = () => {
788
771
 
789
772
  // src/primitive-hooks/message/useMessageIf.tsx
790
773
  var useMessageIf = (props) => {
791
- const messageStore = useMessageStore();
774
+ const messageRuntime = useMessageRuntime();
792
775
  const messageUtilsStore = useMessageUtilsStore();
793
776
  return useCombinedStore(
794
- [messageStore, messageUtilsStore],
777
+ [messageRuntime, messageUtilsStore],
795
778
  ({
796
779
  role,
797
780
  attachments,
@@ -846,11 +829,9 @@ var useThreadEmpty = () => {
846
829
  var useThreadScrollToBottom = () => {
847
830
  const isAtBottom = useThreadViewport((s) => s.isAtBottom);
848
831
  const threadViewportStore = useThreadViewportStore();
849
- const threadComposerStore = useThreadComposerStore();
850
832
  const handleScrollToBottom = _react.useCallback.call(void 0, () => {
851
833
  threadViewportStore.getState().scrollToBottom();
852
- threadComposerStore.getState().focus();
853
- }, [threadViewportStore, threadComposerStore]);
834
+ }, [threadViewportStore]);
854
835
  if (isAtBottom) return null;
855
836
  return handleScrollToBottom;
856
837
  };
@@ -861,20 +842,16 @@ var useThreadSuggestion = ({
861
842
  prompt,
862
843
  autoSend
863
844
  }) => {
864
- const threadStore = useThreadStore();
865
- const composerStore = useThreadComposerStore();
866
- const append = useAppendMessage();
845
+ const threadRuntime = useThreadRuntime();
867
846
  const disabled = useThread((t) => t.isDisabled);
868
847
  const callback = _react.useCallback.call(void 0, () => {
869
- const thread = threadStore.getState();
870
- const composer = composerStore.getState();
871
- if (autoSend && !thread.isRunning) {
872
- append(prompt);
873
- composer.setText("");
848
+ if (autoSend && !threadRuntime.getState().isRunning) {
849
+ threadRuntime.append(prompt);
850
+ threadRuntime.composer.setText("");
874
851
  } else {
875
- composer.setText(prompt);
852
+ threadRuntime.composer.setText(prompt);
876
853
  }
877
- }, [threadStore, composerStore, autoSend, append, prompt]);
854
+ }, [threadRuntime, autoSend, prompt]);
878
855
  if (disabled) return null;
879
856
  return callback;
880
857
  };
@@ -902,11 +879,11 @@ var useActionBarFloatStatus = ({
902
879
  autohide,
903
880
  autohideFloat
904
881
  }) => {
905
- const threadStore = useThreadStore();
906
- const messageStore = useMessageStore();
882
+ const threadRuntime = useThreadRuntime();
883
+ const messageRuntime = useMessageRuntime();
907
884
  const messageUtilsStore = useMessageUtilsStore();
908
885
  return useCombinedStore(
909
- [threadStore, messageStore, messageUtilsStore],
886
+ [threadRuntime, messageRuntime, messageUtilsStore],
910
887
  (t, m, mu) => {
911
888
  if (hideWhenRunning && t.isRunning) return "hidden" /* Hidden */;
912
889
  const autohideEnabled = autohide === "always" || autohide === "not-last" && !m.isLast;
@@ -1110,42 +1087,40 @@ _chunkPZ5AY32Cjs.__export.call(void 0, assistantModal_exports, {
1110
1087
  var _reactpopover = require('@radix-ui/react-popover'); var PopoverPrimitive2 = _interopRequireWildcard(_reactpopover); var PopoverPrimitive = _interopRequireWildcard(_reactpopover); var PopoverPrimitive3 = _interopRequireWildcard(_reactpopover); var PopoverPrimitive4 = _interopRequireWildcard(_reactpopover); var PopoverPrimitive5 = _interopRequireWildcard(_reactpopover);
1111
1088
 
1112
1089
 
1113
- // src/utils/hooks/useOnComposerFocus.tsx
1114
- var _reactusecallbackref = require('@radix-ui/react-use-callback-ref');
1115
-
1116
- var useOnComposerFocus = (callback) => {
1117
- const callbackRef = _reactusecallbackref.useCallbackRef.call(void 0, callback);
1118
- const threadComposerStore = useThreadComposerStore();
1119
- _react.useEffect.call(void 0, () => {
1120
- return threadComposerStore.getState().onFocus(() => {
1121
- callbackRef();
1122
- });
1123
- }, [threadComposerStore, callbackRef]);
1124
- };
1125
-
1126
1090
  // src/primitives/assistantModal/scope.tsx
1127
1091
 
1128
1092
  var usePopoverScope = PopoverPrimitive.createPopoverScope();
1129
1093
 
1130
1094
  // src/primitives/assistantModal/AssistantModalRoot.tsx
1131
1095
 
1132
- var useAssistantModalOpenState = (defaultOpen = false) => {
1096
+ var useAssistantModalOpenState = ({
1097
+ defaultOpen = false,
1098
+ unstable_openOnRunStart = true
1099
+ }) => {
1133
1100
  const state = _react.useState.call(void 0, defaultOpen);
1134
1101
  const [, setOpen] = state;
1135
- useOnComposerFocus(() => {
1136
- setOpen(true);
1137
- });
1102
+ const threadRuntime = useThreadRuntime();
1103
+ _react.useEffect.call(void 0, () => {
1104
+ if (!unstable_openOnRunStart) return void 0;
1105
+ return threadRuntime.unstable_on("run-start", () => {
1106
+ setOpen(true);
1107
+ });
1108
+ }, [unstable_openOnRunStart]);
1138
1109
  return state;
1139
1110
  };
1140
1111
  var AssistantModalPrimitiveRoot = ({
1141
1112
  __scopeAssistantModal,
1142
1113
  defaultOpen,
1114
+ unstable_openOnRunStart,
1143
1115
  open,
1144
1116
  onOpenChange,
1145
1117
  ...rest
1146
1118
  }) => {
1147
1119
  const scope = usePopoverScope(__scopeAssistantModal);
1148
- const [modalOpen, setOpen] = useAssistantModalOpenState(defaultOpen);
1120
+ const [modalOpen, setOpen] = useAssistantModalOpenState({
1121
+ defaultOpen,
1122
+ unstable_openOnRunStart
1123
+ });
1149
1124
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
1150
1125
  PopoverPrimitive2.Root,
1151
1126
  {
@@ -1496,7 +1471,7 @@ var ContentPartRuntimeProvider = ({
1496
1471
 
1497
1472
  // src/utils/smooth/useSmooth.tsx
1498
1473
 
1499
-
1474
+ var _reactusecallbackref = require('@radix-ui/react-use-callback-ref');
1500
1475
 
1501
1476
  // src/utils/smooth/SmoothContext.tsx
1502
1477
 
@@ -1836,7 +1811,7 @@ var METHOD_NOT_SUPPORTED = () => {
1836
1811
  throw new Error("Composer is not available");
1837
1812
  };
1838
1813
  var EMPTY_ARRAY = Object.freeze([]);
1839
- var getThreadComposerState = (runtime, focus, onFocus) => {
1814
+ var getThreadComposerState = (runtime) => {
1840
1815
  return Object.freeze({
1841
1816
  type: "thread",
1842
1817
  isEditing: _nullishCoalesce(_optionalChain([runtime, 'optionalAccess', _24 => _24.isEditing]), () => ( false)),
@@ -1850,8 +1825,6 @@ var getThreadComposerState = (runtime, focus, onFocus) => {
1850
1825
  // edit: beginEdit,
1851
1826
  send: _nullishCoalesce(_optionalChain([runtime, 'optionalAccess', _36 => _36.send, 'access', _37 => _37.bind, 'call', _38 => _38(runtime)]), () => ( METHOD_NOT_SUPPORTED)),
1852
1827
  cancel: _nullishCoalesce(_optionalChain([runtime, 'optionalAccess', _39 => _39.cancel, 'access', _40 => _40.bind, 'call', _41 => _41(runtime)]), () => ( METHOD_NOT_SUPPORTED)),
1853
- focus,
1854
- onFocus,
1855
1828
  reset: _nullishCoalesce(_optionalChain([runtime, 'optionalAccess', _42 => _42.reset, 'access', _43 => _43.bind, 'call', _44 => _44(runtime)]), () => ( METHOD_NOT_SUPPORTED)),
1856
1829
  addAttachment: _nullishCoalesce(_optionalChain([runtime, 'optionalAccess', _45 => _45.addAttachment, 'access', _46 => _46.bind, 'call', _47 => _47(runtime)]), () => ( METHOD_NOT_SUPPORTED)),
1857
1830
  removeAttachment: _nullishCoalesce(_optionalChain([runtime, 'optionalAccess', _48 => _48.removeAttachment, 'access', _49 => _49.bind, 'call', _50 => _50(runtime)]), () => ( METHOD_NOT_SUPPORTED))
@@ -1961,24 +1934,20 @@ var ComposerRuntimeImpl = class {
1961
1934
  return core.getAttachmentAccept();
1962
1935
  }
1963
1936
  };
1964
- var ThreadComposerRuntimeImpl = (_class5 = class extends ComposerRuntimeImpl {
1937
+ var ThreadComposerRuntimeImpl = class extends ComposerRuntimeImpl {
1965
1938
  get type() {
1966
1939
  return "thread";
1967
1940
  }
1968
1941
 
1969
1942
  constructor(core) {
1970
1943
  const stateBinding = new LazyMemoizeSubject({
1971
- getState: () => getThreadComposerState(
1972
- core.getState(),
1973
- this.focus.bind(this),
1974
- this.onFocus.bind(this)
1975
- ),
1944
+ getState: () => getThreadComposerState(core.getState()),
1976
1945
  subscribe: (callback) => core.subscribe(callback)
1977
1946
  });
1978
1947
  super({
1979
1948
  getState: () => core.getState(),
1980
1949
  subscribe: (callback) => stateBinding.subscribe(callback)
1981
- });_class5.prototype.__init9.call(this);;
1950
+ });
1982
1951
  this._getState = stateBinding.getState.bind(stateBinding);
1983
1952
  }
1984
1953
  get attachments() {
@@ -1987,21 +1956,6 @@ var ThreadComposerRuntimeImpl = (_class5 = class extends ComposerRuntimeImpl {
1987
1956
  getState() {
1988
1957
  return this._getState();
1989
1958
  }
1990
- // TODO replace with events
1991
- __init9() {this._focusListeners = /* @__PURE__ */ new Set()}
1992
- /**
1993
- * @deprecated This feature is being removed in 0.6.0. Submit feedback if you need it.
1994
- */
1995
- focus() {
1996
- this._focusListeners.forEach((callback) => callback());
1997
- }
1998
- /**
1999
- * @deprecated This feature is being removed in 0.6.0. Submit feedback if you need it.
2000
- */
2001
- onFocus(callback) {
2002
- this._focusListeners.add(callback);
2003
- return () => this._focusListeners.delete(callback);
2004
- }
2005
1959
  getAttachmentByIndex(idx) {
2006
1960
  return new ThreadComposerAttachmentRuntimeImpl(
2007
1961
  new ShallowMemoizeSubject({
@@ -2020,7 +1974,7 @@ var ThreadComposerRuntimeImpl = (_class5 = class extends ComposerRuntimeImpl {
2020
1974
  this._core
2021
1975
  );
2022
1976
  }
2023
- }, _class5);
1977
+ };
2024
1978
  var EditComposerRuntimeImpl = class extends ComposerRuntimeImpl {
2025
1979
  constructor(core, _beginEdit) {
2026
1980
  const stateBinding = new LazyMemoizeSubject({
@@ -2079,6 +2033,9 @@ var NestedSubscriptionSubject = class extends BaseSubject {
2079
2033
  getState() {
2080
2034
  return this.binding.getState();
2081
2035
  }
2036
+ outerSubscribe(callback) {
2037
+ return this.binding.subscribe(callback);
2038
+ }
2082
2039
  _connect() {
2083
2040
  const callback = () => {
2084
2041
  this.notifySubscribers();
@@ -2093,7 +2050,7 @@ var NestedSubscriptionSubject = class extends BaseSubject {
2093
2050
  innerUnsubscribe = _optionalChain([this, 'access', _75 => _75.binding, 'access', _76 => _76.getState, 'call', _77 => _77(), 'optionalAccess', _78 => _78.subscribe, 'call', _79 => _79(callback)]);
2094
2051
  callback();
2095
2052
  };
2096
- const outerUnsubscribe = this.binding.subscribe(onRuntimeUpdate);
2053
+ const outerUnsubscribe = this.outerSubscribe(onRuntimeUpdate);
2097
2054
  return () => {
2098
2055
  _optionalChain([outerUnsubscribe, 'optionalCall', _80 => _80()]);
2099
2056
  _optionalChain([innerUnsubscribe, 'optionalCall', _81 => _81()]);
@@ -2135,12 +2092,12 @@ var getContentPartState = (message, partIndex) => {
2135
2092
  const status = toContentPartStatus(message, partIndex, part);
2136
2093
  return Object.freeze({ ...part, part, status });
2137
2094
  };
2138
- var MessageRuntimeImpl = (_class6 = class {
2139
- constructor(_core, _threadBinding) {;_class6.prototype.__init10.call(this);
2095
+ var MessageRuntimeImpl = (_class5 = class {
2096
+ constructor(_core, _threadBinding) {;_class5.prototype.__init9.call(this);
2140
2097
  this._core = _core;
2141
2098
  this._threadBinding = _threadBinding;
2142
2099
  }
2143
- __init10() {this.composer = new EditComposerRuntimeImpl(
2100
+ __init9() {this.composer = new EditComposerRuntimeImpl(
2144
2101
  new NestedSubscriptionSubject({
2145
2102
  getState: () => this._threadBinding.getState().getEditComposer(this._core.getState().id),
2146
2103
  subscribe: (callback) => this._threadBinding.subscribe(callback)
@@ -2235,7 +2192,7 @@ var MessageRuntimeImpl = (_class6 = class {
2235
2192
  })
2236
2193
  );
2237
2194
  }
2238
- }, _class6);
2195
+ }, _class5);
2239
2196
 
2240
2197
  // src/primitives/message/MessageContent.tsx
2241
2198
 
@@ -2264,8 +2221,7 @@ var MessageContentPartComponent = ({
2264
2221
  tools: { by_name = {}, Fallback: Fallback2 = void 0 } = {}
2265
2222
  } = {}
2266
2223
  }) => {
2267
- const messageStore = useMessageStore();
2268
- const threadRuntime = useThreadRuntime();
2224
+ const contentPartRuntime = useContentPartRuntime();
2269
2225
  const part = useContentPart();
2270
2226
  const type = part.type;
2271
2227
  switch (type) {
@@ -2286,12 +2242,7 @@ var MessageContentPartComponent = ({
2286
2242
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, UI, { ...part, part });
2287
2243
  case "tool-call": {
2288
2244
  const Tool = by_name[part.toolName] || Fallback2;
2289
- const addResult = (result) => threadRuntime.addToolResult({
2290
- messageId: messageStore.getState().id,
2291
- toolName: part.toolName,
2292
- toolCallId: part.toolCallId,
2293
- result
2294
- });
2245
+ const addResult = (result) => contentPartRuntime.addToolResult(result);
2295
2246
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ToolUIDisplay, { ...part, part, UI: Tool, addResult });
2296
2247
  }
2297
2248
  default:
@@ -2480,6 +2431,19 @@ var _reactslot = require('@radix-ui/react-slot');
2480
2431
  var _reacttextareaautosize = require('react-textarea-autosize'); var _reacttextareaautosize2 = _interopRequireDefault(_reacttextareaautosize);
2481
2432
 
2482
2433
 
2434
+ // src/utils/hooks/useOnScrollToBottom.tsx
2435
+
2436
+
2437
+ var useOnScrollToBottom = (callback) => {
2438
+ const callbackRef = _reactusecallbackref.useCallbackRef.call(void 0, callback);
2439
+ const onScrollToBottom = useThreadViewport((vp) => vp.onScrollToBottom);
2440
+ _react.useEffect.call(void 0, () => {
2441
+ return onScrollToBottom(callbackRef);
2442
+ }, [onScrollToBottom, callbackRef]);
2443
+ };
2444
+
2445
+ // src/primitives/composer/ComposerInput.tsx
2446
+
2483
2447
  var ComposerPrimitiveInput = _react.forwardRef.call(void 0,
2484
2448
  ({
2485
2449
  autoFocus = false,
@@ -2489,10 +2453,13 @@ var ComposerPrimitiveInput = _react.forwardRef.call(void 0,
2489
2453
  onKeyDown,
2490
2454
  submitOnEnter = true,
2491
2455
  cancelOnEscape = true,
2456
+ unstable_focusOnRunStart = true,
2457
+ unstable_focusOnScrollToBottom = true,
2458
+ unstable_focusOnThreadSwitched = true,
2492
2459
  ...rest
2493
2460
  }, forwardedRef) => {
2494
- const threadStore = useThreadStore();
2495
- const composerStore = useComposerStore();
2461
+ const threadRuntime = useThreadRuntime();
2462
+ const composerRuntime = useComposerRuntime();
2496
2463
  const value = useComposer((c) => {
2497
2464
  if (!c.isEditing) return "";
2498
2465
  return c.text;
@@ -2503,9 +2470,8 @@ var ComposerPrimitiveInput = _react.forwardRef.call(void 0,
2503
2470
  const ref = _reactcomposerefs.useComposedRefs.call(void 0, forwardedRef, textareaRef);
2504
2471
  _reactuseescapekeydown.useEscapeKeydown.call(void 0, (e) => {
2505
2472
  if (!cancelOnEscape) return;
2506
- const composer = composerStore.getState();
2507
- if (composer.canCancel) {
2508
- composer.cancel();
2473
+ if (composerRuntime.getState().canCancel) {
2474
+ composerRuntime.cancel();
2509
2475
  e.preventDefault();
2510
2476
  }
2511
2477
  });
@@ -2513,7 +2479,7 @@ var ComposerPrimitiveInput = _react.forwardRef.call(void 0,
2513
2479
  if (isDisabled || !submitOnEnter) return;
2514
2480
  if (e.nativeEvent.isComposing) return;
2515
2481
  if (e.key === "Enter" && e.shiftKey === false) {
2516
- const { isRunning } = threadStore.getState();
2482
+ const { isRunning } = threadRuntime.getState();
2517
2483
  if (!isRunning) {
2518
2484
  e.preventDefault();
2519
2485
  _optionalChain([textareaRef, 'access', _123 => _123.current, 'optionalAccess', _124 => _124.closest, 'call', _125 => _125("form"), 'optionalAccess', _126 => _126.requestSubmit, 'call', _127 => _127()]);
@@ -2521,7 +2487,7 @@ var ComposerPrimitiveInput = _react.forwardRef.call(void 0,
2521
2487
  }
2522
2488
  };
2523
2489
  const autoFocusEnabled = autoFocus && !isDisabled;
2524
- const focus = _react.useCallback.call(void 0, () => {
2490
+ const focus2 = _react.useCallback.call(void 0, () => {
2525
2491
  const textarea = textareaRef.current;
2526
2492
  if (!textarea || !autoFocusEnabled) return;
2527
2493
  textarea.focus({ preventScroll: true });
@@ -2530,12 +2496,22 @@ var ComposerPrimitiveInput = _react.forwardRef.call(void 0,
2530
2496
  textareaRef.current.value.length
2531
2497
  );
2532
2498
  }, [autoFocusEnabled]);
2533
- _react.useEffect.call(void 0, () => focus(), [focus]);
2534
- useOnComposerFocus(() => {
2535
- if (composerStore.getState().type === "thread") {
2536
- focus();
2499
+ _react.useEffect.call(void 0, () => focus2(), [focus2]);
2500
+ useOnScrollToBottom(() => {
2501
+ if (composerRuntime.type === "thread" && unstable_focusOnScrollToBottom) {
2502
+ focus2();
2537
2503
  }
2538
2504
  });
2505
+ _react.useEffect.call(void 0, () => {
2506
+ if (composerRuntime.type !== "thread" || !unstable_focusOnRunStart)
2507
+ return void 0;
2508
+ return threadRuntime.unstable_on("run-start", focus2);
2509
+ }, [unstable_focusOnRunStart]);
2510
+ _react.useEffect.call(void 0, () => {
2511
+ if (composerRuntime.type !== "thread" || !unstable_focusOnThreadSwitched)
2512
+ return void 0;
2513
+ return threadRuntime.unstable_on("switched-to", focus2);
2514
+ }, [unstable_focusOnThreadSwitched]);
2539
2515
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
2540
2516
  Component,
2541
2517
  {
@@ -2545,9 +2521,8 @@ var ComposerPrimitiveInput = _react.forwardRef.call(void 0,
2545
2521
  ref,
2546
2522
  disabled: isDisabled,
2547
2523
  onChange: _primitive.composeEventHandlers.call(void 0, onChange, (e) => {
2548
- const composerState = composerStore.getState();
2549
- if (!composerState.isEditing) return;
2550
- return composerState.setText(e.target.value);
2524
+ if (!composerRuntime.getState().isEditing) return;
2525
+ return composerRuntime.setText(e.target.value);
2551
2526
  }),
2552
2527
  onKeyDown: _primitive.composeEventHandlers.call(void 0, onKeyDown, handleKeyPress)
2553
2528
  }
@@ -2731,22 +2706,10 @@ var useOnResizeContent = (callback) => {
2731
2706
  return useManagedRef(refCallback);
2732
2707
  };
2733
2708
 
2734
- // src/utils/hooks/useOnScrollToBottom.tsx
2735
-
2736
-
2737
- var useOnScrollToBottom = (callback) => {
2738
- const callbackRef = _reactusecallbackref.useCallbackRef.call(void 0, callback);
2739
- const threadViewportStore = useThreadViewportStore();
2740
- _react.useEffect.call(void 0, () => {
2741
- return threadViewportStore.getState().onScrollToBottom(() => {
2742
- callbackRef();
2743
- });
2744
- }, [threadViewportStore, callbackRef]);
2745
- };
2746
-
2747
2709
  // src/primitive-hooks/thread/useThreadViewportAutoScroll.tsx
2748
2710
  var useThreadViewportAutoScroll = ({
2749
- autoScroll = true
2711
+ autoScroll = true,
2712
+ unstable_scrollToBottomOnRunStart = true
2750
2713
  }) => {
2751
2714
  const divRef = _react.useRef.call(void 0, null);
2752
2715
  const threadViewportStore = useThreadViewportStore();
@@ -2792,6 +2755,11 @@ var useThreadViewportAutoScroll = ({
2792
2755
  useOnScrollToBottom(() => {
2793
2756
  scrollToBottom("auto");
2794
2757
  });
2758
+ const threadRuntime = useThreadRuntime();
2759
+ _react.useEffect.call(void 0, () => {
2760
+ if (!unstable_scrollToBottomOnRunStart) return void 0;
2761
+ return threadRuntime.unstable_on("run-start", focus);
2762
+ }, [unstable_scrollToBottomOnRunStart]);
2795
2763
  return autoScrollRef;
2796
2764
  };
2797
2765
 
@@ -2978,8 +2946,8 @@ var subscribeToMainThread = (runtime, callback) => {
2978
2946
 
2979
2947
 
2980
2948
  // src/runtimes/core/BaseAssistantRuntimeCore.tsx
2981
- var BaseAssistantRuntimeCore = (_class7 = class {
2982
- constructor(_thread) {;_class7.prototype.__init11.call(this);_class7.prototype.__init12.call(this);
2949
+ var BaseAssistantRuntimeCore = (_class6 = class {
2950
+ constructor(_thread) {;_class6.prototype.__init10.call(this);_class6.prototype.__init11.call(this);
2983
2951
  this._thread = _thread;
2984
2952
  this._thread = _thread;
2985
2953
  }
@@ -2990,15 +2958,15 @@ var BaseAssistantRuntimeCore = (_class7 = class {
2990
2958
  this._thread = thread;
2991
2959
  this.subscriptionHandler();
2992
2960
  }
2993
- __init11() {this._subscriptions = /* @__PURE__ */ new Set()}
2961
+ __init10() {this._subscriptions = /* @__PURE__ */ new Set()}
2994
2962
  subscribe(callback) {
2995
2963
  this._subscriptions.add(callback);
2996
2964
  return () => this._subscriptions.delete(callback);
2997
2965
  }
2998
- __init12() {this.subscriptionHandler = () => {
2966
+ __init11() {this.subscriptionHandler = () => {
2999
2967
  for (const callback of this._subscriptions) callback();
3000
2968
  }}
3001
- }, _class7);
2969
+ }, _class6);
3002
2970
 
3003
2971
  // src/internal.ts
3004
2972
  var internal_exports = {};
@@ -3018,12 +2986,12 @@ _chunkPZ5AY32Cjs.__export.call(void 0, internal_exports, {
3018
2986
 
3019
2987
  // src/runtimes/composer/BaseComposerRuntimeCore.tsx
3020
2988
  var isAttachmentComplete = (a) => a.status.type === "complete";
3021
- var BaseComposerRuntimeCore = (_class8 = class {constructor() { _class8.prototype.__init13.call(this);_class8.prototype.__init14.call(this);_class8.prototype.__init15.call(this);_class8.prototype.__init16.call(this); }
3022
- __init13() {this.isEditing = true}
2989
+ var BaseComposerRuntimeCore = (_class7 = class {constructor() { _class7.prototype.__init12.call(this);_class7.prototype.__init13.call(this);_class7.prototype.__init14.call(this);_class7.prototype.__init15.call(this); }
2990
+ __init12() {this.isEditing = true}
3023
2991
  getAttachmentAccept() {
3024
2992
  return _nullishCoalesce(_optionalChain([this, 'access', _152 => _152.getAttachmentAdapter, 'call', _153 => _153(), 'optionalAccess', _154 => _154.accept]), () => ( "*"));
3025
2993
  }
3026
- __init14() {this._attachments = []}
2994
+ __init13() {this._attachments = []}
3027
2995
  set attachments(value) {
3028
2996
  this._attachments = value;
3029
2997
  this.notifySubscribers();
@@ -3034,7 +3002,7 @@ var BaseComposerRuntimeCore = (_class8 = class {constructor() { _class8.prototyp
3034
3002
  get isEmpty() {
3035
3003
  return !this.text.trim() && !this.attachments.length;
3036
3004
  }
3037
- __init15() {this._text = ""}
3005
+ __init14() {this._text = ""}
3038
3006
  get text() {
3039
3007
  return this._text;
3040
3008
  }
@@ -3087,7 +3055,7 @@ var BaseComposerRuntimeCore = (_class8 = class {constructor() { _class8.prototyp
3087
3055
  this._attachments = this._attachments.toSpliced(index, 1);
3088
3056
  this.notifySubscribers();
3089
3057
  }
3090
- __init16() {this._subscriptions = /* @__PURE__ */ new Set()}
3058
+ __init15() {this._subscriptions = /* @__PURE__ */ new Set()}
3091
3059
  notifySubscribers() {
3092
3060
  for (const callback of this._subscriptions) callback();
3093
3061
  }
@@ -3095,16 +3063,16 @@ var BaseComposerRuntimeCore = (_class8 = class {constructor() { _class8.prototyp
3095
3063
  this._subscriptions.add(callback);
3096
3064
  return () => this._subscriptions.delete(callback);
3097
3065
  }
3098
- }, _class8);
3066
+ }, _class7);
3099
3067
 
3100
3068
  // src/runtimes/composer/DefaultThreadComposerRuntimeCore.tsx
3101
- var DefaultThreadComposerRuntimeCore = (_class9 = class extends BaseComposerRuntimeCore {
3069
+ var DefaultThreadComposerRuntimeCore = (_class8 = class extends BaseComposerRuntimeCore {
3102
3070
  constructor(runtime) {
3103
- super();_class9.prototype.__init17.call(this);;
3071
+ super();_class8.prototype.__init16.call(this);;
3104
3072
  this.runtime = runtime;
3105
3073
  this.connect();
3106
3074
  }
3107
- __init17() {this._canCancel = false}
3075
+ __init16() {this._canCancel = false}
3108
3076
  get canCancel() {
3109
3077
  return this._canCancel;
3110
3078
  }
@@ -3131,11 +3099,11 @@ var DefaultThreadComposerRuntimeCore = (_class9 = class extends BaseComposerRunt
3131
3099
  async cancel() {
3132
3100
  this.runtime.cancelRun();
3133
3101
  }
3134
- }, _class9);
3102
+ }, _class8);
3135
3103
 
3136
3104
  // src/utils/ProxyConfigProvider.ts
3137
- var ProxyConfigProvider = (_class10 = class {constructor() { _class10.prototype.__init18.call(this); }
3138
- __init18() {this._providers = /* @__PURE__ */ new Set()}
3105
+ var ProxyConfigProvider = (_class9 = class {constructor() { _class9.prototype.__init17.call(this); }
3106
+ __init17() {this._providers = /* @__PURE__ */ new Set()}
3139
3107
  getModelConfig() {
3140
3108
  return _chunkKVXP3Q6Kjs.mergeModelConfigs.call(void 0, this._providers);
3141
3109
  }
@@ -3145,7 +3113,7 @@ var ProxyConfigProvider = (_class10 = class {constructor() { _class10.prototype.
3145
3113
  this._providers.delete(provider);
3146
3114
  };
3147
3115
  }
3148
- }, _class10);
3116
+ }, _class9);
3149
3117
 
3150
3118
  // src/utils/idUtils.tsx
3151
3119
  var _nonsecure = require('nanoid/non-secure');
@@ -3212,11 +3180,11 @@ var findHead = (message) => {
3212
3180
  if ("current" in message) return message;
3213
3181
  return null;
3214
3182
  };
3215
- var MessageRepository = (_class11 = class {constructor() { _class11.prototype.__init19.call(this);_class11.prototype.__init20.call(this);_class11.prototype.__init21.call(this); }
3216
- __init19() {this.messages = /* @__PURE__ */ new Map()}
3183
+ var MessageRepository = (_class10 = class {constructor() { _class10.prototype.__init18.call(this);_class10.prototype.__init19.call(this);_class10.prototype.__init20.call(this); }
3184
+ __init18() {this.messages = /* @__PURE__ */ new Map()}
3217
3185
  // message_id -> item
3218
- __init20() {this.head = null}
3219
- __init21() {this.root = {
3186
+ __init19() {this.head = null}
3187
+ __init20() {this.root = {
3220
3188
  children: [],
3221
3189
  next: null
3222
3190
  }}
@@ -3394,7 +3362,7 @@ var MessageRepository = (_class11 = class {constructor() { _class11.prototype.__
3394
3362
  }
3395
3363
  this.resetHead(_nullishCoalesce(_nullishCoalesce(headId, () => ( _optionalChain([messages2, 'access', _176 => _176.at, 'call', _177 => _177(-1), 'optionalAccess', _178 => _178.message, 'access', _179 => _179.id]))), () => ( null)));
3396
3364
  }
3397
- }, _class11);
3365
+ }, _class10);
3398
3366
 
3399
3367
  // src/ui/base/tooltip-icon-button.tsx
3400
3368
 
@@ -3525,7 +3493,7 @@ var getThreadState = (runtime) => {
3525
3493
  speech: runtime.speech
3526
3494
  });
3527
3495
  };
3528
- var ThreadRuntimeImpl = (_class12 = class {
3496
+ var ThreadRuntimeImpl = (_class11 = class {
3529
3497
  // public path = "assistant.threads[main]"; // TODO
3530
3498
  /**
3531
3499
  * @deprecated Use `getState().threadId` instead. This will be removed in 0.6.0.
@@ -3579,7 +3547,7 @@ var ThreadRuntimeImpl = (_class12 = class {
3579
3547
  return this._threadBinding.getState();
3580
3548
  }
3581
3549
 
3582
- constructor(threadBinding) {;_class12.prototype.__init22.call(this);
3550
+ constructor(threadBinding) {;_class11.prototype.__init21.call(this);_class11.prototype.__init22.call(this);
3583
3551
  const stateBinding = new LazyMemoizeSubject({
3584
3552
  getState: () => getThreadState(threadBinding.getState()),
3585
3553
  subscribe: (callback) => threadBinding.subscribe(callback)
@@ -3587,10 +3555,11 @@ var ThreadRuntimeImpl = (_class12 = class {
3587
3555
  this._threadBinding = {
3588
3556
  getState: () => threadBinding.getState(),
3589
3557
  getStateState: () => stateBinding.getState(),
3558
+ outerSubscribe: (callback) => threadBinding.outerSubscribe(callback),
3590
3559
  subscribe: (callback) => threadBinding.subscribe(callback)
3591
3560
  };
3592
3561
  }
3593
- __init22() {this.composer = new ThreadComposerRuntimeImpl(
3562
+ __init21() {this.composer = new ThreadComposerRuntimeImpl(
3594
3563
  new NestedSubscriptionSubject({
3595
3564
  getState: () => this._threadBinding.getState().composer,
3596
3565
  subscribe: (callback) => this._threadBinding.subscribe(callback)
@@ -3699,7 +3668,21 @@ var ThreadRuntimeImpl = (_class12 = class {
3699
3668
  this._threadBinding
3700
3669
  );
3701
3670
  }
3702
- }, _class12);
3671
+ __init22() {this._eventListenerNestedSubscriptions = /* @__PURE__ */ new Map()}
3672
+ unstable_on(event, callback) {
3673
+ let subject = this._eventListenerNestedSubscriptions.get(event);
3674
+ if (!subject) {
3675
+ subject = new NestedSubscriptionSubject({
3676
+ getState: () => ({
3677
+ subscribe: (callback2) => this._threadBinding.getState().unstable_on(event, callback2)
3678
+ }),
3679
+ subscribe: (callback2) => this._threadBinding.outerSubscribe(callback2)
3680
+ });
3681
+ this._eventListenerNestedSubscriptions.set(event, subject);
3682
+ }
3683
+ return subject.subscribe(callback);
3684
+ }
3685
+ }, _class11);
3703
3686
 
3704
3687
  // src/api/AssistantRuntime.ts
3705
3688
  var AssistantRuntimeImpl = class _AssistantRuntimeImpl {
@@ -3943,17 +3926,13 @@ function assistantDecoderStream() {
3943
3926
  }
3944
3927
  case "c" /* ToolCallDelta */: {
3945
3928
  const { toolCallId, argsTextDelta } = value;
3946
- if (_optionalChain([currentToolCall, 'optionalAccess', _192 => _192.id]) !== toolCallId) {
3947
- throw new Error(
3948
- `Received tool call delta for unknown tool call "${toolCallId}".`
3949
- );
3950
- }
3929
+ const toolName = toolCallNames.get(toolCallId);
3951
3930
  currentToolCall.argsText += argsTextDelta;
3952
3931
  controller.enqueue({
3953
3932
  type: "tool-call-delta",
3954
3933
  toolCallType: "function",
3955
- toolCallId: currentToolCall.id,
3956
- toolName: currentToolCall.name,
3934
+ toolCallId,
3935
+ toolName,
3957
3936
  argsTextDelta
3958
3937
  });
3959
3938
  break;
@@ -4090,7 +4069,7 @@ var useEdgeRuntime = (options) => {
4090
4069
  };
4091
4070
 
4092
4071
  // src/runtimes/local/shouldContinue.tsx
4093
- var shouldContinue = (result) => _optionalChain([result, 'access', _193 => _193.status, 'optionalAccess', _194 => _194.type]) === "requires-action" && result.status.reason === "tool-calls" && result.content.every((c) => c.type !== "tool-call" || !!c.result);
4072
+ var shouldContinue = (result) => _optionalChain([result, 'access', _192 => _192.status, 'optionalAccess', _193 => _193.type]) === "requires-action" && result.status.reason === "tool-calls" && result.content.every((c) => c.type !== "tool-call" || !!c.result);
4094
4073
 
4095
4074
  // src/runtimes/composer/DefaultEditComposerRuntimeCore.tsx
4096
4075
  var DefaultEditComposerRuntimeCore = class extends BaseComposerRuntimeCore {
@@ -4110,7 +4089,7 @@ var DefaultEditComposerRuntimeCore = class extends BaseComposerRuntimeCore {
4110
4089
  return true;
4111
4090
  }
4112
4091
  getAttachmentAdapter() {
4113
- return _optionalChain([this, 'access', _195 => _195.runtime, 'access', _196 => _196.adapters, 'optionalAccess', _197 => _197.attachments]);
4092
+ return _optionalChain([this, 'access', _194 => _194.runtime, 'access', _195 => _195.adapters, 'optionalAccess', _196 => _196.attachments]);
4114
4093
  }
4115
4094
 
4116
4095
 
@@ -4134,8 +4113,8 @@ var DefaultEditComposerRuntimeCore = class extends BaseComposerRuntimeCore {
4134
4113
  };
4135
4114
 
4136
4115
  // src/runtimes/core/BaseThreadRuntimeCore.tsx
4137
- var BaseThreadRuntimeCore = (_class13 = class {
4138
- constructor(configProvider) {;_class13.prototype.__init23.call(this);_class13.prototype.__init24.call(this);_class13.prototype.__init25.call(this);_class13.prototype.__init26.call(this);_class13.prototype.__init27.call(this);
4116
+ var BaseThreadRuntimeCore = (_class12 = class {
4117
+ constructor(configProvider) {;_class12.prototype.__init23.call(this);_class12.prototype.__init24.call(this);_class12.prototype.__init25.call(this);_class12.prototype.__init26.call(this);_class12.prototype.__init27.call(this);_class12.prototype.__init28.call(this);
4139
4118
  this.configProvider = configProvider;
4140
4119
  }
4141
4120
  __init23() {this._subscriptions = /* @__PURE__ */ new Set()}
@@ -4162,18 +4141,23 @@ var BaseThreadRuntimeCore = (_class13 = class {
4162
4141
  this.repository.getMessage(messageId)
4163
4142
  )
4164
4143
  );
4165
- this.notifySubscribers();
4144
+ this._notifySubscribers();
4166
4145
  }
4167
4146
  getBranches(messageId) {
4168
4147
  return this.repository.getBranches(messageId);
4169
4148
  }
4170
4149
  switchToBranch(branchId) {
4171
4150
  this.repository.switchToBranch(branchId);
4172
- this.notifySubscribers();
4151
+ this._notifySubscribers();
4173
4152
  }
4174
- notifySubscribers() {
4153
+ _notifySubscribers() {
4175
4154
  for (const callback of this._subscriptions) callback();
4176
4155
  }
4156
+ _notifyEventSubscribers(event) {
4157
+ const subscribers = this._eventSubscribers.get(event);
4158
+ if (!subscribers) return;
4159
+ for (const callback of subscribers) callback();
4160
+ }
4177
4161
  subscribe(callback) {
4178
4162
  this._subscriptions.add(callback);
4179
4163
  return () => this._subscriptions.delete(callback);
@@ -4183,20 +4167,20 @@ var BaseThreadRuntimeCore = (_class13 = class {
4183
4167
  return this._submittedFeedback[messageId];
4184
4168
  }
4185
4169
  submitFeedback({ messageId, type }) {
4186
- const adapter = _optionalChain([this, 'access', _198 => _198.adapters, 'optionalAccess', _199 => _199.feedback]);
4170
+ const adapter = _optionalChain([this, 'access', _197 => _197.adapters, 'optionalAccess', _198 => _198.feedback]);
4187
4171
  if (!adapter) throw new Error("Feedback adapter not configured");
4188
4172
  const { message } = this.repository.getMessage(messageId);
4189
4173
  adapter.submit({ message, type });
4190
4174
  this._submittedFeedback[messageId] = { type };
4191
- this.notifySubscribers();
4175
+ this._notifySubscribers();
4192
4176
  }
4193
4177
 
4194
4178
 
4195
4179
  speak(messageId) {
4196
- const adapter = _optionalChain([this, 'access', _200 => _200.adapters, 'optionalAccess', _201 => _201.speech]);
4180
+ const adapter = _optionalChain([this, 'access', _199 => _199.adapters, 'optionalAccess', _200 => _200.speech]);
4197
4181
  if (!adapter) throw new Error("Speech adapter not configured");
4198
4182
  const { message } = this.repository.getMessage(messageId);
4199
- _optionalChain([this, 'access', _202 => _202._stopSpeaking, 'optionalCall', _203 => _203()]);
4183
+ _optionalChain([this, 'access', _201 => _201._stopSpeaking, 'optionalCall', _202 => _202()]);
4200
4184
  const utterance = adapter.speak(message);
4201
4185
  const unsub = utterance.subscribe(() => {
4202
4186
  if (utterance.status.type === "ended") {
@@ -4205,10 +4189,10 @@ var BaseThreadRuntimeCore = (_class13 = class {
4205
4189
  } else {
4206
4190
  this.speech = { messageId, status: utterance.status };
4207
4191
  }
4208
- this.notifySubscribers();
4192
+ this._notifySubscribers();
4209
4193
  });
4210
4194
  this.speech = { messageId, status: utterance.status };
4211
- this.notifySubscribers();
4195
+ this._notifySubscribers();
4212
4196
  this._stopSpeaking = () => {
4213
4197
  utterance.cancel();
4214
4198
  unsub();
@@ -4219,21 +4203,34 @@ var BaseThreadRuntimeCore = (_class13 = class {
4219
4203
  stopSpeaking() {
4220
4204
  if (!this._stopSpeaking) throw new Error("No message is being spoken");
4221
4205
  this._stopSpeaking();
4222
- this.notifySubscribers();
4206
+ this._notifySubscribers();
4223
4207
  }
4224
4208
  export() {
4225
4209
  return this.repository.export();
4226
4210
  }
4227
4211
  import(data) {
4228
4212
  this.repository.import(data);
4229
- this.notifySubscribers();
4213
+ this._notifySubscribers();
4230
4214
  }
4231
- }, _class13);
4215
+ __init28() {this._eventSubscribers = /* @__PURE__ */ new Map()}
4216
+ unstable_on(event, callback) {
4217
+ const subscribers = this._eventSubscribers.get(event);
4218
+ if (!subscribers) {
4219
+ this._eventSubscribers.set(event, /* @__PURE__ */ new Set([callback]));
4220
+ } else {
4221
+ subscribers.add(callback);
4222
+ }
4223
+ return () => {
4224
+ const subscribers2 = this._eventSubscribers.get(event);
4225
+ subscribers2.delete(callback);
4226
+ };
4227
+ }
4228
+ }, _class12);
4232
4229
 
4233
4230
  // src/runtimes/local/LocalThreadRuntimeCore.tsx
4234
- var LocalThreadRuntimeCore = (_class14 = class extends BaseThreadRuntimeCore {
4231
+ var LocalThreadRuntimeCore = (_class13 = class extends BaseThreadRuntimeCore {
4235
4232
  constructor(configProvider, adapter, { initialMessages, ...options }) {
4236
- super(configProvider);_class14.prototype.__init28.call(this);_class14.prototype.__init29.call(this);_class14.prototype.__init30.call(this);_class14.prototype.__init31.call(this);;
4233
+ super(configProvider);_class13.prototype.__init29.call(this);_class13.prototype.__init30.call(this);_class13.prototype.__init31.call(this);_class13.prototype.__init32.call(this);;
4237
4234
  this.adapter = adapter;
4238
4235
  this.threadId = generateId();
4239
4236
  this.options = options;
@@ -4246,7 +4243,7 @@ var LocalThreadRuntimeCore = (_class14 = class extends BaseThreadRuntimeCore {
4246
4243
  }
4247
4244
  }
4248
4245
  }
4249
- __init28() {this.capabilities = {
4246
+ __init29() {this.capabilities = {
4250
4247
  switchToBranch: true,
4251
4248
  edit: true,
4252
4249
  reload: true,
@@ -4256,10 +4253,10 @@ var LocalThreadRuntimeCore = (_class14 = class extends BaseThreadRuntimeCore {
4256
4253
  attachments: false,
4257
4254
  feedback: false
4258
4255
  }}
4259
- __init29() {this.abortController = null}
4256
+ __init30() {this.abortController = null}
4260
4257
 
4261
- __init30() {this.isDisabled = false}
4262
- __init31() {this.suggestions = []}
4258
+ __init31() {this.isDisabled = false}
4259
+ __init32() {this.suggestions = []}
4263
4260
  get adapters() {
4264
4261
  return this.options.adapters;
4265
4262
  }
@@ -4273,22 +4270,22 @@ var LocalThreadRuntimeCore = (_class14 = class extends BaseThreadRuntimeCore {
4273
4270
  set options({ initialMessages, ...options }) {
4274
4271
  this._options = options;
4275
4272
  let hasUpdates = false;
4276
- const canSpeak = _optionalChain([options, 'access', _204 => _204.adapters, 'optionalAccess', _205 => _205.speech]) !== void 0;
4273
+ const canSpeak = _optionalChain([options, 'access', _203 => _203.adapters, 'optionalAccess', _204 => _204.speech]) !== void 0;
4277
4274
  if (this.capabilities.speech !== canSpeak) {
4278
4275
  this.capabilities.speech = canSpeak;
4279
4276
  hasUpdates = true;
4280
4277
  }
4281
- const canAttach = _optionalChain([options, 'access', _206 => _206.adapters, 'optionalAccess', _207 => _207.attachments]) !== void 0;
4278
+ const canAttach = _optionalChain([options, 'access', _205 => _205.adapters, 'optionalAccess', _206 => _206.attachments]) !== void 0;
4282
4279
  if (this.capabilities.attachments !== canAttach) {
4283
4280
  this.capabilities.attachments = canAttach;
4284
4281
  hasUpdates = true;
4285
4282
  }
4286
- const canFeedback = _optionalChain([options, 'access', _208 => _208.adapters, 'optionalAccess', _209 => _209.feedback]) !== void 0;
4283
+ const canFeedback = _optionalChain([options, 'access', _207 => _207.adapters, 'optionalAccess', _208 => _208.feedback]) !== void 0;
4287
4284
  if (this.capabilities.feedback !== canFeedback) {
4288
4285
  this.capabilities.feedback = canFeedback;
4289
4286
  hasUpdates = true;
4290
4287
  }
4291
- if (hasUpdates) this.notifySubscribers();
4288
+ if (hasUpdates) this._notifySubscribers();
4292
4289
  }
4293
4290
  async append(message) {
4294
4291
  const newMessage = fromCoreMessage(message, {
@@ -4299,7 +4296,7 @@ var LocalThreadRuntimeCore = (_class14 = class extends BaseThreadRuntimeCore {
4299
4296
  await this.startRun(newMessage.id);
4300
4297
  } else {
4301
4298
  this.repository.resetHead(newMessage.id);
4302
- this.notifySubscribers();
4299
+ this._notifySubscribers();
4303
4300
  }
4304
4301
  }
4305
4302
  async startRun(parentId) {
@@ -4312,19 +4309,20 @@ var LocalThreadRuntimeCore = (_class14 = class extends BaseThreadRuntimeCore {
4312
4309
  content: [],
4313
4310
  createdAt: /* @__PURE__ */ new Date()
4314
4311
  };
4312
+ this._notifyEventSubscribers("run-start");
4315
4313
  do {
4316
4314
  message = await this.performRoundtrip(parentId, message);
4317
4315
  } while (shouldContinue(message));
4318
4316
  }
4319
4317
  async performRoundtrip(parentId, message) {
4320
4318
  const messages2 = this.repository.getMessages();
4321
- _optionalChain([this, 'access', _210 => _210.abortController, 'optionalAccess', _211 => _211.abort, 'call', _212 => _212()]);
4319
+ _optionalChain([this, 'access', _209 => _209.abortController, 'optionalAccess', _210 => _210.abort, 'call', _211 => _211()]);
4322
4320
  this.abortController = new AbortController();
4323
4321
  const initialContent = message.content;
4324
- const initialSteps = _optionalChain([message, 'access', _213 => _213.metadata, 'optionalAccess', _214 => _214.steps]);
4325
- const initalCustom = _optionalChain([message, 'access', _215 => _215.metadata, 'optionalAccess', _216 => _216.custom]);
4322
+ const initialSteps = _optionalChain([message, 'access', _212 => _212.metadata, 'optionalAccess', _213 => _213.steps]);
4323
+ const initalCustom = _optionalChain([message, 'access', _214 => _214.metadata, 'optionalAccess', _215 => _215.custom]);
4326
4324
  const updateMessage = (m) => {
4327
- const newSteps = _optionalChain([m, 'access', _217 => _217.metadata, 'optionalAccess', _218 => _218.steps]) || _optionalChain([m, 'access', _219 => _219.metadata, 'optionalAccess', _220 => _220.roundtrips]);
4325
+ const newSteps = _optionalChain([m, 'access', _216 => _216.metadata, 'optionalAccess', _217 => _217.steps]) || _optionalChain([m, 'access', _218 => _218.metadata, 'optionalAccess', _219 => _219.roundtrips]);
4328
4326
  const steps2 = newSteps ? [..._nullishCoalesce(initialSteps, () => ( [])), ...newSteps] : void 0;
4329
4327
  message = {
4330
4328
  ...message,
@@ -4336,17 +4334,17 @@ var LocalThreadRuntimeCore = (_class14 = class extends BaseThreadRuntimeCore {
4336
4334
  metadata: {
4337
4335
  ...message.metadata,
4338
4336
  ...steps2 ? { roundtrips: steps2, steps: steps2 } : void 0,
4339
- ..._optionalChain([m, 'access', _221 => _221.metadata, 'optionalAccess', _222 => _222.custom]) ? {
4337
+ ..._optionalChain([m, 'access', _220 => _220.metadata, 'optionalAccess', _221 => _221.custom]) ? {
4340
4338
  custom: { ..._nullishCoalesce(initalCustom, () => ( {})), ...m.metadata.custom }
4341
4339
  } : void 0
4342
4340
  }
4343
4341
  } : void 0
4344
4342
  };
4345
4343
  this.repository.addOrUpdateMessage(parentId, message);
4346
- this.notifySubscribers();
4344
+ this._notifySubscribers();
4347
4345
  };
4348
4346
  const maxSteps = this.options.maxSteps ? this.options.maxSteps : (_nullishCoalesce(this.options.maxToolRoundtrips, () => ( 1))) + 1;
4349
- const steps = _nullishCoalesce(_optionalChain([message, 'access', _223 => _223.metadata, 'optionalAccess', _224 => _224.steps, 'optionalAccess', _225 => _225.length]), () => ( 0));
4347
+ const steps = _nullishCoalesce(_optionalChain([message, 'access', _222 => _222.metadata, 'optionalAccess', _223 => _223.steps, 'optionalAccess', _224 => _224.length]), () => ( 0));
4350
4348
  if (steps >= maxSteps) {
4351
4349
  updateMessage({
4352
4350
  status: {
@@ -4398,7 +4396,7 @@ var LocalThreadRuntimeCore = (_class14 = class extends BaseThreadRuntimeCore {
4398
4396
  return message;
4399
4397
  }
4400
4398
  cancelRun() {
4401
- _optionalChain([this, 'access', _226 => _226.abortController, 'optionalAccess', _227 => _227.abort, 'call', _228 => _228()]);
4399
+ _optionalChain([this, 'access', _225 => _225.abortController, 'optionalAccess', _226 => _226.abort, 'call', _227 => _227()]);
4402
4400
  this.abortController = null;
4403
4401
  }
4404
4402
  addToolResult({
@@ -4434,7 +4432,7 @@ var LocalThreadRuntimeCore = (_class14 = class extends BaseThreadRuntimeCore {
4434
4432
  this.performRoundtrip(parentId, message);
4435
4433
  }
4436
4434
  }
4437
- }, _class14);
4435
+ }, _class13);
4438
4436
 
4439
4437
  // src/runtimes/local/LocalRuntimeCore.tsx
4440
4438
  var LocalRuntimeCore = class extends BaseAssistantRuntimeCore {
@@ -4454,6 +4452,7 @@ var LocalRuntimeCore = class extends BaseAssistantRuntimeCore {
4454
4452
  this.thread.adapter,
4455
4453
  options
4456
4454
  );
4455
+ this.thread._notifyEventSubscribers("switched-to");
4457
4456
  }
4458
4457
  switchToThread(threadId) {
4459
4458
  if (threadId !== null) {
@@ -4469,7 +4468,7 @@ var LocalRuntimeCore = class extends BaseAssistantRuntimeCore {
4469
4468
  const messages2 = fromCoreMessages(initialMessages);
4470
4469
  this.thread.import({
4471
4470
  messages: messages2.map((m, idx) => ({
4472
- parentId: _nullishCoalesce(_optionalChain([messages2, 'access', _229 => _229[idx - 1], 'optionalAccess', _230 => _230.id]), () => ( null)),
4471
+ parentId: _nullishCoalesce(_optionalChain([messages2, 'access', _228 => _228[idx - 1], 'optionalAccess', _229 => _229.id]), () => ( null)),
4473
4472
  message: m
4474
4473
  }))
4475
4474
  });
@@ -4511,8 +4510,8 @@ var getExternalStoreMessage = (message) => {
4511
4510
  };
4512
4511
 
4513
4512
  // src/runtimes/external-store/ThreadMessageConverter.ts
4514
- var ThreadMessageConverter = (_class15 = class {constructor() { _class15.prototype.__init32.call(this); }
4515
- __init32() {this.cache = /* @__PURE__ */ new WeakMap()}
4513
+ var ThreadMessageConverter = (_class14 = class {constructor() { _class14.prototype.__init33.call(this); }
4514
+ __init33() {this.cache = /* @__PURE__ */ new WeakMap()}
4516
4515
  convertMessages(messages2, converter) {
4517
4516
  return messages2.map((m, idx) => {
4518
4517
  const cached = this.cache.get(m);
@@ -4521,7 +4520,7 @@ var ThreadMessageConverter = (_class15 = class {constructor() { _class15.prototy
4521
4520
  return newMessage;
4522
4521
  });
4523
4522
  }
4524
- }, _class15);
4523
+ }, _class14);
4525
4524
 
4526
4525
  // src/runtimes/external-store/auto-status.tsx
4527
4526
  var AUTO_STATUS_RUNNING = Object.freeze({ type: "running" });
@@ -4609,11 +4608,11 @@ var fromThreadMessageLike = (like, fallbackId, fallbackStatus) => {
4609
4608
  // src/runtimes/external-store/ExternalStoreThreadRuntimeCore.tsx
4610
4609
  var EMPTY_ARRAY2 = Object.freeze([]);
4611
4610
  var hasUpcomingMessage = (isRunning, messages2) => {
4612
- return isRunning && _optionalChain([messages2, 'access', _231 => _231[messages2.length - 1], 'optionalAccess', _232 => _232.role]) !== "assistant";
4611
+ return isRunning && _optionalChain([messages2, 'access', _230 => _230[messages2.length - 1], 'optionalAccess', _231 => _231.role]) !== "assistant";
4613
4612
  };
4614
- var ExternalStoreThreadRuntimeCore = (_class16 = class extends BaseThreadRuntimeCore {
4615
- __init33() {this.assistantOptimisticId = null}
4616
- __init34() {this._capabilities = {
4613
+ var ExternalStoreThreadRuntimeCore = (_class15 = class extends BaseThreadRuntimeCore {
4614
+ __init34() {this.assistantOptimisticId = null}
4615
+ __init35() {this._capabilities = {
4617
4616
  switchToBranch: false,
4618
4617
  edit: false,
4619
4618
  reload: false,
@@ -4635,9 +4634,9 @@ var ExternalStoreThreadRuntimeCore = (_class16 = class extends BaseThreadRuntime
4635
4634
  get adapters() {
4636
4635
  return this._store.adapters;
4637
4636
  }
4638
- __init35() {this.suggestions = []}
4639
- __init36() {this.extras = void 0}
4640
- __init37() {this._converter = new ThreadMessageConverter()}
4637
+ __init36() {this.suggestions = []}
4638
+ __init37() {this.extras = void 0}
4639
+ __init38() {this._converter = new ThreadMessageConverter()}
4641
4640
 
4642
4641
  beginEdit(messageId) {
4643
4642
  if (!this.store.onEdit)
@@ -4645,7 +4644,7 @@ var ExternalStoreThreadRuntimeCore = (_class16 = class extends BaseThreadRuntime
4645
4644
  super.beginEdit(messageId);
4646
4645
  }
4647
4646
  constructor(configProvider, store) {
4648
- super(configProvider);_class16.prototype.__init33.call(this);_class16.prototype.__init34.call(this);_class16.prototype.__init35.call(this);_class16.prototype.__init36.call(this);_class16.prototype.__init37.call(this);_class16.prototype.__init38.call(this);;
4647
+ super(configProvider);_class15.prototype.__init34.call(this);_class15.prototype.__init35.call(this);_class15.prototype.__init36.call(this);_class15.prototype.__init37.call(this);_class15.prototype.__init38.call(this);_class15.prototype.__init39.call(this);;
4649
4648
  this.store = store;
4650
4649
  }
4651
4650
  get store() {
@@ -4665,17 +4664,17 @@ var ExternalStoreThreadRuntimeCore = (_class16 = class extends BaseThreadRuntime
4665
4664
  edit: this._store.onEdit !== void 0,
4666
4665
  reload: this._store.onReload !== void 0,
4667
4666
  cancel: this._store.onCancel !== void 0,
4668
- speech: _optionalChain([this, 'access', _236 => _236._store, 'access', _237 => _237.adapters, 'optionalAccess', _238 => _238.speech]) !== void 0,
4669
- unstable_copy: _optionalChain([this, 'access', _239 => _239._store, 'access', _240 => _240.unstable_capabilities, 'optionalAccess', _241 => _241.copy]) !== false,
4667
+ speech: _optionalChain([this, 'access', _235 => _235._store, 'access', _236 => _236.adapters, 'optionalAccess', _237 => _237.speech]) !== void 0,
4668
+ unstable_copy: _optionalChain([this, 'access', _238 => _238._store, 'access', _239 => _239.unstable_capabilities, 'optionalAccess', _240 => _240.copy]) !== false,
4670
4669
  // default true
4671
- attachments: !!_optionalChain([this, 'access', _242 => _242.store, 'access', _243 => _243.adapters, 'optionalAccess', _244 => _244.attachments]),
4672
- feedback: !!_optionalChain([this, 'access', _245 => _245.store, 'access', _246 => _246.adapters, 'optionalAccess', _247 => _247.feedback])
4670
+ attachments: !!_optionalChain([this, 'access', _241 => _241.store, 'access', _242 => _242.adapters, 'optionalAccess', _243 => _243.attachments]),
4671
+ feedback: !!_optionalChain([this, 'access', _244 => _244.store, 'access', _245 => _245.adapters, 'optionalAccess', _246 => _246.feedback])
4673
4672
  };
4674
4673
  if (oldStore) {
4675
4674
  if (oldStore.convertMessage !== store.convertMessage) {
4676
4675
  this._converter = new ThreadMessageConverter();
4677
4676
  } else if (oldStore.isRunning === store.isRunning && oldStore.messages === store.messages) {
4678
- this.notifySubscribers();
4677
+ this._notifySubscribers();
4679
4678
  return;
4680
4679
  }
4681
4680
  }
@@ -4696,7 +4695,7 @@ var ExternalStoreThreadRuntimeCore = (_class16 = class extends BaseThreadRuntime
4696
4695
  for (let i = 0; i < messages2.length; i++) {
4697
4696
  const message = messages2[i];
4698
4697
  const parent = messages2[i - 1];
4699
- this.repository.addOrUpdateMessage(_nullishCoalesce(_optionalChain([parent, 'optionalAccess', _248 => _248.id]), () => ( null)), message);
4698
+ this.repository.addOrUpdateMessage(_nullishCoalesce(_optionalChain([parent, 'optionalAccess', _247 => _247.id]), () => ( null)), message);
4700
4699
  }
4701
4700
  if (this.assistantOptimisticId) {
4702
4701
  this.repository.deleteMessage(this.assistantOptimisticId);
@@ -4704,7 +4703,7 @@ var ExternalStoreThreadRuntimeCore = (_class16 = class extends BaseThreadRuntime
4704
4703
  }
4705
4704
  if (hasUpcomingMessage(isRunning, messages2)) {
4706
4705
  this.assistantOptimisticId = this.repository.appendOptimisticMessage(
4707
- _nullishCoalesce(_optionalChain([messages2, 'access', _249 => _249.at, 'call', _250 => _250(-1), 'optionalAccess', _251 => _251.id]), () => ( null)),
4706
+ _nullishCoalesce(_optionalChain([messages2, 'access', _248 => _248.at, 'call', _249 => _249(-1), 'optionalAccess', _250 => _250.id]), () => ( null)),
4708
4707
  {
4709
4708
  role: "assistant",
4710
4709
  content: []
@@ -4712,10 +4711,10 @@ var ExternalStoreThreadRuntimeCore = (_class16 = class extends BaseThreadRuntime
4712
4711
  );
4713
4712
  }
4714
4713
  this.repository.resetHead(
4715
- _nullishCoalesce(_nullishCoalesce(this.assistantOptimisticId, () => ( _optionalChain([messages2, 'access', _252 => _252.at, 'call', _253 => _253(-1), 'optionalAccess', _254 => _254.id]))), () => ( null))
4714
+ _nullishCoalesce(_nullishCoalesce(this.assistantOptimisticId, () => ( _optionalChain([messages2, 'access', _251 => _251.at, 'call', _252 => _252(-1), 'optionalAccess', _253 => _253.id]))), () => ( null))
4716
4715
  );
4717
4716
  this._messages = this.repository.getMessages();
4718
- this.notifySubscribers();
4717
+ this._notifySubscribers();
4719
4718
  }
4720
4719
  switchToBranch(branchId) {
4721
4720
  if (!this._store.setMessages)
@@ -4724,7 +4723,7 @@ var ExternalStoreThreadRuntimeCore = (_class16 = class extends BaseThreadRuntime
4724
4723
  this.updateMessages(this.repository.getMessages());
4725
4724
  }
4726
4725
  async append(message) {
4727
- if (message.parentId !== (_nullishCoalesce(_optionalChain([this, 'access', _255 => _255.messages, 'access', _256 => _256.at, 'call', _257 => _257(-1), 'optionalAccess', _258 => _258.id]), () => ( null)))) {
4726
+ if (message.parentId !== (_nullishCoalesce(_optionalChain([this, 'access', _254 => _254.messages, 'access', _255 => _255.at, 'call', _256 => _256(-1), 'optionalAccess', _257 => _257.id]), () => ( null)))) {
4728
4727
  if (!this._store.onEdit)
4729
4728
  throw new Error("Runtime does not support editing messages.");
4730
4729
  await this._store.onEdit(message);
@@ -4747,14 +4746,14 @@ var ExternalStoreThreadRuntimeCore = (_class16 = class extends BaseThreadRuntime
4747
4746
  }
4748
4747
  let messages2 = this.repository.getMessages();
4749
4748
  const previousMessage = messages2[messages2.length - 1];
4750
- if (_optionalChain([previousMessage, 'optionalAccess', _259 => _259.role]) === "user" && previousMessage.id === _optionalChain([messages2, 'access', _260 => _260.at, 'call', _261 => _261(-1), 'optionalAccess', _262 => _262.id])) {
4749
+ if (_optionalChain([previousMessage, 'optionalAccess', _258 => _258.role]) === "user" && previousMessage.id === _optionalChain([messages2, 'access', _259 => _259.at, 'call', _260 => _260(-1), 'optionalAccess', _261 => _261.id])) {
4751
4750
  this.repository.deleteMessage(previousMessage.id);
4752
4751
  if (!this.composer.text.trim()) {
4753
4752
  this.composer.setText(getThreadMessageText(previousMessage));
4754
4753
  }
4755
4754
  messages2 = this.repository.getMessages();
4756
4755
  } else {
4757
- this.notifySubscribers();
4756
+ this._notifySubscribers();
4758
4757
  }
4759
4758
  setTimeout(() => {
4760
4759
  this.updateMessages(messages2);
@@ -4765,12 +4764,12 @@ var ExternalStoreThreadRuntimeCore = (_class16 = class extends BaseThreadRuntime
4765
4764
  throw new Error("Runtime does not support tool results.");
4766
4765
  this._store.onAddToolResult(options);
4767
4766
  }
4768
- __init38() {this.updateMessages = (messages2) => {
4769
- _optionalChain([this, 'access', _263 => _263._store, 'access', _264 => _264.setMessages, 'optionalCall', _265 => _265(
4767
+ __init39() {this.updateMessages = (messages2) => {
4768
+ _optionalChain([this, 'access', _262 => _262._store, 'access', _263 => _263.setMessages, 'optionalCall', _264 => _264(
4770
4769
  messages2.flatMap(getExternalStoreMessage).filter((m) => m != null)
4771
4770
  )]);
4772
4771
  }}
4773
- }, _class16);
4772
+ }, _class15);
4774
4773
 
4775
4774
  // src/runtimes/external-store/ExternalStoreRuntimeCore.tsx
4776
4775
  var ExternalStoreRuntimeCore = class extends BaseAssistantRuntimeCore {
@@ -4797,6 +4796,7 @@ var ExternalStoreRuntimeCore = class extends BaseAssistantRuntimeCore {
4797
4796
  }
4798
4797
  );
4799
4798
  await this.thread.store.onSwitchToNewThread();
4799
+ this.thread._notifyEventSubscribers("switched-to");
4800
4800
  }
4801
4801
  async switchToThread(threadId) {
4802
4802
  if (threadId !== null) {
@@ -4810,7 +4810,8 @@ var ExternalStoreRuntimeCore = class extends BaseAssistantRuntimeCore {
4810
4810
  // ignore messages until rerender
4811
4811
  }
4812
4812
  );
4813
- this.thread.store.onSwitchToThread(threadId);
4813
+ await this.thread.store.onSwitchToThread(threadId);
4814
+ this.thread._notifyEventSubscribers("switched-to");
4814
4815
  } else {
4815
4816
  this.switchToNewThread();
4816
4817
  }
@@ -5051,8 +5052,8 @@ var WebSpeechSynthesisAdapter = class {
5051
5052
  };
5052
5053
 
5053
5054
  // src/runtimes/attachment/SimpleImageAttachmentAdapter.ts
5054
- var SimpleImageAttachmentAdapter = (_class17 = class {constructor() { _class17.prototype.__init39.call(this); }
5055
- __init39() {this.accept = "image/*"}
5055
+ var SimpleImageAttachmentAdapter = (_class16 = class {constructor() { _class16.prototype.__init40.call(this); }
5056
+ __init40() {this.accept = "image/*"}
5056
5057
  async add(state) {
5057
5058
  return {
5058
5059
  id: state.file.name,
@@ -5077,7 +5078,7 @@ var SimpleImageAttachmentAdapter = (_class17 = class {constructor() { _class17.p
5077
5078
  }
5078
5079
  async remove() {
5079
5080
  }
5080
- }, _class17);
5081
+ }, _class16);
5081
5082
  var getFileDataURL = (file) => new Promise((resolve, reject) => {
5082
5083
  const reader = new FileReader();
5083
5084
  reader.onload = () => resolve(reader.result);
@@ -5086,8 +5087,8 @@ var getFileDataURL = (file) => new Promise((resolve, reject) => {
5086
5087
  });
5087
5088
 
5088
5089
  // src/runtimes/attachment/SimpleTextAttachmentAdapter.ts
5089
- var SimpleTextAttachmentAdapter = (_class18 = class {constructor() { _class18.prototype.__init40.call(this); }
5090
- __init40() {this.accept = "text/plain,text/html,text/markdown,text/csv,text/xml,text/json,text/css"}
5090
+ var SimpleTextAttachmentAdapter = (_class17 = class {constructor() { _class17.prototype.__init41.call(this); }
5091
+ __init41() {this.accept = "text/plain,text/html,text/markdown,text/csv,text/xml,text/json,text/css"}
5091
5092
  async add(state) {
5092
5093
  return {
5093
5094
  id: state.file.name,
@@ -5114,7 +5115,7 @@ ${await getFileText(attachment.file)}
5114
5115
  }
5115
5116
  async remove() {
5116
5117
  }
5117
- }, _class18);
5118
+ }, _class17);
5118
5119
  var getFileText = (file) => new Promise((resolve, reject) => {
5119
5120
  const reader = new FileReader();
5120
5121
  reader.onload = () => resolve(reader.result);
@@ -5215,7 +5216,7 @@ var ThreadConfigProvider = ({
5215
5216
  }) => {
5216
5217
  const hasAssistant = !!useAssistantRuntime({ optional: true });
5217
5218
  const configProvider = config && Object.keys(_nullishCoalesce(config, () => ( {}))).length > 0 ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ThreadConfigContext.Provider, { value: config, children }) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _jsxruntime.Fragment, { children });
5218
- if (!_optionalChain([config, 'optionalAccess', _266 => _266.runtime])) return configProvider;
5219
+ if (!_optionalChain([config, 'optionalAccess', _265 => _265.runtime])) return configProvider;
5219
5220
  if (hasAssistant) {
5220
5221
  throw new Error(
5221
5222
  "You provided a runtime to <Thread> while simulataneously using <AssistantRuntimeProvider>. This is not allowed."
@@ -5543,7 +5544,7 @@ var AssistantMessageContent = _react.forwardRef.call(void 0, ({ components: comp
5543
5544
  {
5544
5545
  components: {
5545
5546
  ...componentsProp,
5546
- Text: _nullishCoalesce(_nullishCoalesce(_optionalChain([componentsProp, 'optionalAccess', _267 => _267.Text]), () => ( components.Text)), () => ( content_part_default.Text)),
5547
+ Text: _nullishCoalesce(_nullishCoalesce(_optionalChain([componentsProp, 'optionalAccess', _266 => _266.Text]), () => ( components.Text)), () => ( content_part_default.Text)),
5547
5548
  tools: toolsComponents
5548
5549
  }
5549
5550
  }
@@ -5654,7 +5655,7 @@ var useAttachmentSrc = () => {
5654
5655
  const { file, src } = useAttachment((a) => {
5655
5656
  if (a.type !== "image") return {};
5656
5657
  if (a.file) return { file: a.file };
5657
- const src2 = _optionalChain([a, 'access', _268 => _268.content, 'optionalAccess', _269 => _269.filter, 'call', _270 => _270((c) => c.type === "image"), 'access', _271 => _271[0], 'optionalAccess', _272 => _272.image]);
5658
+ const src2 = _optionalChain([a, 'access', _267 => _267.content, 'optionalAccess', _268 => _268.filter, 'call', _269 => _269((c) => c.type === "image"), 'access', _270 => _270[0], 'optionalAccess', _271 => _271.image]);
5658
5659
  if (!src2) return {};
5659
5660
  return { src: src2 };
5660
5661
  });
@@ -5798,7 +5799,7 @@ var ComposerAttachments = ({ components }) => {
5798
5799
  {
5799
5800
  components: {
5800
5801
  ...components,
5801
- Attachment: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _273 => _273.Attachment]), () => ( attachment_default))
5802
+ Attachment: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _272 => _272.Attachment]), () => ( attachment_default))
5802
5803
  }
5803
5804
  }
5804
5805
  ) });
@@ -5926,7 +5927,7 @@ var ThreadWelcomeSuggestions = () => {
5926
5927
  const suggestions2 = useThread((t) => t.suggestions);
5927
5928
  const { welcome: { suggestions } = {} } = useThreadConfig();
5928
5929
  const finalSuggestions = suggestions2.length ? suggestions2 : suggestions;
5929
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ThreadWelcomeSuggestionContainer, { children: _optionalChain([finalSuggestions, 'optionalAccess', _274 => _274.map, 'call', _275 => _275((suggestion, idx) => {
5930
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ThreadWelcomeSuggestionContainer, { children: _optionalChain([finalSuggestions, 'optionalAccess', _273 => _273.map, 'call', _274 => _274((suggestion, idx) => {
5930
5931
  const key = `${suggestion.prompt}-${idx}`;
5931
5932
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ThreadWelcomeSuggestion, { suggestion }, key);
5932
5933
  })]) });
@@ -6004,7 +6005,7 @@ var UserMessageContent = _react.forwardRef.call(void 0, ({ components, ...props
6004
6005
  {
6005
6006
  components: {
6006
6007
  ...components,
6007
- Text: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _276 => _276.Text]), () => ( content_part_default.Text))
6008
+ Text: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _275 => _275.Text]), () => ( content_part_default.Text))
6008
6009
  }
6009
6010
  }
6010
6011
  ) });
@@ -6021,7 +6022,7 @@ var UserMessageAttachments = ({
6021
6022
  {
6022
6023
  components: {
6023
6024
  ...components,
6024
- Attachment: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _277 => _277.Attachment]), () => ( attachment_default))
6025
+ Attachment: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _276 => _276.Attachment]), () => ( attachment_default))
6025
6026
  }
6026
6027
  }
6027
6028
  ) }) });
@@ -6124,10 +6125,10 @@ var ThreadMessages = ({ components, unstable_flexGrowDiv: flexGrowDiv = true, ..
6124
6125
  thread_exports.Messages,
6125
6126
  {
6126
6127
  components: {
6127
- UserMessage: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _278 => _278.UserMessage]), () => ( user_message_default)),
6128
- EditComposer: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _279 => _279.EditComposer]), () => ( edit_composer_default)),
6129
- AssistantMessage: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _280 => _280.AssistantMessage]), () => ( assistant_message_default)),
6130
- SystemMessage: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _281 => _281.SystemMessage]), () => ( SystemMessage))
6128
+ UserMessage: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _277 => _277.UserMessage]), () => ( user_message_default)),
6129
+ EditComposer: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _278 => _278.EditComposer]), () => ( edit_composer_default)),
6130
+ AssistantMessage: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _279 => _279.AssistantMessage]), () => ( assistant_message_default)),
6131
+ SystemMessage: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _280 => _280.SystemMessage]), () => ( SystemMessage))
6131
6132
  },
6132
6133
  ...rest
6133
6134
  }
@@ -6138,7 +6139,7 @@ var ThreadMessages = ({ components, unstable_flexGrowDiv: flexGrowDiv = true, ..
6138
6139
  ThreadMessages.displayName = "ThreadMessages";
6139
6140
  var ThreadFollowupSuggestions = () => {
6140
6141
  const suggestions = useThread((t) => t.suggestions);
6141
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, thread_exports.If, { empty: false, running: false, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "aui-thread-followup-suggestions", children: _optionalChain([suggestions, 'optionalAccess', _282 => _282.map, 'call', _283 => _283((suggestion, idx) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
6142
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, thread_exports.If, { empty: false, running: false, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "aui-thread-followup-suggestions", children: _optionalChain([suggestions, 'optionalAccess', _281 => _281.map, 'call', _282 => _282((suggestion, idx) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
6142
6143
  thread_exports.Suggestion,
6143
6144
  {
6144
6145
  className: "aui-thread-followup-suggestion",