@dxos/plugin-assistant 0.8.3 → 0.8.4-main.f9ba587

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