@dxos/plugin-automation 0.7.5-main.b19bfc8 → 0.7.5-main.e94eead

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