@dxos/plugin-assistant 0.8.4-main.dedc0f3 → 0.8.4-main.e8ec1fe

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 (465) hide show
  1. package/dist/lib/browser/BlueprintArticle-IMCR3642.mjs +36 -0
  2. package/dist/lib/browser/BlueprintArticle-IMCR3642.mjs.map +7 -0
  3. package/dist/lib/browser/ChatCompanion-JYD2RIBJ.mjs +158 -0
  4. package/dist/lib/browser/ChatCompanion-JYD2RIBJ.mjs.map +7 -0
  5. package/dist/lib/browser/{ChatContainer-G6YHR6GJ.mjs → ChatContainer-XCPBWYIR.mjs} +22 -20
  6. package/dist/lib/browser/ChatContainer-XCPBWYIR.mjs.map +7 -0
  7. package/dist/lib/browser/{ChatDialog-HJ7VDRQO.mjs → ChatDialog-DT7KFCRL.mjs} +8 -6
  8. package/dist/lib/browser/ChatDialog-DT7KFCRL.mjs.map +7 -0
  9. package/dist/lib/browser/PromptArticle-45QX25Y5.mjs +59 -0
  10. package/dist/lib/browser/PromptArticle-45QX25Y5.mjs.map +7 -0
  11. package/dist/lib/browser/ai-service-ERTZBTP3.mjs +19 -0
  12. package/dist/lib/browser/ai-service-ERTZBTP3.mjs.map +7 -0
  13. package/dist/lib/browser/{app-graph-builder-3C43MLCD.mjs → app-graph-builder-VZEXMDTY.mjs} +67 -21
  14. package/dist/lib/browser/app-graph-builder-VZEXMDTY.mjs.map +7 -0
  15. package/dist/lib/browser/{blueprint-definition-VHFSRTEJ.mjs → blueprint-definition-5FT5JGPY.mjs} +4 -4
  16. package/dist/lib/browser/chunk-2BOE3OTW.mjs +262 -0
  17. package/dist/lib/browser/chunk-2BOE3OTW.mjs.map +7 -0
  18. package/dist/lib/browser/{chunk-SMIVXXAI.mjs → chunk-BNTPFZ7O.mjs} +51 -24
  19. package/dist/lib/browser/chunk-BNTPFZ7O.mjs.map +7 -0
  20. package/dist/lib/browser/chunk-FJQ4ZRYJ.mjs +335 -0
  21. package/dist/lib/browser/chunk-FJQ4ZRYJ.mjs.map +7 -0
  22. package/dist/lib/browser/{chunk-GLWD66TA.mjs → chunk-IXIIS4QA.mjs} +53 -38
  23. package/dist/lib/browser/chunk-IXIIS4QA.mjs.map +7 -0
  24. package/dist/lib/browser/{chunk-EZUSNS2J.mjs → chunk-LRE4VEZV.mjs} +2 -5
  25. package/dist/lib/browser/chunk-LRE4VEZV.mjs.map +7 -0
  26. package/dist/lib/browser/chunk-U62BTGDF.mjs +1929 -0
  27. package/dist/lib/browser/chunk-U62BTGDF.mjs.map +7 -0
  28. package/dist/lib/browser/chunk-WBG5PTSX.mjs +23 -0
  29. package/dist/lib/browser/chunk-WBG5PTSX.mjs.map +7 -0
  30. package/dist/lib/browser/edge-model-resolver-O6OFYIO2.mjs +18 -0
  31. package/dist/lib/browser/edge-model-resolver-O6OFYIO2.mjs.map +7 -0
  32. package/dist/lib/browser/index.mjs +118 -82
  33. package/dist/lib/browser/index.mjs.map +4 -4
  34. package/dist/lib/browser/{intent-resolver-I6M3ZDAS.mjs → intent-resolver-AK5O4GUW.mjs} +55 -24
  35. package/dist/lib/browser/intent-resolver-AK5O4GUW.mjs.map +7 -0
  36. package/dist/lib/browser/local-model-resolver-34MVHRKD.mjs +17 -0
  37. package/dist/lib/browser/local-model-resolver-34MVHRKD.mjs.map +7 -0
  38. package/dist/lib/browser/meta.json +1 -1
  39. package/dist/lib/browser/{react-surface-WNLA2636.mjs → react-surface-YCSR2MSR.mjs} +24 -35
  40. package/dist/lib/browser/react-surface-YCSR2MSR.mjs.map +7 -0
  41. package/dist/lib/browser/{settings-36V3VUMW.mjs → settings-NYJGNQ5I.mjs} +5 -5
  42. package/dist/lib/browser/{settings-36V3VUMW.mjs.map → settings-NYJGNQ5I.mjs.map} +1 -1
  43. package/dist/lib/browser/{state-AINRYS5W.mjs → state-GG7Z3NB7.mjs} +9 -5
  44. package/dist/lib/browser/{state-AINRYS5W.mjs.map → state-GG7Z3NB7.mjs.map} +3 -3
  45. package/dist/lib/browser/toolkit-VYDAWNE4.mjs +17 -0
  46. package/dist/lib/browser/toolkit-VYDAWNE4.mjs.map +7 -0
  47. package/dist/lib/browser/types/index.mjs +2 -2
  48. package/dist/lib/node-esm/BlueprintArticle-OL2HUY6Q.mjs +37 -0
  49. package/dist/lib/node-esm/BlueprintArticle-OL2HUY6Q.mjs.map +7 -0
  50. package/dist/lib/node-esm/ChatCompanion-AHKJS25S.mjs +159 -0
  51. package/dist/lib/node-esm/ChatCompanion-AHKJS25S.mjs.map +7 -0
  52. package/dist/lib/node-esm/{ChatContainer-EZZF7RSQ.mjs → ChatContainer-K7OGPE3G.mjs} +22 -20
  53. package/dist/lib/node-esm/ChatContainer-K7OGPE3G.mjs.map +7 -0
  54. package/dist/lib/node-esm/{ChatDialog-PTQLZNJU.mjs → ChatDialog-QT6ZBX45.mjs} +8 -6
  55. package/dist/lib/node-esm/ChatDialog-QT6ZBX45.mjs.map +7 -0
  56. package/dist/lib/node-esm/PromptArticle-OUKFSJQV.mjs +60 -0
  57. package/dist/lib/node-esm/PromptArticle-OUKFSJQV.mjs.map +7 -0
  58. package/dist/lib/node-esm/ai-service-MUYLV3NT.mjs +20 -0
  59. package/dist/lib/node-esm/ai-service-MUYLV3NT.mjs.map +7 -0
  60. package/dist/lib/node-esm/{app-graph-builder-NM3JDLQ2.mjs → app-graph-builder-VRN6ESRR.mjs} +67 -21
  61. package/dist/lib/node-esm/app-graph-builder-VRN6ESRR.mjs.map +7 -0
  62. package/dist/lib/node-esm/{blueprint-definition-4E6XTLVN.mjs → blueprint-definition-XW6QQVLV.mjs} +4 -4
  63. package/dist/lib/node-esm/chunk-3Q22TTXW.mjs +264 -0
  64. package/dist/lib/node-esm/chunk-3Q22TTXW.mjs.map +7 -0
  65. package/dist/lib/node-esm/{chunk-7YOGZI66.mjs → chunk-AB74FOA2.mjs} +51 -24
  66. package/dist/lib/node-esm/chunk-AB74FOA2.mjs.map +7 -0
  67. package/dist/lib/node-esm/chunk-BHS747K7.mjs +1930 -0
  68. package/dist/lib/node-esm/chunk-BHS747K7.mjs.map +7 -0
  69. package/dist/lib/node-esm/chunk-KJGD4EBJ.mjs +336 -0
  70. package/dist/lib/node-esm/chunk-KJGD4EBJ.mjs.map +7 -0
  71. package/dist/lib/node-esm/{chunk-QG2KT3AT.mjs → chunk-UXTUHH24.mjs} +53 -38
  72. package/dist/lib/node-esm/chunk-UXTUHH24.mjs.map +7 -0
  73. package/dist/lib/node-esm/chunk-WE6KTH72.mjs +25 -0
  74. package/dist/lib/node-esm/chunk-WE6KTH72.mjs.map +7 -0
  75. package/dist/lib/node-esm/{chunk-XD4CDA4R.mjs → chunk-YWFWT57N.mjs} +2 -5
  76. package/dist/lib/node-esm/chunk-YWFWT57N.mjs.map +7 -0
  77. package/dist/lib/node-esm/edge-model-resolver-2ARXDOYS.mjs +19 -0
  78. package/dist/lib/node-esm/edge-model-resolver-2ARXDOYS.mjs.map +7 -0
  79. package/dist/lib/node-esm/index.mjs +118 -82
  80. package/dist/lib/node-esm/index.mjs.map +4 -4
  81. package/dist/lib/node-esm/{intent-resolver-VIINHFMT.mjs → intent-resolver-L2F3N45L.mjs} +55 -24
  82. package/dist/lib/node-esm/intent-resolver-L2F3N45L.mjs.map +7 -0
  83. package/dist/lib/node-esm/local-model-resolver-TP2NTSAX.mjs +18 -0
  84. package/dist/lib/node-esm/local-model-resolver-TP2NTSAX.mjs.map +7 -0
  85. package/dist/lib/node-esm/meta.json +1 -1
  86. package/dist/lib/node-esm/{react-surface-GP3LU6DX.mjs → react-surface-CTW44GEM.mjs} +24 -35
  87. package/dist/lib/node-esm/react-surface-CTW44GEM.mjs.map +7 -0
  88. package/dist/lib/node-esm/{settings-7ZCZ6AS5.mjs → settings-RRHYI5KO.mjs} +5 -5
  89. package/dist/lib/node-esm/{settings-7ZCZ6AS5.mjs.map → settings-RRHYI5KO.mjs.map} +1 -1
  90. package/dist/lib/node-esm/{state-EQS5KP6M.mjs → state-FSUHFMDM.mjs} +9 -5
  91. package/dist/lib/node-esm/{state-EQS5KP6M.mjs.map → state-FSUHFMDM.mjs.map} +3 -3
  92. package/dist/lib/node-esm/toolkit-HFJZLVIR.mjs +18 -0
  93. package/dist/lib/node-esm/toolkit-HFJZLVIR.mjs.map +7 -0
  94. package/dist/lib/node-esm/types/index.mjs +2 -2
  95. package/dist/types/src/AssistantPlugin.d.ts +1 -1
  96. package/dist/types/src/AssistantPlugin.d.ts.map +1 -1
  97. package/dist/types/src/capabilities/ai-service.d.ts +2 -3
  98. package/dist/types/src/capabilities/ai-service.d.ts.map +1 -1
  99. package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -1
  100. package/dist/types/src/capabilities/blueprint-definition.d.ts +1 -1
  101. package/dist/types/src/capabilities/blueprint-definition.d.ts.map +1 -1
  102. package/dist/types/src/capabilities/capabilities.d.ts +2 -24
  103. package/dist/types/src/capabilities/capabilities.d.ts.map +1 -1
  104. package/dist/types/src/capabilities/edge-model-resolver.d.ts.map +1 -1
  105. package/dist/types/src/capabilities/index.d.ts +0 -1
  106. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  107. package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -1
  108. package/dist/types/src/capabilities/local-model-resolver.d.ts.map +1 -1
  109. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
  110. package/dist/types/src/capabilities/state.d.ts.map +1 -1
  111. package/dist/types/src/capabilities/toolkit.d.ts +1 -1
  112. package/dist/types/src/capabilities/toolkit.d.ts.map +1 -1
  113. package/dist/types/src/components/BlueprintArticle.d.ts +7 -0
  114. package/dist/types/src/components/BlueprintArticle.d.ts.map +1 -0
  115. package/dist/types/src/components/Chat/Chat.d.ts +20 -9
  116. package/dist/types/src/components/Chat/Chat.d.ts.map +1 -1
  117. package/dist/types/src/components/Chat/events.d.ts +4 -0
  118. package/dist/types/src/components/Chat/events.d.ts.map +1 -1
  119. package/dist/types/src/components/ChatCompanion.d.ts +2 -2
  120. package/dist/types/src/components/ChatCompanion.d.ts.map +1 -1
  121. package/dist/types/src/components/ChatContainer.d.ts +7 -4
  122. package/dist/types/src/components/ChatContainer.d.ts.map +1 -1
  123. package/dist/types/src/components/ChatDialog.d.ts.map +1 -1
  124. package/dist/types/src/components/ChatProgress/ChatProgress.d.ts.map +1 -1
  125. package/dist/types/src/components/ChatPrompt/ChatActions.d.ts.map +1 -1
  126. package/dist/types/src/components/ChatPrompt/ChatOptions.d.ts.map +1 -1
  127. package/dist/types/src/components/ChatThread/ChatThread.d.ts +6 -7
  128. package/dist/types/src/components/ChatThread/ChatThread.d.ts.map +1 -1
  129. package/dist/types/src/components/ChatThread/ChatThread.stories.d.ts +124 -71
  130. package/dist/types/src/components/ChatThread/ChatThread.stories.d.ts.map +1 -1
  131. package/dist/types/src/components/ChatThread/reducers.d.ts +5 -5
  132. package/dist/types/src/components/ChatThread/reducers.d.ts.map +1 -1
  133. package/dist/types/src/components/ChatThread/registry.d.ts.map +1 -1
  134. package/dist/types/src/components/ChatThread/sync.d.ts +12 -6
  135. package/dist/types/src/components/ChatThread/sync.d.ts.map +1 -1
  136. package/dist/types/src/components/PromptArticle.d.ts +7 -0
  137. package/dist/types/src/components/PromptArticle.d.ts.map +1 -0
  138. package/dist/types/src/components/TemplateEditor/TemplateEditor.d.ts +2 -1
  139. package/dist/types/src/components/TemplateEditor/TemplateEditor.d.ts.map +1 -1
  140. package/dist/types/src/components/TemplateEditor/TemplateEditor.stories.d.ts +111 -61
  141. package/dist/types/src/components/TemplateEditor/TemplateEditor.stories.d.ts.map +1 -1
  142. package/dist/types/src/components/TemplateEditor/TemplateForm.d.ts +1 -1
  143. package/dist/types/src/components/TemplateEditor/TemplateForm.d.ts.map +1 -1
  144. package/dist/types/src/components/TemplateEditor/TemplateForm.stories.d.ts +111 -61
  145. package/dist/types/src/components/TemplateEditor/TemplateForm.stories.d.ts.map +1 -1
  146. package/dist/types/src/components/TemplateEditor/extensions/handlebars-extension.d.ts.map +1 -0
  147. package/dist/types/src/components/TemplateEditor/extensions/index.d.ts +3 -0
  148. package/dist/types/src/components/TemplateEditor/extensions/index.d.ts.map +1 -0
  149. package/dist/types/src/components/TemplateEditor/extensions/xml-extension.d.ts +8 -0
  150. package/dist/types/src/components/TemplateEditor/extensions/xml-extension.d.ts.map +1 -0
  151. package/dist/types/src/components/ToolBlock/ToolBlock.d.ts +9 -7
  152. package/dist/types/src/components/ToolBlock/ToolBlock.d.ts.map +1 -1
  153. package/dist/types/src/components/Toolbox/Toolbox.d.ts +2 -2
  154. package/dist/types/src/components/Toolbox/Toolbox.d.ts.map +1 -1
  155. package/dist/types/src/components/Toolbox/Toolbox.stories.d.ts +111 -61
  156. package/dist/types/src/components/Toolbox/Toolbox.stories.d.ts.map +1 -1
  157. package/dist/types/src/components/index.d.ts +4 -9
  158. package/dist/types/src/components/index.d.ts.map +1 -1
  159. package/dist/types/src/functions/analysis.d.ts +1 -1
  160. package/dist/types/src/functions/analysis.d.ts.map +1 -1
  161. package/dist/types/src/functions/index.d.ts +2 -2
  162. package/dist/types/src/functions/index.d.ts.map +1 -1
  163. package/dist/types/src/functions/{list.d.ts → object-list.d.ts} +2 -2
  164. package/dist/types/src/functions/object-list.d.ts.map +1 -0
  165. package/dist/types/src/functions/{load.d.ts → object-load.d.ts} +2 -2
  166. package/dist/types/src/functions/object-load.d.ts.map +1 -0
  167. package/dist/types/src/hooks/index.d.ts +1 -2
  168. package/dist/types/src/hooks/index.d.ts.map +1 -1
  169. package/dist/types/src/hooks/useBlueprintRegistry.d.ts +2 -1
  170. package/dist/types/src/hooks/useBlueprintRegistry.d.ts.map +1 -1
  171. package/dist/types/src/hooks/useChatProcessor.d.ts +4 -2
  172. package/dist/types/src/hooks/useChatProcessor.d.ts.map +1 -1
  173. package/dist/types/src/hooks/useChatServices.d.ts +1 -1
  174. package/dist/types/src/hooks/useChatServices.d.ts.map +1 -1
  175. package/dist/types/src/hooks/useChatToolbarActions.d.ts +8 -0
  176. package/dist/types/src/hooks/useChatToolbarActions.d.ts.map +1 -0
  177. package/dist/types/src/hooks/useContextBinder.d.ts +2 -2
  178. package/dist/types/src/hooks/useContextBinder.d.ts.map +1 -1
  179. package/dist/types/src/hooks/useReferencesProvider.d.ts.map +1 -1
  180. package/dist/types/src/index.d.ts +2 -0
  181. package/dist/types/src/index.d.ts.map +1 -1
  182. package/dist/types/src/meta.d.ts +1 -2
  183. package/dist/types/src/meta.d.ts.map +1 -1
  184. package/dist/types/src/processor/index.d.ts +1 -0
  185. package/dist/types/src/processor/index.d.ts.map +1 -1
  186. package/dist/types/src/processor/presets.d.ts +1 -1
  187. package/dist/types/src/processor/presets.d.ts.map +1 -1
  188. package/dist/types/src/processor/processor.d.ts +11 -10
  189. package/dist/types/src/processor/processor.d.ts.map +1 -1
  190. package/dist/types/src/processor/update-name.d.ts +10 -0
  191. package/dist/types/src/processor/update-name.d.ts.map +1 -0
  192. package/dist/types/src/queue-logger.d.ts.map +1 -1
  193. package/dist/types/src/testing/index.d.ts +0 -2
  194. package/dist/types/src/testing/index.d.ts.map +1 -1
  195. package/dist/types/src/testing/test-generator.d.ts +3 -3
  196. package/dist/types/src/testing/test-generator.d.ts.map +1 -1
  197. package/dist/types/src/testing/test-services.d.ts +2 -2
  198. package/dist/types/src/testing/test-services.d.ts.map +1 -1
  199. package/dist/types/src/translations.d.ts +239 -26
  200. package/dist/types/src/translations.d.ts.map +1 -1
  201. package/dist/types/src/types/Assistant.d.ts +15 -9
  202. package/dist/types/src/types/Assistant.d.ts.map +1 -1
  203. package/dist/types/src/types/AssistantAction.d.ts +33 -8
  204. package/dist/types/src/types/AssistantAction.d.ts.map +1 -1
  205. package/dist/types/src/types/service.d.ts +24 -18
  206. package/dist/types/src/types/service.d.ts.map +1 -1
  207. package/dist/types/tsconfig.tsbuildinfo +1 -1
  208. package/package.json +94 -113
  209. package/src/AssistantPlugin.tsx +154 -137
  210. package/src/capabilities/ai-service.ts +6 -7
  211. package/src/capabilities/app-graph-builder.ts +69 -21
  212. package/src/capabilities/blueprint-definition.ts +38 -30
  213. package/src/capabilities/capabilities.ts +2 -56
  214. package/src/capabilities/edge-model-resolver.ts +5 -7
  215. package/src/capabilities/index.ts +0 -1
  216. package/src/capabilities/intent-resolver.ts +69 -16
  217. package/src/capabilities/local-model-resolver.ts +7 -9
  218. package/src/capabilities/react-surface.tsx +16 -20
  219. package/src/capabilities/state.ts +2 -0
  220. package/src/capabilities/toolkit.ts +9 -155
  221. package/src/components/BlueprintArticle.tsx +29 -0
  222. package/src/components/Chat/Chat.tsx +155 -113
  223. package/src/components/Chat/events.ts +6 -0
  224. package/src/components/ChatCompanion.tsx +93 -49
  225. package/src/components/ChatContainer.tsx +27 -17
  226. package/src/components/ChatDialog.tsx +9 -2
  227. package/src/components/ChatProgress/ChatProgress.tsx +2 -3
  228. package/src/components/ChatPrompt/ChatActions.tsx +2 -4
  229. package/src/components/ChatPrompt/ChatOptions.tsx +40 -45
  230. package/src/components/ChatPrompt/ChatReferences.tsx +2 -2
  231. package/src/components/ChatThread/ChatThread.stories.tsx +52 -34
  232. package/src/components/ChatThread/ChatThread.tsx +28 -34
  233. package/src/components/ChatThread/reducers.ts +6 -6
  234. package/src/components/ChatThread/registry.tsx +25 -40
  235. package/src/components/ChatThread/sync.test.ts +21 -13
  236. package/src/components/ChatThread/sync.ts +48 -13
  237. package/src/components/ChatThread/testing/thread.md +37 -0
  238. package/src/components/PromptArticle.tsx +51 -0
  239. package/src/components/TemplateEditor/TemplateEditor.stories.tsx +15 -7
  240. package/src/components/TemplateEditor/TemplateEditor.tsx +19 -10
  241. package/src/components/TemplateEditor/TemplateForm.stories.tsx +4 -6
  242. package/src/components/TemplateEditor/TemplateForm.tsx +2 -2
  243. package/src/components/TemplateEditor/extensions/handlebars-extension.ts +269 -0
  244. package/src/components/TemplateEditor/extensions/index.ts +6 -0
  245. package/src/components/TemplateEditor/extensions/xml-extension.ts +64 -0
  246. package/src/components/ToolBlock/ToolBlock.tsx +37 -46
  247. package/src/components/Toolbox/Toolbox.stories.tsx +5 -8
  248. package/src/components/Toolbox/Toolbox.tsx +5 -5
  249. package/src/components/index.ts +2 -5
  250. package/src/functions/analysis.ts +5 -3
  251. package/src/functions/index.ts +2 -2
  252. package/src/functions/{list.ts → object-list.ts} +6 -4
  253. package/src/functions/{load.ts → object-load.ts} +8 -5
  254. package/src/hooks/index.ts +1 -2
  255. package/src/hooks/useBlueprintRegistry.ts +19 -4
  256. package/src/hooks/useChatProcessor.ts +22 -14
  257. package/src/hooks/useChatServices.ts +10 -7
  258. package/src/hooks/useChatToolbarActions.ts +122 -0
  259. package/src/hooks/useContextBinder.ts +19 -7
  260. package/src/hooks/useItemTypes.ts +1 -1
  261. package/src/hooks/useReferencesProvider.ts +2 -1
  262. package/src/index.ts +2 -0
  263. package/src/meta.ts +9 -6
  264. package/src/processor/index.ts +1 -0
  265. package/src/processor/presets.ts +2 -2
  266. package/src/processor/processor.test.ts +18 -24
  267. package/src/processor/processor.ts +35 -60
  268. package/src/processor/update-name.ts +56 -0
  269. package/src/queue-logger.ts +4 -8
  270. package/src/testing/index.ts +0 -2
  271. package/src/testing/test-generator.ts +15 -11
  272. package/src/testing/test-services.ts +2 -8
  273. package/src/translations.ts +24 -16
  274. package/src/types/Assistant.ts +10 -8
  275. package/src/types/AssistantAction.ts +23 -6
  276. package/src/types/service.ts +17 -9
  277. package/dist/lib/browser/BlueprintContainer-BFNN6K46.mjs +0 -29
  278. package/dist/lib/browser/BlueprintContainer-BFNN6K46.mjs.map +0 -7
  279. package/dist/lib/browser/ChatCompanion-YYYCHZYV.mjs +0 -126
  280. package/dist/lib/browser/ChatCompanion-YYYCHZYV.mjs.map +0 -7
  281. package/dist/lib/browser/ChatContainer-G6YHR6GJ.mjs.map +0 -7
  282. package/dist/lib/browser/ChatDialog-HJ7VDRQO.mjs.map +0 -7
  283. package/dist/lib/browser/SequenceContainer-TF5QNXYM.mjs +0 -150
  284. package/dist/lib/browser/SequenceContainer-TF5QNXYM.mjs.map +0 -7
  285. package/dist/lib/browser/ai-service-YC2EQPHA.mjs +0 -22
  286. package/dist/lib/browser/ai-service-YC2EQPHA.mjs.map +0 -7
  287. package/dist/lib/browser/app-graph-builder-3C43MLCD.mjs.map +0 -7
  288. package/dist/lib/browser/chunk-EZUSNS2J.mjs.map +0 -7
  289. package/dist/lib/browser/chunk-GLWD66TA.mjs.map +0 -7
  290. package/dist/lib/browser/chunk-O4LUJEDV.mjs +0 -20
  291. package/dist/lib/browser/chunk-O4LUJEDV.mjs.map +0 -7
  292. package/dist/lib/browser/chunk-PL4O4ZJU.mjs +0 -1974
  293. package/dist/lib/browser/chunk-PL4O4ZJU.mjs.map +0 -7
  294. package/dist/lib/browser/chunk-PPJAIE2T.mjs +0 -299
  295. package/dist/lib/browser/chunk-PPJAIE2T.mjs.map +0 -7
  296. package/dist/lib/browser/chunk-PQI3MGDN.mjs +0 -169
  297. package/dist/lib/browser/chunk-PQI3MGDN.mjs.map +0 -7
  298. package/dist/lib/browser/chunk-R6LRGW3I.mjs +0 -216
  299. package/dist/lib/browser/chunk-R6LRGW3I.mjs.map +0 -7
  300. package/dist/lib/browser/chunk-SMIVXXAI.mjs.map +0 -7
  301. package/dist/lib/browser/compute-runtime-X6IREJN3.mjs +0 -155
  302. package/dist/lib/browser/compute-runtime-X6IREJN3.mjs.map +0 -7
  303. package/dist/lib/browser/edge-model-resolver-JNEB355N.mjs +0 -22
  304. package/dist/lib/browser/edge-model-resolver-JNEB355N.mjs.map +0 -7
  305. package/dist/lib/browser/intent-resolver-I6M3ZDAS.mjs.map +0 -7
  306. package/dist/lib/browser/local-model-resolver-EUXSRZ7X.mjs +0 -21
  307. package/dist/lib/browser/local-model-resolver-EUXSRZ7X.mjs.map +0 -7
  308. package/dist/lib/browser/react-surface-WNLA2636.mjs.map +0 -7
  309. package/dist/lib/browser/toolkit-Y5OYX5PO.mjs +0 -191
  310. package/dist/lib/browser/toolkit-Y5OYX5PO.mjs.map +0 -7
  311. package/dist/lib/node-esm/BlueprintContainer-X4MRBKDR.mjs +0 -30
  312. package/dist/lib/node-esm/BlueprintContainer-X4MRBKDR.mjs.map +0 -7
  313. package/dist/lib/node-esm/ChatCompanion-PUAFRIEC.mjs +0 -127
  314. package/dist/lib/node-esm/ChatCompanion-PUAFRIEC.mjs.map +0 -7
  315. package/dist/lib/node-esm/ChatContainer-EZZF7RSQ.mjs.map +0 -7
  316. package/dist/lib/node-esm/ChatDialog-PTQLZNJU.mjs.map +0 -7
  317. package/dist/lib/node-esm/SequenceContainer-UXOVZPZO.mjs +0 -151
  318. package/dist/lib/node-esm/SequenceContainer-UXOVZPZO.mjs.map +0 -7
  319. package/dist/lib/node-esm/ai-service-XUMZVFCK.mjs +0 -23
  320. package/dist/lib/node-esm/ai-service-XUMZVFCK.mjs.map +0 -7
  321. package/dist/lib/node-esm/app-graph-builder-NM3JDLQ2.mjs.map +0 -7
  322. package/dist/lib/node-esm/chunk-4WLFSXZG.mjs +0 -170
  323. package/dist/lib/node-esm/chunk-4WLFSXZG.mjs.map +0 -7
  324. package/dist/lib/node-esm/chunk-7YOGZI66.mjs.map +0 -7
  325. package/dist/lib/node-esm/chunk-LVTG5JTW.mjs +0 -217
  326. package/dist/lib/node-esm/chunk-LVTG5JTW.mjs.map +0 -7
  327. package/dist/lib/node-esm/chunk-QG2KT3AT.mjs.map +0 -7
  328. package/dist/lib/node-esm/chunk-VFY2JG62.mjs +0 -22
  329. package/dist/lib/node-esm/chunk-VFY2JG62.mjs.map +0 -7
  330. package/dist/lib/node-esm/chunk-VH3LTD76.mjs +0 -300
  331. package/dist/lib/node-esm/chunk-VH3LTD76.mjs.map +0 -7
  332. package/dist/lib/node-esm/chunk-XD4CDA4R.mjs.map +0 -7
  333. package/dist/lib/node-esm/chunk-ZIDP7HBI.mjs +0 -1975
  334. package/dist/lib/node-esm/chunk-ZIDP7HBI.mjs.map +0 -7
  335. package/dist/lib/node-esm/compute-runtime-NRHLLTSC.mjs +0 -156
  336. package/dist/lib/node-esm/compute-runtime-NRHLLTSC.mjs.map +0 -7
  337. package/dist/lib/node-esm/edge-model-resolver-UE5TLLJZ.mjs +0 -23
  338. package/dist/lib/node-esm/edge-model-resolver-UE5TLLJZ.mjs.map +0 -7
  339. package/dist/lib/node-esm/intent-resolver-VIINHFMT.mjs.map +0 -7
  340. package/dist/lib/node-esm/local-model-resolver-JBEFVVZA.mjs +0 -22
  341. package/dist/lib/node-esm/local-model-resolver-JBEFVVZA.mjs.map +0 -7
  342. package/dist/lib/node-esm/react-surface-GP3LU6DX.mjs.map +0 -7
  343. package/dist/lib/node-esm/toolkit-2F2OL6WB.mjs +0 -192
  344. package/dist/lib/node-esm/toolkit-2F2OL6WB.mjs.map +0 -7
  345. package/dist/types/src/capabilities/compute-runtime.d.ts +0 -5
  346. package/dist/types/src/capabilities/compute-runtime.d.ts.map +0 -1
  347. package/dist/types/src/components/BlueprintContainer.d.ts +0 -8
  348. package/dist/types/src/components/BlueprintContainer.d.ts.map +0 -1
  349. package/dist/types/src/components/PromptSettings.d.ts +0 -6
  350. package/dist/types/src/components/PromptSettings.d.ts.map +0 -1
  351. package/dist/types/src/components/SequenceContainer.d.ts +0 -8
  352. package/dist/types/src/components/SequenceContainer.d.ts.map +0 -1
  353. package/dist/types/src/components/SequenceEditor/SequenceEditor.d.ts +0 -13
  354. package/dist/types/src/components/SequenceEditor/SequenceEditor.d.ts.map +0 -1
  355. package/dist/types/src/components/SequenceEditor/SequenceEditor.stories.d.ts +0 -267
  356. package/dist/types/src/components/SequenceEditor/SequenceEditor.stories.d.ts.map +0 -1
  357. package/dist/types/src/components/SequenceEditor/index.d.ts +0 -2
  358. package/dist/types/src/components/SequenceEditor/index.d.ts.map +0 -1
  359. package/dist/types/src/components/TemplateEditor/handlebars-extension.d.ts.map +0 -1
  360. package/dist/types/src/components/Toolbar/Toolbar.d.ts +0 -5
  361. package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +0 -1
  362. package/dist/types/src/components/Toolbar/index.d.ts +0 -2
  363. package/dist/types/src/components/Toolbar/index.d.ts.map +0 -1
  364. package/dist/types/src/components/Toolbar/useChatToolbarActions.d.ts +0 -11
  365. package/dist/types/src/components/Toolbar/useChatToolbarActions.d.ts.map +0 -1
  366. package/dist/types/src/execution-graph/execution-graph.d.ts +0 -21
  367. package/dist/types/src/execution-graph/execution-graph.d.ts.map +0 -1
  368. package/dist/types/src/execution-graph/index.d.ts +0 -2
  369. package/dist/types/src/execution-graph/index.d.ts.map +0 -1
  370. package/dist/types/src/functions/list.d.ts.map +0 -1
  371. package/dist/types/src/functions/load.d.ts.map +0 -1
  372. package/dist/types/src/hooks/useComputeRuntimeCallback.d.ts +0 -8
  373. package/dist/types/src/hooks/useComputeRuntimeCallback.d.ts.map +0 -1
  374. package/dist/types/src/hooks/useExecutionGraph.d.ts +0 -6
  375. package/dist/types/src/hooks/useExecutionGraph.d.ts.map +0 -1
  376. package/dist/types/src/stories/Chat.stories.d.ts +0 -30
  377. package/dist/types/src/stories/Chat.stories.d.ts.map +0 -1
  378. package/dist/types/src/stories/components/BlueprintContainer.d.ts +0 -4
  379. package/dist/types/src/stories/components/BlueprintContainer.d.ts.map +0 -1
  380. package/dist/types/src/stories/components/ChatContainer.d.ts +0 -4
  381. package/dist/types/src/stories/components/ChatContainer.d.ts.map +0 -1
  382. package/dist/types/src/stories/components/ChessContainer.d.ts +0 -4
  383. package/dist/types/src/stories/components/ChessContainer.d.ts.map +0 -1
  384. package/dist/types/src/stories/components/CommentsContainer.d.ts +0 -4
  385. package/dist/types/src/stories/components/CommentsContainer.d.ts.map +0 -1
  386. package/dist/types/src/stories/components/DebugCard.d.ts +0 -8
  387. package/dist/types/src/stories/components/DebugCard.d.ts.map +0 -1
  388. package/dist/types/src/stories/components/GraphContainer.d.ts +0 -6
  389. package/dist/types/src/stories/components/GraphContainer.d.ts.map +0 -1
  390. package/dist/types/src/stories/components/InvocationsContainer.d.ts +0 -4
  391. package/dist/types/src/stories/components/InvocationsContainer.d.ts.map +0 -1
  392. package/dist/types/src/stories/components/LoggingContainer.d.ts +0 -7
  393. package/dist/types/src/stories/components/LoggingContainer.d.ts.map +0 -1
  394. package/dist/types/src/stories/components/MessageContainer.d.ts +0 -4
  395. package/dist/types/src/stories/components/MessageContainer.d.ts.map +0 -1
  396. package/dist/types/src/stories/components/PromptContainer.d.ts +0 -6
  397. package/dist/types/src/stories/components/PromptContainer.d.ts.map +0 -1
  398. package/dist/types/src/stories/components/ResearchInputStack.d.ts +0 -4
  399. package/dist/types/src/stories/components/ResearchInputStack.d.ts.map +0 -1
  400. package/dist/types/src/stories/components/ResearchOutputStack.d.ts +0 -4
  401. package/dist/types/src/stories/components/ResearchOutputStack.d.ts.map +0 -1
  402. package/dist/types/src/stories/components/TasksContainer.d.ts +0 -4
  403. package/dist/types/src/stories/components/TasksContainer.d.ts.map +0 -1
  404. package/dist/types/src/stories/components/TokenManagerContainer.d.ts +0 -3
  405. package/dist/types/src/stories/components/TokenManagerContainer.d.ts.map +0 -1
  406. package/dist/types/src/stories/components/TriggersContainer.d.ts +0 -14
  407. package/dist/types/src/stories/components/TriggersContainer.d.ts.map +0 -1
  408. package/dist/types/src/stories/components/index.d.ts +0 -16
  409. package/dist/types/src/stories/components/index.d.ts.map +0 -1
  410. package/dist/types/src/stories/components/types.d.ts +0 -7
  411. package/dist/types/src/stories/components/types.d.ts.map +0 -1
  412. package/dist/types/src/stories/testing/data.d.ts +0 -9
  413. package/dist/types/src/stories/testing/data.d.ts.map +0 -1
  414. package/dist/types/src/stories/testing/index.d.ts +0 -3
  415. package/dist/types/src/stories/testing/index.d.ts.map +0 -1
  416. package/dist/types/src/stories/testing/schema.d.ts +0 -7
  417. package/dist/types/src/stories/testing/schema.d.ts.map +0 -1
  418. package/dist/types/src/stories/testing/testing.d.ts +0 -48
  419. package/dist/types/src/stories/testing/testing.d.ts.map +0 -1
  420. package/dist/types/src/testing/test-data.d.ts +0 -14
  421. package/dist/types/src/testing/test-data.d.ts.map +0 -1
  422. package/dist/types/src/testing/test-functions.d.ts +0 -6
  423. package/dist/types/src/testing/test-functions.d.ts.map +0 -1
  424. package/src/capabilities/compute-runtime.ts +0 -124
  425. package/src/components/BlueprintContainer.tsx +0 -24
  426. package/src/components/PromptSettings.tsx +0 -90
  427. package/src/components/SequenceContainer.tsx +0 -131
  428. package/src/components/SequenceEditor/SequenceEditor.stories.tsx +0 -33
  429. package/src/components/SequenceEditor/SequenceEditor.tsx +0 -50
  430. package/src/components/SequenceEditor/index.ts +0 -5
  431. package/src/components/TemplateEditor/handlebars-extension.ts +0 -165
  432. package/src/components/Toolbar/Toolbar.tsx +0 -21
  433. package/src/components/Toolbar/index.ts +0 -5
  434. package/src/components/Toolbar/useChatToolbarActions.ts +0 -126
  435. package/src/execution-graph/execution-graph.ts +0 -211
  436. package/src/execution-graph/index.ts +0 -5
  437. package/src/hooks/useComputeRuntimeCallback.ts +0 -25
  438. package/src/hooks/useExecutionGraph.ts +0 -20
  439. package/src/stories/Chat.stories.tsx +0 -657
  440. package/src/stories/components/BlueprintContainer.tsx +0 -34
  441. package/src/stories/components/ChatContainer.tsx +0 -74
  442. package/src/stories/components/ChessContainer.tsx +0 -17
  443. package/src/stories/components/CommentsContainer.tsx +0 -25
  444. package/src/stories/components/DebugCard.tsx +0 -61
  445. package/src/stories/components/GraphContainer.tsx +0 -119
  446. package/src/stories/components/InvocationsContainer.tsx +0 -17
  447. package/src/stories/components/LoggingContainer.tsx +0 -33
  448. package/src/stories/components/MessageContainer.tsx +0 -22
  449. package/src/stories/components/PromptContainer.tsx +0 -52
  450. package/src/stories/components/ResearchInputStack.tsx +0 -30
  451. package/src/stories/components/ResearchOutputStack.tsx +0 -29
  452. package/src/stories/components/TasksContainer.tsx +0 -49
  453. package/src/stories/components/TokenManagerContainer.tsx +0 -14
  454. package/src/stories/components/TriggersContainer.tsx +0 -75
  455. package/src/stories/components/index.ts +0 -20
  456. package/src/stories/components/types.ts +0 -11
  457. package/src/stories/testing/data.ts +0 -142
  458. package/src/stories/testing/index.ts +0 -6
  459. package/src/stories/testing/schema.ts +0 -17
  460. package/src/stories/testing/testing.tsx +0 -279
  461. package/src/testing/test-data.ts +0 -245
  462. package/src/testing/test-functions.ts +0 -16
  463. /package/dist/lib/browser/{blueprint-definition-VHFSRTEJ.mjs.map → blueprint-definition-5FT5JGPY.mjs.map} +0 -0
  464. /package/dist/lib/node-esm/{blueprint-definition-4E6XTLVN.mjs.map → blueprint-definition-XW6QQVLV.mjs.map} +0 -0
  465. /package/dist/types/src/components/TemplateEditor/{handlebars-extension.d.ts → extensions/handlebars-extension.d.ts} +0 -0
@@ -0,0 +1,1929 @@
1
+ import {
2
+ AiChatProcessor,
3
+ AiServicePresets
4
+ } from "./chunk-2BOE3OTW.mjs";
5
+ import {
6
+ AssistantAction_exports,
7
+ Assistant_exports,
8
+ LLM_PROVIDERS,
9
+ ServiceType
10
+ } from "./chunk-BNTPFZ7O.mjs";
11
+ import {
12
+ meta
13
+ } from "./chunk-WBG5PTSX.mjs";
14
+
15
+ // src/components/AssistantSettings/AssistantSettings.tsx
16
+ import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
17
+ import React from "react";
18
+ import { DEFAULT_EDGE_MODELS, DEFAULT_OLLAMA_MODELS } from "@dxos/ai";
19
+ import { Input, Select, useTranslation } from "@dxos/react-ui";
20
+ import { ControlGroup, ControlItemInput, ControlPage, ControlSection } from "@dxos/react-ui-form";
21
+ var DEFAULT_VALUE = "__default";
22
+ var LLM_PROVIDER_LABELS = {
23
+ edge: "DXOS",
24
+ ollama: "Ollama",
25
+ lmstudio: "LM Studio"
26
+ };
27
+ var AssistantSettings = ({ settings }) => {
28
+ var _effect = _useSignals();
29
+ try {
30
+ const { t } = useTranslation(meta.id);
31
+ return /* @__PURE__ */ React.createElement(ControlPage, null, /* @__PURE__ */ React.createElement(ControlSection, {
32
+ title: t("settings title", {
33
+ ns: meta.id
34
+ })
35
+ }, /* @__PURE__ */ React.createElement(ControlGroup, null, /* @__PURE__ */ React.createElement(ControlItemInput, {
36
+ title: t("settings custom prompts label")
37
+ }, /* @__PURE__ */ React.createElement(Input.Switch, {
38
+ checked: !!settings.customPrompts,
39
+ onCheckedChange: (checked) => settings.customPrompts = checked
40
+ })), /* @__PURE__ */ React.createElement(ControlItemInput, {
41
+ title: t("settings llm provider label")
42
+ }, /* @__PURE__ */ React.createElement(Select.Root, {
43
+ value: settings.llmProvider ?? "edge",
44
+ onValueChange: (value) => {
45
+ settings.llmProvider = value === DEFAULT_VALUE ? void 0 : value;
46
+ }
47
+ }, /* @__PURE__ */ React.createElement(Select.TriggerButton, {
48
+ placeholder: t("settings llm provider label")
49
+ }), /* @__PURE__ */ React.createElement(Select.Portal, null, /* @__PURE__ */ React.createElement(Select.Content, null, /* @__PURE__ */ React.createElement(Select.Viewport, null, /* @__PURE__ */ React.createElement(Select.Option, {
50
+ value: DEFAULT_VALUE
51
+ }, t("settings default label")), LLM_PROVIDERS.map((model) => /* @__PURE__ */ React.createElement(Select.Option, {
52
+ key: model,
53
+ value: model
54
+ }, LLM_PROVIDER_LABELS[model]))), /* @__PURE__ */ React.createElement(Select.Arrow, null))))), /* @__PURE__ */ React.createElement(ControlItemInput, {
55
+ title: t("settings edge llm model label")
56
+ }, /* @__PURE__ */ React.createElement(Select.Root, {
57
+ value: settings.edgeModel ?? DEFAULT_VALUE,
58
+ onValueChange: (value) => {
59
+ settings.edgeModel = value === DEFAULT_VALUE ? void 0 : value;
60
+ }
61
+ }, /* @__PURE__ */ React.createElement(Select.TriggerButton, {
62
+ placeholder: t("settings default llm model label")
63
+ }), /* @__PURE__ */ React.createElement(Select.Portal, null, /* @__PURE__ */ React.createElement(Select.Content, null, /* @__PURE__ */ React.createElement(Select.Viewport, null, /* @__PURE__ */ React.createElement(Select.Option, {
64
+ value: DEFAULT_VALUE
65
+ }, t("settings default label")), DEFAULT_EDGE_MODELS.map((model) => /* @__PURE__ */ React.createElement(Select.Option, {
66
+ key: model,
67
+ value: model
68
+ }, model))), /* @__PURE__ */ React.createElement(Select.Arrow, null))))), /* @__PURE__ */ React.createElement(ControlItemInput, {
69
+ title: t("settings ollama llm model label")
70
+ }, /* @__PURE__ */ React.createElement(Select.Root, {
71
+ value: settings.ollamaModel ?? DEFAULT_VALUE,
72
+ onValueChange: (value) => {
73
+ settings.ollamaModel = value === DEFAULT_VALUE ? void 0 : value;
74
+ }
75
+ }, /* @__PURE__ */ React.createElement(Select.TriggerButton, {
76
+ placeholder: t("settings default llm model label")
77
+ }), /* @__PURE__ */ React.createElement(Select.Portal, null, /* @__PURE__ */ React.createElement(Select.Content, null, /* @__PURE__ */ React.createElement(Select.Viewport, null, /* @__PURE__ */ React.createElement(Select.Option, {
78
+ value: DEFAULT_VALUE
79
+ }, t("settings default label")), DEFAULT_OLLAMA_MODELS.map((model) => /* @__PURE__ */ React.createElement(Select.Option, {
80
+ key: model,
81
+ value: model
82
+ }, model))), /* @__PURE__ */ React.createElement(Select.Arrow, null))))))));
83
+ } finally {
84
+ _effect.f();
85
+ }
86
+ };
87
+
88
+ // src/hooks/useBlueprintRegistry.ts
89
+ import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
90
+ import { useSignalEffect } from "@preact/signals-react";
91
+ import { useCallback, useMemo, useState } from "react";
92
+ import { Capabilities } from "@dxos/app-framework";
93
+ import { useCapabilities } from "@dxos/app-framework/react";
94
+ import { Blueprint } from "@dxos/blueprints";
95
+ import { Filter, Obj, Ref } from "@dxos/echo";
96
+ import { useQuery } from "@dxos/react-client/echo";
97
+ import { distinctBy, isNonNullable } from "@dxos/util";
98
+ var useBlueprintRegistry = () => {
99
+ const blueprints = useCapabilities(Capabilities.BlueprintDefinition);
100
+ return useMemo(() => new Blueprint.Registry(blueprints), [
101
+ blueprints
102
+ ]);
103
+ };
104
+ var useBlueprints = ({ blueprintRegistry, space }) => {
105
+ const staticBlueprints = useMemo(() => blueprintRegistry?.query() ?? [], [
106
+ blueprintRegistry
107
+ ]);
108
+ const spaceBlueprints = useQuery(space, Filter.type(Blueprint.Blueprint));
109
+ return useMemo(() => {
110
+ const blueprints = distinctBy([
111
+ ...staticBlueprints,
112
+ ...spaceBlueprints
113
+ ], (b) => b.key);
114
+ blueprints.sort(({ name: a }, { name: b }) => a.localeCompare(b));
115
+ return blueprints;
116
+ }, [
117
+ staticBlueprints,
118
+ spaceBlueprints
119
+ ]);
120
+ };
121
+ var useActiveBlueprints = ({ context }) => {
122
+ var _effect = _useSignals2();
123
+ try {
124
+ const [active, setActive] = useState(/* @__PURE__ */ new Map());
125
+ useSignalEffect(() => {
126
+ const refs = [
127
+ ...context?.blueprints.value ?? []
128
+ ];
129
+ const blueprints = refs.map((ref) => ref.target).filter(isNonNullable);
130
+ setActive(new Map(blueprints.map((blueprint) => [
131
+ blueprint.key,
132
+ blueprint
133
+ ])));
134
+ });
135
+ return active;
136
+ } finally {
137
+ _effect.f();
138
+ }
139
+ };
140
+ var useBlueprintHandlers = ({ space, context, blueprintRegistry }) => {
141
+ const onUpdateBlueprint = useCallback(async (key, checked) => {
142
+ if (!context || !blueprintRegistry) {
143
+ return;
144
+ }
145
+ const { objects } = await space.db.query(Filter.type(Blueprint.Blueprint)).run();
146
+ let storedBlueprint = objects.find((blueprint) => blueprint.key === key);
147
+ if (checked) {
148
+ if (!storedBlueprint) {
149
+ const blueprint = blueprintRegistry.getByKey(key);
150
+ if (!blueprint) {
151
+ return;
152
+ }
153
+ storedBlueprint = space.db.add(Obj.clone(blueprint));
154
+ }
155
+ await context.bind({
156
+ blueprints: [
157
+ Ref.make(storedBlueprint)
158
+ ]
159
+ });
160
+ } else if (storedBlueprint) {
161
+ await context.unbind({
162
+ blueprints: [
163
+ Ref.make(storedBlueprint)
164
+ ]
165
+ });
166
+ }
167
+ }, [
168
+ space,
169
+ context,
170
+ blueprintRegistry
171
+ ]);
172
+ return {
173
+ onUpdateBlueprint
174
+ };
175
+ };
176
+
177
+ // src/hooks/useChatProcessor.ts
178
+ import { RegistryContext } from "@effect-atom/atom-react";
179
+ import { useContext, useMemo as useMemo2, useState as useState2 } from "react";
180
+ import { AiConversation } from "@dxos/assistant";
181
+ import { log } from "@dxos/log";
182
+ import { useAsyncEffect } from "@dxos/react-ui";
183
+ var __dxlog_file = "/__w/dxos/dxos/packages/plugins/plugin-assistant/src/hooks/useChatProcessor.ts";
184
+ var useChatProcessor = ({ space, chat, preset, services, blueprintRegistry, settings }) => {
185
+ const observableRegistry = useContext(RegistryContext);
186
+ const [conversation, setConversation] = useState2();
187
+ useAsyncEffect(async () => {
188
+ if (!space || !chat) {
189
+ return;
190
+ }
191
+ const queue = space.queues.get(chat.queue.dxn);
192
+ const conversation2 = new AiConversation(queue);
193
+ await conversation2.open();
194
+ setConversation(conversation2);
195
+ return () => {
196
+ void conversation2.close();
197
+ setConversation(void 0);
198
+ };
199
+ }, [
200
+ space,
201
+ chat?.queue.dxn.toString()
202
+ ]);
203
+ const processor = useMemo2(() => {
204
+ if (!services || !conversation) {
205
+ return void 0;
206
+ }
207
+ log("creating processor", {
208
+ preset,
209
+ model: preset?.model,
210
+ settings
211
+ }, {
212
+ F: __dxlog_file,
213
+ L: 65,
214
+ S: void 0,
215
+ C: (f, a) => f(...a)
216
+ });
217
+ return new AiChatProcessor(conversation, services, {
218
+ observableRegistry,
219
+ blueprintRegistry,
220
+ model: preset?.model
221
+ });
222
+ }, [
223
+ services,
224
+ conversation,
225
+ blueprintRegistry,
226
+ preset
227
+ ]);
228
+ return processor;
229
+ };
230
+
231
+ // src/hooks/useChatServices.ts
232
+ import * as Effect from "effect/Effect";
233
+ import { useMemo as useMemo3 } from "react";
234
+ import { useCapability } from "@dxos/app-framework/react";
235
+ import { TracingService } from "@dxos/functions";
236
+ import { TracingServiceExt } from "@dxos/functions-runtime";
237
+ import { AutomationCapabilities } from "@dxos/plugin-automation";
238
+ import { useClient } from "@dxos/react-client";
239
+ var useChatServices = ({ space, chat }) => {
240
+ const client = useClient();
241
+ space ??= client.spaces.default;
242
+ const runtimeResolver = useCapability(AutomationCapabilities.ComputeRuntime);
243
+ return useMemo3(() => {
244
+ const runtime2 = runtimeResolver.getRuntime(space.id);
245
+ return () => runtime2.runPromise(Effect.gen(function* () {
246
+ return yield* Effect.runtime().pipe(Effect.provide(chat?.traceQueue?.target ? TracingServiceExt.layerQueue(chat.traceQueue?.target) : TracingService.layerNoop));
247
+ }));
248
+ }, [
249
+ space,
250
+ chat?.traceQueue?.target
251
+ ]);
252
+ };
253
+
254
+ // src/hooks/useChatToolbarActions.ts
255
+ import { Atom } from "@effect-atom/atom-react";
256
+ import * as Effect2 from "effect/Effect";
257
+ import { useMemo as useMemo10 } from "react";
258
+ import { createIntent } from "@dxos/app-framework";
259
+ import { useIntentDispatcher } from "@dxos/app-framework/react";
260
+ import { Filter as Filter5, Obj as Obj6, Query } from "@dxos/echo";
261
+ import { invariant } from "@dxos/invariant";
262
+ import { useQuery as useQuery4 } from "@dxos/react-client/echo";
263
+ import { MenuBuilder, useMenuActions } from "@dxos/react-ui-menu";
264
+
265
+ // src/components/index.ts
266
+ import { lazy } from "react";
267
+
268
+ // src/components/Chat/Chat.tsx
269
+ import { useSignals as _useSignals12 } from "@preact-signals/safe-react/tracking";
270
+ import { Prec } from "@codemirror/state";
271
+ import { keymap } from "@codemirror/view";
272
+ import { useAtomValue } from "@effect-atom/atom-react";
273
+ import { createContext } from "@radix-ui/react-context";
274
+ import * as Array2 from "effect/Array";
275
+ import * as Option2 from "effect/Option";
276
+ import React10, { useCallback as useCallback7, useEffect as useEffect6, useMemo as useMemo9, useRef as useRef3, useState as useState11 } from "react";
277
+ import { Event } from "@dxos/async";
278
+ import { Obj as Obj5 } from "@dxos/echo";
279
+ import { useVoiceInput } from "@dxos/plugin-transcription";
280
+ import { getSpace, useQueue } from "@dxos/react-client/echo";
281
+ import { useIdentity } from "@dxos/react-client/halo";
282
+ import { Input as Input2, useDynamicRef, useTranslation as useTranslation6 } from "@dxos/react-ui";
283
+ import { ChatEditor } from "@dxos/react-ui-chat";
284
+ import { MenuProvider, ToolbarMenu } from "@dxos/react-ui-menu";
285
+ import { mx as mx5 } from "@dxos/react-ui-theme";
286
+ import { Message } from "@dxos/types";
287
+ import { isTruthy } from "@dxos/util";
288
+
289
+ // src/hooks/useContextBinder.ts
290
+ import { useState as useState3 } from "react";
291
+ import { AiContextBinder } from "@dxos/assistant";
292
+ import { useAsyncEffect as useAsyncEffect2 } from "@dxos/react-ui";
293
+ var useContextBinder = (queue) => {
294
+ const [binder, setBinder] = useState3();
295
+ useAsyncEffect2(async () => {
296
+ if (!queue) {
297
+ return;
298
+ }
299
+ const binder2 = new AiContextBinder(queue);
300
+ await binder2.open();
301
+ setBinder(binder2);
302
+ return () => {
303
+ void binder2.close();
304
+ };
305
+ }, [
306
+ queue
307
+ ]);
308
+ return binder;
309
+ };
310
+
311
+ // src/hooks/useContextObjects.ts
312
+ import { useSignals as _useSignals3 } from "@preact-signals/safe-react/tracking";
313
+ import { useCallback as useCallback2 } from "react";
314
+ import { Ref as Ref2 } from "@dxos/echo";
315
+ import { log as log2 } from "@dxos/log";
316
+ import { isNonNullable as isNonNullable2 } from "@dxos/util";
317
+ var __dxlog_file2 = "/__w/dxos/dxos/packages/plugins/plugin-assistant/src/hooks/useContextObjects.ts";
318
+ var useContextObjects = ({ space, context }) => {
319
+ var _effect = _useSignals3();
320
+ try {
321
+ const objects = context?.objects.value.map((ref) => ref.target).filter(isNonNullable2) ?? [];
322
+ const handleUpdateObject = useCallback2(async (dxn, checked) => {
323
+ if (!space || !context) {
324
+ return;
325
+ }
326
+ const id = dxn.asEchoDXN();
327
+ const object = id && await space.db.getObjectById(id.echoId);
328
+ if (!object) {
329
+ log2.warn("Object not found", {
330
+ dxn,
331
+ id
332
+ }, {
333
+ F: __dxlog_file2,
334
+ L: 40,
335
+ S: void 0,
336
+ C: (f, a) => f(...a)
337
+ });
338
+ return;
339
+ }
340
+ const ref = Ref2.fromDXN(dxn);
341
+ if (checked) {
342
+ await context.bind({
343
+ objects: [
344
+ ref
345
+ ]
346
+ });
347
+ } else {
348
+ await context.unbind({
349
+ objects: [
350
+ ref
351
+ ]
352
+ });
353
+ }
354
+ }, [
355
+ space,
356
+ context
357
+ ]);
358
+ return {
359
+ objects,
360
+ onUpdateObject: handleUpdateObject
361
+ };
362
+ } finally {
363
+ _effect.f();
364
+ }
365
+ };
366
+
367
+ // src/hooks/useFlush.ts
368
+ import { useCallback as useCallback3, useRef, useState as useState4 } from "react";
369
+ var useFlush = (space) => {
370
+ const [state, setState] = useState4("idle");
371
+ const resetTimer = useRef(null);
372
+ const handleFlush = useCallback3(() => {
373
+ if (!space) {
374
+ return;
375
+ }
376
+ queueMicrotask(async () => {
377
+ if (resetTimer.current) {
378
+ clearTimeout(resetTimer.current);
379
+ }
380
+ setState("flushing");
381
+ await space.db.flush();
382
+ setState("flushed");
383
+ resetTimer.current = setTimeout(() => {
384
+ setState("idle");
385
+ resetTimer.current = null;
386
+ }, 1e3);
387
+ });
388
+ }, [
389
+ space
390
+ ]);
391
+ return {
392
+ state,
393
+ handleFlush
394
+ };
395
+ };
396
+
397
+ // src/hooks/useItemTypes.ts
398
+ import * as Option from "effect/Option";
399
+ import { useEffect, useState as useState5 } from "react";
400
+ import { ItemAnnotation } from "@dxos/schema";
401
+ var useItemTypes = (space) => {
402
+ const [types, setTypes] = useState5([]);
403
+ useEffect(() => {
404
+ if (!space) {
405
+ return;
406
+ }
407
+ return space.db.schemaRegistry.query().subscribe((query) => {
408
+ const types2 = Array.from(new Set([
409
+ ...space.db.graph.schemaRegistry.schemas,
410
+ ...query.results
411
+ ].filter((type) => Option.isSome(ItemAnnotation.get(type)))));
412
+ setTypes(types2);
413
+ }, {
414
+ fire: true
415
+ });
416
+ }, [
417
+ space
418
+ ]);
419
+ return types;
420
+ };
421
+
422
+ // src/hooks/useOnline.ts
423
+ import { useState as useState6 } from "react";
424
+ var useOnline = () => {
425
+ const [online, setOnline] = useState6(true);
426
+ return [
427
+ online,
428
+ setOnline
429
+ ];
430
+ };
431
+
432
+ // src/hooks/usePresets.ts
433
+ import { useCallback as useCallback4, useEffect as useEffect2, useMemo as useMemo4, useState as useState7 } from "react";
434
+ var usePresets = (online) => {
435
+ const [preset, setPreset] = useState7();
436
+ const presets = useMemo4(() => AiServicePresets.filter((preset2) => online === (preset2.provider === "dxos-remote")), [
437
+ online
438
+ ]);
439
+ const presetOptions = useMemo4(() => presets.map(({ id, model, label }) => ({
440
+ id,
441
+ label: label ?? model
442
+ })), [
443
+ presets
444
+ ]);
445
+ useEffect2(() => {
446
+ setPreset(presets[0]);
447
+ }, [
448
+ presets
449
+ ]);
450
+ const handlePresetChange = useCallback4((id) => {
451
+ const preset2 = presets.find((preset3) => preset3.id === id);
452
+ if (preset2) {
453
+ setPreset(preset2);
454
+ }
455
+ }, [
456
+ presets
457
+ ]);
458
+ return {
459
+ preset,
460
+ presets: presetOptions,
461
+ onPresetChange: handlePresetChange
462
+ };
463
+ };
464
+
465
+ // src/hooks/useReferencesProvider.ts
466
+ import { useMemo as useMemo5 } from "react";
467
+ import { Capabilities as Capabilities2 } from "@dxos/app-framework";
468
+ import { useCapabilities as useCapabilities2 } from "@dxos/app-framework/react";
469
+ import { Filter as Filter2, Obj as Obj2 } from "@dxos/echo";
470
+ var useReferencesProvider = (space) => {
471
+ const blueprints = useCapabilities2(Capabilities2.BlueprintDefinition);
472
+ return useMemo5(() => {
473
+ if (!space) {
474
+ return void 0;
475
+ }
476
+ return {
477
+ getReferences: async ({ query }) => {
478
+ const { objects } = await space.db.query(Filter2.everything()).run();
479
+ return objects.filter((object) => stringMatch(query, Obj2.getLabel(object) ?? "")).filter((object) => !!Obj2.getDXN(object)).map((object) => ({
480
+ uri: Obj2.getDXN(object).toString(),
481
+ label: Obj2.getLabel(object) ?? ""
482
+ }));
483
+ },
484
+ resolveReference: async ({ uri }) => {
485
+ const object = await space.db.query(Filter2.ids(uri)).first();
486
+ return {
487
+ uri,
488
+ label: Obj2.getLabel(object) ?? ""
489
+ };
490
+ }
491
+ };
492
+ }, [
493
+ space,
494
+ blueprints
495
+ ]);
496
+ };
497
+ var stringMatch = (query, label) => label.toLowerCase().startsWith(query.toLowerCase());
498
+
499
+ // src/components/ChatPrompt/ChatActions.tsx
500
+ import { useSignals as _useSignals4 } from "@preact-signals/safe-react/tracking";
501
+ import React2 from "react";
502
+ import { IconButton, useTranslation as useTranslation2 } from "@dxos/react-ui";
503
+ import { mx } from "@dxos/react-ui-theme";
504
+ var ChatActions = ({ classNames, children, microphone, recording, processing, onEvent }) => {
505
+ var _effect = _useSignals4();
506
+ try {
507
+ const { t } = useTranslation2(meta.id);
508
+ return /* @__PURE__ */ React2.createElement("div", {
509
+ className: mx("flex items-center mie-1", classNames)
510
+ }, children, /* @__PURE__ */ React2.createElement(IconButton, {
511
+ disabled: !processing,
512
+ variant: "ghost",
513
+ icon: "ph--x--regular",
514
+ iconOnly: true,
515
+ label: t("cancel processing button"),
516
+ onClick: () => onEvent?.({
517
+ type: "cancel"
518
+ })
519
+ }), microphone && /* @__PURE__ */ React2.createElement(IconButton, {
520
+ disabled: !processing,
521
+ classNames: mx(recording && "bg-primary-500"),
522
+ variant: "ghost",
523
+ icon: "ph--microphone--regular",
524
+ iconOnly: true,
525
+ noTooltip: true,
526
+ label: t("microphone button"),
527
+ onMouseDown: () => onEvent?.({
528
+ type: "record-start"
529
+ }),
530
+ onMouseUp: () => onEvent?.({
531
+ type: "record-stop"
532
+ }),
533
+ onTouchStart: () => onEvent?.({
534
+ type: "record-start"
535
+ }),
536
+ onTouchEnd: () => onEvent?.({
537
+ type: "record-stop"
538
+ })
539
+ }));
540
+ } finally {
541
+ _effect.f();
542
+ }
543
+ };
544
+
545
+ // src/components/ChatPrompt/ChatOptions.tsx
546
+ import { useSignals as _useSignals5 } from "@preact-signals/safe-react/tracking";
547
+ import React3, { useMemo as useMemo6, useState as useState8 } from "react";
548
+ import { Filter as Filter3, Obj as Obj3, Type } from "@dxos/echo";
549
+ import { useQuery as useQuery2 } from "@dxos/react-client/echo";
550
+ import { Icon, IconButton as IconButton2, Popover, Select as Select2, useTranslation as useTranslation3 } from "@dxos/react-ui";
551
+ import { Listbox, SearchList } from "@dxos/react-ui-searchlist";
552
+ import { Tabs } from "@dxos/react-ui-tabs";
553
+ var panelClassNames = "is-[calc(100dvw-.5rem)] sm:is-max md:is-72 max-is-[--text-content]";
554
+ var ChatOptions = ({ space, context, blueprintRegistry, presets, preset, onPresetChange }) => {
555
+ var _effect = _useSignals5();
556
+ try {
557
+ const { t } = useTranslation3(meta.id);
558
+ return /* @__PURE__ */ React3.createElement("div", {
559
+ role: "none",
560
+ className: "flex p-2"
561
+ }, /* @__PURE__ */ React3.createElement(Popover.Root, null, /* @__PURE__ */ React3.createElement(Popover.Trigger, {
562
+ asChild: true
563
+ }, /* @__PURE__ */ React3.createElement(IconButton2, {
564
+ variant: "ghost",
565
+ icon: "ph--plus--regular",
566
+ iconOnly: true,
567
+ label: t("context objects button")
568
+ })), /* @__PURE__ */ React3.createElement(Popover.Portal, null, /* @__PURE__ */ React3.createElement(Popover.Content, {
569
+ side: "top",
570
+ classNames: panelClassNames
571
+ }, /* @__PURE__ */ React3.createElement(Popover.Viewport, null, /* @__PURE__ */ React3.createElement(ObjectsPanel, {
572
+ space,
573
+ context
574
+ })), /* @__PURE__ */ React3.createElement(Popover.Arrow, null)))), /* @__PURE__ */ React3.createElement(Popover.Root, null, /* @__PURE__ */ React3.createElement(Popover.Trigger, {
575
+ asChild: true
576
+ }, /* @__PURE__ */ React3.createElement(IconButton2, {
577
+ variant: "ghost",
578
+ icon: "ph--sliders-horizontal--regular",
579
+ iconOnly: true,
580
+ label: t("context settings button")
581
+ })), /* @__PURE__ */ React3.createElement(Popover.Portal, null, /* @__PURE__ */ React3.createElement(Popover.Content, {
582
+ side: "top",
583
+ classNames: panelClassNames
584
+ }, /* @__PURE__ */ React3.createElement(Popover.Viewport, null, /* @__PURE__ */ React3.createElement(Tabs.Root, {
585
+ orientation: "horizontal",
586
+ defaultValue: "blueprints",
587
+ defaultActivePart: "list",
588
+ tabIndex: -1
589
+ }, /* @__PURE__ */ React3.createElement(Tabs.Viewport, {
590
+ classNames: 'max-bs-[--radix-popover-content-available-height] grid grid-rows-[1fr_min-content] [&_[cmdk-root]]:contents [&_[role="tabpanel"]]:grid [&_[role="tabpanel"]]:grid-rows-[1fr_min-content] [&_[role="listbox"]]:min-bs-0 [&_[role="listbox"]]:overflow-y-auto [&_[role="tabpanel"]]:min-bs-0 [&_[role="tabpanel"]]:pli-cardSpacingChrome [&_[role="tabpanel"][data-state="active"]]:order-first [&_[role="tabpanel"][data-state="inactive"]]:hidden'
591
+ }, /* @__PURE__ */ React3.createElement(Tabs.Tabpanel, {
592
+ value: "blueprints",
593
+ tabIndex: -1,
594
+ classNames: "dx-focus-ring-inset"
595
+ }, /* @__PURE__ */ React3.createElement(BlueprintsPanel, {
596
+ blueprintRegistry,
597
+ space,
598
+ context
599
+ })), /* @__PURE__ */ React3.createElement(Tabs.Tabpanel, {
600
+ value: "model",
601
+ tabIndex: -1,
602
+ classNames: "dx-focus-ring-inset !pli-0"
603
+ }, /* @__PURE__ */ React3.createElement(ModelsPanel, {
604
+ presets,
605
+ preset,
606
+ onPresetChange
607
+ })), /* @__PURE__ */ React3.createElement(Tabs.Tablist, {
608
+ classNames: "sm:overflow-x-hidden justify-center p-[--dx-cardSpacingChrome] border-bs border-subduedSeparator order-last"
609
+ }, /* @__PURE__ */ React3.createElement(Tabs.IconTab, {
610
+ value: "blueprints",
611
+ icon: "ph--blueprint--regular",
612
+ label: t("blueprints in context title")
613
+ }), /* @__PURE__ */ React3.createElement(Tabs.IconTab, {
614
+ value: "model",
615
+ label: t("chat model title"),
616
+ icon: "ph--cpu--regular"
617
+ }))))), /* @__PURE__ */ React3.createElement(Popover.Arrow, null)))));
618
+ } finally {
619
+ _effect.f();
620
+ }
621
+ };
622
+ var BlueprintsPanel = ({ blueprintRegistry, space, context }) => {
623
+ var _effect = _useSignals5();
624
+ try {
625
+ const { t } = useTranslation3(meta.id);
626
+ const blueprints = useBlueprints({
627
+ blueprintRegistry,
628
+ space
629
+ });
630
+ const activeBlueprints = useActiveBlueprints({
631
+ context
632
+ });
633
+ const { onUpdateBlueprint } = useBlueprintHandlers({
634
+ space,
635
+ context,
636
+ blueprintRegistry
637
+ });
638
+ return /* @__PURE__ */ React3.createElement(SearchList.Root, null, /* @__PURE__ */ React3.createElement(SearchList.Content, {
639
+ classNames: "plb-cardSpacingChrome"
640
+ }, blueprints.map((blueprint) => {
641
+ const isActive = activeBlueprints.has(blueprint.key);
642
+ return /* @__PURE__ */ React3.createElement(SearchList.Item, {
643
+ classNames: "flex items-center overflow-hidden",
644
+ key: blueprint.key,
645
+ value: blueprint.name,
646
+ onSelect: () => onUpdateBlueprint?.(blueprint.key, !isActive)
647
+ }, /* @__PURE__ */ React3.createElement("div", {
648
+ className: "grow truncate"
649
+ }, blueprint.name), /* @__PURE__ */ React3.createElement(Icon, {
650
+ icon: "ph--check--regular",
651
+ classNames: [
652
+ !isActive && "invisible"
653
+ ]
654
+ }));
655
+ })), /* @__PURE__ */ React3.createElement(SearchList.Input, {
656
+ placeholder: t("search placeholder"),
657
+ classNames: "mbe-cardSpacingChrome",
658
+ autoFocus: true
659
+ }));
660
+ } finally {
661
+ _effect.f();
662
+ }
663
+ };
664
+ var ModelsPanel = ({ presets, preset, onPresetChange }) => {
665
+ var _effect = _useSignals5();
666
+ try {
667
+ return /* @__PURE__ */ React3.createElement(Listbox.Root, {
668
+ value: preset,
669
+ onValueChange: onPresetChange,
670
+ autoFocus: true
671
+ }, presets?.map(({ id, label }) => {
672
+ return /* @__PURE__ */ React3.createElement(Listbox.Option, {
673
+ key: id,
674
+ value: id
675
+ }, /* @__PURE__ */ React3.createElement(Listbox.OptionLabel, null, label), /* @__PURE__ */ React3.createElement(Listbox.OptionIndicator, null));
676
+ }));
677
+ } finally {
678
+ _effect.f();
679
+ }
680
+ };
681
+ var ANY = "__any__";
682
+ var ObjectsPanel = ({ space, context }) => {
683
+ var _effect = _useSignals5();
684
+ try {
685
+ const { t } = useTranslation3(meta.id);
686
+ const types = useItemTypes(space);
687
+ const typenames = useMemo6(() => {
688
+ const typenames2 = types.map((type) => {
689
+ const typename2 = Type.getTypename(type);
690
+ return {
691
+ typename: typename2,
692
+ label: t("typename label", {
693
+ ns: typename2,
694
+ defaultValue: typename2
695
+ })
696
+ };
697
+ });
698
+ typenames2.sort((a, b) => a.label.localeCompare(b.label));
699
+ return typenames2;
700
+ }, [
701
+ types
702
+ ]);
703
+ const [typename, setTypename] = useState8(ANY);
704
+ const anyFilter = useMemo6(() => Filter3.or(...typenames.map(({ typename: typename2 }) => Filter3.typename(typename2))), [
705
+ typenames
706
+ ]);
707
+ const objects = useQuery2(space, typename === ANY ? anyFilter : Filter3.typename(typename));
708
+ const { objects: contextObjects, onUpdateObject } = useContextObjects({
709
+ space,
710
+ context
711
+ });
712
+ return /* @__PURE__ */ React3.createElement(SearchList.Root, null, /* @__PURE__ */ React3.createElement(SearchList.Content, {
713
+ classNames: "p-cardSpacingChrome [&:has([cmdk-list-sizer]:empty)]:plb-0"
714
+ }, objects.length ? objects.map((object) => {
715
+ const label = Obj3.getLabel(object) ?? Obj3.getTypename(object) ?? object.id;
716
+ const isActive = contextObjects.findIndex((obj) => obj.id === object.id) !== -1;
717
+ return /* @__PURE__ */ React3.createElement(SearchList.Item, {
718
+ classNames: "flex items-center overflow-hidden",
719
+ key: object.id,
720
+ value: object.id,
721
+ onSelect: () => onUpdateObject?.(Obj3.getDXN(object), !isActive)
722
+ }, /* @__PURE__ */ React3.createElement("div", {
723
+ className: "grow truncate"
724
+ }, label), /* @__PURE__ */ React3.createElement(Icon, {
725
+ icon: "ph--check--regular",
726
+ classNames: [
727
+ !isActive && "invisible"
728
+ ]
729
+ }));
730
+ }) : /* @__PURE__ */ React3.createElement(SearchList.Item, null, t("no results"))), /* @__PURE__ */ React3.createElement("div", {
731
+ role: "none",
732
+ className: "grid grid-cols-[min-content_1fr] gap-2 pli-cardSpacingChrome mbe-cardSpacingChrome"
733
+ }, /* @__PURE__ */ React3.createElement(Select2.Root, {
734
+ value: typename === ANY ? void 0 : typename,
735
+ onValueChange: setTypename
736
+ }, /* @__PURE__ */ React3.createElement(Select2.TriggerButton, {
737
+ density: "fine",
738
+ placeholder: t("type filter placeholder")
739
+ }), /* @__PURE__ */ React3.createElement(Select2.Portal, null, /* @__PURE__ */ React3.createElement(Select2.Content, null, /* @__PURE__ */ React3.createElement(Select2.ScrollUpButton, null), /* @__PURE__ */ React3.createElement(Select2.Viewport, null, /* @__PURE__ */ React3.createElement(Select2.Option, {
740
+ value: ANY
741
+ }, t("any type filter label")), typenames.map(({ typename: typename2, label }) => /* @__PURE__ */ React3.createElement(Select2.Option, {
742
+ key: typename2,
743
+ value: typename2
744
+ }, label))), /* @__PURE__ */ React3.createElement(Select2.ScrollDownButton, null), /* @__PURE__ */ React3.createElement(Select2.Arrow, null)))), /* @__PURE__ */ React3.createElement(SearchList.Input, {
745
+ placeholder: t("search placeholder"),
746
+ classNames: "mbe-0",
747
+ autoFocus: true
748
+ })));
749
+ } finally {
750
+ _effect.f();
751
+ }
752
+ };
753
+
754
+ // src/components/ChatPrompt/ChatPresets.tsx
755
+ import { useSignals as _useSignals6 } from "@preact-signals/safe-react/tracking";
756
+ import React4 from "react";
757
+ import { Select as Select3 } from "@dxos/react-ui";
758
+
759
+ // src/components/ChatPrompt/ChatReferences.tsx
760
+ import { useSignals as _useSignals7 } from "@preact-signals/safe-react/tracking";
761
+ import React5 from "react";
762
+ import { Obj as Obj4 } from "@dxos/echo";
763
+ import { IconButton as IconButton3, toLocalizedString, useTranslation as useTranslation4 } from "@dxos/react-ui";
764
+ import { mx as mx2 } from "@dxos/react-ui-theme";
765
+ var ChatReferences = ({ classNames, context, space }) => {
766
+ var _effect = _useSignals7();
767
+ try {
768
+ const { t } = useTranslation4(meta.id);
769
+ const { objects, onUpdateObject } = useContextObjects({
770
+ space,
771
+ context
772
+ });
773
+ return /* @__PURE__ */ React5.createElement("ul", {
774
+ className: mx2("flex", classNames)
775
+ }, objects.map((obj) => {
776
+ const dxn = Obj4.getDXN(obj);
777
+ const typename = Obj4.getTypename(obj);
778
+ const label = Obj4.getLabel(obj) ?? (typename ? [
779
+ "object name placeholder",
780
+ {
781
+ ns: typename
782
+ }
783
+ ] : obj.id);
784
+ return /* @__PURE__ */ React5.createElement("li", {
785
+ key: dxn.toString(),
786
+ className: "dx-tag plb-0 pis-2 flex items-center",
787
+ "data-hue": "neutral"
788
+ }, toLocalizedString(label, t), /* @__PURE__ */ React5.createElement(IconButton3, {
789
+ icon: "ph--x--bold",
790
+ iconOnly: true,
791
+ variant: "ghost",
792
+ label: t("remove object in context label"),
793
+ classNames: "p-0 hover:bg-transparent",
794
+ size: 3,
795
+ onClick: () => onUpdateObject?.(dxn, false)
796
+ }));
797
+ }));
798
+ } finally {
799
+ _effect.f();
800
+ }
801
+ };
802
+
803
+ // src/components/ChatPrompt/ChatStatusIndicator.tsx
804
+ import { useSignals as _useSignals8 } from "@preact-signals/safe-react/tracking";
805
+ import React6, { useEffect as useEffect3, useState as useState9 } from "react";
806
+ import { Tooltip, useTimeout } from "@dxos/react-ui";
807
+ import { Spinner } from "@dxos/react-ui-sfx";
808
+ import { mx as mx3 } from "@dxos/react-ui-theme";
809
+ var period = 3e3;
810
+ var ChatStatusIndicator = ({ classNames, preset, processing, error, ...props }) => {
811
+ var _effect = _useSignals8();
812
+ try {
813
+ const [init, setInit] = useState9(false);
814
+ useEffect3(() => setInit(false), [
815
+ preset
816
+ ]);
817
+ useTimeout(async () => {
818
+ setInit(true);
819
+ }, period / 2, [
820
+ preset
821
+ ]);
822
+ return /* @__PURE__ */ React6.createElement("div", {
823
+ role: "none",
824
+ className: mx3("relative flex", classNames)
825
+ }, /* @__PURE__ */ React6.createElement(Spinner, {
826
+ duration: period,
827
+ state: !init ? "flash" : error ? "error" : processing ? "spin" : "pulse",
828
+ ...props
829
+ }), error && /* @__PURE__ */ React6.createElement(Tooltip.Trigger, {
830
+ asChild: true,
831
+ content: error.message
832
+ }, /* @__PURE__ */ React6.createElement("div", {
833
+ className: "absolute inset-0"
834
+ })));
835
+ } finally {
836
+ _effect.f();
837
+ }
838
+ };
839
+
840
+ // src/components/ChatThread/ChatThread.tsx
841
+ import { useSignals as _useSignals11 } from "@preact-signals/safe-react/tracking";
842
+ import React9, { forwardRef, useCallback as useCallback6, useEffect as useEffect5, useMemo as useMemo8 } from "react";
843
+ import { PublicKey } from "@dxos/keys";
844
+ import { useForwardedRef } from "@dxos/react-ui";
845
+ import { MarkdownStream } from "@dxos/react-ui-components";
846
+ import { mx as mx4 } from "@dxos/react-ui-theme";
847
+ import { keyToFallback } from "@dxos/util";
848
+
849
+ // src/components/ChatThread/registry.tsx
850
+ import { useSignals as _useSignals10 } from "@preact-signals/safe-react/tracking";
851
+ import React8 from "react";
852
+ import { log as log3 } from "@dxos/log";
853
+ import { PromptWidget, ReferenceWidget, SelectWidget, SuggestionWidget, SummaryWidget, ToggleContainer as ToggleContainer2 } from "@dxos/react-ui-components";
854
+ import { getXmlTextChild } from "@dxos/react-ui-editor";
855
+ import { Json as Json2 } from "@dxos/react-ui-syntax-highlighter";
856
+ import { ContentBlock } from "@dxos/types";
857
+
858
+ // src/components/ToolBlock/ToolBlock.tsx
859
+ import { useSignals as _useSignals9 } from "@preact-signals/safe-react/tracking";
860
+ import React7, { useCallback as useCallback5, useEffect as useEffect4, useMemo as useMemo7, useRef as useRef2, useState as useState10 } from "react";
861
+ import { useTranslation as useTranslation5 } from "@dxos/react-ui";
862
+ import { NumericTabs, TextCrawl, ToggleContainer } from "@dxos/react-ui-components";
863
+ import { Json } from "@dxos/react-ui-syntax-highlighter";
864
+ import { isNonNullable as isNonNullable3, safeParseJson } from "@dxos/util";
865
+ var ToolBlock = ({ view, blocks = [] }) => {
866
+ var _effect = _useSignals9();
867
+ try {
868
+ const { t } = useTranslation5(meta.id);
869
+ const items = useMemo7(() => {
870
+ let lastToolCall;
871
+ const tools = [];
872
+ return blocks.filter((block) => block._tag === "toolCall" || block._tag === "toolResult" || block._tag === "summary").map((block) => {
873
+ switch (block._tag) {
874
+ case "toolCall": {
875
+ if (block.pending && lastToolCall?.block.toolCallId === block.toolCallId) {
876
+ return null;
877
+ }
878
+ const tool = tools.find((tool2) => tool2.name === block.name);
879
+ lastToolCall = {
880
+ tool,
881
+ block
882
+ };
883
+ return {
884
+ title: tool?.description ?? [
885
+ t("tool call label"),
886
+ tool?.name
887
+ ].join(" "),
888
+ content: {
889
+ ...block,
890
+ input: safeParseJson(block.input)
891
+ }
892
+ };
893
+ }
894
+ case "toolResult": {
895
+ if (block.error) {
896
+ return {
897
+ title: t("tool error label"),
898
+ content: block
899
+ };
900
+ }
901
+ const title = lastToolCall?.tool?.description ?? [
902
+ t("tool result label"),
903
+ lastToolCall?.tool?.name
904
+ ].join(" ");
905
+ lastToolCall = void 0;
906
+ return {
907
+ title,
908
+ content: {
909
+ ...block,
910
+ result: safeParseJson(block.result)
911
+ }
912
+ };
913
+ }
914
+ case "summary": {
915
+ if (!lastToolCall) {
916
+ return null;
917
+ }
918
+ return {
919
+ title: t("summary label"),
920
+ content: block
921
+ };
922
+ }
923
+ }
924
+ }).filter(isNonNullable3);
925
+ }, [
926
+ blocks
927
+ ]);
928
+ const handleChangeOpen = useCallback5(() => {
929
+ setTimeout(() => {
930
+ view?.requestMeasure();
931
+ }, 1e3);
932
+ }, [
933
+ view
934
+ ]);
935
+ if (!items.length) {
936
+ return null;
937
+ }
938
+ return /* @__PURE__ */ React7.createElement(ToolContainer, {
939
+ items,
940
+ onChangeOpen: handleChangeOpen
941
+ });
942
+ } finally {
943
+ _effect.f();
944
+ }
945
+ };
946
+ ToolBlock.displayName = "ToolBlock";
947
+ var ToolContainer = ({ items, onChangeOpen }) => {
948
+ var _effect = _useSignals9();
949
+ try {
950
+ const tabsRef = useRef2(null);
951
+ const [selected, setSelected] = useState10(0);
952
+ const [open, setOpen] = useState10(false);
953
+ useEffect4(() => {
954
+ onChangeOpen?.(open);
955
+ if (open) {
956
+ tabsRef.current?.focus();
957
+ }
958
+ }, [
959
+ onChangeOpen,
960
+ open
961
+ ]);
962
+ const handleSelect = (index) => {
963
+ setSelected(index);
964
+ };
965
+ return /* @__PURE__ */ React7.createElement(ToggleContainer.Root, {
966
+ classNames: "mbs-2 is-full rounded-sm",
967
+ open,
968
+ onChangeOpen: setOpen
969
+ }, /* @__PURE__ */ React7.createElement(ToggleContainer.Header, {
970
+ classNames: "text-sm text-placeholder"
971
+ }, /* @__PURE__ */ React7.createElement(TextCrawl, {
972
+ key: "status-roll",
973
+ lines: items.map((item) => item.title),
974
+ autoAdvance: true,
975
+ greedy: true
976
+ })), /* @__PURE__ */ React7.createElement(ToggleContainer.Content, {
977
+ classNames: "grid grid-cols-[32px_1fr]"
978
+ }, /* @__PURE__ */ React7.createElement(NumericTabs, {
979
+ ref: tabsRef,
980
+ classNames: "p-1",
981
+ length: items.length,
982
+ selected,
983
+ onSelect: handleSelect
984
+ }), /* @__PURE__ */ React7.createElement(Json, {
985
+ data: items[selected]?.content,
986
+ classNames: "p-1 text-xs bg-transparent",
987
+ replacer: {
988
+ maxDepth: 3,
989
+ maxArrayLen: 10,
990
+ maxStringLen: 128
991
+ }
992
+ })));
993
+ } finally {
994
+ _effect.f();
995
+ }
996
+ };
997
+
998
+ // src/components/ChatThread/registry.tsx
999
+ var __dxlog_file3 = "/__w/dxos/dxos/packages/plugins/plugin-assistant/src/components/ChatThread/registry.tsx";
1000
+ var Fallback = ({ _tag, ...props }) => {
1001
+ var _effect = _useSignals10();
1002
+ try {
1003
+ return /* @__PURE__ */ React8.createElement(ToggleContainer2.Root, {
1004
+ classNames: "rounded-sm"
1005
+ }, /* @__PURE__ */ React8.createElement(ToggleContainer2.Header, {
1006
+ classNames: "bg-groupSurface"
1007
+ }, _tag), /* @__PURE__ */ React8.createElement(ToggleContainer2.Content, {
1008
+ classNames: "bg-modalSurface"
1009
+ }, /* @__PURE__ */ React8.createElement(Json2, {
1010
+ classNames: "!p-2 text-sm",
1011
+ data: props
1012
+ })));
1013
+ } finally {
1014
+ _effect.f();
1015
+ }
1016
+ };
1017
+ var componentRegistry = {
1018
+ //
1019
+ // Widgets
1020
+ //
1021
+ ["prompt"]: {
1022
+ block: true,
1023
+ factory: ({ children }) => {
1024
+ const text = getXmlTextChild(children);
1025
+ return text ? new PromptWidget(text) : null;
1026
+ }
1027
+ },
1028
+ ["reference"]: {
1029
+ block: false,
1030
+ factory: ({ children, ref }) => {
1031
+ const text = getXmlTextChild(children);
1032
+ return text && ref ? new ReferenceWidget(text, ref) : null;
1033
+ }
1034
+ },
1035
+ ["select"]: {
1036
+ block: true,
1037
+ factory: ({ children }) => {
1038
+ const options = children?.map((option) => option._tag === "option" && getXmlTextChild(option.children)).filter(Boolean);
1039
+ return options?.length ? new SelectWidget(options) : null;
1040
+ }
1041
+ },
1042
+ ["suggestion"]: {
1043
+ block: true,
1044
+ factory: ({ children }) => {
1045
+ const text = getXmlTextChild(children);
1046
+ return text ? new SuggestionWidget(text) : null;
1047
+ }
1048
+ },
1049
+ ["summary"]: {
1050
+ block: true,
1051
+ factory: ({ children }) => {
1052
+ const text = getXmlTextChild(children);
1053
+ return text ? new SummaryWidget(text) : null;
1054
+ }
1055
+ },
1056
+ //
1057
+ // React
1058
+ //
1059
+ ["toolCall"]: {
1060
+ block: true,
1061
+ Component: ToolBlock
1062
+ },
1063
+ ["toolResult"]: {
1064
+ block: true,
1065
+ Component: Fallback
1066
+ },
1067
+ ["toolkit"]: {
1068
+ block: true,
1069
+ Component: Fallback
1070
+ },
1071
+ //
1072
+ // Fallback
1073
+ //
1074
+ ["json"]: {
1075
+ block: true,
1076
+ Component: Fallback
1077
+ }
1078
+ };
1079
+ var blockToMarkdown = (context, message, block) => {
1080
+ let str = blockToMarkdownImpl(context, message, block);
1081
+ if (str && !block.pending) {
1082
+ return str += "\n";
1083
+ }
1084
+ return str;
1085
+ };
1086
+ var blockToMarkdownImpl = (context, message, block) => {
1087
+ log3("blockToMarkdown", {
1088
+ block: JSON.stringify(block)
1089
+ }, {
1090
+ F: __dxlog_file3,
1091
+ L: 125,
1092
+ S: void 0,
1093
+ C: (f, a) => f(...a)
1094
+ });
1095
+ switch (block._tag) {
1096
+ case "text": {
1097
+ if (message.sender.role === "user") {
1098
+ return `<prompt>${block.text}</prompt>`;
1099
+ } else {
1100
+ const text = block.text.trim();
1101
+ if (text.length > 0) {
1102
+ return text;
1103
+ }
1104
+ }
1105
+ break;
1106
+ }
1107
+ case "reference": {
1108
+ const dxn = block.reference.dxn;
1109
+ return `<reference ref="${dxn.toString()}">${context.getObjectLabel(dxn)}</reference>`;
1110
+ }
1111
+ case "suggestion": {
1112
+ if (block.pending) {
1113
+ return;
1114
+ }
1115
+ return `<suggestion>${block.text}</suggestion>`;
1116
+ }
1117
+ case "select": {
1118
+ if (block.pending || block.options.length === 0) {
1119
+ return;
1120
+ }
1121
+ return `<select>${block.options.map((option) => `<option>${option}</option>`).join("")}</select>`;
1122
+ }
1123
+ case "toolCall": {
1124
+ context.updateWidget(block.toolCallId, {
1125
+ blocks: [
1126
+ block
1127
+ ]
1128
+ });
1129
+ return `<toolCall id="${block.toolCallId}" />`;
1130
+ }
1131
+ case "toolResult": {
1132
+ context.updateWidget(block.toolCallId, ({ blocks = [] }) => ({
1133
+ blocks: [
1134
+ ...blocks,
1135
+ block
1136
+ ]
1137
+ }));
1138
+ break;
1139
+ }
1140
+ case "summary": {
1141
+ return `<summary>${ContentBlock.createSummaryMessage(block)}</summary>`;
1142
+ }
1143
+ default: {
1144
+ return `<json id="${message.id}">
1145
+ ${JSON.stringify(block)}
1146
+ </json>`;
1147
+ }
1148
+ }
1149
+ };
1150
+
1151
+ // src/components/ChatThread/sync.ts
1152
+ import { log as log4 } from "@dxos/log";
1153
+ var __dxlog_file4 = "/__w/dxos/dxos/packages/plugins/plugin-assistant/src/components/ChatThread/sync.ts";
1154
+ var MessageThreadContext = class {
1155
+ _widgetState;
1156
+ constructor(_widgetState) {
1157
+ this._widgetState = _widgetState;
1158
+ }
1159
+ updateWidget(id, value) {
1160
+ this._widgetState?.updateWidget(id, value);
1161
+ }
1162
+ // TODO(burdon): Resolve from hypergraph.
1163
+ getObjectLabel(_id) {
1164
+ return "Object";
1165
+ }
1166
+ };
1167
+ var MessageSyncer = class {
1168
+ _model;
1169
+ _blockRenderer;
1170
+ _initialMessageId;
1171
+ _currentMessageIndex = 0;
1172
+ _currentBlockIndex = 0;
1173
+ _currentBlockContent;
1174
+ _context;
1175
+ constructor(_model, _blockRenderer) {
1176
+ this._model = _model;
1177
+ this._blockRenderer = _blockRenderer;
1178
+ this._context = new MessageThreadContext(this._model);
1179
+ }
1180
+ get context() {
1181
+ return this._context;
1182
+ }
1183
+ reset() {
1184
+ log4("reset", void 0, {
1185
+ F: __dxlog_file4,
1186
+ L: 64,
1187
+ S: this,
1188
+ C: (f, a) => f(...a)
1189
+ });
1190
+ this._initialMessageId = void 0;
1191
+ this._currentMessageIndex = 0;
1192
+ this._currentBlockIndex = 0;
1193
+ this._currentBlockContent = void 0;
1194
+ void this._model.reset("");
1195
+ }
1196
+ /**
1197
+ * Syncs messages with the editor.
1198
+ */
1199
+ append(messages, flush = false) {
1200
+ if (this._initialMessageId !== messages[0]?.id) {
1201
+ this.reset();
1202
+ this._initialMessageId = messages[0]?.id;
1203
+ }
1204
+ if (flush && this._model.view?.state.doc.length === 0) {
1205
+ const buffer = [];
1206
+ this.process(messages, (content2) => {
1207
+ buffer.push(content2);
1208
+ });
1209
+ const content = buffer.join("");
1210
+ this._model.view?.dispatch({
1211
+ changes: [
1212
+ {
1213
+ from: 0,
1214
+ to: this._model.view?.state.doc.length ?? 0,
1215
+ insert: content
1216
+ }
1217
+ ],
1218
+ selection: {
1219
+ anchor: content.length
1220
+ }
1221
+ });
1222
+ return true;
1223
+ } else {
1224
+ this.process(messages, (content) => {
1225
+ void this._model.append(content);
1226
+ });
1227
+ return false;
1228
+ }
1229
+ }
1230
+ process(messages, append) {
1231
+ log4("sync", {
1232
+ doc: this._model.view?.state.doc.length,
1233
+ messages: messages.map((message) => message.blocks.length),
1234
+ currentMessageIndex: this._currentMessageIndex,
1235
+ currentBlockIndex: this._currentBlockIndex,
1236
+ currentBlockContent: this._currentBlockContent
1237
+ }, {
1238
+ F: __dxlog_file4,
1239
+ L: 105,
1240
+ S: this,
1241
+ C: (f, a) => f(...a)
1242
+ });
1243
+ let i = this._currentMessageIndex;
1244
+ for (const message of messages.slice(this._currentMessageIndex)) {
1245
+ if (i > this._currentMessageIndex) {
1246
+ this._currentBlockIndex = 0;
1247
+ }
1248
+ this._currentMessageIndex = i;
1249
+ let j = this._currentBlockIndex;
1250
+ for (const block of message.blocks.slice(this._currentBlockIndex)) {
1251
+ this._currentBlockIndex = j;
1252
+ const currentBlockContent = this._blockRenderer(this._context, message, block);
1253
+ if (currentBlockContent) {
1254
+ let content = "";
1255
+ if (this._currentBlockContent && currentBlockContent.startsWith(this._currentBlockContent)) {
1256
+ content = currentBlockContent.slice(this._currentBlockContent.length);
1257
+ } else {
1258
+ content = currentBlockContent;
1259
+ }
1260
+ log4("append", {
1261
+ message: i,
1262
+ block: j,
1263
+ content
1264
+ }, {
1265
+ F: __dxlog_file4,
1266
+ L: 132,
1267
+ S: this,
1268
+ C: (f, a) => f(...a)
1269
+ });
1270
+ this._currentBlockContent = currentBlockContent;
1271
+ append(content);
1272
+ }
1273
+ if (block.pending) {
1274
+ return;
1275
+ } else {
1276
+ this._currentBlockContent = void 0;
1277
+ this._currentBlockIndex++;
1278
+ }
1279
+ j++;
1280
+ }
1281
+ i++;
1282
+ }
1283
+ }
1284
+ };
1285
+
1286
+ // src/components/ChatThread/ChatThread.tsx
1287
+ var ChatThread = /* @__PURE__ */ forwardRef(({ classNames, identity, messages = [], error, cursor = false, fadeIn = true, debug = false, onEvent }, forwardedRef) => {
1288
+ var _effect = _useSignals11();
1289
+ try {
1290
+ const controllerRef = useForwardedRef(forwardedRef);
1291
+ const controller = controllerRef.current;
1292
+ const userHue = useMemo8(() => identity?.profile?.data?.hue || keyToFallback(identity?.identityKey ?? PublicKey.random()).hue, [
1293
+ identity
1294
+ ]);
1295
+ useEffect5(() => {
1296
+ controller?.scrollToBottom();
1297
+ }, [
1298
+ controller,
1299
+ error
1300
+ ]);
1301
+ const syncer = useMemo8(() => controller && new MessageSyncer(controller, blockToMarkdown), [
1302
+ controller
1303
+ ]);
1304
+ useEffect5(() => {
1305
+ const reset = syncer?.append(messages, true);
1306
+ if (reset) {
1307
+ controller?.scrollToBottom("instant");
1308
+ }
1309
+ }, [
1310
+ syncer,
1311
+ messages
1312
+ ]);
1313
+ const handleEvent = useCallback6(({ type, value }) => {
1314
+ switch (type) {
1315
+ case "submit": {
1316
+ value && onEvent?.({
1317
+ type,
1318
+ text: value
1319
+ });
1320
+ break;
1321
+ }
1322
+ }
1323
+ }, [
1324
+ onEvent
1325
+ ]);
1326
+ return /* @__PURE__ */ React9.createElement("div", {
1327
+ role: "none",
1328
+ className: mx4("flex bs-full is-full justify-center overflow-hidden", classNames),
1329
+ style: {
1330
+ "--user-fill": `var(--dx-${userHue}Fill)`
1331
+ }
1332
+ }, /* @__PURE__ */ React9.createElement(MarkdownStream, {
1333
+ ref: controllerRef,
1334
+ registry: componentRegistry,
1335
+ cursor,
1336
+ fadeIn,
1337
+ debug,
1338
+ onEvent: handleEvent
1339
+ }));
1340
+ } finally {
1341
+ _effect.f();
1342
+ }
1343
+ });
1344
+
1345
+ // src/components/Chat/Chat.tsx
1346
+ var [ChatContextProvider, useChatContext] = createContext("Chat");
1347
+ var ChatRoot = ({ children, chat, processor, onEvent, ...props }) => {
1348
+ var _effect = _useSignals12();
1349
+ try {
1350
+ const [debug, setDebug] = useState11(false);
1351
+ const pending = useAtomValue(processor.messages);
1352
+ const streaming = useAtomValue(processor.streaming);
1353
+ const lastPrompt = useRef3(void 0);
1354
+ const queue = useQueue(chat?.queue.dxn);
1355
+ const messages = useMemo9(() => {
1356
+ const queueMessages = queue?.objects?.filter(Obj5.instanceOf(Message.Message)) ?? [];
1357
+ return Array2.dedupeWith([
1358
+ ...queueMessages,
1359
+ ...pending
1360
+ ], ({ id: a }, { id: b }) => a === b);
1361
+ }, [
1362
+ queue?.objects,
1363
+ pending
1364
+ ]);
1365
+ const event = useMemo9(() => new Event(), []);
1366
+ useEffect6(() => {
1367
+ return event.on((ev) => {
1368
+ switch (ev.type) {
1369
+ case "toggle-debug": {
1370
+ setDebug((current) => !current);
1371
+ break;
1372
+ }
1373
+ case "submit": {
1374
+ const text = ev.text.trim();
1375
+ if (!streaming && text.length) {
1376
+ lastPrompt.current = ev.text;
1377
+ void processor.request({
1378
+ message: text
1379
+ });
1380
+ }
1381
+ break;
1382
+ }
1383
+ case "retry": {
1384
+ if (!streaming) {
1385
+ void processor.retry();
1386
+ }
1387
+ break;
1388
+ }
1389
+ case "cancel": {
1390
+ if (streaming) {
1391
+ void processor.cancel();
1392
+ if (lastPrompt.current) {
1393
+ event.emit({
1394
+ type: "update-prompt",
1395
+ text: lastPrompt.current
1396
+ });
1397
+ }
1398
+ }
1399
+ break;
1400
+ }
1401
+ }
1402
+ onEvent?.(ev);
1403
+ });
1404
+ }, [
1405
+ event,
1406
+ processor,
1407
+ streaming,
1408
+ onEvent
1409
+ ]);
1410
+ const space = props.space ?? getSpace(chat);
1411
+ return /* @__PURE__ */ React10.createElement(ChatContextProvider, {
1412
+ debug,
1413
+ event,
1414
+ space,
1415
+ chat,
1416
+ messages,
1417
+ processor,
1418
+ ...props
1419
+ }, children);
1420
+ } finally {
1421
+ _effect.f();
1422
+ }
1423
+ };
1424
+ ChatRoot.displayName = "Chat.Root";
1425
+ var ChatViewport = ({ classNames, children }) => {
1426
+ var _effect = _useSignals12();
1427
+ try {
1428
+ return /* @__PURE__ */ React10.createElement("div", {
1429
+ role: "none",
1430
+ className: mx5("flex flex-col bs-full is-full", classNames)
1431
+ }, children);
1432
+ } finally {
1433
+ _effect.f();
1434
+ }
1435
+ };
1436
+ var ChatPrompt = ({ classNames, outline, settings = true, placeholder, expandable, online, presets, preset, onPresetChange, onOnlineChange }) => {
1437
+ var _effect = _useSignals12();
1438
+ try {
1439
+ const { t } = useTranslation6(meta.id);
1440
+ const { space, processor, event } = useChatContext(ChatPrompt.displayName);
1441
+ const error = useAtomValue(processor.error).pipe(Option2.getOrUndefined);
1442
+ const streaming = useAtomValue(processor.streaming);
1443
+ const active = useAtomValue(processor.active);
1444
+ const activeRef = useDynamicRef(active);
1445
+ const editorRef = useRef3(null);
1446
+ const [recordingState, setRecordingState] = useState11(false);
1447
+ useEffect6(() => {
1448
+ return event.on((event2) => {
1449
+ switch (event2.type) {
1450
+ case "update-prompt":
1451
+ if (!editorRef.current?.getText()?.length) {
1452
+ editorRef.current?.setText(event2.text);
1453
+ editorRef.current?.focus();
1454
+ }
1455
+ break;
1456
+ case "record-start":
1457
+ setRecordingState(true);
1458
+ break;
1459
+ case "record-stop":
1460
+ setRecordingState(false);
1461
+ break;
1462
+ }
1463
+ });
1464
+ }, [
1465
+ event
1466
+ ]);
1467
+ const { recording } = useVoiceInput({
1468
+ active: recordingState,
1469
+ onUpdate: (text) => {
1470
+ editorRef.current?.setText(text);
1471
+ editorRef.current?.focus();
1472
+ }
1473
+ });
1474
+ const extensions = useMemo9(() => {
1475
+ return [
1476
+ Prec.highest(keymap.of([
1477
+ {
1478
+ key: "Mod-d",
1479
+ preventDefault: true,
1480
+ run: () => {
1481
+ event.emit({
1482
+ type: "toggle-debug"
1483
+ });
1484
+ return true;
1485
+ }
1486
+ },
1487
+ {
1488
+ key: "Mod-ArrowUp",
1489
+ preventDefault: true,
1490
+ run: () => {
1491
+ event.emit({
1492
+ type: "nav-previous"
1493
+ });
1494
+ return true;
1495
+ },
1496
+ shift: () => {
1497
+ event.emit({
1498
+ type: "thread-open"
1499
+ });
1500
+ return true;
1501
+ }
1502
+ },
1503
+ {
1504
+ key: "Mod-ArrowDown",
1505
+ preventDefault: true,
1506
+ run: () => {
1507
+ event.emit({
1508
+ type: "nav-next"
1509
+ });
1510
+ return true;
1511
+ },
1512
+ shift: () => {
1513
+ event.emit({
1514
+ type: "thread-close"
1515
+ });
1516
+ return true;
1517
+ }
1518
+ }
1519
+ ]))
1520
+ ].filter(isTruthy);
1521
+ }, [
1522
+ event,
1523
+ expandable
1524
+ ]);
1525
+ const handleSubmit = useCallback7((text) => {
1526
+ if (!activeRef.current) {
1527
+ event.emit({
1528
+ type: "submit",
1529
+ text
1530
+ });
1531
+ return true;
1532
+ }
1533
+ }, [
1534
+ event
1535
+ ]);
1536
+ const handleEvent = useCallback7((ev) => {
1537
+ event.emit(ev);
1538
+ }, [
1539
+ event
1540
+ ]);
1541
+ return /* @__PURE__ */ React10.createElement("div", {
1542
+ role: "group",
1543
+ className: mx5("flex flex-col is-full density-fine", outline && "bg-groupSurface border border-subduedSeparator transition transition-border [&:has(.cm-content:focus)]:border-separator rounded", classNames)
1544
+ }, /* @__PURE__ */ React10.createElement("div", {
1545
+ role: "none",
1546
+ className: "flex p-2 gap-2"
1547
+ }, /* @__PURE__ */ React10.createElement(ChatStatusIndicator, {
1548
+ classNames: "p-1",
1549
+ preset,
1550
+ error,
1551
+ processing: streaming
1552
+ }), /* @__PURE__ */ React10.createElement(ChatEditor, {
1553
+ ref: editorRef,
1554
+ autoFocus: true,
1555
+ lineWrapping: true,
1556
+ classNames: "col-span-2 pbs-0.5",
1557
+ placeholder: placeholder ?? t("prompt placeholder"),
1558
+ extensions,
1559
+ onSubmit: handleSubmit
1560
+ })), space && settings && /* @__PURE__ */ React10.createElement("div", {
1561
+ role: "none",
1562
+ className: "flex items-center overflow-hidden"
1563
+ }, /* @__PURE__ */ React10.createElement(ChatOptions, {
1564
+ space,
1565
+ blueprintRegistry: processor.blueprintRegistry,
1566
+ context: processor.context,
1567
+ preset,
1568
+ presets,
1569
+ onPresetChange
1570
+ }), /* @__PURE__ */ React10.createElement("div", {
1571
+ role: "none",
1572
+ className: "flex grow overflow-x-auto scrollbar-none"
1573
+ }, /* @__PURE__ */ React10.createElement(ChatReferences, {
1574
+ space,
1575
+ context: processor.context
1576
+ })), /* @__PURE__ */ React10.createElement(ChatActions, {
1577
+ classNames: "col-span-2",
1578
+ microphone: true,
1579
+ recording,
1580
+ processing: streaming,
1581
+ onEvent: handleEvent
1582
+ }, online !== void 0 && /* @__PURE__ */ React10.createElement(Input2.Root, null, /* @__PURE__ */ React10.createElement(Input2.Label, {
1583
+ srOnly: true
1584
+ }, t("online switch label")), /* @__PURE__ */ React10.createElement(Input2.Switch, {
1585
+ classNames: "mli-2",
1586
+ checked: online,
1587
+ onCheckedChange: onOnlineChange
1588
+ })))));
1589
+ } finally {
1590
+ _effect.f();
1591
+ }
1592
+ };
1593
+ ChatPrompt.displayName = "Chat.Prompt";
1594
+ var ChatThread2 = (props) => {
1595
+ var _effect = _useSignals12();
1596
+ try {
1597
+ const { debug, event, messages, processor } = useChatContext(ChatThread2.displayName);
1598
+ const identity = useIdentity();
1599
+ const error = useAtomValue(processor.error).pipe(Option2.getOrUndefined);
1600
+ const controllerRef = useRef3(null);
1601
+ useEffect6(() => {
1602
+ return event.on((event2) => {
1603
+ switch (event2.type) {
1604
+ case "submit":
1605
+ case "scroll-to-bottom":
1606
+ controllerRef.current?.scrollToBottom();
1607
+ break;
1608
+ case "nav-previous":
1609
+ controllerRef.current?.navigatePrevious();
1610
+ break;
1611
+ case "nav-next":
1612
+ controllerRef.current?.navigateNext();
1613
+ break;
1614
+ }
1615
+ });
1616
+ }, [
1617
+ event
1618
+ ]);
1619
+ const handleEvent = useCallback7((ev) => {
1620
+ event.emit(ev);
1621
+ }, [
1622
+ event
1623
+ ]);
1624
+ if (!identity) {
1625
+ return null;
1626
+ }
1627
+ return /* @__PURE__ */ React10.createElement(ChatThread, {
1628
+ ...props,
1629
+ identity,
1630
+ messages,
1631
+ error,
1632
+ debug,
1633
+ onEvent: handleEvent,
1634
+ ref: controllerRef
1635
+ });
1636
+ } finally {
1637
+ _effect.f();
1638
+ }
1639
+ };
1640
+ ChatThread2.displayName = "Chat.Thread";
1641
+ var ChatToolbar = ({ classNames, companionTo }) => {
1642
+ var _effect = _useSignals12();
1643
+ try {
1644
+ const { chat } = useChatContext(ChatToolbar.displayName);
1645
+ const menu = useChatToolbarActions({
1646
+ chat,
1647
+ companionTo
1648
+ });
1649
+ return /* @__PURE__ */ React10.createElement(MenuProvider, {
1650
+ ...menu,
1651
+ attendableId: companionTo ? Obj5.getDXN(companionTo).toString() : chat ? Obj5.getDXN(chat).toString() : ""
1652
+ }, /* @__PURE__ */ React10.createElement(ToolbarMenu, {
1653
+ classNames,
1654
+ textBlockWidth: true
1655
+ }));
1656
+ } finally {
1657
+ _effect.f();
1658
+ }
1659
+ };
1660
+ ChatToolbar.displayName = "Chat.Toolbar";
1661
+ var Chat = {
1662
+ Root: ChatRoot,
1663
+ Viewport: ChatViewport,
1664
+ Prompt: ChatPrompt,
1665
+ Thread: ChatThread2,
1666
+ Toolbar: ChatToolbar
1667
+ };
1668
+
1669
+ // src/components/Toolbox/Toolbox.tsx
1670
+ import { useSignals as _useSignals13 } from "@preact-signals/safe-react/tracking";
1671
+ import React11, { Fragment, useEffect as useEffect7, useState as useState12 } from "react";
1672
+ import { Function } from "@dxos/functions";
1673
+ import { log as log5 } from "@dxos/log";
1674
+ import { Filter as Filter4, useQuery as useQuery3 } from "@dxos/react-client/echo";
1675
+ import { useTranslation as useTranslation7 } from "@dxos/react-ui";
1676
+ import { mx as mx6 } from "@dxos/react-ui-theme";
1677
+ var __dxlog_file5 = "/__w/dxos/dxos/packages/plugins/plugin-assistant/src/components/Toolbox/Toolbox.tsx";
1678
+ var Toolbox = ({ classNames, functions, services, blueprints, activeBlueprints }) => {
1679
+ var _effect = _useSignals13();
1680
+ try {
1681
+ const { t } = useTranslation7(meta.id);
1682
+ return /* @__PURE__ */ React11.createElement("div", {
1683
+ className: mx6("flex flex-col overflow-y-auto box-content", classNames)
1684
+ }, blueprints && blueprints.length > 0 && /* @__PURE__ */ React11.createElement(Section, {
1685
+ title: "Blueprints",
1686
+ items: blueprints.map(({ target }) => ({
1687
+ name: target?.name ?? "",
1688
+ description: target?.description ?? "",
1689
+ subitems: target?.tools.map((toolId) => ({
1690
+ name: `\u2219 ${safeToolId(toolId)}`
1691
+ }))
1692
+ }))
1693
+ }), activeBlueprints && activeBlueprints.length > 0 && /* @__PURE__ */ React11.createElement(Section, {
1694
+ title: "Blueprints",
1695
+ items: activeBlueprints.map(({ target }) => ({
1696
+ name: target?.name ?? "",
1697
+ description: target?.description ?? "",
1698
+ subitems: target?.tools.map((toolId) => ({
1699
+ name: `\u2219 ${safeToolId(toolId)}`
1700
+ }))
1701
+ }))
1702
+ }), services && services.length > 0 && /* @__PURE__ */ React11.createElement(Section, {
1703
+ title: "Services",
1704
+ items: services.map(({ service: { serviceId, name, description } }) => ({
1705
+ name: name ?? serviceId,
1706
+ description
1707
+ }))
1708
+ }), functions && functions.length > 0 && /* @__PURE__ */ React11.createElement(Section, {
1709
+ title: "Functions",
1710
+ items: functions.map(({ name, description }) => ({
1711
+ name,
1712
+ description
1713
+ }))
1714
+ }));
1715
+ } finally {
1716
+ _effect.f();
1717
+ }
1718
+ };
1719
+ var Section = ({ title, items, striped }) => {
1720
+ var _effect = _useSignals13();
1721
+ try {
1722
+ const stripeClassNames = "odd:bg-neutral-50 dark:odd:bg-neutral-800";
1723
+ const gridClassNames = "grid grid-cols-[8rem_1fr]";
1724
+ const subGridClassNames = mx6("col-span-full grid grid-cols-subgrid text-xs pli-2", striped && stripeClassNames);
1725
+ return /* @__PURE__ */ React11.createElement("div", null, /* @__PURE__ */ React11.createElement("h1", {
1726
+ className: "pli-2 text-sm"
1727
+ }, title), /* @__PURE__ */ React11.createElement("div", {
1728
+ className: gridClassNames
1729
+ }, items.map(({ name, description, subitems }, i) => /* @__PURE__ */ React11.createElement(Fragment, {
1730
+ key: i
1731
+ }, name && /* @__PURE__ */ React11.createElement("div", {
1732
+ className: subGridClassNames
1733
+ }, /* @__PURE__ */ React11.createElement("div", {
1734
+ className: "truncate text-primary-500"
1735
+ }, name), /* @__PURE__ */ React11.createElement("div", {
1736
+ className: "line-clamp-2"
1737
+ }, description)), subitems?.map(({ name: name2, description: description2 }, i2) => /* @__PURE__ */ React11.createElement("div", {
1738
+ key: i2,
1739
+ className: mx6(subGridClassNames, striped && stripeClassNames)
1740
+ }, /* @__PURE__ */ React11.createElement("div", {
1741
+ className: "truncate"
1742
+ }, name2), /* @__PURE__ */ React11.createElement("div", {
1743
+ className: "line-clamp-3 text-subdued"
1744
+ }, description2)))))));
1745
+ } finally {
1746
+ _effect.f();
1747
+ }
1748
+ };
1749
+ var ToolboxContainer = ({ classNames, space, processor }) => {
1750
+ var _effect = _useSignals13();
1751
+ try {
1752
+ const services = useQuery3(space, Filter4.type(ServiceType));
1753
+ const [serviceTools, setServiceTools] = useState12([]);
1754
+ useEffect7(() => {
1755
+ log5("creating service tools...", {
1756
+ services: services.length
1757
+ }, {
1758
+ F: __dxlog_file5,
1759
+ L: 117,
1760
+ S: void 0,
1761
+ C: (f, a) => f(...a)
1762
+ });
1763
+ queueMicrotask(async () => {
1764
+ });
1765
+ }, [
1766
+ services
1767
+ ]);
1768
+ const functions = useQuery3(space, Filter4.type(Function.Function));
1769
+ return /* @__PURE__ */ React11.createElement(Toolbox, {
1770
+ classNames,
1771
+ blueprints: processor?.context.blueprints.value,
1772
+ services: serviceTools,
1773
+ functions
1774
+ });
1775
+ } finally {
1776
+ _effect.f();
1777
+ }
1778
+ };
1779
+ var safeToolId = (name) => {
1780
+ return name.split("_").pop();
1781
+ };
1782
+
1783
+ // src/components/index.ts
1784
+ var BlueprintArticle = lazy(() => import("./BlueprintArticle-IMCR3642.mjs"));
1785
+ var ChatCompanion = lazy(() => import("./ChatCompanion-JYD2RIBJ.mjs"));
1786
+ var ChatContainer = lazy(() => import("./ChatContainer-XCPBWYIR.mjs"));
1787
+ var ChatDialog = lazy(() => import("./ChatDialog-DT7KFCRL.mjs"));
1788
+ var PromptArticle = lazy(() => import("./PromptArticle-45QX25Y5.mjs"));
1789
+
1790
+ // src/hooks/useChatToolbarActions.ts
1791
+ var __dxlog_file6 = "/__w/dxos/dxos/packages/plugins/plugin-assistant/src/hooks/useChatToolbarActions.ts";
1792
+ var useChatToolbarActions = ({ chat, companionTo }) => {
1793
+ const { dispatch } = useIntentDispatcher();
1794
+ const { space } = useChatContext("useChatToolbarActions");
1795
+ const query = companionTo ? Query.select(Filter5.ids(companionTo.id)).targetOf(Assistant_exports.CompanionTo).source() : Query.select(Filter5.nothing());
1796
+ const chats = useQuery4(space, query);
1797
+ return useMenuActions(useMemo10(() => {
1798
+ return Atom.make(() => {
1799
+ const builder = MenuBuilder.make().root({
1800
+ label: [
1801
+ "chat toolbar title",
1802
+ {
1803
+ ns: meta.id
1804
+ }
1805
+ ]
1806
+ }).action("new", {
1807
+ label: [
1808
+ "new thread button",
1809
+ {
1810
+ ns: meta.id
1811
+ }
1812
+ ],
1813
+ icon: "ph--plus--regular",
1814
+ type: "new"
1815
+ }, () => dispatch(createIntent(AssistantAction_exports.SetCurrentChat, {
1816
+ companionTo,
1817
+ chat: void 0
1818
+ })).pipe(Effect2.runPromise)).action("rename", {
1819
+ label: [
1820
+ "rename thread button",
1821
+ {
1822
+ ns: meta.id
1823
+ }
1824
+ ],
1825
+ icon: "ph--magic-wand--regular",
1826
+ type: "rename",
1827
+ disabled: !chat
1828
+ }, () => Effect2.gen(function* () {
1829
+ invariant(chat, void 0, {
1830
+ F: __dxlog_file6,
1831
+ L: 68,
1832
+ S: this,
1833
+ A: [
1834
+ "chat",
1835
+ ""
1836
+ ]
1837
+ });
1838
+ yield* dispatch(createIntent(AssistantAction_exports.UpdateChatName, {
1839
+ chat
1840
+ }));
1841
+ }).pipe(Effect2.runPromise)).action("branch", {
1842
+ label: [
1843
+ "button branch thread",
1844
+ {
1845
+ ns: meta.id
1846
+ }
1847
+ ],
1848
+ icon: "ph--git-branch--regular",
1849
+ type: "branch",
1850
+ disabled: true
1851
+ }, () => {
1852
+ });
1853
+ if (chats.length > 0) {
1854
+ builder.group("chats", {
1855
+ label: [
1856
+ "chat history label",
1857
+ {
1858
+ ns: meta.id
1859
+ }
1860
+ ],
1861
+ icon: "ph--clock-counter-clockwise--regular",
1862
+ selectCardinality: "single",
1863
+ variant: "dropdownMenu"
1864
+ }, (builder2) => {
1865
+ chats.toSorted((a, b) => a.id.localeCompare(b.id)).forEach((chat2) => {
1866
+ builder2.action(chat2.id, {
1867
+ label: Obj6.getLabel(chat2) ?? [
1868
+ "object name placeholder",
1869
+ {
1870
+ ns: Assistant_exports.Chat.typename
1871
+ }
1872
+ ]
1873
+ }, () => Effect2.gen(function* () {
1874
+ invariant(companionTo, void 0, {
1875
+ F: __dxlog_file6,
1876
+ L: 104,
1877
+ S: this,
1878
+ A: [
1879
+ "companionTo",
1880
+ ""
1881
+ ]
1882
+ });
1883
+ yield* dispatch(createIntent(AssistantAction_exports.SetCurrentChat, {
1884
+ companionTo,
1885
+ chat: chat2
1886
+ }));
1887
+ }).pipe(Effect2.runPromise));
1888
+ });
1889
+ });
1890
+ }
1891
+ return builder.build();
1892
+ });
1893
+ }, [
1894
+ chats.length,
1895
+ space?.id,
1896
+ companionTo?.id,
1897
+ chat?.id,
1898
+ dispatch
1899
+ ]));
1900
+ };
1901
+
1902
+ export {
1903
+ AssistantSettings,
1904
+ useBlueprintRegistry,
1905
+ useBlueprints,
1906
+ useActiveBlueprints,
1907
+ useBlueprintHandlers,
1908
+ useChatProcessor,
1909
+ useChatServices,
1910
+ useChatToolbarActions,
1911
+ useContextBinder,
1912
+ useContextObjects,
1913
+ useFlush,
1914
+ useItemTypes,
1915
+ useOnline,
1916
+ usePresets,
1917
+ useReferencesProvider,
1918
+ ChatContextProvider,
1919
+ useChatContext,
1920
+ Chat,
1921
+ Toolbox,
1922
+ ToolboxContainer,
1923
+ BlueprintArticle,
1924
+ ChatCompanion,
1925
+ ChatContainer,
1926
+ ChatDialog,
1927
+ PromptArticle
1928
+ };
1929
+ //# sourceMappingURL=chunk-U62BTGDF.mjs.map