@assistant-ui/react 0.14.27 → 0.14.29

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.
Files changed (257) hide show
  1. package/dist/client/ExternalThread.d.ts +11 -1
  2. package/dist/client/ExternalThread.d.ts.map +1 -1
  3. package/dist/client/ExternalThread.js +758 -513
  4. package/dist/client/ExternalThread.js.map +1 -1
  5. package/dist/context/react/utils/createContextStoreHook.d.ts.map +1 -1
  6. package/dist/context/react/utils/createStateHookForRuntime.d.ts.map +1 -1
  7. package/dist/legacy-runtime/AssistantRuntimeProvider.js.map +1 -1
  8. package/dist/legacy-runtime/cloud/auiV0.d.ts +12 -1
  9. package/dist/legacy-runtime/cloud/auiV0.d.ts.map +1 -1
  10. package/dist/legacy-runtime/cloud/auiV0.js +2 -1
  11. package/dist/legacy-runtime/cloud/auiV0.js.map +1 -1
  12. package/dist/legacy-runtime/runtime-cores/assistant-transport/commandQueue.d.ts +1 -1
  13. package/dist/legacy-runtime/runtime-cores/assistant-transport/commandQueue.d.ts.map +1 -1
  14. package/dist/legacy-runtime/runtime-cores/assistant-transport/commandQueue.js +7 -6
  15. package/dist/legacy-runtime/runtime-cores/assistant-transport/commandQueue.js.map +1 -1
  16. package/dist/legacy-runtime/runtime-cores/assistant-transport/runManager.d.ts.map +1 -1
  17. package/dist/legacy-runtime/runtime-cores/assistant-transport/runManager.js +30 -15
  18. package/dist/legacy-runtime/runtime-cores/assistant-transport/runManager.js.map +1 -1
  19. package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.d.ts.map +1 -1
  20. package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.js +8 -4
  21. package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.js.map +1 -1
  22. package/dist/legacy-runtime/runtime-cores/assistant-transport/useConvertedState.js +1 -0
  23. package/dist/legacy-runtime/runtime-cores/assistant-transport/useConvertedState.js.map +1 -1
  24. package/dist/mcp-apps/McpAppRenderer.d.ts.map +1 -1
  25. package/dist/model-context/makeAssistantVisible.d.ts.map +1 -1
  26. package/dist/model-context/makeAssistantVisible.js +7 -1
  27. package/dist/model-context/makeAssistantVisible.js.map +1 -1
  28. package/dist/primitives/actionBar/ActionBarCopy.d.ts.map +1 -1
  29. package/dist/primitives/actionBar/ActionBarEdit.d.ts.map +1 -1
  30. package/dist/primitives/actionBar/ActionBarExportMarkdown.d.ts.map +1 -1
  31. package/dist/primitives/actionBar/ActionBarFeedbackNegative.d.ts.map +1 -1
  32. package/dist/primitives/actionBar/ActionBarFeedbackPositive.d.ts.map +1 -1
  33. package/dist/primitives/actionBar/ActionBarReload.d.ts.map +1 -1
  34. package/dist/primitives/actionBar/ActionBarRoot.d.ts.map +1 -1
  35. package/dist/primitives/actionBar/ActionBarRoot.js +3 -3
  36. package/dist/primitives/actionBar/ActionBarRoot.js.map +1 -1
  37. package/dist/primitives/actionBar/ActionBarSpeak.d.ts.map +1 -1
  38. package/dist/primitives/actionBar/ActionBarStopSpeaking.d.ts.map +1 -1
  39. package/dist/primitives/actionBar/useActionBarFloatStatus.d.ts +7 -6
  40. package/dist/primitives/actionBar/useActionBarFloatStatus.d.ts.map +1 -1
  41. package/dist/primitives/actionBar/useActionBarFloatStatus.js +10 -11
  42. package/dist/primitives/actionBar/useActionBarFloatStatus.js.map +1 -1
  43. package/dist/primitives/actionBarMore/ActionBarMoreContent.d.ts.map +1 -1
  44. package/dist/primitives/actionBarMore/ActionBarMoreContent.js.map +1 -1
  45. package/dist/primitives/actionBarMore/ActionBarMoreItem.d.ts.map +1 -1
  46. package/dist/primitives/actionBarMore/ActionBarMoreSeparator.d.ts.map +1 -1
  47. package/dist/primitives/actionBarMore/ActionBarMoreTrigger.d.ts.map +1 -1
  48. package/dist/primitives/assistantModal/AssistantModalAnchor.d.ts.map +1 -1
  49. package/dist/primitives/assistantModal/AssistantModalContent.d.ts.map +1 -1
  50. package/dist/primitives/assistantModal/AssistantModalContent.js.map +1 -1
  51. package/dist/primitives/assistantModal/AssistantModalTrigger.d.ts.map +1 -1
  52. package/dist/primitives/assistantModal/popoverRenderPrimitives.d.ts.map +1 -1
  53. package/dist/primitives/attachment/AttachmentRemove.d.ts.map +1 -1
  54. package/dist/primitives/attachment/AttachmentRemove.js +1 -0
  55. package/dist/primitives/attachment/AttachmentRemove.js.map +1 -1
  56. package/dist/primitives/attachment/AttachmentRoot.d.ts.map +1 -1
  57. package/dist/primitives/attachment/AttachmentThumb.d.ts.map +1 -1
  58. package/dist/primitives/attachment/AttachmentThumb.js.map +1 -1
  59. package/dist/primitives/branchPicker/BranchPickerNext.d.ts.map +1 -1
  60. package/dist/primitives/branchPicker/BranchPickerPrevious.d.ts.map +1 -1
  61. package/dist/primitives/branchPicker/BranchPickerRoot.d.ts.map +1 -1
  62. package/dist/primitives/branchPicker/BranchPickerRoot.js.map +1 -1
  63. package/dist/primitives/chainOfThought/ChainOfThoughtAccordionTrigger.d.ts.map +1 -1
  64. package/dist/primitives/chainOfThought/ChainOfThoughtAccordionTrigger.js +1 -0
  65. package/dist/primitives/chainOfThought/ChainOfThoughtAccordionTrigger.js.map +1 -1
  66. package/dist/primitives/chainOfThought/ChainOfThoughtRoot.d.ts.map +1 -1
  67. package/dist/primitives/composer/ComposerAddAttachment.d.ts.map +1 -1
  68. package/dist/primitives/composer/ComposerAddAttachment.js +8 -2
  69. package/dist/primitives/composer/ComposerAddAttachment.js.map +1 -1
  70. package/dist/primitives/composer/ComposerAttachmentDropzone.d.ts.map +1 -1
  71. package/dist/primitives/composer/ComposerAttachmentDropzone.js +1 -3
  72. package/dist/primitives/composer/ComposerAttachmentDropzone.js.map +1 -1
  73. package/dist/primitives/composer/ComposerCancel.d.ts.map +1 -1
  74. package/dist/primitives/composer/ComposerDictate.d.ts.map +1 -1
  75. package/dist/primitives/composer/ComposerDictationTranscript.d.ts.map +1 -1
  76. package/dist/primitives/composer/ComposerDictationTranscript.js.map +1 -1
  77. package/dist/primitives/composer/ComposerInput.js +6 -4
  78. package/dist/primitives/composer/ComposerInput.js.map +1 -1
  79. package/dist/primitives/composer/ComposerQuote.d.ts.map +1 -1
  80. package/dist/primitives/composer/ComposerQuote.js.map +1 -1
  81. package/dist/primitives/composer/ComposerRoot.d.ts +5 -0
  82. package/dist/primitives/composer/ComposerRoot.d.ts.map +1 -1
  83. package/dist/primitives/composer/ComposerRoot.js +86 -40
  84. package/dist/primitives/composer/ComposerRoot.js.map +1 -1
  85. package/dist/primitives/composer/ComposerSend.d.ts.map +1 -1
  86. package/dist/primitives/composer/ComposerSend.js +1 -0
  87. package/dist/primitives/composer/ComposerSend.js.map +1 -1
  88. package/dist/primitives/composer/ComposerStopDictation.d.ts.map +1 -1
  89. package/dist/primitives/composer/ComposerStopDictation.js +1 -0
  90. package/dist/primitives/composer/ComposerStopDictation.js.map +1 -1
  91. package/dist/primitives/composer/trigger/TriggerPopover.d.ts.map +1 -1
  92. package/dist/primitives/composer/trigger/TriggerPopover.js.map +1 -1
  93. package/dist/primitives/composer/trigger/TriggerPopoverBack.d.ts.map +1 -1
  94. package/dist/primitives/composer/trigger/TriggerPopoverCategories.d.ts.map +1 -1
  95. package/dist/primitives/composer/trigger/TriggerPopoverCategories.js.map +1 -1
  96. package/dist/primitives/composer/trigger/TriggerPopoverItems.d.ts.map +1 -1
  97. package/dist/primitives/composer/trigger/TriggerPopoverItems.js.map +1 -1
  98. package/dist/primitives/composer/trigger/TriggerPopoverResource.d.ts.map +1 -1
  99. package/dist/primitives/composer/trigger/TriggerPopoverRootContext.js.map +1 -1
  100. package/dist/primitives/composer/trigger/detectTrigger.d.ts +1 -1
  101. package/dist/primitives/composer/trigger/triggerDetectionResource.d.ts.map +1 -1
  102. package/dist/primitives/composer/trigger/triggerKeyboardResource.d.ts.map +1 -1
  103. package/dist/primitives/composer/trigger/triggerNavigationResource.d.ts.map +1 -1
  104. package/dist/primitives/composer/trigger/triggerSelectionResource.d.ts.map +1 -1
  105. package/dist/primitives/dropdownMenuRenderPrimitives.d.ts.map +1 -1
  106. package/dist/primitives/error/ErrorMessage.d.ts.map +1 -1
  107. package/dist/primitives/error/ErrorMessage.js.map +1 -1
  108. package/dist/primitives/error/ErrorRoot.d.ts.map +1 -1
  109. package/dist/primitives/message/MessageParts.js.map +1 -1
  110. package/dist/primitives/message/MessagePartsGrouped.js.map +1 -1
  111. package/dist/primitives/message/MessageRoot.d.ts.map +1 -1
  112. package/dist/primitives/messagePart/MessagePartImage.d.ts.map +1 -1
  113. package/dist/primitives/messagePart/MessagePartText.d.ts.map +1 -1
  114. package/dist/primitives/messagePart/MessagePartText.js.map +1 -1
  115. package/dist/primitives/messagePart/useMessagePartData.d.ts +3 -2
  116. package/dist/primitives/messagePart/useMessagePartData.d.ts.map +1 -1
  117. package/dist/primitives/messagePart/useMessagePartData.js +3 -2
  118. package/dist/primitives/messagePart/useMessagePartData.js.map +1 -1
  119. package/dist/primitives/messagePart/useMessagePartFile.d.ts +5 -4
  120. package/dist/primitives/messagePart/useMessagePartFile.d.ts.map +1 -1
  121. package/dist/primitives/messagePart/useMessagePartFile.js +11 -3
  122. package/dist/primitives/messagePart/useMessagePartFile.js.map +1 -1
  123. package/dist/primitives/messagePart/useMessagePartImage.d.ts +5 -4
  124. package/dist/primitives/messagePart/useMessagePartImage.d.ts.map +1 -1
  125. package/dist/primitives/messagePart/useMessagePartImage.js +10 -3
  126. package/dist/primitives/messagePart/useMessagePartImage.js.map +1 -1
  127. package/dist/primitives/messagePart/useMessagePartReasoning.d.ts +5 -4
  128. package/dist/primitives/messagePart/useMessagePartReasoning.d.ts.map +1 -1
  129. package/dist/primitives/messagePart/useMessagePartReasoning.js +10 -3
  130. package/dist/primitives/messagePart/useMessagePartReasoning.js.map +1 -1
  131. package/dist/primitives/messagePart/useMessagePartSource.d.ts +6 -4
  132. package/dist/primitives/messagePart/useMessagePartSource.d.ts.map +1 -1
  133. package/dist/primitives/messagePart/useMessagePartSource.js +12 -3
  134. package/dist/primitives/messagePart/useMessagePartSource.js.map +1 -1
  135. package/dist/primitives/messagePart/useMessagePartText.d.ts +6 -5
  136. package/dist/primitives/messagePart/useMessagePartText.d.ts.map +1 -1
  137. package/dist/primitives/messagePart/useMessagePartText.js +10 -3
  138. package/dist/primitives/messagePart/useMessagePartText.js.map +1 -1
  139. package/dist/primitives/queueItem/QueueItemRemove.d.ts.map +1 -1
  140. package/dist/primitives/queueItem/QueueItemRemove.js +1 -0
  141. package/dist/primitives/queueItem/QueueItemRemove.js.map +1 -1
  142. package/dist/primitives/queueItem/QueueItemSteer.d.ts.map +1 -1
  143. package/dist/primitives/queueItem/QueueItemSteer.js +1 -0
  144. package/dist/primitives/queueItem/QueueItemSteer.js.map +1 -1
  145. package/dist/primitives/queueItem/QueueItemText.d.ts.map +1 -1
  146. package/dist/primitives/queueItem/QueueItemText.js.map +1 -1
  147. package/dist/primitives/selectionToolbar/SelectionToolbarQuote.d.ts.map +1 -1
  148. package/dist/primitives/selectionToolbar/SelectionToolbarRoot.d.ts.map +1 -1
  149. package/dist/primitives/selectionToolbar/SelectionToolbarRoot.js.map +1 -1
  150. package/dist/primitives/suggestion/SuggestionDescription.d.ts.map +1 -1
  151. package/dist/primitives/suggestion/SuggestionDescription.js.map +1 -1
  152. package/dist/primitives/suggestion/SuggestionTitle.d.ts.map +1 -1
  153. package/dist/primitives/suggestion/SuggestionTitle.js.map +1 -1
  154. package/dist/primitives/suggestion/SuggestionTrigger.d.ts.map +1 -1
  155. package/dist/primitives/suggestion/SuggestionTrigger.js +1 -0
  156. package/dist/primitives/suggestion/SuggestionTrigger.js.map +1 -1
  157. package/dist/primitives/thread/ThreadRoot.d.ts.map +1 -1
  158. package/dist/primitives/thread/ThreadScrollToBottom.d.ts.map +1 -1
  159. package/dist/primitives/thread/ThreadScrollToBottom.js +1 -0
  160. package/dist/primitives/thread/ThreadScrollToBottom.js.map +1 -1
  161. package/dist/primitives/thread/ThreadSuggestion.d.ts.map +1 -1
  162. package/dist/primitives/thread/ThreadViewport.d.ts.map +1 -1
  163. package/dist/primitives/thread/ThreadViewport.js +53 -19
  164. package/dist/primitives/thread/ThreadViewport.js.map +1 -1
  165. package/dist/primitives/thread/ThreadViewportFooter.d.ts.map +1 -1
  166. package/dist/primitives/thread/topAnchor/createReserveObservers.d.ts.map +1 -1
  167. package/dist/primitives/thread/topAnchor/mountTopAnchorReserve.d.ts +4 -0
  168. package/dist/primitives/thread/topAnchor/mountTopAnchorReserve.d.ts.map +1 -1
  169. package/dist/primitives/thread/topAnchor/mountTopAnchorReserve.js +14 -1
  170. package/dist/primitives/thread/topAnchor/mountTopAnchorReserve.js.map +1 -1
  171. package/dist/primitives/thread/topAnchor/topAnchorTurn.d.ts +13 -1
  172. package/dist/primitives/thread/topAnchor/topAnchorTurn.d.ts.map +1 -1
  173. package/dist/primitives/thread/topAnchor/topAnchorTurn.js +14 -1
  174. package/dist/primitives/thread/topAnchor/topAnchorTurn.js.map +1 -1
  175. package/dist/primitives/thread/useThreadViewportAutoScroll.js +2 -1
  176. package/dist/primitives/thread/useThreadViewportAutoScroll.js.map +1 -1
  177. package/dist/primitives/threadList/ThreadListLoadMore.d.ts.map +1 -1
  178. package/dist/primitives/threadList/ThreadListNew.d.ts.map +1 -1
  179. package/dist/primitives/threadList/ThreadListRoot.d.ts.map +1 -1
  180. package/dist/primitives/threadList/ThreadListRoot.js.map +1 -1
  181. package/dist/primitives/threadListFocusGroup.d.ts.map +1 -1
  182. package/dist/primitives/threadListItem/ThreadListItemArchive.d.ts.map +1 -1
  183. package/dist/primitives/threadListItem/ThreadListItemDelete.d.ts.map +1 -1
  184. package/dist/primitives/threadListItem/ThreadListItemRoot.d.ts.map +1 -1
  185. package/dist/primitives/threadListItem/ThreadListItemRoot.js.map +1 -1
  186. package/dist/primitives/threadListItem/ThreadListItemTrigger.d.ts.map +1 -1
  187. package/dist/primitives/threadListItem/ThreadListItemTrigger.js.map +1 -1
  188. package/dist/primitives/threadListItem/ThreadListItemUnarchive.d.ts.map +1 -1
  189. package/dist/primitives/threadListItemMore/ThreadListItemMoreContent.d.ts.map +1 -1
  190. package/dist/primitives/threadListItemMore/ThreadListItemMoreContent.js.map +1 -1
  191. package/dist/primitives/threadListItemMore/ThreadListItemMoreItem.d.ts.map +1 -1
  192. package/dist/primitives/threadListItemMore/ThreadListItemMoreRoot.js.map +1 -1
  193. package/dist/primitives/threadListItemMore/ThreadListItemMoreSeparator.d.ts.map +1 -1
  194. package/dist/primitives/threadListItemMore/ThreadListItemMoreTrigger.d.ts.map +1 -1
  195. package/dist/tests/setup.d.ts +1 -1
  196. package/dist/utils/Primitive.d.ts.map +1 -1
  197. package/dist/utils/Primitive.js.map +1 -1
  198. package/dist/utils/createActionButton.d.ts.map +1 -1
  199. package/dist/utils/hooks/useOnResizeContent.js +1 -0
  200. package/dist/utils/hooks/useOnResizeContent.js.map +1 -1
  201. package/dist/utils/hooks/useSizeHandle.js +1 -0
  202. package/dist/utils/hooks/useSizeHandle.js.map +1 -1
  203. package/dist/utils/smooth/useSmooth.d.ts.map +1 -1
  204. package/dist/utils/smooth/useSmooth.js +2 -2
  205. package/dist/utils/smooth/useSmooth.js.map +1 -1
  206. package/package.json +20 -20
  207. package/src/client/ExternalThread.ts +341 -53
  208. package/src/legacy-runtime/cloud/auiV0.ts +14 -0
  209. package/src/legacy-runtime/runtime-cores/assistant-transport/commandQueue.ts +4 -1
  210. package/src/legacy-runtime/runtime-cores/assistant-transport/runManager.ts +37 -10
  211. package/src/legacy-runtime/runtime-cores/assistant-transport/transport-delivery.test.tsx +79 -0
  212. package/src/legacy-runtime/runtime-cores/assistant-transport/transport-parentid.test.tsx +97 -0
  213. package/src/legacy-runtime/runtime-cores/assistant-transport/transport-scheduling.test.ts +113 -2
  214. package/src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransport.spec.md +10 -2
  215. package/src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.test.tsx +189 -0
  216. package/src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.ts +20 -4
  217. package/src/model-context/makeAssistantVisible.test.tsx +146 -0
  218. package/src/model-context/makeAssistantVisible.tsx +18 -1
  219. package/src/primitives/actionBar/useActionBarFloatStatus.ts +7 -5
  220. package/src/primitives/composer/ComposerAddAttachment.test.tsx +108 -0
  221. package/src/primitives/composer/ComposerAddAttachment.ts +10 -4
  222. package/src/primitives/composer/ComposerAttachmentDropzone.test.tsx +3 -2
  223. package/src/primitives/composer/ComposerAttachmentDropzone.tsx +3 -2
  224. package/src/primitives/composer/ComposerInput.test.tsx +98 -1
  225. package/src/primitives/composer/ComposerInput.tsx +10 -8
  226. package/src/primitives/composer/ComposerRoot.test.tsx +226 -5
  227. package/src/primitives/composer/ComposerRoot.tsx +50 -1
  228. package/src/primitives/messagePart/useMessagePartData.ts +3 -2
  229. package/src/primitives/messagePart/useMessagePartFile.ts +19 -7
  230. package/src/primitives/messagePart/useMessagePartImage.ts +18 -7
  231. package/src/primitives/messagePart/useMessagePartReasoning.ts +15 -6
  232. package/src/primitives/messagePart/useMessagePartSource.ts +20 -7
  233. package/src/primitives/messagePart/useMessagePartText.ts +15 -5
  234. package/src/primitives/thread/ThreadViewport.tsx +15 -0
  235. package/src/primitives/thread/topAnchor/mountTopAnchorReserve.test.ts +243 -0
  236. package/src/primitives/thread/topAnchor/mountTopAnchorReserve.ts +28 -7
  237. package/src/primitives/thread/topAnchor/topAnchorTurn.test.ts +69 -0
  238. package/src/primitives/thread/topAnchor/topAnchorTurn.ts +29 -0
  239. package/src/primitives/thread/useThreadViewportAutoScroll.test.tsx +86 -1
  240. package/src/primitives/thread/useThreadViewportAutoScroll.ts +6 -1
  241. package/src/tests/DataRenderers.test.tsx +212 -0
  242. package/src/tests/RemoteThreadListRuntime.adapterProvider.test.tsx +1 -11
  243. package/src/tests/external-thread-attachments.test.tsx +372 -0
  244. package/src/tests/external-thread-parity.test.tsx +232 -0
  245. package/src/tests/generative-ui.test.tsx +1 -46
  246. package/src/tests/messagePartSwitchRace.test.tsx +172 -0
  247. package/src/tests/messagePartTypeMismatch.test.tsx +146 -0
  248. package/src/tests/threadMessageById.test.tsx +0 -7
  249. package/src/utils/smooth/useSmooth.ts +7 -4
  250. package/src/tests/BaseComposerRuntimeCore.test.ts +0 -612
  251. package/src/tests/BaseSubscribable.test.ts +0 -54
  252. package/src/tests/DataRenderers.test.ts +0 -355
  253. package/src/tests/ExternalStoreThreadRuntimeCore.test.ts +0 -685
  254. package/src/tests/LocalThreadRuntimeCore.test.ts +0 -324
  255. package/src/tests/auiV0Encode.test.ts +0 -188
  256. package/src/tests/external-message-converter.test.ts +0 -346
  257. package/src/tests/shouldContinue.test.ts +0 -122
@@ -2,35 +2,47 @@ import { SingleThreadList } from "./SingleThreadList.js";
2
2
  import { Derived, attachTransformScopes, useClientLookup, useClientResource } from "@assistant-ui/store";
3
3
  import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
4
4
  import { DataRenderers, Tools } from "@assistant-ui/core/react";
5
- import { useEffect, useEffectEvent, useState } from "@assistant-ui/tap/react-shim";
5
+ import { useEffect, useEffectEvent, useRef, useState } from "@assistant-ui/tap/react-shim";
6
+ import { ToolResponse } from "assistant-stream";
6
7
  import { ModelContext, Suggestions } from "@assistant-ui/core/store";
7
8
  import { resource, withKey } from "@assistant-ui/tap";
8
- import { getThreadMessageText, resolveToolApprovalResponse } from "@assistant-ui/core/internal";
9
+ import { fileMatchesAccept, getThreadMessageText, isCreateAttachment, resolveToolApprovalResponse } from "@assistant-ui/core/internal";
9
10
  //#region src/client/ExternalThread.ts
10
11
  const EMPTY_QUEUE_ITEMS = [];
11
12
  const EMPTY_BRANCH_IDS = [];
13
+ const COMPLETE_STATUS = Object.freeze({ type: "complete" });
14
+ const derivePartStatus = (message, partIndex, part) => {
15
+ if (message.role !== "assistant" || !message.status) return COMPLETE_STATUS;
16
+ if (part.type === "tool-call") {
17
+ if (!part.result) return message.status;
18
+ return COMPLETE_STATUS;
19
+ }
20
+ const isLastPart = partIndex === Math.max(0, message.content.length - 1);
21
+ if (message.status.type === "requires-action") return COMPLETE_STATUS;
22
+ return isLastPart ? message.status : COMPLETE_STATUS;
23
+ };
12
24
  const useMessageClient = (t0) => {
13
- const $ = c(62);
14
- const { message, index, onEdit, onReload, queue, branches, onRespondToToolApproval } = t0;
25
+ const $ = c(65);
26
+ const { message, index, parentId, onEdit, onReload, queue, branches, onRespondToToolApproval, onAddToolResult, onResumeToolCall, attachmentAdapter } = t0;
15
27
  const [isCopied, setIsCopied] = useState(false);
16
28
  const [isHovering, setIsHovering] = useState(false);
17
29
  const [isEditing, setIsEditing] = useState(false);
18
30
  let t1;
19
- if ($[0] !== message.content || $[1] !== onRespondToToolApproval) {
20
- let t2;
21
- if ($[3] !== onRespondToToolApproval) {
22
- t2 = (part, idx) => withKey(idx, PartResource({
23
- part,
24
- onRespondToToolApproval
25
- }));
26
- $[3] = onRespondToToolApproval;
27
- $[4] = t2;
28
- } else t2 = $[4];
29
- t1 = message.content.map(t2);
30
- $[0] = message.content;
31
- $[1] = onRespondToToolApproval;
32
- $[2] = t1;
33
- } else t1 = $[2];
31
+ if ($[0] !== message || $[1] !== onAddToolResult || $[2] !== onRespondToToolApproval || $[3] !== onResumeToolCall) {
32
+ t1 = message.content.map((part, idx) => withKey(idx, PartResource({
33
+ part,
34
+ status: derivePartStatus(message, idx, part),
35
+ messageId: message.id,
36
+ onRespondToToolApproval,
37
+ onAddToolResult,
38
+ onResumeToolCall
39
+ })));
40
+ $[0] = message;
41
+ $[1] = onAddToolResult;
42
+ $[2] = onRespondToToolApproval;
43
+ $[3] = onResumeToolCall;
44
+ $[4] = t1;
45
+ } else t1 = $[4];
34
46
  const partClients = useClientLookup(t1);
35
47
  let t2;
36
48
  if ($[5] !== message.attachments) {
@@ -62,24 +74,25 @@ const useMessageClient = (t0) => {
62
74
  } else t5 = $[10];
63
75
  const handleCancelEdit = t5;
64
76
  let t6;
65
- if ($[11] !== message.id || $[12] !== onEdit || $[13] !== queue) {
77
+ if ($[11] !== message.id || $[12] !== onEdit || $[13] !== parentId || $[14] !== queue) {
66
78
  t6 = (msg) => {
67
79
  queue?.clear("edit");
68
80
  onEdit?.({
69
81
  ...msg,
70
- parentId: message.id,
82
+ parentId,
71
83
  sourceId: message.id
72
84
  });
73
85
  setIsEditing(false);
74
86
  };
75
87
  $[11] = message.id;
76
88
  $[12] = onEdit;
77
- $[13] = queue;
78
- $[14] = t6;
79
- } else t6 = $[14];
89
+ $[13] = parentId;
90
+ $[14] = queue;
91
+ $[15] = t6;
92
+ } else t6 = $[15];
80
93
  const handleSendEdit = t6;
81
94
  let t7;
82
- if ($[15] !== handleSendEdit || $[16] !== isEditing || $[17] !== message || $[18] !== queue) {
95
+ if ($[16] !== attachmentAdapter || $[17] !== handleSendEdit || $[18] !== isEditing || $[19] !== message || $[20] !== queue) {
83
96
  t7 = ComposerClientResource({
84
97
  type: "edit",
85
98
  isEditing,
@@ -88,43 +101,45 @@ const useMessageClient = (t0) => {
88
101
  onBeginEdit: handleBeginEdit,
89
102
  onSend: handleSendEdit,
90
103
  message,
91
- queue
104
+ queue,
105
+ attachmentAdapter
92
106
  });
93
- $[15] = handleSendEdit;
94
- $[16] = isEditing;
95
- $[17] = message;
96
- $[18] = queue;
97
- $[19] = t7;
98
- } else t7 = $[19];
107
+ $[16] = attachmentAdapter;
108
+ $[17] = handleSendEdit;
109
+ $[18] = isEditing;
110
+ $[19] = message;
111
+ $[20] = queue;
112
+ $[21] = t7;
113
+ } else t7 = $[21];
99
114
  const composerClient = useClientResource(t7);
100
115
  let branchIds;
101
116
  let t8;
102
- if ($[20] !== branches || $[21] !== message.id) {
117
+ if ($[22] !== branches || $[23] !== message.id) {
103
118
  branchIds = branches?.getBranches(message.id) ?? EMPTY_BRANCH_IDS;
104
119
  t8 = branchIds.indexOf(message.id);
105
- $[20] = branches;
106
- $[21] = message.id;
107
- $[22] = branchIds;
108
- $[23] = t8;
120
+ $[22] = branches;
121
+ $[23] = message.id;
122
+ $[24] = branchIds;
123
+ $[25] = t8;
109
124
  } else {
110
- branchIds = $[22];
111
- t8 = $[23];
125
+ branchIds = $[24];
126
+ t8 = $[25];
112
127
  }
113
128
  const branchIndex = t8;
114
129
  const branchNumber = branchIndex === -1 ? 1 : branchIndex + 1;
115
130
  const branchCount = branchIndex === -1 ? 1 : branchIds.length;
116
131
  let t9;
117
- if ($[24] !== message.attachments) {
132
+ if ($[26] !== message.attachments) {
118
133
  t9 = message.attachments ?? [];
119
- $[24] = message.attachments;
120
- $[25] = t9;
121
- } else t9 = $[25];
134
+ $[26] = message.attachments;
135
+ $[27] = t9;
136
+ } else t9 = $[27];
122
137
  let t10;
123
- if ($[26] !== branchCount || $[27] !== branchNumber || $[28] !== composerClient.state || $[29] !== index || $[30] !== isCopied || $[31] !== isHovering || $[32] !== message || $[33] !== partClients.state || $[34] !== t9) {
138
+ if ($[28] !== branchCount || $[29] !== branchNumber || $[30] !== composerClient.state || $[31] !== index || $[32] !== isCopied || $[33] !== isHovering || $[34] !== message || $[35] !== parentId || $[36] !== partClients.state || $[37] !== t9) {
124
139
  t10 = {
125
140
  ...message,
126
141
  attachments: t9,
127
- parentId: null,
142
+ parentId,
128
143
  isLast: false,
129
144
  branchNumber,
130
145
  branchCount,
@@ -135,80 +150,81 @@ const useMessageClient = (t0) => {
135
150
  index,
136
151
  composer: composerClient.state
137
152
  };
138
- $[26] = branchCount;
139
- $[27] = branchNumber;
140
- $[28] = composerClient.state;
141
- $[29] = index;
142
- $[30] = isCopied;
143
- $[31] = isHovering;
144
- $[32] = message;
145
- $[33] = partClients.state;
146
- $[34] = t9;
147
- $[35] = t10;
148
- } else t10 = $[35];
153
+ $[28] = branchCount;
154
+ $[29] = branchNumber;
155
+ $[30] = composerClient.state;
156
+ $[31] = index;
157
+ $[32] = isCopied;
158
+ $[33] = isHovering;
159
+ $[34] = message;
160
+ $[35] = parentId;
161
+ $[36] = partClients.state;
162
+ $[37] = t9;
163
+ $[38] = t10;
164
+ } else t10 = $[38];
149
165
  const state = t10;
150
166
  let t11;
151
- if ($[36] !== state) {
167
+ if ($[39] !== state) {
152
168
  t11 = () => state;
153
- $[36] = state;
154
- $[37] = t11;
155
- } else t11 = $[37];
169
+ $[39] = state;
170
+ $[40] = t11;
171
+ } else t11 = $[40];
156
172
  let t12;
157
- if ($[38] !== composerClient.methods) {
173
+ if ($[41] !== composerClient.methods) {
158
174
  t12 = () => composerClient.methods;
159
- $[38] = composerClient.methods;
160
- $[39] = t12;
161
- } else t12 = $[39];
175
+ $[41] = composerClient.methods;
176
+ $[42] = t12;
177
+ } else t12 = $[42];
162
178
  let t13;
163
- if ($[40] !== onReload) {
179
+ if ($[43] !== onReload) {
164
180
  t13 = () => {
165
181
  onReload?.();
166
182
  };
167
- $[40] = onReload;
168
- $[41] = t13;
169
- } else t13 = $[41];
183
+ $[43] = onReload;
184
+ $[44] = t13;
185
+ } else t13 = $[44];
170
186
  let t14;
171
- if ($[42] !== branchIds || $[43] !== branchIndex || $[44] !== branches || $[45] !== message.id) {
187
+ if ($[45] !== branchIds || $[46] !== branchIndex || $[47] !== branches || $[48] !== message.id) {
172
188
  t14 = (t15) => {
173
189
  const { position, branchId } = t15;
174
190
  if (!branches) return;
175
191
  const target = branchId ?? (branchIndex === -1 ? void 0 : position === "previous" ? branchIds[branchIndex - 1] : position === "next" ? branchIds[branchIndex + 1] : void 0);
176
192
  if (target !== void 0 && target !== message.id) branches.switchToBranch(target);
177
193
  };
178
- $[42] = branchIds;
179
- $[43] = branchIndex;
180
- $[44] = branches;
181
- $[45] = message.id;
182
- $[46] = t14;
183
- } else t14 = $[46];
194
+ $[45] = branchIds;
195
+ $[46] = branchIndex;
196
+ $[47] = branches;
197
+ $[48] = message.id;
198
+ $[49] = t14;
199
+ } else t14 = $[49];
184
200
  let t15;
185
- if ($[47] !== message) {
201
+ if ($[50] !== message) {
186
202
  t15 = () => getThreadMessageText(message);
187
- $[47] = message;
188
- $[48] = t15;
189
- } else t15 = $[48];
203
+ $[50] = message;
204
+ $[51] = t15;
205
+ } else t15 = $[51];
190
206
  let t16;
191
- if ($[49] !== partClients || $[50] !== state) {
207
+ if ($[52] !== partClients || $[53] !== state) {
192
208
  t16 = (selector) => {
193
209
  if ("index" in selector) return partClients.get(selector);
194
210
  const partIndex = state.parts.findIndex((p) => p.type === "tool-call" && p.toolCallId === selector.toolCallId);
195
211
  return partClients.get({ index: partIndex });
196
212
  };
197
- $[49] = partClients;
198
- $[50] = state;
199
- $[51] = t16;
200
- } else t16 = $[51];
213
+ $[52] = partClients;
214
+ $[53] = state;
215
+ $[54] = t16;
216
+ } else t16 = $[54];
201
217
  let t17;
202
- if ($[52] !== attachmentClients) {
218
+ if ($[55] !== attachmentClients) {
203
219
  t17 = (selector_0) => {
204
220
  if ("id" in selector_0) return attachmentClients.get({ key: selector_0.id });
205
221
  return attachmentClients.get(selector_0);
206
222
  };
207
- $[52] = attachmentClients;
208
- $[53] = t17;
209
- } else t17 = $[53];
223
+ $[55] = attachmentClients;
224
+ $[56] = t17;
225
+ } else t17 = $[56];
210
226
  let t18;
211
- if ($[54] !== t11 || $[55] !== t12 || $[56] !== t13 || $[57] !== t14 || $[58] !== t15 || $[59] !== t16 || $[60] !== t17) {
227
+ if ($[57] !== t11 || $[58] !== t12 || $[59] !== t13 || $[60] !== t14 || $[61] !== t15 || $[62] !== t16 || $[63] !== t17) {
212
228
  t18 = {
213
229
  getState: t11,
214
230
  composer: t12,
@@ -224,74 +240,107 @@ const useMessageClient = (t0) => {
224
240
  setIsCopied,
225
241
  setIsHovering
226
242
  };
227
- $[54] = t11;
228
- $[55] = t12;
229
- $[56] = t13;
230
- $[57] = t14;
231
- $[58] = t15;
232
- $[59] = t16;
233
- $[60] = t17;
234
- $[61] = t18;
235
- } else t18 = $[61];
243
+ $[57] = t11;
244
+ $[58] = t12;
245
+ $[59] = t13;
246
+ $[60] = t14;
247
+ $[61] = t15;
248
+ $[62] = t16;
249
+ $[63] = t17;
250
+ $[64] = t18;
251
+ } else t18 = $[64];
236
252
  return t18;
237
253
  };
238
254
  const MessageClient = resource(useMessageClient);
239
255
  const usePartResource = (t0) => {
240
- const $ = c(11);
241
- const { part, onRespondToToolApproval } = t0;
256
+ const $ = c(20);
257
+ const { part, status, messageId, onRespondToToolApproval, onAddToolResult, onResumeToolCall } = t0;
242
258
  let t1;
243
- if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
244
- t1 = { type: "complete" };
245
- $[0] = t1;
246
- } else t1 = $[0];
247
- let t2;
248
- if ($[1] !== part) {
249
- t2 = {
259
+ if ($[0] !== part || $[1] !== status) {
260
+ t1 = {
250
261
  ...part,
251
- status: t1
262
+ status
252
263
  };
253
- $[1] = part;
254
- $[2] = t2;
255
- } else t2 = $[2];
256
- const state = t2;
257
- let t3;
264
+ $[0] = part;
265
+ $[1] = status;
266
+ $[2] = t1;
267
+ } else t1 = $[2];
268
+ const state = t1;
269
+ let t2;
258
270
  if ($[3] !== state) {
259
- t3 = () => state;
271
+ t2 = () => state;
260
272
  $[3] = state;
261
- $[4] = t3;
262
- } else t3 = $[4];
273
+ $[4] = t2;
274
+ } else t2 = $[4];
275
+ let t3;
276
+ if ($[5] !== messageId || $[6] !== onAddToolResult || $[7] !== part) {
277
+ t3 = (result) => {
278
+ if (!onAddToolResult) throw new Error("Runtime does not support tool results (onAddToolResult is not set).");
279
+ if (part.type !== "tool-call") throw new Error("Tried to add tool result on non-tool message part");
280
+ const response = ToolResponse.toResponse(result);
281
+ onAddToolResult({
282
+ messageId,
283
+ toolName: part.toolName,
284
+ toolCallId: part.toolCallId,
285
+ result: response.result,
286
+ isError: response.isError,
287
+ ...response.artifact !== void 0 && { artifact: response.artifact },
288
+ ...response.modelContent !== void 0 && { modelContent: response.modelContent }
289
+ });
290
+ };
291
+ $[5] = messageId;
292
+ $[6] = onAddToolResult;
293
+ $[7] = part;
294
+ $[8] = t3;
295
+ } else t3 = $[8];
263
296
  let t4;
264
- if ($[5] !== onRespondToToolApproval || $[6] !== part) {
265
- t4 = (response) => {
297
+ if ($[9] !== onResumeToolCall || $[10] !== part) {
298
+ t4 = (payload) => {
299
+ if (!onResumeToolCall) throw new Error("Runtime does not support resuming tool calls (onResumeToolCall is not set).");
300
+ if (part.type !== "tool-call") throw new Error("Tried to resume tool call on non-tool message part");
301
+ onResumeToolCall({
302
+ toolCallId: part.toolCallId,
303
+ payload
304
+ });
305
+ };
306
+ $[9] = onResumeToolCall;
307
+ $[10] = part;
308
+ $[11] = t4;
309
+ } else t4 = $[11];
310
+ let t5;
311
+ if ($[12] !== onRespondToToolApproval || $[13] !== part) {
312
+ t5 = (response_0) => {
266
313
  if (!onRespondToToolApproval) throw new Error("Runtime does not support tool approvals.");
267
314
  if (part.type !== "tool-call") throw new Error("Tried to respond to tool approval on non-tool message part");
268
315
  if (!part.approval || part.approval.approved !== void 0 || part.approval.resolution !== void 0) throw new Error("Tool call has no pending approval");
269
- onRespondToToolApproval(resolveToolApprovalResponse(part.approval, response));
316
+ onRespondToToolApproval(resolveToolApprovalResponse(part.approval, response_0));
270
317
  };
271
- $[5] = onRespondToToolApproval;
272
- $[6] = part;
273
- $[7] = t4;
274
- } else t4 = $[7];
275
- let t5;
276
- if ($[8] !== t3 || $[9] !== t4) {
277
- t5 = {
278
- getState: t3,
279
- addToolResult: _temp7,
280
- resumeToolCall: _temp8,
281
- respondToToolApproval: t4
318
+ $[12] = onRespondToToolApproval;
319
+ $[13] = part;
320
+ $[14] = t5;
321
+ } else t5 = $[14];
322
+ let t6;
323
+ if ($[15] !== t2 || $[16] !== t3 || $[17] !== t4 || $[18] !== t5) {
324
+ t6 = {
325
+ getState: t2,
326
+ addToolResult: t3,
327
+ resumeToolCall: t4,
328
+ respondToToolApproval: t5
282
329
  };
283
- $[8] = t3;
284
- $[9] = t4;
285
- $[10] = t5;
286
- } else t5 = $[10];
287
- return t5;
330
+ $[15] = t2;
331
+ $[16] = t3;
332
+ $[17] = t4;
333
+ $[18] = t5;
334
+ $[19] = t6;
335
+ } else t6 = $[19];
336
+ return t6;
288
337
  };
289
338
  const PartResource = resource(usePartResource);
290
339
  const useAttachmentResource = ({ attachment, onRemove }) => {
291
340
  return {
292
341
  getState: () => attachment,
293
342
  remove: async () => {
294
- onRemove?.();
343
+ await onRemove?.();
295
344
  }
296
345
  };
297
346
  };
@@ -304,136 +353,217 @@ const useQueueItemClient = ({ item, onSteer, onRemove }) => {
304
353
  };
305
354
  };
306
355
  const QueueItemClient = resource(useQueueItemClient);
356
+ const drainAdapterAdd = async (result, upsert) => {
357
+ if (Symbol.asyncIterator in result) for await (const attachment of result) upsert(attachment);
358
+ else upsert(await result);
359
+ };
360
+ const useLiveState = (initial) => {
361
+ const $ = c(3);
362
+ const [state, setState] = useState(initial);
363
+ const ref = useRef(state);
364
+ let t0;
365
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
366
+ t0 = (next) => {
367
+ ref.current = typeof next === "function" ? next(ref.current) : next;
368
+ setState(ref.current);
369
+ };
370
+ $[0] = t0;
371
+ } else t0 = $[0];
372
+ const set = t0;
373
+ let t1;
374
+ if ($[1] !== state) {
375
+ t1 = [
376
+ state,
377
+ set,
378
+ ref
379
+ ];
380
+ $[1] = state;
381
+ $[2] = t1;
382
+ } else t1 = $[2];
383
+ return t1;
384
+ };
307
385
  const useComposerClientResource = (t0) => {
308
- const $ = c(60);
309
- const { type, isEditing, canCancel, isSendDisabled: t1, onCancel, onBeginEdit, onSend, message, queue } = t0;
386
+ const $ = c(96);
387
+ const { type, isEditing, canCancel, isSendDisabled: t1, onCancel, onBeginEdit, onSend, message, queue, attachmentAdapter } = t0;
310
388
  const isSendDisabled = t1 === void 0 ? false : t1;
311
- const [text, setText] = useState("");
312
- const [role, setRole] = useState("user");
389
+ const [text, setText, textRef] = useLiveState("");
390
+ const [role, setRole, roleRef] = useLiveState("user");
313
391
  let t2;
314
392
  if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
315
393
  t2 = {};
316
394
  $[0] = t2;
317
395
  } else t2 = $[0];
318
- const [runConfig, setRunConfig] = useState(t2);
396
+ const [runConfig, setRunConfig, runConfigRef] = useLiveState(t2);
319
397
  let t3;
320
398
  if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
321
399
  t3 = [];
322
400
  $[1] = t3;
323
401
  } else t3 = $[1];
324
- const [attachments, setAttachments] = useState(t3);
325
- const [quote, setQuote] = useState(void 0);
402
+ const [attachments, setAttachments, attachmentsRef] = useLiveState(t3);
403
+ const [quote, setQuote, quoteRef] = useLiveState(void 0);
326
404
  let t4;
327
- if ($[2] !== message) {
405
+ if ($[2] !== message || $[3] !== setAttachments || $[4] !== setRole || $[5] !== setText) {
328
406
  t4 = () => {
329
407
  if (message) {
330
- const messageText = message.content.filter(_temp9).map(_temp0).join("\n\n");
408
+ const messageText = message.content.filter(_temp7).map(_temp8).join("\n\n");
331
409
  setText(messageText);
332
410
  setRole(message.role);
333
411
  setAttachments(message.attachments ?? []);
334
412
  }
335
413
  };
336
414
  $[2] = message;
337
- $[3] = t4;
338
- } else t4 = $[3];
415
+ $[3] = setAttachments;
416
+ $[4] = setRole;
417
+ $[5] = setText;
418
+ $[6] = t4;
419
+ } else t4 = $[6];
339
420
  const updateFromMessage = useEffectEvent(t4);
340
421
  let t5;
341
- if ($[4] !== isEditing || $[5] !== updateFromMessage) {
422
+ if ($[7] !== isEditing || $[8] !== updateFromMessage) {
342
423
  t5 = () => {
343
424
  if (isEditing) updateFromMessage();
344
425
  };
345
- $[4] = isEditing;
346
- $[5] = updateFromMessage;
347
- $[6] = t5;
348
- } else t5 = $[6];
426
+ $[7] = isEditing;
427
+ $[8] = updateFromMessage;
428
+ $[9] = t5;
429
+ } else t5 = $[9];
349
430
  let t6;
350
- if ($[7] !== isEditing) {
431
+ if ($[10] !== isEditing) {
351
432
  t6 = [isEditing];
352
- $[7] = isEditing;
353
- $[8] = t6;
354
- } else t6 = $[8];
433
+ $[10] = isEditing;
434
+ $[11] = t6;
435
+ } else t6 = $[11];
355
436
  useEffect(t5, t6);
356
437
  let t7;
357
- if ($[9] !== attachments) {
358
- t7 = attachments.map((attachment, idx) => withKey(attachment.id, AttachmentResource({
359
- attachment,
360
- onRemove: () => {
361
- setAttachments(attachments.filter((_, i) => i !== idx));
362
- }
363
- })));
364
- $[9] = attachments;
365
- $[10] = t7;
366
- } else t7 = $[10];
438
+ if ($[12] !== attachmentAdapter || $[13] !== attachments || $[14] !== setAttachments) {
439
+ let t8;
440
+ if ($[16] !== attachmentAdapter || $[17] !== setAttachments) {
441
+ t8 = (attachment) => withKey(attachment.id, AttachmentResource({
442
+ attachment,
443
+ onRemove: async () => {
444
+ await attachmentAdapter?.remove(attachment);
445
+ setAttachments((prev) => prev.filter((a) => a.id !== attachment.id));
446
+ }
447
+ }));
448
+ $[16] = attachmentAdapter;
449
+ $[17] = setAttachments;
450
+ $[18] = t8;
451
+ } else t8 = $[18];
452
+ t7 = attachments.map(t8);
453
+ $[12] = attachmentAdapter;
454
+ $[13] = attachments;
455
+ $[14] = setAttachments;
456
+ $[15] = t7;
457
+ } else t7 = $[15];
367
458
  const attachmentClients = useClientLookup(t7);
368
- const queueItems = queue?.items ?? EMPTY_QUEUE_ITEMS;
369
459
  let t8;
370
- if ($[11] !== queue || $[12] !== queueItems) {
371
- let t9;
372
- if ($[14] !== queue) {
373
- t9 = (item) => withKey(item.id, QueueItemClient({
460
+ if ($[19] !== attachmentAdapter) {
461
+ t8 = async (removed) => {
462
+ if (!attachmentAdapter) return;
463
+ await Promise.all(removed.filter(_temp9).map((a_1) => attachmentAdapter.remove(a_1)));
464
+ };
465
+ $[19] = attachmentAdapter;
466
+ $[20] = t8;
467
+ } else t8 = $[20];
468
+ const removePendingAttachments = t8;
469
+ let t9;
470
+ if ($[21] !== setAttachments) {
471
+ t9 = (attachment_0) => {
472
+ setAttachments((prev_0) => {
473
+ const idx = prev_0.findIndex((a_2) => a_2.id === attachment_0.id);
474
+ if (idx === -1) return [...prev_0, attachment_0];
475
+ const next = [...prev_0];
476
+ next[idx] = attachment_0;
477
+ return next;
478
+ });
479
+ };
480
+ $[21] = setAttachments;
481
+ $[22] = t9;
482
+ } else t9 = $[22];
483
+ const upsertAttachment = t9;
484
+ const queueItems = queue?.items ?? EMPTY_QUEUE_ITEMS;
485
+ let t10;
486
+ if ($[23] !== queue || $[24] !== queueItems) {
487
+ let t11;
488
+ if ($[26] !== queue) {
489
+ t11 = (item) => withKey(item.id, QueueItemClient({
374
490
  item,
375
491
  onSteer: () => queue?.steer(item.id),
376
492
  onRemove: () => queue?.remove(item.id)
377
493
  }));
378
- $[14] = queue;
379
- $[15] = t9;
380
- } else t9 = $[15];
381
- t8 = queueItems.map(t9);
382
- $[11] = queue;
383
- $[12] = queueItems;
384
- $[13] = t8;
385
- } else t8 = $[13];
386
- const queueItemClients = useClientLookup(t8);
387
- let t9;
388
- if ($[16] !== attachments.length || $[17] !== text) {
389
- t9 = !text.trim() && !attachments.length;
390
- $[16] = attachments.length;
391
- $[17] = text;
392
- $[18] = t9;
393
- } else t9 = $[18];
394
- const isEmpty = t9;
395
- const t10 = isEditing && !isEmpty && !isSendDisabled;
494
+ $[26] = queue;
495
+ $[27] = t11;
496
+ } else t11 = $[27];
497
+ t10 = queueItems.map(t11);
498
+ $[23] = queue;
499
+ $[24] = queueItems;
500
+ $[25] = t10;
501
+ } else t10 = $[25];
502
+ const queueItemClients = useClientLookup(t10);
503
+ attachmentAdapter?.accept;
396
504
  let t11;
397
- if ($[19] !== attachmentClients.state || $[20] !== canCancel || $[21] !== isEditing || $[22] !== isEmpty || $[23] !== queueItems || $[24] !== quote || $[25] !== role || $[26] !== runConfig || $[27] !== t10 || $[28] !== text || $[29] !== type) {
398
- t11 = {
505
+ if ($[28] !== attachments.length || $[29] !== text) {
506
+ t11 = !text.trim() && !attachments.length;
507
+ $[28] = attachments.length;
508
+ $[29] = text;
509
+ $[30] = t11;
510
+ } else t11 = $[30];
511
+ const isEmpty = t11;
512
+ const t12 = isEditing && !isEmpty && !isSendDisabled;
513
+ const t13 = attachmentAdapter?.accept ?? "*";
514
+ let t14;
515
+ if ($[31] !== attachmentClients.state || $[32] !== canCancel || $[33] !== isEditing || $[34] !== isEmpty || $[35] !== queueItems || $[36] !== quote || $[37] !== role || $[38] !== runConfig || $[39] !== t12 || $[40] !== t13 || $[41] !== text || $[42] !== type) {
516
+ t14 = {
399
517
  text,
400
518
  role,
401
519
  attachments: attachmentClients.state,
402
520
  runConfig,
403
521
  isEditing,
404
522
  canCancel,
405
- canSend: t10,
406
- attachmentAccept: "*",
523
+ canSend: t12,
524
+ attachmentAccept: t13,
407
525
  isEmpty,
408
526
  type,
409
527
  dictation: void 0,
410
528
  quote,
411
529
  queue: queueItems
412
530
  };
413
- $[19] = attachmentClients.state;
414
- $[20] = canCancel;
415
- $[21] = isEditing;
416
- $[22] = isEmpty;
417
- $[23] = queueItems;
418
- $[24] = quote;
419
- $[25] = role;
420
- $[26] = runConfig;
421
- $[27] = t10;
422
- $[28] = text;
423
- $[29] = type;
424
- $[30] = t11;
425
- } else t11 = $[30];
426
- const state = t11;
427
- let t12;
428
- if ($[31] !== state) {
429
- t12 = () => state;
430
- $[31] = state;
431
- $[32] = t12;
432
- } else t12 = $[32];
433
- let t13;
434
- if ($[33] !== attachments) {
435
- t13 = async (fileOrAttachment) => {
436
- if (fileOrAttachment instanceof File) {
531
+ $[31] = attachmentClients.state;
532
+ $[32] = canCancel;
533
+ $[33] = isEditing;
534
+ $[34] = isEmpty;
535
+ $[35] = queueItems;
536
+ $[36] = quote;
537
+ $[37] = role;
538
+ $[38] = runConfig;
539
+ $[39] = t12;
540
+ $[40] = t13;
541
+ $[41] = text;
542
+ $[42] = type;
543
+ $[43] = t14;
544
+ } else t14 = $[43];
545
+ const state = t14;
546
+ let t15;
547
+ if ($[44] !== state) {
548
+ t15 = () => state;
549
+ $[44] = state;
550
+ $[45] = t15;
551
+ } else t15 = $[45];
552
+ let t16;
553
+ if ($[46] !== attachmentAdapter || $[47] !== setAttachments || $[48] !== upsertAttachment) {
554
+ t16 = async (fileOrAttachment) => {
555
+ if (attachmentAdapter) {
556
+ const file = isCreateAttachment(fileOrAttachment) ? {
557
+ name: fileOrAttachment.name,
558
+ type: fileOrAttachment.contentType ?? ""
559
+ } : {
560
+ name: fileOrAttachment.name,
561
+ type: fileOrAttachment.type
562
+ };
563
+ if (!fileMatchesAccept(file, attachmentAdapter.accept)) throw new Error(`File type ${file.type || "unknown"} is not accepted. Accepted types: ${attachmentAdapter.accept}`);
564
+ }
565
+ if (!isCreateAttachment(fileOrAttachment) && attachmentAdapter) await drainAdapterAdd(attachmentAdapter.add({ file: fileOrAttachment }), upsertAttachment);
566
+ else if (!isCreateAttachment(fileOrAttachment)) {
437
567
  const newAttachment = {
438
568
  id: Math.random().toString(36).substring(7),
439
569
  type: "file",
@@ -443,7 +573,7 @@ const useComposerClientResource = (t0) => {
443
573
  status: { type: "complete" },
444
574
  content: []
445
575
  };
446
- setAttachments([...attachments, newAttachment]);
576
+ setAttachments((prev_1) => [...prev_1, newAttachment]);
447
577
  } else {
448
578
  const newAttachment_0 = {
449
579
  id: fileOrAttachment.id ?? Math.random().toString(36).substring(7),
@@ -453,230 +583,318 @@ const useComposerClientResource = (t0) => {
453
583
  content: fileOrAttachment.content,
454
584
  status: { type: "complete" }
455
585
  };
456
- setAttachments([...attachments, newAttachment_0]);
586
+ setAttachments((prev_2) => [...prev_2, newAttachment_0]);
457
587
  }
458
588
  };
459
- $[33] = attachments;
460
- $[34] = t13;
461
- } else t13 = $[34];
462
- let t14;
463
- if ($[35] === Symbol.for("react.memo_cache_sentinel")) {
464
- t14 = async () => {
589
+ $[46] = attachmentAdapter;
590
+ $[47] = setAttachments;
591
+ $[48] = upsertAttachment;
592
+ $[49] = t16;
593
+ } else t16 = $[49];
594
+ let t17;
595
+ if ($[50] !== attachmentsRef || $[51] !== removePendingAttachments || $[52] !== setAttachments) {
596
+ t17 = async () => {
597
+ const removed_0 = attachmentsRef.current;
465
598
  setAttachments([]);
599
+ await removePendingAttachments(removed_0);
466
600
  };
467
- $[35] = t14;
468
- } else t14 = $[35];
469
- let t15;
470
- if ($[36] !== attachmentClients) {
471
- t15 = (selector) => {
601
+ $[50] = attachmentsRef;
602
+ $[51] = removePendingAttachments;
603
+ $[52] = setAttachments;
604
+ $[53] = t17;
605
+ } else t17 = $[53];
606
+ let t18;
607
+ if ($[54] !== attachmentClients) {
608
+ t18 = (selector) => {
472
609
  if ("id" in selector) return attachmentClients.get({ key: selector.id });
473
610
  return attachmentClients.get(selector);
474
611
  };
475
- $[36] = attachmentClients;
476
- $[37] = t15;
477
- } else t15 = $[37];
478
- let t16;
479
- if ($[38] === Symbol.for("react.memo_cache_sentinel")) {
480
- t16 = async () => {
612
+ $[54] = attachmentClients;
613
+ $[55] = t18;
614
+ } else t18 = $[55];
615
+ let t19;
616
+ if ($[56] !== attachmentsRef || $[57] !== removePendingAttachments || $[58] !== setAttachments || $[59] !== setQuote || $[60] !== setRole || $[61] !== setRunConfig || $[62] !== setText) {
617
+ t19 = async () => {
618
+ const removed_1 = attachmentsRef.current;
481
619
  setText("");
482
620
  setRole("user");
483
621
  setRunConfig({});
484
622
  setAttachments([]);
485
623
  setQuote(void 0);
624
+ await removePendingAttachments(removed_1);
486
625
  };
487
- $[38] = t16;
488
- } else t16 = $[38];
489
- let t17;
490
- if ($[39] !== attachments || $[40] !== onSend || $[41] !== queue || $[42] !== quote || $[43] !== role || $[44] !== runConfig || $[45] !== state || $[46] !== text) {
491
- t17 = (opts) => {
492
- if (!state.canSend) return;
493
- const currentQuote = quote;
494
- const composedMessage = {
495
- role,
496
- content: text ? [{
497
- type: "text",
498
- text
499
- }] : [],
500
- attachments,
501
- createdAt: /* @__PURE__ */ new Date(),
502
- parentId: null,
503
- sourceId: null,
504
- runConfig,
505
- startRun: opts?.startRun,
506
- metadata: { custom: { ...currentQuote ? { quote: currentQuote } : {} } }
507
- };
508
- if (queue) queue.enqueue(composedMessage, { steer: opts?.steer ?? false });
509
- else onSend?.(composedMessage);
626
+ $[56] = attachmentsRef;
627
+ $[57] = removePendingAttachments;
628
+ $[58] = setAttachments;
629
+ $[59] = setQuote;
630
+ $[60] = setRole;
631
+ $[61] = setRunConfig;
632
+ $[62] = setText;
633
+ $[63] = t19;
634
+ } else t19 = $[63];
635
+ let t20;
636
+ if ($[64] !== attachmentAdapter || $[65] !== attachmentsRef || $[66] !== isEditing || $[67] !== isSendDisabled || $[68] !== onSend || $[69] !== queue || $[70] !== quoteRef || $[71] !== roleRef || $[72] !== runConfigRef || $[73] !== setAttachments || $[74] !== setQuote || $[75] !== setText || $[76] !== textRef) {
637
+ t20 = (opts) => {
638
+ const currentQuote = quoteRef.current;
639
+ const currentText = textRef.current;
640
+ const currentAttachments = attachmentsRef.current;
641
+ const isEmpty_0 = !currentText.trim() && !currentAttachments.length;
642
+ if (!isEditing || isEmpty_0 || isSendDisabled) return;
510
643
  setText("");
511
644
  setAttachments([]);
512
645
  setQuote(void 0);
646
+ const dispatch = (sendAttachments) => {
647
+ const composedMessage = {
648
+ role: roleRef.current,
649
+ content: currentText ? [{
650
+ type: "text",
651
+ text: currentText
652
+ }] : [],
653
+ attachments: sendAttachments,
654
+ createdAt: /* @__PURE__ */ new Date(),
655
+ parentId: null,
656
+ sourceId: null,
657
+ runConfig: runConfigRef.current,
658
+ startRun: opts?.startRun,
659
+ metadata: { custom: { ...currentQuote ? { quote: currentQuote } : {} } }
660
+ };
661
+ if (queue) queue.enqueue(composedMessage, { steer: opts?.steer ?? false });
662
+ else onSend?.(composedMessage);
663
+ };
664
+ if (attachmentAdapter && currentAttachments.length > 0) Promise.all(currentAttachments.map((attachment_1) => attachment_1.status.type === "complete" ? attachment_1 : attachmentAdapter.send(attachment_1))).then(dispatch, (error) => {
665
+ setText((prev_3) => currentText && prev_3 ? currentText + "\n" + prev_3 : currentText || prev_3);
666
+ setQuote((prev_4) => prev_4 ?? currentQuote);
667
+ setAttachments((prev_5) => [...currentAttachments, ...prev_5]);
668
+ console.error("Failed to send attachments", error);
669
+ });
670
+ else dispatch(currentAttachments);
513
671
  };
514
- $[39] = attachments;
515
- $[40] = onSend;
516
- $[41] = queue;
517
- $[42] = quote;
518
- $[43] = role;
519
- $[44] = runConfig;
520
- $[45] = state;
521
- $[46] = text;
522
- $[47] = t17;
523
- } else t17 = $[47];
524
- let t18;
525
- if ($[48] !== onBeginEdit) {
526
- t18 = () => {
672
+ $[64] = attachmentAdapter;
673
+ $[65] = attachmentsRef;
674
+ $[66] = isEditing;
675
+ $[67] = isSendDisabled;
676
+ $[68] = onSend;
677
+ $[69] = queue;
678
+ $[70] = quoteRef;
679
+ $[71] = roleRef;
680
+ $[72] = runConfigRef;
681
+ $[73] = setAttachments;
682
+ $[74] = setQuote;
683
+ $[75] = setText;
684
+ $[76] = textRef;
685
+ $[77] = t20;
686
+ } else t20 = $[77];
687
+ let t21;
688
+ if ($[78] !== onBeginEdit) {
689
+ t21 = () => {
527
690
  onBeginEdit?.();
528
691
  };
529
- $[48] = onBeginEdit;
530
- $[49] = t18;
531
- } else t18 = $[49];
532
- let t19;
533
- if ($[50] !== queueItemClients) {
534
- t19 = (selector_0) => queueItemClients.get(selector_0);
535
- $[50] = queueItemClients;
536
- $[51] = t19;
537
- } else t19 = $[51];
538
- let t20;
539
- if ($[52] !== onCancel || $[53] !== t12 || $[54] !== t13 || $[55] !== t15 || $[56] !== t17 || $[57] !== t18 || $[58] !== t19) {
540
- t20 = {
541
- getState: t12,
692
+ $[78] = onBeginEdit;
693
+ $[79] = t21;
694
+ } else t21 = $[79];
695
+ let t22;
696
+ if ($[80] !== queueItemClients) {
697
+ t22 = (selector_0) => queueItemClients.get(selector_0);
698
+ $[80] = queueItemClients;
699
+ $[81] = t22;
700
+ } else t22 = $[81];
701
+ let t23;
702
+ if ($[82] !== onCancel || $[83] !== setQuote || $[84] !== setRole || $[85] !== setRunConfig || $[86] !== setText || $[87] !== t15 || $[88] !== t16 || $[89] !== t17 || $[90] !== t18 || $[91] !== t19 || $[92] !== t20 || $[93] !== t21 || $[94] !== t22) {
703
+ t23 = {
704
+ getState: t15,
542
705
  setText,
543
706
  setRole,
544
707
  setRunConfig,
545
- addAttachment: t13,
546
- clearAttachments: t14,
547
- attachment: t15,
548
- reset: t16,
549
- send: t17,
708
+ addAttachment: t16,
709
+ clearAttachments: t17,
710
+ attachment: t18,
711
+ reset: t19,
712
+ send: t20,
550
713
  cancel: onCancel,
551
- beginEdit: t18,
552
- startDictation: _temp1,
553
- stopDictation: _temp10,
714
+ beginEdit: t21,
715
+ startDictation: _temp0,
716
+ stopDictation: _temp1,
554
717
  setQuote,
555
- queueItem: t19
718
+ queueItem: t22
556
719
  };
557
- $[52] = onCancel;
558
- $[53] = t12;
559
- $[54] = t13;
560
- $[55] = t15;
561
- $[56] = t17;
562
- $[57] = t18;
563
- $[58] = t19;
564
- $[59] = t20;
565
- } else t20 = $[59];
566
- return t20;
720
+ $[82] = onCancel;
721
+ $[83] = setQuote;
722
+ $[84] = setRole;
723
+ $[85] = setRunConfig;
724
+ $[86] = setText;
725
+ $[87] = t15;
726
+ $[88] = t16;
727
+ $[89] = t17;
728
+ $[90] = t18;
729
+ $[91] = t19;
730
+ $[92] = t20;
731
+ $[93] = t21;
732
+ $[94] = t22;
733
+ $[95] = t23;
734
+ } else t23 = $[95];
735
+ return t23;
567
736
  };
568
737
  const ComposerClientResource = resource(useComposerClientResource);
738
+ const dedupeMessagesById = (messages) => {
739
+ const seenIds = /* @__PURE__ */ new Set();
740
+ const deduped = [];
741
+ for (let i = messages.length - 1; i >= 0; i--) {
742
+ const message = messages[i];
743
+ if (seenIds.has(message.id)) {
744
+ console.warn(`ExternalThread: duplicate message id "${message.id}" in the provided messages array; keeping the last occurrence.`);
745
+ continue;
746
+ }
747
+ seenIds.add(message.id);
748
+ deduped.push(message);
749
+ }
750
+ return deduped.length === messages.length ? messages : deduped.reverse();
751
+ };
569
752
  const useExternalThread = (t0) => {
570
- const $ = c(61);
571
- const { messages, isRunning: t1, isSendDisabled: t2, onNew, onEdit, onReload, onStartRun, onCancel, queue, branches, onRespondToToolApproval } = t0;
753
+ const $ = c(80);
754
+ const { messages: messagesProp, isRunning: t1, isLoading: t2, state: threadState, extras, isSendDisabled: t3, onNew, onEdit, onReload, onStartRun, onCancel, onResume, onAddToolResult, onResumeToolCall, onLoadExternalState, attachmentAdapter, queue, branches, onRespondToToolApproval } = t0;
572
755
  const isRunning = t1 === void 0 ? false : t1;
573
- const isSendDisabled = t2 === void 0 ? false : t2;
574
- let t3;
575
- if ($[0] !== messages || $[1] !== onReload || $[2] !== queue) {
576
- t3 = (messageId) => {
756
+ const isLoading = t2 === void 0 ? false : t2;
757
+ const isSendDisabled = t3 === void 0 ? false : t3;
758
+ let t4;
759
+ if ($[0] !== messagesProp) {
760
+ t4 = dedupeMessagesById(messagesProp);
761
+ $[0] = messagesProp;
762
+ $[1] = t4;
763
+ } else t4 = $[1];
764
+ const messages = t4;
765
+ let t5;
766
+ if ($[2] !== messages || $[3] !== onReload || $[4] !== queue) {
767
+ t5 = (messageId) => {
577
768
  const messageIndex = messages.findIndex((m) => m.id === messageId);
578
769
  if (messageIndex === -1) return;
579
770
  const parentId = messageIndex > 0 ? messages[messageIndex - 1].id : null;
580
771
  queue?.clear("reload");
581
772
  onReload?.(parentId);
582
773
  };
583
- $[0] = messages;
584
- $[1] = onReload;
585
- $[2] = queue;
586
- $[3] = t3;
587
- } else t3 = $[3];
588
- const handleReload = t3;
589
- let t4;
590
- if ($[4] !== branches || $[5] !== handleReload || $[6] !== messages || $[7] !== onEdit || $[8] !== onRespondToToolApproval || $[9] !== queue) {
591
- let t5;
592
- if ($[11] !== branches || $[12] !== handleReload || $[13] !== onEdit || $[14] !== onRespondToToolApproval || $[15] !== queue) {
593
- t5 = (msg, index) => {
594
- const props = {
595
- message: msg,
596
- index,
597
- onReload: () => handleReload(msg.id),
598
- queue,
599
- branches,
600
- onRespondToToolApproval
601
- };
602
- if (onEdit) props.onEdit = onEdit;
603
- return withKey(msg.id, MessageClient(props));
774
+ $[2] = messages;
775
+ $[3] = onReload;
776
+ $[4] = queue;
777
+ $[5] = t5;
778
+ } else t5 = $[5];
779
+ const handleReload = t5;
780
+ let t6;
781
+ if ($[6] !== attachmentAdapter || $[7] !== branches || $[8] !== handleReload || $[9] !== messages || $[10] !== onAddToolResult || $[11] !== onEdit || $[12] !== onRespondToToolApproval || $[13] !== onResumeToolCall || $[14] !== queue) {
782
+ t6 = messages.map((msg, index) => {
783
+ const props = {
784
+ message: msg,
785
+ index,
786
+ parentId: index > 0 ? messages[index - 1].id : null,
787
+ onReload: () => handleReload(msg.id),
788
+ queue,
789
+ branches,
790
+ onRespondToToolApproval,
791
+ onAddToolResult,
792
+ onResumeToolCall,
793
+ attachmentAdapter
604
794
  };
605
- $[11] = branches;
606
- $[12] = handleReload;
607
- $[13] = onEdit;
608
- $[14] = onRespondToToolApproval;
609
- $[15] = queue;
610
- $[16] = t5;
611
- } else t5 = $[16];
612
- t4 = messages.map(t5);
613
- $[4] = branches;
614
- $[5] = handleReload;
615
- $[6] = messages;
616
- $[7] = onEdit;
617
- $[8] = onRespondToToolApproval;
618
- $[9] = queue;
619
- $[10] = t4;
620
- } else t4 = $[10];
621
- const messageClients = useClientLookup(t4);
622
- let t5;
623
- if ($[17] !== onCancel || $[18] !== queue) {
624
- t5 = () => {
795
+ if (onEdit) props.onEdit = onEdit;
796
+ return withKey(msg.id, MessageClient(props));
797
+ });
798
+ $[6] = attachmentAdapter;
799
+ $[7] = branches;
800
+ $[8] = handleReload;
801
+ $[9] = messages;
802
+ $[10] = onAddToolResult;
803
+ $[11] = onEdit;
804
+ $[12] = onRespondToToolApproval;
805
+ $[13] = onResumeToolCall;
806
+ $[14] = queue;
807
+ $[15] = t6;
808
+ } else t6 = $[15];
809
+ const messageClients = useClientLookup(t6);
810
+ let t7;
811
+ if ($[16] !== onCancel || $[17] !== queue) {
812
+ t7 = () => {
625
813
  queue?.clear("cancel-run");
626
814
  onCancel?.();
627
815
  };
628
- $[17] = onCancel;
629
- $[18] = queue;
630
- $[19] = t5;
631
- } else t5 = $[19];
632
- const handleCancelRun = t5;
633
- let t6;
634
- if ($[20] !== onNew) {
635
- t6 = (message) => {
636
- onNew?.(message);
816
+ $[16] = onCancel;
817
+ $[17] = queue;
818
+ $[18] = t7;
819
+ } else t7 = $[18];
820
+ const handleCancelRun = t7;
821
+ let t8;
822
+ if ($[19] !== messages || $[20] !== onNew) {
823
+ t8 = (message) => {
824
+ onNew?.({
825
+ ...message,
826
+ parentId: messages.at(-1)?.id ?? null
827
+ });
637
828
  };
829
+ $[19] = messages;
638
830
  $[20] = onNew;
639
- $[21] = t6;
640
- } else t6 = $[21];
641
- const handleSendNew = t6;
642
- let t7;
643
- if ($[22] !== handleCancelRun || $[23] !== handleSendNew || $[24] !== isRunning || $[25] !== isSendDisabled || $[26] !== queue) {
644
- t7 = ComposerClientResource({
831
+ $[21] = t8;
832
+ } else t8 = $[21];
833
+ const handleSendNew = t8;
834
+ let t9;
835
+ if ($[22] !== messages) {
836
+ t9 = messages.at(-1)?.id ?? null;
837
+ $[22] = messages;
838
+ $[23] = t9;
839
+ } else t9 = $[23];
840
+ const headId = t9;
841
+ let t10;
842
+ if ($[24] !== headId || $[25] !== queue) {
843
+ t10 = queue && {
844
+ ...queue,
845
+ enqueue: (message_0, options) => queue.enqueue({
846
+ ...message_0,
847
+ parentId: message_0.parentId ?? headId
848
+ }, options)
849
+ };
850
+ $[24] = headId;
851
+ $[25] = queue;
852
+ $[26] = t10;
853
+ } else t10 = $[26];
854
+ const composerQueue = t10;
855
+ let t11;
856
+ if ($[27] !== attachmentAdapter || $[28] !== composerQueue || $[29] !== handleCancelRun || $[30] !== handleSendNew || $[31] !== isRunning || $[32] !== isSendDisabled) {
857
+ t11 = ComposerClientResource({
645
858
  type: "thread",
646
859
  isEditing: true,
647
860
  canCancel: isRunning,
648
861
  isSendDisabled,
649
862
  onCancel: handleCancelRun,
650
863
  onSend: handleSendNew,
651
- queue
864
+ queue: composerQueue,
865
+ attachmentAdapter
652
866
  });
653
- $[22] = handleCancelRun;
654
- $[23] = handleSendNew;
655
- $[24] = isRunning;
656
- $[25] = isSendDisabled;
657
- $[26] = queue;
658
- $[27] = t7;
659
- } else t7 = $[27];
660
- const composerClient = useClientResource(t7);
867
+ $[27] = attachmentAdapter;
868
+ $[28] = composerQueue;
869
+ $[29] = handleCancelRun;
870
+ $[30] = handleSendNew;
871
+ $[31] = isRunning;
872
+ $[32] = isSendDisabled;
873
+ $[33] = t11;
874
+ } else t11 = $[33];
875
+ const composerClient = useClientResource(t11);
661
876
  const hasQueue = !!queue;
662
877
  const hasBranches = !!branches;
663
- let t8;
664
- if ($[28] !== messageClients.state) {
665
- t8 = messageClients.state.map(_temp11);
666
- $[28] = messageClients.state;
667
- $[29] = t8;
668
- } else t8 = $[29];
669
- const messageStates = t8;
670
- const t9 = messages.length === 0;
671
- let t10;
672
- if ($[30] !== hasBranches || $[31] !== hasQueue || $[32] !== isRunning) {
673
- t10 = {
674
- edit: false,
878
+ const hasEdit = !!onEdit;
879
+ const hasReload = !!onReload;
880
+ const hasAttachments = !!attachmentAdapter;
881
+ let t12;
882
+ if ($[34] !== messageClients.state) {
883
+ t12 = messageClients.state.map(_temp10);
884
+ $[34] = messageClients.state;
885
+ $[35] = t12;
886
+ } else t12 = $[35];
887
+ const messageStates = t12;
888
+ const t13 = messages.length === 0;
889
+ let t14;
890
+ if ($[36] !== hasAttachments || $[37] !== hasBranches || $[38] !== hasEdit || $[39] !== hasQueue || $[40] !== hasReload || $[41] !== isRunning) {
891
+ t14 = {
892
+ edit: hasEdit,
675
893
  delete: false,
676
- reload: false,
894
+ reload: hasReload,
677
895
  cancel: isRunning,
678
896
  speech: false,
679
- attachments: false,
897
+ attachments: hasAttachments,
680
898
  feedback: false,
681
899
  voice: false,
682
900
  switchToBranch: hasBranches,
@@ -685,62 +903,68 @@ const useExternalThread = (t0) => {
685
903
  dictation: false,
686
904
  queue: hasQueue
687
905
  };
688
- $[30] = hasBranches;
689
- $[31] = hasQueue;
690
- $[32] = isRunning;
691
- $[33] = t10;
692
- } else t10 = $[33];
693
- let t11;
694
- let t12;
695
- if ($[34] === Symbol.for("react.memo_cache_sentinel")) {
696
- t11 = {};
697
- t12 = [];
698
- $[34] = t11;
699
- $[35] = t12;
700
- } else {
701
- t11 = $[34];
702
- t12 = $[35];
703
- }
704
- let t13;
705
- if ($[36] !== composerClient.state || $[37] !== isRunning || $[38] !== messageStates || $[39] !== t10 || $[40] !== t9) {
706
- t13 = {
707
- isEmpty: t9,
906
+ $[36] = hasAttachments;
907
+ $[37] = hasBranches;
908
+ $[38] = hasEdit;
909
+ $[39] = hasQueue;
910
+ $[40] = hasReload;
911
+ $[41] = isRunning;
912
+ $[42] = t14;
913
+ } else t14 = $[42];
914
+ let t15;
915
+ if ($[43] !== threadState) {
916
+ t15 = threadState ?? {};
917
+ $[43] = threadState;
918
+ $[44] = t15;
919
+ } else t15 = $[44];
920
+ let t16;
921
+ if ($[45] === Symbol.for("react.memo_cache_sentinel")) {
922
+ t16 = [];
923
+ $[45] = t16;
924
+ } else t16 = $[45];
925
+ let t17;
926
+ if ($[46] !== composerClient.state || $[47] !== extras || $[48] !== isLoading || $[49] !== isRunning || $[50] !== messageStates || $[51] !== t13 || $[52] !== t14 || $[53] !== t15) {
927
+ t17 = {
928
+ isEmpty: t13,
708
929
  isDisabled: false,
709
- isLoading: false,
930
+ isLoading,
710
931
  isRunning,
711
- capabilities: t10,
932
+ capabilities: t14,
712
933
  messages: messageStates,
713
- state: t11,
714
- suggestions: t12,
715
- extras: void 0,
934
+ state: t15,
935
+ suggestions: t16,
936
+ extras,
716
937
  speech: void 0,
717
938
  voice: void 0,
718
939
  composer: composerClient.state
719
940
  };
720
- $[36] = composerClient.state;
721
- $[37] = isRunning;
722
- $[38] = messageStates;
723
- $[39] = t10;
724
- $[40] = t9;
725
- $[41] = t13;
726
- } else t13 = $[41];
727
- const state = t13;
728
- let t14;
729
- if ($[42] !== state) {
730
- t14 = () => state;
731
- $[42] = state;
732
- $[43] = t14;
733
- } else t14 = $[43];
734
- let t15;
735
- if ($[44] !== composerClient.methods) {
736
- t15 = () => composerClient.methods;
737
- $[44] = composerClient.methods;
738
- $[45] = t15;
739
- } else t15 = $[45];
740
- let t16;
741
- if ($[46] !== messages || $[47] !== onNew || $[48] !== queue) {
742
- t16 = (message_0) => {
743
- const appendMessage = typeof message_0 === "string" ? {
941
+ $[46] = composerClient.state;
942
+ $[47] = extras;
943
+ $[48] = isLoading;
944
+ $[49] = isRunning;
945
+ $[50] = messageStates;
946
+ $[51] = t13;
947
+ $[52] = t14;
948
+ $[53] = t15;
949
+ $[54] = t17;
950
+ } else t17 = $[54];
951
+ const state = t17;
952
+ let t18;
953
+ if ($[55] !== state) {
954
+ t18 = () => state;
955
+ $[55] = state;
956
+ $[56] = t18;
957
+ } else t18 = $[56];
958
+ let t19;
959
+ if ($[57] !== composerClient.methods) {
960
+ t19 = () => composerClient.methods;
961
+ $[57] = composerClient.methods;
962
+ $[58] = t19;
963
+ } else t19 = $[58];
964
+ let t20;
965
+ if ($[59] !== messages || $[60] !== onNew || $[61] !== queue) {
966
+ t20 = (message_1) => {
967
+ const appendMessage = typeof message_1 === "string" ? {
744
968
  createdAt: /* @__PURE__ */ new Date(),
745
969
  parentId: messages.at(-1)?.id ?? null,
746
970
  sourceId: null,
@@ -748,78 +972,99 @@ const useExternalThread = (t0) => {
748
972
  role: "user",
749
973
  content: [{
750
974
  type: "text",
751
- text: message_0
975
+ text: message_1
752
976
  }],
753
977
  attachments: [],
754
978
  metadata: { custom: {} }
755
979
  } : {
756
- createdAt: message_0.createdAt ?? /* @__PURE__ */ new Date(),
757
- parentId: message_0.parentId ?? messages.at(-1)?.id ?? null,
758
- sourceId: message_0.sourceId ?? null,
759
- role: message_0.role ?? "user",
760
- content: message_0.content,
761
- attachments: message_0.attachments ?? [],
762
- metadata: message_0.metadata ?? { custom: {} },
763
- runConfig: message_0.runConfig ?? {},
764
- startRun: message_0.startRun
980
+ createdAt: message_1.createdAt ?? /* @__PURE__ */ new Date(),
981
+ parentId: message_1.parentId ?? messages.at(-1)?.id ?? null,
982
+ sourceId: message_1.sourceId ?? null,
983
+ role: message_1.role ?? "user",
984
+ content: message_1.content,
985
+ attachments: message_1.attachments ?? [],
986
+ metadata: message_1.metadata ?? { custom: {} },
987
+ runConfig: message_1.runConfig ?? {},
988
+ startRun: message_1.startRun
765
989
  };
766
990
  if (queue) queue.enqueue(appendMessage, { steer: false });
767
991
  else onNew?.(appendMessage);
768
992
  };
769
- $[46] = messages;
770
- $[47] = onNew;
771
- $[48] = queue;
772
- $[49] = t16;
773
- } else t16 = $[49];
774
- let t17;
775
- if ($[50] !== onStartRun) {
776
- t17 = () => {
993
+ $[59] = messages;
994
+ $[60] = onNew;
995
+ $[61] = queue;
996
+ $[62] = t20;
997
+ } else t20 = $[62];
998
+ let t21;
999
+ if ($[63] !== onStartRun) {
1000
+ t21 = () => {
777
1001
  onStartRun?.();
778
1002
  };
779
- $[50] = onStartRun;
780
- $[51] = t17;
781
- } else t17 = $[51];
782
- let t18;
783
- if ($[52] !== messageClients) {
784
- t18 = (selector) => {
1003
+ $[63] = onStartRun;
1004
+ $[64] = t21;
1005
+ } else t21 = $[64];
1006
+ let t22;
1007
+ if ($[65] !== onResume) {
1008
+ t22 = () => {
1009
+ if (!onResume) throw new Error("Runtime does not support resuming runs (onResume is not set).");
1010
+ onResume();
1011
+ };
1012
+ $[65] = onResume;
1013
+ $[66] = t22;
1014
+ } else t22 = $[66];
1015
+ let t23;
1016
+ if ($[67] !== onLoadExternalState) {
1017
+ t23 = (state_0) => {
1018
+ if (!onLoadExternalState) throw new Error("Runtime does not support importing external states (onLoadExternalState is not set).");
1019
+ onLoadExternalState(state_0);
1020
+ };
1021
+ $[67] = onLoadExternalState;
1022
+ $[68] = t23;
1023
+ } else t23 = $[68];
1024
+ let t24;
1025
+ if ($[69] !== messageClients) {
1026
+ t24 = (selector) => {
785
1027
  if ("id" in selector) return messageClients.get({ key: selector.id });
786
1028
  return messageClients.get(selector);
787
1029
  };
788
- $[52] = messageClients;
789
- $[53] = t18;
790
- } else t18 = $[53];
791
- let t19;
792
- if ($[54] !== handleCancelRun || $[55] !== t14 || $[56] !== t15 || $[57] !== t16 || $[58] !== t17 || $[59] !== t18) {
793
- t19 = {
794
- getState: t14,
795
- composer: t15,
796
- append: t16,
797
- deleteMessage: _temp12,
798
- startRun: t17,
799
- resumeRun: _temp13,
1030
+ $[69] = messageClients;
1031
+ $[70] = t24;
1032
+ } else t24 = $[70];
1033
+ let t25;
1034
+ if ($[71] !== handleCancelRun || $[72] !== t18 || $[73] !== t19 || $[74] !== t20 || $[75] !== t21 || $[76] !== t22 || $[77] !== t23 || $[78] !== t24) {
1035
+ t25 = {
1036
+ getState: t18,
1037
+ composer: t19,
1038
+ append: t20,
1039
+ deleteMessage: _temp11,
1040
+ startRun: t21,
1041
+ resumeRun: t22,
800
1042
  cancelRun: handleCancelRun,
801
- getModelContext: _temp14,
802
- export: _temp15,
803
- import: _temp16,
804
- reset: _temp17,
805
- message: t18,
806
- stopSpeaking: _temp18,
807
- connectVoice: _temp19,
808
- disconnectVoice: _temp20,
809
- getVoiceVolume: _temp21,
810
- subscribeVoiceVolume: _temp23,
811
- muteVoice: _temp24,
812
- unmuteVoice: _temp25
813
- };
814
- $[54] = handleCancelRun;
815
- $[55] = t14;
816
- $[56] = t15;
817
- $[57] = t16;
818
- $[58] = t17;
819
- $[59] = t18;
820
- $[60] = t19;
821
- } else t19 = $[60];
822
- return t19;
1043
+ importExternalState: t23,
1044
+ getModelContext: _temp12,
1045
+ export: _temp13,
1046
+ import: _temp14,
1047
+ reset: _temp15,
1048
+ message: t24,
1049
+ stopSpeaking: _temp16,
1050
+ connectVoice: _temp17,
1051
+ disconnectVoice: _temp18,
1052
+ getVoiceVolume: _temp19,
1053
+ subscribeVoiceVolume: _temp21,
1054
+ muteVoice: _temp22,
1055
+ unmuteVoice: _temp23
1056
+ };
1057
+ $[71] = handleCancelRun;
1058
+ $[72] = t18;
1059
+ $[73] = t19;
1060
+ $[74] = t20;
1061
+ $[75] = t21;
1062
+ $[76] = t22;
1063
+ $[77] = t23;
1064
+ $[78] = t24;
1065
+ $[79] = t25;
1066
+ } else t25 = $[79];
1067
+ return t25;
823
1068
  };
824
1069
  const ExternalThread = resource(useExternalThread);
825
1070
  attachTransformScopes(useExternalThread, (scopes, parent) => {
@@ -858,47 +1103,47 @@ function _temp3() {}
858
1103
  function _temp4() {}
859
1104
  function _temp5() {}
860
1105
  function _temp6() {}
861
- function _temp7() {}
862
- function _temp8() {}
863
- function _temp9(part) {
1106
+ function _temp7(part) {
864
1107
  return part.type === "text";
865
1108
  }
866
- function _temp0(part_0) {
1109
+ function _temp8(part_0) {
867
1110
  return "text" in part_0 ? part_0.text : "";
868
1111
  }
1112
+ function _temp9(a_0) {
1113
+ return a_0.status.type !== "complete";
1114
+ }
1115
+ function _temp0() {}
869
1116
  function _temp1() {}
870
- function _temp10() {}
871
- function _temp11(s, idx, arr) {
1117
+ function _temp10(s, idx, arr) {
872
1118
  return {
873
1119
  ...s,
874
1120
  isLast: idx === arr.length - 1
875
1121
  };
876
1122
  }
877
- function _temp12() {}
878
- function _temp13() {}
879
- function _temp14() {
1123
+ function _temp11() {}
1124
+ function _temp12() {
880
1125
  return {
881
1126
  tools: {},
882
1127
  config: {}
883
1128
  };
884
1129
  }
885
- function _temp15() {
1130
+ function _temp13() {
886
1131
  return { messages: [] };
887
1132
  }
1133
+ function _temp14() {}
1134
+ function _temp15() {}
888
1135
  function _temp16() {}
889
1136
  function _temp17() {}
890
1137
  function _temp18() {}
891
- function _temp19() {}
1138
+ function _temp19() {
1139
+ return 0;
1140
+ }
892
1141
  function _temp20() {}
893
1142
  function _temp21() {
894
- return 0;
1143
+ return _temp20;
895
1144
  }
896
1145
  function _temp22() {}
897
- function _temp23() {
898
- return _temp22;
899
- }
900
- function _temp24() {}
901
- function _temp25() {}
1146
+ function _temp23() {}
902
1147
  //#endregion
903
1148
  export { ExternalThread };
904
1149