@dxos/plugin-automation 0.7.5-main.9d2a38b → 0.7.5-main.b19bfc8

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 (370) hide show
  1. package/dist/lib/browser/AssistantDialog-V67OWLRP.mjs +116 -0
  2. package/dist/lib/browser/AssistantDialog-V67OWLRP.mjs.map +7 -0
  3. package/dist/lib/browser/AutomationPanel-NCKK3CFN.mjs +8 -0
  4. package/dist/lib/browser/AutomationPanel-NCKK3CFN.mjs.map +7 -0
  5. package/dist/lib/browser/ChatContainer-5BS6THNV.mjs +33 -0
  6. package/dist/lib/browser/ChatContainer-5BS6THNV.mjs.map +7 -0
  7. package/dist/lib/browser/TemplateContainer-HJJV44CE.mjs +23 -0
  8. package/dist/lib/browser/TemplateContainer-HJJV44CE.mjs.map +7 -0
  9. package/dist/lib/browser/ai-client-T2PBJISL.mjs +22 -0
  10. package/dist/lib/browser/ai-client-T2PBJISL.mjs.map +7 -0
  11. package/dist/lib/browser/app-graph-builder-IR3CGVM6.mjs +110 -0
  12. package/dist/lib/browser/app-graph-builder-IR3CGVM6.mjs.map +7 -0
  13. package/dist/lib/browser/chunk-62E2AEXF.mjs +162 -0
  14. package/dist/lib/browser/chunk-62E2AEXF.mjs.map +7 -0
  15. package/dist/lib/browser/chunk-67KDIIM6.mjs +15 -0
  16. package/dist/lib/browser/chunk-67KDIIM6.mjs.map +7 -0
  17. package/dist/lib/browser/chunk-BQ4WHY4D.mjs +1818 -0
  18. package/dist/lib/browser/chunk-BQ4WHY4D.mjs.map +7 -0
  19. package/dist/lib/browser/{chunk-HKX3D3ZP.mjs → chunk-HZSTXZWK.mjs} +4 -2
  20. package/dist/lib/browser/chunk-HZSTXZWK.mjs.map +7 -0
  21. package/dist/lib/{node-esm/AutomationPanel-R3D6CRF5.mjs → browser/chunk-LJ7F4KDM.mjs} +31 -21
  22. package/dist/lib/browser/chunk-LJ7F4KDM.mjs.map +7 -0
  23. package/dist/lib/browser/chunk-QH5E22EL.mjs +108 -0
  24. package/dist/lib/browser/chunk-QH5E22EL.mjs.map +7 -0
  25. package/dist/lib/browser/chunk-XAIWETH6.mjs +81 -0
  26. package/dist/lib/browser/chunk-XAIWETH6.mjs.map +7 -0
  27. package/dist/lib/browser/index.mjs +163 -273
  28. package/dist/lib/browser/index.mjs.map +4 -4
  29. package/dist/lib/browser/intent-resolver-ICLE6FSI.mjs +44 -0
  30. package/dist/lib/browser/intent-resolver-ICLE6FSI.mjs.map +7 -0
  31. package/dist/lib/browser/meta.json +1 -1
  32. package/dist/lib/browser/react-surface-KEKVLCPQ.mjs +80 -0
  33. package/dist/lib/browser/react-surface-KEKVLCPQ.mjs.map +7 -0
  34. package/dist/lib/browser/settings-FE5DDWOE.mjs +22 -0
  35. package/dist/lib/browser/settings-FE5DDWOE.mjs.map +7 -0
  36. package/dist/lib/browser/types/index.mjs +20 -9
  37. package/dist/lib/node/AssistantDialog-E62O72KI.cjs +140 -0
  38. package/dist/lib/node/AssistantDialog-E62O72KI.cjs.map +7 -0
  39. package/dist/lib/node/AutomationPanel-6COLKRIB.cjs +26 -0
  40. package/dist/lib/node/AutomationPanel-6COLKRIB.cjs.map +7 -0
  41. package/dist/lib/node/{react-surface-DVAU4MGD.cjs → ChatContainer-4QTLL7TH.cjs} +30 -26
  42. package/dist/lib/node/ChatContainer-4QTLL7TH.cjs.map +7 -0
  43. package/dist/lib/node/{chunk-25AQIF3L.cjs → TemplateContainer-3YCM6XPU.cjs} +21 -11
  44. package/dist/lib/node/TemplateContainer-3YCM6XPU.cjs.map +7 -0
  45. package/dist/lib/node/ai-client-L5GUSAER.cjs +38 -0
  46. package/dist/lib/node/ai-client-L5GUSAER.cjs.map +7 -0
  47. package/dist/lib/node/app-graph-builder-ECNVGTRT.cjs +122 -0
  48. package/dist/lib/node/app-graph-builder-ECNVGTRT.cjs.map +7 -0
  49. package/dist/lib/node/chunk-3QSK6IPK.cjs +133 -0
  50. package/dist/lib/node/chunk-3QSK6IPK.cjs.map +7 -0
  51. package/dist/lib/node/chunk-76F5BCJE.cjs +111 -0
  52. package/dist/lib/node/chunk-76F5BCJE.cjs.map +7 -0
  53. package/dist/lib/node/chunk-B37JIAOP.cjs +1795 -0
  54. package/dist/lib/node/chunk-B37JIAOP.cjs.map +7 -0
  55. package/dist/lib/node/{chunk-5VF5JKUN.cjs → chunk-BAQRBGOJ.cjs} +8 -5
  56. package/dist/lib/node/chunk-BAQRBGOJ.cjs.map +7 -0
  57. package/dist/lib/node/chunk-UVWK2XJE.cjs +183 -0
  58. package/dist/lib/node/chunk-UVWK2XJE.cjs.map +7 -0
  59. package/dist/lib/node/{AutomationPanel-PPODB5XA.cjs → chunk-V4L7LTWM.cjs} +39 -24
  60. package/dist/lib/node/chunk-V4L7LTWM.cjs.map +7 -0
  61. package/dist/lib/node/chunk-VNBYGJ4K.cjs +34 -0
  62. package/dist/lib/node/chunk-VNBYGJ4K.cjs.map +7 -0
  63. package/dist/lib/node/index.cjs +166 -292
  64. package/dist/lib/node/index.cjs.map +4 -4
  65. package/dist/lib/node/intent-resolver-4MQZULXW.cjs +58 -0
  66. package/dist/lib/node/intent-resolver-4MQZULXW.cjs.map +7 -0
  67. package/dist/lib/node/meta.json +1 -1
  68. package/dist/lib/node/react-surface-4RVHY6WI.cjs +95 -0
  69. package/dist/lib/node/react-surface-4RVHY6WI.cjs.map +7 -0
  70. package/dist/lib/node/settings-GOIB2WJQ.cjs +36 -0
  71. package/dist/lib/node/settings-GOIB2WJQ.cjs.map +7 -0
  72. package/dist/lib/node/types/index.cjs +20 -9
  73. package/dist/lib/node/types/index.cjs.map +2 -2
  74. package/dist/lib/node-esm/AssistantDialog-IPRBJKWA.mjs +117 -0
  75. package/dist/lib/node-esm/AssistantDialog-IPRBJKWA.mjs.map +7 -0
  76. package/dist/lib/node-esm/AutomationPanel-3MPIAO7R.mjs +9 -0
  77. package/dist/lib/node-esm/AutomationPanel-3MPIAO7R.mjs.map +7 -0
  78. package/dist/lib/node-esm/ChatContainer-4IWUGMGM.mjs +34 -0
  79. package/dist/lib/node-esm/ChatContainer-4IWUGMGM.mjs.map +7 -0
  80. package/dist/lib/node-esm/TemplateContainer-YJIXR24Z.mjs +24 -0
  81. package/dist/lib/node-esm/TemplateContainer-YJIXR24Z.mjs.map +7 -0
  82. package/dist/lib/node-esm/ai-client-45LZLW7V.mjs +23 -0
  83. package/dist/lib/node-esm/ai-client-45LZLW7V.mjs.map +7 -0
  84. package/dist/lib/node-esm/app-graph-builder-HMRKSZ2X.mjs +111 -0
  85. package/dist/lib/node-esm/app-graph-builder-HMRKSZ2X.mjs.map +7 -0
  86. package/dist/lib/node-esm/chunk-5BKKHYO5.mjs +163 -0
  87. package/dist/lib/node-esm/chunk-5BKKHYO5.mjs.map +7 -0
  88. package/dist/lib/{browser/AutomationPanel-IHZ4JKVS.mjs → node-esm/chunk-AWAU4BHR.mjs} +32 -20
  89. package/dist/lib/node-esm/chunk-AWAU4BHR.mjs.map +7 -0
  90. package/dist/lib/node-esm/chunk-CAWPHOY4.mjs +82 -0
  91. package/dist/lib/node-esm/chunk-CAWPHOY4.mjs.map +7 -0
  92. package/dist/lib/node-esm/chunk-I32H7MCF.mjs +109 -0
  93. package/dist/lib/node-esm/chunk-I32H7MCF.mjs.map +7 -0
  94. package/dist/lib/node-esm/{chunk-X3LPRWIL.mjs → chunk-IG4GSWZN.mjs} +4 -2
  95. package/dist/lib/node-esm/chunk-IG4GSWZN.mjs.map +7 -0
  96. package/dist/lib/node-esm/chunk-QHKP5HT2.mjs +1819 -0
  97. package/dist/lib/node-esm/chunk-QHKP5HT2.mjs.map +7 -0
  98. package/dist/lib/node-esm/chunk-SS7U6GCX.mjs +16 -0
  99. package/dist/lib/node-esm/chunk-SS7U6GCX.mjs.map +7 -0
  100. package/dist/lib/node-esm/index.mjs +163 -273
  101. package/dist/lib/node-esm/index.mjs.map +4 -4
  102. package/dist/lib/node-esm/intent-resolver-ZS7XTYLG.mjs +45 -0
  103. package/dist/lib/node-esm/intent-resolver-ZS7XTYLG.mjs.map +7 -0
  104. package/dist/lib/node-esm/meta.json +1 -1
  105. package/dist/lib/node-esm/react-surface-5ILD642V.mjs +81 -0
  106. package/dist/lib/node-esm/react-surface-5ILD642V.mjs.map +7 -0
  107. package/dist/lib/node-esm/settings-ANNQPPRY.mjs +23 -0
  108. package/dist/lib/node-esm/settings-ANNQPPRY.mjs.map +7 -0
  109. package/dist/lib/node-esm/types/index.mjs +20 -9
  110. package/dist/types/src/AutomationPlugin.d.ts.map +1 -1
  111. package/dist/types/src/capabilities/ai-client.d.ts +5 -0
  112. package/dist/types/src/capabilities/ai-client.d.ts.map +1 -0
  113. package/dist/types/src/capabilities/app-graph-builder.d.ts +111 -110
  114. package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -1
  115. package/dist/types/src/capabilities/capabilities.d.ts +5 -0
  116. package/dist/types/src/capabilities/capabilities.d.ts.map +1 -0
  117. package/dist/types/src/capabilities/index.d.ts +117 -113
  118. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  119. package/dist/types/src/capabilities/intent-resolver.d.ts +4 -0
  120. package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -0
  121. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
  122. package/dist/types/src/capabilities/settings.d.ts +4 -0
  123. package/dist/types/src/capabilities/settings.d.ts.map +1 -0
  124. package/dist/types/src/components/AmbientDialog/AmbientDialog.d.ts +7 -0
  125. package/dist/types/src/components/AmbientDialog/AmbientDialog.d.ts.map +1 -0
  126. package/dist/types/src/components/AmbientDialog/AmbientDialog.stories.d.ts +8 -0
  127. package/dist/types/src/components/AmbientDialog/AmbientDialog.stories.d.ts.map +1 -0
  128. package/dist/types/src/components/AmbientDialog/index.d.ts +2 -0
  129. package/dist/types/src/components/AmbientDialog/index.d.ts.map +1 -0
  130. package/dist/types/src/components/AssistantDialog.d.ts +7 -0
  131. package/dist/types/src/components/AssistantDialog.d.ts.map +1 -0
  132. package/dist/types/src/components/AutomationPanel/AutomationPanel.d.ts +1 -2
  133. package/dist/types/src/components/AutomationPanel/AutomationPanel.d.ts.map +1 -1
  134. package/dist/types/src/components/AutomationSettings/AutomationSettings.d.ts +5 -0
  135. package/dist/types/src/components/AutomationSettings/AutomationSettings.d.ts.map +1 -0
  136. package/dist/types/src/components/AutomationSettings/index.d.ts +2 -0
  137. package/dist/types/src/components/AutomationSettings/index.d.ts.map +1 -0
  138. package/dist/types/src/components/ChatContainer.d.ts +7 -0
  139. package/dist/types/src/components/ChatContainer.d.ts.map +1 -0
  140. package/dist/types/src/components/Prompt/Prompt.d.ts +17 -0
  141. package/dist/types/src/components/Prompt/Prompt.d.ts.map +1 -0
  142. package/dist/types/src/components/Prompt/Prompt.stories.d.ts +9 -0
  143. package/dist/types/src/components/Prompt/Prompt.stories.d.ts.map +1 -0
  144. package/dist/types/src/components/Prompt/PromptBar.d.ts +10 -0
  145. package/dist/types/src/components/Prompt/PromptBar.d.ts.map +1 -0
  146. package/dist/types/src/components/Prompt/autocomplete.d.ts +21 -0
  147. package/dist/types/src/components/Prompt/autocomplete.d.ts.map +1 -0
  148. package/dist/types/src/components/Prompt/index.d.ts +3 -0
  149. package/dist/types/src/components/Prompt/index.d.ts.map +1 -0
  150. package/dist/types/src/components/ServiceRegistry/ServiceRegistry.d.ts +5 -0
  151. package/dist/types/src/components/ServiceRegistry/ServiceRegistry.d.ts.map +1 -0
  152. package/dist/types/src/components/ServiceRegistry/ServiceRegistry.stories.d.ts +8 -0
  153. package/dist/types/src/components/ServiceRegistry/ServiceRegistry.stories.d.ts.map +1 -0
  154. package/dist/types/src/components/ServiceRegistry/index.d.ts +2 -0
  155. package/dist/types/src/components/ServiceRegistry/index.d.ts.map +1 -0
  156. package/dist/types/src/components/TemplateContainer.d.ts +7 -0
  157. package/dist/types/src/components/TemplateContainer.d.ts.map +1 -0
  158. package/dist/types/src/components/TemplateEditor/TemplateEditor.d.ts +12 -0
  159. package/dist/types/src/components/TemplateEditor/TemplateEditor.d.ts.map +1 -0
  160. package/dist/types/src/components/TemplateEditor/TemplateEditor.stories.d.ts +8 -0
  161. package/dist/types/src/components/TemplateEditor/TemplateEditor.stories.d.ts.map +1 -0
  162. package/dist/types/src/components/TemplateEditor/TemplateForm.d.ts +10 -0
  163. package/dist/types/src/components/TemplateEditor/TemplateForm.d.ts.map +1 -0
  164. package/dist/types/src/components/TemplateEditor/TemplateForm.stories.d.ts +8 -0
  165. package/dist/types/src/components/TemplateEditor/TemplateForm.stories.d.ts.map +1 -0
  166. package/dist/types/src/components/TemplateEditor/index.d.ts +2 -0
  167. package/dist/types/src/components/TemplateEditor/index.d.ts.map +1 -0
  168. package/dist/types/src/components/TemplateEditor/types.d.ts.map +1 -0
  169. package/dist/types/src/components/Thread/Thread.d.ts +17 -0
  170. package/dist/types/src/components/Thread/Thread.d.ts.map +1 -0
  171. package/dist/types/src/components/Thread/Thread.stories.d.ts +11 -0
  172. package/dist/types/src/components/Thread/Thread.stories.d.ts.map +1 -0
  173. package/dist/types/src/components/Thread/ThreadContainer.d.ts +10 -0
  174. package/dist/types/src/components/Thread/ThreadContainer.d.ts.map +1 -0
  175. package/dist/types/src/components/Thread/ThreadContainer.stories.d.ts +15 -0
  176. package/dist/types/src/components/Thread/ThreadContainer.stories.d.ts.map +1 -0
  177. package/dist/types/src/components/Thread/ThreadMessage.d.ts +13 -0
  178. package/dist/types/src/components/Thread/ThreadMessage.d.ts.map +1 -0
  179. package/dist/types/src/components/Thread/ToolInvocations.d.ts +13 -0
  180. package/dist/types/src/components/Thread/ToolInvocations.d.ts.map +1 -0
  181. package/dist/types/src/components/Thread/index.d.ts +3 -0
  182. package/dist/types/src/components/Thread/index.d.ts.map +1 -0
  183. package/dist/types/src/components/Thread/reducer.d.ts +12 -0
  184. package/dist/types/src/components/Thread/reducer.d.ts.map +1 -0
  185. package/dist/types/src/components/Toolbox/Toolbox.d.ts +19 -0
  186. package/dist/types/src/components/Toolbox/Toolbox.d.ts.map +1 -0
  187. package/dist/types/src/components/Toolbox/Toolbox.stories.d.ts +8 -0
  188. package/dist/types/src/components/Toolbox/Toolbox.stories.d.ts.map +1 -0
  189. package/dist/types/src/components/Toolbox/index.d.ts +2 -0
  190. package/dist/types/src/components/Toolbox/index.d.ts.map +1 -0
  191. package/dist/types/src/components/TriggerEditor/TriggerEditor.d.ts +1 -2
  192. package/dist/types/src/components/TriggerEditor/TriggerEditor.d.ts.map +1 -1
  193. package/dist/types/src/components/index.d.ts +19 -2
  194. package/dist/types/src/components/index.d.ts.map +1 -1
  195. package/dist/types/src/hooks/index.d.ts +5 -0
  196. package/dist/types/src/hooks/index.d.ts.map +1 -1
  197. package/dist/types/src/hooks/processor.d.ts +75 -0
  198. package/dist/types/src/hooks/processor.d.ts.map +1 -0
  199. package/dist/types/src/hooks/processor.test.d.ts +2 -0
  200. package/dist/types/src/hooks/processor.test.d.ts.map +1 -0
  201. package/dist/types/src/hooks/useChatProcessor.d.ts +8 -0
  202. package/dist/types/src/hooks/useChatProcessor.d.ts.map +1 -0
  203. package/dist/types/src/hooks/useMessageQueue.d.ts +41 -0
  204. package/dist/types/src/hooks/useMessageQueue.d.ts.map +1 -0
  205. package/dist/types/src/hooks/useServices.d.ts +7 -0
  206. package/dist/types/src/hooks/useServices.d.ts.map +1 -0
  207. package/dist/types/src/hooks/useTextInputEvents.d.ts +13 -0
  208. package/dist/types/src/hooks/useTextInputEvents.d.ts.map +1 -0
  209. package/dist/types/src/index.d.ts +1 -2
  210. package/dist/types/src/index.d.ts.map +1 -1
  211. package/dist/types/src/meta.d.ts +1 -0
  212. package/dist/types/src/meta.d.ts.map +1 -1
  213. package/dist/types/src/testing/index.d.ts +2 -1
  214. package/dist/types/src/testing/index.d.ts.map +1 -1
  215. package/dist/types/src/testing/{testing.d.ts → test-functions.d.ts} +3 -1
  216. package/dist/types/src/testing/test-functions.d.ts.map +1 -0
  217. package/dist/types/src/testing/test-services.d.ts +5 -0
  218. package/dist/types/src/testing/test-services.d.ts.map +1 -0
  219. package/dist/types/src/tools/function.d.ts +5 -0
  220. package/dist/types/src/tools/function.d.ts.map +1 -0
  221. package/dist/types/src/tools/index.d.ts +3 -0
  222. package/dist/types/src/tools/index.d.ts.map +1 -0
  223. package/dist/types/src/tools/openapi.d.ts +10 -0
  224. package/dist/types/src/tools/openapi.d.ts.map +1 -0
  225. package/dist/types/src/tools/openapi.test.d.ts +2 -0
  226. package/dist/types/src/tools/openapi.test.d.ts.map +1 -0
  227. package/dist/types/src/translations.d.ts +110 -2
  228. package/dist/types/src/translations.d.ts.map +1 -1
  229. package/dist/types/src/types/chat.d.ts +12 -0
  230. package/dist/types/src/types/chat.d.ts.map +1 -0
  231. package/dist/types/src/types/index.d.ts +4 -1
  232. package/dist/types/src/types/index.d.ts.map +1 -1
  233. package/dist/types/src/types/service.d.ts +160 -0
  234. package/dist/types/src/types/service.d.ts.map +1 -0
  235. package/dist/types/src/types/template.d.ts +40 -0
  236. package/dist/types/src/types/template.d.ts.map +1 -0
  237. package/dist/types/src/types/types.d.ts +37 -0
  238. package/dist/types/src/types/types.d.ts.map +1 -0
  239. package/package.json +62 -40
  240. package/src/AutomationPlugin.tsx +68 -21
  241. package/src/capabilities/ai-client.ts +19 -0
  242. package/src/capabilities/app-graph-builder.ts +82 -110
  243. package/src/capabilities/capabilities.ts +12 -0
  244. package/src/capabilities/index.ts +5 -0
  245. package/src/capabilities/intent-resolver.ts +38 -0
  246. package/src/capabilities/react-surface.tsx +42 -6
  247. package/src/capabilities/settings.ts +19 -0
  248. package/src/components/AmbientDialog/AmbientDialog.stories.tsx +81 -0
  249. package/src/components/AmbientDialog/AmbientDialog.tsx +103 -0
  250. package/src/components/AmbientDialog/index.ts +5 -0
  251. package/src/components/AssistantDialog.tsx +33 -0
  252. package/src/components/AutomationPanel/AutomationPanel.stories.tsx +2 -2
  253. package/src/components/AutomationSettings/AutomationSettings.tsx +49 -0
  254. package/src/components/AutomationSettings/index.ts +5 -0
  255. package/src/components/ChatContainer.tsx +29 -0
  256. package/src/components/Prompt/Prompt.stories.tsx +79 -0
  257. package/src/components/Prompt/Prompt.tsx +100 -0
  258. package/src/components/Prompt/PromptBar.tsx +100 -0
  259. package/src/components/Prompt/autocomplete.ts +212 -0
  260. package/src/components/Prompt/index.ts +6 -0
  261. package/src/components/ServiceRegistry/ServiceRegistry.stories.tsx +49 -0
  262. package/src/components/ServiceRegistry/ServiceRegistry.tsx +76 -0
  263. package/src/components/ServiceRegistry/index.ts +5 -0
  264. package/src/components/TemplateContainer.tsx +21 -0
  265. package/src/components/TemplateEditor/TemplateEditor.stories.tsx +72 -0
  266. package/src/components/TemplateEditor/TemplateEditor.tsx +76 -0
  267. package/src/components/TemplateEditor/TemplateForm.stories.tsx +65 -0
  268. package/src/components/TemplateEditor/TemplateForm.tsx +184 -0
  269. package/src/components/{PromptEditor → TemplateEditor}/index.ts +1 -1
  270. package/src/components/Thread/Thread.stories.tsx +212 -0
  271. package/src/components/Thread/Thread.tsx +97 -0
  272. package/src/components/Thread/ThreadContainer.stories.tsx +258 -0
  273. package/src/components/Thread/ThreadContainer.tsx +78 -0
  274. package/src/components/Thread/ThreadMessage.tsx +187 -0
  275. package/src/components/Thread/ToolInvocations.tsx +93 -0
  276. package/src/components/Thread/index.ts +6 -0
  277. package/src/components/Thread/reducer.ts +52 -0
  278. package/src/components/Toolbox/Toolbox.stories.tsx +65 -0
  279. package/src/components/Toolbox/Toolbox.tsx +117 -0
  280. package/src/components/Toolbox/index.ts +5 -0
  281. package/src/components/TriggerEditor/TriggerEditor.stories.tsx +2 -2
  282. package/src/components/TriggerEditor/TriggerEditor.tsx +25 -18
  283. package/src/components/index.ts +11 -1
  284. package/src/hooks/index.ts +6 -0
  285. package/src/hooks/processor.test.ts +15 -0
  286. package/src/hooks/processor.ts +219 -0
  287. package/src/hooks/useChatProcessor.tsx +77 -0
  288. package/src/hooks/useMessageQueue.ts +23 -0
  289. package/src/hooks/useServices.ts +28 -0
  290. package/src/hooks/useTextInputEvents.ts +49 -0
  291. package/src/index.ts +2 -2
  292. package/src/meta.ts +4 -1
  293. package/src/testing/index.ts +2 -1
  294. package/src/testing/{testing.ts → test-functions.ts} +9 -2
  295. package/src/testing/test-services.ts +131 -0
  296. package/src/tools/function.ts +47 -0
  297. package/src/tools/index.ts +6 -0
  298. package/src/tools/openapi.test.ts +224 -0
  299. package/src/tools/openapi.ts +331 -0
  300. package/src/translations.ts +27 -2
  301. package/src/types/chat.ts +11 -0
  302. package/src/types/index.ts +4 -1
  303. package/src/types/service.ts +102 -0
  304. package/src/types/template.ts +34 -0
  305. package/src/types/types.ts +41 -0
  306. package/src/typings.d.ts +9 -0
  307. package/dist/lib/browser/AssistantPanel-N276BTPV.mjs +0 -339
  308. package/dist/lib/browser/AssistantPanel-N276BTPV.mjs.map +0 -7
  309. package/dist/lib/browser/AutomationPanel-IHZ4JKVS.mjs.map +0 -7
  310. package/dist/lib/browser/app-graph-builder-IJTTULDP.mjs +0 -131
  311. package/dist/lib/browser/app-graph-builder-IJTTULDP.mjs.map +0 -7
  312. package/dist/lib/browser/chunk-4AIMDHKY.mjs +0 -10
  313. package/dist/lib/browser/chunk-4AIMDHKY.mjs.map +0 -7
  314. package/dist/lib/browser/chunk-DL6LB2NI.mjs +0 -43
  315. package/dist/lib/browser/chunk-DL6LB2NI.mjs.map +0 -7
  316. package/dist/lib/browser/chunk-HKX3D3ZP.mjs.map +0 -7
  317. package/dist/lib/browser/react-surface-LL72F3F4.mjs +0 -34
  318. package/dist/lib/browser/react-surface-LL72F3F4.mjs.map +0 -7
  319. package/dist/lib/node/AssistantPanel-Z4GVHUF3.cjs +0 -359
  320. package/dist/lib/node/AssistantPanel-Z4GVHUF3.cjs.map +0 -7
  321. package/dist/lib/node/AutomationPanel-PPODB5XA.cjs.map +0 -7
  322. package/dist/lib/node/app-graph-builder-MF5M4QRS.cjs +0 -147
  323. package/dist/lib/node/app-graph-builder-MF5M4QRS.cjs.map +0 -7
  324. package/dist/lib/node/chunk-25AQIF3L.cjs.map +0 -7
  325. package/dist/lib/node/chunk-5VF5JKUN.cjs.map +0 -7
  326. package/dist/lib/node/chunk-JNDMZQH7.cjs +0 -68
  327. package/dist/lib/node/chunk-JNDMZQH7.cjs.map +0 -7
  328. package/dist/lib/node/react-surface-DVAU4MGD.cjs.map +0 -7
  329. package/dist/lib/node-esm/AssistantPanel-DDCQHBJX.mjs +0 -340
  330. package/dist/lib/node-esm/AssistantPanel-DDCQHBJX.mjs.map +0 -7
  331. package/dist/lib/node-esm/AutomationPanel-R3D6CRF5.mjs.map +0 -7
  332. package/dist/lib/node-esm/app-graph-builder-5N7OK23B.mjs +0 -132
  333. package/dist/lib/node-esm/app-graph-builder-5N7OK23B.mjs.map +0 -7
  334. package/dist/lib/node-esm/chunk-GIAYUM5I.mjs +0 -45
  335. package/dist/lib/node-esm/chunk-GIAYUM5I.mjs.map +0 -7
  336. package/dist/lib/node-esm/chunk-X3LPRWIL.mjs.map +0 -7
  337. package/dist/lib/node-esm/chunk-XW7TEQA3.mjs +0 -12
  338. package/dist/lib/node-esm/chunk-XW7TEQA3.mjs.map +0 -7
  339. package/dist/lib/node-esm/react-surface-4BED2PZ4.mjs +0 -35
  340. package/dist/lib/node-esm/react-surface-4BED2PZ4.mjs.map +0 -7
  341. package/dist/types/src/components/AssistantPanel/AssistantPanel.d.ts +0 -8
  342. package/dist/types/src/components/AssistantPanel/AssistantPanel.d.ts.map +0 -1
  343. package/dist/types/src/components/AssistantPanel/index.d.ts +0 -3
  344. package/dist/types/src/components/AssistantPanel/index.d.ts.map +0 -1
  345. package/dist/types/src/components/AssistantPanel/system-instructions.d.ts +0 -6
  346. package/dist/types/src/components/AssistantPanel/system-instructions.d.ts.map +0 -1
  347. package/dist/types/src/components/PromptEditor/PromptEditor.d.ts +0 -10
  348. package/dist/types/src/components/PromptEditor/PromptEditor.d.ts.map +0 -1
  349. package/dist/types/src/components/PromptEditor/PromptEditor.stories.d.ts +0 -6
  350. package/dist/types/src/components/PromptEditor/PromptEditor.stories.d.ts.map +0 -1
  351. package/dist/types/src/components/PromptEditor/index.d.ts +0 -2
  352. package/dist/types/src/components/PromptEditor/index.d.ts.map +0 -1
  353. package/dist/types/src/components/PromptEditor/prompt-extension.d.ts +0 -4
  354. package/dist/types/src/components/PromptEditor/prompt-extension.d.ts.map +0 -1
  355. package/dist/types/src/components/PromptEditor/types.d.ts.map +0 -1
  356. package/dist/types/src/presets.d.ts +0 -9
  357. package/dist/types/src/presets.d.ts.map +0 -1
  358. package/dist/types/src/testing/testing.d.ts.map +0 -1
  359. package/dist/types/src/types/schema.d.ts +0 -63
  360. package/dist/types/src/types/schema.d.ts.map +0 -1
  361. package/src/components/AssistantPanel/AssistantPanel.tsx +0 -230
  362. package/src/components/AssistantPanel/index.ts +0 -7
  363. package/src/components/AssistantPanel/system-instructions.ts +0 -166
  364. package/src/components/PromptEditor/PromptEditor.stories.tsx +0 -64
  365. package/src/components/PromptEditor/PromptEditor.tsx +0 -222
  366. package/src/components/PromptEditor/prompt-extension.ts +0 -43
  367. package/src/presets.ts +0 -248
  368. package/src/types/schema.ts +0 -38
  369. /package/dist/types/src/components/{PromptEditor → TemplateEditor}/types.d.ts +0 -0
  370. /package/src/components/{PromptEditor → TemplateEditor}/types.tsx +0 -0
@@ -0,0 +1,1818 @@
1
+ import {
2
+ AutomationCapabilities
3
+ } from "./chunk-67KDIIM6.mjs";
4
+ import {
5
+ ServiceType,
6
+ categoryIcons
7
+ } from "./chunk-62E2AEXF.mjs";
8
+ import {
9
+ AUTOMATION_PLUGIN
10
+ } from "./chunk-HZSTXZWK.mjs";
11
+
12
+ // packages/plugins/experimental/plugin-automation/src/components/Toolbox/Toolbox.tsx
13
+ import React, { useState, useEffect, Fragment } from "react";
14
+ import { Capabilities, useCapabilities } from "@dxos/app-framework";
15
+ import { FunctionType } from "@dxos/functions";
16
+ import { log as log3 } from "@dxos/log";
17
+ import { Filter, useQuery } from "@dxos/react-client/echo";
18
+ import { mx } from "@dxos/react-ui-theme";
19
+
20
+ // packages/plugins/experimental/plugin-automation/src/tools/function.ts
21
+ import { defineTool, ToolResult } from "@dxos/artifact";
22
+ import { toEffectSchema } from "@dxos/echo-schema";
23
+ import { getInvocationUrl, getUserFunctionUrlInMetadata } from "@dxos/functions";
24
+ import { log } from "@dxos/log";
25
+ import { getMeta } from "@dxos/react-client/echo";
26
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-automation/src/tools/function.ts";
27
+ var covertFunctionToTool = (fn, edgeUrl, spaceId) => {
28
+ if (!fn.description || !fn.inputSchema) {
29
+ return void 0;
30
+ }
31
+ const existingFunctionUrl = getUserFunctionUrlInMetadata(getMeta(fn));
32
+ if (!existingFunctionUrl) {
33
+ return void 0;
34
+ }
35
+ const url = getInvocationUrl(existingFunctionUrl, edgeUrl, {
36
+ spaceId
37
+ });
38
+ return defineTool({
39
+ name: fn.name,
40
+ description: fn.description,
41
+ schema: toEffectSchema(fn.inputSchema),
42
+ execute: async (input) => {
43
+ log.info("execute function tool", {
44
+ name: fn.name,
45
+ url,
46
+ input
47
+ }, {
48
+ F: __dxlog_file,
49
+ L: 36,
50
+ S: void 0,
51
+ C: (f, a) => f(...a)
52
+ });
53
+ const response = await fetch(url, {
54
+ method: "POST",
55
+ headers: {
56
+ "Content-Type": "application/json"
57
+ },
58
+ body: JSON.stringify(input)
59
+ });
60
+ return ToolResult.Success(await response.text());
61
+ }
62
+ });
63
+ };
64
+
65
+ // packages/plugins/experimental/plugin-automation/src/tools/openapi.ts
66
+ import jsonpointer from "jsonpointer";
67
+ import { ToolResult as ToolResult2 } from "@dxos/artifact";
68
+ import { JsonSchemaType, normalizeSchema, S, toEffectSchema as toEffectSchema2 } from "@dxos/echo-schema";
69
+ import { invariant } from "@dxos/invariant";
70
+ import { log as log2 } from "@dxos/log";
71
+ import { deepMapValues } from "@dxos/util";
72
+ var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-automation/src/tools/openapi.ts";
73
+ var createToolsFromService = async (service) => {
74
+ invariant(service.interfaces?.length === 1 && service.interfaces[0].kind === "api", void 0, {
75
+ F: __dxlog_file2,
76
+ L: 22,
77
+ S: void 0,
78
+ A: [
79
+ "service.interfaces?.length === 1 && service.interfaces[0].kind === 'api'",
80
+ ""
81
+ ]
82
+ });
83
+ const iface = service.interfaces[0];
84
+ invariant(iface.schemaUrl, void 0, {
85
+ F: __dxlog_file2,
86
+ L: 24,
87
+ S: void 0,
88
+ A: [
89
+ "iface.schemaUrl",
90
+ ""
91
+ ]
92
+ });
93
+ invariant(iface.schemaUrl, void 0, {
94
+ F: __dxlog_file2,
95
+ L: 25,
96
+ S: void 0,
97
+ A: [
98
+ "iface.schemaUrl",
99
+ ""
100
+ ]
101
+ });
102
+ return createToolsFromApi(iface.schemaUrl, {
103
+ authorization: iface.authorization
104
+ });
105
+ };
106
+ var createToolsFromApi = async (url, options) => {
107
+ const res = await fetch(url);
108
+ const spec = await res.json();
109
+ log2("spec", {
110
+ spec
111
+ }, {
112
+ F: __dxlog_file2,
113
+ L: 32,
114
+ S: void 0,
115
+ C: (f, a) => f(...a)
116
+ });
117
+ const tools = [];
118
+ for (const [path, pathItem] of Object.entries(spec.paths)) {
119
+ if (typeof pathItem !== "object") {
120
+ continue;
121
+ }
122
+ const { ...methods } = pathItem;
123
+ for (const [method, m] of Object.entries(methods)) {
124
+ const methodItem = m;
125
+ log2("methodItem", {
126
+ path,
127
+ method,
128
+ methodItem
129
+ }, {
130
+ F: __dxlog_file2,
131
+ L: 44,
132
+ S: void 0,
133
+ C: (f, a) => f(...a)
134
+ });
135
+ const parametersResolved = methodItem.parameters?.map((parameter) => {
136
+ const resolved = resolveJsonSchema(parameter, spec);
137
+ return resolved;
138
+ }) ?? [];
139
+ const inputSchema = {
140
+ type: "object",
141
+ properties: {}
142
+ };
143
+ const endpointParameters = [];
144
+ for (const parameter of parametersResolved) {
145
+ log2("parameter", {
146
+ parameter
147
+ }, {
148
+ F: __dxlog_file2,
149
+ L: 59,
150
+ S: void 0,
151
+ C: (f, a) => f(...a)
152
+ });
153
+ if (options?.authorization?.type === "api-key" && options.authorization.placement.type === "query" && parameter.in === "query" && parameter.name === options.authorization.placement.name) {
154
+ continue;
155
+ }
156
+ endpointParameters.push(parameter);
157
+ if (parameter.schema) {
158
+ inputSchema.properties[parameter.name] = normalizeSchema(parameter.schema);
159
+ } else if (typeof parameter.type === "string") {
160
+ const { name, in: _in, required, ...schema } = parameter;
161
+ inputSchema.properties[name] = normalizeSchema(schema);
162
+ if (required) {
163
+ inputSchema.required ??= [];
164
+ inputSchema.required.push(name);
165
+ }
166
+ }
167
+ }
168
+ log2("inputSchema", {
169
+ inputSchema
170
+ }, {
171
+ F: __dxlog_file2,
172
+ L: 84,
173
+ S: void 0,
174
+ C: (f, a) => f(...a)
175
+ });
176
+ S.validateSync(JsonSchemaType)(inputSchema);
177
+ const description = methodItem.description ?? methodItem.summary;
178
+ if (!description) {
179
+ log2.warn("no description", {
180
+ path,
181
+ method
182
+ }, {
183
+ F: __dxlog_file2,
184
+ L: 89,
185
+ S: void 0,
186
+ C: (f, a) => f(...a)
187
+ });
188
+ continue;
189
+ }
190
+ const endpoint = {
191
+ document: spec,
192
+ path,
193
+ method,
194
+ parameters: endpointParameters,
195
+ authorization: options?.authorization
196
+ };
197
+ tools.push({
198
+ name: getToolName(path, method, methodItem),
199
+ description: options?.instructions ? `${options.instructions}
200
+
201
+ ${description}` : description,
202
+ parameters: inputSchema,
203
+ execute: async (input) => {
204
+ const response = await callApiEndpoint(endpoint, input);
205
+ return ToolResult2.Success(response);
206
+ }
207
+ });
208
+ }
209
+ }
210
+ return tools;
211
+ };
212
+ var getToolName = (path, method, methodItem) => {
213
+ if (methodItem.operationId) {
214
+ return methodItem.operationId;
215
+ }
216
+ let name = `${method.toLowerCase()}_${path.replaceAll(/[{}/]/g, "_")}`;
217
+ while (name.length > MAX_TOOL_NAME_LENGTH) {
218
+ const lengthBefore = name.length;
219
+ for (const word of GENERIC_WORDS) {
220
+ if (name.includes(word)) {
221
+ name = name.replace(word, "");
222
+ break;
223
+ }
224
+ }
225
+ name = name.replaceAll("__", "_").replace(/_$/, "");
226
+ const lengthAfter = name.length;
227
+ if (lengthBefore === lengthAfter) {
228
+ break;
229
+ }
230
+ }
231
+ name = name.replaceAll("__", "_").replace(/_$/, "").replace(/^_/, "");
232
+ return name.slice(0, MAX_TOOL_NAME_LENGTH);
233
+ };
234
+ var MAX_TOOL_NAME_LENGTH = 64;
235
+ var GENERIC_WORDS = [
236
+ "services",
237
+ "service",
238
+ "api",
239
+ "rest",
240
+ "endpoint",
241
+ "get",
242
+ "post",
243
+ "put",
244
+ "delete",
245
+ "patch",
246
+ "head",
247
+ "options",
248
+ "trace",
249
+ "service",
250
+ "api",
251
+ "endpoint"
252
+ ];
253
+ var callApiEndpoint = async (endpoint, input) => {
254
+ log2.info("endpoint", {
255
+ method: endpoint.method,
256
+ name: endpoint.path,
257
+ input
258
+ }, {
259
+ F: __dxlog_file2,
260
+ L: 173,
261
+ S: void 0,
262
+ C: (f, a) => f(...a)
263
+ });
264
+ let url = getEndpointUrl(endpoint);
265
+ const request = {
266
+ method: endpoint.method,
267
+ headers: {}
268
+ };
269
+ const query = new URLSearchParams();
270
+ let body;
271
+ for (const parameter of endpoint.parameters) {
272
+ if (input[parameter.name] === void 0) {
273
+ continue;
274
+ }
275
+ switch (parameter.in) {
276
+ case "header": {
277
+ if (parameter.example) {
278
+ request.headers[parameter.name] = parameter.default;
279
+ }
280
+ break;
281
+ }
282
+ case "path": {
283
+ url = url.replace(`{${parameter.name}}`, encodeURIComponent(input[parameter.name]));
284
+ break;
285
+ }
286
+ case "body": {
287
+ const value = input[parameter.name];
288
+ const effectSchema = toEffectSchema2(parameter.schema);
289
+ S.validateSync(effectSchema)(value);
290
+ if (body) {
291
+ throw new Error(`Duplicate body parameter: ${parameter.name}`);
292
+ }
293
+ body = value;
294
+ break;
295
+ }
296
+ case "query": {
297
+ query.set(parameter.name, input[parameter.name]);
298
+ break;
299
+ }
300
+ }
301
+ }
302
+ if (endpoint.authorization?.type === "api-key" && endpoint.authorization.placement.type === "authorization-header" || endpoint.authorization?.type === "oauth") {
303
+ request.headers.Authorization = await resolveAuthorization(endpoint.authorization);
304
+ } else if (endpoint.authorization?.type === "api-key" && endpoint.authorization.placement.type === "query") {
305
+ query.set(endpoint.authorization.placement.name, endpoint.authorization.key);
306
+ }
307
+ if (query.size > 0) {
308
+ url += `?${query.toString()}`;
309
+ }
310
+ if (body) {
311
+ request.body = JSON.stringify(body);
312
+ request.headers["Content-Type"] = "application/json";
313
+ }
314
+ log2.info("request", {
315
+ url,
316
+ request
317
+ }, {
318
+ F: __dxlog_file2,
319
+ L: 236,
320
+ S: void 0,
321
+ C: (f, a) => f(...a)
322
+ });
323
+ const response = await fetch(url, request);
324
+ log2.info("response", {
325
+ ok: response.ok,
326
+ status: response.status,
327
+ statusText: response.statusText
328
+ }, {
329
+ F: __dxlog_file2,
330
+ L: 239,
331
+ S: void 0,
332
+ C: (f, a) => f(...a)
333
+ });
334
+ if (response.ok) {
335
+ const contentType = response.headers.get("Content-Type");
336
+ if (contentType?.includes("application/json")) {
337
+ return await response.json();
338
+ } else {
339
+ return await response.text();
340
+ }
341
+ } else {
342
+ if (response.headers.get("Content-Type")?.includes("application/json")) {
343
+ const responseBody = await response.text();
344
+ let error;
345
+ try {
346
+ error = JSON.parse(responseBody);
347
+ } catch {
348
+ error = responseBody;
349
+ }
350
+ log2.error("error", {
351
+ error
352
+ }, {
353
+ F: __dxlog_file2,
354
+ L: 257,
355
+ S: void 0,
356
+ C: (f, a) => f(...a)
357
+ });
358
+ throw new Error(error.message);
359
+ } else {
360
+ const error = await response.text();
361
+ log2.error("error", {
362
+ error
363
+ }, {
364
+ F: __dxlog_file2,
365
+ L: 261,
366
+ S: void 0,
367
+ C: (f, a) => f(...a)
368
+ });
369
+ throw new Error(error);
370
+ }
371
+ }
372
+ };
373
+ var getEndpointUrl = (endpoint) => {
374
+ let url = "";
375
+ if (isV3_1(endpoint.document) && endpoint.document.servers && endpoint.document.servers.length > 0) {
376
+ url = endpoint.document.servers[0].url;
377
+ } else {
378
+ invariant(!isV3_1(endpoint.document), void 0, {
379
+ F: __dxlog_file2,
380
+ L: 272,
381
+ S: void 0,
382
+ A: [
383
+ "!isV3_1(endpoint.document)",
384
+ ""
385
+ ]
386
+ });
387
+ url = `${endpoint.document.schemes?.[0] ?? "https"}://${endpoint.document.host}`;
388
+ }
389
+ if (!isV3_1(endpoint.document) && endpoint.document.basePath) {
390
+ url += endpoint.document.basePath;
391
+ }
392
+ url += endpoint.path;
393
+ return url;
394
+ };
395
+ var resolveAuthorization = async (authorization) => {
396
+ switch (authorization.type) {
397
+ case "api-key": {
398
+ invariant(authorization.placement.type === "authorization-header", void 0, {
399
+ F: __dxlog_file2,
400
+ L: 288,
401
+ S: void 0,
402
+ A: [
403
+ "authorization.placement.type === 'authorization-header'",
404
+ ""
405
+ ]
406
+ });
407
+ return `Bearer ${authorization.key}`;
408
+ }
409
+ case "oauth": {
410
+ const response = await fetch(authorization.tokenUrl, {
411
+ method: "POST",
412
+ headers: {
413
+ "Content-Type": "application/x-www-form-urlencoded"
414
+ },
415
+ body: `grant_type=${authorization.grantType}&client_id=${authorization.clientId}&client_secret=${authorization.clientSecret}`
416
+ });
417
+ const data = await response.json();
418
+ return `Bearer ${data.access_token}`;
419
+ }
420
+ default: {
421
+ throw new Error(`Unknown authorization type: ${authorization.type}`);
422
+ }
423
+ }
424
+ };
425
+ var resolveJsonSchema = (schema, base) => {
426
+ return deepMapValues(schema, (value, recurse) => {
427
+ if (typeof value === "object" && value !== null && "$ref" in value && typeof value.$ref === "string") {
428
+ if (value.$ref.startsWith("#")) {
429
+ const resolved = jsonpointer.get(base, value.$ref.slice(1));
430
+ if (resolved) {
431
+ return recurse(resolved);
432
+ } else {
433
+ log2.warn("unresolved", {
434
+ ref: value.$ref,
435
+ base
436
+ }, {
437
+ F: __dxlog_file2,
438
+ L: 321,
439
+ S: void 0,
440
+ C: (f, a) => f(...a)
441
+ });
442
+ }
443
+ }
444
+ }
445
+ return recurse(value);
446
+ });
447
+ };
448
+ var isV3_1 = (document2) => {
449
+ return document2.openapi === "3.0.1";
450
+ };
451
+
452
+ // packages/plugins/experimental/plugin-automation/src/components/Toolbox/Toolbox.tsx
453
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-automation/src/components/Toolbox/Toolbox.tsx";
454
+ var stripeClassNames = "odd:bg-neutral-50 dark:odd:bg-neutral-800";
455
+ var Toolbox = ({ classNames, artifacts, functions: functions2, services, striped }) => {
456
+ const gridClassNames = "grid grid-cols-[8rem_8rem_1fr]";
457
+ const subGridClassNames = mx("col-span-full grid grid-cols-subgrid text-xs px-2", striped && stripeClassNames);
458
+ return /* @__PURE__ */ React.createElement("div", {
459
+ className: mx("flex flex-col overflow-y-auto box-content", classNames)
460
+ }, artifacts && artifacts.length > 0 && /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement("h1", {
461
+ className: "px-2 text-sm"
462
+ }, "Artifacts"), /* @__PURE__ */ React.createElement("div", {
463
+ className: gridClassNames
464
+ }, artifacts.map(({ id, description, tools }) => /* @__PURE__ */ React.createElement(Fragment, {
465
+ key: id
466
+ }, /* @__PURE__ */ React.createElement("div", {
467
+ className: subGridClassNames
468
+ }, /* @__PURE__ */ React.createElement("div", {
469
+ className: "text-primary-500 truncate"
470
+ }, id), /* @__PURE__ */ React.createElement("div", {
471
+ className: "col-span-2 line-clamp-2"
472
+ }, description)), tools.map(({ name, description: description2 }, i) => /* @__PURE__ */ React.createElement("div", {
473
+ key: `${name}-${i}`,
474
+ className: subGridClassNames
475
+ }, /* @__PURE__ */ React.createElement("div", null), /* @__PURE__ */ React.createElement("div", {
476
+ className: "truncate"
477
+ }, name), /* @__PURE__ */ React.createElement("div", {
478
+ className: "text-subdued line-clamp-3"
479
+ }, description2))))))), services && services.length > 0 && /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement("h1", {
480
+ className: "px-2 text-sm"
481
+ }, "Services"), /* @__PURE__ */ React.createElement("div", {
482
+ className: gridClassNames
483
+ }, services.map(({ service, tools }) => /* @__PURE__ */ React.createElement(Fragment, {
484
+ key: service.serviceId
485
+ }, /* @__PURE__ */ React.createElement("div", {
486
+ className: subGridClassNames
487
+ }, /* @__PURE__ */ React.createElement("div", {
488
+ className: "text-primary-500 truncate"
489
+ }, service.name ?? service.serviceId), /* @__PURE__ */ React.createElement("div", {
490
+ className: "col-span-2 line-clamp-2"
491
+ }, service.description)), tools.map(({ name, description }, i) => /* @__PURE__ */ React.createElement("div", {
492
+ key: name,
493
+ className: mx(subGridClassNames, striped && stripeClassNames)
494
+ }, /* @__PURE__ */ React.createElement("div", {
495
+ className: "text-primary-500 truncate"
496
+ }, i === 0 && service.serviceId), /* @__PURE__ */ React.createElement("div", {
497
+ className: "truncate"
498
+ }, name), /* @__PURE__ */ React.createElement("div", {
499
+ className: "truncate"
500
+ }, description))))))), functions2 && functions2.length > 0 && /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement("h1", {
501
+ className: "px-2 text-sm"
502
+ }, "Functions"), /* @__PURE__ */ React.createElement("div", {
503
+ className: gridClassNames
504
+ }, functions2.map(({ name, description }) => /* @__PURE__ */ React.createElement("div", {
505
+ key: name,
506
+ className: mx(subGridClassNames, striped && stripeClassNames)
507
+ }, /* @__PURE__ */ React.createElement("div", {
508
+ className: "text-primary-500 truncate"
509
+ }, "function"), /* @__PURE__ */ React.createElement("div", {
510
+ className: "truncate"
511
+ }, name), /* @__PURE__ */ React.createElement("div", {
512
+ className: "truncate"
513
+ }, description))))));
514
+ };
515
+ var ToolboxContainer = ({ classNames, space }) => {
516
+ const artifactDefinitions = useCapabilities(Capabilities.ArtifactDefinition);
517
+ const functions2 = useQuery(space, Filter.schema(FunctionType));
518
+ const services = useQuery(space, Filter.schema(ServiceType));
519
+ const [serviceTools, setServiceTools] = useState([]);
520
+ useEffect(() => {
521
+ log3("creating service tools...", void 0, {
522
+ F: __dxlog_file3,
523
+ L: 104,
524
+ S: void 0,
525
+ C: (f, a) => f(...a)
526
+ });
527
+ queueMicrotask(async () => {
528
+ const tools = await Promise.all(services.map(async (service) => ({
529
+ service,
530
+ tools: await createToolsFromService(service)
531
+ })));
532
+ setServiceTools(tools);
533
+ });
534
+ }, [
535
+ services
536
+ ]);
537
+ return /* @__PURE__ */ React.createElement(Toolbox, {
538
+ classNames,
539
+ artifacts: artifactDefinitions,
540
+ functions: functions2,
541
+ services: serviceTools
542
+ });
543
+ };
544
+
545
+ // packages/plugins/experimental/plugin-automation/src/components/Thread/Thread.tsx
546
+ import React6, { useCallback, useMemo as useMemo2, useRef as useRef3 } from "react";
547
+ import { useIdentity } from "@dxos/react-client/halo";
548
+ import { ScrollContainer } from "@dxos/react-ui-components";
549
+ import { mx as mx5 } from "@dxos/react-ui-theme";
550
+ import { keyToFallback } from "@dxos/util";
551
+
552
+ // packages/plugins/experimental/plugin-automation/src/components/Thread/ThreadMessage.tsx
553
+ import React3 from "react";
554
+ import { invariant as invariant2 } from "@dxos/invariant";
555
+ import { Button, ButtonGroup, Icon, IconButton } from "@dxos/react-ui";
556
+ import { MarkdownViewer, ToggleContainer as NativeToggleContainer } from "@dxos/react-ui-components";
557
+ import { Json as Json2 } from "@dxos/react-ui-syntax-highlighter";
558
+ import { mx as mx2 } from "@dxos/react-ui-theme";
559
+ import { safeParseJson } from "@dxos/util";
560
+
561
+ // packages/plugins/experimental/plugin-automation/src/components/Thread/ToolInvocations.tsx
562
+ import React2, { useEffect as useEffect2, useMemo, useRef, useState as useState2 } from "react";
563
+ import { log as log4 } from "@dxos/log";
564
+ import { NumericTabs, StatusRoll, ToggleContainer } from "@dxos/react-ui-components";
565
+ import { Json } from "@dxos/react-ui-syntax-highlighter";
566
+ import { isNonNullable, isNotFalsy } from "@dxos/util";
567
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-automation/src/components/Thread/ToolInvocations.tsx";
568
+ var isToolMessage = (message) => {
569
+ return message.content.some((block) => block.type === "tool_use" || block.type === "tool_result");
570
+ };
571
+ var ToolBlock = ({ classNames, message }) => {
572
+ const { content = [] } = message;
573
+ let request;
574
+ const blocks = content.filter((block) => block.type === "tool_use" || block.type === "tool_result");
575
+ const items = blocks.map((block, i) => {
576
+ switch (block.type) {
577
+ case "tool_use": {
578
+ if (block.id === request?.id && block.pending) {
579
+ return null;
580
+ }
581
+ request = block;
582
+ return {
583
+ title: `Calling ${block.name}...`,
584
+ block
585
+ };
586
+ }
587
+ case "tool_result": {
588
+ if (!request) {
589
+ log4.warn("unexpected message", {
590
+ block
591
+ }, {
592
+ F: __dxlog_file4,
593
+ L: 41,
594
+ S: void 0,
595
+ C: (f, a) => f(...a)
596
+ });
597
+ return {
598
+ title: "Error",
599
+ block
600
+ };
601
+ }
602
+ return {
603
+ title: `Processed ${request.name}`,
604
+ block
605
+ };
606
+ }
607
+ default: {
608
+ request = void 0;
609
+ return {
610
+ title: "Error",
611
+ block
612
+ };
613
+ }
614
+ }
615
+ }).filter(isNonNullable);
616
+ return /* @__PURE__ */ React2.createElement(ToolContainer, {
617
+ classNames,
618
+ items
619
+ });
620
+ };
621
+ var ToolContainer = ({ classNames, items }) => {
622
+ const tabsRef = useRef(null);
623
+ const [selected, setSelected] = useState2(0);
624
+ const [open, setOpen] = useState2(false);
625
+ useEffect2(() => {
626
+ if (open) {
627
+ tabsRef.current?.focus();
628
+ }
629
+ }, [
630
+ open
631
+ ]);
632
+ const handleSelect = (index) => {
633
+ if (index === selected) {
634
+ setOpen(false);
635
+ } else {
636
+ setSelected(index);
637
+ }
638
+ };
639
+ const title = useMemo(() => {
640
+ const lines = items.map((item) => item.title).filter(isNotFalsy);
641
+ return /* @__PURE__ */ React2.createElement(StatusRoll, {
642
+ key: "status-roll",
643
+ lines,
644
+ autoAdvance: true
645
+ });
646
+ }, [
647
+ items
648
+ ]);
649
+ return /* @__PURE__ */ React2.createElement(ToggleContainer, {
650
+ classNames: [
651
+ "flex flex-col",
652
+ classNames
653
+ ],
654
+ title,
655
+ open,
656
+ onChangeOpen: setOpen
657
+ }, /* @__PURE__ */ React2.createElement("div", {
658
+ className: "grid grid-cols-[32px_1fr]"
659
+ }, /* @__PURE__ */ React2.createElement(NumericTabs, {
660
+ ref: tabsRef,
661
+ length: items.length,
662
+ selected,
663
+ onSelect: handleSelect
664
+ }), /* @__PURE__ */ React2.createElement(Json, {
665
+ data: items[selected].block,
666
+ classNames: "!p-1 text-xs"
667
+ })));
668
+ };
669
+
670
+ // packages/plugins/experimental/plugin-automation/src/components/Thread/ThreadMessage.tsx
671
+ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-automation/src/components/Thread/ThreadMessage.tsx";
672
+ var panelClassNames = "flex flex-col w-full px-2 bg-groupSurface rounded-md";
673
+ var userClassNames = "bg-[--user-fill]";
674
+ var ToggleContainer2 = (props) => {
675
+ return /* @__PURE__ */ React3.createElement(NativeToggleContainer, {
676
+ ...props,
677
+ classNames: mx2(panelClassNames, props.classNames)
678
+ });
679
+ };
680
+ var MessageContainer = ({ children, classNames, user }) => {
681
+ if (!children) {
682
+ return null;
683
+ }
684
+ return /* @__PURE__ */ React3.createElement("div", {
685
+ role: "list-item",
686
+ className: mx2("flex w-full", user && "justify-end", classNames)
687
+ }, /* @__PURE__ */ React3.createElement("div", {
688
+ className: mx2(user ? [
689
+ "px-2 py-1 rounded-md",
690
+ userClassNames
691
+ ] : "w-full")
692
+ }, children));
693
+ };
694
+ var ThreadMessage = ({ classNames, space, message, onPrompt }) => {
695
+ const { role, content = [] } = message;
696
+ if (isToolMessage(message)) {
697
+ return /* @__PURE__ */ React3.createElement(MessageContainer, {
698
+ classNames
699
+ }, /* @__PURE__ */ React3.createElement(ToolBlock, {
700
+ space,
701
+ classNames: panelClassNames,
702
+ message
703
+ }));
704
+ }
705
+ return content.map((block, idx) => {
706
+ if (block.type === "text" && block.text.replaceAll(/\s+/g, "").length === 0) {
707
+ return null;
708
+ }
709
+ const Component = components[block.type] ?? components.default;
710
+ return /* @__PURE__ */ React3.createElement(MessageContainer, {
711
+ key: idx,
712
+ classNames,
713
+ user: block.type === "text" && role === "user"
714
+ }, /* @__PURE__ */ React3.createElement(Component, {
715
+ space,
716
+ block,
717
+ onPrompt
718
+ }));
719
+ });
720
+ };
721
+ var components = {
722
+ //
723
+ // Text
724
+ //
725
+ ["text"]: ({ block }) => {
726
+ invariant2(block.type === "text", void 0, {
727
+ F: __dxlog_file5,
728
+ L: 85,
729
+ S: void 0,
730
+ A: [
731
+ "block.type === 'text'",
732
+ ""
733
+ ]
734
+ });
735
+ const title = block.disposition ? titles[block.disposition] : void 0;
736
+ if (!title) {
737
+ return /* @__PURE__ */ React3.createElement(MarkdownViewer, {
738
+ content: block.text
739
+ });
740
+ }
741
+ return /* @__PURE__ */ React3.createElement(ToggleContainer2, {
742
+ // open={open}
743
+ defaultOpen: block.disposition === "cot" && block.pending,
744
+ title,
745
+ icon: block.pending ? /* @__PURE__ */ React3.createElement(Icon, {
746
+ icon: "ph--circle-notch--regular",
747
+ classNames: "text-subdued ml-2 animate-spin",
748
+ size: 4
749
+ }) : void 0
750
+ }, /* @__PURE__ */ React3.createElement(MarkdownViewer, {
751
+ content: block.text,
752
+ classNames: [
753
+ "pbe-2",
754
+ block.disposition === "cot" && "text-sm text-subdued"
755
+ ]
756
+ }));
757
+ },
758
+ //
759
+ // JSON
760
+ //
761
+ ["json"]: ({ space, block, onPrompt }) => {
762
+ invariant2(block.type === "json", void 0, {
763
+ F: __dxlog_file5,
764
+ L: 123,
765
+ S: void 0,
766
+ A: [
767
+ "block.type === 'json'",
768
+ ""
769
+ ]
770
+ });
771
+ switch (block.disposition) {
772
+ case "tool_list": {
773
+ return /* @__PURE__ */ React3.createElement(ToggleContainer2, {
774
+ title: titles[block.disposition],
775
+ defaultOpen: true
776
+ }, /* @__PURE__ */ React3.createElement(ToolboxContainer, {
777
+ space,
778
+ classNames: "pbe-2"
779
+ }));
780
+ }
781
+ case "suggest": {
782
+ const { text = "" } = safeParseJson(block.json ?? "{}") ?? {};
783
+ return /* @__PURE__ */ React3.createElement(IconButton, {
784
+ icon: "ph--lightning--regular",
785
+ label: text,
786
+ onClick: () => onPrompt?.(text)
787
+ });
788
+ }
789
+ case "select": {
790
+ const { options = [] } = safeParseJson(block.json ?? "{}") ?? {};
791
+ return /* @__PURE__ */ React3.createElement(ButtonGroup, null, options.map((option) => /* @__PURE__ */ React3.createElement(Button, {
792
+ key: option,
793
+ onClick: () => onPrompt?.(option)
794
+ }, option)));
795
+ }
796
+ default: {
797
+ const title = block.disposition ? titles[block.disposition] : void 0;
798
+ return /* @__PURE__ */ React3.createElement(ToggleContainer2, {
799
+ title: title ?? "JSON"
800
+ }, /* @__PURE__ */ React3.createElement(Json2, {
801
+ data: safeParseJson(block.json ?? block),
802
+ classNames: "!p-1 text-xs"
803
+ }));
804
+ }
805
+ }
806
+ },
807
+ //
808
+ // Default
809
+ //
810
+ default: ({ block }) => {
811
+ let title = titles[block.type];
812
+ if (block.type === "tool_use") {
813
+ title = `Tool [${block.name}]`;
814
+ }
815
+ return /* @__PURE__ */ React3.createElement(ToggleContainer2, {
816
+ title: title ?? "JSON"
817
+ }, /* @__PURE__ */ React3.createElement(Json2, {
818
+ data: block,
819
+ classNames: "!p-1 text-xs"
820
+ }));
821
+ }
822
+ };
823
+ var titles = {
824
+ ["cot"]: "Chain of thought",
825
+ ["artifact"]: "Artifact",
826
+ ["tool_use"]: "Tool request",
827
+ ["tool_result"]: "Tool result",
828
+ ["tool_list"]: "Tools"
829
+ };
830
+
831
+ // packages/plugins/experimental/plugin-automation/src/components/Thread/reducer.ts
832
+ var messageReducer = ({ current, messages }, message) => {
833
+ let i = 0;
834
+ for (const block of message.content) {
835
+ switch (block.type) {
836
+ case "tool_use":
837
+ case "tool_result": {
838
+ if (current) {
839
+ current.content.push(block);
840
+ } else {
841
+ current = {
842
+ id: [
843
+ message.id,
844
+ i
845
+ ].join("_"),
846
+ role: message.role,
847
+ content: [
848
+ block
849
+ ]
850
+ };
851
+ messages.push(current);
852
+ }
853
+ break;
854
+ }
855
+ case "text":
856
+ default: {
857
+ current = void 0;
858
+ messages.push({
859
+ id: [
860
+ message.id,
861
+ i
862
+ ].join("_"),
863
+ role: message.role,
864
+ content: [
865
+ block
866
+ ]
867
+ });
868
+ break;
869
+ }
870
+ }
871
+ i++;
872
+ }
873
+ return {
874
+ current,
875
+ messages
876
+ };
877
+ };
878
+
879
+ // packages/plugins/experimental/plugin-automation/src/components/Prompt/Prompt.tsx
880
+ import React4, { forwardRef, useImperativeHandle } from "react";
881
+ import { useThemeContext } from "@dxos/react-ui";
882
+ import { createBasicExtensions, createThemeExtensions, keymap as keymap2, useTextEditor } from "@dxos/react-ui-editor";
883
+ import { mx as mx3 } from "@dxos/react-ui-theme";
884
+
885
+ // packages/plugins/experimental/plugin-automation/src/components/Prompt/autocomplete.ts
886
+ import { Prec } from "@codemirror/state";
887
+ import { EditorView, Decoration, ViewPlugin, keymap, WidgetType } from "@codemirror/view";
888
+ var createAutocompleteExtension = ({ onSubmit, onSuggest }) => {
889
+ const suggestionPlugin = ViewPlugin.fromClass(class {
890
+ constructor(view) {
891
+ this._currentSuggestion = null;
892
+ this._decorations = this.computeDecorations(view);
893
+ }
894
+ update(update) {
895
+ if (update.docChanged || update.selectionSet) {
896
+ this._decorations = this.computeDecorations(update.view);
897
+ }
898
+ }
899
+ computeDecorations(view) {
900
+ const text = view.state.doc.toString();
901
+ const suggestions = onSuggest?.(text) ?? [];
902
+ if (!suggestions.length) {
903
+ this._currentSuggestion = null;
904
+ return Decoration.none;
905
+ }
906
+ this._currentSuggestion = suggestions[0];
907
+ const suffix = this._currentSuggestion.slice(text.length);
908
+ if (!suffix) {
909
+ return Decoration.none;
910
+ }
911
+ return Decoration.set([
912
+ Decoration.widget({
913
+ widget: new InlineSuggestionWidget(suffix),
914
+ side: 1
915
+ }).range(view.state.doc.length)
916
+ ]);
917
+ }
918
+ completeSuggestion(view) {
919
+ if (!this._currentSuggestion) {
920
+ return false;
921
+ }
922
+ const text = view.state.doc.toString();
923
+ const suffix = this._currentSuggestion.slice(text.length);
924
+ if (!suffix) {
925
+ return false;
926
+ }
927
+ view.dispatch({
928
+ changes: {
929
+ from: view.state.doc.length,
930
+ insert: suffix
931
+ },
932
+ selection: {
933
+ anchor: view.state.doc.length + suffix.length
934
+ }
935
+ });
936
+ return true;
937
+ }
938
+ }, {
939
+ decorations: (v) => v._decorations
940
+ });
941
+ return [
942
+ suggestionPlugin,
943
+ EditorView.theme({
944
+ ".cm-inline-suggestion": {
945
+ opacity: 0.4
946
+ }
947
+ }),
948
+ // Accept the current suggestion.
949
+ Prec.highest(keymap.of([
950
+ {
951
+ key: "Tab",
952
+ preventDefault: true,
953
+ run: (view) => {
954
+ const plugin = view.plugin(suggestionPlugin);
955
+ return plugin?.completeSuggestion(view) ?? false;
956
+ }
957
+ },
958
+ {
959
+ key: "ArrowRight",
960
+ preventDefault: true,
961
+ run: (view) => {
962
+ if (view.state.selection.main.head !== view.state.doc.length) {
963
+ return false;
964
+ }
965
+ const plugin = view.plugin(suggestionPlugin);
966
+ return plugin?.completeSuggestion(view) ?? false;
967
+ }
968
+ },
969
+ {
970
+ key: "Enter",
971
+ preventDefault: true,
972
+ run: (view) => {
973
+ const text = view.state.doc.toString().trim();
974
+ if (text.length > 0 && onSubmit) {
975
+ const reset = onSubmit(text);
976
+ if (reset) {
977
+ view.dispatch({
978
+ changes: {
979
+ from: 0,
980
+ to: view.state.doc.length,
981
+ insert: ""
982
+ }
983
+ });
984
+ }
985
+ }
986
+ return true;
987
+ }
988
+ },
989
+ {
990
+ key: "Shift-Enter",
991
+ preventDefault: true,
992
+ run: (view) => {
993
+ view.dispatch({
994
+ changes: {
995
+ from: view.state.selection.main.head,
996
+ insert: "\n"
997
+ },
998
+ selection: {
999
+ anchor: view.state.selection.main.head + 1,
1000
+ head: view.state.selection.main.head + 1
1001
+ }
1002
+ });
1003
+ return true;
1004
+ }
1005
+ },
1006
+ {
1007
+ key: "Escape",
1008
+ preventDefault: true,
1009
+ run: (view) => {
1010
+ view.dispatch({
1011
+ changes: {
1012
+ from: 0,
1013
+ to: view.state.doc.length,
1014
+ insert: ""
1015
+ }
1016
+ });
1017
+ return true;
1018
+ }
1019
+ }
1020
+ ]))
1021
+ ];
1022
+ };
1023
+ var InlineSuggestionWidget = class extends WidgetType {
1024
+ constructor(suffix) {
1025
+ super();
1026
+ this.suffix = suffix;
1027
+ }
1028
+ toDOM() {
1029
+ const span = document.createElement("span");
1030
+ span.textContent = this.suffix;
1031
+ span.className = "cm-inline-suggestion";
1032
+ return span;
1033
+ }
1034
+ eq(other) {
1035
+ return other.suffix === this.suffix;
1036
+ }
1037
+ };
1038
+
1039
+ // packages/plugins/experimental/plugin-automation/src/components/Prompt/Prompt.tsx
1040
+ var Prompt = /* @__PURE__ */ forwardRef(({ classNames, autoFocus, lineWrapping = false, placeholder, onSubmit, onSuggest, onOpenChange }, forwardRef2) => {
1041
+ const { themeMode } = useThemeContext();
1042
+ const { parentRef, view } = useTextEditor({
1043
+ autoFocus,
1044
+ extensions: [
1045
+ createBasicExtensions({
1046
+ bracketMatching: false,
1047
+ lineWrapping,
1048
+ placeholder
1049
+ }),
1050
+ createThemeExtensions({
1051
+ themeMode
1052
+ }),
1053
+ createAutocompleteExtension({
1054
+ onSubmit,
1055
+ onSuggest
1056
+ }),
1057
+ keymap2.of([
1058
+ {
1059
+ key: "Alt-ArrowUp",
1060
+ preventDefault: true,
1061
+ run: (view2) => {
1062
+ onOpenChange?.(true);
1063
+ return true;
1064
+ }
1065
+ },
1066
+ {
1067
+ key: "Alt-ArrowDown",
1068
+ preventDefault: true,
1069
+ run: (view2) => {
1070
+ onOpenChange?.(false);
1071
+ return true;
1072
+ }
1073
+ }
1074
+ ])
1075
+ ]
1076
+ }, [
1077
+ themeMode,
1078
+ onSubmit,
1079
+ onSuggest
1080
+ ]);
1081
+ useImperativeHandle(forwardRef2, () => {
1082
+ return {
1083
+ focus: () => {
1084
+ view?.focus();
1085
+ },
1086
+ setText: (text) => {
1087
+ view?.dispatch({
1088
+ changes: {
1089
+ from: 0,
1090
+ to: view.state.doc.length,
1091
+ insert: text
1092
+ },
1093
+ selection: {
1094
+ anchor: text.length,
1095
+ head: text.length
1096
+ }
1097
+ });
1098
+ }
1099
+ };
1100
+ }, [
1101
+ view,
1102
+ onSubmit
1103
+ ]);
1104
+ return /* @__PURE__ */ React4.createElement("div", {
1105
+ ref: parentRef,
1106
+ className: mx3("w-full overflow-hidden", classNames)
1107
+ });
1108
+ });
1109
+
1110
+ // packages/plugins/experimental/plugin-automation/src/components/Prompt/PromptBar.tsx
1111
+ import React5, { useRef as useRef2, useState as useState3 } from "react";
1112
+ import { useVoiceInput } from "@dxos/plugin-transcription";
1113
+ import { Icon as Icon2, IconButton as IconButton2, useTranslation } from "@dxos/react-ui";
1114
+ import { Spinner } from "@dxos/react-ui-sfx";
1115
+ import { errorText, mx as mx4 } from "@dxos/react-ui-theme";
1116
+ var PromptBar = ({ classNames, placeholder, processing, error, microphone, onCancel, ...props }) => {
1117
+ const { t } = useTranslation(AUTOMATION_PLUGIN);
1118
+ const promptRef = useRef2(null);
1119
+ const [active, setActive] = useState3(false);
1120
+ const { recording } = useVoiceInput({
1121
+ active,
1122
+ onUpdate: (text) => {
1123
+ promptRef.current?.setText(text);
1124
+ promptRef.current?.focus();
1125
+ }
1126
+ });
1127
+ return /* @__PURE__ */ React5.createElement("div", {
1128
+ className: mx4("flex shrink-0 w-full grid grid-cols-[var(--rail-action)_1fr_var(--rail-action)] overflow-hidden", classNames)
1129
+ }, /* @__PURE__ */ React5.createElement("div", {
1130
+ className: "flex w-[--rail-action] h-[--rail-action] items-center justify-center"
1131
+ }, error && /* @__PURE__ */ React5.createElement(Icon2, {
1132
+ icon: "ph--warning-circle--regular",
1133
+ classNames: errorText,
1134
+ size: 5
1135
+ }) || /* @__PURE__ */ React5.createElement(Spinner, {
1136
+ active: processing
1137
+ })), /* @__PURE__ */ React5.createElement(Prompt, {
1138
+ ref: promptRef,
1139
+ autoFocus: true,
1140
+ classNames: "pbs-2",
1141
+ lineWrapping: true,
1142
+ placeholder: placeholder ?? t("prompt placeholder"),
1143
+ ...props
1144
+ }), (onCancel || microphone) && /* @__PURE__ */ React5.createElement("div", {
1145
+ className: "flex w-[--rail-action] h-[--rail-action] items-center justify-center"
1146
+ }, processing && onCancel && /* @__PURE__ */ React5.createElement(IconButton2, {
1147
+ classNames: "px-1.5",
1148
+ variant: "ghost",
1149
+ size: 5,
1150
+ icon: "ph--x--regular",
1151
+ iconOnly: true,
1152
+ label: t("cancel processing button"),
1153
+ onClick: onCancel
1154
+ }), !processing && microphone && /* @__PURE__ */ React5.createElement(IconButton2, {
1155
+ classNames: mx4("px-1.5", recording && "bg-primary-500"),
1156
+ variant: "ghost",
1157
+ size: 5,
1158
+ icon: "ph--microphone--regular",
1159
+ iconOnly: true,
1160
+ noTooltip: true,
1161
+ label: t("microphone button"),
1162
+ onMouseDown: () => setActive(true),
1163
+ onMouseUp: () => setActive(false),
1164
+ onTouchStart: () => setActive(true),
1165
+ onTouchEnd: () => setActive(false)
1166
+ })));
1167
+ };
1168
+
1169
+ // packages/plugins/experimental/plugin-automation/src/components/Thread/Thread.tsx
1170
+ var Thread = ({ classNames, space, messages, collapse = true, transcription, processing, error, onSubmit, onCancel, onOpenChange, ...props }) => {
1171
+ const scroller = useRef3(null);
1172
+ const identity = useIdentity();
1173
+ const fallbackValue = keyToFallback(identity.identityKey);
1174
+ const userHue = identity.profile?.data?.hue || fallbackValue.hue;
1175
+ const handleSubmit = useCallback((value) => {
1176
+ onSubmit?.(value);
1177
+ scroller.current?.scrollToBottom();
1178
+ return true;
1179
+ }, [
1180
+ onSubmit
1181
+ ]);
1182
+ const { messages: filteredMessages = [] } = useMemo2(() => {
1183
+ if (collapse) {
1184
+ return (messages ?? []).reduce(messageReducer, {
1185
+ messages: []
1186
+ });
1187
+ } else {
1188
+ return {
1189
+ messages: messages ?? []
1190
+ };
1191
+ }
1192
+ }, [
1193
+ messages,
1194
+ collapse
1195
+ ]);
1196
+ return /* @__PURE__ */ React6.createElement("div", {
1197
+ role: "none",
1198
+ className: mx5("flex flex-col grow overflow-hidden", classNames)
1199
+ }, /* @__PURE__ */ React6.createElement(ScrollContainer, {
1200
+ ref: scroller,
1201
+ fade: true
1202
+ }, /* @__PURE__ */ React6.createElement("div", {
1203
+ role: "none",
1204
+ className: mx5(filteredMessages.length > 0 && "pbs-6 pbe-6"),
1205
+ style: {
1206
+ "--user-fill": `var(--dx-${userHue}Fill)`
1207
+ }
1208
+ }, filteredMessages.map((message) => /* @__PURE__ */ React6.createElement(ThreadMessage, {
1209
+ key: message.id,
1210
+ classNames: "px-4 pbe-4",
1211
+ space,
1212
+ message,
1213
+ ...props
1214
+ })))), onSubmit && /* @__PURE__ */ React6.createElement(PromptBar, {
1215
+ microphone: transcription,
1216
+ processing,
1217
+ error,
1218
+ onSubmit: handleSubmit,
1219
+ onCancel,
1220
+ onOpenChange
1221
+ }));
1222
+ };
1223
+
1224
+ // packages/plugins/experimental/plugin-automation/src/components/Thread/ThreadContainer.tsx
1225
+ import React7, { useCallback as useCallback3 } from "react";
1226
+ import { invariant as invariant6 } from "@dxos/invariant";
1227
+ import { log as log9 } from "@dxos/log";
1228
+ import { getSpace as getSpace2 } from "@dxos/react-client/echo";
1229
+
1230
+ // packages/plugins/experimental/plugin-automation/src/hooks/processor.ts
1231
+ import { batch, computed, signal } from "@preact/signals-core";
1232
+ import { Message } from "@dxos/artifact";
1233
+ import { isToolUse, runTools, MixedStreamParser, DEFAULT_LLM_MODEL } from "@dxos/assistant";
1234
+ import { createStatic } from "@dxos/echo-schema";
1235
+ import { invariant as invariant3 } from "@dxos/invariant";
1236
+ import { log as log5 } from "@dxos/log";
1237
+ var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-automation/src/hooks/processor.ts";
1238
+ var defaultOptions = {
1239
+ model: DEFAULT_LLM_MODEL,
1240
+ systemPrompt: "you are a helpful assistant"
1241
+ };
1242
+ var ChatProcessor = class {
1243
+ constructor(_client, _tools, _extensions, _options = defaultOptions) {
1244
+ this._client = _client;
1245
+ this._tools = _tools;
1246
+ this._extensions = _extensions;
1247
+ this._options = _options;
1248
+ this._parser = new MixedStreamParser();
1249
+ this._pending = signal([]);
1250
+ this._block = signal(void 0);
1251
+ this._history = [];
1252
+ this.streaming = computed(() => this._block.value !== void 0);
1253
+ this.error = signal(void 0);
1254
+ this.messages = computed(() => {
1255
+ const messages = [
1256
+ ...this._pending.value
1257
+ ];
1258
+ if (this._block.value) {
1259
+ const current = messages.pop();
1260
+ invariant3(current, void 0, {
1261
+ F: __dxlog_file6,
1262
+ L: 85,
1263
+ S: this,
1264
+ A: [
1265
+ "current",
1266
+ ""
1267
+ ]
1268
+ });
1269
+ const { content, ...rest } = current;
1270
+ const message = {
1271
+ ...rest,
1272
+ content: [
1273
+ ...content,
1274
+ this._block.value
1275
+ ]
1276
+ };
1277
+ messages.push(message);
1278
+ }
1279
+ return messages;
1280
+ });
1281
+ this._parser.message.on((message) => {
1282
+ batch(() => {
1283
+ this._pending.value = [
1284
+ ...this._pending.value,
1285
+ message
1286
+ ];
1287
+ this._block.value = void 0;
1288
+ });
1289
+ });
1290
+ this._parser.update.on((block) => {
1291
+ batch(() => {
1292
+ this._block.value = block;
1293
+ });
1294
+ });
1295
+ }
1296
+ /**
1297
+ * Update tools.
1298
+ */
1299
+ setTools(tools) {
1300
+ this._tools = tools;
1301
+ }
1302
+ /**
1303
+ * Make GPT request.
1304
+ */
1305
+ async request(message, options = {}) {
1306
+ batch(() => {
1307
+ this._history = options.history ?? [];
1308
+ this._pending.value = [
1309
+ createStatic(Message, {
1310
+ role: "user",
1311
+ content: [
1312
+ {
1313
+ type: "text",
1314
+ text: message
1315
+ }
1316
+ ]
1317
+ })
1318
+ ];
1319
+ this._block.value = void 0;
1320
+ });
1321
+ await this._generate();
1322
+ options.onComplete?.(this._pending.value);
1323
+ return this._reset();
1324
+ }
1325
+ /**
1326
+ * Cancel pending requests.
1327
+ * @returns Pending requests (incl. the request message).
1328
+ */
1329
+ async cancel() {
1330
+ log5.info("cancelling...", void 0, {
1331
+ F: __dxlog_file6,
1332
+ L: 148,
1333
+ S: this,
1334
+ C: (f, a) => f(...a)
1335
+ });
1336
+ this._stream?.abort();
1337
+ return this._reset();
1338
+ }
1339
+ async _reset() {
1340
+ const messages = this._pending.value;
1341
+ batch(() => {
1342
+ this._history = [];
1343
+ this._pending.value = [];
1344
+ this._block.value = void 0;
1345
+ });
1346
+ return messages;
1347
+ }
1348
+ /**
1349
+ * Generate a response from the AI service.
1350
+ * Iterates over tool requests.
1351
+ */
1352
+ async _generate() {
1353
+ try {
1354
+ let more = false;
1355
+ do {
1356
+ log5.info("requesting", {
1357
+ history: this._history.length,
1358
+ messages: this._pending.value.length
1359
+ }, {
1360
+ F: __dxlog_file6,
1361
+ L: 172,
1362
+ S: this,
1363
+ C: (f, a) => f(...a)
1364
+ });
1365
+ this._stream = await this._client.generate({
1366
+ ...this._options,
1367
+ // TODO(burdon): Rename messages or separate history/message.
1368
+ history: [
1369
+ ...this._history,
1370
+ ...this._pending.value
1371
+ ],
1372
+ tools: this._tools
1373
+ });
1374
+ await this._parser.parse(this._stream);
1375
+ await this._stream.complete();
1376
+ log5.info("response", {
1377
+ messages: this._pending.value
1378
+ }, {
1379
+ F: __dxlog_file6,
1380
+ L: 185,
1381
+ S: this,
1382
+ C: (f, a) => f(...a)
1383
+ });
1384
+ more = false;
1385
+ const message = this._pending.value.at(-1);
1386
+ invariant3(message, void 0, {
1387
+ F: __dxlog_file6,
1388
+ L: 190,
1389
+ S: this,
1390
+ A: [
1391
+ "message",
1392
+ ""
1393
+ ]
1394
+ });
1395
+ if (isToolUse(message)) {
1396
+ log5.info("tool request...", void 0, {
1397
+ F: __dxlog_file6,
1398
+ L: 192,
1399
+ S: this,
1400
+ C: (f, a) => f(...a)
1401
+ });
1402
+ const response = await runTools({
1403
+ message: this._pending.value.at(-1),
1404
+ tools: this._tools ?? [],
1405
+ extensions: this._extensions
1406
+ });
1407
+ log5.info("tool response", {
1408
+ response
1409
+ }, {
1410
+ F: __dxlog_file6,
1411
+ L: 199,
1412
+ S: this,
1413
+ C: (f, a) => f(...a)
1414
+ });
1415
+ switch (response.type) {
1416
+ case "continue": {
1417
+ this._pending.value = [
1418
+ ...this._pending.value,
1419
+ response.message
1420
+ ];
1421
+ more = true;
1422
+ break;
1423
+ }
1424
+ }
1425
+ }
1426
+ } while (more);
1427
+ log5.info("done", void 0, {
1428
+ F: __dxlog_file6,
1429
+ L: 210,
1430
+ S: this,
1431
+ C: (f, a) => f(...a)
1432
+ });
1433
+ } catch (err) {
1434
+ log5.catch(err, void 0, {
1435
+ F: __dxlog_file6,
1436
+ L: 212,
1437
+ S: this,
1438
+ C: (f, a) => f(...a)
1439
+ });
1440
+ this.error.value = new Error("AI service error", {
1441
+ cause: err
1442
+ });
1443
+ } finally {
1444
+ this._stream = void 0;
1445
+ this.error.value = void 0;
1446
+ }
1447
+ }
1448
+ };
1449
+
1450
+ // packages/plugins/experimental/plugin-automation/src/hooks/useChatProcessor.tsx
1451
+ import { useEffect as useEffect3, useMemo as useMemo3, useState as useState4 } from "react";
1452
+ import { Capabilities as Capabilities2, useCapabilities as useCapabilities2, useCapability, useIntentDispatcher } from "@dxos/app-framework";
1453
+ import { createSystemPrompt } from "@dxos/artifact";
1454
+ import { DEFAULT_LLM_MODEL as DEFAULT_LLM_MODEL2 } from "@dxos/assistant";
1455
+ import { FunctionType as FunctionType2 } from "@dxos/functions";
1456
+ import { log as log6 } from "@dxos/log";
1457
+ import { useConfig } from "@dxos/react-client";
1458
+ import { Filter as Filter2, useQuery as useQuery2 } from "@dxos/react-client/echo";
1459
+ import { isNonNullable as isNonNullable2 } from "@dxos/util";
1460
+
1461
+ // packages/plugins/experimental/plugin-automation/src/capabilities/index.ts
1462
+ import { lazy } from "@dxos/app-framework";
1463
+ var AiClient = lazy(() => import("./ai-client-T2PBJISL.mjs"));
1464
+ var AutomationSettings = lazy(() => import("./settings-FE5DDWOE.mjs"));
1465
+ var AppGraphBuilder = lazy(() => import("./app-graph-builder-IR3CGVM6.mjs"));
1466
+ var IntentResolver = lazy(() => import("./intent-resolver-ICLE6FSI.mjs"));
1467
+ var ReactSurface = lazy(() => import("./react-surface-KEKVLCPQ.mjs"));
1468
+
1469
+ // packages/plugins/experimental/plugin-automation/src/hooks/useChatProcessor.tsx
1470
+ var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-automation/src/hooks/useChatProcessor.tsx";
1471
+ var useChatProcessor = (space, settings) => {
1472
+ const aiClient = useCapability(AutomationCapabilities.AiClient);
1473
+ const globalTools = useCapabilities2(Capabilities2.Tools);
1474
+ const artifactDefinitions = useCapabilities2(Capabilities2.ArtifactDefinition);
1475
+ const { dispatchPromise: dispatch } = useIntentDispatcher();
1476
+ const services = useQuery2(space, Filter2.schema(ServiceType));
1477
+ const [serviceTools, setServiceTools] = useState4([]);
1478
+ useEffect3(() => {
1479
+ log6("creating service tools...", void 0, {
1480
+ F: __dxlog_file7,
1481
+ L: 34,
1482
+ S: void 0,
1483
+ C: (f, a) => f(...a)
1484
+ });
1485
+ queueMicrotask(async () => {
1486
+ const tools2 = await Promise.all(services.map((service) => createToolsFromService(service)));
1487
+ setServiceTools(tools2.flat());
1488
+ });
1489
+ }, [
1490
+ services
1491
+ ]);
1492
+ const config = useConfig();
1493
+ const functions2 = useQuery2(space, Filter2.schema(FunctionType2));
1494
+ const [tools, extensions] = useMemo3(() => {
1495
+ log6("creating tools...", void 0, {
1496
+ F: __dxlog_file7,
1497
+ L: 45,
1498
+ S: void 0,
1499
+ C: (f, a) => f(...a)
1500
+ });
1501
+ const tools2 = [
1502
+ ...globalTools.flat(),
1503
+ ...artifactDefinitions.flatMap((definition) => definition.tools),
1504
+ ...serviceTools,
1505
+ ...functions2.map((fn) => covertFunctionToTool(fn, config.values.runtime?.services?.edge?.url ?? "", space?.id)).filter(isNonNullable2)
1506
+ ];
1507
+ const extensions2 = {
1508
+ space,
1509
+ dispatch
1510
+ };
1511
+ return [
1512
+ tools2,
1513
+ extensions2
1514
+ ];
1515
+ }, [
1516
+ dispatch,
1517
+ globalTools,
1518
+ artifactDefinitions,
1519
+ space,
1520
+ serviceTools,
1521
+ functions2
1522
+ ]);
1523
+ const systemPrompt = useMemo3(() => createSystemPrompt({
1524
+ artifacts: artifactDefinitions.map((definition) => definition.instructions)
1525
+ }), [
1526
+ artifactDefinitions
1527
+ ]);
1528
+ const processor = useMemo3(() => {
1529
+ log6("creating processor...", {
1530
+ settings
1531
+ }, {
1532
+ F: __dxlog_file7,
1533
+ L: 67,
1534
+ S: void 0,
1535
+ C: (f, a) => f(...a)
1536
+ });
1537
+ return new ChatProcessor(aiClient, tools, extensions, {
1538
+ // TODO(burdon): Remove defualt (let backend decide if not specified).
1539
+ model: settings?.llmModel ?? DEFAULT_LLM_MODEL2,
1540
+ // TOOD(burdon): Query.
1541
+ systemPrompt
1542
+ });
1543
+ }, [
1544
+ aiClient,
1545
+ tools,
1546
+ extensions,
1547
+ systemPrompt,
1548
+ settings?.llmModel
1549
+ ]);
1550
+ return processor;
1551
+ };
1552
+
1553
+ // packages/plugins/experimental/plugin-automation/src/hooks/useLocalTriggerManager.ts
1554
+ import { useEffect as useEffect4, useState as useState5 } from "react";
1555
+ import { Mutex } from "@dxos/async";
1556
+ import { Context } from "@dxos/context";
1557
+ import { createSubscriptionTrigger } from "@dxos/functions";
1558
+ import { FunctionTrigger } from "@dxos/functions";
1559
+ import { invariant as invariant5 } from "@dxos/invariant";
1560
+ import { log as log8 } from "@dxos/log";
1561
+ import { useClient } from "@dxos/react-client";
1562
+ import { Filter as Filter3, useQuery as useQuery3 } from "@dxos/react-client/echo";
1563
+
1564
+ // packages/plugins/experimental/plugin-automation/src/hooks/invocation-handler.ts
1565
+ import { sleep } from "@dxos/async";
1566
+ import { getObjectCore, ResultFormat } from "@dxos/echo-db";
1567
+ import { FunctionType as FunctionType3 } from "@dxos/functions";
1568
+ import { invariant as invariant4 } from "@dxos/invariant";
1569
+ import { DXN, LOCAL_SPACE_TAG } from "@dxos/keys";
1570
+ import { log as log7 } from "@dxos/log";
1571
+
1572
+ // packages/plugins/experimental/plugin-automation/src/hooks/useLocalTriggerManager.ts
1573
+ var registerTriggersMutex = new Mutex();
1574
+
1575
+ // packages/plugins/experimental/plugin-automation/src/hooks/useMessageQueue.ts
1576
+ import { useMemo as useMemo4 } from "react";
1577
+ import { DXN as DXN2, QueueSubspaceTags } from "@dxos/keys";
1578
+ import { getSpace } from "@dxos/react-client/echo";
1579
+ import { useEdgeClient, useQueue } from "@dxos/react-edge-client";
1580
+ var useMessageQueue = (chat) => {
1581
+ const space = getSpace(chat);
1582
+ const queueDxn = useMemo4(() => {
1583
+ const dxn = space && chat?.queue.dxn;
1584
+ return dxn ? new DXN2(DXN2.kind.QUEUE, [
1585
+ QueueSubspaceTags.DATA,
1586
+ space.id,
1587
+ dxn.parts.at(-1)
1588
+ ]) : void 0;
1589
+ }, [
1590
+ space,
1591
+ chat?.queue.dxn
1592
+ ]);
1593
+ const edgeClient = useEdgeClient();
1594
+ return useQueue(edgeClient, queueDxn);
1595
+ };
1596
+
1597
+ // packages/plugins/experimental/plugin-automation/src/hooks/useServices.ts
1598
+ import { useEffect as useEffect5, useMemo as useMemo5, useState as useState6 } from "react";
1599
+
1600
+ // packages/plugins/experimental/plugin-automation/src/testing/test-functions.ts
1601
+ import { createSystemPrompt as createSystemPrompt2 } from "@dxos/artifact";
1602
+ import { DEFAULT_LLM_MODEL as DEFAULT_LLM_MODEL3 } from "@dxos/assistant";
1603
+ import { AST, S as S2, toJsonSchema } from "@dxos/echo-schema";
1604
+ var functions = [
1605
+ {
1606
+ name: "example.com/function/chess",
1607
+ version: "0.1.0",
1608
+ inputSchema: toJsonSchema(S2.Struct({
1609
+ level: S2.Number.annotations({
1610
+ [AST.TitleAnnotationId]: "Level"
1611
+ })
1612
+ }))
1613
+ },
1614
+ {
1615
+ name: "example.com/function/forex",
1616
+ version: "0.1.0",
1617
+ binding: "FOREX",
1618
+ inputSchema: toJsonSchema(S2.Struct({
1619
+ from: S2.String.annotations({
1620
+ [AST.TitleAnnotationId]: "Currency from"
1621
+ }),
1622
+ to: S2.String.annotations({
1623
+ [AST.TitleAnnotationId]: "Currency to"
1624
+ })
1625
+ }))
1626
+ }
1627
+ ];
1628
+
1629
+ // packages/plugins/experimental/plugin-automation/src/testing/test-services.ts
1630
+ import { createStatic as createStatic2 } from "@dxos/echo-schema";
1631
+ var MockServiceRegistry = class {
1632
+ async queryServices(query) {
1633
+ return TEST_SERVICES;
1634
+ }
1635
+ };
1636
+ var AMADEUS_AUTH = {
1637
+ type: "oauth",
1638
+ clientId: "BOEnpLd1sMyKjAPGKYeAPFFy60u53QEG",
1639
+ clientSecret: "n4qldSN7usvD57gm",
1640
+ tokenUrl: "https://test.api.amadeus.com/v1/security/oauth2/token",
1641
+ grantType: "client_credentials"
1642
+ };
1643
+ var VISUAL_CROSSING_CREDENTIALS = {
1644
+ type: "api-key",
1645
+ key: "FDPRVS953KB4GQQLD25GRT975",
1646
+ placement: {
1647
+ type: "query",
1648
+ name: "key"
1649
+ }
1650
+ };
1651
+ var TEST_SERVICES = [
1652
+ createStatic2(ServiceType, {
1653
+ serviceId: "amadeus.com/service/FlightSearch",
1654
+ name: "Amadeus Flight Search",
1655
+ description: "Search for local and international flights.",
1656
+ category: "travel",
1657
+ interfaces: [
1658
+ {
1659
+ kind: "api",
1660
+ schemaUrl: "https://api.apis.guru/v2/specs/amadeus.com/amadeus-flight-availabilities-search/1.0.2/swagger.json",
1661
+ authorization: AMADEUS_AUTH
1662
+ }
1663
+ ]
1664
+ }),
1665
+ createStatic2(ServiceType, {
1666
+ serviceId: "amadeus.com/service/HotelSearch",
1667
+ name: "Amadeus Hotel Search",
1668
+ description: "Search for local and international hotels.",
1669
+ category: "travel",
1670
+ interfaces: [
1671
+ {
1672
+ kind: "api",
1673
+ schemaUrl: "https://api.apis.guru/v2/specs/amadeus.com/amadeus-hotel-search/3.0.8/swagger.json",
1674
+ authorization: AMADEUS_AUTH
1675
+ }
1676
+ ]
1677
+ }),
1678
+ createStatic2(ServiceType, {
1679
+ serviceId: "visualcrossing.com/service/Weather",
1680
+ name: "Visual Crossing Weather",
1681
+ description: "Search for global weather forecasts.",
1682
+ category: "weather",
1683
+ interfaces: [
1684
+ {
1685
+ kind: "api",
1686
+ schemaUrl: "https://api.apis.guru/v2/specs/visualcrossing.com/weather/4.6/openapi.json",
1687
+ authorization: VISUAL_CROSSING_CREDENTIALS
1688
+ }
1689
+ ]
1690
+ }),
1691
+ // TODO(burdon): Needs auth.
1692
+ createStatic2(ServiceType, {
1693
+ serviceId: "abstractapi.com/service/GeoLocation",
1694
+ name: "Abstract GeoLocation",
1695
+ description: "Get the location of any IP address.",
1696
+ category: "geolocation",
1697
+ interfaces: [
1698
+ {
1699
+ kind: "api",
1700
+ schemaUrl: "https://api.apis.guru/v2/specs/abstractapi.com/geolocation/1.0.0/openapi.json"
1701
+ }
1702
+ ]
1703
+ }),
1704
+ //
1705
+ // Testing
1706
+ //
1707
+ ...Array.from({
1708
+ length: 20
1709
+ }, (_, i) => createStatic2(ServiceType, {
1710
+ serviceId: `example.com/service/test-${i}`,
1711
+ name: `Test ${i}`,
1712
+ description: `Test ${i}`,
1713
+ category: Object.keys(categoryIcons)[Math.floor(Math.random() * Object.keys(categoryIcons).length)],
1714
+ interfaces: [
1715
+ {
1716
+ kind: "api",
1717
+ schemaUrl: "https://petstore.swagger.io/v2/swagger.json"
1718
+ }
1719
+ ]
1720
+ }))
1721
+ ];
1722
+
1723
+ // packages/plugins/experimental/plugin-automation/src/hooks/useServices.ts
1724
+ var useServices = (space, query) => {
1725
+ const registry = useMemo5(() => new MockServiceRegistry(), []);
1726
+ const [services, setServices] = useState6([]);
1727
+ useEffect5(() => {
1728
+ const t = setTimeout(async () => {
1729
+ const services2 = await registry.queryServices(query);
1730
+ setServices(services2);
1731
+ });
1732
+ return () => clearTimeout(t);
1733
+ }, [
1734
+ query,
1735
+ registry
1736
+ ]);
1737
+ return services;
1738
+ };
1739
+
1740
+ // packages/plugins/experimental/plugin-automation/src/hooks/useTextInputEvents.ts
1741
+ import { useState as useState7, useCallback as useCallback2 } from "react";
1742
+
1743
+ // packages/plugins/experimental/plugin-automation/src/components/Thread/ThreadContainer.tsx
1744
+ var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-automation/src/components/Thread/ThreadContainer.tsx";
1745
+ var ThreadContainer = ({ classNames, chat, settings, onOpenChange, ...props }) => {
1746
+ const space = getSpace2(chat);
1747
+ const processor = useChatProcessor(space, settings);
1748
+ const messageQueue = useMessageQueue(chat);
1749
+ const messages = [
1750
+ ...messageQueue?.items ?? [],
1751
+ ...processor.messages.value
1752
+ ];
1753
+ const handleSubmit = useCallback3((text) => {
1754
+ if (processor.streaming.value) {
1755
+ log9.warn("ignoring submit; still processing.", void 0, {
1756
+ F: __dxlog_file8,
1757
+ L: 39,
1758
+ S: void 0,
1759
+ C: (f, a) => f(...a)
1760
+ });
1761
+ return false;
1762
+ }
1763
+ onOpenChange?.(true);
1764
+ invariant6(messageQueue, void 0, {
1765
+ F: __dxlog_file8,
1766
+ L: 45,
1767
+ S: void 0,
1768
+ A: [
1769
+ "messageQueue",
1770
+ ""
1771
+ ]
1772
+ });
1773
+ void processor.request(text, {
1774
+ history: messageQueue.items,
1775
+ onComplete: (messages2) => {
1776
+ messageQueue.append(messages2);
1777
+ }
1778
+ });
1779
+ return true;
1780
+ }, [
1781
+ processor,
1782
+ messageQueue,
1783
+ onOpenChange
1784
+ ]);
1785
+ const handleCancel = useCallback3(() => {
1786
+ if (processor.streaming.value) {
1787
+ void processor.cancel();
1788
+ }
1789
+ }, [
1790
+ processor
1791
+ ]);
1792
+ return /* @__PURE__ */ React7.createElement(Thread, {
1793
+ classNames,
1794
+ space,
1795
+ messages,
1796
+ processing: processor.streaming.value,
1797
+ error: processor.error.value,
1798
+ onSubmit: handleSubmit,
1799
+ onCancel: handleCancel,
1800
+ onPrompt: handleSubmit,
1801
+ onOpenChange,
1802
+ ...props
1803
+ });
1804
+ };
1805
+
1806
+ export {
1807
+ AiClient,
1808
+ AutomationSettings,
1809
+ AppGraphBuilder,
1810
+ IntentResolver,
1811
+ ReactSurface,
1812
+ useServices,
1813
+ Toolbox,
1814
+ ToolboxContainer,
1815
+ Thread,
1816
+ ThreadContainer
1817
+ };
1818
+ //# sourceMappingURL=chunk-BQ4WHY4D.mjs.map