@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,119 @@
1
+ import type {
2
+ Attachment,
3
+ CompleteAttachment,
4
+ PendingAttachment,
5
+ Unsubscribe,
6
+ } from "../../types";
7
+ import type { SubscribableWithState } from "../../subscribable/subscribable";
8
+
9
+ import type { ComposerRuntimeCoreBinding } from "./bindings";
10
+ import type { AttachmentRuntimePath } from "./paths";
11
+
12
+ type MessageAttachmentState = CompleteAttachment & {
13
+ readonly source: "message";
14
+ };
15
+
16
+ type ThreadComposerAttachmentState = PendingAttachment & {
17
+ readonly source: "thread-composer";
18
+ };
19
+
20
+ type EditComposerAttachmentState = Attachment & {
21
+ readonly source: "edit-composer";
22
+ };
23
+
24
+ export type AttachmentState =
25
+ | ThreadComposerAttachmentState
26
+ | EditComposerAttachmentState
27
+ | MessageAttachmentState;
28
+
29
+ type AttachmentSnapshotBinding<Source extends AttachmentRuntimeSource> =
30
+ SubscribableWithState<
31
+ AttachmentState & { source: Source },
32
+ AttachmentRuntimePath & { attachmentSource: Source }
33
+ >;
34
+
35
+ type AttachmentRuntimeSource = AttachmentState["source"];
36
+
37
+ export type AttachmentRuntime<
38
+ TSource extends AttachmentRuntimeSource = AttachmentRuntimeSource,
39
+ > = {
40
+ readonly path: AttachmentRuntimePath & { attachmentSource: TSource };
41
+ readonly source: TSource;
42
+ getState(): AttachmentState & { source: TSource };
43
+ remove(): Promise<void>;
44
+ subscribe(callback: () => void): Unsubscribe;
45
+ };
46
+
47
+ export abstract class AttachmentRuntimeImpl<
48
+ Source extends AttachmentRuntimeSource = AttachmentRuntimeSource,
49
+ > implements AttachmentRuntime
50
+ {
51
+ public get path() {
52
+ return this._core.path;
53
+ }
54
+
55
+ public abstract get source(): Source;
56
+
57
+ constructor(private _core: AttachmentSnapshotBinding<Source>) {
58
+ this.__internal_bindMethods();
59
+ }
60
+
61
+ protected __internal_bindMethods() {
62
+ this.getState = this.getState.bind(this);
63
+ this.remove = this.remove.bind(this);
64
+ this.subscribe = this.subscribe.bind(this);
65
+ }
66
+
67
+ public getState(): AttachmentState & { source: Source } {
68
+ return this._core.getState();
69
+ }
70
+
71
+ public abstract remove(): Promise<void>;
72
+
73
+ public subscribe(callback: () => void) {
74
+ return this._core.subscribe(callback);
75
+ }
76
+ }
77
+
78
+ abstract class ComposerAttachmentRuntime<
79
+ Source extends "thread-composer" | "edit-composer",
80
+ > extends AttachmentRuntimeImpl<Source> {
81
+ constructor(
82
+ core: AttachmentSnapshotBinding<Source>,
83
+ private _composerApi: ComposerRuntimeCoreBinding,
84
+ ) {
85
+ super(core);
86
+ }
87
+
88
+ public remove() {
89
+ const core = this._composerApi.getState();
90
+ if (!core) throw new Error("Composer is not available");
91
+ return core.removeAttachment(this.getState().id);
92
+ }
93
+ }
94
+
95
+ export class ThreadComposerAttachmentRuntimeImpl extends ComposerAttachmentRuntime<"thread-composer"> {
96
+ public get source(): "thread-composer" {
97
+ return "thread-composer";
98
+ }
99
+ }
100
+
101
+ export class EditComposerAttachmentRuntimeImpl extends ComposerAttachmentRuntime<"edit-composer"> {
102
+ public get source(): "edit-composer" {
103
+ return "edit-composer";
104
+ }
105
+ }
106
+
107
+ export class MessageAttachmentRuntimeImpl extends AttachmentRuntimeImpl<"message"> {
108
+ public get source(): "message" {
109
+ return "message";
110
+ }
111
+
112
+ constructor(core: AttachmentSnapshotBinding<"message">) {
113
+ super(core);
114
+ }
115
+
116
+ public remove(): never {
117
+ throw new Error("Message attachments cannot be removed");
118
+ }
119
+ }
@@ -0,0 +1,49 @@
1
+ import type { ThreadMessage } from "../../types";
2
+ import type { SubscribableWithState } from "../../subscribable/subscribable";
3
+ import type {
4
+ ComposerRuntimeCore,
5
+ ThreadComposerRuntimeCore,
6
+ } from "../interfaces/composer-runtime-core";
7
+ import type {
8
+ SpeechState,
9
+ SubmittedFeedback,
10
+ } from "../interfaces/thread-runtime-core";
11
+ import type { ComposerRuntimePath, MessageRuntimePath } from "./paths";
12
+
13
+ export type ComposerRuntimeCoreBinding = SubscribableWithState<
14
+ ComposerRuntimeCore | undefined,
15
+ ComposerRuntimePath
16
+ >;
17
+
18
+ export type ThreadComposerRuntimeCoreBinding = SubscribableWithState<
19
+ ThreadComposerRuntimeCore | undefined,
20
+ ComposerRuntimePath & { composerSource: "thread" }
21
+ >;
22
+
23
+ export type EditComposerRuntimeCoreBinding = SubscribableWithState<
24
+ ComposerRuntimeCore | undefined,
25
+ ComposerRuntimePath & { composerSource: "edit" }
26
+ >;
27
+
28
+ export type MessageStateBinding = SubscribableWithState<
29
+ ThreadMessage & {
30
+ readonly parentId: string | null;
31
+ readonly index: number;
32
+ readonly isLast: boolean;
33
+ readonly branchNumber: number;
34
+ readonly branchCount: number;
35
+ readonly speech: SpeechState | undefined;
36
+ /** @deprecated Use `message.metadata.submittedFeedback` instead. This will be removed in 0.12.0. */
37
+ readonly submittedFeedback: SubmittedFeedback | undefined;
38
+ },
39
+ MessageRuntimePath
40
+ >;
41
+
42
+ export type ThreadListItemState = {
43
+ readonly isMain: boolean;
44
+ readonly id: string;
45
+ readonly remoteId: string | undefined;
46
+ readonly externalId: string | undefined;
47
+ readonly status: import("../interfaces/thread-list-runtime-core").ThreadListItemStatus;
48
+ readonly title?: string | undefined;
49
+ };
@@ -0,0 +1,505 @@
1
+ import type {
2
+ Attachment,
3
+ PendingAttachment,
4
+ MessageRole,
5
+ RunConfig,
6
+ QuoteInfo,
7
+ Unsubscribe,
8
+ } from "../../types";
9
+ import {
10
+ LazyMemoizeSubject,
11
+ ShallowMemoizeSubject,
12
+ SKIP_UPDATE,
13
+ EventSubscriptionSubject,
14
+ } from "../../subscribable";
15
+ import type {
16
+ ComposerRuntimeCore,
17
+ ComposerRuntimeEventType,
18
+ DictationState,
19
+ ThreadComposerRuntimeCore,
20
+ } from "../interfaces/composer-runtime-core";
21
+ import type {
22
+ ThreadComposerRuntimeCoreBinding,
23
+ EditComposerRuntimeCoreBinding,
24
+ ComposerRuntimeCoreBinding,
25
+ } from "./bindings";
26
+ import type { ComposerRuntimePath } from "./paths";
27
+
28
+ import {
29
+ type AttachmentRuntime,
30
+ type AttachmentState,
31
+ EditComposerAttachmentRuntimeImpl,
32
+ ThreadComposerAttachmentRuntimeImpl,
33
+ } from "./attachment-runtime";
34
+
35
+ export type {
36
+ ThreadComposerRuntimeCoreBinding,
37
+ EditComposerRuntimeCoreBinding,
38
+ ComposerRuntimeCoreBinding,
39
+ };
40
+
41
+ type BaseComposerState = {
42
+ readonly canCancel: boolean;
43
+ readonly isEditing: boolean;
44
+ readonly isEmpty: boolean;
45
+
46
+ readonly text: string;
47
+ readonly role: MessageRole;
48
+ readonly attachments: readonly Attachment[];
49
+ readonly runConfig: RunConfig;
50
+
51
+ readonly attachmentAccept: string;
52
+
53
+ /**
54
+ * The current state of dictation.
55
+ * Undefined when dictation is not active.
56
+ */
57
+ readonly dictation: DictationState | undefined;
58
+
59
+ /**
60
+ * The currently quoted text, if any.
61
+ * Undefined when no quote is set.
62
+ */
63
+ readonly quote: QuoteInfo | undefined;
64
+ };
65
+
66
+ export type ThreadComposerState = BaseComposerState & {
67
+ readonly type: "thread";
68
+
69
+ readonly attachments: readonly PendingAttachment[];
70
+ };
71
+
72
+ export type EditComposerState = BaseComposerState & {
73
+ readonly type: "edit";
74
+ };
75
+
76
+ export type ComposerState = ThreadComposerState | EditComposerState;
77
+
78
+ const EMPTY_ARRAY = Object.freeze([]);
79
+ const EMPTY_OBJECT = Object.freeze({});
80
+ const getThreadComposerState = (
81
+ runtime: ThreadComposerRuntimeCore | undefined,
82
+ ): ThreadComposerState => {
83
+ return Object.freeze({
84
+ type: "thread",
85
+
86
+ isEditing: runtime?.isEditing ?? false,
87
+ canCancel: runtime?.canCancel ?? false,
88
+ isEmpty: runtime?.isEmpty ?? true,
89
+
90
+ attachments: runtime?.attachments ?? EMPTY_ARRAY,
91
+ text: runtime?.text ?? "",
92
+ role: runtime?.role ?? "user",
93
+ runConfig: runtime?.runConfig ?? EMPTY_OBJECT,
94
+ attachmentAccept: runtime?.attachmentAccept ?? "",
95
+ dictation: runtime?.dictation,
96
+ quote: runtime?.quote,
97
+
98
+ value: runtime?.text ?? "",
99
+ });
100
+ };
101
+
102
+ const getEditComposerState = (
103
+ runtime: ComposerRuntimeCore | undefined,
104
+ ): EditComposerState => {
105
+ return Object.freeze({
106
+ type: "edit",
107
+
108
+ isEditing: runtime?.isEditing ?? false,
109
+ canCancel: runtime?.canCancel ?? false,
110
+ isEmpty: runtime?.isEmpty ?? true,
111
+
112
+ text: runtime?.text ?? "",
113
+ role: runtime?.role ?? "user",
114
+ attachments: runtime?.attachments ?? EMPTY_ARRAY,
115
+ runConfig: runtime?.runConfig ?? EMPTY_OBJECT,
116
+ attachmentAccept: runtime?.attachmentAccept ?? "",
117
+ dictation: runtime?.dictation,
118
+ quote: runtime?.quote,
119
+
120
+ value: runtime?.text ?? "",
121
+ });
122
+ };
123
+
124
+ export type ComposerRuntime = {
125
+ readonly path: ComposerRuntimePath;
126
+ readonly type: "edit" | "thread";
127
+
128
+ /**
129
+ * Get the current state of the composer. Includes any data that has been added to the composer.
130
+ */
131
+ getState(): ComposerState;
132
+
133
+ /**
134
+ * Given a standard js File object, add it to the composer. A composer can have multiple attachments.
135
+ * @param file The file to add to the composer.
136
+ */
137
+ addAttachment(file: File): Promise<void>;
138
+
139
+ /**
140
+ * Set the text of the composer.
141
+ * @param text The text to set in the composer.
142
+ */
143
+ setText(text: string): void;
144
+
145
+ /**
146
+ * Set the role of the composer. For instance, if you'd like a specific message to have the 'assistant' role, you can do so here.
147
+ * @param role The role to set in the composer.
148
+ */
149
+ setRole(role: MessageRole): void;
150
+
151
+ /**
152
+ * Set the run config of the composer. This is used to send custom configuration data to the model.
153
+ * Within your backend, you can use the `runConfig` object.
154
+ * Example:
155
+ * ```ts
156
+ * composerRuntime.setRunConfig({
157
+ * custom: { customField: "customValue" }
158
+ * });
159
+ * ```
160
+ * @param runConfig The run config to set in the composer.
161
+ */
162
+ setRunConfig(runConfig: RunConfig): void;
163
+
164
+ /**
165
+ * Reset the composer. This will clear the entire state of the composer, including all text and attachments.
166
+ */
167
+ reset(): Promise<void>;
168
+
169
+ /**
170
+ * Clear all attachments from the composer.
171
+ */
172
+ clearAttachments(): Promise<void>;
173
+
174
+ /**
175
+ * Send a message. This will send whatever text or attachments are in the composer.
176
+ */
177
+ send(): void;
178
+
179
+ /**
180
+ * Cancel the current run. In edit mode, this will exit edit mode.
181
+ */
182
+ cancel(): void;
183
+
184
+ /**
185
+ * Listens for changes to the composer state.
186
+ * @param callback The callback to call when the composer state changes.
187
+ */
188
+ subscribe(callback: () => void): Unsubscribe;
189
+
190
+ /**
191
+ * Get an attachment by index.
192
+ * @param idx The index of the attachment to get.
193
+ */
194
+ getAttachmentByIndex(idx: number): AttachmentRuntime;
195
+
196
+ /**
197
+ * Start dictation to convert voice to text input.
198
+ * Requires a DictationAdapter to be configured.
199
+ */
200
+ startDictation(): void;
201
+
202
+ /**
203
+ * Stop the current dictation session.
204
+ */
205
+ stopDictation(): void;
206
+
207
+ /**
208
+ * Set a quote for the next message. Pass undefined to clear.
209
+ * @param quote The quote info to set, or undefined to clear.
210
+ */
211
+ setQuote(quote: QuoteInfo | undefined): void;
212
+
213
+ /**
214
+ * @deprecated This API is still under active development and might change without notice.
215
+ */
216
+ unstable_on(
217
+ event: ComposerRuntimeEventType,
218
+ callback: () => void,
219
+ ): Unsubscribe;
220
+ };
221
+
222
+ export abstract class ComposerRuntimeImpl implements ComposerRuntime {
223
+ public get path() {
224
+ return this._core.path;
225
+ }
226
+
227
+ public abstract get type(): "edit" | "thread";
228
+
229
+ constructor(protected _core: ComposerRuntimeCoreBinding) {}
230
+
231
+ protected __internal_bindMethods() {
232
+ this.setText = this.setText.bind(this);
233
+ this.setRunConfig = this.setRunConfig.bind(this);
234
+ this.getState = this.getState.bind(this);
235
+ this.subscribe = this.subscribe.bind(this);
236
+ this.addAttachment = this.addAttachment.bind(this);
237
+ this.reset = this.reset.bind(this);
238
+ this.clearAttachments = this.clearAttachments.bind(this);
239
+ this.send = this.send.bind(this);
240
+ this.cancel = this.cancel.bind(this);
241
+ this.setRole = this.setRole.bind(this);
242
+ this.getAttachmentByIndex = this.getAttachmentByIndex.bind(this);
243
+ this.startDictation = this.startDictation.bind(this);
244
+ this.stopDictation = this.stopDictation.bind(this);
245
+ this.setQuote = this.setQuote.bind(this);
246
+ this.unstable_on = this.unstable_on.bind(this);
247
+ }
248
+
249
+ public abstract getState(): ComposerState;
250
+
251
+ public setText(text: string) {
252
+ const core = this._core.getState();
253
+ if (!core) throw new Error("Composer is not available");
254
+ core.setText(text);
255
+ }
256
+
257
+ public setRunConfig(runConfig: RunConfig) {
258
+ const core = this._core.getState();
259
+ if (!core) throw new Error("Composer is not available");
260
+ core.setRunConfig(runConfig);
261
+ }
262
+
263
+ public addAttachment(file: File) {
264
+ const core = this._core.getState();
265
+ if (!core) throw new Error("Composer is not available");
266
+ return core.addAttachment(file);
267
+ }
268
+
269
+ public reset() {
270
+ const core = this._core.getState();
271
+ if (!core) throw new Error("Composer is not available");
272
+ return core.reset();
273
+ }
274
+
275
+ public clearAttachments() {
276
+ const core = this._core.getState();
277
+ if (!core) throw new Error("Composer is not available");
278
+ return core.clearAttachments();
279
+ }
280
+
281
+ public send() {
282
+ const core = this._core.getState();
283
+ if (!core) throw new Error("Composer is not available");
284
+ core.send();
285
+ }
286
+
287
+ public cancel() {
288
+ const core = this._core.getState();
289
+ if (!core) throw new Error("Composer is not available");
290
+ core.cancel();
291
+ }
292
+
293
+ public setRole(role: MessageRole) {
294
+ const core = this._core.getState();
295
+ if (!core) throw new Error("Composer is not available");
296
+ core.setRole(role);
297
+ }
298
+
299
+ public startDictation() {
300
+ const core = this._core.getState();
301
+ if (!core) throw new Error("Composer is not available");
302
+ core.startDictation();
303
+ }
304
+
305
+ public stopDictation() {
306
+ const core = this._core.getState();
307
+ if (!core) throw new Error("Composer is not available");
308
+ core.stopDictation();
309
+ }
310
+
311
+ public setQuote(quote: QuoteInfo | undefined) {
312
+ const core = this._core.getState();
313
+ if (!core) throw new Error("Composer is not available");
314
+ core.setQuote(quote);
315
+ }
316
+
317
+ public subscribe(callback: () => void) {
318
+ return this._core.subscribe(callback);
319
+ }
320
+
321
+ private _eventSubscriptionSubjects = new Map<
322
+ string,
323
+ EventSubscriptionSubject<ComposerRuntimeEventType>
324
+ >();
325
+
326
+ public unstable_on(
327
+ event: ComposerRuntimeEventType,
328
+ callback: () => void,
329
+ ): Unsubscribe {
330
+ let subject = this._eventSubscriptionSubjects.get(event);
331
+ if (!subject) {
332
+ subject = new EventSubscriptionSubject({
333
+ event: event,
334
+ binding: this._core,
335
+ });
336
+ this._eventSubscriptionSubjects.set(event, subject);
337
+ }
338
+ return subject.subscribe(callback);
339
+ }
340
+
341
+ public abstract getAttachmentByIndex(idx: number): AttachmentRuntime;
342
+ }
343
+
344
+ export type ThreadComposerRuntime = Omit<
345
+ ComposerRuntime,
346
+ "getState" | "getAttachmentByIndex"
347
+ > & {
348
+ readonly path: ComposerRuntimePath & { composerSource: "thread" };
349
+ readonly type: "thread";
350
+ getState(): ThreadComposerState;
351
+
352
+ getAttachmentByIndex(
353
+ idx: number,
354
+ ): AttachmentRuntime & { source: "thread-composer" };
355
+ };
356
+
357
+ export class ThreadComposerRuntimeImpl
358
+ extends ComposerRuntimeImpl
359
+ implements ThreadComposerRuntime
360
+ {
361
+ public override get path() {
362
+ return this._core.path as ComposerRuntimePath & {
363
+ composerSource: "thread";
364
+ };
365
+ }
366
+
367
+ public get type() {
368
+ return "thread" as const;
369
+ }
370
+
371
+ private _getState;
372
+
373
+ constructor(core: ThreadComposerRuntimeCoreBinding) {
374
+ const stateBinding = new LazyMemoizeSubject({
375
+ path: core.path,
376
+ getState: () => getThreadComposerState(core.getState()),
377
+ subscribe: (callback) => core.subscribe(callback),
378
+ });
379
+ super({
380
+ path: core.path,
381
+ getState: () => core.getState(),
382
+ subscribe: (callback) => stateBinding.subscribe(callback),
383
+ });
384
+ this._getState = stateBinding.getState.bind(stateBinding);
385
+
386
+ this.__internal_bindMethods();
387
+ }
388
+
389
+ public override getState(): ThreadComposerState {
390
+ return this._getState();
391
+ }
392
+
393
+ public getAttachmentByIndex(idx: number) {
394
+ return new ThreadComposerAttachmentRuntimeImpl(
395
+ new ShallowMemoizeSubject({
396
+ path: {
397
+ ...this.path,
398
+ attachmentSource: "thread-composer",
399
+ attachmentSelector: { type: "index", index: idx },
400
+ ref: `${this.path.ref}.attachments[${idx}]`,
401
+ },
402
+ getState: () => {
403
+ const attachments = this.getState().attachments;
404
+ const attachment = attachments[idx];
405
+ if (!attachment) return SKIP_UPDATE;
406
+
407
+ return {
408
+ ...attachment,
409
+ source: "thread-composer",
410
+ } satisfies AttachmentState & { source: "thread-composer" };
411
+ },
412
+ subscribe: (callback) => this._core.subscribe(callback),
413
+ }),
414
+ this._core,
415
+ );
416
+ }
417
+ }
418
+
419
+ export type EditComposerRuntime = Omit<
420
+ ComposerRuntime,
421
+ "getState" | "getAttachmentByIndex"
422
+ > & {
423
+ readonly path: ComposerRuntimePath & { composerSource: "edit" };
424
+ readonly type: "edit";
425
+
426
+ getState(): EditComposerState;
427
+ beginEdit(): void;
428
+
429
+ getAttachmentByIndex(
430
+ idx: number,
431
+ ): AttachmentRuntime & { source: "edit-composer" };
432
+ };
433
+
434
+ export class EditComposerRuntimeImpl
435
+ extends ComposerRuntimeImpl
436
+ implements EditComposerRuntime
437
+ {
438
+ public override get path() {
439
+ return this._core.path as ComposerRuntimePath & { composerSource: "edit" };
440
+ }
441
+
442
+ public get type() {
443
+ return "edit" as const;
444
+ }
445
+
446
+ private _getState;
447
+ constructor(
448
+ core: EditComposerRuntimeCoreBinding,
449
+ private _beginEdit: () => void,
450
+ ) {
451
+ const stateBinding = new LazyMemoizeSubject({
452
+ path: core.path,
453
+ getState: () => getEditComposerState(core.getState()),
454
+ subscribe: (callback) => core.subscribe(callback),
455
+ });
456
+
457
+ super({
458
+ path: core.path,
459
+ getState: () => core.getState(),
460
+ subscribe: (callback) => stateBinding.subscribe(callback),
461
+ });
462
+
463
+ this._getState = stateBinding.getState.bind(stateBinding);
464
+
465
+ this.__internal_bindMethods();
466
+ }
467
+
468
+ public override __internal_bindMethods() {
469
+ super.__internal_bindMethods();
470
+ this.beginEdit = this.beginEdit.bind(this);
471
+ }
472
+
473
+ public override getState(): EditComposerState {
474
+ return this._getState();
475
+ }
476
+
477
+ public beginEdit() {
478
+ this._beginEdit();
479
+ }
480
+
481
+ public getAttachmentByIndex(idx: number) {
482
+ return new EditComposerAttachmentRuntimeImpl(
483
+ new ShallowMemoizeSubject({
484
+ path: {
485
+ ...this.path,
486
+ attachmentSource: "edit-composer",
487
+ attachmentSelector: { type: "index", index: idx },
488
+ ref: `${this.path.ref}.attachments[${idx}]`,
489
+ },
490
+ getState: () => {
491
+ const attachments = this.getState().attachments;
492
+ const attachment = attachments[idx];
493
+ if (!attachment) return SKIP_UPDATE;
494
+
495
+ return {
496
+ ...attachment,
497
+ source: "edit-composer",
498
+ } satisfies AttachmentState & { source: "edit-composer" };
499
+ },
500
+ subscribe: (callback) => this._core.subscribe(callback),
501
+ }),
502
+ this._core,
503
+ );
504
+ }
505
+ }