@assistant-ui/react 0.5.77 → 0.5.78

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,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 {
@@ -4134,8 +4117,8 @@ var DefaultEditComposerRuntimeCore = class extends BaseComposerRuntimeCore {
4134
4117
  };
4135
4118
 
4136
4119
  // 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);
4120
+ var BaseThreadRuntimeCore = (_class12 = class {
4121
+ 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
4122
  this.configProvider = configProvider;
4140
4123
  }
4141
4124
  __init23() {this._subscriptions = /* @__PURE__ */ new Set()}
@@ -4162,18 +4145,23 @@ var BaseThreadRuntimeCore = (_class13 = class {
4162
4145
  this.repository.getMessage(messageId)
4163
4146
  )
4164
4147
  );
4165
- this.notifySubscribers();
4148
+ this._notifySubscribers();
4166
4149
  }
4167
4150
  getBranches(messageId) {
4168
4151
  return this.repository.getBranches(messageId);
4169
4152
  }
4170
4153
  switchToBranch(branchId) {
4171
4154
  this.repository.switchToBranch(branchId);
4172
- this.notifySubscribers();
4155
+ this._notifySubscribers();
4173
4156
  }
4174
- notifySubscribers() {
4157
+ _notifySubscribers() {
4175
4158
  for (const callback of this._subscriptions) callback();
4176
4159
  }
4160
+ _notifyEventSubscribers(event) {
4161
+ const subscribers = this._eventSubscribers.get(event);
4162
+ if (!subscribers) return;
4163
+ for (const callback of subscribers) callback();
4164
+ }
4177
4165
  subscribe(callback) {
4178
4166
  this._subscriptions.add(callback);
4179
4167
  return () => this._subscriptions.delete(callback);
@@ -4188,7 +4176,7 @@ var BaseThreadRuntimeCore = (_class13 = class {
4188
4176
  const { message } = this.repository.getMessage(messageId);
4189
4177
  adapter.submit({ message, type });
4190
4178
  this._submittedFeedback[messageId] = { type };
4191
- this.notifySubscribers();
4179
+ this._notifySubscribers();
4192
4180
  }
4193
4181
 
4194
4182
 
@@ -4205,10 +4193,10 @@ var BaseThreadRuntimeCore = (_class13 = class {
4205
4193
  } else {
4206
4194
  this.speech = { messageId, status: utterance.status };
4207
4195
  }
4208
- this.notifySubscribers();
4196
+ this._notifySubscribers();
4209
4197
  });
4210
4198
  this.speech = { messageId, status: utterance.status };
4211
- this.notifySubscribers();
4199
+ this._notifySubscribers();
4212
4200
  this._stopSpeaking = () => {
4213
4201
  utterance.cancel();
4214
4202
  unsub();
@@ -4219,21 +4207,34 @@ var BaseThreadRuntimeCore = (_class13 = class {
4219
4207
  stopSpeaking() {
4220
4208
  if (!this._stopSpeaking) throw new Error("No message is being spoken");
4221
4209
  this._stopSpeaking();
4222
- this.notifySubscribers();
4210
+ this._notifySubscribers();
4223
4211
  }
4224
4212
  export() {
4225
4213
  return this.repository.export();
4226
4214
  }
4227
4215
  import(data) {
4228
4216
  this.repository.import(data);
4229
- this.notifySubscribers();
4217
+ this._notifySubscribers();
4230
4218
  }
4231
- }, _class13);
4219
+ __init28() {this._eventSubscribers = /* @__PURE__ */ new Map()}
4220
+ unstable_on(event, callback) {
4221
+ const subscribers = this._eventSubscribers.get(event);
4222
+ if (!subscribers) {
4223
+ this._eventSubscribers.set(event, /* @__PURE__ */ new Set([callback]));
4224
+ } else {
4225
+ subscribers.add(callback);
4226
+ }
4227
+ return () => {
4228
+ const subscribers2 = this._eventSubscribers.get(event);
4229
+ subscribers2.delete(callback);
4230
+ };
4231
+ }
4232
+ }, _class12);
4232
4233
 
4233
4234
  // src/runtimes/local/LocalThreadRuntimeCore.tsx
4234
- var LocalThreadRuntimeCore = (_class14 = class extends BaseThreadRuntimeCore {
4235
+ var LocalThreadRuntimeCore = (_class13 = class extends BaseThreadRuntimeCore {
4235
4236
  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);;
4237
+ super(configProvider);_class13.prototype.__init29.call(this);_class13.prototype.__init30.call(this);_class13.prototype.__init31.call(this);_class13.prototype.__init32.call(this);;
4237
4238
  this.adapter = adapter;
4238
4239
  this.threadId = generateId();
4239
4240
  this.options = options;
@@ -4246,7 +4247,7 @@ var LocalThreadRuntimeCore = (_class14 = class extends BaseThreadRuntimeCore {
4246
4247
  }
4247
4248
  }
4248
4249
  }
4249
- __init28() {this.capabilities = {
4250
+ __init29() {this.capabilities = {
4250
4251
  switchToBranch: true,
4251
4252
  edit: true,
4252
4253
  reload: true,
@@ -4256,10 +4257,10 @@ var LocalThreadRuntimeCore = (_class14 = class extends BaseThreadRuntimeCore {
4256
4257
  attachments: false,
4257
4258
  feedback: false
4258
4259
  }}
4259
- __init29() {this.abortController = null}
4260
+ __init30() {this.abortController = null}
4260
4261
 
4261
- __init30() {this.isDisabled = false}
4262
- __init31() {this.suggestions = []}
4262
+ __init31() {this.isDisabled = false}
4263
+ __init32() {this.suggestions = []}
4263
4264
  get adapters() {
4264
4265
  return this.options.adapters;
4265
4266
  }
@@ -4288,7 +4289,7 @@ var LocalThreadRuntimeCore = (_class14 = class extends BaseThreadRuntimeCore {
4288
4289
  this.capabilities.feedback = canFeedback;
4289
4290
  hasUpdates = true;
4290
4291
  }
4291
- if (hasUpdates) this.notifySubscribers();
4292
+ if (hasUpdates) this._notifySubscribers();
4292
4293
  }
4293
4294
  async append(message) {
4294
4295
  const newMessage = fromCoreMessage(message, {
@@ -4299,7 +4300,7 @@ var LocalThreadRuntimeCore = (_class14 = class extends BaseThreadRuntimeCore {
4299
4300
  await this.startRun(newMessage.id);
4300
4301
  } else {
4301
4302
  this.repository.resetHead(newMessage.id);
4302
- this.notifySubscribers();
4303
+ this._notifySubscribers();
4303
4304
  }
4304
4305
  }
4305
4306
  async startRun(parentId) {
@@ -4312,6 +4313,7 @@ var LocalThreadRuntimeCore = (_class14 = class extends BaseThreadRuntimeCore {
4312
4313
  content: [],
4313
4314
  createdAt: /* @__PURE__ */ new Date()
4314
4315
  };
4316
+ this._notifyEventSubscribers("run-start");
4315
4317
  do {
4316
4318
  message = await this.performRoundtrip(parentId, message);
4317
4319
  } while (shouldContinue(message));
@@ -4343,7 +4345,7 @@ var LocalThreadRuntimeCore = (_class14 = class extends BaseThreadRuntimeCore {
4343
4345
  } : void 0
4344
4346
  };
4345
4347
  this.repository.addOrUpdateMessage(parentId, message);
4346
- this.notifySubscribers();
4348
+ this._notifySubscribers();
4347
4349
  };
4348
4350
  const maxSteps = this.options.maxSteps ? this.options.maxSteps : (_nullishCoalesce(this.options.maxToolRoundtrips, () => ( 1))) + 1;
4349
4351
  const steps = _nullishCoalesce(_optionalChain([message, 'access', _223 => _223.metadata, 'optionalAccess', _224 => _224.steps, 'optionalAccess', _225 => _225.length]), () => ( 0));
@@ -4434,7 +4436,7 @@ var LocalThreadRuntimeCore = (_class14 = class extends BaseThreadRuntimeCore {
4434
4436
  this.performRoundtrip(parentId, message);
4435
4437
  }
4436
4438
  }
4437
- }, _class14);
4439
+ }, _class13);
4438
4440
 
4439
4441
  // src/runtimes/local/LocalRuntimeCore.tsx
4440
4442
  var LocalRuntimeCore = class extends BaseAssistantRuntimeCore {
@@ -4454,6 +4456,7 @@ var LocalRuntimeCore = class extends BaseAssistantRuntimeCore {
4454
4456
  this.thread.adapter,
4455
4457
  options
4456
4458
  );
4459
+ this.thread._notifyEventSubscribers("switched-to");
4457
4460
  }
4458
4461
  switchToThread(threadId) {
4459
4462
  if (threadId !== null) {
@@ -4511,8 +4514,8 @@ var getExternalStoreMessage = (message) => {
4511
4514
  };
4512
4515
 
4513
4516
  // src/runtimes/external-store/ThreadMessageConverter.ts
4514
- var ThreadMessageConverter = (_class15 = class {constructor() { _class15.prototype.__init32.call(this); }
4515
- __init32() {this.cache = /* @__PURE__ */ new WeakMap()}
4517
+ var ThreadMessageConverter = (_class14 = class {constructor() { _class14.prototype.__init33.call(this); }
4518
+ __init33() {this.cache = /* @__PURE__ */ new WeakMap()}
4516
4519
  convertMessages(messages2, converter) {
4517
4520
  return messages2.map((m, idx) => {
4518
4521
  const cached = this.cache.get(m);
@@ -4521,7 +4524,7 @@ var ThreadMessageConverter = (_class15 = class {constructor() { _class15.prototy
4521
4524
  return newMessage;
4522
4525
  });
4523
4526
  }
4524
- }, _class15);
4527
+ }, _class14);
4525
4528
 
4526
4529
  // src/runtimes/external-store/auto-status.tsx
4527
4530
  var AUTO_STATUS_RUNNING = Object.freeze({ type: "running" });
@@ -4611,9 +4614,9 @@ var EMPTY_ARRAY2 = Object.freeze([]);
4611
4614
  var hasUpcomingMessage = (isRunning, messages2) => {
4612
4615
  return isRunning && _optionalChain([messages2, 'access', _231 => _231[messages2.length - 1], 'optionalAccess', _232 => _232.role]) !== "assistant";
4613
4616
  };
4614
- var ExternalStoreThreadRuntimeCore = (_class16 = class extends BaseThreadRuntimeCore {
4615
- __init33() {this.assistantOptimisticId = null}
4616
- __init34() {this._capabilities = {
4617
+ var ExternalStoreThreadRuntimeCore = (_class15 = class extends BaseThreadRuntimeCore {
4618
+ __init34() {this.assistantOptimisticId = null}
4619
+ __init35() {this._capabilities = {
4617
4620
  switchToBranch: false,
4618
4621
  edit: false,
4619
4622
  reload: false,
@@ -4635,9 +4638,9 @@ var ExternalStoreThreadRuntimeCore = (_class16 = class extends BaseThreadRuntime
4635
4638
  get adapters() {
4636
4639
  return this._store.adapters;
4637
4640
  }
4638
- __init35() {this.suggestions = []}
4639
- __init36() {this.extras = void 0}
4640
- __init37() {this._converter = new ThreadMessageConverter()}
4641
+ __init36() {this.suggestions = []}
4642
+ __init37() {this.extras = void 0}
4643
+ __init38() {this._converter = new ThreadMessageConverter()}
4641
4644
 
4642
4645
  beginEdit(messageId) {
4643
4646
  if (!this.store.onEdit)
@@ -4645,7 +4648,7 @@ var ExternalStoreThreadRuntimeCore = (_class16 = class extends BaseThreadRuntime
4645
4648
  super.beginEdit(messageId);
4646
4649
  }
4647
4650
  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);;
4651
+ 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
4652
  this.store = store;
4650
4653
  }
4651
4654
  get store() {
@@ -4675,7 +4678,7 @@ var ExternalStoreThreadRuntimeCore = (_class16 = class extends BaseThreadRuntime
4675
4678
  if (oldStore.convertMessage !== store.convertMessage) {
4676
4679
  this._converter = new ThreadMessageConverter();
4677
4680
  } else if (oldStore.isRunning === store.isRunning && oldStore.messages === store.messages) {
4678
- this.notifySubscribers();
4681
+ this._notifySubscribers();
4679
4682
  return;
4680
4683
  }
4681
4684
  }
@@ -4715,7 +4718,7 @@ var ExternalStoreThreadRuntimeCore = (_class16 = class extends BaseThreadRuntime
4715
4718
  _nullishCoalesce(_nullishCoalesce(this.assistantOptimisticId, () => ( _optionalChain([messages2, 'access', _252 => _252.at, 'call', _253 => _253(-1), 'optionalAccess', _254 => _254.id]))), () => ( null))
4716
4719
  );
4717
4720
  this._messages = this.repository.getMessages();
4718
- this.notifySubscribers();
4721
+ this._notifySubscribers();
4719
4722
  }
4720
4723
  switchToBranch(branchId) {
4721
4724
  if (!this._store.setMessages)
@@ -4754,7 +4757,7 @@ var ExternalStoreThreadRuntimeCore = (_class16 = class extends BaseThreadRuntime
4754
4757
  }
4755
4758
  messages2 = this.repository.getMessages();
4756
4759
  } else {
4757
- this.notifySubscribers();
4760
+ this._notifySubscribers();
4758
4761
  }
4759
4762
  setTimeout(() => {
4760
4763
  this.updateMessages(messages2);
@@ -4765,12 +4768,12 @@ var ExternalStoreThreadRuntimeCore = (_class16 = class extends BaseThreadRuntime
4765
4768
  throw new Error("Runtime does not support tool results.");
4766
4769
  this._store.onAddToolResult(options);
4767
4770
  }
4768
- __init38() {this.updateMessages = (messages2) => {
4771
+ __init39() {this.updateMessages = (messages2) => {
4769
4772
  _optionalChain([this, 'access', _263 => _263._store, 'access', _264 => _264.setMessages, 'optionalCall', _265 => _265(
4770
4773
  messages2.flatMap(getExternalStoreMessage).filter((m) => m != null)
4771
4774
  )]);
4772
4775
  }}
4773
- }, _class16);
4776
+ }, _class15);
4774
4777
 
4775
4778
  // src/runtimes/external-store/ExternalStoreRuntimeCore.tsx
4776
4779
  var ExternalStoreRuntimeCore = class extends BaseAssistantRuntimeCore {
@@ -4797,6 +4800,7 @@ var ExternalStoreRuntimeCore = class extends BaseAssistantRuntimeCore {
4797
4800
  }
4798
4801
  );
4799
4802
  await this.thread.store.onSwitchToNewThread();
4803
+ this.thread._notifyEventSubscribers("switched-to");
4800
4804
  }
4801
4805
  async switchToThread(threadId) {
4802
4806
  if (threadId !== null) {
@@ -4810,7 +4814,8 @@ var ExternalStoreRuntimeCore = class extends BaseAssistantRuntimeCore {
4810
4814
  // ignore messages until rerender
4811
4815
  }
4812
4816
  );
4813
- this.thread.store.onSwitchToThread(threadId);
4817
+ await this.thread.store.onSwitchToThread(threadId);
4818
+ this.thread._notifyEventSubscribers("switched-to");
4814
4819
  } else {
4815
4820
  this.switchToNewThread();
4816
4821
  }
@@ -5051,8 +5056,8 @@ var WebSpeechSynthesisAdapter = class {
5051
5056
  };
5052
5057
 
5053
5058
  // src/runtimes/attachment/SimpleImageAttachmentAdapter.ts
5054
- var SimpleImageAttachmentAdapter = (_class17 = class {constructor() { _class17.prototype.__init39.call(this); }
5055
- __init39() {this.accept = "image/*"}
5059
+ var SimpleImageAttachmentAdapter = (_class16 = class {constructor() { _class16.prototype.__init40.call(this); }
5060
+ __init40() {this.accept = "image/*"}
5056
5061
  async add(state) {
5057
5062
  return {
5058
5063
  id: state.file.name,
@@ -5077,7 +5082,7 @@ var SimpleImageAttachmentAdapter = (_class17 = class {constructor() { _class17.p
5077
5082
  }
5078
5083
  async remove() {
5079
5084
  }
5080
- }, _class17);
5085
+ }, _class16);
5081
5086
  var getFileDataURL = (file) => new Promise((resolve, reject) => {
5082
5087
  const reader = new FileReader();
5083
5088
  reader.onload = () => resolve(reader.result);
@@ -5086,8 +5091,8 @@ var getFileDataURL = (file) => new Promise((resolve, reject) => {
5086
5091
  });
5087
5092
 
5088
5093
  // 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"}
5094
+ var SimpleTextAttachmentAdapter = (_class17 = class {constructor() { _class17.prototype.__init41.call(this); }
5095
+ __init41() {this.accept = "text/plain,text/html,text/markdown,text/csv,text/xml,text/json,text/css"}
5091
5096
  async add(state) {
5092
5097
  return {
5093
5098
  id: state.file.name,
@@ -5114,7 +5119,7 @@ ${await getFileText(attachment.file)}
5114
5119
  }
5115
5120
  async remove() {
5116
5121
  }
5117
- }, _class18);
5122
+ }, _class17);
5118
5123
  var getFileText = (file) => new Promise((resolve, reject) => {
5119
5124
  const reader = new FileReader();
5120
5125
  reader.onload = () => resolve(reader.result);