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