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