@dxos/plugin-automation 0.7.5-labs.a279d8c → 0.7.5-labs.ea4b4c2

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 (305) hide show
  1. package/dist/lib/browser/AutomationPanel-VW2XIUPU.mjs +8 -0
  2. package/dist/lib/browser/AutomationPanel-VW2XIUPU.mjs.map +7 -0
  3. package/dist/lib/browser/ChatContainer-5TAVTN3T.mjs +12 -0
  4. package/dist/lib/browser/ChatContainer-5TAVTN3T.mjs.map +7 -0
  5. package/dist/lib/browser/{ai-client-6CRYUC6D.mjs → ai-client-5CNY6JBF.mjs} +4 -4
  6. package/dist/lib/browser/{ai-client-6CRYUC6D.mjs.map → ai-client-5CNY6JBF.mjs.map} +3 -3
  7. package/dist/lib/browser/{app-graph-builder-IJTTULDP.mjs → app-graph-builder-FZGK55G7.mjs} +70 -4
  8. package/dist/lib/browser/app-graph-builder-FZGK55G7.mjs.map +7 -0
  9. package/dist/lib/browser/{chunk-HZ4TA7HY.mjs → chunk-2H2EUYXL.mjs} +2 -2
  10. package/dist/lib/browser/chunk-DVE33EZL.mjs +1602 -0
  11. package/dist/lib/browser/chunk-DVE33EZL.mjs.map +7 -0
  12. package/dist/lib/browser/{chunk-EKJVAFT2.mjs → chunk-MJK7GL5P.mjs} +108 -27
  13. package/dist/lib/browser/chunk-MJK7GL5P.mjs.map +7 -0
  14. package/dist/lib/browser/chunk-NQFZ6XRX.mjs +243 -0
  15. package/dist/lib/browser/chunk-NQFZ6XRX.mjs.map +7 -0
  16. package/dist/lib/browser/chunk-Q4IMHYGH.mjs +150 -0
  17. package/dist/lib/browser/chunk-Q4IMHYGH.mjs.map +7 -0
  18. package/dist/lib/browser/{chunk-HKX3D3ZP.mjs → chunk-R4JH4TLE.mjs} +4 -2
  19. package/dist/lib/browser/chunk-R4JH4TLE.mjs.map +7 -0
  20. package/dist/lib/browser/index.mjs +56 -45
  21. package/dist/lib/browser/index.mjs.map +3 -3
  22. package/dist/lib/browser/intent-resolver-BWAXKT27.mjs +29 -0
  23. package/dist/lib/browser/intent-resolver-BWAXKT27.mjs.map +7 -0
  24. package/dist/lib/browser/meta.json +1 -1
  25. package/dist/lib/browser/{react-surface-IGMBLSV7.mjs → react-surface-ILBDBZCN.mjs} +32 -23
  26. package/dist/lib/browser/react-surface-ILBDBZCN.mjs.map +7 -0
  27. package/dist/lib/browser/types/index.mjs +10 -4
  28. package/dist/lib/node/AutomationPanel-G6EDDYWW.cjs +26 -0
  29. package/dist/lib/node/AutomationPanel-G6EDDYWW.cjs.map +7 -0
  30. package/dist/lib/node/ChatContainer-EN24W3K4.cjs +33 -0
  31. package/dist/lib/node/ChatContainer-EN24W3K4.cjs.map +7 -0
  32. package/dist/lib/node/{ai-client-A3RRU55B.cjs → ai-client-FKLPDELV.cjs} +8 -8
  33. package/dist/lib/node/{ai-client-A3RRU55B.cjs.map → ai-client-FKLPDELV.cjs.map} +3 -3
  34. package/dist/lib/node/{app-graph-builder-MF5M4QRS.cjs → app-graph-builder-T76NYV42.cjs} +77 -12
  35. package/dist/lib/node/app-graph-builder-T76NYV42.cjs.map +7 -0
  36. package/dist/lib/node/chunk-CJGJXNY3.cjs +1586 -0
  37. package/dist/lib/node/chunk-CJGJXNY3.cjs.map +7 -0
  38. package/dist/lib/node/{chunk-5VF5JKUN.cjs → chunk-EQYHOTGG.cjs} +8 -5
  39. package/dist/lib/node/chunk-EQYHOTGG.cjs.map +7 -0
  40. package/dist/lib/node/{chunk-BUQOZA4N.cjs → chunk-GB7245FH.cjs} +87 -11
  41. package/dist/lib/node/chunk-GB7245FH.cjs.map +7 -0
  42. package/dist/lib/node/chunk-HMBKP6VG.cjs +324 -0
  43. package/dist/lib/node/chunk-HMBKP6VG.cjs.map +7 -0
  44. package/dist/lib/node/{AutomationPanel-RXJDVLCF.cjs → chunk-QXIHYOMF.cjs} +123 -9
  45. package/dist/lib/node/chunk-QXIHYOMF.cjs.map +7 -0
  46. package/dist/lib/node/{chunk-ZS5RZ7RM.cjs → chunk-U5Z7LFWB.cjs} +6 -6
  47. package/dist/lib/node/index.cjs +100 -88
  48. package/dist/lib/node/index.cjs.map +3 -3
  49. package/dist/lib/node/{intent-resolver-TBHYXBDI.cjs → intent-resolver-C6OKFVEW.cjs} +20 -15
  50. package/dist/lib/node/intent-resolver-C6OKFVEW.cjs.map +7 -0
  51. package/dist/lib/node/meta.json +1 -1
  52. package/dist/lib/node/{react-surface-BVUZMKYS.cjs → react-surface-LWDY7SQG.cjs} +31 -24
  53. package/dist/lib/node/react-surface-LWDY7SQG.cjs.map +7 -0
  54. package/dist/lib/node/types/index.cjs +15 -9
  55. package/dist/lib/node/types/index.cjs.map +2 -2
  56. package/dist/lib/node-esm/AutomationPanel-V3IWQAMO.mjs +9 -0
  57. package/dist/lib/node-esm/AutomationPanel-V3IWQAMO.mjs.map +7 -0
  58. package/dist/lib/node-esm/ChatContainer-CNTY3C2D.mjs +13 -0
  59. package/dist/lib/node-esm/ChatContainer-CNTY3C2D.mjs.map +7 -0
  60. package/dist/lib/node-esm/{ai-client-2GBZRHBA.mjs → ai-client-XGNA6SJ5.mjs} +4 -4
  61. package/dist/lib/node-esm/{ai-client-2GBZRHBA.mjs.map → ai-client-XGNA6SJ5.mjs.map} +3 -3
  62. package/dist/lib/node-esm/{app-graph-builder-5N7OK23B.mjs → app-graph-builder-IJQEN7WT.mjs} +70 -4
  63. package/dist/lib/node-esm/app-graph-builder-IJQEN7WT.mjs.map +7 -0
  64. package/dist/lib/node-esm/chunk-6HLBYDUI.mjs +244 -0
  65. package/dist/lib/node-esm/chunk-6HLBYDUI.mjs.map +7 -0
  66. package/dist/lib/node-esm/chunk-DNCXRGAF.mjs +151 -0
  67. package/dist/lib/node-esm/chunk-DNCXRGAF.mjs.map +7 -0
  68. package/dist/lib/node-esm/{chunk-X3LPRWIL.mjs → chunk-EMVA6QUT.mjs} +4 -2
  69. package/dist/lib/node-esm/chunk-EMVA6QUT.mjs.map +7 -0
  70. package/dist/lib/node-esm/{chunk-ISYLEDVU.mjs → chunk-IJRTDSKN.mjs} +2 -2
  71. package/dist/lib/node-esm/chunk-QP47VJT6.mjs +1603 -0
  72. package/dist/lib/node-esm/chunk-QP47VJT6.mjs.map +7 -0
  73. package/dist/lib/node-esm/{chunk-5QUXIXNB.mjs → chunk-ZLIAMW45.mjs} +108 -27
  74. package/dist/lib/node-esm/chunk-ZLIAMW45.mjs.map +7 -0
  75. package/dist/lib/node-esm/index.mjs +56 -45
  76. package/dist/lib/node-esm/index.mjs.map +3 -3
  77. package/dist/lib/node-esm/intent-resolver-DCP4ZDBA.mjs +30 -0
  78. package/dist/lib/node-esm/intent-resolver-DCP4ZDBA.mjs.map +7 -0
  79. package/dist/lib/node-esm/meta.json +1 -1
  80. package/dist/lib/node-esm/{react-surface-77S6XJOM.mjs → react-surface-SBDXFVIN.mjs} +32 -23
  81. package/dist/lib/node-esm/react-surface-SBDXFVIN.mjs.map +7 -0
  82. package/dist/lib/node-esm/types/index.mjs +10 -4
  83. package/dist/types/src/AutomationPlugin.d.ts.map +1 -1
  84. package/dist/types/src/artifacts.stories.d.ts +10 -24
  85. package/dist/types/src/artifacts.stories.d.ts.map +1 -1
  86. package/dist/types/src/capabilities/app-graph-builder.d.ts +45 -44
  87. package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -1
  88. package/dist/types/src/capabilities/index.d.ts +27 -27
  89. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  90. package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -1
  91. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
  92. package/dist/types/src/components/AmbientChatDialog/AmbientChatDialog.d.ts +3 -0
  93. package/dist/types/src/components/AmbientChatDialog/AmbientChatDialog.d.ts.map +1 -0
  94. package/dist/types/src/components/AmbientChatDialog/index.d.ts +2 -0
  95. package/dist/types/src/components/AmbientChatDialog/index.d.ts.map +1 -0
  96. package/dist/types/src/components/Box/StatusLine.d.ts +11 -0
  97. package/dist/types/src/components/Box/StatusLine.d.ts.map +1 -0
  98. package/dist/types/src/components/Box/StatusLine.stories.d.ts +9 -0
  99. package/dist/types/src/components/Box/StatusLine.stories.d.ts.map +1 -0
  100. package/dist/types/src/components/Box/Tabbed.d.ts +15 -0
  101. package/dist/types/src/components/Box/Tabbed.d.ts.map +1 -0
  102. package/dist/types/src/components/Box/Tabbed.stories.d.ts +8 -0
  103. package/dist/types/src/components/Box/Tabbed.stories.d.ts.map +1 -0
  104. package/dist/types/src/components/Box/ToggleContainer.d.ts +13 -0
  105. package/dist/types/src/components/Box/ToggleContainer.d.ts.map +1 -0
  106. package/dist/types/src/components/Box/ToggleContainer.stories.d.ts +9 -0
  107. package/dist/types/src/components/Box/ToggleContainer.stories.d.ts.map +1 -0
  108. package/dist/types/src/components/Box/index.d.ts +4 -0
  109. package/dist/types/src/components/Box/index.d.ts.map +1 -0
  110. package/dist/types/src/components/ChatContainer/ChatContainer.d.ts +7 -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/MarkdownViewer/MarkdownViewer.d.ts +14 -0
  115. package/dist/types/src/components/MarkdownViewer/MarkdownViewer.d.ts.map +1 -0
  116. package/dist/types/src/components/MarkdownViewer/MarkdownViewer.stories.d.ts +8 -0
  117. package/dist/types/src/components/MarkdownViewer/MarkdownViewer.stories.d.ts.map +1 -0
  118. package/dist/types/src/components/MarkdownViewer/index.d.ts +2 -0
  119. package/dist/types/src/components/MarkdownViewer/index.d.ts.map +1 -0
  120. package/dist/types/src/components/Prompt/Prompt.d.ts +7 -0
  121. package/dist/types/src/components/Prompt/Prompt.d.ts.map +1 -0
  122. package/dist/types/src/components/Prompt/Prompt.stories.d.ts +8 -0
  123. package/dist/types/src/components/Prompt/Prompt.stories.d.ts.map +1 -0
  124. package/dist/types/src/components/Prompt/index.d.ts +2 -0
  125. package/dist/types/src/components/Prompt/index.d.ts.map +1 -0
  126. package/dist/types/src/components/Prompt/prompt-autocomplete.d.ts +20 -0
  127. package/dist/types/src/components/Prompt/prompt-autocomplete.d.ts.map +1 -0
  128. package/dist/types/src/components/ServiceRegistry/ServiceRegistry.d.ts +6 -0
  129. package/dist/types/src/components/ServiceRegistry/ServiceRegistry.d.ts.map +1 -0
  130. package/dist/types/src/components/ServiceRegistry/ServiceRegistry.stories.d.ts +8 -0
  131. package/dist/types/src/components/ServiceRegistry/ServiceRegistry.stories.d.ts.map +1 -0
  132. package/dist/types/src/components/ServiceRegistry/index.d.ts +2 -0
  133. package/dist/types/src/components/ServiceRegistry/index.d.ts.map +1 -0
  134. package/dist/types/src/components/Thread/Thread.d.ts +6 -9
  135. package/dist/types/src/components/Thread/Thread.d.ts.map +1 -1
  136. package/dist/types/src/components/Thread/Thread.stories.d.ts +3 -4
  137. package/dist/types/src/components/Thread/Thread.stories.d.ts.map +1 -1
  138. package/dist/types/src/components/Thread/ThreadMessage.d.ts +12 -0
  139. package/dist/types/src/components/Thread/ThreadMessage.d.ts.map +1 -0
  140. package/dist/types/src/components/TriggerEditor/TriggerEditor.d.ts.map +1 -1
  141. package/dist/types/src/components/index.d.ts +6 -2
  142. package/dist/types/src/components/index.d.ts.map +1 -1
  143. package/dist/types/src/hooks/index.d.ts +3 -0
  144. package/dist/types/src/hooks/index.d.ts.map +1 -1
  145. package/dist/types/src/hooks/processor.d.ts +39 -15
  146. package/dist/types/src/hooks/processor.d.ts.map +1 -1
  147. package/dist/types/src/hooks/useChatProcessor.d.ts +7 -0
  148. package/dist/types/src/hooks/useChatProcessor.d.ts.map +1 -0
  149. package/dist/types/src/hooks/useMessageQueue.d.ts +41 -0
  150. package/dist/types/src/hooks/useMessageQueue.d.ts.map +1 -0
  151. package/dist/types/src/hooks/useServices.d.ts +7 -0
  152. package/dist/types/src/hooks/useServices.d.ts.map +1 -0
  153. package/dist/types/src/meta.d.ts +1 -0
  154. package/dist/types/src/meta.d.ts.map +1 -1
  155. package/dist/types/src/testing/index.d.ts +2 -1
  156. package/dist/types/src/testing/index.d.ts.map +1 -1
  157. package/dist/types/src/testing/{testing.d.ts → test-functions.d.ts} +1 -1
  158. package/dist/types/src/testing/test-functions.d.ts.map +1 -0
  159. package/dist/types/src/testing/test-services.d.ts +5 -0
  160. package/dist/types/src/testing/test-services.d.ts.map +1 -0
  161. package/dist/types/src/tools/function.d.ts +5 -0
  162. package/dist/types/src/tools/function.d.ts.map +1 -0
  163. package/dist/types/src/tools/index.d.ts +3 -0
  164. package/dist/types/src/tools/index.d.ts.map +1 -0
  165. package/dist/types/src/tools/openapi.d.ts +10 -0
  166. package/dist/types/src/tools/openapi.d.ts.map +1 -0
  167. package/dist/types/src/tools/openapi.test.d.ts +2 -0
  168. package/dist/types/src/tools/openapi.test.d.ts.map +1 -0
  169. package/dist/types/src/translations.d.ts +12 -6
  170. package/dist/types/src/translations.d.ts.map +1 -1
  171. package/dist/types/src/types/index.d.ts +1 -0
  172. package/dist/types/src/types/index.d.ts.map +1 -1
  173. package/dist/types/src/types/registry.d.ts +10 -0
  174. package/dist/types/src/types/registry.d.ts.map +1 -0
  175. package/dist/types/src/types/schema.d.ts +156 -7
  176. package/dist/types/src/types/schema.d.ts.map +1 -1
  177. package/dist/types/src/types/types.d.ts +2 -2
  178. package/dist/types/src/types/types.d.ts.map +1 -1
  179. package/dist/types/tsconfig.tsbuildinfo +1 -1
  180. package/package.json +56 -49
  181. package/src/AutomationPlugin.tsx +18 -26
  182. package/src/artifacts.stories.tsx +126 -65
  183. package/src/capabilities/ai-client.ts +1 -1
  184. package/src/capabilities/app-graph-builder.ts +65 -5
  185. package/src/capabilities/intent-resolver.ts +14 -9
  186. package/src/capabilities/react-surface.tsx +21 -13
  187. package/src/components/AmbientChatDialog/AmbientChatDialog.tsx +26 -0
  188. package/src/components/AmbientChatDialog/index.ts +5 -0
  189. package/src/components/Box/StatusLine.stories.tsx +52 -0
  190. package/src/components/Box/StatusLine.tsx +76 -0
  191. package/src/components/Box/Tabbed.stories.tsx +51 -0
  192. package/src/components/Box/Tabbed.tsx +89 -0
  193. package/src/components/Box/ToggleContainer.stories.tsx +110 -0
  194. package/src/components/Box/ToggleContainer.tsx +108 -0
  195. package/src/components/Box/index.ts +7 -0
  196. package/src/components/ChatContainer/ChatContainer.tsx +52 -0
  197. package/src/components/ChatContainer/index.ts +8 -0
  198. package/src/components/MarkdownViewer/MarkdownViewer.stories.tsx +56 -0
  199. package/src/components/MarkdownViewer/MarkdownViewer.tsx +79 -0
  200. package/src/components/MarkdownViewer/index.ts +5 -0
  201. package/src/components/Prompt/Prompt.stories.tsx +50 -0
  202. package/src/components/Prompt/Prompt.tsx +36 -0
  203. package/src/components/Prompt/index.ts +5 -0
  204. package/src/components/Prompt/prompt-autocomplete.ts +200 -0
  205. package/src/components/PromptEditor/PromptEditor.stories.tsx +3 -3
  206. package/src/components/ServiceRegistry/ServiceRegistry.stories.tsx +49 -0
  207. package/src/components/ServiceRegistry/ServiceRegistry.tsx +75 -0
  208. package/src/components/ServiceRegistry/index.ts +5 -0
  209. package/src/components/Thread/Thread.stories.tsx +152 -97
  210. package/src/components/Thread/Thread.tsx +115 -108
  211. package/src/components/Thread/ThreadMessage.tsx +225 -0
  212. package/src/components/TriggerEditor/TriggerEditor.tsx +8 -5
  213. package/src/components/index.ts +5 -1
  214. package/src/hooks/index.ts +4 -0
  215. package/src/hooks/processor.ts +114 -65
  216. package/src/hooks/useChatProcessor.tsx +86 -0
  217. package/src/hooks/useMessageQueue.ts +23 -0
  218. package/src/hooks/useServices.ts +28 -0
  219. package/src/meta.ts +4 -1
  220. package/src/testing/index.ts +2 -1
  221. package/src/testing/test-services.ts +131 -0
  222. package/src/tools/function.ts +47 -0
  223. package/src/tools/index.ts +6 -0
  224. package/src/tools/openapi.test.ts +227 -0
  225. package/src/tools/openapi.ts +331 -0
  226. package/src/translations.ts +9 -6
  227. package/src/types/index.ts +1 -0
  228. package/src/types/registry.ts +26 -0
  229. package/src/types/schema.ts +90 -3
  230. package/src/types/types.ts +2 -2
  231. package/dist/lib/browser/AssistantPanel-KO6DZBTU.mjs +0 -340
  232. package/dist/lib/browser/AssistantPanel-KO6DZBTU.mjs.map +0 -7
  233. package/dist/lib/browser/AutomationPanel-BMLM533Z.mjs +0 -131
  234. package/dist/lib/browser/AutomationPanel-BMLM533Z.mjs.map +0 -7
  235. package/dist/lib/browser/ChatContainer-SIAJFRFF.mjs +0 -300
  236. package/dist/lib/browser/ChatContainer-SIAJFRFF.mjs.map +0 -7
  237. package/dist/lib/browser/app-graph-builder-IJTTULDP.mjs.map +0 -7
  238. package/dist/lib/browser/chunk-C3VRGDR6.mjs +0 -75
  239. package/dist/lib/browser/chunk-C3VRGDR6.mjs.map +0 -7
  240. package/dist/lib/browser/chunk-EKJVAFT2.mjs.map +0 -7
  241. package/dist/lib/browser/chunk-HKX3D3ZP.mjs.map +0 -7
  242. package/dist/lib/browser/chunk-JSNPW6JF.mjs +0 -14
  243. package/dist/lib/browser/chunk-JSNPW6JF.mjs.map +0 -7
  244. package/dist/lib/browser/chunk-KPSDH6XZ.mjs +0 -118
  245. package/dist/lib/browser/chunk-KPSDH6XZ.mjs.map +0 -7
  246. package/dist/lib/browser/chunk-YZF3SDZL.mjs +0 -139
  247. package/dist/lib/browser/chunk-YZF3SDZL.mjs.map +0 -7
  248. package/dist/lib/browser/intent-resolver-AHDQ3KQP.mjs +0 -24
  249. package/dist/lib/browser/intent-resolver-AHDQ3KQP.mjs.map +0 -7
  250. package/dist/lib/browser/react-surface-IGMBLSV7.mjs.map +0 -7
  251. package/dist/lib/node/AssistantPanel-PPFS2HKK.cjs +0 -360
  252. package/dist/lib/node/AssistantPanel-PPFS2HKK.cjs.map +0 -7
  253. package/dist/lib/node/AutomationPanel-RXJDVLCF.cjs.map +0 -7
  254. package/dist/lib/node/ChatContainer-GS2SC5OG.cjs +0 -318
  255. package/dist/lib/node/ChatContainer-GS2SC5OG.cjs.map +0 -7
  256. package/dist/lib/node/app-graph-builder-MF5M4QRS.cjs.map +0 -7
  257. package/dist/lib/node/chunk-5VF5JKUN.cjs.map +0 -7
  258. package/dist/lib/node/chunk-BUQOZA4N.cjs.map +0 -7
  259. package/dist/lib/node/chunk-DNLBVFR7.cjs +0 -147
  260. package/dist/lib/node/chunk-DNLBVFR7.cjs.map +0 -7
  261. package/dist/lib/node/chunk-TWDGP26W.cjs +0 -172
  262. package/dist/lib/node/chunk-TWDGP26W.cjs.map +0 -7
  263. package/dist/lib/node/chunk-VEGLN4YN.cjs +0 -250
  264. package/dist/lib/node/chunk-VEGLN4YN.cjs.map +0 -7
  265. package/dist/lib/node/chunk-Z2YFE5SJ.cjs +0 -49
  266. package/dist/lib/node/chunk-Z2YFE5SJ.cjs.map +0 -7
  267. package/dist/lib/node/intent-resolver-TBHYXBDI.cjs.map +0 -7
  268. package/dist/lib/node/react-surface-BVUZMKYS.cjs.map +0 -7
  269. package/dist/lib/node-esm/AssistantPanel-XSSKKCJY.mjs +0 -341
  270. package/dist/lib/node-esm/AssistantPanel-XSSKKCJY.mjs.map +0 -7
  271. package/dist/lib/node-esm/AutomationPanel-GQZZ4UBI.mjs +0 -132
  272. package/dist/lib/node-esm/AutomationPanel-GQZZ4UBI.mjs.map +0 -7
  273. package/dist/lib/node-esm/ChatContainer-57ILGC3R.mjs +0 -301
  274. package/dist/lib/node-esm/ChatContainer-57ILGC3R.mjs.map +0 -7
  275. package/dist/lib/node-esm/app-graph-builder-5N7OK23B.mjs.map +0 -7
  276. package/dist/lib/node-esm/chunk-5QUXIXNB.mjs.map +0 -7
  277. package/dist/lib/node-esm/chunk-ICHNUP5M.mjs +0 -119
  278. package/dist/lib/node-esm/chunk-ICHNUP5M.mjs.map +0 -7
  279. package/dist/lib/node-esm/chunk-JCYVS5GG.mjs +0 -76
  280. package/dist/lib/node-esm/chunk-JCYVS5GG.mjs.map +0 -7
  281. package/dist/lib/node-esm/chunk-L2B6VGMG.mjs +0 -16
  282. package/dist/lib/node-esm/chunk-L2B6VGMG.mjs.map +0 -7
  283. package/dist/lib/node-esm/chunk-U7HXYMPZ.mjs +0 -141
  284. package/dist/lib/node-esm/chunk-U7HXYMPZ.mjs.map +0 -7
  285. package/dist/lib/node-esm/chunk-X3LPRWIL.mjs.map +0 -7
  286. package/dist/lib/node-esm/intent-resolver-DPJJHFGK.mjs +0 -25
  287. package/dist/lib/node-esm/intent-resolver-DPJJHFGK.mjs.map +0 -7
  288. package/dist/lib/node-esm/react-surface-77S6XJOM.mjs.map +0 -7
  289. package/dist/types/src/components/AssistantPanel/AssistantPanel.d.ts +0 -8
  290. package/dist/types/src/components/AssistantPanel/AssistantPanel.d.ts.map +0 -1
  291. package/dist/types/src/components/AssistantPanel/index.d.ts +0 -3
  292. package/dist/types/src/components/AssistantPanel/index.d.ts.map +0 -1
  293. package/dist/types/src/components/AssistantPanel/system-instructions.d.ts +0 -6
  294. package/dist/types/src/components/AssistantPanel/system-instructions.d.ts.map +0 -1
  295. package/dist/types/src/components/ChatContainer.d.ts +0 -8
  296. package/dist/types/src/components/ChatContainer.d.ts.map +0 -1
  297. package/dist/types/src/testing/testing.d.ts.map +0 -1
  298. package/src/components/AssistantPanel/AssistantPanel.tsx +0 -232
  299. package/src/components/AssistantPanel/index.ts +0 -7
  300. package/src/components/AssistantPanel/system-instructions.ts +0 -166
  301. package/src/components/ChatContainer.tsx +0 -80
  302. /package/dist/lib/browser/{chunk-HZ4TA7HY.mjs.map → chunk-2H2EUYXL.mjs.map} +0 -0
  303. /package/dist/lib/node/{chunk-ZS5RZ7RM.cjs.map → chunk-U5Z7LFWB.cjs.map} +0 -0
  304. /package/dist/lib/node-esm/{chunk-ISYLEDVU.mjs.map → chunk-IJRTDSKN.mjs.map} +0 -0
  305. /package/src/testing/{testing.ts → test-functions.ts} +0 -0
@@ -0,0 +1,1602 @@
1
+ import {
2
+ AutomationCapabilities
3
+ } from "./chunk-2H2EUYXL.mjs";
4
+ import {
5
+ ServiceType,
6
+ categoryIcons
7
+ } from "./chunk-Q4IMHYGH.mjs";
8
+ import {
9
+ AUTOMATION_PLUGIN
10
+ } from "./chunk-R4JH4TLE.mjs";
11
+
12
+ // packages/plugins/experimental/plugin-automation/src/components/ChatContainer/ChatContainer.tsx
13
+ import React7, { useCallback as useCallback2 } from "react";
14
+ import { invariant as invariant6 } from "@dxos/invariant";
15
+ import { StackItem } from "@dxos/react-ui-stack";
16
+
17
+ // packages/plugins/experimental/plugin-automation/src/hooks/processor.ts
18
+ import { batch, computed, signal } from "@preact/signals-core";
19
+ import { Message } from "@dxos/artifact";
20
+ import { isToolUse, runTools, MixedStreamParser } from "@dxos/assistant";
21
+ import { createStatic } from "@dxos/echo-schema";
22
+ import { invariant } from "@dxos/invariant";
23
+ import { log } from "@dxos/log";
24
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-automation/src/hooks/processor.ts";
25
+ var defaultOptions = {
26
+ model: "@anthropic/claude-3-5-sonnet-20241022",
27
+ systemPrompt: "you are a helpful assistant"
28
+ };
29
+ var ChatProcessor = class {
30
+ constructor(_client, _tools, _extensions, _options = defaultOptions) {
31
+ this._client = _client;
32
+ this._tools = _tools;
33
+ this._extensions = _extensions;
34
+ this._options = _options;
35
+ this._parser = new MixedStreamParser();
36
+ this._pending = signal([]);
37
+ this._block = signal(void 0);
38
+ this._history = [];
39
+ this.streaming = computed(() => this._block.value !== void 0);
40
+ this.messages = computed(() => {
41
+ const messages = [
42
+ ...this._pending.value
43
+ ];
44
+ if (this._block.value) {
45
+ const current = messages.pop();
46
+ invariant(current, void 0, {
47
+ F: __dxlog_file,
48
+ L: 78,
49
+ S: this,
50
+ A: [
51
+ "current",
52
+ ""
53
+ ]
54
+ });
55
+ const { content, ...rest } = current;
56
+ const message = {
57
+ ...rest,
58
+ content: [
59
+ ...content,
60
+ this._block.value
61
+ ]
62
+ };
63
+ messages.push(message);
64
+ }
65
+ return messages;
66
+ });
67
+ this._parser.message.on((message) => {
68
+ batch(() => {
69
+ this._pending.value = [
70
+ ...this._pending.value,
71
+ message
72
+ ];
73
+ this._block.value = void 0;
74
+ });
75
+ });
76
+ this._parser.update.on((block) => {
77
+ batch(() => {
78
+ this._block.value = block;
79
+ });
80
+ });
81
+ }
82
+ /**
83
+ * Update tools.
84
+ */
85
+ setTools(tools) {
86
+ this._tools = tools;
87
+ }
88
+ /**
89
+ * Make GPT request.
90
+ */
91
+ async request(message, options = {}) {
92
+ batch(() => {
93
+ this._history = options.history ?? [];
94
+ this._pending.value = [
95
+ createStatic(Message, {
96
+ role: "user",
97
+ content: [
98
+ {
99
+ type: "text",
100
+ text: message
101
+ }
102
+ ]
103
+ })
104
+ ];
105
+ this._block.value = void 0;
106
+ });
107
+ await this._generate();
108
+ options.onComplete?.(this._pending.value);
109
+ return this._reset();
110
+ }
111
+ /**
112
+ * Cancel pending requests.
113
+ * @returns Pending requests (incl. the request message).
114
+ */
115
+ async cancel() {
116
+ log.info("cancelling...", void 0, {
117
+ F: __dxlog_file,
118
+ L: 141,
119
+ S: this,
120
+ C: (f, a) => f(...a)
121
+ });
122
+ this._stream?.abort();
123
+ return this._reset();
124
+ }
125
+ async _reset() {
126
+ const messages = this._pending.value;
127
+ batch(() => {
128
+ this._history = [];
129
+ this._pending.value = [];
130
+ this._block.value = void 0;
131
+ });
132
+ return messages;
133
+ }
134
+ /**
135
+ * Generate a response from the AI service.
136
+ * Iterates over tool requests.
137
+ */
138
+ async _generate() {
139
+ try {
140
+ let more = false;
141
+ do {
142
+ log.info("requesting...", {
143
+ history: this._history.length,
144
+ messages: this._pending.value.length
145
+ }, {
146
+ F: __dxlog_file,
147
+ L: 165,
148
+ S: this,
149
+ C: (f, a) => f(...a)
150
+ });
151
+ this._stream = await this._client.generate({
152
+ ...this._options,
153
+ // TODO(burdon): Rename messages or separate history/message.
154
+ history: [
155
+ ...this._history,
156
+ ...this._pending.value
157
+ ],
158
+ tools: this._tools
159
+ });
160
+ await this._parser.parse(this._stream);
161
+ await this._stream.complete();
162
+ log.info("response", {
163
+ messages: this._pending.value
164
+ }, {
165
+ F: __dxlog_file,
166
+ L: 178,
167
+ S: this,
168
+ C: (f, a) => f(...a)
169
+ });
170
+ more = false;
171
+ const message = this._pending.value.at(-1);
172
+ invariant(message, void 0, {
173
+ F: __dxlog_file,
174
+ L: 183,
175
+ S: this,
176
+ A: [
177
+ "message",
178
+ ""
179
+ ]
180
+ });
181
+ if (isToolUse(message)) {
182
+ log.info("tool request...", void 0, {
183
+ F: __dxlog_file,
184
+ L: 185,
185
+ S: this,
186
+ C: (f, a) => f(...a)
187
+ });
188
+ const response = await runTools({
189
+ message: this._pending.value.at(-1),
190
+ tools: this._tools ?? [],
191
+ extensions: this._extensions
192
+ });
193
+ log.info("tool response", {
194
+ response
195
+ }, {
196
+ F: __dxlog_file,
197
+ L: 192,
198
+ S: this,
199
+ C: (f, a) => f(...a)
200
+ });
201
+ switch (response.type) {
202
+ case "continue": {
203
+ this._pending.value = [
204
+ ...this._pending.value,
205
+ response.message
206
+ ];
207
+ more = true;
208
+ break;
209
+ }
210
+ }
211
+ }
212
+ } while (more);
213
+ } catch (err) {
214
+ log.catch("request failed", {
215
+ err
216
+ }, {
217
+ F: __dxlog_file,
218
+ L: 204,
219
+ S: this,
220
+ C: (f, a) => f(...a)
221
+ });
222
+ } finally {
223
+ log.info("done", void 0, {
224
+ F: __dxlog_file,
225
+ L: 206,
226
+ S: this,
227
+ C: (f, a) => f(...a)
228
+ });
229
+ this._stream = void 0;
230
+ }
231
+ }
232
+ };
233
+
234
+ // packages/plugins/experimental/plugin-automation/src/hooks/useChatProcessor.tsx
235
+ import { useEffect, useMemo, useState } from "react";
236
+ import { Capabilities, useCapabilities, useCapability, useIntentDispatcher } from "@dxos/app-framework";
237
+ import { createSystemPrompt } from "@dxos/artifact";
238
+ import { FunctionType } from "@dxos/functions";
239
+ import { useConfig } from "@dxos/react-client";
240
+ import { Filter, getSpace, useQuery } from "@dxos/react-client/echo";
241
+ import { isNotNullOrUndefined } from "@dxos/util";
242
+
243
+ // packages/plugins/experimental/plugin-automation/src/capabilities/index.ts
244
+ import { lazy } from "@dxos/app-framework";
245
+ var AiClient = lazy(() => import("./ai-client-5CNY6JBF.mjs"));
246
+ var AppGraphBuilder = lazy(() => import("./app-graph-builder-FZGK55G7.mjs"));
247
+ var IntentResolver = lazy(() => import("./intent-resolver-BWAXKT27.mjs"));
248
+ var ReactSurface = lazy(() => import("./react-surface-ILBDBZCN.mjs"));
249
+
250
+ // packages/plugins/experimental/plugin-automation/src/tools/function.ts
251
+ import { defineTool, ToolResult } from "@dxos/artifact";
252
+ import { toEffectSchema } from "@dxos/echo-schema";
253
+ import { getInvocationUrl, getUserFunctionUrlInMetadata } from "@dxos/functions";
254
+ import { log as log2 } from "@dxos/log";
255
+ import { getMeta } from "@dxos/react-client/echo";
256
+ var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-automation/src/tools/function.ts";
257
+ var covertFunctionToTool = (fn, edgeUrl, spaceId) => {
258
+ if (!fn.description || !fn.inputSchema) {
259
+ return void 0;
260
+ }
261
+ const existingFunctionUrl = getUserFunctionUrlInMetadata(getMeta(fn));
262
+ if (!existingFunctionUrl) {
263
+ return void 0;
264
+ }
265
+ const url = getInvocationUrl(existingFunctionUrl, edgeUrl, {
266
+ spaceId
267
+ });
268
+ return defineTool({
269
+ name: fn.name,
270
+ description: fn.description,
271
+ schema: toEffectSchema(fn.inputSchema),
272
+ execute: async (input) => {
273
+ log2.info("execute function tool", {
274
+ name: fn.name,
275
+ url,
276
+ input
277
+ }, {
278
+ F: __dxlog_file2,
279
+ L: 36,
280
+ S: void 0,
281
+ C: (f, a) => f(...a)
282
+ });
283
+ const response = await fetch(url, {
284
+ method: "POST",
285
+ headers: {
286
+ "Content-Type": "application/json"
287
+ },
288
+ body: JSON.stringify(input)
289
+ });
290
+ return ToolResult.Success(await response.text());
291
+ }
292
+ });
293
+ };
294
+
295
+ // packages/plugins/experimental/plugin-automation/src/tools/openapi.ts
296
+ import jsonpointer from "jsonpointer";
297
+ import { ToolResult as ToolResult2 } from "@dxos/artifact";
298
+ import { JsonSchemaType, normalizeSchema, S, toEffectSchema as toEffectSchema2 } from "@dxos/echo-schema";
299
+ import { invariant as invariant2 } from "@dxos/invariant";
300
+ import { log as log3 } from "@dxos/log";
301
+ import { deepMapValues } from "@dxos/util";
302
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-automation/src/tools/openapi.ts";
303
+ var createToolsFromService = async (service) => {
304
+ invariant2(service.interfaces?.length === 1 && service.interfaces[0].kind === "api", void 0, {
305
+ F: __dxlog_file3,
306
+ L: 22,
307
+ S: void 0,
308
+ A: [
309
+ "service.interfaces?.length === 1 && service.interfaces[0].kind === 'api'",
310
+ ""
311
+ ]
312
+ });
313
+ const iface = service.interfaces[0];
314
+ invariant2(iface.schemaUrl, void 0, {
315
+ F: __dxlog_file3,
316
+ L: 24,
317
+ S: void 0,
318
+ A: [
319
+ "iface.schemaUrl",
320
+ ""
321
+ ]
322
+ });
323
+ invariant2(iface.schemaUrl, void 0, {
324
+ F: __dxlog_file3,
325
+ L: 25,
326
+ S: void 0,
327
+ A: [
328
+ "iface.schemaUrl",
329
+ ""
330
+ ]
331
+ });
332
+ return createToolsFromApi(iface.schemaUrl, {
333
+ authorization: iface.authorization
334
+ });
335
+ };
336
+ var createToolsFromApi = async (url, options) => {
337
+ const res = await fetch(url);
338
+ const spec = await res.json();
339
+ log3("spec", {
340
+ spec
341
+ }, {
342
+ F: __dxlog_file3,
343
+ L: 32,
344
+ S: void 0,
345
+ C: (f, a) => f(...a)
346
+ });
347
+ const tools = [];
348
+ for (const [path, pathItem] of Object.entries(spec.paths)) {
349
+ if (typeof pathItem !== "object") {
350
+ continue;
351
+ }
352
+ const { ...methods } = pathItem;
353
+ for (const [method, m] of Object.entries(methods)) {
354
+ const methodItem = m;
355
+ log3("methodItem", {
356
+ path,
357
+ method,
358
+ methodItem
359
+ }, {
360
+ F: __dxlog_file3,
361
+ L: 44,
362
+ S: void 0,
363
+ C: (f, a) => f(...a)
364
+ });
365
+ const parametersResolved = methodItem.parameters?.map((parameter) => {
366
+ const resolved = resolveJsonSchema(parameter, spec);
367
+ return resolved;
368
+ }) ?? [];
369
+ const inputSchema = {
370
+ type: "object",
371
+ properties: {}
372
+ };
373
+ const endpointParameters = [];
374
+ for (const parameter of parametersResolved) {
375
+ log3("parameter", {
376
+ parameter
377
+ }, {
378
+ F: __dxlog_file3,
379
+ L: 59,
380
+ S: void 0,
381
+ C: (f, a) => f(...a)
382
+ });
383
+ if (options?.authorization?.type === "api-key" && options.authorization.placement.type === "query" && parameter.in === "query" && parameter.name === options.authorization.placement.name) {
384
+ continue;
385
+ }
386
+ endpointParameters.push(parameter);
387
+ if (parameter.schema) {
388
+ inputSchema.properties[parameter.name] = normalizeSchema(parameter.schema);
389
+ } else if (typeof parameter.type === "string") {
390
+ const { name, in: _in, required, ...schema } = parameter;
391
+ inputSchema.properties[name] = normalizeSchema(schema);
392
+ if (required) {
393
+ inputSchema.required ??= [];
394
+ inputSchema.required.push(name);
395
+ }
396
+ }
397
+ }
398
+ log3("inputSchema", {
399
+ inputSchema
400
+ }, {
401
+ F: __dxlog_file3,
402
+ L: 84,
403
+ S: void 0,
404
+ C: (f, a) => f(...a)
405
+ });
406
+ S.validateSync(JsonSchemaType)(inputSchema);
407
+ const description = methodItem.description ?? methodItem.summary;
408
+ if (!description) {
409
+ log3.warn("no description", {
410
+ path,
411
+ method
412
+ }, {
413
+ F: __dxlog_file3,
414
+ L: 89,
415
+ S: void 0,
416
+ C: (f, a) => f(...a)
417
+ });
418
+ continue;
419
+ }
420
+ const endpoint = {
421
+ document: spec,
422
+ path,
423
+ method,
424
+ parameters: endpointParameters,
425
+ authorization: options?.authorization
426
+ };
427
+ tools.push({
428
+ name: getToolName(path, method, methodItem),
429
+ description: options?.instructions ? `${options.instructions}
430
+
431
+ ${description}` : description,
432
+ parameters: inputSchema,
433
+ execute: async (input) => {
434
+ const response = await callApiEndpoint(endpoint, input);
435
+ return ToolResult2.Success(response);
436
+ }
437
+ });
438
+ }
439
+ }
440
+ return tools;
441
+ };
442
+ var getToolName = (path, method, methodItem) => {
443
+ if (methodItem.operationId) {
444
+ return methodItem.operationId;
445
+ }
446
+ let name = `${method.toLowerCase()}_${path.replaceAll(/[{}/]/g, "_")}`;
447
+ while (name.length > MAX_TOOL_NAME_LENGTH) {
448
+ const lengthBefore = name.length;
449
+ for (const word of GENERIC_WORDS) {
450
+ if (name.includes(word)) {
451
+ name = name.replace(word, "");
452
+ break;
453
+ }
454
+ }
455
+ name = name.replaceAll("__", "_").replace(/_$/, "");
456
+ const lengthAfter = name.length;
457
+ if (lengthBefore === lengthAfter) {
458
+ break;
459
+ }
460
+ }
461
+ name = name.replaceAll("__", "_").replace(/_$/, "").replace(/^_/, "");
462
+ return name.slice(0, MAX_TOOL_NAME_LENGTH);
463
+ };
464
+ var MAX_TOOL_NAME_LENGTH = 64;
465
+ var GENERIC_WORDS = [
466
+ "services",
467
+ "service",
468
+ "api",
469
+ "rest",
470
+ "endpoint",
471
+ "get",
472
+ "post",
473
+ "put",
474
+ "delete",
475
+ "patch",
476
+ "head",
477
+ "options",
478
+ "trace",
479
+ "service",
480
+ "api",
481
+ "endpoint"
482
+ ];
483
+ var callApiEndpoint = async (endpoint, input) => {
484
+ log3.info("endpoint", {
485
+ method: endpoint.method,
486
+ name: endpoint.path,
487
+ input
488
+ }, {
489
+ F: __dxlog_file3,
490
+ L: 173,
491
+ S: void 0,
492
+ C: (f, a) => f(...a)
493
+ });
494
+ let url = getEndpointUrl(endpoint);
495
+ const request = {
496
+ method: endpoint.method,
497
+ headers: {}
498
+ };
499
+ const query = new URLSearchParams();
500
+ let body;
501
+ for (const parameter of endpoint.parameters) {
502
+ if (input[parameter.name] === void 0) {
503
+ continue;
504
+ }
505
+ switch (parameter.in) {
506
+ case "header": {
507
+ if (parameter.example) {
508
+ request.headers[parameter.name] = parameter.default;
509
+ }
510
+ break;
511
+ }
512
+ case "path": {
513
+ url = url.replace(`{${parameter.name}}`, encodeURIComponent(input[parameter.name]));
514
+ break;
515
+ }
516
+ case "body": {
517
+ const value = input[parameter.name];
518
+ const effectSchema = toEffectSchema2(parameter.schema);
519
+ S.validateSync(effectSchema)(value);
520
+ if (body) {
521
+ throw new Error(`Duplicate body parameter: ${parameter.name}`);
522
+ }
523
+ body = value;
524
+ break;
525
+ }
526
+ case "query": {
527
+ query.set(parameter.name, input[parameter.name]);
528
+ break;
529
+ }
530
+ }
531
+ }
532
+ if (endpoint.authorization?.type === "api-key" && endpoint.authorization.placement.type === "authorization-header" || endpoint.authorization?.type === "oauth") {
533
+ request.headers.Authorization = await resolveAuthorization(endpoint.authorization);
534
+ } else if (endpoint.authorization?.type === "api-key" && endpoint.authorization.placement.type === "query") {
535
+ query.set(endpoint.authorization.placement.name, endpoint.authorization.key);
536
+ }
537
+ if (query.size > 0) {
538
+ url += `?${query.toString()}`;
539
+ }
540
+ if (body) {
541
+ request.body = JSON.stringify(body);
542
+ request.headers["Content-Type"] = "application/json";
543
+ }
544
+ log3.info("request", {
545
+ url,
546
+ request
547
+ }, {
548
+ F: __dxlog_file3,
549
+ L: 236,
550
+ S: void 0,
551
+ C: (f, a) => f(...a)
552
+ });
553
+ const response = await fetch(url, request);
554
+ log3.info("response", {
555
+ ok: response.ok,
556
+ status: response.status,
557
+ statusText: response.statusText
558
+ }, {
559
+ F: __dxlog_file3,
560
+ L: 239,
561
+ S: void 0,
562
+ C: (f, a) => f(...a)
563
+ });
564
+ if (response.ok) {
565
+ const contentType = response.headers.get("Content-Type");
566
+ if (contentType?.includes("application/json")) {
567
+ return await response.json();
568
+ } else {
569
+ return await response.text();
570
+ }
571
+ } else {
572
+ if (response.headers.get("Content-Type")?.includes("application/json")) {
573
+ const responseBody = await response.text();
574
+ let error;
575
+ try {
576
+ error = JSON.parse(responseBody);
577
+ } catch {
578
+ error = responseBody;
579
+ }
580
+ log3.error("error", {
581
+ error
582
+ }, {
583
+ F: __dxlog_file3,
584
+ L: 257,
585
+ S: void 0,
586
+ C: (f, a) => f(...a)
587
+ });
588
+ throw new Error(error.message);
589
+ } else {
590
+ const error = await response.text();
591
+ log3.error("error", {
592
+ error
593
+ }, {
594
+ F: __dxlog_file3,
595
+ L: 261,
596
+ S: void 0,
597
+ C: (f, a) => f(...a)
598
+ });
599
+ throw new Error(error);
600
+ }
601
+ }
602
+ };
603
+ var getEndpointUrl = (endpoint) => {
604
+ let url = "";
605
+ if (isV3_1(endpoint.document) && endpoint.document.servers && endpoint.document.servers.length > 0) {
606
+ url = endpoint.document.servers[0].url;
607
+ } else {
608
+ invariant2(!isV3_1(endpoint.document), void 0, {
609
+ F: __dxlog_file3,
610
+ L: 272,
611
+ S: void 0,
612
+ A: [
613
+ "!isV3_1(endpoint.document)",
614
+ ""
615
+ ]
616
+ });
617
+ url = `${endpoint.document.schemes?.[0] ?? "https"}://${endpoint.document.host}`;
618
+ }
619
+ if (!isV3_1(endpoint.document) && endpoint.document.basePath) {
620
+ url += endpoint.document.basePath;
621
+ }
622
+ url += endpoint.path;
623
+ return url;
624
+ };
625
+ var resolveAuthorization = async (authorization) => {
626
+ switch (authorization.type) {
627
+ case "api-key": {
628
+ invariant2(authorization.placement.type === "authorization-header", void 0, {
629
+ F: __dxlog_file3,
630
+ L: 288,
631
+ S: void 0,
632
+ A: [
633
+ "authorization.placement.type === 'authorization-header'",
634
+ ""
635
+ ]
636
+ });
637
+ return `Bearer ${authorization.key}`;
638
+ }
639
+ case "oauth": {
640
+ const response = await fetch(authorization.tokenUrl, {
641
+ method: "POST",
642
+ headers: {
643
+ "Content-Type": "application/x-www-form-urlencoded"
644
+ },
645
+ body: `grant_type=${authorization.grantType}&client_id=${authorization.clientId}&client_secret=${authorization.clientSecret}`
646
+ });
647
+ const data = await response.json();
648
+ return `Bearer ${data.access_token}`;
649
+ }
650
+ default: {
651
+ throw new Error(`Unknown authorization type: ${authorization.type}`);
652
+ }
653
+ }
654
+ };
655
+ var resolveJsonSchema = (schema, base) => {
656
+ return deepMapValues(schema, (value, recurse) => {
657
+ if (typeof value === "object" && value !== null && "$ref" in value && typeof value.$ref === "string") {
658
+ if (value.$ref.startsWith("#")) {
659
+ const resolved = jsonpointer.get(base, value.$ref.slice(1));
660
+ if (resolved) {
661
+ return recurse(resolved);
662
+ } else {
663
+ log3.warn("unresolved", {
664
+ ref: value.$ref,
665
+ base
666
+ }, {
667
+ F: __dxlog_file3,
668
+ L: 321,
669
+ S: void 0,
670
+ C: (f, a) => f(...a)
671
+ });
672
+ }
673
+ }
674
+ }
675
+ return recurse(value);
676
+ });
677
+ };
678
+ var isV3_1 = (document) => {
679
+ return document.openapi === "3.0.1";
680
+ };
681
+
682
+ // packages/plugins/experimental/plugin-automation/src/hooks/useChatProcessor.tsx
683
+ var useChatProcessor = (chat) => {
684
+ const aiClient = useCapability(AutomationCapabilities.AiClient);
685
+ const globalTools = useCapabilities(Capabilities.Tools);
686
+ const artifactDefinitions = useCapabilities(Capabilities.ArtifactDefinition);
687
+ const { dispatchPromise: dispatch } = useIntentDispatcher();
688
+ const space = getSpace(chat);
689
+ const services = useQuery(space, Filter.schema(ServiceType));
690
+ const [serviceTools, setServiceTools] = useState([]);
691
+ useEffect(() => {
692
+ queueMicrotask(async () => {
693
+ const tools2 = await Promise.all(services.map((service) => createToolsFromService(service)));
694
+ setServiceTools(tools2.flat());
695
+ });
696
+ }, [
697
+ services
698
+ ]);
699
+ const config = useConfig();
700
+ const functions2 = useQuery(space, Filter.schema(FunctionType));
701
+ const tools = useMemo(() => [
702
+ ...globalTools.flat(),
703
+ ...artifactDefinitions.flatMap((definition) => definition.tools),
704
+ ...serviceTools,
705
+ ...functions2.map((fn) => covertFunctionToTool(fn, config.values.runtime?.services?.edge?.url ?? "", space?.id)).filter(isNotNullOrUndefined)
706
+ ], [
707
+ globalTools,
708
+ artifactDefinitions,
709
+ serviceTools,
710
+ functions2,
711
+ space?.id
712
+ ]);
713
+ const systemPrompt = useMemo(() => createSystemPrompt({
714
+ artifacts: artifactDefinitions.map((definition) => definition.instructions)
715
+ }), [
716
+ artifactDefinitions
717
+ ]);
718
+ const processor = useMemo(() => new ChatProcessor(aiClient, tools, {
719
+ space,
720
+ dispatch
721
+ }, {
722
+ model: "@anthropic/claude-3-5-sonnet-20241022",
723
+ systemPrompt
724
+ }), [
725
+ aiClient,
726
+ tools,
727
+ space,
728
+ dispatch,
729
+ systemPrompt
730
+ ]);
731
+ return processor;
732
+ };
733
+
734
+ // packages/plugins/experimental/plugin-automation/src/hooks/useLocalTriggerManager.ts
735
+ import { useEffect as useEffect2, useState as useState2 } from "react";
736
+ import { Mutex } from "@dxos/async";
737
+ import { Context } from "@dxos/context";
738
+ import { createSubscriptionTrigger } from "@dxos/functions";
739
+ import { FunctionTrigger } from "@dxos/functions";
740
+ import { invariant as invariant4 } from "@dxos/invariant";
741
+ import { log as log5 } from "@dxos/log";
742
+ import { useClient } from "@dxos/react-client";
743
+ import { Filter as Filter2, useQuery as useQuery2 } from "@dxos/react-client/echo";
744
+
745
+ // packages/plugins/experimental/plugin-automation/src/hooks/invocation-handler.ts
746
+ import { sleep } from "@dxos/async";
747
+ import { getObjectCore, ResultFormat } from "@dxos/echo-db";
748
+ import { FunctionType as FunctionType2 } from "@dxos/functions";
749
+ import { invariant as invariant3 } from "@dxos/invariant";
750
+ import { DXN, LOCAL_SPACE_TAG } from "@dxos/keys";
751
+ import { log as log4 } from "@dxos/log";
752
+
753
+ // packages/plugins/experimental/plugin-automation/src/hooks/useLocalTriggerManager.ts
754
+ var registerTriggersMutex = new Mutex();
755
+
756
+ // packages/plugins/experimental/plugin-automation/src/hooks/useMessageQueue.ts
757
+ import { useMemo as useMemo2 } from "react";
758
+ import { DXN as DXN2, QueueSubspaceTags } from "@dxos/keys";
759
+ import { getSpace as getSpace2 } from "@dxos/react-client/echo";
760
+ import { useEdgeClient, useQueue } from "@dxos/react-edge-client";
761
+ var useMessageQueue = (chat) => {
762
+ const edgeClient = useEdgeClient();
763
+ const space = getSpace2(chat);
764
+ const queueDxn = useMemo2(() => new DXN2(DXN2.kind.QUEUE, [
765
+ QueueSubspaceTags.DATA,
766
+ space.id,
767
+ chat.queue.dxn.parts.at(-1)
768
+ ]), [
769
+ chat.queue.dxn
770
+ ]);
771
+ return useQueue(edgeClient, queueDxn);
772
+ };
773
+
774
+ // packages/plugins/experimental/plugin-automation/src/hooks/useServices.ts
775
+ import { useEffect as useEffect3, useMemo as useMemo3, useState as useState3 } from "react";
776
+
777
+ // packages/plugins/experimental/plugin-automation/src/testing/test-functions.ts
778
+ import { createSystemPrompt as createSystemPrompt2 } from "@dxos/artifact";
779
+ import { AST, S as S2, toJsonSchema } from "@dxos/echo-schema";
780
+ var functions = [
781
+ {
782
+ name: "example.com/function/chess",
783
+ version: "0.1.0",
784
+ inputSchema: toJsonSchema(S2.Struct({
785
+ level: S2.Number.annotations({
786
+ [AST.TitleAnnotationId]: "Level"
787
+ })
788
+ }))
789
+ },
790
+ {
791
+ name: "example.com/function/forex",
792
+ version: "0.1.0",
793
+ binding: "FOREX",
794
+ inputSchema: toJsonSchema(S2.Struct({
795
+ from: S2.String.annotations({
796
+ [AST.TitleAnnotationId]: "Currency from"
797
+ }),
798
+ to: S2.String.annotations({
799
+ [AST.TitleAnnotationId]: "Currency to"
800
+ })
801
+ }))
802
+ }
803
+ ];
804
+
805
+ // packages/plugins/experimental/plugin-automation/src/testing/test-services.ts
806
+ import { createStatic as createStatic2 } from "@dxos/echo-schema";
807
+ var MockServiceRegistry = class {
808
+ async queryServices(query) {
809
+ return TEST_SERVICES;
810
+ }
811
+ };
812
+ var AMADEUS_AUTH = {
813
+ type: "oauth",
814
+ clientId: "BOEnpLd1sMyKjAPGKYeAPFFy60u53QEG",
815
+ clientSecret: "n4qldSN7usvD57gm",
816
+ tokenUrl: "https://test.api.amadeus.com/v1/security/oauth2/token",
817
+ grantType: "client_credentials"
818
+ };
819
+ var VISUAL_CROSSING_CREDENTIALS = {
820
+ type: "api-key",
821
+ key: "FDPRVS953KB4GQQLD25GRT975",
822
+ placement: {
823
+ type: "query",
824
+ name: "key"
825
+ }
826
+ };
827
+ var TEST_SERVICES = [
828
+ createStatic2(ServiceType, {
829
+ serviceId: "amadeus.com/service/FlightSearch",
830
+ name: "Amadeus Flight Search",
831
+ description: "Search for local and international flights.",
832
+ category: "travel",
833
+ interfaces: [
834
+ {
835
+ kind: "api",
836
+ schemaUrl: "https://api.apis.guru/v2/specs/amadeus.com/amadeus-flight-availabilities-search/1.0.2/swagger.json",
837
+ authorization: AMADEUS_AUTH
838
+ }
839
+ ]
840
+ }),
841
+ createStatic2(ServiceType, {
842
+ serviceId: "amadeus.com/service/HotelSearch",
843
+ name: "Amadeus Hotel Search",
844
+ description: "Search for local and international hotels.",
845
+ category: "travel",
846
+ interfaces: [
847
+ {
848
+ kind: "api",
849
+ schemaUrl: "https://api.apis.guru/v2/specs/amadeus.com/amadeus-hotel-search/3.0.8/swagger.json",
850
+ authorization: AMADEUS_AUTH
851
+ }
852
+ ]
853
+ }),
854
+ createStatic2(ServiceType, {
855
+ serviceId: "visualcrossing.com/service/Weather",
856
+ name: "Visual Crossing Weather",
857
+ description: "Search for global weather forecasts.",
858
+ category: "weather",
859
+ interfaces: [
860
+ {
861
+ kind: "api",
862
+ schemaUrl: "https://api.apis.guru/v2/specs/visualcrossing.com/weather/4.6/openapi.json",
863
+ authorization: VISUAL_CROSSING_CREDENTIALS
864
+ }
865
+ ]
866
+ }),
867
+ // TODO(burdon): Needs auth.
868
+ createStatic2(ServiceType, {
869
+ serviceId: "abstractapi.com/service/GeoLocation",
870
+ name: "Abstract GeoLocation",
871
+ description: "Get the location of any IP address.",
872
+ category: "geolocation",
873
+ interfaces: [
874
+ {
875
+ kind: "api",
876
+ schemaUrl: "https://api.apis.guru/v2/specs/abstractapi.com/geolocation/1.0.0/openapi.json"
877
+ }
878
+ ]
879
+ }),
880
+ //
881
+ // Testing
882
+ //
883
+ ...Array.from({
884
+ length: 20
885
+ }, (_, i) => createStatic2(ServiceType, {
886
+ serviceId: `example.com/service/test-${i}`,
887
+ name: `Test ${i}`,
888
+ description: `Test ${i}`,
889
+ category: Object.keys(categoryIcons)[Math.floor(Math.random() * Object.keys(categoryIcons).length)],
890
+ interfaces: [
891
+ {
892
+ kind: "api",
893
+ schemaUrl: "https://petstore.swagger.io/v2/swagger.json"
894
+ }
895
+ ]
896
+ }))
897
+ ];
898
+
899
+ // packages/plugins/experimental/plugin-automation/src/hooks/useServices.ts
900
+ var useServices = (space, query) => {
901
+ const registry = useMemo3(() => new MockServiceRegistry(), []);
902
+ const [services, setServices] = useState3([]);
903
+ useEffect3(() => {
904
+ const t = setTimeout(async () => {
905
+ const services2 = await registry.queryServices(query);
906
+ setServices(services2);
907
+ });
908
+ return () => clearTimeout(t);
909
+ }, [
910
+ query,
911
+ registry
912
+ ]);
913
+ return services;
914
+ };
915
+
916
+ // packages/plugins/experimental/plugin-automation/src/components/Thread/Thread.tsx
917
+ import React6, { useCallback, useMemo as useMemo4, useRef as useRef3, useState as useState7 } from "react";
918
+ import { IconButton, Input, useTranslation } from "@dxos/react-ui";
919
+ import { ScrollContainer } from "@dxos/react-ui-components";
920
+ import { Spinner } from "@dxos/react-ui-sfx";
921
+ import { mx as mx6 } from "@dxos/react-ui-theme";
922
+
923
+ // packages/plugins/experimental/plugin-automation/src/components/Thread/ThreadMessage.tsx
924
+ import React5, { useEffect as useEffect6, useRef as useRef2, useState as useState6 } from "react";
925
+ import { invariant as invariant5 } from "@dxos/invariant";
926
+ import { log as log6 } from "@dxos/log";
927
+ import { Button, ButtonGroup, Icon as Icon3 } from "@dxos/react-ui";
928
+ import { Json } from "@dxos/react-ui-syntax-highlighter";
929
+ import { mx as mx5 } from "@dxos/react-ui-theme";
930
+ import { safeParseJson } from "@dxos/util";
931
+
932
+ // packages/plugins/experimental/plugin-automation/src/components/Box/StatusLine.tsx
933
+ import React, { useEffect as useEffect4, useRef, useState as useState4 } from "react";
934
+ import { mx } from "@dxos/react-ui-theme";
935
+ var emptyLines = [];
936
+ var StatusLine = ({ classNames, line = -1, lines = emptyLines, transition = 300, advance = 1e3, autoAdvance }) => {
937
+ const containerRef = useRef(null);
938
+ const [currentLine, setCurrentLine] = useState4(line);
939
+ useEffect4(() => {
940
+ setCurrentLine(line);
941
+ }, [
942
+ line
943
+ ]);
944
+ useEffect4(() => {
945
+ if (!autoAdvance) {
946
+ return;
947
+ }
948
+ const next = () => {
949
+ setCurrentLine((prev) => {
950
+ if (prev >= lines.length - 1) {
951
+ clearInterval(interval);
952
+ return prev;
953
+ }
954
+ return prev + 1;
955
+ });
956
+ };
957
+ next();
958
+ const interval = setInterval(next, advance);
959
+ return () => clearInterval(interval);
960
+ }, [
961
+ lines.length,
962
+ autoAdvance,
963
+ advance
964
+ ]);
965
+ useEffect4(() => {
966
+ if (containerRef.current) {
967
+ containerRef.current.style.transition = `transform ${transition}ms ease-in-out`;
968
+ containerRef.current.style.transform = `translateY(-${currentLine * 24}px)`;
969
+ }
970
+ }, [
971
+ currentLine
972
+ ]);
973
+ return /* @__PURE__ */ React.createElement("div", {
974
+ className: mx("relative h-[24px] overflow-hidden", classNames)
975
+ }, /* @__PURE__ */ React.createElement("div", {
976
+ ref: containerRef,
977
+ className: "h-[24px]"
978
+ }, /* @__PURE__ */ React.createElement("div", {
979
+ className: "flex flex-col"
980
+ }, lines.map((line2, i) => /* @__PURE__ */ React.createElement("div", {
981
+ key: i,
982
+ className: mx("flex h-[24px] items-center")
983
+ }, /* @__PURE__ */ React.createElement("span", {
984
+ className: "truncate"
985
+ }, line2))))));
986
+ };
987
+
988
+ // packages/plugins/experimental/plugin-automation/src/components/Box/Tabbed.tsx
989
+ import React2, { forwardRef } from "react";
990
+ import { Icon } from "@dxos/react-ui";
991
+ import { mx as mx2 } from "@dxos/react-ui-theme";
992
+ var numbers = [
993
+ {
994
+ regular: "ph--number-circle-zero--thin",
995
+ active: "ph--number-circle-zero--duotone"
996
+ },
997
+ {
998
+ regular: "ph--number-circle-one--thin",
999
+ active: "ph--number-circle-one--duotone"
1000
+ },
1001
+ {
1002
+ regular: "ph--number-circle-two--thin",
1003
+ active: "ph--number-circle-two--duotone"
1004
+ },
1005
+ {
1006
+ regular: "ph--number-circle-three--thin",
1007
+ active: "ph--number-circle-three--duotone"
1008
+ },
1009
+ {
1010
+ regular: "ph--number-circle-four--thin",
1011
+ active: "ph--number-circle-four--duotone"
1012
+ },
1013
+ {
1014
+ regular: "ph--number-circle-five--thin",
1015
+ active: "ph--number-circle-five--duotone"
1016
+ },
1017
+ {
1018
+ regular: "ph--number-circle-six--thin",
1019
+ active: "ph--number-circle-six--duotone"
1020
+ },
1021
+ {
1022
+ regular: "ph--number-circle-seven--thin",
1023
+ active: "ph--number-circle-seven--duotone"
1024
+ },
1025
+ {
1026
+ regular: "ph--number-circle-eight--thin",
1027
+ active: "ph--number-circle-eight--duotone"
1028
+ },
1029
+ {
1030
+ regular: "ph--number-circle-nine--thin",
1031
+ active: "ph--number-circle-nine--duotone"
1032
+ }
1033
+ ];
1034
+ var Tabs = /* @__PURE__ */ forwardRef(({ classNames, length, selected = 0, onSelect }, forwardedRef) => {
1035
+ return /* @__PURE__ */ React2.createElement("div", {
1036
+ ref: forwardedRef,
1037
+ className: mx2("flex flex-col overflow-hidden outline-none", classNames),
1038
+ tabIndex: -1,
1039
+ onKeyDown: (ev) => {
1040
+ switch (ev.key) {
1041
+ case "ArrowDown":
1042
+ case "ArrowRight": {
1043
+ ev.preventDefault();
1044
+ ev.stopPropagation();
1045
+ if (selected < length - 1) {
1046
+ onSelect?.(selected + 1);
1047
+ }
1048
+ break;
1049
+ }
1050
+ case "ArrowUp":
1051
+ case "ArrowLeft": {
1052
+ ev.preventDefault();
1053
+ ev.stopPropagation();
1054
+ if (selected > 0) {
1055
+ onSelect?.(selected - 1);
1056
+ }
1057
+ break;
1058
+ }
1059
+ case "Enter": {
1060
+ ev.preventDefault();
1061
+ ev.stopPropagation();
1062
+ onSelect?.(selected);
1063
+ break;
1064
+ }
1065
+ }
1066
+ }
1067
+ }, Array.from({
1068
+ length
1069
+ }).map((_, i) => {
1070
+ const icon = numbers[i + 1];
1071
+ return /* @__PURE__ */ React2.createElement("div", {
1072
+ key: i,
1073
+ className: mx2("relative flex w-[24px] h-[28px] justify-center cursor-pointer text-subdued", selected === i && "!text-cyan-550 !dark:text-cyan-300")
1074
+ }, i < length - 1 && /* @__PURE__ */ React2.createElement("div", {
1075
+ className: "absolute left-[11.5px] top-[21px] w-[1px] h-[10px] bg-neutral-400"
1076
+ }), /* @__PURE__ */ React2.createElement(Icon, {
1077
+ icon: selected === i ? icon.regular : icon.regular,
1078
+ classNames: "z-10 !p-0 !w-[24px] !h-[24px] outline-none",
1079
+ onClick: () => onSelect?.(i)
1080
+ }));
1081
+ }));
1082
+ });
1083
+
1084
+ // packages/plugins/experimental/plugin-automation/src/components/Box/ToggleContainer.tsx
1085
+ import React3, { useEffect as useEffect5, useState as useState5 } from "react";
1086
+ import { Icon as Icon2, useControlledState } from "@dxos/react-ui";
1087
+ import { mx as mx3 } from "@dxos/react-ui-theme";
1088
+ var ToggleContainer = ({ classNames, title, icon, open: _open, duration = 400, shrinkX = false, children, onChangeOpen }) => {
1089
+ const [open, setOpen] = useControlledState(_open);
1090
+ const [expandX, setExpandX] = useState5(shrinkX ? open : true);
1091
+ const [expandY, setExpandY] = useState5(open);
1092
+ useEffect5(() => {
1093
+ let t;
1094
+ if (open) {
1095
+ if (shrinkX) {
1096
+ setExpandX(true);
1097
+ }
1098
+ t = setTimeout(() => {
1099
+ setExpandY(true);
1100
+ }, shrinkX ? duration : 0);
1101
+ } else {
1102
+ setExpandY(false);
1103
+ if (shrinkX) {
1104
+ t = setTimeout(() => {
1105
+ setExpandX(false);
1106
+ }, duration);
1107
+ }
1108
+ }
1109
+ return () => clearTimeout(t);
1110
+ }, [
1111
+ open
1112
+ ]);
1113
+ const handleToggle = () => {
1114
+ if (onChangeOpen) {
1115
+ onChangeOpen(!open);
1116
+ } else {
1117
+ setOpen((open2) => !open2);
1118
+ }
1119
+ };
1120
+ return /* @__PURE__ */ React3.createElement("div", {
1121
+ className: mx3("overflow-hidden", classNames)
1122
+ }, title && /* @__PURE__ */ React3.createElement("div", {
1123
+ className: "flex gap-1 py-1 items-center text-sm text-subdued cursor-pointer select-none",
1124
+ onClick: handleToggle
1125
+ }, /* @__PURE__ */ React3.createElement("div", {
1126
+ className: "flex w-[24px] h-[24px] items-center justify-center"
1127
+ }, /* @__PURE__ */ React3.createElement(Icon2, {
1128
+ size: 4,
1129
+ icon: "ph--caret-right--regular",
1130
+ style: {
1131
+ transitionDuration: `${shrinkX ? duration * 2 : duration}ms`
1132
+ },
1133
+ classNames: [
1134
+ "transition transition-transform ease-in-out",
1135
+ open ? "rotate-90" : "transform-none"
1136
+ ]
1137
+ })), /* @__PURE__ */ React3.createElement("div", {
1138
+ className: "flex-1 pis-1 pie-1 truncate"
1139
+ }, title), icon), /* @__PURE__ */ React3.createElement("div", {
1140
+ style: {
1141
+ transitionDuration: `${duration}ms`
1142
+ },
1143
+ className: mx3("grid transition-[grid-template-columns] ease-in-out", expandX ? "grid-cols-[1fr]" : "grid-cols-[0fr]")
1144
+ }, /* @__PURE__ */ React3.createElement("div", {
1145
+ className: "overflow-hidden"
1146
+ }, /* @__PURE__ */ React3.createElement("div", {
1147
+ style: {
1148
+ transitionDuration: `${duration}ms`
1149
+ },
1150
+ className: mx3("grid transition-[grid-template-rows] ease-in-out", expandY ? "grid-rows-[1fr]" : "grid-rows-[0fr]")
1151
+ }, /* @__PURE__ */ React3.createElement("div", {
1152
+ className: mx3("flex overflow-hidden transition-opacity")
1153
+ }, children)))));
1154
+ };
1155
+
1156
+ // packages/plugins/experimental/plugin-automation/src/components/MarkdownViewer/MarkdownViewer.tsx
1157
+ import React4 from "react";
1158
+ import ReactMarkdown from "react-markdown";
1159
+ import { SyntaxHighlighter } from "@dxos/react-ui-syntax-highlighter";
1160
+ import { mx as mx4 } from "@dxos/react-ui-theme";
1161
+ import { omit } from "@dxos/util";
1162
+ var MarkdownViewer = ({ classNames, content = "" }) => {
1163
+ return /* @__PURE__ */ React4.createElement("div", {
1164
+ className: mx4("space-y-2", classNames)
1165
+ }, /* @__PURE__ */ React4.createElement(ReactMarkdown, {
1166
+ components: {
1167
+ a: ({ node, children, href, ...props }) => /* @__PURE__ */ React4.createElement("a", {
1168
+ href,
1169
+ className: "text-primary-500 hover:text-primary-500",
1170
+ target: "_blank",
1171
+ rel: "noopener noreferrer",
1172
+ ...props
1173
+ }, children),
1174
+ ol: ({ node, children, ...props }) => /* @__PURE__ */ React4.createElement("ol", {
1175
+ className: "leading-tight list-decimal pl-6",
1176
+ ...omit(props, [
1177
+ "ordered"
1178
+ ])
1179
+ }, children),
1180
+ ul: ({ node, children, ...props }) => /* @__PURE__ */ React4.createElement("ul", {
1181
+ className: "leading-tight list-disc pl-6",
1182
+ ...omit(props, [
1183
+ "ordered"
1184
+ ])
1185
+ }, children),
1186
+ li: ({ node, children, ...props }) => /* @__PURE__ */ React4.createElement("li", {
1187
+ className: "",
1188
+ ...omit(props, [
1189
+ "ordered"
1190
+ ])
1191
+ }, children),
1192
+ blockquote: ({ node, children, ...props }) => /* @__PURE__ */ React4.createElement("blockquote", {
1193
+ className: "border-l-4 border-primary-500 pl-4 my-4 text-primary-500",
1194
+ ...props
1195
+ }, children),
1196
+ code: ({ children, className }) => {
1197
+ const [_, language] = /language-(\w+)/.exec(className || "") || [];
1198
+ return /* @__PURE__ */ React4.createElement(SyntaxHighlighter, {
1199
+ PreTag: "div",
1200
+ language,
1201
+ className: "p-0"
1202
+ }, children);
1203
+ }
1204
+ }
1205
+ }, content));
1206
+ };
1207
+
1208
+ // packages/plugins/experimental/plugin-automation/src/components/Thread/ThreadMessage.tsx
1209
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-automation/src/components/Thread/ThreadMessage.tsx";
1210
+ var ThreadMessage = ({ classNames, message, collapse, debug, onSuggest, onDelete }) => {
1211
+ if (typeof message !== "object") {
1212
+ return /* @__PURE__ */ React5.createElement("div", {
1213
+ className: mx5(classNames)
1214
+ }, message);
1215
+ }
1216
+ const { role, content = [] } = message;
1217
+ const toolBlocks = content.filter((block) => block.type === "tool_use" || block.type === "tool_result");
1218
+ if (collapse && toolBlocks.length > 0) {
1219
+ let request;
1220
+ const items = toolBlocks.map((block) => {
1221
+ switch (block.type) {
1222
+ case "tool_use": {
1223
+ request = block;
1224
+ return {
1225
+ title: `Calling ${block.name}...`,
1226
+ block
1227
+ };
1228
+ }
1229
+ case "tool_result": {
1230
+ if (!request) {
1231
+ log6.warn("unexpected message", {
1232
+ block
1233
+ }, {
1234
+ F: __dxlog_file4,
1235
+ L: 54,
1236
+ S: void 0,
1237
+ C: (f, a) => f(...a)
1238
+ });
1239
+ return {
1240
+ title: "Error",
1241
+ block
1242
+ };
1243
+ }
1244
+ return {
1245
+ title: `Processed ${request.name}`,
1246
+ block
1247
+ };
1248
+ }
1249
+ default: {
1250
+ request = void 0;
1251
+ return {
1252
+ title: "Error",
1253
+ block
1254
+ };
1255
+ }
1256
+ }
1257
+ });
1258
+ return /* @__PURE__ */ React5.createElement("div", {
1259
+ className: mx5("flex", classNames)
1260
+ }, /* @__PURE__ */ React5.createElement("div", {
1261
+ className: "w-full p-1 px-2 overflow-hidden rounded-md bg-baseSurface"
1262
+ }, /* @__PURE__ */ React5.createElement(TabbedContainer, {
1263
+ items
1264
+ })));
1265
+ }
1266
+ return /* @__PURE__ */ React5.createElement("div", {
1267
+ className: mx5("flex flex-col shrink-0 gap-2")
1268
+ }, debug && /* @__PURE__ */ React5.createElement("div", {
1269
+ className: "text-xs text-subdued"
1270
+ }, message.id, " ", onDelete && /* @__PURE__ */ React5.createElement("span", {
1271
+ className: "cursor-pointer underline",
1272
+ onClick: () => onDelete(message.id)
1273
+ }, "delete")), content.map((block, idx) => /* @__PURE__ */ React5.createElement("div", {
1274
+ key: idx,
1275
+ className: mx5("flex", classNames, block.type === "text" && role === "user" && "justify-end")
1276
+ }, /* @__PURE__ */ React5.createElement(Block, {
1277
+ role,
1278
+ block,
1279
+ onSuggest: onSuggest ?? (() => {
1280
+ })
1281
+ }))));
1282
+ };
1283
+ var Block = ({ block, role, onSuggest }) => {
1284
+ const Component = componentMap[block.type] ?? componentMap.default;
1285
+ return /* @__PURE__ */ React5.createElement("div", {
1286
+ className: mx5("p-1 px-2 overflow-hidden rounded-md", (block.type !== "text" || block.disposition) && "w-full bg-baseSurface", block.type === "text" && role === "user" && "bg-primary-200 dark:bg-primary-500")
1287
+ }, /* @__PURE__ */ React5.createElement(Component, {
1288
+ block,
1289
+ onSuggest
1290
+ }));
1291
+ };
1292
+ var titles = {
1293
+ ["cot"]: "Chain of thought",
1294
+ ["artifact"]: "Artifact",
1295
+ ["tool_use"]: "Tool request",
1296
+ ["tool_result"]: "Tool result"
1297
+ };
1298
+ var componentMap = {
1299
+ text: ({ block }) => {
1300
+ invariant5(block.type === "text", void 0, {
1301
+ F: __dxlog_file4,
1302
+ L: 128,
1303
+ S: void 0,
1304
+ A: [
1305
+ "block.type === 'text'",
1306
+ ""
1307
+ ]
1308
+ });
1309
+ const title = block.disposition ? titles[block.disposition] : void 0;
1310
+ if (!title) {
1311
+ return /* @__PURE__ */ React5.createElement(MarkdownViewer, {
1312
+ content: block.text,
1313
+ classNames: [
1314
+ block.disposition === "cot" && "text-sm text-subdued"
1315
+ ]
1316
+ });
1317
+ }
1318
+ return /* @__PURE__ */ React5.createElement(ToggleContainer, {
1319
+ title,
1320
+ icon: block.pending ? /* @__PURE__ */ React5.createElement(Icon3, {
1321
+ icon: "ph--circle-notch--regular",
1322
+ classNames: "text-subdued ml-2 animate-spin",
1323
+ size: 4
1324
+ }) : void 0,
1325
+ open: block.disposition === "cot"
1326
+ }, /* @__PURE__ */ React5.createElement(MarkdownViewer, {
1327
+ content: block.text,
1328
+ classNames: [
1329
+ block.disposition === "cot" && "text-sm text-subdued"
1330
+ ]
1331
+ }));
1332
+ },
1333
+ json: ({ block, onSuggest }) => {
1334
+ invariant5(block.type === "json", void 0, {
1335
+ F: __dxlog_file4,
1336
+ L: 152,
1337
+ S: void 0,
1338
+ A: [
1339
+ "block.type === 'json'",
1340
+ ""
1341
+ ]
1342
+ });
1343
+ switch (block.disposition) {
1344
+ case "suggest": {
1345
+ const { text = "" } = safeParseJson(block.json ?? "{}") ?? {};
1346
+ return /* @__PURE__ */ React5.createElement(Button, {
1347
+ onClick: () => onSuggest(text)
1348
+ }, text);
1349
+ }
1350
+ case "select": {
1351
+ const { options = [] } = safeParseJson(block.json ?? "{}") ?? {};
1352
+ return /* @__PURE__ */ React5.createElement(ButtonGroup, null, options.map((option) => /* @__PURE__ */ React5.createElement(Button, {
1353
+ key: option,
1354
+ onClick: () => onSuggest(option)
1355
+ }, option)));
1356
+ }
1357
+ default: {
1358
+ const title = block.disposition ? titles[block.disposition] : void 0;
1359
+ return /* @__PURE__ */ React5.createElement(ToggleContainer, {
1360
+ title: title ?? "JSON"
1361
+ }, /* @__PURE__ */ React5.createElement(Json, {
1362
+ data: safeParseJson(block.json ?? block),
1363
+ classNames: "!p-1 text-xs"
1364
+ }));
1365
+ }
1366
+ }
1367
+ },
1368
+ default: ({ block }) => {
1369
+ let title = titles[block.type];
1370
+ if (block.type === "tool_use") {
1371
+ title = `Tool [${block.name}]`;
1372
+ }
1373
+ return /* @__PURE__ */ React5.createElement(ToggleContainer, {
1374
+ title: title ?? "JSON"
1375
+ }, /* @__PURE__ */ React5.createElement(Json, {
1376
+ data: block,
1377
+ classNames: "!p-1 text-xs"
1378
+ }));
1379
+ }
1380
+ };
1381
+ var TabbedContainer = ({ items }) => {
1382
+ const lines = items.map((item) => item.title);
1383
+ const tabsRef = useRef2(null);
1384
+ const [selected, setSelected] = useState6(0);
1385
+ const [open, setOpen] = useState6(false);
1386
+ useEffect6(() => {
1387
+ if (open) {
1388
+ tabsRef.current?.focus();
1389
+ }
1390
+ }, [
1391
+ open
1392
+ ]);
1393
+ const handleSelect = (index) => {
1394
+ if (index === selected) {
1395
+ setOpen(false);
1396
+ } else {
1397
+ setSelected(index);
1398
+ }
1399
+ };
1400
+ return /* @__PURE__ */ React5.createElement(ToggleContainer, {
1401
+ title: /* @__PURE__ */ React5.createElement(StatusLine, {
1402
+ lines,
1403
+ autoAdvance: true
1404
+ }),
1405
+ open,
1406
+ onChangeOpen: setOpen
1407
+ }, /* @__PURE__ */ React5.createElement("div", {
1408
+ className: "flex gap-2 w-full"
1409
+ }, /* @__PURE__ */ React5.createElement(Tabs, {
1410
+ ref: tabsRef,
1411
+ length: items.length,
1412
+ selected,
1413
+ onSelect: handleSelect
1414
+ }), /* @__PURE__ */ React5.createElement(Json, {
1415
+ data: items[selected].block,
1416
+ classNames: "!p-1 text-xs"
1417
+ })));
1418
+ };
1419
+
1420
+ // packages/plugins/experimental/plugin-automation/src/components/Thread/Thread.tsx
1421
+ var Thread = ({ messages, streaming, collapse, debug, onSubmit, onStop, onSuggest, onDelete }) => {
1422
+ const { t } = useTranslation(AUTOMATION_PLUGIN);
1423
+ const scroller = useRef3(null);
1424
+ const [text, setText] = useState7("");
1425
+ const handleKeyDown = useCallback((ev) => {
1426
+ switch (ev.key) {
1427
+ case "Escape": {
1428
+ setText("");
1429
+ break;
1430
+ }
1431
+ case "Enter": {
1432
+ const value = text.trim();
1433
+ if (value.length > 0) {
1434
+ scroller.current?.scrollToBottom();
1435
+ onSubmit?.(value);
1436
+ setText("");
1437
+ }
1438
+ break;
1439
+ }
1440
+ }
1441
+ }, [
1442
+ text
1443
+ ]);
1444
+ const { messages: lines = [] } = useMemo4(() => {
1445
+ if (!collapse) {
1446
+ return {
1447
+ messages: messages ?? []
1448
+ };
1449
+ }
1450
+ return (messages ?? []).reduce(({ current, messages: messages2 }, message) => {
1451
+ let i = 0;
1452
+ for (const block of message.content) {
1453
+ switch (block.type) {
1454
+ case "tool_use":
1455
+ case "tool_result": {
1456
+ if (current) {
1457
+ current.content.push(block);
1458
+ } else {
1459
+ current = {
1460
+ id: [
1461
+ message.id,
1462
+ i
1463
+ ].join("_"),
1464
+ role: message.role,
1465
+ content: [
1466
+ block
1467
+ ]
1468
+ };
1469
+ messages2.push(current);
1470
+ }
1471
+ break;
1472
+ }
1473
+ case "text":
1474
+ default: {
1475
+ current = void 0;
1476
+ messages2.push({
1477
+ id: [
1478
+ message.id,
1479
+ i
1480
+ ].join("_"),
1481
+ role: message.role,
1482
+ content: [
1483
+ block
1484
+ ]
1485
+ });
1486
+ break;
1487
+ }
1488
+ }
1489
+ i++;
1490
+ }
1491
+ return {
1492
+ current,
1493
+ messages: messages2
1494
+ };
1495
+ }, {
1496
+ messages: []
1497
+ });
1498
+ }, [
1499
+ messages,
1500
+ collapse
1501
+ ]);
1502
+ return /* @__PURE__ */ React6.createElement("div", {
1503
+ className: "flex flex-col grow overflow-hidden"
1504
+ }, /* @__PURE__ */ React6.createElement(ScrollContainer, {
1505
+ ref: scroller,
1506
+ classNames: "py-2 gap-2 overflow-x-hidden"
1507
+ }, lines.map((message) => /* @__PURE__ */ React6.createElement(ThreadMessage, {
1508
+ key: message.id,
1509
+ classNames: "px-4",
1510
+ message,
1511
+ collapse,
1512
+ debug,
1513
+ onSuggest,
1514
+ onDelete
1515
+ }))), onSubmit && /* @__PURE__ */ React6.createElement("div", {
1516
+ className: "flex p-4 gap-3 items-center"
1517
+ }, /* @__PURE__ */ React6.createElement(Spinner, {
1518
+ active: streaming
1519
+ }), /* @__PURE__ */ React6.createElement(Input.Root, null, /* @__PURE__ */ React6.createElement(Input.TextInput, {
1520
+ autoFocus: true,
1521
+ classNames: "px-2 baseSurface rounded",
1522
+ placeholder: t("chat input placeholder"),
1523
+ value: text,
1524
+ onChange: (ev) => setText(ev.target.value),
1525
+ onKeyDown: handleKeyDown
1526
+ })), onStop && /* @__PURE__ */ React6.createElement(IconButton, {
1527
+ disabled: !streaming,
1528
+ classNames: mx6("!p-1 !opacity-20 transition", streaming && "!opacity-80"),
1529
+ variant: "ghost",
1530
+ size: 5,
1531
+ onClick: onStop,
1532
+ icon: "ph--x--regular",
1533
+ label: t("chat stop"),
1534
+ iconOnly: true
1535
+ })));
1536
+ };
1537
+
1538
+ // packages/plugins/experimental/plugin-automation/src/components/ChatContainer/ChatContainer.tsx
1539
+ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-automation/src/components/ChatContainer/ChatContainer.tsx";
1540
+ var ChatContainer = ({ chat, role }) => {
1541
+ const processor = useChatProcessor(chat);
1542
+ const messageQueue = useMessageQueue(chat);
1543
+ const messages = [
1544
+ ...messageQueue?.items ?? [],
1545
+ ...processor.messages.value
1546
+ ];
1547
+ const handleSubmit = useCallback2(async (text) => {
1548
+ if (processor.streaming.value) {
1549
+ await processor.cancel();
1550
+ }
1551
+ invariant6(messageQueue, void 0, {
1552
+ F: __dxlog_file5,
1553
+ L: 25,
1554
+ S: void 0,
1555
+ A: [
1556
+ "messageQueue",
1557
+ ""
1558
+ ]
1559
+ });
1560
+ await processor.request(text, {
1561
+ history: messageQueue.items,
1562
+ onComplete: (messages2) => messageQueue.append(messages2)
1563
+ });
1564
+ }, [
1565
+ processor,
1566
+ messageQueue
1567
+ ]);
1568
+ const handleStop = useCallback2(() => {
1569
+ if (processor.streaming.value) {
1570
+ void processor.cancel();
1571
+ }
1572
+ }, [
1573
+ processor
1574
+ ]);
1575
+ return /* @__PURE__ */ React7.createElement(StackItem.Content, {
1576
+ toolbar: false,
1577
+ role
1578
+ }, /* @__PURE__ */ React7.createElement(Thread, {
1579
+ messages,
1580
+ streaming: processor.streaming.value,
1581
+ collapse: true,
1582
+ onSubmit: handleSubmit,
1583
+ onSuggest: handleSubmit,
1584
+ onStop: handleStop
1585
+ }));
1586
+ };
1587
+
1588
+ // packages/plugins/experimental/plugin-automation/src/components/ChatContainer/index.ts
1589
+ var ChatContainer_default = ChatContainer;
1590
+
1591
+ export {
1592
+ useServices,
1593
+ MarkdownViewer,
1594
+ Thread,
1595
+ ChatContainer,
1596
+ ChatContainer_default,
1597
+ AiClient,
1598
+ AppGraphBuilder,
1599
+ IntentResolver,
1600
+ ReactSurface
1601
+ };
1602
+ //# sourceMappingURL=chunk-DVE33EZL.mjs.map