@dxos/plugin-script 0.7.4 → 0.7.5-labs.a279d8c

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 (255) hide show
  1. package/dist/lib/browser/{AutomationPanel-PMTZROAZ.mjs → AutomationPanel-OOIRJFPJ.mjs} +4 -11
  2. package/dist/lib/browser/AutomationPanel-OOIRJFPJ.mjs.map +7 -0
  3. package/dist/lib/browser/ScriptContainer-T2AOMDT3.mjs +685 -0
  4. package/dist/lib/browser/ScriptContainer-T2AOMDT3.mjs.map +7 -0
  5. package/dist/lib/browser/{chunk-C7VBULMK.mjs → chunk-5BU5ERNU.mjs} +3 -3
  6. package/dist/lib/browser/chunk-5BU5ERNU.mjs.map +7 -0
  7. package/dist/lib/browser/chunk-REL2R7SB.mjs +52 -0
  8. package/dist/lib/browser/chunk-REL2R7SB.mjs.map +7 -0
  9. package/dist/lib/browser/{chunk-4UTRJLQ3.mjs → chunk-SDHKTS6H.mjs} +2 -51
  10. package/dist/lib/browser/{chunk-4UTRJLQ3.mjs.map → chunk-SDHKTS6H.mjs.map} +4 -4
  11. package/dist/lib/browser/chunk-SIOGRRPF.mjs +224 -0
  12. package/dist/lib/browser/chunk-SIOGRRPF.mjs.map +7 -0
  13. package/dist/lib/browser/{chunk-K7KY6YMG.mjs → chunk-SJ4J527G.mjs} +2 -2
  14. package/dist/lib/browser/chunk-XPGBHZ3L.mjs +40 -0
  15. package/dist/lib/browser/chunk-XPGBHZ3L.mjs.map +7 -0
  16. package/dist/lib/browser/chunk-ZM6T4HPR.mjs +15 -0
  17. package/dist/lib/browser/chunk-ZM6T4HPR.mjs.map +7 -0
  18. package/dist/lib/browser/compiler-HT53ILG7.mjs +84 -0
  19. package/dist/lib/browser/compiler-HT53ILG7.mjs.map +7 -0
  20. package/dist/lib/browser/index.mjs +107 -357
  21. package/dist/lib/browser/index.mjs.map +4 -4
  22. package/dist/lib/browser/intent-resolver-YPHT6HDZ.mjs +42 -0
  23. package/dist/lib/browser/intent-resolver-YPHT6HDZ.mjs.map +7 -0
  24. package/dist/lib/browser/meta.json +1 -1
  25. package/dist/lib/browser/react-surface-GAWVYTJ5.mjs +67 -0
  26. package/dist/lib/browser/react-surface-GAWVYTJ5.mjs.map +7 -0
  27. package/dist/lib/browser/settings-YQQEU3DF.mjs +24 -0
  28. package/dist/lib/browser/settings-YQQEU3DF.mjs.map +7 -0
  29. package/dist/lib/browser/types.mjs +10 -0
  30. package/dist/lib/node/{AutomationPanel-AAGQREH7.cjs → AutomationPanel-EPRDDR3A.cjs} +16 -17
  31. package/dist/lib/node/AutomationPanel-EPRDDR3A.cjs.map +7 -0
  32. package/dist/lib/node/ScriptContainer-BV56I4OL.cjs +689 -0
  33. package/dist/lib/node/ScriptContainer-BV56I4OL.cjs.map +7 -0
  34. package/dist/lib/node/chunk-5V3XGLTR.cjs +252 -0
  35. package/dist/lib/node/chunk-5V3XGLTR.cjs.map +7 -0
  36. package/dist/lib/node/chunk-6VKZJ4MH.cjs +60 -0
  37. package/dist/lib/node/chunk-6VKZJ4MH.cjs.map +7 -0
  38. package/dist/lib/node/{meta.cjs → chunk-A2DI2G4D.cjs} +12 -8
  39. package/dist/lib/node/chunk-A2DI2G4D.cjs.map +7 -0
  40. package/dist/lib/node/{chunk-4INUJLXL.cjs → chunk-DQRAVZM7.cjs} +6 -6
  41. package/dist/lib/node/{chunk-6LYX73ZT.cjs → chunk-EFTZN5X7.cjs} +7 -7
  42. package/dist/lib/node/chunk-EFTZN5X7.cjs.map +7 -0
  43. package/dist/lib/node/{chunk-WPP65EYS.cjs → chunk-T4TXCRN5.cjs} +6 -44
  44. package/dist/lib/node/chunk-T4TXCRN5.cjs.map +7 -0
  45. package/dist/lib/node/chunk-TJ4BTPOS.cjs +64 -0
  46. package/dist/lib/node/chunk-TJ4BTPOS.cjs.map +7 -0
  47. package/dist/lib/node/compiler-457ZR24G.cjs +104 -0
  48. package/dist/lib/node/compiler-457ZR24G.cjs.map +7 -0
  49. package/dist/lib/node/index.cjs +104 -346
  50. package/dist/lib/node/index.cjs.map +4 -4
  51. package/dist/lib/node/intent-resolver-SUAPE7H3.cjs +56 -0
  52. package/dist/lib/node/intent-resolver-SUAPE7H3.cjs.map +7 -0
  53. package/dist/lib/node/meta.json +1 -1
  54. package/dist/lib/node/react-surface-OMBMSFZT.cjs +86 -0
  55. package/dist/lib/node/react-surface-OMBMSFZT.cjs.map +7 -0
  56. package/dist/lib/node/settings-NGHDYAVK.cjs +38 -0
  57. package/dist/lib/node/settings-NGHDYAVK.cjs.map +7 -0
  58. package/dist/lib/node/{types/index.cjs → types.cjs} +6 -8
  59. package/dist/lib/node/types.cjs.map +7 -0
  60. package/dist/lib/node-esm/{AutomationPanel-ETQEDY5I.mjs → AutomationPanel-DMLAGQS5.mjs} +4 -11
  61. package/dist/lib/node-esm/AutomationPanel-DMLAGQS5.mjs.map +7 -0
  62. package/dist/lib/node-esm/ScriptContainer-3S5VHJVR.mjs +686 -0
  63. package/dist/lib/node-esm/ScriptContainer-3S5VHJVR.mjs.map +7 -0
  64. package/dist/lib/node-esm/chunk-675XSDRN.mjs +16 -0
  65. package/dist/lib/node-esm/chunk-675XSDRN.mjs.map +7 -0
  66. package/dist/lib/node-esm/{chunk-SLTZMY34.mjs → chunk-BHP545D7.mjs} +3 -3
  67. package/dist/lib/node-esm/chunk-BHP545D7.mjs.map +7 -0
  68. package/dist/lib/node-esm/{chunk-4SRPREUK.mjs → chunk-G76M6O46.mjs} +2 -51
  69. package/dist/lib/node-esm/{chunk-4SRPREUK.mjs.map → chunk-G76M6O46.mjs.map} +4 -4
  70. package/dist/lib/node-esm/chunk-JHGOPQVO.mjs +41 -0
  71. package/dist/lib/node-esm/chunk-JHGOPQVO.mjs.map +7 -0
  72. package/dist/lib/node-esm/chunk-JJZYWSD7.mjs +54 -0
  73. package/dist/lib/node-esm/chunk-JJZYWSD7.mjs.map +7 -0
  74. package/dist/lib/node-esm/chunk-XPIKUBGS.mjs +225 -0
  75. package/dist/lib/node-esm/chunk-XPIKUBGS.mjs.map +7 -0
  76. package/dist/lib/node-esm/{chunk-OFYGBUNI.mjs → chunk-XUWS7OTK.mjs} +2 -2
  77. package/dist/lib/node-esm/compiler-PEARFTFR.mjs +85 -0
  78. package/dist/lib/node-esm/compiler-PEARFTFR.mjs.map +7 -0
  79. package/dist/lib/node-esm/index.mjs +107 -357
  80. package/dist/lib/node-esm/index.mjs.map +4 -4
  81. package/dist/lib/node-esm/intent-resolver-SZJXQ3CW.mjs +43 -0
  82. package/dist/lib/node-esm/intent-resolver-SZJXQ3CW.mjs.map +7 -0
  83. package/dist/lib/node-esm/meta.json +1 -1
  84. package/dist/lib/node-esm/react-surface-J7NLV2V4.mjs +68 -0
  85. package/dist/lib/node-esm/react-surface-J7NLV2V4.mjs.map +7 -0
  86. package/dist/lib/node-esm/settings-XGXDY4NI.mjs +25 -0
  87. package/dist/lib/node-esm/settings-XGXDY4NI.mjs.map +7 -0
  88. package/dist/lib/node-esm/types.mjs +11 -0
  89. package/dist/types/src/ScriptPlugin.d.ts +1 -3
  90. package/dist/types/src/ScriptPlugin.d.ts.map +1 -1
  91. package/dist/types/src/capabilities/capabilities.d.ts +5 -0
  92. package/dist/types/src/capabilities/capabilities.d.ts.map +1 -0
  93. package/dist/types/src/capabilities/compiler.d.ts +4 -0
  94. package/dist/types/src/capabilities/compiler.d.ts.map +1 -0
  95. package/dist/types/src/capabilities/index.d.ts +6 -0
  96. package/dist/types/src/capabilities/index.d.ts.map +1 -0
  97. package/dist/types/src/capabilities/intent-resolver.d.ts +4 -0
  98. package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -0
  99. package/dist/types/src/capabilities/react-surface.d.ts +4 -0
  100. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -0
  101. package/dist/types/src/capabilities/settings.d.ts +4 -0
  102. package/dist/types/src/capabilities/settings.d.ts.map +1 -0
  103. package/dist/types/src/components/AutomationPanel/AutomationPanel.d.ts +2 -2
  104. package/dist/types/src/components/AutomationPanel/AutomationPanel.d.ts.map +1 -1
  105. package/dist/types/src/components/ScriptContainer.d.ts +10 -2
  106. package/dist/types/src/components/ScriptContainer.d.ts.map +1 -1
  107. package/dist/types/src/components/ScriptSettings/ScriptSettings.d.ts.map +1 -1
  108. package/dist/types/src/components/ScriptSettingsPanel.d.ts +1 -1
  109. package/dist/types/src/components/ScriptSettingsPanel.d.ts.map +1 -1
  110. package/dist/types/src/components/ScriptToolbar/ScriptToolbar.d.ts +11 -0
  111. package/dist/types/src/components/ScriptToolbar/ScriptToolbar.d.ts.map +1 -0
  112. package/dist/types/src/components/{Toolbar/Toolbar.stories.d.ts → ScriptToolbar/ScriptToolbar.stories.d.ts} +1 -1
  113. package/dist/types/src/components/ScriptToolbar/ScriptToolbar.stories.d.ts.map +1 -0
  114. package/dist/types/src/components/ScriptToolbar/deploy.d.ts +48 -0
  115. package/dist/types/src/components/ScriptToolbar/deploy.d.ts.map +1 -0
  116. package/dist/types/src/components/ScriptToolbar/format.d.ts +25 -0
  117. package/dist/types/src/components/ScriptToolbar/format.d.ts.map +1 -0
  118. package/dist/types/src/components/ScriptToolbar/index.d.ts +2 -0
  119. package/dist/types/src/components/ScriptToolbar/index.d.ts.map +1 -0
  120. package/dist/types/src/components/ScriptToolbar/templateSelect.d.ts +31 -0
  121. package/dist/types/src/components/ScriptToolbar/templateSelect.d.ts.map +1 -0
  122. package/dist/types/src/components/ScriptToolbar/useToolbarAction.d.ts +14 -0
  123. package/dist/types/src/components/ScriptToolbar/useToolbarAction.d.ts.map +1 -0
  124. package/dist/types/src/components/ScriptToolbar/useToolbarState.d.ts +10 -0
  125. package/dist/types/src/components/ScriptToolbar/useToolbarState.d.ts.map +1 -0
  126. package/dist/types/src/components/ScriptToolbar/view.d.ts +33 -0
  127. package/dist/types/src/components/ScriptToolbar/view.d.ts.map +1 -0
  128. package/dist/types/src/components/TypescriptEditor/TypescriptEditor.d.ts +4 -2
  129. package/dist/types/src/components/TypescriptEditor/TypescriptEditor.d.ts.map +1 -1
  130. package/dist/types/src/components/TypescriptEditor/TypescriptEditor.stories.d.ts.map +1 -1
  131. package/dist/types/src/components/index.d.ts +1 -1
  132. package/dist/types/src/components/index.d.ts.map +1 -1
  133. package/dist/types/src/index.d.ts +2 -4
  134. package/dist/types/src/index.d.ts.map +1 -1
  135. package/dist/types/src/meta.d.ts +1 -2
  136. package/dist/types/src/meta.d.ts.map +1 -1
  137. package/dist/types/src/templates/email.d.ts +2 -1
  138. package/dist/types/src/templates/email.d.ts.map +1 -1
  139. package/dist/types/src/{templates.d.ts → templates/index.d.ts} +1 -1
  140. package/dist/types/src/templates/index.d.ts.map +1 -0
  141. package/dist/types/src/translations.d.ts +48 -0
  142. package/dist/types/src/translations.d.ts.map +1 -1
  143. package/dist/types/src/types.d.ts +30 -0
  144. package/dist/types/src/types.d.ts.map +1 -0
  145. package/dist/types/tsconfig.tsbuildinfo +1 -0
  146. package/package.json +45 -55
  147. package/src/ScriptPlugin.tsx +65 -145
  148. package/src/bundler/bundler.test.ts +4 -3
  149. package/src/capabilities/capabilities.ts +12 -0
  150. package/src/capabilities/compiler.ts +33 -0
  151. package/src/capabilities/index.ts +12 -0
  152. package/src/capabilities/intent-resolver.ts +43 -0
  153. package/src/capabilities/react-surface.tsx +54 -0
  154. package/src/capabilities/settings.ts +14 -0
  155. package/src/compiler/compiler.browser.test.ts +1 -1
  156. package/src/components/AutomationPanel/AutomationPanel.tsx +2 -4
  157. package/src/components/FrameContainer/FrameContainer.tsx +1 -1
  158. package/src/components/ScriptContainer.tsx +64 -9
  159. package/src/components/ScriptSettings/ScriptSettings.tsx +25 -1
  160. package/src/components/ScriptSettingsPanel.tsx +125 -52
  161. package/src/components/{Toolbar/Toolbar.stories.tsx → ScriptToolbar/ScriptToolbar.stories.tsx} +2 -2
  162. package/src/components/ScriptToolbar/ScriptToolbar.tsx +51 -0
  163. package/src/components/ScriptToolbar/deploy.ts +157 -0
  164. package/src/components/ScriptToolbar/format.ts +47 -0
  165. package/src/components/{Toolbar → ScriptToolbar}/index.ts +1 -1
  166. package/src/components/ScriptToolbar/templateSelect.ts +64 -0
  167. package/src/components/ScriptToolbar/useToolbarAction.ts +54 -0
  168. package/src/components/ScriptToolbar/useToolbarState.ts +16 -0
  169. package/src/components/ScriptToolbar/view.ts +52 -0
  170. package/src/components/TypescriptEditor/TypescriptEditor.stories.tsx +2 -0
  171. package/src/components/TypescriptEditor/TypescriptEditor.tsx +73 -8
  172. package/src/index.ts +2 -6
  173. package/src/meta.ts +1 -1
  174. package/src/templates/email.ts +26 -23
  175. package/src/{templates.ts → templates/index.ts} +5 -5
  176. package/src/translations.ts +18 -1
  177. package/src/types.ts +39 -0
  178. package/dist/lib/browser/AutomationPanel-PMTZROAZ.mjs.map +0 -7
  179. package/dist/lib/browser/ScriptContainer-RYZFYCNK.mjs +0 -425
  180. package/dist/lib/browser/ScriptContainer-RYZFYCNK.mjs.map +0 -7
  181. package/dist/lib/browser/chunk-C7VBULMK.mjs.map +0 -7
  182. package/dist/lib/browser/chunk-QFZUFT5G.mjs +0 -48
  183. package/dist/lib/browser/chunk-QFZUFT5G.mjs.map +0 -7
  184. package/dist/lib/browser/chunk-U3OP64V4.mjs +0 -123
  185. package/dist/lib/browser/chunk-U3OP64V4.mjs.map +0 -7
  186. package/dist/lib/browser/edge/index.mjs +0 -19
  187. package/dist/lib/browser/meta.mjs +0 -9
  188. package/dist/lib/browser/types/index.mjs +0 -12
  189. package/dist/lib/browser/types/index.mjs.map +0 -7
  190. package/dist/lib/node/AutomationPanel-AAGQREH7.cjs.map +0 -7
  191. package/dist/lib/node/ScriptContainer-FZ44UIRC.cjs +0 -427
  192. package/dist/lib/node/ScriptContainer-FZ44UIRC.cjs.map +0 -7
  193. package/dist/lib/node/chunk-6LYX73ZT.cjs.map +0 -7
  194. package/dist/lib/node/chunk-CS25QNKZ.cjs +0 -151
  195. package/dist/lib/node/chunk-CS25QNKZ.cjs.map +0 -7
  196. package/dist/lib/node/chunk-DQYAU2CJ.cjs +0 -67
  197. package/dist/lib/node/chunk-DQYAU2CJ.cjs.map +0 -7
  198. package/dist/lib/node/chunk-WPP65EYS.cjs.map +0 -7
  199. package/dist/lib/node/edge/index.cjs +0 -41
  200. package/dist/lib/node/edge/index.cjs.map +0 -7
  201. package/dist/lib/node/meta.cjs.map +0 -7
  202. package/dist/lib/node/types/index.cjs.map +0 -7
  203. package/dist/lib/node-esm/AutomationPanel-ETQEDY5I.mjs.map +0 -7
  204. package/dist/lib/node-esm/ScriptContainer-3PKDW34A.mjs +0 -426
  205. package/dist/lib/node-esm/ScriptContainer-3PKDW34A.mjs.map +0 -7
  206. package/dist/lib/node-esm/chunk-36DLLQ6E.mjs +0 -125
  207. package/dist/lib/node-esm/chunk-36DLLQ6E.mjs.map +0 -7
  208. package/dist/lib/node-esm/chunk-GMVPKT6A.mjs +0 -49
  209. package/dist/lib/node-esm/chunk-GMVPKT6A.mjs.map +0 -7
  210. package/dist/lib/node-esm/chunk-SLTZMY34.mjs.map +0 -7
  211. package/dist/lib/node-esm/edge/index.mjs +0 -20
  212. package/dist/lib/node-esm/edge/index.mjs.map +0 -7
  213. package/dist/lib/node-esm/meta.mjs +0 -10
  214. package/dist/lib/node-esm/meta.mjs.map +0 -7
  215. package/dist/lib/node-esm/types/index.mjs +0 -13
  216. package/dist/lib/node-esm/types/index.mjs.map +0 -7
  217. package/dist/types/src/components/ScriptBlock/ScriptBlock.d.ts +0 -12
  218. package/dist/types/src/components/ScriptBlock/ScriptBlock.d.ts.map +0 -1
  219. package/dist/types/src/components/ScriptBlock/ScriptBlock.stories.d.ts +0 -6
  220. package/dist/types/src/components/ScriptBlock/ScriptBlock.stories.d.ts.map +0 -1
  221. package/dist/types/src/components/ScriptBlock/index.d.ts +0 -2
  222. package/dist/types/src/components/ScriptBlock/index.d.ts.map +0 -1
  223. package/dist/types/src/components/ScriptEditor.d.ts +0 -9
  224. package/dist/types/src/components/ScriptEditor.d.ts.map +0 -1
  225. package/dist/types/src/components/Toolbar/Toolbar.d.ts +0 -23
  226. package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +0 -1
  227. package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts.map +0 -1
  228. package/dist/types/src/components/Toolbar/index.d.ts +0 -2
  229. package/dist/types/src/components/Toolbar/index.d.ts.map +0 -1
  230. package/dist/types/src/edge/functions.d.ts +0 -25
  231. package/dist/types/src/edge/functions.d.ts.map +0 -1
  232. package/dist/types/src/edge/index.d.ts +0 -2
  233. package/dist/types/src/edge/index.d.ts.map +0 -1
  234. package/dist/types/src/templates.d.ts.map +0 -1
  235. package/dist/types/src/types/index.d.ts +0 -3
  236. package/dist/types/src/types/index.d.ts.map +0 -1
  237. package/dist/types/src/types/schema.d.ts +0 -71
  238. package/dist/types/src/types/schema.d.ts.map +0 -1
  239. package/dist/types/src/types/types.d.ts +0 -8
  240. package/dist/types/src/types/types.d.ts.map +0 -1
  241. package/src/components/ScriptBlock/ScriptBlock.stories.tsx +0 -52
  242. package/src/components/ScriptBlock/ScriptBlock.tsx +0 -102
  243. package/src/components/ScriptBlock/index.ts +0 -5
  244. package/src/components/ScriptEditor.tsx +0 -191
  245. package/src/components/Toolbar/Toolbar.tsx +0 -177
  246. package/src/edge/functions.ts +0 -116
  247. package/src/edge/index.ts +0 -7
  248. package/src/types/index.ts +0 -6
  249. package/src/types/schema.ts +0 -44
  250. package/src/types/types.ts +0 -29
  251. /package/dist/lib/browser/{chunk-K7KY6YMG.mjs.map → chunk-SJ4J527G.mjs.map} +0 -0
  252. /package/dist/lib/browser/{edge/index.mjs.map → types.mjs.map} +0 -0
  253. /package/dist/lib/node/{chunk-4INUJLXL.cjs.map → chunk-DQRAVZM7.cjs.map} +0 -0
  254. /package/dist/lib/node-esm/{chunk-OFYGBUNI.mjs.map → chunk-XUWS7OTK.mjs.map} +0 -0
  255. /package/dist/lib/{browser/meta.mjs.map → node-esm/types.mjs.map} +0 -0
@@ -3,156 +3,76 @@
3
3
  //
4
4
 
5
5
  // @ts-ignore
6
- import wasmUrl from 'esbuild-wasm/esbuild.wasm?url';
7
- import React from 'react';
8
6
 
9
- import { NavigationAction, parseIntentPlugin, type PluginDefinition, resolvePlugin } from '@dxos/app-framework';
10
- import { create } from '@dxos/live-object';
11
- import { parseClientPlugin } from '@dxos/plugin-client';
12
- import { type ActionGroup, createExtension, isActionGroup } from '@dxos/plugin-graph';
13
- import { TextType } from '@dxos/plugin-markdown/types';
14
- import { SpaceAction } from '@dxos/plugin-space';
15
- import { loadObjectReferences } from '@dxos/react-client/echo';
7
+ import {
8
+ Capabilities,
9
+ contributes,
10
+ createIntent,
11
+ defineModule,
12
+ definePlugin,
13
+ Events,
14
+ oneOf,
15
+ } from '@dxos/app-framework';
16
+ import { type Space } from '@dxos/client/echo';
17
+ import { FunctionType, ScriptType } from '@dxos/functions';
18
+ import { RefArray } from '@dxos/live-object';
19
+ import { ClientCapabilities, ClientEvents } from '@dxos/plugin-client';
16
20
 
17
- import { initializeBundler } from './bundler';
18
- import { Compiler } from './compiler';
19
- import { AutomationPanel, ScriptContainer, ScriptSettings, ScriptSettingsPanel } from './components';
20
- import meta, { SCRIPT_PLUGIN } from './meta';
21
- import { templates } from './templates';
21
+ import { Compiler, IntentResolver, ReactSurface, ScriptSettings } from './capabilities';
22
+ import { meta, SCRIPT_PLUGIN } from './meta';
22
23
  import translations from './translations';
23
- import { FunctionType, ScriptAction, type ScriptPluginProvides, ScriptType } from './types';
24
+ import { ScriptAction } from './types';
24
25
 
25
- export const ScriptPlugin = (): PluginDefinition<ScriptPluginProvides> => {
26
- const compiler = new Compiler();
27
-
28
- return {
29
- meta,
30
- initialize: async () => {
31
- await compiler.initialize();
32
- // TODO(wittjosiah): Fetch types for https modules.
33
- compiler.setFile('/src/typings.d.ts', "declare module 'https://*';");
34
- // TODO(wittjosiah): Proper function handler types.
35
- // TODO(wittjosiah): Remove.
36
- compiler.setFile(
37
- '/src/runtime.ts',
38
- `
39
- export const Filter: any = {};
40
- export type FunctionHandler = ({ event, context }: { event: any; context: any }) => Promise<Response>;
41
- export const functionHandler = (handler: FunctionHandler) => handler;
42
- `,
43
- );
44
- await initializeBundler({ wasmUrl });
45
- },
46
- provides: {
47
- settings: {},
48
- metadata: {
49
- records: {
50
- [ScriptType.typename]: {
51
- createObject: ScriptAction.CREATE,
26
+ export const ScriptPlugin = () =>
27
+ definePlugin(meta, [
28
+ defineModule({
29
+ id: `${meta.id}/module/settings`,
30
+ activatesOn: Events.SetupSettings,
31
+ activate: ScriptSettings,
32
+ }),
33
+ defineModule({
34
+ id: `${meta.id}/module/compiler`,
35
+ activatesOn: Events.Startup,
36
+ activate: Compiler,
37
+ }),
38
+ defineModule({
39
+ id: `${meta.id}/module/translations`,
40
+ activatesOn: Events.SetupTranslations,
41
+ activate: () => contributes(Capabilities.Translations, translations),
42
+ }),
43
+ defineModule({
44
+ id: `${meta.id}/module/metadata`,
45
+ activatesOn: oneOf(Events.Startup, Events.SetupAppGraph),
46
+ activate: () =>
47
+ contributes(Capabilities.Metadata, {
48
+ id: ScriptType.typename,
49
+ metadata: {
50
+ creationSchema: ScriptAction.CreateScriptSchema,
51
+ createObject: (props: ScriptAction.CreateScriptProps, { space }: { space: Space }) =>
52
+ createIntent(ScriptAction.Create, { ...props, space }),
52
53
  placeholder: ['object title placeholder', { ns: SCRIPT_PLUGIN }],
53
54
  icon: 'ph--code--regular',
54
55
  // TODO(wittjosiah): Move out of metadata.
55
- loadReferences: (script: ScriptType) => loadObjectReferences(script, (script) => [script.source]),
56
+ loadReferences: async (script: ScriptType) => await RefArray.loadAll([script.source]),
56
57
  },
57
- },
58
- },
59
- translations,
60
- echo: {
61
- schema: [ScriptType],
62
- system: [FunctionType],
63
- },
64
- graph: {
65
- builder: (plugins) => {
66
- const client = resolvePlugin(plugins, parseClientPlugin)?.provides.client;
67
- const dispatch = resolvePlugin(plugins, parseIntentPlugin)?.provides.intent.dispatch;
68
- if (!client || !dispatch) {
69
- return [];
70
- }
71
-
72
- return createExtension({
73
- id: ScriptAction.CREATE,
74
- filter: (node): node is ActionGroup => isActionGroup(node) && node.id.startsWith(SpaceAction.ADD_OBJECT),
75
- actions: ({ node }) => {
76
- const id = node.id.split('/').at(-1);
77
- const [spaceId, objectId] = id?.split(':') ?? [];
78
- const space = client.spaces.get().find((space) => space.id === spaceId);
79
- const object = objectId && space?.db.getObjectById(objectId);
80
- const target = objectId ? object : space;
81
- if (!target) {
82
- return;
83
- }
84
-
85
- return [
86
- {
87
- id: `${SCRIPT_PLUGIN}/create/${node.id}`,
88
- data: async () => {
89
- await dispatch([
90
- { plugin: SCRIPT_PLUGIN, action: ScriptAction.CREATE },
91
- { action: SpaceAction.ADD_OBJECT, data: { target } },
92
- { action: NavigationAction.OPEN },
93
- ]);
94
- },
95
- properties: {
96
- label: ['create object label', { ns: SCRIPT_PLUGIN }],
97
- icon: 'ph--code--regular',
98
- testId: 'scriptPlugin.createObject',
99
- },
100
- },
101
- ];
102
- },
103
- });
104
- },
105
- },
106
- surface: {
107
- component: ({ data, role }) => {
108
- switch (role) {
109
- case 'settings': {
110
- return data.plugin === meta.id ? <ScriptSettings settings={{}} /> : null;
111
- }
112
-
113
- case 'article': {
114
- if (data.object instanceof ScriptType) {
115
- return <ScriptContainer script={data.object} env={compiler.environment} />;
116
- }
117
- break;
118
- }
119
-
120
- case 'complementary--automation': {
121
- if (data.subject instanceof ScriptType) {
122
- return {
123
- node: <AutomationPanel subject={data.subject as any} />,
124
- disposition: 'hoist',
125
- };
126
- }
127
- break;
128
- }
129
-
130
- case 'complementary--settings': {
131
- if (data.subject instanceof ScriptType) {
132
- return <ScriptSettingsPanel script={data.subject} />;
133
- }
134
- break;
135
- }
136
- }
137
-
138
- return null;
139
- },
140
- },
141
- intent: {
142
- resolver: (intent) => {
143
- switch (intent.action) {
144
- case ScriptAction.CREATE: {
145
- return {
146
- data: create(ScriptType, {
147
- source: create(TextType, {
148
- content: templates[0].source,
149
- }),
150
- }),
151
- };
152
- }
153
- }
154
- },
155
- },
156
- },
157
- };
158
- };
58
+ }),
59
+ }),
60
+ defineModule({
61
+ id: `${meta.id}/module/schema`,
62
+ activatesOn: ClientEvents.SetupClient,
63
+ activate: () => [
64
+ contributes(ClientCapabilities.SystemSchema, [FunctionType]),
65
+ contributes(ClientCapabilities.Schema, [ScriptType]),
66
+ ],
67
+ }),
68
+ defineModule({
69
+ id: `${meta.id}/module/react-surface`,
70
+ activatesOn: Events.Startup,
71
+ activate: ReactSurface,
72
+ }),
73
+ defineModule({
74
+ id: `${meta.id}/module/intent-resolver`,
75
+ activatesOn: Events.SetupIntents,
76
+ activate: IntentResolver,
77
+ }),
78
+ ]);
@@ -35,11 +35,12 @@ describe('Bundler', () => {
35
35
  expect(result.error).to.not.exist;
36
36
  });
37
37
 
38
- test('HTTPS Import', async () => {
38
+ // TODO(dmaretskyi): Flaky on CI: https://cloud.nx.app/runs/Hjcifa8Ccq/task/plugin-script%3Atest
39
+ test.skip('HTTPS Import', async () => {
39
40
  const bundler = new Bundler({ platform: 'node', sandboxedModules: [], remoteModules: {} });
40
41
  const result = await bundler.bundle(`
41
- import { Octokit } from 'https://esm.sh/octokit';
42
- const octokit = new Octokit();
42
+ import { invariant } from 'https://esm.sh/@dxos/invariant';
43
+ invariant(true);
43
44
  `);
44
45
  expect(result.bundle).to.exist;
45
46
  expect(result.error).to.not.exist;
@@ -0,0 +1,12 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { defineCapability } from '@dxos/app-framework';
6
+
7
+ import { type Compiler } from '../compiler';
8
+ import { SCRIPT_PLUGIN } from '../meta';
9
+
10
+ export namespace ScriptCapabilities {
11
+ export const Compiler = defineCapability<Compiler>(`${SCRIPT_PLUGIN}/capability/compiler`);
12
+ }
@@ -0,0 +1,33 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ // @ts-ignore
6
+ import wasmUrl from 'esbuild-wasm/esbuild.wasm?url';
7
+
8
+ import { contributes } from '@dxos/app-framework';
9
+
10
+ import { ScriptCapabilities } from './capabilities';
11
+ import { initializeBundler } from '../bundler';
12
+ import { Compiler } from '../compiler';
13
+
14
+ export default async () => {
15
+ const compiler = new Compiler();
16
+
17
+ await compiler.initialize();
18
+ // TODO(wittjosiah): Fetch types for https modules.
19
+ compiler.setFile('/src/typings.d.ts', "declare module 'https://*';");
20
+ // TODO(wittjosiah): Proper function handler types.
21
+ // TODO(wittjosiah): Remove.
22
+ compiler.setFile(
23
+ '/src/runtime.ts',
24
+ `
25
+ export const Filter: any = {};
26
+ export type FunctionHandler = ({ event, context }: { event: any; context: any }) => Promise<Response>;
27
+ export const functionHandler = (handler: FunctionHandler) => handler;
28
+ `,
29
+ );
30
+ await initializeBundler({ wasmUrl });
31
+
32
+ return contributes(ScriptCapabilities.Compiler, compiler);
33
+ };
@@ -0,0 +1,12 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { lazy } from '@dxos/app-framework';
6
+
7
+ export const Compiler = lazy(() => import('./compiler'));
8
+ export const IntentResolver = lazy(() => import('./intent-resolver'));
9
+ export const ReactSurface = lazy(() => import('./react-surface'));
10
+ export const ScriptSettings = lazy(() => import('./settings'));
11
+
12
+ export * from './capabilities';
@@ -0,0 +1,43 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { Octokit } from '@octokit/core';
6
+
7
+ import { contributes, Capabilities, createResolver } from '@dxos/app-framework';
8
+ import { ScriptType } from '@dxos/functions';
9
+ import { create, makeRef } from '@dxos/live-object';
10
+ import { TextType } from '@dxos/schema';
11
+
12
+ import { templates } from '../templates';
13
+ import { ScriptAction } from '../types';
14
+
15
+ export default () =>
16
+ contributes(
17
+ Capabilities.IntentResolver,
18
+ createResolver(ScriptAction.Create, async ({ name, gistUrl, space }) => {
19
+ let content = templates[0].source;
20
+ const gistId = gistUrl?.split('/').at(-1);
21
+ if (gistId) {
22
+ // TODO(wittjosiah): Capability which contributes Octokit?
23
+ // NOTE: AccessToken not needed to read public gists.
24
+ const octokit = new Octokit();
25
+ const response = await octokit.request('GET /gists/{gist_id}', {
26
+ gist_id: gistId,
27
+ });
28
+ const gistContent = Object.values(response.data.files ?? {})[0]?.content;
29
+ if (gistContent) {
30
+ content = gistContent;
31
+ }
32
+ }
33
+
34
+ return {
35
+ data: {
36
+ object: create(ScriptType, {
37
+ name,
38
+ source: makeRef(create(TextType, { content })),
39
+ }),
40
+ },
41
+ };
42
+ }),
43
+ );
@@ -0,0 +1,54 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import React from 'react';
6
+
7
+ import { Capabilities, contributes, createSurface, useCapability } from '@dxos/app-framework';
8
+ import { ScriptType } from '@dxos/functions';
9
+ import { Clipboard } from '@dxos/react-ui';
10
+
11
+ import { ScriptCapabilities } from './capabilities';
12
+ import { AutomationPanel, ScriptSettings, ScriptContainer, ScriptSettingsPanel } from '../components';
13
+ import { SCRIPT_PLUGIN } from '../meta';
14
+ import { type ScriptSettingsProps } from '../types';
15
+
16
+ export default () =>
17
+ contributes(Capabilities.ReactSurface, [
18
+ createSurface({
19
+ id: `${SCRIPT_PLUGIN}/settings`,
20
+ role: 'settings',
21
+ filter: (data): data is any => data.subject === SCRIPT_PLUGIN,
22
+ component: () => {
23
+ const settings = useCapability(Capabilities.SettingsStore).getStore<ScriptSettingsProps>(SCRIPT_PLUGIN)!.value;
24
+ return <ScriptSettings settings={settings} />;
25
+ },
26
+ }),
27
+ createSurface({
28
+ id: `${SCRIPT_PLUGIN}/article`,
29
+ role: 'article',
30
+ filter: (data): data is { subject: ScriptType } => data.subject instanceof ScriptType,
31
+ component: ({ data, role }) => {
32
+ const compiler = useCapability(ScriptCapabilities.Compiler);
33
+ const settings = useCapability(Capabilities.SettingsStore).getStore<ScriptSettingsProps>(SCRIPT_PLUGIN)!.value;
34
+ return <ScriptContainer role={role} script={data.subject} settings={settings} env={compiler.environment} />;
35
+ },
36
+ }),
37
+ createSurface({
38
+ id: `${SCRIPT_PLUGIN}/automation`,
39
+ role: 'complementary--automation',
40
+ disposition: 'hoist',
41
+ filter: (data): data is { subject: ScriptType } => data.subject instanceof ScriptType,
42
+ component: ({ data }) => <AutomationPanel subject={data.subject} />,
43
+ }),
44
+ createSurface({
45
+ id: `${SCRIPT_PLUGIN}/settings-panel`,
46
+ role: 'complementary--settings',
47
+ filter: (data): data is { subject: ScriptType } => data.subject instanceof ScriptType,
48
+ component: ({ data }) => (
49
+ <Clipboard.Provider>
50
+ <ScriptSettingsPanel script={data.subject} />
51
+ </Clipboard.Provider>
52
+ ),
53
+ }),
54
+ ]);
@@ -0,0 +1,14 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { Capabilities, contributes } from '@dxos/app-framework';
6
+ import { create } from '@dxos/live-object';
7
+
8
+ import { SCRIPT_PLUGIN } from '../meta';
9
+ import { ScriptSettingsSchema } from '../types';
10
+
11
+ export default () => {
12
+ const settings = create(ScriptSettingsSchema, { editorInputMode: 'vscode' });
13
+ return contributes(Capabilities.Settings, { schema: ScriptSettingsSchema, prefix: SCRIPT_PLUGIN, value: settings });
14
+ };
@@ -12,7 +12,7 @@ describe('Compiler', () => {
12
12
  await compiler.initialize();
13
13
  compiler.setFile('/src/x.ts', 'export const x = 100');
14
14
  compiler.setFile('/src/y.ts', 'import { x } from "./x"; export const y = x + 100;');
15
- const result = await compiler.compile('/src/y.ts');
15
+ const result = compiler.compile('/src/y.ts');
16
16
  expect(result).to.exist;
17
17
  });
18
18
  });
@@ -4,15 +4,13 @@
4
4
 
5
5
  import React, { useMemo, useState } from 'react';
6
6
 
7
- import { type ReactiveEchoObject } from '@dxos/client/echo';
8
7
  import { failUndefined } from '@dxos/debug';
8
+ import { FunctionType, ScriptType, getInvocationUrl, getUserFunctionUrlInMetadata } from '@dxos/functions';
9
9
  import { useClient } from '@dxos/react-client';
10
- import { Filter, getMeta, getSpace, useQuery } from '@dxos/react-client/echo';
10
+ import { Filter, getMeta, getSpace, type ReactiveEchoObject, useQuery } from '@dxos/react-client/echo';
11
11
  import { Select, useTranslation } from '@dxos/react-ui';
12
12
 
13
- import { getInvocationUrl, getUserFunctionUrlInMetadata } from '../../edge';
14
13
  import { SCRIPT_PLUGIN } from '../../meta';
15
- import { FunctionType, ScriptType } from '../../types';
16
14
  import { DebugPanel } from '../DebugPanel';
17
15
 
18
16
  export interface AutomationPanelProps {
@@ -59,7 +59,7 @@ export const FrameContainer = ({ containerUrl, result, debug = true }: FrameCont
59
59
  className={mx(
60
60
  baseSurface,
61
61
  'flex absolute right-2 bottom-2 w-[400px] h-[200px] ring rounded',
62
- 'z-[100] overflow-x-hidden overflow-y-auto',
62
+ 'z-20 overflow-x-hidden overflow-y-auto',
63
63
  )}
64
64
  >
65
65
  <pre className='text-xs whitespace-break-spaces break-all p-2'>
@@ -2,20 +2,75 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import React from 'react';
5
+ import React, { useMemo } from 'react';
6
6
 
7
- import { fullyQualifiedId } from '@dxos/react-client/echo';
8
- import { useAttendableAttributes } from '@dxos/react-ui-attention';
7
+ import { type ScriptType } from '@dxos/functions';
8
+ import { createDocAccessor, getSpace } from '@dxos/react-client/echo';
9
+ import { useIdentity } from '@dxos/react-client/halo';
10
+ import { type ThemedClassName } from '@dxos/react-ui';
11
+ import { createDataExtensions, listener, stackItemContentEditorClassNames } from '@dxos/react-ui-editor';
12
+ import { StackItem } from '@dxos/react-ui-stack';
9
13
  import { mx } from '@dxos/react-ui-theme';
10
14
 
11
- import { ScriptEditor, type ScriptEditorProps } from './ScriptEditor';
15
+ import { DebugPanel } from './DebugPanel';
16
+ import { ScriptToolbar } from './ScriptToolbar';
17
+ import { useDeployState } from './ScriptToolbar/deploy';
18
+ import { useToolbarState } from './ScriptToolbar/useToolbarState';
19
+ import { TypescriptEditor, type TypescriptEditorProps } from './TypescriptEditor';
20
+ import { type ScriptSettingsProps } from '../types';
21
+
22
+ export type ScriptEditorProps = ThemedClassName<{
23
+ script: ScriptType;
24
+ settings: ScriptSettingsProps;
25
+ role?: string;
26
+ }> &
27
+ Pick<TypescriptEditorProps, 'env'>;
28
+
29
+ export const ScriptContainer = ({ role, classNames, script, settings, env }: ScriptEditorProps) => {
30
+ const identity = useIdentity();
31
+ const space = getSpace(script);
32
+
33
+ const extensions = useMemo(
34
+ () => [
35
+ listener({
36
+ onChange: (text) => {
37
+ if (script.source.target && script.source.target.content !== text) {
38
+ script.changed = true;
39
+ }
40
+ },
41
+ }),
42
+ createDataExtensions({
43
+ id: script.id,
44
+ text: script.source.target && createDocAccessor(script.source.target, ['content']),
45
+ space,
46
+ identity,
47
+ }),
48
+ ],
49
+ [script, script.source.target, space, identity],
50
+ );
51
+
52
+ const state = useToolbarState({ view: 'split' });
53
+ useDeployState({ state, script });
12
54
 
13
- const ScriptContainer = ({ script, ...props }: ScriptEditorProps) => {
14
- const attendableAttrs = useAttendableAttributes(fullyQualifiedId(script));
15
55
  return (
16
- <div role='none' className={mx('flex row-span-2 w-full overflow-hidden attention-surface')} {...attendableAttrs}>
17
- <ScriptEditor {...props} script={script} />
18
- </div>
56
+ <StackItem.Content toolbar>
57
+ <ScriptToolbar state={state} role={role} script={script} />
58
+ <div role='none' className={mx('flex flex-col w-full overflow-hidden divide-y divide-separator', classNames)}>
59
+ {state.view !== 'debug' && (
60
+ <TypescriptEditor
61
+ id={script.id}
62
+ env={env}
63
+ initialValue={script.source?.target?.content}
64
+ extensions={extensions}
65
+ className={stackItemContentEditorClassNames(role)}
66
+ inputMode={settings.editorInputMode}
67
+ toolbar
68
+ />
69
+ )}
70
+
71
+ {state.view !== 'editor' && <DebugPanel functionUrl={state.functionUrl} />}
72
+ </div>
73
+ </StackItem.Content>
19
74
  );
20
75
  };
21
76
 
@@ -6,7 +6,8 @@ import React from 'react';
6
6
 
7
7
  import { type Credential } from '@dxos/protocols/proto/dxos/halo/credentials';
8
8
  import { useClient } from '@dxos/react-client';
9
- import { Button, useTranslation } from '@dxos/react-ui';
9
+ import { Button, Select, useTranslation } from '@dxos/react-ui';
10
+ import { type EditorInputMode, EditorInputModes } from '@dxos/react-ui-editor';
10
11
  import { DeprecatedFormInput } from '@dxos/react-ui-form';
11
12
 
12
13
  import { SCRIPT_PLUGIN } from '../../meta';
@@ -39,9 +40,32 @@ export const ScriptSettings = ({ settings }: { settings: ScriptSettingsProps })
39
40
 
40
41
  return (
41
42
  <>
43
+ {/* TODO(wittjosiah): Hide outside of dev environments. */}
42
44
  <DeprecatedFormInput label={t('authenticate action label')}>
43
45
  <Button onClick={handleAuthenticate}>{t('authenticate button label')}</Button>
44
46
  </DeprecatedFormInput>
47
+
48
+ <DeprecatedFormInput label={t('editor input mode label')}>
49
+ <Select.Root
50
+ value={settings.editorInputMode ?? 'default'}
51
+ onValueChange={(value) => {
52
+ settings.editorInputMode = value as EditorInputMode;
53
+ }}
54
+ >
55
+ <Select.TriggerButton placeholder={t('select editor input mode placeholder')} />
56
+ <Select.Portal>
57
+ <Select.Content>
58
+ <Select.Viewport>
59
+ {EditorInputModes.map((mode) => (
60
+ <Select.Option key={mode} value={mode}>
61
+ {t(`settings editor input mode ${mode} label`)}
62
+ </Select.Option>
63
+ ))}
64
+ </Select.Viewport>
65
+ </Select.Content>
66
+ </Select.Portal>
67
+ </Select.Root>
68
+ </DeprecatedFormInput>
45
69
  </>
46
70
  );
47
71
  };