@dxos/plugin-assistant 0.8.4-main.f9ba587 → 0.8.4-main.fcc0d83b33

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