@dxos/plugin-automation 0.7.5-labs.5f04cf6 → 0.7.5-labs.e27f9b9

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