@dxos/plugin-script 0.8.2-main.2f9c567 → 0.8.2-main.30e4dbb
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-EMYG5BCD.mjs → DeploymentDialog-UG5U6FV3.mjs} +3 -3
- package/dist/lib/browser/{ScriptContainer-YI4U25EM.mjs → ScriptContainer-DXWBDTTY.mjs} +29 -16
- package/dist/lib/browser/ScriptContainer-DXWBDTTY.mjs.map +7 -0
- package/dist/lib/browser/{chunk-FIWZUPMO.mjs → chunk-46GGDAF3.mjs} +80 -149
- package/dist/lib/browser/chunk-46GGDAF3.mjs.map +7 -0
- package/dist/lib/browser/{chunk-RIKHDIEO.mjs → chunk-6KNSDU6W.mjs} +2 -2
- package/dist/lib/browser/{chunk-AA3MEHWR.mjs → chunk-DC5K5J2I.mjs} +3 -4
- package/dist/lib/browser/chunk-DC5K5J2I.mjs.map +7 -0
- package/dist/lib/browser/chunk-GTJJTVTQ.mjs +87 -0
- package/dist/lib/browser/chunk-GTJJTVTQ.mjs.map +7 -0
- package/dist/lib/browser/{chunk-4EA5VWVM.mjs → chunk-XA23QLKB.mjs} +3 -3
- package/dist/lib/browser/index.mjs +5 -5
- package/dist/lib/browser/{intent-resolver-UCPY7F6I.mjs → intent-resolver-R4K3E4TC.mjs} +5 -5
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/{react-surface-M76DWUVT.mjs → react-surface-CB57UU7H.mjs} +6 -6
- package/dist/lib/node/{DeploymentDialog-VWKE3X2Y.cjs → DeploymentDialog-AN3MHEJO.cjs} +8 -8
- package/dist/lib/node/{DeploymentDialog-VWKE3X2Y.cjs.map → DeploymentDialog-AN3MHEJO.cjs.map} +2 -2
- package/dist/lib/node/{ScriptContainer-2MIDQAOV.cjs → ScriptContainer-G7ZMW2Q7.cjs} +29 -18
- package/dist/lib/node/ScriptContainer-G7ZMW2Q7.cjs.map +7 -0
- package/dist/lib/node/{chunk-XT76CMHH.cjs → chunk-3TAIWINX.cjs} +6 -7
- package/dist/lib/node/chunk-3TAIWINX.cjs.map +7 -0
- package/dist/lib/node/chunk-DGFQHBA7.cjs +91 -0
- package/dist/lib/node/chunk-DGFQHBA7.cjs.map +7 -0
- package/dist/lib/node/{chunk-I4U27VO6.cjs → chunk-OWEKYL6J.cjs} +6 -6
- package/dist/lib/node/{chunk-FVCSTJDX.cjs → chunk-SB2KMOBO.cjs} +84 -151
- package/dist/lib/node/chunk-SB2KMOBO.cjs.map +7 -0
- package/dist/lib/node/{chunk-NBOJUJSM.cjs → chunk-TEALGRAH.cjs} +6 -6
- package/dist/lib/node/index.cjs +12 -12
- package/dist/lib/node/{intent-resolver-IO3FBKP2.cjs → intent-resolver-CVBZQA4C.cjs} +12 -12
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/{react-surface-AIHO75E7.cjs → react-surface-DX24JIJ2.cjs} +19 -19
- package/dist/lib/node-esm/{DeploymentDialog-FGFA6MG2.mjs → DeploymentDialog-D5K6GURW.mjs} +3 -3
- package/dist/lib/node-esm/{ScriptContainer-GYTXNQMB.mjs → ScriptContainer-ILGGJ7Z2.mjs} +29 -16
- package/dist/lib/node-esm/ScriptContainer-ILGGJ7Z2.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-5ES2REWL.mjs +89 -0
- package/dist/lib/node-esm/chunk-5ES2REWL.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-X27CHZ64.mjs → chunk-BHP3ROOY.mjs} +3 -4
- package/dist/lib/node-esm/chunk-BHP3ROOY.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-3FAUXSL4.mjs → chunk-OE2RF62T.mjs} +80 -149
- package/dist/lib/node-esm/chunk-OE2RF62T.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-NERLX6GG.mjs → chunk-PYEI5U66.mjs} +2 -2
- package/dist/lib/node-esm/{chunk-OSDNCSBE.mjs → chunk-RR3TOXE5.mjs} +3 -3
- package/dist/lib/node-esm/index.mjs +5 -5
- package/dist/lib/node-esm/{intent-resolver-W3MJ427G.mjs → intent-resolver-LOA5H2J3.mjs} +5 -5
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/{react-surface-IAUELUG6.mjs → react-surface-SO4EPQE4.mjs} +6 -6
- package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -1
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/components/DeploymentDialog/DeploymentDialog.d.ts.map +1 -1
- package/dist/types/src/components/FrameContainer/FrameContainer.d.ts.map +1 -1
- 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.map +1 -1
- package/dist/types/src/components/Settings/ScriptPluginSettings.d.ts.map +1 -1
- package/dist/types/src/components/TestPanel/TestPanel.d.ts.map +1 -1
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.d.ts.map +1 -1
- package/dist/types/src/hooks/deploy.d.ts +16 -14
- package/dist/types/src/hooks/deploy.d.ts.map +1 -1
- package/dist/types/src/hooks/format.d.ts +1 -4
- package/dist/types/src/hooks/format.d.ts.map +1 -1
- package/dist/types/src/hooks/index.d.ts +0 -1
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/template.d.ts +1 -4
- package/dist/types/src/hooks/template.d.ts.map +1 -1
- package/dist/types/src/hooks/useCreateAndDeployScriptTemplates.d.ts.map +1 -1
- package/dist/types/src/hooks/useToolbarState.d.ts.map +1 -1
- package/dist/types/src/templates/chat.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.map +1 -1
- package/dist/types/src/templates/discord.d.ts.map +1 -1
- package/dist/types/src/templates/echo.d.ts.map +1 -1
- package/dist/types/src/templates/email.d.ts.map +1 -1
- package/dist/types/src/templates/forex-effect.d.ts.map +1 -1
- package/dist/types/src/templates/forex.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +2 -110
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types.d.ts.map +1 -1
- package/dist/types/src/util/deploy.d.ts.map +1 -1
- package/dist/types/src/util/functions.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +49 -49
- package/src/components/DeploymentDialog/DeploymentDialog.stories.tsx +1 -1
- package/src/components/ScriptToolbar/ScriptToolbar.stories.tsx +1 -1
- package/src/components/ScriptToolbar/ScriptToolbar.tsx +15 -9
- package/src/hooks/deploy.ts +60 -54
- package/src/hooks/format.ts +25 -25
- package/src/hooks/index.ts +0 -1
- package/src/hooks/template.ts +23 -31
- package/src/templates/chess.ts +6 -7
- package/src/templates/data-generator.ts +5 -6
- package/src/templates/discord.ts +13 -14
- package/src/templates/forex-effect.ts +5 -6
- package/src/templates/forex.ts +4 -5
- package/src/templates/gmail.ts +68 -68
- package/src/util/deploy.ts +1 -2
- package/dist/lib/browser/ScriptContainer-YI4U25EM.mjs.map +0 -7
- package/dist/lib/browser/chunk-AA3MEHWR.mjs.map +0 -7
- package/dist/lib/browser/chunk-AIO76GTZ.mjs +0 -87
- package/dist/lib/browser/chunk-AIO76GTZ.mjs.map +0 -7
- package/dist/lib/browser/chunk-FIWZUPMO.mjs.map +0 -7
- package/dist/lib/node/ScriptContainer-2MIDQAOV.cjs.map +0 -7
- package/dist/lib/node/chunk-BWBZ22HH.cjs +0 -91
- package/dist/lib/node/chunk-BWBZ22HH.cjs.map +0 -7
- package/dist/lib/node/chunk-FVCSTJDX.cjs.map +0 -7
- package/dist/lib/node/chunk-XT76CMHH.cjs.map +0 -7
- package/dist/lib/node-esm/ScriptContainer-GYTXNQMB.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-3FAUXSL4.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-NMMN5ZIG.mjs +0 -89
- package/dist/lib/node-esm/chunk-NMMN5ZIG.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-X27CHZ64.mjs.map +0 -7
- package/dist/types/src/hooks/useToolbarAction.d.ts +0 -13
- package/dist/types/src/hooks/useToolbarAction.d.ts.map +0 -1
- package/src/hooks/useToolbarAction.ts +0 -50
- /package/dist/lib/browser/{DeploymentDialog-EMYG5BCD.mjs.map → DeploymentDialog-UG5U6FV3.mjs.map} +0 -0
- /package/dist/lib/browser/{chunk-RIKHDIEO.mjs.map → chunk-6KNSDU6W.mjs.map} +0 -0
- /package/dist/lib/browser/{chunk-4EA5VWVM.mjs.map → chunk-XA23QLKB.mjs.map} +0 -0
- /package/dist/lib/browser/{intent-resolver-UCPY7F6I.mjs.map → intent-resolver-R4K3E4TC.mjs.map} +0 -0
- /package/dist/lib/browser/{react-surface-M76DWUVT.mjs.map → react-surface-CB57UU7H.mjs.map} +0 -0
- /package/dist/lib/node/{chunk-I4U27VO6.cjs.map → chunk-OWEKYL6J.cjs.map} +0 -0
- /package/dist/lib/node/{chunk-NBOJUJSM.cjs.map → chunk-TEALGRAH.cjs.map} +0 -0
- /package/dist/lib/node/{intent-resolver-IO3FBKP2.cjs.map → intent-resolver-CVBZQA4C.cjs.map} +0 -0
- /package/dist/lib/node/{react-surface-AIHO75E7.cjs.map → react-surface-DX24JIJ2.cjs.map} +0 -0
- /package/dist/lib/node-esm/{DeploymentDialog-FGFA6MG2.mjs.map → DeploymentDialog-D5K6GURW.mjs.map} +0 -0
- /package/dist/lib/node-esm/{chunk-NERLX6GG.mjs.map → chunk-PYEI5U66.mjs.map} +0 -0
- /package/dist/lib/node-esm/{chunk-OSDNCSBE.mjs.map → chunk-RR3TOXE5.mjs.map} +0 -0
- /package/dist/lib/node-esm/{intent-resolver-W3MJ427G.mjs.map → intent-resolver-LOA5H2J3.mjs.map} +0 -0
- /package/dist/lib/node-esm/{react-surface-IAUELUG6.mjs.map → react-surface-SO4EPQE4.mjs.map} +0 -0
package/src/hooks/deploy.ts
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { useEffect, useMemo } from 'react';
|
|
6
6
|
|
|
7
7
|
import { FunctionType, type ScriptType, getUserFunctionUrlInMetadata } from '@dxos/functions';
|
|
8
8
|
import { log } from '@dxos/log';
|
|
9
|
-
import { useClient } from '@dxos/react-client';
|
|
10
|
-
import { Filter, getMeta, getSpace, useQuery } from '@dxos/react-client/echo';
|
|
11
|
-
import {
|
|
9
|
+
import { type Client, useClient } from '@dxos/react-client';
|
|
10
|
+
import { Filter, getMeta, getSpace, type Space, useQuery } from '@dxos/react-client/echo';
|
|
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';
|
|
14
14
|
|
|
@@ -24,28 +24,68 @@ export type DeployState = {
|
|
|
24
24
|
error: string;
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
export
|
|
28
|
-
|
|
27
|
+
export type CreateDeployOptions = {
|
|
28
|
+
state: Partial<DeployState>;
|
|
29
|
+
script: ScriptType;
|
|
30
|
+
fn: FunctionType;
|
|
31
|
+
space?: Space;
|
|
32
|
+
existingFunctionUrl?: string;
|
|
33
|
+
client: Client;
|
|
34
|
+
t: TFunction;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const createDeploy = ({ state, script, space, fn, client, existingFunctionUrl, t }: CreateDeployOptions) => {
|
|
38
|
+
// TODO(wittjosiah): Should this be an action?
|
|
39
|
+
const errorItem = createMenuAction('error', () => {}, {
|
|
29
40
|
label: state.error ?? ['no error label', { ns: SCRIPT_PLUGIN }],
|
|
30
41
|
icon: 'ph--warning-circle--regular',
|
|
31
42
|
hidden: !state.error,
|
|
32
43
|
classNames: state.error && errorMessageColors,
|
|
33
44
|
});
|
|
34
45
|
|
|
35
|
-
const deployAction = createMenuAction<DeployActionProperties>(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
const deployAction = createMenuAction<DeployActionProperties>(
|
|
47
|
+
'deploy',
|
|
48
|
+
async () => {
|
|
49
|
+
if (!script.source || !space) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
state.error = undefined;
|
|
54
|
+
state.deploying = true;
|
|
55
|
+
|
|
56
|
+
const result = await deployScript({ script, client, space, fn, existingFunctionUrl });
|
|
57
|
+
|
|
58
|
+
if (!result.success) {
|
|
59
|
+
log.catch(result.error);
|
|
60
|
+
state.error = t('upload failed label');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
state.deploying = false;
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
type: 'deploy',
|
|
67
|
+
label: [state.deploying ? 'pending label' : 'deploy label', { ns: SCRIPT_PLUGIN }],
|
|
68
|
+
icon: state.deploying ? 'ph--spinner-gap--regular' : 'ph--cloud-arrow-up--regular',
|
|
69
|
+
disabled: state.deploying,
|
|
70
|
+
classNames: state.deploying ? '[&_svg]:animate-spin' : '',
|
|
71
|
+
},
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
const copyAction = createMenuAction<DeployActionProperties>(
|
|
75
|
+
'copy',
|
|
76
|
+
async () => {
|
|
77
|
+
if (!state.functionUrl) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
await navigator.clipboard.writeText(state.functionUrl);
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
type: 'copy',
|
|
84
|
+
label: ['copy link label', { ns: SCRIPT_PLUGIN }],
|
|
85
|
+
icon: 'ph--link--regular',
|
|
86
|
+
disabled: !state.functionUrl,
|
|
87
|
+
},
|
|
88
|
+
);
|
|
49
89
|
|
|
50
90
|
return {
|
|
51
91
|
nodes: [errorItem, deployAction, copyAction],
|
|
@@ -83,37 +123,3 @@ export const useDeployDeps = ({ script }: { script: ScriptType }) => {
|
|
|
83
123
|
const existingFunctionUrl = useMemo(() => fn && getUserFunctionUrlInMetadata(getMeta(fn)), [fn]);
|
|
84
124
|
return { space, fn, client, existingFunctionUrl };
|
|
85
125
|
};
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Manage EDGE function deployment.
|
|
89
|
-
*/
|
|
90
|
-
export const useDeployHandler = ({ state, script }: { state: Partial<DeployState>; script: ScriptType }) => {
|
|
91
|
-
const { space, fn, client, existingFunctionUrl } = useDeployDeps({ script });
|
|
92
|
-
const { t } = useTranslation(SCRIPT_PLUGIN);
|
|
93
|
-
|
|
94
|
-
return useCallback(async () => {
|
|
95
|
-
if (!script.source || !space) {
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
state.error = undefined;
|
|
100
|
-
state.deploying = true;
|
|
101
|
-
|
|
102
|
-
const result = await deployScript({ script, client, space, fn, existingFunctionUrl });
|
|
103
|
-
|
|
104
|
-
if (!result.success) {
|
|
105
|
-
log.catch(result.error);
|
|
106
|
-
state.error = t('upload failed label');
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
state.deploying = false;
|
|
110
|
-
}, [fn, client, t, existingFunctionUrl, script, space]);
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
export const useCopyHandler = ({ state }: { state: Partial<DeployState> }) =>
|
|
114
|
-
useCallback(async () => {
|
|
115
|
-
if (!state.functionUrl) {
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
await navigator.clipboard.writeText(state.functionUrl);
|
|
119
|
-
}, [state.functionUrl]);
|
package/src/hooks/format.ts
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
import { format } from 'prettier';
|
|
6
6
|
import prettierPluginEstree from 'prettier/plugins/estree';
|
|
7
7
|
import prettierPluginTypescript from 'prettier/plugins/typescript';
|
|
8
|
-
import { useCallback } from 'react';
|
|
9
8
|
|
|
10
9
|
import { type ScriptType } from '@dxos/functions';
|
|
11
10
|
import { log } from '@dxos/log';
|
|
@@ -15,33 +14,34 @@ import { SCRIPT_PLUGIN } from '../meta';
|
|
|
15
14
|
|
|
16
15
|
export type FormatActionProperties = { type: 'format' };
|
|
17
16
|
|
|
18
|
-
export const createFormat = () => {
|
|
19
|
-
const formatAction = createMenuAction(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
export const createFormat = (script: ScriptType) => {
|
|
18
|
+
const formatAction = createMenuAction(
|
|
19
|
+
'format',
|
|
20
|
+
async () => {
|
|
21
|
+
if (!script.source) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
script.source.target!.content = await format(script.source.target!.content, {
|
|
27
|
+
parser: 'typescript',
|
|
28
|
+
plugins: [prettierPluginEstree, prettierPluginTypescript],
|
|
29
|
+
semi: true,
|
|
30
|
+
singleQuote: true,
|
|
31
|
+
});
|
|
32
|
+
} catch (err: any) {
|
|
33
|
+
// TODO(wittjosiah): Show error in UI.
|
|
34
|
+
log.catch(err);
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
label: ['format label', { ns: SCRIPT_PLUGIN }],
|
|
39
|
+
icon: 'ph--magic-wand--regular',
|
|
40
|
+
},
|
|
41
|
+
);
|
|
23
42
|
|
|
24
43
|
return {
|
|
25
44
|
nodes: [formatAction],
|
|
26
45
|
edges: [{ source: 'root', target: 'format' }],
|
|
27
46
|
};
|
|
28
47
|
};
|
|
29
|
-
|
|
30
|
-
export const useFormatHandler = ({ script }: { script: ScriptType }) =>
|
|
31
|
-
useCallback(async () => {
|
|
32
|
-
if (!script.source) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
try {
|
|
37
|
-
script.source.target!.content = await format(script.source.target!.content, {
|
|
38
|
-
parser: 'typescript',
|
|
39
|
-
plugins: [prettierPluginEstree, prettierPluginTypescript],
|
|
40
|
-
semi: true,
|
|
41
|
-
singleQuote: true,
|
|
42
|
-
});
|
|
43
|
-
} catch (err: any) {
|
|
44
|
-
// TODO(wittjosiah): Show error in UI.
|
|
45
|
-
log.catch(err);
|
|
46
|
-
}
|
|
47
|
-
}, [script.source]);
|
package/src/hooks/index.ts
CHANGED
package/src/hooks/template.ts
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { useCallback } from 'react';
|
|
6
|
-
|
|
7
5
|
import { FUNCTIONS_PRESET_META_KEY, type ScriptType } from '@dxos/functions';
|
|
8
6
|
import { getMeta } from '@dxos/live-object';
|
|
9
7
|
import { createMenuItemGroup, createMenuAction } from '@dxos/react-ui-menu';
|
|
@@ -20,19 +18,34 @@ const createTemplateSelectGroup = () => {
|
|
|
20
18
|
});
|
|
21
19
|
};
|
|
22
20
|
|
|
23
|
-
const createTemplateSelectActions = () => {
|
|
21
|
+
const createTemplateSelectActions = (script: ScriptType) => {
|
|
24
22
|
return templates.map((template) => {
|
|
25
|
-
return createMenuAction<TemplateActionProperties>(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
return createMenuAction<TemplateActionProperties>(
|
|
24
|
+
`template--${template.id}`,
|
|
25
|
+
() => {
|
|
26
|
+
script.name = template.name;
|
|
27
|
+
script.source!.target!.content = template.source;
|
|
28
|
+
const metaKeys = getMeta(script).keys;
|
|
29
|
+
const oldPresetIndex = metaKeys.findIndex((key) => key.source === FUNCTIONS_PRESET_META_KEY);
|
|
30
|
+
if (oldPresetIndex >= 0) {
|
|
31
|
+
metaKeys.splice(oldPresetIndex, 1);
|
|
32
|
+
}
|
|
33
|
+
if (template.presetId) {
|
|
34
|
+
metaKeys.push({ source: FUNCTIONS_PRESET_META_KEY, id: template.presetId });
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
label: template.name,
|
|
39
|
+
value: template.id,
|
|
40
|
+
type: 'template',
|
|
41
|
+
},
|
|
42
|
+
);
|
|
30
43
|
});
|
|
31
44
|
};
|
|
32
45
|
|
|
33
|
-
export const createTemplateSelect = () => {
|
|
46
|
+
export const createTemplateSelect = (script: ScriptType) => {
|
|
34
47
|
const templateSelectGroup = createTemplateSelectGroup();
|
|
35
|
-
const templateSelectActions = createTemplateSelectActions();
|
|
48
|
+
const templateSelectActions = createTemplateSelectActions(script);
|
|
36
49
|
return {
|
|
37
50
|
nodes: [templateSelectGroup, ...templateSelectActions],
|
|
38
51
|
edges: [
|
|
@@ -41,24 +54,3 @@ export const createTemplateSelect = () => {
|
|
|
41
54
|
],
|
|
42
55
|
};
|
|
43
56
|
};
|
|
44
|
-
|
|
45
|
-
export const useTemplateSelectHandler = ({ script }: { script: ScriptType }) => {
|
|
46
|
-
return useCallback(
|
|
47
|
-
(templateId: string) => {
|
|
48
|
-
const template = templates.find((template) => template.id === templateId);
|
|
49
|
-
if (template) {
|
|
50
|
-
script.name = template.name;
|
|
51
|
-
script.source!.target!.content = template.source;
|
|
52
|
-
const metaKeys = getMeta(script).keys;
|
|
53
|
-
const oldPresetIndex = metaKeys.findIndex((key) => key.source === FUNCTIONS_PRESET_META_KEY);
|
|
54
|
-
if (oldPresetIndex >= 0) {
|
|
55
|
-
metaKeys.splice(oldPresetIndex, 1);
|
|
56
|
-
}
|
|
57
|
-
if (template.presetId) {
|
|
58
|
-
metaKeys.push({ source: FUNCTIONS_PRESET_META_KEY, id: template.presetId });
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
[script],
|
|
63
|
-
);
|
|
64
|
-
};
|
package/src/templates/chess.ts
CHANGED
|
@@ -2,26 +2,25 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { Schema } from 'effect';
|
|
6
5
|
// @ts-ignore
|
|
7
|
-
import { defineFunction } from 'dxos:functions';
|
|
6
|
+
import { defineFunction, S } from 'dxos:functions';
|
|
8
7
|
// @ts-ignore
|
|
9
8
|
import { Chess } from 'https://esm.sh/chess.js@0.13.1';
|
|
10
9
|
|
|
11
10
|
export default defineFunction({
|
|
12
11
|
description: 'Plays a random move in a chess game.',
|
|
13
12
|
|
|
14
|
-
inputSchema:
|
|
15
|
-
changedObjectId:
|
|
13
|
+
inputSchema: S.Struct({
|
|
14
|
+
changedObjectId: S.String.annotations({
|
|
16
15
|
description: 'The objects to play the game on.',
|
|
17
16
|
}),
|
|
18
|
-
player:
|
|
17
|
+
player: S.optional(S.Literal('w', 'b')).annotations({
|
|
19
18
|
description: 'The player to play the game as.',
|
|
20
19
|
}),
|
|
21
20
|
}),
|
|
22
21
|
|
|
23
|
-
outputSchema:
|
|
24
|
-
state:
|
|
22
|
+
outputSchema: S.Struct({
|
|
23
|
+
state: S.String.annotations({
|
|
25
24
|
description: 'The state of the game as an ASCII art board.',
|
|
26
25
|
}),
|
|
27
26
|
}),
|
|
@@ -2,20 +2,19 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { Schema } from 'effect';
|
|
6
5
|
// @ts-ignore
|
|
7
6
|
import { defineFunction, S, create, Expando } from 'dxos:functions';
|
|
8
7
|
// @ts-ignore
|
|
9
8
|
import { randText } from 'https://esm.sh/@ngneat/falso@7.1.1';
|
|
10
9
|
|
|
11
10
|
export default defineFunction({
|
|
12
|
-
inputSchema:
|
|
13
|
-
documentAmount:
|
|
14
|
-
textSize:
|
|
15
|
-
mutationAmount:
|
|
11
|
+
inputSchema: S.Struct({
|
|
12
|
+
documentAmount: S.optional(S.Number),
|
|
13
|
+
textSize: S.optional(S.Number),
|
|
14
|
+
mutationAmount: S.optional(S.Number),
|
|
16
15
|
}),
|
|
17
16
|
|
|
18
|
-
outputSchema:
|
|
17
|
+
outputSchema: S.Struct({}),
|
|
19
18
|
|
|
20
19
|
handler: async ({
|
|
21
20
|
event: {
|
package/src/templates/discord.ts
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { Schema } from 'effect';
|
|
6
5
|
// @ts-ignore
|
|
7
6
|
import { create, defineFunction, DXN, Filter, ObjectId, S } from 'dxos:functions';
|
|
8
7
|
import {
|
|
@@ -16,12 +15,12 @@ import { Effect, Config, Redacted, Ref } from 'https://esm.sh/effect@3.13.3';
|
|
|
16
15
|
|
|
17
16
|
import { Type } from '@dxos/echo';
|
|
18
17
|
|
|
19
|
-
const MessageSchema =
|
|
18
|
+
const MessageSchema = S.Struct({
|
|
20
19
|
id: ObjectId,
|
|
21
|
-
foreignId:
|
|
22
|
-
from:
|
|
23
|
-
created:
|
|
24
|
-
content:
|
|
20
|
+
foreignId: S.Any, // bigint?
|
|
21
|
+
from: S.String,
|
|
22
|
+
created: S.String,
|
|
23
|
+
content: S.String,
|
|
25
24
|
}).pipe(
|
|
26
25
|
Type.def({
|
|
27
26
|
typename: 'example.com/type/Message',
|
|
@@ -37,17 +36,17 @@ const generateSnowflake = (unixTimestamp: number): bigint => {
|
|
|
37
36
|
};
|
|
38
37
|
|
|
39
38
|
export default defineFunction({
|
|
40
|
-
inputSchema:
|
|
39
|
+
inputSchema: S.Struct({
|
|
41
40
|
// TODO(wittjosiah): Remove. This is used to provide a terminal for a cron trigger.
|
|
42
|
-
tick:
|
|
43
|
-
channelId:
|
|
44
|
-
after:
|
|
45
|
-
pageSize:
|
|
46
|
-
queueId:
|
|
41
|
+
tick: S.optional(S.String),
|
|
42
|
+
channelId: S.String,
|
|
43
|
+
after: S.optional(S.Number),
|
|
44
|
+
pageSize: S.optional(S.Number),
|
|
45
|
+
queueId: S.String,
|
|
47
46
|
}),
|
|
48
47
|
|
|
49
|
-
outputSchema:
|
|
50
|
-
newMessages:
|
|
48
|
+
outputSchema: S.Struct({
|
|
49
|
+
newMessages: S.Number,
|
|
51
50
|
}),
|
|
52
51
|
|
|
53
52
|
handler: ({
|
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { Schema } from 'effect';
|
|
6
5
|
// @ts-ignore
|
|
7
|
-
import { defineFunction } from 'dxos:functions';
|
|
6
|
+
import { S, defineFunction } from 'dxos:functions';
|
|
8
7
|
import {
|
|
9
8
|
HttpClient,
|
|
10
9
|
HttpClientRequest,
|
|
@@ -17,12 +16,12 @@ import { Effect, Schedule } from 'https://esm.sh/effect@3.13.3';
|
|
|
17
16
|
export default defineFunction({
|
|
18
17
|
description: 'Returns the exchange rate between two currencies.',
|
|
19
18
|
|
|
20
|
-
inputSchema:
|
|
21
|
-
from:
|
|
22
|
-
to:
|
|
19
|
+
inputSchema: S.Struct({
|
|
20
|
+
from: S.String.annotations({ description: 'The source currency' }),
|
|
21
|
+
to: S.String.annotations({ description: 'The target currency' }),
|
|
23
22
|
}),
|
|
24
23
|
|
|
25
|
-
outputSchema:
|
|
24
|
+
outputSchema: S.String.annotations({ description: 'The exchange rate between the two currencies' }),
|
|
26
25
|
|
|
27
26
|
handler: async ({
|
|
28
27
|
event: {
|
package/src/templates/forex.ts
CHANGED
|
@@ -2,16 +2,15 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { Schema } from 'effect';
|
|
6
5
|
// @ts-ignore
|
|
7
|
-
import { defineFunction } from 'dxos:functions';
|
|
6
|
+
import { defineFunction, S } from 'dxos:functions';
|
|
8
7
|
|
|
9
8
|
export default defineFunction({
|
|
10
9
|
description: 'Returns the exchange rate between two currencies.',
|
|
11
10
|
|
|
12
|
-
inputSchema:
|
|
13
|
-
from:
|
|
14
|
-
to:
|
|
11
|
+
inputSchema: S.Struct({
|
|
12
|
+
from: S.String.annotations({ description: 'The source currency' }),
|
|
13
|
+
to: S.String.annotations({ description: 'The target currency' }),
|
|
15
14
|
}),
|
|
16
15
|
|
|
17
16
|
handler: async ({
|
package/src/templates/gmail.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
// @ts-ignore
|
|
6
|
-
import { create, defineFunction, Filter, ObjectId } from 'dxos:functions';
|
|
6
|
+
import { create, defineFunction, Filter, ObjectId, S } from 'dxos:functions';
|
|
7
7
|
// @ts-ignore
|
|
8
8
|
import {
|
|
9
9
|
HttpClient,
|
|
@@ -14,24 +14,24 @@ import {
|
|
|
14
14
|
// @ts-ignore
|
|
15
15
|
import { format, subDays } from 'https://esm.sh/date-fns@3.3.1';
|
|
16
16
|
// @ts-ignore
|
|
17
|
-
import { pipe, Chunk, Effect, Ref, Schedule,
|
|
17
|
+
import { pipe, Chunk, Effect, Ref, Schedule, Stream } from 'https://esm.sh/effect@3.13.3';
|
|
18
18
|
|
|
19
19
|
import { Type } from '@dxos/echo';
|
|
20
20
|
|
|
21
21
|
export default defineFunction({
|
|
22
|
-
inputSchema:
|
|
23
|
-
mailboxId:
|
|
24
|
-
userId:
|
|
25
|
-
after:
|
|
26
|
-
|
|
22
|
+
inputSchema: S.Struct({
|
|
23
|
+
mailboxId: S.String,
|
|
24
|
+
userId: S.optional(S.String).pipe(S.withDecodingDefault(() => 'me')),
|
|
25
|
+
after: S.optional(S.Union(S.Number, S.String)).pipe(
|
|
26
|
+
S.withDecodingDefault(() => format(subDays(new Date(), 30), 'yyyy-MM-dd')),
|
|
27
27
|
),
|
|
28
|
-
pageSize:
|
|
28
|
+
pageSize: S.optional(S.Number).pipe(S.withDecodingDefault(() => 100)),
|
|
29
29
|
// TODO(wittjosiah): Remove. This is used to provide a terminal for a cron trigger.
|
|
30
|
-
tick:
|
|
30
|
+
tick: S.optional(S.String),
|
|
31
31
|
}),
|
|
32
32
|
|
|
33
|
-
outputSchema:
|
|
34
|
-
newMessages:
|
|
33
|
+
outputSchema: S.Struct({
|
|
34
|
+
newMessages: S.Number,
|
|
35
35
|
}),
|
|
36
36
|
|
|
37
37
|
handler: ({
|
|
@@ -165,86 +165,86 @@ const parseEmailString = (emailString: string): { name?: string; email: string }
|
|
|
165
165
|
|
|
166
166
|
//
|
|
167
167
|
// Schemas
|
|
168
|
-
// TODO(wittjosiah): These schemas should be imported from @dxos/
|
|
168
|
+
// TODO(wittjosiah): These schemas should be imported from @dxos/S.
|
|
169
169
|
//
|
|
170
170
|
|
|
171
171
|
const ActorRoles = ['user', 'assistant'] as const;
|
|
172
|
-
const ActorRole =
|
|
173
|
-
type ActorRole =
|
|
172
|
+
const ActorRole = S.Literal(...ActorRoles);
|
|
173
|
+
type ActorRole = S.S.Type<typeof ActorRole>;
|
|
174
174
|
|
|
175
|
-
const ActorSchema =
|
|
176
|
-
identityKey:
|
|
177
|
-
email:
|
|
178
|
-
name:
|
|
179
|
-
role:
|
|
175
|
+
const ActorSchema = S.Struct({
|
|
176
|
+
identityKey: S.optional(S.String),
|
|
177
|
+
email: S.optional(S.String),
|
|
178
|
+
name: S.optional(S.String),
|
|
179
|
+
role: S.optional(ActorRole),
|
|
180
180
|
});
|
|
181
181
|
|
|
182
|
-
const AbstractContentBlock =
|
|
183
|
-
pending:
|
|
182
|
+
const AbstractContentBlock = S.Struct({
|
|
183
|
+
pending: S.optional(S.Boolean),
|
|
184
184
|
});
|
|
185
|
-
type AbstractContentBlock =
|
|
186
|
-
const TextContentBlock =
|
|
185
|
+
type AbstractContentBlock = S.S.Type<typeof AbstractContentBlock>;
|
|
186
|
+
const TextContentBlock = S.extend(
|
|
187
187
|
AbstractContentBlock,
|
|
188
|
-
|
|
189
|
-
type:
|
|
190
|
-
disposition:
|
|
191
|
-
text:
|
|
188
|
+
S.Struct({
|
|
189
|
+
type: S.Literal('text'),
|
|
190
|
+
disposition: S.optional(S.String),
|
|
191
|
+
text: S.String,
|
|
192
192
|
}),
|
|
193
|
-
).pipe(
|
|
194
|
-
type TextContentBlock =
|
|
195
|
-
const JsonContentBlock =
|
|
193
|
+
).pipe(S.mutable);
|
|
194
|
+
type TextContentBlock = S.S.Type<typeof TextContentBlock>;
|
|
195
|
+
const JsonContentBlock = S.extend(
|
|
196
196
|
AbstractContentBlock,
|
|
197
|
-
|
|
198
|
-
type:
|
|
199
|
-
disposition:
|
|
200
|
-
data:
|
|
197
|
+
S.Struct({
|
|
198
|
+
type: S.Literal('json'),
|
|
199
|
+
disposition: S.optional(S.String),
|
|
200
|
+
data: S.String,
|
|
201
201
|
}),
|
|
202
|
-
).pipe(
|
|
203
|
-
type JsonContentBlock =
|
|
204
|
-
const Base64ImageSource =
|
|
205
|
-
type:
|
|
206
|
-
mediaType:
|
|
207
|
-
data:
|
|
208
|
-
}).pipe(
|
|
209
|
-
const HttpImageSource =
|
|
210
|
-
type:
|
|
211
|
-
url:
|
|
212
|
-
}).pipe(
|
|
213
|
-
const ImageSource =
|
|
214
|
-
type ImageSource =
|
|
215
|
-
const ImageContentBlock =
|
|
202
|
+
).pipe(S.mutable);
|
|
203
|
+
type JsonContentBlock = S.S.Type<typeof JsonContentBlock>;
|
|
204
|
+
const Base64ImageSource = S.Struct({
|
|
205
|
+
type: S.Literal('base64'),
|
|
206
|
+
mediaType: S.String,
|
|
207
|
+
data: S.String,
|
|
208
|
+
}).pipe(S.mutable);
|
|
209
|
+
const HttpImageSource = S.Struct({
|
|
210
|
+
type: S.Literal('http'),
|
|
211
|
+
url: S.String,
|
|
212
|
+
}).pipe(S.mutable);
|
|
213
|
+
const ImageSource = S.Union(Base64ImageSource, HttpImageSource);
|
|
214
|
+
type ImageSource = S.S.Type<typeof ImageSource>;
|
|
215
|
+
const ImageContentBlock = S.extend(
|
|
216
216
|
AbstractContentBlock,
|
|
217
|
-
|
|
218
|
-
type:
|
|
219
|
-
id:
|
|
220
|
-
source:
|
|
217
|
+
S.Struct({
|
|
218
|
+
type: S.Literal('image'),
|
|
219
|
+
id: S.optional(S.String),
|
|
220
|
+
source: S.optional(ImageSource),
|
|
221
221
|
}),
|
|
222
|
-
).pipe(
|
|
223
|
-
type ImageContentBlock =
|
|
224
|
-
const ReferenceContentBlock =
|
|
222
|
+
).pipe(S.mutable);
|
|
223
|
+
type ImageContentBlock = S.S.Type<typeof ImageContentBlock>;
|
|
224
|
+
const ReferenceContentBlock = S.extend(
|
|
225
225
|
AbstractContentBlock,
|
|
226
|
-
|
|
227
|
-
type:
|
|
228
|
-
reference:
|
|
226
|
+
S.Struct({
|
|
227
|
+
type: S.Literal('reference'),
|
|
228
|
+
reference: S.Any,
|
|
229
229
|
}),
|
|
230
|
-
).pipe(
|
|
231
|
-
type ReferenceContentBlock =
|
|
232
|
-
const MessageContentBlock =
|
|
230
|
+
).pipe(S.mutable);
|
|
231
|
+
type ReferenceContentBlock = S.S.Type<typeof ReferenceContentBlock>;
|
|
232
|
+
const MessageContentBlock = S.Union(TextContentBlock, JsonContentBlock, ImageContentBlock, ReferenceContentBlock);
|
|
233
233
|
|
|
234
|
-
const MessageType =
|
|
234
|
+
const MessageType = S.Struct({
|
|
235
235
|
id: ObjectId,
|
|
236
|
-
created:
|
|
236
|
+
created: S.String.annotations({
|
|
237
237
|
description: 'ISO date string when the message was sent.',
|
|
238
238
|
}),
|
|
239
239
|
sender: ActorSchema.annotations({
|
|
240
240
|
description: 'Identity of the message sender.',
|
|
241
241
|
}),
|
|
242
|
-
blocks:
|
|
242
|
+
blocks: S.Array(MessageContentBlock).annotations({
|
|
243
243
|
description: 'Contents of the message.',
|
|
244
244
|
}),
|
|
245
|
-
properties:
|
|
246
|
-
|
|
247
|
-
|
|
245
|
+
properties: S.optional(
|
|
246
|
+
S.mutable(
|
|
247
|
+
S.Record({ key: S.String, value: S.Any }).annotations({
|
|
248
248
|
description: 'Custom properties for specific message types (e.g. attention context, email subject, etc.).',
|
|
249
249
|
}),
|
|
250
250
|
),
|
|
@@ -255,4 +255,4 @@ const MessageType = Schema.Struct({
|
|
|
255
255
|
version: '0.1.0',
|
|
256
256
|
}),
|
|
257
257
|
);
|
|
258
|
-
type MessageType =
|
|
258
|
+
type MessageType = S.S.Type<typeof MessageType>;
|
package/src/util/deploy.ts
CHANGED
|
@@ -57,7 +57,6 @@ export const deployScript = async ({
|
|
|
57
57
|
|
|
58
58
|
const { functionId, version, meta } = await uploadWorkerFunction({
|
|
59
59
|
client,
|
|
60
|
-
spaceId: space.id,
|
|
61
60
|
version: fn ? incrementSemverPatch(fn.version) : '0.0.1',
|
|
62
61
|
functionId: existingFunctionId,
|
|
63
62
|
source: bundle,
|
|
@@ -71,7 +70,7 @@ export const deployScript = async ({
|
|
|
71
70
|
script.changed = false;
|
|
72
71
|
updateFunctionMetadata(script, storedFunction, meta, functionId);
|
|
73
72
|
|
|
74
|
-
const functionUrl = makeFunctionUrl(
|
|
73
|
+
const functionUrl = makeFunctionUrl({ functionId });
|
|
75
74
|
setUserFunctionUrlInMetadata(getMeta(storedFunction), functionUrl);
|
|
76
75
|
|
|
77
76
|
return { success: true, functionUrl };
|