@assistant-ui/core 0.2.21 → 0.2.23

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 (345) hide show
  1. package/dist/adapters/attachment.d.ts.map +1 -1
  2. package/dist/adapters/speech.d.ts.map +1 -1
  3. package/dist/adapters/speech.js +9 -2
  4. package/dist/adapters/speech.js.map +1 -1
  5. package/dist/adapters/thread-history.d.ts +8 -0
  6. package/dist/adapters/thread-history.d.ts.map +1 -1
  7. package/dist/adapters/voice.d.ts.map +1 -1
  8. package/dist/adapters/voice.js +13 -5
  9. package/dist/adapters/voice.js.map +1 -1
  10. package/dist/internal.d.ts +5 -2
  11. package/dist/internal.js +5 -2
  12. package/dist/model-context/frame/host.d.ts +1 -0
  13. package/dist/model-context/frame/host.d.ts.map +1 -1
  14. package/dist/model-context/frame/host.js +41 -21
  15. package/dist/model-context/frame/host.js.map +1 -1
  16. package/dist/model-context/frame/provider.d.ts.map +1 -1
  17. package/dist/model-context/frame/provider.js +1 -0
  18. package/dist/model-context/frame/provider.js.map +1 -1
  19. package/dist/model-context/interactable-composer-metadata.js.map +1 -1
  20. package/dist/model-context/types.d.ts.map +1 -1
  21. package/dist/model-context/types.js +13 -4
  22. package/dist/model-context/types.js.map +1 -1
  23. package/dist/react/AssistantProvider.js.map +1 -1
  24. package/dist/react/adapters/LocalStorageThreadListAdapter.d.ts.map +1 -1
  25. package/dist/react/adapters/LocalStorageThreadListAdapter.js +78 -50
  26. package/dist/react/adapters/LocalStorageThreadListAdapter.js.map +1 -1
  27. package/dist/react/client/Interactables.js.map +1 -1
  28. package/dist/react/client/Tools.d.ts.map +1 -1
  29. package/dist/react/client/interactable-model-context.d.ts.map +1 -1
  30. package/dist/react/client/interactable-model-context.js +1 -0
  31. package/dist/react/client/interactable-model-context.js.map +1 -1
  32. package/dist/react/interactables-legacy/useInteractableState.js +1 -0
  33. package/dist/react/interactables-legacy/useInteractableState.js.map +1 -1
  34. package/dist/react/model-context/useInteractable.js.map +1 -1
  35. package/dist/react/model-context/useInteractableState.js +1 -0
  36. package/dist/react/model-context/useInteractableState.js.map +1 -1
  37. package/dist/react/model-context/useInteractableVersions.js +1 -0
  38. package/dist/react/model-context/useInteractableVersions.js.map +1 -1
  39. package/dist/react/model-context/useToolArgsStatus.js +1 -0
  40. package/dist/react/model-context/useToolArgsStatus.js.map +1 -1
  41. package/dist/react/primitive-hooks/useActionBarCopy.js +14 -13
  42. package/dist/react/primitive-hooks/useActionBarCopy.js.map +1 -1
  43. package/dist/react/primitive-hooks/useActionBarEdit.js +1 -0
  44. package/dist/react/primitive-hooks/useActionBarEdit.js.map +1 -1
  45. package/dist/react/primitive-hooks/useActionBarFeedback.js +1 -0
  46. package/dist/react/primitive-hooks/useActionBarFeedback.js.map +1 -1
  47. package/dist/react/primitive-hooks/useActionBarReload.js +1 -0
  48. package/dist/react/primitive-hooks/useActionBarReload.js.map +1 -1
  49. package/dist/react/primitive-hooks/useActionBarSpeak.js +1 -0
  50. package/dist/react/primitive-hooks/useActionBarSpeak.js.map +1 -1
  51. package/dist/react/primitive-hooks/useActionBarStopSpeaking.js +1 -0
  52. package/dist/react/primitive-hooks/useActionBarStopSpeaking.js.map +1 -1
  53. package/dist/react/primitive-hooks/useBranchPickerNext.js +1 -0
  54. package/dist/react/primitive-hooks/useBranchPickerNext.js.map +1 -1
  55. package/dist/react/primitive-hooks/useBranchPickerPrevious.js +1 -0
  56. package/dist/react/primitive-hooks/useBranchPickerPrevious.js.map +1 -1
  57. package/dist/react/primitive-hooks/useComposerAddAttachment.d.ts.map +1 -1
  58. package/dist/react/primitive-hooks/useComposerAddAttachment.js +1 -0
  59. package/dist/react/primitive-hooks/useComposerAddAttachment.js.map +1 -1
  60. package/dist/react/primitive-hooks/useComposerCancel.js +1 -0
  61. package/dist/react/primitive-hooks/useComposerCancel.js.map +1 -1
  62. package/dist/react/primitive-hooks/useComposerDictate.js +1 -0
  63. package/dist/react/primitive-hooks/useComposerDictate.js.map +1 -1
  64. package/dist/react/primitive-hooks/useComposerSend.d.ts.map +1 -1
  65. package/dist/react/primitive-hooks/useComposerSend.js +1 -0
  66. package/dist/react/primitive-hooks/useComposerSend.js.map +1 -1
  67. package/dist/react/primitive-hooks/useEditComposerCancel.js +1 -0
  68. package/dist/react/primitive-hooks/useEditComposerCancel.js.map +1 -1
  69. package/dist/react/primitive-hooks/useEditComposerSend.js +1 -0
  70. package/dist/react/primitive-hooks/useEditComposerSend.js.map +1 -1
  71. package/dist/react/primitive-hooks/useMessageBranching.js +1 -0
  72. package/dist/react/primitive-hooks/useMessageBranching.js.map +1 -1
  73. package/dist/react/primitive-hooks/useMessageReload.js +1 -0
  74. package/dist/react/primitive-hooks/useMessageReload.js.map +1 -1
  75. package/dist/react/primitive-hooks/useSuggestionTrigger.js +1 -0
  76. package/dist/react/primitive-hooks/useSuggestionTrigger.js.map +1 -1
  77. package/dist/react/primitive-hooks/useThreadListItemArchive.js +1 -0
  78. package/dist/react/primitive-hooks/useThreadListItemArchive.js.map +1 -1
  79. package/dist/react/primitive-hooks/useThreadListItemDelete.js +1 -0
  80. package/dist/react/primitive-hooks/useThreadListItemDelete.js.map +1 -1
  81. package/dist/react/primitive-hooks/useThreadListItemTrigger.js +1 -0
  82. package/dist/react/primitive-hooks/useThreadListItemTrigger.js.map +1 -1
  83. package/dist/react/primitive-hooks/useThreadListItemUnarchive.js +1 -0
  84. package/dist/react/primitive-hooks/useThreadListItemUnarchive.js.map +1 -1
  85. package/dist/react/primitive-hooks/useThreadListLoadMore.js +1 -0
  86. package/dist/react/primitive-hooks/useThreadListLoadMore.js.map +1 -1
  87. package/dist/react/primitive-hooks/useThreadListNew.js +1 -0
  88. package/dist/react/primitive-hooks/useThreadListNew.js.map +1 -1
  89. package/dist/react/primitives/chainOfThought/ChainOfThoughtParts.d.ts.map +1 -1
  90. package/dist/react/primitives/chainOfThought/ChainOfThoughtParts.js +1 -1
  91. package/dist/react/primitives/chainOfThought/ChainOfThoughtParts.js.map +1 -1
  92. package/dist/react/primitives/composer/ComposerAttachments.js.map +1 -1
  93. package/dist/react/primitives/composer/ComposerQueue.d.ts.map +1 -1
  94. package/dist/react/primitives/composer/ComposerQueue.js.map +1 -1
  95. package/dist/react/primitives/generativeUI/GenerativeUI.d.ts.map +1 -1
  96. package/dist/react/primitives/message/MessageAttachments.js.map +1 -1
  97. package/dist/react/primitives/message/MessageGroupedParts.js.map +1 -1
  98. package/dist/react/primitives/message/MessageParts.d.ts +2 -1
  99. package/dist/react/primitives/message/MessageParts.d.ts.map +1 -1
  100. package/dist/react/primitives/message/MessageParts.js +46 -36
  101. package/dist/react/primitives/message/MessageParts.js.map +1 -1
  102. package/dist/react/primitives/part/PartMessages.js.map +1 -1
  103. package/dist/react/primitives/thread/ThreadMessages.js.map +1 -1
  104. package/dist/react/primitives/thread/ThreadSuggestions.js.map +1 -1
  105. package/dist/react/primitives/threadList/ThreadListItems.js.map +1 -1
  106. package/dist/react/providers/ChainOfThoughtPartByIndexProvider.d.ts.map +1 -1
  107. package/dist/react/providers/ChainOfThoughtPartByIndexProvider.js +18 -30
  108. package/dist/react/providers/ChainOfThoughtPartByIndexProvider.js.map +1 -1
  109. package/dist/react/providers/PartByIndexProvider.d.ts.map +1 -1
  110. package/dist/react/providers/PartByIndexProvider.js +18 -30
  111. package/dist/react/providers/PartByIndexProvider.js.map +1 -1
  112. package/dist/react/providers/TextMessagePartProvider.js +1 -0
  113. package/dist/react/providers/TextMessagePartProvider.js.map +1 -1
  114. package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts.map +1 -1
  115. package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js +1 -0
  116. package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js.map +1 -1
  117. package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts +9 -2
  118. package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -1
  119. package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js +55 -12
  120. package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js.map +1 -1
  121. package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.d.ts +31 -1
  122. package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.d.ts.map +1 -1
  123. package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js +12 -2
  124. package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js.map +1 -1
  125. package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.d.ts +1 -1
  126. package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.d.ts.map +1 -1
  127. package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.js +3 -2
  128. package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.js.map +1 -1
  129. package/dist/react/runtimes/cloud/auiV0.d.ts +12 -1
  130. package/dist/react/runtimes/cloud/auiV0.d.ts.map +1 -1
  131. package/dist/react/runtimes/cloud/auiV0.js +2 -1
  132. package/dist/react/runtimes/cloud/auiV0.js.map +1 -1
  133. package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js +75 -73
  134. package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js.map +1 -1
  135. package/dist/react/runtimes/createMessageConverter.d.ts.map +1 -1
  136. package/dist/react/runtimes/external-message-converter.js +2 -2
  137. package/dist/react/runtimes/external-message-converter.js.map +1 -1
  138. package/dist/react/runtimes/useExternalStoreSharedOptions.js +1 -0
  139. package/dist/react/runtimes/useExternalStoreSharedOptions.js.map +1 -1
  140. package/dist/react/runtimes/useLocalRuntime.d.ts.map +1 -1
  141. package/dist/react/runtimes/useLocalRuntime.js +9 -1
  142. package/dist/react/runtimes/useLocalRuntime.js.map +1 -1
  143. package/dist/runtime/api/assistant-runtime.d.ts +1 -1
  144. package/dist/runtime/api/assistant-runtime.d.ts.map +1 -1
  145. package/dist/runtime/api/assistant-runtime.js +1 -1
  146. package/dist/runtime/api/assistant-runtime.js.map +1 -1
  147. package/dist/runtime/api/attachment-runtime.d.ts +1 -1
  148. package/dist/runtime/api/attachment-runtime.d.ts.map +1 -1
  149. package/dist/runtime/api/attachment-runtime.js +1 -1
  150. package/dist/runtime/api/attachment-runtime.js.map +1 -1
  151. package/dist/runtime/api/composer-runtime.d.ts +2 -2
  152. package/dist/runtime/api/composer-runtime.d.ts.map +1 -1
  153. package/dist/runtime/api/composer-runtime.js +2 -2
  154. package/dist/runtime/api/composer-runtime.js.map +1 -1
  155. package/dist/runtime/api/message-part-runtime.d.ts +4 -4
  156. package/dist/runtime/api/message-part-runtime.d.ts.map +1 -1
  157. package/dist/runtime/api/message-part-runtime.js +3 -3
  158. package/dist/runtime/api/message-part-runtime.js.map +1 -1
  159. package/dist/runtime/api/message-runtime.d.ts +1 -1
  160. package/dist/runtime/api/message-runtime.d.ts.map +1 -1
  161. package/dist/runtime/api/message-runtime.js +6 -6
  162. package/dist/runtime/api/message-runtime.js.map +1 -1
  163. package/dist/runtime/api/thread-list-item-runtime.d.ts +1 -1
  164. package/dist/runtime/api/thread-list-item-runtime.d.ts.map +1 -1
  165. package/dist/runtime/api/thread-list-item-runtime.js +4 -3
  166. package/dist/runtime/api/thread-list-item-runtime.js.map +1 -1
  167. package/dist/runtime/api/thread-list-runtime.d.ts +1 -1
  168. package/dist/runtime/api/thread-list-runtime.d.ts.map +1 -1
  169. package/dist/runtime/api/thread-list-runtime.js +1 -1
  170. package/dist/runtime/api/thread-list-runtime.js.map +1 -1
  171. package/dist/runtime/api/thread-runtime.d.ts.map +1 -1
  172. package/dist/runtime/base/base-composer-runtime-core.d.ts +4 -1
  173. package/dist/runtime/base/base-composer-runtime-core.d.ts.map +1 -1
  174. package/dist/runtime/base/base-composer-runtime-core.js +41 -14
  175. package/dist/runtime/base/base-composer-runtime-core.js.map +1 -1
  176. package/dist/runtime/base/base-thread-runtime-core.d.ts +1 -1
  177. package/dist/runtime/base/base-thread-runtime-core.d.ts.map +1 -1
  178. package/dist/runtime/base/base-thread-runtime-core.js +3 -2
  179. package/dist/runtime/base/base-thread-runtime-core.js.map +1 -1
  180. package/dist/runtime/base/default-edit-composer-runtime-core.d.ts +2 -2
  181. package/dist/runtime/base/default-edit-composer-runtime-core.d.ts.map +1 -1
  182. package/dist/runtime/base/default-edit-composer-runtime-core.js +6 -4
  183. package/dist/runtime/base/default-edit-composer-runtime-core.js.map +1 -1
  184. package/dist/runtime/base/default-thread-composer-runtime-core.d.ts +1 -1
  185. package/dist/runtime/base/default-thread-composer-runtime-core.d.ts.map +1 -1
  186. package/dist/runtime/base/default-thread-composer-runtime-core.js +3 -3
  187. package/dist/runtime/base/default-thread-composer-runtime-core.js.map +1 -1
  188. package/dist/runtime/utils/message-repository.d.ts.map +1 -1
  189. package/dist/runtime/utils/message-repository.js +4 -2
  190. package/dist/runtime/utils/message-repository.js.map +1 -1
  191. package/dist/runtime/utils/thread-message-like.js +4 -1
  192. package/dist/runtime/utils/thread-message-like.js.map +1 -1
  193. package/dist/runtimes/external-store/external-store-runtime-core.d.ts.map +1 -1
  194. package/dist/runtimes/external-store/external-store-thread-list-runtime-core.d.ts +1 -1
  195. package/dist/runtimes/external-store/external-store-thread-list-runtime-core.d.ts.map +1 -1
  196. package/dist/runtimes/external-store/external-store-thread-list-runtime-core.js +1 -1
  197. package/dist/runtimes/external-store/external-store-thread-list-runtime-core.js.map +1 -1
  198. package/dist/runtimes/external-store/external-store-thread-runtime-core.d.ts.map +1 -1
  199. package/dist/runtimes/external-store/external-store-thread-runtime-core.js +12 -0
  200. package/dist/runtimes/external-store/external-store-thread-runtime-core.js.map +1 -1
  201. package/dist/runtimes/internal.d.ts +2 -1
  202. package/dist/runtimes/internal.js +2 -1
  203. package/dist/runtimes/local/local-runtime-core.d.ts.map +1 -1
  204. package/dist/runtimes/local/local-thread-list-runtime-core.d.ts.map +1 -1
  205. package/dist/runtimes/local/local-thread-runtime-core.d.ts +3 -0
  206. package/dist/runtimes/local/local-thread-runtime-core.d.ts.map +1 -1
  207. package/dist/runtimes/local/local-thread-runtime-core.js +49 -15
  208. package/dist/runtimes/local/local-thread-runtime-core.js.map +1 -1
  209. package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.d.ts.map +1 -1
  210. package/dist/runtimes/remote-thread-list/optimistic-state.d.ts +4 -4
  211. package/dist/runtimes/remote-thread-list/optimistic-state.d.ts.map +1 -1
  212. package/dist/runtimes/remote-thread-list/optimistic-state.js +22 -9
  213. package/dist/runtimes/remote-thread-list/optimistic-state.js.map +1 -1
  214. package/dist/runtimes/remote-thread-list/types.d.ts +1 -1
  215. package/dist/runtimes/tool-invocations/ToolInvocationTracker.d.ts +32 -27
  216. package/dist/runtimes/tool-invocations/ToolInvocationTracker.d.ts.map +1 -1
  217. package/dist/runtimes/tool-invocations/ToolInvocationTracker.js +3 -2
  218. package/dist/runtimes/tool-invocations/ToolInvocationTracker.js.map +1 -1
  219. package/dist/store/clients/chain-of-thought-client.d.ts.map +1 -1
  220. package/dist/store/clients/no-op-composer-client.d.ts.map +1 -1
  221. package/dist/store/clients/no-op-composer-client.js +1 -0
  222. package/dist/store/clients/no-op-composer-client.js.map +1 -1
  223. package/dist/store/runtime-clients/attachment-runtime-client.d.ts.map +1 -1
  224. package/dist/store/runtime-clients/composer-runtime-client.d.ts.map +1 -1
  225. package/dist/store/runtime-clients/message-part-runtime-client.d.ts.map +1 -1
  226. package/dist/store/runtime-clients/message-runtime-client.d.ts.map +1 -1
  227. package/dist/store/runtime-clients/thread-list-item-runtime-client.d.ts.map +1 -1
  228. package/dist/store/runtime-clients/thread-list-runtime-client.d.ts.map +1 -1
  229. package/dist/store/runtime-clients/thread-list-runtime-client.js +1 -0
  230. package/dist/store/runtime-clients/thread-list-runtime-client.js.map +1 -1
  231. package/dist/store/runtime-clients/thread-runtime-client.d.ts.map +1 -1
  232. package/dist/store/runtime-clients/thread-runtime-client.js +17 -15
  233. package/dist/store/runtime-clients/thread-runtime-client.js.map +1 -1
  234. package/dist/store/scopes/thread.d.ts +1 -0
  235. package/dist/store/scopes/thread.d.ts.map +1 -1
  236. package/dist/subscribable/subscribable.d.ts +4 -4
  237. package/dist/subscribable/subscribable.d.ts.map +1 -1
  238. package/dist/subscribable/subscribable.js +14 -6
  239. package/dist/subscribable/subscribable.js.map +1 -1
  240. package/dist/tests/remote-thread-list-test-helpers.d.ts +2 -1
  241. package/dist/tests/remote-thread-list-test-helpers.d.ts.map +1 -1
  242. package/dist/tests/remote-thread-list-test-helpers.js +5 -2
  243. package/dist/tests/remote-thread-list-test-helpers.js.map +1 -1
  244. package/dist/types/attachment.d.ts +2 -1
  245. package/dist/types/attachment.d.ts.map +1 -1
  246. package/dist/types/attachment.js +6 -0
  247. package/dist/types/attachment.js.map +1 -0
  248. package/dist/types/message.d.ts +1 -0
  249. package/dist/types/message.d.ts.map +1 -1
  250. package/dist/types/message.js.map +1 -1
  251. package/dist/utils/data-url.d.ts +9 -0
  252. package/dist/utils/data-url.d.ts.map +1 -0
  253. package/dist/utils/data-url.js +14 -0
  254. package/dist/utils/data-url.js.map +1 -0
  255. package/dist/utils/notify-event-listeners.d.ts +6 -0
  256. package/dist/utils/notify-event-listeners.d.ts.map +1 -0
  257. package/dist/utils/notify-event-listeners.js +16 -0
  258. package/dist/utils/notify-event-listeners.js.map +1 -0
  259. package/package.json +10 -9
  260. package/src/adapters/speech.test.ts +88 -0
  261. package/src/adapters/speech.ts +17 -2
  262. package/src/adapters/thread-history.ts +8 -0
  263. package/src/adapters/voice.test.ts +130 -0
  264. package/src/adapters/voice.ts +26 -6
  265. package/src/internal.ts +6 -1
  266. package/src/model-context/frame/host.test.ts +147 -0
  267. package/src/model-context/frame/host.ts +56 -19
  268. package/src/model-context/frame/provider.test.ts +83 -0
  269. package/src/model-context/frame/provider.ts +1 -0
  270. package/src/model-context/types.ts +16 -6
  271. package/src/react/adapters/LocalStorageThreadListAdapter.test.ts +82 -0
  272. package/src/react/adapters/LocalStorageThreadListAdapter.tsx +108 -58
  273. package/src/react/primitive-hooks/useActionBarCopy.test.ts +79 -0
  274. package/src/react/primitive-hooks/useActionBarCopy.ts +4 -3
  275. package/src/react/primitives/chainOfThought/ChainOfThoughtParts.tsx +1 -3
  276. package/src/react/primitives/message/MessageParts.tsx +48 -35
  277. package/src/react/providers/ChainOfThoughtPartByIndexProvider.tsx +19 -2
  278. package/src/react/providers/PartByIndexProvider.tsx +16 -2
  279. package/src/react/runtimes/RemoteThreadListHookInstanceManager.test.tsx +18 -0
  280. package/src/react/runtimes/RemoteThreadListHookInstanceManager.tsx +1 -0
  281. package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.tsx +68 -13
  282. package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.test.ts +34 -0
  283. package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.test.tsx +69 -0
  284. package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.ts +27 -6
  285. package/src/react/runtimes/cloud/CloudFileAttachmentAdapter.test.ts +16 -0
  286. package/src/react/runtimes/cloud/CloudFileAttachmentAdapter.ts +7 -2
  287. package/src/react/runtimes/cloud/auiV0.ts +14 -0
  288. package/src/react/runtimes/cloud/useCloudThreadListAdapter.tsx +90 -88
  289. package/src/react/runtimes/external-message-converter.test.ts +346 -0
  290. package/src/react/runtimes/external-message-converter.test.tsx +21 -0
  291. package/src/react/runtimes/external-message-converter.ts +2 -2
  292. package/src/react/runtimes/useLocalRuntime.test.tsx +99 -0
  293. package/src/react/runtimes/useLocalRuntime.ts +13 -1
  294. package/src/runtime/api/assistant-runtime.ts +4 -1
  295. package/src/runtime/api/attachment-runtime.ts +8 -2
  296. package/src/runtime/api/composer-runtime.ts +9 -5
  297. package/src/runtime/api/message-part-runtime.ts +10 -3
  298. package/src/runtime/api/message-runtime.test.ts +81 -0
  299. package/src/runtime/api/message-runtime.ts +11 -8
  300. package/src/runtime/api/thread-list-item-runtime.ts +13 -3
  301. package/src/runtime/api/thread-list-runtime.ts +10 -2
  302. package/src/runtime/base/base-composer-runtime-core.ts +77 -31
  303. package/src/runtime/base/base-thread-runtime-core.ts +7 -2
  304. package/src/runtime/base/default-edit-composer-runtime-core.ts +18 -4
  305. package/src/runtime/base/default-thread-composer-runtime-core.ts +13 -3
  306. package/src/runtime/utils/message-repository.ts +19 -13
  307. package/src/runtime/utils/thread-message-like.ts +1 -0
  308. package/src/runtimes/external-store/external-store-thread-list-runtime-core.ts +4 -1
  309. package/src/runtimes/external-store/external-store-thread-runtime-core.ts +15 -0
  310. package/src/runtimes/internal.ts +3 -0
  311. package/src/runtimes/local/local-thread-runtime-core.test.ts +746 -1
  312. package/src/runtimes/local/local-thread-runtime-core.ts +89 -23
  313. package/src/runtimes/local/should-continue.test.ts +122 -0
  314. package/src/runtimes/remote-thread-list/optimistic-state.test.ts +63 -0
  315. package/src/runtimes/remote-thread-list/optimistic-state.ts +49 -17
  316. package/src/runtimes/remote-thread-list/types.ts +1 -1
  317. package/src/runtimes/tool-invocations/EDGE_CASES.md +13 -19
  318. package/src/runtimes/tool-invocations/ToolInvocationTracker.test.ts +128 -8
  319. package/src/runtimes/tool-invocations/ToolInvocationTracker.ts +42 -34
  320. package/src/store/clients/model-context-client.test.ts +21 -1
  321. package/src/store/runtime-clients/thread-runtime-client.ts +2 -1
  322. package/src/store/scopes/thread.ts +1 -0
  323. package/src/subscribable/subscribable.test.ts +58 -0
  324. package/src/subscribable/subscribable.ts +29 -11
  325. package/src/tests/MessageRepository.test.ts +12 -0
  326. package/src/tests/OptimisticState-list-race.test.ts +33 -0
  327. package/src/tests/RemoteThreadListThreadListRuntimeCore-switchToThread-order.test.ts +223 -0
  328. package/src/tests/RemoteThreadListThreadListRuntimeCore-switchToThread-position.test.ts +121 -0
  329. package/src/tests/auiV0Encode.test.ts +74 -0
  330. package/src/tests/base-composer-runtime-core-addAttachment.test.ts +44 -0
  331. package/src/tests/base-composer-runtime-core-send.test.ts +433 -5
  332. package/src/tests/base-composer-runtime-core.test.ts +422 -0
  333. package/src/tests/default-edit-composer-runtime-core.test.ts +43 -5
  334. package/src/tests/event-subscription-listener-errors.test.ts +205 -0
  335. package/src/tests/external-store-thread-list-runtime-core.test.ts +6 -6
  336. package/src/tests/external-store-thread-runtime-core-adapter.test.ts +575 -0
  337. package/src/tests/external-store-thread-runtime-core.test.ts +55 -1
  338. package/src/tests/remote-thread-list-test-helpers.ts +14 -7
  339. package/src/tests/thread-message-like.test.ts +57 -0
  340. package/src/types/attachment.ts +5 -0
  341. package/src/types/message.ts +1 -0
  342. package/src/utils/data-url.test.ts +50 -0
  343. package/src/utils/data-url.ts +9 -0
  344. package/src/utils/notify-event-listeners.ts +30 -0
  345. package/src/tests/OptimisticState-delete-crash.test.ts +0 -208
@@ -1,9 +1,9 @@
1
1
  //#region src/runtime/api/attachment-runtime.ts
2
2
  var AttachmentRuntimeImpl = class {
3
- _core;
4
3
  get path() {
5
4
  return this._core.path;
6
5
  }
6
+ _core;
7
7
  constructor(_core) {
8
8
  this._core = _core;
9
9
  this.__internal_bindMethods();
@@ -1 +1 @@
1
- {"version":3,"file":"attachment-runtime.js","names":["Attachment","CompleteAttachment","Unsubscribe","SubscribableWithState","ComposerRuntimeCoreBinding","AttachmentRuntimePath","MessageAttachmentState","source","ThreadComposerAttachmentState","EditComposerAttachmentState","AttachmentState","AttachmentSnapshotBinding","AttachmentRuntimeSource","Source","attachmentSource","AttachmentRuntime","path","TSource","getState","remove","Promise","subscribe","callback","AttachmentRuntimeImpl","_core","constructor","__internal_bindMethods","bind","ComposerAttachmentRuntime","core","_composerApi","Error","removeAttachment","id","ThreadComposerAttachmentRuntimeImpl","EditComposerAttachmentRuntimeImpl","MessageAttachmentRuntimeImpl"],"sources":["../../../src/runtime/api/attachment-runtime.ts"],"sourcesContent":["import type { Attachment, CompleteAttachment } from \"../../types/attachment\";\nimport type { Unsubscribe } from \"../../types/unsubscribe\";\nimport type { SubscribableWithState } from \"../../subscribable/subscribable\";\n\nimport type { ComposerRuntimeCoreBinding } from \"./bindings\";\nimport type { AttachmentRuntimePath } from \"./paths\";\n\ntype MessageAttachmentState = CompleteAttachment & {\n readonly source: \"message\";\n};\n\ntype ThreadComposerAttachmentState = Attachment & {\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 public get path() {\n return this._core.path;\n }\n\n public abstract get source(): Source;\n\n constructor(private _core: AttachmentSnapshotBinding<Source>) {\n this.__internal_bindMethods();\n }\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 public remove(): never {\n throw new Error(\"Message attachments cannot be removed\");\n }\n}\n"],"mappings":";AA0CA,IAAsBuB,wBAAtB,MAE+B;CAOTC;CANpB,IAAWR,OAAO;EAChB,OAAO,KAAKQ,MAAMR;CACpB;CAIAS,YAAY,OAAkD;EAA1CD,KAAAA,QAAAA;EAClB,KAAKE,uBAAuB;CAC9B;CAEA,yBAAmC;EACjC,KAAKR,WAAW,KAAKA,SAASS,KAAK,IAAI;EACvC,KAAKR,SAAS,KAAKA,OAAOQ,KAAK,IAAI;EACnC,KAAKN,YAAY,KAAKA,UAAUM,KAAK,IAAI;CAC3C;CAEA,WAAwD;EACtD,OAAO,KAAKH,MAAMN,SAAS;CAC7B;CAIA,UAAiBI,UAAsB;EACrC,OAAO,KAAKE,MAAMH,UAAUC,QAAQ;CACtC;AACF;AAEA,IAAeM,4BAAf,cAEUL,sBAA8B;CAG5BO;CAFVL,YACEI,MACA,cACA;EACA,MAAMA,IAAI;EAFFC,KAAAA,eAAAA;CAGV;CAEA,SAAgB;EACd,MAAMD,OAAO,KAAKC,aAAaZ,SAAS;EACxC,IAAI,CAACW,MAAM,MAAM,IAAIE,MAAM,2BAA2B;EACtD,OAAOF,KAAKG,iBAAiB,KAAKd,SAAS,CAAC,CAACe,EAAE;CACjD;AACF;AAEA,IAAaC,sCAAb,cAAyDN,0BAA6C;CACpG,IAAWrB,SAA4B;EACrC,OAAO;CACT;AACF;AAEA,IAAa4B,oCAAb,cAAuDP,0BAA2C;CAChG,IAAWrB,SAA0B;EACnC,OAAO;CACT;AACF;AAEA,IAAa6B,+BAAb,cAAkDb,sBAAiC;CACjF,IAAWhB,SAAoB;EAC7B,OAAO;CACT;CAEA,SAAuB;EACrB,MAAM,IAAIwB,MAAM,uCAAuC;CACzD;AACF"}
1
+ {"version":3,"file":"attachment-runtime.js","names":["Attachment","CompleteAttachment","Unsubscribe","SubscribableWithState","ComposerRuntimeCoreBinding","AttachmentRuntimePath","MessageAttachmentState","source","ThreadComposerAttachmentState","EditComposerAttachmentState","AttachmentState","AttachmentSnapshotBinding","AttachmentRuntimeSource","Source","attachmentSource","AttachmentRuntime","path","TSource","getState","remove","Promise","subscribe","callback","AttachmentRuntimeImpl","_core","constructor","__internal_bindMethods","bind","ComposerAttachmentRuntime","_composerApi","core","Error","removeAttachment","id","ThreadComposerAttachmentRuntimeImpl","EditComposerAttachmentRuntimeImpl","MessageAttachmentRuntimeImpl"],"sources":["../../../src/runtime/api/attachment-runtime.ts"],"sourcesContent":["import type { Attachment, CompleteAttachment } from \"../../types/attachment\";\nimport type { Unsubscribe } from \"../../types/unsubscribe\";\nimport type { SubscribableWithState } from \"../../subscribable/subscribable\";\n\nimport type { ComposerRuntimeCoreBinding } from \"./bindings\";\nimport type { AttachmentRuntimePath } from \"./paths\";\n\ntype MessageAttachmentState = CompleteAttachment & {\n readonly source: \"message\";\n};\n\ntype ThreadComposerAttachmentState = Attachment & {\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 public get path() {\n return this._core.path;\n }\n\n public abstract get source(): Source;\n\n private _core: AttachmentSnapshotBinding<Source>;\n\n constructor(_core: AttachmentSnapshotBinding<Source>) {\n this._core = _core;\n this.__internal_bindMethods();\n }\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 private _composerApi: ComposerRuntimeCoreBinding;\n\n constructor(\n core: AttachmentSnapshotBinding<Source>,\n _composerApi: ComposerRuntimeCoreBinding,\n ) {\n super(core);\n this._composerApi = _composerApi;\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 public remove(): never {\n throw new Error(\"Message attachments cannot be removed\");\n }\n}\n"],"mappings":";AA0CA,IAAsBuB,wBAAtB,MAE+B;CAC7B,IAAWP,OAAO;EAChB,OAAO,KAAKQ,MAAMR;CACpB;CAIA;CAEAS,YAAYD,OAA0C;EACpD,KAAKA,QAAQA;EACb,KAAKE,uBAAuB;CAC9B;CAEA,yBAAmC;EACjC,KAAKR,WAAW,KAAKA,SAASS,KAAK,IAAI;EACvC,KAAKR,SAAS,KAAKA,OAAOQ,KAAK,IAAI;EACnC,KAAKN,YAAY,KAAKA,UAAUM,KAAK,IAAI;CAC3C;CAEA,WAAwD;EACtD,OAAO,KAAKH,MAAMN,SAAS;CAC7B;CAIA,UAAiBI,UAAsB;EACrC,OAAO,KAAKE,MAAMH,UAAUC,QAAQ;CACtC;AACF;AAEA,IAAeM,4BAAf,cAEUL,sBAA8B;CACtC;CAEAE,YACEK,MACAD,cACA;EACA,MAAMC,IAAI;EACV,KAAKD,eAAeA;CACtB;CAEA,SAAgB;EACd,MAAMC,OAAO,KAAKD,aAAaX,SAAS;EACxC,IAAI,CAACY,MAAM,MAAM,IAAIC,MAAM,2BAA2B;EACtD,OAAOD,KAAKE,iBAAiB,KAAKd,SAAS,CAAC,CAACe,EAAE;CACjD;AACF;AAEA,IAAaC,sCAAb,cAAyDN,0BAA6C;CACpG,IAAWrB,SAA4B;EACrC,OAAO;CACT;AACF;AAEA,IAAa4B,oCAAb,cAAuDP,0BAA2C;CAChG,IAAWrB,SAA0B;EACnC,OAAO;CACT;AACF;AAEA,IAAa6B,+BAAb,cAAkDb,sBAAiC;CACjF,IAAWhB,SAAoB;EAC7B,OAAO;CACT;CAEA,SAAuB;EACrB,MAAM,IAAIwB,MAAM,uCAAuC;CACzD;AACF"}
@@ -130,9 +130,9 @@ type ComposerRuntime = {
130
130
  unstable_on<E extends ComposerRuntimeEventType>(event: E, callback: ComposerRuntimeEventCallback<E>): Unsubscribe;
131
131
  };
132
132
  declare abstract class ComposerRuntimeImpl implements ComposerRuntime {
133
- protected _core: ComposerRuntimeCoreBinding;
134
133
  get path(): ComposerRuntimePath;
135
134
  abstract get type(): "edit" | "thread";
135
+ protected _core: ComposerRuntimeCoreBinding;
136
136
  constructor(_core: ComposerRuntimeCoreBinding);
137
137
  protected __internal_bindMethods(): void;
138
138
  abstract getState(): ComposerState;
@@ -186,12 +186,12 @@ type EditComposerRuntime = Omit<ComposerRuntime, "getState" | "getAttachmentByIn
186
186
  };
187
187
  };
188
188
  declare class EditComposerRuntimeImpl extends ComposerRuntimeImpl implements EditComposerRuntime {
189
- private _beginEdit;
190
189
  get path(): ComposerRuntimePath & {
191
190
  composerSource: "edit";
192
191
  };
193
192
  get type(): "edit";
194
193
  private _getState;
194
+ private _beginEdit;
195
195
  constructor(core: EditComposerRuntimeCoreBinding, _beginEdit: () => void);
196
196
  __internal_bindMethods(): void;
197
197
  getState(): EditComposerState;
@@ -1 +1 @@
1
- {"version":3,"file":"composer-runtime.d.ts","names":[],"sources":["../../../src/runtime/api/composer-runtime.ts"],"mappings":";;;;;;;;;;KA0CK;WACM;WACA;WACA;WACA;WAEA;WACA,MAAM;WACN,sBAAsB;WACtB,WAAW;WAEX;;;;;WAMA,WAAW;;;;;WAMX,OAAO;;WAGP,gBAAgB;;KAGf,sBAAsB;WACvB;;KAGC,oBAAoB;WACrB;WACA;WACA;;KAGC,gBAAgB,sBAAsB;KAuDtC;WACD,MAAM;WACN;;;;EAKT,YAAY;;;;;;;;;;EAWZ,cAAc,kBAAkB,OAAO,mBAAmB;;;;;EAM1D,QAAQ;;;;;EAMR,QAAQ,MAAM;;;;;;;;;;;;EAad,aAAa,WAAW;;;;EAKxB,SAAS;;;;EAKT,oBAAoB;;;;;EAMpB,KAAK,UAAU;;;;EAKf;;EAGA,eAAe;;EAGf,gBAAgB;;;;;EAMhB,UAAU,uBAAuB;;;;;EAMjC,qBAAqB,cAAc;;;;;EAMnC;;;;EAKA;;;;;EAMA,SAAS,OAAO;;;;EAKhB,YAAY,UAAU,0BACpB,OAAO,GACP,UAAU,6BAA6B,KACtC;;uBAGiB,+BAA+B;YAO7B,OAAO;MANlB,QAAI;eAIK;cAEE,OAAO;YAEnB;WAoBM,YAAY;EAErB,QA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Gf,gBAAgB;;;;;EAMhB,UAAU,uBAAuB;;;;;EAMjC,qBAAqB,cAAc;;;;;EAMnC;;;;EAKA;;;;;EAMA,SAAS,OAAO;;;;EAKhB,YAAY,UAAU,0BACpB,OAAO,GACP,UAAU,6BAA6B,KACtC;;uBAGiB,+BAA+B;MACxC,QAAI;eAIK;YAEV,OAAO;EAEL,YAAA,OAAO;YAIT;WAoBM,YAAY;EAErB,QAAQ;EAMR,aAAa,WAAW;EAMxB,cAAc,kBAAkB,OAAO,mBAAgB;EAMvD,SAAK;EAML,oBAAgB;EAMhB,KAAK,UAAU;EAMf;EAMA,eAAe;EAMf,gBAAgB;EAMhB,QAAQ,MAAM;EAMd;EAMA;EAMA,SAAS,OAAO;EAMhB,UAAU,uBAAoB;UAI7B;EAKD,YAAY,UAAU,0BAC3B,OAAO,GACP,UAAU,6BAA6B,KACtC;WAYa,qBAAqB,cAAc;;KAGzC,wBAAwB,KAClC;WAGS,MAAM;IAAwB;;WAC9B;EACT,YAAY;EAEZ,qBACE,cACC;IAAsB;;;cAGd,kCACH,+BACG;MAES,QACQ;IACxB;;MAIO;UAIH;EAEI,YAAA,MAAM;EAgBF,YAAY;EAIrB,qBAAqB,cAAW;;KA0B7B,sBAAsB,KAChC;WAGS,MAAM;IAAwB;;WAC9B;EAET,YAAY;EACZ;EAEA,qBACE,cACC;IAAsB;;;cAGd,gCACH,+BACG;MAES,QACQ;IAAwB;;MAGzC;UAIH;UACA;EAEI,YAAA,MAAM,gCAAgC;EAmBlC;EAKA,YAAY;EAIrB;EAIA,qBAAqB,cAAW"}
@@ -42,10 +42,10 @@ const getEditComposerState = (runtime) => {
42
42
  });
43
43
  };
44
44
  var ComposerRuntimeImpl = class {
45
- _core;
46
45
  get path() {
47
46
  return this._core.path;
48
47
  }
48
+ _core;
49
49
  constructor(_core) {
50
50
  this._core = _core;
51
51
  }
@@ -198,7 +198,6 @@ var ThreadComposerRuntimeImpl = class extends ComposerRuntimeImpl {
198
198
  }
199
199
  };
200
200
  var EditComposerRuntimeImpl = class extends ComposerRuntimeImpl {
201
- _beginEdit;
202
201
  get path() {
203
202
  return this._core.path;
204
203
  }
@@ -206,6 +205,7 @@ var EditComposerRuntimeImpl = class extends ComposerRuntimeImpl {
206
205
  return "edit";
207
206
  }
208
207
  _getState;
208
+ _beginEdit;
209
209
  constructor(core, _beginEdit) {
210
210
  const stateBinding = new LazyMemoizeSubject({
211
211
  path: core.path,
@@ -1 +1 @@
1
- {"version":3,"file":"composer-runtime.js","names":["Attachment","CreateAttachment","MessageRole","QuoteInfo","Unsubscribe","RunConfig","QueueItemState","LazyMemoizeSubject","EventSubscriptionSubject","ShallowMemoizeSubject","SKIP_UPDATE","ComposerRuntimeEventCallback","ComposerRuntimeEventType","DictationState","EditComposerRuntimeCore","SendOptions","ThreadComposerRuntimeCore","ThreadComposerRuntimeCoreBinding","EditComposerRuntimeCoreBinding","ComposerRuntimeCoreBinding","ComposerRuntimePath","AttachmentRuntime","AttachmentState","EditComposerAttachmentRuntimeImpl","ThreadComposerAttachmentRuntimeImpl","BaseComposerState","canCancel","canSend","isEditing","isEmpty","text","role","attachments","runConfig","attachmentAccept","dictation","quote","queue","ThreadComposerState","type","EditComposerState","parentId","sourceId","ComposerState","EMPTY_ARRAY","Object","freeze","EMPTY_OBJECT","getThreadComposerState","runtime","value","getEditComposerState","ComposerRuntime","path","getState","addAttachment","fileOrAttachment","File","Promise","setText","setRole","setRunConfig","reset","clearAttachments","send","options","cancel","steerQueueItem","queueItemId","removeQueueItem","subscribe","callback","getAttachmentByIndex","idx","startDictation","stopDictation","setQuote","unstable_on","event","E","ComposerRuntimeImpl","_core","constructor","__internal_bindMethods","bind","core","Error","_eventSubscriptionSubjects","Map","subject","get","binding","set","payload","ThreadComposerRuntime","Omit","composerSource","source","ThreadComposerRuntimeImpl","const","_getState","stateBinding","attachmentSource","attachmentSelector","index","ref","attachment","EditComposerRuntime","beginEdit","EditComposerRuntimeImpl","_beginEdit"],"sources":["../../../src/runtime/api/composer-runtime.ts"],"sourcesContent":["import type { Attachment, CreateAttachment } from \"../../types/attachment\";\nimport type { MessageRole } from \"../../types/message\";\nimport type { QuoteInfo } from \"../../types/quote\";\nimport type { Unsubscribe } from \"../../types/unsubscribe\";\nimport type { RunConfig } from \"../../types/message\";\nimport type { QueueItemState } from \"../../store/scopes/queue-item\";\nimport {\n LazyMemoizeSubject,\n EventSubscriptionSubject,\n} from \"../../subscribable/subscribable\";\nimport {\n ShallowMemoizeSubject,\n SKIP_UPDATE,\n} from \"../../subscribable/subscribable\";\nimport type {\n ComposerRuntimeEventCallback,\n ComposerRuntimeEventType,\n DictationState,\n EditComposerRuntimeCore,\n SendOptions,\n ThreadComposerRuntimeCore,\n} from \"../interfaces/composer-runtime-core\";\nimport type {\n ThreadComposerRuntimeCoreBinding,\n EditComposerRuntimeCoreBinding,\n ComposerRuntimeCoreBinding,\n} from \"./bindings\";\nimport type { ComposerRuntimePath } from \"./paths\";\n\nimport {\n type AttachmentRuntime,\n type AttachmentState,\n EditComposerAttachmentRuntimeImpl,\n ThreadComposerAttachmentRuntimeImpl,\n} from \"./attachment-runtime\";\n\nexport type {\n ThreadComposerRuntimeCoreBinding,\n EditComposerRuntimeCoreBinding,\n ComposerRuntimeCoreBinding,\n};\n\ntype BaseComposerState = {\n readonly canCancel: boolean;\n readonly canSend: 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 readonly attachmentAccept: string;\n\n /**\n * The current state of dictation.\n * Undefined when dictation is not active.\n */\n readonly dictation: DictationState | undefined;\n\n /**\n * The currently quoted text, if any.\n * Undefined when no quote is set.\n */\n readonly quote: QuoteInfo | undefined;\n\n /** Messages waiting to be processed. Empty unless the `queue` capability is set. */\n readonly queue: readonly QueueItemState[];\n};\n\nexport type ThreadComposerState = BaseComposerState & {\n readonly type: \"thread\";\n};\n\nexport type EditComposerState = BaseComposerState & {\n readonly type: \"edit\";\n readonly parentId: string | null;\n readonly sourceId: string | null;\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 canSend: runtime?.canSend ?? 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 attachmentAccept: runtime?.attachmentAccept ?? \"\",\n dictation: runtime?.dictation,\n quote: runtime?.quote,\n queue: runtime?.queue ?? EMPTY_ARRAY,\n\n value: runtime?.text ?? \"\",\n });\n};\n\nconst getEditComposerState = (\n runtime: EditComposerRuntimeCore | undefined,\n): EditComposerState => {\n return Object.freeze({\n type: \"edit\",\n\n isEditing: runtime?.isEditing ?? false,\n canCancel: runtime?.canCancel ?? false,\n canSend: runtime?.canSend ?? 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 attachmentAccept: runtime?.attachmentAccept ?? \"\",\n dictation: runtime?.dictation,\n quote: runtime?.quote,\n queue: runtime?.queue ?? EMPTY_ARRAY,\n\n parentId: runtime?.parentId ?? null,\n sourceId: runtime?.sourceId ?? null,\n\n value: runtime?.text ?? \"\",\n });\n};\n\nexport type ComposerRuntime = {\n readonly path: ComposerRuntimePath;\n readonly type: \"edit\" | \"thread\";\n\n /**\n * Get the current state of the composer. Includes any data that has been added to the composer.\n */\n getState(): ComposerState;\n\n /**\n * Add an attachment to the composer. Accepts either a standard File object\n * (processed through the AttachmentAdapter) or a CreateAttachment descriptor\n * for external-source attachments (URLs, API data, CMS references). External\n * descriptors bypass the adapter's `add()` step but still respect\n * `adapter.accept` when an adapter is configured; without an adapter they\n * are added as-is.\n * @param fileOrAttachment The file or attachment descriptor to add.\n */\n addAttachment(fileOrAttachment: File | CreateAttachment): Promise<void>;\n\n /**\n * Set the text of the composer.\n * @param text The text to set in the composer.\n */\n setText(text: string): void;\n\n /**\n * Set the role of the composer. For instance, if you'd like a specific message to have the 'assistant' role, you can do so here.\n * @param role The role to set in the composer.\n */\n setRole(role: MessageRole): void;\n\n /**\n * Set the run config of the composer. This is used to send custom configuration data to the model.\n * Within your backend, you can use the `runConfig` object.\n * Example:\n * ```ts\n * composerRuntime.setRunConfig({\n * custom: { customField: \"customValue\" }\n * });\n * ```\n * @param runConfig The run config to set in the composer.\n */\n setRunConfig(runConfig: RunConfig): void;\n\n /**\n * Reset the composer. This will clear the entire state of the composer, including all text and attachments.\n */\n reset(): Promise<void>;\n\n /**\n * Clear all attachments from the composer.\n */\n clearAttachments(): Promise<void>;\n\n /**\n * Send a message. This will send whatever text or attachments are in the composer.\n * @param options Optional send options. Use `{ startRun: true }` to force starting a new run.\n */\n send(options?: SendOptions): void;\n\n /**\n * Cancel the current run. In edit mode, this will exit edit mode.\n */\n cancel(): void;\n\n /** Promote a queued message so it processes next. */\n steerQueueItem(queueItemId: string): void;\n\n /** Remove a queued message. */\n removeQueueItem(queueItemId: string): void;\n\n /**\n * Listens for changes to the composer state.\n * @param callback The callback to call when the composer state changes.\n */\n subscribe(callback: () => void): Unsubscribe;\n\n /**\n * Get an attachment by index.\n * @param idx The index of the attachment to get.\n */\n getAttachmentByIndex(idx: number): AttachmentRuntime;\n\n /**\n * Start dictation to convert voice to text input.\n * Requires a DictationAdapter to be configured.\n */\n startDictation(): void;\n\n /**\n * Stop the current dictation session.\n */\n stopDictation(): void;\n\n /**\n * Set a quote for the next message. Pass undefined to clear.\n * @param quote The quote info to set, or undefined to clear.\n */\n setQuote(quote: QuoteInfo | undefined): void;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n unstable_on<E extends ComposerRuntimeEventType>(\n event: E,\n callback: ComposerRuntimeEventCallback<E>,\n ): Unsubscribe;\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.steerQueueItem = this.steerQueueItem.bind(this);\n this.removeQueueItem = this.removeQueueItem.bind(this);\n this.setRole = this.setRole.bind(this);\n this.getAttachmentByIndex = this.getAttachmentByIndex.bind(this);\n this.startDictation = this.startDictation.bind(this);\n this.stopDictation = this.stopDictation.bind(this);\n this.setQuote = this.setQuote.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(fileOrAttachment: File | CreateAttachment) {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n return core.addAttachment(fileOrAttachment);\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(options?: SendOptions) {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.send(options);\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 steerQueueItem(queueItemId: string) {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.steerQueueItem(queueItemId);\n }\n\n public removeQueueItem(queueItemId: string) {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.removeQueueItem(queueItemId);\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 startDictation() {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.startDictation();\n }\n\n public stopDictation() {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.stopDictation();\n }\n\n public setQuote(quote: QuoteInfo | undefined) {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.setQuote(quote);\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<E extends ComposerRuntimeEventType>(\n event: E,\n callback: ComposerRuntimeEventCallback<E>,\n ): Unsubscribe {\n let subject = this._eventSubscriptionSubjects.get(event);\n if (!subject) {\n subject = new EventSubscriptionSubject<ComposerRuntimeEventType>({\n event,\n binding: this._core,\n });\n this._eventSubscriptionSubjects.set(event, subject);\n }\n return subject.subscribe(callback as (payload?: unknown) => void);\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 this.__internal_bindMethods();\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}.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 this.__internal_bindMethods();\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}.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":";;;AAmFA,MAAM4C,cAAcC,OAAOC,OAAO,CAAA,CAAE;AACpC,MAAMC,eAAeF,OAAOC,OAAO,CAAC,CAAC;AACrC,MAAME,0BACJC,YACwB;CACxB,OAAOJ,OAAOC,OAAO;EACnBP,MAAM;EAENX,WAAWqB,SAASrB,aAAa;EACjCF,WAAWuB,SAASvB,aAAa;EACjCC,SAASsB,SAAStB,WAAW;EAC7BE,SAASoB,SAASpB,WAAW;EAE7BG,aAAaiB,SAASjB,eAAeY;EACrCd,MAAMmB,SAASnB,QAAQ;EACvBC,MAAMkB,SAASlB,QAAQ;EACvBE,WAAWgB,SAAShB,aAAac;EACjCb,kBAAkBe,SAASf,oBAAoB;EAC/CC,WAAWc,SAASd;EACpBC,OAAOa,SAASb;EAChBC,OAAOY,SAASZ,SAASO;EAEzBM,OAAO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names":["Attachment","CreateAttachment","MessageRole","QuoteInfo","Unsubscribe","RunConfig","QueueItemState","LazyMemoizeSubject","EventSubscriptionSubject","ShallowMemoizeSubject","SKIP_UPDATE","ComposerRuntimeEventCallback","ComposerRuntimeEventType","DictationState","EditComposerRuntimeCore","SendOptions","ThreadComposerRuntimeCore","ThreadComposerRuntimeCoreBinding","EditComposerRuntimeCoreBinding","ComposerRuntimeCoreBinding","ComposerRuntimePath","AttachmentRuntime","AttachmentState","EditComposerAttachmentRuntimeImpl","ThreadComposerAttachmentRuntimeImpl","BaseComposerState","canCancel","canSend","isEditing","isEmpty","text","role","attachments","runConfig","attachmentAccept","dictation","quote","queue","ThreadComposerState","type","EditComposerState","parentId","sourceId","ComposerState","EMPTY_ARRAY","Object","freeze","EMPTY_OBJECT","getThreadComposerState","runtime","value","getEditComposerState","ComposerRuntime","path","getState","addAttachment","fileOrAttachment","File","Promise","setText","setRole","setRunConfig","reset","clearAttachments","send","options","cancel","steerQueueItem","queueItemId","removeQueueItem","subscribe","callback","getAttachmentByIndex","idx","startDictation","stopDictation","setQuote","unstable_on","event","E","ComposerRuntimeImpl","_core","constructor","__internal_bindMethods","bind","core","Error","_eventSubscriptionSubjects","Map","subject","get","binding","set","payload","ThreadComposerRuntime","Omit","composerSource","source","ThreadComposerRuntimeImpl","const","_getState","stateBinding","attachmentSource","attachmentSelector","index","ref","attachment","EditComposerRuntime","beginEdit","EditComposerRuntimeImpl","_beginEdit"],"sources":["../../../src/runtime/api/composer-runtime.ts"],"sourcesContent":["import type { Attachment, CreateAttachment } from \"../../types/attachment\";\nimport type { MessageRole } from \"../../types/message\";\nimport type { QuoteInfo } from \"../../types/quote\";\nimport type { Unsubscribe } from \"../../types/unsubscribe\";\nimport type { RunConfig } from \"../../types/message\";\nimport type { QueueItemState } from \"../../store/scopes/queue-item\";\nimport {\n LazyMemoizeSubject,\n EventSubscriptionSubject,\n} from \"../../subscribable/subscribable\";\nimport {\n ShallowMemoizeSubject,\n SKIP_UPDATE,\n} from \"../../subscribable/subscribable\";\nimport type {\n ComposerRuntimeEventCallback,\n ComposerRuntimeEventType,\n DictationState,\n EditComposerRuntimeCore,\n SendOptions,\n ThreadComposerRuntimeCore,\n} from \"../interfaces/composer-runtime-core\";\nimport type {\n ThreadComposerRuntimeCoreBinding,\n EditComposerRuntimeCoreBinding,\n ComposerRuntimeCoreBinding,\n} from \"./bindings\";\nimport type { ComposerRuntimePath } from \"./paths\";\n\nimport {\n type AttachmentRuntime,\n type AttachmentState,\n EditComposerAttachmentRuntimeImpl,\n ThreadComposerAttachmentRuntimeImpl,\n} from \"./attachment-runtime\";\n\nexport type {\n ThreadComposerRuntimeCoreBinding,\n EditComposerRuntimeCoreBinding,\n ComposerRuntimeCoreBinding,\n};\n\ntype BaseComposerState = {\n readonly canCancel: boolean;\n readonly canSend: 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 readonly attachmentAccept: string;\n\n /**\n * The current state of dictation.\n * Undefined when dictation is not active.\n */\n readonly dictation: DictationState | undefined;\n\n /**\n * The currently quoted text, if any.\n * Undefined when no quote is set.\n */\n readonly quote: QuoteInfo | undefined;\n\n /** Messages waiting to be processed. Empty unless the `queue` capability is set. */\n readonly queue: readonly QueueItemState[];\n};\n\nexport type ThreadComposerState = BaseComposerState & {\n readonly type: \"thread\";\n};\n\nexport type EditComposerState = BaseComposerState & {\n readonly type: \"edit\";\n readonly parentId: string | null;\n readonly sourceId: string | null;\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 canSend: runtime?.canSend ?? 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 attachmentAccept: runtime?.attachmentAccept ?? \"\",\n dictation: runtime?.dictation,\n quote: runtime?.quote,\n queue: runtime?.queue ?? EMPTY_ARRAY,\n\n value: runtime?.text ?? \"\",\n });\n};\n\nconst getEditComposerState = (\n runtime: EditComposerRuntimeCore | undefined,\n): EditComposerState => {\n return Object.freeze({\n type: \"edit\",\n\n isEditing: runtime?.isEditing ?? false,\n canCancel: runtime?.canCancel ?? false,\n canSend: runtime?.canSend ?? 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 attachmentAccept: runtime?.attachmentAccept ?? \"\",\n dictation: runtime?.dictation,\n quote: runtime?.quote,\n queue: runtime?.queue ?? EMPTY_ARRAY,\n\n parentId: runtime?.parentId ?? null,\n sourceId: runtime?.sourceId ?? null,\n\n value: runtime?.text ?? \"\",\n });\n};\n\nexport type ComposerRuntime = {\n readonly path: ComposerRuntimePath;\n readonly type: \"edit\" | \"thread\";\n\n /**\n * Get the current state of the composer. Includes any data that has been added to the composer.\n */\n getState(): ComposerState;\n\n /**\n * Add an attachment to the composer. Accepts either a standard File object\n * (processed through the AttachmentAdapter) or a CreateAttachment descriptor\n * for external-source attachments (URLs, API data, CMS references). External\n * descriptors bypass the adapter's `add()` step but still respect\n * `adapter.accept` when an adapter is configured; without an adapter they\n * are added as-is.\n * @param fileOrAttachment The file or attachment descriptor to add.\n */\n addAttachment(fileOrAttachment: File | CreateAttachment): Promise<void>;\n\n /**\n * Set the text of the composer.\n * @param text The text to set in the composer.\n */\n setText(text: string): void;\n\n /**\n * Set the role of the composer. For instance, if you'd like a specific message to have the 'assistant' role, you can do so here.\n * @param role The role to set in the composer.\n */\n setRole(role: MessageRole): void;\n\n /**\n * Set the run config of the composer. This is used to send custom configuration data to the model.\n * Within your backend, you can use the `runConfig` object.\n * Example:\n * ```ts\n * composerRuntime.setRunConfig({\n * custom: { customField: \"customValue\" }\n * });\n * ```\n * @param runConfig The run config to set in the composer.\n */\n setRunConfig(runConfig: RunConfig): void;\n\n /**\n * Reset the composer. This will clear the entire state of the composer, including all text and attachments.\n */\n reset(): Promise<void>;\n\n /**\n * Clear all attachments from the composer.\n */\n clearAttachments(): Promise<void>;\n\n /**\n * Send a message. This will send whatever text or attachments are in the composer.\n * @param options Optional send options. Use `{ startRun: true }` to force starting a new run.\n */\n send(options?: SendOptions): void;\n\n /**\n * Cancel the current run. In edit mode, this will exit edit mode.\n */\n cancel(): void;\n\n /** Promote a queued message so it processes next. */\n steerQueueItem(queueItemId: string): void;\n\n /** Remove a queued message. */\n removeQueueItem(queueItemId: string): void;\n\n /**\n * Listens for changes to the composer state.\n * @param callback The callback to call when the composer state changes.\n */\n subscribe(callback: () => void): Unsubscribe;\n\n /**\n * Get an attachment by index.\n * @param idx The index of the attachment to get.\n */\n getAttachmentByIndex(idx: number): AttachmentRuntime;\n\n /**\n * Start dictation to convert voice to text input.\n * Requires a DictationAdapter to be configured.\n */\n startDictation(): void;\n\n /**\n * Stop the current dictation session.\n */\n stopDictation(): void;\n\n /**\n * Set a quote for the next message. Pass undefined to clear.\n * @param quote The quote info to set, or undefined to clear.\n */\n setQuote(quote: QuoteInfo | undefined): void;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n unstable_on<E extends ComposerRuntimeEventType>(\n event: E,\n callback: ComposerRuntimeEventCallback<E>,\n ): Unsubscribe;\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 protected _core: ComposerRuntimeCoreBinding;\n\n constructor(_core: ComposerRuntimeCoreBinding) {\n this._core = _core;\n }\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.steerQueueItem = this.steerQueueItem.bind(this);\n this.removeQueueItem = this.removeQueueItem.bind(this);\n this.setRole = this.setRole.bind(this);\n this.getAttachmentByIndex = this.getAttachmentByIndex.bind(this);\n this.startDictation = this.startDictation.bind(this);\n this.stopDictation = this.stopDictation.bind(this);\n this.setQuote = this.setQuote.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(fileOrAttachment: File | CreateAttachment) {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n return core.addAttachment(fileOrAttachment);\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(options?: SendOptions) {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.send(options);\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 steerQueueItem(queueItemId: string) {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.steerQueueItem(queueItemId);\n }\n\n public removeQueueItem(queueItemId: string) {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.removeQueueItem(queueItemId);\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 startDictation() {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.startDictation();\n }\n\n public stopDictation() {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.stopDictation();\n }\n\n public setQuote(quote: QuoteInfo | undefined) {\n const core = this._core.getState();\n if (!core) throw new Error(\"Composer is not available\");\n core.setQuote(quote);\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<E extends ComposerRuntimeEventType>(\n event: E,\n callback: ComposerRuntimeEventCallback<E>,\n ): Unsubscribe {\n let subject = this._eventSubscriptionSubjects.get(event);\n if (!subject) {\n subject = new EventSubscriptionSubject<ComposerRuntimeEventType>({\n event,\n binding: this._core,\n });\n this._eventSubscriptionSubjects.set(event, subject);\n }\n return subject.subscribe(callback as (payload?: unknown) => void);\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 this.__internal_bindMethods();\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}.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 private _beginEdit: () => void;\n\n constructor(core: EditComposerRuntimeCoreBinding, _beginEdit: () => void) {\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 this._beginEdit = _beginEdit;\n\n this._getState = stateBinding.getState.bind(stateBinding);\n\n this.__internal_bindMethods();\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}.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":";;;AAmFA,MAAM4C,cAAcC,OAAOC,OAAO,CAAA,CAAE;AACpC,MAAMC,eAAeF,OAAOC,OAAO,CAAC,CAAC;AACrC,MAAME,0BACJC,YACwB;CACxB,OAAOJ,OAAOC,OAAO;EACnBP,MAAM;EAENX,WAAWqB,SAASrB,aAAa;EACjCF,WAAWuB,SAASvB,aAAa;EACjCC,SAASsB,SAAStB,WAAW;EAC7BE,SAASoB,SAASpB,WAAW;EAE7BG,aAAaiB,SAASjB,eAAeY;EACrCd,MAAMmB,SAASnB,QAAQ;EACvBC,MAAMkB,SAASlB,QAAQ;EACvBE,WAAWgB,SAAShB,aAAac;EACjCb,kBAAkBe,SAASf,oBAAoB;EAC/CC,WAAWc,SAASd;EACpBC,OAAOa,SAASb;EAChBC,OAAOY,SAASZ,SAASO;EAEzBM,OAAOD,SAASnB,QAAQ;CAC1B,CAAC;AACH;AAEA,MAAMqB,wBACJF,YACsB;CACtB,OAAOJ,OAAOC,OAAO;EACnBP,MAAM;EAENX,WAAWqB,SAASrB,aAAa;EACjCF,WAAWuB,SAASvB,aAAa;EACjCC,SAASsB,SAAStB,WAAW;EAC7BE,SAASoB,SAASpB,WAAW;EAE7BC,MAAMmB,SAASnB,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C,KAAK/B,SAAS,CAAC;GACpDgB,YAAYC,aAAac,KAAKf,UAAUC,QAAQ;EAClD,CAAC;EAED,MAAM;GACJlB,MAAMgC,KAAKhC;GACXC,gBAAgB+B,KAAK/B,SAAS;GAC9BgB,YAAYC,aAAa8B,aAAa/B,UAAUC,QAAQ;EAC1D,CAAC;EACD,KAAKuC,aAAaA;EAElB,KAAKV,YAAYC,aAAa/C,SAAS8B,KAAKiB,YAAY;EAExD,KAAKlB,uBAAuB;CAC9B;CAEA,yBAAyC;EACvC,MAAMA,uBAAuB;EAC7B,KAAKyB,YAAY,KAAKA,UAAUxB,KAAK,IAAI;CAC3C;CAEA,WAA8C;EAC5C,OAAO,KAAKgB,UAAU;CACxB;CAEA,YAAmB;EACjB,KAAKU,WAAW;CAClB;CAEA,qBAA4BrC,KAAa;EACvC,OAAO,IAAIlD,kCACT,IAAId,sBAAsB;GACxB4C,MAAM;IACJ,GAAG,KAAKA;IACRiD,kBAAkB;IAClBC,oBAAoB;KAAEhE,MAAM;KAASiE,OAAO/B;IAAI;IAChDgC,KAAK,GAAG,KAAKpD,KAAKoD,IAAG,eAAgBhC,IAAG;GAC1C;GACAnB,gBAAgB;IAEd,MAAMoD,aADc,KAAKpD,SAAS,CAAC,CAACtB,YACLyC;IAC/B,IAAI,CAACiC,YAAY,OAAOhG;IAExB,OAAO;KACL,GAAGgG;KACHT,QAAQ;IACV;GACF;GACA3B,YAAYC,aAAa,KAAKU,MAAMX,UAAUC,QAAQ;EACxD,CAAC,GACD,KAAKU,KACP;CACF;AACF"}
@@ -19,11 +19,11 @@ type MessagePartRuntime = {
19
19
  subscribe(callback: () => void): Unsubscribe;
20
20
  };
21
21
  declare class MessagePartRuntimeImpl implements MessagePartRuntime {
22
- private contentBinding;
23
- private messageApi?;
24
- private threadApi?;
25
22
  get path(): MessagePartRuntimePath;
26
- constructor(contentBinding: MessagePartSnapshotBinding, messageApi?: MessageStateBinding | undefined, threadApi?: ThreadRuntimeCoreBinding | undefined);
23
+ private contentBinding;
24
+ private messageApi;
25
+ private threadApi;
26
+ constructor(contentBinding: MessagePartSnapshotBinding, messageApi?: MessageStateBinding, threadApi?: ThreadRuntimeCoreBinding);
27
27
  protected __internal_bindMethods(): void;
28
28
  getState(): MessagePartState;
29
29
  addToolResult(result: any | ToolResponse<any>): void;
@@ -1 +1 @@
1
- {"version":3,"file":"message-part-runtime.d.ts","names":[],"sources":["../../../src/runtime/api/message-part-runtime.ts"],"mappings":";;;;;;;;KAeY,oBACR,wBACA;WAEO,QAAQ,oBAAoB;;KAGlC,6BAA6B,sBAChC,kBACA;KAGU;EACV,cAAc,cAAc;EAC5B,eAAe;EACf,sBAAsB,UAAU;WAEvB,MAAM;EACf,YAAY;EACZ,UAAU,uBAAuB;;cAGtB,kCAAkC;UAMnC;UACA;UACA;MAPC,QAAI;cAKL,gBAAgB,4BAChB,aAAa,iCACb,YAAY;YAKZ;EAQH,YAAQ;EAIR,cAAc,cAAc;EA8B5B,eAAe;EAgBf,sBAAsB,UAAU;EAyBhC,UAAU,uBAAoB"}
1
+ {"version":3,"file":"message-part-runtime.d.ts","names":[],"sources":["../../../src/runtime/api/message-part-runtime.ts"],"mappings":";;;;;;;;KAeY,oBACR,wBACA;WAEO,QAAQ,oBAAoB;;KAGlC,6BAA6B,sBAChC,kBACA;KAGU;EACV,cAAc,cAAc;EAC5B,eAAe;EACf,sBAAsB,UAAU;WAEvB,MAAM;EACf,YAAY;EACZ,UAAU,uBAAuB;;cAGtB,kCAAkC;MAClC,QAAI;UAIP;UACA;UACA;EAGN,YAAA,gBAAgB,4BAChB,aAAa,qBACb,YAAY;YAQJ;EAQH,YAAQ;EAIR,cAAc,cAAc;EA8B5B,eAAe;EAgBf,sBAAsB,UAAU;EAyBhC,UAAU,uBAAoB"}
@@ -2,12 +2,12 @@ import { resolveToolApprovalResponse } from "../utils/resolveToolApprovalRespons
2
2
  import { ToolResponse } from "assistant-stream";
3
3
  //#region src/runtime/api/message-part-runtime.ts
4
4
  var MessagePartRuntimeImpl = class {
5
- contentBinding;
6
- messageApi;
7
- threadApi;
8
5
  get path() {
9
6
  return this.contentBinding.path;
10
7
  }
8
+ contentBinding;
9
+ messageApi;
10
+ threadApi;
11
11
  constructor(contentBinding, messageApi, threadApi) {
12
12
  this.contentBinding = contentBinding;
13
13
  this.messageApi = messageApi;
@@ -1 +1 @@
1
- {"version":3,"file":"message-part-runtime.js","names":["ThreadAssistantMessagePart","ThreadUserMessagePart","ToolApprovalResponse","ToolCallMessagePartStatus","resolveToolApprovalResponse","Unsubscribe","MessagePartStatus","SubscribableWithState","ThreadRuntimeCoreBinding","MessageStateBinding","MessagePartRuntimePath","ToolResponse","MessagePartState","status","MessagePartSnapshotBinding","MessagePartRuntime","addToolResult","result","resumeToolCall","payload","respondToToolApproval","response","path","getState","subscribe","callback","MessagePartRuntimeImpl","contentBinding","constructor","messageApi","threadApi","__internal_bindMethods","bind","state","Error","type","message","toolName","toolCallId","toResponse","messageId","id","artifact","isError","approval","approved","undefined","resolution"],"sources":["../../../src/runtime/api/message-part-runtime.ts"],"sourcesContent":["import type {\n ThreadAssistantMessagePart,\n ThreadUserMessagePart,\n ToolApprovalResponse,\n ToolCallMessagePartStatus,\n} from \"../../types/message\";\nimport { resolveToolApprovalResponse } from \"../utils/resolveToolApprovalResponse\";\nimport type { Unsubscribe } from \"../../types/unsubscribe\";\nimport type { MessagePartStatus } from \"../../types/message\";\nimport type { SubscribableWithState } from \"../../subscribable/subscribable\";\nimport type { ThreadRuntimeCoreBinding } from \"./thread-runtime\";\nimport type { MessageStateBinding } from \"./bindings\";\nimport type { MessagePartRuntimePath } from \"./paths\";\nimport { ToolResponse } from \"assistant-stream\";\n\nexport type MessagePartState = (\n | ThreadUserMessagePart\n | ThreadAssistantMessagePart\n) & {\n readonly status: MessagePartStatus | ToolCallMessagePartStatus;\n};\n\ntype MessagePartSnapshotBinding = SubscribableWithState<\n MessagePartState,\n MessagePartRuntimePath\n>;\n\nexport type MessagePartRuntime = {\n addToolResult(result: any | ToolResponse<any>): void;\n resumeToolCall(payload: unknown): void;\n respondToToolApproval(response: ToolApprovalResponse): void;\n\n readonly path: MessagePartRuntimePath;\n getState(): MessagePartState;\n subscribe(callback: () => void): Unsubscribe;\n};\n\nexport class MessagePartRuntimeImpl implements MessagePartRuntime {\n public get path() {\n return this.contentBinding.path;\n }\n\n constructor(\n private contentBinding: MessagePartSnapshotBinding,\n private messageApi?: MessageStateBinding,\n private threadApi?: ThreadRuntimeCoreBinding,\n ) {\n this.__internal_bindMethods();\n }\n\n protected __internal_bindMethods() {\n this.addToolResult = this.addToolResult.bind(this);\n this.resumeToolCall = this.resumeToolCall.bind(this);\n this.respondToToolApproval = this.respondToToolApproval.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 | ToolResponse<any>) {\n const state = this.contentBinding.getState();\n if (!state) throw new Error(\"Message part is not available\");\n\n if (state.type !== \"tool-call\")\n throw new Error(\"Tried to add tool result to non-tool message 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 const response = ToolResponse.toResponse(result);\n this.threadApi.getState().addToolResult({\n messageId: message.id,\n toolName,\n toolCallId,\n result: response.result,\n artifact: response.artifact,\n isError: response.isError,\n });\n }\n\n public resumeToolCall(payload: unknown) {\n const state = this.contentBinding.getState();\n if (!state) throw new Error(\"Message part is not available\");\n\n if (state.type !== \"tool-call\")\n throw new Error(\"Tried to resume tool call on non-tool message part\");\n\n if (!this.threadApi) throw new Error(\"Thread API is not available\");\n\n const toolCallId = state.toolCallId;\n this.threadApi.getState().resumeToolCall({\n toolCallId,\n payload,\n });\n }\n\n public respondToToolApproval(response: ToolApprovalResponse) {\n const state = this.contentBinding.getState();\n if (!state) throw new Error(\"Message part is not available\");\n\n if (state.type !== \"tool-call\")\n throw new Error(\n \"Tried to respond to tool approval on non-tool message part\",\n );\n\n if (\n !state.approval ||\n state.approval.approved !== undefined ||\n state.approval.resolution !== undefined\n )\n throw new Error(\"Tool call has no pending approval\");\n\n if (!this.threadApi) throw new Error(\"Thread API is not available\");\n\n this.threadApi\n .getState()\n .respondToToolApproval(\n resolveToolApprovalResponse(state.approval, response),\n );\n }\n\n public subscribe(callback: () => void) {\n return this.contentBinding.subscribe(callback);\n }\n}\n"],"mappings":";;;AAqCA,IAAa0B,yBAAb,MAAkE;CAMtDC;CACAE;CACAC;CAPV,IAAWR,OAAO;EAChB,OAAO,KAAKK,eAAeL;CAC7B;CAEAM,YACE,gBACA,YACA,WACA;EAHQD,KAAAA,iBAAAA;EACAE,KAAAA,aAAAA;EACAC,KAAAA,YAAAA;EAER,KAAKC,uBAAuB;CAC9B;CAEA,yBAAmC;EACjC,KAAKf,gBAAgB,KAAKA,cAAcgB,KAAK,IAAI;EACjD,KAAKd,iBAAiB,KAAKA,eAAec,KAAK,IAAI;EACnD,KAAKZ,wBAAwB,KAAKA,sBAAsBY,KAAK,IAAI;EACjE,KAAKT,WAAW,KAAKA,SAASS,KAAK,IAAI;EACvC,KAAKR,YAAY,KAAKA,UAAUQ,KAAK,IAAI;CAC3C;CAEA,WAAkB;EAChB,OAAO,KAAKL,eAAeJ,SAAS;CACtC;CAEA,cAAqBN,QAAiC;EACpD,MAAMgB,QAAQ,KAAKN,eAAeJ,SAAS;EAC3C,IAAI,CAACU,OAAO,MAAM,IAAIC,MAAM,+BAA+B;EAE3D,IAAID,MAAME,SAAS,aACjB,MAAM,IAAID,MAAM,mDAAmD;EAErE,IAAI,CAAC,KAAKL,YACR,MAAM,IAAIK,MACR,qEACF;EACF,IAAI,CAAC,KAAKJ,WAAW,MAAM,IAAII,MAAM,6BAA6B;EAElE,MAAME,UAAU,KAAKP,WAAWN,SAAS;EACz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agePart","ThreadUserMessagePart","ToolApprovalResponse","ToolCallMessagePartStatus","resolveToolApprovalResponse","Unsubscribe","MessagePartStatus","SubscribableWithState","ThreadRuntimeCoreBinding","MessageStateBinding","MessagePartRuntimePath","ToolResponse","MessagePartState","status","MessagePartSnapshotBinding","MessagePartRuntime","addToolResult","result","resumeToolCall","payload","respondToToolApproval","response","path","getState","subscribe","callback","MessagePartRuntimeImpl","contentBinding","messageApi","threadApi","constructor","__internal_bindMethods","bind","state","Error","type","message","toolName","toolCallId","toResponse","messageId","id","artifact","isError","approval","approved","undefined","resolution"],"sources":["../../../src/runtime/api/message-part-runtime.ts"],"sourcesContent":["import type {\n ThreadAssistantMessagePart,\n ThreadUserMessagePart,\n ToolApprovalResponse,\n ToolCallMessagePartStatus,\n} from \"../../types/message\";\nimport { resolveToolApprovalResponse } from \"../utils/resolveToolApprovalResponse\";\nimport type { Unsubscribe } from \"../../types/unsubscribe\";\nimport type { MessagePartStatus } from \"../../types/message\";\nimport type { SubscribableWithState } from \"../../subscribable/subscribable\";\nimport type { ThreadRuntimeCoreBinding } from \"./thread-runtime\";\nimport type { MessageStateBinding } from \"./bindings\";\nimport type { MessagePartRuntimePath } from \"./paths\";\nimport { ToolResponse } from \"assistant-stream\";\n\nexport type MessagePartState = (\n | ThreadUserMessagePart\n | ThreadAssistantMessagePart\n) & {\n readonly status: MessagePartStatus | ToolCallMessagePartStatus;\n};\n\ntype MessagePartSnapshotBinding = SubscribableWithState<\n MessagePartState,\n MessagePartRuntimePath\n>;\n\nexport type MessagePartRuntime = {\n addToolResult(result: any | ToolResponse<any>): void;\n resumeToolCall(payload: unknown): void;\n respondToToolApproval(response: ToolApprovalResponse): void;\n\n readonly path: MessagePartRuntimePath;\n getState(): MessagePartState;\n subscribe(callback: () => void): Unsubscribe;\n};\n\nexport class MessagePartRuntimeImpl implements MessagePartRuntime {\n public get path() {\n return this.contentBinding.path;\n }\n\n private contentBinding: MessagePartSnapshotBinding;\n private messageApi: MessageStateBinding | undefined;\n private threadApi: ThreadRuntimeCoreBinding | undefined;\n\n constructor(\n contentBinding: MessagePartSnapshotBinding,\n messageApi?: MessageStateBinding,\n threadApi?: ThreadRuntimeCoreBinding,\n ) {\n this.contentBinding = contentBinding;\n this.messageApi = messageApi;\n this.threadApi = threadApi;\n this.__internal_bindMethods();\n }\n\n protected __internal_bindMethods() {\n this.addToolResult = this.addToolResult.bind(this);\n this.resumeToolCall = this.resumeToolCall.bind(this);\n this.respondToToolApproval = this.respondToToolApproval.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 | ToolResponse<any>) {\n const state = this.contentBinding.getState();\n if (!state) throw new Error(\"Message part is not available\");\n\n if (state.type !== \"tool-call\")\n throw new Error(\"Tried to add tool result to non-tool message 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 const response = ToolResponse.toResponse(result);\n this.threadApi.getState().addToolResult({\n messageId: message.id,\n toolName,\n toolCallId,\n result: response.result,\n artifact: response.artifact,\n isError: response.isError,\n });\n }\n\n public resumeToolCall(payload: unknown) {\n const state = this.contentBinding.getState();\n if (!state) throw new Error(\"Message part is not available\");\n\n if (state.type !== \"tool-call\")\n throw new Error(\"Tried to resume tool call on non-tool message part\");\n\n if (!this.threadApi) throw new Error(\"Thread API is not available\");\n\n const toolCallId = state.toolCallId;\n this.threadApi.getState().resumeToolCall({\n toolCallId,\n payload,\n });\n }\n\n public respondToToolApproval(response: ToolApprovalResponse) {\n const state = this.contentBinding.getState();\n if (!state) throw new Error(\"Message part is not available\");\n\n if (state.type !== \"tool-call\")\n throw new Error(\n \"Tried to respond to tool approval on non-tool message part\",\n );\n\n if (\n !state.approval ||\n state.approval.approved !== undefined ||\n state.approval.resolution !== undefined\n )\n throw new Error(\"Tool call has no pending approval\");\n\n if (!this.threadApi) throw new Error(\"Thread API is not available\");\n\n this.threadApi\n .getState()\n .respondToToolApproval(\n resolveToolApprovalResponse(state.approval, response),\n );\n }\n\n public subscribe(callback: () => void) {\n return this.contentBinding.subscribe(callback);\n }\n}\n"],"mappings":";;;AAqCA,IAAa0B,yBAAb,MAAkE;CAChE,IAAWJ,OAAO;EAChB,OAAO,KAAKK,eAAeL;CAC7B;CAEA;CACA;CACA;CAEAQ,YACEH,gBACAC,YACAC,WACA;EACA,KAAKF,iBAAiBA;EACtB,KAAKC,aAAaA;EAClB,KAAKC,YAAYA;EACjB,KAAKE,uBAAuB;CAC9B;CAEA,yBAAmC;EACjC,KAAKf,gBAAgB,KAAKA,cAAcgB,KAAK,IAAI;EACjD,KAAKd,iBAAiB,KAAKA,eAAec,KAAK,IAAI;EACnD,KAAKZ,wBAAwB,KAAKA,sBAAsBY,KAAK,IAAI;EACjE,KAAKT,WAAW,KAAKA,SAASS,KAAK,IAAI;EACvC,KAAKR,YAAY,KAAKA,UAAUQ,KAAK,IAAI;CAC3C;CAEA,WAAkB;EAChB,OAAO,KAAKL,eAAeJ,SAAS;CACtC;CAEA,cAAqBN,QAAiC;EACpD,MAAMgB,QAAQ,KAAKN,eAAeJ,SAAS;EAC3C,IAAI,CAACU,OAAO,MAAM,IAAIC,MAAM,+BAA+B;EAE3D,IAAID,MAAME,SAAS,aACjB,MAAM,IAAID,MAAM,mDAAmD;EAErE,IAAI,CAAC,KAAKN,YACR,MAAM,IAAIM,MACR,qEACF;EACF,IAAI,CAAC,KAAKL,WAAW,MAAM,IAAIK,MAAM,6BAA6B;EAElE,MAAME,UAAU,KAAKR,WAAWL,SAAS;EACzC,IAAI,CAACa,SAAS,MAAM,IAAIF,MAAM,0BAA0B;EAExD,MAAMG,WAAWJ,MAAMI;EACvB,MAAMC,aAAaL,MAAMK;EAEzB,MAAMjB,WAAWV,aAAa4B,WAAWtB,MAAM;EAC/C,KAAKY,UAAUN,SAAS,CAAC,CAACP,cAAc;GACtCwB,WAAWJ,QAAQK;GACnBJ;GACAC;GACArB,QAAQI,SAASJ;GACjByB,UAAUrB,SAASqB;GACnBC,SAAStB,SAASsB;EACpB,CAAC;CACH;CAEA,eAAsBxB,SAAkB;EACtC,MAAMc,QAAQ,KAAKN,eAAeJ,SAAS;EAC3C,IAAI,CAACU,OAAO,MAAM,IAAIC,MAAM,+BAA+B;EAE3D,IAAID,MAAME,SAAS,aACjB,MAAM,IAAID,MAAM,oDAAoD;EAEtE,IAAI,CAAC,KAAKL,WAAW,MAAM,IAAIK,MAAM,6BAA6B;EAElE,MAAMI,aAAaL,MAAMK;EACzB,KAAKT,UAAUN,SAAS,CAAC,CAACL,eAAe;GACvCoB;GACAnB;EACF,CAAC;CACH;CAEA,sBAA6BE,UAAgC;EAC3D,MAAMY,QAAQ,KAAKN,eAAeJ,SAAS;EAC3C,IAAI,CAACU,OAAO,MAAM,IAAIC,MAAM,+BAA+B;EAE3D,IAAID,MAAME,SAAS,aACjB,MAAM,IAAID,MACR,4DACF;EAEF,IACE,CAACD,MAAMW,YACPX,MAAMW,SAASC,aAAaC,KAAAA,KAC5Bb,MAAMW,SAASG,eAAeD,KAAAA,GAE9B,MAAM,IAAIZ,MAAM,mCAAmC;EAErD,IAAI,CAAC,KAAKL,WAAW,MAAM,IAAIK,MAAM,6BAA6B;EAElE,KAAKL,UACFN,SAAS,CAAC,CACVH,sBACChB,4BAA4B6B,MAAMW,UAAUvB,QAAQ,CACtD;CACJ;CAEA,UAAiBI,UAAsB;EACrC,OAAO,KAAKE,eAAeH,UAAUC,QAAQ;CAC/C;AACF"}
@@ -54,9 +54,9 @@ type MessageRuntime = {
54
54
  };
55
55
  };
56
56
  declare class MessageRuntimeImpl implements MessageRuntime {
57
+ get path(): MessageRuntimePath;
57
58
  private _core;
58
59
  private _threadBinding;
59
- get path(): MessageRuntimePath;
60
60
  constructor(_core: MessageStateBinding, _threadBinding: ThreadRuntimeCoreBinding);
61
61
  protected __internal_bindMethods(): void;
62
62
  readonly composer: EditComposerRuntimeImpl;
@@ -1 +1 @@
1
- {"version":3,"file":"message-runtime.d.ts","names":[],"sources":["../../../src/runtime/api/message-runtime.ts"],"mappings":";;;;;;;;;;cAsCa,sBACX,SAAS,eACT,mBACA,MAAM,wBAAwB,+BAC7B;KAkCS,eAAe;WAChB;;WAEA;WACA;WAEA;WACA;;;;WAKA,QAAQ;;KAKd;EACH,YAAY;;KAGF;WACD,MAAM;WAEN,UAAU;EAEnB,YAAY;EACZ,iBAAiB;EACjB,OAAO,SAAS;;;;EAIhB;;;;EAIA;EACA,iBAAiB;IAAU;;EAC3B,iBACE,UACA;IAEA;IACA;;EAEF;EAEA,UAAU,uBAAuB;EAEjC,sBAAsB,cAAc;EACpC,2BAA2B,qBAAqB;EAEhD,qBAAqB,cAAc;IAAsB;;;cAG9C,8BAA8B;UAM/B;UACA;MANC,QAAI;cAKL,OAAO,qBACP,gBAAgB;YAkBhB;WAgBM,UAAQ;UAEhB;EAMD,YAAQ;;;;;;;;EAIR,iBAAM;EAKN,OAAO,eAAc;EAkBrB;EAKA;EAUA,iBAAiB;IAAU;;EAQ3B,iBACL,UACA;IAEA;IACA;;EAsBK;EAIA,UAAU,uBAAoB;EAI9B,sBAAsB,cAAW;EAmBjC,2BAA2B,qBAAkB;EA0B7C,qBAAqB,cAAW"}
1
+ {"version":3,"file":"message-runtime.d.ts","names":[],"sources":["../../../src/runtime/api/message-runtime.ts"],"mappings":";;;;;;;;;;cAsCa,sBACX,SAAS,eACT,mBACA,MAAM,wBAAwB,+BAC7B;KAkCS,eAAe;WAChB;;WAEA;WACA;WAEA;WACA;;;;WAKA,QAAQ;;KAKd;EACH,YAAY;;KAGF;WACD,MAAM;WAEN,UAAU;EAEnB,YAAY;EACZ,iBAAiB;EACjB,OAAO,SAAS;;;;EAIhB;;;;EAIA;EACA,iBAAiB;IAAU;;EAC3B,iBACE,UACA;IAEA;IACA;;EAEF;EAEA,UAAU,uBAAuB;EAEjC,sBAAsB,cAAc;EACpC,2BAA2B,qBAAqB;EAEhD,qBAAqB,cAAc;IAAsB;;;cAG9C,8BAA8B;MAC9B,QAAI;UAIP;UACA;EAGN,YAAA,OAAO,qBACP,gBAAgB;YAoBR;WAgBM,UAAQ;UAEhB;EAMD,YAAQ;;;;;;;;EAIR,iBAAM;EAKN,OAAO,eAAc;EAkBrB;EAKA;EAUA,iBAAiB;IAAU;;EAQ3B,iBACL,UACA;IAEA;IACA;;EAsBK;EAIA,UAAU,uBAAoB;EAI9B,sBAAsB,cAAW;EAmBjC,2BAA2B,qBAAkB;EAwB7C,qBAAqB,cAAW"}
@@ -25,18 +25,18 @@ const getMessagePartState = (message, partIndex) => {
25
25
  });
26
26
  };
27
27
  var MessageRuntimeImpl = class {
28
- _core;
29
- _threadBinding;
30
28
  get path() {
31
29
  return this._core.path;
32
30
  }
31
+ _core;
32
+ _threadBinding;
33
33
  constructor(_core, _threadBinding) {
34
34
  this._core = _core;
35
35
  this._threadBinding = _threadBinding;
36
36
  this.composer = new EditComposerRuntimeImpl(new NestedSubscriptionSubject({
37
37
  path: {
38
38
  ...this.path,
39
- ref: `${this.path.ref}${this.path.ref}.composer`,
39
+ ref: `${this.path.ref}.composer`,
40
40
  composerSource: "edit"
41
41
  },
42
42
  getState: this._getEditComposerRuntimeCore,
@@ -120,7 +120,7 @@ var MessageRuntimeImpl = class {
120
120
  return new MessagePartRuntimeImpl(new ShallowMemoizeSubject({
121
121
  path: {
122
122
  ...this.path,
123
- ref: `${this.path.ref}${this.path.ref}.content[${idx}]`,
123
+ ref: `${this.path.ref}.content[${idx}]`,
124
124
  messagePartSelector: {
125
125
  type: "index",
126
126
  index: idx
@@ -136,7 +136,7 @@ var MessageRuntimeImpl = class {
136
136
  return new MessagePartRuntimeImpl(new ShallowMemoizeSubject({
137
137
  path: {
138
138
  ...this.path,
139
- ref: this.path.ref + `${this.path.ref}.content[toolCallId=${JSON.stringify(toolCallId)}]`,
139
+ ref: `${this.path.ref}.content[toolCallId=${JSON.stringify(toolCallId)}]`,
140
140
  messagePartSelector: {
141
141
  type: "toolCallId",
142
142
  toolCallId
@@ -155,7 +155,7 @@ var MessageRuntimeImpl = class {
155
155
  return new MessageAttachmentRuntimeImpl(new ShallowMemoizeSubject({
156
156
  path: {
157
157
  ...this.path,
158
- ref: `${this.path.ref}${this.path.ref}.attachments[${idx}]`,
158
+ ref: `${this.path.ref}.attachments[${idx}]`,
159
159
  attachmentSource: "message",
160
160
  attachmentSelector: {
161
161
  type: "index",
@@ -1 +1 @@
1
- {"version":3,"file":"message-runtime.js","names":["SpeechState","symbolInnerMessage","ToolCallMessagePartStatus","ThreadMessage","ThreadAssistantMessagePart","ThreadUserMessagePart","Unsubscribe","MessagePartStatus","RunConfig","getThreadMessageText","NestedSubscriptionSubject","SKIP_UPDATE","ShallowMemoizeSubject","AttachmentRuntime","AttachmentState","MessageAttachmentRuntimeImpl","EditComposerRuntime","EditComposerRuntimeImpl","MessagePartRuntime","MessagePartRuntimeImpl","MessagePartState","MessageRuntimePath","ThreadRuntimeCoreBinding","MessageStateBinding","COMPLETE_STATUS","Object","freeze","type","toMessagePartStatus","message","partIndex","part","role","result","status","isLastPart","Math","max","content","length","getMessagePartState","MessageState","parentId","index","isLast","branchNumber","branchCount","speech","ReloadConfig","runConfig","MessageRuntime","path","composer","getState","delete","Promise","reload","config","speak","stopSpeaking","submitFeedback","switchToBranch","position","branchId","unstable_getCopyText","subscribe","callback","getMessagePartByIndex","idx","getMessagePartByToolCallId","toolCallId","getAttachmentByIndex","source","MessageRuntimeImpl","_core","constructor","_threadBinding","ref","composerSource","_getEditComposerRuntimeCore","beginEdit","id","__internal_bindMethods","bind","getEditComposer","state","deleteMessage","reloadConfig","editComposerRuntimeCore","composerRuntimeCore","Error","startRun","sourceId","thread","messageId","branches","getBranches","targetBranch","messagePartSelector","JSON","stringify","findIndex","attachmentSource","attachmentSelector","attachments","attachment"],"sources":["../../../src/runtime/api/message-runtime.ts"],"sourcesContent":["import type { SpeechState } from \"../interfaces/thread-runtime-core\";\nimport { symbolInnerMessage } from \"../utils/external-store-message\";\nimport type {\n ToolCallMessagePartStatus,\n ThreadMessage,\n ThreadAssistantMessagePart,\n ThreadUserMessagePart,\n} from \"../../types/message\";\nimport type { Unsubscribe } from \"../../types/unsubscribe\";\nimport type { MessagePartStatus, RunConfig } from \"../../types/message\";\nimport { getThreadMessageText } from \"../../utils/text\";\nimport { NestedSubscriptionSubject } from \"../../subscribable/subscribable\";\nimport {\n SKIP_UPDATE,\n ShallowMemoizeSubject,\n} from \"../../subscribable/subscribable\";\nimport {\n type AttachmentRuntime,\n type AttachmentState,\n MessageAttachmentRuntimeImpl,\n} from \"./attachment-runtime\";\nimport {\n type EditComposerRuntime,\n EditComposerRuntimeImpl,\n} from \"./composer-runtime\";\nimport {\n type MessagePartRuntime,\n MessagePartRuntimeImpl,\n type MessagePartState,\n} from \"./message-part-runtime\";\nimport type { MessageRuntimePath } from \"./paths\";\nimport type { ThreadRuntimeCoreBinding } from \"./thread-runtime\";\nimport type { MessageStateBinding } from \"./bindings\";\n\nconst COMPLETE_STATUS: MessagePartStatus = Object.freeze({\n type: \"complete\",\n});\n\nexport const toMessagePartStatus = (\n message: ThreadMessage,\n partIndex: number,\n part: ThreadUserMessagePart | ThreadAssistantMessagePart,\n): ToolCallMessagePartStatus => {\n if (message.role !== \"assistant\") return COMPLETE_STATUS;\n\n if (part.type === \"tool-call\") {\n if (!part.result) {\n return message.status as ToolCallMessagePartStatus;\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 MessagePartStatus) : COMPLETE_STATUS;\n};\n\nconst getMessagePartState = (\n message: MessageState,\n partIndex: number,\n): MessagePartState | SKIP_UPDATE => {\n const part = message.content[partIndex];\n if (!part) {\n return SKIP_UPDATE;\n }\n\n // if the message part is the same, don't update\n const status = toMessagePartStatus(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 /** The position of this message in the thread (0 for first message) */\n readonly index: number;\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};\n\nexport type { MessageStateBinding } from \"./bindings\";\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 delete(): void | Promise<void>;\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 getMessagePartByIndex(idx: number): MessagePartRuntime;\n getMessagePartByToolCallId(toolCallId: string): MessagePartRuntime;\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 this.__internal_bindMethods();\n }\n\n protected __internal_bindMethods() {\n this.reload = this.reload.bind(this);\n this.delete = this.delete.bind(this);\n this.getState = this.getState.bind(this);\n this.subscribe = this.subscribe.bind(this);\n this.getMessagePartByIndex = this.getMessagePartByIndex.bind(this);\n this.getMessagePartByToolCallId =\n this.getMessagePartByToolCallId.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 delete() {\n const state = this._core.getState();\n return this._threadBinding.getState().deleteMessage(state.id);\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 getMessagePartByIndex(idx: number) {\n if (idx < 0) throw new Error(\"Message part index must be >= 0\");\n return new MessagePartRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n ref: `${this.path.ref}${this.path.ref}.content[${idx}]`,\n messagePartSelector: { type: \"index\", index: idx },\n },\n getState: () => {\n return getMessagePartState(this.getState(), idx);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n this._threadBinding,\n );\n }\n\n public getMessagePartByToolCallId(toolCallId: string) {\n return new MessagePartRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n ref:\n this.path.ref +\n `${this.path.ref}.content[toolCallId=${JSON.stringify(toolCallId)}]`,\n messagePartSelector: { 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 getMessagePartState(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":";;;;;;;AAkCA,MAAMwB,kBAAqCC,OAAOC,OAAO,EACvDC,MAAM,WACR,CAAC;AAED,MAAaC,uBACXC,SACAC,WACAC,SAC8B;CAC9B,IAAIF,QAAQG,SAAS,aAAa,OAAOR;CAEzC,IAAIO,KAAKJ,SAAS,aAChB,IAAI,CAACI,KAAKE,QACR,OAAOJ,QAAQK;MAEf,OAAOV;CAIX,MAAMW,aAAaL,cAAcM,KAAKC,IAAI,GAAGR,QAAQS,QAAQC,SAAS,CAAC;CACvE,IAAIV,QAAQK,OAAOP,SAAS,mBAAmB,OAAOH;CACtD,OAAOW,aAAcN,QAAQK,SAA+BV;AAC9D;AAEA,MAAMgB,uBACJX,SACAC,cACmC;CACnC,MAAMC,OAAOF,QAAQS,QAAQR;CAC7B,IAAI,CAACC,MACH,OAAOpB;CAIT,MAAMuB,SAASN,oBAAoBC,SAASC,WAAWC,IAAI;CAC3D,OAAON,OAAOC,OAAO;EACnB,GAAGK;GACG9B,qBAAsB8B,KAAa9B;EACzCiC;CACF,CAAC;AACH;AAyDA,IAAauC,qBAAb,MAA0D;CAM9CC;CACAE;CANV,IAAWzB,OAAO;EAChB,OAAO,KAAKuB,MAAMvB;CACpB;CAEAwB,YACE,OACA,gBACA;EAFQD,KAAAA,QAAAA;EACAE,KAAAA,iBAAAA;EAER,KAAKxB,WAAW,IAAInC,wBAClB,IAAIP,0BAA0B;GAC5ByC,MAAM;IACJ,GAAG,KAAKA;IACR0B,KAAK,GAAG,KAAK1B,KAAK0B,MAAM,KAAK1B,KAAK0B,IAAG;IACrCC,gBAAgB;G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AAa,KAAKQ,MAAMT,UAAUC,QAAQ;EACxD,CAAC,GACD,KAAKQ,OACL,KAAKE,cACP;CACF;CAEA,qBAA4BR,KAAa;EACvC,OAAO,IAAIrD,6BACT,IAAIH,sBAAsB;GACxBuC,MAAM;IACJ,GAAG,KAAKA;IACR0B,KAAK,GAAG,KAAK1B,KAAK0B,MAAM,KAAK1B,KAAK0B,IAAG,eAAgBT,IAAG;IACxDkC,kBAAkB;IAClBC,oBAAoB;KAAE5E,MAAM;KAASgB,OAAOyB;IAAI;GAClD;GACAf,gBAAgB;IAEd,MAAMoD,aADc,KAAKpD,SAAS,CAAC,CAACmD,cACHpC;IACjC,IAAI,CAACqC,YAAY,OAAO9F;IAExB,OAAO;KACL,GAAG8F;KACHjC,QAAQ;IACV;GACF;GACAP,YAAYC,aAAa,KAAKQ,MAAMT,UAAUC,QAAQ;EACxD,CAAC,CACH;CACF;AACF"}
1
+ {"version":3,"file":"message-runtime.js","names":["SpeechState","symbolInnerMessage","ToolCallMessagePartStatus","ThreadMessage","ThreadAssistantMessagePart","ThreadUserMessagePart","Unsubscribe","MessagePartStatus","RunConfig","getThreadMessageText","NestedSubscriptionSubject","SKIP_UPDATE","ShallowMemoizeSubject","AttachmentRuntime","AttachmentState","MessageAttachmentRuntimeImpl","EditComposerRuntime","EditComposerRuntimeImpl","MessagePartRuntime","MessagePartRuntimeImpl","MessagePartState","MessageRuntimePath","ThreadRuntimeCoreBinding","MessageStateBinding","COMPLETE_STATUS","Object","freeze","type","toMessagePartStatus","message","partIndex","part","role","result","status","isLastPart","Math","max","content","length","getMessagePartState","MessageState","parentId","index","isLast","branchNumber","branchCount","speech","ReloadConfig","runConfig","MessageRuntime","path","composer","getState","delete","Promise","reload","config","speak","stopSpeaking","submitFeedback","switchToBranch","position","branchId","unstable_getCopyText","subscribe","callback","getMessagePartByIndex","idx","getMessagePartByToolCallId","toolCallId","getAttachmentByIndex","source","MessageRuntimeImpl","_core","_threadBinding","constructor","ref","composerSource","_getEditComposerRuntimeCore","beginEdit","id","__internal_bindMethods","bind","getEditComposer","state","deleteMessage","reloadConfig","editComposerRuntimeCore","composerRuntimeCore","Error","startRun","sourceId","thread","messageId","branches","getBranches","targetBranch","messagePartSelector","JSON","stringify","findIndex","attachmentSource","attachmentSelector","attachments","attachment"],"sources":["../../../src/runtime/api/message-runtime.ts"],"sourcesContent":["import type { SpeechState } from \"../interfaces/thread-runtime-core\";\nimport { symbolInnerMessage } from \"../utils/external-store-message\";\nimport type {\n ToolCallMessagePartStatus,\n ThreadMessage,\n ThreadAssistantMessagePart,\n ThreadUserMessagePart,\n} from \"../../types/message\";\nimport type { Unsubscribe } from \"../../types/unsubscribe\";\nimport type { MessagePartStatus, RunConfig } from \"../../types/message\";\nimport { getThreadMessageText } from \"../../utils/text\";\nimport { NestedSubscriptionSubject } from \"../../subscribable/subscribable\";\nimport {\n SKIP_UPDATE,\n ShallowMemoizeSubject,\n} from \"../../subscribable/subscribable\";\nimport {\n type AttachmentRuntime,\n type AttachmentState,\n MessageAttachmentRuntimeImpl,\n} from \"./attachment-runtime\";\nimport {\n type EditComposerRuntime,\n EditComposerRuntimeImpl,\n} from \"./composer-runtime\";\nimport {\n type MessagePartRuntime,\n MessagePartRuntimeImpl,\n type MessagePartState,\n} from \"./message-part-runtime\";\nimport type { MessageRuntimePath } from \"./paths\";\nimport type { ThreadRuntimeCoreBinding } from \"./thread-runtime\";\nimport type { MessageStateBinding } from \"./bindings\";\n\nconst COMPLETE_STATUS: MessagePartStatus = Object.freeze({\n type: \"complete\",\n});\n\nexport const toMessagePartStatus = (\n message: ThreadMessage,\n partIndex: number,\n part: ThreadUserMessagePart | ThreadAssistantMessagePart,\n): ToolCallMessagePartStatus => {\n if (message.role !== \"assistant\") return COMPLETE_STATUS;\n\n if (part.type === \"tool-call\") {\n if (!part.result) {\n return message.status as ToolCallMessagePartStatus;\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 MessagePartStatus) : COMPLETE_STATUS;\n};\n\nconst getMessagePartState = (\n message: MessageState,\n partIndex: number,\n): MessagePartState | SKIP_UPDATE => {\n const part = message.content[partIndex];\n if (!part) {\n return SKIP_UPDATE;\n }\n\n // if the message part is the same, don't update\n const status = toMessagePartStatus(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 /** The position of this message in the thread (0 for first message) */\n readonly index: number;\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};\n\nexport type { MessageStateBinding } from \"./bindings\";\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 delete(): void | Promise<void>;\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 getMessagePartByIndex(idx: number): MessagePartRuntime;\n getMessagePartByToolCallId(toolCallId: string): MessagePartRuntime;\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 private _core: MessageStateBinding;\n private _threadBinding: ThreadRuntimeCoreBinding;\n\n constructor(\n _core: MessageStateBinding,\n _threadBinding: ThreadRuntimeCoreBinding,\n ) {\n this._core = _core;\n this._threadBinding = _threadBinding;\n this.composer = new EditComposerRuntimeImpl(\n new NestedSubscriptionSubject({\n path: {\n ...this.path,\n 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 this.__internal_bindMethods();\n }\n\n protected __internal_bindMethods() {\n this.reload = this.reload.bind(this);\n this.delete = this.delete.bind(this);\n this.getState = this.getState.bind(this);\n this.subscribe = this.subscribe.bind(this);\n this.getMessagePartByIndex = this.getMessagePartByIndex.bind(this);\n this.getMessagePartByToolCallId =\n this.getMessagePartByToolCallId.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 delete() {\n const state = this._core.getState();\n return this._threadBinding.getState().deleteMessage(state.id);\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 getMessagePartByIndex(idx: number) {\n if (idx < 0) throw new Error(\"Message part index must be >= 0\");\n return new MessagePartRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n ref: `${this.path.ref}.content[${idx}]`,\n messagePartSelector: { type: \"index\", index: idx },\n },\n getState: () => {\n return getMessagePartState(this.getState(), idx);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n this._threadBinding,\n );\n }\n\n public getMessagePartByToolCallId(toolCallId: string) {\n return new MessagePartRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n ref: `${this.path.ref}.content[toolCallId=${JSON.stringify(toolCallId)}]`,\n messagePartSelector: { 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 getMessagePartState(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}.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":";;;;;;;AAkCA,MAAMwB,kBAAqCC,OAAOC,OAAO,EACvDC,MAAM,WACR,CAAC;AAED,MAAaC,uBACXC,SACAC,WACAC,SAC8B;CAC9B,IAAIF,QAAQG,SAAS,aAAa,OAAOR;CAEzC,IAAIO,KAAKJ,SAAS,aAChB,IAAI,CAACI,KAAKE,QACR,OAAOJ,QAAQK;MAEf,OAAOV;CAIX,MAAMW,aAAaL,cAAcM,KAAKC,IAAI,GAAGR,QAAQS,QAAQC,SAAS,CAAC;CACvE,IAAIV,QAAQK,OAAOP,SAAS,mBAAmB,OAAOH;CACtD,OAAOW,aAAcN,QAAQK,SAA+BV;AAC9D;AAEA,MAAMgB,uBACJX,SACAC,cACmC;CACnC,MAAMC,OAAOF,QAAQS,QAAQR;CAC7B,IAAI,CAACC,MACH,OAAOpB;CAIT,MAAMuB,SAASN,oBAAoBC,SAASC,WAAWC,IAAI;CAC3D,OAAON,OAAOC,OAAO;EACnB,GAAGK;GACG9B,qBAAsB8B,KAAa9B;EACzCiC;CACF,CAAC;AACH;AAyDA,IAAauC,qBAAb,MAA0D;CACxD,IAAWtB,OAAO;EAChB,OAAO,KAAKuB,MAAMvB;CACpB;CAEA;CACA;CAEAyB,YACEF,OACAC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BtE,SACCA,KAAKJ,SAAS,eAAeI,KAAKuC,eAAeA,UACrD;IACA,IAAIF,QAAQ,IAAI,OAAOzD;IACvB,OAAO6B,oBAAoB6C,OAAOjB,GAAG;GACvC;GACAH,YAAYC,aAAa,KAAKQ,MAAMT,UAAUC,QAAQ;EACxD,CAAC,GACD,KAAKQ,OACL,KAAKC,cACP;CACF;CAEA,qBAA4BP,KAAa;EACvC,OAAO,IAAIrD,6BACT,IAAIH,sBAAsB;GACxBuC,MAAM;IACJ,GAAG,KAAKA;IACR0B,KAAK,GAAG,KAAK1B,KAAK0B,IAAG,eAAgBT,IAAG;IACxCkC,kBAAkB;IAClBC,oBAAoB;KAAE5E,MAAM;KAASgB,OAAOyB;IAAI;GAClD;GACAf,gBAAgB;IAEd,MAAMoD,aADc,KAAKpD,SAAS,CAAC,CAACmD,cACHpC;IACjC,IAAI,CAACqC,YAAY,OAAO9F;IAExB,OAAO;KACL,GAAG8F;KACHjC,QAAQ;IACV;GACF;GACAP,YAAYC,aAAa,KAAKQ,MAAMT,UAAUC,QAAQ;EACxD,CAAC,CACH;CACF;AACF"}
@@ -44,9 +44,9 @@ type ThreadListItemRuntime = {
44
44
  };
45
45
  type ThreadListItemStateBinding = SubscribableWithState<ThreadListItemState, ThreadListItemRuntimePath>;
46
46
  declare class ThreadListItemRuntimeImpl implements ThreadListItemRuntime {
47
+ get path(): ThreadListItemRuntimePath;
47
48
  private _core;
48
49
  private _threadListBinding;
49
- get path(): ThreadListItemRuntimePath;
50
50
  constructor(_core: ThreadListItemStateBinding, _threadListBinding: ThreadListRuntimeCoreBinding);
51
51
  protected __internal_bindMethods(): void;
52
52
  getState(): ThreadListItemState;
@@ -1 +1 @@
1
- {"version":3,"file":"thread-list-item-runtime.d.ts","names":[],"sources":["../../../src/runtime/api/thread-list-item-runtime.ts"],"mappings":";;;;;;;KAKY;;;;;;EAMV,YAAY;;;;;;EAMZ,cAAc;;KAGJ,gCAAgC;KAEhC,4BAA4B,UAAU,4BAChD,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P,oBAAoB;YAOZ;EAeH,YAAY;EAIZ,SAAS;IAAY;MAAwB;EAK7C,OAAO,mBAAmB;EAM1B,aACL,QAAQ,sCACP;EAWI,WAAW;EAMX,aAAa;EAMb,UAAU;EAMV,cAAc;IACnB;IACA;;EAMK,iBAAiB;EAKjB,YAAY,UAAU,yBAC3B,OAAO,GACP,UAAU,4BAA4B,KAAE;EAsBnC,UAAU,uBAAuB;EAIjC;EAMA,yBAAyB"}
@@ -1,10 +1,11 @@
1
+ import { notifyEventListeners } from "../../utils/notify-event-listeners.js";
1
2
  //#region src/runtime/api/thread-list-item-runtime.ts
2
3
  var ThreadListItemRuntimeImpl = class {
3
- _core;
4
- _threadListBinding;
5
4
  get path() {
6
5
  return this._core.path;
7
6
  }
7
+ _core;
8
+ _threadListBinding;
8
9
  constructor(_core, _threadListBinding) {
9
10
  this._core = _core;
10
11
  this._threadListBinding = _threadListBinding;
@@ -72,7 +73,7 @@ var ThreadListItemRuntimeImpl = class {
72
73
  prevThreadId = newThreadId;
73
74
  if (event === "switchedTo" && !newIsMain) return;
74
75
  if (event === "switchedAway" && newIsMain) return;
75
- callback({});
76
+ notifyEventListeners([callback], {}, `Thread list item "${event}"`);
76
77
  });
77
78
  }
78
79
  subscribe(callback) {
@@ -1 +1 @@
1
- {"version":3,"file":"thread-list-item-runtime.js","names":["Unsubscribe","SubscribableWithState","ThreadListItemRuntimePath","ThreadListRuntimeCoreBinding","ThreadListItemEventPayload","switchedTo","Record","switchedAway","ThreadListItemEventType","ThreadListItemEventCallback","payload","E","ThreadListItemState","ThreadListItemStatus","ThreadListItemRuntime","path","getState","initialize","Promise","remoteId","externalId","generateTitle","switchTo","options","unarchive","rename","newTitle","updateCustom","custom","archive","delete","detach","subscribe","callback","unstable_on","event","__internal_getRuntime","ThreadListItemStateBinding","ThreadListItemRuntimeImpl","_core","constructor","_threadListBinding","__internal_bindMethods","bind","state","switchToThread","id","Error","prevIsMain","isMain","prevThreadId","currentState","newIsMain","newThreadId"],"sources":["../../../src/runtime/api/thread-list-item-runtime.ts"],"sourcesContent":["import type { Unsubscribe } from \"../../types/unsubscribe\";\nimport type { SubscribableWithState } from \"../../subscribable/subscribable\";\nimport type { ThreadListItemRuntimePath } from \"./paths\";\nimport type { ThreadListRuntimeCoreBinding } from \"./thread-list-runtime\";\n\nexport type ThreadListItemEventPayload = {\n /**\n * @deprecated State-derivable. Compare `s.threads.mainThreadId` against the\n * item's `s.threadListItem.id` via `useAuiState` instead. Kept for backward\n * compatibility.\n */\n switchedTo: Record<string, never>;\n /**\n * @deprecated State-derivable. Compare `s.threads.mainThreadId` against the\n * item's `s.threadListItem.id` via `useAuiState` instead. Kept for backward\n * compatibility.\n */\n switchedAway: Record<string, never>;\n};\n\nexport type ThreadListItemEventType = keyof ThreadListItemEventPayload;\n\nexport type ThreadListItemEventCallback<E extends ThreadListItemEventType> = (\n payload: ThreadListItemEventPayload[E],\n) => void;\n\nimport type { ThreadListItemState } from \"./bindings\";\nimport type { ThreadListItemStatus } from \"../interfaces/thread-list-runtime-core\";\n\nexport type { ThreadListItemState, ThreadListItemStatus };\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(options?: { unarchive?: boolean }): Promise<void>;\n rename(newTitle: string): Promise<void>;\n updateCustom(custom: Record<string, unknown> | undefined): Promise<void>;\n archive(): Promise<void>;\n unarchive(): Promise<void>;\n delete(): Promise<void>;\n\n detach(): void;\n\n subscribe(callback: () => void): Unsubscribe;\n\n unstable_on<E extends ThreadListItemEventType>(\n event: E,\n callback: ThreadListItemEventCallback<E>,\n ): Unsubscribe;\n\n __internal_getRuntime(): ThreadListItemRuntime;\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 this.__internal_bindMethods();\n }\n\n protected __internal_bindMethods() {\n this.switchTo = this.switchTo.bind(this);\n this.rename = this.rename.bind(this);\n this.updateCustom = this.updateCustom.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 this.detach = this.detach.bind(this);\n }\n\n public getState(): ThreadListItemState {\n return this._core.getState();\n }\n\n public switchTo(options?: { unarchive?: boolean }): Promise<void> {\n const state = this._core.getState();\n return this._threadListBinding.switchToThread(state.id, options);\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 updateCustom(\n custom: Record<string, unknown> | undefined,\n ): Promise<void> {\n const state = this._core.getState();\n if (!this._threadListBinding.updateCustom) {\n throw new Error(\n \"Thread list runtime does not support updating custom metadata\",\n );\n }\n\n return this._threadListBinding.updateCustom(state.id, custom);\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<E extends ThreadListItemEventType>(\n event: E,\n callback: ThreadListItemEventCallback<E>,\n ) {\n let prevIsMain = this._core.getState().isMain;\n let prevThreadId = this._core.getState().id;\n return this.subscribe(() => {\n const currentState = this._core.getState();\n const newIsMain = currentState.isMain;\n const newThreadId = currentState.id;\n if (prevIsMain === newIsMain && prevThreadId === newThreadId) return;\n prevIsMain = newIsMain;\n prevThreadId = newThreadId;\n\n if (event === \"switchedTo\" && !newIsMain) return;\n if (event === \"switchedAway\" && newIsMain) return;\n (callback as (payload?: unknown) => void)({});\n });\n }\n\n public subscribe(callback: () => void): Unsubscribe {\n return this._core.subscribe(callback);\n }\n\n public detach(): void {\n const state = this._core.getState();\n\n this._threadListBinding.detach(state.id);\n }\n\n public __internal_getRuntime(): ThreadListItemRuntime {\n return this;\n }\n}\n"],"mappings":";AA8DA,IAAasC,4BAAb,MAAwE;CAM5DC;CACAE;CANV,IAAW1B,OAAO;EAChB,OAAO,KAAKwB,MAAMxB;CACpB;CAEAyB,YACE,OACA,oBACA;EAFQD,KAAAA,QAAAA;EACAE,KAAAA,qBAAAA;EAER,KAAKC,uBAAuB;CAC9B;CAEA,yBAAmC;EACjC,KAAKpB,WAAW,KAAKA,SAASqB,KAAK,IAAI;EACvC,KAAKlB,SAAS,KAAKA,OAAOkB,KAAK,IAAI;EACnC,KAAKhB,eAAe,KAAKA,aAAagB,KAAK,IAAI;EAC/C,KAAKd,UAAU,KAAKA,QAAQc,KAAK,IAAI;EACrC,KAAKnB,YAAY,KAAKA,UAAUmB,KAAK,IAAI;EACzC,KAAKb,SAAS,KAAKA,OAAOa,KAAK,IAAI;EACnC,KAAK1B,aAAa,KAAKA,WAAW0B,KAAK,IAAI;EAC3C,KAAKtB,gBAAgB,KAAKA,cAAcsB,KAAK,IAAI;EACjD,KAAKX,YAAY,KAAKA,UAAUW,KAAK,IAAI;EACzC,KAAKT,cAAc,KAAKA,YAAYS,KAAK,IAAI;EAC7C,KAAK3B,WAAW,KAAKA,SAAS2B,KAAK,IAAI;EACvC,KAAKZ,SAAS,KAAKA,OAAOY,KAAK,IAAI;CACrC;CAEA,WAAuC;EACrC,OAAO,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AKZ,MAAMvB,SAAS;GACzC,MAAMoC,YAAYD,aAAaF;GAC/B,MAAMI,cAAcF,aAAaL;GACjC,IAAIE,eAAeI,aAAaF,iBAAiBG,aAAa;GAC9DL,aAAaI;GACbF,eAAeG;GAEf,IAAIlB,UAAU,gBAAgB,CAACiB,WAAW;GAC1C,IAAIjB,UAAU,kBAAkBiB,WAAW;GAC3C,SAA0C,CAAC,CAAC;EAC9C,CAAC;CACH;CAEA,UAAiBnB,UAAmC;EAClD,OAAO,KAAKM,MAAMP,UAAUC,QAAQ;CACtC;CAEA,SAAsB;EACpB,MAAMW,QAAQ,KAAKL,MAAMvB,SAAS;EAElC,KAAKyB,mBAAmBV,OAAOa,MAAME,EAAE;CACzC;CAEA,wBAAsD;EACpD,OAAO;CACT;AACF"}
1
+ {"version":3,"file":"thread-list-item-runtime.js","names":["Unsubscribe","SubscribableWithState","ThreadListItemRuntimePath","ThreadListRuntimeCoreBinding","notifyEventListeners","ThreadListItemEventPayload","switchedTo","Record","switchedAway","ThreadListItemEventType","ThreadListItemEventCallback","payload","E","ThreadListItemState","ThreadListItemStatus","ThreadListItemRuntime","path","getState","initialize","Promise","remoteId","externalId","generateTitle","switchTo","options","unarchive","rename","newTitle","updateCustom","custom","archive","delete","detach","subscribe","callback","unstable_on","event","__internal_getRuntime","ThreadListItemStateBinding","ThreadListItemRuntimeImpl","_core","_threadListBinding","constructor","__internal_bindMethods","bind","state","switchToThread","id","Error","prevIsMain","isMain","prevThreadId","currentState","newIsMain","newThreadId"],"sources":["../../../src/runtime/api/thread-list-item-runtime.ts"],"sourcesContent":["import type { Unsubscribe } from \"../../types/unsubscribe\";\nimport type { SubscribableWithState } from \"../../subscribable/subscribable\";\nimport type { ThreadListItemRuntimePath } from \"./paths\";\nimport type { ThreadListRuntimeCoreBinding } from \"./thread-list-runtime\";\nimport { notifyEventListeners } from \"../../utils/notify-event-listeners\";\n\nexport type ThreadListItemEventPayload = {\n /**\n * @deprecated State-derivable. Compare `s.threads.mainThreadId` against the\n * item's `s.threadListItem.id` via `useAuiState` instead. Kept for backward\n * compatibility.\n */\n switchedTo: Record<string, never>;\n /**\n * @deprecated State-derivable. Compare `s.threads.mainThreadId` against the\n * item's `s.threadListItem.id` via `useAuiState` instead. Kept for backward\n * compatibility.\n */\n switchedAway: Record<string, never>;\n};\n\nexport type ThreadListItemEventType = keyof ThreadListItemEventPayload;\n\nexport type ThreadListItemEventCallback<E extends ThreadListItemEventType> = (\n payload: ThreadListItemEventPayload[E],\n) => void;\n\nimport type { ThreadListItemState } from \"./bindings\";\nimport type { ThreadListItemStatus } from \"../interfaces/thread-list-runtime-core\";\n\nexport type { ThreadListItemState, ThreadListItemStatus };\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(options?: { unarchive?: boolean }): Promise<void>;\n rename(newTitle: string): Promise<void>;\n updateCustom(custom: Record<string, unknown> | undefined): Promise<void>;\n archive(): Promise<void>;\n unarchive(): Promise<void>;\n delete(): Promise<void>;\n\n detach(): void;\n\n subscribe(callback: () => void): Unsubscribe;\n\n unstable_on<E extends ThreadListItemEventType>(\n event: E,\n callback: ThreadListItemEventCallback<E>,\n ): Unsubscribe;\n\n __internal_getRuntime(): ThreadListItemRuntime;\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 private _core: ThreadListItemStateBinding;\n private _threadListBinding: ThreadListRuntimeCoreBinding;\n\n constructor(\n _core: ThreadListItemStateBinding,\n _threadListBinding: ThreadListRuntimeCoreBinding,\n ) {\n this._core = _core;\n this._threadListBinding = _threadListBinding;\n this.__internal_bindMethods();\n }\n\n protected __internal_bindMethods() {\n this.switchTo = this.switchTo.bind(this);\n this.rename = this.rename.bind(this);\n this.updateCustom = this.updateCustom.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 this.detach = this.detach.bind(this);\n }\n\n public getState(): ThreadListItemState {\n return this._core.getState();\n }\n\n public switchTo(options?: { unarchive?: boolean }): Promise<void> {\n const state = this._core.getState();\n return this._threadListBinding.switchToThread(state.id, options);\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 updateCustom(\n custom: Record<string, unknown> | undefined,\n ): Promise<void> {\n const state = this._core.getState();\n if (!this._threadListBinding.updateCustom) {\n throw new Error(\n \"Thread list runtime does not support updating custom metadata\",\n );\n }\n\n return this._threadListBinding.updateCustom(state.id, custom);\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<E extends ThreadListItemEventType>(\n event: E,\n callback: ThreadListItemEventCallback<E>,\n ) {\n let prevIsMain = this._core.getState().isMain;\n let prevThreadId = this._core.getState().id;\n return this.subscribe(() => {\n const currentState = this._core.getState();\n const newIsMain = currentState.isMain;\n const newThreadId = currentState.id;\n if (prevIsMain === newIsMain && prevThreadId === newThreadId) return;\n prevIsMain = newIsMain;\n prevThreadId = newThreadId;\n\n if (event === \"switchedTo\" && !newIsMain) return;\n if (event === \"switchedAway\" && newIsMain) return;\n notifyEventListeners(\n [callback as (payload?: unknown) => void],\n {},\n `Thread list item \"${event}\"`,\n );\n });\n }\n\n public subscribe(callback: () => void): Unsubscribe {\n return this._core.subscribe(callback);\n }\n\n public detach(): void {\n const state = this._core.getState();\n\n this._threadListBinding.detach(state.id);\n }\n\n public __internal_getRuntime(): ThreadListItemRuntime {\n return this;\n }\n}\n"],"mappings":";;AA+DA,IAAauC,4BAAb,MAAwE;CACtE,IAAWvB,OAAO;EAChB,OAAO,KAAKwB,MAAMxB;CACpB;CAEA;CACA;CAEA0B,YACEF,OACAC,oBACA;EACA,KAAKD,QAAQA;EACb,KAAKC,qBAAqBA;EAC1B,KAAKE,uBAAuB;CAC9B;CAEA,yBAAmC;EACjC,KAAKpB,WAAW,KAAKA,SAASqB,KAAK,IAAI;EACvC,KAAKlB,SAAS,KAAKA,OAAOkB,KAAK,IAAI;EACnC,KAAKhB,eAAe,KAAKA,aAAagB,KAAK,IAAI;EAC/C,KAAKd,UAAU,KAAKA,QAAQc,KAAK,IAAI;EACrC,KAAKnB,YAAY,KAAKA,UAAUmB,KAAK,IAAI;EACzC,KAAKb,SAAS,KAAKA,OAAOa,KAAK,IAAI;EACnC,KAAK1B,aAAa,KAAKA,WAAW0B,KAAK,IAAI;EAC3C,KAAKtB,gBAAgB,KAAKA,cAAcsB,KAAK,IAAI;EACjD,KAAKX,YAAY,KAAKA,UAAUW,KAAK,IAAI;EACzC,KAAKT,cAAc,KAAKA,YAAYS,KAAK,IAAI;EAC7C,KAAK3B,WAAW,KAAKA,SAAS2B,KAAK,IAAI;EACvC,KAAKZ,SAAS,KAAKA,OAAOY,KAAK,IAAI;CACrC;CAEA,WAAuC;EACrC,OAAO,KAAKJ,MAAMvB,SAAS;CAC7B;CAEA,SAAgBO,SAAkD;EAChE,MAAMqB,QAAQ,KAAKL,MAAMvB,SAAS;EAClC,OAAO,KAAKwB,mBAAmB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9DL,aAAaI;GACbF,eAAeG;GAEf,IAAIlB,UAAU,gBAAgB,CAACiB,WAAW;GAC1C,IAAIjB,UAAU,kBAAkBiB,WAAW;GAC3CjD,qBACE,CAAC8B,QAAuC,GACxC,CAAC,GACD,qBAAqBE,MAAK,EAC5B;EACF,CAAC;CACH;CAEA,UAAiBF,UAAmC;EAClD,OAAO,KAAKM,MAAMP,UAAUC,QAAQ;CACtC;CAEA,SAAsB;EACpB,MAAMW,QAAQ,KAAKL,MAAMvB,SAAS;EAElC,KAAKwB,mBAAmBT,OAAOa,MAAME,EAAE;CACzC;CAEA,wBAAsD;EACpD,OAAO;CACT;AACF"}
@@ -33,9 +33,9 @@ type ThreadListRuntime = {
33
33
  };
34
34
  type ThreadListRuntimeCoreBinding = ThreadListRuntimeCore;
35
35
  declare class ThreadListRuntimeImpl implements ThreadListRuntime {
36
+ private _getState;
36
37
  private _core;
37
38
  private _runtimeFactory;
38
- private _getState;
39
39
  constructor(_core: ThreadListRuntimeCoreBinding, _runtimeFactory?: new (binding: ThreadRuntimeCoreBinding, threadListItemBinding: ThreadListItemRuntimeBinding) => ThreadRuntime);
40
40
  protected __internal_bindMethods(): void;
41
41
  switchToThread(threadId: string, options?: {
@@ -1 +1 @@
1
- {"version":3,"file":"thread-list-runtime.d.ts","names":[],"sources":["../../../src/runtime/api/thread-list-runtime.ts"],"mappings":";;;;;;KAwBY;WACD;WACA;WACA;WACA;WACA;WACA;WACA;WACA,aAAa,SACpB,eAAe,KAAK;;KAIZ;EACV,YAAY;EAEZ,UAAU,uBAAuB;WAExB,MAAM;EACf,QAAQ,mBAAmB;WAElB,UAAU;EACnB,YAAY,mBAAmB;EAC/B,eAAe,cAAc;EAC7B,uBAAuB,cAAc;EAErC,eACE,kBACA;IAAY;MACX;EACH,qBAAqB;EAErB,yBAAyB;EACzB,UAAU;EACV,YAAY;;KAsCF,+BAA+B;cAE9B,iCAAiC;UAGlC;UACA;UAHF;cAEE,OAAO,8BACP,uBACN,SAAS,0BACT,uBAAuB,iCACpB;YAuCG;EAcH,eACL,kBACA;IAAY;MACX;EAII,qBAAqB;EAIrB,yBAAyB;EAIzB,UAAU;EAIV,YAAY;EAIZ,YAAY;EAIZ,UAAU,uBAAuB;UAIhC;WAEQ,MAAM;MAEX,YAAQ;EAIZ,QAAQ,mBAAgB;EAcxB,eAAe,cAAW;EAgB1B,uBAAuB,cAAW;EAmBlC,YAAY,mBAAgB"}
1
+ {"version":3,"file":"thread-list-runtime.d.ts","names":[],"sources":["../../../src/runtime/api/thread-list-runtime.ts"],"mappings":";;;;;;KAwBY;WACD;WACA;WACA;WACA;WACA;WACA;WACA;WACA,aAAa,SACpB,eAAe,KAAK;;KAIZ;EACV,YAAY;EAEZ,UAAU,uBAAuB;WAExB,MAAM;EACf,QAAQ,mBAAmB;WAElB,UAAU;EACnB,YAAY,mBAAmB;EAC/B,eAAe,cAAc;EAC7B,uBAAuB,cAAc;EAErC,eACE,kBACA;IAAY;MACX;EACH,qBAAqB;EAErB,yBAAyB;EACzB,UAAU;EACV,YAAY;;KAsCF,+BAA+B;cAE9B,iCAAiC;UACpC;UACA;UACA;EAMN,YAAA,OAAO,8BACP,uBACE,SAAS,0BACT,uBAAuB,iCACpB;YAyCG;EAcH,eACL,kBACA;IAAY;MACX;EAII,qBAAqB;EAIrB,yBAAyB;EAIzB,UAAU;EAIV,YAAY;EAIZ,YAAY;EAIZ,UAAU,uBAAuB;UAIhC;WAEQ,MAAM;MAEX,YAAQ;EAIZ,QAAQ,mBAAgB;EAcxB,eAAe,cAAW;EAgB1B,uBAAuB,cAAW;EAmBlC,YAAY,mBAAgB"}
@@ -31,9 +31,9 @@ const getThreadListItemState = (threadList, threadId) => {
31
31
  };
32
32
  };
33
33
  var ThreadListRuntimeImpl = class {
34
+ _getState;
34
35
  _core;
35
36
  _runtimeFactory;
36
- _getState;
37
37
  constructor(_core, _runtimeFactory = ThreadRuntimeImpl) {
38
38
  this._core = _core;
39
39
  this._runtimeFactory = _runtimeFactory;