@dxos/plugin-assistant 0.8.2-staging.7ac8446 → 0.8.2

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