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