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

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