@dxos/plugin-assistant 0.8.4-main.5ea62a8 → 0.8.4-main.ae835ea

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 (441) hide show
  1. package/dist/lib/browser/{BlueprintContainer-OWUSKPRK.mjs → BlueprintContainer-GMSYKGSO.mjs} +13 -6
  2. package/dist/lib/browser/BlueprintContainer-GMSYKGSO.mjs.map +7 -0
  3. package/dist/lib/browser/{ChatCompanion-FRCVSLPP.mjs → ChatCompanion-M3FDKTQM.mjs} +39 -14
  4. package/dist/lib/browser/ChatCompanion-M3FDKTQM.mjs.map +7 -0
  5. package/dist/lib/browser/{ChatContainer-YBJBIVUZ.mjs → ChatContainer-KAH7XITI.mjs} +10 -11
  6. package/dist/lib/browser/ChatContainer-KAH7XITI.mjs.map +7 -0
  7. package/dist/lib/browser/{ChatDialog-MTPJLEHM.mjs → ChatDialog-ZWRGABW6.mjs} +8 -10
  8. package/dist/lib/browser/ChatDialog-ZWRGABW6.mjs.map +7 -0
  9. package/dist/lib/browser/ai-service-ERTZBTP3.mjs +19 -0
  10. package/dist/lib/browser/ai-service-ERTZBTP3.mjs.map +7 -0
  11. package/dist/lib/browser/{app-graph-builder-7AAWTWGA.mjs → app-graph-builder-R5T7BJPC.mjs} +41 -11
  12. package/dist/lib/browser/app-graph-builder-R5T7BJPC.mjs.map +7 -0
  13. package/dist/lib/browser/blueprint-definition-AGTDXTXO.mjs +13 -0
  14. package/dist/lib/browser/chunk-357IHWQL.mjs +1519 -0
  15. package/dist/lib/browser/chunk-357IHWQL.mjs.map +7 -0
  16. package/dist/lib/browser/{chunk-6QMISAU6.mjs → chunk-A2NVNXPL.mjs} +15 -12
  17. package/dist/lib/browser/chunk-A2NVNXPL.mjs.map +7 -0
  18. package/dist/lib/browser/{chunk-V5H5CCZA.mjs → chunk-CQW6UPJM.mjs} +24 -43
  19. package/dist/lib/browser/chunk-CQW6UPJM.mjs.map +7 -0
  20. package/dist/lib/browser/{chunk-SMIVXXAI.mjs → chunk-GNI6HL6G.mjs} +37 -20
  21. package/dist/lib/browser/chunk-GNI6HL6G.mjs.map +7 -0
  22. package/dist/lib/browser/chunk-GXHZTOWJ.mjs +378 -0
  23. package/dist/lib/browser/chunk-GXHZTOWJ.mjs.map +7 -0
  24. package/dist/lib/browser/chunk-L5OA5OGS.mjs +262 -0
  25. package/dist/lib/browser/chunk-L5OA5OGS.mjs.map +7 -0
  26. package/dist/lib/browser/{chunk-OYFQS7JM.mjs → chunk-MEN5WTLA.mjs} +64 -39
  27. package/dist/lib/browser/chunk-MEN5WTLA.mjs.map +7 -0
  28. package/dist/lib/browser/{chunk-CFXXQM25.mjs → chunk-PUG24BEC.mjs} +118 -23
  29. package/dist/lib/browser/chunk-PUG24BEC.mjs.map +7 -0
  30. package/dist/lib/browser/{chunk-IJAJRAR7.mjs → chunk-SJJV3HEX.mjs} +2 -4
  31. package/dist/lib/browser/chunk-SJJV3HEX.mjs.map +7 -0
  32. package/dist/lib/browser/chunk-WBG5PTSX.mjs +23 -0
  33. package/dist/lib/browser/chunk-WBG5PTSX.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 +85 -51
  37. package/dist/lib/browser/index.mjs.map +4 -4
  38. package/dist/lib/browser/{intent-resolver-BQO5SVGI.mjs → intent-resolver-3C5TABOX.mjs} +38 -14
  39. package/dist/lib/browser/intent-resolver-3C5TABOX.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-VNCD2H7C.mjs → react-surface-EYKA5IFU.mjs} +11 -30
  44. package/dist/lib/browser/react-surface-EYKA5IFU.mjs.map +7 -0
  45. package/dist/lib/browser/{settings-36V3VUMW.mjs → settings-VMVBYZLN.mjs} +5 -5
  46. package/dist/lib/browser/{settings-36V3VUMW.mjs.map → settings-VMVBYZLN.mjs.map} +1 -1
  47. package/dist/lib/browser/{state-D5IVKNYG.mjs → state-CFREPBB6.mjs} +5 -5
  48. package/dist/lib/browser/{state-D5IVKNYG.mjs.map → state-CFREPBB6.mjs.map} +1 -1
  49. package/dist/lib/browser/toolkit-F3NQ7TSI.mjs +21 -0
  50. package/dist/lib/browser/toolkit-F3NQ7TSI.mjs.map +7 -0
  51. package/dist/lib/browser/types/index.mjs +2 -2
  52. package/dist/lib/node-esm/{BlueprintContainer-UFVWCRN6.mjs → BlueprintContainer-6GBLMK4Z.mjs} +13 -6
  53. package/dist/lib/node-esm/BlueprintContainer-6GBLMK4Z.mjs.map +7 -0
  54. package/dist/lib/node-esm/{ChatCompanion-ZNRZEKH5.mjs → ChatCompanion-OV426GCP.mjs} +39 -14
  55. package/dist/lib/node-esm/ChatCompanion-OV426GCP.mjs.map +7 -0
  56. package/dist/lib/node-esm/{ChatContainer-TUCITJJW.mjs → ChatContainer-UKY7NHFY.mjs} +10 -11
  57. package/dist/lib/node-esm/ChatContainer-UKY7NHFY.mjs.map +7 -0
  58. package/dist/lib/node-esm/{ChatDialog-JLM7RDZQ.mjs → ChatDialog-2BDQIEXH.mjs} +8 -10
  59. package/dist/lib/node-esm/ChatDialog-2BDQIEXH.mjs.map +7 -0
  60. package/dist/lib/node-esm/ai-service-MUYLV3NT.mjs +20 -0
  61. package/dist/lib/node-esm/ai-service-MUYLV3NT.mjs.map +7 -0
  62. package/dist/lib/node-esm/{app-graph-builder-PNAFQUYT.mjs → app-graph-builder-I52RYVWH.mjs} +41 -11
  63. package/dist/lib/node-esm/app-graph-builder-I52RYVWH.mjs.map +7 -0
  64. package/dist/lib/node-esm/{blueprint-definition-275J3XL2.mjs → blueprint-definition-CFCUD2VC.mjs} +5 -4
  65. package/dist/lib/node-esm/{chunk-CAQKGW3B.mjs → chunk-2CAETDW2.mjs} +63 -39
  66. package/dist/lib/node-esm/chunk-2CAETDW2.mjs.map +7 -0
  67. package/dist/lib/node-esm/{chunk-RLBN4RNR.mjs → chunk-4J5FYNNM.mjs} +15 -12
  68. package/dist/lib/node-esm/chunk-4J5FYNNM.mjs.map +7 -0
  69. package/dist/lib/node-esm/{chunk-7YOGZI66.mjs → chunk-5ARE4R2I.mjs} +37 -20
  70. package/dist/lib/node-esm/chunk-5ARE4R2I.mjs.map +7 -0
  71. package/dist/lib/node-esm/chunk-7ZYOYW7F.mjs +264 -0
  72. package/dist/lib/node-esm/chunk-7ZYOYW7F.mjs.map +7 -0
  73. package/dist/lib/node-esm/chunk-HJPIYMWD.mjs +1520 -0
  74. package/dist/lib/node-esm/chunk-HJPIYMWD.mjs.map +7 -0
  75. package/dist/lib/node-esm/{chunk-UWUUZQWJ.mjs → chunk-O36P4LN5.mjs} +24 -43
  76. package/dist/lib/node-esm/chunk-O36P4LN5.mjs.map +7 -0
  77. package/dist/lib/node-esm/chunk-WE6KTH72.mjs +25 -0
  78. package/dist/lib/node-esm/chunk-WE6KTH72.mjs.map +7 -0
  79. package/dist/lib/node-esm/{chunk-FNZJJL7G.mjs → chunk-XM4BVQQR.mjs} +118 -23
  80. package/dist/lib/node-esm/chunk-XM4BVQQR.mjs.map +7 -0
  81. package/dist/lib/node-esm/{chunk-YPXEA46Q.mjs → chunk-XQBL2SBL.mjs} +2 -4
  82. package/dist/lib/node-esm/chunk-XQBL2SBL.mjs.map +7 -0
  83. package/dist/lib/node-esm/chunk-YIO5MEPR.mjs +380 -0
  84. package/dist/lib/node-esm/chunk-YIO5MEPR.mjs.map +7 -0
  85. package/dist/lib/node-esm/edge-model-resolver-2ARXDOYS.mjs +19 -0
  86. package/dist/lib/node-esm/edge-model-resolver-2ARXDOYS.mjs.map +7 -0
  87. package/dist/lib/node-esm/index.mjs +85 -51
  88. package/dist/lib/node-esm/index.mjs.map +4 -4
  89. package/dist/lib/node-esm/{intent-resolver-FIS3T5KP.mjs → intent-resolver-HQ27YALS.mjs} +38 -14
  90. package/dist/lib/node-esm/intent-resolver-HQ27YALS.mjs.map +7 -0
  91. package/dist/lib/node-esm/local-model-resolver-WOQ2D2R2.mjs +18 -0
  92. package/dist/lib/node-esm/local-model-resolver-WOQ2D2R2.mjs.map +7 -0
  93. package/dist/lib/node-esm/meta.json +1 -1
  94. package/dist/lib/node-esm/{react-surface-4NLRKNBU.mjs → react-surface-UOC3CBPH.mjs} +11 -30
  95. package/dist/lib/node-esm/react-surface-UOC3CBPH.mjs.map +7 -0
  96. package/dist/lib/node-esm/{settings-7ZCZ6AS5.mjs → settings-7AUVNDM2.mjs} +5 -5
  97. package/dist/lib/node-esm/{settings-7ZCZ6AS5.mjs.map → settings-7AUVNDM2.mjs.map} +1 -1
  98. package/dist/lib/node-esm/{state-4VLKPLW3.mjs → state-XXND44OW.mjs} +5 -5
  99. package/dist/lib/node-esm/{state-4VLKPLW3.mjs.map → state-XXND44OW.mjs.map} +1 -1
  100. package/dist/lib/node-esm/toolkit-7CH5UNSQ.mjs +22 -0
  101. package/dist/lib/node-esm/toolkit-7CH5UNSQ.mjs.map +7 -0
  102. package/dist/lib/node-esm/types/index.mjs +2 -2
  103. package/dist/types/src/AssistantPlugin.d.ts +1 -1
  104. package/dist/types/src/AssistantPlugin.d.ts.map +1 -1
  105. package/dist/types/src/capabilities/ai-service.d.ts +2 -3
  106. package/dist/types/src/capabilities/ai-service.d.ts.map +1 -1
  107. package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -1
  108. package/dist/types/src/capabilities/blueprint-definition.d.ts +1 -1
  109. package/dist/types/src/capabilities/blueprint-definition.d.ts.map +1 -1
  110. package/dist/types/src/capabilities/capabilities.d.ts +0 -8
  111. package/dist/types/src/capabilities/capabilities.d.ts.map +1 -1
  112. package/dist/types/src/capabilities/edge-model-resolver.d.ts.map +1 -1
  113. package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -1
  114. package/dist/types/src/capabilities/local-model-resolver.d.ts.map +1 -1
  115. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
  116. package/dist/types/src/capabilities/toolkit.d.ts.map +1 -1
  117. package/dist/types/src/components/BlueprintContainer.d.ts.map +1 -1
  118. package/dist/types/src/components/Chat/Chat.d.ts +4 -3
  119. package/dist/types/src/components/Chat/Chat.d.ts.map +1 -1
  120. package/dist/types/src/components/ChatCompanion.d.ts.map +1 -1
  121. package/dist/types/src/components/ChatProgress/ChatProgress.d.ts.map +1 -1
  122. package/dist/types/src/components/ChatThread/ChatThread.d.ts +10 -5
  123. package/dist/types/src/components/ChatThread/ChatThread.d.ts.map +1 -1
  124. package/dist/types/src/components/ChatThread/ChatThread.stories.d.ts +35 -26
  125. package/dist/types/src/components/ChatThread/ChatThread.stories.d.ts.map +1 -1
  126. package/dist/types/src/components/ChatThread/Link.d.ts.map +1 -1
  127. package/dist/types/src/components/ChatThread/registry.d.ts +11 -0
  128. package/dist/types/src/components/ChatThread/registry.d.ts.map +1 -0
  129. package/dist/types/src/components/ChatThread/sync.d.ts +36 -0
  130. package/dist/types/src/components/ChatThread/sync.d.ts.map +1 -0
  131. package/dist/types/src/components/ChatThread/sync.test.d.ts +2 -0
  132. package/dist/types/src/components/ChatThread/sync.test.d.ts.map +1 -0
  133. package/dist/types/src/components/ChatToolbar/ChatToolbar.d.ts +6 -0
  134. package/dist/types/src/components/ChatToolbar/ChatToolbar.d.ts.map +1 -0
  135. package/dist/types/src/components/ChatToolbar/index.d.ts +2 -0
  136. package/dist/types/src/components/ChatToolbar/index.d.ts.map +1 -0
  137. package/dist/types/src/components/{Toolbar → ChatToolbar}/useChatToolbarActions.d.ts +1 -3
  138. package/dist/types/src/components/ChatToolbar/useChatToolbarActions.d.ts.map +1 -0
  139. package/dist/types/src/components/TemplateEditor/TemplateEditor.d.ts +2 -1
  140. package/dist/types/src/components/TemplateEditor/TemplateEditor.d.ts.map +1 -1
  141. package/dist/types/src/components/TemplateEditor/TemplateEditor.stories.d.ts +21 -14
  142. package/dist/types/src/components/TemplateEditor/TemplateEditor.stories.d.ts.map +1 -1
  143. package/dist/types/src/components/TemplateEditor/TemplateForm.d.ts +1 -1
  144. package/dist/types/src/components/TemplateEditor/TemplateForm.d.ts.map +1 -1
  145. package/dist/types/src/components/TemplateEditor/TemplateForm.stories.d.ts +21 -14
  146. package/dist/types/src/components/TemplateEditor/TemplateForm.stories.d.ts.map +1 -1
  147. package/dist/types/src/components/ToolBlock/ToolBlock.d.ts +19 -0
  148. package/dist/types/src/components/ToolBlock/ToolBlock.d.ts.map +1 -0
  149. package/dist/types/src/components/ToolBlock/ToolBlockWidget.d.ts +2 -0
  150. package/dist/types/src/components/ToolBlock/ToolBlockWidget.d.ts.map +1 -0
  151. package/dist/types/src/components/ToolBlock/index.d.ts +3 -0
  152. package/dist/types/src/components/ToolBlock/index.d.ts.map +1 -0
  153. package/dist/types/src/components/Toolbox/Toolbox.d.ts +2 -2
  154. package/dist/types/src/components/Toolbox/Toolbox.d.ts.map +1 -1
  155. package/dist/types/src/components/Toolbox/Toolbox.stories.d.ts +21 -14
  156. package/dist/types/src/components/Toolbox/Toolbox.stories.d.ts.map +1 -1
  157. package/dist/types/src/components/index.d.ts +1 -5
  158. package/dist/types/src/components/index.d.ts.map +1 -1
  159. package/dist/types/src/functions/analysis.d.ts.map +1 -1
  160. package/dist/types/src/functions/index.d.ts +2 -2
  161. package/dist/types/src/functions/index.d.ts.map +1 -1
  162. package/dist/types/src/functions/{list.d.ts → object-list.d.ts} +1 -1
  163. package/dist/types/src/functions/object-list.d.ts.map +1 -0
  164. package/dist/types/src/functions/{load.d.ts → object-load.d.ts} +1 -1
  165. package/dist/types/src/functions/object-load.d.ts.map +1 -0
  166. package/dist/types/src/hooks/index.d.ts +0 -3
  167. package/dist/types/src/hooks/index.d.ts.map +1 -1
  168. package/dist/types/src/hooks/useBlueprintRegistry.d.ts +2 -1
  169. package/dist/types/src/hooks/useBlueprintRegistry.d.ts.map +1 -1
  170. package/dist/types/src/hooks/useChatProcessor.d.ts +2 -2
  171. package/dist/types/src/hooks/useChatProcessor.d.ts.map +1 -1
  172. package/dist/types/src/hooks/useChatServices.d.ts +2 -2
  173. package/dist/types/src/hooks/useChatServices.d.ts.map +1 -1
  174. package/dist/types/src/hooks/useContextBinder.d.ts.map +1 -1
  175. package/dist/types/src/index.d.ts +2 -0
  176. package/dist/types/src/index.d.ts.map +1 -1
  177. package/dist/types/src/meta.d.ts +1 -2
  178. package/dist/types/src/meta.d.ts.map +1 -1
  179. package/dist/types/src/processor/index.d.ts +1 -0
  180. package/dist/types/src/processor/index.d.ts.map +1 -1
  181. package/dist/types/src/processor/presets.d.ts +1 -1
  182. package/dist/types/src/processor/presets.d.ts.map +1 -1
  183. package/dist/types/src/processor/processor.d.ts +11 -17
  184. package/dist/types/src/processor/processor.d.ts.map +1 -1
  185. package/dist/types/src/processor/update-name.d.ts +10 -0
  186. package/dist/types/src/processor/update-name.d.ts.map +1 -0
  187. package/dist/types/src/testing/index.d.ts +1 -2
  188. package/dist/types/src/testing/index.d.ts.map +1 -1
  189. package/dist/types/src/testing/test-generator.d.ts +7 -0
  190. package/dist/types/src/testing/test-generator.d.ts.map +1 -0
  191. package/dist/types/src/testing/test-services.d.ts +2 -2
  192. package/dist/types/src/testing/test-services.d.ts.map +1 -1
  193. package/dist/types/src/toolkits/AssistantToolkit.d.ts +21 -0
  194. package/dist/types/src/toolkits/AssistantToolkit.d.ts.map +1 -0
  195. package/dist/types/src/toolkits/SystemToolkit.d.ts +69 -0
  196. package/dist/types/src/toolkits/SystemToolkit.d.ts.map +1 -0
  197. package/dist/types/src/toolkits/index.d.ts +3 -0
  198. package/dist/types/src/toolkits/index.d.ts.map +1 -0
  199. package/dist/types/src/translations.d.ts +6 -4
  200. package/dist/types/src/translations.d.ts.map +1 -1
  201. package/dist/types/src/types/Assistant.d.ts +15 -9
  202. package/dist/types/src/types/Assistant.d.ts.map +1 -1
  203. package/dist/types/src/types/AssistantAction.d.ts +18 -6
  204. package/dist/types/src/types/AssistantAction.d.ts.map +1 -1
  205. package/dist/types/src/types/service.d.ts +12 -12
  206. package/dist/types/src/types/service.d.ts.map +1 -1
  207. package/dist/types/tsconfig.tsbuildinfo +1 -1
  208. package/package.json +93 -110
  209. package/src/AssistantPlugin.tsx +140 -129
  210. package/src/capabilities/ai-service.ts +6 -7
  211. package/src/capabilities/app-graph-builder.ts +36 -4
  212. package/src/capabilities/blueprint-definition.ts +39 -15
  213. package/src/capabilities/capabilities.ts +0 -13
  214. package/src/capabilities/edge-model-resolver.ts +5 -7
  215. package/src/capabilities/intent-resolver.ts +33 -6
  216. package/src/capabilities/local-model-resolver.ts +6 -8
  217. package/src/capabilities/react-surface.tsx +1 -21
  218. package/src/capabilities/toolkit.ts +10 -154
  219. package/src/components/BlueprintContainer.tsx +8 -2
  220. package/src/components/Chat/Chat.tsx +72 -70
  221. package/src/components/ChatCompanion.tsx +33 -8
  222. package/src/components/ChatContainer.tsx +4 -4
  223. package/src/components/ChatDialog.tsx +8 -8
  224. package/src/components/ChatProgress/ChatProgress.tsx +2 -3
  225. package/src/components/ChatPrompt/ChatOptions.tsx +17 -25
  226. package/src/components/ChatThread/ChatThread.stories.tsx +75 -229
  227. package/src/components/ChatThread/ChatThread.tsx +64 -46
  228. package/src/components/ChatThread/Link.tsx +11 -8
  229. package/src/components/ChatThread/registry.tsx +184 -0
  230. package/src/components/ChatThread/sync.test.ts +81 -0
  231. package/src/components/ChatThread/sync.ts +113 -0
  232. package/src/components/{Toolbar/Toolbar.tsx → ChatToolbar/ChatToolbar.tsx} +5 -2
  233. package/src/components/{Toolbar → ChatToolbar}/index.ts +1 -1
  234. package/src/components/{Toolbar → ChatToolbar}/useChatToolbarActions.ts +2 -1
  235. package/src/components/TemplateEditor/TemplateEditor.stories.tsx +5 -5
  236. package/src/components/TemplateEditor/TemplateEditor.tsx +18 -10
  237. package/src/components/TemplateEditor/TemplateForm.stories.tsx +3 -5
  238. package/src/components/TemplateEditor/TemplateForm.tsx +1 -1
  239. package/src/components/TemplateEditor/handlebars-extension.ts +12 -11
  240. package/src/components/{ChatThread → ToolBlock}/ToolBlock.tsx +31 -26
  241. package/src/components/ToolBlock/ToolBlockWidget.tsx +5 -0
  242. package/src/components/ToolBlock/index.ts +6 -0
  243. package/src/components/Toolbox/Toolbox.stories.tsx +4 -7
  244. package/src/components/Toolbox/Toolbox.tsx +3 -3
  245. package/src/components/index.ts +1 -3
  246. package/src/functions/analysis.ts +4 -2
  247. package/src/functions/index.ts +2 -2
  248. package/src/functions/{list.ts → object-list.ts} +6 -4
  249. package/src/functions/{load.ts → object-load.ts} +9 -7
  250. package/src/hooks/index.ts +0 -3
  251. package/src/hooks/useBlueprintRegistry.ts +17 -3
  252. package/src/hooks/useChatProcessor.ts +13 -5
  253. package/src/hooks/useChatServices.ts +26 -42
  254. package/src/hooks/useContextBinder.ts +17 -5
  255. package/src/hooks/useItemTypes.ts +1 -1
  256. package/src/index.ts +2 -0
  257. package/src/meta.ts +9 -6
  258. package/src/processor/index.ts +1 -0
  259. package/src/processor/presets.ts +1 -1
  260. package/src/processor/processor.test.ts +21 -17
  261. package/src/processor/processor.ts +30 -57
  262. package/src/processor/update-name.ts +57 -0
  263. package/src/queue-logger.ts +5 -5
  264. package/src/testing/index.ts +1 -2
  265. package/src/testing/test-generator.ts +261 -0
  266. package/src/testing/test-services.ts +2 -8
  267. package/src/toolkits/AssistantToolkit.ts +55 -0
  268. package/src/toolkits/SystemToolkit.ts +292 -0
  269. package/src/toolkits/index.ts +6 -0
  270. package/src/translations.ts +6 -5
  271. package/src/types/Assistant.ts +10 -8
  272. package/src/types/AssistantAction.ts +10 -2
  273. package/src/types/service.ts +17 -9
  274. package/dist/lib/browser/BlueprintContainer-OWUSKPRK.mjs.map +0 -7
  275. package/dist/lib/browser/ChatCompanion-FRCVSLPP.mjs.map +0 -7
  276. package/dist/lib/browser/ChatContainer-YBJBIVUZ.mjs.map +0 -7
  277. package/dist/lib/browser/ChatDialog-MTPJLEHM.mjs.map +0 -7
  278. package/dist/lib/browser/SequenceContainer-TF5QNXYM.mjs +0 -150
  279. package/dist/lib/browser/SequenceContainer-TF5QNXYM.mjs.map +0 -7
  280. package/dist/lib/browser/ai-service-NRZPTUHO.mjs +0 -22
  281. package/dist/lib/browser/ai-service-NRZPTUHO.mjs.map +0 -7
  282. package/dist/lib/browser/app-graph-builder-7AAWTWGA.mjs.map +0 -7
  283. package/dist/lib/browser/blueprint-definition-CRZPIA5A.mjs +0 -12
  284. package/dist/lib/browser/chunk-6QMISAU6.mjs.map +0 -7
  285. package/dist/lib/browser/chunk-CFXXQM25.mjs.map +0 -7
  286. package/dist/lib/browser/chunk-IJAJRAR7.mjs.map +0 -7
  287. package/dist/lib/browser/chunk-O4LUJEDV.mjs +0 -20
  288. package/dist/lib/browser/chunk-O4LUJEDV.mjs.map +0 -7
  289. package/dist/lib/browser/chunk-OYFQS7JM.mjs.map +0 -7
  290. package/dist/lib/browser/chunk-SMIVXXAI.mjs.map +0 -7
  291. package/dist/lib/browser/chunk-V5H5CCZA.mjs.map +0 -7
  292. package/dist/lib/browser/chunk-XL557TXF.mjs +0 -2332
  293. package/dist/lib/browser/chunk-XL557TXF.mjs.map +0 -7
  294. package/dist/lib/browser/edge-model-resolver-E5M3CC46.mjs +0 -22
  295. package/dist/lib/browser/edge-model-resolver-E5M3CC46.mjs.map +0 -7
  296. package/dist/lib/browser/intent-resolver-BQO5SVGI.mjs.map +0 -7
  297. package/dist/lib/browser/local-model-resolver-VZ5WZQIC.mjs +0 -21
  298. package/dist/lib/browser/local-model-resolver-VZ5WZQIC.mjs.map +0 -7
  299. package/dist/lib/browser/react-surface-VNCD2H7C.mjs.map +0 -7
  300. package/dist/lib/browser/toolkit-Y5OYX5PO.mjs +0 -191
  301. package/dist/lib/browser/toolkit-Y5OYX5PO.mjs.map +0 -7
  302. package/dist/lib/node-esm/BlueprintContainer-UFVWCRN6.mjs.map +0 -7
  303. package/dist/lib/node-esm/ChatCompanion-ZNRZEKH5.mjs.map +0 -7
  304. package/dist/lib/node-esm/ChatContainer-TUCITJJW.mjs.map +0 -7
  305. package/dist/lib/node-esm/ChatDialog-JLM7RDZQ.mjs.map +0 -7
  306. package/dist/lib/node-esm/SequenceContainer-UXOVZPZO.mjs +0 -151
  307. package/dist/lib/node-esm/SequenceContainer-UXOVZPZO.mjs.map +0 -7
  308. package/dist/lib/node-esm/ai-service-UDEPIPTO.mjs +0 -23
  309. package/dist/lib/node-esm/ai-service-UDEPIPTO.mjs.map +0 -7
  310. package/dist/lib/node-esm/app-graph-builder-PNAFQUYT.mjs.map +0 -7
  311. package/dist/lib/node-esm/chunk-2X6VEO32.mjs +0 -2333
  312. package/dist/lib/node-esm/chunk-2X6VEO32.mjs.map +0 -7
  313. package/dist/lib/node-esm/chunk-7YOGZI66.mjs.map +0 -7
  314. package/dist/lib/node-esm/chunk-CAQKGW3B.mjs.map +0 -7
  315. package/dist/lib/node-esm/chunk-FNZJJL7G.mjs.map +0 -7
  316. package/dist/lib/node-esm/chunk-RLBN4RNR.mjs.map +0 -7
  317. package/dist/lib/node-esm/chunk-UWUUZQWJ.mjs.map +0 -7
  318. package/dist/lib/node-esm/chunk-VFY2JG62.mjs +0 -22
  319. package/dist/lib/node-esm/chunk-VFY2JG62.mjs.map +0 -7
  320. package/dist/lib/node-esm/chunk-YPXEA46Q.mjs.map +0 -7
  321. package/dist/lib/node-esm/edge-model-resolver-SZHDLXCT.mjs +0 -23
  322. package/dist/lib/node-esm/edge-model-resolver-SZHDLXCT.mjs.map +0 -7
  323. package/dist/lib/node-esm/intent-resolver-FIS3T5KP.mjs.map +0 -7
  324. package/dist/lib/node-esm/local-model-resolver-2KCBKMYA.mjs +0 -22
  325. package/dist/lib/node-esm/local-model-resolver-2KCBKMYA.mjs.map +0 -7
  326. package/dist/lib/node-esm/react-surface-4NLRKNBU.mjs.map +0 -7
  327. package/dist/lib/node-esm/toolkit-2F2OL6WB.mjs +0 -192
  328. package/dist/lib/node-esm/toolkit-2F2OL6WB.mjs.map +0 -7
  329. package/dist/types/src/components/ChatThread/ChatMessage.d.ts +0 -33
  330. package/dist/types/src/components/ChatThread/ChatMessage.d.ts.map +0 -1
  331. package/dist/types/src/components/ChatThread/ToolBlock.d.ts +0 -19
  332. package/dist/types/src/components/ChatThread/ToolBlock.d.ts.map +0 -1
  333. package/dist/types/src/components/PromptSettings.d.ts +0 -6
  334. package/dist/types/src/components/PromptSettings.d.ts.map +0 -1
  335. package/dist/types/src/components/SequenceContainer.d.ts +0 -8
  336. package/dist/types/src/components/SequenceContainer.d.ts.map +0 -1
  337. package/dist/types/src/components/SequenceEditor/SequenceEditor.d.ts +0 -13
  338. package/dist/types/src/components/SequenceEditor/SequenceEditor.d.ts.map +0 -1
  339. package/dist/types/src/components/SequenceEditor/SequenceEditor.stories.d.ts +0 -263
  340. package/dist/types/src/components/SequenceEditor/SequenceEditor.stories.d.ts.map +0 -1
  341. package/dist/types/src/components/SequenceEditor/index.d.ts +0 -2
  342. package/dist/types/src/components/SequenceEditor/index.d.ts.map +0 -1
  343. package/dist/types/src/components/Toolbar/Toolbar.d.ts +0 -4
  344. package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +0 -1
  345. package/dist/types/src/components/Toolbar/index.d.ts +0 -2
  346. package/dist/types/src/components/Toolbar/index.d.ts.map +0 -1
  347. package/dist/types/src/components/Toolbar/useChatToolbarActions.d.ts.map +0 -1
  348. package/dist/types/src/execution-graph/execution-graph.d.ts +0 -21
  349. package/dist/types/src/execution-graph/execution-graph.d.ts.map +0 -1
  350. package/dist/types/src/execution-graph/index.d.ts +0 -2
  351. package/dist/types/src/execution-graph/index.d.ts.map +0 -1
  352. package/dist/types/src/functions/list.d.ts.map +0 -1
  353. package/dist/types/src/functions/load.d.ts.map +0 -1
  354. package/dist/types/src/hooks/useExecutionGraph.d.ts +0 -7
  355. package/dist/types/src/hooks/useExecutionGraph.d.ts.map +0 -1
  356. package/dist/types/src/hooks/useMatcherExtension.d.ts +0 -3
  357. package/dist/types/src/hooks/useMatcherExtension.d.ts.map +0 -1
  358. package/dist/types/src/hooks/useResolveRef.d.ts +0 -4
  359. package/dist/types/src/hooks/useResolveRef.d.ts.map +0 -1
  360. package/dist/types/src/parser/filter-generator.d.ts +0 -4
  361. package/dist/types/src/parser/filter-generator.d.ts.map +0 -1
  362. package/dist/types/src/parser/filter-generator.test.d.ts +0 -2
  363. package/dist/types/src/parser/filter-generator.test.d.ts.map +0 -1
  364. package/dist/types/src/parser/index.d.ts +0 -4
  365. package/dist/types/src/parser/index.d.ts.map +0 -1
  366. package/dist/types/src/parser/query-parser.d.ts +0 -15
  367. package/dist/types/src/parser/query-parser.d.ts.map +0 -1
  368. package/dist/types/src/parser/query-parser.test.d.ts +0 -2
  369. package/dist/types/src/parser/query-parser.test.d.ts.map +0 -1
  370. package/dist/types/src/parser/types.d.ts +0 -24
  371. package/dist/types/src/parser/types.d.ts.map +0 -1
  372. package/dist/types/src/stories/Chat.stories.d.ts +0 -26
  373. package/dist/types/src/stories/Chat.stories.d.ts.map +0 -1
  374. package/dist/types/src/stories/components/BlueprintContainer.d.ts +0 -4
  375. package/dist/types/src/stories/components/BlueprintContainer.d.ts.map +0 -1
  376. package/dist/types/src/stories/components/ChatContainer.d.ts +0 -4
  377. package/dist/types/src/stories/components/ChatContainer.d.ts.map +0 -1
  378. package/dist/types/src/stories/components/CommentsContainer.d.ts +0 -4
  379. package/dist/types/src/stories/components/CommentsContainer.d.ts.map +0 -1
  380. package/dist/types/src/stories/components/GraphContainer.d.ts +0 -6
  381. package/dist/types/src/stories/components/GraphContainer.d.ts.map +0 -1
  382. package/dist/types/src/stories/components/LoggingContainer.d.ts +0 -4
  383. package/dist/types/src/stories/components/LoggingContainer.d.ts.map +0 -1
  384. package/dist/types/src/stories/components/MessageContainer.d.ts +0 -4
  385. package/dist/types/src/stories/components/MessageContainer.d.ts.map +0 -1
  386. package/dist/types/src/stories/components/SurfaceContainer.d.ts +0 -8
  387. package/dist/types/src/stories/components/SurfaceContainer.d.ts.map +0 -1
  388. package/dist/types/src/stories/components/TasksContainer.d.ts +0 -4
  389. package/dist/types/src/stories/components/TasksContainer.d.ts.map +0 -1
  390. package/dist/types/src/stories/components/TokenManagerContainer.d.ts +0 -3
  391. package/dist/types/src/stories/components/TokenManagerContainer.d.ts.map +0 -1
  392. package/dist/types/src/stories/components/index.d.ts +0 -11
  393. package/dist/types/src/stories/components/index.d.ts.map +0 -1
  394. package/dist/types/src/stories/components/types.d.ts +0 -7
  395. package/dist/types/src/stories/components/types.d.ts.map +0 -1
  396. package/dist/types/src/stories/testing/data.d.ts +0 -5
  397. package/dist/types/src/stories/testing/data.d.ts.map +0 -1
  398. package/dist/types/src/stories/testing/index.d.ts +0 -3
  399. package/dist/types/src/stories/testing/index.d.ts.map +0 -1
  400. package/dist/types/src/stories/testing/testing.d.ts +0 -44
  401. package/dist/types/src/stories/testing/testing.d.ts.map +0 -1
  402. package/dist/types/src/testing/test-data.d.ts +0 -4
  403. package/dist/types/src/testing/test-data.d.ts.map +0 -1
  404. package/dist/types/src/testing/test-functions.d.ts +0 -6
  405. package/dist/types/src/testing/test-functions.d.ts.map +0 -1
  406. package/src/components/ChatThread/ChatMessage.tsx +0 -334
  407. package/src/components/PromptSettings.tsx +0 -90
  408. package/src/components/SequenceContainer.tsx +0 -131
  409. package/src/components/SequenceEditor/SequenceEditor.stories.tsx +0 -33
  410. package/src/components/SequenceEditor/SequenceEditor.tsx +0 -50
  411. package/src/components/SequenceEditor/index.ts +0 -5
  412. package/src/execution-graph/execution-graph.ts +0 -211
  413. package/src/execution-graph/index.ts +0 -5
  414. package/src/hooks/useExecutionGraph.ts +0 -20
  415. package/src/hooks/useMatcherExtension.ts +0 -45
  416. package/src/hooks/useResolveRef.ts +0 -33
  417. package/src/parser/filter-generator.test.ts +0 -32
  418. package/src/parser/filter-generator.ts +0 -76
  419. package/src/parser/index.ts +0 -7
  420. package/src/parser/query-parser.test.ts +0 -139
  421. package/src/parser/query-parser.ts +0 -199
  422. package/src/parser/types.ts +0 -36
  423. package/src/stories/Chat.stories.tsx +0 -469
  424. package/src/stories/components/BlueprintContainer.tsx +0 -32
  425. package/src/stories/components/ChatContainer.tsx +0 -57
  426. package/src/stories/components/CommentsContainer.tsx +0 -25
  427. package/src/stories/components/GraphContainer.tsx +0 -118
  428. package/src/stories/components/LoggingContainer.tsx +0 -21
  429. package/src/stories/components/MessageContainer.tsx +0 -27
  430. package/src/stories/components/SurfaceContainer.tsx +0 -52
  431. package/src/stories/components/TasksContainer.tsx +0 -49
  432. package/src/stories/components/TokenManagerContainer.tsx +0 -14
  433. package/src/stories/components/index.ts +0 -15
  434. package/src/stories/components/types.ts +0 -11
  435. package/src/stories/testing/data.ts +0 -142
  436. package/src/stories/testing/index.ts +0 -6
  437. package/src/stories/testing/testing.tsx +0 -254
  438. package/src/testing/test-data.ts +0 -109
  439. package/src/testing/test-functions.ts +0 -16
  440. /package/dist/lib/browser/{blueprint-definition-CRZPIA5A.mjs.map → blueprint-definition-AGTDXTXO.mjs.map} +0 -0
  441. /package/dist/lib/node-esm/{blueprint-definition-275J3XL2.mjs.map → blueprint-definition-CFCUD2VC.mjs.map} +0 -0
@@ -1,2332 +0,0 @@
1
- import {
2
- ServiceType
3
- } from "./chunk-SMIVXXAI.mjs";
4
- import {
5
- AssistantCapabilities
6
- } from "./chunk-IJAJRAR7.mjs";
7
- import {
8
- meta
9
- } from "./chunk-O4LUJEDV.mjs";
10
-
11
- // src/hooks/useBlueprintRegistry.ts
12
- import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
13
- import { useSignalEffect } from "@preact/signals-react";
14
- import { useCallback, useMemo, useState } from "react";
15
- import { Capabilities, useCapabilities } from "@dxos/app-framework";
16
- import { Blueprint } from "@dxos/blueprints";
17
- import { Filter, Obj, Ref } from "@dxos/echo";
18
- import { isNonNullable } from "@dxos/util";
19
- var useBlueprintRegistry = () => {
20
- const blueprints = useCapabilities(Capabilities.BlueprintDefinition);
21
- return useMemo(() => new Blueprint.Registry(blueprints), [
22
- blueprints
23
- ]);
24
- };
25
- var useBlueprints = ({ blueprintRegistry }) => useMemo(() => blueprintRegistry?.query() ?? [], [
26
- blueprintRegistry
27
- ]);
28
- var useActiveBlueprints = ({ context }) => {
29
- var _effect = _useSignals();
30
- try {
31
- const [active, setActive] = useState(/* @__PURE__ */ new Map());
32
- useSignalEffect(() => {
33
- const refs = [
34
- ...context?.blueprints.value ?? []
35
- ];
36
- const blueprints = refs.map((ref) => ref.target).filter(isNonNullable);
37
- setActive(new Map(blueprints.map((blueprint) => [
38
- blueprint.key,
39
- blueprint
40
- ])));
41
- });
42
- return active;
43
- } finally {
44
- _effect.f();
45
- }
46
- };
47
- var useBlueprintHandlers = ({ space, context, blueprintRegistry }) => {
48
- const onUpdateBlueprint = useCallback(async (key, checked) => {
49
- if (!context || !blueprintRegistry) {
50
- return;
51
- }
52
- const { objects } = await space.db.query(Filter.type(Blueprint.Blueprint)).run();
53
- let storedBlueprint = objects.find((blueprint) => blueprint.key === key);
54
- if (checked) {
55
- if (!storedBlueprint) {
56
- const blueprint = blueprintRegistry.getByKey(key);
57
- if (!blueprint) {
58
- return;
59
- }
60
- storedBlueprint = space.db.add(Obj.clone(blueprint));
61
- }
62
- await context.bind({
63
- blueprints: [
64
- Ref.make(storedBlueprint)
65
- ]
66
- });
67
- } else if (storedBlueprint) {
68
- await context.unbind({
69
- blueprints: [
70
- Ref.make(storedBlueprint)
71
- ]
72
- });
73
- }
74
- }, [
75
- space,
76
- context,
77
- blueprintRegistry
78
- ]);
79
- return {
80
- onUpdateBlueprint
81
- };
82
- };
83
-
84
- // src/hooks/useChatProcessor.ts
85
- import { RegistryContext } from "@effect-rx/rx-react";
86
- import { useContext, useMemo as useMemo2 } from "react";
87
- import { AiConversation } from "@dxos/assistant";
88
- import { log as log2 } from "@dxos/log";
89
-
90
- // src/processor/presets.ts
91
- import { Schema } from "effect";
92
- var ModelProviders = [
93
- "dxos-local",
94
- "dxos-remote",
95
- "lm-studio"
96
- ];
97
- var ModelProvider = Schema.Literal(...ModelProviders);
98
- var createModelLabel = (model) => {
99
- const parts = model.split("/");
100
- return parts[parts.length - 1];
101
- };
102
- var AiServicePresets = [
103
- {
104
- provider: "dxos-remote",
105
- model: "@anthropic/claude-opus-4-0"
106
- },
107
- {
108
- provider: "dxos-remote",
109
- model: "@anthropic/claude-sonnet-4-0"
110
- },
111
- {
112
- provider: "dxos-remote",
113
- model: "@anthropic/claude-3-5-haiku-20241022"
114
- },
115
- {
116
- provider: "lm-studio",
117
- model: "@google/gemma-3-27b"
118
- },
119
- {
120
- provider: "lm-studio",
121
- model: "@mlx-community/llama-3.2-3b-instruct"
122
- },
123
- {
124
- model: "deepseek-r1:latest",
125
- provider: "dxos-local"
126
- }
127
- ].map(({ model, provider }, i) => ({
128
- id: `preset-${i}`,
129
- provider,
130
- model,
131
- label: createModelLabel(model)
132
- }));
133
-
134
- // src/processor/processor.ts
135
- import { Registry, Rx } from "@effect-rx/rx-react";
136
- import { Cause, Effect, Exit, Fiber, Layer, Option } from "effect";
137
- import { AiService, DEFAULT_EDGE_MODEL } from "@dxos/ai";
138
- import { AiSession, ArtifactDiffResolver, GenerationObserver, createSystemPrompt } from "@dxos/assistant";
139
- import { Obj as Obj2 } from "@dxos/echo";
140
- import { throwCause } from "@dxos/effect";
141
- import { log } from "@dxos/log";
142
- import { DataType } from "@dxos/schema";
143
- import { trim } from "@dxos/util";
144
- function _define_property(obj, key, value) {
145
- if (key in obj) {
146
- Object.defineProperty(obj, key, {
147
- value,
148
- enumerable: true,
149
- configurable: true,
150
- writable: true
151
- });
152
- } else {
153
- obj[key] = value;
154
- }
155
- return obj;
156
- }
157
- var __dxlog_file = "/__w/dxos/dxos/packages/plugins/plugin-assistant/src/processor/processor.ts";
158
- var defaultOptions = {
159
- model: DEFAULT_EDGE_MODEL
160
- };
161
- var AiChatProcessor = class {
162
- get isRunning() {
163
- return !!this._fiber;
164
- }
165
- get context() {
166
- return this._conversation.context;
167
- }
168
- get conversation() {
169
- return this._conversation;
170
- }
171
- get blueprintRegistry() {
172
- return this._options.blueprintRegistry;
173
- }
174
- /**
175
- * Initiates a new request.
176
- */
177
- async request(requestParam) {
178
- if (this._fiber) {
179
- await this.cancel();
180
- }
181
- try {
182
- this._lastRequest = requestParam;
183
- this._rx.set(this.error, Option.none());
184
- const request = this._conversation.createRequest({
185
- system: this._options.system,
186
- prompt: requestParam.message,
187
- observer: this._observer
188
- });
189
- this._fiber = request.pipe(
190
- Effect.provide(Layer.provideMerge(AiService.model(this._options.model ?? DEFAULT_EDGE_MODEL), this._services)),
191
- // TODO(dmaretskyi): Move ArtifactDiffResolver upstream.
192
- Effect.provideService(ArtifactDiffResolver, this._artifactDiffResolver),
193
- Effect.asVoid,
194
- Effect.tapErrorCause((cause) => {
195
- log.error("request failed", {
196
- cause
197
- }, {
198
- F: __dxlog_file,
199
- L: 176,
200
- S: this,
201
- C: (f, a) => f(...a)
202
- });
203
- return Effect.void;
204
- }),
205
- Effect.runFork
206
- );
207
- const response = await this._fiber.pipe(Fiber.join, Effect.runPromiseExit);
208
- if (!Exit.isSuccess(response) && !Cause.isInterruptedOnly(response.cause)) {
209
- throwCause(response.cause);
210
- }
211
- this._rx.set(this.error, Option.none());
212
- this._lastRequest = void 0;
213
- this._fiber = void 0;
214
- } catch (err) {
215
- log.error("request failed", {
216
- err
217
- }, {
218
- F: __dxlog_file,
219
- L: 192,
220
- S: this,
221
- C: (f, a) => f(...a)
222
- });
223
- this._rx.set(this.error, Option.some(new Error("AI service error", {
224
- cause: err
225
- })));
226
- } finally {
227
- this._fiber = void 0;
228
- }
229
- }
230
- /**
231
- * Cancels the current request.
232
- */
233
- async cancel() {
234
- await Effect.runPromise(Effect.gen(this, function* () {
235
- if (this._fiber) {
236
- yield* this._fiber.pipe(Fiber.interrupt);
237
- }
238
- }));
239
- this._fiber = void 0;
240
- }
241
- /**
242
- * Retry last failed request.
243
- */
244
- async retry() {
245
- if (this._lastRequest) {
246
- return this.request(this._lastRequest);
247
- }
248
- }
249
- /**
250
- * Update the current chat's name.
251
- */
252
- async updateName(chat) {
253
- const system = trim`
254
- It is extremely important that you respond only with the title and nothing else.
255
- If you cannot do this effectively respond with "New Chat".
256
- `;
257
- const history = await this._conversation.getHistory();
258
- const fiber = Effect.gen(this, function* () {
259
- const session = new AiSession();
260
- return yield* session.run({
261
- system,
262
- prompt: "Suggest a name for this chat",
263
- history
264
- });
265
- }).pipe(
266
- // TODO(burdon): Use simpler model.
267
- Effect.provide(Layer.provideMerge(AiService.model(this._options.model ?? DEFAULT_EDGE_MODEL), this._services)),
268
- Effect.tap((messages) => {
269
- const message = messages.find((message2) => message2.sender.role === "assistant");
270
- const title = message?.blocks.find((b) => b._tag === "text")?.text;
271
- if (title) {
272
- chat.name = title;
273
- }
274
- }),
275
- Effect.runFork
276
- );
277
- const response = await fiber.pipe(Fiber.join, Effect.runPromiseExit);
278
- if (!Exit.isSuccess(response)) {
279
- throwCause(response.cause);
280
- }
281
- }
282
- constructor(_conversation, _services, _options = defaultOptions) {
283
- _define_property(this, "_conversation", void 0);
284
- _define_property(this, "_services", void 0);
285
- _define_property(this, "_options", void 0);
286
- _define_property(this, "_rx", void 0);
287
- _define_property(this, "_observer", void 0);
288
- _define_property(this, "_fiber", void 0);
289
- _define_property(this, "_lastRequest", void 0);
290
- _define_property(this, "_pending", void 0);
291
- _define_property(this, "_streaming", void 0);
292
- _define_property(this, "streaming", void 0);
293
- _define_property(this, "messages", void 0);
294
- _define_property(this, "error", void 0);
295
- _define_property(this, "_artifactDiffResolver", void 0);
296
- _define_property(this, "_onMessage", void 0);
297
- _define_property(this, "_onBlock", void 0);
298
- this._conversation = _conversation;
299
- this._services = _services;
300
- this._options = _options;
301
- this._pending = Rx.make([]);
302
- this._streaming = Rx.make(Option.none());
303
- this.streaming = Rx.make((get) => Option.isSome(get(this._streaming)));
304
- this.messages = Rx.make((get) => Option.match(get(this._streaming), {
305
- onNone: () => get(this._pending),
306
- onSome: (streaming) => [
307
- ...get(this._pending),
308
- streaming
309
- ]
310
- }));
311
- this.error = Rx.make(Option.none());
312
- this._artifactDiffResolver = {
313
- resolve: async (_artifacts) => {
314
- const versions = /* @__PURE__ */ new Map();
315
- return versions;
316
- }
317
- };
318
- this._onMessage = Effect.fn(function* (message) {
319
- this._rx.set(this._streaming, Option.none());
320
- this._rx.update(this._pending, (pending) => [
321
- ...pending,
322
- message
323
- ]);
324
- }.bind(this));
325
- this._onBlock = Effect.fn(function* (block) {
326
- this._rx.update(this._streaming, (streaming) => {
327
- const blocks = streaming.pipe(Option.map((streaming2) => streaming2.blocks.filter((b) => !b.pending)), Option.getOrElse(() => []));
328
- return Option.some(Obj2.make(DataType.Message, {
329
- created: (/* @__PURE__ */ new Date()).toISOString(),
330
- sender: {
331
- role: "assistant"
332
- },
333
- blocks: [
334
- ...blocks,
335
- block
336
- ]
337
- }));
338
- });
339
- }.bind(this));
340
- this._rx = this._options.observableRegistry ?? Registry.make();
341
- this._observer = GenerationObserver.make({
342
- onBlock: this._onBlock,
343
- onMessage: this._onMessage
344
- });
345
- if (this._options.model && !this._options.system) {
346
- const capabilities = this._options.modelRegistry?.getCapabilities(this._options.model) ?? {};
347
- this._options.system = createSystemPrompt(capabilities);
348
- }
349
- }
350
- };
351
-
352
- // src/hooks/useChatProcessor.ts
353
- var __dxlog_file2 = "/__w/dxos/dxos/packages/plugins/plugin-assistant/src/hooks/useChatProcessor.ts";
354
- var useChatProcessor = ({ chat, preset, services, blueprintRegistry, settings }) => {
355
- const observableRegistry = useContext(RegistryContext);
356
- const conversation = useMemo2(() => {
357
- if (!chat?.queue.target) {
358
- return;
359
- }
360
- return new AiConversation({
361
- queue: chat.queue.target
362
- });
363
- }, [
364
- chat?.queue.target
365
- ]);
366
- const processor = useMemo2(() => {
367
- if (!services || !conversation) {
368
- return void 0;
369
- }
370
- log2("creating processor", {
371
- preset,
372
- model: preset?.model,
373
- settings
374
- }, {
375
- F: __dxlog_file2,
376
- L: 52,
377
- S: void 0,
378
- C: (f, a) => f(...a)
379
- });
380
- return new AiChatProcessor(conversation, services, {
381
- observableRegistry,
382
- blueprintRegistry,
383
- model: preset?.model
384
- });
385
- }, [
386
- services,
387
- conversation,
388
- blueprintRegistry,
389
- preset
390
- ]);
391
- return processor;
392
- };
393
-
394
- // src/hooks/useChatServices.ts
395
- import { AiToolkit } from "@effect/ai";
396
- import { Layer as Layer2 } from "effect";
397
- import { useMemo as useMemo3 } from "react";
398
- import { Capabilities as Capabilities2, useCapabilities as useCapabilities2 } from "@dxos/app-framework";
399
- import { makeToolExecutionServiceFromFunctions, makeToolResolverFromFunctions } from "@dxos/assistant";
400
- import { ComputeEventLogger, CredentialsService, DatabaseService, LocalFunctionExecutionService, QueueService, RemoteFunctionExecutionService, TracingService } from "@dxos/functions";
401
-
402
- // src/capabilities/index.ts
403
- import { lazy } from "@dxos/app-framework";
404
- var AiService2 = lazy(() => import("./ai-service-NRZPTUHO.mjs"));
405
- var AppGraphBuilder = lazy(() => import("./app-graph-builder-7AAWTWGA.mjs"));
406
- var AssistantState = lazy(() => import("./state-D5IVKNYG.mjs"));
407
- var BlueprintDefinition = lazy(() => import("./blueprint-definition-CRZPIA5A.mjs"));
408
- var EdgeModelResolver = lazy(() => import("./edge-model-resolver-E5M3CC46.mjs"));
409
- var IntentResolver = lazy(() => import("./intent-resolver-BQO5SVGI.mjs"));
410
- var LocalModelResolver = lazy(() => import("./local-model-resolver-VZ5WZQIC.mjs"));
411
- var ReactSurface = lazy(() => import("./react-surface-VNCD2H7C.mjs"));
412
- var Settings = lazy(() => import("./settings-36V3VUMW.mjs"));
413
- var Toolkit = lazy(() => import("./toolkit-Y5OYX5PO.mjs"));
414
-
415
- // src/hooks/useChatServices.ts
416
- var useChatServices = ({ space, chat }) => {
417
- const serviceLayer = useCapabilities2(AssistantCapabilities.AiServiceLayer).at(0) ?? Layer2.die("AiService not found");
418
- const functions = useCapabilities2(Capabilities2.Functions);
419
- const toolkits = useCapabilities2(Capabilities2.Toolkit);
420
- const handlers = useCapabilities2(Capabilities2.ToolkitHandler);
421
- return useMemo3(() => {
422
- const allFunctions = functions.flat();
423
- const toolkit = AiToolkit.merge(...toolkits);
424
- const handlersLayer = Layer2.mergeAll(Layer2.empty, ...handlers);
425
- return Layer2.mergeAll(serviceLayer, makeToolResolverFromFunctions(allFunctions, toolkit), makeToolExecutionServiceFromFunctions(allFunctions, toolkit, handlersLayer), CredentialsService.layerFromDatabase(), ComputeEventLogger.layerFromTracing).pipe(Layer2.provideMerge(Layer2.mergeAll(space ? DatabaseService.layer(space.db) : DatabaseService.notAvailable, space ? QueueService.layer(space.queues) : QueueService.notAvailable, chat?.traceQueue?.target ? TracingService.layerQueue(chat.traceQueue?.target) : TracingService.layerNoop, LocalFunctionExecutionService.layer, RemoteFunctionExecutionService.mockLayer)));
426
- }, [
427
- space,
428
- functions,
429
- toolkits,
430
- handlers,
431
- chat?.traceQueue?.target
432
- ]);
433
- };
434
-
435
- // src/hooks/useContextBinder.ts
436
- import { useMemo as useMemo4 } from "react";
437
- import { AiContextBinder } from "@dxos/assistant";
438
- var useContextBinder = (chat) => {
439
- const binder = useMemo4(() => {
440
- const queue = chat?.queue.target;
441
- return queue && new AiContextBinder(queue);
442
- }, [
443
- chat
444
- ]);
445
- return binder;
446
- };
447
-
448
- // src/hooks/useOnline.ts
449
- import { useState as useState2 } from "react";
450
- var useOnline = () => {
451
- const [online, setOnline] = useState2(true);
452
- return [
453
- online,
454
- setOnline
455
- ];
456
- };
457
-
458
- // src/hooks/usePresets.ts
459
- import { useCallback as useCallback2, useEffect, useMemo as useMemo5, useState as useState3 } from "react";
460
- var usePresets = (online) => {
461
- const [preset, setPreset] = useState3();
462
- const presets = useMemo5(() => AiServicePresets.filter((preset2) => online === (preset2.provider === "dxos-remote")), [
463
- online
464
- ]);
465
- const presetOptions = useMemo5(() => presets.map(({ id, model, label }) => ({
466
- id,
467
- label: label ?? model
468
- })), [
469
- presets
470
- ]);
471
- useEffect(() => {
472
- setPreset(presets[0]);
473
- }, [
474
- presets
475
- ]);
476
- const handlePresetChange = useCallback2((id) => {
477
- const preset2 = presets.find((preset3) => preset3.id === id);
478
- if (preset2) {
479
- setPreset(preset2);
480
- }
481
- }, [
482
- presets
483
- ]);
484
- return {
485
- preset,
486
- presets: presetOptions,
487
- onPresetChange: handlePresetChange
488
- };
489
- };
490
-
491
- // src/hooks/useContextObjects.ts
492
- import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
493
- import { useCallback as useCallback3 } from "react";
494
- import { Ref as Ref2 } from "@dxos/echo";
495
- import { log as log3 } from "@dxos/log";
496
- import { isNonNullable as isNonNullable2 } from "@dxos/util";
497
- var __dxlog_file3 = "/__w/dxos/dxos/packages/plugins/plugin-assistant/src/hooks/useContextObjects.ts";
498
- var useContextObjects = ({ space, context }) => {
499
- var _effect = _useSignals2();
500
- try {
501
- const objects = context?.objects.value.map((ref) => ref.target).filter(isNonNullable2) ?? [];
502
- const handleUpdateObject = useCallback3(async (dxn, checked) => {
503
- if (!space || !context) {
504
- return;
505
- }
506
- const id = dxn.asEchoDXN();
507
- const object = id && await space.db.getObjectById(id.echoId);
508
- if (!object) {
509
- log3.warn("Object not found", {
510
- dxn,
511
- id
512
- }, {
513
- F: __dxlog_file3,
514
- L: 40,
515
- S: void 0,
516
- C: (f, a) => f(...a)
517
- });
518
- return;
519
- }
520
- const ref = Ref2.fromDXN(dxn);
521
- if (checked) {
522
- await context.bind({
523
- objects: [
524
- ref
525
- ]
526
- });
527
- } else {
528
- await context.unbind({
529
- objects: [
530
- ref
531
- ]
532
- });
533
- }
534
- }, [
535
- space,
536
- context
537
- ]);
538
- return {
539
- objects,
540
- onUpdateObject: handleUpdateObject
541
- };
542
- } finally {
543
- _effect.f();
544
- }
545
- };
546
-
547
- // src/hooks/useExecutionGraph.ts
548
- import { useMemo as useMemo6 } from "react";
549
- import { Obj as Obj4 } from "@dxos/echo";
550
- import { useQueue } from "@dxos/react-client/echo";
551
-
552
- // src/execution-graph/execution-graph.ts
553
- import { AgentStatus } from "@dxos/ai";
554
- import { Obj as Obj3 } from "@dxos/echo";
555
- import { MESSAGE_PROPERTY_TOOL_CALL_ID } from "@dxos/functions";
556
- import { LogLevel } from "@dxos/log";
557
- import { ContentBlock, DataType as DataType2 } from "@dxos/schema";
558
- import { isNotFalsy } from "@dxos/util";
559
- function _define_property2(obj, key, value) {
560
- if (key in obj) {
561
- Object.defineProperty(obj, key, {
562
- value,
563
- enumerable: true,
564
- configurable: true,
565
- writable: true
566
- });
567
- } else {
568
- obj[key] = value;
569
- }
570
- return obj;
571
- }
572
- var ExecutionGraph = class {
573
- /**
574
- * Adds events to the graph.
575
- */
576
- addEvents(events) {
577
- for (const event of events) {
578
- if (Obj3.instanceOf(DataType2.Message, event)) {
579
- const messageCommits = messageToCommit(event);
580
- this._commits.push(...messageCommits);
581
- messageCommits.map((c) => c.branch).forEach((branch) => this._branchNames.add(branch));
582
- } else if (Obj3.instanceOf(AgentStatus, event)) {
583
- const branch = getBranchName({
584
- parentMessage: event.parentMessage,
585
- toolCallId: event.toolCallId
586
- });
587
- this._branchNames.add(branch);
588
- this._commits.push({
589
- id: event.id,
590
- branch,
591
- message: event.message,
592
- icon: "ph--flag--regular",
593
- parents: event.parentMessage && event.toolCallId ? [
594
- getToolCallId(event.parentMessage, event.toolCallId)
595
- ] : void 0
596
- });
597
- }
598
- }
599
- }
600
- /**
601
- * Returns the current state of the graph.
602
- */
603
- getGraph(lastRequest = false) {
604
- const idx = lastRequest ? this._commits.findLastIndex((c) => c.tags?.includes("user")) : -1;
605
- const commits = idx === -1 ? this._commits : this._commits.slice(idx);
606
- return {
607
- branches: Array.from(this._branchNames),
608
- commits
609
- };
610
- }
611
- constructor() {
612
- _define_property2(this, "_commits", []);
613
- _define_property2(this, "_branchNames", /* @__PURE__ */ new Set());
614
- }
615
- };
616
- var messageToCommit = (message) => {
617
- return message.blocks.map((block, idx) => {
618
- const branch = getMessageBranch(message);
619
- const parent = getParentId(message);
620
- const parents = parent ? [
621
- parent
622
- ] : [];
623
- switch (block._tag) {
624
- case "text":
625
- if (!block.text.trim().length) {
626
- return null;
627
- }
628
- return {
629
- id: getGenericBlockId(message.id, idx),
630
- branch,
631
- parents,
632
- ...message.sender.role === "user" ? {
633
- icon: "ph--user--regular",
634
- tags: [
635
- "user"
636
- ],
637
- message: "Processing request..."
638
- } : {
639
- icon: "ph--robot--regular",
640
- message: `Response (${block.text.split(" ").length} words)`
641
- }
642
- };
643
- case "toolCall":
644
- return {
645
- id: getToolCallId(message.id, block.toolCallId),
646
- branch,
647
- parents,
648
- icon: "ph--wrench--regular",
649
- level: LogLevel.INFO,
650
- // TODO(burdon): Lookup tool name/description?
651
- message: `Calling tool (${block.name})`
652
- };
653
- case "toolResult":
654
- return {
655
- id: getToolResultId(message.id, block.toolCallId),
656
- branch,
657
- parents,
658
- icon: block.error ? "ph--x-circle--regular" : "ph--check-circle--regular",
659
- level: block.error ? LogLevel.ERROR : LogLevel.INFO,
660
- message: block.error ? "Tool error: " + block.error : "Tool call succeeded"
661
- };
662
- case "summary":
663
- return {
664
- id: getGenericBlockId(message.id, idx),
665
- branch,
666
- parents,
667
- icon: "ph--rocket--regular",
668
- level: LogLevel.INFO,
669
- message: ContentBlock.createSummaryMessage(block)
670
- };
671
- case "status":
672
- return {
673
- id: getGenericBlockId(message.id, idx),
674
- branch,
675
- parents,
676
- message: block.statusText,
677
- level: LogLevel.INFO,
678
- icon: "ph--flag--regular"
679
- };
680
- case "reasoning":
681
- return {
682
- id: getGenericBlockId(message.id, idx),
683
- branch,
684
- parents,
685
- message: block.reasoningText ?? "Thinking...",
686
- icon: "ph--brain--regular"
687
- };
688
- case "reference":
689
- return {
690
- id: getGenericBlockId(message.id, idx),
691
- branch,
692
- parents,
693
- icon: "ph--link--regular",
694
- message: stringifyRef(block.reference)
695
- };
696
- default:
697
- return null;
698
- }
699
- }).filter(isNotFalsy);
700
- };
701
- var getToolCallId = (messageId, toolCallId) => `${messageId}_toolCall_${toolCallId}`;
702
- var getToolResultId = (messageId, toolCallId) => `${messageId}_toolResult_${toolCallId}`;
703
- var getGenericBlockId = (messageId, idx) => `${messageId}_block_${idx}`;
704
- var getBranchName = (options) => {
705
- if (options.parentMessage && options.toolCallId) {
706
- return `${options.parentMessage}_${options.toolCallId}`;
707
- } else if (options.parentMessage) {
708
- return options.parentMessage;
709
- } else {
710
- return "main";
711
- }
712
- };
713
- var getMessageBranch = (message) => {
714
- return getBranchName({
715
- parentMessage: message.parentMessage,
716
- toolCallId: message.properties?.[MESSAGE_PROPERTY_TOOL_CALL_ID]
717
- });
718
- };
719
- var getParentId = (message) => {
720
- if (message.parentMessage && message.properties?.[MESSAGE_PROPERTY_TOOL_CALL_ID]) {
721
- return getToolCallId(message.parentMessage, message.properties[MESSAGE_PROPERTY_TOOL_CALL_ID]);
722
- } else {
723
- return void 0;
724
- }
725
- };
726
- var stringifyRef = (ref) => {
727
- if (ref.target) {
728
- return stringifyObject(ref.target);
729
- }
730
- return ref.dxn.asEchoDXN()?.echoId ?? ref.dxn.asQueueDXN()?.objectId ?? "";
731
- };
732
- var stringifyObject = (obj) => {
733
- return Obj3.getLabel(obj) ?? Obj3.getTypename(obj) ?? obj.id;
734
- };
735
-
736
- // src/hooks/useExecutionGraph.ts
737
- var useExecutionGraph = (queueRef, lastRequest = false) => {
738
- const queue = useQueue(queueRef?.dxn);
739
- return useMemo6(() => {
740
- const graph = new ExecutionGraph();
741
- graph.addEvents(queue?.objects.filter(Obj4.isObject) ?? []);
742
- return graph.getGraph(lastRequest);
743
- }, [
744
- queue?.objects,
745
- lastRequest
746
- ]);
747
- };
748
-
749
- // src/hooks/useFlush.ts
750
- import { useCallback as useCallback4, useRef, useState as useState4 } from "react";
751
-
752
- // src/hooks/useItemTypes.ts
753
- import { Option as Option2 } from "effect";
754
- import { useEffect as useEffect2, useState as useState5 } from "react";
755
- import { ItemAnnotation } from "@dxos/schema";
756
- var useItemTypes = (space) => {
757
- const [types, setTypes] = useState5([]);
758
- useEffect2(() => {
759
- if (!space) {
760
- return;
761
- }
762
- return space.db.schemaRegistry.query().subscribe((query) => {
763
- const types2 = Array.from(new Set([
764
- ...space.db.graph.schemaRegistry.schemas,
765
- ...query.results
766
- ].filter((type) => Option2.isSome(ItemAnnotation.get(type)))));
767
- setTypes(types2);
768
- }, {
769
- fire: true
770
- });
771
- }, [
772
- space
773
- ]);
774
- return types;
775
- };
776
-
777
- // src/hooks/useMatcherExtension.ts
778
- import { useMemo as useMemo7 } from "react";
779
- import { Type } from "@dxos/echo";
780
- import { matchCompletion, staticCompletion, typeahead } from "@dxos/react-ui-editor";
781
-
782
- // src/hooks/useReferencesProvider.ts
783
- import { useMemo as useMemo8 } from "react";
784
- import { Capabilities as Capabilities3, useCapabilities as useCapabilities3 } from "@dxos/app-framework";
785
- import { Filter as Filter2, Obj as Obj5 } from "@dxos/echo";
786
- var useReferencesProvider = (space) => {
787
- const blueprints = useCapabilities3(Capabilities3.BlueprintDefinition);
788
- return useMemo8(() => {
789
- if (!space) {
790
- return void 0;
791
- }
792
- return {
793
- getReferences: async ({ query }) => {
794
- const { objects } = await space.db.query(Filter2.everything()).run();
795
- return objects.filter((object) => stringMatch(query, Obj5.getLabel(object) ?? "")).filter((object) => !!Obj5.getDXN(object)).map((object) => ({
796
- uri: Obj5.getDXN(object).toString(),
797
- label: Obj5.getLabel(object) ?? ""
798
- }));
799
- },
800
- resolveReference: async ({ uri }) => {
801
- const object = await space.db.query(Filter2.ids(uri)).first();
802
- return {
803
- uri,
804
- label: Obj5.getLabel(object) ?? ""
805
- };
806
- }
807
- };
808
- }, [
809
- space,
810
- blueprints
811
- ]);
812
- };
813
- var stringMatch = (query, label) => label.toLowerCase().startsWith(query.toLowerCase());
814
-
815
- // src/hooks/useResolveRef.ts
816
- import { useMemo as useMemo9, useSyncExternalStore } from "react";
817
- var useResolvedRef = (space, ref) => {
818
- const { subscribe, getSnapshot } = useMemo9(() => {
819
- const resolver = space.db.graph.createRefResolver({});
820
- let currentCallback = void 0;
821
- return {
822
- subscribe: (cb) => {
823
- currentCallback = cb;
824
- return () => {
825
- if (currentCallback === cb) {
826
- currentCallback = void 0;
827
- }
828
- };
829
- },
830
- getSnapshot: () => resolver?.resolveSync(ref.dxn, true, () => {
831
- currentCallback?.();
832
- })
833
- };
834
- }, [
835
- space,
836
- ref.dxn.toString()
837
- ]);
838
- return useSyncExternalStore(subscribe, getSnapshot);
839
- };
840
-
841
- // src/components/Toolbox/Toolbox.tsx
842
- import { useSignals as _useSignals3 } from "@preact-signals/safe-react/tracking";
843
- import React, { Fragment, useEffect as useEffect3, useState as useState6 } from "react";
844
- import { FunctionType } from "@dxos/functions";
845
- import { log as log4 } from "@dxos/log";
846
- import { Filter as Filter3, useQuery } from "@dxos/react-client/echo";
847
- import { useTranslation } from "@dxos/react-ui";
848
- import { mx } from "@dxos/react-ui-theme";
849
- var __dxlog_file4 = "/__w/dxos/dxos/packages/plugins/plugin-assistant/src/components/Toolbox/Toolbox.tsx";
850
- var Toolbox = ({ classNames, functions, services, blueprints, activeBlueprints }) => {
851
- var _effect = _useSignals3();
852
- try {
853
- const { t } = useTranslation(meta.id);
854
- return /* @__PURE__ */ React.createElement("div", {
855
- className: mx("flex flex-col overflow-y-auto box-content", classNames)
856
- }, blueprints && blueprints.length > 0 && /* @__PURE__ */ React.createElement(Section, {
857
- title: "Blueprints",
858
- items: blueprints.map(({ target }) => ({
859
- name: target?.name ?? "",
860
- description: target?.description ?? "",
861
- subitems: target?.tools.map((toolId) => ({
862
- name: `\u2219 ${safeToolId(toolId)}`
863
- }))
864
- }))
865
- }), activeBlueprints && activeBlueprints.length > 0 && /* @__PURE__ */ React.createElement(Section, {
866
- title: "Blueprints",
867
- items: activeBlueprints.map(({ target }) => ({
868
- name: target?.name ?? "",
869
- description: target?.description ?? "",
870
- subitems: target?.tools.map((toolId) => ({
871
- name: `\u2219 ${safeToolId(toolId)}`
872
- }))
873
- }))
874
- }), services && services.length > 0 && /* @__PURE__ */ React.createElement(Section, {
875
- title: "Services",
876
- items: services.map(({ service: { serviceId, name, description } }) => ({
877
- name: name ?? serviceId,
878
- description
879
- }))
880
- }), functions && functions.length > 0 && /* @__PURE__ */ React.createElement(Section, {
881
- title: "Functions",
882
- items: functions.map(({ name, description }) => ({
883
- name,
884
- description
885
- }))
886
- }));
887
- } finally {
888
- _effect.f();
889
- }
890
- };
891
- var Section = ({ title, items, striped }) => {
892
- var _effect = _useSignals3();
893
- try {
894
- const stripeClassNames = "odd:bg-neutral-50 dark:odd:bg-neutral-800";
895
- const gridClassNames = "grid grid-cols-[8rem_1fr]";
896
- const subGridClassNames = mx("col-span-full grid grid-cols-subgrid text-xs px-2", striped && stripeClassNames);
897
- return /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement("h1", {
898
- className: "px-2 text-sm"
899
- }, title), /* @__PURE__ */ React.createElement("div", {
900
- className: gridClassNames
901
- }, items.map(({ name, description, subitems }, i) => /* @__PURE__ */ React.createElement(Fragment, {
902
- key: i
903
- }, name && /* @__PURE__ */ React.createElement("div", {
904
- className: subGridClassNames
905
- }, /* @__PURE__ */ React.createElement("div", {
906
- className: "truncate text-primary-500"
907
- }, name), /* @__PURE__ */ React.createElement("div", {
908
- className: "line-clamp-2"
909
- }, description)), subitems?.map(({ name: name2, description: description2 }, i2) => /* @__PURE__ */ React.createElement("div", {
910
- key: i2,
911
- className: mx(subGridClassNames, striped && stripeClassNames)
912
- }, /* @__PURE__ */ React.createElement("div", {
913
- className: "truncate"
914
- }, name2), /* @__PURE__ */ React.createElement("div", {
915
- className: "line-clamp-3 text-subdued"
916
- }, description2)))))));
917
- } finally {
918
- _effect.f();
919
- }
920
- };
921
- var ToolboxContainer = ({ classNames, space, processor }) => {
922
- var _effect = _useSignals3();
923
- try {
924
- const services = useQuery(space, Filter3.type(ServiceType));
925
- const [serviceTools, setServiceTools] = useState6([]);
926
- useEffect3(() => {
927
- log4("creating service tools...", {
928
- services: services.length
929
- }, {
930
- F: __dxlog_file4,
931
- L: 117,
932
- S: void 0,
933
- C: (f, a) => f(...a)
934
- });
935
- queueMicrotask(async () => {
936
- });
937
- }, [
938
- services
939
- ]);
940
- const functions = useQuery(space, Filter3.type(FunctionType));
941
- return /* @__PURE__ */ React.createElement(Toolbox, {
942
- classNames,
943
- blueprints: processor?.context.blueprints.value,
944
- services: serviceTools,
945
- functions
946
- });
947
- } finally {
948
- _effect.f();
949
- }
950
- };
951
- var safeToolId = (name) => {
952
- return name.split("_").pop();
953
- };
954
-
955
- // src/components/Chat/Chat.tsx
956
- import { useSignals as _useSignals13 } from "@preact-signals/safe-react/tracking";
957
- import { Prec } from "@codemirror/state";
958
- import { keymap } from "@codemirror/view";
959
- import { useRxValue } from "@effect-rx/rx-react";
960
- import { createContext } from "@radix-ui/react-context";
961
- import { Array as Array2, Option as Option3 } from "effect";
962
- import React11, { useCallback as useCallback5, useEffect as useEffect7, useMemo as useMemo14, useRef as useRef3, useState as useState10 } from "react";
963
- import { Event } from "@dxos/async";
964
- import { Obj as Obj10 } from "@dxos/echo";
965
- import { log as log5 } from "@dxos/log";
966
- import { useVoiceInput } from "@dxos/plugin-transcription";
967
- import { getSpace, useQueue as useQueue2 } from "@dxos/react-client/echo";
968
- import { useIdentity } from "@dxos/react-client/halo";
969
- import { Input, useTranslation as useTranslation7 } from "@dxos/react-ui";
970
- import { ChatEditor, references } from "@dxos/react-ui-chat";
971
- import { mx as mx7 } from "@dxos/react-ui-theme";
972
- import { DataType as DataType3 } from "@dxos/schema";
973
- import { isNotFalsy as isNotFalsy3 } from "@dxos/util";
974
-
975
- // src/components/ChatPrompt/ChatActions.tsx
976
- import { useSignals as _useSignals4 } from "@preact-signals/safe-react/tracking";
977
- import React2 from "react";
978
- import { IconButton, useTranslation as useTranslation2 } from "@dxos/react-ui";
979
- import { mx as mx2 } from "@dxos/react-ui-theme";
980
- var ChatActions = ({ classNames, children, microphone, recording, processing, onEvent }) => {
981
- var _effect = _useSignals4();
982
- try {
983
- const { t } = useTranslation2(meta.id);
984
- return /* @__PURE__ */ React2.createElement("div", {
985
- className: mx2("flex items-center mie-1", classNames)
986
- }, children, /* @__PURE__ */ React2.createElement(IconButton, {
987
- disabled: !processing,
988
- variant: "ghost",
989
- size: 5,
990
- icon: "ph--x--regular",
991
- iconOnly: true,
992
- label: t("button cancel processing"),
993
- onClick: () => onEvent?.({
994
- type: "cancel"
995
- })
996
- }), microphone && /* @__PURE__ */ React2.createElement(IconButton, {
997
- disabled: !processing,
998
- classNames: mx2(recording && "bg-primary-500"),
999
- variant: "ghost",
1000
- size: 5,
1001
- icon: "ph--microphone--regular",
1002
- iconOnly: true,
1003
- noTooltip: true,
1004
- label: t("button microphone"),
1005
- onMouseDown: () => onEvent?.({
1006
- type: "record-start"
1007
- }),
1008
- onMouseUp: () => onEvent?.({
1009
- type: "record-stop"
1010
- }),
1011
- onTouchStart: () => onEvent?.({
1012
- type: "record-start"
1013
- }),
1014
- onTouchEnd: () => onEvent?.({
1015
- type: "record-stop"
1016
- })
1017
- }));
1018
- } finally {
1019
- _effect.f();
1020
- }
1021
- };
1022
-
1023
- // src/components/ChatPrompt/ChatOptions.tsx
1024
- import { useSignals as _useSignals5 } from "@preact-signals/safe-react/tracking";
1025
- import React3, { useMemo as useMemo10, useState as useState7 } from "react";
1026
- import { Filter as Filter4, Obj as Obj6, Type as Type2 } from "@dxos/echo";
1027
- import { useQuery as useQuery2 } from "@dxos/react-client/echo";
1028
- import { Icon, IconButton as IconButton2, Popover, Select, useTranslation as useTranslation3 } from "@dxos/react-ui";
1029
- import { SearchList } from "@dxos/react-ui-searchlist";
1030
- import { Tabs } from "@dxos/react-ui-tabs";
1031
- var panelClassNames = "is-[calc(100dvw-.5rem)] sm:is-max md:is-[25rem] max-is-[--text-content]";
1032
- var ChatOptions = ({ space, context, blueprintRegistry, presets, preset, onPresetChange }) => {
1033
- var _effect = _useSignals5();
1034
- try {
1035
- const { t } = useTranslation3(meta.id);
1036
- return /* @__PURE__ */ React3.createElement("div", {
1037
- role: "none",
1038
- className: "flex gap-0.5"
1039
- }, /* @__PURE__ */ React3.createElement(Popover.Root, null, /* @__PURE__ */ React3.createElement(Popover.Trigger, {
1040
- asChild: true
1041
- }, /* @__PURE__ */ React3.createElement(IconButton2, {
1042
- variant: "ghost",
1043
- icon: "ph--plus--regular",
1044
- iconOnly: true,
1045
- size: 5,
1046
- label: t("button context objects")
1047
- })), /* @__PURE__ */ React3.createElement(Popover.Portal, null, /* @__PURE__ */ React3.createElement(Popover.Content, {
1048
- side: "top",
1049
- classNames: panelClassNames
1050
- }, /* @__PURE__ */ React3.createElement(ObjectsPanel, {
1051
- space,
1052
- context
1053
- }), /* @__PURE__ */ React3.createElement(Popover.Arrow, null)))), /* @__PURE__ */ React3.createElement(Popover.Root, null, /* @__PURE__ */ React3.createElement(Popover.Trigger, {
1054
- asChild: true
1055
- }, /* @__PURE__ */ React3.createElement(IconButton2, {
1056
- variant: "ghost",
1057
- icon: "ph--sliders-horizontal--regular",
1058
- iconOnly: true,
1059
- size: 5,
1060
- label: t("button context settings")
1061
- })), /* @__PURE__ */ React3.createElement(Popover.Portal, null, /* @__PURE__ */ React3.createElement(Popover.Content, {
1062
- side: "top",
1063
- classNames: panelClassNames
1064
- }, /* @__PURE__ */ React3.createElement(Tabs.Root, {
1065
- orientation: "horizontal",
1066
- defaultValue: "blueprints",
1067
- defaultActivePart: "list"
1068
- }, /* @__PURE__ */ React3.createElement(Tabs.Viewport, {
1069
- 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'
1070
- }, /* @__PURE__ */ React3.createElement(Tabs.Tabpanel, {
1071
- value: "blueprints"
1072
- }, /* @__PURE__ */ React3.createElement(BlueprintsPanel, {
1073
- blueprintRegistry,
1074
- space,
1075
- context
1076
- })), /* @__PURE__ */ React3.createElement(Tabs.Tabpanel, {
1077
- value: "model"
1078
- }, /* @__PURE__ */ React3.createElement(ModelsPanel, {
1079
- presets,
1080
- preset,
1081
- onPresetChange
1082
- })), /* @__PURE__ */ React3.createElement(Tabs.Tablist, {
1083
- classNames: "sm:overflow-x-hidden justify-center p-[--dx-cardSpacingChrome] border-bs border-subduedSeparator order-last"
1084
- }, /* @__PURE__ */ React3.createElement(Tabs.IconTab, {
1085
- value: "blueprints",
1086
- icon: "ph--blueprint--regular",
1087
- label: t("blueprints in context title")
1088
- }), /* @__PURE__ */ React3.createElement(Tabs.IconTab, {
1089
- value: "model",
1090
- label: t("chat model title"),
1091
- icon: "ph--cpu--regular"
1092
- })))), /* @__PURE__ */ React3.createElement(Popover.Arrow, null)))));
1093
- } finally {
1094
- _effect.f();
1095
- }
1096
- };
1097
- var BlueprintsPanel = ({ blueprintRegistry, space, context }) => {
1098
- var _effect = _useSignals5();
1099
- try {
1100
- const { t } = useTranslation3(meta.id);
1101
- const blueprints = useBlueprints({
1102
- blueprintRegistry
1103
- });
1104
- const activeBlueprints = useActiveBlueprints({
1105
- context
1106
- });
1107
- const { onUpdateBlueprint } = useBlueprintHandlers({
1108
- space,
1109
- context,
1110
- blueprintRegistry
1111
- });
1112
- return /* @__PURE__ */ React3.createElement(SearchList.Root, null, /* @__PURE__ */ React3.createElement(SearchList.Content, {
1113
- classNames: "plb-cardSpacingChrome"
1114
- }, blueprints.map((blueprint) => {
1115
- const isActive = activeBlueprints.has(blueprint.key);
1116
- return /* @__PURE__ */ React3.createElement(SearchList.Item, {
1117
- classNames: "flex items-center overflow-hidden",
1118
- key: blueprint.key,
1119
- value: blueprint.name,
1120
- onSelect: () => onUpdateBlueprint?.(blueprint.key, !isActive)
1121
- }, /* @__PURE__ */ React3.createElement("div", {
1122
- className: "grow truncate"
1123
- }, blueprint.name), /* @__PURE__ */ React3.createElement(Icon, {
1124
- icon: "ph--check--regular",
1125
- classNames: [
1126
- !isActive && "invisible"
1127
- ]
1128
- }));
1129
- })), /* @__PURE__ */ React3.createElement(SearchList.Input, {
1130
- placeholder: t("search placeholder"),
1131
- classNames: "mbe-cardSpacingChrome"
1132
- }));
1133
- } finally {
1134
- _effect.f();
1135
- }
1136
- };
1137
- var ModelsPanel = ({ presets, preset, onPresetChange }) => {
1138
- var _effect = _useSignals5();
1139
- try {
1140
- return /* @__PURE__ */ React3.createElement("ul", {
1141
- role: "listbox",
1142
- className: "plb-cardSpacingChrome"
1143
- }, presets?.map(({ id, label }) => {
1144
- const isActive = preset === id;
1145
- return /* @__PURE__ */ React3.createElement("li", {
1146
- role: "option",
1147
- key: id,
1148
- "aria-selected": isActive,
1149
- tabIndex: 0,
1150
- className: "overflow-hidden dx-focus-ring flex gap-2 p-1 pis-2 pie-2 items-center rounded-sm select-none cursor-pointer hover:bg-hoverOverlay",
1151
- onClick: () => onPresetChange?.(id)
1152
- }, /* @__PURE__ */ React3.createElement("div", {
1153
- className: "grow truncate"
1154
- }, label), /* @__PURE__ */ React3.createElement(Icon, {
1155
- icon: "ph--check--regular",
1156
- classNames: [
1157
- !isActive && "invisible"
1158
- ]
1159
- }));
1160
- }));
1161
- } finally {
1162
- _effect.f();
1163
- }
1164
- };
1165
- var ANY = "__any__";
1166
- var ObjectsPanel = ({ space, context }) => {
1167
- var _effect = _useSignals5();
1168
- try {
1169
- const { t } = useTranslation3(meta.id);
1170
- const types = useItemTypes(space);
1171
- const typenames = useMemo10(() => {
1172
- const typenames2 = types.map((type) => {
1173
- const typename2 = Type2.getTypename(type);
1174
- return {
1175
- typename: typename2,
1176
- label: t("typename label", {
1177
- ns: typename2,
1178
- defaultValue: typename2
1179
- })
1180
- };
1181
- });
1182
- typenames2.sort((a, b) => a.label.localeCompare(b.label));
1183
- return typenames2;
1184
- }, [
1185
- types
1186
- ]);
1187
- const [typename, setTypename] = useState7(ANY);
1188
- const anyFilter = useMemo10(() => Filter4.or(...typenames.map(({ typename: typename2 }) => Filter4.typename(typename2))), [
1189
- typenames
1190
- ]);
1191
- const objects = useQuery2(space, typename === ANY ? anyFilter : Filter4.typename(typename));
1192
- const { objects: contextObjects, onUpdateObject } = useContextObjects({
1193
- space,
1194
- context
1195
- });
1196
- return /* @__PURE__ */ React3.createElement(SearchList.Root, {
1197
- classNames: "pis-2 pie-2"
1198
- }, /* @__PURE__ */ React3.createElement(SearchList.Content, {
1199
- classNames: "plb-cardSpacingChrome [&:has([cmdk-list-sizer]:empty)]:plb-0"
1200
- }, objects.length ? objects.map((object) => {
1201
- const label = Obj6.getLabel(object) ?? Obj6.getTypename(object) ?? object.id;
1202
- const isActive = contextObjects.findIndex((obj) => obj.id === object.id) !== -1;
1203
- return /* @__PURE__ */ React3.createElement(SearchList.Item, {
1204
- classNames: "flex items-center overflow-hidden",
1205
- key: object.id,
1206
- value: object.id,
1207
- onSelect: () => onUpdateObject?.(Obj6.getDXN(object), !isActive)
1208
- }, /* @__PURE__ */ React3.createElement("div", {
1209
- className: "grow truncate"
1210
- }, label), /* @__PURE__ */ React3.createElement(Icon, {
1211
- icon: "ph--check--regular",
1212
- classNames: [
1213
- !isActive && "invisible"
1214
- ]
1215
- }));
1216
- }) : /* @__PURE__ */ React3.createElement(SearchList.Item, null, t("no results"))), /* @__PURE__ */ React3.createElement("div", {
1217
- role: "none",
1218
- className: "grid grid-cols-[min-content_1fr] gap-2 mbe-cardSpacingChrome"
1219
- }, /* @__PURE__ */ React3.createElement(Select.Root, {
1220
- value: typename === ANY ? void 0 : typename,
1221
- onValueChange: setTypename
1222
- }, /* @__PURE__ */ React3.createElement(Select.TriggerButton, {
1223
- density: "fine",
1224
- placeholder: t("type filter placeholder")
1225
- }), /* @__PURE__ */ React3.createElement(Select.Portal, null, /* @__PURE__ */ React3.createElement(Select.Content, null, /* @__PURE__ */ React3.createElement(Select.ScrollUpButton, null), /* @__PURE__ */ React3.createElement(Select.Viewport, null, /* @__PURE__ */ React3.createElement(Select.Option, {
1226
- value: ANY
1227
- }, t("any type filter label")), typenames.map(({ typename: typename2, label }) => /* @__PURE__ */ React3.createElement(Select.Option, {
1228
- key: typename2,
1229
- value: typename2
1230
- }, label))), /* @__PURE__ */ React3.createElement(Select.ScrollDownButton, null), /* @__PURE__ */ React3.createElement(Select.Arrow, null)))), /* @__PURE__ */ React3.createElement(SearchList.Input, {
1231
- placeholder: t("search placeholder"),
1232
- classNames: "mbe-0"
1233
- })));
1234
- } finally {
1235
- _effect.f();
1236
- }
1237
- };
1238
-
1239
- // src/components/ChatPrompt/ChatPresets.tsx
1240
- import { useSignals as _useSignals6 } from "@preact-signals/safe-react/tracking";
1241
- import React4 from "react";
1242
- import { Select as Select2 } from "@dxos/react-ui";
1243
-
1244
- // src/components/ChatPrompt/ChatReferences.tsx
1245
- import { useSignals as _useSignals7 } from "@preact-signals/safe-react/tracking";
1246
- import React5 from "react";
1247
- import { Obj as Obj7 } from "@dxos/echo";
1248
- import { IconButton as IconButton3, toLocalizedString, useTranslation as useTranslation4 } from "@dxos/react-ui";
1249
- import { mx as mx3 } from "@dxos/react-ui-theme";
1250
- var ChatReferences = ({ classNames, context, space }) => {
1251
- var _effect = _useSignals7();
1252
- try {
1253
- const { t } = useTranslation4(meta.id);
1254
- const { objects, onUpdateObject } = useContextObjects({
1255
- space,
1256
- context
1257
- });
1258
- return /* @__PURE__ */ React5.createElement("ul", {
1259
- className: mx3("flex flex-wrap", classNames)
1260
- }, objects.map((obj) => {
1261
- const dxn = Obj7.getDXN(obj);
1262
- const typename = Obj7.getTypename(obj);
1263
- const label = Obj7.getLabel(obj) ?? (typename ? [
1264
- "object name placeholder",
1265
- {
1266
- ns: typename
1267
- }
1268
- ] : obj.id);
1269
- return /* @__PURE__ */ React5.createElement("li", {
1270
- key: dxn.toString(),
1271
- className: "dx-tag plb-0 pis-2 flex items-center",
1272
- "data-hue": "neutral"
1273
- }, toLocalizedString(label, t), /* @__PURE__ */ React5.createElement(IconButton3, {
1274
- iconOnly: true,
1275
- variant: "ghost",
1276
- label: t("remove object in context label"),
1277
- classNames: "p-0 hover:bg-transparent",
1278
- size: 3,
1279
- icon: "ph--x--bold",
1280
- onClick: () => onUpdateObject?.(dxn, false)
1281
- }));
1282
- }));
1283
- } finally {
1284
- _effect.f();
1285
- }
1286
- };
1287
-
1288
- // src/components/ChatPrompt/ChatStatusIndicator.tsx
1289
- import { useSignals as _useSignals8 } from "@preact-signals/safe-react/tracking";
1290
- import React6, { useEffect as useEffect4, useState as useState8 } from "react";
1291
- import { Tooltip, useTimeout } from "@dxos/react-ui";
1292
- import { Spinner } from "@dxos/react-ui-sfx";
1293
- import { mx as mx4 } from "@dxos/react-ui-theme";
1294
- var period = 3e3;
1295
- var ChatStatusIndicator = ({ classNames, preset, processing, error, ...props }) => {
1296
- var _effect = _useSignals8();
1297
- try {
1298
- const [init, setInit] = useState8(false);
1299
- useEffect4(() => setInit(false), [
1300
- preset
1301
- ]);
1302
- useTimeout(async () => {
1303
- setInit(true);
1304
- }, period / 2, [
1305
- preset
1306
- ]);
1307
- return /* @__PURE__ */ React6.createElement("div", {
1308
- role: "none",
1309
- className: mx4("relative flex", classNames)
1310
- }, /* @__PURE__ */ React6.createElement(Spinner, {
1311
- duration: period,
1312
- state: !init ? "flash" : error ? "error" : processing ? "spin" : "pulse",
1313
- ...props
1314
- }), error && /* @__PURE__ */ React6.createElement(Tooltip.Trigger, {
1315
- asChild: true,
1316
- content: error.message
1317
- }, /* @__PURE__ */ React6.createElement("div", {
1318
- className: "absolute inset-0"
1319
- })));
1320
- } finally {
1321
- _effect.f();
1322
- }
1323
- };
1324
-
1325
- // src/components/ChatThread/ChatThread.tsx
1326
- import { useSignals as _useSignals12 } from "@preact-signals/safe-react/tracking";
1327
- import React10, { Fragment as Fragment2, forwardRef, useEffect as useEffect6, useMemo as useMemo13 } from "react";
1328
- import { invariant as invariant2 } from "@dxos/invariant";
1329
- import { PublicKey } from "@dxos/keys";
1330
- import { ScrollContainer } from "@dxos/react-ui-components";
1331
- import { mx as mx6 } from "@dxos/react-ui-theme";
1332
- import { keyToFallback } from "@dxos/util";
1333
-
1334
- // src/components/ChatThread/ChatMessage.tsx
1335
- import { useSignals as _useSignals11 } from "@preact-signals/safe-react/tracking";
1336
- import React9, { useMemo as useMemo12 } from "react";
1337
- import { ErrorBoundary, Surface } from "@dxos/app-framework";
1338
- import { resolveRef } from "@dxos/client";
1339
- import { Obj as Obj9 } from "@dxos/echo";
1340
- import { invariant } from "@dxos/invariant";
1341
- import { DXN, DXN_ECHO_REGEXP } from "@dxos/keys";
1342
- import { useClient } from "@dxos/react-client";
1343
- import { Button, IconButton as IconButton4, Link, useTranslation as useTranslation6 } from "@dxos/react-ui";
1344
- import { MarkdownViewer, ToggleContainer as ToggleContainer2 } from "@dxos/react-ui-components";
1345
- import { Json as Json2 } from "@dxos/react-ui-syntax-highlighter";
1346
- import { mx as mx5 } from "@dxos/react-ui-theme";
1347
- import { ContentBlock as ContentBlock2 } from "@dxos/schema";
1348
- import { safeParseJson as safeParseJson2 } from "@dxos/util";
1349
-
1350
- // src/components/ChatThread/Link.tsx
1351
- import { useSignals as _useSignals9 } from "@preact-signals/safe-react/tracking";
1352
- import React7 from "react";
1353
- import { Obj as Obj8, Ref as Ref3 } from "@dxos/echo";
1354
- import { DxRefTag } from "@dxos/lit-ui/react";
1355
- var ObjectLink = ({ space, dxn }) => {
1356
- var _effect = _useSignals9();
1357
- try {
1358
- const object = useResolvedRef(space, Ref3.fromDXN(dxn));
1359
- const title = Obj8.getLabel(object) ?? object?.id ?? dxn.toString();
1360
- return /* @__PURE__ */ React7.createElement(DxRefTag, {
1361
- refid: dxn.toString()
1362
- }, title);
1363
- } finally {
1364
- _effect.f();
1365
- }
1366
- };
1367
-
1368
- // src/components/ChatThread/ToolBlock.tsx
1369
- import { useSignals as _useSignals10 } from "@preact-signals/safe-react/tracking";
1370
- import React8, { useEffect as useEffect5, useMemo as useMemo11, useRef as useRef2, useState as useState9 } from "react";
1371
- import { useTranslation as useTranslation5 } from "@dxos/react-ui";
1372
- import { NumericTabs, TextCrawl, ToggleContainer } from "@dxos/react-ui-components";
1373
- import { Json } from "@dxos/react-ui-syntax-highlighter";
1374
- import { isNonNullable as isNonNullable3, isNotFalsy as isNotFalsy2 } from "@dxos/util";
1375
- import { safeParseJson } from "@dxos/util";
1376
- var isToolMessage = (message) => {
1377
- return message.blocks.some((block) => block._tag === "toolCall" || block._tag === "toolResult");
1378
- };
1379
- var ToolBlock = ({ message, toolProvider }) => {
1380
- var _effect = _useSignals10();
1381
- try {
1382
- const { t } = useTranslation5(meta.id);
1383
- const { blocks = [] } = message;
1384
- const getToolCaption = (tool, status) => {
1385
- if (!tool) {
1386
- return t("calling tool label");
1387
- }
1388
- return status?.message ?? tool.description ?? [
1389
- t("calling label"),
1390
- tool.name
1391
- ].join(" ");
1392
- };
1393
- const items = useMemo11(() => {
1394
- let lastToolCall;
1395
- const tools = toolProvider();
1396
- return blocks.filter((block) => block._tag === "toolCall" || block._tag === "toolResult" || block._tag === "summary").map((block) => {
1397
- switch (block._tag) {
1398
- case "toolCall": {
1399
- if (block.pending && lastToolCall?.block.toolCallId === block.toolCallId) {
1400
- return null;
1401
- }
1402
- const tool = tools.find((tool2) => tool2.name === block.name);
1403
- lastToolCall = {
1404
- tool,
1405
- block
1406
- };
1407
- return {
1408
- title: getToolCaption(lastToolCall?.tool),
1409
- content: {
1410
- ...block,
1411
- input: safeParseJson(block.input)
1412
- }
1413
- };
1414
- }
1415
- case "toolResult": {
1416
- if (block.error) {
1417
- return {
1418
- title: t("error label"),
1419
- content: block
1420
- };
1421
- }
1422
- const title = getToolCaption(lastToolCall?.tool ?? t("tool result label"));
1423
- lastToolCall = void 0;
1424
- return {
1425
- title,
1426
- content: {
1427
- ...block,
1428
- result: safeParseJson(block.result)
1429
- }
1430
- };
1431
- }
1432
- case "summary": {
1433
- if (!lastToolCall) {
1434
- return null;
1435
- }
1436
- return {
1437
- title: t("summary label"),
1438
- content: block
1439
- };
1440
- }
1441
- }
1442
- }).filter(isNonNullable3);
1443
- }, [
1444
- blocks
1445
- ]);
1446
- return /* @__PURE__ */ React8.createElement(ToolContainer, {
1447
- items
1448
- });
1449
- } finally {
1450
- _effect.f();
1451
- }
1452
- };
1453
- var ToolContainer = ({ items }) => {
1454
- var _effect = _useSignals10();
1455
- try {
1456
- const tabsRef = useRef2(null);
1457
- const [selected, setSelected] = useState9(0);
1458
- const [open, setOpen] = useState9(false);
1459
- useEffect5(() => {
1460
- if (open) {
1461
- tabsRef.current?.focus();
1462
- }
1463
- }, [
1464
- open
1465
- ]);
1466
- const handleSelect = (index) => {
1467
- setSelected(index);
1468
- };
1469
- const title = useMemo11(() => {
1470
- const lines = items.map((item) => item.title).filter(isNotFalsy2);
1471
- return /* @__PURE__ */ React8.createElement(TextCrawl, {
1472
- key: "status-roll",
1473
- lines,
1474
- autoAdvance: true
1475
- });
1476
- }, [
1477
- items
1478
- ]);
1479
- const data = items[selected].content;
1480
- return /* @__PURE__ */ React8.createElement(ToggleContainer.Root, {
1481
- classNames: styles.panel,
1482
- open,
1483
- onChangeOpen: setOpen
1484
- }, /* @__PURE__ */ React8.createElement(ToggleContainer.Header, {
1485
- classNames: styles.panelHeader,
1486
- title
1487
- }), /* @__PURE__ */ React8.createElement(ToggleContainer.Content, {
1488
- classNames: [
1489
- "grid grid-cols-[32px_1fr]",
1490
- styles.panelContent
1491
- ]
1492
- }, /* @__PURE__ */ React8.createElement(NumericTabs, {
1493
- ref: tabsRef,
1494
- classNames: "p-1",
1495
- length: items.length,
1496
- selected,
1497
- onSelect: handleSelect
1498
- }), /* @__PURE__ */ React8.createElement(Json, {
1499
- data,
1500
- classNames: styles.json,
1501
- replacer: {
1502
- maxDepth: 3,
1503
- maxArrayLen: 10,
1504
- maxStringLen: 128
1505
- }
1506
- })));
1507
- } finally {
1508
- _effect.f();
1509
- }
1510
- };
1511
-
1512
- // src/components/ChatThread/ChatMessage.tsx
1513
- var __dxlog_file5 = "/__w/dxos/dxos/packages/plugins/plugin-assistant/src/components/ChatThread/ChatMessage.tsx";
1514
- var styles = {
1515
- margin: "pie-4 pis-4",
1516
- padding: "pis-2 pie-2 pbs-0.5 pbe-0.5",
1517
- panel: "is-full rounded-sm",
1518
- panelHeader: "bg-groupSurface",
1519
- panelContent: "bg-modalSurface",
1520
- json: "!p-1 text-xs bg-transparent"
1521
- };
1522
- var ChatMessage = ({ classNames, debug, space, message, toolProvider, onEvent, onDelete }) => {
1523
- var _effect = _useSignals11();
1524
- try {
1525
- const { t } = useTranslation6(meta.id);
1526
- const { sender: { role }, blocks } = message;
1527
- if (!debug && toolProvider && isToolMessage(message)) {
1528
- return /* @__PURE__ */ React9.createElement(MessageItem, {
1529
- classNames: [
1530
- styles.margin,
1531
- "animate-[fadeIn_0.5s]"
1532
- ]
1533
- }, /* @__PURE__ */ React9.createElement(ToolBlock, {
1534
- message,
1535
- toolProvider
1536
- }));
1537
- }
1538
- return /* @__PURE__ */ React9.createElement(React9.Fragment, null, blocks.map((block, idx) => {
1539
- if (block._tag === "text" && block.text.replaceAll(/\s+/g, "").length === 0) {
1540
- return null;
1541
- }
1542
- const Component = components[block._tag] ?? components.default;
1543
- if (!Component) {
1544
- return null;
1545
- }
1546
- return /* @__PURE__ */ React9.createElement(MessageItem, {
1547
- key: idx,
1548
- classNames,
1549
- user: block._tag === "text" && role === "user"
1550
- }, /* @__PURE__ */ React9.createElement(ErrorBoundary, {
1551
- data: block
1552
- }, /* @__PURE__ */ React9.createElement(Component, {
1553
- space,
1554
- block,
1555
- onEvent
1556
- })));
1557
- }), onDelete && /* @__PURE__ */ React9.createElement("div", {
1558
- className: mx5("flex justify-end pbs-2 pbe-2 opacity-50 hover:opacity-100", styles.margin)
1559
- }, /* @__PURE__ */ React9.createElement(IconButton4, {
1560
- classNames: "animate-[fadeIn_0.5s]",
1561
- icon: "ph--trash--regular",
1562
- iconOnly: true,
1563
- label: t("button delete message"),
1564
- onClick: () => onDelete()
1565
- })));
1566
- } finally {
1567
- _effect.f();
1568
- }
1569
- };
1570
- var components = {
1571
- //
1572
- // Text
1573
- //
1574
- ["text"]: ({ space, block }) => {
1575
- invariant(block._tag === "text", void 0, {
1576
- F: __dxlog_file5,
1577
- L: 122,
1578
- S: void 0,
1579
- A: [
1580
- "block._tag === 'text'",
1581
- ""
1582
- ]
1583
- });
1584
- return /* @__PURE__ */ React9.createElement(MarkdownViewer, {
1585
- content: preprocessTextContent(block.text),
1586
- components: {
1587
- a: ({ node: { properties }, children, href, ...props }) => {
1588
- if (space && typeof properties?.href === "string" && properties?.href?.startsWith("dxn")) {
1589
- try {
1590
- const dxn = DXN.parse(properties.href);
1591
- return /* @__PURE__ */ React9.createElement(ObjectLink, {
1592
- space,
1593
- dxn
1594
- });
1595
- } catch {
1596
- }
1597
- }
1598
- return /* @__PURE__ */ React9.createElement(Link, {
1599
- href,
1600
- target: "_blank",
1601
- rel: "noopener noreferrer",
1602
- ...props
1603
- }, children);
1604
- },
1605
- img: ({ node: { properties } }) => {
1606
- const client = useClient();
1607
- if (space && typeof properties?.src === "string" && properties?.src?.startsWith("dxn")) {
1608
- try {
1609
- const dxn = DXN.parse(properties?.src);
1610
- const subject = resolveRef(client, dxn, space);
1611
- const data = useMemo12(() => ({
1612
- subject
1613
- }), [
1614
- subject
1615
- ]);
1616
- return /* @__PURE__ */ React9.createElement(Surface, {
1617
- role: "card--transclusion",
1618
- data,
1619
- limit: 1
1620
- });
1621
- } catch {
1622
- }
1623
- }
1624
- return /* @__PURE__ */ React9.createElement("img", properties);
1625
- }
1626
- }
1627
- });
1628
- },
1629
- //
1630
- // Suggest
1631
- //
1632
- ["suggestion"]: ({ block, onEvent }) => {
1633
- invariant(block._tag === "suggestion", void 0, {
1634
- F: __dxlog_file5,
1635
- L: 165,
1636
- S: void 0,
1637
- A: [
1638
- "block._tag === 'suggestion'",
1639
- ""
1640
- ]
1641
- });
1642
- return /* @__PURE__ */ React9.createElement(IconButton4, {
1643
- icon: "ph--lightning--regular",
1644
- label: block.text,
1645
- classNames: "text-description",
1646
- onClick: () => onEvent?.({
1647
- type: "submit",
1648
- text: block.text
1649
- })
1650
- });
1651
- },
1652
- //
1653
- // Select
1654
- //
1655
- ["select"]: ({ block, onEvent }) => {
1656
- invariant(block._tag === "select", void 0, {
1657
- F: __dxlog_file5,
1658
- L: 181,
1659
- S: void 0,
1660
- A: [
1661
- "block._tag === 'select'",
1662
- ""
1663
- ]
1664
- });
1665
- return /* @__PURE__ */ React9.createElement("div", {
1666
- className: "flex flex-wrap gap-1"
1667
- }, block.options.map((option, idx) => /* @__PURE__ */ React9.createElement(Button, {
1668
- classNames: "animate-[fadeIn_0.5s] rounded-sm text-sm",
1669
- key: idx,
1670
- onClick: () => onEvent?.({
1671
- type: "submit",
1672
- text: option
1673
- })
1674
- }, option)));
1675
- },
1676
- //
1677
- // Toolkit
1678
- //
1679
- ["toolkit"]: ({ block }) => {
1680
- invariant(block._tag === "toolkit", void 0, {
1681
- F: __dxlog_file5,
1682
- L: 202,
1683
- S: void 0,
1684
- A: [
1685
- "block._tag === 'toolkit'",
1686
- ""
1687
- ]
1688
- });
1689
- const { t } = useTranslation6(meta.id);
1690
- return /* @__PURE__ */ React9.createElement(ToggleContainer2.Root, {
1691
- classNames: styles.panel,
1692
- defaultOpen: true
1693
- }, /* @__PURE__ */ React9.createElement(ToggleContainer2.Header, {
1694
- classNames: styles.panelHeader,
1695
- title: t("toolkit label")
1696
- }), /* @__PURE__ */ React9.createElement(ToggleContainer2.Content, {
1697
- classNames: styles.panelContent
1698
- }, /* @__PURE__ */ React9.createElement(Toolbox, null)));
1699
- },
1700
- //
1701
- // Summary
1702
- //
1703
- ["summary"]: ({ block }) => {
1704
- invariant(block._tag === "summary", void 0, {
1705
- F: __dxlog_file5,
1706
- L: 219,
1707
- S: void 0,
1708
- A: [
1709
- "block._tag === 'summary'",
1710
- ""
1711
- ]
1712
- });
1713
- const summary = ContentBlock2.createSummaryMessage(block, false);
1714
- return /* @__PURE__ */ React9.createElement("div", {
1715
- className: "text-sm text-subdued"
1716
- }, summary);
1717
- },
1718
- //
1719
- // JSON
1720
- //
1721
- ["json"]: ({ block, onEvent }) => {
1722
- invariant(block._tag === "json", void 0, {
1723
- F: __dxlog_file5,
1724
- L: 229,
1725
- S: void 0,
1726
- A: [
1727
- "block._tag === 'json'",
1728
- ""
1729
- ]
1730
- });
1731
- switch (block.disposition) {
1732
- case "graph": {
1733
- return /* @__PURE__ */ React9.createElement("div", {
1734
- className: "flex flex-wrap gap-1"
1735
- }, /* @__PURE__ */ React9.createElement(Surface, {
1736
- role: "card",
1737
- data: {
1738
- subject: JSON.parse(block.data ?? "{}")
1739
- },
1740
- limit: 1,
1741
- fallback: /* @__PURE__ */ React9.createElement("div", {
1742
- className: "font-mono text-xs text-pre"
1743
- }, block.data)
1744
- }), onEvent && /* @__PURE__ */ React9.createElement(IconButton4, {
1745
- icon: "ph--plus--regular",
1746
- label: "Add to graph",
1747
- onClick: () => onEvent?.({
1748
- type: "add",
1749
- object: JSON.parse(block.data ?? "{}")
1750
- })
1751
- }));
1752
- }
1753
- default: {
1754
- return /* @__PURE__ */ React9.createElement(ToggleContainer2.Root, {
1755
- classNames: styles.panel
1756
- }, /* @__PURE__ */ React9.createElement(ToggleContainer2.Header, {
1757
- classNames: styles.panelHeader,
1758
- title: block.disposition ?? block._tag
1759
- }), /* @__PURE__ */ React9.createElement(ToggleContainer2.Content, {
1760
- classNames: styles.panelContent
1761
- }, /* @__PURE__ */ React9.createElement(Json2, {
1762
- data: safeParseJson2(block.data ?? block),
1763
- classNames: styles.json
1764
- })));
1765
- }
1766
- }
1767
- },
1768
- //
1769
- // Fallback
1770
- //
1771
- default: ({ block }) => {
1772
- return /* @__PURE__ */ React9.createElement(ToggleContainer2.Root, {
1773
- classNames: styles.panel
1774
- }, /* @__PURE__ */ React9.createElement(ToggleContainer2.Header, {
1775
- classNames: styles.panelHeader,
1776
- title: block._tag
1777
- }), /* @__PURE__ */ React9.createElement(ToggleContainer2.Content, {
1778
- classNames: styles.panelContent
1779
- }, /* @__PURE__ */ React9.createElement(Json2, {
1780
- data: block,
1781
- classNames: styles.json
1782
- })));
1783
- }
1784
- };
1785
- var ChatError = ({ error, onEvent }) => {
1786
- var _effect = _useSignals11();
1787
- try {
1788
- const { t } = useTranslation6(meta.id);
1789
- return /* @__PURE__ */ React9.createElement(React9.Fragment, null, /* @__PURE__ */ React9.createElement(MessageItem, null, /* @__PURE__ */ React9.createElement(ToggleContainer2.Root, {
1790
- classNames: styles.panel
1791
- }, /* @__PURE__ */ React9.createElement(ToggleContainer2.Header, {
1792
- classNames: styles.panelHeader,
1793
- title: error.message || t("error label")
1794
- }), /* @__PURE__ */ React9.createElement(ToggleContainer2.Content, {
1795
- classNames: styles.panelContent
1796
- }, String(error.cause)))), /* @__PURE__ */ React9.createElement(MessageItem, null, /* @__PURE__ */ React9.createElement(IconButton4, {
1797
- classNames: "bg-errorSurface text-errorSurfaceText",
1798
- icon: "ph--lightning--regular",
1799
- label: t("button retry"),
1800
- onClick: () => onEvent?.({
1801
- type: "retry"
1802
- })
1803
- })));
1804
- } finally {
1805
- _effect.f();
1806
- }
1807
- };
1808
- var MessageItem = ({ classNames, children, user }) => {
1809
- var _effect = _useSignals11();
1810
- try {
1811
- if (!children) {
1812
- return null;
1813
- }
1814
- return /* @__PURE__ */ React9.createElement("div", {
1815
- role: "list-item",
1816
- className: mx5("flex is-full", user && "justify-end", styles.margin, classNames)
1817
- }, /* @__PURE__ */ React9.createElement("div", {
1818
- className: mx5(user ? [
1819
- "bg-[--user-fill] text-white dark:text-black rounded-sm",
1820
- styles.padding
1821
- ] : "is-full")
1822
- }, children));
1823
- } finally {
1824
- _effect.f();
1825
- }
1826
- };
1827
- var preprocessTextContent = (content) => content.replaceAll(new RegExp(DXN_ECHO_REGEXP, "g"), (_, dxn) => `<${dxn}>`);
1828
-
1829
- // src/components/ChatThread/reducers.ts
1830
- var reduceMessages = ({ messages, current, toolBlock, assistantMessages = [] }, message) => {
1831
- let assistant = message?.sender.role === "assistant";
1832
- let i = 0;
1833
- for (const block of message.blocks) {
1834
- switch (block._tag) {
1835
- // TODO(burdon): Preserve call tool title.
1836
- case "toolCall": {
1837
- assistant = true;
1838
- if (!toolBlock) {
1839
- current = {
1840
- ...message,
1841
- id: [
1842
- message.id,
1843
- i++
1844
- ].join("_"),
1845
- blocks: [
1846
- block
1847
- ]
1848
- };
1849
- messages.push(current);
1850
- toolBlock = true;
1851
- } else {
1852
- current.blocks.push(block);
1853
- }
1854
- break;
1855
- }
1856
- case "toolResult": {
1857
- assistant = true;
1858
- if (toolBlock) {
1859
- current.blocks.push(block);
1860
- }
1861
- break;
1862
- }
1863
- case "summary": {
1864
- assistant = true;
1865
- if (toolBlock) {
1866
- current.blocks.push(block);
1867
- } else {
1868
- const summary = reduceSummary([
1869
- ...assistantMessages,
1870
- message
1871
- ]);
1872
- current.blocks.push(summary);
1873
- }
1874
- break;
1875
- }
1876
- default: {
1877
- assistant = message.sender.role === "assistant";
1878
- current = {
1879
- ...message,
1880
- id: [
1881
- message.id,
1882
- i++
1883
- ].join("_"),
1884
- blocks: [
1885
- block
1886
- ]
1887
- };
1888
- messages.push(current);
1889
- toolBlock = false;
1890
- break;
1891
- }
1892
- }
1893
- }
1894
- return {
1895
- messages,
1896
- current,
1897
- toolBlock,
1898
- assistantMessages: assistant ? [
1899
- ...assistantMessages,
1900
- message
1901
- ] : void 0
1902
- };
1903
- };
1904
- var reduceSummary = (messages) => {
1905
- let start;
1906
- return messages.reduce((acc, msg) => {
1907
- const time = new Date(msg.created).getTime();
1908
- if (!start) {
1909
- start = time;
1910
- }
1911
- msg.blocks.forEach((block) => {
1912
- switch (block._tag) {
1913
- case "toolCall": {
1914
- acc.toolCalls = (acc.toolCalls ?? 0) + 1;
1915
- break;
1916
- }
1917
- case "summary": {
1918
- acc.model = block.model;
1919
- if (block.usage) {
1920
- acc.message = block.message;
1921
- acc.usage = {
1922
- inputTokens: (acc.usage?.inputTokens ?? 0) + (block.usage.inputTokens ?? 0),
1923
- outputTokens: (acc.usage?.outputTokens ?? 0) + (block.usage.outputTokens ?? 0),
1924
- totalTokens: (acc.usage?.totalTokens ?? 0) + (block.usage.totalTokens ?? 0)
1925
- };
1926
- acc.duration = time - (start ?? time);
1927
- }
1928
- break;
1929
- }
1930
- }
1931
- });
1932
- return acc;
1933
- }, {
1934
- _tag: "summary",
1935
- duration: 0
1936
- });
1937
- };
1938
-
1939
- // src/components/ChatThread/ChatThread.tsx
1940
- var __dxlog_file6 = "/__w/dxos/dxos/packages/plugins/plugin-assistant/src/components/ChatThread/ChatThread.tsx";
1941
- var ChatThread = /* @__PURE__ */ forwardRef(({ classNames, identity, messages = [], error, debug, onEvent, ...props }, forwardedRef) => {
1942
- var _effect = _useSignals12();
1943
- try {
1944
- const userHue = useMemo13(() => {
1945
- return identity?.profile?.data?.hue || keyToFallback(identity?.identityKey ?? PublicKey.random()).hue;
1946
- }, [
1947
- identity
1948
- ]);
1949
- useEffect6(() => {
1950
- onEvent?.({
1951
- type: "scroll-to-bottom"
1952
- });
1953
- }, [
1954
- error
1955
- ]);
1956
- const reducedMessages = useMemo13(() => {
1957
- if (!debug) {
1958
- return messages.reduce(reduceMessages, {
1959
- messages: []
1960
- }).messages;
1961
- } else {
1962
- return messages;
1963
- }
1964
- }, [
1965
- messages,
1966
- debug
1967
- ]);
1968
- const getDelta = (idx) => {
1969
- invariant2(idx > 0, void 0, {
1970
- F: __dxlog_file6,
1971
- L: 48,
1972
- S: void 0,
1973
- A: [
1974
- "idx > 0",
1975
- ""
1976
- ]
1977
- });
1978
- const prev = new Date(reducedMessages[idx - 1].created).getTime();
1979
- const current = new Date(reducedMessages[idx].created).getTime();
1980
- return current - prev;
1981
- };
1982
- return /* @__PURE__ */ React10.createElement(ScrollContainer.Root, {
1983
- pin: true,
1984
- fade: true,
1985
- ref: forwardedRef,
1986
- classNames
1987
- }, /* @__PURE__ */ React10.createElement(ScrollContainer.Content, {
1988
- classNames: "relative flex flex-col gap-2 pbs-2 pbe-2",
1989
- style: {
1990
- "--user-fill": `var(--dx-${userHue}Fill)`
1991
- }
1992
- }, reducedMessages.map((message, idx) => /* @__PURE__ */ React10.createElement(Fragment2, {
1993
- key: message.id
1994
- }, debug && /* @__PURE__ */ React10.createElement("div", {
1995
- className: mx6("flex justify-end text-subdued", styles.margin)
1996
- }, /* @__PURE__ */ React10.createElement("pre", {
1997
- className: "text-xs"
1998
- }, JSON.stringify({
1999
- created: message.created,
2000
- delta: idx > 0 ? getDelta(idx) : void 0
2001
- }))), /* @__PURE__ */ React10.createElement(ChatMessage, {
2002
- message,
2003
- debug,
2004
- onEvent,
2005
- ...props
2006
- }))), error && /* @__PURE__ */ React10.createElement(ChatError, {
2007
- error,
2008
- onEvent
2009
- })), /* @__PURE__ */ React10.createElement(ScrollContainer.ScrollDownButton, null));
2010
- } finally {
2011
- _effect.f();
2012
- }
2013
- });
2014
-
2015
- // src/components/Chat/Chat.tsx
2016
- var __dxlog_file7 = "/__w/dxos/dxos/packages/plugins/plugin-assistant/src/components/Chat/Chat.tsx";
2017
- var [ChatContextProvider, useChatContext] = createContext("Chat");
2018
- var ChatRoot = ({ classNames, children, chat, processor, onEvent, ...props }) => {
2019
- var _effect = _useSignals13();
2020
- try {
2021
- const [debug, setDebug] = useState10(false);
2022
- const space = getSpace(chat);
2023
- const queue = useQueue2(chat?.queue.dxn);
2024
- const pending = useRxValue(processor.messages);
2025
- const streaming = useRxValue(processor.streaming);
2026
- const lastPrompt = useRef3(void 0);
2027
- const messages = useMemo14(() => {
2028
- const queueMessages = queue?.objects?.filter(Obj10.instanceOf(DataType3.Message)) ?? [];
2029
- return Array2.dedupeWith([
2030
- ...queueMessages,
2031
- ...pending
2032
- ], (a, b) => a.id === b.id);
2033
- }, [
2034
- queue?.objects,
2035
- pending
2036
- ]);
2037
- const event = useMemo14(() => new Event(), []);
2038
- useEffect7(() => {
2039
- return event.on((ev) => {
2040
- switch (ev.type) {
2041
- case "toggle-debug": {
2042
- setDebug((current) => {
2043
- const debug2 = !current;
2044
- log5.info("toggle-debug", {
2045
- debug: debug2
2046
- }, {
2047
- F: __dxlog_file7,
2048
- L: 95,
2049
- S: void 0,
2050
- C: (f, a) => f(...a)
2051
- });
2052
- return debug2;
2053
- });
2054
- break;
2055
- }
2056
- case "submit": {
2057
- if (!streaming) {
2058
- lastPrompt.current = ev.text;
2059
- void processor.request({
2060
- message: ev.text
2061
- });
2062
- }
2063
- break;
2064
- }
2065
- case "retry": {
2066
- if (!streaming) {
2067
- void processor.retry();
2068
- }
2069
- break;
2070
- }
2071
- case "cancel": {
2072
- if (streaming) {
2073
- void processor.cancel();
2074
- if (lastPrompt.current) {
2075
- event.emit({
2076
- type: "update-prompt",
2077
- text: lastPrompt.current
2078
- });
2079
- }
2080
- }
2081
- break;
2082
- }
2083
- default: {
2084
- onEvent?.(ev);
2085
- }
2086
- }
2087
- });
2088
- }, [
2089
- event,
2090
- processor,
2091
- streaming,
2092
- onEvent
2093
- ]);
2094
- if (!space) {
2095
- return null;
2096
- }
2097
- return /* @__PURE__ */ React11.createElement(ChatContextProvider, {
2098
- debug,
2099
- event,
2100
- chat,
2101
- space,
2102
- processor,
2103
- messages,
2104
- ...props
2105
- }, /* @__PURE__ */ React11.createElement("div", {
2106
- role: "none",
2107
- className: mx7("flex flex-col h-full overflow-hidden", classNames)
2108
- }, children));
2109
- } finally {
2110
- _effect.f();
2111
- }
2112
- };
2113
- ChatRoot.displayName = "Chat.Root";
2114
- var ChatPrompt = ({ classNames, outline, placeholder, expandable, online, presets, preset, onPresetChange, onOnlineChange }) => {
2115
- var _effect = _useSignals13();
2116
- try {
2117
- const { t } = useTranslation7(meta.id);
2118
- const { space, event, processor } = useChatContext(ChatPrompt.displayName);
2119
- const error = useRxValue(processor.error).pipe(Option3.getOrUndefined);
2120
- const streaming = useRxValue(processor.streaming);
2121
- const streamingRef = useRef3(streaming);
2122
- const editorRef = useRef3(null);
2123
- const [active, setActive] = useState10(false);
2124
- useEffect7(() => {
2125
- return event.on((event2) => {
2126
- switch (event2.type) {
2127
- case "update-prompt":
2128
- if (!editorRef.current?.getText()?.length) {
2129
- editorRef.current?.setText(event2.text);
2130
- editorRef.current?.focus();
2131
- }
2132
- break;
2133
- case "record-start":
2134
- setActive(true);
2135
- break;
2136
- case "record-stop":
2137
- setActive(false);
2138
- break;
2139
- }
2140
- });
2141
- }, [
2142
- event
2143
- ]);
2144
- const { recording } = useVoiceInput({
2145
- active,
2146
- onUpdate: (text) => {
2147
- editorRef.current?.setText(text);
2148
- editorRef.current?.focus();
2149
- }
2150
- });
2151
- const referencesProvider = useReferencesProvider(space);
2152
- const extensions = useMemo14(() => {
2153
- return [
2154
- referencesProvider && references({
2155
- provider: referencesProvider
2156
- }),
2157
- Prec.highest(keymap.of([
2158
- {
2159
- key: "cmd-d",
2160
- preventDefault: true,
2161
- run: () => {
2162
- event.emit({
2163
- type: "toggle-debug"
2164
- });
2165
- return true;
2166
- }
2167
- },
2168
- expandable && {
2169
- key: "cmd-ArrowUp",
2170
- preventDefault: true,
2171
- run: () => {
2172
- event.emit({
2173
- type: "thread-open"
2174
- });
2175
- return true;
2176
- }
2177
- },
2178
- expandable && {
2179
- key: "cmd-ArrowDown",
2180
- preventDefault: true,
2181
- run: () => {
2182
- event.emit({
2183
- type: "thread-close"
2184
- });
2185
- return true;
2186
- }
2187
- }
2188
- ].filter(isNotFalsy3)))
2189
- ].filter(isNotFalsy3);
2190
- }, [
2191
- event,
2192
- expandable,
2193
- referencesProvider
2194
- ]);
2195
- const handleSubmit = useCallback5((text) => {
2196
- if (!streamingRef.current) {
2197
- event.emit({
2198
- type: "submit",
2199
- text
2200
- });
2201
- return true;
2202
- }
2203
- }, [
2204
- event
2205
- ]);
2206
- const handleEvent = useCallback5((ev) => {
2207
- event.emit(ev);
2208
- }, [
2209
- event
2210
- ]);
2211
- return /* @__PURE__ */ React11.createElement("div", {
2212
- className: mx7("is-full flex flex-col density-fine", outline && [
2213
- "p-2 bg-groupSurface border border-subduedSeparator transition transition-border [&:has(.cm-content:focus)]:border-separator rounded"
2214
- ], classNames)
2215
- }, /* @__PURE__ */ React11.createElement("div", {
2216
- className: "flex gap-2"
2217
- }, /* @__PURE__ */ React11.createElement(ChatStatusIndicator, {
2218
- classNames: "p-1",
2219
- preset,
2220
- error,
2221
- processing: streaming
2222
- }), /* @__PURE__ */ React11.createElement(ChatEditor, {
2223
- ref: editorRef,
2224
- autoFocus: true,
2225
- lineWrapping: true,
2226
- classNames: "col-span-2 pbs-0.5",
2227
- placeholder: placeholder ?? t("prompt placeholder"),
2228
- extensions,
2229
- onSubmit: handleSubmit
2230
- })), /* @__PURE__ */ React11.createElement("div", {
2231
- className: "flex pbs-2 items-center"
2232
- }, /* @__PURE__ */ React11.createElement(ChatOptions, {
2233
- space,
2234
- blueprintRegistry: processor.blueprintRegistry,
2235
- context: processor.context,
2236
- preset,
2237
- presets,
2238
- onPresetChange
2239
- }), /* @__PURE__ */ React11.createElement("div", {
2240
- role: "none",
2241
- className: "pli-cardSpacingChrome grow"
2242
- }, /* @__PURE__ */ React11.createElement(ChatReferences, {
2243
- space,
2244
- context: processor.context
2245
- })), /* @__PURE__ */ React11.createElement(ChatActions, {
2246
- classNames: "col-span-2",
2247
- microphone: true,
2248
- recording,
2249
- processing: streaming,
2250
- onEvent: handleEvent
2251
- }, online !== void 0 && /* @__PURE__ */ React11.createElement(Input.Root, null, /* @__PURE__ */ React11.createElement(Input.Switch, {
2252
- classNames: "mis-2 mie-2",
2253
- checked: online,
2254
- onCheckedChange: onOnlineChange
2255
- })))));
2256
- } finally {
2257
- _effect.f();
2258
- }
2259
- };
2260
- ChatPrompt.displayName = "Chat.Prompt";
2261
- var ChatThread2 = (props) => {
2262
- var _effect = _useSignals13();
2263
- try {
2264
- const { debug, event, space, messages, processor } = useChatContext(ChatThread2.displayName);
2265
- const identity = useIdentity();
2266
- const error = useRxValue(processor.error).pipe(Option3.getOrUndefined);
2267
- const toolProvider = useCallback5(() => processor.conversation.toolkit?.tools ?? [], [
2268
- processor
2269
- ]);
2270
- const scrollerRef = useRef3(null);
2271
- useEffect7(() => {
2272
- return event.on((event2) => {
2273
- switch (event2.type) {
2274
- case "submit":
2275
- case "scroll-to-bottom":
2276
- scrollerRef.current?.scrollToBottom("smooth");
2277
- break;
2278
- }
2279
- });
2280
- }, [
2281
- event
2282
- ]);
2283
- if (!identity) {
2284
- return null;
2285
- }
2286
- return /* @__PURE__ */ React11.createElement(ChatThread, {
2287
- ...props,
2288
- ref: scrollerRef,
2289
- debug,
2290
- identity,
2291
- space,
2292
- messages,
2293
- error,
2294
- toolProvider,
2295
- onEvent: (ev) => event.emit(ev)
2296
- });
2297
- } finally {
2298
- _effect.f();
2299
- }
2300
- };
2301
- ChatThread2.displayName = "Chat.Thread";
2302
- var Chat = {
2303
- Root: ChatRoot,
2304
- Prompt: ChatPrompt,
2305
- Thread: ChatThread2
2306
- };
2307
-
2308
- export {
2309
- useBlueprintRegistry,
2310
- useChatProcessor,
2311
- useChatServices,
2312
- useContextBinder,
2313
- useExecutionGraph,
2314
- useOnline,
2315
- usePresets,
2316
- Toolbox,
2317
- ToolboxContainer,
2318
- ChatContextProvider,
2319
- useChatContext,
2320
- Chat,
2321
- AiService2 as AiService,
2322
- AppGraphBuilder,
2323
- AssistantState,
2324
- BlueprintDefinition,
2325
- EdgeModelResolver,
2326
- IntentResolver,
2327
- LocalModelResolver,
2328
- ReactSurface,
2329
- Settings,
2330
- Toolkit
2331
- };
2332
- //# sourceMappingURL=chunk-XL557TXF.mjs.map