@dxos/plugin-assistant 0.7.5-labs.a8b535d

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