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

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 (209) hide show
  1. package/dist/lib/browser/{AutomationPanel-OOIRJFPJ.mjs → AutomationPanel-J3SZ5L3Y.mjs} +3 -3
  2. package/dist/lib/browser/{ScriptContainer-T2AOMDT3.mjs → ScriptContainer-JHAVO2KA.mjs} +98 -70
  3. package/dist/lib/browser/ScriptContainer-JHAVO2KA.mjs.map +7 -0
  4. package/dist/lib/browser/artifact-YCIVHFSS.mjs +243 -0
  5. package/dist/lib/browser/artifact-YCIVHFSS.mjs.map +7 -0
  6. package/dist/lib/browser/{chunk-SJ4J527G.mjs → chunk-45LXDWNF.mjs} +2 -2
  7. package/dist/lib/browser/{chunk-ZM6T4HPR.mjs → chunk-6MOQ4BP3.mjs} +2 -2
  8. package/dist/lib/browser/chunk-FVVCAWNP.mjs +21 -0
  9. package/dist/lib/browser/chunk-FVVCAWNP.mjs.map +7 -0
  10. package/dist/lib/browser/{chunk-XPGBHZ3L.mjs → chunk-N46LE7FS.mjs} +2 -2
  11. package/dist/lib/browser/{chunk-REL2R7SB.mjs → chunk-UDLKK74O.mjs} +20 -3
  12. package/dist/lib/browser/chunk-UDLKK74O.mjs.map +7 -0
  13. package/dist/lib/browser/{chunk-SIOGRRPF.mjs → chunk-WAXHENSY.mjs} +21 -9
  14. package/dist/lib/browser/chunk-WAXHENSY.mjs.map +7 -0
  15. package/dist/lib/browser/{compiler-HT53ILG7.mjs → compiler-YY2XSKHQ.mjs} +4 -6
  16. package/dist/lib/browser/compiler-YY2XSKHQ.mjs.map +7 -0
  17. package/dist/lib/browser/index.mjs +20 -18
  18. package/dist/lib/browser/index.mjs.map +3 -3
  19. package/dist/lib/browser/intent-resolver-RV3YXIVN.mjs +45 -0
  20. package/dist/lib/browser/intent-resolver-RV3YXIVN.mjs.map +7 -0
  21. package/dist/lib/browser/meta.json +1 -1
  22. package/dist/lib/browser/{react-surface-GAWVYTJ5.mjs → react-surface-ETY4XKFG.mjs} +12 -14
  23. package/dist/lib/browser/react-surface-ETY4XKFG.mjs.map +7 -0
  24. package/dist/lib/browser/{settings-YQQEU3DF.mjs → settings-SZCDKHWO.mjs} +3 -3
  25. package/dist/lib/browser/types.mjs +2 -2
  26. package/dist/lib/node/{AutomationPanel-EPRDDR3A.cjs → AutomationPanel-4M55FURO.cjs} +8 -8
  27. package/dist/lib/node/{ScriptContainer-BV56I4OL.cjs → ScriptContainer-EBIT6CT4.cjs} +101 -71
  28. package/dist/lib/node/ScriptContainer-EBIT6CT4.cjs.map +7 -0
  29. package/dist/lib/node/artifact-IPGGY2Z2.cjs +262 -0
  30. package/dist/lib/node/artifact-IPGGY2Z2.cjs.map +7 -0
  31. package/dist/lib/node/{chunk-5V3XGLTR.cjs → chunk-3VDHZ54A.cjs} +24 -12
  32. package/dist/lib/node/chunk-3VDHZ54A.cjs.map +7 -0
  33. package/dist/lib/node/{chunk-EFTZN5X7.cjs → chunk-5UH3F7TA.cjs} +8 -5
  34. package/dist/lib/node/chunk-5UH3F7TA.cjs.map +7 -0
  35. package/dist/lib/node/{chunk-A2DI2G4D.cjs → chunk-ALY3N6PW.cjs} +6 -6
  36. package/dist/lib/node/{chunk-6VKZJ4MH.cjs → chunk-DJGLGRQV.cjs} +6 -6
  37. package/dist/lib/node/{chunk-DQRAVZM7.cjs → chunk-IID7WUQS.cjs} +6 -6
  38. package/dist/lib/node/{chunk-TJ4BTPOS.cjs → chunk-JKPNBFU2.cjs} +19 -6
  39. package/dist/lib/node/chunk-JKPNBFU2.cjs.map +7 -0
  40. package/dist/lib/node/{compiler-457ZR24G.cjs → compiler-UIBLKJKG.cjs} +9 -9
  41. package/dist/lib/node/compiler-UIBLKJKG.cjs.map +7 -0
  42. package/dist/lib/node/index.cjs +38 -35
  43. package/dist/lib/node/index.cjs.map +3 -3
  44. package/dist/lib/node/{intent-resolver-SUAPE7H3.cjs → intent-resolver-WFLQNAID.cjs} +31 -28
  45. package/dist/lib/node/intent-resolver-WFLQNAID.cjs.map +7 -0
  46. package/dist/lib/node/meta.json +1 -1
  47. package/dist/lib/node/{react-surface-OMBMSFZT.cjs → react-surface-OIQJFA7P.cjs} +23 -25
  48. package/dist/lib/node/react-surface-OIQJFA7P.cjs.map +7 -0
  49. package/dist/lib/node/{settings-NGHDYAVK.cjs → settings-SZFSMSKM.cjs} +9 -9
  50. package/dist/lib/node/types.cjs +4 -4
  51. package/dist/lib/node/types.cjs.map +1 -1
  52. package/dist/lib/node-esm/{AutomationPanel-DMLAGQS5.mjs → AutomationPanel-W6SKG35R.mjs} +3 -3
  53. package/dist/lib/node-esm/{ScriptContainer-3S5VHJVR.mjs → ScriptContainer-QVFTCAML.mjs} +98 -70
  54. package/dist/lib/node-esm/ScriptContainer-QVFTCAML.mjs.map +7 -0
  55. package/dist/lib/node-esm/artifact-7H4HGX5W.mjs +245 -0
  56. package/dist/lib/node-esm/artifact-7H4HGX5W.mjs.map +7 -0
  57. package/dist/lib/node-esm/{chunk-JJZYWSD7.mjs → chunk-5CEKSMA5.mjs} +20 -3
  58. package/dist/lib/node-esm/chunk-5CEKSMA5.mjs.map +7 -0
  59. package/dist/lib/node-esm/{chunk-XUWS7OTK.mjs → chunk-CGF7EOGD.mjs} +2 -2
  60. package/dist/lib/node-esm/{chunk-675XSDRN.mjs → chunk-CP5LXTK5.mjs} +2 -2
  61. package/dist/lib/node-esm/{chunk-BHP545D7.mjs → chunk-P2V2Y5LV.mjs} +5 -2
  62. package/dist/lib/node-esm/chunk-P2V2Y5LV.mjs.map +7 -0
  63. package/dist/lib/node-esm/{chunk-JHGOPQVO.mjs → chunk-UNQFIERE.mjs} +2 -2
  64. package/dist/lib/node-esm/{chunk-XPIKUBGS.mjs → chunk-WCAUDRF4.mjs} +21 -9
  65. package/dist/lib/node-esm/chunk-WCAUDRF4.mjs.map +7 -0
  66. package/dist/lib/node-esm/{compiler-PEARFTFR.mjs → compiler-XTXFGZJM.mjs} +4 -6
  67. package/dist/lib/node-esm/compiler-XTXFGZJM.mjs.map +7 -0
  68. package/dist/lib/node-esm/index.mjs +20 -18
  69. package/dist/lib/node-esm/index.mjs.map +3 -3
  70. package/dist/lib/node-esm/intent-resolver-CYT6IYYH.mjs +46 -0
  71. package/dist/lib/node-esm/intent-resolver-CYT6IYYH.mjs.map +7 -0
  72. package/dist/lib/node-esm/meta.json +1 -1
  73. package/dist/lib/node-esm/{react-surface-J7NLV2V4.mjs → react-surface-N67GNKC2.mjs} +12 -14
  74. package/dist/lib/node-esm/react-surface-N67GNKC2.mjs.map +7 -0
  75. package/dist/lib/node-esm/{settings-XGXDY4NI.mjs → settings-GR4O2WHZ.mjs} +3 -3
  76. package/dist/lib/node-esm/types.mjs +2 -2
  77. package/dist/types/src/ScriptPlugin.d.ts.map +1 -1
  78. package/dist/types/src/capabilities/artifact.d.ts +11 -0
  79. package/dist/types/src/capabilities/artifact.d.ts.map +1 -0
  80. package/dist/types/src/capabilities/index.d.ts +5 -4
  81. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  82. package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -1
  83. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
  84. package/dist/types/src/components/FrameContainer/FrameContainer.d.ts +2 -2
  85. package/dist/types/src/components/FrameContainer/FrameContainer.d.ts.map +1 -1
  86. package/dist/types/src/components/ScriptContainer.d.ts +2 -2
  87. package/dist/types/src/components/ScriptContainer.d.ts.map +1 -1
  88. package/dist/types/src/components/ScriptSettingsPanel.d.ts.map +1 -1
  89. package/dist/types/src/components/ScriptToolbar/ScriptToolbar.d.ts +1 -1
  90. package/dist/types/src/components/ScriptToolbar/ScriptToolbar.d.ts.map +1 -1
  91. package/dist/types/src/components/index.d.ts +1 -1
  92. package/dist/types/src/components/index.d.ts.map +1 -1
  93. package/dist/types/src/hooks/deploy.d.ts.map +1 -0
  94. package/dist/types/src/hooks/format.d.ts.map +1 -0
  95. package/dist/types/src/hooks/index.d.ts +7 -0
  96. package/dist/types/src/hooks/index.d.ts.map +1 -0
  97. package/dist/types/src/{components/ScriptToolbar/templateSelect.d.ts → hooks/template.d.ts} +1 -1
  98. package/dist/types/src/hooks/template.d.ts.map +1 -0
  99. package/dist/types/src/{components/ScriptToolbar → hooks}/useToolbarAction.d.ts +1 -1
  100. package/dist/types/src/hooks/useToolbarAction.d.ts.map +1 -0
  101. package/dist/types/src/hooks/useToolbarState.d.ts.map +1 -0
  102. package/dist/types/src/hooks/view.d.ts.map +1 -0
  103. package/dist/types/src/index.d.ts +0 -1
  104. package/dist/types/src/index.d.ts.map +1 -1
  105. package/dist/types/src/meta.d.ts +1 -0
  106. package/dist/types/src/meta.d.ts.map +1 -1
  107. package/dist/types/src/templates/discord.d.ts +3 -0
  108. package/dist/types/src/templates/discord.d.ts.map +1 -0
  109. package/dist/types/src/templates/echo.d.ts.map +1 -1
  110. package/dist/types/src/templates/forex-effect.d.ts +6 -0
  111. package/dist/types/src/templates/forex-effect.d.ts.map +1 -0
  112. package/dist/types/src/templates/forex.d.ts +1 -1
  113. package/dist/types/src/templates/forex.d.ts.map +1 -1
  114. package/dist/types/src/templates/index.d.ts.map +1 -1
  115. package/dist/types/src/translations.d.ts +6 -0
  116. package/dist/types/src/translations.d.ts.map +1 -1
  117. package/dist/types/tsconfig.tsbuildinfo +1 -1
  118. package/package.json +41 -41
  119. package/src/ScriptPlugin.tsx +10 -13
  120. package/src/capabilities/artifact.ts +219 -0
  121. package/src/capabilities/compiler.ts +1 -1
  122. package/src/capabilities/index.ts +1 -0
  123. package/src/capabilities/intent-resolver.ts +25 -22
  124. package/src/capabilities/react-surface.tsx +8 -8
  125. package/src/components/FrameContainer/FrameContainer.tsx +4 -3
  126. package/src/components/ScriptContainer.tsx +10 -5
  127. package/src/components/ScriptSettings/ScriptSettings.tsx +3 -3
  128. package/src/components/ScriptSettingsPanel.tsx +16 -2
  129. package/src/components/ScriptToolbar/ScriptToolbar.tsx +8 -6
  130. package/src/components/TypescriptEditor/TypescriptEditor.tsx +3 -3
  131. package/src/{components/ScriptToolbar → hooks}/deploy.ts +16 -4
  132. package/src/{components/ScriptToolbar → hooks}/format.ts +1 -1
  133. package/src/hooks/index.ts +11 -0
  134. package/src/{components/ScriptToolbar/templateSelect.ts → hooks/template.ts} +2 -2
  135. package/src/{components/ScriptToolbar → hooks}/useToolbarAction.ts +1 -1
  136. package/src/{components/ScriptToolbar → hooks}/view.ts +1 -1
  137. package/src/index.ts +0 -1
  138. package/src/meta.ts +3 -1
  139. package/src/templates/discord.ts +88 -0
  140. package/src/templates/echo.ts +5 -1
  141. package/src/templates/forex-effect.ts +44 -0
  142. package/src/templates/forex.ts +21 -13
  143. package/src/templates/index.ts +15 -0
  144. package/src/translations.ts +2 -0
  145. package/dist/lib/browser/ScriptContainer-T2AOMDT3.mjs.map +0 -7
  146. package/dist/lib/browser/chunk-5BU5ERNU.mjs +0 -18
  147. package/dist/lib/browser/chunk-5BU5ERNU.mjs.map +0 -7
  148. package/dist/lib/browser/chunk-REL2R7SB.mjs.map +0 -7
  149. package/dist/lib/browser/chunk-SDHKTS6H.mjs +0 -237
  150. package/dist/lib/browser/chunk-SDHKTS6H.mjs.map +0 -7
  151. package/dist/lib/browser/chunk-SIOGRRPF.mjs.map +0 -7
  152. package/dist/lib/browser/compiler-HT53ILG7.mjs.map +0 -7
  153. package/dist/lib/browser/intent-resolver-YPHT6HDZ.mjs +0 -42
  154. package/dist/lib/browser/intent-resolver-YPHT6HDZ.mjs.map +0 -7
  155. package/dist/lib/browser/react-surface-GAWVYTJ5.mjs.map +0 -7
  156. package/dist/lib/node/ScriptContainer-BV56I4OL.cjs.map +0 -7
  157. package/dist/lib/node/chunk-5V3XGLTR.cjs.map +0 -7
  158. package/dist/lib/node/chunk-EFTZN5X7.cjs.map +0 -7
  159. package/dist/lib/node/chunk-T4TXCRN5.cjs +0 -260
  160. package/dist/lib/node/chunk-T4TXCRN5.cjs.map +0 -7
  161. package/dist/lib/node/chunk-TJ4BTPOS.cjs.map +0 -7
  162. package/dist/lib/node/compiler-457ZR24G.cjs.map +0 -7
  163. package/dist/lib/node/intent-resolver-SUAPE7H3.cjs.map +0 -7
  164. package/dist/lib/node/react-surface-OMBMSFZT.cjs.map +0 -7
  165. package/dist/lib/node-esm/ScriptContainer-3S5VHJVR.mjs.map +0 -7
  166. package/dist/lib/node-esm/chunk-BHP545D7.mjs.map +0 -7
  167. package/dist/lib/node-esm/chunk-G76M6O46.mjs +0 -239
  168. package/dist/lib/node-esm/chunk-G76M6O46.mjs.map +0 -7
  169. package/dist/lib/node-esm/chunk-JJZYWSD7.mjs.map +0 -7
  170. package/dist/lib/node-esm/chunk-XPIKUBGS.mjs.map +0 -7
  171. package/dist/lib/node-esm/compiler-PEARFTFR.mjs.map +0 -7
  172. package/dist/lib/node-esm/intent-resolver-SZJXQ3CW.mjs +0 -43
  173. package/dist/lib/node-esm/intent-resolver-SZJXQ3CW.mjs.map +0 -7
  174. package/dist/lib/node-esm/react-surface-J7NLV2V4.mjs.map +0 -7
  175. package/dist/types/src/bundler/bundler.d.ts +0 -39
  176. package/dist/types/src/bundler/bundler.d.ts.map +0 -1
  177. package/dist/types/src/bundler/bundler.test.d.ts +0 -2
  178. package/dist/types/src/bundler/bundler.test.d.ts.map +0 -1
  179. package/dist/types/src/bundler/index.d.ts +0 -2
  180. package/dist/types/src/bundler/index.d.ts.map +0 -1
  181. package/dist/types/src/components/ScriptToolbar/deploy.d.ts.map +0 -1
  182. package/dist/types/src/components/ScriptToolbar/format.d.ts.map +0 -1
  183. package/dist/types/src/components/ScriptToolbar/templateSelect.d.ts.map +0 -1
  184. package/dist/types/src/components/ScriptToolbar/useToolbarAction.d.ts.map +0 -1
  185. package/dist/types/src/components/ScriptToolbar/useToolbarState.d.ts.map +0 -1
  186. package/dist/types/src/components/ScriptToolbar/view.d.ts.map +0 -1
  187. package/src/bundler/bundler.test.ts +0 -55
  188. package/src/bundler/bundler.ts +0 -250
  189. package/src/bundler/index.ts +0 -5
  190. /package/dist/lib/browser/{AutomationPanel-OOIRJFPJ.mjs.map → AutomationPanel-J3SZ5L3Y.mjs.map} +0 -0
  191. /package/dist/lib/browser/{chunk-SJ4J527G.mjs.map → chunk-45LXDWNF.mjs.map} +0 -0
  192. /package/dist/lib/browser/{chunk-ZM6T4HPR.mjs.map → chunk-6MOQ4BP3.mjs.map} +0 -0
  193. /package/dist/lib/browser/{chunk-XPGBHZ3L.mjs.map → chunk-N46LE7FS.mjs.map} +0 -0
  194. /package/dist/lib/browser/{settings-YQQEU3DF.mjs.map → settings-SZCDKHWO.mjs.map} +0 -0
  195. /package/dist/lib/node/{AutomationPanel-EPRDDR3A.cjs.map → AutomationPanel-4M55FURO.cjs.map} +0 -0
  196. /package/dist/lib/node/{chunk-A2DI2G4D.cjs.map → chunk-ALY3N6PW.cjs.map} +0 -0
  197. /package/dist/lib/node/{chunk-6VKZJ4MH.cjs.map → chunk-DJGLGRQV.cjs.map} +0 -0
  198. /package/dist/lib/node/{chunk-DQRAVZM7.cjs.map → chunk-IID7WUQS.cjs.map} +0 -0
  199. /package/dist/lib/node/{settings-NGHDYAVK.cjs.map → settings-SZFSMSKM.cjs.map} +0 -0
  200. /package/dist/lib/node-esm/{AutomationPanel-DMLAGQS5.mjs.map → AutomationPanel-W6SKG35R.mjs.map} +0 -0
  201. /package/dist/lib/node-esm/{chunk-XUWS7OTK.mjs.map → chunk-CGF7EOGD.mjs.map} +0 -0
  202. /package/dist/lib/node-esm/{chunk-675XSDRN.mjs.map → chunk-CP5LXTK5.mjs.map} +0 -0
  203. /package/dist/lib/node-esm/{chunk-JHGOPQVO.mjs.map → chunk-UNQFIERE.mjs.map} +0 -0
  204. /package/dist/lib/node-esm/{settings-XGXDY4NI.mjs.map → settings-GR4O2WHZ.mjs.map} +0 -0
  205. /package/dist/types/src/{components/ScriptToolbar → hooks}/deploy.d.ts +0 -0
  206. /package/dist/types/src/{components/ScriptToolbar → hooks}/format.d.ts +0 -0
  207. /package/dist/types/src/{components/ScriptToolbar → hooks}/useToolbarState.d.ts +0 -0
  208. /package/dist/types/src/{components/ScriptToolbar → hooks}/view.d.ts +0 -0
  209. /package/src/{components/ScriptToolbar → hooks}/useToolbarState.ts +0 -0
@@ -6,6 +6,7 @@ import React from 'react';
6
6
 
7
7
  import { Capabilities, contributes, createSurface, useCapability } from '@dxos/app-framework';
8
8
  import { ScriptType } from '@dxos/functions';
9
+ import { SettingsStore } from '@dxos/local-storage';
9
10
  import { Clipboard } from '@dxos/react-ui';
10
11
 
11
12
  import { ScriptCapabilities } from './capabilities';
@@ -17,12 +18,10 @@ export default () =>
17
18
  contributes(Capabilities.ReactSurface, [
18
19
  createSurface({
19
20
  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
- },
21
+ role: 'article',
22
+ filter: (data): data is { subject: SettingsStore<ScriptSettingsProps> } =>
23
+ data.subject instanceof SettingsStore && data.subject.prefix === SCRIPT_PLUGIN,
24
+ component: ({ data: { subject } }) => <ScriptSettings settings={subject.value} />,
26
25
  }),
27
26
  createSurface({
28
27
  id: `${SCRIPT_PLUGIN}/article`,
@@ -30,14 +29,15 @@ export default () =>
30
29
  filter: (data): data is { subject: ScriptType } => data.subject instanceof ScriptType,
31
30
  component: ({ data, role }) => {
32
31
  const compiler = useCapability(ScriptCapabilities.Compiler);
33
- const settings = useCapability(Capabilities.SettingsStore).getStore<ScriptSettingsProps>(SCRIPT_PLUGIN)!.value;
32
+ // TODO(dmaretskyi): Since settings store is not reactive, this would break on the script plugin being enabled without a page reload.
33
+ const settings = useCapability(Capabilities.SettingsStore).getStore<ScriptSettingsProps>(SCRIPT_PLUGIN)?.value;
34
34
  return <ScriptContainer role={role} script={data.subject} settings={settings} env={compiler.environment} />;
35
35
  },
36
36
  }),
37
37
  createSurface({
38
38
  id: `${SCRIPT_PLUGIN}/automation`,
39
39
  role: 'complementary--automation',
40
- disposition: 'hoist',
40
+ position: 'hoist',
41
41
  filter: (data): data is { subject: ScriptType } => data.subject instanceof ScriptType,
42
42
  component: ({ data }) => <AutomationPanel subject={data.subject} />,
43
43
  }),
@@ -5,17 +5,17 @@
5
5
  import React, { useEffect, useRef } from 'react';
6
6
 
7
7
  import { clientServiceBundle } from '@dxos/client-protocol';
8
+ import { type BundleResult } from '@dxos/functions/bundler';
9
+ import { invariant } from '@dxos/invariant';
8
10
  import { log } from '@dxos/log';
9
11
  import { useClient } from '@dxos/react-client';
10
12
  import { baseSurface, mx } from '@dxos/react-ui-theme';
11
13
  import { createProtoRpcPeer } from '@dxos/rpc';
12
14
  import { createIFramePort } from '@dxos/rpc-tunnel';
13
15
 
14
- import { type BundlerResult } from '../../bundler';
15
-
16
16
  export type FrameContainerProps = {
17
17
  containerUrl: string;
18
- result: BundlerResult;
18
+ result: BundleResult;
19
19
  debug?: boolean;
20
20
  };
21
21
 
@@ -46,6 +46,7 @@ export const FrameContainer = ({ containerUrl, result, debug = true }: FrameCont
46
46
  }, [iframeRef]);
47
47
 
48
48
  // Encodes compiled code via URL.
49
+ invariant(result.sourceHash, 'Source hash is required.');
49
50
  const sourceHash = Buffer.from(result.sourceHash).toString('hex');
50
51
  const src = result.bundle && `${containerUrl}?ts=${sourceHash}#code=${encodeURIComponent(result.bundle)}`;
51
52
 
@@ -14,19 +14,24 @@ import { mx } from '@dxos/react-ui-theme';
14
14
 
15
15
  import { DebugPanel } from './DebugPanel';
16
16
  import { ScriptToolbar } from './ScriptToolbar';
17
- import { useDeployState } from './ScriptToolbar/deploy';
18
- import { useToolbarState } from './ScriptToolbar/useToolbarState';
19
17
  import { TypescriptEditor, type TypescriptEditorProps } from './TypescriptEditor';
18
+ import { useDeployState, useToolbarState } from '../hooks';
20
19
  import { type ScriptSettingsProps } from '../types';
21
20
 
22
21
  export type ScriptEditorProps = ThemedClassName<{
23
22
  script: ScriptType;
24
- settings: ScriptSettingsProps;
23
+ settings?: ScriptSettingsProps;
25
24
  role?: string;
26
25
  }> &
27
26
  Pick<TypescriptEditorProps, 'env'>;
28
27
 
29
- export const ScriptContainer = ({ role, classNames, script, settings, env }: ScriptEditorProps) => {
28
+ export const ScriptContainer = ({
29
+ role,
30
+ classNames,
31
+ script,
32
+ settings = { editorInputMode: 'vscode' },
33
+ env,
34
+ }: ScriptEditorProps) => {
30
35
  const identity = useIdentity();
31
36
  const space = getSpace(script);
32
37
 
@@ -49,7 +54,7 @@ export const ScriptContainer = ({ role, classNames, script, settings, env }: Scr
49
54
  [script, script.source.target, space, identity],
50
55
  );
51
56
 
52
- const state = useToolbarState({ view: 'split' });
57
+ const state = useToolbarState({ view: 'editor' });
53
58
  useDeployState({ state, script });
54
59
 
55
60
  return (
@@ -8,7 +8,7 @@ import { type Credential } from '@dxos/protocols/proto/dxos/halo/credentials';
8
8
  import { useClient } from '@dxos/react-client';
9
9
  import { Button, Select, useTranslation } from '@dxos/react-ui';
10
10
  import { type EditorInputMode, EditorInputModes } from '@dxos/react-ui-editor';
11
- import { DeprecatedFormInput } from '@dxos/react-ui-form';
11
+ import { DeprecatedFormContainer, DeprecatedFormInput } from '@dxos/react-ui-form';
12
12
 
13
13
  import { SCRIPT_PLUGIN } from '../../meta';
14
14
  import { type ScriptSettingsProps } from '../../types';
@@ -39,7 +39,7 @@ export const ScriptSettings = ({ settings }: { settings: ScriptSettingsProps })
39
39
  };
40
40
 
41
41
  return (
42
- <>
42
+ <DeprecatedFormContainer>
43
43
  {/* TODO(wittjosiah): Hide outside of dev environments. */}
44
44
  <DeprecatedFormInput label={t('authenticate action label')}>
45
45
  <Button onClick={handleAuthenticate}>{t('authenticate button label')}</Button>
@@ -66,6 +66,6 @@ export const ScriptSettings = ({ settings }: { settings: ScriptSettingsProps })
66
66
  </Select.Portal>
67
67
  </Select.Root>
68
68
  </DeprecatedFormInput>
69
- </>
69
+ </DeprecatedFormContainer>
70
70
  );
71
71
  };
@@ -10,7 +10,7 @@ import { FunctionType, type ScriptType, getInvocationUrl, getUserFunctionUrlInMe
10
10
  import { log } from '@dxos/log';
11
11
  import { useClient } from '@dxos/react-client';
12
12
  import { Filter, getMeta, getSpace, useQuery } from '@dxos/react-client/echo';
13
- import { Button, Clipboard, Input, Separator, useControlledValue, useTranslation } from '@dxos/react-ui';
13
+ import { Button, Clipboard, Input, Separator, useControlledState, useTranslation } from '@dxos/react-ui';
14
14
  import { AccessTokenType } from '@dxos/schema';
15
15
 
16
16
  import { SCRIPT_PLUGIN } from '../meta';
@@ -57,7 +57,7 @@ export const ScriptSettingsPanel = ({ script }: ScriptSettingsPanelProps) => {
57
57
  return () => clearTimeout(timeout);
58
58
  }, [githubToken, gistKey]);
59
59
 
60
- const [binding, setBinding] = useControlledValue(fn?.binding ?? '');
60
+ const [binding, setBinding] = useControlledState(fn?.binding ?? '');
61
61
  const handleBindingChange = useCallback(
62
62
  (event: ChangeEvent<HTMLInputElement>) => {
63
63
  setBinding(event.target.value);
@@ -114,6 +114,20 @@ export const ScriptSettingsPanel = ({ script }: ScriptSettingsPanelProps) => {
114
114
 
115
115
  return (
116
116
  <>
117
+ <div role='form' className='flex flex-col w-full p-2 gap-4'>
118
+ <Input.Root>
119
+ <div role='none' className='flex flex-col gap-1'>
120
+ <Input.Label>{t('description label')}</Input.Label>
121
+ <Input.TextInput
122
+ placeholder={t('description placeholder')}
123
+ value={script.description ?? ''}
124
+ onChange={(event) => {
125
+ script.description = event.target.value;
126
+ }}
127
+ />
128
+ </div>
129
+ </Input.Root>
130
+ </div>
117
131
  {fn && functionUrl && (
118
132
  <>
119
133
  <Separator />
@@ -10,12 +10,14 @@ import { ElevationProvider, type ThemedClassName } from '@dxos/react-ui';
10
10
  import { stackItemContentToolbarClassNames } from '@dxos/react-ui-editor';
11
11
  import { createGapSeparator, MenuProvider, ToolbarMenu, useMenuActions } from '@dxos/react-ui-menu';
12
12
 
13
- import { createDeploy } from './deploy';
14
- import { createFormat } from './format';
15
- import { createTemplateSelect } from './templateSelect';
16
- import { useToolbarAction } from './useToolbarAction';
17
- import { type ScriptToolbarState } from './useToolbarState';
18
- import { createView } from './view';
13
+ import {
14
+ type ScriptToolbarState,
15
+ createDeploy,
16
+ createFormat,
17
+ createTemplateSelect,
18
+ createView,
19
+ useToolbarAction,
20
+ } from '../../hooks';
19
21
 
20
22
  export type ScriptToolbarProps = ThemedClassName<{
21
23
  role?: string;
@@ -27,7 +27,7 @@ import {
27
27
  useTextEditor,
28
28
  type UseTextEditorProps,
29
29
  } from '@dxos/react-ui-editor';
30
- import { nonNullable } from '@dxos/util';
30
+ import { isNonNullable } from '@dxos/util';
31
31
 
32
32
  export type TypescriptEditorProps = {
33
33
  id: string;
@@ -94,7 +94,7 @@ export const TypescriptEditor = ({
94
94
  ]
95
95
  : [],
96
96
  ],
97
- ].filter(nonNullable),
97
+ ].filter(isNonNullable),
98
98
  selection,
99
99
  scrollTo,
100
100
  }),
@@ -127,7 +127,7 @@ const createTooltipRenderer = (themeMode: ThemeMode) => {
127
127
 
128
128
  return (info: HoverInfo) => {
129
129
  const div = document.createElement('div');
130
- div.className = 'p-1 rounded border border-separator bg-base xs:max-w-80 max-w-lg';
130
+ div.className = 'p-1 rounded border border-separator bg-baseSurface xs:max-w-80 max-w-lg';
131
131
 
132
132
  if (info.quickInfo?.displayParts) {
133
133
  for (const part of info.quickInfo.displayParts) {
@@ -6,13 +6,14 @@ import { useCallback, useEffect, useMemo } from 'react';
6
6
 
7
7
  import {
8
8
  FunctionType,
9
+ type ScriptType,
9
10
  getInvocationUrl,
10
11
  getUserFunctionUrlInMetadata,
11
12
  incrementSemverPatch,
12
- type ScriptType,
13
13
  setUserFunctionUrlInMetadata,
14
14
  uploadWorkerFunction,
15
15
  } from '@dxos/functions';
16
+ import { Bundler } from '@dxos/functions/bundler';
16
17
  import { log } from '@dxos/log';
17
18
  import { useClient } from '@dxos/react-client';
18
19
  import { Filter, create, getMeta, getSpace, makeRef, useQuery } from '@dxos/react-client/echo';
@@ -20,8 +21,7 @@ import { useTranslation } from '@dxos/react-ui';
20
21
  import { createMenuAction } from '@dxos/react-ui-menu';
21
22
 
22
23
  import { type ViewState } from './view';
23
- import { Bundler } from '../../bundler';
24
- import { SCRIPT_PLUGIN } from '../../meta';
24
+ import { SCRIPT_PLUGIN } from '../meta';
25
25
 
26
26
  export type DeployActionProperties = { type: 'deploy' } | { type: 'copy' };
27
27
 
@@ -105,7 +105,7 @@ export const useDeployHandler = ({ state, script }: { state: Partial<DeployState
105
105
  const existingFunctionId = existingFunctionUrl?.split('/').at(-1);
106
106
 
107
107
  const bundler = new Bundler({ platform: 'browser', sandboxedModules: [], remoteModules: {} });
108
- const buildResult = await bundler.bundle(script.source.target!.content);
108
+ const buildResult = await bundler.bundle({ source: script.source.target!.content });
109
109
  if (buildResult.error || !buildResult.bundle) {
110
110
  throw buildResult.error;
111
111
  }
@@ -130,12 +130,24 @@ export const useDeployHandler = ({ state, script }: { state: Partial<DeployState
130
130
  fn ?? space.db.add(create(FunctionType, { name: functionId, version, source: makeRef(script) }));
131
131
 
132
132
  script.changed = false;
133
+ if (script.description !== undefined && script.description.trim() !== '') {
134
+ deployedFunction.description = script.description;
135
+ } else if (meta.description) {
136
+ deployedFunction.description = meta.description;
137
+ } else {
138
+ log.verbose('no description in function metadata', { functionId });
139
+ }
133
140
 
134
141
  if (meta.inputSchema) {
135
142
  deployedFunction.inputSchema = meta.inputSchema;
136
143
  } else {
137
144
  log.verbose('no input schema in function metadata', { functionId });
138
145
  }
146
+ if (meta.outputSchema) {
147
+ deployedFunction.outputSchema = meta.outputSchema;
148
+ } else {
149
+ log.verbose('no output schema in function metadata', { functionId });
150
+ }
139
151
 
140
152
  setUserFunctionUrlInMetadata(getMeta(deployedFunction), `/${space.id}/${functionId}`);
141
153
 
@@ -11,7 +11,7 @@ import { type ScriptType } from '@dxos/functions';
11
11
  import { log } from '@dxos/log';
12
12
  import { createMenuAction } from '@dxos/react-ui-menu';
13
13
 
14
- import { SCRIPT_PLUGIN } from '../../meta';
14
+ import { SCRIPT_PLUGIN } from '../meta';
15
15
 
16
16
  export type FormatActionProperties = { type: 'format' };
17
17
 
@@ -0,0 +1,11 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ export * from './deploy';
6
+ export * from './format';
7
+ export * from './template';
8
+ export * from './view';
9
+
10
+ export * from './useToolbarAction';
11
+ export * from './useToolbarState';
@@ -8,8 +8,8 @@ import { FUNCTIONS_PRESET_META_KEY, type ScriptType } from '@dxos/functions';
8
8
  import { getMeta } from '@dxos/live-object';
9
9
  import { createMenuItemGroup, createMenuAction } from '@dxos/react-ui-menu';
10
10
 
11
- import { SCRIPT_PLUGIN } from '../../meta';
12
- import { templates } from '../../templates';
11
+ import { SCRIPT_PLUGIN } from '../meta';
12
+ import { templates } from '../templates';
13
13
 
14
14
  export type TemplateActionProperties = { type: 'template'; value: string };
15
15
 
@@ -10,7 +10,7 @@ import { type MenuAction, type MenuActionHandler } from '@dxos/react-ui-menu';
10
10
 
11
11
  import { type DeployActionProperties, useDeployHandler, useCopyHandler } from './deploy';
12
12
  import { type FormatActionProperties, useFormatHandler } from './format';
13
- import { type TemplateActionProperties, useTemplateSelectHandler } from './templateSelect';
13
+ import { type TemplateActionProperties, useTemplateSelectHandler } from './template';
14
14
  import { type ScriptToolbarState } from './useToolbarState';
15
15
  import { type ViewActionProperties } from './view';
16
16
 
@@ -4,7 +4,7 @@
4
4
 
5
5
  import { createMenuAction, createMenuItemGroup } from '@dxos/react-ui-menu';
6
6
 
7
- import { SCRIPT_PLUGIN } from '../../meta';
7
+ import { SCRIPT_PLUGIN } from '../meta';
8
8
 
9
9
  export type ViewType = 'editor' | 'split' | 'debug';
10
10
 
package/src/index.ts CHANGED
@@ -2,7 +2,6 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- export * from './bundler';
6
5
  export { ScriptCapabilities } from './capabilities';
7
6
  export * from './components';
8
7
  export * from './meta';
package/src/meta.ts CHANGED
@@ -9,8 +9,10 @@ export const SCRIPT_PLUGIN = 'dxos.org/plugin/script';
9
9
  export const meta = {
10
10
  id: SCRIPT_PLUGIN,
11
11
  name: 'Scripts',
12
- description: 'Distributed functions.',
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.',
13
14
  icon: 'ph--code--regular',
14
15
  source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/experimental/plugin-explorer',
15
16
  tags: ['experimental'],
17
+ screenshots: ['https://dxos.network/plugin-details-scripts-dark.png'],
16
18
  } satisfies PluginMeta;
@@ -0,0 +1,88 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ // @ts-ignore
6
+ import { createStatic, EchoObject, defineFunction, DXN, Filter, ObjectId, S } from 'dxos:functions';
7
+ import {
8
+ FetchHttpClient,
9
+ // @ts-ignore
10
+ } from 'https://esm.sh/@effect/platform@0.77.2?deps=effect@3.13.3';
11
+ // @ts-ignore
12
+ import { DiscordConfig, DiscordREST, DiscordRESTMemoryLive } from 'https://esm.sh/dfx@0.113.0?deps=effect@3.13.3';
13
+ // @ts-ignore
14
+ import { Effect, Config, Redacted } from 'https://esm.sh/effect@3.13.3';
15
+
16
+ const MessageSchema = S.Struct({
17
+ id: S.String,
18
+ foreignId: S.Number,
19
+ content: S.String,
20
+ }).pipe(EchoObject('example.com/type/Message', '0.1.0'));
21
+
22
+ export default defineFunction({
23
+ inputSchema: S.Struct({
24
+ // TODO(wittjosiah): Remove. This is used to provide a terminal for a cron trigger.
25
+ tick: S.optional(S.String),
26
+ channelId: S.String,
27
+ pageSize: S.optional(S.Number),
28
+ queueId: S.String,
29
+ }),
30
+
31
+ outputSchema: S.Struct({
32
+ newMessages: S.Number,
33
+ }),
34
+
35
+ handler: ({
36
+ event: {
37
+ data: { channelId, queueId, pageSize = 5 },
38
+ },
39
+ context: { space },
40
+ }: any) =>
41
+ Effect.gen(function* () {
42
+ const { token } = yield* Effect.tryPromise(() =>
43
+ space.db.query(Filter.typename('dxos.org/type/AccessToken', { source: 'discord.com' })).first(),
44
+ );
45
+
46
+ const enqueueMessages = Effect.gen(function* () {
47
+ const rest = yield* DiscordREST;
48
+ const { objects } = yield* Effect.tryPromise(() => space.queues.queryQueue(DXN.parse(queueId)));
49
+
50
+ let newMessages = 0;
51
+ let lastMessage = objects.at(-1);
52
+ while (true) {
53
+ // NOTE: If `after` is specified, the specified message is included in the results.
54
+ const messages = yield* rest
55
+ .getChannelMessages(channelId, { after: lastMessage?.foreignId, limit: pageSize })
56
+ .pipe((res: any) => res.json);
57
+ if (messages.length === 1) {
58
+ break;
59
+ }
60
+ const queueMessages = messages
61
+ .map((message: any) =>
62
+ createStatic(MessageSchema, {
63
+ id: ObjectId.random(),
64
+ foreignId: parseInt(message.id),
65
+ content: message.content,
66
+ }),
67
+ )
68
+ .slice(lastMessage ? 1 : 0)
69
+ .toReversed();
70
+ yield* Effect.tryPromise(() => space.queues.insertIntoQueue(DXN.parse(queueId), queueMessages));
71
+ newMessages += queueMessages.length;
72
+ lastMessage = queueMessages.at(-1);
73
+ }
74
+
75
+ return { newMessages };
76
+ }).pipe(
77
+ Effect.provide(DiscordRESTMemoryLive),
78
+ Effect.provide(
79
+ DiscordConfig.layerConfig({
80
+ token: Config.succeed(Redacted.make(token)),
81
+ }),
82
+ ),
83
+ Effect.provide(FetchHttpClient.layer),
84
+ );
85
+
86
+ return yield* enqueueMessages;
87
+ }),
88
+ });
@@ -11,5 +11,9 @@ export default async ({
11
11
  },
12
12
  }: any) => {
13
13
  const data = await request.json();
14
- return new Response(JSON.stringify(data ?? {}), { headers: { 'Content-Type': 'application/json' } });
14
+ return new Response(JSON.stringify(data ?? {}), {
15
+ headers: {
16
+ 'Content-Type': 'application/json',
17
+ },
18
+ });
15
19
  };
@@ -0,0 +1,44 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ // @ts-ignore
6
+ import { defineFunction, S } from 'dxos:functions';
7
+ import {
8
+ HttpClient,
9
+ HttpClientRequest,
10
+ FetchHttpClient,
11
+ // @ts-ignore
12
+ } from 'https://esm.sh/@effect/platform@0.77.2?deps=effect@3.13.3';
13
+ // @ts-ignore
14
+ import { Effect, Schedule } from 'https://esm.sh/effect@3.13.3';
15
+
16
+ /**
17
+ * Returns the exchange rate between two currencies.
18
+ */
19
+ export default defineFunction({
20
+ inputSchema: S.Struct({
21
+ from: S.String.annotations({ description: 'The source currency' }),
22
+ to: S.String.annotations({ description: 'The target currency' }),
23
+ }),
24
+
25
+ outputSchema: S.Struct({
26
+ rate: S.Number,
27
+ }),
28
+
29
+ handler: async ({
30
+ event: {
31
+ data: { from, to },
32
+ },
33
+ }: any) =>
34
+ Effect.gen(function* () {
35
+ const res = yield* HttpClientRequest.get(`https://free.ratesdb.com/v1/rates?from=${from}&to=${to}`).pipe(
36
+ HttpClient.execute,
37
+ Effect.flatMap((res: any) => res.json),
38
+ Effect.timeout('1 second'),
39
+ Effect.retry(Schedule.exponential(1000).pipe(Schedule.compose(Schedule.recurs(3)))),
40
+ Effect.scoped,
41
+ );
42
+ return { rate: res.data.rates[to].toString() };
43
+ }).pipe(Effect.provide(FetchHttpClient.layer)),
44
+ });
@@ -1,21 +1,29 @@
1
1
  //
2
- // Copyright 2024 DXOS.org
2
+ // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
+ // @ts-ignore
6
+ import { defineFunction, S } from 'dxos:functions';
7
+
5
8
  /**
6
9
  * Returns the exchange rate between two currencies.
7
10
  */
8
- export default async ({
9
- event: {
10
- data: { request },
11
- },
12
- }: any) => {
13
- const { args: [from = 'EUR', to = 'USD'] = [] } = await request.json();
11
+ export default defineFunction({
12
+ inputSchema: S.Struct({
13
+ from: S.String.annotations({ description: 'The source currency' }),
14
+ to: S.String.annotations({ description: 'The target currency' }),
15
+ }),
14
16
 
15
- const res = await fetch(`https://free.ratesdb.com/v1/rates?from=${from}&to=${to}`);
16
- const {
17
- data: { rates },
18
- } = await res.json();
17
+ handler: async ({
18
+ event: {
19
+ data: { from, to },
20
+ },
21
+ }: any) => {
22
+ const res = await fetch(`https://free.ratesdb.com/v1/rates?from=${from}&to=${to}`);
23
+ const {
24
+ data: { rates },
25
+ } = await res.json();
19
26
 
20
- return new Response(rates[to].toString());
21
- };
27
+ return rates[to].toString();
28
+ },
29
+ });
@@ -7,10 +7,14 @@ import chat from './chat.ts?raw';
7
7
  // @ts-ignore
8
8
  import chess from './chess.ts?raw';
9
9
  // @ts-ignore
10
+ import discord from './discord.ts?raw';
11
+ // @ts-ignore
10
12
  import echo from './echo.ts?raw';
11
13
  // @ts-ignore
12
14
  import email from './email.ts?raw';
13
15
  // @ts-ignore
16
+ import forexEffect from './forex-effect.ts?raw';
17
+ // @ts-ignore
14
18
  import forex from './forex.ts?raw';
15
19
 
16
20
  const removeHeader = (str: string) => str.split('\n').slice(4).join('\n');
@@ -33,6 +37,11 @@ export const templates: Template[] = [
33
37
  name: 'Forex',
34
38
  source: removeHeader(forex),
35
39
  },
40
+ {
41
+ id: 'dxos.org/script/forex-effect',
42
+ name: 'Forex (Effect)',
43
+ source: removeHeader(forexEffect),
44
+ },
36
45
  {
37
46
  id: 'dxos.org/script/gpt',
38
47
  name: 'Gpt',
@@ -51,4 +60,10 @@ export const templates: Template[] = [
51
60
  source: removeHeader(email),
52
61
  presetId: 'dxos.org/function/email',
53
62
  },
63
+ {
64
+ id: 'dxos.org/script/discord',
65
+ name: 'Discord',
66
+ source: removeHeader(discord),
67
+ presetId: 'dxos.org/function/discord',
68
+ },
54
69
  ];
@@ -17,6 +17,8 @@ export default [
17
17
  'object title placeholder': 'New script',
18
18
  'create object label': 'Create script',
19
19
  'create stack section label': 'Create script',
20
+ 'description label': 'Description',
21
+ 'description placeholder': 'Describe what the script does.',
20
22
  'binding placeholder': 'Function name',
21
23
  'function request placeholder': 'Function request',
22
24
  'deploy label': 'Deploy',