@dxos/plugin-script 0.8.1-staging.5be625a → 0.8.1-staging.9eaf14f
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.
- package/dist/lib/browser/DeploymentDialog-AEPYJKPO.mjs +12 -0
- package/dist/lib/browser/DeploymentDialog-AEPYJKPO.mjs.map +7 -0
- package/dist/lib/browser/{ScriptContainer-DDXZNAPF.mjs → ScriptContainer-R25PRK2D.mjs} +26 -33
- package/dist/lib/browser/ScriptContainer-R25PRK2D.mjs.map +7 -0
- package/dist/lib/browser/app-graph-builder-RRLY67QC.mjs +64 -0
- package/dist/lib/browser/app-graph-builder-RRLY67QC.mjs.map +7 -0
- package/dist/lib/browser/{artifact-definition-GYCZJGR4.mjs → artifact-definition-WXFYD2V5.mjs} +5 -5
- package/dist/lib/browser/artifact-definition-WXFYD2V5.mjs.map +7 -0
- package/dist/lib/browser/{chunk-T7XG5GED.mjs → chunk-2CGZFDCR.mjs} +290 -277
- package/dist/lib/browser/chunk-2CGZFDCR.mjs.map +7 -0
- package/dist/lib/browser/chunk-4VD3K3PY.mjs +15 -0
- package/dist/lib/browser/{chunk-FG66JYON.mjs.map → chunk-4VD3K3PY.mjs.map} +3 -3
- package/dist/lib/browser/chunk-CSZXPLYY.mjs +147 -0
- package/dist/lib/browser/chunk-CSZXPLYY.mjs.map +7 -0
- package/dist/lib/browser/chunk-KLEOGVXY.mjs +352 -0
- package/dist/lib/browser/chunk-KLEOGVXY.mjs.map +7 -0
- package/dist/lib/browser/chunk-MQZQB5VD.mjs +233 -0
- package/dist/lib/browser/chunk-MQZQB5VD.mjs.map +7 -0
- package/dist/lib/browser/{chunk-AJNRPWAA.mjs → chunk-R2CHVWJ2.mjs} +5 -4
- package/dist/lib/browser/chunk-R2CHVWJ2.mjs.map +7 -0
- package/dist/lib/browser/chunk-SUCBNCEQ.mjs +87 -0
- package/dist/lib/browser/chunk-SUCBNCEQ.mjs.map +7 -0
- package/dist/lib/browser/{chunk-27LV6ARH.mjs → chunk-WSK3YQXI.mjs} +9 -3
- package/dist/lib/browser/{chunk-27LV6ARH.mjs.map → chunk-WSK3YQXI.mjs.map} +3 -3
- package/dist/lib/browser/{compiler-ZQLHHJ5P.mjs → compiler-56LTBEQB.mjs} +7 -7
- package/dist/lib/browser/index.mjs +62 -52
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/intent-resolver-WCVXKRBR.mjs +90 -0
- package/dist/lib/browser/intent-resolver-WCVXKRBR.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/react-surface-WXZVPNGI.mjs +117 -0
- package/dist/lib/browser/react-surface-WXZVPNGI.mjs.map +7 -0
- package/dist/lib/browser/{settings-467GVEBU.mjs → settings-Z7B37V2I.mjs} +6 -6
- package/dist/lib/browser/{settings-467GVEBU.mjs.map → settings-Z7B37V2I.mjs.map} +3 -3
- package/dist/lib/browser/types.mjs +5 -2
- package/dist/lib/node/DeploymentDialog-O4MU4OMF.cjs +33 -0
- package/dist/lib/node/DeploymentDialog-O4MU4OMF.cjs.map +7 -0
- package/dist/lib/node/{ScriptContainer-DM4WSS4Y.cjs → ScriptContainer-5KY6ZOQD.cjs} +29 -34
- package/dist/lib/node/ScriptContainer-5KY6ZOQD.cjs.map +7 -0
- package/dist/lib/node/app-graph-builder-6I2BWD46.cjs +80 -0
- package/dist/lib/node/app-graph-builder-6I2BWD46.cjs.map +7 -0
- package/dist/lib/node/{artifact-definition-3SNVJ34V.cjs → artifact-definition-6NVXEHJD.cjs} +11 -11
- package/dist/lib/node/artifact-definition-6NVXEHJD.cjs.map +7 -0
- package/dist/lib/node/chunk-65MIJR3Q.cjs +173 -0
- package/dist/lib/node/chunk-65MIJR3Q.cjs.map +7 -0
- package/dist/lib/node/chunk-F4DP7WON.cjs +372 -0
- package/dist/lib/node/chunk-F4DP7WON.cjs.map +7 -0
- package/dist/lib/node/{chunk-AOKGOI5J.cjs → chunk-JICWAOWZ.cjs} +6 -6
- package/dist/lib/node/{chunk-AOKGOI5J.cjs.map → chunk-JICWAOWZ.cjs.map} +3 -3
- package/dist/lib/node/{chunk-VLQUYHPB.cjs → chunk-SLDJM45C.cjs} +286 -272
- package/dist/lib/node/chunk-SLDJM45C.cjs.map +7 -0
- package/dist/lib/node/chunk-VYBEBLDO.cjs +251 -0
- package/dist/lib/node/chunk-VYBEBLDO.cjs.map +7 -0
- package/dist/lib/node/chunk-X7MHLHHS.cjs +91 -0
- package/dist/lib/node/chunk-X7MHLHHS.cjs.map +7 -0
- package/dist/lib/node/{chunk-XFB6JL2G.cjs → chunk-XFZPWFEG.cjs} +8 -7
- package/dist/lib/node/chunk-XFZPWFEG.cjs.map +7 -0
- package/dist/lib/node/{chunk-2XX4L67K.cjs → chunk-YJQZHKKA.cjs} +11 -4
- package/dist/lib/node/{chunk-2XX4L67K.cjs.map → chunk-YJQZHKKA.cjs.map} +3 -3
- package/dist/lib/node/{compiler-5ALLTH2B.cjs → compiler-W2RU3M7U.cjs} +8 -8
- package/dist/lib/node/index.cjs +72 -62
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/intent-resolver-J4NBDNFH.cjs +100 -0
- package/dist/lib/node/intent-resolver-J4NBDNFH.cjs.map +7 -0
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/react-surface-27KTUBIZ.cjs +129 -0
- package/dist/lib/node/react-surface-27KTUBIZ.cjs.map +7 -0
- package/dist/lib/node/{settings-WLYT2XQF.cjs → settings-EI6VPNKN.cjs} +9 -9
- package/dist/lib/node/{settings-WLYT2XQF.cjs.map → settings-EI6VPNKN.cjs.map} +3 -3
- package/dist/lib/node/types.cjs +6 -4
- package/dist/lib/node/types.cjs.map +2 -2
- package/dist/lib/node-esm/DeploymentDialog-SSQSWLHX.mjs +13 -0
- package/dist/lib/node-esm/DeploymentDialog-SSQSWLHX.mjs.map +7 -0
- package/dist/lib/node-esm/{ScriptContainer-HWCHDARL.mjs → ScriptContainer-W2F4FGDV.mjs} +26 -33
- package/dist/lib/node-esm/ScriptContainer-W2F4FGDV.mjs.map +7 -0
- package/dist/lib/node-esm/app-graph-builder-H5XLRVX3.mjs +65 -0
- package/dist/lib/node-esm/app-graph-builder-H5XLRVX3.mjs.map +7 -0
- package/dist/lib/node-esm/{artifact-definition-VAFNV62U.mjs → artifact-definition-KQ64AYBP.mjs} +5 -5
- package/dist/lib/node-esm/artifact-definition-KQ64AYBP.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-BIFA5BEB.mjs → chunk-4MTPYMV2.mjs} +290 -277
- package/dist/lib/node-esm/chunk-4MTPYMV2.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-MFXRE7ZD.mjs → chunk-EB5DSAD4.mjs} +5 -5
- package/dist/lib/node-esm/{chunk-MFXRE7ZD.mjs.map → chunk-EB5DSAD4.mjs.map} +3 -3
- package/dist/lib/node-esm/chunk-F4HA5C34.mjs +234 -0
- package/dist/lib/node-esm/chunk-F4HA5C34.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-5S2KBIMH.mjs → chunk-FDEAVT67.mjs} +9 -3
- package/dist/lib/node-esm/{chunk-5S2KBIMH.mjs.map → chunk-FDEAVT67.mjs.map} +3 -3
- package/dist/lib/node-esm/chunk-MU3JKVL2.mjs +148 -0
- package/dist/lib/node-esm/chunk-MU3JKVL2.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-PBGVTGL2.mjs +353 -0
- package/dist/lib/node-esm/chunk-PBGVTGL2.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-QDYGTY4L.mjs +89 -0
- package/dist/lib/node-esm/chunk-QDYGTY4L.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-WQ4YIZ2L.mjs → chunk-RW2APVMV.mjs} +5 -4
- package/dist/lib/node-esm/chunk-RW2APVMV.mjs.map +7 -0
- package/dist/lib/node-esm/{compiler-K7GYROAO.mjs → compiler-VT5C2Z3T.mjs} +7 -7
- package/dist/lib/node-esm/index.mjs +62 -52
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/intent-resolver-PDZ2A26X.mjs +91 -0
- package/dist/lib/node-esm/intent-resolver-PDZ2A26X.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/react-surface-UCUVDVSH.mjs +118 -0
- package/dist/lib/node-esm/react-surface-UCUVDVSH.mjs.map +7 -0
- package/dist/lib/node-esm/{settings-DR3B6GHE.mjs → settings-HU5UEFRF.mjs} +6 -6
- package/dist/lib/node-esm/{settings-DR3B6GHE.mjs.map → settings-HU5UEFRF.mjs.map} +3 -3
- package/dist/lib/node-esm/types.mjs +5 -2
- package/dist/types/src/ScriptPlugin.d.ts.map +1 -1
- package/dist/types/src/capabilities/app-graph-builder.d.ts +181 -0
- package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -0
- package/dist/types/src/capabilities/capabilities.d.ts.map +1 -1
- package/dist/types/src/capabilities/index.d.ts +178 -1
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -1
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
- package/dist/types/src/components/DeploymentDialog/DeploymentDialog.d.ts +11 -0
- package/dist/types/src/components/DeploymentDialog/DeploymentDialog.d.ts.map +1 -0
- package/dist/types/src/components/DeploymentDialog/DeploymentDialog.stories.d.ts +18 -0
- package/dist/types/src/components/DeploymentDialog/DeploymentDialog.stories.d.ts.map +1 -0
- package/dist/types/src/components/DeploymentDialog/index.d.ts +4 -0
- package/dist/types/src/components/DeploymentDialog/index.d.ts.map +1 -0
- package/dist/types/src/components/ScriptContainer.d.ts +3 -4
- package/dist/types/src/components/ScriptContainer.d.ts.map +1 -1
- package/dist/types/src/components/ScriptToolbar/ScriptToolbar.d.ts.map +1 -1
- package/dist/types/src/components/Settings/ScriptObjectSettings.d.ts +8 -0
- package/dist/types/src/components/Settings/ScriptObjectSettings.d.ts.map +1 -0
- package/dist/types/src/components/{ScriptSettings/ScriptSettings.d.ts → Settings/ScriptPluginSettings.d.ts} +2 -2
- package/dist/types/src/components/Settings/ScriptPluginSettings.d.ts.map +1 -0
- package/dist/types/src/components/Settings/index.d.ts +3 -0
- package/dist/types/src/components/Settings/index.d.ts.map +1 -0
- package/dist/types/src/components/TestPanel/TestPanel.d.ts +7 -0
- package/dist/types/src/components/TestPanel/TestPanel.d.ts.map +1 -0
- package/dist/types/src/components/TestPanel/index.d.ts +2 -0
- package/dist/types/src/components/TestPanel/index.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +8 -5
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/hooks/deploy.d.ts +10 -7
- package/dist/types/src/hooks/deploy.d.ts.map +1 -1
- package/dist/types/src/hooks/index.d.ts +1 -1
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useCreateAndDeployScriptTemplates.d.ts +17 -0
- package/dist/types/src/hooks/useCreateAndDeployScriptTemplates.d.ts.map +1 -0
- package/dist/types/src/hooks/useToolbarAction.d.ts +2 -3
- package/dist/types/src/hooks/useToolbarAction.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +1 -0
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/templates/chess.d.ts.map +1 -1
- package/dist/types/src/templates/data-generator.d.ts +10 -0
- package/dist/types/src/templates/data-generator.d.ts.map +1 -0
- package/dist/types/src/templates/forex-effect.d.ts.map +1 -1
- package/dist/types/src/templates/gmail.d.ts +3 -0
- package/dist/types/src/templates/gmail.d.ts.map +1 -0
- package/dist/types/src/templates/index.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +66 -15
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +4 -0
- package/dist/types/src/types.d.ts.map +1 -1
- package/dist/types/src/util/deploy.d.ts +25 -0
- package/dist/types/src/util/deploy.d.ts.map +1 -0
- package/dist/types/src/util/functions.d.ts +11 -0
- package/dist/types/src/util/functions.d.ts.map +1 -0
- package/dist/types/src/util/index.d.ts +3 -0
- package/dist/types/src/util/index.d.ts.map +1 -0
- package/package.json +51 -49
- package/src/ScriptPlugin.tsx +12 -17
- package/src/capabilities/app-graph-builder.ts +47 -0
- package/src/capabilities/artifact-definition.ts +1 -1
- package/src/capabilities/capabilities.ts +2 -2
- package/src/capabilities/index.ts +2 -1
- package/src/capabilities/intent-resolver.ts +39 -5
- package/src/capabilities/react-surface.tsx +62 -33
- package/src/capabilities/settings.ts +2 -2
- package/src/components/DeploymentDialog/DeploymentDialog.stories.tsx +39 -0
- package/src/components/DeploymentDialog/DeploymentDialog.tsx +112 -0
- package/src/components/DeploymentDialog/index.ts +9 -0
- package/src/components/ScriptContainer.tsx +22 -35
- package/src/components/ScriptToolbar/ScriptToolbar.tsx +3 -4
- package/src/components/{ScriptSettingsPanel.tsx → Settings/ScriptObjectSettings.tsx} +120 -102
- package/src/components/{ScriptSettings/ScriptSettings.tsx → Settings/ScriptPluginSettings.tsx} +3 -3
- package/src/components/Settings/index.ts +6 -0
- package/src/components/{DebugPanel/DebugPanel.tsx → TestPanel/TestPanel.tsx} +8 -14
- package/src/components/{LogsPanel → TestPanel}/index.ts +1 -1
- package/src/components/index.ts +4 -4
- package/src/hooks/deploy.ts +31 -80
- package/src/hooks/index.ts +1 -1
- package/src/hooks/useCreateAndDeployScriptTemplates.ts +59 -0
- package/src/hooks/useToolbarAction.ts +9 -22
- package/src/meta.ts +5 -0
- package/src/templates/chess.ts +4 -0
- package/src/templates/data-generator.ts +73 -0
- package/src/templates/discord.ts +1 -1
- package/src/templates/forex-effect.ts +2 -1
- package/src/templates/gmail.ts +244 -0
- package/src/templates/index.ts +14 -0
- package/src/translations.ts +27 -8
- package/src/types.ts +4 -0
- package/src/util/deploy.ts +126 -0
- package/src/util/functions.ts +53 -0
- package/src/util/index.ts +6 -0
- package/dist/lib/browser/ScriptContainer-DDXZNAPF.mjs.map +0 -7
- package/dist/lib/browser/artifact-definition-GYCZJGR4.mjs.map +0 -7
- package/dist/lib/browser/chunk-4SSKJNMZ.mjs +0 -69
- package/dist/lib/browser/chunk-4SSKJNMZ.mjs.map +0 -7
- package/dist/lib/browser/chunk-AJNRPWAA.mjs.map +0 -7
- package/dist/lib/browser/chunk-FG66JYON.mjs +0 -15
- package/dist/lib/browser/chunk-LJN26TSM.mjs +0 -526
- package/dist/lib/browser/chunk-LJN26TSM.mjs.map +0 -7
- package/dist/lib/browser/chunk-T7XG5GED.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-3B3Z67FP.mjs +0 -45
- package/dist/lib/browser/intent-resolver-3B3Z67FP.mjs.map +0 -7
- package/dist/lib/browser/react-surface-ICXHFHN7.mjs +0 -79
- package/dist/lib/browser/react-surface-ICXHFHN7.mjs.map +0 -7
- package/dist/lib/node/ScriptContainer-DM4WSS4Y.cjs.map +0 -7
- package/dist/lib/node/artifact-definition-3SNVJ34V.cjs.map +0 -7
- package/dist/lib/node/chunk-I5Z6TRZY.cjs +0 -548
- package/dist/lib/node/chunk-I5Z6TRZY.cjs.map +0 -7
- package/dist/lib/node/chunk-VLQUYHPB.cjs.map +0 -7
- package/dist/lib/node/chunk-XCQNFRZ6.cjs +0 -77
- package/dist/lib/node/chunk-XCQNFRZ6.cjs.map +0 -7
- package/dist/lib/node/chunk-XFB6JL2G.cjs.map +0 -7
- package/dist/lib/node/intent-resolver-CN5WMMAD.cjs +0 -59
- package/dist/lib/node/intent-resolver-CN5WMMAD.cjs.map +0 -7
- package/dist/lib/node/react-surface-IER3VEZR.cjs +0 -95
- package/dist/lib/node/react-surface-IER3VEZR.cjs.map +0 -7
- package/dist/lib/node-esm/ScriptContainer-HWCHDARL.mjs.map +0 -7
- package/dist/lib/node-esm/artifact-definition-VAFNV62U.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-4YUSGXJ2.mjs +0 -71
- package/dist/lib/node-esm/chunk-4YUSGXJ2.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-BIFA5BEB.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-F2O475DQ.mjs +0 -527
- package/dist/lib/node-esm/chunk-F2O475DQ.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-WQ4YIZ2L.mjs.map +0 -7
- package/dist/lib/node-esm/intent-resolver-6F7CVQEX.mjs +0 -46
- package/dist/lib/node-esm/intent-resolver-6F7CVQEX.mjs.map +0 -7
- package/dist/lib/node-esm/react-surface-EXSKKZNP.mjs +0 -80
- package/dist/lib/node-esm/react-surface-EXSKKZNP.mjs.map +0 -7
- package/dist/types/src/components/DebugPanel/DebugPanel.d.ts +0 -7
- package/dist/types/src/components/DebugPanel/DebugPanel.d.ts.map +0 -1
- package/dist/types/src/components/DebugPanel/index.d.ts +0 -2
- package/dist/types/src/components/DebugPanel/index.d.ts.map +0 -1
- package/dist/types/src/components/LogsPanel/LogsPanel.d.ts +0 -8
- package/dist/types/src/components/LogsPanel/LogsPanel.d.ts.map +0 -1
- package/dist/types/src/components/LogsPanel/index.d.ts +0 -2
- package/dist/types/src/components/LogsPanel/index.d.ts.map +0 -1
- package/dist/types/src/components/ScriptSettings/ScriptSettings.d.ts.map +0 -1
- package/dist/types/src/components/ScriptSettings/index.d.ts +0 -2
- package/dist/types/src/components/ScriptSettings/index.d.ts.map +0 -1
- package/dist/types/src/components/ScriptSettingsPanel.d.ts +0 -7
- package/dist/types/src/components/ScriptSettingsPanel.d.ts.map +0 -1
- package/dist/types/src/hooks/view.d.ts +0 -21
- package/dist/types/src/hooks/view.d.ts.map +0 -1
- package/src/components/DebugPanel/index.ts +0 -5
- package/src/components/LogsPanel/LogsPanel.tsx +0 -116
- package/src/components/ScriptSettings/index.ts +0 -5
- package/src/hooks/view.ts +0 -38
- /package/dist/lib/browser/{compiler-ZQLHHJ5P.mjs.map → compiler-56LTBEQB.mjs.map} +0 -0
- /package/dist/lib/node/{compiler-5ALLTH2B.cjs.map → compiler-W2RU3M7U.cjs.map} +0 -0
- /package/dist/lib/node-esm/{compiler-K7GYROAO.mjs.map → compiler-VT5C2Z3T.mjs.map} +0 -0
|
@@ -10,27 +10,110 @@ 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,
|
|
13
|
+
import { Button, Clipboard, Input, useControlledState, useTranslation } from '@dxos/react-ui';
|
|
14
14
|
import { AccessTokenType } from '@dxos/schema';
|
|
15
15
|
|
|
16
|
-
import { SCRIPT_PLUGIN } from '
|
|
16
|
+
import { SCRIPT_PLUGIN } from '../../meta';
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
export type ScriptObjectSettingsProps = {
|
|
19
|
+
object: ScriptType;
|
|
20
|
+
};
|
|
21
21
|
|
|
22
|
-
export
|
|
23
|
-
|
|
22
|
+
export const ScriptObjectSettings = ({ object }: ScriptObjectSettingsProps) => {
|
|
23
|
+
return (
|
|
24
|
+
<>
|
|
25
|
+
<Binding object={object} />
|
|
26
|
+
<Publishing object={object} />
|
|
27
|
+
</>
|
|
28
|
+
);
|
|
24
29
|
};
|
|
25
30
|
|
|
26
|
-
export const
|
|
31
|
+
export const ScriptProperties = ({ object }: ScriptObjectSettingsProps) => {
|
|
32
|
+
const { t } = useTranslation(SCRIPT_PLUGIN);
|
|
33
|
+
return (
|
|
34
|
+
<Input.Root>
|
|
35
|
+
<Input.Label>{t('description label')}</Input.Label>
|
|
36
|
+
<Input.TextInput
|
|
37
|
+
placeholder={t('description placeholder')}
|
|
38
|
+
value={object.description ?? ''}
|
|
39
|
+
onChange={(event) => {
|
|
40
|
+
object.description = event.target.value;
|
|
41
|
+
}}
|
|
42
|
+
/>
|
|
43
|
+
</Input.Root>
|
|
44
|
+
);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const Binding = ({ object }: ScriptObjectSettingsProps) => {
|
|
27
48
|
const { t } = useTranslation(SCRIPT_PLUGIN);
|
|
28
|
-
const { dispatchPromise: dispatch } = useIntentDispatcher();
|
|
29
49
|
const client = useClient();
|
|
30
|
-
const space = getSpace(
|
|
31
|
-
const [fn] = useQuery(space, Filter.schema(FunctionType, { source:
|
|
50
|
+
const space = getSpace(object);
|
|
51
|
+
const [fn] = useQuery(space, Filter.schema(FunctionType, { source: object }));
|
|
52
|
+
|
|
53
|
+
const functionPath = fn && getUserFunctionUrlInMetadata(getMeta(fn));
|
|
54
|
+
const functionUrl =
|
|
55
|
+
functionPath &&
|
|
56
|
+
getInvocationUrl(functionPath, client.config.values.runtime?.services?.edge?.url ?? '', {
|
|
57
|
+
spaceId: space?.id,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
const [binding, setBinding] = useControlledState(fn?.binding ?? '');
|
|
61
|
+
const handleBindingChange = useCallback(
|
|
62
|
+
(event: ChangeEvent<HTMLInputElement>) => {
|
|
63
|
+
setBinding(event.target.value);
|
|
64
|
+
},
|
|
65
|
+
[setBinding],
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
const handleBindingBlur = useCallback(() => {
|
|
69
|
+
fn.binding = binding;
|
|
70
|
+
}, [fn, binding]);
|
|
71
|
+
|
|
72
|
+
if (!fn || !functionUrl) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// TODO(burdon): Use form.
|
|
77
|
+
return (
|
|
78
|
+
<div role='form' className='flex flex-col p-2 gap-2'>
|
|
79
|
+
<h2>{t('remote function settings heading')}</h2>
|
|
80
|
+
<Input.Root>
|
|
81
|
+
<div role='none' className='flex flex-col gap-1'>
|
|
82
|
+
<Input.Label>{t('function url label')}</Input.Label>
|
|
83
|
+
<div role='none' className='flex gap-1'>
|
|
84
|
+
<Input.TextInput
|
|
85
|
+
disabled
|
|
86
|
+
value={functionUrl}
|
|
87
|
+
onChange={(event) => {
|
|
88
|
+
fn.name = event.target.value;
|
|
89
|
+
}}
|
|
90
|
+
/>
|
|
91
|
+
<Clipboard.IconButton value={functionUrl} />
|
|
92
|
+
</div>
|
|
93
|
+
</div>
|
|
94
|
+
</Input.Root>
|
|
95
|
+
<Input.Root>
|
|
96
|
+
<div role='none' className='flex flex-col gap-1'>
|
|
97
|
+
<Input.Label>{t('function binding label')}</Input.Label>
|
|
98
|
+
<Input.TextInput
|
|
99
|
+
placeholder={t('function binding placeholder')}
|
|
100
|
+
value={binding}
|
|
101
|
+
onChange={handleBindingChange}
|
|
102
|
+
onBlur={handleBindingBlur}
|
|
103
|
+
/>
|
|
104
|
+
</div>
|
|
105
|
+
</Input.Root>
|
|
106
|
+
</div>
|
|
107
|
+
);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
// TODO(burdon): Move to separate tab?
|
|
111
|
+
const Publishing = ({ object }: ScriptObjectSettingsProps) => {
|
|
112
|
+
const { t } = useTranslation(SCRIPT_PLUGIN);
|
|
113
|
+
const { dispatchPromise: dispatch } = useIntentDispatcher();
|
|
114
|
+
const space = getSpace(object);
|
|
32
115
|
const [githubToken] = useQuery(space, Filter.schema(AccessTokenType, { source: 'github.com' }));
|
|
33
|
-
const gistKey = getMeta(
|
|
116
|
+
const gistKey = getMeta(object).keys.find(({ source }) => source === 'github.com');
|
|
34
117
|
const [gistUrl, setGistUrl] = useState<string | undefined>();
|
|
35
118
|
|
|
36
119
|
useEffect(() => {
|
|
@@ -57,24 +140,6 @@ export const ScriptSettingsPanel = ({ script }: ScriptSettingsPanelProps) => {
|
|
|
57
140
|
return () => clearTimeout(timeout);
|
|
58
141
|
}, [githubToken, gistKey]);
|
|
59
142
|
|
|
60
|
-
const [binding, setBinding] = useControlledState(fn?.binding ?? '');
|
|
61
|
-
const handleBindingChange = useCallback(
|
|
62
|
-
(event: ChangeEvent<HTMLInputElement>) => {
|
|
63
|
-
setBinding(event.target.value);
|
|
64
|
-
},
|
|
65
|
-
[setBinding],
|
|
66
|
-
);
|
|
67
|
-
const handleBindingBlur = useCallback(() => {
|
|
68
|
-
fn.binding = binding;
|
|
69
|
-
}, [fn, binding]);
|
|
70
|
-
|
|
71
|
-
const functionPath = fn && getUserFunctionUrlInMetadata(getMeta(fn));
|
|
72
|
-
const functionUrl =
|
|
73
|
-
functionPath &&
|
|
74
|
-
getInvocationUrl(functionPath, client.config.values.runtime?.services?.edge?.url ?? '', {
|
|
75
|
-
spaceId: space?.id,
|
|
76
|
-
});
|
|
77
|
-
|
|
78
143
|
const handleOpenTokenManager = useCallback(
|
|
79
144
|
() => dispatch(createIntent(SettingsAction.Open, { plugin: 'dxos.org/plugin/token-manager' })),
|
|
80
145
|
[],
|
|
@@ -84,13 +149,13 @@ export const ScriptSettingsPanel = ({ script }: ScriptSettingsPanelProps) => {
|
|
|
84
149
|
const handlePublish = useCallback(async () => {
|
|
85
150
|
setPublishing(true);
|
|
86
151
|
const octokit = new Octokit({ auth: githubToken.token });
|
|
87
|
-
const source = await
|
|
88
|
-
const filename =
|
|
152
|
+
const source = await object.source.load();
|
|
153
|
+
const filename = object.name ? kebabize(object.name) : 'composer-script';
|
|
89
154
|
const files = { [`${filename}.ts`]: { content: source.content } };
|
|
90
155
|
|
|
91
156
|
try {
|
|
92
157
|
// TODO(wittjosiah): Factor out to intent.
|
|
93
|
-
const meta = getMeta(
|
|
158
|
+
const meta = getMeta(object);
|
|
94
159
|
const githubKey = meta.keys.find(({ source }) => source === 'github.com');
|
|
95
160
|
const gistId = githubKey?.id;
|
|
96
161
|
if (gistId) {
|
|
@@ -110,79 +175,32 @@ export const ScriptSettingsPanel = ({ script }: ScriptSettingsPanelProps) => {
|
|
|
110
175
|
} finally {
|
|
111
176
|
setPublishing(false);
|
|
112
177
|
}
|
|
113
|
-
}, [
|
|
178
|
+
}, [object, githubToken]);
|
|
114
179
|
|
|
115
180
|
return (
|
|
116
|
-
|
|
117
|
-
<div
|
|
118
|
-
<
|
|
119
|
-
|
|
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>
|
|
181
|
+
<div className='flex flex-col p-2 gap-4'>
|
|
182
|
+
<div>
|
|
183
|
+
<h2>{t('script publish settings label')}</h2>
|
|
184
|
+
<p className='text-description text-sm'>{t('script publish settings description')}</p>
|
|
130
185
|
</div>
|
|
131
|
-
{
|
|
132
|
-
|
|
133
|
-
<
|
|
134
|
-
<
|
|
135
|
-
|
|
136
|
-
<Input.Root>
|
|
137
|
-
<div role='none' className='flex flex-col gap-1'>
|
|
138
|
-
<Input.Label>{t('function url label')}</Input.Label>
|
|
139
|
-
<div role='none' className='flex gap-1'>
|
|
140
|
-
<Input.TextInput
|
|
141
|
-
disabled
|
|
142
|
-
value={functionUrl}
|
|
143
|
-
onChange={(event) => {
|
|
144
|
-
fn.name = event.target.value;
|
|
145
|
-
}}
|
|
146
|
-
/>
|
|
147
|
-
<Clipboard.IconButton value={functionUrl} />
|
|
148
|
-
</div>
|
|
149
|
-
</div>
|
|
150
|
-
</Input.Root>
|
|
151
|
-
<Input.Root>
|
|
152
|
-
<div role='none' className='flex flex-col gap-1'>
|
|
153
|
-
<Input.Label>{t('function binding label')}</Input.Label>
|
|
154
|
-
<Input.TextInput
|
|
155
|
-
placeholder={t('function binding placeholder')}
|
|
156
|
-
value={binding}
|
|
157
|
-
onChange={handleBindingChange}
|
|
158
|
-
onBlur={handleBindingBlur}
|
|
159
|
-
/>
|
|
160
|
-
</div>
|
|
161
|
-
</Input.Root>
|
|
162
|
-
</div>
|
|
163
|
-
</>
|
|
186
|
+
{!githubToken && (
|
|
187
|
+
<div className='flex flex-col gap-2'>
|
|
188
|
+
<span>{t('no github token label')}</span>
|
|
189
|
+
<Button onClick={handleOpenTokenManager}>{t('open token manager label')}</Button>
|
|
190
|
+
</div>
|
|
164
191
|
)}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
<
|
|
169
|
-
|
|
192
|
+
{githubToken && (
|
|
193
|
+
<div className='flex justify-end gap-2'>
|
|
194
|
+
{gistUrl && <Clipboard.IconButton value={gistUrl} />}
|
|
195
|
+
<Button disabled={publishing} onClick={handlePublish}>
|
|
196
|
+
{t(publishing ? 'publishing label' : 'publish label')}
|
|
197
|
+
</Button>
|
|
170
198
|
</div>
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
<span>{t('no github token label')}</span>
|
|
174
|
-
<Button onClick={handleOpenTokenManager}>{t('open token manager label')}</Button>
|
|
175
|
-
</div>
|
|
176
|
-
)}
|
|
177
|
-
{githubToken && (
|
|
178
|
-
<div className='flex justify-end gap-2'>
|
|
179
|
-
{gistUrl && <Clipboard.IconButton value={gistUrl} />}
|
|
180
|
-
<Button disabled={publishing} onClick={handlePublish}>
|
|
181
|
-
{t(publishing ? 'publishing label' : 'publish label')}
|
|
182
|
-
</Button>
|
|
183
|
-
</div>
|
|
184
|
-
)}
|
|
185
|
-
</div>
|
|
186
|
-
</>
|
|
199
|
+
)}
|
|
200
|
+
</div>
|
|
187
201
|
);
|
|
188
202
|
};
|
|
203
|
+
|
|
204
|
+
// TODO(wittjosiah): Factor out.
|
|
205
|
+
// From https://stackoverflow.com/a/67243723/2804332
|
|
206
|
+
const kebabize = (str: string) => str.replace(/[A-Z]+(?![a-z])|[A-Z]/g, ($, ofs) => (ofs ? '-' : '') + $.toLowerCase());
|
package/src/components/{ScriptSettings/ScriptSettings.tsx → Settings/ScriptPluginSettings.tsx}
RENAMED
|
@@ -10,11 +10,11 @@ import { Button, Select, useTranslation } from '@dxos/react-ui';
|
|
|
10
10
|
import { type EditorInputMode, EditorInputModes } from '@dxos/react-ui-editor';
|
|
11
11
|
import { DeprecatedFormContainer, DeprecatedFormInput } from '@dxos/react-ui-form';
|
|
12
12
|
|
|
13
|
-
import {
|
|
13
|
+
import { meta } from '../../meta';
|
|
14
14
|
import { type ScriptSettingsProps } from '../../types';
|
|
15
15
|
|
|
16
|
-
export const
|
|
17
|
-
const { t } = useTranslation(
|
|
16
|
+
export const ScriptPluginSettings = ({ settings }: { settings: ScriptSettingsProps }) => {
|
|
17
|
+
const { t } = useTranslation(meta.id);
|
|
18
18
|
const client = useClient();
|
|
19
19
|
|
|
20
20
|
// TODO(burdon): Check token.
|
|
@@ -18,11 +18,12 @@ type State = 'pending' | 'responding';
|
|
|
18
18
|
*/
|
|
19
19
|
type Message = { type: 'request' | 'response'; text?: string; data?: any; error?: Error };
|
|
20
20
|
|
|
21
|
-
export type
|
|
21
|
+
export type TestPanelProps = ThemedClassName<{
|
|
22
22
|
functionUrl?: string;
|
|
23
23
|
}>;
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
// TODO(burdon): Need persistent history (currently lost when switching tabs)..
|
|
26
|
+
export const TestPanel = ({ classNames, functionUrl }: TestPanelProps) => {
|
|
26
27
|
const { t } = useTranslation(SCRIPT_PLUGIN);
|
|
27
28
|
|
|
28
29
|
const inputRef = useRef<HTMLInputElement>(null);
|
|
@@ -30,7 +31,7 @@ export const DebugPanel = ({ classNames, functionUrl }: DebugPanelProps) => {
|
|
|
30
31
|
const [result, setResult] = useState('');
|
|
31
32
|
const [state, setState] = useState<State | null>(null);
|
|
32
33
|
|
|
33
|
-
// TODO(burdon): Persistent history
|
|
34
|
+
// TODO(burdon): Persistent history (thread).
|
|
34
35
|
const [history, setHistory] = useState<Message[]>([]);
|
|
35
36
|
|
|
36
37
|
const scrollerRef = useRef<HTMLDivElement>(null);
|
|
@@ -161,8 +162,8 @@ export const DebugPanel = ({ classNames, functionUrl }: DebugPanelProps) => {
|
|
|
161
162
|
<div className={mx('flex flex-col h-full overflow-hidden', classNames)}>
|
|
162
163
|
{/* TODO(burdon): Replace with Thread. */}
|
|
163
164
|
<MessageThread ref={scrollerRef} state={state} result={result} history={history} />
|
|
164
|
-
|
|
165
|
-
<Toolbar.Root classNames='p-
|
|
165
|
+
{/* TODO(burdon): Replace with Form based on the function's input schema. */}
|
|
166
|
+
<Toolbar.Root classNames='p-2'>
|
|
166
167
|
<Input.Root>
|
|
167
168
|
<Input.TextInput
|
|
168
169
|
ref={inputRef}
|
|
@@ -185,7 +186,6 @@ export const DebugPanel = ({ classNames, functionUrl }: DebugPanelProps) => {
|
|
|
185
186
|
};
|
|
186
187
|
|
|
187
188
|
// TODO(burdon): Replace with thread?
|
|
188
|
-
// TODO(burdon): Button to delete individual messages.
|
|
189
189
|
// TODO(burdon): Button to edit/re-run question.
|
|
190
190
|
type MessageThreadProps = {
|
|
191
191
|
state: State | null;
|
|
@@ -195,10 +195,6 @@ type MessageThreadProps = {
|
|
|
195
195
|
|
|
196
196
|
const MessageThread = forwardRef<HTMLDivElement, MessageThreadProps>(
|
|
197
197
|
({ state, history, result }: MessageThreadProps, forwardedRef) => {
|
|
198
|
-
if (!history.length && !result.length) {
|
|
199
|
-
return null;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
198
|
return (
|
|
203
199
|
<div ref={forwardedRef} className='flex flex-col gap-6 h-full p-2 overflow-x-hidden overflow-y-auto'>
|
|
204
200
|
{history.map((message, i) => (
|
|
@@ -250,9 +246,7 @@ const MessageItem = ({ classNames, message }: ThemedClassName<{ message: Message
|
|
|
250
246
|
};
|
|
251
247
|
|
|
252
248
|
const RobotAvatar = () => (
|
|
253
|
-
<Avatar.Root
|
|
254
|
-
<Avatar.
|
|
255
|
-
<Avatar.Icon icon='ph--robot--regular' />
|
|
256
|
-
</Avatar.Frame>
|
|
249
|
+
<Avatar.Root>
|
|
250
|
+
<Avatar.Content size={6} variant='circle' icon='ph--robot--regular' />
|
|
257
251
|
</Avatar.Root>
|
|
258
252
|
);
|
package/src/components/index.ts
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
import { lazy } from 'react';
|
|
6
6
|
|
|
7
|
-
export * from './
|
|
8
|
-
export * from './
|
|
9
|
-
export
|
|
10
|
-
export * from './ScriptSettingsPanel';
|
|
7
|
+
export * from './Settings';
|
|
8
|
+
export * from './TestPanel';
|
|
9
|
+
export { DEPLOYMENT_DIALOG } from './DeploymentDialog';
|
|
11
10
|
|
|
12
11
|
export const ScriptContainer = lazy(() => import('./ScriptContainer'));
|
|
12
|
+
export const DeploymentDialog = lazy(() => import('./DeploymentDialog'));
|
package/src/hooks/deploy.ts
CHANGED
|
@@ -4,28 +4,20 @@
|
|
|
4
4
|
|
|
5
5
|
import { useCallback, useEffect, useMemo } from 'react';
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
FunctionType,
|
|
9
|
-
type ScriptType,
|
|
10
|
-
getInvocationUrl,
|
|
11
|
-
getUserFunctionUrlInMetadata,
|
|
12
|
-
incrementSemverPatch,
|
|
13
|
-
setUserFunctionUrlInMetadata,
|
|
14
|
-
uploadWorkerFunction,
|
|
15
|
-
} from '@dxos/functions';
|
|
16
|
-
import { Bundler } from '@dxos/functions/bundler';
|
|
7
|
+
import { FunctionType, type ScriptType, getUserFunctionUrlInMetadata } from '@dxos/functions';
|
|
17
8
|
import { log } from '@dxos/log';
|
|
18
9
|
import { useClient } from '@dxos/react-client';
|
|
19
|
-
import { Filter,
|
|
10
|
+
import { Filter, getMeta, getSpace, useQuery } from '@dxos/react-client/echo';
|
|
20
11
|
import { useTranslation } from '@dxos/react-ui';
|
|
21
12
|
import { createMenuAction } from '@dxos/react-ui-menu';
|
|
13
|
+
import { errorMessageColors } from '@dxos/react-ui-theme';
|
|
22
14
|
|
|
23
|
-
import { type ViewState } from './view';
|
|
24
15
|
import { SCRIPT_PLUGIN } from '../meta';
|
|
16
|
+
import { deployScript, getFunctionUrl, isScriptDeployed } from '../util';
|
|
25
17
|
|
|
26
18
|
export type DeployActionProperties = { type: 'deploy' } | { type: 'copy' };
|
|
27
19
|
|
|
28
|
-
export type DeployState =
|
|
20
|
+
export type DeployState = {
|
|
29
21
|
deploying: boolean;
|
|
30
22
|
deployed: boolean;
|
|
31
23
|
functionUrl: string;
|
|
@@ -37,6 +29,7 @@ export const createDeploy = (state: Partial<DeployState>) => {
|
|
|
37
29
|
label: state.error ?? ['no error label', { ns: SCRIPT_PLUGIN }],
|
|
38
30
|
icon: 'ph--warning-circle--regular',
|
|
39
31
|
hidden: !state.error,
|
|
32
|
+
classNames: state.error && errorMessageColors,
|
|
40
33
|
});
|
|
41
34
|
|
|
42
35
|
const deployAction = createMenuAction<DeployActionProperties>('deploy', {
|
|
@@ -64,31 +57,36 @@ export const createDeploy = (state: Partial<DeployState>) => {
|
|
|
64
57
|
};
|
|
65
58
|
};
|
|
66
59
|
|
|
67
|
-
export const useDeployDeps = ({ script }: { script: ScriptType }) => {
|
|
68
|
-
const space = getSpace(script);
|
|
69
|
-
const [fn] = useQuery(space, Filter.schema(FunctionType, { source: script }));
|
|
70
|
-
const client = useClient();
|
|
71
|
-
const existingFunctionUrl = useMemo(() => fn && getUserFunctionUrlInMetadata(getMeta(fn)), [fn]);
|
|
72
|
-
return { space, fn, client, existingFunctionUrl };
|
|
73
|
-
};
|
|
74
|
-
|
|
75
60
|
export const useDeployState = ({ state, script }: { state: Partial<DeployState>; script: ScriptType }) => {
|
|
76
|
-
const { space, client, existingFunctionUrl } = useDeployDeps({ script });
|
|
61
|
+
const { space, client, fn, existingFunctionUrl } = useDeployDeps({ script });
|
|
77
62
|
useEffect(() => {
|
|
78
63
|
if (!existingFunctionUrl) {
|
|
79
64
|
return;
|
|
80
65
|
}
|
|
81
66
|
|
|
82
|
-
state.functionUrl =
|
|
83
|
-
|
|
67
|
+
state.functionUrl = getFunctionUrl({
|
|
68
|
+
script,
|
|
69
|
+
fn,
|
|
70
|
+
edgeUrl: client.config.values.runtime?.services?.edge?.url ?? '',
|
|
84
71
|
});
|
|
85
|
-
}, [existingFunctionUrl, space]);
|
|
72
|
+
}, [existingFunctionUrl, space, fn, script, client.config.values.runtime?.services?.edge?.url]);
|
|
86
73
|
|
|
87
74
|
useEffect(() => {
|
|
88
|
-
state.deployed =
|
|
89
|
-
}, [script.changed, existingFunctionUrl]);
|
|
75
|
+
state.deployed = isScriptDeployed({ script, fn });
|
|
76
|
+
}, [script.changed, existingFunctionUrl, fn, script]);
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export const useDeployDeps = ({ script }: { script: ScriptType }) => {
|
|
80
|
+
const space = getSpace(script);
|
|
81
|
+
const [fn] = useQuery(space, Filter.schema(FunctionType, { source: script }));
|
|
82
|
+
const client = useClient();
|
|
83
|
+
const existingFunctionUrl = useMemo(() => fn && getUserFunctionUrlInMetadata(getMeta(fn)), [fn]);
|
|
84
|
+
return { space, fn, client, existingFunctionUrl };
|
|
90
85
|
};
|
|
91
86
|
|
|
87
|
+
/**
|
|
88
|
+
* Manage EDGE function deployment.
|
|
89
|
+
*/
|
|
92
90
|
export const useDeployHandler = ({ state, script }: { state: Partial<DeployState>; script: ScriptType }) => {
|
|
93
91
|
const { space, fn, client, existingFunctionUrl } = useDeployDeps({ script });
|
|
94
92
|
const { t } = useTranslation(SCRIPT_PLUGIN);
|
|
@@ -101,62 +99,15 @@ export const useDeployHandler = ({ state, script }: { state: Partial<DeployState
|
|
|
101
99
|
state.error = undefined;
|
|
102
100
|
state.deploying = true;
|
|
103
101
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const buildResult = await bundler.bundle({ source: script.source.target!.content });
|
|
109
|
-
if (buildResult.error || !buildResult.bundle) {
|
|
110
|
-
throw buildResult.error;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const { functionId, version, meta } = await uploadWorkerFunction({
|
|
114
|
-
client,
|
|
115
|
-
spaceId: space.id,
|
|
116
|
-
version: fn ? incrementSemverPatch(fn.version) : '0.0.1',
|
|
117
|
-
functionId: existingFunctionId,
|
|
118
|
-
source: buildResult.bundle,
|
|
119
|
-
});
|
|
120
|
-
if (functionId === undefined || version === undefined) {
|
|
121
|
-
throw new Error(`Upload didn't return expected data: functionId=${functionId}, version=${version}`);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
log.info('function uploaded', { functionId, version });
|
|
125
|
-
if (fn) {
|
|
126
|
-
fn.version = version;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const deployedFunction =
|
|
130
|
-
fn ?? space.db.add(create(FunctionType, { name: functionId, version, source: makeRef(script) }));
|
|
131
|
-
|
|
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
|
-
}
|
|
140
|
-
|
|
141
|
-
if (meta.inputSchema) {
|
|
142
|
-
deployedFunction.inputSchema = meta.inputSchema;
|
|
143
|
-
} else {
|
|
144
|
-
log.verbose('no input schema in function metadata', { functionId });
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
if (meta.outputSchema) {
|
|
148
|
-
deployedFunction.outputSchema = meta.outputSchema;
|
|
149
|
-
} else {
|
|
150
|
-
log.verbose('no output schema in function metadata', { functionId });
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
setUserFunctionUrlInMetadata(getMeta(deployedFunction), `/${space.id}/${functionId}`);
|
|
154
|
-
} catch (err: any) {
|
|
155
|
-
log.catch(err);
|
|
102
|
+
const result = await deployScript({ script, client, space, fn, existingFunctionUrl });
|
|
103
|
+
|
|
104
|
+
if (!result.success) {
|
|
105
|
+
log.catch(result.error);
|
|
156
106
|
state.error = t('upload failed label');
|
|
157
107
|
}
|
|
108
|
+
|
|
158
109
|
state.deploying = false;
|
|
159
|
-
}, [fn, client, t, existingFunctionUrl, script,
|
|
110
|
+
}, [fn, client, t, existingFunctionUrl, script, space]);
|
|
160
111
|
};
|
|
161
112
|
|
|
162
113
|
export const useCopyHandler = ({ state }: { state: Partial<DeployState> }) =>
|
package/src/hooks/index.ts
CHANGED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { pipe } from 'effect/Function';
|
|
6
|
+
import { useCallback, useState } from 'react';
|
|
7
|
+
|
|
8
|
+
import { chain, createIntent, useIntentDispatcher } from '@dxos/app-framework';
|
|
9
|
+
import { isInstanceOf } from '@dxos/echo-schema';
|
|
10
|
+
import { ScriptType } from '@dxos/functions';
|
|
11
|
+
import { invariant } from '@dxos/invariant';
|
|
12
|
+
import { SpaceAction } from '@dxos/plugin-space/types';
|
|
13
|
+
import { useClient } from '@dxos/react-client';
|
|
14
|
+
import { type Space } from '@dxos/react-client/echo';
|
|
15
|
+
|
|
16
|
+
import { type Template } from '../templates';
|
|
17
|
+
import { ScriptAction } from '../types';
|
|
18
|
+
import { deployScript } from '../util';
|
|
19
|
+
|
|
20
|
+
type DeploymentStatus = 'idle' | 'pending' | 'success' | 'error';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Hook for creating and deploying multiple script templates concurrently.
|
|
24
|
+
*
|
|
25
|
+
* Takes a space and an array of script template IDs, then provides a callback
|
|
26
|
+
* function that creates each script from its template and deploys it to the space.
|
|
27
|
+
* All creation / deployment operations run concurrently for improved performance.
|
|
28
|
+
*/
|
|
29
|
+
export const useCreateAndDeployScriptTemplates = (space: Space | undefined, scriptTemplates: Template[]) => {
|
|
30
|
+
const { dispatchPromise: dispatch } = useIntentDispatcher();
|
|
31
|
+
const client = useClient();
|
|
32
|
+
const [status, setStatus] = useState<DeploymentStatus>('idle');
|
|
33
|
+
const [error, setError] = useState<Error | undefined>(undefined);
|
|
34
|
+
|
|
35
|
+
const handleCreateAndDeployScripts = useCallback(async () => {
|
|
36
|
+
invariant(space);
|
|
37
|
+
setStatus('pending');
|
|
38
|
+
setError(undefined);
|
|
39
|
+
|
|
40
|
+
const deploymentResults = await Promise.all(
|
|
41
|
+
scriptTemplates.map(async (template) => {
|
|
42
|
+
const result = await dispatch(
|
|
43
|
+
pipe(
|
|
44
|
+
createIntent(ScriptAction.Create, { space, initialTemplateId: template.id }),
|
|
45
|
+
chain(SpaceAction.AddObject, { target: space }),
|
|
46
|
+
),
|
|
47
|
+
);
|
|
48
|
+
invariant(isInstanceOf(ScriptType, result.data?.object));
|
|
49
|
+
|
|
50
|
+
return deployScript({ space, client, script: result.data.object });
|
|
51
|
+
}),
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
const hasErrors = deploymentResults.some((result) => !result.success);
|
|
55
|
+
setStatus(hasErrors ? 'error' : 'success');
|
|
56
|
+
}, [space, dispatch, client, scriptTemplates]);
|
|
57
|
+
|
|
58
|
+
return { handleCreateAndDeployScripts, status, error };
|
|
59
|
+
};
|
|
@@ -4,44 +4,31 @@
|
|
|
4
4
|
|
|
5
5
|
import { useCallback } from 'react';
|
|
6
6
|
|
|
7
|
-
import { createIntent, useIntentDispatcher } from '@dxos/app-framework';
|
|
8
7
|
import { type ScriptType } from '@dxos/functions/types';
|
|
9
8
|
import { log } from '@dxos/log';
|
|
10
|
-
import { DeckAction, surfaceVariant } from '@dxos/plugin-deck/types';
|
|
11
|
-
import { fullyQualifiedId } from '@dxos/react-client/echo';
|
|
12
9
|
import { type MenuAction, type MenuActionHandler } from '@dxos/react-ui-menu';
|
|
13
10
|
|
|
14
11
|
import { type DeployActionProperties, useDeployHandler, useCopyHandler } from './deploy';
|
|
15
12
|
import { type FormatActionProperties, useFormatHandler } from './format';
|
|
16
13
|
import { type TemplateActionProperties, useTemplateSelectHandler } from './template';
|
|
17
14
|
import { type ScriptToolbarState } from './useToolbarState';
|
|
18
|
-
import { type ViewActionProperties } from './view';
|
|
19
15
|
|
|
20
|
-
export type ScriptToolbarActionProperties =
|
|
21
|
-
| TemplateActionProperties
|
|
22
|
-
| ViewActionProperties
|
|
23
|
-
| FormatActionProperties
|
|
24
|
-
| DeployActionProperties;
|
|
16
|
+
export type ScriptToolbarActionProperties = TemplateActionProperties | FormatActionProperties | DeployActionProperties;
|
|
25
17
|
|
|
26
18
|
export type ScriptToolbarAction = MenuAction<ScriptToolbarActionProperties>;
|
|
27
19
|
|
|
28
|
-
export const useToolbarAction = (props: {
|
|
20
|
+
export const useToolbarAction = (props: {
|
|
21
|
+
state: ScriptToolbarState;
|
|
22
|
+
script: ScriptType;
|
|
23
|
+
}): MenuActionHandler<ScriptToolbarAction> => {
|
|
29
24
|
const handleTemplateSelect = useTemplateSelectHandler(props);
|
|
30
25
|
const handleFormat = useFormatHandler(props);
|
|
31
26
|
const handleDeploy = useDeployHandler(props);
|
|
32
27
|
const handleCopy = useCopyHandler(props);
|
|
33
|
-
|
|
34
|
-
return useCallback(
|
|
35
|
-
(
|
|
28
|
+
|
|
29
|
+
return useCallback<MenuActionHandler<ScriptToolbarAction>>(
|
|
30
|
+
(action: ScriptToolbarAction) => {
|
|
36
31
|
switch (action.properties.type) {
|
|
37
|
-
case 'view':
|
|
38
|
-
void dispatch(
|
|
39
|
-
createIntent(DeckAction.ChangeCompanion, {
|
|
40
|
-
primary: fullyQualifiedId(props.script),
|
|
41
|
-
companion: surfaceVariant('logs'),
|
|
42
|
-
}),
|
|
43
|
-
);
|
|
44
|
-
break;
|
|
45
32
|
case 'template':
|
|
46
33
|
handleTemplateSelect(action.properties.value);
|
|
47
34
|
break;
|
|
@@ -57,7 +44,7 @@ export const useToolbarAction = (props: { state: ScriptToolbarState; script: Scr
|
|
|
57
44
|
default:
|
|
58
45
|
log.error('Unknown action type', action);
|
|
59
46
|
}
|
|
60
|
-
}
|
|
47
|
+
},
|
|
61
48
|
[handleTemplateSelect, handleFormat, handleDeploy, handleCopy],
|
|
62
49
|
);
|
|
63
50
|
};
|