@dxos/plugin-script 0.7.5-main.ff8607b → 0.7.5-staging.b81e783

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 (182) hide show
  1. package/dist/lib/browser/{AutomationPanel-J3SZ5L3Y.mjs → AutomationPanel-6HFRNRWV.mjs} +2 -2
  2. package/dist/lib/browser/{ScriptContainer-4TSLLF4O.mjs → ScriptContainer-GR7X5NSI.mjs} +96 -68
  3. package/dist/lib/browser/ScriptContainer-GR7X5NSI.mjs.map +7 -0
  4. package/dist/lib/browser/artifact-definition-NAWYXFF5.mjs +243 -0
  5. package/dist/lib/browser/artifact-definition-NAWYXFF5.mjs.map +7 -0
  6. package/dist/lib/browser/{chunk-45LXDWNF.mjs → chunk-5SXOHNAK.mjs} +3 -3
  7. package/dist/lib/browser/chunk-5SXOHNAK.mjs.map +7 -0
  8. package/dist/lib/browser/{chunk-UJD45AFL.mjs → chunk-7RUMC44X.mjs} +18 -6
  9. package/dist/lib/browser/{chunk-UJD45AFL.mjs.map → chunk-7RUMC44X.mjs.map} +3 -3
  10. package/dist/lib/browser/chunk-YJAKD6E3.mjs +69 -0
  11. package/dist/lib/browser/chunk-YJAKD6E3.mjs.map +7 -0
  12. package/dist/lib/browser/{compiler-K3FNRDDN.mjs → compiler-YY2XSKHQ.mjs} +2 -4
  13. package/dist/lib/browser/compiler-YY2XSKHQ.mjs.map +7 -0
  14. package/dist/lib/browser/index.mjs +43 -26
  15. package/dist/lib/browser/index.mjs.map +4 -4
  16. package/dist/lib/browser/{intent-resolver-PPUEEPJJ.mjs → intent-resolver-I6VDXUDH.mjs} +2 -2
  17. package/dist/lib/browser/meta.json +1 -1
  18. package/dist/lib/browser/{react-surface-4CEIM2FE.mjs → react-surface-FGWXHB7P.mjs} +3 -3
  19. package/dist/lib/browser/{react-surface-4CEIM2FE.mjs.map → react-surface-FGWXHB7P.mjs.map} +2 -2
  20. package/dist/lib/node/{AutomationPanel-4M55FURO.cjs → AutomationPanel-RBQ4DODN.cjs} +6 -6
  21. package/dist/lib/node/{ScriptContainer-7JNYGHWK.cjs → ScriptContainer-SLARXOSU.cjs} +91 -61
  22. package/dist/lib/node/ScriptContainer-SLARXOSU.cjs.map +7 -0
  23. package/dist/lib/node/artifact-definition-7AANUS3X.cjs +262 -0
  24. package/dist/lib/node/artifact-definition-7AANUS3X.cjs.map +7 -0
  25. package/dist/lib/node/chunk-7XULMIYT.cjs +77 -0
  26. package/dist/lib/node/chunk-7XULMIYT.cjs.map +7 -0
  27. package/dist/lib/node/{chunk-2LHV7KAI.cjs → chunk-JITODKGN.cjs} +20 -8
  28. package/dist/lib/node/{chunk-2LHV7KAI.cjs.map → chunk-JITODKGN.cjs.map} +3 -3
  29. package/dist/lib/node/{chunk-IID7WUQS.cjs → chunk-K3ZZWVXS.cjs} +5 -5
  30. package/dist/lib/node/chunk-K3ZZWVXS.cjs.map +7 -0
  31. package/dist/lib/node/{compiler-P2HQB22H.cjs → compiler-UIBLKJKG.cjs} +6 -6
  32. package/dist/lib/node/compiler-UIBLKJKG.cjs.map +7 -0
  33. package/dist/lib/node/index.cjs +45 -29
  34. package/dist/lib/node/index.cjs.map +4 -4
  35. package/dist/lib/node/{intent-resolver-XZC3OXVT.cjs → intent-resolver-MYATX7IR.cjs} +6 -6
  36. package/dist/lib/node/meta.json +1 -1
  37. package/dist/lib/node/{react-surface-I36RLNYL.cjs → react-surface-2GH5HQX4.cjs} +10 -10
  38. package/dist/lib/node/{react-surface-I36RLNYL.cjs.map → react-surface-2GH5HQX4.cjs.map} +2 -2
  39. package/dist/lib/node-esm/{AutomationPanel-W6SKG35R.mjs → AutomationPanel-WTVVVMRH.mjs} +2 -2
  40. package/dist/lib/node-esm/{ScriptContainer-BR6YLHCD.mjs → ScriptContainer-MHRJXMC4.mjs} +96 -68
  41. package/dist/lib/node-esm/ScriptContainer-MHRJXMC4.mjs.map +7 -0
  42. package/dist/lib/node-esm/artifact-definition-KBASPVMM.mjs +245 -0
  43. package/dist/lib/node-esm/artifact-definition-KBASPVMM.mjs.map +7 -0
  44. package/dist/lib/node-esm/{chunk-CGF7EOGD.mjs → chunk-2AFXX34U.mjs} +3 -3
  45. package/dist/lib/node-esm/chunk-2AFXX34U.mjs.map +7 -0
  46. package/dist/lib/node-esm/chunk-6CHX4CEL.mjs +71 -0
  47. package/dist/lib/node-esm/chunk-6CHX4CEL.mjs.map +7 -0
  48. package/dist/lib/node-esm/{chunk-VZ7NFQL3.mjs → chunk-IAELQPSI.mjs} +18 -6
  49. package/dist/lib/node-esm/{chunk-VZ7NFQL3.mjs.map → chunk-IAELQPSI.mjs.map} +3 -3
  50. package/dist/lib/node-esm/{compiler-PDN46H4Y.mjs → compiler-XTXFGZJM.mjs} +2 -4
  51. package/dist/lib/node-esm/compiler-XTXFGZJM.mjs.map +7 -0
  52. package/dist/lib/node-esm/index.mjs +43 -26
  53. package/dist/lib/node-esm/index.mjs.map +4 -4
  54. package/dist/lib/node-esm/{intent-resolver-WUVFJ6AO.mjs → intent-resolver-PBDTYC4P.mjs} +2 -2
  55. package/dist/lib/node-esm/meta.json +1 -1
  56. package/dist/lib/node-esm/{react-surface-ET5KDADI.mjs → react-surface-MLE3J3TF.mjs} +3 -3
  57. package/dist/lib/node-esm/{react-surface-ET5KDADI.mjs.map → react-surface-MLE3J3TF.mjs.map} +2 -2
  58. package/dist/types/src/ScriptPlugin.d.ts.map +1 -1
  59. package/dist/types/src/capabilities/artifact-definition.d.ts +11 -0
  60. package/dist/types/src/capabilities/artifact-definition.d.ts.map +1 -0
  61. package/dist/types/src/capabilities/index.d.ts +1 -0
  62. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  63. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
  64. package/dist/types/src/components/AutomationPanel/AutomationPanel.d.ts +1 -2
  65. package/dist/types/src/components/AutomationPanel/AutomationPanel.d.ts.map +1 -1
  66. package/dist/types/src/components/DebugPanel/DebugPanel.d.ts +1 -2
  67. package/dist/types/src/components/DebugPanel/DebugPanel.d.ts.map +1 -1
  68. package/dist/types/src/components/FrameContainer/FrameContainer.d.ts +3 -4
  69. package/dist/types/src/components/FrameContainer/FrameContainer.d.ts.map +1 -1
  70. package/dist/types/src/components/ScriptContainer.d.ts +2 -3
  71. package/dist/types/src/components/ScriptContainer.d.ts.map +1 -1
  72. package/dist/types/src/components/ScriptSettings/ScriptSettings.d.ts +1 -2
  73. package/dist/types/src/components/ScriptSettings/ScriptSettings.d.ts.map +1 -1
  74. package/dist/types/src/components/ScriptSettingsPanel.d.ts +1 -2
  75. package/dist/types/src/components/ScriptSettingsPanel.d.ts.map +1 -1
  76. package/dist/types/src/components/ScriptToolbar/ScriptToolbar.d.ts +2 -3
  77. package/dist/types/src/components/ScriptToolbar/ScriptToolbar.d.ts.map +1 -1
  78. package/dist/types/src/components/TypescriptEditor/TypescriptEditor.d.ts +1 -2
  79. package/dist/types/src/components/TypescriptEditor/TypescriptEditor.d.ts.map +1 -1
  80. package/dist/types/src/components/index.d.ts +2 -2
  81. package/dist/types/src/components/index.d.ts.map +1 -1
  82. package/dist/types/src/events.d.ts +4 -0
  83. package/dist/types/src/events.d.ts.map +1 -0
  84. package/dist/types/src/hooks/deploy.d.ts.map +1 -0
  85. package/dist/types/src/hooks/format.d.ts.map +1 -0
  86. package/dist/types/src/hooks/index.d.ts +7 -0
  87. package/dist/types/src/hooks/index.d.ts.map +1 -0
  88. package/dist/types/src/{components/ScriptToolbar/templateSelect.d.ts → hooks/template.d.ts} +1 -1
  89. package/dist/types/src/hooks/template.d.ts.map +1 -0
  90. package/dist/types/src/{components/ScriptToolbar → hooks}/useToolbarAction.d.ts +1 -1
  91. package/dist/types/src/hooks/useToolbarAction.d.ts.map +1 -0
  92. package/dist/types/src/hooks/useToolbarState.d.ts.map +1 -0
  93. package/dist/types/src/hooks/view.d.ts.map +1 -0
  94. package/dist/types/src/index.d.ts +0 -1
  95. package/dist/types/src/index.d.ts.map +1 -1
  96. package/dist/types/src/templates/chess.d.ts +1 -4
  97. package/dist/types/src/templates/chess.d.ts.map +1 -1
  98. package/dist/types/src/templates/discord.d.ts +3 -0
  99. package/dist/types/src/templates/discord.d.ts.map +1 -0
  100. package/dist/types/src/templates/echo.d.ts.map +1 -1
  101. package/dist/types/src/templates/forex-effect.d.ts +3 -0
  102. package/dist/types/src/templates/forex-effect.d.ts.map +1 -0
  103. package/dist/types/src/templates/forex.d.ts +1 -4
  104. package/dist/types/src/templates/forex.d.ts.map +1 -1
  105. package/dist/types/src/templates/index.d.ts.map +1 -1
  106. package/dist/types/src/translations.d.ts +6 -0
  107. package/dist/types/src/translations.d.ts.map +1 -1
  108. package/package.json +42 -42
  109. package/src/ScriptPlugin.tsx +28 -12
  110. package/src/capabilities/artifact-definition.ts +219 -0
  111. package/src/capabilities/compiler.ts +1 -1
  112. package/src/capabilities/index.ts +1 -0
  113. package/src/capabilities/react-surface.tsx +2 -1
  114. package/src/compiler/compiler.browser.test.ts +1 -1
  115. package/src/components/DebugPanel/DebugPanel.tsx +2 -2
  116. package/src/components/FrameContainer/FrameContainer.tsx +5 -4
  117. package/src/components/ScriptContainer.tsx +10 -5
  118. package/src/components/ScriptSettingsPanel.tsx +16 -2
  119. package/src/components/ScriptToolbar/ScriptToolbar.tsx +8 -6
  120. package/src/components/TypescriptEditor/TypescriptEditor.tsx +2 -2
  121. package/src/events.ts +11 -0
  122. package/src/{components/ScriptToolbar → hooks}/deploy.ts +16 -4
  123. package/src/{components/ScriptToolbar → hooks}/format.ts +1 -1
  124. package/src/hooks/index.ts +11 -0
  125. package/src/{components/ScriptToolbar/templateSelect.ts → hooks/template.ts} +2 -2
  126. package/src/{components/ScriptToolbar → hooks}/useToolbarAction.ts +1 -1
  127. package/src/{components/ScriptToolbar → hooks}/view.ts +1 -1
  128. package/src/index.ts +0 -1
  129. package/src/templates/chess.ts +42 -35
  130. package/src/templates/discord.ts +103 -0
  131. package/src/templates/echo.ts +5 -1
  132. package/src/templates/forex-effect.ts +41 -0
  133. package/src/templates/forex.ts +23 -16
  134. package/src/templates/index.ts +15 -0
  135. package/src/translations.ts +2 -0
  136. package/dist/lib/browser/ScriptContainer-4TSLLF4O.mjs.map +0 -7
  137. package/dist/lib/browser/chunk-45LXDWNF.mjs.map +0 -7
  138. package/dist/lib/browser/chunk-REL2R7SB.mjs +0 -52
  139. package/dist/lib/browser/chunk-REL2R7SB.mjs.map +0 -7
  140. package/dist/lib/browser/chunk-SDHKTS6H.mjs +0 -237
  141. package/dist/lib/browser/chunk-SDHKTS6H.mjs.map +0 -7
  142. package/dist/lib/browser/compiler-K3FNRDDN.mjs.map +0 -7
  143. package/dist/lib/node/ScriptContainer-7JNYGHWK.cjs.map +0 -7
  144. package/dist/lib/node/chunk-IID7WUQS.cjs.map +0 -7
  145. package/dist/lib/node/chunk-T4TXCRN5.cjs +0 -260
  146. package/dist/lib/node/chunk-T4TXCRN5.cjs.map +0 -7
  147. package/dist/lib/node/chunk-TJ4BTPOS.cjs +0 -64
  148. package/dist/lib/node/chunk-TJ4BTPOS.cjs.map +0 -7
  149. package/dist/lib/node/compiler-P2HQB22H.cjs.map +0 -7
  150. package/dist/lib/node-esm/ScriptContainer-BR6YLHCD.mjs.map +0 -7
  151. package/dist/lib/node-esm/chunk-CGF7EOGD.mjs.map +0 -7
  152. package/dist/lib/node-esm/chunk-G76M6O46.mjs +0 -239
  153. package/dist/lib/node-esm/chunk-G76M6O46.mjs.map +0 -7
  154. package/dist/lib/node-esm/chunk-JJZYWSD7.mjs +0 -54
  155. package/dist/lib/node-esm/chunk-JJZYWSD7.mjs.map +0 -7
  156. package/dist/lib/node-esm/compiler-PDN46H4Y.mjs.map +0 -7
  157. package/dist/types/src/bundler/bundler.d.ts +0 -39
  158. package/dist/types/src/bundler/bundler.d.ts.map +0 -1
  159. package/dist/types/src/bundler/bundler.test.d.ts +0 -2
  160. package/dist/types/src/bundler/bundler.test.d.ts.map +0 -1
  161. package/dist/types/src/bundler/index.d.ts +0 -2
  162. package/dist/types/src/bundler/index.d.ts.map +0 -1
  163. package/dist/types/src/components/ScriptToolbar/deploy.d.ts.map +0 -1
  164. package/dist/types/src/components/ScriptToolbar/format.d.ts.map +0 -1
  165. package/dist/types/src/components/ScriptToolbar/templateSelect.d.ts.map +0 -1
  166. package/dist/types/src/components/ScriptToolbar/useToolbarAction.d.ts.map +0 -1
  167. package/dist/types/src/components/ScriptToolbar/useToolbarState.d.ts.map +0 -1
  168. package/dist/types/src/components/ScriptToolbar/view.d.ts.map +0 -1
  169. package/src/bundler/bundler.test.ts +0 -55
  170. package/src/bundler/bundler.ts +0 -250
  171. package/src/bundler/index.ts +0 -5
  172. /package/dist/lib/browser/{AutomationPanel-J3SZ5L3Y.mjs.map → AutomationPanel-6HFRNRWV.mjs.map} +0 -0
  173. /package/dist/lib/browser/{intent-resolver-PPUEEPJJ.mjs.map → intent-resolver-I6VDXUDH.mjs.map} +0 -0
  174. /package/dist/lib/node/{AutomationPanel-4M55FURO.cjs.map → AutomationPanel-RBQ4DODN.cjs.map} +0 -0
  175. /package/dist/lib/node/{intent-resolver-XZC3OXVT.cjs.map → intent-resolver-MYATX7IR.cjs.map} +0 -0
  176. /package/dist/lib/node-esm/{AutomationPanel-W6SKG35R.mjs.map → AutomationPanel-WTVVVMRH.mjs.map} +0 -0
  177. /package/dist/lib/node-esm/{intent-resolver-WUVFJ6AO.mjs.map → intent-resolver-PBDTYC4P.mjs.map} +0 -0
  178. /package/dist/types/src/{components/ScriptToolbar → hooks}/deploy.d.ts +0 -0
  179. /package/dist/types/src/{components/ScriptToolbar → hooks}/format.d.ts +0 -0
  180. /package/dist/types/src/{components/ScriptToolbar → hooks}/useToolbarState.d.ts +0 -0
  181. /package/dist/types/src/{components/ScriptToolbar → hooks}/view.d.ts +0 -0
  182. /package/src/{components/ScriptToolbar → hooks}/useToolbarState.ts +0 -0
@@ -7,7 +7,7 @@ import React, { forwardRef, useEffect, useRef, useState } from 'react';
7
7
  import { log } from '@dxos/log';
8
8
  import { Avatar, Icon, Input, type ThemedClassName, Toolbar, useTranslation } from '@dxos/react-ui';
9
9
  import { SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';
10
- import { mx } from '@dxos/react-ui-theme';
10
+ import { errorText, mx } from '@dxos/react-ui-theme';
11
11
 
12
12
  import { SCRIPT_PLUGIN } from '../../meta';
13
13
 
@@ -232,7 +232,7 @@ const MessageItem = ({ classNames, message }: ThemedClassName<{ message: Message
232
232
  const wrapper = 'p-1 px-2 rounded-lg bg-hoverSurface overflow-auto';
233
233
  return (
234
234
  <div className={mx('flex', type === 'request' ? 'ml-[1rem] justify-end' : 'mr-[1rem]', classNames)}>
235
- {error && <div className={mx(wrapper, 'whitespace-pre text-error')}>{String(error)}</div>}
235
+ {error && <div className={mx(wrapper, 'whitespace-pre', errorText)}>{String(error)}</div>}
236
236
 
237
237
  {text !== undefined && (
238
238
  <div className={mx(wrapper, type === 'request' && 'bg-primary-400 dark:bg-primary-600')}>
@@ -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
 
@@ -58,7 +59,7 @@ export const FrameContainer = ({ containerUrl, result, debug = true }: FrameCont
58
59
  <div
59
60
  className={mx(
60
61
  baseSurface,
61
- 'flex absolute right-2 bottom-2 w-[400px] h-[200px] ring rounded',
62
+ 'flex absolute right-2 bottom-2 w-[30rem] h-[200px] ring rounded',
62
63
  'z-20 overflow-x-hidden overflow-y-auto',
63
64
  )}
64
65
  >
@@ -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 (
@@ -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
  }),
package/src/events.ts ADDED
@@ -0,0 +1,11 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { defineEvent } from '@dxos/app-framework';
6
+
7
+ import { SCRIPT_PLUGIN } from './meta';
8
+
9
+ export namespace ScriptEvents {
10
+ export const SetupCompiler = defineEvent(`${SCRIPT_PLUGIN}/event/setup-compiler`);
11
+ }
@@ -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';
@@ -1,41 +1,48 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
1
+ // @ts-ignore
2
+ import { defineFunction, S } from 'dxos:functions';
5
3
  // @ts-ignore
6
4
  import { Chess } from 'https://esm.sh/chess.js@0.13.1';
7
5
 
8
- /**
9
- * Plays a random move in a chess game.
10
- */
11
- export default async ({
12
- event: {
13
- data: { request },
14
- },
15
- context: { space },
16
- }: any) => {
17
- const {
18
- data: {
19
- objects: [gameId],
20
- player = 'b',
21
- },
22
- } = await request.json();
6
+ export default defineFunction({
7
+ description: 'Plays a random move in a chess game.',
23
8
 
24
- const { pgn } = await space.crud.query({ id: gameId }).first();
25
- const game = new Chess();
26
- game.load_pgn(pgn);
27
- if (game.turn() !== player) {
28
- return new Response('Invalid turn', { status: 409 });
29
- }
9
+ inputSchema: S.Struct({
10
+ changedObjectId: S.String.annotations({
11
+ description: 'The objects to play the game on.',
12
+ }),
13
+ player: S.optional(S.Literal('w', 'b')).annotations({
14
+ description: 'The player to play the game as.',
15
+ }),
16
+ }),
30
17
 
31
- const moves = game.moves();
32
- const move = moves[Math.floor(Math.random() * moves.length)];
33
- if (!move) {
34
- return new Response('No legal moves', { status: 406 });
35
- }
18
+ outputSchema: S.Struct({
19
+ state: S.String.annotations({
20
+ description: 'The state of the game as an ASCII art board.',
21
+ }),
22
+ }),
36
23
 
37
- game.move(move);
38
- const newPgn = game.pgn();
39
- await space.crud.update({ id: gameId }, { pgn: newPgn });
40
- return new Response(game.ascii());
41
- };
24
+ handler: async ({
25
+ event: {
26
+ data: { changedObjectId, player = 'b' },
27
+ },
28
+ context: { space },
29
+ }: any) => {
30
+ const { pgn } = await space.db.query({ id: changedObjectId }).first();
31
+ const game = new Chess();
32
+ game.load_pgn(pgn);
33
+ if (game.turn() !== player) {
34
+ return new Response('Invalid turn', { status: 409 });
35
+ }
36
+
37
+ const moves = game.moves();
38
+ const move = moves[Math.floor(Math.random() * moves.length)];
39
+ if (!move) {
40
+ return new Response('No legal moves', { status: 406 });
41
+ }
42
+
43
+ game.move(move);
44
+ const newPgn = game.pgn();
45
+ await space.db.update({ id: changedObjectId }, { pgn: newPgn, fen: game.fen() });
46
+ return { state: game.ascii() };
47
+ },
48
+ });
@@ -0,0 +1,103 @@
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, Ref } from 'https://esm.sh/effect@3.13.3';
15
+
16
+ const MessageSchema = S.Struct({
17
+ id: S.String,
18
+ foreignId: S.Any, // bigint?
19
+ from: S.String,
20
+ created: S.String,
21
+ content: S.String,
22
+ }).pipe(EchoObject('example.com/type/Message', '0.1.0'));
23
+
24
+ const DEFAULT_AFTER = 1704067200; // 2024-01-01
25
+
26
+ const generateSnowflake = (unixTimestamp: number): bigint => {
27
+ const discordEpoch = 1420070400000n; // Discord Epoch (ms)
28
+ return (BigInt(unixTimestamp * 1000) - discordEpoch) << 22n;
29
+ };
30
+
31
+ export default defineFunction({
32
+ inputSchema: S.Struct({
33
+ // TODO(wittjosiah): Remove. This is used to provide a terminal for a cron trigger.
34
+ tick: S.optional(S.String),
35
+ channelId: S.String,
36
+ after: S.optional(S.Number),
37
+ pageSize: S.optional(S.Number),
38
+ queueId: S.String,
39
+ }),
40
+
41
+ outputSchema: S.Struct({
42
+ newMessages: S.Number,
43
+ }),
44
+
45
+ handler: ({
46
+ event: {
47
+ data: { channelId, queueId, after = DEFAULT_AFTER, pageSize = 5 },
48
+ },
49
+ context: { space },
50
+ }: any) =>
51
+ Effect.gen(function* () {
52
+ const { token } = yield* Effect.tryPromise(() =>
53
+ space.db.query(Filter.typename('dxos.org/type/AccessToken', { source: 'discord.com' })).first(),
54
+ );
55
+ const { objects } = yield* Effect.tryPromise(() => space.queues.queryQueue(DXN.parse(queueId)));
56
+ const backfill = objects.length === 0;
57
+ const newMessages = yield* Ref.make(0);
58
+ const lastMessage = yield* Ref.make(objects.at(-1));
59
+
60
+ const enqueueMessages = Effect.gen(function* () {
61
+ const rest = yield* DiscordREST;
62
+
63
+ while (true) {
64
+ const last = yield* Ref.get(lastMessage);
65
+ const options = {
66
+ after: backfill && !last ? `${generateSnowflake(after)}` : last?.foreignId,
67
+ limit: pageSize,
68
+ };
69
+ const messages = yield* rest.getChannelMessages(channelId, options).pipe((res: any) => res.json);
70
+ const queueMessages = messages
71
+ .map((message: any) =>
72
+ createStatic(MessageSchema, {
73
+ id: ObjectId.random(),
74
+ foreignId: message.id,
75
+ from: message.author.username,
76
+ created: message.timestamp,
77
+ content: message.content,
78
+ }),
79
+ )
80
+ .toReversed();
81
+ if (queueMessages.length > 0) {
82
+ yield* Effect.tryPromise(() => space.queues.insertIntoQueue(DXN.parse(queueId), queueMessages));
83
+ yield* Ref.update(newMessages, (n: any) => n + queueMessages.length);
84
+ yield* Ref.update(lastMessage, (m: any) => queueMessages.at(-1));
85
+ }
86
+ if (messages.length < pageSize) {
87
+ break;
88
+ }
89
+ }
90
+ }).pipe(
91
+ Effect.provide(DiscordRESTMemoryLive),
92
+ Effect.provide(
93
+ DiscordConfig.layerConfig({
94
+ token: Config.succeed(Redacted.make(token)),
95
+ }),
96
+ ),
97
+ Effect.provide(FetchHttpClient.layer),
98
+ );
99
+
100
+ yield* enqueueMessages;
101
+ return { newMessages: yield* Ref.get(newMessages) };
102
+ }),
103
+ });
@@ -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,41 @@
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
+ export default defineFunction({
17
+ description: 'Returns the exchange rate between two currencies.',
18
+
19
+ inputSchema: S.Struct({
20
+ from: S.String.annotations({ description: 'The source currency' }),
21
+ to: S.String.annotations({ description: 'The target currency' }),
22
+ }),
23
+
24
+ outputSchema: S.String.annotations({ description: 'The exchange rate between the two currencies' }),
25
+
26
+ handler: async ({
27
+ event: {
28
+ data: { from, to },
29
+ },
30
+ }: any) =>
31
+ Effect.gen(function* () {
32
+ const res = yield* HttpClientRequest.get(`https://free.ratesdb.com/v1/rates?from=${from}&to=${to}`).pipe(
33
+ HttpClient.execute,
34
+ Effect.flatMap((res: any) => res.json),
35
+ Effect.timeout('1 second'),
36
+ Effect.retry(Schedule.exponential(1000).pipe(Schedule.compose(Schedule.recurs(3)))),
37
+ Effect.scoped,
38
+ );
39
+ return res.data.rates[to].toString();
40
+ }).pipe(Effect.provide(FetchHttpClient.layer)),
41
+ });
@@ -1,21 +1,28 @@
1
1
  //
2
- // Copyright 2024 DXOS.org
2
+ // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- /**
6
- * Returns the exchange rate between two currencies.
7
- */
8
- export default async ({
9
- event: {
10
- data: { request },
11
- },
12
- }: any) => {
13
- const { args: [from = 'EUR', to = 'USD'] = [] } = await request.json();
5
+ // @ts-ignore
6
+ import { defineFunction, S } from 'dxos:functions';
7
+
8
+ export default defineFunction({
9
+ description: 'Returns the exchange rate between two currencies.',
14
10
 
15
- const res = await fetch(`https://free.ratesdb.com/v1/rates?from=${from}&to=${to}`);
16
- const {
17
- data: { rates },
18
- } = await res.json();
11
+ inputSchema: S.Struct({
12
+ from: S.String.annotations({ description: 'The source currency' }),
13
+ to: S.String.annotations({ description: 'The target currency' }),
14
+ }),
19
15
 
20
- return new Response(rates[to].toString());
21
- };
16
+ handler: async ({
17
+ event: {
18
+ data: { from, to },
19
+ },
20
+ }: any) => {
21
+ const res = await fetch(`https://free.ratesdb.com/v1/rates?from=${from}&to=${to}`);
22
+ const {
23
+ data: { rates },
24
+ } = await res.json();
25
+
26
+ return rates[to].toString();
27
+ },
28
+ });
@@ -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',