@dxos/plugin-assistant 0.8.4-main.ae835ea → 0.8.4-main.bc674ce

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