@dxos/plugin-assistant 0.8.3-staging.0fa589b → 0.8.4-main.c1de068

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 (430) hide show
  1. package/dist/lib/browser/ChatContainer-M3IHQLRS.mjs +54 -0
  2. package/dist/lib/browser/ChatContainer-M3IHQLRS.mjs.map +7 -0
  3. package/dist/lib/browser/ChatDialog-X6VN6QZI.mjs +72 -0
  4. package/dist/lib/browser/ChatDialog-X6VN6QZI.mjs.map +7 -0
  5. package/dist/lib/browser/SequenceContainer-3UDVKWPA.mjs +162 -0
  6. package/dist/lib/browser/SequenceContainer-3UDVKWPA.mjs.map +7 -0
  7. package/dist/lib/browser/{TemplateContainer-QQHVOTSI.mjs → TemplateContainer-RPJ2LBOB.mjs} +5 -6
  8. package/dist/lib/browser/TemplateContainer-RPJ2LBOB.mjs.map +7 -0
  9. package/dist/lib/browser/{app-graph-builder-E4H5DCOJ.mjs → app-graph-builder-JTXBKE7O.mjs} +34 -36
  10. package/dist/lib/browser/app-graph-builder-JTXBKE7O.mjs.map +7 -0
  11. package/dist/lib/browser/chunk-AEAEKWOC.mjs +98 -0
  12. package/dist/lib/browser/chunk-AEAEKWOC.mjs.map +7 -0
  13. package/dist/lib/browser/{chunk-BI6AHRNJ.mjs → chunk-EQDW6BYQ.mjs} +19 -68
  14. package/dist/lib/browser/chunk-EQDW6BYQ.mjs.map +7 -0
  15. package/dist/lib/{node/chunk-P74TWGMG.cjs → browser/chunk-FDCJSQYF.mjs} +10 -14
  16. package/dist/lib/{node-esm/chunk-BB2TAT4P.mjs.map → browser/chunk-FDCJSQYF.mjs.map} +1 -1
  17. package/dist/lib/browser/chunk-JQBVLTM5.mjs +158 -0
  18. package/dist/lib/browser/chunk-JQBVLTM5.mjs.map +7 -0
  19. package/dist/lib/browser/chunk-OWY4CUQY.mjs +2245 -0
  20. package/dist/lib/browser/chunk-OWY4CUQY.mjs.map +7 -0
  21. package/dist/lib/browser/index.mjs +87 -119
  22. package/dist/lib/browser/index.mjs.map +4 -4
  23. package/dist/lib/browser/intent-resolver-5RMMCMXG.mjs +60 -0
  24. package/dist/lib/browser/intent-resolver-5RMMCMXG.mjs.map +7 -0
  25. package/dist/lib/browser/meta.json +1 -1
  26. package/dist/lib/browser/{react-surface-LXCNUSZN.mjs → react-surface-66VY37YQ.mjs} +42 -51
  27. package/dist/lib/browser/react-surface-66VY37YQ.mjs.map +7 -0
  28. package/dist/lib/browser/{settings-XRHXVWGB.mjs → settings-2DGP3UTS.mjs} +6 -6
  29. package/dist/lib/browser/settings-2DGP3UTS.mjs.map +7 -0
  30. package/dist/lib/browser/types/index.mjs +4 -20
  31. package/dist/lib/node-esm/ChatContainer-VZT74PO2.mjs +55 -0
  32. package/dist/lib/node-esm/ChatContainer-VZT74PO2.mjs.map +7 -0
  33. package/dist/lib/node-esm/ChatDialog-RJ6FDX4Q.mjs +73 -0
  34. package/dist/lib/node-esm/ChatDialog-RJ6FDX4Q.mjs.map +7 -0
  35. package/dist/lib/node-esm/SequenceContainer-RQQH5XOC.mjs +163 -0
  36. package/dist/lib/node-esm/SequenceContainer-RQQH5XOC.mjs.map +7 -0
  37. package/dist/lib/node-esm/{TemplateContainer-SOEWY2ZN.mjs → TemplateContainer-A3NAQCZE.mjs} +5 -6
  38. package/dist/lib/node-esm/TemplateContainer-A3NAQCZE.mjs.map +7 -0
  39. package/dist/lib/node-esm/{app-graph-builder-3SY5MBIK.mjs → app-graph-builder-OWSOXFTD.mjs} +34 -36
  40. package/dist/lib/node-esm/app-graph-builder-OWSOXFTD.mjs.map +7 -0
  41. package/dist/lib/node-esm/{chunk-OYN6HLXZ.mjs → chunk-2XL6MNPE.mjs} +44 -33
  42. package/dist/lib/node-esm/chunk-2XL6MNPE.mjs.map +7 -0
  43. package/dist/lib/node-esm/chunk-BISJDTBK.mjs +159 -0
  44. package/dist/lib/node-esm/chunk-BISJDTBK.mjs.map +7 -0
  45. package/dist/lib/node-esm/{chunk-UCOFKNKN.mjs → chunk-E33DNNDW.mjs} +19 -68
  46. package/dist/lib/node-esm/chunk-E33DNNDW.mjs.map +7 -0
  47. package/dist/lib/node-esm/chunk-QN2H2EHV.mjs +41 -0
  48. package/dist/lib/{browser/chunk-XOZ7YMO3.mjs.map → node-esm/chunk-QN2H2EHV.mjs.map} +1 -1
  49. package/dist/lib/node-esm/chunk-SENTQAEO.mjs +2246 -0
  50. package/dist/lib/node-esm/chunk-SENTQAEO.mjs.map +7 -0
  51. package/dist/lib/node-esm/index.mjs +87 -119
  52. package/dist/lib/node-esm/index.mjs.map +4 -4
  53. package/dist/lib/node-esm/intent-resolver-YPPYELY3.mjs +61 -0
  54. package/dist/lib/node-esm/intent-resolver-YPPYELY3.mjs.map +7 -0
  55. package/dist/lib/node-esm/meta.json +1 -1
  56. package/dist/lib/node-esm/{react-surface-7HA5EDWY.mjs → react-surface-RJMRBR2M.mjs} +42 -51
  57. package/dist/lib/node-esm/react-surface-RJMRBR2M.mjs.map +7 -0
  58. package/dist/lib/node-esm/{settings-5IAY6BT4.mjs → settings-47RYZOU4.mjs} +6 -6
  59. package/dist/lib/node-esm/settings-47RYZOU4.mjs.map +7 -0
  60. package/dist/lib/node-esm/types/index.mjs +4 -20
  61. package/dist/types/src/AssistantPlugin.d.ts.map +1 -1
  62. package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -1
  63. package/dist/types/src/capabilities/index.d.ts +1 -3
  64. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  65. package/dist/types/src/capabilities/intent-resolver.d.ts +2 -2
  66. package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -1
  67. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
  68. package/dist/types/src/components/AssistantSettings/AssistantSettings.d.ts +2 -2
  69. package/dist/types/src/components/AssistantSettings/AssistantSettings.d.ts.map +1 -1
  70. package/dist/types/src/components/Chat/Chat.d.ts +47 -0
  71. package/dist/types/src/components/Chat/Chat.d.ts.map +1 -0
  72. package/dist/types/src/components/Chat/events.d.ts +30 -0
  73. package/dist/types/src/components/Chat/events.d.ts.map +1 -0
  74. package/dist/types/src/components/Chat/index.d.ts +3 -0
  75. package/dist/types/src/components/Chat/index.d.ts.map +1 -0
  76. package/dist/types/src/components/ChatContainer.d.ts +6 -6
  77. package/dist/types/src/components/ChatContainer.d.ts.map +1 -1
  78. package/dist/types/src/components/ChatDialog.d.ts +8 -0
  79. package/dist/types/src/components/ChatDialog.d.ts.map +1 -0
  80. package/dist/types/src/components/ChatPrompt/ChatActions.d.ts +11 -0
  81. package/dist/types/src/components/ChatPrompt/ChatActions.d.ts.map +1 -0
  82. package/dist/types/src/components/ChatPrompt/ChatOptionsMenu.d.ts +9 -0
  83. package/dist/types/src/components/ChatPrompt/ChatOptionsMenu.d.ts.map +1 -0
  84. package/dist/types/src/components/ChatPrompt/ChatPresets.d.ts +11 -0
  85. package/dist/types/src/components/ChatPrompt/ChatPresets.d.ts.map +1 -0
  86. package/dist/types/src/components/ChatPrompt/ChatReferences.d.ts +11 -0
  87. package/dist/types/src/components/ChatPrompt/ChatReferences.d.ts.map +1 -0
  88. package/dist/types/src/components/ChatPrompt/ChatStatusIndicator.d.ts +8 -0
  89. package/dist/types/src/components/ChatPrompt/ChatStatusIndicator.d.ts.map +1 -0
  90. package/dist/types/src/components/ChatPrompt/index.d.ts +6 -0
  91. package/dist/types/src/components/ChatPrompt/index.d.ts.map +1 -0
  92. package/dist/types/src/components/ChatThread/ChatMessage.d.ts +17 -0
  93. package/dist/types/src/components/ChatThread/ChatMessage.d.ts.map +1 -0
  94. package/dist/types/src/components/ChatThread/ChatThread.d.ts +19 -0
  95. package/dist/types/src/components/ChatThread/ChatThread.d.ts.map +1 -0
  96. package/dist/types/src/components/ChatThread/ChatThread.stories.d.ts +241 -0
  97. package/dist/types/src/components/ChatThread/ChatThread.stories.d.ts.map +1 -0
  98. package/dist/types/src/components/ChatThread/ToolBlock.d.ts +19 -0
  99. package/dist/types/src/components/ChatThread/ToolBlock.d.ts.map +1 -0
  100. package/dist/types/src/components/ChatThread/index.d.ts +2 -0
  101. package/dist/types/src/components/ChatThread/index.d.ts.map +1 -0
  102. package/dist/types/src/components/{Thread → ChatThread}/reducer.d.ts +4 -4
  103. package/dist/types/src/components/ChatThread/reducer.d.ts.map +1 -0
  104. package/dist/types/src/components/PromptSettings.d.ts +2 -2
  105. package/dist/types/src/components/PromptSettings.d.ts.map +1 -1
  106. package/dist/types/src/components/SequenceContainer.d.ts +8 -0
  107. package/dist/types/src/components/SequenceContainer.d.ts.map +1 -0
  108. package/dist/types/src/components/SequenceEditor/SequenceEditor.d.ts +13 -0
  109. package/dist/types/src/components/SequenceEditor/SequenceEditor.d.ts.map +1 -0
  110. package/dist/types/src/components/SequenceEditor/SequenceEditor.stories.d.ts +8 -0
  111. package/dist/types/src/components/SequenceEditor/SequenceEditor.stories.d.ts.map +1 -0
  112. package/dist/types/src/components/SequenceEditor/index.d.ts +2 -0
  113. package/dist/types/src/components/SequenceEditor/index.d.ts.map +1 -0
  114. package/dist/types/src/components/TemplateContainer.d.ts +5 -5
  115. package/dist/types/src/components/TemplateContainer.d.ts.map +1 -1
  116. package/dist/types/src/components/TemplateEditor/TemplateEditor.d.ts +2 -2
  117. package/dist/types/src/components/TemplateEditor/TemplateEditor.d.ts.map +1 -1
  118. package/dist/types/src/components/TemplateEditor/TemplateEditor.stories.d.ts +3 -3
  119. package/dist/types/src/components/TemplateEditor/TemplateEditor.stories.d.ts.map +1 -1
  120. package/dist/types/src/components/TemplateEditor/TemplateForm.d.ts +3 -3
  121. package/dist/types/src/components/TemplateEditor/TemplateForm.d.ts.map +1 -1
  122. package/dist/types/src/components/TemplateEditor/TemplateForm.stories.d.ts +1 -1
  123. package/dist/types/src/components/TemplateEditor/TemplateForm.stories.d.ts.map +1 -1
  124. package/dist/types/src/components/Toolbox/Toolbox.d.ts +11 -4
  125. package/dist/types/src/components/Toolbox/Toolbox.d.ts.map +1 -1
  126. package/dist/types/src/components/Toolbox/Toolbox.stories.d.ts +1 -1
  127. package/dist/types/src/components/Toolbox/Toolbox.stories.d.ts.map +1 -1
  128. package/dist/types/src/components/index.d.ts +6 -12
  129. package/dist/types/src/components/index.d.ts.map +1 -1
  130. package/dist/types/src/events.d.ts.map +1 -1
  131. package/dist/types/src/hooks/{processor.d.ts → chat-processor.d.ts} +36 -22
  132. package/dist/types/src/hooks/chat-processor.d.ts.map +1 -0
  133. package/dist/types/src/hooks/chat-processor.test.d.ts +2 -0
  134. package/dist/types/src/hooks/chat-processor.test.d.ts.map +1 -0
  135. package/dist/types/src/hooks/index.d.ts +5 -5
  136. package/dist/types/src/hooks/index.d.ts.map +1 -1
  137. package/dist/types/src/hooks/presets.d.ts +13 -0
  138. package/dist/types/src/hooks/presets.d.ts.map +1 -0
  139. package/dist/types/src/hooks/useBlueprints.d.ts +9 -0
  140. package/dist/types/src/hooks/useBlueprints.d.ts.map +1 -0
  141. package/dist/types/src/hooks/useChatProcessor.d.ts +20 -8
  142. package/dist/types/src/hooks/useChatProcessor.d.ts.map +1 -1
  143. package/dist/types/src/hooks/useChatServices.d.ts +14 -0
  144. package/dist/types/src/hooks/useChatServices.d.ts.map +1 -0
  145. package/dist/types/src/hooks/useReferencesProvider.d.ts +7 -0
  146. package/dist/types/src/hooks/useReferencesProvider.d.ts.map +1 -0
  147. package/dist/types/src/parser/index.d.ts +1 -1
  148. package/dist/types/src/parser/index.d.ts.map +1 -1
  149. package/dist/types/src/queue-logger.d.ts +5 -5
  150. package/dist/types/src/queue-logger.d.ts.map +1 -1
  151. package/dist/types/src/stories/Chat.stories.d.ts +249 -0
  152. package/dist/types/src/stories/Chat.stories.d.ts.map +1 -0
  153. package/dist/types/src/testing/index.d.ts +1 -1
  154. package/dist/types/src/testing/index.d.ts.map +1 -1
  155. package/dist/types/src/testing/test-sequence.d.ts +8 -0
  156. package/dist/types/src/testing/test-sequence.d.ts.map +1 -0
  157. package/dist/types/src/translations.d.ts +77 -113
  158. package/dist/types/src/translations.d.ts.map +1 -1
  159. package/dist/types/src/types/index.d.ts +1 -3
  160. package/dist/types/src/types/index.d.ts.map +1 -1
  161. package/dist/types/src/types/schema.d.ts +88 -0
  162. package/dist/types/src/types/schema.d.ts.map +1 -0
  163. package/dist/types/src/types/service.d.ts +9 -9
  164. package/dist/types/src/types/service.d.ts.map +1 -1
  165. package/dist/types/tsconfig.tsbuildinfo +1 -1
  166. package/package.json +80 -74
  167. package/src/AssistantPlugin.tsx +20 -47
  168. package/src/capabilities/app-graph-builder.ts +35 -30
  169. package/src/capabilities/index.ts +0 -3
  170. package/src/capabilities/intent-resolver.ts +27 -14
  171. package/src/capabilities/react-surface.tsx +38 -37
  172. package/src/capabilities/settings.ts +3 -3
  173. package/src/components/AssistantSettings/AssistantSettings.tsx +4 -4
  174. package/src/components/Chat/Chat.tsx +388 -0
  175. package/src/components/Chat/events.ts +50 -0
  176. package/src/components/Chat/index.ts +7 -0
  177. package/src/components/ChatContainer.tsx +26 -20
  178. package/src/components/ChatDialog.tsx +64 -0
  179. package/src/components/ChatPrompt/ChatActions.tsx +71 -0
  180. package/src/components/ChatPrompt/ChatOptionsMenu.tsx +52 -0
  181. package/src/components/ChatPrompt/ChatPresets.tsx +28 -0
  182. package/src/components/ChatPrompt/ChatReferences.tsx +53 -0
  183. package/src/components/ChatPrompt/ChatStatusIndicator.tsx +39 -0
  184. package/src/components/ChatPrompt/index.ts +9 -0
  185. package/src/components/ChatThread/ChatMessage.tsx +268 -0
  186. package/src/components/ChatThread/ChatThread.stories.tsx +143 -0
  187. package/src/components/ChatThread/ChatThread.tsx +57 -0
  188. package/src/components/{Thread/ToolInvocations.tsx → ChatThread/ToolBlock.tsx} +36 -21
  189. package/src/{experimental/transcription → components/ChatThread}/index.ts +2 -0
  190. package/src/components/{Thread → ChatThread}/reducer.ts +14 -14
  191. package/src/components/PromptSettings.tsx +43 -45
  192. package/src/components/SequenceContainer.tsx +132 -0
  193. package/src/components/SequenceEditor/SequenceEditor.stories.tsx +32 -0
  194. package/src/components/{BlueprintEditor/BlueprintEditor.tsx → SequenceEditor/SequenceEditor.tsx} +7 -7
  195. package/src/components/{AmbientDialog → SequenceEditor}/index.ts +1 -1
  196. package/src/components/TemplateContainer.tsx +8 -7
  197. package/src/components/TemplateEditor/TemplateEditor.stories.tsx +28 -33
  198. package/src/components/TemplateEditor/TemplateEditor.tsx +32 -19
  199. package/src/components/TemplateEditor/TemplateForm.stories.tsx +15 -15
  200. package/src/components/TemplateEditor/TemplateForm.tsx +47 -55
  201. package/src/components/Toolbox/Toolbox.stories.tsx +5 -6
  202. package/src/components/Toolbox/Toolbox.tsx +60 -4
  203. package/src/components/index.ts +4 -5
  204. package/src/events.ts +2 -2
  205. package/src/hooks/{processor.test.ts → chat-processor.test.ts} +3 -2
  206. package/src/hooks/chat-processor.ts +314 -0
  207. package/src/hooks/index.ts +5 -5
  208. package/src/hooks/presets.ts +52 -0
  209. package/src/hooks/useBlueprints.ts +57 -0
  210. package/src/hooks/useChatProcessor.ts +143 -0
  211. package/src/hooks/useChatServices.ts +91 -0
  212. package/src/hooks/{useContextProvider.ts → useReferencesProvider.ts} +14 -14
  213. package/src/parser/index.ts +1 -1
  214. package/src/queue-logger.ts +6 -6
  215. package/src/stories/Chat.stories.tsx +378 -0
  216. package/src/testing/index.ts +1 -1
  217. package/src/testing/test-functions.ts +1 -1
  218. package/src/testing/test-sequence.ts +51 -0
  219. package/src/tools/openapi.test.ts +11 -11
  220. package/src/translations.ts +43 -23
  221. package/src/types/index.ts +1 -3
  222. package/src/types/schema.ts +95 -0
  223. package/dist/lib/browser/AssistantDialog-MQOOR364.mjs +0 -47
  224. package/dist/lib/browser/AssistantDialog-MQOOR364.mjs.map +0 -7
  225. package/dist/lib/browser/BlueprintContainer-AT5Y7EXG.mjs +0 -321
  226. package/dist/lib/browser/BlueprintContainer-AT5Y7EXG.mjs.map +0 -7
  227. package/dist/lib/browser/ChatContainer-C2NEAS3A.mjs +0 -40
  228. package/dist/lib/browser/ChatContainer-C2NEAS3A.mjs.map +0 -7
  229. package/dist/lib/browser/TemplateContainer-QQHVOTSI.mjs.map +0 -7
  230. package/dist/lib/browser/ai-client-MK2ZZII2.mjs +0 -39
  231. package/dist/lib/browser/ai-client-MK2ZZII2.mjs.map +0 -7
  232. package/dist/lib/browser/app-graph-builder-E4H5DCOJ.mjs.map +0 -7
  233. package/dist/lib/browser/chunk-AAOKC2JN.mjs +0 -208
  234. package/dist/lib/browser/chunk-AAOKC2JN.mjs.map +0 -7
  235. package/dist/lib/browser/chunk-BI6AHRNJ.mjs.map +0 -7
  236. package/dist/lib/browser/chunk-JO4W3MF7.mjs +0 -2101
  237. package/dist/lib/browser/chunk-JO4W3MF7.mjs.map +0 -7
  238. package/dist/lib/browser/chunk-JQFUME3B.mjs +0 -87
  239. package/dist/lib/browser/chunk-JQFUME3B.mjs.map +0 -7
  240. package/dist/lib/browser/chunk-MEGMOFJB.mjs +0 -16
  241. package/dist/lib/browser/chunk-MEGMOFJB.mjs.map +0 -7
  242. package/dist/lib/browser/chunk-Q6UZ4F3H.mjs +0 -96
  243. package/dist/lib/browser/chunk-Q6UZ4F3H.mjs.map +0 -7
  244. package/dist/lib/browser/chunk-UE3IZ4PN.mjs +0 -15
  245. package/dist/lib/browser/chunk-UE3IZ4PN.mjs.map +0 -7
  246. package/dist/lib/browser/chunk-XOZ7YMO3.mjs +0 -20
  247. package/dist/lib/browser/intent-resolver-3UICTGPM.mjs +0 -43
  248. package/dist/lib/browser/intent-resolver-3UICTGPM.mjs.map +0 -7
  249. package/dist/lib/browser/react-surface-LXCNUSZN.mjs.map +0 -7
  250. package/dist/lib/browser/settings-XRHXVWGB.mjs.map +0 -7
  251. package/dist/lib/node/AssistantDialog-AN4Z6YUV.cjs +0 -73
  252. package/dist/lib/node/AssistantDialog-AN4Z6YUV.cjs.map +0 -7
  253. package/dist/lib/node/BlueprintContainer-NOWLDYCZ.cjs +0 -344
  254. package/dist/lib/node/BlueprintContainer-NOWLDYCZ.cjs.map +0 -7
  255. package/dist/lib/node/ChatContainer-VKYBQHUB.cjs +0 -68
  256. package/dist/lib/node/ChatContainer-VKYBQHUB.cjs.map +0 -7
  257. package/dist/lib/node/TemplateContainer-JZF2DCCG.cjs +0 -58
  258. package/dist/lib/node/TemplateContainer-JZF2DCCG.cjs.map +0 -7
  259. package/dist/lib/node/ai-client-7HNSMUMT.cjs +0 -53
  260. package/dist/lib/node/ai-client-7HNSMUMT.cjs.map +0 -7
  261. package/dist/lib/node/app-graph-builder-PPR5B5KU.cjs +0 -235
  262. package/dist/lib/node/app-graph-builder-PPR5B5KU.cjs.map +0 -7
  263. package/dist/lib/node/chunk-4EEWTDQK.cjs +0 -117
  264. package/dist/lib/node/chunk-4EEWTDQK.cjs.map +0 -7
  265. package/dist/lib/node/chunk-FUAGEO7Q.cjs +0 -52
  266. package/dist/lib/node/chunk-FUAGEO7Q.cjs.map +0 -7
  267. package/dist/lib/node/chunk-HRNIUYVQ.cjs +0 -128
  268. package/dist/lib/node/chunk-HRNIUYVQ.cjs.map +0 -7
  269. package/dist/lib/node/chunk-IKZBMHSW.cjs +0 -184
  270. package/dist/lib/node/chunk-IKZBMHSW.cjs.map +0 -7
  271. package/dist/lib/node/chunk-LMDJEGZ2.cjs +0 -233
  272. package/dist/lib/node/chunk-LMDJEGZ2.cjs.map +0 -7
  273. package/dist/lib/node/chunk-NIDICM57.cjs +0 -2080
  274. package/dist/lib/node/chunk-NIDICM57.cjs.map +0 -7
  275. package/dist/lib/node/chunk-P74TWGMG.cjs.map +0 -7
  276. package/dist/lib/node/chunk-QGPWY6GW.cjs +0 -34
  277. package/dist/lib/node/chunk-QGPWY6GW.cjs.map +0 -7
  278. package/dist/lib/node/index.cjs +0 -289
  279. package/dist/lib/node/index.cjs.map +0 -7
  280. package/dist/lib/node/intent-resolver-QSWGTKON.cjs +0 -58
  281. package/dist/lib/node/intent-resolver-QSWGTKON.cjs.map +0 -7
  282. package/dist/lib/node/meta.json +0 -1
  283. package/dist/lib/node/react-surface-D3NBYRZ6.cjs +0 -172
  284. package/dist/lib/node/react-surface-D3NBYRZ6.cjs.map +0 -7
  285. package/dist/lib/node/settings-2JXLKYGE.cjs +0 -36
  286. package/dist/lib/node/settings-2JXLKYGE.cjs.map +0 -7
  287. package/dist/lib/node/types/index.cjs +0 -54
  288. package/dist/lib/node/types/index.cjs.map +0 -7
  289. package/dist/lib/node-esm/AssistantDialog-6WEMLUPU.mjs +0 -48
  290. package/dist/lib/node-esm/AssistantDialog-6WEMLUPU.mjs.map +0 -7
  291. package/dist/lib/node-esm/BlueprintContainer-STOJAVML.mjs +0 -322
  292. package/dist/lib/node-esm/BlueprintContainer-STOJAVML.mjs.map +0 -7
  293. package/dist/lib/node-esm/ChatContainer-3MVBTUJN.mjs +0 -41
  294. package/dist/lib/node-esm/ChatContainer-3MVBTUJN.mjs.map +0 -7
  295. package/dist/lib/node-esm/TemplateContainer-SOEWY2ZN.mjs.map +0 -7
  296. package/dist/lib/node-esm/ai-client-XGZBJ6BE.mjs +0 -40
  297. package/dist/lib/node-esm/ai-client-XGZBJ6BE.mjs.map +0 -7
  298. package/dist/lib/node-esm/app-graph-builder-3SY5MBIK.mjs.map +0 -7
  299. package/dist/lib/node-esm/chunk-34EX6E5Q.mjs +0 -18
  300. package/dist/lib/node-esm/chunk-34EX6E5Q.mjs.map +0 -7
  301. package/dist/lib/node-esm/chunk-3UEZLJ2V.mjs +0 -16
  302. package/dist/lib/node-esm/chunk-3UEZLJ2V.mjs.map +0 -7
  303. package/dist/lib/node-esm/chunk-BB2TAT4P.mjs +0 -22
  304. package/dist/lib/node-esm/chunk-CDAILLCU.mjs +0 -98
  305. package/dist/lib/node-esm/chunk-CDAILLCU.mjs.map +0 -7
  306. package/dist/lib/node-esm/chunk-J6UXXZGJ.mjs +0 -209
  307. package/dist/lib/node-esm/chunk-J6UXXZGJ.mjs.map +0 -7
  308. package/dist/lib/node-esm/chunk-OD574YIU.mjs +0 -2102
  309. package/dist/lib/node-esm/chunk-OD574YIU.mjs.map +0 -7
  310. package/dist/lib/node-esm/chunk-OYN6HLXZ.mjs.map +0 -7
  311. package/dist/lib/node-esm/chunk-UCOFKNKN.mjs.map +0 -7
  312. package/dist/lib/node-esm/intent-resolver-E6MXTYAU.mjs +0 -44
  313. package/dist/lib/node-esm/intent-resolver-E6MXTYAU.mjs.map +0 -7
  314. package/dist/lib/node-esm/react-surface-7HA5EDWY.mjs.map +0 -7
  315. package/dist/lib/node-esm/settings-5IAY6BT4.mjs.map +0 -7
  316. package/dist/types/src/capabilities/ai-client.d.ts +0 -5
  317. package/dist/types/src/capabilities/ai-client.d.ts.map +0 -1
  318. package/dist/types/src/capabilities/capabilities.d.ts +0 -6
  319. package/dist/types/src/capabilities/capabilities.d.ts.map +0 -1
  320. package/dist/types/src/components/AmbientDialog/AmbientDialog.d.ts +0 -10
  321. package/dist/types/src/components/AmbientDialog/AmbientDialog.d.ts.map +0 -1
  322. package/dist/types/src/components/AmbientDialog/AmbientDialog.stories.d.ts +0 -8
  323. package/dist/types/src/components/AmbientDialog/AmbientDialog.stories.d.ts.map +0 -1
  324. package/dist/types/src/components/AmbientDialog/index.d.ts +0 -2
  325. package/dist/types/src/components/AmbientDialog/index.d.ts.map +0 -1
  326. package/dist/types/src/components/AssistantDialog.d.ts +0 -7
  327. package/dist/types/src/components/AssistantDialog.d.ts.map +0 -1
  328. package/dist/types/src/components/BlueprintContainer.d.ts +0 -9
  329. package/dist/types/src/components/BlueprintContainer.d.ts.map +0 -1
  330. package/dist/types/src/components/BlueprintEditor/BlueprintEditor.d.ts +0 -13
  331. package/dist/types/src/components/BlueprintEditor/BlueprintEditor.d.ts.map +0 -1
  332. package/dist/types/src/components/BlueprintEditor/BlueprintEditor.stories.d.ts +0 -8
  333. package/dist/types/src/components/BlueprintEditor/BlueprintEditor.stories.d.ts.map +0 -1
  334. package/dist/types/src/components/BlueprintEditor/index.d.ts +0 -2
  335. package/dist/types/src/components/BlueprintEditor/index.d.ts.map +0 -1
  336. package/dist/types/src/components/Prompt/Prompt.d.ts +0 -23
  337. package/dist/types/src/components/Prompt/Prompt.d.ts.map +0 -1
  338. package/dist/types/src/components/Prompt/Prompt.stories.d.ts +0 -13
  339. package/dist/types/src/components/Prompt/Prompt.stories.d.ts.map +0 -1
  340. package/dist/types/src/components/Prompt/PromptBar.d.ts +0 -16
  341. package/dist/types/src/components/Prompt/PromptBar.d.ts.map +0 -1
  342. package/dist/types/src/components/Prompt/PromptBar.stories.d.ts +0 -9
  343. package/dist/types/src/components/Prompt/PromptBar.stories.d.ts.map +0 -1
  344. package/dist/types/src/components/Prompt/autocomplete.d.ts +0 -25
  345. package/dist/types/src/components/Prompt/autocomplete.d.ts.map +0 -1
  346. package/dist/types/src/components/Prompt/index.d.ts +0 -3
  347. package/dist/types/src/components/Prompt/index.d.ts.map +0 -1
  348. package/dist/types/src/components/Prompt/references.d.ts +0 -30
  349. package/dist/types/src/components/Prompt/references.d.ts.map +0 -1
  350. package/dist/types/src/components/Thread/Thread.d.ts +0 -28
  351. package/dist/types/src/components/Thread/Thread.d.ts.map +0 -1
  352. package/dist/types/src/components/Thread/Thread.stories.d.ts +0 -11
  353. package/dist/types/src/components/Thread/Thread.stories.d.ts.map +0 -1
  354. package/dist/types/src/components/Thread/ThreadContainer.d.ts +0 -13
  355. package/dist/types/src/components/Thread/ThreadContainer.d.ts.map +0 -1
  356. package/dist/types/src/components/Thread/ThreadContainer.stories.d.ts +0 -16
  357. package/dist/types/src/components/Thread/ThreadContainer.stories.d.ts.map +0 -1
  358. package/dist/types/src/components/Thread/ThreadMessage.d.ts +0 -16
  359. package/dist/types/src/components/Thread/ThreadMessage.d.ts.map +0 -1
  360. package/dist/types/src/components/Thread/ToolInvocations.d.ts +0 -13
  361. package/dist/types/src/components/Thread/ToolInvocations.d.ts.map +0 -1
  362. package/dist/types/src/components/Thread/index.d.ts +0 -3
  363. package/dist/types/src/components/Thread/index.d.ts.map +0 -1
  364. package/dist/types/src/components/Thread/reducer.d.ts.map +0 -1
  365. package/dist/types/src/experimental/transcription/index.d.ts +0 -1
  366. package/dist/types/src/experimental/transcription/index.d.ts.map +0 -1
  367. package/dist/types/src/hooks/processor.d.ts.map +0 -1
  368. package/dist/types/src/hooks/processor.test.d.ts +0 -2
  369. package/dist/types/src/hooks/processor.test.d.ts.map +0 -1
  370. package/dist/types/src/hooks/useContextProvider.d.ts +0 -17
  371. package/dist/types/src/hooks/useContextProvider.d.ts.map +0 -1
  372. package/dist/types/src/hooks/useMessageQueue.d.ts +0 -42
  373. package/dist/types/src/hooks/useMessageQueue.d.ts.map +0 -1
  374. package/dist/types/src/hooks/useServices.d.ts +0 -7
  375. package/dist/types/src/hooks/useServices.d.ts.map +0 -1
  376. package/dist/types/src/hooks/useTextInputEvents.d.ts +0 -13
  377. package/dist/types/src/hooks/useTextInputEvents.d.ts.map +0 -1
  378. package/dist/types/src/stories/Prompt.stories.d.ts +0 -8
  379. package/dist/types/src/stories/Prompt.stories.d.ts.map +0 -1
  380. package/dist/types/src/stories/Query.stories.d.ts +0 -19
  381. package/dist/types/src/stories/Query.stories.d.ts.map +0 -1
  382. package/dist/types/src/stories/Research.stories.d.ts +0 -15
  383. package/dist/types/src/stories/Research.stories.d.ts.map +0 -1
  384. package/dist/types/src/stories/test-data.d.ts +0 -3
  385. package/dist/types/src/stories/test-data.d.ts.map +0 -1
  386. package/dist/types/src/stories/testing.d.ts +0 -12
  387. package/dist/types/src/stories/testing.d.ts.map +0 -1
  388. package/dist/types/src/testing/test-blueprint.d.ts +0 -8
  389. package/dist/types/src/testing/test-blueprint.d.ts.map +0 -1
  390. package/dist/types/src/types/chat.d.ts +0 -23
  391. package/dist/types/src/types/chat.d.ts.map +0 -1
  392. package/dist/types/src/types/template.d.ts +0 -56
  393. package/dist/types/src/types/template.d.ts.map +0 -1
  394. package/dist/types/src/types/types.d.ts +0 -50
  395. package/dist/types/src/types/types.d.ts.map +0 -1
  396. package/src/capabilities/ai-client.ts +0 -42
  397. package/src/capabilities/capabilities.ts +0 -15
  398. package/src/components/AmbientDialog/AmbientDialog.stories.tsx +0 -84
  399. package/src/components/AmbientDialog/AmbientDialog.tsx +0 -117
  400. package/src/components/AssistantDialog.tsx +0 -37
  401. package/src/components/BlueprintContainer.tsx +0 -148
  402. package/src/components/BlueprintEditor/BlueprintEditor.stories.tsx +0 -32
  403. package/src/components/BlueprintEditor/index.ts +0 -5
  404. package/src/components/Prompt/Prompt.stories.tsx +0 -121
  405. package/src/components/Prompt/Prompt.tsx +0 -124
  406. package/src/components/Prompt/PromptBar.stories.tsx +0 -69
  407. package/src/components/Prompt/PromptBar.tsx +0 -105
  408. package/src/components/Prompt/autocomplete.ts +0 -218
  409. package/src/components/Prompt/index.ts +0 -6
  410. package/src/components/Prompt/references.ts +0 -180
  411. package/src/components/Thread/Thread.stories.tsx +0 -201
  412. package/src/components/Thread/Thread.tsx +0 -118
  413. package/src/components/Thread/ThreadContainer.stories.tsx +0 -283
  414. package/src/components/Thread/ThreadContainer.tsx +0 -105
  415. package/src/components/Thread/ThreadMessage.tsx +0 -234
  416. package/src/components/Thread/index.ts +0 -6
  417. package/src/hooks/processor.ts +0 -238
  418. package/src/hooks/useChatProcessor.tsx +0 -97
  419. package/src/hooks/useMessageQueue.ts +0 -22
  420. package/src/hooks/useServices.ts +0 -28
  421. package/src/hooks/useTextInputEvents.ts +0 -49
  422. package/src/stories/Prompt.stories.tsx +0 -60
  423. package/src/stories/Query.stories.tsx +0 -514
  424. package/src/stories/Research.stories.tsx +0 -482
  425. package/src/stories/test-data.ts +0 -128
  426. package/src/stories/testing.ts +0 -60
  427. package/src/testing/test-blueprint.ts +0 -58
  428. package/src/types/chat.ts +0 -32
  429. package/src/types/template.ts +0 -66
  430. package/src/types/types.ts +0 -48
@@ -1,2101 +0,0 @@
1
- import {
2
- ServiceType,
3
- categoryIcons
4
- } from "./chunk-AAOKC2JN.mjs";
5
- import {
6
- AssistantCapabilities
7
- } from "./chunk-UE3IZ4PN.mjs";
8
- import {
9
- ASSISTANT_PLUGIN
10
- } from "./chunk-XOZ7YMO3.mjs";
11
-
12
- // packages/plugins/plugin-assistant/src/components/Prompt/Prompt.tsx
13
- import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
14
- import { Prec as Prec2 } from "@codemirror/state";
15
- import React, { forwardRef, useImperativeHandle } from "react";
16
- import { useThemeContext } from "@dxos/react-ui";
17
- import { createBasicExtensions, createThemeExtensions, keymap as keymap3, useTextEditor } from "@dxos/react-ui-editor";
18
- import { mx } from "@dxos/react-ui-theme";
19
- import { isNonNullable } from "@dxos/util";
20
-
21
- // packages/plugins/plugin-assistant/src/components/Prompt/autocomplete.ts
22
- import { Prec } from "@codemirror/state";
23
- import { EditorView, Decoration, ViewPlugin, keymap, WidgetType } from "@codemirror/view";
24
- var autocompleteExtension = ({ onSubmit, onSuggest, onCancel }) => {
25
- const suggest = ViewPlugin.fromClass(class {
26
- constructor(view) {
27
- this._currentSuggestion = null;
28
- this._decorations = this.computeDecorations(view);
29
- }
30
- update(update) {
31
- if (update.docChanged || update.selectionSet) {
32
- this._decorations = this.computeDecorations(update.view);
33
- }
34
- }
35
- computeDecorations(view) {
36
- const text = view.state.doc.toString();
37
- const suggestions = onSuggest?.(text) ?? [];
38
- if (!suggestions.length) {
39
- this._currentSuggestion = null;
40
- return Decoration.none;
41
- }
42
- this._currentSuggestion = suggestions[0];
43
- const suffix = this._currentSuggestion.slice(text.length);
44
- if (!suffix) {
45
- return Decoration.none;
46
- }
47
- return Decoration.set([
48
- Decoration.widget({
49
- widget: new InlineSuggestionWidget(suffix),
50
- side: 1
51
- }).range(view.state.doc.length)
52
- ]);
53
- }
54
- completeSuggestion(view) {
55
- if (!this._currentSuggestion) {
56
- return false;
57
- }
58
- const text = view.state.doc.toString();
59
- const suffix = this._currentSuggestion.slice(text.length);
60
- if (!suffix) {
61
- return false;
62
- }
63
- view.dispatch({
64
- changes: {
65
- from: view.state.doc.length,
66
- insert: suffix
67
- },
68
- selection: {
69
- anchor: view.state.doc.length + suffix.length
70
- }
71
- });
72
- return true;
73
- }
74
- }, {
75
- decorations: (v) => v._decorations
76
- });
77
- return [
78
- suggest,
79
- EditorView.theme({
80
- ".cm-inline-suggestion": {
81
- opacity: 0.4
82
- }
83
- }),
84
- Prec.highest(keymap.of([
85
- {
86
- key: "Tab",
87
- preventDefault: true,
88
- run: (view) => {
89
- const plugin = view.plugin(suggest);
90
- return plugin?.completeSuggestion(view) ?? false;
91
- }
92
- },
93
- {
94
- key: "ArrowRight",
95
- preventDefault: true,
96
- run: (view) => {
97
- if (view.state.selection.main.head !== view.state.doc.length) {
98
- return false;
99
- }
100
- const plugin = view.plugin(suggest);
101
- return plugin?.completeSuggestion(view) ?? false;
102
- }
103
- },
104
- {
105
- key: "Enter",
106
- preventDefault: true,
107
- run: (view) => {
108
- const text = view.state.doc.toString().trim();
109
- if (text.length > 0 && onSubmit) {
110
- const reset = onSubmit(text);
111
- if (reset) {
112
- view.dispatch({
113
- changes: {
114
- from: 0,
115
- to: view.state.doc.length,
116
- insert: ""
117
- }
118
- });
119
- }
120
- }
121
- return true;
122
- }
123
- },
124
- {
125
- key: "Shift-Enter",
126
- preventDefault: true,
127
- run: (view) => {
128
- view.dispatch({
129
- changes: {
130
- from: view.state.selection.main.head,
131
- insert: "\n"
132
- },
133
- selection: {
134
- anchor: view.state.selection.main.head + 1,
135
- head: view.state.selection.main.head + 1
136
- }
137
- });
138
- return true;
139
- }
140
- },
141
- {
142
- key: "Escape",
143
- preventDefault: true,
144
- run: (view) => {
145
- view.dispatch({
146
- changes: {
147
- from: 0,
148
- to: view.state.doc.length,
149
- insert: ""
150
- }
151
- });
152
- onCancel?.();
153
- return true;
154
- }
155
- }
156
- ]))
157
- ];
158
- };
159
- var InlineSuggestionWidget = class extends WidgetType {
160
- constructor(suffix) {
161
- super(), this.suffix = suffix;
162
- }
163
- toDOM() {
164
- const span = document.createElement("span");
165
- span.textContent = this.suffix;
166
- span.className = "cm-inline-suggestion";
167
- return span;
168
- }
169
- eq(other) {
170
- return other.suffix === this.suffix;
171
- }
172
- };
173
-
174
- // packages/plugins/plugin-assistant/src/components/Prompt/references.ts
175
- import { autocompletion, completionKeymap } from "@codemirror/autocomplete";
176
- import { RangeSet } from "@codemirror/state";
177
- import { Decoration as Decoration2, EditorView as EditorView2, keymap as keymap2, ViewPlugin as ViewPlugin2, WidgetType as WidgetType2 } from "@codemirror/view";
178
- import { Mutex } from "@dxos/async";
179
- var promptReferences = ({ provider, debug = false, triggerCharacter = "@" }) => {
180
- if (triggerCharacter.length !== 1) {
181
- throw new Error("triggerCharacter must be a single character");
182
- }
183
- const decorationField = ViewPlugin2.fromClass(class ReferenceView {
184
- constructor(view) {
185
- this._mutex = new Mutex();
186
- this.decorations = Decoration2.set([]);
187
- queueMicrotask(async () => {
188
- const guard = await this._mutex.acquire();
189
- try {
190
- this.decorations = await this._computeDecorations(view);
191
- } finally {
192
- guard.release();
193
- }
194
- });
195
- }
196
- update(update) {
197
- if (update.docChanged) {
198
- queueMicrotask(async () => {
199
- const guard = await this._mutex.acquire();
200
- try {
201
- this.decorations = await this._computeDecorations(update.view);
202
- } finally {
203
- guard.release();
204
- }
205
- });
206
- }
207
- }
208
- async _computeDecorations(view) {
209
- const text = view.state.doc.toString();
210
- const references = text.matchAll(new RegExp(`${triggerCharacter}[a-zA-Z0-9@:]+\\s`, "g"));
211
- const decorations = [];
212
- for (const match of references) {
213
- const reference = match[0];
214
- const uri = reference.slice(1, -1);
215
- const data = await provider.resolveReference({
216
- uri
217
- });
218
- if (data) {
219
- decorations.push(Decoration2.replace({
220
- widget: new ReferenceWidget(data)
221
- }).range(match.index, match.index + reference.length));
222
- }
223
- }
224
- return Decoration2.set(decorations);
225
- }
226
- }, {
227
- decorations: (v) => v.decorations,
228
- provide: (plugin) => [
229
- EditorView2.atomicRanges.of((view) => view.plugin(decorationField)?.decorations ?? RangeSet.empty)
230
- ]
231
- });
232
- return [
233
- decorationField,
234
- EditorView2.theme({
235
- ".cm-reference-pill": {
236
- borderRadius: "0.25rem",
237
- borderWidth: "1px",
238
- marginRight: "0.25rem",
239
- marginLeft: "0.25rem"
240
- }
241
- }),
242
- autocompletion({
243
- activateOnTyping: true,
244
- override: [
245
- async (context) => {
246
- const match = context.matchBefore(new RegExp(`${triggerCharacter}[a-zA-Z0-9]+`));
247
- if (!match || match?.to === match?.from) {
248
- return null;
249
- }
250
- const query = match.text.slice(1);
251
- const references = await provider.getReferences({
252
- query
253
- });
254
- return {
255
- from: match.from,
256
- filter: false,
257
- options: references.map((reference) => ({
258
- label: reference.label,
259
- apply: `${triggerCharacter}${reference.uri} `
260
- }))
261
- };
262
- }
263
- ],
264
- closeOnBlur: !debug,
265
- tooltipClass: () => "shadow rounded",
266
- aboveCursor: true
267
- }),
268
- keymap2.of(completionKeymap)
269
- ];
270
- };
271
- var ReferenceWidget = class extends WidgetType2 {
272
- constructor(data) {
273
- super(), this.data = data;
274
- }
275
- toDOM() {
276
- const span = document.createElement("span");
277
- span.textContent = `@ ${this.data.label}`;
278
- span.className = "cm-reference-pill";
279
- return span;
280
- }
281
- eq(other) {
282
- return other.data.uri === this.data.uri;
283
- }
284
- ignoreEvent() {
285
- return true;
286
- }
287
- };
288
-
289
- // packages/plugins/plugin-assistant/src/components/Prompt/Prompt.tsx
290
- var Prompt = /* @__PURE__ */ forwardRef(({ classNames, extensions, references, autoFocus, lineWrapping = false, placeholder, onSubmit, onSuggest, onCancel, onOpenChange }, forwardRef3) => {
291
- var _effect = _useSignals();
292
- try {
293
- const { themeMode } = useThemeContext();
294
- const { parentRef, view } = useTextEditor({
295
- debug: true,
296
- autoFocus,
297
- extensions: [
298
- autocompleteExtension({
299
- onSubmit,
300
- onSuggest,
301
- onCancel
302
- }),
303
- createBasicExtensions({
304
- bracketMatching: false,
305
- lineWrapping,
306
- placeholder
307
- }),
308
- createThemeExtensions({
309
- themeMode
310
- }),
311
- references ? promptReferences({
312
- provider: references
313
- }) : [],
314
- Prec2.highest(keymap3.of([
315
- {
316
- key: "cmd-ArrowUp",
317
- preventDefault: true,
318
- run: () => {
319
- onOpenChange?.(true);
320
- return true;
321
- }
322
- },
323
- {
324
- key: "cmd-ArrowDown",
325
- preventDefault: true,
326
- run: () => {
327
- onOpenChange?.(false);
328
- return true;
329
- }
330
- }
331
- ])),
332
- extensions
333
- ].filter(isNonNullable)
334
- }, [
335
- themeMode,
336
- extensions,
337
- onSubmit,
338
- onSuggest
339
- ]);
340
- useImperativeHandle(forwardRef3, () => {
341
- return {
342
- focus: () => {
343
- view?.focus();
344
- },
345
- setText: (text) => {
346
- view?.dispatch({
347
- changes: {
348
- from: 0,
349
- to: view.state.doc.length,
350
- insert: text
351
- },
352
- selection: {
353
- anchor: text.length,
354
- head: text.length
355
- }
356
- });
357
- }
358
- };
359
- }, [
360
- view,
361
- onSubmit
362
- ]);
363
- return /* @__PURE__ */ React.createElement("div", {
364
- ref: parentRef,
365
- className: mx("w-full", classNames)
366
- });
367
- } finally {
368
- _effect.f();
369
- }
370
- });
371
-
372
- // packages/plugins/plugin-assistant/src/components/Prompt/PromptBar.tsx
373
- import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
374
- import React2, { forwardRef as forwardRef2, useState } from "react";
375
- import { useVoiceInput } from "@dxos/plugin-transcription";
376
- import { Icon, IconButton, Tooltip, useForwardedRef, useTranslation } from "@dxos/react-ui";
377
- import { Spinner } from "@dxos/react-ui-sfx";
378
- import { errorText, mx as mx2 } from "@dxos/react-ui-theme";
379
- var PromptBar = /* @__PURE__ */ forwardRef2(({ classNames, placeholder, processing, error, microphone, references, onCancel, ...props }, forwardedRef) => {
380
- var _effect = _useSignals2();
381
- try {
382
- const { t } = useTranslation(ASSISTANT_PLUGIN);
383
- const promptRef = useForwardedRef(forwardedRef);
384
- const [active, setActive] = useState(false);
385
- const { recording } = useVoiceInput({
386
- active,
387
- onUpdate: (text) => {
388
- promptRef.current?.setText(text);
389
- promptRef.current?.focus();
390
- }
391
- });
392
- return /* @__PURE__ */ React2.createElement("div", {
393
- className: mx2("shrink-0 w-full grid grid-cols-[var(--rail-action)_1fr_var(--rail-action)] overflow-hidden", classNames)
394
- }, /* @__PURE__ */ React2.createElement("div", {
395
- className: "flex w-[--rail-action] h-[--rail-action] items-center justify-center"
396
- }, error && /* @__PURE__ */ React2.createElement(Tooltip.Trigger, {
397
- content: error.message,
398
- delayDuration: 0
399
- }, /* @__PURE__ */ React2.createElement(Icon, {
400
- icon: "ph--warning-circle--regular",
401
- classNames: errorText,
402
- size: 5
403
- })) || /* @__PURE__ */ React2.createElement(Spinner, {
404
- active: processing
405
- })), /* @__PURE__ */ React2.createElement(Prompt, {
406
- ref: promptRef,
407
- autoFocus: true,
408
- classNames: "pbs-2",
409
- lineWrapping: true,
410
- placeholder: placeholder ?? t("prompt placeholder"),
411
- references,
412
- onCancel,
413
- ...props
414
- }), (onCancel || microphone) && /* @__PURE__ */ React2.createElement("div", {
415
- className: "flex w-[--rail-action] h-[--rail-action] items-center justify-center"
416
- }, processing && onCancel && /* @__PURE__ */ React2.createElement(IconButton, {
417
- classNames: "px-1.5",
418
- variant: "ghost",
419
- size: 5,
420
- icon: "ph--x--regular",
421
- iconOnly: true,
422
- label: t("cancel processing button"),
423
- onClick: onCancel
424
- }), !processing && microphone && /* @__PURE__ */ React2.createElement(IconButton, {
425
- classNames: mx2("px-1.5", recording && "bg-primary-500"),
426
- variant: "ghost",
427
- size: 5,
428
- icon: "ph--microphone--regular",
429
- iconOnly: true,
430
- noTooltip: true,
431
- label: t("microphone button"),
432
- onMouseDown: () => setActive(true),
433
- onMouseUp: () => setActive(false),
434
- onTouchStart: () => setActive(true),
435
- onTouchEnd: () => setActive(false)
436
- })));
437
- } finally {
438
- _effect.f();
439
- }
440
- });
441
-
442
- // packages/plugins/plugin-assistant/src/components/Toolbox/Toolbox.tsx
443
- import { useSignals as _useSignals3 } from "@preact-signals/safe-react/tracking";
444
- import React3, { useState as useState2, useEffect, Fragment } from "react";
445
- import { parseToolName } from "@dxos/ai";
446
- import { Capabilities, useCapabilities } from "@dxos/app-framework";
447
- import { FunctionType } from "@dxos/functions";
448
- import { log as log3 } from "@dxos/log";
449
- import { Filter, useQuery } from "@dxos/react-client/echo";
450
- import { mx as mx3 } from "@dxos/react-ui-theme";
451
-
452
- // packages/plugins/plugin-assistant/src/tools/function.ts
453
- import { createTool, ToolResult } from "@dxos/ai";
454
- import { Type } from "@dxos/echo";
455
- import { getInvocationUrl, getUserFunctionUrlInMetadata } from "@dxos/functions";
456
- import { log } from "@dxos/log";
457
- import { getMeta } from "@dxos/react-client/echo";
458
- var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/plugin-assistant/src/tools/function.ts";
459
- var convertFunctionToTool = (fn, edgeUrl, spaceId) => {
460
- if (!fn.description || !fn.inputSchema) {
461
- return void 0;
462
- }
463
- const existingFunctionUrl = getUserFunctionUrlInMetadata(getMeta(fn));
464
- if (!existingFunctionUrl) {
465
- return void 0;
466
- }
467
- const url = getInvocationUrl(existingFunctionUrl, edgeUrl, {
468
- spaceId
469
- });
470
- return createTool("user-function", {
471
- name: fn.name,
472
- description: fn.description,
473
- schema: Type.toEffectSchema(fn.inputSchema),
474
- execute: async (input) => {
475
- log.info("execute function tool", {
476
- name: fn.name,
477
- url,
478
- input
479
- }, {
480
- F: __dxlog_file,
481
- L: 34,
482
- S: void 0,
483
- C: (f, a) => f(...a)
484
- });
485
- const response = await fetch(url, {
486
- method: "POST",
487
- headers: {
488
- "Content-Type": "application/json"
489
- },
490
- body: JSON.stringify(input)
491
- });
492
- return ToolResult.Success(await response.text());
493
- }
494
- });
495
- };
496
-
497
- // packages/plugins/plugin-assistant/src/tools/openapi.ts
498
- import { Schema } from "effect";
499
- import jsonpointer from "jsonpointer";
500
- import { ToolResult as ToolResult2, createRawTool } from "@dxos/ai";
501
- import { Type as Type2 } from "@dxos/echo";
502
- import { normalizeSchema } from "@dxos/echo-schema";
503
- import { invariant } from "@dxos/invariant";
504
- import { log as log2 } from "@dxos/log";
505
- import { deepMapValues } from "@dxos/util";
506
- var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-assistant/src/tools/openapi.ts";
507
- var createToolsFromService = async (service) => {
508
- invariant(service.interfaces?.length === 1 && service.interfaces[0].kind === "api", void 0, {
509
- F: __dxlog_file2,
510
- L: 24,
511
- S: void 0,
512
- A: [
513
- "service.interfaces?.length === 1 && service.interfaces[0].kind === 'api'",
514
- ""
515
- ]
516
- });
517
- const iface = service.interfaces[0];
518
- invariant(iface.schemaUrl, void 0, {
519
- F: __dxlog_file2,
520
- L: 26,
521
- S: void 0,
522
- A: [
523
- "iface.schemaUrl",
524
- ""
525
- ]
526
- });
527
- invariant(iface.schemaUrl, void 0, {
528
- F: __dxlog_file2,
529
- L: 27,
530
- S: void 0,
531
- A: [
532
- "iface.schemaUrl",
533
- ""
534
- ]
535
- });
536
- return createToolsFromApi(iface.schemaUrl, {
537
- authorization: iface.authorization
538
- });
539
- };
540
- var createToolsFromApi = async (url, options) => {
541
- const res = await fetch(url);
542
- const spec = await res.json();
543
- log2("spec", {
544
- spec
545
- }, {
546
- F: __dxlog_file2,
547
- L: 37,
548
- S: void 0,
549
- C: (f, a) => f(...a)
550
- });
551
- const tools = [];
552
- for (const [path, pathItem] of Object.entries(spec.paths)) {
553
- if (typeof pathItem !== "object") {
554
- continue;
555
- }
556
- const { ...methods } = pathItem;
557
- for (const [method, m] of Object.entries(methods)) {
558
- const methodItem = m;
559
- log2("methodItem", {
560
- path,
561
- method,
562
- methodItem
563
- }, {
564
- F: __dxlog_file2,
565
- L: 48,
566
- S: void 0,
567
- C: (f, a) => f(...a)
568
- });
569
- const parametersResolved = methodItem.parameters?.map((parameter) => {
570
- const resolved = resolveJsonSchema(parameter, spec);
571
- return resolved;
572
- }) ?? [];
573
- const inputSchema = {
574
- type: "object",
575
- properties: {}
576
- };
577
- const endpointParameters = [];
578
- for (const parameter of parametersResolved) {
579
- log2("parameter", {
580
- parameter
581
- }, {
582
- F: __dxlog_file2,
583
- L: 63,
584
- S: void 0,
585
- C: (f, a) => f(...a)
586
- });
587
- if (options?.authorization?.type === "api-key" && options.authorization.placement.type === "query" && parameter.in === "query" && parameter.name === options.authorization.placement.name) {
588
- continue;
589
- }
590
- endpointParameters.push(parameter);
591
- if (parameter.schema) {
592
- inputSchema.properties[parameter.name] = normalizeSchema(parameter.schema);
593
- } else if (typeof parameter.type === "string") {
594
- const { name, in: _in, required, ...schema } = parameter;
595
- inputSchema.properties[name] = normalizeSchema(schema);
596
- if (required) {
597
- inputSchema.required ??= [];
598
- inputSchema.required.push(name);
599
- }
600
- }
601
- }
602
- log2("inputSchema", {
603
- inputSchema
604
- }, {
605
- F: __dxlog_file2,
606
- L: 88,
607
- S: void 0,
608
- C: (f, a) => f(...a)
609
- });
610
- Schema.validateSync(Type2.JsonSchema)(inputSchema);
611
- const description = methodItem.description ?? methodItem.summary;
612
- if (!description) {
613
- log2.warn("no description", {
614
- path,
615
- method
616
- }, {
617
- F: __dxlog_file2,
618
- L: 93,
619
- S: void 0,
620
- C: (f, a) => f(...a)
621
- });
622
- continue;
623
- }
624
- const endpoint = {
625
- document: spec,
626
- path,
627
- method,
628
- parameters: endpointParameters,
629
- authorization: options?.authorization
630
- };
631
- tools.push(
632
- // TODO(burdon): Namespace?
633
- createRawTool("openapi", {
634
- name: getToolName(path, method, methodItem),
635
- description: options?.instructions ? `${options.instructions}
636
-
637
- ${description}` : description,
638
- parameters: inputSchema,
639
- execute: async (input) => {
640
- const response = await callApiEndpoint(endpoint, input);
641
- return ToolResult2.Success(response);
642
- }
643
- })
644
- );
645
- }
646
- }
647
- return tools;
648
- };
649
- var getToolName = (path, method, methodItem) => {
650
- if (methodItem.operationId) {
651
- return methodItem.operationId;
652
- }
653
- let name = `${method.toLowerCase()}_${path.replaceAll(/[{}/]/g, "_")}`;
654
- while (name.length > MAX_TOOL_NAME_LENGTH) {
655
- const lengthBefore = name.length;
656
- for (const word of GENERIC_WORDS) {
657
- if (name.includes(word)) {
658
- name = name.replace(word, "");
659
- break;
660
- }
661
- }
662
- name = name.replaceAll("__", "_").replace(/_$/, "");
663
- const lengthAfter = name.length;
664
- if (lengthBefore === lengthAfter) {
665
- break;
666
- }
667
- }
668
- name = name.replaceAll("__", "_").replace(/_$/, "").replace(/^_/, "");
669
- return name.slice(0, MAX_TOOL_NAME_LENGTH);
670
- };
671
- var MAX_TOOL_NAME_LENGTH = 64;
672
- var GENERIC_WORDS = [
673
- "services",
674
- "service",
675
- "api",
676
- "rest",
677
- "endpoint",
678
- "get",
679
- "post",
680
- "put",
681
- "delete",
682
- "patch",
683
- "head",
684
- "options",
685
- "trace",
686
- "service",
687
- "api",
688
- "endpoint"
689
- ];
690
- var callApiEndpoint = async (endpoint, input) => {
691
- log2.info("endpoint", {
692
- method: endpoint.method,
693
- name: endpoint.path,
694
- input
695
- }, {
696
- F: __dxlog_file2,
697
- L: 180,
698
- S: void 0,
699
- C: (f, a) => f(...a)
700
- });
701
- let url = getEndpointUrl(endpoint);
702
- const request = {
703
- method: endpoint.method,
704
- headers: {}
705
- };
706
- const query = new URLSearchParams();
707
- let body;
708
- for (const parameter of endpoint.parameters) {
709
- if (input[parameter.name] === void 0) {
710
- continue;
711
- }
712
- switch (parameter.in) {
713
- case "header": {
714
- if (parameter.example) {
715
- request.headers[parameter.name] = parameter.default;
716
- }
717
- break;
718
- }
719
- case "path": {
720
- url = url.replace(`{${parameter.name}}`, encodeURIComponent(input[parameter.name]));
721
- break;
722
- }
723
- case "body": {
724
- const value = input[parameter.name];
725
- const effectSchema = Type2.toEffectSchema(parameter.schema);
726
- Schema.validateSync(effectSchema)(value);
727
- if (body) {
728
- throw new Error(`Duplicate body parameter: ${parameter.name}`);
729
- }
730
- body = value;
731
- break;
732
- }
733
- case "query": {
734
- query.set(parameter.name, input[parameter.name]);
735
- break;
736
- }
737
- }
738
- }
739
- if (endpoint.authorization?.type === "api-key" && endpoint.authorization.placement.type === "authorization-header" || endpoint.authorization?.type === "oauth") {
740
- request.headers.Authorization = await resolveAuthorization(endpoint.authorization);
741
- } else if (endpoint.authorization?.type === "api-key" && endpoint.authorization.placement.type === "query") {
742
- query.set(endpoint.authorization.placement.name, endpoint.authorization.key);
743
- }
744
- if (query.size > 0) {
745
- url += `?${query.toString()}`;
746
- }
747
- if (body) {
748
- request.body = JSON.stringify(body);
749
- request.headers["Content-Type"] = "application/json";
750
- }
751
- log2.info("request", {
752
- url,
753
- request
754
- }, {
755
- F: __dxlog_file2,
756
- L: 243,
757
- S: void 0,
758
- C: (f, a) => f(...a)
759
- });
760
- const response = await fetch(url, request);
761
- log2.info("response", {
762
- ok: response.ok,
763
- status: response.status,
764
- statusText: response.statusText
765
- }, {
766
- F: __dxlog_file2,
767
- L: 246,
768
- S: void 0,
769
- C: (f, a) => f(...a)
770
- });
771
- if (response.ok) {
772
- const contentType = response.headers.get("Content-Type");
773
- if (contentType?.includes("application/json")) {
774
- return await response.json();
775
- } else {
776
- return await response.text();
777
- }
778
- } else {
779
- if (response.headers.get("Content-Type")?.includes("application/json")) {
780
- const responseBody = await response.text();
781
- let error;
782
- try {
783
- error = JSON.parse(responseBody);
784
- } catch {
785
- error = responseBody;
786
- }
787
- log2.error("error", {
788
- error
789
- }, {
790
- F: __dxlog_file2,
791
- L: 264,
792
- S: void 0,
793
- C: (f, a) => f(...a)
794
- });
795
- throw new Error(error.message);
796
- } else {
797
- const error = await response.text();
798
- log2.error("error", {
799
- error
800
- }, {
801
- F: __dxlog_file2,
802
- L: 268,
803
- S: void 0,
804
- C: (f, a) => f(...a)
805
- });
806
- throw new Error(error);
807
- }
808
- }
809
- };
810
- var getEndpointUrl = (endpoint) => {
811
- let url = "";
812
- if (isV3_1(endpoint.document) && endpoint.document.servers && endpoint.document.servers.length > 0) {
813
- url = endpoint.document.servers[0].url;
814
- } else {
815
- invariant(!isV3_1(endpoint.document), void 0, {
816
- F: __dxlog_file2,
817
- L: 279,
818
- S: void 0,
819
- A: [
820
- "!isV3_1(endpoint.document)",
821
- ""
822
- ]
823
- });
824
- url = `${endpoint.document.schemes?.[0] ?? "https"}://${endpoint.document.host}`;
825
- }
826
- if (!isV3_1(endpoint.document) && endpoint.document.basePath) {
827
- url += endpoint.document.basePath;
828
- }
829
- url += endpoint.path;
830
- return url;
831
- };
832
- var resolveAuthorization = async (authorization) => {
833
- switch (authorization.type) {
834
- case "api-key": {
835
- invariant(authorization.placement.type === "authorization-header", void 0, {
836
- F: __dxlog_file2,
837
- L: 295,
838
- S: void 0,
839
- A: [
840
- "authorization.placement.type === 'authorization-header'",
841
- ""
842
- ]
843
- });
844
- return `Bearer ${authorization.key}`;
845
- }
846
- case "oauth": {
847
- const response = await fetch(authorization.tokenUrl, {
848
- method: "POST",
849
- headers: {
850
- "Content-Type": "application/x-www-form-urlencoded"
851
- },
852
- body: `grant_type=${authorization.grantType}&client_id=${authorization.clientId}&client_secret=${authorization.clientSecret}`
853
- });
854
- const data = await response.json();
855
- return `Bearer ${data.access_token}`;
856
- }
857
- default: {
858
- throw new Error(`Unknown authorization type: ${authorization.type}`);
859
- }
860
- }
861
- };
862
- var resolveJsonSchema = (schema, base) => {
863
- return deepMapValues(schema, (value, recurse) => {
864
- if (typeof value === "object" && value !== null && "$ref" in value && typeof value.$ref === "string") {
865
- if (value.$ref.startsWith("#")) {
866
- const resolved = jsonpointer.get(base, value.$ref.slice(1));
867
- if (resolved) {
868
- return recurse(resolved);
869
- } else {
870
- log2.warn("unresolved", {
871
- ref: value.$ref,
872
- base
873
- }, {
874
- F: __dxlog_file2,
875
- L: 328,
876
- S: void 0,
877
- C: (f, a) => f(...a)
878
- });
879
- }
880
- }
881
- }
882
- return recurse(value);
883
- });
884
- };
885
- var isV3_1 = (document2) => {
886
- return document2.openapi === "3.0.1";
887
- };
888
-
889
- // packages/plugins/plugin-assistant/src/components/Toolbox/Toolbox.tsx
890
- var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-assistant/src/components/Toolbox/Toolbox.tsx";
891
- var Toolbox = ({ classNames, artifacts, functions, services, striped }) => {
892
- var _effect = _useSignals3();
893
- try {
894
- return /* @__PURE__ */ React3.createElement("div", {
895
- className: mx3("flex flex-col overflow-y-auto box-content", classNames)
896
- }, artifacts && artifacts.length > 0 && /* @__PURE__ */ React3.createElement(Section, {
897
- title: "Artifacts",
898
- items: artifacts.map(({ name, description, tools }) => ({
899
- name,
900
- description,
901
- subitems: tools.map(({ name: name2, description: description2 }) => ({
902
- name: `\u2219 ${parseToolName(name2)}`,
903
- description: description2
904
- }))
905
- }))
906
- }), services && services.length > 0 && /* @__PURE__ */ React3.createElement(Section, {
907
- title: "Services",
908
- items: services.map(({ service: { serviceId, name, description }, tools }) => ({
909
- name: name ?? serviceId,
910
- description,
911
- subitems: tools.map(({ name: name2, description: description2 }) => ({
912
- name: `\u2219 ${name2}`,
913
- description: description2
914
- }))
915
- }))
916
- }), functions && functions.length > 0 && /* @__PURE__ */ React3.createElement(Section, {
917
- title: "Functions",
918
- items: functions.map(({ name, description }) => ({
919
- name,
920
- description
921
- }))
922
- }));
923
- } finally {
924
- _effect.f();
925
- }
926
- };
927
- var Section = ({ title, items, striped }) => {
928
- var _effect = _useSignals3();
929
- try {
930
- const stripeClassNames = "odd:bg-neutral-50 dark:odd:bg-neutral-800";
931
- const gridClassNames = "grid grid-cols-[8rem_1fr]";
932
- const subGridClassNames = mx3("col-span-full grid grid-cols-subgrid text-xs px-2", striped && stripeClassNames);
933
- return /* @__PURE__ */ React3.createElement("div", null, /* @__PURE__ */ React3.createElement("h1", {
934
- className: "px-2 text-sm"
935
- }, title), /* @__PURE__ */ React3.createElement("div", {
936
- className: gridClassNames
937
- }, items.map(({ name, description, subitems }, i) => /* @__PURE__ */ React3.createElement(Fragment, {
938
- key: i
939
- }, name && /* @__PURE__ */ React3.createElement("div", {
940
- className: subGridClassNames
941
- }, /* @__PURE__ */ React3.createElement("div", {
942
- className: "truncate text-primary-500"
943
- }, name), /* @__PURE__ */ React3.createElement("div", {
944
- className: "line-clamp-2"
945
- }, description)), subitems?.map(({ name: name2, description: description2 }, i2) => /* @__PURE__ */ React3.createElement("div", {
946
- key: i2,
947
- className: mx3(subGridClassNames, striped && stripeClassNames)
948
- }, /* @__PURE__ */ React3.createElement("div", {
949
- className: "truncate"
950
- }, name2), /* @__PURE__ */ React3.createElement("div", {
951
- className: "line-clamp-3 text-subdued"
952
- }, description2)))))));
953
- } finally {
954
- _effect.f();
955
- }
956
- };
957
- var ToolboxContainer = ({ classNames, space }) => {
958
- var _effect = _useSignals3();
959
- try {
960
- const artifactDefinitions = useCapabilities(Capabilities.ArtifactDefinition);
961
- const services = useQuery(space, Filter.type(ServiceType));
962
- const [serviceTools, setServiceTools] = useState2([]);
963
- useEffect(() => {
964
- log3("creating service tools...", {
965
- services: services.length
966
- }, {
967
- F: __dxlog_file3,
968
- L: 100,
969
- S: void 0,
970
- C: (f, a) => f(...a)
971
- });
972
- queueMicrotask(async () => {
973
- const tools = await Promise.all(services.map(async (service) => ({
974
- service,
975
- tools: await createToolsFromService(service)
976
- })));
977
- setServiceTools(tools);
978
- });
979
- }, [
980
- services
981
- ]);
982
- const functions = useQuery(space, Filter.type(FunctionType));
983
- return /* @__PURE__ */ React3.createElement(Toolbox, {
984
- classNames,
985
- artifacts: artifactDefinitions,
986
- services: serviceTools,
987
- functions
988
- });
989
- } finally {
990
- _effect.f();
991
- }
992
- };
993
-
994
- // packages/plugins/plugin-assistant/src/components/Thread/Thread.tsx
995
- import { useSignals as _useSignals6 } from "@preact-signals/safe-react/tracking";
996
- import React6, { useCallback, useMemo as useMemo2, useRef as useRef2 } from "react";
997
- import { useIdentity } from "@dxos/react-client/halo";
998
- import { ScrollContainer } from "@dxos/react-ui-components";
999
- import { mx as mx5 } from "@dxos/react-ui-theme";
1000
- import { keyToFallback } from "@dxos/util";
1001
-
1002
- // packages/plugins/plugin-assistant/src/components/Thread/ThreadMessage.tsx
1003
- import { useSignals as _useSignals5 } from "@preact-signals/safe-react/tracking";
1004
- import React5 from "react";
1005
- import { Surface } from "@dxos/app-framework";
1006
- import { invariant as invariant2 } from "@dxos/invariant";
1007
- import { Button, Icon as Icon2, IconButton as IconButton2 } from "@dxos/react-ui";
1008
- import { MarkdownViewer, ToggleContainer as NativeToggleContainer } from "@dxos/react-ui-components";
1009
- import { Json as Json2 } from "@dxos/react-ui-syntax-highlighter";
1010
- import { mx as mx4 } from "@dxos/react-ui-theme";
1011
- import { safeParseJson } from "@dxos/util";
1012
-
1013
- // packages/plugins/plugin-assistant/src/components/Thread/ToolInvocations.tsx
1014
- import { useSignals as _useSignals4 } from "@preact-signals/safe-react/tracking";
1015
- import React4, { useEffect as useEffect2, useMemo, useRef, useState as useState3 } from "react";
1016
- import { log as log4 } from "@dxos/log";
1017
- import { NumericTabs, StatusRoll, ToggleContainer } from "@dxos/react-ui-components";
1018
- import { Json } from "@dxos/react-ui-syntax-highlighter";
1019
- import { isNonNullable as isNonNullable2, isNotFalsy } from "@dxos/util";
1020
- var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-assistant/src/components/Thread/ToolInvocations.tsx";
1021
- var isToolMessage = (message) => {
1022
- return message.content.some((block) => block.type === "tool_use" || block.type === "tool_result");
1023
- };
1024
- var getToolName2 = (tool) => {
1025
- return tool.namespace && tool.function ? `${tool.namespace}:${tool.function}` : tool.name.split("_").pop();
1026
- };
1027
- var getToolCaption = (tool, status) => {
1028
- if (!tool) {
1029
- return "Calling tool...";
1030
- }
1031
- return status?.message ?? tool.caption ?? `Calling ${getToolName2(tool)}...`;
1032
- };
1033
- var ToolBlock = ({ classNames, message, tools }) => {
1034
- var _effect = _useSignals4();
1035
- try {
1036
- const { content = [] } = message;
1037
- let request;
1038
- const blocks = content.filter((block) => block.type === "tool_use" || block.type === "tool_result");
1039
- const items = blocks.map((block) => {
1040
- switch (block.type) {
1041
- case "tool_use": {
1042
- if (block.pending && request?.block.id === block.id) {
1043
- return null;
1044
- }
1045
- log4.info("tool_use", {
1046
- tool: request?.tool,
1047
- status: block.currentStatus
1048
- }, {
1049
- F: __dxlog_file4,
1050
- L: 46,
1051
- S: void 0,
1052
- C: (f, a) => f(...a)
1053
- });
1054
- request = {
1055
- tool: tools?.find((tool) => tool.name === block.name),
1056
- block
1057
- };
1058
- return {
1059
- title: getToolCaption(request.tool, block.currentStatus),
1060
- block
1061
- };
1062
- }
1063
- case "tool_result": {
1064
- if (!request) {
1065
- log4.warn("unexpected message", {
1066
- block
1067
- }, {
1068
- F: __dxlog_file4,
1069
- L: 54,
1070
- S: void 0,
1071
- C: (f, a) => f(...a)
1072
- });
1073
- return {
1074
- title: "Error",
1075
- block
1076
- };
1077
- }
1078
- return {
1079
- title: `${getToolCaption(request.tool, void 0)} (Success)`,
1080
- block
1081
- };
1082
- }
1083
- default: {
1084
- request = void 0;
1085
- return {
1086
- title: "Error",
1087
- block
1088
- };
1089
- }
1090
- }
1091
- }).filter(isNonNullable2);
1092
- return /* @__PURE__ */ React4.createElement(ToolContainer, {
1093
- classNames,
1094
- items
1095
- });
1096
- } finally {
1097
- _effect.f();
1098
- }
1099
- };
1100
- var ToolContainer = ({ classNames, items }) => {
1101
- var _effect = _useSignals4();
1102
- try {
1103
- const tabsRef = useRef(null);
1104
- const [selected, setSelected] = useState3(0);
1105
- const [open, setOpen] = useState3(false);
1106
- useEffect2(() => {
1107
- if (open) {
1108
- tabsRef.current?.focus();
1109
- }
1110
- }, [
1111
- open
1112
- ]);
1113
- const handleSelect = (index) => {
1114
- if (index === selected) {
1115
- setOpen(false);
1116
- } else {
1117
- setSelected(index);
1118
- }
1119
- };
1120
- const title = useMemo(() => {
1121
- const lines = items.map((item) => item.title).filter(isNotFalsy);
1122
- return /* @__PURE__ */ React4.createElement(StatusRoll, {
1123
- key: "status-roll",
1124
- lines,
1125
- duration: 1e3,
1126
- autoAdvance: true
1127
- });
1128
- }, [
1129
- items
1130
- ]);
1131
- return /* @__PURE__ */ React4.createElement(ToggleContainer, {
1132
- classNames: [
1133
- "flex flex-col",
1134
- classNames
1135
- ],
1136
- title,
1137
- open,
1138
- onChangeOpen: setOpen
1139
- }, /* @__PURE__ */ React4.createElement("div", {
1140
- className: "grid grid-cols-[32px_1fr]"
1141
- }, /* @__PURE__ */ React4.createElement(NumericTabs, {
1142
- ref: tabsRef,
1143
- length: items.length,
1144
- selected,
1145
- onSelect: handleSelect
1146
- }), /* @__PURE__ */ React4.createElement(Json, {
1147
- data: items[selected].block,
1148
- classNames: "!p-1 text-xs"
1149
- })));
1150
- } finally {
1151
- _effect.f();
1152
- }
1153
- };
1154
-
1155
- // packages/plugins/plugin-assistant/src/components/Thread/ThreadMessage.tsx
1156
- var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-assistant/src/components/Thread/ThreadMessage.tsx";
1157
- var panelClassNames = "flex flex-col w-full px-2 bg-activeSurface rounded-md";
1158
- var userClassNames = "bg-[--user-fill] text-accentSurfaceText";
1159
- var ToggleContainer2 = (props) => {
1160
- var _effect = _useSignals5();
1161
- try {
1162
- return /* @__PURE__ */ React5.createElement(NativeToggleContainer, {
1163
- ...props,
1164
- classNames: mx4(panelClassNames, props.classNames)
1165
- });
1166
- } finally {
1167
- _effect.f();
1168
- }
1169
- };
1170
- var MessageContainer = ({ children, classNames, user }) => {
1171
- var _effect = _useSignals5();
1172
- try {
1173
- if (!children) {
1174
- return null;
1175
- }
1176
- return /* @__PURE__ */ React5.createElement("div", {
1177
- role: "list-item",
1178
- className: mx4("flex w-full", user && "justify-end", classNames)
1179
- }, /* @__PURE__ */ React5.createElement("div", {
1180
- className: mx4(user ? [
1181
- "px-2 py-1 rounded-md",
1182
- userClassNames
1183
- ] : "w-full")
1184
- }, children));
1185
- } finally {
1186
- _effect.f();
1187
- }
1188
- };
1189
- var ThreadMessage = ({ classNames, space, message, tools, onPrompt, onAddToGraph }) => {
1190
- var _effect = _useSignals5();
1191
- try {
1192
- const { role, content = [] } = message;
1193
- if (isToolMessage(message)) {
1194
- return /* @__PURE__ */ React5.createElement(MessageContainer, {
1195
- classNames: mx4(classNames, "animate-[fadeIn_0.5s]")
1196
- }, /* @__PURE__ */ React5.createElement(ToolBlock, {
1197
- space,
1198
- classNames: panelClassNames,
1199
- message,
1200
- tools
1201
- }));
1202
- }
1203
- return content.map((block, idx) => {
1204
- if (block.type === "text" && block.text.replaceAll(/\s+/g, "").length === 0) {
1205
- return null;
1206
- }
1207
- const Component = components[block.type] ?? components.default;
1208
- return /* @__PURE__ */ React5.createElement(MessageContainer, {
1209
- key: idx,
1210
- classNames: mx4(classNames, "animate-[fadeIn_0.5s]"),
1211
- user: block.type === "text" && role === "user"
1212
- }, /* @__PURE__ */ React5.createElement(Component, {
1213
- space,
1214
- block,
1215
- onPrompt,
1216
- onAddToGraph
1217
- }));
1218
- });
1219
- } finally {
1220
- _effect.f();
1221
- }
1222
- };
1223
- var components = {
1224
- //
1225
- // Text
1226
- //
1227
- ["text"]: ({ block }) => {
1228
- invariant2(block.type === "text", void 0, {
1229
- F: __dxlog_file5,
1230
- L: 105,
1231
- S: void 0,
1232
- A: [
1233
- "block.type === 'text'",
1234
- ""
1235
- ]
1236
- });
1237
- const title = block.disposition ? titles[block.disposition] : void 0;
1238
- if (!title) {
1239
- return /* @__PURE__ */ React5.createElement(MarkdownViewer, {
1240
- classNames: "[&>p]:animate-[fadeIn_0.5s]",
1241
- content: block.text
1242
- });
1243
- }
1244
- return /* @__PURE__ */ React5.createElement(ToggleContainer2, {
1245
- // open={open}
1246
- defaultOpen: systemDispositions.includes(block.disposition ?? "") && block.pending,
1247
- title,
1248
- icon: block.pending ? /* @__PURE__ */ React5.createElement(Icon2, {
1249
- icon: "ph--circle-notch--regular",
1250
- classNames: "text-subdued ml-2 animate-spin",
1251
- size: 4
1252
- }) : void 0
1253
- }, /* @__PURE__ */ React5.createElement(MarkdownViewer, {
1254
- content: block.text,
1255
- classNames: [
1256
- "pbe-2",
1257
- systemDispositions.includes(block.disposition ?? "") && "text-sm text-subdued"
1258
- ]
1259
- }));
1260
- },
1261
- //
1262
- // JSON
1263
- //
1264
- ["json"]: ({ space, block, onPrompt, onAddToGraph }) => {
1265
- invariant2(block.type === "json", void 0, {
1266
- F: __dxlog_file5,
1267
- L: 143,
1268
- S: void 0,
1269
- A: [
1270
- "block.type === 'json'",
1271
- ""
1272
- ]
1273
- });
1274
- switch (block.disposition) {
1275
- case "tool_list": {
1276
- return /* @__PURE__ */ React5.createElement(ToggleContainer2, {
1277
- title: titles[block.disposition],
1278
- defaultOpen: true
1279
- }, /* @__PURE__ */ React5.createElement(ToolboxContainer, {
1280
- space,
1281
- classNames: "pbe-2"
1282
- }));
1283
- }
1284
- case "suggest": {
1285
- const { text = "" } = safeParseJson(block.json ?? "{}") ?? {};
1286
- return /* @__PURE__ */ React5.createElement(IconButton2, {
1287
- icon: "ph--lightning--regular",
1288
- label: text,
1289
- onClick: () => onPrompt?.(text)
1290
- });
1291
- }
1292
- case "select": {
1293
- const { options = [] } = safeParseJson(block.json ?? "{}") ?? {};
1294
- return /* @__PURE__ */ React5.createElement("div", {
1295
- className: "flex flex-wrap gap-1"
1296
- }, options.map((option, idx) => /* @__PURE__ */ React5.createElement(Button, {
1297
- classNames: "animate-[fadeIn_0.5s] rounded-2xl text-sm",
1298
- key: option,
1299
- onClick: () => onPrompt?.(option)
1300
- }, option)));
1301
- }
1302
- case "graph": {
1303
- return /* @__PURE__ */ React5.createElement("div", {
1304
- className: "flex flex-wrap gap-1"
1305
- }, /* @__PURE__ */ React5.createElement(Surface, {
1306
- role: "card",
1307
- data: {
1308
- subject: JSON.parse(block.json ?? "{}")
1309
- },
1310
- limit: 1,
1311
- fallback: /* @__PURE__ */ React5.createElement("div", {
1312
- className: "font-mono text-xs text-pre"
1313
- }, block.json)
1314
- }), onAddToGraph && /* @__PURE__ */ React5.createElement(IconButton2, {
1315
- icon: "ph--plus--regular",
1316
- label: "Add to graph",
1317
- onClick: () => onAddToGraph?.(JSON.parse(block.json ?? "{}"))
1318
- }));
1319
- }
1320
- default: {
1321
- const title = block.disposition ? titles[block.disposition] : void 0;
1322
- return /* @__PURE__ */ React5.createElement(ToggleContainer2, {
1323
- title: title ?? "JSON"
1324
- }, /* @__PURE__ */ React5.createElement(Json2, {
1325
- data: safeParseJson(block.json ?? block),
1326
- classNames: "!p-1 text-xs"
1327
- }));
1328
- }
1329
- }
1330
- },
1331
- //
1332
- // Default
1333
- //
1334
- default: ({ block }) => {
1335
- let title = titles[block.type];
1336
- if (block.type === "tool_use") {
1337
- title = `Tool [${block.name}]`;
1338
- }
1339
- return /* @__PURE__ */ React5.createElement(ToggleContainer2, {
1340
- title: title ?? "JSON"
1341
- }, /* @__PURE__ */ React5.createElement(Json2, {
1342
- data: block,
1343
- classNames: "!p-1 text-xs"
1344
- }));
1345
- }
1346
- };
1347
- var titles = {
1348
- ["cot"]: "Chain of thought",
1349
- ["artifact"]: "Artifact",
1350
- ["tool_use"]: "Tool request",
1351
- ["tool_result"]: "Tool result",
1352
- ["tool_list"]: "Tools",
1353
- ["artifact-update"]: "Artifact(s) changed"
1354
- };
1355
- var systemDispositions = [
1356
- "cot",
1357
- "artifact-update"
1358
- ];
1359
-
1360
- // packages/plugins/plugin-assistant/src/components/Thread/reducer.ts
1361
- var messageReducer = ({ current, messages }, message) => {
1362
- let i = 0;
1363
- for (const block of message.content) {
1364
- switch (block.type) {
1365
- case "tool_use":
1366
- case "tool_result": {
1367
- if (current) {
1368
- current.content.push(block);
1369
- } else {
1370
- current = {
1371
- id: [
1372
- message.id,
1373
- i
1374
- ].join("_"),
1375
- role: message.role,
1376
- content: [
1377
- block
1378
- ]
1379
- };
1380
- messages.push(current);
1381
- }
1382
- break;
1383
- }
1384
- case "text":
1385
- default: {
1386
- current = void 0;
1387
- messages.push({
1388
- id: [
1389
- message.id,
1390
- i
1391
- ].join("_"),
1392
- role: message.role,
1393
- content: [
1394
- block
1395
- ]
1396
- });
1397
- break;
1398
- }
1399
- }
1400
- i++;
1401
- }
1402
- return {
1403
- current,
1404
- messages
1405
- };
1406
- };
1407
-
1408
- // packages/plugins/plugin-assistant/src/components/Thread/Thread.tsx
1409
- var Thread = ({ classNames, space, messages, collapse = true, transcription, processing, error, onSubmit, onCancel, onOpenChange, contextProvider, ...props }) => {
1410
- var _effect = _useSignals6();
1411
- try {
1412
- const scroller = useRef2(null);
1413
- const identity = useIdentity();
1414
- const fallbackValue = keyToFallback(identity.identityKey);
1415
- const userHue = identity.profile?.data?.hue || fallbackValue.hue;
1416
- const handleSubmit = useCallback((value) => {
1417
- onSubmit?.(value);
1418
- scroller.current?.scrollToBottom();
1419
- return true;
1420
- }, [
1421
- onSubmit
1422
- ]);
1423
- const { messages: filteredMessages = [] } = useMemo2(() => {
1424
- if (collapse) {
1425
- return (messages ?? []).reduce(messageReducer, {
1426
- messages: []
1427
- });
1428
- } else {
1429
- return {
1430
- messages: messages ?? []
1431
- };
1432
- }
1433
- }, [
1434
- messages,
1435
- collapse
1436
- ]);
1437
- const references = useMemo2(() => {
1438
- if (!contextProvider) {
1439
- return void 0;
1440
- }
1441
- return {
1442
- getReferences: async ({ query }) => contextProvider.query({
1443
- query
1444
- }),
1445
- resolveReference: async ({ uri }) => contextProvider.resolveMetadata({
1446
- uri
1447
- })
1448
- };
1449
- }, [
1450
- contextProvider
1451
- ]);
1452
- return /* @__PURE__ */ React6.createElement("div", {
1453
- role: "none",
1454
- className: mx5("flex flex-col grow overflow-hidden", classNames)
1455
- }, /* @__PURE__ */ React6.createElement(ScrollContainer, {
1456
- ref: scroller,
1457
- fade: true
1458
- }, /* @__PURE__ */ React6.createElement("div", {
1459
- role: "none",
1460
- className: mx5(filteredMessages.length > 0 && "pbs-6 pbe-6"),
1461
- style: {
1462
- "--user-fill": `var(--dx-${userHue}Fill)`
1463
- }
1464
- }, filteredMessages.map((message) => /* @__PURE__ */ React6.createElement(ThreadMessage, {
1465
- key: message.id,
1466
- classNames: "px-4 pbe-4",
1467
- space,
1468
- message,
1469
- ...props
1470
- })))), onSubmit && /* @__PURE__ */ React6.createElement(PromptBar, {
1471
- microphone: transcription,
1472
- processing,
1473
- error,
1474
- onSubmit: handleSubmit,
1475
- onCancel,
1476
- onOpenChange,
1477
- references
1478
- }));
1479
- } finally {
1480
- _effect.f();
1481
- }
1482
- };
1483
-
1484
- // packages/plugins/plugin-assistant/src/components/Thread/ThreadContainer.tsx
1485
- import { useSignals as _useSignals9 } from "@preact-signals/safe-react/tracking";
1486
- import React7, { useCallback as useCallback3, useEffect as useEffect5 } from "react";
1487
- import { CollaborationActions, createIntent, useIntentDispatcher as useIntentDispatcher2 } from "@dxos/app-framework";
1488
- import { DXN, Ref } from "@dxos/echo";
1489
- import { invariant as invariant4 } from "@dxos/invariant";
1490
- import { log as log7 } from "@dxos/log";
1491
- import { getSpace as getSpace2 } from "@dxos/react-client/echo";
1492
-
1493
- // packages/plugins/plugin-assistant/src/hooks/processor.ts
1494
- import { batch, computed, signal } from "@preact/signals-core";
1495
- import { DEFAULT_EDGE_MODEL } from "@dxos/ai";
1496
- import { AISession } from "@dxos/assistant";
1497
- import { invariant as invariant3 } from "@dxos/invariant";
1498
- import { log as log5 } from "@dxos/log";
1499
- import { Filter as Filter2, getVersion } from "@dxos/react-client/echo";
1500
- var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-assistant/src/hooks/processor.ts";
1501
- var defaultOptions = {
1502
- model: DEFAULT_EDGE_MODEL,
1503
- systemPrompt: "you are a helpful assistant"
1504
- };
1505
- var ChatProcessor = class {
1506
- constructor(_ai, _tools, _artifacts, _extensions, _options = defaultOptions) {
1507
- this._ai = _ai;
1508
- this._tools = _tools;
1509
- this._artifacts = _artifacts;
1510
- this._extensions = _extensions;
1511
- this._options = _options;
1512
- this._pending = signal([]);
1513
- this._block = signal(void 0);
1514
- this.streaming = computed(() => this._block.value !== void 0);
1515
- this.error = signal(void 0);
1516
- this.messages = computed(() => {
1517
- const messages = [
1518
- ...this._pending.value
1519
- ];
1520
- if (this._block.value) {
1521
- const current = messages.pop();
1522
- invariant3(current, void 0, {
1523
- F: __dxlog_file6,
1524
- L: 79,
1525
- S: this,
1526
- A: [
1527
- "current",
1528
- ""
1529
- ]
1530
- });
1531
- const { content, ...rest } = current;
1532
- const message = {
1533
- ...rest,
1534
- content: [
1535
- ...content,
1536
- this._block.value
1537
- ]
1538
- };
1539
- messages.push(message);
1540
- }
1541
- return messages;
1542
- });
1543
- this._artifactDiffResolver = async (artifacts) => {
1544
- const space = this._extensions?.space;
1545
- if (!space) {
1546
- return /* @__PURE__ */ new Map();
1547
- }
1548
- const versions = /* @__PURE__ */ new Map();
1549
- await Promise.all(artifacts.map(async (artifact) => {
1550
- const { objects: [object] } = await space.db.query(Filter2.ids(artifact.id)).run();
1551
- if (!object) {
1552
- return;
1553
- }
1554
- versions.set(artifact.id, {
1555
- version: getVersion(object),
1556
- diff: `Current state: ${JSON.stringify(object)}`
1557
- });
1558
- }));
1559
- return versions;
1560
- };
1561
- }
1562
- get tools() {
1563
- return this._tools;
1564
- }
1565
- /**
1566
- * Update tools.
1567
- */
1568
- setTools(tools) {
1569
- this._tools = tools;
1570
- }
1571
- /**
1572
- * Make GPT request.
1573
- */
1574
- async request(message, options = {}) {
1575
- this._session = new AISession({
1576
- operationModel: "configured"
1577
- });
1578
- this._session.message.on((message2) => {
1579
- batch(() => {
1580
- this._pending.value = [
1581
- ...this._pending.value,
1582
- message2
1583
- ];
1584
- this._block.value = void 0;
1585
- });
1586
- });
1587
- this._session.update.on((block) => {
1588
- batch(() => {
1589
- this._block.value = block;
1590
- });
1591
- });
1592
- this._session.userMessage.on((message2) => {
1593
- this._pending.value = [
1594
- ...this._pending.value,
1595
- message2
1596
- ];
1597
- });
1598
- this._session.toolStatusReport.on(({ message: message2, status }) => {
1599
- const msg = this._pending.peek().find((m) => m.id === message2.id);
1600
- const toolUse = msg?.content.find((block2) => block2.type === "tool_use");
1601
- if (!toolUse) {
1602
- return;
1603
- }
1604
- const block = msg?.content.find((block2) => block2.type === "tool_use" && block2.id === toolUse.id);
1605
- if (block) {
1606
- this._pending.value = this._pending.value.map((m) => {
1607
- if (m.id === message2.id) {
1608
- return {
1609
- ...m,
1610
- content: m.content.map((b) => b.type === "tool_use" && b.id === toolUse.id ? {
1611
- ...b,
1612
- currentStatus: status
1613
- } : b)
1614
- };
1615
- }
1616
- return m;
1617
- });
1618
- } else {
1619
- log5.warn("no block for status report", void 0, {
1620
- F: __dxlog_file6,
1621
- L: 155,
1622
- S: this,
1623
- C: (f, a) => f(...a)
1624
- });
1625
- }
1626
- });
1627
- try {
1628
- const messages = await this._session.run({
1629
- client: this._ai,
1630
- history: options.history ?? [],
1631
- artifacts: this._artifacts ?? [],
1632
- requiredArtifactIds: this._artifacts?.map((artifact) => artifact.id) ?? [],
1633
- tools: this._tools ?? [],
1634
- prompt: message,
1635
- systemPrompt: this._options.systemPrompt,
1636
- extensions: this._extensions,
1637
- artifactDiffResolver: this._artifactDiffResolver,
1638
- generationOptions: {
1639
- model: this._options.model
1640
- }
1641
- });
1642
- log5("completed", {
1643
- messages
1644
- }, {
1645
- F: __dxlog_file6,
1646
- L: 175,
1647
- S: this,
1648
- C: (f, a) => f(...a)
1649
- });
1650
- options.onComplete?.(this._pending.value);
1651
- } catch (err) {
1652
- log5.catch(err, void 0, {
1653
- F: __dxlog_file6,
1654
- L: 178,
1655
- S: this,
1656
- C: (f, a) => f(...a)
1657
- });
1658
- if (err instanceof Error && err.message.includes("Overloaded")) {
1659
- this.error.value = new AiServiceOverloadedError("AI service overloaded", {
1660
- cause: err
1661
- });
1662
- } else {
1663
- this.error.value = new Error("AI service error", {
1664
- cause: err
1665
- });
1666
- }
1667
- } finally {
1668
- this._session = void 0;
1669
- }
1670
- return this._reset();
1671
- }
1672
- /**
1673
- * Cancel pending requests.
1674
- * @returns Pending requests (incl. the request message).
1675
- */
1676
- async cancel() {
1677
- log5.info("cancelling...", void 0, {
1678
- F: __dxlog_file6,
1679
- L: 196,
1680
- S: this,
1681
- C: (f, a) => f(...a)
1682
- });
1683
- this._session?.abort();
1684
- return this._reset();
1685
- }
1686
- async _reset() {
1687
- const messages = this._pending.value;
1688
- batch(() => {
1689
- this._pending.value = [];
1690
- this._block.value = void 0;
1691
- });
1692
- return messages;
1693
- }
1694
- };
1695
- var AiServiceOverloadedError = class extends Error {
1696
- constructor() {
1697
- super(...arguments);
1698
- this.code = "AI_SERVICE_OVERLOADED";
1699
- }
1700
- };
1701
-
1702
- // packages/plugins/plugin-assistant/src/hooks/useChatProcessor.tsx
1703
- import { useSignals as _useSignals7 } from "@preact-signals/safe-react/tracking";
1704
- import { useEffect as useEffect3, useMemo as useMemo3, useState as useState4 } from "react";
1705
- import { DEFAULT_EDGE_MODEL as DEFAULT_EDGE_MODEL2, DEFAULT_OLLAMA_MODEL } from "@dxos/ai";
1706
- import { Capabilities as Capabilities2, useCapabilities as useCapabilities2, useCapability, useIntentDispatcher } from "@dxos/app-framework";
1707
- import { createSystemPrompt } from "@dxos/artifact";
1708
- import { FunctionType as FunctionType2 } from "@dxos/functions";
1709
- import { log as log6 } from "@dxos/log";
1710
- import { useConfig } from "@dxos/react-client";
1711
- import { Filter as Filter3, fullyQualifiedId, useQuery as useQuery2 } from "@dxos/react-client/echo";
1712
- import { isNonNullable as isNonNullable3 } from "@dxos/util";
1713
- var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-assistant/src/hooks/useChatProcessor.tsx";
1714
- var useChatProcessor = ({
1715
- chat,
1716
- space,
1717
- settings,
1718
- // part = 'deck',
1719
- part,
1720
- associatedArtifact
1721
- }) => {
1722
- var _effect = _useSignals7();
1723
- try {
1724
- const aiClient = useCapability(AssistantCapabilities.AiClient);
1725
- const globalTools = useCapabilities2(Capabilities2.Tools);
1726
- const artifactDefinitions = useCapabilities2(Capabilities2.ArtifactDefinition);
1727
- const { dispatchPromise: dispatch } = useIntentDispatcher();
1728
- const services = useQuery2(space, Filter3.type(ServiceType));
1729
- const [serviceTools, setServiceTools] = useState4([]);
1730
- useEffect3(() => {
1731
- log6("creating service tools...", void 0, {
1732
- F: __dxlog_file7,
1733
- L: 49,
1734
- S: void 0,
1735
- C: (f, a) => f(...a)
1736
- });
1737
- queueMicrotask(async () => {
1738
- const tools2 = await Promise.all(services.map((service) => createToolsFromService(service)));
1739
- setServiceTools(tools2.flat());
1740
- });
1741
- }, [
1742
- services
1743
- ]);
1744
- const config = useConfig();
1745
- const functions = useQuery2(space, Filter3.type(FunctionType2));
1746
- const chatId = useMemo3(() => chat ? fullyQualifiedId(chat) : void 0, [
1747
- chat
1748
- ]);
1749
- const [tools, extensions] = useMemo3(() => {
1750
- log6("creating tools...", void 0, {
1751
- F: __dxlog_file7,
1752
- L: 61,
1753
- S: void 0,
1754
- C: (f, a) => f(...a)
1755
- });
1756
- const tools2 = [
1757
- ...globalTools.flat(),
1758
- ...serviceTools,
1759
- ...functions.map((fn) => convertFunctionToTool(fn, config.values.runtime?.services?.edge?.url ?? "", space?.id)).filter(isNonNullable3)
1760
- ];
1761
- const extensions2 = {
1762
- space,
1763
- dispatch,
1764
- pivotId: chatId,
1765
- part
1766
- };
1767
- return [
1768
- tools2,
1769
- extensions2
1770
- ];
1771
- }, [
1772
- dispatch,
1773
- globalTools,
1774
- space,
1775
- chatId,
1776
- serviceTools,
1777
- functions
1778
- ]);
1779
- const systemPrompt = useMemo3(() => createSystemPrompt({
1780
- artifacts: artifactDefinitions.map((definition) => `${definition.name}
1781
- ${definition.instructions}`),
1782
- associatedArtifact
1783
- }), [
1784
- artifactDefinitions,
1785
- associatedArtifact
1786
- ]);
1787
- const model = settings?.llmProvider === "ollama" ? settings?.ollamaModel ?? DEFAULT_OLLAMA_MODEL : settings?.edgeModel ?? DEFAULT_EDGE_MODEL2;
1788
- const processor = useMemo3(() => {
1789
- log6("creating processor...", {
1790
- settings
1791
- }, {
1792
- F: __dxlog_file7,
1793
- L: 92,
1794
- S: void 0,
1795
- C: (f, a) => f(...a)
1796
- });
1797
- return new ChatProcessor(aiClient.value, tools, artifactDefinitions, extensions, {
1798
- model,
1799
- systemPrompt
1800
- });
1801
- }, [
1802
- aiClient.value,
1803
- tools,
1804
- artifactDefinitions,
1805
- extensions,
1806
- model,
1807
- systemPrompt
1808
- ]);
1809
- return processor;
1810
- } finally {
1811
- _effect.f();
1812
- }
1813
- };
1814
-
1815
- // packages/plugins/plugin-assistant/src/hooks/useMessageQueue.ts
1816
- import { useMemo as useMemo4 } from "react";
1817
- import { createQueueDXN } from "@dxos/echo-schema";
1818
- import { getSpace, useQueue } from "@dxos/react-client/echo";
1819
- var useMessageQueue = (chat) => {
1820
- const space = getSpace(chat);
1821
- const queueDxn = useMemo4(() => {
1822
- const dxn = space && chat?.queue.dxn;
1823
- return dxn ? createQueueDXN(space.id, dxn.parts.at(-1)) : void 0;
1824
- }, [
1825
- space,
1826
- chat?.queue.dxn
1827
- ]);
1828
- return useQueue(queueDxn);
1829
- };
1830
-
1831
- // packages/plugins/plugin-assistant/src/hooks/useServices.ts
1832
- import { useEffect as useEffect4, useMemo as useMemo5, useState as useState5 } from "react";
1833
-
1834
- // packages/plugins/plugin-assistant/src/testing/test-blueprint.ts
1835
- import { ToolRegistry } from "@dxos/ai";
1836
- import { EXA_API_KEY } from "@dxos/ai/testing";
1837
- import { BlueprintParser, createExaTool, createGraphWriterTool, createLocalSearchTool } from "@dxos/assistant";
1838
- import { DataTypes } from "@dxos/schema";
1839
- import { isNonNullable as isNonNullable4 } from "@dxos/util";
1840
- var RESEARCH_BLUEPRINT_DEFINITION = {
1841
- steps: [
1842
- {
1843
- instructions: "Research information and entities related to the selected objects.",
1844
- tools: [
1845
- "search/web_search"
1846
- ]
1847
- },
1848
- {
1849
- instructions: "Based on your research find matching entires that are already in the graph. Do exaustive research.",
1850
- tools: [
1851
- "search/local_search"
1852
- ]
1853
- },
1854
- {
1855
- instructions: "Add researched data to the graph. Make connections to existing objects.",
1856
- tools: [
1857
- "search/local_search",
1858
- "graph/writer"
1859
- ]
1860
- }
1861
- ]
1862
- };
1863
- var RESEARCH_BLUEPRINT = BlueprintParser.create().parse(RESEARCH_BLUEPRINT_DEFINITION);
1864
-
1865
- // packages/plugins/plugin-assistant/src/testing/test-functions.ts
1866
- import { DEFAULT_EDGE_MODEL as DEFAULT_EDGE_MODEL3 } from "@dxos/ai";
1867
- import { createSystemPrompt as createSystemPrompt2 } from "@dxos/artifact";
1868
-
1869
- // packages/plugins/plugin-assistant/src/testing/test-services.ts
1870
- import { Obj } from "@dxos/echo";
1871
- var AMADEUS_AUTH = {
1872
- type: "oauth",
1873
- clientId: "BOEnpLd1sMyKjAPGKYeAPFFy60u53QEG",
1874
- clientSecret: "n4qldSN7usvD57gm",
1875
- tokenUrl: "https://test.api.amadeus.com/v1/security/oauth2/token",
1876
- grantType: "client_credentials"
1877
- };
1878
- var VISUAL_CROSSING_CREDENTIALS = {
1879
- type: "api-key",
1880
- key: "FDPRVS953KB4GQQLD25GRT975",
1881
- placement: {
1882
- type: "query",
1883
- name: "key"
1884
- }
1885
- };
1886
- var TEST_SERVICES = [
1887
- Obj.make(ServiceType, {
1888
- serviceId: "amadeus.com/service/FlightSearch",
1889
- name: "Amadeus Flight Search",
1890
- description: "Search for local and international flights.",
1891
- category: "travel",
1892
- interfaces: [
1893
- {
1894
- kind: "api",
1895
- schemaUrl: "https://api.apis.guru/v2/specs/amadeus.com/amadeus-flight-availabilities-search/1.0.2/swagger.json",
1896
- authorization: AMADEUS_AUTH
1897
- }
1898
- ]
1899
- }),
1900
- Obj.make(ServiceType, {
1901
- serviceId: "amadeus.com/service/HotelSearch",
1902
- name: "Amadeus Hotel Search",
1903
- description: "Search for local and international hotels.",
1904
- category: "travel",
1905
- interfaces: [
1906
- {
1907
- kind: "api",
1908
- schemaUrl: "https://api.apis.guru/v2/specs/amadeus.com/amadeus-hotel-search/3.0.8/swagger.json",
1909
- authorization: AMADEUS_AUTH
1910
- }
1911
- ]
1912
- }),
1913
- Obj.make(ServiceType, {
1914
- serviceId: "visualcrossing.com/service/Weather",
1915
- name: "Visual Crossing Weather",
1916
- description: "Search for global weather forecasts.",
1917
- category: "weather",
1918
- interfaces: [
1919
- {
1920
- kind: "api",
1921
- schemaUrl: "https://api.apis.guru/v2/specs/visualcrossing.com/weather/4.6/openapi.json",
1922
- authorization: VISUAL_CROSSING_CREDENTIALS
1923
- }
1924
- ]
1925
- }),
1926
- // TODO(burdon): Needs auth.
1927
- Obj.make(ServiceType, {
1928
- serviceId: "abstractapi.com/service/GeoLocation",
1929
- name: "Abstract GeoLocation",
1930
- description: "Get the location of any IP address.",
1931
- category: "geolocation",
1932
- interfaces: [
1933
- {
1934
- kind: "api",
1935
- schemaUrl: "https://api.apis.guru/v2/specs/abstractapi.com/geolocation/1.0.0/openapi.json"
1936
- }
1937
- ]
1938
- }),
1939
- //
1940
- // Testing
1941
- //
1942
- ...Array.from({
1943
- length: 20
1944
- }, (_, i) => Obj.make(ServiceType, {
1945
- serviceId: `example.com/service/test-${i}`,
1946
- name: `Test ${i}`,
1947
- description: `Test ${i}`,
1948
- category: Object.keys(categoryIcons)[Math.floor(Math.random() * Object.keys(categoryIcons).length)],
1949
- interfaces: [
1950
- {
1951
- kind: "api",
1952
- schemaUrl: "https://petstore.swagger.io/v2/swagger.json"
1953
- }
1954
- ]
1955
- }))
1956
- ];
1957
-
1958
- // packages/plugins/plugin-assistant/src/hooks/useTextInputEvents.ts
1959
- import { useSignals as _useSignals8 } from "@preact-signals/safe-react/tracking";
1960
- import { useState as useState6, useCallback as useCallback2 } from "react";
1961
-
1962
- // packages/plugins/plugin-assistant/src/hooks/useContextProvider.ts
1963
- import { useMemo as useMemo6 } from "react";
1964
- import { Capabilities as Capabilities3, useCapabilities as useCapabilities3 } from "@dxos/app-framework";
1965
- import { Filter as Filter4, Obj as Obj2 } from "@dxos/echo";
1966
- var stringMatch = (query, label) => label.toLowerCase().startsWith(query.toLowerCase());
1967
- var useContextProvider = (space) => {
1968
- const artifactDefinitions = useCapabilities3(Capabilities3.ArtifactDefinition);
1969
- return useMemo6(() => {
1970
- if (!space) {
1971
- return void 0;
1972
- }
1973
- return {
1974
- query: async ({ query }) => {
1975
- const artifactSchemas = artifactDefinitions.map((artifact) => artifact.schema);
1976
- const { objects } = await space.db.query(Filter4.or(...artifactSchemas.map((schema) => Filter4.type(schema)))).run();
1977
- return objects.filter((object) => stringMatch(query, Obj2.getLabel(object) ?? "")).filter((object) => !!Obj2.getDXN(object)).map((object) => ({
1978
- uri: Obj2.getDXN(object).toString(),
1979
- label: Obj2.getLabel(object) ?? ""
1980
- }));
1981
- },
1982
- resolveMetadata: async ({ uri }) => {
1983
- const object = await space.db.query(Filter4.ids(uri)).first();
1984
- return {
1985
- uri,
1986
- label: Obj2.getLabel(object) ?? ""
1987
- };
1988
- }
1989
- };
1990
- }, [
1991
- space,
1992
- artifactDefinitions
1993
- ]);
1994
- };
1995
-
1996
- // packages/plugins/plugin-assistant/src/components/Thread/ThreadContainer.tsx
1997
- var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-assistant/src/components/Thread/ThreadContainer.tsx";
1998
- var ThreadContainer = ({ classNames, chat, settings, part, associatedArtifact, onOpenChange, ...props }) => {
1999
- var _effect = _useSignals9();
2000
- try {
2001
- const space = getSpace2(chat);
2002
- const contextProvider = useContextProvider(space);
2003
- const processor = useChatProcessor({
2004
- chat,
2005
- space,
2006
- settings,
2007
- part,
2008
- associatedArtifact
2009
- });
2010
- const messageQueue = useMessageQueue(chat);
2011
- const { dispatchPromise: dispatch } = useIntentDispatcher2();
2012
- const messages = [
2013
- ...messageQueue?.objects ?? [],
2014
- ...processor.messages.value
2015
- ];
2016
- useEffect5(() => {
2017
- if (!processor.streaming.value && messageQueue?.objects) {
2018
- const message = messageQueue.objects[messageQueue.objects.length - 1];
2019
- if (space && chat && message && dispatch && associatedArtifact) {
2020
- void dispatch(createIntent(CollaborationActions.InsertContent, {
2021
- target: associatedArtifact,
2022
- object: Ref.fromDXN(new DXN(DXN.kind.QUEUE, [
2023
- ...chat.queue.dxn.parts,
2024
- message.id
2025
- ])),
2026
- label: "View proposal"
2027
- }));
2028
- }
2029
- }
2030
- }, [
2031
- messageQueue,
2032
- associatedArtifact,
2033
- processor.streaming.value
2034
- ]);
2035
- const handleSubmit = useCallback3((text) => {
2036
- if (processor.streaming.value) {
2037
- log7.warn("ignoring submit; still processing.", void 0, {
2038
- F: __dxlog_file8,
2039
- L: 64,
2040
- S: void 0,
2041
- C: (f, a) => f(...a)
2042
- });
2043
- return false;
2044
- }
2045
- onOpenChange?.(true);
2046
- invariant4(messageQueue, void 0, {
2047
- F: __dxlog_file8,
2048
- L: 70,
2049
- S: void 0,
2050
- A: [
2051
- "messageQueue",
2052
- ""
2053
- ]
2054
- });
2055
- void processor.request(text, {
2056
- history: messageQueue.objects,
2057
- onComplete: (messages2) => {
2058
- void messageQueue.append(messages2);
2059
- }
2060
- });
2061
- return true;
2062
- }, [
2063
- processor,
2064
- messageQueue,
2065
- onOpenChange
2066
- ]);
2067
- const handleCancel = useCallback3(() => {
2068
- if (processor.streaming.value) {
2069
- void processor.cancel();
2070
- }
2071
- }, [
2072
- processor
2073
- ]);
2074
- return /* @__PURE__ */ React7.createElement(Thread, {
2075
- classNames,
2076
- space,
2077
- messages,
2078
- processing: processor.streaming.value,
2079
- error: processor.error.value,
2080
- tools: processor.tools,
2081
- contextProvider,
2082
- onSubmit: handleSubmit,
2083
- onCancel: handleCancel,
2084
- onPrompt: handleSubmit,
2085
- onOpenChange,
2086
- ...props
2087
- });
2088
- } finally {
2089
- _effect.f();
2090
- }
2091
- };
2092
-
2093
- export {
2094
- Prompt,
2095
- PromptBar,
2096
- Toolbox,
2097
- ToolboxContainer,
2098
- Thread,
2099
- ThreadContainer
2100
- };
2101
- //# sourceMappingURL=chunk-JO4W3MF7.mjs.map