@assistant-ui/core 0.2.12 → 0.2.15

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 (445) 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/thread-history.d.ts +3 -1
  5. package/dist/adapters/thread-history.d.ts.map +1 -1
  6. package/dist/adapters/voice.js.map +1 -1
  7. package/dist/index.d.ts +3 -2
  8. package/dist/index.js.map +1 -1
  9. package/dist/internal/duplicate-detection.js.map +1 -1
  10. package/dist/internal.d.ts +2 -1
  11. package/dist/internal.js +2 -1
  12. package/dist/model-context/frame/host.js.map +1 -1
  13. package/dist/model-context/frame/provider.js.map +1 -1
  14. package/dist/model-context/frame/types.js.map +1 -1
  15. package/dist/model-context/registry.js.map +1 -1
  16. package/dist/model-context/tool.js.map +1 -1
  17. package/dist/model-context/types.d.ts +1 -0
  18. package/dist/model-context/types.d.ts.map +1 -1
  19. package/dist/model-context/types.js.map +1 -1
  20. package/dist/react/AssistantProvider.js +7 -1
  21. package/dist/react/AssistantProvider.js.map +1 -1
  22. package/dist/react/AssistantRuntimeProvider.js +18 -6
  23. package/dist/react/AssistantRuntimeProvider.js.map +1 -1
  24. package/dist/react/RuntimeAdapter.d.ts +1 -1
  25. package/dist/react/RuntimeAdapter.d.ts.map +1 -1
  26. package/dist/react/RuntimeAdapter.js +35 -6
  27. package/dist/react/RuntimeAdapter.js.map +1 -1
  28. package/dist/react/adapters/LocalStorageThreadListAdapter.js +29 -7
  29. package/dist/react/adapters/LocalStorageThreadListAdapter.js.map +1 -1
  30. package/dist/react/adapters/TitleGenerationAdapter.js.map +1 -1
  31. package/dist/react/client/DataRenderers.d.ts +1 -8
  32. package/dist/react/client/DataRenderers.d.ts.map +1 -1
  33. package/dist/react/client/DataRenderers.js +56 -36
  34. package/dist/react/client/DataRenderers.js.map +1 -1
  35. package/dist/react/client/Interactables.d.ts +1 -1
  36. package/dist/react/client/Interactables.d.ts.map +1 -1
  37. package/dist/react/client/Interactables.js +71 -70
  38. package/dist/react/client/Interactables.js.map +1 -1
  39. package/dist/react/client/Tools.d.ts +2 -13
  40. package/dist/react/client/Tools.d.ts.map +1 -1
  41. package/dist/react/client/Tools.js +121 -57
  42. package/dist/react/client/Tools.js.map +1 -1
  43. package/dist/react/client/interactable-model-context.js.map +1 -1
  44. package/dist/react/model-context/define-mcp-toolkit.js.map +1 -1
  45. package/dist/react/model-context/define-toolkit.js.map +1 -1
  46. package/dist/react/model-context/external-tool.js.map +1 -1
  47. package/dist/react/model-context/human-tool.js.map +1 -1
  48. package/dist/react/model-context/makeAssistantDataUI.js.map +1 -1
  49. package/dist/react/model-context/makeAssistantTool.js.map +1 -1
  50. package/dist/react/model-context/makeAssistantToolUI.js.map +1 -1
  51. package/dist/react/model-context/provider-tool.js.map +1 -1
  52. package/dist/react/model-context/stub-tool.js.map +1 -1
  53. package/dist/react/model-context/toolbox.js.map +1 -1
  54. package/dist/react/model-context/useAssistantContext.js.map +1 -1
  55. package/dist/react/model-context/useAssistantDataUI.js +27 -8
  56. package/dist/react/model-context/useAssistantDataUI.js.map +1 -1
  57. package/dist/react/model-context/useAssistantInstructions.js +33 -10
  58. package/dist/react/model-context/useAssistantInstructions.js.map +1 -1
  59. package/dist/react/model-context/useAssistantInteractable.js.map +1 -1
  60. package/dist/react/model-context/useAssistantTool.js +59 -17
  61. package/dist/react/model-context/useAssistantTool.js.map +1 -1
  62. package/dist/react/model-context/useAssistantToolUI.js +30 -9
  63. package/dist/react/model-context/useAssistantToolUI.js.map +1 -1
  64. package/dist/react/model-context/useAuiToolOverrides.js.map +1 -1
  65. package/dist/react/model-context/useInlineRender.js +35 -8
  66. package/dist/react/model-context/useInlineRender.js.map +1 -1
  67. package/dist/react/model-context/useInteractableState.js +65 -19
  68. package/dist/react/model-context/useInteractableState.js.map +1 -1
  69. package/dist/react/model-context/useToolArgsStatus.js +42 -14
  70. package/dist/react/model-context/useToolArgsStatus.js.map +1 -1
  71. package/dist/react/primitive-hooks/useActionBarCopy.js +59 -22
  72. package/dist/react/primitive-hooks/useActionBarCopy.js.map +1 -1
  73. package/dist/react/primitive-hooks/useActionBarEdit.js +25 -7
  74. package/dist/react/primitive-hooks/useActionBarEdit.js.map +1 -1
  75. package/dist/react/primitive-hooks/useActionBarFeedback.js +49 -13
  76. package/dist/react/primitive-hooks/useActionBarFeedback.js.map +1 -1
  77. package/dist/react/primitive-hooks/useActionBarReload.js +25 -7
  78. package/dist/react/primitive-hooks/useActionBarReload.js.map +1 -1
  79. package/dist/react/primitive-hooks/useActionBarSpeak.js +28 -9
  80. package/dist/react/primitive-hooks/useActionBarSpeak.js.map +1 -1
  81. package/dist/react/primitive-hooks/useActionBarStopSpeaking.js +25 -7
  82. package/dist/react/primitive-hooks/useActionBarStopSpeaking.js.map +1 -1
  83. package/dist/react/primitive-hooks/useBranchPickerNext.js +27 -11
  84. package/dist/react/primitive-hooks/useBranchPickerNext.js.map +1 -1
  85. package/dist/react/primitive-hooks/useBranchPickerPrevious.js +27 -11
  86. package/dist/react/primitive-hooks/useBranchPickerPrevious.js.map +1 -1
  87. package/dist/react/primitive-hooks/useComposerAddAttachment.js +24 -8
  88. package/dist/react/primitive-hooks/useComposerAddAttachment.js.map +1 -1
  89. package/dist/react/primitive-hooks/useComposerCancel.js +25 -7
  90. package/dist/react/primitive-hooks/useComposerCancel.js.map +1 -1
  91. package/dist/react/primitive-hooks/useComposerDictate.js +25 -7
  92. package/dist/react/primitive-hooks/useComposerDictate.js.map +1 -1
  93. package/dist/react/primitive-hooks/useComposerSend.js +25 -7
  94. package/dist/react/primitive-hooks/useComposerSend.js.map +1 -1
  95. package/dist/react/primitive-hooks/useEditComposerCancel.js +18 -4
  96. package/dist/react/primitive-hooks/useEditComposerCancel.js.map +1 -1
  97. package/dist/react/primitive-hooks/useEditComposerSend.js +25 -7
  98. package/dist/react/primitive-hooks/useEditComposerSend.js.map +1 -1
  99. package/dist/react/primitive-hooks/useMessageBranching.js +41 -9
  100. package/dist/react/primitive-hooks/useMessageBranching.js.map +1 -1
  101. package/dist/react/primitive-hooks/useMessageError.js +4 -1
  102. package/dist/react/primitive-hooks/useMessageError.js.map +1 -1
  103. package/dist/react/primitive-hooks/useMessageReload.js +25 -7
  104. package/dist/react/primitive-hooks/useMessageReload.js.map +1 -1
  105. package/dist/react/primitive-hooks/useSuggestionTrigger.js +31 -13
  106. package/dist/react/primitive-hooks/useSuggestionTrigger.js.map +1 -1
  107. package/dist/react/primitive-hooks/useThreadIsEmpty.js +4 -1
  108. package/dist/react/primitive-hooks/useThreadIsEmpty.js.map +1 -1
  109. package/dist/react/primitive-hooks/useThreadIsRunning.js +4 -1
  110. package/dist/react/primitive-hooks/useThreadIsRunning.js.map +1 -1
  111. package/dist/react/primitive-hooks/useThreadListItemArchive.js +18 -4
  112. package/dist/react/primitive-hooks/useThreadListItemArchive.js.map +1 -1
  113. package/dist/react/primitive-hooks/useThreadListItemDelete.js +18 -4
  114. package/dist/react/primitive-hooks/useThreadListItemDelete.js.map +1 -1
  115. package/dist/react/primitive-hooks/useThreadListItemTrigger.js +18 -4
  116. package/dist/react/primitive-hooks/useThreadListItemTrigger.js.map +1 -1
  117. package/dist/react/primitive-hooks/useThreadListItemUnarchive.js +18 -4
  118. package/dist/react/primitive-hooks/useThreadListItemUnarchive.js.map +1 -1
  119. package/dist/react/primitive-hooks/useThreadListLoadMore.js +25 -7
  120. package/dist/react/primitive-hooks/useThreadListLoadMore.js.map +1 -1
  121. package/dist/react/primitive-hooks/useThreadListNew.js +18 -4
  122. package/dist/react/primitive-hooks/useThreadListNew.js.map +1 -1
  123. package/dist/react/primitive-hooks/useThreadMessages.js +4 -1
  124. package/dist/react/primitive-hooks/useThreadMessages.js.map +1 -1
  125. package/dist/react/primitive-hooks/useVoice.js +63 -13
  126. package/dist/react/primitive-hooks/useVoice.js.map +1 -1
  127. package/dist/react/primitives/chainOfThought/ChainOfThoughtParts.js +42 -7
  128. package/dist/react/primitives/chainOfThought/ChainOfThoughtParts.js.map +1 -1
  129. package/dist/react/primitives/composer/ComposerAttachments.js +67 -16
  130. package/dist/react/primitives/composer/ComposerAttachments.js.map +1 -1
  131. package/dist/react/primitives/composer/ComposerIf.js +30 -9
  132. package/dist/react/primitives/composer/ComposerIf.js.map +1 -1
  133. package/dist/react/primitives/composer/ComposerQueue.js.map +1 -1
  134. package/dist/react/primitives/generativeUI/GenerativeUI.js +55 -13
  135. package/dist/react/primitives/generativeUI/GenerativeUI.js.map +1 -1
  136. package/dist/react/primitives/message/MessageAttachments.js +68 -16
  137. package/dist/react/primitives/message/MessageAttachments.js.map +1 -1
  138. package/dist/react/primitives/message/MessageGroupedParts.d.ts +3 -2
  139. package/dist/react/primitives/message/MessageGroupedParts.d.ts.map +1 -1
  140. package/dist/react/primitives/message/MessageGroupedParts.js +6 -6
  141. package/dist/react/primitives/message/MessageGroupedParts.js.map +1 -1
  142. package/dist/react/primitives/message/MessageParts.d.ts +28 -1
  143. package/dist/react/primitives/message/MessageParts.d.ts.map +1 -1
  144. package/dist/react/primitives/message/MessageParts.js +665 -163
  145. package/dist/react/primitives/message/MessageParts.js.map +1 -1
  146. package/dist/react/primitives/message/MessageQuote.js +18 -2
  147. package/dist/react/primitives/message/MessageQuote.js.map +1 -1
  148. package/dist/react/primitives/messagePart/MessagePartInProgress.js +6 -2
  149. package/dist/react/primitives/messagePart/MessagePartInProgress.js.map +1 -1
  150. package/dist/react/primitives/part/PartMessages.js +46 -14
  151. package/dist/react/primitives/part/PartMessages.js.map +1 -1
  152. package/dist/react/primitives/thread/ThreadMessages.js +67 -10
  153. package/dist/react/primitives/thread/ThreadMessages.js.map +1 -1
  154. package/dist/react/primitives/thread/ThreadSuggestions.js +50 -10
  155. package/dist/react/primitives/thread/ThreadSuggestions.js.map +1 -1
  156. package/dist/react/primitives/threadList/ThreadListItems.js +55 -14
  157. package/dist/react/primitives/threadList/ThreadListItems.js.map +1 -1
  158. package/dist/react/primitives/threadListItem/ThreadListItemTitle.js +15 -2
  159. package/dist/react/primitives/threadListItem/ThreadListItemTitle.js.map +1 -1
  160. package/dist/react/providers/AttachmentByIndexProvider.js +57 -12
  161. package/dist/react/providers/AttachmentByIndexProvider.js.map +1 -1
  162. package/dist/react/providers/ChainOfThoughtByIndicesProvider.js +33 -11
  163. package/dist/react/providers/ChainOfThoughtByIndicesProvider.js.map +1 -1
  164. package/dist/react/providers/ChainOfThoughtPartByIndexProvider.js +29 -6
  165. package/dist/react/providers/ChainOfThoughtPartByIndexProvider.js.map +1 -1
  166. package/dist/react/providers/MessageByIndexProvider.js +49 -19
  167. package/dist/react/providers/MessageByIndexProvider.js.map +1 -1
  168. package/dist/react/providers/PartByIndexProvider.js +29 -6
  169. package/dist/react/providers/PartByIndexProvider.js.map +1 -1
  170. package/dist/react/providers/QueueItemByIndexProvider.js +29 -6
  171. package/dist/react/providers/QueueItemByIndexProvider.js.map +1 -1
  172. package/dist/react/providers/ReadonlyThreadProvider.js +83 -28
  173. package/dist/react/providers/ReadonlyThreadProvider.js.map +1 -1
  174. package/dist/react/providers/SuggestionByIndexProvider.js +29 -6
  175. package/dist/react/providers/SuggestionByIndexProvider.js.map +1 -1
  176. package/dist/react/providers/TextMessagePartProvider.d.ts.map +1 -1
  177. package/dist/react/providers/TextMessagePartProvider.js +75 -26
  178. package/dist/react/providers/TextMessagePartProvider.js.map +1 -1
  179. package/dist/react/providers/ThreadListItemByIndexProvider.js +30 -6
  180. package/dist/react/providers/ThreadListItemByIndexProvider.js.map +1 -1
  181. package/dist/react/providers/ThreadListItemRuntimeProvider.js +28 -5
  182. package/dist/react/providers/ThreadListItemRuntimeProvider.js.map +1 -1
  183. package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts +2 -0
  184. package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts.map +1 -1
  185. package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js +19 -4
  186. package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js.map +1 -1
  187. package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts +2 -0
  188. package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -1
  189. package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js +1 -0
  190. package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js.map +1 -1
  191. package/dist/react/runtimes/RuntimeAdapterProvider.js +27 -10
  192. package/dist/react/runtimes/RuntimeAdapterProvider.js.map +1 -1
  193. package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.d.ts.map +1 -1
  194. package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js +16 -1
  195. package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js.map +1 -1
  196. package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.js.map +1 -1
  197. package/dist/react/runtimes/cloud/auiV0.js.map +1 -1
  198. package/dist/react/runtimes/cloud/useCloudThreadListAdapter.d.ts.map +1 -1
  199. package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js +19 -17
  200. package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js.map +1 -1
  201. package/dist/react/runtimes/createMessageConverter.js.map +1 -1
  202. package/dist/react/runtimes/external-message-converter.d.ts.map +1 -1
  203. package/dist/react/runtimes/external-message-converter.js +67 -30
  204. package/dist/react/runtimes/external-message-converter.js.map +1 -1
  205. package/dist/react/runtimes/useExternalStoreRuntime.js +44 -10
  206. package/dist/react/runtimes/useExternalStoreRuntime.js.map +1 -1
  207. package/dist/react/runtimes/useExternalStoreSharedOptions.js +17 -12
  208. package/dist/react/runtimes/useExternalStoreSharedOptions.js.map +1 -1
  209. package/dist/react/runtimes/useLocalRuntime.js.map +1 -1
  210. package/dist/react/runtimes/useRemoteThreadListRuntime.js +34 -6
  211. package/dist/react/runtimes/useRemoteThreadListRuntime.js.map +1 -1
  212. package/dist/react/types/MessagePartComponentTypes.d.ts +5 -6
  213. package/dist/react/types/MessagePartComponentTypes.d.ts.map +1 -1
  214. package/dist/react/utils/getMessageQuote.js.map +1 -1
  215. package/dist/react/utils/groupParts.d.ts +13 -1
  216. package/dist/react/utils/groupParts.d.ts.map +1 -1
  217. package/dist/react/utils/groupParts.js +17 -5
  218. package/dist/react/utils/groupParts.js.map +1 -1
  219. package/dist/runtime/api/assistant-runtime.js.map +1 -1
  220. package/dist/runtime/api/attachment-runtime.js.map +1 -1
  221. package/dist/runtime/api/bindings.d.ts +1 -0
  222. package/dist/runtime/api/bindings.d.ts.map +1 -1
  223. package/dist/runtime/api/composer-runtime.js.map +1 -1
  224. package/dist/runtime/api/message-part-runtime.d.ts +3 -9
  225. package/dist/runtime/api/message-part-runtime.d.ts.map +1 -1
  226. package/dist/runtime/api/message-part-runtime.js +3 -6
  227. package/dist/runtime/api/message-part-runtime.js.map +1 -1
  228. package/dist/runtime/api/message-runtime.d.ts +2 -0
  229. package/dist/runtime/api/message-runtime.d.ts.map +1 -1
  230. package/dist/runtime/api/message-runtime.js +5 -0
  231. package/dist/runtime/api/message-runtime.js.map +1 -1
  232. package/dist/runtime/api/thread-list-item-runtime.js.map +1 -1
  233. package/dist/runtime/api/thread-list-runtime.d.ts.map +1 -1
  234. package/dist/runtime/api/thread-list-runtime.js +1 -0
  235. package/dist/runtime/api/thread-list-runtime.js.map +1 -1
  236. package/dist/runtime/api/thread-runtime.d.ts +3 -0
  237. package/dist/runtime/api/thread-runtime.d.ts.map +1 -1
  238. package/dist/runtime/api/thread-runtime.js +4 -0
  239. package/dist/runtime/api/thread-runtime.js.map +1 -1
  240. package/dist/runtime/base/base-assistant-runtime-core.js.map +1 -1
  241. package/dist/runtime/base/base-composer-runtime-core.js.map +1 -1
  242. package/dist/runtime/base/base-thread-runtime-core.d.ts +1 -0
  243. package/dist/runtime/base/base-thread-runtime-core.d.ts.map +1 -1
  244. package/dist/runtime/base/base-thread-runtime-core.js.map +1 -1
  245. package/dist/runtime/base/default-edit-composer-runtime-core.js.map +1 -1
  246. package/dist/runtime/base/default-thread-composer-runtime-core.js.map +1 -1
  247. package/dist/runtime/branch/external-thread-branch-adapter.d.ts +30 -0
  248. package/dist/runtime/branch/external-thread-branch-adapter.d.ts.map +1 -0
  249. package/dist/runtime/branch/external-thread-branch-adapter.js +0 -0
  250. package/dist/runtime/interfaces/thread-list-runtime-core.d.ts +1 -0
  251. package/dist/runtime/interfaces/thread-list-runtime-core.d.ts.map +1 -1
  252. package/dist/runtime/interfaces/thread-runtime-core.d.ts +4 -1
  253. package/dist/runtime/interfaces/thread-runtime-core.d.ts.map +1 -1
  254. package/dist/runtime/queue/message-queue.js.map +1 -1
  255. package/dist/runtime/utils/auto-status.js.map +1 -1
  256. package/dist/runtime/utils/external-store-message.js.map +1 -1
  257. package/dist/runtime/utils/message-repository.js.map +1 -1
  258. package/dist/runtime/utils/resolveToolApprovalResponse.d.ts +15 -0
  259. package/dist/runtime/utils/resolveToolApprovalResponse.d.ts.map +1 -0
  260. package/dist/runtime/utils/resolveToolApprovalResponse.js +35 -0
  261. package/dist/runtime/utils/resolveToolApprovalResponse.js.map +1 -0
  262. package/dist/runtime/utils/thread-message-like.d.ts +5 -1
  263. package/dist/runtime/utils/thread-message-like.d.ts.map +1 -1
  264. package/dist/runtime/utils/thread-message-like.js.map +1 -1
  265. package/dist/runtimes/assistant-transport/utils.js.map +1 -1
  266. package/dist/runtimes/external-store/external-store-adapter.d.ts +1 -0
  267. package/dist/runtimes/external-store/external-store-adapter.d.ts.map +1 -1
  268. package/dist/runtimes/external-store/external-store-runtime-core.js.map +1 -1
  269. package/dist/runtimes/external-store/external-store-shared-options.js.map +1 -1
  270. package/dist/runtimes/external-store/external-store-thread-list-runtime-core.js.map +1 -1
  271. package/dist/runtimes/external-store/external-store-thread-runtime-core.d.ts +1 -0
  272. package/dist/runtimes/external-store/external-store-thread-runtime-core.d.ts.map +1 -1
  273. package/dist/runtimes/external-store/external-store-thread-runtime-core.js +13 -0
  274. package/dist/runtimes/external-store/external-store-thread-runtime-core.js.map +1 -1
  275. package/dist/runtimes/external-store/thread-message-converter.js.map +1 -1
  276. package/dist/runtimes/local/local-runtime-core.js.map +1 -1
  277. package/dist/runtimes/local/local-runtime-options.d.ts +1 -1
  278. package/dist/runtimes/local/local-thread-list-runtime-core.js.map +1 -1
  279. package/dist/runtimes/local/local-thread-runtime-core.d.ts +9 -1
  280. package/dist/runtimes/local/local-thread-runtime-core.d.ts.map +1 -1
  281. package/dist/runtimes/local/local-thread-runtime-core.js +65 -5
  282. package/dist/runtimes/local/local-thread-runtime-core.js.map +1 -1
  283. package/dist/runtimes/local/should-continue.js +4 -2
  284. package/dist/runtimes/local/should-continue.js.map +1 -1
  285. package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.d.ts +2 -0
  286. package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.d.ts.map +1 -1
  287. package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.js +4 -0
  288. package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.js.map +1 -1
  289. package/dist/runtimes/remote-thread-list/adapter/in-memory.js.map +1 -1
  290. package/dist/runtimes/remote-thread-list/empty-thread-core.d.ts.map +1 -1
  291. package/dist/runtimes/remote-thread-list/empty-thread-core.js +4 -0
  292. package/dist/runtimes/remote-thread-list/empty-thread-core.js.map +1 -1
  293. package/dist/runtimes/remote-thread-list/optimistic-state.js.map +1 -1
  294. package/dist/runtimes/remote-thread-list/remote-thread-state.d.ts +1 -0
  295. package/dist/runtimes/remote-thread-list/remote-thread-state.d.ts.map +1 -1
  296. package/dist/runtimes/remote-thread-list/remote-thread-state.js +1 -0
  297. package/dist/runtimes/remote-thread-list/remote-thread-state.js.map +1 -1
  298. package/dist/runtimes/remote-thread-list/types.d.ts +1 -0
  299. package/dist/runtimes/remote-thread-list/types.d.ts.map +1 -1
  300. package/dist/runtimes/tool-invocations/ToolInvocationTracker.js.map +1 -1
  301. package/dist/store/clients/chain-of-thought-client.d.ts +2 -7
  302. package/dist/store/clients/chain-of-thought-client.d.ts.map +1 -1
  303. package/dist/store/clients/chain-of-thought-client.js +39 -20
  304. package/dist/store/clients/chain-of-thought-client.js.map +1 -1
  305. package/dist/store/clients/model-context-client.d.ts +1 -1
  306. package/dist/store/clients/model-context-client.d.ts.map +1 -1
  307. package/dist/store/clients/model-context-client.js +67 -16
  308. package/dist/store/clients/model-context-client.js.map +1 -1
  309. package/dist/store/clients/no-op-composer-client.d.ts +2 -4
  310. package/dist/store/clients/no-op-composer-client.d.ts.map +1 -1
  311. package/dist/store/clients/no-op-composer-client.js +96 -54
  312. package/dist/store/clients/no-op-composer-client.js.map +1 -1
  313. package/dist/store/clients/runtime-adapter.d.ts +1 -3
  314. package/dist/store/clients/runtime-adapter.d.ts.map +1 -1
  315. package/dist/store/clients/runtime-adapter.js +2 -15
  316. package/dist/store/clients/runtime-adapter.js.map +1 -1
  317. package/dist/store/clients/suggestions.d.ts +1 -4
  318. package/dist/store/clients/suggestions.d.ts.map +1 -1
  319. package/dist/store/clients/suggestions.js +63 -23
  320. package/dist/store/clients/suggestions.js.map +1 -1
  321. package/dist/store/clients/thread-message-client.d.ts +1 -1
  322. package/dist/store/clients/thread-message-client.d.ts.map +1 -1
  323. package/dist/store/clients/thread-message-client.js +184 -73
  324. package/dist/store/clients/thread-message-client.js.map +1 -1
  325. package/dist/store/internal.d.ts +2 -2
  326. package/dist/store/internal.js +2 -2
  327. package/dist/store/runtime-clients/attachment-runtime-client.d.ts +2 -4
  328. package/dist/store/runtime-clients/attachment-runtime-client.d.ts.map +1 -1
  329. package/dist/store/runtime-clients/attachment-runtime-client.js +31 -7
  330. package/dist/store/runtime-clients/attachment-runtime-client.js.map +1 -1
  331. package/dist/store/runtime-clients/composer-runtime-client.d.ts +2 -10
  332. package/dist/store/runtime-clients/composer-runtime-client.d.ts.map +1 -1
  333. package/dist/store/runtime-clients/composer-runtime-client.js +195 -72
  334. package/dist/store/runtime-clients/composer-runtime-client.js.map +1 -1
  335. package/dist/store/runtime-clients/liveRef.d.ts +7 -0
  336. package/dist/store/runtime-clients/liveRef.d.ts.map +1 -0
  337. package/dist/store/runtime-clients/liveRef.js +8 -0
  338. package/dist/store/runtime-clients/liveRef.js.map +1 -0
  339. package/dist/store/runtime-clients/message-part-runtime-client.d.ts +2 -4
  340. package/dist/store/runtime-clients/message-part-runtime-client.d.ts.map +1 -1
  341. package/dist/store/runtime-clients/message-part-runtime-client.js +49 -9
  342. package/dist/store/runtime-clients/message-part-runtime-client.js.map +1 -1
  343. package/dist/store/runtime-clients/message-runtime-client.d.ts +2 -7
  344. package/dist/store/runtime-clients/message-runtime-client.d.ts.map +1 -1
  345. package/dist/store/runtime-clients/message-runtime-client.js +220 -54
  346. package/dist/store/runtime-clients/message-runtime-client.js.map +1 -1
  347. package/dist/store/runtime-clients/thread-list-item-runtime-client.d.ts +2 -4
  348. package/dist/store/runtime-clients/thread-list-item-runtime-client.d.ts.map +1 -1
  349. package/dist/store/runtime-clients/thread-list-item-runtime-client.js +71 -26
  350. package/dist/store/runtime-clients/thread-list-item-runtime-client.js.map +1 -1
  351. package/dist/store/runtime-clients/thread-list-runtime-client.d.ts +2 -5
  352. package/dist/store/runtime-clients/thread-list-runtime-client.d.ts.map +1 -1
  353. package/dist/store/runtime-clients/thread-list-runtime-client.js +141 -36
  354. package/dist/store/runtime-clients/thread-list-runtime-client.js.map +1 -1
  355. package/dist/store/runtime-clients/thread-runtime-client.d.ts +2 -4
  356. package/dist/store/runtime-clients/thread-runtime-client.d.ts.map +1 -1
  357. package/dist/store/runtime-clients/thread-runtime-client.js +196 -72
  358. package/dist/store/runtime-clients/thread-runtime-client.js.map +1 -1
  359. package/dist/store/runtime-clients/useSubscribable.js +2 -9
  360. package/dist/store/runtime-clients/useSubscribable.js.map +1 -1
  361. package/dist/store/scopes/message.d.ts +1 -0
  362. package/dist/store/scopes/message.d.ts.map +1 -1
  363. package/dist/store/scopes/part.d.ts +5 -6
  364. package/dist/store/scopes/part.d.ts.map +1 -1
  365. package/dist/store/scopes/queue-item.js.map +1 -1
  366. package/dist/store/scopes/thread-list-item.d.ts +1 -0
  367. package/dist/store/scopes/thread-list-item.d.ts.map +1 -1
  368. package/dist/store/scopes/thread.d.ts +1 -0
  369. package/dist/store/scopes/thread.d.ts.map +1 -1
  370. package/dist/subscribable/subscribable.js.map +1 -1
  371. package/dist/tests/remote-thread-list-test-helpers.js.map +1 -1
  372. package/dist/types/message.d.ts +38 -5
  373. package/dist/types/message.d.ts.map +1 -1
  374. package/dist/types/message.js.map +1 -1
  375. package/dist/utils/composite-context-provider.js.map +1 -1
  376. package/dist/utils/id.js.map +1 -1
  377. package/dist/utils/json/is-json-equal.js.map +1 -1
  378. package/dist/utils/json/is-json.js.map +1 -1
  379. package/dist/utils/text.js.map +1 -1
  380. package/package.json +6 -6
  381. package/src/adapters/thread-history.ts +2 -0
  382. package/src/index.ts +5 -0
  383. package/src/internal.ts +1 -0
  384. package/src/model-context/types.ts +1 -0
  385. package/src/react/AssistantProvider.tsx +10 -1
  386. package/src/react/RuntimeAdapter.ts +25 -8
  387. package/src/react/client/DataRenderers.ts +42 -45
  388. package/src/react/client/Interactables.ts +261 -261
  389. package/src/react/client/Tools.ts +9 -9
  390. package/src/react/primitives/message/MessageGroupedParts.tsx +19 -7
  391. package/src/react/primitives/message/MessageParts.tsx +64 -13
  392. package/src/react/providers/TextMessagePartProvider.tsx +5 -3
  393. package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.tsx +1 -0
  394. package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.ts +11 -0
  395. package/src/react/runtimes/cloud/useCloudThreadListAdapter.tsx +6 -0
  396. package/src/react/runtimes/external-message-converter.ts +3 -1
  397. package/src/react/types/MessagePartComponentTypes.ts +5 -5
  398. package/src/react/utils/groupParts.ts +27 -0
  399. package/src/runtime/api/bindings.ts +1 -0
  400. package/src/runtime/api/message-part-runtime.ts +14 -11
  401. package/src/runtime/api/message-runtime.ts +7 -0
  402. package/src/runtime/api/thread-list-runtime.ts +1 -0
  403. package/src/runtime/api/thread-runtime.ts +7 -0
  404. package/src/runtime/base/base-thread-runtime-core.ts +1 -0
  405. package/src/runtime/branch/external-thread-branch-adapter.ts +26 -0
  406. package/src/runtime/interfaces/thread-list-runtime-core.ts +1 -0
  407. package/src/runtime/interfaces/thread-runtime-core.ts +4 -0
  408. package/src/runtime/utils/resolveToolApprovalResponse.test.ts +91 -0
  409. package/src/runtime/utils/resolveToolApprovalResponse.ts +55 -0
  410. package/src/runtime/utils/thread-message-like.ts +10 -1
  411. package/src/runtimes/external-store/external-store-adapter.ts +1 -0
  412. package/src/runtimes/external-store/external-store-thread-runtime-core.ts +24 -0
  413. package/src/runtimes/local/local-runtime-options.ts +1 -1
  414. package/src/runtimes/local/local-thread-runtime-core.test.ts +370 -0
  415. package/src/runtimes/local/local-thread-runtime-core.ts +113 -7
  416. package/src/runtimes/local/should-continue.ts +24 -13
  417. package/src/runtimes/readonly/ReadonlyThreadRuntimeCore.ts +5 -0
  418. package/src/runtimes/remote-thread-list/empty-thread-core.ts +5 -0
  419. package/src/runtimes/remote-thread-list/remote-thread-state.ts +2 -0
  420. package/src/runtimes/remote-thread-list/types.ts +1 -0
  421. package/src/store/clients/chain-of-thought-client.ts +5 -3
  422. package/src/store/clients/model-context-client.test.ts +5 -4
  423. package/src/store/clients/model-context-client.ts +21 -21
  424. package/src/store/clients/no-op-composer-client.ts +5 -3
  425. package/src/store/clients/runtime-adapter.ts +0 -24
  426. package/src/store/clients/suggestions.ts +12 -23
  427. package/src/store/clients/thread-message-client.ts +42 -40
  428. package/src/store/internal.ts +1 -4
  429. package/src/store/runtime-clients/attachment-runtime-client.ts +14 -14
  430. package/src/store/runtime-clients/composer-runtime-client.ts +48 -45
  431. package/src/store/runtime-clients/liveRef.ts +5 -0
  432. package/src/store/runtime-clients/message-part-runtime-client.ts +5 -3
  433. package/src/store/runtime-clients/message-runtime-client.ts +42 -40
  434. package/src/store/runtime-clients/thread-list-item-runtime-client.ts +5 -3
  435. package/src/store/runtime-clients/thread-list-runtime-client.ts +13 -11
  436. package/src/store/runtime-clients/thread-runtime-client.ts +20 -16
  437. package/src/store/runtime-clients/useSubscribable.ts +2 -10
  438. package/src/store/scopes/message.ts +1 -0
  439. package/src/store/scopes/part.ts +5 -2
  440. package/src/store/scopes/thread-list-item.ts +1 -0
  441. package/src/store/scopes/thread.ts +1 -0
  442. package/src/tests/external-store-thread-runtime-core.test.ts +57 -0
  443. package/src/tests/groupMessageParts.test.ts +84 -0
  444. package/src/tests/groupParts.test.ts +55 -0
  445. package/src/types/message.ts +45 -3
@@ -1 +1 @@
1
- {"version":3,"file":"thread-message-converter.js","names":[],"sources":["../../../src/runtimes/external-store/thread-message-converter.ts"],"sourcesContent":["import type { ThreadMessage } from \"../../types/message\";\n\nexport type ConverterCallback<TIn> = (\n cache: ThreadMessage | undefined,\n message: TIn,\n idx: number,\n) => ThreadMessage;\n\nexport class ThreadMessageConverter {\n private readonly cache = new WeakMap<WeakKey, ThreadMessage>();\n\n convertMessages<TIn extends WeakKey>(\n messages: readonly TIn[],\n converter: ConverterCallback<TIn>,\n ): ThreadMessage[] {\n return messages.map((m, idx) => {\n const cached = this.cache.get(m);\n const newMessage = converter(cached, m, idx);\n this.cache.set(m, newMessage);\n return newMessage;\n });\n }\n}\n"],"mappings":";AAQA,IAAa,yBAAb,MAAoC;CAClC,wBAAyB,IAAI,QAAgC;CAE7D,gBACE,UACA,WACiB;EACjB,OAAO,SAAS,KAAK,GAAG,QAAQ;GAE9B,MAAM,aAAa,UADJ,KAAK,MAAM,IAAI,CACI,GAAG,GAAG,GAAG;GAC3C,KAAK,MAAM,IAAI,GAAG,UAAU;GAC5B,OAAO;EACT,CAAC;CACH;AACF"}
1
+ {"version":3,"file":"thread-message-converter.js","names":["ThreadMessage","ConverterCallback","cache","message","TIn","idx","ThreadMessageConverter","WeakMap","WeakKey","convertMessages","messages","converter","map","m","cached","get","newMessage","set"],"sources":["../../../src/runtimes/external-store/thread-message-converter.ts"],"sourcesContent":["import type { ThreadMessage } from \"../../types/message\";\n\nexport type ConverterCallback<TIn> = (\n cache: ThreadMessage | undefined,\n message: TIn,\n idx: number,\n) => ThreadMessage;\n\nexport class ThreadMessageConverter {\n private readonly cache = new WeakMap<WeakKey, ThreadMessage>();\n\n convertMessages<TIn extends WeakKey>(\n messages: readonly TIn[],\n converter: ConverterCallback<TIn>,\n ): ThreadMessage[] {\n return messages.map((m, idx) => {\n const cached = this.cache.get(m);\n const newMessage = converter(cached, m, idx);\n this.cache.set(m, newMessage);\n return newMessage;\n });\n }\n}\n"],"mappings":";AAQA,IAAaM,yBAAb,MAAoC;CAClC,wBAAyB,IAAIC,QAAgC;CAE7DE,gBACEC,UACAC,WACiB;EACjB,OAAOD,SAASE,KAAKC,GAAGR,QAAQ;GAE9B,MAAMW,aAAaL,UADJ,KAAKT,MAAMa,IAAIF,CACDC,GAAQD,GAAGR,GAAG;GAC3C,KAAKH,MAAMe,IAAIJ,GAAGG,UAAU;GAC5B,OAAOA;EACT,CAAC;CACH;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"local-runtime-core.js","names":[],"sources":["../../../src/runtimes/local/local-runtime-core.ts"],"sourcesContent":["import { BaseAssistantRuntimeCore } from \"../../runtime/base/base-assistant-runtime-core\";\nimport { LocalThreadRuntimeCore } from \"./local-thread-runtime-core\";\nimport type { LocalRuntimeOptionsBase } from \"./local-runtime-options\";\nimport { LocalThreadListRuntimeCore } from \"./local-thread-list-runtime-core\";\nimport { ExportedMessageRepository } from \"../../runtime/utils/message-repository\";\nimport type { ThreadMessageLike } from \"../../runtime/utils/thread-message-like\";\n\nexport class LocalRuntimeCore extends BaseAssistantRuntimeCore {\n public readonly threads;\n public readonly Provider = undefined;\n\n private _options: LocalRuntimeOptionsBase;\n\n constructor(\n options: LocalRuntimeOptionsBase,\n initialMessages: readonly ThreadMessageLike[] | undefined,\n ) {\n super();\n\n this._options = options;\n\n this.threads = new LocalThreadListRuntimeCore(() => {\n return new LocalThreadRuntimeCore(this._contextProvider, this._options);\n });\n\n if (initialMessages) {\n this.threads\n .getMainThreadRuntimeCore()\n .import(ExportedMessageRepository.fromArray(initialMessages));\n }\n }\n}\n"],"mappings":";;;;;AAOA,IAAa,mBAAb,cAAsC,yBAAyB;CAC7D;CACA,WAA2B,KAAA;CAE3B;CAEA,YACE,SACA,iBACA;EACA,MAAM;EAEN,KAAK,WAAW;EAEhB,KAAK,UAAU,IAAI,iCAAiC;GAClD,OAAO,IAAI,uBAAuB,KAAK,kBAAkB,KAAK,QAAQ;EACxE,CAAC;EAED,IAAI,iBACF,KAAK,QACF,yBAAyB,CAAC,CAC1B,OAAO,0BAA0B,UAAU,eAAe,CAAC;CAElE;AACF"}
1
+ {"version":3,"file":"local-runtime-core.js","names":["BaseAssistantRuntimeCore","LocalThreadRuntimeCore","LocalRuntimeOptionsBase","LocalThreadListRuntimeCore","ExportedMessageRepository","ThreadMessageLike","LocalRuntimeCore","threads","Provider","undefined","_options","constructor","options","initialMessages","_contextProvider","getMainThreadRuntimeCore","import","fromArray"],"sources":["../../../src/runtimes/local/local-runtime-core.ts"],"sourcesContent":["import { BaseAssistantRuntimeCore } from \"../../runtime/base/base-assistant-runtime-core\";\nimport { LocalThreadRuntimeCore } from \"./local-thread-runtime-core\";\nimport type { LocalRuntimeOptionsBase } from \"./local-runtime-options\";\nimport { LocalThreadListRuntimeCore } from \"./local-thread-list-runtime-core\";\nimport { ExportedMessageRepository } from \"../../runtime/utils/message-repository\";\nimport type { ThreadMessageLike } from \"../../runtime/utils/thread-message-like\";\n\nexport class LocalRuntimeCore extends BaseAssistantRuntimeCore {\n public readonly threads;\n public readonly Provider = undefined;\n\n private _options: LocalRuntimeOptionsBase;\n\n constructor(\n options: LocalRuntimeOptionsBase,\n initialMessages: readonly ThreadMessageLike[] | undefined,\n ) {\n super();\n\n this._options = options;\n\n this.threads = new LocalThreadListRuntimeCore(() => {\n return new LocalThreadRuntimeCore(this._contextProvider, this._options);\n });\n\n if (initialMessages) {\n this.threads\n .getMainThreadRuntimeCore()\n .import(ExportedMessageRepository.fromArray(initialMessages));\n }\n }\n}\n"],"mappings":";;;;;AAOA,IAAaM,mBAAb,cAAsCN,yBAAyB;CAC7D;CACA,WAA2BS,KAAAA;CAE3B;CAEAE,YACEC,SACAC,iBACA;EACA,MAAM;EAEN,KAAKH,WAAWE;EAEhB,KAAKL,UAAU,IAAIJ,iCAAiC;GAClD,OAAO,IAAIF,uBAAuB,KAAKa,kBAAkB,KAAKJ,QAAQ;EACxE,CAAC;EAED,IAAIG,iBACF,KAAKN,QACFQ,yBAAyB,CAAC,CAC1BC,OAAOZ,0BAA0Ba,UAAUJ,eAAe,CAAC;CAElE;AACF"}
@@ -20,7 +20,7 @@ type LocalRuntimeOptionsBase = {
20
20
  suggestion?: SuggestionAdapter | undefined;
21
21
  };
22
22
  /**
23
- * Names of tools that are allowed to interrupt the run in order to wait for human/external approval.
23
+ * Names of tools that pause the run until a result is supplied via `addToolResult`.
24
24
  */
25
25
  unstable_humanToolNames?: string[] | undefined;
26
26
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"local-thread-list-runtime-core.js","names":[],"sources":["../../../src/runtimes/local/local-thread-list-runtime-core.ts"],"sourcesContent":["import type { ThreadListRuntimeCore } from \"../../runtime/interfaces/thread-list-runtime-core\";\nimport { BaseSubscribable } from \"../../subscribable/subscribable\";\nimport type { LocalThreadRuntimeCore } from \"./local-thread-runtime-core\";\n\nexport type LocalThreadFactory = () => LocalThreadRuntimeCore;\n\nconst EMPTY_ARRAY = Object.freeze([]);\nconst DEFAULT_THREAD_ID = \"__DEFAULT_ID__\";\nconst DEFAULT_THREAD_DATA = Object.freeze({\n [DEFAULT_THREAD_ID]: {\n id: DEFAULT_THREAD_ID,\n remoteId: undefined,\n externalId: undefined,\n status: \"regular\" as const,\n title: undefined,\n },\n});\nexport class LocalThreadListRuntimeCore\n extends BaseSubscribable\n implements ThreadListRuntimeCore\n{\n private _mainThread: LocalThreadRuntimeCore;\n constructor(_threadFactory: LocalThreadFactory) {\n super();\n\n this._mainThread = _threadFactory();\n }\n\n public get isLoading() {\n return false;\n }\n\n public getMainThreadRuntimeCore() {\n return this._mainThread;\n }\n\n public get newThreadId(): string | undefined {\n return undefined;\n }\n\n public get threadIds(): readonly string[] {\n return EMPTY_ARRAY;\n }\n\n public get archivedThreadIds(): readonly string[] {\n return EMPTY_ARRAY;\n }\n\n public get mainThreadId(): string {\n return DEFAULT_THREAD_ID;\n }\n\n public get threadItems() {\n return DEFAULT_THREAD_DATA;\n }\n\n public getThreadRuntimeCore(): never {\n throw new Error(\"Method not implemented.\");\n }\n\n public getLoadThreadsPromise(): Promise<void> {\n return Promise.resolve();\n }\n\n public getItemById(threadId: string) {\n if (threadId === this.mainThreadId) {\n return {\n status: \"regular\" as const,\n id: this.mainThreadId,\n remoteId: this.mainThreadId,\n externalId: undefined,\n title: undefined,\n isMain: true,\n };\n }\n throw new Error(\"Method not implemented\");\n }\n\n public async switchToThread(): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n\n public switchToNewThread(): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n\n public rename(): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n\n public archive(): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n\n public detach(): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n\n public unarchive(): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n\n public delete(): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n\n public initialize(\n threadId: string,\n ): Promise<{ remoteId: string; externalId: string | undefined }> {\n return Promise.resolve({ remoteId: threadId, externalId: undefined });\n }\n\n public generateTitle(): never {\n throw new Error(\"Method not implemented.\");\n }\n}\n"],"mappings":";;AAMA,MAAM,cAAc,OAAO,OAAO,CAAC,CAAC;AACpC,MAAM,oBAAoB;AAC1B,MAAM,sBAAsB,OAAO,OAAO,GACvC,oBAAoB;CACnB,IAAI;CACJ,UAA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B;CAC3C;AACF"}
1
+ {"version":3,"file":"local-thread-list-runtime-core.js","names":["ThreadListRuntimeCore","BaseSubscribable","LocalThreadRuntimeCore","LocalThreadFactory","EMPTY_ARRAY","Object","freeze","DEFAULT_THREAD_ID","DEFAULT_THREAD_DATA","id","remoteId","undefined","externalId","status","const","title","LocalThreadListRuntimeCore","_mainThread","constructor","_threadFactory","isLoading","getMainThreadRuntimeCore","newThreadId","threadIds","archivedThreadIds","mainThreadId","threadItems","getThreadRuntimeCore","Error","getLoadThreadsPromise","Promise","resolve","getItemById","threadId","isMain","switchToThread","switchToNewThread","rename","archive","detach","unarchive","delete","initialize","generateTitle"],"sources":["../../../src/runtimes/local/local-thread-list-runtime-core.ts"],"sourcesContent":["import type { ThreadListRuntimeCore } from \"../../runtime/interfaces/thread-list-runtime-core\";\nimport { BaseSubscribable } from \"../../subscribable/subscribable\";\nimport type { LocalThreadRuntimeCore } from \"./local-thread-runtime-core\";\n\nexport type LocalThreadFactory = () => LocalThreadRuntimeCore;\n\nconst EMPTY_ARRAY = Object.freeze([]);\nconst DEFAULT_THREAD_ID = \"__DEFAULT_ID__\";\nconst DEFAULT_THREAD_DATA = Object.freeze({\n [DEFAULT_THREAD_ID]: {\n id: DEFAULT_THREAD_ID,\n remoteId: undefined,\n externalId: undefined,\n status: \"regular\" as const,\n title: undefined,\n },\n});\nexport class LocalThreadListRuntimeCore\n extends BaseSubscribable\n implements ThreadListRuntimeCore\n{\n private _mainThread: LocalThreadRuntimeCore;\n constructor(_threadFactory: LocalThreadFactory) {\n super();\n\n this._mainThread = _threadFactory();\n }\n\n public get isLoading() {\n return false;\n }\n\n public getMainThreadRuntimeCore() {\n return this._mainThread;\n }\n\n public get newThreadId(): string | undefined {\n return undefined;\n }\n\n public get threadIds(): readonly string[] {\n return EMPTY_ARRAY;\n }\n\n public get archivedThreadIds(): readonly string[] {\n return EMPTY_ARRAY;\n }\n\n public get mainThreadId(): string {\n return DEFAULT_THREAD_ID;\n }\n\n public get threadItems() {\n return DEFAULT_THREAD_DATA;\n }\n\n public getThreadRuntimeCore(): never {\n throw new Error(\"Method not implemented.\");\n }\n\n public getLoadThreadsPromise(): Promise<void> {\n return Promise.resolve();\n }\n\n public getItemById(threadId: string) {\n if (threadId === this.mainThreadId) {\n return {\n status: \"regular\" as const,\n id: this.mainThreadId,\n remoteId: this.mainThreadId,\n externalId: undefined,\n title: undefined,\n isMain: true,\n };\n }\n throw new Error(\"Method not implemented\");\n }\n\n public async switchToThread(): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n\n public switchToNewThread(): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n\n public rename(): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n\n public archive(): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n\n public detach(): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n\n public unarchive(): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n\n public delete(): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n\n public initialize(\n threadId: string,\n ): Promise<{ remoteId: string; externalId: string | undefined }> {\n return Promise.resolve({ remoteId: threadId, externalId: undefined });\n }\n\n public generateTitle(): never {\n throw new Error(\"Method not implemented.\");\n }\n}\n"],"mappings":";;AAMA,MAAMI,cAAcC,OAAOC,OAAO,CAAA,CAAE;AACpC,MAAMC,oBAAoB;AAC1B,MAAMC,sBAAsBH,OAAOC,OAAO,GACvCC,oBAAoB;CACnBE,IAAIF;CACJG,UAAUC,KAAAA;CACVC,YAAYD,KAAAA;CACZE,QAAQ;CACRE,OAAOJ,KAAAA;AACT,EACF,CAAC;AACD,IAAaK,6BAAb,cACUf,iBAEV;CACE;CACAiB,YAAYC,gBAAoC;EAC9C,MAAM;EAEN,KAAKF,cAAcE,eAAe;CACpC;CAEA,IAAWC,YAAY;EACrB,OAAO;CACT;CAEA,2BAAkC;EAChC,OAAO,KAAKH;CACd;CAEA,IAAWK,cAAkC,CAE7C;CAEA,IAAWC,YAA+B;EACxC,OAAOnB;CACT;CAEA,IAAWoB,oBAAuC;EAChD,OAAOpB;CACT;CAEA,IAAWqB,eAAuB;EAChC,OAAOlB;CACT;CAEA,IAAWmB,cAAc;EACvB,OAAOlB;CACT;CAEA,uBAAqC;EACnC,MAAM,IAAIoB,MAAM,yBAAyB;CAC3C;CAEA,wBAA8C;EAC5C,OAAOE,QAAQC,QAAQ;CACzB;CAEA,YAAmBE,UAAkB;EACnC,IAAIA,aAAa,KAAKR,cACpB,OAAO;GACLZ,QAAQ;GACRJ,IAAI,KAAKgB;GACTf,UAAU,KAAKe;GACfb,YAAYD,KAAAA;GACZI,OAAOJ,KAAAA;GACPuB,QAAQ;EACV;EAEF,MAAM,IAAIN,MAAM,wBAAwB;CAC1C;CAEA,MAAaO,iBAAgC;EAC3C,MAAM,IAAIP,MAAM,yBAAyB;CAC3C;CAEA,oBAA0C;EACxC,MAAM,IAAIA,MAAM,yBAAyB;CAC3C;CAEA,SAA+B;EAC7B,MAAM,IAAIA,MAAM,yBAAyB;CAC3C;CAEA,UAAgC;EAC9B,MAAM,IAAIA,MAAM,yBAAyB;CAC3C;CAEA,SAA+B;EAC7B,MAAM,IAAIA,MAAM,yBAAyB;CAC3C;CAEA,YAAkC;EAChC,MAAM,IAAIA,MAAM,yBAAyB;CAC3C;CAEA,SAA+B;EAC7B,MAAM,IAAIA,MAAM,yBAAyB;CAC3C;CAEA,WACEK,UAC+D;EAC/D,OAAOH,QAAQC,QAAQ;GAAErB,UAAUuB;GAAUrB,YAAYD,KAAAA;EAAU,CAAC;CACtE;CAEA,gBAA8B;EAC5B,MAAM,IAAIiB,MAAM,yBAAyB;CAC3C;AACF"}
@@ -17,6 +17,7 @@ declare class LocalThreadRuntimeCore extends BaseThreadRuntimeCore implements Th
17
17
  switchToBranch: boolean;
18
18
  switchBranchDuringRun: boolean;
19
19
  edit: boolean;
20
+ delete: boolean;
20
21
  reload: boolean;
21
22
  cancel: boolean;
22
23
  unstable_copy: boolean;
@@ -63,6 +64,7 @@ declare class LocalThreadRuntimeCore extends BaseThreadRuntimeCore implements Th
63
64
  steerQueueItem(queueItemId: string): void;
64
65
  removeQueueItem(queueItemId: string): void;
65
66
  private _runAppend;
67
+ deleteMessage(messageId: string): Promise<void>;
66
68
  resumeRun({
67
69
  stream,
68
70
  ...startConfig
@@ -73,6 +75,7 @@ declare class LocalThreadRuntimeCore extends BaseThreadRuntimeCore implements Th
73
75
  parentId,
74
76
  runConfig
75
77
  }: StartRunConfig, runCallback?: ChatModelAdapter["run"]): Promise<void>;
78
+ private _runLoop;
76
79
  private performRoundtrip;
77
80
  detach(): void;
78
81
  cancelRun(): void;
@@ -84,7 +87,12 @@ declare class LocalThreadRuntimeCore extends BaseThreadRuntimeCore implements Th
84
87
  artifact
85
88
  }: AddToolResultOptions): void;
86
89
  resumeToolCall(_options: ResumeToolCallOptions): void;
87
- respondToToolApproval(_options: RespondToToolApprovalOptions): void;
90
+ respondToToolApproval({
91
+ approvalId,
92
+ approved,
93
+ optionId,
94
+ reason
95
+ }: RespondToToolApprovalOptions): void;
88
96
  }
89
97
  //#endregion
90
98
  export { LocalThreadRuntimeCore };
@@ -1 +1 @@
1
- {"version":3,"file":"local-thread-runtime-core.d.ts","names":[],"sources":["../../../src/runtimes/local/local-thread-runtime-core.ts"],"mappings":";;;;;;;;;;;;;;cA2Ca,sBAAA,SACH,qBAAA,YACG,iBAAA;EAAA,SAEK,YAAA;;;;;;;;;;;;;;UAeR,eAAA;EAAA,QAEA,MAAA;EAAA,QACA,iBAAA;EAAA,SAEQ,UAAA;EAAA,SACA,cAAA;EAAA,QAER,UAAA;EAAA,IACG,SAAA;EAAA,QAIH,YAAA;EAAA,QACA,sBAAA;EAAA,IACG,WAAA,aAAwB,gBAAA;EAAA,IAIxB,QAAA;;;;;;;;;;cAKT,eAAA,EAAiB,oBAAA,EACjB,OAAA,EAAS,uBAAA;EAAA,QAMH,QAAA;EAAA,QAEA,cAAA;EAAA,QAEA,YAAA;EAED,yBAAA,CAA0B,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QAIzB,qBAAA;EAED,kCAAA,CACL,UAAA,QAAkB,OAAA;EAAA,IAKT,MAAA;EAIJ,qBAAA,CAAsB,OAAA,EAAS,uBAAA;EAAA,QAuE9B,YAAA;EACD,eAAA,IAAe,OAAA;EAuCT,MAAA,CAAO,OAAA,EAAS,aAAA,GAAgB,OAAA;EAWtC,aAAA,aAA0B,cAAA;EAM1B,cAAA,CAAe,WAAA;EAIf,eAAA,CAAgB,WAAA;EAAA,QAIT,UAAA;EAgCD,aAAA,CAAc,SAAA,WAAoB,OAAA;EAmBxC,SAAA;IAAY,MAAA;IAAA,GAAW;EAAA,GAAe,eAAA,GAAkB,OAAA;EAMxD,mBAAA;EAIA,mBAAA;EAIM,QAAA;IACT,QAAA;IAAU;EAAA,GAAa,cAAA,EACzB,WAAA,GAAc,gBAAA,UACb,OAAA;EAAA,QAuBW,QAAA;EAAA,QA2DA,gBAAA;EAgLP,MAAA;EAOA,SAAA;EAOA,aAAA;IACL,SAAA;IACA,UAAA;IACA,MAAA;IACA,OAAA;IACA;EAAA,GACC,oBAAA;EA2CI,cAAA,CAAe,QAAA,EAAU,qBAAA;EAMzB,qBAAA;IACL,UAAA;IACA,QAAA;IACA,QAAA;IACA;EAAA,GACC,4BAAA;AAAA"}
@@ -18,6 +18,7 @@ var LocalThreadRuntimeCore = class extends BaseThreadRuntimeCore {
18
18
  switchToBranch: true,
19
19
  switchBranchDuringRun: true,
20
20
  edit: true,
21
+ delete: false,
21
22
  reload: true,
22
23
  cancel: true,
23
24
  unstable_copy: true,
@@ -89,6 +90,11 @@ var LocalThreadRuntimeCore = class extends BaseThreadRuntimeCore {
89
90
  this.capabilities.feedback = canFeedback;
90
91
  hasUpdates = true;
91
92
  }
93
+ const canDelete = options.adapters?.history?.delete !== void 0;
94
+ if (this.capabilities.delete !== canDelete) {
95
+ this.capabilities.delete = canDelete;
96
+ hasUpdates = true;
97
+ }
92
98
  const canQueue = options.unstable_enableMessageQueue === true;
93
99
  if (canQueue && !this._queue) {
94
100
  this._queue = createMessageQueue({ run: (message) => {
@@ -175,6 +181,21 @@ var LocalThreadRuntimeCore = class extends BaseThreadRuntimeCore {
175
181
  this._notifySubscribers();
176
182
  }
177
183
  }
184
+ async deleteMessage(messageId) {
185
+ const adapter = this._options.adapters.history;
186
+ if (!adapter?.delete) throw new Error("Runtime does not support deleting messages.");
187
+ const messages = this.repository.getMessages();
188
+ const messageIndex = messages.findIndex((m) => m.id === messageId);
189
+ if (messageIndex === -1) throw new Error("Message not found.");
190
+ const message = messages[messageIndex];
191
+ const items = [{
192
+ parentId: messages[messageIndex - 1]?.id ?? null,
193
+ message
194
+ }];
195
+ await adapter.delete(items);
196
+ this.repository.deleteMessage(messageId);
197
+ this._notifySubscribers();
198
+ }
178
199
  resumeRun({ stream, ...startConfig }) {
179
200
  if (!stream) throw new Error("You must pass a stream parameter to resume runs.");
180
201
  return this.startRun(startConfig, stream);
@@ -187,7 +208,7 @@ var LocalThreadRuntimeCore = class extends BaseThreadRuntimeCore {
187
208
  }
188
209
  async startRun({ parentId, runConfig }, runCallback) {
189
210
  this.ensureInitialized();
190
- let message = {
211
+ const message = {
191
212
  id: generateId(),
192
213
  role: "assistant",
193
214
  status: { type: "running" },
@@ -201,6 +222,9 @@ var LocalThreadRuntimeCore = class extends BaseThreadRuntimeCore {
201
222
  },
202
223
  createdAt: /* @__PURE__ */ new Date()
203
224
  };
225
+ return this._runLoop(parentId, message, runConfig, runCallback);
226
+ }
227
+ async _runLoop(parentId, message, runConfig, runCallback) {
204
228
  this._notifyEventSubscribers("runStart", {});
205
229
  try {
206
230
  this._queue?.notifyBusy();
@@ -378,13 +402,49 @@ var LocalThreadRuntimeCore = class extends BaseThreadRuntimeCore {
378
402
  content: newContent
379
403
  };
380
404
  this.repository.addOrUpdateMessage(parentId, message);
381
- if (added && shouldContinue(message, this._options.unstable_humanToolNames)) this.performRoundtrip(parentId, message, this._lastRunConfig).catch(() => {});
405
+ this._notifySubscribers();
406
+ if (added && shouldContinue(message, this._options.unstable_humanToolNames)) this._runLoop(parentId, message, this._lastRunConfig).catch(() => {});
382
407
  }
383
408
  resumeToolCall(_options) {
384
- throw new Error("Local runtime does not support resuming tool calls.");
409
+ throw new Error("Local runtime does not support resuming tool calls. For human-in-the-loop tools, list the tool in unstable_humanToolNames and complete the call with addToolResult.");
385
410
  }
386
- respondToToolApproval(_options) {
387
- throw new Error("Local runtime does not support tool approvals.");
411
+ respondToToolApproval({ approvalId, approved, optionId, reason }) {
412
+ let message = this.repository.getMessages().findLast((m) => m.role === "assistant" && m.content.some((c) => c.type === "tool-call" && c.approval?.id === approvalId));
413
+ if (!message) throw new Error("Tried to respond to a non-existing tool approval");
414
+ if (this.abortController !== null) throw new Error("Tried to respond to a tool approval while a run is in progress");
415
+ if (message.status?.type !== "requires-action") throw new Error("Tried to respond to a tool approval on a message whose status is not requires-action");
416
+ const target = message.content.find((c) => c.type === "tool-call" && c.approval?.id === approvalId);
417
+ if (target?.type !== "tool-call" || !target.approval) throw new Error("Tried to respond to a non-existing tool approval");
418
+ if (target.approval.resolution !== void 0) throw new Error("Tried to respond to a tool approval that was cancelled or expired");
419
+ if (target.approval.approved !== void 0) throw new Error("Tried to respond to an already decided tool approval");
420
+ const targetApproval = target.approval;
421
+ const newContent = message.content.map((c) => {
422
+ if (c !== target) return c;
423
+ const approval = {
424
+ ...targetApproval,
425
+ approved,
426
+ ...optionId != null && { optionId },
427
+ ...reason != null && { reason }
428
+ };
429
+ if (approved) return {
430
+ ...c,
431
+ approval
432
+ };
433
+ return {
434
+ ...c,
435
+ approval,
436
+ result: { error: reason || "Tool approval denied" },
437
+ isError: true
438
+ };
439
+ });
440
+ message = {
441
+ ...message,
442
+ content: newContent
443
+ };
444
+ const { parentId } = this.repository.getMessage(message.id);
445
+ this.repository.addOrUpdateMessage(parentId, message);
446
+ this._notifySubscribers();
447
+ if (this.repository.headId === message.id && shouldContinue(message, this._options.unstable_humanToolNames)) this._runLoop(parentId, message, this._lastRunConfig).catch(() => {});
388
448
  }
389
449
  };
390
450
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"local-thread-runtime-core.js","names":[],"sources":["../../../src/runtimes/local/local-thread-runtime-core.ts"],"sourcesContent":["import { fromThreadMessageLike } from \"../../runtime/utils/thread-message-like\";\nimport { generateId } from \"../../utils/id\";\nimport type {\n ChatModelAdapter,\n ChatModelRunResult,\n} from \"../../runtime/utils/chat-model-adapter\";\nimport { shouldContinue } from \"./should-continue\";\nimport type { LocalRuntimeOptionsBase } from \"./local-runtime-options\";\nimport type {\n AddToolResultOptions,\n ResumeToolCallOptions,\n RespondToToolApprovalOptions,\n ThreadSuggestion,\n ThreadRuntimeCore,\n StartRunConfig,\n ResumeRunConfig,\n} from \"../../runtime/interfaces/thread-runtime-core\";\nimport { BaseThreadRuntimeCore } from \"../../runtime/base/base-thread-runtime-core\";\nimport type {\n AppendMessage,\n ThreadAssistantMessage,\n} from \"../../types/message\";\nimport type { RunConfig } from \"../../types/message\";\nimport type { ModelContextProvider } from \"../../model-context/types\";\nimport {\n createMessageQueue,\n type MessageQueueController,\n} from \"../../runtime/queue/message-queue\";\nimport {\n EMPTY_QUEUE_ITEMS,\n type QueueItemState,\n} from \"../../store/scopes/queue-item\";\n\nclass AbortError extends Error {\n override name = \"AbortError\";\n detach: boolean;\n\n constructor(detach: boolean, message?: string) {\n super(message);\n this.detach = detach;\n }\n}\n\nexport class LocalThreadRuntimeCore\n extends BaseThreadRuntimeCore\n implements ThreadRuntimeCore\n{\n public readonly capabilities = {\n switchToBranch: true,\n switchBranchDuringRun: true,\n edit: true,\n reload: true,\n cancel: true,\n unstable_copy: true,\n speech: false,\n dictation: false,\n voice: false,\n attachments: false,\n feedback: false,\n queue: false,\n };\n\n private abortController: AbortController | null = null;\n\n private _queue: MessageQueueController | null = null;\n private _queueRunInFlight = false;\n\n public readonly isDisabled = false;\n public readonly isSendDisabled = false;\n\n private _isLoading = false;\n public get isLoading() {\n return this._isLoading;\n }\n\n private _suggestions: readonly ThreadSuggestion[] = [];\n private _suggestionsController: AbortController | null = null;\n public get suggestions(): readonly ThreadSuggestion[] {\n return this._suggestions;\n }\n\n public get adapters() {\n return this._options.adapters;\n }\n\n constructor(\n contextProvider: ModelContextProvider,\n options: LocalRuntimeOptionsBase,\n ) {\n super(contextProvider);\n this.__internal_setOptions(options);\n }\n\n private _options!: LocalRuntimeOptionsBase;\n\n private _lastRunConfig: RunConfig = {};\n\n private _getThreadId?: () => string | undefined;\n\n public __internal_setGetThreadId(getThreadId: () => string | undefined) {\n this._getThreadId = getThreadId;\n }\n\n private _getInitializePromise?: () => Promise<unknown> | undefined;\n\n public __internal_setGetInitializePromise(\n getPromise: () => Promise<unknown> | undefined,\n ) {\n this._getInitializePromise = getPromise;\n }\n\n public get extras() {\n return undefined;\n }\n\n public __internal_setOptions(options: LocalRuntimeOptionsBase) {\n if (this._options === options) return;\n\n this._options = options;\n\n let hasUpdates = false;\n\n const canSpeak = options.adapters?.speech !== undefined;\n if (this.capabilities.speech !== canSpeak) {\n this.capabilities.speech = canSpeak;\n hasUpdates = true;\n }\n\n const canDictate = options.adapters?.dictation !== undefined;\n if (this.capabilities.dictation !== canDictate) {\n this.capabilities.dictation = canDictate;\n hasUpdates = true;\n }\n\n const canVoice = options.adapters?.voice !== undefined;\n if (this.capabilities.voice !== canVoice) {\n this.capabilities.voice = canVoice;\n hasUpdates = true;\n }\n\n const canAttach = options.adapters?.attachments !== undefined;\n if (this.capabilities.attachments !== canAttach) {\n this.capabilities.attachments = canAttach;\n hasUpdates = true;\n }\n\n const canFeedback = options.adapters?.feedback !== undefined;\n if (this.capabilities.feedback !== canFeedback) {\n this.capabilities.feedback = canFeedback;\n hasUpdates = true;\n }\n\n const canQueue = options.unstable_enableMessageQueue === true;\n if (canQueue && !this._queue) {\n this._queue = createMessageQueue({\n run: (message) => {\n // release the queue when the dispatch settles, even if it rejects\n // before reaching startRun's finally, so a failure can't deadlock it\n this._queueRunInFlight = true;\n void this._runAppend(message)\n .finally(() => {\n this._queueRunInFlight = false;\n this._queue?.notifyIdle();\n })\n .catch(() => {});\n },\n });\n this._queue.subscribe(() => this._notifySubscribers());\n } else if (!canQueue && this._queue) {\n this._queue.adapter.clear(\"cancel-run\");\n this._queue = null;\n }\n if (this.capabilities.queue !== canQueue) {\n this.capabilities.queue = canQueue;\n hasUpdates = true;\n }\n\n if (hasUpdates) this._notifySubscribers();\n }\n\n private _loadPromise: Promise<void> | undefined;\n public __internal_load() {\n if (this._loadPromise) return this._loadPromise;\n\n const promise = this.adapters.history?.load() ?? Promise.resolve(null);\n\n this._isLoading = true;\n this._notifySubscribers();\n\n this._loadPromise = promise\n .then((repo) => {\n if (!repo) return;\n this.repository.import(repo);\n if (repo.messages.length > 0) {\n this.ensureInitialized();\n }\n this._notifySubscribers();\n\n const resume = this.adapters.history?.resume?.bind(\n this.adapters.history,\n );\n if (repo.unstable_resume && resume) {\n this.startRun(\n {\n parentId: this.repository.headId,\n sourceId: this.repository.headId,\n runConfig: this._lastRunConfig,\n },\n resume,\n ).catch(() => {});\n }\n })\n .finally(() => {\n this._isLoading = false;\n this._notifySubscribers();\n });\n\n return this._loadPromise;\n }\n\n public async append(message: AppendMessage): Promise<void> {\n const isTail = message.parentId === (this.messages.at(-1)?.id ?? null);\n const willRun = message.startRun ?? message.role === \"user\";\n if (this._queue && willRun && isTail) {\n this._queue.adapter.enqueue(message, { steer: message.steer ?? false });\n return;\n }\n if (this._queue && !isTail) this._queue.adapter.clear(\"edit\");\n return this._runAppend(message);\n }\n\n public getQueueItems(): readonly QueueItemState[] {\n // Reads can arrive during base-thread construction, before the queue field\n // is assigned, so guard against the unset field.\n return this._queue?.adapter.items ?? EMPTY_QUEUE_ITEMS;\n }\n\n public steerQueueItem(queueItemId: string): void {\n this._queue?.adapter.steer(queueItemId);\n }\n\n public removeQueueItem(queueItemId: string): void {\n this._queue?.adapter.remove(queueItemId);\n }\n\n private async _runAppend(message: AppendMessage): Promise<void> {\n this.ensureInitialized();\n\n const initPromise = this._getInitializePromise?.();\n if (initPromise) {\n await initPromise;\n }\n\n const newMessage = fromThreadMessageLike(message, generateId(), {\n type: \"complete\",\n reason: \"unknown\",\n });\n this.repository.addOrUpdateMessage(message.parentId, newMessage);\n this._options.adapters.history?.append({\n parentId: message.parentId,\n message: newMessage,\n ...(message.runConfig !== undefined && { runConfig: message.runConfig }),\n });\n\n const startRun = message.startRun ?? message.role === \"user\";\n if (startRun) {\n await this.startRun({\n parentId: newMessage.id,\n sourceId: message.sourceId,\n runConfig: message.runConfig ?? {},\n });\n } else {\n this.repository.resetHead(newMessage.id);\n this._notifySubscribers();\n }\n }\n\n public resumeRun({ stream, ...startConfig }: ResumeRunConfig): Promise<void> {\n if (!stream)\n throw new Error(\"You must pass a stream parameter to resume runs.\");\n return this.startRun(startConfig, stream);\n }\n\n public exportExternalState(): any {\n throw new Error(\"Runtime does not support exporting external states.\");\n }\n\n public importExternalState(): void {\n throw new Error(\"Runtime does not support importing external states.\");\n }\n\n public async startRun(\n { parentId, runConfig }: StartRunConfig,\n runCallback?: ChatModelAdapter[\"run\"],\n ): Promise<void> {\n this.ensureInitialized();\n\n // add assistant message\n const id = generateId();\n let message: ThreadAssistantMessage = {\n id,\n role: \"assistant\",\n status: { type: \"running\" },\n content: [],\n metadata: {\n unstable_state: this.state,\n unstable_annotations: [],\n unstable_data: [],\n steps: [],\n custom: {},\n },\n createdAt: new Date(),\n };\n\n this._notifyEventSubscribers(\"runStart\", {});\n\n try {\n // mark busy for runs not started through the queue (regenerate, resume)\n this._queue?.notifyBusy();\n this._suggestions = [];\n this._suggestionsController?.abort();\n this._suggestionsController = null;\n this._notifySubscribers();\n\n do {\n message = await this.performRoundtrip(\n parentId,\n message,\n runConfig,\n runCallback,\n );\n runCallback = undefined;\n } while (shouldContinue(message, this._options.unstable_humanToolNames));\n } finally {\n this._notifyEventSubscribers(\"runEnd\", {});\n // queue-driven runs release from the driver settle handler; a direct\n // run (regenerate, resume) releases here\n if (!this._queueRunInFlight) {\n queueMicrotask(() => this._queue?.notifyIdle());\n }\n }\n\n this._suggestionsController = new AbortController();\n const signal = this._suggestionsController.signal;\n if (\n this.adapters.suggestion &&\n message.status?.type !== \"requires-action\"\n ) {\n const promiseOrGenerator = this.adapters.suggestion?.generate({\n messages: this.messages,\n });\n\n if (Symbol.asyncIterator in promiseOrGenerator) {\n for await (const r of promiseOrGenerator) {\n if (signal.aborted) break;\n this._suggestions = r;\n this._notifySubscribers();\n }\n } else {\n const result = await promiseOrGenerator;\n if (signal.aborted) return;\n this._suggestions = result;\n this._notifySubscribers();\n }\n }\n }\n\n private async performRoundtrip(\n parentId: string | null,\n message: ThreadAssistantMessage,\n runConfig: RunConfig | undefined,\n runCallback?: ChatModelAdapter[\"run\"],\n ) {\n const messages = parentId ? this.repository.getMessages(parentId) : [];\n\n // abort existing run\n this.abortController?.abort();\n this.abortController = new AbortController();\n\n const initialContent = message.content;\n const initialAnnotations = message.metadata?.unstable_annotations;\n const initialData = message.metadata?.unstable_data;\n const initialSteps = message.metadata?.steps;\n const initialCustom = message.metadata?.custom;\n const updateMessage = (m: Partial<ChatModelRunResult>) => {\n const newSteps = m.metadata?.steps;\n const steps = newSteps\n ? [...(initialSteps ?? []), ...newSteps]\n : undefined;\n\n const newAnnotations = m.metadata?.unstable_annotations;\n const newData = m.metadata?.unstable_data;\n const annotations = newAnnotations\n ? [...(initialAnnotations ?? []), ...newAnnotations]\n : undefined;\n const data = newData ? [...(initialData ?? []), ...newData] : undefined;\n\n message = {\n ...message,\n ...(m.content\n ? { content: [...initialContent, ...(m.content ?? [])] }\n : undefined),\n status: m.status ?? message.status,\n ...(m.metadata\n ? {\n metadata: {\n ...message.metadata,\n ...(m.metadata.unstable_state\n ? { unstable_state: m.metadata.unstable_state }\n : undefined),\n ...(annotations\n ? { unstable_annotations: annotations }\n : undefined),\n ...(data ? { unstable_data: data } : undefined),\n ...(steps ? { steps } : undefined),\n ...(m.metadata?.timing\n ? { timing: m.metadata.timing }\n : undefined),\n ...(m.metadata?.custom\n ? {\n custom: {\n ...(initialCustom ?? {}),\n ...m.metadata.custom,\n },\n }\n : undefined),\n },\n }\n : undefined),\n };\n this.repository.addOrUpdateMessage(parentId, message);\n this._notifySubscribers();\n };\n\n const maxSteps = this._options.maxSteps ?? 2;\n\n const steps = message.metadata?.steps?.length ?? 0;\n if (steps >= maxSteps) {\n // reached max tool steps\n updateMessage({\n status: {\n type: \"incomplete\",\n reason: \"tool-calls\",\n },\n });\n return message;\n } else {\n updateMessage({\n status: {\n type: \"running\",\n },\n });\n\n // Switch to the new message branch right after adding it for the first time\n this.repository.resetHead(message.id);\n this._notifySubscribers();\n }\n\n try {\n this._lastRunConfig = runConfig ?? {};\n const context = this.getModelContext();\n\n runCallback =\n runCallback ??\n this.adapters.chatModel.run.bind(this.adapters.chatModel);\n\n const abortSignal = this.abortController.signal;\n const threadId = this._getThreadId?.();\n const promiseOrGenerator = runCallback({\n messages,\n runConfig: this._lastRunConfig,\n abortSignal,\n context,\n unstable_assistantMessageId: message.id,\n unstable_threadId: threadId,\n unstable_parentId: parentId,\n unstable_getMessage() {\n return message;\n },\n });\n\n // handle async iterator for streaming results\n if (Symbol.asyncIterator in promiseOrGenerator) {\n for await (const r of promiseOrGenerator) {\n if (abortSignal.aborted) {\n updateMessage({\n status: { type: \"incomplete\", reason: \"cancelled\" },\n });\n break;\n }\n\n updateMessage(r);\n }\n } else {\n updateMessage(await promiseOrGenerator);\n }\n\n if (message.status.type === \"running\") {\n updateMessage({\n status: { type: \"complete\", reason: \"unknown\" },\n });\n }\n } catch (e) {\n // TODO this should be handled by the run result stream\n if (e instanceof AbortError) {\n updateMessage({\n status: { type: \"incomplete\", reason: \"cancelled\" },\n });\n } else if (e instanceof Error && e.name === \"AbortError\") {\n updateMessage({\n status: { type: \"incomplete\", reason: \"cancelled\" },\n });\n } else {\n updateMessage({\n status: {\n type: \"incomplete\",\n reason: \"error\",\n error:\n e instanceof Error\n ? e.message\n : `[${typeof e}] ${new String(e).toString()}`,\n },\n });\n\n throw e;\n }\n } finally {\n this.abortController = null;\n\n if (\n message.status.type === \"complete\" ||\n message.status.type === \"incomplete\"\n ) {\n await this._options.adapters.history?.append({\n parentId,\n message: message,\n runConfig: this._lastRunConfig,\n });\n }\n }\n return message;\n }\n\n public detach() {\n this._queue?.adapter.clear(\"cancel-run\");\n const error = new AbortError(true);\n this.abortController?.abort(error);\n this.abortController = null;\n }\n\n public cancelRun() {\n this._queue?.adapter.clear(\"cancel-run\");\n const error = new AbortError(false);\n this.abortController?.abort(error);\n this.abortController = null;\n }\n\n public addToolResult({\n messageId,\n toolCallId,\n result,\n isError,\n artifact,\n }: AddToolResultOptions) {\n const messageData = this.repository.getMessage(messageId);\n const { parentId } = messageData;\n let { message } = messageData;\n\n if (message.role !== \"assistant\")\n throw new Error(\"Tried to add tool result to non-assistant message\");\n\n let added = false;\n let found = false;\n const newContent = message.content.map((c) => {\n if (c.type !== \"tool-call\") return c;\n if (c.toolCallId !== toolCallId) return c;\n found = true;\n if (!c.result) added = true;\n return {\n ...c,\n result,\n artifact,\n isError,\n };\n });\n\n if (!found)\n throw new Error(\"Tried to add tool result to non-existing tool call\");\n\n message = {\n ...message,\n content: newContent,\n };\n this.repository.addOrUpdateMessage(parentId, message);\n\n if (\n added &&\n shouldContinue(message, this._options.unstable_humanToolNames)\n ) {\n this.performRoundtrip(parentId, message, this._lastRunConfig).catch(\n () => {},\n );\n }\n }\n\n public resumeToolCall(_options: ResumeToolCallOptions) {\n throw new Error(\"Local runtime does not support resuming tool calls.\");\n }\n\n public respondToToolApproval(_options: RespondToToolApprovalOptions) {\n throw new Error(\"Local runtime does not support tool approvals.\");\n }\n}\n"],"mappings":";;;;;;;AAiCA,IAAM,aAAN,cAAyB,MAAM;CAC7B,OAAgB;CAChB;CAEA,YAAY,QAAiB,SAAkB;EAC7C,MAAM,OAAO;EACb,KAAK,SAAS;CAChB;AACF;AAEA,IAAa,yBAAb,cACU,sBAEV;CACE,eAA+B;EAC7B,gBAAgB;EAChB,uBAAuB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,QAAQ;GACR,IAAI,CAAC,EAAE,QAAQ,QAAQ;GACvB,OAAO;IACL,GAAG;IACH;IACA;IACA;GACF;EACF,CAAC;EAED,IAAI,CAAC,OACH,MAAM,IAAI,MAAM,oDAAoD;EAEtE,UAAU;GACR,GAAG;GACH,SAAS;EACX;EACA,KAAK,WAAW,mBAAmB,UAAU,OAAO;EAEpD,IACE,SACA,eAAe,SAAS,KAAK,SAAS,uBAAuB,GAE7D,KAAK,iBAAiB,UAAU,SAAS,KAAK,cAAc,CAAC,CAAC,YACtD,CAAC,CACT;CAEJ;CAEA,eAAsB,UAAiC;EACrD,MAAM,IAAI,MAAM,qDAAqD;CACvE;CAEA,sBAA6B,UAAwC;EACnE,MAAM,IAAI,MAAM,gDAAgD;CAClE;AACF"}
1
+ {"version":3,"file":"local-thread-runtime-core.js","names":["fromThreadMessageLike","generateId","ChatModelAdapter","ChatModelRunResult","shouldContinue","LocalRuntimeOptionsBase","AddToolResultOptions","ResumeToolCallOptions","RespondToToolApprovalOptions","ThreadSuggestion","ThreadRuntimeCore","StartRunConfig","ResumeRunConfig","BaseThreadRuntimeCore","AppendMessage","ThreadAssistantMessage","RunConfig","ModelContextProvider","createMessageQueue","MessageQueueController","EMPTY_QUEUE_ITEMS","QueueItemState","AbortError","Error","name","detach","constructor","message","LocalThreadRuntimeCore","capabilities","switchToBranch","switchBranchDuringRun","edit","delete","reload","cancel","unstable_copy","speech","dictation","voice","attachments","feedback","queue","abortController","AbortController","_queue","_queueRunInFlight","isDisabled","isSendDisabled","_isLoading","isLoading","_suggestions","_suggestionsController","suggestions","adapters","_options","contextProvider","options","__internal_setOptions","_lastRunConfig","_getThreadId","__internal_setGetThreadId","getThreadId","_getInitializePromise","Promise","__internal_setGetInitializePromise","getPromise","extras","undefined","hasUpdates","canSpeak","canDictate","canVoice","canAttach","canFeedback","canDelete","history","canQueue","unstable_enableMessageQueue","run","_runAppend","finally","notifyIdle","catch","subscribe","_notifySubscribers","adapter","clear","_loadPromise","__internal_load","promise","load","resolve","then","repo","repository","import","messages","length","ensureInitialized","resume","bind","unstable_resume","startRun","parentId","headId","sourceId","runConfig","append","isTail","at","id","willRun","role","enqueue","steer","getQueueItems","items","steerQueueItem","queueItemId","removeQueueItem","remove","initPromise","newMessage","type","reason","addOrUpdateMessage","resetHead","deleteMessage","messageId","getMessages","messageIndex","findIndex","m","resumeRun","stream","startConfig","exportExternalState","importExternalState","runCallback","status","content","metadata","unstable_state","state","unstable_annotations","unstable_data","steps","custom","createdAt","Date","_runLoop","_notifyEventSubscribers","notifyBusy","abort","performRoundtrip","unstable_humanToolNames","queueMicrotask","signal","suggestion","promiseOrGenerator","generate","Symbol","asyncIterator","r","aborted","result","initialContent","initialAnnotations","initialData","initialSteps","initialCustom","updateMessage","Partial","newSteps","newAnnotations","newData","annotations","data","timing","maxSteps","context","getModelContext","chatModel","abortSignal","threadId","unstable_assistantMessageId","unstable_threadId","unstable_parentId","unstable_getMessage","e","error","String","toString","cancelRun","addToolResult","toolCallId","isError","artifact","messageData","getMessage","added","found","newContent","map","c","resumeToolCall","respondToToolApproval","approvalId","approved","optionId","findLast","some","approval","target","find","resolution","targetApproval"],"sources":["../../../src/runtimes/local/local-thread-runtime-core.ts"],"sourcesContent":["import { fromThreadMessageLike } from \"../../runtime/utils/thread-message-like\";\nimport { generateId } from \"../../utils/id\";\nimport type {\n ChatModelAdapter,\n ChatModelRunResult,\n} from \"../../runtime/utils/chat-model-adapter\";\nimport { shouldContinue } from \"./should-continue\";\nimport type { LocalRuntimeOptionsBase } from \"./local-runtime-options\";\nimport type {\n AddToolResultOptions,\n ResumeToolCallOptions,\n RespondToToolApprovalOptions,\n ThreadSuggestion,\n ThreadRuntimeCore,\n StartRunConfig,\n ResumeRunConfig,\n} from \"../../runtime/interfaces/thread-runtime-core\";\nimport { BaseThreadRuntimeCore } from \"../../runtime/base/base-thread-runtime-core\";\nimport type {\n AppendMessage,\n ThreadAssistantMessage,\n} from \"../../types/message\";\nimport type { RunConfig } from \"../../types/message\";\nimport type { ModelContextProvider } from \"../../model-context/types\";\nimport {\n createMessageQueue,\n type MessageQueueController,\n} from \"../../runtime/queue/message-queue\";\nimport {\n EMPTY_QUEUE_ITEMS,\n type QueueItemState,\n} from \"../../store/scopes/queue-item\";\n\nclass AbortError extends Error {\n override name = \"AbortError\";\n detach: boolean;\n\n constructor(detach: boolean, message?: string) {\n super(message);\n this.detach = detach;\n }\n}\n\nexport class LocalThreadRuntimeCore\n extends BaseThreadRuntimeCore\n implements ThreadRuntimeCore\n{\n public readonly capabilities = {\n switchToBranch: true,\n switchBranchDuringRun: true,\n edit: true,\n delete: false,\n reload: true,\n cancel: true,\n unstable_copy: true,\n speech: false,\n dictation: false,\n voice: false,\n attachments: false,\n feedback: false,\n queue: false,\n };\n\n private abortController: AbortController | null = null;\n\n private _queue: MessageQueueController | null = null;\n private _queueRunInFlight = false;\n\n public readonly isDisabled = false;\n public readonly isSendDisabled = false;\n\n private _isLoading = false;\n public get isLoading() {\n return this._isLoading;\n }\n\n private _suggestions: readonly ThreadSuggestion[] = [];\n private _suggestionsController: AbortController | null = null;\n public get suggestions(): readonly ThreadSuggestion[] {\n return this._suggestions;\n }\n\n public get adapters() {\n return this._options.adapters;\n }\n\n constructor(\n contextProvider: ModelContextProvider,\n options: LocalRuntimeOptionsBase,\n ) {\n super(contextProvider);\n this.__internal_setOptions(options);\n }\n\n private _options!: LocalRuntimeOptionsBase;\n\n private _lastRunConfig: RunConfig = {};\n\n private _getThreadId?: () => string | undefined;\n\n public __internal_setGetThreadId(getThreadId: () => string | undefined) {\n this._getThreadId = getThreadId;\n }\n\n private _getInitializePromise?: () => Promise<unknown> | undefined;\n\n public __internal_setGetInitializePromise(\n getPromise: () => Promise<unknown> | undefined,\n ) {\n this._getInitializePromise = getPromise;\n }\n\n public get extras() {\n return undefined;\n }\n\n public __internal_setOptions(options: LocalRuntimeOptionsBase) {\n if (this._options === options) return;\n\n this._options = options;\n\n let hasUpdates = false;\n\n const canSpeak = options.adapters?.speech !== undefined;\n if (this.capabilities.speech !== canSpeak) {\n this.capabilities.speech = canSpeak;\n hasUpdates = true;\n }\n\n const canDictate = options.adapters?.dictation !== undefined;\n if (this.capabilities.dictation !== canDictate) {\n this.capabilities.dictation = canDictate;\n hasUpdates = true;\n }\n\n const canVoice = options.adapters?.voice !== undefined;\n if (this.capabilities.voice !== canVoice) {\n this.capabilities.voice = canVoice;\n hasUpdates = true;\n }\n\n const canAttach = options.adapters?.attachments !== undefined;\n if (this.capabilities.attachments !== canAttach) {\n this.capabilities.attachments = canAttach;\n hasUpdates = true;\n }\n\n const canFeedback = options.adapters?.feedback !== undefined;\n if (this.capabilities.feedback !== canFeedback) {\n this.capabilities.feedback = canFeedback;\n hasUpdates = true;\n }\n\n const canDelete = options.adapters?.history?.delete !== undefined;\n if (this.capabilities.delete !== canDelete) {\n this.capabilities.delete = canDelete;\n hasUpdates = true;\n }\n\n const canQueue = options.unstable_enableMessageQueue === true;\n if (canQueue && !this._queue) {\n this._queue = createMessageQueue({\n run: (message) => {\n // release the queue when the dispatch settles, even if it rejects\n // before reaching startRun's finally, so a failure can't deadlock it\n this._queueRunInFlight = true;\n void this._runAppend(message)\n .finally(() => {\n this._queueRunInFlight = false;\n this._queue?.notifyIdle();\n })\n .catch(() => {});\n },\n });\n this._queue.subscribe(() => this._notifySubscribers());\n } else if (!canQueue && this._queue) {\n this._queue.adapter.clear(\"cancel-run\");\n this._queue = null;\n }\n if (this.capabilities.queue !== canQueue) {\n this.capabilities.queue = canQueue;\n hasUpdates = true;\n }\n\n if (hasUpdates) this._notifySubscribers();\n }\n\n private _loadPromise: Promise<void> | undefined;\n public __internal_load() {\n if (this._loadPromise) return this._loadPromise;\n\n const promise = this.adapters.history?.load() ?? Promise.resolve(null);\n\n this._isLoading = true;\n this._notifySubscribers();\n\n this._loadPromise = promise\n .then((repo) => {\n if (!repo) return;\n this.repository.import(repo);\n if (repo.messages.length > 0) {\n this.ensureInitialized();\n }\n this._notifySubscribers();\n\n const resume = this.adapters.history?.resume?.bind(\n this.adapters.history,\n );\n if (repo.unstable_resume && resume) {\n this.startRun(\n {\n parentId: this.repository.headId,\n sourceId: this.repository.headId,\n runConfig: this._lastRunConfig,\n },\n resume,\n ).catch(() => {});\n }\n })\n .finally(() => {\n this._isLoading = false;\n this._notifySubscribers();\n });\n\n return this._loadPromise;\n }\n\n public async append(message: AppendMessage): Promise<void> {\n const isTail = message.parentId === (this.messages.at(-1)?.id ?? null);\n const willRun = message.startRun ?? message.role === \"user\";\n if (this._queue && willRun && isTail) {\n this._queue.adapter.enqueue(message, { steer: message.steer ?? false });\n return;\n }\n if (this._queue && !isTail) this._queue.adapter.clear(\"edit\");\n return this._runAppend(message);\n }\n\n public getQueueItems(): readonly QueueItemState[] {\n // Reads can arrive during base-thread construction, before the queue field\n // is assigned, so guard against the unset field.\n return this._queue?.adapter.items ?? EMPTY_QUEUE_ITEMS;\n }\n\n public steerQueueItem(queueItemId: string): void {\n this._queue?.adapter.steer(queueItemId);\n }\n\n public removeQueueItem(queueItemId: string): void {\n this._queue?.adapter.remove(queueItemId);\n }\n\n private async _runAppend(message: AppendMessage): Promise<void> {\n this.ensureInitialized();\n\n const initPromise = this._getInitializePromise?.();\n if (initPromise) {\n await initPromise;\n }\n\n const newMessage = fromThreadMessageLike(message, generateId(), {\n type: \"complete\",\n reason: \"unknown\",\n });\n this.repository.addOrUpdateMessage(message.parentId, newMessage);\n this._options.adapters.history?.append({\n parentId: message.parentId,\n message: newMessage,\n ...(message.runConfig !== undefined && { runConfig: message.runConfig }),\n });\n\n const startRun = message.startRun ?? message.role === \"user\";\n if (startRun) {\n await this.startRun({\n parentId: newMessage.id,\n sourceId: message.sourceId,\n runConfig: message.runConfig ?? {},\n });\n } else {\n this.repository.resetHead(newMessage.id);\n this._notifySubscribers();\n }\n }\n\n public async deleteMessage(messageId: string): Promise<void> {\n const adapter = this._options.adapters.history;\n if (!adapter?.delete)\n throw new Error(\"Runtime does not support deleting messages.\");\n\n const messages = this.repository.getMessages();\n const messageIndex = messages.findIndex((m) => m.id === messageId);\n if (messageIndex === -1) throw new Error(\"Message not found.\");\n\n const message = messages[messageIndex]!;\n const parentId = messages[messageIndex - 1]?.id ?? null;\n const items = [{ parentId, message }];\n\n await adapter.delete(items);\n\n this.repository.deleteMessage(messageId);\n this._notifySubscribers();\n }\n\n public resumeRun({ stream, ...startConfig }: ResumeRunConfig): Promise<void> {\n if (!stream)\n throw new Error(\"You must pass a stream parameter to resume runs.\");\n return this.startRun(startConfig, stream);\n }\n\n public exportExternalState(): any {\n throw new Error(\"Runtime does not support exporting external states.\");\n }\n\n public importExternalState(): void {\n throw new Error(\"Runtime does not support importing external states.\");\n }\n\n public async startRun(\n { parentId, runConfig }: StartRunConfig,\n runCallback?: ChatModelAdapter[\"run\"],\n ): Promise<void> {\n this.ensureInitialized();\n\n // add assistant message\n const id = generateId();\n const message: ThreadAssistantMessage = {\n id,\n role: \"assistant\",\n status: { type: \"running\" },\n content: [],\n metadata: {\n unstable_state: this.state,\n unstable_annotations: [],\n unstable_data: [],\n steps: [],\n custom: {},\n },\n createdAt: new Date(),\n };\n\n return this._runLoop(parentId, message, runConfig, runCallback);\n }\n\n private async _runLoop(\n parentId: string | null,\n message: ThreadAssistantMessage,\n runConfig: RunConfig | undefined,\n runCallback?: ChatModelAdapter[\"run\"],\n ): Promise<void> {\n this._notifyEventSubscribers(\"runStart\", {});\n\n try {\n // mark busy for runs not started through the queue (regenerate, resume)\n this._queue?.notifyBusy();\n this._suggestions = [];\n this._suggestionsController?.abort();\n this._suggestionsController = null;\n this._notifySubscribers();\n\n do {\n message = await this.performRoundtrip(\n parentId,\n message,\n runConfig,\n runCallback,\n );\n runCallback = undefined;\n } while (shouldContinue(message, this._options.unstable_humanToolNames));\n } finally {\n this._notifyEventSubscribers(\"runEnd\", {});\n // queue-driven runs release from the driver settle handler; a direct\n // run (regenerate, resume) releases here\n if (!this._queueRunInFlight) {\n queueMicrotask(() => this._queue?.notifyIdle());\n }\n }\n\n this._suggestionsController = new AbortController();\n const signal = this._suggestionsController.signal;\n if (\n this.adapters.suggestion &&\n message.status?.type !== \"requires-action\"\n ) {\n const promiseOrGenerator = this.adapters.suggestion?.generate({\n messages: this.messages,\n });\n\n if (Symbol.asyncIterator in promiseOrGenerator) {\n for await (const r of promiseOrGenerator) {\n if (signal.aborted) break;\n this._suggestions = r;\n this._notifySubscribers();\n }\n } else {\n const result = await promiseOrGenerator;\n if (signal.aborted) return;\n this._suggestions = result;\n this._notifySubscribers();\n }\n }\n }\n\n private async performRoundtrip(\n parentId: string | null,\n message: ThreadAssistantMessage,\n runConfig: RunConfig | undefined,\n runCallback?: ChatModelAdapter[\"run\"],\n ) {\n const messages = parentId ? this.repository.getMessages(parentId) : [];\n\n // abort existing run\n this.abortController?.abort();\n this.abortController = new AbortController();\n\n const initialContent = message.content;\n const initialAnnotations = message.metadata?.unstable_annotations;\n const initialData = message.metadata?.unstable_data;\n const initialSteps = message.metadata?.steps;\n const initialCustom = message.metadata?.custom;\n const updateMessage = (m: Partial<ChatModelRunResult>) => {\n const newSteps = m.metadata?.steps;\n const steps = newSteps\n ? [...(initialSteps ?? []), ...newSteps]\n : undefined;\n\n const newAnnotations = m.metadata?.unstable_annotations;\n const newData = m.metadata?.unstable_data;\n const annotations = newAnnotations\n ? [...(initialAnnotations ?? []), ...newAnnotations]\n : undefined;\n const data = newData ? [...(initialData ?? []), ...newData] : undefined;\n\n message = {\n ...message,\n ...(m.content\n ? { content: [...initialContent, ...(m.content ?? [])] }\n : undefined),\n status: m.status ?? message.status,\n ...(m.metadata\n ? {\n metadata: {\n ...message.metadata,\n ...(m.metadata.unstable_state\n ? { unstable_state: m.metadata.unstable_state }\n : undefined),\n ...(annotations\n ? { unstable_annotations: annotations }\n : undefined),\n ...(data ? { unstable_data: data } : undefined),\n ...(steps ? { steps } : undefined),\n ...(m.metadata?.timing\n ? { timing: m.metadata.timing }\n : undefined),\n ...(m.metadata?.custom\n ? {\n custom: {\n ...(initialCustom ?? {}),\n ...m.metadata.custom,\n },\n }\n : undefined),\n },\n }\n : undefined),\n };\n this.repository.addOrUpdateMessage(parentId, message);\n this._notifySubscribers();\n };\n\n const maxSteps = this._options.maxSteps ?? 2;\n\n const steps = message.metadata?.steps?.length ?? 0;\n if (steps >= maxSteps) {\n // reached max tool steps\n updateMessage({\n status: {\n type: \"incomplete\",\n reason: \"tool-calls\",\n },\n });\n return message;\n } else {\n updateMessage({\n status: {\n type: \"running\",\n },\n });\n\n // Switch to the new message branch right after adding it for the first time\n this.repository.resetHead(message.id);\n this._notifySubscribers();\n }\n\n try {\n this._lastRunConfig = runConfig ?? {};\n const context = this.getModelContext();\n\n runCallback =\n runCallback ??\n this.adapters.chatModel.run.bind(this.adapters.chatModel);\n\n const abortSignal = this.abortController.signal;\n const threadId = this._getThreadId?.();\n const promiseOrGenerator = runCallback({\n messages,\n runConfig: this._lastRunConfig,\n abortSignal,\n context,\n unstable_assistantMessageId: message.id,\n unstable_threadId: threadId,\n unstable_parentId: parentId,\n unstable_getMessage() {\n return message;\n },\n });\n\n // handle async iterator for streaming results\n if (Symbol.asyncIterator in promiseOrGenerator) {\n for await (const r of promiseOrGenerator) {\n if (abortSignal.aborted) {\n updateMessage({\n status: { type: \"incomplete\", reason: \"cancelled\" },\n });\n break;\n }\n\n updateMessage(r);\n }\n } else {\n updateMessage(await promiseOrGenerator);\n }\n\n if (message.status.type === \"running\") {\n updateMessage({\n status: { type: \"complete\", reason: \"unknown\" },\n });\n }\n } catch (e) {\n // TODO this should be handled by the run result stream\n if (e instanceof AbortError) {\n updateMessage({\n status: { type: \"incomplete\", reason: \"cancelled\" },\n });\n } else if (e instanceof Error && e.name === \"AbortError\") {\n updateMessage({\n status: { type: \"incomplete\", reason: \"cancelled\" },\n });\n } else {\n updateMessage({\n status: {\n type: \"incomplete\",\n reason: \"error\",\n error:\n e instanceof Error\n ? e.message\n : `[${typeof e}] ${new String(e).toString()}`,\n },\n });\n\n throw e;\n }\n } finally {\n this.abortController = null;\n\n if (\n message.status.type === \"complete\" ||\n message.status.type === \"incomplete\"\n ) {\n await this._options.adapters.history?.append({\n parentId,\n message: message,\n runConfig: this._lastRunConfig,\n });\n }\n }\n return message;\n }\n\n public detach() {\n this._queue?.adapter.clear(\"cancel-run\");\n const error = new AbortError(true);\n this.abortController?.abort(error);\n this.abortController = null;\n }\n\n public cancelRun() {\n this._queue?.adapter.clear(\"cancel-run\");\n const error = new AbortError(false);\n this.abortController?.abort(error);\n this.abortController = null;\n }\n\n public addToolResult({\n messageId,\n toolCallId,\n result,\n isError,\n artifact,\n }: AddToolResultOptions) {\n const messageData = this.repository.getMessage(messageId);\n const { parentId } = messageData;\n let { message } = messageData;\n\n if (message.role !== \"assistant\")\n throw new Error(\"Tried to add tool result to non-assistant message\");\n\n let added = false;\n let found = false;\n const newContent = message.content.map((c) => {\n if (c.type !== \"tool-call\") return c;\n if (c.toolCallId !== toolCallId) return c;\n found = true;\n if (!c.result) added = true;\n return {\n ...c,\n result,\n artifact,\n isError,\n };\n });\n\n if (!found)\n throw new Error(\"Tried to add tool result to non-existing tool call\");\n\n message = {\n ...message,\n content: newContent,\n };\n this.repository.addOrUpdateMessage(parentId, message);\n this._notifySubscribers();\n\n // a result may arrive mid-run or on a non-head message; the resume\n // intentionally aborts any in-flight run, unlike respondToToolApproval\n if (\n added &&\n shouldContinue(message, this._options.unstable_humanToolNames)\n ) {\n this._runLoop(parentId, message, this._lastRunConfig).catch(() => {});\n }\n }\n\n public resumeToolCall(_options: ResumeToolCallOptions) {\n throw new Error(\n \"Local runtime does not support resuming tool calls. For human-in-the-loop tools, list the tool in unstable_humanToolNames and complete the call with addToolResult.\",\n );\n }\n\n public respondToToolApproval({\n approvalId,\n approved,\n optionId,\n reason,\n }: RespondToToolApprovalOptions) {\n let message = this.repository\n .getMessages()\n .findLast(\n (m): m is ThreadAssistantMessage =>\n m.role === \"assistant\" &&\n m.content.some(\n (c) => c.type === \"tool-call\" && c.approval?.id === approvalId,\n ),\n );\n\n if (!message)\n throw new Error(\"Tried to respond to a non-existing tool approval\");\n\n if (this.abortController !== null)\n throw new Error(\n \"Tried to respond to a tool approval while a run is in progress\",\n );\n\n if (message.status?.type !== \"requires-action\")\n throw new Error(\n \"Tried to respond to a tool approval on a message whose status is not requires-action\",\n );\n\n const target = message.content.find(\n (c) => c.type === \"tool-call\" && c.approval?.id === approvalId,\n );\n if (target?.type !== \"tool-call\" || !target.approval)\n throw new Error(\"Tried to respond to a non-existing tool approval\");\n if (target.approval.resolution !== undefined)\n throw new Error(\n \"Tried to respond to a tool approval that was cancelled or expired\",\n );\n if (target.approval.approved !== undefined)\n throw new Error(\"Tried to respond to an already decided tool approval\");\n\n const targetApproval = target.approval;\n const newContent = message.content.map((c) => {\n if (c !== target) return c;\n const approval = {\n ...targetApproval,\n approved,\n ...(optionId != null && { optionId }),\n ...(reason != null && { reason }),\n };\n if (approved) return { ...c, approval };\n return {\n ...c,\n approval,\n result: { error: reason || \"Tool approval denied\" },\n isError: true,\n };\n });\n\n message = { ...message, content: newContent };\n const { parentId } = this.repository.getMessage(message.id);\n this.repository.addOrUpdateMessage(parentId, message);\n this._notifySubscribers();\n\n if (\n this.repository.headId === message.id &&\n shouldContinue(message, this._options.unstable_humanToolNames)\n ) {\n this._runLoop(parentId, message, this._lastRunConfig).catch(() => {});\n }\n }\n}\n"],"mappings":";;;;;;;AAiCA,IAAMsB,aAAN,cAAyBC,MAAM;CAC7B,OAAgB;CAChBE;CAEAC,YAAYD,QAAiBE,SAAkB;EAC7C,MAAMA,OAAO;EACb,KAAKF,SAASA;CAChB;AACF;AAEA,IAAaG,yBAAb,cACUf,sBAEV;CACE,eAA+B;EAC7BiB,gBAAgB;EAChBC,uBAAuB;EACvBC,MAAM;EACNC,QAAQ;EACRC,QAAQ;EACRC,QAAQ;EACRC,eAAe;EACfC,QAAQ;EACRC,WAAW;EACXC,OAAO;EACPC,aAAa;EACbC,UAAU;EACVC,OAAO;CACT;CAEA,kBAAkD;CAElD,SAAgD;C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oF,MACnC3G,eAAeuB,SAAS,KAAK4B,SAASqG,uBAAuB,GAE7D,KAAKL,SAAS/C,UAAU7E,SAAS,KAAKgC,cAAc,CAAC,CAACwB,YAAY,CAAC,CAAC;CAExE;AACF"}
@@ -1,7 +1,9 @@
1
1
  //#region src/runtimes/local/should-continue.ts
2
2
  const shouldContinue = (result, humanToolNames) => {
3
- if (humanToolNames === void 0) return result.status?.type === "requires-action" && result.status.reason === "tool-calls" && result.content.every((c) => c.type !== "tool-call" || !!c.result);
4
- return result.status?.type === "requires-action" && result.status.reason === "tool-calls" && result.content.every((c) => c.type !== "tool-call" || !!c.result || !humanToolNames.includes(c.toolName));
3
+ if (result.status?.type !== "requires-action" || result.status.reason !== "tool-calls") return false;
4
+ if (result.content.some((c) => c.type === "tool-call" && c.result === void 0 && c.approval !== void 0 && c.approval.approved === void 0 && c.approval.resolution === void 0)) return false;
5
+ if (humanToolNames === void 0) return result.content.every((c) => c.type !== "tool-call" || !!c.result || c.approval !== void 0);
6
+ return result.content.every((c) => c.type !== "tool-call" || !!c.result || c.approval !== void 0 || !humanToolNames.includes(c.toolName));
5
7
  };
6
8
  //#endregion
7
9
  export { shouldContinue };
@@ -1 +1 @@
1
- {"version":3,"file":"should-continue.js","names":[],"sources":["../../../src/runtimes/local/should-continue.ts"],"sourcesContent":["import type { ThreadAssistantMessage } from \"../../types/message\";\n\nexport const shouldContinue = (\n result: ThreadAssistantMessage,\n humanToolNames: string[] | undefined,\n) => {\n // TODO legacy behavior -- make specifying human tool names required\n if (humanToolNames === undefined) {\n return (\n result.status?.type === \"requires-action\" &&\n result.status.reason === \"tool-calls\" &&\n result.content.every((c) => c.type !== \"tool-call\" || !!c.result)\n );\n }\n\n return (\n result.status?.type === \"requires-action\" &&\n result.status.reason === \"tool-calls\" &&\n result.content.every(\n (c) =>\n c.type !== \"tool-call\" ||\n !!c.result ||\n !humanToolNames.includes(c.toolName),\n )\n );\n};\n"],"mappings":";AAEA,MAAa,kBACX,QACA,mBACG;CAEH,IAAI,mBAAmB,KAAA,GACrB,OACE,OAAO,QAAQ,SAAS,qBACxB,OAAO,OAAO,WAAW,gBACzB,OAAO,QAAQ,OAAO,MAAM,EAAE,SAAS,eAAe,CAAC,CAAC,EAAE,MAAM;CAIpE,OACE,OAAO,QAAQ,SAAS,qBACxB,OAAO,OAAO,WAAW,gBACzB,OAAO,QAAQ,OACZ,MACC,EAAE,SAAS,eACX,CAAC,CAAC,EAAE,UACJ,CAAC,eAAe,SAAS,EAAE,QAAQ,CACvC;AAEJ"}
1
+ {"version":3,"file":"should-continue.js","names":["ThreadAssistantMessage","shouldContinue","result","humanToolNames","status","type","reason","hasPendingApproval","content","some","c","undefined","approval","approved","resolution","every","includes","toolName"],"sources":["../../../src/runtimes/local/should-continue.ts"],"sourcesContent":["import type { ThreadAssistantMessage } from \"../../types/message\";\n\nexport const shouldContinue = (\n result: ThreadAssistantMessage,\n humanToolNames: string[] | undefined,\n) => {\n if (\n result.status?.type !== \"requires-action\" ||\n result.status.reason !== \"tool-calls\"\n )\n return false;\n\n const hasPendingApproval = result.content.some(\n (c) =>\n c.type === \"tool-call\" &&\n c.result === undefined &&\n c.approval !== undefined &&\n c.approval.approved === undefined &&\n c.approval.resolution === undefined,\n );\n if (hasPendingApproval) return false;\n\n // TODO legacy behavior -- make specifying human tool names required\n if (humanToolNames === undefined) {\n return result.content.every(\n (c) => c.type !== \"tool-call\" || !!c.result || c.approval !== undefined,\n );\n }\n\n return result.content.every(\n (c) =>\n c.type !== \"tool-call\" ||\n !!c.result ||\n c.approval !== undefined ||\n !humanToolNames.includes(c.toolName),\n );\n};\n"],"mappings":";AAEA,MAAaC,kBACXC,QACAC,mBACG;CACH,IACED,OAAOE,QAAQC,SAAS,qBACxBH,OAAOE,OAAOE,WAAW,cAEzB,OAAO;CAUT,IAR2BJ,OAAOM,QAAQC,MACvCC,MACCA,EAAEL,SAAS,eACXK,EAAER,WAAWS,KAAAA,KACbD,EAAEE,aAAaD,KAAAA,KACfD,EAAEE,SAASC,aAAaF,KAAAA,KACxBD,EAAEE,SAASE,eAAeH,KAAAA,CAE1BJ,GAAoB,OAAO;CAG/B,IAAIJ,mBAAmBQ,KAAAA,GACrB,OAAOT,OAAOM,QAAQO,OACnBL,MAAMA,EAAEL,SAAS,eAAe,CAAC,CAACK,EAAER,UAAUQ,EAAEE,aAAaD,KAAAA,CAChE;CAGF,OAAOT,OAAOM,QAAQO,OACnBL,MACCA,EAAEL,SAAS,eACX,CAAC,CAACK,EAAER,UACJQ,EAAEE,aAAaD,KAAAA,KACf,CAACR,eAAea,SAASN,EAAEO,QAAQ,CACvC;AACF"}
@@ -16,6 +16,7 @@ declare class ReadonlyThreadRuntimeCore extends BaseSubscribable implements Thre
16
16
  getBranches(messageId: string): string[];
17
17
  switchToBranch(): void;
18
18
  append(): void;
19
+ deleteMessage(): void;
19
20
  startRun(): void;
20
21
  resumeRun(): void;
21
22
  cancelRun(): void;
@@ -72,6 +73,7 @@ declare class ReadonlyThreadRuntimeCore extends BaseSubscribable implements Thre
72
73
  readonly switchToBranch: false;
73
74
  readonly switchBranchDuringRun: false;
74
75
  readonly edit: false;
76
+ readonly delete: false;
75
77
  readonly reload: false;
76
78
  readonly cancel: false;
77
79
  readonly unstable_copy: false;
@@ -1 +1 @@
1
- {"version":3,"file":"ReadonlyThreadRuntimeCore.d.ts","names":[],"sources":["../../../src/runtimes/readonly/ReadonlyThreadRuntimeCore.ts"],"mappings":";;;;;;cASa,yBAAA,SACH,gBAAA,YACG,iBAAA;EAAA,QAEH,SAAA;EAAA,IAEJ,QAAA,aAAQ,aAAA;EAIZ,WAAA,CAAY,QAAA,WAAmB,aAAA;EAM/B,cAAA,CAAe,SAAA;;;;;EAUf,WAAA,CAAY,SAAA;EAMZ,cAAA;EAIA,MAAA;EAIA,QAAA;EAIA,SAAA;EAIA,SAAA;EAEA,aAAA;EAIA,cAAA;EAIA,qBAAA;EAIA,KAAA;EAIA,YAAA;EAEA,YAAA;EAIA,eAAA;EAEA,cA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ThreadRuntimeCore = class extends BaseSubscribable {
30
30
  append() {
31
31
  throw READONLY_THREAD_ERROR;
32
32
  }
33
+ deleteMessage() {
34
+ throw READONLY_THREAD_ERROR;
35
+ }
33
36
  startRun() {
34
37
  throw READONLY_THREAD_ERROR;
35
38
  }
@@ -134,6 +137,7 @@ var ReadonlyThreadRuntimeCore = class extends BaseSubscribable {
134
137
  switchToBranch: false,
135
138
  switchBranchDuringRun: false,
136
139
  edit: false,
140
+ delete: false,
137
141
  reload: false,
138
142
  cancel: false,
139
143
  unstable_copy: false,
@@ -1 +1 @@
1
- {"version":3,"file":"ReadonlyThreadRuntimeCore.js","names":[],"sources":["../../../src/runtimes/readonly/ReadonlyThreadRuntimeCore.ts"],"sourcesContent":["import type { Unsubscribe } from \"../../types/unsubscribe\";\nimport type { ThreadMessage } from \"../../types/message\";\nimport type { ThreadRuntimeCore } from \"../../runtime/interfaces/thread-runtime-core\";\nimport { BaseSubscribable } from \"../../subscribable/subscribable\";\n\nconst READONLY_THREAD_ERROR = new Error(\n \"This is a readonly thread. You cannot perform mutations on readonly threads.\",\n);\n\nexport class ReadonlyThreadRuntimeCore\n extends BaseSubscribable\n implements ThreadRuntimeCore\n{\n private _messages: readonly ThreadMessage[] = [];\n\n get messages() {\n return this._messages;\n }\n\n setMessages(messages: readonly ThreadMessage[]) {\n if (this._messages === messages) return;\n this._messages = messages;\n this._notifySubscribers();\n }\n\n getMessageById(messageId: string) {\n const idx = this._messages.findIndex((m) => m.id === messageId);\n if (idx === -1) return undefined;\n return {\n parentId: this._messages[idx - 1]?.id ?? null,\n message: this._messages[idx]!,\n index: idx,\n };\n }\n\n getBranches(messageId: string) {\n const idx = this._messages.findIndex((m) => m.id === messageId);\n if (idx === -1) return [];\n return [messageId];\n }\n\n switchToBranch(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n append(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n startRun(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n resumeRun(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n cancelRun(): void {}\n\n addToolResult(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n resumeToolCall(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n respondToToolApproval(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n speak(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n stopSpeaking(): void {}\n\n connectVoice(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n disconnectVoice(): void {}\n\n getVoiceVolume = () => 0;\n subscribeVoiceVolume = (): Unsubscribe => () => {};\n\n muteVoice(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n unmuteVoice(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n submitFeedback(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n getModelContext() {\n return {};\n }\n\n exportExternalState() {\n throw READONLY_THREAD_ERROR;\n }\n\n importExternalState(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n composer = {\n attachments: [] as never[],\n attachmentAccept: \"*\",\n\n async addAttachment() {\n throw READONLY_THREAD_ERROR;\n },\n\n async removeAttachment() {\n throw READONLY_THREAD_ERROR;\n },\n\n isEditing: false as const,\n canCancel: false,\n canSend: false,\n isEmpty: true,\n text: \"\",\n\n setText() {\n throw READONLY_THREAD_ERROR;\n },\n\n role: \"user\" as const,\n\n setRole() {\n throw READONLY_THREAD_ERROR;\n },\n\n runConfig: {},\n\n setRunConfig() {\n throw READONLY_THREAD_ERROR;\n },\n\n async reset() {\n // noop\n },\n\n async clearAttachments() {\n // noop\n },\n\n send() {\n throw READONLY_THREAD_ERROR;\n },\n\n cancel() {\n // noop\n },\n\n queue: [] as never[],\n steerQueueItem() {},\n removeQueueItem() {},\n\n dictation: undefined,\n\n startDictation() {\n throw READONLY_THREAD_ERROR;\n },\n\n stopDictation() {\n // noop\n },\n\n quote: undefined,\n\n setQuote() {\n throw READONLY_THREAD_ERROR;\n },\n\n subscribe() {\n return () => {};\n },\n\n unstable_on() {\n return () => {};\n },\n };\n\n getEditComposer() {\n return undefined;\n }\n\n beginEdit(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n speech = undefined;\n voice = undefined;\n\n capabilities = {\n switchToBranch: false,\n switchBranchDuringRun: false,\n edit: false,\n reload: false,\n cancel: false,\n unstable_copy: false,\n speech: false,\n dictation: false,\n voice: false,\n attachments: false,\n feedback: false,\n queue: false,\n } as const;\n\n isDisabled = false;\n isSendDisabled = false;\n isLoading = false;\n\n state = null;\n suggestions = [] as never[];\n extras = undefined;\n\n import(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n export() {\n return {\n messages: this._messages.map((message, idx) => ({\n message,\n parentId: this._messages[idx - 1]?.id ?? null,\n })),\n };\n }\n\n reset(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n unstable_on(): Unsubscribe {\n return () => {};\n }\n}\n"],"mappings":";;AAKA,MAAM,wCAAwB,IAAI,MAChC,8EACF;AAEA,IAAa,4BAAb,cACU,iBAEV;CACE,YAA8C,CAAC;CAE/C,IAAI,WAAW;EACb,OAAO,KAAK;CACd;CAEA,YAAY,UAAoC;EAC9C,IAAI,KAAK,cAAc,UAAU;EACjC,KAAK,YAAY;EACjB,KAAK,mBAAmB;CAC1B;CAEA,eAAe,WAAmB;EAChC,MAAM,MAAM,KAAK,UAAU,WAAW,MAAM,EAAE,OAAO,SAAS;EAC9D,IAAI,QAAQ,IAAI,OAAO,KAAA;EACvB,OAAO;GACL,UAAU,KAAK,UAAU,MAAM,EAAE,EAAE,MAAM;GACzC,SAAS,KAAK,UAAU;GACxB,OAAO;EACT;CACF;CAEA,YAAY,WAAmB;EAE7B,IADY,KAAK,UAAU,WAAW,MAAM,EAAE,OAAO,SAC/C,MAAM,IAAI,OAAO,CAAC;EACxB,OAAO,CAAC,SAAS;CACnB;CAEA,iBAAuB;EACrB,MAAM;CACR;CAEA,SAAe;EACb,MAAM;CACR;CAEA,WAAiB;EACf,MAAM;CACR;CAEA,YAAkB;EAChB,MAAM;CACR;CAEA,YAAkB,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eAAe;EACf,QAAQ;EACR,WAAW;EACX,OAAO;EACP,aAAa;EACb,UAAU;EACV,OAAO;CACT;CAEA,aAAa;CACb,iBAAiB;CACjB,YAAY;CAEZ,QAAQ;CACR,cAAc,CAAC;CACf,SAAS,KAAA;CAET,SAAe;EACb,MAAM;CACR;CAEA,SAAS;EACP,OAAO,EACL,UAAU,KAAK,UAAU,KAAK,SAAS,SAAS;GAC9C;GACA,UAAU,KAAK,UAAU,MAAM,EAAE,EAAE,MAAM;EAC3C,EAAE,EACJ;CACF;CAEA,QAAc;EACZ,MAAM;CACR;CAEA,cAA2B;EACzB,aAAa,CAAC;CAChB;AACF"}
1
+ {"version":3,"file":"ReadonlyThreadRuntimeCore.js","names":["Unsubscribe","ThreadMessage","ThreadRuntimeCore","BaseSubscribable","READONLY_THREAD_ERROR","Error","ReadonlyThreadRuntimeCore","_messages","messages","setMessages","_notifySubscribers","getMessageById","messageId","idx","findIndex","m","id","undefined","parentId","message","index","getBranches","switchToBranch","append","deleteMessage","startRun","resumeRun","cancelRun","addToolResult","resumeToolCall","respondToToolApproval","speak","stopSpeaking","connectVoice","disconnectVoice","getVoiceVolume","subscribeVoiceVolume","muteVoice","unmuteVoice","submitFeedback","getModelContext","exportExternalState","importExternalState","composer","attachments","attachmentAccept","addAttachment","removeAttachment","isEditing","const","canCancel","canSend","isEmpty","text","setText","role","setRole","runConfig","setRunConfig","reset","clearAttachments","send","cancel","queue","steerQueueItem","removeQueueItem","dictation","startDictation","stopDictation","quote","setQuote","subscribe","unstable_on","getEditComposer","beginEdit","speech","voice","capabilities","switchBranchDuringRun","edit","delete","reload","unstable_copy","feedback","isDisabled","isSendDisabled","isLoading","state","suggestions","extras","import","export","map"],"sources":["../../../src/runtimes/readonly/ReadonlyThreadRuntimeCore.ts"],"sourcesContent":["import type { Unsubscribe } from \"../../types/unsubscribe\";\nimport type { ThreadMessage } from \"../../types/message\";\nimport type { ThreadRuntimeCore } from \"../../runtime/interfaces/thread-runtime-core\";\nimport { BaseSubscribable } from \"../../subscribable/subscribable\";\n\nconst READONLY_THREAD_ERROR = new Error(\n \"This is a readonly thread. You cannot perform mutations on readonly threads.\",\n);\n\nexport class ReadonlyThreadRuntimeCore\n extends BaseSubscribable\n implements ThreadRuntimeCore\n{\n private _messages: readonly ThreadMessage[] = [];\n\n get messages() {\n return this._messages;\n }\n\n setMessages(messages: readonly ThreadMessage[]) {\n if (this._messages === messages) return;\n this._messages = messages;\n this._notifySubscribers();\n }\n\n getMessageById(messageId: string) {\n const idx = this._messages.findIndex((m) => m.id === messageId);\n if (idx === -1) return undefined;\n return {\n parentId: this._messages[idx - 1]?.id ?? null,\n message: this._messages[idx]!,\n index: idx,\n };\n }\n\n getBranches(messageId: string) {\n const idx = this._messages.findIndex((m) => m.id === messageId);\n if (idx === -1) return [];\n return [messageId];\n }\n\n switchToBranch(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n append(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n deleteMessage(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n startRun(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n resumeRun(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n cancelRun(): void {}\n\n addToolResult(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n resumeToolCall(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n respondToToolApproval(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n speak(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n stopSpeaking(): void {}\n\n connectVoice(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n disconnectVoice(): void {}\n\n getVoiceVolume = () => 0;\n subscribeVoiceVolume = (): Unsubscribe => () => {};\n\n muteVoice(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n unmuteVoice(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n submitFeedback(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n getModelContext() {\n return {};\n }\n\n exportExternalState() {\n throw READONLY_THREAD_ERROR;\n }\n\n importExternalState(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n composer = {\n attachments: [] as never[],\n attachmentAccept: \"*\",\n\n async addAttachment() {\n throw READONLY_THREAD_ERROR;\n },\n\n async removeAttachment() {\n throw READONLY_THREAD_ERROR;\n },\n\n isEditing: false as const,\n canCancel: false,\n canSend: false,\n isEmpty: true,\n text: \"\",\n\n setText() {\n throw READONLY_THREAD_ERROR;\n },\n\n role: \"user\" as const,\n\n setRole() {\n throw READONLY_THREAD_ERROR;\n },\n\n runConfig: {},\n\n setRunConfig() {\n throw READONLY_THREAD_ERROR;\n },\n\n async reset() {\n // noop\n },\n\n async clearAttachments() {\n // noop\n },\n\n send() {\n throw READONLY_THREAD_ERROR;\n },\n\n cancel() {\n // noop\n },\n\n queue: [] as never[],\n steerQueueItem() {},\n removeQueueItem() {},\n\n dictation: undefined,\n\n startDictation() {\n throw READONLY_THREAD_ERROR;\n },\n\n stopDictation() {\n // noop\n },\n\n quote: undefined,\n\n setQuote() {\n throw READONLY_THREAD_ERROR;\n },\n\n subscribe() {\n return () => {};\n },\n\n unstable_on() {\n return () => {};\n },\n };\n\n getEditComposer() {\n return undefined;\n }\n\n beginEdit(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n speech = undefined;\n voice = undefined;\n\n capabilities = {\n switchToBranch: false,\n switchBranchDuringRun: false,\n edit: false,\n delete: false,\n reload: false,\n cancel: false,\n unstable_copy: false,\n speech: false,\n dictation: false,\n voice: false,\n attachments: false,\n feedback: false,\n queue: false,\n } as const;\n\n isDisabled = false;\n isSendDisabled = false;\n isLoading = false;\n\n state = null;\n suggestions = [] as never[];\n extras = undefined;\n\n import(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n export() {\n return {\n messages: this._messages.map((message, idx) => ({\n message,\n parentId: this._messages[idx - 1]?.id ?? null,\n })),\n };\n }\n\n reset(): void {\n throw READONLY_THREAD_ERROR;\n }\n\n unstable_on(): Unsubscribe {\n return () => {};\n }\n}\n"],"mappings":";;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UAAU,KAAKD,UAAUqF,KAAKzE,SAASN,SAAS;GAC9CM;GACAD,UAAU,KAAKX,UAAUM,MAAM,EAAE,EAAEG,MAAM;EAC3C,EAAE,EACJ;CACF;CAEA2C,QAAc;EACZ,MAAMvD;CACR;CAEAoE,cAA2B;EACzB,aAAa,CAAC;CAChB;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"in-memory.js","names":[],"sources":["../../../../src/runtimes/remote-thread-list/adapter/in-memory.ts"],"sourcesContent":["import type { AssistantStream, AssistantStreamChunk } from \"assistant-stream\";\nimport type {\n RemoteThreadInitializeResponse,\n RemoteThreadListAdapter,\n RemoteThreadListResponse,\n RemoteThreadMetadata,\n} from \"../types\";\n\nexport class InMemoryThreadListAdapter implements RemoteThreadListAdapter {\n list(): Promise<RemoteThreadListResponse> {\n return Promise.resolve({\n threads: [],\n });\n }\n\n rename(): Promise<void> {\n return Promise.resolve();\n }\n\n updateCustom(): Promise<void> {\n return Promise.resolve();\n }\n\n archive(): Promise<void> {\n return Promise.resolve();\n }\n\n unarchive(): Promise<void> {\n return Promise.resolve();\n }\n\n delete(): Promise<void> {\n return Promise.resolve();\n }\n\n initialize(threadId: string): Promise<RemoteThreadInitializeResponse> {\n return Promise.resolve({ remoteId: threadId, externalId: undefined });\n }\n\n generateTitle(): Promise<AssistantStream> {\n return Promise.resolve(new ReadableStream<AssistantStreamChunk>());\n }\n\n fetch(_threadId: string): Promise<RemoteThreadMetadata> {\n return Promise.reject(new Error(\"Thread not found\"));\n }\n}\n"],"mappings":";AAQA,IAAa,4BAAb,MAA0E;CACxE,OAA0C;EACxC,OAAO,QAAQ,QAAQ,EACrB,SAAS,CAAC,EACZ,CAAC;CACH;CAEA,SAAwB;EACtB,OAAO,QAAQ,QAAQ;CACzB;CAEA,eAA8B;EAC5B,OAAO,QAAQ,QAAQ;CACzB;CAEA,UAAyB;EACvB,OAAO,QAAQ,QAAQ;CACzB;CAEA,YAA2B;EACzB,OAAO,QAAQ,QAAQ;CACzB;CAEA,SAAwB;EACtB,OAAO,QAAQ,QAAQ;CACzB;CAEA,WAAW,UAA2D;EACpE,OAAO,QAAQ,QAAQ;GAAE,UAAU;GAAU,YAAY,KAAA;EAAU,CAAC;CACtE;CAEA,gBAA0C;EACxC,OAAO,QAAQ,QAAQ,IAAI,eAAqC,CAAC;CACnE;CAEA,MAAM,WAAkD;EACtD,OAAO,QAAQ,uBAAO,IAAI,MAAM,kBAAkB,CAAC;CACrD;AACF"}
1
+ {"version":3,"file":"in-memory.js","names":["AssistantStream","AssistantStreamChunk","RemoteThreadInitializeResponse","RemoteThreadListAdapter","RemoteThreadListResponse","RemoteThreadMetadata","InMemoryThreadListAdapter","list","Promise","resolve","threads","rename","updateCustom","archive","unarchive","delete","initialize","threadId","remoteId","externalId","undefined","generateTitle","ReadableStream","fetch","_threadId","reject","Error"],"sources":["../../../../src/runtimes/remote-thread-list/adapter/in-memory.ts"],"sourcesContent":["import type { AssistantStream, AssistantStreamChunk } from \"assistant-stream\";\nimport type {\n RemoteThreadInitializeResponse,\n RemoteThreadListAdapter,\n RemoteThreadListResponse,\n RemoteThreadMetadata,\n} from \"../types\";\n\nexport class InMemoryThreadListAdapter implements RemoteThreadListAdapter {\n list(): Promise<RemoteThreadListResponse> {\n return Promise.resolve({\n threads: [],\n });\n }\n\n rename(): Promise<void> {\n return Promise.resolve();\n }\n\n updateCustom(): Promise<void> {\n return Promise.resolve();\n }\n\n archive(): Promise<void> {\n return Promise.resolve();\n }\n\n unarchive(): Promise<void> {\n return Promise.resolve();\n }\n\n delete(): Promise<void> {\n return Promise.resolve();\n }\n\n initialize(threadId: string): Promise<RemoteThreadInitializeResponse> {\n return Promise.resolve({ remoteId: threadId, externalId: undefined });\n }\n\n generateTitle(): Promise<AssistantStream> {\n return Promise.resolve(new ReadableStream<AssistantStreamChunk>());\n }\n\n fetch(_threadId: string): Promise<RemoteThreadMetadata> {\n return Promise.reject(new Error(\"Thread not found\"));\n }\n}\n"],"mappings":";AAQA,IAAaM,4BAAb,MAA0E;CACxEC,OAA0C;EACxC,OAAOC,QAAQC,QAAQ,EACrBC,SAAS,CAAA,EACX,CAAC;CACH;CAEAC,SAAwB;EACtB,OAAOH,QAAQC,QAAQ;CACzB;CAEAG,eAA8B;EAC5B,OAAOJ,QAAQC,QAAQ;CACzB;CAEAI,UAAyB;EACvB,OAAOL,QAAQC,QAAQ;CACzB;CAEAK,YAA2B;EACzB,OAAON,QAAQC,QAAQ;CACzB;CAEAM,SAAwB;EACtB,OAAOP,QAAQC,QAAQ;CACzB;CAEAO,WAAWC,UAA2D;EACpE,OAAOT,QAAQC,QAAQ;GAAES,UAAUD;GAAUE,YAAYC,KAAAA;EAAU,CAAC;CACtE;CAEAC,gBAA0C;EACxC,OAAOb,QAAQC,QAAQ,IAAIa,eAAqC,CAAC;CACnE;CAEAC,MAAMC,WAAkD;EACtD,OAAOhB,QAAQiB,uBAAO,IAAIC,MAAM,kBAAkB,CAAC;CACrD;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"empty-thread-core.d.ts","names":[],"sources":["../../../src/runtimes/remote-thread-list/empty-thread-core.ts"],"mappings":";;;cAKa,iBAAA,EAAmB,iBA8N/B"}
1
+ {"version":3,"file":"empty-thread-core.d.ts","names":[],"sources":["../../../src/runtimes/remote-thread-list/empty-thread-core.ts"],"mappings":";;;cAKa,iBAAA,EAAmB,iBAmO/B"}
@@ -11,6 +11,9 @@ const EMPTY_THREAD_CORE = {
11
11
  append() {
12
12
  throw EMPTY_THREAD_ERROR;
13
13
  },
14
+ deleteMessage() {
15
+ throw EMPTY_THREAD_ERROR;
16
+ },
14
17
  startRun() {
15
18
  throw EMPTY_THREAD_ERROR;
16
19
  },
@@ -121,6 +124,7 @@ const EMPTY_THREAD_CORE = {
121
124
  switchToBranch: false,
122
125
  switchBranchDuringRun: false,
123
126
  edit: false,
127
+ delete: false,
124
128
  reload: false,
125
129
  cancel: false,
126
130
  unstable_copy: false,
@@ -1 +1 @@
1
- {"version":3,"file":"empty-thread-core.js","names":[],"sources":["../../../src/runtimes/remote-thread-list/empty-thread-core.ts"],"sourcesContent":["import type { ThreadRuntimeCore } from \"../../runtime/interfaces/thread-runtime-core\";\n\nconst EMPTY_THREAD_ERROR = new Error(\n \"This is the empty thread, a placeholder for the main thread. You cannot perform any actions on this thread instance. This error is probably because you tried to call a thread method in your render function. Call the method inside a `useEffect` hook instead.\",\n);\nexport const EMPTY_THREAD_CORE: ThreadRuntimeCore = {\n getMessageById() {\n return undefined;\n },\n\n getBranches() {\n return [];\n },\n\n switchToBranch() {\n throw EMPTY_THREAD_ERROR;\n },\n\n append() {\n throw EMPTY_THREAD_ERROR;\n },\n\n startRun() {\n throw EMPTY_THREAD_ERROR;\n },\n\n resumeRun() {\n throw EMPTY_THREAD_ERROR;\n },\n\n cancelRun() {\n throw EMPTY_THREAD_ERROR;\n },\n\n addToolResult() {\n throw EMPTY_THREAD_ERROR;\n },\n\n resumeToolCall() {\n throw EMPTY_THREAD_ERROR;\n },\n\n respondToToolApproval() {\n throw EMPTY_THREAD_ERROR;\n },\n\n speak() {\n throw EMPTY_THREAD_ERROR;\n },\n\n stopSpeaking() {\n throw EMPTY_THREAD_ERROR;\n },\n\n connectVoice() {\n throw EMPTY_THREAD_ERROR;\n },\n\n disconnectVoice() {\n throw EMPTY_THREAD_ERROR;\n },\n\n getVoiceVolume: () => 0,\n subscribeVoiceVolume: () => () => {},\n\n muteVoice() {\n throw EMPTY_THREAD_ERROR;\n },\n\n unmuteVoice() {\n throw EMPTY_THREAD_ERROR;\n },\n\n submitFeedback() {\n throw EMPTY_THREAD_ERROR;\n },\n\n getModelContext() {\n return {};\n },\n\n exportExternalState() {\n throw EMPTY_THREAD_ERROR;\n },\n\n importExternalState() {\n throw EMPTY_THREAD_ERROR;\n },\n\n composer: {\n attachments: [],\n attachmentAccept: \"*\",\n\n async addAttachment() {\n throw EMPTY_THREAD_ERROR;\n },\n\n async removeAttachment() {\n throw EMPTY_THREAD_ERROR;\n },\n\n isEditing: true,\n\n canCancel: false,\n canSend: false,\n isEmpty: true,\n\n text: \"\",\n\n setText() {\n throw EMPTY_THREAD_ERROR;\n },\n\n role: \"user\",\n\n setRole() {\n throw EMPTY_THREAD_ERROR;\n },\n\n runConfig: {},\n\n setRunConfig() {\n throw EMPTY_THREAD_ERROR;\n },\n\n async reset() {\n // noop\n },\n\n async clearAttachments() {\n // noop\n },\n\n send() {\n throw EMPTY_THREAD_ERROR;\n },\n\n cancel() {\n // noop\n },\n\n queue: [] as never[],\n steerQueueItem() {},\n removeQueueItem() {},\n\n dictation: undefined,\n\n startDictation() {\n throw EMPTY_THREAD_ERROR;\n },\n\n stopDictation() {\n // noop\n },\n\n quote: undefined,\n\n setQuote() {\n throw EMPTY_THREAD_ERROR;\n },\n\n subscribe() {\n return () => {};\n },\n\n unstable_on() {\n return () => {};\n },\n },\n\n getEditComposer() {\n return undefined;\n },\n\n beginEdit() {\n throw EMPTY_THREAD_ERROR;\n },\n\n speech: undefined,\n voice: undefined,\n\n capabilities: {\n switchToBranch: false,\n switchBranchDuringRun: false,\n edit: false,\n reload: false,\n cancel: false,\n unstable_copy: false,\n speech: false,\n dictation: false,\n voice: false,\n attachments: false,\n feedback: false,\n queue: false,\n },\n\n isDisabled: false,\n isSendDisabled: false,\n isLoading: true,\n\n messages: [],\n\n state: null,\n\n suggestions: [],\n\n extras: undefined,\n\n subscribe() {\n return () => {};\n },\n\n import() {\n throw EMPTY_THREAD_ERROR;\n },\n\n export() {\n return { messages: [] };\n },\n\n reset() {\n throw EMPTY_THREAD_ERROR;\n },\n\n unstable_on() {\n return () => {};\n },\n};\n"],"mappings":";AAEA,MAAM,qCAAqB,IAAI,MAC7B,mQACF;AACA,MAAa,oBAAuC;CAClD,iBAAiB,CAEjB;CAEA,cAAc;EACZ,OAAO,CAAC;CACV;CAEA,iBAAiB;EACf,MAAM;CACR;CAEA,SAAS;EACP,MAAM;CACR;CAEA,WAAW;EACT,MAAM;CACR;CAEA,YAAY;EACV,MAAM;CACR;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N,QAAQ;EACR,QAAQ;EACR,eAAe;EACf,QAAQ;EACR,WAAW;EACX,OAAO;EACP,aAAa;EACb,UAAU;EACV,OAAO;CACT;CAEA,YAAY;CACZ,gBAAgB;CAChB,WAAW;CAEX,UAAU,CAAC;CAEX,OAAO;CAEP,aAAa,CAAC;CAEd,QAAQ,KAAA;CAER,YAAY;EACV,aAAa,CAAC;CAChB;CAEA,SAAS;EACP,MAAM;CACR;CAEA,SAAS;EACP,OAAO,EAAE,UAAU,CAAC,EAAE;CACxB;CAEA,QAAQ;EACN,MAAM;CACR;CAEA,cAAc;EACZ,aAAa,CAAC;CAChB;AACF"}
1
+ {"version":3,"file":"empty-thread-core.js","names":["ThreadRuntimeCore","EMPTY_THREAD_ERROR","Error","EMPTY_THREAD_CORE","getMessageById","undefined","getBranches","switchToBranch","append","deleteMessage","startRun","resumeRun","cancelRun","addToolResult","resumeToolCall","respondToToolApproval","speak","stopSpeaking","connectVoice","disconnectVoice","getVoiceVolume","subscribeVoiceVolume","muteVoice","unmuteVoice","submitFeedback","getModelContext","exportExternalState","importExternalState","composer","attachments","attachmentAccept","addAttachment","removeAttachment","isEditing","canCancel","canSend","isEmpty","text","setText","role","setRole","runConfig","setRunConfig","reset","clearAttachments","send","cancel","queue","steerQueueItem","removeQueueItem","dictation","startDictation","stopDictation","quote","setQuote","subscribe","unstable_on","getEditComposer","beginEdit","speech","voice","capabilities","switchBranchDuringRun","edit","delete","reload","unstable_copy","feedback","isDisabled","isSendDisabled","isLoading","messages","state","suggestions","extras","import","export"],"sources":["../../../src/runtimes/remote-thread-list/empty-thread-core.ts"],"sourcesContent":["import type { ThreadRuntimeCore } from \"../../runtime/interfaces/thread-runtime-core\";\n\nconst EMPTY_THREAD_ERROR = new Error(\n \"This is the empty thread, a placeholder for the main thread. You cannot perform any actions on this thread instance. This error is probably because you tried to call a thread method in your render function. Call the method inside a `useEffect` hook instead.\",\n);\nexport const EMPTY_THREAD_CORE: ThreadRuntimeCore = {\n getMessageById() {\n return undefined;\n },\n\n getBranches() {\n return [];\n },\n\n switchToBranch() {\n throw EMPTY_THREAD_ERROR;\n },\n\n append() {\n throw EMPTY_THREAD_ERROR;\n },\n\n deleteMessage() {\n throw EMPTY_THREAD_ERROR;\n },\n\n startRun() {\n throw EMPTY_THREAD_ERROR;\n },\n\n resumeRun() {\n throw EMPTY_THREAD_ERROR;\n },\n\n cancelRun() {\n throw EMPTY_THREAD_ERROR;\n },\n\n addToolResult() {\n throw EMPTY_THREAD_ERROR;\n },\n\n resumeToolCall() {\n throw EMPTY_THREAD_ERROR;\n },\n\n respondToToolApproval() {\n throw EMPTY_THREAD_ERROR;\n },\n\n speak() {\n throw EMPTY_THREAD_ERROR;\n },\n\n stopSpeaking() {\n throw EMPTY_THREAD_ERROR;\n },\n\n connectVoice() {\n throw EMPTY_THREAD_ERROR;\n },\n\n disconnectVoice() {\n throw EMPTY_THREAD_ERROR;\n },\n\n getVoiceVolume: () => 0,\n subscribeVoiceVolume: () => () => {},\n\n muteVoice() {\n throw EMPTY_THREAD_ERROR;\n },\n\n unmuteVoice() {\n throw EMPTY_THREAD_ERROR;\n },\n\n submitFeedback() {\n throw EMPTY_THREAD_ERROR;\n },\n\n getModelContext() {\n return {};\n },\n\n exportExternalState() {\n throw EMPTY_THREAD_ERROR;\n },\n\n importExternalState() {\n throw EMPTY_THREAD_ERROR;\n },\n\n composer: {\n attachments: [],\n attachmentAccept: \"*\",\n\n async addAttachment() {\n throw EMPTY_THREAD_ERROR;\n },\n\n async removeAttachment() {\n throw EMPTY_THREAD_ERROR;\n },\n\n isEditing: true,\n\n canCancel: false,\n canSend: false,\n isEmpty: true,\n\n text: \"\",\n\n setText() {\n throw EMPTY_THREAD_ERROR;\n },\n\n role: \"user\",\n\n setRole() {\n throw EMPTY_THREAD_ERROR;\n },\n\n runConfig: {},\n\n setRunConfig() {\n throw EMPTY_THREAD_ERROR;\n },\n\n async reset() {\n // noop\n },\n\n async clearAttachments() {\n // noop\n },\n\n send() {\n throw EMPTY_THREAD_ERROR;\n },\n\n cancel() {\n // noop\n },\n\n queue: [] as never[],\n steerQueueItem() {},\n removeQueueItem() {},\n\n dictation: undefined,\n\n startDictation() {\n throw EMPTY_THREAD_ERROR;\n },\n\n stopDictation() {\n // noop\n },\n\n quote: undefined,\n\n setQuote() {\n throw EMPTY_THREAD_ERROR;\n },\n\n subscribe() {\n return () => {};\n },\n\n unstable_on() {\n return () => {};\n },\n },\n\n getEditComposer() {\n return undefined;\n },\n\n beginEdit() {\n throw EMPTY_THREAD_ERROR;\n },\n\n speech: undefined,\n voice: undefined,\n\n capabilities: {\n switchToBranch: false,\n switchBranchDuringRun: false,\n edit: false,\n delete: false,\n reload: false,\n cancel: false,\n unstable_copy: false,\n speech: false,\n dictation: false,\n voice: false,\n attachments: false,\n feedback: false,\n queue: false,\n },\n\n isDisabled: false,\n isSendDisabled: false,\n isLoading: true,\n\n messages: [],\n\n state: null,\n\n suggestions: [],\n\n extras: undefined,\n\n subscribe() {\n return () => {};\n },\n\n import() {\n throw EMPTY_THREAD_ERROR;\n },\n\n export() {\n return { messages: [] };\n },\n\n reset() {\n throw EMPTY_THREAD_ERROR;\n },\n\n unstable_on() {\n return () => {};\n },\n};\n"],"mappings":";AAEA,MAAMC,qCAAqB,IAAIC,MAC7B,mQACF;AACA,MAAaC,oBAAuC;CAClDC,iBAAiB,CAEjB;CAEAE,cAAc;EACZ,OAAO,CAAA;CACT;CAEAC,iBAAiB;EACf,MAAMN;CACR;CAEAO,SAAS;EACP,MAAMP;CACR;CAEAQ,gBAAgB;EACd,MAAMR;CACR;CAEAS,WAAW;EACT,MAAMT;CACR;CAEAU,YAAY;EACV,MAAMV;CACR;CAEAW,YAAY;EACV,MAAMX;CACR;CAEAY,gBAAgB;EACd,MAAMZ;CACR;CAEAa,iBAAiB;EACf,MAAMb;CACR;CAEAc,wBAAwB;EACtB,MAAMd;CACR;CAEAe,QAAQ;EACN,MAAMf;CACR;CAEAgB,eAAe;EACb,MAAMhB;CACR;C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