@dxos/plugin-script 0.8.4-main.ae835ea → 0.8.4-main.bc674ce

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 (386) hide show
  1. package/dist/lib/browser/DeploymentDialog-OSL6RMPA.mjs +14 -0
  2. package/dist/lib/browser/{NotebookContainer-C36N7AFF.mjs → NotebookContainer-NBAXYESH.mjs} +267 -239
  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-TWX2NMZN.mjs +137 -0
  20. package/dist/lib/browser/chunk-TWX2NMZN.mjs.map +7 -0
  21. package/dist/lib/browser/chunk-UUR4JNNB.mjs +113 -0
  22. package/dist/lib/browser/chunk-UUR4JNNB.mjs.map +7 -0
  23. package/dist/lib/browser/{chunk-ST3ACVUC.mjs → chunk-UX4GHJ5E.mjs} +29 -12
  24. package/dist/lib/browser/chunk-UX4GHJ5E.mjs.map +7 -0
  25. package/dist/lib/browser/{chunk-EB6AXFXO.mjs → chunk-WYR4QHPE.mjs} +1 -1
  26. package/dist/lib/browser/chunk-WYR4QHPE.mjs.map +7 -0
  27. package/dist/lib/browser/chunk-XCN4D3Z5.mjs +606 -0
  28. package/dist/lib/browser/chunk-XCN4D3Z5.mjs.map +7 -0
  29. package/dist/lib/browser/compiler-76F3QAXC.mjs +161 -0
  30. package/dist/lib/browser/compiler-76F3QAXC.mjs.map +7 -0
  31. package/dist/lib/browser/index.mjs +96 -126
  32. package/dist/lib/browser/index.mjs.map +4 -4
  33. package/dist/lib/browser/meta.json +1 -1
  34. package/dist/lib/browser/operation-resolver-HUILPPKT.mjs +82 -0
  35. package/dist/lib/browser/operation-resolver-HUILPPKT.mjs.map +7 -0
  36. package/dist/lib/browser/{react-surface-X4NATU6B.mjs → react-surface-O6GKHB2J.mjs} +52 -41
  37. package/dist/lib/browser/react-surface-O6GKHB2J.mjs.map +7 -0
  38. package/dist/lib/browser/settings-3ENI25PI.mjs +35 -0
  39. package/dist/lib/browser/settings-3ENI25PI.mjs.map +7 -0
  40. package/dist/lib/browser/templates/index.mjs +1 -1
  41. package/dist/lib/browser/types/index.mjs +9 -5
  42. package/dist/lib/node-esm/{DeploymentDialog-OSHHSEBH.mjs → DeploymentDialog-OGBJPVIX.mjs} +6 -6
  43. package/dist/lib/node-esm/DeploymentDialog-OGBJPVIX.mjs.map +7 -0
  44. package/dist/lib/node-esm/{NotebookContainer-FOVFGJQR.mjs → NotebookContainer-IUAYVJSD.mjs} +267 -239
  45. package/dist/lib/node-esm/NotebookContainer-IUAYVJSD.mjs.map +7 -0
  46. package/dist/lib/node-esm/ScriptContainer-K7JCEU5Z.mjs +150 -0
  47. package/dist/lib/node-esm/ScriptContainer-K7JCEU5Z.mjs.map +7 -0
  48. package/dist/lib/node-esm/app-graph-builder-NVE3EVBG.mjs +69 -0
  49. package/dist/lib/node-esm/app-graph-builder-NVE3EVBG.mjs.map +7 -0
  50. package/dist/lib/node-esm/blueprint-definition-NC7NNJGI.mjs +18 -0
  51. package/dist/lib/node-esm/blueprint-definition-NC7NNJGI.mjs.map +7 -0
  52. package/dist/lib/node-esm/blueprints/index.mjs +9 -0
  53. package/dist/lib/node-esm/blueprints/index.mjs.map +7 -0
  54. package/dist/lib/node-esm/{chunk-2GVTWESW.mjs → chunk-4F5FJZ36.mjs} +29 -12
  55. package/dist/lib/node-esm/chunk-4F5FJZ36.mjs.map +7 -0
  56. package/dist/lib/node-esm/chunk-4QNZMXW6.mjs +607 -0
  57. package/dist/lib/node-esm/chunk-4QNZMXW6.mjs.map +7 -0
  58. package/dist/lib/node-esm/{chunk-IBV2DR36.mjs → chunk-5HSJPAK7.mjs} +1 -1
  59. package/dist/lib/node-esm/chunk-5HSJPAK7.mjs.map +7 -0
  60. package/dist/lib/node-esm/chunk-BX5PP6AW.mjs +558 -0
  61. package/dist/lib/node-esm/chunk-BX5PP6AW.mjs.map +7 -0
  62. package/dist/lib/node-esm/chunk-G3J76DWP.mjs +114 -0
  63. package/dist/lib/node-esm/chunk-G3J76DWP.mjs.map +7 -0
  64. package/dist/lib/node-esm/chunk-SLU3KRV3.mjs +112 -0
  65. package/dist/lib/node-esm/chunk-SLU3KRV3.mjs.map +7 -0
  66. package/dist/lib/node-esm/chunk-VQPIA4VF.mjs +138 -0
  67. package/dist/lib/node-esm/chunk-VQPIA4VF.mjs.map +7 -0
  68. package/dist/lib/node-esm/chunk-VWOLKNMO.mjs +271 -0
  69. package/dist/lib/node-esm/chunk-VWOLKNMO.mjs.map +7 -0
  70. package/dist/lib/node-esm/chunk-Y3G5NCTP.mjs +36 -0
  71. package/dist/lib/node-esm/chunk-Y3G5NCTP.mjs.map +7 -0
  72. package/dist/lib/node-esm/compiler-FNZH6TFN.mjs +162 -0
  73. package/dist/lib/node-esm/compiler-FNZH6TFN.mjs.map +7 -0
  74. package/dist/lib/node-esm/index.mjs +96 -126
  75. package/dist/lib/node-esm/index.mjs.map +4 -4
  76. package/dist/lib/node-esm/meta.json +1 -1
  77. package/dist/lib/node-esm/operation-resolver-JTCIY6HU.mjs +83 -0
  78. package/dist/lib/node-esm/operation-resolver-JTCIY6HU.mjs.map +7 -0
  79. package/dist/lib/node-esm/{react-surface-LVGLBSTE.mjs → react-surface-RLANMVMB.mjs} +52 -41
  80. package/dist/lib/node-esm/react-surface-RLANMVMB.mjs.map +7 -0
  81. package/dist/lib/node-esm/settings-7AYC5VXN.mjs +36 -0
  82. package/dist/lib/node-esm/settings-7AYC5VXN.mjs.map +7 -0
  83. package/dist/lib/node-esm/templates/index.mjs +1 -1
  84. package/dist/lib/node-esm/types/index.mjs +9 -5
  85. package/dist/types/src/ScriptPlugin.d.ts +2 -1
  86. package/dist/types/src/ScriptPlugin.d.ts.map +1 -1
  87. package/dist/types/src/blueprints/index.d.ts +2 -0
  88. package/dist/types/src/blueprints/index.d.ts.map +1 -0
  89. package/dist/types/src/blueprints/script-blueprint.d.ts +22 -0
  90. package/dist/types/src/blueprints/script-blueprint.d.ts.map +1 -0
  91. package/dist/types/src/capabilities/app-graph-builder/app-graph-builder.d.ts +6 -0
  92. package/dist/types/src/capabilities/app-graph-builder/app-graph-builder.d.ts.map +1 -0
  93. package/dist/types/src/capabilities/app-graph-builder/index.d.ts +3 -0
  94. package/dist/types/src/capabilities/app-graph-builder/index.d.ts.map +1 -0
  95. package/dist/types/src/capabilities/artifact-definition/artifact-definition.d.ts +12 -0
  96. package/dist/types/src/capabilities/artifact-definition/artifact-definition.d.ts.map +1 -0
  97. package/dist/types/src/capabilities/artifact-definition/index.d.ts +3 -0
  98. package/dist/types/src/capabilities/artifact-definition/index.d.ts.map +1 -0
  99. package/dist/types/src/capabilities/blueprint-definition/blueprint-definition.d.ts +9 -0
  100. package/dist/types/src/capabilities/blueprint-definition/blueprint-definition.d.ts.map +1 -0
  101. package/dist/types/src/capabilities/blueprint-definition/index.d.ts +3 -0
  102. package/dist/types/src/capabilities/blueprint-definition/index.d.ts.map +1 -0
  103. package/dist/types/src/capabilities/compiler/compiler.d.ts +6 -0
  104. package/dist/types/src/capabilities/compiler/compiler.d.ts.map +1 -0
  105. package/dist/types/src/capabilities/compiler/index.d.ts +3 -0
  106. package/dist/types/src/capabilities/compiler/index.d.ts.map +1 -0
  107. package/dist/types/src/capabilities/index.d.ts +6 -7
  108. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  109. package/dist/types/src/capabilities/operation-resolver/index.d.ts +3 -0
  110. package/dist/types/src/capabilities/operation-resolver/index.d.ts.map +1 -0
  111. package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts +5 -0
  112. package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts.map +1 -0
  113. package/dist/types/src/capabilities/react-surface/index.d.ts +3 -0
  114. package/dist/types/src/capabilities/react-surface/index.d.ts.map +1 -0
  115. package/dist/types/src/capabilities/react-surface/react-surface.d.ts +5 -0
  116. package/dist/types/src/capabilities/react-surface/react-surface.d.ts.map +1 -0
  117. package/dist/types/src/capabilities/settings/index.d.ts +7 -0
  118. package/dist/types/src/capabilities/settings/index.d.ts.map +1 -0
  119. package/dist/types/src/capabilities/settings/settings.d.ts +9 -0
  120. package/dist/types/src/capabilities/settings/settings.d.ts.map +1 -0
  121. package/dist/types/src/compiler/compiler.d.ts +1 -1
  122. package/dist/types/src/compiler/compiler.d.ts.map +1 -1
  123. package/dist/types/src/components/DeploymentDialog/DeploymentDialog.d.ts +2 -2
  124. package/dist/types/src/components/DeploymentDialog/DeploymentDialog.d.ts.map +1 -1
  125. package/dist/types/src/components/DeploymentDialog/DeploymentDialog.stories.d.ts +4 -3
  126. package/dist/types/src/components/DeploymentDialog/DeploymentDialog.stories.d.ts.map +1 -1
  127. package/dist/types/src/components/FrameContainer/FrameContainer.d.ts +1 -1
  128. package/dist/types/src/components/FrameContainer/FrameContainer.d.ts.map +1 -1
  129. package/dist/types/src/components/NotebookContainer.d.ts +3 -5
  130. package/dist/types/src/components/NotebookContainer.d.ts.map +1 -1
  131. package/dist/types/src/components/NotebookContainer.stories.d.ts +3 -247
  132. package/dist/types/src/components/NotebookContainer.stories.d.ts.map +1 -1
  133. package/dist/types/src/components/NotebookStack/NotebookCell.d.ts +3 -3
  134. package/dist/types/src/components/NotebookStack/NotebookCell.d.ts.map +1 -1
  135. package/dist/types/src/components/NotebookStack/NotebookStack.d.ts +1 -1
  136. package/dist/types/src/components/NotebookStack/NotebookStack.d.ts.map +1 -1
  137. package/dist/types/src/components/NotebookStack/NotebookStack.stories.d.ts +5 -1
  138. package/dist/types/src/components/NotebookStack/NotebookStack.stories.d.ts.map +1 -1
  139. package/dist/types/src/components/QueryEditor/QueryEditor.d.ts +5 -0
  140. package/dist/types/src/components/QueryEditor/QueryEditor.d.ts.map +1 -0
  141. package/dist/types/src/components/QueryEditor/QueryEditor.stories.d.ts +13 -0
  142. package/dist/types/src/components/QueryEditor/QueryEditor.stories.d.ts.map +1 -0
  143. package/dist/types/src/components/QueryEditor/index.d.ts +2 -0
  144. package/dist/types/src/components/QueryEditor/index.d.ts.map +1 -0
  145. package/dist/types/src/components/ScriptContainer.d.ts +4 -5
  146. package/dist/types/src/components/ScriptContainer.d.ts.map +1 -1
  147. package/dist/types/src/components/ScriptToolbar/ScriptToolbar.d.ts +2 -2
  148. package/dist/types/src/components/ScriptToolbar/ScriptToolbar.d.ts.map +1 -1
  149. package/dist/types/src/components/ScriptToolbar/ScriptToolbar.stories.d.ts +5 -1
  150. package/dist/types/src/components/ScriptToolbar/ScriptToolbar.stories.d.ts.map +1 -1
  151. package/dist/types/src/components/Settings/ScriptObjectSettings.d.ts.map +1 -1
  152. package/dist/types/src/components/Settings/ScriptPluginSettings.d.ts +4 -2
  153. package/dist/types/src/components/Settings/ScriptPluginSettings.d.ts.map +1 -1
  154. package/dist/types/src/components/TestPanel/TestContainer.d.ts +1 -1
  155. package/dist/types/src/components/TestPanel/TestContainer.d.ts.map +1 -1
  156. package/dist/types/src/components/TestPanel/TestPanel.d.ts.map +1 -1
  157. package/dist/types/src/components/TypescriptEditor/TypescriptEditor.d.ts +3 -2
  158. package/dist/types/src/components/TypescriptEditor/TypescriptEditor.d.ts.map +1 -1
  159. package/dist/types/src/components/TypescriptEditor/TypescriptEditor.stories.d.ts +1 -1
  160. package/dist/types/src/components/TypescriptEditor/TypescriptEditor.stories.d.ts.map +1 -1
  161. package/dist/types/src/components/index.d.ts +2 -2
  162. package/dist/types/src/components/index.d.ts.map +1 -1
  163. package/dist/types/src/e2e/ai.test.d.ts +2 -0
  164. package/dist/types/src/e2e/ai.test.d.ts.map +1 -0
  165. package/dist/types/src/e2e/deploy.test.d.ts +2 -0
  166. package/dist/types/src/e2e/deploy.test.d.ts.map +1 -0
  167. package/dist/types/src/hooks/deploy.d.ts +10 -25
  168. package/dist/types/src/hooks/deploy.d.ts.map +1 -1
  169. package/dist/types/src/hooks/format.d.ts +2 -2
  170. package/dist/types/src/hooks/format.d.ts.map +1 -1
  171. package/dist/types/src/hooks/index.d.ts +1 -0
  172. package/dist/types/src/hooks/index.d.ts.map +1 -1
  173. package/dist/types/src/hooks/template.d.ts +2 -2
  174. package/dist/types/src/hooks/template.d.ts.map +1 -1
  175. package/dist/types/src/hooks/useCompiler.d.ts +7 -0
  176. package/dist/types/src/hooks/useCompiler.d.ts.map +1 -0
  177. package/dist/types/src/hooks/useCreateAndDeployScriptTemplates.d.ts.map +1 -1
  178. package/dist/types/src/hooks/useToolbarState.d.ts +8 -1
  179. package/dist/types/src/hooks/useToolbarState.d.ts.map +1 -1
  180. package/dist/types/src/index.d.ts +1 -1
  181. package/dist/types/src/index.d.ts.map +1 -1
  182. package/dist/types/src/meta.d.ts +2 -2
  183. package/dist/types/src/meta.d.ts.map +1 -1
  184. package/dist/types/src/notebook/compute-graph.d.ts +24 -11
  185. package/dist/types/src/notebook/compute-graph.d.ts.map +1 -1
  186. package/dist/types/src/templates/anthropic.d.ts +8 -0
  187. package/dist/types/src/templates/anthropic.d.ts.map +1 -0
  188. package/dist/types/src/templates/chess-bot.d.ts +16 -0
  189. package/dist/types/src/templates/chess-bot.d.ts.map +1 -0
  190. package/dist/types/src/templates/commentary.d.ts +16 -0
  191. package/dist/types/src/templates/commentary.d.ts.map +1 -0
  192. package/dist/types/src/templates/forex-effect.d.ts +4 -1
  193. package/dist/types/src/templates/forex-effect.d.ts.map +1 -1
  194. package/dist/types/src/templates/forex.d.ts +4 -1
  195. package/dist/types/src/templates/forex.d.ts.map +1 -1
  196. package/dist/types/src/templates/index.d.ts +12 -3
  197. package/dist/types/src/templates/index.d.ts.map +1 -1
  198. package/dist/types/src/templates/ping.d.ts +1 -4
  199. package/dist/types/src/templates/ping.d.ts.map +1 -1
  200. package/dist/types/src/testing/simulator.test.d.ts +2 -0
  201. package/dist/types/src/testing/simulator.test.d.ts.map +1 -0
  202. package/dist/types/src/translations.d.ts +2 -0
  203. package/dist/types/src/translations.d.ts.map +1 -1
  204. package/dist/types/src/types/Notebook.d.ts +91 -22
  205. package/dist/types/src/types/Notebook.d.ts.map +1 -1
  206. package/dist/types/src/types/actions.d.ts +30 -44
  207. package/dist/types/src/types/actions.d.ts.map +1 -1
  208. package/dist/types/src/types/capabilities.d.ts +12 -0
  209. package/dist/types/src/types/capabilities.d.ts.map +1 -0
  210. package/dist/types/src/types/events.d.ts +5 -0
  211. package/dist/types/src/types/events.d.ts.map +1 -0
  212. package/dist/types/src/types/index.d.ts +2 -0
  213. package/dist/types/src/types/index.d.ts.map +1 -1
  214. package/dist/types/src/util/deploy.d.ts.map +1 -1
  215. package/dist/types/src/util/functions.d.ts.map +1 -1
  216. package/dist/types/tsconfig.tsbuildinfo +1 -1
  217. package/package.json +113 -85
  218. package/src/ScriptPlugin.tsx +36 -75
  219. package/src/blueprints/index.ts +5 -0
  220. package/src/blueprints/script-blueprint.ts +24 -0
  221. package/src/capabilities/app-graph-builder/app-graph-builder.ts +55 -0
  222. package/src/capabilities/app-graph-builder/index.ts +7 -0
  223. package/src/capabilities/{artifact-definition.ts → artifact-definition/artifact-definition.ts} +97 -95
  224. package/src/capabilities/artifact-definition/index.ts +7 -0
  225. package/src/capabilities/blueprint-definition/blueprint-definition.ts +23 -0
  226. package/src/capabilities/blueprint-definition/index.ts +7 -0
  227. package/src/capabilities/compiler/compiler.ts +103 -0
  228. package/src/capabilities/compiler/index.ts +7 -0
  229. package/src/capabilities/index.ts +6 -10
  230. package/src/capabilities/operation-resolver/index.ts +7 -0
  231. package/src/capabilities/operation-resolver/operation-resolver.ts +74 -0
  232. package/src/capabilities/react-surface/index.ts +7 -0
  233. package/src/capabilities/react-surface/react-surface.tsx +118 -0
  234. package/src/capabilities/settings/index.ts +7 -0
  235. package/src/capabilities/settings/settings.ts +32 -0
  236. package/src/compiler/compiler.ts +10 -3
  237. package/src/components/DeploymentDialog/DeploymentDialog.stories.tsx +28 -24
  238. package/src/components/DeploymentDialog/DeploymentDialog.tsx +38 -41
  239. package/src/components/FrameContainer/FrameContainer.tsx +6 -4
  240. package/src/components/NotebookContainer.stories.tsx +23 -19
  241. package/src/components/NotebookContainer.tsx +69 -61
  242. package/src/components/NotebookStack/NotebookCell.tsx +36 -27
  243. package/src/components/NotebookStack/NotebookStack.stories.tsx +19 -18
  244. package/src/components/NotebookStack/NotebookStack.tsx +4 -4
  245. package/src/components/QueryEditor/QueryEditor.stories.tsx +100 -0
  246. package/src/components/QueryEditor/QueryEditor.tsx +47 -0
  247. package/src/components/QueryEditor/index.ts +5 -0
  248. package/src/components/ScriptContainer.tsx +48 -33
  249. package/src/components/ScriptToolbar/ScriptToolbar.stories.tsx +38 -15
  250. package/src/components/ScriptToolbar/ScriptToolbar.tsx +18 -21
  251. package/src/components/Settings/ScriptObjectSettings.tsx +54 -31
  252. package/src/components/Settings/ScriptPluginSettings.tsx +8 -3
  253. package/src/components/TestPanel/TestContainer.tsx +5 -5
  254. package/src/components/TestPanel/TestPanel.tsx +36 -13
  255. package/src/components/TypescriptEditor/TypescriptEditor.stories.tsx +14 -9
  256. package/src/components/TypescriptEditor/TypescriptEditor.tsx +69 -69
  257. package/src/e2e/ai.test.ts +92 -0
  258. package/src/e2e/deploy.test.ts +64 -0
  259. package/src/hooks/deploy.ts +36 -28
  260. package/src/hooks/format.ts +5 -1
  261. package/src/hooks/index.ts +1 -0
  262. package/src/hooks/template.ts +15 -9
  263. package/src/hooks/useCompiler.ts +24 -0
  264. package/src/hooks/useCreateAndDeployScriptTemplates.ts +13 -15
  265. package/src/hooks/useToolbarState.ts +29 -5
  266. package/src/index.ts +1 -1
  267. package/src/meta.ts +2 -2
  268. package/src/notebook/compute-graph.test.ts +20 -8
  269. package/src/notebook/compute-graph.ts +45 -21
  270. package/src/templates/anthropic.ts +42 -0
  271. package/src/templates/chess-bot.ts +58 -0
  272. package/src/templates/commentary.ts +232 -0
  273. package/src/templates/data-generator.ts +1 -1
  274. package/src/templates/forex-effect.ts +22 -27
  275. package/src/templates/forex.ts +7 -6
  276. package/src/templates/gmail.ts +1 -2
  277. package/src/templates/index.ts +18 -5
  278. package/src/templates/ping.ts +14 -5
  279. package/src/testing/data.ts +7 -7
  280. package/src/testing/simulator.test.ts +40 -0
  281. package/src/translations.ts +2 -0
  282. package/src/types/Notebook.ts +12 -12
  283. package/src/types/actions.ts +17 -25
  284. package/src/types/capabilities.ts +17 -0
  285. package/src/types/events.ts +11 -0
  286. package/src/types/index.ts +2 -0
  287. package/src/types/types.ts +1 -1
  288. package/src/util/deploy.ts +23 -29
  289. package/src/util/functions.ts +29 -25
  290. package/src/vite-env.d.ts +2 -0
  291. package/dist/lib/browser/DeploymentDialog-E5NXT4UQ.mjs +0 -14
  292. package/dist/lib/browser/NotebookContainer-C36N7AFF.mjs.map +0 -7
  293. package/dist/lib/browser/ScriptContainer-4YPRUM3C.mjs +0 -148
  294. package/dist/lib/browser/ScriptContainer-4YPRUM3C.mjs.map +0 -7
  295. package/dist/lib/browser/app-graph-builder-LEOPGBJD.mjs +0 -66
  296. package/dist/lib/browser/app-graph-builder-LEOPGBJD.mjs.map +0 -7
  297. package/dist/lib/browser/blueprint-definition-6PZWZM2Y.mjs +0 -30
  298. package/dist/lib/browser/blueprint-definition-6PZWZM2Y.mjs.map +0 -7
  299. package/dist/lib/browser/chunk-5S5YQNJZ.mjs +0 -304
  300. package/dist/lib/browser/chunk-5S5YQNJZ.mjs.map +0 -7
  301. package/dist/lib/browser/chunk-A5K3TXYA.mjs +0 -269
  302. package/dist/lib/browser/chunk-A5K3TXYA.mjs.map +0 -7
  303. package/dist/lib/browser/chunk-EB6AXFXO.mjs.map +0 -7
  304. package/dist/lib/browser/chunk-HCURXADW.mjs +0 -102
  305. package/dist/lib/browser/chunk-HCURXADW.mjs.map +0 -7
  306. package/dist/lib/browser/chunk-HHTOAI2J.mjs +0 -644
  307. package/dist/lib/browser/chunk-HHTOAI2J.mjs.map +0 -7
  308. package/dist/lib/browser/chunk-IQMYIWHG.mjs +0 -153
  309. package/dist/lib/browser/chunk-IQMYIWHG.mjs.map +0 -7
  310. package/dist/lib/browser/chunk-LI4P25M5.mjs +0 -111
  311. package/dist/lib/browser/chunk-LI4P25M5.mjs.map +0 -7
  312. package/dist/lib/browser/chunk-Q2DGRQRN.mjs +0 -255
  313. package/dist/lib/browser/chunk-Q2DGRQRN.mjs.map +0 -7
  314. package/dist/lib/browser/chunk-ST3ACVUC.mjs.map +0 -7
  315. package/dist/lib/browser/chunk-UOQ6NCH3.mjs +0 -15
  316. package/dist/lib/browser/chunk-UOQ6NCH3.mjs.map +0 -7
  317. package/dist/lib/browser/compiler-Q4UY2COU.mjs +0 -86
  318. package/dist/lib/browser/compiler-Q4UY2COU.mjs.map +0 -7
  319. package/dist/lib/browser/intent-resolver-AMMHATM7.mjs +0 -105
  320. package/dist/lib/browser/intent-resolver-AMMHATM7.mjs.map +0 -7
  321. package/dist/lib/browser/react-surface-X4NATU6B.mjs.map +0 -7
  322. package/dist/lib/browser/settings-6UXY7F7D.mjs +0 -26
  323. package/dist/lib/browser/settings-6UXY7F7D.mjs.map +0 -7
  324. package/dist/lib/node-esm/NotebookContainer-FOVFGJQR.mjs.map +0 -7
  325. package/dist/lib/node-esm/ScriptContainer-EW24D5II.mjs +0 -149
  326. package/dist/lib/node-esm/ScriptContainer-EW24D5II.mjs.map +0 -7
  327. package/dist/lib/node-esm/app-graph-builder-XJ3MY5BM.mjs +0 -67
  328. package/dist/lib/node-esm/app-graph-builder-XJ3MY5BM.mjs.map +0 -7
  329. package/dist/lib/node-esm/blueprint-definition-5R6YCSZZ.mjs +0 -31
  330. package/dist/lib/node-esm/blueprint-definition-5R6YCSZZ.mjs.map +0 -7
  331. package/dist/lib/node-esm/chunk-2GVTWESW.mjs.map +0 -7
  332. package/dist/lib/node-esm/chunk-55JZVM6K.mjs +0 -16
  333. package/dist/lib/node-esm/chunk-55JZVM6K.mjs.map +0 -7
  334. package/dist/lib/node-esm/chunk-EJLYOSD7.mjs +0 -113
  335. package/dist/lib/node-esm/chunk-EJLYOSD7.mjs.map +0 -7
  336. package/dist/lib/node-esm/chunk-GA27XSEY.mjs +0 -270
  337. package/dist/lib/node-esm/chunk-GA27XSEY.mjs.map +0 -7
  338. package/dist/lib/node-esm/chunk-IBV2DR36.mjs.map +0 -7
  339. package/dist/lib/node-esm/chunk-N2XLVOFB.mjs +0 -103
  340. package/dist/lib/node-esm/chunk-N2XLVOFB.mjs.map +0 -7
  341. package/dist/lib/node-esm/chunk-O7HXE72S.mjs +0 -256
  342. package/dist/lib/node-esm/chunk-O7HXE72S.mjs.map +0 -7
  343. package/dist/lib/node-esm/chunk-OZ6LCME4.mjs +0 -645
  344. package/dist/lib/node-esm/chunk-OZ6LCME4.mjs.map +0 -7
  345. package/dist/lib/node-esm/chunk-TUGLYZDT.mjs +0 -305
  346. package/dist/lib/node-esm/chunk-TUGLYZDT.mjs.map +0 -7
  347. package/dist/lib/node-esm/chunk-UEGPBCSF.mjs +0 -154
  348. package/dist/lib/node-esm/chunk-UEGPBCSF.mjs.map +0 -7
  349. package/dist/lib/node-esm/compiler-I6A4KE6E.mjs +0 -87
  350. package/dist/lib/node-esm/compiler-I6A4KE6E.mjs.map +0 -7
  351. package/dist/lib/node-esm/intent-resolver-YKLZQR7U.mjs +0 -106
  352. package/dist/lib/node-esm/intent-resolver-YKLZQR7U.mjs.map +0 -7
  353. package/dist/lib/node-esm/react-surface-LVGLBSTE.mjs.map +0 -7
  354. package/dist/lib/node-esm/settings-O4EZPUE3.mjs +0 -27
  355. package/dist/lib/node-esm/settings-O4EZPUE3.mjs.map +0 -7
  356. package/dist/types/src/capabilities/app-graph-builder.d.ts +0 -4
  357. package/dist/types/src/capabilities/app-graph-builder.d.ts.map +0 -1
  358. package/dist/types/src/capabilities/artifact-definition.d.ts +0 -11
  359. package/dist/types/src/capabilities/artifact-definition.d.ts.map +0 -1
  360. package/dist/types/src/capabilities/blueprint-definition.d.ts +0 -5
  361. package/dist/types/src/capabilities/blueprint-definition.d.ts.map +0 -1
  362. package/dist/types/src/capabilities/capabilities.d.ts +0 -5
  363. package/dist/types/src/capabilities/capabilities.d.ts.map +0 -1
  364. package/dist/types/src/capabilities/compiler.d.ts +0 -4
  365. package/dist/types/src/capabilities/compiler.d.ts.map +0 -1
  366. package/dist/types/src/capabilities/intent-resolver.d.ts +0 -4
  367. package/dist/types/src/capabilities/intent-resolver.d.ts.map +0 -1
  368. package/dist/types/src/capabilities/react-surface.d.ts +0 -4
  369. package/dist/types/src/capabilities/react-surface.d.ts.map +0 -1
  370. package/dist/types/src/capabilities/settings.d.ts +0 -4
  371. package/dist/types/src/capabilities/settings.d.ts.map +0 -1
  372. package/dist/types/src/events.d.ts +0 -4
  373. package/dist/types/src/events.d.ts.map +0 -1
  374. package/dist/types/src/templates/chess.d.ts +0 -3
  375. package/dist/types/src/templates/chess.d.ts.map +0 -1
  376. package/src/capabilities/app-graph-builder.ts +0 -65
  377. package/src/capabilities/blueprint-definition.ts +0 -30
  378. package/src/capabilities/capabilities.ts +0 -12
  379. package/src/capabilities/compiler.ts +0 -34
  380. package/src/capabilities/intent-resolver.ts +0 -86
  381. package/src/capabilities/react-surface.tsx +0 -102
  382. package/src/capabilities/settings.ts +0 -21
  383. package/src/events.ts +0 -11
  384. package/src/templates/chess.ts +0 -49
  385. /package/dist/lib/browser/{DeploymentDialog-E5NXT4UQ.mjs.map → DeploymentDialog-OSL6RMPA.mjs.map} +0 -0
  386. /package/dist/lib/{node-esm/DeploymentDialog-OSHHSEBH.mjs.map → browser/blueprints/index.mjs.map} +0 -0
@@ -2,19 +2,18 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import * as Function 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
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,20 @@ 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
- Function.pipe(
44
- createIntent(ScriptAction.CreateScript, { space, initialTemplateId: template.id as any }),
45
- chain(SpaceAction.AddObject, { target: space }),
46
- ),
47
- );
48
- invariant(Obj.instanceOf(Script.Script, 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
 
58
56
  // TODO(burdon): Return onCreateAndDeployScripts.
59
57
  return { handleCreateAndDeployScripts, status, error };
@@ -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,7 +2,7 @@
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
8
  export * from './util';
package/src/meta.ts CHANGED
@@ -2,10 +2,10 @@
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
6
  import { trim } from '@dxos/util';
7
7
 
8
- export const meta: PluginMeta = {
8
+ export const meta: Plugin.Meta = {
9
9
  id: 'dxos.org/plugin/script',
10
10
  name: 'Scripts',
11
11
  description: trim`
@@ -2,16 +2,20 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
+ import { Registry } from '@effect-atom/atom-react';
5
6
  import { describe, expect, test } from 'vitest';
6
7
 
8
+ import { Obj } from '@dxos/echo';
9
+
7
10
  import { createNotebook } from '../testing';
8
11
 
9
12
  import { ComputeGraph } from './compute-graph';
10
13
 
11
14
  describe('notebook', () => {
12
15
  test('parse dependency graph', async () => {
16
+ const registry = Registry.make();
13
17
  const notebook = createNotebook();
14
- const graph = new ComputeGraph(notebook);
18
+ const graph = new ComputeGraph(notebook, registry);
15
19
  const result = graph.parse();
16
20
 
17
21
  const getId = (i: number) => notebook.cells[i].id;
@@ -34,13 +38,17 @@ describe('notebook', () => {
34
38
  });
35
39
 
36
40
  test('evalScript blocks access to window and document', async () => {
41
+ const registry = Registry.make();
37
42
  const notebook = createNotebook();
38
43
  // Replace one of the cells with code that tries to access window/document.
39
- if (notebook.cells[2].source?.target) {
40
- notebook.cells[2].source.target.content = 'b = typeof window';
44
+ const sourceTarget = notebook.cells[2].source?.target;
45
+ if (sourceTarget) {
46
+ Obj.change(sourceTarget, (t) => {
47
+ t.content = 'b = typeof window';
48
+ });
41
49
  }
42
50
 
43
- const graph = new ComputeGraph(notebook);
51
+ const graph = new ComputeGraph(notebook, registry);
44
52
  graph.parse();
45
53
  const values = await graph.evaluate();
46
54
 
@@ -48,8 +56,10 @@ describe('notebook', () => {
48
56
  expect(values[notebook.cells[2].id]).toBe('undefined');
49
57
 
50
58
  // Test document access.
51
- if (notebook.cells[2].source?.target) {
52
- notebook.cells[2].source.target.content = 'b = typeof document';
59
+ if (sourceTarget) {
60
+ Obj.change(sourceTarget, (t) => {
61
+ t.content = 'b = typeof document';
62
+ });
53
63
  }
54
64
  graph.parse();
55
65
  const values2 = await graph.evaluate();
@@ -58,8 +68,10 @@ describe('notebook', () => {
58
68
  expect(values2[notebook.cells[2].id]).toBe('undefined');
59
69
 
60
70
  // Test that safe globals still work.
61
- if (notebook.cells[2].source?.target) {
62
- notebook.cells[2].source.target.content = 'b = Math.max(100, 200)';
71
+ if (sourceTarget) {
72
+ Obj.change(sourceTarget, (t) => {
73
+ t.content = 'b = Math.max(100, 200)';
74
+ });
63
75
  }
64
76
  graph.parse();
65
77
  const values3 = await graph.evaluate();
@@ -2,7 +2,7 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { type Signal, signal } from '@preact/signals-core';
5
+ import { Atom, type Registry } from '@effect-atom/atom-react';
6
6
 
7
7
  import { log } from '@dxos/log';
8
8
 
@@ -18,38 +18,62 @@ import { type ParsedExpression, VirtualTypeScriptParser } from './vfs-parser';
18
18
  export class ComputeGraph {
19
19
  private readonly _parser = new VirtualTypeScriptParser();
20
20
 
21
- private _expressions = signal<Record<string, ParsedExpression>>({});
22
- private _valuesByCellId = signal<Record<string, any>>({});
23
- private _valuesByName = signal<Record<string, any>>({});
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
24
 
25
- constructor(private readonly _notebook: Notebook.Notebook) {}
25
+ constructor(
26
+ private readonly _notebook: Notebook.Notebook,
27
+ private readonly _registry: Registry.Registry,
28
+ ) {}
26
29
 
27
30
  /**
28
- * Parsed expressions by cell ID.
31
+ * Atom for parsed expressions by cell ID.
29
32
  */
30
- get expressions(): Signal<Record<string, ParsedExpression>> {
31
- return this._expressions;
33
+ get expressions(): Atom.Atom<Record<string, ParsedExpression>> {
34
+ return this._expressionsAtom;
32
35
  }
33
36
 
34
37
  /**
35
- * Computed values by cell ID.
38
+ * Get current expressions by cell ID.
36
39
  */
37
- get values(): Signal<Record<string, any>> {
38
- return this._valuesByCellId;
40
+ getExpressions(): Record<string, ParsedExpression> {
41
+ return this._registry.get(this._expressionsAtom);
39
42
  }
40
43
 
41
44
  /**
42
- * Computed values by name.
45
+ * Atom for computed values by cell ID.
43
46
  */
44
- get valuesByName(): Signal<Record<string, any>> {
45
- return this._valuesByName;
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);
46
70
  }
47
71
 
48
72
  /**
49
73
  * Get computed value by cell ID.
50
74
  */
51
- getValue(cellId: string) {
52
- return this._valuesByCellId.value[cellId];
75
+ getValue(cellId: string): any {
76
+ return this._registry.get(this._valuesByCellIdAtom)[cellId];
53
77
  }
54
78
 
55
79
  /**
@@ -58,8 +82,8 @@ export class ComputeGraph {
58
82
  async evaluate() {
59
83
  // Parse expressions.
60
84
  const { expressions, dependencyGraph } = this.parse();
61
- this._valuesByCellId.value = {};
62
- this._valuesByName.value = {};
85
+ this._registry.set(this._valuesByCellIdAtom, {});
86
+ this._registry.set(this._valuesByNameAtom, {});
63
87
 
64
88
  // Create a map of cell IDs to expressions for easy lookup.
65
89
  const cellExpressions = new Map<string, ParsedExpression>();
@@ -124,8 +148,8 @@ export class ComputeGraph {
124
148
  }
125
149
  }
126
150
 
127
- this._valuesByCellId.value = valuesByCellId;
128
- this._valuesByName.value = valuesByName;
151
+ this._registry.set(this._valuesByCellIdAtom, valuesByCellId);
152
+ this._registry.set(this._valuesByNameAtom, valuesByName);
129
153
  return valuesByCellId;
130
154
  }
131
155
 
@@ -151,7 +175,7 @@ export class ComputeGraph {
151
175
 
152
176
  // Build dependency graph.
153
177
  const dependencyGraph = this.buildDependencyGraph(expressions);
154
- this._expressions.value = expressions;
178
+ this._registry.set(this._expressionsAtom, expressions);
155
179
  return { expressions, dependencyGraph };
156
180
  }
157
181
 
@@ -0,0 +1,42 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import * as LanguageModel from '@effect/ai/LanguageModel';
6
+ import * as Chunk from 'effect/Chunk';
7
+ import * as Effect from 'effect/Effect';
8
+ import * as Schema from 'effect/Schema';
9
+ import * as Stream from 'effect/Stream';
10
+
11
+ import { AiService } from '@dxos/ai';
12
+ import { defineFunction } from '@dxos/functions';
13
+
14
+ export default defineFunction({
15
+ key: 'dxos.org/script/anthropic',
16
+ name: 'Anthropic Chat',
17
+ description: 'Chat with Anthropic',
18
+ inputSchema: Schema.Struct({
19
+ message: Schema.String,
20
+ }),
21
+ services: [AiService.AiService],
22
+ handler: ({ data }) => {
23
+ return Effect.gen(function* () {
24
+ const model = (yield* AiService.AiService).model('@anthropic/claude-sonnet-4-5');
25
+ //
26
+ // Basic example.
27
+ //
28
+ const { text } = yield* LanguageModel.generateText({ prompt: data.message }).pipe(Effect.provide(model));
29
+
30
+ //
31
+ // Streaming example.
32
+ //
33
+ const parts = yield* LanguageModel.streamText({
34
+ prompt: 'Count from 1 to 5, one number per line.',
35
+ }).pipe(Stream.runCollect, Effect.map(Chunk.toArray), Effect.provide(model));
36
+ const textDeltas = parts.filter((p) => p.type === 'text-delta');
37
+ const fullText = textDeltas.map((p) => (p as { delta: string }).delta).join('');
38
+
39
+ return { response: text, streamText: fullText };
40
+ });
41
+ },
42
+ });
@@ -0,0 +1,58 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { Chess as ChessJS } from 'chess.js';
6
+ import * as Effect from 'effect/Effect';
7
+ import * as Schema from 'effect/Schema';
8
+
9
+ import { Database, Obj, Type } from '@dxos/echo';
10
+ import { defineFunction } from '@dxos/functions';
11
+ import { Chess } from '@dxos/plugin-chess/types';
12
+
13
+ export default defineFunction({
14
+ key: 'dxos.org/script/chess-bot',
15
+ name: 'Chess Bot',
16
+ description: 'Plays a random move in a chess game.',
17
+
18
+ inputSchema: Schema.Struct({
19
+ game: Type.Ref(Chess.Game).annotations({
20
+ description: 'The chess game to comment on.',
21
+ }),
22
+ player: Schema.optional(Schema.Literal('white', 'black')).annotations({
23
+ description: 'The player to play the game as.',
24
+ }),
25
+ }),
26
+
27
+ outputSchema: Schema.Struct({
28
+ state: Schema.String.annotations({
29
+ description: 'The state of the game as an ASCII art board.',
30
+ }),
31
+ }),
32
+
33
+ types: [Chess.Game],
34
+ services: [Database.Service],
35
+
36
+ handler: Effect.fnUntraced(function* ({ data: { game, player = 'black' } }) {
37
+ const loadedGame = yield* Database.Service.load(game);
38
+ const chess = new ChessJS();
39
+ chess.loadPgn(loadedGame.pgn ?? '');
40
+ if (chess.turn() !== (player === 'white' ? 'w' : 'b')) {
41
+ return { state: chess.ascii() };
42
+ }
43
+
44
+ const moves = chess.moves({ verbose: true });
45
+ const move = moves[Math.floor(Math.random() * moves.length)];
46
+ if (!move) {
47
+ return { state: chess.ascii() };
48
+ }
49
+
50
+ chess.move(move.san);
51
+ const newPgn = chess.pgn();
52
+ Obj.change(loadedGame, (g) => {
53
+ g.pgn = newPgn;
54
+ });
55
+ yield* Database.Service.flush();
56
+ return { state: chess.ascii() };
57
+ }),
58
+ });
@@ -0,0 +1,232 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import * as A from '@automerge/automerge';
6
+ import { Chess as ChessJS } from 'chess.js';
7
+ import * as Array from 'effect/Array';
8
+ import * as Effect from 'effect/Effect';
9
+ import * as Function from 'effect/Function';
10
+ import * as Layer from 'effect/Layer';
11
+ import * as Option from 'effect/Option';
12
+ import * as Schema from 'effect/Schema';
13
+
14
+ import { AiService, ConsolePrinter, ToolExecutionService, ToolResolverService } from '@dxos/ai';
15
+ import { AiSession, GenerationObserver } from '@dxos/assistant';
16
+ import { ArtifactId } from '@dxos/assistant';
17
+ import { Database, Filter, Obj, Ref, Relation, Type } from '@dxos/echo';
18
+ import { createDocAccessor } from '@dxos/echo-db';
19
+ import { TracingService, defineFunction } from '@dxos/functions';
20
+ import { log } from '@dxos/log';
21
+ import { Chess } from '@dxos/plugin-chess/types';
22
+ import { Markdown } from '@dxos/plugin-markdown/types';
23
+ import { Collection, Text } from '@dxos/schema';
24
+ import { HasSubject } from '@dxos/types';
25
+ import { trim } from '@dxos/util';
26
+
27
+ export default defineFunction({
28
+ key: 'dxos.org/function/chess/commentary',
29
+ name: 'Commentary',
30
+ description: 'Adds commentary about the most recent move to a markdown document associated with the chess game.',
31
+ inputSchema: Schema.Struct({
32
+ game: Type.Ref(Chess.Game).annotations({
33
+ description: 'The chess game to comment on.',
34
+ }),
35
+ }),
36
+ outputSchema: Schema.Union(
37
+ Schema.Struct({
38
+ documentId: ArtifactId.annotations({
39
+ description: 'The ID of the markdown document that was updated or created.',
40
+ }),
41
+ commentary: Schema.String.annotations({
42
+ description: 'The commentary that was added.',
43
+ }),
44
+ }),
45
+ Schema.Void.annotations({
46
+ description: 'Function did not find anything to comment on.',
47
+ }),
48
+ ),
49
+ types: [Chess.Game, Markdown.Document, Text.Text, HasSubject.HasSubject, Collection.Collection],
50
+ services: [AiService.AiService, Database.Service],
51
+ handler: Effect.fnUntraced(
52
+ function* ({ data: { game: gameRef } }) {
53
+ // Load the chess game
54
+ log.info('load game', { gameRef });
55
+ const chessGame = yield* Database.Service.load(gameRef);
56
+
57
+ // Load the chess position from PGN or FEN
58
+ const chess = new ChessJS();
59
+ if (chessGame.pgn) {
60
+ chess.loadPgn(chessGame.pgn);
61
+ } else if (chessGame.fen) {
62
+ chess.load(chessGame.fen);
63
+ } else {
64
+ log.info('Early return: no pgn or fen');
65
+ return;
66
+ }
67
+
68
+ // Get the most recent move
69
+ const history = chess.history({ verbose: true });
70
+ if (history.length === 0) {
71
+ throw new Error('No moves have been played yet');
72
+ }
73
+ const lastMove = history[history.length - 1];
74
+ const moveNumber = Math.ceil(history.length / 2);
75
+ const isWhiteMove = history.length % 2 === 1;
76
+ const player = isWhiteMove ? 'White' : 'Black';
77
+ const moveNotation = lastMove.san;
78
+
79
+ // Generate AI commentary about the move
80
+ const result = yield* new AiSession().run({
81
+ prompt:
82
+ `Comment on this chess move as if you're commentating a live match for an audience:\n\n` +
83
+ `Move ${moveNumber}: ${player} plays ${moveNotation} (${lastMove.from} to ${lastMove.to})${lastMove.captured ? `, capturing ${lastMove.captured}` : ''}\n` +
84
+ `Current position: ${chess.fen()}\n` +
85
+ `${chess.isCheck() ? 'The king is in check! ' : ''}` +
86
+ `${chess.isCheckmate() ? 'CHECKMATE! ' : ''}` +
87
+ `${chess.isStalemate() ? 'STALEMATE! ' : ''}` +
88
+ `\nGame so far:\n${chess.pgn()}`,
89
+ system: COMMENTARY_SYSTEM_PROMPT,
90
+ history: [],
91
+ observer: GenerationObserver.fromPrinter(new ConsolePrinter({ tag: 'chess-commentary' })),
92
+ });
93
+
94
+ const commentaryText = Function.pipe(
95
+ result,
96
+ Array.findLast((msg) => msg.sender.role === 'assistant' && msg.blocks.some((block) => block._tag === 'text')),
97
+ Option.flatMap((msg) =>
98
+ Function.pipe(
99
+ msg.blocks,
100
+ Array.findLast((block) => block._tag === 'text'),
101
+ Option.map((block) => block.text),
102
+ ),
103
+ ),
104
+ Option.getOrThrowWith(() => new Error('No commentary generated')),
105
+ );
106
+
107
+ const commentary = `## Move ${moveNumber}: ${player} plays ${moveNotation}\n\n${commentaryText}\n\n`;
108
+ log.info('commentary', { commentary });
109
+
110
+ // TODO(wittjosiah): Functions currently don't support traversals.
111
+ // const docs = yield* Database.Service.runQuery(
112
+ // Query.select(Filter.id(chessGame.id)).targetOf(HasSubject.HasSubject).source(),
113
+ // ).pipe(Effect.map((objects) => objects.filter((object) => Obj.instanceOf(Markdown.Document, object))));
114
+ const docs = yield* Database.Service.runQuery(Filter.type(HasSubject.HasSubject)).pipe(
115
+ Effect.map((relations) =>
116
+ relations.filter((relation) => {
117
+ // TODO(wittjosiah): This is a workaround for getTarget not handling deleted objects.
118
+ try {
119
+ log.info('relation', {
120
+ source: Obj.getDXN(Relation.getTarget(relation)).toString(),
121
+ game: Obj.getDXN(chessGame).toString(),
122
+ });
123
+ return Obj.getDXN(Relation.getTarget(relation)).toString() === Obj.getDXN(chessGame).toString();
124
+ } catch {
125
+ return false;
126
+ }
127
+ }),
128
+ ),
129
+ Effect.map((relations) =>
130
+ relations
131
+ .map((relation) => {
132
+ // TODO(wittjosiah): This is a workaround for getSource not handling deleted objects.
133
+ try {
134
+ return Relation.getSource(relation);
135
+ } catch {
136
+ return undefined;
137
+ }
138
+ })
139
+ .filter((source) => source !== undefined),
140
+ ),
141
+ Effect.map((sources) => {
142
+ const docs = sources.filter((source) => Obj.instanceOf(Markdown.Document, source));
143
+ log.info('docs', { sources, docs });
144
+ return docs;
145
+ }),
146
+ );
147
+ log.info('docs', { count: docs.length });
148
+
149
+ let document: Markdown.Document;
150
+ if (docs.length === 0) {
151
+ // TODO(wittjosiah): Deploy fails if `SpaceProperties` schema is imported because its from `client-protocol`.
152
+ const [properties] = yield* Database.Service.runQuery(Filter.typename('dxos.org/type/Properties'));
153
+ const rootCollection = yield* Database.Service.load<Collection.Collection>(
154
+ properties[Collection.Collection.typename],
155
+ );
156
+
157
+ log.info('rootCollection', { rootCollection });
158
+
159
+ // Create a new markdown document
160
+ const gameName = chessGame.name || 'Chess Game';
161
+ document = yield* Database.Service.add(
162
+ Markdown.make({
163
+ name: `${gameName} Commentary`,
164
+ content: `# ${gameName} Commentary\n\n${commentary}`,
165
+ }),
166
+ );
167
+
168
+ const documentRef = Ref.make(document);
169
+ Obj.change(rootCollection, (c) => {
170
+ c.objects.push(documentRef);
171
+ });
172
+
173
+ // Create the HasSubject relation
174
+ yield* Database.Service.add(
175
+ Relation.make(HasSubject.HasSubject, {
176
+ [Relation.Source]: document,
177
+ [Relation.Target]: chessGame,
178
+ completedAt: new Date().toISOString(),
179
+ }),
180
+ );
181
+ } else {
182
+ document = docs[0];
183
+
184
+ // Load the text content and append the commentary
185
+ const text = yield* Database.Service.load(document.content);
186
+ const accessor = createDocAccessor(text, ['content']);
187
+ accessor.handle.change((doc: A.Doc<Text.Text>) => {
188
+ A.splice(doc, accessor.path.slice(), text.content.length, 0, commentary);
189
+ });
190
+ }
191
+
192
+ log.info('result', { documentId: Obj.getDXN(document).toString(), commentary });
193
+
194
+ yield* Database.Service.flush();
195
+
196
+ return {
197
+ documentId: Obj.getDXN(document).toString(),
198
+ commentary,
199
+ };
200
+ },
201
+ Effect.provide(
202
+ Layer.mergeAll(
203
+ AiService.model('@anthropic/claude-haiku-4-5'),
204
+ ToolResolverService.layerEmpty,
205
+ ToolExecutionService.layerEmpty,
206
+ TracingService.layerNoop,
207
+ ),
208
+ ),
209
+ ),
210
+ });
211
+
212
+ const COMMENTARY_SYSTEM_PROMPT = trim`
213
+ You are a professional chess commentator providing live commentary for a chess match.
214
+
215
+ # Style
216
+ - Write in an engaging, enthusiastic style as if commentating for a live audience
217
+ - Be concise but informative (2-4 sentences)
218
+ - Explain the strategic implications of the move
219
+ - Note any tactical elements (captures, threats, checks)
220
+ - Comment on the position and what it means for the game
221
+
222
+ # Format
223
+ - Write in plain text (no markdown formatting in the commentary itself)
224
+ - Be natural and conversational
225
+ - Use chess terminology appropriately but keep it accessible
226
+
227
+ # Special Situations
228
+ - If it's checkmate, express excitement about the conclusion
229
+ - If it's check, note the pressure on the king
230
+ - If a piece is captured, mention the material exchange
231
+ - Comment on the development of pieces and control of key squares when relevant
232
+ `;
@@ -23,7 +23,7 @@ export default defineFunction({
23
23
  data: { documentAmount = 1, textSize = 10, mutationAmount = 0, waitAfterCreation = 10_000 },
24
24
  context: { space },
25
25
  }: any) => {
26
- await space.db.graph.schemaRegistry.addSchema([Expando]);
26
+ await space.db.graph.schemaRegistry.register([Expando]);
27
27
  const result: Record<string, any> = {};
28
28
  const objects: Expando[] = [];
29
29