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