@dxos/plugin-assistant 0.8.3 → 0.8.4-main.f9ba587

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