@assistant-ui/react 0.5.74 → 0.5.75

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
@@ -604,20 +604,13 @@ var useActionBarReload = () => {
604
604
  // src/primitive-hooks/actionBar/useActionBarSpeak.tsx
605
605
 
606
606
  var useActionBarSpeak = () => {
607
- const messageStore = useMessageStore();
608
- const editComposerStore = useEditComposerStore();
609
607
  const messageRunime = useMessageRuntime();
610
- const messageUtilsStore = useMessageUtilsStore();
611
- const hasSpeakableContent = useCombinedStore(
612
- [messageStore, editComposerStore],
613
- (message, c) => {
614
- return !c.isEditing && (message.role !== "assistant" || message.status.type !== "running") && message.content.some((c2) => c2.type === "text" && c2.text.length > 0);
615
- }
616
- );
617
608
  const callback = _react.useCallback.call(void 0, async () => {
618
- const utt = messageRunime.speak();
619
- messageUtilsStore.getState().addUtterance(utt);
620
- }, [messageRunime, messageUtilsStore]);
609
+ messageRunime.speak();
610
+ }, [messageRunime]);
611
+ const hasSpeakableContent = useMessage((m) => {
612
+ return (m.role !== "assistant" || m.status.type !== "running") && m.content.some((c) => c.type === "text" && c.text.length > 0);
613
+ });
621
614
  if (!hasSpeakableContent) return null;
622
615
  return callback;
623
616
  };
@@ -625,11 +618,11 @@ var useActionBarSpeak = () => {
625
618
  // src/primitive-hooks/actionBar/useActionBarStopSpeaking.tsx
626
619
 
627
620
  var useActionBarStopSpeaking = () => {
628
- const messageUtilsStore = useMessageUtilsStore();
629
- const isSpeaking = useMessageUtils((u) => u.isSpeaking);
621
+ const messageRuntime = useMessageRuntime();
622
+ const isSpeaking = useMessage((u) => u.speech != null);
630
623
  const callback = _react.useCallback.call(void 0, async () => {
631
- messageUtilsStore.getState().stopSpeaking();
632
- }, [messageUtilsStore]);
624
+ messageRuntime.stopSpeaking();
625
+ }, [messageRuntime]);
633
626
  if (!isSpeaking) return null;
634
627
  return callback;
635
628
  };
@@ -809,7 +802,7 @@ var useMessageIf = (props) => {
809
802
  const messageUtilsStore = useMessageUtilsStore();
810
803
  return useCombinedStore(
811
804
  [messageStore, messageUtilsStore],
812
- ({ role, attachments, branchCount, isLast }, { isCopied, isHovering, isSpeaking, submittedFeedback }) => {
805
+ ({ role, attachments, branchCount, isLast, speech }, { isCopied, isHovering, submittedFeedback }) => {
813
806
  if (props.hasBranches === true && branchCount < 2) return false;
814
807
  if (props.user && role !== "user") return false;
815
808
  if (props.assistant && role !== "assistant") return false;
@@ -817,8 +810,8 @@ var useMessageIf = (props) => {
817
810
  if (props.lastOrHover === true && !isHovering && !isLast) return false;
818
811
  if (props.copied === true && !isCopied) return false;
819
812
  if (props.copied === false && isCopied) return false;
820
- if (props.speaking === true && !isSpeaking) return false;
821
- if (props.speaking === false && isSpeaking) return false;
813
+ if (props.speaking === true && speech == null) return false;
814
+ if (props.speaking === false && speech != null) return false;
822
815
  if (props.hasAttachments === true && (role !== "user" || !attachments.length))
823
816
  return false;
824
817
  if (props.hasAttachments === false && role === "user" && !!attachments.length)
@@ -1347,7 +1340,7 @@ _chunkPZ5AY32Cjs.__export.call(void 0, branchPicker_exports, {
1347
1340
  Count: () => BranchPickerPrimitiveCount,
1348
1341
  Next: () => BranchPickerPrimitiveNext,
1349
1342
  Number: () => BranchPickerPrimitiveNumber,
1350
- Previous: () => BranchPickerPrevious,
1343
+ Previous: () => BranchPickerPrimitivePrevious,
1351
1344
  Root: () => BranchPickerPrimitiveRoot
1352
1345
  });
1353
1346
 
@@ -1358,7 +1351,7 @@ var BranchPickerPrimitiveNext = createActionButton(
1358
1351
  );
1359
1352
 
1360
1353
  // src/primitives/branchPicker/BranchPickerPrevious.tsx
1361
- var BranchPickerPrevious = createActionButton(
1354
+ var BranchPickerPrimitivePrevious = createActionButton(
1362
1355
  "BranchPickerPrimitive.Previous",
1363
1356
  useBranchPickerPrevious
1364
1357
  );
@@ -2172,6 +2165,16 @@ var MessageRuntimeImpl = (_class6 = class {
2172
2165
  if (!state) throw new Error("Message is not available");
2173
2166
  return this._threadBinding.getState().speak(state.id);
2174
2167
  }
2168
+ stopSpeaking() {
2169
+ const state = this._core.getState();
2170
+ if (!state) throw new Error("Message is not available");
2171
+ const thread = this._threadBinding.getState();
2172
+ if (_optionalChain([thread, 'access', _79 => _79.speech, 'optionalAccess', _80 => _80.messageId]) === state.id) {
2173
+ this._threadBinding.getState().stopSpeaking();
2174
+ } else {
2175
+ throw new Error("Message is not being spoken");
2176
+ }
2177
+ }
2175
2178
  submitFeedback({ type }) {
2176
2179
  const state = this._core.getState();
2177
2180
  if (!state) throw new Error("Message is not available");
@@ -2223,7 +2226,7 @@ var MessageRuntimeImpl = (_class6 = class {
2223
2226
  new ShallowMemoizeSubject({
2224
2227
  getState: () => {
2225
2228
  const attachments = this.getState().attachments;
2226
- const attachment = _optionalChain([attachments, 'optionalAccess', _79 => _79[idx]]);
2229
+ const attachment = _optionalChain([attachments, 'optionalAccess', _81 => _81[idx]]);
2227
2230
  if (!attachment) return SKIP_UPDATE;
2228
2231
  return {
2229
2232
  ...attachment,
@@ -2312,7 +2315,7 @@ var MessageContentPartImpl = ({
2312
2315
  };
2313
2316
  var MessageContentPart = _react.memo.call(void 0,
2314
2317
  MessageContentPartImpl,
2315
- (prev, next) => prev.partIndex === next.partIndex && _optionalChain([prev, 'access', _80 => _80.components, 'optionalAccess', _81 => _81.Text]) === _optionalChain([next, 'access', _82 => _82.components, 'optionalAccess', _83 => _83.Text]) && _optionalChain([prev, 'access', _84 => _84.components, 'optionalAccess', _85 => _85.Image]) === _optionalChain([next, 'access', _86 => _86.components, 'optionalAccess', _87 => _87.Image]) && _optionalChain([prev, 'access', _88 => _88.components, 'optionalAccess', _89 => _89.UI]) === _optionalChain([next, 'access', _90 => _90.components, 'optionalAccess', _91 => _91.UI]) && _optionalChain([prev, 'access', _92 => _92.components, 'optionalAccess', _93 => _93.tools]) === _optionalChain([next, 'access', _94 => _94.components, 'optionalAccess', _95 => _95.tools])
2318
+ (prev, next) => prev.partIndex === next.partIndex && _optionalChain([prev, 'access', _82 => _82.components, 'optionalAccess', _83 => _83.Text]) === _optionalChain([next, 'access', _84 => _84.components, 'optionalAccess', _85 => _85.Text]) && _optionalChain([prev, 'access', _86 => _86.components, 'optionalAccess', _87 => _87.Image]) === _optionalChain([next, 'access', _88 => _88.components, 'optionalAccess', _89 => _89.Image]) && _optionalChain([prev, 'access', _90 => _90.components, 'optionalAccess', _91 => _91.UI]) === _optionalChain([next, 'access', _92 => _92.components, 'optionalAccess', _93 => _93.UI]) && _optionalChain([prev, 'access', _94 => _94.components, 'optionalAccess', _95 => _95.tools]) === _optionalChain([next, 'access', _96 => _96.components, 'optionalAccess', _97 => _97.tools])
2316
2319
  );
2317
2320
  var MessagePrimitiveContent = ({
2318
2321
  components
@@ -2378,11 +2381,11 @@ var getComponent = (components, attachment) => {
2378
2381
  const type = attachment.type;
2379
2382
  switch (type) {
2380
2383
  case "image":
2381
- return _nullishCoalesce(_optionalChain([components, 'optionalAccess', _96 => _96.Image]), () => ( _optionalChain([components, 'optionalAccess', _97 => _97.Attachment])));
2384
+ return _nullishCoalesce(_optionalChain([components, 'optionalAccess', _98 => _98.Image]), () => ( _optionalChain([components, 'optionalAccess', _99 => _99.Attachment])));
2382
2385
  case "document":
2383
- return _nullishCoalesce(_optionalChain([components, 'optionalAccess', _98 => _98.Document]), () => ( _optionalChain([components, 'optionalAccess', _99 => _99.Attachment])));
2386
+ return _nullishCoalesce(_optionalChain([components, 'optionalAccess', _100 => _100.Document]), () => ( _optionalChain([components, 'optionalAccess', _101 => _101.Attachment])));
2384
2387
  case "file":
2385
- return _nullishCoalesce(_optionalChain([components, 'optionalAccess', _100 => _100.File]), () => ( _optionalChain([components, 'optionalAccess', _101 => _101.Attachment])));
2388
+ return _nullishCoalesce(_optionalChain([components, 'optionalAccess', _102 => _102.File]), () => ( _optionalChain([components, 'optionalAccess', _103 => _103.Attachment])));
2386
2389
  default:
2387
2390
  const _exhaustiveCheck = type;
2388
2391
  throw new Error(`Unknown attachment type: ${_exhaustiveCheck}`);
@@ -2405,7 +2408,7 @@ var MessageAttachmentImpl = ({ components, attachmentIndex }) => {
2405
2408
  };
2406
2409
  var MessageAttachment = _react.memo.call(void 0,
2407
2410
  MessageAttachmentImpl,
2408
- (prev, next) => prev.attachmentIndex === next.attachmentIndex && _optionalChain([prev, 'access', _102 => _102.components, 'optionalAccess', _103 => _103.Image]) === _optionalChain([next, 'access', _104 => _104.components, 'optionalAccess', _105 => _105.Image]) && _optionalChain([prev, 'access', _106 => _106.components, 'optionalAccess', _107 => _107.Document]) === _optionalChain([next, 'access', _108 => _108.components, 'optionalAccess', _109 => _109.Document]) && _optionalChain([prev, 'access', _110 => _110.components, 'optionalAccess', _111 => _111.File]) === _optionalChain([next, 'access', _112 => _112.components, 'optionalAccess', _113 => _113.File]) && _optionalChain([prev, 'access', _114 => _114.components, 'optionalAccess', _115 => _115.Attachment]) === _optionalChain([next, 'access', _116 => _116.components, 'optionalAccess', _117 => _117.Attachment])
2411
+ (prev, next) => prev.attachmentIndex === next.attachmentIndex && _optionalChain([prev, 'access', _104 => _104.components, 'optionalAccess', _105 => _105.Image]) === _optionalChain([next, 'access', _106 => _106.components, 'optionalAccess', _107 => _107.Image]) && _optionalChain([prev, 'access', _108 => _108.components, 'optionalAccess', _109 => _109.Document]) === _optionalChain([next, 'access', _110 => _110.components, 'optionalAccess', _111 => _111.Document]) && _optionalChain([prev, 'access', _112 => _112.components, 'optionalAccess', _113 => _113.File]) === _optionalChain([next, 'access', _114 => _114.components, 'optionalAccess', _115 => _115.File]) && _optionalChain([prev, 'access', _116 => _116.components, 'optionalAccess', _117 => _117.Attachment]) === _optionalChain([next, 'access', _118 => _118.components, 'optionalAccess', _119 => _119.Attachment])
2409
2412
  );
2410
2413
  var MessagePrimitiveAttachments = ({ components }) => {
2411
2414
  const attachmentsCount = useMessage(({ message }) => {
@@ -2516,7 +2519,7 @@ var ComposerPrimitiveInput = _react.forwardRef.call(void 0,
2516
2519
  const { isRunning } = threadStore.getState();
2517
2520
  if (!isRunning) {
2518
2521
  e.preventDefault();
2519
- _optionalChain([textareaRef, 'access', _118 => _118.current, 'optionalAccess', _119 => _119.closest, 'call', _120 => _120("form"), 'optionalAccess', _121 => _121.requestSubmit, 'call', _122 => _122()]);
2522
+ _optionalChain([textareaRef, 'access', _120 => _120.current, 'optionalAccess', _121 => _121.closest, 'call', _122 => _122("form"), 'optionalAccess', _123 => _123.requestSubmit, 'call', _124 => _124()]);
2520
2523
  }
2521
2524
  }
2522
2525
  };
@@ -2581,11 +2584,11 @@ var getComponent2 = (components, attachment) => {
2581
2584
  const type = attachment.type;
2582
2585
  switch (type) {
2583
2586
  case "image":
2584
- return _nullishCoalesce(_optionalChain([components, 'optionalAccess', _123 => _123.Image]), () => ( _optionalChain([components, 'optionalAccess', _124 => _124.Attachment])));
2587
+ return _nullishCoalesce(_optionalChain([components, 'optionalAccess', _125 => _125.Image]), () => ( _optionalChain([components, 'optionalAccess', _126 => _126.Attachment])));
2585
2588
  case "document":
2586
- return _nullishCoalesce(_optionalChain([components, 'optionalAccess', _125 => _125.Document]), () => ( _optionalChain([components, 'optionalAccess', _126 => _126.Attachment])));
2589
+ return _nullishCoalesce(_optionalChain([components, 'optionalAccess', _127 => _127.Document]), () => ( _optionalChain([components, 'optionalAccess', _128 => _128.Attachment])));
2587
2590
  case "file":
2588
- return _nullishCoalesce(_optionalChain([components, 'optionalAccess', _127 => _127.File]), () => ( _optionalChain([components, 'optionalAccess', _128 => _128.Attachment])));
2591
+ return _nullishCoalesce(_optionalChain([components, 'optionalAccess', _129 => _129.File]), () => ( _optionalChain([components, 'optionalAccess', _130 => _130.Attachment])));
2589
2592
  default:
2590
2593
  const _exhaustiveCheck = type;
2591
2594
  throw new Error(`Unknown attachment type: ${_exhaustiveCheck}`);
@@ -2608,7 +2611,7 @@ var ComposerAttachmentImpl = ({ components, attachmentIndex }) => {
2608
2611
  };
2609
2612
  var ComposerAttachment = _react.memo.call(void 0,
2610
2613
  ComposerAttachmentImpl,
2611
- (prev, next) => prev.attachmentIndex === next.attachmentIndex && _optionalChain([prev, 'access', _129 => _129.components, 'optionalAccess', _130 => _130.Image]) === _optionalChain([next, 'access', _131 => _131.components, 'optionalAccess', _132 => _132.Image]) && _optionalChain([prev, 'access', _133 => _133.components, 'optionalAccess', _134 => _134.Document]) === _optionalChain([next, 'access', _135 => _135.components, 'optionalAccess', _136 => _136.Document]) && _optionalChain([prev, 'access', _137 => _137.components, 'optionalAccess', _138 => _138.File]) === _optionalChain([next, 'access', _139 => _139.components, 'optionalAccess', _140 => _140.File]) && _optionalChain([prev, 'access', _141 => _141.components, 'optionalAccess', _142 => _142.Attachment]) === _optionalChain([next, 'access', _143 => _143.components, 'optionalAccess', _144 => _144.Attachment])
2614
+ (prev, next) => prev.attachmentIndex === next.attachmentIndex && _optionalChain([prev, 'access', _131 => _131.components, 'optionalAccess', _132 => _132.Image]) === _optionalChain([next, 'access', _133 => _133.components, 'optionalAccess', _134 => _134.Image]) && _optionalChain([prev, 'access', _135 => _135.components, 'optionalAccess', _136 => _136.Document]) === _optionalChain([next, 'access', _137 => _137.components, 'optionalAccess', _138 => _138.Document]) && _optionalChain([prev, 'access', _139 => _139.components, 'optionalAccess', _140 => _140.File]) === _optionalChain([next, 'access', _141 => _141.components, 'optionalAccess', _142 => _142.File]) && _optionalChain([prev, 'access', _143 => _143.components, 'optionalAccess', _144 => _144.Attachment]) === _optionalChain([next, 'access', _145 => _145.components, 'optionalAccess', _146 => _146.Attachment])
2612
2615
  );
2613
2616
  var ComposerPrimitiveAttachments = ({ components }) => {
2614
2617
  const attachmentsCount = useComposer((s) => s.attachments.length);
@@ -2816,7 +2819,6 @@ ThreadPrimitiveViewport.displayName = "ThreadPrimitive.Viewport";
2816
2819
  // src/context/stores/MessageUtils.ts
2817
2820
 
2818
2821
  var makeMessageUtilsStore = () => _zustand.create.call(void 0, (set) => {
2819
- let utterance = null;
2820
2822
  return {
2821
2823
  isCopied: false,
2822
2824
  setIsCopied: (value) => {
@@ -2826,17 +2828,6 @@ var makeMessageUtilsStore = () => _zustand.create.call(void 0, (set) => {
2826
2828
  setIsHovering: (value) => {
2827
2829
  set({ isHovering: value });
2828
2830
  },
2829
- isSpeaking: false,
2830
- stopSpeaking: () => {
2831
- _optionalChain([utterance, 'optionalAccess', _145 => _145.cancel, 'call', _146 => _146()]);
2832
- },
2833
- addUtterance: (utt) => {
2834
- utterance = utt;
2835
- set({ isSpeaking: true });
2836
- utt.onEnd(() => {
2837
- set({ isSpeaking: false });
2838
- });
2839
- },
2840
2831
  submittedFeedback: null,
2841
2832
  setSubmittedFeedback: (feedback) => {
2842
2833
  set({ submittedFeedback: feedback });
@@ -3570,7 +3561,8 @@ var getThreadState = (runtime) => {
3570
3561
  isRunning: _optionalChain([lastMessage, 'optionalAccess', _178 => _178.role]) !== "assistant" ? false : lastMessage.status.type === "running",
3571
3562
  messages: runtime.messages,
3572
3563
  suggestions: runtime.suggestions,
3573
- extras: runtime.extras
3564
+ extras: runtime.extras,
3565
+ speech: runtime.speech
3574
3566
  });
3575
3567
  };
3576
3568
  var ThreadRuntimeImpl = (_class12 = class {
@@ -3617,6 +3609,12 @@ var ThreadRuntimeImpl = (_class12 = class {
3617
3609
  get messages() {
3618
3610
  return this._threadBinding.getState().messages;
3619
3611
  }
3612
+ /**
3613
+ * @deprecated Use `getState().speechState` instead. This will be removed in 0.6.0.
3614
+ */
3615
+ get speech() {
3616
+ return this._threadBinding.getState().speech;
3617
+ }
3620
3618
  unstable_getCore() {
3621
3619
  return this._threadBinding.getState();
3622
3620
  }
@@ -3677,15 +3675,18 @@ var ThreadRuntimeImpl = (_class12 = class {
3677
3675
  switchToBranch(branchId) {
3678
3676
  return this._threadBinding.getState().switchToBranch(branchId);
3679
3677
  }
3680
- // /**
3681
- // * @deprecated Use `getMesssageById(id).speak()` instead. This will be removed in 0.6.0.
3682
- // */
3678
+ /**
3679
+ * @deprecated Use `getMesssageById(id).speak()` instead. This will be removed in 0.6.0.
3680
+ */
3683
3681
  speak(messageId) {
3684
3682
  return this._threadBinding.getState().speak(messageId);
3685
3683
  }
3686
- // /**
3687
- // * @deprecated Use `getMesssageById(id).submitFeedback({ type })` instead. This will be removed in 0.6.0.
3688
- // */
3684
+ stopSpeaking() {
3685
+ return this._threadBinding.getState().stopSpeaking();
3686
+ }
3687
+ /**
3688
+ * @deprecated Use `getMesssageById(id).submitFeedback({ type })` instead. This will be removed in 0.6.0.
3689
+ */
3689
3690
  submitFeedback(options) {
3690
3691
  return this._threadBinding.getState().submitFeedback(options);
3691
3692
  }
@@ -3712,7 +3713,7 @@ var ThreadRuntimeImpl = (_class12 = class {
3712
3713
  return new MessageRuntimeImpl(
3713
3714
  new ShallowMemoizeSubject({
3714
3715
  getState: () => {
3715
- const messages2 = this.getState().messages;
3716
+ const { messages: messages2, speech: speechState } = this.getState();
3716
3717
  const message = messages2[idx];
3717
3718
  if (!message) return SKIP_UPDATE;
3718
3719
  const branches = this._threadBinding.getState().getBranches(message.id);
@@ -3723,7 +3724,8 @@ var ThreadRuntimeImpl = (_class12 = class {
3723
3724
  parentId: _nullishCoalesce(_optionalChain([messages2, 'access', _179 => _179[idx - 1], 'optionalAccess', _180 => _180.id]), () => ( null)),
3724
3725
  branches,
3725
3726
  branchNumber: branches.indexOf(message.id) + 1,
3726
- branchCount: branches.length
3727
+ branchCount: branches.length,
3728
+ speech: _optionalChain([speechState, 'optionalAccess', _181 => _181.messageId]) === message.id ? speechState : null
3727
3729
  };
3728
3730
  },
3729
3731
  subscribe: (callback) => this._threadBinding.subscribe(callback)
@@ -3799,7 +3801,7 @@ var fromLanguageModelMessages = (lm, { mergeSteps }) => {
3799
3801
  });
3800
3802
  if (mergeSteps) {
3801
3803
  const previousMessage = messages2[messages2.length - 1];
3802
- if (_optionalChain([previousMessage, 'optionalAccess', _181 => _181.role]) === "assistant") {
3804
+ if (_optionalChain([previousMessage, 'optionalAccess', _182 => _182.role]) === "assistant") {
3803
3805
  previousMessage.content.push(...newContent);
3804
3806
  break;
3805
3807
  }
@@ -3812,7 +3814,7 @@ var fromLanguageModelMessages = (lm, { mergeSteps }) => {
3812
3814
  }
3813
3815
  case "tool": {
3814
3816
  const previousMessage = messages2[messages2.length - 1];
3815
- if (_optionalChain([previousMessage, 'optionalAccess', _182 => _182.role]) !== "assistant")
3817
+ if (_optionalChain([previousMessage, 'optionalAccess', _183 => _183.role]) !== "assistant")
3816
3818
  throw new Error(
3817
3819
  "A tool message must be preceded by an assistant message."
3818
3820
  );
@@ -3934,7 +3936,7 @@ function assistantDecoderStream() {
3934
3936
  }
3935
3937
  case "c" /* ToolCallDelta */: {
3936
3938
  const { toolCallId, argsTextDelta } = value;
3937
- if (_optionalChain([currentToolCall, 'optionalAccess', _183 => _183.id]) !== toolCallId) {
3939
+ if (_optionalChain([currentToolCall, 'optionalAccess', _184 => _184.id]) !== toolCallId) {
3938
3940
  throw new Error(
3939
3941
  `Received tool call delta for unknown tool call "${toolCallId}".`
3940
3942
  );
@@ -4081,7 +4083,7 @@ var useEdgeRuntime = (options) => {
4081
4083
  };
4082
4084
 
4083
4085
  // src/runtimes/local/shouldContinue.tsx
4084
- var shouldContinue = (result) => _optionalChain([result, 'access', _184 => _184.status, 'optionalAccess', _185 => _185.type]) === "requires-action" && result.status.reason === "tool-calls" && result.content.every((c) => c.type !== "tool-call" || !!c.result);
4086
+ var shouldContinue = (result) => _optionalChain([result, 'access', _185 => _185.status, 'optionalAccess', _186 => _186.type]) === "requires-action" && result.status.reason === "tool-calls" && result.content.every((c) => c.type !== "tool-call" || !!c.result);
4085
4087
 
4086
4088
  // src/runtimes/composer/DefaultEditComposerRuntimeCore.tsx
4087
4089
  var DefaultEditComposerRuntimeCore = class extends BaseComposerRuntimeCore {
@@ -4122,7 +4124,7 @@ var DefaultEditComposerRuntimeCore = class extends BaseComposerRuntimeCore {
4122
4124
 
4123
4125
  // src/runtimes/local/LocalThreadRuntimeCore.tsx
4124
4126
  var LocalThreadRuntimeCore = (_class13 = class {
4125
- constructor(configProvider, adapter, { initialMessages, ...options }) {;_class13.prototype.__init24.call(this);_class13.prototype.__init25.call(this);_class13.prototype.__init26.call(this);_class13.prototype.__init27.call(this);_class13.prototype.__init28.call(this);_class13.prototype.__init29.call(this);_class13.prototype.__init30.call(this);_class13.prototype.__init31.call(this);
4127
+ constructor(configProvider, adapter, { initialMessages, ...options }) {;_class13.prototype.__init24.call(this);_class13.prototype.__init25.call(this);_class13.prototype.__init26.call(this);_class13.prototype.__init27.call(this);_class13.prototype.__init28.call(this);_class13.prototype.__init29.call(this);_class13.prototype.__init30.call(this);_class13.prototype.__init31.call(this);_class13.prototype.__init32.call(this);
4126
4128
  this.configProvider = configProvider;
4127
4129
  this.adapter = adapter;
4128
4130
  this.threadId = generateId();
@@ -4169,18 +4171,18 @@ var LocalThreadRuntimeCore = (_class13 = class {
4169
4171
  set options({ initialMessages, ...options }) {
4170
4172
  this._options = options;
4171
4173
  let hasUpdates = false;
4172
- const canSpeak = _optionalChain([options, 'access', _186 => _186.adapters, 'optionalAccess', _187 => _187.speech]) !== void 0;
4174
+ const canSpeak = _optionalChain([options, 'access', _187 => _187.adapters, 'optionalAccess', _188 => _188.speech]) !== void 0;
4173
4175
  if (this.capabilities.speak !== canSpeak) {
4174
4176
  this.capabilities.speak = canSpeak;
4175
4177
  hasUpdates = true;
4176
4178
  }
4177
- this.composer.setAttachmentAdapter(_optionalChain([options, 'access', _188 => _188.adapters, 'optionalAccess', _189 => _189.attachments]));
4178
- const canAttach = _optionalChain([options, 'access', _190 => _190.adapters, 'optionalAccess', _191 => _191.attachments]) !== void 0;
4179
+ this.composer.setAttachmentAdapter(_optionalChain([options, 'access', _189 => _189.adapters, 'optionalAccess', _190 => _190.attachments]));
4180
+ const canAttach = _optionalChain([options, 'access', _191 => _191.adapters, 'optionalAccess', _192 => _192.attachments]) !== void 0;
4179
4181
  if (this.capabilities.attachments !== canAttach) {
4180
4182
  this.capabilities.attachments = canAttach;
4181
4183
  hasUpdates = true;
4182
4184
  }
4183
- const canFeedback = _optionalChain([options, 'access', _192 => _192.adapters, 'optionalAccess', _193 => _193.feedback]) !== void 0;
4185
+ const canFeedback = _optionalChain([options, 'access', _193 => _193.adapters, 'optionalAccess', _194 => _194.feedback]) !== void 0;
4184
4186
  if (this.capabilities.feedback !== canFeedback) {
4185
4187
  this.capabilities.feedback = canFeedback;
4186
4188
  hasUpdates = true;
@@ -4239,13 +4241,13 @@ var LocalThreadRuntimeCore = (_class13 = class {
4239
4241
  }
4240
4242
  async performRoundtrip(parentId, message) {
4241
4243
  const messages2 = this.repository.getMessages();
4242
- _optionalChain([this, 'access', _194 => _194.abortController, 'optionalAccess', _195 => _195.abort, 'call', _196 => _196()]);
4244
+ _optionalChain([this, 'access', _195 => _195.abortController, 'optionalAccess', _196 => _196.abort, 'call', _197 => _197()]);
4243
4245
  this.abortController = new AbortController();
4244
4246
  const initialContent = message.content;
4245
- const initialSteps = _optionalChain([message, 'access', _197 => _197.metadata, 'optionalAccess', _198 => _198.steps]);
4246
- const initalCustom = _optionalChain([message, 'access', _199 => _199.metadata, 'optionalAccess', _200 => _200.custom]);
4247
+ const initialSteps = _optionalChain([message, 'access', _198 => _198.metadata, 'optionalAccess', _199 => _199.steps]);
4248
+ const initalCustom = _optionalChain([message, 'access', _200 => _200.metadata, 'optionalAccess', _201 => _201.custom]);
4247
4249
  const updateMessage = (m) => {
4248
- const newSteps = _optionalChain([m, 'access', _201 => _201.metadata, 'optionalAccess', _202 => _202.steps]) || _optionalChain([m, 'access', _203 => _203.metadata, 'optionalAccess', _204 => _204.roundtrips]);
4250
+ const newSteps = _optionalChain([m, 'access', _202 => _202.metadata, 'optionalAccess', _203 => _203.steps]) || _optionalChain([m, 'access', _204 => _204.metadata, 'optionalAccess', _205 => _205.roundtrips]);
4249
4251
  const steps2 = newSteps ? [..._nullishCoalesce(initialSteps, () => ( [])), ...newSteps] : void 0;
4250
4252
  message = {
4251
4253
  ...message,
@@ -4257,7 +4259,7 @@ var LocalThreadRuntimeCore = (_class13 = class {
4257
4259
  metadata: {
4258
4260
  ...message.metadata,
4259
4261
  ...steps2 ? { roundtrips: steps2, steps: steps2 } : void 0,
4260
- ..._optionalChain([m, 'access', _205 => _205.metadata, 'optionalAccess', _206 => _206.custom]) ? {
4262
+ ..._optionalChain([m, 'access', _206 => _206.metadata, 'optionalAccess', _207 => _207.custom]) ? {
4261
4263
  custom: { ..._nullishCoalesce(initalCustom, () => ( {})), ...m.metadata.custom }
4262
4264
  } : void 0
4263
4265
  }
@@ -4267,7 +4269,7 @@ var LocalThreadRuntimeCore = (_class13 = class {
4267
4269
  this.notifySubscribers();
4268
4270
  };
4269
4271
  const maxSteps = this.options.maxSteps ? this.options.maxSteps : (_nullishCoalesce(this.options.maxToolRoundtrips, () => ( 1))) + 1;
4270
- const steps = _nullishCoalesce(_optionalChain([message, 'access', _207 => _207.metadata, 'optionalAccess', _208 => _208.steps, 'optionalAccess', _209 => _209.length]), () => ( 0));
4272
+ const steps = _nullishCoalesce(_optionalChain([message, 'access', _208 => _208.metadata, 'optionalAccess', _209 => _209.steps, 'optionalAccess', _210 => _210.length]), () => ( 0));
4271
4273
  if (steps >= maxSteps) {
4272
4274
  updateMessage({
4273
4275
  status: {
@@ -4363,27 +4365,38 @@ var LocalThreadRuntimeCore = (_class13 = class {
4363
4365
  this.performRoundtrip(parentId, message);
4364
4366
  }
4365
4367
  }
4366
- // TODO lift utterance state to thread runtime
4368
+ // TODO speech runtime?
4367
4369
 
4370
+ __init32() {this.speech = null}
4368
4371
  speak(messageId) {
4369
- const adapter = _optionalChain([this, 'access', _210 => _210.options, 'access', _211 => _211.adapters, 'optionalAccess', _212 => _212.speech]);
4372
+ const adapter = _optionalChain([this, 'access', _211 => _211.options, 'access', _212 => _212.adapters, 'optionalAccess', _213 => _213.speech]);
4370
4373
  if (!adapter) throw new Error("Speech adapter not configured");
4371
4374
  const { message } = this.repository.getMessage(messageId);
4372
- if (this._utterance) {
4373
- this._utterance.cancel();
4374
- this._utterance = void 0;
4375
- }
4375
+ _optionalChain([this, 'access', _214 => _214._stopSpeaking, 'optionalCall', _215 => _215()]);
4376
4376
  const utterance = adapter.speak(message);
4377
- utterance.onEnd(() => {
4378
- if (this._utterance === utterance) {
4379
- this._utterance = void 0;
4377
+ const unsub = utterance.subscribe(() => {
4378
+ if (utterance.status.type === "ended") {
4379
+ this._stopSpeaking = void 0;
4380
+ this.speech = null;
4381
+ } else {
4382
+ this.speech = { messageId, status: utterance.status };
4380
4383
  }
4384
+ this.notifySubscribers();
4381
4385
  });
4382
- this._utterance = utterance;
4383
- return this._utterance;
4386
+ this.speech = { messageId, status: utterance.status };
4387
+ this._stopSpeaking = () => {
4388
+ utterance.cancel();
4389
+ unsub();
4390
+ this.speech = null;
4391
+ this._stopSpeaking = void 0;
4392
+ };
4393
+ }
4394
+ stopSpeaking() {
4395
+ if (!this._stopSpeaking) throw new Error("No message is being spoken");
4396
+ this._stopSpeaking();
4384
4397
  }
4385
4398
  submitFeedback({ messageId, type }) {
4386
- const adapter = _optionalChain([this, 'access', _213 => _213.options, 'access', _214 => _214.adapters, 'optionalAccess', _215 => _215.feedback]);
4399
+ const adapter = _optionalChain([this, 'access', _216 => _216.options, 'access', _217 => _217.adapters, 'optionalAccess', _218 => _218.feedback]);
4387
4400
  if (!adapter) throw new Error("Feedback adapter not configured");
4388
4401
  const { message } = this.repository.getMessage(messageId);
4389
4402
  adapter.submit({ message, type });
@@ -4430,7 +4443,7 @@ var LocalRuntimeCore = class extends BaseAssistantRuntimeCore {
4430
4443
  const messages2 = fromCoreMessages(initialMessages);
4431
4444
  this.thread.import({
4432
4445
  messages: messages2.map((m, idx) => ({
4433
- parentId: _nullishCoalesce(_optionalChain([messages2, 'access', _216 => _216[idx - 1], 'optionalAccess', _217 => _217.id]), () => ( null)),
4446
+ parentId: _nullishCoalesce(_optionalChain([messages2, 'access', _219 => _219[idx - 1], 'optionalAccess', _220 => _220.id]), () => ( null)),
4434
4447
  message: m
4435
4448
  }))
4436
4449
  });
@@ -4466,8 +4479,8 @@ var getExternalStoreMessage = (message) => {
4466
4479
  };
4467
4480
 
4468
4481
  // src/runtimes/external-store/ThreadMessageConverter.ts
4469
- var ThreadMessageConverter = (_class14 = class {constructor() { _class14.prototype.__init32.call(this); }
4470
- __init32() {this.cache = /* @__PURE__ */ new WeakMap()}
4482
+ var ThreadMessageConverter = (_class14 = class {constructor() { _class14.prototype.__init33.call(this); }
4483
+ __init33() {this.cache = /* @__PURE__ */ new WeakMap()}
4471
4484
  convertMessages(messages2, converter) {
4472
4485
  return messages2.map((m, idx) => {
4473
4486
  const cached = this.cache.get(m);
@@ -4564,17 +4577,17 @@ var fromThreadMessageLike = (like, fallbackId, fallbackStatus) => {
4564
4577
  // src/runtimes/external-store/ExternalStoreThreadRuntimeCore.tsx
4565
4578
  var EMPTY_ARRAY2 = Object.freeze([]);
4566
4579
  var hasUpcomingMessage = (isRunning, messages2) => {
4567
- return isRunning && _optionalChain([messages2, 'access', _218 => _218[messages2.length - 1], 'optionalAccess', _219 => _219.role]) !== "assistant";
4580
+ return isRunning && _optionalChain([messages2, 'access', _221 => _221[messages2.length - 1], 'optionalAccess', _222 => _222.role]) !== "assistant";
4568
4581
  };
4569
4582
  var ExternalStoreThreadRuntimeCore = (_class15 = class {
4570
- constructor(configProvider, store) {;_class15.prototype.__init33.call(this);_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);_class15.prototype.__init40.call(this);_class15.prototype.__init41.call(this);_class15.prototype.__init42.call(this);
4583
+ constructor(configProvider, store) {;_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);_class15.prototype.__init40.call(this);_class15.prototype.__init41.call(this);_class15.prototype.__init42.call(this);_class15.prototype.__init43.call(this);_class15.prototype.__init44.call(this);
4571
4584
  this.configProvider = configProvider;
4572
4585
  this.store = store;
4573
4586
  }
4574
- __init33() {this._subscriptions = /* @__PURE__ */ new Set()}
4575
- __init34() {this.repository = new MessageRepository()}
4576
- __init35() {this.assistantOptimisticId = null}
4577
- __init36() {this._capabilities = {
4587
+ __init34() {this._subscriptions = /* @__PURE__ */ new Set()}
4588
+ __init35() {this.repository = new MessageRepository()}
4589
+ __init36() {this.assistantOptimisticId = null}
4590
+ __init37() {this._capabilities = {
4578
4591
  switchToBranch: false,
4579
4592
  edit: false,
4580
4593
  reload: false,
@@ -4590,12 +4603,12 @@ var ExternalStoreThreadRuntimeCore = (_class15 = class {
4590
4603
 
4591
4604
 
4592
4605
 
4593
- __init37() {this.suggestions = []}
4594
- __init38() {this.extras = void 0}
4595
- __init39() {this._converter = new ThreadMessageConverter()}
4606
+ __init38() {this.suggestions = []}
4607
+ __init39() {this.extras = void 0}
4608
+ __init40() {this._converter = new ThreadMessageConverter()}
4596
4609
 
4597
- __init40() {this.composer = new DefaultThreadComposerRuntimeCore(this)}
4598
- __init41() {this._editComposers = /* @__PURE__ */ new Map()}
4610
+ __init41() {this.composer = new DefaultThreadComposerRuntimeCore(this)}
4611
+ __init42() {this._editComposers = /* @__PURE__ */ new Map()}
4599
4612
  getEditComposer(messageId) {
4600
4613
  return this._editComposers.get(messageId);
4601
4614
  }
@@ -4630,12 +4643,12 @@ var ExternalStoreThreadRuntimeCore = (_class15 = class {
4630
4643
  reload: this._store.onReload !== void 0,
4631
4644
  cancel: this._store.onCancel !== void 0,
4632
4645
  speak: this._store.onSpeak !== void 0,
4633
- unstable_copy: _optionalChain([this, 'access', _223 => _223._store, 'access', _224 => _224.unstable_capabilities, 'optionalAccess', _225 => _225.copy]) !== false,
4646
+ unstable_copy: _optionalChain([this, 'access', _226 => _226._store, 'access', _227 => _227.unstable_capabilities, 'optionalAccess', _228 => _228.copy]) !== false,
4634
4647
  // default true
4635
- attachments: !!_optionalChain([this, 'access', _226 => _226.store, 'access', _227 => _227.adapters, 'optionalAccess', _228 => _228.attachments]),
4636
- feedback: !!_optionalChain([this, 'access', _229 => _229.store, 'access', _230 => _230.adapters, 'optionalAccess', _231 => _231.feedback])
4648
+ attachments: !!_optionalChain([this, 'access', _229 => _229.store, 'access', _230 => _230.adapters, 'optionalAccess', _231 => _231.attachments]),
4649
+ feedback: !!_optionalChain([this, 'access', _232 => _232.store, 'access', _233 => _233.adapters, 'optionalAccess', _234 => _234.feedback])
4637
4650
  };
4638
- this.composer.setAttachmentAdapter(_optionalChain([this, 'access', _232 => _232._store, 'access', _233 => _233.adapters, 'optionalAccess', _234 => _234.attachments]));
4651
+ this.composer.setAttachmentAdapter(_optionalChain([this, 'access', _235 => _235._store, 'access', _236 => _236.adapters, 'optionalAccess', _237 => _237.attachments]));
4639
4652
  if (oldStore) {
4640
4653
  if (oldStore.convertMessage !== store.convertMessage) {
4641
4654
  this._converter = new ThreadMessageConverter();
@@ -4661,7 +4674,7 @@ var ExternalStoreThreadRuntimeCore = (_class15 = class {
4661
4674
  for (let i = 0; i < messages2.length; i++) {
4662
4675
  const message = messages2[i];
4663
4676
  const parent = messages2[i - 1];
4664
- this.repository.addOrUpdateMessage(_nullishCoalesce(_optionalChain([parent, 'optionalAccess', _235 => _235.id]), () => ( null)), message);
4677
+ this.repository.addOrUpdateMessage(_nullishCoalesce(_optionalChain([parent, 'optionalAccess', _238 => _238.id]), () => ( null)), message);
4665
4678
  }
4666
4679
  if (this.assistantOptimisticId) {
4667
4680
  this.repository.deleteMessage(this.assistantOptimisticId);
@@ -4669,7 +4682,7 @@ var ExternalStoreThreadRuntimeCore = (_class15 = class {
4669
4682
  }
4670
4683
  if (hasUpcomingMessage(isRunning, messages2)) {
4671
4684
  this.assistantOptimisticId = this.repository.appendOptimisticMessage(
4672
- _nullishCoalesce(_optionalChain([messages2, 'access', _236 => _236.at, 'call', _237 => _237(-1), 'optionalAccess', _238 => _238.id]), () => ( null)),
4685
+ _nullishCoalesce(_optionalChain([messages2, 'access', _239 => _239.at, 'call', _240 => _240(-1), 'optionalAccess', _241 => _241.id]), () => ( null)),
4673
4686
  {
4674
4687
  role: "assistant",
4675
4688
  content: []
@@ -4677,7 +4690,7 @@ var ExternalStoreThreadRuntimeCore = (_class15 = class {
4677
4690
  );
4678
4691
  }
4679
4692
  this.repository.resetHead(
4680
- _nullishCoalesce(_nullishCoalesce(this.assistantOptimisticId, () => ( _optionalChain([messages2, 'access', _239 => _239.at, 'call', _240 => _240(-1), 'optionalAccess', _241 => _241.id]))), () => ( null))
4693
+ _nullishCoalesce(_nullishCoalesce(this.assistantOptimisticId, () => ( _optionalChain([messages2, 'access', _242 => _242.at, 'call', _243 => _243(-1), 'optionalAccess', _244 => _244.id]))), () => ( null))
4681
4694
  );
4682
4695
  this.messages = this.repository.getMessages();
4683
4696
  this.notifySubscribers();
@@ -4698,7 +4711,7 @@ var ExternalStoreThreadRuntimeCore = (_class15 = class {
4698
4711
  this.updateMessages(this.repository.getMessages());
4699
4712
  }
4700
4713
  async append(message) {
4701
- if (message.parentId !== (_nullishCoalesce(_optionalChain([this, 'access', _242 => _242.messages, 'access', _243 => _243.at, 'call', _244 => _244(-1), 'optionalAccess', _245 => _245.id]), () => ( null)))) {
4714
+ if (message.parentId !== (_nullishCoalesce(_optionalChain([this, 'access', _245 => _245.messages, 'access', _246 => _246.at, 'call', _247 => _247(-1), 'optionalAccess', _248 => _248.id]), () => ( null)))) {
4702
4715
  if (!this._store.onEdit)
4703
4716
  throw new Error("Runtime does not support editing messages.");
4704
4717
  await this._store.onEdit(message);
@@ -4721,7 +4734,7 @@ var ExternalStoreThreadRuntimeCore = (_class15 = class {
4721
4734
  }
4722
4735
  let messages2 = this.repository.getMessages();
4723
4736
  const previousMessage = messages2[messages2.length - 1];
4724
- if (_optionalChain([previousMessage, 'optionalAccess', _246 => _246.role]) === "user" && previousMessage.id === _optionalChain([messages2, 'access', _247 => _247.at, 'call', _248 => _248(-1), 'optionalAccess', _249 => _249.id])) {
4737
+ if (_optionalChain([previousMessage, 'optionalAccess', _249 => _249.role]) === "user" && previousMessage.id === _optionalChain([messages2, 'access', _250 => _250.at, 'call', _251 => _251(-1), 'optionalAccess', _252 => _252.id])) {
4725
4738
  this.repository.deleteMessage(previousMessage.id);
4726
4739
  if (!this.composer.text.trim()) {
4727
4740
  this.composer.setText(getThreadMessageText(previousMessage));
@@ -4739,14 +4752,41 @@ var ExternalStoreThreadRuntimeCore = (_class15 = class {
4739
4752
  throw new Error("Runtime does not support tool results.");
4740
4753
  this._store.onAddToolResult(options);
4741
4754
  }
4755
+ // TODO speech runtime?
4756
+
4757
+ __init43() {this.speech = null}
4742
4758
  speak(messageId) {
4743
- if (!this._store.onSpeak)
4744
- throw new Error("Runtime does not support speaking.");
4759
+ let adapter = _optionalChain([this, 'access', _253 => _253.store, 'access', _254 => _254.adapters, 'optionalAccess', _255 => _255.speech]);
4760
+ if (!adapter && this.store.onSpeak) {
4761
+ adapter = { speak: this.store.onSpeak };
4762
+ }
4763
+ if (!adapter) throw new Error("Speech adapter not configured");
4745
4764
  const { message } = this.repository.getMessage(messageId);
4746
- return this._store.onSpeak(message);
4765
+ _optionalChain([this, 'access', _256 => _256._stopSpeaking, 'optionalCall', _257 => _257()]);
4766
+ const utterance = adapter.speak(message);
4767
+ const unsub = utterance.subscribe(() => {
4768
+ if (utterance.status.type === "ended") {
4769
+ this._stopSpeaking = void 0;
4770
+ this.speech = null;
4771
+ } else {
4772
+ this.speech = { messageId, status: utterance.status };
4773
+ }
4774
+ this.notifySubscribers();
4775
+ });
4776
+ this.speech = { messageId, status: utterance.status };
4777
+ this._stopSpeaking = () => {
4778
+ utterance.cancel();
4779
+ unsub();
4780
+ this.speech = null;
4781
+ this._stopSpeaking = void 0;
4782
+ };
4783
+ }
4784
+ stopSpeaking() {
4785
+ if (!this._stopSpeaking) throw new Error("No message is being spoken");
4786
+ this._stopSpeaking();
4747
4787
  }
4748
4788
  submitFeedback({ messageId, type }) {
4749
- const adapter = _optionalChain([this, 'access', _250 => _250._store, 'access', _251 => _251.adapters, 'optionalAccess', _252 => _252.feedback]);
4789
+ const adapter = _optionalChain([this, 'access', _258 => _258._store, 'access', _259 => _259.adapters, 'optionalAccess', _260 => _260.feedback]);
4750
4790
  if (!adapter) throw new Error("Feedback adapter not configured");
4751
4791
  const { message } = this.repository.getMessage(messageId);
4752
4792
  adapter.submit({ message, type });
@@ -4755,8 +4795,8 @@ var ExternalStoreThreadRuntimeCore = (_class15 = class {
4755
4795
  this._subscriptions.add(callback);
4756
4796
  return () => this._subscriptions.delete(callback);
4757
4797
  }
4758
- __init42() {this.updateMessages = (messages2) => {
4759
- _optionalChain([this, 'access', _253 => _253._store, 'access', _254 => _254.setMessages, 'optionalCall', _255 => _255(
4798
+ __init44() {this.updateMessages = (messages2) => {
4799
+ _optionalChain([this, 'access', _261 => _261._store, 'access', _262 => _262.setMessages, 'optionalCall', _263 => _263(
4760
4800
  messages2.flatMap(getExternalStoreMessage).filter((m) => m != null)
4761
4801
  )]);
4762
4802
  }}
@@ -5010,11 +5050,11 @@ var WebSpeechSynthesisAdapter = class {
5010
5050
  speak(message) {
5011
5051
  const text = getThreadMessageText(message);
5012
5052
  const utterance = new SpeechSynthesisUtterance(text);
5013
- const endHandlers = /* @__PURE__ */ new Set();
5053
+ const subscribers = /* @__PURE__ */ new Set();
5014
5054
  const handleEnd = (reason, error) => {
5015
5055
  if (res.status.type === "ended") return;
5016
5056
  res.status = { type: "ended", reason, error };
5017
- endHandlers.forEach((handler) => handler());
5057
+ subscribers.forEach((handler) => handler());
5018
5058
  };
5019
5059
  utterance.addEventListener("end", () => handleEnd("finished"));
5020
5060
  utterance.addEventListener("error", (e) => handleEnd("error", e.error));
@@ -5025,7 +5065,7 @@ var WebSpeechSynthesisAdapter = class {
5025
5065
  window.speechSynthesis.cancel();
5026
5066
  handleEnd("cancelled");
5027
5067
  },
5028
- onEnd: (callback) => {
5068
+ subscribe: (callback) => {
5029
5069
  if (res.status.type === "ended") {
5030
5070
  let cancelled = false;
5031
5071
  queueMicrotask(() => {
@@ -5035,9 +5075,9 @@ var WebSpeechSynthesisAdapter = class {
5035
5075
  cancelled = true;
5036
5076
  };
5037
5077
  } else {
5038
- endHandlers.add(callback);
5078
+ subscribers.add(callback);
5039
5079
  return () => {
5040
- endHandlers.delete(callback);
5080
+ subscribers.delete(callback);
5041
5081
  };
5042
5082
  }
5043
5083
  }
@@ -5047,8 +5087,8 @@ var WebSpeechSynthesisAdapter = class {
5047
5087
  };
5048
5088
 
5049
5089
  // src/runtimes/attachment/SimpleImageAttachmentAdapter.ts
5050
- var SimpleImageAttachmentAdapter = (_class16 = class {constructor() { _class16.prototype.__init43.call(this); }
5051
- __init43() {this.accept = "image/*"}
5090
+ var SimpleImageAttachmentAdapter = (_class16 = class {constructor() { _class16.prototype.__init45.call(this); }
5091
+ __init45() {this.accept = "image/*"}
5052
5092
  async add(state) {
5053
5093
  return {
5054
5094
  id: state.file.name,
@@ -5082,8 +5122,8 @@ var getFileDataURL = (file) => new Promise((resolve, reject) => {
5082
5122
  });
5083
5123
 
5084
5124
  // src/runtimes/attachment/SimpleTextAttachmentAdapter.ts
5085
- var SimpleTextAttachmentAdapter = (_class17 = class {constructor() { _class17.prototype.__init44.call(this); }
5086
- __init44() {this.accept = "text/plain,text/html,text/markdown,text/csv,text/xml,text/json,text/css"}
5125
+ var SimpleTextAttachmentAdapter = (_class17 = class {constructor() { _class17.prototype.__init46.call(this); }
5126
+ __init46() {this.accept = "text/plain,text/html,text/markdown,text/csv,text/xml,text/json,text/css"}
5087
5127
  async add(state) {
5088
5128
  return {
5089
5129
  id: state.file.name,
@@ -5211,7 +5251,7 @@ var ThreadConfigProvider = ({
5211
5251
  }) => {
5212
5252
  const hasAssistant = !!useAssistantRuntime({ optional: true });
5213
5253
  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 });
5214
- if (!_optionalChain([config, 'optionalAccess', _256 => _256.runtime])) return configProvider;
5254
+ if (!_optionalChain([config, 'optionalAccess', _264 => _264.runtime])) return configProvider;
5215
5255
  if (hasAssistant) {
5216
5256
  throw new Error(
5217
5257
  "You provided a runtime to <Thread> while simulataneously using <AssistantRuntimeProvider>. This is not allowed."
@@ -5287,13 +5327,13 @@ var AssistantActionBarRoot = withDefaults(actionBar_exports.Root, {
5287
5327
  className: "aui-assistant-action-bar-root"
5288
5328
  });
5289
5329
  AssistantActionBarRoot.displayName = "AssistantActionBarRoot";
5290
- var AssistantActionBarCopy = _react.forwardRef.call(void 0, (props, ref) => {
5330
+ var AssistantActionBarCopy = _react.forwardRef.call(void 0, ({ copiedDuration, ...props }, ref) => {
5291
5331
  const {
5292
5332
  strings: {
5293
5333
  assistantMessage: { copy: { tooltip = "Copy" } = {} } = {}
5294
5334
  } = {}
5295
5335
  } = useThreadConfig();
5296
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, actionBar_exports.Copy, { asChild: true, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, TooltipIconButton, { tooltip, ...props, ref, children: _nullishCoalesce(props.children, () => ( /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
5336
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, actionBar_exports.Copy, { copiedDuration, asChild: true, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, TooltipIconButton, { tooltip, ...props, ref, children: _nullishCoalesce(props.children, () => ( /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
5297
5337
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, message_exports.If, { copied: true, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _lucidereact.CheckIcon, {}) }),
5298
5338
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, message_exports.If, { copied: false, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _lucidereact.CopyIcon, {}) })
5299
5339
  ] }))) }) });
@@ -5408,7 +5448,7 @@ var BranchPicker = () => {
5408
5448
  const allowBranchPicker = useAllowBranchPicker(true);
5409
5449
  if (!allowBranchPicker) return null;
5410
5450
  return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, BranchPickerRoot, { hideWhenSingleBranch: true, children: [
5411
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, BranchPickerPrevious2, {}),
5451
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, BranchPickerPrevious, {}),
5412
5452
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, BranchPickerState, {}),
5413
5453
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, BranchPickerNext, {})
5414
5454
  ] });
@@ -5418,7 +5458,7 @@ var BranchPickerRoot = withDefaults(branchPicker_exports.Root, {
5418
5458
  className: "aui-branch-picker-root"
5419
5459
  });
5420
5460
  BranchPickerRoot.displayName = "BranchPickerRoot";
5421
- var BranchPickerPrevious2 = _react.forwardRef.call(void 0, (props, ref) => {
5461
+ var BranchPickerPrevious = _react.forwardRef.call(void 0, (props, ref) => {
5422
5462
  const {
5423
5463
  strings: {
5424
5464
  branchPicker: { previous: { tooltip = "Previous" } = {} } = {}
@@ -5427,7 +5467,7 @@ var BranchPickerPrevious2 = _react.forwardRef.call(void 0, (props, ref) => {
5427
5467
  const allowBranchPicker = useAllowBranchPicker();
5428
5468
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, branchPicker_exports.Previous, { disabled: !allowBranchPicker, asChild: true, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, TooltipIconButton, { tooltip, ...props, ref, children: _nullishCoalesce(props.children, () => ( /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _lucidereact.ChevronLeftIcon, {}))) }) });
5429
5469
  });
5430
- BranchPickerPrevious2.displayName = "BranchPickerPrevious";
5470
+ BranchPickerPrevious.displayName = "BranchPickerPrevious";
5431
5471
  var BranchPickerStateWrapper = withDefaults("span", {
5432
5472
  className: "aui-branch-picker-state"
5433
5473
  });
@@ -5449,7 +5489,7 @@ var BranchPickerNext = _react.forwardRef.call(void 0, (props, ref) => {
5449
5489
  BranchPickerNext.displayName = "BranchPickerNext";
5450
5490
  var exports2 = {
5451
5491
  Root: BranchPickerRoot,
5452
- Previous: BranchPickerPrevious2,
5492
+ Previous: BranchPickerPrevious,
5453
5493
  Next: BranchPickerNext
5454
5494
  };
5455
5495
  var branch_picker_default = Object.assign(BranchPicker, exports2);
@@ -5539,7 +5579,7 @@ var AssistantMessageContent = _react.forwardRef.call(void 0, ({ components: comp
5539
5579
  {
5540
5580
  components: {
5541
5581
  ...componentsProp,
5542
- Text: _nullishCoalesce(_nullishCoalesce(_optionalChain([componentsProp, 'optionalAccess', _257 => _257.Text]), () => ( components.Text)), () => ( content_part_default.Text)),
5582
+ Text: _nullishCoalesce(_nullishCoalesce(_optionalChain([componentsProp, 'optionalAccess', _265 => _265.Text]), () => ( components.Text)), () => ( content_part_default.Text)),
5543
5583
  tools: toolsComponents
5544
5584
  }
5545
5585
  }
@@ -5674,7 +5714,7 @@ var ComposerAttachments = ({ components }) => {
5674
5714
  {
5675
5715
  components: {
5676
5716
  ...components,
5677
- Attachment: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _258 => _258.Attachment]), () => ( composer_attachment_default))
5717
+ Attachment: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _266 => _266.Attachment]), () => ( composer_attachment_default))
5678
5718
  }
5679
5719
  }
5680
5720
  ) });
@@ -5719,23 +5759,27 @@ var ComposerSendButton = withDefaults(TooltipIconButton, {
5719
5759
  variant: "default",
5720
5760
  className: "aui-composer-send"
5721
5761
  });
5722
- var ComposerSend = _react.forwardRef.call(void 0, (props, ref) => {
5723
- const {
5724
- strings: { composer: { send: { tooltip = "Send" } = {} } = {} } = {}
5725
- } = useThreadConfig();
5726
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, composer_exports.Send, { asChild: true, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ComposerSendButton, { tooltip, ...props, ref, children: _nullishCoalesce(props.children, () => ( /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _lucidereact.SendHorizontalIcon, {}))) }) });
5727
- });
5762
+ var ComposerSend = _react.forwardRef.call(void 0,
5763
+ (props, ref) => {
5764
+ const {
5765
+ strings: { composer: { send: { tooltip = "Send" } = {} } = {} } = {}
5766
+ } = useThreadConfig();
5767
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, composer_exports.Send, { asChild: true, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ComposerSendButton, { tooltip, ...props, ref, children: _nullishCoalesce(props.children, () => ( /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _lucidereact.SendHorizontalIcon, {}))) }) });
5768
+ }
5769
+ );
5728
5770
  ComposerSend.displayName = "ComposerSend";
5729
5771
  var ComposerCancelButton = withDefaults(TooltipIconButton, {
5730
5772
  variant: "default",
5731
5773
  className: "aui-composer-cancel"
5732
5774
  });
5733
- var ComposerCancel = _react.forwardRef.call(void 0, (props, ref) => {
5734
- const {
5735
- strings: { composer: { cancel: { tooltip = "Cancel" } = {} } = {} } = {}
5736
- } = useThreadConfig();
5737
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, composer_exports.Cancel, { asChild: true, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ComposerCancelButton, { tooltip, ...props, ref, children: _nullishCoalesce(props.children, () => ( /* @__PURE__ */ _jsxruntime.jsx.call(void 0, CircleStopIcon, {}))) }) });
5738
- });
5775
+ var ComposerCancel = _react.forwardRef.call(void 0,
5776
+ (props, ref) => {
5777
+ const {
5778
+ strings: { composer: { cancel: { tooltip = "Cancel" } = {} } = {} } = {}
5779
+ } = useThreadConfig();
5780
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, composer_exports.Cancel, { asChild: true, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ComposerCancelButton, { tooltip, ...props, ref, children: _nullishCoalesce(props.children, () => ( /* @__PURE__ */ _jsxruntime.jsx.call(void 0, CircleStopIcon, {}))) }) });
5781
+ }
5782
+ );
5739
5783
  ComposerCancel.displayName = "ComposerCancel";
5740
5784
  var exports6 = {
5741
5785
  Root: ComposerRoot,
@@ -5767,11 +5811,9 @@ var ThreadWelcomeRootStyled = withDefaults("div", {
5767
5811
  var ThreadWelcomeCenter = withDefaults("div", {
5768
5812
  className: "aui-thread-welcome-center"
5769
5813
  });
5770
- var ThreadWelcomeRoot = _react.forwardRef.call(void 0,
5771
- (props, ref) => {
5772
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, thread_exports.Empty, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ThreadWelcomeRootStyled, { ...props, ref }) });
5773
- }
5774
- );
5814
+ var ThreadWelcomeRoot = _react.forwardRef.call(void 0, (props, ref) => {
5815
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, thread_exports.Empty, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ThreadWelcomeRootStyled, { ...props, ref }) });
5816
+ });
5775
5817
  ThreadWelcomeRoot.displayName = "ThreadWelcomeRoot";
5776
5818
  var ThreadWelcomeAvatar = () => {
5777
5819
  const { assistantAvatar: avatar = { fallback: "A" } } = useThreadConfig();
@@ -5800,7 +5842,7 @@ var ThreadWelcomeSuggestions = () => {
5800
5842
  const suggestions2 = useThread((t) => t.suggestions);
5801
5843
  const { welcome: { suggestions } = {} } = useThreadConfig();
5802
5844
  const finalSuggestions = suggestions2.length ? suggestions2 : suggestions;
5803
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ThreadWelcomeSuggestionContainer, { children: _optionalChain([finalSuggestions, 'optionalAccess', _259 => _259.map, 'call', _260 => _260((suggestion, idx) => {
5845
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ThreadWelcomeSuggestionContainer, { children: _optionalChain([finalSuggestions, 'optionalAccess', _267 => _267.map, 'call', _268 => _268((suggestion, idx) => {
5804
5846
  const key = `${suggestion.prompt}-${idx}`;
5805
5847
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ThreadWelcomeSuggestion, { suggestion }, key);
5806
5848
  })]) });
@@ -5888,19 +5930,17 @@ UserMessageRoot.displayName = "UserMessageRoot";
5888
5930
  var UserMessageContentWrapper = withDefaults("div", {
5889
5931
  className: "aui-user-message-content"
5890
5932
  });
5891
- var UserMessageContent = _react.forwardRef.call(void 0,
5892
- ({ components, ...props }, ref) => {
5893
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, UserMessageContentWrapper, { ...props, ref, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
5894
- message_exports.Content,
5895
- {
5896
- components: {
5897
- ...components,
5898
- Text: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _261 => _261.Text]), () => ( content_part_default.Text))
5899
- }
5933
+ var UserMessageContent = _react.forwardRef.call(void 0, ({ components, ...props }, ref) => {
5934
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, UserMessageContentWrapper, { ...props, ref, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
5935
+ message_exports.Content,
5936
+ {
5937
+ components: {
5938
+ ...components,
5939
+ Text: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _269 => _269.Text]), () => ( content_part_default.Text))
5900
5940
  }
5901
- ) });
5902
- }
5903
- );
5941
+ }
5942
+ ) });
5943
+ });
5904
5944
  UserMessageContent.displayName = "UserMessageContent";
5905
5945
  var UserMessageAttachmentsContainer = withDefaults("div", {
5906
5946
  className: "aui-user-message-attachments"
@@ -5913,7 +5953,7 @@ var UserMessageAttachments = ({
5913
5953
  {
5914
5954
  components: {
5915
5955
  ...components,
5916
- Attachment: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _262 => _262.Attachment]), () => ( user_message_attachment_default))
5956
+ Attachment: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _270 => _270.Attachment]), () => ( user_message_attachment_default))
5917
5957
  }
5918
5958
  }
5919
5959
  ) }) });
@@ -5950,25 +5990,19 @@ var EditComposerFooter = withDefaults("div", {
5950
5990
  className: "aui-edit-composer-footer"
5951
5991
  });
5952
5992
  EditComposerFooter.displayName = "EditComposerFooter";
5953
- var EditComposerCancel = _react.forwardRef.call(void 0,
5954
- (props, ref) => {
5955
- const {
5956
- strings: {
5957
- editComposer: { cancel: { label = "Cancel" } = {} } = {}
5958
- } = {}
5959
- } = useThreadConfig();
5960
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, composer_exports.Cancel, { asChild: true, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Button, { variant: "ghost", ...props, ref, children: _nullishCoalesce(props.children, () => ( label)) }) });
5961
- }
5962
- );
5993
+ var EditComposerCancel = _react.forwardRef.call(void 0, (props, ref) => {
5994
+ const {
5995
+ strings: { editComposer: { cancel: { label = "Cancel" } = {} } = {} } = {}
5996
+ } = useThreadConfig();
5997
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, composer_exports.Cancel, { asChild: true, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Button, { variant: "ghost", ...props, ref, children: _nullishCoalesce(props.children, () => ( label)) }) });
5998
+ });
5963
5999
  EditComposerCancel.displayName = "EditComposerCancel";
5964
- var EditComposerSend = _react.forwardRef.call(void 0,
5965
- (props, ref) => {
5966
- const {
5967
- strings: { editComposer: { send: { label = "Send" } = {} } = {} } = {}
5968
- } = useThreadConfig();
5969
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, composer_exports.Send, { asChild: true, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Button, { ...props, ref, children: _nullishCoalesce(props.children, () => ( label)) }) });
5970
- }
5971
- );
6000
+ var EditComposerSend = _react.forwardRef.call(void 0, (props, ref) => {
6001
+ const {
6002
+ strings: { editComposer: { send: { label = "Send" } = {} } = {} } = {}
6003
+ } = useThreadConfig();
6004
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, composer_exports.Send, { asChild: true, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Button, { ...props, ref, children: _nullishCoalesce(props.children, () => ( label)) }) });
6005
+ });
5972
6006
  EditComposerSend.displayName = "EditComposerSend";
5973
6007
  var exports11 = {
5974
6008
  Root: EditComposerRoot,
@@ -6022,10 +6056,10 @@ var ThreadMessages = ({ components, unstable_flexGrowDiv: flexGrowDiv = true, ..
6022
6056
  thread_exports.Messages,
6023
6057
  {
6024
6058
  components: {
6025
- UserMessage: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _263 => _263.UserMessage]), () => ( user_message_default)),
6026
- EditComposer: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _264 => _264.EditComposer]), () => ( edit_composer_default)),
6027
- AssistantMessage: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _265 => _265.AssistantMessage]), () => ( assistant_message_default)),
6028
- SystemMessage: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _266 => _266.SystemMessage]), () => ( SystemMessage))
6059
+ UserMessage: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _271 => _271.UserMessage]), () => ( user_message_default)),
6060
+ EditComposer: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _272 => _272.EditComposer]), () => ( edit_composer_default)),
6061
+ AssistantMessage: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _273 => _273.AssistantMessage]), () => ( assistant_message_default)),
6062
+ SystemMessage: _nullishCoalesce(_optionalChain([components, 'optionalAccess', _274 => _274.SystemMessage]), () => ( SystemMessage))
6029
6063
  },
6030
6064
  ...rest
6031
6065
  }
@@ -6036,7 +6070,7 @@ var ThreadMessages = ({ components, unstable_flexGrowDiv: flexGrowDiv = true, ..
6036
6070
  ThreadMessages.displayName = "ThreadMessages";
6037
6071
  var ThreadFollowupSuggestions = () => {
6038
6072
  const suggestions = useThread((t) => t.suggestions);
6039
- 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', _267 => _267.map, 'call', _268 => _268((suggestion, idx) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
6073
+ 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', _275 => _275.map, 'call', _276 => _276((suggestion, idx) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
6040
6074
  thread_exports.Suggestion,
6041
6075
  {
6042
6076
  className: "aui-thread-followup-suggestion",
@@ -6080,7 +6114,10 @@ var AssistantModal = (config) => {
6080
6114
  ] });
6081
6115
  };
6082
6116
  AssistantModal.displayName = "AssistantModal";
6083
- var AssistantModalRoot = ({ config, ...props }) => {
6117
+ var AssistantModalRoot = ({
6118
+ config,
6119
+ ...props
6120
+ }) => {
6084
6121
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ThreadConfigProvider, { config, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, assistantModal_exports.Root, { ...props }) });
6085
6122
  };
6086
6123
  AssistantModalRoot.displayName = "AssistantModalRoot";