@assistant-ui/core 0.2.14 → 0.2.16

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 (323) hide show
  1. package/dist/adapters/attachment.js.map +1 -1
  2. package/dist/adapters/directive-formatter.js.map +1 -1
  3. package/dist/adapters/speech.js.map +1 -1
  4. package/dist/adapters/voice.js.map +1 -1
  5. package/dist/index.d.ts +2 -2
  6. package/dist/index.js.map +1 -1
  7. package/dist/internal/duplicate-detection.js.map +1 -1
  8. package/dist/internal.d.ts +2 -1
  9. package/dist/internal.js +2 -1
  10. package/dist/model-context/frame/host.js.map +1 -1
  11. package/dist/model-context/frame/provider.js.map +1 -1
  12. package/dist/model-context/frame/types.js.map +1 -1
  13. package/dist/model-context/registry.js.map +1 -1
  14. package/dist/model-context/tool.js.map +1 -1
  15. package/dist/model-context/types.d.ts +1 -0
  16. package/dist/model-context/types.d.ts.map +1 -1
  17. package/dist/model-context/types.js.map +1 -1
  18. package/dist/react/AssistantProvider.js +1 -0
  19. package/dist/react/AssistantProvider.js.map +1 -1
  20. package/dist/react/AssistantRuntimeProvider.js +18 -6
  21. package/dist/react/AssistantRuntimeProvider.js.map +1 -1
  22. package/dist/react/RuntimeAdapter.js +26 -7
  23. package/dist/react/RuntimeAdapter.js.map +1 -1
  24. package/dist/react/adapters/LocalStorageThreadListAdapter.js +29 -7
  25. package/dist/react/adapters/LocalStorageThreadListAdapter.js.map +1 -1
  26. package/dist/react/adapters/TitleGenerationAdapter.js.map +1 -1
  27. package/dist/react/client/DataRenderers.js +54 -35
  28. package/dist/react/client/DataRenderers.js.map +1 -1
  29. package/dist/react/client/Interactables.js +67 -67
  30. package/dist/react/client/Interactables.js.map +1 -1
  31. package/dist/react/client/Tools.d.ts.map +1 -1
  32. package/dist/react/client/Tools.js +118 -55
  33. package/dist/react/client/Tools.js.map +1 -1
  34. package/dist/react/client/interactable-model-context.js.map +1 -1
  35. package/dist/react/model-context/define-mcp-toolkit.js.map +1 -1
  36. package/dist/react/model-context/define-toolkit.js.map +1 -1
  37. package/dist/react/model-context/external-tool.js.map +1 -1
  38. package/dist/react/model-context/human-tool.js.map +1 -1
  39. package/dist/react/model-context/makeAssistantDataUI.js.map +1 -1
  40. package/dist/react/model-context/makeAssistantTool.js.map +1 -1
  41. package/dist/react/model-context/makeAssistantToolUI.js.map +1 -1
  42. package/dist/react/model-context/provider-tool.js.map +1 -1
  43. package/dist/react/model-context/stub-tool.js.map +1 -1
  44. package/dist/react/model-context/toolbox.d.ts +3 -3
  45. package/dist/react/model-context/toolbox.d.ts.map +1 -1
  46. package/dist/react/model-context/toolbox.js.map +1 -1
  47. package/dist/react/model-context/useAssistantContext.js.map +1 -1
  48. package/dist/react/model-context/useAssistantDataUI.js +27 -8
  49. package/dist/react/model-context/useAssistantDataUI.js.map +1 -1
  50. package/dist/react/model-context/useAssistantInstructions.js +33 -10
  51. package/dist/react/model-context/useAssistantInstructions.js.map +1 -1
  52. package/dist/react/model-context/useAssistantInteractable.js.map +1 -1
  53. package/dist/react/model-context/useAssistantTool.js +59 -17
  54. package/dist/react/model-context/useAssistantTool.js.map +1 -1
  55. package/dist/react/model-context/useAssistantToolUI.js +30 -9
  56. package/dist/react/model-context/useAssistantToolUI.js.map +1 -1
  57. package/dist/react/model-context/useAuiToolOverrides.js.map +1 -1
  58. package/dist/react/model-context/useInlineRender.js +35 -8
  59. package/dist/react/model-context/useInlineRender.js.map +1 -1
  60. package/dist/react/model-context/useInteractableState.js +65 -19
  61. package/dist/react/model-context/useInteractableState.js.map +1 -1
  62. package/dist/react/model-context/useToolArgsStatus.js +42 -14
  63. package/dist/react/model-context/useToolArgsStatus.js.map +1 -1
  64. package/dist/react/primitive-hooks/useActionBarCopy.js +59 -22
  65. package/dist/react/primitive-hooks/useActionBarCopy.js.map +1 -1
  66. package/dist/react/primitive-hooks/useActionBarEdit.js +25 -7
  67. package/dist/react/primitive-hooks/useActionBarEdit.js.map +1 -1
  68. package/dist/react/primitive-hooks/useActionBarFeedback.js +49 -13
  69. package/dist/react/primitive-hooks/useActionBarFeedback.js.map +1 -1
  70. package/dist/react/primitive-hooks/useActionBarReload.js +25 -7
  71. package/dist/react/primitive-hooks/useActionBarReload.js.map +1 -1
  72. package/dist/react/primitive-hooks/useActionBarSpeak.js +28 -9
  73. package/dist/react/primitive-hooks/useActionBarSpeak.js.map +1 -1
  74. package/dist/react/primitive-hooks/useActionBarStopSpeaking.js +25 -7
  75. package/dist/react/primitive-hooks/useActionBarStopSpeaking.js.map +1 -1
  76. package/dist/react/primitive-hooks/useBranchPickerNext.js +27 -11
  77. package/dist/react/primitive-hooks/useBranchPickerNext.js.map +1 -1
  78. package/dist/react/primitive-hooks/useBranchPickerPrevious.js +27 -11
  79. package/dist/react/primitive-hooks/useBranchPickerPrevious.js.map +1 -1
  80. package/dist/react/primitive-hooks/useComposerAddAttachment.js +24 -8
  81. package/dist/react/primitive-hooks/useComposerAddAttachment.js.map +1 -1
  82. package/dist/react/primitive-hooks/useComposerCancel.js +25 -7
  83. package/dist/react/primitive-hooks/useComposerCancel.js.map +1 -1
  84. package/dist/react/primitive-hooks/useComposerDictate.js +25 -7
  85. package/dist/react/primitive-hooks/useComposerDictate.js.map +1 -1
  86. package/dist/react/primitive-hooks/useComposerSend.js +25 -7
  87. package/dist/react/primitive-hooks/useComposerSend.js.map +1 -1
  88. package/dist/react/primitive-hooks/useEditComposerCancel.js +18 -4
  89. package/dist/react/primitive-hooks/useEditComposerCancel.js.map +1 -1
  90. package/dist/react/primitive-hooks/useEditComposerSend.js +25 -7
  91. package/dist/react/primitive-hooks/useEditComposerSend.js.map +1 -1
  92. package/dist/react/primitive-hooks/useMessageBranching.js +41 -9
  93. package/dist/react/primitive-hooks/useMessageBranching.js.map +1 -1
  94. package/dist/react/primitive-hooks/useMessageError.js +4 -1
  95. package/dist/react/primitive-hooks/useMessageError.js.map +1 -1
  96. package/dist/react/primitive-hooks/useMessageReload.js +25 -7
  97. package/dist/react/primitive-hooks/useMessageReload.js.map +1 -1
  98. package/dist/react/primitive-hooks/useSuggestionTrigger.js +31 -13
  99. package/dist/react/primitive-hooks/useSuggestionTrigger.js.map +1 -1
  100. package/dist/react/primitive-hooks/useThreadIsEmpty.js +4 -1
  101. package/dist/react/primitive-hooks/useThreadIsEmpty.js.map +1 -1
  102. package/dist/react/primitive-hooks/useThreadIsRunning.js +4 -1
  103. package/dist/react/primitive-hooks/useThreadIsRunning.js.map +1 -1
  104. package/dist/react/primitive-hooks/useThreadListItemArchive.js +18 -4
  105. package/dist/react/primitive-hooks/useThreadListItemArchive.js.map +1 -1
  106. package/dist/react/primitive-hooks/useThreadListItemDelete.js +18 -4
  107. package/dist/react/primitive-hooks/useThreadListItemDelete.js.map +1 -1
  108. package/dist/react/primitive-hooks/useThreadListItemTrigger.js +18 -4
  109. package/dist/react/primitive-hooks/useThreadListItemTrigger.js.map +1 -1
  110. package/dist/react/primitive-hooks/useThreadListItemUnarchive.js +18 -4
  111. package/dist/react/primitive-hooks/useThreadListItemUnarchive.js.map +1 -1
  112. package/dist/react/primitive-hooks/useThreadListLoadMore.js +25 -7
  113. package/dist/react/primitive-hooks/useThreadListLoadMore.js.map +1 -1
  114. package/dist/react/primitive-hooks/useThreadListNew.js +18 -4
  115. package/dist/react/primitive-hooks/useThreadListNew.js.map +1 -1
  116. package/dist/react/primitive-hooks/useThreadMessages.js +4 -1
  117. package/dist/react/primitive-hooks/useThreadMessages.js.map +1 -1
  118. package/dist/react/primitive-hooks/useVoice.js +63 -13
  119. package/dist/react/primitive-hooks/useVoice.js.map +1 -1
  120. package/dist/react/primitives/chainOfThought/ChainOfThoughtParts.js +42 -7
  121. package/dist/react/primitives/chainOfThought/ChainOfThoughtParts.js.map +1 -1
  122. package/dist/react/primitives/composer/ComposerAttachments.js +67 -16
  123. package/dist/react/primitives/composer/ComposerAttachments.js.map +1 -1
  124. package/dist/react/primitives/composer/ComposerIf.js +30 -9
  125. package/dist/react/primitives/composer/ComposerIf.js.map +1 -1
  126. package/dist/react/primitives/composer/ComposerQueue.js.map +1 -1
  127. package/dist/react/primitives/generativeUI/GenerativeUI.js +55 -13
  128. package/dist/react/primitives/generativeUI/GenerativeUI.js.map +1 -1
  129. package/dist/react/primitives/message/MessageAttachments.js +68 -16
  130. package/dist/react/primitives/message/MessageAttachments.js.map +1 -1
  131. package/dist/react/primitives/message/MessageGroupedParts.js +3 -3
  132. package/dist/react/primitives/message/MessageGroupedParts.js.map +1 -1
  133. package/dist/react/primitives/message/MessageParts.js +649 -181
  134. package/dist/react/primitives/message/MessageParts.js.map +1 -1
  135. package/dist/react/primitives/message/MessageQuote.js +18 -2
  136. package/dist/react/primitives/message/MessageQuote.js.map +1 -1
  137. package/dist/react/primitives/messagePart/MessagePartInProgress.js +6 -2
  138. package/dist/react/primitives/messagePart/MessagePartInProgress.js.map +1 -1
  139. package/dist/react/primitives/part/PartMessages.js +46 -14
  140. package/dist/react/primitives/part/PartMessages.js.map +1 -1
  141. package/dist/react/primitives/thread/ThreadMessages.js +67 -10
  142. package/dist/react/primitives/thread/ThreadMessages.js.map +1 -1
  143. package/dist/react/primitives/thread/ThreadSuggestions.js +50 -10
  144. package/dist/react/primitives/thread/ThreadSuggestions.js.map +1 -1
  145. package/dist/react/primitives/threadList/ThreadListItems.js +55 -14
  146. package/dist/react/primitives/threadList/ThreadListItems.js.map +1 -1
  147. package/dist/react/primitives/threadListItem/ThreadListItemTitle.js +15 -2
  148. package/dist/react/primitives/threadListItem/ThreadListItemTitle.js.map +1 -1
  149. package/dist/react/providers/AttachmentByIndexProvider.js +57 -12
  150. package/dist/react/providers/AttachmentByIndexProvider.js.map +1 -1
  151. package/dist/react/providers/ChainOfThoughtByIndicesProvider.js +33 -11
  152. package/dist/react/providers/ChainOfThoughtByIndicesProvider.js.map +1 -1
  153. package/dist/react/providers/ChainOfThoughtPartByIndexProvider.js +29 -6
  154. package/dist/react/providers/ChainOfThoughtPartByIndexProvider.js.map +1 -1
  155. package/dist/react/providers/MessageByIndexProvider.js +49 -19
  156. package/dist/react/providers/MessageByIndexProvider.js.map +1 -1
  157. package/dist/react/providers/PartByIndexProvider.js +29 -6
  158. package/dist/react/providers/PartByIndexProvider.js.map +1 -1
  159. package/dist/react/providers/QueueItemByIndexProvider.js +29 -6
  160. package/dist/react/providers/QueueItemByIndexProvider.js.map +1 -1
  161. package/dist/react/providers/ReadonlyThreadProvider.js +83 -28
  162. package/dist/react/providers/ReadonlyThreadProvider.js.map +1 -1
  163. package/dist/react/providers/SuggestionByIndexProvider.js +29 -6
  164. package/dist/react/providers/SuggestionByIndexProvider.js.map +1 -1
  165. package/dist/react/providers/TextMessagePartProvider.js +73 -25
  166. package/dist/react/providers/TextMessagePartProvider.js.map +1 -1
  167. package/dist/react/providers/ThreadListItemByIndexProvider.js +30 -6
  168. package/dist/react/providers/ThreadListItemByIndexProvider.js.map +1 -1
  169. package/dist/react/providers/ThreadListItemRuntimeProvider.js +28 -5
  170. package/dist/react/providers/ThreadListItemRuntimeProvider.js.map +1 -1
  171. package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js +19 -4
  172. package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js.map +1 -1
  173. package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js.map +1 -1
  174. package/dist/react/runtimes/RuntimeAdapterProvider.js +27 -10
  175. package/dist/react/runtimes/RuntimeAdapterProvider.js.map +1 -1
  176. package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js +10 -1
  177. package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js.map +1 -1
  178. package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.js.map +1 -1
  179. package/dist/react/runtimes/cloud/auiV0.js.map +1 -1
  180. package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js +17 -17
  181. package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js.map +1 -1
  182. package/dist/react/runtimes/createMessageConverter.js.map +1 -1
  183. package/dist/react/runtimes/external-message-converter.d.ts.map +1 -1
  184. package/dist/react/runtimes/external-message-converter.js +67 -30
  185. package/dist/react/runtimes/external-message-converter.js.map +1 -1
  186. package/dist/react/runtimes/useExternalStoreRuntime.js +44 -10
  187. package/dist/react/runtimes/useExternalStoreRuntime.js.map +1 -1
  188. package/dist/react/runtimes/useExternalStoreSharedOptions.js +17 -12
  189. package/dist/react/runtimes/useExternalStoreSharedOptions.js.map +1 -1
  190. package/dist/react/runtimes/useLocalRuntime.js.map +1 -1
  191. package/dist/react/runtimes/useRemoteThreadListRuntime.js +34 -6
  192. package/dist/react/runtimes/useRemoteThreadListRuntime.js.map +1 -1
  193. package/dist/react/types/MessagePartComponentTypes.d.ts +5 -6
  194. package/dist/react/types/MessagePartComponentTypes.d.ts.map +1 -1
  195. package/dist/react/utils/getMessageQuote.js.map +1 -1
  196. package/dist/react/utils/groupParts.js.map +1 -1
  197. package/dist/runtime/api/assistant-runtime.js.map +1 -1
  198. package/dist/runtime/api/attachment-runtime.js.map +1 -1
  199. package/dist/runtime/api/composer-runtime.js.map +1 -1
  200. package/dist/runtime/api/message-part-runtime.d.ts +3 -9
  201. package/dist/runtime/api/message-part-runtime.d.ts.map +1 -1
  202. package/dist/runtime/api/message-part-runtime.js +3 -6
  203. package/dist/runtime/api/message-part-runtime.js.map +1 -1
  204. package/dist/runtime/api/message-runtime.js.map +1 -1
  205. package/dist/runtime/api/thread-list-item-runtime.js.map +1 -1
  206. package/dist/runtime/api/thread-list-runtime.js.map +1 -1
  207. package/dist/runtime/api/thread-runtime.js.map +1 -1
  208. package/dist/runtime/base/base-assistant-runtime-core.js.map +1 -1
  209. package/dist/runtime/base/base-composer-runtime-core.js.map +1 -1
  210. package/dist/runtime/base/base-thread-runtime-core.js.map +1 -1
  211. package/dist/runtime/base/default-edit-composer-runtime-core.js.map +1 -1
  212. package/dist/runtime/base/default-thread-composer-runtime-core.js.map +1 -1
  213. package/dist/runtime/interfaces/thread-runtime-core.d.ts +2 -1
  214. package/dist/runtime/interfaces/thread-runtime-core.d.ts.map +1 -1
  215. package/dist/runtime/queue/message-queue.js.map +1 -1
  216. package/dist/runtime/utils/auto-status.js.map +1 -1
  217. package/dist/runtime/utils/external-store-message.js.map +1 -1
  218. package/dist/runtime/utils/message-repository.js.map +1 -1
  219. package/dist/runtime/utils/resolveToolApprovalResponse.d.ts +15 -0
  220. package/dist/runtime/utils/resolveToolApprovalResponse.d.ts.map +1 -0
  221. package/dist/runtime/utils/resolveToolApprovalResponse.js +35 -0
  222. package/dist/runtime/utils/resolveToolApprovalResponse.js.map +1 -0
  223. package/dist/runtime/utils/thread-message-like.d.ts +5 -1
  224. package/dist/runtime/utils/thread-message-like.d.ts.map +1 -1
  225. package/dist/runtime/utils/thread-message-like.js.map +1 -1
  226. package/dist/runtimes/assistant-transport/utils.js.map +1 -1
  227. package/dist/runtimes/external-store/external-store-runtime-core.js.map +1 -1
  228. package/dist/runtimes/external-store/external-store-shared-options.js.map +1 -1
  229. package/dist/runtimes/external-store/external-store-thread-list-runtime-core.js.map +1 -1
  230. package/dist/runtimes/external-store/external-store-thread-runtime-core.js.map +1 -1
  231. package/dist/runtimes/external-store/thread-message-converter.js.map +1 -1
  232. package/dist/runtimes/local/local-runtime-core.js.map +1 -1
  233. package/dist/runtimes/local/local-thread-list-runtime-core.js.map +1 -1
  234. package/dist/runtimes/local/local-thread-runtime-core.d.ts +1 -0
  235. package/dist/runtimes/local/local-thread-runtime-core.d.ts.map +1 -1
  236. package/dist/runtimes/local/local-thread-runtime-core.js +9 -7
  237. package/dist/runtimes/local/local-thread-runtime-core.js.map +1 -1
  238. package/dist/runtimes/local/should-continue.js +1 -1
  239. package/dist/runtimes/local/should-continue.js.map +1 -1
  240. package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.js.map +1 -1
  241. package/dist/runtimes/remote-thread-list/adapter/in-memory.js.map +1 -1
  242. package/dist/runtimes/remote-thread-list/empty-thread-core.js.map +1 -1
  243. package/dist/runtimes/remote-thread-list/optimistic-state.js.map +1 -1
  244. package/dist/runtimes/remote-thread-list/remote-thread-state.js.map +1 -1
  245. package/dist/runtimes/tool-invocations/ToolInvocationTracker.js.map +1 -1
  246. package/dist/store/clients/chain-of-thought-client.js +37 -19
  247. package/dist/store/clients/chain-of-thought-client.js.map +1 -1
  248. package/dist/store/clients/model-context-client.js +64 -14
  249. package/dist/store/clients/model-context-client.js.map +1 -1
  250. package/dist/store/clients/no-op-composer-client.js +94 -53
  251. package/dist/store/clients/no-op-composer-client.js.map +1 -1
  252. package/dist/store/clients/runtime-adapter.js.map +1 -1
  253. package/dist/store/clients/suggestions.d.ts.map +1 -1
  254. package/dist/store/clients/suggestions.js +59 -21
  255. package/dist/store/clients/suggestions.js.map +1 -1
  256. package/dist/store/clients/thread-message-client.d.ts.map +1 -1
  257. package/dist/store/clients/thread-message-client.js +176 -69
  258. package/dist/store/clients/thread-message-client.js.map +1 -1
  259. package/dist/store/runtime-clients/attachment-runtime-client.js +29 -6
  260. package/dist/store/runtime-clients/attachment-runtime-client.js.map +1 -1
  261. package/dist/store/runtime-clients/composer-runtime-client.d.ts.map +1 -1
  262. package/dist/store/runtime-clients/composer-runtime-client.js +188 -68
  263. package/dist/store/runtime-clients/composer-runtime-client.js.map +1 -1
  264. package/dist/store/runtime-clients/liveRef.d.ts +7 -0
  265. package/dist/store/runtime-clients/liveRef.d.ts.map +1 -0
  266. package/dist/store/runtime-clients/liveRef.js +8 -0
  267. package/dist/store/runtime-clients/liveRef.js.map +1 -0
  268. package/dist/store/runtime-clients/message-part-runtime-client.js +47 -8
  269. package/dist/store/runtime-clients/message-part-runtime-client.js.map +1 -1
  270. package/dist/store/runtime-clients/message-runtime-client.d.ts.map +1 -1
  271. package/dist/store/runtime-clients/message-runtime-client.js +214 -52
  272. package/dist/store/runtime-clients/message-runtime-client.js.map +1 -1
  273. package/dist/store/runtime-clients/thread-list-item-runtime-client.js +69 -25
  274. package/dist/store/runtime-clients/thread-list-item-runtime-client.js.map +1 -1
  275. package/dist/store/runtime-clients/thread-list-runtime-client.d.ts.map +1 -1
  276. package/dist/store/runtime-clients/thread-list-runtime-client.js +137 -34
  277. package/dist/store/runtime-clients/thread-list-runtime-client.js.map +1 -1
  278. package/dist/store/runtime-clients/thread-runtime-client.d.ts.map +1 -1
  279. package/dist/store/runtime-clients/thread-runtime-client.js +192 -71
  280. package/dist/store/runtime-clients/thread-runtime-client.js.map +1 -1
  281. package/dist/store/runtime-clients/useSubscribable.js +2 -9
  282. package/dist/store/runtime-clients/useSubscribable.js.map +1 -1
  283. package/dist/store/scopes/part.d.ts +5 -6
  284. package/dist/store/scopes/part.d.ts.map +1 -1
  285. package/dist/store/scopes/queue-item.js.map +1 -1
  286. package/dist/subscribable/subscribable.js.map +1 -1
  287. package/dist/tests/remote-thread-list-test-helpers.js.map +1 -1
  288. package/dist/types/message.d.ts +38 -5
  289. package/dist/types/message.d.ts.map +1 -1
  290. package/dist/types/message.js.map +1 -1
  291. package/dist/utils/composite-context-provider.js.map +1 -1
  292. package/dist/utils/id.js.map +1 -1
  293. package/dist/utils/json/is-json-equal.js.map +1 -1
  294. package/dist/utils/json/is-json.js.map +1 -1
  295. package/dist/utils/text.js.map +1 -1
  296. package/package.json +8 -8
  297. package/src/index.ts +4 -0
  298. package/src/internal.ts +1 -0
  299. package/src/model-context/types.ts +1 -0
  300. package/src/react/AssistantProvider.tsx +7 -0
  301. package/src/react/client/Tools.ts +3 -5
  302. package/src/react/model-context/toolbox.test.ts +2 -1
  303. package/src/react/model-context/toolbox.ts +2 -6
  304. package/src/react/runtimes/external-message-converter.ts +3 -1
  305. package/src/react/types/MessagePartComponentTypes.ts +5 -5
  306. package/src/runtime/api/message-part-runtime.ts +14 -11
  307. package/src/runtime/interfaces/thread-runtime-core.ts +2 -0
  308. package/src/runtime/utils/resolveToolApprovalResponse.test.ts +91 -0
  309. package/src/runtime/utils/resolveToolApprovalResponse.ts +55 -0
  310. package/src/runtime/utils/thread-message-like.ts +10 -1
  311. package/src/runtimes/local/local-thread-runtime-core.test.ts +61 -2
  312. package/src/runtimes/local/local-thread-runtime-core.ts +17 -8
  313. package/src/runtimes/local/should-continue.ts +2 -1
  314. package/src/store/clients/suggestions.ts +3 -5
  315. package/src/store/clients/thread-message-client.ts +13 -14
  316. package/src/store/runtime-clients/composer-runtime-client.ts +18 -21
  317. package/src/store/runtime-clients/liveRef.ts +5 -0
  318. package/src/store/runtime-clients/message-runtime-client.ts +16 -21
  319. package/src/store/runtime-clients/thread-list-runtime-client.ts +3 -5
  320. package/src/store/runtime-clients/thread-runtime-client.ts +9 -10
  321. package/src/store/runtime-clients/useSubscribable.ts +2 -10
  322. package/src/store/scopes/part.ts +5 -2
  323. package/src/types/message.ts +45 -3
@@ -3,6 +3,7 @@ import { AssistantRuntimeImpl } from "../../runtime/api/assistant-runtime.js";
3
3
  import { RemoteThreadListThreadListRuntimeCore } from "./RemoteThreadListThreadListRuntimeCore.js";
4
4
  import { useCallback, useEffect, useMemo, useRef, useState } from "@assistant-ui/tap/react-shim";
5
5
  import { useAui } from "@assistant-ui/store";
6
+ import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
6
7
  //#region src/react/runtimes/useRemoteThreadListRuntime.ts
7
8
  var RemoteThreadListRuntimeCore = class extends BaseAssistantRuntimeCore {
8
9
  threads;
@@ -15,12 +16,39 @@ var RemoteThreadListRuntimeCore = class extends BaseAssistantRuntimeCore {
15
16
  }
16
17
  };
17
18
  const useRemoteThreadListRuntimeImpl = (options) => {
18
- const [runtime] = useState(() => new RemoteThreadListRuntimeCore(options));
19
- useEffect(() => {
20
- runtime.threads.__internal_setOptions(options);
21
- runtime.threads.__internal_load();
22
- }, [runtime, options]);
23
- return useMemo(() => new AssistantRuntimeImpl(runtime), [runtime]);
19
+ const $ = c(10);
20
+ let t0;
21
+ if ($[0] !== options) {
22
+ t0 = () => new RemoteThreadListRuntimeCore(options);
23
+ $[0] = options;
24
+ $[1] = t0;
25
+ } else t0 = $[1];
26
+ const [runtime] = useState(t0);
27
+ let t1;
28
+ if ($[2] !== options || $[3] !== runtime.threads) {
29
+ t1 = () => {
30
+ runtime.threads.__internal_setOptions(options);
31
+ runtime.threads.__internal_load();
32
+ };
33
+ $[2] = options;
34
+ $[3] = runtime.threads;
35
+ $[4] = t1;
36
+ } else t1 = $[4];
37
+ let t2;
38
+ if ($[5] !== options || $[6] !== runtime) {
39
+ t2 = [runtime, options];
40
+ $[5] = options;
41
+ $[6] = runtime;
42
+ $[7] = t2;
43
+ } else t2 = $[7];
44
+ useEffect(t1, t2);
45
+ let t3;
46
+ if ($[8] !== runtime) {
47
+ t3 = new AssistantRuntimeImpl(runtime);
48
+ $[8] = runtime;
49
+ $[9] = t3;
50
+ } else t3 = $[9];
51
+ return t3;
24
52
  };
25
53
  const useRemoteThreadListRuntime = (options) => {
26
54
  const runtimeHookRef = useRef(options.runtimeHook);
@@ -1 +1 @@
1
- {"version":3,"file":"useRemoteThreadListRuntime.js","names":[],"sources":["../../../src/react/runtimes/useRemoteThreadListRuntime.ts"],"sourcesContent":["import { useState, useEffect, useMemo, useRef, useCallback } from \"react\";\nimport { BaseAssistantRuntimeCore } from \"../../runtime/base/base-assistant-runtime-core\";\nimport { AssistantRuntimeImpl } from \"../../runtime/api/assistant-runtime\";\nimport type { RemoteThreadListOptions } from \"../../runtimes/remote-thread-list/types\";\nimport type { AssistantRuntimeCore } from \"../../runtime/interfaces/assistant-runtime-core\";\nimport type { AssistantRuntime } from \"../../runtime/api/assistant-runtime\";\nimport { RemoteThreadListThreadListRuntimeCore } from \"./RemoteThreadListThreadListRuntimeCore\";\nimport { useAui } from \"@assistant-ui/store\";\n\nclass RemoteThreadListRuntimeCore\n extends BaseAssistantRuntimeCore\n implements AssistantRuntimeCore\n{\n public readonly threads;\n\n constructor(options: RemoteThreadListOptions) {\n super();\n this.threads = new RemoteThreadListThreadListRuntimeCore(\n options,\n this._contextProvider,\n );\n }\n\n public get RenderComponent() {\n return this.threads.__internal_RenderComponent;\n }\n}\n\nconst useRemoteThreadListRuntimeImpl = (\n options: RemoteThreadListOptions,\n): AssistantRuntime => {\n const [runtime] = useState(() => new RemoteThreadListRuntimeCore(options));\n useEffect(() => {\n runtime.threads.__internal_setOptions(options);\n runtime.threads.__internal_load();\n }, [runtime, options]);\n\n return useMemo(() => new AssistantRuntimeImpl(runtime), [runtime]);\n};\n\nexport const useRemoteThreadListRuntime = (\n options: RemoteThreadListOptions,\n): AssistantRuntime => {\n const runtimeHookRef = useRef(options.runtimeHook);\n runtimeHookRef.current = options.runtimeHook;\n\n // threadId/initialThreadId only affect the constructor; capture once via ref\n const startThreadIdRef = useRef(options.threadId ?? options.initialThreadId);\n\n const stableRuntimeHook = useCallback(() => {\n return runtimeHookRef.current();\n }, []);\n\n const stableOptions = useMemo<RemoteThreadListOptions>(\n () => ({\n adapter: options.adapter,\n allowNesting: options.allowNesting,\n initialThreadId: startThreadIdRef.current,\n runtimeHook: stableRuntimeHook,\n }),\n [options.adapter, options.allowNesting, stableRuntimeHook],\n );\n\n const aui = useAui();\n const isNested = aui.threadListItem.source !== null;\n\n if (isNested) {\n if (!stableOptions.allowNesting) {\n throw new Error(\n \"useRemoteThreadListRuntime cannot be nested inside another RemoteThreadListRuntime. \" +\n \"Set allowNesting: true to allow nesting (the inner runtime will become a no-op).\",\n );\n }\n\n // If allowNesting is true and already inside a thread list context,\n // just call the runtimeHook directly (no-op behavior)\n return stableRuntimeHook();\n }\n\n const runtime = useRemoteThreadListRuntimeImpl(stableOptions);\n\n const prevThreadIdRef = useRef(options.threadId);\n useEffect(() => {\n if (options.threadId === prevThreadIdRef.current) return;\n prevThreadIdRef.current = options.threadId;\n if (options.threadId) {\n runtime.threads.switchToThread(options.threadId).catch(() => {});\n } else {\n runtime.threads.switchToNewThread().catch(() => {});\n }\n }, [runtime, options.threadId]);\n\n return runtime;\n};\n"],"mappings":";;;;;;AASA,IAAM,8BAAN,cACU,yBAEV;CACE;CAEA,YAAY,SAAkC;EAC5C,MAAM;EACN,KAAK,UAAU,IAAI,sCACjB,SACA,KAAK,gBACP;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adListRuntime.js","names":["useState","useEffect","useMemo","useRef","useCallback","BaseAssistantRuntimeCore","AssistantRuntimeImpl","RemoteThreadListOptions","AssistantRuntimeCore","AssistantRuntime","RemoteThreadListThreadListRuntimeCore","useAui","RemoteThreadListRuntimeCore","threads","constructor","options","_contextProvider","RenderComponent","__internal_RenderComponent","useRemoteThreadListRuntimeImpl","$","_c","t0","runtime","t1","__internal_setOptions","__internal_load","t2","t3","useRemoteThreadListRuntime","runtimeHookRef","runtimeHook","current","startThreadIdRef","threadId","initialThreadId","stableRuntimeHook","stableOptions","adapter","allowNesting","aui","isNested","threadListItem","source","Error","prevThreadIdRef","switchToThread","catch","switchToNewThread"],"sources":["../../../src/react/runtimes/useRemoteThreadListRuntime.ts"],"sourcesContent":["import { useState, useEffect, useMemo, useRef, useCallback } from \"react\";\nimport { BaseAssistantRuntimeCore } from \"../../runtime/base/base-assistant-runtime-core\";\nimport { AssistantRuntimeImpl } from \"../../runtime/api/assistant-runtime\";\nimport type { RemoteThreadListOptions } from \"../../runtimes/remote-thread-list/types\";\nimport type { AssistantRuntimeCore } from \"../../runtime/interfaces/assistant-runtime-core\";\nimport type { AssistantRuntime } from \"../../runtime/api/assistant-runtime\";\nimport { RemoteThreadListThreadListRuntimeCore } from \"./RemoteThreadListThreadListRuntimeCore\";\nimport { useAui } from \"@assistant-ui/store\";\n\nclass RemoteThreadListRuntimeCore\n extends BaseAssistantRuntimeCore\n implements AssistantRuntimeCore\n{\n public readonly threads;\n\n constructor(options: RemoteThreadListOptions) {\n super();\n this.threads = new RemoteThreadListThreadListRuntimeCore(\n options,\n this._contextProvider,\n );\n }\n\n public get RenderComponent() {\n return this.threads.__internal_RenderComponent;\n }\n}\n\nconst useRemoteThreadListRuntimeImpl = (\n options: RemoteThreadListOptions,\n): AssistantRuntime => {\n const [runtime] = useState(() => new RemoteThreadListRuntimeCore(options));\n useEffect(() => {\n runtime.threads.__internal_setOptions(options);\n runtime.threads.__internal_load();\n }, [runtime, options]);\n\n return useMemo(() => new AssistantRuntimeImpl(runtime), [runtime]);\n};\n\nexport const useRemoteThreadListRuntime = (\n options: RemoteThreadListOptions,\n): AssistantRuntime => {\n const runtimeHookRef = useRef(options.runtimeHook);\n runtimeHookRef.current = options.runtimeHook;\n\n // threadId/initialThreadId only affect the constructor; capture once via ref\n const startThreadIdRef = useRef(options.threadId ?? options.initialThreadId);\n\n const stableRuntimeHook = useCallback(() => {\n return runtimeHookRef.current();\n }, []);\n\n const stableOptions = useMemo<RemoteThreadListOptions>(\n () => ({\n adapter: options.adapter,\n allowNesting: options.allowNesting,\n initialThreadId: startThreadIdRef.current,\n runtimeHook: stableRuntimeHook,\n }),\n [options.adapter, options.allowNesting, stableRuntimeHook],\n );\n\n const aui = useAui();\n const isNested = aui.threadListItem.source !== null;\n\n if (isNested) {\n if (!stableOptions.allowNesting) {\n throw new Error(\n \"useRemoteThreadListRuntime cannot be nested inside another RemoteThreadListRuntime. \" +\n \"Set allowNesting: true to allow nesting (the inner runtime will become a no-op).\",\n );\n }\n\n // If allowNesting is true and already inside a thread list context,\n // just call the runtimeHook directly (no-op behavior)\n return stableRuntimeHook();\n }\n\n const runtime = useRemoteThreadListRuntimeImpl(stableOptions);\n\n const prevThreadIdRef = useRef(options.threadId);\n useEffect(() => {\n if (options.threadId === prevThreadIdRef.current) return;\n prevThreadIdRef.current = options.threadId;\n if (options.threadId) {\n runtime.threads.switchToThread(options.threadId).catch(() => {});\n } else {\n runtime.threads.switchToNewThread().catch(() => {});\n }\n }, [runtime, options.threadId]);\n\n return runtime;\n};\n"],"mappings":";;;;;;;AASA,IAAMY,8BAAN,cACUP,yBAEV;CACE;CAEAS,YAAYC,SAAkC;EAC5C,MAAM;EACN,KAAKF,UAAU,IAAIH,sCACjBK,SACA,KAAKC,gBACP;CACF;CAEA,IAAWC,kBAAkB;EAC3B,OAAO,KAAKJ,QAAQK;CACtB;AACF;AAEA,MAAMC,kCAAiCJ,YAAA;CAAA,MAAAK,IAAAC,EAAA,EAAA;CA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AQuB;EAASvB,QAAQwB;EAAcH;CAAiB,CAC3D;CAKA,IAHYzB,OACK6B,CAAG,CAACE,eAAeC,WAAW,MAEjC;EACZ,IAAI,CAACN,cAAcE,cACjB,MAAM,IAAIK,MACR,sKAEF;EAKF,OAAOR,kBAAkB;CAC3B;CAEA,MAAMb,UAAUJ,+BAA+BkB,aAAa;CAE5D,MAAMQ,kBAAkB1C,OAAOY,QAAQmB,QAAQ;CAC/CjC,gBAAgB;EACd,IAAIc,QAAQmB,aAAaW,gBAAgBb,SAAS;EAClDa,gBAAgBb,UAAUjB,QAAQmB;EAClC,IAAInB,QAAQmB,UACVX,QAAQV,QAAQiC,eAAe/B,QAAQmB,QAAQ,CAAC,CAACa,YAAY,CAAC,CAAC;OAE/DxB,QAAQV,QAAQmC,kBAAkB,CAAC,CAACD,YAAY,CAAC,CAAC;CAEtD,GAAG,CAACxB,SAASR,QAAQmB,QAAQ,CAAC;CAE9B,OAAOX;AACT"}
@@ -1,4 +1,4 @@
1
- import { DataMessagePart, FileMessagePart, GenerativeUIMessagePart, GenerativeUISpec, ImageMessagePart, MessagePartStatus, ReasoningMessagePart, SourceMessagePart, TextMessagePart, ToolCallMessagePart, Unstable_AudioMessagePart } from "../../types/message.js";
1
+ import { DataMessagePart, FileMessagePart, GenerativeUIMessagePart, GenerativeUISpec, ImageMessagePart, MessagePartStatus, ReasoningMessagePart, SourceMessagePart, TextMessagePart, ToolApprovalResponse, ToolCallMessagePart, Unstable_AudioMessagePart } from "../../types/message.js";
2
2
  import { QuoteInfo } from "../../types/quote.js";
3
3
  import { MessagePartState } from "../../runtime/api/message-part-runtime.js";
4
4
  import { ToolResponse } from "assistant-stream";
@@ -43,12 +43,11 @@ type ToolCallMessagePartProps<TArgs = any, TResult = unknown> = MessagePartState
43
43
  resume: (payload: unknown) => void;
44
44
  /**
45
45
  * Responds to a server-side tool approval gate. Only valid while
46
- * `approval` is set on the part and `approval.approved === undefined`.
46
+ * `approval` is set on the part, `approval.approved === undefined`, and
47
+ * no `approval.resolution` is recorded. Accepts a boolean decision or the
48
+ * id of one of `approval.options`; option kinds resolve to the boolean.
47
49
  */
48
- respondToApproval: (response: {
49
- approved: boolean;
50
- reason?: string;
51
- }) => void;
50
+ respondToApproval: (response: ToolApprovalResponse) => void;
52
51
  };
53
52
  /** Component used to render a tool-call message part. */
54
53
  type ToolCallMessagePartComponent<TArgs = any, TResult = any> = ComponentType<ToolCallMessagePartProps<TArgs, TResult>>;
@@ -1 +1 @@
1
- {"version":3,"file":"MessagePartComponentTypes.d.ts","names":[],"sources":["../../../src/react/types/MessagePartComponentTypes.ts"],"mappings":";;;;;;;KAkBY,qBAAA;EACV,MAAA,EAAQ,iBAAiB;AAAA;AAAA,KAEf,yBAAA,GAA4B,aAAa,CAAC,qBAAA;AAAA,KAE1C,oBAAA,GAAuB,gBAAA,GAAmB,eAAe;AAAA,KACzD,wBAAA,GAA2B,aAAa,CAAC,oBAAA;AAAA,KAEzC,yBAAA,GAA4B,gBAAA,GAAmB,oBAAoB;AAAA,KACnE,6BAAA,GACV,aAAa,CAAC,yBAAA;AAAA,KAEJ,mBAAA,GAAsB,iBAAiB;EACjD,UAAA;EACA,QAAA;AAAA;AAAA,KAEU,uBAAA,GAA0B,aAAa,CAAC,mBAAA;AAAA,KAExC,sBAAA,GAAyB,gBAAA,GAAmB,iBAAiB;AAAA,KAC7D,0BAAA,GAA6B,aAAa,CAAC,sBAAA;AAAA,KAE3C,qBAAA,GAAwB,gBAAA,GAAmB,gBAAgB;AAAA,KAC3D,yBAAA,GAA4B,aAAa,CAAC,qBAAA;AAAA,KAE1C,oBAAA,GAAuB,gBAAA,GAAmB,eAAe;AAAA,KACzD,wBAAA,GAA2B,aAAa,CAAC,oBAAA;AAAA,KAEzC,8BAAA,GAAiC,gBAAA,GAC3C,yBAAyB;AAAA,KACf,kCAAA,GACV,aAAa,CAAC,8BAAA;AAAA,KAEJ,oBAAA,YAAgC,gBAAA,GAC1C,eAAA,CAAgB,CAAA;AAAA,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AAA;AAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"getMessageQuote.js","names":[],"sources":["../../../src/react/utils/getMessageQuote.ts"],"sourcesContent":["import type { QuoteInfo } from \"../../types/quote\";\n\ntype MessageQuoteState = {\n message: {\n metadata?: unknown;\n };\n};\n\nexport const getMessageQuote = (\n state: MessageQuoteState,\n): QuoteInfo | undefined => {\n const metadata = state.message.metadata;\n if (!metadata || typeof metadata !== \"object\") return undefined;\n\n return (metadata as { custom?: Record<string, unknown> }).custom?.quote as\n | QuoteInfo\n | undefined;\n};\n"],"mappings":";AAQA,MAAa,mBACX,UAC0B;CAC1B,MAAM,WAAW,MAAM,QAAQ;CAC/B,IAAI,CAAC,YAAY,OAAO,aAAa,UAAU,OAAO,KAAA;CAEtD,OAAQ,SAAkD,QAAQ;AAGpE"}
1
+ {"version":3,"file":"getMessageQuote.js","names":["QuoteInfo","MessageQuoteState","message","metadata","getMessageQuote","state","undefined","custom","Record","quote"],"sources":["../../../src/react/utils/getMessageQuote.ts"],"sourcesContent":["import type { QuoteInfo } from \"../../types/quote\";\n\ntype MessageQuoteState = {\n message: {\n metadata?: unknown;\n };\n};\n\nexport const getMessageQuote = (\n state: MessageQuoteState,\n): QuoteInfo | undefined => {\n const metadata = state.message.metadata;\n if (!metadata || typeof metadata !== \"object\") return undefined;\n\n return (metadata as { custom?: Record<string, unknown> }).custom?.quote as\n | QuoteInfo\n | undefined;\n};\n"],"mappings":";AAQA,MAAaI,mBACXC,UAC0B;CAC1B,MAAMF,WAAWE,MAAMH,QAAQC;CAC/B,IAAI,CAACA,YAAY,OAAOA,aAAa,UAAU,OAAOG,KAAAA;CAEtD,OAAQH,SAAkDI,QAAQE;AAGpE"}
@@ -1 +1 @@
1
- {"version":3,"file":"groupParts.js","names":[],"sources":["../../../src/react/utils/groupParts.ts"],"sourcesContent":["import { isMcpAppUri } from \"../../types/message\";\nimport type { PartState } from \"../../store/scopes/part\";\nimport type { ToolsState } from \"../types/scopes/tools\";\n\n/**\n * Registry context passed to a `groupBy` function as its second argument by\n * `<MessagePrimitive.GroupedParts>`. Carries the live tool-UI registry so a\n * `groupBy` can resolve registry-driven grouping (e.g. standalone tool calls)\n * without the part itself having to carry that information.\n */\nexport type GroupByContext = {\n /** Tool UIs registered in the tool-UI registry, keyed by tool name. */\n readonly toolUIs?: ToolsState[\"toolUIs\"];\n};\n\n/**\n * Hierarchical adjacent-coalescing grouping for message parts.\n *\n * Given a group path per part (from `groupBy`), builds a tree of group\n * nodes wrapping individual parts. Adjacent parts sharing a path prefix\n * coalesce into the same group; ungrouped parts are direct children of\n * the root.\n *\n * Each node gets a structural `nodeKey` built from sibling indices\n * (`\"0.1.0\"`), stable under append-only streaming.\n */\n\n/**\n * Symbol attached to memoizable `groupBy` functions (e.g. those returned\n * by {@link groupPartByType}). Carries a string fingerprint of the config\n * so `MessagePrimitive.GroupedParts` can memo the tree on\n * `[parts, memoKey]` across renders — even when the helper call site\n * reconstructs the function each render.\n */\nexport const GROUPBY_MEMO_KEY: unique symbol = Symbol.for(\n \"@assistant-ui/groupBy.memoKey\",\n);\n\n/**\n * Synthetic part-type keys recognized by {@link groupPartByType}, in\n * addition to real {@link PartState} types:\n *\n * - `\"standalone-tool-call\"` — a tool-call whose UI should be presented on its\n * own, outside the chain-of-thought grouping. Matches MCP-app tool calls plus\n * any tool-call whose registered UI opts into standalone display (human\n * tools, the built-in generative-UI tool, and tools that set\n * `display: \"standalone\"`). Resolving the registry-driven cases reads the\n * {@link GroupByContext} passed to the `groupBy` function. Takes precedence\n * over the `\"tool-call\"` entry.\n * - `\"mcp-app\"` — **deprecated**, kept for back-compat. Matches only MCP-app\n * tool calls. Prefer `\"standalone-tool-call\"`, which is a superset.\n */\ntype GroupPartType = PartState[\"type\"] | \"standalone-tool-call\" | \"mcp-app\";\n\n/**\n * Build a `groupBy` from a `part.type → group-key path` lookup.\n * Parts whose type isn't in the map are left ungrouped. The returned\n * function carries a stable {@link GROUPBY_MEMO_KEY} fingerprint so\n * `<MessagePrimitive.GroupedParts>` can memoize its tree across renders.\n *\n * The synthetic `\"standalone-tool-call\"` key matches tool calls that should\n * render outside the chain-of-thought grouping. MCP-app calls are detected from\n * the part alone; the registry-driven cases (human tools, the generative-UI\n * tool, `display: \"standalone\"` opt-ins) are resolved from the\n * {@link GroupByContext} that `<MessagePrimitive.GroupedParts>` passes to the\n * `groupBy` function — the helper needs nothing threaded into it.\n *\n * @example\n * ```tsx\n * <MessagePrimitive.GroupedParts\n * groupBy={groupPartByType({\n * reasoning: [\"group-thought\", \"group-reasoning\"],\n * \"tool-call\": [\"group-thought\", \"group-tool\"],\n * \"standalone-tool-call\": [],\n * })}\n * >\n * {({ part, children }) => { ... }}\n * </MessagePrimitive.GroupedParts>\n * ```\n */\nexport const groupPartByType = <TKey extends `group-${string}`>(\n map: Partial<Readonly<Record<GroupPartType, readonly TKey[]>>>,\n): ((part: PartState, context?: GroupByContext) => readonly TKey[]) => {\n const lookup = map as Readonly<Record<string, readonly TKey[] | undefined>>;\n const fn = ((part, context) => {\n if (part.type === \"tool-call\") {\n const isMcpApp = isMcpAppUri(part.mcp?.app?.resourceUri);\n // Read the first registration's flag — the same one `resolveToolRender`\n // renders — so grouping and rendering never disagree for a tool name.\n const isStandalone =\n isMcpApp ||\n (context?.toolUIs?.[part.toolName]?.[0]?.standalone ?? false);\n if (isStandalone && lookup[\"standalone-tool-call\"] !== undefined) {\n return lookup[\"standalone-tool-call\"]!;\n }\n // TODO(v0.15): drop the deprecated \"mcp-app\" key (superseded by \"standalone-tool-call\").\n if (isMcpApp && lookup[\"mcp-app\"] !== undefined) {\n return lookup[\"mcp-app\"]!;\n }\n }\n return lookup[part.type] ?? [];\n }) as ((part: PartState, context?: GroupByContext) => readonly TKey[]) & {\n [GROUPBY_MEMO_KEY]?: string;\n };\n // Sort keys so the fingerprint is insensitive to map insertion order —\n // two maps with the same key/value pairs but different declaration order\n // would otherwise hash differently and invalidate the memo unnecessarily.\n const sortedKeys = Object.keys(map).sort();\n const sortedEntries = sortedKeys.map((k) => [k, map[k as keyof typeof map]]);\n fn[GROUPBY_MEMO_KEY] = `groupPartByType:${JSON.stringify(sortedEntries)}`;\n return fn;\n};\n\nexport type GroupNode = GroupNodeGroup | GroupNodePart;\n\nexport interface GroupNodeGroup {\n readonly type: \"group\";\n /** Current-level group key (last segment of the path). */\n readonly key: string;\n /** Structural React key: sibling-index path, e.g. `\"0.1.0\"`. */\n readonly nodeKey: string;\n /**\n * Identity key (`\"id:<partId>\"`) from the group's first part; undefined\n * when absent or already claimed by an earlier sibling.\n */\n readonly idKey: string | undefined;\n /** Indices of parts in this subtree, in order. */\n readonly indices: readonly number[];\n readonly children: readonly GroupNode[];\n}\n\nexport interface GroupNodePart {\n readonly type: \"part\";\n /** Index of the part in the message. */\n readonly index: number;\n /** Structural React key: sibling-index path within parent. */\n readonly nodeKey: string;\n /**\n * Identity key (`\"id:<partId>\"`); undefined when absent or already\n * claimed by an earlier sibling.\n */\n readonly idKey: string | undefined;\n}\n\ninterface BuildFrame {\n key: string;\n nodeKey: string;\n indices: number[];\n children: GroupNode[];\n nextChildIdx: number;\n claimed: Set<string>;\n}\n\nconst makeChildNodeKey = (parent: BuildFrame): string => {\n const idx = parent.nextChildIdx++;\n return parent.nodeKey === \"\" ? String(idx) : `${parent.nodeKey}.${idx}`;\n};\n\nconst claimIdKey = (\n frame: BuildFrame,\n id: string | undefined,\n): string | undefined => {\n if (id === undefined || frame.claimed.has(id)) return undefined;\n frame.claimed.add(id);\n return `id:${id}`;\n};\n\n/**\n * Build the group tree from an array of normalized group paths.\n * `paths[i]` is the path for part `i`. The output tree contains one\n * `part` node per part and one `group` node per coalesced run.\n * `partIds[i]` optionally carries a stable identity for part `i` (e.g. a\n * tool call id), from which nodes derive an `idKey`.\n */\nexport const buildGroupTree = (\n paths: readonly (readonly string[])[],\n partIds?: readonly (string | undefined)[],\n): readonly GroupNode[] => {\n const root: BuildFrame = {\n key: \"\",\n nodeKey: \"\",\n indices: [],\n children: [],\n nextChildIdx: 0,\n claimed: new Set(),\n };\n const stack: BuildFrame[] = [root];\n\n const closeTop = (): void => {\n const closing = stack.pop()!;\n const parent = stack[stack.length - 1]!;\n parent.children.push({\n type: \"group\",\n key: closing.key,\n nodeKey: closing.nodeKey,\n idKey: claimIdKey(parent, partIds?.[closing.indices[0]!]),\n indices: closing.indices,\n children: closing.children,\n });\n };\n\n for (let i = 0; i < paths.length; i++) {\n const path = paths[i]!;\n\n // Find the longest prefix shared between currently-open groups\n // (excluding root) and this part's path.\n let common = 0;\n while (\n common < stack.length - 1 &&\n common < path.length &&\n stack[common + 1]!.key === path[common]\n ) {\n common++;\n }\n\n // Close groups not on this path.\n while (stack.length - 1 > common) {\n closeTop();\n }\n\n // Open new groups down to the part's depth.\n while (stack.length - 1 < path.length) {\n const parent = stack[stack.length - 1]!;\n stack.push({\n key: path[stack.length - 1]!,\n nodeKey: makeChildNodeKey(parent),\n indices: [],\n children: [],\n nextChildIdx: 0,\n claimed: new Set(),\n });\n }\n\n // Push this part as a leaf in the deepest open group (or root).\n const top = stack[stack.length - 1]!;\n top.children.push({\n type: \"part\",\n index: i,\n nodeKey: makeChildNodeKey(top),\n idKey: claimIdKey(top, partIds?.[i]),\n });\n\n // Record the part index in every open ancestor group.\n for (let s = 1; s < stack.length; s++) {\n stack[s]!.indices.push(i);\n }\n }\n\n // Close any still-open groups.\n while (stack.length > 1) {\n closeTop();\n }\n\n return root.children;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAkCA,MAAa,mBAAkC,OAAO,IACpD,+BACF;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,MAAa,mBACX,QACqE;CACrE,MAAM,SAAS;CACf,MAAM,OAAO,MAAM,YAAY;EAC7B,IAAI,KAAK,SAAS,aAAa;GAC7B,MAAM,WAAW,YAAY,KAAK,KAAK,KAAK,WAAW;GAMvD,KAFE,aACC,SAAS,UAAU,KAAK,SAAS,GAAG,EAAE,EAAE,cAAc,WACrC,OAAO,4BAA4B,K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;EAIF,OAAO,MAAM,SAAS,IAAI,QACxB,SAAS;EAIX,OAAO,MAAM,SAAS,IAAI,KAAK,QAAQ;GACrC,MAAM,SAAS,MAAM,MAAM,SAAS;GACpC,MAAM,KAAK;IACT,KAAK,KAAK,MAAM,SAAS;IACzB,SAAS,iBAAiB,MAAM;IAChC,SAAS,CAAC;IACV,UAAU,CAAC;IACX,cAAc;IACd,yBAAS,IAAI,IAAI;GACnB,CAAC;EACH;EAGA,MAAM,MAAM,MAAM,MAAM,SAAS;EACjC,IAAI,SAAS,KAAK;GAChB,MAAM;GACN,OAAO;GACP,SAAS,iBAAiB,GAAG;GAC7B,OAAO,WAAW,KAAK,UAAU,EAAE;EACrC,CAAC;EAGD,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAChC,MAAM,EAAE,CAAE,QAAQ,KAAK,CAAC;CAE5B;CAGA,OAAO,MAAM,SAAS,GACpB,SAAS;CAGX,OAAO,KAAK;AACd"}
1
+ {"version":3,"file":"groupParts.js","names":["isMcpAppUri","PartState","ToolsState","GroupByContext","toolUIs","GROUPBY_MEMO_KEY","Symbol","for","GroupPartType","groupPartByType","map","Partial","Readonly","Record","TKey","part","context","lookup","fn","type","isMcpApp","mcp","app","resourceUri","isStandalone","toolName","standalone","undefined","sortedKeys","Object","keys","sort","sortedEntries","k","JSON","stringify","GroupNode","GroupNodeGroup","GroupNodePart","key","nodeKey","idKey","indices","children","index","BuildFrame","nextChildIdx","claimed","Set","makeChildNodeKey","parent","idx","String","claimIdKey","frame","id","has","add","buildGroupTree","paths","partIds","root","stack","closeTop","closing","pop","length","push","i","path","common","top","s"],"sources":["../../../src/react/utils/groupParts.ts"],"sourcesContent":["import { isMcpAppUri } from \"../../types/message\";\nimport type { PartState } from \"../../store/scopes/part\";\nimport type { ToolsState } from \"../types/scopes/tools\";\n\n/**\n * Registry context passed to a `groupBy` function as its second argument by\n * `<MessagePrimitive.GroupedParts>`. Carries the live tool-UI registry so a\n * `groupBy` can resolve registry-driven grouping (e.g. standalone tool calls)\n * without the part itself having to carry that information.\n */\nexport type GroupByContext = {\n /** Tool UIs registered in the tool-UI registry, keyed by tool name. */\n readonly toolUIs?: ToolsState[\"toolUIs\"];\n};\n\n/**\n * Hierarchical adjacent-coalescing grouping for message parts.\n *\n * Given a group path per part (from `groupBy`), builds a tree of group\n * nodes wrapping individual parts. Adjacent parts sharing a path prefix\n * coalesce into the same group; ungrouped parts are direct children of\n * the root.\n *\n * Each node gets a structural `nodeKey` built from sibling indices\n * (`\"0.1.0\"`), stable under append-only streaming.\n */\n\n/**\n * Symbol attached to memoizable `groupBy` functions (e.g. those returned\n * by {@link groupPartByType}). Carries a string fingerprint of the config\n * so `MessagePrimitive.GroupedParts` can memo the tree on\n * `[parts, memoKey]` across renders — even when the helper call site\n * reconstructs the function each render.\n */\nexport const GROUPBY_MEMO_KEY: unique symbol = Symbol.for(\n \"@assistant-ui/groupBy.memoKey\",\n);\n\n/**\n * Synthetic part-type keys recognized by {@link groupPartByType}, in\n * addition to real {@link PartState} types:\n *\n * - `\"standalone-tool-call\"` — a tool-call whose UI should be presented on its\n * own, outside the chain-of-thought grouping. Matches MCP-app tool calls plus\n * any tool-call whose registered UI opts into standalone display (human\n * tools, the built-in generative-UI tool, and tools that set\n * `display: \"standalone\"`). Resolving the registry-driven cases reads the\n * {@link GroupByContext} passed to the `groupBy` function. Takes precedence\n * over the `\"tool-call\"` entry.\n * - `\"mcp-app\"` — **deprecated**, kept for back-compat. Matches only MCP-app\n * tool calls. Prefer `\"standalone-tool-call\"`, which is a superset.\n */\ntype GroupPartType = PartState[\"type\"] | \"standalone-tool-call\" | \"mcp-app\";\n\n/**\n * Build a `groupBy` from a `part.type → group-key path` lookup.\n * Parts whose type isn't in the map are left ungrouped. The returned\n * function carries a stable {@link GROUPBY_MEMO_KEY} fingerprint so\n * `<MessagePrimitive.GroupedParts>` can memoize its tree across renders.\n *\n * The synthetic `\"standalone-tool-call\"` key matches tool calls that should\n * render outside the chain-of-thought grouping. MCP-app calls are detected from\n * the part alone; the registry-driven cases (human tools, the generative-UI\n * tool, `display: \"standalone\"` opt-ins) are resolved from the\n * {@link GroupByContext} that `<MessagePrimitive.GroupedParts>` passes to the\n * `groupBy` function — the helper needs nothing threaded into it.\n *\n * @example\n * ```tsx\n * <MessagePrimitive.GroupedParts\n * groupBy={groupPartByType({\n * reasoning: [\"group-thought\", \"group-reasoning\"],\n * \"tool-call\": [\"group-thought\", \"group-tool\"],\n * \"standalone-tool-call\": [],\n * })}\n * >\n * {({ part, children }) => { ... }}\n * </MessagePrimitive.GroupedParts>\n * ```\n */\nexport const groupPartByType = <TKey extends `group-${string}`>(\n map: Partial<Readonly<Record<GroupPartType, readonly TKey[]>>>,\n): ((part: PartState, context?: GroupByContext) => readonly TKey[]) => {\n const lookup = map as Readonly<Record<string, readonly TKey[] | undefined>>;\n const fn = ((part, context) => {\n if (part.type === \"tool-call\") {\n const isMcpApp = isMcpAppUri(part.mcp?.app?.resourceUri);\n // Read the first registration's flag — the same one `resolveToolRender`\n // renders — so grouping and rendering never disagree for a tool name.\n const isStandalone =\n isMcpApp ||\n (context?.toolUIs?.[part.toolName]?.[0]?.standalone ?? false);\n if (isStandalone && lookup[\"standalone-tool-call\"] !== undefined) {\n return lookup[\"standalone-tool-call\"]!;\n }\n // TODO(v0.15): drop the deprecated \"mcp-app\" key (superseded by \"standalone-tool-call\").\n if (isMcpApp && lookup[\"mcp-app\"] !== undefined) {\n return lookup[\"mcp-app\"]!;\n }\n }\n return lookup[part.type] ?? [];\n }) as ((part: PartState, context?: GroupByContext) => readonly TKey[]) & {\n [GROUPBY_MEMO_KEY]?: string;\n };\n // Sort keys so the fingerprint is insensitive to map insertion order —\n // two maps with the same key/value pairs but different declaration order\n // would otherwise hash differently and invalidate the memo unnecessarily.\n const sortedKeys = Object.keys(map).sort();\n const sortedEntries = sortedKeys.map((k) => [k, map[k as keyof typeof map]]);\n fn[GROUPBY_MEMO_KEY] = `groupPartByType:${JSON.stringify(sortedEntries)}`;\n return fn;\n};\n\nexport type GroupNode = GroupNodeGroup | GroupNodePart;\n\nexport interface GroupNodeGroup {\n readonly type: \"group\";\n /** Current-level group key (last segment of the path). */\n readonly key: string;\n /** Structural React key: sibling-index path, e.g. `\"0.1.0\"`. */\n readonly nodeKey: string;\n /**\n * Identity key (`\"id:<partId>\"`) from the group's first part; undefined\n * when absent or already claimed by an earlier sibling.\n */\n readonly idKey: string | undefined;\n /** Indices of parts in this subtree, in order. */\n readonly indices: readonly number[];\n readonly children: readonly GroupNode[];\n}\n\nexport interface GroupNodePart {\n readonly type: \"part\";\n /** Index of the part in the message. */\n readonly index: number;\n /** Structural React key: sibling-index path within parent. */\n readonly nodeKey: string;\n /**\n * Identity key (`\"id:<partId>\"`); undefined when absent or already\n * claimed by an earlier sibling.\n */\n readonly idKey: string | undefined;\n}\n\ninterface BuildFrame {\n key: string;\n nodeKey: string;\n indices: number[];\n children: GroupNode[];\n nextChildIdx: number;\n claimed: Set<string>;\n}\n\nconst makeChildNodeKey = (parent: BuildFrame): string => {\n const idx = parent.nextChildIdx++;\n return parent.nodeKey === \"\" ? String(idx) : `${parent.nodeKey}.${idx}`;\n};\n\nconst claimIdKey = (\n frame: BuildFrame,\n id: string | undefined,\n): string | undefined => {\n if (id === undefined || frame.claimed.has(id)) return undefined;\n frame.claimed.add(id);\n return `id:${id}`;\n};\n\n/**\n * Build the group tree from an array of normalized group paths.\n * `paths[i]` is the path for part `i`. The output tree contains one\n * `part` node per part and one `group` node per coalesced run.\n * `partIds[i]` optionally carries a stable identity for part `i` (e.g. a\n * tool call id), from which nodes derive an `idKey`.\n */\nexport const buildGroupTree = (\n paths: readonly (readonly string[])[],\n partIds?: readonly (string | undefined)[],\n): readonly GroupNode[] => {\n const root: BuildFrame = {\n key: \"\",\n nodeKey: \"\",\n indices: [],\n children: [],\n nextChildIdx: 0,\n claimed: new Set(),\n };\n const stack: BuildFrame[] = [root];\n\n const closeTop = (): void => {\n const closing = stack.pop()!;\n const parent = stack[stack.length - 1]!;\n parent.children.push({\n type: \"group\",\n key: closing.key,\n nodeKey: closing.nodeKey,\n idKey: claimIdKey(parent, partIds?.[closing.indices[0]!]),\n indices: closing.indices,\n children: closing.children,\n });\n };\n\n for (let i = 0; i < paths.length; i++) {\n const path = paths[i]!;\n\n // Find the longest prefix shared between currently-open groups\n // (excluding root) and this part's path.\n let common = 0;\n while (\n common < stack.length - 1 &&\n common < path.length &&\n stack[common + 1]!.key === path[common]\n ) {\n common++;\n }\n\n // Close groups not on this path.\n while (stack.length - 1 > common) {\n closeTop();\n }\n\n // Open new groups down to the part's depth.\n while (stack.length - 1 < path.length) {\n const parent = stack[stack.length - 1]!;\n stack.push({\n key: path[stack.length - 1]!,\n nodeKey: makeChildNodeKey(parent),\n indices: [],\n children: [],\n nextChildIdx: 0,\n claimed: new Set(),\n });\n }\n\n // Push this part as a leaf in the deepest open group (or root).\n const top = stack[stack.length - 1]!;\n top.children.push({\n type: \"part\",\n index: i,\n nodeKey: makeChildNodeKey(top),\n idKey: claimIdKey(top, partIds?.[i]),\n });\n\n // Record the part index in every open ancestor group.\n for (let s = 1; s < stack.length; s++) {\n stack[s]!.indices.push(i);\n }\n }\n\n // Close any still-open groups.\n while (stack.length > 1) {\n closeTop();\n }\n\n return root.children;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAkCA,MAAaK,mBAAkCC,OAAOC,IACpD,+BACF;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,MAAaE,mBACXC,QACqE;CACrE,MAAMO,SAASP;CACf,MAAMQ,OAAOH,MAAMC,YAAY;EAC7B,IAAID,KAAKI,SAAS,aAAa;GAC7B,MAAMC,WAAWpB,YAAYe,KAAKM,KAAKC,KAAKC,WAAW;GAMvD,KAFEH,aACCJ,SAASZ,UAAUW,KAAKU,SAAS,GAAG,EAAE,EAAEC,cAAc,WACrCT,OAAO,4BAA4BU,KAAAA,GACrD,OAAOV,OAAO;GAGhB,IAAIG,YAAYH,OAAO,eAA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ASR,MAAMI,SAAS,KACxBI,SAASD,KAAKH,UACdJ,MAAMQ,SAAS,EAAE,CAAE/B,QAAQ8B,KAAKC,SAEhCA;EAIF,OAAOR,MAAMI,SAAS,IAAII,QACxBP,SAAS;EAIX,OAAOD,MAAMI,SAAS,IAAIG,KAAKH,QAAQ;GACrC,MAAMhB,SAASY,MAAMA,MAAMI,SAAS;GACpCJ,MAAMK,KAAK;IACT5B,KAAK8B,KAAKP,MAAMI,SAAS;IACzB1B,SAASS,iBAAiBC,MAAM;IAChCR,SAAS,CAAA;IACTC,UAAU,CAAA;IACVG,cAAc;IACdC,yBAAS,IAAIC,IAAI;GACnB,CAAC;EACH;EAGA,MAAMuB,MAAMT,MAAMA,MAAMI,SAAS;EACjCK,IAAI5B,SAASwB,KAAK;GAChBhD,MAAM;GACNyB,OAAOwB;GACP5B,SAASS,iBAAiBsB,GAAG;GAC7B9B,OAAOY,WAAWkB,KAAKX,UAAUQ,EAAE;EACrC,CAAC;EAGD,KAAK,IAAII,IAAI,GAAGA,IAAIV,MAAMI,QAAQM,KAChCV,MAAMU,EAAE,CAAE9B,QAAQyB,KAAKC,CAAC;CAE5B;CAGA,OAAON,MAAMI,SAAS,GACpBH,SAAS;CAGX,OAAOF,KAAKlB;AACd"}
@@ -1 +1 @@
1
- {"version":3,"file":"assistant-runtime.js","names":[],"sources":["../../../src/runtime/api/assistant-runtime.ts"],"sourcesContent":["import type { Unsubscribe } from \"../../types/unsubscribe\";\nimport type { ModelContextProvider } from \"../../model-context/types\";\nimport type { AssistantRuntimeCore } from \"../interfaces/assistant-runtime-core\";\nimport type { ThreadRuntime } from \"./thread-runtime\";\nimport {\n type ThreadListRuntime,\n ThreadListRuntimeImpl,\n} from \"./thread-list-runtime\";\n\nexport type AssistantRuntime = {\n /**\n * The threads in this assistant.\n */\n readonly threads: ThreadListRuntime;\n\n /**\n * The currently selected main thread. Equivalent to `threads.main`.\n */\n readonly thread: ThreadRuntime;\n\n /**\n * Register a model context provider. Model context providers are configuration such as system message, temperature, etc. that are set in the frontend.\n *\n * @param provider The model context provider to register.\n */\n registerModelContextProvider(provider: ModelContextProvider): Unsubscribe;\n};\n\nexport class AssistantRuntimeImpl implements AssistantRuntime {\n public readonly threads;\n\n public readonly _thread: ThreadRuntime;\n\n public constructor(private readonly _core: AssistantRuntimeCore) {\n this.threads = new ThreadListRuntimeImpl(_core.threads);\n this._thread = this.threads.main;\n\n this.__internal_bindMethods();\n }\n\n protected __internal_bindMethods() {\n this.registerModelContextProvider =\n this.registerModelContextProvider.bind(this);\n }\n\n public get thread() {\n return this._thread;\n }\n\n public registerModelContextProvider(provider: ModelContextProvider) {\n return this._core.registerModelContextProvider(provider);\n }\n}\n"],"mappings":";;AA4BA,IAAa,uBAAb,MAA8D;CAKxB;CAJpC;CAEA;CAEA,YAAmB,OAA8C;EAA7B,KAAA,QAAA;EAClC,KAAK,UAAU,IAAI,sBAAsB,MAAM,OAAO;EACtD,KAAK,UAAU,KAAK,QAAQ;EAE5B,KAAK,uBAAuB;CAC9B;CAEA,yBAAmC;EACjC,KAAK,+BACH,KAAK,6BAA6B,KAAK,IAAI;CAC/C;CAEA,IAAW,SAAS;EAClB,OAAO,KAAK;CACd;CAEA,6BAAoC,UAAgC;EAClE,OAAO,KAAK,MAAM,6BAA6B,QAAQ;CACzD;AACF"}
1
+ {"version":3,"file":"assistant-runtime.js","names":["Unsubscribe","ModelContextProvider","AssistantRuntimeCore","ThreadRuntime","ThreadListRuntime","ThreadListRuntimeImpl","AssistantRuntime","threads","thread","registerModelContextProvider","provider","AssistantRuntimeImpl","_thread","constructor","_core","main","__internal_bindMethods","bind"],"sources":["../../../src/runtime/api/assistant-runtime.ts"],"sourcesContent":["import type { Unsubscribe } from \"../../types/unsubscribe\";\nimport type { ModelContextProvider } from \"../../model-context/types\";\nimport type { AssistantRuntimeCore } from \"../interfaces/assistant-runtime-core\";\nimport type { ThreadRuntime } from \"./thread-runtime\";\nimport {\n type ThreadListRuntime,\n ThreadListRuntimeImpl,\n} from \"./thread-list-runtime\";\n\nexport type AssistantRuntime = {\n /**\n * The threads in this assistant.\n */\n readonly threads: ThreadListRuntime;\n\n /**\n * The currently selected main thread. Equivalent to `threads.main`.\n */\n readonly thread: ThreadRuntime;\n\n /**\n * Register a model context provider. Model context providers are configuration such as system message, temperature, etc. that are set in the frontend.\n *\n * @param provider The model context provider to register.\n */\n registerModelContextProvider(provider: ModelContextProvider): Unsubscribe;\n};\n\nexport class AssistantRuntimeImpl implements AssistantRuntime {\n public readonly threads;\n\n public readonly _thread: ThreadRuntime;\n\n public constructor(private readonly _core: AssistantRuntimeCore) {\n this.threads = new ThreadListRuntimeImpl(_core.threads);\n this._thread = this.threads.main;\n\n this.__internal_bindMethods();\n }\n\n protected __internal_bindMethods() {\n this.registerModelContextProvider =\n this.registerModelContextProvider.bind(this);\n }\n\n public get thread() {\n return this._thread;\n }\n\n public registerModelContextProvider(provider: ModelContextProvider) {\n return this._core.registerModelContextProvider(provider);\n }\n}\n"],"mappings":";;AA4BA,IAAaW,uBAAb,MAA8D;CAKxBG;CAJpC;CAEA;CAEA,YAAmB,OAA8C;EAA7BA,KAAAA,QAAAA;EAClC,KAAKP,UAAU,IAAIF,sBAAsBS,MAAMP,OAAO;EACtD,KAAKK,UAAU,KAAKL,QAAQQ;EAE5B,KAAKC,uBAAuB;CAC9B;CAEA,yBAAmC;EACjC,KAAKP,+BACH,KAAKA,6BAA6BQ,KAAK,IAAI;CAC/C;CAEA,IAAWT,SAAS;EAClB,OAAO,KAAKI;CACd;CAEA,6BAAoCF,UAAgC;EAClE,OAAO,KAAKI,MAAML,6BAA6BC,QAAQ;CACzD;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"attachment-runtime.js","names":[],"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,IAAsB,wBAAtB,MAE+B;CAOT;CANpB,IAAW,OAAO;EAChB,OAAO,KAAK,MAAM;CACpB;CAIA,YAAY,OAAkD;EAA1C,KAAA,QAAA;EAClB,KAAK,uBAAuB;CAC9B;CAEA,yBAAmC;EACjC,KAAK,WAAW,KAAK,SAAS,KAAK,IAAI;EACvC,KAAK,SAAS,KAAK,OAAO,KAAK,IAAI;EACnC,KAAK,YAAY,KAAK,UAAU,KAAK,IAAI;CAC3C;CAEA,WAAwD;EACtD,OAAO,KAAK,MAAM,SAAS;CAC7B;CAIA,UAAiB,UAAsB;EACrC,OAAO,KAAK,MAAM,UAAU,QAAQ;CACtC;AACF;AAEA,IAAe,4BAAf,cAEU,sBAA8B;CAG5B;CAFV,YACE,MACA,cACA;EACA,MAAM,IAAI;EAFF,KAAA,eAAA;CAGV;CAEA,SAAgB;EACd,MAAM,OAAO,KAAK,aAAa,SAAS;EACxC,IAAI,CAAC,MAAM,MAAM,IAAI,MAAM,2BAA2B;EACtD,OAAO,KAAK,iBAAiB,KAAK,SAAS,CAAC,CAAC,EAAE;CACjD;AACF;AAEA,IAAa,sCAAb,cAAyD,0BAA6C;CACpG,IAAW,SAA4B;EACrC,OAAO;CACT;AACF;AAEA,IAAa,oCAAb,cAAuD,0BAA2C;CAChG,IAAW,SAA0B;EACnC,OAAO;CACT;AACF;AAEA,IAAa,+BAAb,cAAkD,sBAAiC;CACjF,IAAW,SAAoB;EAC7B,OAAO;CACT;CAEA,SAAuB;EACrB,MAAM,IAAI,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","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 +1 @@
1
- {"version":3,"file":"composer-runtime.js","names":[],"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,MAAM,cAAc,OAAO,OAAO,CAAC,CAAC;AACpC,MAAM,eAAe,OAAO,OAAO,CAAC,CAAC;AACrC,MAAM,0BACJ,YACwB;CACxB,OAAO,OAAO,OAAO;EACnB,MAAM;EAEN,WAAW,SAAS,aAAa;EACjC,WAAW,SAAS,aAAa;EACjC,SAAS,SAAS,WAAW;EAC7B,SAAS,SAAS,WAAW;EAE7B,aAAa,SAAS,eAAe;EACrC,MAAM,SAAS,QAAQ;EACvB,MAAM,SAAS,QAAQ;EACvB,WAAW,SAAS,aAAa;EACjC,kBAAkB,SAAS,oBAAoB;EAC/C,WAAW,SAAS;EACpB,OAAO,SAAS;EAChB,OAAO,SAAS,SAAS;EAEzB,OAAO,SAAS,QAAQ;CAC1B,CAAC;AACH;AAEA,MAAM,wBACJ,YACsB;CACtB,OAAO,OAAO,OAAO;EACnB,MAAM;EAEN,WAAW,SAAS,aAAa;EACjC,WAAW,SAAS,aAAa;EACjC,SAAS,SAAS,WAAW;EAC7B,SAAS,SAAS,WAAW;EAE7B,MAAM,SAAS,QAAQ;EACvB,MAAM,SAAS,QAAQ;EACvB,aAAa,SAAS,eAAe;EACrC,WAAW,SAAS,aAAa;EACjC,kBAAkB,SAAS,oBAAoB;EAC/C,WAAW,SAAS;EACpB,OAAO,SAAS;EACh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IAAI,CAAC,YAAY,OAAO;IAExB,OAAO;KACL,GAAG;KACH,QAAQ;IACV;GACF;GACA,YAAY,aAAa,KAAK,MAAM,UAAU,QAAQ;EACxD,CAAC,GACD,KAAK,KACP;CACF;AACF"}
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,OAAOD,SAASnB,QAAQ;CAC1B,CAAC;AACH;AAEA,MAAMqB,wBACJF,YACsB;CACtB,OAAOJ,OAAOC,OAAO;EACnBP,MAAM;EAENX,WAAWqB,SAASrB,aAAa;E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CACA2C,YACEG,MACA,YACA;EACA,MAAMgB,eAAe,IAAI9F,mBAAmB;GAC1C8C,MAAMgC,KAAKhC;GACXC,gBAAgBH,qBAAqBkC,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;EAZOuC,KAAAA,aAAAA;EAcR,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"}
@@ -1,4 +1,4 @@
1
- import { MessagePartStatus, ThreadAssistantMessagePart, ThreadUserMessagePart, ToolCallMessagePartStatus } from "../../types/message.js";
1
+ import { MessagePartStatus, ThreadAssistantMessagePart, ThreadUserMessagePart, ToolApprovalResponse, ToolCallMessagePartStatus } from "../../types/message.js";
2
2
  import { Unsubscribe } from "../../types/unsubscribe.js";
3
3
  import { MessagePartRuntimePath } from "./paths.js";
4
4
  import { SubscribableWithState } from "../../subscribable/subscribable.js";
@@ -14,10 +14,7 @@ type MessagePartSnapshotBinding = SubscribableWithState<MessagePartState, Messag
14
14
  type MessagePartRuntime = {
15
15
  addToolResult(result: any | ToolResponse<any>): void;
16
16
  resumeToolCall(payload: unknown): void;
17
- respondToToolApproval(response: {
18
- approved: boolean;
19
- reason?: string;
20
- }): void;
17
+ respondToToolApproval(response: ToolApprovalResponse): void;
21
18
  readonly path: MessagePartRuntimePath;
22
19
  getState(): MessagePartState;
23
20
  subscribe(callback: () => void): Unsubscribe;
@@ -32,10 +29,7 @@ declare class MessagePartRuntimeImpl implements MessagePartRuntime {
32
29
  getState(): MessagePartState;
33
30
  addToolResult(result: any | ToolResponse<any>): void;
34
31
  resumeToolCall(payload: unknown): void;
35
- respondToToolApproval(response: {
36
- approved: boolean;
37
- reason?: string;
38
- }): void;
32
+ respondToToolApproval(response: ToolApprovalResponse): void;
39
33
  subscribe(callback: () => void): Unsubscribe;
40
34
  }
41
35
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"message-part-runtime.d.ts","names":[],"sources":["../../../src/runtime/api/message-part-runtime.ts"],"mappings":";;;;;;;;;KAaY,gBAAA,IACR,qBAAA,GACA,0BAAA;EAAA,SAEO,MAAA,EAAQ,iBAAA,GAAoB,yBAAA;AAAA;AAAA,KAGlC,0BAAA,GAA6B,qBAAA,CAChC,gBAAA,EACA,sBAAA;AAAA,KAGU,kBAAA;EACV,aAAA,CAAc,MAAA,QAAc,YAAA;EAC5B,cAAA,CAAe,OAAA;EACf,qBAAA,CAAsB,QAAA;IAAY,QAAA;IAAmB,MAAA;EAAA;EAAA,SAE5C,IAAA,EAAM,sBAAA;EACf,QAAA,IAAY,gBAAA;EACZ,SAAA,CAAU,QAAA,eAAuB,WAAA;AAAA;AAAA,cAGtB,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AAA;AAAA"}
@@ -1,3 +1,4 @@
1
+ import { resolveToolApprovalResponse } from "../utils/resolveToolApprovalResponse.js";
1
2
  import { ToolResponse } from "assistant-stream";
2
3
  //#region src/runtime/api/message-part-runtime.ts
3
4
  var MessagePartRuntimeImpl = class {
@@ -58,13 +59,9 @@ var MessagePartRuntimeImpl = class {
58
59
  const state = this.contentBinding.getState();
59
60
  if (!state) throw new Error("Message part is not available");
60
61
  if (state.type !== "tool-call") throw new Error("Tried to respond to tool approval on non-tool message part");
61
- if (!state.approval || state.approval.approved !== void 0) throw new Error("Tool call has no pending approval");
62
+ if (!state.approval || state.approval.approved !== void 0 || state.approval.resolution !== void 0) throw new Error("Tool call has no pending approval");
62
63
  if (!this.threadApi) throw new Error("Thread API is not available");
63
- this.threadApi.getState().respondToToolApproval({
64
- approvalId: state.approval.id,
65
- approved: response.approved,
66
- ...response.reason != null && { reason: response.reason }
67
- });
64
+ this.threadApi.getState().respondToToolApproval(resolveToolApprovalResponse(state.approval, response));
68
65
  }
69
66
  subscribe(callback) {
70
67
  return this.contentBinding.subscribe(callback);
@@ -1 +1 @@
1
- {"version":3,"file":"message-part-runtime.js","names":[],"sources":["../../../src/runtime/api/message-part-runtime.ts"],"sourcesContent":["import type {\n ThreadAssistantMessagePart,\n ThreadUserMessagePart,\n ToolCallMessagePartStatus,\n} from \"../../types/message\";\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: { approved: boolean; reason?: string }): 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: {\n approved: boolean;\n reason?: string;\n }) {\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 (!state.approval || state.approval.approved !== undefined)\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.getState().respondToToolApproval({\n approvalId: state.approval.id,\n approved: response.approved,\n ...(response.reason != null && { reason: response.reason }),\n });\n }\n\n public subscribe(callback: () => void) {\n return this.contentBinding.subscribe(callback);\n }\n}\n"],"mappings":";;AAmCA,IAAa,yBAAb,MAAkE;CAMtD;CACA;CACA;CAPV,IAAW,OAAO;EAChB,OAAO,KAAK,eAAe;CAC7B;CAEA,YACE,gBACA,YACA,WACA;EAHQ,KAAA,iBAAA;EACA,KAAA,aAAA;EACA,KAAA,YAAA;EAER,KAAK,uBAAuB;CAC9B;CAEA,yBAAmC;EACjC,KAAK,gBAAgB,KAAK,cAAc,KAAK,IAAI;EACjD,KAAK,iBAAiB,KAAK,eAAe,KAAK,IAAI;EACnD,KAAK,wBAAwB,KAAK,sBAAsB,KAAK,IAAI;EACjE,KAAK,WAAW,KAAK,SAAS,KAAK,IAAI;EACvC,KAAK,YAAY,KAAK,UAAU,KAAK,IAAI;CAC3C;CAEA,WAAkB;EAChB,OAAO,KAAK,eAAe,SAAS;CACtC;CAEA,cAAqB,QAAiC;EACpD,MAAM,QAAQ,KAAK,eAAe,SAAS;EAC3C,IAAI,CAAC,OAAO,MAAM,IAAI,MAAM,+BAA+B;EAE3D,IAAI,MAAM,SAAS,aACjB,MAAM,IAAI,MAAM,mDAAmD;EAErE,IAAI,CAAC,KAAK,YACR,MAAM,IAAI,MACR,qEACF;EACF,IAAI,CAAC,KAAK,WAAW,MAAM,IAAI,MAAM,6BAA6B;EAElE,MAAM,UAAU,KAAK,WAAW,SAAS;EACzC,IAAI,CAAC,SAAS,MAAM,IAAI,MAAM,0BAA0B;EAExD,MAAM,WAAW,MAAM;EACvB,MAAM,aAAa,MAAM;EAEzB,MAAM,WAAW,aAAa,WAAW,MAAM;EAC/C,KAAK,UAAU,SAAS,CAAC,CAAC,cAAc;GACtC,WAAW,QAAQ;GACnB;GACA;GACA,QAAQ,SAAS;GACjB,UAAU,SAAS;GACnB,SAAS,SAAS;EACpB,CAAC;CACH;CAEA,eAAsB,SAAkB;EACtC,MAAM,QAAQ,KAAK,eAAe,SAAS;EAC3C,IAAI,CAAC,OAAO,MAAM,IAAI,MAAM,+BAA+B;EAE3D,IAAI,MAAM,SAAS,aACjB,MAAM,IAAI,MAAM,oDAAoD;EAEtE,IAAI,CAAC,KAAK,WAAW,MAAM,IAAI,MAAM,6BAA6B;EAElE,MAAM,aAAa,MAAM;EACzB,KAAK,UAAU,SAAS,CAAC,CAAC,eAAe;GACvC;GACA;EACF,CAAC;CACH;CAEA,sBAA6B,UAG1B;EACD,MAAM,QAAQ,KAAK,eAAe,SAAS;EAC3C,IAAI,CAAC,OAAO,MAAM,IAAI,MAAM,+BAA+B;EAE3D,IAAI,MAAM,SAAS,aACjB,MAAM,IAAI,MACR,4DACF;EAEF,IAAI,CAAC,MAAM,YAAY,MAAM,SAAS,aAAa,KAAA,GACjD,MAAM,IAAI,MAAM,mCAAmC;EAErD,IAAI,CAAC,KAAK,WAAW,MAAM,IAAI,MAAM,6BAA6B;EAElE,KAAK,UAAU,SAAS,CAAC,CAAC,sBAAsB;GAC9C,YAAY,MAAM,SAAS;GAC3B,UAAU,SAAS;GACnB,GAAI,SAAS,UAAU,QAAQ,EAAE,QAAQ,SAAS,OAAO;EAC3D,CAAC;CACH;CAEA,UAAiB,UAAsB;EACrC,OAAO,KAAK,eAAe,UAAU,QAAQ;CAC/C;AACF"}
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.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BxB,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,KAAKJ,WAAW,MAAM,IAAII,MAAM,6BAA6B;EAElE,MAAMI,aAAaL,MAAMK;EACzB,KAAKR,UAAUP,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,KAAKJ,WAAW,MAAM,IAAII,MAAM,6BAA6B;EAElE,KAAKJ,UACFP,SAAS,CAAC,CACVH,sBACChB,4BAA4B6B,MAAMW,UAAUvB,QAAQ,CACtD;CACJ;CAEA,UAAiBI,UAAsB;EACrC,OAAO,KAAKE,eAAeH,UAAUC,QAAQ;CAC/C;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"message-runtime.js","names":[],"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,MAAM,kBAAqC,OAAO,OAAO,EACvD,MAAM,WACR,CAAC;AAED,MAAa,uB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AI,sBAAsB;GACxB,MAAM;IACJ,GAAG,KAAK;IACR,KACE,KAAK,KAAK,MACV,GAAG,KAAK,KAAK,IAAI,sBAAsB,KAAK,UAAU,UAAU,EAAE;IACpE,qBAAqB;KAAE,MAAM;KAAc;IAAW;GACxD;GACA,gBAAgB;IACd,MAAM,QAAQ,KAAK,MAAM,SAAS;IAClC,MAAM,MAAM,MAAM,QAAQ,WACvB,SACC,KAAK,SAAS,eAAe,KAAK,eAAe,UACrD;IACA,IAAI,QAAQ,IAAI,OAAO;IACvB,OAAO,oBAAoB,OAAO,GAAG;GACvC;GACA,YAAY,aAAa,KAAK,MAAM,UAAU,QAAQ;EACxD,CAAC,GACD,KAAK,OACL,KAAK,cACP;CACF;CAEA,qBAA4B,KAAa;EACvC,OAAO,IAAI,6BACT,IAAI,sBAAsB;GACxB,MAAM;IACJ,GAAG,KAAK;IACR,KAAK,GAAG,KAAK,KAAK,MAAM,KAAK,KAAK,IAAI,eAAe,IAAI;IACzD,kBAAkB;IAClB,oBAAoB;KAAE,MAAM;KAAS,OAAO;IAAI;GAClD;GACA,gBAAgB;IAEd,MAAM,aADc,KAAK,SAAS,CAAC,CAAC,cACH;IACjC,IAAI,CAAC,YAAY,OAAO;IAExB,OAAO;KACL,GAAG;KACH,QAAQ;IACV;GACF;GACA,YAAY,aAAa,KAAK,MAAM,UAAU,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","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,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