@dxos/plugin-assistant 0.8.4-main.2e9d522 → 0.8.4-main.3c1ae3b

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 (481) hide show
  1. package/dist/lib/browser/BlueprintArticle-BWSLH6LG.mjs +36 -0
  2. package/dist/lib/browser/BlueprintArticle-BWSLH6LG.mjs.map +7 -0
  3. package/dist/lib/browser/ChatCompanion-U7VMDYO6.mjs +159 -0
  4. package/dist/lib/browser/ChatCompanion-U7VMDYO6.mjs.map +7 -0
  5. package/dist/lib/browser/ChatContainer-JXDZQ2EY.mjs +79 -0
  6. package/dist/lib/browser/ChatContainer-JXDZQ2EY.mjs.map +7 -0
  7. package/dist/lib/browser/{ChatDialog-X6VN6QZI.mjs → ChatDialog-5NNGCRKJ.mjs} +30 -12
  8. package/dist/lib/browser/ChatDialog-5NNGCRKJ.mjs.map +7 -0
  9. package/dist/lib/browser/PromptArticle-Q7JYGFQV.mjs +59 -0
  10. package/dist/lib/browser/PromptArticle-Q7JYGFQV.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-ADZRPJ3V.mjs +199 -0
  14. package/dist/lib/browser/app-graph-builder-ADZRPJ3V.mjs.map +7 -0
  15. package/dist/lib/browser/blueprint-definition-7HPQPCL7.mjs +12 -0
  16. package/dist/lib/browser/blueprint-definition-7HPQPCL7.mjs.map +7 -0
  17. package/dist/lib/browser/chunk-5JZRYQZL.mjs +229 -0
  18. package/dist/lib/browser/chunk-5JZRYQZL.mjs.map +7 -0
  19. package/dist/lib/browser/chunk-7ZJIXQ2Y.mjs +335 -0
  20. package/dist/lib/browser/chunk-7ZJIXQ2Y.mjs.map +7 -0
  21. package/dist/lib/browser/chunk-F6YX2HHA.mjs +262 -0
  22. package/dist/lib/browser/chunk-F6YX2HHA.mjs.map +7 -0
  23. package/dist/lib/browser/chunk-J5LGTIGS.mjs +10 -0
  24. package/dist/lib/browser/chunk-J5LGTIGS.mjs.map +7 -0
  25. package/dist/lib/browser/chunk-LRE4VEZV.mjs +16 -0
  26. package/dist/lib/browser/chunk-LRE4VEZV.mjs.map +7 -0
  27. package/dist/lib/browser/chunk-SWEOO227.mjs +1930 -0
  28. package/dist/lib/browser/chunk-SWEOO227.mjs.map +7 -0
  29. package/dist/lib/browser/chunk-WBG5PTSX.mjs +23 -0
  30. package/dist/lib/browser/chunk-WBG5PTSX.mjs.map +7 -0
  31. package/dist/lib/browser/chunk-YDSFERCV.mjs +178 -0
  32. package/dist/lib/browser/chunk-YDSFERCV.mjs.map +7 -0
  33. package/dist/lib/browser/edge-model-resolver-O6OFYIO2.mjs +18 -0
  34. package/dist/lib/browser/edge-model-resolver-O6OFYIO2.mjs.map +7 -0
  35. package/dist/lib/browser/index.mjs +227 -101
  36. package/dist/lib/browser/index.mjs.map +4 -4
  37. package/dist/lib/browser/intent-resolver-Q7TX3MV7.mjs +143 -0
  38. package/dist/lib/browser/intent-resolver-Q7TX3MV7.mjs.map +7 -0
  39. package/dist/lib/browser/local-model-resolver-34MVHRKD.mjs +17 -0
  40. package/dist/lib/browser/local-model-resolver-34MVHRKD.mjs.map +7 -0
  41. package/dist/lib/browser/meta.json +1 -1
  42. package/dist/lib/browser/react-surface-VXXS6ZVC.mjs +100 -0
  43. package/dist/lib/browser/react-surface-VXXS6ZVC.mjs.map +7 -0
  44. package/dist/lib/browser/repair-3MZXLUHO.mjs +44 -0
  45. package/dist/lib/browser/repair-3MZXLUHO.mjs.map +7 -0
  46. package/dist/lib/browser/{settings-2DGP3UTS.mjs → settings-HD5WA24I.mjs} +8 -7
  47. package/dist/lib/{node-esm/settings-47RYZOU4.mjs.map → browser/settings-HD5WA24I.mjs.map} +1 -1
  48. package/dist/lib/browser/state-GG7Z3NB7.mjs +25 -0
  49. package/dist/lib/browser/state-GG7Z3NB7.mjs.map +7 -0
  50. package/dist/lib/browser/toolkit-VYDAWNE4.mjs +17 -0
  51. package/dist/lib/browser/toolkit-VYDAWNE4.mjs.map +7 -0
  52. package/dist/lib/browser/types/index.mjs +7 -4
  53. package/dist/lib/node-esm/BlueprintArticle-R2XYBRCK.mjs +37 -0
  54. package/dist/lib/node-esm/BlueprintArticle-R2XYBRCK.mjs.map +7 -0
  55. package/dist/lib/node-esm/ChatCompanion-O4T7PMMC.mjs +160 -0
  56. package/dist/lib/node-esm/ChatCompanion-O4T7PMMC.mjs.map +7 -0
  57. package/dist/lib/node-esm/ChatContainer-OWAZI6ZF.mjs +80 -0
  58. package/dist/lib/node-esm/ChatContainer-OWAZI6ZF.mjs.map +7 -0
  59. package/dist/lib/node-esm/{ChatDialog-RJ6FDX4Q.mjs → ChatDialog-IBXH5FRI.mjs} +30 -12
  60. package/dist/lib/node-esm/ChatDialog-IBXH5FRI.mjs.map +7 -0
  61. package/dist/lib/node-esm/PromptArticle-IV7O5UZ3.mjs +60 -0
  62. package/dist/lib/node-esm/PromptArticle-IV7O5UZ3.mjs.map +7 -0
  63. package/dist/lib/node-esm/ai-service-MUYLV3NT.mjs +20 -0
  64. package/dist/lib/node-esm/ai-service-MUYLV3NT.mjs.map +7 -0
  65. package/dist/lib/node-esm/app-graph-builder-26KXQ5ZY.mjs +200 -0
  66. package/dist/lib/node-esm/app-graph-builder-26KXQ5ZY.mjs.map +7 -0
  67. package/dist/lib/node-esm/blueprint-definition-S3DNWJFV.mjs +13 -0
  68. package/dist/lib/node-esm/blueprint-definition-S3DNWJFV.mjs.map +7 -0
  69. package/dist/lib/node-esm/chunk-CKW4IYLY.mjs +336 -0
  70. package/dist/lib/node-esm/chunk-CKW4IYLY.mjs.map +7 -0
  71. package/dist/lib/node-esm/chunk-E4JSYCWZ.mjs +230 -0
  72. package/dist/lib/node-esm/chunk-E4JSYCWZ.mjs.map +7 -0
  73. package/dist/lib/node-esm/chunk-GWKWQSEQ.mjs +264 -0
  74. package/dist/lib/node-esm/chunk-GWKWQSEQ.mjs.map +7 -0
  75. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +11 -0
  76. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +7 -0
  77. package/dist/lib/node-esm/chunk-VGSP5WMV.mjs +180 -0
  78. package/dist/lib/node-esm/chunk-VGSP5WMV.mjs.map +7 -0
  79. package/dist/lib/node-esm/chunk-WE6KTH72.mjs +25 -0
  80. package/dist/lib/node-esm/chunk-WE6KTH72.mjs.map +7 -0
  81. package/dist/lib/node-esm/chunk-YWFWT57N.mjs +17 -0
  82. package/dist/lib/node-esm/chunk-YWFWT57N.mjs.map +7 -0
  83. package/dist/lib/node-esm/chunk-ZNSHGWE4.mjs +1931 -0
  84. package/dist/lib/node-esm/chunk-ZNSHGWE4.mjs.map +7 -0
  85. package/dist/lib/node-esm/edge-model-resolver-2ARXDOYS.mjs +19 -0
  86. package/dist/lib/node-esm/edge-model-resolver-2ARXDOYS.mjs.map +7 -0
  87. package/dist/lib/node-esm/index.mjs +227 -101
  88. package/dist/lib/node-esm/index.mjs.map +4 -4
  89. package/dist/lib/node-esm/intent-resolver-LTKMN3YB.mjs +144 -0
  90. package/dist/lib/node-esm/intent-resolver-LTKMN3YB.mjs.map +7 -0
  91. package/dist/lib/node-esm/local-model-resolver-TP2NTSAX.mjs +18 -0
  92. package/dist/lib/node-esm/local-model-resolver-TP2NTSAX.mjs.map +7 -0
  93. package/dist/lib/node-esm/meta.json +1 -1
  94. package/dist/lib/node-esm/react-surface-AOBQALOV.mjs +101 -0
  95. package/dist/lib/node-esm/react-surface-AOBQALOV.mjs.map +7 -0
  96. package/dist/lib/node-esm/repair-RER5H7Y6.mjs +45 -0
  97. package/dist/lib/node-esm/repair-RER5H7Y6.mjs.map +7 -0
  98. package/dist/lib/node-esm/{settings-47RYZOU4.mjs → settings-YJQVKHH5.mjs} +8 -7
  99. package/dist/lib/{browser/settings-2DGP3UTS.mjs.map → node-esm/settings-YJQVKHH5.mjs.map} +1 -1
  100. package/dist/lib/node-esm/state-FSUHFMDM.mjs +26 -0
  101. package/dist/lib/node-esm/state-FSUHFMDM.mjs.map +7 -0
  102. package/dist/lib/node-esm/toolkit-HFJZLVIR.mjs +18 -0
  103. package/dist/lib/node-esm/toolkit-HFJZLVIR.mjs.map +7 -0
  104. package/dist/lib/node-esm/types/index.mjs +7 -4
  105. package/dist/types/src/AssistantPlugin.d.ts +1 -1
  106. package/dist/types/src/AssistantPlugin.d.ts.map +1 -1
  107. package/dist/types/src/capabilities/ai-service.d.ts +4 -0
  108. package/dist/types/src/capabilities/ai-service.d.ts.map +1 -0
  109. package/dist/types/src/capabilities/app-graph-builder.d.ts +1 -1
  110. package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -1
  111. package/dist/types/src/capabilities/blueprint-definition.d.ts +7 -0
  112. package/dist/types/src/capabilities/blueprint-definition.d.ts.map +1 -0
  113. package/dist/types/src/capabilities/capabilities.d.ts +10 -0
  114. package/dist/types/src/capabilities/capabilities.d.ts.map +1 -0
  115. package/dist/types/src/capabilities/edge-model-resolver.d.ts +4 -0
  116. package/dist/types/src/capabilities/edge-model-resolver.d.ts.map +1 -0
  117. package/dist/types/src/capabilities/index.d.ts +12 -3
  118. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  119. package/dist/types/src/capabilities/intent-resolver.d.ts +1 -1
  120. package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -1
  121. package/dist/types/src/capabilities/local-model-resolver.d.ts +10 -0
  122. package/dist/types/src/capabilities/local-model-resolver.d.ts.map +1 -0
  123. package/dist/types/src/capabilities/react-surface.d.ts +1 -1
  124. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
  125. package/dist/types/src/capabilities/repair.d.ts +4 -0
  126. package/dist/types/src/capabilities/repair.d.ts.map +1 -0
  127. package/dist/types/src/capabilities/settings.d.ts +1 -1
  128. package/dist/types/src/capabilities/state.d.ts +4 -0
  129. package/dist/types/src/capabilities/state.d.ts.map +1 -0
  130. package/dist/types/src/capabilities/toolkit.d.ts +4 -0
  131. package/dist/types/src/capabilities/toolkit.d.ts.map +1 -0
  132. package/dist/types/src/components/AssistantSettings/AssistantSettings.d.ts.map +1 -1
  133. package/dist/types/src/components/BlueprintArticle.d.ts +7 -0
  134. package/dist/types/src/components/BlueprintArticle.d.ts.map +1 -0
  135. package/dist/types/src/components/Chat/Chat.d.ts +35 -21
  136. package/dist/types/src/components/Chat/Chat.d.ts.map +1 -1
  137. package/dist/types/src/components/Chat/events.d.ts +9 -0
  138. package/dist/types/src/components/Chat/events.d.ts.map +1 -1
  139. package/dist/types/src/components/ChatCompanion.d.ts +13 -0
  140. package/dist/types/src/components/ChatCompanion.d.ts.map +1 -0
  141. package/dist/types/src/components/ChatContainer.d.ts +14 -6
  142. package/dist/types/src/components/ChatContainer.d.ts.map +1 -1
  143. package/dist/types/src/components/ChatDialog.d.ts.map +1 -1
  144. package/dist/types/src/components/ChatProgress/ChatProgress.d.ts +7 -0
  145. package/dist/types/src/components/ChatProgress/ChatProgress.d.ts.map +1 -0
  146. package/dist/types/src/components/ChatProgress/index.d.ts +2 -0
  147. package/dist/types/src/components/ChatProgress/index.d.ts.map +1 -0
  148. package/dist/types/src/components/ChatPrompt/ChatActions.d.ts.map +1 -1
  149. package/dist/types/src/components/ChatPrompt/ChatOptions.d.ts +20 -0
  150. package/dist/types/src/components/ChatPrompt/ChatOptions.d.ts.map +1 -0
  151. package/dist/types/src/components/ChatPrompt/ChatPresets.d.ts.map +1 -1
  152. package/dist/types/src/components/ChatPrompt/ChatReferences.d.ts +4 -5
  153. package/dist/types/src/components/ChatPrompt/ChatReferences.d.ts.map +1 -1
  154. package/dist/types/src/components/ChatPrompt/ChatStatusIndicator.d.ts +6 -4
  155. package/dist/types/src/components/ChatPrompt/ChatStatusIndicator.d.ts.map +1 -1
  156. package/dist/types/src/components/ChatPrompt/index.d.ts +1 -1
  157. package/dist/types/src/components/ChatPrompt/index.d.ts.map +1 -1
  158. package/dist/types/src/components/ChatThread/ChatThread.d.ts +12 -10
  159. package/dist/types/src/components/ChatThread/ChatThread.d.ts.map +1 -1
  160. package/dist/types/src/components/ChatThread/ChatThread.stories.d.ts +170 -70
  161. package/dist/types/src/components/ChatThread/ChatThread.stories.d.ts.map +1 -1
  162. package/dist/types/src/components/ChatThread/Link.d.ts +9 -0
  163. package/dist/types/src/components/ChatThread/Link.d.ts.map +1 -0
  164. package/dist/types/src/components/ChatThread/reducers.d.ts +40 -0
  165. package/dist/types/src/components/ChatThread/reducers.d.ts.map +1 -0
  166. package/dist/types/src/components/ChatThread/registry.d.ts +11 -0
  167. package/dist/types/src/components/ChatThread/registry.d.ts.map +1 -0
  168. package/dist/types/src/components/ChatThread/sync.d.ts +42 -0
  169. package/dist/types/src/components/ChatThread/sync.d.ts.map +1 -0
  170. package/dist/types/src/components/ChatThread/sync.test.d.ts +2 -0
  171. package/dist/types/src/components/ChatThread/sync.test.d.ts.map +1 -0
  172. package/dist/types/src/components/PromptArticle.d.ts +7 -0
  173. package/dist/types/src/components/PromptArticle.d.ts.map +1 -0
  174. package/dist/types/src/components/TemplateEditor/TemplateEditor.d.ts +3 -6
  175. package/dist/types/src/components/TemplateEditor/TemplateEditor.d.ts.map +1 -1
  176. package/dist/types/src/components/TemplateEditor/TemplateEditor.stories.d.ts +317 -7
  177. package/dist/types/src/components/TemplateEditor/TemplateEditor.stories.d.ts.map +1 -1
  178. package/dist/types/src/components/TemplateEditor/TemplateForm.d.ts +3 -2
  179. package/dist/types/src/components/TemplateEditor/TemplateForm.d.ts.map +1 -1
  180. package/dist/types/src/components/TemplateEditor/TemplateForm.stories.d.ts +314 -2
  181. package/dist/types/src/components/TemplateEditor/TemplateForm.stories.d.ts.map +1 -1
  182. package/dist/types/src/components/TemplateEditor/extensions/handlebars-extension.d.ts +12 -0
  183. package/dist/types/src/components/TemplateEditor/extensions/handlebars-extension.d.ts.map +1 -0
  184. package/dist/types/src/components/TemplateEditor/extensions/index.d.ts +3 -0
  185. package/dist/types/src/components/TemplateEditor/extensions/index.d.ts.map +1 -0
  186. package/dist/types/src/components/TemplateEditor/extensions/xml-extension.d.ts +8 -0
  187. package/dist/types/src/components/TemplateEditor/extensions/xml-extension.d.ts.map +1 -0
  188. package/dist/types/src/components/ToolBlock/ToolBlock.d.ts +21 -0
  189. package/dist/types/src/components/ToolBlock/ToolBlock.d.ts.map +1 -0
  190. package/dist/types/src/components/ToolBlock/ToolBlockWidget.d.ts +2 -0
  191. package/dist/types/src/components/ToolBlock/ToolBlockWidget.d.ts.map +1 -0
  192. package/dist/types/src/components/ToolBlock/index.d.ts +3 -0
  193. package/dist/types/src/components/ToolBlock/index.d.ts.map +1 -0
  194. package/dist/types/src/components/Toolbox/Toolbox.d.ts +6 -11
  195. package/dist/types/src/components/Toolbox/Toolbox.d.ts.map +1 -1
  196. package/dist/types/src/components/Toolbox/Toolbox.stories.d.ts +318 -5
  197. package/dist/types/src/components/Toolbox/Toolbox.stories.d.ts.map +1 -1
  198. package/dist/types/src/components/index.d.ts +9 -6
  199. package/dist/types/src/components/index.d.ts.map +1 -1
  200. package/dist/types/src/events.d.ts +1 -1
  201. package/dist/types/src/events.d.ts.map +1 -1
  202. package/dist/types/src/functions/analysis.d.ts +5 -0
  203. package/dist/types/src/functions/analysis.d.ts.map +1 -0
  204. package/dist/types/src/functions/index.d.ts +4 -0
  205. package/dist/types/src/functions/index.d.ts.map +1 -0
  206. package/dist/types/src/functions/object-list.d.ts +10 -0
  207. package/dist/types/src/functions/object-list.d.ts.map +1 -0
  208. package/dist/types/src/functions/object-load.d.ts +8 -0
  209. package/dist/types/src/functions/object-load.d.ts.map +1 -0
  210. package/dist/types/src/hooks/index.d.ts +8 -3
  211. package/dist/types/src/hooks/index.d.ts.map +1 -1
  212. package/dist/types/src/hooks/useBlueprintRegistry.d.ts +25 -0
  213. package/dist/types/src/hooks/useBlueprintRegistry.d.ts.map +1 -0
  214. package/dist/types/src/hooks/useChatProcessor.d.ts +8 -19
  215. package/dist/types/src/hooks/useChatProcessor.d.ts.map +1 -1
  216. package/dist/types/src/hooks/useChatServices.d.ts +5 -6
  217. package/dist/types/src/hooks/useChatServices.d.ts.map +1 -1
  218. package/dist/types/src/hooks/useChatToolbarActions.d.ts +8 -0
  219. package/dist/types/src/hooks/useChatToolbarActions.d.ts.map +1 -0
  220. package/dist/types/src/hooks/useContextBinder.d.ts +4 -0
  221. package/dist/types/src/hooks/useContextBinder.d.ts.map +1 -0
  222. package/dist/types/src/hooks/useContextObjects.d.ts +15 -0
  223. package/dist/types/src/hooks/useContextObjects.d.ts.map +1 -0
  224. package/dist/types/src/hooks/useFilteredTypes.d.ts +4 -0
  225. package/dist/types/src/hooks/useFilteredTypes.d.ts.map +1 -0
  226. package/dist/types/src/hooks/useFlush.d.ts +6 -0
  227. package/dist/types/src/hooks/useFlush.d.ts.map +1 -0
  228. package/dist/types/src/hooks/useOnline.d.ts +3 -0
  229. package/dist/types/src/hooks/useOnline.d.ts.map +1 -0
  230. package/dist/types/src/hooks/usePresets.d.ts +7 -0
  231. package/dist/types/src/hooks/usePresets.d.ts.map +1 -0
  232. package/dist/types/src/hooks/useReferencesProvider.d.ts.map +1 -1
  233. package/dist/types/src/index.d.ts +2 -0
  234. package/dist/types/src/index.d.ts.map +1 -1
  235. package/dist/types/src/meta.d.ts +1 -2
  236. package/dist/types/src/meta.d.ts.map +1 -1
  237. package/dist/types/src/processor/index.d.ts +4 -0
  238. package/dist/types/src/processor/index.d.ts.map +1 -0
  239. package/dist/types/src/{hooks → processor}/presets.d.ts +3 -3
  240. package/dist/types/src/processor/presets.d.ts.map +1 -0
  241. package/dist/types/src/processor/processor.d.ts +75 -0
  242. package/dist/types/src/processor/processor.d.ts.map +1 -0
  243. package/dist/types/src/processor/processor.test.d.ts +2 -0
  244. package/dist/types/src/processor/processor.test.d.ts.map +1 -0
  245. package/dist/types/src/processor/update-name.d.ts +10 -0
  246. package/dist/types/src/processor/update-name.d.ts.map +1 -0
  247. package/dist/types/src/queue-logger.d.ts.map +1 -1
  248. package/dist/types/src/testing/index.d.ts +1 -1
  249. package/dist/types/src/testing/index.d.ts.map +1 -1
  250. package/dist/types/src/testing/test-generator.d.ts +8 -0
  251. package/dist/types/src/testing/test-generator.d.ts.map +1 -0
  252. package/dist/types/src/testing/test-sequence.d.ts +0 -4
  253. package/dist/types/src/testing/test-sequence.d.ts.map +1 -1
  254. package/dist/types/src/testing/test-services.d.ts +2 -2
  255. package/dist/types/src/testing/test-services.d.ts.map +1 -1
  256. package/dist/types/src/translations.d.ts +262 -37
  257. package/dist/types/src/translations.d.ts.map +1 -1
  258. package/dist/types/src/types/Assistant.d.ts +45 -0
  259. package/dist/types/src/types/Assistant.d.ts.map +1 -0
  260. package/dist/types/src/types/AssistantAction.d.ts +129 -0
  261. package/dist/types/src/types/AssistantAction.d.ts.map +1 -0
  262. package/dist/types/src/types/defs.d.ts +2 -0
  263. package/dist/types/src/types/defs.d.ts.map +1 -0
  264. package/dist/types/src/types/index.d.ts +3 -1
  265. package/dist/types/src/types/index.d.ts.map +1 -1
  266. package/dist/types/src/types/service.d.ts +135 -85
  267. package/dist/types/src/types/service.d.ts.map +1 -1
  268. package/dist/types/tsconfig.tsbuildinfo +1 -1
  269. package/package.json +99 -93
  270. package/src/AssistantPlugin.tsx +151 -85
  271. package/src/capabilities/ai-service.ts +27 -0
  272. package/src/capabilities/app-graph-builder.ts +104 -149
  273. package/src/capabilities/blueprint-definition.ts +66 -0
  274. package/src/capabilities/capabilities.ts +17 -0
  275. package/src/capabilities/edge-model-resolver.ts +25 -0
  276. package/src/capabilities/index.ts +10 -0
  277. package/src/capabilities/intent-resolver.ts +92 -15
  278. package/src/capabilities/local-model-resolver.ts +30 -0
  279. package/src/capabilities/react-surface.tsx +27 -78
  280. package/src/capabilities/repair.ts +49 -0
  281. package/src/capabilities/state.ts +22 -0
  282. package/src/capabilities/toolkit.ts +17 -0
  283. package/src/components/AssistantSettings/AssistantSettings.tsx +83 -76
  284. package/src/components/BlueprintArticle.tsx +29 -0
  285. package/src/components/Chat/Chat.tsx +260 -217
  286. package/src/components/Chat/events.ts +13 -0
  287. package/src/components/ChatCompanion.tsx +166 -0
  288. package/src/components/ChatContainer.tsx +39 -22
  289. package/src/components/ChatDialog.tsx +25 -14
  290. package/src/components/ChatProgress/ChatProgress.tsx +67 -0
  291. package/src/components/{SequenceEditor → ChatProgress}/index.ts +1 -1
  292. package/src/components/ChatPrompt/ChatActions.tsx +10 -26
  293. package/src/components/ChatPrompt/ChatOptions.tsx +234 -0
  294. package/src/components/ChatPrompt/ChatPresets.tsx +1 -0
  295. package/src/components/ChatPrompt/ChatReferences.tsx +31 -36
  296. package/src/components/ChatPrompt/ChatStatusIndicator.tsx +25 -22
  297. package/src/components/ChatPrompt/index.ts +1 -1
  298. package/src/components/ChatThread/ChatThread.stories.tsx +122 -116
  299. package/src/components/ChatThread/ChatThread.tsx +65 -35
  300. package/src/components/ChatThread/Link.tsx +26 -0
  301. package/src/components/ChatThread/reducers.ts +151 -0
  302. package/src/components/ChatThread/registry.tsx +174 -0
  303. package/src/components/ChatThread/sync.test.ts +89 -0
  304. package/src/components/ChatThread/sync.ts +148 -0
  305. package/src/components/ChatThread/testing/thread.md +37 -0
  306. package/src/components/PromptArticle.tsx +51 -0
  307. package/src/components/TemplateEditor/TemplateEditor.stories.tsx +40 -19
  308. package/src/components/TemplateEditor/TemplateEditor.tsx +30 -52
  309. package/src/components/TemplateEditor/TemplateForm.stories.tsx +19 -14
  310. package/src/components/TemplateEditor/TemplateForm.tsx +8 -5
  311. package/src/components/TemplateEditor/extensions/handlebars-extension.ts +269 -0
  312. package/src/components/TemplateEditor/extensions/index.ts +6 -0
  313. package/src/components/TemplateEditor/extensions/xml-extension.ts +64 -0
  314. package/src/components/ToolBlock/ToolBlock.tsx +143 -0
  315. package/src/components/ToolBlock/ToolBlockWidget.tsx +5 -0
  316. package/src/components/ToolBlock/index.ts +6 -0
  317. package/src/components/Toolbox/Toolbox.stories.tsx +14 -23
  318. package/src/components/Toolbox/Toolbox.tsx +25 -55
  319. package/src/components/index.ts +3 -7
  320. package/src/events.ts +2 -2
  321. package/src/functions/analysis.ts +22 -0
  322. package/src/functions/index.ts +7 -0
  323. package/src/functions/object-list.ts +49 -0
  324. package/src/functions/object-load.ts +46 -0
  325. package/src/hooks/index.ts +8 -4
  326. package/src/hooks/useBlueprintRegistry.ts +95 -0
  327. package/src/hooks/useChatProcessor.ts +35 -104
  328. package/src/hooks/useChatServices.ts +33 -73
  329. package/src/hooks/useChatToolbarActions.ts +122 -0
  330. package/src/hooks/useContextBinder.ts +30 -0
  331. package/src/hooks/useContextObjects.ts +58 -0
  332. package/src/hooks/useFilteredTypes.ts +38 -0
  333. package/src/hooks/useFlush.ts +35 -0
  334. package/src/hooks/useOnline.ts +10 -0
  335. package/src/hooks/usePresets.ts +44 -0
  336. package/src/hooks/useReferencesProvider.ts +14 -11
  337. package/src/index.ts +2 -0
  338. package/src/meta.ts +9 -6
  339. package/src/processor/index.ts +7 -0
  340. package/src/{hooks → processor}/presets.ts +16 -8
  341. package/src/processor/processor.test.ts +72 -0
  342. package/src/processor/processor.ts +277 -0
  343. package/src/processor/update-name.ts +56 -0
  344. package/src/queue-logger.ts +13 -17
  345. package/src/testing/index.ts +1 -1
  346. package/src/testing/test-generator.ts +262 -0
  347. package/src/testing/test-sequence.ts +2 -27
  348. package/src/testing/test-services.ts +2 -8
  349. package/src/translations.ts +48 -26
  350. package/src/types/Assistant.ts +63 -0
  351. package/src/types/AssistantAction.ts +79 -0
  352. package/src/types/defs.ts +5 -0
  353. package/src/types/index.ts +4 -1
  354. package/src/types/service.ts +17 -9
  355. package/src/vite-env.d.ts +30 -0
  356. package/dist/lib/browser/ChatContainer-M3IHQLRS.mjs +0 -54
  357. package/dist/lib/browser/ChatContainer-M3IHQLRS.mjs.map +0 -7
  358. package/dist/lib/browser/ChatDialog-X6VN6QZI.mjs.map +0 -7
  359. package/dist/lib/browser/SequenceContainer-3UDVKWPA.mjs +0 -162
  360. package/dist/lib/browser/SequenceContainer-3UDVKWPA.mjs.map +0 -7
  361. package/dist/lib/browser/TemplateContainer-RPJ2LBOB.mjs +0 -27
  362. package/dist/lib/browser/TemplateContainer-RPJ2LBOB.mjs.map +0 -7
  363. package/dist/lib/browser/app-graph-builder-JTXBKE7O.mjs +0 -223
  364. package/dist/lib/browser/app-graph-builder-JTXBKE7O.mjs.map +0 -7
  365. package/dist/lib/browser/chunk-AEAEKWOC.mjs +0 -98
  366. package/dist/lib/browser/chunk-AEAEKWOC.mjs.map +0 -7
  367. package/dist/lib/browser/chunk-EQDW6BYQ.mjs +0 -108
  368. package/dist/lib/browser/chunk-EQDW6BYQ.mjs.map +0 -7
  369. package/dist/lib/browser/chunk-FDCJSQYF.mjs +0 -40
  370. package/dist/lib/browser/chunk-FDCJSQYF.mjs.map +0 -7
  371. package/dist/lib/browser/chunk-JQBVLTM5.mjs +0 -158
  372. package/dist/lib/browser/chunk-JQBVLTM5.mjs.map +0 -7
  373. package/dist/lib/browser/chunk-OWY4CUQY.mjs +0 -2245
  374. package/dist/lib/browser/chunk-OWY4CUQY.mjs.map +0 -7
  375. package/dist/lib/browser/intent-resolver-5RMMCMXG.mjs +0 -60
  376. package/dist/lib/browser/intent-resolver-5RMMCMXG.mjs.map +0 -7
  377. package/dist/lib/browser/react-surface-66VY37YQ.mjs +0 -150
  378. package/dist/lib/browser/react-surface-66VY37YQ.mjs.map +0 -7
  379. package/dist/lib/node-esm/ChatContainer-VZT74PO2.mjs +0 -55
  380. package/dist/lib/node-esm/ChatContainer-VZT74PO2.mjs.map +0 -7
  381. package/dist/lib/node-esm/ChatDialog-RJ6FDX4Q.mjs.map +0 -7
  382. package/dist/lib/node-esm/SequenceContainer-RQQH5XOC.mjs +0 -163
  383. package/dist/lib/node-esm/SequenceContainer-RQQH5XOC.mjs.map +0 -7
  384. package/dist/lib/node-esm/TemplateContainer-A3NAQCZE.mjs +0 -28
  385. package/dist/lib/node-esm/TemplateContainer-A3NAQCZE.mjs.map +0 -7
  386. package/dist/lib/node-esm/app-graph-builder-OWSOXFTD.mjs +0 -224
  387. package/dist/lib/node-esm/app-graph-builder-OWSOXFTD.mjs.map +0 -7
  388. package/dist/lib/node-esm/chunk-2XL6MNPE.mjs +0 -99
  389. package/dist/lib/node-esm/chunk-2XL6MNPE.mjs.map +0 -7
  390. package/dist/lib/node-esm/chunk-BISJDTBK.mjs +0 -159
  391. package/dist/lib/node-esm/chunk-BISJDTBK.mjs.map +0 -7
  392. package/dist/lib/node-esm/chunk-E33DNNDW.mjs +0 -109
  393. package/dist/lib/node-esm/chunk-E33DNNDW.mjs.map +0 -7
  394. package/dist/lib/node-esm/chunk-QN2H2EHV.mjs +0 -41
  395. package/dist/lib/node-esm/chunk-QN2H2EHV.mjs.map +0 -7
  396. package/dist/lib/node-esm/chunk-SENTQAEO.mjs +0 -2246
  397. package/dist/lib/node-esm/chunk-SENTQAEO.mjs.map +0 -7
  398. package/dist/lib/node-esm/intent-resolver-YPPYELY3.mjs +0 -61
  399. package/dist/lib/node-esm/intent-resolver-YPPYELY3.mjs.map +0 -7
  400. package/dist/lib/node-esm/react-surface-RJMRBR2M.mjs +0 -151
  401. package/dist/lib/node-esm/react-surface-RJMRBR2M.mjs.map +0 -7
  402. package/dist/types/src/components/ChatPrompt/ChatOptionsMenu.d.ts +0 -9
  403. package/dist/types/src/components/ChatPrompt/ChatOptionsMenu.d.ts.map +0 -1
  404. package/dist/types/src/components/ChatThread/ChatMessage.d.ts +0 -17
  405. package/dist/types/src/components/ChatThread/ChatMessage.d.ts.map +0 -1
  406. package/dist/types/src/components/ChatThread/ToolBlock.d.ts +0 -19
  407. package/dist/types/src/components/ChatThread/ToolBlock.d.ts.map +0 -1
  408. package/dist/types/src/components/ChatThread/reducer.d.ts +0 -12
  409. package/dist/types/src/components/ChatThread/reducer.d.ts.map +0 -1
  410. package/dist/types/src/components/PromptSettings.d.ts +0 -6
  411. package/dist/types/src/components/PromptSettings.d.ts.map +0 -1
  412. package/dist/types/src/components/SequenceContainer.d.ts +0 -8
  413. package/dist/types/src/components/SequenceContainer.d.ts.map +0 -1
  414. package/dist/types/src/components/SequenceEditor/SequenceEditor.d.ts +0 -13
  415. package/dist/types/src/components/SequenceEditor/SequenceEditor.d.ts.map +0 -1
  416. package/dist/types/src/components/SequenceEditor/SequenceEditor.stories.d.ts +0 -8
  417. package/dist/types/src/components/SequenceEditor/SequenceEditor.stories.d.ts.map +0 -1
  418. package/dist/types/src/components/SequenceEditor/index.d.ts +0 -2
  419. package/dist/types/src/components/SequenceEditor/index.d.ts.map +0 -1
  420. package/dist/types/src/components/TemplateContainer.d.ts +0 -8
  421. package/dist/types/src/components/TemplateContainer.d.ts.map +0 -1
  422. package/dist/types/src/hooks/chat-processor.d.ts +0 -86
  423. package/dist/types/src/hooks/chat-processor.d.ts.map +0 -1
  424. package/dist/types/src/hooks/chat-processor.test.d.ts +0 -2
  425. package/dist/types/src/hooks/chat-processor.test.d.ts.map +0 -1
  426. package/dist/types/src/hooks/presets.d.ts.map +0 -1
  427. package/dist/types/src/hooks/useBlueprints.d.ts +0 -9
  428. package/dist/types/src/hooks/useBlueprints.d.ts.map +0 -1
  429. package/dist/types/src/parser/filter-generator.d.ts +0 -4
  430. package/dist/types/src/parser/filter-generator.d.ts.map +0 -1
  431. package/dist/types/src/parser/filter-generator.test.d.ts +0 -2
  432. package/dist/types/src/parser/filter-generator.test.d.ts.map +0 -1
  433. package/dist/types/src/parser/index.d.ts +0 -4
  434. package/dist/types/src/parser/index.d.ts.map +0 -1
  435. package/dist/types/src/parser/query-parser.d.ts +0 -15
  436. package/dist/types/src/parser/query-parser.d.ts.map +0 -1
  437. package/dist/types/src/parser/query-parser.test.d.ts +0 -2
  438. package/dist/types/src/parser/query-parser.test.d.ts.map +0 -1
  439. package/dist/types/src/parser/types.d.ts +0 -24
  440. package/dist/types/src/parser/types.d.ts.map +0 -1
  441. package/dist/types/src/stories/Chat.stories.d.ts +0 -249
  442. package/dist/types/src/stories/Chat.stories.d.ts.map +0 -1
  443. package/dist/types/src/testing/test-functions.d.ts +0 -3
  444. package/dist/types/src/testing/test-functions.d.ts.map +0 -1
  445. package/dist/types/src/tools/function.d.ts +0 -5
  446. package/dist/types/src/tools/function.d.ts.map +0 -1
  447. package/dist/types/src/tools/index.d.ts +0 -3
  448. package/dist/types/src/tools/index.d.ts.map +0 -1
  449. package/dist/types/src/tools/openapi.d.ts +0 -10
  450. package/dist/types/src/tools/openapi.d.ts.map +0 -1
  451. package/dist/types/src/tools/openapi.test.d.ts +0 -2
  452. package/dist/types/src/tools/openapi.test.d.ts.map +0 -1
  453. package/dist/types/src/types/schema.d.ts +0 -88
  454. package/dist/types/src/types/schema.d.ts.map +0 -1
  455. package/src/components/ChatPrompt/ChatOptionsMenu.tsx +0 -52
  456. package/src/components/ChatThread/ChatMessage.tsx +0 -268
  457. package/src/components/ChatThread/ToolBlock.tsx +0 -121
  458. package/src/components/ChatThread/reducer.ts +0 -52
  459. package/src/components/PromptSettings.tsx +0 -89
  460. package/src/components/SequenceContainer.tsx +0 -132
  461. package/src/components/SequenceEditor/SequenceEditor.stories.tsx +0 -32
  462. package/src/components/SequenceEditor/SequenceEditor.tsx +0 -50
  463. package/src/components/TemplateContainer.tsx +0 -24
  464. package/src/hooks/chat-processor.test.ts +0 -16
  465. package/src/hooks/chat-processor.ts +0 -314
  466. package/src/hooks/useBlueprints.ts +0 -57
  467. package/src/parser/filter-generator.test.ts +0 -32
  468. package/src/parser/filter-generator.ts +0 -81
  469. package/src/parser/index.ts +0 -7
  470. package/src/parser/query-parser.test.ts +0 -139
  471. package/src/parser/query-parser.ts +0 -199
  472. package/src/parser/types.ts +0 -34
  473. package/src/shims.d.ts +0 -8
  474. package/src/stories/Chat.stories.tsx +0 -378
  475. package/src/testing/test-functions.ts +0 -11
  476. package/src/tools/function.ts +0 -46
  477. package/src/tools/index.ts +0 -6
  478. package/src/tools/openapi.test.ts +0 -217
  479. package/src/tools/openapi.ts +0 -338
  480. package/src/types/schema.ts +0 -95
  481. package/src/typings.d.ts +0 -9
@@ -0,0 +1,1931 @@
1
+ import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
+ import {
3
+ AiChatProcessor,
4
+ AiServicePresets
5
+ } from "./chunk-GWKWQSEQ.mjs";
6
+ import {
7
+ AssistantAction_exports,
8
+ Assistant_exports,
9
+ LLM_PROVIDERS,
10
+ ServiceType
11
+ } from "./chunk-E4JSYCWZ.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 && 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/useFilteredTypes.ts
369
+ import * as Option from "effect/Option";
370
+ import { useEffect, useState as useState4 } from "react";
371
+ import { EntityKind, SystemTypeAnnotation, getTypeAnnotation } from "@dxos/echo/internal";
372
+ var useFilteredTypes = (space) => {
373
+ const [types, setTypes] = useState4([]);
374
+ useEffect(() => {
375
+ if (!space) {
376
+ return;
377
+ }
378
+ return space.db.schemaRegistry.query().subscribe((query) => {
379
+ const types2 = Array.from(new Set([
380
+ ...space.db.graph.schemaRegistry.schemas,
381
+ ...query.results
382
+ ].filter((schema) => getTypeAnnotation(schema)?.kind !== EntityKind.Relation).filter((schema) => SystemTypeAnnotation.get(schema).pipe(Option.getOrElse(() => false)))));
383
+ setTypes(types2);
384
+ }, {
385
+ fire: true
386
+ });
387
+ }, [
388
+ space
389
+ ]);
390
+ return types;
391
+ };
392
+
393
+ // src/hooks/useFlush.ts
394
+ import { useCallback as useCallback3, useRef, useState as useState5 } from "react";
395
+ var useFlush = (space) => {
396
+ const [state, setState] = useState5("idle");
397
+ const resetTimer = useRef(null);
398
+ const handleFlush = useCallback3(() => {
399
+ if (!space) {
400
+ return;
401
+ }
402
+ queueMicrotask(async () => {
403
+ if (resetTimer.current) {
404
+ clearTimeout(resetTimer.current);
405
+ }
406
+ setState("flushing");
407
+ await space.db.flush();
408
+ setState("flushed");
409
+ resetTimer.current = setTimeout(() => {
410
+ setState("idle");
411
+ resetTimer.current = null;
412
+ }, 1e3);
413
+ });
414
+ }, [
415
+ space
416
+ ]);
417
+ return {
418
+ state,
419
+ handleFlush
420
+ };
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.id(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 = useFilteredTypes(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 { ToggleContainer as ToggleContainer2 } from "@dxos/react-ui-components";
855
+ import { PromptWidget, ReferenceWidget, SelectWidget, SuggestionWidget, SummaryWidget } from "@dxos/react-ui-components";
856
+ import { getXmlTextChild } from "@dxos/react-ui-editor";
857
+ import { Json as Json2 } from "@dxos/react-ui-syntax-highlighter";
858
+ import { ContentBlock } from "@dxos/types";
859
+
860
+ // src/components/ToolBlock/ToolBlock.tsx
861
+ import { useSignals as _useSignals9 } from "@preact-signals/safe-react/tracking";
862
+ import React7, { useCallback as useCallback5, useEffect as useEffect4, useMemo as useMemo7, useRef as useRef2, useState as useState10 } from "react";
863
+ import { useTranslation as useTranslation5 } from "@dxos/react-ui";
864
+ import { NumericTabs, TextCrawl, ToggleContainer } from "@dxos/react-ui-components";
865
+ import { Json } from "@dxos/react-ui-syntax-highlighter";
866
+ import { isNonNullable as isNonNullable3, safeParseJson } from "@dxos/util";
867
+ var ToolBlock = ({ view, blocks = [] }) => {
868
+ var _effect = _useSignals9();
869
+ try {
870
+ const { t } = useTranslation5(meta.id);
871
+ const items = useMemo7(() => {
872
+ let lastToolCall;
873
+ const tools = [];
874
+ return blocks.filter((block) => block._tag === "toolCall" || block._tag === "toolResult" || block._tag === "summary").map((block) => {
875
+ switch (block._tag) {
876
+ case "toolCall": {
877
+ if (block.pending && lastToolCall?.block.toolCallId === block.toolCallId) {
878
+ return null;
879
+ }
880
+ const tool = tools.find((tool2) => tool2.name === block.name);
881
+ lastToolCall = {
882
+ tool,
883
+ block
884
+ };
885
+ return {
886
+ title: tool?.description ?? [
887
+ t("tool call label"),
888
+ tool?.name
889
+ ].join(" "),
890
+ content: {
891
+ ...block,
892
+ input: safeParseJson(block.input)
893
+ }
894
+ };
895
+ }
896
+ case "toolResult": {
897
+ if (block.error) {
898
+ return {
899
+ title: t("tool error label"),
900
+ content: block
901
+ };
902
+ }
903
+ const title = lastToolCall?.tool?.description ?? [
904
+ t("tool result label"),
905
+ lastToolCall?.tool?.name
906
+ ].join(" ");
907
+ lastToolCall = void 0;
908
+ return {
909
+ title,
910
+ content: {
911
+ ...block,
912
+ result: safeParseJson(block.result)
913
+ }
914
+ };
915
+ }
916
+ case "summary": {
917
+ if (!lastToolCall) {
918
+ return null;
919
+ }
920
+ return {
921
+ title: t("summary label"),
922
+ content: block
923
+ };
924
+ }
925
+ }
926
+ }).filter(isNonNullable3);
927
+ }, [
928
+ blocks
929
+ ]);
930
+ const handleChangeOpen = useCallback5(() => {
931
+ setTimeout(() => {
932
+ view?.requestMeasure();
933
+ }, 1e3);
934
+ }, [
935
+ view
936
+ ]);
937
+ if (!items.length) {
938
+ return null;
939
+ }
940
+ return /* @__PURE__ */ React7.createElement(ToolContainer, {
941
+ items,
942
+ onChangeOpen: handleChangeOpen
943
+ });
944
+ } finally {
945
+ _effect.f();
946
+ }
947
+ };
948
+ ToolBlock.displayName = "ToolBlock";
949
+ var ToolContainer = ({ items, onChangeOpen }) => {
950
+ var _effect = _useSignals9();
951
+ try {
952
+ const tabsRef = useRef2(null);
953
+ const [selected, setSelected] = useState10(0);
954
+ const [open, setOpen] = useState10(false);
955
+ useEffect4(() => {
956
+ onChangeOpen?.(open);
957
+ if (open) {
958
+ tabsRef.current?.focus();
959
+ }
960
+ }, [
961
+ open,
962
+ onChangeOpen
963
+ ]);
964
+ const handleSelect = (index) => {
965
+ setSelected(index);
966
+ };
967
+ return /* @__PURE__ */ React7.createElement(ToggleContainer.Root, {
968
+ classNames: "mbs-2 is-full rounded-sm",
969
+ open,
970
+ onChangeOpen: setOpen
971
+ }, /* @__PURE__ */ React7.createElement(ToggleContainer.Header, {
972
+ classNames: "text-sm text-placeholder"
973
+ }, /* @__PURE__ */ React7.createElement(TextCrawl, {
974
+ key: "status-roll",
975
+ lines: items.map((item) => item.title),
976
+ autoAdvance: true,
977
+ greedy: true
978
+ })), /* @__PURE__ */ React7.createElement(ToggleContainer.Content, {
979
+ classNames: "grid grid-cols-[32px_1fr]"
980
+ }, /* @__PURE__ */ React7.createElement(NumericTabs, {
981
+ ref: tabsRef,
982
+ classNames: "p-1",
983
+ length: items.length,
984
+ selected,
985
+ onSelect: handleSelect
986
+ }), /* @__PURE__ */ React7.createElement(Json, {
987
+ data: items[selected]?.content,
988
+ classNames: "p-1 text-xs bg-transparent",
989
+ replacer: {
990
+ maxDepth: 3,
991
+ maxArrayLen: 10,
992
+ maxStringLen: 128
993
+ }
994
+ })));
995
+ } finally {
996
+ _effect.f();
997
+ }
998
+ };
999
+
1000
+ // src/components/ChatThread/registry.tsx
1001
+ var __dxlog_file3 = "/__w/dxos/dxos/packages/plugins/plugin-assistant/src/components/ChatThread/registry.tsx";
1002
+ var Fallback = ({ _tag, ...props }) => {
1003
+ var _effect = _useSignals10();
1004
+ try {
1005
+ return /* @__PURE__ */ React8.createElement(ToggleContainer2.Root, {
1006
+ classNames: "rounded-sm"
1007
+ }, /* @__PURE__ */ React8.createElement(ToggleContainer2.Header, {
1008
+ classNames: "bg-groupSurface"
1009
+ }, _tag), /* @__PURE__ */ React8.createElement(ToggleContainer2.Content, {
1010
+ classNames: "bg-modalSurface"
1011
+ }, /* @__PURE__ */ React8.createElement(Json2, {
1012
+ classNames: "!p-2 text-sm",
1013
+ data: props
1014
+ })));
1015
+ } finally {
1016
+ _effect.f();
1017
+ }
1018
+ };
1019
+ var componentRegistry = {
1020
+ //
1021
+ // Widgets
1022
+ //
1023
+ ["prompt"]: {
1024
+ block: true,
1025
+ factory: ({ children }) => {
1026
+ const text = getXmlTextChild(children);
1027
+ return text ? new PromptWidget(text) : null;
1028
+ }
1029
+ },
1030
+ ["reference"]: {
1031
+ block: false,
1032
+ factory: ({ children, ref }) => {
1033
+ const text = getXmlTextChild(children);
1034
+ return text && ref ? new ReferenceWidget(text, ref) : null;
1035
+ }
1036
+ },
1037
+ ["select"]: {
1038
+ block: true,
1039
+ factory: ({ children }) => {
1040
+ const options = children?.map((option) => option._tag === "option" && getXmlTextChild(option.children)).filter(Boolean);
1041
+ return options?.length ? new SelectWidget(options) : null;
1042
+ }
1043
+ },
1044
+ ["suggestion"]: {
1045
+ block: true,
1046
+ factory: ({ children }) => {
1047
+ const text = getXmlTextChild(children);
1048
+ return text ? new SuggestionWidget(text) : null;
1049
+ }
1050
+ },
1051
+ ["summary"]: {
1052
+ block: true,
1053
+ factory: ({ children }) => {
1054
+ const text = getXmlTextChild(children);
1055
+ return text ? new SummaryWidget(text) : null;
1056
+ }
1057
+ },
1058
+ //
1059
+ // React
1060
+ //
1061
+ ["toolCall"]: {
1062
+ block: true,
1063
+ Component: ToolBlock
1064
+ },
1065
+ ["toolResult"]: {
1066
+ block: true,
1067
+ Component: Fallback
1068
+ },
1069
+ ["toolkit"]: {
1070
+ block: true,
1071
+ Component: Fallback
1072
+ },
1073
+ //
1074
+ // Fallback
1075
+ //
1076
+ ["json"]: {
1077
+ block: true,
1078
+ Component: Fallback
1079
+ }
1080
+ };
1081
+ var blockToMarkdown = (context, message, block) => {
1082
+ let str = blockToMarkdownImpl(context, message, block);
1083
+ if (str && !block.pending) {
1084
+ return str += "\n";
1085
+ }
1086
+ return str;
1087
+ };
1088
+ var blockToMarkdownImpl = (context, message, block) => {
1089
+ log3("blockToMarkdown", {
1090
+ block: JSON.stringify(block)
1091
+ }, {
1092
+ F: __dxlog_file3,
1093
+ L: 125,
1094
+ S: void 0,
1095
+ C: (f, a) => f(...a)
1096
+ });
1097
+ switch (block._tag) {
1098
+ case "text": {
1099
+ if (message.sender.role === "user") {
1100
+ return `<prompt>${block.text}</prompt>`;
1101
+ } else {
1102
+ const text = block.text.trim();
1103
+ if (text.length > 0) {
1104
+ return text;
1105
+ }
1106
+ }
1107
+ break;
1108
+ }
1109
+ case "reference": {
1110
+ const dxn = block.reference.dxn;
1111
+ return `<reference ref="${dxn.toString()}">${context.getObjectLabel(dxn)}</reference>`;
1112
+ }
1113
+ case "suggestion": {
1114
+ if (block.pending) {
1115
+ return;
1116
+ }
1117
+ return `<suggestion>${block.text}</suggestion>`;
1118
+ }
1119
+ case "select": {
1120
+ if (block.pending || block.options.length === 0) {
1121
+ return;
1122
+ }
1123
+ return `<select>${block.options.map((option) => `<option>${option}</option>`).join("")}</select>`;
1124
+ }
1125
+ case "toolCall": {
1126
+ context.updateWidget(block.toolCallId, {
1127
+ blocks: [
1128
+ block
1129
+ ]
1130
+ });
1131
+ return `<toolCall id="${block.toolCallId}" />`;
1132
+ }
1133
+ case "toolResult": {
1134
+ context.updateWidget(block.toolCallId, ({ blocks = [] }) => ({
1135
+ blocks: [
1136
+ ...blocks,
1137
+ block
1138
+ ]
1139
+ }));
1140
+ break;
1141
+ }
1142
+ case "summary": {
1143
+ return `<summary>${ContentBlock.createSummaryMessage(block)}</summary>`;
1144
+ }
1145
+ default: {
1146
+ return `<json id="${message.id}">
1147
+ ${JSON.stringify(block)}
1148
+ </json>`;
1149
+ }
1150
+ }
1151
+ };
1152
+
1153
+ // src/components/ChatThread/sync.ts
1154
+ import { log as log4 } from "@dxos/log";
1155
+ var __dxlog_file4 = "/__w/dxos/dxos/packages/plugins/plugin-assistant/src/components/ChatThread/sync.ts";
1156
+ var MessageThreadContext = class {
1157
+ _widgetState;
1158
+ constructor(_widgetState) {
1159
+ this._widgetState = _widgetState;
1160
+ }
1161
+ updateWidget(id, value) {
1162
+ this._widgetState?.updateWidget(id, value);
1163
+ }
1164
+ // TODO(burdon): Resolve from hypergraph.
1165
+ getObjectLabel(_id) {
1166
+ return "Object";
1167
+ }
1168
+ };
1169
+ var MessageSyncer = class {
1170
+ _model;
1171
+ _blockRenderer;
1172
+ _initialMessageId;
1173
+ _currentMessageIndex = 0;
1174
+ _currentBlockIndex = 0;
1175
+ _currentBlockContent;
1176
+ _context;
1177
+ constructor(_model, _blockRenderer) {
1178
+ this._model = _model;
1179
+ this._blockRenderer = _blockRenderer;
1180
+ this._context = new MessageThreadContext(this._model);
1181
+ }
1182
+ get context() {
1183
+ return this._context;
1184
+ }
1185
+ reset() {
1186
+ log4("reset", void 0, {
1187
+ F: __dxlog_file4,
1188
+ L: 64,
1189
+ S: this,
1190
+ C: (f, a) => f(...a)
1191
+ });
1192
+ this._initialMessageId = void 0;
1193
+ this._currentMessageIndex = 0;
1194
+ this._currentBlockIndex = 0;
1195
+ this._currentBlockContent = void 0;
1196
+ void this._model.reset("");
1197
+ }
1198
+ /**
1199
+ * Syncs messages with the editor.
1200
+ */
1201
+ append(messages, flush = false) {
1202
+ if (this._initialMessageId !== messages[0]?.id) {
1203
+ this.reset();
1204
+ this._initialMessageId = messages[0]?.id;
1205
+ }
1206
+ if (flush && this._model.view?.state.doc.length === 0) {
1207
+ const buffer = [];
1208
+ this.process(messages, (content2) => {
1209
+ buffer.push(content2);
1210
+ });
1211
+ const content = buffer.join("");
1212
+ this._model.view?.dispatch({
1213
+ changes: [
1214
+ {
1215
+ from: 0,
1216
+ to: this._model.view?.state.doc.length ?? 0,
1217
+ insert: content
1218
+ }
1219
+ ],
1220
+ selection: {
1221
+ anchor: content.length
1222
+ }
1223
+ });
1224
+ return true;
1225
+ } else {
1226
+ this.process(messages, (content) => {
1227
+ void this._model.append(content);
1228
+ });
1229
+ return false;
1230
+ }
1231
+ }
1232
+ process(messages, append) {
1233
+ log4("sync", {
1234
+ doc: this._model.view?.state.doc.length,
1235
+ messages: messages.map((message) => message.blocks.length),
1236
+ currentMessageIndex: this._currentMessageIndex,
1237
+ currentBlockIndex: this._currentBlockIndex,
1238
+ currentBlockContent: this._currentBlockContent
1239
+ }, {
1240
+ F: __dxlog_file4,
1241
+ L: 105,
1242
+ S: this,
1243
+ C: (f, a) => f(...a)
1244
+ });
1245
+ let i = this._currentMessageIndex;
1246
+ for (const message of messages.slice(this._currentMessageIndex)) {
1247
+ if (i > this._currentMessageIndex) {
1248
+ this._currentBlockIndex = 0;
1249
+ }
1250
+ this._currentMessageIndex = i;
1251
+ let j = this._currentBlockIndex;
1252
+ for (const block of message.blocks.slice(this._currentBlockIndex)) {
1253
+ this._currentBlockIndex = j;
1254
+ const currentBlockContent = this._blockRenderer(this._context, message, block);
1255
+ if (currentBlockContent) {
1256
+ let content = "";
1257
+ if (this._currentBlockContent && currentBlockContent.startsWith(this._currentBlockContent)) {
1258
+ content = currentBlockContent.slice(this._currentBlockContent.length);
1259
+ } else {
1260
+ content = currentBlockContent;
1261
+ }
1262
+ log4("append", {
1263
+ message: i,
1264
+ block: j,
1265
+ content
1266
+ }, {
1267
+ F: __dxlog_file4,
1268
+ L: 132,
1269
+ S: this,
1270
+ C: (f, a) => f(...a)
1271
+ });
1272
+ this._currentBlockContent = currentBlockContent;
1273
+ append(content);
1274
+ }
1275
+ if (block.pending) {
1276
+ return;
1277
+ } else {
1278
+ this._currentBlockContent = void 0;
1279
+ this._currentBlockIndex++;
1280
+ }
1281
+ j++;
1282
+ }
1283
+ i++;
1284
+ }
1285
+ }
1286
+ };
1287
+
1288
+ // src/components/ChatThread/ChatThread.tsx
1289
+ var ChatThread = /* @__PURE__ */ forwardRef(({ classNames, identity, messages = [], error, cursor = false, fadeIn = true, debug = false, onEvent }, forwardedRef) => {
1290
+ var _effect = _useSignals11();
1291
+ try {
1292
+ const controllerRef = useForwardedRef(forwardedRef);
1293
+ const controller = controllerRef.current;
1294
+ const userHue = useMemo8(() => identity?.profile?.data?.hue || keyToFallback(identity?.identityKey ?? PublicKey.random()).hue, [
1295
+ identity
1296
+ ]);
1297
+ useEffect5(() => {
1298
+ controller?.scrollToBottom();
1299
+ }, [
1300
+ controller,
1301
+ error
1302
+ ]);
1303
+ const syncer = useMemo8(() => controller && new MessageSyncer(controller, blockToMarkdown), [
1304
+ controller
1305
+ ]);
1306
+ useEffect5(() => {
1307
+ const reset = syncer?.append(messages, true);
1308
+ if (reset) {
1309
+ controller?.scrollToBottom("instant");
1310
+ }
1311
+ }, [
1312
+ syncer,
1313
+ messages
1314
+ ]);
1315
+ const handleEvent = useCallback6(({ type, value }) => {
1316
+ switch (type) {
1317
+ case "submit": {
1318
+ value && onEvent?.({
1319
+ type,
1320
+ text: value
1321
+ });
1322
+ break;
1323
+ }
1324
+ }
1325
+ }, [
1326
+ onEvent
1327
+ ]);
1328
+ return /* @__PURE__ */ React9.createElement("div", {
1329
+ role: "none",
1330
+ className: mx4("flex bs-full is-full justify-center overflow-hidden", classNames),
1331
+ style: {
1332
+ "--user-fill": `var(--dx-${userHue}Fill)`
1333
+ }
1334
+ }, /* @__PURE__ */ React9.createElement(MarkdownStream, {
1335
+ ref: controllerRef,
1336
+ registry: componentRegistry,
1337
+ cursor,
1338
+ fadeIn,
1339
+ debug,
1340
+ onEvent: handleEvent
1341
+ }));
1342
+ } finally {
1343
+ _effect.f();
1344
+ }
1345
+ });
1346
+
1347
+ // src/components/Chat/Chat.tsx
1348
+ var [ChatContextProvider, useChatContext] = createContext("Chat");
1349
+ var ChatRoot = ({ children, chat, processor, onEvent, ...props }) => {
1350
+ var _effect = _useSignals12();
1351
+ try {
1352
+ const [debug, setDebug] = useState11(false);
1353
+ const pending = useAtomValue(processor.messages);
1354
+ const streaming = useAtomValue(processor.streaming);
1355
+ const lastPrompt = useRef3(void 0);
1356
+ const queue = useQueue(chat?.queue.dxn);
1357
+ const messages = useMemo9(() => {
1358
+ const queueMessages = queue?.objects?.filter(Obj5.instanceOf(Message.Message)) ?? [];
1359
+ return Array2.dedupeWith([
1360
+ ...queueMessages,
1361
+ ...pending
1362
+ ], ({ id: a }, { id: b }) => a === b);
1363
+ }, [
1364
+ queue?.objects,
1365
+ pending
1366
+ ]);
1367
+ const event = useMemo9(() => new Event(), []);
1368
+ useEffect6(() => {
1369
+ return event.on((ev) => {
1370
+ switch (ev.type) {
1371
+ case "toggle-debug": {
1372
+ setDebug((current) => !current);
1373
+ break;
1374
+ }
1375
+ case "submit": {
1376
+ const text = ev.text.trim();
1377
+ if (!streaming && text.length) {
1378
+ lastPrompt.current = ev.text;
1379
+ void processor.request({
1380
+ message: text
1381
+ });
1382
+ }
1383
+ break;
1384
+ }
1385
+ case "retry": {
1386
+ if (!streaming) {
1387
+ void processor.retry();
1388
+ }
1389
+ break;
1390
+ }
1391
+ case "cancel": {
1392
+ if (streaming) {
1393
+ void processor.cancel();
1394
+ if (lastPrompt.current) {
1395
+ event.emit({
1396
+ type: "update-prompt",
1397
+ text: lastPrompt.current
1398
+ });
1399
+ }
1400
+ }
1401
+ break;
1402
+ }
1403
+ }
1404
+ onEvent?.(ev);
1405
+ });
1406
+ }, [
1407
+ event,
1408
+ processor,
1409
+ streaming,
1410
+ onEvent
1411
+ ]);
1412
+ const space = props.space ?? getSpace(chat);
1413
+ return /* @__PURE__ */ React10.createElement(ChatContextProvider, {
1414
+ debug,
1415
+ event,
1416
+ space,
1417
+ chat,
1418
+ messages,
1419
+ processor,
1420
+ ...props
1421
+ }, children);
1422
+ } finally {
1423
+ _effect.f();
1424
+ }
1425
+ };
1426
+ ChatRoot.displayName = "Chat.Root";
1427
+ var ChatViewport = ({ classNames, children }) => {
1428
+ var _effect = _useSignals12();
1429
+ try {
1430
+ return /* @__PURE__ */ React10.createElement("div", {
1431
+ role: "none",
1432
+ className: mx5("flex flex-col bs-full is-full", classNames)
1433
+ }, children);
1434
+ } finally {
1435
+ _effect.f();
1436
+ }
1437
+ };
1438
+ var ChatPrompt = ({ classNames, outline, settings = true, placeholder, expandable, online, presets, preset, onPresetChange, onOnlineChange }) => {
1439
+ var _effect = _useSignals12();
1440
+ try {
1441
+ const { t } = useTranslation6(meta.id);
1442
+ const { space, processor, event } = useChatContext(ChatPrompt.displayName);
1443
+ const error = useAtomValue(processor.error).pipe(Option2.getOrUndefined);
1444
+ const streaming = useAtomValue(processor.streaming);
1445
+ const active = useAtomValue(processor.active);
1446
+ const activeRef = useDynamicRef(active);
1447
+ const editorRef = useRef3(null);
1448
+ const [recordingState, setRecordingState] = useState11(false);
1449
+ useEffect6(() => {
1450
+ return event.on((event2) => {
1451
+ switch (event2.type) {
1452
+ case "update-prompt":
1453
+ if (!editorRef.current?.getText()?.length) {
1454
+ editorRef.current?.setText(event2.text);
1455
+ editorRef.current?.focus();
1456
+ }
1457
+ break;
1458
+ case "record-start":
1459
+ setRecordingState(true);
1460
+ break;
1461
+ case "record-stop":
1462
+ setRecordingState(false);
1463
+ break;
1464
+ }
1465
+ });
1466
+ }, [
1467
+ event
1468
+ ]);
1469
+ const { recording } = useVoiceInput({
1470
+ active: recordingState,
1471
+ onUpdate: (text) => {
1472
+ editorRef.current?.setText(text);
1473
+ editorRef.current?.focus();
1474
+ }
1475
+ });
1476
+ const extensions = useMemo9(() => {
1477
+ return [
1478
+ Prec.highest(keymap.of([
1479
+ {
1480
+ key: "Mod-d",
1481
+ preventDefault: true,
1482
+ run: () => {
1483
+ event.emit({
1484
+ type: "toggle-debug"
1485
+ });
1486
+ return true;
1487
+ }
1488
+ },
1489
+ {
1490
+ key: "Mod-ArrowUp",
1491
+ preventDefault: true,
1492
+ run: () => {
1493
+ event.emit({
1494
+ type: "nav-previous"
1495
+ });
1496
+ return true;
1497
+ },
1498
+ shift: () => {
1499
+ event.emit({
1500
+ type: "thread-open"
1501
+ });
1502
+ return true;
1503
+ }
1504
+ },
1505
+ {
1506
+ key: "Mod-ArrowDown",
1507
+ preventDefault: true,
1508
+ run: () => {
1509
+ event.emit({
1510
+ type: "nav-next"
1511
+ });
1512
+ return true;
1513
+ },
1514
+ shift: () => {
1515
+ event.emit({
1516
+ type: "thread-close"
1517
+ });
1518
+ return true;
1519
+ }
1520
+ }
1521
+ ]))
1522
+ ].filter(isTruthy);
1523
+ }, [
1524
+ event,
1525
+ expandable
1526
+ ]);
1527
+ const handleSubmit = useCallback7((text) => {
1528
+ if (!activeRef.current) {
1529
+ event.emit({
1530
+ type: "submit",
1531
+ text
1532
+ });
1533
+ return true;
1534
+ }
1535
+ }, [
1536
+ event
1537
+ ]);
1538
+ const handleEvent = useCallback7((ev) => {
1539
+ event.emit(ev);
1540
+ }, [
1541
+ event
1542
+ ]);
1543
+ return /* @__PURE__ */ React10.createElement("div", {
1544
+ role: "group",
1545
+ 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)
1546
+ }, /* @__PURE__ */ React10.createElement("div", {
1547
+ role: "none",
1548
+ className: "flex p-2 gap-2"
1549
+ }, /* @__PURE__ */ React10.createElement(ChatStatusIndicator, {
1550
+ classNames: "p-1",
1551
+ preset,
1552
+ error,
1553
+ processing: streaming
1554
+ }), /* @__PURE__ */ React10.createElement(ChatEditor, {
1555
+ ref: editorRef,
1556
+ autoFocus: true,
1557
+ lineWrapping: true,
1558
+ classNames: "col-span-2 pbs-0.5",
1559
+ placeholder: placeholder ?? t("prompt placeholder"),
1560
+ extensions,
1561
+ onSubmit: handleSubmit
1562
+ })), space && settings && /* @__PURE__ */ React10.createElement("div", {
1563
+ role: "none",
1564
+ className: "flex items-center overflow-hidden"
1565
+ }, /* @__PURE__ */ React10.createElement(ChatOptions, {
1566
+ space,
1567
+ blueprintRegistry: processor.blueprintRegistry,
1568
+ context: processor.context,
1569
+ preset,
1570
+ presets,
1571
+ onPresetChange
1572
+ }), /* @__PURE__ */ React10.createElement("div", {
1573
+ role: "none",
1574
+ className: "flex grow overflow-x-auto scrollbar-none"
1575
+ }, /* @__PURE__ */ React10.createElement(ChatReferences, {
1576
+ space,
1577
+ context: processor.context
1578
+ })), /* @__PURE__ */ React10.createElement(ChatActions, {
1579
+ classNames: "col-span-2",
1580
+ microphone: true,
1581
+ recording,
1582
+ processing: streaming,
1583
+ onEvent: handleEvent
1584
+ }, online !== void 0 && /* @__PURE__ */ React10.createElement(Input2.Root, null, /* @__PURE__ */ React10.createElement(Input2.Label, {
1585
+ srOnly: true
1586
+ }, t("online switch label")), /* @__PURE__ */ React10.createElement(Input2.Switch, {
1587
+ classNames: "mli-2",
1588
+ checked: online,
1589
+ onCheckedChange: onOnlineChange
1590
+ })))));
1591
+ } finally {
1592
+ _effect.f();
1593
+ }
1594
+ };
1595
+ ChatPrompt.displayName = "Chat.Prompt";
1596
+ var ChatThread2 = (props) => {
1597
+ var _effect = _useSignals12();
1598
+ try {
1599
+ const { debug, event, messages, processor } = useChatContext(ChatThread2.displayName);
1600
+ const identity = useIdentity();
1601
+ const error = useAtomValue(processor.error).pipe(Option2.getOrUndefined);
1602
+ const controllerRef = useRef3(null);
1603
+ useEffect6(() => {
1604
+ return event.on((event2) => {
1605
+ switch (event2.type) {
1606
+ case "submit":
1607
+ case "scroll-to-bottom":
1608
+ controllerRef.current?.scrollToBottom();
1609
+ break;
1610
+ case "nav-previous":
1611
+ controllerRef.current?.navigatePrevious();
1612
+ break;
1613
+ case "nav-next":
1614
+ controllerRef.current?.navigateNext();
1615
+ break;
1616
+ }
1617
+ });
1618
+ }, [
1619
+ event
1620
+ ]);
1621
+ const handleEvent = useCallback7((ev) => {
1622
+ event.emit(ev);
1623
+ }, [
1624
+ event
1625
+ ]);
1626
+ if (!identity) {
1627
+ return null;
1628
+ }
1629
+ return /* @__PURE__ */ React10.createElement(ChatThread, {
1630
+ ...props,
1631
+ identity,
1632
+ messages,
1633
+ error,
1634
+ debug,
1635
+ onEvent: handleEvent,
1636
+ ref: controllerRef
1637
+ });
1638
+ } finally {
1639
+ _effect.f();
1640
+ }
1641
+ };
1642
+ ChatThread2.displayName = "Chat.Thread";
1643
+ var ChatToolbar = ({ classNames, companionTo }) => {
1644
+ var _effect = _useSignals12();
1645
+ try {
1646
+ const { chat } = useChatContext(ChatToolbar.displayName);
1647
+ const menu = useChatToolbarActions({
1648
+ chat,
1649
+ companionTo
1650
+ });
1651
+ return /* @__PURE__ */ React10.createElement(MenuProvider, {
1652
+ ...menu,
1653
+ attendableId: companionTo ? Obj5.getDXN(companionTo).toString() : chat ? Obj5.getDXN(chat).toString() : ""
1654
+ }, /* @__PURE__ */ React10.createElement(ToolbarMenu, {
1655
+ classNames,
1656
+ textBlockWidth: true
1657
+ }));
1658
+ } finally {
1659
+ _effect.f();
1660
+ }
1661
+ };
1662
+ ChatToolbar.displayName = "Chat.Toolbar";
1663
+ var Chat = {
1664
+ Root: ChatRoot,
1665
+ Viewport: ChatViewport,
1666
+ Prompt: ChatPrompt,
1667
+ Thread: ChatThread2,
1668
+ Toolbar: ChatToolbar
1669
+ };
1670
+
1671
+ // src/components/Toolbox/Toolbox.tsx
1672
+ import { useSignals as _useSignals13 } from "@preact-signals/safe-react/tracking";
1673
+ import React11, { Fragment, useEffect as useEffect7, useState as useState12 } from "react";
1674
+ import { Function } from "@dxos/functions";
1675
+ import { log as log5 } from "@dxos/log";
1676
+ import { Filter as Filter4, useQuery as useQuery3 } from "@dxos/react-client/echo";
1677
+ import { useTranslation as useTranslation7 } from "@dxos/react-ui";
1678
+ import { mx as mx6 } from "@dxos/react-ui-theme";
1679
+ var __dxlog_file5 = "/__w/dxos/dxos/packages/plugins/plugin-assistant/src/components/Toolbox/Toolbox.tsx";
1680
+ var Toolbox = ({ classNames, functions, services, blueprints, activeBlueprints }) => {
1681
+ var _effect = _useSignals13();
1682
+ try {
1683
+ const { t } = useTranslation7(meta.id);
1684
+ return /* @__PURE__ */ React11.createElement("div", {
1685
+ className: mx6("flex flex-col overflow-y-auto box-content", classNames)
1686
+ }, blueprints && blueprints.length > 0 && /* @__PURE__ */ React11.createElement(Section, {
1687
+ title: "Blueprints",
1688
+ items: blueprints.map(({ target }) => ({
1689
+ name: target?.name ?? "",
1690
+ description: target?.description ?? "",
1691
+ subitems: target?.tools.map((toolId) => ({
1692
+ name: `\u2219 ${safeToolId(toolId)}`
1693
+ }))
1694
+ }))
1695
+ }), activeBlueprints && activeBlueprints.length > 0 && /* @__PURE__ */ React11.createElement(Section, {
1696
+ title: "Blueprints",
1697
+ items: activeBlueprints.map(({ target }) => ({
1698
+ name: target?.name ?? "",
1699
+ description: target?.description ?? "",
1700
+ subitems: target?.tools.map((toolId) => ({
1701
+ name: `\u2219 ${safeToolId(toolId)}`
1702
+ }))
1703
+ }))
1704
+ }), services && services.length > 0 && /* @__PURE__ */ React11.createElement(Section, {
1705
+ title: "Services",
1706
+ items: services.map(({ service: { serviceId, name, description } }) => ({
1707
+ name: name ?? serviceId,
1708
+ description
1709
+ }))
1710
+ }), functions && functions.length > 0 && /* @__PURE__ */ React11.createElement(Section, {
1711
+ title: "Functions",
1712
+ items: functions.map(({ name, description }) => ({
1713
+ name,
1714
+ description
1715
+ }))
1716
+ }));
1717
+ } finally {
1718
+ _effect.f();
1719
+ }
1720
+ };
1721
+ var Section = ({ title, items, striped }) => {
1722
+ var _effect = _useSignals13();
1723
+ try {
1724
+ const stripeClassNames = "odd:bg-neutral-50 dark:odd:bg-neutral-800";
1725
+ const gridClassNames = "grid grid-cols-[8rem_1fr]";
1726
+ const subGridClassNames = mx6("col-span-full grid grid-cols-subgrid text-xs pli-2", striped && stripeClassNames);
1727
+ return /* @__PURE__ */ React11.createElement("div", null, /* @__PURE__ */ React11.createElement("h1", {
1728
+ className: "pli-2 text-sm"
1729
+ }, title), /* @__PURE__ */ React11.createElement("div", {
1730
+ className: gridClassNames
1731
+ }, items.map(({ name, description, subitems }, i) => /* @__PURE__ */ React11.createElement(Fragment, {
1732
+ key: i
1733
+ }, name && /* @__PURE__ */ React11.createElement("div", {
1734
+ className: subGridClassNames
1735
+ }, /* @__PURE__ */ React11.createElement("div", {
1736
+ className: "truncate text-primary-500"
1737
+ }, name), /* @__PURE__ */ React11.createElement("div", {
1738
+ className: "line-clamp-2"
1739
+ }, description)), subitems?.map(({ name: name2, description: description2 }, i2) => /* @__PURE__ */ React11.createElement("div", {
1740
+ key: i2,
1741
+ className: mx6(subGridClassNames, striped && stripeClassNames)
1742
+ }, /* @__PURE__ */ React11.createElement("div", {
1743
+ className: "truncate"
1744
+ }, name2), /* @__PURE__ */ React11.createElement("div", {
1745
+ className: "line-clamp-3 text-subdued"
1746
+ }, description2)))))));
1747
+ } finally {
1748
+ _effect.f();
1749
+ }
1750
+ };
1751
+ var ToolboxContainer = ({ classNames, space, processor }) => {
1752
+ var _effect = _useSignals13();
1753
+ try {
1754
+ const services = useQuery3(space, Filter4.type(ServiceType));
1755
+ const [serviceTools, setServiceTools] = useState12([]);
1756
+ useEffect7(() => {
1757
+ log5("creating service tools...", {
1758
+ services: services.length
1759
+ }, {
1760
+ F: __dxlog_file5,
1761
+ L: 117,
1762
+ S: void 0,
1763
+ C: (f, a) => f(...a)
1764
+ });
1765
+ queueMicrotask(async () => {
1766
+ });
1767
+ }, [
1768
+ services
1769
+ ]);
1770
+ const functions = useQuery3(space, Filter4.type(Function.Function));
1771
+ return /* @__PURE__ */ React11.createElement(Toolbox, {
1772
+ classNames,
1773
+ blueprints: processor?.context.blueprints.value,
1774
+ services: serviceTools,
1775
+ functions
1776
+ });
1777
+ } finally {
1778
+ _effect.f();
1779
+ }
1780
+ };
1781
+ var safeToolId = (name) => {
1782
+ return name.split("_").pop();
1783
+ };
1784
+
1785
+ // src/components/index.ts
1786
+ var BlueprintArticle = lazy(() => import("./BlueprintArticle-R2XYBRCK.mjs"));
1787
+ var ChatCompanion = lazy(() => import("./ChatCompanion-O4T7PMMC.mjs"));
1788
+ var ChatContainer = lazy(() => import("./ChatContainer-OWAZI6ZF.mjs"));
1789
+ var ChatDialog = lazy(() => import("./ChatDialog-IBXH5FRI.mjs"));
1790
+ var PromptArticle = lazy(() => import("./PromptArticle-IV7O5UZ3.mjs"));
1791
+
1792
+ // src/hooks/useChatToolbarActions.ts
1793
+ var __dxlog_file6 = "/__w/dxos/dxos/packages/plugins/plugin-assistant/src/hooks/useChatToolbarActions.ts";
1794
+ var useChatToolbarActions = ({ chat, companionTo }) => {
1795
+ const { dispatch } = useIntentDispatcher();
1796
+ const { space } = useChatContext("useChatToolbarActions");
1797
+ const query = companionTo ? Query.select(Filter5.id(companionTo.id)).targetOf(Assistant_exports.CompanionTo).source() : Query.select(Filter5.nothing());
1798
+ const chats = useQuery4(space, query);
1799
+ return useMenuActions(useMemo10(() => {
1800
+ return Atom.make(() => {
1801
+ const builder = MenuBuilder.make().root({
1802
+ label: [
1803
+ "chat toolbar title",
1804
+ {
1805
+ ns: meta.id
1806
+ }
1807
+ ]
1808
+ }).action("new", {
1809
+ label: [
1810
+ "new thread button",
1811
+ {
1812
+ ns: meta.id
1813
+ }
1814
+ ],
1815
+ icon: "ph--plus--regular",
1816
+ type: "new"
1817
+ }, () => dispatch(createIntent(AssistantAction_exports.SetCurrentChat, {
1818
+ companionTo,
1819
+ chat: void 0
1820
+ })).pipe(Effect2.runPromise)).action("rename", {
1821
+ label: [
1822
+ "rename thread button",
1823
+ {
1824
+ ns: meta.id
1825
+ }
1826
+ ],
1827
+ icon: "ph--magic-wand--regular",
1828
+ type: "rename",
1829
+ disabled: !chat
1830
+ }, () => Effect2.gen(function* () {
1831
+ invariant(chat, void 0, {
1832
+ F: __dxlog_file6,
1833
+ L: 68,
1834
+ S: this,
1835
+ A: [
1836
+ "chat",
1837
+ ""
1838
+ ]
1839
+ });
1840
+ yield* dispatch(createIntent(AssistantAction_exports.UpdateChatName, {
1841
+ chat
1842
+ }));
1843
+ }).pipe(Effect2.runPromise)).action("branch", {
1844
+ label: [
1845
+ "button branch thread",
1846
+ {
1847
+ ns: meta.id
1848
+ }
1849
+ ],
1850
+ icon: "ph--git-branch--regular",
1851
+ type: "branch",
1852
+ disabled: true
1853
+ }, () => {
1854
+ });
1855
+ if (chats.length > 0) {
1856
+ builder.group("chats", {
1857
+ label: [
1858
+ "chat history label",
1859
+ {
1860
+ ns: meta.id
1861
+ }
1862
+ ],
1863
+ icon: "ph--clock-counter-clockwise--regular",
1864
+ selectCardinality: "single",
1865
+ variant: "dropdownMenu"
1866
+ }, (builder2) => {
1867
+ chats.toSorted((a, b) => a.id.localeCompare(b.id)).forEach((chat2) => {
1868
+ builder2.action(chat2.id, {
1869
+ label: Obj6.getLabel(chat2) ?? [
1870
+ "object name placeholder",
1871
+ {
1872
+ ns: Assistant_exports.Chat.typename
1873
+ }
1874
+ ]
1875
+ }, () => Effect2.gen(function* () {
1876
+ invariant(companionTo, void 0, {
1877
+ F: __dxlog_file6,
1878
+ L: 104,
1879
+ S: this,
1880
+ A: [
1881
+ "companionTo",
1882
+ ""
1883
+ ]
1884
+ });
1885
+ yield* dispatch(createIntent(AssistantAction_exports.SetCurrentChat, {
1886
+ companionTo,
1887
+ chat: chat2
1888
+ }));
1889
+ }).pipe(Effect2.runPromise));
1890
+ });
1891
+ });
1892
+ }
1893
+ return builder.build();
1894
+ });
1895
+ }, [
1896
+ chats.length,
1897
+ space?.id,
1898
+ companionTo?.id,
1899
+ chat?.id,
1900
+ dispatch
1901
+ ]));
1902
+ };
1903
+
1904
+ export {
1905
+ AssistantSettings,
1906
+ useBlueprintRegistry,
1907
+ useBlueprints,
1908
+ useActiveBlueprints,
1909
+ useBlueprintHandlers,
1910
+ useChatProcessor,
1911
+ useChatServices,
1912
+ useChatToolbarActions,
1913
+ useContextBinder,
1914
+ useContextObjects,
1915
+ useFilteredTypes,
1916
+ useFlush,
1917
+ useOnline,
1918
+ usePresets,
1919
+ useReferencesProvider,
1920
+ ChatContextProvider,
1921
+ useChatContext,
1922
+ Chat,
1923
+ Toolbox,
1924
+ ToolboxContainer,
1925
+ BlueprintArticle,
1926
+ ChatCompanion,
1927
+ ChatContainer,
1928
+ ChatDialog,
1929
+ PromptArticle
1930
+ };
1931
+ //# sourceMappingURL=chunk-ZNSHGWE4.mjs.map