@assistant-ui/react 0.10.1 → 0.10.3

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 (393) hide show
  1. package/dist/api/AssistantRuntime.js +5 -4
  2. package/dist/api/AssistantRuntime.js.map +1 -1
  3. package/dist/api/AttachmentRuntime.js +11 -10
  4. package/dist/api/AttachmentRuntime.js.map +1 -1
  5. package/dist/api/ComposerRuntime.js +16 -15
  6. package/dist/api/ComposerRuntime.js.map +1 -1
  7. package/dist/api/ContentPartRuntime.js +3 -2
  8. package/dist/api/ContentPartRuntime.js.map +1 -1
  9. package/dist/api/MessageRuntime.js +14 -13
  10. package/dist/api/MessageRuntime.js.map +1 -1
  11. package/dist/api/ThreadListItemRuntime.js +3 -2
  12. package/dist/api/ThreadListItemRuntime.js.map +1 -1
  13. package/dist/api/ThreadListRuntime.js +11 -10
  14. package/dist/api/ThreadListRuntime.js.map +1 -1
  15. package/dist/api/ThreadRuntime.js +14 -13
  16. package/dist/api/ThreadRuntime.js.map +1 -1
  17. package/dist/api/subscribable/BaseSubject.js +3 -2
  18. package/dist/api/subscribable/BaseSubject.js.map +1 -1
  19. package/dist/api/subscribable/EventSubscriptionSubject.js +4 -3
  20. package/dist/api/subscribable/EventSubscriptionSubject.js.map +1 -1
  21. package/dist/api/subscribable/LazyMemoizeSubject.js +5 -4
  22. package/dist/api/subscribable/LazyMemoizeSubject.js.map +1 -1
  23. package/dist/api/subscribable/NestedSubscriptionSubject.js +4 -3
  24. package/dist/api/subscribable/NestedSubscriptionSubject.js.map +1 -1
  25. package/dist/api/subscribable/SKIP_UPDATE.js +2 -1
  26. package/dist/api/subscribable/SKIP_UPDATE.js.map +1 -1
  27. package/dist/api/subscribable/ShallowMemoizeSubject.js +6 -5
  28. package/dist/api/subscribable/ShallowMemoizeSubject.js.map +1 -1
  29. package/dist/api/subscribable/shallowEqual.js +1 -0
  30. package/dist/api/subscribable/shallowEqual.js.map +1 -1
  31. package/dist/cloud/AssistantCloud.js +7 -6
  32. package/dist/cloud/AssistantCloud.js.map +1 -1
  33. package/dist/cloud/AssistantCloudAPI.js +6 -5
  34. package/dist/cloud/AssistantCloudAPI.js.map +1 -1
  35. package/dist/cloud/AssistantCloudAuthStrategy.js +9 -8
  36. package/dist/cloud/AssistantCloudAuthStrategy.js.map +1 -1
  37. package/dist/cloud/AssistantCloudAuthTokens.js +3 -2
  38. package/dist/cloud/AssistantCloudAuthTokens.js.map +1 -1
  39. package/dist/cloud/AssistantCloudRuns.js +3 -2
  40. package/dist/cloud/AssistantCloudRuns.js.map +1 -1
  41. package/dist/cloud/AssistantCloudThreadHistoryAdapter.js +6 -5
  42. package/dist/cloud/AssistantCloudThreadHistoryAdapter.js.map +1 -1
  43. package/dist/cloud/AssistantCloudThreadMessages.js +3 -2
  44. package/dist/cloud/AssistantCloudThreadMessages.js.map +1 -1
  45. package/dist/cloud/AssistantCloudThreads.js +4 -3
  46. package/dist/cloud/AssistantCloudThreads.js.map +1 -1
  47. package/dist/cloud/auiV0.js +5 -4
  48. package/dist/cloud/auiV0.js.map +1 -1
  49. package/dist/cloud/index.js +3 -2
  50. package/dist/cloud/index.js.map +1 -1
  51. package/dist/cloud/useCloudThreadListRuntime.js +5 -3
  52. package/dist/cloud/useCloudThreadListRuntime.js.map +1 -1
  53. package/dist/context/ReadonlyStore.js +2 -1
  54. package/dist/context/ReadonlyStore.js.map +1 -1
  55. package/dist/context/index.js +4 -3
  56. package/dist/context/index.js.map +1 -1
  57. package/dist/context/providers/AssistantRuntimeProvider.js +13 -11
  58. package/dist/context/providers/AssistantRuntimeProvider.js.map +1 -1
  59. package/dist/context/providers/AttachmentRuntimeProvider.js +8 -6
  60. package/dist/context/providers/AttachmentRuntimeProvider.js.map +1 -1
  61. package/dist/context/providers/ContentPartRuntimeProvider.js +8 -6
  62. package/dist/context/providers/ContentPartRuntimeProvider.js.map +1 -1
  63. package/dist/context/providers/MessageRuntimeProvider.js +10 -8
  64. package/dist/context/providers/MessageRuntimeProvider.js.map +1 -1
  65. package/dist/context/providers/TextContentPartProvider.js +10 -8
  66. package/dist/context/providers/TextContentPartProvider.js.map +1 -1
  67. package/dist/context/providers/ThreadListItemRuntimeProvider.js +8 -6
  68. package/dist/context/providers/ThreadListItemRuntimeProvider.js.map +1 -1
  69. package/dist/context/providers/ThreadRuntimeProvider.js +10 -8
  70. package/dist/context/providers/ThreadRuntimeProvider.js.map +1 -1
  71. package/dist/context/providers/ThreadViewportProvider.js +8 -6
  72. package/dist/context/providers/ThreadViewportProvider.js.map +1 -1
  73. package/dist/context/providers/index.js +3 -2
  74. package/dist/context/providers/index.js.map +1 -1
  75. package/dist/context/react/AssistantContext.js +10 -8
  76. package/dist/context/react/AssistantContext.js.map +1 -1
  77. package/dist/context/react/AttachmentContext.js +10 -8
  78. package/dist/context/react/AttachmentContext.js.map +1 -1
  79. package/dist/context/react/ComposerContext.js +6 -4
  80. package/dist/context/react/ComposerContext.js.map +1 -1
  81. package/dist/context/react/ContentPartContext.js +7 -5
  82. package/dist/context/react/ContentPartContext.js.map +1 -1
  83. package/dist/context/react/MessageContext.js +11 -9
  84. package/dist/context/react/MessageContext.js.map +1 -1
  85. package/dist/context/react/ThreadContext.js +9 -7
  86. package/dist/context/react/ThreadContext.js.map +1 -1
  87. package/dist/context/react/ThreadListItemContext.js +7 -5
  88. package/dist/context/react/ThreadListItemContext.js.map +1 -1
  89. package/dist/context/react/ThreadViewportContext.js +7 -5
  90. package/dist/context/react/ThreadViewportContext.js.map +1 -1
  91. package/dist/context/react/index.js +11 -9
  92. package/dist/context/react/index.js.map +1 -1
  93. package/dist/context/react/utils/createContextHook.js +2 -0
  94. package/dist/context/react/utils/createContextHook.js.map +1 -1
  95. package/dist/context/react/utils/createContextStoreHook.js +1 -0
  96. package/dist/context/react/utils/createContextStoreHook.js.map +1 -1
  97. package/dist/context/react/utils/createStateHookForRuntime.js +2 -1
  98. package/dist/context/react/utils/createStateHookForRuntime.js.map +1 -1
  99. package/dist/context/react/utils/ensureBinding.js +2 -21
  100. package/dist/context/react/utils/ensureBinding.js.map +1 -1
  101. package/dist/context/react/utils/useRuntimeState.js +3 -2
  102. package/dist/context/react/utils/useRuntimeState.js.map +1 -1
  103. package/dist/context/stores/AssistantToolUIs.js +2 -1
  104. package/dist/context/stores/AssistantToolUIs.js.map +1 -1
  105. package/dist/context/stores/MessageUtils.js +2 -1
  106. package/dist/context/stores/MessageUtils.js.map +1 -1
  107. package/dist/context/stores/ThreadViewport.js +3 -1
  108. package/dist/context/stores/ThreadViewport.js.map +1 -1
  109. package/dist/index.js +9 -8
  110. package/dist/index.js.map +1 -1
  111. package/dist/internal.js +12 -11
  112. package/dist/internal.js.map +1 -1
  113. package/dist/model-context/ModelContextTypes.js +2 -1
  114. package/dist/model-context/ModelContextTypes.js.map +1 -1
  115. package/dist/model-context/index.js +10 -9
  116. package/dist/model-context/index.js.map +1 -1
  117. package/dist/model-context/makeAssistantTool.js +4 -2
  118. package/dist/model-context/makeAssistantTool.js.map +1 -1
  119. package/dist/model-context/makeAssistantToolUI.js +4 -2
  120. package/dist/model-context/makeAssistantToolUI.js.map +1 -1
  121. package/dist/model-context/makeAssistantVisible.js +9 -7
  122. package/dist/model-context/makeAssistantVisible.js.map +1 -1
  123. package/dist/model-context/tool.d.ts +1 -10
  124. package/dist/model-context/tool.d.ts.map +1 -1
  125. package/dist/model-context/tool.js +1 -0
  126. package/dist/model-context/tool.js.map +1 -1
  127. package/dist/model-context/useAssistantInstructions.js +5 -3
  128. package/dist/model-context/useAssistantInstructions.js.map +1 -1
  129. package/dist/model-context/useAssistantTool.d.ts +0 -1
  130. package/dist/model-context/useAssistantTool.d.ts.map +1 -1
  131. package/dist/model-context/useAssistantTool.js +5 -4
  132. package/dist/model-context/useAssistantTool.js.map +1 -1
  133. package/dist/model-context/useAssistantToolUI.js +4 -2
  134. package/dist/model-context/useAssistantToolUI.js.map +1 -1
  135. package/dist/model-context/useInlineRender.js +3 -1
  136. package/dist/model-context/useInlineRender.js.map +1 -1
  137. package/dist/primitives/actionBar/ActionBarCopy.js +8 -6
  138. package/dist/primitives/actionBar/ActionBarCopy.js.map +1 -1
  139. package/dist/primitives/actionBar/ActionBarEdit.js +6 -4
  140. package/dist/primitives/actionBar/ActionBarEdit.js.map +1 -1
  141. package/dist/primitives/actionBar/ActionBarFeedbackNegative.js +7 -5
  142. package/dist/primitives/actionBar/ActionBarFeedbackNegative.js.map +1 -1
  143. package/dist/primitives/actionBar/ActionBarFeedbackPositive.js +6 -4
  144. package/dist/primitives/actionBar/ActionBarFeedbackPositive.js.map +1 -1
  145. package/dist/primitives/actionBar/ActionBarReload.js +8 -6
  146. package/dist/primitives/actionBar/ActionBarReload.js.map +1 -1
  147. package/dist/primitives/actionBar/ActionBarRoot.js +5 -3
  148. package/dist/primitives/actionBar/ActionBarRoot.js.map +1 -1
  149. package/dist/primitives/actionBar/ActionBarSpeak.js +6 -4
  150. package/dist/primitives/actionBar/ActionBarSpeak.js.map +1 -1
  151. package/dist/primitives/actionBar/ActionBarStopSpeaking.js +6 -4
  152. package/dist/primitives/actionBar/ActionBarStopSpeaking.js.map +1 -1
  153. package/dist/primitives/actionBar/index.js +9 -8
  154. package/dist/primitives/actionBar/index.js.map +1 -1
  155. package/dist/primitives/actionBar/useActionBarFloatStatus.js +6 -4
  156. package/dist/primitives/actionBar/useActionBarFloatStatus.js.map +1 -1
  157. package/dist/primitives/assistantModal/AssistantModalAnchor.js +5 -3
  158. package/dist/primitives/assistantModal/AssistantModalAnchor.js.map +1 -1
  159. package/dist/primitives/assistantModal/AssistantModalContent.js +5 -3
  160. package/dist/primitives/assistantModal/AssistantModalContent.js.map +1 -1
  161. package/dist/primitives/assistantModal/AssistantModalRoot.js +7 -5
  162. package/dist/primitives/assistantModal/AssistantModalRoot.js.map +1 -1
  163. package/dist/primitives/assistantModal/AssistantModalTrigger.js +4 -3
  164. package/dist/primitives/assistantModal/AssistantModalTrigger.js.map +1 -1
  165. package/dist/primitives/assistantModal/index.js +5 -4
  166. package/dist/primitives/assistantModal/index.js.map +1 -1
  167. package/dist/primitives/assistantModal/scope.js +2 -1
  168. package/dist/primitives/assistantModal/scope.js.map +1 -1
  169. package/dist/primitives/attachment/AttachmentName.js +4 -2
  170. package/dist/primitives/attachment/AttachmentName.js.map +1 -1
  171. package/dist/primitives/attachment/AttachmentRemove.js +6 -4
  172. package/dist/primitives/attachment/AttachmentRemove.js.map +1 -1
  173. package/dist/primitives/attachment/AttachmentRoot.js +3 -2
  174. package/dist/primitives/attachment/AttachmentRoot.js.map +1 -1
  175. package/dist/primitives/attachment/AttachmentThumb.js +5 -3
  176. package/dist/primitives/attachment/AttachmentThumb.js.map +1 -1
  177. package/dist/primitives/attachment/index.js +5 -4
  178. package/dist/primitives/attachment/index.js.map +1 -1
  179. package/dist/primitives/branchPicker/BranchPickerCount.js +5 -3
  180. package/dist/primitives/branchPicker/BranchPickerCount.js.map +1 -1
  181. package/dist/primitives/branchPicker/BranchPickerNext.js +6 -4
  182. package/dist/primitives/branchPicker/BranchPickerNext.js.map +1 -1
  183. package/dist/primitives/branchPicker/BranchPickerNumber.js +5 -3
  184. package/dist/primitives/branchPicker/BranchPickerNumber.js.map +1 -1
  185. package/dist/primitives/branchPicker/BranchPickerPrevious.js +6 -4
  186. package/dist/primitives/branchPicker/BranchPickerPrevious.js.map +1 -1
  187. package/dist/primitives/branchPicker/BranchPickerRoot.js +4 -3
  188. package/dist/primitives/branchPicker/BranchPickerRoot.js.map +1 -1
  189. package/dist/primitives/branchPicker/index.js +6 -5
  190. package/dist/primitives/branchPicker/index.js.map +1 -1
  191. package/dist/primitives/composer/ComposerAddAttachment.js +6 -4
  192. package/dist/primitives/composer/ComposerAddAttachment.js.map +1 -1
  193. package/dist/primitives/composer/ComposerAttachments.js +11 -9
  194. package/dist/primitives/composer/ComposerAttachments.js.map +1 -1
  195. package/dist/primitives/composer/ComposerCancel.js +6 -4
  196. package/dist/primitives/composer/ComposerCancel.js.map +1 -1
  197. package/dist/primitives/composer/ComposerIf.js +5 -3
  198. package/dist/primitives/composer/ComposerIf.js.map +1 -1
  199. package/dist/primitives/composer/ComposerInput.js +8 -6
  200. package/dist/primitives/composer/ComposerInput.js.map +1 -1
  201. package/dist/primitives/composer/ComposerRoot.js +5 -3
  202. package/dist/primitives/composer/ComposerRoot.js.map +1 -1
  203. package/dist/primitives/composer/ComposerSend.js +8 -6
  204. package/dist/primitives/composer/ComposerSend.js.map +1 -1
  205. package/dist/primitives/composer/index.js +8 -7
  206. package/dist/primitives/composer/index.js.map +1 -1
  207. package/dist/primitives/contentPart/ContentPartImage.js +5 -3
  208. package/dist/primitives/contentPart/ContentPartImage.js.map +1 -1
  209. package/dist/primitives/contentPart/ContentPartInProgress.js +4 -2
  210. package/dist/primitives/contentPart/ContentPartInProgress.js.map +1 -1
  211. package/dist/primitives/contentPart/ContentPartText.js +6 -4
  212. package/dist/primitives/contentPart/ContentPartText.js.map +1 -1
  213. package/dist/primitives/contentPart/index.js +4 -3
  214. package/dist/primitives/contentPart/index.js.map +1 -1
  215. package/dist/primitives/contentPart/useContentPartFile.js +4 -2
  216. package/dist/primitives/contentPart/useContentPartFile.js.map +1 -1
  217. package/dist/primitives/contentPart/useContentPartImage.js +4 -2
  218. package/dist/primitives/contentPart/useContentPartImage.js.map +1 -1
  219. package/dist/primitives/contentPart/useContentPartReasoning.js +4 -2
  220. package/dist/primitives/contentPart/useContentPartReasoning.js.map +1 -1
  221. package/dist/primitives/contentPart/useContentPartSource.js +4 -2
  222. package/dist/primitives/contentPart/useContentPartSource.js.map +1 -1
  223. package/dist/primitives/contentPart/useContentPartText.js +4 -2
  224. package/dist/primitives/contentPart/useContentPartText.js.map +1 -1
  225. package/dist/primitives/index.js +17 -16
  226. package/dist/primitives/index.js.map +1 -1
  227. package/dist/primitives/message/MessageAttachments.js +11 -9
  228. package/dist/primitives/message/MessageAttachments.js.map +1 -1
  229. package/dist/primitives/message/MessageContent.js +19 -17
  230. package/dist/primitives/message/MessageContent.js.map +1 -1
  231. package/dist/primitives/message/MessageIf.js +6 -4
  232. package/dist/primitives/message/MessageIf.js.map +1 -1
  233. package/dist/primitives/message/MessageRoot.js +7 -5
  234. package/dist/primitives/message/MessageRoot.js.map +1 -1
  235. package/dist/primitives/message/index.js +5 -4
  236. package/dist/primitives/message/index.js.map +1 -1
  237. package/dist/primitives/thread/ThreadEmpty.js +4 -2
  238. package/dist/primitives/thread/ThreadEmpty.js.map +1 -1
  239. package/dist/primitives/thread/ThreadIf.js +5 -3
  240. package/dist/primitives/thread/ThreadIf.js.map +1 -1
  241. package/dist/primitives/thread/ThreadMessages.js +14 -12
  242. package/dist/primitives/thread/ThreadMessages.js.map +1 -1
  243. package/dist/primitives/thread/ThreadRoot.js +3 -2
  244. package/dist/primitives/thread/ThreadRoot.js.map +1 -1
  245. package/dist/primitives/thread/ThreadScrollToBottom.js +6 -4
  246. package/dist/primitives/thread/ThreadScrollToBottom.js.map +1 -1
  247. package/dist/primitives/thread/ThreadSuggestion.js +7 -5
  248. package/dist/primitives/thread/ThreadSuggestion.js.map +1 -1
  249. package/dist/primitives/thread/ThreadViewport.js +7 -5
  250. package/dist/primitives/thread/ThreadViewport.js.map +1 -1
  251. package/dist/primitives/thread/index.js +8 -7
  252. package/dist/primitives/thread/index.js.map +1 -1
  253. package/dist/primitives/thread/useThreadViewportAutoScroll.js +9 -7
  254. package/dist/primitives/thread/useThreadViewportAutoScroll.js.map +1 -1
  255. package/dist/primitives/threadList/ThreadListItems.js +8 -6
  256. package/dist/primitives/threadList/ThreadListItems.js.map +1 -1
  257. package/dist/primitives/threadList/ThreadListNew.js +6 -4
  258. package/dist/primitives/threadList/ThreadListNew.js.map +1 -1
  259. package/dist/primitives/threadList/ThreadListRoot.js +3 -2
  260. package/dist/primitives/threadList/ThreadListRoot.js.map +1 -1
  261. package/dist/primitives/threadList/index.js +4 -3
  262. package/dist/primitives/threadList/index.js.map +1 -1
  263. package/dist/primitives/threadListItem/ThreadListItemArchive.js +6 -4
  264. package/dist/primitives/threadListItem/ThreadListItemArchive.js.map +1 -1
  265. package/dist/primitives/threadListItem/ThreadListItemDelete.js +6 -4
  266. package/dist/primitives/threadListItem/ThreadListItemDelete.js.map +1 -1
  267. package/dist/primitives/threadListItem/ThreadListItemRoot.js +5 -3
  268. package/dist/primitives/threadListItem/ThreadListItemRoot.js.map +1 -1
  269. package/dist/primitives/threadListItem/ThreadListItemTitle.js +4 -2
  270. package/dist/primitives/threadListItem/ThreadListItemTitle.js.map +1 -1
  271. package/dist/primitives/threadListItem/ThreadListItemTrigger.js +6 -4
  272. package/dist/primitives/threadListItem/ThreadListItemTrigger.js.map +1 -1
  273. package/dist/primitives/threadListItem/ThreadListItemUnarchive.js +6 -4
  274. package/dist/primitives/threadListItem/ThreadListItemUnarchive.js.map +1 -1
  275. package/dist/primitives/threadListItem/index.js +7 -6
  276. package/dist/primitives/threadListItem/index.js.map +1 -1
  277. package/dist/runtimes/adapters/RuntimeAdapterProvider.js +5 -4
  278. package/dist/runtimes/adapters/RuntimeAdapterProvider.js.map +1 -1
  279. package/dist/runtimes/adapters/attachment/CompositeAttachmentAdapter.js +3 -2
  280. package/dist/runtimes/adapters/attachment/CompositeAttachmentAdapter.js.map +1 -1
  281. package/dist/runtimes/adapters/attachment/SimpleImageAttachmentAdapter.js +4 -3
  282. package/dist/runtimes/adapters/attachment/SimpleImageAttachmentAdapter.js.map +1 -1
  283. package/dist/runtimes/adapters/attachment/SimpleTextAttachmentAdapter.js +4 -3
  284. package/dist/runtimes/adapters/attachment/SimpleTextAttachmentAdapter.js.map +1 -1
  285. package/dist/runtimes/adapters/attachment/index.js +4 -3
  286. package/dist/runtimes/adapters/attachment/index.js.map +1 -1
  287. package/dist/runtimes/adapters/index.js +5 -4
  288. package/dist/runtimes/adapters/index.js.map +1 -1
  289. package/dist/runtimes/adapters/speech/WebSpeechSynthesisAdapter.js +3 -2
  290. package/dist/runtimes/adapters/speech/WebSpeechSynthesisAdapter.js.map +1 -1
  291. package/dist/runtimes/adapters/speech/index.js +2 -1
  292. package/dist/runtimes/adapters/speech/index.js.map +1 -1
  293. package/dist/runtimes/composer/BaseComposerRuntimeCore.js +5 -4
  294. package/dist/runtimes/composer/BaseComposerRuntimeCore.js.map +1 -1
  295. package/dist/runtimes/composer/DefaultEditComposerRuntimeCore.js +5 -4
  296. package/dist/runtimes/composer/DefaultEditComposerRuntimeCore.js.map +1 -1
  297. package/dist/runtimes/composer/DefaultThreadComposerRuntimeCore.js +4 -3
  298. package/dist/runtimes/composer/DefaultThreadComposerRuntimeCore.js.map +1 -1
  299. package/dist/runtimes/core/BaseAssistantRuntimeCore.js +4 -3
  300. package/dist/runtimes/core/BaseAssistantRuntimeCore.js.map +1 -1
  301. package/dist/runtimes/core/BaseThreadRuntimeCore.js +7 -6
  302. package/dist/runtimes/core/BaseThreadRuntimeCore.js.map +1 -1
  303. package/dist/runtimes/external-store/ExternalStoreRuntimeCore.js +7 -6
  304. package/dist/runtimes/external-store/ExternalStoreRuntimeCore.js.map +1 -1
  305. package/dist/runtimes/external-store/ExternalStoreThreadListRuntimeCore.js +8 -7
  306. package/dist/runtimes/external-store/ExternalStoreThreadListRuntimeCore.js.map +1 -1
  307. package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.js +11 -10
  308. package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.js.map +1 -1
  309. package/dist/runtimes/external-store/ThreadMessageConverter.js +3 -2
  310. package/dist/runtimes/external-store/ThreadMessageConverter.js.map +1 -1
  311. package/dist/runtimes/external-store/ThreadMessageLike.js +3 -2
  312. package/dist/runtimes/external-store/ThreadMessageLike.js.map +1 -1
  313. package/dist/runtimes/external-store/auto-status.js +5 -4
  314. package/dist/runtimes/external-store/auto-status.js.map +1 -1
  315. package/dist/runtimes/external-store/createMessageConverter.js +6 -4
  316. package/dist/runtimes/external-store/createMessageConverter.js.map +1 -1
  317. package/dist/runtimes/external-store/external-message-converter.js +11 -9
  318. package/dist/runtimes/external-store/external-message-converter.js.map +1 -1
  319. package/dist/runtimes/external-store/getExternalStoreMessage.js +6 -5
  320. package/dist/runtimes/external-store/getExternalStoreMessage.js.map +1 -1
  321. package/dist/runtimes/external-store/index.js +5 -4
  322. package/dist/runtimes/external-store/index.js.map +1 -1
  323. package/dist/runtimes/external-store/useExternalStoreRuntime.js +6 -4
  324. package/dist/runtimes/external-store/useExternalStoreRuntime.js.map +1 -1
  325. package/dist/runtimes/index.js +7 -6
  326. package/dist/runtimes/index.js.map +1 -1
  327. package/dist/runtimes/local/LocalRuntimeCore.js +7 -6
  328. package/dist/runtimes/local/LocalRuntimeCore.js.map +1 -1
  329. package/dist/runtimes/local/LocalRuntimeOptions.js +2 -1
  330. package/dist/runtimes/local/LocalRuntimeOptions.js.map +1 -1
  331. package/dist/runtimes/local/LocalThreadListRuntimeCore.js +5 -4
  332. package/dist/runtimes/local/LocalThreadListRuntimeCore.js.map +1 -1
  333. package/dist/runtimes/local/LocalThreadRuntimeCore.js +6 -5
  334. package/dist/runtimes/local/LocalThreadRuntimeCore.js.map +1 -1
  335. package/dist/runtimes/local/index.js +2 -1
  336. package/dist/runtimes/local/index.js.map +1 -1
  337. package/dist/runtimes/local/shouldContinue.js +2 -1
  338. package/dist/runtimes/local/shouldContinue.js.map +1 -1
  339. package/dist/runtimes/local/useLocalRuntime.js +9 -7
  340. package/dist/runtimes/local/useLocalRuntime.js.map +1 -1
  341. package/dist/runtimes/remote-thread-list/BaseSubscribable.js +3 -2
  342. package/dist/runtimes/remote-thread-list/BaseSubscribable.js.map +1 -1
  343. package/dist/runtimes/remote-thread-list/EMPTY_THREAD_CORE.js +3 -2
  344. package/dist/runtimes/remote-thread-list/EMPTY_THREAD_CORE.js.map +1 -1
  345. package/dist/runtimes/remote-thread-list/OptimisticState.js +5 -4
  346. package/dist/runtimes/remote-thread-list/OptimisticState.js.map +1 -1
  347. package/dist/runtimes/remote-thread-list/RemoteThreadListHookInstanceManager.js +9 -7
  348. package/dist/runtimes/remote-thread-list/RemoteThreadListHookInstanceManager.js.map +1 -1
  349. package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.js +13 -11
  350. package/dist/runtimes/remote-thread-list/RemoteThreadListThreadListRuntimeCore.js.map +1 -1
  351. package/dist/runtimes/remote-thread-list/adapter/cloud.js +9 -8
  352. package/dist/runtimes/remote-thread-list/adapter/cloud.js.map +1 -1
  353. package/dist/runtimes/remote-thread-list/adapter/in-memory.js +3 -2
  354. package/dist/runtimes/remote-thread-list/adapter/in-memory.js.map +1 -1
  355. package/dist/runtimes/remote-thread-list/index.js +3 -2
  356. package/dist/runtimes/remote-thread-list/index.js.map +1 -1
  357. package/dist/runtimes/remote-thread-list/useRemoteThreadListRuntime.js +8 -6
  358. package/dist/runtimes/remote-thread-list/useRemoteThreadListRuntime.js.map +1 -1
  359. package/dist/runtimes/utils/MessageRepository.js +10 -9
  360. package/dist/runtimes/utils/MessageRepository.js.map +1 -1
  361. package/dist/tests/setup.js +2971 -3
  362. package/dist/tests/setup.js.map +1 -1
  363. package/dist/utils/CompositeContextProvider.js +4 -3
  364. package/dist/utils/CompositeContextProvider.js.map +1 -1
  365. package/dist/utils/combined/createCombinedStore.js +3 -1
  366. package/dist/utils/combined/createCombinedStore.js.map +1 -1
  367. package/dist/utils/combined/useCombinedStore.js +4 -2
  368. package/dist/utils/combined/useCombinedStore.js.map +1 -1
  369. package/dist/utils/createActionButton.js +3 -2
  370. package/dist/utils/createActionButton.js.map +1 -1
  371. package/dist/utils/getThreadMessageText.js +2 -1
  372. package/dist/utils/getThreadMessageText.js.map +1 -1
  373. package/dist/utils/hooks/useManagedRef.js +2 -1
  374. package/dist/utils/hooks/useManagedRef.js.map +1 -1
  375. package/dist/utils/hooks/useOnResizeContent.js +3 -2
  376. package/dist/utils/hooks/useOnResizeContent.js.map +1 -1
  377. package/dist/utils/hooks/useOnScrollToBottom.js +4 -2
  378. package/dist/utils/hooks/useOnScrollToBottom.js.map +1 -1
  379. package/dist/utils/idUtils.js +5 -4
  380. package/dist/utils/idUtils.js.map +1 -1
  381. package/dist/utils/json/is-json.js +1 -0
  382. package/dist/utils/json/is-json.js.map +1 -1
  383. package/dist/utils/smooth/SmoothContext.js +10 -8
  384. package/dist/utils/smooth/SmoothContext.js.map +1 -1
  385. package/dist/utils/smooth/index.js +4 -2
  386. package/dist/utils/smooth/index.js.map +1 -1
  387. package/dist/utils/smooth/useSmooth.js +9 -7
  388. package/dist/utils/smooth/useSmooth.js.map +1 -1
  389. package/dist/utils/useToolArgsFieldStatus.js +4 -3
  390. package/dist/utils/useToolArgsFieldStatus.js.map +1 -1
  391. package/package.json +4 -4
  392. package/src/model-context/tool.ts +3 -16
  393. package/src/model-context/useAssistantTool.tsx +1 -4
@@ -1,6 +1,7 @@
1
- import { ThreadListRuntimeImpl } from "./ThreadListRuntime";
2
- import { ExportedMessageRepository } from "../runtimes";
3
- class AssistantRuntimeImpl {
1
+ // src/api/AssistantRuntime.ts
2
+ import { ThreadListRuntimeImpl } from "./ThreadListRuntime.js";
3
+ import { ExportedMessageRepository } from "../runtimes/index.js";
4
+ var AssistantRuntimeImpl = class {
4
5
  constructor(_core) {
5
6
  this._core = _core;
6
7
  this.threads = new ThreadListRuntimeImpl(_core.threads);
@@ -38,7 +39,7 @@ class AssistantRuntimeImpl {
38
39
  } = {}) {
39
40
  return this._core.threads.getMainThreadRuntimeCore().import(ExportedMessageRepository.fromArray(initialMessages ?? []));
40
41
  }
41
- }
42
+ };
42
43
  export {
43
44
  AssistantRuntimeImpl
44
45
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/api/AssistantRuntime.ts"],"sourcesContent":["import { AssistantRuntimeCore } from \"../runtimes/core/AssistantRuntimeCore\";\nimport { ModelContextProvider } from \"../model-context/ModelContextTypes\";\nimport { ThreadRuntime } from \"./ThreadRuntime\";\nimport { Unsubscribe } from \"../types\";\nimport { ThreadListRuntime, ThreadListRuntimeImpl } from \"./ThreadListRuntime\";\nimport { ExportedMessageRepository, ThreadMessageLike } from \"../runtimes\";\n\nexport type AssistantRuntime = {\n /**\n * The threads in this assistant.\n */\n readonly threads: ThreadListRuntime;\n\n /**\n * The currently selected main thread. Equivalent to `threads.main`.\n */\n readonly thread: ThreadRuntime;\n\n /**\n * @deprecated This field was renamed to `threads`.\n */\n readonly threadList: ThreadListRuntime;\n\n /**\n * Switch to a new thread.\n *\n * @deprecated This method was moved to `threads.switchToNewThread`.\n */\n switchToNewThread(): void;\n\n /**\n * Switch to a thread.\n *\n * @param threadId The thread ID to switch to.\n * @deprecated This method was moved to `threads.switchToThread`.\n */\n switchToThread(threadId: string): void;\n\n /**\n * Register a model context provider. Model context providers are configuration such as system message, temperature, etc. that are set in the frontend.\n *\n * @param provider The model context provider to register.\n */\n registerModelContextProvider(provider: ModelContextProvider): Unsubscribe;\n\n /**\n * @deprecated This method was renamed to `registerModelContextProvider`.\n */\n registerModelConfigProvider(provider: ModelContextProvider): Unsubscribe;\n\n /**\n * @deprecated Deprecated. Please use `runtime.threads.main.import(ExportedMessageRepository.fromArray(initialMessages))`.\n */\n reset: unknown; // make it a type error\n};\n\nexport class AssistantRuntimeImpl implements AssistantRuntime {\n public readonly threads;\n public get threadList() {\n return this.threads;\n }\n\n public readonly _thread: ThreadRuntime;\n\n public constructor(private readonly _core: AssistantRuntimeCore) {\n this.threads = new ThreadListRuntimeImpl(_core.threads);\n this._thread = this.threads.main;\n }\n\n protected __internal_bindMethods() {\n this.switchToNewThread = this.switchToNewThread.bind(this);\n this.switchToThread = this.switchToThread.bind(this);\n this.registerModelContextProvider =\n this.registerModelContextProvider.bind(this);\n this.registerModelConfigProvider =\n this.registerModelConfigProvider.bind(this);\n this.reset = this.reset.bind(this);\n }\n\n public get thread() {\n return this._thread;\n }\n\n public switchToNewThread() {\n return this._core.threads.switchToNewThread();\n }\n\n public switchToThread(threadId: string) {\n return this._core.threads.switchToThread(threadId);\n }\n\n public registerModelContextProvider(provider: ModelContextProvider) {\n return this._core.registerModelContextProvider(provider);\n }\n\n public registerModelConfigProvider(provider: ModelContextProvider) {\n return this.registerModelContextProvider(provider);\n }\n\n public reset({\n initialMessages,\n }: { initialMessages?: ThreadMessageLike[] } = {}) {\n return this._core.threads\n .getMainThreadRuntimeCore()\n .import(ExportedMessageRepository.fromArray(initialMessages ?? []));\n }\n}\n"],"mappings":"AAIA,SAA4B,6BAA6B;AACzD,SAAS,iCAAoD;AAmDtD,MAAM,qBAAiD;AAAA,EAQrD,YAA6B,OAA6B;AAA7B;AAClC,SAAK,UAAU,IAAI,sBAAsB,MAAM,OAAO;AACtD,SAAK,UAAU,KAAK,QAAQ;AAAA,EAC9B;AAAA,EAVgB;AAAA,EAChB,IAAW,aAAa;AACtB,WAAO,KAAK;AAAA,EACd;AAAA,EAEgB;AAAA,EAON,yBAAyB;AACjC,SAAK,oBAAoB,KAAK,kBAAkB,KAAK,IAAI;AACzD,SAAK,iBAAiB,KAAK,eAAe,KAAK,IAAI;AACnD,SAAK,+BACH,KAAK,6BAA6B,KAAK,IAAI;AAC7C,SAAK,8BACH,KAAK,4BAA4B,KAAK,IAAI;AAC5C,SAAK,QAAQ,KAAK,MAAM,KAAK,IAAI;AAAA,EACnC;AAAA,EAEA,IAAW,SAAS;AAClB,WAAO,KAAK;AAAA,EACd;AAAA,EAEO,oBAAoB;AACzB,WAAO,KAAK,MAAM,QAAQ,kBAAkB;AAAA,EAC9C;AAAA,EAEO,eAAe,UAAkB;AACtC,WAAO,KAAK,MAAM,QAAQ,eAAe,QAAQ;AAAA,EACnD;AAAA,EAEO,6BAA6B,UAAgC;AAClE,WAAO,KAAK,MAAM,6BAA6B,QAAQ;AAAA,EACzD;AAAA,EAEO,4BAA4B,UAAgC;AACjE,WAAO,KAAK,6BAA6B,QAAQ;AAAA,EACnD;AAAA,EAEO,MAAM;AAAA,IACX;AAAA,EACF,IAA+C,CAAC,GAAG;AACjD,WAAO,KAAK,MAAM,QACf,yBAAyB,EACzB,OAAO,0BAA0B,UAAU,mBAAmB,CAAC,CAAC,CAAC;AAAA,EACtE;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/api/AssistantRuntime.ts"],"sourcesContent":["import { AssistantRuntimeCore } from \"../runtimes/core/AssistantRuntimeCore\";\nimport { ModelContextProvider } from \"../model-context/ModelContextTypes\";\nimport { ThreadRuntime } from \"./ThreadRuntime\";\nimport { Unsubscribe } from \"../types\";\nimport { ThreadListRuntime, ThreadListRuntimeImpl } from \"./ThreadListRuntime\";\nimport { ExportedMessageRepository, ThreadMessageLike } from \"../runtimes\";\n\nexport type AssistantRuntime = {\n /**\n * The threads in this assistant.\n */\n readonly threads: ThreadListRuntime;\n\n /**\n * The currently selected main thread. Equivalent to `threads.main`.\n */\n readonly thread: ThreadRuntime;\n\n /**\n * @deprecated This field was renamed to `threads`.\n */\n readonly threadList: ThreadListRuntime;\n\n /**\n * Switch to a new thread.\n *\n * @deprecated This method was moved to `threads.switchToNewThread`.\n */\n switchToNewThread(): void;\n\n /**\n * Switch to a thread.\n *\n * @param threadId The thread ID to switch to.\n * @deprecated This method was moved to `threads.switchToThread`.\n */\n switchToThread(threadId: string): void;\n\n /**\n * Register a model context provider. Model context providers are configuration such as system message, temperature, etc. that are set in the frontend.\n *\n * @param provider The model context provider to register.\n */\n registerModelContextProvider(provider: ModelContextProvider): Unsubscribe;\n\n /**\n * @deprecated This method was renamed to `registerModelContextProvider`.\n */\n registerModelConfigProvider(provider: ModelContextProvider): Unsubscribe;\n\n /**\n * @deprecated Deprecated. Please use `runtime.threads.main.import(ExportedMessageRepository.fromArray(initialMessages))`.\n */\n reset: unknown; // make it a type error\n};\n\nexport class AssistantRuntimeImpl implements AssistantRuntime {\n public readonly threads;\n public get threadList() {\n return this.threads;\n }\n\n public readonly _thread: ThreadRuntime;\n\n public constructor(private readonly _core: AssistantRuntimeCore) {\n this.threads = new ThreadListRuntimeImpl(_core.threads);\n this._thread = this.threads.main;\n }\n\n protected __internal_bindMethods() {\n this.switchToNewThread = this.switchToNewThread.bind(this);\n this.switchToThread = this.switchToThread.bind(this);\n this.registerModelContextProvider =\n this.registerModelContextProvider.bind(this);\n this.registerModelConfigProvider =\n this.registerModelConfigProvider.bind(this);\n this.reset = this.reset.bind(this);\n }\n\n public get thread() {\n return this._thread;\n }\n\n public switchToNewThread() {\n return this._core.threads.switchToNewThread();\n }\n\n public switchToThread(threadId: string) {\n return this._core.threads.switchToThread(threadId);\n }\n\n public registerModelContextProvider(provider: ModelContextProvider) {\n return this._core.registerModelContextProvider(provider);\n }\n\n public registerModelConfigProvider(provider: ModelContextProvider) {\n return this.registerModelContextProvider(provider);\n }\n\n public reset({\n initialMessages,\n }: { initialMessages?: ThreadMessageLike[] } = {}) {\n return this._core.threads\n .getMainThreadRuntimeCore()\n .import(ExportedMessageRepository.fromArray(initialMessages ?? []));\n }\n}\n"],"mappings":";AAIA,SAA4B,6BAA6B;AACzD,SAAS,iCAAoD;AAmDtD,IAAM,uBAAN,MAAuD;AAAA,EAQrD,YAA6B,OAA6B;AAA7B;AAClC,SAAK,UAAU,IAAI,sBAAsB,MAAM,OAAO;AACtD,SAAK,UAAU,KAAK,QAAQ;AAAA,EAC9B;AAAA,EAVgB;AAAA,EAChB,IAAW,aAAa;AACtB,WAAO,KAAK;AAAA,EACd;AAAA,EAEgB;AAAA,EAON,yBAAyB;AACjC,SAAK,oBAAoB,KAAK,kBAAkB,KAAK,IAAI;AACzD,SAAK,iBAAiB,KAAK,eAAe,KAAK,IAAI;AACnD,SAAK,+BACH,KAAK,6BAA6B,KAAK,IAAI;AAC7C,SAAK,8BACH,KAAK,4BAA4B,KAAK,IAAI;AAC5C,SAAK,QAAQ,KAAK,MAAM,KAAK,IAAI;AAAA,EACnC;AAAA,EAEA,IAAW,SAAS;AAClB,WAAO,KAAK;AAAA,EACd;AAAA,EAEO,oBAAoB;AACzB,WAAO,KAAK,MAAM,QAAQ,kBAAkB;AAAA,EAC9C;AAAA,EAEO,eAAe,UAAkB;AACtC,WAAO,KAAK,MAAM,QAAQ,eAAe,QAAQ;AAAA,EACnD;AAAA,EAEO,6BAA6B,UAAgC;AAClE,WAAO,KAAK,MAAM,6BAA6B,QAAQ;AAAA,EACzD;AAAA,EAEO,4BAA4B,UAAgC;AACjE,WAAO,KAAK,6BAA6B,QAAQ;AAAA,EACnD;AAAA,EAEO,MAAM;AAAA,IACX;AAAA,EACF,IAA+C,CAAC,GAAG;AACjD,WAAO,KAAK,MAAM,QACf,yBAAyB,EACzB,OAAO,0BAA0B,UAAU,mBAAmB,CAAC,CAAC,CAAC;AAAA,EACtE;AACF;","names":[]}
@@ -1,4 +1,5 @@
1
- class AttachmentRuntimeImpl {
1
+ // src/api/AttachmentRuntime.ts
2
+ var AttachmentRuntimeImpl = class {
2
3
  constructor(_core) {
3
4
  this._core = _core;
4
5
  }
@@ -16,8 +17,8 @@ class AttachmentRuntimeImpl {
16
17
  subscribe(callback) {
17
18
  return this._core.subscribe(callback);
18
19
  }
19
- }
20
- class ComposerAttachmentRuntime extends AttachmentRuntimeImpl {
20
+ };
21
+ var ComposerAttachmentRuntime = class extends AttachmentRuntimeImpl {
21
22
  constructor(core, _composerApi) {
22
23
  super(core);
23
24
  this._composerApi = _composerApi;
@@ -27,18 +28,18 @@ class ComposerAttachmentRuntime extends AttachmentRuntimeImpl {
27
28
  if (!core) throw new Error("Composer is not available");
28
29
  return core.removeAttachment(this.getState().id);
29
30
  }
30
- }
31
- class ThreadComposerAttachmentRuntimeImpl extends ComposerAttachmentRuntime {
31
+ };
32
+ var ThreadComposerAttachmentRuntimeImpl = class extends ComposerAttachmentRuntime {
32
33
  get source() {
33
34
  return "thread-composer";
34
35
  }
35
- }
36
- class EditComposerAttachmentRuntimeImpl extends ComposerAttachmentRuntime {
36
+ };
37
+ var EditComposerAttachmentRuntimeImpl = class extends ComposerAttachmentRuntime {
37
38
  get source() {
38
39
  return "edit-composer";
39
40
  }
40
- }
41
- class MessageAttachmentRuntimeImpl extends AttachmentRuntimeImpl {
41
+ };
42
+ var MessageAttachmentRuntimeImpl = class extends AttachmentRuntimeImpl {
42
43
  get source() {
43
44
  return "message";
44
45
  }
@@ -48,7 +49,7 @@ class MessageAttachmentRuntimeImpl extends AttachmentRuntimeImpl {
48
49
  remove() {
49
50
  throw new Error("Message attachments cannot be removed");
50
51
  }
51
- }
52
+ };
52
53
  export {
53
54
  AttachmentRuntimeImpl,
54
55
  EditComposerAttachmentRuntimeImpl,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/api/AttachmentRuntime.ts"],"sourcesContent":["import { SubscribableWithState } from \"./subscribable/Subscribable\";\n\nimport { ComposerRuntimeCoreBinding } from \"./ComposerRuntime\";\nimport {\n Attachment,\n CompleteAttachment,\n PendingAttachment,\n Unsubscribe,\n} from \"../types\";\nimport { AttachmentRuntimePath } from \"./RuntimePathTypes\";\n\ntype MessageAttachmentState = CompleteAttachment & {\n readonly source: \"message\";\n};\n\ntype ThreadComposerAttachmentState = PendingAttachment & {\n readonly source: \"thread-composer\";\n};\n\ntype EditComposerAttachmentState = Attachment & {\n readonly source: \"edit-composer\";\n};\n\nexport type AttachmentState =\n | ThreadComposerAttachmentState\n | EditComposerAttachmentState\n | MessageAttachmentState;\n\ntype AttachmentSnapshotBinding<Source extends AttachmentRuntimeSource> =\n SubscribableWithState<\n AttachmentState & { source: Source },\n AttachmentRuntimePath & { attachmentSource: Source }\n >;\n\ntype AttachmentRuntimeSource = AttachmentState[\"source\"];\n\nexport type AttachmentRuntime<\n TSource extends AttachmentRuntimeSource = AttachmentRuntimeSource,\n> = {\n readonly path: AttachmentRuntimePath & { attachmentSource: TSource };\n readonly source: TSource;\n getState(): AttachmentState & { source: TSource };\n remove(): Promise<void>;\n subscribe(callback: () => void): Unsubscribe;\n};\n\nexport abstract class AttachmentRuntimeImpl<\n Source extends AttachmentRuntimeSource = AttachmentRuntimeSource,\n> implements AttachmentRuntime\n{\n public get path() {\n return this._core.path;\n }\n\n public abstract get source(): Source;\n\n constructor(private _core: AttachmentSnapshotBinding<Source>) {}\n\n protected __internal_bindMethods() {\n this.getState = this.getState.bind(this);\n this.remove = this.remove.bind(this);\n this.subscribe = this.subscribe.bind(this);\n }\n\n public getState(): AttachmentState & { source: Source } {\n return this._core.getState();\n }\n\n public abstract remove(): Promise<void>;\n\n public subscribe(callback: () => void) {\n return this._core.subscribe(callback);\n }\n}\n\nabstract class ComposerAttachmentRuntime<\n Source extends \"thread-composer\" | \"edit-composer\",\n> extends AttachmentRuntimeImpl<Source> {\n constructor(\n core: AttachmentSnapshotBinding<Source>,\n private _composerApi: ComposerRuntimeCoreBinding,\n ) {\n super(core);\n }\n\n public remove() {\n const core = this._composerApi.getState();\n if (!core) throw new Error(\"Composer is not available\");\n return core.removeAttachment(this.getState().id);\n }\n}\n\nexport class ThreadComposerAttachmentRuntimeImpl extends ComposerAttachmentRuntime<\"thread-composer\"> {\n public get source(): \"thread-composer\" {\n return \"thread-composer\";\n }\n}\n\nexport class EditComposerAttachmentRuntimeImpl extends ComposerAttachmentRuntime<\"edit-composer\"> {\n public get source(): \"edit-composer\" {\n return \"edit-composer\";\n }\n}\n\nexport class MessageAttachmentRuntimeImpl extends AttachmentRuntimeImpl<\"message\"> {\n public get source(): \"message\" {\n return \"message\";\n }\n\n constructor(core: AttachmentSnapshotBinding<\"message\">) {\n super(core);\n }\n\n public remove(): never {\n throw new Error(\"Message attachments cannot be removed\");\n }\n}\n"],"mappings":"AA8CO,MAAe,sBAGtB;AAAA,EAOE,YAAoB,OAA0C;AAA1C;AAAA,EAA2C;AAAA,EAN/D,IAAW,OAAO;AAChB,WAAO,KAAK,MAAM;AAAA,EACpB;AAAA,EAMU,yBAAyB;AACjC,SAAK,WAAW,KAAK,SAAS,KAAK,IAAI;AACvC,SAAK,SAAS,KAAK,OAAO,KAAK,IAAI;AACnC,SAAK,YAAY,KAAK,UAAU,KAAK,IAAI;AAAA,EAC3C;AAAA,EAEO,WAAiD;AACtD,WAAO,KAAK,MAAM,SAAS;AAAA,EAC7B;AAAA,EAIO,UAAU,UAAsB;AACrC,WAAO,KAAK,MAAM,UAAU,QAAQ;AAAA,EACtC;AACF;AAEA,MAAe,kCAEL,sBAA8B;AAAA,EACtC,YACE,MACQ,cACR;AACA,UAAM,IAAI;AAFF;AAAA,EAGV;AAAA,EAEO,SAAS;AACd,UAAM,OAAO,KAAK,aAAa,SAAS;AACxC,QAAI,CAAC,KAAM,OAAM,IAAI,MAAM,2BAA2B;AACtD,WAAO,KAAK,iBAAiB,KAAK,SAAS,EAAE,EAAE;AAAA,EACjD;AACF;AAEO,MAAM,4CAA4C,0BAA6C;AAAA,EACpG,IAAW,SAA4B;AACrC,WAAO;AAAA,EACT;AACF;AAEO,MAAM,0CAA0C,0BAA2C;AAAA,EAChG,IAAW,SAA0B;AACnC,WAAO;AAAA,EACT;AACF;AAEO,MAAM,qCAAqC,sBAAiC;AAAA,EACjF,IAAW,SAAoB;AAC7B,WAAO;AAAA,EACT;AAAA,EAEA,YAAY,MAA4C;AACtD,UAAM,IAAI;AAAA,EACZ;AAAA,EAEO,SAAgB;AACrB,UAAM,IAAI,MAAM,uCAAuC;AAAA,EACzD;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/api/AttachmentRuntime.ts"],"sourcesContent":["import { SubscribableWithState } from \"./subscribable/Subscribable\";\n\nimport { ComposerRuntimeCoreBinding } from \"./ComposerRuntime\";\nimport {\n Attachment,\n CompleteAttachment,\n PendingAttachment,\n Unsubscribe,\n} from \"../types\";\nimport { AttachmentRuntimePath } from \"./RuntimePathTypes\";\n\ntype MessageAttachmentState = CompleteAttachment & {\n readonly source: \"message\";\n};\n\ntype ThreadComposerAttachmentState = PendingAttachment & {\n readonly source: \"thread-composer\";\n};\n\ntype EditComposerAttachmentState = Attachment & {\n readonly source: \"edit-composer\";\n};\n\nexport type AttachmentState =\n | ThreadComposerAttachmentState\n | EditComposerAttachmentState\n | MessageAttachmentState;\n\ntype AttachmentSnapshotBinding<Source extends AttachmentRuntimeSource> =\n SubscribableWithState<\n AttachmentState & { source: Source },\n AttachmentRuntimePath & { attachmentSource: Source }\n >;\n\ntype AttachmentRuntimeSource = AttachmentState[\"source\"];\n\nexport type AttachmentRuntime<\n TSource extends AttachmentRuntimeSource = AttachmentRuntimeSource,\n> = {\n readonly path: AttachmentRuntimePath & { attachmentSource: TSource };\n readonly source: TSource;\n getState(): AttachmentState & { source: TSource };\n remove(): Promise<void>;\n subscribe(callback: () => void): Unsubscribe;\n};\n\nexport abstract class AttachmentRuntimeImpl<\n Source extends AttachmentRuntimeSource = AttachmentRuntimeSource,\n> implements AttachmentRuntime\n{\n public get path() {\n return this._core.path;\n }\n\n public abstract get source(): Source;\n\n constructor(private _core: AttachmentSnapshotBinding<Source>) {}\n\n protected __internal_bindMethods() {\n this.getState = this.getState.bind(this);\n this.remove = this.remove.bind(this);\n this.subscribe = this.subscribe.bind(this);\n }\n\n public getState(): AttachmentState & { source: Source } {\n return this._core.getState();\n }\n\n public abstract remove(): Promise<void>;\n\n public subscribe(callback: () => void) {\n return this._core.subscribe(callback);\n }\n}\n\nabstract class ComposerAttachmentRuntime<\n Source extends \"thread-composer\" | \"edit-composer\",\n> extends AttachmentRuntimeImpl<Source> {\n constructor(\n core: AttachmentSnapshotBinding<Source>,\n private _composerApi: ComposerRuntimeCoreBinding,\n ) {\n super(core);\n }\n\n public remove() {\n const core = this._composerApi.getState();\n if (!core) throw new Error(\"Composer is not available\");\n return core.removeAttachment(this.getState().id);\n }\n}\n\nexport class ThreadComposerAttachmentRuntimeImpl extends ComposerAttachmentRuntime<\"thread-composer\"> {\n public get source(): \"thread-composer\" {\n return \"thread-composer\";\n }\n}\n\nexport class EditComposerAttachmentRuntimeImpl extends ComposerAttachmentRuntime<\"edit-composer\"> {\n public get source(): \"edit-composer\" {\n return \"edit-composer\";\n }\n}\n\nexport class MessageAttachmentRuntimeImpl extends AttachmentRuntimeImpl<\"message\"> {\n public get source(): \"message\" {\n return \"message\";\n }\n\n constructor(core: AttachmentSnapshotBinding<\"message\">) {\n super(core);\n }\n\n public remove(): never {\n throw new Error(\"Message attachments cannot be removed\");\n }\n}\n"],"mappings":";AA8CO,IAAe,wBAAf,MAGP;AAAA,EAOE,YAAoB,OAA0C;AAA1C;AAAA,EAA2C;AAAA,EAN/D,IAAW,OAAO;AAChB,WAAO,KAAK,MAAM;AAAA,EACpB;AAAA,EAMU,yBAAyB;AACjC,SAAK,WAAW,KAAK,SAAS,KAAK,IAAI;AACvC,SAAK,SAAS,KAAK,OAAO,KAAK,IAAI;AACnC,SAAK,YAAY,KAAK,UAAU,KAAK,IAAI;AAAA,EAC3C;AAAA,EAEO,WAAiD;AACtD,WAAO,KAAK,MAAM,SAAS;AAAA,EAC7B;AAAA,EAIO,UAAU,UAAsB;AACrC,WAAO,KAAK,MAAM,UAAU,QAAQ;AAAA,EACtC;AACF;AAEA,IAAe,4BAAf,cAEU,sBAA8B;AAAA,EACtC,YACE,MACQ,cACR;AACA,UAAM,IAAI;AAFF;AAAA,EAGV;AAAA,EAEO,SAAS;AACd,UAAM,OAAO,KAAK,aAAa,SAAS;AACxC,QAAI,CAAC,KAAM,OAAM,IAAI,MAAM,2BAA2B;AACtD,WAAO,KAAK,iBAAiB,KAAK,SAAS,EAAE,EAAE;AAAA,EACjD;AACF;AAEO,IAAM,sCAAN,cAAkD,0BAA6C;AAAA,EACpG,IAAW,SAA4B;AACrC,WAAO;AAAA,EACT;AACF;AAEO,IAAM,oCAAN,cAAgD,0BAA2C;AAAA,EAChG,IAAW,SAA0B;AACnC,WAAO;AAAA,EACT;AACF;AAEO,IAAM,+BAAN,cAA2C,sBAAiC;AAAA,EACjF,IAAW,SAAoB;AAC7B,WAAO;AAAA,EACT;AAAA,EAEA,YAAY,MAA4C;AACtD,UAAM,IAAI;AAAA,EACZ;AAAA,EAEO,SAAgB;AACrB,UAAM,IAAI,MAAM,uCAAuC;AAAA,EACzD;AACF;","names":[]}
@@ -1,14 +1,15 @@
1
- import { LazyMemoizeSubject } from "./subscribable/LazyMemoizeSubject";
1
+ // src/api/ComposerRuntime.ts
2
+ import { LazyMemoizeSubject } from "./subscribable/LazyMemoizeSubject.js";
2
3
  import {
3
4
  EditComposerAttachmentRuntimeImpl,
4
5
  ThreadComposerAttachmentRuntimeImpl
5
- } from "./AttachmentRuntime";
6
- import { ShallowMemoizeSubject } from "./subscribable/ShallowMemoizeSubject";
7
- import { SKIP_UPDATE } from "./subscribable/SKIP_UPDATE";
8
- import { EventSubscriptionSubject } from "./subscribable/EventSubscriptionSubject";
9
- const EMPTY_ARRAY = Object.freeze([]);
10
- const EMPTY_OBJECT = Object.freeze({});
11
- const getThreadComposerState = (runtime) => {
6
+ } from "./AttachmentRuntime.js";
7
+ import { ShallowMemoizeSubject } from "./subscribable/ShallowMemoizeSubject.js";
8
+ import { SKIP_UPDATE } from "./subscribable/SKIP_UPDATE.js";
9
+ import { EventSubscriptionSubject } from "./subscribable/EventSubscriptionSubject.js";
10
+ var EMPTY_ARRAY = Object.freeze([]);
11
+ var EMPTY_OBJECT = Object.freeze({});
12
+ var getThreadComposerState = (runtime) => {
12
13
  return Object.freeze({
13
14
  type: "thread",
14
15
  isEditing: runtime?.isEditing ?? false,
@@ -21,7 +22,7 @@ const getThreadComposerState = (runtime) => {
21
22
  value: runtime?.text ?? ""
22
23
  });
23
24
  };
24
- const getEditComposerState = (runtime) => {
25
+ var getEditComposerState = (runtime) => {
25
26
  return Object.freeze({
26
27
  type: "edit",
27
28
  isEditing: runtime?.isEditing ?? false,
@@ -34,7 +35,7 @@ const getEditComposerState = (runtime) => {
34
35
  value: runtime?.text ?? ""
35
36
  });
36
37
  };
37
- class ComposerRuntimeImpl {
38
+ var ComposerRuntimeImpl = class {
38
39
  constructor(_core) {
39
40
  this._core = _core;
40
41
  }
@@ -116,8 +117,8 @@ class ComposerRuntimeImpl {
116
117
  if (!core) throw new Error("Composer is not available");
117
118
  return core.getAttachmentAccept();
118
119
  }
119
- }
120
- class ThreadComposerRuntimeImpl extends ComposerRuntimeImpl {
120
+ };
121
+ var ThreadComposerRuntimeImpl = class extends ComposerRuntimeImpl {
121
122
  get path() {
122
123
  return this._core.path;
123
124
  }
@@ -164,8 +165,8 @@ class ThreadComposerRuntimeImpl extends ComposerRuntimeImpl {
164
165
  this._core
165
166
  );
166
167
  }
167
- }
168
- class EditComposerRuntimeImpl extends ComposerRuntimeImpl {
168
+ };
169
+ var EditComposerRuntimeImpl = class extends ComposerRuntimeImpl {
169
170
  constructor(core, _beginEdit) {
170
171
  const stateBinding = new LazyMemoizeSubject({
171
172
  path: core.path,
@@ -220,7 +221,7 @@ class EditComposerRuntimeImpl extends ComposerRuntimeImpl {
220
221
  this._core
221
222
  );
222
223
  }
223
- }
224
+ };
224
225
  export {
225
226
  ComposerRuntimeImpl,
226
227
  EditComposerRuntimeImpl,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/api/ComposerRuntime.ts"],"sourcesContent":["import { Attachment, PendingAttachment } from \"../types/AttachmentTypes\";\nimport {\n ComposerRuntimeCore,\n ComposerRuntimeEventType,\n ThreadComposerRuntimeCore,\n} from \"../runtimes/core/ComposerRuntimeCore\";\nimport { Unsubscribe } from \"../types\";\nimport { SubscribableWithState } from \"./subscribable/Subscribable\";\nimport { LazyMemoizeSubject } from \"./subscribable/LazyMemoizeSubject\";\nimport {\n AttachmentRuntime,\n AttachmentState,\n EditComposerAttachmentRuntimeImpl,\n ThreadComposerAttachmentRuntimeImpl,\n} from \"./AttachmentRuntime\";\nimport { ShallowMemoizeSubject } from \"./subscribable/ShallowMemoizeSubject\";\nimport { SKIP_UPDATE } from \"./subscribable/SKIP_UPDATE\";\nimport { ComposerRuntimePath } from \"./RuntimePathTypes\";\nimport { MessageRole, RunConfig } from \"../types/AssistantTypes\";\nimport { EventSubscriptionSubject } from \"./subscribable/EventSubscriptionSubject\";\n\nexport type ThreadComposerRuntimeCoreBinding = SubscribableWithState<\n ThreadComposerRuntimeCore | undefined,\n ComposerRuntimePath & { composerSource: \"thread\" }\n>;\n\nexport type EditComposerRuntimeCoreBinding = SubscribableWithState<\n ComposerRuntimeCore | undefined,\n ComposerRuntimePath & { composerSource: \"edit\" }\n>;\n\nexport type ComposerRuntimeCoreBinding = SubscribableWithState<\n ComposerRuntimeCore | undefined,\n ComposerRuntimePath\n>;\n\ntype BaseComposerState = {\n readonly canCancel: boolean;\n readonly isEditing: boolean;\n readonly isEmpty: boolean;\n\n readonly text: string;\n readonly role: MessageRole;\n readonly attachments: readonly Attachment[];\n readonly runConfig: RunConfig;\n};\n\nexport type ThreadComposerState = BaseComposerState & {\n readonly type: \"thread\";\n\n readonly attachments: readonly PendingAttachment[];\n};\n\nexport type EditComposerState = BaseComposerState & {\n readonly type: \"edit\";\n};\n\nexport type ComposerState = ThreadComposerState | EditComposerState;\n\nconst EMPTY_ARRAY = Object.freeze([]);\nconst EMPTY_OBJECT = Object.freeze({});\nconst getThreadComposerState = (\n runtime: ThreadComposerRuntimeCore | undefined,\n): ThreadComposerState => {\n return Object.freeze({\n type: \"thread\",\n\n isEditing: runtime?.isEditing ?? false,\n canCancel: runtime?.canCancel ?? false,\n isEmpty: runtime?.isEmpty ?? true,\n\n attachments: runtime?.attachments ?? EMPTY_ARRAY,\n text: runtime?.text ?? \"\",\n role: runtime?.role ?? \"user\",\n runConfig: runtime?.runConfig ?? EMPTY_OBJECT,\n\n value: runtime?.text ?? \"\",\n });\n};\n\nconst getEditComposerState = (\n runtime: ComposerRuntimeCore | undefined,\n): EditComposerState => {\n return Object.freeze({\n type: \"edit\",\n\n isEditing: runtime?.isEditing ?? false,\n canCancel: runtime?.canCancel ?? false,\n isEmpty: runtime?.isEmpty ?? true,\n\n text: runtime?.text ?? \"\",\n role: runtime?.role ?? \"user\",\n attachments: runtime?.attachments ?? EMPTY_ARRAY,\n runConfig: runtime?.runConfig ?? EMPTY_OBJECT,\n\n value: runtime?.text ?? \"\",\n });\n};\n\nexport type ComposerRuntime = {\n readonly path: ComposerRuntimePath;\n readonly type: \"edit\" | \"thread\";\n getState(): ComposerState;\n\n getAttachmentAccept(): string;\n addAttachment(file: File): Promise<void>;\n\n setText(text: string): void;\n setRole(role: MessageRole): void;\n setRunConfig(runConfig: RunConfig): void;\n\n reset(): Promise<void>;\n clearAttachments(): Promise<void>;\n\n send(): void;\n cancel(): void;\n subscribe(callback: () => void): Unsubscribe;\n getAttachmentByIndex(idx: number): AttachmentRuntime;\n};\n\nexport abstract class ComposerRuntimeImpl implements ComposerRuntime {\n public get path() {\n return this._core.path;\n }\n\n public abstract get type(): \"edit\" | \"thread\";\n\n constructor(protected _core: ComposerRuntimeCoreBinding) {}\n\n protected __internal_bindMethods() {\n this.setText = this.setText.bind(this);\n this.setRunConfig = this.setRunConfig.bind(this);\n this.getState = this.getState.bind(this);\n this.subscribe = this.subscribe.bind(this);\n this.addAttachment = this.addAttachment.bind(this);\n this.reset = this.reset.bind(this);\n this.clearAttachments = this.clearAttachments.bind(this);\n this.send = this.send.bind(this);\n this.cancel = this.cancel.bind(this);\n this.setRole = this.setRole.bind(this);\n this.getAttachmentAccept = this.getAttachmentAccept.bind(this);\n this.getAttachmentByIndex = this.getAttachmentByIndex.bind(this);\n this.unstable_on = this.unstable_on.bind(this);\n }\n\n public abstract getState(): ComposerState;\n\n public setText(text: string) {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.setText(text);\n }\n\n public setRunConfig(runConfig: RunConfig) {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.setRunConfig(runConfig);\n }\n\n public addAttachment(file: File) {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n return core.addAttachment(file);\n }\n\n public reset() {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n return core.reset();\n }\n\n public clearAttachments() {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n return core.clearAttachments();\n }\n\n public send() {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.send();\n }\n\n public cancel() {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.cancel();\n }\n\n public setRole(role: MessageRole) {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.setRole(role);\n }\n\n public subscribe(callback: () => void) {\n return this._core.subscribe(callback);\n }\n\n private _eventSubscriptionSubjects = new Map<\n string,\n EventSubscriptionSubject<ComposerRuntimeEventType>\n >();\n\n public unstable_on(\n event: ComposerRuntimeEventType,\n callback: () => void,\n ): Unsubscribe {\n let subject = this._eventSubscriptionSubjects.get(event);\n if (!subject) {\n subject = new EventSubscriptionSubject({\n event: event,\n binding: this._core,\n });\n this._eventSubscriptionSubjects.set(event, subject);\n }\n return subject.subscribe(callback);\n }\n\n public getAttachmentAccept(): string {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n return core.getAttachmentAccept();\n }\n\n public abstract getAttachmentByIndex(idx: number): AttachmentRuntime;\n}\n\nexport type ThreadComposerRuntime = Omit<\n ComposerRuntime,\n \"getState\" | \"getAttachmentByIndex\"\n> & {\n readonly path: ComposerRuntimePath & { composerSource: \"thread\" };\n readonly type: \"thread\";\n getState(): ThreadComposerState;\n\n getAttachmentByIndex(\n idx: number,\n ): AttachmentRuntime & { source: \"thread-composer\" };\n};\n\nexport class ThreadComposerRuntimeImpl\n extends ComposerRuntimeImpl\n implements ThreadComposerRuntime\n{\n public override get path() {\n return this._core.path as ComposerRuntimePath & {\n composerSource: \"thread\";\n };\n }\n\n public get type() {\n return \"thread\" as const;\n }\n\n private _getState;\n\n constructor(core: ThreadComposerRuntimeCoreBinding) {\n const stateBinding = new LazyMemoizeSubject({\n path: core.path,\n getState: () => getThreadComposerState(core.getState()),\n subscribe: (callback) => core.subscribe(callback),\n });\n super({\n path: core.path,\n getState: () => core.getState(),\n subscribe: (callback) => stateBinding.subscribe(callback),\n });\n this._getState = stateBinding.getState.bind(stateBinding);\n }\n\n public override getState(): ThreadComposerState {\n return this._getState();\n }\n\n public getAttachmentByIndex(idx: number) {\n return new ThreadComposerAttachmentRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n attachmentSource: \"thread-composer\",\n attachmentSelector: { type: \"index\", index: idx },\n ref: this.path.ref + `${this.path.ref}.attachments[${idx}]`,\n },\n getState: () => {\n const attachments = this.getState().attachments;\n const attachment = attachments[idx];\n if (!attachment) return SKIP_UPDATE;\n\n return {\n ...attachment,\n source: \"thread-composer\",\n } satisfies AttachmentState & { source: \"thread-composer\" };\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n }\n}\n\nexport type EditComposerRuntime = Omit<\n ComposerRuntime,\n \"getState\" | \"getAttachmentByIndex\"\n> & {\n readonly path: ComposerRuntimePath & { composerSource: \"edit\" };\n readonly type: \"edit\";\n\n getState(): EditComposerState;\n beginEdit(): void;\n\n getAttachmentByIndex(\n idx: number,\n ): AttachmentRuntime & { source: \"edit-composer\" };\n};\n\nexport class EditComposerRuntimeImpl\n extends ComposerRuntimeImpl\n implements EditComposerRuntime\n{\n public override get path() {\n return this._core.path as ComposerRuntimePath & { composerSource: \"edit\" };\n }\n\n public get type() {\n return \"edit\" as const;\n }\n\n private _getState;\n constructor(\n core: EditComposerRuntimeCoreBinding,\n private _beginEdit: () => void,\n ) {\n const stateBinding = new LazyMemoizeSubject({\n path: core.path,\n getState: () => getEditComposerState(core.getState()),\n subscribe: (callback) => core.subscribe(callback),\n });\n\n super({\n path: core.path,\n getState: () => core.getState(),\n subscribe: (callback) => stateBinding.subscribe(callback),\n });\n\n this._getState = stateBinding.getState.bind(stateBinding);\n }\n\n public override __internal_bindMethods() {\n super.__internal_bindMethods();\n this.beginEdit = this.beginEdit.bind(this);\n }\n\n public override getState(): EditComposerState {\n return this._getState();\n }\n\n public beginEdit() {\n this._beginEdit();\n }\n\n public getAttachmentByIndex(idx: number) {\n return new EditComposerAttachmentRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n attachmentSource: \"edit-composer\",\n attachmentSelector: { type: \"index\", index: idx },\n ref: this.path.ref + `${this.path.ref}.attachments[${idx}]`,\n },\n getState: () => {\n const attachments = this.getState().attachments;\n const attachment = attachments[idx];\n if (!attachment) return SKIP_UPDATE;\n\n return {\n ...attachment,\n source: \"edit-composer\",\n } satisfies AttachmentState & { source: \"edit-composer\" };\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n }\n}\n"],"mappings":"AAQA,SAAS,0BAA0B;AACnC;AAAA,EAGE;AAAA,EACA;AAAA,OACK;AACP,SAAS,6BAA6B;AACtC,SAAS,mBAAmB;AAG5B,SAAS,gCAAgC;AAwCzC,MAAM,cAAc,OAAO,OAAO,CAAC,CAAC;AACpC,MAAM,eAAe,OAAO,OAAO,CAAC,CAAC;AACrC,MAAM,yBAAyB,CAC7B,YACwB;AACxB,SAAO,OAAO,OAAO;AAAA,IACnB,MAAM;AAAA,IAEN,WAAW,SAAS,aAAa;AAAA,IACjC,WAAW,SAAS,aAAa;AAAA,IACjC,SAAS,SAAS,WAAW;AAAA,IAE7B,aAAa,SAAS,eAAe;AAAA,IACrC,MAAM,SAAS,QAAQ;AAAA,IACvB,MAAM,SAAS,QAAQ;AAAA,IACvB,WAAW,SAAS,aAAa;AAAA,IAEjC,OAAO,SAAS,QAAQ;AAAA,EAC1B,CAAC;AACH;AAEA,MAAM,uBAAuB,CAC3B,YACsB;AACtB,SAAO,OAAO,OAAO;AAAA,IACnB,MAAM;AAAA,IAEN,WAAW,SAAS,aAAa;AAAA,IACjC,WAAW,SAAS,aAAa;AAAA,IACjC,SAAS,SAAS,WAAW;AAAA,IAE7B,MAAM,SAAS,QAAQ;AAAA,IACvB,MAAM,SAAS,QAAQ;AAAA,IACvB,aAAa,SAAS,eAAe;AAAA,IACrC,WAAW,SAAS,aAAa;AAAA,IAEjC,OAAO,SAAS,QAAQ;AAAA,EAC1B,CAAC;AACH;AAuBO,MAAe,oBAA+C;AAAA,EAOnE,YAAsB,OAAmC;AAAnC;AAAA,EAAoC;AAAA,EAN1D,IAAW,OAAO;AAChB,WAAO,KAAK,MAAM;AAAA,EACpB;AAAA,EAMU,yBAAyB;AACjC,SAAK,UA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AA,MACX,UAAU,MAAM,KAAK,SAAS;AAAA,MAC9B,WAAW,CAAC,aAAa,aAAa,UAAU,QAAQ;AAAA,IAC1D,CAAC;AAZO;AAcR,SAAK,YAAY,aAAa,SAAS,KAAK,YAAY;AAAA,EAC1D;AAAA,EA1BA,IAAoB,OAAO;AACzB,WAAO,KAAK,MAAM;AAAA,EACpB;AAAA,EAEA,IAAW,OAAO;AAChB,WAAO;AAAA,EACT;AAAA,EAEQ;AAAA,EAoBQ,yBAAyB;AACvC,UAAM,uBAAuB;AAC7B,SAAK,YAAY,KAAK,UAAU,KAAK,IAAI;AAAA,EAC3C;AAAA,EAEgB,WAA8B;AAC5C,WAAO,KAAK,UAAU;AAAA,EACxB;AAAA,EAEO,YAAY;AACjB,SAAK,WAAW;AAAA,EAClB;AAAA,EAEO,qBAAqB,KAAa;AACvC,WAAO,IAAI;AAAA,MACT,IAAI,sBAAsB;AAAA,QACxB,MAAM;AAAA,UACJ,GAAG,KAAK;AAAA,UACR,kBAAkB;AAAA,UAClB,oBAAoB,EAAE,MAAM,SAAS,OAAO,IAAI;AAAA,UAChD,KAAK,KAAK,KAAK,MAAM,GAAG,KAAK,KAAK,GAAG,gBAAgB,GAAG;AAAA,QAC1D;AAAA,QACA,UAAU,MAAM;AACd,gBAAM,cAAc,KAAK,SAAS,EAAE;AACpC,gBAAM,aAAa,YAAY,GAAG;AAClC,cAAI,CAAC,WAAY,QAAO;AAExB,iBAAO;AAAA,YACL,GAAG;AAAA,YACH,QAAQ;AAAA,UACV;AAAA,QACF;AAAA,QACA,WAAW,CAAC,aAAa,KAAK,MAAM,UAAU,QAAQ;AAAA,MACxD,CAAC;AAAA,MACD,KAAK;AAAA,IACP;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/api/ComposerRuntime.ts"],"sourcesContent":["import { Attachment, PendingAttachment } from \"../types/AttachmentTypes\";\nimport {\n ComposerRuntimeCore,\n ComposerRuntimeEventType,\n ThreadComposerRuntimeCore,\n} from \"../runtimes/core/ComposerRuntimeCore\";\nimport { Unsubscribe } from \"../types\";\nimport { SubscribableWithState } from \"./subscribable/Subscribable\";\nimport { LazyMemoizeSubject } from \"./subscribable/LazyMemoizeSubject\";\nimport {\n AttachmentRuntime,\n AttachmentState,\n EditComposerAttachmentRuntimeImpl,\n ThreadComposerAttachmentRuntimeImpl,\n} from \"./AttachmentRuntime\";\nimport { ShallowMemoizeSubject } from \"./subscribable/ShallowMemoizeSubject\";\nimport { SKIP_UPDATE } from \"./subscribable/SKIP_UPDATE\";\nimport { ComposerRuntimePath } from \"./RuntimePathTypes\";\nimport { MessageRole, RunConfig } from \"../types/AssistantTypes\";\nimport { EventSubscriptionSubject } from \"./subscribable/EventSubscriptionSubject\";\n\nexport type ThreadComposerRuntimeCoreBinding = SubscribableWithState<\n ThreadComposerRuntimeCore | undefined,\n ComposerRuntimePath & { composerSource: \"thread\" }\n>;\n\nexport type EditComposerRuntimeCoreBinding = SubscribableWithState<\n ComposerRuntimeCore | undefined,\n ComposerRuntimePath & { composerSource: \"edit\" }\n>;\n\nexport type ComposerRuntimeCoreBinding = SubscribableWithState<\n ComposerRuntimeCore | undefined,\n ComposerRuntimePath\n>;\n\ntype BaseComposerState = {\n readonly canCancel: boolean;\n readonly isEditing: boolean;\n readonly isEmpty: boolean;\n\n readonly text: string;\n readonly role: MessageRole;\n readonly attachments: readonly Attachment[];\n readonly runConfig: RunConfig;\n};\n\nexport type ThreadComposerState = BaseComposerState & {\n readonly type: \"thread\";\n\n readonly attachments: readonly PendingAttachment[];\n};\n\nexport type EditComposerState = BaseComposerState & {\n readonly type: \"edit\";\n};\n\nexport type ComposerState = ThreadComposerState | EditComposerState;\n\nconst EMPTY_ARRAY = Object.freeze([]);\nconst EMPTY_OBJECT = Object.freeze({});\nconst getThreadComposerState = (\n runtime: ThreadComposerRuntimeCore | undefined,\n): ThreadComposerState => {\n return Object.freeze({\n type: \"thread\",\n\n isEditing: runtime?.isEditing ?? false,\n canCancel: runtime?.canCancel ?? false,\n isEmpty: runtime?.isEmpty ?? true,\n\n attachments: runtime?.attachments ?? EMPTY_ARRAY,\n text: runtime?.text ?? \"\",\n role: runtime?.role ?? \"user\",\n runConfig: runtime?.runConfig ?? EMPTY_OBJECT,\n\n value: runtime?.text ?? \"\",\n });\n};\n\nconst getEditComposerState = (\n runtime: ComposerRuntimeCore | undefined,\n): EditComposerState => {\n return Object.freeze({\n type: \"edit\",\n\n isEditing: runtime?.isEditing ?? false,\n canCancel: runtime?.canCancel ?? false,\n isEmpty: runtime?.isEmpty ?? true,\n\n text: runtime?.text ?? \"\",\n role: runtime?.role ?? \"user\",\n attachments: runtime?.attachments ?? EMPTY_ARRAY,\n runConfig: runtime?.runConfig ?? EMPTY_OBJECT,\n\n value: runtime?.text ?? \"\",\n });\n};\n\nexport type ComposerRuntime = {\n readonly path: ComposerRuntimePath;\n readonly type: \"edit\" | \"thread\";\n getState(): ComposerState;\n\n getAttachmentAccept(): string;\n addAttachment(file: File): Promise<void>;\n\n setText(text: string): void;\n setRole(role: MessageRole): void;\n setRunConfig(runConfig: RunConfig): void;\n\n reset(): Promise<void>;\n clearAttachments(): Promise<void>;\n\n send(): void;\n cancel(): void;\n subscribe(callback: () => void): Unsubscribe;\n getAttachmentByIndex(idx: number): AttachmentRuntime;\n};\n\nexport abstract class ComposerRuntimeImpl implements ComposerRuntime {\n public get path() {\n return this._core.path;\n }\n\n public abstract get type(): \"edit\" | \"thread\";\n\n constructor(protected _core: ComposerRuntimeCoreBinding) {}\n\n protected __internal_bindMethods() {\n this.setText = this.setText.bind(this);\n this.setRunConfig = this.setRunConfig.bind(this);\n this.getState = this.getState.bind(this);\n this.subscribe = this.subscribe.bind(this);\n this.addAttachment = this.addAttachment.bind(this);\n this.reset = this.reset.bind(this);\n this.clearAttachments = this.clearAttachments.bind(this);\n this.send = this.send.bind(this);\n this.cancel = this.cancel.bind(this);\n this.setRole = this.setRole.bind(this);\n this.getAttachmentAccept = this.getAttachmentAccept.bind(this);\n this.getAttachmentByIndex = this.getAttachmentByIndex.bind(this);\n this.unstable_on = this.unstable_on.bind(this);\n }\n\n public abstract getState(): ComposerState;\n\n public setText(text: string) {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.setText(text);\n }\n\n public setRunConfig(runConfig: RunConfig) {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.setRunConfig(runConfig);\n }\n\n public addAttachment(file: File) {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n return core.addAttachment(file);\n }\n\n public reset() {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n return core.reset();\n }\n\n public clearAttachments() {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n return core.clearAttachments();\n }\n\n public send() {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.send();\n }\n\n public cancel() {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.cancel();\n }\n\n public setRole(role: MessageRole) {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.setRole(role);\n }\n\n public subscribe(callback: () => void) {\n return this._core.subscribe(callback);\n }\n\n private _eventSubscriptionSubjects = new Map<\n string,\n EventSubscriptionSubject<ComposerRuntimeEventType>\n >();\n\n public unstable_on(\n event: ComposerRuntimeEventType,\n callback: () => void,\n ): Unsubscribe {\n let subject = this._eventSubscriptionSubjects.get(event);\n if (!subject) {\n subject = new EventSubscriptionSubject({\n event: event,\n binding: this._core,\n });\n this._eventSubscriptionSubjects.set(event, subject);\n }\n return subject.subscribe(callback);\n }\n\n public getAttachmentAccept(): string {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n return core.getAttachmentAccept();\n }\n\n public abstract getAttachmentByIndex(idx: number): AttachmentRuntime;\n}\n\nexport type ThreadComposerRuntime = Omit<\n ComposerRuntime,\n \"getState\" | \"getAttachmentByIndex\"\n> & {\n readonly path: ComposerRuntimePath & { composerSource: \"thread\" };\n readonly type: \"thread\";\n getState(): ThreadComposerState;\n\n getAttachmentByIndex(\n idx: number,\n ): AttachmentRuntime & { source: \"thread-composer\" };\n};\n\nexport class ThreadComposerRuntimeImpl\n extends ComposerRuntimeImpl\n implements ThreadComposerRuntime\n{\n public override get path() {\n return this._core.path as ComposerRuntimePath & {\n composerSource: \"thread\";\n };\n }\n\n public get type() {\n return \"thread\" as const;\n }\n\n private _getState;\n\n constructor(core: ThreadComposerRuntimeCoreBinding) {\n const stateBinding = new LazyMemoizeSubject({\n path: core.path,\n getState: () => getThreadComposerState(core.getState()),\n subscribe: (callback) => core.subscribe(callback),\n });\n super({\n path: core.path,\n getState: () => core.getState(),\n subscribe: (callback) => stateBinding.subscribe(callback),\n });\n this._getState = stateBinding.getState.bind(stateBinding);\n }\n\n public override getState(): ThreadComposerState {\n return this._getState();\n }\n\n public getAttachmentByIndex(idx: number) {\n return new ThreadComposerAttachmentRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n attachmentSource: \"thread-composer\",\n attachmentSelector: { type: \"index\", index: idx },\n ref: this.path.ref + `${this.path.ref}.attachments[${idx}]`,\n },\n getState: () => {\n const attachments = this.getState().attachments;\n const attachment = attachments[idx];\n if (!attachment) return SKIP_UPDATE;\n\n return {\n ...attachment,\n source: \"thread-composer\",\n } satisfies AttachmentState & { source: \"thread-composer\" };\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n }\n}\n\nexport type EditComposerRuntime = Omit<\n ComposerRuntime,\n \"getState\" | \"getAttachmentByIndex\"\n> & {\n readonly path: ComposerRuntimePath & { composerSource: \"edit\" };\n readonly type: \"edit\";\n\n getState(): EditComposerState;\n beginEdit(): void;\n\n getAttachmentByIndex(\n idx: number,\n ): AttachmentRuntime & { source: \"edit-composer\" };\n};\n\nexport class EditComposerRuntimeImpl\n extends ComposerRuntimeImpl\n implements EditComposerRuntime\n{\n public override get path() {\n return this._core.path as ComposerRuntimePath & { composerSource: \"edit\" };\n }\n\n public get type() {\n return \"edit\" as const;\n }\n\n private _getState;\n constructor(\n core: EditComposerRuntimeCoreBinding,\n private _beginEdit: () => void,\n ) {\n const stateBinding = new LazyMemoizeSubject({\n path: core.path,\n getState: () => getEditComposerState(core.getState()),\n subscribe: (callback) => core.subscribe(callback),\n });\n\n super({\n path: core.path,\n getState: () => core.getState(),\n subscribe: (callback) => stateBinding.subscribe(callback),\n });\n\n this._getState = stateBinding.getState.bind(stateBinding);\n }\n\n public override __internal_bindMethods() {\n super.__internal_bindMethods();\n this.beginEdit = this.beginEdit.bind(this);\n }\n\n public override getState(): EditComposerState {\n return this._getState();\n }\n\n public beginEdit() {\n this._beginEdit();\n }\n\n public getAttachmentByIndex(idx: number) {\n return new EditComposerAttachmentRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n attachmentSource: \"edit-composer\",\n attachmentSelector: { type: \"index\", index: idx },\n ref: this.path.ref + `${this.path.ref}.attachments[${idx}]`,\n },\n getState: () => {\n const attachments = this.getState().attachments;\n const attachment = attachments[idx];\n if (!attachment) return SKIP_UPDATE;\n\n return {\n ...attachment,\n source: \"edit-composer\",\n } satisfies AttachmentState & { source: \"edit-composer\" };\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n }\n}\n"],"mappings":";AAQA,SAAS,0BAA0B;AACnC;AAAA,EAGE;AAAA,EACA;AAAA,OACK;AACP,SAAS,6BAA6B;AACtC,SAAS,mBAAmB;AAG5B,SAAS,gCAAgC;AAwCzC,IAAM,cAAc,OAAO,OAAO,CAAC,CAAC;AACpC,IAAM,eAAe,OAAO,OAAO,CAAC,CAAC;AACrC,IAAM,yBAAyB,CAC7B,YACwB;AACxB,SAAO,OAAO,OAAO;AAAA,IACnB,MAAM;AAAA,IAEN,WAAW,SAAS,aAAa;AAAA,IACjC,WAAW,SAAS,aAAa;AAAA,IACjC,SAAS,SAAS,WAAW;AAAA,IAE7B,aAAa,SAAS,eAAe;AAAA,IACrC,M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A,QACxB,MAAM;AAAA,UACJ,GAAG,KAAK;AAAA,UACR,kBAAkB;AAAA,UAClB,oBAAoB,EAAE,MAAM,SAAS,OAAO,IAAI;AAAA,UAChD,KAAK,KAAK,KAAK,MAAM,GAAG,KAAK,KAAK,GAAG,gBAAgB,GAAG;AAAA,QAC1D;AAAA,QACA,UAAU,MAAM;AACd,gBAAM,cAAc,KAAK,SAAS,EAAE;AACpC,gBAAM,aAAa,YAAY,GAAG;AAClC,cAAI,CAAC,WAAY,QAAO;AAExB,iBAAO;AAAA,YACL,GAAG;AAAA,YACH,QAAQ;AAAA,UACV;AAAA,QACF;AAAA,QACA,WAAW,CAAC,aAAa,KAAK,MAAM,UAAU,QAAQ;AAAA,MACxD,CAAC;AAAA,MACD,KAAK;AAAA,IACP;AAAA,EACF;AACF;","names":[]}
@@ -1,4 +1,5 @@
1
- class ContentPartRuntimeImpl {
1
+ // src/api/ContentPartRuntime.ts
2
+ var ContentPartRuntimeImpl = class {
2
3
  constructor(contentBinding, messageApi, threadApi) {
3
4
  this.contentBinding = contentBinding;
4
5
  this.messageApi = messageApi;
@@ -39,7 +40,7 @@ class ContentPartRuntimeImpl {
39
40
  subscribe(callback) {
40
41
  return this.contentBinding.subscribe(callback);
41
42
  }
42
- }
43
+ };
43
44
  export {
44
45
  ContentPartRuntimeImpl
45
46
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/api/ContentPartRuntime.ts"],"sourcesContent":["import {\n ThreadAssistantContentPart,\n ThreadUserContentPart,\n ContentPartStatus,\n ToolCallContentPartStatus,\n} from \"../types/AssistantTypes\";\nimport { ThreadRuntimeCoreBinding } from \"./ThreadRuntime\";\nimport { MessageStateBinding } from \"./MessageRuntime\";\nimport { SubscribableWithState } from \"./subscribable/Subscribable\";\nimport { Unsubscribe } from \"../types\";\nimport { ContentPartRuntimePath } from \"./RuntimePathTypes\";\n\nexport type ContentPartState = (\n | ThreadUserContentPart\n | ThreadAssistantContentPart\n) & {\n readonly status: ContentPartStatus | ToolCallContentPartStatus;\n};\n\ntype ContentPartSnapshotBinding = SubscribableWithState<\n ContentPartState,\n ContentPartRuntimePath\n>;\n\nexport type ContentPartRuntime = {\n /**\n * Add tool result to a tool call content part that has no tool result yet.\n * This is useful when you are collecting a tool result via user input (\"human tool calls\").\n */\n addToolResult(result: any): void;\n\n readonly path: ContentPartRuntimePath;\n getState(): ContentPartState;\n subscribe(callback: () => void): Unsubscribe;\n};\n\nexport class ContentPartRuntimeImpl implements ContentPartRuntime {\n public get path() {\n return this.contentBinding.path;\n }\n\n constructor(\n private contentBinding: ContentPartSnapshotBinding,\n private messageApi?: MessageStateBinding,\n private threadApi?: ThreadRuntimeCoreBinding,\n ) {}\n\n protected __internal_bindMethods() {\n this.addToolResult = this.addToolResult.bind(this);\n this.getState = this.getState.bind(this);\n this.subscribe = this.subscribe.bind(this);\n }\n\n public getState() {\n return this.contentBinding.getState();\n }\n\n public addToolResult(result: any) {\n const state = this.contentBinding.getState();\n if (!state) throw new Error(\"Content part is not available\");\n\n if (state.type !== \"tool-call\")\n throw new Error(\"Tried to add tool result to non-tool content part\");\n\n if (!this.messageApi)\n throw new Error(\n \"Message API is not available. This is likely a bug in assistant-ui.\",\n );\n if (!this.threadApi) throw new Error(\"Thread API is not available\");\n\n const message = this.messageApi.getState();\n if (!message) throw new Error(\"Message is not available\");\n\n const toolName = state.toolName;\n const toolCallId = state.toolCallId;\n\n this.threadApi.getState().addToolResult({\n messageId: message.id,\n toolName,\n toolCallId,\n result,\n });\n }\n\n public subscribe(callback: () => void) {\n return this.contentBinding.subscribe(callback);\n }\n}\n"],"mappings":"AAoCO,MAAM,uBAAqD;AAAA,EAKhE,YACU,gBACA,YACA,WACR;AAHQ;AACA;AACA;AAAA,EACP;AAAA,EARH,IAAW,OAAO;AAChB,WAAO,KAAK,eAAe;AAAA,EAC7B;AAAA,EAQU,yBAAyB;AACjC,SAAK,gBAAgB,KAAK,cAAc,KAAK,IAAI;AACjD,SAAK,WAAW,KAAK,SAAS,KAAK,IAAI;AACvC,SAAK,YAAY,KAAK,UAAU,KAAK,IAAI;AAAA,EAC3C;AAAA,EAEO,WAAW;AAChB,WAAO,KAAK,eAAe,SAAS;AAAA,EACtC;AAAA,EAEO,cAAc,QAAa;AAChC,UAAM,QAAQ,KAAK,eAAe,SAAS;AAC3C,QAAI,CAAC,MAAO,OAAM,IAAI,MAAM,+BAA+B;AAE3D,QAAI,MAAM,SAAS;AACjB,YAAM,IAAI,MAAM,mDAAmD;AAErE,QAAI,CAAC,KAAK;AACR,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AACF,QAAI,CAAC,KAAK,UAAW,OAAM,IAAI,MAAM,6BAA6B;AAElE,UAAM,UAAU,KAAK,WAAW,SAAS;AACzC,QAAI,CAAC,QAAS,OAAM,IAAI,MAAM,0BAA0B;AAExD,UAAM,WAAW,MAAM;AACvB,UAAM,aAAa,MAAM;AAEzB,SAAK,UAAU,SAAS,EAAE,cAAc;AAAA,MACtC,WAAW,QAAQ;AAAA,MACnB;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EAEO,UAAU,UAAsB;AACrC,WAAO,KAAK,eAAe,UAAU,QAAQ;AAAA,EAC/C;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/api/ContentPartRuntime.ts"],"sourcesContent":["import {\n ThreadAssistantContentPart,\n ThreadUserContentPart,\n ContentPartStatus,\n ToolCallContentPartStatus,\n} from \"../types/AssistantTypes\";\nimport { ThreadRuntimeCoreBinding } from \"./ThreadRuntime\";\nimport { MessageStateBinding } from \"./MessageRuntime\";\nimport { SubscribableWithState } from \"./subscribable/Subscribable\";\nimport { Unsubscribe } from \"../types\";\nimport { ContentPartRuntimePath } from \"./RuntimePathTypes\";\n\nexport type ContentPartState = (\n | ThreadUserContentPart\n | ThreadAssistantContentPart\n) & {\n readonly status: ContentPartStatus | ToolCallContentPartStatus;\n};\n\ntype ContentPartSnapshotBinding = SubscribableWithState<\n ContentPartState,\n ContentPartRuntimePath\n>;\n\nexport type ContentPartRuntime = {\n /**\n * Add tool result to a tool call content part that has no tool result yet.\n * This is useful when you are collecting a tool result via user input (\"human tool calls\").\n */\n addToolResult(result: any): void;\n\n readonly path: ContentPartRuntimePath;\n getState(): ContentPartState;\n subscribe(callback: () => void): Unsubscribe;\n};\n\nexport class ContentPartRuntimeImpl implements ContentPartRuntime {\n public get path() {\n return this.contentBinding.path;\n }\n\n constructor(\n private contentBinding: ContentPartSnapshotBinding,\n private messageApi?: MessageStateBinding,\n private threadApi?: ThreadRuntimeCoreBinding,\n ) {}\n\n protected __internal_bindMethods() {\n this.addToolResult = this.addToolResult.bind(this);\n this.getState = this.getState.bind(this);\n this.subscribe = this.subscribe.bind(this);\n }\n\n public getState() {\n return this.contentBinding.getState();\n }\n\n public addToolResult(result: any) {\n const state = this.contentBinding.getState();\n if (!state) throw new Error(\"Content part is not available\");\n\n if (state.type !== \"tool-call\")\n throw new Error(\"Tried to add tool result to non-tool content part\");\n\n if (!this.messageApi)\n throw new Error(\n \"Message API is not available. This is likely a bug in assistant-ui.\",\n );\n if (!this.threadApi) throw new Error(\"Thread API is not available\");\n\n const message = this.messageApi.getState();\n if (!message) throw new Error(\"Message is not available\");\n\n const toolName = state.toolName;\n const toolCallId = state.toolCallId;\n\n this.threadApi.getState().addToolResult({\n messageId: message.id,\n toolName,\n toolCallId,\n result,\n });\n }\n\n public subscribe(callback: () => void) {\n return this.contentBinding.subscribe(callback);\n }\n}\n"],"mappings":";AAoCO,IAAM,yBAAN,MAA2D;AAAA,EAKhE,YACU,gBACA,YACA,WACR;AAHQ;AACA;AACA;AAAA,EACP;AAAA,EARH,IAAW,OAAO;AAChB,WAAO,KAAK,eAAe;AAAA,EAC7B;AAAA,EAQU,yBAAyB;AACjC,SAAK,gBAAgB,KAAK,cAAc,KAAK,IAAI;AACjD,SAAK,WAAW,KAAK,SAAS,KAAK,IAAI;AACvC,SAAK,YAAY,KAAK,UAAU,KAAK,IAAI;AAAA,EAC3C;AAAA,EAEO,WAAW;AAChB,WAAO,KAAK,eAAe,SAAS;AAAA,EACtC;AAAA,EAEO,cAAc,QAAa;AAChC,UAAM,QAAQ,KAAK,eAAe,SAAS;AAC3C,QAAI,CAAC,MAAO,OAAM,IAAI,MAAM,+BAA+B;AAE3D,QAAI,MAAM,SAAS;AACjB,YAAM,IAAI,MAAM,mDAAmD;AAErE,QAAI,CAAC,KAAK;AACR,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AACF,QAAI,CAAC,KAAK,UAAW,OAAM,IAAI,MAAM,6BAA6B;AAElE,UAAM,UAAU,KAAK,WAAW,SAAS;AACzC,QAAI,CAAC,QAAS,OAAM,IAAI,MAAM,0BAA0B;AAExD,UAAM,WAAW,MAAM;AACvB,UAAM,aAAa,MAAM;AAEzB,SAAK,UAAU,SAAS,EAAE,cAAc;AAAA,MACtC,WAAW,QAAQ;AAAA,MACnB;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EAEO,UAAU,UAAsB;AACrC,WAAO,KAAK,eAAe,UAAU,QAAQ;AAAA,EAC/C;AACF;","names":[]}
@@ -1,21 +1,22 @@
1
- import { symbolInnerMessage } from "../runtimes/external-store/getExternalStoreMessage";
2
- import { getThreadMessageText } from "../utils/getThreadMessageText";
1
+ // src/api/MessageRuntime.ts
2
+ import { symbolInnerMessage } from "../runtimes/external-store/getExternalStoreMessage.js";
3
+ import { getThreadMessageText } from "../utils/getThreadMessageText.js";
3
4
  import {
4
5
  MessageAttachmentRuntimeImpl
5
- } from "./AttachmentRuntime";
6
+ } from "./AttachmentRuntime.js";
6
7
  import {
7
8
  EditComposerRuntimeImpl
8
- } from "./ComposerRuntime";
9
+ } from "./ComposerRuntime.js";
9
10
  import {
10
11
  ContentPartRuntimeImpl
11
- } from "./ContentPartRuntime";
12
- import { NestedSubscriptionSubject } from "./subscribable/NestedSubscriptionSubject";
13
- import { SKIP_UPDATE } from "./subscribable/SKIP_UPDATE";
14
- import { ShallowMemoizeSubject } from "./subscribable/ShallowMemoizeSubject";
15
- const COMPLETE_STATUS = Object.freeze({
12
+ } from "./ContentPartRuntime.js";
13
+ import { NestedSubscriptionSubject } from "./subscribable/NestedSubscriptionSubject.js";
14
+ import { SKIP_UPDATE } from "./subscribable/SKIP_UPDATE.js";
15
+ import { ShallowMemoizeSubject } from "./subscribable/ShallowMemoizeSubject.js";
16
+ var COMPLETE_STATUS = Object.freeze({
16
17
  type: "complete"
17
18
  });
18
- const toContentPartStatus = (message, partIndex, part) => {
19
+ var toContentPartStatus = (message, partIndex, part) => {
19
20
  if (message.role !== "assistant") return COMPLETE_STATUS;
20
21
  if (part.type === "tool-call") {
21
22
  if (!part.result) {
@@ -28,7 +29,7 @@ const toContentPartStatus = (message, partIndex, part) => {
28
29
  if (message.status.type === "requires-action") return COMPLETE_STATUS;
29
30
  return isLastPart ? message.status : COMPLETE_STATUS;
30
31
  };
31
- const getContentPartState = (message, partIndex) => {
32
+ var getContentPartState = (message, partIndex) => {
32
33
  const part = message.content[partIndex];
33
34
  if (!part) {
34
35
  return SKIP_UPDATE;
@@ -40,7 +41,7 @@ const getContentPartState = (message, partIndex) => {
40
41
  status
41
42
  });
42
43
  };
43
- class MessageRuntimeImpl {
44
+ var MessageRuntimeImpl = class {
44
45
  constructor(_core, _threadBinding) {
45
46
  this._core = _core;
46
47
  this._threadBinding = _threadBinding;
@@ -203,7 +204,7 @@ class MessageRuntimeImpl {
203
204
  })
204
205
  );
205
206
  }
206
- }
207
+ };
207
208
  export {
208
209
  MessageRuntimeImpl,
209
210
  toContentPartStatus
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/api/MessageRuntime.ts"],"sourcesContent":["import {\n SpeechState,\n SubmittedFeedback,\n} from \"../runtimes/core/ThreadRuntimeCore\";\nimport { symbolInnerMessage } from \"../runtimes/external-store/getExternalStoreMessage\";\nimport {\n ThreadMessage,\n ThreadAssistantContentPart,\n ThreadUserContentPart,\n Unsubscribe,\n} from \"../types\";\nimport {\n ContentPartStatus,\n RunConfig,\n ToolCallContentPartStatus,\n} from \"../types/AssistantTypes\";\nimport { getThreadMessageText } from \"../utils/getThreadMessageText\";\nimport {\n AttachmentRuntime,\n AttachmentState,\n MessageAttachmentRuntimeImpl,\n} from \"./AttachmentRuntime\";\nimport {\n EditComposerRuntime,\n EditComposerRuntimeImpl,\n} from \"./ComposerRuntime\";\nimport {\n ContentPartRuntime,\n ContentPartRuntimeImpl,\n ContentPartState,\n} from \"./ContentPartRuntime\";\nimport { MessageRuntimePath } from \"./RuntimePathTypes\";\nimport { ThreadRuntimeCoreBinding } from \"./ThreadRuntime\";\nimport { NestedSubscriptionSubject } from \"./subscribable/NestedSubscriptionSubject\";\nimport { SKIP_UPDATE } from \"./subscribable/SKIP_UPDATE\";\nimport { ShallowMemoizeSubject } from \"./subscribable/ShallowMemoizeSubject\";\nimport { SubscribableWithState } from \"./subscribable/Subscribable\";\n\nconst COMPLETE_STATUS: ContentPartStatus = Object.freeze({\n type: \"complete\",\n});\n\nexport const toContentPartStatus = (\n message: ThreadMessage,\n partIndex: number,\n part: ThreadUserContentPart | ThreadAssistantContentPart,\n): ToolCallContentPartStatus => {\n if (message.role !== \"assistant\") return COMPLETE_STATUS;\n\n if (part.type === \"tool-call\") {\n if (!part.result) {\n return message.status as ToolCallContentPartStatus;\n } else {\n return COMPLETE_STATUS;\n }\n }\n\n const isLastPart = partIndex === Math.max(0, message.content.length - 1);\n if (message.status.type === \"requires-action\") return COMPLETE_STATUS;\n return isLastPart ? (message.status as ContentPartStatus) : COMPLETE_STATUS;\n};\n\nconst getContentPartState = (\n message: MessageState,\n partIndex: number,\n): ContentPartState | SKIP_UPDATE => {\n const part = message.content[partIndex];\n if (!part) {\n return SKIP_UPDATE;\n }\n\n // if the content part is the same, don't update\n const status = toContentPartStatus(message, partIndex, part);\n return Object.freeze({\n ...part,\n ...{ [symbolInnerMessage]: (part as any)[symbolInnerMessage] },\n status,\n });\n};\n\nexport type MessageState = ThreadMessage & {\n readonly parentId: string | null;\n readonly isLast: boolean;\n\n readonly branchNumber: number;\n readonly branchCount: number;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n readonly speech: SpeechState | undefined;\n readonly submittedFeedback: SubmittedFeedback | undefined;\n};\n\nexport type MessageStateBinding = SubscribableWithState<\n MessageState,\n MessageRuntimePath\n>;\n\ntype ReloadConfig = {\n runConfig?: RunConfig;\n};\n\nexport type MessageRuntime = {\n readonly path: MessageRuntimePath;\n\n readonly composer: EditComposerRuntime;\n\n getState(): MessageState;\n reload(config?: ReloadConfig): void;\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n speak(): void;\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n stopSpeaking(): void;\n submitFeedback({ type }: { type: \"positive\" | \"negative\" }): void;\n switchToBranch({\n position,\n branchId,\n }: {\n position?: \"previous\" | \"next\" | undefined;\n branchId?: string | undefined;\n }): void;\n unstable_getCopyText(): string;\n\n subscribe(callback: () => void): Unsubscribe;\n\n getContentPartByIndex(idx: number): ContentPartRuntime;\n getContentPartByToolCallId(toolCallId: string): ContentPartRuntime;\n\n getAttachmentByIndex(idx: number): AttachmentRuntime & { source: \"message\" };\n};\n\nexport class MessageRuntimeImpl implements MessageRuntime {\n public get path() {\n return this._core.path;\n }\n\n constructor(\n private _core: MessageStateBinding,\n private _threadBinding: ThreadRuntimeCoreBinding,\n ) {\n this.composer = new EditComposerRuntimeImpl(\n new NestedSubscriptionSubject({\n path: {\n ...this.path,\n ref: this.path.ref + `${this.path.ref}.composer`,\n composerSource: \"edit\",\n },\n getState: this._getEditComposerRuntimeCore,\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n () => this._threadBinding.getState().beginEdit(this._core.getState().id),\n );\n }\n\n protected __internal_bindMethods() {\n this.reload = this.reload.bind(this);\n this.getState = this.getState.bind(this);\n this.subscribe = this.subscribe.bind(this);\n this.getContentPartByIndex = this.getContentPartByIndex.bind(this);\n this.getContentPartByToolCallId =\n this.getContentPartByToolCallId.bind(this);\n this.getAttachmentByIndex = this.getAttachmentByIndex.bind(this);\n this.unstable_getCopyText = this.unstable_getCopyText.bind(this);\n this.speak = this.speak.bind(this);\n this.stopSpeaking = this.stopSpeaking.bind(this);\n this.submitFeedback = this.submitFeedback.bind(this);\n this.switchToBranch = this.switchToBranch.bind(this);\n }\n\n public readonly composer;\n\n private _getEditComposerRuntimeCore = () => {\n return this._threadBinding\n .getState()\n .getEditComposer(this._core.getState().id);\n };\n\n public getState() {\n return this._core.getState();\n }\n\n public reload(reloadConfig: ReloadConfig = {}) {\n const editComposerRuntimeCore = this._getEditComposerRuntimeCore();\n const composerRuntimeCore =\n editComposerRuntimeCore ?? this._threadBinding.getState().composer;\n const composer = editComposerRuntimeCore ?? composerRuntimeCore;\n\n const { runConfig = composer.runConfig } = reloadConfig;\n const state = this._core.getState();\n if (state.role !== \"assistant\")\n throw new Error(\"Can only reload assistant messages\");\n\n this._threadBinding.getState().startRun({\n parentId: state.parentId,\n sourceId: state.id,\n runConfig,\n });\n }\n\n public speak() {\n const state = this._core.getState();\n return this._threadBinding.getState().speak(state.id);\n }\n\n public stopSpeaking() {\n const state = this._core.getState();\n const thread = this._threadBinding.getState();\n if (thread.speech?.messageId === state.id) {\n this._threadBinding.getState().stopSpeaking();\n } else {\n throw new Error(\"Message is not being spoken\");\n }\n }\n\n public submitFeedback({ type }: { type: \"positive\" | \"negative\" }) {\n const state = this._core.getState();\n this._threadBinding.getState().submitFeedback({\n messageId: state.id,\n type,\n });\n }\n\n public switchToBranch({\n position,\n branchId,\n }: {\n position?: \"previous\" | \"next\" | undefined;\n branchId?: string | undefined;\n }) {\n const state = this._core.getState();\n if (branchId && position) {\n throw new Error(\"May not specify both branchId and position\");\n } else if (!branchId && !position) {\n throw new Error(\"Must specify either branchId or position\");\n }\n\n const thread = this._threadBinding.getState();\n const branches = thread.getBranches(state.id);\n let targetBranch = branchId;\n if (position === \"previous\") {\n targetBranch = branches[state.branchNumber - 2];\n } else if (position === \"next\") {\n targetBranch = branches[state.branchNumber];\n }\n if (!targetBranch) throw new Error(\"Branch not found\");\n\n this._threadBinding.getState().switchToBranch(targetBranch);\n }\n\n public unstable_getCopyText() {\n return getThreadMessageText(this.getState());\n }\n\n public subscribe(callback: () => void) {\n return this._core.subscribe(callback);\n }\n\n public getContentPartByIndex(idx: number) {\n if (idx < 0) throw new Error(\"Content part index must be >= 0\");\n return new ContentPartRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n ref: this.path.ref + `${this.path.ref}.content[${idx}]`,\n contentPartSelector: { type: \"index\", index: idx },\n },\n getState: () => {\n return getContentPartState(this.getState(), idx);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n this._threadBinding,\n );\n }\n\n public getContentPartByToolCallId(toolCallId: string) {\n return new ContentPartRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n ref:\n this.path.ref +\n `${this.path.ref}.content[toolCallId=${JSON.stringify(toolCallId)}]`,\n contentPartSelector: { type: \"toolCallId\", toolCallId },\n },\n getState: () => {\n const state = this._core.getState();\n const idx = state.content.findIndex(\n (part) =>\n part.type === \"tool-call\" && part.toolCallId === toolCallId,\n );\n if (idx === -1) return SKIP_UPDATE;\n return getContentPartState(state, idx);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n this._threadBinding,\n );\n }\n\n public getAttachmentByIndex(idx: number) {\n return new MessageAttachmentRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n ref: this.path.ref + `${this.path.ref}.attachments[${idx}]`,\n attachmentSource: \"message\",\n attachmentSelector: { type: \"index\", index: idx },\n },\n getState: () => {\n const attachments = this.getState().attachments;\n const attachment = attachments?.[idx];\n if (!attachment) return SKIP_UPDATE;\n\n return {\n ...attachment,\n source: \"message\",\n } satisfies AttachmentState & { source: \"message\" };\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n );\n }\n}\n"],"mappings":"AAIA,SAAS,0BAA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ACP;AAAA,EACF;AAAA,EAEO,qBAAqB,KAAa;AACvC,WAAO,IAAI;AAAA,MACT,IAAI,sBAAsB;AAAA,QACxB,MAAM;AAAA,UACJ,GAAG,KAAK;AAAA,UACR,KAAK,KAAK,KAAK,MAAM,GAAG,KAAK,KAAK,GAAG,gBAAgB,GAAG;AAAA,UACxD,kBAAkB;AAAA,UAClB,oBAAoB,EAAE,MAAM,SAAS,OAAO,IAAI;AAAA,QAClD;AAAA,QACA,UAAU,MAAM;AACd,gBAAM,cAAc,KAAK,SAAS,EAAE;AACpC,gBAAM,aAAa,cAAc,GAAG;AACpC,cAAI,CAAC,WAAY,QAAO;AAExB,iBAAO;AAAA,YACL,GAAG;AAAA,YACH,QAAQ;AAAA,UACV;AAAA,QACF;AAAA,QACA,WAAW,CAAC,aAAa,KAAK,MAAM,UAAU,QAAQ;AAAA,MACxD,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/api/MessageRuntime.ts"],"sourcesContent":["import {\n SpeechState,\n SubmittedFeedback,\n} from \"../runtimes/core/ThreadRuntimeCore\";\nimport { symbolInnerMessage } from \"../runtimes/external-store/getExternalStoreMessage\";\nimport {\n ThreadMessage,\n ThreadAssistantContentPart,\n ThreadUserContentPart,\n Unsubscribe,\n} from \"../types\";\nimport {\n ContentPartStatus,\n RunConfig,\n ToolCallContentPartStatus,\n} from \"../types/AssistantTypes\";\nimport { getThreadMessageText } from \"../utils/getThreadMessageText\";\nimport {\n AttachmentRuntime,\n AttachmentState,\n MessageAttachmentRuntimeImpl,\n} from \"./AttachmentRuntime\";\nimport {\n EditComposerRuntime,\n EditComposerRuntimeImpl,\n} from \"./ComposerRuntime\";\nimport {\n ContentPartRuntime,\n ContentPartRuntimeImpl,\n ContentPartState,\n} from \"./ContentPartRuntime\";\nimport { MessageRuntimePath } from \"./RuntimePathTypes\";\nimport { ThreadRuntimeCoreBinding } from \"./ThreadRuntime\";\nimport { NestedSubscriptionSubject } from \"./subscribable/NestedSubscriptionSubject\";\nimport { SKIP_UPDATE } from \"./subscribable/SKIP_UPDATE\";\nimport { ShallowMemoizeSubject } from \"./subscribable/ShallowMemoizeSubject\";\nimport { SubscribableWithState } from \"./subscribable/Subscribable\";\n\nconst COMPLETE_STATUS: ContentPartStatus = Object.freeze({\n type: \"complete\",\n});\n\nexport const toContentPartStatus = (\n message: ThreadMessage,\n partIndex: number,\n part: ThreadUserContentPart | ThreadAssistantContentPart,\n): ToolCallContentPartStatus => {\n if (message.role !== \"assistant\") return COMPLETE_STATUS;\n\n if (part.type === \"tool-call\") {\n if (!part.result) {\n return message.status as ToolCallContentPartStatus;\n } else {\n return COMPLETE_STATUS;\n }\n }\n\n const isLastPart = partIndex === Math.max(0, message.content.length - 1);\n if (message.status.type === \"requires-action\") return COMPLETE_STATUS;\n return isLastPart ? (message.status as ContentPartStatus) : COMPLETE_STATUS;\n};\n\nconst getContentPartState = (\n message: MessageState,\n partIndex: number,\n): ContentPartState | SKIP_UPDATE => {\n const part = message.content[partIndex];\n if (!part) {\n return SKIP_UPDATE;\n }\n\n // if the content part is the same, don't update\n const status = toContentPartStatus(message, partIndex, part);\n return Object.freeze({\n ...part,\n ...{ [symbolInnerMessage]: (part as any)[symbolInnerMessage] },\n status,\n });\n};\n\nexport type MessageState = ThreadMessage & {\n readonly parentId: string | null;\n readonly isLast: boolean;\n\n readonly branchNumber: number;\n readonly branchCount: number;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n readonly speech: SpeechState | undefined;\n readonly submittedFeedback: SubmittedFeedback | undefined;\n};\n\nexport type MessageStateBinding = SubscribableWithState<\n MessageState,\n MessageRuntimePath\n>;\n\ntype ReloadConfig = {\n runConfig?: RunConfig;\n};\n\nexport type MessageRuntime = {\n readonly path: MessageRuntimePath;\n\n readonly composer: EditComposerRuntime;\n\n getState(): MessageState;\n reload(config?: ReloadConfig): void;\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n speak(): void;\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n stopSpeaking(): void;\n submitFeedback({ type }: { type: \"positive\" | \"negative\" }): void;\n switchToBranch({\n position,\n branchId,\n }: {\n position?: \"previous\" | \"next\" | undefined;\n branchId?: string | undefined;\n }): void;\n unstable_getCopyText(): string;\n\n subscribe(callback: () => void): Unsubscribe;\n\n getContentPartByIndex(idx: number): ContentPartRuntime;\n getContentPartByToolCallId(toolCallId: string): ContentPartRuntime;\n\n getAttachmentByIndex(idx: number): AttachmentRuntime & { source: \"message\" };\n};\n\nexport class MessageRuntimeImpl implements MessageRuntime {\n public get path() {\n return this._core.path;\n }\n\n constructor(\n private _core: MessageStateBinding,\n private _threadBinding: ThreadRuntimeCoreBinding,\n ) {\n this.composer = new EditComposerRuntimeImpl(\n new NestedSubscriptionSubject({\n path: {\n ...this.path,\n ref: this.path.ref + `${this.path.ref}.composer`,\n composerSource: \"edit\",\n },\n getState: this._getEditComposerRuntimeCore,\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n () => this._threadBinding.getState().beginEdit(this._core.getState().id),\n );\n }\n\n protected __internal_bindMethods() {\n this.reload = this.reload.bind(this);\n this.getState = this.getState.bind(this);\n this.subscribe = this.subscribe.bind(this);\n this.getContentPartByIndex = this.getContentPartByIndex.bind(this);\n this.getContentPartByToolCallId =\n this.getContentPartByToolCallId.bind(this);\n this.getAttachmentByIndex = this.getAttachmentByIndex.bind(this);\n this.unstable_getCopyText = this.unstable_getCopyText.bind(this);\n this.speak = this.speak.bind(this);\n this.stopSpeaking = this.stopSpeaking.bind(this);\n this.submitFeedback = this.submitFeedback.bind(this);\n this.switchToBranch = this.switchToBranch.bind(this);\n }\n\n public readonly composer;\n\n private _getEditComposerRuntimeCore = () => {\n return this._threadBinding\n .getState()\n .getEditComposer(this._core.getState().id);\n };\n\n public getState() {\n return this._core.getState();\n }\n\n public reload(reloadConfig: ReloadConfig = {}) {\n const editComposerRuntimeCore = this._getEditComposerRuntimeCore();\n const composerRuntimeCore =\n editComposerRuntimeCore ?? this._threadBinding.getState().composer;\n const composer = editComposerRuntimeCore ?? composerRuntimeCore;\n\n const { runConfig = composer.runConfig } = reloadConfig;\n const state = this._core.getState();\n if (state.role !== \"assistant\")\n throw new Error(\"Can only reload assistant messages\");\n\n this._threadBinding.getState().startRun({\n parentId: state.parentId,\n sourceId: state.id,\n runConfig,\n });\n }\n\n public speak() {\n const state = this._core.getState();\n return this._threadBinding.getState().speak(state.id);\n }\n\n public stopSpeaking() {\n const state = this._core.getState();\n const thread = this._threadBinding.getState();\n if (thread.speech?.messageId === state.id) {\n this._threadBinding.getState().stopSpeaking();\n } else {\n throw new Error(\"Message is not being spoken\");\n }\n }\n\n public submitFeedback({ type }: { type: \"positive\" | \"negative\" }) {\n const state = this._core.getState();\n this._threadBinding.getState().submitFeedback({\n messageId: state.id,\n type,\n });\n }\n\n public switchToBranch({\n position,\n branchId,\n }: {\n position?: \"previous\" | \"next\" | undefined;\n branchId?: string | undefined;\n }) {\n const state = this._core.getState();\n if (branchId && position) {\n throw new Error(\"May not specify both branchId and position\");\n } else if (!branchId && !position) {\n throw new Error(\"Must specify either branchId or position\");\n }\n\n const thread = this._threadBinding.getState();\n const branches = thread.getBranches(state.id);\n let targetBranch = branchId;\n if (position === \"previous\") {\n targetBranch = branches[state.branchNumber - 2];\n } else if (position === \"next\") {\n targetBranch = branches[state.branchNumber];\n }\n if (!targetBranch) throw new Error(\"Branch not found\");\n\n this._threadBinding.getState().switchToBranch(targetBranch);\n }\n\n public unstable_getCopyText() {\n return getThreadMessageText(this.getState());\n }\n\n public subscribe(callback: () => void) {\n return this._core.subscribe(callback);\n }\n\n public getContentPartByIndex(idx: number) {\n if (idx < 0) throw new Error(\"Content part index must be >= 0\");\n return new ContentPartRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n ref: this.path.ref + `${this.path.ref}.content[${idx}]`,\n contentPartSelector: { type: \"index\", index: idx },\n },\n getState: () => {\n return getContentPartState(this.getState(), idx);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n this._threadBinding,\n );\n }\n\n public getContentPartByToolCallId(toolCallId: string) {\n return new ContentPartRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n ref:\n this.path.ref +\n `${this.path.ref}.content[toolCallId=${JSON.stringify(toolCallId)}]`,\n contentPartSelector: { type: \"toolCallId\", toolCallId },\n },\n getState: () => {\n const state = this._core.getState();\n const idx = state.content.findIndex(\n (part) =>\n part.type === \"tool-call\" && part.toolCallId === toolCallId,\n );\n if (idx === -1) return SKIP_UPDATE;\n return getContentPartState(state, idx);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n this._threadBinding,\n );\n }\n\n public getAttachmentByIndex(idx: number) {\n return new MessageAttachmentRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n ref: this.path.ref + `${this.path.ref}.attachments[${idx}]`,\n attachmentSource: \"message\",\n attachmentSelector: { type: \"index\", index: idx },\n },\n getState: () => {\n const attachments = this.getState().attachments;\n const attachment = attachments?.[idx];\n if (!attachment) return SKIP_UPDATE;\n\n return {\n ...attachment,\n source: \"message\",\n } satisfies AttachmentState & { source: \"message\" };\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n );\n }\n}\n"],"mappings":";AAIA,SAAS,0BAA0B;AAYnC,SAAS,4BAA4B;AACrC;AAAA,EAGE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OAEK;AAGP,SAAS,iCAAiC;AAC1C,SAAS,mBAAmB;AAC5B,SAAS,6BAA6B;AAGtC,IAAM,kBAAqC,OAAO,OAAO;AAAA,EACvD,MAAM;AACR,CAAC;AAEM,IAAM,sBAAsB,CACjC,SACA,WACA,SAC8B;AAC9B,MAAI,QAAQ,SAAS,YAAa,QAAO;AAEzC,MAAI,KAAK,SAAS,aAAa;AAC7B,QAAI,CAAC,KAAK,QAAQ;AAChB,aAAO,QAAQ;AAAA,IACj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ExB,iBAAO;AAAA,YACL,GAAG;AAAA,YACH,QAAQ;AAAA,UACV;AAAA,QACF;AAAA,QACA,WAAW,CAAC,aAAa,KAAK,MAAM,UAAU,QAAQ;AAAA,MACxD,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":[]}
@@ -1,4 +1,5 @@
1
- class ThreadListItemRuntimeImpl {
1
+ // src/api/ThreadListItemRuntime.ts
2
+ var ThreadListItemRuntimeImpl = class {
2
3
  constructor(_core, _threadListBinding) {
3
4
  this._core = _core;
4
5
  this._threadListBinding = _threadListBinding;
@@ -63,7 +64,7 @@ class ThreadListItemRuntimeImpl {
63
64
  subscribe(callback) {
64
65
  return this._core.subscribe(callback);
65
66
  }
66
- }
67
+ };
67
68
  export {
68
69
  ThreadListItemRuntimeImpl
69
70
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/api/ThreadListItemRuntime.ts"],"sourcesContent":["import { Unsubscribe } from \"../types\";\nimport { ThreadListItemRuntimePath } from \"./RuntimePathTypes\";\nimport { SubscribableWithState } from \"./subscribable/Subscribable\";\nimport { ThreadListRuntimeCoreBinding } from \"./ThreadListRuntime\";\n\nexport type ThreadListItemEventType = \"switched-to\" | \"switched-away\";\n\nexport type ThreadListItemState = {\n readonly isMain: boolean;\n\n readonly id: string;\n readonly remoteId: string | undefined;\n readonly externalId: string | undefined;\n\n /**\n * @deprecated This field was renamed to `id`. This field will be removed in 0.8.0.\n */\n readonly threadId: string;\n\n readonly status: \"archived\" | \"regular\" | \"new\" | \"deleted\";\n readonly title?: string | undefined;\n};\n\nexport type ThreadListItemRuntime = {\n readonly path: ThreadListItemRuntimePath;\n getState(): ThreadListItemState;\n\n initialize(): Promise<{ remoteId: string; externalId: string | undefined }>;\n generateTitle(): Promise<void>;\n\n switchTo(): Promise<void>;\n rename(newTitle: string): Promise<void>;\n archive(): Promise<void>;\n unarchive(): Promise<void>;\n delete(): Promise<void>;\n\n subscribe(callback: () => void): Unsubscribe;\n\n unstable_on(\n event: ThreadListItemEventType,\n callback: () => void,\n ): Unsubscribe;\n};\n\nexport type ThreadListItemStateBinding = SubscribableWithState<\n ThreadListItemState,\n ThreadListItemRuntimePath\n>;\n\nexport class ThreadListItemRuntimeImpl implements ThreadListItemRuntime {\n public get path() {\n return this._core.path;\n }\n\n constructor(\n private _core: ThreadListItemStateBinding,\n private _threadListBinding: ThreadListRuntimeCoreBinding,\n ) {}\n\n protected __internal_bindMethods() {\n this.switchTo = this.switchTo.bind(this);\n this.rename = this.rename.bind(this);\n this.archive = this.archive.bind(this);\n this.unarchive = this.unarchive.bind(this);\n this.delete = this.delete.bind(this);\n this.initialize = this.initialize.bind(this);\n this.generateTitle = this.generateTitle.bind(this);\n this.subscribe = this.subscribe.bind(this);\n this.unstable_on = this.unstable_on.bind(this);\n this.getState = this.getState.bind(this);\n }\n\n public getState(): ThreadListItemState {\n return this._core.getState();\n }\n\n public switchTo(): Promise<void> {\n const state = this._core.getState();\n return this._threadListBinding.switchToThread(state.id);\n }\n\n public rename(newTitle: string): Promise<void> {\n const state = this._core.getState();\n\n return this._threadListBinding.rename(state.id, newTitle);\n }\n\n public archive(): Promise<void> {\n const state = this._core.getState();\n\n return this._threadListBinding.archive(state.id);\n }\n\n public unarchive(): Promise<void> {\n const state = this._core.getState();\n\n return this._threadListBinding.unarchive(state.id);\n }\n\n public delete(): Promise<void> {\n const state = this._core.getState();\n\n return this._threadListBinding.delete(state.id);\n }\n\n public initialize(): Promise<{\n remoteId: string;\n externalId: string | undefined;\n }> {\n const state = this._core.getState();\n return this._threadListBinding.initialize(state.id);\n }\n\n public generateTitle(): Promise<void> {\n const state = this._core.getState();\n return this._threadListBinding.generateTitle(state.id);\n }\n\n public unstable_on(event: ThreadListItemEventType, callback: () => void) {\n let prevIsMain = this._core.getState().isMain;\n return this.subscribe(() => {\n const newIsMain = this._core.getState().isMain;\n if (prevIsMain === newIsMain) return;\n prevIsMain = newIsMain;\n\n if (event === \"switched-to\" && !newIsMain) return;\n if (event === \"switched-away\" && newIsMain) return;\n callback();\n });\n }\n\n public subscribe(callback: () => void): Unsubscribe {\n return this._core.subscribe(callback);\n }\n}\n"],"mappings":"AAiDO,MAAM,0BAA2D;AAAA,EAKtE,YACU,OACA,oBACR;AAFQ;AACA;AAAA,EACP;AAAA,EAPH,IAAW,OAAO;AAChB,WAAO,KAAK,MAAM;AAAA,EACpB;AAAA,EAOU,yBAAyB;AACjC,SAAK,WAAW,KAAK,SAAS,KAAK,IAAI;AACvC,SAAK,SAAS,KAAK,OAAO,KAAK,IAAI;AACnC,SAAK,UAAU,KAAK,QAAQ,KAAK,IAAI;AACrC,SAAK,YAAY,KAAK,UAAU,KAAK,IAAI;AACzC,SAAK,SAAS,KAAK,OAAO,KAAK,IAAI;AACnC,SAAK,aAAa,KAAK,WAAW,KAAK,IAAI;AAC3C,SAAK,gBAAgB,KAAK,cAAc,KAAK,IAAI;AACjD,SAAK,YAAY,KAAK,UAAU,KAAK,IAAI;AACzC,SAAK,cAAc,KAAK,YAAY,KAAK,IAAI;AAC7C,SAAK,WAAW,KAAK,SAAS,KAAK,IAAI;AAAA,EACzC;AAAA,EAEO,WAAgC;AACrC,WAAO,KAAK,MAAM,SAAS;AAAA,EAC7B;AAAA,EAEO,WAA0B;AAC/B,UAAM,QAAQ,KAAK,MAAM,SAAS;AAClC,WAAO,KAAK,mBAAmB,eAAe,MAAM,EAAE;AAAA,EACxD;AAAA,EAEO,OAAO,UAAiC;AAC7C,UAAM,QAAQ,KAAK,MAAM,SAAS;AAElC,WAAO,KAAK,mBAAmB,OAAO,MAAM,IAAI,QAAQ;AAAA,EAC1D;AAAA,EAEO,UAAyB;AAC9B,UAAM,QAAQ,KAAK,MAAM,SAAS;AAElC,WAAO,KAAK,mBAAmB,QAAQ,MAAM,EAAE;AAAA,EACjD;AAAA,EAEO,YAA2B;AAChC,UAAM,QAAQ,KAAK,MAAM,SAAS;AAElC,WAAO,KAAK,mBAAmB,UAAU,MAAM,EAAE;AAAA,EACnD;AAAA,EAEO,SAAwB;AAC7B,UAAM,QAAQ,KAAK,MAAM,SAAS;AAElC,WAAO,KAAK,mBAAmB,OAAO,MAAM,EAAE;AAAA,EAChD;AAAA,EAEO,aAGJ;AACD,UAAM,QAAQ,KAAK,MAAM,SAAS;AAClC,WAAO,KAAK,mBAAmB,WAAW,MAAM,EAAE;AAAA,EACpD;AAAA,EAEO,gBAA+B;AACpC,UAAM,QAAQ,KAAK,MAAM,SAAS;AAClC,WAAO,KAAK,mBAAmB,cAAc,MAAM,EAAE;AAAA,EACvD;AAAA,EAEO,YAAY,OAAgC,UAAsB;AACvE,QAAI,aAAa,KAAK,MAAM,SAAS,EAAE;AACvC,WAAO,KAAK,UAAU,MAAM;AAC1B,YAAM,YAAY,KAAK,MAAM,SAAS,EAAE;AACxC,UAAI,eAAe,UAAW;AAC9B,mBAAa;AAEb,UAAI,UAAU,iBAAiB,CAAC,UAAW;AAC3C,UAAI,UAAU,mBAAmB,UAAW;AAC5C,eAAS;AAAA,IACX,CAAC;AAAA,EACH;AAAA,EAEO,UAAU,UAAmC;AAClD,WAAO,KAAK,MAAM,UAAU,QAAQ;AAAA,EACtC;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/api/ThreadListItemRuntime.ts"],"sourcesContent":["import { Unsubscribe } from \"../types\";\nimport { ThreadListItemRuntimePath } from \"./RuntimePathTypes\";\nimport { SubscribableWithState } from \"./subscribable/Subscribable\";\nimport { ThreadListRuntimeCoreBinding } from \"./ThreadListRuntime\";\n\nexport type ThreadListItemEventType = \"switched-to\" | \"switched-away\";\n\nexport type ThreadListItemState = {\n readonly isMain: boolean;\n\n readonly id: string;\n readonly remoteId: string | undefined;\n readonly externalId: string | undefined;\n\n /**\n * @deprecated This field was renamed to `id`. This field will be removed in 0.8.0.\n */\n readonly threadId: string;\n\n readonly status: \"archived\" | \"regular\" | \"new\" | \"deleted\";\n readonly title?: string | undefined;\n};\n\nexport type ThreadListItemRuntime = {\n readonly path: ThreadListItemRuntimePath;\n getState(): ThreadListItemState;\n\n initialize(): Promise<{ remoteId: string; externalId: string | undefined }>;\n generateTitle(): Promise<void>;\n\n switchTo(): Promise<void>;\n rename(newTitle: string): Promise<void>;\n archive(): Promise<void>;\n unarchive(): Promise<void>;\n delete(): Promise<void>;\n\n subscribe(callback: () => void): Unsubscribe;\n\n unstable_on(\n event: ThreadListItemEventType,\n callback: () => void,\n ): Unsubscribe;\n};\n\nexport type ThreadListItemStateBinding = SubscribableWithState<\n ThreadListItemState,\n ThreadListItemRuntimePath\n>;\n\nexport class ThreadListItemRuntimeImpl implements ThreadListItemRuntime {\n public get path() {\n return this._core.path;\n }\n\n constructor(\n private _core: ThreadListItemStateBinding,\n private _threadListBinding: ThreadListRuntimeCoreBinding,\n ) {}\n\n protected __internal_bindMethods() {\n this.switchTo = this.switchTo.bind(this);\n this.rename = this.rename.bind(this);\n this.archive = this.archive.bind(this);\n this.unarchive = this.unarchive.bind(this);\n this.delete = this.delete.bind(this);\n this.initialize = this.initialize.bind(this);\n this.generateTitle = this.generateTitle.bind(this);\n this.subscribe = this.subscribe.bind(this);\n this.unstable_on = this.unstable_on.bind(this);\n this.getState = this.getState.bind(this);\n }\n\n public getState(): ThreadListItemState {\n return this._core.getState();\n }\n\n public switchTo(): Promise<void> {\n const state = this._core.getState();\n return this._threadListBinding.switchToThread(state.id);\n }\n\n public rename(newTitle: string): Promise<void> {\n const state = this._core.getState();\n\n return this._threadListBinding.rename(state.id, newTitle);\n }\n\n public archive(): Promise<void> {\n const state = this._core.getState();\n\n return this._threadListBinding.archive(state.id);\n }\n\n public unarchive(): Promise<void> {\n const state = this._core.getState();\n\n return this._threadListBinding.unarchive(state.id);\n }\n\n public delete(): Promise<void> {\n const state = this._core.getState();\n\n return this._threadListBinding.delete(state.id);\n }\n\n public initialize(): Promise<{\n remoteId: string;\n externalId: string | undefined;\n }> {\n const state = this._core.getState();\n return this._threadListBinding.initialize(state.id);\n }\n\n public generateTitle(): Promise<void> {\n const state = this._core.getState();\n return this._threadListBinding.generateTitle(state.id);\n }\n\n public unstable_on(event: ThreadListItemEventType, callback: () => void) {\n let prevIsMain = this._core.getState().isMain;\n return this.subscribe(() => {\n const newIsMain = this._core.getState().isMain;\n if (prevIsMain === newIsMain) return;\n prevIsMain = newIsMain;\n\n if (event === \"switched-to\" && !newIsMain) return;\n if (event === \"switched-away\" && newIsMain) return;\n callback();\n });\n }\n\n public subscribe(callback: () => void): Unsubscribe {\n return this._core.subscribe(callback);\n }\n}\n"],"mappings":";AAiDO,IAAM,4BAAN,MAAiE;AAAA,EAKtE,YACU,OACA,oBACR;AAFQ;AACA;AAAA,EACP;AAAA,EAPH,IAAW,OAAO;AAChB,WAAO,KAAK,MAAM;AAAA,EACpB;AAAA,EAOU,yBAAyB;AACjC,SAAK,WAAW,KAAK,SAAS,KAAK,IAAI;AACvC,SAAK,SAAS,KAAK,OAAO,KAAK,IAAI;AACnC,SAAK,UAAU,KAAK,QAAQ,KAAK,IAAI;AACrC,SAAK,YAAY,KAAK,UAAU,KAAK,IAAI;AACzC,SAAK,SAAS,KAAK,OAAO,KAAK,IAAI;AACnC,SAAK,aAAa,KAAK,WAAW,KAAK,IAAI;AAC3C,SAAK,gBAAgB,KAAK,cAAc,KAAK,IAAI;AACjD,SAAK,YAAY,KAAK,UAAU,KAAK,IAAI;AACzC,SAAK,cAAc,KAAK,YAAY,KAAK,IAAI;AAC7C,SAAK,WAAW,KAAK,SAAS,KAAK,IAAI;AAAA,EACzC;AAAA,EAEO,WAAgC;AACrC,WAAO,KAAK,MAAM,SAAS;AAAA,EAC7B;AAAA,EAEO,WAA0B;AAC/B,UAAM,QAAQ,KAAK,MAAM,SAAS;AAClC,WAAO,KAAK,mBAAmB,eAAe,MAAM,EAAE;AAAA,EACxD;AAAA,EAEO,OAAO,UAAiC;AAC7C,UAAM,QAAQ,KAAK,MAAM,SAAS;AAElC,WAAO,KAAK,mBAAmB,OAAO,MAAM,IAAI,QAAQ;AAAA,EAC1D;AAAA,EAEO,UAAyB;AAC9B,UAAM,QAAQ,KAAK,MAAM,SAAS;AAElC,WAAO,KAAK,mBAAmB,QAAQ,MAAM,EAAE;AAAA,EACjD;AAAA,EAEO,YAA2B;AAChC,UAAM,QAAQ,KAAK,MAAM,SAAS;AAElC,WAAO,KAAK,mBAAmB,UAAU,MAAM,EAAE;AAAA,EACnD;AAAA,EAEO,SAAwB;AAC7B,UAAM,QAAQ,KAAK,MAAM,SAAS;AAElC,WAAO,KAAK,mBAAmB,OAAO,MAAM,EAAE;AAAA,EAChD;AAAA,EAEO,aAGJ;AACD,UAAM,QAAQ,KAAK,MAAM,SAAS;AAClC,WAAO,KAAK,mBAAmB,WAAW,MAAM,EAAE;AAAA,EACpD;AAAA,EAEO,gBAA+B;AACpC,UAAM,QAAQ,KAAK,MAAM,SAAS;AAClC,WAAO,KAAK,mBAAmB,cAAc,MAAM,EAAE;AAAA,EACvD;AAAA,EAEO,YAAY,OAAgC,UAAsB;AACvE,QAAI,aAAa,KAAK,MAAM,SAAS,EAAE;AACvC,WAAO,KAAK,UAAU,MAAM;AAC1B,YAAM,YAAY,KAAK,MAAM,SAAS,EAAE;AACxC,UAAI,eAAe,UAAW;AAC9B,mBAAa;AAEb,UAAI,UAAU,iBAAiB,CAAC,UAAW;AAC3C,UAAI,UAAU,mBAAmB,UAAW;AAC5C,eAAS;AAAA,IACX,CAAC;AAAA,EACH;AAAA,EAEO,UAAU,UAAmC;AAClD,WAAO,KAAK,MAAM,UAAU,QAAQ;AAAA,EACtC;AACF;","names":[]}
@@ -1,14 +1,15 @@
1
- import { LazyMemoizeSubject } from "./subscribable/LazyMemoizeSubject";
1
+ // src/api/ThreadListRuntime.ts
2
+ import { LazyMemoizeSubject } from "./subscribable/LazyMemoizeSubject.js";
2
3
  import {
3
4
  ThreadListItemRuntimeImpl
4
- } from "./ThreadListItemRuntime";
5
- import { SKIP_UPDATE } from "./subscribable/SKIP_UPDATE";
6
- import { ShallowMemoizeSubject } from "./subscribable/ShallowMemoizeSubject";
5
+ } from "./ThreadListItemRuntime.js";
6
+ import { SKIP_UPDATE } from "./subscribable/SKIP_UPDATE.js";
7
+ import { ShallowMemoizeSubject } from "./subscribable/ShallowMemoizeSubject.js";
7
8
  import {
8
9
  ThreadRuntimeImpl
9
- } from "./ThreadRuntime";
10
- import { NestedSubscriptionSubject } from "./subscribable/NestedSubscriptionSubject";
11
- const getThreadListState = (threadList) => {
10
+ } from "./ThreadRuntime.js";
11
+ import { NestedSubscriptionSubject } from "./subscribable/NestedSubscriptionSubject.js";
12
+ var getThreadListState = (threadList) => {
12
13
  return {
13
14
  mainThreadId: threadList.mainThreadId,
14
15
  newThread: threadList.newThreadId,
@@ -16,7 +17,7 @@ const getThreadListState = (threadList) => {
16
17
  archivedThreads: threadList.archivedThreadIds
17
18
  };
18
19
  };
19
- const getThreadListItemState = (threadList, threadId) => {
20
+ var getThreadListItemState = (threadList, threadId) => {
20
21
  if (threadId === void 0) return SKIP_UPDATE;
21
22
  const threadData = threadList.getItemById(threadId);
22
23
  if (!threadData) return SKIP_UPDATE;
@@ -31,7 +32,7 @@ const getThreadListItemState = (threadList, threadId) => {
31
32
  isMain: threadData.threadId === threadList.mainThreadId
32
33
  };
33
34
  };
34
- class ThreadListRuntimeImpl {
35
+ var ThreadListRuntimeImpl = class {
35
36
  constructor(_core, _runtimeFactory = ThreadRuntimeImpl) {
36
37
  this._core = _core;
37
38
  this._runtimeFactory = _runtimeFactory;
@@ -157,7 +158,7 @@ class ThreadListRuntimeImpl {
157
158
  this._core
158
159
  );
159
160
  }
160
- }
161
+ };
161
162
  export {
162
163
  ThreadListRuntimeImpl
163
164
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/api/ThreadListRuntime.ts"],"sourcesContent":["import { LazyMemoizeSubject } from \"./subscribable/LazyMemoizeSubject\";\nimport { ThreadListRuntimeCore } from \"../runtimes/core/ThreadListRuntimeCore\";\nimport { Unsubscribe } from \"../types\";\nimport {\n ThreadListItemRuntime,\n ThreadListItemRuntimeImpl,\n ThreadListItemState,\n} from \"./ThreadListItemRuntime\";\nimport { SKIP_UPDATE } from \"./subscribable/SKIP_UPDATE\";\nimport { ShallowMemoizeSubject } from \"./subscribable/ShallowMemoizeSubject\";\nimport {\n ThreadListItemRuntimeBinding,\n ThreadRuntime,\n ThreadRuntimeCoreBinding,\n ThreadRuntimeImpl,\n} from \"./ThreadRuntime\";\nimport { NestedSubscriptionSubject } from \"./subscribable/NestedSubscriptionSubject\";\n\nexport type ThreadListState = {\n readonly mainThreadId: string;\n readonly newThread: string | undefined;\n readonly threads: readonly string[];\n readonly archivedThreads: readonly string[];\n};\n\nexport type ThreadListRuntime = {\n getState(): ThreadListState;\n\n subscribe(callback: () => void): Unsubscribe;\n\n readonly main: ThreadRuntime;\n getById(threadId: string): ThreadRuntime;\n\n readonly mainItem: ThreadListItemRuntime;\n getItemById(threadId: string): ThreadListItemRuntime;\n getItemByIndex(idx: number): ThreadListItemRuntime;\n getArchivedItemByIndex(idx: number): ThreadListItemRuntime;\n\n switchToThread(threadId: string): Promise<void>;\n switchToNewThread(): Promise<void>;\n};\n\nconst getThreadListState = (\n threadList: ThreadListRuntimeCore,\n): ThreadListState => {\n return {\n mainThreadId: threadList.mainThreadId,\n newThread: threadList.newThreadId,\n threads: threadList.threadIds,\n archivedThreads: threadList.archivedThreadIds,\n };\n};\n\nconst getThreadListItemState = (\n threadList: ThreadListRuntimeCore,\n threadId: string | undefined,\n): ThreadListItemState | SKIP_UPDATE => {\n if (threadId === undefined) return SKIP_UPDATE;\n\n const threadData = threadList.getItemById(threadId);\n if (!threadData) return SKIP_UPDATE;\n return {\n id: threadData.threadId,\n threadId: threadData.threadId, // TODO remove in 0.8.0\n remoteId: threadData.remoteId,\n externalId: threadData.externalId,\n title: threadData.title,\n status: threadData.status,\n isMain: threadData.threadId === threadList.mainThreadId,\n };\n};\n\nexport type ThreadListRuntimeCoreBinding = ThreadListRuntimeCore;\n\nexport class ThreadListRuntimeImpl implements ThreadListRuntime {\n private _getState;\n constructor(\n private _core: ThreadListRuntimeCoreBinding,\n private _runtimeFactory: new (\n binding: ThreadRuntimeCoreBinding,\n threadListItemBinding: ThreadListItemRuntimeBinding,\n ) => ThreadRuntime = ThreadRuntimeImpl,\n ) {\n const stateBinding = new LazyMemoizeSubject({\n path: {},\n getState: () => getThreadListState(_core),\n subscribe: (callback) => _core.subscribe(callback),\n });\n\n this._getState = stateBinding.getState.bind(stateBinding);\n\n this._mainThreadListItemRuntime = new ThreadListItemRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ref: `threadItems[main]`,\n threadSelector: { type: \"main\" },\n },\n getState: () => {\n return getThreadListItemState(this._core, this._core.mainThreadId);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n\n this.main = new _runtimeFactory(\n new NestedSubscriptionSubject({\n path: {\n ref: \"threads.main\",\n threadSelector: { type: \"main\" },\n },\n getState: () => _core.getMainThreadRuntimeCore(),\n subscribe: (callback) => _core.subscribe(callback),\n }),\n this._mainThreadListItemRuntime, // TODO capture \"main\" threadListItem from context around useLocalRuntime / useExternalStoreRuntime\n );\n }\n\n protected __internal_bindMethods() {\n this.switchToThread = this.switchToThread.bind(this);\n this.switchToNewThread = this.switchToNewThread.bind(this);\n this.getState = this.getState.bind(this);\n this.subscribe = this.subscribe.bind(this);\n this.getById = this.getById.bind(this);\n this.getItemById = this.getItemById.bind(this);\n this.getItemByIndex = this.getItemByIndex.bind(this);\n this.getArchivedItemByIndex = this.getArchivedItemByIndex.bind(this);\n }\n\n public switchToThread(threadId: string): Promise<void> {\n return this._core.switchToThread(threadId);\n }\n\n public switchToNewThread(): Promise<void> {\n return this._core.switchToNewThread();\n }\n\n public getState(): ThreadListState {\n return this._getState();\n }\n\n public subscribe(callback: () => void): Unsubscribe {\n return this._core.subscribe(callback);\n }\n\n private _mainThreadListItemRuntime;\n\n public readonly main: ThreadRuntime;\n\n public get mainItem() {\n return this._mainThreadListItemRuntime;\n }\n\n public getById(threadId: string) {\n return new this._runtimeFactory(\n new NestedSubscriptionSubject({\n path: {\n ref: \"threads[threadId=\" + JSON.stringify(threadId) + \"]\",\n threadSelector: { type: \"threadId\", threadId },\n },\n getState: () => this._core.getThreadRuntimeCore(threadId),\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this.mainItem, // TODO capture \"main\" threadListItem from context around useLocalRuntime / useExternalStoreRuntime\n );\n }\n\n public getItemByIndex(idx: number) {\n return new ThreadListItemRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ref: `threadItems[${idx}]`,\n threadSelector: { type: \"index\", index: idx },\n },\n getState: () => {\n return getThreadListItemState(this._core, this._core.threadIds[idx]);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n }\n\n public getArchivedItemByIndex(idx: number) {\n return new ThreadListItemRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ref: `archivedThreadItems[${idx}]`,\n threadSelector: { type: \"archiveIndex\", index: idx },\n },\n getState: () => {\n return getThreadListItemState(\n this._core,\n this._core.archivedThreadIds[idx],\n );\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n }\n\n public getItemById(threadId: string) {\n return new ThreadListItemRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ref: `threadItems[threadId=${threadId}]`,\n threadSelector: { type: \"threadId\", threadId },\n },\n getState: () => {\n return getThreadListItemState(this._core, threadId);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n }\n}\n"],"mappings":"AAAA,SAAS,0BAA0B;AAGnC;AAAA,EAEE;AAAA,OAEK;AACP,SAAS,mBAAmB;AAC5B,SAAS,6BAA6B;AACtC;AAAA,EAIE;AAAA,OACK;AACP,SAAS,iCAAiC;AA0B1C,MAAM,qBAAqB,CACzB,eACoB;AACpB,SAAO;AAAA,IACL,cAAc,WAAW;AAAA,IACzB,WAAW,WAAW;AAAA,IACtB,SAAS,WAAW;AAAA,IACpB,iBAAiB,WAAW;AAAA,EAC9B;AACF;AAEA,MAA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AAG;AAAA,UACvB,gBAAgB,EAAE,MAAM,SAAS,OAAO,IAAI;AAAA,QAC9C;AAAA,QACA,UAAU,MAAM;AACd,iBAAO,uBAAuB,KAAK,OAAO,KAAK,MAAM,UAAU,GAAG,CAAC;AAAA,QACrE;AAAA,QACA,WAAW,CAAC,aAAa,KAAK,MAAM,UAAU,QAAQ;AAAA,MACxD,CAAC;AAAA,MACD,KAAK;AAAA,IACP;AAAA,EACF;AAAA,EAEO,uBAAuB,KAAa;AACzC,WAAO,IAAI;AAAA,MACT,IAAI,sBAAsB;AAAA,QACxB,MAAM;AAAA,UACJ,KAAK,uBAAuB,GAAG;AAAA,UAC/B,gBAAgB,EAAE,MAAM,gBAAgB,OAAO,IAAI;AAAA,QACrD;AAAA,QACA,UAAU,MAAM;AACd,iBAAO;AAAA,YACL,KAAK;AAAA,YACL,KAAK,MAAM,kBAAkB,GAAG;AAAA,UAClC;AAAA,QACF;AAAA,QACA,WAAW,CAAC,aAAa,KAAK,MAAM,UAAU,QAAQ;AAAA,MACxD,CAAC;AAAA,MACD,KAAK;AAAA,IACP;AAAA,EACF;AAAA,EAEO,YAAY,UAAkB;AACnC,WAAO,IAAI;AAAA,MACT,IAAI,sBAAsB;AAAA,QACxB,MAAM;AAAA,UACJ,KAAK,wBAAwB,QAAQ;AAAA,UACrC,gBAAgB,EAAE,MAAM,YAAY,SAAS;AAAA,QAC/C;AAAA,QACA,UAAU,MAAM;AACd,iBAAO,uBAAuB,KAAK,OAAO,QAAQ;AAAA,QACpD;AAAA,QACA,WAAW,CAAC,aAAa,KAAK,MAAM,UAAU,QAAQ;AAAA,MACxD,CAAC;AAAA,MACD,KAAK;AAAA,IACP;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/api/ThreadListRuntime.ts"],"sourcesContent":["import { LazyMemoizeSubject } from \"./subscribable/LazyMemoizeSubject\";\nimport { ThreadListRuntimeCore } from \"../runtimes/core/ThreadListRuntimeCore\";\nimport { Unsubscribe } from \"../types\";\nimport {\n ThreadListItemRuntime,\n ThreadListItemRuntimeImpl,\n ThreadListItemState,\n} from \"./ThreadListItemRuntime\";\nimport { SKIP_UPDATE } from \"./subscribable/SKIP_UPDATE\";\nimport { ShallowMemoizeSubject } from \"./subscribable/ShallowMemoizeSubject\";\nimport {\n ThreadListItemRuntimeBinding,\n ThreadRuntime,\n ThreadRuntimeCoreBinding,\n ThreadRuntimeImpl,\n} from \"./ThreadRuntime\";\nimport { NestedSubscriptionSubject } from \"./subscribable/NestedSubscriptionSubject\";\n\nexport type ThreadListState = {\n readonly mainThreadId: string;\n readonly newThread: string | undefined;\n readonly threads: readonly string[];\n readonly archivedThreads: readonly string[];\n};\n\nexport type ThreadListRuntime = {\n getState(): ThreadListState;\n\n subscribe(callback: () => void): Unsubscribe;\n\n readonly main: ThreadRuntime;\n getById(threadId: string): ThreadRuntime;\n\n readonly mainItem: ThreadListItemRuntime;\n getItemById(threadId: string): ThreadListItemRuntime;\n getItemByIndex(idx: number): ThreadListItemRuntime;\n getArchivedItemByIndex(idx: number): ThreadListItemRuntime;\n\n switchToThread(threadId: string): Promise<void>;\n switchToNewThread(): Promise<void>;\n};\n\nconst getThreadListState = (\n threadList: ThreadListRuntimeCore,\n): ThreadListState => {\n return {\n mainThreadId: threadList.mainThreadId,\n newThread: threadList.newThreadId,\n threads: threadList.threadIds,\n archivedThreads: threadList.archivedThreadIds,\n };\n};\n\nconst getThreadListItemState = (\n threadList: ThreadListRuntimeCore,\n threadId: string | undefined,\n): ThreadListItemState | SKIP_UPDATE => {\n if (threadId === undefined) return SKIP_UPDATE;\n\n const threadData = threadList.getItemById(threadId);\n if (!threadData) return SKIP_UPDATE;\n return {\n id: threadData.threadId,\n threadId: threadData.threadId, // TODO remove in 0.8.0\n remoteId: threadData.remoteId,\n externalId: threadData.externalId,\n title: threadData.title,\n status: threadData.status,\n isMain: threadData.threadId === threadList.mainThreadId,\n };\n};\n\nexport type ThreadListRuntimeCoreBinding = ThreadListRuntimeCore;\n\nexport class ThreadListRuntimeImpl implements ThreadListRuntime {\n private _getState;\n constructor(\n private _core: ThreadListRuntimeCoreBinding,\n private _runtimeFactory: new (\n binding: ThreadRuntimeCoreBinding,\n threadListItemBinding: ThreadListItemRuntimeBinding,\n ) => ThreadRuntime = ThreadRuntimeImpl,\n ) {\n const stateBinding = new LazyMemoizeSubject({\n path: {},\n getState: () => getThreadListState(_core),\n subscribe: (callback) => _core.subscribe(callback),\n });\n\n this._getState = stateBinding.getState.bind(stateBinding);\n\n this._mainThreadListItemRuntime = new ThreadListItemRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ref: `threadItems[main]`,\n threadSelector: { type: \"main\" },\n },\n getState: () => {\n return getThreadListItemState(this._core, this._core.mainThreadId);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n\n this.main = new _runtimeFactory(\n new NestedSubscriptionSubject({\n path: {\n ref: \"threads.main\",\n threadSelector: { type: \"main\" },\n },\n getState: () => _core.getMainThreadRuntimeCore(),\n subscribe: (callback) => _core.subscribe(callback),\n }),\n this._mainThreadListItemRuntime, // TODO capture \"main\" threadListItem from context around useLocalRuntime / useExternalStoreRuntime\n );\n }\n\n protected __internal_bindMethods() {\n this.switchToThread = this.switchToThread.bind(this);\n this.switchToNewThread = this.switchToNewThread.bind(this);\n this.getState = this.getState.bind(this);\n this.subscribe = this.subscribe.bind(this);\n this.getById = this.getById.bind(this);\n this.getItemById = this.getItemById.bind(this);\n this.getItemByIndex = this.getItemByIndex.bind(this);\n this.getArchivedItemByIndex = this.getArchivedItemByIndex.bind(this);\n }\n\n public switchToThread(threadId: string): Promise<void> {\n return this._core.switchToThread(threadId);\n }\n\n public switchToNewThread(): Promise<void> {\n return this._core.switchToNewThread();\n }\n\n public getState(): ThreadListState {\n return this._getState();\n }\n\n public subscribe(callback: () => void): Unsubscribe {\n return this._core.subscribe(callback);\n }\n\n private _mainThreadListItemRuntime;\n\n public readonly main: ThreadRuntime;\n\n public get mainItem() {\n return this._mainThreadListItemRuntime;\n }\n\n public getById(threadId: string) {\n return new this._runtimeFactory(\n new NestedSubscriptionSubject({\n path: {\n ref: \"threads[threadId=\" + JSON.stringify(threadId) + \"]\",\n threadSelector: { type: \"threadId\", threadId },\n },\n getState: () => this._core.getThreadRuntimeCore(threadId),\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this.mainItem, // TODO capture \"main\" threadListItem from context around useLocalRuntime / useExternalStoreRuntime\n );\n }\n\n public getItemByIndex(idx: number) {\n return new ThreadListItemRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ref: `threadItems[${idx}]`,\n threadSelector: { type: \"index\", index: idx },\n },\n getState: () => {\n return getThreadListItemState(this._core, this._core.threadIds[idx]);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n }\n\n public getArchivedItemByIndex(idx: number) {\n return new ThreadListItemRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ref: `archivedThreadItems[${idx}]`,\n threadSelector: { type: \"archiveIndex\", index: idx },\n },\n getState: () => {\n return getThreadListItemState(\n this._core,\n this._core.archivedThreadIds[idx],\n );\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n }\n\n public getItemById(threadId: string) {\n return new ThreadListItemRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ref: `threadItems[threadId=${threadId}]`,\n threadSelector: { type: \"threadId\", threadId },\n },\n getState: () => {\n return getThreadListItemState(this._core, threadId);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n }\n}\n"],"mappings":";AAAA,SAAS,0BAA0B;AAGnC;AAAA,EAEE;AAAA,OAEK;AACP,SAAS,mBAAmB;AAC5B,SAAS,6BAA6B;AACtC;AAAA,EAIE;AAAA,OACK;AACP,SAAS,iCAAiC;AA0B1C,IAAM,qBAAqB,CACzB,eACoB;AACpB,SAAO;AAAA,IACL,cAAc,WAAW;AAAA,IACzB,WAAW,WAAW;AAAA,IACtB,SAAS,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