@dxos/plugin-assistant 0.8.4-main.28f8d3d → 0.8.4-main.406dc2a

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 (476) hide show
  1. package/dist/lib/browser/{BlueprintContainer-H7H4BQ2C.mjs → BlueprintContainer-WX2SSDVI.mjs} +6 -7
  2. package/dist/lib/browser/{BlueprintContainer-H7H4BQ2C.mjs.map → BlueprintContainer-WX2SSDVI.mjs.map} +3 -3
  3. package/dist/lib/browser/ChatCompanion-BDZ55ZRF.mjs +150 -0
  4. package/dist/lib/browser/ChatCompanion-BDZ55ZRF.mjs.map +7 -0
  5. package/dist/lib/browser/{ChatContainer-OUVSX5V5.mjs → ChatContainer-RYGNN73X.mjs} +20 -23
  6. package/dist/lib/browser/ChatContainer-RYGNN73X.mjs.map +7 -0
  7. package/dist/lib/browser/{ChatDialog-P4FLEOHG.mjs → ChatDialog-MVHH2U66.mjs} +12 -12
  8. package/dist/lib/browser/ChatDialog-MVHH2U66.mjs.map +7 -0
  9. package/dist/lib/browser/{SequenceContainer-627OQ557.mjs → SequenceContainer-2FEWMQGW.mjs} +6 -19
  10. package/dist/lib/browser/SequenceContainer-2FEWMQGW.mjs.map +7 -0
  11. package/dist/lib/browser/ai-service-ERTZBTP3.mjs +19 -0
  12. package/dist/lib/browser/ai-service-ERTZBTP3.mjs.map +7 -0
  13. package/dist/lib/browser/{app-graph-builder-AVHHQ3KV.mjs → app-graph-builder-2U7SLCRX.mjs} +22 -34
  14. package/dist/lib/browser/app-graph-builder-2U7SLCRX.mjs.map +7 -0
  15. package/dist/lib/browser/blueprint-definition-NSJARW5U.mjs +12 -0
  16. package/dist/lib/browser/blueprint-definition-NSJARW5U.mjs.map +7 -0
  17. package/dist/lib/browser/{blueprint-definition-CMGIZAOW.mjs → chunk-2CE2KPKZ.mjs} +69 -40
  18. package/dist/lib/browser/chunk-2CE2KPKZ.mjs.map +7 -0
  19. package/dist/lib/browser/chunk-43I2LR6O.mjs +216 -0
  20. package/dist/lib/browser/chunk-43I2LR6O.mjs.map +7 -0
  21. package/dist/lib/browser/chunk-5EGXHCAZ.mjs +16 -0
  22. package/dist/lib/browser/chunk-5EGXHCAZ.mjs.map +7 -0
  23. package/dist/lib/browser/chunk-5RICKAMN.mjs +18 -0
  24. package/dist/lib/browser/chunk-5RICKAMN.mjs.map +7 -0
  25. package/dist/lib/browser/chunk-CQ7UHYTT.mjs +296 -0
  26. package/dist/lib/browser/chunk-CQ7UHYTT.mjs.map +7 -0
  27. package/dist/lib/browser/{chunk-HRLMD35M.mjs → chunk-FP56WB24.mjs} +36 -15
  28. package/dist/lib/browser/chunk-FP56WB24.mjs.map +7 -0
  29. package/dist/lib/browser/chunk-JZRZVB2A.mjs +170 -0
  30. package/dist/lib/browser/chunk-JZRZVB2A.mjs.map +7 -0
  31. package/dist/lib/browser/chunk-WRJGOT5P.mjs +1794 -0
  32. package/dist/lib/browser/chunk-WRJGOT5P.mjs.map +7 -0
  33. package/dist/lib/browser/edge-model-resolver-O6OFYIO2.mjs +18 -0
  34. package/dist/lib/browser/edge-model-resolver-O6OFYIO2.mjs.map +7 -0
  35. package/dist/lib/browser/index.mjs +127 -54
  36. package/dist/lib/browser/index.mjs.map +4 -4
  37. package/dist/lib/browser/{intent-resolver-MVOIEJXZ.mjs → intent-resolver-3GOJMBXJ.mjs} +48 -15
  38. package/dist/lib/browser/intent-resolver-3GOJMBXJ.mjs.map +7 -0
  39. package/dist/lib/browser/local-model-resolver-GO6ZEMLL.mjs +17 -0
  40. package/dist/lib/browser/local-model-resolver-GO6ZEMLL.mjs.map +7 -0
  41. package/dist/lib/browser/meta.json +1 -1
  42. package/dist/lib/browser/{react-surface-4HXS3YLT.mjs → react-surface-FTKCE6GG.mjs} +20 -76
  43. package/dist/lib/browser/react-surface-FTKCE6GG.mjs.map +7 -0
  44. package/dist/lib/browser/{settings-G2EZXMWT.mjs → settings-HBF32KV6.mjs} +5 -5
  45. package/dist/lib/browser/{settings-G2EZXMWT.mjs.map → settings-HBF32KV6.mjs.map} +1 -1
  46. package/dist/lib/browser/state-LXTS54DI.mjs +21 -0
  47. package/dist/lib/browser/state-LXTS54DI.mjs.map +7 -0
  48. package/dist/lib/browser/toolkit-NQ2GXCF5.mjs +199 -0
  49. package/dist/lib/browser/toolkit-NQ2GXCF5.mjs.map +7 -0
  50. package/dist/lib/browser/types/index.mjs +2 -2
  51. package/dist/lib/node-esm/{BlueprintContainer-VH4EE4CM.mjs → BlueprintContainer-4MKN6ZRB.mjs} +6 -7
  52. package/dist/lib/node-esm/{BlueprintContainer-VH4EE4CM.mjs.map → BlueprintContainer-4MKN6ZRB.mjs.map} +3 -3
  53. package/dist/lib/node-esm/ChatCompanion-XFNXVZIP.mjs +151 -0
  54. package/dist/lib/node-esm/ChatCompanion-XFNXVZIP.mjs.map +7 -0
  55. package/dist/lib/node-esm/{ChatContainer-D5FABDNE.mjs → ChatContainer-UTJGCQXF.mjs} +20 -23
  56. package/dist/lib/node-esm/ChatContainer-UTJGCQXF.mjs.map +7 -0
  57. package/dist/lib/node-esm/{ChatDialog-NKWVXHJP.mjs → ChatDialog-QEYZ4IOV.mjs} +12 -12
  58. package/dist/lib/node-esm/ChatDialog-QEYZ4IOV.mjs.map +7 -0
  59. package/dist/lib/node-esm/{SequenceContainer-EQ5NP2PG.mjs → SequenceContainer-PGGJUQ46.mjs} +6 -19
  60. package/dist/lib/node-esm/SequenceContainer-PGGJUQ46.mjs.map +7 -0
  61. package/dist/lib/node-esm/ai-service-MUYLV3NT.mjs +20 -0
  62. package/dist/lib/node-esm/ai-service-MUYLV3NT.mjs.map +7 -0
  63. package/dist/lib/node-esm/{app-graph-builder-RMOUJMMG.mjs → app-graph-builder-OKNLR7H2.mjs} +22 -34
  64. package/dist/lib/node-esm/app-graph-builder-OKNLR7H2.mjs.map +7 -0
  65. package/dist/lib/node-esm/blueprint-definition-WD2IVMAI.mjs +13 -0
  66. package/dist/lib/node-esm/blueprint-definition-WD2IVMAI.mjs.map +7 -0
  67. package/dist/lib/node-esm/chunk-73ABYRYX.mjs +20 -0
  68. package/dist/lib/node-esm/chunk-73ABYRYX.mjs.map +7 -0
  69. package/dist/lib/node-esm/chunk-DSE2IILK.mjs +217 -0
  70. package/dist/lib/node-esm/chunk-DSE2IILK.mjs.map +7 -0
  71. package/dist/lib/node-esm/chunk-E2WXZND7.mjs +297 -0
  72. package/dist/lib/node-esm/chunk-E2WXZND7.mjs.map +7 -0
  73. package/dist/lib/node-esm/chunk-HXIBCBH4.mjs +171 -0
  74. package/dist/lib/node-esm/chunk-HXIBCBH4.mjs.map +7 -0
  75. package/dist/lib/node-esm/{chunk-F7RXCX5Y.mjs → chunk-TNR46C3L.mjs} +36 -15
  76. package/dist/lib/node-esm/chunk-TNR46C3L.mjs.map +7 -0
  77. package/dist/lib/node-esm/{blueprint-definition-AEWYMW6I.mjs → chunk-U2NYUS2N.mjs} +69 -39
  78. package/dist/lib/node-esm/chunk-U2NYUS2N.mjs.map +7 -0
  79. package/dist/lib/node-esm/chunk-UFKLCEAE.mjs +1795 -0
  80. package/dist/lib/node-esm/chunk-UFKLCEAE.mjs.map +7 -0
  81. package/dist/lib/node-esm/{chunk-X6AANUHZ.mjs → chunk-XQGWSZ4T.mjs} +4 -4
  82. package/dist/lib/node-esm/chunk-XQGWSZ4T.mjs.map +7 -0
  83. package/dist/lib/node-esm/edge-model-resolver-2ARXDOYS.mjs +19 -0
  84. package/dist/lib/node-esm/edge-model-resolver-2ARXDOYS.mjs.map +7 -0
  85. package/dist/lib/node-esm/index.mjs +127 -54
  86. package/dist/lib/node-esm/index.mjs.map +4 -4
  87. package/dist/lib/node-esm/{intent-resolver-DTDNCX3C.mjs → intent-resolver-6XLVTRDJ.mjs} +48 -15
  88. package/dist/lib/node-esm/intent-resolver-6XLVTRDJ.mjs.map +7 -0
  89. package/dist/lib/node-esm/local-model-resolver-WOQ2D2R2.mjs +18 -0
  90. package/dist/lib/node-esm/local-model-resolver-WOQ2D2R2.mjs.map +7 -0
  91. package/dist/lib/node-esm/meta.json +1 -1
  92. package/dist/lib/node-esm/{react-surface-V6JNEZVO.mjs → react-surface-K7ZXQLAP.mjs} +20 -76
  93. package/dist/lib/node-esm/react-surface-K7ZXQLAP.mjs.map +7 -0
  94. package/dist/lib/node-esm/{settings-AIP5FOJG.mjs → settings-CWP6MTWP.mjs} +5 -5
  95. package/dist/lib/node-esm/{settings-AIP5FOJG.mjs.map → settings-CWP6MTWP.mjs.map} +1 -1
  96. package/dist/lib/node-esm/state-BO6GUFLB.mjs +22 -0
  97. package/dist/lib/node-esm/state-BO6GUFLB.mjs.map +7 -0
  98. package/dist/lib/node-esm/toolkit-V57PRJNG.mjs +200 -0
  99. package/dist/lib/node-esm/toolkit-V57PRJNG.mjs.map +7 -0
  100. package/dist/lib/node-esm/types/index.mjs +2 -2
  101. package/dist/types/src/AssistantPlugin.d.ts +1 -1
  102. package/dist/types/src/AssistantPlugin.d.ts.map +1 -1
  103. package/dist/types/src/capabilities/ai-service.d.ts +2 -3
  104. package/dist/types/src/capabilities/ai-service.d.ts.map +1 -1
  105. package/dist/types/src/capabilities/app-graph-builder.d.ts +1 -1
  106. package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -1
  107. package/dist/types/src/capabilities/blueprint-definition.d.ts +5 -1
  108. package/dist/types/src/capabilities/blueprint-definition.d.ts.map +1 -1
  109. package/dist/types/src/capabilities/capabilities.d.ts +8 -8
  110. package/dist/types/src/capabilities/capabilities.d.ts.map +1 -1
  111. package/dist/types/src/capabilities/edge-model-resolver.d.ts +2 -3
  112. package/dist/types/src/capabilities/edge-model-resolver.d.ts.map +1 -1
  113. package/dist/types/src/capabilities/index.d.ts +7 -4
  114. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  115. package/dist/types/src/capabilities/intent-resolver.d.ts +1 -1
  116. package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -1
  117. package/dist/types/src/capabilities/local-model-resolver.d.ts +10 -0
  118. package/dist/types/src/capabilities/local-model-resolver.d.ts.map +1 -0
  119. package/dist/types/src/capabilities/react-surface.d.ts +1 -1
  120. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
  121. package/dist/types/src/capabilities/settings.d.ts +1 -1
  122. package/dist/types/src/capabilities/state.d.ts +4 -0
  123. package/dist/types/src/capabilities/state.d.ts.map +1 -0
  124. package/dist/types/src/capabilities/toolkit.d.ts +2 -3
  125. package/dist/types/src/capabilities/toolkit.d.ts.map +1 -1
  126. package/dist/types/src/components/AssistantSettings/AssistantSettings.d.ts.map +1 -1
  127. package/dist/types/src/components/Chat/Chat.d.ts +16 -10
  128. package/dist/types/src/components/Chat/Chat.d.ts.map +1 -1
  129. package/dist/types/src/components/Chat/events.d.ts +5 -0
  130. package/dist/types/src/components/Chat/events.d.ts.map +1 -1
  131. package/dist/types/src/components/ChatCompanion.d.ts +13 -0
  132. package/dist/types/src/components/ChatCompanion.d.ts.map +1 -0
  133. package/dist/types/src/components/ChatContainer.d.ts +3 -4
  134. package/dist/types/src/components/ChatContainer.d.ts.map +1 -1
  135. package/dist/types/src/components/ChatProgress/ChatProgress.d.ts +7 -0
  136. package/dist/types/src/components/ChatProgress/ChatProgress.d.ts.map +1 -0
  137. package/dist/types/src/components/ChatProgress/index.d.ts +2 -0
  138. package/dist/types/src/components/ChatProgress/index.d.ts.map +1 -0
  139. package/dist/types/src/components/ChatPrompt/ChatActions.d.ts.map +1 -1
  140. package/dist/types/src/components/ChatPrompt/ChatOptions.d.ts +11 -4
  141. package/dist/types/src/components/ChatPrompt/ChatOptions.d.ts.map +1 -1
  142. package/dist/types/src/components/ChatPrompt/ChatPresets.d.ts.map +1 -1
  143. package/dist/types/src/components/ChatPrompt/ChatReferences.d.ts +3 -4
  144. package/dist/types/src/components/ChatPrompt/ChatReferences.d.ts.map +1 -1
  145. package/dist/types/src/components/ChatPrompt/ChatStatusIndicator.d.ts +6 -4
  146. package/dist/types/src/components/ChatPrompt/ChatStatusIndicator.d.ts.map +1 -1
  147. package/dist/types/src/components/ChatThread/ChatThread.d.ts +12 -7
  148. package/dist/types/src/components/ChatThread/ChatThread.d.ts.map +1 -1
  149. package/dist/types/src/components/ChatThread/ChatThread.stories.d.ts +112 -56
  150. package/dist/types/src/components/ChatThread/ChatThread.stories.d.ts.map +1 -1
  151. package/dist/types/src/components/ChatThread/Link.d.ts.map +1 -1
  152. package/dist/types/src/components/ChatThread/reducers.d.ts +40 -0
  153. package/dist/types/src/components/ChatThread/reducers.d.ts.map +1 -0
  154. package/dist/types/src/components/ChatThread/registry.d.ts +11 -0
  155. package/dist/types/src/components/ChatThread/registry.d.ts.map +1 -0
  156. package/dist/types/src/components/ChatThread/sync.d.ts +36 -0
  157. package/dist/types/src/components/ChatThread/sync.d.ts.map +1 -0
  158. package/dist/types/src/components/ChatThread/sync.test.d.ts +2 -0
  159. package/dist/types/src/components/ChatThread/sync.test.d.ts.map +1 -0
  160. package/dist/types/src/components/PromptSettings.d.ts.map +1 -1
  161. package/dist/types/src/components/SequenceContainer.d.ts.map +1 -1
  162. package/dist/types/src/components/SequenceEditor/SequenceEditor.d.ts +1 -1
  163. package/dist/types/src/components/SequenceEditor/SequenceEditor.d.ts.map +1 -1
  164. package/dist/types/src/components/SequenceEditor/SequenceEditor.stories.d.ts +264 -3
  165. package/dist/types/src/components/SequenceEditor/SequenceEditor.stories.d.ts.map +1 -1
  166. package/dist/types/src/components/TemplateEditor/TemplateEditor.d.ts +0 -5
  167. package/dist/types/src/components/TemplateEditor/TemplateEditor.d.ts.map +1 -1
  168. package/dist/types/src/components/TemplateEditor/TemplateEditor.stories.d.ts +262 -7
  169. package/dist/types/src/components/TemplateEditor/TemplateEditor.stories.d.ts.map +1 -1
  170. package/dist/types/src/components/TemplateEditor/TemplateForm.d.ts +1 -1
  171. package/dist/types/src/components/TemplateEditor/TemplateForm.d.ts.map +1 -1
  172. package/dist/types/src/components/TemplateEditor/TemplateForm.stories.d.ts +259 -2
  173. package/dist/types/src/components/TemplateEditor/TemplateForm.stories.d.ts.map +1 -1
  174. package/dist/types/src/components/TemplateEditor/handlebars-extension.d.ts +12 -0
  175. package/dist/types/src/components/TemplateEditor/handlebars-extension.d.ts.map +1 -0
  176. package/dist/types/src/components/ToolBlock/ToolBlock.d.ts +19 -0
  177. package/dist/types/src/components/ToolBlock/ToolBlock.d.ts.map +1 -0
  178. package/dist/types/src/components/ToolBlock/ToolBlockWidget.d.ts +2 -0
  179. package/dist/types/src/components/ToolBlock/ToolBlockWidget.d.ts.map +1 -0
  180. package/dist/types/src/components/ToolBlock/index.d.ts +3 -0
  181. package/dist/types/src/components/ToolBlock/index.d.ts.map +1 -0
  182. package/dist/types/src/components/Toolbar/Toolbar.d.ts +5 -0
  183. package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +1 -0
  184. package/dist/types/src/components/Toolbar/index.d.ts +2 -0
  185. package/dist/types/src/components/Toolbar/index.d.ts.map +1 -0
  186. package/dist/types/src/components/Toolbar/useChatToolbarActions.d.ts +11 -0
  187. package/dist/types/src/components/Toolbar/useChatToolbarActions.d.ts.map +1 -0
  188. package/dist/types/src/components/Toolbox/Toolbox.d.ts +1 -3
  189. package/dist/types/src/components/Toolbox/Toolbox.d.ts.map +1 -1
  190. package/dist/types/src/components/Toolbox/Toolbox.stories.d.ts +263 -5
  191. package/dist/types/src/components/Toolbox/Toolbox.stories.d.ts.map +1 -1
  192. package/dist/types/src/components/index.d.ts +4 -2
  193. package/dist/types/src/components/index.d.ts.map +1 -1
  194. package/dist/types/src/functions/analysis.d.ts.map +1 -1
  195. package/dist/types/src/functions/list.d.ts.map +1 -1
  196. package/dist/types/src/functions/load.d.ts +1 -1
  197. package/dist/types/src/functions/load.d.ts.map +1 -1
  198. package/dist/types/src/hooks/index.d.ts +4 -4
  199. package/dist/types/src/hooks/index.d.ts.map +1 -1
  200. package/dist/types/src/hooks/useBlueprintRegistry.d.ts +5 -1
  201. package/dist/types/src/hooks/useBlueprintRegistry.d.ts.map +1 -1
  202. package/dist/types/src/hooks/useChatProcessor.d.ts +4 -10
  203. package/dist/types/src/hooks/useChatProcessor.d.ts.map +1 -1
  204. package/dist/types/src/hooks/useChatServices.d.ts +5 -5
  205. package/dist/types/src/hooks/useChatServices.d.ts.map +1 -1
  206. package/dist/types/src/hooks/useContextBinder.d.ts +4 -0
  207. package/dist/types/src/hooks/useContextBinder.d.ts.map +1 -0
  208. package/dist/types/src/hooks/useContextObjects.d.ts +15 -0
  209. package/dist/types/src/hooks/useContextObjects.d.ts.map +1 -0
  210. package/dist/types/src/hooks/useFlush.d.ts.map +1 -0
  211. package/dist/types/src/hooks/useItemTypes.d.ts +4 -0
  212. package/dist/types/src/hooks/useItemTypes.d.ts.map +1 -0
  213. package/dist/types/src/hooks/usePresets.d.ts +2 -2
  214. package/dist/types/src/hooks/usePresets.d.ts.map +1 -1
  215. package/dist/types/src/index.d.ts +2 -0
  216. package/dist/types/src/index.d.ts.map +1 -1
  217. package/dist/types/src/meta.d.ts +1 -2
  218. package/dist/types/src/meta.d.ts.map +1 -1
  219. package/dist/types/src/processor/index.d.ts +3 -0
  220. package/dist/types/src/processor/index.d.ts.map +1 -0
  221. package/dist/types/src/{hooks → processor}/presets.d.ts +1 -1
  222. package/dist/types/src/processor/presets.d.ts.map +1 -0
  223. package/dist/types/src/processor/processor.d.ts +74 -0
  224. package/dist/types/src/processor/processor.d.ts.map +1 -0
  225. package/dist/types/src/processor/processor.test.d.ts +2 -0
  226. package/dist/types/src/processor/processor.test.d.ts.map +1 -0
  227. package/dist/types/src/testing/index.d.ts +1 -1
  228. package/dist/types/src/testing/index.d.ts.map +1 -1
  229. package/dist/types/src/testing/test-generator.d.ts +7 -0
  230. package/dist/types/src/testing/test-generator.d.ts.map +1 -0
  231. package/dist/types/src/testing/test-sequence.d.ts +0 -4
  232. package/dist/types/src/testing/test-sequence.d.ts.map +1 -1
  233. package/dist/types/src/testing/test-services.d.ts +2 -2
  234. package/dist/types/src/testing/test-services.d.ts.map +1 -1
  235. package/dist/types/src/translations.d.ts +27 -16
  236. package/dist/types/src/translations.d.ts.map +1 -1
  237. package/dist/types/src/types/Assistant.d.ts +16 -5
  238. package/dist/types/src/types/Assistant.d.ts.map +1 -1
  239. package/dist/types/src/types/AssistantAction.d.ts +23 -6
  240. package/dist/types/src/types/AssistantAction.d.ts.map +1 -1
  241. package/dist/types/src/types/service.d.ts +21 -18
  242. package/dist/types/src/types/service.d.ts.map +1 -1
  243. package/dist/types/tsconfig.tsbuildinfo +1 -1
  244. package/package.json +90 -96
  245. package/src/AssistantPlugin.tsx +138 -116
  246. package/src/capabilities/ai-service.ts +6 -7
  247. package/src/capabilities/app-graph-builder.ts +39 -45
  248. package/src/capabilities/blueprint-definition.ts +51 -19
  249. package/src/capabilities/capabilities.ts +8 -12
  250. package/src/capabilities/edge-model-resolver.ts +17 -21
  251. package/src/capabilities/index.ts +5 -2
  252. package/src/capabilities/intent-resolver.ts +38 -15
  253. package/src/capabilities/local-model-resolver.ts +30 -0
  254. package/src/capabilities/react-surface.tsx +9 -63
  255. package/src/capabilities/state.ts +20 -0
  256. package/src/capabilities/toolkit.ts +93 -31
  257. package/src/components/AssistantSettings/AssistantSettings.tsx +82 -75
  258. package/src/components/BlueprintContainer.tsx +2 -2
  259. package/src/components/Chat/Chat.tsx +167 -172
  260. package/src/components/Chat/events.ts +7 -0
  261. package/src/components/ChatCompanion.tsx +136 -0
  262. package/src/components/ChatContainer.tsx +13 -31
  263. package/src/components/ChatDialog.tsx +11 -11
  264. package/src/components/ChatProgress/ChatProgress.tsx +67 -0
  265. package/src/components/ChatProgress/index.ts +5 -0
  266. package/src/components/ChatPrompt/ChatActions.tsx +10 -24
  267. package/src/components/ChatPrompt/ChatOptions.tsx +200 -34
  268. package/src/components/ChatPrompt/ChatPresets.tsx +1 -0
  269. package/src/components/ChatPrompt/ChatReferences.tsx +29 -36
  270. package/src/components/ChatPrompt/ChatStatusIndicator.tsx +25 -22
  271. package/src/components/ChatThread/ChatThread.stories.tsx +74 -205
  272. package/src/components/ChatThread/ChatThread.tsx +69 -29
  273. package/src/components/ChatThread/Link.tsx +8 -21
  274. package/src/components/ChatThread/reducers.ts +151 -0
  275. package/src/components/ChatThread/registry.tsx +184 -0
  276. package/src/components/ChatThread/sync.test.ts +81 -0
  277. package/src/components/ChatThread/sync.ts +113 -0
  278. package/src/components/PromptSettings.tsx +1 -0
  279. package/src/components/SequenceContainer.tsx +27 -29
  280. package/src/components/SequenceEditor/SequenceEditor.stories.tsx +8 -6
  281. package/src/components/SequenceEditor/SequenceEditor.tsx +2 -2
  282. package/src/components/TemplateEditor/TemplateEditor.stories.tsx +17 -13
  283. package/src/components/TemplateEditor/TemplateEditor.tsx +16 -50
  284. package/src/components/TemplateEditor/TemplateForm.stories.tsx +6 -8
  285. package/src/components/TemplateEditor/TemplateForm.tsx +2 -1
  286. package/src/components/TemplateEditor/handlebars-extension.ts +165 -0
  287. package/src/components/ToolBlock/ToolBlock.tsx +152 -0
  288. package/src/components/ToolBlock/ToolBlockWidget.tsx +5 -0
  289. package/src/components/ToolBlock/index.ts +6 -0
  290. package/src/components/Toolbar/Toolbar.tsx +21 -0
  291. package/src/components/{Timeline → Toolbar}/index.ts +1 -1
  292. package/src/components/Toolbar/useChatToolbarActions.ts +126 -0
  293. package/src/components/Toolbox/Toolbox.stories.tsx +9 -12
  294. package/src/components/Toolbox/Toolbox.tsx +10 -16
  295. package/src/components/index.ts +3 -1
  296. package/src/functions/analysis.ts +6 -4
  297. package/src/functions/list.ts +9 -3
  298. package/src/functions/load.ts +8 -5
  299. package/src/hooks/index.ts +4 -5
  300. package/src/hooks/useBlueprintRegistry.ts +24 -9
  301. package/src/hooks/useChatProcessor.ts +19 -26
  302. package/src/hooks/useChatServices.ts +30 -53
  303. package/src/hooks/useContextBinder.ts +30 -0
  304. package/src/hooks/useContextObjects.ts +58 -0
  305. package/src/hooks/useItemTypes.ts +37 -0
  306. package/src/hooks/usePresets.ts +4 -5
  307. package/src/index.ts +2 -0
  308. package/src/meta.ts +4 -6
  309. package/src/processor/index.ts +6 -0
  310. package/src/{hooks → processor}/presets.ts +10 -3
  311. package/src/processor/processor.test.ts +81 -0
  312. package/src/processor/processor.ts +302 -0
  313. package/src/queue-logger.ts +5 -5
  314. package/src/testing/index.ts +1 -1
  315. package/src/testing/test-generator.ts +261 -0
  316. package/src/testing/test-sequence.ts +1 -26
  317. package/src/testing/test-services.ts +2 -8
  318. package/src/translations.ts +29 -17
  319. package/src/types/Assistant.ts +9 -4
  320. package/src/types/AssistantAction.ts +11 -3
  321. package/src/types/service.ts +15 -7
  322. package/src/vite-env.d.ts +30 -0
  323. package/dist/lib/browser/ChatContainer-OUVSX5V5.mjs.map +0 -7
  324. package/dist/lib/browser/ChatDialog-P4FLEOHG.mjs.map +0 -7
  325. package/dist/lib/browser/SequenceContainer-627OQ557.mjs.map +0 -7
  326. package/dist/lib/browser/ai-service-7KJ5LXBT.mjs +0 -22
  327. package/dist/lib/browser/ai-service-7KJ5LXBT.mjs.map +0 -7
  328. package/dist/lib/browser/app-graph-builder-AVHHQ3KV.mjs.map +0 -7
  329. package/dist/lib/browser/blueprint-definition-CMGIZAOW.mjs.map +0 -7
  330. package/dist/lib/browser/chunk-BRLHDHOF.mjs +0 -244
  331. package/dist/lib/browser/chunk-BRLHDHOF.mjs.map +0 -7
  332. package/dist/lib/browser/chunk-HRLMD35M.mjs.map +0 -7
  333. package/dist/lib/browser/chunk-LKP65RPA.mjs +0 -20
  334. package/dist/lib/browser/chunk-LKP65RPA.mjs.map +0 -7
  335. package/dist/lib/browser/chunk-NZDCKQ6W.mjs +0 -89
  336. package/dist/lib/browser/chunk-NZDCKQ6W.mjs.map +0 -7
  337. package/dist/lib/browser/chunk-QB7OVS6Z.mjs +0 -16
  338. package/dist/lib/browser/chunk-QB7OVS6Z.mjs.map +0 -7
  339. package/dist/lib/browser/chunk-VEBVAHNM.mjs +0 -2231
  340. package/dist/lib/browser/chunk-VEBVAHNM.mjs.map +0 -7
  341. package/dist/lib/browser/edge-model-resolver-2HB4PCWH.mjs +0 -24
  342. package/dist/lib/browser/edge-model-resolver-2HB4PCWH.mjs.map +0 -7
  343. package/dist/lib/browser/intent-resolver-MVOIEJXZ.mjs.map +0 -7
  344. package/dist/lib/browser/react-surface-4HXS3YLT.mjs.map +0 -7
  345. package/dist/lib/browser/toolkit-IW4FBLLB.mjs +0 -105
  346. package/dist/lib/browser/toolkit-IW4FBLLB.mjs.map +0 -7
  347. package/dist/lib/node-esm/ChatContainer-D5FABDNE.mjs.map +0 -7
  348. package/dist/lib/node-esm/ChatDialog-NKWVXHJP.mjs.map +0 -7
  349. package/dist/lib/node-esm/SequenceContainer-EQ5NP2PG.mjs.map +0 -7
  350. package/dist/lib/node-esm/ai-service-LDD32477.mjs +0 -23
  351. package/dist/lib/node-esm/ai-service-LDD32477.mjs.map +0 -7
  352. package/dist/lib/node-esm/app-graph-builder-RMOUJMMG.mjs.map +0 -7
  353. package/dist/lib/node-esm/blueprint-definition-AEWYMW6I.mjs.map +0 -7
  354. package/dist/lib/node-esm/chunk-3SOC5GOP.mjs +0 -2232
  355. package/dist/lib/node-esm/chunk-3SOC5GOP.mjs.map +0 -7
  356. package/dist/lib/node-esm/chunk-F7RXCX5Y.mjs.map +0 -7
  357. package/dist/lib/node-esm/chunk-GAWXJ7K5.mjs +0 -90
  358. package/dist/lib/node-esm/chunk-GAWXJ7K5.mjs.map +0 -7
  359. package/dist/lib/node-esm/chunk-KOC6ESG7.mjs +0 -22
  360. package/dist/lib/node-esm/chunk-KOC6ESG7.mjs.map +0 -7
  361. package/dist/lib/node-esm/chunk-RD755HN3.mjs +0 -245
  362. package/dist/lib/node-esm/chunk-RD755HN3.mjs.map +0 -7
  363. package/dist/lib/node-esm/chunk-X6AANUHZ.mjs.map +0 -7
  364. package/dist/lib/node-esm/edge-model-resolver-UDDR2IA6.mjs +0 -25
  365. package/dist/lib/node-esm/edge-model-resolver-UDDR2IA6.mjs.map +0 -7
  366. package/dist/lib/node-esm/intent-resolver-DTDNCX3C.mjs.map +0 -7
  367. package/dist/lib/node-esm/react-surface-V6JNEZVO.mjs.map +0 -7
  368. package/dist/lib/node-esm/toolkit-2VNUL77B.mjs +0 -106
  369. package/dist/lib/node-esm/toolkit-2VNUL77B.mjs.map +0 -7
  370. package/dist/types/src/components/ChatThread/ChatMessage.d.ts +0 -18
  371. package/dist/types/src/components/ChatThread/ChatMessage.d.ts.map +0 -1
  372. package/dist/types/src/components/ChatThread/ToolBlock.d.ts +0 -19
  373. package/dist/types/src/components/ChatThread/ToolBlock.d.ts.map +0 -1
  374. package/dist/types/src/components/ChatThread/reducer.d.ts +0 -12
  375. package/dist/types/src/components/ChatThread/reducer.d.ts.map +0 -1
  376. package/dist/types/src/components/Timeline/Timeline.d.ts +0 -24
  377. package/dist/types/src/components/Timeline/Timeline.d.ts.map +0 -1
  378. package/dist/types/src/components/Timeline/Timeline.stories.d.ts +0 -9
  379. package/dist/types/src/components/Timeline/Timeline.stories.d.ts.map +0 -1
  380. package/dist/types/src/components/Timeline/index.d.ts +0 -2
  381. package/dist/types/src/components/Timeline/index.d.ts.map +0 -1
  382. package/dist/types/src/hooks/chat-processor.d.ts +0 -72
  383. package/dist/types/src/hooks/chat-processor.d.ts.map +0 -1
  384. package/dist/types/src/hooks/errors.d.ts +0 -4
  385. package/dist/types/src/hooks/errors.d.ts.map +0 -1
  386. package/dist/types/src/hooks/presets.d.ts.map +0 -1
  387. package/dist/types/src/hooks/useResolveRef.d.ts +0 -4
  388. package/dist/types/src/hooks/useResolveRef.d.ts.map +0 -1
  389. package/dist/types/src/parser/filter-generator.d.ts +0 -4
  390. package/dist/types/src/parser/filter-generator.d.ts.map +0 -1
  391. package/dist/types/src/parser/filter-generator.test.d.ts +0 -2
  392. package/dist/types/src/parser/filter-generator.test.d.ts.map +0 -1
  393. package/dist/types/src/parser/index.d.ts +0 -4
  394. package/dist/types/src/parser/index.d.ts.map +0 -1
  395. package/dist/types/src/parser/query-parser.d.ts +0 -15
  396. package/dist/types/src/parser/query-parser.d.ts.map +0 -1
  397. package/dist/types/src/parser/query-parser.test.d.ts +0 -2
  398. package/dist/types/src/parser/query-parser.test.d.ts.map +0 -1
  399. package/dist/types/src/parser/types.d.ts +0 -24
  400. package/dist/types/src/parser/types.d.ts.map +0 -1
  401. package/dist/types/src/stories/Chat.stories.d.ts +0 -268
  402. package/dist/types/src/stories/Chat.stories.d.ts.map +0 -1
  403. package/dist/types/src/stories/components/BlueprintContainer.d.ts +0 -5
  404. package/dist/types/src/stories/components/BlueprintContainer.d.ts.map +0 -1
  405. package/dist/types/src/stories/components/ChatContainer.d.ts +0 -5
  406. package/dist/types/src/stories/components/ChatContainer.d.ts.map +0 -1
  407. package/dist/types/src/stories/components/GraphContainer.d.ts +0 -6
  408. package/dist/types/src/stories/components/GraphContainer.d.ts.map +0 -1
  409. package/dist/types/src/stories/components/LoggingContainer.d.ts +0 -5
  410. package/dist/types/src/stories/components/LoggingContainer.d.ts.map +0 -1
  411. package/dist/types/src/stories/components/SurfaceContainer.d.ts +0 -8
  412. package/dist/types/src/stories/components/SurfaceContainer.d.ts.map +0 -1
  413. package/dist/types/src/stories/components/TasksContainer.d.ts +0 -5
  414. package/dist/types/src/stories/components/TasksContainer.d.ts.map +0 -1
  415. package/dist/types/src/stories/components/index.d.ts +0 -8
  416. package/dist/types/src/stories/components/index.d.ts.map +0 -1
  417. package/dist/types/src/stories/components/types.d.ts +0 -7
  418. package/dist/types/src/stories/components/types.d.ts.map +0 -1
  419. package/dist/types/src/stories/hooks/index.d.ts +0 -3
  420. package/dist/types/src/stories/hooks/index.d.ts.map +0 -1
  421. package/dist/types/src/stories/hooks/useFlush.d.ts.map +0 -1
  422. package/dist/types/src/stories/hooks/useMatcherExtension.d.ts +0 -3
  423. package/dist/types/src/stories/hooks/useMatcherExtension.d.ts.map +0 -1
  424. package/dist/types/src/stories/testing/data.d.ts +0 -142
  425. package/dist/types/src/stories/testing/data.d.ts.map +0 -1
  426. package/dist/types/src/stories/testing/index.d.ts +0 -3
  427. package/dist/types/src/stories/testing/index.d.ts.map +0 -1
  428. package/dist/types/src/stories/testing/testing.d.ts +0 -26
  429. package/dist/types/src/stories/testing/testing.d.ts.map +0 -1
  430. package/dist/types/src/testing/test-functions.d.ts +0 -6
  431. package/dist/types/src/testing/test-functions.d.ts.map +0 -1
  432. package/dist/types/src/tools/function.d.ts +0 -5
  433. package/dist/types/src/tools/function.d.ts.map +0 -1
  434. package/dist/types/src/tools/index.d.ts +0 -3
  435. package/dist/types/src/tools/index.d.ts.map +0 -1
  436. package/dist/types/src/tools/openapi.d.ts +0 -10
  437. package/dist/types/src/tools/openapi.d.ts.map +0 -1
  438. package/dist/types/src/tools/openapi.test.d.ts +0 -2
  439. package/dist/types/src/tools/openapi.test.d.ts.map +0 -1
  440. package/src/components/ChatThread/ChatMessage.tsx +0 -282
  441. package/src/components/ChatThread/ToolBlock.tsx +0 -125
  442. package/src/components/ChatThread/reducer.ts +0 -52
  443. package/src/components/Timeline/Timeline.stories.tsx +0 -53
  444. package/src/components/Timeline/Timeline.tsx +0 -159
  445. package/src/hooks/chat-processor.ts +0 -260
  446. package/src/hooks/errors.ts +0 -8
  447. package/src/hooks/useResolveRef.ts +0 -33
  448. package/src/parser/filter-generator.test.ts +0 -32
  449. package/src/parser/filter-generator.ts +0 -74
  450. package/src/parser/index.ts +0 -7
  451. package/src/parser/query-parser.test.ts +0 -139
  452. package/src/parser/query-parser.ts +0 -199
  453. package/src/parser/types.ts +0 -34
  454. package/src/shims.d.ts +0 -8
  455. package/src/stories/Chat.stories.tsx +0 -317
  456. package/src/stories/components/BlueprintContainer.tsx +0 -34
  457. package/src/stories/components/ChatContainer.tsx +0 -80
  458. package/src/stories/components/GraphContainer.tsx +0 -118
  459. package/src/stories/components/LoggingContainer.tsx +0 -22
  460. package/src/stories/components/SurfaceContainer.tsx +0 -62
  461. package/src/stories/components/TasksContainer.tsx +0 -51
  462. package/src/stories/components/index.ts +0 -12
  463. package/src/stories/components/types.ts +0 -11
  464. package/src/stories/hooks/index.ts +0 -6
  465. package/src/stories/hooks/useMatcherExtension.ts +0 -45
  466. package/src/stories/testing/data.ts +0 -130
  467. package/src/stories/testing/index.ts +0 -6
  468. package/src/stories/testing/testing.tsx +0 -162
  469. package/src/testing/test-functions.ts +0 -16
  470. package/src/tools/function.ts +0 -49
  471. package/src/tools/index.ts +0 -6
  472. package/src/tools/openapi.test.ts +0 -219
  473. package/src/tools/openapi.ts +0 -341
  474. package/src/typings.d.ts +0 -9
  475. /package/dist/types/src/{stories/hooks → hooks}/useFlush.d.ts +0 -0
  476. /package/src/{stories/hooks → hooks}/useFlush.ts +0 -0
@@ -0,0 +1,1795 @@
1
+ import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
+ import {
3
+ meta
4
+ } from "./chunk-73ABYRYX.mjs";
5
+
6
+ // src/hooks/useBlueprintRegistry.ts
7
+ import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
8
+ import { useSignalEffect } from "@preact/signals-react";
9
+ import { useCallback, useMemo, useState } from "react";
10
+ import { Capabilities, useCapabilities } from "@dxos/app-framework";
11
+ import { Blueprint } from "@dxos/blueprints";
12
+ import { Filter, Obj, Ref } from "@dxos/echo";
13
+ import { useQuery } from "@dxos/react-client/echo";
14
+ import { distinctBy, isNonNullable } from "@dxos/util";
15
+ var useBlueprintRegistry = () => {
16
+ const blueprints = useCapabilities(Capabilities.BlueprintDefinition);
17
+ return useMemo(() => new Blueprint.Registry(blueprints), [
18
+ blueprints
19
+ ]);
20
+ };
21
+ var useBlueprints = ({ blueprintRegistry, space }) => {
22
+ const staticBlueprints = useMemo(() => blueprintRegistry?.query() ?? [], [
23
+ blueprintRegistry
24
+ ]);
25
+ const spaceBlueprints = useQuery(space, Filter.type(Blueprint.Blueprint));
26
+ return useMemo(() => {
27
+ const blueprints = distinctBy([
28
+ ...staticBlueprints,
29
+ ...spaceBlueprints
30
+ ], (b) => b.key);
31
+ blueprints.sort(({ name: a }, { name: b }) => a.localeCompare(b));
32
+ return blueprints;
33
+ }, [
34
+ staticBlueprints,
35
+ spaceBlueprints
36
+ ]);
37
+ };
38
+ var useActiveBlueprints = ({ context }) => {
39
+ var _effect = _useSignals();
40
+ try {
41
+ const [active, setActive] = useState(/* @__PURE__ */ new Map());
42
+ useSignalEffect(() => {
43
+ const refs = [
44
+ ...context?.blueprints.value ?? []
45
+ ];
46
+ const blueprints = refs.map((ref) => ref.target).filter(isNonNullable);
47
+ setActive(new Map(blueprints.map((blueprint) => [
48
+ blueprint.key,
49
+ blueprint
50
+ ])));
51
+ });
52
+ return active;
53
+ } finally {
54
+ _effect.f();
55
+ }
56
+ };
57
+ var useBlueprintHandlers = ({ space, context, blueprintRegistry }) => {
58
+ const onUpdateBlueprint = useCallback(async (key, checked) => {
59
+ if (!context || !blueprintRegistry) {
60
+ return;
61
+ }
62
+ const { objects } = await space.db.query(Filter.type(Blueprint.Blueprint)).run();
63
+ let storedBlueprint = objects.find((blueprint) => blueprint.key === key);
64
+ if (checked) {
65
+ if (!storedBlueprint) {
66
+ const blueprint = blueprintRegistry.getByKey(key);
67
+ if (!blueprint) {
68
+ return;
69
+ }
70
+ storedBlueprint = space.db.add(Obj.clone(blueprint));
71
+ }
72
+ await context.bind({
73
+ blueprints: [
74
+ Ref.make(storedBlueprint)
75
+ ]
76
+ });
77
+ } else if (storedBlueprint) {
78
+ await context.unbind({
79
+ blueprints: [
80
+ Ref.make(storedBlueprint)
81
+ ]
82
+ });
83
+ }
84
+ }, [
85
+ space,
86
+ context,
87
+ blueprintRegistry
88
+ ]);
89
+ return {
90
+ onUpdateBlueprint
91
+ };
92
+ };
93
+
94
+ // src/hooks/useChatProcessor.ts
95
+ import { RegistryContext } from "@effect-rx/rx-react";
96
+ import { useContext, useMemo as useMemo2, useState as useState2 } from "react";
97
+ import { AiConversation } from "@dxos/assistant";
98
+ import { log as log2 } from "@dxos/log";
99
+ import { useAsyncEffect } from "@dxos/react-ui";
100
+
101
+ // src/processor/presets.ts
102
+ import * as Schema from "effect/Schema";
103
+ var ModelProviders = [
104
+ "dxos-local",
105
+ "dxos-remote",
106
+ "lm-studio"
107
+ ];
108
+ var ModelProvider = Schema.Literal(...ModelProviders);
109
+ var createModelLabel = (model) => {
110
+ const parts = model.split("/");
111
+ return parts[parts.length - 1];
112
+ };
113
+ var AiServicePresets = [
114
+ {
115
+ provider: "dxos-remote",
116
+ model: "@anthropic/claude-opus-4-0"
117
+ },
118
+ {
119
+ provider: "dxos-remote",
120
+ model: "@anthropic/claude-sonnet-4-0"
121
+ },
122
+ {
123
+ provider: "dxos-remote",
124
+ model: "@anthropic/claude-3-5-haiku-20241022"
125
+ },
126
+ {
127
+ provider: "lm-studio",
128
+ model: "@google/gemma-3-27b"
129
+ },
130
+ {
131
+ provider: "lm-studio",
132
+ model: "@mlx-community/llama-3.2-3b-instruct"
133
+ },
134
+ {
135
+ model: "deepseek-r1:latest",
136
+ provider: "dxos-local"
137
+ }
138
+ ].map(({ model, provider }, i) => ({
139
+ id: `preset-${i}`,
140
+ provider,
141
+ model,
142
+ label: createModelLabel(model)
143
+ }));
144
+
145
+ // src/processor/processor.ts
146
+ import { Registry, Rx } from "@effect-rx/rx-react";
147
+ import * as Cause from "effect/Cause";
148
+ import * as Effect from "effect/Effect";
149
+ import * as Exit from "effect/Exit";
150
+ import * as Fiber from "effect/Fiber";
151
+ import * as Option from "effect/Option";
152
+ import * as Runtime from "effect/Runtime";
153
+ import { AiService, DEFAULT_EDGE_MODEL } from "@dxos/ai";
154
+ import { AiSession, ArtifactDiffResolver, GenerationObserver, createSystemPrompt } from "@dxos/assistant";
155
+ import { Obj as Obj2 } from "@dxos/echo";
156
+ import { throwCause } from "@dxos/effect";
157
+ import { log } from "@dxos/log";
158
+ import { DataType } from "@dxos/schema";
159
+ import { trim } from "@dxos/util";
160
+ function _define_property(obj, key, value) {
161
+ if (key in obj) {
162
+ Object.defineProperty(obj, key, {
163
+ value,
164
+ enumerable: true,
165
+ configurable: true,
166
+ writable: true
167
+ });
168
+ } else {
169
+ obj[key] = value;
170
+ }
171
+ return obj;
172
+ }
173
+ var __dxlog_file = "/__w/dxos/dxos/packages/plugins/plugin-assistant/src/processor/processor.ts";
174
+ var defaultOptions = {
175
+ model: DEFAULT_EDGE_MODEL
176
+ };
177
+ var AiChatProcessor = class {
178
+ get context() {
179
+ return this._conversation.context;
180
+ }
181
+ get conversation() {
182
+ return this._conversation;
183
+ }
184
+ get blueprintRegistry() {
185
+ return this._options.blueprintRegistry;
186
+ }
187
+ /**
188
+ * Initiates a new request.
189
+ */
190
+ async request(requestParam) {
191
+ if (this._fiber) {
192
+ await this.cancel();
193
+ }
194
+ try {
195
+ this._lastRequest = requestParam;
196
+ this._rx.set(this.error, Option.none());
197
+ this._rx.set(this.active, true);
198
+ const request = this._conversation.createRequest({
199
+ system: this._options.system,
200
+ prompt: requestParam.message,
201
+ observer: this._observer
202
+ });
203
+ const runtime2 = await this._services();
204
+ this._fiber = request.pipe(
205
+ Effect.provide(AiService.model(this._options.model ?? DEFAULT_EDGE_MODEL)),
206
+ // TODO(dmaretskyi): Move ArtifactDiffResolver upstream.
207
+ Effect.provideService(ArtifactDiffResolver, this._artifactDiffResolver),
208
+ Effect.asVoid,
209
+ Runtime.runFork(runtime2)
210
+ );
211
+ const response = await this._fiber.pipe(Fiber.join, Effect.runPromiseExit);
212
+ if (!Exit.isSuccess(response) && !Cause.isInterruptedOnly(response.cause)) {
213
+ throwCause(response.cause);
214
+ }
215
+ this._rx.set(this.error, Option.none());
216
+ this._lastRequest = void 0;
217
+ this._fiber = void 0;
218
+ } catch (error) {
219
+ log.error("request failed", {
220
+ error
221
+ }, {
222
+ F: __dxlog_file,
223
+ L: 187,
224
+ S: this,
225
+ C: (f, a) => f(...a)
226
+ });
227
+ this._rx.set(this.error, Option.some(new Error("AI service error", {
228
+ cause: error
229
+ })));
230
+ } finally {
231
+ this._fiber = void 0;
232
+ this._rx.set(this.active, false);
233
+ }
234
+ }
235
+ /**
236
+ * Cancels the current request.
237
+ */
238
+ async cancel() {
239
+ await Effect.runPromise(Effect.gen(this, function* () {
240
+ if (this._fiber) {
241
+ yield* this._fiber.pipe(Fiber.interrupt);
242
+ }
243
+ }));
244
+ this._fiber = void 0;
245
+ this._rx.set(this.active, false);
246
+ }
247
+ /**
248
+ * Retry last failed request.
249
+ */
250
+ async retry() {
251
+ if (this._lastRequest) {
252
+ return this.request(this._lastRequest);
253
+ }
254
+ }
255
+ /**
256
+ * Update the current chat's name.
257
+ */
258
+ async updateName(chat) {
259
+ const runtime2 = await this._services();
260
+ const system = trim`
261
+ It is extremely important that you respond only with the title and nothing else.
262
+ If you cannot do this effectively respond with "New Chat".
263
+ `;
264
+ const history = await this._conversation.getHistory();
265
+ const fiber = Effect.gen(this, function* () {
266
+ const session = new AiSession();
267
+ return yield* session.run({
268
+ system,
269
+ prompt: "Suggest a name for this chat",
270
+ history
271
+ });
272
+ }).pipe(
273
+ // TODO(burdon): Use simpler model.
274
+ Effect.provide(AiService.model(this._options.model ?? DEFAULT_EDGE_MODEL)),
275
+ Effect.tap((messages) => {
276
+ const message = messages.find((message2) => message2.sender.role === "assistant");
277
+ const title = message?.blocks.find((b) => b._tag === "text")?.text;
278
+ if (title) {
279
+ chat.name = title;
280
+ }
281
+ }),
282
+ Runtime.runFork(runtime2)
283
+ );
284
+ const response = await fiber.pipe(Fiber.join, Effect.runPromiseExit);
285
+ if (!Exit.isSuccess(response)) {
286
+ throwCause(response.cause);
287
+ }
288
+ }
289
+ constructor(_conversation, _services, _options = defaultOptions) {
290
+ _define_property(this, "_conversation", void 0);
291
+ _define_property(this, "_services", void 0);
292
+ _define_property(this, "_options", void 0);
293
+ _define_property(this, "_rx", void 0);
294
+ _define_property(this, "_observer", void 0);
295
+ _define_property(this, "_fiber", void 0);
296
+ _define_property(this, "_lastRequest", void 0);
297
+ _define_property(this, "_pending", void 0);
298
+ _define_property(this, "_streaming", void 0);
299
+ _define_property(this, "streaming", void 0);
300
+ _define_property(this, "active", void 0);
301
+ _define_property(this, "messages", void 0);
302
+ _define_property(this, "error", void 0);
303
+ _define_property(this, "_artifactDiffResolver", void 0);
304
+ _define_property(this, "_onMessage", void 0);
305
+ _define_property(this, "_onBlock", void 0);
306
+ this._conversation = _conversation;
307
+ this._services = _services;
308
+ this._options = _options;
309
+ this._pending = Rx.make([]);
310
+ this._streaming = Rx.make(Option.none());
311
+ this.streaming = Rx.make((get) => Option.isSome(get(this._streaming)));
312
+ this.active = Rx.make(false);
313
+ this.messages = Rx.make((get) => Option.match(get(this._streaming), {
314
+ onNone: () => get(this._pending),
315
+ onSome: (streaming) => [
316
+ ...get(this._pending),
317
+ streaming
318
+ ]
319
+ }));
320
+ this.error = Rx.make(Option.none());
321
+ this._artifactDiffResolver = {
322
+ resolve: async (_artifacts) => {
323
+ const versions = /* @__PURE__ */ new Map();
324
+ return versions;
325
+ }
326
+ };
327
+ this._onMessage = Effect.fn((function* (message) {
328
+ this._rx.set(this._streaming, Option.none());
329
+ this._rx.update(this._pending, (pending) => [
330
+ ...pending,
331
+ message
332
+ ]);
333
+ }).bind(this));
334
+ this._onBlock = Effect.fn((function* (block) {
335
+ this._rx.update(this._streaming, (streaming) => {
336
+ const blocks = streaming.pipe(Option.map((streaming2) => streaming2.blocks.filter((b) => !b.pending)), Option.getOrElse(() => []));
337
+ return Option.some(Obj2.make(DataType.Message, {
338
+ created: (/* @__PURE__ */ new Date()).toISOString(),
339
+ sender: {
340
+ role: "assistant"
341
+ },
342
+ blocks: [
343
+ ...blocks,
344
+ block
345
+ ]
346
+ }));
347
+ });
348
+ }).bind(this));
349
+ this._rx = this._options.observableRegistry ?? Registry.make();
350
+ this._observer = GenerationObserver.make({
351
+ onBlock: this._onBlock,
352
+ onMessage: this._onMessage
353
+ });
354
+ if (this._options.model && !this._options.system) {
355
+ const capabilities = this._options.modelRegistry?.getCapabilities(this._options.model) ?? {};
356
+ this._options.system = createSystemPrompt(capabilities);
357
+ }
358
+ }
359
+ };
360
+
361
+ // src/hooks/useChatProcessor.ts
362
+ var __dxlog_file2 = "/__w/dxos/dxos/packages/plugins/plugin-assistant/src/hooks/useChatProcessor.ts";
363
+ var useChatProcessor = ({ chat, preset, services, blueprintRegistry, settings }) => {
364
+ const observableRegistry = useContext(RegistryContext);
365
+ const [conversation, setConversation] = useState2();
366
+ useAsyncEffect(async () => {
367
+ if (!chat?.queue.target) {
368
+ return;
369
+ }
370
+ const conversation2 = new AiConversation({
371
+ queue: chat.queue.target
372
+ });
373
+ await conversation2.open();
374
+ setConversation(conversation2);
375
+ return () => {
376
+ void conversation2.close();
377
+ };
378
+ }, [
379
+ chat?.queue.target
380
+ ]);
381
+ const processor = useMemo2(() => {
382
+ if (!services || !conversation) {
383
+ return void 0;
384
+ }
385
+ log2("creating processor", {
386
+ preset,
387
+ model: preset?.model,
388
+ settings
389
+ }, {
390
+ F: __dxlog_file2,
391
+ L: 60,
392
+ S: void 0,
393
+ C: (f, a) => f(...a)
394
+ });
395
+ return new AiChatProcessor(conversation, services, {
396
+ observableRegistry,
397
+ blueprintRegistry,
398
+ model: preset?.model
399
+ });
400
+ }, [
401
+ services,
402
+ conversation,
403
+ blueprintRegistry,
404
+ preset
405
+ ]);
406
+ return processor;
407
+ };
408
+
409
+ // src/hooks/useChatServices.ts
410
+ import * as Effect2 from "effect/Effect";
411
+ import { useMemo as useMemo3 } from "react";
412
+ import { useCapability } from "@dxos/app-framework";
413
+ import { TracingService } from "@dxos/functions";
414
+ import { AutomationCapabilities } from "@dxos/plugin-automation";
415
+ import { useClient } from "@dxos/react-client";
416
+ var useChatServices = ({ space, chat }) => {
417
+ const client = useClient();
418
+ space ?? (space = client.spaces.default);
419
+ const computeRuntimeResolver = useCapability(AutomationCapabilities.ComputeRuntime);
420
+ return useMemo3(() => {
421
+ const runtime2 = computeRuntimeResolver.getRuntime(space.id);
422
+ return () => runtime2.runPromise(Effect2.gen(function* () {
423
+ return yield* Effect2.runtime().pipe(Effect2.provide(chat?.traceQueue?.target ? TracingService.layerQueue(chat.traceQueue?.target) : TracingService.layerNoop));
424
+ }));
425
+ }, [
426
+ space,
427
+ chat?.traceQueue?.target
428
+ ]);
429
+ };
430
+
431
+ // src/hooks/useContextBinder.ts
432
+ import { useState as useState3 } from "react";
433
+ import { AiContextBinder } from "@dxos/assistant";
434
+ import { useAsyncEffect as useAsyncEffect2 } from "@dxos/react-ui";
435
+ var useContextBinder = (chat) => {
436
+ const [binder, setBinder] = useState3();
437
+ useAsyncEffect2(async () => {
438
+ if (!chat?.queue.target) {
439
+ return;
440
+ }
441
+ const binder2 = new AiContextBinder(chat.queue.target);
442
+ await binder2.open();
443
+ setBinder(binder2);
444
+ return () => {
445
+ void binder2.close();
446
+ };
447
+ }, [
448
+ chat?.queue.target
449
+ ]);
450
+ return binder;
451
+ };
452
+
453
+ // src/hooks/useContextObjects.ts
454
+ import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
455
+ import { useCallback as useCallback2 } from "react";
456
+ import { Ref as Ref2 } from "@dxos/echo";
457
+ import { log as log3 } from "@dxos/log";
458
+ import { isNonNullable as isNonNullable2 } from "@dxos/util";
459
+ var __dxlog_file3 = "/__w/dxos/dxos/packages/plugins/plugin-assistant/src/hooks/useContextObjects.ts";
460
+ var useContextObjects = ({ space, context }) => {
461
+ var _effect = _useSignals2();
462
+ try {
463
+ const objects = context?.objects.value.map((ref) => ref.target).filter(isNonNullable2) ?? [];
464
+ const handleUpdateObject = useCallback2(async (dxn, checked) => {
465
+ if (!space || !context) {
466
+ return;
467
+ }
468
+ const id = dxn.asEchoDXN();
469
+ const object = id && await space.db.getObjectById(id.echoId);
470
+ if (!object) {
471
+ log3.warn("Object not found", {
472
+ dxn,
473
+ id
474
+ }, {
475
+ F: __dxlog_file3,
476
+ L: 40,
477
+ S: void 0,
478
+ C: (f, a) => f(...a)
479
+ });
480
+ return;
481
+ }
482
+ const ref = Ref2.fromDXN(dxn);
483
+ if (checked) {
484
+ await context.bind({
485
+ objects: [
486
+ ref
487
+ ]
488
+ });
489
+ } else {
490
+ await context.unbind({
491
+ objects: [
492
+ ref
493
+ ]
494
+ });
495
+ }
496
+ }, [
497
+ space,
498
+ context
499
+ ]);
500
+ return {
501
+ objects,
502
+ onUpdateObject: handleUpdateObject
503
+ };
504
+ } finally {
505
+ _effect.f();
506
+ }
507
+ };
508
+
509
+ // src/hooks/useFlush.ts
510
+ import { useCallback as useCallback3, useRef, useState as useState4 } from "react";
511
+ var useFlush = (space) => {
512
+ const [state, setState] = useState4("idle");
513
+ const resetTimer = useRef(null);
514
+ const handleFlush = useCallback3(() => {
515
+ if (!space) {
516
+ return;
517
+ }
518
+ queueMicrotask(async () => {
519
+ if (resetTimer.current) {
520
+ clearTimeout(resetTimer.current);
521
+ }
522
+ setState("flushing");
523
+ await space.db.flush();
524
+ setState("flushed");
525
+ resetTimer.current = setTimeout(() => {
526
+ setState("idle");
527
+ resetTimer.current = null;
528
+ }, 1e3);
529
+ });
530
+ }, [
531
+ space
532
+ ]);
533
+ return {
534
+ state,
535
+ handleFlush
536
+ };
537
+ };
538
+
539
+ // src/hooks/useItemTypes.ts
540
+ import * as Option2 from "effect/Option";
541
+ import { useEffect, useState as useState5 } from "react";
542
+ import { ItemAnnotation } from "@dxos/schema";
543
+ var useItemTypes = (space) => {
544
+ const [types, setTypes] = useState5([]);
545
+ useEffect(() => {
546
+ if (!space) {
547
+ return;
548
+ }
549
+ return space.db.schemaRegistry.query().subscribe((query) => {
550
+ const types2 = Array.from(new Set([
551
+ ...space.db.graph.schemaRegistry.schemas,
552
+ ...query.results
553
+ ].filter((type) => Option2.isSome(ItemAnnotation.get(type)))));
554
+ setTypes(types2);
555
+ }, {
556
+ fire: true
557
+ });
558
+ }, [
559
+ space
560
+ ]);
561
+ return types;
562
+ };
563
+
564
+ // src/hooks/useOnline.ts
565
+ import { useState as useState6 } from "react";
566
+ var useOnline = () => {
567
+ const [online, setOnline] = useState6(true);
568
+ return [
569
+ online,
570
+ setOnline
571
+ ];
572
+ };
573
+
574
+ // src/hooks/usePresets.ts
575
+ import { useCallback as useCallback4, useEffect as useEffect2, useMemo as useMemo4, useState as useState7 } from "react";
576
+ var usePresets = (online) => {
577
+ const [preset, setPreset] = useState7();
578
+ const presets = useMemo4(() => AiServicePresets.filter((preset2) => online === (preset2.provider === "dxos-remote")), [
579
+ online
580
+ ]);
581
+ const presetOptions = useMemo4(() => presets.map(({ id, model, label }) => ({
582
+ id,
583
+ label: label ?? model
584
+ })), [
585
+ presets
586
+ ]);
587
+ useEffect2(() => {
588
+ setPreset(presets[0]);
589
+ }, [
590
+ presets
591
+ ]);
592
+ const handlePresetChange = useCallback4((id) => {
593
+ const preset2 = presets.find((preset3) => preset3.id === id);
594
+ if (preset2) {
595
+ setPreset(preset2);
596
+ }
597
+ }, [
598
+ presets
599
+ ]);
600
+ return {
601
+ preset,
602
+ presets: presetOptions,
603
+ onPresetChange: handlePresetChange
604
+ };
605
+ };
606
+
607
+ // src/hooks/useReferencesProvider.ts
608
+ import { useMemo as useMemo5 } from "react";
609
+ import { Capabilities as Capabilities2, useCapabilities as useCapabilities2 } from "@dxos/app-framework";
610
+ import { Filter as Filter2, Obj as Obj3 } from "@dxos/echo";
611
+ var useReferencesProvider = (space) => {
612
+ const blueprints = useCapabilities2(Capabilities2.BlueprintDefinition);
613
+ return useMemo5(() => {
614
+ if (!space) {
615
+ return void 0;
616
+ }
617
+ return {
618
+ getReferences: async ({ query }) => {
619
+ const { objects } = await space.db.query(Filter2.everything()).run();
620
+ return objects.filter((object) => stringMatch(query, Obj3.getLabel(object) ?? "")).filter((object) => !!Obj3.getDXN(object)).map((object) => ({
621
+ uri: Obj3.getDXN(object).toString(),
622
+ label: Obj3.getLabel(object) ?? ""
623
+ }));
624
+ },
625
+ resolveReference: async ({ uri }) => {
626
+ const object = await space.db.query(Filter2.ids(uri)).first();
627
+ return {
628
+ uri,
629
+ label: Obj3.getLabel(object) ?? ""
630
+ };
631
+ }
632
+ };
633
+ }, [
634
+ space,
635
+ blueprints
636
+ ]);
637
+ };
638
+ var stringMatch = (query, label) => label.toLowerCase().startsWith(query.toLowerCase());
639
+
640
+ // src/components/Chat/Chat.tsx
641
+ import { useSignals as _useSignals11 } from "@preact-signals/safe-react/tracking";
642
+ import { Prec } from "@codemirror/state";
643
+ import { keymap } from "@codemirror/view";
644
+ import { useRxValue } from "@effect-rx/rx-react";
645
+ import { createContext } from "@radix-ui/react-context";
646
+ import * as Array2 from "effect/Array";
647
+ import * as Option3 from "effect/Option";
648
+ import React9, { useCallback as useCallback6, useEffect as useEffect6, useMemo as useMemo9, useRef as useRef3, useState as useState12 } from "react";
649
+ import { Event } from "@dxos/async";
650
+ import { Obj as Obj6 } from "@dxos/echo";
651
+ import { useVoiceInput } from "@dxos/plugin-transcription";
652
+ import { getSpace, useQueue } from "@dxos/react-client/echo";
653
+ import { useIdentity } from "@dxos/react-client/halo";
654
+ import { Input, useDynamicRef, useTranslation as useTranslation5 } from "@dxos/react-ui";
655
+ import { ChatEditor, references } from "@dxos/react-ui-chat";
656
+ import { mx as mx5 } from "@dxos/react-ui-theme";
657
+ import { DataType as DataType2 } from "@dxos/schema";
658
+ import { isTruthy } from "@dxos/util";
659
+
660
+ // src/components/ChatPrompt/ChatActions.tsx
661
+ import { useSignals as _useSignals3 } from "@preact-signals/safe-react/tracking";
662
+ import React from "react";
663
+ import { IconButton, useTranslation } from "@dxos/react-ui";
664
+ import { mx } from "@dxos/react-ui-theme";
665
+ var ChatActions = ({ classNames, children, microphone, recording, processing, onEvent }) => {
666
+ var _effect = _useSignals3();
667
+ try {
668
+ const { t } = useTranslation(meta.id);
669
+ return /* @__PURE__ */ React.createElement("div", {
670
+ className: mx("flex items-center mie-1", classNames)
671
+ }, children, /* @__PURE__ */ React.createElement(IconButton, {
672
+ disabled: !processing,
673
+ variant: "ghost",
674
+ size: 5,
675
+ icon: "ph--x--regular",
676
+ iconOnly: true,
677
+ label: t("button cancel processing"),
678
+ onClick: () => onEvent?.({
679
+ type: "cancel"
680
+ })
681
+ }), microphone && /* @__PURE__ */ React.createElement(IconButton, {
682
+ disabled: !processing,
683
+ classNames: mx(recording && "bg-primary-500"),
684
+ variant: "ghost",
685
+ size: 5,
686
+ icon: "ph--microphone--regular",
687
+ iconOnly: true,
688
+ noTooltip: true,
689
+ label: t("button microphone"),
690
+ onMouseDown: () => onEvent?.({
691
+ type: "record-start"
692
+ }),
693
+ onMouseUp: () => onEvent?.({
694
+ type: "record-stop"
695
+ }),
696
+ onTouchStart: () => onEvent?.({
697
+ type: "record-start"
698
+ }),
699
+ onTouchEnd: () => onEvent?.({
700
+ type: "record-stop"
701
+ })
702
+ }));
703
+ } finally {
704
+ _effect.f();
705
+ }
706
+ };
707
+
708
+ // src/components/ChatPrompt/ChatOptions.tsx
709
+ import { useSignals as _useSignals4 } from "@preact-signals/safe-react/tracking";
710
+ import React2, { useMemo as useMemo6, useState as useState8 } from "react";
711
+ import { Filter as Filter3, Obj as Obj4, Type } from "@dxos/echo";
712
+ import { useQuery as useQuery2 } from "@dxos/react-client/echo";
713
+ import { Icon, IconButton as IconButton2, Popover, Select, useTranslation as useTranslation2 } from "@dxos/react-ui";
714
+ import { Listbox, SearchList } from "@dxos/react-ui-searchlist";
715
+ import { Tabs } from "@dxos/react-ui-tabs";
716
+ var panelClassNames = "is-[calc(100dvw-.5rem)] sm:is-max md:is-72 max-is-[--text-content]";
717
+ var ChatOptions = ({ space, context, blueprintRegistry, presets, preset, onPresetChange }) => {
718
+ var _effect = _useSignals4();
719
+ try {
720
+ const { t } = useTranslation2(meta.id);
721
+ return /* @__PURE__ */ React2.createElement("div", {
722
+ role: "none",
723
+ className: "flex gap-0.5"
724
+ }, /* @__PURE__ */ React2.createElement(Popover.Root, null, /* @__PURE__ */ React2.createElement(Popover.Trigger, {
725
+ asChild: true
726
+ }, /* @__PURE__ */ React2.createElement(IconButton2, {
727
+ variant: "ghost",
728
+ icon: "ph--plus--regular",
729
+ iconOnly: true,
730
+ size: 5,
731
+ label: t("button context objects")
732
+ })), /* @__PURE__ */ React2.createElement(Popover.Portal, null, /* @__PURE__ */ React2.createElement(Popover.Content, {
733
+ side: "top",
734
+ classNames: panelClassNames
735
+ }, /* @__PURE__ */ React2.createElement(ObjectsPanel, {
736
+ space,
737
+ context
738
+ }), /* @__PURE__ */ React2.createElement(Popover.Arrow, null)))), /* @__PURE__ */ React2.createElement(Popover.Root, null, /* @__PURE__ */ React2.createElement(Popover.Trigger, {
739
+ asChild: true
740
+ }, /* @__PURE__ */ React2.createElement(IconButton2, {
741
+ variant: "ghost",
742
+ icon: "ph--sliders-horizontal--regular",
743
+ iconOnly: true,
744
+ size: 5,
745
+ label: t("button context settings")
746
+ })), /* @__PURE__ */ React2.createElement(Popover.Portal, null, /* @__PURE__ */ React2.createElement(Popover.Content, {
747
+ side: "top",
748
+ classNames: panelClassNames
749
+ }, /* @__PURE__ */ React2.createElement(Tabs.Root, {
750
+ orientation: "horizontal",
751
+ defaultValue: "blueprints",
752
+ defaultActivePart: "list",
753
+ tabIndex: -1
754
+ }, /* @__PURE__ */ React2.createElement(Tabs.Viewport, {
755
+ classNames: 'max-bs-[--radix-popover-content-available-height] grid grid-rows-[1fr_min-content] [&_[cmdk-root]]:contents [&_[role="tabpanel"]]:grid [&_[role="tabpanel"]]:grid-rows-[1fr_min-content] [&_[role="listbox"]]:min-bs-0 [&_[role="listbox"]]:overflow-y-auto [&_[role="tabpanel"]]:min-bs-0 [&_[role="tabpanel"]]:pli-cardSpacingChrome [&_[role="tabpanel"][data-state="active"]]:order-first [&_[role="tabpanel"][data-state="inactive"]]:hidden'
756
+ }, /* @__PURE__ */ React2.createElement(Tabs.Tabpanel, {
757
+ value: "blueprints",
758
+ tabIndex: -1,
759
+ classNames: "dx-focus-ring-inset"
760
+ }, /* @__PURE__ */ React2.createElement(BlueprintsPanel, {
761
+ blueprintRegistry,
762
+ space,
763
+ context
764
+ })), /* @__PURE__ */ React2.createElement(Tabs.Tabpanel, {
765
+ value: "model",
766
+ tabIndex: -1,
767
+ classNames: "dx-focus-ring-inset !pli-0"
768
+ }, /* @__PURE__ */ React2.createElement(ModelsPanel, {
769
+ presets,
770
+ preset,
771
+ onPresetChange
772
+ })), /* @__PURE__ */ React2.createElement(Tabs.Tablist, {
773
+ classNames: "sm:overflow-x-hidden justify-center p-[--dx-cardSpacingChrome] border-bs border-subduedSeparator order-last"
774
+ }, /* @__PURE__ */ React2.createElement(Tabs.IconTab, {
775
+ value: "blueprints",
776
+ icon: "ph--blueprint--regular",
777
+ label: t("blueprints in context title")
778
+ }), /* @__PURE__ */ React2.createElement(Tabs.IconTab, {
779
+ value: "model",
780
+ label: t("chat model title"),
781
+ icon: "ph--cpu--regular"
782
+ })))), /* @__PURE__ */ React2.createElement(Popover.Arrow, null)))));
783
+ } finally {
784
+ _effect.f();
785
+ }
786
+ };
787
+ var BlueprintsPanel = ({ blueprintRegistry, space, context }) => {
788
+ var _effect = _useSignals4();
789
+ try {
790
+ const { t } = useTranslation2(meta.id);
791
+ const blueprints = useBlueprints({
792
+ blueprintRegistry,
793
+ space
794
+ });
795
+ const activeBlueprints = useActiveBlueprints({
796
+ context
797
+ });
798
+ const { onUpdateBlueprint } = useBlueprintHandlers({
799
+ space,
800
+ context,
801
+ blueprintRegistry
802
+ });
803
+ return /* @__PURE__ */ React2.createElement(SearchList.Root, null, /* @__PURE__ */ React2.createElement(SearchList.Content, {
804
+ classNames: "plb-cardSpacingChrome"
805
+ }, blueprints.map((blueprint) => {
806
+ const isActive = activeBlueprints.has(blueprint.key);
807
+ return /* @__PURE__ */ React2.createElement(SearchList.Item, {
808
+ classNames: "flex items-center overflow-hidden",
809
+ key: blueprint.key,
810
+ value: blueprint.name,
811
+ onSelect: () => onUpdateBlueprint?.(blueprint.key, !isActive)
812
+ }, /* @__PURE__ */ React2.createElement("div", {
813
+ className: "grow truncate"
814
+ }, blueprint.name), /* @__PURE__ */ React2.createElement(Icon, {
815
+ icon: "ph--check--regular",
816
+ classNames: [
817
+ !isActive && "invisible"
818
+ ]
819
+ }));
820
+ })), /* @__PURE__ */ React2.createElement(SearchList.Input, {
821
+ placeholder: t("search placeholder"),
822
+ classNames: "mbe-cardSpacingChrome",
823
+ autoFocus: true
824
+ }));
825
+ } finally {
826
+ _effect.f();
827
+ }
828
+ };
829
+ var ModelsPanel = ({ presets, preset, onPresetChange }) => {
830
+ var _effect = _useSignals4();
831
+ try {
832
+ return /* @__PURE__ */ React2.createElement(Listbox.Root, {
833
+ value: preset,
834
+ onValueChange: onPresetChange,
835
+ autoFocus: true
836
+ }, presets?.map(({ id, label }) => {
837
+ return /* @__PURE__ */ React2.createElement(Listbox.Option, {
838
+ key: id,
839
+ value: id
840
+ }, /* @__PURE__ */ React2.createElement(Listbox.OptionLabel, null, label), /* @__PURE__ */ React2.createElement(Listbox.OptionIndicator, null));
841
+ }));
842
+ } finally {
843
+ _effect.f();
844
+ }
845
+ };
846
+ var ANY = "__any__";
847
+ var ObjectsPanel = ({ space, context }) => {
848
+ var _effect = _useSignals4();
849
+ try {
850
+ const { t } = useTranslation2(meta.id);
851
+ const types = useItemTypes(space);
852
+ const typenames = useMemo6(() => {
853
+ const typenames2 = types.map((type) => {
854
+ const typename2 = Type.getTypename(type);
855
+ return {
856
+ typename: typename2,
857
+ label: t("typename label", {
858
+ ns: typename2,
859
+ defaultValue: typename2
860
+ })
861
+ };
862
+ });
863
+ typenames2.sort((a, b) => a.label.localeCompare(b.label));
864
+ return typenames2;
865
+ }, [
866
+ types
867
+ ]);
868
+ const [typename, setTypename] = useState8(ANY);
869
+ const anyFilter = useMemo6(() => Filter3.or(...typenames.map(({ typename: typename2 }) => Filter3.typename(typename2))), [
870
+ typenames
871
+ ]);
872
+ const objects = useQuery2(space, typename === ANY ? anyFilter : Filter3.typename(typename));
873
+ const { objects: contextObjects, onUpdateObject } = useContextObjects({
874
+ space,
875
+ context
876
+ });
877
+ return /* @__PURE__ */ React2.createElement(SearchList.Root, null, /* @__PURE__ */ React2.createElement(SearchList.Content, {
878
+ classNames: "p-cardSpacingChrome [&:has([cmdk-list-sizer]:empty)]:plb-0"
879
+ }, objects.length ? objects.map((object) => {
880
+ const label = Obj4.getLabel(object) ?? Obj4.getTypename(object) ?? object.id;
881
+ const isActive = contextObjects.findIndex((obj) => obj.id === object.id) !== -1;
882
+ return /* @__PURE__ */ React2.createElement(SearchList.Item, {
883
+ classNames: "flex items-center overflow-hidden",
884
+ key: object.id,
885
+ value: object.id,
886
+ onSelect: () => onUpdateObject?.(Obj4.getDXN(object), !isActive)
887
+ }, /* @__PURE__ */ React2.createElement("div", {
888
+ className: "grow truncate"
889
+ }, label), /* @__PURE__ */ React2.createElement(Icon, {
890
+ icon: "ph--check--regular",
891
+ classNames: [
892
+ !isActive && "invisible"
893
+ ]
894
+ }));
895
+ }) : /* @__PURE__ */ React2.createElement(SearchList.Item, null, t("no results"))), /* @__PURE__ */ React2.createElement("div", {
896
+ role: "none",
897
+ className: "grid grid-cols-[min-content_1fr] gap-2 pli-cardSpacingChrome mbe-cardSpacingChrome"
898
+ }, /* @__PURE__ */ React2.createElement(Select.Root, {
899
+ value: typename === ANY ? void 0 : typename,
900
+ onValueChange: setTypename
901
+ }, /* @__PURE__ */ React2.createElement(Select.TriggerButton, {
902
+ density: "fine",
903
+ placeholder: t("type filter placeholder")
904
+ }), /* @__PURE__ */ React2.createElement(Select.Portal, null, /* @__PURE__ */ React2.createElement(Select.Content, null, /* @__PURE__ */ React2.createElement(Select.ScrollUpButton, null), /* @__PURE__ */ React2.createElement(Select.Viewport, null, /* @__PURE__ */ React2.createElement(Select.Option, {
905
+ value: ANY
906
+ }, t("any type filter label")), typenames.map(({ typename: typename2, label }) => /* @__PURE__ */ React2.createElement(Select.Option, {
907
+ key: typename2,
908
+ value: typename2
909
+ }, label))), /* @__PURE__ */ React2.createElement(Select.ScrollDownButton, null), /* @__PURE__ */ React2.createElement(Select.Arrow, null)))), /* @__PURE__ */ React2.createElement(SearchList.Input, {
910
+ placeholder: t("search placeholder"),
911
+ classNames: "mbe-0",
912
+ autoFocus: true
913
+ })));
914
+ } finally {
915
+ _effect.f();
916
+ }
917
+ };
918
+
919
+ // src/components/ChatPrompt/ChatPresets.tsx
920
+ import { useSignals as _useSignals5 } from "@preact-signals/safe-react/tracking";
921
+ import React3 from "react";
922
+ import { Select as Select2 } from "@dxos/react-ui";
923
+
924
+ // src/components/ChatPrompt/ChatReferences.tsx
925
+ import { useSignals as _useSignals6 } from "@preact-signals/safe-react/tracking";
926
+ import React4 from "react";
927
+ import { Obj as Obj5 } from "@dxos/echo";
928
+ import { IconButton as IconButton3, toLocalizedString, useTranslation as useTranslation3 } from "@dxos/react-ui";
929
+ import { mx as mx2 } from "@dxos/react-ui-theme";
930
+ var ChatReferences = ({ classNames, context, space }) => {
931
+ var _effect = _useSignals6();
932
+ try {
933
+ const { t } = useTranslation3(meta.id);
934
+ const { objects, onUpdateObject } = useContextObjects({
935
+ space,
936
+ context
937
+ });
938
+ return /* @__PURE__ */ React4.createElement("ul", {
939
+ className: mx2("flex flex-wrap", classNames)
940
+ }, objects.map((obj) => {
941
+ const dxn = Obj5.getDXN(obj);
942
+ const typename = Obj5.getTypename(obj);
943
+ const label = Obj5.getLabel(obj) ?? (typename ? [
944
+ "object name placeholder",
945
+ {
946
+ ns: typename
947
+ }
948
+ ] : obj.id);
949
+ return /* @__PURE__ */ React4.createElement("li", {
950
+ key: dxn.toString(),
951
+ className: "dx-tag plb-0 pis-2 flex items-center",
952
+ "data-hue": "neutral"
953
+ }, toLocalizedString(label, t), /* @__PURE__ */ React4.createElement(IconButton3, {
954
+ iconOnly: true,
955
+ variant: "ghost",
956
+ label: t("remove object in context label"),
957
+ classNames: "p-0 hover:bg-transparent",
958
+ size: 3,
959
+ icon: "ph--x--bold",
960
+ onClick: () => onUpdateObject?.(dxn, false)
961
+ }));
962
+ }));
963
+ } finally {
964
+ _effect.f();
965
+ }
966
+ };
967
+
968
+ // src/components/ChatPrompt/ChatStatusIndicator.tsx
969
+ import { useSignals as _useSignals7 } from "@preact-signals/safe-react/tracking";
970
+ import React5, { useEffect as useEffect3, useState as useState9 } from "react";
971
+ import { Tooltip, useTimeout } from "@dxos/react-ui";
972
+ import { Spinner } from "@dxos/react-ui-sfx";
973
+ import { mx as mx3 } from "@dxos/react-ui-theme";
974
+ var period = 3e3;
975
+ var ChatStatusIndicator = ({ classNames, preset, processing, error, ...props }) => {
976
+ var _effect = _useSignals7();
977
+ try {
978
+ const [init, setInit] = useState9(false);
979
+ useEffect3(() => setInit(false), [
980
+ preset
981
+ ]);
982
+ useTimeout(async () => {
983
+ setInit(true);
984
+ }, period / 2, [
985
+ preset
986
+ ]);
987
+ return /* @__PURE__ */ React5.createElement("div", {
988
+ role: "none",
989
+ className: mx3("relative flex", classNames)
990
+ }, /* @__PURE__ */ React5.createElement(Spinner, {
991
+ duration: period,
992
+ state: !init ? "flash" : error ? "error" : processing ? "spin" : "pulse",
993
+ ...props
994
+ }), error && /* @__PURE__ */ React5.createElement(Tooltip.Trigger, {
995
+ asChild: true,
996
+ content: error.message
997
+ }, /* @__PURE__ */ React5.createElement("div", {
998
+ className: "absolute inset-0"
999
+ })));
1000
+ } finally {
1001
+ _effect.f();
1002
+ }
1003
+ };
1004
+
1005
+ // src/components/ChatThread/ChatThread.tsx
1006
+ import { useSignals as _useSignals10 } from "@preact-signals/safe-react/tracking";
1007
+ import React8, { forwardRef, useCallback as useCallback5, useEffect as useEffect5, useImperativeHandle, useMemo as useMemo8, useState as useState11 } from "react";
1008
+ import { PublicKey } from "@dxos/keys";
1009
+ import { MarkdownStream } from "@dxos/react-ui-components";
1010
+ import { mx as mx4 } from "@dxos/react-ui-theme";
1011
+ import { keyToFallback } from "@dxos/util";
1012
+
1013
+ // src/components/ChatThread/registry.tsx
1014
+ import { useSignals as _useSignals9 } from "@preact-signals/safe-react/tracking";
1015
+ import React7 from "react";
1016
+ import { log as log4 } from "@dxos/log";
1017
+ import { PromptWidget, ReferenceWidget, SelectWidget, SuggestionWidget, SummaryWidget, ToggleContainer as ToggleContainer2 } from "@dxos/react-ui-components";
1018
+ import { getXmlTextChild } from "@dxos/react-ui-editor";
1019
+ import { Json as Json2 } from "@dxos/react-ui-syntax-highlighter";
1020
+ import { ContentBlock } from "@dxos/schema";
1021
+
1022
+ // src/components/ToolBlock/ToolBlock.tsx
1023
+ import { useSignals as _useSignals8 } from "@preact-signals/safe-react/tracking";
1024
+ import React6, { useEffect as useEffect4, useMemo as useMemo7, useRef as useRef2, useState as useState10 } from "react";
1025
+ import { useTranslation as useTranslation4 } from "@dxos/react-ui";
1026
+ import { NumericTabs, TextCrawl, ToggleContainer, chatMessageJson, chatMessagePanel, chatMessagePanelContent, chatMessagePanelHeader } from "@dxos/react-ui-components";
1027
+ import { Json } from "@dxos/react-ui-syntax-highlighter";
1028
+ import { isNonNullable as isNonNullable3, safeParseJson } from "@dxos/util";
1029
+ var ToolBlock = ({ blocks = [] }) => {
1030
+ var _effect = _useSignals8();
1031
+ try {
1032
+ const { t } = useTranslation4(meta.id);
1033
+ const getToolCaption = (tool, status) => {
1034
+ if (!tool) {
1035
+ return t("calling tool label");
1036
+ }
1037
+ return status?.message ?? tool.description ?? [
1038
+ t("calling label"),
1039
+ tool.name
1040
+ ].join(" ");
1041
+ };
1042
+ const items = useMemo7(() => {
1043
+ let lastToolCall;
1044
+ const tools = [];
1045
+ return blocks.filter((block) => block._tag === "toolCall" || block._tag === "toolResult" || block._tag === "summary").map((block) => {
1046
+ switch (block._tag) {
1047
+ case "toolCall": {
1048
+ if (block.pending && lastToolCall?.block.toolCallId === block.toolCallId) {
1049
+ return null;
1050
+ }
1051
+ const tool = tools.find((tool2) => tool2.name === block.name);
1052
+ lastToolCall = {
1053
+ tool,
1054
+ block
1055
+ };
1056
+ return {
1057
+ title: getToolCaption(lastToolCall?.tool),
1058
+ content: {
1059
+ ...block,
1060
+ input: safeParseJson(block.input)
1061
+ }
1062
+ };
1063
+ }
1064
+ case "toolResult": {
1065
+ if (block.error) {
1066
+ return {
1067
+ title: t("error label"),
1068
+ content: block
1069
+ };
1070
+ }
1071
+ const title = getToolCaption(lastToolCall?.tool ?? t("tool result label"));
1072
+ lastToolCall = void 0;
1073
+ return {
1074
+ title,
1075
+ content: {
1076
+ ...block,
1077
+ result: safeParseJson(block.result)
1078
+ }
1079
+ };
1080
+ }
1081
+ case "summary": {
1082
+ if (!lastToolCall) {
1083
+ return null;
1084
+ }
1085
+ return {
1086
+ title: t("summary label"),
1087
+ content: block
1088
+ };
1089
+ }
1090
+ }
1091
+ }).filter(isNonNullable3);
1092
+ }, [
1093
+ blocks
1094
+ ]);
1095
+ if (!items.length) {
1096
+ return null;
1097
+ }
1098
+ return /* @__PURE__ */ React6.createElement(ToolContainer, {
1099
+ items
1100
+ });
1101
+ } finally {
1102
+ _effect.f();
1103
+ }
1104
+ };
1105
+ ToolBlock.displayName = "ToolBlock";
1106
+ var ToolContainer = ({ items }) => {
1107
+ var _effect = _useSignals8();
1108
+ try {
1109
+ const tabsRef = useRef2(null);
1110
+ const [selected, setSelected] = useState10(0);
1111
+ const [open, setOpen] = useState10(false);
1112
+ useEffect4(() => {
1113
+ if (open) {
1114
+ tabsRef.current?.focus();
1115
+ }
1116
+ }, [
1117
+ open
1118
+ ]);
1119
+ const handleSelect = (index) => {
1120
+ setSelected(index);
1121
+ };
1122
+ const data = items[selected]?.content;
1123
+ return /* @__PURE__ */ React6.createElement(ToggleContainer.Root, {
1124
+ classNames: chatMessagePanel,
1125
+ open,
1126
+ onChangeOpen: setOpen
1127
+ }, /* @__PURE__ */ React6.createElement(ToggleContainer.Header, {
1128
+ classNames: chatMessagePanelHeader
1129
+ }, /* @__PURE__ */ React6.createElement(TextCrawl, {
1130
+ key: "status-roll",
1131
+ lines: items.map((item) => item.title)
1132
+ })), /* @__PURE__ */ React6.createElement(ToggleContainer.Content, {
1133
+ classNames: [
1134
+ "grid grid-cols-[32px_1fr]",
1135
+ chatMessagePanelContent
1136
+ ]
1137
+ }, /* @__PURE__ */ React6.createElement(NumericTabs, {
1138
+ ref: tabsRef,
1139
+ classNames: "p-1",
1140
+ length: items.length,
1141
+ selected,
1142
+ onSelect: handleSelect
1143
+ }), /* @__PURE__ */ React6.createElement(Json, {
1144
+ data,
1145
+ classNames: chatMessageJson,
1146
+ replacer: {
1147
+ maxDepth: 3,
1148
+ maxArrayLen: 10,
1149
+ maxStringLen: 128
1150
+ }
1151
+ })));
1152
+ } finally {
1153
+ _effect.f();
1154
+ }
1155
+ };
1156
+
1157
+ // src/components/ChatThread/registry.tsx
1158
+ var __dxlog_file4 = "/__w/dxos/dxos/packages/plugins/plugin-assistant/src/components/ChatThread/registry.tsx";
1159
+ var Fallback = ({ _tag, ...props }) => {
1160
+ var _effect = _useSignals9();
1161
+ try {
1162
+ return /* @__PURE__ */ React7.createElement(ToggleContainer2.Root, {
1163
+ classNames: "rounded-sm"
1164
+ }, /* @__PURE__ */ React7.createElement(ToggleContainer2.Header, {
1165
+ classNames: "bg-groupSurface"
1166
+ }, _tag), /* @__PURE__ */ React7.createElement(ToggleContainer2.Content, {
1167
+ classNames: "bg-modalSurface"
1168
+ }, /* @__PURE__ */ React7.createElement(Json2, {
1169
+ classNames: "!p-2 text-sm",
1170
+ data: props
1171
+ })));
1172
+ } finally {
1173
+ _effect.f();
1174
+ }
1175
+ };
1176
+ var componentRegistry = {
1177
+ //
1178
+ // Widgets
1179
+ //
1180
+ ["prompt"]: {
1181
+ block: true,
1182
+ factory: (props) => {
1183
+ const text = getXmlTextChild(props.children);
1184
+ return text ? new PromptWidget(text) : null;
1185
+ }
1186
+ },
1187
+ ["reference"]: {
1188
+ block: false,
1189
+ factory: (props) => {
1190
+ const text = getXmlTextChild(props.children);
1191
+ return text && props.ref ? new ReferenceWidget(text, props.ref) : null;
1192
+ }
1193
+ },
1194
+ ["select"]: {
1195
+ block: true,
1196
+ factory: (props) => {
1197
+ const options = props.children?.map((option) => option._tag === "option" && getXmlTextChild(option.children)).filter(Boolean);
1198
+ return options?.length ? new SelectWidget(options) : null;
1199
+ }
1200
+ },
1201
+ ["suggestion"]: {
1202
+ block: true,
1203
+ factory: (props) => {
1204
+ const text = getXmlTextChild(props.children);
1205
+ return text ? new SuggestionWidget(text) : null;
1206
+ }
1207
+ },
1208
+ ["summary"]: {
1209
+ block: true,
1210
+ factory: (props) => {
1211
+ const text = getXmlTextChild(props.children);
1212
+ return text ? new SummaryWidget(text) : null;
1213
+ }
1214
+ },
1215
+ //
1216
+ // React
1217
+ //
1218
+ ["toolCall"]: {
1219
+ block: true,
1220
+ Component: ToolBlock
1221
+ },
1222
+ ["toolResult"]: {
1223
+ block: true,
1224
+ Component: Fallback
1225
+ },
1226
+ ["toolkit"]: {
1227
+ block: true,
1228
+ Component: Fallback
1229
+ },
1230
+ //
1231
+ // Fallback
1232
+ //
1233
+ ["json"]: {
1234
+ block: true,
1235
+ Component: Fallback
1236
+ }
1237
+ };
1238
+ var blockToMarkdown = (context, message, block) => {
1239
+ let str = _blockToMarkdown(context, message, block);
1240
+ if (str && !block.pending) {
1241
+ return str += "\n";
1242
+ }
1243
+ return str;
1244
+ };
1245
+ var _blockToMarkdown = (context, message, block) => {
1246
+ log4("blockToMarkdown", {
1247
+ block: JSON.stringify(block)
1248
+ }, {
1249
+ F: __dxlog_file4,
1250
+ L: 125,
1251
+ S: void 0,
1252
+ C: (f, a) => f(...a)
1253
+ });
1254
+ switch (block._tag) {
1255
+ case "text": {
1256
+ if (message.sender.role === "user") {
1257
+ return `
1258
+ <prompt>${block.text}</prompt>
1259
+ `;
1260
+ } else {
1261
+ const text = block.text.trim();
1262
+ if (text.length > 0) {
1263
+ return text;
1264
+ }
1265
+ }
1266
+ break;
1267
+ }
1268
+ case "suggestion": {
1269
+ if (block.pending) {
1270
+ return;
1271
+ }
1272
+ return `<suggestion>${block.text}</suggestion>`;
1273
+ }
1274
+ case "select": {
1275
+ if (block.pending || block.options.length === 0) {
1276
+ return;
1277
+ }
1278
+ return `<select>${block.options.map((option) => `<option>${option}</option>`).join("")}</select>`;
1279
+ }
1280
+ // TODO(burdon): Need label.
1281
+ case "reference": {
1282
+ return `<reference ref="${block.reference.dxn.toString()}">Ref</reference>`;
1283
+ }
1284
+ // case 'toolkit': {
1285
+ // return `<toolkit />`;
1286
+ // }
1287
+ case "toolCall": {
1288
+ context.updateWidget(block.toolCallId, {
1289
+ blocks: [
1290
+ block
1291
+ ]
1292
+ });
1293
+ return `<toolCall id="${block.toolCallId}" />`;
1294
+ }
1295
+ case "toolResult": {
1296
+ context.updateWidget(block.toolCallId, ({ blocks = [] }) => ({
1297
+ blocks: [
1298
+ ...blocks,
1299
+ block
1300
+ ]
1301
+ }));
1302
+ break;
1303
+ }
1304
+ case "summary": {
1305
+ return `<summary>${ContentBlock.createSummaryMessage(block)}</summary>`;
1306
+ }
1307
+ // TODO(burdon): Need stable ID.
1308
+ default: {
1309
+ return `<json id="${message.id}">
1310
+ ${JSON.stringify(block)}
1311
+ </json>`;
1312
+ }
1313
+ }
1314
+ };
1315
+
1316
+ // src/components/ChatThread/sync.ts
1317
+ import { log as log5 } from "@dxos/log";
1318
+ function _define_property2(obj, key, value) {
1319
+ if (key in obj) {
1320
+ Object.defineProperty(obj, key, {
1321
+ value,
1322
+ enumerable: true,
1323
+ configurable: true,
1324
+ writable: true
1325
+ });
1326
+ } else {
1327
+ obj[key] = value;
1328
+ }
1329
+ return obj;
1330
+ }
1331
+ var __dxlog_file5 = "/__w/dxos/dxos/packages/plugins/plugin-assistant/src/components/ChatThread/sync.ts";
1332
+ var MessageThreadContext = class {
1333
+ updateWidget(id, value) {
1334
+ this._widgetState?.updateWidget(id, value);
1335
+ }
1336
+ constructor(_widgetState) {
1337
+ _define_property2(this, "_widgetState", void 0);
1338
+ this._widgetState = _widgetState;
1339
+ }
1340
+ };
1341
+ var MessageSyncer = class {
1342
+ get context() {
1343
+ return this._context;
1344
+ }
1345
+ reset() {
1346
+ log5("reset", void 0, {
1347
+ F: __dxlog_file5,
1348
+ L: 58,
1349
+ S: this,
1350
+ C: (f, a) => f(...a)
1351
+ });
1352
+ this._initialMessageId = void 0;
1353
+ this._currentMessageIndex = 0;
1354
+ this._currentBlockIndex = 0;
1355
+ this._currentBlockContent = void 0;
1356
+ void this._model.reset("");
1357
+ }
1358
+ sync(messages) {
1359
+ log5("sync", {
1360
+ messages: messages.map((message) => message.blocks.length),
1361
+ currentMessageIndex: this._currentMessageIndex,
1362
+ currentBlockIndex: this._currentBlockIndex,
1363
+ currentBlockContent: this._currentBlockContent
1364
+ }, {
1365
+ F: __dxlog_file5,
1366
+ L: 67,
1367
+ S: this,
1368
+ C: (f, a) => f(...a)
1369
+ });
1370
+ if (this._initialMessageId !== messages[0]?.id) {
1371
+ this.reset();
1372
+ this._initialMessageId = messages[0]?.id;
1373
+ }
1374
+ let i = this._currentMessageIndex;
1375
+ for (const message of messages.slice(this._currentMessageIndex)) {
1376
+ if (i > this._currentMessageIndex) {
1377
+ this._currentBlockIndex = 0;
1378
+ }
1379
+ this._currentMessageIndex = i;
1380
+ let j = this._currentBlockIndex;
1381
+ for (const block of message.blocks.slice(this._currentBlockIndex)) {
1382
+ this._currentBlockIndex = j;
1383
+ const currentBlockContent = this._blockRenderer(this._context, message, block);
1384
+ if (currentBlockContent) {
1385
+ let content = "";
1386
+ if (this._currentBlockContent && currentBlockContent.startsWith(this._currentBlockContent)) {
1387
+ content = currentBlockContent.slice(this._currentBlockContent.length);
1388
+ } else {
1389
+ content = currentBlockContent;
1390
+ }
1391
+ void this._model.append(content);
1392
+ this._currentBlockContent = currentBlockContent;
1393
+ log5("append", {
1394
+ message: i,
1395
+ block: j,
1396
+ content
1397
+ }, {
1398
+ F: __dxlog_file5,
1399
+ L: 99,
1400
+ S: this,
1401
+ C: (f, a) => f(...a)
1402
+ });
1403
+ }
1404
+ if (block.pending) {
1405
+ return;
1406
+ } else {
1407
+ this._currentBlockContent = void 0;
1408
+ this._currentBlockIndex++;
1409
+ }
1410
+ j++;
1411
+ }
1412
+ i++;
1413
+ }
1414
+ }
1415
+ constructor(_model, _blockRenderer) {
1416
+ _define_property2(this, "_model", void 0);
1417
+ _define_property2(this, "_blockRenderer", void 0);
1418
+ _define_property2(this, "_initialMessageId", void 0);
1419
+ _define_property2(this, "_currentMessageIndex", void 0);
1420
+ _define_property2(this, "_currentBlockIndex", void 0);
1421
+ _define_property2(this, "_currentBlockContent", void 0);
1422
+ _define_property2(this, "_context", void 0);
1423
+ this._model = _model;
1424
+ this._blockRenderer = _blockRenderer;
1425
+ this._currentMessageIndex = 0;
1426
+ this._currentBlockIndex = 0;
1427
+ this._context = new MessageThreadContext(this._model);
1428
+ }
1429
+ };
1430
+
1431
+ // src/components/ChatThread/ChatThread.tsx
1432
+ var ChatThread = /* @__PURE__ */ forwardRef(({ classNames, identity, messages = [], error, cursor = false, fadeIn = true, overscroll, onEvent }, forwardedRef) => {
1433
+ var _effect = _useSignals10();
1434
+ try {
1435
+ const userHue = useMemo8(() => {
1436
+ return identity?.profile?.data?.hue || keyToFallback(identity?.identityKey ?? PublicKey.random()).hue;
1437
+ }, [
1438
+ identity
1439
+ ]);
1440
+ const [controller, setController] = useState11(null);
1441
+ useImperativeHandle(forwardedRef, () => controller ? controller : null, [
1442
+ controller
1443
+ ]);
1444
+ useEffect5(() => {
1445
+ controller?.scrollToBottom();
1446
+ }, [
1447
+ controller,
1448
+ error
1449
+ ]);
1450
+ const syncer = useMemo8(() => controller && new MessageSyncer(controller, blockToMarkdown), [
1451
+ controller
1452
+ ]);
1453
+ useEffect5(() => {
1454
+ syncer?.sync(messages);
1455
+ }, [
1456
+ syncer,
1457
+ messages
1458
+ ]);
1459
+ const handleEvent = useCallback5((ev) => {
1460
+ switch (ev.type) {
1461
+ case "submit": {
1462
+ ev.value && onEvent?.({
1463
+ type: "submit",
1464
+ text: ev.value
1465
+ });
1466
+ break;
1467
+ }
1468
+ }
1469
+ }, [
1470
+ onEvent
1471
+ ]);
1472
+ return /* @__PURE__ */ React8.createElement("div", {
1473
+ className: mx4("flex bs-full is-full justify-center overflow-hidden", classNames),
1474
+ style: {
1475
+ "--user-fill": `var(--dx-${userHue}Fill)`
1476
+ }
1477
+ }, /* @__PURE__ */ React8.createElement(MarkdownStream, {
1478
+ ref: setController,
1479
+ registry: componentRegistry,
1480
+ cursor,
1481
+ fadeIn,
1482
+ overscroll,
1483
+ onEvent: handleEvent
1484
+ }));
1485
+ } finally {
1486
+ _effect.f();
1487
+ }
1488
+ });
1489
+
1490
+ // src/components/Chat/Chat.tsx
1491
+ var [ChatContextProvider, useChatContext] = createContext("Chat");
1492
+ var ChatRoot = ({ classNames, children, chat, processor, onEvent, ...props }) => {
1493
+ var _effect = _useSignals11();
1494
+ try {
1495
+ const [debug, setDebug] = useState12(false);
1496
+ const space = getSpace(chat);
1497
+ const queue = useQueue(chat?.queue.dxn);
1498
+ const pending = useRxValue(processor.messages);
1499
+ const streaming = useRxValue(processor.streaming);
1500
+ const lastPrompt = useRef3(void 0);
1501
+ const messages = useMemo9(() => {
1502
+ const queueMessages = queue?.objects?.filter(Obj6.instanceOf(DataType2.Message)) ?? [];
1503
+ return Array2.dedupeWith([
1504
+ ...queueMessages,
1505
+ ...pending
1506
+ ], (a, b) => a.id === b.id);
1507
+ }, [
1508
+ queue?.objects,
1509
+ pending
1510
+ ]);
1511
+ const event = useMemo9(() => new Event(), []);
1512
+ useEffect6(() => {
1513
+ return event.on((ev) => {
1514
+ switch (ev.type) {
1515
+ case "toggle-debug": {
1516
+ setDebug((current) => !current);
1517
+ break;
1518
+ }
1519
+ case "submit": {
1520
+ const text = ev.text.trim();
1521
+ if (!streaming && text.length) {
1522
+ lastPrompt.current = ev.text;
1523
+ void processor.request({
1524
+ message: text
1525
+ });
1526
+ }
1527
+ break;
1528
+ }
1529
+ case "retry": {
1530
+ if (!streaming) {
1531
+ void processor.retry();
1532
+ }
1533
+ break;
1534
+ }
1535
+ case "cancel": {
1536
+ if (streaming) {
1537
+ void processor.cancel();
1538
+ if (lastPrompt.current) {
1539
+ event.emit({
1540
+ type: "update-prompt",
1541
+ text: lastPrompt.current
1542
+ });
1543
+ }
1544
+ }
1545
+ break;
1546
+ }
1547
+ default: {
1548
+ onEvent?.(ev);
1549
+ }
1550
+ }
1551
+ });
1552
+ }, [
1553
+ event,
1554
+ processor,
1555
+ streaming,
1556
+ onEvent
1557
+ ]);
1558
+ if (!space) {
1559
+ return null;
1560
+ }
1561
+ return /* @__PURE__ */ React9.createElement(ChatContextProvider, {
1562
+ debug,
1563
+ event,
1564
+ chat,
1565
+ space,
1566
+ messages,
1567
+ processor,
1568
+ ...props
1569
+ }, /* @__PURE__ */ React9.createElement("div", {
1570
+ role: "none",
1571
+ className: mx5("flex flex-col bs-full is-full", classNames)
1572
+ }, children));
1573
+ } finally {
1574
+ _effect.f();
1575
+ }
1576
+ };
1577
+ ChatRoot.displayName = "Chat.Root";
1578
+ var ChatPrompt = ({ classNames, outline, settings = true, placeholder, expandable, online, presets, preset, onPresetChange, onOnlineChange }) => {
1579
+ var _effect = _useSignals11();
1580
+ try {
1581
+ const { t } = useTranslation5(meta.id);
1582
+ const { space, event, processor } = useChatContext(ChatPrompt.displayName);
1583
+ const error = useRxValue(processor.error).pipe(Option3.getOrUndefined);
1584
+ const streaming = useRxValue(processor.streaming);
1585
+ const active = useRxValue(processor.active);
1586
+ const activeRef = useDynamicRef(active);
1587
+ const editorRef = useRef3(null);
1588
+ const [recordingState, setRecordingState] = useState12(false);
1589
+ useEffect6(() => {
1590
+ return event.on((event2) => {
1591
+ switch (event2.type) {
1592
+ case "update-prompt":
1593
+ if (!editorRef.current?.getText()?.length) {
1594
+ editorRef.current?.setText(event2.text);
1595
+ editorRef.current?.focus();
1596
+ }
1597
+ break;
1598
+ case "record-start":
1599
+ setRecordingState(true);
1600
+ break;
1601
+ case "record-stop":
1602
+ setRecordingState(false);
1603
+ break;
1604
+ }
1605
+ });
1606
+ }, [
1607
+ event
1608
+ ]);
1609
+ const { recording } = useVoiceInput({
1610
+ active: recordingState,
1611
+ onUpdate: (text) => {
1612
+ editorRef.current?.setText(text);
1613
+ editorRef.current?.focus();
1614
+ }
1615
+ });
1616
+ const referencesProvider = useReferencesProvider(space);
1617
+ const extensions = useMemo9(() => {
1618
+ return [
1619
+ referencesProvider && references({
1620
+ provider: referencesProvider
1621
+ }),
1622
+ Prec.highest(keymap.of([
1623
+ {
1624
+ key: "cmd-d",
1625
+ preventDefault: true,
1626
+ run: () => {
1627
+ event.emit({
1628
+ type: "toggle-debug"
1629
+ });
1630
+ return true;
1631
+ }
1632
+ },
1633
+ expandable && {
1634
+ key: "cmd-ArrowUp",
1635
+ preventDefault: true,
1636
+ run: () => {
1637
+ event.emit({
1638
+ type: "thread-open"
1639
+ });
1640
+ return true;
1641
+ }
1642
+ },
1643
+ expandable && {
1644
+ key: "cmd-ArrowDown",
1645
+ preventDefault: true,
1646
+ run: () => {
1647
+ event.emit({
1648
+ type: "thread-close"
1649
+ });
1650
+ return true;
1651
+ }
1652
+ }
1653
+ ].filter(isTruthy)))
1654
+ ].filter(isTruthy);
1655
+ }, [
1656
+ event,
1657
+ expandable,
1658
+ referencesProvider
1659
+ ]);
1660
+ const handleSubmit = useCallback6((text) => {
1661
+ if (!activeRef.current) {
1662
+ event.emit({
1663
+ type: "submit",
1664
+ text
1665
+ });
1666
+ return true;
1667
+ }
1668
+ }, [
1669
+ event
1670
+ ]);
1671
+ const handleEvent = useCallback6((ev) => {
1672
+ event.emit(ev);
1673
+ }, [
1674
+ event
1675
+ ]);
1676
+ return /* @__PURE__ */ React9.createElement("div", {
1677
+ role: "group",
1678
+ className: mx5("flex flex-col is-full density-fine", outline && [
1679
+ "p-2 bg-groupSurface border border-subduedSeparator transition transition-border [&:has(.cm-content:focus)]:border-separator rounded"
1680
+ ], classNames)
1681
+ }, /* @__PURE__ */ React9.createElement("div", {
1682
+ role: "none",
1683
+ className: "flex gap-2"
1684
+ }, /* @__PURE__ */ React9.createElement(ChatStatusIndicator, {
1685
+ classNames: "p-1",
1686
+ preset,
1687
+ error,
1688
+ processing: streaming
1689
+ }), /* @__PURE__ */ React9.createElement(ChatEditor, {
1690
+ ref: editorRef,
1691
+ autoFocus: true,
1692
+ lineWrapping: true,
1693
+ classNames: "col-span-2 pbs-0.5",
1694
+ placeholder: placeholder ?? t("prompt placeholder"),
1695
+ extensions,
1696
+ onSubmit: handleSubmit
1697
+ })), settings && /* @__PURE__ */ React9.createElement("div", {
1698
+ role: "none",
1699
+ className: "flex pbs-2 items-center"
1700
+ }, /* @__PURE__ */ React9.createElement(ChatOptions, {
1701
+ space,
1702
+ blueprintRegistry: processor.blueprintRegistry,
1703
+ context: processor.context,
1704
+ preset,
1705
+ presets,
1706
+ onPresetChange
1707
+ }), /* @__PURE__ */ React9.createElement("div", {
1708
+ role: "none",
1709
+ className: "pli-cardSpacingChrome grow"
1710
+ }, /* @__PURE__ */ React9.createElement(ChatReferences, {
1711
+ space,
1712
+ context: processor.context
1713
+ })), /* @__PURE__ */ React9.createElement(ChatActions, {
1714
+ classNames: "col-span-2",
1715
+ microphone: true,
1716
+ recording,
1717
+ processing: streaming,
1718
+ onEvent: handleEvent
1719
+ }, online !== void 0 && /* @__PURE__ */ React9.createElement(Input.Root, null, /* @__PURE__ */ React9.createElement(Input.Label, {
1720
+ srOnly: true
1721
+ }, t("online switch label")), /* @__PURE__ */ React9.createElement(Input.Switch, {
1722
+ classNames: "mis-2 mie-2",
1723
+ checked: online,
1724
+ onCheckedChange: onOnlineChange
1725
+ })))));
1726
+ } finally {
1727
+ _effect.f();
1728
+ }
1729
+ };
1730
+ ChatPrompt.displayName = "Chat.Prompt";
1731
+ var ChatThread2 = (props) => {
1732
+ var _effect = _useSignals11();
1733
+ try {
1734
+ const { event, messages, processor } = useChatContext(ChatThread2.displayName);
1735
+ const identity = useIdentity();
1736
+ const error = useRxValue(processor.error).pipe(Option3.getOrUndefined);
1737
+ const scrollerRef = useRef3(null);
1738
+ useEffect6(() => {
1739
+ return event.on((event2) => {
1740
+ switch (event2.type) {
1741
+ case "submit":
1742
+ case "scroll-to-bottom":
1743
+ scrollerRef.current?.scrollToBottom();
1744
+ break;
1745
+ }
1746
+ });
1747
+ }, [
1748
+ event
1749
+ ]);
1750
+ const handleEvent = useCallback6((ev) => {
1751
+ event.emit(ev);
1752
+ }, [
1753
+ event
1754
+ ]);
1755
+ if (!identity) {
1756
+ return null;
1757
+ }
1758
+ return /* @__PURE__ */ React9.createElement(ChatThread, {
1759
+ ...props,
1760
+ ref: scrollerRef,
1761
+ identity,
1762
+ messages,
1763
+ error,
1764
+ onEvent: handleEvent
1765
+ });
1766
+ } finally {
1767
+ _effect.f();
1768
+ }
1769
+ };
1770
+ ChatThread2.displayName = "Chat.Thread";
1771
+ var Chat = {
1772
+ Root: ChatRoot,
1773
+ Prompt: ChatPrompt,
1774
+ Thread: ChatThread2
1775
+ };
1776
+
1777
+ export {
1778
+ useBlueprintRegistry,
1779
+ useBlueprints,
1780
+ useActiveBlueprints,
1781
+ useBlueprintHandlers,
1782
+ useChatProcessor,
1783
+ useChatServices,
1784
+ useContextBinder,
1785
+ useContextObjects,
1786
+ useFlush,
1787
+ useItemTypes,
1788
+ useOnline,
1789
+ usePresets,
1790
+ useReferencesProvider,
1791
+ ChatContextProvider,
1792
+ useChatContext,
1793
+ Chat
1794
+ };
1795
+ //# sourceMappingURL=chunk-UFKLCEAE.mjs.map