@dxos/plugin-automation 0.7.5-main.e9bb01b → 0.7.5-staging.2ff1350

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