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