@dxos/plugin-automation 0.7.5-staging.b81e783 → 0.8.0

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