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