@dxos/plugin-script 0.8.4-main.67995b8 → 0.8.4-main.69d29f4

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 (426) hide show
  1. package/dist/lib/browser/DeploymentDialog-OSL6RMPA.mjs +14 -0
  2. package/dist/lib/browser/NotebookContainer-NBAXYESH.mjs +845 -0
  3. package/dist/lib/browser/NotebookContainer-NBAXYESH.mjs.map +7 -0
  4. package/dist/lib/browser/ScriptContainer-WD33CJMI.mjs +149 -0
  5. package/dist/lib/browser/ScriptContainer-WD33CJMI.mjs.map +7 -0
  6. package/dist/lib/browser/app-graph-builder-7VO7AUI6.mjs +68 -0
  7. package/dist/lib/browser/app-graph-builder-7VO7AUI6.mjs.map +7 -0
  8. package/dist/lib/browser/blueprint-definition-OSOUYI7A.mjs +17 -0
  9. package/dist/lib/browser/blueprint-definition-OSOUYI7A.mjs.map +7 -0
  10. package/dist/lib/browser/blueprints/index.mjs +8 -0
  11. package/dist/lib/browser/chunk-BTWHM6FH.mjs +270 -0
  12. package/dist/lib/browser/chunk-BTWHM6FH.mjs.map +7 -0
  13. package/dist/lib/browser/chunk-C53UJGSU.mjs +557 -0
  14. package/dist/lib/browser/chunk-C53UJGSU.mjs.map +7 -0
  15. package/dist/lib/browser/chunk-F3QKSKSF.mjs +35 -0
  16. package/dist/lib/browser/chunk-F3QKSKSF.mjs.map +7 -0
  17. package/dist/lib/browser/chunk-I7CSE6T3.mjs +110 -0
  18. package/dist/lib/browser/chunk-I7CSE6T3.mjs.map +7 -0
  19. package/dist/lib/browser/chunk-J5LGTIGS.mjs +10 -0
  20. package/dist/lib/browser/chunk-J5LGTIGS.mjs.map +7 -0
  21. package/dist/lib/browser/chunk-TWX2NMZN.mjs +137 -0
  22. package/dist/lib/browser/chunk-TWX2NMZN.mjs.map +7 -0
  23. package/dist/lib/browser/chunk-UUR4JNNB.mjs +113 -0
  24. package/dist/lib/browser/chunk-UUR4JNNB.mjs.map +7 -0
  25. package/dist/lib/browser/chunk-UX4GHJ5E.mjs +105 -0
  26. package/dist/lib/browser/chunk-UX4GHJ5E.mjs.map +7 -0
  27. package/dist/lib/browser/{chunk-QYAREHGH.mjs → chunk-WYR4QHPE.mjs} +8 -5
  28. package/dist/lib/browser/chunk-WYR4QHPE.mjs.map +7 -0
  29. package/dist/lib/browser/chunk-XCN4D3Z5.mjs +606 -0
  30. package/dist/lib/browser/chunk-XCN4D3Z5.mjs.map +7 -0
  31. package/dist/lib/browser/compiler-76F3QAXC.mjs +161 -0
  32. package/dist/lib/browser/compiler-76F3QAXC.mjs.map +7 -0
  33. package/dist/lib/browser/index.mjs +138 -103
  34. package/dist/lib/browser/index.mjs.map +4 -4
  35. package/dist/lib/browser/meta.json +1 -1
  36. package/dist/lib/browser/operation-resolver-HUILPPKT.mjs +82 -0
  37. package/dist/lib/browser/operation-resolver-HUILPPKT.mjs.map +7 -0
  38. package/dist/lib/browser/react-surface-O6GKHB2J.mjs +139 -0
  39. package/dist/lib/browser/react-surface-O6GKHB2J.mjs.map +7 -0
  40. package/dist/lib/browser/settings-3ENI25PI.mjs +35 -0
  41. package/dist/lib/browser/settings-3ENI25PI.mjs.map +7 -0
  42. package/dist/lib/browser/templates/index.mjs +2 -1
  43. package/dist/lib/browser/types/index.mjs +14 -6
  44. package/dist/lib/node-esm/DeploymentDialog-OGBJPVIX.mjs +15 -0
  45. package/dist/lib/node-esm/DeploymentDialog-OGBJPVIX.mjs.map +7 -0
  46. package/dist/lib/node-esm/NotebookContainer-IUAYVJSD.mjs +846 -0
  47. package/dist/lib/node-esm/NotebookContainer-IUAYVJSD.mjs.map +7 -0
  48. package/dist/lib/node-esm/ScriptContainer-K7JCEU5Z.mjs +150 -0
  49. package/dist/lib/node-esm/ScriptContainer-K7JCEU5Z.mjs.map +7 -0
  50. package/dist/lib/node-esm/app-graph-builder-NVE3EVBG.mjs +69 -0
  51. package/dist/lib/node-esm/app-graph-builder-NVE3EVBG.mjs.map +7 -0
  52. package/dist/lib/node-esm/blueprint-definition-NC7NNJGI.mjs +18 -0
  53. package/dist/lib/node-esm/blueprint-definition-NC7NNJGI.mjs.map +7 -0
  54. package/dist/lib/node-esm/blueprints/index.mjs +9 -0
  55. package/dist/lib/node-esm/blueprints/index.mjs.map +7 -0
  56. package/dist/lib/node-esm/chunk-4F5FJZ36.mjs +107 -0
  57. package/dist/lib/node-esm/chunk-4F5FJZ36.mjs.map +7 -0
  58. package/dist/lib/node-esm/chunk-4QNZMXW6.mjs +607 -0
  59. package/dist/lib/node-esm/chunk-4QNZMXW6.mjs.map +7 -0
  60. package/dist/lib/node-esm/{chunk-AHXJ6NQU.mjs → chunk-5HSJPAK7.mjs} +8 -5
  61. package/dist/lib/node-esm/chunk-5HSJPAK7.mjs.map +7 -0
  62. package/dist/lib/node-esm/chunk-BX5PP6AW.mjs +558 -0
  63. package/dist/lib/node-esm/chunk-BX5PP6AW.mjs.map +7 -0
  64. package/dist/lib/node-esm/chunk-G3J76DWP.mjs +114 -0
  65. package/dist/lib/node-esm/chunk-G3J76DWP.mjs.map +7 -0
  66. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +11 -0
  67. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +7 -0
  68. package/dist/lib/node-esm/chunk-SLU3KRV3.mjs +112 -0
  69. package/dist/lib/node-esm/chunk-SLU3KRV3.mjs.map +7 -0
  70. package/dist/lib/node-esm/chunk-VQPIA4VF.mjs +138 -0
  71. package/dist/lib/node-esm/chunk-VQPIA4VF.mjs.map +7 -0
  72. package/dist/lib/node-esm/chunk-VWOLKNMO.mjs +271 -0
  73. package/dist/lib/node-esm/chunk-VWOLKNMO.mjs.map +7 -0
  74. package/dist/lib/node-esm/chunk-Y3G5NCTP.mjs +36 -0
  75. package/dist/lib/node-esm/chunk-Y3G5NCTP.mjs.map +7 -0
  76. package/dist/lib/node-esm/compiler-FNZH6TFN.mjs +162 -0
  77. package/dist/lib/node-esm/compiler-FNZH6TFN.mjs.map +7 -0
  78. package/dist/lib/node-esm/index.mjs +138 -103
  79. package/dist/lib/node-esm/index.mjs.map +4 -4
  80. package/dist/lib/node-esm/meta.json +1 -1
  81. package/dist/lib/node-esm/operation-resolver-JTCIY6HU.mjs +83 -0
  82. package/dist/lib/node-esm/operation-resolver-JTCIY6HU.mjs.map +7 -0
  83. package/dist/lib/node-esm/react-surface-RLANMVMB.mjs +140 -0
  84. package/dist/lib/node-esm/react-surface-RLANMVMB.mjs.map +7 -0
  85. package/dist/lib/node-esm/settings-7AYC5VXN.mjs +36 -0
  86. package/dist/lib/node-esm/settings-7AYC5VXN.mjs.map +7 -0
  87. package/dist/lib/node-esm/templates/index.mjs +2 -1
  88. package/dist/lib/node-esm/types/index.mjs +14 -6
  89. package/dist/types/src/ScriptPlugin.d.ts +2 -1
  90. package/dist/types/src/ScriptPlugin.d.ts.map +1 -1
  91. package/dist/types/src/blueprints/index.d.ts +2 -0
  92. package/dist/types/src/blueprints/index.d.ts.map +1 -0
  93. package/dist/types/src/blueprints/script-blueprint.d.ts +22 -0
  94. package/dist/types/src/blueprints/script-blueprint.d.ts.map +1 -0
  95. package/dist/types/src/capabilities/app-graph-builder/app-graph-builder.d.ts +6 -0
  96. package/dist/types/src/capabilities/app-graph-builder/app-graph-builder.d.ts.map +1 -0
  97. package/dist/types/src/capabilities/app-graph-builder/index.d.ts +3 -0
  98. package/dist/types/src/capabilities/app-graph-builder/index.d.ts.map +1 -0
  99. package/dist/types/src/capabilities/artifact-definition/artifact-definition.d.ts +12 -0
  100. package/dist/types/src/capabilities/artifact-definition/artifact-definition.d.ts.map +1 -0
  101. package/dist/types/src/capabilities/artifact-definition/index.d.ts +3 -0
  102. package/dist/types/src/capabilities/artifact-definition/index.d.ts.map +1 -0
  103. package/dist/types/src/capabilities/blueprint-definition/blueprint-definition.d.ts +9 -0
  104. package/dist/types/src/capabilities/blueprint-definition/blueprint-definition.d.ts.map +1 -0
  105. package/dist/types/src/capabilities/blueprint-definition/index.d.ts +3 -0
  106. package/dist/types/src/capabilities/blueprint-definition/index.d.ts.map +1 -0
  107. package/dist/types/src/capabilities/compiler/compiler.d.ts +6 -0
  108. package/dist/types/src/capabilities/compiler/compiler.d.ts.map +1 -0
  109. package/dist/types/src/capabilities/compiler/index.d.ts +3 -0
  110. package/dist/types/src/capabilities/compiler/index.d.ts.map +1 -0
  111. package/dist/types/src/capabilities/index.d.ts +6 -7
  112. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  113. package/dist/types/src/capabilities/operation-resolver/index.d.ts +3 -0
  114. package/dist/types/src/capabilities/operation-resolver/index.d.ts.map +1 -0
  115. package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts +5 -0
  116. package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts.map +1 -0
  117. package/dist/types/src/capabilities/react-surface/index.d.ts +3 -0
  118. package/dist/types/src/capabilities/react-surface/index.d.ts.map +1 -0
  119. package/dist/types/src/capabilities/react-surface/react-surface.d.ts +5 -0
  120. package/dist/types/src/capabilities/react-surface/react-surface.d.ts.map +1 -0
  121. package/dist/types/src/capabilities/settings/index.d.ts +7 -0
  122. package/dist/types/src/capabilities/settings/index.d.ts.map +1 -0
  123. package/dist/types/src/capabilities/settings/settings.d.ts +9 -0
  124. package/dist/types/src/capabilities/settings/settings.d.ts.map +1 -0
  125. package/dist/types/src/compiler/compiler.d.ts +1 -1
  126. package/dist/types/src/compiler/compiler.d.ts.map +1 -1
  127. package/dist/types/src/components/DeploymentDialog/DeploymentDialog.d.ts +4 -4
  128. package/dist/types/src/components/DeploymentDialog/DeploymentDialog.d.ts.map +1 -1
  129. package/dist/types/src/components/DeploymentDialog/DeploymentDialog.stories.d.ts +244 -13
  130. package/dist/types/src/components/DeploymentDialog/DeploymentDialog.stories.d.ts.map +1 -1
  131. package/dist/types/src/components/DeploymentDialog/index.d.ts +1 -1
  132. package/dist/types/src/components/DeploymentDialog/index.d.ts.map +1 -1
  133. package/dist/types/src/components/FrameContainer/FrameContainer.d.ts +1 -1
  134. package/dist/types/src/components/FrameContainer/FrameContainer.d.ts.map +1 -1
  135. package/dist/types/src/components/NotebookContainer.d.ts +8 -0
  136. package/dist/types/src/components/NotebookContainer.d.ts.map +1 -0
  137. package/dist/types/src/components/NotebookContainer.stories.d.ts +7 -0
  138. package/dist/types/src/components/NotebookContainer.stories.d.ts.map +1 -0
  139. package/dist/types/src/components/NotebookStack/NotebookCell.d.ts +15 -0
  140. package/dist/types/src/components/NotebookStack/NotebookCell.d.ts.map +1 -0
  141. package/dist/types/src/components/NotebookStack/NotebookMenu.d.ts +9 -0
  142. package/dist/types/src/components/NotebookStack/NotebookMenu.d.ts.map +1 -0
  143. package/dist/types/src/components/NotebookStack/NotebookStack.d.ts +14 -0
  144. package/dist/types/src/components/NotebookStack/NotebookStack.d.ts.map +1 -0
  145. package/dist/types/src/components/NotebookStack/NotebookStack.stories.d.ts +249 -0
  146. package/dist/types/src/components/NotebookStack/NotebookStack.stories.d.ts.map +1 -0
  147. package/dist/types/src/components/NotebookStack/index.d.ts +3 -0
  148. package/dist/types/src/components/NotebookStack/index.d.ts.map +1 -0
  149. package/dist/types/src/components/QueryEditor/QueryEditor.d.ts +5 -0
  150. package/dist/types/src/components/QueryEditor/QueryEditor.d.ts.map +1 -0
  151. package/dist/types/src/components/QueryEditor/QueryEditor.stories.d.ts +13 -0
  152. package/dist/types/src/components/QueryEditor/QueryEditor.stories.d.ts.map +1 -0
  153. package/dist/types/src/components/QueryEditor/index.d.ts +2 -0
  154. package/dist/types/src/components/QueryEditor/index.d.ts.map +1 -0
  155. package/dist/types/src/components/ScriptContainer.d.ts +7 -8
  156. package/dist/types/src/components/ScriptContainer.d.ts.map +1 -1
  157. package/dist/types/src/components/ScriptToolbar/ScriptToolbar.d.ts +7 -8
  158. package/dist/types/src/components/ScriptToolbar/ScriptToolbar.d.ts.map +1 -1
  159. package/dist/types/src/components/ScriptToolbar/ScriptToolbar.stories.d.ts +246 -10
  160. package/dist/types/src/components/ScriptToolbar/ScriptToolbar.stories.d.ts.map +1 -1
  161. package/dist/types/src/components/Settings/ScriptObjectSettings.d.ts +2 -2
  162. package/dist/types/src/components/Settings/ScriptObjectSettings.d.ts.map +1 -1
  163. package/dist/types/src/components/Settings/ScriptPluginSettings.d.ts +6 -4
  164. package/dist/types/src/components/Settings/ScriptPluginSettings.d.ts.map +1 -1
  165. package/dist/types/src/components/TestPanel/TestContainer.d.ts +3 -3
  166. package/dist/types/src/components/TestPanel/TestContainer.d.ts.map +1 -1
  167. package/dist/types/src/components/TestPanel/TestPanel.d.ts.map +1 -1
  168. package/dist/types/src/components/TypescriptEditor/TypescriptEditor.d.ts +5 -2
  169. package/dist/types/src/components/TypescriptEditor/TypescriptEditor.d.ts.map +1 -1
  170. package/dist/types/src/components/TypescriptEditor/TypescriptEditor.stories.d.ts +11 -4
  171. package/dist/types/src/components/TypescriptEditor/TypescriptEditor.stories.d.ts.map +1 -1
  172. package/dist/types/src/components/index.d.ts +4 -5
  173. package/dist/types/src/components/index.d.ts.map +1 -1
  174. package/dist/types/src/e2e/ai.test.d.ts +2 -0
  175. package/dist/types/src/e2e/ai.test.d.ts.map +1 -0
  176. package/dist/types/src/e2e/deploy.test.d.ts +2 -0
  177. package/dist/types/src/e2e/deploy.test.d.ts.map +1 -0
  178. package/dist/types/src/hooks/deploy.d.ts +18 -32
  179. package/dist/types/src/hooks/deploy.d.ts.map +1 -1
  180. package/dist/types/src/hooks/format.d.ts +4 -4
  181. package/dist/types/src/hooks/format.d.ts.map +1 -1
  182. package/dist/types/src/hooks/index.d.ts +1 -0
  183. package/dist/types/src/hooks/index.d.ts.map +1 -1
  184. package/dist/types/src/hooks/template.d.ts +6 -16
  185. package/dist/types/src/hooks/template.d.ts.map +1 -1
  186. package/dist/types/src/hooks/useCompiler.d.ts +7 -0
  187. package/dist/types/src/hooks/useCompiler.d.ts.map +1 -0
  188. package/dist/types/src/hooks/useCreateAndDeployScriptTemplates.d.ts.map +1 -1
  189. package/dist/types/src/hooks/useToolbarState.d.ts +8 -1
  190. package/dist/types/src/hooks/useToolbarState.d.ts.map +1 -1
  191. package/dist/types/src/index.d.ts +2 -1
  192. package/dist/types/src/index.d.ts.map +1 -1
  193. package/dist/types/src/meta.d.ts +2 -3
  194. package/dist/types/src/meta.d.ts.map +1 -1
  195. package/dist/types/src/notebook/compute-graph.d.ts +58 -0
  196. package/dist/types/src/notebook/compute-graph.d.ts.map +1 -0
  197. package/dist/types/src/notebook/compute-graph.test.d.ts +2 -0
  198. package/dist/types/src/notebook/compute-graph.test.d.ts.map +1 -0
  199. package/dist/types/src/notebook/eval.d.ts +13 -0
  200. package/dist/types/src/notebook/eval.d.ts.map +1 -0
  201. package/dist/types/src/notebook/index.d.ts +2 -0
  202. package/dist/types/src/notebook/index.d.ts.map +1 -0
  203. package/dist/types/src/notebook/vfs-parser.d.ts +74 -0
  204. package/dist/types/src/notebook/vfs-parser.d.ts.map +1 -0
  205. package/dist/types/src/notebook/vfs-parser.test.d.ts +2 -0
  206. package/dist/types/src/notebook/vfs-parser.test.d.ts.map +1 -0
  207. package/dist/types/src/templates/anthropic.d.ts +8 -0
  208. package/dist/types/src/templates/anthropic.d.ts.map +1 -0
  209. package/dist/types/src/templates/chess-bot.d.ts +16 -0
  210. package/dist/types/src/templates/chess-bot.d.ts.map +1 -0
  211. package/dist/types/src/templates/commentary.d.ts +16 -0
  212. package/dist/types/src/templates/commentary.d.ts.map +1 -0
  213. package/dist/types/src/templates/data-generator.d.ts.map +1 -1
  214. package/dist/types/src/templates/discord.d.ts.map +1 -1
  215. package/dist/types/src/templates/forex-effect.d.ts +4 -1
  216. package/dist/types/src/templates/forex-effect.d.ts.map +1 -1
  217. package/dist/types/src/templates/forex.d.ts +4 -1
  218. package/dist/types/src/templates/forex.d.ts.map +1 -1
  219. package/dist/types/src/templates/gmail.d.ts.map +1 -1
  220. package/dist/types/src/templates/index.d.ts +52 -1
  221. package/dist/types/src/templates/index.d.ts.map +1 -1
  222. package/dist/types/src/templates/ping.d.ts +3 -0
  223. package/dist/types/src/templates/ping.d.ts.map +1 -0
  224. package/dist/types/src/testing/data.d.ts +3 -0
  225. package/dist/types/src/testing/data.d.ts.map +1 -0
  226. package/dist/types/src/testing/index.d.ts +2 -0
  227. package/dist/types/src/testing/index.d.ts.map +1 -0
  228. package/dist/types/src/testing/simulator.test.d.ts +2 -0
  229. package/dist/types/src/testing/simulator.test.d.ts.map +1 -0
  230. package/dist/types/src/translations.d.ts +32 -5
  231. package/dist/types/src/translations.d.ts.map +1 -1
  232. package/dist/types/src/types/Notebook.d.ts +100 -0
  233. package/dist/types/src/types/Notebook.d.ts.map +1 -0
  234. package/dist/types/src/types/actions.d.ts +40 -0
  235. package/dist/types/src/types/actions.d.ts.map +1 -0
  236. package/dist/types/src/types/capabilities.d.ts +12 -0
  237. package/dist/types/src/types/capabilities.d.ts.map +1 -0
  238. package/dist/types/src/types/events.d.ts +5 -0
  239. package/dist/types/src/types/events.d.ts.map +1 -0
  240. package/dist/types/src/types/index.d.ts +5 -1
  241. package/dist/types/src/types/index.d.ts.map +1 -1
  242. package/dist/types/src/types/types.d.ts +6 -0
  243. package/dist/types/src/types/types.d.ts.map +1 -0
  244. package/dist/types/src/util/deploy.d.ts +7 -7
  245. package/dist/types/src/util/deploy.d.ts.map +1 -1
  246. package/dist/types/src/util/functions.d.ts +6 -3
  247. package/dist/types/src/util/functions.d.ts.map +1 -1
  248. package/dist/types/tsconfig.tsbuildinfo +1 -1
  249. package/package.json +120 -85
  250. package/src/ScriptPlugin.tsx +56 -76
  251. package/src/blueprints/index.ts +5 -0
  252. package/src/blueprints/script-blueprint.ts +24 -0
  253. package/src/capabilities/app-graph-builder/app-graph-builder.ts +55 -0
  254. package/src/capabilities/app-graph-builder/index.ts +7 -0
  255. package/src/capabilities/{artifact-definition.ts → artifact-definition/artifact-definition.ts} +103 -98
  256. package/src/capabilities/artifact-definition/index.ts +7 -0
  257. package/src/capabilities/blueprint-definition/blueprint-definition.ts +23 -0
  258. package/src/capabilities/blueprint-definition/index.ts +7 -0
  259. package/src/capabilities/compiler/compiler.ts +103 -0
  260. package/src/capabilities/compiler/index.ts +7 -0
  261. package/src/capabilities/index.ts +6 -10
  262. package/src/capabilities/operation-resolver/index.ts +7 -0
  263. package/src/capabilities/operation-resolver/operation-resolver.ts +74 -0
  264. package/src/capabilities/react-surface/index.ts +7 -0
  265. package/src/capabilities/react-surface/react-surface.tsx +118 -0
  266. package/src/capabilities/settings/index.ts +7 -0
  267. package/src/capabilities/settings/settings.ts +32 -0
  268. package/src/compiler/compiler.ts +11 -4
  269. package/src/components/DeploymentDialog/DeploymentDialog.stories.tsx +45 -22
  270. package/src/components/DeploymentDialog/DeploymentDialog.tsx +45 -54
  271. package/src/components/DeploymentDialog/index.ts +1 -1
  272. package/src/components/FrameContainer/FrameContainer.tsx +8 -5
  273. package/src/components/NotebookContainer.stories.tsx +87 -0
  274. package/src/components/NotebookContainer.tsx +271 -0
  275. package/src/components/NotebookStack/NotebookCell.tsx +217 -0
  276. package/src/components/NotebookStack/NotebookMenu.tsx +47 -0
  277. package/src/components/NotebookStack/NotebookStack.stories.tsx +55 -0
  278. package/src/components/NotebookStack/NotebookStack.tsx +86 -0
  279. package/src/components/NotebookStack/index.ts +6 -0
  280. package/src/components/QueryEditor/QueryEditor.stories.tsx +100 -0
  281. package/src/components/QueryEditor/QueryEditor.tsx +47 -0
  282. package/src/components/QueryEditor/index.ts +5 -0
  283. package/src/components/ScriptContainer.tsx +52 -36
  284. package/src/components/ScriptToolbar/ScriptToolbar.stories.tsx +57 -17
  285. package/src/components/ScriptToolbar/ScriptToolbar.tsx +37 -33
  286. package/src/components/Settings/ScriptObjectSettings.tsx +151 -48
  287. package/src/components/Settings/ScriptPluginSettings.tsx +43 -48
  288. package/src/components/TestPanel/TestContainer.tsx +9 -8
  289. package/src/components/TestPanel/TestPanel.tsx +43 -20
  290. package/src/components/TypescriptEditor/TypescriptEditor.stories.tsx +86 -33
  291. package/src/components/TypescriptEditor/TypescriptEditor.tsx +84 -81
  292. package/src/components/index.ts +3 -0
  293. package/src/e2e/ai.test.ts +92 -0
  294. package/src/e2e/deploy.test.ts +64 -0
  295. package/src/hooks/deploy.ts +49 -42
  296. package/src/hooks/format.ts +9 -5
  297. package/src/hooks/index.ts +1 -0
  298. package/src/hooks/template.ts +20 -23
  299. package/src/hooks/useCompiler.ts +24 -0
  300. package/src/hooks/useCreateAndDeployScriptTemplates.ts +15 -16
  301. package/src/hooks/useToolbarState.ts +29 -5
  302. package/src/index.ts +2 -1
  303. package/src/meta.ts +9 -7
  304. package/src/notebook/compute-graph.test.ts +82 -0
  305. package/src/notebook/compute-graph.ts +230 -0
  306. package/src/notebook/eval.ts +105 -0
  307. package/src/notebook/index.ts +5 -0
  308. package/src/notebook/vfs-parser.test.ts +149 -0
  309. package/src/notebook/vfs-parser.ts +451 -0
  310. package/src/templates/anthropic.ts +42 -0
  311. package/src/templates/chess-bot.ts +58 -0
  312. package/src/templates/commentary.ts +232 -0
  313. package/src/templates/data-generator.ts +10 -4
  314. package/src/templates/discord.ts +12 -4
  315. package/src/templates/forex-effect.ts +24 -25
  316. package/src/templates/forex.ts +9 -6
  317. package/src/templates/gmail.ts +34 -64
  318. package/src/templates/index.ts +24 -11
  319. package/src/templates/ping.ts +17 -0
  320. package/src/testing/data.ts +72 -0
  321. package/src/testing/index.ts +5 -0
  322. package/src/testing/simulator.test.ts +40 -0
  323. package/src/translations.ts +35 -7
  324. package/src/types/Notebook.ts +41 -0
  325. package/src/types/actions.ts +45 -0
  326. package/src/types/capabilities.ts +17 -0
  327. package/src/types/events.ts +11 -0
  328. package/src/types/index.ts +5 -1
  329. package/src/types/types.ts +15 -0
  330. package/src/util/deploy.ts +38 -61
  331. package/src/util/functions.ts +58 -25
  332. package/src/vite-env.d.ts +2 -0
  333. package/dist/lib/browser/DeploymentDialog-M4QIHTDR.mjs +0 -12
  334. package/dist/lib/browser/ScriptContainer-Z6SIGRRC.mjs +0 -262
  335. package/dist/lib/browser/ScriptContainer-Z6SIGRRC.mjs.map +0 -7
  336. package/dist/lib/browser/app-graph-builder-HLQ7K3BT.mjs +0 -64
  337. package/dist/lib/browser/app-graph-builder-HLQ7K3BT.mjs.map +0 -7
  338. package/dist/lib/browser/artifact-definition-CK3BIBSI.mjs +0 -247
  339. package/dist/lib/browser/artifact-definition-CK3BIBSI.mjs.map +0 -7
  340. package/dist/lib/browser/chunk-3U6DTUH3.mjs +0 -283
  341. package/dist/lib/browser/chunk-3U6DTUH3.mjs.map +0 -7
  342. package/dist/lib/browser/chunk-5TVBECWH.mjs +0 -15
  343. package/dist/lib/browser/chunk-5TVBECWH.mjs.map +0 -7
  344. package/dist/lib/browser/chunk-FIM2MVNJ.mjs +0 -555
  345. package/dist/lib/browser/chunk-FIM2MVNJ.mjs.map +0 -7
  346. package/dist/lib/browser/chunk-FMDXKOP7.mjs +0 -233
  347. package/dist/lib/browser/chunk-FMDXKOP7.mjs.map +0 -7
  348. package/dist/lib/browser/chunk-IS4OG2UW.mjs +0 -39
  349. package/dist/lib/browser/chunk-IS4OG2UW.mjs.map +0 -7
  350. package/dist/lib/browser/chunk-P4HQKUCP.mjs +0 -153
  351. package/dist/lib/browser/chunk-P4HQKUCP.mjs.map +0 -7
  352. package/dist/lib/browser/chunk-QYAREHGH.mjs.map +0 -7
  353. package/dist/lib/browser/chunk-R4R7VOFY.mjs +0 -88
  354. package/dist/lib/browser/chunk-R4R7VOFY.mjs.map +0 -7
  355. package/dist/lib/browser/compiler-CXCUA4UQ.mjs +0 -82
  356. package/dist/lib/browser/compiler-CXCUA4UQ.mjs.map +0 -7
  357. package/dist/lib/browser/intent-resolver-S3H2SMUY.mjs +0 -89
  358. package/dist/lib/browser/intent-resolver-S3H2SMUY.mjs.map +0 -7
  359. package/dist/lib/browser/react-surface-FYYXZA7C.mjs +0 -104
  360. package/dist/lib/browser/react-surface-FYYXZA7C.mjs.map +0 -7
  361. package/dist/lib/browser/settings-KCTBK5TY.mjs +0 -24
  362. package/dist/lib/browser/settings-KCTBK5TY.mjs.map +0 -7
  363. package/dist/lib/node-esm/DeploymentDialog-3KPRWFE7.mjs +0 -13
  364. package/dist/lib/node-esm/ScriptContainer-KPU75HHI.mjs +0 -263
  365. package/dist/lib/node-esm/ScriptContainer-KPU75HHI.mjs.map +0 -7
  366. package/dist/lib/node-esm/app-graph-builder-7EYIHWH4.mjs +0 -65
  367. package/dist/lib/node-esm/app-graph-builder-7EYIHWH4.mjs.map +0 -7
  368. package/dist/lib/node-esm/artifact-definition-YCBV4YX2.mjs +0 -248
  369. package/dist/lib/node-esm/artifact-definition-YCBV4YX2.mjs.map +0 -7
  370. package/dist/lib/node-esm/chunk-35M3CHYE.mjs +0 -16
  371. package/dist/lib/node-esm/chunk-35M3CHYE.mjs.map +0 -7
  372. package/dist/lib/node-esm/chunk-7NMI4CEU.mjs +0 -556
  373. package/dist/lib/node-esm/chunk-7NMI4CEU.mjs.map +0 -7
  374. package/dist/lib/node-esm/chunk-AHXJ6NQU.mjs.map +0 -7
  375. package/dist/lib/node-esm/chunk-F5GFJ3PY.mjs +0 -90
  376. package/dist/lib/node-esm/chunk-F5GFJ3PY.mjs.map +0 -7
  377. package/dist/lib/node-esm/chunk-JIPFLBYA.mjs +0 -40
  378. package/dist/lib/node-esm/chunk-JIPFLBYA.mjs.map +0 -7
  379. package/dist/lib/node-esm/chunk-QKK3NDHW.mjs +0 -154
  380. package/dist/lib/node-esm/chunk-QKK3NDHW.mjs.map +0 -7
  381. package/dist/lib/node-esm/chunk-RT43MACC.mjs +0 -284
  382. package/dist/lib/node-esm/chunk-RT43MACC.mjs.map +0 -7
  383. package/dist/lib/node-esm/chunk-XJPK3IYI.mjs +0 -234
  384. package/dist/lib/node-esm/chunk-XJPK3IYI.mjs.map +0 -7
  385. package/dist/lib/node-esm/compiler-EPFKQXPE.mjs +0 -83
  386. package/dist/lib/node-esm/compiler-EPFKQXPE.mjs.map +0 -7
  387. package/dist/lib/node-esm/intent-resolver-OHKNJFCC.mjs +0 -90
  388. package/dist/lib/node-esm/intent-resolver-OHKNJFCC.mjs.map +0 -7
  389. package/dist/lib/node-esm/react-surface-V32NWHKN.mjs +0 -105
  390. package/dist/lib/node-esm/react-surface-V32NWHKN.mjs.map +0 -7
  391. package/dist/lib/node-esm/settings-DXZ334A3.mjs +0 -25
  392. package/dist/lib/node-esm/settings-DXZ334A3.mjs.map +0 -7
  393. package/dist/types/src/capabilities/app-graph-builder.d.ts +0 -4
  394. package/dist/types/src/capabilities/app-graph-builder.d.ts.map +0 -1
  395. package/dist/types/src/capabilities/artifact-definition.d.ts +0 -11
  396. package/dist/types/src/capabilities/artifact-definition.d.ts.map +0 -1
  397. package/dist/types/src/capabilities/capabilities.d.ts +0 -5
  398. package/dist/types/src/capabilities/capabilities.d.ts.map +0 -1
  399. package/dist/types/src/capabilities/compiler.d.ts +0 -4
  400. package/dist/types/src/capabilities/compiler.d.ts.map +0 -1
  401. package/dist/types/src/capabilities/intent-resolver.d.ts +0 -4
  402. package/dist/types/src/capabilities/intent-resolver.d.ts.map +0 -1
  403. package/dist/types/src/capabilities/react-surface.d.ts +0 -4
  404. package/dist/types/src/capabilities/react-surface.d.ts.map +0 -1
  405. package/dist/types/src/capabilities/settings.d.ts +0 -4
  406. package/dist/types/src/capabilities/settings.d.ts.map +0 -1
  407. package/dist/types/src/events.d.ts +0 -4
  408. package/dist/types/src/events.d.ts.map +0 -1
  409. package/dist/types/src/templates/chess.d.ts +0 -3
  410. package/dist/types/src/templates/chess.d.ts.map +0 -1
  411. package/dist/types/src/templates/echo.d.ts +0 -6
  412. package/dist/types/src/templates/echo.d.ts.map +0 -1
  413. package/dist/types/src/types/schema.d.ts +0 -38
  414. package/dist/types/src/types/schema.d.ts.map +0 -1
  415. package/src/capabilities/app-graph-builder.ts +0 -64
  416. package/src/capabilities/capabilities.ts +0 -12
  417. package/src/capabilities/compiler.ts +0 -33
  418. package/src/capabilities/intent-resolver.ts +0 -77
  419. package/src/capabilities/react-surface.tsx +0 -89
  420. package/src/capabilities/settings.ts +0 -21
  421. package/src/events.ts +0 -11
  422. package/src/templates/chess.ts +0 -47
  423. package/src/templates/echo.ts +0 -8
  424. package/src/types/schema.ts +0 -37
  425. /package/dist/lib/browser/{DeploymentDialog-M4QIHTDR.mjs.map → DeploymentDialog-OSL6RMPA.mjs.map} +0 -0
  426. /package/dist/lib/{node-esm/DeploymentDialog-3KPRWFE7.mjs.map → browser/blueprints/index.mjs.map} +0 -0
@@ -6,15 +6,16 @@ import { format } from 'prettier';
6
6
  import prettierPluginEstree from 'prettier/plugins/estree';
7
7
  import prettierPluginTypescript from 'prettier/plugins/typescript';
8
8
 
9
- import { type ScriptType } from '@dxos/functions';
9
+ import { Obj } from '@dxos/echo';
10
+ import { type Script } from '@dxos/functions';
10
11
  import { log } from '@dxos/log';
11
12
  import { createMenuAction } from '@dxos/react-ui-menu';
12
13
 
13
- import { SCRIPT_PLUGIN } from '../meta';
14
+ import { meta } from '../meta';
14
15
 
15
16
  export type FormatActionProperties = { type: 'format' };
16
17
 
17
- export const createFormat = (script: ScriptType) => {
18
+ export const createFormat = (script: Script.Script) => {
18
19
  const formatAction = createMenuAction(
19
20
  'format',
20
21
  async () => {
@@ -23,19 +24,22 @@ export const createFormat = (script: ScriptType) => {
23
24
  }
24
25
 
25
26
  try {
26
- script.source.target!.content = await format(script.source.target!.content, {
27
+ const formatted = await format(script.source.target!.content, {
27
28
  parser: 'typescript',
28
29
  plugins: [prettierPluginEstree, prettierPluginTypescript],
29
30
  semi: true,
30
31
  singleQuote: true,
31
32
  });
33
+ Obj.change(script.source.target!, (s) => {
34
+ s.content = formatted;
35
+ });
32
36
  } catch (err: any) {
33
37
  // TODO(wittjosiah): Show error in UI.
34
38
  log.catch(err);
35
39
  }
36
40
  },
37
41
  {
38
- label: ['format label', { ns: SCRIPT_PLUGIN }],
42
+ label: ['format label', { ns: meta.id }],
39
43
  icon: 'ph--magic-wand--regular',
40
44
  },
41
45
  );
@@ -8,3 +8,4 @@ export * from './template';
8
8
 
9
9
  export * from './useCreateAndDeployScriptTemplates';
10
10
  export * from './useToolbarState';
11
+ export * from './useCompiler';
@@ -3,35 +3,33 @@
3
3
  //
4
4
 
5
5
  import { Obj } from '@dxos/echo';
6
- import { FUNCTIONS_PRESET_META_KEY, type ScriptType } from '@dxos/functions';
7
- import { createMenuItemGroup, createMenuAction } from '@dxos/react-ui-menu';
6
+ import { FUNCTIONS_PRESET_META_KEY, type Script } from '@dxos/functions';
7
+ import { createMenuAction } from '@dxos/react-ui-menu';
8
8
 
9
- import { SCRIPT_PLUGIN } from '../meta';
10
9
  import { templates } from '../templates';
11
10
 
12
11
  export type TemplateActionProperties = { type: 'template'; value: string };
13
12
 
14
- const createTemplateSelectGroup = () => {
15
- return createMenuItemGroup('template-select', {
16
- label: ['template select group label', { ns: SCRIPT_PLUGIN }],
17
- variant: 'dropdownMenu',
18
- });
19
- };
20
-
21
- const createTemplateSelectActions = (script: ScriptType) => {
13
+ const createTemplateSelectActions = (script: Script.Script) => {
22
14
  return templates.map((template) => {
23
15
  return createMenuAction<TemplateActionProperties>(
24
16
  `template--${template.id}`,
25
17
  () => {
26
- script.name = template.name;
27
- script.source!.target!.content = template.source;
28
- const metaKeys = Obj.getMeta(script).keys;
29
- const oldPresetIndex = metaKeys.findIndex((key) => key.source === FUNCTIONS_PRESET_META_KEY);
30
- if (oldPresetIndex >= 0) {
31
- metaKeys.splice(oldPresetIndex, 1);
32
- }
33
- if (template.presetId) {
34
- metaKeys.push({ source: FUNCTIONS_PRESET_META_KEY, id: template.presetId });
18
+ Obj.change(script, (s) => {
19
+ s.name = template.name;
20
+ const meta = Obj.getMeta(s);
21
+ const oldPresetIndex = meta.keys.findIndex((key) => key.source === FUNCTIONS_PRESET_META_KEY);
22
+ if (oldPresetIndex >= 0) {
23
+ meta.keys.splice(oldPresetIndex, 1);
24
+ }
25
+ if ('presetId' in template) {
26
+ meta.keys.push({ source: FUNCTIONS_PRESET_META_KEY, id: template.presetId });
27
+ }
28
+ });
29
+ if (script.source?.target) {
30
+ Obj.change(script.source.target, (s) => {
31
+ s.content = template.source;
32
+ });
35
33
  }
36
34
  },
37
35
  {
@@ -43,11 +41,10 @@ const createTemplateSelectActions = (script: ScriptType) => {
43
41
  });
44
42
  };
45
43
 
46
- export const createTemplateSelect = (script: ScriptType) => {
47
- const templateSelectGroup = createTemplateSelectGroup();
44
+ export const createTemplateSelect = (script: Script.Script) => {
48
45
  const templateSelectActions = createTemplateSelectActions(script);
49
46
  return {
50
- nodes: [templateSelectGroup, ...templateSelectActions],
47
+ nodes: [...templateSelectActions],
51
48
  edges: [
52
49
  { source: 'root', target: 'template-select' },
53
50
  ...templateSelectActions.map((action) => ({ source: 'template-select', target: action.id })),
@@ -0,0 +1,24 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { useCapabilities, usePluginManager } from '@dxos/app-framework/react';
6
+ import { runAndForwardErrors } from '@dxos/effect';
7
+ import { useAsyncEffect } from '@dxos/react-ui';
8
+
9
+ import type { Compiler } from '../compiler';
10
+ import { ScriptEvents } from '../types';
11
+ import { ScriptCapabilities } from '../types';
12
+
13
+ /**
14
+ * Asynchronously sets up the compiler and returns it.
15
+ * @returns The compiler instance or undefined if it is not ready.
16
+ */
17
+ export const useCompiler = (): Compiler | undefined => {
18
+ const manager = usePluginManager();
19
+ useAsyncEffect(async () => {
20
+ await manager.activate(ScriptEvents.SetupCompiler).pipe(runAndForwardErrors);
21
+ }, [manager]);
22
+ const [compiler] = useCapabilities(ScriptCapabilities.Compiler);
23
+ return compiler;
24
+ };
@@ -2,19 +2,18 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { pipe } from 'effect/Function';
6
5
  import { useCallback, useState } from 'react';
7
6
 
8
- import { chain, createIntent, useIntentDispatcher } from '@dxos/app-framework';
7
+ import { useOperationInvoker } from '@dxos/app-framework/react';
9
8
  import { Obj } from '@dxos/echo';
10
- import { ScriptType } from '@dxos/functions';
9
+ import { Script } from '@dxos/functions';
11
10
  import { invariant } from '@dxos/invariant';
12
- import { SpaceAction } from '@dxos/plugin-space/types';
11
+ import { SpaceOperation } from '@dxos/plugin-space/types';
13
12
  import { useClient } from '@dxos/react-client';
14
13
  import { type Space } from '@dxos/react-client/echo';
15
14
 
16
15
  import { type Template } from '../templates';
17
- import { ScriptAction } from '../types';
16
+ import { ScriptOperation } from '../types';
18
17
  import { deployScript } from '../util';
19
18
 
20
19
  type DeploymentStatus = 'idle' | 'pending' | 'success' | 'error';
@@ -27,7 +26,7 @@ type DeploymentStatus = 'idle' | 'pending' | 'success' | 'error';
27
26
  * All creation / deployment operations run concurrently for improved performance.
28
27
  */
29
28
  export const useCreateAndDeployScriptTemplates = (space: Space | undefined, scriptTemplates: Template[]) => {
30
- const { dispatchPromise: dispatch } = useIntentDispatcher();
29
+ const { invokePromise } = useOperationInvoker();
31
30
  const client = useClient();
32
31
  const [status, setStatus] = useState<DeploymentStatus>('idle');
33
32
  const [error, setError] = useState<Error | undefined>(undefined);
@@ -39,21 +38,21 @@ export const useCreateAndDeployScriptTemplates = (space: Space | undefined, scri
39
38
 
40
39
  const deploymentResults = await Promise.all(
41
40
  scriptTemplates.map(async (template) => {
42
- const result = await dispatch(
43
- pipe(
44
- createIntent(ScriptAction.Create, { space, initialTemplateId: template.id }),
45
- chain(SpaceAction.AddObject, { target: space }),
46
- ),
47
- );
48
- invariant(Obj.instanceOf(ScriptType, result.data?.object));
49
-
50
- return deployScript({ space, client, script: result.data.object });
41
+ const createResult = await invokePromise(ScriptOperation.CreateScript, {
42
+ db: space.db,
43
+ initialTemplateId: template.id as any,
44
+ });
45
+ invariant(Obj.instanceOf(Script.Script, createResult.data?.object));
46
+ await invokePromise(SpaceOperation.AddObject, { target: space.db, object: createResult.data.object });
47
+
48
+ return deployScript({ space, client, script: createResult.data.object });
51
49
  }),
52
50
  );
53
51
 
54
52
  const hasErrors = deploymentResults.some((result) => !result.success);
55
53
  setStatus(hasErrors ? 'error' : 'success');
56
- }, [space, dispatch, client, scriptTemplates]);
54
+ }, [space, invokePromise, client, scriptTemplates]);
57
55
 
56
+ // TODO(burdon): Return onCreateAndDeployScripts.
58
57
  return { handleCreateAndDeployScripts, status, error };
59
58
  };
@@ -2,15 +2,39 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { useMemo } from 'react';
6
-
7
- import { live } from '@dxos/live-object';
5
+ import { Atom, RegistryContext, useAtomValue } from '@effect-atom/atom-react';
6
+ import { useContext, useMemo } from 'react';
8
7
 
9
8
  import { type DeployState } from './deploy';
10
9
 
11
10
  export type ScriptToolbarState = Partial<DeployState>;
12
11
 
12
+ export type ScriptToolbarStateStore = {
13
+ atom: Atom.Writable<ScriptToolbarState>;
14
+ get value(): ScriptToolbarState;
15
+ update: (updater: (current: ScriptToolbarState) => ScriptToolbarState) => void;
16
+ set: <K extends keyof ScriptToolbarState>(key: K, value: ScriptToolbarState[K]) => void;
17
+ };
18
+
13
19
  // TODO(burdon): Replace with context provider?
14
- export const useToolbarState = (initialState: ScriptToolbarState = {}) => {
15
- return useMemo(() => live<ScriptToolbarState>(initialState), []);
20
+ export const useToolbarState = (initialState: ScriptToolbarState = {}): ScriptToolbarStateStore => {
21
+ const registry = useContext(RegistryContext);
22
+ const atom = useMemo(() => Atom.make<ScriptToolbarState>(initialState), []);
23
+ const value = useAtomValue(atom);
24
+
25
+ return useMemo(
26
+ () => ({
27
+ atom,
28
+ get value() {
29
+ return registry.get(atom);
30
+ },
31
+ update: (updater: (current: ScriptToolbarState) => ScriptToolbarState) => {
32
+ registry.set(atom, updater(registry.get(atom)));
33
+ },
34
+ set: <K extends keyof ScriptToolbarState>(key: K, v: ScriptToolbarState[K]) => {
35
+ registry.set(atom, { ...registry.get(atom), [key]: v });
36
+ },
37
+ }),
38
+ [atom, registry, value],
39
+ );
16
40
  };
package/src/index.ts CHANGED
@@ -2,8 +2,9 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- export { ScriptCapabilities } from './capabilities';
5
+ export { ScriptCapabilities, ScriptEvents } from './types';
6
6
  export * from './components';
7
7
  export * from './meta';
8
+ export * from './util';
8
9
 
9
10
  export * from './ScriptPlugin';
package/src/meta.ts CHANGED
@@ -2,16 +2,18 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import { type PluginMeta } from '@dxos/app-framework';
5
+ import { type Plugin } from '@dxos/app-framework';
6
+ import { trim } from '@dxos/util';
6
7
 
7
- export const SCRIPT_PLUGIN = 'dxos.org/plugin/script';
8
-
9
- export const meta: PluginMeta = {
10
- id: SCRIPT_PLUGIN,
8
+ export const meta: Plugin.Meta = {
9
+ id: 'dxos.org/plugin/script',
11
10
  name: 'Scripts',
12
- description:
13
- 'Scripts in Composer allow you to deploy custom functions that run on the edge. These functions can be referenced by your AI agent and called inside of cells in any Sheet. Use scripts to interact with API’s or external data inside of Composer.',
11
+ description: trim`
12
+ Write and deploy custom JavaScript functions that extend your workspace capabilities.
13
+ Create AI agent tools, spreadsheet formulas, and automation scripts that integrate seamlessly with other plugins.
14
+ `,
14
15
  icon: 'ph--code--regular',
16
+ iconHue: 'sky',
15
17
  source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-explorer',
16
18
  tags: ['labs'],
17
19
  screenshots: ['https://dxos.network/plugin-details-scripts-dark.png'],
@@ -0,0 +1,82 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { Registry } from '@effect-atom/atom-react';
6
+ import { describe, expect, test } from 'vitest';
7
+
8
+ import { Obj } from '@dxos/echo';
9
+
10
+ import { createNotebook } from '../testing';
11
+
12
+ import { ComputeGraph } from './compute-graph';
13
+
14
+ describe('notebook', () => {
15
+ test('parse dependency graph', async () => {
16
+ const registry = Registry.make();
17
+ const notebook = createNotebook();
18
+ const graph = new ComputeGraph(notebook, registry);
19
+ const result = graph.parse();
20
+
21
+ const getId = (i: number) => notebook.cells[i].id;
22
+
23
+ // Check dependencies.
24
+ expect(result.dependencyGraph).toMatchObject({
25
+ [getId(0)]: [getId(1), getId(2)],
26
+ [getId(3)]: [getId(1)],
27
+ [getId(4)]: [getId(0), getId(3)],
28
+ });
29
+
30
+ // Compute values.
31
+ const values = await graph.evaluate();
32
+ expect(values).toEqual({
33
+ [getId(0)]: 300,
34
+ [getId(2)]: 200,
35
+ [getId(3)]: 200,
36
+ [getId(4)]: 500,
37
+ });
38
+ });
39
+
40
+ test('evalScript blocks access to window and document', async () => {
41
+ const registry = Registry.make();
42
+ const notebook = createNotebook();
43
+ // Replace one of the cells with code that tries to access window/document.
44
+ const sourceTarget = notebook.cells[2].source?.target;
45
+ if (sourceTarget) {
46
+ Obj.change(sourceTarget, (t) => {
47
+ t.content = 'b = typeof window';
48
+ });
49
+ }
50
+
51
+ const graph = new ComputeGraph(notebook, registry);
52
+ graph.parse();
53
+ const values = await graph.evaluate();
54
+
55
+ // Should evaluate to 'undefined' since window is blocked.
56
+ expect(values[notebook.cells[2].id]).toBe('undefined');
57
+
58
+ // Test document access.
59
+ if (sourceTarget) {
60
+ Obj.change(sourceTarget, (t) => {
61
+ t.content = 'b = typeof document';
62
+ });
63
+ }
64
+ graph.parse();
65
+ const values2 = await graph.evaluate();
66
+
67
+ // Should evaluate to 'undefined' since document is blocked.
68
+ expect(values2[notebook.cells[2].id]).toBe('undefined');
69
+
70
+ // Test that safe globals still work.
71
+ if (sourceTarget) {
72
+ Obj.change(sourceTarget, (t) => {
73
+ t.content = 'b = Math.max(100, 200)';
74
+ });
75
+ }
76
+ graph.parse();
77
+ const values3 = await graph.evaluate();
78
+
79
+ // Should evaluate correctly.
80
+ expect(values3[notebook.cells[2].id]).toBe(200);
81
+ });
82
+ });
@@ -0,0 +1,230 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { Atom, type Registry } from '@effect-atom/atom-react';
6
+
7
+ import { log } from '@dxos/log';
8
+
9
+ import { type Notebook } from '../types';
10
+
11
+ import { evalScript } from './eval';
12
+ import { type ParsedExpression, VirtualTypeScriptParser } from './vfs-parser';
13
+
14
+ /**
15
+ * Compute graph that evaluates the notebook cells.
16
+ */
17
+ // TODO(burdon): Reconcile with @dxos/conductor.
18
+ export class ComputeGraph {
19
+ private readonly _parser = new VirtualTypeScriptParser();
20
+
21
+ private _expressionsAtom = Atom.make<Record<string, ParsedExpression>>({});
22
+ private _valuesByCellIdAtom = Atom.make<Record<string, any>>({});
23
+ private _valuesByNameAtom = Atom.make<Record<string, any>>({});
24
+
25
+ constructor(
26
+ private readonly _notebook: Notebook.Notebook,
27
+ private readonly _registry: Registry.Registry,
28
+ ) {}
29
+
30
+ /**
31
+ * Atom for parsed expressions by cell ID.
32
+ */
33
+ get expressions(): Atom.Atom<Record<string, ParsedExpression>> {
34
+ return this._expressionsAtom;
35
+ }
36
+
37
+ /**
38
+ * Get current expressions by cell ID.
39
+ */
40
+ getExpressions(): Record<string, ParsedExpression> {
41
+ return this._registry.get(this._expressionsAtom);
42
+ }
43
+
44
+ /**
45
+ * Atom for computed values by cell ID.
46
+ */
47
+ get values(): Atom.Atom<Record<string, any>> {
48
+ return this._valuesByCellIdAtom;
49
+ }
50
+
51
+ /**
52
+ * Get computed values by cell ID.
53
+ */
54
+ getValues(): Record<string, any> {
55
+ return this._registry.get(this._valuesByCellIdAtom);
56
+ }
57
+
58
+ /**
59
+ * Atom for computed values by name.
60
+ */
61
+ get valuesByName(): Atom.Atom<Record<string, any>> {
62
+ return this._valuesByNameAtom;
63
+ }
64
+
65
+ /**
66
+ * Get current values by name.
67
+ */
68
+ getValuesByName(): Record<string, any> {
69
+ return this._registry.get(this._valuesByNameAtom);
70
+ }
71
+
72
+ /**
73
+ * Get computed value by cell ID.
74
+ */
75
+ getValue(cellId: string): any {
76
+ return this._registry.get(this._valuesByCellIdAtom)[cellId];
77
+ }
78
+
79
+ /**
80
+ * Compute values.
81
+ */
82
+ async evaluate() {
83
+ // Parse expressions.
84
+ const { expressions, dependencyGraph } = this.parse();
85
+ this._registry.set(this._valuesByCellIdAtom, {});
86
+ this._registry.set(this._valuesByNameAtom, {});
87
+
88
+ // Create a map of cell IDs to expressions for easy lookup.
89
+ const cellExpressions = new Map<string, ParsedExpression>();
90
+ Object.entries(expressions).forEach(([id, expr]) => {
91
+ cellExpressions.set(id, expr);
92
+ });
93
+
94
+ // Topological sort to determine evaluation order.
95
+ const evaluationOrder = this.topologicalSort(Object.keys(expressions), dependencyGraph);
96
+
97
+ // Values by reference name.
98
+ const valuesByName: Record<string, any> = {};
99
+ const valuesByCellId: Record<string, any> = {};
100
+
101
+ // Evaluate cells in dependency order.
102
+ for (const cellId of evaluationOrder) {
103
+ const expr = cellExpressions.get(cellId);
104
+ if (!expr) {
105
+ log.error('no expression for cell', { cellId });
106
+ continue;
107
+ }
108
+
109
+ const cellSource = this._notebook.cells.find((cell) => cell.id === cellId)?.source?.target?.content;
110
+ if (!cellSource) {
111
+ log.error('no source for cell', { cellId });
112
+ continue;
113
+ }
114
+
115
+ try {
116
+ // For assignments or declarations, evaluate and store the value.
117
+ if (expr.name && expr.value !== undefined) {
118
+ // If the parser extracted a literal value, use it directly.
119
+ valuesByName[expr.name] = expr.value;
120
+ valuesByCellId[cellId] = expr.value;
121
+ } else if (expr.name) {
122
+ // For non-literal assignments, we need to evaluate the expression.
123
+ // The parser identifies it's an assignment, so we can extract the RHS.
124
+ const equalIndex = cellSource.indexOf('=');
125
+ if (equalIndex !== -1) {
126
+ // Find the actual assignment operator (not in strings or other contexts).
127
+ let rhs = cellSource.substring(equalIndex + 1).trim();
128
+
129
+ // Handle semicolon at the end.
130
+ if (rhs.endsWith(';')) {
131
+ rhs = rhs.slice(0, -1).trim();
132
+ }
133
+
134
+ const result = await this.eval(rhs, valuesByName);
135
+ valuesByName[expr.name] = result;
136
+ if (typeof result !== 'function') {
137
+ valuesByCellId[cellId] = result;
138
+ }
139
+ }
140
+ } else {
141
+ // For expressions without assignment, just evaluate.
142
+ const result = await this.eval(cellSource, valuesByName);
143
+ valuesByCellId[cellId] = result;
144
+ }
145
+ } catch (error) {
146
+ // TODO(burdon): Set error state.
147
+ log.error('error evaluating cell', { cellId, error });
148
+ }
149
+ }
150
+
151
+ this._registry.set(this._valuesByCellIdAtom, valuesByCellId);
152
+ this._registry.set(this._valuesByNameAtom, valuesByName);
153
+ return valuesByCellId;
154
+ }
155
+
156
+ private async eval(source: string, values: Record<string, any>) {
157
+ return evalScript(source, values);
158
+ }
159
+
160
+ /**
161
+ * Parse expressions.
162
+ */
163
+ parse() {
164
+ const expressions = this._notebook.cells
165
+ .filter((cell) => cell.type === 'script')
166
+ .reduce<Record<string, ParsedExpression>>((acc, cell) => {
167
+ const text = cell.source?.target?.content.trim();
168
+ if (text) {
169
+ const parsed = this._parser.parseExpression(text);
170
+ acc[cell.id] = parsed;
171
+ }
172
+
173
+ return acc;
174
+ }, {});
175
+
176
+ // Build dependency graph.
177
+ const dependencyGraph = this.buildDependencyGraph(expressions);
178
+ this._registry.set(this._expressionsAtom, expressions);
179
+ return { expressions, dependencyGraph };
180
+ }
181
+
182
+ private topologicalSort(nodes: string[], dependencies: Record<string, string[]>): string[] {
183
+ const visited = new Set<string>();
184
+ const result: string[] = [];
185
+
186
+ const visit = (node: string) => {
187
+ if (visited.has(node)) {
188
+ return;
189
+ }
190
+
191
+ visited.add(node);
192
+
193
+ // Visit dependencies first.
194
+ const deps = dependencies[node] || [];
195
+ deps.forEach((dep) => visit(dep));
196
+ result.push(node);
197
+ };
198
+
199
+ // Visit all nodes.
200
+ nodes.forEach((node) => visit(node));
201
+ return result;
202
+ }
203
+
204
+ private buildDependencyGraph(expressions: Record<string, ParsedExpression>): Record<string, string[]> {
205
+ // Create a map of variable names to their cell IDs.
206
+ const nameToCellId = new Map<string, string>();
207
+ Object.entries(expressions).forEach(([id, expr]) => {
208
+ if (expr.name) {
209
+ nameToCellId.set(expr.name, id);
210
+ }
211
+ });
212
+
213
+ // Build the dependency graph using cell IDs.
214
+ const graph: Record<string, string[]> = {};
215
+ Object.entries(expressions).forEach(([id, expr]) => {
216
+ if (expr.references && expr.references.length > 0) {
217
+ // Map variable references to cell IDs.
218
+ const dependencyCellIds = expr.references
219
+ .map((ref) => nameToCellId.get(ref))
220
+ .filter((cellId): cellId is string => cellId !== undefined && cellId !== id);
221
+
222
+ if (dependencyCellIds.length > 0) {
223
+ graph[id] = dependencyCellIds;
224
+ }
225
+ }
226
+ });
227
+
228
+ return graph;
229
+ }
230
+ }