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