@dxos/plugin-assistant 0.8.2-main.f11618f → 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 (330) 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-XPNXNPSW.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-OK5SMYJC.mjs → ai-client-COXVUC6V.mjs} +6 -6
  8. package/dist/lib/browser/ai-client-COXVUC6V.mjs.map +7 -0
  9. package/dist/lib/browser/app-graph-builder-YH4EGNBC.mjs +206 -0
  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-7CAHKTZQ.mjs → chunk-QTW7KVDO.mjs} +1665 -1547
  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-W6XREK5F.mjs → intent-resolver-63EAHENI.mjs} +7 -11
  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-LAJZQI4H.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-U6AVMAHY.cjs → ChatContainer-5CLHJOIQ.cjs} +25 -19
  37. package/dist/lib/node/{ChatContainer-U6AVMAHY.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-3EVTLXTT.cjs → ai-client-R2CGEYZW.cjs} +13 -13
  41. package/dist/lib/node/ai-client-R2CGEYZW.cjs.map +7 -0
  42. package/dist/lib/node/app-graph-builder-PSHIOW3Q.cjs +216 -0
  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-CWHFK36A.cjs → chunk-H4A42LNR.cjs} +1154 -1030
  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-MUJMV7II.cjs → intent-resolver-66F7WLW6.cjs} +13 -17
  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-NPXTE6ND.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-GAYN3FEF.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-LYCBXZI7.mjs → ai-client-I5LXHMOZ.mjs} +6 -6
  75. package/dist/lib/node-esm/ai-client-I5LXHMOZ.mjs.map +7 -0
  76. package/dist/lib/node-esm/app-graph-builder-Z3GMMJMD.mjs +207 -0
  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-XFUXN5QU.mjs → chunk-SI5LOQEO.mjs} +1665 -1547
  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-DZY2O2DG.mjs → intent-resolver-X3PWH7KM.mjs} +7 -11
  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-K3JDH2I5.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 +3 -3
  103. package/dist/types/src/capabilities/ai-client.d.ts.map +1 -1
  104. package/dist/types/src/capabilities/app-graph-builder.d.ts +2 -179
  105. package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -1
  106. package/dist/types/src/capabilities/capabilities.d.ts +1 -1
  107. package/dist/types/src/capabilities/capabilities.d.ts.map +1 -1
  108. package/dist/types/src/capabilities/index.d.ts +2 -178
  109. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  110. package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -1
  111. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
  112. package/dist/types/src/components/AmbientDialog/AmbientDialog.d.ts +3 -1
  113. package/dist/types/src/components/AmbientDialog/AmbientDialog.d.ts.map +1 -1
  114. package/dist/types/src/components/AssistantSettings/AssistantSettings.d.ts.map +1 -1
  115. package/dist/types/src/components/BlueprintEditor/BlueprintEditor.d.ts +8 -0
  116. package/dist/types/src/components/BlueprintEditor/BlueprintEditor.d.ts.map +1 -0
  117. package/dist/types/src/components/BlueprintEditor/BlueprintEditor.stories.d.ts +8 -0
  118. package/dist/types/src/components/BlueprintEditor/BlueprintEditor.stories.d.ts.map +1 -0
  119. package/dist/types/src/components/BlueprintEditor/index.d.ts +2 -0
  120. package/dist/types/src/components/BlueprintEditor/index.d.ts.map +1 -0
  121. package/dist/types/src/components/Prompt/Prompt.d.ts +5 -2
  122. package/dist/types/src/components/Prompt/Prompt.d.ts.map +1 -1
  123. package/dist/types/src/components/Prompt/Prompt.stories.d.ts +6 -3
  124. package/dist/types/src/components/Prompt/Prompt.stories.d.ts.map +1 -1
  125. package/dist/types/src/components/Prompt/PromptBar.d.ts +9 -4
  126. package/dist/types/src/components/Prompt/PromptBar.d.ts.map +1 -1
  127. package/dist/types/src/components/Prompt/PromptBar.stories.d.ts +9 -0
  128. package/dist/types/src/components/Prompt/PromptBar.stories.d.ts.map +1 -0
  129. package/dist/types/src/components/Prompt/autocomplete.d.ts +5 -1
  130. package/dist/types/src/components/Prompt/autocomplete.d.ts.map +1 -1
  131. package/dist/types/src/components/Prompt/references.d.ts.map +1 -1
  132. package/dist/types/src/components/PromptSettings.d.ts.map +1 -1
  133. package/dist/types/src/components/TemplateContainer.d.ts.map +1 -1
  134. package/dist/types/src/components/TemplateEditor/TemplateEditor.d.ts.map +1 -1
  135. package/dist/types/src/components/TemplateEditor/TemplateEditor.stories.d.ts.map +1 -1
  136. package/dist/types/src/components/TemplateEditor/TemplateForm.d.ts +2 -2
  137. package/dist/types/src/components/TemplateEditor/TemplateForm.d.ts.map +1 -1
  138. package/dist/types/src/components/Thread/Thread.d.ts +2 -2
  139. package/dist/types/src/components/Thread/Thread.d.ts.map +1 -1
  140. package/dist/types/src/components/Thread/Thread.stories.d.ts.map +1 -1
  141. package/dist/types/src/components/Thread/ThreadContainer.d.ts +1 -1
  142. package/dist/types/src/components/Thread/ThreadContainer.d.ts.map +1 -1
  143. package/dist/types/src/components/Thread/ThreadContainer.stories.d.ts +2 -2
  144. package/dist/types/src/components/Thread/ThreadContainer.stories.d.ts.map +1 -1
  145. package/dist/types/src/components/Thread/ThreadMessage.d.ts +4 -2
  146. package/dist/types/src/components/Thread/ThreadMessage.d.ts.map +1 -1
  147. package/dist/types/src/components/Thread/ToolInvocations.d.ts +1 -1
  148. package/dist/types/src/components/Thread/ToolInvocations.d.ts.map +1 -1
  149. package/dist/types/src/components/Thread/reducer.d.ts +1 -1
  150. package/dist/types/src/components/Thread/reducer.d.ts.map +1 -1
  151. package/dist/types/src/components/Toolbox/Toolbox.d.ts +3 -2
  152. package/dist/types/src/components/Toolbox/Toolbox.d.ts.map +1 -1
  153. package/dist/types/src/components/index.d.ts +2 -0
  154. package/dist/types/src/components/index.d.ts.map +1 -1
  155. package/dist/types/src/experimental/transcription/index.d.ts +1 -0
  156. package/dist/types/src/experimental/transcription/index.d.ts.map +1 -0
  157. package/dist/types/src/hooks/index.d.ts +0 -1
  158. package/dist/types/src/hooks/index.d.ts.map +1 -1
  159. package/dist/types/src/hooks/processor.d.ts +6 -5
  160. package/dist/types/src/hooks/processor.d.ts.map +1 -1
  161. package/dist/types/src/hooks/useChatProcessor.d.ts.map +1 -1
  162. package/dist/types/src/hooks/useContextProvider.d.ts +1 -1
  163. package/dist/types/src/hooks/useContextProvider.d.ts.map +1 -1
  164. package/dist/types/src/hooks/useMessageQueue.d.ts +11 -7
  165. package/dist/types/src/hooks/useMessageQueue.d.ts.map +1 -1
  166. package/dist/types/src/hooks/useServices.d.ts.map +1 -1
  167. package/dist/types/src/hooks/useTextInputEvents.d.ts.map +1 -1
  168. package/dist/types/src/parser/filter-generator.d.ts +4 -0
  169. package/dist/types/src/parser/filter-generator.d.ts.map +1 -0
  170. package/dist/types/src/parser/filter-generator.test.d.ts +2 -0
  171. package/dist/types/src/parser/filter-generator.test.d.ts.map +1 -0
  172. package/dist/types/src/parser/index.d.ts +4 -0
  173. package/dist/types/src/parser/index.d.ts.map +1 -0
  174. package/dist/types/src/parser/query-parser.d.ts +15 -0
  175. package/dist/types/src/parser/query-parser.d.ts.map +1 -0
  176. package/dist/types/src/parser/query-parser.test.d.ts +2 -0
  177. package/dist/types/src/parser/query-parser.test.d.ts.map +1 -0
  178. package/dist/types/src/parser/types.d.ts +24 -0
  179. package/dist/types/src/parser/types.d.ts.map +1 -0
  180. package/dist/types/src/stories/Prompt.stories.d.ts +8 -0
  181. package/dist/types/src/stories/Prompt.stories.d.ts.map +1 -0
  182. package/dist/types/src/stories/Query.stories.d.ts +19 -0
  183. package/dist/types/src/stories/Query.stories.d.ts.map +1 -0
  184. package/dist/types/src/stories/Research.stories.d.ts +15 -0
  185. package/dist/types/src/stories/Research.stories.d.ts.map +1 -0
  186. package/dist/types/src/stories/test-data.d.ts +3 -0
  187. package/dist/types/src/stories/test-data.d.ts.map +1 -0
  188. package/dist/types/src/stories/testing.d.ts +12 -0
  189. package/dist/types/src/stories/testing.d.ts.map +1 -0
  190. package/dist/types/src/testing/blueprint.d.ts +7 -0
  191. package/dist/types/src/testing/blueprint.d.ts.map +1 -0
  192. package/dist/types/src/testing/index.d.ts +1 -0
  193. package/dist/types/src/testing/index.d.ts.map +1 -1
  194. package/dist/types/src/testing/test-functions.d.ts +1 -1
  195. package/dist/types/src/testing/test-functions.d.ts.map +1 -1
  196. package/dist/types/src/tools/function.d.ts +4 -4
  197. package/dist/types/src/tools/function.d.ts.map +1 -1
  198. package/dist/types/src/tools/openapi.d.ts +3 -3
  199. package/dist/types/src/tools/openapi.d.ts.map +1 -1
  200. package/dist/types/src/translations.d.ts +3 -0
  201. package/dist/types/src/translations.d.ts.map +1 -1
  202. package/dist/types/src/types/chat.d.ts +18 -8
  203. package/dist/types/src/types/chat.d.ts.map +1 -1
  204. package/dist/types/src/types/service.d.ts +96 -95
  205. package/dist/types/src/types/service.d.ts.map +1 -1
  206. package/dist/types/src/types/template.d.ts +52 -52
  207. package/dist/types/src/types/template.d.ts.map +1 -1
  208. package/dist/types/src/types/types.d.ts +24 -21
  209. package/dist/types/src/types/types.d.ts.map +1 -1
  210. package/dist/types/tsconfig.tsbuildinfo +1 -1
  211. package/package.json +79 -61
  212. package/src/AssistantPlugin.tsx +5 -4
  213. package/src/capabilities/ai-client.ts +5 -5
  214. package/src/capabilities/app-graph-builder.ts +179 -109
  215. package/src/capabilities/capabilities.ts +1 -1
  216. package/src/capabilities/intent-resolver.ts +4 -6
  217. package/src/capabilities/react-surface.tsx +58 -13
  218. package/src/components/AmbientDialog/AmbientDialog.stories.tsx +2 -2
  219. package/src/components/AmbientDialog/AmbientDialog.tsx +27 -13
  220. package/src/components/AssistantDialog.tsx +1 -1
  221. package/src/components/AssistantSettings/AssistantSettings.tsx +1 -1
  222. package/src/components/BlueprintEditor/BlueprintEditor.stories.tsx +32 -0
  223. package/src/components/BlueprintEditor/BlueprintEditor.tsx +41 -0
  224. package/src/components/BlueprintEditor/index.ts +5 -0
  225. package/src/components/Prompt/Prompt.stories.tsx +59 -52
  226. package/src/components/Prompt/Prompt.tsx +24 -10
  227. package/src/components/Prompt/PromptBar.stories.tsx +68 -0
  228. package/src/components/Prompt/PromptBar.tsx +82 -88
  229. package/src/components/Prompt/autocomplete.ts +14 -8
  230. package/src/components/Prompt/references.ts +3 -3
  231. package/src/components/PromptSettings.tsx +2 -2
  232. package/src/components/TemplateEditor/TemplateEditor.stories.tsx +2 -2
  233. package/src/components/TemplateEditor/TemplateForm.stories.tsx +1 -1
  234. package/src/components/TemplateEditor/TemplateForm.tsx +2 -2
  235. package/src/components/Thread/Thread.stories.tsx +14 -17
  236. package/src/components/Thread/Thread.tsx +2 -2
  237. package/src/components/Thread/ThreadContainer.stories.tsx +79 -49
  238. package/src/components/Thread/ThreadContainer.tsx +8 -9
  239. package/src/components/Thread/ThreadMessage.tsx +44 -9
  240. package/src/components/Thread/ToolInvocations.tsx +9 -7
  241. package/src/components/Thread/reducer.ts +1 -1
  242. package/src/components/Toolbox/Toolbox.stories.tsx +3 -3
  243. package/src/components/Toolbox/Toolbox.tsx +5 -4
  244. package/src/components/index.ts +2 -0
  245. package/src/experimental/transcription/index.ts +3 -0
  246. package/src/hooks/index.ts +0 -1
  247. package/src/hooks/processor.ts +65 -27
  248. package/src/hooks/useChatProcessor.tsx +9 -9
  249. package/src/hooks/useContextProvider.ts +21 -17
  250. package/src/hooks/useMessageQueue.ts +5 -5
  251. package/src/meta.ts +2 -2
  252. package/src/parser/filter-generator.test.ts +32 -0
  253. package/src/parser/filter-generator.ts +81 -0
  254. package/src/parser/index.ts +7 -0
  255. package/src/parser/query-parser.test.ts +139 -0
  256. package/src/parser/query-parser.ts +199 -0
  257. package/src/parser/types.ts +34 -0
  258. package/src/shims.d.ts +8 -0
  259. package/src/stories/Prompt.stories.tsx +59 -0
  260. package/src/stories/Query.stories.tsx +448 -0
  261. package/src/stories/Research.stories.tsx +495 -0
  262. package/src/stories/test-data.ts +128 -0
  263. package/src/stories/testing.ts +64 -0
  264. package/src/testing/blueprint.ts +47 -0
  265. package/src/testing/index.ts +1 -0
  266. package/src/testing/test-functions.ts +1 -1
  267. package/src/tools/function.ts +11 -12
  268. package/src/tools/openapi.test.ts +18 -19
  269. package/src/tools/openapi.ts +24 -17
  270. package/src/translations.ts +4 -2
  271. package/src/types/chat.ts +27 -4
  272. package/src/types/service.ts +39 -37
  273. package/src/types/template.ts +27 -25
  274. package/src/types/types.ts +20 -18
  275. package/dist/lib/browser/AssistantDialog-I47GUXWR.mjs +0 -117
  276. package/dist/lib/browser/AssistantDialog-I47GUXWR.mjs.map +0 -7
  277. package/dist/lib/browser/ChatContainer-GAYN3FEF.mjs +0 -33
  278. package/dist/lib/browser/TemplateContainer-WKU5XFSO.mjs +0 -22
  279. package/dist/lib/browser/ai-client-OK5SMYJC.mjs.map +0 -7
  280. package/dist/lib/browser/app-graph-builder-ZXKGE3H5.mjs +0 -179
  281. package/dist/lib/browser/app-graph-builder-ZXKGE3H5.mjs.map +0 -7
  282. package/dist/lib/browser/chunk-7CAHKTZQ.mjs.map +0 -7
  283. package/dist/lib/browser/chunk-BGMQ2YYP.mjs +0 -143
  284. package/dist/lib/browser/chunk-BGMQ2YYP.mjs.map +0 -7
  285. package/dist/lib/browser/chunk-E7BN4QKP.mjs +0 -190
  286. package/dist/lib/browser/chunk-E7BN4QKP.mjs.map +0 -7
  287. package/dist/lib/browser/chunk-NFUHCW2J.mjs +0 -81
  288. package/dist/lib/browser/chunk-TXJWGWJ7.mjs.map +0 -7
  289. package/dist/lib/browser/intent-resolver-W6XREK5F.mjs.map +0 -7
  290. package/dist/lib/browser/react-surface-QMI5KG4H.mjs +0 -90
  291. package/dist/lib/browser/react-surface-QMI5KG4H.mjs.map +0 -7
  292. package/dist/lib/node/AssistantDialog-SDS2TE5L.cjs +0 -141
  293. package/dist/lib/node/AssistantDialog-SDS2TE5L.cjs.map +0 -7
  294. package/dist/lib/node/ai-client-3EVTLXTT.cjs.map +0 -7
  295. package/dist/lib/node/app-graph-builder-TXHPXIIC.cjs +0 -190
  296. package/dist/lib/node/app-graph-builder-TXHPXIIC.cjs.map +0 -7
  297. package/dist/lib/node/chunk-5UELRDHQ.cjs +0 -214
  298. package/dist/lib/node/chunk-5UELRDHQ.cjs.map +0 -7
  299. package/dist/lib/node/chunk-CWHFK36A.cjs.map +0 -7
  300. package/dist/lib/node/chunk-GBUNQ257.cjs.map +0 -7
  301. package/dist/lib/node/chunk-XBJO453B.cjs +0 -169
  302. package/dist/lib/node/chunk-XBJO453B.cjs.map +0 -7
  303. package/dist/lib/node/intent-resolver-MUJMV7II.cjs.map +0 -7
  304. package/dist/lib/node/react-surface-SAJF4XBB.cjs +0 -106
  305. package/dist/lib/node/react-surface-SAJF4XBB.cjs.map +0 -7
  306. package/dist/lib/node-esm/AssistantDialog-KGA5HBFO.mjs +0 -118
  307. package/dist/lib/node-esm/AssistantDialog-KGA5HBFO.mjs.map +0 -7
  308. package/dist/lib/node-esm/ChatContainer-XPNXNPSW.mjs +0 -34
  309. package/dist/lib/node-esm/TemplateContainer-3LEBT5ZC.mjs +0 -23
  310. package/dist/lib/node-esm/ai-client-LYCBXZI7.mjs.map +0 -7
  311. package/dist/lib/node-esm/app-graph-builder-SV4WC2E2.mjs +0 -180
  312. package/dist/lib/node-esm/app-graph-builder-SV4WC2E2.mjs.map +0 -7
  313. package/dist/lib/node-esm/chunk-6JK5HEUQ.mjs.map +0 -7
  314. package/dist/lib/node-esm/chunk-ECYNZYEG.mjs +0 -191
  315. package/dist/lib/node-esm/chunk-ECYNZYEG.mjs.map +0 -7
  316. package/dist/lib/node-esm/chunk-R7Q3OHWG.mjs +0 -144
  317. package/dist/lib/node-esm/chunk-R7Q3OHWG.mjs.map +0 -7
  318. package/dist/lib/node-esm/chunk-XFUXN5QU.mjs.map +0 -7
  319. package/dist/lib/node-esm/intent-resolver-DZY2O2DG.mjs.map +0 -7
  320. package/dist/lib/node-esm/react-surface-R43NHNMC.mjs +0 -91
  321. package/dist/lib/node-esm/react-surface-R43NHNMC.mjs.map +0 -7
  322. package/dist/types/src/hooks/invocation-handler.d.ts +0 -5
  323. package/dist/types/src/hooks/invocation-handler.d.ts.map +0 -1
  324. package/dist/types/src/hooks/useLocalTriggerManager.d.ts +0 -3
  325. package/dist/types/src/hooks/useLocalTriggerManager.d.ts.map +0 -1
  326. package/src/hooks/invocation-handler.ts +0 -107
  327. package/src/hooks/useLocalTriggerManager.ts +0 -82
  328. /package/dist/lib/browser/{settings-LAJZQI4H.mjs.map → settings-SHNQ4XXP.mjs.map} +0 -0
  329. /package/dist/lib/node/{settings-NPXTE6ND.cjs.map → settings-ERKLO6IO.cjs.map} +0 -0
  330. /package/dist/lib/node-esm/{settings-K3JDH2I5.mjs.map → settings-IVQRZUCU.mjs.map} +0 -0
@@ -1,1404 +1,1502 @@
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-E7BN4QKP.mjs";
7
+ } from "./chunk-IHEBFO5O.mjs";
8
8
  import {
9
9
  ASSISTANT_PLUGIN
10
- } from "./chunk-3HCI5FIL.mjs";
10
+ } from "./chunk-XOZ7YMO3.mjs";
11
11
 
12
- // packages/plugins/plugin-assistant/src/components/Toolbox/Toolbox.tsx
13
- import React, { useState, useEffect, Fragment } from "react";
14
- import { Capabilities, useCapabilities } from "@dxos/app-framework";
15
- import { parseToolName } from "@dxos/artifact";
16
- import { FunctionType } from "@dxos/functions/types";
17
- import { log as log3 } from "@dxos/log";
18
- import { Filter, useQuery } from "@dxos/react-client/echo";
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";
19
18
  import { mx } from "@dxos/react-ui-theme";
19
+ import { isNonNullable } from "@dxos/util";
20
20
 
21
- // packages/plugins/plugin-assistant/src/tools/function.ts
22
- import { defineTool, ToolResult } from "@dxos/artifact";
23
- import { toEffectSchema } from "@dxos/echo-schema";
24
- import { getInvocationUrl, getUserFunctionUrlInMetadata } from "@dxos/functions/types";
25
- import { log } from "@dxos/log";
26
- import { getMeta } from "@dxos/react-client/echo";
27
- var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/plugin-assistant/src/tools/function.ts";
28
- var covertFunctionToTool = (fn, edgeUrl, spaceId) => {
29
- if (!fn.description || !fn.inputSchema) {
30
- return void 0;
31
- }
32
- const existingFunctionUrl = getUserFunctionUrlInMetadata(getMeta(fn));
33
- if (!existingFunctionUrl) {
34
- return void 0;
35
- }
36
- const url = getInvocationUrl(existingFunctionUrl, edgeUrl, {
37
- spaceId
38
- });
39
- return defineTool("user-function", {
40
- name: fn.name,
41
- description: fn.description,
42
- schema: toEffectSchema(fn.inputSchema),
43
- execute: async (input) => {
44
- log.info("execute function tool", {
45
- name: fn.name,
46
- url,
47
- input
48
- }, {
49
- F: __dxlog_file,
50
- L: 36,
51
- S: void 0,
52
- C: (f, a) => f(...a)
53
- });
54
- const response = await fetch(url, {
55
- method: "POST",
56
- headers: {
57
- "Content-Type": "application/json"
58
- },
59
- body: JSON.stringify(input)
60
- });
61
- return ToolResult.Success(await response.text());
62
- }
63
- });
64
- };
65
-
66
- // packages/plugins/plugin-assistant/src/tools/openapi.ts
67
- import jsonpointer from "jsonpointer";
68
- import { ToolResult as ToolResult2 } from "@dxos/artifact";
69
- import { JsonSchemaType, normalizeSchema, S, toEffectSchema as toEffectSchema2 } from "@dxos/echo-schema";
70
- import { invariant } from "@dxos/invariant";
71
- import { log as log2 } from "@dxos/log";
72
- import { deepMapValues } from "@dxos/util";
73
- var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-assistant/src/tools/openapi.ts";
74
- var createToolsFromService = async (service) => {
75
- invariant(service.interfaces?.length === 1 && service.interfaces[0].kind === "api", void 0, {
76
- F: __dxlog_file2,
77
- L: 22,
78
- S: void 0,
79
- A: [
80
- "service.interfaces?.length === 1 && service.interfaces[0].kind === 'api'",
81
- ""
82
- ]
83
- });
84
- const iface = service.interfaces[0];
85
- invariant(iface.schemaUrl, void 0, {
86
- F: __dxlog_file2,
87
- L: 24,
88
- S: void 0,
89
- A: [
90
- "iface.schemaUrl",
91
- ""
92
- ]
93
- });
94
- invariant(iface.schemaUrl, void 0, {
95
- F: __dxlog_file2,
96
- L: 25,
97
- S: void 0,
98
- A: [
99
- "iface.schemaUrl",
100
- ""
101
- ]
102
- });
103
- return createToolsFromApi(iface.schemaUrl, {
104
- authorization: iface.authorization
105
- });
106
- };
107
- var createToolsFromApi = async (url, options) => {
108
- const res = await fetch(url);
109
- const spec = await res.json();
110
- log2("spec", {
111
- spec
112
- }, {
113
- F: __dxlog_file2,
114
- L: 32,
115
- S: void 0,
116
- C: (f, a) => f(...a)
117
- });
118
- const tools = [];
119
- for (const [path, pathItem] of Object.entries(spec.paths)) {
120
- if (typeof pathItem !== "object") {
121
- continue;
122
- }
123
- const { ...methods } = pathItem;
124
- for (const [method, m] of Object.entries(methods)) {
125
- const methodItem = m;
126
- log2("methodItem", {
127
- path,
128
- method,
129
- methodItem
130
- }, {
131
- F: __dxlog_file2,
132
- L: 44,
133
- S: void 0,
134
- C: (f, a) => f(...a)
135
- });
136
- const parametersResolved = methodItem.parameters?.map((parameter) => {
137
- const resolved = resolveJsonSchema(parameter, spec);
138
- return resolved;
139
- }) ?? [];
140
- const inputSchema = {
141
- type: "object",
142
- properties: {}
143
- };
144
- const endpointParameters = [];
145
- for (const parameter of parametersResolved) {
146
- log2("parameter", {
147
- parameter
148
- }, {
149
- F: __dxlog_file2,
150
- L: 59,
151
- S: void 0,
152
- C: (f, a) => f(...a)
153
- });
154
- if (options?.authorization?.type === "api-key" && options.authorization.placement.type === "query" && parameter.in === "query" && parameter.name === options.authorization.placement.name) {
155
- continue;
156
- }
157
- endpointParameters.push(parameter);
158
- if (parameter.schema) {
159
- inputSchema.properties[parameter.name] = normalizeSchema(parameter.schema);
160
- } else if (typeof parameter.type === "string") {
161
- const { name, in: _in, required, ...schema } = parameter;
162
- inputSchema.properties[name] = normalizeSchema(schema);
163
- if (required) {
164
- inputSchema.required ??= [];
165
- inputSchema.required.push(name);
166
- }
167
- }
168
- }
169
- log2("inputSchema", {
170
- inputSchema
171
- }, {
172
- F: __dxlog_file2,
173
- L: 84,
174
- S: void 0,
175
- C: (f, a) => f(...a)
176
- });
177
- S.validateSync(JsonSchemaType)(inputSchema);
178
- const description = methodItem.description ?? methodItem.summary;
179
- if (!description) {
180
- log2.warn("no description", {
181
- path,
182
- method
183
- }, {
184
- F: __dxlog_file2,
185
- L: 89,
186
- S: void 0,
187
- C: (f, a) => f(...a)
188
- });
189
- continue;
190
- }
191
- const endpoint = {
192
- document: spec,
193
- path,
194
- method,
195
- parameters: endpointParameters,
196
- authorization: options?.authorization
197
- };
198
- tools.push({
199
- name: getToolName(path, method, methodItem),
200
- description: options?.instructions ? `${options.instructions}
201
-
202
- ${description}` : description,
203
- parameters: inputSchema,
204
- execute: async (input) => {
205
- const response = await callApiEndpoint(endpoint, input);
206
- return ToolResult2.Success(response);
207
- }
208
- });
209
- }
210
- }
211
- return tools;
212
- };
213
- var getToolName = (path, method, methodItem) => {
214
- if (methodItem.operationId) {
215
- return methodItem.operationId;
216
- }
217
- let name = `${method.toLowerCase()}_${path.replaceAll(/[{}/]/g, "_")}`;
218
- while (name.length > MAX_TOOL_NAME_LENGTH) {
219
- const lengthBefore = name.length;
220
- for (const word of GENERIC_WORDS) {
221
- if (name.includes(word)) {
222
- name = name.replace(word, "");
223
- break;
224
- }
225
- }
226
- name = name.replaceAll("__", "_").replace(/_$/, "");
227
- const lengthAfter = name.length;
228
- if (lengthBefore === lengthAfter) {
229
- break;
230
- }
231
- }
232
- name = name.replaceAll("__", "_").replace(/_$/, "").replace(/^_/, "");
233
- return name.slice(0, MAX_TOOL_NAME_LENGTH);
234
- };
235
- var MAX_TOOL_NAME_LENGTH = 64;
236
- var GENERIC_WORDS = [
237
- "services",
238
- "service",
239
- "api",
240
- "rest",
241
- "endpoint",
242
- "get",
243
- "post",
244
- "put",
245
- "delete",
246
- "patch",
247
- "head",
248
- "options",
249
- "trace",
250
- "service",
251
- "api",
252
- "endpoint"
253
- ];
254
- var callApiEndpoint = async (endpoint, input) => {
255
- log2.info("endpoint", {
256
- method: endpoint.method,
257
- name: endpoint.path,
258
- input
259
- }, {
260
- F: __dxlog_file2,
261
- L: 173,
262
- S: void 0,
263
- C: (f, a) => f(...a)
264
- });
265
- let url = getEndpointUrl(endpoint);
266
- const request = {
267
- method: endpoint.method,
268
- headers: {}
269
- };
270
- const query = new URLSearchParams();
271
- let body;
272
- for (const parameter of endpoint.parameters) {
273
- if (input[parameter.name] === void 0) {
274
- continue;
275
- }
276
- switch (parameter.in) {
277
- case "header": {
278
- if (parameter.example) {
279
- request.headers[parameter.name] = parameter.default;
280
- }
281
- break;
282
- }
283
- case "path": {
284
- url = url.replace(`{${parameter.name}}`, encodeURIComponent(input[parameter.name]));
285
- break;
286
- }
287
- case "body": {
288
- const value = input[parameter.name];
289
- const effectSchema = toEffectSchema2(parameter.schema);
290
- S.validateSync(effectSchema)(value);
291
- if (body) {
292
- throw new Error(`Duplicate body parameter: ${parameter.name}`);
293
- }
294
- body = value;
295
- break;
296
- }
297
- case "query": {
298
- query.set(parameter.name, input[parameter.name]);
299
- break;
300
- }
301
- }
302
- }
303
- if (endpoint.authorization?.type === "api-key" && endpoint.authorization.placement.type === "authorization-header" || endpoint.authorization?.type === "oauth") {
304
- request.headers.Authorization = await resolveAuthorization(endpoint.authorization);
305
- } else if (endpoint.authorization?.type === "api-key" && endpoint.authorization.placement.type === "query") {
306
- query.set(endpoint.authorization.placement.name, endpoint.authorization.key);
307
- }
308
- if (query.size > 0) {
309
- url += `?${query.toString()}`;
310
- }
311
- if (body) {
312
- request.body = JSON.stringify(body);
313
- request.headers["Content-Type"] = "application/json";
314
- }
315
- log2.info("request", {
316
- url,
317
- request
318
- }, {
319
- F: __dxlog_file2,
320
- L: 236,
321
- S: void 0,
322
- C: (f, a) => f(...a)
323
- });
324
- const response = await fetch(url, request);
325
- log2.info("response", {
326
- ok: response.ok,
327
- status: response.status,
328
- statusText: response.statusText
329
- }, {
330
- F: __dxlog_file2,
331
- L: 239,
332
- S: void 0,
333
- C: (f, a) => f(...a)
334
- });
335
- if (response.ok) {
336
- const contentType = response.headers.get("Content-Type");
337
- if (contentType?.includes("application/json")) {
338
- return await response.json();
339
- } else {
340
- return await response.text();
341
- }
342
- } else {
343
- if (response.headers.get("Content-Type")?.includes("application/json")) {
344
- const responseBody = await response.text();
345
- let error;
346
- try {
347
- error = JSON.parse(responseBody);
348
- } catch {
349
- error = responseBody;
350
- }
351
- log2.error("error", {
352
- error
353
- }, {
354
- F: __dxlog_file2,
355
- L: 257,
356
- S: void 0,
357
- C: (f, a) => f(...a)
358
- });
359
- throw new Error(error.message);
360
- } else {
361
- const error = await response.text();
362
- log2.error("error", {
363
- error
364
- }, {
365
- F: __dxlog_file2,
366
- L: 261,
367
- S: void 0,
368
- C: (f, a) => f(...a)
369
- });
370
- throw new Error(error);
371
- }
372
- }
373
- };
374
- var getEndpointUrl = (endpoint) => {
375
- let url = "";
376
- if (isV3_1(endpoint.document) && endpoint.document.servers && endpoint.document.servers.length > 0) {
377
- url = endpoint.document.servers[0].url;
378
- } else {
379
- invariant(!isV3_1(endpoint.document), void 0, {
380
- F: __dxlog_file2,
381
- L: 272,
382
- S: void 0,
383
- A: [
384
- "!isV3_1(endpoint.document)",
385
- ""
386
- ]
387
- });
388
- url = `${endpoint.document.schemes?.[0] ?? "https"}://${endpoint.document.host}`;
389
- }
390
- if (!isV3_1(endpoint.document) && endpoint.document.basePath) {
391
- url += endpoint.document.basePath;
392
- }
393
- url += endpoint.path;
394
- return url;
395
- };
396
- var resolveAuthorization = async (authorization) => {
397
- switch (authorization.type) {
398
- case "api-key": {
399
- invariant(authorization.placement.type === "authorization-header", void 0, {
400
- F: __dxlog_file2,
401
- L: 288,
402
- S: void 0,
403
- A: [
404
- "authorization.placement.type === 'authorization-header'",
405
- ""
406
- ]
407
- });
408
- return `Bearer ${authorization.key}`;
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);
409
29
  }
410
- case "oauth": {
411
- const response = await fetch(authorization.tokenUrl, {
412
- method: "POST",
413
- headers: {
414
- "Content-Type": "application/x-www-form-urlencoded"
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
415
67
  },
416
- body: `grant_type=${authorization.grantType}&client_id=${authorization.clientId}&client_secret=${authorization.clientSecret}`
68
+ selection: {
69
+ anchor: view.state.doc.length + suffix.length
70
+ }
417
71
  });
418
- const data = await response.json();
419
- return `Bearer ${data.access_token}`;
420
- }
421
- default: {
422
- throw new Error(`Unknown authorization type: ${authorization.type}`);
72
+ return true;
423
73
  }
424
- }
425
- };
426
- var resolveJsonSchema = (schema, base) => {
427
- return deepMapValues(schema, (value, recurse) => {
428
- if (typeof value === "object" && value !== null && "$ref" in value && typeof value.$ref === "string") {
429
- if (value.$ref.startsWith("#")) {
430
- const resolved = jsonpointer.get(base, value.$ref.slice(1));
431
- if (resolved) {
432
- return recurse(resolved);
433
- } else {
434
- log2.warn("unresolved", {
435
- ref: value.$ref,
436
- base
437
- }, {
438
- F: __dxlog_file2,
439
- L: 321,
440
- S: void 0,
441
- C: (f, a) => f(...a)
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
+ }
442
151
  });
152
+ onCancel?.();
153
+ return true;
443
154
  }
444
155
  }
445
- }
446
- return recurse(value);
447
- });
448
- };
449
- var isV3_1 = (document2) => {
450
- return document2.openapi === "3.0.1";
451
- };
452
-
453
- // packages/plugins/plugin-assistant/src/components/Toolbox/Toolbox.tsx
454
- var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-assistant/src/components/Toolbox/Toolbox.tsx";
455
- var Toolbox = ({ classNames, artifacts, functions, services, striped }) => {
456
- return /* @__PURE__ */ React.createElement("div", {
457
- className: mx("flex flex-col overflow-y-auto box-content", classNames)
458
- }, artifacts && artifacts.length > 0 && /* @__PURE__ */ React.createElement(Section, {
459
- title: "Artifacts",
460
- items: artifacts.map(({ name, description, tools }) => ({
461
- name,
462
- description,
463
- subitems: tools.map(({ name: name2, description: description2 }) => ({
464
- name: `\u2219 ${parseToolName(name2)}`,
465
- description: description2
466
- }))
467
- }))
468
- }), services && services.length > 0 && /* @__PURE__ */ React.createElement(Section, {
469
- title: "Services",
470
- items: services.map(({ service: { serviceId, name, description }, tools }) => ({
471
- name: name ?? serviceId,
472
- description,
473
- subitems: tools.map(({ name: name2, description: description2 }) => ({
474
- name: `\u2219 ${name2}`,
475
- description: description2
476
- }))
477
- }))
478
- }), functions && functions.length > 0 && /* @__PURE__ */ React.createElement(Section, {
479
- title: "Functions",
480
- items: functions.map(({ name, description }) => ({
481
- name,
482
- description
483
- }))
484
- }));
485
- };
486
- var Section = ({ title, items, striped }) => {
487
- const stripeClassNames = "odd:bg-neutral-50 dark:odd:bg-neutral-800";
488
- const gridClassNames = "grid grid-cols-[8rem_1fr]";
489
- const subGridClassNames = mx("col-span-full grid grid-cols-subgrid text-xs px-2", striped && stripeClassNames);
490
- return /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement("h1", {
491
- className: "px-2 text-sm"
492
- }, title), /* @__PURE__ */ React.createElement("div", {
493
- className: gridClassNames
494
- }, items.map(({ name, description, subitems }, i) => /* @__PURE__ */ React.createElement(Fragment, {
495
- key: i
496
- }, name && /* @__PURE__ */ React.createElement("div", {
497
- className: subGridClassNames
498
- }, /* @__PURE__ */ React.createElement("div", {
499
- className: "truncate text-primary-500"
500
- }, name), /* @__PURE__ */ React.createElement("div", {
501
- className: "line-clamp-2"
502
- }, description)), subitems?.map(({ name: name2, description: description2 }, i2) => /* @__PURE__ */ React.createElement("div", {
503
- key: i2,
504
- className: mx(subGridClassNames, striped && stripeClassNames)
505
- }, /* @__PURE__ */ React.createElement("div", {
506
- className: "truncate"
507
- }, name2), /* @__PURE__ */ React.createElement("div", {
508
- className: "line-clamp-3 text-subdued"
509
- }, description2)))))));
156
+ ]))
157
+ ];
510
158
  };
511
- var ToolboxContainer = ({ classNames, space }) => {
512
- const artifactDefinitions = useCapabilities(Capabilities.ArtifactDefinition);
513
- const services = useQuery(space, Filter.schema(ServiceType));
514
- const [serviceTools, setServiceTools] = useState([]);
515
- useEffect(() => {
516
- log3("creating service tools...", {
517
- services: services.length
518
- }, {
519
- F: __dxlog_file3,
520
- L: 99,
521
- S: void 0,
522
- C: (f, a) => f(...a)
523
- });
524
- queueMicrotask(async () => {
525
- const tools = await Promise.all(services.map(async (service) => ({
526
- service,
527
- tools: await createToolsFromService(service)
528
- })));
529
- setServiceTools(tools);
530
- });
531
- }, [
532
- services
533
- ]);
534
- const functions = useQuery(space, Filter.schema(FunctionType));
535
- return /* @__PURE__ */ React.createElement(Toolbox, {
536
- classNames,
537
- artifacts: artifactDefinitions,
538
- services: serviceTools,
539
- functions
540
- });
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
+ }
541
172
  };
542
173
 
543
- // packages/plugins/plugin-assistant/src/components/Thread/Thread.tsx
544
- import React6, { useCallback, useMemo as useMemo2, useRef as useRef3 } from "react";
545
- import { useIdentity } from "@dxos/react-client/halo";
546
- import { ScrollContainer } from "@dxos/react-ui-components";
547
- import { mx as mx5 } from "@dxos/react-ui-theme";
548
- import { keyToFallback } from "@dxos/util";
549
-
550
- // packages/plugins/plugin-assistant/src/components/Thread/ThreadMessage.tsx
551
- import React3 from "react";
552
- import { invariant as invariant2 } from "@dxos/invariant";
553
- import { Button, Icon, IconButton } from "@dxos/react-ui";
554
- import { MarkdownViewer, ToggleContainer as NativeToggleContainer } from "@dxos/react-ui-components";
555
- import { Json as Json2 } from "@dxos/react-ui-syntax-highlighter";
556
- import { mx as mx2 } from "@dxos/react-ui-theme";
557
- import { safeParseJson } from "@dxos/util";
558
-
559
- // packages/plugins/plugin-assistant/src/components/Thread/ToolInvocations.tsx
560
- import React2, { useEffect as useEffect2, useMemo, useRef, useState as useState2 } from "react";
561
- import { log as log4 } from "@dxos/log";
562
- import { NumericTabs, StatusRoll, ToggleContainer } from "@dxos/react-ui-components";
563
- import { Json } from "@dxos/react-ui-syntax-highlighter";
564
- import { isNonNullable, isNotFalsy } from "@dxos/util";
565
- var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-assistant/src/components/Thread/ToolInvocations.tsx";
566
- var isToolMessage = (message) => {
567
- return message.content.some((block) => block.type === "tool_use" || block.type === "tool_result");
568
- };
569
- var getToolName2 = (tool) => {
570
- return tool.namespace && tool.function ? `${tool.namespace}:${tool.function}` : tool.name.split("_").pop();
571
- };
572
- var getToolCaption = (tool) => {
573
- if (!tool) {
574
- return "Calling tool...";
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");
575
182
  }
576
- return tool.caption ?? `Calling ${getToolName2(tool)}...`;
577
- };
578
- var ToolBlock = ({ classNames, message, tools }) => {
579
- const { content = [] } = message;
580
- let request;
581
- const blocks = content.filter((block) => block.type === "tool_use" || block.type === "tool_result");
582
- const items = blocks.map((block) => {
583
- switch (block.type) {
584
- case "tool_use": {
585
- if (block.pending && request?.block.id === block.id) {
586
- return null;
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));
587
222
  }
588
- request = {
589
- tool: tools?.find((tool) => tool.name === block.name),
590
- block
591
- };
592
- return {
593
- title: getToolCaption(request.tool),
594
- block
595
- };
596
223
  }
597
- case "tool_result": {
598
- if (!request) {
599
- log4.warn("unexpected message", {
600
- block
601
- }, {
602
- F: __dxlog_file4,
603
- L: 52,
604
- S: void 0,
605
- C: (f, a) => f(...a)
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
606
253
  });
607
254
  return {
608
- title: "Error",
609
- block
255
+ from: match.from,
256
+ filter: false,
257
+ options: references.map((reference) => ({
258
+ label: reference.label,
259
+ apply: `${triggerCharacter}${reference.uri} `
260
+ }))
610
261
  };
611
262
  }
612
- return {
613
- title: `${getToolCaption(request.tool)} (Success)`,
614
- block
615
- };
616
- }
617
- default: {
618
- request = void 0;
619
- return {
620
- title: "Error",
621
- block
622
- };
623
- }
624
- }
625
- }).filter(isNonNullable);
626
- return /* @__PURE__ */ React2.createElement(ToolContainer, {
627
- classNames,
628
- items
629
- });
630
- };
631
- var ToolContainer = ({ classNames, items }) => {
632
- const tabsRef = useRef(null);
633
- const [selected, setSelected] = useState2(0);
634
- const [open, setOpen] = useState2(false);
635
- useEffect2(() => {
636
- if (open) {
637
- tabsRef.current?.focus();
638
- }
639
- }, [
640
- open
641
- ]);
642
- const handleSelect = (index) => {
643
- if (index === selected) {
644
- setOpen(false);
645
- } else {
646
- setSelected(index);
647
- }
648
- };
649
- const title = useMemo(() => {
650
- const lines = items.map((item) => item.title).filter(isNotFalsy);
651
- return /* @__PURE__ */ React2.createElement(StatusRoll, {
652
- key: "status-roll",
653
- lines,
654
- duration: 1e3,
655
- autoAdvance: true
656
- });
657
- }, [
658
- items
659
- ]);
660
- return /* @__PURE__ */ React2.createElement(ToggleContainer, {
661
- classNames: [
662
- "flex flex-col",
663
- classNames
664
- ],
665
- title,
666
- open,
667
- onChangeOpen: setOpen
668
- }, /* @__PURE__ */ React2.createElement("div", {
669
- className: "grid grid-cols-[32px_1fr]"
670
- }, /* @__PURE__ */ React2.createElement(NumericTabs, {
671
- ref: tabsRef,
672
- length: items.length,
673
- selected,
674
- onSelect: handleSelect
675
- }), /* @__PURE__ */ React2.createElement(Json, {
676
- data: items[selected].block,
677
- classNames: "!p-1 text-xs"
678
- })));
679
- };
680
-
681
- // packages/plugins/plugin-assistant/src/components/Thread/ThreadMessage.tsx
682
- var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-assistant/src/components/Thread/ThreadMessage.tsx";
683
- var panelClassNames = "flex flex-col w-full px-2 bg-groupSurface rounded-md";
684
- var userClassNames = "bg-[--user-fill] text-inverse";
685
- var ToggleContainer2 = (props) => {
686
- return /* @__PURE__ */ React3.createElement(NativeToggleContainer, {
687
- ...props,
688
- classNames: mx2(panelClassNames, props.classNames)
689
- });
263
+ ],
264
+ closeOnBlur: !debug,
265
+ tooltipClass: () => "shadow rounded",
266
+ aboveCursor: true
267
+ }),
268
+ keymap2.of(completionKeymap)
269
+ ];
690
270
  };
691
- var MessageContainer = ({ children, classNames, user }) => {
692
- if (!children) {
693
- return null;
271
+ var ReferenceWidget = class extends WidgetType2 {
272
+ constructor(data) {
273
+ super(), this.data = data;
694
274
  }
695
- return /* @__PURE__ */ React3.createElement("div", {
696
- role: "list-item",
697
- className: mx2("flex w-full", user && "justify-end", classNames)
698
- }, /* @__PURE__ */ React3.createElement("div", {
699
- className: mx2(user ? [
700
- "px-2 py-1 rounded-md",
701
- userClassNames
702
- ] : "w-full")
703
- }, children));
704
- };
705
- var ThreadMessage = ({ classNames, space, message, tools, onPrompt }) => {
706
- const { role, content = [] } = message;
707
- if (isToolMessage(message)) {
708
- return /* @__PURE__ */ React3.createElement(MessageContainer, {
709
- classNames: mx2(classNames, "animate-[fadeIn_0.5s]")
710
- }, /* @__PURE__ */ React3.createElement(ToolBlock, {
711
- space,
712
- classNames: panelClassNames,
713
- message,
714
- tools
715
- }));
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;
716
286
  }
717
- return content.map((block, idx) => {
718
- if (block.type === "text" && block.text.replaceAll(/\s+/g, "").length === 0) {
719
- return null;
720
- }
721
- const Component = components[block.type] ?? components.default;
722
- return /* @__PURE__ */ React3.createElement(MessageContainer, {
723
- key: idx,
724
- classNames: mx2(classNames, "animate-[fadeIn_0.5s]"),
725
- user: block.type === "text" && role === "user"
726
- }, /* @__PURE__ */ React3.createElement(Component, {
727
- space,
728
- block,
729
- onPrompt
730
- }));
731
- });
732
287
  };
733
- var components = {
734
- //
735
- // Text
736
- //
737
- ["text"]: ({ block }) => {
738
- invariant2(block.type === "text", void 0, {
739
- F: __dxlog_file5,
740
- L: 90,
741
- S: void 0,
742
- A: [
743
- "block.type === 'text'",
744
- ""
745
- ]
746
- });
747
- const title = block.disposition ? titles[block.disposition] : void 0;
748
- if (!title) {
749
- return /* @__PURE__ */ React3.createElement(MarkdownViewer, {
750
- classNames: "[&>p]:animate-[fadeIn_0.5s]",
751
- content: block.text
752
- });
753
- }
754
- return /* @__PURE__ */ React3.createElement(ToggleContainer2, {
755
- // open={open}
756
- defaultOpen: systemDispositions.includes(block.disposition ?? "") && block.pending,
757
- title,
758
- icon: block.pending ? /* @__PURE__ */ React3.createElement(Icon, {
759
- icon: "ph--circle-notch--regular",
760
- classNames: "text-subdued ml-2 animate-spin",
761
- size: 4
762
- }) : void 0
763
- }, /* @__PURE__ */ React3.createElement(MarkdownViewer, {
764
- content: block.text,
765
- classNames: [
766
- "pbe-2",
767
- systemDispositions.includes(block.disposition ?? "") && "text-sm text-subdued"
768
- ]
769
- }));
770
- },
771
- //
772
- // JSON
773
- //
774
- ["json"]: ({ space, block, onPrompt }) => {
775
- invariant2(block.type === "json", void 0, {
776
- F: __dxlog_file5,
777
- L: 128,
778
- S: void 0,
779
- A: [
780
- "block.type === 'json'",
781
- ""
782
- ]
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)
783
366
  });
784
- switch (block.disposition) {
785
- case "tool_list": {
786
- return /* @__PURE__ */ React3.createElement(ToggleContainer2, {
787
- title: titles[block.disposition],
788
- defaultOpen: true
789
- }, /* @__PURE__ */ React3.createElement(ToolboxContainer, {
790
- space,
791
- classNames: "pbe-2"
792
- }));
793
- }
794
- case "suggest": {
795
- const { text = "" } = safeParseJson(block.json ?? "{}") ?? {};
796
- return /* @__PURE__ */ React3.createElement(IconButton, {
797
- icon: "ph--lightning--regular",
798
- label: text,
799
- onClick: () => onPrompt?.(text)
800
- });
801
- }
802
- case "select": {
803
- const { options = [] } = safeParseJson(block.json ?? "{}") ?? {};
804
- return /* @__PURE__ */ React3.createElement("div", {
805
- className: "flex flex-wrap gap-1"
806
- }, options.map((option, idx) => /* @__PURE__ */ React3.createElement(Button, {
807
- classNames: "animate-[fadeIn_0.5s] rounded-2xl text-sm",
808
- key: option,
809
- onClick: () => onPrompt?.(option)
810
- }, option)));
811
- }
812
- default: {
813
- const title = block.disposition ? titles[block.disposition] : void 0;
814
- return /* @__PURE__ */ React3.createElement(ToggleContainer2, {
815
- title: title ?? "JSON"
816
- }, /* @__PURE__ */ React3.createElement(Json2, {
817
- data: safeParseJson(block.json ?? block),
818
- classNames: "!p-1 text-xs"
819
- }));
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();
820
390
  }
821
- }
822
- },
823
- //
824
- // Default
825
- //
826
- default: ({ block }) => {
827
- let title = titles[block.type];
828
- if (block.type === "tool_use") {
829
- title = `Tool [${block.name}]`;
830
- }
831
- return /* @__PURE__ */ React3.createElement(ToggleContainer2, {
832
- title: title ?? "JSON"
833
- }, /* @__PURE__ */ React3.createElement(Json2, {
834
- data: block,
835
- classNames: "!p-1 text-xs"
836
- }));
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();
837
439
  }
440
+ });
441
+
442
+ // packages/plugins/plugin-assistant/src/components/Toolbox/Toolbox.tsx
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";
446
+ import { Capabilities, useCapabilities } from "@dxos/app-framework";
447
+ import { FunctionType } from "@dxos/functions";
448
+ import { log as log3 } from "@dxos/log";
449
+ import { Filter, useQuery } from "@dxos/react-client/echo";
450
+ import { mx as mx3 } from "@dxos/react-ui-theme";
451
+
452
+ // packages/plugins/plugin-assistant/src/tools/function.ts
453
+ import { createTool, ToolResult } from "@dxos/ai";
454
+ import { toEffectSchema } from "@dxos/echo-schema";
455
+ import { getInvocationUrl, getUserFunctionUrlInMetadata } from "@dxos/functions";
456
+ import { log } from "@dxos/log";
457
+ import { getMeta } from "@dxos/react-client/echo";
458
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/plugin-assistant/src/tools/function.ts";
459
+ var convertFunctionToTool = (fn, edgeUrl, spaceId) => {
460
+ if (!fn.description || !fn.inputSchema) {
461
+ return void 0;
462
+ }
463
+ const existingFunctionUrl = getUserFunctionUrlInMetadata(getMeta(fn));
464
+ if (!existingFunctionUrl) {
465
+ return void 0;
466
+ }
467
+ const url = getInvocationUrl(existingFunctionUrl, edgeUrl, {
468
+ spaceId
469
+ });
470
+ return createTool("user-function", {
471
+ name: fn.name,
472
+ description: fn.description,
473
+ schema: toEffectSchema(fn.inputSchema),
474
+ execute: async (input) => {
475
+ log.info("execute function tool", {
476
+ name: fn.name,
477
+ url,
478
+ input
479
+ }, {
480
+ F: __dxlog_file,
481
+ L: 34,
482
+ S: void 0,
483
+ C: (f, a) => f(...a)
484
+ });
485
+ const response = await fetch(url, {
486
+ method: "POST",
487
+ headers: {
488
+ "Content-Type": "application/json"
489
+ },
490
+ body: JSON.stringify(input)
491
+ });
492
+ return ToolResult.Success(await response.text());
493
+ }
494
+ });
838
495
  };
839
- var titles = {
840
- ["cot"]: "Chain of thought",
841
- ["artifact"]: "Artifact",
842
- ["tool_use"]: "Tool request",
843
- ["tool_result"]: "Tool result",
844
- ["tool_list"]: "Tools",
845
- ["artifact-update"]: "Artifact(s) changed"
846
- };
847
- var systemDispositions = [
848
- "cot",
849
- "artifact-update"
850
- ];
851
496
 
852
- // packages/plugins/plugin-assistant/src/components/Thread/reducer.ts
853
- var messageReducer = ({ current, messages }, message) => {
854
- let i = 0;
855
- for (const block of message.content) {
856
- switch (block.type) {
857
- case "tool_use":
858
- case "tool_result": {
859
- if (current) {
860
- current.content.push(block);
861
- } else {
862
- current = {
863
- id: [
864
- message.id,
865
- i
866
- ].join("_"),
867
- role: message.role,
868
- content: [
869
- block
870
- ]
871
- };
872
- messages.push(current);
497
+ // packages/plugins/plugin-assistant/src/tools/openapi.ts
498
+ import { Schema } from "effect";
499
+ import jsonpointer from "jsonpointer";
500
+ import { ToolResult as ToolResult2, createRawTool } from "@dxos/ai";
501
+ import { JsonSchemaType, normalizeSchema, toEffectSchema as toEffectSchema2 } from "@dxos/echo-schema";
502
+ import { invariant } from "@dxos/invariant";
503
+ import { log as log2 } from "@dxos/log";
504
+ import { deepMapValues } from "@dxos/util";
505
+ var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-assistant/src/tools/openapi.ts";
506
+ var createToolsFromService = async (service) => {
507
+ invariant(service.interfaces?.length === 1 && service.interfaces[0].kind === "api", void 0, {
508
+ F: __dxlog_file2,
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, {
518
+ F: __dxlog_file2,
519
+ L: 25,
520
+ S: void 0,
521
+ A: [
522
+ "iface.schemaUrl",
523
+ ""
524
+ ]
525
+ });
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
544
+ }, {
545
+ F: __dxlog_file2,
546
+ L: 36,
547
+ S: void 0,
548
+ C: (f, a) => f(...a)
549
+ });
550
+ const tools = [];
551
+ for (const [path, pathItem] of Object.entries(spec.paths)) {
552
+ if (typeof pathItem !== "object") {
553
+ continue;
554
+ }
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
562
+ }, {
563
+ F: __dxlog_file2,
564
+ L: 47,
565
+ S: void 0,
566
+ C: (f, a) => f(...a)
567
+ });
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
+ }
873
599
  }
874
- break;
875
600
  }
876
- case "text":
877
- default: {
878
- current = void 0;
879
- messages.push({
880
- id: [
881
- message.id,
882
- i
883
- ].join("_"),
884
- role: message.role,
885
- content: [
886
- block
887
- ]
601
+ log2("inputSchema", {
602
+ inputSchema
603
+ }, {
604
+ F: __dxlog_file2,
605
+ L: 88,
606
+ S: void 0,
607
+ C: (f, a) => f(...a)
608
+ });
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)
888
620
  });
889
- break;
621
+ continue;
890
622
  }
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}
635
+
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
+ );
891
644
  }
892
- i++;
893
645
  }
894
- return {
895
- current,
896
- messages
897
- };
646
+ return tools;
898
647
  };
899
-
900
- // packages/plugins/plugin-assistant/src/components/Prompt/Prompt.tsx
901
- import { Prec as Prec2 } from "@codemirror/state";
902
- import React4, { forwardRef, useImperativeHandle } from "react";
903
- import { useThemeContext } from "@dxos/react-ui";
904
- import { createBasicExtensions, createThemeExtensions, keymap as keymap3, useTextEditor } from "@dxos/react-ui-editor";
905
- import { mx as mx3 } from "@dxos/react-ui-theme";
906
-
907
- // packages/plugins/plugin-assistant/src/components/Prompt/autocomplete.ts
908
- import { Prec } from "@codemirror/state";
909
- import { EditorView, Decoration, ViewPlugin, keymap, WidgetType } from "@codemirror/view";
910
- var createAutocompleteExtension = ({ onSubmit, onSuggest }) => {
911
- const suggestionPlugin = ViewPlugin.fromClass(class {
912
- constructor(view) {
913
- this._currentSuggestion = null;
914
- this._decorations = this.computeDecorations(view);
915
- }
916
- update(update) {
917
- if (update.docChanged || update.selectionSet) {
918
- this._decorations = this.computeDecorations(update.view);
648
+ var getToolName = (path, method, methodItem) => {
649
+ if (methodItem.operationId) {
650
+ return methodItem.operationId;
651
+ }
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;
919
659
  }
920
660
  }
921
- computeDecorations(view) {
922
- const text = view.state.doc.toString();
923
- const suggestions = onSuggest?.(text) ?? [];
924
- if (!suggestions.length) {
925
- this._currentSuggestion = null;
926
- return Decoration.none;
927
- }
928
- this._currentSuggestion = suggestions[0];
929
- const suffix = this._currentSuggestion.slice(text.length);
930
- if (!suffix) {
931
- return Decoration.none;
932
- }
933
- return Decoration.set([
934
- Decoration.widget({
935
- widget: new InlineSuggestionWidget(suffix),
936
- side: 1
937
- }).range(view.state.doc.length)
938
- ]);
661
+ name = name.replaceAll("__", "_").replace(/_$/, "");
662
+ const lengthAfter = name.length;
663
+ if (lengthBefore === lengthAfter) {
664
+ break;
665
+ }
666
+ }
667
+ name = name.replaceAll("__", "_").replace(/_$/, "").replace(/^_/, "");
668
+ return name.slice(0, MAX_TOOL_NAME_LENGTH);
669
+ };
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"
688
+ ];
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;
939
710
  }
940
- completeSuggestion(view) {
941
- if (!this._currentSuggestion) {
942
- return false;
711
+ switch (parameter.in) {
712
+ case "header": {
713
+ if (parameter.example) {
714
+ request.headers[parameter.name] = parameter.default;
715
+ }
716
+ break;
943
717
  }
944
- const text = view.state.doc.toString();
945
- const suffix = this._currentSuggestion.slice(text.length);
946
- if (!suffix) {
947
- return false;
718
+ case "path": {
719
+ url = url.replace(`{${parameter.name}}`, encodeURIComponent(input[parameter.name]));
720
+ break;
948
721
  }
949
- view.dispatch({
950
- changes: {
951
- from: view.state.doc.length,
952
- insert: suffix
953
- },
954
- selection: {
955
- anchor: view.state.doc.length + suffix.length
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}`);
956
728
  }
957
- });
958
- return true;
729
+ body = value;
730
+ break;
731
+ }
732
+ case "query": {
733
+ query.set(parameter.name, input[parameter.name]);
734
+ break;
735
+ }
959
736
  }
737
+ }
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
960
753
  }, {
961
- decorations: (v) => v._decorations
754
+ F: __dxlog_file2,
755
+ L: 243,
756
+ S: void 0,
757
+ C: (f, a) => f(...a)
962
758
  });
963
- return [
964
- suggestionPlugin,
965
- EditorView.theme({
966
- ".cm-inline-suggestion": {
967
- opacity: 0.4
968
- }
969
- }),
970
- // Accept the current suggestion.
971
- Prec.highest(keymap.of([
972
- {
973
- key: "Tab",
974
- preventDefault: true,
975
- run: (view) => {
976
- const plugin = view.plugin(suggestionPlugin);
977
- return plugin?.completeSuggestion(view) ?? false;
978
- }
979
- },
980
- {
981
- key: "ArrowRight",
982
- preventDefault: true,
983
- run: (view) => {
984
- if (view.state.selection.main.head !== view.state.doc.length) {
985
- return false;
986
- }
987
- const plugin = view.plugin(suggestionPlugin);
988
- return plugin?.completeSuggestion(view) ?? false;
989
- }
990
- },
991
- {
992
- key: "Enter",
993
- preventDefault: true,
994
- run: (view) => {
995
- const text = view.state.doc.toString().trim();
996
- if (text.length > 0 && onSubmit) {
997
- const reset = onSubmit(text);
998
- if (reset) {
999
- view.dispatch({
1000
- changes: {
1001
- from: 0,
1002
- to: view.state.doc.length,
1003
- insert: ""
1004
- }
1005
- });
1006
- }
1007
- }
1008
- return true;
1009
- }
1010
- },
1011
- {
1012
- key: "Shift-Enter",
1013
- preventDefault: true,
1014
- run: (view) => {
1015
- view.dispatch({
1016
- changes: {
1017
- from: view.state.selection.main.head,
1018
- insert: "\n"
1019
- },
1020
- selection: {
1021
- anchor: view.state.selection.main.head + 1,
1022
- head: view.state.selection.main.head + 1
1023
- }
1024
- });
1025
- return true;
1026
- }
1027
- },
1028
- {
1029
- key: "Escape",
1030
- preventDefault: true,
1031
- run: (view) => {
1032
- view.dispatch({
1033
- changes: {
1034
- from: 0,
1035
- to: view.state.doc.length,
1036
- insert: ""
1037
- }
1038
- });
1039
- return true;
1040
- }
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();
776
+ }
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;
1041
785
  }
1042
- ]))
1043
- ];
1044
- };
1045
- var InlineSuggestionWidget = class extends WidgetType {
1046
- constructor(suffix) {
1047
- super();
1048
- this.suffix = suffix;
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);
806
+ }
1049
807
  }
1050
- toDOM() {
1051
- const span = document.createElement("span");
1052
- span.textContent = this.suffix;
1053
- span.className = "cm-inline-suggestion";
1054
- return span;
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}`;
1055
824
  }
1056
- eq(other) {
1057
- return other.suffix === this.suffix;
825
+ if (!isV3_1(endpoint.document) && endpoint.document.basePath) {
826
+ url += endpoint.document.basePath;
1058
827
  }
828
+ url += endpoint.path;
829
+ return url;
1059
830
  };
1060
-
1061
- // packages/plugins/plugin-assistant/src/components/Prompt/references.ts
1062
- import { autocompletion, completionKeymap } from "@codemirror/autocomplete";
1063
- import { RangeSet } from "@codemirror/state";
1064
- import { Decoration as Decoration2, EditorView as EditorView2, keymap as keymap2, ViewPlugin as ViewPlugin2, WidgetType as WidgetType2 } from "@codemirror/view";
1065
- import { Mutex } from "@dxos/async";
1066
- var promptReferences = ({ provider, debug = false, triggerCharacter = "@" }) => {
1067
- if (triggerCharacter.length !== 1) {
1068
- throw new Error("triggerCharacter must be a single character");
1069
- }
1070
- const decorationField = ViewPlugin2.fromClass(class ReferenceView {
1071
- constructor(view) {
1072
- this._mutex = new Mutex();
1073
- this.decorations = Decoration2.set([]);
1074
- queueMicrotask(async () => {
1075
- const guard = await this._mutex.acquire();
1076
- try {
1077
- this.decorations = await this._computeDecorations(view);
1078
- } finally {
1079
- guard.release();
1080
- }
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}`;
844
+ }
845
+ case "oauth": {
846
+ const response = await fetch(authorization.tokenUrl, {
847
+ method: "POST",
848
+ headers: {
849
+ "Content-Type": "application/x-www-form-urlencoded"
850
+ },
851
+ body: `grant_type=${authorization.grantType}&client_id=${authorization.clientId}&client_secret=${authorization.clientSecret}`
1081
852
  });
853
+ const data = await response.json();
854
+ return `Bearer ${data.access_token}`;
1082
855
  }
1083
- update(update) {
1084
- if (update.docChanged) {
1085
- queueMicrotask(async () => {
1086
- const guard = await this._mutex.acquire();
1087
- try {
1088
- this.decorations = await this._computeDecorations(update.view);
1089
- } finally {
1090
- guard.release();
1091
- }
1092
- });
1093
- }
856
+ default: {
857
+ throw new Error(`Unknown authorization type: ${authorization.type}`);
1094
858
  }
1095
- async _computeDecorations(view) {
1096
- const text = view.state.doc.toString();
1097
- const references = text.matchAll(new RegExp(`${triggerCharacter}[a-zA-Z0-9@:]+\\s`, "g"));
1098
- const decorations = [];
1099
- for (const match of references) {
1100
- const reference = match[0];
1101
- const uri = reference.slice(1, -1);
1102
- const data = await provider.resolveReference({
1103
- uri
1104
- });
1105
- if (data) {
1106
- decorations.push(Decoration2.replace({
1107
- widget: new ReferenceWidget(data)
1108
- }).range(match.index, match.index + reference.length));
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)
877
+ });
1109
878
  }
1110
879
  }
1111
- return Decoration2.set(decorations);
1112
880
  }
1113
- }, {
1114
- decorations: (v) => v.decorations,
1115
- provide: (plugin) => [
1116
- EditorView2.atomicRanges.of((view) => view.plugin(decorationField)?.decorations ?? RangeSet.empty)
1117
- ]
881
+ return recurse(value);
1118
882
  });
1119
- return [
1120
- decorationField,
1121
- EditorView2.theme({
1122
- ".cm-reference-pill": {
1123
- borderRadius: "0.25rem",
1124
- borderWidth: "1px",
1125
- marginRight: "0.25rem",
1126
- marginLeft: "0.25rem"
1127
- }
1128
- }),
1129
- autocompletion({
1130
- activateOnTyping: true,
1131
- override: [
1132
- async (context) => {
1133
- const match = context.matchBefore(new RegExp(`${triggerCharacter}[a-zA-Z0-9]+`));
1134
- if (!match || match?.to === match?.from) {
883
+ };
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();
924
+ }
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();
954
+ }
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();
990
+ }
991
+ };
992
+
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...";
1029
+ }
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) {
1135
1042
  return null;
1136
1043
  }
1137
- const query = match.text.slice(1);
1138
- const references = await provider.getReferences({
1139
- 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)
1140
1052
  });
1053
+ request = {
1054
+ tool: tools?.find((tool) => tool.name === block.name),
1055
+ block
1056
+ };
1141
1057
  return {
1142
- from: match.from,
1143
- filter: false,
1144
- options: references.map((reference) => ({
1145
- label: reference.label,
1146
- apply: `${triggerCharacter}${reference.uri} `
1147
- }))
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
1148
1087
  };
1149
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
1150
1134
  ],
1151
- closeOnBlur: !debug,
1152
- tooltipClass: () => "shadow rounded",
1153
- aboveCursor: true
1154
- }),
1155
- keymap2.of(completionKeymap)
1156
- ];
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
+ }
1157
1152
  };
1158
- var ReferenceWidget = class extends WidgetType2 {
1159
- constructor(data) {
1160
- super();
1161
- 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();
1162
1167
  }
1163
- toDOM() {
1164
- const span = document.createElement("span");
1165
- span.textContent = `@ ${this.data.label}`;
1166
- span.className = "cm-reference-pill";
1167
- 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();
1168
1186
  }
1169
- eq(other) {
1170
- 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();
1171
1220
  }
1172
- ignoreEvent() {
1173
- 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
+ }));
1174
1344
  }
1175
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
+ ];
1176
1358
 
1177
- // packages/plugins/plugin-assistant/src/components/Prompt/Prompt.tsx
1178
- var Prompt = /* @__PURE__ */ forwardRef(({ classNames, autoFocus, lineWrapping = false, placeholder, onSubmit, onSuggest, onOpenChange, references }, forwardRef2) => {
1179
- const { themeMode } = useThemeContext();
1180
- const { parentRef, view } = useTextEditor({
1181
- debug: true,
1182
- autoFocus,
1183
- extensions: [
1184
- createBasicExtensions({
1185
- bracketMatching: false,
1186
- lineWrapping,
1187
- placeholder
1188
- }),
1189
- createThemeExtensions({
1190
- themeMode
1191
- }),
1192
- references ? promptReferences({
1193
- provider: references
1194
- }) : [],
1195
- createAutocompleteExtension({
1196
- onSubmit,
1197
- onSuggest
1198
- }),
1199
- Prec2.highest(keymap3.of([
1200
- {
1201
- key: "cmd-ArrowUp",
1202
- preventDefault: true,
1203
- run: (view2) => {
1204
- onOpenChange?.(true);
1205
- return true;
1206
- }
1207
- },
1208
- {
1209
- key: "cmd-ArrowDown",
1210
- preventDefault: true,
1211
- run: (view2) => {
1212
- onOpenChange?.(false);
1213
- return true;
1214
- }
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);
1215
1380
  }
1216
- ]))
1217
- ]
1218
- }, [
1219
- themeMode,
1220
- onSubmit,
1221
- onSuggest
1222
- ]);
1223
- useImperativeHandle(forwardRef2, () => {
1224
- return {
1225
- focus: () => {
1226
- view?.focus();
1227
- },
1228
- setText: (text) => {
1229
- view?.dispatch({
1230
- changes: {
1231
- from: 0,
1232
- to: view.state.doc.length,
1233
- insert: text
1234
- },
1235
- selection: {
1236
- anchor: text.length,
1237
- head: text.length
1238
- }
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
+ ]
1239
1395
  });
1396
+ break;
1240
1397
  }
1241
- };
1242
- }, [
1243
- view,
1244
- onSubmit
1245
- ]);
1246
- return /* @__PURE__ */ React4.createElement("div", {
1247
- ref: parentRef,
1248
- className: mx3("w-full", classNames)
1249
- });
1250
- });
1251
-
1252
- // packages/plugins/plugin-assistant/src/components/Prompt/PromptBar.tsx
1253
- import React5, { useRef as useRef2, useState as useState3 } from "react";
1254
- import { useVoiceInput } from "@dxos/plugin-transcription";
1255
- import { Icon as Icon2, IconButton as IconButton2, Tooltip, useTranslation } from "@dxos/react-ui";
1256
- import { Spinner } from "@dxos/react-ui-sfx";
1257
- import { errorMessageColors, errorText, mx as mx4 } from "@dxos/react-ui-theme";
1258
- var PromptBar = ({ classNames, placeholder, processing, error, microphone, onCancel, references, ...props }) => {
1259
- const { t } = useTranslation(ASSISTANT_PLUGIN);
1260
- const promptRef = useRef2(null);
1261
- const [active, setActive] = useState3(false);
1262
- const { recording } = useVoiceInput({
1263
- active,
1264
- onUpdate: (text) => {
1265
- promptRef.current?.setText(text);
1266
- promptRef.current?.focus();
1267
1398
  }
1268
- });
1269
- return /* @__PURE__ */ React5.createElement("div", {
1270
- className: mx4("shrink-0 w-full grid grid-cols-[var(--rail-action)_1fr_var(--rail-action)] overflow-hidden", classNames)
1271
- }, /* @__PURE__ */ React5.createElement("div", {
1272
- className: "flex w-[--rail-action] h-[--rail-action] items-center justify-center"
1273
- }, error && /* @__PURE__ */ React5.createElement(Tooltip.Root, {
1274
- delayDuration: 0
1275
- }, /* @__PURE__ */ React5.createElement(Tooltip.Trigger, null, /* @__PURE__ */ React5.createElement(Icon2, {
1276
- icon: "ph--warning-circle--regular",
1277
- classNames: errorText,
1278
- size: 5
1279
- })), /* @__PURE__ */ React5.createElement(Tooltip.Portal, null, /* @__PURE__ */ React5.createElement(Tooltip.Content, null, /* @__PURE__ */ React5.createElement("div", {
1280
- className: mx4("text-sm", errorMessageColors)
1281
- }, error.message), /* @__PURE__ */ React5.createElement(Tooltip.Arrow, null)))) || /* @__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
1388
- import React7, { useCallback as useCallback3, useEffect as useEffect6 } from "react";
1484
+ import { useSignals as _useSignals9 } from "@preact-signals/safe-react/tracking";
1485
+ import React7, { useCallback as useCallback3, useEffect as useEffect5 } from "react";
1389
1486
  import { CollaborationActions, createIntent, useIntentDispatcher as useIntentDispatcher2 } from "@dxos/app-framework";
1390
- import { invariant as invariant6 } from "@dxos/invariant";
1391
- import { DXN as DXN3 } from "@dxos/keys";
1392
- import { makeRef, refFromDXN } from "@dxos/live-object";
1393
- import { log as log10 } from "@dxos/log";
1487
+ import { invariant as invariant4 } from "@dxos/invariant";
1488
+ import { DXN } from "@dxos/keys";
1489
+ import { refFromDXN } from "@dxos/live-object";
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
- import { FunctionType as FunctionType2 } from "@dxos/functions/types";
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-OK5SMYJC.mjs"));
1590
- var AppGraphBuilder = lazy(() => import("./app-graph-builder-ZXKGE3H5.mjs"));
1591
- var IntentResolver = lazy(() => import("./intent-resolver-W6XREK5F.mjs"));
1592
- var ReactSurface = lazy(() => import("./react-surface-QMI5KG4H.mjs"));
1593
- var Settings = lazy(() => import("./settings-LAJZQI4H.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,142 +1729,127 @@ 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.schema(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.schema(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) => covertFunctionToTool(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
- // packages/plugins/plugin-assistant/src/hooks/useLocalTriggerManager.ts
1694
- import { useEffect as useEffect4, useState as useState5 } from "react";
1695
- import { Mutex as Mutex2 } from "@dxos/async";
1696
- import { Context } from "@dxos/context";
1697
- import { createSubscriptionTrigger } from "@dxos/functions";
1698
- import { FunctionTrigger } from "@dxos/functions/types";
1699
- import { invariant as invariant5 } from "@dxos/invariant";
1700
- import { log as log8 } from "@dxos/log";
1701
- import { useClient } from "@dxos/react-client";
1702
- import { Filter as Filter3, useQuery as useQuery3 } from "@dxos/react-client/echo";
1703
-
1704
- // packages/plugins/plugin-assistant/src/hooks/invocation-handler.ts
1705
- import { sleep } from "@dxos/async";
1706
- import { getObjectCore, ResultFormat } from "@dxos/echo-db";
1707
- import { FunctionType as FunctionType3, getUserFunctionUrlInMetadata as getUserFunctionUrlInMetadata2 } from "@dxos/functions/types";
1708
- import { invariant as invariant4 } from "@dxos/invariant";
1709
- import { DXN, LOCAL_SPACE_TAG } from "@dxos/keys";
1710
- import { log as log7 } from "@dxos/log";
1711
-
1712
- // packages/plugins/plugin-assistant/src/hooks/useLocalTriggerManager.ts
1713
- var registerTriggersMutex = new Mutex2();
1714
-
1715
1825
  // packages/plugins/plugin-assistant/src/hooks/useMessageQueue.ts
1716
1826
  import { useMemo as useMemo4 } from "react";
1717
- import { DXN as DXN2, QueueSubspaceTags } from "@dxos/keys";
1827
+ import { createQueueDxn } from "@dxos/echo-schema";
1718
1828
  import { getSpace, useQueue } from "@dxos/react-client/echo";
1719
1829
  var useMessageQueue = (chat) => {
1720
1830
  const space = getSpace(chat);
1721
1831
  const queueDxn = useMemo4(() => {
1722
- const dxn = space && chat?.assistantChatQueue.dxn;
1723
- return dxn ? new DXN2(DXN2.kind.QUEUE, [
1724
- QueueSubspaceTags.DATA,
1725
- space.id,
1726
- dxn.parts.at(-1)
1727
- ]) : void 0;
1832
+ const dxn = space && chat?.queue.dxn;
1833
+ return dxn ? createQueueDxn(space.id, dxn.parts.at(-1)) : void 0;
1728
1834
  }, [
1729
1835
  space,
1730
- chat?.assistantChatQueue.dxn
1836
+ chat?.queue.dxn
1731
1837
  ]);
1732
1838
  return useQueue(queueDxn);
1733
1839
  };
1734
1840
 
1735
1841
  // packages/plugins/plugin-assistant/src/hooks/useServices.ts
1736
- import { useEffect as useEffect5, useMemo as useMemo5, useState as useState6 } from "react";
1842
+ import { useEffect as useEffect4, useMemo as useMemo5, useState as useState5 } from "react";
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";
1737
1849
 
1738
1850
  // packages/plugins/plugin-assistant/src/testing/test-functions.ts
1851
+ import { DEFAULT_EDGE_MODEL as DEFAULT_EDGE_MODEL3 } from "@dxos/ai";
1739
1852
  import { createSystemPrompt as createSystemPrompt2 } from "@dxos/artifact";
1740
- import { DEFAULT_EDGE_MODEL as DEFAULT_EDGE_MODEL3 } from "@dxos/assistant";
1741
1853
 
1742
1854
  // packages/plugins/plugin-assistant/src/testing/test-services.ts
1743
1855
  import { create } from "@dxos/echo-schema";
@@ -1829,14 +1941,16 @@ var TEST_SERVICES = [
1829
1941
  ];
1830
1942
 
1831
1943
  // packages/plugins/plugin-assistant/src/hooks/useTextInputEvents.ts
1832
- import { useState as useState7, useCallback as useCallback2 } from "react";
1944
+ import { useSignals as _useSignals8 } from "@preact-signals/safe-react/tracking";
1945
+ import { useState as useState6, useCallback as useCallback2 } from "react";
1833
1946
 
1834
1947
  // packages/plugins/plugin-assistant/src/hooks/useContextProvider.ts
1835
1948
  import { useMemo as useMemo6 } from "react";
1836
1949
  import { Capabilities as Capabilities3, useCapabilities as useCapabilities3 } from "@dxos/app-framework";
1837
- import { getDXN, getLabel, getSchema } from "@dxos/echo-schema";
1838
- import { log as log9 } from "@dxos/log";
1839
- import { Filter as Filter4 } from "@dxos/react-client/echo";
1950
+ import { Filter as Filter4 } from "@dxos/client/echo";
1951
+ import { Obj } from "@dxos/echo";
1952
+ import { getDXN, getLabel } from "@dxos/echo-schema";
1953
+ import { log as log7 } from "@dxos/log";
1840
1954
  var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-assistant/src/hooks/useContextProvider.ts";
1841
1955
  var stringMatch = (query, label) => label.toLowerCase().startsWith(query.toLowerCase());
1842
1956
  var useContextProvider = (space) => {
@@ -1848,30 +1962,28 @@ var useContextProvider = (space) => {
1848
1962
  return {
1849
1963
  query: async ({ query }) => {
1850
1964
  const artifactSchemas = artifactDefinitions.map((artifact) => artifact.schema);
1851
- const { objects } = await space.db.query(Filter4.or(...artifactSchemas.map((schema) => Filter4.schema(schema)))).run();
1965
+ const { objects } = await space.db.query(Filter4.or(...artifactSchemas.map((schema) => Filter4.type(schema)))).run();
1852
1966
  return objects.map((object) => {
1853
- log9.info("object", {
1967
+ log7.info("object", {
1854
1968
  object,
1855
- label: getLabel(getSchema(object), object)
1969
+ label: getLabel(Obj.getSchema(object), object)
1856
1970
  }, {
1857
1971
  F: __dxlog_file8,
1858
- L: 36,
1972
+ L: 38,
1859
1973
  S: void 0,
1860
1974
  C: (f, a) => f(...a)
1861
1975
  });
1862
1976
  return object;
1863
- }).filter((object) => stringMatch(query, getLabel(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) => ({
1864
1978
  uri: getDXN(object).toString(),
1865
- label: getLabel(getSchema(object), object) ?? ""
1979
+ label: getLabel(Obj.getSchema(object), object) ?? ""
1866
1980
  }));
1867
1981
  },
1868
1982
  resolveMetadata: async ({ uri }) => {
1869
- const object = await space.db.query({
1870
- id: uri
1871
- }).first();
1983
+ const object = await space.db.query(Filter4.ids(uri)).first();
1872
1984
  return {
1873
1985
  uri,
1874
- label: getLabel(getSchema(object), object) ?? ""
1986
+ label: getLabel(Obj.getSchema(object), object) ?? ""
1875
1987
  };
1876
1988
  }
1877
1989
  };
@@ -1884,97 +1996,103 @@ var useContextProvider = (space) => {
1884
1996
  // packages/plugins/plugin-assistant/src/components/Thread/ThreadContainer.tsx
1885
1997
  var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-assistant/src/components/Thread/ThreadContainer.tsx";
1886
1998
  var ThreadContainer = ({ classNames, chat, settings, part, associatedArtifact, onOpenChange, ...props }) => {
1887
- const space = getSpace2(chat);
1888
- const contextProvider = useContextProvider(space);
1889
- const processor = useChatProcessor({
1890
- chat,
1891
- space,
1892
- settings,
1893
- part,
1894
- associatedArtifact
1895
- });
1896
- const messageQueue = useMessageQueue(chat);
1897
- const { dispatchPromise: dispatch } = useIntentDispatcher2();
1898
- const messages = [
1899
- ...messageQueue?.items ?? [],
1900
- ...processor.messages.value
1901
- ];
1902
- useEffect6(() => {
1903
- if (!processor.streaming.value && messageQueue?.items) {
1904
- const message = messageQueue.items[messageQueue.items.length - 1];
1905
- if (space && chat && message && dispatch && associatedArtifact) {
1906
- void dispatch(createIntent(CollaborationActions.InsertContent, {
1907
- spaceId: space.id,
1908
- target: makeRef(associatedArtifact),
1909
- object: refFromDXN(new DXN3(DXN3.kind.QUEUE, [
1910
- ...chat.assistantChatQueue.dxn.parts,
1911
- message.id
1912
- ])),
1913
- label: "View proposal"
1914
- }));
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
+ }
1915
2029
  }
1916
- }
1917
- }, [
1918
- messageQueue,
1919
- associatedArtifact,
1920
- processor.streaming.value
1921
- ]);
1922
- const handleSubmit = useCallback3((text) => {
1923
- if (processor.streaming.value) {
1924
- log10.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, {
1925
2047
  F: __dxlog_file9,
1926
- L: 66,
2048
+ L: 71,
1927
2049
  S: void 0,
1928
- C: (f, a) => f(...a)
2050
+ A: [
2051
+ "messageQueue",
2052
+ ""
2053
+ ]
1929
2054
  });
1930
- return false;
1931
- }
1932
- onOpenChange?.(true);
1933
- invariant6(messageQueue, void 0, {
1934
- F: __dxlog_file9,
1935
- L: 72,
1936
- S: void 0,
1937
- A: [
1938
- "messageQueue",
1939
- ""
1940
- ]
1941
- });
1942
- void processor.request(text, {
1943
- history: messageQueue.items,
1944
- onComplete: (messages2) => {
1945
- 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();
1946
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
1947
2087
  });
1948
- return true;
1949
- }, [
1950
- processor,
1951
- messageQueue,
1952
- onOpenChange
1953
- ]);
1954
- const handleCancel = useCallback3(() => {
1955
- if (processor.streaming.value) {
1956
- void processor.cancel();
1957
- }
1958
- }, [
1959
- processor
1960
- ]);
1961
- return /* @__PURE__ */ React7.createElement(Thread, {
1962
- classNames,
1963
- space,
1964
- messages,
1965
- processing: processor.streaming.value,
1966
- error: processor.error.value,
1967
- tools: processor.tools,
1968
- contextProvider,
1969
- onSubmit: handleSubmit,
1970
- onCancel: handleCancel,
1971
- onPrompt: handleSubmit,
1972
- onOpenChange,
1973
- ...props
1974
- });
2088
+ } finally {
2089
+ _effect.f();
2090
+ }
1975
2091
  };
1976
2092
 
1977
2093
  export {
2094
+ Prompt,
2095
+ PromptBar,
1978
2096
  Toolbox,
1979
2097
  ToolboxContainer,
1980
2098
  Thread,
@@ -1985,4 +2103,4 @@ export {
1985
2103
  Settings,
1986
2104
  ThreadContainer
1987
2105
  };
1988
- //# sourceMappingURL=chunk-7CAHKTZQ.mjs.map
2106
+ //# sourceMappingURL=chunk-QTW7KVDO.mjs.map