@dxos/plugin-script 0.8.4-main.c1de068 → 0.8.4-main.e098934

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 (161) hide show
  1. package/dist/lib/browser/{DeploymentDialog-M4QIHTDR.mjs → DeploymentDialog-QZSTVNIS.mjs} +3 -3
  2. package/dist/lib/browser/{ScriptContainer-Z6SIGRRC.mjs → ScriptContainer-DNNA6XC6.mjs} +14 -11
  3. package/dist/lib/browser/ScriptContainer-DNNA6XC6.mjs.map +7 -0
  4. package/dist/lib/browser/{app-graph-builder-HLQ7K3BT.mjs → app-graph-builder-IABOSTBK.mjs} +2 -2
  5. package/dist/lib/{node-esm/app-graph-builder-7EYIHWH4.mjs.map → browser/app-graph-builder-IABOSTBK.mjs.map} +3 -3
  6. package/dist/lib/browser/blueprint-definition-AR7ITBCD.mjs +28 -0
  7. package/dist/lib/browser/blueprint-definition-AR7ITBCD.mjs.map +7 -0
  8. package/dist/lib/browser/{chunk-3U6DTUH3.mjs → chunk-6CAH7VIE.mjs} +14 -14
  9. package/dist/lib/browser/chunk-6CAH7VIE.mjs.map +7 -0
  10. package/dist/lib/browser/{chunk-FIM2MVNJ.mjs → chunk-GZKWMME3.mjs} +42 -41
  11. package/dist/lib/browser/chunk-GZKWMME3.mjs.map +7 -0
  12. package/dist/lib/browser/{chunk-FMDXKOP7.mjs → chunk-NXKU3BNX.mjs} +33 -44
  13. package/dist/lib/browser/chunk-NXKU3BNX.mjs.map +7 -0
  14. package/dist/lib/browser/chunk-RNGIQIEJ.mjs +88 -0
  15. package/dist/lib/browser/chunk-RNGIQIEJ.mjs.map +7 -0
  16. package/dist/lib/browser/{chunk-P4HQKUCP.mjs → chunk-YCZPTTFO.mjs} +3 -3
  17. package/dist/lib/browser/chunk-YCZPTTFO.mjs.map +7 -0
  18. package/dist/lib/browser/{compiler-CXCUA4UQ.mjs → compiler-2HJH34GM.mjs} +20 -4
  19. package/dist/lib/browser/compiler-2HJH34GM.mjs.map +7 -0
  20. package/dist/lib/browser/index.mjs +14 -13
  21. package/dist/lib/browser/index.mjs.map +3 -3
  22. package/dist/lib/browser/{intent-resolver-7B77IG3N.mjs → intent-resolver-F4YSRPJI.mjs} +8 -10
  23. package/dist/lib/browser/intent-resolver-F4YSRPJI.mjs.map +7 -0
  24. package/dist/lib/browser/meta.json +1 -1
  25. package/dist/lib/browser/{react-surface-FYYXZA7C.mjs → react-surface-BBHFU6MI.mjs} +6 -6
  26. package/dist/lib/browser/react-surface-BBHFU6MI.mjs.map +7 -0
  27. package/dist/lib/browser/templates/index.mjs +1 -1
  28. package/dist/lib/node-esm/{DeploymentDialog-3KPRWFE7.mjs → DeploymentDialog-G6EHEPXN.mjs} +3 -3
  29. package/dist/lib/node-esm/{ScriptContainer-KPU75HHI.mjs → ScriptContainer-KPYZN2KY.mjs} +14 -11
  30. package/dist/lib/node-esm/ScriptContainer-KPYZN2KY.mjs.map +7 -0
  31. package/dist/lib/node-esm/{app-graph-builder-7EYIHWH4.mjs → app-graph-builder-CQTTAYHP.mjs} +2 -2
  32. package/dist/lib/{browser/app-graph-builder-HLQ7K3BT.mjs.map → node-esm/app-graph-builder-CQTTAYHP.mjs.map} +3 -3
  33. package/dist/lib/node-esm/blueprint-definition-TJY4TX6S.mjs +30 -0
  34. package/dist/lib/node-esm/blueprint-definition-TJY4TX6S.mjs.map +7 -0
  35. package/dist/lib/node-esm/{chunk-RT43MACC.mjs → chunk-2GBESIHU.mjs} +14 -14
  36. package/dist/lib/node-esm/chunk-2GBESIHU.mjs.map +7 -0
  37. package/dist/lib/node-esm/chunk-GWHLP5LM.mjs +90 -0
  38. package/dist/lib/node-esm/chunk-GWHLP5LM.mjs.map +7 -0
  39. package/dist/lib/node-esm/{chunk-7NMI4CEU.mjs → chunk-HUHVIOL5.mjs} +42 -41
  40. package/dist/lib/node-esm/chunk-HUHVIOL5.mjs.map +7 -0
  41. package/dist/lib/node-esm/{chunk-XJPK3IYI.mjs → chunk-M642JUOZ.mjs} +33 -44
  42. package/dist/lib/node-esm/chunk-M642JUOZ.mjs.map +7 -0
  43. package/dist/lib/node-esm/{chunk-QKK3NDHW.mjs → chunk-ZA36GO4T.mjs} +3 -3
  44. package/dist/lib/node-esm/chunk-ZA36GO4T.mjs.map +7 -0
  45. package/dist/lib/node-esm/{compiler-EPFKQXPE.mjs → compiler-7SP27RA6.mjs} +20 -4
  46. package/dist/lib/node-esm/compiler-7SP27RA6.mjs.map +7 -0
  47. package/dist/lib/node-esm/index.mjs +14 -13
  48. package/dist/lib/node-esm/index.mjs.map +3 -3
  49. package/dist/lib/node-esm/{intent-resolver-FRZGS4TB.mjs → intent-resolver-CGQYRWWD.mjs} +8 -10
  50. package/dist/lib/node-esm/intent-resolver-CGQYRWWD.mjs.map +7 -0
  51. package/dist/lib/node-esm/meta.json +1 -1
  52. package/dist/lib/node-esm/{react-surface-V32NWHKN.mjs → react-surface-UWIWPKZD.mjs} +6 -6
  53. package/dist/lib/node-esm/react-surface-UWIWPKZD.mjs.map +7 -0
  54. package/dist/lib/node-esm/templates/index.mjs +1 -1
  55. package/dist/types/src/capabilities/app-graph-builder.d.ts +1 -1
  56. package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -1
  57. package/dist/types/src/capabilities/artifact-definition.d.ts +1 -1
  58. package/dist/types/src/capabilities/artifact-definition.d.ts.map +1 -1
  59. package/dist/types/src/capabilities/blueprint-definition.d.ts +5 -0
  60. package/dist/types/src/capabilities/blueprint-definition.d.ts.map +1 -0
  61. package/dist/types/src/capabilities/compiler.d.ts +1 -1
  62. package/dist/types/src/capabilities/compiler.d.ts.map +1 -1
  63. package/dist/types/src/capabilities/index.d.ts +6 -6
  64. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  65. package/dist/types/src/capabilities/intent-resolver.d.ts +1 -1
  66. package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -1
  67. package/dist/types/src/capabilities/react-surface.d.ts +1 -1
  68. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
  69. package/dist/types/src/capabilities/settings.d.ts +1 -1
  70. package/dist/types/src/compiler/compiler.d.ts.map +1 -1
  71. package/dist/types/src/components/DeploymentDialog/DeploymentDialog.d.ts +1 -1
  72. package/dist/types/src/components/DeploymentDialog/DeploymentDialog.d.ts.map +1 -1
  73. package/dist/types/src/components/DeploymentDialog/DeploymentDialog.stories.d.ts +139 -12
  74. package/dist/types/src/components/DeploymentDialog/DeploymentDialog.stories.d.ts.map +1 -1
  75. package/dist/types/src/components/DeploymentDialog/index.d.ts +1 -1
  76. package/dist/types/src/components/DeploymentDialog/index.d.ts.map +1 -1
  77. package/dist/types/src/components/FrameContainer/FrameContainer.d.ts.map +1 -1
  78. package/dist/types/src/components/ScriptContainer.d.ts +1 -1
  79. package/dist/types/src/components/ScriptContainer.d.ts.map +1 -1
  80. package/dist/types/src/components/ScriptToolbar/ScriptToolbar.d.ts.map +1 -1
  81. package/dist/types/src/components/ScriptToolbar/ScriptToolbar.stories.d.ts +7 -10
  82. package/dist/types/src/components/ScriptToolbar/ScriptToolbar.stories.d.ts.map +1 -1
  83. package/dist/types/src/components/Settings/ScriptObjectSettings.d.ts.map +1 -1
  84. package/dist/types/src/components/Settings/ScriptPluginSettings.d.ts.map +1 -1
  85. package/dist/types/src/components/TestPanel/TestContainer.d.ts.map +1 -1
  86. package/dist/types/src/components/TypescriptEditor/TypescriptEditor.d.ts.map +1 -1
  87. package/dist/types/src/components/TypescriptEditor/TypescriptEditor.stories.d.ts +10 -3
  88. package/dist/types/src/components/TypescriptEditor/TypescriptEditor.stories.d.ts.map +1 -1
  89. package/dist/types/src/components/index.d.ts +1 -4
  90. package/dist/types/src/components/index.d.ts.map +1 -1
  91. package/dist/types/src/hooks/deploy.d.ts +5 -4
  92. package/dist/types/src/hooks/deploy.d.ts.map +1 -1
  93. package/dist/types/src/hooks/useCreateAndDeployScriptTemplates.d.ts.map +1 -1
  94. package/dist/types/src/templates/data-generator.d.ts.map +1 -1
  95. package/dist/types/src/translations.d.ts +1 -0
  96. package/dist/types/src/translations.d.ts.map +1 -1
  97. package/dist/types/src/util/deploy.d.ts +3 -3
  98. package/dist/types/src/util/deploy.d.ts.map +1 -1
  99. package/dist/types/src/util/functions.d.ts.map +1 -1
  100. package/dist/types/tsconfig.tsbuildinfo +1 -1
  101. package/package.json +64 -61
  102. package/src/ScriptPlugin.tsx +4 -4
  103. package/src/capabilities/app-graph-builder.ts +2 -2
  104. package/src/capabilities/artifact-definition.ts +7 -11
  105. package/src/capabilities/blueprint-definition.ts +30 -0
  106. package/src/capabilities/compiler.ts +2 -1
  107. package/src/capabilities/index.ts +1 -1
  108. package/src/capabilities/intent-resolver.ts +2 -5
  109. package/src/capabilities/react-surface.tsx +3 -2
  110. package/src/compiler/compiler.ts +1 -1
  111. package/src/components/DeploymentDialog/DeploymentDialog.stories.tsx +28 -16
  112. package/src/components/DeploymentDialog/DeploymentDialog.tsx +5 -5
  113. package/src/components/DeploymentDialog/index.ts +1 -1
  114. package/src/components/FrameContainer/FrameContainer.tsx +3 -2
  115. package/src/components/ScriptContainer.tsx +3 -2
  116. package/src/components/ScriptToolbar/ScriptToolbar.stories.tsx +19 -14
  117. package/src/components/ScriptToolbar/ScriptToolbar.tsx +14 -4
  118. package/src/components/Settings/ScriptObjectSettings.tsx +19 -23
  119. package/src/components/Settings/ScriptPluginSettings.tsx +33 -28
  120. package/src/components/TestPanel/TestContainer.tsx +2 -1
  121. package/src/components/TestPanel/TestPanel.tsx +1 -1
  122. package/src/components/TypescriptEditor/TypescriptEditor.stories.tsx +9 -16
  123. package/src/components/TypescriptEditor/TypescriptEditor.tsx +6 -4
  124. package/src/hooks/deploy.ts +11 -11
  125. package/src/hooks/template.ts +1 -1
  126. package/src/hooks/useCreateAndDeployScriptTemplates.ts +1 -0
  127. package/src/templates/chess.ts +1 -1
  128. package/src/templates/data-generator.ts +7 -3
  129. package/src/templates/discord.ts +4 -4
  130. package/src/templates/forex-effect.ts +3 -3
  131. package/src/templates/forex.ts +1 -1
  132. package/src/templates/gmail.ts +13 -54
  133. package/src/translations.ts +1 -0
  134. package/src/util/deploy.ts +20 -33
  135. package/src/util/functions.ts +4 -4
  136. package/dist/lib/browser/ScriptContainer-Z6SIGRRC.mjs.map +0 -7
  137. package/dist/lib/browser/artifact-definition-24Q3IHOU.mjs +0 -249
  138. package/dist/lib/browser/artifact-definition-24Q3IHOU.mjs.map +0 -7
  139. package/dist/lib/browser/chunk-3U6DTUH3.mjs.map +0 -7
  140. package/dist/lib/browser/chunk-FIM2MVNJ.mjs.map +0 -7
  141. package/dist/lib/browser/chunk-FMDXKOP7.mjs.map +0 -7
  142. package/dist/lib/browser/chunk-P4HQKUCP.mjs.map +0 -7
  143. package/dist/lib/browser/chunk-R4R7VOFY.mjs +0 -88
  144. package/dist/lib/browser/chunk-R4R7VOFY.mjs.map +0 -7
  145. package/dist/lib/browser/compiler-CXCUA4UQ.mjs.map +0 -7
  146. package/dist/lib/browser/intent-resolver-7B77IG3N.mjs.map +0 -7
  147. package/dist/lib/browser/react-surface-FYYXZA7C.mjs.map +0 -7
  148. package/dist/lib/node-esm/ScriptContainer-KPU75HHI.mjs.map +0 -7
  149. package/dist/lib/node-esm/artifact-definition-WAJFALUI.mjs +0 -250
  150. package/dist/lib/node-esm/artifact-definition-WAJFALUI.mjs.map +0 -7
  151. package/dist/lib/node-esm/chunk-7NMI4CEU.mjs.map +0 -7
  152. package/dist/lib/node-esm/chunk-F5GFJ3PY.mjs +0 -90
  153. package/dist/lib/node-esm/chunk-F5GFJ3PY.mjs.map +0 -7
  154. package/dist/lib/node-esm/chunk-QKK3NDHW.mjs.map +0 -7
  155. package/dist/lib/node-esm/chunk-RT43MACC.mjs.map +0 -7
  156. package/dist/lib/node-esm/chunk-XJPK3IYI.mjs.map +0 -7
  157. package/dist/lib/node-esm/compiler-EPFKQXPE.mjs.map +0 -7
  158. package/dist/lib/node-esm/intent-resolver-FRZGS4TB.mjs.map +0 -7
  159. package/dist/lib/node-esm/react-surface-V32NWHKN.mjs.map +0 -7
  160. /package/dist/lib/browser/{DeploymentDialog-M4QIHTDR.mjs.map → DeploymentDialog-QZSTVNIS.mjs.map} +0 -0
  161. /package/dist/lib/node-esm/{DeploymentDialog-3KPRWFE7.mjs.map → DeploymentDialog-G6EHEPXN.mjs.map} +0 -0
@@ -3,14 +3,14 @@
3
3
  //
4
4
 
5
5
  import { Octokit } from '@octokit/core';
6
- import React, { type ChangeEvent, useCallback, useEffect, useState } from 'react';
6
+ import React, { type ChangeEvent, useCallback, useState } from 'react';
7
7
 
8
- import { createIntent, SettingsAction, useIntentDispatcher } from '@dxos/app-framework';
9
- import { FunctionType, type ScriptType, getInvocationUrl, getUserFunctionUrlInMetadata } from '@dxos/functions';
8
+ import { SettingsAction, createIntent, useIntentDispatcher } from '@dxos/app-framework';
9
+ import { FunctionType, type ScriptType, getInvocationUrl, getUserFunctionIdInMetadata } from '@dxos/functions';
10
10
  import { log } from '@dxos/log';
11
11
  import { useClient } from '@dxos/react-client';
12
- import { Filter, getMeta, getSpace, Ref, useQuery } from '@dxos/react-client/echo';
13
- import { Button, Clipboard, Input, useControlledState, useTranslation } from '@dxos/react-ui';
12
+ import { Filter, Ref, getMeta, getSpace, useQuery } from '@dxos/react-client/echo';
13
+ import { Button, Clipboard, Input, useAsyncEffect, useControlledState, useTranslation } from '@dxos/react-ui';
14
14
  import { DataType } from '@dxos/schema';
15
15
 
16
16
  import { SCRIPT_PLUGIN } from '../../meta';
@@ -50,10 +50,10 @@ const Binding = ({ object }: ScriptObjectSettingsProps) => {
50
50
  const space = getSpace(object);
51
51
  const [fn] = useQuery(space, Filter.type(FunctionType, { source: Ref.make(object) }));
52
52
 
53
- const functionPath = fn && getUserFunctionUrlInMetadata(getMeta(fn));
53
+ const functionId = fn && getUserFunctionIdInMetadata(getMeta(fn));
54
54
  const functionUrl =
55
- functionPath &&
56
- getInvocationUrl(functionPath, client.config.values.runtime?.services?.edge?.url ?? '', {
55
+ functionId &&
56
+ getInvocationUrl(functionId, client.config.values.runtime?.services?.edge?.url ?? '', {
57
57
  spaceId: space?.id,
58
58
  });
59
59
 
@@ -116,7 +116,7 @@ const Publishing = ({ object }: ScriptObjectSettingsProps) => {
116
116
  const gistKey = getMeta(object).keys.find(({ source }) => source === 'github.com');
117
117
  const [gistUrl, setGistUrl] = useState<string | undefined>();
118
118
 
119
- useEffect(() => {
119
+ useAsyncEffect(async () => {
120
120
  const token = githubToken?.token;
121
121
  const gistId = gistKey?.id;
122
122
  if (!token || !gistId) {
@@ -124,20 +124,16 @@ const Publishing = ({ object }: ScriptObjectSettingsProps) => {
124
124
  return;
125
125
  }
126
126
 
127
- const timeout = setTimeout(async () => {
128
- try {
129
- const octokit = new Octokit({ auth: githubToken.token });
130
- const response = await octokit.request('GET /gists/{gist_id}', {
131
- gist_id: gistId,
132
- });
133
- setGistUrl(response.data.html_url);
134
- } catch (err) {
135
- log.catch(err);
136
- setGistUrl(undefined);
137
- }
138
- });
139
-
140
- return () => clearTimeout(timeout);
127
+ try {
128
+ const octokit = new Octokit({ auth: githubToken.token });
129
+ const response = await octokit.request('GET /gists/{gist_id}', {
130
+ gist_id: gistId,
131
+ });
132
+ setGistUrl(response.data.html_url);
133
+ } catch (err) {
134
+ log.catch(err);
135
+ setGistUrl(undefined);
136
+ }
141
137
  }, [githubToken, gistKey]);
142
138
 
143
139
  const handleOpenTokenManager = useCallback(
@@ -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 { DeprecatedFormContainer, DeprecatedFormInput } from '@dxos/react-ui-form';
11
+ import { ControlGroup, ControlItemInput, ControlPage, ControlSection } from '@dxos/react-ui-form';
12
12
 
13
13
  import { meta } from '../../meta';
14
14
  import { type ScriptSettingsProps } from '../../types';
@@ -39,33 +39,38 @@ export const ScriptPluginSettings = ({ settings }: { settings: ScriptSettingsPro
39
39
  };
40
40
 
41
41
  return (
42
- <DeprecatedFormContainer>
43
- {/* TODO(wittjosiah): Hide outside of dev environments. */}
44
- <DeprecatedFormInput label={t('authenticate action label')}>
45
- <Button onClick={handleAuthenticate}>{t('authenticate button label')}</Button>
46
- </DeprecatedFormInput>
42
+ <ControlPage>
43
+ <ControlSection title={t('settings title', { ns: meta.id })}>
44
+ <ControlGroup>
45
+ {/* TODO(wittjosiah): Hide outside of dev environments. */}
46
+ <ControlItemInput title={t('authenticate action label')}>
47
+ <Button onClick={handleAuthenticate}>{t('authenticate button label')}</Button>
48
+ </ControlItemInput>
47
49
 
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>
69
- </DeprecatedFormContainer>
50
+ <ControlItemInput title={t('editor input mode label')}>
51
+ <Select.Root
52
+ value={settings.editorInputMode ?? 'default'}
53
+ onValueChange={(value) => {
54
+ settings.editorInputMode = value as EditorInputMode;
55
+ }}
56
+ >
57
+ <Select.TriggerButton placeholder={t('select editor input mode placeholder')} />
58
+ <Select.Portal>
59
+ <Select.Content>
60
+ <Select.Viewport>
61
+ {EditorInputModes.map((mode) => (
62
+ <Select.Option key={mode} value={mode}>
63
+ {t(`settings editor input mode ${mode} label`)}
64
+ </Select.Option>
65
+ ))}
66
+ </Select.Viewport>
67
+ <Select.Arrow />
68
+ </Select.Content>
69
+ </Select.Portal>
70
+ </Select.Root>
71
+ </ControlItemInput>
72
+ </ControlGroup>
73
+ </ControlSection>
74
+ </ControlPage>
70
75
  );
71
76
  };
@@ -7,9 +7,10 @@ import React from 'react';
7
7
  import { type ScriptType } from '@dxos/functions';
8
8
  import { StackItem } from '@dxos/react-ui-stack';
9
9
 
10
- import { TestPanel } from './TestPanel';
11
10
  import { useDeployState, useToolbarState } from '../../hooks';
12
11
 
12
+ import { TestPanel } from './TestPanel';
13
+
13
14
  export type TestContainerProps = {
14
15
  role: string;
15
16
  script: ScriptType;
@@ -237,7 +237,7 @@ const MessageItem = ({ classNames, message }: ThemedClassName<{ message: Message
237
237
  )}
238
238
 
239
239
  {data && (
240
- <SyntaxHighlighter language='json' className={mx(wrapper, 'px-8 py-2 text-xs')}>
240
+ <SyntaxHighlighter language='json' className={mx(wrapper, 'text-xs')}>
241
241
  {JSON.stringify(data, null, 2)}
242
242
  </SyntaxHighlighter>
243
243
  )}
@@ -4,25 +4,16 @@
4
4
 
5
5
  import '@dxos-theme';
6
6
 
7
- import { type Meta } from '@storybook/react-vite';
7
+ import { type Meta, type StoryObj } from '@storybook/react-vite';
8
8
  import React, { useMemo } from 'react';
9
9
 
10
10
  import { createDocAccessor, createObject } from '@dxos/react-client/echo';
11
11
  import { createDataExtensions } from '@dxos/react-ui-editor';
12
12
  import { withTheme } from '@dxos/storybook-utils';
13
13
 
14
- import { TypescriptEditor } from './TypescriptEditor';
15
14
  import { templates } from '../../templates';
16
15
 
17
- // TODO(burdon): Features:
18
- // - language support for S
19
- // - hierarchical editor (DND)
20
- // - virtual document image rendering
21
- // - mobile rendering error
22
-
23
- // TODO(burdon): JSX.
24
- // TODO(burdon): Effect schema.
25
- // TODO(burdon): react-buddy for storybook?
16
+ import { TypescriptEditor } from './TypescriptEditor';
26
17
 
27
18
  const DefaultStory = () => {
28
19
  const object = useMemo(() => createObject({ content: templates[0].source }), []);
@@ -32,13 +23,15 @@ const DefaultStory = () => {
32
23
  return <TypescriptEditor id='test' initialValue={initialValue} extensions={extensions} />;
33
24
  };
34
25
 
35
- export const Default = {};
36
-
37
- const meta: Meta = {
26
+ const meta = {
38
27
  title: 'plugins/plugin-script/TypescriptEditor',
39
- component: TypescriptEditor,
28
+ component: TypescriptEditor as any,
40
29
  render: DefaultStory,
41
30
  decorators: [withTheme],
42
- };
31
+ } satisfies Meta<typeof DefaultStory>;
43
32
 
44
33
  export default meta;
34
+
35
+ type Story = StoryObj<typeof meta>;
36
+
37
+ export const Default: Story = {};
@@ -2,6 +2,7 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
+ import { autocompletion, completionKeymap } from '@codemirror/autocomplete';
5
6
  import { javascript } from '@codemirror/lang-javascript';
6
7
  import { defaultHighlightStyle } from '@codemirror/language';
7
8
  import { lintKeymap } from '@codemirror/lint';
@@ -11,15 +12,14 @@ import { keymap } from '@codemirror/view';
11
12
  import { tags } from '@lezer/highlight';
12
13
  import { type VirtualTypeScriptEnvironment } from '@typescript/vfs';
13
14
  import { continueKeymap } from '@valtown/codemirror-continue';
14
- import { tsSync, tsFacet, tsLinter, tsAutocomplete, tsHover, type HoverInfo } from '@valtown/codemirror-ts';
15
+ import { type HoverInfo, tsAutocomplete, tsFacet, tsHover, tsLinter, tsSync } from '@valtown/codemirror-ts';
15
16
  import React from 'react';
16
17
 
17
- import { type ThemedClassName, type ThemeMode, useThemeContext } from '@dxos/react-ui';
18
+ import { type ThemeMode, type ThemedClassName, useThemeContext } from '@dxos/react-ui';
18
19
  import {
19
20
  type EditorInputMode,
20
21
  InputModeExtensions,
21
22
  type UseTextEditorProps,
22
- autocomplete,
23
23
  createBasicExtensions,
24
24
  createThemeExtensions,
25
25
  folding,
@@ -64,6 +64,7 @@ export const TypescriptEditor = ({
64
64
  lineWrapping: false,
65
65
  monospace: true,
66
66
  scrollPastEnd: true,
67
+ search: true,
67
68
  }),
68
69
  createThemeExtensions({ themeMode, syntaxHighlighting: true }),
69
70
  InputModeExtensions[inputMode],
@@ -74,7 +75,8 @@ export const TypescriptEditor = ({
74
75
  // TODO(burdon): Factor out.
75
76
  javascript({ typescript: true }),
76
77
  // https://github.com/val-town/codemirror-ts
77
- autocomplete({ override: env ? [tsAutocomplete()] : undefined }),
78
+ keymap.of(completionKeymap),
79
+ autocompletion({ override: env ? [tsAutocomplete()] : undefined }),
78
80
  keymap.of(lintKeymap),
79
81
  env && [
80
82
  tsFacet.of({ env, path: `/src/${id}.ts` }),
@@ -4,10 +4,10 @@
4
4
 
5
5
  import { useEffect, useMemo } from 'react';
6
6
 
7
- import { FunctionType, type ScriptType, getUserFunctionUrlInMetadata } from '@dxos/functions';
7
+ import { FunctionType, type ScriptType, getUserFunctionIdInMetadata } from '@dxos/functions';
8
8
  import { log } from '@dxos/log';
9
9
  import { type Client, useClient } from '@dxos/react-client';
10
- import { getMeta, getSpace, Query, Ref, type Space, useQuery } from '@dxos/react-client/echo';
10
+ import { Query, Ref, type Space, getMeta, getSpace, useQuery } from '@dxos/react-client/echo';
11
11
  import { type TFunction } from '@dxos/react-ui';
12
12
  import { createMenuAction } from '@dxos/react-ui-menu';
13
13
  import { errorMessageColors } from '@dxos/react-ui-theme';
@@ -29,12 +29,12 @@ export type CreateDeployOptions = {
29
29
  script: ScriptType;
30
30
  fn: FunctionType;
31
31
  space?: Space;
32
- existingFunctionUrl?: string;
32
+ existingFunctionId?: string;
33
33
  client: Client;
34
34
  t: TFunction;
35
35
  };
36
36
 
37
- export const createDeploy = ({ state, script, space, fn, client, existingFunctionUrl, t }: CreateDeployOptions) => {
37
+ export const createDeploy = ({ state, script, space, fn, client, existingFunctionId, t }: CreateDeployOptions) => {
38
38
  // TODO(wittjosiah): Should this be an action?
39
39
  const errorItem = createMenuAction('error', () => {}, {
40
40
  label: state.error ?? ['no error label', { ns: SCRIPT_PLUGIN }],
@@ -53,7 +53,7 @@ export const createDeploy = ({ state, script, space, fn, client, existingFunctio
53
53
  state.error = undefined;
54
54
  state.deploying = true;
55
55
 
56
- const result = await deployScript({ script, client, space, fn, existingFunctionUrl });
56
+ const result = await deployScript({ script, client, space, fn, existingFunctionId });
57
57
 
58
58
  if (!result.success) {
59
59
  log.catch(result.error);
@@ -98,9 +98,9 @@ export const createDeploy = ({ state, script, space, fn, client, existingFunctio
98
98
  };
99
99
 
100
100
  export const useDeployState = ({ state, script }: { state: Partial<DeployState>; script: ScriptType }) => {
101
- const { space, client, fn, existingFunctionUrl } = useDeployDeps({ script });
101
+ const { space, client, fn, existingFunctionId } = useDeployDeps({ script });
102
102
  useEffect(() => {
103
- if (!existingFunctionUrl) {
103
+ if (!existingFunctionId) {
104
104
  return;
105
105
  }
106
106
 
@@ -109,17 +109,17 @@ export const useDeployState = ({ state, script }: { state: Partial<DeployState>;
109
109
  fn,
110
110
  edgeUrl: client.config.values.runtime?.services?.edge?.url ?? '',
111
111
  });
112
- }, [existingFunctionUrl, space, fn, script, client.config.values.runtime?.services?.edge?.url]);
112
+ }, [existingFunctionId, space, fn, script, client.config.values.runtime?.services?.edge?.url]);
113
113
 
114
114
  useEffect(() => {
115
115
  state.deployed = isScriptDeployed({ script, fn });
116
- }, [script.changed, existingFunctionUrl, fn, script]);
116
+ }, [script.changed, existingFunctionId, fn, script]);
117
117
  };
118
118
 
119
119
  export const useDeployDeps = ({ script }: { script: ScriptType }) => {
120
120
  const space = getSpace(script);
121
121
  const [fn] = useQuery(space, Query.type(FunctionType, { source: Ref.make(script) }));
122
122
  const client = useClient();
123
- const existingFunctionUrl = useMemo(() => fn && getUserFunctionUrlInMetadata(getMeta(fn)), [fn]);
124
- return { space, fn, client, existingFunctionUrl };
123
+ const existingFunctionId = useMemo(() => fn && getUserFunctionIdInMetadata(getMeta(fn)), [fn]);
124
+ return { space, fn, client, existingFunctionId };
125
125
  };
@@ -4,7 +4,7 @@
4
4
 
5
5
  import { Obj } from '@dxos/echo';
6
6
  import { FUNCTIONS_PRESET_META_KEY, type ScriptType } from '@dxos/functions';
7
- import { createMenuItemGroup, createMenuAction } from '@dxos/react-ui-menu';
7
+ import { createMenuAction, createMenuItemGroup } from '@dxos/react-ui-menu';
8
8
 
9
9
  import { SCRIPT_PLUGIN } from '../meta';
10
10
  import { templates } from '../templates';
@@ -55,5 +55,6 @@ export const useCreateAndDeployScriptTemplates = (space: Space | undefined, scri
55
55
  setStatus(hasErrors ? 'error' : 'success');
56
56
  }, [space, dispatch, client, scriptTemplates]);
57
57
 
58
+ // TODO(burdon): Return onCreateAndDeployScripts.
58
59
  return { handleCreateAndDeployScripts, status, error };
59
60
  };
@@ -3,7 +3,7 @@
3
3
  //
4
4
 
5
5
  // @ts-ignore
6
- import { defineFunction, S } from 'dxos:functions';
6
+ import { S, defineFunction } from 'dxos:functions';
7
7
  // @ts-ignore
8
8
  import { Chess } from 'https://esm.sh/chess.js@0.13.1?bundle=false';
9
9
 
@@ -3,7 +3,7 @@
3
3
  //
4
4
 
5
5
  // @ts-ignore
6
- import { defineFunction, S, create, Expando } from 'dxos:functions';
6
+ import { Expando, S, create, defineFunction } from 'dxos:functions';
7
7
  // @ts-ignore
8
8
  import { randText } from 'https://esm.sh/@ngneat/falso@7.1.1?bundle=false';
9
9
 
@@ -12,11 +12,15 @@ export default defineFunction({
12
12
  documentAmount: S.optional(S.Number),
13
13
  textSize: S.optional(S.Number),
14
14
  mutationAmount: S.optional(S.Number),
15
+ waitAfterCreation: S.optional(S.Number),
15
16
  }),
16
17
 
17
18
  outputSchema: S.Struct({}),
18
19
 
19
- handler: async ({ data: { documentAmount = 1, textSize = 10, mutationAmount = 0 }, context: { space } }: any) => {
20
+ handler: async ({
21
+ data: { documentAmount = 1, textSize = 10, mutationAmount = 0, waitAfterCreation = 10_000 },
22
+ context: { space },
23
+ }: any) => {
20
24
  await space.db.graph.schemaRegistry.addSchema([Expando]);
21
25
  const result: Record<string, any> = {};
22
26
  const objects: Expando[] = [];
@@ -42,7 +46,7 @@ export default defineFunction({
42
46
 
43
47
  // Flush and wait for data to propagate.
44
48
  await space.db.flush();
45
- await new Promise((resolve) => setTimeout(resolve, 10_000));
49
+ await new Promise((resolve) => setTimeout(resolve, waitAfterCreation));
46
50
  return { createdObjects: objects.length };
47
51
  },
48
52
  });
@@ -3,17 +3,17 @@
3
3
  //
4
4
 
5
5
  // @ts-ignore
6
- import { create, defineFunction, DXN, EchoObject, Filter, ObjectId, S } from 'dxos:functions';
6
+ import { DXN, EchoObject, Filter, ObjectId, S, create, defineFunction } from 'dxos:functions';
7
7
  // @ts-ignore
8
- import { FetchHttpClient } from 'https://esm.sh/@effect/platform@0.77.2?deps=effect@3.14.21&bundle=false';
8
+ import { FetchHttpClient } from 'https://esm.sh/@effect/platform@0.89.0?deps=effect@3.17.0&bundle=false';
9
9
  import {
10
10
  DiscordConfig,
11
11
  DiscordREST,
12
12
  DiscordRESTMemoryLive,
13
13
  // @ts-ignore
14
- } from 'https://esm.sh/dfx@0.113.0?deps=effect@3.14.21&bundle=false';
14
+ } from 'https://esm.sh/dfx@0.113.0?deps=effect@3.17.0&bundle=false';
15
15
  // @ts-ignore
16
- import { Effect, Config, Redacted, Ref } from 'https://esm.sh/effect@3.14.21?bundle=false';
16
+ import { Config, Effect, Redacted, Ref } from 'https://esm.sh/effect@3.17.0?bundle=false';
17
17
 
18
18
  const MessageSchema = S.Struct({
19
19
  id: ObjectId,
@@ -5,13 +5,13 @@
5
5
  // @ts-ignore
6
6
  import { S, defineFunction } from 'dxos:functions';
7
7
  import {
8
+ FetchHttpClient,
8
9
  HttpClient,
9
10
  HttpClientRequest,
10
- FetchHttpClient,
11
11
  // @ts-ignore
12
- } from 'https://esm.sh/@effect/platform@0.77.2?deps=effect@3.14.21&bundle=false';
12
+ } from 'https://esm.sh/@effect/platform@0.89.0?deps=effect@3.17.0&bundle=false';
13
13
  // @ts-ignore
14
- import { Effect, Schedule } from 'https://esm.sh/effect@3.14.21?bundle=false';
14
+ import { Effect, Schedule } from 'https://esm.sh/effect@3.17.0?bundle=false';
15
15
 
16
16
  export default defineFunction({
17
17
  description: 'Returns the exchange rate between two currencies.',
@@ -3,7 +3,7 @@
3
3
  //
4
4
 
5
5
  // @ts-ignore
6
- import { defineFunction, S } from 'dxos:functions';
6
+ import { S, defineFunction } from 'dxos:functions';
7
7
 
8
8
  export default defineFunction({
9
9
  description: 'Returns the exchange rate between two currencies.',
@@ -3,18 +3,18 @@
3
3
  //
4
4
 
5
5
  // @ts-ignore
6
- import { create, defineFunction, EchoObject, Filter, ObjectId, S } from 'dxos:functions';
6
+ import { EchoObject, Filter, ObjectId, S, create, defineFunction } from 'dxos:functions';
7
7
  // @ts-ignore
8
8
  import {
9
+ FetchHttpClient,
9
10
  HttpClient,
10
11
  HttpClientRequest,
11
- FetchHttpClient,
12
12
  // @ts-ignore
13
- } from 'https://esm.sh/@effect/platform@0.77.2?deps=effect@3.14.21&bundle=false';
13
+ } from 'https://esm.sh/@effect/platform@0.89.0?deps=effect@3.17.0&bundle=false';
14
14
  // @ts-ignore
15
15
  import { format, subDays } from 'https://esm.sh/date-fns@3.3.1?bundle=false';
16
16
  // @ts-ignore
17
- import { pipe, Chunk, Effect, Ref, Schedule, Stream } from 'https://esm.sh/effect@3.14.21?bundle=false';
17
+ import { Chunk, Effect, Ref, Schedule, Stream, pipe } from 'https://esm.sh/effect@3.17.0?bundle=false';
18
18
 
19
19
  export default defineFunction({
20
20
  inputSchema: S.Struct({
@@ -98,7 +98,7 @@ export default defineFunction({
98
98
  sender,
99
99
  blocks: [
100
100
  {
101
- type: 'text',
101
+ _tag: 'text',
102
102
  text: Buffer.from(content, 'base64').toString('utf-8'),
103
103
  },
104
104
  ],
@@ -174,57 +174,16 @@ const ActorSchema = S.Struct({
174
174
  role: S.optional(ActorRole),
175
175
  });
176
176
 
177
- const AbstractContentBlock = S.Struct({
177
+ const Base = S.Struct({
178
178
  pending: S.optional(S.Boolean),
179
179
  });
180
- type AbstractContentBlock = S.Schema.Type<typeof AbstractContentBlock>;
181
- const TextContentBlock = S.extend(
182
- AbstractContentBlock,
183
- S.Struct({
184
- type: S.Literal('text'),
185
- disposition: S.optional(S.String),
186
- text: S.String,
187
- }),
188
- ).pipe(S.mutable);
189
- type TextContentBlock = S.Schema.Type<typeof TextContentBlock>;
190
- const JsonContentBlock = S.extend(
191
- AbstractContentBlock,
192
- S.Struct({
193
- type: S.Literal('json'),
194
- disposition: S.optional(S.String),
195
- data: S.String,
196
- }),
197
- ).pipe(S.mutable);
198
- type JsonContentBlock = S.Schema.Type<typeof JsonContentBlock>;
199
- const Base64ImageSource = S.Struct({
200
- type: S.Literal('base64'),
201
- mediaType: S.String,
202
- data: S.String,
180
+ type Base = S.Schema.Type<typeof Base>;
181
+ const Text = S.TaggedStruct('text', {
182
+ mimeType: S.optional(S.String),
183
+ text: S.String,
184
+ ...Base.fields,
203
185
  }).pipe(S.mutable);
204
- const HttpImageSource = S.Struct({
205
- type: S.Literal('http'),
206
- url: S.String,
207
- }).pipe(S.mutable);
208
- const ImageSource = S.Union(Base64ImageSource, HttpImageSource);
209
- type ImageSource = S.Schema.Type<typeof ImageSource>;
210
- const ImageContentBlock = S.extend(
211
- AbstractContentBlock,
212
- S.Struct({
213
- type: S.Literal('image'),
214
- id: S.optional(S.String),
215
- source: S.optional(ImageSource),
216
- }),
217
- ).pipe(S.mutable);
218
- type ImageContentBlock = S.Schema.Type<typeof ImageContentBlock>;
219
- const ReferenceContentBlock = S.extend(
220
- AbstractContentBlock,
221
- S.Struct({
222
- type: S.Literal('reference'),
223
- reference: S.Any,
224
- }),
225
- ).pipe(S.mutable);
226
- type ReferenceContentBlock = S.Schema.Type<typeof ReferenceContentBlock>;
227
- const MessageContentBlock = S.Union(TextContentBlock, JsonContentBlock, ImageContentBlock, ReferenceContentBlock);
186
+ interface Text extends S.Schema.Type<typeof Text> {}
228
187
 
229
188
  const MessageType = S.Struct({
230
189
  id: ObjectId,
@@ -234,7 +193,7 @@ const MessageType = S.Struct({
234
193
  sender: ActorSchema.annotations({
235
194
  description: 'Identity of the message sender.',
236
195
  }),
237
- blocks: S.Array(MessageContentBlock).annotations({
196
+ blocks: S.Array(Text).annotations({
238
197
  description: 'Contents of the message.',
239
198
  }),
240
199
  properties: S.optional(
@@ -21,6 +21,7 @@ export const translations = [
21
21
  },
22
22
  [meta.id]: {
23
23
  'plugin name': 'Scripts',
24
+ 'settings title': 'Scripts plugin settings',
24
25
  'description label': 'Description',
25
26
  'description placeholder': 'Enter description',
26
27
  'binding placeholder': 'Function name',