@dxos/plugin-assistant 0.8.4-main.67995b8 → 0.8.4-main.c4373fc

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