@dxos/plugin-assistant 0.8.4-main.937b3ca → 0.8.4-main.9be5663bfe

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 (607) hide show
  1. package/dist/lib/browser/AssistantSettings-7QMO3LGF.mjs +97 -0
  2. package/dist/lib/browser/AssistantSettings-7QMO3LGF.mjs.map +7 -0
  3. package/dist/lib/browser/blueprints/index.mjs +3 -7
  4. package/dist/lib/browser/chunk-ATHYBVGN.mjs +176 -0
  5. package/dist/lib/browser/chunk-ATHYBVGN.mjs.map +7 -0
  6. package/dist/lib/browser/chunk-EZRS3J25.mjs +30 -0
  7. package/dist/lib/browser/chunk-EZRS3J25.mjs.map +7 -0
  8. package/dist/lib/browser/chunk-RUV2WOQH.mjs +154 -0
  9. package/dist/lib/browser/chunk-RUV2WOQH.mjs.map +7 -0
  10. package/dist/lib/browser/create-chat-LBZHGVSN.mjs +82 -0
  11. package/dist/lib/browser/create-chat-LBZHGVSN.mjs.map +7 -0
  12. package/dist/lib/browser/ensure-companion-chat-FR4AWZ2P.mjs +65 -0
  13. package/dist/lib/browser/ensure-companion-chat-FR4AWZ2P.mjs.map +7 -0
  14. package/dist/lib/browser/index.mjs +3163 -245
  15. package/dist/lib/browser/index.mjs.map +4 -4
  16. package/dist/lib/browser/meta.json +1 -1
  17. package/dist/lib/browser/on-create-space-54RNX5JI.mjs +22 -0
  18. package/dist/lib/browser/on-create-space-54RNX5JI.mjs.map +7 -0
  19. package/dist/lib/browser/operations/index.mjs +13 -0
  20. package/dist/lib/browser/operations/index.mjs.map +7 -0
  21. package/dist/lib/browser/resolve-navigation-targets-NZOD66NY.mjs +22 -0
  22. package/dist/lib/browser/resolve-navigation-targets-NZOD66NY.mjs.map +7 -0
  23. package/dist/lib/browser/run-prompt-in-new-chat-4YQ37XIS.mjs +136 -0
  24. package/dist/lib/browser/run-prompt-in-new-chat-4YQ37XIS.mjs.map +7 -0
  25. package/dist/lib/browser/set-current-chat-WJI3WAVM.mjs +54 -0
  26. package/dist/lib/browser/set-current-chat-WJI3WAVM.mjs.map +7 -0
  27. package/dist/lib/browser/types/index.mjs +1 -4
  28. package/dist/lib/browser/update-chat-name-3Y36KFAS.mjs +71 -0
  29. package/dist/lib/browser/update-chat-name-3Y36KFAS.mjs.map +7 -0
  30. package/dist/lib/node-esm/AssistantSettings-UVUTKO7E.mjs +98 -0
  31. package/dist/lib/node-esm/AssistantSettings-UVUTKO7E.mjs.map +7 -0
  32. package/dist/lib/node-esm/blueprints/index.mjs +3 -7
  33. package/dist/lib/node-esm/chunk-NZIKC7AN.mjs +32 -0
  34. package/dist/lib/node-esm/chunk-NZIKC7AN.mjs.map +7 -0
  35. package/dist/lib/node-esm/chunk-PXAJSTGZ.mjs +177 -0
  36. package/dist/lib/node-esm/chunk-PXAJSTGZ.mjs.map +7 -0
  37. package/dist/lib/node-esm/chunk-PY4X6FJT.mjs +155 -0
  38. package/dist/lib/node-esm/chunk-PY4X6FJT.mjs.map +7 -0
  39. package/dist/lib/node-esm/create-chat-3BEG4R6J.mjs +83 -0
  40. package/dist/lib/node-esm/create-chat-3BEG4R6J.mjs.map +7 -0
  41. package/dist/lib/node-esm/ensure-companion-chat-BLP7NT32.mjs +66 -0
  42. package/dist/lib/node-esm/ensure-companion-chat-BLP7NT32.mjs.map +7 -0
  43. package/dist/lib/node-esm/index.mjs +3163 -245
  44. package/dist/lib/node-esm/index.mjs.map +4 -4
  45. package/dist/lib/node-esm/meta.json +1 -1
  46. package/dist/lib/node-esm/on-create-space-YRPZ6HZY.mjs +23 -0
  47. package/dist/lib/node-esm/on-create-space-YRPZ6HZY.mjs.map +7 -0
  48. package/dist/lib/node-esm/operations/index.mjs +14 -0
  49. package/dist/lib/node-esm/operations/index.mjs.map +7 -0
  50. package/dist/lib/node-esm/resolve-navigation-targets-3PPK7XLH.mjs +23 -0
  51. package/dist/lib/node-esm/resolve-navigation-targets-3PPK7XLH.mjs.map +7 -0
  52. package/dist/lib/node-esm/run-prompt-in-new-chat-2IJBSDTM.mjs +137 -0
  53. package/dist/lib/node-esm/run-prompt-in-new-chat-2IJBSDTM.mjs.map +7 -0
  54. package/dist/lib/node-esm/set-current-chat-KBMMZULR.mjs +55 -0
  55. package/dist/lib/node-esm/set-current-chat-KBMMZULR.mjs.map +7 -0
  56. package/dist/lib/node-esm/types/index.mjs +1 -4
  57. package/dist/lib/node-esm/update-chat-name-HM2P4NSI.mjs +72 -0
  58. package/dist/lib/node-esm/update-chat-name-HM2P4NSI.mjs.map +7 -0
  59. package/dist/types/src/AssistantPlugin.d.ts.map +1 -1
  60. package/dist/types/src/blueprints/assistant/blueprint.d.ts +4 -0
  61. package/dist/types/src/blueprints/assistant/blueprint.d.ts.map +1 -0
  62. package/dist/types/src/blueprints/assistant/blueprint.test.d.ts +2 -0
  63. package/dist/types/src/blueprints/assistant/blueprint.test.d.ts.map +1 -0
  64. package/dist/types/src/blueprints/assistant/index.d.ts +2 -0
  65. package/dist/types/src/blueprints/assistant/index.d.ts.map +1 -0
  66. package/dist/types/src/blueprints/index.d.ts +1 -6
  67. package/dist/types/src/blueprints/index.d.ts.map +1 -1
  68. package/dist/types/src/capabilities/ai-service.d.ts +6 -0
  69. package/dist/types/src/capabilities/ai-service.d.ts.map +1 -0
  70. package/dist/types/src/capabilities/app-graph-builder.d.ts +6 -0
  71. package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -0
  72. package/dist/types/src/capabilities/blueprint-definition.d.ts +5 -0
  73. package/dist/types/src/capabilities/blueprint-definition.d.ts.map +1 -0
  74. package/dist/types/src/capabilities/companion-chat-provisioner.d.ts +9 -0
  75. package/dist/types/src/capabilities/companion-chat-provisioner.d.ts.map +1 -0
  76. package/dist/types/src/capabilities/edge-model-resolver.d.ts +7 -0
  77. package/dist/types/src/capabilities/edge-model-resolver.d.ts.map +1 -0
  78. package/dist/types/src/capabilities/index.d.ts +41 -11
  79. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  80. package/dist/types/src/capabilities/local-model-resolver.d.ts +13 -0
  81. package/dist/types/src/capabilities/local-model-resolver.d.ts.map +1 -0
  82. package/dist/types/src/capabilities/markdown.d.ts +5 -0
  83. package/dist/types/src/capabilities/markdown.d.ts.map +1 -0
  84. package/dist/types/src/capabilities/migrations.d.ts +5 -0
  85. package/dist/types/src/capabilities/migrations.d.ts.map +1 -0
  86. package/dist/types/src/capabilities/operation-handler.d.ts +6 -0
  87. package/dist/types/src/capabilities/operation-handler.d.ts.map +1 -0
  88. package/dist/types/src/capabilities/react-surface.d.ts +5 -0
  89. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -0
  90. package/dist/types/src/capabilities/{settings/settings.d.ts → settings.d.ts} +4 -3
  91. package/dist/types/src/capabilities/settings.d.ts.map +1 -0
  92. package/dist/types/src/capabilities/state.d.ts +21 -0
  93. package/dist/types/src/capabilities/state.d.ts.map +1 -0
  94. package/dist/types/src/capabilities/toolkit.d.ts +6 -0
  95. package/dist/types/src/capabilities/toolkit.d.ts.map +1 -0
  96. package/dist/types/src/components/AssistantSettings/AssistantSettings.d.ts +4 -6
  97. package/dist/types/src/components/AssistantSettings/AssistantSettings.d.ts.map +1 -1
  98. package/dist/types/src/components/AssistantSettings/AssistantSettings.stories.d.ts +553 -0
  99. package/dist/types/src/components/AssistantSettings/AssistantSettings.stories.d.ts.map +1 -0
  100. package/dist/types/src/components/AssistantSettings/index.d.ts +1 -1
  101. package/dist/types/src/components/AssistantSettings/index.d.ts.map +1 -1
  102. package/dist/types/src/components/Chat/Chat.d.ts +15 -11
  103. package/dist/types/src/components/Chat/Chat.d.ts.map +1 -1
  104. package/dist/types/src/components/ChatProgress/ChatProgress.d.ts +6 -3
  105. package/dist/types/src/components/ChatProgress/ChatProgress.d.ts.map +1 -1
  106. package/dist/types/src/components/ChatPrompt/ChatActions.d.ts +2 -1
  107. package/dist/types/src/components/ChatPrompt/ChatActions.d.ts.map +1 -1
  108. package/dist/types/src/components/ChatPrompt/ChatOptions.d.ts.map +1 -1
  109. package/dist/types/src/components/ChatPrompt/ChatReferences.d.ts.map +1 -1
  110. package/dist/types/src/components/ChatThread/ChatThread.d.ts +3 -3
  111. package/dist/types/src/components/ChatThread/ChatThread.d.ts.map +1 -1
  112. package/dist/types/src/components/ChatThread/ChatThread.stories.d.ts +535 -303
  113. package/dist/types/src/components/ChatThread/ChatThread.stories.d.ts.map +1 -1
  114. package/dist/types/src/components/ChatThread/MarkdownStream.stories.d.ts +573 -0
  115. package/dist/types/src/components/ChatThread/MarkdownStream.stories.d.ts.map +1 -0
  116. package/dist/types/src/components/ChatThread/registry.d.ts.map +1 -1
  117. package/dist/types/src/components/ChatThread/sync.d.ts +6 -5
  118. package/dist/types/src/components/ChatThread/sync.d.ts.map +1 -1
  119. package/dist/types/src/components/ChatThread/tool-widget-state.d.ts +18 -0
  120. package/dist/types/src/components/ChatThread/tool-widget-state.d.ts.map +1 -0
  121. package/dist/types/src/components/ChatThread/tool-widget-state.test.d.ts +2 -0
  122. package/dist/types/src/components/ChatThread/tool-widget-state.test.d.ts.map +1 -0
  123. package/dist/types/src/components/ChatThread/widgets/FallbackWidget.d.ts +8 -0
  124. package/dist/types/src/components/ChatThread/widgets/FallbackWidget.d.ts.map +1 -0
  125. package/dist/types/src/components/ChatThread/widgets/PromptWidget.d.ts +14 -0
  126. package/dist/types/src/components/ChatThread/widgets/PromptWidget.d.ts.map +1 -0
  127. package/dist/types/src/components/ChatThread/widgets/ReasoningWidget.d.ts +25 -0
  128. package/dist/types/src/components/ChatThread/widgets/ReasoningWidget.d.ts.map +1 -0
  129. package/dist/types/src/components/ChatThread/widgets/ReasoningWidget.stories.d.ts +18 -0
  130. package/dist/types/src/components/ChatThread/widgets/ReasoningWidget.stories.d.ts.map +1 -0
  131. package/dist/types/src/components/ChatThread/widgets/ReferenceWidget.d.ts +9 -0
  132. package/dist/types/src/components/ChatThread/widgets/ReferenceWidget.d.ts.map +1 -0
  133. package/dist/types/src/components/ChatThread/widgets/SelectWidget.d.ts +14 -0
  134. package/dist/types/src/components/ChatThread/widgets/SelectWidget.d.ts.map +1 -0
  135. package/dist/types/src/components/ChatThread/widgets/StatsWidget.d.ts +12 -0
  136. package/dist/types/src/components/ChatThread/widgets/StatsWidget.d.ts.map +1 -0
  137. package/dist/types/src/components/ChatThread/widgets/StatusWidget.d.ts +25 -0
  138. package/dist/types/src/components/ChatThread/widgets/StatusWidget.d.ts.map +1 -0
  139. package/dist/types/src/components/ChatThread/widgets/SuggestionWidget.d.ts +11 -0
  140. package/dist/types/src/components/ChatThread/widgets/SuggestionWidget.d.ts.map +1 -0
  141. package/dist/types/src/components/ChatThread/widgets/SummaryWidget.d.ts +5 -0
  142. package/dist/types/src/components/ChatThread/widgets/SummaryWidget.d.ts.map +1 -0
  143. package/dist/types/src/components/ChatThread/widgets/ToolWidget.d.ts +9 -0
  144. package/dist/types/src/components/ChatThread/widgets/ToolWidget.d.ts.map +1 -0
  145. package/dist/types/src/components/ChatThread/widgets/ToolWidget.stories.d.ts +553 -0
  146. package/dist/types/src/components/ChatThread/widgets/ToolWidget.stories.d.ts.map +1 -0
  147. package/dist/types/src/components/ChatThread/widgets/index.d.ts +11 -0
  148. package/dist/types/src/components/ChatThread/widgets/index.d.ts.map +1 -0
  149. package/dist/types/src/components/ProcessTree/ProcessTree.d.ts +10 -0
  150. package/dist/types/src/components/ProcessTree/ProcessTree.d.ts.map +1 -0
  151. package/dist/types/src/components/ProcessTree/ProcessTree.stories.d.ts +8 -0
  152. package/dist/types/src/components/ProcessTree/ProcessTree.stories.d.ts.map +1 -0
  153. package/dist/types/src/components/ProcessTree/index.d.ts +2 -0
  154. package/dist/types/src/components/ProcessTree/index.d.ts.map +1 -0
  155. package/dist/types/src/components/TemplateEditor/TemplateEditor.d.ts +5 -4
  156. package/dist/types/src/components/TemplateEditor/TemplateEditor.d.ts.map +1 -1
  157. package/dist/types/src/components/TemplateEditor/TemplateEditor.stories.d.ts +529 -295
  158. package/dist/types/src/components/TemplateEditor/TemplateEditor.stories.d.ts.map +1 -1
  159. package/dist/types/src/components/TemplateEditor/TemplateForm.d.ts.map +1 -1
  160. package/dist/types/src/components/TemplateEditor/TemplateForm.stories.d.ts +529 -295
  161. package/dist/types/src/components/TemplateEditor/TemplateForm.stories.d.ts.map +1 -1
  162. package/dist/types/src/components/ToolBlock/ToolBlock.d.ts +0 -9
  163. package/dist/types/src/components/ToolBlock/ToolBlock.d.ts.map +1 -1
  164. package/dist/types/src/components/Toolbox/Toolbox.d.ts +10 -8
  165. package/dist/types/src/components/Toolbox/Toolbox.d.ts.map +1 -1
  166. package/dist/types/src/components/Toolbox/Toolbox.stories.d.ts +529 -295
  167. package/dist/types/src/components/Toolbox/Toolbox.stories.d.ts.map +1 -1
  168. package/dist/types/src/components/Typewriter/AssistantToolbar.d.ts +2 -2
  169. package/dist/types/src/components/Typewriter/AssistantToolbar.d.ts.map +1 -1
  170. package/dist/types/src/components/Typewriter/Typewriter.d.ts.map +1 -1
  171. package/dist/types/src/components/Typewriter/Typewriter.stories.d.ts.map +1 -1
  172. package/dist/types/src/components/index.d.ts +3 -12
  173. package/dist/types/src/components/index.d.ts.map +1 -1
  174. package/dist/types/src/containers/AgentArticle/AgentArticle.d.ts +6 -0
  175. package/dist/types/src/containers/AgentArticle/AgentArticle.d.ts.map +1 -0
  176. package/dist/types/src/containers/AgentArticle/AgentArticle.stories.d.ts +554 -0
  177. package/dist/types/src/containers/AgentArticle/AgentArticle.stories.d.ts.map +1 -0
  178. package/dist/types/src/containers/AgentArticle/index.d.ts +2 -0
  179. package/dist/types/src/containers/AgentArticle/index.d.ts.map +1 -0
  180. package/dist/types/src/containers/AgentProperties/AgentProperties.d.ts +6 -0
  181. package/dist/types/src/containers/AgentProperties/AgentProperties.d.ts.map +1 -0
  182. package/dist/types/src/containers/AgentProperties/AgentProperties.stories.d.ts +554 -0
  183. package/dist/types/src/containers/AgentProperties/AgentProperties.stories.d.ts.map +1 -0
  184. package/dist/types/src/containers/AgentProperties/index.d.ts +2 -0
  185. package/dist/types/src/containers/AgentProperties/index.d.ts.map +1 -0
  186. package/dist/types/src/containers/BlueprintArticle/BlueprintArticle.d.ts +6 -0
  187. package/dist/types/src/containers/BlueprintArticle/BlueprintArticle.d.ts.map +1 -0
  188. package/dist/types/src/containers/BlueprintArticle/index.d.ts +2 -0
  189. package/dist/types/src/containers/BlueprintArticle/index.d.ts.map +1 -0
  190. package/dist/types/src/containers/ChatCompanion/ChatCompanion.d.ts +18 -0
  191. package/dist/types/src/containers/ChatCompanion/ChatCompanion.d.ts.map +1 -0
  192. package/dist/types/src/containers/ChatCompanion/index.d.ts +2 -0
  193. package/dist/types/src/containers/ChatCompanion/index.d.ts.map +1 -0
  194. package/dist/types/src/containers/ChatContainer/ChatContainer.d.ts +12 -0
  195. package/dist/types/src/containers/ChatContainer/ChatContainer.d.ts.map +1 -0
  196. package/dist/types/src/containers/ChatContainer/index.d.ts +2 -0
  197. package/dist/types/src/containers/ChatContainer/index.d.ts.map +1 -0
  198. package/dist/types/src/{components → containers/ChatDialog}/ChatDialog.d.ts +2 -3
  199. package/dist/types/src/containers/ChatDialog/ChatDialog.d.ts.map +1 -0
  200. package/dist/types/src/containers/ChatDialog/index.d.ts +2 -0
  201. package/dist/types/src/containers/ChatDialog/index.d.ts.map +1 -0
  202. package/dist/types/src/containers/PromptArticle/PromptArticle.d.ts +6 -0
  203. package/dist/types/src/containers/PromptArticle/PromptArticle.d.ts.map +1 -0
  204. package/dist/types/src/containers/PromptArticle/index.d.ts +2 -0
  205. package/dist/types/src/containers/PromptArticle/index.d.ts.map +1 -0
  206. package/dist/types/src/containers/PromptList/PromptList.d.ts +6 -0
  207. package/dist/types/src/containers/PromptList/PromptList.d.ts.map +1 -0
  208. package/dist/types/src/containers/PromptList/PromptList.stories.d.ts +559 -0
  209. package/dist/types/src/containers/PromptList/PromptList.stories.d.ts.map +1 -0
  210. package/dist/types/src/containers/PromptList/index.d.ts +2 -0
  211. package/dist/types/src/containers/PromptList/index.d.ts.map +1 -0
  212. package/dist/types/src/containers/TracePanel/TracePanel.d.ts +6 -0
  213. package/dist/types/src/containers/TracePanel/TracePanel.d.ts.map +1 -0
  214. package/dist/types/src/containers/TracePanel/dxn-extractor.d.ts +19 -0
  215. package/dist/types/src/containers/TracePanel/dxn-extractor.d.ts.map +1 -0
  216. package/dist/types/src/containers/TracePanel/dxn-extractor.test.d.ts +2 -0
  217. package/dist/types/src/containers/TracePanel/dxn-extractor.test.d.ts.map +1 -0
  218. package/dist/types/src/containers/TracePanel/index.d.ts +4 -0
  219. package/dist/types/src/containers/TracePanel/index.d.ts.map +1 -0
  220. package/dist/types/src/containers/TriggerStatus/TriggerStatus.d.ts +4 -0
  221. package/dist/types/src/containers/TriggerStatus/TriggerStatus.d.ts.map +1 -0
  222. package/dist/types/src/containers/TriggerStatus/index.d.ts +2 -0
  223. package/dist/types/src/containers/TriggerStatus/index.d.ts.map +1 -0
  224. package/dist/types/src/containers/index.d.ts +12 -0
  225. package/dist/types/src/containers/index.d.ts.map +1 -0
  226. package/dist/types/src/extensions/index.d.ts +2 -0
  227. package/dist/types/src/extensions/index.d.ts.map +1 -0
  228. package/dist/types/src/extensions/prompt-extension.d.ts +10 -0
  229. package/dist/types/src/extensions/prompt-extension.d.ts.map +1 -0
  230. package/dist/types/src/hooks/useBlueprintRegistry.d.ts.map +1 -1
  231. package/dist/types/src/hooks/useChatProcessor.d.ts +7 -6
  232. package/dist/types/src/hooks/useChatProcessor.d.ts.map +1 -1
  233. package/dist/types/src/hooks/useChatServices.d.ts +3 -6
  234. package/dist/types/src/hooks/useChatServices.d.ts.map +1 -1
  235. package/dist/types/src/hooks/useChatToolbarActions.d.ts +2 -2
  236. package/dist/types/src/hooks/useChatToolbarActions.d.ts.map +1 -1
  237. package/dist/types/src/hooks/useContextBinder.d.ts +3 -2
  238. package/dist/types/src/hooks/useContextBinder.d.ts.map +1 -1
  239. package/dist/types/src/hooks/useContextObjects.d.ts.map +1 -1
  240. package/dist/types/src/hooks/useFilteredTypes.d.ts +1 -1
  241. package/dist/types/src/hooks/useFilteredTypes.d.ts.map +1 -1
  242. package/dist/types/src/hooks/usePresets.d.ts +1 -1
  243. package/dist/types/src/hooks/usePresets.d.ts.map +1 -1
  244. package/dist/types/src/hooks/useReferencesProvider.d.ts.map +1 -1
  245. package/dist/types/src/index.d.ts +1 -1
  246. package/dist/types/src/index.d.ts.map +1 -1
  247. package/dist/types/src/meta.d.ts +2 -0
  248. package/dist/types/src/meta.d.ts.map +1 -1
  249. package/dist/types/src/operations/create-chat.d.ts +5 -0
  250. package/dist/types/src/operations/create-chat.d.ts.map +1 -0
  251. package/dist/types/src/operations/definitions.d.ts +135 -0
  252. package/dist/types/src/operations/definitions.d.ts.map +1 -0
  253. package/dist/types/src/operations/ensure-companion-chat.d.ts +5 -0
  254. package/dist/types/src/operations/ensure-companion-chat.d.ts.map +1 -0
  255. package/dist/types/src/operations/index.d.ts +4 -0
  256. package/dist/types/src/operations/index.d.ts.map +1 -0
  257. package/dist/types/src/operations/on-create-space.d.ts +5 -0
  258. package/dist/types/src/operations/on-create-space.d.ts.map +1 -0
  259. package/dist/types/src/operations/resolve-navigation-targets.d.ts +15 -0
  260. package/dist/types/src/operations/resolve-navigation-targets.d.ts.map +1 -0
  261. package/dist/types/src/operations/run-prompt-in-new-chat.d.ts +5 -0
  262. package/dist/types/src/operations/run-prompt-in-new-chat.d.ts.map +1 -0
  263. package/dist/types/src/operations/set-current-chat.d.ts +5 -0
  264. package/dist/types/src/operations/set-current-chat.d.ts.map +1 -0
  265. package/dist/types/src/operations/update-chat-name.d.ts +5 -0
  266. package/dist/types/src/operations/update-chat-name.d.ts.map +1 -0
  267. package/dist/types/src/processor/index.d.ts +0 -1
  268. package/dist/types/src/processor/index.d.ts.map +1 -1
  269. package/dist/types/src/processor/processor.d.ts +33 -28
  270. package/dist/types/src/processor/processor.d.ts.map +1 -1
  271. package/dist/types/src/testing/test-generator.d.ts.map +1 -1
  272. package/dist/types/src/testing/test-services.d.ts +1 -1
  273. package/dist/types/src/testing/test-services.d.ts.map +1 -1
  274. package/dist/types/src/translations.d.ts +529 -295
  275. package/dist/types/src/translations.d.ts.map +1 -1
  276. package/dist/types/src/types/Assistant.d.ts +17 -39
  277. package/dist/types/src/types/Assistant.d.ts.map +1 -1
  278. package/dist/types/src/types/Settings.d.ts +10 -0
  279. package/dist/types/src/types/Settings.d.ts.map +1 -0
  280. package/dist/types/src/types/capabilities.d.ts +11 -0
  281. package/dist/types/src/types/capabilities.d.ts.map +1 -1
  282. package/dist/types/src/types/index.d.ts +1 -1
  283. package/dist/types/src/types/index.d.ts.map +1 -1
  284. package/dist/types/src/types/service.d.ts.map +1 -1
  285. package/dist/types/tsconfig.tsbuildinfo +1 -1
  286. package/package.json +120 -92
  287. package/src/AssistantPlugin.tsx +148 -52
  288. package/src/blueprints/assistant/blueprint.conversations.json +1 -0
  289. package/src/blueprints/assistant/blueprint.test.ts +46 -0
  290. package/src/blueprints/assistant/blueprint.ts +31 -0
  291. package/src/blueprints/assistant/index.ts +5 -0
  292. package/src/blueprints/index.ts +1 -8
  293. package/src/capabilities/{ai-service/ai-service.ts → ai-service.ts} +4 -3
  294. package/src/capabilities/app-graph-builder.ts +217 -0
  295. package/src/capabilities/blueprint-definition.ts +58 -0
  296. package/src/capabilities/companion-chat-provisioner.ts +164 -0
  297. package/src/capabilities/{edge-model-resolver/edge-model-resolver.ts → edge-model-resolver.ts} +4 -3
  298. package/src/capabilities/index.ts +22 -11
  299. package/src/capabilities/{local-model-resolver/local-model-resolver.ts → local-model-resolver.ts} +4 -3
  300. package/src/capabilities/markdown.ts +40 -0
  301. package/src/capabilities/migrations.ts +34 -0
  302. package/src/capabilities/operation-handler.ts +16 -0
  303. package/src/capabilities/react-surface.tsx +157 -0
  304. package/src/capabilities/{settings/settings.ts → settings.ts} +5 -4
  305. package/src/capabilities/{state/state.ts → state.ts} +11 -3
  306. package/src/capabilities/toolkit.ts +13 -0
  307. package/src/components/AssistantSettings/AssistantSettings.stories.tsx +34 -0
  308. package/src/components/AssistantSettings/AssistantSettings.tsx +104 -92
  309. package/src/components/AssistantSettings/index.ts +2 -2
  310. package/src/components/Chat/Chat.tsx +88 -45
  311. package/src/components/ChatProgress/ChatProgress.tsx +9 -7
  312. package/src/components/ChatPrompt/ChatActions.tsx +25 -5
  313. package/src/components/ChatPrompt/ChatOptions.tsx +43 -29
  314. package/src/components/ChatPrompt/ChatReferences.tsx +18 -8
  315. package/src/components/ChatThread/ChatThread.stories.tsx +31 -48
  316. package/src/components/ChatThread/ChatThread.tsx +28 -17
  317. package/src/components/ChatThread/Link.tsx +1 -1
  318. package/src/components/ChatThread/MarkdownStream.stories.tsx +243 -0
  319. package/src/components/ChatThread/registry.tsx +107 -43
  320. package/src/components/ChatThread/sync.test.ts +13 -10
  321. package/src/components/ChatThread/sync.ts +43 -32
  322. package/src/components/ChatThread/testing/thinking.md +21 -0
  323. package/src/components/ChatThread/testing/thread-1.md +30 -0
  324. package/src/components/ChatThread/testing/{thread.md → thread-2.md} +19 -0
  325. package/src/components/ChatThread/testing/thread-widgets.md +79 -0
  326. package/src/components/ChatThread/tool-widget-state.test.ts +34 -0
  327. package/src/components/ChatThread/tool-widget-state.ts +48 -0
  328. package/src/components/ChatThread/widgets/FallbackWidget.tsx +26 -0
  329. package/src/components/ChatThread/widgets/PromptWidget.ts +28 -0
  330. package/src/components/ChatThread/widgets/ReasoningWidget.stories.tsx +68 -0
  331. package/src/components/ChatThread/widgets/ReasoningWidget.ts +133 -0
  332. package/src/components/ChatThread/widgets/ReferenceWidget.ts +31 -0
  333. package/src/components/ChatThread/widgets/SelectWidget.ts +37 -0
  334. package/src/components/ChatThread/widgets/StatsWidget.ts +29 -0
  335. package/src/components/ChatThread/widgets/StatusWidget.ts +133 -0
  336. package/src/components/ChatThread/widgets/SuggestionWidget.ts +41 -0
  337. package/src/components/ChatThread/widgets/SummaryWidget.tsx +28 -0
  338. package/src/components/ChatThread/widgets/ToolWidget.stories.tsx +54 -0
  339. package/src/components/ChatThread/widgets/ToolWidget.tsx +156 -0
  340. package/src/components/ChatThread/widgets/index.ts +14 -0
  341. package/src/components/ProcessTree/ProcessTree.stories.tsx +109 -0
  342. package/src/components/ProcessTree/ProcessTree.tsx +85 -0
  343. package/src/components/ProcessTree/index.ts +5 -0
  344. package/src/components/TemplateEditor/TemplateEditor.stories.tsx +4 -9
  345. package/src/components/TemplateEditor/TemplateEditor.tsx +50 -42
  346. package/src/components/TemplateEditor/TemplateForm.stories.tsx +7 -6
  347. package/src/components/TemplateEditor/TemplateForm.tsx +9 -10
  348. package/src/components/TemplateEditor/extensions/handlebars-extension.ts +4 -4
  349. package/src/components/ToolBlock/ToolBlock.tsx +21 -20
  350. package/src/components/Toolbox/Toolbox.stories.tsx +4 -6
  351. package/src/components/Toolbox/Toolbox.tsx +66 -60
  352. package/src/components/Typewriter/AssistantToolbar.tsx +7 -7
  353. package/src/components/Typewriter/Typewriter.stories.tsx +18 -15
  354. package/src/components/Typewriter/Typewriter.tsx +6 -10
  355. package/src/components/Typewriter/assistant-extension.tsx +5 -8
  356. package/src/components/index.ts +3 -7
  357. package/src/containers/AgentArticle/AgentArticle.stories.tsx +105 -0
  358. package/src/containers/AgentArticle/AgentArticle.tsx +157 -0
  359. package/src/containers/AgentArticle/index.ts +5 -0
  360. package/src/containers/AgentProperties/AgentProperties.stories.tsx +91 -0
  361. package/src/containers/AgentProperties/AgentProperties.tsx +169 -0
  362. package/src/containers/AgentProperties/index.ts +5 -0
  363. package/src/containers/BlueprintArticle/BlueprintArticle.tsx +29 -0
  364. package/src/containers/BlueprintArticle/index.ts +5 -0
  365. package/src/{components → containers/ChatCompanion}/ChatCompanion.tsx +23 -44
  366. package/src/containers/ChatCompanion/index.ts +5 -0
  367. package/src/containers/ChatContainer/ChatContainer.tsx +95 -0
  368. package/src/containers/ChatContainer/index.ts +5 -0
  369. package/src/{components → containers/ChatDialog}/ChatDialog.tsx +10 -12
  370. package/src/containers/ChatDialog/index.ts +5 -0
  371. package/src/containers/PromptArticle/PromptArticle.tsx +59 -0
  372. package/src/containers/PromptArticle/index.ts +5 -0
  373. package/src/containers/PromptList/PromptList.stories.tsx +129 -0
  374. package/src/containers/PromptList/PromptList.tsx +49 -0
  375. package/src/containers/PromptList/index.ts +5 -0
  376. package/src/containers/TracePanel/TracePanel.tsx +361 -0
  377. package/src/containers/TracePanel/dxn-extractor.test.ts +153 -0
  378. package/src/containers/TracePanel/dxn-extractor.ts +178 -0
  379. package/src/containers/TracePanel/index.ts +9 -0
  380. package/src/containers/TriggerStatus/TriggerStatus.tsx +144 -0
  381. package/src/containers/TriggerStatus/index.ts +5 -0
  382. package/src/containers/index.ts +16 -0
  383. package/src/extensions/index.ts +5 -0
  384. package/src/extensions/prompt-extension.ts +111 -0
  385. package/src/hooks/useBlueprintRegistry.ts +8 -4
  386. package/src/hooks/useChatProcessor.ts +30 -17
  387. package/src/hooks/useChatServices.ts +7 -28
  388. package/src/hooks/useChatToolbarActions.ts +13 -12
  389. package/src/hooks/useContextBinder.ts +17 -6
  390. package/src/hooks/useContextObjects.ts +8 -4
  391. package/src/hooks/useFilteredTypes.ts +3 -3
  392. package/src/hooks/usePresets.ts +2 -1
  393. package/src/hooks/useReferencesProvider.ts +1 -5
  394. package/src/index.ts +1 -1
  395. package/src/meta.ts +6 -3
  396. package/src/operations/create-chat.ts +80 -0
  397. package/src/operations/definitions.ts +127 -0
  398. package/src/operations/ensure-companion-chat.ts +61 -0
  399. package/src/operations/index.ts +17 -0
  400. package/src/operations/on-create-space.ts +24 -0
  401. package/src/operations/resolve-navigation-targets.ts +26 -0
  402. package/src/operations/run-prompt-in-new-chat.ts +113 -0
  403. package/src/operations/set-current-chat.ts +50 -0
  404. package/src/operations/update-chat-name.ts +61 -0
  405. package/src/processor/index.ts +0 -1
  406. package/src/processor/presets.ts +2 -2
  407. package/src/processor/processor.test.ts +18 -50
  408. package/src/processor/processor.ts +190 -129
  409. package/src/queue-logger.ts +2 -2
  410. package/src/testing/test-generator.ts +45 -14
  411. package/src/testing/test-sequence.ts +3 -3
  412. package/src/testing/test-services.ts +2 -2
  413. package/src/translations.ts +134 -83
  414. package/src/types/Assistant.ts +8 -56
  415. package/src/types/Settings.ts +21 -0
  416. package/src/types/capabilities.ts +11 -3
  417. package/src/types/events.ts +2 -2
  418. package/src/types/index.ts +3 -1
  419. package/src/types/service.ts +5 -5
  420. package/dist/lib/browser/BlueprintArticle-WP3G5GLG.mjs +0 -31
  421. package/dist/lib/browser/BlueprintArticle-WP3G5GLG.mjs.map +0 -7
  422. package/dist/lib/browser/ChatCompanion-GFSJZTOT.mjs +0 -153
  423. package/dist/lib/browser/ChatCompanion-GFSJZTOT.mjs.map +0 -7
  424. package/dist/lib/browser/ChatContainer-IHAPBIZE.mjs +0 -72
  425. package/dist/lib/browser/ChatContainer-IHAPBIZE.mjs.map +0 -7
  426. package/dist/lib/browser/ChatDialog-EGRMPCTL.mjs +0 -85
  427. package/dist/lib/browser/ChatDialog-EGRMPCTL.mjs.map +0 -7
  428. package/dist/lib/browser/PromptArticle-K362ZPAE.mjs +0 -53
  429. package/dist/lib/browser/PromptArticle-K362ZPAE.mjs.map +0 -7
  430. package/dist/lib/browser/ai-service-5GUDOEWF.mjs +0 -21
  431. package/dist/lib/browser/ai-service-5GUDOEWF.mjs.map +0 -7
  432. package/dist/lib/browser/app-graph-builder-DSNH2OMY.mjs +0 -212
  433. package/dist/lib/browser/app-graph-builder-DSNH2OMY.mjs.map +0 -7
  434. package/dist/lib/browser/blueprint-definition-DGHH7MUU.mjs +0 -14
  435. package/dist/lib/browser/blueprint-definition-DGHH7MUU.mjs.map +0 -7
  436. package/dist/lib/browser/chunk-A75V4MOQ.mjs +0 -1832
  437. package/dist/lib/browser/chunk-A75V4MOQ.mjs.map +0 -7
  438. package/dist/lib/browser/chunk-DKQMSMBN.mjs +0 -326
  439. package/dist/lib/browser/chunk-DKQMSMBN.mjs.map +0 -7
  440. package/dist/lib/browser/chunk-EXVT7D4B.mjs +0 -23
  441. package/dist/lib/browser/chunk-EXVT7D4B.mjs.map +0 -7
  442. package/dist/lib/browser/chunk-ML3QCFKA.mjs +0 -265
  443. package/dist/lib/browser/chunk-ML3QCFKA.mjs.map +0 -7
  444. package/dist/lib/browser/chunk-MRJVYGLU.mjs +0 -208
  445. package/dist/lib/browser/chunk-MRJVYGLU.mjs.map +0 -7
  446. package/dist/lib/browser/chunk-V772AMZM.mjs +0 -250
  447. package/dist/lib/browser/chunk-V772AMZM.mjs.map +0 -7
  448. package/dist/lib/browser/chunk-WGQTU6UJ.mjs +0 -41
  449. package/dist/lib/browser/chunk-WGQTU6UJ.mjs.map +0 -7
  450. package/dist/lib/browser/edge-model-resolver-26BOY6HY.mjs +0 -20
  451. package/dist/lib/browser/edge-model-resolver-26BOY6HY.mjs.map +0 -7
  452. package/dist/lib/browser/local-model-resolver-ZFIM6GGV.mjs +0 -19
  453. package/dist/lib/browser/local-model-resolver-ZFIM6GGV.mjs.map +0 -7
  454. package/dist/lib/browser/operation-resolver-7XJLBRQY.mjs +0 -132
  455. package/dist/lib/browser/operation-resolver-7XJLBRQY.mjs.map +0 -7
  456. package/dist/lib/browser/react-surface-S7SBFOSW.mjs +0 -109
  457. package/dist/lib/browser/react-surface-S7SBFOSW.mjs.map +0 -7
  458. package/dist/lib/browser/repair-6QGAKOVM.mjs +0 -54
  459. package/dist/lib/browser/repair-6QGAKOVM.mjs.map +0 -7
  460. package/dist/lib/browser/settings-4ZDLUMYE.mjs +0 -32
  461. package/dist/lib/browser/settings-4ZDLUMYE.mjs.map +0 -7
  462. package/dist/lib/browser/state-AN6336ZX.mjs +0 -26
  463. package/dist/lib/browser/state-AN6336ZX.mjs.map +0 -7
  464. package/dist/lib/browser/toolkit-7AVTEPMA.mjs +0 -18
  465. package/dist/lib/browser/toolkit-7AVTEPMA.mjs.map +0 -7
  466. package/dist/lib/node-esm/BlueprintArticle-WZ76E2C4.mjs +0 -32
  467. package/dist/lib/node-esm/BlueprintArticle-WZ76E2C4.mjs.map +0 -7
  468. package/dist/lib/node-esm/ChatCompanion-UR7DXZ54.mjs +0 -154
  469. package/dist/lib/node-esm/ChatCompanion-UR7DXZ54.mjs.map +0 -7
  470. package/dist/lib/node-esm/ChatContainer-YMLLGOZK.mjs +0 -73
  471. package/dist/lib/node-esm/ChatContainer-YMLLGOZK.mjs.map +0 -7
  472. package/dist/lib/node-esm/ChatDialog-D24WJPK4.mjs +0 -86
  473. package/dist/lib/node-esm/ChatDialog-D24WJPK4.mjs.map +0 -7
  474. package/dist/lib/node-esm/PromptArticle-D4HAIIC6.mjs +0 -54
  475. package/dist/lib/node-esm/PromptArticle-D4HAIIC6.mjs.map +0 -7
  476. package/dist/lib/node-esm/ai-service-PXKKCFIF.mjs +0 -22
  477. package/dist/lib/node-esm/ai-service-PXKKCFIF.mjs.map +0 -7
  478. package/dist/lib/node-esm/app-graph-builder-TJCUEXW5.mjs +0 -213
  479. package/dist/lib/node-esm/app-graph-builder-TJCUEXW5.mjs.map +0 -7
  480. package/dist/lib/node-esm/blueprint-definition-SEMDEIYG.mjs +0 -15
  481. package/dist/lib/node-esm/blueprint-definition-SEMDEIYG.mjs.map +0 -7
  482. package/dist/lib/node-esm/chunk-355W5B27.mjs +0 -251
  483. package/dist/lib/node-esm/chunk-355W5B27.mjs.map +0 -7
  484. package/dist/lib/node-esm/chunk-4BERCIES.mjs +0 -1833
  485. package/dist/lib/node-esm/chunk-4BERCIES.mjs.map +0 -7
  486. package/dist/lib/node-esm/chunk-75PHXBN3.mjs +0 -327
  487. package/dist/lib/node-esm/chunk-75PHXBN3.mjs.map +0 -7
  488. package/dist/lib/node-esm/chunk-DCA5QWQT.mjs +0 -209
  489. package/dist/lib/node-esm/chunk-DCA5QWQT.mjs.map +0 -7
  490. package/dist/lib/node-esm/chunk-MSBPC4RJ.mjs +0 -42
  491. package/dist/lib/node-esm/chunk-MSBPC4RJ.mjs.map +0 -7
  492. package/dist/lib/node-esm/chunk-POWB2BPC.mjs +0 -25
  493. package/dist/lib/node-esm/chunk-POWB2BPC.mjs.map +0 -7
  494. package/dist/lib/node-esm/chunk-ZRIPP7YF.mjs +0 -267
  495. package/dist/lib/node-esm/chunk-ZRIPP7YF.mjs.map +0 -7
  496. package/dist/lib/node-esm/edge-model-resolver-G5KMODPO.mjs +0 -21
  497. package/dist/lib/node-esm/edge-model-resolver-G5KMODPO.mjs.map +0 -7
  498. package/dist/lib/node-esm/local-model-resolver-KDZLYI7Y.mjs +0 -20
  499. package/dist/lib/node-esm/local-model-resolver-KDZLYI7Y.mjs.map +0 -7
  500. package/dist/lib/node-esm/operation-resolver-SX4WMNA7.mjs +0 -133
  501. package/dist/lib/node-esm/operation-resolver-SX4WMNA7.mjs.map +0 -7
  502. package/dist/lib/node-esm/react-surface-ZR6FXGLF.mjs +0 -110
  503. package/dist/lib/node-esm/react-surface-ZR6FXGLF.mjs.map +0 -7
  504. package/dist/lib/node-esm/repair-QJ7CQDKU.mjs +0 -55
  505. package/dist/lib/node-esm/repair-QJ7CQDKU.mjs.map +0 -7
  506. package/dist/lib/node-esm/settings-CQEOHR3R.mjs +0 -33
  507. package/dist/lib/node-esm/settings-CQEOHR3R.mjs.map +0 -7
  508. package/dist/lib/node-esm/state-HDON4REW.mjs +0 -27
  509. package/dist/lib/node-esm/state-HDON4REW.mjs.map +0 -7
  510. package/dist/lib/node-esm/toolkit-OWGCEKOO.mjs +0 -19
  511. package/dist/lib/node-esm/toolkit-OWGCEKOO.mjs.map +0 -7
  512. package/dist/types/src/blueprints/assistant-blueprint.d.ts +0 -209
  513. package/dist/types/src/blueprints/assistant-blueprint.d.ts.map +0 -1
  514. package/dist/types/src/capabilities/ai-service/ai-service.d.ts +0 -5
  515. package/dist/types/src/capabilities/ai-service/ai-service.d.ts.map +0 -1
  516. package/dist/types/src/capabilities/ai-service/index.d.ts +0 -3
  517. package/dist/types/src/capabilities/ai-service/index.d.ts.map +0 -1
  518. package/dist/types/src/capabilities/app-graph-builder/app-graph-builder.d.ts +0 -6
  519. package/dist/types/src/capabilities/app-graph-builder/app-graph-builder.d.ts.map +0 -1
  520. package/dist/types/src/capabilities/app-graph-builder/index.d.ts +0 -3
  521. package/dist/types/src/capabilities/app-graph-builder/index.d.ts.map +0 -1
  522. package/dist/types/src/capabilities/blueprint-definition/blueprint-definition.d.ts +0 -21
  523. package/dist/types/src/capabilities/blueprint-definition/blueprint-definition.d.ts.map +0 -1
  524. package/dist/types/src/capabilities/blueprint-definition/index.d.ts +0 -4
  525. package/dist/types/src/capabilities/blueprint-definition/index.d.ts.map +0 -1
  526. package/dist/types/src/capabilities/edge-model-resolver/edge-model-resolver.d.ts +0 -6
  527. package/dist/types/src/capabilities/edge-model-resolver/edge-model-resolver.d.ts.map +0 -1
  528. package/dist/types/src/capabilities/edge-model-resolver/index.d.ts +0 -3
  529. package/dist/types/src/capabilities/edge-model-resolver/index.d.ts.map +0 -1
  530. package/dist/types/src/capabilities/local-model-resolver/index.d.ts +0 -3
  531. package/dist/types/src/capabilities/local-model-resolver/index.d.ts.map +0 -1
  532. package/dist/types/src/capabilities/local-model-resolver/local-model-resolver.d.ts +0 -12
  533. package/dist/types/src/capabilities/local-model-resolver/local-model-resolver.d.ts.map +0 -1
  534. package/dist/types/src/capabilities/operation-resolver/index.d.ts +0 -3
  535. package/dist/types/src/capabilities/operation-resolver/index.d.ts.map +0 -1
  536. package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts +0 -5
  537. package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts.map +0 -1
  538. package/dist/types/src/capabilities/react-surface/index.d.ts +0 -3
  539. package/dist/types/src/capabilities/react-surface/index.d.ts.map +0 -1
  540. package/dist/types/src/capabilities/react-surface/react-surface.d.ts +0 -5
  541. package/dist/types/src/capabilities/react-surface/react-surface.d.ts.map +0 -1
  542. package/dist/types/src/capabilities/repair/index.d.ts +0 -3
  543. package/dist/types/src/capabilities/repair/index.d.ts.map +0 -1
  544. package/dist/types/src/capabilities/repair/repair.d.ts +0 -6
  545. package/dist/types/src/capabilities/repair/repair.d.ts.map +0 -1
  546. package/dist/types/src/capabilities/settings/index.d.ts +0 -15
  547. package/dist/types/src/capabilities/settings/index.d.ts.map +0 -1
  548. package/dist/types/src/capabilities/settings/settings.d.ts.map +0 -1
  549. package/dist/types/src/capabilities/state/index.d.ts +0 -11
  550. package/dist/types/src/capabilities/state/index.d.ts.map +0 -1
  551. package/dist/types/src/capabilities/state/state.d.ts +0 -13
  552. package/dist/types/src/capabilities/state/state.d.ts.map +0 -1
  553. package/dist/types/src/capabilities/toolkit/index.d.ts +0 -3
  554. package/dist/types/src/capabilities/toolkit/index.d.ts.map +0 -1
  555. package/dist/types/src/capabilities/toolkit/toolkit.d.ts +0 -5
  556. package/dist/types/src/capabilities/toolkit/toolkit.d.ts.map +0 -1
  557. package/dist/types/src/components/BlueprintArticle.d.ts +0 -7
  558. package/dist/types/src/components/BlueprintArticle.d.ts.map +0 -1
  559. package/dist/types/src/components/ChatCompanion.d.ts +0 -13
  560. package/dist/types/src/components/ChatCompanion.d.ts.map +0 -1
  561. package/dist/types/src/components/ChatContainer.d.ts +0 -19
  562. package/dist/types/src/components/ChatContainer.d.ts.map +0 -1
  563. package/dist/types/src/components/ChatDialog.d.ts.map +0 -1
  564. package/dist/types/src/components/ChatThread/reducers.d.ts +0 -40
  565. package/dist/types/src/components/ChatThread/reducers.d.ts.map +0 -1
  566. package/dist/types/src/components/PromptArticle.d.ts +0 -7
  567. package/dist/types/src/components/PromptArticle.d.ts.map +0 -1
  568. package/dist/types/src/functions/index.d.ts +0 -4
  569. package/dist/types/src/functions/index.d.ts.map +0 -1
  570. package/dist/types/src/functions/object-list.d.ts +0 -10
  571. package/dist/types/src/functions/object-list.d.ts.map +0 -1
  572. package/dist/types/src/functions/object-load.d.ts +0 -8
  573. package/dist/types/src/functions/object-load.d.ts.map +0 -1
  574. package/dist/types/src/functions/object-search.d.ts +0 -10
  575. package/dist/types/src/functions/object-search.d.ts.map +0 -1
  576. package/dist/types/src/processor/update-name.d.ts +0 -10
  577. package/dist/types/src/processor/update-name.d.ts.map +0 -1
  578. package/dist/types/src/types/AssistantAction.d.ts +0 -95
  579. package/dist/types/src/types/AssistantAction.d.ts.map +0 -1
  580. package/src/blueprints/assistant-blueprint.ts +0 -62
  581. package/src/capabilities/ai-service/index.ts +0 -7
  582. package/src/capabilities/app-graph-builder/app-graph-builder.ts +0 -180
  583. package/src/capabilities/app-graph-builder/index.ts +0 -7
  584. package/src/capabilities/blueprint-definition/blueprint-definition.ts +0 -60
  585. package/src/capabilities/blueprint-definition/index.ts +0 -8
  586. package/src/capabilities/edge-model-resolver/index.ts +0 -7
  587. package/src/capabilities/local-model-resolver/index.ts +0 -7
  588. package/src/capabilities/operation-resolver/index.ts +0 -7
  589. package/src/capabilities/operation-resolver/operation-resolver.ts +0 -110
  590. package/src/capabilities/react-surface/index.ts +0 -7
  591. package/src/capabilities/react-surface/react-surface.tsx +0 -95
  592. package/src/capabilities/repair/index.ts +0 -7
  593. package/src/capabilities/repair/repair.ts +0 -63
  594. package/src/capabilities/settings/index.ts +0 -7
  595. package/src/capabilities/state/index.ts +0 -7
  596. package/src/capabilities/toolkit/index.ts +0 -7
  597. package/src/capabilities/toolkit/toolkit.ts +0 -26
  598. package/src/components/BlueprintArticle.tsx +0 -29
  599. package/src/components/ChatContainer.tsx +0 -61
  600. package/src/components/ChatThread/reducers.ts +0 -151
  601. package/src/components/PromptArticle.tsx +0 -50
  602. package/src/functions/index.ts +0 -7
  603. package/src/functions/object-list.ts +0 -49
  604. package/src/functions/object-load.ts +0 -47
  605. package/src/functions/object-search.ts +0 -46
  606. package/src/processor/update-name.ts +0 -59
  607. package/src/types/AssistantAction.ts +0 -75
@@ -1,353 +1,3271 @@
1
1
  import {
2
- AssistantSettings,
3
- BlueprintArticle,
4
- Chat,
5
- ChatCompanion,
6
- ChatContainer,
7
- ChatContextProvider,
8
- ChatDialog,
9
- PromptArticle,
10
- Toolbox,
11
- ToolboxContainer,
12
- useActiveBlueprints,
13
- useBlueprintHandlers,
14
- useBlueprintRegistry,
15
- useBlueprints,
16
- useChatContext,
17
- useChatProcessor,
18
- useChatServices,
19
- useChatToolbarActions,
20
- useContextBinder,
21
- useContextObjects,
22
- useFilteredTypes,
23
- useFlush,
24
- useOnline,
25
- usePresets,
26
- useReferencesProvider
27
- } from "./chunk-A75V4MOQ.mjs";
28
- import "./chunk-ML3QCFKA.mjs";
29
- import {
30
- TemplateEditor
31
- } from "./chunk-DKQMSMBN.mjs";
2
+ blueprint_default
3
+ } from "./chunk-EZRS3J25.mjs";
32
4
  import {
33
5
  ApiAuthorization,
34
6
  AssistantCapabilities,
35
7
  AssistantEvents,
36
- AssistantOperation,
37
8
  Assistant_exports,
38
9
  LLM_PROVIDERS,
39
10
  ServiceType,
40
11
  categoryIcons
41
- } from "./chunk-V772AMZM.mjs";
42
- import {
43
- ASSISTANT_DIALOG,
44
- meta
45
- } from "./chunk-EXVT7D4B.mjs";
46
- import "./chunk-WGQTU6UJ.mjs";
12
+ } from "./chunk-RUV2WOQH.mjs";
47
13
  import {
48
- assistant_blueprint_exports
49
- } from "./chunk-MRJVYGLU.mjs";
14
+ UpdateChatName
15
+ } from "./chunk-ATHYBVGN.mjs";
50
16
  import "./chunk-J5LGTIGS.mjs";
51
17
 
52
- // src/capabilities/ai-service/index.ts
53
- import { Capability } from "@dxos/app-framework";
54
- var AiService = Capability.lazy("AiService", () => import("./ai-service-5GUDOEWF.mjs"));
18
+ // src/components/index.ts
19
+ import { lazy } from "react";
20
+
21
+ // src/components/Chat/Chat.tsx
22
+ import { Prec } from "@codemirror/state";
23
+ import { keymap } from "@codemirror/view";
24
+ import { useAtomValue } from "@effect-atom/atom-react";
25
+ import { createContext } from "@radix-ui/react-context";
26
+ import * as Array2 from "effect/Array";
27
+ import * as Option3 from "effect/Option";
28
+ import React11, { useCallback as useCallback3, useEffect as useEffect4, useMemo as useMemo4, useRef as useRef2, useState as useState5 } from "react";
29
+ import { Event } from "@dxos/async";
30
+ import { Filter as Filter2, Obj as Obj3 } from "@dxos/echo";
31
+ import { useVoiceInput } from "@dxos/plugin-transcription";
32
+ import { useQuery as useQuery2 } from "@dxos/react-client/echo";
33
+ import { useIdentity } from "@dxos/react-client/halo";
34
+ import { Input, useDynamicRef, useTranslation as useTranslation6 } from "@dxos/react-ui";
35
+ import { ChatEditor } from "@dxos/react-ui-chat";
36
+ import { Menu } from "@dxos/react-ui-menu";
37
+ import { Message } from "@dxos/types";
38
+ import { composable, composableProps, mx as mx7 } from "@dxos/ui-theme";
39
+ import { isTruthy, trim } from "@dxos/util";
40
+ import { useChatToolbarActions } from "#hooks";
41
+ import { meta as meta6 } from "#meta";
42
+
43
+ // src/components/ChatPrompt/ChatActions.tsx
44
+ import React from "react";
45
+ import { IconButton, useTranslation } from "@dxos/react-ui";
46
+ import { mx } from "@dxos/ui-theme";
47
+ import { meta } from "#meta";
48
+ var ChatActions = ({ classNames, children, microphone, recording, processing, debug, onEvent }) => {
49
+ const { t } = useTranslation(meta.id);
50
+ return /* @__PURE__ */ React.createElement("div", {
51
+ className: mx("flex items-center me-1", classNames)
52
+ }, children, /* @__PURE__ */ React.createElement(IconButton, {
53
+ disabled: !processing,
54
+ variant: "ghost",
55
+ icon: "ph--x--regular",
56
+ iconOnly: true,
57
+ label: t("cancel-processing.button"),
58
+ onClick: () => onEvent?.({
59
+ type: "cancel"
60
+ })
61
+ }), microphone && /* @__PURE__ */ React.createElement(IconButton, {
62
+ disabled: !processing,
63
+ classNames: mx(recording && "bg-primary-500"),
64
+ variant: "ghost",
65
+ icon: "ph--microphone--regular",
66
+ iconOnly: true,
67
+ noTooltip: true,
68
+ label: t("microphone.button"),
69
+ onMouseDown: () => onEvent?.({
70
+ type: "record-start"
71
+ }),
72
+ onMouseUp: () => onEvent?.({
73
+ type: "record-stop"
74
+ }),
75
+ onTouchStart: () => onEvent?.({
76
+ type: "record-start"
77
+ }),
78
+ onTouchEnd: () => onEvent?.({
79
+ type: "record-stop"
80
+ })
81
+ }), debug && /* @__PURE__ */ React.createElement(IconButton, {
82
+ variant: "ghost",
83
+ icon: "ph--wrench--regular",
84
+ iconOnly: true,
85
+ label: t("debug.button"),
86
+ onClick: () => onEvent?.({
87
+ type: "toggle-debug"
88
+ })
89
+ }));
90
+ };
91
+
92
+ // src/components/ChatPrompt/ChatOptions.tsx
93
+ import * as Option from "effect/Option";
94
+ import React2, { useMemo, useState } from "react";
95
+ import { Filter, Obj, Type } from "@dxos/echo";
96
+ import { Annotation } from "@dxos/echo";
97
+ import { useQuery } from "@dxos/react-client/echo";
98
+ import { IconButton as IconButton2, Popover, Select, useTranslation as useTranslation2 } from "@dxos/react-ui";
99
+ import { Listbox, SearchList, useSearchListResults } from "@dxos/react-ui-search";
100
+ import { Tabs } from "@dxos/react-ui-tabs";
101
+ import { getStyles, mx as mx2 } from "@dxos/ui-theme";
102
+ import { useActiveBlueprints, useBlueprintHandlers, useBlueprints, useContextObjects, useFilteredTypes } from "#hooks";
103
+ import { meta as meta2 } from "#meta";
104
+ var panelClassNames = "w-[calc(100dvw-.5rem)] sm:w-max md:w-72 max-w-document-width";
105
+ var ChatOptions = ({ db, context, blueprintRegistry, presets, preset, onPresetChange }) => {
106
+ const { t } = useTranslation2(meta2.id);
107
+ return /* @__PURE__ */ React2.createElement("div", {
108
+ role: "none",
109
+ className: "flex p-2"
110
+ }, /* @__PURE__ */ React2.createElement(Popover.Root, null, /* @__PURE__ */ React2.createElement(Popover.Trigger, {
111
+ asChild: true
112
+ }, /* @__PURE__ */ React2.createElement(IconButton2, {
113
+ variant: "ghost",
114
+ icon: "ph--plus--regular",
115
+ iconOnly: true,
116
+ label: t("context-objects.button")
117
+ })), /* @__PURE__ */ React2.createElement(Popover.Portal, null, /* @__PURE__ */ React2.createElement(Popover.Content, {
118
+ side: "top",
119
+ classNames: panelClassNames
120
+ }, /* @__PURE__ */ React2.createElement(Popover.Viewport, null, /* @__PURE__ */ React2.createElement(ObjectsPanel, {
121
+ db,
122
+ context
123
+ })), /* @__PURE__ */ React2.createElement(Popover.Arrow, null)))), /* @__PURE__ */ React2.createElement(Popover.Root, null, /* @__PURE__ */ React2.createElement(Popover.Trigger, {
124
+ asChild: true
125
+ }, /* @__PURE__ */ React2.createElement(IconButton2, {
126
+ variant: "ghost",
127
+ icon: "ph--sliders-horizontal--regular",
128
+ iconOnly: true,
129
+ label: t("context-settings.button")
130
+ })), /* @__PURE__ */ React2.createElement(Popover.Portal, null, /* @__PURE__ */ React2.createElement(Popover.Content, {
131
+ side: "top",
132
+ classNames: panelClassNames
133
+ }, /* @__PURE__ */ React2.createElement(Popover.Viewport, null, /* @__PURE__ */ React2.createElement(Tabs.Root, {
134
+ orientation: "horizontal",
135
+ defaultValue: "blueprints",
136
+ defaultActivePart: "list",
137
+ tabIndex: -1
138
+ }, /* @__PURE__ */ React2.createElement(Tabs.Viewport, {
139
+ classNames: mx2("max-h-(--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-h-0 [&_[role="listbox"]]:overflow-y-auto', '[&_[role="tabpanel"]]:min-h-0 [&_[role="tabpanel"]]:px-form-chrome [&_[role="tabpanel"][data-state="active"]]:order-first [&_[role="tabpanel"][data-state="inactive"]]:hidden')
140
+ }, /* @__PURE__ */ React2.createElement(Tabs.Panel, {
141
+ value: "blueprints",
142
+ tabIndex: -1,
143
+ classNames: "dx-focus-ring-inset"
144
+ }, /* @__PURE__ */ React2.createElement(BlueprintsPanel, {
145
+ blueprintRegistry,
146
+ db,
147
+ context
148
+ })), /* @__PURE__ */ React2.createElement(Tabs.Panel, {
149
+ value: "model",
150
+ tabIndex: -1,
151
+ classNames: "dx-focus-ring-inset px-0!"
152
+ }, /* @__PURE__ */ React2.createElement(ModelsPanel, {
153
+ presets,
154
+ preset,
155
+ onPresetChange
156
+ })), /* @__PURE__ */ React2.createElement(Tabs.Tablist, {
157
+ classNames: "justify-center p-form-chrome border-y border-subdued-separator order-last"
158
+ }, /* @__PURE__ */ React2.createElement(Tabs.IconTab, {
159
+ value: "blueprints",
160
+ icon: "ph--blueprint--regular",
161
+ label: t("blueprints-in-context.title")
162
+ }), /* @__PURE__ */ React2.createElement(Tabs.IconTab, {
163
+ value: "model",
164
+ label: t("chat-model.title"),
165
+ icon: "ph--cpu--regular"
166
+ }))))), /* @__PURE__ */ React2.createElement(Popover.Arrow, null)))));
167
+ };
168
+ var BlueprintsPanel = ({ blueprintRegistry, db, context }) => {
169
+ const { t } = useTranslation2(meta2.id);
170
+ const blueprints = useBlueprints({
171
+ blueprintRegistry,
172
+ db
173
+ });
174
+ const activeBlueprints = useActiveBlueprints({
175
+ context
176
+ });
177
+ const { onUpdateBlueprint } = useBlueprintHandlers({
178
+ db,
179
+ context,
180
+ blueprintRegistry
181
+ });
182
+ const { results, handleSearch } = useSearchListResults({
183
+ items: blueprints,
184
+ extract: (blueprint) => blueprint.name
185
+ });
186
+ return /* @__PURE__ */ React2.createElement(SearchList.Root, {
187
+ onSearch: handleSearch
188
+ }, /* @__PURE__ */ React2.createElement(SearchList.Content, {
189
+ classNames: "py-form-chrome"
190
+ }, /* @__PURE__ */ React2.createElement(SearchList.Viewport, null, results.map((blueprint) => {
191
+ const isActive = activeBlueprints.has(blueprint.key);
192
+ return /* @__PURE__ */ React2.createElement(SearchList.Item, {
193
+ classNames: "flex items-center overflow-hidden",
194
+ key: blueprint.key,
195
+ value: blueprint.key,
196
+ label: blueprint.name,
197
+ checked: isActive,
198
+ onSelect: () => onUpdateBlueprint?.(blueprint.key, !isActive)
199
+ });
200
+ }))), /* @__PURE__ */ React2.createElement(SearchList.Input, {
201
+ placeholder: t("search.placeholder"),
202
+ classNames: "mb-form-chrome",
203
+ autoFocus: true
204
+ }));
205
+ };
206
+ var ModelsPanel = ({ presets, preset, onPresetChange }) => {
207
+ return /* @__PURE__ */ React2.createElement(Listbox.Root, {
208
+ value: preset,
209
+ onValueChange: onPresetChange,
210
+ autoFocus: true
211
+ }, presets?.map(({ id, label }) => {
212
+ return /* @__PURE__ */ React2.createElement(Listbox.Option, {
213
+ key: id,
214
+ value: id
215
+ }, /* @__PURE__ */ React2.createElement(Listbox.OptionLabel, null, label), /* @__PURE__ */ React2.createElement(Listbox.OptionIndicator, null));
216
+ }));
217
+ };
218
+ var ANY = "__any__";
219
+ var ObjectsPanel = ({ db, context }) => {
220
+ const { t } = useTranslation2(meta2.id);
221
+ const types = useFilteredTypes(db);
222
+ const typenames = useMemo(() => {
223
+ const typenames2 = types.map((type) => {
224
+ const typename2 = Type.getTypename(type);
225
+ return {
226
+ typename: typename2,
227
+ label: t("typename.label", {
228
+ ns: typename2,
229
+ defaultValue: typename2
230
+ })
231
+ };
232
+ });
233
+ typenames2.sort((a, b) => a.label.localeCompare(b.label));
234
+ return typenames2;
235
+ }, [
236
+ types
237
+ ]);
238
+ const [typename, setTypename] = useState(ANY);
239
+ const anyFilter = useMemo(() => Filter.or(...typenames.map(({ typename: typename2 }) => Filter.typename(typename2))), [
240
+ typenames
241
+ ]);
242
+ const objects = useQuery(db, typename === ANY ? anyFilter : Filter.typename(typename));
243
+ const { objects: contextObjects, onUpdateObject } = useContextObjects({
244
+ db,
245
+ context
246
+ });
247
+ const { results, handleSearch } = useSearchListResults({
248
+ items: objects,
249
+ extract: (object) => Obj.getLabel(object) ?? Obj.getTypename(object) ?? object.id
250
+ });
251
+ return /* @__PURE__ */ React2.createElement(SearchList.Root, {
252
+ onSearch: handleSearch
253
+ }, /* @__PURE__ */ React2.createElement(SearchList.Content, {
254
+ classNames: "p-form-chrome [&:has([cmdk-list-sizer]:empty)]:py-0"
255
+ }, /* @__PURE__ */ React2.createElement(SearchList.Viewport, null, results.length ? results.map((object) => {
256
+ const isActive = contextObjects.findIndex((obj) => obj.id === object.id) !== -1;
257
+ const { icon, hue } = Option.fromNullable(Obj.getSchema(object)).pipe(Option.flatMap(Annotation.IconAnnotation.get), Option.getOrElse(() => ({
258
+ icon: DEFAULT_OBJECT_ICON,
259
+ hue: void 0
260
+ })));
261
+ const styles = hue ? getStyles(hue) : void 0;
262
+ return /* @__PURE__ */ React2.createElement(SearchList.Item, {
263
+ classNames: "flex items-center overflow-hidden",
264
+ key: object.id,
265
+ value: object.id,
266
+ icon,
267
+ iconClassNames: styles?.surfaceText,
268
+ label: Obj.getLabel(object) ?? Obj.getTypename(object) ?? object.id,
269
+ checked: isActive,
270
+ onSelect: () => onUpdateObject?.(Obj.getDXN(object), !isActive)
271
+ });
272
+ }) : /* @__PURE__ */ React2.createElement(SearchList.Item, {
273
+ value: "__empty__",
274
+ label: t("no-results.message")
275
+ }))), /* @__PURE__ */ React2.createElement("div", {
276
+ role: "none",
277
+ className: "grid grid-cols-[min-content_1fr] gap-2 px-form-chrome mb-form-chrome"
278
+ }, /* @__PURE__ */ React2.createElement(Select.Root, {
279
+ value: typename === ANY ? void 0 : typename,
280
+ onValueChange: setTypename
281
+ }, /* @__PURE__ */ React2.createElement(Select.TriggerButton, {
282
+ placeholder: t("type-filter.placeholder")
283
+ }), /* @__PURE__ */ React2.createElement(Select.Portal, null, /* @__PURE__ */ React2.createElement(Select.Content, null, /* @__PURE__ */ React2.createElement(Select.ScrollUpButton, null), /* @__PURE__ */ React2.createElement(Select.Viewport, null, /* @__PURE__ */ React2.createElement(Select.Option, {
284
+ value: ANY
285
+ }, t("any-type-filter.label")), typenames.map(({ typename: typename2, label }) => /* @__PURE__ */ React2.createElement(Select.Option, {
286
+ key: typename2,
287
+ value: typename2
288
+ }, label))), /* @__PURE__ */ React2.createElement(Select.ScrollDownButton, null), /* @__PURE__ */ React2.createElement(Select.Arrow, null)))), /* @__PURE__ */ React2.createElement(SearchList.Input, {
289
+ placeholder: t("search.placeholder"),
290
+ classNames: "mb-0",
291
+ autoFocus: true
292
+ })));
293
+ };
294
+ var DEFAULT_OBJECT_ICON = "ph--cube--regular";
295
+
296
+ // src/components/ChatPrompt/ChatPresets.tsx
297
+ import React3 from "react";
298
+ import { Select as Select2 } from "@dxos/react-ui";
299
+
300
+ // src/components/ChatPrompt/ChatReferences.tsx
301
+ import * as Option2 from "effect/Option";
302
+ import React4 from "react";
303
+ import { Annotation as Annotation2, Obj as Obj2 } from "@dxos/echo";
304
+ import { Icon, IconButton as IconButton3, toLocalizedString, useTranslation as useTranslation3 } from "@dxos/react-ui";
305
+ import { getStyles as getStyles2, mx as mx3 } from "@dxos/ui-theme";
306
+ import { useContextObjects as useContextObjects2 } from "#hooks";
307
+ import { meta as meta3 } from "#meta";
308
+ var ChatReferences = ({ classNames, context, db }) => {
309
+ const { t } = useTranslation3(meta3.id);
310
+ const { objects, onUpdateObject } = useContextObjects2({
311
+ db,
312
+ context
313
+ });
314
+ return /* @__PURE__ */ React4.createElement("ul", {
315
+ className: mx3("flex", classNames)
316
+ }, objects.map((obj) => {
317
+ const dxn = Obj2.getDXN(obj);
318
+ const typename = Obj2.getTypename(obj);
319
+ const label = Obj2.getLabel(obj) ?? (typename ? [
320
+ "object-name.placeholder",
321
+ {
322
+ ns: typename
323
+ }
324
+ ] : obj.id);
325
+ const { icon, hue } = Option2.fromNullable(Obj2.getSchema(obj)).pipe(Option2.flatMap(Annotation2.IconAnnotation.get), Option2.getOrElse(() => ({
326
+ icon: DEFAULT_OBJECT_ICON2,
327
+ hue: void 0
328
+ })));
329
+ const styles = hue ? getStyles2(hue) : void 0;
330
+ return /* @__PURE__ */ React4.createElement("li", {
331
+ key: dxn.toString(),
332
+ className: "dx-tag py-0 ps-2 flex items-center gap-1",
333
+ "data-hue": "neutral"
334
+ }, /* @__PURE__ */ React4.createElement(Icon, {
335
+ icon,
336
+ size: 4,
337
+ classNames: styles?.surfaceText
338
+ }), toLocalizedString(label, t), /* @__PURE__ */ React4.createElement(IconButton3, {
339
+ icon: "ph--x--bold",
340
+ iconOnly: true,
341
+ variant: "ghost",
342
+ label: t("remove-object-in-context.label"),
343
+ classNames: "p-0 hover:bg-transparent",
344
+ size: 3,
345
+ onClick: () => onUpdateObject?.(dxn, false)
346
+ }));
347
+ }));
348
+ };
349
+ var DEFAULT_OBJECT_ICON2 = "ph--cube--regular";
350
+
351
+ // src/components/ChatPrompt/ChatStatusIndicator.tsx
352
+ import React5, { useEffect, useState as useState2 } from "react";
353
+ import { Tooltip, useTimeout } from "@dxos/react-ui";
354
+ import { Spinner } from "@dxos/react-ui-sfx";
355
+ import { mx as mx4 } from "@dxos/ui-theme";
356
+ var period = 3e3;
357
+ var ChatStatusIndicator = ({ classNames, preset, processing, error, ...props }) => {
358
+ const [init, setInit] = useState2(false);
359
+ useEffect(() => setInit(false), [
360
+ preset
361
+ ]);
362
+ useTimeout(async () => {
363
+ setInit(true);
364
+ }, period / 2, [
365
+ preset
366
+ ]);
367
+ return /* @__PURE__ */ React5.createElement("div", {
368
+ role: "none",
369
+ className: mx4("relative flex", classNames)
370
+ }, /* @__PURE__ */ React5.createElement(Spinner, {
371
+ duration: period,
372
+ state: !init ? "flash" : error ? "error" : processing ? "spin" : "pulse",
373
+ ...props
374
+ }), error && /* @__PURE__ */ React5.createElement(Tooltip.Trigger, {
375
+ asChild: true,
376
+ content: error.message
377
+ }, /* @__PURE__ */ React5.createElement("div", {
378
+ className: "absolute inset-0"
379
+ })));
380
+ };
381
+
382
+ // src/components/ChatThread/ChatThread.tsx
383
+ import React10, { forwardRef, useCallback as useCallback2, useEffect as useEffect3, useMemo as useMemo3, useState as useState4 } from "react";
384
+ import { PublicKey } from "@dxos/keys";
385
+ import { setRef } from "@dxos/react-ui";
386
+ import { MarkdownStream } from "@dxos/react-ui-components";
387
+ import { mx as mx6 } from "@dxos/ui-theme";
388
+ import { keyToFallback } from "@dxos/util";
389
+
390
+ // src/components/ChatThread/registry.tsx
391
+ import React9 from "react";
392
+ import { log } from "@dxos/log";
393
+ import { getXmlTextChild } from "@dxos/ui-editor";
394
+
395
+ // src/components/ChatThread/tool-widget-state.ts
396
+ var applyToolBlockToWidgetState = (context, block) => {
397
+ switch (block._tag) {
398
+ case "toolCall": {
399
+ context.updateWidget(block.toolCallId, {
400
+ blocks: [
401
+ block
402
+ ]
403
+ });
404
+ break;
405
+ }
406
+ case "toolResult": {
407
+ context.updateWidget(block.toolCallId, ({ blocks = [] } = {
408
+ blocks: []
409
+ }) => ({
410
+ blocks: [
411
+ ...blocks,
412
+ block
413
+ ]
414
+ }));
415
+ break;
416
+ }
417
+ default: {
418
+ break;
419
+ }
420
+ }
421
+ };
422
+ var rehydrateToolWidgetsFromMessages = (context, messages) => {
423
+ for (const message of messages) {
424
+ for (const block of message.blocks) {
425
+ applyToolBlockToWidgetState(context, block);
426
+ }
427
+ }
428
+ };
429
+
430
+ // src/components/ChatThread/widgets/FallbackWidget.tsx
431
+ import React6 from "react";
432
+ import { TogglePanel } from "@dxos/react-ui-components";
433
+ import { Json } from "@dxos/react-ui-syntax-highlighter";
434
+ var FallbackWidget = ({ _tag, ...props }) => {
435
+ return /* @__PURE__ */ React6.createElement(TogglePanel.Root, null, /* @__PURE__ */ React6.createElement(TogglePanel.Header, {
436
+ classNames: "bg-group-surface"
437
+ }, _tag), /* @__PURE__ */ React6.createElement(TogglePanel.Content, {
438
+ classNames: "bg-modal-surface"
439
+ }, /* @__PURE__ */ React6.createElement(TogglePanel.Viewport, null, /* @__PURE__ */ React6.createElement(Json.Data, {
440
+ classNames: "p-2! text-sm",
441
+ data: props
442
+ }))));
443
+ };
444
+ FallbackWidget.displayName = "Fallback";
445
+
446
+ // src/components/ChatThread/widgets/PromptWidget.ts
447
+ import { WidgetType } from "@codemirror/view";
448
+ import { Domino } from "@dxos/ui";
449
+ var PromptWidget = class extends WidgetType {
450
+ text;
451
+ constructor(text) {
452
+ super(), this.text = text;
453
+ }
454
+ eq(other) {
455
+ return this.text === other.text;
456
+ }
457
+ /**
458
+ * NOTE: Container must set var based on user's identity.
459
+ */
460
+ toDOM() {
461
+ const inner = Domino.of("div").classNames("px-3 py-1.5 bg-(--user-fill) rounded-xs").text(this.text);
462
+ return Domino.of("div").classNames("flex justify-end my-2").append(inner).root;
463
+ }
464
+ };
465
+
466
+ // src/components/ChatThread/widgets/ReasoningWidget.ts
467
+ import { WidgetType as WidgetType2 } from "@codemirror/view";
468
+ import { Domino as Domino2 } from "@dxos/ui";
469
+ var ReasoningWidget = class extends WidgetType2 {
470
+ text;
471
+ #pos;
472
+ /** The timer id last registered for this instance (may differ from the map if superseded). */
473
+ #ownedTimerId = null;
474
+ constructor(text, pos) {
475
+ super(), this.text = text;
476
+ this.#pos = pos === void 0 || pos === "" ? "reasoning" : String(pos);
477
+ }
478
+ eq(other) {
479
+ return this.text === other.text && this.#pos === other.#pos;
480
+ }
481
+ toDOM() {
482
+ const root = Domino2.of("div").classNames("pt-2 pb-2").append(Domino2.of("div").classNames("relative overflow-hidden p-px rounded-sm border border-subdued-separator").attributes({
483
+ "data-trail-container": ""
484
+ }).append(Domino2.of("div").classNames("relative z-10 bg-base-surface rounded-sm text-sm text-description px-2 py-1").append(Domino2.of("div").classNames("max-h-[5lh] overflow-y-auto").text(this.text).attributes({
485
+ "data-reasoning-text": ""
486
+ })), Domino2.of("div").attributes({
487
+ "data-id": this.#pos
488
+ }))).root;
489
+ return root;
490
+ }
491
+ updateDOM(dom) {
492
+ dom.querySelector("[data-reasoning-text]")?.replaceChildren(this.text);
493
+ const container = dom.querySelector("[data-trail-container]");
494
+ let trailHost = container?.querySelector("[data-id]");
495
+ if (container && !trailHost) {
496
+ trailHost = Domino2.of("div").attributes({
497
+ "data-id": this.#pos
498
+ }).root;
499
+ container.append(trailHost);
500
+ }
501
+ if (trailHost?.childElementCount === 0) {
502
+ trailHost.append(...createTrailLayers());
503
+ }
504
+ this.#scheduleTrailRemoval(dom);
505
+ return true;
506
+ }
507
+ destroy(_dom) {
508
+ this.#clearOwnedTrailTimer();
509
+ }
510
+ #scheduleTrailRemoval(dom) {
511
+ const previous = trailRemovalTimers.get(this.#pos);
512
+ if (previous !== void 0) {
513
+ clearTimeout(previous);
514
+ }
515
+ const timerId = setTimeout(() => {
516
+ if (trailRemovalTimers.get(this.#pos) !== timerId) {
517
+ return;
518
+ }
519
+ trailRemovalTimers.delete(this.#pos);
520
+ this.#ownedTimerId = null;
521
+ dom.querySelector("[data-id]")?.remove();
522
+ }, TRAIL_REMOVAL_DELAY_MS);
523
+ trailRemovalTimers.set(this.#pos, timerId);
524
+ this.#ownedTimerId = timerId;
525
+ }
526
+ #clearOwnedTrailTimer() {
527
+ const active = trailRemovalTimers.get(this.#pos);
528
+ if (active !== void 0 && active === this.#ownedTimerId) {
529
+ clearTimeout(active);
530
+ trailRemovalTimers.delete(this.#pos);
531
+ }
532
+ this.#ownedTimerId = null;
533
+ }
534
+ };
535
+ var trail = [
536
+ "absolute z-0 aspect-[2/1] w-16",
537
+ "bg-[radial-gradient(at_100%_50%,_theme(colors.green.700),_transparent_80%)]",
538
+ "[offset-anchor:100%_50%] [offset-path:border-box]"
539
+ ];
540
+ var TRAIL_REMOVAL_DELAY_MS = 1e3;
541
+ var trailRemovalTimers = /* @__PURE__ */ new Map();
542
+ var createTrailLayers = () => [
543
+ Domino2.of("div").classNames(...trail, "animate-trail").root,
544
+ Domino2.of("div").classNames(...trail, "animate-trail-offset").root
545
+ ];
546
+
547
+ // src/components/ChatThread/widgets/ReferenceWidget.ts
548
+ import { WidgetType as WidgetType3 } from "@codemirror/view";
549
+ import { Domino as Domino3 } from "@dxos/ui";
550
+ var ReferenceWidget = class extends WidgetType3 {
551
+ text;
552
+ dxn;
553
+ constructor(text, dxn) {
554
+ super(), this.text = text, this.dxn = dxn;
555
+ }
556
+ eq(other) {
557
+ return this.dxn === other.dxn;
558
+ }
559
+ toDOM() {
560
+ return Domino3.of("div").classNames("pt-2 pb-2").append(Domino3.of("dx-anchor").classNames("dx-tag--anchor").attributes({
561
+ dxn: this.dxn
562
+ }).text(this.text)).root;
563
+ }
564
+ };
565
+
566
+ // src/components/ChatThread/widgets/SelectWidget.ts
567
+ import { WidgetType as WidgetType4 } from "@codemirror/view";
568
+ import { Domino as Domino4 } from "@dxos/ui";
569
+ var SelectWidget = class extends WidgetType4 {
570
+ options;
571
+ constructor(options) {
572
+ super(), this.options = options;
573
+ }
574
+ eq(other) {
575
+ return JSON.stringify(this.options) === JSON.stringify(other.options);
576
+ }
577
+ /**
578
+ * NOTE: Container must set var based on user's identity.
579
+ */
580
+ toDOM() {
581
+ return Domino4.of("div").attributes({
582
+ role: "group"
583
+ }).classNames("flex flex-wrap pt-2 pb-2 gap-1").append(...this.options.map((option) => Domino4.of("button").classNames("dx-button inline-block max-w-[100cqi]").attributes({
584
+ "data-action": "submit",
585
+ "data-value": option,
586
+ "data-density": "fine"
587
+ }).text(option))).root;
588
+ }
589
+ };
590
+
591
+ // src/components/ChatThread/widgets/StatsWidget.ts
592
+ import { WidgetType as WidgetType5 } from "@codemirror/view";
593
+ import { Domino as Domino5 } from "@dxos/ui";
594
+ var StatsWidget = class extends WidgetType5 {
595
+ text;
596
+ constructor(text) {
597
+ super(), this.text = text;
598
+ }
599
+ eq(other) {
600
+ return this.text === other.text;
601
+ }
602
+ toDOM() {
603
+ return Domino5.of("div").classNames("pt-2 pb-4 text-sm text-placeholder").text(this.text).root;
604
+ }
605
+ updateDOM(dom) {
606
+ dom.textContent = this.text;
607
+ return true;
608
+ }
609
+ };
610
+
611
+ // src/components/ChatThread/widgets/SummaryWidget.tsx
612
+ import React7 from "react";
613
+ import { useTranslation as useTranslation4 } from "@dxos/react-ui";
614
+ import { TogglePanel as TogglePanel2 } from "@dxos/react-ui-components";
615
+ import { meta as meta4 } from "#meta";
616
+ var SummaryWidget = ({ children }) => {
617
+ const { t } = useTranslation4(meta4.id);
618
+ return /* @__PURE__ */ React7.createElement(TogglePanel2.Root, {
619
+ classNames: "border border-separator rounded-sm"
620
+ }, /* @__PURE__ */ React7.createElement(TogglePanel2.Header, {
621
+ classNames: "text-sm bg-group-surface"
622
+ }, t("summary.label")), /* @__PURE__ */ React7.createElement(TogglePanel2.Content, null, /* @__PURE__ */ React7.createElement("div", {
623
+ role: "none",
624
+ className: "p-1 text-sm text-description"
625
+ }, children)));
626
+ };
627
+
628
+ // src/components/ChatThread/widgets/SuggestionWidget.ts
629
+ import { WidgetType as WidgetType6 } from "@codemirror/view";
630
+ import { Domino as Domino6, mx as mx5 } from "@dxos/ui";
631
+ var SuggestionWidget = class extends WidgetType6 {
632
+ text;
633
+ constructor(text) {
634
+ super(), this.text = text;
635
+ }
636
+ eq(other) {
637
+ return this.text === other.text;
638
+ }
639
+ toDOM() {
640
+ return Domino6.of("span").classNames(mx5("inline-flex max-w-[calc(100cqi-8px)] my-1 pe-2 overflow-hidden")).append(Domino6.of("button").attributes({
641
+ "data-action": "submit",
642
+ "data-density": "fine",
643
+ "data-value": this.text
644
+ }).classNames(mx5("dx-button gap-2 w-full overflow-hidden")).append(Domino6.of("dx-icon").attributes({
645
+ icon: "ph--lightning--regular"
646
+ }), Domino6.of("span").classNames("flex-1 truncate min-w-0").text(this.text))).root;
647
+ }
648
+ };
649
+
650
+ // src/components/ChatThread/widgets/ToolWidget.tsx
651
+ import React8, { useCallback, useEffect as useEffect2, useMemo as useMemo2, useRef, useState as useState3 } from "react";
652
+ import { useTranslation as useTranslation5 } from "@dxos/react-ui";
653
+ import { NumericTabs, TextCrawl, TogglePanel as TogglePanel3 } from "@dxos/react-ui-components";
654
+ import { Json as Json2 } from "@dxos/react-ui-syntax-highlighter";
655
+ import { isNonNullable, safeParseJson } from "@dxos/util";
656
+ import { meta as meta5 } from "#meta";
657
+ var ToolWidget = ({ view, blocks = [] }) => {
658
+ const { t } = useTranslation5(meta5.id);
659
+ const items = useMemo2(() => {
660
+ let lastToolCall;
661
+ const tools = [];
662
+ return blocks.filter((block) => block._tag === "toolCall" || block._tag === "toolResult" || block._tag === "stats").map((block) => {
663
+ switch (block._tag) {
664
+ case "toolCall": {
665
+ if (block.pending && lastToolCall?.block.toolCallId === block.toolCallId) {
666
+ return null;
667
+ }
668
+ const tool = tools.find((tool2) => tool2.name === block.name);
669
+ lastToolCall = {
670
+ tool,
671
+ block
672
+ };
673
+ return {
674
+ title: tool?.description ?? [
675
+ t("tool-call.label"),
676
+ block.name
677
+ ].filter(Boolean).join(" "),
678
+ content: {
679
+ ...block,
680
+ input: safeParseJson(block.input)
681
+ }
682
+ };
683
+ }
684
+ case "toolResult": {
685
+ if (block.error) {
686
+ return {
687
+ title: t("tool-error.label"),
688
+ content: block
689
+ };
690
+ }
691
+ const title = lastToolCall?.tool?.description ?? [
692
+ t("tool-result.label"),
693
+ lastToolCall?.block.name
694
+ ].filter(Boolean).join(" ");
695
+ lastToolCall = void 0;
696
+ return {
697
+ title,
698
+ content: {
699
+ ...block,
700
+ result: safeParseJson(block.result)
701
+ }
702
+ };
703
+ }
704
+ case "stats": {
705
+ if (!lastToolCall) {
706
+ return null;
707
+ }
708
+ return {
709
+ title: t("stats.label"),
710
+ content: block
711
+ };
712
+ }
713
+ }
714
+ }).filter(isNonNullable);
715
+ }, [
716
+ blocks,
717
+ t
718
+ ]);
719
+ const handleChangeOpen = useCallback(() => {
720
+ setTimeout(() => {
721
+ view?.requestMeasure();
722
+ }, 1e3);
723
+ }, [
724
+ view
725
+ ]);
726
+ if (!items.length) {
727
+ return null;
728
+ }
729
+ return /* @__PURE__ */ React8.createElement(ToolPanel, {
730
+ items,
731
+ onChangeOpen: handleChangeOpen
732
+ });
733
+ };
734
+ var ToolPanel = ({ items, onChangeOpen }) => {
735
+ const tabsRef = useRef(null);
736
+ const [selected, setSelected] = useState3(0);
737
+ const [open, setOpen] = useState3(false);
738
+ useEffect2(() => {
739
+ setSelected((prev) => Math.min(prev, Math.max(0, items.length - 1)));
740
+ }, [
741
+ items.length
742
+ ]);
743
+ useEffect2(() => {
744
+ onChangeOpen?.(open);
745
+ if (open) {
746
+ tabsRef.current?.focus();
747
+ }
748
+ }, [
749
+ open,
750
+ onChangeOpen
751
+ ]);
752
+ const handleSelect = useCallback((index) => {
753
+ setSelected(index);
754
+ }, []);
755
+ return /* @__PURE__ */ React8.createElement(TogglePanel3.Root, {
756
+ open,
757
+ onChangeOpen: setOpen
758
+ }, /* @__PURE__ */ React8.createElement(TogglePanel3.Header, {
759
+ classNames: "text-sm text-placeholder"
760
+ }, /* @__PURE__ */ React8.createElement(TextCrawl, {
761
+ key: "status-roll",
762
+ lines: items.map((item) => item.title),
763
+ autoAdvance: true,
764
+ greedy: true
765
+ })), /* @__PURE__ */ React8.createElement(TogglePanel3.Content, null, /* @__PURE__ */ React8.createElement(TogglePanel3.Viewport, {
766
+ classNames: "grid grid-cols-[32px_1fr]"
767
+ }, /* @__PURE__ */ React8.createElement(NumericTabs, {
768
+ ref: tabsRef,
769
+ classNames: "p-1",
770
+ length: items.length,
771
+ selected,
772
+ onSelect: handleSelect
773
+ }), /* @__PURE__ */ React8.createElement(Json2.Data, {
774
+ data: items[selected]?.content,
775
+ classNames: "p-1 text-xs bg-transparent",
776
+ replacer: {
777
+ maxDepth: 3,
778
+ maxArrayLen: 10,
779
+ maxStringLen: 128
780
+ }
781
+ }))));
782
+ };
783
+
784
+ // src/components/ChatThread/widgets/StatusWidget.ts
785
+ import { WidgetType as WidgetType7 } from "@codemirror/view";
786
+ import { Domino as Domino7 } from "@dxos/ui";
787
+ import { XML_WIDGET_DATA_ATTR } from "@dxos/ui-editor";
788
+ var StatusWidget = class extends WidgetType7 {
789
+ text;
790
+ #pos;
791
+ /** The timer id last registered for this instance (may differ from the map if superseded). */
792
+ #ownedTimerId = null;
793
+ constructor(text, pos) {
794
+ super(), this.text = text;
795
+ this.#pos = pos === void 0 || pos === "" ? "status" : String(pos);
796
+ }
797
+ eq(other) {
798
+ return this.text === other.text && this.#pos === other.#pos;
799
+ }
800
+ toDOM() {
801
+ return Domino7.of("div").classNames("py-0.5").attributes({
802
+ [XML_WIDGET_DATA_ATTR]: ""
803
+ }).append(Domino7.of("div").classNames("relative overflow-hidden rounded-sm").append(Domino7.of("div").classNames("grid grid-cols-[24px_1fr] gap-x-0.5 gap-y-0 items-start px-0.5 py-0.5 text-placeholder").append(Domino7.of("div").classNames("flex h-5 w-full shrink-0 items-center justify-center self-start").append(Domino7.of("span").classNames("block size-1.5 shrink-0 rounded-full bg-current opacity-45")), Domino7.of("div").classNames("relative min-w-0").append(Domino7.of("div").classNames("relative z-10 rounded-sm text-sm leading-5").attributes({
804
+ "data-status-text": ""
805
+ }).text(this.text), Domino7.of("div").attributes({
806
+ "data-id": this.#pos
807
+ }))))).root;
808
+ }
809
+ updateDOM(dom) {
810
+ dom.querySelector("[data-status-text]")?.replaceChildren(this.text);
811
+ const trailHost = dom.querySelector("[data-id]");
812
+ if (trailHost?.childElementCount === 0) {
813
+ trailHost.append(...createTrailLayers2());
814
+ }
815
+ this.#scheduleTrailRemoval(dom);
816
+ return true;
817
+ }
818
+ destroy(_dom) {
819
+ this.#clearOwnedTrailTimer();
820
+ }
821
+ #scheduleTrailRemoval(dom) {
822
+ const previous = trailRemovalTimers2.get(this.#pos);
823
+ if (previous !== void 0) {
824
+ clearTimeout(previous);
825
+ }
826
+ const timerId = setTimeout(() => {
827
+ if (trailRemovalTimers2.get(this.#pos) !== timerId) {
828
+ return;
829
+ }
830
+ trailRemovalTimers2.delete(this.#pos);
831
+ this.#ownedTimerId = null;
832
+ dom.querySelector("[data-id]")?.remove();
833
+ }, TRAIL_REMOVAL_DELAY_MS2);
834
+ trailRemovalTimers2.set(this.#pos, timerId);
835
+ this.#ownedTimerId = timerId;
836
+ }
837
+ #clearOwnedTrailTimer() {
838
+ const active = trailRemovalTimers2.get(this.#pos);
839
+ if (active !== void 0 && active === this.#ownedTimerId) {
840
+ clearTimeout(active);
841
+ trailRemovalTimers2.delete(this.#pos);
842
+ }
843
+ this.#ownedTimerId = null;
844
+ }
845
+ };
846
+ var trail2 = [
847
+ "absolute z-0 aspect-[2/1] w-16",
848
+ "bg-[radial-gradient(at_100%_50%,_theme(colors.green.700),_transparent_80%)]",
849
+ "[offset-anchor:100%_50%] [offset-path:border-box]"
850
+ ];
851
+ var TRAIL_REMOVAL_DELAY_MS2 = 1e3;
852
+ var trailRemovalTimers2 = /* @__PURE__ */ new Map();
853
+ var createTrailLayers2 = () => [
854
+ Domino7.of("div").classNames(...trail2, "animate-trail").root,
855
+ Domino7.of("div").classNames(...trail2, "animate-trail-offset").root
856
+ ];
857
+
858
+ // src/components/ChatThread/registry.tsx
859
+ var __dxlog_file = "/__w/dxos/dxos/packages/plugins/plugin-assistant/src/components/ChatThread/registry.tsx";
860
+ var componentRegistry = {
861
+ //
862
+ // DOM Widgets
863
+ //
864
+ prompt: {
865
+ block: true,
866
+ factory: ({ children }) => {
867
+ const text = getXmlTextChild(children);
868
+ return text ? new PromptWidget(text) : null;
869
+ }
870
+ },
871
+ reasoning: {
872
+ block: true,
873
+ streaming: true,
874
+ factory: ({ children, range }) => {
875
+ const text = getXmlTextChild(children);
876
+ return text ? new ReasoningWidget(text, range.from) : null;
877
+ }
878
+ },
879
+ reference: {
880
+ block: false,
881
+ factory: ({ children, ref }) => {
882
+ const text = getXmlTextChild(children);
883
+ return text && ref ? new ReferenceWidget(text, ref) : null;
884
+ }
885
+ },
886
+ select: {
887
+ block: true,
888
+ factory: ({ children }) => {
889
+ const options = children?.map((option) => option._tag === "option" && getXmlTextChild(option.children)).filter(Boolean);
890
+ return options?.length ? new SelectWidget(options) : null;
891
+ }
892
+ },
893
+ suggestion: {
894
+ block: true,
895
+ factory: ({ children }) => {
896
+ const text = getXmlTextChild(children);
897
+ return text ? new SuggestionWidget(text) : null;
898
+ }
899
+ },
900
+ stats: {
901
+ block: true,
902
+ factory: ({ children }) => {
903
+ const text = getXmlTextChild(children);
904
+ return text ? new StatsWidget(text) : null;
905
+ }
906
+ },
907
+ status: {
908
+ block: true,
909
+ streaming: true,
910
+ factory: ({ children, range }) => {
911
+ const text = getXmlTextChild(children);
912
+ return text ? new StatusWidget(text, range.from) : null;
913
+ }
914
+ },
915
+ //
916
+ // React Widgets (portaled outside of the editor)
917
+ //
918
+ summary: {
919
+ block: true,
920
+ Component: SummaryWidget
921
+ },
922
+ toolCall: {
923
+ block: true,
924
+ Component: (props) => /* @__PURE__ */ React9.createElement("div", {
925
+ role: "none",
926
+ className: "py-2"
927
+ }, /* @__PURE__ */ React9.createElement(ToolWidget, props))
928
+ },
929
+ toolResult: {
930
+ block: true,
931
+ Component: FallbackWidget
932
+ },
933
+ toolkit: {
934
+ block: true,
935
+ Component: FallbackWidget
936
+ },
937
+ //
938
+ // Fallback
939
+ //
940
+ json: {
941
+ block: true,
942
+ Component: FallbackWidget
943
+ }
944
+ };
945
+ var blockToMarkdown = (context, message, block) => {
946
+ let str = blockToMarkdownImpl(context, message, block);
947
+ if (str && !block.pending) {
948
+ return str += "\n";
949
+ }
950
+ return str;
951
+ };
952
+ var blockToMarkdownImpl = (context, message, block) => {
953
+ log("blockToMarkdown", {
954
+ block: JSON.stringify(block)
955
+ }, {
956
+ F: __dxlog_file,
957
+ L: 140,
958
+ S: void 0,
959
+ C: (f, a) => f(...a)
960
+ });
961
+ switch (block._tag) {
962
+ case "text": {
963
+ if (message.sender.role === "user") {
964
+ return `<prompt>${block.text}</prompt>`;
965
+ } else {
966
+ const text = block.text.trim();
967
+ if (text.length > 0) {
968
+ return text;
969
+ }
970
+ }
971
+ break;
972
+ }
973
+ case "reference": {
974
+ if (block.pending) {
975
+ return;
976
+ }
977
+ const dxn = block.reference.dxn;
978
+ return `<reference ref="${dxn.toString()}">${context.getObjectLabel(dxn)}</reference>`;
979
+ }
980
+ case "suggestion": {
981
+ if (block.pending) {
982
+ return;
983
+ }
984
+ return `<suggestion>${block.text}</suggestion>`;
985
+ }
986
+ case "select": {
987
+ if (block.pending || block.options.length === 0) {
988
+ return;
989
+ }
990
+ return `<select>${block.options.map((option) => `<option>${option}</option>`).join("")}</select>`;
991
+ }
992
+ case "toolCall": {
993
+ applyToolBlockToWidgetState(context, block);
994
+ return `<toolCall id="${block.toolCallId}" />`;
995
+ }
996
+ case "toolResult": {
997
+ applyToolBlockToWidgetState(context, block);
998
+ break;
999
+ }
1000
+ case "stats": {
1001
+ return "";
1002
+ }
1003
+ case "reasoning": {
1004
+ let text = block.reasoningText ?? block.redactedText;
1005
+ if (!text) {
1006
+ return;
1007
+ }
1008
+ return renderXMLBlock("reasoning", {
1009
+ content: text,
1010
+ pending: block.pending
1011
+ });
1012
+ }
1013
+ case "summary": {
1014
+ return renderXMLBlock("summary", {
1015
+ content: block.content,
1016
+ pending: block.pending
1017
+ });
1018
+ }
1019
+ case "status": {
1020
+ return renderXMLBlock("status", {
1021
+ content: block.statusText,
1022
+ pending: block.pending
1023
+ });
1024
+ }
1025
+ default: {
1026
+ return `<json id="${message.id}">
1027
+ ${JSON.stringify(block)}
1028
+ </json>`;
1029
+ }
1030
+ }
1031
+ };
1032
+ var escapeXmlTextContent = (raw) => raw.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
1033
+ var stripBulletLikeLinePrefixes = (raw) => raw.split(/\r?\n/).map((line) => line.replace(/^\s*(?:[-*+•]|\d+[.)]\s)/, "")).join("\n");
1034
+ var renderXMLBlock = (tag, opts) => {
1035
+ const content = escapeXmlTextContent(stripBulletLikeLinePrefixes((opts.content ?? "").replace(/\n\n/g, " ").trim()));
1036
+ if (opts.pending) {
1037
+ return `<${tag}${opts.attributes ? ` ${opts.attributes}` : ""}>${content}`;
1038
+ } else {
1039
+ return `<${tag}${opts.attributes ? ` ${opts.attributes}` : ""}>${content}</${tag}>`;
1040
+ }
1041
+ };
1042
+
1043
+ // src/components/ChatThread/sync.ts
1044
+ import { log as log2 } from "@dxos/log";
1045
+ var __dxlog_file2 = "/__w/dxos/dxos/packages/plugins/plugin-assistant/src/components/ChatThread/sync.ts";
1046
+ var MessageThreadContext = class {
1047
+ _widgetState;
1048
+ constructor(_widgetState) {
1049
+ this._widgetState = _widgetState;
1050
+ }
1051
+ updateWidget(id, value2) {
1052
+ this._widgetState?.updateWidget(id, value2);
1053
+ }
1054
+ // TODO(burdon): Resolve from hypergraph.
1055
+ getObjectLabel(_id) {
1056
+ return "Object";
1057
+ }
1058
+ };
1059
+ var MessageSyncer = class {
1060
+ _document;
1061
+ _renderer;
1062
+ #syncEpoch = 0;
1063
+ _initialMessageId;
1064
+ _currentMessageIndex = 0;
1065
+ _currentBlockIndex = 0;
1066
+ _currentBlockContent;
1067
+ _context;
1068
+ constructor(_document, _renderer) {
1069
+ this._document = _document;
1070
+ this._renderer = _renderer;
1071
+ this._context = new MessageThreadContext(this._document);
1072
+ }
1073
+ get context() {
1074
+ return this._context;
1075
+ }
1076
+ reset() {
1077
+ log2("reset", void 0, {
1078
+ F: __dxlog_file2,
1079
+ L: 67,
1080
+ S: this,
1081
+ C: (f, a) => f(...a)
1082
+ });
1083
+ this.#syncEpoch++;
1084
+ this._initialMessageId = void 0;
1085
+ this._currentMessageIndex = 0;
1086
+ this._currentBlockIndex = 0;
1087
+ this._currentBlockContent = void 0;
1088
+ void this._document.setContent("");
1089
+ }
1090
+ /**
1091
+ * Syncs messages with the editor.
1092
+ */
1093
+ append(messages, flush = false) {
1094
+ if (this._initialMessageId !== messages[0]?.id) {
1095
+ this.reset();
1096
+ this._initialMessageId = messages[0]?.id;
1097
+ }
1098
+ if (this._document.length === 0 && flush) {
1099
+ const buffer = [];
1100
+ this.processBlocks(messages, (content2) => buffer.push(content2));
1101
+ const content = buffer.join("");
1102
+ const epoch = this.#syncEpoch;
1103
+ void this._document.setContent(content).then(() => {
1104
+ if (epoch !== this.#syncEpoch) {
1105
+ return;
1106
+ }
1107
+ rehydrateToolWidgetsFromMessages(this._context, messages);
1108
+ }).catch((error) => {
1109
+ log2.warn("failed to replace thread content before widget rehydration", {
1110
+ error
1111
+ }, {
1112
+ F: __dxlog_file2,
1113
+ L: 108,
1114
+ S: this,
1115
+ C: (f, a) => f(...a)
1116
+ });
1117
+ });
1118
+ return true;
1119
+ } else {
1120
+ this.processBlocks(messages, (content) => {
1121
+ void this._document.append(content);
1122
+ });
1123
+ return false;
1124
+ }
1125
+ }
1126
+ processBlocks(messages, append) {
1127
+ let i = this._currentMessageIndex;
1128
+ for (const message of messages.slice(this._currentMessageIndex)) {
1129
+ if (i > this._currentMessageIndex) {
1130
+ this._currentBlockIndex = 0;
1131
+ }
1132
+ this._currentMessageIndex = i;
1133
+ let j = this._currentBlockIndex;
1134
+ for (const block of message.blocks.slice(this._currentBlockIndex)) {
1135
+ this._currentBlockIndex = j;
1136
+ const currentBlockContent = this._renderer(this._context, message, block);
1137
+ if (currentBlockContent) {
1138
+ let content = "";
1139
+ if (this._currentBlockContent && currentBlockContent.startsWith(this._currentBlockContent)) {
1140
+ content = currentBlockContent.slice(this._currentBlockContent.length);
1141
+ } else {
1142
+ content = currentBlockContent;
1143
+ }
1144
+ this._currentBlockContent = currentBlockContent;
1145
+ append(content);
1146
+ }
1147
+ if (block.pending) {
1148
+ return;
1149
+ } else {
1150
+ this._currentBlockContent = void 0;
1151
+ this._currentBlockIndex++;
1152
+ }
1153
+ j++;
1154
+ }
1155
+ i++;
1156
+ }
1157
+ }
1158
+ };
1159
+
1160
+ // src/components/ChatThread/ChatThread.tsx
1161
+ var defaultOptions = {
1162
+ autoScroll: true,
1163
+ // wire: true,
1164
+ cursor: true
1165
+ };
1166
+ var ChatThread = /* @__PURE__ */ forwardRef(({ classNames, identity, messages = [], error, options = defaultOptions, debug = false, onEvent }, forwardedRef) => {
1167
+ const [controller, setController] = useState4(null);
1168
+ const handleMarkdownStreamRef = useCallback2((instance) => {
1169
+ setController(instance);
1170
+ setRef(forwardedRef, instance);
1171
+ }, [
1172
+ forwardedRef
1173
+ ]);
1174
+ const userHue = useMemo3(() => identity?.profile?.data?.hue || keyToFallback(identity?.identityKey ?? PublicKey.random()).hue, [
1175
+ identity
1176
+ ]);
1177
+ useEffect3(() => {
1178
+ controller?.scrollToBottom();
1179
+ }, [
1180
+ controller,
1181
+ error
1182
+ ]);
1183
+ const syncer = useMemo3(() => controller && new MessageSyncer(controller, blockToMarkdown), [
1184
+ controller
1185
+ ]);
1186
+ useEffect3(() => {
1187
+ const reset = syncer?.append(messages, true);
1188
+ if (reset) {
1189
+ controller?.scrollToBottom("instant");
1190
+ }
1191
+ }, [
1192
+ controller,
1193
+ syncer,
1194
+ messages
1195
+ ]);
1196
+ const handleEvent = useCallback2(({ type, value: value2 }) => {
1197
+ switch (type) {
1198
+ case "submit": {
1199
+ value2 && onEvent?.({
1200
+ type,
1201
+ text: value2
1202
+ });
1203
+ break;
1204
+ }
1205
+ }
1206
+ }, [
1207
+ onEvent
1208
+ ]);
1209
+ return /* @__PURE__ */ React10.createElement("div", {
1210
+ role: "none",
1211
+ className: mx6("flex h-full w-full justify-center overflow-hidden", classNames),
1212
+ style: {
1213
+ "--user-fill": `var(--color-${userHue}-fill)`
1214
+ }
1215
+ }, /* @__PURE__ */ React10.createElement(MarkdownStream, {
1216
+ registry: componentRegistry,
1217
+ options,
1218
+ debug,
1219
+ onEvent: handleEvent,
1220
+ ref: handleMarkdownStreamRef
1221
+ }));
1222
+ });
1223
+
1224
+ // src/components/Chat/Chat.tsx
1225
+ var [ChatContextProvider, useChatContext] = createContext("Chat");
1226
+ var ChatRoot = ({ children, chat, queue, processor, onEvent, ...props }) => {
1227
+ const [debug, setDebug] = useState5(false);
1228
+ const pending = useAtomValue(processor.messages);
1229
+ const streaming = useAtomValue(processor.streaming);
1230
+ const lastPrompt = useRef2(void 0);
1231
+ const storedMessages = useQuery2(queue, Filter2.type(Message.Message));
1232
+ const messages = useMemo4(() => {
1233
+ return Array2.dedupeWith([
1234
+ ...storedMessages,
1235
+ ...pending
1236
+ ], ({ id: a }, { id: b }) => a === b);
1237
+ }, [
1238
+ storedMessages,
1239
+ pending
1240
+ ]);
1241
+ const dump = useCallback3(async () => {
1242
+ const objects = processor.context.getObjects();
1243
+ const blueprints = processor.context.getBlueprints();
1244
+ const system = await processor.getSystemPrompt();
1245
+ const tools = await processor.getTools();
1246
+ console.group("Chat", {
1247
+ objects,
1248
+ blueprints
1249
+ });
1250
+ console.log(trim`
1251
+ System Prompt:
1252
+ ${system}
1253
+ `);
1254
+ console.log(trim`
1255
+ Tools:
1256
+ ${Object.values(tools).map((tool) => JSON.stringify(tool, null, 2)).join("\n")}
1257
+ `);
1258
+ console.groupEnd();
1259
+ }, [
1260
+ processor
1261
+ ]);
1262
+ const event = useMemo4(() => new Event(), []);
1263
+ useEffect4(() => {
1264
+ return event.on((ev) => {
1265
+ switch (ev.type) {
1266
+ case "toggle-debug": {
1267
+ setDebug((debug2) => {
1268
+ if (debug2) {
1269
+ return false;
1270
+ } else {
1271
+ void dump();
1272
+ return true;
1273
+ }
1274
+ });
1275
+ break;
1276
+ }
1277
+ case "submit": {
1278
+ const text = ev.text.trim();
1279
+ if (!streaming && text.length) {
1280
+ lastPrompt.current = ev.text;
1281
+ void processor.request({
1282
+ message: text
1283
+ });
1284
+ }
1285
+ break;
1286
+ }
1287
+ case "retry": {
1288
+ if (!streaming) {
1289
+ void processor.retry();
1290
+ }
1291
+ break;
1292
+ }
1293
+ case "cancel": {
1294
+ if (streaming) {
1295
+ void processor.cancel();
1296
+ if (lastPrompt.current) {
1297
+ event.emit({
1298
+ type: "update-prompt",
1299
+ text: lastPrompt.current
1300
+ });
1301
+ }
1302
+ }
1303
+ break;
1304
+ }
1305
+ }
1306
+ onEvent?.(ev);
1307
+ });
1308
+ }, [
1309
+ event,
1310
+ dump,
1311
+ processor,
1312
+ streaming,
1313
+ onEvent
1314
+ ]);
1315
+ const db = props.db ?? (chat && Obj3.getDatabase(chat));
1316
+ return /* @__PURE__ */ React11.createElement(ChatContextProvider, {
1317
+ debug,
1318
+ event,
1319
+ db,
1320
+ chat,
1321
+ messages,
1322
+ processor,
1323
+ ...props
1324
+ }, children);
1325
+ };
1326
+ ChatRoot.displayName = "Chat.Root";
1327
+ var CHAT_VIEWPORT_NAME = "Chat.Viewport";
1328
+ var ChatViewport = composable(({ children, ...props }, forwardedRef) => {
1329
+ return /* @__PURE__ */ React11.createElement("div", {
1330
+ ...composableProps(props, {
1331
+ classNames: "dx-expander flex flex-col"
1332
+ }),
1333
+ ref: forwardedRef
1334
+ }, children);
1335
+ });
1336
+ ChatViewport.displayName = CHAT_VIEWPORT_NAME;
1337
+ var CHAT_THREAD_NAME = "Chat.Thread";
1338
+ var ChatThread2 = (props) => {
1339
+ const { debug, event, messages, processor } = useChatContext(CHAT_THREAD_NAME);
1340
+ const identity = useIdentity();
1341
+ const error = useAtomValue(processor.error).pipe(Option3.getOrUndefined);
1342
+ const controllerRef = useRef2(null);
1343
+ useEffect4(() => {
1344
+ return event.on((event2) => {
1345
+ switch (event2.type) {
1346
+ case "submit":
1347
+ case "scroll-to-bottom":
1348
+ controllerRef.current?.scrollToBottom();
1349
+ break;
1350
+ case "nav-previous":
1351
+ controllerRef.current?.navigatePrevious();
1352
+ break;
1353
+ case "nav-next":
1354
+ controllerRef.current?.navigateNext();
1355
+ break;
1356
+ }
1357
+ });
1358
+ }, [
1359
+ event
1360
+ ]);
1361
+ const handleEvent = useCallback3((ev) => {
1362
+ event.emit(ev);
1363
+ }, [
1364
+ event
1365
+ ]);
1366
+ if (!identity) {
1367
+ return null;
1368
+ }
1369
+ return /* @__PURE__ */ React11.createElement(ChatThread, {
1370
+ ...props,
1371
+ identity,
1372
+ messages,
1373
+ error,
1374
+ debug,
1375
+ onEvent: handleEvent,
1376
+ ref: controllerRef
1377
+ });
1378
+ };
1379
+ ChatThread2.displayName = CHAT_THREAD_NAME;
1380
+ var CHAT_PROMPT_NAME = "Chat.Prompt";
1381
+ var ChatPrompt = ({ classNames, outline, settings = true, placeholder, expandable, online, presets, preset, onPresetChange, onOnlineChange }) => {
1382
+ const { t } = useTranslation6(meta6.id);
1383
+ const { db, processor, event } = useChatContext(CHAT_PROMPT_NAME);
1384
+ const error = useAtomValue(processor.error).pipe(Option3.getOrUndefined);
1385
+ const streaming = useAtomValue(processor.streaming);
1386
+ const active = useAtomValue(processor.active);
1387
+ const activeRef = useDynamicRef(active);
1388
+ const editorRef = useRef2(null);
1389
+ const [recordingState, setRecordingState] = useState5(false);
1390
+ useEffect4(() => {
1391
+ return event.on((event2) => {
1392
+ switch (event2.type) {
1393
+ case "update-prompt":
1394
+ if (!editorRef.current?.getText()?.length) {
1395
+ editorRef.current?.setText(event2.text);
1396
+ editorRef.current?.focus();
1397
+ }
1398
+ break;
1399
+ case "record-start":
1400
+ setRecordingState(true);
1401
+ break;
1402
+ case "record-stop":
1403
+ setRecordingState(false);
1404
+ break;
1405
+ }
1406
+ });
1407
+ }, [
1408
+ event
1409
+ ]);
1410
+ const { recording } = useVoiceInput({
1411
+ active: recordingState,
1412
+ onUpdate: (text) => {
1413
+ editorRef.current?.setText(text);
1414
+ editorRef.current?.focus();
1415
+ }
1416
+ });
1417
+ const extensions = useMemo4(() => {
1418
+ return [
1419
+ Prec.highest(keymap.of([
1420
+ {
1421
+ key: "Mod-d",
1422
+ preventDefault: true,
1423
+ run: () => {
1424
+ event.emit({
1425
+ type: "toggle-debug"
1426
+ });
1427
+ return true;
1428
+ }
1429
+ },
1430
+ {
1431
+ key: "Mod-ArrowUp",
1432
+ preventDefault: true,
1433
+ run: () => {
1434
+ event.emit({
1435
+ type: "nav-previous"
1436
+ });
1437
+ return true;
1438
+ },
1439
+ shift: () => {
1440
+ event.emit({
1441
+ type: "thread-open"
1442
+ });
1443
+ return true;
1444
+ }
1445
+ },
1446
+ {
1447
+ key: "Mod-ArrowDown",
1448
+ preventDefault: true,
1449
+ run: () => {
1450
+ event.emit({
1451
+ type: "nav-next"
1452
+ });
1453
+ return true;
1454
+ },
1455
+ shift: () => {
1456
+ event.emit({
1457
+ type: "thread-close"
1458
+ });
1459
+ return true;
1460
+ }
1461
+ }
1462
+ ]))
1463
+ ].filter(isTruthy);
1464
+ }, [
1465
+ event,
1466
+ expandable
1467
+ ]);
1468
+ const handleSubmit = useCallback3((text) => {
1469
+ if (!activeRef.current) {
1470
+ event.emit({
1471
+ type: "submit",
1472
+ text
1473
+ });
1474
+ return true;
1475
+ }
1476
+ }, [
1477
+ event
1478
+ ]);
1479
+ const handleEvent = useCallback3((ev) => {
1480
+ event.emit(ev);
1481
+ }, [
1482
+ event
1483
+ ]);
1484
+ return /* @__PURE__ */ React11.createElement("div", {
1485
+ role: "group",
1486
+ className: mx7("flex flex-col w-full dx-density-fine", outline && "bg-group-surface border border-subdued-separator transition transition-border [&:has(.cm-content:focus)]:border-separator rounded-sm", classNames)
1487
+ }, /* @__PURE__ */ React11.createElement("div", {
1488
+ role: "none",
1489
+ className: "flex p-2 gap-2"
1490
+ }, /* @__PURE__ */ React11.createElement(ChatStatusIndicator, {
1491
+ classNames: "p-1",
1492
+ preset,
1493
+ error,
1494
+ processing: streaming
1495
+ }), /* @__PURE__ */ React11.createElement(ChatEditor, {
1496
+ ref: editorRef,
1497
+ autoFocus: true,
1498
+ lineWrapping: true,
1499
+ classNames: "col-span-2 pt-0.5",
1500
+ placeholder: placeholder ?? t("prompt.placeholder"),
1501
+ extensions,
1502
+ onSubmit: handleSubmit
1503
+ })), db && settings && /* @__PURE__ */ React11.createElement("div", {
1504
+ role: "none",
1505
+ className: "flex items-center overflow-hidden"
1506
+ }, /* @__PURE__ */ React11.createElement(ChatOptions, {
1507
+ db,
1508
+ blueprintRegistry: processor.blueprintRegistry,
1509
+ context: processor.context,
1510
+ preset,
1511
+ presets,
1512
+ onPresetChange
1513
+ }), /* @__PURE__ */ React11.createElement("div", {
1514
+ role: "none",
1515
+ className: "flex grow overflow-x-auto scrollbar-none"
1516
+ }, /* @__PURE__ */ React11.createElement(ChatReferences, {
1517
+ db,
1518
+ context: processor.context
1519
+ })), /* @__PURE__ */ React11.createElement(ChatActions, {
1520
+ classNames: "col-span-2",
1521
+ microphone: true,
1522
+ recording,
1523
+ processing: streaming,
1524
+ onEvent: handleEvent
1525
+ }, online !== void 0 && /* @__PURE__ */ React11.createElement(Input.Root, null, /* @__PURE__ */ React11.createElement(Input.Label, {
1526
+ srOnly: true
1527
+ }, t("online-switch.label")), /* @__PURE__ */ React11.createElement(Input.Switch, {
1528
+ classNames: "mx-2",
1529
+ checked: online,
1530
+ onCheckedChange: onOnlineChange
1531
+ })))));
1532
+ };
1533
+ ChatPrompt.displayName = CHAT_PROMPT_NAME;
1534
+ var CHAT_TOOLBAR_NAME = "Chat.Toolbar";
1535
+ var ChatToolbar = composable(({ attendableId, companionTo, ...props }, forwardedRef) => {
1536
+ const { chat } = useChatContext(CHAT_TOOLBAR_NAME);
1537
+ const menuActions = useChatToolbarActions({
1538
+ chat,
1539
+ companionTo
1540
+ });
1541
+ return /* @__PURE__ */ React11.createElement(Menu.Root, {
1542
+ ...menuActions,
1543
+ attendableId
1544
+ }, /* @__PURE__ */ React11.createElement(Menu.Toolbar, {
1545
+ ...composableProps(props),
1546
+ ref: forwardedRef
1547
+ }));
1548
+ });
1549
+ ChatToolbar.displayName = CHAT_TOOLBAR_NAME;
1550
+ var Chat = {
1551
+ Root: ChatRoot,
1552
+ Viewport: ChatViewport,
1553
+ Thread: ChatThread2,
1554
+ Prompt: ChatPrompt,
1555
+ Toolbar: ChatToolbar
1556
+ };
1557
+
1558
+ // src/components/ProcessTree/ProcessTree.tsx
1559
+ import * as Match from "effect/Match";
1560
+ import React12 from "react";
1561
+ import { Process } from "@dxos/functions-runtime";
1562
+ import { Icon as Icon2, ScrollArea, Treegrid } from "@dxos/react-ui";
1563
+ import { composable as composable2, composableProps as composableProps2, mx as mx8 } from "@dxos/ui-theme";
1564
+ var ProcessTree = composable2(({ processes, onProcessSelect, ...props }, forwardedRef) => {
1565
+ const filteredProcesses = [
1566
+ ...processes.filter((process) => [
1567
+ Process.State.RUNNING,
1568
+ Process.State.HYBERNATING
1569
+ ].includes(process.state)),
1570
+ ...processes.filter((process) => [
1571
+ Process.State.IDLE
1572
+ ].includes(process.state)).slice(0, 3),
1573
+ ...processes.filter((process) => [
1574
+ Process.State.SUCCEEDED,
1575
+ Process.State.FAILED,
1576
+ Process.State.TERMINATED
1577
+ ].includes(process.state)).slice(0, 3)
1578
+ ];
1579
+ return /* @__PURE__ */ React12.createElement(ScrollArea.Root, {
1580
+ ...composableProps2(props, {
1581
+ classNames: "dx-expander"
1582
+ }),
1583
+ thin: true,
1584
+ ref: forwardedRef
1585
+ }, /* @__PURE__ */ React12.createElement(ScrollArea.Viewport, null, /* @__PURE__ */ React12.createElement(Treegrid.Root, {
1586
+ gridTemplateColumns: "1fr"
1587
+ }, filteredProcesses.filter((process) => process.parentPid === null).map((process) => {
1588
+ const activeChildren = filteredProcesses.filter((candidate) => candidate.parentPid?.toString() === process.pid.toString() && candidate.state === Process.State.RUNNING);
1589
+ return /* @__PURE__ */ React12.createElement(Treegrid.Row, {
1590
+ key: process.pid.toString(),
1591
+ id: process.pid.toString(),
1592
+ parentOf: process.parentPid?.toString()
1593
+ }, /* @__PURE__ */ React12.createElement(Treegrid.Cell, {
1594
+ indent: true,
1595
+ classNames: "flex items-center p-1 gap-2 min-w-0",
1596
+ onClick: () => onProcessSelect?.(process)
1597
+ }, /* @__PURE__ */ React12.createElement(Icon2, {
1598
+ size: 4,
1599
+ icon: Match.value(process.state).pipe(Match.when(Process.State.RUNNING, () => "ph--spinner-gap--regular"), Match.when(Process.State.SUCCEEDED, () => "ph--check-circle--regular"), Match.when(Process.State.FAILED, () => "ph--warning--regular"), Match.when(Process.State.HYBERNATING, () => "ph--spinner--regular"), Match.when(Process.State.IDLE, () => "ph--hourglass--regular"), Match.when(Process.State.TERMINATING, () => "ph--x-circle--regular"), Match.when(Process.State.TERMINATED, () => "ph--x-circle--regular"), Match.orElse(() => "ph--spinner-gap--regular")),
1600
+ classNames: mx8(process.state === Process.State.RUNNING && "animate-spin", process.state === Process.State.FAILED && "text-error-text", process.state === Process.State.SUCCEEDED && "text-success-text")
1601
+ }), /* @__PURE__ */ React12.createElement("div", {
1602
+ role: "none",
1603
+ className: "flex items-center gap-2 text-xs overflow-hidden"
1604
+ }, /* @__PURE__ */ React12.createElement("span", {
1605
+ className: "text-description"
1606
+ }, process.params.name), activeChildren.length > 0 && /* @__PURE__ */ React12.createElement("span", {
1607
+ className: "text-xs text-description ml-1"
1608
+ }, activeChildren[0].params.name))));
1609
+ }))));
1610
+ });
1611
+
1612
+ // src/components/TemplateEditor/TemplateEditor.tsx
1613
+ import { defaultHighlightStyle, syntaxHighlighting } from "@codemirror/language";
1614
+ import { composeRefs } from "@radix-ui/react-compose-refs";
1615
+ import React13 from "react";
1616
+ import { createDocAccessor } from "@dxos/echo-db";
1617
+ import { useThemeContext, useTranslation as useTranslation7 } from "@dxos/react-ui";
1618
+ import { useTextEditor } from "@dxos/react-ui-editor";
1619
+ import { createBasicExtensions, createDataExtensions, createMarkdownExtensions, createThemeExtensions, decorateMarkdown } from "@dxos/ui-editor";
1620
+ import { composable as composable3, composableProps as composableProps3 } from "@dxos/ui-theme";
1621
+ import { isNonNullable as isNonNullable2 } from "@dxos/util";
1622
+ import { meta as meta7 } from "#meta";
1623
+
1624
+ // src/components/TemplateEditor/extensions/handlebars-extension.ts
1625
+ import { autocompletion, completionKeymap } from "@codemirror/autocomplete";
1626
+ import { RangeSetBuilder } from "@codemirror/state";
1627
+ import { Decoration, ViewPlugin, WidgetType as WidgetType8, keymap as keymap2 } from "@codemirror/view";
1628
+ import { Domino as Domino8, mx as mx9 } from "@dxos/ui";
1629
+ var handlebars = (_ = {}) => {
1630
+ return [
1631
+ handlebarsHighlightPlugin,
1632
+ autocompletion({
1633
+ activateOnTyping: true,
1634
+ aboveCursor: true,
1635
+ closeOnBlur: true,
1636
+ override: [
1637
+ handlebarsCompletions
1638
+ ]
1639
+ }),
1640
+ keymap2.of(completionKeymap)
1641
+ ];
1642
+ };
1643
+ var regex = {
1644
+ // {{! comment }}
1645
+ comment: /\{\{!\s*[^}]*\}\}/g,
1646
+ // {{var}}
1647
+ brackets: /\{\{[^}]*\}\}/g,
1648
+ // {{#command}} {{/command}}
1649
+ command: /\{\{[#/]([^}]+)\}\}/g,
1650
+ // {{var}}
1651
+ var: /\{\{(?!\s*!)(\w[^}]*)\}\}/g,
1652
+ // @dxn:queue:data:xxx
1653
+ dxn: /@?dxn:[\w@:]+/g,
1654
+ // dxos.org/type/xxx
1655
+ url: /[\w.-]+\.[\w.-]+\/[\w/]+/g
1656
+ };
1657
+ var tagPadding = "mx-0.5 px-1 rounded-xs";
1658
+ var handlebarsHighlightPlugin = ViewPlugin.fromClass(class {
1659
+ decorations;
1660
+ constructor(view) {
1661
+ this.decorations = this.buildDecorations(view);
1662
+ }
1663
+ update(update) {
1664
+ if (update.docChanged || update.viewportChanged || update.selectionSet) {
1665
+ this.decorations = this.buildDecorations(update.view);
1666
+ }
1667
+ }
1668
+ // NOTE: Decorations may clash with other extensions (e.g., markdown).
1669
+ buildDecorations(view) {
1670
+ const selection = view.state.selection.main;
1671
+ const decorations = [];
1672
+ for (const { from, to } of view.visibleRanges) {
1673
+ const text = view.state.doc.sliceString(from, to);
1674
+ {
1675
+ let match;
1676
+ while ((match = regex.dxn.exec(text)) !== null) {
1677
+ const start = from + match.index;
1678
+ const end = start + match[0].length;
1679
+ const overlaps = selection.to > start && selection.from <= end;
1680
+ if (!overlaps) {
1681
+ decorations.push({
1682
+ from: start,
1683
+ to: end,
1684
+ decoration: Decoration.widget({
1685
+ widget: new DXNWidget(match[0])
1686
+ })
1687
+ });
1688
+ }
1689
+ }
1690
+ }
1691
+ {
1692
+ let match;
1693
+ while ((match = regex.url.exec(text)) !== null) {
1694
+ const start = from + match.index;
1695
+ const end = start + match[0].length;
1696
+ decorations.push({
1697
+ from: start,
1698
+ to: end,
1699
+ decoration: Decoration.mark({
1700
+ class: mx9("dx-tag--blue", tagPadding)
1701
+ })
1702
+ });
1703
+ }
1704
+ }
1705
+ {
1706
+ let match;
1707
+ while ((match = regex.brackets.exec(text)) !== null) {
1708
+ const start = from + match.index;
1709
+ const end = start + match[0].length;
1710
+ decorations.push({
1711
+ from: start,
1712
+ to: end,
1713
+ decoration: Decoration.mark({
1714
+ class: "text-subdued"
1715
+ })
1716
+ });
1717
+ }
1718
+ }
1719
+ {
1720
+ let match;
1721
+ while ((match = regex.command.exec(text)) !== null) {
1722
+ const start = from + match.index + 2;
1723
+ let end = start + match[0].length - 4;
1724
+ const text2 = view.state.doc.sliceString(start, end);
1725
+ const parts = text2.split(/\s+/);
1726
+ if (parts.length > 1) {
1727
+ const idx = start + parts[0].length;
1728
+ decorations.push({
1729
+ from: idx,
1730
+ to: end,
1731
+ decoration: Decoration.mark({
1732
+ class: "text-green-text"
1733
+ })
1734
+ });
1735
+ end = idx;
1736
+ }
1737
+ decorations.push({
1738
+ from: start,
1739
+ to: end,
1740
+ decoration: Decoration.mark({
1741
+ class: "text-blue-text"
1742
+ })
1743
+ });
1744
+ }
1745
+ }
1746
+ {
1747
+ let match;
1748
+ while ((match = regex.var.exec(text)) !== null) {
1749
+ const start = from + match.index + 2;
1750
+ const end = start + match[0].length - 4;
1751
+ decorations.push({
1752
+ from: start,
1753
+ to: end,
1754
+ decoration: Decoration.mark({
1755
+ class: "text-green-text"
1756
+ })
1757
+ });
1758
+ }
1759
+ }
1760
+ }
1761
+ decorations.sort((a, b) => a.from - b.from || a.to - b.to);
1762
+ const builder = new RangeSetBuilder();
1763
+ for (const { from, to, decoration } of decorations) {
1764
+ builder.add(from, to, decoration);
1765
+ }
1766
+ return builder.finish();
1767
+ }
1768
+ }, {
1769
+ decorations: (v) => v.decorations
1770
+ });
1771
+ var DXNWidget = class extends WidgetType8 {
1772
+ _identifier;
1773
+ constructor(_identifier) {
1774
+ super(), this._identifier = _identifier;
1775
+ }
1776
+ ignoreEvent() {
1777
+ return false;
1778
+ }
1779
+ eq(other) {
1780
+ return this._identifier === other._identifier;
1781
+ }
1782
+ toDOM() {
1783
+ const text = this._identifier.split(":").map((part) => {
1784
+ const len = 16;
1785
+ const plen = 4;
1786
+ if (part.length > len) {
1787
+ return `[${part.slice(0, plen)}\u2026${part.slice(-plen)}]`;
1788
+ }
1789
+ return part;
1790
+ }).join(":");
1791
+ return Domino8.of("span").classNames(mx9("font-mono dx-tag--blue", tagPadding)).text(text).root;
1792
+ }
1793
+ };
1794
+ var variables = [
1795
+ "this"
1796
+ ];
1797
+ var commands = [
1798
+ "this",
1799
+ "each",
1800
+ "if",
1801
+ "unless",
1802
+ "with"
1803
+ ];
1804
+ function handlebarsCompletions(context) {
1805
+ const match = context.matchBefore(/\{\{[^}]*/);
1806
+ if (!match || match.from === match.to) {
1807
+ return null;
1808
+ }
1809
+ let type = "variable";
1810
+ let text = match.text.slice(2);
1811
+ let from = match.from + 2;
1812
+ let matches = [];
1813
+ if (text.startsWith("#") || text.startsWith("/")) {
1814
+ const idx = text.lastIndexOf(" ");
1815
+ if (idx !== -1) {
1816
+ type = "variable";
1817
+ matches = variables;
1818
+ text = text.slice(idx + 1);
1819
+ from += idx + 1;
1820
+ } else {
1821
+ type = "command";
1822
+ text = text.slice(1);
1823
+ matches = commands;
1824
+ from += 1;
1825
+ }
1826
+ } else {
1827
+ type = "variable";
1828
+ matches = variables;
1829
+ }
1830
+ const options = matches.filter((name) => name.startsWith(text)).map((name) => ({
1831
+ type,
1832
+ label: name
1833
+ }));
1834
+ return {
1835
+ from,
1836
+ options
1837
+ };
1838
+ }
1839
+
1840
+ // src/components/TemplateEditor/extensions/xml-extension.ts
1841
+ import { syntaxTree } from "@codemirror/language";
1842
+ import { RangeSetBuilder as RangeSetBuilder2 } from "@codemirror/state";
1843
+ import { Decoration as Decoration2, ViewPlugin as ViewPlugin2 } from "@codemirror/view";
1844
+ var xmlDecorator = (_ = {}) => {
1845
+ return [
1846
+ xmlDecoratorPlugin
1847
+ ];
1848
+ };
1849
+ var xmlDecoratorPlugin = ViewPlugin2.fromClass(class {
1850
+ decorations;
1851
+ constructor(view) {
1852
+ this.decorations = this.buildDecorations(view);
1853
+ }
1854
+ update(update) {
1855
+ if (update.docChanged || update.viewportChanged) {
1856
+ this.decorations = this.buildDecorations(update.view);
1857
+ }
1858
+ }
1859
+ buildDecorations(view) {
1860
+ const builder = new RangeSetBuilder2();
1861
+ for (const { from, to } of view.visibleRanges) {
1862
+ syntaxTree(view.state).iterate({
1863
+ from,
1864
+ to,
1865
+ enter: (node) => {
1866
+ if (node.name === "HTMLTag" || node.name === "OpenTag" || node.name === "CloseTag" || node.name === "SelfClosingTag" || node.name === "Element") {
1867
+ builder.add(node.from, node.to, Decoration2.mark({
1868
+ class: "font-mono text-subdued"
1869
+ }));
1870
+ }
1871
+ }
1872
+ });
1873
+ }
1874
+ return builder.finish();
1875
+ }
1876
+ }, {
1877
+ decorations: (v) => v.decorations
1878
+ });
1879
+
1880
+ // src/components/TemplateEditor/TemplateEditor.tsx
1881
+ var TemplateEditor = composable3(({ classNames, id, template, lineNumbers = true, ...props }, forwardedRef) => {
1882
+ const { t } = useTranslation7(meta7.id);
1883
+ const { themeMode } = useThemeContext();
1884
+ const { parentRef } = useTextEditor(() => {
1885
+ const text = template.source?.target;
1886
+ if (!text) {
1887
+ return {};
1888
+ }
1889
+ return {
1890
+ initialValue: text.content ?? "",
1891
+ extensions: [
1892
+ createDataExtensions({
1893
+ id,
1894
+ text: createDocAccessor(text, [
1895
+ "content"
1896
+ ])
1897
+ }),
1898
+ createBasicExtensions({
1899
+ bracketMatching: false,
1900
+ lineNumbers,
1901
+ lineWrapping: true,
1902
+ placeholder: t("template.placeholder")
1903
+ }),
1904
+ createThemeExtensions({
1905
+ themeMode
1906
+ }),
1907
+ createMarkdownExtensions(),
1908
+ decorateMarkdown(),
1909
+ handlebars(),
1910
+ // xml(),
1911
+ // NOTE: Since we're using markdown only HTML nodes are parsed.
1912
+ xmlDecorator(),
1913
+ syntaxHighlighting(defaultHighlightStyle)
1914
+ ].filter(isNonNullable2)
1915
+ };
1916
+ }, [
1917
+ themeMode,
1918
+ template.source?.target,
1919
+ lineNumbers
1920
+ ]);
1921
+ return /* @__PURE__ */ React13.createElement("div", {
1922
+ ...composableProps3(props, {
1923
+ role: "none",
1924
+ classNames: [
1925
+ "h-full overflow-hidden",
1926
+ classNames
1927
+ ]
1928
+ }),
1929
+ ref: composeRefs(parentRef, forwardedRef)
1930
+ });
1931
+ });
1932
+
1933
+ // src/components/Toolbox/Toolbox.tsx
1934
+ import React14, { Fragment, useEffect as useEffect5, useState as useState6 } from "react";
1935
+ import { log as log3 } from "@dxos/log";
1936
+ import { Operation } from "@dxos/operation";
1937
+ import { Filter as Filter3, useQuery as useQuery3 } from "@dxos/react-client/echo";
1938
+ import { ScrollArea as ScrollArea2 } from "@dxos/react-ui";
1939
+ import { composable as composable4, composableProps as composableProps4, mx as mx10 } from "@dxos/ui-theme";
1940
+ import { ServiceType as ServiceType2 } from "#types";
1941
+ var __dxlog_file3 = "/__w/dxos/dxos/packages/plugins/plugin-assistant/src/components/Toolbox/Toolbox.tsx";
1942
+ var Toolbox = composable4(({ functions, services, blueprints, activeBlueprints, ...props }, forwardedRef) => {
1943
+ return /* @__PURE__ */ React14.createElement(ScrollArea2.Root, {
1944
+ ...composableProps4(props),
1945
+ thin: true,
1946
+ orientation: "vertical",
1947
+ ref: forwardedRef
1948
+ }, /* @__PURE__ */ React14.createElement(ScrollArea2.Viewport, null, blueprints && blueprints.length > 0 && /* @__PURE__ */ React14.createElement(Section, {
1949
+ title: "Blueprints",
1950
+ items: blueprints.map(({ name, description, tools }) => ({
1951
+ name,
1952
+ description,
1953
+ subitems: tools.map((toolId) => ({
1954
+ name: `\u2219 ${safeToolId(toolId)}`
1955
+ }))
1956
+ }))
1957
+ }), activeBlueprints && activeBlueprints.length > 0 && /* @__PURE__ */ React14.createElement(Section, {
1958
+ title: "Blueprints",
1959
+ items: activeBlueprints.map(({ target }) => ({
1960
+ name: target?.name ?? "",
1961
+ description: target?.description ?? "",
1962
+ subitems: target?.tools.map((toolId) => ({
1963
+ name: `\u2219 ${safeToolId(toolId)}`
1964
+ }))
1965
+ }))
1966
+ }), services && services.length > 0 && /* @__PURE__ */ React14.createElement(Section, {
1967
+ title: "Services",
1968
+ items: services.map(({ service: { serviceId, name, description } }) => ({
1969
+ name: name ?? serviceId,
1970
+ description
1971
+ }))
1972
+ }), functions && functions.length > 0 && /* @__PURE__ */ React14.createElement(Section, {
1973
+ title: "Functions",
1974
+ items: functions.map(({ name, description }) => ({
1975
+ name,
1976
+ description
1977
+ }))
1978
+ })));
1979
+ });
1980
+ Toolbox.displayName = "Toolbox";
1981
+ var Section = ({ title, items, striped }) => {
1982
+ const stripeClassNames = "odd:bg-neutral-50 dark:odd:bg-neutral-800";
1983
+ const gridClassNames = "grid grid-cols-[8rem_1fr]";
1984
+ const subGridClassNames = mx10("col-span-full grid grid-cols-subgrid text-xs px-2", striped && stripeClassNames);
1985
+ return /* @__PURE__ */ React14.createElement("div", null, /* @__PURE__ */ React14.createElement("h1", {
1986
+ className: "px-2 text-sm"
1987
+ }, title), /* @__PURE__ */ React14.createElement("div", {
1988
+ className: gridClassNames
1989
+ }, items.map(({ name, description, subitems }, i) => /* @__PURE__ */ React14.createElement(Fragment, {
1990
+ key: i
1991
+ }, name && /* @__PURE__ */ React14.createElement("div", {
1992
+ className: subGridClassNames
1993
+ }, /* @__PURE__ */ React14.createElement("div", {
1994
+ className: "truncate text-primary-500"
1995
+ }, name), /* @__PURE__ */ React14.createElement("div", {
1996
+ className: "line-clamp-2"
1997
+ }, description)), subitems?.map(({ name: name2, description: description2 }, i2) => /* @__PURE__ */ React14.createElement("div", {
1998
+ key: i2,
1999
+ className: mx10(subGridClassNames, striped && stripeClassNames)
2000
+ }, /* @__PURE__ */ React14.createElement("div", {
2001
+ className: "truncate"
2002
+ }, name2), /* @__PURE__ */ React14.createElement("div", {
2003
+ className: "line-clamp-3 text-subdued"
2004
+ }, description2)))))));
2005
+ };
2006
+ var ToolboxPanel = ({ classNames, db, processor }) => {
2007
+ const services = useQuery3(db, Filter3.type(ServiceType2));
2008
+ const [serviceTools, setServiceTools] = useState6([]);
2009
+ useEffect5(() => {
2010
+ log3("creating service tools...", {
2011
+ services: services.length
2012
+ }, {
2013
+ F: __dxlog_file3,
2014
+ L: 122,
2015
+ S: void 0,
2016
+ C: (f, a) => f(...a)
2017
+ });
2018
+ queueMicrotask(async () => {
2019
+ });
2020
+ }, [
2021
+ services
2022
+ ]);
2023
+ const functions = useQuery3(db, Filter3.type(Operation.PersistentOperation));
2024
+ return /* @__PURE__ */ React14.createElement(Toolbox, {
2025
+ classNames,
2026
+ blueprints: processor?.context.getBlueprints(),
2027
+ services: serviceTools,
2028
+ functions
2029
+ });
2030
+ };
2031
+ var safeToolId = (name) => {
2032
+ return name.split("_").pop();
2033
+ };
2034
+
2035
+ // src/components/index.ts
2036
+ var AssistantSettings = lazy(() => import("./AssistantSettings-7QMO3LGF.mjs"));
2037
+
2038
+ // src/hooks/useBlueprintRegistry.ts
2039
+ import { useCallback as useCallback4, useEffect as useEffect6, useMemo as useMemo5, useState as useState7 } from "react";
2040
+ import { useCapabilities } from "@dxos/app-framework/ui";
2041
+ import { AppCapabilities } from "@dxos/app-toolkit";
2042
+ import { Blueprint } from "@dxos/blueprints";
2043
+ import { Filter as Filter4, Obj as Obj4, Ref } from "@dxos/echo";
2044
+ import { useQuery as useQuery4 } from "@dxos/react-client/echo";
2045
+ import { distinctBy } from "@dxos/util";
2046
+ var useBlueprintRegistry = () => {
2047
+ const blueprintDefinitions = useCapabilities(AppCapabilities.BlueprintDefinition);
2048
+ return useMemo5(() => new Blueprint.Registry(blueprintDefinitions.map((blueprint) => blueprint.make())), [
2049
+ blueprintDefinitions
2050
+ ]);
2051
+ };
2052
+ var useBlueprints2 = ({ blueprintRegistry, db }) => {
2053
+ const staticBlueprints = useMemo5(() => blueprintRegistry?.query() ?? [], [
2054
+ blueprintRegistry
2055
+ ]);
2056
+ const spaceBlueprints = useQuery4(db, Filter4.type(Blueprint.Blueprint));
2057
+ return useMemo5(() => {
2058
+ const blueprints = distinctBy([
2059
+ ...staticBlueprints,
2060
+ ...spaceBlueprints
2061
+ ], (b) => b.key);
2062
+ blueprints.sort(({ name: a }, { name: b }) => a.localeCompare(b));
2063
+ return blueprints;
2064
+ }, [
2065
+ staticBlueprints,
2066
+ spaceBlueprints
2067
+ ]);
2068
+ };
2069
+ var useActiveBlueprints2 = ({ context }) => {
2070
+ const [active, setActive] = useState7(/* @__PURE__ */ new Map());
2071
+ useEffect6(() => {
2072
+ if (!context) {
2073
+ setActive(/* @__PURE__ */ new Map());
2074
+ return;
2075
+ }
2076
+ const updateActive = () => {
2077
+ const blueprints = context.getBlueprints();
2078
+ setActive(new Map(blueprints.map((blueprint) => [
2079
+ blueprint.key,
2080
+ blueprint
2081
+ ])));
2082
+ };
2083
+ updateActive();
2084
+ return context.subscribeBlueprints(updateActive);
2085
+ }, [
2086
+ context
2087
+ ]);
2088
+ return active;
2089
+ };
2090
+ var useBlueprintHandlers2 = ({ db, context, blueprintRegistry }) => {
2091
+ const onUpdateBlueprint = useCallback4(async (key, checked) => {
2092
+ if (!context || !blueprintRegistry) {
2093
+ return;
2094
+ }
2095
+ const objects = await db.query(Filter4.type(Blueprint.Blueprint)).run();
2096
+ let storedBlueprint = objects.find((blueprint) => blueprint.key === key);
2097
+ if (checked) {
2098
+ if (!storedBlueprint) {
2099
+ const blueprint = blueprintRegistry.getByKey(key);
2100
+ if (!blueprint) {
2101
+ return;
2102
+ }
2103
+ storedBlueprint = db.add(Obj4.clone(blueprint));
2104
+ }
2105
+ await context.bind({
2106
+ blueprints: [
2107
+ Ref.make(storedBlueprint)
2108
+ ]
2109
+ });
2110
+ } else if (storedBlueprint) {
2111
+ await context.unbind({
2112
+ blueprints: [
2113
+ Ref.make(storedBlueprint)
2114
+ ]
2115
+ });
2116
+ }
2117
+ }, [
2118
+ db,
2119
+ context,
2120
+ blueprintRegistry
2121
+ ]);
2122
+ return {
2123
+ onUpdateBlueprint
2124
+ };
2125
+ };
2126
+
2127
+ // src/hooks/useChatProcessor.ts
2128
+ import { RegistryContext } from "@effect-atom/atom-react";
2129
+ import * as Effect2 from "effect/Effect";
2130
+ import { useContext, useMemo as useMemo6, useState as useState8 } from "react";
2131
+ import { AiConversation } from "@dxos/assistant";
2132
+ import { Ref as Ref2 } from "@dxos/echo";
2133
+ import { createFeedServiceLayer } from "@dxos/echo-db";
2134
+ import { runAndForwardErrors as runAndForwardErrors2 } from "@dxos/effect";
2135
+ import { log as log5 } from "@dxos/log";
2136
+ import { useAsyncEffect } from "@dxos/react-ui";
2137
+
2138
+ // src/processor/presets.ts
2139
+ import * as Schema from "effect/Schema";
2140
+ var ModelProviders = [
2141
+ "dxos-local",
2142
+ "dxos-remote",
2143
+ "lm-studio"
2144
+ ];
2145
+ var ModelProvider = Schema.Literal(...ModelProviders);
2146
+ var createModelLabel = (model) => {
2147
+ const parts = model.split("/");
2148
+ return parts[parts.length - 1];
2149
+ };
2150
+ var AiServicePresets = [
2151
+ {
2152
+ provider: "dxos-remote",
2153
+ model: "@anthropic/claude-opus-4-6"
2154
+ },
2155
+ {
2156
+ provider: "dxos-remote",
2157
+ model: "@anthropic/claude-sonnet-4-5"
2158
+ },
2159
+ {
2160
+ provider: "dxos-remote",
2161
+ model: "@anthropic/claude-3-5-haiku-20241022"
2162
+ },
2163
+ {
2164
+ provider: "lm-studio",
2165
+ model: "@google/gemma-3-27b"
2166
+ },
2167
+ {
2168
+ provider: "lm-studio",
2169
+ model: "@meta/llama-3.2-3b-instruct"
2170
+ },
2171
+ {
2172
+ model: "deepseek-r1:latest",
2173
+ provider: "dxos-local"
2174
+ }
2175
+ ].map(({ model, provider }, i) => ({
2176
+ id: `preset-${i}`,
2177
+ provider,
2178
+ model,
2179
+ label: createModelLabel(model)
2180
+ }));
2181
+
2182
+ // src/processor/processor.ts
2183
+ import { Atom, Registry } from "@effect-atom/atom-react";
2184
+ import * as Effect from "effect/Effect";
2185
+ import * as Fiber from "effect/Fiber";
2186
+ import * as Option4 from "effect/Option";
2187
+ import * as Stream from "effect/Stream";
2188
+ import { DEFAULT_EDGE_MODEL } from "@dxos/ai";
2189
+ import { AiContextService, createSystemPrompt, formatSystemPrompt, AgentService, PartialBlock } from "@dxos/assistant";
2190
+ import { Obj as Obj5 } from "@dxos/echo";
2191
+ import { runAndForwardErrors, unwrapExit } from "@dxos/effect";
2192
+ import { Trace } from "@dxos/functions";
2193
+ import { log as log4 } from "@dxos/log";
2194
+ import { Operation as Operation2 } from "@dxos/operation";
2195
+ import { Message as Message2 } from "@dxos/types";
2196
+ var __dxlog_file4 = "/__w/dxos/dxos/packages/plugins/plugin-assistant/src/processor/processor.ts";
2197
+ var defaultOptions2 = {
2198
+ model: DEFAULT_EDGE_MODEL,
2199
+ autoUpdateNameChance: 0.1
2200
+ };
2201
+ var AiChatProcessor = class {
2202
+ _conversation;
2203
+ _runtime;
2204
+ _feed;
2205
+ _options;
2206
+ #registry;
2207
+ /** Pending messages (finalized, non-streaming). */
2208
+ #pending = Atom.make([]);
2209
+ /** Currently streaming messages (from ephemeral trace events). */
2210
+ #streaming = Atom.make([]);
2211
+ /** Set of message IDs that have been finalized (non-pending delivered via ephemeral). */
2212
+ #finalizedIds = /* @__PURE__ */ new Set();
2213
+ /** Currently active request fiber. */
2214
+ #requestFiber;
2215
+ /** Last request (for retries). */
2216
+ #lastRequest;
2217
+ /** Streaming state. */
2218
+ streaming = Atom.make((get) => get(this.#streaming).length > 0);
2219
+ /** Active state. */
2220
+ active = Atom.make(false);
2221
+ /** Array of Messages (incl. the current message being streamed). */
2222
+ messages = Atom.make((get) => [
2223
+ ...get(this.#pending),
2224
+ ...get(this.#streaming)
2225
+ ]);
2226
+ /** Last error. */
2227
+ error = Atom.make(Option4.none());
2228
+ constructor(_conversation, _runtime, _feed, _options = defaultOptions2) {
2229
+ this._conversation = _conversation;
2230
+ this._runtime = _runtime;
2231
+ this._feed = _feed;
2232
+ this._options = _options;
2233
+ this.#registry = this._options.observableRegistry ?? Registry.make();
2234
+ if (this._options.model && !this._options.system) {
2235
+ const capabilities = this._options.modelRegistry?.getCapabilities(this._options.model) ?? {};
2236
+ this._options.system = createSystemPrompt(capabilities);
2237
+ }
2238
+ }
2239
+ get context() {
2240
+ return this._conversation.context;
2241
+ }
2242
+ get conversation() {
2243
+ return this._conversation;
2244
+ }
2245
+ get blueprintRegistry() {
2246
+ return this._options.blueprintRegistry;
2247
+ }
2248
+ get system() {
2249
+ return this._options.system ?? "";
2250
+ }
2251
+ async getTools() {
2252
+ return this._runtime.runPromise(this._conversation.getTools());
2253
+ }
2254
+ async getSystemPrompt() {
2255
+ return this._runtime.runPromise(Effect.gen(this, function* () {
2256
+ const blueprints = this.context.getBlueprints();
2257
+ const objects = this.context.getObjects();
2258
+ return yield* formatSystemPrompt({
2259
+ system: this._options.system,
2260
+ blueprints,
2261
+ objects
2262
+ });
2263
+ }).pipe(Effect.provideService(AiContextService, {
2264
+ binder: this.context
2265
+ }), Effect.orDie));
2266
+ }
2267
+ /**
2268
+ * Initiates a new request via AgentService.
2269
+ */
2270
+ async request(requestProp) {
2271
+ if (this.#requestFiber) {
2272
+ await this.cancel();
2273
+ }
2274
+ try {
2275
+ this.#lastRequest = requestProp;
2276
+ this.#registry.set(this.error, Option4.none());
2277
+ this.#registry.set(this.active, true);
2278
+ const effect = Effect.gen(this, function* () {
2279
+ const session = yield* AgentService.getSession(this._feed);
2280
+ const ephemeralStream = session.subscribeEphemeral();
2281
+ yield* ephemeralStream.pipe(Stream.runForEach((message) => Effect.sync(() => {
2282
+ for (const event of message.events) {
2283
+ if (Trace.isOfType(PartialBlock, event)) {
2284
+ this.#handleEphemeralMessage(event.data);
2285
+ }
2286
+ }
2287
+ })), Effect.fork);
2288
+ log4("chat processor submitting prompt", {
2289
+ length: requestProp.message.length
2290
+ }, {
2291
+ F: __dxlog_file4,
2292
+ L: 197,
2293
+ S: this,
2294
+ C: (f, a) => f(...a)
2295
+ });
2296
+ yield* session.submitPrompt(requestProp.message);
2297
+ log4("chat processor submitPrompt returned, waiting for agent", {}, {
2298
+ F: __dxlog_file4,
2299
+ L: 199,
2300
+ S: this,
2301
+ C: (f, a) => f(...a)
2302
+ });
2303
+ yield* session.waitForCompletion();
2304
+ log4.info("session complete", void 0, {
2305
+ F: __dxlog_file4,
2306
+ L: 201,
2307
+ S: this,
2308
+ C: (f, a) => f(...a)
2309
+ });
2310
+ this.#flushStreaming();
2311
+ yield* this.#maybeUpdateChatName();
2312
+ });
2313
+ this.#requestFiber = this._runtime.runFork(effect);
2314
+ try {
2315
+ await this._runtime.runPromise(Fiber.join(this.#requestFiber));
2316
+ } catch (err) {
2317
+ if (err._tag === "InterruptedException" || err.message?.includes("interrupted")) {
2318
+ return;
2319
+ }
2320
+ throw err;
2321
+ }
2322
+ this.#registry.set(this.error, Option4.none());
2323
+ this.#lastRequest = void 0;
2324
+ this.#requestFiber = void 0;
2325
+ } catch (err) {
2326
+ log4.error("request failed", {
2327
+ error: err
2328
+ }, {
2329
+ F: __dxlog_file4,
2330
+ L: 223,
2331
+ S: this,
2332
+ C: (f, a) => f(...a)
2333
+ });
2334
+ this.#registry.set(this.error, Option4.some(new Error("AI service error", {
2335
+ cause: err
2336
+ })));
2337
+ } finally {
2338
+ log4.info("setting active to false", void 0, {
2339
+ F: __dxlog_file4,
2340
+ L: 226,
2341
+ S: this,
2342
+ C: (f, a) => f(...a)
2343
+ });
2344
+ this.#registry.set(this.active, false);
2345
+ this.#requestFiber = void 0;
2346
+ }
2347
+ }
2348
+ /**
2349
+ * Cancels the current request.
2350
+ */
2351
+ async cancel() {
2352
+ await runAndForwardErrors(Effect.gen(this, function* () {
2353
+ if (this.#requestFiber) {
2354
+ yield* Fiber.interrupt(this.#requestFiber);
2355
+ }
2356
+ }));
2357
+ this.#requestFiber = void 0;
2358
+ this.#registry.set(this.active, false);
2359
+ }
2360
+ /**
2361
+ * Retry last failed request.
2362
+ */
2363
+ async retry() {
2364
+ if (this.#lastRequest) {
2365
+ return this.request(this.#lastRequest);
2366
+ }
2367
+ }
2368
+ /**
2369
+ * Update the current chat's name.
2370
+ */
2371
+ async updateName(chat) {
2372
+ unwrapExit(await this._runtime.runPromiseExit(Operation2.invoke(UpdateChatName, {
2373
+ chat
2374
+ })));
2375
+ }
2376
+ /**
2377
+ * Handles an ephemeral message from the agent process.
2378
+ * Both pending and completed blocks arrive here. Completed blocks are deduped
2379
+ * against messages already written to the feed queue to handle the race between
2380
+ * ephemeral delivery and feed replication.
2381
+ */
2382
+ #handleEphemeralMessage(event) {
2383
+ const isPending = event.block.pending;
2384
+ const message = Obj5.make(Message2.Message, {
2385
+ id: event.messageId,
2386
+ created: (/* @__PURE__ */ new Date()).toISOString(),
2387
+ sender: {
2388
+ role: event.role
2389
+ },
2390
+ blocks: [
2391
+ event.block
2392
+ ]
2393
+ });
2394
+ if (isPending) {
2395
+ if (this.#finalizedIds.has(event.messageId)) {
2396
+ return;
2397
+ }
2398
+ this.#registry.update(this.#streaming, (streaming) => {
2399
+ const idx = streaming.findIndex((existing) => existing.id === event.messageId);
2400
+ if (idx >= 0) {
2401
+ const updated = [
2402
+ ...streaming
2403
+ ];
2404
+ updated[idx] = message;
2405
+ return updated;
2406
+ }
2407
+ return [
2408
+ ...streaming,
2409
+ message
2410
+ ];
2411
+ });
2412
+ } else {
2413
+ this.#finalizedIds.add(event.messageId);
2414
+ this.#registry.update(this.#streaming, (streaming) => streaming.filter((existing) => existing.id !== message.id));
2415
+ this.#registry.update(this.#pending, (pending) => {
2416
+ if (pending.some((existing) => existing.id === message.id)) {
2417
+ return pending;
2418
+ }
2419
+ return [
2420
+ ...pending,
2421
+ message
2422
+ ];
2423
+ });
2424
+ }
2425
+ }
2426
+ /**
2427
+ * Move remaining streaming messages to pending (called when agent completes).
2428
+ */
2429
+ #flushStreaming() {
2430
+ const remaining = this.#registry.get(this.#streaming);
2431
+ if (remaining.length > 0) {
2432
+ this.#registry.update(this.#pending, (pending) => [
2433
+ ...pending,
2434
+ ...remaining
2435
+ ]);
2436
+ this.#registry.set(this.#streaming, []);
2437
+ }
2438
+ this.#finalizedIds.clear();
2439
+ }
2440
+ /**
2441
+ * Conditionally schedule chat name update in detached fork mode.
2442
+ * Updates if chat has no name OR based on random chance (default 10%).
2443
+ */
2444
+ #maybeUpdateChatName() {
2445
+ const chat = this._options.chat?.target;
2446
+ if (!chat) {
2447
+ return Effect.void;
2448
+ }
2449
+ const chance = this._options.autoUpdateNameChance ?? defaultOptions2.autoUpdateNameChance ?? 0.1;
2450
+ const shouldUpdate = !chat.name || Math.random() < chance;
2451
+ if (!shouldUpdate) {
2452
+ return Effect.void;
2453
+ }
2454
+ log4.info("scheduling chat name update", {
2455
+ hasName: !!chat.name,
2456
+ chance
2457
+ }, {
2458
+ F: __dxlog_file4,
2459
+ L: 333,
2460
+ S: this,
2461
+ C: (f, a) => f(...a)
2462
+ });
2463
+ return Operation2.schedule(UpdateChatName, {
2464
+ chat
2465
+ });
2466
+ }
2467
+ };
55
2468
 
56
- // src/capabilities/app-graph-builder/index.ts
57
- import { Capability as Capability2 } from "@dxos/app-framework";
58
- var AppGraphBuilder = Capability2.lazy("AppGraphBuilder", () => import("./app-graph-builder-DSNH2OMY.mjs"));
2469
+ // src/hooks/useChatProcessor.ts
2470
+ var __dxlog_file5 = "/__w/dxos/dxos/packages/plugins/plugin-assistant/src/hooks/useChatProcessor.ts";
2471
+ var useChatProcessor = ({ space, chat, preset, runtime: runtime3, blueprintRegistry, settings }) => {
2472
+ const observableRegistry = useContext(RegistryContext);
2473
+ const [conversation, setConversation] = useState8();
2474
+ useAsyncEffect(async () => {
2475
+ if (!space || !chat) {
2476
+ return;
2477
+ }
2478
+ const feedTarget = chat.feed.target;
2479
+ if (!feedTarget) {
2480
+ return;
2481
+ }
2482
+ const feedServiceLayer = createFeedServiceLayer(space.queues);
2483
+ const runtime4 = await runAndForwardErrors2(Effect2.runtime().pipe(Effect2.provide(feedServiceLayer)));
2484
+ const conversation2 = new AiConversation({
2485
+ feed: feedTarget,
2486
+ runtime: runtime4,
2487
+ registry: observableRegistry
2488
+ });
2489
+ await conversation2.open();
2490
+ setConversation(conversation2);
2491
+ return () => {
2492
+ void conversation2.close();
2493
+ setConversation(void 0);
2494
+ };
2495
+ }, [
2496
+ space,
2497
+ chat?.feed.target
2498
+ ]);
2499
+ const feed = chat?.feed.target;
2500
+ const processor = useMemo6(() => {
2501
+ if (!runtime3 || !conversation || !chat || !feed) {
2502
+ return void 0;
2503
+ }
2504
+ log5("creating processor", {
2505
+ preset,
2506
+ model: preset?.model,
2507
+ settings
2508
+ }, {
2509
+ F: __dxlog_file5,
2510
+ L: 80,
2511
+ S: void 0,
2512
+ C: (f, a) => f(...a)
2513
+ });
2514
+ return new AiChatProcessor(conversation, runtime3, feed, {
2515
+ chat: chat ? Ref2.make(chat) : void 0,
2516
+ observableRegistry,
2517
+ blueprintRegistry,
2518
+ model: preset?.model
2519
+ });
2520
+ }, [
2521
+ runtime3,
2522
+ conversation,
2523
+ blueprintRegistry,
2524
+ preset,
2525
+ feed
2526
+ ]);
2527
+ return processor;
2528
+ };
2529
+
2530
+ // src/hooks/useChatServices.ts
2531
+ import { useMemo as useMemo7 } from "react";
2532
+ import { useCapability } from "@dxos/app-framework/ui";
2533
+ import { getPersonalSpace } from "@dxos/app-toolkit";
2534
+ import { AutomationCapabilities } from "@dxos/plugin-automation/types";
2535
+ import { useClient } from "@dxos/react-client";
2536
+ var useChatServices = ({ id }) => {
2537
+ const client = useClient();
2538
+ id ??= getPersonalSpace(client)?.id;
2539
+ const runtimeResolver = useCapability(AutomationCapabilities.ComputeRuntime);
2540
+ return useMemo7(() => !id ? void 0 : runtimeResolver.getRuntime(id), [
2541
+ id
2542
+ ]);
2543
+ };
59
2544
 
60
- // src/capabilities/blueprint-definition/index.ts
61
- import { Capability as Capability3 } from "@dxos/app-framework";
62
- var BlueprintDefinition = Capability3.lazy("BlueprintDefinition", () => import("./blueprint-definition-DGHH7MUU.mjs"));
2545
+ // src/hooks/useChatToolbarActions.ts
2546
+ import { Atom as Atom2 } from "@effect-atom/atom-react";
2547
+ import * as Effect3 from "effect/Effect";
2548
+ import { useMemo as useMemo8 } from "react";
2549
+ import { useOperationInvoker } from "@dxos/app-framework/ui";
2550
+ import { Chat as Chat2 } from "@dxos/assistant-toolkit";
2551
+ import { Filter as Filter5, Obj as Obj6, Query } from "@dxos/echo";
2552
+ import { runAndForwardErrors as runAndForwardErrors3 } from "@dxos/effect";
2553
+ import { invariant } from "@dxos/invariant";
2554
+ import { useQuery as useQuery5 } from "@dxos/react-client/echo";
2555
+ import { MenuBuilder, useMenuActions } from "@dxos/react-ui-menu";
2556
+ import { useChatContext as useChatContext2 } from "#components";
2557
+ import { meta as meta8 } from "#meta";
2558
+ import { AssistantOperation } from "#operations";
2559
+ var __dxlog_file6 = "/__w/dxos/dxos/packages/plugins/plugin-assistant/src/hooks/useChatToolbarActions.ts";
2560
+ var useChatToolbarActions2 = ({ chat, companionTo }) => {
2561
+ const { invoke } = useOperationInvoker();
2562
+ const { db } = useChatContext2("useChatToolbarActions");
2563
+ const query = companionTo ? Query.select(Filter5.id(companionTo.id)).targetOf(Chat2.CompanionTo).source() : Query.select(Filter5.nothing());
2564
+ const chats = useQuery5(db, query);
2565
+ return useMenuActions(useMemo8(() => {
2566
+ return Atom2.make(() => {
2567
+ const builder = MenuBuilder.make().root({
2568
+ label: [
2569
+ "chat-toolbar.title",
2570
+ {
2571
+ ns: meta8.id
2572
+ }
2573
+ ]
2574
+ }).action("new", {
2575
+ label: [
2576
+ "new-thread.button",
2577
+ {
2578
+ ns: meta8.id
2579
+ }
2580
+ ],
2581
+ icon: "ph--plus--regular",
2582
+ type: "new",
2583
+ disabled: !companionTo
2584
+ }, () => {
2585
+ invariant(companionTo, void 0, {
2586
+ F: __dxlog_file6,
2587
+ L: 53,
2588
+ S: void 0,
2589
+ A: [
2590
+ "companionTo",
2591
+ ""
2592
+ ]
2593
+ });
2594
+ return invoke(AssistantOperation.SetCurrentChat, {
2595
+ companionTo,
2596
+ chat: void 0
2597
+ }).pipe(runAndForwardErrors3);
2598
+ }).action("rename", {
2599
+ label: [
2600
+ "rename-thread.button",
2601
+ {
2602
+ ns: meta8.id
2603
+ }
2604
+ ],
2605
+ icon: "ph--magic-wand--regular",
2606
+ type: "rename",
2607
+ disabled: !chat
2608
+ }, () => Effect3.gen(function* () {
2609
+ invariant(chat, void 0, {
2610
+ F: __dxlog_file6,
2611
+ L: 70,
2612
+ S: this,
2613
+ A: [
2614
+ "chat",
2615
+ ""
2616
+ ]
2617
+ });
2618
+ yield* invoke(AssistantOperation.UpdateChatName, {
2619
+ chat
2620
+ });
2621
+ }).pipe(runAndForwardErrors3)).action("branch", {
2622
+ label: [
2623
+ "branch-thread.menu",
2624
+ {
2625
+ ns: meta8.id
2626
+ }
2627
+ ],
2628
+ icon: "ph--git-branch--regular",
2629
+ type: "branch",
2630
+ disabled: true
2631
+ }, () => {
2632
+ });
2633
+ if (chats.length > 0) {
2634
+ builder.group("chats", {
2635
+ label: [
2636
+ "chat-history.label",
2637
+ {
2638
+ ns: meta8.id
2639
+ }
2640
+ ],
2641
+ icon: "ph--clock-counter-clockwise--regular",
2642
+ selectCardinality: "single",
2643
+ variant: "dropdownMenu"
2644
+ }, (builder2) => {
2645
+ chats.toSorted((a, b) => a.id.localeCompare(b.id)).forEach((chat2) => {
2646
+ builder2.action(chat2.id, {
2647
+ label: Obj6.getLabel(chat2) ?? [
2648
+ "object-name.placeholder",
2649
+ {
2650
+ ns: Chat2.Chat.typename
2651
+ }
2652
+ ]
2653
+ }, () => Effect3.gen(function* () {
2654
+ invariant(companionTo, void 0, {
2655
+ F: __dxlog_file6,
2656
+ L: 106,
2657
+ S: this,
2658
+ A: [
2659
+ "companionTo",
2660
+ ""
2661
+ ]
2662
+ });
2663
+ yield* invoke(AssistantOperation.SetCurrentChat, {
2664
+ companionTo,
2665
+ chat: chat2
2666
+ });
2667
+ }).pipe(runAndForwardErrors3));
2668
+ });
2669
+ });
2670
+ }
2671
+ return builder.build();
2672
+ });
2673
+ }, [
2674
+ chats.length,
2675
+ db?.spaceId,
2676
+ companionTo?.id,
2677
+ chat?.id,
2678
+ invoke
2679
+ ]));
2680
+ };
63
2681
 
64
- // src/capabilities/edge-model-resolver/index.ts
65
- import { Capability as Capability4 } from "@dxos/app-framework";
66
- var EdgeModelResolver = Capability4.lazy("EdgeModelResolver", () => import("./edge-model-resolver-26BOY6HY.mjs"));
2682
+ // src/hooks/useContextBinder.ts
2683
+ import { RegistryContext as RegistryContext2 } from "@effect-atom/atom-react";
2684
+ import * as Effect4 from "effect/Effect";
2685
+ import { useContext as useContext2, useState as useState9 } from "react";
2686
+ import { AiContextBinder } from "@dxos/assistant";
2687
+ import { createFeedServiceLayer as createFeedServiceLayer2 } from "@dxos/echo-db";
2688
+ import { runAndForwardErrors as runAndForwardErrors4 } from "@dxos/effect";
2689
+ import { useAsyncEffect as useAsyncEffect2 } from "@dxos/react-ui";
2690
+ var useContextBinder = (space, feed) => {
2691
+ const registry = useContext2(RegistryContext2);
2692
+ const [binder, setBinder] = useState9();
2693
+ useAsyncEffect2(async () => {
2694
+ setBinder(void 0);
2695
+ if (!space || !feed) {
2696
+ return;
2697
+ }
2698
+ const feedServiceLayer = createFeedServiceLayer2(space.queues);
2699
+ const runtime3 = await runAndForwardErrors4(Effect4.runtime().pipe(Effect4.provide(feedServiceLayer)));
2700
+ const binder2 = new AiContextBinder({
2701
+ feed,
2702
+ runtime: runtime3,
2703
+ registry
2704
+ });
2705
+ await binder2.open();
2706
+ setBinder(binder2);
2707
+ return () => {
2708
+ void binder2.close();
2709
+ };
2710
+ }, [
2711
+ space,
2712
+ feed
2713
+ ]);
2714
+ return binder;
2715
+ };
67
2716
 
68
- // src/capabilities/local-model-resolver/index.ts
69
- import { Capability as Capability5 } from "@dxos/app-framework";
70
- var LocalModelResolver = Capability5.lazy("LocalModelResolver", () => import("./local-model-resolver-ZFIM6GGV.mjs"));
2717
+ // src/hooks/useContextObjects.ts
2718
+ import { Atom as Atom3, useAtomValue as useAtomValue2 } from "@effect-atom/atom-react";
2719
+ import { useCallback as useCallback5 } from "react";
2720
+ var emptyObjectsAtom = Atom3.make([]);
2721
+ var useContextObjects3 = ({ db, context }) => {
2722
+ const objects = useAtomValue2(context?.objects ?? emptyObjectsAtom);
2723
+ const handleUpdateObject = useCallback5(async (dxn, checked) => {
2724
+ if (!db || !context) {
2725
+ return;
2726
+ }
2727
+ const ref = db.makeRef(dxn);
2728
+ await ref.load();
2729
+ if (checked) {
2730
+ await context.bind({
2731
+ objects: [
2732
+ ref
2733
+ ]
2734
+ });
2735
+ } else {
2736
+ await context.unbind({
2737
+ objects: [
2738
+ ref
2739
+ ]
2740
+ });
2741
+ }
2742
+ }, [
2743
+ db,
2744
+ context
2745
+ ]);
2746
+ return {
2747
+ objects,
2748
+ onUpdateObject: handleUpdateObject
2749
+ };
2750
+ };
71
2751
 
72
- // src/capabilities/operation-resolver/index.ts
73
- import { Capability as Capability6 } from "@dxos/app-framework";
74
- var OperationResolver = Capability6.lazy("OperationResolver", () => import("./operation-resolver-7XJLBRQY.mjs"));
2752
+ // src/hooks/useFilteredTypes.ts
2753
+ import * as Option5 from "effect/Option";
2754
+ import { useEffect as useEffect7, useState as useState10 } from "react";
2755
+ import { EntityKind, SystemTypeAnnotation, getTypeAnnotation } from "@dxos/echo/internal";
2756
+ var useFilteredTypes2 = (db) => {
2757
+ const [types, setTypes] = useState10([]);
2758
+ useEffect7(() => {
2759
+ if (!db) {
2760
+ return;
2761
+ }
2762
+ return db.schemaRegistry.query({
2763
+ location: [
2764
+ "database",
2765
+ "runtime"
2766
+ ]
2767
+ }).subscribe((query) => {
2768
+ const types2 = Array.from(new Set(query.results.filter((schema) => getTypeAnnotation(schema)?.kind !== EntityKind.Relation).filter((schema) => !SystemTypeAnnotation.get(schema).pipe(Option5.getOrElse(() => false)))));
2769
+ setTypes(types2);
2770
+ }, {
2771
+ fire: true
2772
+ });
2773
+ }, [
2774
+ db
2775
+ ]);
2776
+ return types;
2777
+ };
75
2778
 
76
- // src/capabilities/react-surface/index.ts
77
- import { Capability as Capability7 } from "@dxos/app-framework";
78
- var ReactSurface = Capability7.lazy("ReactSurface", () => import("./react-surface-S7SBFOSW.mjs"));
2779
+ // src/hooks/useFlush.ts
2780
+ import { useCallback as useCallback6, useRef as useRef3, useState as useState11 } from "react";
2781
+ var useFlush = (space) => {
2782
+ const [state, setState] = useState11("idle");
2783
+ const resetTimer = useRef3(null);
2784
+ const handleFlush = useCallback6(() => {
2785
+ if (!space) {
2786
+ return;
2787
+ }
2788
+ queueMicrotask(async () => {
2789
+ if (resetTimer.current) {
2790
+ clearTimeout(resetTimer.current);
2791
+ }
2792
+ setState("flushing");
2793
+ await space.db.flush();
2794
+ setState("flushed");
2795
+ resetTimer.current = setTimeout(() => {
2796
+ setState("idle");
2797
+ resetTimer.current = null;
2798
+ }, 1e3);
2799
+ });
2800
+ }, [
2801
+ space
2802
+ ]);
2803
+ return {
2804
+ state,
2805
+ handleFlush
2806
+ };
2807
+ };
79
2808
 
80
- // src/capabilities/repair/index.ts
81
- import { Capability as Capability8 } from "@dxos/app-framework";
82
- var Repair = Capability8.lazy("Repair", () => import("./repair-6QGAKOVM.mjs"));
2809
+ // src/hooks/useOnline.ts
2810
+ import { useState as useState12 } from "react";
2811
+ var useOnline = () => {
2812
+ const [online, setOnline] = useState12(true);
2813
+ return [
2814
+ online,
2815
+ setOnline
2816
+ ];
2817
+ };
83
2818
 
84
- // src/capabilities/settings/index.ts
85
- import { Capability as Capability9 } from "@dxos/app-framework";
86
- var Settings = Capability9.lazy("Settings", () => import("./settings-4ZDLUMYE.mjs"));
2819
+ // src/hooks/usePresets.ts
2820
+ import { useCallback as useCallback7, useEffect as useEffect8, useMemo as useMemo9, useState as useState13 } from "react";
2821
+ var usePresets = (online) => {
2822
+ const [preset, setPreset] = useState13();
2823
+ const presets = useMemo9(() => AiServicePresets.filter((preset2) => online === (preset2.provider === "dxos-remote")), [
2824
+ online
2825
+ ]);
2826
+ const presetOptions = useMemo9(() => presets.map(({ id, model, label }) => ({
2827
+ id,
2828
+ label: label ?? model
2829
+ })), [
2830
+ presets
2831
+ ]);
2832
+ useEffect8(() => {
2833
+ setPreset(presets[0]);
2834
+ }, [
2835
+ presets
2836
+ ]);
2837
+ const handlePresetChange = useCallback7((id) => {
2838
+ const preset2 = presets.find((preset3) => preset3.id === id);
2839
+ if (preset2) {
2840
+ setPreset(preset2);
2841
+ }
2842
+ }, [
2843
+ presets
2844
+ ]);
2845
+ return {
2846
+ preset,
2847
+ presets: presetOptions,
2848
+ onPresetChange: handlePresetChange
2849
+ };
2850
+ };
87
2851
 
88
- // src/capabilities/state/index.ts
89
- import { Capability as Capability10 } from "@dxos/app-framework";
90
- var AssistantState = Capability10.lazy("AssistantState", () => import("./state-AN6336ZX.mjs"));
2852
+ // src/hooks/useReferencesProvider.ts
2853
+ import { useMemo as useMemo10 } from "react";
2854
+ import { Filter as Filter6, Obj as Obj7 } from "@dxos/echo";
2855
+ var useReferencesProvider = (space) => {
2856
+ return useMemo10(() => {
2857
+ if (!space) {
2858
+ return void 0;
2859
+ }
2860
+ return {
2861
+ getReferences: async ({ query }) => {
2862
+ const objects = await space.db.query(Filter6.everything()).run();
2863
+ return objects.filter((object) => stringMatch(query, Obj7.getLabel(object) ?? "")).filter((object) => !!Obj7.getDXN(object)).map((object) => ({
2864
+ uri: Obj7.getDXN(object).toString(),
2865
+ label: Obj7.getLabel(object) ?? ""
2866
+ }));
2867
+ },
2868
+ resolveReference: async ({ uri }) => {
2869
+ const object = await space.db.query(Filter6.id(uri)).first();
2870
+ return {
2871
+ uri,
2872
+ label: Obj7.getLabel(object) ?? ""
2873
+ };
2874
+ }
2875
+ };
2876
+ }, [
2877
+ space
2878
+ ]);
2879
+ };
2880
+ var stringMatch = (query, label) => label.toLowerCase().startsWith(query.toLowerCase());
91
2881
 
92
- // src/capabilities/toolkit/index.ts
93
- import { Capability as Capability11 } from "@dxos/app-framework";
94
- var Toolkit = Capability11.lazy("Toolkit", () => import("./toolkit-7AVTEPMA.mjs"));
2882
+ // src/meta.ts
2883
+ import { trim as trim2 } from "@dxos/util";
2884
+ var meta9 = {
2885
+ id: "org.dxos.plugin.assistant",
2886
+ name: "Assistant",
2887
+ description: trim2`
2888
+ Intelligent AI assistant that can analyze and interact with objects across your spaces.
2889
+ Chat naturally to get insights, search content, and perform actions using AI-powered context awareness.
2890
+ `,
2891
+ icon: "ph--sparkle--regular",
2892
+ iconHue: "sky",
2893
+ source: "https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-assistant",
2894
+ tags: [
2895
+ "labs"
2896
+ ]
2897
+ };
2898
+ var ASSISTANT_DIALOG = `${meta9.id}.assistant.dialog`;
2899
+ var ASSISTANT_COMPANION_VARIANT = "assistant-chat";
95
2900
 
96
2901
  // src/translations.ts
97
- import { Blueprint, Prompt } from "@dxos/blueprints";
2902
+ import { Chat as Chat3, Agent } from "@dxos/assistant-toolkit";
2903
+ import { Blueprint as Blueprint2, Prompt } from "@dxos/blueprints";
98
2904
  import { Sequence } from "@dxos/conductor";
99
- import { Type } from "@dxos/echo";
2905
+ import { Type as Type2 } from "@dxos/echo";
2906
+ import { meta as meta10 } from "#meta";
100
2907
  var translations = [
101
2908
  {
102
2909
  "en-US": {
103
2910
  // TODO(burdon): From assistant.
104
- [Blueprint.Blueprint.typename]: {
105
- "typename label": "Blueprint",
106
- "typename label_zero": "Blueprints",
107
- "typename label_one": "Blueprint",
108
- "typename label_other": "Blueprints",
109
- "object name placeholder": "New blueprint",
110
- "rename object label": "Rename blueprint",
111
- "delete object label": "Delete blueprint",
112
- "object deleted label": "Blueprint deleted"
2911
+ [Blueprint2.Blueprint.typename]: {
2912
+ "typename.label": "Blueprint",
2913
+ "typename.label_zero": "Blueprints",
2914
+ "typename.label_one": "Blueprint",
2915
+ "typename.label_other": "Blueprints",
2916
+ "object-name.placeholder": "New blueprint",
2917
+ "add-object.label": "Add blueprint",
2918
+ "rename-object.label": "Rename blueprint",
2919
+ "delete-object.label": "Delete blueprint",
2920
+ "object-deleted.label": "Blueprint deleted"
113
2921
  },
114
- [Type.getTypename(Prompt.Prompt)]: {
115
- "typename label": "Prompt",
116
- "typename label_zero": "Prompts",
117
- "typename label_one": "Prompt",
118
- "typename label_other": "Prompts",
119
- "object name placeholder": "New prompt",
120
- "rename object label": "Rename prompt",
121
- "delete object label": "Delete prompt",
122
- "object deleted label": "Prompt deleted"
2922
+ [Type2.getTypename(Prompt.Prompt)]: {
2923
+ "typename.label": "Prompt",
2924
+ "typename.label_zero": "Prompts",
2925
+ "typename.label_one": "Prompt",
2926
+ "typename.label_other": "Prompts",
2927
+ "object-name.placeholder": "New prompt",
2928
+ "add-object.label": "Add prompt",
2929
+ "rename-object.label": "Rename prompt",
2930
+ "delete-object.label": "Delete prompt",
2931
+ "object-deleted.label": "Prompt deleted"
123
2932
  },
124
2933
  // TODO(burdon): From conductor.
125
2934
  [Sequence.typename]: {
126
- "typename label": "Sequence",
127
- "typename label_zero": "Sequences",
128
- "typename label_one": "Sequence",
129
- "typename label_other": "Sequences",
130
- "object name placeholder": "New sequence",
131
- "rename object label": "Rename sequence",
132
- "delete object label": "Delete sequence",
133
- "object deleted label": "Sequence deleted"
2935
+ "typename.label": "Sequence",
2936
+ "typename.label_zero": "Sequences",
2937
+ "typename.label_one": "Sequence",
2938
+ "typename.label_other": "Sequences",
2939
+ "object-name.placeholder": "New sequence",
2940
+ "add-object.label": "Add sequence",
2941
+ "rename-object.label": "Rename sequence",
2942
+ "delete-object.label": "Delete sequence",
2943
+ "object-deleted.label": "Sequence deleted"
134
2944
  },
135
- [Assistant_exports.Chat.typename]: {
136
- "typename label": "AI Chat",
137
- "object name placeholder": "New AI Chat",
138
- "rename object label": "Rename AI Chat",
139
- "delete object label": "Delete AI Chat",
140
- "object deleted label": "AI Chat deleted"
2945
+ [Chat3.Chat.typename]: {
2946
+ "typename.label": "AI Chat",
2947
+ "object-name.placeholder": "New AI Chat",
2948
+ "add-object.label": "Add AI chat",
2949
+ "rename-object.label": "Rename AI Chat",
2950
+ "delete-object.label": "Delete AI Chat",
2951
+ "object-deleted.label": "AI Chat deleted"
2952
+ },
2953
+ [Agent.Agent.typename]: {
2954
+ "typename.label": "Agent",
2955
+ "typename.label_zero": "Agents",
2956
+ "typename.label_one": "Agent",
2957
+ "typename.label_other": "Agents",
2958
+ "object-name.placeholder": "New agent",
2959
+ "add-object.label": "Add agent",
2960
+ "rename-object.label": "Rename agent",
2961
+ "delete-object.label": "Delete agent",
2962
+ "object-deleted.label": "Agent deleted"
141
2963
  },
142
2964
  // TODO(burdon): Reconcile with react-ui-chat.
143
- [meta.id]: {
144
- "templates label": "Templates",
145
- "open ambient chat label": "Open Assistant",
146
- "assistant chat label": "Assistant",
147
- "plugin name": "Assistant",
148
- "settings title": "Assistant settings",
149
- "object placeholder": "New prompt",
150
- "create object label": "Create prompt",
151
- "create trigger label": "Create trigger",
152
- "create stack section label": "Create prompt",
153
- "command placeholder": "Enter slash command...",
154
- "template placeholder": "Enter template...",
155
- "value placeholder": "Enter value...",
156
- "prompt rules label": "Prompt Rules",
157
- "typename placeholder": "Enter typename of objects which this template is for",
158
- "description placeholder": "Enter description of when this template should be used",
159
- "select preset template placeholder": "Select preset",
160
- "service registry label": "Service Registry",
161
- "type filter placeholder": "Type",
162
- "any type filter label": "Any",
163
- "no blueprint message": "No active blueprints",
164
- "tool call label": "Calling tool...",
165
- "tool result label": "Success",
166
- "tool error label": "Tool call failed",
167
- "invocations label": "Invocations",
168
- "assistant dialog title": "Assistant",
169
- "open assistant label": "Open assistant",
170
- "no tools": "No tools are configured",
171
- "no results": "No results",
172
- "cancel button": "Cancel",
173
- "save button": "Save",
174
- "new thread button": "New Chat",
175
- "rename thread button": "Rename Chat",
176
- "chat history label": "Chat History",
177
- "chat update name label": "Update AI Chat name",
178
- "toolkit label": "Toolkit",
179
- "summary label": "Summary",
180
- "search placeholder": "Search...",
181
- "prompt placeholder": "Enter question or command...",
182
- "context objects button": "Add to context",
183
- "context settings button": "Chat settings",
184
- "microphone button": "Click to speak",
185
- "cancel processing button": "Stop processing",
186
- "blueprints in context title": "Blueprints",
187
- "objects in context title": "Content",
188
- "remove object in context label": "Remove document",
189
- "chat model title": "Model",
190
- "settings default label": "Default",
191
- "settings custom prompts label": "Use custom prompts",
192
- "settings llm provider label": "LLM provider",
193
- "settings edge llm model label": "Remote language model",
194
- "settings ollama llm model label": "Ollama language model"
2965
+ [meta10.id]: {
2966
+ "templates.label": "Templates",
2967
+ "open-ambient-chat.label": "Open Assistant",
2968
+ "assistant-chat.label": "Assistant",
2969
+ "plugin.name": "Assistant",
2970
+ "settings.title": "Assistant settings",
2971
+ "object.placeholder": "New prompt",
2972
+ "create-object.label": "Create prompt",
2973
+ "create-trigger.label": "Create trigger",
2974
+ "create-stack-section.label": "Create prompt",
2975
+ "command.placeholder": "Enter slash command...",
2976
+ "template.placeholder": "Enter template...",
2977
+ "value.placeholder": "Enter value...",
2978
+ "prompt-rules.label": "Prompt Rules",
2979
+ "typename.placeholder": "Enter typename of objects which this template is for",
2980
+ "description.placeholder": "Enter description of when this template should be used",
2981
+ "select-preset-template.placeholder": "Select preset",
2982
+ "service-registry.label": "Service Registry",
2983
+ "type-filter.placeholder": "Type",
2984
+ "any-type-filter.label": "Any",
2985
+ "no-blueprint.message": "No active blueprints",
2986
+ "tool-call.label": "Calling",
2987
+ "tool-result.label": "Success",
2988
+ "tool-error.label": "Tool call failed",
2989
+ "invocations.label": "Invocations",
2990
+ "trace.label": "Trace",
2991
+ "assistant-dialog.title": "Assistant",
2992
+ "open-assistant.label": "Open assistant",
2993
+ "reset-blueprints.label": "Reset blueprints",
2994
+ "no-results.message": "No results",
2995
+ "cancel.button": "Cancel",
2996
+ "save.button": "Save",
2997
+ "new-thread.button": "New Chat",
2998
+ "rename-thread.button": "Rename Chat",
2999
+ "chat-history.label": "Chat History",
3000
+ "chat-update-name.label": "Update AI Chat name",
3001
+ "toolkit.label": "Toolkit",
3002
+ "stats.label": "Stats",
3003
+ "summary.label": "Summary",
3004
+ "thinking.label": "Thinking",
3005
+ "search.placeholder": "Search...",
3006
+ "prompt.placeholder": "Enter question or command...",
3007
+ "context-objects.button": "Add to context",
3008
+ "context-settings.button": "Chat settings",
3009
+ "microphone.button": "Click to speak",
3010
+ "cancel-processing.button": "Stop processing",
3011
+ "blueprints-in-context.title": "Blueprints",
3012
+ "objects-in-context.title": "Content",
3013
+ "remove-object-in-context.label": "Remove document",
3014
+ "chat-model.title": "Model",
3015
+ "debug.button": "Debug",
3016
+ "online-switch.label": "Online",
3017
+ "run-prompt.label": "Run prompt",
3018
+ "typename.label": "Typename",
3019
+ "branch-thread.menu": "Branch chat",
3020
+ "chat-toolbar.title": "Chat toolbar",
3021
+ "settings.default.label": "Default",
3022
+ "settings.custom-prompts.label": "Use custom prompts",
3023
+ "settings.custom-prompts.description": "Allow the assistant to use custom prompts defined in your spaces.",
3024
+ "settings.llm-provider.label": "LLM provider",
3025
+ "settings.llm-provider.description": "Select which language model service to use for AI responses.",
3026
+ "settings.edge-llm-model.label": "Remote language model",
3027
+ "settings.edge-llm-model.description": "Choose the remote language model used for AI requests.",
3028
+ "settings.ollama-llm-model.label": "Ollama language model",
3029
+ "settings.ollama-llm-model.description": "Choose the locally hosted Ollama model for AI requests.",
3030
+ "settings.default-llm-model.label": "Default language model",
3031
+ // Trigger status
3032
+ "trigger-status-disabled.label": "Triggers disabled",
3033
+ "trigger-status-idle.label": "Triggers idle",
3034
+ "trigger-status-running.label": "Trigger running",
3035
+ "trigger-status-error.label": "Trigger error",
3036
+ "trigger-runtime.label": "Auto trigger execution",
3037
+ "trigger-last-invocation.label": "Last run",
3038
+ "trigger-duration.label": "Duration",
3039
+ // AgentArticle.
3040
+ "project-empty-spec.message": "Open Properties to configure the agent.",
3041
+ "project-empty-spec.description": "Open Assistant to interact with the agent.",
3042
+ "artifacts.label": "Artifacts",
3043
+ "input-queue.label": "Inputs",
3044
+ // AgentProperties.
3045
+ "instructions.label": "Instructions",
3046
+ "agent.spec.placeholder": "Enter instructions, goals, and constraints for the assistant.",
3047
+ "reset-history.button": "Reset",
3048
+ "subscriptions.label": "Subscriptions"
195
3049
  }
196
3050
  }
197
3051
  }
198
3052
  ];
199
3053
 
200
3054
  // src/AssistantPlugin.tsx
201
- import * as Effect from "effect/Effect";
202
- import { Capability as Capability12, Common, Plugin } from "@dxos/app-framework";
203
- import { ResearchGraph } from "@dxos/assistant-toolkit";
204
- import { Blueprint as Blueprint2, Prompt as Prompt2 } from "@dxos/blueprints";
3055
+ import * as Effect5 from "effect/Effect";
3056
+ import * as Option6 from "effect/Option";
3057
+ import { ActivationEvent, ActivationEvents, Capability, Plugin } from "@dxos/app-framework";
3058
+ import { AppActivationEvents, AppPlugin } from "@dxos/app-toolkit";
3059
+ import { Agent as Agent2, AgentBlueprint, Chat as Chat4, Memory, Plan, ResearchGraph } from "@dxos/assistant-toolkit";
3060
+ import { Blueprint as Blueprint3, Prompt as Prompt2 } from "@dxos/blueprints";
205
3061
  import { Sequence as Sequence2 } from "@dxos/conductor";
206
- import { Obj, Type as Type2 } from "@dxos/echo";
207
- import { Operation } from "@dxos/operation";
3062
+ import { Annotation as Annotation3, Feed, Obj as Obj8, Type as Type3 } from "@dxos/echo";
3063
+ import { Operation as Operation3 } from "@dxos/operation";
3064
+ import { AutomationCapabilities as AutomationCapabilities2 } from "@dxos/plugin-automation/types";
208
3065
  import { ClientEvents } from "@dxos/plugin-client/types";
3066
+ import { DeckEvents } from "@dxos/plugin-deck/types";
3067
+ import { MarkdownEvents } from "@dxos/plugin-markdown";
3068
+ import { SpaceOperation } from "@dxos/plugin-space/operations";
209
3069
  import { SpaceCapabilities, SpaceEvents } from "@dxos/plugin-space/types";
210
3070
  import { HasSubject } from "@dxos/types";
211
- var AssistantPlugin = Plugin.define(meta).pipe(Common.Plugin.addTranslationsModule({
212
- translations
213
- }), Common.Plugin.addSettingsModule({
214
- activate: Settings
215
- }), Plugin.addModule({
216
- // TODO(wittjosiah): Does not integrate with settings store.
217
- // Should this be a different event?
218
- // Should settings store be renamed to be more generic?
219
- activatesOn: Common.ActivationEvent.SetupSettings,
220
- activate: AssistantState
221
- }), Common.Plugin.addMetadataModule({
3071
+ import { AiService, AppGraphBuilder, AssistantState, BlueprintDefinition, CompanionChatProvisioner, EdgeModelResolver, LocalModelResolver, MarkdownExtension, Migrations, OperationHandler, ReactSurface, Settings, Toolkit } from "#capabilities";
3072
+ import { meta as meta11 } from "#meta";
3073
+ import { AssistantOperation as AssistantOperation2 } from "#operations";
3074
+ import { AssistantEvents as AssistantEvents2 } from "#types";
3075
+ var AssistantPlugin = Plugin.define(meta11).pipe(AppPlugin.addAppGraphModule({
3076
+ activate: AppGraphBuilder
3077
+ }), AppPlugin.addBlueprintDefinitionModule({
3078
+ activate: BlueprintDefinition
3079
+ }), AppPlugin.addMetadataModule({
222
3080
  metadata: [
223
3081
  {
224
- id: Type2.getTypename(Assistant_exports.Chat),
3082
+ id: Type3.getTypename(Chat4.Chat),
225
3083
  metadata: {
226
- icon: "ph--atom--regular",
227
- iconHue: "sky",
228
- createObject: (props) => Effect.sync(() => Assistant_exports.make(props))
3084
+ icon: Annotation3.IconAnnotation.get(Chat4.Chat).pipe(Option6.getOrThrow).icon,
3085
+ iconHue: Annotation3.IconAnnotation.get(Chat4.Chat).pipe(Option6.getOrThrow).hue ?? "white",
3086
+ createObject: (props, options) => Effect5.gen(function* () {
3087
+ const { object } = yield* Operation3.invoke(AssistantOperation2.CreateChat, {
3088
+ db: options.db,
3089
+ name: props?.name
3090
+ });
3091
+ return yield* Operation3.invoke(SpaceOperation.AddObject, {
3092
+ object,
3093
+ target: options.target,
3094
+ hidden: true,
3095
+ targetNodeId: options.targetNodeId
3096
+ });
3097
+ })
229
3098
  }
230
3099
  },
231
3100
  {
232
- id: Type2.getTypename(Blueprint2.Blueprint),
3101
+ id: Type3.getTypename(Blueprint3.Blueprint),
233
3102
  metadata: {
234
- icon: "ph--blueprint--regular",
235
- iconHue: "sky",
236
- inputSchema: AssistantOperation.BlueprintForm,
237
- createObject: (props) => Effect.sync(() => Blueprint2.make(props))
3103
+ icon: Annotation3.IconAnnotation.get(Blueprint3.Blueprint).pipe(Option6.getOrThrow).icon,
3104
+ iconHue: Annotation3.IconAnnotation.get(Blueprint3.Blueprint).pipe(Option6.getOrThrow).hue ?? "white",
3105
+ inputSchema: AssistantOperation2.BlueprintForm,
3106
+ createObject: (props, options) => Effect5.gen(function* () {
3107
+ const object = Blueprint3.make(props);
3108
+ return yield* Operation3.invoke(SpaceOperation.AddObject, {
3109
+ object,
3110
+ target: options.target,
3111
+ hidden: true,
3112
+ targetNodeId: options.targetNodeId
3113
+ });
3114
+ })
238
3115
  }
239
3116
  },
240
3117
  {
241
- id: Type2.getTypename(Prompt2.Prompt),
3118
+ id: Type3.getTypename(Prompt2.Prompt),
242
3119
  metadata: {
243
- icon: "ph--scroll--regular",
244
- iconHue: "sky",
245
- createObject: (props) => Effect.sync(() => Prompt2.make(props))
3120
+ icon: Annotation3.IconAnnotation.get(Prompt2.Prompt).pipe(Option6.getOrThrow).icon,
3121
+ iconHue: Annotation3.IconAnnotation.get(Prompt2.Prompt).pipe(Option6.getOrThrow).hue ?? "white",
3122
+ createObject: (props, options) => Effect5.gen(function* () {
3123
+ const object = Prompt2.make(props);
3124
+ return yield* Operation3.invoke(SpaceOperation.AddObject, {
3125
+ object,
3126
+ target: options.target,
3127
+ hidden: true,
3128
+ targetNodeId: options.targetNodeId
3129
+ });
3130
+ })
246
3131
  }
247
3132
  },
248
3133
  {
249
- id: Type2.getTypename(Sequence2),
3134
+ id: Type3.getTypename(Sequence2),
250
3135
  metadata: {
251
- icon: "ph--circuitry--regular",
252
- iconHue: "sky",
253
- createObject: (props) => Effect.sync(() => Obj.make(Sequence2, props)),
254
- addToCollectionOnCreate: true
3136
+ icon: Annotation3.IconAnnotation.get(Sequence2).pipe(Option6.getOrThrow).icon,
3137
+ iconHue: Annotation3.IconAnnotation.get(Sequence2).pipe(Option6.getOrThrow).hue ?? "white",
3138
+ createObject: (props, options) => Effect5.gen(function* () {
3139
+ const object = Obj8.make(Sequence2, props);
3140
+ return yield* Operation3.invoke(SpaceOperation.AddObject, {
3141
+ object,
3142
+ target: options.target,
3143
+ hidden: true,
3144
+ targetNodeId: options.targetNodeId
3145
+ });
3146
+ })
3147
+ }
3148
+ },
3149
+ {
3150
+ id: Type3.getTypename(Agent2.Agent),
3151
+ metadata: {
3152
+ icon: Annotation3.IconAnnotation.get(Agent2.Agent).pipe(Option6.getOrThrow).icon,
3153
+ iconHue: Annotation3.IconAnnotation.get(Agent2.Agent).pipe(Option6.getOrThrow).hue ?? "white",
3154
+ createObject: (props, options) => Effect5.gen(function* () {
3155
+ const object = yield* Agent2.makeInitialized({
3156
+ name: "",
3157
+ spec: ""
3158
+ }, AgentBlueprint.make()).pipe(withComputeRuntime(options.db.spaceId));
3159
+ return yield* Operation3.invoke(SpaceOperation.AddObject, {
3160
+ object,
3161
+ target: options.target,
3162
+ hidden: true,
3163
+ targetNodeId: options.targetNodeId
3164
+ });
3165
+ })
255
3166
  }
256
3167
  }
257
3168
  ]
258
- }), Common.Plugin.addSchemaModule({
3169
+ }), AppPlugin.addOperationHandlerModule({
3170
+ activate: OperationHandler
3171
+ }), AppPlugin.addSchemaModule({
259
3172
  schema: [
260
- Assistant_exports.Chat,
261
- Assistant_exports.CompanionTo,
262
- Blueprint2.Blueprint,
3173
+ Chat4.Chat,
3174
+ Chat4.CompanionTo,
3175
+ Blueprint3.Blueprint,
3176
+ Feed.Feed,
263
3177
  HasSubject.HasSubject,
264
3178
  Prompt2.Prompt,
265
- ResearchGraph,
266
- Sequence2
3179
+ ResearchGraph.ResearchGraph,
3180
+ Agent2.Agent,
3181
+ Plan.Plan,
3182
+ Sequence2,
3183
+ Memory.Memory
267
3184
  ]
268
- }), Plugin.addModule({
269
- id: "on-space-created",
270
- activatesOn: SpaceEvents.SpaceCreated,
271
- activate: () => Effect.succeed(Capability12.contributes(SpaceCapabilities.OnCreateSpace, (params) => Operation.invoke(AssistantOperation.OnCreateSpace, params)))
272
- }), Plugin.addModule({
273
- activatesOn: ClientEvents.SpacesReady,
274
- activate: Repair
275
- }), Common.Plugin.addAppGraphModule({
276
- activate: AppGraphBuilder
277
- }), Common.Plugin.addOperationResolverModule({
278
- activate: OperationResolver
279
- }), Common.Plugin.addSurfaceModule({
3185
+ }), AppPlugin.addSettingsModule({
3186
+ activate: Settings
3187
+ }), AppPlugin.addSurfaceModule({
280
3188
  activate: ReactSurface,
281
3189
  activatesBefore: [
282
- Common.ActivationEvent.SetupArtifactDefinition
3190
+ AppActivationEvents.SetupArtifactDefinition
283
3191
  ]
3192
+ }), AppPlugin.addTranslationsModule({
3193
+ translations
3194
+ }), Plugin.addModule({
3195
+ id: "markdown",
3196
+ activatesOn: MarkdownEvents.SetupExtensions,
3197
+ activate: MarkdownExtension
3198
+ }), Plugin.addModule({
3199
+ // TODO(wittjosiah): Does not integrate with settings store.
3200
+ // Should this be a different event?
3201
+ // Should settings store be renamed to be more generic?
3202
+ activatesOn: AppActivationEvents.SetupSettings,
3203
+ activate: AssistantState
3204
+ }), Plugin.addModule({
3205
+ id: "on-space-created",
3206
+ activatesOn: SpaceEvents.SpaceCreated,
3207
+ activate: () => Effect5.succeed(Capability.contributes(SpaceCapabilities.OnCreateSpace, (params) => Operation3.invoke(AssistantOperation2.OnCreateSpace, params)))
284
3208
  }), Plugin.addModule({
285
- activatesOn: AssistantEvents.SetupAiServiceProviders,
3209
+ activatesOn: AssistantEvents2.SetupAiServiceProviders,
286
3210
  activate: EdgeModelResolver
287
3211
  }), Plugin.addModule({
288
- activatesOn: AssistantEvents.SetupAiServiceProviders,
3212
+ activatesOn: AssistantEvents2.SetupAiServiceProviders,
289
3213
  activate: LocalModelResolver
290
3214
  }), Plugin.addModule({
291
3215
  activatesBefore: [
292
- AssistantEvents.SetupAiServiceProviders
3216
+ AssistantEvents2.SetupAiServiceProviders
293
3217
  ],
294
3218
  // TODO(dmaretskyi): This should activate lazily when the AI chat is used.
295
- activatesOn: Common.ActivationEvent.Startup,
3219
+ activatesOn: ActivationEvents.Startup,
296
3220
  activate: AiService
297
- }), Common.Plugin.addBlueprintDefinitionModule({
298
- activate: BlueprintDefinition
299
3221
  }), Plugin.addModule({
300
3222
  // TODO(wittjosiah): Use a different event.
301
- activatesOn: Common.ActivationEvent.Startup,
3223
+ activatesOn: ActivationEvents.Startup,
302
3224
  activate: Toolkit
3225
+ }), Plugin.addModule({
3226
+ activatesOn: ActivationEvent.allOf(ActivationEvents.OperationInvokerReady, AppActivationEvents.AppGraphReady, DeckEvents.StateReady),
3227
+ activate: CompanionChatProvisioner
3228
+ }), Plugin.addModule({
3229
+ activatesOn: ClientEvents.SetupMigration,
3230
+ activate: Migrations
303
3231
  }), Plugin.make);
3232
+ var withComputeRuntime = (spaceId) => (effect) => Effect5.gen(function* () {
3233
+ const provider = yield* Capability.get(AutomationCapabilities2.ComputeRuntime).pipe(Effect5.orDie);
3234
+ const runtime3 = yield* provider.getRuntime(spaceId).runtimeEffect;
3235
+ return yield* effect.pipe(Effect5.provide(runtime3));
3236
+ });
304
3237
  export {
3238
+ ASSISTANT_COMPANION_VARIANT,
305
3239
  ASSISTANT_DIALOG,
306
- AiService,
307
3240
  ApiAuthorization,
308
- AppGraphBuilder,
309
3241
  Assistant_exports as Assistant,
310
- assistant_blueprint_exports as AssistantBlueprint,
3242
+ blueprint_default as AssistantBlueprint,
311
3243
  AssistantCapabilities,
312
3244
  AssistantEvents,
313
- AssistantOperation,
314
3245
  AssistantPlugin,
315
3246
  AssistantSettings,
316
- AssistantState,
317
- BlueprintArticle,
318
- BlueprintDefinition,
319
3247
  Chat,
320
- ChatCompanion,
321
- ChatContainer,
322
3248
  ChatContextProvider,
323
- ChatDialog,
324
- EdgeModelResolver,
325
3249
  LLM_PROVIDERS,
326
- LocalModelResolver,
327
- OperationResolver,
328
- PromptArticle,
329
- ReactSurface,
330
- Repair,
3250
+ ProcessTree,
331
3251
  ServiceType,
332
- Settings,
333
3252
  TemplateEditor,
334
3253
  Toolbox,
335
- ToolboxContainer,
336
- Toolkit,
3254
+ ToolboxPanel,
337
3255
  categoryIcons,
338
- meta,
3256
+ meta9 as meta,
339
3257
  translations,
340
- useActiveBlueprints,
341
- useBlueprintHandlers,
3258
+ useActiveBlueprints2 as useActiveBlueprints,
3259
+ useBlueprintHandlers2 as useBlueprintHandlers,
342
3260
  useBlueprintRegistry,
343
- useBlueprints,
3261
+ useBlueprints2 as useBlueprints,
344
3262
  useChatContext,
345
3263
  useChatProcessor,
346
3264
  useChatServices,
347
- useChatToolbarActions,
3265
+ useChatToolbarActions2 as useChatToolbarActions,
348
3266
  useContextBinder,
349
- useContextObjects,
350
- useFilteredTypes,
3267
+ useContextObjects3 as useContextObjects,
3268
+ useFilteredTypes2 as useFilteredTypes,
351
3269
  useFlush,
352
3270
  useOnline,
353
3271
  usePresets,