@dxos/plugin-assistant 0.7.5-main.5ae2ba8

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