@dxos/plugin-assistant 0.10.0 → 0.11.1

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 (611) hide show
  1. package/PLUGIN.mdl +3 -28
  2. package/dist/lib/AssistantPlugin.mjs +2 -0
  3. package/dist/lib/AssistantPlugin.node.mjs +55 -0
  4. package/dist/lib/AssistantPlugin.node.mjs.map +1 -0
  5. package/dist/lib/AssistantPlugin.workerd.mjs +43 -0
  6. package/dist/lib/AssistantPlugin.workerd.mjs.map +1 -0
  7. package/dist/lib/capabilities.mjs +24 -0
  8. package/dist/lib/capabilities.mjs.map +1 -0
  9. package/dist/lib/chunk-AgentArticle.mjs +52 -0
  10. package/dist/lib/chunk-AgentArticle.mjs.map +1 -0
  11. package/dist/lib/chunk-AgentProperties.mjs +35 -0
  12. package/dist/lib/chunk-AgentProperties.mjs.map +1 -0
  13. package/dist/lib/chunk-AssistantPlugin.mjs +88 -0
  14. package/dist/lib/chunk-AssistantPlugin.mjs.map +1 -0
  15. package/dist/lib/chunk-AssistantSettings.mjs +285 -0
  16. package/dist/lib/chunk-AssistantSettings.mjs.map +1 -0
  17. package/dist/lib/chunk-ChatArticle.mjs +121 -0
  18. package/dist/lib/chunk-ChatArticle.mjs.map +1 -0
  19. package/dist/lib/chunk-ChatCompanion.mjs +116 -0
  20. package/dist/lib/chunk-ChatCompanion.mjs.map +1 -0
  21. package/dist/lib/chunk-ChatDialog.mjs +73 -0
  22. package/dist/lib/chunk-ChatDialog.mjs.map +1 -0
  23. package/dist/lib/chunk-IntegrationPrompt.mjs +73 -0
  24. package/dist/lib/chunk-IntegrationPrompt.mjs.map +1 -0
  25. package/dist/lib/chunk-SpaceHomePrompt.mjs +104 -0
  26. package/dist/lib/chunk-SpaceHomePrompt.mjs.map +1 -0
  27. package/dist/lib/chunk-SpaceHomeSuggestions.mjs +60 -0
  28. package/dist/lib/chunk-SpaceHomeSuggestions.mjs.map +1 -0
  29. package/dist/lib/chunk-TracePanel.mjs +127 -0
  30. package/dist/lib/chunk-TracePanel.mjs.map +1 -0
  31. package/dist/lib/chunk-TracePanel2.mjs +7 -0
  32. package/dist/lib/chunk-TracePanel2.mjs.map +1 -0
  33. package/dist/lib/chunk-TriggerStatus.mjs +72 -0
  34. package/dist/lib/chunk-TriggerStatus.mjs.map +1 -0
  35. package/dist/lib/chunk-agent-hydrator.mjs +22 -0
  36. package/dist/lib/chunk-agent-hydrator.mjs.map +1 -0
  37. package/dist/lib/chunk-agent-service.mjs +21 -0
  38. package/dist/lib/chunk-agent-service.mjs.map +1 -0
  39. package/dist/lib/{neutral/ai-context-LIKJYMIN.mjs → chunk-ai-context.mjs} +8 -12
  40. package/dist/lib/chunk-ai-context.mjs.map +1 -0
  41. package/dist/lib/chunk-ai-service.mjs +27 -0
  42. package/dist/lib/chunk-ai-service.mjs.map +1 -0
  43. package/dist/lib/chunk-app-graph-builder.mjs +179 -0
  44. package/dist/lib/chunk-app-graph-builder.mjs.map +1 -0
  45. package/dist/lib/chunk-automation-templates.mjs +99 -0
  46. package/dist/lib/chunk-automation-templates.mjs.map +1 -0
  47. package/dist/lib/chunk-companion-chat-provisioner.mjs +123 -0
  48. package/dist/lib/chunk-companion-chat-provisioner.mjs.map +1 -0
  49. package/dist/lib/chunk-connector.mjs +60 -0
  50. package/dist/lib/chunk-connector.mjs.map +1 -0
  51. package/dist/lib/chunk-constants.mjs +9 -0
  52. package/dist/lib/chunk-constants.mjs.map +1 -0
  53. package/dist/lib/chunk-context.mjs +7 -0
  54. package/dist/lib/chunk-context.mjs.map +1 -0
  55. package/dist/lib/chunk-create-chat.mjs +53 -0
  56. package/dist/lib/chunk-create-chat.mjs.map +1 -0
  57. package/dist/lib/chunk-create-object.mjs +70 -0
  58. package/dist/lib/chunk-create-object.mjs.map +1 -0
  59. package/dist/lib/chunk-edge-model-resolver.mjs +64 -0
  60. package/dist/lib/chunk-edge-model-resolver.mjs.map +1 -0
  61. package/dist/lib/chunk-ensure-companion-chat.mjs +49 -0
  62. package/dist/lib/chunk-ensure-companion-chat.mjs.map +1 -0
  63. package/dist/lib/chunk-extensions.mjs +78 -0
  64. package/dist/lib/chunk-extensions.mjs.map +1 -0
  65. package/dist/lib/chunk-fork-chat.mjs +83 -0
  66. package/dist/lib/chunk-fork-chat.mjs.map +1 -0
  67. package/dist/lib/chunk-generate-home-suggestions.mjs +71 -0
  68. package/dist/lib/chunk-generate-home-suggestions.mjs.map +1 -0
  69. package/dist/lib/chunk-local-model-resolver.mjs +25 -0
  70. package/dist/lib/chunk-local-model-resolver.mjs.map +1 -0
  71. package/dist/lib/chunk-markdown-extension.mjs +27 -0
  72. package/dist/lib/chunk-markdown-extension.mjs.map +1 -0
  73. package/dist/lib/{neutral/chunk-L7AR4VTA.mjs → chunk-meta.mjs} +20 -25
  74. package/dist/lib/chunk-meta.mjs.map +1 -0
  75. package/dist/lib/chunk-operation-handler.mjs +13 -0
  76. package/dist/lib/chunk-operation-handler.mjs.map +1 -0
  77. package/dist/lib/chunk-paths.mjs +8 -0
  78. package/dist/lib/chunk-paths.mjs.map +1 -0
  79. package/dist/lib/chunk-processor.mjs +432 -0
  80. package/dist/lib/chunk-processor.mjs.map +1 -0
  81. package/dist/lib/chunk-react-surface.mjs +177 -0
  82. package/dist/lib/chunk-react-surface.mjs.map +1 -0
  83. package/dist/lib/chunk-run-prompt-in-new-chat.mjs +96 -0
  84. package/dist/lib/chunk-run-prompt-in-new-chat.mjs.map +1 -0
  85. package/dist/lib/chunk-set-current-chat.mjs +43 -0
  86. package/dist/lib/chunk-set-current-chat.mjs.map +1 -0
  87. package/dist/lib/chunk-settings.mjs +23 -0
  88. package/dist/lib/chunk-settings.mjs.map +1 -0
  89. package/dist/lib/chunk-skill-definition.mjs +42 -0
  90. package/dist/lib/chunk-skill-definition.mjs.map +1 -0
  91. package/dist/lib/chunk-skills.mjs +19 -0
  92. package/dist/lib/chunk-skills.mjs.map +1 -0
  93. package/dist/lib/chunk-state.mjs +32 -0
  94. package/dist/lib/chunk-state.mjs.map +1 -0
  95. package/dist/lib/chunk-toggle-trace-panel-debug.mjs +18 -0
  96. package/dist/lib/chunk-toggle-trace-panel-debug.mjs.map +1 -0
  97. package/dist/lib/chunk-toolkit.mjs +12 -0
  98. package/dist/lib/chunk-toolkit.mjs.map +1 -0
  99. package/dist/lib/chunk-types.mjs +332 -0
  100. package/dist/lib/chunk-types.mjs.map +1 -0
  101. package/dist/lib/chunk-update-chat-name.mjs +63 -0
  102. package/dist/lib/chunk-update-chat-name.mjs.map +1 -0
  103. package/dist/lib/components.mjs +2616 -0
  104. package/dist/lib/components.mjs.map +1 -0
  105. package/dist/lib/containers.mjs +17 -0
  106. package/dist/lib/containers.mjs.map +1 -0
  107. package/dist/lib/execution-graph.mjs +961 -0
  108. package/dist/lib/execution-graph.mjs.map +1 -0
  109. package/dist/lib/extensions.mjs +2 -0
  110. package/dist/lib/hooks.mjs +674 -0
  111. package/dist/lib/hooks.mjs.map +1 -0
  112. package/dist/lib/index.mjs +5 -0
  113. package/dist/lib/meta.mjs +2 -0
  114. package/dist/lib/operations.mjs +7 -0
  115. package/dist/lib/operations.mjs.map +1 -0
  116. package/dist/lib/plugin.mjs +9 -0
  117. package/dist/lib/plugin.mjs.map +1 -0
  118. package/dist/lib/plugin.workerd.mjs +2 -0
  119. package/dist/lib/skills.mjs +2 -0
  120. package/dist/lib/testing.mjs +2 -0
  121. package/dist/lib/translations.mjs +207 -0
  122. package/dist/lib/translations.mjs.map +1 -0
  123. package/dist/lib/types.mjs +2 -0
  124. package/dist/types/src/AssistantPlugin.d.ts.map +1 -1
  125. package/dist/types/src/AssistantPlugin.node.d.ts.map +1 -1
  126. package/dist/types/src/AssistantPlugin.workerd.d.ts.map +1 -1
  127. package/dist/types/src/capabilities/AssistantSurfaces.d.ts +22 -0
  128. package/dist/types/src/capabilities/AssistantSurfaces.d.ts.map +1 -0
  129. package/dist/types/src/capabilities/agent-hydrator.d.ts +1 -1
  130. package/dist/types/src/capabilities/agent-service.d.ts +1 -1
  131. package/dist/types/src/capabilities/agent-service.d.ts.map +1 -1
  132. package/dist/types/src/capabilities/ai-context.d.ts +1 -1
  133. package/dist/types/src/capabilities/ai-service.d.ts +1 -1
  134. package/dist/types/src/capabilities/app-graph-builder.d.ts +12 -1
  135. package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -1
  136. package/dist/types/src/capabilities/automation-templates.d.ts +1 -1
  137. package/dist/types/src/capabilities/companion-chat-provisioner.d.ts +1 -1
  138. package/dist/types/src/capabilities/connector.d.ts +1 -1
  139. package/dist/types/src/capabilities/create-object.d.ts +1 -1
  140. package/dist/types/src/capabilities/edge-model-resolver.d.ts +1 -1
  141. package/dist/types/src/capabilities/edge-model-resolver.d.ts.map +1 -1
  142. package/dist/types/src/capabilities/index.d.ts +0 -2
  143. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  144. package/dist/types/src/capabilities/local-model-resolver.d.ts +1 -1
  145. package/dist/types/src/capabilities/local-model-resolver.d.ts.map +1 -1
  146. package/dist/types/src/capabilities/markdown-extension.d.ts +1 -1
  147. package/dist/types/src/capabilities/operation-handler.d.ts +1 -1
  148. package/dist/types/src/capabilities/react-surface.d.ts +1 -1
  149. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
  150. package/dist/types/src/capabilities/settings.d.ts +1 -1
  151. package/dist/types/src/capabilities/skill-definition.d.ts.map +1 -1
  152. package/dist/types/src/capabilities/standalone-chats-query.test.d.ts +2 -0
  153. package/dist/types/src/capabilities/standalone-chats-query.test.d.ts.map +1 -0
  154. package/dist/types/src/capabilities/state.d.ts +1 -1
  155. package/dist/types/src/capabilities/toolkit.d.ts +1 -1
  156. package/dist/types/src/components/AgentProperties/AgentProperties.d.ts +4 -1
  157. package/dist/types/src/components/AgentProperties/AgentProperties.d.ts.map +1 -1
  158. package/dist/types/src/components/AgentProperties/AgentProperties.stories.d.ts.map +1 -1
  159. package/dist/types/src/components/Chat/Chat.d.ts +21 -8
  160. package/dist/types/src/components/Chat/Chat.d.ts.map +1 -1
  161. package/dist/types/src/components/Chat/{Chat.stories.d.ts → Error.stories.d.ts} +1 -1
  162. package/dist/types/src/components/Chat/Error.stories.d.ts.map +1 -0
  163. package/dist/types/src/components/Chat/context.d.ts +8 -0
  164. package/dist/types/src/components/Chat/context.d.ts.map +1 -1
  165. package/dist/types/src/components/Chat/events.d.ts +5 -0
  166. package/dist/types/src/components/Chat/events.d.ts.map +1 -1
  167. package/dist/types/src/components/Chat/thread.d.ts +42 -0
  168. package/dist/types/src/components/Chat/thread.d.ts.map +1 -0
  169. package/dist/types/src/components/Chat/thread.test.d.ts +2 -0
  170. package/dist/types/src/components/Chat/thread.test.d.ts.map +1 -0
  171. package/dist/types/src/components/ChatPrompt/ChatActions.d.ts.map +1 -1
  172. package/dist/types/src/components/ChatPrompt/ChatOptions.stories.d.ts.map +1 -1
  173. package/dist/types/src/components/ChatPrompt/ChatPrompt.d.ts +5 -3
  174. package/dist/types/src/components/ChatPrompt/ChatPrompt.d.ts.map +1 -1
  175. package/dist/types/src/components/ChatPrompt/index.d.ts +0 -1
  176. package/dist/types/src/components/ChatPrompt/index.d.ts.map +1 -1
  177. package/dist/types/src/components/ChatThread/Anchor.stories.d.ts.map +1 -1
  178. package/dist/types/src/components/ChatThread/ChatThread.d.ts +8 -3
  179. package/dist/types/src/components/ChatThread/ChatThread.d.ts.map +1 -1
  180. package/dist/types/src/components/ChatThread/ChatThread.stories.d.ts +30 -2
  181. package/dist/types/src/components/ChatThread/ChatThread.stories.d.ts.map +1 -1
  182. package/dist/types/src/components/ChatThread/Link.d.ts.map +1 -1
  183. package/dist/types/src/components/ChatThread/index.d.ts +1 -0
  184. package/dist/types/src/components/ChatThread/index.d.ts.map +1 -1
  185. package/dist/types/src/components/ChatThread/registry.d.ts.map +1 -1
  186. package/dist/types/src/components/ChatThread/sync/index.d.ts +3 -0
  187. package/dist/types/src/components/ChatThread/sync/index.d.ts.map +1 -0
  188. package/dist/types/src/components/ChatThread/{sync.d.ts → sync/sync.d.ts} +46 -2
  189. package/dist/types/src/components/ChatThread/sync/sync.d.ts.map +1 -0
  190. package/dist/types/src/components/ChatThread/sync/sync.test.d.ts.map +1 -0
  191. package/dist/types/src/components/ChatThread/sync/tool-widget-state.d.ts.map +1 -0
  192. package/dist/types/src/components/ChatThread/sync/tool-widget-state.test.d.ts.map +1 -0
  193. package/dist/types/src/components/ChatThread/widgets/BranchWidget.d.ts +15 -0
  194. package/dist/types/src/components/ChatThread/widgets/BranchWidget.d.ts.map +1 -0
  195. package/dist/types/src/components/ChatThread/widgets/BranchWidget.stories.d.ts +21 -0
  196. package/dist/types/src/components/ChatThread/widgets/BranchWidget.stories.d.ts.map +1 -0
  197. package/dist/types/src/components/ChatThread/widgets/BranchWidget.test.d.ts +2 -0
  198. package/dist/types/src/components/ChatThread/widgets/BranchWidget.test.d.ts.map +1 -0
  199. package/dist/types/src/components/ChatThread/widgets/ReferenceWidget.d.ts.map +1 -1
  200. package/dist/types/src/components/ChatThread/widgets/SuggestionWidget.d.ts.map +1 -1
  201. package/dist/types/src/components/ChatThread/widgets/ToolWidget.d.ts +1 -2
  202. package/dist/types/src/components/ChatThread/widgets/ToolWidget.d.ts.map +1 -1
  203. package/dist/types/src/components/ChatThread/widgets/defaults.d.ts +6 -0
  204. package/dist/types/src/components/ChatThread/widgets/defaults.d.ts.map +1 -1
  205. package/dist/types/src/components/ChatThread/widgets/format-time.d.ts +2 -0
  206. package/dist/types/src/components/ChatThread/widgets/format-time.d.ts.map +1 -0
  207. package/dist/types/src/components/ChatThread/widgets/index.d.ts +4 -1
  208. package/dist/types/src/components/ChatThread/widgets/index.d.ts.map +1 -1
  209. package/dist/types/src/components/ChatThread/widgets/is-tool-message.d.ts +3 -0
  210. package/dist/types/src/components/ChatThread/widgets/is-tool-message.d.ts.map +1 -0
  211. package/dist/types/src/components/ConnectorAuthMenu/ConnectorAuthMenu.d.ts +16 -0
  212. package/dist/types/src/components/ConnectorAuthMenu/ConnectorAuthMenu.d.ts.map +1 -0
  213. package/dist/types/src/components/ConnectorAuthMenu/ConnectorAuthMenu.stories.d.ts +210 -0
  214. package/dist/types/src/components/ConnectorAuthMenu/ConnectorAuthMenu.stories.d.ts.map +1 -0
  215. package/dist/types/src/components/ConnectorAuthMenu/index.d.ts +2 -0
  216. package/dist/types/src/components/ConnectorAuthMenu/index.d.ts.map +1 -0
  217. package/dist/types/src/components/ProcessTree/ProcessTree.d.ts +1 -1
  218. package/dist/types/src/components/ProcessTree/ProcessTree.d.ts.map +1 -1
  219. package/dist/types/src/components/TaskList/TaskList.d.ts +9 -11
  220. package/dist/types/src/components/TaskList/TaskList.d.ts.map +1 -1
  221. package/dist/types/src/components/TaskList/TaskList.stories.d.ts +3 -4
  222. package/dist/types/src/components/TaskList/TaskList.stories.d.ts.map +1 -1
  223. package/dist/types/src/components/ToolBlock/ToolBlock.d.ts +1 -2
  224. package/dist/types/src/components/ToolBlock/ToolBlock.d.ts.map +1 -1
  225. package/dist/types/src/components/ToolBlock/index.d.ts +1 -0
  226. package/dist/types/src/components/ToolBlock/index.d.ts.map +1 -1
  227. package/dist/types/src/components/ToolBlock/is-tool-message.d.ts +3 -0
  228. package/dist/types/src/components/ToolBlock/is-tool-message.d.ts.map +1 -0
  229. package/dist/types/src/components/Toolbox/Toolbox.d.ts +1 -1
  230. package/dist/types/src/components/Toolbox/Toolbox.d.ts.map +1 -1
  231. package/dist/types/src/components/index.d.ts +1 -0
  232. package/dist/types/src/components/index.d.ts.map +1 -1
  233. package/dist/types/src/containers/AgentArticle/AgentArticle.d.ts +5 -2
  234. package/dist/types/src/containers/AgentArticle/AgentArticle.d.ts.map +1 -1
  235. package/dist/types/src/containers/AgentArticle/AgentArticle.stories.d.ts.map +1 -1
  236. package/dist/types/src/containers/AgentProperties/AgentProperties.d.ts +4 -1
  237. package/dist/types/src/containers/AgentProperties/AgentProperties.d.ts.map +1 -1
  238. package/dist/types/src/containers/AssistantSettings/AssistantSettings.d.ts +4 -1
  239. package/dist/types/src/containers/AssistantSettings/AssistantSettings.d.ts.map +1 -1
  240. package/dist/types/src/containers/AssistantSettings/AssistantSettings.stories.d.ts +4 -1
  241. package/dist/types/src/containers/AssistantSettings/AssistantSettings.stories.d.ts.map +1 -1
  242. package/dist/types/src/containers/AssistantSettings/OllamaModels.d.ts +4 -6
  243. package/dist/types/src/containers/AssistantSettings/OllamaModels.d.ts.map +1 -1
  244. package/dist/types/src/containers/ChatArticle/ChatArticle.d.ts.map +1 -1
  245. package/dist/types/src/containers/ChatArticle/ChatArticle.stories.d.ts +22 -1
  246. package/dist/types/src/containers/ChatArticle/ChatArticle.stories.d.ts.map +1 -1
  247. package/dist/types/src/containers/ChatCompanion/ChatCompanion.d.ts.map +1 -1
  248. package/dist/types/src/containers/ChatDialog/ChatDialog.d.ts +4 -1
  249. package/dist/types/src/containers/ChatDialog/ChatDialog.d.ts.map +1 -1
  250. package/dist/types/src/containers/IntegrationPrompt/IntegrationPrompt.d.ts +4 -7
  251. package/dist/types/src/containers/IntegrationPrompt/IntegrationPrompt.d.ts.map +1 -1
  252. package/dist/types/src/containers/SpaceHomePrompt/SpaceHomePrompt.d.ts +4 -9
  253. package/dist/types/src/containers/SpaceHomePrompt/SpaceHomePrompt.d.ts.map +1 -1
  254. package/dist/types/src/containers/SpaceHomeSuggestions/SpaceHomeSuggestions.d.ts +5 -7
  255. package/dist/types/src/containers/SpaceHomeSuggestions/SpaceHomeSuggestions.d.ts.map +1 -1
  256. package/dist/types/src/containers/TracePanel/TracePanel.d.ts +1 -1
  257. package/dist/types/src/containers/TracePanel/TracePanel.d.ts.map +1 -1
  258. package/dist/types/src/containers/TracePanel/TracePanel.stories.d.ts.map +1 -1
  259. package/dist/types/src/containers/TriggerStatus/TriggerStatus.d.ts +15 -1
  260. package/dist/types/src/containers/TriggerStatus/TriggerStatus.d.ts.map +1 -1
  261. package/dist/types/src/containers/index.d.ts +0 -1
  262. package/dist/types/src/containers/index.d.ts.map +1 -1
  263. package/dist/types/src/execution-graph/execution-graph.d.ts +12 -1
  264. package/dist/types/src/execution-graph/execution-graph.d.ts.map +1 -1
  265. package/dist/types/src/execution-graph/index.d.ts +1 -1
  266. package/dist/types/src/execution-graph/index.d.ts.map +1 -1
  267. package/dist/types/src/execution-graph/pending-block-status.d.ts.map +1 -1
  268. package/dist/types/src/execution-graph/span-tree.d.ts +17 -0
  269. package/dist/types/src/execution-graph/span-tree.d.ts.map +1 -1
  270. package/dist/types/src/feed-logger.d.ts +1 -1
  271. package/dist/types/src/feed-logger.d.ts.map +1 -1
  272. package/dist/types/src/hooks/index.d.ts +1 -1
  273. package/dist/types/src/hooks/index.d.ts.map +1 -1
  274. package/dist/types/src/hooks/useChatProcessor.d.ts.map +1 -1
  275. package/dist/types/src/hooks/useChatToolbarActions.d.ts.map +1 -1
  276. package/dist/types/src/hooks/useContextObjects.d.ts +1 -1
  277. package/dist/types/src/hooks/useContextObjects.d.ts.map +1 -1
  278. package/dist/types/src/hooks/useSelectionContext.d.ts +13 -0
  279. package/dist/types/src/hooks/useSelectionContext.d.ts.map +1 -0
  280. package/dist/types/src/hooks/useSelectionContext.test.d.ts +2 -0
  281. package/dist/types/src/hooks/useSelectionContext.test.d.ts.map +1 -0
  282. package/dist/types/src/hooks/useTraceMessages.d.ts.map +1 -1
  283. package/dist/types/src/operations/index.d.ts.map +1 -1
  284. package/dist/types/src/processor/index.d.ts +1 -0
  285. package/dist/types/src/processor/index.d.ts.map +1 -1
  286. package/dist/types/src/processor/processor.d.ts +5 -2
  287. package/dist/types/src/processor/processor.d.ts.map +1 -1
  288. package/dist/types/src/processor/prompt.d.ts +18 -0
  289. package/dist/types/src/processor/prompt.d.ts.map +1 -0
  290. package/dist/types/src/processor/prompt.test.d.ts +2 -0
  291. package/dist/types/src/processor/prompt.test.d.ts.map +1 -0
  292. package/dist/types/src/processor/streaming.node.test.d.ts +2 -0
  293. package/dist/types/src/processor/streaming.node.test.d.ts.map +1 -0
  294. package/dist/types/src/skills/assistant/skill.d.ts.map +1 -1
  295. package/dist/types/src/templates/scaffold.d.ts +1 -1
  296. package/dist/types/src/templates/scaffold.d.ts.map +1 -1
  297. package/dist/types/src/translations.d.ts.map +1 -1
  298. package/dist/types/src/types/AssistantCapabilities.d.ts +1 -1
  299. package/dist/types/src/types/AssistantCapabilities.d.ts.map +1 -1
  300. package/dist/types/src/types/AssistantOperation.d.ts +2 -13
  301. package/dist/types/src/types/AssistantOperation.d.ts.map +1 -1
  302. package/dist/types/src/types/ChatSurface.d.ts +2 -2
  303. package/dist/types/src/types/ChatSurface.d.ts.map +1 -1
  304. package/dist/types/src/types/Ollama.d.ts +1 -1
  305. package/dist/types/src/types/Ollama.d.ts.map +1 -1
  306. package/dist/types/tsconfig.tsbuildinfo +1 -1
  307. package/dx.config.ts +1 -0
  308. package/package.json +106 -105
  309. package/src/AssistantPlugin.node.ts +1 -2
  310. package/src/AssistantPlugin.test.ts +60 -62
  311. package/src/AssistantPlugin.ts +1 -10
  312. package/src/AssistantPlugin.workerd.ts +1 -2
  313. package/src/capabilities/AssistantSurfaces.tsx +86 -0
  314. package/src/capabilities/agent-service.ts +1 -1
  315. package/src/capabilities/app-graph-builder.ts +31 -17
  316. package/src/capabilities/companion-chat-provisioner.ts +12 -11
  317. package/src/capabilities/connector.ts +3 -3
  318. package/src/capabilities/edge-model-resolver.ts +5 -2
  319. package/src/capabilities/index.ts +0 -2
  320. package/src/capabilities/react-surface.ts +135 -0
  321. package/src/capabilities/skill-definition.ts +4 -0
  322. package/src/capabilities/standalone-chats-query.test.ts +51 -0
  323. package/src/capabilities/state.ts +1 -1
  324. package/src/components/AgentProperties/AgentProperties.stories.tsx +6 -7
  325. package/src/components/AgentProperties/AgentProperties.tsx +37 -30
  326. package/src/components/Chat/Chat.tsx +275 -59
  327. package/src/components/Chat/{Chat.stories.tsx → Error.stories.tsx} +1 -1
  328. package/src/components/Chat/context.ts +8 -0
  329. package/src/components/Chat/events.ts +5 -0
  330. package/src/components/Chat/thread.test.ts +127 -0
  331. package/src/components/Chat/thread.ts +87 -0
  332. package/src/components/ChatPrompt/ChatActions.tsx +8 -8
  333. package/src/components/ChatPrompt/ChatMcpErrors.tsx +2 -2
  334. package/src/components/ChatPrompt/ChatOptions.stories.tsx +2 -1
  335. package/src/components/ChatPrompt/ChatOptions.tsx +5 -5
  336. package/src/components/ChatPrompt/ChatPrompt.tsx +33 -6
  337. package/src/components/ChatPrompt/index.ts +0 -1
  338. package/src/components/ChatThread/Anchor.stories.tsx +2 -1
  339. package/src/components/ChatThread/ChatThread.stories.tsx +99 -4
  340. package/src/components/ChatThread/ChatThread.tsx +34 -6
  341. package/src/components/ChatThread/Link.tsx +1 -0
  342. package/src/components/ChatThread/index.ts +2 -0
  343. package/src/components/ChatThread/registry.tsx +28 -4
  344. package/src/components/ChatThread/sync/index.ts +6 -0
  345. package/src/components/ChatThread/{sync.test.ts → sync/sync.test.ts} +167 -7
  346. package/src/components/ChatThread/{sync.ts → sync/sync.ts} +97 -3
  347. package/src/components/ChatThread/{tool-widget-state.ts → sync/tool-widget-state.ts} +1 -3
  348. package/src/components/ChatThread/widgets/BranchWidget.stories.tsx +83 -0
  349. package/src/components/ChatThread/widgets/BranchWidget.test.ts +55 -0
  350. package/src/components/ChatThread/widgets/BranchWidget.tsx +61 -0
  351. package/src/components/ChatThread/widgets/FallbackWidget.tsx +2 -2
  352. package/src/components/ChatThread/widgets/ReasoningWidget.ts +1 -1
  353. package/src/components/ChatThread/widgets/ReferenceWidget.ts +1 -6
  354. package/src/components/ChatThread/widgets/SuggestionWidget.ts +12 -3
  355. package/src/components/ChatThread/widgets/SummaryWidget.tsx +1 -1
  356. package/src/components/ChatThread/widgets/ToolWidget.tsx +15 -9
  357. package/src/components/ChatThread/widgets/defaults.ts +7 -1
  358. package/src/components/ChatThread/widgets/format-time.ts +45 -0
  359. package/src/components/ChatThread/widgets/index.ts +4 -1
  360. package/src/components/ChatThread/widgets/is-tool-message.ts +13 -0
  361. package/src/components/ConnectorAuthMenu/ConnectorAuthMenu.stories.tsx +177 -0
  362. package/src/components/ConnectorAuthMenu/ConnectorAuthMenu.tsx +82 -0
  363. package/src/components/ConnectorAuthMenu/index.ts +5 -0
  364. package/src/components/ProcessTree/ProcessTree.stories.tsx +1 -1
  365. package/src/components/TaskList/TaskList.stories.tsx +19 -26
  366. package/src/components/TaskList/TaskList.tsx +32 -104
  367. package/src/components/ToolBlock/ToolBlock.tsx +1 -5
  368. package/src/components/ToolBlock/index.ts +1 -0
  369. package/src/components/ToolBlock/is-tool-message.ts +13 -0
  370. package/src/components/Toolbox/Toolbox.tsx +1 -1
  371. package/src/components/index.ts +1 -0
  372. package/src/containers/AgentArticle/AgentArticle.stories.tsx +18 -11
  373. package/src/containers/AgentArticle/AgentArticle.tsx +27 -151
  374. package/src/containers/AgentProperties/AgentProperties.tsx +21 -17
  375. package/src/containers/AssistantSettings/AssistantSettings.tsx +2 -0
  376. package/src/containers/AssistantSettings/OllamaModels.tsx +6 -4
  377. package/src/containers/ChatArticle/ChatArticle.stories.tsx +200 -27
  378. package/src/containers/ChatArticle/ChatArticle.tsx +25 -5
  379. package/src/containers/ChatCompanion/ChatCompanion.tsx +45 -10
  380. package/src/containers/ChatDialog/ChatDialog.tsx +4 -1
  381. package/src/containers/IntegrationPrompt/IntegrationPrompt.tsx +9 -6
  382. package/src/containers/SpaceHomePrompt/SpaceHomePrompt.tsx +2 -0
  383. package/src/containers/SpaceHomeSuggestions/SpaceHomeSuggestions.tsx +40 -39
  384. package/src/containers/TracePanel/TracePanel.stories.tsx +9 -4
  385. package/src/containers/TracePanel/TracePanel.tsx +22 -6
  386. package/src/containers/TriggerStatus/TriggerStatus.tsx +9 -16
  387. package/src/containers/index.ts +0 -1
  388. package/src/execution-graph/SPEC.md +60 -2
  389. package/src/execution-graph/execution-graph.ts +15 -2
  390. package/src/execution-graph/index.ts +1 -0
  391. package/src/execution-graph/pending-block-status.ts +3 -2
  392. package/src/execution-graph/span-tree.test.ts +87 -1
  393. package/src/execution-graph/span-tree.ts +95 -0
  394. package/src/feed-logger.ts +6 -6
  395. package/src/hooks/index.ts +1 -1
  396. package/src/hooks/useChatProcessor.ts +2 -1
  397. package/src/hooks/useChatToolbarActions.ts +22 -19
  398. package/src/hooks/useContextObjects.ts +9 -3
  399. package/src/hooks/useSelectionContext.test.ts +93 -0
  400. package/src/hooks/useSelectionContext.ts +72 -0
  401. package/src/hooks/useSkillRegistry.ts +1 -1
  402. package/src/hooks/useTraceMessages.ts +5 -3
  403. package/src/operations/create-chat.ts +2 -2
  404. package/src/operations/fork-chat.ts +2 -2
  405. package/src/operations/generate-home-suggestions.test.ts +2 -2
  406. package/src/operations/index.ts +0 -1
  407. package/src/operations/prompt.node.test.ts +1 -1
  408. package/src/paths.ts +3 -3
  409. package/src/processor/index.ts +1 -0
  410. package/src/processor/processor.node.test.ts +1 -1
  411. package/src/processor/processor.ts +33 -5
  412. package/src/processor/prompt.test.ts +37 -0
  413. package/src/processor/prompt.ts +42 -0
  414. package/src/processor/streaming.node.test.ts +196 -0
  415. package/src/skills/assistant/skill.node.test.ts +2 -2
  416. package/src/skills/assistant/skill.ts +3 -5
  417. package/src/templates/routine-templates.test.ts +1 -2
  418. package/src/templates/scaffold.ts +3 -3
  419. package/src/testing/data/trace-timeline-multiple.dx.json +1 -1
  420. package/src/testing/data/trace-timeline-remote.dx.json +1 -1
  421. package/src/testing/data/trace-timeline.dx.json +1 -2
  422. package/src/testing/trace-timeline.node.test.ts +3 -3
  423. package/src/translations.ts +11 -10
  424. package/src/types/AssistantCapabilities.ts +1 -1
  425. package/src/types/AssistantOperation.ts +8 -31
  426. package/src/types/ChatSurface.ts +3 -3
  427. package/src/types/Ollama.ts +1 -1
  428. package/dist/lib/neutral/AgentArticle-GV6EEW3I.mjs +0 -161
  429. package/dist/lib/neutral/AgentArticle-GV6EEW3I.mjs.map +0 -7
  430. package/dist/lib/neutral/AgentProperties-LFTEYJ54.mjs +0 -40
  431. package/dist/lib/neutral/AgentProperties-LFTEYJ54.mjs.map +0 -7
  432. package/dist/lib/neutral/AssistantPlugin.mjs +0 -10
  433. package/dist/lib/neutral/AssistantPlugin.mjs.map +0 -7
  434. package/dist/lib/neutral/AssistantPlugin.node.mjs +0 -72
  435. package/dist/lib/neutral/AssistantPlugin.node.mjs.map +0 -7
  436. package/dist/lib/neutral/AssistantPlugin.workerd.mjs +0 -13
  437. package/dist/lib/neutral/AssistantPlugin.workerd.mjs.map +0 -7
  438. package/dist/lib/neutral/AssistantSettings-3N5M5VCN.mjs +0 -302
  439. package/dist/lib/neutral/AssistantSettings-3N5M5VCN.mjs.map +0 -7
  440. package/dist/lib/neutral/ChatArticle-OO7GGEFW.mjs +0 -8
  441. package/dist/lib/neutral/ChatArticle-OO7GGEFW.mjs.map +0 -7
  442. package/dist/lib/neutral/ChatCompanion-GIFJRY6I.mjs +0 -128
  443. package/dist/lib/neutral/ChatCompanion-GIFJRY6I.mjs.map +0 -7
  444. package/dist/lib/neutral/ChatDialog-5MXN4MXS.mjs +0 -74
  445. package/dist/lib/neutral/ChatDialog-5MXN4MXS.mjs.map +0 -7
  446. package/dist/lib/neutral/IntegrationPrompt-2HJQFYJE.mjs +0 -72
  447. package/dist/lib/neutral/IntegrationPrompt-2HJQFYJE.mjs.map +0 -7
  448. package/dist/lib/neutral/PlanArticle-VPK2IYWU.mjs +0 -34
  449. package/dist/lib/neutral/PlanArticle-VPK2IYWU.mjs.map +0 -7
  450. package/dist/lib/neutral/SpaceHomePrompt-ISAB76LD.mjs +0 -114
  451. package/dist/lib/neutral/SpaceHomePrompt-ISAB76LD.mjs.map +0 -7
  452. package/dist/lib/neutral/SpaceHomeSuggestions-IDH77QQR.mjs +0 -63
  453. package/dist/lib/neutral/SpaceHomeSuggestions-IDH77QQR.mjs.map +0 -7
  454. package/dist/lib/neutral/TracePanel-JKNWADJ4.mjs +0 -12
  455. package/dist/lib/neutral/TracePanel-JKNWADJ4.mjs.map +0 -7
  456. package/dist/lib/neutral/TriggerStatus-FURRBHYA.mjs +0 -95
  457. package/dist/lib/neutral/TriggerStatus-FURRBHYA.mjs.map +0 -7
  458. package/dist/lib/neutral/agent-hydrator-OBO3RHLO.mjs +0 -23
  459. package/dist/lib/neutral/agent-hydrator-OBO3RHLO.mjs.map +0 -7
  460. package/dist/lib/neutral/agent-service-XFJ4VQMT.mjs +0 -32
  461. package/dist/lib/neutral/agent-service-XFJ4VQMT.mjs.map +0 -7
  462. package/dist/lib/neutral/ai-context-LIKJYMIN.mjs.map +0 -7
  463. package/dist/lib/neutral/ai-service-DM6YXWUC.mjs +0 -44
  464. package/dist/lib/neutral/ai-service-DM6YXWUC.mjs.map +0 -7
  465. package/dist/lib/neutral/app-graph-builder-OPVOEQY7.mjs +0 -249
  466. package/dist/lib/neutral/app-graph-builder-OPVOEQY7.mjs.map +0 -7
  467. package/dist/lib/neutral/automation-templates-MADJLXGJ.mjs +0 -97
  468. package/dist/lib/neutral/automation-templates-MADJLXGJ.mjs.map +0 -7
  469. package/dist/lib/neutral/capabilities/index.mjs +0 -47
  470. package/dist/lib/neutral/capabilities/index.mjs.map +0 -7
  471. package/dist/lib/neutral/chunk-5IHQ52KJ.mjs +0 -9
  472. package/dist/lib/neutral/chunk-5IHQ52KJ.mjs.map +0 -7
  473. package/dist/lib/neutral/chunk-6Q4OBGIK.mjs +0 -420
  474. package/dist/lib/neutral/chunk-6Q4OBGIK.mjs.map +0 -7
  475. package/dist/lib/neutral/chunk-BXI2R4OO.mjs +0 -410
  476. package/dist/lib/neutral/chunk-BXI2R4OO.mjs.map +0 -7
  477. package/dist/lib/neutral/chunk-CMPLPDYE.mjs +0 -30
  478. package/dist/lib/neutral/chunk-CMPLPDYE.mjs.map +0 -7
  479. package/dist/lib/neutral/chunk-GPHT3HYS.mjs +0 -8
  480. package/dist/lib/neutral/chunk-GPHT3HYS.mjs.map +0 -7
  481. package/dist/lib/neutral/chunk-HKLSFB5I.mjs +0 -90
  482. package/dist/lib/neutral/chunk-HKLSFB5I.mjs.map +0 -7
  483. package/dist/lib/neutral/chunk-J5LGTIGS.mjs +0 -10
  484. package/dist/lib/neutral/chunk-J5LGTIGS.mjs.map +0 -7
  485. package/dist/lib/neutral/chunk-L7AR4VTA.mjs.map +0 -7
  486. package/dist/lib/neutral/chunk-LS72HWMM.mjs +0 -42
  487. package/dist/lib/neutral/chunk-LS72HWMM.mjs.map +0 -7
  488. package/dist/lib/neutral/chunk-OZWZGIV2.mjs +0 -12
  489. package/dist/lib/neutral/chunk-OZWZGIV2.mjs.map +0 -7
  490. package/dist/lib/neutral/chunk-QOKLFHUS.mjs +0 -13
  491. package/dist/lib/neutral/chunk-QOKLFHUS.mjs.map +0 -7
  492. package/dist/lib/neutral/chunk-SCTHQVIJ.mjs +0 -155
  493. package/dist/lib/neutral/chunk-SCTHQVIJ.mjs.map +0 -7
  494. package/dist/lib/neutral/chunk-U4LTLBAX.mjs +0 -56
  495. package/dist/lib/neutral/chunk-U4LTLBAX.mjs.map +0 -7
  496. package/dist/lib/neutral/chunk-UPKFUZ6V.mjs +0 -115
  497. package/dist/lib/neutral/chunk-UPKFUZ6V.mjs.map +0 -7
  498. package/dist/lib/neutral/chunk-V2Y4XE3O.mjs +0 -12
  499. package/dist/lib/neutral/chunk-V2Y4XE3O.mjs.map +0 -7
  500. package/dist/lib/neutral/chunk-VTK5R4H3.mjs +0 -9
  501. package/dist/lib/neutral/chunk-VTK5R4H3.mjs.map +0 -7
  502. package/dist/lib/neutral/chunk-XVGEJWJX.mjs +0 -133
  503. package/dist/lib/neutral/chunk-XVGEJWJX.mjs.map +0 -7
  504. package/dist/lib/neutral/companion-chat-provisioner-IQV5VIVE.mjs +0 -126
  505. package/dist/lib/neutral/companion-chat-provisioner-IQV5VIVE.mjs.map +0 -7
  506. package/dist/lib/neutral/components/index.mjs +0 -2527
  507. package/dist/lib/neutral/components/index.mjs.map +0 -7
  508. package/dist/lib/neutral/connector-ITLLTBPZ.mjs +0 -70
  509. package/dist/lib/neutral/connector-ITLLTBPZ.mjs.map +0 -7
  510. package/dist/lib/neutral/containers/index.mjs +0 -31
  511. package/dist/lib/neutral/containers/index.mjs.map +0 -7
  512. package/dist/lib/neutral/create-chat-YGVZZYGP.mjs +0 -56
  513. package/dist/lib/neutral/create-chat-YGVZZYGP.mjs.map +0 -7
  514. package/dist/lib/neutral/create-object-5PAEJ6KM.mjs +0 -76
  515. package/dist/lib/neutral/create-object-5PAEJ6KM.mjs.map +0 -7
  516. package/dist/lib/neutral/edge-model-resolver-WDJWDZTT.mjs +0 -55
  517. package/dist/lib/neutral/edge-model-resolver-WDJWDZTT.mjs.map +0 -7
  518. package/dist/lib/neutral/ensure-companion-chat-AMOF3C66.mjs +0 -58
  519. package/dist/lib/neutral/ensure-companion-chat-AMOF3C66.mjs.map +0 -7
  520. package/dist/lib/neutral/execution-graph/index.mjs +0 -977
  521. package/dist/lib/neutral/execution-graph/index.mjs.map +0 -7
  522. package/dist/lib/neutral/extensions/index.mjs +0 -8
  523. package/dist/lib/neutral/extensions/index.mjs.map +0 -7
  524. package/dist/lib/neutral/fork-chat-RMAAYYQF.mjs +0 -92
  525. package/dist/lib/neutral/fork-chat-RMAAYYQF.mjs.map +0 -7
  526. package/dist/lib/neutral/generate-home-suggestions-6MM2XWPV.mjs +0 -93
  527. package/dist/lib/neutral/generate-home-suggestions-6MM2XWPV.mjs.map +0 -7
  528. package/dist/lib/neutral/hooks/index.mjs +0 -877
  529. package/dist/lib/neutral/hooks/index.mjs.map +0 -7
  530. package/dist/lib/neutral/index.mjs +0 -42
  531. package/dist/lib/neutral/index.mjs.map +0 -7
  532. package/dist/lib/neutral/local-model-resolver-I2BENFFS.mjs +0 -24
  533. package/dist/lib/neutral/local-model-resolver-I2BENFFS.mjs.map +0 -7
  534. package/dist/lib/neutral/markdown-extension-R4TKDTIF.mjs +0 -41
  535. package/dist/lib/neutral/markdown-extension-R4TKDTIF.mjs.map +0 -7
  536. package/dist/lib/neutral/meta.json +0 -1
  537. package/dist/lib/neutral/meta.mjs +0 -12
  538. package/dist/lib/neutral/meta.mjs.map +0 -7
  539. package/dist/lib/neutral/migrations-7DEMVBOG.mjs +0 -28
  540. package/dist/lib/neutral/migrations-7DEMVBOG.mjs.map +0 -7
  541. package/dist/lib/neutral/navigation-resolver-PYGP2DAW.mjs +0 -18
  542. package/dist/lib/neutral/navigation-resolver-PYGP2DAW.mjs.map +0 -7
  543. package/dist/lib/neutral/operation-handler-2LEN45GP.mjs +0 -8
  544. package/dist/lib/neutral/operation-handler-2LEN45GP.mjs.map +0 -7
  545. package/dist/lib/neutral/operations/index.mjs +0 -8
  546. package/dist/lib/neutral/operations/index.mjs.map +0 -7
  547. package/dist/lib/neutral/plugin.mjs +0 -16
  548. package/dist/lib/neutral/plugin.mjs.map +0 -7
  549. package/dist/lib/neutral/plugin.workerd.mjs +0 -13
  550. package/dist/lib/neutral/plugin.workerd.mjs.map +0 -7
  551. package/dist/lib/neutral/react-surface-HEJEK44F.mjs +0 -171
  552. package/dist/lib/neutral/react-surface-HEJEK44F.mjs.map +0 -7
  553. package/dist/lib/neutral/resolve-navigation-targets-PBQ3OLUE.mjs +0 -28
  554. package/dist/lib/neutral/resolve-navigation-targets-PBQ3OLUE.mjs.map +0 -7
  555. package/dist/lib/neutral/run-prompt-in-new-chat-RNUJE2FM.mjs +0 -102
  556. package/dist/lib/neutral/run-prompt-in-new-chat-RNUJE2FM.mjs.map +0 -7
  557. package/dist/lib/neutral/set-current-chat-VWBPSIMZ.mjs +0 -48
  558. package/dist/lib/neutral/set-current-chat-VWBPSIMZ.mjs.map +0 -7
  559. package/dist/lib/neutral/settings-7Q3RITIT.mjs +0 -28
  560. package/dist/lib/neutral/settings-7Q3RITIT.mjs.map +0 -7
  561. package/dist/lib/neutral/skill-definition-553MQRTR.mjs +0 -8
  562. package/dist/lib/neutral/skill-definition-553MQRTR.mjs.map +0 -7
  563. package/dist/lib/neutral/skills/index.mjs +0 -8
  564. package/dist/lib/neutral/skills/index.mjs.map +0 -7
  565. package/dist/lib/neutral/state-4LGAKSSD.mjs +0 -34
  566. package/dist/lib/neutral/state-4LGAKSSD.mjs.map +0 -7
  567. package/dist/lib/neutral/testing.mjs +0 -8
  568. package/dist/lib/neutral/testing.mjs.map +0 -7
  569. package/dist/lib/neutral/toggle-trace-panel-debug-JGTB6KVJ.mjs +0 -21
  570. package/dist/lib/neutral/toggle-trace-panel-debug-JGTB6KVJ.mjs.map +0 -7
  571. package/dist/lib/neutral/toolkit-ETWLG5NT.mjs +0 -8
  572. package/dist/lib/neutral/toolkit-ETWLG5NT.mjs.map +0 -7
  573. package/dist/lib/neutral/translations.mjs +0 -217
  574. package/dist/lib/neutral/translations.mjs.map +0 -7
  575. package/dist/lib/neutral/types/index.mjs +0 -24
  576. package/dist/lib/neutral/types/index.mjs.map +0 -7
  577. package/dist/lib/neutral/update-chat-name-IJJELRR6.mjs +0 -61
  578. package/dist/lib/neutral/update-chat-name-IJJELRR6.mjs.map +0 -7
  579. package/dist/types/src/capabilities/migrations.d.ts +0 -5
  580. package/dist/types/src/capabilities/migrations.d.ts.map +0 -1
  581. package/dist/types/src/capabilities/navigation-resolver.d.ts +0 -5
  582. package/dist/types/src/capabilities/navigation-resolver.d.ts.map +0 -1
  583. package/dist/types/src/components/Chat/Chat.stories.d.ts.map +0 -1
  584. package/dist/types/src/components/ChatPrompt/ChatStatusIndicator.d.ts +0 -10
  585. package/dist/types/src/components/ChatPrompt/ChatStatusIndicator.d.ts.map +0 -1
  586. package/dist/types/src/components/ChatThread/sync.d.ts.map +0 -1
  587. package/dist/types/src/components/ChatThread/sync.test.d.ts.map +0 -1
  588. package/dist/types/src/components/ChatThread/tool-widget-state.d.ts.map +0 -1
  589. package/dist/types/src/components/ChatThread/tool-widget-state.test.d.ts.map +0 -1
  590. package/dist/types/src/containers/PlanArticle/PlanArticle.d.ts +0 -6
  591. package/dist/types/src/containers/PlanArticle/PlanArticle.d.ts.map +0 -1
  592. package/dist/types/src/containers/PlanArticle/index.d.ts +0 -2
  593. package/dist/types/src/containers/PlanArticle/index.d.ts.map +0 -1
  594. package/dist/types/src/hooks/useFlush.d.ts +0 -6
  595. package/dist/types/src/hooks/useFlush.d.ts.map +0 -1
  596. package/dist/types/src/operations/resolve-navigation-targets.d.ts +0 -5
  597. package/dist/types/src/operations/resolve-navigation-targets.d.ts.map +0 -1
  598. package/src/AssistantPlugin.conversations.json +0 -1
  599. package/src/capabilities/migrations.ts +0 -28
  600. package/src/capabilities/navigation-resolver.ts +0 -20
  601. package/src/capabilities/react-surface.tsx +0 -177
  602. package/src/components/ChatPrompt/ChatStatusIndicator.tsx +0 -42
  603. package/src/components/ChatThread/DEBUG.md +0 -64
  604. package/src/containers/PlanArticle/PlanArticle.tsx +0 -37
  605. package/src/containers/PlanArticle/index.ts +0 -5
  606. package/src/hooks/useFlush.ts +0 -35
  607. package/src/operations/resolve-navigation-targets.ts +0 -44
  608. /package/dist/types/src/components/ChatThread/{sync.test.d.ts → sync/sync.test.d.ts} +0 -0
  609. /package/dist/types/src/components/ChatThread/{tool-widget-state.d.ts → sync/tool-widget-state.d.ts} +0 -0
  610. /package/dist/types/src/components/ChatThread/{tool-widget-state.test.d.ts → sync/tool-widget-state.test.d.ts} +0 -0
  611. /package/src/components/ChatThread/{tool-widget-state.test.ts → sync/tool-widget-state.test.ts} +0 -0
@@ -1,2527 +0,0 @@
1
- import {
2
- TracePanel
3
- } from "../chunk-SCTHQVIJ.mjs";
4
- import {
5
- ChatContextProvider,
6
- useChatContext
7
- } from "../chunk-VTK5R4H3.mjs";
8
- import {
9
- AiUsageQuotaError
10
- } from "../chunk-BXI2R4OO.mjs";
11
- import "../chunk-J5LGTIGS.mjs";
12
-
13
- // src/components/AgentProperties/AgentProperties.tsx
14
- import { Atom } from "@effect-atom/atom";
15
- import { useAtomValue } from "@effect-atom/atom-react";
16
- import * as Option from "effect/Option";
17
- import React, { useCallback, useMemo } from "react";
18
- import { Filter, Obj, Ref, Type } from "@dxos/echo";
19
- import { useQuery } from "@dxos/react-client/echo";
20
- import { Input, useTranslation } from "@dxos/react-ui";
21
- import { Form } from "@dxos/react-ui-form";
22
- import { FeedAnnotation } from "@dxos/schema";
23
- import { meta } from "#meta";
24
- var AgentProperties = ({ agent }) => {
25
- const { t } = useTranslation(meta.profile.key);
26
- const db = Obj.getDatabase(agent);
27
- const feedFilter = useMemo(() => {
28
- if (!db) {
29
- return Filter.nothing();
30
- }
31
- const schemas = db.graph.registry.list().filter(Type.isType);
32
- const feedSchemas = schemas.filter((type) => {
33
- const annotation = FeedAnnotation.get(Type.getSchema(type));
34
- return Option.isSome(annotation) && annotation.value === true;
35
- });
36
- return feedSchemas.length === 0 ? Filter.nothing() : Filter.or(...feedSchemas.map((schema) => Filter.type(schema)));
37
- }, [
38
- db
39
- ]);
40
- const subscribedObjects = useQuery(db, feedFilter);
41
- const existingSubscriptions = useAtomValue(useMemo(() => Obj.atom(agent).pipe((_) => Atom.make((get) => {
42
- const agentObj = get(_);
43
- const selectedSubscriptions = subscribedObjects.filter((object) => agentObj.subscriptions.some((subscription) => subscription.uri === Obj.getURI(object)));
44
- return selectedSubscriptions;
45
- })), [
46
- agent,
47
- subscribedObjects
48
- ]));
49
- const handleSubscriptionChange = useCallback((object, checked) => {
50
- Obj.update(agent, (agent2) => {
51
- if (checked) {
52
- agent2.subscriptions.push(Ref.fromURI(Obj.getURI(object)));
53
- } else {
54
- agent2.subscriptions = agent2.subscriptions.filter((subscription) => subscription.uri !== Obj.getURI(object));
55
- }
56
- });
57
- }, [
58
- agent
59
- ]);
60
- if (subscribedObjects.length === 0) {
61
- return null;
62
- }
63
- return /* @__PURE__ */ React.createElement(Form.Section, null, /* @__PURE__ */ React.createElement(Input.Root, null, /* @__PURE__ */ React.createElement(Input.Label, {
64
- classNames: "mt-form-gap"
65
- }, t("subscriptions.label"))), subscribedObjects.map((object) => /* @__PURE__ */ React.createElement(Input.Root, {
66
- key: object.id
67
- }, /* @__PURE__ */ React.createElement("div", {
68
- className: "flex items-center gap-2"
69
- }, /* @__PURE__ */ React.createElement(Input.Checkbox, {
70
- checked: existingSubscriptions.includes(object),
71
- onCheckedChange: (checked) => {
72
- handleSubscriptionChange(object, checked === true);
73
- }
74
- }), /* @__PURE__ */ React.createElement(Input.Label, null, Obj.getLabel(object) ?? object.id)))));
75
- };
76
-
77
- // src/components/Chat/Chat.tsx
78
- import { Atom as Atom2 } from "@effect-atom/atom";
79
- import { useAtomValue as useAtomValue4 } from "@effect-atom/atom-react";
80
- import * as Array2 from "effect/Array";
81
- import * as Option3 from "effect/Option";
82
- import React17, { useCallback as useCallback9, useEffect as useEffect8, useMemo as useMemo10, useRef as useRef5, useState as useState7 } from "react";
83
- import { Event } from "@dxos/async";
84
- import { getSpace } from "@dxos/client/echo";
85
- import { Filter as Filter3, Obj as Obj4, Query } from "@dxos/echo";
86
- import { useObject as useObject3, useQuery as useQuery3 } from "@dxos/react-client/echo";
87
- import { useIdentity } from "@dxos/react-client/halo";
88
- import { Button, Toast, composable as composable2, composableProps as composableProps2, useTranslation as useTranslation10 } from "@dxos/react-ui";
89
- import { Menu } from "@dxos/react-ui-menu";
90
- import { Message as Message2 } from "@dxos/types";
91
- import { useChatKeymapExtensions as useChatKeymapExtensions2, useChatToolbarActions, useDebug, useTraceMessages } from "#hooks";
92
- import { meta as meta10 } from "#meta";
93
-
94
- // src/components/ChatPrompt/ChatActions.tsx
95
- import React2, { useCallback as useCallback2, useEffect, useState } from "react";
96
- import { useOptionalAtomCapabilityState, useOptionalCapabilities } from "@dxos/app-framework/ui";
97
- import { TranscriptionCapabilities } from "@dxos/plugin-transcription";
98
- import { DropdownMenu, Icon, IconButton, MicButton, useTranslation as useTranslation2 } from "@dxos/react-ui";
99
- import { mx } from "@dxos/ui-theme";
100
- import { meta as meta2 } from "#meta";
101
- var ChatActions = ({ classNames, children, docId, microphone, processing, debug, onEvent }) => {
102
- const { t } = useTranslation2(meta2.profile.key);
103
- const transcriptionAvailable = useOptionalCapabilities(TranscriptionCapabilities.RecordingSession).length > 0;
104
- const [session, setSession] = useOptionalAtomCapabilityState(TranscriptionCapabilities.RecordingSession);
105
- const [settings, setSettings] = useOptionalAtomCapabilityState(TranscriptionCapabilities.Settings);
106
- const recording = !!session?.recording && session.id === docId;
107
- const recordMode = settings?.recordMode ?? "toggle";
108
- const entityExtraction = settings?.entityExtraction !== false;
109
- const selectedDeviceId = settings?.audioDeviceId ?? "";
110
- const [devices, setDevices] = useState([]);
111
- useEffect(() => {
112
- if (!microphone || !transcriptionAvailable || !navigator.mediaDevices?.enumerateDevices) {
113
- return;
114
- }
115
- let cancelled = false;
116
- const refresh = async () => {
117
- const all = await navigator.mediaDevices.enumerateDevices();
118
- if (cancelled) {
119
- return;
120
- }
121
- setDevices(all.filter((device) => device.kind === "audioinput" && device.deviceId).map((device, index) => ({
122
- deviceId: device.deviceId,
123
- label: device.label || `Microphone ${index + 1}`
124
- })));
125
- };
126
- void refresh();
127
- navigator.mediaDevices.addEventListener("devicechange", refresh);
128
- return () => {
129
- cancelled = true;
130
- navigator.mediaDevices.removeEventListener("devicechange", refresh);
131
- };
132
- }, [
133
- microphone,
134
- transcriptionAvailable
135
- ]);
136
- const handleToggle = useCallback2(() => {
137
- if (!docId) {
138
- return;
139
- }
140
- setSession((current) => current?.recording && current.id === docId ? null : {
141
- id: docId,
142
- recording: true
143
- });
144
- }, [
145
- setSession,
146
- docId
147
- ]);
148
- const handlePressStart = useCallback2(() => {
149
- if (!docId) {
150
- return;
151
- }
152
- setSession(() => ({
153
- id: docId,
154
- recording: true
155
- }));
156
- }, [
157
- setSession,
158
- docId
159
- ]);
160
- const handlePressEnd = useCallback2(() => {
161
- setSession((current) => current?.id === docId ? null : current);
162
- }, [
163
- setSession,
164
- docId
165
- ]);
166
- const handleRecordModeChange = useCallback2((mode) => setSettings((current) => ({
167
- ...current,
168
- recordMode: mode
169
- })), [
170
- setSettings
171
- ]);
172
- const handleEntityExtractionChange = useCallback2((value2) => setSettings((current) => ({
173
- ...current,
174
- entityExtraction: value2
175
- })), [
176
- setSettings
177
- ]);
178
- const handleSelectDevice = useCallback2((deviceId) => setSettings((current) => ({
179
- ...current,
180
- audioDeviceId: deviceId || void 0
181
- })), [
182
- setSettings
183
- ]);
184
- const recordLabel = recording ? t("stop-recording.label") : recordMode === "hold" ? t("hold-to-record.label") : t("start-recording.label");
185
- return /* @__PURE__ */ React2.createElement("div", {
186
- className: mx("flex items-center", classNames)
187
- }, children, microphone && docId && transcriptionAvailable && /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(MicButton, {
188
- iconOnly: true,
189
- variant: "ghost",
190
- label: recordLabel,
191
- recording,
192
- mode: recordMode,
193
- onToggle: handleToggle,
194
- onPressStart: handlePressStart,
195
- onPressEnd: handlePressEnd,
196
- "data-testid": "assistant.record"
197
- }), /* @__PURE__ */ React2.createElement(DropdownMenu.Root, null, /* @__PURE__ */ React2.createElement(DropdownMenu.Trigger, {
198
- asChild: true
199
- }, /* @__PURE__ */ React2.createElement(IconButton, {
200
- icon: "ph--caret-down--regular",
201
- iconOnly: true,
202
- label: t("recording-options.label"),
203
- variant: "ghost",
204
- classNames: "w-4",
205
- "data-testid": "assistant.record.options"
206
- })), /* @__PURE__ */ React2.createElement(DropdownMenu.Portal, null, /* @__PURE__ */ React2.createElement(DropdownMenu.Content, null, /* @__PURE__ */ React2.createElement(DropdownMenu.Viewport, null, /* @__PURE__ */ React2.createElement(DropdownMenu.GroupLabel, null, t("record-mode.label")), /* @__PURE__ */ React2.createElement(SettingsSelectableItem, {
207
- label: t("record-mode.toggle.label"),
208
- selected: recordMode === "toggle",
209
- onSelect: () => handleRecordModeChange("toggle")
210
- }), /* @__PURE__ */ React2.createElement(SettingsSelectableItem, {
211
- label: t("record-mode.hold.label"),
212
- selected: recordMode === "hold",
213
- onSelect: () => handleRecordModeChange("hold")
214
- }), /* @__PURE__ */ React2.createElement(DropdownMenu.Separator, null), /* @__PURE__ */ React2.createElement(DropdownMenu.GroupLabel, null, t("audio-device.label")), /* @__PURE__ */ React2.createElement(SettingsSelectableItem, {
215
- label: t("audio-device.default.label"),
216
- selected: selectedDeviceId === "",
217
- onSelect: () => handleSelectDevice("")
218
- }), devices.map((device) => /* @__PURE__ */ React2.createElement(SettingsSelectableItem, {
219
- key: device.deviceId,
220
- label: device.label,
221
- selected: selectedDeviceId === device.deviceId,
222
- onSelect: () => handleSelectDevice(device.deviceId)
223
- })), /* @__PURE__ */ React2.createElement(DropdownMenu.Separator, null), /* @__PURE__ */ React2.createElement(DropdownMenu.CheckboxItem, {
224
- checked: entityExtraction,
225
- onCheckedChange: handleEntityExtractionChange,
226
- classNames: "gap-2",
227
- "data-testid": "assistant.entity-extraction"
228
- }, /* @__PURE__ */ React2.createElement("span", {
229
- className: "grow truncate"
230
- }, t("settings.entity-extraction.label")), /* @__PURE__ */ React2.createElement(DropdownMenu.ItemIndicator, {
231
- asChild: true
232
- }, /* @__PURE__ */ React2.createElement(Icon, {
233
- icon: "ph--check--regular",
234
- size: 4
235
- })))), /* @__PURE__ */ React2.createElement(DropdownMenu.Arrow, null))))), debug && /* @__PURE__ */ React2.createElement(IconButton, {
236
- variant: "ghost",
237
- icon: "ph--wrench--regular",
238
- iconOnly: true,
239
- label: t("debug.button"),
240
- onClick: () => onEvent?.({
241
- type: "toggle-debug"
242
- })
243
- }), /* @__PURE__ */ React2.createElement(IconButton, {
244
- // disabled={!processing} // TODO(dmaretskyi): Set processing state correctly on rehydrated agents.
245
- variant: "ghost",
246
- icon: "ph--x--regular",
247
- iconOnly: true,
248
- label: t("cancel-processing.button"),
249
- onClick: () => {
250
- onEvent?.({
251
- type: "cancel"
252
- });
253
- }
254
- }));
255
- };
256
- var SettingsSelectableItem = ({ label, selected, onSelect }) => /* @__PURE__ */ React2.createElement(DropdownMenu.Item, {
257
- classNames: "gap-2",
258
- role: "menuitemradio",
259
- "aria-checked": selected,
260
- onSelect
261
- }, /* @__PURE__ */ React2.createElement("span", {
262
- className: "grow truncate"
263
- }, label), selected && /* @__PURE__ */ React2.createElement(Icon, {
264
- icon: "ph--check--regular",
265
- size: 4
266
- }));
267
-
268
- // src/components/ChatPrompt/ChatMcpErrors.tsx
269
- import { useAtomValue as useAtomValue2 } from "@effect-atom/atom-react";
270
- import React3, { useCallback as useCallback3 } from "react";
271
- import { Message, useTranslation as useTranslation3 } from "@dxos/react-ui";
272
- import { meta as meta3 } from "#meta";
273
- var ChatMcpErrors = ({ classNames, processor }) => {
274
- const { t } = useTranslation3(meta3.profile.key);
275
- const errors = useAtomValue2(processor.mcpErrors);
276
- const handleDismiss = useCallback3(() => {
277
- processor.dismissMcpErrors();
278
- }, [
279
- processor
280
- ]);
281
- if (errors.length === 0) {
282
- return null;
283
- }
284
- return /* @__PURE__ */ React3.createElement(Message.Root, {
285
- classNames: [
286
- "m-1",
287
- classNames
288
- ],
289
- valence: "warning"
290
- }, /* @__PURE__ */ React3.createElement(Message.Title, {
291
- onClose: handleDismiss
292
- }, t("mcp-server-error.label")), /* @__PURE__ */ React3.createElement(Message.Content, {
293
- asChild: true
294
- }, /* @__PURE__ */ React3.createElement("ul", {
295
- className: "flex flex-col gap-0.5 text-sm"
296
- }, errors.map((error) => /* @__PURE__ */ React3.createElement("li", {
297
- key: `${error.url}::${error.protocol}`,
298
- className: "truncate"
299
- }, /* @__PURE__ */ React3.createElement("span", {
300
- className: "font-mono"
301
- }, error.url), " \u2014 ", /* @__PURE__ */ React3.createElement("span", null, error.message))))));
302
- };
303
-
304
- // src/components/ChatPrompt/ChatOptions.tsx
305
- import React4, { useCallback as useCallback4, useMemo as useMemo2, useState as useState2 } from "react";
306
- import { McpServer } from "@dxos/assistant-toolkit";
307
- import { Filter as Filter2, Obj as Obj2, Type as Type2 } from "@dxos/echo";
308
- import { useObject, useQuery as useQuery2 } from "@dxos/react-client/echo";
309
- import { IconButton as IconButton2, Input as Input2, Popover, Select, useTranslation as useTranslation4 } from "@dxos/react-ui";
310
- import { Listbox } from "@dxos/react-ui-list";
311
- import { SearchList, useSearchListResults } from "@dxos/react-ui-search";
312
- import { Tabs } from "@dxos/react-ui-tabs";
313
- import { getStyles, mx as mx2 } from "@dxos/ui-theme";
314
- import { useActiveSkills, useContextObjects, useFilteredTypes, useSkillHandlers, useSkills } from "#hooks";
315
- import { meta as meta4 } from "#meta";
316
- import { Assistant } from "#types";
317
- var styles = {
318
- panel: "w-[calc(100dvw-.5rem)] sm:w-max max-w-document-width",
319
- toolbar: "p-0! gap-0! border-t border-separator"
320
- };
321
- var ChatOptions = ({ chat, db, context, registry, presets, preset, onPresetChange }) => {
322
- const { t } = useTranslation4(meta4.profile.key);
323
- return /* @__PURE__ */ React4.createElement("div", {
324
- className: "flex"
325
- }, /* @__PURE__ */ React4.createElement(Popover.Root, null, /* @__PURE__ */ React4.createElement(Popover.Trigger, {
326
- asChild: true
327
- }, /* @__PURE__ */ React4.createElement(IconButton2, {
328
- variant: "ghost",
329
- icon: "ph--plus--regular",
330
- iconOnly: true,
331
- label: t("context-objects.button")
332
- })), /* @__PURE__ */ React4.createElement(Popover.Portal, null, /* @__PURE__ */ React4.createElement(Popover.Content, {
333
- side: "top",
334
- classNames: styles.panel
335
- }, /* @__PURE__ */ React4.createElement(Popover.Viewport, null, /* @__PURE__ */ React4.createElement(ObjectsPanel, {
336
- db,
337
- context
338
- })), /* @__PURE__ */ React4.createElement(Popover.Arrow, null)))), /* @__PURE__ */ React4.createElement(Popover.Root, null, /* @__PURE__ */ React4.createElement(Popover.Trigger, {
339
- asChild: true
340
- }, /* @__PURE__ */ React4.createElement(IconButton2, {
341
- variant: "ghost",
342
- icon: "ph--sliders-horizontal--regular",
343
- iconOnly: true,
344
- label: t("context-settings.button")
345
- })), /* @__PURE__ */ React4.createElement(Popover.Portal, null, /* @__PURE__ */ React4.createElement(Popover.Content, {
346
- side: "top",
347
- classNames: styles.panel
348
- }, /* @__PURE__ */ React4.createElement(Popover.Viewport, null, /* @__PURE__ */ React4.createElement(Tabs.Root, {
349
- asChild: true,
350
- orientation: "horizontal",
351
- defaultValue: "view",
352
- defaultActivePart: "list",
353
- tabIndex: -1
354
- }, /* @__PURE__ */ React4.createElement(Tabs.Viewport, {
355
- classNames: mx2("grid grid-rows-[1fr_40px] w-full")
356
- }, /* @__PURE__ */ React4.createElement(Tabs.Panel, {
357
- tabIndex: -1,
358
- classNames: "dx-focus-ring-inset overflow-hidden",
359
- value: "view"
360
- }, /* @__PURE__ */ React4.createElement(ViewPanel, {
361
- chat
362
- })), /* @__PURE__ */ React4.createElement(Tabs.Panel, {
363
- tabIndex: -1,
364
- classNames: "dx-focus-ring-inset overflow-hidden",
365
- value: "skills"
366
- }, /* @__PURE__ */ React4.createElement(SkillsPanel, {
367
- registry,
368
- db,
369
- context
370
- })), /* @__PURE__ */ React4.createElement(Tabs.Panel, {
371
- tabIndex: -1,
372
- classNames: "dx-focus-ring-inset overflow-hidden",
373
- value: "mcp-servers"
374
- }, /* @__PURE__ */ React4.createElement(McpServersPanel, {
375
- db
376
- })), /* @__PURE__ */ React4.createElement(Tabs.Panel, {
377
- tabIndex: -1,
378
- classNames: "dx-focus-ring-inset overflow-hidden",
379
- value: "model"
380
- }, /* @__PURE__ */ React4.createElement(ModelsPanel, {
381
- presets,
382
- preset,
383
- onPresetChange
384
- })), /* @__PURE__ */ React4.createElement(Tabs.Tablist, {
385
- classNames: [
386
- styles.toolbar
387
- ]
388
- }, /* @__PURE__ */ React4.createElement(Tabs.IconTab, {
389
- value: "view",
390
- icon: "ph--eye--regular",
391
- label: t("chat-view.title")
392
- }), /* @__PURE__ */ React4.createElement(Tabs.IconTab, {
393
- value: "skills",
394
- icon: "ph--blueprint--regular",
395
- label: t("options.skills.title")
396
- }), /* @__PURE__ */ React4.createElement(Tabs.IconTab, {
397
- value: "mcp-servers",
398
- icon: "ph--plugs-connected--regular",
399
- label: t("options.mcp.title")
400
- }), /* @__PURE__ */ React4.createElement(Tabs.IconTab, {
401
- value: "model",
402
- icon: "ph--cpu--regular",
403
- label: t("options.chat-model.title")
404
- }))))), /* @__PURE__ */ React4.createElement(Popover.Arrow, null)))));
405
- };
406
- var SkillsPanel = ({ registry, db, context }) => {
407
- const { t } = useTranslation4(meta4.profile.key);
408
- const skills = useSkills({
409
- registry,
410
- db
411
- });
412
- const activeSkills = useActiveSkills({
413
- context
414
- });
415
- const { onUpdateSkill } = useSkillHandlers({
416
- db,
417
- context,
418
- registry
419
- });
420
- const { results, handleSearch } = useSearchListResults({
421
- items: skills,
422
- extract: (skill) => skill.name
423
- });
424
- return /* @__PURE__ */ React4.createElement(SearchList.Root, {
425
- onSearch: handleSearch
426
- }, /* @__PURE__ */ React4.createElement(SearchList.Content, {
427
- classNames: "flex flex-col"
428
- }, /* @__PURE__ */ React4.createElement(SearchList.Viewport, null, results.map((skill) => {
429
- const skillKey = Obj2.getMeta(skill).key ?? skill.id;
430
- const isActive = activeSkills.has(skillKey);
431
- return /* @__PURE__ */ React4.createElement(SearchList.Item, {
432
- classNames: "flex items-center overflow-hidden",
433
- key: skillKey,
434
- value: skillKey,
435
- label: skill.name,
436
- checked: isActive,
437
- onSelect: () => onUpdateSkill?.(skillKey, !isActive)
438
- });
439
- })), /* @__PURE__ */ React4.createElement(SearchList.Input, {
440
- placeholder: t("search.placeholder"),
441
- classNames: "border-t border-separator",
442
- autoFocus: true
443
- })));
444
- };
445
- var ViewPanel = ({ chat }) => {
446
- const { t } = useTranslation4(meta4.profile.key);
447
- const [view, setView] = useObject(chat, "viewType");
448
- const value2 = view ?? "normal";
449
- return /* @__PURE__ */ React4.createElement(Listbox.Root, {
450
- value: value2,
451
- onValueChange: setView,
452
- autoFocus: true
453
- }, /* @__PURE__ */ React4.createElement(Listbox.Content, {
454
- "aria-label": t("chat-view.title")
455
- }, Assistant.ChatViews.map((view2) => /* @__PURE__ */ React4.createElement(Listbox.Item, {
456
- key: view2,
457
- id: view2,
458
- classNames: "px-2 py-1 dx-focus-ring rounded-xs"
459
- }, /* @__PURE__ */ React4.createElement(Listbox.ItemLabel, null, t(`chat-view.${view2}.label`, {
460
- defaultValue: view2
461
- })), /* @__PURE__ */ React4.createElement(Listbox.Indicator, null)))));
462
- };
463
- var ModelsPanel = ({ presets, preset, onPresetChange }) => {
464
- const { t } = useTranslation4(meta4.profile.key);
465
- return /* @__PURE__ */ React4.createElement(Listbox.Root, {
466
- value: preset,
467
- onValueChange: onPresetChange,
468
- autoFocus: true
469
- }, /* @__PURE__ */ React4.createElement(Listbox.Content, {
470
- "aria-label": t("options.chat-model.title")
471
- }, presets?.map(({ id, label }) => /* @__PURE__ */ React4.createElement(Listbox.Item, {
472
- key: id,
473
- id,
474
- classNames: "px-2 py-1 dx-focus-ring rounded-xs"
475
- }, /* @__PURE__ */ React4.createElement(Listbox.ItemLabel, null, label), /* @__PURE__ */ React4.createElement(Listbox.Indicator, null)))));
476
- };
477
- var McpServersPanel = ({ db }) => {
478
- const { t } = useTranslation4(meta4.profile.key);
479
- const servers = useQuery2(db, Filter2.type(McpServer.McpServer));
480
- const [adding, setAdding] = useState2(false);
481
- const handleAdd = useCallback4((name, url, protocol, apiKey) => {
482
- db.add(Obj2.make(McpServer.McpServer, {
483
- name,
484
- url,
485
- protocol,
486
- apiKey,
487
- enabled: true
488
- }));
489
- setAdding(false);
490
- }, [
491
- db
492
- ]);
493
- const handleRemove = useCallback4((server) => {
494
- db.remove(server);
495
- }, [
496
- db
497
- ]);
498
- return /* @__PURE__ */ React4.createElement("div", {
499
- className: "p-form-chrome"
500
- }, servers.map((server) => /* @__PURE__ */ React4.createElement(McpServerRow, {
501
- key: server.id,
502
- server,
503
- onRemove: handleRemove
504
- })), adding ? /* @__PURE__ */ React4.createElement(McpServerForm, {
505
- onSubmit: handleAdd,
506
- onCancel: () => setAdding(false)
507
- }) : /* @__PURE__ */ React4.createElement("div", null, /* @__PURE__ */ React4.createElement(IconButton2, {
508
- variant: "ghost",
509
- icon: "ph--plus--regular",
510
- label: t("mcp-server-add.label"),
511
- onClick: () => setAdding(true)
512
- })));
513
- };
514
- var McpServerRow = ({ server, onRemove }) => {
515
- const { t } = useTranslation4(meta4.profile.key);
516
- const [enabled, setEnabled] = useObject(server, "enabled");
517
- return /* @__PURE__ */ React4.createElement("div", {
518
- className: "flex items-center gap-2 px-form-chrome"
519
- }, /* @__PURE__ */ React4.createElement(Input2.Root, null, /* @__PURE__ */ React4.createElement(Input2.Label, {
520
- srOnly: true
521
- }, server.name), /* @__PURE__ */ React4.createElement(Input2.Switch, {
522
- checked: enabled !== false,
523
- onCheckedChange: (checked) => setEnabled(!!checked)
524
- })), /* @__PURE__ */ React4.createElement("span", {
525
- className: "flex-1 truncate text-sm"
526
- }, server.name), /* @__PURE__ */ React4.createElement("span", {
527
- className: "truncate text-xs text-description"
528
- }, server.url), /* @__PURE__ */ React4.createElement(IconButton2, {
529
- variant: "ghost",
530
- icon: "ph--x--regular",
531
- iconOnly: true,
532
- label: t("mcp-server-remove.label"),
533
- onClick: () => onRemove(server)
534
- }));
535
- };
536
- var McpServerForm = ({ onSubmit, onCancel }) => {
537
- const { t } = useTranslation4(meta4.profile.key);
538
- const [name, setName] = useState2("");
539
- const [url, setUrl] = useState2("");
540
- const [protocol, setProtocol] = useState2("sse");
541
- const [apiKey, setApiKey] = useState2("");
542
- const canSubmit = name.trim().length > 0 && url.trim().length > 0;
543
- const handleSubmit = useCallback4(() => {
544
- if (canSubmit) {
545
- onSubmit(name.trim(), url.trim(), protocol, apiKey.trim() || void 0);
546
- }
547
- }, [
548
- canSubmit,
549
- name,
550
- url,
551
- protocol,
552
- apiKey,
553
- onSubmit
554
- ]);
555
- return /* @__PURE__ */ React4.createElement("div", {
556
- className: "space-y-2 px-form-chrome"
557
- }, /* @__PURE__ */ React4.createElement(Input2.Root, null, /* @__PURE__ */ React4.createElement(Input2.Label, {
558
- srOnly: true
559
- }, t("mcp-server-name.label")), /* @__PURE__ */ React4.createElement(Input2.TextInput, {
560
- placeholder: t("mcp-server-name.placeholder"),
561
- value: name,
562
- onChange: (event) => setName(event.target.value),
563
- autoFocus: true
564
- })), /* @__PURE__ */ React4.createElement(Input2.Root, null, /* @__PURE__ */ React4.createElement(Input2.Label, {
565
- srOnly: true
566
- }, t("mcp-server-url.label")), /* @__PURE__ */ React4.createElement(Input2.TextInput, {
567
- placeholder: t("mcp-server-url.placeholder"),
568
- value: url,
569
- onChange: (event) => setUrl(event.target.value)
570
- })), /* @__PURE__ */ React4.createElement(Select.Root, {
571
- value: protocol,
572
- onValueChange: (value2) => setProtocol(value2)
573
- }, /* @__PURE__ */ React4.createElement(Select.TriggerButton, {
574
- placeholder: t("mcp-server-protocol.label")
575
- }), /* @__PURE__ */ React4.createElement(Select.Portal, null, /* @__PURE__ */ React4.createElement(Select.Content, null, /* @__PURE__ */ React4.createElement(Select.Viewport, null, /* @__PURE__ */ React4.createElement(Select.Option, {
576
- value: "sse"
577
- }, "SSE"), /* @__PURE__ */ React4.createElement(Select.Option, {
578
- value: "http"
579
- }, "HTTP"))))), /* @__PURE__ */ React4.createElement(Input2.Root, null, /* @__PURE__ */ React4.createElement(Input2.Label, {
580
- srOnly: true
581
- }, t("mcp-server-api-key.label")), /* @__PURE__ */ React4.createElement(Input2.TextInput, {
582
- type: "password",
583
- placeholder: t("mcp-server-api-key.placeholder"),
584
- value: apiKey,
585
- onChange: (event) => setApiKey(event.target.value)
586
- })), /* @__PURE__ */ React4.createElement("div", {
587
- className: "flex gap-2"
588
- }, /* @__PURE__ */ React4.createElement(IconButton2, {
589
- variant: "ghost",
590
- icon: "ph--check--regular",
591
- iconOnly: true,
592
- label: t("save.button"),
593
- onClick: handleSubmit,
594
- disabled: !canSubmit
595
- }), /* @__PURE__ */ React4.createElement(IconButton2, {
596
- variant: "ghost",
597
- icon: "ph--x--regular",
598
- iconOnly: true,
599
- label: t("cancel.button"),
600
- onClick: onCancel
601
- })));
602
- };
603
- var ANY = "__any__";
604
- var ObjectsPanel = ({ db, context }) => {
605
- const { t } = useTranslation4(meta4.profile.key);
606
- const types = useFilteredTypes(db);
607
- const typeOptions = useMemo2(() => {
608
- const options = types.map((type) => {
609
- const typename = Type2.getTypename(type);
610
- return {
611
- uri: Type2.getURI(type),
612
- label: t("typename.label", {
613
- ns: typename,
614
- defaultValue: typename
615
- })
616
- };
617
- });
618
- options.sort((a, b) => a.label.localeCompare(b.label));
619
- return options;
620
- }, [
621
- types,
622
- t
623
- ]);
624
- const [selectedUri, setSelectedUri] = useState2(ANY);
625
- const anyFilter = useMemo2(() => Filter2.or(...typeOptions.map(({ uri }) => Filter2.type(uri))), [
626
- typeOptions
627
- ]);
628
- const objects = useQuery2(db, selectedUri === ANY ? anyFilter : Filter2.type(selectedUri));
629
- const { objects: contextObjects, onUpdateObject } = useContextObjects({
630
- db,
631
- context
632
- });
633
- const { results, handleSearch } = useSearchListResults({
634
- items: objects,
635
- extract: (object) => Obj2.getLabel(object) ?? Obj2.getTypename(object) ?? object.id
636
- });
637
- return /* @__PURE__ */ React4.createElement(SearchList.Root, {
638
- onSearch: handleSearch
639
- }, /* @__PURE__ */ React4.createElement(SearchList.Content, {
640
- classNames: "p-form-chrome [&:has([cmdk-list-sizer]:empty)]:py-0"
641
- }, /* @__PURE__ */ React4.createElement(SearchList.Viewport, null, results.length ? results.map((object) => {
642
- const isActive = contextObjects.findIndex((obj) => obj.id === object.id) !== -1;
643
- const { icon, hue } = Obj2.getIcon(object) ?? {
644
- icon: "ph--cube--regular",
645
- hue: void 0
646
- };
647
- const styles3 = hue ? getStyles(hue) : void 0;
648
- return /* @__PURE__ */ React4.createElement(SearchList.Item, {
649
- classNames: "flex items-center overflow-hidden",
650
- key: object.id,
651
- value: object.id,
652
- icon,
653
- iconClassNames: styles3?.text,
654
- label: Obj2.getLabel(object) ?? Obj2.getTypename(object) ?? object.id,
655
- checked: isActive,
656
- onSelect: () => onUpdateObject?.(Obj2.getURI(object), !isActive)
657
- });
658
- }) : /* @__PURE__ */ React4.createElement(SearchList.Item, {
659
- value: "__empty__",
660
- label: t("no-results.message")
661
- }))), /* @__PURE__ */ React4.createElement("div", {
662
- className: mx2("flex flex-col", styles.toolbar)
663
- }, /* @__PURE__ */ React4.createElement(Select.Root, {
664
- value: selectedUri === ANY ? void 0 : selectedUri,
665
- onValueChange: (val) => setSelectedUri(val)
666
- }, /* @__PURE__ */ React4.createElement(Select.TriggerButton, {
667
- placeholder: t("type-filter.placeholder")
668
- }), /* @__PURE__ */ React4.createElement(Select.Portal, null, /* @__PURE__ */ React4.createElement(Select.Content, null, /* @__PURE__ */ React4.createElement(Select.ScrollUpButton, null), /* @__PURE__ */ React4.createElement(Select.Viewport, null, /* @__PURE__ */ React4.createElement(Select.Option, {
669
- value: ANY
670
- }, t("any-type-filter.label")), typeOptions.map(({ uri, label }) => /* @__PURE__ */ React4.createElement(Select.Option, {
671
- key: uri,
672
- value: uri
673
- }, label))), /* @__PURE__ */ React4.createElement(Select.ScrollDownButton, null), /* @__PURE__ */ React4.createElement(Select.Arrow, null)))), /* @__PURE__ */ React4.createElement(SearchList.Input, {
674
- placeholder: t("search.placeholder"),
675
- autoFocus: true
676
- })));
677
- };
678
-
679
- // src/components/ChatPrompt/ChatPresets.tsx
680
- import React5 from "react";
681
- import { Select as Select2 } from "@dxos/react-ui";
682
-
683
- // src/components/ChatPrompt/ChatPrompt.tsx
684
- import { useAtomValue as useAtomValue3 } from "@effect-atom/atom-react";
685
- import * as Option2 from "effect/Option";
686
- import React8, { useCallback as useCallback6, useEffect as useEffect4, useId, useMemo as useMemo4, useRef as useRef2 } from "react";
687
- import { Input as Input3, useDynamicRef, useTranslation as useTranslation7 } from "@dxos/react-ui";
688
- import { ChatEditor } from "@dxos/react-ui-chat";
689
- import { pendingText } from "@dxos/ui-editor";
690
- import { mx as mx5 } from "@dxos/ui-theme";
691
- import { useChatKeymapExtensions } from "#hooks";
692
- import { meta as meta7 } from "#meta";
693
-
694
- // src/components/ChatPrompt/ChatReferences.tsx
695
- import React6 from "react";
696
- import { Obj as Obj3 } from "@dxos/echo";
697
- import { Icon as Icon2, IconButton as IconButton3, toLocalizedString, useTranslation as useTranslation5 } from "@dxos/react-ui";
698
- import { getStyles as getStyles2, mx as mx3 } from "@dxos/ui-theme";
699
- import { useContextObjects as useContextObjects2 } from "#hooks";
700
- import { meta as meta5 } from "#meta";
701
- var ChatReferences = ({ classNames, context, db }) => {
702
- const { t } = useTranslation5(meta5.profile.key);
703
- const { objects, onUpdateObject } = useContextObjects2({
704
- db,
705
- context
706
- });
707
- return /* @__PURE__ */ React6.createElement("ul", {
708
- className: mx3("flex", classNames)
709
- }, objects.map((obj) => {
710
- const uri = Obj3.getURI(obj);
711
- const typename = Obj3.getTypename(obj);
712
- const label = Obj3.getLabel(obj) ?? (typename ? [
713
- "object-name.placeholder",
714
- {
715
- ns: typename
716
- }
717
- ] : obj.id);
718
- const { icon, hue } = Obj3.getIcon(obj) ?? {
719
- icon: DEFAULT_OBJECT_ICON,
720
- hue: void 0
721
- };
722
- const styles3 = hue ? getStyles2(hue) : void 0;
723
- return /* @__PURE__ */ React6.createElement("li", {
724
- key: uri.toString(),
725
- className: "dx-tag py-0 flex items-center gap-1",
726
- "data-hue": "neutral"
727
- }, /* @__PURE__ */ React6.createElement(Icon2, {
728
- icon,
729
- size: 4
730
- }), toLocalizedString(label, t), /* @__PURE__ */ React6.createElement(IconButton3, {
731
- icon: "ph--x--bold",
732
- iconOnly: true,
733
- variant: "ghost",
734
- label: t("remove-object.label"),
735
- classNames: "p-0 hover:bg-transparent",
736
- size: 3,
737
- onClick: () => onUpdateObject?.(uri, false)
738
- }));
739
- }));
740
- };
741
- var DEFAULT_OBJECT_ICON = "ph--cube--regular";
742
-
743
- // src/components/ChatPrompt/ChatStatusIndicator.tsx
744
- import React7, { useEffect as useEffect2, useState as useState3 } from "react";
745
- import { Tooltip, useTimeout } from "@dxos/react-ui";
746
- import { Spinner } from "@dxos/react-ui-components";
747
- import { mx as mx4 } from "@dxos/ui-theme";
748
- var period = 3e3;
749
- var ChatStatusIndicator = ({ classNames, preset, processing, error, ...props }) => {
750
- const [init, setInit] = useState3(false);
751
- useEffect2(() => setInit(false), [
752
- preset
753
- ]);
754
- useTimeout(async () => {
755
- setInit(true);
756
- }, period / 2, [
757
- preset
758
- ]);
759
- return /* @__PURE__ */ React7.createElement("div", {
760
- className: mx4("relative flex", classNames)
761
- }, /* @__PURE__ */ React7.createElement(Spinner, {
762
- duration: period,
763
- state: !init ? "flash" : error ? "error" : processing ? "spin" : "pulse",
764
- ...props
765
- }), error && /* @__PURE__ */ React7.createElement(Tooltip.Trigger, {
766
- asChild: true,
767
- content: error.message
768
- }, /* @__PURE__ */ React7.createElement("div", {
769
- className: "absolute inset-0"
770
- })));
771
- };
772
-
773
- // src/components/ChatPrompt/useChatVoiceInput.ts
774
- import { useCallback as useCallback5, useEffect as useEffect3, useMemo as useMemo3, useRef } from "react";
775
- import { useOptionalAtomCapabilityState as useOptionalAtomCapabilityState2 } from "@dxos/app-framework/ui";
776
- import { TranscriptionCapabilities as TranscriptionCapabilities2 } from "@dxos/plugin-transcription/types";
777
- import { useTranslation as useTranslation6 } from "@dxos/react-ui";
778
- import { useAudioTrack, useTranscriber } from "@dxos/react-ui-transcription";
779
- import { PendingTextStreamer, cancelPendingText, editorPendingTextSink, pendingTextState } from "@dxos/ui-editor";
780
- import { meta as meta6 } from "#meta";
781
- var RECORDER_INTERVAL_MS = 200;
782
- var useChatVoiceInput = (docId, editorRef) => {
783
- const { t } = useTranslation6(meta6.profile.key);
784
- const [session] = useOptionalAtomCapabilityState2(TranscriptionCapabilities2.RecordingSession);
785
- const [settings] = useOptionalAtomCapabilityState2(TranscriptionCapabilities2.Settings);
786
- const active = !!session?.recording && session.id === docId;
787
- const streamerRef = useRef(null);
788
- useEffect3(() => {
789
- if (!active) {
790
- return;
791
- }
792
- const view = editorRef.current?.view;
793
- if (!view) {
794
- return;
795
- }
796
- const streamer = new PendingTextStreamer(editorPendingTextSink(view), {
797
- mode: settings?.streamMode ?? "word",
798
- wordIntervalMs: settings?.wordIntervalMs ?? 80
799
- });
800
- streamer.start({
801
- anchor: view.state.selection.main.head,
802
- placeholder: t("recording.placeholder")
803
- });
804
- streamerRef.current = streamer;
805
- return () => {
806
- streamer.dispose();
807
- streamerRef.current = null;
808
- const currentView = editorRef.current?.view;
809
- if (currentView) {
810
- const pending = currentView.state.field(pendingTextState, false);
811
- if (pending && pending.final.length === 0) {
812
- currentView.dispatch({
813
- effects: cancelPendingText.of()
814
- });
815
- }
816
- }
817
- };
818
- }, [
819
- active,
820
- settings?.streamMode,
821
- settings?.wordIntervalMs
822
- ]);
823
- const handleSegments = useCallback5(async (segments) => {
824
- const text = segments.map((segment) => segment.text).join(" ").trim();
825
- if (text.length > 0) {
826
- streamerRef.current?.push(text);
827
- }
828
- }, []);
829
- const transcriberConfig = useMemo3(() => ({
830
- transcribeAfterChunksAmount: Math.max(1, Math.round((settings?.transcribeAfterMs ?? 4e3) / RECORDER_INTERVAL_MS))
831
- }), [
832
- settings?.transcribeAfterMs
833
- ]);
834
- const recorderConfig = useMemo3(() => ({
835
- interval: RECORDER_INTERVAL_MS
836
- }), []);
837
- const audioConstraints = useMemo3(() => settings?.audioDeviceId ? {
838
- deviceId: {
839
- exact: settings.audioDeviceId
840
- }
841
- } : void 0, [
842
- settings?.audioDeviceId
843
- ]);
844
- const track = useAudioTrack(active, audioConstraints);
845
- useTranscriber({
846
- audioStreamTrack: track,
847
- transcriberConfig,
848
- recorderConfig,
849
- onSegments: handleSegments
850
- });
851
- };
852
-
853
- // src/components/ChatPrompt/ChatPrompt.tsx
854
- var ChatPrompt = ({ classNames, outline, db, chat, processor, event, online, placeholder, onPresetChange, settings = true, presets, preset }) => {
855
- const { t } = useTranslation7(meta7.profile.key);
856
- const error = useAtomValue3(processor.error).pipe(Option2.getOrUndefined);
857
- const streaming = useAtomValue3(processor.streaming);
858
- const active = useAtomValue3(processor.active);
859
- const activeRef = useDynamicRef(active);
860
- const editorRef = useRef2(null);
861
- useEffect4(() => {
862
- return event.on((ev) => {
863
- if (ev.type === "update-prompt" && !editorRef.current?.getText()?.length) {
864
- editorRef.current?.setText(ev.text);
865
- editorRef.current?.focus();
866
- }
867
- });
868
- }, [
869
- event
870
- ]);
871
- const fallbackDocId = useId();
872
- const docId = chat?.id ?? fallbackDocId;
873
- useChatVoiceInput(docId, editorRef);
874
- const keymapExtensions = useChatKeymapExtensions({
875
- event
876
- });
877
- const extensions = useMemo4(() => [
878
- keymapExtensions,
879
- pendingText()
880
- ], [
881
- keymapExtensions
882
- ]);
883
- const handleSubmit = useCallback6((text) => {
884
- if (!activeRef.current) {
885
- event.emit({
886
- type: "submit",
887
- text
888
- });
889
- return true;
890
- }
891
- }, [
892
- event
893
- ]);
894
- const handleEvent = useCallback6((ev) => {
895
- event.emit(ev);
896
- }, [
897
- event
898
- ]);
899
- return /* @__PURE__ */ React8.createElement("div", {
900
- role: "group",
901
- className: mx5("flex flex-col w-full dx-density-md", outline && "bg-group-surface rounded-sm border border-subdued-separator transition transition-border [&:has(.cm-content:focus)]:border-separator", classNames)
902
- }, /* @__PURE__ */ React8.createElement(ChatMcpErrors, {
903
- processor
904
- }), /* @__PURE__ */ React8.createElement("div", {
905
- className: "flex p-2 gap-2"
906
- }, /* @__PURE__ */ React8.createElement(ChatStatusIndicator, {
907
- classNames: "p-1",
908
- preset,
909
- error,
910
- processing: streaming
911
- }), /* @__PURE__ */ React8.createElement(ChatEditor, {
912
- ref: editorRef,
913
- autoFocus: true,
914
- lineWrapping: true,
915
- classNames: "col-span-2 pt-0.5",
916
- placeholder: placeholder ?? t("prompt.placeholder"),
917
- extensions,
918
- onSubmit: handleSubmit
919
- })), db && settings && /* @__PURE__ */ React8.createElement("div", {
920
- className: "flex items-center overflow-hidden p-1.5"
921
- }, /* @__PURE__ */ React8.createElement(ChatOptions, {
922
- chat,
923
- db,
924
- registry: processor.registry,
925
- context: processor.context,
926
- preset,
927
- presets,
928
- onPresetChange
929
- }), /* @__PURE__ */ React8.createElement("div", {
930
- className: "flex h-6 grow overflow-x-auto scrollbar-none"
931
- }, /* @__PURE__ */ React8.createElement(ChatReferences, {
932
- db,
933
- context: processor.context
934
- })), /* @__PURE__ */ React8.createElement(ChatActions, {
935
- classNames: "col-span-2",
936
- microphone: true,
937
- docId,
938
- processing: streaming,
939
- onEvent: handleEvent
940
- }, online !== void 0 && /* @__PURE__ */ React8.createElement(Input3.Root, null, /* @__PURE__ */ React8.createElement(Input3.Label, {
941
- srOnly: true
942
- }, t("online-switch.label")), /* @__PURE__ */ React8.createElement(Input3.Switch, {
943
- classNames: "mx-1",
944
- checked: online,
945
- disabled: true
946
- })))));
947
- };
948
- ChatPrompt.displayName = "Chat.Prompt";
949
-
950
- // src/components/ChatPrompt/ChatStatus.tsx
951
- import React9, { useEffect as useEffect5, useMemo as useMemo5, useState as useState4 } from "react";
952
- import { ChatStatus as NaturalChatStatus, formatElapsed } from "@dxos/react-ui-chat";
953
- import { Matrix } from "@dxos/react-ui-components";
954
- import { Unit } from "@dxos/util";
955
- var CHAT_STREAM_STATUS_NAME = "Chat.StreamStatus";
956
- var TICK_MS = 1e3;
957
- var ChatStatus = ({ classNames, icon }) => {
958
- const { messages, requestTiming } = useChatContext(CHAT_STREAM_STATUS_NAME);
959
- const { lastOutputTokens, sessionTotalTokens } = useMemo5(() => {
960
- let last;
961
- let total = 0;
962
- for (const message of messages) {
963
- for (const block of message.blocks) {
964
- if (isStats(block) && block.usage) {
965
- last = block.usage.outputTokens;
966
- total += block.usage.totalTokens ?? 0;
967
- }
968
- }
969
- }
970
- return {
971
- lastOutputTokens: last,
972
- sessionTotalTokens: total
973
- };
974
- }, [
975
- messages
976
- ]);
977
- const isRunning = requestTiming != null && requestTiming.endedAt == null;
978
- const show = requestTiming || lastOutputTokens || sessionTotalTokens > 0;
979
- if (!show) {
980
- return null;
981
- }
982
- return /* @__PURE__ */ React9.createElement(NaturalChatStatus.Root, {
983
- defaultRunning: false,
984
- classNames: [
985
- "py-2 gap-2 text-sm",
986
- classNames
987
- ]
988
- }, icon && /* @__PURE__ */ React9.createElement(NaturalChatStatus.Icon, null, /* @__PURE__ */ React9.createElement(Matrix, {
989
- classNames: "w-5 h-5",
990
- dotClassNames: "bg-primary-500",
991
- dim: 4,
992
- dotSize: 3,
993
- count: 10,
994
- interval: 500,
995
- active: isRunning
996
- })), show && /* @__PURE__ */ React9.createElement("div", {
997
- className: "flex items-center"
998
- }, requestTiming && /* @__PURE__ */ React9.createElement(NaturalChatStatus.Text, null, /* @__PURE__ */ React9.createElement(Elapsed, {
999
- timing: requestTiming
1000
- })), lastOutputTokens != null && /* @__PURE__ */ React9.createElement(React9.Fragment, null, requestTiming && /* @__PURE__ */ React9.createElement(NaturalChatStatus.Separator, null), /* @__PURE__ */ React9.createElement(NaturalChatStatus.Text, null, "\u2193 ", Unit.Thousand(lastOutputTokens).toString())), sessionTotalTokens > 0 && /* @__PURE__ */ React9.createElement(React9.Fragment, null, (requestTiming || lastOutputTokens != null) && /* @__PURE__ */ React9.createElement(NaturalChatStatus.Separator, null), /* @__PURE__ */ React9.createElement(NaturalChatStatus.Text, null, "\u03A3 ", Unit.Thousand(sessionTotalTokens).toString()))));
1001
- };
1002
- var Elapsed = ({ timing }) => {
1003
- const isRunning = timing.endedAt == null;
1004
- const [now, setNow] = useState4(Date.now());
1005
- useEffect5(() => {
1006
- if (!isRunning) {
1007
- return;
1008
- }
1009
- const id = setInterval(() => setNow(Date.now()), TICK_MS);
1010
- return () => clearInterval(id);
1011
- }, [
1012
- isRunning
1013
- ]);
1014
- return /* @__PURE__ */ React9.createElement(React9.Fragment, null, formatElapsed((timing.endedAt ?? now) - timing.startedAt));
1015
- };
1016
- var isStats = (block) => block._tag === "stats";
1017
-
1018
- // src/components/ChatThread/ChatThread.tsx
1019
- import React15, { forwardRef, useCallback as useCallback8, useEffect as useEffect7, useMemo as useMemo8, useRef as useRef4, useState as useState6 } from "react";
1020
- import { PublicKey } from "@dxos/keys";
1021
- import { setRef } from "@dxos/react-ui";
1022
- import { MarkdownStream } from "@dxos/react-ui-markdown";
1023
- import { keyToFallback } from "@dxos/util";
1024
-
1025
- // src/components/ChatThread/registry.tsx
1026
- import React14 from "react";
1027
- import { log as log2 } from "@dxos/log";
1028
- import { AnchorWidget, getXmlTextChild as getXmlTextChild2 } from "@dxos/ui-editor";
1029
-
1030
- // src/components/ChatThread/tool-widget-state.ts
1031
- var applyToolBlockToWidgetState = (context, block) => {
1032
- switch (block._tag) {
1033
- case "toolCall": {
1034
- context.updateWidget(block.toolCallId, {
1035
- blocks: [
1036
- block
1037
- ]
1038
- });
1039
- break;
1040
- }
1041
- case "toolResult": {
1042
- context.updateWidget(block.toolCallId, ({ blocks = [] } = {
1043
- blocks: []
1044
- }) => ({
1045
- blocks: [
1046
- ...blocks,
1047
- block
1048
- ]
1049
- }));
1050
- break;
1051
- }
1052
- default: {
1053
- break;
1054
- }
1055
- }
1056
- };
1057
- var rehydrateToolWidgetsFromMessages = (context, messages) => {
1058
- for (const message of messages) {
1059
- for (const block of message.blocks) {
1060
- applyToolBlockToWidgetState(context, block);
1061
- }
1062
- }
1063
- };
1064
-
1065
- // src/components/ChatThread/widgets/FallbackWidget.tsx
1066
- import React10 from "react";
1067
- import { TogglePanel } from "@dxos/react-ui-components";
1068
- import { JsonHighlighter } from "@dxos/react-ui-syntax-highlighter";
1069
- var FallbackWidget = ({ _tag, ...props }) => {
1070
- return /* @__PURE__ */ React10.createElement(TogglePanel.Root, null, /* @__PURE__ */ React10.createElement(TogglePanel.Content, null, /* @__PURE__ */ React10.createElement(TogglePanel.Header, {
1071
- classNames: "bg-group-surface"
1072
- }, _tag), /* @__PURE__ */ React10.createElement(TogglePanel.Body, {
1073
- classNames: "bg-modal-surface"
1074
- }, /* @__PURE__ */ React10.createElement(TogglePanel.Viewport, null, /* @__PURE__ */ React10.createElement(JsonHighlighter, {
1075
- classNames: "p-2! text-sm",
1076
- data: props
1077
- })))));
1078
- };
1079
- FallbackWidget.displayName = "Fallback";
1080
-
1081
- // src/components/ChatThread/widgets/ReasoningWidget.ts
1082
- import { WidgetType } from "@codemirror/view";
1083
- import { Domino } from "@dxos/ui";
1084
-
1085
- // src/components/ChatThread/widgets/defaults.ts
1086
- var styles2 = {
1087
- padding: "my-4",
1088
- border: "border border-subdued-separator rounded-sm"
1089
- };
1090
-
1091
- // src/components/ChatThread/widgets/ReasoningWidget.ts
1092
- var ReasoningWidget = class extends WidgetType {
1093
- text;
1094
- #pos;
1095
- /** The timer id last registered for this instance (may differ from the map if superseded). */
1096
- #ownedTimerId = null;
1097
- constructor(text, pos) {
1098
- super(), this.text = text;
1099
- this.#pos = pos === void 0 || pos === "" ? "reasoning" : String(pos);
1100
- }
1101
- eq(other) {
1102
- return this.text === other.text && this.#pos === other.#pos;
1103
- }
1104
- toDOM() {
1105
- return Domino.of("div").classNames(styles2.padding).append(Domino.of("div").classNames("relative overflow-hidden p-px", styles2.border).attributes({
1106
- "data-trail-container": ""
1107
- }).append(Domino.of("div").classNames("relative z-10 bg-base-surface rounded-sm text-sm text-subdued py-1", "grid grid-cols-[24px_1fr] gap-x-0.5 items-start").append(Domino.of("div").classNames("flex h-5 w-full shrink-0 items-center justify-center self-start").append(Domino.svg("ph--brain--regular").classNames("shrink-0 size-4 opacity-70")), Domino.of("div").classNames("px-2 max-h-[5lh] overflow-y-auto dx-scrollbar-thin min-w-0").text(this.text).attributes({
1108
- "data-reasoning-text": ""
1109
- })), Domino.of("div").attributes({
1110
- "data-id": this.#pos
1111
- }))).root;
1112
- }
1113
- updateDOM(dom) {
1114
- dom.querySelector("[data-reasoning-text]")?.replaceChildren(this.text);
1115
- const container = dom.querySelector("[data-trail-container]");
1116
- let trailHost = container?.querySelector("[data-id]");
1117
- if (container && !trailHost) {
1118
- trailHost = Domino.of("div").attributes({
1119
- "data-id": this.#pos
1120
- }).root;
1121
- container.append(trailHost);
1122
- }
1123
- if (trailHost?.childElementCount === 0) {
1124
- trailHost.append(...createTrailLayers());
1125
- }
1126
- this.#scheduleTrailRemoval(dom);
1127
- return true;
1128
- }
1129
- destroy(_dom) {
1130
- this.#clearOwnedTrailTimer();
1131
- }
1132
- #scheduleTrailRemoval(dom) {
1133
- const previous = trailRemovalTimers.get(this.#pos);
1134
- if (previous !== void 0) {
1135
- clearTimeout(previous);
1136
- }
1137
- const timerId = setTimeout(() => {
1138
- if (trailRemovalTimers.get(this.#pos) !== timerId) {
1139
- return;
1140
- }
1141
- trailRemovalTimers.delete(this.#pos);
1142
- this.#ownedTimerId = null;
1143
- dom.querySelector("[data-id]")?.remove();
1144
- }, TRAIL_REMOVAL_DELAY_MS);
1145
- trailRemovalTimers.set(this.#pos, timerId);
1146
- this.#ownedTimerId = timerId;
1147
- }
1148
- #clearOwnedTrailTimer() {
1149
- const active = trailRemovalTimers.get(this.#pos);
1150
- if (active !== void 0 && active === this.#ownedTimerId) {
1151
- clearTimeout(active);
1152
- trailRemovalTimers.delete(this.#pos);
1153
- }
1154
- this.#ownedTimerId = null;
1155
- }
1156
- };
1157
- var trail = [
1158
- "absolute z-0 aspect-[2/1] w-16",
1159
- "bg-[radial-gradient(at_100%_50%,_theme(colors.green.700),_transparent_80%)]",
1160
- "[offset-anchor:100%_50%] [offset-path:border-box]"
1161
- ];
1162
- var TRAIL_REMOVAL_DELAY_MS = 1e3;
1163
- var trailRemovalTimers = /* @__PURE__ */ new Map();
1164
- var createTrailLayers = () => [
1165
- Domino.of("div").classNames(...trail, "animate-trail").root,
1166
- Domino.of("div").classNames(...trail, "animate-trail-offset").root
1167
- ];
1168
-
1169
- // src/components/ChatThread/widgets/ReferenceWidget.ts
1170
- import { WidgetType as WidgetType2 } from "@codemirror/view";
1171
- import { Domino as Domino2 } from "@dxos/ui";
1172
- var ReferenceWidget = class extends WidgetType2 {
1173
- text;
1174
- dxn;
1175
- constructor(text, dxn) {
1176
- super(), this.text = text, this.dxn = dxn;
1177
- }
1178
- eq(other) {
1179
- return this.dxn === other.dxn;
1180
- }
1181
- toDOM() {
1182
- return Domino2.of("div").classNames(styles2.padding).append(Domino2.of("dx-anchor").classNames("dx-tag--anchor").attributes({
1183
- dxn: this.dxn
1184
- }).text(this.text)).root;
1185
- }
1186
- };
1187
-
1188
- // src/components/ChatThread/widgets/SelectWidget.ts
1189
- import { WidgetType as WidgetType3 } from "@codemirror/view";
1190
- import { Domino as Domino3 } from "@dxos/ui";
1191
- var SelectWidget = class extends WidgetType3 {
1192
- options;
1193
- constructor(options) {
1194
- super(), this.options = options;
1195
- }
1196
- eq(other) {
1197
- return JSON.stringify(this.options) === JSON.stringify(other.options);
1198
- }
1199
- /**
1200
- * NOTE: Container must set var based on user's identity.
1201
- */
1202
- toDOM() {
1203
- return Domino3.of("div").attributes({
1204
- role: "group"
1205
- }).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({
1206
- "data-action": "submit",
1207
- "data-value": option,
1208
- "data-density": "md"
1209
- }).text(option))).root;
1210
- }
1211
- };
1212
-
1213
- // src/components/ChatThread/widgets/StatsWidget.ts
1214
- import { WidgetType as WidgetType4 } from "@codemirror/view";
1215
- import { Domino as Domino4 } from "@dxos/ui";
1216
- var StatsWidget = class extends WidgetType4 {
1217
- text;
1218
- constructor(text) {
1219
- super(), this.text = text;
1220
- }
1221
- eq(other) {
1222
- return this.text === other.text;
1223
- }
1224
- toDOM() {
1225
- return Domino4.of("div").classNames(styles2.padding, "text-sm text-placeholder").text(this.text).root;
1226
- }
1227
- updateDOM(dom) {
1228
- dom.textContent = this.text;
1229
- return true;
1230
- }
1231
- };
1232
-
1233
- // src/components/ChatThread/widgets/StatusWidget.ts
1234
- import { WidgetType as WidgetType5 } from "@codemirror/view";
1235
- import { Domino as Domino5 } from "@dxos/ui";
1236
- var StatusWidget = class extends WidgetType5 {
1237
- text;
1238
- constructor(text) {
1239
- super(), this.text = text;
1240
- }
1241
- eq(other) {
1242
- return this.text === other.text;
1243
- }
1244
- toDOM() {
1245
- 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.svg("ph--info--regular").classNames("shrink-0 size-4 opacity-70")), Domino5.of("div").classNames("relative min-w-0").append(Domino5.of("div").classNames("relative z-10 rounded-sm text-sm leading-5").attributes({
1246
- "data-status-text": ""
1247
- }).text(this.text))))).root;
1248
- }
1249
- updateDOM(dom) {
1250
- dom.querySelector("[data-status-text]")?.replaceChildren(this.text);
1251
- return true;
1252
- }
1253
- };
1254
-
1255
- // src/components/ChatThread/widgets/SummaryWidget.tsx
1256
- import React11 from "react";
1257
- import { useTranslation as useTranslation8 } from "@dxos/react-ui";
1258
- import { TogglePanel as TogglePanel2 } from "@dxos/react-ui-components";
1259
- import { meta as meta8 } from "#meta";
1260
- var SummaryWidget = ({ children }) => {
1261
- const { t } = useTranslation8(meta8.profile.key);
1262
- return /* @__PURE__ */ React11.createElement(TogglePanel2.Root, null, /* @__PURE__ */ React11.createElement(TogglePanel2.Content, {
1263
- classNames: styles2.border
1264
- }, /* @__PURE__ */ React11.createElement(TogglePanel2.Header, {
1265
- classNames: "text-sm bg-group-surface"
1266
- }, t("summary.label")), /* @__PURE__ */ React11.createElement(TogglePanel2.Body, null, /* @__PURE__ */ React11.createElement("div", {
1267
- className: "p-1 text-sm text-subdued"
1268
- }, children))));
1269
- };
1270
-
1271
- // src/components/ChatThread/widgets/SurfaceWidget.tsx
1272
- import React12, { useMemo as useMemo6 } from "react";
1273
- import { Surface } from "@dxos/app-framework/ui";
1274
- import { log } from "@dxos/log";
1275
- import { getXmlTextChild } from "@dxos/ui-editor";
1276
- import { ChatSurface } from "#types";
1277
- var __dxlog_file = "/__w/dxos/dxos/packages/plugins/plugin-assistant/src/components/ChatThread/widgets/SurfaceWidget.tsx";
1278
- var SurfaceWidget = ({ role, children }) => {
1279
- const data = useMemo6(() => {
1280
- const raw = getXmlTextChild(children ?? []);
1281
- if (!raw) {
1282
- return void 0;
1283
- }
1284
- try {
1285
- const parsed = JSON.parse(raw);
1286
- return parsed != null && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : void 0;
1287
- } catch (err) {
1288
- log.warn("failed to parse surface data", {
1289
- raw,
1290
- err
1291
- }, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 24, S: void 0 });
1292
- return void 0;
1293
- }
1294
- }, [
1295
- children
1296
- ]);
1297
- if (!role) {
1298
- return null;
1299
- }
1300
- return /* @__PURE__ */ React12.createElement(Surface.Surface, {
1301
- type: ChatSurface,
1302
- data: {
1303
- role,
1304
- data
1305
- },
1306
- limit: 1
1307
- });
1308
- };
1309
-
1310
- // src/components/ChatThread/widgets/SuggestionWidget.ts
1311
- import { WidgetType as WidgetType6 } from "@codemirror/view";
1312
- import { Domino as Domino6, mx as mx6 } from "@dxos/ui";
1313
- var SuggestionWidget = class extends WidgetType6 {
1314
- text;
1315
- constructor(text) {
1316
- super(), this.text = text;
1317
- }
1318
- eq(other) {
1319
- return this.text === other.text;
1320
- }
1321
- toDOM() {
1322
- return Domino6.of("span").classNames(mx6("inline-flex max-w-[calc(100cqi-8px)] my-1 pe-2 overflow-hidden")).append(Domino6.of("button").attributes({
1323
- "data-action": "submit",
1324
- "data-density": "md",
1325
- "data-value": this.text
1326
- }).classNames(mx6("dx-button gap-2 w-full overflow-hidden")).append(Domino6.of("dx-icon").attributes({
1327
- icon: "ph--lightning--regular"
1328
- }), Domino6.of("span").classNames("flex-1 truncate min-w-0").text(this.text))).root;
1329
- }
1330
- };
1331
-
1332
- // src/components/ChatThread/widgets/ToolWidget.tsx
1333
- import React13, { useCallback as useCallback7, useEffect as useEffect6, useMemo as useMemo7, useRef as useRef3, useState as useState5 } from "react";
1334
- import { Icon as Icon3, useTranslation as useTranslation9 } from "@dxos/react-ui";
1335
- import { NumericTabs, TextCrawl, TogglePanel as TogglePanel3 } from "@dxos/react-ui-components";
1336
- import { JsonHighlighter as JsonHighlighter2 } from "@dxos/react-ui-syntax-highlighter";
1337
- import { isNonNullable, safeParseJson } from "@dxos/util";
1338
- import { meta as meta9 } from "#meta";
1339
- var ToolWidget = ({ view, blocks = [] }) => {
1340
- const { t } = useTranslation9(meta9.profile.key);
1341
- const items = useMemo7(() => {
1342
- let lastToolCall;
1343
- const tools = [];
1344
- return blocks.filter((block) => block._tag === "toolCall" || block._tag === "toolResult" || block._tag === "stats").map((block) => {
1345
- switch (block._tag) {
1346
- case "toolCall": {
1347
- if (block.pending && lastToolCall?.block.toolCallId === block.toolCallId) {
1348
- return null;
1349
- }
1350
- const tool = tools.find((tool2) => tool2.name === block.name);
1351
- lastToolCall = {
1352
- tool,
1353
- block
1354
- };
1355
- return {
1356
- title: tool?.description ?? [
1357
- t("tool-call.label"),
1358
- block.name
1359
- ].filter(Boolean).join(" "),
1360
- icon: block.operationIcon,
1361
- content: {
1362
- ...block,
1363
- input: safeParseJson(block.input)
1364
- }
1365
- };
1366
- }
1367
- case "toolResult": {
1368
- if (block.error) {
1369
- return {
1370
- title: t("tool-error.label"),
1371
- icon: lastToolCall?.block.operationIcon,
1372
- content: block
1373
- };
1374
- }
1375
- const title = lastToolCall?.tool?.description ?? [
1376
- t("tool-result.label"),
1377
- lastToolCall?.block.name
1378
- ].filter(Boolean).join(" ");
1379
- const icon = lastToolCall?.block.operationIcon;
1380
- lastToolCall = void 0;
1381
- return {
1382
- title,
1383
- icon,
1384
- content: {
1385
- ...block,
1386
- result: typeof block.result === "string" ? safeParseJson(block.result) : block.result
1387
- }
1388
- };
1389
- }
1390
- case "stats": {
1391
- if (!lastToolCall) {
1392
- return null;
1393
- }
1394
- return {
1395
- title: t("stats.label"),
1396
- icon: lastToolCall.block.operationIcon,
1397
- content: block
1398
- };
1399
- }
1400
- }
1401
- }).filter(isNonNullable);
1402
- }, [
1403
- blocks,
1404
- t
1405
- ]);
1406
- const handleChangeOpen = useCallback7(() => {
1407
- setTimeout(() => {
1408
- view?.requestMeasure();
1409
- }, 1e3);
1410
- }, [
1411
- view
1412
- ]);
1413
- if (!items.length) {
1414
- return null;
1415
- }
1416
- return /* @__PURE__ */ React13.createElement(ToolPanel, {
1417
- items,
1418
- onChangeOpen: handleChangeOpen
1419
- });
1420
- };
1421
- var DEFAULT_TOOL_ICON = "ph--wrench--regular";
1422
- var ToolPanel = ({ items, onChangeOpen }) => {
1423
- const tabsRef = useRef3(null);
1424
- const [selected, setSelected] = useState5(0);
1425
- const [open, setOpen] = useState5(false);
1426
- useEffect6(() => {
1427
- setSelected((prev) => Math.min(prev, Math.max(0, items.length - 1)));
1428
- }, [
1429
- items.length
1430
- ]);
1431
- useEffect6(() => {
1432
- onChangeOpen?.(open);
1433
- if (open) {
1434
- tabsRef.current?.focus();
1435
- }
1436
- }, [
1437
- open,
1438
- onChangeOpen
1439
- ]);
1440
- const handleSelect = useCallback7((index) => {
1441
- setSelected(index);
1442
- }, []);
1443
- const headerIcon = items[items.length - 1]?.icon ?? items[0]?.icon ?? DEFAULT_TOOL_ICON;
1444
- return /* @__PURE__ */ React13.createElement(TogglePanel3.Root, {
1445
- open,
1446
- onChangeOpen: setOpen
1447
- }, /* @__PURE__ */ React13.createElement(TogglePanel3.Content, null, /* @__PURE__ */ React13.createElement(TogglePanel3.Header, {
1448
- classNames: "flex items-center gap-2 text-sm text-placeholder"
1449
- }, /* @__PURE__ */ React13.createElement(Icon3, {
1450
- icon: headerIcon,
1451
- size: 4,
1452
- classNames: "shrink-0 opacity-70"
1453
- }), /* @__PURE__ */ React13.createElement(TextCrawl, {
1454
- key: "status-roll",
1455
- lines: items.map((item) => item.title),
1456
- autoAdvance: true,
1457
- greedy: true
1458
- })), /* @__PURE__ */ React13.createElement(TogglePanel3.Body, null, /* @__PURE__ */ React13.createElement(TogglePanel3.Viewport, {
1459
- classNames: "grid grid-cols-[32px_1fr]"
1460
- }, /* @__PURE__ */ React13.createElement(NumericTabs, {
1461
- ref: tabsRef,
1462
- classNames: "p-1",
1463
- length: items.length,
1464
- selected,
1465
- onSelect: handleSelect
1466
- }), /* @__PURE__ */ React13.createElement(JsonHighlighter2, {
1467
- data: items[selected]?.content,
1468
- classNames: "p-1 text-xs bg-transparent",
1469
- replacer: {
1470
- maxDepth: 3,
1471
- maxArrayLen: 10,
1472
- maxStringLen: 128
1473
- }
1474
- })))));
1475
- };
1476
-
1477
- // src/components/ChatThread/registry.tsx
1478
- var __dxlog_file2 = "/__w/dxos/dxos/packages/plugins/plugin-assistant/src/components/ChatThread/registry.tsx";
1479
- var componentRegistry = {
1480
- //
1481
- // Block-only (no widget — see note above).
1482
- //
1483
- "prompt": {
1484
- block: true
1485
- },
1486
- //
1487
- // DOM Widgets
1488
- //
1489
- "link-preview": {
1490
- block: false,
1491
- urlSchemes: [
1492
- "dxn:",
1493
- "echo:"
1494
- ],
1495
- factory: ({ label, dxn }) => typeof label === "string" && typeof dxn === "string" ? new AnchorWidget(label, dxn) : null
1496
- },
1497
- "synthetic": {
1498
- block: true,
1499
- factory: ({ children, range }) => {
1500
- const text = getXmlTextChild2(children);
1501
- return text ? new ReasoningWidget(text, range.from) : null;
1502
- }
1503
- },
1504
- "reasoning": {
1505
- block: true,
1506
- streaming: true,
1507
- factory: ({ children, range }) => {
1508
- const text = getXmlTextChild2(children);
1509
- return text ? new ReasoningWidget(text, range.from) : null;
1510
- }
1511
- },
1512
- "reference": {
1513
- block: false,
1514
- factory: ({ children, ref }) => {
1515
- const text = getXmlTextChild2(children);
1516
- return text && ref ? new ReferenceWidget(text, ref) : null;
1517
- }
1518
- },
1519
- "select": {
1520
- block: true,
1521
- factory: ({ children }) => {
1522
- const options = children?.map((option) => option._tag === "option" && getXmlTextChild2(option.children)).filter(Boolean);
1523
- return options?.length ? new SelectWidget(options) : null;
1524
- }
1525
- },
1526
- "suggestion": {
1527
- block: true,
1528
- factory: ({ children }) => {
1529
- const text = getXmlTextChild2(children);
1530
- return text ? new SuggestionWidget(text) : null;
1531
- }
1532
- },
1533
- "stats": {
1534
- block: true,
1535
- factory: ({ children }) => {
1536
- const text = getXmlTextChild2(children);
1537
- return text ? new StatsWidget(text) : null;
1538
- }
1539
- },
1540
- "status": {
1541
- block: true,
1542
- streaming: true,
1543
- factory: ({ children }) => {
1544
- const text = getXmlTextChild2(children);
1545
- return text ? new StatusWidget(text) : null;
1546
- }
1547
- },
1548
- //
1549
- // React Widgets (portaled outside of the editor)
1550
- //
1551
- "summary": {
1552
- block: true,
1553
- Component: SummaryWidget
1554
- },
1555
- "surface": {
1556
- block: true,
1557
- Component: SurfaceWidget
1558
- },
1559
- "toolCall": {
1560
- block: true,
1561
- Component: (props) => /* @__PURE__ */ React14.createElement("div", {
1562
- className: "py-2"
1563
- }, /* @__PURE__ */ React14.createElement(ToolWidget, props))
1564
- },
1565
- "toolResult": {
1566
- block: true,
1567
- Component: FallbackWidget
1568
- },
1569
- "toolkit": {
1570
- block: true,
1571
- Component: FallbackWidget
1572
- },
1573
- //
1574
- // Fallback
1575
- //
1576
- "json": {
1577
- block: true,
1578
- Component: FallbackWidget
1579
- }
1580
- };
1581
- var blockToMarkdown = createBlockRenderer("normal");
1582
- function createBlockRenderer(viewType) {
1583
- return (context, message, block) => {
1584
- if (!isBlockVisible(viewType, message, block)) {
1585
- return;
1586
- }
1587
- let str = blockToMarkdownImpl(context, message, block);
1588
- if (str && !block.pending) {
1589
- return str += "\n";
1590
- }
1591
- return str;
1592
- };
1593
- }
1594
- var isBlockVisible = (viewType, message, block) => {
1595
- switch (viewType) {
1596
- case "debug":
1597
- return true;
1598
- case "normal":
1599
- return block._tag !== "reasoning";
1600
- case "summary":
1601
- return block._tag === "text" && block.disposition !== "synthetic";
1602
- case "thinking":
1603
- default:
1604
- return true;
1605
- }
1606
- };
1607
- var blockToMarkdownImpl = (context, message, block) => {
1608
- log2("blockToMarkdown", {
1609
- block: JSON.stringify(block)
1610
- }, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 166, S: void 0 });
1611
- switch (block._tag) {
1612
- case "text": {
1613
- if (message.sender.role === "user") {
1614
- if (block.disposition === "synthetic") {
1615
- return renderXMLBlock("synthetic", {
1616
- content: block.text,
1617
- pending: block.pending
1618
- });
1619
- } else {
1620
- return `
1621
- <prompt>${block.text}</prompt>`;
1622
- }
1623
- } else {
1624
- const text = block.text.trim();
1625
- if (text.length > 0) {
1626
- return text;
1627
- }
1628
- }
1629
- break;
1630
- }
1631
- case "reference": {
1632
- if (block.pending) {
1633
- return;
1634
- }
1635
- const dxn = block.reference.uri;
1636
- return `<reference ref="${dxn.toString()}">${context.getObjectLabel(dxn)}</reference>`;
1637
- }
1638
- case "suggestion": {
1639
- if (block.pending) {
1640
- return;
1641
- }
1642
- return `<suggestion>${block.text}</suggestion>`;
1643
- }
1644
- case "select": {
1645
- if (block.pending || block.options.length === 0) {
1646
- return;
1647
- }
1648
- return `<select>${block.options.map((option) => `<option>${option}</option>`).join("")}</select>`;
1649
- }
1650
- case "toolCall": {
1651
- applyToolBlockToWidgetState(context, block);
1652
- return `<toolCall id="${block.toolCallId}" />`;
1653
- }
1654
- case "toolResult": {
1655
- applyToolBlockToWidgetState(context, block);
1656
- break;
1657
- }
1658
- case "stats": {
1659
- return "";
1660
- }
1661
- case "reasoning": {
1662
- let text = block.reasoningText ?? block.redactedText;
1663
- if (!text) {
1664
- return;
1665
- }
1666
- return renderXMLBlock("reasoning", {
1667
- content: text,
1668
- pending: block.pending
1669
- });
1670
- }
1671
- case "summary": {
1672
- return renderXMLBlock("summary", {
1673
- content: block.content,
1674
- pending: block.pending
1675
- });
1676
- }
1677
- case "status": {
1678
- return renderXMLBlock("status", {
1679
- content: block.statusText,
1680
- pending: block.pending
1681
- });
1682
- }
1683
- case "surface": {
1684
- if (block.pending) {
1685
- return;
1686
- }
1687
- return renderXMLBlock("surface", {
1688
- content: JSON.stringify(block.data ?? {}),
1689
- attributes: `role="${escapeXmlAttribute(block.role)}"`
1690
- });
1691
- }
1692
- default: {
1693
- return `<json id="${message.id}">
1694
- ${JSON.stringify(block)}
1695
- </json>`;
1696
- }
1697
- }
1698
- };
1699
- var escapeXmlTextContent = (raw) => raw.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
1700
- var escapeXmlAttribute = (raw) => escapeXmlTextContent(raw).replace(/"/g, "&quot;");
1701
- var renderXMLBlock = (tag, opts) => {
1702
- const content = escapeXmlTextContent((opts.content ?? "").replace(/\n\n/g, " ").trim());
1703
- if (opts.pending) {
1704
- return `<${tag}${opts.attributes ? ` ${opts.attributes}` : ""}>${content}`;
1705
- } else {
1706
- return `<${tag}${opts.attributes ? ` ${opts.attributes}` : ""}>${content}</${tag}>`;
1707
- }
1708
- };
1709
-
1710
- // src/components/ChatThread/sync.ts
1711
- var MessageThreadContext = class {
1712
- _widgetState;
1713
- constructor(_widgetState) {
1714
- this._widgetState = _widgetState;
1715
- }
1716
- updateWidget(id, value2) {
1717
- this._widgetState?.updateWidget(id, value2);
1718
- }
1719
- // TODO(burdon): Resolve name from hypergraph.
1720
- getObjectLabel(_id) {
1721
- return "Object";
1722
- }
1723
- };
1724
- var MessageSyncer = class {
1725
- _document;
1726
- _renderer;
1727
- _threadId;
1728
- _completed = 0;
1729
- _trailing = 0;
1730
- _context;
1731
- constructor(_document, _renderer) {
1732
- this._document = _document;
1733
- this._renderer = _renderer;
1734
- this._context = new MessageThreadContext(this._document);
1735
- }
1736
- get context() {
1737
- return this._context;
1738
- }
1739
- /**
1740
- * Replace the document with the rendering of `messages`. Use on mount, on thread switch,
1741
- * and from {@link update} when it detects an identity change in `messages[0]`.
1742
- */
1743
- reset(messages = []) {
1744
- this._threadId = messages[0]?.id;
1745
- this._completed = 0;
1746
- this._trailing = 0;
1747
- const buffer = this._walk(messages);
1748
- void this._document.setContent(buffer).then(() => {
1749
- rehydrateToolWidgetsFromMessages(this._context, messages);
1750
- });
1751
- }
1752
- /**
1753
- * Stream the suffix of the rendered messages into the document.
1754
- * Returns `true` if the document was replaced (initial mount or thread switch), `false`
1755
- * if the call was a streaming append (or a no-op).
1756
- */
1757
- update(messages) {
1758
- if (messages[0]?.id !== this._threadId) {
1759
- this.reset(messages);
1760
- return true;
1761
- }
1762
- const buffer = this._walk(messages);
1763
- if (buffer.length > 0) {
1764
- void this._document.append(buffer);
1765
- }
1766
- return false;
1767
- }
1768
- /**
1769
- * Walk flat blocks starting at `_completed`, advancing the cursors and returning the chars
1770
- * to append. Blocks before `_completed` are skipped — their renderer is never re-invoked,
1771
- * which preserves single-shot side effects (e.g. tool widget state mutation).
1772
- */
1773
- _walk(messages) {
1774
- let buffer = "";
1775
- let index = 0;
1776
- outer: for (const message of messages) {
1777
- for (const block of message.blocks) {
1778
- if (index < this._completed) {
1779
- index++;
1780
- continue;
1781
- }
1782
- const rendered = this._renderer(this._context, message, block) ?? "";
1783
- if (rendered.length > this._trailing) {
1784
- buffer += rendered.slice(this._trailing);
1785
- }
1786
- if (block.pending) {
1787
- if (rendered.length > this._trailing) {
1788
- this._trailing = rendered.length;
1789
- }
1790
- break outer;
1791
- }
1792
- this._completed = index + 1;
1793
- this._trailing = 0;
1794
- index++;
1795
- }
1796
- }
1797
- return buffer;
1798
- }
1799
- };
1800
-
1801
- // src/components/ChatThread/ChatThread.tsx
1802
- var defaultOptions = {
1803
- autoScroll: true,
1804
- cursor: false,
1805
- fader: false,
1806
- typewriter: true
1807
- };
1808
- var ChatThread = /* @__PURE__ */ forwardRef(({ classNames, identity, messages = [], error, options = defaultOptions, footer, debug = false, extensions, viewType, onEvent }, forwardedRef) => {
1809
- const [controller, setController] = useState6(null);
1810
- const handleMarkdownStreamRef = useCallback8((instance) => {
1811
- setController(instance);
1812
- setRef(forwardedRef, instance);
1813
- }, [
1814
- forwardedRef
1815
- ]);
1816
- const userHue = useMemo8(() => identity?.profile?.data?.hue || keyToFallback(identity?.identityKey ?? PublicKey.random()).hue, [
1817
- identity
1818
- ]);
1819
- const initializedRef = useRef4(false);
1820
- useEffect7(() => {
1821
- if (!controller) {
1822
- initializedRef.current = false;
1823
- return;
1824
- }
1825
- controller.scrollToBottom(initializedRef.current ? "smooth" : "instant");
1826
- initializedRef.current = true;
1827
- }, [
1828
- controller,
1829
- error
1830
- ]);
1831
- const renderer = useMemo8(() => createBlockRenderer(viewType), [
1832
- viewType
1833
- ]);
1834
- const syncer = useMemo8(() => controller && new MessageSyncer(controller, renderer), [
1835
- controller,
1836
- renderer
1837
- ]);
1838
- useEffect7(() => {
1839
- if (!syncer) {
1840
- return;
1841
- }
1842
- if (syncer.update(messages)) {
1843
- controller?.scrollToBottom("instant");
1844
- }
1845
- }, [
1846
- controller,
1847
- syncer,
1848
- messages
1849
- ]);
1850
- const handleEvent = useCallback8(({ type, value: value2 }) => {
1851
- switch (type) {
1852
- case "submit": {
1853
- value2 && onEvent?.({
1854
- type,
1855
- text: value2
1856
- });
1857
- break;
1858
- }
1859
- }
1860
- }, [
1861
- onEvent
1862
- ]);
1863
- return /* @__PURE__ */ React15.createElement("div", {
1864
- "data-hue": userHue,
1865
- className: "contents"
1866
- }, /* @__PURE__ */ React15.createElement(MarkdownStream, {
1867
- key: viewType,
1868
- classNames,
1869
- registry: componentRegistry,
1870
- options,
1871
- debug,
1872
- extensions,
1873
- footer,
1874
- onEvent: handleEvent,
1875
- ref: handleMarkdownStreamRef
1876
- }));
1877
- });
1878
-
1879
- // src/components/TaskList/TaskList.tsx
1880
- import React16, { useMemo as useMemo9 } from "react";
1881
- import { Plan } from "@dxos/assistant-toolkit";
1882
- import { useObject as useObject2 } from "@dxos/react-client/echo";
1883
- import { Icon as Icon4, Tag } from "@dxos/react-ui";
1884
- import { composable, composableProps } from "@dxos/react-ui";
1885
- import { TextCrawl as TextCrawl2 } from "@dxos/react-ui-components";
1886
- import { Listbox as Listbox2 } from "@dxos/react-ui-list";
1887
- import { collectProcessActivityLines, deriveInFlightActivityLine } from "#execution-graph";
1888
- import { isTerminalActivityLine, useProcessEphemeralStatus } from "#hooks";
1889
- var TaskList = composable(({ plan, space, conversationId, traceMessages, ...props }, forwardedRef) => {
1890
- const [snapshot] = useObject2(plan);
1891
- const tasks = snapshot?.tasks ?? [];
1892
- return /* @__PURE__ */ React16.createElement(Listbox2.Root, null, /* @__PURE__ */ React16.createElement(Listbox2.Viewport, {
1893
- ...composableProps(props, {
1894
- classNames: "dx-container"
1895
- }),
1896
- ref: forwardedRef
1897
- }, /* @__PURE__ */ React16.createElement(Listbox2.Content, {
1898
- "aria-label": "Tasks"
1899
- }, tasks.map((task) => /* @__PURE__ */ React16.createElement(TaskListItem, {
1900
- key: task.id,
1901
- task,
1902
- space,
1903
- traceMessages,
1904
- conversationId
1905
- })))));
1906
- });
1907
- var TaskListItem = ({ task, space, traceMessages, conversationId }) => {
1908
- const durableLines = useMemo9(() => {
1909
- if (!task.agentPid || !traceMessages?.length) {
1910
- return [];
1911
- }
1912
- const lines = collectProcessActivityLines(traceMessages, String(task.agentPid), {
1913
- conversationId
1914
- });
1915
- if (task.status !== "in-progress") {
1916
- return lines;
1917
- }
1918
- return lines.filter((line) => !isTerminalActivityLine(line));
1919
- }, [
1920
- task.agentPid,
1921
- task.status,
1922
- traceMessages,
1923
- conversationId
1924
- ]);
1925
- const ephemeralLine = useProcessEphemeralStatus(task.delegated === true && task.status === "in-progress" ? task.agentPid : void 0, space);
1926
- const inFlightLine = useMemo9(() => {
1927
- if (ephemeralLine || task.status !== "in-progress" || !task.agentPid || !traceMessages?.length) {
1928
- return void 0;
1929
- }
1930
- return deriveInFlightActivityLine(traceMessages, String(task.agentPid), {
1931
- conversationId
1932
- });
1933
- }, [
1934
- ephemeralLine,
1935
- task.status,
1936
- task.agentPid,
1937
- traceMessages,
1938
- conversationId
1939
- ]);
1940
- const activityLines = useMemo9(() => {
1941
- if (ephemeralLine) {
1942
- return [
1943
- ephemeralLine
1944
- ];
1945
- }
1946
- if (inFlightLine) {
1947
- return [
1948
- inFlightLine
1949
- ];
1950
- }
1951
- return durableLines;
1952
- }, [
1953
- durableLines,
1954
- ephemeralLine,
1955
- inFlightLine
1956
- ]);
1957
- const agentPid = task.agentPid;
1958
- const showActivity = task.delegated === true && agentPid != null && activityLines.length > 0;
1959
- return /* @__PURE__ */ React16.createElement(Listbox2.Item, {
1960
- id: task.id,
1961
- classNames: "py-0"
1962
- }, /* @__PURE__ */ React16.createElement("div", {
1963
- className: "flex flex-col gap-0.5 min-w-0"
1964
- }, /* @__PURE__ */ React16.createElement("div", {
1965
- className: "flex items-center gap-2 min-w-0"
1966
- }, /* @__PURE__ */ React16.createElement(Icon4, {
1967
- icon: task.status === "done" ? "ph--check--regular" : "ph--circle--regular",
1968
- classNames: task.status === "done" ? "text-success-text" : void 0,
1969
- size: 4
1970
- }), /* @__PURE__ */ React16.createElement("span", {
1971
- className: "sr-only"
1972
- }, task.status === "done" ? "done" : task.status === "in-progress" ? "in progress" : "to do"), /* @__PURE__ */ React16.createElement("span", {
1973
- className: "truncate flex-1"
1974
- }, task.title), task.status === "in-progress" && /* @__PURE__ */ React16.createElement(Tag, {
1975
- hue: "info"
1976
- }, "pending"), task.agentPid && /* @__PURE__ */ React16.createElement(Tag, {
1977
- hue: "info"
1978
- }, Plan.formatAgentPidTag(task.agentPid))), showActivity && agentPid != null && /* @__PURE__ */ React16.createElement(DelegatedTaskActivity, {
1979
- agentPid,
1980
- lines: activityLines
1981
- })));
1982
- };
1983
- var DelegatedTaskActivity = ({ agentPid, lines }) => {
1984
- return /* @__PURE__ */ React16.createElement("div", {
1985
- className: "flex items-center gap-2 ps-6 min-w-0 text-placeholder"
1986
- }, /* @__PURE__ */ React16.createElement(Icon4, {
1987
- icon: "ph--brain--regular",
1988
- size: 3,
1989
- classNames: "shrink-0 opacity-70"
1990
- }), /* @__PURE__ */ React16.createElement(TextCrawl2, {
1991
- key: `${String(agentPid)}:${lines.length}:${lines[lines.length - 1]}`,
1992
- lines,
1993
- autoAdvance: true,
1994
- greedy: true,
1995
- size: "sm",
1996
- classNames: "text-xs text-subdued min-w-0 flex-1"
1997
- }));
1998
- };
1999
-
2000
- // src/components/Chat/Chat.tsx
2001
- var ChatRoot = ({ children, chat, processor, db: dbFallback, onEvent, onSubmit, ...props }) => {
2002
- const [debug, setDebug] = useState7(false);
2003
- const streaming = useAtomValue4(processor.streaming);
2004
- const active = useAtomValue4(processor.active);
2005
- const requestTiming = useRequestTiming({
2006
- active
2007
- });
2008
- const lastPrompt = useRef5(void 0);
2009
- const db = chat && Obj4.getDatabase(chat) || dbFallback;
2010
- const [feedSnapshot] = useObject3(chat?.feed);
2011
- const feed = Obj4.getReactiveOrUndefined(feedSnapshot);
2012
- const event = useMemo10(() => new Event(), []);
2013
- const feedMessages = useQuery3(db, feed ? Query.select(Filter3.type(Message2.Message)).from(feed) : Query.select(Filter3.nothing()));
2014
- const pendingMessages = useAtomValue4(processor.messages);
2015
- const messages = useMemo10(() => Array2.dedupeWith([
2016
- ...feedMessages,
2017
- ...pendingMessages
2018
- ], ({ id: a }, { id: b }) => a === b), [
2019
- feedMessages,
2020
- pendingMessages
2021
- ]);
2022
- const dump = useDebug({
2023
- processor
2024
- });
2025
- const error = useAtomValue4(processor.error);
2026
- useEffect8(() => {
2027
- if (Option3.isSome(error)) {
2028
- event.emit({
2029
- type: "error",
2030
- error: error.value
2031
- });
2032
- }
2033
- }, [
2034
- event,
2035
- error
2036
- ]);
2037
- useEffect8(() => {
2038
- return event.on((ev) => {
2039
- switch (ev.type) {
2040
- case "toggle-debug": {
2041
- setDebug((debug2) => {
2042
- if (debug2) {
2043
- return false;
2044
- } else {
2045
- void dump();
2046
- return true;
2047
- }
2048
- });
2049
- break;
2050
- }
2051
- case "submit": {
2052
- const text = ev.text.trim();
2053
- if (!streaming && text.length) {
2054
- lastPrompt.current = ev.text;
2055
- void Promise.resolve(onSubmit?.(text)).then(() => processor.request({
2056
- message: text
2057
- }));
2058
- }
2059
- break;
2060
- }
2061
- case "retry": {
2062
- if (!streaming) {
2063
- void processor.retry();
2064
- }
2065
- break;
2066
- }
2067
- case "cancel": {
2068
- void processor.cancel();
2069
- if (streaming) {
2070
- if (lastPrompt.current) {
2071
- event.emit({
2072
- type: "update-prompt",
2073
- text: lastPrompt.current
2074
- });
2075
- }
2076
- }
2077
- break;
2078
- }
2079
- }
2080
- onEvent?.(ev);
2081
- });
2082
- }, [
2083
- event,
2084
- dump,
2085
- processor,
2086
- streaming,
2087
- onEvent,
2088
- onSubmit
2089
- ]);
2090
- return /* @__PURE__ */ React17.createElement(ChatContextProvider, {
2091
- debug,
2092
- event,
2093
- db,
2094
- chat,
2095
- messages,
2096
- processor,
2097
- requestTiming,
2098
- ...props
2099
- }, children);
2100
- };
2101
- ChatRoot.displayName = "Chat.Root";
2102
- var useRequestTiming = ({ active }) => {
2103
- const [requestTiming, setRequestTiming] = useState7(null);
2104
- useEffect8(() => {
2105
- if (active) {
2106
- setRequestTiming({
2107
- startedAt: Date.now(),
2108
- endedAt: null
2109
- });
2110
- } else {
2111
- setRequestTiming((prev) => prev && prev.endedAt == null ? {
2112
- ...prev,
2113
- endedAt: Date.now()
2114
- } : prev);
2115
- }
2116
- }, [
2117
- active
2118
- ]);
2119
- return requestTiming;
2120
- };
2121
- var CHAT_TOOLBAR_NAME = "Chat.Toolbar";
2122
- var ChatToolbar = composable2(({ children, attendableId, alwaysActive, companionTo, ...props }, forwardedRef) => {
2123
- const { chat } = useChatContext(CHAT_TOOLBAR_NAME);
2124
- const menuActions = useChatToolbarActions({
2125
- chat,
2126
- companionTo
2127
- });
2128
- return /* @__PURE__ */ React17.createElement(Menu.Root, {
2129
- ...menuActions,
2130
- attendableId,
2131
- alwaysActive
2132
- }, /* @__PURE__ */ React17.createElement(Menu.Toolbar, {
2133
- ...composableProps2(props),
2134
- ref: forwardedRef
2135
- }, children));
2136
- });
2137
- ChatToolbar.displayName = CHAT_TOOLBAR_NAME;
2138
- var CHAT_CONTENT_NAME = "Chat.Content";
2139
- var ChatContent = composable2(({ children, ...props }, forwardedRef) => {
2140
- return /* @__PURE__ */ React17.createElement("div", {
2141
- ...composableProps2(props, {
2142
- classNames: "dx-expander flex flex-col"
2143
- }),
2144
- ref: forwardedRef
2145
- }, children);
2146
- });
2147
- ChatContent.displayName = CHAT_CONTENT_NAME;
2148
- var CHAT_THREAD_NAME = "Chat.Thread";
2149
- var ChatThread2 = ({ viewType, debug: debugProp, onViewUsage, ...props }) => {
2150
- const { t } = useTranslation10(meta10.profile.key);
2151
- const { debug, event, messages, processor } = useChatContext(CHAT_THREAD_NAME);
2152
- const extensions = useChatKeymapExtensions2({
2153
- event
2154
- });
2155
- const identity = useIdentity();
2156
- const error = useAtomValue4(processor.error).pipe(Option3.getOrUndefined);
2157
- const [toastError, setToastError] = useState7(void 0);
2158
- const toastAction = toastError instanceof AiUsageQuotaError ? toastError.action : void 0;
2159
- const debugView = viewType === "debug";
2160
- const controllerRef = useRef5(null);
2161
- useEffect8(() => {
2162
- return event.on((event2) => {
2163
- switch (event2.type) {
2164
- case "submit":
2165
- case "scroll-to-bottom":
2166
- controllerRef.current?.scrollToBottom();
2167
- break;
2168
- case "nav-previous":
2169
- controllerRef.current?.navigatePrevious();
2170
- break;
2171
- case "nav-next":
2172
- controllerRef.current?.navigateNext();
2173
- break;
2174
- case "error":
2175
- setToastError(event2.error);
2176
- break;
2177
- }
2178
- });
2179
- }, [
2180
- event
2181
- ]);
2182
- const handleEvent = useCallback9((ev) => {
2183
- event.emit(ev);
2184
- }, [
2185
- event
2186
- ]);
2187
- if (!identity) {
2188
- return /* @__PURE__ */ React17.createElement("div", {
2189
- className: "dx-expander"
2190
- });
2191
- }
2192
- return /* @__PURE__ */ React17.createElement(React17.Fragment, null, /* @__PURE__ */ React17.createElement(ChatThread, {
2193
- ...props,
2194
- identity,
2195
- messages,
2196
- error,
2197
- debug: debugProp ?? (debug || debugView),
2198
- viewType,
2199
- extensions,
2200
- onEvent: handleEvent,
2201
- ref: controllerRef
2202
- }), /* @__PURE__ */ React17.createElement(Toast.Root, {
2203
- type: "foreground",
2204
- open: !!toastError,
2205
- duration: 2e4,
2206
- onOpenChange: (open) => !open && setToastError(void 0)
2207
- }, /* @__PURE__ */ React17.createElement(Toast.Title, {
2208
- icon: "ph--warning--regular",
2209
- onClose: () => setToastError(void 0)
2210
- }, t("ai-service-error.label")), /* @__PURE__ */ React17.createElement(Toast.Description, null, toastError?.message), toastAction && onViewUsage && /* @__PURE__ */ React17.createElement(Toast.Actions, null, /* @__PURE__ */ React17.createElement(Toast.Action, {
2211
- altText: t(toastAction.labelKey),
2212
- asChild: true
2213
- }, /* @__PURE__ */ React17.createElement(Button, {
2214
- onClick: () => {
2215
- setToastError(void 0);
2216
- onViewUsage();
2217
- }
2218
- }, t(toastAction.labelKey))))));
2219
- };
2220
- ChatThread2.displayName = CHAT_THREAD_NAME;
2221
- var CHAT_PROMPT_NAME = "Chat.Prompt";
2222
- var ChatPrompt2 = (props) => {
2223
- const { chat, db, processor, event } = useChatContext(CHAT_PROMPT_NAME);
2224
- return /* @__PURE__ */ React17.createElement(ChatPrompt, {
2225
- ...props,
2226
- chat,
2227
- db,
2228
- processor,
2229
- event
2230
- });
2231
- };
2232
- ChatPrompt2.displayName = CHAT_PROMPT_NAME;
2233
- var CHAT_TASK_LIST_NAME = "Chat.TaskList";
2234
- var ChatTaskList = composable2(({ plan: planProp, ...props }, forwardedRef) => {
2235
- const { chat } = useChatContext(CHAT_TASK_LIST_NAME);
2236
- const plan = useAtomValue4(useMemo10(() => Atom2.make((get) => planProp ?? Option3.fromNullable(chat).pipe(Option3.map((_) => get(Obj4.atom(_))), Option3.flatMapNullable((_) => _?.plan?.atom), Option3.map(get), Option3.getOrUndefined)), [
2237
- chat,
2238
- planProp
2239
- ]));
2240
- const space = chat ? getSpace(chat) : void 0;
2241
- const traceMessages = useTraceMessages(space);
2242
- const conversationId = chat?.feed?.target?.id;
2243
- if (!plan || !(plan.tasks?.length ?? 0)) {
2244
- return null;
2245
- }
2246
- return /* @__PURE__ */ React17.createElement(TaskList, {
2247
- ...props,
2248
- plan,
2249
- space,
2250
- traceMessages,
2251
- conversationId,
2252
- ref: forwardedRef
2253
- });
2254
- });
2255
- ChatTaskList.displayName = CHAT_TASK_LIST_NAME;
2256
- var Chat = {
2257
- Root: ChatRoot,
2258
- Toolbar: ChatToolbar,
2259
- Content: ChatContent,
2260
- Prompt: ChatPrompt2,
2261
- Status: ChatStatus,
2262
- Thread: ChatThread2,
2263
- TaskList: ChatTaskList
2264
- };
2265
-
2266
- // src/components/ProcessTree/ProcessTree.tsx
2267
- import * as Match from "effect/Match";
2268
- import * as Option4 from "effect/Option";
2269
- import React18, { useMemo as useMemo11 } from "react";
2270
- import { Process } from "@dxos/compute";
2271
- import { Icon as Icon5, IconButton as IconButton4, ScrollArea, Tooltip as Tooltip2, composable as composable3, composableProps as composableProps3 } from "@dxos/react-ui";
2272
- import { Treegrid, TREEGRID_PATH_SEPARATOR } from "@dxos/react-ui-list";
2273
- import { mx as mx7 } from "@dxos/ui-theme";
2274
- import { Unit as Unit2 } from "@dxos/util";
2275
- var DEFAULT_DEPTH = 1;
2276
- var LABEL_INDENT_REM = 0.5;
2277
- var NESTED_ACTIVE_STATES = /* @__PURE__ */ new Set([
2278
- Process.State.RUNNING,
2279
- Process.State.HYBERNATING,
2280
- Process.State.TERMINATING
2281
- ]);
2282
- var ProcessTree = /* @__PURE__ */ React18.memo(composable3(({ processes, depth = DEFAULT_DEPTH, onProcessSelect, onProcessTerminate, ...props }, forwardedRef) => {
2283
- const rows = useMemo11(() => buildProcessTreeRows(processes, depth), [
2284
- processes,
2285
- depth
2286
- ]);
2287
- return /* @__PURE__ */ React18.createElement(ScrollArea.Root, {
2288
- ...composableProps3(props, {
2289
- classNames: "dx-expander"
2290
- }),
2291
- thin: true,
2292
- ref: forwardedRef
2293
- }, /* @__PURE__ */ React18.createElement(ScrollArea.Viewport, null, /* @__PURE__ */ React18.createElement(Treegrid.Root, {
2294
- classNames: "grid grid-cols-[min-content_1fr_min-content_min-content]"
2295
- }, rows.map(({ process, path }) => /* @__PURE__ */ React18.createElement(ProcessTreeRowView, {
2296
- key: path.join(TREEGRID_PATH_SEPARATOR),
2297
- process,
2298
- path,
2299
- onProcessSelect,
2300
- onProcessTerminate
2301
- })))));
2302
- }));
2303
- var ProcessTreeRowView = ({ process, path, onProcessSelect, onProcessTerminate }) => {
2304
- const duration = Unit2.Duration(process.metrics.wallTime);
2305
- const level = path.length;
2306
- const nested = level > 1;
2307
- return /* @__PURE__ */ React18.createElement(Treegrid.Row, {
2308
- id: path.join(TREEGRID_PATH_SEPARATOR),
2309
- classNames: mx7("col-span-full grid grid-cols-subgrid gap-2 ps-1", onProcessSelect && "dx-hover")
2310
- }, /* @__PURE__ */ React18.createElement(Treegrid.Cell, {
2311
- classNames: "flex items-center gap-0.5"
2312
- }, nested && /* @__PURE__ */ React18.createElement(Icon5, {
2313
- icon: "ph--arrow-elbow-down-right--regular",
2314
- size: 3,
2315
- classNames: "shrink-0 text-subdued"
2316
- }), /* @__PURE__ */ React18.createElement(Tooltip2.Trigger, {
2317
- content: process.state.toString()
2318
- }, /* @__PURE__ */ React18.createElement(Icon5, {
2319
- size: 4,
2320
- synchronized: true,
2321
- 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"),
2322
- 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--moon-stars--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"))
2323
- }))), /* @__PURE__ */ React18.createElement(Treegrid.Cell, {
2324
- classNames: "flex items-center truncate",
2325
- style: nested ? {
2326
- paddingInlineStart: `${(level - 1) * LABEL_INDENT_REM}rem`
2327
- } : void 0,
2328
- onClick: () => onProcessSelect?.(process)
2329
- }, /* @__PURE__ */ React18.createElement("span", {
2330
- className: mx7("truncate text-sm", level === 1 && "font-medium", process.state !== Process.State.RUNNING && "text-description")
2331
- }, process.params.name ?? process.pid.toString())), /* @__PURE__ */ React18.createElement(Treegrid.Cell, {
2332
- classNames: "flex items-center justify-end text-xs text-description tabular-nums"
2333
- }, [
2334
- Process.State.FAILED,
2335
- Process.State.SUCCEEDED
2336
- ].includes(process.state) && /* @__PURE__ */ React18.createElement("span", {
2337
- className: "whitespace-nowrap"
2338
- }, duration.toString())), /* @__PURE__ */ React18.createElement(Treegrid.Cell, null, onProcessTerminate && /* @__PURE__ */ React18.createElement(IconButton4, {
2339
- classNames: "min-h-0 p-1",
2340
- icon: "ph--x--regular",
2341
- iconOnly: true,
2342
- variant: "ghost",
2343
- size: 4,
2344
- label: "Actions",
2345
- onClick: (event) => {
2346
- event.stopPropagation();
2347
- onProcessTerminate?.(process);
2348
- }
2349
- })));
2350
- };
2351
- var sortProcesses = (processes) => {
2352
- return [
2353
- ...processes.filter((process) => [
2354
- Process.State.RUNNING,
2355
- Process.State.HYBERNATING
2356
- ].includes(process.state)),
2357
- ...processes.filter((process) => [
2358
- Process.State.IDLE
2359
- ].includes(process.state)).slice(0, 3),
2360
- ...processes.filter((process) => [
2361
- Process.State.SUCCEEDED,
2362
- Process.State.FAILED,
2363
- Process.State.TERMINATED
2364
- ].includes(process.state))
2365
- ].sort((left, right) => {
2366
- const leftCompletedAt = Option4.getOrElse(left.completedAt, () => Infinity);
2367
- const rightCompletedAt = Option4.getOrElse(right.completedAt, () => Infinity);
2368
- return rightCompletedAt - leftCompletedAt;
2369
- });
2370
- };
2371
- var sortNestedActive = (processes) => processes.filter((process) => NESTED_ACTIVE_STATES.has(process.state)).sort((left, right) => {
2372
- const priority = (state) => state === Process.State.RUNNING ? 0 : state === Process.State.HYBERNATING ? 1 : 2;
2373
- return priority(left.state) - priority(right.state);
2374
- });
2375
- var buildProcessTreeRows = (processes, maxDepth) => {
2376
- const pidSet = new Set(processes.map((process) => String(process.pid)));
2377
- const childrenByParent = /* @__PURE__ */ new Map();
2378
- const roots = [];
2379
- for (const process of processes) {
2380
- const parent = process.parentPid;
2381
- if (parent === null || !pidSet.has(String(parent))) {
2382
- roots.push(process);
2383
- continue;
2384
- }
2385
- const key = String(parent);
2386
- const siblings = childrenByParent.get(key) ?? [];
2387
- siblings.push(process);
2388
- childrenByParent.set(key, siblings);
2389
- }
2390
- const sortedRoots = sortProcesses(roots);
2391
- const rows = [];
2392
- const visit = (process, path, level) => {
2393
- if (level > maxDepth) {
2394
- return;
2395
- }
2396
- rows.push({
2397
- process,
2398
- path
2399
- });
2400
- if (level >= maxDepth) {
2401
- return;
2402
- }
2403
- const children = sortNestedActive(childrenByParent.get(String(process.pid)) ?? []);
2404
- for (const child of children) {
2405
- visit(child, [
2406
- ...path,
2407
- String(child.pid)
2408
- ], level + 1);
2409
- }
2410
- };
2411
- for (const root of sortedRoots) {
2412
- visit(root, [
2413
- String(root.pid)
2414
- ], 1);
2415
- }
2416
- return rows;
2417
- };
2418
-
2419
- // src/components/Toolbox/Toolbox.tsx
2420
- import React19, { Fragment, useEffect as useEffect9, useState as useState8 } from "react";
2421
- import { Operation } from "@dxos/compute";
2422
- import { Filter as Filter4 } from "@dxos/echo";
2423
- import { log as log3 } from "@dxos/log";
2424
- import { useQuery as useQuery4 } from "@dxos/react-client/echo";
2425
- import { ScrollArea as ScrollArea2 } from "@dxos/react-ui";
2426
- import { composable as composable4, composableProps as composableProps4 } from "@dxos/react-ui";
2427
- import { mx as mx8 } from "@dxos/ui-theme";
2428
- import { ServiceType } from "#types";
2429
- var __dxlog_file3 = "/__w/dxos/dxos/packages/plugins/plugin-assistant/src/components/Toolbox/Toolbox.tsx";
2430
- var Toolbox = composable4(({ functions, services, skills, activeSkills, ...props }, forwardedRef) => {
2431
- return /* @__PURE__ */ React19.createElement(ScrollArea2.Root, {
2432
- ...composableProps4(props),
2433
- thin: true,
2434
- orientation: "vertical",
2435
- ref: forwardedRef
2436
- }, /* @__PURE__ */ React19.createElement(ScrollArea2.Viewport, null, skills && skills.length > 0 && /* @__PURE__ */ React19.createElement(Section, {
2437
- title: "Skills",
2438
- items: skills.map(({ name, description, tools }) => ({
2439
- name,
2440
- description,
2441
- subitems: tools.map((toolId) => ({
2442
- name: `\u2219 ${safeToolId(toolId)}`
2443
- }))
2444
- }))
2445
- }), activeSkills && activeSkills.length > 0 && /* @__PURE__ */ React19.createElement(Section, {
2446
- title: "Skills",
2447
- items: activeSkills.map(({ target }) => ({
2448
- name: target?.name ?? "",
2449
- description: target?.description ?? "",
2450
- subitems: target?.tools.map((toolId) => ({
2451
- name: `\u2219 ${safeToolId(toolId)}`
2452
- }))
2453
- }))
2454
- }), services && services.length > 0 && /* @__PURE__ */ React19.createElement(Section, {
2455
- title: "Services",
2456
- items: services.map(({ service: { serviceId, name, description } }) => ({
2457
- name: name ?? serviceId,
2458
- description
2459
- }))
2460
- }), functions && functions.length > 0 && /* @__PURE__ */ React19.createElement(Section, {
2461
- title: "Functions",
2462
- items: functions.map(({ name, description }) => ({
2463
- name,
2464
- description
2465
- }))
2466
- })));
2467
- });
2468
- Toolbox.displayName = "Toolbox";
2469
- var Section = ({ title, items, striped }) => {
2470
- const stripeClassNames = "odd:bg-neutral-50 dark:odd:bg-neutral-800";
2471
- const gridClassNames = "grid grid-cols-[8rem_1fr]";
2472
- const subGridClassNames = mx8("col-span-full grid grid-cols-subgrid text-xs px-2", striped && stripeClassNames);
2473
- return /* @__PURE__ */ React19.createElement("div", null, /* @__PURE__ */ React19.createElement("h1", {
2474
- className: "px-2 text-sm"
2475
- }, title), /* @__PURE__ */ React19.createElement("div", {
2476
- className: gridClassNames
2477
- }, items.map(({ name, description, subitems }, i) => /* @__PURE__ */ React19.createElement(Fragment, {
2478
- key: i
2479
- }, name && /* @__PURE__ */ React19.createElement("div", {
2480
- className: subGridClassNames
2481
- }, /* @__PURE__ */ React19.createElement("div", {
2482
- className: "truncate text-primary-500"
2483
- }, name), /* @__PURE__ */ React19.createElement("div", {
2484
- className: "line-clamp-2"
2485
- }, description)), subitems?.map(({ name: name2, description: description2 }, i2) => /* @__PURE__ */ React19.createElement("div", {
2486
- key: i2,
2487
- className: mx8(subGridClassNames, striped && stripeClassNames)
2488
- }, /* @__PURE__ */ React19.createElement("div", {
2489
- className: "truncate"
2490
- }, name2), /* @__PURE__ */ React19.createElement("div", {
2491
- className: "line-clamp-3 text-subdued"
2492
- }, description2)))))));
2493
- };
2494
- var ToolboxPanel = ({ classNames, db, processor }) => {
2495
- const services = useQuery4(db, Filter4.type(ServiceType));
2496
- const [serviceTools, setServiceTools] = useState8([]);
2497
- useEffect9(() => {
2498
- log3("creating service tools...", {
2499
- services: services.length
2500
- }, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 82, S: void 0 });
2501
- queueMicrotask(async () => {
2502
- });
2503
- }, [
2504
- services
2505
- ]);
2506
- const functions = useQuery4(db, Filter4.type(Operation.PersistentOperation));
2507
- return /* @__PURE__ */ React19.createElement(Toolbox, {
2508
- classNames,
2509
- skills: processor?.context.getSkills(),
2510
- services: serviceTools,
2511
- functions
2512
- });
2513
- };
2514
- var safeToolId = (name) => {
2515
- return name.split("_").pop();
2516
- };
2517
- export {
2518
- AgentProperties,
2519
- Chat,
2520
- ChatPrompt,
2521
- ProcessTree,
2522
- TaskList,
2523
- Toolbox,
2524
- ToolboxPanel,
2525
- TracePanel
2526
- };
2527
- //# sourceMappingURL=index.mjs.map