@dxos/plugin-automation 0.7.4 → 0.7.5-labs.071a3e2

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