@dxos/plugin-assistant 0.8.4-main.c1de068 → 0.8.4-main.dedc0f3

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