@dxos/plugin-assistant 0.8.2-main.fbd8ed0 → 0.8.2-staging.4d6ad0f

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 (295) hide show
  1. package/dist/lib/browser/AssistantDialog-K6POM23O.mjs +46 -0
  2. package/dist/lib/browser/AssistantDialog-K6POM23O.mjs.map +7 -0
  3. package/dist/lib/browser/ChatContainer-QTO4LE2C.mjs +39 -0
  4. package/dist/lib/{node-esm/ChatContainer-FAYGNMQW.mjs.map → browser/ChatContainer-QTO4LE2C.mjs.map} +1 -1
  5. package/dist/lib/browser/TemplateContainer-AKUYL4AV.mjs +28 -0
  6. package/dist/lib/{node-esm/TemplateContainer-3LEBT5ZC.mjs.map → browser/TemplateContainer-AKUYL4AV.mjs.map} +1 -1
  7. package/dist/lib/browser/{ai-client-5PRCXI7N.mjs → ai-client-COXVUC6V.mjs} +4 -4
  8. package/dist/lib/browser/ai-client-COXVUC6V.mjs.map +7 -0
  9. package/dist/lib/browser/{app-graph-builder-HTK3HFGM.mjs → app-graph-builder-YH4EGNBC.mjs} +45 -28
  10. package/dist/lib/browser/app-graph-builder-YH4EGNBC.mjs.map +7 -0
  11. package/dist/lib/browser/{chunk-TXJWGWJ7.mjs → chunk-3F44MBHU.mjs} +3 -3
  12. package/dist/lib/browser/chunk-3F44MBHU.mjs.map +7 -0
  13. package/dist/lib/browser/chunk-IHEBFO5O.mjs +205 -0
  14. package/dist/lib/browser/chunk-IHEBFO5O.mjs.map +7 -0
  15. package/dist/lib/browser/chunk-JQFUME3B.mjs +87 -0
  16. package/dist/lib/{node-esm/chunk-PBZA7XJR.mjs.map → browser/chunk-JQFUME3B.mjs.map} +1 -1
  17. package/dist/lib/browser/chunk-Q6UZ4F3H.mjs +96 -0
  18. package/dist/lib/browser/chunk-Q6UZ4F3H.mjs.map +7 -0
  19. package/dist/lib/browser/{chunk-OWZHLWW5.mjs → chunk-QTW7KVDO.mjs} +1595 -1452
  20. package/dist/lib/browser/chunk-QTW7KVDO.mjs.map +7 -0
  21. package/dist/lib/browser/chunk-USJBRB3H.mjs +155 -0
  22. package/dist/lib/browser/chunk-USJBRB3H.mjs.map +7 -0
  23. package/dist/lib/browser/{chunk-3HCI5FIL.mjs → chunk-XOZ7YMO3.mjs} +3 -3
  24. package/dist/lib/browser/{chunk-3HCI5FIL.mjs.map → chunk-XOZ7YMO3.mjs.map} +1 -1
  25. package/dist/lib/browser/index.mjs +24 -10
  26. package/dist/lib/browser/index.mjs.map +3 -3
  27. package/dist/lib/browser/{intent-resolver-QV5AAVJZ.mjs → intent-resolver-63EAHENI.mjs} +6 -5
  28. package/dist/lib/browser/intent-resolver-63EAHENI.mjs.map +7 -0
  29. package/dist/lib/browser/meta.json +1 -1
  30. package/dist/lib/browser/react-surface-XCV6NR75.mjs +131 -0
  31. package/dist/lib/browser/react-surface-XCV6NR75.mjs.map +7 -0
  32. package/dist/lib/browser/{settings-OZX7J65A.mjs → settings-SHNQ4XXP.mjs} +3 -3
  33. package/dist/lib/browser/types/index.mjs +4 -2
  34. package/dist/lib/node/AssistantDialog-FDATKYE5.cjs +72 -0
  35. package/dist/lib/node/AssistantDialog-FDATKYE5.cjs.map +7 -0
  36. package/dist/lib/node/{ChatContainer-WVAAOEOH.cjs → ChatContainer-5CLHJOIQ.cjs} +25 -19
  37. package/dist/lib/node/{ChatContainer-WVAAOEOH.cjs.map → ChatContainer-5CLHJOIQ.cjs.map} +1 -1
  38. package/dist/lib/node/{TemplateContainer-EQXKHWTF.cjs → TemplateContainer-CTG2MB4W.cjs} +18 -12
  39. package/dist/lib/node/{TemplateContainer-EQXKHWTF.cjs.map → TemplateContainer-CTG2MB4W.cjs.map} +1 -1
  40. package/dist/lib/node/{ai-client-OUPSRQT7.cjs → ai-client-R2CGEYZW.cjs} +12 -12
  41. package/dist/lib/node/ai-client-R2CGEYZW.cjs.map +7 -0
  42. package/dist/lib/node/{app-graph-builder-LEO63CZZ.cjs → app-graph-builder-PSHIOW3Q.cjs} +62 -46
  43. package/dist/lib/node/app-graph-builder-PSHIOW3Q.cjs.map +7 -0
  44. package/dist/lib/node/{chunk-XI2ARIEO.cjs → chunk-4EEWTDQK.cjs} +45 -39
  45. package/dist/lib/node/{chunk-XI2ARIEO.cjs.map → chunk-4EEWTDQK.cjs.map} +1 -1
  46. package/dist/lib/node/chunk-FLJWJ35M.cjs +181 -0
  47. package/dist/lib/node/chunk-FLJWJ35M.cjs.map +7 -0
  48. package/dist/lib/node/{chunk-OOHFSPWR.cjs → chunk-H4A42LNR.cjs} +1126 -983
  49. package/dist/lib/node/chunk-H4A42LNR.cjs.map +7 -0
  50. package/dist/lib/node/chunk-HRNIUYVQ.cjs +128 -0
  51. package/dist/lib/node/chunk-HRNIUYVQ.cjs.map +7 -0
  52. package/dist/lib/node/{chunk-Q5XWEMHB.cjs → chunk-P74TWGMG.cjs} +6 -6
  53. package/dist/lib/node/{chunk-Q5XWEMHB.cjs.map → chunk-P74TWGMG.cjs.map} +1 -1
  54. package/dist/lib/node/chunk-RXPA2C2A.cjs +230 -0
  55. package/dist/lib/node/chunk-RXPA2C2A.cjs.map +7 -0
  56. package/dist/lib/node/{chunk-GBUNQ257.cjs → chunk-TS3H5OSX.cjs} +7 -7
  57. package/dist/lib/node/chunk-TS3H5OSX.cjs.map +7 -0
  58. package/dist/lib/node/index.cjs +72 -59
  59. package/dist/lib/node/index.cjs.map +3 -3
  60. package/dist/lib/node/{intent-resolver-QDGZMWLY.cjs → intent-resolver-66F7WLW6.cjs} +13 -12
  61. package/dist/lib/node/intent-resolver-66F7WLW6.cjs.map +7 -0
  62. package/dist/lib/node/meta.json +1 -1
  63. package/dist/lib/node/react-surface-TASAPRPQ.cjs +145 -0
  64. package/dist/lib/node/react-surface-TASAPRPQ.cjs.map +7 -0
  65. package/dist/lib/node/{settings-WLTC7XO5.cjs → settings-ERKLO6IO.cjs} +8 -8
  66. package/dist/lib/node/types/index.cjs +16 -14
  67. package/dist/lib/node/types/index.cjs.map +2 -2
  68. package/dist/lib/node-esm/AssistantDialog-PIMYK774.mjs +47 -0
  69. package/dist/lib/node-esm/AssistantDialog-PIMYK774.mjs.map +7 -0
  70. package/dist/lib/node-esm/ChatContainer-QTC5NYE2.mjs +40 -0
  71. package/dist/lib/{browser/ChatContainer-ZNKENYKZ.mjs.map → node-esm/ChatContainer-QTC5NYE2.mjs.map} +1 -1
  72. package/dist/lib/node-esm/TemplateContainer-IVDQ4XQG.mjs +29 -0
  73. package/dist/lib/{browser/TemplateContainer-WKU5XFSO.mjs.map → node-esm/TemplateContainer-IVDQ4XQG.mjs.map} +1 -1
  74. package/dist/lib/node-esm/{ai-client-RZQWEDUX.mjs → ai-client-I5LXHMOZ.mjs} +4 -4
  75. package/dist/lib/node-esm/ai-client-I5LXHMOZ.mjs.map +7 -0
  76. package/dist/lib/node-esm/{app-graph-builder-WXJNZDYB.mjs → app-graph-builder-Z3GMMJMD.mjs} +45 -28
  77. package/dist/lib/node-esm/app-graph-builder-Z3GMMJMD.mjs.map +7 -0
  78. package/dist/lib/node-esm/{chunk-ECRK6TUQ.mjs → chunk-BB2TAT4P.mjs} +3 -3
  79. package/dist/lib/node-esm/{chunk-ECRK6TUQ.mjs.map → chunk-BB2TAT4P.mjs.map} +1 -1
  80. package/dist/lib/node-esm/chunk-CDAILLCU.mjs +98 -0
  81. package/dist/lib/node-esm/chunk-CDAILLCU.mjs.map +7 -0
  82. package/dist/lib/node-esm/{chunk-6JK5HEUQ.mjs → chunk-HLPGKJ7N.mjs} +3 -3
  83. package/dist/lib/node-esm/chunk-HLPGKJ7N.mjs.map +7 -0
  84. package/dist/lib/node-esm/{chunk-PBZA7XJR.mjs → chunk-OYN6HLXZ.mjs} +42 -36
  85. package/dist/lib/{browser/chunk-NFUHCW2J.mjs.map → node-esm/chunk-OYN6HLXZ.mjs.map} +1 -1
  86. package/dist/lib/node-esm/chunk-QU626JMR.mjs +156 -0
  87. package/dist/lib/node-esm/chunk-QU626JMR.mjs.map +7 -0
  88. package/dist/lib/node-esm/{chunk-ED55ZE4G.mjs → chunk-SI5LOQEO.mjs} +1595 -1452
  89. package/dist/lib/node-esm/chunk-SI5LOQEO.mjs.map +7 -0
  90. package/dist/lib/node-esm/chunk-ZKBACPIW.mjs +206 -0
  91. package/dist/lib/node-esm/chunk-ZKBACPIW.mjs.map +7 -0
  92. package/dist/lib/node-esm/index.mjs +24 -10
  93. package/dist/lib/node-esm/index.mjs.map +3 -3
  94. package/dist/lib/node-esm/{intent-resolver-Q3I6S6HN.mjs → intent-resolver-X3PWH7KM.mjs} +6 -5
  95. package/dist/lib/node-esm/intent-resolver-X3PWH7KM.mjs.map +7 -0
  96. package/dist/lib/node-esm/meta.json +1 -1
  97. package/dist/lib/node-esm/react-surface-QMIQCXUM.mjs +132 -0
  98. package/dist/lib/node-esm/react-surface-QMIQCXUM.mjs.map +7 -0
  99. package/dist/lib/node-esm/{settings-CLE57WEP.mjs → settings-IVQRZUCU.mjs} +3 -3
  100. package/dist/lib/node-esm/types/index.mjs +4 -2
  101. package/dist/types/src/AssistantPlugin.d.ts.map +1 -1
  102. package/dist/types/src/capabilities/ai-client.d.ts +1 -1
  103. package/dist/types/src/capabilities/ai-client.d.ts.map +1 -1
  104. package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -1
  105. package/dist/types/src/capabilities/capabilities.d.ts +1 -1
  106. package/dist/types/src/capabilities/capabilities.d.ts.map +1 -1
  107. package/dist/types/src/capabilities/index.d.ts +1 -1
  108. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  109. package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -1
  110. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
  111. package/dist/types/src/components/AmbientDialog/AmbientDialog.d.ts +3 -1
  112. package/dist/types/src/components/AmbientDialog/AmbientDialog.d.ts.map +1 -1
  113. package/dist/types/src/components/BlueprintEditor/BlueprintEditor.d.ts +8 -0
  114. package/dist/types/src/components/BlueprintEditor/BlueprintEditor.d.ts.map +1 -0
  115. package/dist/types/src/components/BlueprintEditor/BlueprintEditor.stories.d.ts +8 -0
  116. package/dist/types/src/components/BlueprintEditor/BlueprintEditor.stories.d.ts.map +1 -0
  117. package/dist/types/src/components/BlueprintEditor/index.d.ts +2 -0
  118. package/dist/types/src/components/BlueprintEditor/index.d.ts.map +1 -0
  119. package/dist/types/src/components/Prompt/Prompt.d.ts +5 -2
  120. package/dist/types/src/components/Prompt/Prompt.d.ts.map +1 -1
  121. package/dist/types/src/components/Prompt/Prompt.stories.d.ts +6 -3
  122. package/dist/types/src/components/Prompt/Prompt.stories.d.ts.map +1 -1
  123. package/dist/types/src/components/Prompt/PromptBar.d.ts +9 -4
  124. package/dist/types/src/components/Prompt/PromptBar.d.ts.map +1 -1
  125. package/dist/types/src/components/Prompt/PromptBar.stories.d.ts +9 -0
  126. package/dist/types/src/components/Prompt/PromptBar.stories.d.ts.map +1 -0
  127. package/dist/types/src/components/Prompt/autocomplete.d.ts +5 -1
  128. package/dist/types/src/components/Prompt/autocomplete.d.ts.map +1 -1
  129. package/dist/types/src/components/Thread/Thread.d.ts +2 -2
  130. package/dist/types/src/components/Thread/Thread.d.ts.map +1 -1
  131. package/dist/types/src/components/Thread/ThreadContainer.d.ts +1 -1
  132. package/dist/types/src/components/Thread/ThreadContainer.d.ts.map +1 -1
  133. package/dist/types/src/components/Thread/ThreadContainer.stories.d.ts +2 -2
  134. package/dist/types/src/components/Thread/ThreadContainer.stories.d.ts.map +1 -1
  135. package/dist/types/src/components/Thread/ThreadMessage.d.ts +4 -2
  136. package/dist/types/src/components/Thread/ThreadMessage.d.ts.map +1 -1
  137. package/dist/types/src/components/Thread/ToolInvocations.d.ts +1 -1
  138. package/dist/types/src/components/Thread/ToolInvocations.d.ts.map +1 -1
  139. package/dist/types/src/components/Thread/reducer.d.ts +1 -1
  140. package/dist/types/src/components/Thread/reducer.d.ts.map +1 -1
  141. package/dist/types/src/components/Toolbox/Toolbox.d.ts +2 -1
  142. package/dist/types/src/components/Toolbox/Toolbox.d.ts.map +1 -1
  143. package/dist/types/src/components/index.d.ts +2 -0
  144. package/dist/types/src/components/index.d.ts.map +1 -1
  145. package/dist/types/src/experimental/transcription/index.d.ts +1 -0
  146. package/dist/types/src/experimental/transcription/index.d.ts.map +1 -0
  147. package/dist/types/src/hooks/processor.d.ts +6 -5
  148. package/dist/types/src/hooks/processor.d.ts.map +1 -1
  149. package/dist/types/src/hooks/useChatProcessor.d.ts.map +1 -1
  150. package/dist/types/src/hooks/useMessageQueue.d.ts +11 -7
  151. package/dist/types/src/hooks/useMessageQueue.d.ts.map +1 -1
  152. package/dist/types/src/parser/filter-generator.d.ts +4 -0
  153. package/dist/types/src/parser/filter-generator.d.ts.map +1 -0
  154. package/dist/types/src/parser/filter-generator.test.d.ts +2 -0
  155. package/dist/types/src/parser/filter-generator.test.d.ts.map +1 -0
  156. package/dist/types/src/parser/index.d.ts +4 -0
  157. package/dist/types/src/parser/index.d.ts.map +1 -0
  158. package/dist/types/src/parser/query-parser.d.ts +15 -0
  159. package/dist/types/src/parser/query-parser.d.ts.map +1 -0
  160. package/dist/types/src/parser/query-parser.test.d.ts +2 -0
  161. package/dist/types/src/parser/query-parser.test.d.ts.map +1 -0
  162. package/dist/types/src/parser/types.d.ts +24 -0
  163. package/dist/types/src/parser/types.d.ts.map +1 -0
  164. package/dist/types/src/stories/Prompt.stories.d.ts +8 -0
  165. package/dist/types/src/stories/Prompt.stories.d.ts.map +1 -0
  166. package/dist/types/src/stories/Query.stories.d.ts +19 -0
  167. package/dist/types/src/stories/Query.stories.d.ts.map +1 -0
  168. package/dist/types/src/stories/Research.stories.d.ts +15 -0
  169. package/dist/types/src/stories/Research.stories.d.ts.map +1 -0
  170. package/dist/types/src/stories/test-data.d.ts +3 -0
  171. package/dist/types/src/stories/test-data.d.ts.map +1 -0
  172. package/dist/types/src/stories/testing.d.ts +10 -0
  173. package/dist/types/src/stories/testing.d.ts.map +1 -0
  174. package/dist/types/src/testing/blueprint.d.ts +7 -0
  175. package/dist/types/src/testing/blueprint.d.ts.map +1 -0
  176. package/dist/types/src/testing/index.d.ts +1 -0
  177. package/dist/types/src/testing/index.d.ts.map +1 -1
  178. package/dist/types/src/testing/test-functions.d.ts +1 -1
  179. package/dist/types/src/testing/test-functions.d.ts.map +1 -1
  180. package/dist/types/src/tools/function.d.ts +4 -4
  181. package/dist/types/src/tools/function.d.ts.map +1 -1
  182. package/dist/types/src/tools/openapi.d.ts +3 -3
  183. package/dist/types/src/tools/openapi.d.ts.map +1 -1
  184. package/dist/types/src/translations.d.ts +63 -6
  185. package/dist/types/src/translations.d.ts.map +1 -1
  186. package/dist/types/src/types/chat.d.ts +18 -8
  187. package/dist/types/src/types/chat.d.ts.map +1 -1
  188. package/dist/types/src/types/types.d.ts +6 -3
  189. package/dist/types/src/types/types.d.ts.map +1 -1
  190. package/package.json +73 -61
  191. package/src/AssistantPlugin.tsx +5 -4
  192. package/src/capabilities/ai-client.ts +1 -1
  193. package/src/capabilities/app-graph-builder.ts +34 -24
  194. package/src/capabilities/capabilities.ts +1 -1
  195. package/src/capabilities/intent-resolver.ts +3 -2
  196. package/src/capabilities/react-surface.tsx +58 -13
  197. package/src/components/AmbientDialog/AmbientDialog.stories.tsx +1 -1
  198. package/src/components/AmbientDialog/AmbientDialog.tsx +27 -13
  199. package/src/components/AssistantDialog.tsx +1 -1
  200. package/src/components/AssistantSettings/AssistantSettings.tsx +1 -1
  201. package/src/components/BlueprintEditor/BlueprintEditor.stories.tsx +32 -0
  202. package/src/components/BlueprintEditor/BlueprintEditor.tsx +41 -0
  203. package/src/components/BlueprintEditor/index.ts +5 -0
  204. package/src/components/Prompt/Prompt.stories.tsx +59 -52
  205. package/src/components/Prompt/Prompt.tsx +24 -10
  206. package/src/components/Prompt/PromptBar.stories.tsx +68 -0
  207. package/src/components/Prompt/PromptBar.tsx +82 -80
  208. package/src/components/Prompt/autocomplete.ts +14 -8
  209. package/src/components/Prompt/references.ts +3 -3
  210. package/src/components/TemplateEditor/TemplateEditor.stories.tsx +2 -2
  211. package/src/components/TemplateEditor/TemplateForm.stories.tsx +1 -1
  212. package/src/components/Thread/Thread.stories.tsx +2 -2
  213. package/src/components/Thread/Thread.tsx +2 -2
  214. package/src/components/Thread/ThreadContainer.stories.tsx +77 -47
  215. package/src/components/Thread/ThreadContainer.tsx +8 -9
  216. package/src/components/Thread/ThreadMessage.tsx +43 -8
  217. package/src/components/Thread/ToolInvocations.tsx +9 -7
  218. package/src/components/Thread/reducer.ts +1 -1
  219. package/src/components/Toolbox/Toolbox.stories.tsx +1 -1
  220. package/src/components/Toolbox/Toolbox.tsx +2 -1
  221. package/src/components/index.ts +2 -0
  222. package/src/experimental/transcription/index.ts +3 -0
  223. package/src/hooks/processor.ts +65 -27
  224. package/src/hooks/useChatProcessor.tsx +4 -4
  225. package/src/hooks/useContextProvider.ts +6 -6
  226. package/src/hooks/useMessageQueue.ts +4 -4
  227. package/src/meta.ts +2 -2
  228. package/src/parser/filter-generator.test.ts +32 -0
  229. package/src/parser/filter-generator.ts +81 -0
  230. package/src/parser/index.ts +7 -0
  231. package/src/parser/query-parser.test.ts +139 -0
  232. package/src/parser/query-parser.ts +199 -0
  233. package/src/parser/types.ts +34 -0
  234. package/src/shims.d.ts +8 -0
  235. package/src/stories/Prompt.stories.tsx +59 -0
  236. package/src/stories/Query.stories.tsx +432 -0
  237. package/src/stories/Research.stories.tsx +495 -0
  238. package/src/stories/test-data.ts +128 -0
  239. package/src/stories/testing.ts +67 -0
  240. package/src/testing/blueprint.ts +47 -0
  241. package/src/testing/index.ts +1 -0
  242. package/src/testing/test-functions.ts +1 -1
  243. package/src/tools/function.ts +8 -7
  244. package/src/tools/openapi.test.ts +18 -19
  245. package/src/tools/openapi.ts +20 -14
  246. package/src/translations.ts +4 -2
  247. package/src/types/chat.ts +27 -4
  248. package/src/types/types.ts +3 -1
  249. package/dist/lib/browser/AssistantDialog-DTWVEQBB.mjs +0 -117
  250. package/dist/lib/browser/AssistantDialog-DTWVEQBB.mjs.map +0 -7
  251. package/dist/lib/browser/ChatContainer-ZNKENYKZ.mjs +0 -33
  252. package/dist/lib/browser/TemplateContainer-WKU5XFSO.mjs +0 -22
  253. package/dist/lib/browser/ai-client-5PRCXI7N.mjs.map +0 -7
  254. package/dist/lib/browser/app-graph-builder-HTK3HFGM.mjs.map +0 -7
  255. package/dist/lib/browser/chunk-5P7U35RJ.mjs +0 -192
  256. package/dist/lib/browser/chunk-5P7U35RJ.mjs.map +0 -7
  257. package/dist/lib/browser/chunk-7VDZP5WX.mjs +0 -143
  258. package/dist/lib/browser/chunk-7VDZP5WX.mjs.map +0 -7
  259. package/dist/lib/browser/chunk-NFUHCW2J.mjs +0 -81
  260. package/dist/lib/browser/chunk-OWZHLWW5.mjs.map +0 -7
  261. package/dist/lib/browser/chunk-TXJWGWJ7.mjs.map +0 -7
  262. package/dist/lib/browser/intent-resolver-QV5AAVJZ.mjs.map +0 -7
  263. package/dist/lib/browser/react-surface-JJPYWEIN.mjs +0 -90
  264. package/dist/lib/browser/react-surface-JJPYWEIN.mjs.map +0 -7
  265. package/dist/lib/node/AssistantDialog-RJJHZI63.cjs +0 -141
  266. package/dist/lib/node/AssistantDialog-RJJHZI63.cjs.map +0 -7
  267. package/dist/lib/node/ai-client-OUPSRQT7.cjs.map +0 -7
  268. package/dist/lib/node/app-graph-builder-LEO63CZZ.cjs.map +0 -7
  269. package/dist/lib/node/chunk-GBUNQ257.cjs.map +0 -7
  270. package/dist/lib/node/chunk-GQ3XS5FZ.cjs +0 -169
  271. package/dist/lib/node/chunk-GQ3XS5FZ.cjs.map +0 -7
  272. package/dist/lib/node/chunk-OOHFSPWR.cjs.map +0 -7
  273. package/dist/lib/node/chunk-VG2UQY4S.cjs +0 -216
  274. package/dist/lib/node/chunk-VG2UQY4S.cjs.map +0 -7
  275. package/dist/lib/node/intent-resolver-QDGZMWLY.cjs.map +0 -7
  276. package/dist/lib/node/react-surface-XNEIJJYJ.cjs +0 -106
  277. package/dist/lib/node/react-surface-XNEIJJYJ.cjs.map +0 -7
  278. package/dist/lib/node-esm/AssistantDialog-D33WZUGR.mjs +0 -118
  279. package/dist/lib/node-esm/AssistantDialog-D33WZUGR.mjs.map +0 -7
  280. package/dist/lib/node-esm/ChatContainer-FAYGNMQW.mjs +0 -34
  281. package/dist/lib/node-esm/TemplateContainer-3LEBT5ZC.mjs +0 -23
  282. package/dist/lib/node-esm/ai-client-RZQWEDUX.mjs.map +0 -7
  283. package/dist/lib/node-esm/app-graph-builder-WXJNZDYB.mjs.map +0 -7
  284. package/dist/lib/node-esm/chunk-6JK5HEUQ.mjs.map +0 -7
  285. package/dist/lib/node-esm/chunk-74GFINWJ.mjs +0 -144
  286. package/dist/lib/node-esm/chunk-74GFINWJ.mjs.map +0 -7
  287. package/dist/lib/node-esm/chunk-ED55ZE4G.mjs.map +0 -7
  288. package/dist/lib/node-esm/chunk-UZWYXNR5.mjs +0 -193
  289. package/dist/lib/node-esm/chunk-UZWYXNR5.mjs.map +0 -7
  290. package/dist/lib/node-esm/intent-resolver-Q3I6S6HN.mjs.map +0 -7
  291. package/dist/lib/node-esm/react-surface-RI3JONQY.mjs +0 -91
  292. package/dist/lib/node-esm/react-surface-RI3JONQY.mjs.map +0 -7
  293. /package/dist/lib/browser/{settings-OZX7J65A.mjs.map → settings-SHNQ4XXP.mjs.map} +0 -0
  294. /package/dist/lib/node/{settings-WLTC7XO5.cjs.map → settings-ERKLO6IO.cjs.map} +0 -0
  295. /package/dist/lib/node-esm/{settings-CLE57WEP.mjs.map → settings-IVQRZUCU.mjs.map} +0 -0
@@ -1,26 +1,457 @@
1
1
  import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
2
  import {
3
3
  AssistantCapabilities
4
- } from "./chunk-6JK5HEUQ.mjs";
4
+ } from "./chunk-HLPGKJ7N.mjs";
5
5
  import {
6
6
  ServiceType,
7
7
  categoryIcons
8
- } from "./chunk-UZWYXNR5.mjs";
8
+ } from "./chunk-ZKBACPIW.mjs";
9
9
  import {
10
10
  ASSISTANT_PLUGIN
11
- } from "./chunk-ECRK6TUQ.mjs";
11
+ } from "./chunk-BB2TAT4P.mjs";
12
+
13
+ // packages/plugins/plugin-assistant/src/components/Prompt/Prompt.tsx
14
+ import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
15
+ import { Prec as Prec2 } from "@codemirror/state";
16
+ import React, { forwardRef, useImperativeHandle } from "react";
17
+ import { useThemeContext } from "@dxos/react-ui";
18
+ import { createBasicExtensions, createThemeExtensions, keymap as keymap3, useTextEditor } from "@dxos/react-ui-editor";
19
+ import { mx } from "@dxos/react-ui-theme";
20
+ import { isNonNullable } from "@dxos/util";
21
+
22
+ // packages/plugins/plugin-assistant/src/components/Prompt/autocomplete.ts
23
+ import { Prec } from "@codemirror/state";
24
+ import { EditorView, Decoration, ViewPlugin, keymap, WidgetType } from "@codemirror/view";
25
+ var autocompleteExtension = ({ onSubmit, onSuggest, onCancel }) => {
26
+ const suggest = ViewPlugin.fromClass(class {
27
+ constructor(view) {
28
+ this._currentSuggestion = null;
29
+ this._decorations = this.computeDecorations(view);
30
+ }
31
+ update(update) {
32
+ if (update.docChanged || update.selectionSet) {
33
+ this._decorations = this.computeDecorations(update.view);
34
+ }
35
+ }
36
+ computeDecorations(view) {
37
+ const text = view.state.doc.toString();
38
+ const suggestions = onSuggest?.(text) ?? [];
39
+ if (!suggestions.length) {
40
+ this._currentSuggestion = null;
41
+ return Decoration.none;
42
+ }
43
+ this._currentSuggestion = suggestions[0];
44
+ const suffix = this._currentSuggestion.slice(text.length);
45
+ if (!suffix) {
46
+ return Decoration.none;
47
+ }
48
+ return Decoration.set([
49
+ Decoration.widget({
50
+ widget: new InlineSuggestionWidget(suffix),
51
+ side: 1
52
+ }).range(view.state.doc.length)
53
+ ]);
54
+ }
55
+ completeSuggestion(view) {
56
+ if (!this._currentSuggestion) {
57
+ return false;
58
+ }
59
+ const text = view.state.doc.toString();
60
+ const suffix = this._currentSuggestion.slice(text.length);
61
+ if (!suffix) {
62
+ return false;
63
+ }
64
+ view.dispatch({
65
+ changes: {
66
+ from: view.state.doc.length,
67
+ insert: suffix
68
+ },
69
+ selection: {
70
+ anchor: view.state.doc.length + suffix.length
71
+ }
72
+ });
73
+ return true;
74
+ }
75
+ }, {
76
+ decorations: (v) => v._decorations
77
+ });
78
+ return [
79
+ suggest,
80
+ EditorView.theme({
81
+ ".cm-inline-suggestion": {
82
+ opacity: 0.4
83
+ }
84
+ }),
85
+ Prec.highest(keymap.of([
86
+ {
87
+ key: "Tab",
88
+ preventDefault: true,
89
+ run: (view) => {
90
+ const plugin = view.plugin(suggest);
91
+ return plugin?.completeSuggestion(view) ?? false;
92
+ }
93
+ },
94
+ {
95
+ key: "ArrowRight",
96
+ preventDefault: true,
97
+ run: (view) => {
98
+ if (view.state.selection.main.head !== view.state.doc.length) {
99
+ return false;
100
+ }
101
+ const plugin = view.plugin(suggest);
102
+ return plugin?.completeSuggestion(view) ?? false;
103
+ }
104
+ },
105
+ {
106
+ key: "Enter",
107
+ preventDefault: true,
108
+ run: (view) => {
109
+ const text = view.state.doc.toString().trim();
110
+ if (text.length > 0 && onSubmit) {
111
+ const reset = onSubmit(text);
112
+ if (reset) {
113
+ view.dispatch({
114
+ changes: {
115
+ from: 0,
116
+ to: view.state.doc.length,
117
+ insert: ""
118
+ }
119
+ });
120
+ }
121
+ }
122
+ return true;
123
+ }
124
+ },
125
+ {
126
+ key: "Shift-Enter",
127
+ preventDefault: true,
128
+ run: (view) => {
129
+ view.dispatch({
130
+ changes: {
131
+ from: view.state.selection.main.head,
132
+ insert: "\n"
133
+ },
134
+ selection: {
135
+ anchor: view.state.selection.main.head + 1,
136
+ head: view.state.selection.main.head + 1
137
+ }
138
+ });
139
+ return true;
140
+ }
141
+ },
142
+ {
143
+ key: "Escape",
144
+ preventDefault: true,
145
+ run: (view) => {
146
+ view.dispatch({
147
+ changes: {
148
+ from: 0,
149
+ to: view.state.doc.length,
150
+ insert: ""
151
+ }
152
+ });
153
+ onCancel?.();
154
+ return true;
155
+ }
156
+ }
157
+ ]))
158
+ ];
159
+ };
160
+ var InlineSuggestionWidget = class extends WidgetType {
161
+ constructor(suffix) {
162
+ super(), this.suffix = suffix;
163
+ }
164
+ toDOM() {
165
+ const span = document.createElement("span");
166
+ span.textContent = this.suffix;
167
+ span.className = "cm-inline-suggestion";
168
+ return span;
169
+ }
170
+ eq(other) {
171
+ return other.suffix === this.suffix;
172
+ }
173
+ };
174
+
175
+ // packages/plugins/plugin-assistant/src/components/Prompt/references.ts
176
+ import { autocompletion, completionKeymap } from "@codemirror/autocomplete";
177
+ import { RangeSet } from "@codemirror/state";
178
+ import { Decoration as Decoration2, EditorView as EditorView2, keymap as keymap2, ViewPlugin as ViewPlugin2, WidgetType as WidgetType2 } from "@codemirror/view";
179
+ import { Mutex } from "@dxos/async";
180
+ var promptReferences = ({ provider, debug = false, triggerCharacter = "@" }) => {
181
+ if (triggerCharacter.length !== 1) {
182
+ throw new Error("triggerCharacter must be a single character");
183
+ }
184
+ const decorationField = ViewPlugin2.fromClass(class ReferenceView {
185
+ constructor(view) {
186
+ this._mutex = new Mutex();
187
+ this.decorations = Decoration2.set([]);
188
+ queueMicrotask(async () => {
189
+ const guard = await this._mutex.acquire();
190
+ try {
191
+ this.decorations = await this._computeDecorations(view);
192
+ } finally {
193
+ guard.release();
194
+ }
195
+ });
196
+ }
197
+ update(update) {
198
+ if (update.docChanged) {
199
+ queueMicrotask(async () => {
200
+ const guard = await this._mutex.acquire();
201
+ try {
202
+ this.decorations = await this._computeDecorations(update.view);
203
+ } finally {
204
+ guard.release();
205
+ }
206
+ });
207
+ }
208
+ }
209
+ async _computeDecorations(view) {
210
+ const text = view.state.doc.toString();
211
+ const references = text.matchAll(new RegExp(`${triggerCharacter}[a-zA-Z0-9@:]+\\s`, "g"));
212
+ const decorations = [];
213
+ for (const match of references) {
214
+ const reference = match[0];
215
+ const uri = reference.slice(1, -1);
216
+ const data = await provider.resolveReference({
217
+ uri
218
+ });
219
+ if (data) {
220
+ decorations.push(Decoration2.replace({
221
+ widget: new ReferenceWidget(data)
222
+ }).range(match.index, match.index + reference.length));
223
+ }
224
+ }
225
+ return Decoration2.set(decorations);
226
+ }
227
+ }, {
228
+ decorations: (v) => v.decorations,
229
+ provide: (plugin) => [
230
+ EditorView2.atomicRanges.of((view) => view.plugin(decorationField)?.decorations ?? RangeSet.empty)
231
+ ]
232
+ });
233
+ return [
234
+ decorationField,
235
+ EditorView2.theme({
236
+ ".cm-reference-pill": {
237
+ borderRadius: "0.25rem",
238
+ borderWidth: "1px",
239
+ marginRight: "0.25rem",
240
+ marginLeft: "0.25rem"
241
+ }
242
+ }),
243
+ autocompletion({
244
+ activateOnTyping: true,
245
+ override: [
246
+ async (context) => {
247
+ const match = context.matchBefore(new RegExp(`${triggerCharacter}[a-zA-Z0-9]+`));
248
+ if (!match || match?.to === match?.from) {
249
+ return null;
250
+ }
251
+ const query = match.text.slice(1);
252
+ const references = await provider.getReferences({
253
+ query
254
+ });
255
+ return {
256
+ from: match.from,
257
+ filter: false,
258
+ options: references.map((reference) => ({
259
+ label: reference.label,
260
+ apply: `${triggerCharacter}${reference.uri} `
261
+ }))
262
+ };
263
+ }
264
+ ],
265
+ closeOnBlur: !debug,
266
+ tooltipClass: () => "shadow rounded",
267
+ aboveCursor: true
268
+ }),
269
+ keymap2.of(completionKeymap)
270
+ ];
271
+ };
272
+ var ReferenceWidget = class extends WidgetType2 {
273
+ constructor(data) {
274
+ super(), this.data = data;
275
+ }
276
+ toDOM() {
277
+ const span = document.createElement("span");
278
+ span.textContent = `@ ${this.data.label}`;
279
+ span.className = "cm-reference-pill";
280
+ return span;
281
+ }
282
+ eq(other) {
283
+ return other.data.uri === this.data.uri;
284
+ }
285
+ ignoreEvent() {
286
+ return true;
287
+ }
288
+ };
289
+
290
+ // packages/plugins/plugin-assistant/src/components/Prompt/Prompt.tsx
291
+ var Prompt = /* @__PURE__ */ forwardRef(({ classNames, extensions, references, autoFocus, lineWrapping = false, placeholder, onSubmit, onSuggest, onCancel, onOpenChange }, forwardRef3) => {
292
+ var _effect = _useSignals();
293
+ try {
294
+ const { themeMode } = useThemeContext();
295
+ const { parentRef, view } = useTextEditor({
296
+ debug: true,
297
+ autoFocus,
298
+ extensions: [
299
+ autocompleteExtension({
300
+ onSubmit,
301
+ onSuggest,
302
+ onCancel
303
+ }),
304
+ createBasicExtensions({
305
+ bracketMatching: false,
306
+ lineWrapping,
307
+ placeholder
308
+ }),
309
+ createThemeExtensions({
310
+ themeMode
311
+ }),
312
+ references ? promptReferences({
313
+ provider: references
314
+ }) : [],
315
+ Prec2.highest(keymap3.of([
316
+ {
317
+ key: "cmd-ArrowUp",
318
+ preventDefault: true,
319
+ run: () => {
320
+ onOpenChange?.(true);
321
+ return true;
322
+ }
323
+ },
324
+ {
325
+ key: "cmd-ArrowDown",
326
+ preventDefault: true,
327
+ run: () => {
328
+ onOpenChange?.(false);
329
+ return true;
330
+ }
331
+ }
332
+ ])),
333
+ extensions
334
+ ].filter(isNonNullable)
335
+ }, [
336
+ themeMode,
337
+ extensions,
338
+ onSubmit,
339
+ onSuggest
340
+ ]);
341
+ useImperativeHandle(forwardRef3, () => {
342
+ return {
343
+ focus: () => {
344
+ view?.focus();
345
+ },
346
+ setText: (text) => {
347
+ view?.dispatch({
348
+ changes: {
349
+ from: 0,
350
+ to: view.state.doc.length,
351
+ insert: text
352
+ },
353
+ selection: {
354
+ anchor: text.length,
355
+ head: text.length
356
+ }
357
+ });
358
+ }
359
+ };
360
+ }, [
361
+ view,
362
+ onSubmit
363
+ ]);
364
+ return /* @__PURE__ */ React.createElement("div", {
365
+ ref: parentRef,
366
+ className: mx("w-full", classNames)
367
+ });
368
+ } finally {
369
+ _effect.f();
370
+ }
371
+ });
372
+
373
+ // packages/plugins/plugin-assistant/src/components/Prompt/PromptBar.tsx
374
+ import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
375
+ import React2, { forwardRef as forwardRef2, useState } from "react";
376
+ import { useVoiceInput } from "@dxos/plugin-transcription";
377
+ import { Icon, IconButton, Tooltip, useForwardedRef, useTranslation } from "@dxos/react-ui";
378
+ import { Spinner } from "@dxos/react-ui-sfx";
379
+ import { errorText, mx as mx2 } from "@dxos/react-ui-theme";
380
+ var PromptBar = /* @__PURE__ */ forwardRef2(({ classNames, placeholder, processing, error, microphone, references, onCancel, ...props }, forwardedRef) => {
381
+ var _effect = _useSignals2();
382
+ try {
383
+ const { t } = useTranslation(ASSISTANT_PLUGIN);
384
+ const promptRef = useForwardedRef(forwardedRef);
385
+ const [active, setActive] = useState(false);
386
+ const { recording } = useVoiceInput({
387
+ active,
388
+ onUpdate: (text) => {
389
+ promptRef.current?.setText(text);
390
+ promptRef.current?.focus();
391
+ }
392
+ });
393
+ return /* @__PURE__ */ React2.createElement("div", {
394
+ className: mx2("shrink-0 w-full grid grid-cols-[var(--rail-action)_1fr_var(--rail-action)] overflow-hidden", classNames)
395
+ }, /* @__PURE__ */ React2.createElement("div", {
396
+ className: "flex w-[--rail-action] h-[--rail-action] items-center justify-center"
397
+ }, error && /* @__PURE__ */ React2.createElement(Tooltip.Trigger, {
398
+ content: error.message,
399
+ delayDuration: 0
400
+ }, /* @__PURE__ */ React2.createElement(Icon, {
401
+ icon: "ph--warning-circle--regular",
402
+ classNames: errorText,
403
+ size: 5
404
+ })) || /* @__PURE__ */ React2.createElement(Spinner, {
405
+ active: processing
406
+ })), /* @__PURE__ */ React2.createElement(Prompt, {
407
+ ref: promptRef,
408
+ autoFocus: true,
409
+ classNames: "pbs-2",
410
+ lineWrapping: true,
411
+ placeholder: placeholder ?? t("prompt placeholder"),
412
+ references,
413
+ onCancel,
414
+ ...props
415
+ }), (onCancel || microphone) && /* @__PURE__ */ React2.createElement("div", {
416
+ className: "flex w-[--rail-action] h-[--rail-action] items-center justify-center"
417
+ }, processing && onCancel && /* @__PURE__ */ React2.createElement(IconButton, {
418
+ classNames: "px-1.5",
419
+ variant: "ghost",
420
+ size: 5,
421
+ icon: "ph--x--regular",
422
+ iconOnly: true,
423
+ label: t("cancel processing button"),
424
+ onClick: onCancel
425
+ }), !processing && microphone && /* @__PURE__ */ React2.createElement(IconButton, {
426
+ classNames: mx2("px-1.5", recording && "bg-primary-500"),
427
+ variant: "ghost",
428
+ size: 5,
429
+ icon: "ph--microphone--regular",
430
+ iconOnly: true,
431
+ noTooltip: true,
432
+ label: t("microphone button"),
433
+ onMouseDown: () => setActive(true),
434
+ onMouseUp: () => setActive(false),
435
+ onTouchStart: () => setActive(true),
436
+ onTouchEnd: () => setActive(false)
437
+ })));
438
+ } finally {
439
+ _effect.f();
440
+ }
441
+ });
12
442
 
13
443
  // packages/plugins/plugin-assistant/src/components/Toolbox/Toolbox.tsx
14
- import React, { useState, useEffect, Fragment } from "react";
444
+ import { useSignals as _useSignals3 } from "@preact-signals/safe-react/tracking";
445
+ import React3, { useState as useState2, useEffect, Fragment } from "react";
446
+ import { parseToolName } from "@dxos/ai";
15
447
  import { Capabilities, useCapabilities } from "@dxos/app-framework";
16
- import { parseToolName } from "@dxos/artifact";
17
448
  import { FunctionType } from "@dxos/functions";
18
449
  import { log as log3 } from "@dxos/log";
19
450
  import { Filter, useQuery } from "@dxos/react-client/echo";
20
- import { mx } from "@dxos/react-ui-theme";
451
+ import { mx as mx3 } from "@dxos/react-ui-theme";
21
452
 
22
453
  // packages/plugins/plugin-assistant/src/tools/function.ts
23
- import { defineTool, ToolResult } from "@dxos/artifact";
454
+ import { createTool, ToolResult } from "@dxos/ai";
24
455
  import { toEffectSchema } from "@dxos/echo-schema";
25
456
  import { getInvocationUrl, getUserFunctionUrlInMetadata } from "@dxos/functions";
26
457
  import { log } from "@dxos/log";
@@ -37,7 +468,7 @@ var convertFunctionToTool = (fn, edgeUrl, spaceId) => {
37
468
  const url = getInvocationUrl(existingFunctionUrl, edgeUrl, {
38
469
  spaceId
39
470
  });
40
- return defineTool("user-function", {
471
+ return createTool("user-function", {
41
472
  name: fn.name,
42
473
  description: fn.description,
43
474
  schema: toEffectSchema(fn.inputSchema),
@@ -67,7 +498,7 @@ var convertFunctionToTool = (fn, edgeUrl, spaceId) => {
67
498
  // packages/plugins/plugin-assistant/src/tools/openapi.ts
68
499
  import { Schema } from "effect";
69
500
  import jsonpointer from "jsonpointer";
70
- import { ToolResult as ToolResult2 } from "@dxos/artifact";
501
+ import { ToolResult as ToolResult2, createRawTool } from "@dxos/ai";
71
502
  import { JsonSchemaType, normalizeSchema, toEffectSchema as toEffectSchema2 } from "@dxos/echo-schema";
72
503
  import { invariant } from "@dxos/invariant";
73
504
  import { log as log2 } from "@dxos/log";
@@ -76,1330 +507,997 @@ var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-assista
76
507
  var createToolsFromService = async (service) => {
77
508
  invariant(service.interfaces?.length === 1 && service.interfaces[0].kind === "api", void 0, {
78
509
  F: __dxlog_file2,
79
- L: 23,
80
- S: void 0,
81
- A: [
82
- "service.interfaces?.length === 1 && service.interfaces[0].kind === 'api'",
83
- ""
84
- ]
85
- });
86
- const iface = service.interfaces[0];
87
- invariant(iface.schemaUrl, void 0, {
88
- F: __dxlog_file2,
89
- L: 25,
90
- S: void 0,
91
- A: [
92
- "iface.schemaUrl",
93
- ""
94
- ]
95
- });
96
- invariant(iface.schemaUrl, void 0, {
97
- F: __dxlog_file2,
98
- L: 26,
99
- S: void 0,
100
- A: [
101
- "iface.schemaUrl",
102
- ""
103
- ]
104
- });
105
- return createToolsFromApi(iface.schemaUrl, {
106
- authorization: iface.authorization
107
- });
108
- };
109
- var createToolsFromApi = async (url, options) => {
110
- const res = await fetch(url);
111
- const spec = await res.json();
112
- log2("spec", {
113
- spec
114
- }, {
115
- F: __dxlog_file2,
116
- L: 33,
117
- S: void 0,
118
- C: (f, a) => f(...a)
119
- });
120
- const tools = [];
121
- for (const [path, pathItem] of Object.entries(spec.paths)) {
122
- if (typeof pathItem !== "object") {
123
- continue;
124
- }
125
- const { ...methods } = pathItem;
126
- for (const [method, m] of Object.entries(methods)) {
127
- const methodItem = m;
128
- log2("methodItem", {
129
- path,
130
- method,
131
- methodItem
132
- }, {
133
- F: __dxlog_file2,
134
- L: 45,
135
- S: void 0,
136
- C: (f, a) => f(...a)
137
- });
138
- const parametersResolved = methodItem.parameters?.map((parameter) => {
139
- const resolved = resolveJsonSchema(parameter, spec);
140
- return resolved;
141
- }) ?? [];
142
- const inputSchema = {
143
- type: "object",
144
- properties: {}
145
- };
146
- const endpointParameters = [];
147
- for (const parameter of parametersResolved) {
148
- log2("parameter", {
149
- parameter
150
- }, {
151
- F: __dxlog_file2,
152
- L: 60,
153
- S: void 0,
154
- C: (f, a) => f(...a)
155
- });
156
- if (options?.authorization?.type === "api-key" && options.authorization.placement.type === "query" && parameter.in === "query" && parameter.name === options.authorization.placement.name) {
157
- continue;
158
- }
159
- endpointParameters.push(parameter);
160
- if (parameter.schema) {
161
- inputSchema.properties[parameter.name] = normalizeSchema(parameter.schema);
162
- } else if (typeof parameter.type === "string") {
163
- const { name, in: _in, required, ...schema } = parameter;
164
- inputSchema.properties[name] = normalizeSchema(schema);
165
- if (required) {
166
- inputSchema.required ??= [];
167
- inputSchema.required.push(name);
168
- }
169
- }
170
- }
171
- log2("inputSchema", {
172
- inputSchema
173
- }, {
174
- F: __dxlog_file2,
175
- L: 85,
176
- S: void 0,
177
- C: (f, a) => f(...a)
178
- });
179
- Schema.validateSync(JsonSchemaType)(inputSchema);
180
- const description = methodItem.description ?? methodItem.summary;
181
- if (!description) {
182
- log2.warn("no description", {
183
- path,
184
- method
185
- }, {
186
- F: __dxlog_file2,
187
- L: 90,
188
- S: void 0,
189
- C: (f, a) => f(...a)
190
- });
191
- continue;
192
- }
193
- const endpoint = {
194
- document: spec,
195
- path,
196
- method,
197
- parameters: endpointParameters,
198
- authorization: options?.authorization
199
- };
200
- tools.push({
201
- name: getToolName(path, method, methodItem),
202
- description: options?.instructions ? `${options.instructions}
203
-
204
- ${description}` : description,
205
- parameters: inputSchema,
206
- execute: async (input) => {
207
- const response = await callApiEndpoint(endpoint, input);
208
- return ToolResult2.Success(response);
209
- }
210
- });
211
- }
212
- }
213
- return tools;
214
- };
215
- var getToolName = (path, method, methodItem) => {
216
- if (methodItem.operationId) {
217
- return methodItem.operationId;
218
- }
219
- let name = `${method.toLowerCase()}_${path.replaceAll(/[{}/]/g, "_")}`;
220
- while (name.length > MAX_TOOL_NAME_LENGTH) {
221
- const lengthBefore = name.length;
222
- for (const word of GENERIC_WORDS) {
223
- if (name.includes(word)) {
224
- name = name.replace(word, "");
225
- break;
226
- }
227
- }
228
- name = name.replaceAll("__", "_").replace(/_$/, "");
229
- const lengthAfter = name.length;
230
- if (lengthBefore === lengthAfter) {
231
- break;
232
- }
233
- }
234
- name = name.replaceAll("__", "_").replace(/_$/, "").replace(/^_/, "");
235
- return name.slice(0, MAX_TOOL_NAME_LENGTH);
236
- };
237
- var MAX_TOOL_NAME_LENGTH = 64;
238
- var GENERIC_WORDS = [
239
- "services",
240
- "service",
241
- "api",
242
- "rest",
243
- "endpoint",
244
- "get",
245
- "post",
246
- "put",
247
- "delete",
248
- "patch",
249
- "head",
250
- "options",
251
- "trace",
252
- "service",
253
- "api",
254
- "endpoint"
255
- ];
256
- var callApiEndpoint = async (endpoint, input) => {
257
- log2.info("endpoint", {
258
- method: endpoint.method,
259
- name: endpoint.path,
260
- input
261
- }, {
262
- F: __dxlog_file2,
263
- L: 174,
264
- S: void 0,
265
- C: (f, a) => f(...a)
266
- });
267
- let url = getEndpointUrl(endpoint);
268
- const request = {
269
- method: endpoint.method,
270
- headers: {}
271
- };
272
- const query = new URLSearchParams();
273
- let body;
274
- for (const parameter of endpoint.parameters) {
275
- if (input[parameter.name] === void 0) {
276
- continue;
277
- }
278
- switch (parameter.in) {
279
- case "header": {
280
- if (parameter.example) {
281
- request.headers[parameter.name] = parameter.default;
282
- }
283
- break;
284
- }
285
- case "path": {
286
- url = url.replace(`{${parameter.name}}`, encodeURIComponent(input[parameter.name]));
287
- break;
288
- }
289
- case "body": {
290
- const value = input[parameter.name];
291
- const effectSchema = toEffectSchema2(parameter.schema);
292
- Schema.validateSync(effectSchema)(value);
293
- if (body) {
294
- throw new Error(`Duplicate body parameter: ${parameter.name}`);
295
- }
296
- body = value;
297
- break;
298
- }
299
- case "query": {
300
- query.set(parameter.name, input[parameter.name]);
301
- break;
302
- }
303
- }
304
- }
305
- if (endpoint.authorization?.type === "api-key" && endpoint.authorization.placement.type === "authorization-header" || endpoint.authorization?.type === "oauth") {
306
- request.headers.Authorization = await resolveAuthorization(endpoint.authorization);
307
- } else if (endpoint.authorization?.type === "api-key" && endpoint.authorization.placement.type === "query") {
308
- query.set(endpoint.authorization.placement.name, endpoint.authorization.key);
309
- }
310
- if (query.size > 0) {
311
- url += `?${query.toString()}`;
312
- }
313
- if (body) {
314
- request.body = JSON.stringify(body);
315
- request.headers["Content-Type"] = "application/json";
316
- }
317
- log2.info("request", {
318
- url,
319
- request
320
- }, {
510
+ L: 23,
511
+ S: void 0,
512
+ A: [
513
+ "service.interfaces?.length === 1 && service.interfaces[0].kind === 'api'",
514
+ ""
515
+ ]
516
+ });
517
+ const iface = service.interfaces[0];
518
+ invariant(iface.schemaUrl, void 0, {
321
519
  F: __dxlog_file2,
322
- L: 237,
520
+ L: 25,
323
521
  S: void 0,
324
- C: (f, a) => f(...a)
522
+ A: [
523
+ "iface.schemaUrl",
524
+ ""
525
+ ]
325
526
  });
326
- const response = await fetch(url, request);
327
- log2.info("response", {
328
- ok: response.ok,
329
- status: response.status,
330
- statusText: response.statusText
527
+ invariant(iface.schemaUrl, void 0, {
528
+ F: __dxlog_file2,
529
+ L: 26,
530
+ S: void 0,
531
+ A: [
532
+ "iface.schemaUrl",
533
+ ""
534
+ ]
535
+ });
536
+ return createToolsFromApi(iface.schemaUrl, {
537
+ authorization: iface.authorization
538
+ });
539
+ };
540
+ var createToolsFromApi = async (url, options) => {
541
+ const res = await fetch(url);
542
+ const spec = await res.json();
543
+ log2("spec", {
544
+ spec
331
545
  }, {
332
546
  F: __dxlog_file2,
333
- L: 240,
547
+ L: 36,
334
548
  S: void 0,
335
549
  C: (f, a) => f(...a)
336
550
  });
337
- if (response.ok) {
338
- const contentType = response.headers.get("Content-Type");
339
- if (contentType?.includes("application/json")) {
340
- return await response.json();
341
- } else {
342
- return await response.text();
551
+ const tools = [];
552
+ for (const [path, pathItem] of Object.entries(spec.paths)) {
553
+ if (typeof pathItem !== "object") {
554
+ continue;
343
555
  }
344
- } else {
345
- if (response.headers.get("Content-Type")?.includes("application/json")) {
346
- const responseBody = await response.text();
347
- let error;
348
- try {
349
- error = JSON.parse(responseBody);
350
- } catch {
351
- error = responseBody;
352
- }
353
- log2.error("error", {
354
- error
556
+ const { ...methods } = pathItem;
557
+ for (const [method, m] of Object.entries(methods)) {
558
+ const methodItem = m;
559
+ log2("methodItem", {
560
+ path,
561
+ method,
562
+ methodItem
355
563
  }, {
356
564
  F: __dxlog_file2,
357
- L: 258,
565
+ L: 47,
358
566
  S: void 0,
359
567
  C: (f, a) => f(...a)
360
568
  });
361
- throw new Error(error.message);
362
- } else {
363
- const error = await response.text();
364
- log2.error("error", {
365
- error
569
+ const parametersResolved = methodItem.parameters?.map((parameter) => {
570
+ const resolved = resolveJsonSchema(parameter, spec);
571
+ return resolved;
572
+ }) ?? [];
573
+ const inputSchema = {
574
+ type: "object",
575
+ properties: {}
576
+ };
577
+ const endpointParameters = [];
578
+ for (const parameter of parametersResolved) {
579
+ log2("parameter", {
580
+ parameter
581
+ }, {
582
+ F: __dxlog_file2,
583
+ L: 63,
584
+ S: void 0,
585
+ C: (f, a) => f(...a)
586
+ });
587
+ if (options?.authorization?.type === "api-key" && options.authorization.placement.type === "query" && parameter.in === "query" && parameter.name === options.authorization.placement.name) {
588
+ continue;
589
+ }
590
+ endpointParameters.push(parameter);
591
+ if (parameter.schema) {
592
+ inputSchema.properties[parameter.name] = normalizeSchema(parameter.schema);
593
+ } else if (typeof parameter.type === "string") {
594
+ const { name, in: _in, required, ...schema } = parameter;
595
+ inputSchema.properties[name] = normalizeSchema(schema);
596
+ if (required) {
597
+ inputSchema.required ??= [];
598
+ inputSchema.required.push(name);
599
+ }
600
+ }
601
+ }
602
+ log2("inputSchema", {
603
+ inputSchema
366
604
  }, {
367
605
  F: __dxlog_file2,
368
- L: 262,
606
+ L: 88,
369
607
  S: void 0,
370
608
  C: (f, a) => f(...a)
371
609
  });
372
- throw new Error(error);
373
- }
374
- }
375
- };
376
- var getEndpointUrl = (endpoint) => {
377
- let url = "";
378
- if (isV3_1(endpoint.document) && endpoint.document.servers && endpoint.document.servers.length > 0) {
379
- url = endpoint.document.servers[0].url;
380
- } else {
381
- invariant(!isV3_1(endpoint.document), void 0, {
382
- F: __dxlog_file2,
383
- L: 273,
384
- S: void 0,
385
- A: [
386
- "!isV3_1(endpoint.document)",
387
- ""
388
- ]
389
- });
390
- url = `${endpoint.document.schemes?.[0] ?? "https"}://${endpoint.document.host}`;
391
- }
392
- if (!isV3_1(endpoint.document) && endpoint.document.basePath) {
393
- url += endpoint.document.basePath;
394
- }
395
- url += endpoint.path;
396
- return url;
397
- };
398
- var resolveAuthorization = async (authorization) => {
399
- switch (authorization.type) {
400
- case "api-key": {
401
- invariant(authorization.placement.type === "authorization-header", void 0, {
402
- F: __dxlog_file2,
403
- L: 289,
404
- S: void 0,
405
- A: [
406
- "authorization.placement.type === 'authorization-header'",
407
- ""
408
- ]
409
- });
410
- return `Bearer ${authorization.key}`;
411
- }
412
- case "oauth": {
413
- const response = await fetch(authorization.tokenUrl, {
414
- method: "POST",
415
- headers: {
416
- "Content-Type": "application/x-www-form-urlencoded"
417
- },
418
- body: `grant_type=${authorization.grantType}&client_id=${authorization.clientId}&client_secret=${authorization.clientSecret}`
419
- });
420
- const data = await response.json();
421
- return `Bearer ${data.access_token}`;
422
- }
423
- default: {
424
- throw new Error(`Unknown authorization type: ${authorization.type}`);
425
- }
426
- }
427
- };
428
- var resolveJsonSchema = (schema, base) => {
429
- return deepMapValues(schema, (value, recurse) => {
430
- if (typeof value === "object" && value !== null && "$ref" in value && typeof value.$ref === "string") {
431
- if (value.$ref.startsWith("#")) {
432
- const resolved = jsonpointer.get(base, value.$ref.slice(1));
433
- if (resolved) {
434
- return recurse(resolved);
435
- } else {
436
- log2.warn("unresolved", {
437
- ref: value.$ref,
438
- base
439
- }, {
440
- F: __dxlog_file2,
441
- L: 322,
442
- S: void 0,
443
- C: (f, a) => f(...a)
444
- });
445
- }
446
- }
447
- }
448
- return recurse(value);
449
- });
450
- };
451
- var isV3_1 = (document2) => {
452
- return document2.openapi === "3.0.1";
453
- };
454
-
455
- // packages/plugins/plugin-assistant/src/components/Toolbox/Toolbox.tsx
456
- var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-assistant/src/components/Toolbox/Toolbox.tsx";
457
- var Toolbox = ({ classNames, artifacts, functions, services, striped }) => {
458
- return /* @__PURE__ */ React.createElement("div", {
459
- className: mx("flex flex-col overflow-y-auto box-content", classNames)
460
- }, artifacts && artifacts.length > 0 && /* @__PURE__ */ React.createElement(Section, {
461
- title: "Artifacts",
462
- items: artifacts.map(({ name, description, tools }) => ({
463
- name,
464
- description,
465
- subitems: tools.map(({ name: name2, description: description2 }) => ({
466
- name: `\u2219 ${parseToolName(name2)}`,
467
- description: description2
468
- }))
469
- }))
470
- }), services && services.length > 0 && /* @__PURE__ */ React.createElement(Section, {
471
- title: "Services",
472
- items: services.map(({ service: { serviceId, name, description }, tools }) => ({
473
- name: name ?? serviceId,
474
- description,
475
- subitems: tools.map(({ name: name2, description: description2 }) => ({
476
- name: `\u2219 ${name2}`,
477
- description: description2
478
- }))
479
- }))
480
- }), functions && functions.length > 0 && /* @__PURE__ */ React.createElement(Section, {
481
- title: "Functions",
482
- items: functions.map(({ name, description }) => ({
483
- name,
484
- description
485
- }))
486
- }));
487
- };
488
- var Section = ({ title, items, striped }) => {
489
- const stripeClassNames = "odd:bg-neutral-50 dark:odd:bg-neutral-800";
490
- const gridClassNames = "grid grid-cols-[8rem_1fr]";
491
- const subGridClassNames = mx("col-span-full grid grid-cols-subgrid text-xs px-2", striped && stripeClassNames);
492
- return /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement("h1", {
493
- className: "px-2 text-sm"
494
- }, title), /* @__PURE__ */ React.createElement("div", {
495
- className: gridClassNames
496
- }, items.map(({ name, description, subitems }, i) => /* @__PURE__ */ React.createElement(Fragment, {
497
- key: i
498
- }, name && /* @__PURE__ */ React.createElement("div", {
499
- className: subGridClassNames
500
- }, /* @__PURE__ */ React.createElement("div", {
501
- className: "truncate text-primary-500"
502
- }, name), /* @__PURE__ */ React.createElement("div", {
503
- className: "line-clamp-2"
504
- }, description)), subitems?.map(({ name: name2, description: description2 }, i2) => /* @__PURE__ */ React.createElement("div", {
505
- key: i2,
506
- className: mx(subGridClassNames, striped && stripeClassNames)
507
- }, /* @__PURE__ */ React.createElement("div", {
508
- className: "truncate"
509
- }, name2), /* @__PURE__ */ React.createElement("div", {
510
- className: "line-clamp-3 text-subdued"
511
- }, description2)))))));
512
- };
513
- var ToolboxContainer = ({ classNames, space }) => {
514
- const artifactDefinitions = useCapabilities(Capabilities.ArtifactDefinition);
515
- const services = useQuery(space, Filter.type(ServiceType));
516
- const [serviceTools, setServiceTools] = useState([]);
517
- useEffect(() => {
518
- log3("creating service tools...", {
519
- services: services.length
520
- }, {
521
- F: __dxlog_file3,
522
- L: 99,
523
- S: void 0,
524
- C: (f, a) => f(...a)
525
- });
526
- queueMicrotask(async () => {
527
- const tools = await Promise.all(services.map(async (service) => ({
528
- service,
529
- tools: await createToolsFromService(service)
530
- })));
531
- setServiceTools(tools);
532
- });
533
- }, [
534
- services
535
- ]);
536
- const functions = useQuery(space, Filter.type(FunctionType));
537
- return /* @__PURE__ */ React.createElement(Toolbox, {
538
- classNames,
539
- artifacts: artifactDefinitions,
540
- services: serviceTools,
541
- functions
542
- });
543
- };
544
-
545
- // packages/plugins/plugin-assistant/src/components/Thread/Thread.tsx
546
- import React6, { useCallback, useMemo as useMemo2, useRef as useRef3 } from "react";
547
- import { useIdentity } from "@dxos/react-client/halo";
548
- import { ScrollContainer } from "@dxos/react-ui-components";
549
- import { mx as mx5 } from "@dxos/react-ui-theme";
550
- import { keyToFallback } from "@dxos/util";
551
-
552
- // packages/plugins/plugin-assistant/src/components/Thread/ThreadMessage.tsx
553
- import React3 from "react";
554
- import { invariant as invariant2 } from "@dxos/invariant";
555
- import { Button, Icon, IconButton } from "@dxos/react-ui";
556
- import { MarkdownViewer, ToggleContainer as NativeToggleContainer } from "@dxos/react-ui-components";
557
- import { Json as Json2 } from "@dxos/react-ui-syntax-highlighter";
558
- import { mx as mx2 } from "@dxos/react-ui-theme";
559
- import { safeParseJson } from "@dxos/util";
560
-
561
- // packages/plugins/plugin-assistant/src/components/Thread/ToolInvocations.tsx
562
- import React2, { useEffect as useEffect2, useMemo, useRef, useState as useState2 } from "react";
563
- import { log as log4 } from "@dxos/log";
564
- import { NumericTabs, StatusRoll, ToggleContainer } from "@dxos/react-ui-components";
565
- import { Json } from "@dxos/react-ui-syntax-highlighter";
566
- import { isNonNullable, isNotFalsy } from "@dxos/util";
567
- var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-assistant/src/components/Thread/ToolInvocations.tsx";
568
- var isToolMessage = (message) => {
569
- return message.content.some((block) => block.type === "tool_use" || block.type === "tool_result");
570
- };
571
- var getToolName2 = (tool) => {
572
- return tool.namespace && tool.function ? `${tool.namespace}:${tool.function}` : tool.name.split("_").pop();
573
- };
574
- var getToolCaption = (tool) => {
575
- if (!tool) {
576
- return "Calling tool...";
577
- }
578
- return tool.caption ?? `Calling ${getToolName2(tool)}...`;
579
- };
580
- var ToolBlock = ({ classNames, message, tools }) => {
581
- const { content = [] } = message;
582
- let request;
583
- const blocks = content.filter((block) => block.type === "tool_use" || block.type === "tool_result");
584
- const items = blocks.map((block) => {
585
- switch (block.type) {
586
- case "tool_use": {
587
- if (block.pending && request?.block.id === block.id) {
588
- return null;
589
- }
590
- request = {
591
- tool: tools?.find((tool) => tool.name === block.name),
592
- block
593
- };
594
- return {
595
- title: getToolCaption(request.tool),
596
- block
597
- };
598
- }
599
- case "tool_result": {
600
- if (!request) {
601
- log4.warn("unexpected message", {
602
- block
603
- }, {
604
- F: __dxlog_file4,
605
- L: 52,
606
- S: void 0,
607
- C: (f, a) => f(...a)
608
- });
609
- return {
610
- title: "Error",
611
- block
612
- };
613
- }
614
- return {
615
- title: `${getToolCaption(request.tool)} (Success)`,
616
- block
617
- };
618
- }
619
- default: {
620
- request = void 0;
621
- return {
622
- title: "Error",
623
- block
624
- };
610
+ Schema.validateSync(JsonSchemaType)(inputSchema);
611
+ const description = methodItem.description ?? methodItem.summary;
612
+ if (!description) {
613
+ log2.warn("no description", {
614
+ path,
615
+ method
616
+ }, {
617
+ F: __dxlog_file2,
618
+ L: 93,
619
+ S: void 0,
620
+ C: (f, a) => f(...a)
621
+ });
622
+ continue;
625
623
  }
626
- }
627
- }).filter(isNonNullable);
628
- return /* @__PURE__ */ React2.createElement(ToolContainer, {
629
- classNames,
630
- items
631
- });
632
- };
633
- var ToolContainer = ({ classNames, items }) => {
634
- const tabsRef = useRef(null);
635
- const [selected, setSelected] = useState2(0);
636
- const [open, setOpen] = useState2(false);
637
- useEffect2(() => {
638
- if (open) {
639
- tabsRef.current?.focus();
640
- }
641
- }, [
642
- open
643
- ]);
644
- const handleSelect = (index) => {
645
- if (index === selected) {
646
- setOpen(false);
647
- } else {
648
- setSelected(index);
649
- }
650
- };
651
- const title = useMemo(() => {
652
- const lines = items.map((item) => item.title).filter(isNotFalsy);
653
- return /* @__PURE__ */ React2.createElement(StatusRoll, {
654
- key: "status-roll",
655
- lines,
656
- duration: 1e3,
657
- autoAdvance: true
658
- });
659
- }, [
660
- items
661
- ]);
662
- return /* @__PURE__ */ React2.createElement(ToggleContainer, {
663
- classNames: [
664
- "flex flex-col",
665
- classNames
666
- ],
667
- title,
668
- open,
669
- onChangeOpen: setOpen
670
- }, /* @__PURE__ */ React2.createElement("div", {
671
- className: "grid grid-cols-[32px_1fr]"
672
- }, /* @__PURE__ */ React2.createElement(NumericTabs, {
673
- ref: tabsRef,
674
- length: items.length,
675
- selected,
676
- onSelect: handleSelect
677
- }), /* @__PURE__ */ React2.createElement(Json, {
678
- data: items[selected].block,
679
- classNames: "!p-1 text-xs"
680
- })));
681
- };
624
+ const endpoint = {
625
+ document: spec,
626
+ path,
627
+ method,
628
+ parameters: endpointParameters,
629
+ authorization: options?.authorization
630
+ };
631
+ tools.push(
632
+ // TODO(burdon): Namespace?
633
+ createRawTool("openapi", {
634
+ name: getToolName(path, method, methodItem),
635
+ description: options?.instructions ? `${options.instructions}
682
636
 
683
- // packages/plugins/plugin-assistant/src/components/Thread/ThreadMessage.tsx
684
- var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-assistant/src/components/Thread/ThreadMessage.tsx";
685
- var panelClassNames = "flex flex-col w-full px-2 bg-groupSurface rounded-md";
686
- var userClassNames = "bg-[--user-fill] text-accentSurfaceText";
687
- var ToggleContainer2 = (props) => {
688
- return /* @__PURE__ */ React3.createElement(NativeToggleContainer, {
689
- ...props,
690
- classNames: mx2(panelClassNames, props.classNames)
691
- });
692
- };
693
- var MessageContainer = ({ children, classNames, user }) => {
694
- if (!children) {
695
- return null;
637
+ ${description}` : description,
638
+ parameters: inputSchema,
639
+ execute: async (input) => {
640
+ const response = await callApiEndpoint(endpoint, input);
641
+ return ToolResult2.Success(response);
642
+ }
643
+ })
644
+ );
645
+ }
696
646
  }
697
- return /* @__PURE__ */ React3.createElement("div", {
698
- role: "list-item",
699
- className: mx2("flex w-full", user && "justify-end", classNames)
700
- }, /* @__PURE__ */ React3.createElement("div", {
701
- className: mx2(user ? [
702
- "px-2 py-1 rounded-md",
703
- userClassNames
704
- ] : "w-full")
705
- }, children));
647
+ return tools;
706
648
  };
707
- var ThreadMessage = ({ classNames, space, message, tools, onPrompt }) => {
708
- const { role, content = [] } = message;
709
- if (isToolMessage(message)) {
710
- return /* @__PURE__ */ React3.createElement(MessageContainer, {
711
- classNames: mx2(classNames, "animate-[fadeIn_0.5s]")
712
- }, /* @__PURE__ */ React3.createElement(ToolBlock, {
713
- space,
714
- classNames: panelClassNames,
715
- message,
716
- tools
717
- }));
649
+ var getToolName = (path, method, methodItem) => {
650
+ if (methodItem.operationId) {
651
+ return methodItem.operationId;
718
652
  }
719
- return content.map((block, idx) => {
720
- if (block.type === "text" && block.text.replaceAll(/\s+/g, "").length === 0) {
721
- return null;
722
- }
723
- const Component = components[block.type] ?? components.default;
724
- return /* @__PURE__ */ React3.createElement(MessageContainer, {
725
- key: idx,
726
- classNames: mx2(classNames, "animate-[fadeIn_0.5s]"),
727
- user: block.type === "text" && role === "user"
728
- }, /* @__PURE__ */ React3.createElement(Component, {
729
- space,
730
- block,
731
- onPrompt
732
- }));
733
- });
734
- };
735
- var components = {
736
- //
737
- // Text
738
- //
739
- ["text"]: ({ block }) => {
740
- invariant2(block.type === "text", void 0, {
741
- F: __dxlog_file5,
742
- L: 90,
743
- S: void 0,
744
- A: [
745
- "block.type === 'text'",
746
- ""
747
- ]
748
- });
749
- const title = block.disposition ? titles[block.disposition] : void 0;
750
- if (!title) {
751
- return /* @__PURE__ */ React3.createElement(MarkdownViewer, {
752
- classNames: "[&>p]:animate-[fadeIn_0.5s]",
753
- content: block.text
754
- });
755
- }
756
- return /* @__PURE__ */ React3.createElement(ToggleContainer2, {
757
- // open={open}
758
- defaultOpen: systemDispositions.includes(block.disposition ?? "") && block.pending,
759
- title,
760
- icon: block.pending ? /* @__PURE__ */ React3.createElement(Icon, {
761
- icon: "ph--circle-notch--regular",
762
- classNames: "text-subdued ml-2 animate-spin",
763
- size: 4
764
- }) : void 0
765
- }, /* @__PURE__ */ React3.createElement(MarkdownViewer, {
766
- content: block.text,
767
- classNames: [
768
- "pbe-2",
769
- systemDispositions.includes(block.disposition ?? "") && "text-sm text-subdued"
770
- ]
771
- }));
772
- },
773
- //
774
- // JSON
775
- //
776
- ["json"]: ({ space, block, onPrompt }) => {
777
- invariant2(block.type === "json", void 0, {
778
- F: __dxlog_file5,
779
- L: 128,
780
- S: void 0,
781
- A: [
782
- "block.type === 'json'",
783
- ""
784
- ]
785
- });
786
- switch (block.disposition) {
787
- case "tool_list": {
788
- return /* @__PURE__ */ React3.createElement(ToggleContainer2, {
789
- title: titles[block.disposition],
790
- defaultOpen: true
791
- }, /* @__PURE__ */ React3.createElement(ToolboxContainer, {
792
- space,
793
- classNames: "pbe-2"
794
- }));
795
- }
796
- case "suggest": {
797
- const { text = "" } = safeParseJson(block.json ?? "{}") ?? {};
798
- return /* @__PURE__ */ React3.createElement(IconButton, {
799
- icon: "ph--lightning--regular",
800
- label: text,
801
- onClick: () => onPrompt?.(text)
802
- });
803
- }
804
- case "select": {
805
- const { options = [] } = safeParseJson(block.json ?? "{}") ?? {};
806
- return /* @__PURE__ */ React3.createElement("div", {
807
- className: "flex flex-wrap gap-1"
808
- }, options.map((option, idx) => /* @__PURE__ */ React3.createElement(Button, {
809
- classNames: "animate-[fadeIn_0.5s] rounded-2xl text-sm",
810
- key: option,
811
- onClick: () => onPrompt?.(option)
812
- }, option)));
813
- }
814
- default: {
815
- const title = block.disposition ? titles[block.disposition] : void 0;
816
- return /* @__PURE__ */ React3.createElement(ToggleContainer2, {
817
- title: title ?? "JSON"
818
- }, /* @__PURE__ */ React3.createElement(Json2, {
819
- data: safeParseJson(block.json ?? block),
820
- classNames: "!p-1 text-xs"
821
- }));
653
+ let name = `${method.toLowerCase()}_${path.replaceAll(/[{}/]/g, "_")}`;
654
+ while (name.length > MAX_TOOL_NAME_LENGTH) {
655
+ const lengthBefore = name.length;
656
+ for (const word of GENERIC_WORDS) {
657
+ if (name.includes(word)) {
658
+ name = name.replace(word, "");
659
+ break;
822
660
  }
823
661
  }
824
- },
825
- //
826
- // Default
827
- //
828
- default: ({ block }) => {
829
- let title = titles[block.type];
830
- if (block.type === "tool_use") {
831
- title = `Tool [${block.name}]`;
662
+ name = name.replaceAll("__", "_").replace(/_$/, "");
663
+ const lengthAfter = name.length;
664
+ if (lengthBefore === lengthAfter) {
665
+ break;
832
666
  }
833
- return /* @__PURE__ */ React3.createElement(ToggleContainer2, {
834
- title: title ?? "JSON"
835
- }, /* @__PURE__ */ React3.createElement(Json2, {
836
- data: block,
837
- classNames: "!p-1 text-xs"
838
- }));
839
667
  }
668
+ name = name.replaceAll("__", "_").replace(/_$/, "").replace(/^_/, "");
669
+ return name.slice(0, MAX_TOOL_NAME_LENGTH);
840
670
  };
841
- var titles = {
842
- ["cot"]: "Chain of thought",
843
- ["artifact"]: "Artifact",
844
- ["tool_use"]: "Tool request",
845
- ["tool_result"]: "Tool result",
846
- ["tool_list"]: "Tools",
847
- ["artifact-update"]: "Artifact(s) changed"
848
- };
849
- var systemDispositions = [
850
- "cot",
851
- "artifact-update"
671
+ var MAX_TOOL_NAME_LENGTH = 64;
672
+ var GENERIC_WORDS = [
673
+ "services",
674
+ "service",
675
+ "api",
676
+ "rest",
677
+ "endpoint",
678
+ "get",
679
+ "post",
680
+ "put",
681
+ "delete",
682
+ "patch",
683
+ "head",
684
+ "options",
685
+ "trace",
686
+ "service",
687
+ "api",
688
+ "endpoint"
852
689
  ];
853
-
854
- // packages/plugins/plugin-assistant/src/components/Thread/reducer.ts
855
- var messageReducer = ({ current, messages }, message) => {
856
- let i = 0;
857
- for (const block of message.content) {
858
- switch (block.type) {
859
- case "tool_use":
860
- case "tool_result": {
861
- if (current) {
862
- current.content.push(block);
863
- } else {
864
- current = {
865
- id: [
866
- message.id,
867
- i
868
- ].join("_"),
869
- role: message.role,
870
- content: [
871
- block
872
- ]
873
- };
874
- messages.push(current);
690
+ var callApiEndpoint = async (endpoint, input) => {
691
+ log2.info("endpoint", {
692
+ method: endpoint.method,
693
+ name: endpoint.path,
694
+ input
695
+ }, {
696
+ F: __dxlog_file2,
697
+ L: 180,
698
+ S: void 0,
699
+ C: (f, a) => f(...a)
700
+ });
701
+ let url = getEndpointUrl(endpoint);
702
+ const request = {
703
+ method: endpoint.method,
704
+ headers: {}
705
+ };
706
+ const query = new URLSearchParams();
707
+ let body;
708
+ for (const parameter of endpoint.parameters) {
709
+ if (input[parameter.name] === void 0) {
710
+ continue;
711
+ }
712
+ switch (parameter.in) {
713
+ case "header": {
714
+ if (parameter.example) {
715
+ request.headers[parameter.name] = parameter.default;
875
716
  }
876
717
  break;
877
718
  }
878
- case "text":
879
- default: {
880
- current = void 0;
881
- messages.push({
882
- id: [
883
- message.id,
884
- i
885
- ].join("_"),
886
- role: message.role,
887
- content: [
888
- block
889
- ]
890
- });
719
+ case "path": {
720
+ url = url.replace(`{${parameter.name}}`, encodeURIComponent(input[parameter.name]));
721
+ break;
722
+ }
723
+ case "body": {
724
+ const value = input[parameter.name];
725
+ const effectSchema = toEffectSchema2(parameter.schema);
726
+ Schema.validateSync(effectSchema)(value);
727
+ if (body) {
728
+ throw new Error(`Duplicate body parameter: ${parameter.name}`);
729
+ }
730
+ body = value;
731
+ break;
732
+ }
733
+ case "query": {
734
+ query.set(parameter.name, input[parameter.name]);
891
735
  break;
892
736
  }
893
737
  }
894
- i++;
895
738
  }
896
- return {
897
- current,
898
- messages
899
- };
900
- };
901
-
902
- // packages/plugins/plugin-assistant/src/components/Prompt/Prompt.tsx
903
- import { Prec as Prec2 } from "@codemirror/state";
904
- import React4, { forwardRef, useImperativeHandle } from "react";
905
- import { useThemeContext } from "@dxos/react-ui";
906
- import { createBasicExtensions, createThemeExtensions, keymap as keymap3, useTextEditor } from "@dxos/react-ui-editor";
907
- import { mx as mx3 } from "@dxos/react-ui-theme";
908
-
909
- // packages/plugins/plugin-assistant/src/components/Prompt/autocomplete.ts
910
- import { Prec } from "@codemirror/state";
911
- import { EditorView, Decoration, ViewPlugin, keymap, WidgetType } from "@codemirror/view";
912
- var createAutocompleteExtension = ({ onSubmit, onSuggest }) => {
913
- const suggestionPlugin = ViewPlugin.fromClass(class {
914
- constructor(view) {
915
- this._currentSuggestion = null;
916
- this._decorations = this.computeDecorations(view);
739
+ if (endpoint.authorization?.type === "api-key" && endpoint.authorization.placement.type === "authorization-header" || endpoint.authorization?.type === "oauth") {
740
+ request.headers.Authorization = await resolveAuthorization(endpoint.authorization);
741
+ } else if (endpoint.authorization?.type === "api-key" && endpoint.authorization.placement.type === "query") {
742
+ query.set(endpoint.authorization.placement.name, endpoint.authorization.key);
743
+ }
744
+ if (query.size > 0) {
745
+ url += `?${query.toString()}`;
746
+ }
747
+ if (body) {
748
+ request.body = JSON.stringify(body);
749
+ request.headers["Content-Type"] = "application/json";
750
+ }
751
+ log2.info("request", {
752
+ url,
753
+ request
754
+ }, {
755
+ F: __dxlog_file2,
756
+ L: 243,
757
+ S: void 0,
758
+ C: (f, a) => f(...a)
759
+ });
760
+ const response = await fetch(url, request);
761
+ log2.info("response", {
762
+ ok: response.ok,
763
+ status: response.status,
764
+ statusText: response.statusText
765
+ }, {
766
+ F: __dxlog_file2,
767
+ L: 246,
768
+ S: void 0,
769
+ C: (f, a) => f(...a)
770
+ });
771
+ if (response.ok) {
772
+ const contentType = response.headers.get("Content-Type");
773
+ if (contentType?.includes("application/json")) {
774
+ return await response.json();
775
+ } else {
776
+ return await response.text();
917
777
  }
918
- update(update) {
919
- if (update.docChanged || update.selectionSet) {
920
- this._decorations = this.computeDecorations(update.view);
778
+ } else {
779
+ if (response.headers.get("Content-Type")?.includes("application/json")) {
780
+ const responseBody = await response.text();
781
+ let error;
782
+ try {
783
+ error = JSON.parse(responseBody);
784
+ } catch {
785
+ error = responseBody;
921
786
  }
787
+ log2.error("error", {
788
+ error
789
+ }, {
790
+ F: __dxlog_file2,
791
+ L: 264,
792
+ S: void 0,
793
+ C: (f, a) => f(...a)
794
+ });
795
+ throw new Error(error.message);
796
+ } else {
797
+ const error = await response.text();
798
+ log2.error("error", {
799
+ error
800
+ }, {
801
+ F: __dxlog_file2,
802
+ L: 268,
803
+ S: void 0,
804
+ C: (f, a) => f(...a)
805
+ });
806
+ throw new Error(error);
922
807
  }
923
- computeDecorations(view) {
924
- const text = view.state.doc.toString();
925
- const suggestions = onSuggest?.(text) ?? [];
926
- if (!suggestions.length) {
927
- this._currentSuggestion = null;
928
- return Decoration.none;
929
- }
930
- this._currentSuggestion = suggestions[0];
931
- const suffix = this._currentSuggestion.slice(text.length);
932
- if (!suffix) {
933
- return Decoration.none;
934
- }
935
- return Decoration.set([
936
- Decoration.widget({
937
- widget: new InlineSuggestionWidget(suffix),
938
- side: 1
939
- }).range(view.state.doc.length)
940
- ]);
808
+ }
809
+ };
810
+ var getEndpointUrl = (endpoint) => {
811
+ let url = "";
812
+ if (isV3_1(endpoint.document) && endpoint.document.servers && endpoint.document.servers.length > 0) {
813
+ url = endpoint.document.servers[0].url;
814
+ } else {
815
+ invariant(!isV3_1(endpoint.document), void 0, {
816
+ F: __dxlog_file2,
817
+ L: 279,
818
+ S: void 0,
819
+ A: [
820
+ "!isV3_1(endpoint.document)",
821
+ ""
822
+ ]
823
+ });
824
+ url = `${endpoint.document.schemes?.[0] ?? "https"}://${endpoint.document.host}`;
825
+ }
826
+ if (!isV3_1(endpoint.document) && endpoint.document.basePath) {
827
+ url += endpoint.document.basePath;
828
+ }
829
+ url += endpoint.path;
830
+ return url;
831
+ };
832
+ var resolveAuthorization = async (authorization) => {
833
+ switch (authorization.type) {
834
+ case "api-key": {
835
+ invariant(authorization.placement.type === "authorization-header", void 0, {
836
+ F: __dxlog_file2,
837
+ L: 295,
838
+ S: void 0,
839
+ A: [
840
+ "authorization.placement.type === 'authorization-header'",
841
+ ""
842
+ ]
843
+ });
844
+ return `Bearer ${authorization.key}`;
941
845
  }
942
- completeSuggestion(view) {
943
- if (!this._currentSuggestion) {
944
- return false;
945
- }
946
- const text = view.state.doc.toString();
947
- const suffix = this._currentSuggestion.slice(text.length);
948
- if (!suffix) {
949
- return false;
950
- }
951
- view.dispatch({
952
- changes: {
953
- from: view.state.doc.length,
954
- insert: suffix
846
+ case "oauth": {
847
+ const response = await fetch(authorization.tokenUrl, {
848
+ method: "POST",
849
+ headers: {
850
+ "Content-Type": "application/x-www-form-urlencoded"
955
851
  },
956
- selection: {
957
- anchor: view.state.doc.length + suffix.length
958
- }
852
+ body: `grant_type=${authorization.grantType}&client_id=${authorization.clientId}&client_secret=${authorization.clientSecret}`
959
853
  });
960
- return true;
854
+ const data = await response.json();
855
+ return `Bearer ${data.access_token}`;
961
856
  }
962
- }, {
963
- decorations: (v) => v._decorations
964
- });
965
- return [
966
- suggestionPlugin,
967
- EditorView.theme({
968
- ".cm-inline-suggestion": {
969
- opacity: 0.4
970
- }
971
- }),
972
- // Accept the current suggestion.
973
- Prec.highest(keymap.of([
974
- {
975
- key: "Tab",
976
- preventDefault: true,
977
- run: (view) => {
978
- const plugin = view.plugin(suggestionPlugin);
979
- return plugin?.completeSuggestion(view) ?? false;
980
- }
981
- },
982
- {
983
- key: "ArrowRight",
984
- preventDefault: true,
985
- run: (view) => {
986
- if (view.state.selection.main.head !== view.state.doc.length) {
987
- return false;
988
- }
989
- const plugin = view.plugin(suggestionPlugin);
990
- return plugin?.completeSuggestion(view) ?? false;
991
- }
992
- },
993
- {
994
- key: "Enter",
995
- preventDefault: true,
996
- run: (view) => {
997
- const text = view.state.doc.toString().trim();
998
- if (text.length > 0 && onSubmit) {
999
- const reset = onSubmit(text);
1000
- if (reset) {
1001
- view.dispatch({
1002
- changes: {
1003
- from: 0,
1004
- to: view.state.doc.length,
1005
- insert: ""
1006
- }
1007
- });
1008
- }
1009
- }
1010
- return true;
1011
- }
1012
- },
1013
- {
1014
- key: "Shift-Enter",
1015
- preventDefault: true,
1016
- run: (view) => {
1017
- view.dispatch({
1018
- changes: {
1019
- from: view.state.selection.main.head,
1020
- insert: "\n"
1021
- },
1022
- selection: {
1023
- anchor: view.state.selection.main.head + 1,
1024
- head: view.state.selection.main.head + 1
1025
- }
1026
- });
1027
- return true;
1028
- }
1029
- },
1030
- {
1031
- key: "Escape",
1032
- preventDefault: true,
1033
- run: (view) => {
1034
- view.dispatch({
1035
- changes: {
1036
- from: 0,
1037
- to: view.state.doc.length,
1038
- insert: ""
1039
- }
857
+ default: {
858
+ throw new Error(`Unknown authorization type: ${authorization.type}`);
859
+ }
860
+ }
861
+ };
862
+ var resolveJsonSchema = (schema, base) => {
863
+ return deepMapValues(schema, (value, recurse) => {
864
+ if (typeof value === "object" && value !== null && "$ref" in value && typeof value.$ref === "string") {
865
+ if (value.$ref.startsWith("#")) {
866
+ const resolved = jsonpointer.get(base, value.$ref.slice(1));
867
+ if (resolved) {
868
+ return recurse(resolved);
869
+ } else {
870
+ log2.warn("unresolved", {
871
+ ref: value.$ref,
872
+ base
873
+ }, {
874
+ F: __dxlog_file2,
875
+ L: 328,
876
+ S: void 0,
877
+ C: (f, a) => f(...a)
1040
878
  });
1041
- return true;
1042
879
  }
1043
880
  }
1044
- ]))
1045
- ];
881
+ }
882
+ return recurse(value);
883
+ });
1046
884
  };
1047
- var InlineSuggestionWidget = class extends WidgetType {
1048
- constructor(suffix) {
1049
- super();
1050
- this.suffix = suffix;
885
+ var isV3_1 = (document2) => {
886
+ return document2.openapi === "3.0.1";
887
+ };
888
+
889
+ // packages/plugins/plugin-assistant/src/components/Toolbox/Toolbox.tsx
890
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-assistant/src/components/Toolbox/Toolbox.tsx";
891
+ var Toolbox = ({ classNames, artifacts, functions, services, striped }) => {
892
+ var _effect = _useSignals3();
893
+ try {
894
+ return /* @__PURE__ */ React3.createElement("div", {
895
+ className: mx3("flex flex-col overflow-y-auto box-content", classNames)
896
+ }, artifacts && artifacts.length > 0 && /* @__PURE__ */ React3.createElement(Section, {
897
+ title: "Artifacts",
898
+ items: artifacts.map(({ name, description, tools }) => ({
899
+ name,
900
+ description,
901
+ subitems: tools.map(({ name: name2, description: description2 }) => ({
902
+ name: `\u2219 ${parseToolName(name2)}`,
903
+ description: description2
904
+ }))
905
+ }))
906
+ }), services && services.length > 0 && /* @__PURE__ */ React3.createElement(Section, {
907
+ title: "Services",
908
+ items: services.map(({ service: { serviceId, name, description }, tools }) => ({
909
+ name: name ?? serviceId,
910
+ description,
911
+ subitems: tools.map(({ name: name2, description: description2 }) => ({
912
+ name: `\u2219 ${name2}`,
913
+ description: description2
914
+ }))
915
+ }))
916
+ }), functions && functions.length > 0 && /* @__PURE__ */ React3.createElement(Section, {
917
+ title: "Functions",
918
+ items: functions.map(({ name, description }) => ({
919
+ name,
920
+ description
921
+ }))
922
+ }));
923
+ } finally {
924
+ _effect.f();
1051
925
  }
1052
- toDOM() {
1053
- const span = document.createElement("span");
1054
- span.textContent = this.suffix;
1055
- span.className = "cm-inline-suggestion";
1056
- return span;
926
+ };
927
+ var Section = ({ title, items, striped }) => {
928
+ var _effect = _useSignals3();
929
+ try {
930
+ const stripeClassNames = "odd:bg-neutral-50 dark:odd:bg-neutral-800";
931
+ const gridClassNames = "grid grid-cols-[8rem_1fr]";
932
+ const subGridClassNames = mx3("col-span-full grid grid-cols-subgrid text-xs px-2", striped && stripeClassNames);
933
+ return /* @__PURE__ */ React3.createElement("div", null, /* @__PURE__ */ React3.createElement("h1", {
934
+ className: "px-2 text-sm"
935
+ }, title), /* @__PURE__ */ React3.createElement("div", {
936
+ className: gridClassNames
937
+ }, items.map(({ name, description, subitems }, i) => /* @__PURE__ */ React3.createElement(Fragment, {
938
+ key: i
939
+ }, name && /* @__PURE__ */ React3.createElement("div", {
940
+ className: subGridClassNames
941
+ }, /* @__PURE__ */ React3.createElement("div", {
942
+ className: "truncate text-primary-500"
943
+ }, name), /* @__PURE__ */ React3.createElement("div", {
944
+ className: "line-clamp-2"
945
+ }, description)), subitems?.map(({ name: name2, description: description2 }, i2) => /* @__PURE__ */ React3.createElement("div", {
946
+ key: i2,
947
+ className: mx3(subGridClassNames, striped && stripeClassNames)
948
+ }, /* @__PURE__ */ React3.createElement("div", {
949
+ className: "truncate"
950
+ }, name2), /* @__PURE__ */ React3.createElement("div", {
951
+ className: "line-clamp-3 text-subdued"
952
+ }, description2)))))));
953
+ } finally {
954
+ _effect.f();
1057
955
  }
1058
- eq(other) {
1059
- return other.suffix === this.suffix;
956
+ };
957
+ var ToolboxContainer = ({ classNames, space }) => {
958
+ var _effect = _useSignals3();
959
+ try {
960
+ const artifactDefinitions = useCapabilities(Capabilities.ArtifactDefinition);
961
+ const services = useQuery(space, Filter.type(ServiceType));
962
+ const [serviceTools, setServiceTools] = useState2([]);
963
+ useEffect(() => {
964
+ log3("creating service tools...", {
965
+ services: services.length
966
+ }, {
967
+ F: __dxlog_file3,
968
+ L: 100,
969
+ S: void 0,
970
+ C: (f, a) => f(...a)
971
+ });
972
+ queueMicrotask(async () => {
973
+ const tools = await Promise.all(services.map(async (service) => ({
974
+ service,
975
+ tools: await createToolsFromService(service)
976
+ })));
977
+ setServiceTools(tools);
978
+ });
979
+ }, [
980
+ services
981
+ ]);
982
+ const functions = useQuery(space, Filter.type(FunctionType));
983
+ return /* @__PURE__ */ React3.createElement(Toolbox, {
984
+ classNames,
985
+ artifacts: artifactDefinitions,
986
+ services: serviceTools,
987
+ functions
988
+ });
989
+ } finally {
990
+ _effect.f();
1060
991
  }
1061
992
  };
1062
993
 
1063
- // packages/plugins/plugin-assistant/src/components/Prompt/references.ts
1064
- import { autocompletion, completionKeymap } from "@codemirror/autocomplete";
1065
- import { RangeSet } from "@codemirror/state";
1066
- import { Decoration as Decoration2, EditorView as EditorView2, keymap as keymap2, ViewPlugin as ViewPlugin2, WidgetType as WidgetType2 } from "@codemirror/view";
1067
- import { Mutex } from "@dxos/async";
1068
- var promptReferences = ({ provider, debug = false, triggerCharacter = "@" }) => {
1069
- if (triggerCharacter.length !== 1) {
1070
- throw new Error("triggerCharacter must be a single character");
994
+ // packages/plugins/plugin-assistant/src/components/Thread/Thread.tsx
995
+ import { useSignals as _useSignals6 } from "@preact-signals/safe-react/tracking";
996
+ import React6, { useCallback, useMemo as useMemo2, useRef as useRef2 } from "react";
997
+ import { useIdentity } from "@dxos/react-client/halo";
998
+ import { ScrollContainer } from "@dxos/react-ui-components";
999
+ import { mx as mx5 } from "@dxos/react-ui-theme";
1000
+ import { keyToFallback } from "@dxos/util";
1001
+
1002
+ // packages/plugins/plugin-assistant/src/components/Thread/ThreadMessage.tsx
1003
+ import { useSignals as _useSignals5 } from "@preact-signals/safe-react/tracking";
1004
+ import React5 from "react";
1005
+ import { Surface } from "@dxos/app-framework";
1006
+ import { invariant as invariant2 } from "@dxos/invariant";
1007
+ import { Button, Icon as Icon2, IconButton as IconButton2 } from "@dxos/react-ui";
1008
+ import { MarkdownViewer, ToggleContainer as NativeToggleContainer } from "@dxos/react-ui-components";
1009
+ import { Json as Json2 } from "@dxos/react-ui-syntax-highlighter";
1010
+ import { mx as mx4 } from "@dxos/react-ui-theme";
1011
+ import { safeParseJson } from "@dxos/util";
1012
+
1013
+ // packages/plugins/plugin-assistant/src/components/Thread/ToolInvocations.tsx
1014
+ import { useSignals as _useSignals4 } from "@preact-signals/safe-react/tracking";
1015
+ import React4, { useEffect as useEffect2, useMemo, useRef, useState as useState3 } from "react";
1016
+ import { log as log4 } from "@dxos/log";
1017
+ import { NumericTabs, StatusRoll, ToggleContainer } from "@dxos/react-ui-components";
1018
+ import { Json } from "@dxos/react-ui-syntax-highlighter";
1019
+ import { isNonNullable as isNonNullable2, isNotFalsy } from "@dxos/util";
1020
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-assistant/src/components/Thread/ToolInvocations.tsx";
1021
+ var isToolMessage = (message) => {
1022
+ return message.content.some((block) => block.type === "tool_use" || block.type === "tool_result");
1023
+ };
1024
+ var getToolName2 = (tool) => {
1025
+ return tool.namespace && tool.function ? `${tool.namespace}:${tool.function}` : tool.name.split("_").pop();
1026
+ };
1027
+ var getToolCaption = (tool, status) => {
1028
+ if (!tool) {
1029
+ return "Calling tool...";
1071
1030
  }
1072
- const decorationField = ViewPlugin2.fromClass(class ReferenceView {
1073
- constructor(view) {
1074
- this._mutex = new Mutex();
1075
- this.decorations = Decoration2.set([]);
1076
- queueMicrotask(async () => {
1077
- const guard = await this._mutex.acquire();
1078
- try {
1079
- this.decorations = await this._computeDecorations(view);
1080
- } finally {
1081
- guard.release();
1082
- }
1083
- });
1084
- }
1085
- update(update) {
1086
- if (update.docChanged) {
1087
- queueMicrotask(async () => {
1088
- const guard = await this._mutex.acquire();
1089
- try {
1090
- this.decorations = await this._computeDecorations(update.view);
1091
- } finally {
1092
- guard.release();
1093
- }
1094
- });
1095
- }
1096
- }
1097
- async _computeDecorations(view) {
1098
- const text = view.state.doc.toString();
1099
- const references = text.matchAll(new RegExp(`${triggerCharacter}[a-zA-Z0-9@:]+\\s`, "g"));
1100
- const decorations = [];
1101
- for (const match of references) {
1102
- const reference = match[0];
1103
- const uri = reference.slice(1, -1);
1104
- const data = await provider.resolveReference({
1105
- uri
1106
- });
1107
- if (data) {
1108
- decorations.push(Decoration2.replace({
1109
- widget: new ReferenceWidget(data)
1110
- }).range(match.index, match.index + reference.length));
1111
- }
1112
- }
1113
- return Decoration2.set(decorations);
1114
- }
1115
- }, {
1116
- decorations: (v) => v.decorations,
1117
- provide: (plugin) => [
1118
- EditorView2.atomicRanges.of((view) => view.plugin(decorationField)?.decorations ?? RangeSet.empty)
1119
- ]
1120
- });
1121
- return [
1122
- decorationField,
1123
- EditorView2.theme({
1124
- ".cm-reference-pill": {
1125
- borderRadius: "0.25rem",
1126
- borderWidth: "1px",
1127
- marginRight: "0.25rem",
1128
- marginLeft: "0.25rem"
1129
- }
1130
- }),
1131
- autocompletion({
1132
- activateOnTyping: true,
1133
- override: [
1134
- async (context) => {
1135
- const match = context.matchBefore(new RegExp(`${triggerCharacter}[a-zA-Z0-9]+`));
1136
- if (!match || match?.to === match?.from) {
1031
+ return status?.message ?? tool.caption ?? `Calling ${getToolName2(tool)}...`;
1032
+ };
1033
+ var ToolBlock = ({ classNames, message, tools }) => {
1034
+ var _effect = _useSignals4();
1035
+ try {
1036
+ const { content = [] } = message;
1037
+ let request;
1038
+ const blocks = content.filter((block) => block.type === "tool_use" || block.type === "tool_result");
1039
+ const items = blocks.map((block) => {
1040
+ switch (block.type) {
1041
+ case "tool_use": {
1042
+ if (block.pending && request?.block.id === block.id) {
1137
1043
  return null;
1138
1044
  }
1139
- const query = match.text.slice(1);
1140
- const references = await provider.getReferences({
1141
- query
1045
+ log4.info("tool_use", {
1046
+ tool: request?.tool,
1047
+ status: block.currentStatus
1048
+ }, {
1049
+ F: __dxlog_file4,
1050
+ L: 46,
1051
+ S: void 0,
1052
+ C: (f, a) => f(...a)
1142
1053
  });
1054
+ request = {
1055
+ tool: tools?.find((tool) => tool.name === block.name),
1056
+ block
1057
+ };
1143
1058
  return {
1144
- from: match.from,
1145
- filter: false,
1146
- options: references.map((reference) => ({
1147
- label: reference.label,
1148
- apply: `${triggerCharacter}${reference.uri} `
1149
- }))
1059
+ title: getToolCaption(request.tool, block.currentStatus),
1060
+ block
1061
+ };
1062
+ }
1063
+ case "tool_result": {
1064
+ if (!request) {
1065
+ log4.warn("unexpected message", {
1066
+ block
1067
+ }, {
1068
+ F: __dxlog_file4,
1069
+ L: 54,
1070
+ S: void 0,
1071
+ C: (f, a) => f(...a)
1072
+ });
1073
+ return {
1074
+ title: "Error",
1075
+ block
1076
+ };
1077
+ }
1078
+ return {
1079
+ title: `${getToolCaption(request.tool, void 0)} (Success)`,
1080
+ block
1081
+ };
1082
+ }
1083
+ default: {
1084
+ request = void 0;
1085
+ return {
1086
+ title: "Error",
1087
+ block
1150
1088
  };
1151
1089
  }
1090
+ }
1091
+ }).filter(isNonNullable2);
1092
+ return /* @__PURE__ */ React4.createElement(ToolContainer, {
1093
+ classNames,
1094
+ items
1095
+ });
1096
+ } finally {
1097
+ _effect.f();
1098
+ }
1099
+ };
1100
+ var ToolContainer = ({ classNames, items }) => {
1101
+ var _effect = _useSignals4();
1102
+ try {
1103
+ const tabsRef = useRef(null);
1104
+ const [selected, setSelected] = useState3(0);
1105
+ const [open, setOpen] = useState3(false);
1106
+ useEffect2(() => {
1107
+ if (open) {
1108
+ tabsRef.current?.focus();
1109
+ }
1110
+ }, [
1111
+ open
1112
+ ]);
1113
+ const handleSelect = (index) => {
1114
+ if (index === selected) {
1115
+ setOpen(false);
1116
+ } else {
1117
+ setSelected(index);
1118
+ }
1119
+ };
1120
+ const title = useMemo(() => {
1121
+ const lines = items.map((item) => item.title).filter(isNotFalsy);
1122
+ return /* @__PURE__ */ React4.createElement(StatusRoll, {
1123
+ key: "status-roll",
1124
+ lines,
1125
+ duration: 1e3,
1126
+ autoAdvance: true
1127
+ });
1128
+ }, [
1129
+ items
1130
+ ]);
1131
+ return /* @__PURE__ */ React4.createElement(ToggleContainer, {
1132
+ classNames: [
1133
+ "flex flex-col",
1134
+ classNames
1152
1135
  ],
1153
- closeOnBlur: !debug,
1154
- tooltipClass: () => "shadow rounded",
1155
- aboveCursor: true
1156
- }),
1157
- keymap2.of(completionKeymap)
1158
- ];
1136
+ title,
1137
+ open,
1138
+ onChangeOpen: setOpen
1139
+ }, /* @__PURE__ */ React4.createElement("div", {
1140
+ className: "grid grid-cols-[32px_1fr]"
1141
+ }, /* @__PURE__ */ React4.createElement(NumericTabs, {
1142
+ ref: tabsRef,
1143
+ length: items.length,
1144
+ selected,
1145
+ onSelect: handleSelect
1146
+ }), /* @__PURE__ */ React4.createElement(Json, {
1147
+ data: items[selected].block,
1148
+ classNames: "!p-1 text-xs"
1149
+ })));
1150
+ } finally {
1151
+ _effect.f();
1152
+ }
1159
1153
  };
1160
- var ReferenceWidget = class extends WidgetType2 {
1161
- constructor(data) {
1162
- super();
1163
- this.data = data;
1154
+
1155
+ // packages/plugins/plugin-assistant/src/components/Thread/ThreadMessage.tsx
1156
+ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-assistant/src/components/Thread/ThreadMessage.tsx";
1157
+ var panelClassNames = "flex flex-col w-full px-2 bg-activeSurface rounded-md";
1158
+ var userClassNames = "bg-[--user-fill] text-accentSurfaceText";
1159
+ var ToggleContainer2 = (props) => {
1160
+ var _effect = _useSignals5();
1161
+ try {
1162
+ return /* @__PURE__ */ React5.createElement(NativeToggleContainer, {
1163
+ ...props,
1164
+ classNames: mx4(panelClassNames, props.classNames)
1165
+ });
1166
+ } finally {
1167
+ _effect.f();
1164
1168
  }
1165
- toDOM() {
1166
- const span = document.createElement("span");
1167
- span.textContent = `@ ${this.data.label}`;
1168
- span.className = "cm-reference-pill";
1169
- return span;
1169
+ };
1170
+ var MessageContainer = ({ children, classNames, user }) => {
1171
+ var _effect = _useSignals5();
1172
+ try {
1173
+ if (!children) {
1174
+ return null;
1175
+ }
1176
+ return /* @__PURE__ */ React5.createElement("div", {
1177
+ role: "list-item",
1178
+ className: mx4("flex w-full", user && "justify-end", classNames)
1179
+ }, /* @__PURE__ */ React5.createElement("div", {
1180
+ className: mx4(user ? [
1181
+ "px-2 py-1 rounded-md",
1182
+ userClassNames
1183
+ ] : "w-full")
1184
+ }, children));
1185
+ } finally {
1186
+ _effect.f();
1170
1187
  }
1171
- eq(other) {
1172
- return other.data.uri === this.data.uri;
1188
+ };
1189
+ var ThreadMessage = ({ classNames, space, message, tools, onPrompt, onAddToGraph }) => {
1190
+ var _effect = _useSignals5();
1191
+ try {
1192
+ const { role, content = [] } = message;
1193
+ if (isToolMessage(message)) {
1194
+ return /* @__PURE__ */ React5.createElement(MessageContainer, {
1195
+ classNames: mx4(classNames, "animate-[fadeIn_0.5s]")
1196
+ }, /* @__PURE__ */ React5.createElement(ToolBlock, {
1197
+ space,
1198
+ classNames: panelClassNames,
1199
+ message,
1200
+ tools
1201
+ }));
1202
+ }
1203
+ return content.map((block, idx) => {
1204
+ if (block.type === "text" && block.text.replaceAll(/\s+/g, "").length === 0) {
1205
+ return null;
1206
+ }
1207
+ const Component = components[block.type] ?? components.default;
1208
+ return /* @__PURE__ */ React5.createElement(MessageContainer, {
1209
+ key: idx,
1210
+ classNames: mx4(classNames, "animate-[fadeIn_0.5s]"),
1211
+ user: block.type === "text" && role === "user"
1212
+ }, /* @__PURE__ */ React5.createElement(Component, {
1213
+ space,
1214
+ block,
1215
+ onPrompt,
1216
+ onAddToGraph
1217
+ }));
1218
+ });
1219
+ } finally {
1220
+ _effect.f();
1173
1221
  }
1174
- ignoreEvent() {
1175
- return true;
1222
+ };
1223
+ var components = {
1224
+ //
1225
+ // Text
1226
+ //
1227
+ ["text"]: ({ block }) => {
1228
+ invariant2(block.type === "text", void 0, {
1229
+ F: __dxlog_file5,
1230
+ L: 105,
1231
+ S: void 0,
1232
+ A: [
1233
+ "block.type === 'text'",
1234
+ ""
1235
+ ]
1236
+ });
1237
+ const title = block.disposition ? titles[block.disposition] : void 0;
1238
+ if (!title) {
1239
+ return /* @__PURE__ */ React5.createElement(MarkdownViewer, {
1240
+ classNames: "[&>p]:animate-[fadeIn_0.5s]",
1241
+ content: block.text
1242
+ });
1243
+ }
1244
+ return /* @__PURE__ */ React5.createElement(ToggleContainer2, {
1245
+ // open={open}
1246
+ defaultOpen: systemDispositions.includes(block.disposition ?? "") && block.pending,
1247
+ title,
1248
+ icon: block.pending ? /* @__PURE__ */ React5.createElement(Icon2, {
1249
+ icon: "ph--circle-notch--regular",
1250
+ classNames: "text-subdued ml-2 animate-spin",
1251
+ size: 4
1252
+ }) : void 0
1253
+ }, /* @__PURE__ */ React5.createElement(MarkdownViewer, {
1254
+ content: block.text,
1255
+ classNames: [
1256
+ "pbe-2",
1257
+ systemDispositions.includes(block.disposition ?? "") && "text-sm text-subdued"
1258
+ ]
1259
+ }));
1260
+ },
1261
+ //
1262
+ // JSON
1263
+ //
1264
+ ["json"]: ({ space, block, onPrompt, onAddToGraph }) => {
1265
+ invariant2(block.type === "json", void 0, {
1266
+ F: __dxlog_file5,
1267
+ L: 143,
1268
+ S: void 0,
1269
+ A: [
1270
+ "block.type === 'json'",
1271
+ ""
1272
+ ]
1273
+ });
1274
+ switch (block.disposition) {
1275
+ case "tool_list": {
1276
+ return /* @__PURE__ */ React5.createElement(ToggleContainer2, {
1277
+ title: titles[block.disposition],
1278
+ defaultOpen: true
1279
+ }, /* @__PURE__ */ React5.createElement(ToolboxContainer, {
1280
+ space,
1281
+ classNames: "pbe-2"
1282
+ }));
1283
+ }
1284
+ case "suggest": {
1285
+ const { text = "" } = safeParseJson(block.json ?? "{}") ?? {};
1286
+ return /* @__PURE__ */ React5.createElement(IconButton2, {
1287
+ icon: "ph--lightning--regular",
1288
+ label: text,
1289
+ onClick: () => onPrompt?.(text)
1290
+ });
1291
+ }
1292
+ case "select": {
1293
+ const { options = [] } = safeParseJson(block.json ?? "{}") ?? {};
1294
+ return /* @__PURE__ */ React5.createElement("div", {
1295
+ className: "flex flex-wrap gap-1"
1296
+ }, options.map((option, idx) => /* @__PURE__ */ React5.createElement(Button, {
1297
+ classNames: "animate-[fadeIn_0.5s] rounded-2xl text-sm",
1298
+ key: option,
1299
+ onClick: () => onPrompt?.(option)
1300
+ }, option)));
1301
+ }
1302
+ case "graph": {
1303
+ return /* @__PURE__ */ React5.createElement("div", {
1304
+ className: "flex flex-wrap gap-1"
1305
+ }, /* @__PURE__ */ React5.createElement(Surface, {
1306
+ role: "card",
1307
+ data: {
1308
+ subject: JSON.parse(block.json ?? "{}")
1309
+ },
1310
+ limit: 1,
1311
+ fallback: /* @__PURE__ */ React5.createElement("div", {
1312
+ className: "font-mono text-xs text-pre"
1313
+ }, block.json)
1314
+ }), onAddToGraph && /* @__PURE__ */ React5.createElement(IconButton2, {
1315
+ icon: "ph--plus--regular",
1316
+ label: "Add to graph",
1317
+ onClick: () => onAddToGraph?.(JSON.parse(block.json ?? "{}"))
1318
+ }));
1319
+ }
1320
+ default: {
1321
+ const title = block.disposition ? titles[block.disposition] : void 0;
1322
+ return /* @__PURE__ */ React5.createElement(ToggleContainer2, {
1323
+ title: title ?? "JSON"
1324
+ }, /* @__PURE__ */ React5.createElement(Json2, {
1325
+ data: safeParseJson(block.json ?? block),
1326
+ classNames: "!p-1 text-xs"
1327
+ }));
1328
+ }
1329
+ }
1330
+ },
1331
+ //
1332
+ // Default
1333
+ //
1334
+ default: ({ block }) => {
1335
+ let title = titles[block.type];
1336
+ if (block.type === "tool_use") {
1337
+ title = `Tool [${block.name}]`;
1338
+ }
1339
+ return /* @__PURE__ */ React5.createElement(ToggleContainer2, {
1340
+ title: title ?? "JSON"
1341
+ }, /* @__PURE__ */ React5.createElement(Json2, {
1342
+ data: block,
1343
+ classNames: "!p-1 text-xs"
1344
+ }));
1176
1345
  }
1177
1346
  };
1347
+ var titles = {
1348
+ ["cot"]: "Chain of thought",
1349
+ ["artifact"]: "Artifact",
1350
+ ["tool_use"]: "Tool request",
1351
+ ["tool_result"]: "Tool result",
1352
+ ["tool_list"]: "Tools",
1353
+ ["artifact-update"]: "Artifact(s) changed"
1354
+ };
1355
+ var systemDispositions = [
1356
+ "cot",
1357
+ "artifact-update"
1358
+ ];
1178
1359
 
1179
- // packages/plugins/plugin-assistant/src/components/Prompt/Prompt.tsx
1180
- var Prompt = /* @__PURE__ */ forwardRef(({ classNames, autoFocus, lineWrapping = false, placeholder, onSubmit, onSuggest, onOpenChange, references }, forwardRef2) => {
1181
- const { themeMode } = useThemeContext();
1182
- const { parentRef, view } = useTextEditor({
1183
- debug: true,
1184
- autoFocus,
1185
- extensions: [
1186
- createBasicExtensions({
1187
- bracketMatching: false,
1188
- lineWrapping,
1189
- placeholder
1190
- }),
1191
- createThemeExtensions({
1192
- themeMode
1193
- }),
1194
- references ? promptReferences({
1195
- provider: references
1196
- }) : [],
1197
- createAutocompleteExtension({
1198
- onSubmit,
1199
- onSuggest
1200
- }),
1201
- Prec2.highest(keymap3.of([
1202
- {
1203
- key: "cmd-ArrowUp",
1204
- preventDefault: true,
1205
- run: (view2) => {
1206
- onOpenChange?.(true);
1207
- return true;
1208
- }
1209
- },
1210
- {
1211
- key: "cmd-ArrowDown",
1212
- preventDefault: true,
1213
- run: (view2) => {
1214
- onOpenChange?.(false);
1215
- return true;
1216
- }
1360
+ // packages/plugins/plugin-assistant/src/components/Thread/reducer.ts
1361
+ var messageReducer = ({ current, messages }, message) => {
1362
+ let i = 0;
1363
+ for (const block of message.content) {
1364
+ switch (block.type) {
1365
+ case "tool_use":
1366
+ case "tool_result": {
1367
+ if (current) {
1368
+ current.content.push(block);
1369
+ } else {
1370
+ current = {
1371
+ id: [
1372
+ message.id,
1373
+ i
1374
+ ].join("_"),
1375
+ role: message.role,
1376
+ content: [
1377
+ block
1378
+ ]
1379
+ };
1380
+ messages.push(current);
1217
1381
  }
1218
- ]))
1219
- ]
1220
- }, [
1221
- themeMode,
1222
- onSubmit,
1223
- onSuggest
1224
- ]);
1225
- useImperativeHandle(forwardRef2, () => {
1226
- return {
1227
- focus: () => {
1228
- view?.focus();
1229
- },
1230
- setText: (text) => {
1231
- view?.dispatch({
1232
- changes: {
1233
- from: 0,
1234
- to: view.state.doc.length,
1235
- insert: text
1236
- },
1237
- selection: {
1238
- anchor: text.length,
1239
- head: text.length
1240
- }
1382
+ break;
1383
+ }
1384
+ case "text":
1385
+ default: {
1386
+ current = void 0;
1387
+ messages.push({
1388
+ id: [
1389
+ message.id,
1390
+ i
1391
+ ].join("_"),
1392
+ role: message.role,
1393
+ content: [
1394
+ block
1395
+ ]
1241
1396
  });
1397
+ break;
1242
1398
  }
1243
- };
1244
- }, [
1245
- view,
1246
- onSubmit
1247
- ]);
1248
- return /* @__PURE__ */ React4.createElement("div", {
1249
- ref: parentRef,
1250
- className: mx3("w-full", classNames)
1251
- });
1252
- });
1253
-
1254
- // packages/plugins/plugin-assistant/src/components/Prompt/PromptBar.tsx
1255
- import React5, { useRef as useRef2, useState as useState3 } from "react";
1256
- import { useVoiceInput } from "@dxos/plugin-transcription";
1257
- import { Icon as Icon2, IconButton as IconButton2, Tooltip, useTranslation } from "@dxos/react-ui";
1258
- import { Spinner } from "@dxos/react-ui-sfx";
1259
- import { errorText, mx as mx4 } from "@dxos/react-ui-theme";
1260
- var PromptBar = ({ classNames, placeholder, processing, error, microphone, onCancel, references, ...props }) => {
1261
- const { t } = useTranslation(ASSISTANT_PLUGIN);
1262
- const promptRef = useRef2(null);
1263
- const [active, setActive] = useState3(false);
1264
- const { recording } = useVoiceInput({
1265
- active,
1266
- onUpdate: (text) => {
1267
- promptRef.current?.setText(text);
1268
- promptRef.current?.focus();
1269
1399
  }
1270
- });
1271
- return /* @__PURE__ */ React5.createElement("div", {
1272
- className: mx4("shrink-0 w-full grid grid-cols-[var(--rail-action)_1fr_var(--rail-action)] overflow-hidden", classNames)
1273
- }, /* @__PURE__ */ React5.createElement("div", {
1274
- className: "flex w-[--rail-action] h-[--rail-action] items-center justify-center"
1275
- }, error && /* @__PURE__ */ React5.createElement(Tooltip.Trigger, {
1276
- content: error.message,
1277
- delayDuration: 0
1278
- }, /* @__PURE__ */ React5.createElement(Icon2, {
1279
- icon: "ph--warning-circle--regular",
1280
- classNames: errorText,
1281
- size: 5
1282
- })) || /* @__PURE__ */ React5.createElement(Spinner, {
1283
- active: processing
1284
- })), /* @__PURE__ */ React5.createElement(Prompt, {
1285
- ref: promptRef,
1286
- autoFocus: true,
1287
- classNames: "pbs-2",
1288
- lineWrapping: true,
1289
- placeholder: placeholder ?? t("prompt placeholder"),
1290
- references,
1291
- ...props
1292
- }), (onCancel || microphone) && /* @__PURE__ */ React5.createElement("div", {
1293
- className: "flex w-[--rail-action] h-[--rail-action] items-center justify-center"
1294
- }, processing && onCancel && /* @__PURE__ */ React5.createElement(IconButton2, {
1295
- classNames: "px-1.5",
1296
- variant: "ghost",
1297
- size: 5,
1298
- icon: "ph--x--regular",
1299
- iconOnly: true,
1300
- label: t("cancel processing button"),
1301
- onClick: onCancel
1302
- }), !processing && microphone && /* @__PURE__ */ React5.createElement(IconButton2, {
1303
- classNames: mx4("px-1.5", recording && "bg-primary-500"),
1304
- variant: "ghost",
1305
- size: 5,
1306
- icon: "ph--microphone--regular",
1307
- iconOnly: true,
1308
- noTooltip: true,
1309
- label: t("microphone button"),
1310
- onMouseDown: () => setActive(true),
1311
- onMouseUp: () => setActive(false),
1312
- onTouchStart: () => setActive(true),
1313
- onTouchEnd: () => setActive(false)
1314
- })));
1400
+ i++;
1401
+ }
1402
+ return {
1403
+ current,
1404
+ messages
1405
+ };
1315
1406
  };
1316
1407
 
1317
1408
  // packages/plugins/plugin-assistant/src/components/Thread/Thread.tsx
1318
1409
  var Thread = ({ classNames, space, messages, collapse = true, transcription, processing, error, onSubmit, onCancel, onOpenChange, contextProvider, ...props }) => {
1319
- const scroller = useRef3(null);
1320
- const identity = useIdentity();
1321
- const fallbackValue = keyToFallback(identity.identityKey);
1322
- const userHue = identity.profile?.data?.hue || fallbackValue.hue;
1323
- const handleSubmit = useCallback((value) => {
1324
- onSubmit?.(value);
1325
- scroller.current?.scrollToBottom();
1326
- return true;
1327
- }, [
1328
- onSubmit
1329
- ]);
1330
- const { messages: filteredMessages = [] } = useMemo2(() => {
1331
- if (collapse) {
1332
- return (messages ?? []).reduce(messageReducer, {
1333
- messages: []
1334
- });
1335
- } else {
1410
+ var _effect = _useSignals6();
1411
+ try {
1412
+ const scroller = useRef2(null);
1413
+ const identity = useIdentity();
1414
+ const fallbackValue = keyToFallback(identity.identityKey);
1415
+ const userHue = identity.profile?.data?.hue || fallbackValue.hue;
1416
+ const handleSubmit = useCallback((value) => {
1417
+ onSubmit?.(value);
1418
+ scroller.current?.scrollToBottom();
1419
+ return true;
1420
+ }, [
1421
+ onSubmit
1422
+ ]);
1423
+ const { messages: filteredMessages = [] } = useMemo2(() => {
1424
+ if (collapse) {
1425
+ return (messages ?? []).reduce(messageReducer, {
1426
+ messages: []
1427
+ });
1428
+ } else {
1429
+ return {
1430
+ messages: messages ?? []
1431
+ };
1432
+ }
1433
+ }, [
1434
+ messages,
1435
+ collapse
1436
+ ]);
1437
+ const references = useMemo2(() => {
1438
+ if (!contextProvider) {
1439
+ return void 0;
1440
+ }
1336
1441
  return {
1337
- messages: messages ?? []
1442
+ getReferences: async ({ query }) => contextProvider.query({
1443
+ query
1444
+ }),
1445
+ resolveReference: async ({ uri }) => contextProvider.resolveMetadata({
1446
+ uri
1447
+ })
1338
1448
  };
1339
- }
1340
- }, [
1341
- messages,
1342
- collapse
1343
- ]);
1344
- const references = useMemo2(() => {
1345
- if (!contextProvider) {
1346
- return void 0;
1347
- }
1348
- return {
1349
- getReferences: async ({ query }) => contextProvider.query({
1350
- query
1351
- }),
1352
- resolveReference: async ({ uri }) => contextProvider.resolveMetadata({
1353
- uri
1354
- })
1355
- };
1356
- }, [
1357
- contextProvider
1358
- ]);
1359
- return /* @__PURE__ */ React6.createElement("div", {
1360
- role: "none",
1361
- className: mx5("flex flex-col grow overflow-hidden", classNames)
1362
- }, /* @__PURE__ */ React6.createElement(ScrollContainer, {
1363
- ref: scroller,
1364
- fade: true
1365
- }, /* @__PURE__ */ React6.createElement("div", {
1366
- role: "none",
1367
- className: mx5(filteredMessages.length > 0 && "pbs-6 pbe-6"),
1368
- style: {
1369
- "--user-fill": `var(--dx-${userHue}Fill)`
1370
- }
1371
- }, filteredMessages.map((message) => /* @__PURE__ */ React6.createElement(ThreadMessage, {
1372
- key: message.id,
1373
- classNames: "px-4 pbe-4",
1374
- space,
1375
- message,
1376
- ...props
1377
- })))), onSubmit && /* @__PURE__ */ React6.createElement(PromptBar, {
1378
- microphone: transcription,
1379
- processing,
1380
- error,
1381
- onSubmit: handleSubmit,
1382
- onCancel,
1383
- onOpenChange,
1384
- references
1385
- }));
1449
+ }, [
1450
+ contextProvider
1451
+ ]);
1452
+ return /* @__PURE__ */ React6.createElement("div", {
1453
+ role: "none",
1454
+ className: mx5("flex flex-col grow overflow-hidden", classNames)
1455
+ }, /* @__PURE__ */ React6.createElement(ScrollContainer, {
1456
+ ref: scroller,
1457
+ fade: true
1458
+ }, /* @__PURE__ */ React6.createElement("div", {
1459
+ role: "none",
1460
+ className: mx5(filteredMessages.length > 0 && "pbs-6 pbe-6"),
1461
+ style: {
1462
+ "--user-fill": `var(--dx-${userHue}Fill)`
1463
+ }
1464
+ }, filteredMessages.map((message) => /* @__PURE__ */ React6.createElement(ThreadMessage, {
1465
+ key: message.id,
1466
+ classNames: "px-4 pbe-4",
1467
+ space,
1468
+ message,
1469
+ ...props
1470
+ })))), onSubmit && /* @__PURE__ */ React6.createElement(PromptBar, {
1471
+ microphone: transcription,
1472
+ processing,
1473
+ error,
1474
+ onSubmit: handleSubmit,
1475
+ onCancel,
1476
+ onOpenChange,
1477
+ references
1478
+ }));
1479
+ } finally {
1480
+ _effect.f();
1481
+ }
1386
1482
  };
1387
1483
 
1388
1484
  // packages/plugins/plugin-assistant/src/components/Thread/ThreadContainer.tsx
1485
+ import { useSignals as _useSignals9 } from "@preact-signals/safe-react/tracking";
1389
1486
  import React7, { useCallback as useCallback3, useEffect as useEffect5 } from "react";
1390
1487
  import { CollaborationActions, createIntent, useIntentDispatcher as useIntentDispatcher2 } from "@dxos/app-framework";
1391
1488
  import { invariant as invariant4 } from "@dxos/invariant";
1392
1489
  import { DXN } from "@dxos/keys";
1393
- import { makeRef, refFromDXN } from "@dxos/live-object";
1490
+ import { refFromDXN } from "@dxos/live-object";
1394
1491
  import { log as log8 } from "@dxos/log";
1395
1492
  import { getSpace as getSpace2 } from "@dxos/react-client/echo";
1396
1493
 
1397
1494
  // packages/plugins/plugin-assistant/src/hooks/processor.ts
1398
1495
  import { batch, computed, signal } from "@preact/signals-core";
1399
- import { AISession, DEFAULT_EDGE_MODEL } from "@dxos/assistant";
1496
+ import { DEFAULT_EDGE_MODEL } from "@dxos/ai";
1497
+ import { AISession } from "@dxos/assistant";
1400
1498
  import { invariant as invariant3 } from "@dxos/invariant";
1401
1499
  import { log as log5 } from "@dxos/log";
1402
- import { getVersion } from "@dxos/react-client/echo";
1500
+ import { Filter as Filter2, getVersion } from "@dxos/react-client/echo";
1403
1501
  var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-assistant/src/hooks/processor.ts";
1404
1502
  var defaultOptions = {
1405
1503
  model: DEFAULT_EDGE_MODEL,
@@ -1424,7 +1522,7 @@ var ChatProcessor = class {
1424
1522
  const current = messages.pop();
1425
1523
  invariant3(current, void 0, {
1426
1524
  F: __dxlog_file6,
1427
- L: 70,
1525
+ L: 79,
1428
1526
  S: this,
1429
1527
  A: [
1430
1528
  "current",
@@ -1443,6 +1541,24 @@ var ChatProcessor = class {
1443
1541
  }
1444
1542
  return messages;
1445
1543
  });
1544
+ this._artifactDiffResolver = async (artifacts) => {
1545
+ const space = this._extensions?.space;
1546
+ if (!space) {
1547
+ return /* @__PURE__ */ new Map();
1548
+ }
1549
+ const versions = /* @__PURE__ */ new Map();
1550
+ await Promise.all(artifacts.map(async (artifact) => {
1551
+ const { objects: [object] } = await space.db.query(Filter2.ids(artifact.id)).run();
1552
+ if (!object) {
1553
+ return;
1554
+ }
1555
+ versions.set(artifact.id, {
1556
+ version: getVersion(object),
1557
+ diff: `Current state: ${JSON.stringify(object)}`
1558
+ });
1559
+ }));
1560
+ return versions;
1561
+ };
1446
1562
  }
1447
1563
  get tools() {
1448
1564
  return this._tools;
@@ -1480,6 +1596,35 @@ var ChatProcessor = class {
1480
1596
  message2
1481
1597
  ];
1482
1598
  });
1599
+ this._session.toolStatusReport.on(({ message: message2, status }) => {
1600
+ const msg = this._pending.peek().find((m) => m.id === message2.id);
1601
+ const toolUse = msg?.content.find((block2) => block2.type === "tool_use");
1602
+ if (!toolUse) {
1603
+ return;
1604
+ }
1605
+ const block = msg?.content.find((block2) => block2.type === "tool_use" && block2.id === toolUse.id);
1606
+ if (block) {
1607
+ this._pending.value = this._pending.value.map((m) => {
1608
+ if (m.id === message2.id) {
1609
+ return {
1610
+ ...m,
1611
+ content: m.content.map((b) => b.type === "tool_use" && b.id === toolUse.id ? {
1612
+ ...b,
1613
+ currentStatus: status
1614
+ } : b)
1615
+ };
1616
+ }
1617
+ return m;
1618
+ });
1619
+ } else {
1620
+ log5.warn("no block for status report", void 0, {
1621
+ F: __dxlog_file6,
1622
+ L: 155,
1623
+ S: this,
1624
+ C: (f, a) => f(...a)
1625
+ });
1626
+ }
1627
+ });
1483
1628
  try {
1484
1629
  const messages = await this._session.run({
1485
1630
  client: this._ai,
@@ -1490,26 +1635,7 @@ var ChatProcessor = class {
1490
1635
  prompt: message,
1491
1636
  systemPrompt: this._options.systemPrompt,
1492
1637
  extensions: this._extensions,
1493
- artifactDiffResolver: async (artifacts) => {
1494
- const space = this._extensions?.space;
1495
- if (!space) {
1496
- return /* @__PURE__ */ new Map();
1497
- }
1498
- const versions = /* @__PURE__ */ new Map();
1499
- await Promise.all(artifacts.map(async (artifact) => {
1500
- const { objects: [object] } = await space.db.query({
1501
- id: artifact.id
1502
- }).run();
1503
- if (!object) {
1504
- return;
1505
- }
1506
- versions.set(artifact.id, {
1507
- version: getVersion(object),
1508
- diff: `Current state: ${JSON.stringify(object)}`
1509
- });
1510
- }));
1511
- return versions;
1512
- },
1638
+ artifactDiffResolver: this._artifactDiffResolver,
1513
1639
  generationOptions: {
1514
1640
  model: this._options.model
1515
1641
  }
@@ -1518,7 +1644,7 @@ var ChatProcessor = class {
1518
1644
  messages
1519
1645
  }, {
1520
1646
  F: __dxlog_file6,
1521
- L: 160,
1647
+ L: 175,
1522
1648
  S: this,
1523
1649
  C: (f, a) => f(...a)
1524
1650
  });
@@ -1526,7 +1652,7 @@ var ChatProcessor = class {
1526
1652
  } catch (err) {
1527
1653
  log5.catch(err, void 0, {
1528
1654
  F: __dxlog_file6,
1529
- L: 163,
1655
+ L: 178,
1530
1656
  S: this,
1531
1657
  C: (f, a) => f(...a)
1532
1658
  });
@@ -1551,7 +1677,7 @@ var ChatProcessor = class {
1551
1677
  async cancel() {
1552
1678
  log5.info("cancelling...", void 0, {
1553
1679
  F: __dxlog_file6,
1554
- L: 181,
1680
+ L: 196,
1555
1681
  S: this,
1556
1682
  C: (f, a) => f(...a)
1557
1683
  });
@@ -1575,23 +1701,24 @@ var AIServiceOverloadedError = class extends Error {
1575
1701
  };
1576
1702
 
1577
1703
  // packages/plugins/plugin-assistant/src/hooks/useChatProcessor.tsx
1704
+ import { useSignals as _useSignals7 } from "@preact-signals/safe-react/tracking";
1578
1705
  import { useEffect as useEffect3, useMemo as useMemo3, useState as useState4 } from "react";
1706
+ import { DEFAULT_EDGE_MODEL as DEFAULT_EDGE_MODEL2, DEFAULT_OLLAMA_MODEL } from "@dxos/ai";
1579
1707
  import { Capabilities as Capabilities2, useCapabilities as useCapabilities2, useCapability, useIntentDispatcher } from "@dxos/app-framework";
1580
1708
  import { createSystemPrompt } from "@dxos/artifact";
1581
- import { DEFAULT_EDGE_MODEL as DEFAULT_EDGE_MODEL2, DEFAULT_OLLAMA_MODEL } from "@dxos/assistant";
1582
1709
  import { FunctionType as FunctionType2 } from "@dxos/functions";
1583
1710
  import { log as log6 } from "@dxos/log";
1584
1711
  import { useConfig } from "@dxos/react-client";
1585
- import { Filter as Filter2, fullyQualifiedId, useQuery as useQuery2 } from "@dxos/react-client/echo";
1586
- import { isNonNullable as isNonNullable2 } from "@dxos/util";
1712
+ import { Filter as Filter3, fullyQualifiedId, useQuery as useQuery2 } from "@dxos/react-client/echo";
1713
+ import { isNonNullable as isNonNullable3 } from "@dxos/util";
1587
1714
 
1588
1715
  // packages/plugins/plugin-assistant/src/capabilities/index.ts
1589
1716
  import { lazy } from "@dxos/app-framework";
1590
- var AiClient = lazy(() => import("./ai-client-RZQWEDUX.mjs"));
1591
- var AppGraphBuilder = lazy(() => import("./app-graph-builder-WXJNZDYB.mjs"));
1592
- var IntentResolver = lazy(() => import("./intent-resolver-Q3I6S6HN.mjs"));
1593
- var ReactSurface = lazy(() => import("./react-surface-RI3JONQY.mjs"));
1594
- var Settings = lazy(() => import("./settings-CLE57WEP.mjs"));
1717
+ var AiClient = lazy(() => import("./ai-client-I5LXHMOZ.mjs"));
1718
+ var AppGraphBuilder = lazy(() => import("./app-graph-builder-Z3GMMJMD.mjs"));
1719
+ var IntentResolver = lazy(() => import("./intent-resolver-X3PWH7KM.mjs"));
1720
+ var ReactSurface = lazy(() => import("./react-surface-QMIQCXUM.mjs"));
1721
+ var Settings = lazy(() => import("./settings-IVQRZUCU.mjs"));
1595
1722
 
1596
1723
  // packages/plugins/plugin-assistant/src/hooks/useChatProcessor.tsx
1597
1724
  var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-assistant/src/hooks/useChatProcessor.tsx";
@@ -1603,92 +1730,97 @@ var useChatProcessor = ({
1603
1730
  part,
1604
1731
  associatedArtifact
1605
1732
  }) => {
1606
- const aiClient = useCapability(AssistantCapabilities.AiClient);
1607
- const globalTools = useCapabilities2(Capabilities2.Tools);
1608
- const artifactDefinitions = useCapabilities2(Capabilities2.ArtifactDefinition);
1609
- const { dispatchPromise: dispatch } = useIntentDispatcher();
1610
- const services = useQuery2(space, Filter2.type(ServiceType));
1611
- const [serviceTools, setServiceTools] = useState4([]);
1612
- useEffect3(() => {
1613
- log6("creating service tools...", void 0, {
1614
- F: __dxlog_file7,
1615
- L: 49,
1616
- S: void 0,
1617
- C: (f, a) => f(...a)
1618
- });
1619
- queueMicrotask(async () => {
1620
- const tools2 = await Promise.all(services.map((service) => createToolsFromService(service)));
1621
- setServiceTools(tools2.flat());
1622
- });
1623
- }, [
1624
- services
1625
- ]);
1626
- const config = useConfig();
1627
- const functions = useQuery2(space, Filter2.type(FunctionType2));
1628
- const chatId = useMemo3(() => chat ? fullyQualifiedId(chat) : void 0, [
1629
- chat
1630
- ]);
1631
- const [tools, extensions] = useMemo3(() => {
1632
- log6("creating tools...", void 0, {
1633
- F: __dxlog_file7,
1634
- L: 61,
1635
- S: void 0,
1636
- C: (f, a) => f(...a)
1637
- });
1638
- const tools2 = [
1639
- ...globalTools.flat(),
1640
- ...serviceTools,
1641
- ...functions.map((fn) => convertFunctionToTool(fn, config.values.runtime?.services?.edge?.url ?? "", space?.id)).filter(isNonNullable2)
1642
- ];
1643
- const extensions2 = {
1644
- space,
1733
+ var _effect = _useSignals7();
1734
+ try {
1735
+ const aiClient = useCapability(AssistantCapabilities.AiClient);
1736
+ const globalTools = useCapabilities2(Capabilities2.Tools);
1737
+ const artifactDefinitions = useCapabilities2(Capabilities2.ArtifactDefinition);
1738
+ const { dispatchPromise: dispatch } = useIntentDispatcher();
1739
+ const services = useQuery2(space, Filter3.type(ServiceType));
1740
+ const [serviceTools, setServiceTools] = useState4([]);
1741
+ useEffect3(() => {
1742
+ log6("creating service tools...", void 0, {
1743
+ F: __dxlog_file7,
1744
+ L: 49,
1745
+ S: void 0,
1746
+ C: (f, a) => f(...a)
1747
+ });
1748
+ queueMicrotask(async () => {
1749
+ const tools2 = await Promise.all(services.map((service) => createToolsFromService(service)));
1750
+ setServiceTools(tools2.flat());
1751
+ });
1752
+ }, [
1753
+ services
1754
+ ]);
1755
+ const config = useConfig();
1756
+ const functions = useQuery2(space, Filter3.type(FunctionType2));
1757
+ const chatId = useMemo3(() => chat ? fullyQualifiedId(chat) : void 0, [
1758
+ chat
1759
+ ]);
1760
+ const [tools, extensions] = useMemo3(() => {
1761
+ log6("creating tools...", void 0, {
1762
+ F: __dxlog_file7,
1763
+ L: 61,
1764
+ S: void 0,
1765
+ C: (f, a) => f(...a)
1766
+ });
1767
+ const tools2 = [
1768
+ ...globalTools.flat(),
1769
+ ...serviceTools,
1770
+ ...functions.map((fn) => convertFunctionToTool(fn, config.values.runtime?.services?.edge?.url ?? "", space?.id)).filter(isNonNullable3)
1771
+ ];
1772
+ const extensions2 = {
1773
+ space,
1774
+ dispatch,
1775
+ pivotId: chatId,
1776
+ part
1777
+ };
1778
+ return [
1779
+ tools2,
1780
+ extensions2
1781
+ ];
1782
+ }, [
1645
1783
  dispatch,
1646
- pivotId: chatId,
1647
- part
1648
- };
1649
- return [
1650
- tools2,
1651
- extensions2
1652
- ];
1653
- }, [
1654
- dispatch,
1655
- globalTools,
1656
- space,
1657
- chatId,
1658
- serviceTools,
1659
- functions
1660
- ]);
1661
- const systemPrompt = useMemo3(() => createSystemPrompt({
1662
- artifacts: artifactDefinitions.map((definition) => `${definition.name}
1784
+ globalTools,
1785
+ space,
1786
+ chatId,
1787
+ serviceTools,
1788
+ functions
1789
+ ]);
1790
+ const systemPrompt = useMemo3(() => createSystemPrompt({
1791
+ artifacts: artifactDefinitions.map((definition) => `${definition.name}
1663
1792
  ${definition.instructions}`),
1664
- associatedArtifact
1665
- }), [
1666
- artifactDefinitions,
1667
- associatedArtifact
1668
- ]);
1669
- const model = settings?.llmProvider === "ollama" ? settings?.ollamaModel ?? DEFAULT_OLLAMA_MODEL : settings?.edgeModel ?? DEFAULT_EDGE_MODEL2;
1670
- const processor = useMemo3(() => {
1671
- log6("creating processor...", {
1672
- settings
1673
- }, {
1674
- F: __dxlog_file7,
1675
- L: 92,
1676
- S: void 0,
1677
- C: (f, a) => f(...a)
1678
- });
1679
- return new ChatProcessor(aiClient.value, tools, artifactDefinitions, extensions, {
1793
+ associatedArtifact
1794
+ }), [
1795
+ artifactDefinitions,
1796
+ associatedArtifact
1797
+ ]);
1798
+ const model = settings?.llmProvider === "ollama" ? settings?.ollamaModel ?? DEFAULT_OLLAMA_MODEL : settings?.edgeModel ?? DEFAULT_EDGE_MODEL2;
1799
+ const processor = useMemo3(() => {
1800
+ log6("creating processor...", {
1801
+ settings
1802
+ }, {
1803
+ F: __dxlog_file7,
1804
+ L: 92,
1805
+ S: void 0,
1806
+ C: (f, a) => f(...a)
1807
+ });
1808
+ return new ChatProcessor(aiClient.value, tools, artifactDefinitions, extensions, {
1809
+ model,
1810
+ systemPrompt
1811
+ });
1812
+ }, [
1813
+ aiClient.value,
1814
+ tools,
1815
+ artifactDefinitions,
1816
+ extensions,
1680
1817
  model,
1681
1818
  systemPrompt
1682
- });
1683
- }, [
1684
- aiClient.value,
1685
- tools,
1686
- artifactDefinitions,
1687
- extensions,
1688
- model,
1689
- systemPrompt
1690
- ]);
1691
- return processor;
1819
+ ]);
1820
+ return processor;
1821
+ } finally {
1822
+ _effect.f();
1823
+ }
1692
1824
  };
1693
1825
 
1694
1826
  // packages/plugins/plugin-assistant/src/hooks/useMessageQueue.ts
@@ -1698,11 +1830,11 @@ import { getSpace, useQueue } from "@dxos/react-client/echo";
1698
1830
  var useMessageQueue = (chat) => {
1699
1831
  const space = getSpace(chat);
1700
1832
  const queueDxn = useMemo4(() => {
1701
- const dxn = space && chat?.assistantChatQueue.dxn;
1702
- return dxn ? createQueueDxn(space.id) : void 0;
1833
+ const dxn = space && chat?.queue.dxn;
1834
+ return dxn ? createQueueDxn(space.id, dxn.parts.at(-1)) : void 0;
1703
1835
  }, [
1704
1836
  space,
1705
- chat?.assistantChatQueue.dxn
1837
+ chat?.queue.dxn
1706
1838
  ]);
1707
1839
  return useQueue(queueDxn);
1708
1840
  };
@@ -1710,9 +1842,15 @@ var useMessageQueue = (chat) => {
1710
1842
  // packages/plugins/plugin-assistant/src/hooks/useServices.ts
1711
1843
  import { useEffect as useEffect4, useMemo as useMemo5, useState as useState5 } from "react";
1712
1844
 
1845
+ // packages/plugins/plugin-assistant/src/testing/blueprint.ts
1846
+ import { EXA_API_KEY } from "@dxos/ai/testing";
1847
+ import { createExaTool, createGraphWriterTool, createLocalSearchTool } from "@dxos/assistant";
1848
+ import { DataTypes } from "@dxos/schema";
1849
+ import { isNonNullable as isNonNullable4 } from "@dxos/util";
1850
+
1713
1851
  // packages/plugins/plugin-assistant/src/testing/test-functions.ts
1852
+ import { DEFAULT_EDGE_MODEL as DEFAULT_EDGE_MODEL3 } from "@dxos/ai";
1714
1853
  import { createSystemPrompt as createSystemPrompt2 } from "@dxos/artifact";
1715
- import { DEFAULT_EDGE_MODEL as DEFAULT_EDGE_MODEL3 } from "@dxos/assistant";
1716
1854
 
1717
1855
  // packages/plugins/plugin-assistant/src/testing/test-services.ts
1718
1856
  import { create } from "@dxos/echo-schema";
@@ -1804,13 +1942,14 @@ var TEST_SERVICES = [
1804
1942
  ];
1805
1943
 
1806
1944
  // packages/plugins/plugin-assistant/src/hooks/useTextInputEvents.ts
1945
+ import { useSignals as _useSignals8 } from "@preact-signals/safe-react/tracking";
1807
1946
  import { useState as useState6, useCallback as useCallback2 } from "react";
1808
1947
 
1809
1948
  // packages/plugins/plugin-assistant/src/hooks/useContextProvider.ts
1810
1949
  import { useMemo as useMemo6 } from "react";
1811
1950
  import { Capabilities as Capabilities3, useCapabilities as useCapabilities3 } from "@dxos/app-framework";
1812
- import { Filter as Filter3 } from "@dxos/client/echo";
1813
- import { Type } from "@dxos/echo";
1951
+ import { Filter as Filter4 } from "@dxos/client/echo";
1952
+ import { Obj } from "@dxos/echo";
1814
1953
  import { getDXN, getLabel } from "@dxos/echo-schema";
1815
1954
  import { log as log7 } from "@dxos/log";
1816
1955
  var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-assistant/src/hooks/useContextProvider.ts";
@@ -1824,11 +1963,11 @@ var useContextProvider = (space) => {
1824
1963
  return {
1825
1964
  query: async ({ query }) => {
1826
1965
  const artifactSchemas = artifactDefinitions.map((artifact) => artifact.schema);
1827
- const { objects } = await space.db.query(Filter3.or(...artifactSchemas.map((schema) => Filter3.type(schema)))).run();
1966
+ const { objects } = await space.db.query(Filter4.or(...artifactSchemas.map((schema) => Filter4.type(schema)))).run();
1828
1967
  return objects.map((object) => {
1829
1968
  log7.info("object", {
1830
1969
  object,
1831
- label: getLabel(Type.getSchema(object), object)
1970
+ label: getLabel(Obj.getSchema(object), object)
1832
1971
  }, {
1833
1972
  F: __dxlog_file8,
1834
1973
  L: 38,
@@ -1836,18 +1975,16 @@ var useContextProvider = (space) => {
1836
1975
  C: (f, a) => f(...a)
1837
1976
  });
1838
1977
  return object;
1839
- }).filter((object) => stringMatch(query, getLabel(Type.getSchema(object), object) ?? "")).filter((object) => !!getDXN(object)).map((object) => ({
1978
+ }).filter((object) => stringMatch(query, getLabel(Obj.getSchema(object), object) ?? "")).filter((object) => !!getDXN(object)).map((object) => ({
1840
1979
  uri: getDXN(object).toString(),
1841
- label: getLabel(Type.getSchema(object), object) ?? ""
1980
+ label: getLabel(Obj.getSchema(object), object) ?? ""
1842
1981
  }));
1843
1982
  },
1844
1983
  resolveMetadata: async ({ uri }) => {
1845
- const object = await space.db.query({
1846
- id: uri
1847
- }).first();
1984
+ const object = await space.db.query(Filter4.ids(uri)).first();
1848
1985
  return {
1849
1986
  uri,
1850
- label: getLabel(Type.getSchema(object), object) ?? ""
1987
+ label: getLabel(Obj.getSchema(object), object) ?? ""
1851
1988
  };
1852
1989
  }
1853
1990
  };
@@ -1860,97 +1997,103 @@ var useContextProvider = (space) => {
1860
1997
  // packages/plugins/plugin-assistant/src/components/Thread/ThreadContainer.tsx
1861
1998
  var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-assistant/src/components/Thread/ThreadContainer.tsx";
1862
1999
  var ThreadContainer = ({ classNames, chat, settings, part, associatedArtifact, onOpenChange, ...props }) => {
1863
- const space = getSpace2(chat);
1864
- const contextProvider = useContextProvider(space);
1865
- const processor = useChatProcessor({
1866
- chat,
1867
- space,
1868
- settings,
1869
- part,
1870
- associatedArtifact
1871
- });
1872
- const messageQueue = useMessageQueue(chat);
1873
- const { dispatchPromise: dispatch } = useIntentDispatcher2();
1874
- const messages = [
1875
- ...messageQueue?.items ?? [],
1876
- ...processor.messages.value
1877
- ];
1878
- useEffect5(() => {
1879
- if (!processor.streaming.value && messageQueue?.items) {
1880
- const message = messageQueue.items[messageQueue.items.length - 1];
1881
- if (space && chat && message && dispatch && associatedArtifact) {
1882
- void dispatch(createIntent(CollaborationActions.InsertContent, {
1883
- spaceId: space.id,
1884
- target: makeRef(associatedArtifact),
1885
- object: refFromDXN(new DXN(DXN.kind.QUEUE, [
1886
- ...chat.assistantChatQueue.dxn.parts,
1887
- message.id
1888
- ])),
1889
- label: "View proposal"
1890
- }));
2000
+ var _effect = _useSignals9();
2001
+ try {
2002
+ const space = getSpace2(chat);
2003
+ const contextProvider = useContextProvider(space);
2004
+ const processor = useChatProcessor({
2005
+ chat,
2006
+ space,
2007
+ settings,
2008
+ part,
2009
+ associatedArtifact
2010
+ });
2011
+ const messageQueue = useMessageQueue(chat);
2012
+ const { dispatchPromise: dispatch } = useIntentDispatcher2();
2013
+ const messages = [
2014
+ ...messageQueue?.objects ?? [],
2015
+ ...processor.messages.value
2016
+ ];
2017
+ useEffect5(() => {
2018
+ if (!processor.streaming.value && messageQueue?.objects) {
2019
+ const message = messageQueue.objects[messageQueue.objects.length - 1];
2020
+ if (space && chat && message && dispatch && associatedArtifact) {
2021
+ void dispatch(createIntent(CollaborationActions.InsertContent, {
2022
+ target: associatedArtifact,
2023
+ object: refFromDXN(new DXN(DXN.kind.QUEUE, [
2024
+ ...chat.queue.dxn.parts,
2025
+ message.id
2026
+ ])),
2027
+ label: "View proposal"
2028
+ }));
2029
+ }
1891
2030
  }
1892
- }
1893
- }, [
1894
- messageQueue,
1895
- associatedArtifact,
1896
- processor.streaming.value
1897
- ]);
1898
- const handleSubmit = useCallback3((text) => {
1899
- if (processor.streaming.value) {
1900
- log8.warn("ignoring submit; still processing.", void 0, {
2031
+ }, [
2032
+ messageQueue,
2033
+ associatedArtifact,
2034
+ processor.streaming.value
2035
+ ]);
2036
+ const handleSubmit = useCallback3((text) => {
2037
+ if (processor.streaming.value) {
2038
+ log8.warn("ignoring submit; still processing.", void 0, {
2039
+ F: __dxlog_file9,
2040
+ L: 65,
2041
+ S: void 0,
2042
+ C: (f, a) => f(...a)
2043
+ });
2044
+ return false;
2045
+ }
2046
+ onOpenChange?.(true);
2047
+ invariant4(messageQueue, void 0, {
1901
2048
  F: __dxlog_file9,
1902
- L: 66,
2049
+ L: 71,
1903
2050
  S: void 0,
1904
- C: (f, a) => f(...a)
2051
+ A: [
2052
+ "messageQueue",
2053
+ ""
2054
+ ]
1905
2055
  });
1906
- return false;
1907
- }
1908
- onOpenChange?.(true);
1909
- invariant4(messageQueue, void 0, {
1910
- F: __dxlog_file9,
1911
- L: 72,
1912
- S: void 0,
1913
- A: [
1914
- "messageQueue",
1915
- ""
1916
- ]
1917
- });
1918
- void processor.request(text, {
1919
- history: messageQueue.items,
1920
- onComplete: (messages2) => {
1921
- messageQueue.append(messages2);
2056
+ void processor.request(text, {
2057
+ history: messageQueue.objects,
2058
+ onComplete: (messages2) => {
2059
+ messageQueue.append(messages2);
2060
+ }
2061
+ });
2062
+ return true;
2063
+ }, [
2064
+ processor,
2065
+ messageQueue,
2066
+ onOpenChange
2067
+ ]);
2068
+ const handleCancel = useCallback3(() => {
2069
+ if (processor.streaming.value) {
2070
+ void processor.cancel();
1922
2071
  }
2072
+ }, [
2073
+ processor
2074
+ ]);
2075
+ return /* @__PURE__ */ React7.createElement(Thread, {
2076
+ classNames,
2077
+ space,
2078
+ messages,
2079
+ processing: processor.streaming.value,
2080
+ error: processor.error.value,
2081
+ tools: processor.tools,
2082
+ contextProvider,
2083
+ onSubmit: handleSubmit,
2084
+ onCancel: handleCancel,
2085
+ onPrompt: handleSubmit,
2086
+ onOpenChange,
2087
+ ...props
1923
2088
  });
1924
- return true;
1925
- }, [
1926
- processor,
1927
- messageQueue,
1928
- onOpenChange
1929
- ]);
1930
- const handleCancel = useCallback3(() => {
1931
- if (processor.streaming.value) {
1932
- void processor.cancel();
1933
- }
1934
- }, [
1935
- processor
1936
- ]);
1937
- return /* @__PURE__ */ React7.createElement(Thread, {
1938
- classNames,
1939
- space,
1940
- messages,
1941
- processing: processor.streaming.value,
1942
- error: processor.error.value,
1943
- tools: processor.tools,
1944
- contextProvider,
1945
- onSubmit: handleSubmit,
1946
- onCancel: handleCancel,
1947
- onPrompt: handleSubmit,
1948
- onOpenChange,
1949
- ...props
1950
- });
2089
+ } finally {
2090
+ _effect.f();
2091
+ }
1951
2092
  };
1952
2093
 
1953
2094
  export {
2095
+ Prompt,
2096
+ PromptBar,
1954
2097
  Toolbox,
1955
2098
  ToolboxContainer,
1956
2099
  Thread,
@@ -1961,4 +2104,4 @@ export {
1961
2104
  Settings,
1962
2105
  ThreadContainer
1963
2106
  };
1964
- //# sourceMappingURL=chunk-ED55ZE4G.mjs.map
2107
+ //# sourceMappingURL=chunk-SI5LOQEO.mjs.map