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