@assistant-ui/core 0.1.0

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 (599) hide show
  1. package/dist/adapters/attachment.d.ts +36 -0
  2. package/dist/adapters/attachment.d.ts.map +1 -0
  3. package/dist/adapters/attachment.js +148 -0
  4. package/dist/adapters/attachment.js.map +1 -0
  5. package/dist/adapters/feedback.d.ts +10 -0
  6. package/dist/adapters/feedback.d.ts.map +1 -0
  7. package/dist/adapters/feedback.js +2 -0
  8. package/dist/adapters/feedback.js.map +1 -0
  9. package/dist/adapters/index.d.ts +8 -0
  10. package/dist/adapters/index.d.ts.map +1 -0
  11. package/dist/adapters/index.js +3 -0
  12. package/dist/adapters/index.js.map +1 -0
  13. package/dist/adapters/speech.d.ts +76 -0
  14. package/dist/adapters/speech.d.ts.map +1 -0
  15. package/dist/adapters/speech.js +179 -0
  16. package/dist/adapters/speech.js.map +1 -0
  17. package/dist/adapters/suggestion.d.ts +10 -0
  18. package/dist/adapters/suggestion.d.ts.map +1 -0
  19. package/dist/adapters/suggestion.js +2 -0
  20. package/dist/adapters/suggestion.js.map +1 -0
  21. package/dist/adapters/thread-history.d.ts +43 -0
  22. package/dist/adapters/thread-history.d.ts.map +1 -0
  23. package/dist/adapters/thread-history.js +2 -0
  24. package/dist/adapters/thread-history.js.map +1 -0
  25. package/dist/index.d.ts +6 -0
  26. package/dist/index.d.ts.map +1 -0
  27. package/dist/index.js +7 -0
  28. package/dist/index.js.map +1 -0
  29. package/dist/internal.d.ts +5 -0
  30. package/dist/internal.d.ts.map +1 -0
  31. package/dist/internal.js +7 -0
  32. package/dist/internal.js.map +1 -0
  33. package/dist/model-context/frame/host.d.ts +21 -0
  34. package/dist/model-context/frame/host.d.ts.map +1 -0
  35. package/dist/model-context/frame/host.js +141 -0
  36. package/dist/model-context/frame/host.js.map +1 -0
  37. package/dist/model-context/frame/index.d.ts +5 -0
  38. package/dist/model-context/frame/index.d.ts.map +1 -0
  39. package/dist/model-context/frame/index.js +4 -0
  40. package/dist/model-context/frame/index.js.map +1 -0
  41. package/dist/model-context/frame/provider.d.ts +18 -0
  42. package/dist/model-context/frame/provider.d.ts.map +1 -0
  43. package/dist/model-context/frame/provider.js +133 -0
  44. package/dist/model-context/frame/provider.js.map +1 -0
  45. package/dist/model-context/frame/types.d.ts +29 -0
  46. package/dist/model-context/frame/types.d.ts.map +1 -0
  47. package/dist/model-context/frame/types.js +2 -0
  48. package/dist/model-context/frame/types.js.map +1 -0
  49. package/dist/model-context/index.d.ts +8 -0
  50. package/dist/model-context/index.d.ts.map +1 -0
  51. package/dist/model-context/index.js +9 -0
  52. package/dist/model-context/index.js.map +1 -0
  53. package/dist/model-context/registry-handles.d.ts +13 -0
  54. package/dist/model-context/registry-handles.d.ts.map +1 -0
  55. package/dist/model-context/registry-handles.js +2 -0
  56. package/dist/model-context/registry-handles.js.map +1 -0
  57. package/dist/model-context/registry.d.ts +17 -0
  58. package/dist/model-context/registry.d.ts.map +1 -0
  59. package/dist/model-context/registry.js +108 -0
  60. package/dist/model-context/registry.js.map +1 -0
  61. package/dist/model-context/tool.d.ts +3 -0
  62. package/dist/model-context/tool.d.ts.map +1 -0
  63. package/dist/model-context/tool.js +5 -0
  64. package/dist/model-context/tool.js.map +1 -0
  65. package/dist/model-context/types.d.ts +37 -0
  66. package/dist/model-context/types.d.ts.map +1 -0
  67. package/dist/model-context/types.js +43 -0
  68. package/dist/model-context/types.js.map +1 -0
  69. package/dist/runtime/api/assistant-runtime.d.ts +64 -0
  70. package/dist/runtime/api/assistant-runtime.d.ts.map +1 -0
  71. package/dist/runtime/api/assistant-runtime.js +46 -0
  72. package/dist/runtime/api/assistant-runtime.js.map +1 -0
  73. package/dist/runtime/api/attachment-runtime.d.ts +63 -0
  74. package/dist/runtime/api/attachment-runtime.d.ts.map +1 -0
  75. package/dist/runtime/api/attachment-runtime.js +56 -0
  76. package/dist/runtime/api/attachment-runtime.js.map +1 -0
  77. package/dist/runtime/api/bindings.d.ts +31 -0
  78. package/dist/runtime/api/bindings.d.ts.map +1 -0
  79. package/dist/runtime/api/bindings.js +2 -0
  80. package/dist/runtime/api/bindings.js.map +1 -0
  81. package/dist/runtime/api/composer-runtime.d.ts +181 -0
  82. package/dist/runtime/api/composer-runtime.d.ts.map +1 -0
  83. package/dist/runtime/api/composer-runtime.js +247 -0
  84. package/dist/runtime/api/composer-runtime.js.map +1 -0
  85. package/dist/runtime/api/message-part-runtime.d.ts +31 -0
  86. package/dist/runtime/api/message-part-runtime.d.ts.map +1 -0
  87. package/dist/runtime/api/message-part-runtime.js +67 -0
  88. package/dist/runtime/api/message-part-runtime.js.map +1 -0
  89. package/dist/runtime/api/message-runtime.d.ts +91 -0
  90. package/dist/runtime/api/message-runtime.d.ts.map +1 -0
  91. package/dist/runtime/api/message-runtime.js +199 -0
  92. package/dist/runtime/api/message-runtime.js.map +1 -0
  93. package/dist/runtime/api/paths.d.ts +64 -0
  94. package/dist/runtime/api/paths.d.ts.map +1 -0
  95. package/dist/runtime/api/paths.js +2 -0
  96. package/dist/runtime/api/paths.js.map +1 -0
  97. package/dist/runtime/api/thread-list-item-runtime.d.ts +50 -0
  98. package/dist/runtime/api/thread-list-item-runtime.d.ts.map +1 -0
  99. package/dist/runtime/api/thread-list-item-runtime.js +85 -0
  100. package/dist/runtime/api/thread-list-item-runtime.js.map +1 -0
  101. package/dist/runtime/api/thread-list-runtime.d.ts +44 -0
  102. package/dist/runtime/api/thread-list-runtime.d.ts.map +1 -0
  103. package/dist/runtime/api/thread-list-runtime.js +136 -0
  104. package/dist/runtime/api/thread-list-runtime.js.map +1 -0
  105. package/dist/runtime/api/thread-runtime.d.ts +272 -0
  106. package/dist/runtime/api/thread-runtime.d.ts.map +1 -0
  107. package/dist/runtime/api/thread-runtime.js +240 -0
  108. package/dist/runtime/api/thread-runtime.js.map +1 -0
  109. package/dist/runtime/base/base-assistant-runtime-core.d.ts +12 -0
  110. package/dist/runtime/base/base-assistant-runtime-core.d.ts.map +1 -0
  111. package/dist/runtime/base/base-assistant-runtime-core.js +11 -0
  112. package/dist/runtime/base/base-assistant-runtime-core.js.map +1 -0
  113. package/dist/runtime/base/base-composer-runtime-core.d.ts +55 -0
  114. package/dist/runtime/base/base-composer-runtime-core.d.ts.map +1 -0
  115. package/dist/runtime/base/base-composer-runtime-core.js +320 -0
  116. package/dist/runtime/base/base-composer-runtime-core.js.map +1 -0
  117. package/dist/runtime/base/base-thread-runtime-core.d.ts +67 -0
  118. package/dist/runtime/base/base-thread-runtime-core.d.ts.map +1 -0
  119. package/dist/runtime/base/base-thread-runtime-core.js +157 -0
  120. package/dist/runtime/base/base-thread-runtime-core.js.map +1 -0
  121. package/dist/runtime/base/default-edit-composer-runtime-core.d.ts +28 -0
  122. package/dist/runtime/base/default-edit-composer-runtime-core.d.ts.map +1 -0
  123. package/dist/runtime/base/default-edit-composer-runtime-core.js +49 -0
  124. package/dist/runtime/base/default-edit-composer-runtime-core.js.map +1 -0
  125. package/dist/runtime/base/default-thread-composer-runtime-core.d.ts +24 -0
  126. package/dist/runtime/base/default-thread-composer-runtime-core.d.ts.map +1 -0
  127. package/dist/runtime/base/default-thread-composer-runtime-core.js +41 -0
  128. package/dist/runtime/base/default-thread-composer-runtime-core.js.map +1 -0
  129. package/dist/runtime/index.d.ts +20 -0
  130. package/dist/runtime/index.d.ts.map +1 -0
  131. package/dist/runtime/index.js +7 -0
  132. package/dist/runtime/index.js.map +1 -0
  133. package/dist/runtime/interfaces/assistant-runtime-core.d.ts +10 -0
  134. package/dist/runtime/interfaces/assistant-runtime-core.d.ts.map +1 -0
  135. package/dist/runtime/interfaces/assistant-runtime-core.js +2 -0
  136. package/dist/runtime/interfaces/assistant-runtime-core.js.map +1 -0
  137. package/dist/runtime/interfaces/composer-runtime-core.d.ts +38 -0
  138. package/dist/runtime/interfaces/composer-runtime-core.d.ts.map +1 -0
  139. package/dist/runtime/interfaces/composer-runtime-core.js +2 -0
  140. package/dist/runtime/interfaces/composer-runtime-core.js.map +1 -0
  141. package/dist/runtime/interfaces/thread-list-runtime-core.d.ts +37 -0
  142. package/dist/runtime/interfaces/thread-list-runtime-core.d.ts.map +1 -0
  143. package/dist/runtime/interfaces/thread-list-runtime-core.js +2 -0
  144. package/dist/runtime/interfaces/thread-list-runtime-core.js.map +1 -0
  145. package/dist/runtime/interfaces/thread-runtime-core.d.ts +97 -0
  146. package/dist/runtime/interfaces/thread-runtime-core.d.ts.map +1 -0
  147. package/dist/runtime/interfaces/thread-runtime-core.js +2 -0
  148. package/dist/runtime/interfaces/thread-runtime-core.js.map +1 -0
  149. package/dist/runtime/internal.d.ts +23 -0
  150. package/dist/runtime/internal.d.ts.map +1 -0
  151. package/dist/runtime/internal.js +25 -0
  152. package/dist/runtime/internal.js.map +1 -0
  153. package/dist/runtime/utils/auto-status.d.ts +5 -0
  154. package/dist/runtime/utils/auto-status.d.ts.map +1 -0
  155. package/dist/runtime/utils/auto-status.js +32 -0
  156. package/dist/runtime/utils/auto-status.js.map +1 -0
  157. package/dist/runtime/utils/chat-model-adapter.d.ts +40 -0
  158. package/dist/runtime/utils/chat-model-adapter.d.ts.map +1 -0
  159. package/dist/runtime/utils/chat-model-adapter.js +2 -0
  160. package/dist/runtime/utils/chat-model-adapter.js.map +1 -0
  161. package/dist/runtime/utils/external-store-message.d.ts +10 -0
  162. package/dist/runtime/utils/external-store-message.d.ts.map +1 -0
  163. package/dist/runtime/utils/external-store-message.js +22 -0
  164. package/dist/runtime/utils/external-store-message.js.map +1 -0
  165. package/dist/runtime/utils/message-repository.d.ts +43 -0
  166. package/dist/runtime/utils/message-repository.d.ts.map +1 -0
  167. package/dist/runtime/utils/message-repository.js +257 -0
  168. package/dist/runtime/utils/message-repository.js.map +1 -0
  169. package/dist/runtime/utils/thread-message-like.d.ts +34 -0
  170. package/dist/runtime/utils/thread-message-like.d.ts.map +1 -0
  171. package/dist/runtime/utils/thread-message-like.js +129 -0
  172. package/dist/runtime/utils/thread-message-like.js.map +1 -0
  173. package/dist/runtimes/assistant-transport/utils.d.ts +11 -0
  174. package/dist/runtimes/assistant-transport/utils.d.ts.map +1 -0
  175. package/dist/runtimes/assistant-transport/utils.js +20 -0
  176. package/dist/runtimes/assistant-transport/utils.js.map +1 -0
  177. package/dist/runtimes/external-store/external-store-adapter.d.ts +81 -0
  178. package/dist/runtimes/external-store/external-store-adapter.d.ts.map +1 -0
  179. package/dist/runtimes/external-store/external-store-adapter.js +2 -0
  180. package/dist/runtimes/external-store/external-store-adapter.js.map +1 -0
  181. package/dist/runtimes/external-store/external-store-runtime-core.d.ts +9 -0
  182. package/dist/runtimes/external-store/external-store-runtime-core.d.ts.map +1 -0
  183. package/dist/runtimes/external-store/external-store-runtime-core.js +19 -0
  184. package/dist/runtimes/external-store/external-store-runtime-core.js.map +1 -0
  185. package/dist/runtimes/external-store/external-store-thread-list-runtime-core.d.ts +42 -0
  186. package/dist/runtimes/external-store/external-store-thread-list-runtime-core.d.ts.map +1 -0
  187. package/dist/runtimes/external-store/external-store-thread-list-runtime-core.js +174 -0
  188. package/dist/runtimes/external-store/external-store-thread-list-runtime-core.js.map +1 -0
  189. package/dist/runtimes/external-store/external-store-thread-runtime-core.d.ts +47 -0
  190. package/dist/runtimes/external-store/external-store-thread-runtime-core.d.ts.map +1 -0
  191. package/dist/runtimes/external-store/external-store-thread-runtime-core.js +260 -0
  192. package/dist/runtimes/external-store/external-store-thread-runtime-core.js.map +1 -0
  193. package/dist/runtimes/external-store/index.d.ts +8 -0
  194. package/dist/runtimes/external-store/index.d.ts.map +1 -0
  195. package/dist/runtimes/external-store/index.js +5 -0
  196. package/dist/runtimes/external-store/index.js.map +1 -0
  197. package/dist/runtimes/external-store/thread-message-converter.d.ts +7 -0
  198. package/dist/runtimes/external-store/thread-message-converter.d.ts.map +1 -0
  199. package/dist/runtimes/external-store/thread-message-converter.js +12 -0
  200. package/dist/runtimes/external-store/thread-message-converter.js.map +1 -0
  201. package/dist/runtimes/index.d.ts +6 -0
  202. package/dist/runtimes/index.d.ts.map +1 -0
  203. package/dist/runtimes/index.js +4 -0
  204. package/dist/runtimes/index.js.map +1 -0
  205. package/dist/runtimes/internal.d.ts +18 -0
  206. package/dist/runtimes/internal.d.ts.map +1 -0
  207. package/dist/runtimes/internal.js +15 -0
  208. package/dist/runtimes/internal.js.map +1 -0
  209. package/dist/runtimes/local/index.d.ts +7 -0
  210. package/dist/runtimes/local/index.d.ts.map +1 -0
  211. package/dist/runtimes/local/index.js +5 -0
  212. package/dist/runtimes/local/index.js.map +1 -0
  213. package/dist/runtimes/local/local-runtime-core.d.ts +11 -0
  214. package/dist/runtimes/local/local-runtime-core.d.ts.map +1 -0
  215. package/dist/runtimes/local/local-runtime-core.js +22 -0
  216. package/dist/runtimes/local/local-runtime-core.js.map +1 -0
  217. package/dist/runtimes/local/local-runtime-options.d.ts +23 -0
  218. package/dist/runtimes/local/local-runtime-options.d.ts.map +1 -0
  219. package/dist/runtimes/local/local-runtime-options.js +2 -0
  220. package/dist/runtimes/local/local-runtime-options.js.map +1 -0
  221. package/dist/runtimes/local/local-thread-list-runtime-core.d.ts +46 -0
  222. package/dist/runtimes/local/local-thread-list-runtime-core.d.ts.map +1 -0
  223. package/dist/runtimes/local/local-thread-list-runtime-core.js +87 -0
  224. package/dist/runtimes/local/local-thread-list-runtime-core.js.map +1 -0
  225. package/dist/runtimes/local/local-thread-runtime-core.d.ts +59 -0
  226. package/dist/runtimes/local/local-thread-runtime-core.d.ts.map +1 -0
  227. package/dist/runtimes/local/local-thread-runtime-core.js +423 -0
  228. package/dist/runtimes/local/local-thread-runtime-core.js.map +1 -0
  229. package/dist/runtimes/local/should-continue.d.ts +3 -0
  230. package/dist/runtimes/local/should-continue.d.ts.map +1 -0
  231. package/dist/runtimes/local/should-continue.js +14 -0
  232. package/dist/runtimes/local/should-continue.js.map +1 -0
  233. package/dist/runtimes/remote-thread-list/adapter/in-memory.d.ts +13 -0
  234. package/dist/runtimes/remote-thread-list/adapter/in-memory.d.ts.map +1 -0
  235. package/dist/runtimes/remote-thread-list/adapter/in-memory.js +29 -0
  236. package/dist/runtimes/remote-thread-list/adapter/in-memory.js.map +1 -0
  237. package/dist/runtimes/remote-thread-list/empty-thread-core.d.ts +3 -0
  238. package/dist/runtimes/remote-thread-list/empty-thread-core.d.ts.map +1 -0
  239. package/dist/runtimes/remote-thread-list/empty-thread-core.js +146 -0
  240. package/dist/runtimes/remote-thread-list/empty-thread-core.js.map +1 -0
  241. package/dist/runtimes/remote-thread-list/optimistic-state.d.ts +23 -0
  242. package/dist/runtimes/remote-thread-list/optimistic-state.d.ts.map +1 -0
  243. package/dist/runtimes/remote-thread-list/optimistic-state.js +57 -0
  244. package/dist/runtimes/remote-thread-list/optimistic-state.js.map +1 -0
  245. package/dist/runtimes/remote-thread-list/remote-thread-state.d.ts +37 -0
  246. package/dist/runtimes/remote-thread-list/remote-thread-state.d.ts.map +1 -0
  247. package/dist/runtimes/remote-thread-list/remote-thread-state.js +62 -0
  248. package/dist/runtimes/remote-thread-list/remote-thread-state.js.map +1 -0
  249. package/dist/runtimes/remote-thread-list/types.d.ts +38 -0
  250. package/dist/runtimes/remote-thread-list/types.d.ts.map +1 -0
  251. package/dist/runtimes/remote-thread-list/types.js +2 -0
  252. package/dist/runtimes/remote-thread-list/types.js.map +1 -0
  253. package/dist/store/clients/chain-of-thought-client.d.ts +15 -0
  254. package/dist/store/clients/chain-of-thought-client.d.ts.map +1 -0
  255. package/dist/store/clients/chain-of-thought-client.js +18 -0
  256. package/dist/store/clients/chain-of-thought-client.js.map +1 -0
  257. package/dist/store/clients/index.d.ts +6 -0
  258. package/dist/store/clients/index.d.ts.map +1 -0
  259. package/dist/store/clients/index.js +6 -0
  260. package/dist/store/clients/index.js.map +1 -0
  261. package/dist/store/clients/model-context-client.d.ts +3 -0
  262. package/dist/store/clients/model-context-client.d.ts.map +1 -0
  263. package/dist/store/clients/model-context-client.js +14 -0
  264. package/dist/store/clients/model-context-client.js.map +1 -0
  265. package/dist/store/clients/no-op-composer-client.d.ts +7 -0
  266. package/dist/store/clients/no-op-composer-client.d.ts.map +1 -0
  267. package/dist/store/clients/no-op-composer-client.js +61 -0
  268. package/dist/store/clients/no-op-composer-client.js.map +1 -0
  269. package/dist/store/clients/suggestions.d.ts +11 -0
  270. package/dist/store/clients/suggestions.d.ts.map +1 -0
  271. package/dist/store/clients/suggestions.js +37 -0
  272. package/dist/store/clients/suggestions.js.map +1 -0
  273. package/dist/store/clients/thread-message-client.d.ts +11 -0
  274. package/dist/store/clients/thread-message-client.d.ts.map +1 -0
  275. package/dist/store/clients/thread-message-client.js +112 -0
  276. package/dist/store/clients/thread-message-client.js.map +1 -0
  277. package/dist/store/index.d.ts +14 -0
  278. package/dist/store/index.d.ts.map +1 -0
  279. package/dist/store/index.js +14 -0
  280. package/dist/store/index.js.map +1 -0
  281. package/dist/store/internal.d.ts +11 -0
  282. package/dist/store/internal.d.ts.map +1 -0
  283. package/dist/store/internal.js +12 -0
  284. package/dist/store/internal.js.map +1 -0
  285. package/dist/store/runtime-clients/attachment-runtime-client.d.ts +8 -0
  286. package/dist/store/runtime-clients/attachment-runtime-client.d.ts.map +1 -0
  287. package/dist/store/runtime-clients/attachment-runtime-client.js +11 -0
  288. package/dist/store/runtime-clients/attachment-runtime-client.js.map +1 -0
  289. package/dist/store/runtime-clients/composer-runtime-client.d.ts +13 -0
  290. package/dist/store/runtime-clients/composer-runtime-client.d.ts.map +1 -0
  291. package/dist/store/runtime-clients/composer-runtime-client.js +83 -0
  292. package/dist/store/runtime-clients/composer-runtime-client.js.map +1 -0
  293. package/dist/store/runtime-clients/index.d.ts +8 -0
  294. package/dist/store/runtime-clients/index.d.ts.map +1 -0
  295. package/dist/store/runtime-clients/index.js +8 -0
  296. package/dist/store/runtime-clients/index.js.map +1 -0
  297. package/dist/store/runtime-clients/message-part-runtime-client.d.ts +8 -0
  298. package/dist/store/runtime-clients/message-part-runtime-client.d.ts.map +1 -0
  299. package/dist/store/runtime-clients/message-part-runtime-client.js +12 -0
  300. package/dist/store/runtime-clients/message-part-runtime-client.js.map +1 -0
  301. package/dist/store/runtime-clients/message-runtime-client.d.ts +11 -0
  302. package/dist/store/runtime-clients/message-runtime-client.d.ts.map +1 -0
  303. package/dist/store/runtime-clients/message-runtime-client.js +78 -0
  304. package/dist/store/runtime-clients/message-runtime-client.js.map +1 -0
  305. package/dist/store/runtime-clients/tap-subscribable.d.ts +3 -0
  306. package/dist/store/runtime-clients/tap-subscribable.d.ts.map +1 -0
  307. package/dist/store/runtime-clients/tap-subscribable.js +12 -0
  308. package/dist/store/runtime-clients/tap-subscribable.js.map +1 -0
  309. package/dist/store/runtime-clients/thread-list-item-runtime-client.d.ts +8 -0
  310. package/dist/store/runtime-clients/thread-list-item-runtime-client.d.ts.map +1 -0
  311. package/dist/store/runtime-clients/thread-list-item-runtime-client.js +41 -0
  312. package/dist/store/runtime-clients/thread-list-item-runtime-client.js.map +1 -0
  313. package/dist/store/runtime-clients/thread-list-runtime-client.d.ts +10 -0
  314. package/dist/store/runtime-clients/thread-list-runtime-client.d.ts.map +1 -0
  315. package/dist/store/runtime-clients/thread-list-runtime-client.js +54 -0
  316. package/dist/store/runtime-clients/thread-list-runtime-client.js.map +1 -0
  317. package/dist/store/runtime-clients/thread-runtime-client.d.ts +8 -0
  318. package/dist/store/runtime-clients/thread-runtime-client.d.ts.map +1 -0
  319. package/dist/store/runtime-clients/thread-runtime-client.js +91 -0
  320. package/dist/store/runtime-clients/thread-runtime-client.js.map +1 -0
  321. package/dist/store/scopes/attachment.d.ts +23 -0
  322. package/dist/store/scopes/attachment.d.ts.map +1 -0
  323. package/dist/store/scopes/attachment.js +2 -0
  324. package/dist/store/scopes/attachment.js.map +1 -0
  325. package/dist/store/scopes/chain-of-thought.d.ts +39 -0
  326. package/dist/store/scopes/chain-of-thought.d.ts.map +1 -0
  327. package/dist/store/scopes/chain-of-thought.js +2 -0
  328. package/dist/store/scopes/chain-of-thought.js.map +1 -0
  329. package/dist/store/scopes/composer.d.ts +75 -0
  330. package/dist/store/scopes/composer.d.ts.map +1 -0
  331. package/dist/store/scopes/composer.js +2 -0
  332. package/dist/store/scopes/composer.js.map +1 -0
  333. package/dist/store/scopes/index.d.ts +12 -0
  334. package/dist/store/scopes/index.d.ts.map +1 -0
  335. package/dist/store/scopes/index.js +2 -0
  336. package/dist/store/scopes/index.js.map +1 -0
  337. package/dist/store/scopes/message.d.ts +86 -0
  338. package/dist/store/scopes/message.d.ts.map +1 -0
  339. package/dist/store/scopes/message.js +2 -0
  340. package/dist/store/scopes/message.js.map +1 -0
  341. package/dist/store/scopes/model-context.d.ts +11 -0
  342. package/dist/store/scopes/model-context.d.ts.map +1 -0
  343. package/dist/store/scopes/model-context.js +2 -0
  344. package/dist/store/scopes/model-context.js.map +1 -0
  345. package/dist/store/scopes/part.d.ts +44 -0
  346. package/dist/store/scopes/part.d.ts.map +1 -0
  347. package/dist/store/scopes/part.js +2 -0
  348. package/dist/store/scopes/part.js.map +1 -0
  349. package/dist/store/scopes/suggestion.d.ts +19 -0
  350. package/dist/store/scopes/suggestion.d.ts.map +1 -0
  351. package/dist/store/scopes/suggestion.js +2 -0
  352. package/dist/store/scopes/suggestion.js.map +1 -0
  353. package/dist/store/scopes/suggestions.d.ts +19 -0
  354. package/dist/store/scopes/suggestions.d.ts.map +1 -0
  355. package/dist/store/scopes/suggestions.js +2 -0
  356. package/dist/store/scopes/suggestions.js.map +1 -0
  357. package/dist/store/scopes/thread-list-item.d.ts +50 -0
  358. package/dist/store/scopes/thread-list-item.d.ts.map +1 -0
  359. package/dist/store/scopes/thread-list-item.js +2 -0
  360. package/dist/store/scopes/thread-list-item.js.map +1 -0
  361. package/dist/store/scopes/thread.d.ts +135 -0
  362. package/dist/store/scopes/thread.d.ts.map +1 -0
  363. package/dist/store/scopes/thread.js +2 -0
  364. package/dist/store/scopes/thread.js.map +1 -0
  365. package/dist/store/scopes/threads.d.ts +29 -0
  366. package/dist/store/scopes/threads.d.ts.map +1 -0
  367. package/dist/store/scopes/threads.js +2 -0
  368. package/dist/store/scopes/threads.js.map +1 -0
  369. package/dist/store/types/client.d.ts +137 -0
  370. package/dist/store/types/client.d.ts.map +1 -0
  371. package/dist/store/types/client.js +2 -0
  372. package/dist/store/types/client.js.map +1 -0
  373. package/dist/store/types/events.d.ts +33 -0
  374. package/dist/store/types/events.d.ts.map +1 -0
  375. package/dist/store/types/events.js +8 -0
  376. package/dist/store/types/events.js.map +1 -0
  377. package/dist/store/types/index.d.ts +3 -0
  378. package/dist/store/types/index.d.ts.map +1 -0
  379. package/dist/store/types/index.js +2 -0
  380. package/dist/store/types/index.js.map +1 -0
  381. package/dist/store/utils/attach-transform-scopes.d.ts +11 -0
  382. package/dist/store/utils/attach-transform-scopes.d.ts.map +1 -0
  383. package/dist/store/utils/attach-transform-scopes.js +12 -0
  384. package/dist/store/utils/attach-transform-scopes.js.map +1 -0
  385. package/dist/store/utils/base-proxy-handler.d.ts +23 -0
  386. package/dist/store/utils/base-proxy-handler.d.ts.map +1 -0
  387. package/dist/store/utils/base-proxy-handler.js +46 -0
  388. package/dist/store/utils/base-proxy-handler.js.map +1 -0
  389. package/dist/store/utils/derived.d.ts +34 -0
  390. package/dist/store/utils/derived.d.ts.map +1 -0
  391. package/dist/store/utils/derived.js +24 -0
  392. package/dist/store/utils/derived.js.map +1 -0
  393. package/dist/store/utils/index.d.ts +7 -0
  394. package/dist/store/utils/index.d.ts.map +1 -0
  395. package/dist/store/utils/index.js +7 -0
  396. package/dist/store/utils/index.js.map +1 -0
  397. package/dist/store/utils/notification-manager.d.ts +11 -0
  398. package/dist/store/utils/notification-manager.d.ts.map +1 -0
  399. package/dist/store/utils/notification-manager.js +84 -0
  400. package/dist/store/utils/notification-manager.js.map +1 -0
  401. package/dist/store/utils/proxied-assistant-state.d.ts +8 -0
  402. package/dist/store/utils/proxied-assistant-state.d.ts.map +1 -0
  403. package/dist/store/utils/proxied-assistant-state.js +33 -0
  404. package/dist/store/utils/proxied-assistant-state.js.map +1 -0
  405. package/dist/store/utils/split-clients.d.ts +10 -0
  406. package/dist/store/utils/split-clients.d.ts.map +1 -0
  407. package/dist/store/utils/split-clients.js +53 -0
  408. package/dist/store/utils/split-clients.js.map +1 -0
  409. package/dist/store/utils/tap-assistant-context.d.ts +19 -0
  410. package/dist/store/utils/tap-assistant-context.d.ts.map +1 -0
  411. package/dist/store/utils/tap-assistant-context.js +23 -0
  412. package/dist/store/utils/tap-assistant-context.js.map +1 -0
  413. package/dist/store/utils/tap-client-list.d.ts +28 -0
  414. package/dist/store/utils/tap-client-list.d.ts.map +1 -0
  415. package/dist/store/utils/tap-client-list.js +68 -0
  416. package/dist/store/utils/tap-client-list.js.map +1 -0
  417. package/dist/store/utils/tap-client-lookup.d.ts +15 -0
  418. package/dist/store/utils/tap-client-lookup.d.ts.map +1 -0
  419. package/dist/store/utils/tap-client-lookup.js +42 -0
  420. package/dist/store/utils/tap-client-lookup.js.map +1 -0
  421. package/dist/store/utils/tap-client-resource.d.ts +13 -0
  422. package/dist/store/utils/tap-client-resource.d.ts.map +1 -0
  423. package/dist/store/utils/tap-client-resource.js +114 -0
  424. package/dist/store/utils/tap-client-resource.js.map +1 -0
  425. package/dist/store/utils/tap-client-stack-context.d.ts +23 -0
  426. package/dist/store/utils/tap-client-stack-context.d.ts.map +1 -0
  427. package/dist/store/utils/tap-client-stack-context.js +28 -0
  428. package/dist/store/utils/tap-client-stack-context.js.map +1 -0
  429. package/dist/store/utils/wrapper-resource.d.ts +3 -0
  430. package/dist/store/utils/wrapper-resource.d.ts.map +1 -0
  431. package/dist/store/utils/wrapper-resource.js +11 -0
  432. package/dist/store/utils/wrapper-resource.js.map +1 -0
  433. package/dist/subscribable/index.d.ts +3 -0
  434. package/dist/subscribable/index.d.ts.map +1 -0
  435. package/dist/subscribable/index.js +8 -0
  436. package/dist/subscribable/index.js.map +1 -0
  437. package/dist/subscribable/subscribable.d.ts +68 -0
  438. package/dist/subscribable/subscribable.d.ts.map +1 -0
  439. package/dist/subscribable/subscribable.js +237 -0
  440. package/dist/subscribable/subscribable.js.map +1 -0
  441. package/dist/types/attachment.d.ts +35 -0
  442. package/dist/types/attachment.d.ts.map +1 -0
  443. package/dist/types/attachment.js +2 -0
  444. package/dist/types/attachment.js.map +1 -0
  445. package/dist/types/index.d.ts +5 -0
  446. package/dist/types/index.d.ts.map +1 -0
  447. package/dist/types/index.js +2 -0
  448. package/dist/types/index.js.map +1 -0
  449. package/dist/types/message.d.ts +179 -0
  450. package/dist/types/message.d.ts.map +1 -0
  451. package/dist/types/message.js +2 -0
  452. package/dist/types/message.js.map +1 -0
  453. package/dist/types/quote.d.ts +5 -0
  454. package/dist/types/quote.d.ts.map +1 -0
  455. package/dist/types/quote.js +2 -0
  456. package/dist/types/quote.js.map +1 -0
  457. package/dist/types/unsubscribe.d.ts +2 -0
  458. package/dist/types/unsubscribe.d.ts.map +1 -0
  459. package/dist/types/unsubscribe.js +2 -0
  460. package/dist/types/unsubscribe.js.map +1 -0
  461. package/dist/utils/composite-context-provider.d.ts +10 -0
  462. package/dist/utils/composite-context-provider.d.ts.map +1 -0
  463. package/dist/utils/composite-context-provider.js +29 -0
  464. package/dist/utils/composite-context-provider.js.map +1 -0
  465. package/dist/utils/id.d.ts +6 -0
  466. package/dist/utils/id.d.ts.map +1 -0
  467. package/dist/utils/id.js +9 -0
  468. package/dist/utils/id.js.map +1 -0
  469. package/dist/utils/index.d.ts +4 -0
  470. package/dist/utils/index.d.ts.map +1 -0
  471. package/dist/utils/index.js +7 -0
  472. package/dist/utils/index.js.map +1 -0
  473. package/dist/utils/text.d.ts +3 -0
  474. package/dist/utils/text.d.ts.map +1 -0
  475. package/dist/utils/text.js +5 -0
  476. package/dist/utils/text.js.map +1 -0
  477. package/package.json +85 -0
  478. package/src/adapters/attachment.ts +209 -0
  479. package/src/adapters/feedback.ts +10 -0
  480. package/src/adapters/index.ts +30 -0
  481. package/src/adapters/speech.ts +338 -0
  482. package/src/adapters/suggestion.ts +14 -0
  483. package/src/adapters/thread-history.ts +72 -0
  484. package/src/index.ts +7 -0
  485. package/src/internal.ts +7 -0
  486. package/src/model-context/frame/host.ts +195 -0
  487. package/src/model-context/frame/index.ts +10 -0
  488. package/src/model-context/frame/provider.ts +193 -0
  489. package/src/model-context/frame/types.ts +40 -0
  490. package/src/model-context/index.ts +35 -0
  491. package/src/model-context/registry-handles.ts +18 -0
  492. package/src/model-context/registry.ts +159 -0
  493. package/src/model-context/tool.ts +9 -0
  494. package/src/model-context/types.ts +104 -0
  495. package/src/runtime/api/assistant-runtime.ts +115 -0
  496. package/src/runtime/api/attachment-runtime.ts +119 -0
  497. package/src/runtime/api/bindings.ts +49 -0
  498. package/src/runtime/api/composer-runtime.ts +505 -0
  499. package/src/runtime/api/message-part-runtime.ts +108 -0
  500. package/src/runtime/api/message-runtime.ts +335 -0
  501. package/src/runtime/api/paths.ts +61 -0
  502. package/src/runtime/api/thread-list-item-runtime.ts +145 -0
  503. package/src/runtime/api/thread-list-runtime.ts +227 -0
  504. package/src/runtime/api/thread-runtime.ts +568 -0
  505. package/src/runtime/base/base-assistant-runtime-core.ts +20 -0
  506. package/src/runtime/base/base-composer-runtime-core.ts +418 -0
  507. package/src/runtime/base/base-thread-runtime-core.ts +234 -0
  508. package/src/runtime/base/default-edit-composer-runtime-core.ts +71 -0
  509. package/src/runtime/base/default-thread-composer-runtime-core.ts +65 -0
  510. package/src/runtime/index.ts +108 -0
  511. package/src/runtime/interfaces/assistant-runtime-core.ts +12 -0
  512. package/src/runtime/interfaces/composer-runtime-core.ts +64 -0
  513. package/src/runtime/interfaces/thread-list-runtime-core.ts +49 -0
  514. package/src/runtime/interfaces/thread-runtime-core.ts +142 -0
  515. package/src/runtime/internal.ts +64 -0
  516. package/src/runtime/utils/auto-status.ts +67 -0
  517. package/src/runtime/utils/chat-model-adapter.ts +66 -0
  518. package/src/runtime/utils/external-store-message.ts +37 -0
  519. package/src/runtime/utils/message-repository.ts +390 -0
  520. package/src/runtime/utils/thread-message-like.ts +225 -0
  521. package/src/runtimes/assistant-transport/utils.ts +37 -0
  522. package/src/runtimes/external-store/external-store-adapter.ts +111 -0
  523. package/src/runtimes/external-store/external-store-runtime-core.ts +26 -0
  524. package/src/runtimes/external-store/external-store-thread-list-runtime-core.ts +235 -0
  525. package/src/runtimes/external-store/external-store-thread-runtime-core.ts +368 -0
  526. package/src/runtimes/external-store/index.ts +15 -0
  527. package/src/runtimes/external-store/thread-message-converter.ts +23 -0
  528. package/src/runtimes/index.ts +28 -0
  529. package/src/runtimes/internal.ts +36 -0
  530. package/src/runtimes/local/index.ts +6 -0
  531. package/src/runtimes/local/local-runtime-core.ts +32 -0
  532. package/src/runtimes/local/local-runtime-options.ts +27 -0
  533. package/src/runtimes/local/local-thread-list-runtime-core.ts +116 -0
  534. package/src/runtimes/local/local-thread-runtime-core.ts +534 -0
  535. package/src/runtimes/local/should-continue.ts +26 -0
  536. package/src/runtimes/remote-thread-list/adapter/in-memory.ts +43 -0
  537. package/src/runtimes/remote-thread-list/empty-thread-core.ts +200 -0
  538. package/src/runtimes/remote-thread-list/optimistic-state.ts +89 -0
  539. package/src/runtimes/remote-thread-list/remote-thread-state.ts +123 -0
  540. package/src/runtimes/remote-thread-list/types.ts +48 -0
  541. package/src/store/clients/chain-of-thought-client.ts +40 -0
  542. package/src/store/clients/index.ts +8 -0
  543. package/src/store/clients/model-context-client.ts +20 -0
  544. package/src/store/clients/no-op-composer-client.ts +66 -0
  545. package/src/store/clients/suggestions.ts +69 -0
  546. package/src/store/clients/thread-message-client.ts +170 -0
  547. package/src/store/index.ts +44 -0
  548. package/src/store/internal.ts +32 -0
  549. package/src/store/runtime-clients/attachment-runtime-client.ts +16 -0
  550. package/src/store/runtime-clients/composer-runtime-client.ts +131 -0
  551. package/src/store/runtime-clients/index.ts +7 -0
  552. package/src/store/runtime-clients/message-part-runtime-client.ts +17 -0
  553. package/src/store/runtime-clients/message-runtime-client.ts +141 -0
  554. package/src/store/runtime-clients/tap-subscribable.ts +16 -0
  555. package/src/store/runtime-clients/thread-list-item-runtime-client.ts +53 -0
  556. package/src/store/runtime-clients/thread-list-runtime-client.ts +86 -0
  557. package/src/store/runtime-clients/thread-runtime-client.ts +141 -0
  558. package/src/store/scopes/attachment.ts +20 -0
  559. package/src/store/scopes/chain-of-thought.ts +38 -0
  560. package/src/store/scopes/composer.ts +80 -0
  561. package/src/store/scopes/index.ts +68 -0
  562. package/src/store/scopes/message.ts +75 -0
  563. package/src/store/scopes/model-context.ts +13 -0
  564. package/src/store/scopes/part.ts +47 -0
  565. package/src/store/scopes/suggestion.ts +19 -0
  566. package/src/store/scopes/suggestions.ts +20 -0
  567. package/src/store/scopes/thread-list-item.ts +44 -0
  568. package/src/store/scopes/thread.ts +135 -0
  569. package/src/store/scopes/threads.ts +34 -0
  570. package/src/store/types/client.ts +203 -0
  571. package/src/store/types/events.ts +77 -0
  572. package/src/store/types/index.ts +23 -0
  573. package/src/store/utils/attach-transform-scopes.ts +38 -0
  574. package/src/store/utils/base-proxy-handler.ts +50 -0
  575. package/src/store/utils/derived.ts +46 -0
  576. package/src/store/utils/index.ts +28 -0
  577. package/src/store/utils/notification-manager.ts +114 -0
  578. package/src/store/utils/proxied-assistant-state.ts +55 -0
  579. package/src/store/utils/split-clients.ts +82 -0
  580. package/src/store/utils/tap-assistant-context.ts +58 -0
  581. package/src/store/utils/tap-client-list.ts +121 -0
  582. package/src/store/utils/tap-client-lookup.ts +79 -0
  583. package/src/store/utils/tap-client-resource.ts +187 -0
  584. package/src/store/utils/tap-client-stack-context.ts +51 -0
  585. package/src/store/utils/wrapper-resource.ts +17 -0
  586. package/src/subscribable/index.ts +21 -0
  587. package/src/subscribable/subscribable.ts +317 -0
  588. package/src/tests/BaseSubscribable.test.ts +54 -0
  589. package/src/tests/MessageRepository.test.ts +607 -0
  590. package/src/tests/OptimisticState-delete-crash.test.ts +206 -0
  591. package/src/types/attachment.ts +45 -0
  592. package/src/types/index.ts +39 -0
  593. package/src/types/message.ts +248 -0
  594. package/src/types/quote.ts +4 -0
  595. package/src/types/unsubscribe.ts +1 -0
  596. package/src/utils/composite-context-provider.ts +36 -0
  597. package/src/utils/id.ts +14 -0
  598. package/src/utils/index.ts +14 -0
  599. package/src/utils/text.ts +11 -0
@@ -0,0 +1,418 @@
1
+ import type {
2
+ Attachment,
3
+ CompleteAttachment,
4
+ PendingAttachment,
5
+ MessageRole,
6
+ RunConfig,
7
+ QuoteInfo,
8
+ AppendMessage,
9
+ Unsubscribe,
10
+ } from "../../types";
11
+ import { BaseSubscribable } from "../../subscribable";
12
+ import type { AttachmentAdapter } from "../../adapters/attachment";
13
+ import type {
14
+ ComposerRuntimeCore,
15
+ ComposerRuntimeEventType,
16
+ DictationState,
17
+ } from "../interfaces/composer-runtime-core";
18
+ import type { DictationAdapter } from "../../adapters/speech";
19
+
20
+ const isAttachmentComplete = (a: Attachment): a is CompleteAttachment =>
21
+ a.status.type === "complete";
22
+
23
+ export abstract class BaseComposerRuntimeCore
24
+ extends BaseSubscribable
25
+ implements ComposerRuntimeCore
26
+ {
27
+ public readonly isEditing = true;
28
+
29
+ protected abstract getAttachmentAdapter(): AttachmentAdapter | undefined;
30
+ protected abstract getDictationAdapter(): DictationAdapter | undefined;
31
+
32
+ public get attachmentAccept(): string {
33
+ return this.getAttachmentAdapter()?.accept ?? "*";
34
+ }
35
+
36
+ private _attachments: readonly Attachment[] = [];
37
+ public get attachments() {
38
+ return this._attachments;
39
+ }
40
+
41
+ protected setAttachments(value: readonly Attachment[]) {
42
+ this._attachments = value;
43
+ this._notifySubscribers();
44
+ }
45
+
46
+ public abstract get canCancel(): boolean;
47
+
48
+ public get isEmpty() {
49
+ return !this.text.trim() && !this.attachments.length;
50
+ }
51
+
52
+ private _text = "";
53
+
54
+ get text() {
55
+ return this._text;
56
+ }
57
+
58
+ private _role: MessageRole = "user";
59
+
60
+ get role() {
61
+ return this._role;
62
+ }
63
+
64
+ private _runConfig: RunConfig = {};
65
+
66
+ get runConfig() {
67
+ return this._runConfig;
68
+ }
69
+
70
+ private _quote: QuoteInfo | undefined = undefined;
71
+
72
+ get quote() {
73
+ return this._quote;
74
+ }
75
+
76
+ public setQuote(quote: QuoteInfo | undefined) {
77
+ if (this._quote === quote) return;
78
+
79
+ this._quote = quote;
80
+ this._notifySubscribers();
81
+ }
82
+
83
+ public setText(value: string) {
84
+ if (this._text === value) return;
85
+
86
+ this._text = value;
87
+ if (this._dictation) {
88
+ this._dictationBaseText = value;
89
+ this._currentInterimText = "";
90
+ const { status, inputDisabled } = this._dictation;
91
+ this._dictation = inputDisabled ? { status, inputDisabled } : { status };
92
+ }
93
+ this._notifySubscribers();
94
+ }
95
+
96
+ public setRole(role: MessageRole) {
97
+ if (this._role === role) return;
98
+
99
+ this._role = role;
100
+ this._notifySubscribers();
101
+ }
102
+
103
+ public setRunConfig(runConfig: RunConfig) {
104
+ if (this._runConfig === runConfig) return;
105
+
106
+ this._runConfig = runConfig;
107
+ this._notifySubscribers();
108
+ }
109
+
110
+ private _emptyTextAndAttachments() {
111
+ this._attachments = [];
112
+ this._text = "";
113
+ this._notifySubscribers();
114
+ }
115
+
116
+ private async _onClearAttachments() {
117
+ const adapter = this.getAttachmentAdapter();
118
+ if (adapter) {
119
+ await Promise.all(this._attachments.map((a) => adapter.remove(a)));
120
+ }
121
+ }
122
+
123
+ public async reset() {
124
+ if (
125
+ this._attachments.length === 0 &&
126
+ this._text === "" &&
127
+ this._role === "user" &&
128
+ Object.keys(this._runConfig).length === 0 &&
129
+ this._quote === undefined
130
+ ) {
131
+ return;
132
+ }
133
+
134
+ this._role = "user";
135
+ this._runConfig = {};
136
+ this._quote = undefined;
137
+
138
+ const task = this._onClearAttachments();
139
+ this._emptyTextAndAttachments();
140
+ await task;
141
+ }
142
+
143
+ public async clearAttachments() {
144
+ const task = this._onClearAttachments();
145
+ this.setAttachments([]);
146
+
147
+ await task;
148
+ }
149
+
150
+ public async send() {
151
+ if (this._dictationSession) {
152
+ this._dictationSession.cancel();
153
+ this._cleanupDictation();
154
+ }
155
+
156
+ const adapter = this.getAttachmentAdapter();
157
+ const attachments =
158
+ adapter && this.attachments.length > 0
159
+ ? Promise.all(
160
+ this.attachments.map(async (a) => {
161
+ if (isAttachmentComplete(a)) return a;
162
+ const result = await adapter.send(a);
163
+ return result as CompleteAttachment;
164
+ }),
165
+ )
166
+ : [];
167
+
168
+ const text = this.text;
169
+ const quote = this._quote;
170
+ this._quote = undefined;
171
+ this._emptyTextAndAttachments();
172
+
173
+ const message: Omit<AppendMessage, "parentId" | "sourceId"> = {
174
+ createdAt: new Date(),
175
+ role: this.role,
176
+ content: text ? [{ type: "text", text }] : [],
177
+ attachments: await attachments,
178
+ runConfig: this.runConfig,
179
+ metadata: { custom: { ...(quote ? { quote } : {}) } },
180
+ };
181
+
182
+ this.handleSend(message);
183
+ this._notifyEventSubscribers("send");
184
+ }
185
+
186
+ public cancel() {
187
+ this.handleCancel();
188
+ }
189
+
190
+ protected abstract handleSend(
191
+ message: Omit<AppendMessage, "parentId" | "sourceId">,
192
+ ): void;
193
+ protected abstract handleCancel(): void;
194
+
195
+ async addAttachment(file: File) {
196
+ const adapter = this.getAttachmentAdapter();
197
+ if (!adapter) throw new Error("Attachments are not supported");
198
+
199
+ const upsertAttachment = (a: PendingAttachment) => {
200
+ const idx = this._attachments.findIndex(
201
+ (attachment) => attachment.id === a.id,
202
+ );
203
+ if (idx !== -1)
204
+ this._attachments = [
205
+ ...this._attachments.slice(0, idx),
206
+ a,
207
+ ...this._attachments.slice(idx + 1),
208
+ ];
209
+ else {
210
+ this._attachments = [...this._attachments, a];
211
+ }
212
+
213
+ this._notifySubscribers();
214
+ };
215
+
216
+ const promiseOrGenerator = adapter.add({ file });
217
+ if (Symbol.asyncIterator in promiseOrGenerator) {
218
+ for await (const r of promiseOrGenerator) {
219
+ upsertAttachment(r);
220
+ }
221
+ } else {
222
+ upsertAttachment(await promiseOrGenerator);
223
+ }
224
+
225
+ this._notifyEventSubscribers("attachmentAdd");
226
+ this._notifySubscribers();
227
+ }
228
+
229
+ async removeAttachment(attachmentId: string) {
230
+ const adapter = this.getAttachmentAdapter();
231
+ if (!adapter) throw new Error("Attachments are not supported");
232
+
233
+ const index = this._attachments.findIndex((a) => a.id === attachmentId);
234
+ if (index === -1) throw new Error("Attachment not found");
235
+ const attachment = this._attachments[index]!;
236
+
237
+ await adapter.remove(attachment);
238
+
239
+ this._attachments = this._attachments.filter((a) => a.id !== attachmentId);
240
+ this._notifySubscribers();
241
+ }
242
+
243
+ private _dictation: DictationState | undefined;
244
+ private _dictationSession: DictationAdapter.Session | undefined;
245
+ private _dictationUnsubscribes: Unsubscribe[] = [];
246
+ private _dictationBaseText = "";
247
+ private _currentInterimText = "";
248
+ private _dictationSessionIdCounter = 0;
249
+ private _activeDictationSessionId: number | undefined;
250
+ private _isCleaningDictation = false;
251
+
252
+ public get dictation(): DictationState | undefined {
253
+ return this._dictation;
254
+ }
255
+
256
+ private _isActiveSession(
257
+ sessionId: number,
258
+ session: DictationAdapter.Session,
259
+ ): boolean {
260
+ return (
261
+ this._activeDictationSessionId === sessionId &&
262
+ this._dictationSession === session
263
+ );
264
+ }
265
+
266
+ public startDictation(): void {
267
+ const adapter = this.getDictationAdapter();
268
+ if (!adapter) {
269
+ throw new Error("Dictation adapter not configured");
270
+ }
271
+
272
+ if (this._dictationSession) {
273
+ for (const unsub of this._dictationUnsubscribes) {
274
+ unsub();
275
+ }
276
+ this._dictationUnsubscribes = [];
277
+ const oldSession = this._dictationSession;
278
+ oldSession.stop().catch(() => {});
279
+ this._dictationSession = undefined;
280
+ }
281
+
282
+ const inputDisabled = adapter.disableInputDuringDictation ?? false;
283
+
284
+ this._dictationBaseText = this._text;
285
+ this._currentInterimText = "";
286
+
287
+ const session = adapter.listen();
288
+ this._dictationSession = session;
289
+ const sessionId = ++this._dictationSessionIdCounter;
290
+ this._activeDictationSessionId = sessionId;
291
+ this._dictation = { status: session.status, inputDisabled };
292
+ this._notifySubscribers();
293
+
294
+ const unsubSpeech = session.onSpeech((result) => {
295
+ if (!this._isActiveSession(sessionId, session)) return;
296
+ const isFinal = result.isFinal !== false;
297
+
298
+ const needsSeparator =
299
+ this._dictationBaseText &&
300
+ !this._dictationBaseText.endsWith(" ") &&
301
+ result.transcript;
302
+ const separator = needsSeparator ? " " : "";
303
+
304
+ if (isFinal) {
305
+ this._dictationBaseText =
306
+ this._dictationBaseText + separator + result.transcript;
307
+ this._currentInterimText = "";
308
+ this._text = this._dictationBaseText;
309
+
310
+ if (this._dictation) {
311
+ const { transcript: _, ...rest } = this._dictation;
312
+ this._dictation = rest;
313
+ }
314
+ this._notifySubscribers();
315
+ } else {
316
+ this._currentInterimText = separator + result.transcript;
317
+ this._text = this._dictationBaseText + this._currentInterimText;
318
+
319
+ if (this._dictation) {
320
+ this._dictation = {
321
+ ...this._dictation,
322
+ transcript: result.transcript,
323
+ };
324
+ }
325
+ this._notifySubscribers();
326
+ }
327
+ });
328
+ this._dictationUnsubscribes.push(unsubSpeech);
329
+
330
+ const unsubStart = session.onSpeechStart(() => {
331
+ if (!this._isActiveSession(sessionId, session)) return;
332
+
333
+ this._dictation = {
334
+ status: { type: "running" },
335
+ inputDisabled,
336
+ ...(this._dictation?.transcript && {
337
+ transcript: this._dictation.transcript,
338
+ }),
339
+ };
340
+ this._notifySubscribers();
341
+ });
342
+ this._dictationUnsubscribes.push(unsubStart);
343
+
344
+ const unsubEnd = session.onSpeechEnd(() => {
345
+ this._cleanupDictation({ sessionId });
346
+ });
347
+ this._dictationUnsubscribes.push(unsubEnd);
348
+
349
+ const statusInterval = setInterval(() => {
350
+ if (!this._isActiveSession(sessionId, session)) return;
351
+
352
+ if (session.status.type === "ended") {
353
+ this._cleanupDictation({ sessionId });
354
+ }
355
+ }, 100);
356
+ this._dictationUnsubscribes.push(() => clearInterval(statusInterval));
357
+ }
358
+
359
+ public stopDictation(): void {
360
+ if (!this._dictationSession) return;
361
+
362
+ const session = this._dictationSession;
363
+ const sessionId = this._activeDictationSessionId;
364
+ session.stop().finally(() => {
365
+ this._cleanupDictation({ sessionId });
366
+ });
367
+ }
368
+
369
+ private _cleanupDictation(options?: { sessionId: number | undefined }): void {
370
+ const isStaleSession =
371
+ options?.sessionId !== undefined &&
372
+ options.sessionId !== this._activeDictationSessionId;
373
+ if (isStaleSession || this._isCleaningDictation) return;
374
+
375
+ this._isCleaningDictation = true;
376
+ try {
377
+ for (const unsub of this._dictationUnsubscribes) {
378
+ unsub();
379
+ }
380
+ this._dictationUnsubscribes = [];
381
+ this._dictationSession = undefined;
382
+ this._activeDictationSessionId = undefined;
383
+ this._dictation = undefined;
384
+ this._dictationBaseText = "";
385
+ this._currentInterimText = "";
386
+ this._notifySubscribers();
387
+ } finally {
388
+ this._isCleaningDictation = false;
389
+ }
390
+ }
391
+
392
+ private _eventSubscribers = new Map<
393
+ ComposerRuntimeEventType,
394
+ Set<() => void>
395
+ >();
396
+
397
+ protected _notifyEventSubscribers(event: ComposerRuntimeEventType) {
398
+ const subscribers = this._eventSubscribers.get(event);
399
+ if (!subscribers) return;
400
+
401
+ for (const callback of subscribers) callback();
402
+ }
403
+
404
+ public unstable_on(event: ComposerRuntimeEventType, callback: () => void) {
405
+ const subscribers = this._eventSubscribers.get(event);
406
+ if (!subscribers) {
407
+ this._eventSubscribers.set(event, new Set([callback]));
408
+ } else {
409
+ subscribers.add(callback);
410
+ }
411
+
412
+ return () => {
413
+ const subscribers = this._eventSubscribers.get(event);
414
+ if (!subscribers) return;
415
+ subscribers.delete(callback);
416
+ };
417
+ }
418
+ }
@@ -0,0 +1,234 @@
1
+ import type { AppendMessage, ThreadMessage, Unsubscribe } from "../../types";
2
+ import type { ModelContextProvider } from "../../model-context";
3
+ import { getThreadMessageText } from "../../utils/text";
4
+ import {
5
+ ExportedMessageRepository,
6
+ MessageRepository,
7
+ } from "../utils/message-repository";
8
+ import { DefaultThreadComposerRuntimeCore } from "./default-thread-composer-runtime-core";
9
+ import type {
10
+ AddToolResultOptions,
11
+ ResumeToolCallOptions,
12
+ ThreadSuggestion,
13
+ SubmitFeedbackOptions,
14
+ ThreadRuntimeCore,
15
+ SpeechState,
16
+ RuntimeCapabilities,
17
+ ThreadRuntimeEventType,
18
+ StartRunConfig,
19
+ ResumeRunConfig,
20
+ } from "../interfaces/thread-runtime-core";
21
+ import { DefaultEditComposerRuntimeCore } from "./default-edit-composer-runtime-core";
22
+ import type { SpeechSynthesisAdapter } from "../../adapters/speech";
23
+ import type { FeedbackAdapter } from "../../adapters/feedback";
24
+ import type { AttachmentAdapter } from "../../adapters/attachment";
25
+ import type { ThreadMessageLike } from "../utils/thread-message-like";
26
+
27
+ type BaseThreadAdapters = {
28
+ speech?: SpeechSynthesisAdapter | undefined;
29
+ feedback?: FeedbackAdapter | undefined;
30
+ attachments?: AttachmentAdapter | undefined;
31
+ };
32
+
33
+ export abstract class BaseThreadRuntimeCore implements ThreadRuntimeCore {
34
+ private _subscriptions = new Set<() => void>();
35
+ private _isInitialized = false;
36
+
37
+ protected readonly repository = new MessageRepository();
38
+ public abstract get adapters(): BaseThreadAdapters | undefined;
39
+ public abstract get isDisabled(): boolean;
40
+ public abstract get isLoading(): boolean;
41
+ public abstract get suggestions(): readonly ThreadSuggestion[];
42
+ public abstract get extras(): unknown;
43
+
44
+ public abstract get capabilities(): RuntimeCapabilities;
45
+ public abstract append(message: AppendMessage): void;
46
+ public abstract startRun(config: StartRunConfig): void;
47
+ public abstract resumeRun(config: ResumeRunConfig): void;
48
+ public abstract addToolResult(options: AddToolResultOptions): void;
49
+ public abstract resumeToolCall(options: ResumeToolCallOptions): void;
50
+ public abstract cancelRun(): void;
51
+ public abstract exportExternalState(): any;
52
+ public abstract importExternalState(state: any): void;
53
+ public abstract unstable_loadExternalState(state: any): void;
54
+
55
+ public get messages() {
56
+ return this.repository.getMessages();
57
+ }
58
+
59
+ public get state() {
60
+ let mostRecentAssistantMessage;
61
+ for (const message of this.messages) {
62
+ if (message.role === "assistant") {
63
+ mostRecentAssistantMessage = message;
64
+ }
65
+ }
66
+
67
+ return mostRecentAssistantMessage?.metadata.unstable_state ?? null;
68
+ }
69
+
70
+ public readonly composer = new DefaultThreadComposerRuntimeCore(this);
71
+
72
+ constructor(private readonly _contextProvider: ModelContextProvider) {}
73
+
74
+ public getModelContext() {
75
+ return this._contextProvider.getModelContext();
76
+ }
77
+
78
+ private _editComposers = new Map<string, DefaultEditComposerRuntimeCore>();
79
+ public getEditComposer(messageId: string) {
80
+ return this._editComposers.get(messageId);
81
+ }
82
+ public beginEdit(messageId: string) {
83
+ if (this._editComposers.has(messageId))
84
+ throw new Error("Edit already in progress");
85
+
86
+ this._editComposers.set(
87
+ messageId,
88
+ new DefaultEditComposerRuntimeCore(
89
+ this,
90
+ () => this._editComposers.delete(messageId),
91
+ this.repository.getMessage(messageId),
92
+ ),
93
+ );
94
+ this._notifySubscribers();
95
+ }
96
+
97
+ public getMessageById(messageId: string) {
98
+ try {
99
+ return this.repository.getMessage(messageId);
100
+ } catch {
101
+ return undefined;
102
+ }
103
+ }
104
+
105
+ public getBranches(messageId: string): string[] {
106
+ return this.repository.getBranches(messageId);
107
+ }
108
+
109
+ public switchToBranch(branchId: string): void {
110
+ this.repository.switchToBranch(branchId);
111
+ this._notifySubscribers();
112
+ }
113
+
114
+ protected _notifySubscribers() {
115
+ for (const callback of this._subscriptions) callback();
116
+ }
117
+
118
+ public _notifyEventSubscribers(event: ThreadRuntimeEventType) {
119
+ const subscribers = this._eventSubscribers.get(event);
120
+ if (!subscribers) return;
121
+
122
+ for (const callback of subscribers) callback();
123
+ }
124
+
125
+ public subscribe(callback: () => void): Unsubscribe {
126
+ this._subscriptions.add(callback);
127
+ return () => this._subscriptions.delete(callback);
128
+ }
129
+
130
+ public submitFeedback({ messageId, type }: SubmitFeedbackOptions) {
131
+ const adapter = this.adapters?.feedback;
132
+ if (!adapter) throw new Error("Feedback adapter not configured");
133
+
134
+ const { message, parentId } = this.repository.getMessage(messageId);
135
+ adapter.submit({ message, type });
136
+
137
+ if (message.role === "assistant") {
138
+ const updatedMessage: ThreadMessage = {
139
+ ...message,
140
+ metadata: {
141
+ ...message.metadata,
142
+ submittedFeedback: { type },
143
+ },
144
+ };
145
+ this.repository.addOrUpdateMessage(parentId, updatedMessage);
146
+ }
147
+
148
+ this._notifySubscribers();
149
+ }
150
+
151
+ private _stopSpeaking: Unsubscribe | undefined;
152
+ public speech: SpeechState | undefined;
153
+
154
+ public speak(messageId: string) {
155
+ const adapter = this.adapters?.speech;
156
+ if (!adapter) throw new Error("Speech adapter not configured");
157
+
158
+ const { message } = this.repository.getMessage(messageId);
159
+
160
+ this._stopSpeaking?.();
161
+
162
+ const utterance = adapter.speak(getThreadMessageText(message));
163
+ const unsub = utterance.subscribe(() => {
164
+ if (utterance.status.type === "ended") {
165
+ this._stopSpeaking = undefined;
166
+ this.speech = undefined;
167
+ } else {
168
+ this.speech = { messageId, status: utterance.status };
169
+ }
170
+ this._notifySubscribers();
171
+ });
172
+
173
+ this.speech = { messageId, status: utterance.status };
174
+ this._notifySubscribers();
175
+
176
+ this._stopSpeaking = () => {
177
+ utterance.cancel();
178
+ unsub();
179
+ this.speech = undefined;
180
+ this._stopSpeaking = undefined;
181
+ };
182
+ }
183
+
184
+ public stopSpeaking() {
185
+ if (!this._stopSpeaking) throw new Error("No message is being spoken");
186
+ this._stopSpeaking();
187
+ this._notifySubscribers();
188
+ }
189
+
190
+ protected ensureInitialized() {
191
+ if (!this._isInitialized) {
192
+ this._isInitialized = true;
193
+ this._notifyEventSubscribers("initialize");
194
+ }
195
+ }
196
+
197
+ public export() {
198
+ return this.repository.export();
199
+ }
200
+
201
+ public import(data: ExportedMessageRepository) {
202
+ this.ensureInitialized();
203
+ this.repository.clear();
204
+ this.repository.import(data);
205
+ this._notifySubscribers();
206
+ }
207
+
208
+ public reset(initialMessages?: readonly ThreadMessageLike[]) {
209
+ this.import(ExportedMessageRepository.fromArray(initialMessages ?? []));
210
+ }
211
+
212
+ private _eventSubscribers = new Map<
213
+ ThreadRuntimeEventType,
214
+ Set<() => void>
215
+ >();
216
+
217
+ public unstable_on(event: ThreadRuntimeEventType, callback: () => void) {
218
+ if (event === "modelContextUpdate") {
219
+ return this._contextProvider.subscribe?.(callback) ?? (() => {});
220
+ }
221
+
222
+ const subscribers = this._eventSubscribers.get(event);
223
+ if (!subscribers) {
224
+ this._eventSubscribers.set(event, new Set([callback]));
225
+ } else {
226
+ subscribers.add(callback);
227
+ }
228
+
229
+ return () => {
230
+ const subscribers = this._eventSubscribers.get(event)!;
231
+ subscribers.delete(callback);
232
+ };
233
+ }
234
+ }
@@ -0,0 +1,71 @@
1
+ import type { AppendMessage, ThreadMessage } from "../../types";
2
+ import { getThreadMessageText } from "../../utils/text";
3
+ import type { AttachmentAdapter } from "../../adapters/attachment";
4
+ import type { DictationAdapter } from "../../adapters/speech";
5
+ import type { ThreadRuntimeCore } from "../interfaces/thread-runtime-core";
6
+ import { BaseComposerRuntimeCore } from "./base-composer-runtime-core";
7
+
8
+ export class DefaultEditComposerRuntimeCore extends BaseComposerRuntimeCore {
9
+ public get canCancel() {
10
+ return true;
11
+ }
12
+
13
+ protected getAttachmentAdapter() {
14
+ return this.runtime.adapters?.attachments;
15
+ }
16
+
17
+ protected getDictationAdapter() {
18
+ return this.runtime.adapters?.dictation;
19
+ }
20
+
21
+ private _nonTextParts;
22
+ private _previousText;
23
+ private _parentId;
24
+ private _sourceId;
25
+ constructor(
26
+ private runtime: ThreadRuntimeCore & {
27
+ adapters?:
28
+ | {
29
+ attachments?: AttachmentAdapter | undefined;
30
+ dictation?: DictationAdapter | undefined;
31
+ }
32
+ | undefined;
33
+ },
34
+ private endEditCallback: () => void,
35
+ { parentId, message }: { parentId: string | null; message: ThreadMessage },
36
+ ) {
37
+ super();
38
+ this._parentId = parentId;
39
+ this._sourceId = message.id;
40
+ this._previousText = getThreadMessageText(message);
41
+ this.setText(this._previousText);
42
+
43
+ this.setRole(message.role);
44
+ this.setAttachments(message.attachments ?? []);
45
+
46
+ this._nonTextParts = message.content.filter((part) => part.type !== "text");
47
+
48
+ this.setRunConfig({ ...runtime.composer.runConfig });
49
+ }
50
+
51
+ public async handleSend(
52
+ message: Omit<AppendMessage, "parentId" | "sourceId">,
53
+ ) {
54
+ const text = getThreadMessageText(message as AppendMessage);
55
+ if (text !== this._previousText) {
56
+ this.runtime.append({
57
+ ...message,
58
+ content: [...message.content, ...this._nonTextParts] as any,
59
+ parentId: this._parentId,
60
+ sourceId: this._sourceId,
61
+ });
62
+ }
63
+
64
+ this.handleCancel();
65
+ }
66
+
67
+ public handleCancel() {
68
+ this.endEditCallback();
69
+ this._notifySubscribers();
70
+ }
71
+ }