@dxos/plugin-assistant 0.8.2-main.fbd8ed0 → 0.8.2-staging.42af850

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