@dxos/plugin-script 0.8.2-staging.7ac8446 → 0.8.3-main.672df60
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-NLWQHNKE.mjs +12 -0
- package/dist/lib/browser/ScriptContainer-NDMTQG2N.mjs +271 -0
- package/dist/lib/browser/ScriptContainer-NDMTQG2N.mjs.map +7 -0
- package/dist/lib/browser/{app-graph-builder-RRLY67QC.mjs → app-graph-builder-V3HPXJAD.mjs} +10 -10
- package/dist/lib/browser/app-graph-builder-V3HPXJAD.mjs.map +7 -0
- package/dist/lib/browser/{artifact-definition-WXFYD2V5.mjs → artifact-definition-L3AIY4XA.mjs} +45 -48
- package/dist/lib/browser/artifact-definition-L3AIY4XA.mjs.map +7 -0
- package/dist/lib/browser/{chunk-MQZQB5VD.mjs → chunk-6T64VQHF.mjs} +10 -10
- package/dist/lib/browser/chunk-6T64VQHF.mjs.map +7 -0
- package/dist/lib/browser/{chunk-WSK3YQXI.mjs → chunk-6ZHHWU6S.mjs} +4 -3
- package/dist/lib/browser/{chunk-WSK3YQXI.mjs.map → chunk-6ZHHWU6S.mjs.map} +2 -2
- package/dist/lib/browser/chunk-BMVT3XMV.mjs +557 -0
- package/dist/lib/browser/chunk-BMVT3XMV.mjs.map +7 -0
- package/dist/lib/browser/chunk-BTEFFA4C.mjs +153 -0
- package/dist/lib/browser/chunk-BTEFFA4C.mjs.map +7 -0
- package/dist/lib/browser/chunk-SH4MI7PU.mjs +364 -0
- package/dist/lib/browser/chunk-SH4MI7PU.mjs.map +7 -0
- package/dist/lib/browser/chunk-WB3X5Z7Q.mjs +40 -0
- package/dist/lib/browser/chunk-WB3X5Z7Q.mjs.map +7 -0
- package/dist/lib/browser/{chunk-4VD3K3PY.mjs → chunk-YSQMXTYO.mjs} +3 -3
- package/dist/lib/{node-esm/chunk-EB5DSAD4.mjs.map → browser/chunk-YSQMXTYO.mjs.map} +1 -1
- package/dist/lib/browser/{compiler-56LTBEQB.mjs → compiler-W4BYJYTL.mjs} +3 -3
- package/dist/lib/browser/compiler-W4BYJYTL.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +20 -16
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/{intent-resolver-WCVXKRBR.mjs → intent-resolver-BIJLOJU3.mjs} +14 -14
- package/dist/lib/browser/intent-resolver-BIJLOJU3.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/{react-surface-WXZVPNGI.mjs → react-surface-ZBCIYBGH.mjs} +16 -28
- package/dist/lib/browser/react-surface-ZBCIYBGH.mjs.map +7 -0
- package/dist/lib/browser/{settings-Z7B37V2I.mjs → settings-FU7NTENS.mjs} +5 -5
- package/dist/lib/browser/settings-FU7NTENS.mjs.map +7 -0
- package/dist/lib/browser/types.mjs +2 -2
- package/dist/lib/node/{DeploymentDialog-O4MU4OMF.cjs → DeploymentDialog-PC5AL3BB.cjs} +10 -10
- package/dist/lib/node/DeploymentDialog-PC5AL3BB.cjs.map +7 -0
- package/dist/lib/node/ScriptContainer-CLW7YCIP.cjs +288 -0
- package/dist/lib/node/ScriptContainer-CLW7YCIP.cjs.map +7 -0
- package/dist/lib/node/{app-graph-builder-6I2BWD46.cjs → app-graph-builder-YE4OM4OC.cjs} +17 -17
- package/dist/lib/node/app-graph-builder-YE4OM4OC.cjs.map +7 -0
- package/dist/lib/node/{artifact-definition-6NVXEHJD.cjs → artifact-definition-6BD6CVOV.cjs} +55 -58
- package/dist/lib/node/artifact-definition-6BD6CVOV.cjs.map +7 -0
- package/dist/lib/node/{chunk-XFZPWFEG.cjs → chunk-HCRW6T3G.cjs} +19 -20
- package/dist/lib/node/chunk-HCRW6T3G.cjs.map +7 -0
- package/dist/lib/node/chunk-Q44SJXEN.cjs +369 -0
- package/dist/lib/node/chunk-Q44SJXEN.cjs.map +7 -0
- package/dist/lib/node/chunk-QCAKVK6S.cjs +580 -0
- package/dist/lib/node/chunk-QCAKVK6S.cjs.map +7 -0
- package/dist/lib/node/{chunk-YJQZHKKA.cjs → chunk-QG2X6J74.cjs} +7 -6
- package/dist/lib/node/{chunk-YJQZHKKA.cjs.map → chunk-QG2X6J74.cjs.map} +2 -2
- package/dist/lib/node/chunk-RARNZD62.cjs +179 -0
- package/dist/lib/node/chunk-RARNZD62.cjs.map +7 -0
- package/dist/lib/node/{chunk-VYBEBLDO.cjs → chunk-V6L73D7S.cjs} +14 -14
- package/dist/lib/node/chunk-V6L73D7S.cjs.map +7 -0
- package/dist/lib/node/{chunk-JICWAOWZ.cjs → chunk-ZEV3VARQ.cjs} +7 -7
- package/dist/lib/node/{chunk-JICWAOWZ.cjs.map → chunk-ZEV3VARQ.cjs.map} +1 -1
- package/dist/lib/node/{compiler-W2RU3M7U.cjs → compiler-TFSJRLL4.cjs} +7 -7
- package/dist/lib/node/{compiler-W2RU3M7U.cjs.map → compiler-TFSJRLL4.cjs.map} +3 -3
- package/dist/lib/node/index.cjs +49 -45
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/{intent-resolver-J4NBDNFH.cjs → intent-resolver-QKBCESXR.cjs} +21 -21
- package/dist/lib/node/intent-resolver-QKBCESXR.cjs.map +7 -0
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/{react-surface-27KTUBIZ.cjs → react-surface-HZJOZHHG.cjs} +38 -47
- package/dist/lib/node/react-surface-HZJOZHHG.cjs.map +7 -0
- package/dist/lib/node/{settings-EI6VPNKN.cjs → settings-RRCQ7ZQD.cjs} +9 -9
- package/dist/lib/node/settings-RRCQ7ZQD.cjs.map +7 -0
- package/dist/lib/node/types.cjs +5 -5
- package/dist/lib/node/types.cjs.map +1 -1
- package/dist/lib/node-esm/{DeploymentDialog-SSQSWLHX.mjs → DeploymentDialog-QHB2BGNJ.mjs} +5 -5
- package/dist/lib/node-esm/ScriptContainer-PMRP7AJ5.mjs +272 -0
- package/dist/lib/node-esm/ScriptContainer-PMRP7AJ5.mjs.map +7 -0
- package/dist/lib/node-esm/{app-graph-builder-H5XLRVX3.mjs → app-graph-builder-4CN7URJQ.mjs} +10 -10
- package/dist/lib/node-esm/app-graph-builder-4CN7URJQ.mjs.map +7 -0
- package/dist/lib/node-esm/{artifact-definition-KQ64AYBP.mjs → artifact-definition-PPV2XKU7.mjs} +45 -48
- package/dist/lib/node-esm/artifact-definition-PPV2XKU7.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-25GOLUXY.mjs +154 -0
- package/dist/lib/node-esm/chunk-25GOLUXY.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-EB5DSAD4.mjs → chunk-2KJYPUQD.mjs} +3 -3
- package/dist/lib/{browser/chunk-4VD3K3PY.mjs.map → node-esm/chunk-2KJYPUQD.mjs.map} +1 -1
- package/dist/lib/node-esm/{chunk-F4HA5C34.mjs → chunk-47MABIVX.mjs} +10 -10
- package/dist/lib/node-esm/chunk-47MABIVX.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-FDEAVT67.mjs → chunk-AEB5TPEW.mjs} +4 -3
- package/dist/lib/node-esm/{chunk-FDEAVT67.mjs.map → chunk-AEB5TPEW.mjs.map} +2 -2
- package/dist/lib/node-esm/chunk-IIPL3OKN.mjs +558 -0
- package/dist/lib/node-esm/chunk-IIPL3OKN.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-JFCZ3L27.mjs +365 -0
- package/dist/lib/node-esm/chunk-JFCZ3L27.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-UESZKXLR.mjs +41 -0
- package/dist/lib/node-esm/chunk-UESZKXLR.mjs.map +7 -0
- package/dist/lib/node-esm/{compiler-VT5C2Z3T.mjs → compiler-7PQ4D43R.mjs} +3 -3
- package/dist/lib/{browser/compiler-56LTBEQB.mjs.map → node-esm/compiler-7PQ4D43R.mjs.map} +3 -3
- package/dist/lib/node-esm/index.mjs +20 -16
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/{intent-resolver-PDZ2A26X.mjs → intent-resolver-UWYXAPLZ.mjs} +14 -14
- package/dist/lib/node-esm/intent-resolver-UWYXAPLZ.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/{react-surface-UCUVDVSH.mjs → react-surface-MHCPAP55.mjs} +16 -28
- package/dist/lib/node-esm/react-surface-MHCPAP55.mjs.map +7 -0
- package/dist/lib/node-esm/{settings-HU5UEFRF.mjs → settings-NKNC32QC.mjs} +5 -5
- package/dist/lib/node-esm/settings-NKNC32QC.mjs.map +7 -0
- package/dist/lib/node-esm/types.mjs +2 -2
- package/dist/types/src/ScriptPlugin.d.ts.map +1 -1
- package/dist/types/src/capabilities/app-graph-builder.d.ts +2 -179
- package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -1
- package/dist/types/src/capabilities/artifact-definition.d.ts.map +1 -1
- package/dist/types/src/capabilities/index.d.ts +1 -177
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
- package/dist/types/src/compiler/compiler.d.ts.map +1 -1
- package/dist/types/src/components/DeploymentDialog/DeploymentDialog.d.ts +2 -2
- 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 +1 -1
- package/dist/types/src/components/ScriptContainer.d.ts.map +1 -1
- package/dist/types/src/components/ScriptToolbar/ScriptToolbar.d.ts +1 -1
- package/dist/types/src/components/ScriptToolbar/ScriptToolbar.d.ts.map +1 -1
- package/dist/types/src/components/Settings/ScriptObjectSettings.d.ts +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/TestContainer.d.ts +7 -0
- package/dist/types/src/components/TestPanel/TestContainer.d.ts.map +1 -0
- package/dist/types/src/components/TestPanel/TestPanel.d.ts.map +1 -1
- package/dist/types/src/components/TestPanel/index.d.ts +1 -0
- package/dist/types/src/components/TestPanel/index.d.ts.map +1 -1
- package/dist/types/src/components/TypescriptEditor/TypescriptEditor.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +1 -1
- package/dist/types/src/hooks/deploy.d.ts +22 -19
- package/dist/types/src/hooks/deploy.d.ts.map +1 -1
- package/dist/types/src/hooks/format.d.ts +2 -5
- 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 +2 -5
- 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 +1 -1
- package/dist/types/src/hooks/useToolbarState.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/templates/chat.d.ts +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 +0 -7
- 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 +1 -1
- package/dist/types/src/templates/echo.d.ts.map +1 -1
- package/dist/types/src/templates/email.d.ts +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/templates/gmail.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 +27 -26
- 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 +59 -53
- package/src/ScriptPlugin.tsx +4 -2
- package/src/capabilities/app-graph-builder.ts +46 -29
- package/src/capabilities/artifact-definition.ts +40 -38
- package/src/capabilities/intent-resolver.ts +7 -7
- package/src/capabilities/react-surface.tsx +7 -17
- package/src/capabilities/settings.ts +2 -2
- package/src/compiler/compiler.ts +3 -3
- package/src/components/DeploymentDialog/DeploymentDialog.stories.tsx +1 -1
- package/src/components/DeploymentDialog/DeploymentDialog.tsx +2 -2
- package/src/components/ScriptContainer.tsx +2 -2
- package/src/components/ScriptToolbar/ScriptToolbar.stories.tsx +1 -1
- package/src/components/ScriptToolbar/ScriptToolbar.tsx +27 -18
- package/src/components/Settings/ScriptObjectSettings.tsx +5 -5
- package/src/components/TestPanel/TestContainer.tsx +21 -0
- package/src/components/TestPanel/index.ts +1 -0
- package/src/components/TypescriptEditor/TypescriptEditor.tsx +0 -6
- package/src/hooks/deploy.ts +61 -55
- package/src/hooks/format.ts +26 -26
- package/src/hooks/index.ts +0 -1
- package/src/hooks/template.ts +24 -32
- package/src/hooks/useToolbarState.ts +2 -2
- package/src/meta.ts +3 -2
- package/src/templates/chat.ts +4 -10
- package/src/templates/chess.ts +2 -7
- package/src/templates/data-generator.ts +20 -45
- package/src/templates/discord.ts +17 -15
- package/src/templates/echo.ts +1 -12
- package/src/templates/email.ts +8 -14
- package/src/templates/forex-effect.ts +4 -8
- package/src/templates/forex.ts +1 -5
- package/src/templates/gmail.ts +37 -28
- package/src/translations.ts +1 -1
- package/src/types.ts +13 -14
- package/src/util/deploy.ts +6 -10
- package/dist/lib/browser/DeploymentDialog-AEPYJKPO.mjs +0 -12
- package/dist/lib/browser/ScriptContainer-R25PRK2D.mjs +0 -248
- package/dist/lib/browser/ScriptContainer-R25PRK2D.mjs.map +0 -7
- package/dist/lib/browser/app-graph-builder-RRLY67QC.mjs.map +0 -7
- package/dist/lib/browser/artifact-definition-WXFYD2V5.mjs.map +0 -7
- package/dist/lib/browser/chunk-2CGZFDCR.mjs +0 -480
- package/dist/lib/browser/chunk-2CGZFDCR.mjs.map +0 -7
- package/dist/lib/browser/chunk-CSZXPLYY.mjs +0 -147
- package/dist/lib/browser/chunk-CSZXPLYY.mjs.map +0 -7
- package/dist/lib/browser/chunk-KLEOGVXY.mjs +0 -352
- package/dist/lib/browser/chunk-KLEOGVXY.mjs.map +0 -7
- package/dist/lib/browser/chunk-MQZQB5VD.mjs.map +0 -7
- package/dist/lib/browser/chunk-R2CHVWJ2.mjs +0 -41
- package/dist/lib/browser/chunk-R2CHVWJ2.mjs.map +0 -7
- package/dist/lib/browser/chunk-SUCBNCEQ.mjs +0 -87
- package/dist/lib/browser/chunk-SUCBNCEQ.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-WCVXKRBR.mjs.map +0 -7
- package/dist/lib/browser/react-surface-WXZVPNGI.mjs.map +0 -7
- package/dist/lib/browser/settings-Z7B37V2I.mjs.map +0 -7
- package/dist/lib/node/DeploymentDialog-O4MU4OMF.cjs.map +0 -7
- package/dist/lib/node/ScriptContainer-5KY6ZOQD.cjs +0 -267
- package/dist/lib/node/ScriptContainer-5KY6ZOQD.cjs.map +0 -7
- package/dist/lib/node/app-graph-builder-6I2BWD46.cjs.map +0 -7
- package/dist/lib/node/artifact-definition-6NVXEHJD.cjs.map +0 -7
- package/dist/lib/node/chunk-65MIJR3Q.cjs +0 -173
- package/dist/lib/node/chunk-65MIJR3Q.cjs.map +0 -7
- package/dist/lib/node/chunk-F4DP7WON.cjs +0 -372
- package/dist/lib/node/chunk-F4DP7WON.cjs.map +0 -7
- package/dist/lib/node/chunk-SLDJM45C.cjs +0 -507
- package/dist/lib/node/chunk-SLDJM45C.cjs.map +0 -7
- package/dist/lib/node/chunk-VYBEBLDO.cjs.map +0 -7
- package/dist/lib/node/chunk-X7MHLHHS.cjs +0 -91
- package/dist/lib/node/chunk-X7MHLHHS.cjs.map +0 -7
- package/dist/lib/node/chunk-XFZPWFEG.cjs.map +0 -7
- package/dist/lib/node/intent-resolver-J4NBDNFH.cjs.map +0 -7
- package/dist/lib/node/react-surface-27KTUBIZ.cjs.map +0 -7
- package/dist/lib/node/settings-EI6VPNKN.cjs.map +0 -7
- package/dist/lib/node-esm/ScriptContainer-W2F4FGDV.mjs +0 -249
- package/dist/lib/node-esm/ScriptContainer-W2F4FGDV.mjs.map +0 -7
- package/dist/lib/node-esm/app-graph-builder-H5XLRVX3.mjs.map +0 -7
- package/dist/lib/node-esm/artifact-definition-KQ64AYBP.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-4MTPYMV2.mjs +0 -481
- package/dist/lib/node-esm/chunk-4MTPYMV2.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-F4HA5C34.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-MU3JKVL2.mjs +0 -148
- package/dist/lib/node-esm/chunk-MU3JKVL2.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-PBGVTGL2.mjs +0 -353
- package/dist/lib/node-esm/chunk-PBGVTGL2.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-QDYGTY4L.mjs +0 -89
- package/dist/lib/node-esm/chunk-QDYGTY4L.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-RW2APVMV.mjs +0 -42
- package/dist/lib/node-esm/chunk-RW2APVMV.mjs.map +0 -7
- package/dist/lib/node-esm/compiler-VT5C2Z3T.mjs.map +0 -7
- package/dist/lib/node-esm/intent-resolver-PDZ2A26X.mjs.map +0 -7
- package/dist/lib/node-esm/react-surface-UCUVDVSH.mjs.map +0 -7
- package/dist/lib/node-esm/settings-HU5UEFRF.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-AEPYJKPO.mjs.map → DeploymentDialog-NLWQHNKE.mjs.map} +0 -0
- /package/dist/lib/node-esm/{DeploymentDialog-SSQSWLHX.mjs.map → DeploymentDialog-QHB2BGNJ.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 {
|
|
11
|
-
import {
|
|
9
|
+
import { type Client, useClient } from '@dxos/react-client';
|
|
10
|
+
import { getMeta, getSpace, Query, Ref, 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],
|
|
@@ -78,42 +118,8 @@ export const useDeployState = ({ state, script }: { state: Partial<DeployState>;
|
|
|
78
118
|
|
|
79
119
|
export const useDeployDeps = ({ script }: { script: ScriptType }) => {
|
|
80
120
|
const space = getSpace(script);
|
|
81
|
-
const [fn] = useQuery(space,
|
|
121
|
+
const [fn] = useQuery(space, Query.type(FunctionType, { source: Ref.make(script) }));
|
|
82
122
|
const client = useClient();
|
|
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,9 +5,8 @@
|
|
|
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
|
-
import { type ScriptType } from '@dxos/functions
|
|
9
|
+
import { type ScriptType } from '@dxos/functions';
|
|
11
10
|
import { log } from '@dxos/log';
|
|
12
11
|
import { createMenuAction } from '@dxos/react-ui-menu';
|
|
13
12
|
|
|
@@ -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,9 +2,7 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
import { FUNCTIONS_PRESET_META_KEY, type ScriptType } from '@dxos/functions/types';
|
|
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';
|
|
10
8
|
|
|
@@ -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
|
-
};
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { useMemo } from 'react';
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { live } from '@dxos/live-object';
|
|
8
8
|
|
|
9
9
|
import { type DeployState } from './deploy';
|
|
10
10
|
|
|
@@ -12,5 +12,5 @@ export type ScriptToolbarState = Partial<DeployState>;
|
|
|
12
12
|
|
|
13
13
|
// TODO(burdon): Replace with context provider?
|
|
14
14
|
export const useToolbarState = (initialState: ScriptToolbarState = {}) => {
|
|
15
|
-
return useMemo(() =>
|
|
15
|
+
return useMemo(() => live<ScriptToolbarState>(initialState), []);
|
|
16
16
|
};
|
package/src/meta.ts
CHANGED
|
@@ -12,12 +12,13 @@ export const meta: PluginMeta = {
|
|
|
12
12
|
description:
|
|
13
13
|
'Scripts in Composer allow you to deploy custom functions that run on the edge. These functions can be referenced by your AI agent and called inside of cells in any Sheet. Use scripts to interact with API’s or external data inside of Composer.',
|
|
14
14
|
icon: 'ph--code--regular',
|
|
15
|
-
source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/
|
|
16
|
-
tags: ['
|
|
15
|
+
source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-explorer',
|
|
16
|
+
tags: ['labs'],
|
|
17
17
|
screenshots: ['https://dxos.network/plugin-details-scripts-dark.png'],
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
// TODO(ZaymonFC): Configure by scopes?
|
|
21
21
|
export const defaultScriptsForIntegration: Record<string, string[]> = {
|
|
22
|
+
// TODO(wittjosiah): Also include content extraction scripts in the default set.
|
|
22
23
|
'gmail.com': ['dxos.org/script/gmail'],
|
|
23
24
|
};
|
package/src/templates/chat.ts
CHANGED
|
@@ -3,21 +3,15 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
// @ts-ignore
|
|
6
|
-
import { transformServerSentEvents } from 'https://esm.sh/@dxos/script-toolbox';
|
|
6
|
+
import { transformServerSentEvents } from 'https://esm.sh/@dxos/script-toolbox?bundle=false';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Chatbot that answers questions based on the context data.
|
|
10
10
|
*/
|
|
11
|
-
export default async ({
|
|
12
|
-
event: {
|
|
13
|
-
data: { request },
|
|
14
|
-
},
|
|
15
|
-
context: { space, ai },
|
|
16
|
-
}: any) => {
|
|
17
|
-
const textBody = await request.text();
|
|
11
|
+
export default async ({ data: { bodyText }, context: { space, ai } }: any) => {
|
|
18
12
|
let parsedRequest: any;
|
|
19
13
|
try {
|
|
20
|
-
parsedRequest = JSON.parse(
|
|
14
|
+
parsedRequest = JSON.parse(bodyText);
|
|
21
15
|
} catch (err) {
|
|
22
16
|
const answer = await ai.run('@cf/meta/llama-3.1-8b-instruct', {
|
|
23
17
|
stream: true,
|
|
@@ -29,7 +23,7 @@ export default async ({
|
|
|
29
23
|
${await getContext({ space })}
|
|
30
24
|
|
|
31
25
|
QUESTION:
|
|
32
|
-
${
|
|
26
|
+
${bodyText}
|
|
33
27
|
`,
|
|
34
28
|
});
|
|
35
29
|
return new Response(transformServerSentEvents(answer));
|
package/src/templates/chess.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// @ts-ignore
|
|
6
6
|
import { defineFunction, S } from 'dxos:functions';
|
|
7
7
|
// @ts-ignore
|
|
8
|
-
import { Chess } from 'https://esm.sh/chess.js@0.13.1';
|
|
8
|
+
import { Chess } from 'https://esm.sh/chess.js@0.13.1?bundle=false';
|
|
9
9
|
|
|
10
10
|
export default defineFunction({
|
|
11
11
|
description: 'Plays a random move in a chess game.',
|
|
@@ -25,12 +25,7 @@ export default defineFunction({
|
|
|
25
25
|
}),
|
|
26
26
|
}),
|
|
27
27
|
|
|
28
|
-
handler: async ({
|
|
29
|
-
event: {
|
|
30
|
-
data: { changedObjectId, player = 'b' },
|
|
31
|
-
},
|
|
32
|
-
context: { space },
|
|
33
|
-
}: any) => {
|
|
28
|
+
handler: async ({ data: { changedObjectId, player = 'b' }, context: { space } }: any) => {
|
|
34
29
|
const { pgn } = await space.db.query({ id: changedObjectId }).first();
|
|
35
30
|
const game = new Chess();
|
|
36
31
|
game.load_pgn(pgn);
|
|
@@ -2,35 +2,10 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
EchoObject,
|
|
7
|
-
defineFunction,
|
|
8
|
-
S,
|
|
9
|
-
createStatic,
|
|
10
|
-
Expando,
|
|
11
|
-
TypedObject,
|
|
12
|
-
Ref,
|
|
13
|
-
LabelAnnotationId,
|
|
14
|
-
// @ts-ignore
|
|
15
|
-
} from 'dxos:functions';
|
|
16
5
|
// @ts-ignore
|
|
17
|
-
import {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
content: S.String,
|
|
21
|
-
}) {}
|
|
22
|
-
|
|
23
|
-
export const DocumentSchema = S.Struct({
|
|
24
|
-
name: S.optional(S.String),
|
|
25
|
-
fallbackName: S.optional(S.String),
|
|
26
|
-
content: Ref(TextType),
|
|
27
|
-
threads: S.mutable(S.Array(Ref(Expando))),
|
|
28
|
-
}).annotations({
|
|
29
|
-
[LabelAnnotationId]: ['name', 'fallbackName'],
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
export const DocumentType = DocumentSchema.pipe(EchoObject('dxos.org/type/Document', '0.1.0'));
|
|
33
|
-
export type DocumentType = S.Schema.Type<typeof DocumentType>;
|
|
6
|
+
import { defineFunction, S, create, Expando } from 'dxos:functions';
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
import { randText } from 'https://esm.sh/@ngneat/falso@7.1.1?bundle=false';
|
|
34
9
|
|
|
35
10
|
export default defineFunction({
|
|
36
11
|
inputSchema: S.Struct({
|
|
@@ -41,33 +16,33 @@ export default defineFunction({
|
|
|
41
16
|
|
|
42
17
|
outputSchema: S.Struct({}),
|
|
43
18
|
|
|
44
|
-
handler: async ({
|
|
19
|
+
handler: async ({ data: { documentAmount = 1, textSize = 10, mutationAmount = 0 }, context: { space } }: any) => {
|
|
45
20
|
await space.db.graph.schemaRegistry.addSchema([Expando]);
|
|
21
|
+
const result: Record<string, any> = {};
|
|
22
|
+
const objects: Expando[] = [];
|
|
46
23
|
|
|
47
|
-
|
|
48
|
-
// const rootCollection = await space.properties[COLLECTION_TYPENAME]?.load();
|
|
24
|
+
// Create objects.
|
|
49
25
|
for (let i = 0; i < documentAmount; i++) {
|
|
50
26
|
const obj = space.db.add(
|
|
51
|
-
|
|
27
|
+
create(Expando, {
|
|
52
28
|
name: 'scriptGenerated',
|
|
53
|
-
content:
|
|
29
|
+
content: randText({ charCount: textSize }),
|
|
54
30
|
}),
|
|
55
31
|
);
|
|
56
|
-
// rootCollection.objects.push(obj);
|
|
57
32
|
objects.push(obj);
|
|
33
|
+
const objectResult: any = {};
|
|
34
|
+
// Mutate the object.
|
|
35
|
+
for (let i = 0; i < mutationAmount; i++) {
|
|
36
|
+
obj.content = randText({ charCount: textSize });
|
|
37
|
+
}
|
|
38
|
+
objectResult.mutations = mutationAmount;
|
|
39
|
+
objectResult.contentLength = obj.content.length;
|
|
40
|
+
result[obj.id] = objectResult;
|
|
58
41
|
}
|
|
59
42
|
|
|
60
|
-
|
|
61
|
-
const obj = objects[Math.floor(Math.random() * objects.length)];
|
|
62
|
-
obj.content = randParagraph({ length: textSize });
|
|
63
|
-
}
|
|
64
|
-
|
|
43
|
+
// Flush and wait for data to propagate.
|
|
65
44
|
await space.db.flush();
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
await space.db.query({ id: obj.id }).first();
|
|
69
|
-
console.log('obj', obj.id);
|
|
70
|
-
}
|
|
71
|
-
return 'OK';
|
|
45
|
+
await new Promise((resolve) => setTimeout(resolve, 10_000));
|
|
46
|
+
return result;
|
|
72
47
|
},
|
|
73
48
|
});
|
package/src/templates/discord.ts
CHANGED
|
@@ -3,23 +3,30 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
// @ts-ignore
|
|
6
|
-
import {
|
|
6
|
+
import { create, defineFunction, DXN, EchoObject, Filter, ObjectId, S } from 'dxos:functions';
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
import { FetchHttpClient } from 'https://esm.sh/@effect/platform@0.77.2?deps=effect@3.14.21&bundle=false';
|
|
7
9
|
import {
|
|
8
|
-
|
|
10
|
+
DiscordConfig,
|
|
11
|
+
DiscordREST,
|
|
12
|
+
DiscordRESTMemoryLive,
|
|
9
13
|
// @ts-ignore
|
|
10
|
-
} from 'https://esm.sh
|
|
11
|
-
// @ts-ignore
|
|
12
|
-
import { DiscordConfig, DiscordREST, DiscordRESTMemoryLive } from 'https://esm.sh/dfx@0.113.0?deps=effect@3.13.3';
|
|
14
|
+
} from 'https://esm.sh/dfx@0.113.0?deps=effect@3.14.21&bundle=false';
|
|
13
15
|
// @ts-ignore
|
|
14
|
-
import { Effect, Config, Redacted, Ref } from 'https://esm.sh/effect@3.
|
|
16
|
+
import { Effect, Config, Redacted, Ref } from 'https://esm.sh/effect@3.14.21?bundle=false';
|
|
15
17
|
|
|
16
18
|
const MessageSchema = S.Struct({
|
|
17
|
-
id:
|
|
19
|
+
id: ObjectId,
|
|
18
20
|
foreignId: S.Any, // bigint?
|
|
19
21
|
from: S.String,
|
|
20
22
|
created: S.String,
|
|
21
23
|
content: S.String,
|
|
22
|
-
}).pipe(
|
|
24
|
+
}).pipe(
|
|
25
|
+
EchoObject({
|
|
26
|
+
typename: 'example.com/type/Message',
|
|
27
|
+
version: '0.1.0',
|
|
28
|
+
}),
|
|
29
|
+
);
|
|
23
30
|
|
|
24
31
|
const DEFAULT_AFTER = 1704067200; // 2024-01-01
|
|
25
32
|
|
|
@@ -42,12 +49,7 @@ export default defineFunction({
|
|
|
42
49
|
newMessages: S.Number,
|
|
43
50
|
}),
|
|
44
51
|
|
|
45
|
-
handler: ({
|
|
46
|
-
event: {
|
|
47
|
-
data: { channelId, queueId, after = DEFAULT_AFTER, pageSize = 5 },
|
|
48
|
-
},
|
|
49
|
-
context: { space },
|
|
50
|
-
}: any) =>
|
|
52
|
+
handler: ({ data: { channelId, queueId, after = DEFAULT_AFTER, pageSize = 5 }, context: { space } }: any) =>
|
|
51
53
|
Effect.gen(function* () {
|
|
52
54
|
const { token } = yield* Effect.tryPromise({
|
|
53
55
|
try: () => space.db.query(Filter.typename('dxos.org/type/AccessToken', { source: 'discord.com' })).first(),
|
|
@@ -73,7 +75,7 @@ export default defineFunction({
|
|
|
73
75
|
const messages = yield* rest.getChannelMessages(channelId, options).pipe((res: any) => res.json);
|
|
74
76
|
const queueMessages = messages
|
|
75
77
|
.map((message: any) =>
|
|
76
|
-
|
|
78
|
+
create(MessageSchema, {
|
|
77
79
|
id: ObjectId.random(),
|
|
78
80
|
foreignId: message.id,
|
|
79
81
|
from: message.author.username,
|
package/src/templates/echo.ts
CHANGED
|
@@ -5,15 +5,4 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* Echos the request data.
|
|
7
7
|
*/
|
|
8
|
-
export default async ({
|
|
9
|
-
event: {
|
|
10
|
-
data: { request },
|
|
11
|
-
},
|
|
12
|
-
}: any) => {
|
|
13
|
-
const data = await request.json();
|
|
14
|
-
return new Response(JSON.stringify(data ?? {}), {
|
|
15
|
-
headers: {
|
|
16
|
-
'Content-Type': 'application/json',
|
|
17
|
-
},
|
|
18
|
-
});
|
|
19
|
-
};
|
|
8
|
+
export default async ({ data }: any) => data;
|
package/src/templates/email.ts
CHANGED
|
@@ -6,15 +6,9 @@
|
|
|
6
6
|
* Appends a message to the end of a Document configured through a trigger.
|
|
7
7
|
* Trigger must have a targetDocumentId field set in Meta.
|
|
8
8
|
*/
|
|
9
|
-
export default async ({
|
|
10
|
-
|
|
11
|
-
data: { request },
|
|
12
|
-
},
|
|
13
|
-
context: { space },
|
|
14
|
-
}: any) => {
|
|
15
|
-
const { data, trigger } = (await request.json()) as RequestPayload;
|
|
9
|
+
export default async ({ data: { bodyText }, context: { space } }: any) => {
|
|
10
|
+
const { email, targetDocumentId: documentId } = JSON.parse(bodyText) as RequestPayload;
|
|
16
11
|
|
|
17
|
-
const documentId = trigger.meta.targetDocumentId;
|
|
18
12
|
const document = await space.db.query({ id: documentId }, { format: 'plain' }).first();
|
|
19
13
|
|
|
20
14
|
const contentId = document.content['/'].split(':')[3];
|
|
@@ -23,11 +17,11 @@ export default async ({
|
|
|
23
17
|
documentContent.content,
|
|
24
18
|
'',
|
|
25
19
|
'---',
|
|
26
|
-
`**From:** ${
|
|
27
|
-
`**Subject:** ${
|
|
28
|
-
`**Date:** ${
|
|
20
|
+
`**From:** ${email.from}`,
|
|
21
|
+
`**Subject:** ${email.subject}`,
|
|
22
|
+
`**Date:** ${email.created}`,
|
|
29
23
|
'',
|
|
30
|
-
|
|
24
|
+
email.body,
|
|
31
25
|
].join('\n');
|
|
32
26
|
|
|
33
27
|
await space.db.update({ id: contentId }, { content: modifiedContent });
|
|
@@ -36,6 +30,6 @@ export default async ({
|
|
|
36
30
|
};
|
|
37
31
|
|
|
38
32
|
type RequestPayload = {
|
|
39
|
-
|
|
40
|
-
|
|
33
|
+
email: { from: string; subject: string; created: string; body: string };
|
|
34
|
+
targetDocumentId: string;
|
|
41
35
|
};
|
|
@@ -3,15 +3,15 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
// @ts-ignore
|
|
6
|
-
import {
|
|
6
|
+
import { S, defineFunction } from 'dxos:functions';
|
|
7
7
|
import {
|
|
8
8
|
HttpClient,
|
|
9
9
|
HttpClientRequest,
|
|
10
10
|
FetchHttpClient,
|
|
11
11
|
// @ts-ignore
|
|
12
|
-
} from 'https://esm.sh/@effect/platform@0.77.2?deps=effect@3.
|
|
12
|
+
} from 'https://esm.sh/@effect/platform@0.77.2?deps=effect@3.14.21&bundle=false';
|
|
13
13
|
// @ts-ignore
|
|
14
|
-
import { Effect, Schedule } from 'https://esm.sh/effect@3.
|
|
14
|
+
import { Effect, Schedule } from 'https://esm.sh/effect@3.14.21?bundle=false';
|
|
15
15
|
|
|
16
16
|
export default defineFunction({
|
|
17
17
|
description: 'Returns the exchange rate between two currencies.',
|
|
@@ -23,11 +23,7 @@ export default defineFunction({
|
|
|
23
23
|
|
|
24
24
|
outputSchema: S.String.annotations({ description: 'The exchange rate between the two currencies' }),
|
|
25
25
|
|
|
26
|
-
handler: async ({
|
|
27
|
-
event: {
|
|
28
|
-
data: { from, to },
|
|
29
|
-
},
|
|
30
|
-
}: any) =>
|
|
26
|
+
handler: async ({ data: { from, to } }: any) =>
|
|
31
27
|
Effect.gen(function* () {
|
|
32
28
|
const res = yield* HttpClientRequest.get(`https://free.ratesdb.com/v1/rates?from=${from}&to=${to}`).pipe(
|
|
33
29
|
HttpClient.execute,
|
package/src/templates/forex.ts
CHANGED
|
@@ -13,11 +13,7 @@ export default defineFunction({
|
|
|
13
13
|
to: S.String.annotations({ description: 'The target currency' }),
|
|
14
14
|
}),
|
|
15
15
|
|
|
16
|
-
handler: async ({
|
|
17
|
-
event: {
|
|
18
|
-
data: { from, to },
|
|
19
|
-
},
|
|
20
|
-
}: any) => {
|
|
16
|
+
handler: async ({ data: { from, to } }: any) => {
|
|
21
17
|
const res = await fetch(`https://free.ratesdb.com/v1/rates?from=${from}&to=${to}`);
|
|
22
18
|
const {
|
|
23
19
|
data: { rates },
|